{"text": "C************************************************************\nC Subroutine GENE_ELLIPSE to generate a portion of an ellipse\nC in the arrays XX(NPOINTS), YY(NPOINTS). (NPOINTS<1000)\nC Called by FITELLI and compatible with EFIT\nC\nC NPOINT : (output) number of points in the arrays XX and YY\nC THEMI,THEMA: limiting angles in degrees\nC ARRAY Z : REAL*8 !\nC Z(1): major axis\nC Z(2): minor axis\nC Z(3): THETA0 in radians\nC Z(4): OX\nC Z(5): OY\nC\nC IOPT=0 : COMPLETE ELLIPSE\nC IOPT=1 : PART OF AN ELLIPSE\nC\nC JLP\nC Version 02-02-96\nC************************************************************\n\tSUBROUTINE GENE_ELLIPSE(XX,YY,NPOINT,Z,THEMI,THEMA,IOPT)\n\tREAL*4 XX(1),YY(1)\n\tREAL*8 Z(5),THEMI,THEMA\n REAL*4 THETA_RAD,THETA0_RAD\n\tREAL*4 OX,OY,THETA0,MAJAXIS,MINAXIS,PI\n INTEGER*4 IOPT\n\tCHARACTER*4 NCHAR\n\tPI=ACOS(-1.)\n \n\tMAJAXIS=SNGL(Z(1))\n\tMINAXIS=SNGL(Z(2))\n\tTHETA0=SNGL(Z(3))*180./PI\n\tOX=SNGL(Z(4))\n\tOY=SNGL(Z(5))\n \n\tIF(IOPT.EQ.1)THEN\n \n\tECCEN=MINAXIS/MAJAXIS\n\tTHEMI0=THEMI-THETA0\n\tTHEMA0=THEMA-THETA0\n \n\tTHEMIN=ELLIP_LIMIT(THEMI0,ECCEN)\n\tTHEMAX=ELLIP_LIMIT(THEMA0,ECCEN)\n\tIF(THEMIN.GT.THEMAX)THEMIN=THEMIN-360.\n \n\tELSE\n \n\tTHEMIN=0.\n\tTHEMAX=360.\n\t\n\tENDIF\n \nC Generating the ellipse (Step=.361 degree , i.e. less than 1000 pts max)\n\tTHETA=THEMIN\n THETA0_RAD=THETA0*PI/180.\n\tJJ=0\n94\tIF (THETA.GT.THEMAX) GOTO 95\n\tJJ=JJ+1\n THETA_RAD=THETA*PI/180.\n\tCALL ELLIP(THETA_RAD,XX(JJ),YY(JJ),OX,OY,THETA0_RAD,MAJAXIS,MINAXIS)\n\tTHETA=THETA+0.361\n\tGOTO 94\n \n95\tNPOINT=JJ\n\tRETURN\n\tEND\nC*******************************************************************\nC Computing XX,YY for a given value of THETA (degrees):\nC*******************************************************************\n\tSUBROUTINE ELLIP(THETA_RAD,X,Y,OX,OY,THETA0_RAD,MAJAXIS,MINAXIS)\n\tREAL*4 OX,OY,THETA0,MAJAXIS,MINAXIS\n REAL*4 THETA_RAD,THETA0_RAD\nC Ellipse centred on (0.,0.) and with major axis OX\n\tXXX=MAJAXIS*COS(THETA_RAD)\n\tYYY=MINAXIS*SIN(THETA_RAD)\nC Rotation of THETA0 and translation to (OX,OY)\n\tX=OX+COS(THETA0_RAD)*XXX-SIN(THETA0_RAD)*YYY\n\tY=OY+SIN(THETA0_RAD)*XXX+COS(THETA0_RAD)*YYY\n\tRETURN\n\tEND\nC*******************************************************************\nC Function ELLIP_LIMIT to compute the angular limits of an arc of ellipse\nC taking into account the effects of the eccentricity\nC*******************************************************************\n\tREAL FUNCTION ELLIP_LIMIT(THEMI0,ECCEN)\n REAL PI,THEMI0_RAD\n\tPI=ACOS(-1.)\n THEMI0_RAD=THEMI0*PI/180.\n\t IF(COS(THEMI0_RAD).EQ.0)THEN\n\t ELLIP_LIMIT=THEMI0\n\t ELSE\n\t TGTMIN=TAN(THEMI0_RAD)/ECCEN\n\t THEMIN=ATAN(TGTMIN)*180./PI\n\t IF(COS(THEMI0_RAD).LT.0.)THEMIN=THEMIN+180.\n\t ELLIP_LIMIT=THEMIN\n\t ENDIF\n\tEND\n \n", "meta": {"hexsha": "03b9a47368a19687901d4ded85a5fddd1843ca8c", "size": 2684, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "jlpsub/gene_ellipse.for", "max_stars_repo_name": "jlprieur/shell_galaxies", "max_stars_repo_head_hexsha": "1dde87ef33b3c33b3a892e9ad0d642ae02ac6d9e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "jlpsub/gene_ellipse.for", "max_issues_repo_name": "jlprieur/shell_galaxies", "max_issues_repo_head_hexsha": "1dde87ef33b3c33b3a892e9ad0d642ae02ac6d9e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "jlpsub/gene_ellipse.for", "max_forks_repo_name": "jlprieur/shell_galaxies", "max_forks_repo_head_hexsha": "1dde87ef33b3c33b3a892e9ad0d642ae02ac6d9e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.1111111111, "max_line_length": 73, "alphanum_fraction": 0.6140089419, "num_tokens": 991, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297887874625, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6999816751624032}} {"text": " SUBROUTINE MA02FD( X1, X2, C, S, INFO )\r\nC\r\nC SLICOT RELEASE 5.5.\r\nC\r\nC Copyright (c) 2002-2012 NICONET e.V.\r\nC\r\nC PURPOSE\r\nC\r\nC To compute the coefficients c and s (c^2 + s^2 = 1) for a modified\r\nC hyperbolic plane rotation, such that,\r\nC\r\nC y1 := 1/c * x1 - s/c * x2 = sqrt(x1^2 - x2^2),\r\nC y2 := -s * y1 + c * x2 = 0,\r\nC\r\nC given two real numbers x1 and x2, satisfying either x1 = x2 = 0,\r\nC or abs(x2) < abs(x1).\r\nC\r\nC ARGUMENTS\r\nC\r\nC Input/Output Parameters\r\nC\r\nC X1 (input/output) DOUBLE PRECISION\r\nC On entry, the real number x1.\r\nC On exit, the real number y1.\r\nC\r\nC X2 (input) DOUBLE PRECISION\r\nC The real number x2.\r\nC The values x1 and x2 should satisfy either x1 = x2 = 0, or\r\nC abs(x2) < abs(x1).\r\nC\r\nC C (output) DOUBLE PRECISION\r\nC The cosines c of the modified hyperbolic plane rotation.\r\nC\r\nC S (output) DOUBLE PRECISION\r\nC The sines s of the modified hyperbolic plane rotation.\r\nC\r\nC Error Indicator\r\nC\r\nC INFO INTEGER\r\nC = 0: succesful exit;\r\nC = 1: if abs(x2) >= abs(x1) and either x1 <> 0 or x2 <> 0.\r\nC\r\nC CONTRIBUTOR\r\nC\r\nC D. Kressner, Technical Univ. Chemnitz, Germany, June 2000.\r\nC\r\nC REVISIONS\r\nC\r\nC V. Sima, Katholieke Univ. Leuven, Belgium, June 2000.\r\nC\r\nC KEYWORDS\r\nC\r\nC Orthogonal transformation, plane rotation.\r\nC\r\nC *****************************************************************\r\nC\r\nC .. Parameters ..\r\n DOUBLE PRECISION ONE, ZERO\r\n PARAMETER ( ONE = 1.0D0, ZERO = 0.0D0 )\r\nC .. Scalar Arguments ..\r\n DOUBLE PRECISION X1, X2, C, S\r\n INTEGER INFO\r\nC .. Intrinsic Functions ..\r\n INTRINSIC ABS, SIGN, SQRT\r\nC .. Executable Statements ..\r\nC\r\n IF ( ( X1.NE.ZERO .OR. X2.NE.ZERO ) .AND.\r\n $ ABS( X2 ).GE.ABS( X1 ) ) THEN\r\n INFO = 1\r\n ELSE\r\n INFO = 0\r\n IF ( X1.EQ.ZERO ) THEN\r\n S = ZERO\r\n C = ONE\r\n ELSE\r\n S = X2 / X1\r\nC\r\nC No overflows could appear in the next statement; underflows\r\nC are possible if X2 is tiny and X1 is huge, but then\r\nC abs(C) = ONE - delta,\r\nC where delta is much less than machine precision.\r\nC\r\n C = SIGN( SQRT( ONE - S ) * SQRT( ONE + S ), X1 )\r\n X1 = C * X1\r\n END IF\r\n END IF\r\nC\r\n RETURN\r\nC *** Last line of MA02FD ***\r\n END\r\n", "meta": {"hexsha": "5f8ac720b976157999d11cd523fabc053ede6e59", "size": 2573, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "External/SLICOT/MA02FD.f", "max_stars_repo_name": "bgin/MissileSimulation", "max_stars_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2016-08-28T23:20:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-15T14:43:58.000Z", "max_issues_repo_path": "External/SLICOT/MA02FD.f", "max_issues_repo_name": "bgin/MissileSimulation", "max_issues_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-06-02T21:29:51.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-05T05:59:31.000Z", "max_forks_repo_path": "External/SLICOT/MA02FD.f", "max_forks_repo_name": "bgin/MissileSimulation", "max_forks_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-07-04T22:38:22.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-04T22:38:22.000Z", "avg_line_length": 28.2747252747, "max_line_length": 73, "alphanum_fraction": 0.5064127478, "num_tokens": 800, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240142763574, "lm_q2_score": 0.7461389873857264, "lm_q1q2_score": 0.699970902054394}} {"text": "!! R445 type-bound-procedure-part\n! is contains-stmt [ binding-private-stmt ] [ type-bound-proc-binding ] ...\n!\n! NOTE 4.43\n\nmodule myjunk\n\nTYPE POINT\n REAL :: X, Y\nCONTAINS\n PROCEDURE, PASS :: LENGTH => POINT_LENGTH\nEND TYPE POINT\n\ncontains\n\nREAL FUNCTION POINT_LENGTH (A, B)\n CLASS (POINT), INTENT (IN) :: A, B\n POINT_LENGTH = SQRT ( (A%X - B%X)**2 + (A%Y - B%Y)**2 )\nEND FUNCTION POINT_LENGTH\n\nend module\n", "meta": {"hexsha": "4406f6da7a6945593b86e21b108495ff2add1c51", "size": 415, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/rule-tests/pp/new/R445a.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/rule-tests/R445a.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/rule-tests/R445a.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": 18.8636363636, "max_line_length": 78, "alphanum_fraction": 0.6626506024, "num_tokens": 131, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267694452331, "lm_q2_score": 0.8056321843145404, "lm_q1q2_score": 0.6999548080591087}} {"text": " MODULE MOD_FLGRID\r\n\r\n CONTAINS\r\n\r\n SUBROUTINE FLGRID(NFLDIM, NFL, PHI, PWEIGHT, DELTAX)\r\n\r\n! FREQUENCY SCALE ETC. FOR THE CMF LINE CALCULATIONS\r\n! NFL NUMBER OF FREQUENCY POINTS (ORIGINAL POINTS)\r\n! XMAX MAXIMUM FREQUENCY\r\n! XK FREQUENCY POINTS (FALLING, DOPPLER UNITS) - NOT STORED\r\n! PHI(K) NORMALIZED LINE PROFILE\r\n! PWEIGHT(K) RENORMALIZED INTEGRATION WEIGHTS\r\n\r\n IMPLICIT REAL*8(A - H, O - Z)\r\n\r\n DIMENSION PHI(NFLDIM), PWEIGHT(NFLDIM)\r\n\r\n! WPI = SQRT(PI)\r\n DATA WPI /1.7724538509055D0/\r\n \r\n XMAX = 6.7D0\r\n NFL = 61\r\n \r\n IF (NFL .GT. NFLDIM) STOP \"FLGRID: DIMENSION IS TOO SMALL\"\r\n\r\n DELTAX = 2.D0 * XMAX / FLOAT(NFL - 1)\r\n WS = 0.0D0\r\n\r\n DO K = 1, NFL\r\n\r\n XK = XMAX - (K - 1) * DELTAX\r\n \r\n PWEIGHT(K) = EXP(-XK * XK)\r\n\r\n WS = WS + PWEIGHT(K)\r\n\r\n PHI(K) = EXP(-XK * XK) / WPI\r\n\r\n ENDDO\r\n \r\n! RENORMALIZATION\r\n DO K = 1, NFL; PWEIGHT(K) = PWEIGHT(K) / WS; ENDDO\r\n\r\n RETURN\r\n\r\n END SUBROUTINE\r\n\r\n END MODULE\r\n", "meta": {"hexsha": "b54ca588328adc8f588139854ae7a89551660ea7", "size": 1110, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/flgrid.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/flgrid.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/flgrid.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": 22.6530612245, "max_line_length": 75, "alphanum_fraction": 0.5207207207, "num_tokens": 373, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951588871158, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6999434655186425}} {"text": " REAL FUNCTION DCAL(RCELL,IH,IK,IL)\n IMPLICIT NONE\nC\n REAL RCELL(6)\n REAL RH,RK,RL\n INTEGER IH,IK,IL\nC\n RH = FLOAT(IH)\n RK = FLOAT(IK)\n RL = FLOAT(IL)\nC\n DCAL = SQRT(RH*RH*RCELL(1)*RCELL(1) + \n & RK*RK*RCELL(2)*RCELL(2) +\n & RL*RL*RCELL(3)*RCELL(3) + \n & 2.0*RK*RL*RCELL(2)*RCELL(3)*COS(RCELL(4)) +\n & 2.0*RL*RH*RCELL(3)*RCELL(1)*COS(RCELL(5)) +\n & 2.0*RH*RK*RCELL(1)*RCELL(2)*COS(RCELL(6)))\n RETURN \nC\n END\n", "meta": {"hexsha": "6e7c84638ceb362067ed0ec1b7cc18c4212ae981", "size": 538, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "software/lsqint/DCAL.f", "max_stars_repo_name": "scattering-central/CCP13", "max_stars_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "software/lsqint/DCAL.f", "max_issues_repo_name": "scattering-central/CCP13", "max_issues_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "software/lsqint/DCAL.f", "max_forks_repo_name": "scattering-central/CCP13", "max_forks_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-09-05T15:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-15T11:13:45.000Z", "avg_line_length": 25.619047619, "max_line_length": 61, "alphanum_fraction": 0.4628252788, "num_tokens": 219, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9740426450627306, "lm_q2_score": 0.7185943925708561, "lm_q1q2_score": 0.699941582866963}} {"text": "program Heapsort_Demo\n implicit none\n\n integer, parameter :: num = 20\n real :: array(num)\n\n call random_seed\n call random_number(array)\n write(*,*) \"Unsorted array:-\"\n write(*,*) array\n write(*,*)\n call heapsort(array)\n write(*,*) \"Sorted array:-\"\n write(*,*) array\n\ncontains\n\nsubroutine heapsort(a)\n\n real, intent(in out) :: a(0:)\n integer :: start, n, bottom\n real :: temp\n\n n = size(a)\n do start = (n - 2) / 2, 0, -1\n call siftdown(a, start, n);\n end do\n\n do bottom = n - 1, 1, -1\n temp = a(0)\n a(0) = a(bottom)\n a(bottom) = temp;\n call siftdown(a, 0, bottom)\n end do\n\nend subroutine heapsort\n\nsubroutine siftdown(a, start, bottom)\n\n real, intent(in out) :: a(0:)\n integer, intent(in) :: start, bottom\n integer :: child, root\n real :: temp\n\n root = start\n do while(root*2 + 1 < bottom)\n child = root * 2 + 1\n\n if (child + 1 < bottom) then\n if (a(child) < a(child+1)) child = child + 1\n end if\n\n if (a(root) < a(child)) then\n temp = a(child)\n a(child) = a (root)\n a(root) = temp\n root = child\n else\n return\n end if\n end do\n\nend subroutine siftdown\n\nend program Heapsort_Demo\n", "meta": {"hexsha": "843b4fe97dedc0d52f219f967e2fcc7bf49ec0e3", "size": 1179, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Sorting-algorithms-Heapsort/Fortran/sorting-algorithms-heapsort.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/Sorting-algorithms-Heapsort/Fortran/sorting-algorithms-heapsort.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Sorting-algorithms-Heapsort/Fortran/sorting-algorithms-heapsort.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 17.8636363636, "max_line_length": 50, "alphanum_fraction": 0.5767599661, "num_tokens": 394, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772417253255, "lm_q2_score": 0.8006919925839875, "lm_q1q2_score": 0.6998666483493666}} {"text": "!> K.A.Johannessen et al./Compt. Methods Appl. Mech. Engrg 269 (2014) 471-514\u306e2.2.4 Example\u3092\u518d\u73fe\nprogram main\n use module_globals\n use module_meshline\n use module_LRspline\n implicit none\n\n !> global tensor knot\n real(8),allocatable :: tn1(:), tn2(:)\n\n !> LR-spline\n type(LocallyRefinedSpline),pointer :: lrs_\n\n !> Mesh Line\n type(MeshLine),pointer :: ml_\n\n ! local variables\n type(LocallyRefinedSpline),pointer :: lrs\n type(MeshLine),pointer :: ml\n\n ! initialise\n call init_LRspline(lrs_)\n call init_meshline(ml_)\n \n ! tensor mesh = Bspline \u306e global knot\u3092\u8a2d\u5b9a\n ncp(1)=6\n ncp(2)=6\n ncp(0)=(ncp(1)+1)*(ncp(2)+1)\n allocate(tn1(0:ncp(1)+ndeg(1)+1))\n allocate(tn2(0:ncp(2)+ndeg(2)+1))\n tn1=[0.d0,0.d0,0.d0,1.d0,2.d0,4.d0,5.d0,6.d0,6.d0,6.d0]/6.d0\n tn2=[0.d0,0.d0,0.d0,1.d0,2.d0,4.d0,5.d0,6.d0,6.d0,6.d0]/6.d0\n\n ! tensor mesh \u306e local knot \u3092\u8a2d\u5b9a = Bspline \u306e knot\n call set_Bspline(lrs_,tn1,tn2)\n\n ! \u9069\u5f53\u306asurface\u3092\u8a2d\u5b9a\n call set_Greville(lrs_)\n lrs=>lrs_\n do while(associated(lrs))\n lrs%cp(3)=cos(2.d0*pi*lrs%cp(1))*sin(2.d0*pi*lrs%cp(2))\n lrs=>lrs%next\n end do\n\n ! draw itinial Bspline\n call draw_LRmesh(lrs_,\"LRmesh.res\")\n call draw_controlpoints(lrs_,\"controlpoints.res\")\n call draw_surface(lrs_,50,\"surface.res\")\n\n ! set meshlines\n call append_meshline(ml_,1,3.d0/6.d0,1.d0/6.d0,5.d0/6.d0)\n call append_meshline(ml_,2,3.d0/6.d0,1.d0/6.d0,5.d0/6.d0)\n\n ! draw meshline\n call draw_meshline(ml_,\"meshline.res\")\n\n ! refine LR-splines\n ml=>ml_\n do while(associated(ml))\n call refine_LRspline(lrs_,ml_,ml)\n ml=>ml%next\n end do\n\n ! draw refined LR-spline\n call draw_LRmesh(lrs_,\"LRmesh2.res\")\n call draw_controlpoints(lrs_,\"controlpoints2.res\")\n call draw_surface(lrs_,50,\"surface2.res\")\n \n ! finalise\n deallocate(tn1,tn2)\n call uninit_meshline(ml_)\n call uninit_LRspline(lrs_)\n\nend program main\n", "meta": {"hexsha": "e58d9f8da23274aa0dc709795379fe28ff16e339", "size": 1843, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "01example224/src/main.f90", "max_stars_repo_name": "isakari/testLRspline", "max_stars_repo_head_hexsha": "167a4b4a6495a260d2c0ab9453a7249e666d8e1c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "01example224/src/main.f90", "max_issues_repo_name": "isakari/testLRspline", "max_issues_repo_head_hexsha": "167a4b4a6495a260d2c0ab9453a7249e666d8e1c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "01example224/src/main.f90", "max_forks_repo_name": "isakari/testLRspline", "max_forks_repo_head_hexsha": "167a4b4a6495a260d2c0ab9453a7249e666d8e1c", "max_forks_repo_licenses": ["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.5733333333, "max_line_length": 94, "alphanum_fraction": 0.6836679327, "num_tokens": 753, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772253241802, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.6998666476883911}} {"text": "module interpol_mod\n\nuse constants_mod\n\ninteger, parameter :: RP = selected_real_kind(15)\n!real(dp), parameter :: PI = 4.0_rp * atan(1.0_rp)\n!real(dp), parameter :: TOL = 4.0e-16\n\nCONTAINS\n\n!pure SUBROUTINE DiffMatrix(x,N,D)\n! IMPLICIT NONE\n! INTEGER, INTENT(IN) :: N\n! real(dp)(KIND=RP), DIMENSION(0:N), INTENT(IN) :: x\n! real(dp)(KIND=RP), DIMENSION(0:N,0:N), INTENT(OUT) :: D\n!!\n! ! lokale Variablen\n! INTEGER :: i,j\n! real(dp)(KIND=RP), DIMENSION(0:N) :: w\n!!\n! ! Baryzentrische Gewichte bestimmen\n! CALL BarycentricWeights(x,N,w)\n! ! DiffMatrix gemaess Aufg.1e) befuellen\n! DO i=0,N\n! DO j=0,N\n! IF (i.NE.j) THEN\n! D(i,j) = w(j) / ( w(i) * (x(i)-x(j)) )\n! ! auf der Diagonalen alle anderen subtrahieren\n! D(i,i) = D(i,i) - D(i,j)\n! END IF\n! END DO\n! END DO\n!!\n! RETURN\n!!\n! END SUBROUTINE DiffMatrix\n\npure SUBROUTINE BarycentricWeights(N_in,xGP,wBary)\nIMPLICIT NONE\n!----------------------------------------------------------------------------------------------------------------------------------\n! INPUT/OUTPUT VARIABLES\nINTEGER,INTENT(IN) :: N_in !< polynomial degree\nreal(dp),INTENT(IN) :: xGP(0:N_in) !< Gauss point positions for the reference interval [-1,1]\nreal(dp),INTENT(OUT) :: wBary(0:N_in) !< barycentric weights\n!----------------------------------------------------------------------------------------------------------------------------------\n! LOCAL VARIABLES\nINTEGER :: iGP,jGP\n!==================================================================================================================================\nwBary(:)=1.\nDO iGP=1,N_in\n DO jGP=0,iGP-1\n wBary(jGP)=wBary(jGP)*(xGP(jGP)-xGP(iGP))\n wBary(iGP)=wBary(iGP)*(xGP(iGP)-xGP(jGP))\n END DO ! jGP\nEND DO ! iGP\nwBary(:)=1./wBary(:)\nEND SUBROUTINE BarycentricWeights\n\npure SUBROUTINE DiffMatrix(N_in,xGP,D)\nIMPLICIT NONE\n!----------------------------------------------------------------------------------------------------------------------------------\n! INPUT/OUTPUT VARIABLES\nINTEGER,INTENT(IN) :: N_in !< polynomial degree\nreal(dp),INTENT(IN) :: xGP(0:N_in) !< Gauss point positions for the reference interval [-1,1]\nreal(dp),INTENT(OUT) :: D(0:N_in,0:N_in) !< differentiation Matrix\n!----------------------------------------------------------------------------------------------------------------------------------\n! LOCAL VARIABLES\nINTEGER :: iGP,iLagrange\nreal(dp) :: wBary(0:N_in)\n!==================================================================================================================================\nCALL BarycentricWeights(N_in,xGP,wBary)\nD(:,:)=0.\nDO iLagrange=0,N_in\n DO iGP=0,N_in\n IF(iLagrange.NE.iGP)THEN\n D(iGP,iLagrange)=wBary(iLagrange)/(wBary(iGP)*(xGP(iGP)-xGP(iLagrange)))\n D(iGP,iGP)=D(iGP,iGP)-D(iGP,iLagrange)\n END IF ! (iLagrange.NE.iGP)\n END DO ! iGP\nEND DO ! iLagrange\nEND SUBROUTINE\n\npure function LagrangePolynomialDerivative(N, xs, j, x) result(lp)\n\n integer, intent(in) :: N\n real(dp), intent(in) :: xs(N)\n integer, intent(in) :: j\n real(dp), intent(in) :: x\n\n real(dp) :: lp\n real(dp) :: acc\n integer :: i,m\n\n lp = 0.0_dp\n\n do i = 1,N\n if (i == j) cycle\n acc = 1.0_dp\n do m = 1,N\n if (m == i .or. m == j) cycle\n acc = acc * (x-xs(m))/(xs(j)-xs(m))\n end do\n lp = lp + acc/(xs(j)-xs(i))\n end do\n\nend function\n\npure function LagrangePolynomialDerivativeMatrix(N,M, xs, ys) result(mat)\n\n integer, intent(in) :: N,M\n real(dp), intent(in) :: xs(N),ys(M)\n\n real(dp) :: mat(M,N)\n integer :: i,j\n\n do i = 1,M; do j = 1,N;\n mat(i,j) = LagrangePolynomialDerivative(N,xs,j,ys(i))\n end do; end do\n\nend function\n\npure function LagrangePolynomial(n, nodes, j, x) result(lp)\n \n integer, intent(in) :: n\n real(dp), intent(in) :: nodes(0:)\n integer, intent(in) :: j\n real(dp), intent(in) :: x\n\n real(dp) :: lp\n integer :: i\n\n lp = 1.0_dp\n do i = 0,n-1\n if (i == j) cycle\n lp = lp * (x - nodes(i))/(nodes(j) - nodes(i))\n end do\n \nend function\n\npure SUBROUTINE LagrangeInterpolatingPolynomials(y,x,w,N,l)\n\n!(Algorithm 34)\n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: N\n real(dp), INTENT(IN) :: y\n real(dp), DIMENSION(0:N), INTENT(IN) :: x,w\n real(dp), DIMENSION(0:N), INTENT(OUT) :: l\n !\n ! lokale Variablen\n LOGICAL :: stuetzstelle\n INTEGER :: j\n real(dp) :: s,t\n real(dp), PARAMETER :: tol = 10.0E-16_dp\n !\n ! Falls y eine Stuetzstelle ist:\n stuetzstelle = .FALSE.\n DO j=0,N\n l(j) = 0.0_RP\n IF (ABS(y-x(j)).LT.tol) THEN\n l(j) = 1.0_RP\n stuetzstelle = .TRUE.\n END IF\n END DO\n !\n! IF (stuetzstelle) THEN\n! EXIT\n! END IF\n\n ! Falls y keine Stuetzstelle ist:\n IF (.NOT. stuetzstelle) THEN\n s = 0.0_RP\n\n DO j=0,N\n t = w(j) / (y-x(j))\n l(j) = t\n s = s + t\n END DO\n DO j=0,N\n l(j) = l(j)/s\n END DO\n END IF\n!\n RETURN\n!\n END SUBROUTINE LagrangeInterpolatingPolynomials\n!\n! ------------------------------------------------------------------------------------------------------------- !\n!\npure SUBROUTINE Evaluation(y,x,f,w,N,f_y)\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: N\n real(dp), INTENT(IN) :: y\n real(dp), DIMENSION(0:N), INTENT(IN) :: x,f,w\n real(dp), INTENT(OUT) :: f_y\n !\n ! lokale Variablen\n LOGICAL :: stuetzstelle\n INTEGER :: j\n real(dp) :: numerator,denominator,hilf\n real(dp), PARAMETER :: tol = 1.0E-16_dp\n !\n ! Falls y eine Stuetzstelle ist:\n stuetzstelle = .FALSE.\n DO j=0,N\n IF (ABS(y-x(j)).LT.tol) THEN\n f_y = f(j)\n stuetzstelle = .TRUE.\n EXIT\n END IF\n END DO\n !\n ! Falls y keine Stuetzstelle ist:\n numerator = 0\n denominator = 0\n IF (.NOT. stuetzstelle) THEN\n DO j=0,N\n hilf = w(j) / (y-x(j))\n numerator = numerator + hilf * f(j)\n denominator = denominator + hilf\n END DO\n f_y = numerator / denominator\n END IF\n !\n RETURN\n !\n END SUBROUTINE Evaluation\n\npure SUBROUTINE LegendrePolynomialAndDerivativeAlbert(N,x,L_N,dL_N)\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: N\n real(dp), INTENT(IN) :: x\n real(dp), INTENT(OUT) :: L_N,dL_N\n !\n ! lokale Variablen\n INTEGER :: k\n real(dp) :: L_N_1,L_N_2,dL_N_1,dL_N_2\n !\n ! Fuer den einfachsten Fall explizit vorgeben\n IF (N.EQ.0) THEN\n L_N = 0.0_RP\n dL_N = 0.0_RP\n !\n ! Ebenso fuer den zweit-einfachsten Fall\n ELSE IF (N.EQ.1) THEN\n L_N = x\n dL_N = 1.0_RP\n !\n ! Ansonsten auf die 3-Term-Rekursion zurueckgreifen\n ELSE\n ! Dazu wieder die beiden ersten Polynome vorgeben\n L_N_2 = 1.0_RP\n L_N_1 = x\n dL_N_2 = 0.0_RP\n dL_N_1 = 1.0_RP\n !\n DO k=2,N\n ! Rekursionsformel fuer die Legendre-Polynome verwenden\n L_N = ( (2.0_RP*real(k,dP)-1.0_RP) / real(k,dp) ) * x * L_N_1 - (real(k,dP)-1.0_RP) / real(k,dP) * L_N_2\n ! Rekursionsformel fuer die Ableitungen verwenden\n dL_N = dL_N_2 + ( 2.0_RP*real(k,dP) - 1.0_RP ) * L_N_1\n ! Werte fuer den naechsten Schritt updaten\n L_N_2 = L_N_1\n L_N_1 = L_N\n dL_N_2 = dL_N_1\n dL_N_1 = dL_N\n END DO\n !\n END IF\n !\n RETURN\n END SUBROUTINE\n\npure ELEMENTAL SUBROUTINE LegendrePolynomialAndDerivative(N_in,x,L,Lder)\nIMPLICIT NONE\n!----------------------------------------------------------------------------------------------------------------------------------\n! INPUT/OUTPUT VARIABLES\nINTEGER,INTENT(IN) :: N_in !< (IN) polynomial degree, (N+1) CLpoints\nreal(dp),INTENT(IN) :: x !< (IN) coordinate value in the interval [-1,1]\nreal(dp),INTENT(OUT) :: L !< (OUT) Legedre polynomial evaluated at \\f$ \\xi: L_N(\\xi), \\partial/\\partial\\xi L_N(\\xi) \\f$\nreal(dp),INTENT(OUT) :: Lder !< (OUT) Legedre polynomial deriv. evaluated at \\f$ \\xi: L_N(\\xi), \\partial/\\partial\\xi L_N(\\xi) \\f$\n!----------------------------------------------------------------------------------------------------------------------------------\n! LOCAL VARIABLES\nINTEGER :: iLegendre\nreal(dp) :: L_Nm1,L_Nm2 ! L_{N_in-2},L_{N_in-1}\nreal(dp) :: Lder_Nm1,Lder_Nm2 ! Lder_{N_in-2},Lder_{N_in-1}\n!==================================================================================================================================\nIF(N_in .EQ. 0)THEN\n L=1.0_dp\n Lder=0.0_dp\nELSEIF(N_in .EQ. 1) THEN\n L=x\n Lder=1.0_dp\nELSE ! N_in > 1\n L_Nm2=1.0_dp\n L_Nm1=x\n Lder_Nm2=0.0_dp\n Lder_Nm1=1.0_dp\n DO iLegendre=2,N_in\n L=(real(2*iLegendre-1,dp)*x*L_Nm1 - real(iLegendre-1,dp)*L_Nm2)/real(iLegendre,dp)\n Lder=Lder_Nm2 + real(2*iLegendre-1,dp)*L_Nm1\n L_Nm2=L_Nm1\n L_Nm1=L\n Lder_Nm2=Lder_Nm1\n Lder_Nm1=Lder\n END DO !iLegendre=2,N_in\nEND IF ! N_in\n!normalize\nL=L*SQRT(real(N_in,dp)+0.5_dp)\nLder=Lder*SQRT(real(N_in,dp)+0.5_dp)\nEND SUBROUTINE LegendrePolynomialAndDerivative\n\npure SUBROUTINE EquidistantNodesAndWeights(N_in,xGP,wGP)\n\n IMPLICIT NONE\n\n INTEGER,INTENT(IN) :: N_in !< polynomial degree, (N_in+1) Gausspoints\n real(dp),INTENT(OUT) :: xGP(0:N_in) !< Gauss point positions for the reference interval [-1,1]\n real(dp),INTENT(OUT),OPTIONAL :: wGP(0:N_in) !< Gauss point weights\n\n integer :: i\n\n do i = 1,N_IN+1\n xGP(i-1) = -1.0_dp + 2.0_dp*(real(i,dp)-0.5_dp)/real(N_IN+1,dp)\n end do\n\n wGP = 2.0_dp/real(N_IN+1,dp)\n\nend subroutine\n\npure subroutine equidistandinterfacenodes_3times(N,xs,ws)\n\n implicit none\n\n integer,intent(in) :: N\n real(dp),intent(out) :: xs(N)\n real(dp),intent(out),optional :: ws(N)\n\n integer :: i\n\n do i = 2,N,3\n xs(i-1) = -1.0_dp + 2.0_dp*(real(i,dp)-0.5_dp)/real(N,dp) - 3.0_dp/real(N,dp)\n xs(i+0) = -1.0_dp + 2.0_dp*(real(i,dp)-0.5_dp)/real(N,dp)\n xs(i+1) = -1.0_dp + 2.0_dp*(real(i,dp)-0.5_dp)/real(N,dp) + 3.0_dp/real(N,dp)\n end do\n\n !wgp = 2.0/real(n_in+1,dp)\n ws = 0.0_dp\n\nend subroutine\n\npure subroutine equidistandinterfacenodes(N,xs)\n\n integer,intent(in) :: N\n real(dp),intent(out) :: xs(N)\n\n integer :: i\n\n do i = 1,N\n xs(2*i-1) = -1.0_dp + 2.0_dp*(real(i,dp)-0.5_dp)/real(N,dp) - 1.0_dp/real(N,dp)\n xs(2*i+0) = -1.0_dp + 2.0_dp*(real(i,dp)-0.5_dp)/real(N,dp)\n end do\n\n xs(2*N+1) = 1.0_dp\n\nend subroutine\n\npure subroutine InterfaceNodes(N,xL,xC,xR)\n\n implicit none\n\n integer,intent(in) :: N\n real(dp),intent(out) :: xL(N),xC(N),xR(N)\n\n integer :: i\n\n do i = 1,N\n xL(i) = -1.0_dp + 2.0_dp*(real(i,dp)-0.5_dp)/real(N,dp) - 1.0_dp/real(N,dp)\n xC(i) = -1.0_dp + 2.0_dp*(real(i,dp)-0.5_dp)/real(N,dp)\n xR(i) = -1.0_dp + 2.0_dp*(real(i,dp)-0.5_dp)/real(N,dp) + 1.0_dp/real(N,dp)\n end do\n\nend subroutine\n\n\npure SUBROUTINE NodesAndWeights(N_in,xGP,wGP)\n\n IMPLICIT NONE\n\n INTEGER,INTENT(IN) :: N_in !< polynomial degree, (N_in+1) Gausspoints\n real(dp),INTENT(OUT) :: xGP(0:N_in) !< Gauss point positions for the reference interval [-1,1]\n real(dp),INTENT(OUT),OPTIONAL :: wGP(0:N_in) !< Gauss point weights\n\n call LegendreGaussNodesAndWeights(N_in, xGP, wGP)\n\nend subroutine\n\n\npure SUBROUTINE LegendreGaussNodesAndWeights(N_in,xGP,wGP)\n\nIMPLICIT NONE\n!----------------------------------------------------------------------------------------------------------------------------------\n! INPUT/OUTPUT VARIABLES\nINTEGER,INTENT(IN) :: N_in !< polynomial degree, (N_in+1) Gausspoints\nreal(dp),INTENT(OUT) :: xGP(0:N_in) !< Gauss point positions for the reference interval [-1,1]\nreal(dp),INTENT(OUT),OPTIONAL :: wGP(0:N_in) !< Gauss point weights\n!----------------------------------------------------------------------------------------------------------------------------------\n! LOCAL VARIABLES\nINTEGER, parameter :: nIter = 10 ! max. number of newton iterations\nreal(dp), parameter :: Tol = 1.E-15_dp ! tolerance for Newton iteration: TODO: use variable tolerance here!\nINTEGER :: iGP,iter\nreal(dp) :: L_Np1,Lder_Np1 ! L_{N_in+1},Lder_{N_in+1}\nreal(dp) :: dx ! Newton step\nreal(dp) :: cheb_tmp ! temporary variable for evaluation of chebychev node positions\n!==================================================================================================================================\nIF(N_in .EQ. 0) THEN\n xGP=0.0_dp\n IF(PRESENT(wGP))wGP=2.0_dp\n RETURN\nELSEIF(N_in.EQ.1)THEN\n xGP(0)=-sqrt(1.0_dp/3.0_dp)\n xGP(N_in)=-xGP(0)\n IF(PRESENT(wGP))wGP=1.0_dp\n RETURN\nELSE ! N_in>1\n cheb_tmp=2.0_dp*atan(1.0_dp)/real(N_in+1,dp) ! pi/(2N+2)\n DO iGP=0,(N_in+1)/2-1 !since points are symmetric, only left side is computed\n xGP(iGP)=-cos(cheb_tmp*real(2*iGP+1,dp)) !initial guess\n ! Newton iteration\n DO iter=0,nIter\n CALL LegendrePolynomialAndDerivative(N_in+1,xGP(iGP),L_Np1,Lder_Np1)\n dx=-L_Np1/Lder_Np1\n xGP(iGP)=xGP(iGP)+dx\n IF(abs(dx).LT.Tol*abs(xGP(iGP))) EXIT\n END DO ! iter\n IF(iter.GT.nIter) THEN\n !WRITE(*,*) 'maximum iteration steps >10 in Newton iteration for Legendre Gausspoint'\n xGP(iGP)=-cos(cheb_tmp*real(2*iGP+1,dp)) !initial guess\n ! Newton iteration\n DO iter=0,nIter\n !WRITE(*,*) iter,xGP(iGP) !DEBUG\n CALL LegendrePolynomialAndDerivative(N_in+1,xGP(iGP),L_Np1,Lder_Np1)\n dx=-L_Np1/Lder_Np1\n xGP(iGP)=xGP(iGP)+dx\n IF(abs(dx).LT.Tol*abs(xGP(iGP))) EXIT\n END DO !iter\n !CALL abort(__STAMP__,&\n ! 'ERROR: Legendre Gauss nodes could not be computed up to desired precision. Code stopped!')\n END IF ! (iter.GT.nIter)\n CALL LegendrePolynomialAndDerivative(N_in+1,xGP(iGP),L_Np1,Lder_Np1)\n xGP(N_in-iGP)=-xGP(iGP)\n IF(PRESENT(wGP))THEN\n !wGP(iGP)=2./((1.-xGP(iGP)*xGP(iGP))*Lder_Np1*Lder_Np1) !if Legendre not normalized\n wGP(iGP)=(2.0_dp*N_in+3)/((1.0_dp-xGP(iGP)*xGP(iGP))*Lder_Np1*Lder_Np1)\n wGP(N_in-iGP)=wGP(iGP)\n END IF\n END DO !iGP\nEND IF ! N_in\nIF(mod(N_in,2) .EQ. 0) THEN\n xGP(N_in/2)=0.\n CALL LegendrePolynomialAndDerivative(N_in+1,xGP(N_in/2),L_Np1,Lder_Np1)\n !IF(PRESENT(wGP))wGP(N_in/2)=2./(Lder_Np1*Lder_Np1) !if Legendre not normalized\n IF(PRESENT(wGP))wGP(N_in/2)=(2.0_dp*N_in+3.0_dp)/(Lder_Np1*Lder_Np1)\nEND IF ! (mod(N_in,2) .EQ. 0)\nEND SUBROUTINE LegendreGaussNodesAndWeights\n\n\npure SUBROUTINE qAndLEvaluation(N,x,q,dq,L_N)\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: N\n real(dp), INTENT(IN) :: x\n real(dp), INTENT(OUT) :: L_N,q,dq\n !\n ! lokale Variablen\n INTEGER :: k\n real(dp) :: L_N_1,L_N_2,L_k,dL_N,dL_N_1,dL_N_2,dL_k\n !\n ! NUR FUER N>=2 !\n !\n ! Initialisieren\n L_N_2 = 1.0_RP\n L_N_1 = x\n dL_N_2 = 0.0_RP\n dL_N_1 = 1.0_RP\n !\n DO k=2,N\n ! Rekursionsformel verwenden\n L_N = (2.0_RP*real(k,dP)-1.0_RP)/real(k,dP) * x * L_N_1 - (real(k,dP)-1.0_RP)/real(k,dP) * L_N_2\n ! Rekursionsformel fuer die Ableitungen verwenden\n dL_N = dL_N_2 + (2.0_RP*real(k,dP)-1.0_RP) * L_N_1\n ! Werte fuer den naechsten Schritt updaten\n L_N_2 = L_N_1\n L_N_1 = L_N\n dL_N_2 = dL_N_1\n dL_N_1 = dL_N\n END DO\n !\n ! Einen weiteren Schritt gehen\n k = N+1\n ! Rekursionsformel verwenden\n L_k = (2.0_RP*real(k,dP)-1.0_RP)/real(k,dP) * x * L_N - (real(k,dP)-1.0_RP)/real(k,dP) * L_N_2\n ! Rekursionsformel fuer die Ableitungen verwenden\n dL_k = dL_N_2 + (2.0_RP*real(k,dP)-1.0_RP) * L_N_1\n ! Benoetigtes Polynom und Ableitung bestimmen\n q = L_k - L_N_2\n dq = dL_k - dL_N_2\n !\n RETURN\n END SUBROUTINE qAndLEvaluation\n!\n! ------------------------------------------------------------------------------------------------------------- !\n!\npure SUBROUTINE LegendreGaussLobattoNodesAndWeights(N,x,w)\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: N\n real(dp), DIMENSION(0:N), INTENT(OUT) :: x,w\n !\n ! lokale Variablen\n INTEGER, PARAMETER :: n_it = 4\n INTEGER :: j,k\n real(dp), PARAMETER :: tol = 4.0E-16_dp\n real(dp) :: q,dq,L_N,Delta\n\n L_N = 0.0_dp\n !\n ! Fuer den einfachsten Fall Knoten und Gewicht explizit angeben\n IF (N.EQ.1) THEN\n x(0) = -1.0_RP\n w(0) = 1.0_RP\n x(1) = 1.0_RP\n w(1) = w(0)\n !\n ELSE\n ! Randwerte explizit vorgeben\n x(0) = -1.0_RP\n w(0) = 2.0_RP / ( real(N,dP)*(real(N,dP)+1) )\n x(N) = 1.0_RP\n w(N) = w(0)\n ! Ansonsten: Symmetrie ausnutzen (nur fuer die erste Haelfte berechnen)\n DO j=1,((N+1)/2 - 1)\n ! Anfangsschaetzung mittels asymptotischer Relation nach Parter:\n ! Setzte negatives Vorzeichen, um die Stuetzstellen aus dem Intervall (-1,0) zu erhalten.\n x(j) = -cos( ((real(j,dP)+0.25_RP)*pi)/real(N,dP) - (3.0_RP/(8_RP*real(N,dP)*pi)) * (1.0_dp/(real(j,dP)+0.25_RP)) )\n !\n ! Diese Schaetzung wird nun mithilfe des Newton-Verfahrens praezisiert\n DO k=0,n_it\n ! Dazu wird das (N+1)-ste Polynom sowie dessen Ableitung benoetigt\n ! (ausgewertet an der entspr. Stuetzstelle)\n CALL qAndLEvaluation(N,x(j),q,dq,L_N)\n ! Newton-Korrektur berechnen und anwenden\n Delta = -q/dq\n x(j) = x(j) + Delta\n ! Falls vor Abarbeiten aller festgelegten Iterationen des Newton-Verfahrens der berechnete Wert\n ! schon nahe genug an der Nullstelle liegt, wird abgebrochen.\n IF ( ABS(Delta).LE.(tol * ABS(x(j))) ) THEN\n EXIT\n END IF\n !\n END DO\n !\n CALL qAndLEvaluation(N,x(j),q,dq,L_N)\n ! Nutze Symmetrie aus (Multiplikation mit -1)\n x(N-j) = -x(j)\n ! Gewichte berechnen\n w(j) = 2.0_RP / ( real(N,dP)*(real(N,dP)+1.0_RP) * (L_N*L_N) )\n ! Auch die Gewichte sind symmetrisch\n w(N-j) = w(j)\n !\n END DO\n !\n END IF\n !\n ! Falls eine ungerade Anzahl gefordert wird, noch die \"mittleren\" Werte angeben\n IF (MOD(N,2).EQ.0) THEN\n CALL qAndLEvaluation(N,0.0_RP,q,dq,L_N)\n ! Berechnung der Stuetzstellen und Gewichte analog\n x(N/2) = 0.0_RP\n w(N/2) = 2.0_RP / ( real(N,dP) * (real(N,dP)+1.0_RP) * (L_N*L_N) )\n END IF\n !\n RETURN\n END SUBROUTINE LegendreGaussLobattoNodesAndWeights\n\npure subroutine mkVanderMondeMatrix(n, nodes, Vdm, sVdm)\n\n use linalg_mod, only: invert\n\n integer, intent(in) :: n\n real(dp), intent(in) :: nodes(:)\n real(dp), intent(out) :: Vdm(:,:)\n real(dp), intent(out) :: sVdm(:,:)\n real(dp) :: dummy\n integer :: i,j\n\n do i = 1,n; do j = 1,n\n call LegendrePolynomialAnDderivative(j-1, nodes(i), Vdm(i,j), dummy)\n end do; end do\n\n sVdm = invert(Vdm,n)\n \n end subroutine\n\nEND MODULE\n", "meta": {"hexsha": "c45ccfd2ba0ec761e08d694df0d9792dc0d751af", "size": 20928, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/utils/interpol_mod.f90", "max_stars_repo_name": "jmark/nemo", "max_stars_repo_head_hexsha": "cf8a6a8bed5c54626f5e300c701b9c278fd5e0cd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source/utils/interpol_mod.f90", "max_issues_repo_name": "jmark/nemo", "max_issues_repo_head_hexsha": "cf8a6a8bed5c54626f5e300c701b9c278fd5e0cd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/utils/interpol_mod.f90", "max_forks_repo_name": "jmark/nemo", "max_forks_repo_head_hexsha": "cf8a6a8bed5c54626f5e300c701b9c278fd5e0cd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.6490066225, "max_line_length": 133, "alphanum_fraction": 0.4869074924, "num_tokens": 6594, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.874077222043951, "lm_q2_score": 0.8006920092299293, "lm_q1q2_score": 0.6998666471404862}} {"text": "! sets.f90 --\n! Implementation of unordered sets\n!\n! See the example/test program for the way to use this\n!\n! The module is straightforward: it uses the vector\n! data structure to store the data. The operations\n! are the typical mathematical set operations,\n! with operators defined for convenience.\n!\n! Note:\n! Define the type SET_DATA for the data to be\n! maintained via this module.\n!\n! Note:\n! To allow maximum freedom in chosing the names of\n! the modules the code is split in two parts:\n! - an include file to define the VECTOR data type\n! (see data_for_sets.f90)\n! - this file to define the SET data type itself.\n! The test/example program shows how to use them.\n!\n! $Id: sets.f90,v 1.2 2006-03-26 19:03:53 arjenmarkus Exp $\n\n!\n! Make everything private, except what we want to\n! expose\n!\nimplicit none\nprivate\n\ntype SET\n type(VECTOR) :: values\nendtype\n\npublic :: SET, SET_DATA\npublic :: set_create, set_destroy, set_add, set_haselement, &\n set_union, set_intersection, set_exclusion, &\n set_hassubset, set_size, set_equal, set_delete_element, &\n operator(.elementof.), &\n operator(.union.), &\n operator(.intersect.), &\n operator(.exclude.), &\n operator(.subsetof.), &\n operator(.eq.), &\n operator(.ne.)\n\ninterface operator(.elementof.)\n module procedure set_iselement\nend interface\n\ninterface operator(.subsetof.)\n module procedure set_issubset\nend interface\n\ninterface operator(.union.)\n module procedure set_union\nend interface\n\ninterface operator(.intersect.)\n module procedure set_intersection\nend interface\n\ninterface operator(.exclude.)\n module procedure set_exclusion\nend interface\n\ninterface operator(.eq.)\n module procedure set_equal\nend interface\n\ninterface operator(.ne.)\n module procedure set_notequal\nend interface\n\ncontains\n!\n! Code specific for the set data structure\n!\n\n! set_create --\n! Create and initialise a set\n! Arguments:\n! dataset New set\n!\nsubroutine set_create( dataset )\n type(SET), intent(inout) :: dataset\n\n call vector_create( dataset%values )\n\nend subroutine set_create\n\n! set_destroy --\n! Destroy a set\n! Arguments:\n! dataset Existing set\n!\nsubroutine set_destroy( dataset )\n type(SET), intent(inout) :: dataset\n\n call vector_destroy( dataset%values )\n\nend subroutine set_destroy\n\n! set_size --\n! Function to return the size of the set\n! Arguments:\n! dataset Existing set\n!\ninteger function set_size( dataset )\n type(SET), intent(in) :: dataset\n\n set_size = vector_size( dataset%values )\n\nend function set_size\n\n! set_haselement --\n! Function to check if an element is contained\n! in the set\n! Arguments:\n! dataset Existing set\n! elem Element to be checked\n!\nlogical function set_haselement( dataset, elem )\n type(SET), intent(in) :: dataset\n type(SET_DATA), intent(in) :: elem\n\n type(VECTOR_DATA) :: vector_elem\n integer :: size\n integer :: i\n\n size = vector_size( dataset%values )\n\n set_haselement = .false.\n do i = 1,size\n vector_elem = vector_at( dataset%values, i )\n if ( elem == vector_elem%data ) then\n set_haselement = .true.\n exit\n endif\n enddo\nend function set_haselement\n\n! set_iselement --\n! Function to check if an element is contained\n! in the set (reversed arguments)\n! Arguments:\n! elem Element to be checked\n! dataset Existing set\n!\nlogical function set_iselement( elem, dataset )\n type(SET_DATA), intent(in) :: elem\n type(SET), intent(in) :: dataset\n\n set_iselement = set_haselement( dataset, elem )\nend function set_iselement\n\n! set_hassubset --\n! Function to check if one set is contained\n! in another set\n! Arguments:\n! set1 Set that may contain the second\n! set2 Set that is possibly a subset\n!\nlogical function set_hassubset( set1, set2 )\n type(SET), intent(in) :: set1\n type(SET), intent(in) :: set2\n\n type(VECTOR_DATA) :: vector_elem\n integer :: size\n integer :: i\n\n size = vector_size( set2%values )\n\n set_hassubset = .true.\n do i = 1,size\n vector_elem = vector_at( set2%values, i )\n if ( .not. set_haselement( set1, vector_elem%data ) ) then\n set_hassubset = .false.\n exit\n endif\n enddo\nend function set_hassubset\n\n! set_issubset --\n! Function to check if one set is contained\n! in another set (reversed arguments)\n! Arguments:\n! set1 Set that is possibly a subset\n! set2 Set that may contain the first\n!\nlogical function set_issubset( set1, set2 )\n type(SET), intent(in) :: set1\n type(SET), intent(in) :: set2\n\n set_issubset = set_hassubset( set2, set1 )\nend function set_issubset\n\n! set_equal --\n! Function to check if two sets are equal\n! Arguments:\n! set1 First set\n! set2 Second set\n!\nlogical function set_equal( set1, set2 )\n type(SET), intent(in) :: set1\n type(SET), intent(in) :: set2\n\n set_equal = set_hassubset( set2, set1 )\n if ( set_equal ) then\n set_equal = set_hassubset( set1, set2 )\n endif\nend function set_equal\n\n! set_notequal --\n! Function to check if two sets are not equal\n! Arguments:\n! set1 First set\n! set2 Second set\n!\nlogical function set_notequal( set1, set2 )\n type(SET), intent(in) :: set1\n type(SET), intent(in) :: set2\n\n set_notequal = .not. set_hassubset( set2, set1 )\n if ( .not. set_notequal ) then\n set_notequal = .not. set_hassubset( set1, set2 )\n endif\nend function set_notequal\n\n! set_union --\n! Function to return the union of two sets\n! Arguments:\n! set1 First set\n! set2 Second set\n!\nfunction set_union( set1, set2 ) result(union)\n type(SET), intent(in) :: set1\n type(SET), intent(in) :: set2\n type(SET) :: union\n\n type(VECTOR_DATA) :: vector_elem\n integer :: size\n integer :: i\n\n call set_create( union )\n\n size = vector_size( set1%values )\n do i = 1,size\n vector_elem = vector_at( set1%values, i )\n call set_add( union, vector_elem%data )\n enddo\n\n size = vector_size( set2%values )\n do i = 1,size\n vector_elem = vector_at( set2%values, i )\n call set_add( union, vector_elem%data )\n enddo\nend function set_union\n\n! set_intersection --\n! Function to return the intersection of two sets\n! Arguments:\n! set1 First set\n! set2 Second set\n!\nfunction set_intersection( set1, set2 ) result(intersection)\n type(SET), intent(in) :: set1\n type(SET), intent(in) :: set2\n type(SET) :: intersection\n\n type(VECTOR_DATA) :: vector_elem\n integer :: size\n integer :: i\n\n call set_create( intersection )\n\n size = vector_size( set1%values )\n do i = 1,size\n vector_elem = vector_at( set1%values, i )\n if ( set_haselement( set2, vector_elem%data ) ) then\n call set_add( intersection, vector_elem%data )\n endif\n enddo\nend function set_intersection\n\n! set_exclusion --\n! Function to return the exclusion of two sets\n! Arguments:\n! set1 First set\n! set2 Second set\n!\nfunction set_exclusion( set1, set2 ) result(exclusion)\n type(SET), intent(in) :: set1\n type(SET), intent(in) :: set2\n type(SET) :: exclusion\n\n type(VECTOR_DATA) :: vector_elem\n integer :: size\n integer :: i\n\n call set_create( exclusion )\n\n size = vector_size( set1%values )\n do i = 1,size\n vector_elem = vector_at( set1%values, i )\n if ( .not. set_haselement( set2, vector_elem%data ) ) then\n call set_add( exclusion, vector_elem%data )\n endif\n enddo\nend function set_exclusion\n\n! set_add --\n! Add an element to the set (if it already exists,\n! it is not added)\n! Arguments:\n! dataset Set to which the element must be added\n! elem Element to be added\n!\nsubroutine set_add( dataset, elem )\n type(SET), intent(in) :: dataset\n type(SET_DATA), intent(in) :: elem\n\n type(VECTOR_DATA) :: vector_elem\n\n if ( .not. set_haselement( dataset, elem ) ) then\n vector_elem%data = elem\n call vector_append( dataset%values, vector_elem )\n endif\nend subroutine set_add\n\n! set_delete_element --\n! Delete an element from the set (if it does not exist,\n! nothing happens)\n! Arguments:\n! dataset Set from which the element must be deleted\n! elem Element to be deleted\n!\nsubroutine set_delete_element( dataset, elem )\n type(SET), intent(in) :: dataset\n type(SET_DATA), intent(in) :: elem\n\n type(VECTOR_DATA) :: vector_elem\n integer :: size\n integer :: i\n\n size = vector_size( dataset%values )\n do i = 1,size\n vector_elem = vector_at( dataset%values, i )\n if ( elem == vector_elem%data ) then\n call vector_delete_elements( dataset%values, i, 1 )\n exit\n endif\n enddo\nend subroutine set_delete_element\n", "meta": {"hexsha": "cead454ee514d9d2f7821db1a2fc79e3ddab1876", "size": 9299, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/datastructures/sets.f90", "max_stars_repo_name": "timcera/flibs_from_svn", "max_stars_repo_head_hexsha": "7790369ac1f0ff6e35ef43546446b32446dccc6b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/datastructures/sets.f90", "max_issues_repo_name": "timcera/flibs_from_svn", "max_issues_repo_head_hexsha": "7790369ac1f0ff6e35ef43546446b32446dccc6b", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/datastructures/sets.f90", "max_forks_repo_name": "timcera/flibs_from_svn", "max_forks_repo_head_hexsha": "7790369ac1f0ff6e35ef43546446b32446dccc6b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.1207865169, "max_line_length": 67, "alphanum_fraction": 0.6299602108, "num_tokens": 2414, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044094, "lm_q2_score": 0.8006919949619793, "lm_q1q2_score": 0.6998666399221026}} {"text": "!===========================================\r\nsubroutine MatVecProd_real(Mat,m,vec) !real product of a matrix and vector\r\n\r\n use global_com,only:dp\r\n\r\n implicit none\r\n INTEGER,INTENT(IN):: m\r\n REAL(kind=dp), INTENT(INOUT):: vec(m)\r\n REAL(kind=dp), INTENT(IN):: Mat(m,m)\r\n \r\n INTEGER:: i\r\n REAL(kind=dp):: temp(m),tempM(m)\r\n \r\n DO i = 1,m\r\n tempM(:) = Mat(i,:)\r\n temp(i) = DOT_PRODUCT(tempM,vec)\r\n ENDDO\r\n vec(:) = temp(:) \r\n \r\nEND SUBROUTINE MatVecProd_real\r\n!!******************************************************************************************END \r\n\r\n \r\n \r\n \r\nSUBROUTINE real_cross_product(va,vb,vc) !cross product of two real numbers\r\n\r\n use global_com,only:dp\r\n\r\n implicit none\r\n real(kind=dp):: va(3),vb(3),vc(3)\r\n\r\n vc = 0.0_dp\r\n vc(1)=va(2)*vb(3)-va(3)*vb(2) \r\n vc(2)=va(3)*vb(1)-va(1)*vb(3)\r\n vc(3)=va(1)*vb(2)-va(2)*vb(1) \r\n\r\nEND subroutine real_cross_product\r\n!******************************************************************************************END \r\n \r\n \r\n \r\n \r\n \r\n!=========================================== \r\nsubroutine getinverse(a,c,n)\r\n !\r\n ! Inverse matrix\r\n ! Method: Based on DOolittle LU factorization for Ax=b\r\n ! Alex G. December 2009\r\n !-----------------------------------------------------------\r\n ! input ...\r\n ! a(n,n) - array of coefficients for matrix A\r\n ! n - dimension\r\n ! output ...\r\n ! c(n,n) - inverse matrix of A\r\n ! comments ...\r\n ! the original matrix a(n,n) will be destroyed \r\n ! during the calculation\r\n !\r\n use global_com,only:dp\r\n\r\n implicit none \r\n integer n\r\n real(kind=dp):: a(n,n), c(n,n)\r\n real(kind=dp):: L(n,n), U(n,n), b(n), d(n), x(n)\r\n real(kind=dp):: coeff\r\n integer i, j, k\r\n\r\n ! step 0: initialization for matrices L and U and b\r\n ! Fortran 90/95 aloows such operations on matrices\r\n L=0.0_dp\r\n U=0.0_dp\r\n b=0.0_dp\r\n\r\n ! step 1: forward elimination\r\n DO k=1, n-1\r\n DO i=k+1,n\r\n coeff=a(i,k)/a(k,k)\r\n L(i,k) = coeff\r\n DO j=k+1,n\r\n a(i,j) = a(i,j)-coeff*a(k,j)\r\n END DO\r\n END DO\r\n END DO\r\n\r\n ! Step 2: prepare L and U matrices \r\n ! L matrix is a matrix of the elimination coefficient\r\n ! + the diagonal elements are 1.0\r\n DO i=1,n\r\n L(i,i) = 1.0_dp\r\n END DO\r\n ! U matrix is the upper triangular part of A\r\n DO j=1,n\r\n DO i=1,j\r\n U(i,j) = a(i,j)\r\n END DO\r\n END DO\r\n\r\n ! Step 3: compute columns of the inverse matrix C\r\n DO k=1,n\r\n b(k)=1.0_dp\r\n d(1) = b(1)\r\n ! Step 3a: Solve Ld=b using the forward substitution\r\n DO i=2,n\r\n d(i)=b(i)\r\n DO j=1,i-1\r\n d(i) = d(i) - L(i,j)*d(j)\r\n END DO\r\n END DO\r\n ! Step 3b: Solve Ux=d using the back substitution\r\n x(n)=d(n)/U(n,n)\r\n DO i = n-1,1,-1\r\n x(i) = d(i)\r\n DO j=n,i+1,-1\r\n x(i)=x(i)-U(i,j)*x(j)\r\n END DO\r\n x(i) = x(i)/u(i,i)\r\n END DO\r\n ! Step 3c: fill the solutions x(n) into column k of C\r\n DO i=1,n\r\n c(i,k) = x(i)\r\n END DO\r\n b(k)=0.0_dp\r\n END DO\r\nEND subroutine getinverse\r\n!******************************************************************************************END \r\n\r\n \r\n !*********************************************************************************************** \r\nSUBROUTINE OriginalGuiggiani_hard(vcsio,nipp,nums,quadPt_u,quadWgt_u,&\r\n quadPt_v,quadWgt_v,coeffs,i,rNodes_field,nnpt,cjvk,z00)\r\n\r\n USE global_com,ONLY:dp,pid\r\n IMPLICIT NONE\r\n \r\n INTEGER,INTENT(IN) :: nnpt,nipp,i,nums(2)\r\n COMPLEX(kind=dp), INTENT(OUT) :: z00\r\n REAL(kind=dp), INTENT(IN)::vcsio(2),coeffs(nipp,nipp)\r\n REAL(kind=dp), INTENT(IN)::rNodes_field(3,nnpt),quadPt_u(nums(1))\r\n REAL(kind=dp), INTENT(IN)::quadPt_v(nums(2)),quadWgt_u(nums(1))\r\n REAL(kind=dp), INTENT(IN)::quadWgt_v(nums(2))\r\n COMPLEX(kind=dp), INTENT(IN) :: cjvk\r\n \r\n INTEGER :: aa,ff,uu,vv,N_uu,N_vv\r\n REAL(kind=dp)::U1(3),U2(3),nCap(3),beta(3),nCapDotR\r\n REAL(kind=dp)::etaVecS(2),eta(2),zeta(2),temp_T(2),Lij,rho\r\n REAL(kind=dp):: R_bar(3),rrr,z,thetaBarPrime,th_bar,th\r\n REAL(kind=dp)::xxu(nums(1)),xxv(nums(2)),rhoCap_th,vipps(3),vippo(3)\r\n REAL(kind=dp):: thetaBar(2,3),theta(2,3),h_alpha(3)\r\n REAL(kind=dp):: wwv(nums(2)),wwu(nums(2)),rhoCap(3)\r\n COMPLEX(kind=dp) :: z11,F_rho_th \r\n \r\n !OPEN(unit=5001,file='polar_Gauss_points.out')\r\n \r\n !parameters for 1-D gauss quadrature\r\n xxu(:) = quadPt_u\r\n xxv(:)= quadPt_v\r\n wwu(:) = quadWgt_u\r\n wwv(:)= quadWgt_v\r\n N_uu = nums(1)\r\n N_vv = nums(2)\r\n \r\n CALL calcParams(vcsio,thetaBar,h_alpha,beta,rhoCap) !Relevant quantities needed\r\n\r\n !Computing singular integral using Original Guiggiani formula\r\n z00 = 0.0_dp \r\n \r\n DO aa = 1,3 !per sub-triangle\r\n\r\n z11 = 0.0_dp\r\n \r\n !Along x direction\r\n DO uu = 1,N_uu\r\n \r\n th_bar = (thetaBar(1,aa)-thetaBar(2,aa))*xxu(uu) + thetaBar(2,aa) \r\n \r\n th = th_bar + beta(aa)\r\n \r\n rhoCap_th = h_alpha(aa)/cos(th_bar)\r\n thetaBarPrime = thetaBar(1,aa)-thetaBar(2,aa)\r\n \r\n !Along rho direction\r\n DO vv = 1,N_vv\r\n \r\n !map (rho,theta) to eta coordinates\r\n rho = rhoCap_th*xxv(vv)\r\n zeta(1) = vcsio(1) + rho*cos(th)\r\n zeta(2) = vcsio(2) + rho*sin(th)\r\n \r\n !Error detection mechanism\r\n IF ((zeta(1)<0.0_dp).OR.(zeta(2)<0.0_dp).OR.(zeta(1)>1.0_dp).OR.(zeta(2)>1.0_dp)) THEN\r\n PRINT*,\"zeta = \", zeta\r\n PRINT*,\"Error detected in zeta variable\"\r\n STOP\r\n ENDIF \r\n \r\n !unit normal evaluated at source point in the zeta plane\r\n CALL calcUnitNormal(zeta(1),zeta(2),nnpt,rNodes_field,nCap)\r\n \r\n !corresponding local distance\r\n CALL mapGaussPtTo3Ddomain(zeta(1),zeta(2),nnpt,rNodes_field,vipps)\r\n CALL mapGaussPtTo3Ddomain(vcsio(1),vcsio(2),nnpt,rNodes_field,vippo)\r\n R_bar = vippo-vipps\r\n rrr = SQRT(DOT_PRODUCT(R_bar,R_bar))\r\n nCapDotR = DOT_PRODUCT(nCap,R_bar)\r\n \r\n !basis function, Lij\r\n CALL basis_function(zeta,nipp,coeffs,i,Lij) \r\n \r\n !singular integral kernel evaluated at source point\r\n F_rho_th = nCapDotR*exp(cjvk*rrr)*(1.0_dp-cjvk*rrr)&\r\n /(4.0_dp*pid*rrr**3)*Lij*rho \r\n ! I(1) summation\r\n z11 = z11 + wwu(uu)*wwv(vv)*F_rho_th*rhoCap_th*thetaBarPrime\r\n \r\n \r\n ENDDO\r\n ENDDO\r\n \r\n z00 = z00 + z11 !Total singular integral value\r\n ENDDO\r\n \r\n RETURN\r\n \r\n \r\n CONTAINS\r\n \r\n SUBROUTINE calcParams(vcsio,thetaBar,h_alpha,beta,rhoCap)\r\n !Subroutine to find the point on the closest edge to the projected field point\r\n \r\n IMPLICIT NONE\r\n \r\n REAL(kind=dp), INTENT(IN) :: vcsio(2) \r\n REAL(kind=dp), INTENT(OUT)::beta(3),h_alpha(3),thetaBar(2,3),rhoCap(3)\r\n \r\n INTEGER :: aa\r\n REAL(kind=dp)::Rs1(3),Rs2(3),Rs3(3),R31(3),R23(3),R12(3)\r\n REAL(kind=dp)::zetaCap(3,2),nCap(3),zetaVec1(2),zetaVec2(2),zetaVec3(2),zetaVecS(2)\r\n REAL(kind=dp)::mCap(3,3),temp(3)\r\n \r\n !compute eta_2\r\n zetaVec1 = (/1.0_dp, 0.0_dp/)\r\n zetaVec2 = (/0.0_dp, 1.0_dp/)\r\n zetaVec3 = (/0.0_dp, 0.0_dp/)\r\n zetaVecS = vcsio\r\n \r\n !local unit vectors in the zeta domain\r\n zetaCap(:,1) = (/1.0_dp,0.0_dp,0.0_dp/)\r\n zetaCap(:,2) = (/0.0_dp,1.0_dp,0.0_dp/)\r\n nCap = (/0.0_dp,0.0_dp,1.0_dp/)\r\n \r\n Rs1 = (zetaVec1(1)-zetaVecS(1))*zetaCap(:,1) + (zetaVec1(2)-zetaVecS(2))*zetaCap(:,2)\r\n Rs2 = (zetaVec2(1)-zetaVecS(1))*zetaCap(:,1) + (zetaVec2(2)-zetaVecS(2))*zetaCap(:,2)\r\n Rs3 = (zetaVec3(1)-zetaVecS(1))*zetaCap(:,1) + (zetaVec3(2)-zetaVecS(2))*zetaCap(:,2)\r\n R12 = (zetaVec2(1)-zetaVec1(1))*zetaCap(:,1) + (zetaVec2(2)-zetaVec1(2))*zetaCap(:,2)\r\n R23 = (zetaVec3(1)-zetaVec2(1))*zetaCap(:,1) + (zetaVec3(2)-zetaVec2(2))*zetaCap(:,2)\r\n R31 = (zetaVec1(1)-zetaVec3(1))*zetaCap(:,1) + (zetaVec1(2)-zetaVec3(2))*zetaCap(:,2)\r\n \r\n !\r\n rhoCap=(/SQRT(DOT_PRODUCT(Rs3,Rs3)),SQRT(DOT_PRODUCT(Rs1,Rs1)),&\r\n SQRT(DOT_PRODUCT(Rs2,Rs2))/)\r\n \r\n CALL real_cross_product(R23,nCap,temp)\r\n mCap(:,1) = temp/SQRT(DOT_PRODUCT(temp,temp))\r\n \r\n CALL real_cross_product(R31,nCap,temp)\r\n mCap(:,2) = temp/SQRT(DOT_PRODUCT(temp,temp))\r\n \r\n CALL real_cross_product(R12,nCap,temp)\r\n mCap(:,3) = temp/SQRT(DOT_PRODUCT(temp,temp))\r\n \r\n h_alpha(1) = DOT_PRODUCT(Rs3,mCap(:,1))\r\n h_alpha(2) = DOT_PRODUCT(Rs1,mCap(:,2))\r\n h_alpha(3) = DOT_PRODUCT(Rs2,mCap(:,3))\r\n \r\n thetaBar(:,1) = (/ACOS(h_alpha(1)/rhoCap(1)),&\r\n -ACOS(h_alpha(1)/rhoCap(3))/)\r\n thetaBar(:,2) = (/ACOS(h_alpha(2)/rhoCap(2)),&\r\n -ACOS(h_alpha(2)/rhoCap(1))/)\r\n thetaBar(:,3) = (/ACOS(h_alpha(3)/rhoCap(3)),&\r\n -ACOS(h_alpha(3)/rhoCap(2))/)\r\n \r\n beta(3) = ACOS(DOT_PRODUCT((R31/SQRT(DOT_PRODUCT(R31,R31))),&\r\n mCap(:,3)))\r\n \r\n beta(2) = 3.0_dp/2.0_dp*pid\r\n beta(1) = beta(3) + thetaBar(1,3) + abs(thetaBar(2,1)) \r\n \r\n END SUBROUTINE calcParams \r\n \r\nEND SUBROUTINE OriginalGuiggiani_hard \r\n!*****************************************************************************************END \r\n \r\n \r\n \r\n !*********************************************************************************************** \r\nSUBROUTINE ImprovedGuiggianiMethod(vcsio,nipp,nums,quadPt_u,quadWgt_u,&\r\n quadPt_v,quadWgt_v,coeffs,i,rNodes_field,nnpt,cjvk,z00)\r\n\r\n USE global_com,ONLY:dp,pid\r\n IMPLICIT NONE\r\n \r\n INTEGER,INTENT(IN) :: nnpt,nipp,i,nums(2)\r\n COMPLEX(kind=dp), INTENT(OUT) :: z00\r\n REAL(kind=dp), INTENT(IN)::vcsio(2),coeffs(nipp,nipp)\r\n REAL(kind=dp), INTENT(IN)::rNodes_field(3,nnpt),quadPt_u(nums(1))\r\n REAL(kind=dp), INTENT(IN)::quadPt_v(nums(2)),quadWgt_u(nums(1))\r\n REAL(kind=dp), INTENT(IN)::quadWgt_v(nums(2))\r\n COMPLEX(kind=dp), INTENT(IN) :: cjvk\r\n \r\n INTEGER :: aa,ff,uu,vv,N_uu,N_vv, wrt1=1, wrt2=2, derivativeDeg=1\r\n REAL(kind=dp)::U1(3),U2(3),nCap(3),beta(3),etaVec2(2),nCapDotR\r\n REAL(kind=dp)::etaVecS(2),eta(2),zeta(2),temp_T(2),Lij0,Lij,f_1,rho\r\n REAL(kind=dp):: R_bar(3),rrr,z,sigma_z,thetaBarPrime,th_bar,th,rr0\r\n REAL(kind=dp)::xxu(nums(1)),xxv(nums(2)),rhoCap_th,vipps(3),vippo(3)\r\n REAL(kind=dp):: Z_alpha(2,3),theta(2,3),h_alpha(3),R_cap(3)\r\n REAL(kind=dp)::Det_T_1,wwu(nums(1)),wwv(nums(2)),tVec_1(2,2),rhoCap(3)\r\n COMPLEX(kind=dp) :: z11,z22,F_rho_th \r\n \r\n !parameters for 1-D gauss quadrature\r\n xxu(:) = quadPt_u\r\n xxv(:)= quadPt_v\r\n wwu(:) = quadWgt_u\r\n wwv(:)= quadWgt_v\r\n N_uu = nums(1)\r\n N_vv = nums(2)\r\n \r\n ! Column vectors of Jacobian matrix from physical to zeta plane\r\n CALL calcPosVectDerivative(derivativeDeg,wrt1,vcsio(1),vcsio(2),nnpt,&\r\n rNodes_field,U1) !dr/dZeta1\r\n CALL calcPosVectDerivative(derivativeDeg,wrt2,vcsio(1),vcsio(2),&\r\n nnpt,rNodes_field,U2) !dr/dZeta2\r\n \r\n !Relevant quantities needed\r\n CALL computeParams_IGM(U1,U2,Det_T_1,Z_alpha,etaVecS,h_alpha,tVec_1,beta,rhoCap,etaVec2)\r\n \r\n !Computing singular integral using improved Guiggiani formula\r\n \r\n z00 = 0.0_dp \r\n DO aa = 1,3 !per subtriangle\r\n z11 = 0.0_dp\r\n \r\n \r\n DO uu = 1,N_uu !Along theta direction\r\n z = (Z_alpha(1,aa)-Z_alpha(2,aa))*xxu(uu) + Z_alpha(2,aa) ! z(x)\r\n \r\n !m = 3 \r\n sigma_z = (z**3)/(z**3+(1.0_dp-z)**3) ! sigma(z) for m = 3\r\n thetaBarPrime = 3.0_dp*pid*(Z_alpha(1,aa)-Z_alpha(2,aa))*&\r\n sigma_z*((1.0_dp-z)**2)/(z*(z**3 + (1.0_dp-z)**3)) \r\n \r\n !!m = 2 \r\n !sigma_z = (z**2)/(z**2+(1.0_dp-z)**2) ! sigma(z) for m = 2\r\n !thetaBarPrime = 2.0_dp*pid*(Z_alpha(1,aa)-Z_alpha(2,aa))*sigma_z*&\r\n ! (1.0_dp-z)/(z*(z**2 + (1.0_dp-z)**2)) \r\n \r\n th_bar = pid*sigma_z - 0.5_dp*pid \r\n th = th_bar + beta(aa)\r\n \r\n rhoCap_th = h_alpha(aa)/cos(th_bar)\r\n \r\n \r\n DO vv = 1,N_vv !Along rho direction\r\n \r\n !map (rho,theta) to eta coordinates\r\n rho = rhoCap_th*xxv(vv)\r\n eta(1) = etaVecS(1) + rho*cos(th)\r\n eta(2) = etaVecS(2) + rho*sin(th)\r\n temp_T = eta\r\n \r\n !map eta to zeta plane\r\n CALL MatVecProd_real(tVec_1,2,temp_T)\r\n zeta = temp_T\r\n \r\n !Error detection mechanism\r\n IF ((zeta(1)<0.0_dp).OR.(zeta(2)<0.0_dp).OR.(zeta(1)>1.0_dp).OR.(zeta(2)>1.0_dp)) THEN\r\n PRINT*,\"zeta = \", zeta\r\n PRINT*,\"vcsio = \", vcsio\r\n PRINT*,\"Error detected in zeta variable\"\r\n STOP\r\n ENDIF \r\n \r\n !unit normal evaluated at source point in the zeta plane\r\n CALL calcUnitNormal(zeta(1),zeta(2),nnpt,rNodes_field,nCap)\r\n \r\n !corresponding local distance\r\n CALL mapGaussPtTo3Ddomain(zeta(1),zeta(2),nnpt,rNodes_field,vipps)\r\n CALL mapGaussPtTo3Ddomain(vcsio(1),vcsio(2),nnpt,rNodes_field,vippo)\r\n R_bar = vippo-vipps\r\n rrr = SQRT(DOT_PRODUCT(R_bar,R_bar))\r\n nCapDotR = DOT_PRODUCT(nCap,R_bar)\r\n \r\n !basis function, Lij\r\n CALL basis_function(zeta,nipp,coeffs,i,Lij) \r\n \r\n !singular integral kernel evaluated at source point\r\n F_rho_th = nCapDotR*exp(cjvk*rrr)*(1.0_dp-cjvk*rrr)&\r\n /(4.0_dp*pid*rrr**3)*Lij*rho\r\n \r\n ! I(1) summation\r\n z11 = z11 + wwu(uu)*wwv(vv)*F_rho_th*rhoCap_th*thetaBarPrime*Det_T_1 \r\n \r\n ENDDO\r\n ENDDO\r\n \r\n z00 = z00 + z11 !Total singular integral value\r\n ENDDO\r\n \r\n RETURN\r\n \r\n \r\n CONTAINS\r\n \r\n SUBROUTINE computeParams_IGM(U1,U2,Det_T_1,Z_alpha,etaVecS,&\r\n h_alpha,tVec_1,beta,rhoCap,etaVec2)\r\n !Subroutine to find the point on the closest edge to the projected field point\r\n \r\n IMPLICIT NONE\r\n \r\n REAL(kind=dp), INTENT(IN) :: U1(3),U2(3) \r\n REAL(kind=dp), INTENT(OUT)::Z_alpha(2,3)\r\n REAL(kind=dp), INTENT(OUT)::etaVecS(2),tVec_1(2,2)\r\n REAL(kind=dp), INTENT(OUT)::beta(3),h_alpha(3),Det_T_1\r\n REAL(kind=dp), INTENT(OUT)::rhoCap(3),etaVec2(2)\r\n \r\n INTEGER :: aa\r\n REAL(kind=dp)::Tvec(2,2),temp_T(2)\r\n REAL(kind=dp)::Rs1(3),Rs2(3),Rs3(3),R31(3),R23(3),R12(3)\r\n REAL(kind=dp)::etaCap(3,2),nCap(3),sigma(2)\r\n REAL(kind=dp)::mCap(3,3),thetaBar(2,3),temp(3),lambda,gamma\r\n \r\n !compute eta_2\r\n lambda = SQRT(DOT_PRODUCT(U1,U1))/SQRT(DOT_PRODUCT(U2,U2))\r\n gamma = ACOS(DOT_PRODUCT(U1,U2)/(SQRT(DOT_PRODUCT(U1,U1))&\r\n *SQRT(DOT_PRODUCT(U2,U2))))\r\n etaVec2 = (/(COS(gamma)/lambda), (SIN(gamma)/lambda)/)\r\n \r\n !Define transformation jacobian from zeta to eta (i.e., Tvec) and vice versa, (i.e., tvec_1)\r\n temp_T = (/-etaVec2(1)/etaVec2(2), 1.0_dp/etaVec2(2)/)\r\n tVec_1 = RESHAPE((/1.0_dp, 0.0_dp,temp_T(1),temp_T(2)/),(/2,2/))\r\n Tvec = RESHAPE((/1.0_dp,0.0_dp,etaVec2(1),etaVec2(2)/),(/2,2/))\r\n \r\n !image of singular point in the eta plane.\r\n temp_T = vcsio !singular point in the zeta plane\r\n CALL MatVecProd_real(Tvec,2,temp_T)\r\n etaVecS = temp_T\r\n \r\n !local unit vectors in the eta domain\r\n etaCap(:,1) = (/1.0_dp,0.0_dp,0.0_dp/)\r\n etaCap(:,2) = (/0.0_dp,1.0_dp,0.0_dp/)\r\n nCap = (/0.0_dp,0.0_dp,1.0_dp/)\r\n \r\n !Distance vectors\r\n Rs1 = (1.0_dp-etaVecS(1))*etaCap(:,1) - etaVecS(2)*etaCap(:,2)\r\n Rs2 = (etaVec2(1)-etaVecS(1))*etaCap(:,1) +&\r\n (etaVec2(2)-etaVecS(2))*etaCap(:,2)\r\n Rs3 = -etaVecS(1)*etaCap(:,1) - etaVecS(2)*etaCap(:,2)\r\n R12 = (etaVec2(1)-1.0_dp)*etaCap(:,1) + etaVec2(2)*etaCap(:,2)\r\n R23 = -etaVec2(1)*etaCap(:,1) - etaVec2(2)*etaCap(:,2)\r\n R31 = etaCap(:,1)\r\n \r\n rhoCap=(/SQRT(DOT_PRODUCT(Rs3,Rs3)),SQRT(DOT_PRODUCT(Rs1,Rs1)),&\r\n SQRT(DOT_PRODUCT(Rs2,Rs2))/)\r\n \r\n CALL real_cross_product(R23,nCap,temp)\r\n mCap(:,1) = temp/SQRT(DOT_PRODUCT(temp,temp))\r\n \r\n CALL real_cross_product(R31,nCap,temp)\r\n mCap(:,2) = temp/SQRT(DOT_PRODUCT(temp,temp))\r\n \r\n CALL real_cross_product(R12,nCap,temp)\r\n mCap(:,3) = temp/SQRT(DOT_PRODUCT(temp,temp))\r\n \r\n h_alpha(1) = DOT_PRODUCT(Rs3,mCap(:,1))\r\n h_alpha(2) = DOT_PRODUCT(Rs1,mCap(:,2))\r\n h_alpha(3) = DOT_PRODUCT(Rs2,mCap(:,3))\r\n \r\n CALL calcAngles(mCap,rhoCap,h_alpha,etaVecS,etaVec2,Rs1,Rs2,Rs3,R31,R23,R12,beta,thetaBar)\r\n \r\n DO aa = 1,3\r\n sigma(:) = (thetaBar(:,aa)+0.5_dp*pid)/pid\r\n \r\n !m = 2 \r\n !DO ff = 1,2\r\n ! IF (sigma(ff).EQ.0.5_dp) THEN\r\n ! Z_alpha(ff,aa) = 0.5_dp\r\n ! ELSE\r\n ! Z_alpha(ff,aa) = (sigma(ff)-sqrt(sigma(ff)-&\r\n ! sigma(ff)**2))/(2.0_dp*sigma(ff)-1.0_dp) \r\n ! ENDIF\r\n !ENDDO\r\n \r\n !m = 3\r\n Z_alpha(:,aa) = (sigma**3-sigma**2)**(1.0_dp/3.0_dp) + &\r\n (sigma**2-sigma)/((sigma**3-sigma**2)**(1.0_dp/3.0_dp))&\r\n + sigma \r\n \r\n ENDDO\r\n Det_T_1 = tVec_1(1,1)*tVec_1(2,2)-tVec_1(1,2)*tVec_1(2,1)\r\n \r\n END SUBROUTINE computeParams_IGM \r\n \r\n \r\n \r\n SUBROUTINE calcAngles(mCap,rhoCap,h_alpha,etaVecS,etaVec2,Rs1,Rs2,Rs3,R31,R23,R12,beta,thetaBar)\r\n \r\n !Subroutine to find the point on the closest edge to the projected field point\r\n \r\n IMPLICIT NONE\r\n \r\n REAL(kind=dp), INTENT(IN) :: h_alpha(3),mCap(3,3),rhoCap(3),etaVec2(2),etaVecS(2)\r\n REAL(kind=dp), INTENT(IN) :: Rs1(3),Rs2(3),Rs3(3),R31(3),R23(3),R12(3)\r\n REAL(kind=dp), INTENT(OUT):: beta(3),thetaBar(2,3)\r\n \r\n REAL(kind=dp)::theta_tot(3),psi(3),area(3),ss,area_tot \r\n REAL(kind=dp)::len_Rs1,len_Rs2,len_Rs3,len_R31,len_R23,len_R12\r\n \r\n !Lengths of the distance vectors in eta plane.\r\n len_Rs1 = SQRT(DOT_PRODUCT(Rs1,Rs1))\r\n len_Rs2 = SQRT(DOT_PRODUCT(Rs2,Rs2))\r\n len_Rs3 = SQRT(DOT_PRODUCT(Rs3,Rs3))\r\n len_R31 = SQRT(DOT_PRODUCT(R31,R31))\r\n len_R23 = SQRT(DOT_PRODUCT(R23,R23))\r\n len_R12 = SQRT(DOT_PRODUCT(R12,R12))\r\n \r\n !Angles subtended at the singular image point by each sub-triangle\r\n theta_tot(1) = ACOS((len_Rs2**2+len_Rs3**2-len_R23**2)/(2.0_dp*len_Rs2*len_Rs3))\r\n theta_tot(2) = ACOS((len_Rs1**2+len_Rs3**2-len_R31**2)/(2.0_dp*len_Rs1*len_Rs3))\r\n theta_tot(3) = ACOS((len_Rs1**2+len_Rs2**2-len_R12**2)/(2.0_dp*len_Rs1*len_Rs2))\r\n \r\n !\r\n psi(1) = ACOS((len_R31**2+len_Rs1**2-len_Rs3**2)/(2.0_dp*len_R31*len_Rs1))\r\n psi(2) = ACOS((len_Rs2**2+len_R23**2-len_Rs3**2)/(2.0_dp*len_Rs2*len_R23))\r\n psi(3) = ACOS((len_R12**2+len_Rs2**2-len_Rs1**2)/(2.0_dp*len_R12*len_Rs2))\r\n \r\n thetaBar(:,1) = (/ACOS(h_alpha(1)/rhoCap(1)),&\r\n -ACOS(h_alpha(1)/rhoCap(3))/)\r\n thetaBar(:,2) = (/ACOS(h_alpha(2)/rhoCap(2)),&\r\n -ACOS(h_alpha(2)/rhoCap(1))/)\r\n thetaBar(:,3) = (/ACOS(h_alpha(3)/rhoCap(3)),&\r\n -ACOS(h_alpha(3)/rhoCap(2))/)\r\n beta(2) = 3.0_dp/2.0_dp*pid\r\n \r\n !Calculation of beta and thetaBar based on eta-plane triangle type.\r\n IF (etaVec2(1)>1) THEN\r\n \r\n beta(3) = -ACOS(DOT_PRODUCT((R31/SQRT(DOT_PRODUCT(R31,R31))),&\r\n mCap(:,3)))\r\n \r\n IF (theta_tot(3).LE.abs(thetaBar(1,3))) THEN\r\n thetaBar(2,3) = thetaBar(1,3) - theta_tot(3)\r\n thetaBar(2,1) = -(theta_tot(1) - thetaBar(1,1))\r\n thetaBar(2,2) = -(theta_tot(2) - thetaBar(1,2))\r\n beta(1) = beta(3) + thetaBar(1,3) + abs(thetaBar(2,1))\r\n !PRINT*,\"triangle-type 1a \"\r\n \r\n ELSEIF (theta_tot(2).LE.abs(thetaBar(2,2))) THEN\r\n thetaBar(1,2) = thetaBar(2,2) + theta_tot(2)\r\n beta(1) = beta(3) + thetaBar(1,3) + abs(thetaBar(2,1))\r\n !PRINT*,\"triangle-type 1b \"\r\n \r\n ELSE\r\n thetaBar(2,3) = -(theta_tot(3) - thetaBar(1,3)) \r\n thetaBar(2,1) = -(theta_tot(1) - thetaBar(1,1))\r\n thetaBar(2,2) = -(theta_tot(2) - thetaBar(1,2))\r\n beta(1) = beta(3) + thetaBar(1,3) + abs(thetaBar(2,1))\r\n !PRINT*,\"triangle-type 1c \"\r\n ENDIF\r\n \r\n ELSEIF (etaVec2(1)<0) THEN \r\n thetaBar(2,3) = -(theta_tot(3) - thetaBar(1,3))\r\n thetaBar(2,1) = -(theta_tot(1) - thetaBar(1,1))\r\n beta(3) = ACOS(DOT_PRODUCT((R31/SQRT(DOT_PRODUCT(R31,R31))),&\r\n mCap(:,3)))\r\n \r\n IF (theta_tot(1).LE.abs(thetaBar(2,1))) THEN\r\n thetaBar(1,1) = theta_tot(1) - abs(thetaBar(2,1)) \r\n thetaBar(2,3) = -(theta_tot(3) - thetaBar(1,3))\r\n thetaBar(2,2) = -(theta_tot(2) - thetaBar(1,2))\r\n beta(1) = beta(3) + thetaBar(1,3) + abs(thetaBar(2,1))\r\n !PRINT*,\"triangle-type 2a \"\r\n \r\n ELSEIF (theta_tot(2).LE.abs(thetaBar(1,2))) THEN\r\n thetaBar(2,2) = thetaBar(1,2) - theta_tot(2)\r\n thetaBar(2,1) = -(theta_tot(1) - thetaBar(1,1))\r\n thetaBar(2,3) = -(theta_tot(3) - thetaBar(1,3)) \r\n beta(1) = beta(3) + thetaBar(1,3) + abs(thetaBar(2,1))\r\n !PRINT*,\"triangle-type 2b \" \r\n \r\n ELSE\r\n thetaBar(2,3) = -(theta_tot(3) - thetaBar(1,3)) \r\n thetaBar(2,1) = -(theta_tot(1) - thetaBar(1,1))\r\n thetaBar(2,2) = -(theta_tot(2) - thetaBar(1,2))\r\n beta(1) = beta(3) + thetaBar(1,3) + abs(thetaBar(2,1))\r\n !PRINT*,\"triangle-type 2c \"\r\n ENDIF\r\n\r\n\r\n ELSE\r\n IF (len_R23.GT.len_R12) THEN \r\n beta(3) = ACOS(DOT_PRODUCT((R31/SQRT(DOT_PRODUCT(R31,R31))),&\r\n mCap(:,3)))\r\n \r\n thetaBar(2,2) = -(theta_tot(2) - thetaBar(1,2))\r\n \r\n IF (etaVec2(2)<1) THEN\r\n \r\n IF (theta_tot(3).LE.abs(thetaBar(2,3))) THEN\r\n thetaBar(1,3) = thetaBar(2,3) + theta_tot(3)\r\n thetaBar(2,1) = -(theta_tot(1) - thetaBar(1,1))\r\n beta(1) = beta(3) + ACOS(DOT_PRODUCT(mCap(:,1),mCap(:,3))) \r\n !PRINT*,\"triangle-type 3a \"\r\n \r\n ELSEIF (theta_tot(1).LE.abs(thetaBar(1,1))) THEN\r\n thetaBar(2,1) = thetaBar(1,1) - theta_tot(1)\r\n beta(1) = beta(3) + thetaBar(1,3) - abs(thetaBar(2,1))\r\n !PRINT*,\"triangle-type 3b \" \r\n \r\n ELSE\r\n thetaBar(2,3) = -(theta_tot(3) - thetaBar(1,3)) \r\n thetaBar(2,1) = -(theta_tot(1) - thetaBar(1,1))\r\n beta(1) = beta(3) + thetaBar(1,3) + abs(thetaBar(2,1))\r\n !PRINT*,\"triangle-type 3c \"\r\n \r\n ENDIF\r\n ELSE\r\n thetaBar(2,3) = -(theta_tot(3) - thetaBar(1,3)) \r\n thetaBar(2,1) = -(theta_tot(1) - thetaBar(1,1))\r\n beta(1) = beta(3) + thetaBar(1,3) + abs(thetaBar(2,1))\r\n !PRINT*,\"triangle-type 3d \"\r\n ENDIF\r\n \r\n \r\n ELSEIF (len_R23.LT.len_R12) THEN\r\n \r\n beta(3) = ACOS(DOT_PRODUCT((R31/SQRT(DOT_PRODUCT(R31,R31))),&\r\n mCap(:,3)))\r\n \r\n thetaBar(2,2) = -(theta_tot(2) - thetaBar(1,2))\r\n \r\n IF (etaVec2(2)<1) THEN\r\n \r\n IF (theta_tot(3).LE.abs(thetaBar(2,3))) THEN\r\n thetaBar(1,3) = thetaBar(2,3) + theta_tot(3)\r\n thetaBar(2,1) = -(theta_tot(1) - thetaBar(1,1))\r\n beta(1) = beta(3) + ACOS(DOT_PRODUCT(mCap(:,1),mCap(:,3))) \r\n !PRINT*,\"triangle-type 4a \"\r\n \r\n ELSEIF (theta_tot(1).LE.abs(thetaBar(1,1))) THEN\r\n thetaBar(2,1) = thetaBar(1,1) - theta_tot(1)\r\n beta(1) = beta(3) + thetaBar(1,3) - abs(thetaBar(2,1))\r\n !PRINT*,\"triangle-type 4b \" \r\n \r\n ELSE\r\n thetaBar(2,3) = -(theta_tot(3) - thetaBar(1,3)) \r\n thetaBar(2,1) = -(theta_tot(1) - thetaBar(1,1))\r\n beta(1) = beta(3) + thetaBar(1,3) + abs(thetaBar(2,1))\r\n !PRINT*,\"triangle-type 4c \"\r\n ENDIF\r\n \r\n ELSE\r\n thetaBar(2,3) = -(theta_tot(3) - thetaBar(1,3)) \r\n thetaBar(2,1) = -(theta_tot(1) - thetaBar(1,1))\r\n beta(1) = beta(3) + thetaBar(1,3) + abs(thetaBar(2,1))\r\n !PRINT*,\"triangle-type 4d \"\r\n \r\n ENDIF\r\n ELSE\r\n beta(3) = ACOS(DOT_PRODUCT((R31/SQRT(DOT_PRODUCT(R31,R31))),&\r\n mCap(:,3)))\r\n \r\n thetaBar(2,2) = -(theta_tot(2) - thetaBar(1,2))\r\n \r\n IF (etaVec2(2)<1) THEN\r\n \r\n IF (theta_tot(3).LE.abs(thetaBar(2,3))) THEN\r\n thetaBar(1,3) = thetaBar(2,3) + theta_tot(3)\r\n thetaBar(2,1) = -(theta_tot(1) - thetaBar(1,1))\r\n beta(1) = beta(3) + ACOS(DOT_PRODUCT(mCap(:,1),mCap(:,3))) \r\n !PRINT*,\"triangle-type 5a \"\r\n ELSEIF (theta_tot(1).LE.abs(thetaBar(1,1))) THEN\r\n thetaBar(2,1) = thetaBar(1,1) - theta_tot(1)\r\n beta(1) = beta(3) + thetaBar(1,3) - abs(thetaBar(2,1))\r\n !PRINT*,\"triangle-type 5b \" \r\n ELSE\r\n thetaBar(2,3) = -(theta_tot(3) - thetaBar(1,3)) \r\n thetaBar(2,1) = -(theta_tot(1) - thetaBar(1,1))\r\n beta(1) = beta(3) + thetaBar(1,3) + abs(thetaBar(2,1))\r\n !PRINT*,\"triangle-type 5c \"\r\n ENDIF\r\n ELSE\r\n thetaBar(2,3) = -(theta_tot(3) - thetaBar(1,3)) \r\n thetaBar(2,1) = -(theta_tot(1) - thetaBar(1,1))\r\n beta(1) = beta(3) + thetaBar(1,3) + abs(thetaBar(2,1))\r\n !PRINT*,\"triangle-type 5d \"\r\n ENDIF\r\n \r\n ENDIF\r\n ENDIF\r\n \r\n !Areas of each sub-triangles and area of eta-plane triangle\r\n area(1) = 0.5_dp*len_Rs2*len_Rs3*sin(theta_tot(1))\r\n area(2) = 0.5_dp*len_Rs1*len_Rs3*sin(theta_tot(2))\r\n area(3) = 0.5_dp*len_Rs1*len_Rs2*sin(theta_tot(3))\r\n area_tot = 0.5_dp*etaVec2(2)*len_R31\r\n \r\n !Error-detection mechanism\r\n IF (abs(area_tot-sum(area)).GT.1.0E-10_dp) THEN\r\n PRINT*,\"An overlap of subtiangles detected.\"\r\n PRINT*,\"Total Area = \",area_tot\r\n PRINT*,\"sub_area1+sub_area2+sub_area3 = \",sum(area)\r\n PRINT*,\"Error detected in 'calcAngles'!!.\"\r\n STOP\r\n ENDIF \r\n \r\n END SUBROUTINE calcAngles \r\n \r\nEND SUBROUTINE ImprovedGuiggianiMethod \r\n!*****************************************************************************************END \r\n \r\n \r\n\r\n!*********************************************************************************************** \r\nSUBROUTINE calcJacobian(zeta,eta,numNodes,rNodes,J) \r\n !Subroutine for calculating the Jacobian and unit normal vector, respectively, at area coordinates:(zeta,eta) \r\n USE global_com,ONLY:dp\r\n IMPLICIT NONE\r\n \r\n INTEGER,INTENT(IN) :: numNodes\r\n REAL(kind=dp), INTENT(OUT) :: J\r\n REAL(kind=dp),INTENT(IN) :: zeta, eta, rNodes(3,numNodes)\r\n REAL(kind=dp) :: dr_bar1(3), dr_bar2(3), temp_J(3)\r\n INTEGER :: i, wrt1=1, wrt2=2, derivativeDeg=1\r\n\r\n CALL calcPosVectDerivative(derivativeDeg,wrt1,zeta,eta,numNodes,rNodes,dr_bar1)\r\n CALL calcPosVectDerivative(derivativeDeg,wrt2,zeta,eta,numNodes,rNodes,dr_bar2)\r\n \r\n CALL real_cross_product(dr_bar1,dr_bar2,temp_J) !cross-product of edge vectors\r\n J = SQRT(DOT_PRODUCT(temp_J,temp_J)) ! Jacobian\r\n \r\nEND SUBROUTINE calcJacobian \r\n!******************************************************************************************END \r\n \r\n \r\n !*********************************************************************************************** \r\nSUBROUTINE calcUnitVec(zeta,eta,numNodes,rNodes,dr_bar1,dr_bar2) \r\n !Subroutine for calculating the Jacobian and unit normal vector, respectively, at area coordinates:(zeta,eta) \r\n USE global_com,ONLY:dp\r\n IMPLICIT NONE\r\n \r\n INTEGER,INTENT(IN) :: numNodes\r\n REAL(kind=dp), INTENT(OUT) :: dr_bar1(3), dr_bar2(3)\r\n REAL(kind=dp),INTENT(IN) :: zeta, eta, rNodes(3,numNodes)\r\n REAL(kind=dp) :: temp_J(3)\r\n INTEGER :: i, wrt1=1, wrt2=2, derivativeDeg=1\r\n\r\n CALL calcPosVectDerivative(derivativeDeg,wrt1,zeta,eta,numNodes,rNodes,dr_bar1)\r\n CALL calcPosVectDerivative(derivativeDeg,wrt2,zeta,eta,numNodes,rNodes,dr_bar2)\r\n \r\nEND SUBROUTINE calcUnitVec \r\n!******************************************************************************************END \r\n \r\n \r\n\r\n !*********************************************************************************************** \r\nSUBROUTINE calcUnitNormal(zeta,eta,numNodes,rNodes,N) \r\n !Subroutine for calculating the Jacobian and unit normal vector, respectively, at area coordinates:(zeta,eta) \r\n USE global_com,ONLY:dp\r\n IMPLICIT NONE\r\n \r\n INTEGER,INTENT(IN) :: numNodes\r\n REAL(kind=dp), INTENT(OUT) :: N(3)\r\n REAL(kind=dp),INTENT(IN) :: zeta, eta, rNodes(3,numNodes)\r\n REAL(kind=dp) :: dr_bar1(3), dr_bar2(3), temp_J(3),J\r\n INTEGER :: i, wrt1=1, wrt2=2, derivativeDeg=1\r\n\r\n CALL calcPosVectDerivative(derivativeDeg,wrt1,zeta,eta,numNodes,rNodes,dr_bar1)\r\n CALL calcPosVectDerivative(derivativeDeg,wrt2,zeta,eta,numNodes,rNodes,dr_bar2)\r\n \r\n CALL real_cross_product(dr_bar1,dr_bar2,temp_J) !cross-product of edge vectors\r\n J = SQRT(DOT_PRODUCT(temp_J,temp_J)) ! Jacobian\r\n \r\n N = temp_J/J\r\n \r\nEND SUBROUTINE calcUnitNormal \r\n!******************************************************************************************END \r\n\r\n \r\n \r\n!*********************************************************************************************** \r\nSUBROUTINE calcPosVectDerivative(derivativeDeg,wrt,zeta,eta,numNodes,rNodes,dr_bar)\r\n !Subroutine for interpolating derivatives of r in terms of given nodes rNodes\r\n ! triangular patch given the area coordinates:(zeta,eta) \r\n USE global_com,ONLY:dp\r\n IMPLICIT NONE\r\n \r\n INTEGER,INTENT(IN) :: numNodes, wrt, derivativeDeg\r\n REAL(kind=dp), INTENT(OUT) :: dr_bar(3) \r\n REAL(kind=dp),INTENT(IN) :: zeta, eta, rNodes(3,numNodes)\r\n REAL(kind=dp) :: dN(numNodes) \r\n INTEGER :: i\r\n \r\n!-------------Determine the degree and type of derivative --------------------------\r\n IF (wrt == 1) THEN !derivative w.r.t zeta\r\n \r\n !First derivatives w.r.t zeta of shape functions \r\n INNER1:IF (derivativeDeg==1) THEN\r\n INNER2:IF (numNodes==6) THEN\r\n dN(1) = 4.0_dp*zeta-1.0_dp\r\n dN(2) = 0.0_dp\r\n dN(3) = -3.0_dp+4.0_dp*zeta+4.0_dp*eta\r\n dN(4) = 4.0_dp*eta\r\n dN(5) = -4.0_dp*eta\r\n dN(6) = 4.0_dp*(1.0_dp-2.0_dp*zeta-eta)\r\n ELSEIF (numNodes==3) THEN\r\n dN(1) = 1.0_dp\r\n dN(2) = 0.0_dp\r\n dN(3) = -1.0_dp\r\n ELSE \r\n PRINT*,\"1st derivatives for order > 3 or < 1, not supported for now.\"\r\n STOP\r\n ENDIF INNER2\r\n \r\n !Second derivatives w.r.t zeta of shape functions \r\n ELSEIF (derivativeDeg==2) THEN\r\n INNER3:IF (numNodes==6) THEN \r\n dN(1) = 4.0_dp\r\n dN(2) = 0.0_dp\r\n dN(3) = 4.0_dp\r\n dN(4) = 0.0_dp\r\n dN(5) = 0.0_dp\r\n dN(6) = -8.0_dp\r\n ELSEIF (numNodes==3) THEN\r\n dN(1) = 0.0_dp\r\n dN(2) = 0.0_dp\r\n dN(3) = 0.0_dp\r\n ELSE \r\n PRINT*,\"2nd derivatives for order > 3 or < 1, not supported for now.\"\r\n STOP\r\n ENDIF INNER3\r\n ELSE \r\n PRINT*,\"Derivative degrees must be <= 3.\"\r\n STOP\r\n ENDIF INNER1\r\n\r\n ELSEIF (wrt == 2) THEN !derivative w.r.t eta\r\n \r\n !First derivatives w.r.t eta of shape functions \r\n INNERa:IF (derivativeDeg==1) THEN\r\n INNERb:IF (numNodes==6) THEN \r\n dN(1) = 0.0_dp\r\n dN(2) = 4.0_dp*eta-1.0_dp\r\n dN(3) = -3.0_dp+4.0_dp*zeta+4.0_dp*eta\r\n dN(4) = 4.0_dp*zeta\r\n dN(5) = 4.0_dp*(1.0_dp-zeta-2.0_dp*eta)\r\n dN(6) = -4.0_dp*zeta\r\n ELSEIF (numNodes==3) THEN\r\n dN(1) = 0.0_dp\r\n dN(2) = 1.0_dp\r\n dN(3) = -1.0_dp\r\n ELSE \r\n PRINT*,\"1st derivatives for order > 3 or < 1, not supported for now.\"\r\n STOP\r\n ENDIF INNERb\r\n \r\n !Second derivatives w.r.t eta of shape functions \r\n ELSEIF (derivativeDeg==2) THEN\r\n INNERc:IF (numNodes==6) THEN\r\n dN(1) = 0.0_dp\r\n dN(2) = 4.0_dp\r\n dN(3) = 4.0_dp\r\n dN(4) = 0.0_dp\r\n dN(5) = -8.0_dp\r\n dN(6) = 0.0_dp\r\n ELSEIF (numNodes==3) THEN\r\n dN(1) = 0.0_dp\r\n dN(2) = 0.0_dp\r\n dN(3) = 0.0_dp\r\n ELSE \r\n PRINT*,\"2nd derivatives for order > 3 or < 1, not supported for now.\"\r\n STOP\r\n ENDIF INNERc\r\n ELSE \r\n\r\n PRINT*,\"Derivative degrees must be <= 3.\"\r\n STOP\r\n ENDIF INNERa\r\n \r\n ELSE !2nd derivative w.r.t zeta and eta\r\n IF (numNodes==6) THEN\r\n dN(1) = 0.0_dp\r\n dN(2) = 0.0_dp\r\n dN(3) = 4.0_dp\r\n dN(4) = 4.0_dp\r\n dN(5) = -4.0_dp\r\n dN(6) = -4.0_dp\r\n ELSEIF (numNodes==3) THEN\r\n dN(1) = 0.0_dp\r\n dN(2) = 0.0_dp\r\n dN(3) = 0.0_dp\r\n ELSE \r\n PRINT*,\"2nd derivatives for order > 3 or < 1, not supported for now.\"\r\n STOP\r\n ENDIF\r\n ENDIF\r\n \r\n!-----------------Compute position-vector derivative ---------------------------------\r\n dr_bar(:) = 0.0_dp !initialize variable\r\n \r\n DO i = 1,numNodes \r\n dr_bar(:) = dr_bar(:) + dN(i)*rNodes(:,i)\r\n ENDDO\r\n\r\nEND SUBROUTINE calcPosVectDerivative \r\n!******************************************************************************************END \r\n \r\n \r\n\r\n!*********************************************************************************************** \r\nSUBROUTINE mapGaussPtTo3DDOmain(zetaSrc,etaSrc,numNodes,rNodes,r)\r\n !Subroutine for interpolating r in terms of given nodes rj\r\n ! triangular patch given the area coordinates:(zetaSrc,etaSrc) \r\n USE global_com,ONLY:dp\r\n IMPLICIT NONE\r\n \r\n INTEGER,INTENT(IN) :: numNodes\r\n REAL(kind=dp), INTENT(OUT) :: r(3)\r\n REAL(kind=dp),INTENT(IN) :: zetaSrc, etaSrc, rNodes(3,numNodes)\r\n REAL(kind=dp) :: shape_func(numNodes) \r\n INTEGER :: i\r\n \r\n CALL shape_function(zetaSrc,etaSrc,numNodes,shape_func)\r\n \r\n r(:) = 0.0_dp\r\n DO i=1,numNodes\r\n r(:) = r(:) + shape_func(i)*rNodes(:,i)\r\n ENDDO\r\n \r\nEND SUBROUTINE mapGaussPtTo3DDOmain \r\n!******************************************************************************************END \r\n\r\n\r\n!********************************************************************************************** \r\nSUBROUTINE shape_function(zeta,eta,numNodes,shape_func)\r\n !Subroutine for implementing silvester-Lagrange shape function for a 1,3, & 6-node \r\n ! triangular patch given an area coordinate:(zetaSrc,eta) \r\n USE global_com,ONLY:dp\r\n IMPLICIT NONE\r\n \r\n INTEGER,INTENT(IN) :: numNodes\r\n REAL(kind=dp), INTENT(OUT) :: shape_func(numNodes)\r\n REAL(kind=dp),INTENT(IN) :: zeta, eta\r\n REAL(kind=dp) :: AreaCoords(3)\r\n \r\n AreaCoords(1) = zeta\r\n AreaCoords(2) = eta\r\n AreaCoords(3) = 1.0_dp-zeta-eta\r\n \r\n IF (numNodes==1) THEN\r\n shape_func(1) = 1.0_dp\r\n \r\n ELSEIF (numNodes==3) THEN\r\n shape_func(1) = AreaCoords(1)\r\n shape_func(2) = AreaCoords(2)\r\n shape_func(3) = AreaCoords(3)\r\n \r\n ELSEIF (numNodes==6) THEN\r\n shape_func(1) = AreaCoords(1)*(2.0_dp*AreaCoords(1)-1.0_dp)\r\n shape_func(2) = AreaCoords(2)*(2.0_dp*AreaCoords(2)-1.0_dp)\r\n shape_func(3) = AreaCoords(3)*(2.0_dp*AreaCoords(3)-1.0_dp)\r\n shape_func(4) = 4.0_dp*AreaCoords(1)*AreaCoords(2)\r\n shape_func(5) = 4.0_dp*AreaCoords(2)*AreaCoords(3)\r\n shape_func(6) = 4.0_dp*AreaCoords(1)*AreaCoords(3)\r\n \r\n ELSEIF (numNodes==10) THEN\r\n shape_func(1) = 0.5_dp*AreaCoords(1)*(3.0_dp*AreaCoords(1)-1.0_dp)*(3.0*AreaCoords(1)-2.0_dp)\r\n shape_func(2) = 0.5_dp*AreaCoords(2)*(3.0_dp*AreaCoords(2)-1.0_dp)*(3.0*AreaCoords(2)-2.0_dp)\r\n shape_func(3) = 0.5_dp*AreaCoords(3)*(3.0_dp*AreaCoords(3)-1.0_dp)*(3.0*AreaCoords(3)-2.0_dp)\r\n shape_func(4) = 9.0_dp/2.0_dp*AreaCoords(2)*AreaCoords(1)*(3.0_dp*AreaCoords(1)-1.0_dp)\r\n shape_func(5) = 9.0_dp/2.0_dp*AreaCoords(1)*AreaCoords(2)*(3.0_dp*AreaCoords(2)-1.0_dp)\r\n shape_func(6) = 9.0_dp/2.0_dp*AreaCoords(3)*AreaCoords(2)*(3.0_dp*AreaCoords(2)-1.0_dp)\r\n shape_func(7) = 9.0_dp/2.0_dp*AreaCoords(2)*AreaCoords(3)*(3.0_dp*AreaCoords(3)-1.0_dp)\r\n shape_func(8) = 9.0_dp/2.0_dp*AreaCoords(1)*AreaCoords(3)*(3.0_dp*AreaCoords(3)-1.0_dp)\r\n shape_func(9) = 9.0_dp/2.0_dp*AreaCoords(3)*AreaCoords(1)*(3.0_dp*AreaCoords(1)-1.0_dp)\r\n shape_func(10) = 27.0_dp*AreaCoords(1)*AreaCoords(2)*AreaCoords(3)\r\n\r\n \r\n ELSE\r\n PRINT*,\"Shape function undefined for order > 3 for now\"\r\n STOP\r\n ENDIF\r\n \r\n END SUBROUTINE shape_function\r\n!******************************************************************************************END \r\n\r\n \r\n!*********************************************************************************************** \r\nSUBROUTINE basis_function(zeta,numNodes,coeffs,i,basisFunc)\r\n !Subroutine for interpolating the grid-robust Lagrange basis functions at any desired (interior) point\r\n ! on a patch with area coordinates: (zeta,eta). (See G. Kang et al, 2001).\r\n \r\n USE global_com,ONLY:dp\r\n IMPLICIT NONE\r\n \r\n INTEGER,INTENT(IN) :: numNodes,i\r\n REAL(kind=dp), INTENT(OUT) :: basisFunc\r\n REAL(kind=dp), INTENT(IN) :: zeta(2),coeffs(numNodes,numNodes)\r\n INTEGER :: k\r\n REAL(kind=dp) :: polyvector(numNodes)\r\n\r\n\r\n basisFunc=0.0_dp\r\n IF(numNodes.eq.6) THEN\r\n polyvector(1)=1.0_dp\r\n polyvector(2)=zeta(1)\r\n polyvector(3)=zeta(2)\r\n polyvector(4)=zeta(1)*zeta(2)\r\n polyvector(5)=zeta(1)*zeta(1)\r\n polyvector(6)=zeta(2)*zeta(2)\r\n DO k=1,6\r\n basisFunc=basisFunc+coeffs(i,k)*polyvector(k)\r\n ENDDO\r\n ELSEIF(numNodes.eq.12) THEN\r\n polyvector(1)=1.0_dp\r\n polyvector(2)=zeta(1)\r\n polyvector(3)=zeta(2)\r\n polyvector(4)=zeta(1)*zeta(1)\r\n polyvector(5)=zeta(1)*zeta(2)\r\n polyvector(6)=zeta(2)*zeta(2)\r\n polyvector(7)=zeta(1)*zeta(1)*zeta(1)\r\n polyvector(8)=zeta(1)*zeta(1)*zeta(2)\r\n polyvector(9)=zeta(1)*zeta(2)*zeta(2)\r\n polyvector(10)=zeta(2)*zeta(2)*zeta(2)\r\n polyvector(11)=zeta(1)*zeta(1)*zeta(1)*zeta(2)\r\n polyvector(12)=zeta(1)*zeta(2)*zeta(2)*zeta(2)\r\n DO k=1,12\r\n basisFunc=basisFunc+coeffs(i,k)*polyvector(k)\r\n ENDDO\r\n ELSEIF(numNodes.eq.3) THEN\r\n polyvector(1)=1.0_dp\r\n polyvector(2)=zeta(1)\r\n polyvector(3)=zeta(2)\r\n DO k=1,3\r\n basisFunc=basisFunc+coeffs(i,k)*polyvector(k)\r\n ENDDO\r\n ELSEIF(numNodes.eq.1) THEN\r\n polyvector(1)=1.0_dp\r\n DO k=1,1\r\n basisFunc=basisFunc+coeffs(i,k)*polyvector(k)\r\n ENDDO\r\n ELSE\r\n PRINT*,\"can not set polynomial vector for higher order now\"\r\n STOP\r\n ENDIF\r\n \r\nEND SUBROUTINE basis_function \r\n!******************************************************************************************END \r\n \r\n \r\n!*********************************************************************************************** \r\nSUBROUTINE findPolyCoeffs(alphas,betas,gammas,numNodes,coeffs) \r\n USE global_com,ONLY:dp\r\n IMPLICIT NONE\r\n \r\n INTEGER,INTENT(IN) :: numNodes\r\n REAL(kind=dp), INTENT(OUT) :: coeffs(numNodes,numNodes)\r\n REAL(kind=dp), INTENT(IN) :: alphas(numNodes),betas(numNodes),gammas(numNodes)\r\n REAL(kind=dp) :: vcsis(2),vos1(2),vos2(2),vos3(2)\r\n REAL(kind=dp) :: polymatrix(numNodes,numNodes),idMat(numNodes,numNodes)\r\n INTEGER :: IPIV(numNodes),INFO,k,i\r\n \r\n vos1=(/1.0_dp,0.0_dp/) !right angle triangle vertex points in (u,v) space\t\r\n vos2=(/0.0_dp,1.0_dp/) !the first number is u value, the second number is v value\t\r\n vos3=(/0.0_dp,0.0_dp/)\r\n\r\n \r\n IF(numNodes.eq.6) THEN\r\n DO i=1,6\r\n vcsis= alphas(i)*vos1+betas(i)*vos2+gammas(i)*vos3 \r\n polymatrix(1,i)=1.0_dp\r\n polymatrix(2,i)=vcsis(1)\r\n polymatrix(3,i)=vcsis(2)\r\n polymatrix(4,i)=vcsis(1)*vcsis(2)\r\n polymatrix(5,i)=vcsis(1)*vcsis(1)\r\n polymatrix(6,i)=vcsis(2)*vcsis(2)\r\n ENDDO\r\n\r\n idMat(1:6,1:6)=0.0_dp\r\n DO k=1,6\r\n idMat(k,k)=1.0_dp\r\n ENDDO\r\n\r\n CALL dGESV(6,6,polymatrix,6,IPIV,idMat,6,INFO)\r\n\r\n ELSEIF(numNodes.eq.12) THEN\r\n DO i=1,12\r\n vcsis= alphas(i)*vos1+betas(i)*vos2+gammas(i)*vos3 \r\n polymatrix(1,i)=1.0_dp\r\n polymatrix(2,i)=vcsis(1)\r\n polymatrix(3,i)=vcsis(2)\r\n polymatrix(4,i)=vcsis(1)*vcsis(1)\r\n polymatrix(5,i)=vcsis(1)*vcsis(2)\r\n polymatrix(6,i)=vcsis(2)*vcsis(2)\r\n polymatrix(7,i)=vcsis(1)*vcsis(1)*vcsis(1)\r\n polymatrix(8,i)=vcsis(1)*vcsis(1)*vcsis(2)\r\n polymatrix(9,i)=vcsis(1)*vcsis(2)*vcsis(2)\r\n polymatrix(10,i)=vcsis(2)*vcsis(2)*vcsis(2)\r\n polymatrix(11,i)=vcsis(1)*vcsis(1)*vcsis(1)*vcsis(2)\r\n polymatrix(12,i)=vcsis(1)*vcsis(2)*vcsis(2)*vcsis(2)\r\n ENDDO\r\n\r\n idMat(1:12,1:12)=0.0_dp\r\n DO k=1,12\r\n idMat(k,k)=1.0_dp\r\n ENDDO\r\n\r\n CALL dGESV(12,12,polymatrix,12,IPIV,idMat,12,INFO)\r\n\r\n ELSEIF(numNodes.eq.3) THEN\r\n DO i=1,3\r\n vcsis= alphas(i)*vos1+betas(i)*vos2+gammas(i)*vos3 \r\n polymatrix(1,i)=1.0_dp\r\n polymatrix(2,i)=vcsis(1)\r\n polymatrix(3,i)=vcsis(2)\r\n ENDDO\r\n\r\n idMat(1:3,1:3)=0.0_dp\r\n DO k=1,3\r\n idMat(k,k)=1.0_dp\r\n ENDDO\r\n\r\n CALL dGESV(3,3,polymatrix,3,IPIV,idMat,3,INFO)\r\n\r\n ELSEIF(numNodes.eq.1) THEN\r\n DO i=1,1\r\n vcsis= alphas(i)*vos1+betas(i)*vos2+gammas(i)*vos3 \r\n polymatrix(1,i)=1.0_dp\r\n ENDDO\r\n\r\n idMat(1:1,1:1)=0.0_dp\r\n DO k=1,1\r\n idMat(k,k)=1.0_dp\r\n ENDDO\r\n\r\n CALL dGESV(1,1,polymatrix,1,IPIV,idMat,1,INFO)\r\n\r\n ELSE\r\n PRINT*,\"can not set polynomial matrix for higher order now\"\r\n STOP\r\n ENDIF\r\n \r\n coeffs(:,:) = idMat(:,:)\r\n\r\nEND SUBROUTINE findPolyCoeffs \r\n!******************************************************************************************END \r\n \r\n \r\n \r\n \r\n \r\n\r\n ", "meta": {"hexsha": "dd07aa4edcd1cf4880e1066d29dcc33bff5d0e57", "size": 48203, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/applications/acoustic/acoustic-kernel/curve_para.f90", "max_stars_repo_name": "wawando/stars-h", "max_stars_repo_head_hexsha": "03e11375bf559bc850243c4c38796be21112a5f4", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-11-22T22:28:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-09T07:35:59.000Z", "max_issues_repo_path": "src/applications/acoustic/acoustic-kernel/curve_para.f90", "max_issues_repo_name": "wawando/stars-h", "max_issues_repo_head_hexsha": "03e11375bf559bc850243c4c38796be21112a5f4", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-11-04T01:10:54.000Z", "max_issues_repo_issues_event_max_datetime": "2020-11-08T20:01:54.000Z", "max_forks_repo_path": "src/applications/acoustic/acoustic-kernel/curve_para.f90", "max_forks_repo_name": "wawando/stars-h", "max_forks_repo_head_hexsha": "03e11375bf559bc850243c4c38796be21112a5f4", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2017-11-12T16:28:00.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T18:08:24.000Z", "avg_line_length": 41.4471195185, "max_line_length": 115, "alphanum_fraction": 0.460178827, "num_tokens": 14438, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278726384089, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.6998588015955332}} {"text": "program euler226\n integer, parameter :: dp = selected_real_kind(15,307)\n real(dp) :: x, dx, F\n\n x = lower_bound()\n dx = (0.5 - x)/50000.0\n F = 0.0\n do while(x < 0.5)\n F = F + dx*something()\n end do !- \n print *,\"The area of overlap is %0.8f\",F\n\ncontains\n !> finds the lower bound for integrating\n real(dp) function lower_bound()\n real(dp) :: p, q, r\n p = 0.0\n q = 0.5\n do while (abs(p-q) > 1e-15)\n r = 0.5*(q + p)\n f = something()\n g = something()\n h = something()\n if (f*h < 0.0) then\n q = r\n else if (g*h < 0.0) then\n p = r\n end if\n end do !-\n lower_bound = 0.5*(q + p)\n end function lower_bound\n \n !> snipped out relevant function(s)\nend program euler226\n", "meta": {"hexsha": "5bbffe3e08f126050e2773842ddc9b086ab4b7f3", "size": 797, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "euler_226.f90", "max_stars_repo_name": "kylekanos/ProjectEuler", "max_stars_repo_head_hexsha": "bfdbda0a9a83af45b92c47439f657d11df785527", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-05-13T03:36:23.000Z", "max_stars_repo_stars_event_max_datetime": "2016-05-13T03:36:23.000Z", "max_issues_repo_path": "euler_226.f90", "max_issues_repo_name": "kylekanos/ProjectEuler", "max_issues_repo_head_hexsha": "bfdbda0a9a83af45b92c47439f657d11df785527", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "euler_226.f90", "max_forks_repo_name": "kylekanos/ProjectEuler", "max_forks_repo_head_hexsha": "bfdbda0a9a83af45b92c47439f657d11df785527", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.7714285714, "max_line_length": 56, "alphanum_fraction": 0.4993726474, "num_tokens": 270, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544911, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.6998587880604801}} {"text": "program main\n use plantFEM\n implicit none\n\n real(real64),parameter :: dt = 0.010d0\n type(Random_) :: random\n type(IO_) :: f,z\n type(Math_) :: Math\n integer(int32) :: i\n complex(kind(0d0) ),allocatable :: wave(:),spectre(:)\n \n\n wave = zeros(4096)\n do i=1, size(wave)\n wave(i) = random%gauss(mu=0.0d0, sigma=1.0d0)\n wave(i) = sin( dt*dble(i) )+sin( 3.0d0*dt*dble(i) )+random%gauss(mu=0.0d0, sigma=1.0d0)\n enddo\n \n call f%open(\"gauss.txt\")\n call f%write( real(wave) )\n call f%close()\n\n spectre = zeros(1024 )\n spectre = FFT(wave)\n call z%open(\"spectre.txt\")\n do i=1,size(spectre)/2\n call z%write( sqrt( spectre(i)*spectre(i) ))\n enddo\n call z%close()\n\n \nend program main", "meta": {"hexsha": "af489561248e1fb086c87f96a359f66ec683d456", "size": 761, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/std/simpleFFT.f90", "max_stars_repo_name": "kazulagi/plantFEM", "max_stars_repo_head_hexsha": "20bf2df8202d41aa5dc25d1cc820385dabbc604f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2020-06-21T08:21:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-13T04:28:30.000Z", "max_issues_repo_path": "Tutorial/std/simpleFFT.f90", "max_issues_repo_name": "kazulagi/plantFEM", "max_issues_repo_head_hexsha": "20bf2df8202d41aa5dc25d1cc820385dabbc604f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-05-08T05:20:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T05:39:29.000Z", "max_forks_repo_path": "Tutorial/std/simpleFFT.f90", "max_forks_repo_name": "kazulagi/plantFEM", "max_forks_repo_head_hexsha": "20bf2df8202d41aa5dc25d1cc820385dabbc604f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-10-20T18:28:59.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-15T08:35:25.000Z", "avg_line_length": 23.78125, "max_line_length": 95, "alphanum_fraction": 0.5703022339, "num_tokens": 274, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380482, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.6997915007319854}} {"text": "function julday(dd,mm,yyyy)\n!\nimplicit none\n!\n! PARAMETER definitions\n!\ninteger,parameter :: igreg = 15 + 31*(10+12*1582)\n!\n! Dummy arguments\n!\ninteger :: dd,mm,yyyy\ninteger :: julday\n!\n! Local variables\n!\nreal*8 :: dble\ninteger :: int\ninteger :: ja,jm,jy,y_nw\n!\n! + + + purpose + + +\n! in this routine julday returns the julian day number which begins at\n! noon of the calendar date specified by day \"dd\", month \"mm\", & year \"yyyy\"\n! all are integer variables. positive year signifies a.d.; negative, b.c.\n! remember that the year after 1 b.c. was 1 a.d.\n \n! the following invalid calendar dates are checked for and reported:\n! 1. zero year\n! 2. dates between 4/10/1582 and 15/10/1582 are specified.\n!\n! additional checking for other invalid dates could be added\n! in the future if necessary.\n!\n! + + + keywords + + +\n! date, utility\n!\n! + + + argument declarations + + +\n!\n! + + + argument definitions + + +\n! dd - integer value of day in the range 1-31\n! julday - value returned by the julday function. debe added 09/09/09\n! mm - integer value of month in the range 1-12\n! yyyy - integer value of year (negative a.d., positive b.c.)\n!\n! + + + parameters + + +\n! gregorian calendar was adopted on oct. 15, 1582.\n!\n! + + + local variable definitions + + +\n! dble -\n! int -\n! ja -\n! jm -\n! jy -\n! y_nw -\n \n! + + + end specifications + + +\n!\nif (yyyy==0) write (*,*) 'there is no year zero'\nif ((yyyy==1582).and.(mm==10).and.(dd<15).and.(dd>4)) write (*,*) &\n & 'this is an invalid date'\nif (yyyy<0) then\n y_nw = yyyy + 1\nelse\n y_nw = yyyy\nend if\nif (mm>2) then\n jy = y_nw\n jm = mm + 1\nelse\n jy = y_nw - 1\n jm = mm + 13\nend if\njulday = int(365.25*jy) + int(30.6001*jm) + dd + 1720995\nif (dd+31*(mm+12*y_nw)>=igreg) then\n ja = jy/100\n! ja=int(dble(0.01)*dble(jy))\n julday = julday + 2 - ja + int(dble(0.25)*dble(ja))\nend if\n!\nend function julday\n", "meta": {"hexsha": "6f17318037fc758abefb57fdfad3d99954650754", "size": 1988, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Source Code/julday.f90", "max_stars_repo_name": "USDA-ARS-WMSRU/upgm-standalone", "max_stars_repo_head_hexsha": "1ae5dee5fe2cdba97b69c19d51b1cf61ceeab3d7", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Source Code/julday.f90", "max_issues_repo_name": "USDA-ARS-WMSRU/upgm-standalone", "max_issues_repo_head_hexsha": "1ae5dee5fe2cdba97b69c19d51b1cf61ceeab3d7", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Source Code/julday.f90", "max_forks_repo_name": "USDA-ARS-WMSRU/upgm-standalone", "max_forks_repo_head_hexsha": "1ae5dee5fe2cdba97b69c19d51b1cf61ceeab3d7", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.85, "max_line_length": 81, "alphanum_fraction": 0.597082495, "num_tokens": 670, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380482, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.6997915007319854}} {"text": "program main\n\n use array_utils, only: diagonal, norm\n use davidson, only: generalized_eigensolver\n use numeric_kinds, only: dp\n use test_utils, only: read_matrix\n\n implicit none\n\n integer, parameter :: dim = 864\n integer, parameter :: lowest = 6\n real(dp), dimension(lowest) :: eigenvalues_DPR, eigenvalues_GJD, expected\n real(dp), dimension(dim, lowest) :: eigenvectors_DPR, eigenvectors_GJD\n real(dp), dimension(dim, dim) :: mtx\n integer :: iter_i\n\n mtx = read_matrix(\"../src/tests/data/bse_singlet.dat\", dim)\n\n print *, \"DPR Method\"\n call generalized_eigensolver(mtx, eigenvalues_DPR, eigenvectors_DPR, lowest, \"DPR\", 50, 1d-4, iter_i, lowest*3)\n\n expected = [0.30445426, 0.31341032, 0.31360998, 0.33246853, 0.34212415, 0.35761287]\n\n print \"(a, i2)\", \"steps to convergence: \", iter_i\n print \"(a, 6f8.4)\", \"Eigenvalues:\", eigenvalues_DPR\n print \"(a, e10.3)\", \"Relative error with expected eigenvalues: \", norm(eigenvalues_DPR - expected)\n\n print *, \"GJD Method\"\n\n call generalized_eigensolver(mtx, eigenvalues_GJD, eigenvectors_GJD, lowest, \"GJD\", 10, 1d-4, iter_i, lowest*2)\n\n print \"(a, i2)\", \"steps to convergence: \", iter_i\n print \"(a, 6f8.4)\", \"Eigenvalues:\", eigenvalues_GJD\n print \"(a, e10.3)\", \"Relative error with expected eigenvalues: \", norm(eigenvalues_GJD - expected)\n \nend program main\n", "meta": {"hexsha": "890c81fec5924a5de3103bb288a4e0f5a8baae76", "size": 1326, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/test_reorder.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_reorder.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_reorder.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": 35.8378378378, "max_line_length": 113, "alphanum_fraction": 0.7111613876, "num_tokens": 434, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380481, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.6997915007319853}} {"text": "! { dg-do run }\n! Tests the fix for PR28496 in which initializer array constructors with\n! a missing initial array index would cause an ICE.\n!\n! Test for the fix of the initializer array constructor part of PR29975\n! was added later. Here, the indexing would get in a mess if the array\n! specification had a lower bound other than unity.\n!\n! Contributed by Paul Thomas \n! Based on original test case from Samir Nordin \n!\n integer, dimension(3), parameter :: a=(/1,2,3/)\n integer, dimension(3), parameter :: b=(/a(:)/)\n integer, dimension(3,3), parameter :: c=reshape ((/(i, i = 1,9)/),(/3,3/))\n integer, dimension(2,3), parameter :: d=reshape ((/c(3:2:-1,:)/),(/2,3/))\n integer, dimension(3,3), parameter :: e=reshape ((/a(:),a(:)+3,a(:)+6/),(/3,3/))\n integer, dimension(2,3), parameter :: f=reshape ((/c(2:1:-1,:)/),(/2,3/))\n CHARACTER (LEN=1), DIMENSION(3:7), PARAMETER :: g = &\n (/ '+', '-', '*', '/', '^' /)\n CHARACTER (LEN=3) :: h = \"A+C\"\n!\n! PR28496\n!\n if (any (b .ne. (/1,2,3/))) call abort ()\n if (any (reshape(d,(/6/)) .ne. (/3, 2, 6, 5, 9, 8/))) call abort () \n if (any (reshape(f,(/6/)) .ne. (/2, 1, 5, 4, 8, 7/))) call abort () \n!\n! PR29975\n!\n IF (all(h(2:2) /= g(3:4))) call abort ()\nend\n", "meta": {"hexsha": "ef30b84d409176bb80d31b299eedf33ef5dfbff1", "size": 1262, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/array_initializer_2.f90", "max_stars_repo_name": "maurizioabba/rose", "max_stars_repo_head_hexsha": "7597292cf14da292bdb9a4ef573001b6c5b9b6c0", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/array_initializer_2.f90", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/array_initializer_2.f90", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 39.4375, "max_line_length": 82, "alphanum_fraction": 0.588748019, "num_tokens": 459, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.839733983715524, "lm_q2_score": 0.8333245891029456, "lm_q1q2_score": 0.6997709769355186}} {"text": " double precision function DSVAL ( K, NC, T, BCOEF, X, IDERIV )\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc>> 1994-10-20 DSVAL Krogh Changes to use M77CON\nc>> 1994-09-26 DSVAL CLL Moved \"DSVAL = ZERO\" to be 1st executable stmt.\nc>> 1992-11-12 C. L. Lawson, JPL Saving LEFTI.\nc>> 1992-10-27 C. L. Lawson, JPL\nc>> 1988-03-15 C. L. Lawson, JPL\nC Calculates the value at X of the derivative of order IDERIV\nc of the spline function represented in B-spline form by\nc K, NC, T(), and BCOEF().\nc\nc Based on subroutine BVALUE on pp. 144-145 of A PRACTICAL GUIDE TO\nc SPLINES by Carl De Boor, Springer-Verlag, 1978.\nc Current version by C. L. Lawson, JPL, March 1988.\nc ------------------------------------------------------------------\nc K [in] Order of the spline functions. Note that the polynomial\nc degree of the segments of the spline is one less than the\nc order. Example: Cubic splines have order K = 4.\nc NC [in] Number of B-spline coefficients. Require NC .ge. 1.\nC T() [in] Knot sequence, indexed from 1 to NT, with\nc NT = NC + K. Knot values must be nonincreasing.\nc Repetition of values is permitted and has the effect of\nc decreasing the order of contimuity at the repeated knot.\nc Proper function representation by splines of order K is\nc supported on the interval from T(K) to T(NC+1).\nc Extrapolation can be done outside this interval.\nc BCOEF() [in] Coefficients of B-spline basis functions, indexed from\nc 1 to NC.\nc X [in] Abcissa at which the spline function or one of its\nc derivatives is to be evaluated. The evaluation will use one\nc of the polynomial pieces of the spline as follows:\nc If X .lt. T(K+1) use the piece associated with [T(K),T(K+1))\nc If T(L) .le. X .lt. T(L+1) for some L in [K+1, NC-1] use the\nc piece associated with [T(L),T(L+1)).\nc If T(NC) .le. X use the piece associated with\nc [T(NC),T(NC+1)].\nc IDERIV [in] Order of derivative to be evaluated. IDERIV = 0\nc selects evaluation of the spline function. Require\nc IDERIV .ge. 0. All derivatives of orders .ge. K will be zero.\nc DSVAL [out] Returned value of the spline function or its requested\nc derivative.\nc ------------------------------------------------------------------\nc--D replaces \"?\": ?SVAL, ?SFIND\nc ------------------------------------------------------------------\n integer KMAX\n parameter(KMAX = 20)\n integer IDERIV, IDERP1, IHI, ILO, IMK, IP1\n integer J, JJ, K, KM1, KMIDER, KMJ, LEFTI, MODE, NC\n double precision AJ(KMAX), BCOEF(NC)\n double precision DP(KMAX), DM(KMAX), FKMJ, T(NC+K), X, ZERO\n parameter(ZERO=0.0D0)\n save LEFTI\n data LEFTI / 1 /\nc ------------------------------------------------------------------\n DSVAL = ZERO\n if(K .gt. KMAX) then\n call IERM1('DSVAL',1,2,'Require KORDER .le. KMAX.',\n * 'KORDER',K,',')\n call IERV1('KMAX',KMAX,'.')\n return\n endif\n KMIDER = K - IDERIV\n if (KMIDER .LE. 0) GO TO 99\nC\nc If T(K) .le. X .lt. NC+1, DSFIND will return LEFTI such that\nC T(LEFTI) .le. X .lt. T(LEFTI+1).\nc Otherwise if X .lt. T(K), sets LEFTI := K\nc or if X .ge. T(NC+1), sets LEFTI := NC.\nc\n KM1 = K-1\n call DSFIND (T, K, NC+1, X, LEFTI, MODE )\nc\nc MODE = -1 if X < T(K)\nc 0 if T(1) .le. X .le. T(NC+1)\nc +1 if T(NC+1) .lt. X\nc\nC *** DIFFERENCE THE COEFFICIENTS *IDERIV* TIMES .\n IMK = LEFTI-K\n do 21 J=1,K\n AJ(J) = BCOEF(IMK+J)\n 21 continue\n do 25 J=1,IDERIV\n KMJ = K-J\n FKMJ = dble(KMJ)\n do 23 JJ=1,KMJ\n IHI = LEFTI + JJ\n AJ(JJ) = (AJ(JJ+1) - AJ(JJ))/(T(IHI) - T(IHI-KMJ))*FKMJ\n 23 continue\n 25 continue\nC\nC *** COMPUTE VALUE AT *X* IN (T(I),T(I+1)) OF IDERIV-TH DERIVATIVE,\nC GIVEN ITS RELEVANT B-SPLINE COEFF. IN AJ(1),...,AJ(K-IDERIV).\nc\n if (IDERIV .ne. KM1) then\n IP1 = LEFTI+1\n do 32 J=1,KMIDER\n DP(J) = T(LEFTI+J) - X\n DM(J) = X - T(IP1-J)\n 32 continue\n IDERP1 = IDERIV+1\n do 35 J=IDERP1,KM1\n KMJ = K-J\n ILO = KMJ\n do 33 JJ=1,KMJ\n AJ(JJ) = (AJ(JJ+1)*DM(ILO) + AJ(JJ)*DP(JJ))/\n * (DM(ILO)+DP(JJ))\n ILO = ILO - 1\n 33 continue\n 35 continue\n endif\n DSVAL = AJ(1)\nC\n 99 continue\n return\n end\n", "meta": {"hexsha": "d200326573d399b84605aab681169bee904722ba", "size": 4705, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/dsval.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/dsval.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/dsval.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.8728813559, "max_line_length": 72, "alphanum_fraction": 0.54282678, "num_tokens": 1540, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391624034103, "lm_q2_score": 0.8104789178257654, "lm_q1q2_score": 0.6997607091069898}} {"text": "program compute_pi\n use, intrinsic :: iso_fortran_env, only : I8 => INT64\n implicit none\n real, parameter :: PI = acos(-1.0)\n integer(kind=I8), parameter :: nr_tries = 500000000\n integer(kind=I8) :: nr_success, i\n integer :: num_threads = 1, thread_num = 0\n real :: x, y\n\n nr_success = 0\n do i = 1, nr_tries\n call random_number(x)\n call random_number(y)\n if (x**2 + y**2 <= 1.0) nr_success = nr_success + 1\n end do\n print '(A, F10.7)', 'sampled pi = ', 4.0*real(nr_success)/real(nr_tries)\n print '(A, F10.7)', 'real pi = ', PI\nend program compute_pi\n", "meta": {"hexsha": "806687528db59cbf4ee737cb5a04845239ca13ed", "size": 607, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "scenarios/Week_05/OpenMP/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": "scenarios/Week_05/OpenMP/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": "scenarios/Week_05/OpenMP/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": 31.9473684211, "max_line_length": 76, "alphanum_fraction": 0.6013179572, "num_tokens": 204, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582632076909, "lm_q2_score": 0.7520125848754472, "lm_q1q2_score": 0.6997163236335349}} {"text": " FUNCTION bessi(n,x)\r\n INTEGER n,IACC\r\n REAL bessi,x,BIGNO,BIGNI\r\n PARAMETER (IACC=40,BIGNO=1.0e10,BIGNI=1.0e-10)\r\nCU USES bessi0\r\n INTEGER j,m\r\n REAL bi,bim,bip,tox,bessi0\r\n if (n.lt.2) pause 'bad argument n in bessi'\r\n if (x.eq.0.) then\r\n bessi=0.\r\n else\r\n tox=2.0/abs(x)\r\n bip=0.0\r\n bi=1.0\r\n bessi=0.\r\n m=2*((n+int(sqrt(float(IACC*n)))))\r\n do 11 j=m,1,-1\r\n bim=bip+float(j)*tox*bi\r\n bip=bi\r\n bi=bim\r\n if (abs(bi).gt.BIGNO) then\r\n bessi=bessi*BIGNI\r\n bi=bi*BIGNI\r\n bip=bip*BIGNI\r\n endif\r\n if (j.eq.n) bessi=bip\r\n11 continue\r\n bessi=bessi*bessi0(x)/bi\r\n if (x.lt.0..and.mod(n,2).eq.1) bessi=-bessi\r\n endif\r\n return\r\n END\r\n", "meta": {"hexsha": "42b7014e83b5741e95af495a663205296dcc1c96", "size": 841, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/bessi.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/bessi.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/bessi.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.4848484848, "max_line_length": 53, "alphanum_fraction": 0.4696789536, "num_tokens": 313, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.930458263207691, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6997163132908866}} {"text": " SUBROUTINE PCGNS(NN,AA,LENAA,MAXA,PP,RHO,START,WORK,IFLAG)\nC\nC This subroutine solves a system of equations using the method\nC of Conjugate Gradients.\nC \nC The system to be solved is in the form Bx=b, where\nC\nC +-- --+ +- -+ \nC | | | | | T = START(k), where \nC | AA | -PP | | -RHO | \nC B = | | | , b = | | |START(k)|= max |START(i)|\nC +--------+-----+ +------+ 1<=i<=NN+1\nC | E(k)**t | | T | \nC +-- --+ +- -+\nC\nC AA is an (NN x NN) symmetric matrix, PP, RHO are (NN x 1) vectors, \nC b is of length NN+1 and E(k)**t is the ( 1 x (NN+1) ) vector \nC consisting of all zeros, except for a '1' in its k-th position.\nC It is assumed that rank [AA,-PP]=NN and B is invertible.\nC\nC The system is solved by splitting B into two matrices M and L, where\nC\nC +- -+ +- -+\nC | | | | |\nC | AA | c | | -PP-c |\nC M = | | | , L = u * [E(NN+1)**t], u = | | ,\nC +------+---+ +-------+\nC | c | d | | 0 |\nC +- -+ +- -+\nC\nC E(NN+1) is the (NN+1) x 1 vector consisting of all zeros except for\nC a '1' in its last position, and x**t is the transpose of x.\nC\nC The final solution vector, x, is given by\nC\nC +- -+\nC | [sol(u)]*[E(NN+1)**t] |\nC x = | I - ----------------------------- | * sol(b)\nC | {[(sol(u))**t]*E(NN+1)}+1.0 |\nC +- -+\nC\nC where sol(a)=[M**(-1)]*a. The two systems (Mz=u, Mz=b) are solved\nC by a preconditioned conjugate gradient algorithm.\nC\nC \nC \nC Input variables: \nC\nC NN -- dimension of the matrix packed in AA.\nC\nC AA -- one dimensional real array containing the leading NN x NN\nC submatrix of B in packed skyline storage form.\nC\nC LENAA -- number of elements in the packed array AA.\nC\nC MAXA -- integer array used for specifying information about AA.\nC Using packed skyline storage, it has length NN+2, and\nC stores the indices of the diagonal elements within AA.\nC MAXA(NN+1) = LENAA + 1 and MAXA(NN+2) = LENAA + NN + 3 - k\nC (k as defined above) by convention.\nC (NOTE: The value of MAXA(NN+2) is set by this \nC subroutine when the preconditioning matrix Q is \nC initialized.)\nC\nC For example, using the packed storage scheme,\nC a symmetric 5 x 5 matrix of the form\nC\nC +-- --+\nC | 1 3 0 0 0 |\nC | 3 2 0 7 0 |\nC | 0 0 4 6 0 |\nC | 0 7 6 5 9 |\nC | 0 0 0 9 8 |\nC +-- --+\nC\nC would result in NN=5, LENAA=9, MAXA=(1,2,4,5,8,10,*),\nC and AA=(1,2,3,4,5,6,7,8,9).\nC\nC PP -- vector of length NN, used for (NN+1)st column of \nC augmented matrix B .\nC\nC RHO -- vector of length NN, negative of top part of right hand\nC side b .\nC\nC START -- vector of length NN+1, normally the solution to the\nC previous linear system; used to determine the index k .\nC\nC Output variables:\nC\nC START -- solution vector x of B x = b (defined above).\nC\nC IFLAG -- normally unchanged on output. If the conjugate gradient\nC iteration fails to converge in 10*(NN+1) iterations (most\nC likely due to a singular Jacobian matrix), PCGNS returns\nC with IFLAG = 4 , and does not compute x.\nC\nC Working storage:\nC\nC WORK -- array of length 6*(NN+1) + LENAA :\nC\nC WORK(1..NN+1) = temporary working storage;\nC\nC WORK(NN+2..2NN+2) = intermediate solution vector z for Mz=u,\nC input value is used as initial estimate for z;\nC\nC WORK(2NN+3..3NN+3) = intermediate solution vector z for Mz=b,\nC input value is used as initial estimate for z;\nC\nC WORK(3NN+4..4NN+4) = storage for residual vectors;\nC\nC WORK(4NN+5..5NN+5) = storage for direction vectors;\nC\nC WORK(5NN+6.. * ) = storage for the preconditioning matrix\nC Q, normally of length LENAA+NN+1. A storage scheme for Q\nC (and AA) other than the default packed skyline storage\nC scheme can be accomodated by simply extending the length\nC of WORK (and MAXA), and prodiving different versions of\nC the subroutines MULTDS, MFACDS, and QIMUDS.\nC\nC\nC Three user-defined subroutines are required:\nC\nC MULTDS(y,AA,x,MAXA,NN,LENAA) -- computes y = AA x .\nC\nC MFACDS(NN,Q,LENAA,MAXA) -- computes the preconditioning matrix\nC Q based on M. A copy of AA is placed in Q before the call; \nC after the call, it is assumed that Q contains some factorization\nC for the preconditioning matrix Q. If no preconditioning is \nC required, MFACDS may be a dummy subroutine.\nC\nC QIMUDS(Q,f,MAXA,NN,LENAA) -- computes f := [Q**(-1)]*f for any \nC vector f, given the factorization of Q produced by subroutine\nC MFACDS. Again, if no preconditioning is required, QIMUDS\nC may be a dummy subroutine.\nC\nC\nC Subroutines and functions called:\nC\nC BLAS -- DAXPY, DCOPY, DDOT, DNRM2, DSCAL, IDAMAX\nC D1MACH,MULTDS,MFACDS,QIMUDS\nC\nC\n INTEGER IFLAG,IMAX,IND,J,K,LENAA,NN,MAXA(NN+2),NP1,NP2,N2P3,\n & N3P4,N4P5,N5P6\n DOUBLE PRECISION AA(LENAA),AB,AU,BB,BU,DZNRM,PBNPRD,PP(NN),\n & PUNPRD,RBNPRD,RBTOL,RHO(NN),RNPRD,RUNPRD,RUTOL,\n & START(NN+1),STARTK,TEMP,UNRM,WORK(5*(NN+1)+LENAA+NN+1),\n & ZLEN,ZTOL\n LOGICAL STILLU,STILLB\nC\n DOUBLE PRECISION D1MACH,DDOT,DNRM2\n INTEGER IDAMAX\nC\nC\nC SET UP BASES FOR VECTORS STORED IN WORK ARRAY.\nC\n NP1=NN+1\n NP2=NN+2\n N2P3=(2*NN)+3\n N3P4=(3*NN)+4\n N4P5=(4*NN)+5\n N5P6=(5*NN)+6\nC\nC FIND THE ELEMENT OF LARGEST MAGNITUDE IN THE INITIAL VECTOR, AND\nC RECORD ITS POSITION IN K.\nC\n K=IDAMAX(NP1,START,1)\n STARTK=START(K)\nC\nC INITIALIZE Q, SET VALUES OF MAXA(NN+1) AND MAXA(NN+2),\nC COMPUTE PRECONDITIONER.\nC\n CALL DCOPY(LENAA,AA,1,WORK(N5P6),1)\n MAXA(NN+1)=LENAA+1\n MAXA(NN+2)=LENAA+NN+3-K\n CALL MFACDS(NN,WORK(N5P6),LENAA,MAXA)\nC\nC COMPUTE ALL TOLERANCES NEEDED FOR EXIT CRITERIA.\nC\n CALL DCOPY(NN,PP,1,WORK,1)\n IF (K .LT. NP1) WORK(K)=WORK(K)+1.0D0\n UNRM=DNRM2(NN,WORK,1)\nC\n IMAX=10*NP1\n STILLU=.TRUE.\n STILLB=.TRUE.\n ZTOL=100.0*D1MACH(4)\n RBTOL=ZTOL*SQRT(STARTK**2 + DNRM2(NN,RHO,1)**2)\n RUTOL=ZTOL*UNRM\nC\nC COMPUTE INITIAL RESIDUAL VECTOR FOR THE SYSTEM M z = u .\nC\n CALL MULTDS(WORK(N3P4),AA,WORK(NP2),MAXA,NN,LENAA)\n WORK(N3P4+NN)=WORK(NP2+K-1)\n IND=N3P4+K-1\n IF (K .LT. NP1) WORK(IND)=WORK(IND)+WORK(NP2+NN)\n CALL DSCAL(NP1,-1.0D0,WORK(N3P4),1)\n CALL DAXPY(NN,-1.0D0,PP,1,WORK(N3P4),1)\n IF (K .LT. NP1) WORK(IND)=WORK(IND)-1.0D0\n CALL QIMUDS(WORK(N5P6),WORK(N3P4),MAXA,NN,LENAA)\nC\nC COMPUTE INITIAL DIRECTION VECTOR, ALL INNER PRODUCTS FOR M z = u .\nC\n CALL DCOPY(NP1,WORK(N3P4),1,WORK,1)\n CALL QIMUDS(WORK(N5P6),WORK,MAXA,NN,LENAA)\n CALL MULTDS(WORK(N4P5),AA,WORK,MAXA,NN,LENAA)\n WORK(N4P5+NN)=WORK(K)\n IF (K .LT. NP1) WORK(N4P5+K-1)=WORK(N4P5+K-1)+WORK(NP1)\nC\n RUNPRD=DDOT(NP1,WORK(N3P4),1,WORK(N3P4),1)\n PUNPRD=DDOT(NP1,WORK(N4P5),1,WORK(N4P5),1)\nC\n J=1\nC\nC DO WHILE ((STILLU) .AND. (J .LE. IMAX))\n100 IF (.NOT. ((STILLU) .AND. (J .LE. IMAX)) ) GO TO 200\nC\nC IF ||RESIDUAL|| IS STILL NOT SMALL ENOUGH, CONTINUE.\n IF (SQRT(RUNPRD) .GT. RUTOL) THEN\n IF (PUNPRD .EQ. 0.0) THEN\n CALL MULTDS(WORK(N3P4),AA,WORK(NP2),MAXA,NN,LENAA)\n WORK(N3P4+NN)=WORK(NP2+K-1)\n IND=N3P4+K-1\n IF (K .LT. NP1) WORK(IND)=WORK(IND)+WORK(NP2+NN)\n CALL DSCAL(NP1,-1.0D0,WORK(N3P4),1)\n CALL DAXPY(NN,-1.0D0,PP,1,WORK(N3P4),1)\n IF (K .LT. NP1) WORK(N3P4+K-1)=WORK(N3P4+K-1)-1.0D0\n CALL QIMUDS(WORK(N5P6),WORK(N3P4),MAXA,NN,LENAA)\n CALL DCOPY(NP1,WORK(N3P4),1,WORK,1)\n CALL QIMUDS(WORK(N5P6),WORK,MAXA,NN,LENAA)\n CALL MULTDS(WORK(N4P5),AA,WORK,MAXA,NN,LENAA)\n WORK(N4P5+NN)=WORK(K)\n IND=N4P5+K-1\n IF (K .LT. NP1) WORK(IND)=WORK(IND)+WORK(NP1)\n RUNPRD=DDOT(NP1,WORK(N3P4),1,WORK(N3P4),1)\n PUNPRD=DDOT(NP1,WORK(N4P5),1,WORK(N4P5),1)\n IF (SQRT(RUNPRD) .LE. RUTOL) THEN\n STILLU=.FALSE.\n ENDIF\n ENDIF\n IF (STILLU) THEN\nC UPDATE SOLUTION VECTOR; COMPUTE ||DELTA SOL||/||UPDATED||.\n AU=RUNPRD/PUNPRD\n CALL DCOPY(NP1,WORK(NP2),1,WORK,1)\n CALL DAXPY(NP1,AU,WORK(N4P5),1,WORK(NP2),1)\n CALL DAXPY(NP1,-1.0D0,WORK(NP2),1,WORK,1)\n ZLEN=DNRM2(NP1,WORK(NP2),1)\n DZNRM=DNRM2(NP1,WORK,1)\nC IF RELATIVE CHANGE IN SOLUTIONS IS SMALL ENOUGH, EXIT.\n IF ( (DZNRM/ZLEN) .LT. ZTOL) STILLU=.FALSE.\n ENDIF\n ELSE\n STILLU=.FALSE.\n ENDIF\nC\nC IF NO EXIT CRITERIA FOR Mz=u HAVE BEEN MET, CONTINUE.\n IF (STILLU) THEN\nC UPDATE RESIDUAL VECTOR; COMPUTE (RNEW,RNEW), ||RNEW|| .\n CALL MULTDS(WORK,AA,WORK(N4P5),MAXA,NN,LENAA)\n WORK(NP1)=WORK(N4P5+K-1)\n IF (K .LT. NP1) WORK(K)=WORK(K)+WORK(N4P5+NN)\n CALL QIMUDS(WORK(N5P6),WORK,MAXA,NN,LENAA)\n CALL DAXPY(NP1,-AU,WORK,1,WORK(N3P4),1)\n RNPRD=DDOT(NP1,WORK(N3P4),1,WORK(N3P4),1)\nC UPDATE DIRECTION VECTOR; COMPUTE (PNEW,PNEW).\n BU=RNPRD/RUNPRD\n RUNPRD=RNPRD\n CALL DCOPY(NP1,WORK(N3P4),1,WORK,1)\n CALL QIMUDS(WORK(N5P6),WORK,MAXA,NN,LENAA)\n CALL MULTDS(START,AA,WORK,MAXA,NN,LENAA)\n START(NP1)=WORK(K)\n IF (K .LT. NP1) START(K)=START(K)+WORK(NP1)\n CALL DAXPY(NP1,BU,WORK(N4P5),1,START,1)\n CALL DCOPY(NP1,START,1,WORK(N4P5),1)\n PUNPRD=DDOT(NP1,WORK(N4P5),1,WORK(N4P5),1)\n ENDIF\nC\n J=J+1\n GO TO 100\n200 CONTINUE\nC END DO\nC\nC SET ERROR FLAG IF THE CONJUGATE GRADIENT ITERATION DID NOT CONVERGE.\nC\n IF (J .GT. IMAX) THEN\n IFLAG=4\n RETURN\n ENDIF\nC\nC COMPUTE INITIAL RESIDUAL VECTOR FOR THE SYSTEM M z = b .\nC\n CALL MULTDS(WORK(N3P4),AA,WORK(N2P3),MAXA,NN,LENAA)\n WORK(N3P4+NN)=WORK(N2P3+K-1)\n IND=N3P4+K-1\n IF (K .LT. NP1) WORK(IND)=WORK(IND)+WORK(N2P3+NN)\n CALL DSCAL(NP1,-1.0D0,WORK(N3P4),1)\n CALL DAXPY(NN,-1.0D0,RHO,1,WORK(N3P4),1)\n WORK(N3P4+NN)=STARTK+WORK(N3P4+NN)\n CALL QIMUDS(WORK(N5P6),WORK(N3P4),MAXA,NN,LENAA)\nC\nC COMPUTE INITIAL DIRECTION VECTOR, ALL INNER PRODUCTS FOR M z = b .\nC\n CALL DCOPY(NP1,WORK(N3P4),1,WORK,1)\n CALL QIMUDS(WORK(N5P6),WORK,MAXA,NN,LENAA)\n CALL MULTDS(WORK(N4P5),AA,WORK,MAXA,NN,LENAA)\n WORK(N4P5+NN)=WORK(K)\n IF (K .LT. NP1) WORK(N4P5+K-1)=WORK(N4P5+K-1)+WORK(NP1)\nC\n RBNPRD=DDOT(NP1,WORK(N3P4),1,WORK(N3P4),1)\n PBNPRD=DDOT(NP1,WORK(N4P5),1,WORK(N4P5),1)\nC\n J=1\nC\nC DO WHILE ( STILLB .AND. (J .LE. IMAX) )\n300 IF (.NOT. ( STILLB .AND. (J .LE. IMAX) ) ) GO TO 400\nC\nC IF ||RESIDUAL|| IS STILL NOT SMALL ENOUGH, CONTINUE.\n IF (SQRT(RBNPRD) .GT. RBTOL) THEN\n IF (PBNPRD .EQ. 0.0) THEN\n CALL MULTDS(WORK(N3P4),AA,WORK(N2P3),MAXA,NN,LENAA)\n WORK(N3P4+NN)=WORK(N2P3+K-1)\n IND=N3P4+K-1\n IF (K .LT. NP1) WORK(IND)=WORK(IND)+WORK(N2P3+NN)\n CALL DSCAL(NP1,-1.0D0,WORK(N3P4),1)\n CALL DAXPY(NN,-1.0D0,RHO,1,WORK(N3P4),1)\n WORK(N3P4+NN)=STARTK+WORK(N3P4+NN)\n CALL QIMUDS(WORK(N5P6),WORK(N3P4),MAXA,NN,LENAA)\n CALL DCOPY(NP1,WORK(N3P4),1,WORK,1)\n CALL QIMUDS(WORK(N5P6),WORK,MAXA,NN,LENAA)\n CALL MULTDS(WORK(N4P5),AA,WORK,MAXA,NN,LENAA)\n WORK(N4P5+NN)=WORK(K)\n IND=N4P5+K-1\n IF (K .LT. NP1) WORK(IND)=WORK(IND)+WORK(NP1)\n RBNPRD=DDOT(NP1,WORK(N3P4),1,WORK(N3P4),1)\n PBNPRD=DDOT(NP1,WORK(N4P5),1,WORK(N4P5),1)\n IF (SQRT(RBNPRD) .LE. RBTOL) THEN\n STILLB=.FALSE.\n ENDIF\n ENDIF\n IF (STILLB) THEN\nC UPDATE SOLUTION VECTOR; COMPUTE ||DELTA SOL||/||UPDATED|| .\n AB=RBNPRD/PBNPRD\n CALL DCOPY(NP1,WORK(N2P3),1,WORK,1)\n CALL DAXPY(NP1,AB,WORK(N4P5),1,WORK(N2P3),1)\n CALL DAXPY(NP1,-1.0D0,WORK(N2P3),1,WORK,1)\n ZLEN=DNRM2(NP1,WORK(N2P3),1)\n DZNRM=DNRM2(NP1,WORK,1)\nC IF RELATIVE CHANGE IN SOLUTIONS IS SMALL ENOUGH, EXIT.\n IF ( (DZNRM/ZLEN) .LT. ZTOL) STILLB=.FALSE.\n ENDIF\n ELSE\n STILLB=.FALSE.\n ENDIF\nC\nC IF NO EXIT CRITERIA FOR Mz=b HAVE BEEN MET, CONTINUE.\n IF (STILLB) THEN\nC UPDATE RESIDUAL VECTOR; COMPUTE (RNEW,RNEW), ||RNEW|| .\n CALL MULTDS(WORK,AA,WORK(N4P5),MAXA,NN,LENAA)\n WORK(NP1)=WORK(N4P5+K-1)\n IF (K .LT. NP1) WORK(K)=WORK(K)+WORK(N4P5+NN)\n CALL QIMUDS(WORK(N5P6),WORK,MAXA,NN,LENAA)\n CALL DAXPY(NP1,-AB,WORK,1,WORK(N3P4),1)\n RNPRD=DDOT(NP1,WORK(N3P4),1,WORK(N3P4),1)\nC UPDATE DIRECTION VECTOR; COMPUTE (PNEW,PNEW).\n BB=RNPRD/RBNPRD\n RBNPRD=RNPRD\n CALL DCOPY(NP1,WORK(N3P4),1,WORK,1)\n CALL QIMUDS(WORK(N5P6),WORK,MAXA,NN,LENAA)\n CALL MULTDS(START,AA,WORK,MAXA,NN,LENAA)\n START(NP1)=WORK(K)\n IF (K .LT. NP1) START(K)=START(K)+WORK(NP1)\n CALL DAXPY(NP1,BB,WORK(N4P5),1,START,1)\n CALL DCOPY(NP1,START,1,WORK(N4P5),1)\n PBNPRD=DDOT(NP1,WORK(N4P5),1,WORK(N4P5),1)\n ENDIF\nC \n J=J+1\n GO TO 300\n400 CONTINUE\nC END DO\nC\nC SET ERROR FLAG IF THE CONJUGATE GRADIENT ITERATION DID NOT CONVERGE.\nC\n IF (J .GT. IMAX) THEN\n IFLAG=4\n RETURN\n ENDIF\nC\nC COMPUTE FINAL SOLUTION VECTOR X, RETURN IT IN START.\nC\n TEMP=-WORK(N2P3+NN)/(1.0D0+WORK(NP2+NN))\n CALL DCOPY(NP1,WORK(N2P3),1,START,1)\n CALL DAXPY(NP1,TEMP,WORK(NP2),1,START,1)\nC\n RETURN\n END\n", "meta": {"hexsha": "4d47673af356a9221ebdd939cefb9f9649f4dc65", "size": 15270, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/f2cl/packages/hompack/pcgns.f", "max_stars_repo_name": "sbwhitecap/clocc-hg", "max_stars_repo_head_hexsha": "f6cf2591ceef8a3a80e04da9b414cdf60a25a90f", "max_stars_repo_licenses": ["MIT"], "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/f2cl/packages/hompack/pcgns.f", "max_issues_repo_name": "sbwhitecap/clocc-hg", "max_issues_repo_head_hexsha": "f6cf2591ceef8a3a80e04da9b414cdf60a25a90f", "max_issues_repo_licenses": ["MIT"], "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/f2cl/packages/hompack/pcgns.f", "max_forks_repo_name": "sbwhitecap/clocc-hg", "max_forks_repo_head_hexsha": "f6cf2591ceef8a3a80e04da9b414cdf60a25a90f", "max_forks_repo_licenses": ["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.4634760705, "max_line_length": 75, "alphanum_fraction": 0.5258022266, "num_tokens": 5513, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582554941719, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6997163126615473}} {"text": " FUNCTION bessy1(x)\r\n REAL bessy1,x\r\nCU USES bessj1\r\n REAL xx,z,bessj1\r\n DOUBLE PRECISION p1,p2,p3,p4,p5,q1,q2,q3,q4,q5,r1,r2,r3,r4,r5,r6,\r\n *s1,s2,s3,s4,s5,s6,s7,y\r\n SAVE p1,p2,p3,p4,p5,q1,q2,q3,q4,q5,r1,r2,r3,r4,r5,r6,s1,s2,s3,s4,\r\n *s5,s6,s7\r\n DATA p1,p2,p3,p4,p5/1.d0,.183105d-2,-.3516396496d-4,\r\n *.2457520174d-5,-.240337019d-6/, q1,q2,q3,q4,q5/.04687499995d0,\r\n *-.2002690873d-3,.8449199096d-5,-.88228987d-6,.105787412d-6/\r\n DATA r1,r2,r3,r4,r5,r6/-.4900604943d13,.1275274390d13,\r\n *-.5153438139d11,.7349264551d9,-.4237922726d7,.8511937935d4/,s1,s2,\r\n *s3,s4,s5,s6,s7/.2499580570d14,.4244419664d12,.3733650367d10,\r\n *.2245904002d8,.1020426050d6,.3549632885d3,1.d0/\r\n if(x.lt.8.)then\r\n y=x**2\r\n bessy1=x*(r1+y*(r2+y*(r3+y*(r4+y*(r5+y*r6)))))/(s1+y*(s2+y*(s3+\r\n *y*(s4+y*(s5+y*(s6+y*s7))))))+.636619772*(bessj1(x)*log(x)-1./x)\r\n else\r\n z=8./x\r\n y=z**2\r\n xx=x-2.356194491\r\n bessy1=sqrt(.636619772/x)*(sin(xx)*(p1+y*(p2+y*(p3+y*(p4+y*\r\n *p5))))+z*cos(xx)*(q1+y*(q2+y*(q3+y*(q4+y*q5)))))\r\n endif\r\n return\r\n END\r\n", "meta": {"hexsha": "99472883471640b06190245a77912b309d4cb7bc", "size": 1154, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/bessy1.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/bessy1.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/bessy1.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.7931034483, "max_line_length": 73, "alphanum_fraction": 0.5623916811, "num_tokens": 561, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.930458251637412, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6997163045898913}} {"text": "!\tafStresses:\tCurrent afStresses (IN), New afStresses (OUT)\n!\tfEpsilonP:\tCurrent State variables (IN), New State variables (OUT)\n!\tafE:\tConstitutive Matrix (OUT)\n!\tafdStrains:\tINCREMENTAL Strains (IN)\n!\tafProps:\tProperties (IN)\n! afStressesElastic(6) = Elastic afStresses predictor\n! afDElastic(6,6) = Elastic constitutive matrix\n! afStressesDeviatoric(6)= (New) Deviatoric Stresses tensor --> Used to form afE\n\nSubroutine MaterialVonMises(afdStrains, fEpsilonP, afStresses, afProps, afStressesNew, fEpsilonPNew, afE)\n !DEC$ ATTRIBUTES DLLEXPORT::MaterialVonMises\n\tImplicit None\n Real, Intent(IN) :: fEpsilonP, afdStrains(6), afStresses(6), afProps(5)\n\tReal, Intent(OUT) :: afStressesNew(6), fEpsilonPNew, afE(6, 6)\n\n\tReal :: afStressesElastic(6), afDElastic(6, 6), afStressesDeviatoric(6)\n\tInteger :: K1, K2\n\tReal :: fTemp1, fTemp2, fTemp3, fG, fdEpsilonP, P_EL, P_NEW, CJ2_EL, CJ2_NEW\n\n! afProps(1)=E (Young's modulus), afProps(2)=nu (Poisson's ratio)\n! Do not use nu=0.5 (incrompressible solid)\n! Evaluate elastic constitutive matrix\n afDElastic = 0.\n\tfTemp1 = afProps(1) * (1. - afProps(2)) / (1. + afProps(2)) / (1. - 2. * afProps(2))\n\tfTemp2 = afProps(1) * afProps(2) / (1. + afProps(2)) / (1. - 2. * afProps(2))\n\tfTemp3 = afProps(1) / (1. + afProps(2)) / 2.\n\tafDElastic(1, 1) = fTemp1\n\tafDElastic(2, 2) = fTemp1\n\tafDElastic(3, 3) = fTemp1\n\tafDElastic(1, 2) = fTemp2\n\tafDElastic(1, 3) = fTemp2\n\tafDElastic(2, 1) = fTemp2\n\tafDElastic(2, 3) = fTemp2\n\tafDElastic(3, 1) = fTemp2\n\tafDElastic(3, 2) = fTemp2\n\tafDElastic(4, 4) = fTemp3\n\tafDElastic(5, 5) = fTemp3\n\tafDElastic(6, 6) = fTemp3\n\n! EVALUATE NEW afStresses TENSOR and STATE VARIABLE\n! Calculate trial (elastic) afStresses state\n\tafStressesElastic = afStresses + MatMul(afDElastic, afdStrains)\n! Yield function <>0 ?\n! afProps(3)=sigma(y) (initial yield afStresses),\n! afProps(4)=h (hardening modulus for linear hardening)\n! fEpsilonP(1)=epsilon(p)_BAR (accumulated plastic strain)\n\tCJ2_EL = ((afStressesElastic(1) - afStressesElastic(2)) ** 2 + (afStressesElastic(2) - afStressesElastic(3)) ** 2 + &\n\t\t(afStressesElastic(3) - afStressesElastic(1)) ** 2) / 6. + afStressesElastic(4) ** 2 + afStressesElastic(5) ** 2 + &\n\t\tafStressesElastic(6) ** 2\n\tfTemp1 = SQRT(3. * CJ2_EL) - (afProps(3) + afProps(4) * fEpsilonP)\n\tIf (fTemp1 <= 0.) Then\n\t\tafStressesNew = afStressesElastic ! No plastic correction needed\n\t\tafE = afDElastic ! Const. matrix = Elastic const. matrix, no change to the accumulated plastic strain\n\tElse\n! Return mapping\n\t\tfG = afProps(1) / 2. / (1. + afProps(2)) ! fG = Shear modulus\n\t\tfdEpsilonP = fTemp1 / (3. * fG + afProps(4))\n\t\tfEpsilonPNew = fEpsilonP + fdEpsilonP ! Update accumulated plastic strain\n\t\tfTemp1 = fG * fdEpsilonP * SQRT(3. / CJ2_EL) ! 2. and 1/2. cancel out\n\t\tP_EL = (afStressesElastic(1) + afStressesElastic(2) + afStressesElastic(3)) / 3. ! P_EL=mean afStresses (elastic)\n\t\tafStressesNew(1) = afStressesElastic(1) - fTemp1 * (afStressesElastic(1) - P_EL)\n\t\tafStressesNew(2) = afStressesElastic(2) - fTemp1 * (afStressesElastic(2) - P_EL)\n\t\tafStressesNew(3) = afStressesElastic(3) - fTemp1 * (afStressesElastic(3) - P_EL)\n\t\tafStressesNew(4) = afStressesElastic(4) - fTemp1 * afStressesElastic(4)\n\t\tafStressesNew(5) = afStressesElastic(5) - fTemp1 * afStressesElastic(5)\n\t\tafStressesNew(6) = afStressesElastic(6) - fTemp1 * afStressesElastic(6)\n\n! CREATE NEW JACOBIAN\n\t\tP_NEW = (afStressesNew(1) + afStressesNew(2) + afStressesNew(3)) / 3.\n\t\tafStressesDeviatoric(1) = afStressesNew(1) - P_NEW\n\t\tafStressesDeviatoric(2) = afStressesNew(2) - P_NEW\n\t\tafStressesDeviatoric(3) = afStressesNew(3) - P_NEW\n\t\tafStressesDeviatoric(4) = afStressesNew(4)\n\t\tafStressesDeviatoric(5) = afStressesNew(5)\n\t\tafStressesDeviatoric(6) = afStressesNew(6)\n\n\t\tCJ2_NEW = ((afStressesNew(1) - afStressesNew(2)) ** 2 + (afStressesNew(2) - afStressesNew(3)) ** 2 + &\n\t\t\t(afStressesNew(3) - afStressesNew(1)) ** 2 ) / 6. + afStressesNew(4) ** 2 + afStressesNew(5) ** 2 + &\n\t\t\tafStressesNew(6) ** 2\n\t\tfTemp1 = 3. * fG * fG / (afProps(4) + 3. * fG) / CJ2_NEW\n\t\tDo K1 = 1, 6\n\t\t\tDo K2 = 1, 6\n\t\t\t\tafE(K2, K1) = afDElastic(K2, K1) - fTemp1 * afStressesDeviatoric(K2) * afStressesDeviatoric(K1)\n\t\t\tEnd Do\n\t\tEnd Do\n!\t\tafE = afDElastic ! Const. matrix = Elastic const. matrix, no change to the accumulated plastic strain\n\tEnd If\nEnd Subroutine\n", "meta": {"hexsha": "bc4cc0f280a56757d6169d9a54280d0883510ce7", "size": 4330, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "FEMElements/FEMElements/rMaterialVonMises.f90", "max_stars_repo_name": "gsoim/MSolve", "max_stars_repo_head_hexsha": "5cf2ae4f84cdb49f4676fa2ae00fc619421b2bef", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2016-06-06T17:42:17.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-12T09:02:09.000Z", "max_issues_repo_path": "FEMElements/FEMElements/rMaterialVonMises.f90", "max_issues_repo_name": "gsoim/AnsysMSolve", "max_issues_repo_head_hexsha": "3a552a7559e8f02bf2f5682ea5c1836d7fd6663b", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 90, "max_issues_repo_issues_event_min_datetime": "2016-06-16T11:58:01.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-06T00:10:53.000Z", "max_forks_repo_path": "FEMElements/FEMElements/rMaterialVonMises.f90", "max_forks_repo_name": "gsoim/AnsysMSolve", "max_forks_repo_head_hexsha": "3a552a7559e8f02bf2f5682ea5c1836d7fd6663b", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 28, "max_forks_repo_forks_event_min_datetime": "2016-07-19T13:50:30.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-09T21:53:32.000Z", "avg_line_length": 48.6516853933, "max_line_length": 118, "alphanum_fraction": 0.6956120092, "num_tokens": 1779, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.930458253565792, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.699716300868733}} {"text": "!! This module define physical and numerical constant used by ROHSA\nmodule mod_constants\n !! This module define physical and numerical constant used by ROHSA\n use, intrinsic :: iso_fortran_env\n implicit none\n\n integer, parameter, public :: xp = REAL64\n \n !physical constants FIXME CHECK VALUES\n real(xp), parameter, public :: G = 6.67408e-8_xp !nravitationnal cst in cgs\n real(xp), parameter, public :: c = 2.99792458e10_xp !speed of light in cgs\n real(xp), parameter, public :: pi = 4.0_xp*atan(1.0_xp)\n real(xp), parameter, public :: M_sun = 1.98855e33_xp !mass of the sun in cgs\n real(xp), parameter, public :: cst_rad = 7.5657308531642009e-15_xp !radiation cst in cgs\n real(xp), parameter, public :: stefan = (c * cst_rad) / 4.0_xp !stefan cst in cgs\n real(xp), parameter, public :: kb = 1.3806488e-16_xp !boltzmann cst in cgs\n real(xp), parameter, public :: R = 8.3144598e7_xp !gas cst in csg = Boltzmann cst over proton mass\n real(xp), parameter, public :: gammag = 5._xp / 3._xp !adiabatic coefficient\n real(xp), parameter, public :: thomson = 6.6524587158e-25_xp !thomson cross-section in cgs\n \nend module mod_constants\n", "meta": {"hexsha": "6ed86e7e52b19f83e677089398c5ff793337c842", "size": 1178, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/mod_constants.f90", "max_stars_repo_name": "antoinemarchal/ROHSA", "max_stars_repo_head_hexsha": "e36bc49b5bc60047634594d6c7ae42ef92291194", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2018-11-01T15:46:41.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-12T19:02:27.000Z", "max_issues_repo_path": "src/mod_constants.f90", "max_issues_repo_name": "antoinemarchal/ROHSA", "max_issues_repo_head_hexsha": "e36bc49b5bc60047634594d6c7ae42ef92291194", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-04-24T12:13:18.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-24T12:41:02.000Z", "max_forks_repo_path": "src/mod_constants.f90", "max_forks_repo_name": "antoinemarchal/ROHSA", "max_forks_repo_head_hexsha": "e36bc49b5bc60047634594d6c7ae42ef92291194", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-10-08T07:58:34.000Z", "max_forks_repo_forks_event_max_datetime": "2019-10-08T07:58:34.000Z", "avg_line_length": 53.5454545455, "max_line_length": 106, "alphanum_fraction": 0.701188455, "num_tokens": 396, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942171172603, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.6996767009920625}} {"text": "\nsubroutine compute_localization_weights( istat, dist, nlb, nub, mlb, mub, nmax, mmax, nostat, mnstat, kcs, xz, yz, locval ) \n\n use globaldata\n \n implicit none\n\n integer, intent(in) :: istat ! current station number\n integer, intent(in) :: nostat ! number of stations\n integer, intent(in) :: nlb, nub, nmax\n integer, intent(in) :: mlb, mub, mmax\n integer, dimension(nmax,mmax), intent(in) :: kcs\n integer, dimension(2,nostat) , intent(in) :: mnstat\n \n double precision, intent(in) :: dist\n real(fp) , dimension(nlb:nub, mlb:mub) , intent(in) :: xz ! Description and declaration in esm_alloc_real.f90\n real(fp) , dimension(nlb:nub, mlb:mub) , intent(in) :: yz ! Description and declaration in esm_alloc_real.f90\n\n double precision, dimension(nlb:nub, mlb:mub), intent(out) :: locval ! computed weights\n\n ! local variables\n integer :: m, n\n ! mn values of station\n integer :: ms, ns\n ! xy coordinates of station\n double precision :: sx, sy\n real :: weight\n real, external :: cohn\n \n ! intialize weight values\n locval = 0.0\n \n weight = 0.\n ms = mnstat(1,istat)\n ns = mnstat(2,istat)\n sx = xz(ns,ms)\n sy = yz(ns,ms)\n do n = 1, nmax\n do m = 1, mmax\n if (kcs(n,m) .gt. 0) then\n weight = cohn(sx,sy,xz(n,m),yz(n,m),dist)\n endif\n locval(n,m) = weight\n enddo\n enddo\n \nend subroutine compute_localization_weights\n!\n!-------------------------------------------------------------------------------\n!\nfunction cohn(sm,sn,rm,rn,dist) result(weight)\n \n implicit none\n\n real :: weight ! localization weight according to Cohn's formula\n\n ! coordinates to compute localization weight for\n double precision :: sm, sn \n \n ! treshold distance for Cohn's formula. all points at a distance\n ! more than 2*dist have weight 0\n double precision :: dist\n double precision :: rm, rn \n\n ! local parameters\n real :: zc1 ! value of (z/c)\n real :: zc2 ! value of (z/c)^2\n real :: zc3 ! value of (z/c)^3\n real :: zc4 ! value of (z/c)^4\n real :: zc5 ! value of (z/c)^5\n real :: z ! Eucledean distance between (m,n) and (rm, rn)\n real :: dm ! distance between rm and sm\n real :: dn ! distance between rn and sn\n \n real p1_4, p1_2, p2_3, p5_8, p5_3, p1_12\n parameter( p1_4 = 1.0/4.0 ) ! value of 1/4\n parameter( p1_2 = 1.0/2.0 ) ! value of 1/2\n parameter( p2_3 = 2.0/3.0 ) ! value of 2/3\n parameter( p5_8 = 5.0/8.0 ) ! value of 5/8\n parameter( p5_3 = 5.0/3.0 ) ! value of 5/3\n parameter( p1_12 = 1.0/12.0 ) ! value of 1/12\n\n! Compute distance per direction\n!\n dn=abs(rn-sn)\n dm=abs(rm-sm)\n!\n! Initialize weight\n weight=0.0\n!\n! If point is likely to be within localization region\n!\n if (dn<2.0*dist .and. dm<2.0*dist) then\n!\n! compute euclidian distance\n!\n z=sqrt(dn*dn+dm*dm)\n!\n! compute weight according to Cohn's formula\n!\n if (z .le. 2.0*dist) then\n zc1=z/dist\n zc2=zc1*zc1\n zc3=zc2*zc1\n zc4=zc3*zc1\n zc5=zc4*zc1\n if (z .le. dist) then\n weight=-p1_4 *zc5+p1_2*zc4+p5_8*zc3-p5_3*zc2+1.0\n else\n weight=p1_12*zc5-p1_2*zc4+p5_8*zc3+p5_3*zc2-5.0*zc1+4-p2_3*(dist/z)\n endif\n endif\n endif\n \n end function cohn\n\n", "meta": {"hexsha": "2b8ff83eac77f537d01769561d52be9d21a735dd", "size": 3443, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "docker/water/delft3d/tags/v6686/src/engines_gpl/flow2d3d/packages/flow2d3d_openda/src/localization.f90", "max_stars_repo_name": "liujiamingustc/phd", "max_stars_repo_head_hexsha": "4f815a738abad43531d02ac66f5bd0d9a1def52a", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-01-06T03:01:18.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T03:02:55.000Z", "max_issues_repo_path": "docker/water/delft3d/tags/v6686/src/engines_gpl/flow2d3d/packages/flow2d3d_openda/src/localization.f90", "max_issues_repo_name": "liujiamingustc/phd", "max_issues_repo_head_hexsha": "4f815a738abad43531d02ac66f5bd0d9a1def52a", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docker/water/delft3d/tags/v6686/src/engines_gpl/flow2d3d/packages/flow2d3d_openda/src/localization.f90", "max_forks_repo_name": "liujiamingustc/phd", "max_forks_repo_head_hexsha": "4f815a738abad43531d02ac66f5bd0d9a1def52a", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.4273504274, "max_line_length": 124, "alphanum_fraction": 0.5663665408, "num_tokens": 1172, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942145139149, "lm_q2_score": 0.7745833841649232, "lm_q1q2_score": 0.6996766895747843}} {"text": "module vorticity\n use boundaries\n use exchange\n\n implicit none\n\n contains\n\n ! ---------------------------------------------------------------------------\n !> Evaluate relative vorticity at lower left grid boundary (du/dy\n !! and dv/dx are at lower left corner as well)\n subroutine evaluate_zeta(zeta, u, v, dx, dy, nx, ny, layers, &\n xlow, xhigh, ylow, yhigh, OL, &\n ilower, iupper, num_procs, myid)\n implicit none\n\n double precision, intent(out) :: zeta(xlow-OL:xhigh+OL, ylow-OL:yhigh+OL, layers)\n double precision, intent(in) :: u(xlow-OL:xhigh+OL, ylow-OL:yhigh+OL, layers)\n double precision, intent(in) :: v(xlow-OL:xhigh+OL, ylow-OL:yhigh+OL, layers)\n double precision, intent(in) :: dx, dy\n integer, intent(in) :: nx, ny, layers\n integer, intent(in) :: xlow, xhigh, ylow, yhigh, OL\n integer, intent(in) :: ilower(0:num_procs-1,2)\n integer, intent(in) :: iupper(0:num_procs-1,2)\n integer, intent(in) :: num_procs, myid\n integer i, j, k\n\n zeta = 0d0\n\n do k = 1, layers\n do j = ylow-OL+1, yhigh+OL\n do i = xlow-OL+1, xhigh+OL\n zeta(i,j,k) = (v(i,j,k)-v(i-1,j,k))/dx-(u(i,j,k)-u(i,j-1,k))/dy\n end do\n end do\n end do\n\n return\n end subroutine evaluate_zeta\n\nend module vorticity\n", "meta": {"hexsha": "720733e6fc71871c10a64eb58aa5d36feb765dc7", "size": 1366, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/vorticity.f90", "max_stars_repo_name": "edoddridge/aronnax", "max_stars_repo_head_hexsha": "7c33836fe8d6c8ea4283f2357325d12ff655bc10", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2017-05-03T17:21:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-17T21:01:06.000Z", "max_issues_repo_path": "src/vorticity.f90", "max_issues_repo_name": "edoddridge/aronnax", "max_issues_repo_head_hexsha": "7c33836fe8d6c8ea4283f2357325d12ff655bc10", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 172, "max_issues_repo_issues_event_min_datetime": "2017-03-26T16:00:03.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-18T23:34:08.000Z", "max_forks_repo_path": "src/vorticity.f90", "max_forks_repo_name": "edoddridge/aronnax", "max_forks_repo_head_hexsha": "7c33836fe8d6c8ea4283f2357325d12ff655bc10", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2017-08-19T12:41:16.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-18T08:32:48.000Z", "avg_line_length": 32.5238095238, "max_line_length": 85, "alphanum_fraction": 0.5505124451, "num_tokens": 430, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941962904956, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.6996766754592266}} {"text": "! point_smoothers.f08\r\n!\r\n! Point smoothers for geometric multigrid.\r\n\r\nmodule point_smoothers\r\n use, intrinsic iso_fortran_env\r\n use structured_grids\r\n implicit none\r\n \r\n ! Interface for the weighted jacobi method.\r\n interface wjacobi\r\n module procedure wjacobi_2d\r\n module procedure wjacobi_3d\r\n end interface wjacobi\r\n \r\n ! Interface for the guass seidel method.\r\n interface gauss_seidel\r\n module procedure gauss_seidel_2d\r\n module procedure gauss_seidel_3d\r\n end interface gauss_seidel\r\n \r\n ! Interface for the (weighted) SOR method.\r\n interface wsor\r\n module procedure wsor_2d\r\n module procedure wsor_3d\r\n end interface wsor\r\n \r\n contains\r\n \r\n !\r\n ! Subroutine definitions for weighted jacobi in 2D and 3D\r\n !\r\n \r\n subroutine wjacobi_2d(grid, U, F, w)\r\n type(Grid2D), intent(in) :: grid ! The grid that contains step size information, etc.\r\n real(REAL64), dimension(1:grid%nx, 1:grid%ny), intent(inout) :: U ! The (discrete) function we are relaxing.\r\n real(REAL64), dimension(1:grid%nx, 1:grid%ny), intent(in) :: F ! The right-hand-side of the PDE, in discrete form.\r\n real(REAL64), intent(in) :: w ! The weight for the method.\r\n \r\n ! A temporary array that holds the next guess.\r\n real(REAL64), dimension(1:grid%nx, 1:grid%ny) :: temp\r\n \r\n ! Counters for the loops.\r\n integer :: i, j, k\r\n \r\n ! Temporary x- and y-coordinates.\r\n real(REAL64) :: x, y\r\n \r\n ! A temporary variable that stores the ratio of the square of the step sizes.\r\n real(REAL64) :: alpha\r\n \r\n ! Store the ratio of the step sizes.\r\n alpha = (grid%hx / grid%hy)**2\r\n \r\n ! First compute the interior points.\r\n !$omp parallel do private(i, j) collapse(2)\r\n do j = 2, grid%ny - 1\r\n do i = 2, grid%nx - 1\r\n temp(i, j) = w * &\r\n ( &\r\n F(i, j) + &\r\n U(i + 1, j) + U(i - 1, j) + &\r\n alpha * ( U(i, j + 1) + U(i, j - 1) )\r\n ) / (2 * (1 + alpha))\r\n + &\r\n (1 - w) * U(i, j)\r\n end do\r\n end do\r\n !$omp end parallel do\r\n\r\n ! Set the new version of U to the current value of the temporary array.\r\n U = temp\r\n end subroutine wjacobi_2d\r\n \r\n subroutine wjacobi_3d(grid, U, F, w)\r\n type(Grid3D), intent(in) :: grid\r\n real(REAL64), dimension(1:grid%nx, 1:grid%ny, 1:grid%nz), intent(inout) :: U\r\n real(REAL64), dimension(1:grid%nx, 1:grid%ny, 1:grid%nz), intent(in) :: F\r\n real(REAL64), intent(in) :: w\r\n \r\n ! A temporary array that holds the next guess.\r\n real(REAL64), dimension(1:grid%nx, 1:grid%ny, 1:grid%nz) :: temp\r\n \r\n ! Counters for the loops.\r\n integer :: i, j, k, m\r\n \r\n ! Temporary x- and y-coordinates.\r\n real(REAL64) :: x, y, z\r\n \r\n ! A temporary variable that stores the ratio of the square of the step sizes.\r\n real(REAL64) :: alpha, beta\r\n \r\n ! Store the ratio of the step sizes.\r\n alpha = (grid%hx / grid%hy)**2\r\n beta = (grid%hx / grid%hz)**2\r\n \r\n ! First compute the interior points.\r\n !$omp parallel do private(i, j, k) collapse(3)\r\n do k = 2, grid%nz - 1\r\n do j = 2, grid%ny - 1\r\n do i = 2, grid%nx - 1\r\n temp(i, j, k) = w * &\r\n ( &\r\n F(i, j, k) + &\r\n U(i + 1, j, k) + U(i - 1, j, k) + &\r\n alpha * ( U(i, j + 1, k) + U(i, j - 1, k) ) + &\r\n beta * (U(i, j, k + 1) + U(i, j, k - 1) ) &\r\n ) / (2 * (1 + alpha)) &\r\n + &\r\n (1 - w) * U(i, j, k)\r\n end do\r\n end do\r\n end do\r\n !$omp end parallel do\r\n \r\n ! Set the new version of U to the current value of the temporary array.\r\n U = temp\r\n end subroutine wjacobi_3d\r\n \r\n !\r\n ! Subroutine definitions for gauss seidel in 2D and 3D\r\n !\r\n \r\n subroutine gauss_seidel_2d(grid, U, F)\r\n type(Grid2D), intent(in) :: grid\r\n real(REAL64), dimension(1:grid%nx, 1:grid%ny), intent(inout) :: U\r\n real(REAL64), dimension(1:grid%nx, 1:grid%ny), intent(in) :: F\r\n \r\n ! A parameter to hold the ratio of our step sizes.\r\n real(REAL64), parameter :: alpha = (grid%hx / grid%hy)**2\r\n \r\n ! Counter variables for looping over the interior points and the boundaries.\r\n integer :: i, j, k\r\n \r\n ! Temporary x- and y-coordinates.\r\n real(REAL64) :: x, y\r\n \r\n ! Compute the new interior points.\r\n !$omp parallel do private(i, j) collapse(2)\r\n do j = 2, grid%ny - 1\r\n do i = 2, grid%nx - 1\r\n U(i, j) = ( &\r\n F(i, j) + &\r\n U(i - 1, j) + U(i + 1, j) + &\r\n alpha * ( &\r\n U(i, j - 1) + U(i, j + 1) &\r\n ) &\r\n ) / (2.0 * (1 + alpha))\r\n end do\r\n end do\r\n !$omp end parallel do\r\n end subroutine gauss_seidel_2d\r\n \r\n subroutine gauss_seidel_3d(grid, U)\r\n type(Grid3D), intent(in) :: grid\r\n real(REAL64), dimension(1:grid%nx, 1:grid%ny, 1:grid%nz), intent(inout) :: U\r\n \r\n real, parameter :: alpha = (grid%hx / grid%hy)**2\r\n real, parameter :: beta = (grid%hx / grid%hz)**2\r\n \r\n integer :: i, j, k\r\n \r\n ! First relax the interior points.\r\n !$omp parallel do private(i, j, k) collapse(3)\r\n do k = 2, grid%nz - 1\r\n do j = 2, grid%ny - 1\r\n do i = 2, grid%nx - 1\r\n U(i, j, k) = ( &\r\n F(i, j, k) + &\r\n \r\n U(i - 1, j, k) + U(i + 1, j, k) + &\r\n \r\n alpha * ( &\r\n U(i, j - 1, k) + U(i, j + 1, k)\r\n ) + &\r\n \r\n beta * ( &\r\n U(i, j, k - 1) + U(i, j, k + 1)\r\n )\r\n ) / (2.0 * (1 + alpha + beta))\r\n end do\r\n end do\r\n end do\r\n !$omp end parallel do\r\n end subroutine gauss_seidel_3d\r\n \r\n !\r\n ! Subroutine definitions for (weighted) successive overrelaxation in 2D and 3D.\r\n !\r\n \r\n subroutine wsor_2d(grid, U, F)\r\n type(Grid2D), intent(in) :: grid\r\n real(REAL64), dimension(1:grid%nx, 1:grid%ny), intent(inout) :: U\r\n real(REAL64), dimension(1:grid%nx, 1:grid%ny), intent(in) :: F\r\n \r\n real(REAL64), parameter :: alpha = (grid%hx / grid%hy)**2\r\n \r\n integer :: i, j, k\r\n \r\n ! First relax the interior points.\r\n !$omp parallel do private(i, j) collapse(2)\r\n do j = 2, grid%ny - 1\r\n do i = 2, grid%nx - 1\r\n U(i, j) = w * ( &\r\n F(i, j) + &\r\n \r\n U(i - 1, j) + U(i + 1, j) + &\r\n \r\n alpha * ( &\r\n U(i, j - 1) + U(i, j + 1) &\r\n ) &\r\n ) / (2.0 * (1 + alpha)) + &\r\n \r\n (1 - w) * U(i, j)\r\n end do\r\n end do\r\n !$omp end parallel do\r\n end subroutine wsor_2d\r\n \r\n subroutine wsor_3d(grid, U, F)\r\n type(Grid3D), intent(in) :: grid\r\n real(REAL64), dimension(1:grid%nx, 1:grid%ny, 1:grid%nz), intent(inout) :: U\r\n real(REAL64), dimension(1:grid%nx, 1:grid%ny, 1:grid%nz), intent(in) :: F\r\n \r\n real(REAL64), parameter :: alpha = (grid%hx / grid%hy)**2\r\n real(REAL64), parameter :: beta = (grid%hx / grid%hz)**2\r\n \r\n integer :: i, j, k, m\r\n \r\n ! First relax the interior points.\r\n !$omp parallel do private(i, j, k) collapse(3)\r\n do k = 2, grid%nz - 1\r\n do j = 2, grid%ny - 1\r\n do i = 2, grid%nx - 1\r\n U(i, j, k) = w * ( &\r\n F(i, j, k) + &\r\n \r\n U(i - 1, j, k) + U(i + 1, j, k) + &\r\n \r\n alpha * ( &\r\n U(i, j - 1, k) + U(i, j + 1, k) &\r\n ) + &\r\n \r\n beta * ( &\r\n U(i, j, k - 1) + U(i, j, k + 1) &\r\n )\r\n ) / (2.0 * (1 + alpha + beta)) + &\r\n \r\n (1 - w) * U(i, j, k)\r\n end do\r\n end do\r\n end do\r\n !$omp end parallel do\r\n end subroutine wsor_3d\r\n\r\nend module point_smoothers\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "meta": {"hexsha": "2bc169c72bf8118b2bf0a2c46bf00deca8dadfb4", "size": 10107, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "geometric/point_smoothers.f08", "max_stars_repo_name": "bbqp/multigrid", "max_stars_repo_head_hexsha": "8573b676652ff2bf9c3d8f799f5341f6dc5cf154", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "geometric/point_smoothers.f08", "max_issues_repo_name": "bbqp/multigrid", "max_issues_repo_head_hexsha": "8573b676652ff2bf9c3d8f799f5341f6dc5cf154", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "geometric/point_smoothers.f08", "max_forks_repo_name": "bbqp/multigrid", "max_forks_repo_head_hexsha": "8573b676652ff2bf9c3d8f799f5341f6dc5cf154", "max_forks_repo_licenses": ["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.0964285714, "max_line_length": 127, "alphanum_fraction": 0.3817156426, "num_tokens": 2581, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425377849806, "lm_q2_score": 0.7606506635289836, "lm_q1q2_score": 0.6995267065756239}} {"text": " subroutine INTERPCENTRALSLOPE(\n & slope\n & ,islopelo0,islopelo1\n & ,islopehi0,islopehi1\n & ,nslopecomp\n & ,state\n & ,istatelo0,istatelo1\n & ,istatehi0,istatehi1\n & ,nstatecomp\n & ,iblo0,iblo1\n & ,ibhi0,ibhi1\n & ,dir\n & )\n implicit none\n integer*8 chiterations\n integer*8 chflops,chloads,chstores\n common /chiterations/ chiterations\n common /chflops/ chflops,chloads,chstores\n EXTERNAL CHCOMMON\n integer CHF_ID(0:5,0:5)\n data CHF_ID/ 1,0,0,0,0,0 ,0,1,0,0,0,0 ,0,0,1,0,0,0 ,0,0,0,1,0,0 ,0\n &,0,0,0,1,0 ,0,0,0,0,0,1 /\n integer nslopecomp\n integer islopelo0,islopelo1\n integer islopehi0,islopehi1\n REAL*8 slope(\n & islopelo0:islopehi0,\n & islopelo1:islopehi1,\n & 0:nslopecomp-1)\n integer nstatecomp\n integer istatelo0,istatelo1\n integer istatehi0,istatehi1\n REAL*8 state(\n & istatelo0:istatehi0,\n & istatelo1:istatehi1,\n & 0:nstatecomp-1)\n integer iblo0,iblo1\n integer ibhi0,ibhi1\n integer dir\n integer i0,i1\n integer ii0,ii1\n integer var\n ii0=CHF_ID(0, dir)\n ii1=CHF_ID(1, dir)\n do var = 0, nstatecomp - 1\n chiterations=(1+ibhi1-iblo1)*(1+ibhi0-iblo0)*1\n do i1 = iblo1,ibhi1\n do i0 = iblo0,ibhi0\n slope (i0,i1,var) = (0.500d0) * (\n & state (i0+ii0,i1+ii1,var) -\n & state (i0-ii0,i1-ii1,var) )\n enddo\n enddo\n end do\n chflops=chflops+2*chiterations\n chloads=chloads+chiterations\n chstores=chstores+chiterations\n return\n end\n\n", "meta": {"hexsha": "12d15389f9d3bce1901da910ce7e299e92be92cc", "size": 1603, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "projects/ArithmeticMeasureTool/test/fortran/InterpF_002.f", "max_stars_repo_name": "ouankou/rose", "max_stars_repo_head_hexsha": "76f2a004bd6d8036bc24be2c566a14e33ba4f825", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "projects/ArithmeticMeasureTool/test/fortran/InterpF_002.f", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "projects/ArithmeticMeasureTool/test/fortran/InterpF_002.f", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 26.2786885246, "max_line_length": 72, "alphanum_fraction": 0.5938864629, "num_tokens": 638, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425267730008, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6995266882196738}} {"text": "C\nC\t$Id$\nC\n SUBROUTINE CSGRADL (N,K,X,Y,Z,W,LIST,LPTR,LEND, G,IER)\n INTEGER N, K, LIST(*), LPTR(*), LEND(N), IER\n DOUBLE PRECISION X(N), Y(N), Z(N), W(N), G(3)\nC\nC***********************************************************\nC\nC From SSRFPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 07/24/96\nC\nC Given a triangulation of a set of nodes on the unit\nC sphere with their associated data values W, this routine\nC estimates a gradient vector at node K as follows: the\nC coordinate system is rotated so that K becomes the north\nC pole, node K and a set of nearby nodes are projected\nC orthogonally onto the X-Y plane (in the new coordinate\nC system), a quadratic is fitted in a weighted least squares\nC sense to the data values at the projected nodes such that\nC the value (associated with K) at (0,0) is interpolated, X\nC and Y-partial derivative estimates DX and DY are computed\nC by differentiating the quadratic at (0,0), and the esti-\nC mated gradient G is obtained by rotating (DX,DY,0) back to\nC the original coordinate system. Note that G lies in the\nC plane tangent to the sphere at node K, i.e., G is orthogo-\nC nal to the unit vector represented by node K. A Marquardt\nC stabilization factor is used if necessary to ensure a\nC well-conditioned least squares system, and a unique solu-\nC tion exists unless the nodes are collinear.\nC\nC On input:\nC\nC N = Number of nodes in the triangulation. N .GE. 7.\nC\nC K = Node at which the gradient is sought. 1 .LE. K\nC .LE. N.\nC\nC X,Y,Z = Arrays containing the Cartesian coordinates\nC of the nodes.\nC\nC W = Array containing the data values at the nodes.\nC W(I) is associated with (X(I),Y(I),Z(I)) for\nC I = 1,...,N.\nC\nC LIST,LPTR,LEND = Data structure defining the trian-\nC gulation. Refer to STRIPACK\nC Subroutine CSTRMESH.\nC\nC Input parameters are not altered by this routine.\nC\nC On output:\nC\nC G = X, Y, and Z components (in that order) of the\nC estimated gradient at node K unless IER < 0.\nC\nC IER = Error indicator:\nC IER .GE. 6 if no errors were encountered.\nC IER contains the number of nodes\nC (including K) used in the least\nC squares fit.\nC IER = -1 if N or K is outside its valid range.\nC IER = -2 if the least squares system has no\nC unique solution due to duplicate or\nC collinear nodes.\nC\nC STRIPACK module required by CSGRADL: CSGETNP\nC\nC SSRFPACK modules required by CSGRADL: CSAPLYR, CSAPLYRT,\nC CSCONSTR, CSGIVENS,\nC CSROTATE, CSSETUP\nC\nC Intrinsic functions called by CSGRADL: ABS, MIN, DBLE, SQRT\nC\nC***********************************************************\nC\n INTEGER LMN, LMX\n PARAMETER (LMN=10, LMX=30)\n INTEGER I, IERR, IM1, IP1, J, JP1, KK, L, LM1, LMAX,\n . LMIN, LNP, NN, NP, NPTS(LMX)\n DOUBLE PRECISION A(6,6), AV, AVSQ, C, CX, CY, DF,\n . DMIN, DTOL, DX, DY, RF, RIN, RTOL, S,\n . SF, SUM, SX, SY, WK, WT, XP, YP, ZP\nC\n DATA RTOL/1.D-6/, DTOL/.01D0/, SF/1.D0/\nC\nC Local parameters:\nC\nC A = Transpose of the (upper triangle of the) aug-\nC mented regression matrix\nC AV = Root-mean-square distance (in the rotated\nC coordinate system) between the origin and\nC the nodes (other than K) in the least\nC squares fit. The first 3 columns of A**T\nC are scaled by 1/AVSQ, the next 2 by 1/AV.\nC AVSQ = AV*AV: accumulated in SUM\nC C,S = Components of the plane rotation used to\nC triangularize the regression matrix\nC CX,SX = Components of a plane rotation about the X-\nC axis which, together with CY and SY, define\nC a mapping from node K to the north pole\nC (0,0,1)\nC CY,SY = Components of a plane rotation about the Y-\nC axis\nC DF = Negative Z component (in the rotated coordi-\nC nate system) of an element NP of NPTS --\nC increasing function of the angular distance\nC between K and NP. DF lies in the interval\nC (-1,1).\nC DMIN = Minimum of the magnitudes of the diagonal\nC elements of the triangularized regression\nC matrix\nC DTOL = Tolerance for detecting an ill-conditioned\nC system (DMIN is required to be at least\nC DTOL)\nC DX,DY = X and Y components of the estimated gradient\nC in the rotated coordinate system\nC I,J = Loop indexes\nC IERR = Error flag for calls to CSGETNP (not checked)\nC IM1,IP1 = I-1, I+1\nC JP1 = J+1\nC KK = Local copy of K\nC L = Number of columns of A**T to which a rotation\nC is applied\nC LM1 = LMIN-1\nC LMIN,LMAX = Min(LMN,N), Min(LMX,N)\nC LMN,LMX = Minimum and maximum values of LNP for N\nC sufficiently large. In most cases LMN-1\nC nodes are used in the fit. 7 .LE. LMN .LE.\nC LMX.\nC LNP = Length of NPTS or LMAX+1\nC NN = Local copy of N\nC NP = Element of NPTS to be added to the system\nC NPTS = Array containing the indexes of a sequence of\nC nodes ordered by angular distance from K.\nC NPTS(1)=K and the first LNP-1 elements of\nC NPTS are used in the least squares fit.\nC unless LNP = LMAX+1, NPTS(LNP) determines R\nC (see RIN).\nC RF = Value of DF associated with NPTS(LNP) unless\nC LNP = LMAX+1 (see RIN)\nC RIN = Inverse of a radius of influence R which\nC enters into WT: R = 1+RF unless all ele-\nC ments of NPTS are used in the fit (LNP =\nC LMAX+1), in which case R is the distance\nC function associated with some point more\nC distant from K than NPTS(LMAX)\nC RTOL = Tolerance for determining LNP (and hence R):\nC if the increase in DF between two successive\nC elements of NPTS is less than RTOL, they are\nC treated as being the same distance from node\nC K and an additional node is added\nC SF = Marquardt stabilization factor used to damp\nC out the first 3 solution components (second\nC partials of the quadratic) when the system\nC is ill-conditioned. Increasing SF results\nC in more damping (a more nearly linear fit).\nC SUM = Sum of squared Euclidean distances (in the\nC rotated coordinate system) between the\nC origin and the nodes used in the least\nC squares fit\nC WK = W(K) -- data value at node K\nC WT = Weight for the equation coreesponding to NP:\nC WT = (R-D)/(R*D) = 1/D - RIN, where D = 1-ZP\nC is associated with NP\nC XP,YP,ZP = Coordinates of NP in the rotated coordinate\nC system unless ZP < 0, in which case\nC (XP,YP,0) lies on the equator\nC\n NN = N\n KK = K\n WK = W(KK)\nC\nC Check for errors and initialize LMIN, LMAX.\nC\n IF (NN .LT. 7 .OR. KK .LT. 1 .OR. KK .GT. NN)\n . GO TO 13\n LMIN = MIN(LMN,NN)\n LMAX = MIN(LMX,NN)\nC\nC Compute NPTS, LNP, AVSQ, AV, and R.\nC Set NPTS to the closest LMIN-1 nodes to K. DF contains\nC the negative Z component (in the rotated coordinate\nC system) of the new node on return from CSGETNP.\nC\n SUM = 0.\n NPTS(1) = KK\n LM1 = LMIN - 1\n DO 1 LNP = 2,LM1\n CALL CSGETNP (X,Y,Z,LIST,LPTR,LEND,LNP, NPTS, DF,IERR)\n SUM = SUM + 1. - DF*DF\n 1 CONTINUE\nC\nC Add additional nodes to NPTS until the increase in\nC R = 1+RF is at least RTOL.\nC\n DO 2 LNP = LMIN,LMAX\n CALL CSGETNP (X,Y,Z,LIST,LPTR,LEND,LNP, NPTS, RF,IERR)\n IF (RF-DF .GE. RTOL) GO TO 3\n SUM = SUM + 1. - RF*RF\n 2 CONTINUE\nC\nC Use all LMAX nodes in the least squares fit. R is\nC arbitrarily increased by 5 percent.\nC\n RF = 1.05*RF + .05\n LNP = LMAX + 1\nC\nC There are LNP-2 equations corresponding to nodes\nC NPTS(2),...,NPTS(LNP-1).\nC\n 3 AVSQ = SUM/DBLE(LNP-2)\n AV = SQRT(AVSQ)\n RIN = 1./(1.+RF)\nC\nC Construct the rotation.\nC\n CALL CSCONSTR (X(KK),Y(KK),Z(KK), CX,SX,CY,SY)\nC\nC Set up the first 5 equations of the augmented regression\nC matrix (transposed) as the columns of A, and zero out\nC the lower triangle (upper triangle of A) with Givens\nC rotations.\nC\n DO 5 I = 1,5\n NP = NPTS(I+1)\n CALL CSAPLYR (X(NP),Y(NP),Z(NP),CX,SX,CY,SY, XP,YP,ZP)\n WT = 1./(1.-ZP) - RIN\n CALL CSSETUP (XP,YP,W(NP),WK,AV,AVSQ,WT, A(1,I))\n IF (I .EQ. 1) GO TO 5\n IM1 = I - 1\n DO 4 J = 1,IM1\n JP1 = J + 1\n L = 6 - J\n CALL CSGIVENS ( A(J,J),A(J,I), C,S)\n CALL CSROTATE (L,C,S, A(JP1,J),A(JP1,I) )\n 4 CONTINUE\n 5 CONTINUE\nC\nC Add the additional equations to the system using\nC the last column of A. I .LE. LNP.\nC\n I = 7\n 6 IF (I .EQ. LNP) GO TO 8\n NP = NPTS(I)\n CALL CSAPLYR (X(NP),Y(NP),Z(NP),CX,SX,CY,SY, XP,YP,ZP)\n WT = 1./(1.-ZP) - RIN\n CALL CSSETUP (XP,YP,W(NP),WK,AV,AVSQ,WT, A(1,6))\n DO 7 J = 1,5\n JP1 = J + 1\n L = 6 - J\n CALL CSGIVENS ( A(J,J),A(J,6), C,S)\n CALL CSROTATE (L,C,S, A(JP1,J),A(JP1,6) )\n 7 CONTINUE\n I = I + 1\n GO TO 6\nC\nC Test the system for ill-conditioning.\nC\n 8 DMIN = MIN( ABS(A(1,1)),ABS(A(2,2)),ABS(A(3,3)),\n . ABS(A(4,4)),ABS(A(5,5)) )\n IF (DMIN .GE. DTOL) GO TO 12\n IF (LNP .LE. LMAX) THEN\nC\nC Add another node to the system and increase R.\nC I = LNP.\nC\n LNP = LNP + 1\n IF (LNP .LE. LMAX) CALL CSGETNP (X,Y,Z,LIST,LPTR,LEND,\n . LNP,NPTS, RF,IERR)\n RIN = 1./(1.05*(1.+RF))\n GO TO 6\n ENDIF\nC\nC Stabilize the system by damping second partials. Add\nC multiples of the first three unit vectors to the first\nC three equations.\nC\n DO 11 I = 1,3\n A(I,6) = SF\n IP1 = I + 1\n DO 9 J = IP1,6\n A(J,6) = 0.\n 9 CONTINUE\n DO 10 J = I,5\n JP1 = J + 1\n L = 6 - J\n CALL CSGIVENS ( A(J,J),A(J,6), C,S)\n CALL CSROTATE (L,C,S, A(JP1,J),A(JP1,6) )\n 10 CONTINUE\n 11 CONTINUE\nC\nC Test the linear portion of the stabilized system for\nC ill-conditioning.\nC\n DMIN = MIN( ABS(A(4,4)),ABS(A(5,5)) )\n IF (DMIN .LT. DTOL) GO TO 14\nC\nC Solve the 2 by 2 triangular system for the estimated\nC partial derivatives.\nC\n 12 DY = A(6,5)/A(5,5)\n DX = (A(6,4) - A(5,4)*DY)/A(4,4)/AV\n DY = DY/AV\nC\nC Rotate the gradient (DX,DY,0) back into the original\nC coordinate system.\nC\n CALL CSAPLYRT (DX,DY,CX,SX,CY,SY, G)\n IER = LNP - 1\n RETURN\nC\nC N or K is outside its valid range.\nC\n 13 IER = -1\n RETURN\nC\nC No unique solution due to collinear nodes.\nC\n 14 IER = -2\n RETURN\n END\n", "meta": {"hexsha": "24c844ef99c32c10351b5352767e8038e18cece5", "size": 11603, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "contrib/cssgrid/Src/csgradl.f", "max_stars_repo_name": "xylar/cdat", "max_stars_repo_head_hexsha": "8a5080cb18febfde365efc96147e25f51494a2bf", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 62, "max_stars_repo_stars_event_min_datetime": "2018-03-30T15:46:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-08T23:30:24.000Z", "max_issues_repo_path": "contrib/cssgrid/Src/csgradl.f", "max_issues_repo_name": "xylar/cdat", "max_issues_repo_head_hexsha": "8a5080cb18febfde365efc96147e25f51494a2bf", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 114, "max_issues_repo_issues_event_min_datetime": "2018-03-21T01:12:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-05T12:29:54.000Z", "max_forks_repo_path": "contrib/cssgrid/Src/csgradl.f", "max_forks_repo_name": "CDAT/uvcdat", "max_forks_repo_head_hexsha": "5133560c0c049b5c93ee321ba0af494253b44f91", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2018-06-06T02:42:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-26T03:27:00.000Z", "avg_line_length": 35.4831804281, "max_line_length": 62, "alphanum_fraction": 0.5562354563, "num_tokens": 3587, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425245706047, "lm_q2_score": 0.7606506418255928, "lm_q1q2_score": 0.699526676564739}} {"text": "C NCLFORTSTART\n SUBROUTINE DTAPER(X,N,P,XT,IOPT)\n IMPLICIT NONE\nC NCL: xTaper = taper(x,p,iopt)\n\nc this subroutine applies split-cosine-bell tapering to the series x.\nc . the series will be tapered to the mean of x.\nc . See Bloomfield's \"Intro to Fourier ..\"\nc . This is used prior performing an fft on non-cyclic data\n\nc arguments:\nc . x series to be tapered (tapering done in place)\nc . **missing data not allowed**\nc . n series length\nc . p the proportion of the time series to be tapered\nc . [p=0.10 means 10 %]\nc . xt tapered series\nc . iopt iopt=0 taper to series mean\nc . iopt iopt=1 means *force* taper to 0.0\nC INPUT\n INTEGER N,IOPT\n DOUBLE PRECISION X(N),P\nC OUTPUT\n DOUBLE PRECISION XT(N)\nC NCLEND\n INTEGER I,M,kopt\n DOUBLE PRECISION WEIGHT,PI,PIM,XAV\n DATA PI/3.141592653589D0/\n\n kopt = iopt\n\nc pathological case: all values constant \nc force taper to xav=0.0\n\n do i=2,n\n if (x(i).ne.x(1)) then\n go to 10\n end if\n end do\n kopt = 1\n 10 continue\n \n XAV = 0.0D0\n if (kopt.ne.1) then\n DO I = 1,N\n XT(I) = X(I)\n XAV = XAV + X(I)\n END DO\n XAV = XAV/N\n end if\n\n M = MAX0(1,INT(P*DBLE(N)+0.5D0)/2)\n PIM = PI/DBLE(M)\n\n DO I = 1,M\n WEIGHT = 0.5D0 - 0.5D0*COS(PIM* (DBLE(I)-0.5D0))\n XT(I) = (X(I)-XAV)*WEIGHT + XAV\n XT(N+1-I) = (X(N+1-I)-XAV)*WEIGHT + XAV\n END DO\n\nc . cft correction factor for taper (not used , for info only)\nc c c cft = 0.5*(128.-93.*p)/(8.-5.*p)**2\n\n RETURN\n END\n", "meta": {"hexsha": "9ce55c0ebabfd7eda6c3e4b9fa6b25c8ad65e2be", "size": 1725, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ni/src/lib/nfpfort/taper.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "ni/src/lib/nfpfort/taper.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "ni/src/lib/nfpfort/taper.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 26.1363636364, "max_line_length": 69, "alphanum_fraction": 0.5339130435, "num_tokens": 583, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095294, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.6995002531030867}} {"text": "** Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.\n** See https://llvm.org/LICENSE.txt for license information.\n** SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception\n\n* Real arithmetic operations (+, -, *, /) including constant\n* folding and implied type conversions of integer operands.\n\n\tprogramp\n\n\tparameter(N = 33)\n\treal rslts(N), expect(N)\n\nc tests 1 - 3:\n\tdata expect /-2.0, 2.0, 3.0,\nc tests 4 - 11:\n + 3.5, 5e-5, 5e-5, -1.0, 3.5, 0.0, 4.0, 4.0,\nc tests 12 - 18:\n + -0.5, -0.5, 5.0, -8.0, 0.5, 1.0, 2.0,\nc tests 19 - 25:\n + 1.5, -6.0, 1.0, 1.0, -9.0, 4.0, 4.0,\nc tests 26 - 33:\n + 10.0, -1.5, 4.0, 1.0, -2.5, 4.0, 3.0, 1.0 /\n\n\tdata i2 / 2/, x2, xn3, x2en5 / 2.0, - 3.0, 2.0e-5 /\n\nc tests 1 - 3, unary minus:\n\n\trslts(1) = -2.0\n\trslts(2) = - ( -x2)\n\trslts(3) = -xn3\n\nc tests 4 - 11, addition:\n\n\trslts(4) = 1.5 + 2.0\n\trslts(5) = x2en5 + 3e-5\n\trslts(6) = 3e-5 + x2en5\n\trslts(7) = x2 + xn3\n\n\trslts(8) = 2 + 1.5\n\trslts(9) = xn3 + (+3)\n\trslts(10) = +x2 + i2\n\trslts(11) = i2 + x2\n\nc tests 12 - 18, subtraction:\n\n\trslts(12) = 1.5 - 2.0\n\trslts(13) = 1.5 - x2\n\trslts(14) = x2 - xn3\n\n\trslts(15) = (-5) - (- xn3)\n\trslts(16) = i2 - 1.5\n\trslts(17) = 3.0 - i2\n\trslts(18) = 3.0 - 1\n\nc tests 19 - 25, multiplication:\n\n\trslts(19) = 0.5 * 3.0\n\trslts(20) = x2 * xn3\n\trslts(21) = x2 * .5\n\n\trslts(22) = 2 * .5\n\trslts(23) = xn3 * 3\n\trslts(24) = x2 * i2\n\trslts(25) = i2 * x2\n\nc tests 26 - 33, division:\n\n\trslts(26) = 5.0 / .5\n\trslts(27) = xn3 / x2\n\trslts(28) = x2 / .5\n\trslts(29) = 2.0 / x2\n\n\trslts(30) = 5 / (-x2)\n\trslts(31) = i2 / .5\n\trslts(32) = 3.0 / (i2 - 1)\n\trslts(33) = 5.0 / 5\n\nc check results:\n\n\tcall check(rslts, expect, N)\n\tend\n", "meta": {"hexsha": "9d7815027a34ff10e76d802583385f247d32c249", "size": 1754, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "test/f90_correct/src/gc00.f", "max_stars_repo_name": "abrahamtovarmob/flang", "max_stars_repo_head_hexsha": "bcd84b29df046b6d6574f0bfa34ea5059092615a", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 716, "max_stars_repo_stars_event_min_datetime": "2017-05-17T17:58:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T11:20:58.000Z", "max_issues_repo_path": "test/f90_correct/src/gc00.f", "max_issues_repo_name": "abrahamtovarmob/flang", "max_issues_repo_head_hexsha": "bcd84b29df046b6d6574f0bfa34ea5059092615a", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 794, "max_issues_repo_issues_event_min_datetime": "2017-05-18T19:27:40.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T23:22:11.000Z", "max_forks_repo_path": "test/f90_correct/src/gc00.f", "max_forks_repo_name": "abrahamtovarmob/flang", "max_forks_repo_head_hexsha": "bcd84b29df046b6d6574f0bfa34ea5059092615a", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 157, "max_forks_repo_forks_event_min_datetime": "2017-05-17T18:50:33.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T07:06:45.000Z", "avg_line_length": 21.3902439024, "max_line_length": 80, "alphanum_fraction": 0.523945268, "num_tokens": 903, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095292, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.6995002488432259}} {"text": "! Define BLAS API in Fortran module\r\nmodule spral_blas_iface\r\n implicit none\r\n\r\n private\r\n public :: daxpy, dcopy, ddot, dnrm2, dscal\r\n public :: zaxpy, zcopy, zdotc, dznrm2, zscal\r\n public :: dgemm, dtrsm\r\n public :: zgemm, ztrsm\r\n\r\n ! Level 1 BLAS\r\n interface\r\n subroutine daxpy( n, a, x, incx, y, incy )\r\n implicit none\r\n integer, intent(in) :: n, incx, incy\r\n double precision, intent(in) :: a\r\n double precision, intent(in ), dimension(*) :: x\r\n double precision, intent(inout), dimension(*) :: y\r\n end subroutine daxpy\r\n subroutine dcopy( n, x, incx, y, incy )\r\n implicit none\r\n integer, intent(in) :: n, incx, incy\r\n double precision, intent(in ), dimension(*) :: x\r\n double precision, intent(out), dimension(*) :: y\r\n end subroutine dcopy\r\n double precision function ddot( n, x, incx, y, incy )\r\n implicit none\r\n integer, intent(in) :: n, incx, incy\r\n double precision, intent(in), dimension(*) :: x\r\n double precision, intent(in), dimension(*) :: y\r\n end function ddot\r\n double precision function dnrm2( n, x, incx )\r\n implicit none\r\n integer, intent(in) :: n, incx\r\n double precision, intent(in), dimension(*) :: x\r\n end function dnrm2\r\n subroutine dscal( n, a, x, incx )\r\n implicit none\r\n integer, intent(in) :: n, incx\r\n double precision, intent(in) :: a\r\n double precision, intent(in), dimension(*) :: x\r\n end subroutine dscal\r\n subroutine zcopy( n, x, incx, y, incy )\r\n implicit none\r\n integer, parameter :: PRECISION = kind(1.0D0)\r\n integer, intent(in) :: n, incx, incy\r\n complex(PRECISION), intent(in ), dimension(*) :: x\r\n complex(PRECISION), intent(out), dimension(*) :: y\r\n end subroutine zcopy\r\n double precision function dznrm2( n, x, incx )\r\n implicit none\r\n integer, parameter :: PRECISION = kind(1.0D0)\r\n integer, intent(in) :: n, incx\r\n complex(PRECISION), intent(in), dimension(*) :: x\r\n end function dznrm2\r\n function zdotc( n, x, incx, y, incy )\r\n implicit none\r\n integer, parameter :: PRECISION = kind(1.0D0)\r\n integer, intent(in) :: n, incx, incy\r\n complex(PRECISION), intent(in), dimension(*) :: x\r\n complex(PRECISION), intent(in), dimension(*) :: y\r\n complex(PRECISION) :: zdotc\r\n end function zdotc\r\n subroutine zscal( n, a, x, incx )\r\n implicit none\r\n integer, parameter :: PRECISION = kind(1.0D0)\r\n integer, intent(in) :: n, incx\r\n complex(PRECISION), intent(in) :: a\r\n complex(PRECISION), intent(in), dimension(*) :: x\r\n end subroutine zscal\r\n subroutine zaxpy( n, a, x, incx, y, incy )\r\n implicit none\r\n integer, parameter :: PRECISION = kind(1.0D0)\r\n integer, intent(in) :: n, incx, incy\r\n complex(PRECISION), intent(in) :: a\r\n complex(PRECISION), intent(in ), dimension(*) :: x\r\n complex(PRECISION), intent(inout), dimension(*) :: y\r\n end subroutine zaxpy\r\n end interface\r\n\r\n ! Level 3 BLAS\r\n interface\r\n subroutine dgemm( ta, tb, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc )\r\n implicit none\r\n character, intent(in) :: ta, tb\r\n integer, intent(in) :: m, n, k\r\n integer, intent(in) :: lda, ldb, ldc\r\n double precision, intent(in) :: alpha, beta\r\n double precision, intent(in ), dimension(lda, *) :: a\r\n double precision, intent(in ), dimension(ldb, *) :: b\r\n double precision, intent(inout), dimension(ldc, *) :: c\r\n end subroutine dgemm\r\n subroutine dtrsm( side, uplo, trans, diag, m, n, alpha, a, lda, b, ldb )\r\n implicit none\r\n character, intent(in) :: side, uplo, trans, diag\r\n integer, intent(in) :: m, n, lda, ldb\r\n double precision, intent(in ) :: alpha\r\n double precision, intent(in ) :: a(lda, *)\r\n double precision, intent(inout) :: b(ldb, n)\r\n end subroutine dtrsm\r\n subroutine zgemm( ta, tb, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc )\r\n implicit none\r\n integer, parameter :: PRECISION = kind(1.0D0)\r\n character, intent(in) :: ta, tb\r\n integer, intent(in) :: m, n, k\r\n integer, intent(in) :: lda, ldb, ldc\r\n complex(PRECISION), intent(in) :: alpha, beta\r\n complex(PRECISION), intent(in ), dimension(lda, *) :: a\r\n complex(PRECISION), intent(in ), dimension(ldb, *) :: b\r\n complex(PRECISION), intent(inout), dimension(ldc, *) :: c\r\n end subroutine zgemm\r\n subroutine ztrsm( side, uplo, trans, diag, m, n, alpha, a, lda, b, ldb )\r\n implicit none\r\n integer, parameter :: PRECISION = kind(1.0D0)\r\n character, intent(in) :: side, uplo, trans, diag\r\n integer, intent(in) :: m, n, lda, ldb\r\n complex(PRECISION), intent(in ) :: alpha\r\n complex(PRECISION), intent(in ) :: a(lda, *)\r\n complex(PRECISION), intent(inout) :: b(ldb, n)\r\n end subroutine ztrsm\r\n end interface\r\n\r\nend module spral_blas_iface\r\n", "meta": {"hexsha": "b766d1ef60671a7fb54da4bb3ff47a8a8b1e75b3", "size": 4944, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/blas_iface.f90", "max_stars_repo_name": "mjacobse/spral", "max_stars_repo_head_hexsha": "9bf003b2cc199928ec18c967ce0e009d98790898", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 76, "max_stars_repo_stars_event_min_datetime": "2016-10-03T13:58:37.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-14T00:11:34.000Z", "max_issues_repo_path": "src/blas_iface.f90", "max_issues_repo_name": "mjacobse/spral", "max_issues_repo_head_hexsha": "9bf003b2cc199928ec18c967ce0e009d98790898", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 51, "max_issues_repo_issues_event_min_datetime": "2016-09-20T19:01:18.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-11T12:52:21.000Z", "max_forks_repo_path": "src/blas_iface.f90", "max_forks_repo_name": "mjacobse/spral", "max_forks_repo_head_hexsha": "9bf003b2cc199928ec18c967ce0e009d98790898", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2016-09-30T20:52:47.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-28T14:58:37.000Z", "avg_line_length": 39.8709677419, "max_line_length": 77, "alphanum_fraction": 0.5958737864, "num_tokens": 1437, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467611766711, "lm_q2_score": 0.7956581049086031, "lm_q1q2_score": 0.6995002459343664}} {"text": "module particles_objs\n\n use iso_fortran_env\n\n implicit none\n\n! Define parameter\n real(real64), parameter :: pi = 3.14159\n real(real64), parameter :: e0 = 8.854188e-12\n\n! Define types\n type, public :: Particle\n ! define the attributes\n character(9) :: name\n real(real64) :: radius\n real(real64) :: mass\n contains\n procedure :: cross_area => ca ! Multiple Dispatch & Overloading Functions\n procedure :: show => show_p ! Multiple Dispatch & Overloading Functions\n end type Particle\n\n ! hereditary\n type, extends(Particle) :: Electron\n real(real64) :: charge\n contains\n procedure :: electric_potential => ep\n procedure :: show => show_e ! Multiple Dispatch\n end type Electron\n\n! Define Procedure\ncontains\n\n subroutine ca(this)\n ! arguments\n class(Particle), intent(in) :: this\n print *, pi * (this%radius + this%radius)**2\n end subroutine ca\n\n subroutine show_p(this)\n class(Particle), intent(in) :: this\n print *, 'name :', this%name, 'radius :', this%radius, 'mass :', this%mass\n end subroutine show_p\n\n real(real64) function ep(this, radius) &\n result(V)\n ! arguments\n class(Electron), intent(in) :: this\n real(real64), intent(in) :: radius\n\n V = 1./(4.*pi*e0) * this%charge / radius\n\n end function ep\n\n subroutine show_e(this)\n class(Electron), intent(in) :: this\n print *, 'name .', this%name, 'radius :', this%radius, 'mass :', this%mass, 'charge :', this%charge\n end subroutine show_e\n\nend module particles_objs\n", "meta": {"hexsha": "fff7eb714375507b0617d67247a3d76f7ba7154a", "size": 1514, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Ejemplo103/MODlearning_class.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": "Ejemplo103/MODlearning_class.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": "Ejemplo103/MODlearning_class.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": 25.2333333333, "max_line_length": 103, "alphanum_fraction": 0.6565389696, "num_tokens": 412, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095294, "lm_q2_score": 0.795658090372256, "lm_q1q2_score": 0.6995002381935739}} {"text": "\tFUNCTION PR_AMSL ( pmsl )\nC************************************************************************\nC* PR_AMSL\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes a standard abbreviated 3-digit display of\t*\nC* pressure containing the tens and units digits and the first digit\t*\nC* after the decimal point. The input is multiplied by 10, truncated,\t*\nC* and the original thousand and hundred digits are dropped. The\t*\nC* following equation is used:\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* AMSL = NINT ( AMOD ( PMSL, 100 ) * 10 )\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function can be used to compute SALT from ALTM, and SMSL from \t*\nC* PMSL.\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PR_AMSL ( PMSL )\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*\tPMSL\t\tREAL\t\tPressure in mb\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPR_AMSL\t\tREAL\t\tStandard abbreviated pressure\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* M. Goodman/RDS\t 2/85\tOriginal source\t\t\t\t*\nC* M. desJardins/GSFC\t 9/85\tCorrected\t\t\t\t*\nC* I. Graffman/RDS\t12/87\tGEMPAK4\t\t\t\t\t*\nC* G. Huffman/GSC\t 7/88\tDocumentation\t\t\t\t*\nC* K. F. Brill/GSC 6/89 Generalized for pmsl and altm\t\t*\nC************************************************************************\n INCLUDE 'GEMPRM.PRM'\n INCLUDE 'ERMISS.FNC'\nC------------------------------------------------------------------------\nC*\tCheck for missing data.\nC\n\tIF ( ERMISS ( pmsl ) ) THEN\n\t pr_amsl = RMISSD\n\t ELSE\nC\nC*\t Drop the leading thousand and/or hundreds digits.\nC\n\t aalt = AMOD ( pmsl, 100. )\nC\nC*\t Include the tenths digit.\nC\n\t aalt = aalt * 10.\n\t PR_AMSL = ANINT ( aalt ) \n\tEND IF\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "376f31dad24c9cbf06d5873880407fde7d2d6853", "size": 1622, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/pr/pramsl.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/pramsl.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/pramsl.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.1923076923, "max_line_length": 73, "alphanum_fraction": 0.5123304562, "num_tokens": 504, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391727723469, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6994738946418905}} {"text": "C SOLVE QUADRATIC EQUATION IN FORTRAN I\r\n READ 100,A,B,C\r\n100 FORMAT(3F12.4)\r\n DISCR = B**2-4*A*C\r\n IF (DISCR) 10,20,30\r\n10 X1=(-B)/(2.*A)\r\n X2=SQRTF(ABSF(DISCR))/(2.*A)\r\n PRINT 110,X1,X2\r\n110 FORMAT(5H X = ,F12.3,4H +i ,F12.3)\r\n PRINT 120,X1,X2\r\n120 FORMAT(5H X = ,F12.3,4H -i ,F12.3)\r\n GOTO 40\r\n20 X1=(-B)/(2.*A)\r\n PRINT 130,X1\r\n130 FORMAT(11H X1 = X2 = ,F12.3)\r\n GOTO 40\r\n30 X1=((-B)+SQRTF(ABSF(DISCR)))/(2.*A)\r\n X2=((-B)-SQRTF(ABSF(DISCR)))/(2.*A)\r\n PRINT 140,X1\r\n140 FORMAT(6H X1 = ,F12.3)\r\n PRINT 150,X2\r\n150 FORMAT(6H X2 = ,F12.3)\r\n40 CONTINUE\r\n STOP 25252\r\n", "meta": {"hexsha": "63dc9541ff4005a66f18c316bfa11a0b2ff34afd", "size": 658, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap1/Fig1-5.for", "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/chap1/Fig1-5.for", "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/chap1/Fig1-5.for", "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": 26.32, "max_line_length": 44, "alphanum_fraction": 0.5121580547, "num_tokens": 298, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381605, "lm_q2_score": 0.757794360334681, "lm_q1q2_score": 0.699473876286231}} {"text": "!==============================================================================\nprogram Au\n!==============================================================================\n! Computes the Universal Elastic Anisotropy Index (A^U) given a set of elastic\n! constants.\n!\n! A^U = Cv:Sr - 6, where Cv is Voigt-averaged stiffness, Sr is Reuss-averaged \n! compliance, and : signifies inner product, such that\n! Cij:Sij = C11*S11 + C12*S21 + C13*S31 ... C66*S66\n!\n! = 5(Gv/Gr) + (Kv/Kr) - 6\n!\n! where 9Kv = c11 + c22 + c33 + 2(c12 + c23 + c31)\n! 15Gv = c11 + c22 + c33 - (c12 + c23 + c31) + 3(c44 + c55 + c66)\n! 1/Kr = s11 + s22 + s33 + 2(s12 + s23 + s31)\n! 15/Gr = 4(s11 + s22 + s33) - 4(s12 + s23 + s31) + 3(s44 + s55 + s66)\n!\n! According to:\n! Hill, R. The elastic behaviour of a crystalline aggregate. \n! P Phys Soc Lond A (1952) vol. 65 (389) pp. 349-355\n!\n! Read ECs from stdin, assuming only 21 are supplied.\n! If first command line argument is set, use that number of elastic constants\n \n use anisotropy_ajn\n \n implicit none\n \n double precision :: C(6,6),S(6,6),Kv,Kr,Gv,Gr,A\n integer :: nec=21,i,j,iostatus=0\n character(len=20) :: arg\n \n! Check for command line options\n if (command_argument_count() > 0) then\n call get_command_argument(1,arg)\n read(arg,*,iostat=iostatus) nec\n if (iostatus /= 0 .or. (nec /= 21 .and. nec /= 36)) then\n write(0,'(3a)') 'Argument \"',trim(arg),'\" not understood.'\n write(0,'(a)') 'Please specify whether 21 or 36 elastic constants input.'\n stop\n endif\n endif\n \n! Loop over all lines of input\n iostatus=0\n do while (iostatus==0)\n \n! Read in constants\n if (nec == 21) then\n read (*,*,iostat=iostatus) ((C(i,j),j=i,6),i=1,6)\n else \n read (*,*,iostat=iostatus) ((C(i,j),j=1,6),i=1,6)\n endif\n \n if (iostatus < 0) stop\n if (iostatus > 0) then \n write(0,'(a)') 'Problem reading elastic constants: stopping.'\n stop\n endif\n \n! Fill in lower diagonal\n do i=1,6; do j=1,6; C(j,i) = C(i,j); enddo; enddo\n \n!! Find stiffness from inverse\n! call inverse(6,6,C,S)\n! \n!! Calculate Voigt moduli\n! Kv = (1./9.) * (C(1,1) + C(2,2) + C(3,3) + 2.*(C(1,2) + C(2,3) + C(3,1)))\n! \n! Gv = (1./15.) * (C(1,1) + C(2,2) + C(3,3) - (C(1,2) + C(2,3) + C(3,1)) + &\n! 3.*(C(4,4) + C(5,5) + C(6,6)))\n! \n!! Calculate Reuss moduli\n! Kr = 1./(S(1,1) + S(2,2) + S(3,3) + 2.*(S(1,2) + S(2,3) + S(3,1)))\n! \n! Gr = 15./(4.*(S(1,1) + S(2,2) + S(3,3)) - 4.*(S(1,2) + S(2,3) + S(3,1)) + &\n! 3.*(S(4,4) + S(5,5) + S(6,6)))\n! \n!! Calculate Au\n! A = 5.*(Gv/Gr) + (Kv/Kr) - 6.\n \n A = CIJ_Au(C)\n \n! Output value to stdout\n write(*,*) A\n\n enddo\n \nend program Au\n!------------------------------------------------------------------------------\n", "meta": {"hexsha": "5c3f10d4544f9564b836c241df271d000e4c9de4", "size": 2918, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Au/Au.f90", "max_stars_repo_name": "anowacki/elasticity", "max_stars_repo_head_hexsha": "ba17bcfc8a8dd8dd881f200997526bffaca3e781", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2017-03-29T21:32:13.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-21T14:47:06.000Z", "max_issues_repo_path": "Au/Au.f90", "max_issues_repo_name": "anowacki/elasticity", "max_issues_repo_head_hexsha": "ba17bcfc8a8dd8dd881f200997526bffaca3e781", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Au/Au.f90", "max_forks_repo_name": "anowacki/elasticity", "max_forks_repo_head_hexsha": "ba17bcfc8a8dd8dd881f200997526bffaca3e781", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-30T05:31:13.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-30T05:31:13.000Z", "avg_line_length": 32.0659340659, "max_line_length": 82, "alphanum_fraction": 0.4780671693, "num_tokens": 1099, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391621868804, "lm_q2_score": 0.7577943603346811, "lm_q1q2_score": 0.699473871473267}} {"text": " SUBROUTINE TD05AD( UNITF, OUTPUT, NP1, MP1, W, A, B, VALR, VALI,\n $ INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC Given a complex valued rational function of frequency (transfer\nC function) G(jW) this routine will calculate its complex value or\nC its magnitude and phase for a specified frequency value.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC UNITF CHARACTER*1\nC Indicates the choice of frequency unit as follows:\nC = 'R': Input frequency W in radians/second;\nC = 'H': Input frequency W in hertz.\nC\nC OUTPUT CHARACTER*1\nC Indicates the choice of co-ordinates for output as folows:\nC = 'C': Cartesian co-ordinates (output real and imaginary\nC parts of G(jW));\nC = 'P': Polar co-ordinates (output magnitude and phase\nC of G(jW)).\nC\nC Input/Output Parameters\nC\nC NP1 (input) INTEGER\nC The order of the denominator + 1, i.e. N + 1. NP1 >= 1.\nC\nC MP1 (input) INTEGER\nC The order of the numerator + 1, i.e. M + 1. MP1 >= 1.\nC\nC W (input) DOUBLE PRECISION\nC The frequency value W for which the transfer function is\nC to be evaluated.\nC\nC A (input) DOUBLE PRECISION array, dimension (NP1)\nC This array must contain the vector of denominator\nC coefficients in ascending order of powers. That is, A(i)\nC must contain the coefficient of (jW)**(i-1) for i = 1,\nC 2,...,NP1.\nC\nC B (input) DOUBLE PRECISION array, dimension (MP1)\nC This array must contain the vector of numerator\nC coefficients in ascending order of powers. That is, B(i)\nC must contain the coefficient of (jW)**(i-1) for i = 1,\nC 2,...,MP1.\nC\nC VALR (output) DOUBLE PRECISION\nC If OUTPUT = 'C', VALR contains the real part of G(jW).\nC If OUTPUT = 'P', VALR contains the magnitude of G(jW)\nC in dBs.\nC\nC VALI (output) DOUBLE PRECISION\nC If OUTPUT = 'C', VALI contains the imaginary part of\nC G(jW).\nC If OUTPUT = 'P', VALI contains the phase of G(jW) in\nC degrees.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value;\nC = 1: if the frequency value W is a pole of G(jW), or all\nC the coefficients of the A polynomial are zero.\nC\nC METHOD\nC\nC By substituting the values of A, B and W in the following\nC formula:\nC\nC B(1)+B(2)*(jW)+B(3)*(jW)**2+...+B(MP1)*(jW)**(MP1-1)\nC G(jW) = ---------------------------------------------------.\nC A(1)+A(2)*(jW)+A(3)*(jW)**2+...+A(NP1)*(jW)**(NP1-1)\nC\nC REFERENCES\nC\nC None.\nC\nC NUMERICAL ASPECTS\nC\nC The algorithm requires 0(N+M) operations.\nC\nC CONTRIBUTORS\nC\nC Release 3.0: V. Sima, Katholieke Univ. Leuven, Belgium, Dec. 1996.\nC Supersedes Release 2.0 routine TD01AD by Control Systems Research\nC Group, Kingston Polytechnic, United Kingdom, March 1981.\nC\nC REVISIONS\nC\nC February 1997.\nC February 22, 1998 (changed the name of TD01MD).\nC\nC KEYWORDS\nC\nC Elementary polynomial operations, frequency response, matrix\nC fraction, polynomial matrix, state-space representation, transfer\nC matrix.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, ONE, EIGHT, TWENTY, NINETY, ONE80, THRE60\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0, EIGHT=8.0D0,\n $ TWENTY=20.0D0, NINETY=90.0D0, ONE80 = 180.0D0,\n $ THRE60=360.0D0 )\nC .. Scalar Arguments ..\n CHARACTER OUTPUT, UNITF\n INTEGER INFO, MP1, NP1\n DOUBLE PRECISION VALI, VALR, W\nC .. Array Arguments ..\n DOUBLE PRECISION A(*), B(*)\nC .. Local Scalars ..\n LOGICAL LOUTPU, LUNITF\n INTEGER I, IPHASE, M, M2, N, N2, NPZERO, NZZERO\n DOUBLE PRECISION BIMAG, BREAL, G, TIMAG, TREAL, TWOPI, W2, WC\n COMPLEX*16 ZTEMP\nC .. External Functions ..\n LOGICAL LSAME\n DOUBLE PRECISION DLAPY2\n COMPLEX*16 ZLADIV\n EXTERNAL DLAPY2, LSAME, ZLADIV\nC .. External Subroutines ..\n EXTERNAL XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC ABS, ATAN, DBLE, DCMPLX, DIMAG, LOG10, MAX, MOD,\n $ SIGN\nC .. Executable Statements ..\nC\n INFO = 0\n LUNITF = LSAME( UNITF, 'H' )\n LOUTPU = LSAME( OUTPUT, 'P' )\nC\nC Test the input scalar arguments.\nC\n IF( .NOT.LUNITF .AND. .NOT.LSAME( UNITF, 'R' ) ) THEN\n INFO = -1\n ELSE IF( .NOT.LOUTPU .AND. .NOT.LSAME( OUTPUT, 'C' ) ) THEN\n INFO = -2\n ELSE IF( NP1.LT.1 ) THEN\n INFO = -3\n ELSE IF( MP1.LT.1 ) THEN\n INFO = -4\n END IF\nC\n IF ( INFO.NE.0 ) THEN\nC\nC Error return.\nC\n CALL XERBLA( 'TD05AD', -INFO )\n RETURN\n END IF\nC\n M = MP1 - 1\n N = NP1 - 1\n WC = W\n TWOPI = EIGHT*ATAN( ONE )\n IF ( LUNITF ) WC = WC*TWOPI\n W2 = WC**2\nC\nC Determine the orders z (NZZERO) and p (NPZERO) of the factors\nC (jW)**k in the numerator and denominator polynomials, by counting\nC the zero trailing coefficients. The value of G(jW) will then be\nC computed as (jW)**(z-p)*m(jW)/n(jW), for appropriate m and n.\nC\n I = 0\nC\n 10 CONTINUE\n I = I + 1\n IF ( I.LE.M ) THEN\n IF ( B(I).EQ.ZERO ) GO TO 10\n END IF\nC\n NZZERO = I - 1\n I = 0\nC\n 20 CONTINUE\n I = I + 1\n IF ( I.LE.N ) THEN\n IF ( A(I).EQ.ZERO ) GO TO 20\n END IF\nC\n NPZERO = I - 1\n IPHASE = NZZERO - NPZERO\nC\n M2 = MOD( M - NZZERO, 2 )\nC\nC Add real parts of the numerator m(jW).\nC\n TREAL = B(MP1-M2)\nC\n DO 30 I = M - 1 - M2, NZZERO + 1, -2\n TREAL = B(I) - W2*TREAL\n 30 CONTINUE\nC\nC Add imaginary parts of the numerator m(jW).\nC\n IF ( M.EQ.0 ) THEN\n TIMAG = ZERO\n ELSE\n TIMAG = B(M+M2)\nC\n DO 40 I = M + M2 - 2, NZZERO + 2, -2\n TIMAG = B(I) - W2*TIMAG\n 40 CONTINUE\nC\n TIMAG = TIMAG*WC\n END IF\nC\n N2 = MOD( N - NPZERO, 2 )\nC\nC Add real parts of the denominator n(jW).\nC\n BREAL = A(NP1-N2)\nC\n DO 50 I = N - 1 - N2, NPZERO + 1, -2\n BREAL = A(I) - W2*BREAL\n 50 CONTINUE\nC\nC Add imaginary parts of the denominator n(jW).\nC\n IF ( N.EQ.0 ) THEN\n BIMAG = ZERO\n ELSE\n BIMAG = A(N+N2)\nC\n DO 60 I = N + N2 - 2, NPZERO + 2, -2\n BIMAG = A(I) - W2*BIMAG\n 60 CONTINUE\nC\n BIMAG = BIMAG*WC\n END IF\nC\n IF ( ( MAX( ABS( BREAL ), ABS( BIMAG ) ).EQ.ZERO ) .OR.\n $ ( W.EQ.ZERO .AND. IPHASE.LT.0 ) ) THEN\nC\nC Error return: The specified frequency W is a pole of G(jW),\nC or all the coefficients of the A polynomial are zero.\nC\n INFO = 1\n ELSE\nC\nC Evaluate the complex number W**(z-p)*m(jW)/n(jW).\nC\n ZTEMP =\n $ ZLADIV( DCMPLX( TREAL, TIMAG ), DCMPLX( BREAL, BIMAG ) )\n VALR = DBLE( ZTEMP )*WC**IPHASE\n VALI = DIMAG( ZTEMP )*WC**IPHASE\nC\n IF ( .NOT.LOUTPU ) THEN\nC\nC Cartesian co-ordinates: Update the result for j**(z-p).\nC\n I = MOD( ABS( IPHASE ), 4 )\n IF ( ( IPHASE.GT.0 .AND. I.GT.1 ) .OR.\n $ ( IPHASE.LT.0 .AND. ( I.EQ.1 .OR. I.EQ.2) ) ) THEN\n VALR = -VALR\n VALI = -VALI\n END IF\nC\n IF ( MOD( I, 2 ).NE.0 ) THEN\n G = VALR\n VALR = -VALI\n VALI = G\n END IF\nC\n ELSE\nC\nC Polar co-ordinates: Compute the magnitude and phase.\nC\n G = DLAPY2( VALR, VALI )\nC\n IF ( VALR.EQ.ZERO ) THEN\n VALI = SIGN( NINETY, VALI )\n ELSE\n VALI = ( ATAN( VALI/VALR )/TWOPI )*THRE60\n IF ( VALI.EQ.ZERO .AND. NZZERO.EQ.M .AND. NPZERO.EQ.N\n $ .AND. B(NZZERO+1)*A(NPZERO+1).LT.ZERO )\n $ VALI = ONE80\n END IF\nC\n VALR = TWENTY*LOG10( G )\nC\n IF ( IPHASE.NE.0 )\n $ VALI = VALI + DBLE( NZZERO - NPZERO )*NINETY\n END IF\nC\n END IF\nC\n RETURN\nC *** Last line of TD05AD ***\n END\n", "meta": {"hexsha": "2849c372d3f07aaac21c9d3d2971ebad9781eec8", "size": 8730, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/TD05AD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/TD05AD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/TD05AD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 29.0033222591, "max_line_length": 72, "alphanum_fraction": 0.5139747995, "num_tokens": 2854, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9230391579526935, "lm_q2_score": 0.7577943603346811, "lm_q1q2_score": 0.699473868264624}} {"text": " SUBROUTINE MB03YT( A, LDA, B, LDB, ALPHAR, ALPHAI, BETA, CSL, SNL,\n $ CSR, SNR )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute the periodic Schur factorization of a real 2-by-2\nC matrix pair (A,B) where B is upper triangular. This routine\nC computes orthogonal (rotation) matrices given by CSL, SNL and CSR,\nC SNR such that\nC\nC 1) if the pair (A,B) has two real eigenvalues, then\nC\nC [ a11 a12 ] := [ CSL SNL ] [ a11 a12 ] [ CSR -SNR ]\nC [ 0 a22 ] [ -SNL CSL ] [ a21 a22 ] [ SNR CSR ]\nC\nC [ b11 b12 ] := [ CSR SNR ] [ b11 b12 ] [ CSL -SNL ]\nC [ 0 b22 ] [ -SNR CSR ] [ 0 b22 ] [ SNL CSL ],\nC\nC 2) if the pair (A,B) has a pair of complex conjugate eigenvalues,\nC then\nC\nC [ a11 a12 ] := [ CSL SNL ] [ a11 a12 ] [ CSR -SNR ]\nC [ a21 a22 ] [ -SNL CSL ] [ a21 a22 ] [ SNR CSR ]\nC\nC [ b11 0 ] := [ CSR SNR ] [ b11 b12 ] [ CSL -SNL ]\nC [ 0 b22 ] [ -SNR CSR ] [ 0 b22 ] [ SNL CSL ].\nC\nC This is a modified version of the LAPACK routine DLAGV2 for\nC computing the real, generalized Schur decomposition of a\nC two-by-two matrix pencil.\nC\nC ARGUMENTS\nC\nC Input/Output Parameters\nC\nC A (input/output) DOUBLE PRECISION array, dimension (LDA,2)\nC On entry, the leading 2-by-2 part of this array must\nC contain the matrix A.\nC On exit, the leading 2-by-2 part of this array contains\nC the matrix A of the pair in periodic Schur form.\nC\nC LDA INTEGER\nC The leading dimension of the array A. LDA >= 2.\nC\nC B (input/output) DOUBLE PRECISION array, dimension (LDB,2)\nC On entry, the leading 2-by-2 part of this array must\nC contain the upper triangular matrix B.\nC On exit, the leading 2-by-2 part of this array contains\nC the matrix B of the pair in periodic Schur form.\nC\nC LDB INTEGER\nC The leading dimension of the array B. LDB >= 2.\nC\nC ALPHAR (output) DOUBLE PRECISION array, dimension (2)\nC ALPHAI (output) DOUBLE PRECISION array, dimension (2)\nC BETA (output) DOUBLE PRECISION array, dimension (2)\nC (ALPHAR(k)+i*ALPHAI(k))*BETA(k) are the eigenvalues of the\nC pair (A,B), k=1,2, i = sqrt(-1). ALPHAI(1) >= 0.\nC\nC CSL (output) DOUBLE PRECISION\nC The cosine of the first rotation matrix.\nC\nC SNL (output) DOUBLE PRECISION\nC The sine of the first rotation matrix.\nC\nC CSR (output) DOUBLE PRECISION\nC The cosine of the second rotation matrix.\nC\nC SNR (output) DOUBLE PRECISION\nC The sine of the second rotation matrix.\nC\nC REFERENCES\nC\nC [1] Van Loan, C.\nC Generalized Singular Values with Algorithms and Applications.\nC Ph. D. Thesis, University of Michigan, 1973.\nC\nC CONTRIBUTORS\nC\nC D. Kressner, Technical Univ. Berlin, Germany, and\nC P. Benner, Technical Univ. Chemnitz, Germany, December 2003.\nC\nC REVISIONS\nC\nC V. Sima, June 2008 (SLICOT version of the HAPACK routine DLAPV2).\nC V. Sima, July 2008, May 2009.\nC\nC KEYWORDS\nC\nC Eigenvalue, periodic Schur form\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, ONE\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )\nC .. Scalar Arguments ..\n INTEGER LDA, LDB\n DOUBLE PRECISION CSL, CSR, SNL, SNR\nC .. Array Arguments ..\n DOUBLE PRECISION A(LDA,*), ALPHAI(2), ALPHAR(2), B(LDB,*),\n $ BETA(2)\nC .. Local Scalars ..\n DOUBLE PRECISION ANORM, BNORM, H1, H2, H3, QQ, R, RR, SAFMIN,\n $ SCALE1, SCALE2, T, ULP, WI, WR1, WR2\nC .. External Functions ..\n DOUBLE PRECISION DLAMCH, DLAPY2\n EXTERNAL DLAMCH, DLAPY2\nC .. External Subroutines ..\n EXTERNAL DLAG2, DLARTG, DLASV2, DROT\nC .. Intrinsic Functions ..\n INTRINSIC ABS, MAX\nC\nC .. Executable Statements ..\nC\n SAFMIN = DLAMCH( 'S' )\n ULP = DLAMCH( 'P' )\nC\nC Scale A.\nC\n ANORM = MAX( ABS( A(1,1) ) + ABS( A(2,1) ),\n $ ABS( A(1,2) ) + ABS( A(2,2) ), SAFMIN )\n A(1,1) = A(1,1) / ANORM\n A(1,2) = A(1,2) / ANORM\n A(2,1) = A(2,1) / ANORM\n A(2,2) = A(2,2) / ANORM\nC\nC Scale B.\nC\n BNORM = MAX( ABS( B(1,1) ), ABS( B(1,2) ) + ABS( B(2,2) ), SAFMIN)\n B(1,1) = B(1,1) / BNORM\n B(1,2) = B(1,2) / BNORM\n B(2,2) = B(2,2) / BNORM\nC\nC Check if A can be deflated.\nC\n IF ( ABS( A(2,1) ).LE.ULP ) THEN\n CSL = ONE\n SNL = ZERO\n CSR = ONE\n SNR = ZERO\n WI = ZERO\n A(2,1) = ZERO\n B(2,1) = ZERO\nC\nC Check if B is singular.\nC\n ELSE IF ( ABS( B(1,1) ).LE.ULP ) THEN\n CALL DLARTG( A(2,2), A(2,1), CSR, SNR, T )\n SNR = -SNR\n CALL DROT( 2, A(1,1), 1, A(1,2), 1, CSR, SNR )\n CALL DROT( 2, B(1,1), LDB, B(2,1), LDB, CSR, SNR )\n CSL = ONE\n SNL = ZERO\n WI = ZERO\n A(2,1) = ZERO\n B(1,1) = ZERO\n B(2,1) = ZERO\n ELSE IF( ABS( B(2,2) ).LE.ULP ) THEN\n CALL DLARTG( A(1,1), A(2,1), CSL, SNL, R )\n CSR = ONE\n SNR = ZERO\n WI = ZERO\n CALL DROT( 2, A(1,1), LDA, A(2,1), LDA, CSL, SNL )\n CALL DROT( 2, B(1,1), 1, B(1,2), 1, CSL, SNL )\n A(2,1) = ZERO\n B(2,1) = ZERO\n B(2,2) = ZERO\n ELSE\nC\nC B is nonsingular, first compute the eigenvalues of A / adj(B).\nC\n R = B(1,1)\n B(1,1) = B(2,2)\n B(2,2) = R\n B(1,2) = -B(1,2)\n CALL DLAG2( A, LDA, B, LDB, SAFMIN, SCALE1, SCALE2, WR1, WR2,\n $ WI )\nC\n IF( WI.EQ.ZERO ) THEN\nC\nC Two real eigenvalues, compute s*A-w*B.\nC\n H1 = SCALE1*A(1,1) - WR1*B(1,1)\n H2 = SCALE1*A(1,2) - WR1*B(1,2)\n H3 = SCALE1*A(2,2) - WR1*B(2,2)\nC\n RR = DLAPY2( H1, H2 )\n QQ = DLAPY2( SCALE1*A(2,1), H3 )\nC\n IF ( RR.GT.QQ ) THEN\nC\nC Find right rotation matrix to zero 1,1 element of\nC (sA - wB).\nC\n CALL DLARTG( H2, H1, CSR, SNR, T )\nC\n ELSE\nC\nC Find right rotation matrix to zero 2,1 element of\nC (sA - wB).\nC\n CALL DLARTG( H3, SCALE1*A(2,1), CSR, SNR, T )\nC\n END IF\nC\n SNR = -SNR\n CALL DROT( 2, A(1,1), 1, A(1,2), 1, CSR, SNR )\n CALL DROT( 2, B(1,1), 1, B(1,2), 1, CSR, SNR )\nC\nC Compute inf norms of A and B.\nC\n H1 = MAX( ABS( A(1,1) ) + ABS( A(1,2) ),\n $ ABS( A(2,1) ) + ABS( A(2,2) ) )\n H2 = MAX( ABS( B(1,1) ) + ABS( B(1,2) ),\n $ ABS( B(2,1) ) + ABS( B(2,2) ) )\nC\n IF( ( SCALE1*H1 ).GE.ABS( WR1 )*H2 ) THEN\nC\nC Find left rotation matrix Q to zero out B(2,1).\nC\n CALL DLARTG( B(1,1), B(2,1), CSL, SNL, R )\nC\n ELSE\nC\nC Find left rotation matrix Q to zero out A(2,1).\nC\n CALL DLARTG( A(1,1), A(2,1), CSL, SNL, R )\nC\n END IF\nC\n CALL DROT( 2, A(1,1), LDA, A(2,1), LDA, CSL, SNL )\n CALL DROT( 2, B(1,1), LDB, B(2,1), LDB, CSL, SNL )\nC\n A(2,1) = ZERO\n B(2,1) = ZERO\nC\nC Re-adjoint B.\nC\n R = B(1,1)\n B(1,1) = B(2,2)\n B(2,2) = R\n B(1,2) = -B(1,2)\nC\n ELSE\nC\nC A pair of complex conjugate eigenvalues:\nC first compute the SVD of the matrix adj(B).\nC\n R = B(1,1)\n B(1,1) = B(2,2)\n B(2,2) = R\n B(1,2) = -B(1,2)\n CALL DLASV2( B(1,1), B(1,2), B(2,2), R, T, SNL, CSL,\n $ SNR, CSR )\nC\nC Form (A,B) := Q(A,adj(B))Z' where Q is left rotation matrix\nC and Z is right rotation matrix computed from DLASV2.\nC\n CALL DROT( 2, A(1,1), LDA, A(2,1), LDA, CSL, SNL )\n CALL DROT( 2, B(1,1), LDB, B(2,1), LDB, CSR, SNR )\n CALL DROT( 2, A(1,1), 1, A(1,2), 1, CSR, SNR )\n CALL DROT( 2, B(1,1), 1, B(1,2), 1, CSL, SNL )\nC\n B(2,1) = ZERO\n B(1,2) = ZERO\n END IF\nC\n END IF\nC\nC Unscaling\nC\n R = B(1,1)\n T = B(2,2)\n A(1,1) = ANORM*A(1,1)\n A(2,1) = ANORM*A(2,1)\n A(1,2) = ANORM*A(1,2)\n A(2,2) = ANORM*A(2,2)\n B(1,1) = BNORM*B(1,1)\n B(2,1) = BNORM*B(2,1)\n B(1,2) = BNORM*B(1,2)\n B(2,2) = BNORM*B(2,2)\nC\n IF( WI.EQ.ZERO ) THEN\n ALPHAR(1) = A(1,1)\n ALPHAR(2) = A(2,2)\n ALPHAI(1) = ZERO\n ALPHAI(2) = ZERO\n BETA(1) = B(1,1)\n BETA(2) = B(2,2)\n ELSE\n WR1 = ANORM*WR1\n WI = ANORM*WI\n IF ( ABS( WR1 ).GT.ONE .OR. WI.GT.ONE ) THEN\n WR1 = WR1*R\n WI = WI*R\n R = ONE\n END IF\n IF ( ABS( WR1 ).GT.ONE .OR. ABS( WI ).GT.ONE ) THEN\n WR1 = WR1*T\n WI = WI*T\n T = ONE\n END IF\n ALPHAR(1) = ( WR1 / SCALE1 )*R*T\n ALPHAI(1) = ABS( ( WI / SCALE1 )*R*T )\n ALPHAR(2) = ALPHAR(1)\n ALPHAI(2) = -ALPHAI(1)\n BETA(1) = BNORM\n BETA(2) = BNORM\n END IF\n RETURN\nC *** Last line of MB03YT ***\n END\n", "meta": {"hexsha": "b12b5bc912f19ee1887642d756e2177b308fca04", "size": 9538, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB03YT.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB03YT.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB03YT.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 29.9937106918, "max_line_length": 72, "alphanum_fraction": 0.4755713986, "num_tokens": 3602, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9449947101574299, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.6994608621372311}} {"text": "c****************************************************************\nc\nc Various curvature functions\nc \nc\nc****************************************************************\nc**\nc**\tFILE NAME: curvature.f\nc**\nc** DATE WRITTEN: 12/02/93\nc**\nc** PROGRAMMER:Scott Hensley\nc**\nc** \tFUNCTIONAL DESCRIPTION: This routine computes the curvature for \nc** of various types required for ellipsoidal or spherical earth \nc** calculations. \nc**\nc** ROUTINES CALLED:none\nc** \nc** NOTES: none\nc**\nc** UPDATE LOG:\nc**\nc*****************************************************************\n\n real*8 function reast(r_a,r_e2,r_lat)\n\n \timplicit none\n real*8 r_a,r_e2,r_lat\n \n reast = r_a/sqrt(1.d0 - r_e2*sin(r_lat)**2) \n \n end \n\n real*8 function rnorth(r_a,r_e2,r_lat)\n\n \timplicit none\n real*8 r_a,r_e2,r_lat\n \n rnorth = (r_a*(1.d0 - r_e2))/(1.d0 - r_e2*sin(r_lat)**2)**(1.5d0) \n\n end\n\n real*8 function rdir(r_a,r_e2,r_hdg,r_lat)\n\n \timplicit none\n real*8 r_a,r_e2,r_lat,r_hdg,r_re,r_rn,reast,rnorth\n \n r_re = reast(r_a,r_e2,r_lat)\n r_rn = rnorth(r_a,r_e2,r_lat)\n\n rdir = (r_re*r_rn)/(r_re*cos(r_hdg)**2 + r_rn*sin(r_hdg)**2) \n\n end \n\n", "meta": {"hexsha": "aa3d32f8ead20c3dc9cb93e6c648c05ac7b2b3f3", "size": 1293, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "contrib/alos2proc_f/src/curvature.f", "max_stars_repo_name": "vincentschut/isce2", "max_stars_repo_head_hexsha": "1557a05b7b6a3e65abcfc32f89c982ccc9b65e3c", "max_stars_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_stars_count": 1133, "max_stars_repo_stars_event_min_datetime": "2022-01-07T21:24:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-07T21:33:08.000Z", "max_issues_repo_path": "contrib/alos2proc_f/src/curvature.f", "max_issues_repo_name": "vincentschut/isce2", "max_issues_repo_head_hexsha": "1557a05b7b6a3e65abcfc32f89c982ccc9b65e3c", "max_issues_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_issues_count": 276, "max_issues_repo_issues_event_min_datetime": "2019-02-10T07:18:28.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:45:55.000Z", "max_forks_repo_path": "contrib/alos2proc_f/src/curvature.f", "max_forks_repo_name": "vincentschut/isce2", "max_forks_repo_head_hexsha": "1557a05b7b6a3e65abcfc32f89c982ccc9b65e3c", "max_forks_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_forks_count": 235, "max_forks_repo_forks_event_min_datetime": "2019-02-10T05:00:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T07:37:24.000Z", "avg_line_length": 23.0892857143, "max_line_length": 74, "alphanum_fraction": 0.4802784223, "num_tokens": 374, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096181702032, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6994348240390018}} {"text": "\tsubroutine tuispl (xa, ya, y2, x, y)\nC\nC Interpolate at point X using cubic splines. The array Y2 must have\nC previously been computed by calling TUCSPL. Note that XA, YA, Y2\nC are two-element subarrays of the arrays with the same names elsewhere.\nC Input and output are all double precision.\nC This routine was copied with slight modifications from the SPLINT\nC subroutine in Numerical Recipes by Press, Flannery, Teukolsky and\nC Vetterling.\nC\nC XA\t\ti: pair of independent-variable values\nC YA\t\ti: pair of dependent-variable values\nC Y2\t\ti: second derivatives of YA at each point\nC X\t\ti: value at which spline is to be computed\nC Y\t\to: interpolated value at X\nC\nCH Phil Hodge, 14-Apr-1988 Subroutine copied from Numerical Recipes SPLINT.\nC\n\tdouble precision xa(2), ya(2), y2(2), x, y\nC--\n\tdouble precision h, a, b\n\n\th = xa(2) - xa(1)\n\n\ta = (xa(2) - x) / h\n\tb = (x - xa(1)) / h\n\ty = a * ya(1) + b * ya(2) +\n +\t\t((a**3 - a) * y2(1) + (b**3 - b) * y2(2))\n +\t\t* h * h / 6.\n\n\treturn\n\tend\n", "meta": {"hexsha": "2f4c68b85e1f2a2f44fd7054445bad0af476be6b", "size": 1009, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iraf.v2161/pkg/utilities/nttools/trebin/tuispl.f", "max_stars_repo_name": "ysBach/irafdocgen", "max_stars_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:19:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T16:48:42.000Z", "max_issues_repo_path": "iraf.v2161/pkg/utilities/nttools/trebin/tuispl.f", "max_issues_repo_name": "ysBach/irafdocgen", "max_issues_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-30T13:48:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-02T19:40:25.000Z", "max_forks_repo_path": "iraf.v2161/pkg/utilities/nttools/trebin/tuispl.f", "max_forks_repo_name": "ysBach/irafdocgen", "max_forks_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_forks_repo_licenses": ["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.5757575758, "max_line_length": 77, "alphanum_fraction": 0.6689791873, "num_tokens": 351, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096227509861, "lm_q2_score": 0.7634837527911057, "lm_q1q2_score": 0.699434812745967}} {"text": "c\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc . .\nc . copyright (c) 1998 by UCAR .\nc . .\nc . University Corporation for Atmospheric Research .\nc . .\nc . all rights reserved .\nc . .\nc . .\nc . SPHEREPACK3.0 .\nc . .\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc\nc\nc\nc ... file igradgc.f\nc\nc this file includes documentation and code for\nc subroutine igradgc i\nc\nc ... files which must be loaded with igradgc.f\nc\nc sphcom.f, hrfft.f, shsgc.f,vhagc.f\nc\nc subroutine igradgc(nlat,nlon,isym,nt,sf,isf,jsf,br,bi,mdb,ndb,\nc + wshsgc,lshsgc,work,lwork,ierror)\nc\nc let br,bi,cr,ci be the vector spherical harmonic coefficients\nc precomputed by vhagc for a vector field (v,w). let (v',w') be\nc the irrotational component of (v,w) (i.e., (v',w') is generated\nc by assuming cr,ci are zero and synthesizing br,bi with vhsgs).\nc then subroutine igradgc computes a scalar field sf such that\nc\nc gradient(sf) = (v',w').\nc\nc i.e.,\nc\nc v'(i,j) = d(sf(i,j))/dtheta (colatitudinal component of\nc the gradient)\nc and\nc\nc w'(i,j) = 1/sint*d(sf(i,j))/dlambda (east longitudinal component\nc of the gradient)\nc\nc at the gaussian colatitude theta(i) (see nlat as input parameter)\nc and longitude lambda(j) = (j-1)*2*pi/nlon where sint = sin(theta(i)).\nc\nc note: for an irrotational vector field (v,w), subroutine igradgc\nc computes a scalar field whose gradient is (v,w). in ay case,\nc subroutine igradgc \"inverts\" the gradient subroutine gradgc.\nc\nc input parameters\nc\nc nlat the number of points in the gaussian colatitude grid on the\nc full sphere. these lie in the interval (0,pi) and are computed\nc in radians in theta(1) <...< theta(nlat) by subroutine gaqd.\nc if nlat is odd the equator will be included as the grid point\nc theta((nlat+1)/2). if nlat is even the equator will be\nc excluded as a grid point and will lie half way between\nc theta(nlat/2) and theta(nlat/2+1). nlat must be at least 3.\nc note: on the half sphere, the number of grid points in the\nc colatitudinal direction is nlat/2 if nlat is even or\nc (nlat+1)/2 if nlat is odd.\nc\nc nlon the number of distinct londitude points. nlon determines\nc the grid increment in longitude as 2*pi/nlon. for example\nc nlon = 72 for a five degree grid. nlon must be greater than\nc 3. the efficiency of the computation is improved when nlon\nc is a product of small prime numbers.\nc\nc\nc isym a parameter which determines whether the scalar field sf is\nc computed on the full or half sphere as follows:\nc\nc = 0\nc\nc the symmetries/antsymmetries described in isym=1,2 below\nc do not exist in (v,w) about the equator. in this case sf\nc is neither symmetric nor antisymmetric about the equator.\nc sf is computed on the entire sphere. i.e., in the array\nc sf(i,j) for i=1,...,nlat and j=1,...,nlon\nc\nc = 1\nc\nc w is antisymmetric and v is symmetric about the equator.\nc in this case sf is antisymmetyric about the equator and\nc is computed for the northern hemisphere only. i.e.,\nc if nlat is odd sf is computed in the array sf(i,j) for\nc i=1,...,(nlat+1)/2 and for j=1,...,nlon. if nlat is even\nc sf is computed in the array sf(i,j) for i=1,...,nlat/2\nc and j=1,...,nlon.\nc\nc = 2\nc\nc w is symmetric and v is antisymmetric about the equator.\nc in this case sf is symmetyric about the equator and\nc is computed for the northern hemisphere only. i.e.,\nc if nlat is odd sf is computed in the array sf(i,j) for\nc i=1,...,(nlat+1)/2 and for j=1,...,nlon. if nlat is even\nc sf is computed in the array sf(i,j) for i=1,...,nlat/2\nc and j=1,...,nlon.\nc\nc\nc nt nt is the number of scalar and vector fields. some\nc computational efficiency is obtained for multiple fields.\nc the arrays br,bi, and sf can be three dimensional corresponding\nc to an indexed multiple vector field (v,w). in this case,\nc multiple scalar synthesis will be performed to compute each\nc scalar field. the third index for br,bi, and sf is the synthesis\nc index which assumes the values k = 1,...,nt. for a single\nc synthesis set nt = 1. the description of the remaining\nc parameters is simplified by assuming that nt=1 or that br,bi,\nc and sf are two dimensional arrays.\nc\nc isf the first dimension of the array sf as it appears in\nc the program that calls igradgc. if isym = 0 then isf\nc must be at least nlat. if isym = 1 or 2 and nlat is\nc even then isf must be at least nlat/2. if isym = 1 or 2\nc and nlat is odd then isf must be at least (nlat+1)/2.\nc\nc jsf the second dimension of the array sf as it appears in\nc the program that calls igradgc. jsf must be at least nlon.\nc\nc br,bi two or three dimensional arrays (see input parameter nt)\nc that contain vector spherical harmonic coefficients\nc of the vector field (v,w) as computed by subroutine vhagc.\nc *** br,bi must be computed by vhagc prior to calling igradgc.\nc\nc mdb the first dimension of the arrays br and bi as it appears in\nc the program that calls igradgc (and vhagc). mdb must be at\nc least min0(nlat,nlon/2) if nlon is even or at least\nc min0(nlat,(nlon+1)/2) if nlon is odd.\nc\nc ndb the second dimension of the arrays br and bi as it appears in\nc the program that calls igradgc (and vhagc). ndb must be at\nc least nlat.\nc\nc\nc wshsgc an array which must be initialized by subroutine shsgci.\nc once initialized,\nc wshsgc can be used repeatedly by igradgc as long as nlon\nc and nlat remain unchanged. wshsgc must not be altered\nc between calls of igradgc.\nc\nc\nc lshsgc the dimension of the array wshsgc as it appears in the\nc program that calls igradgc. define\nc\nc l1 = min0(nlat,(nlon+2)/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc and\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd.\nc\nc\nc then lshsgc must be at least\nc\nc nlat*(2*l2+3*l1-2)+3*l1*(1-l1)/2+nlon+15\nc\nc\nc work a work array that does not have to be saved.\nc\nc lwork the dimension of the array work as it appears in the\nc program that calls igradgc define\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc l1 = min0(nlat,(nlon+2)/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\n\nc if isym is zero then lwork must be at least\nc\nc nlat*(nlon*nt+max0(3*l2,nlon)+2*nt*l1+1)\nc\nc if isym is not zero then lwork must be at least\nc\nc l2*(nlon*nt+max0(3*nlat,nlon)) + nlat*(2*nt*l1+1)\nc\nc\nc\nc **************************************************************\nc\nc output parameters\nc\nc\nc sf a two or three dimensional array (see input parameter nt) that\nc contain a scalar field whose gradient is the irrotational\nc component of the vector field (v,w). the vector spherical\nc harmonic coefficients br,bi were precomputed by subroutine\nc vhagc. sf(i,j) is given at the gaussian colatitude theta(i)\nc and longitude lambda(j) = (j-1)*2*pi/nlon. the index ranges\nc are defined at input parameter isym.\nc\nc\nc ierror = 0 no errors\nc = 1 error in the specification of nlat\nc = 2 error in the specification of nlon\nc = 3 error in the specification of isym\nc = 4 error in the specification of nt\nc = 5 error in the specification of isf\nc = 6 error in the specification of jsf\nc = 7 error in the specification of mdb\nc = 8 error in the specification of ndb\nc = 9 error in the specification of lshsgc\nc = 10 error in the specification of lwork\nc\nc **********************************************************************\nc \n subroutine igradgc(nlat,nlon,isym,nt,sf,isf,jsf,br,bi,mdb,ndb,\n +wshsgc,lshsgc,work,lwork,ierror)\n dimension sf(isf,jsf,nt)\n dimension br(mdb,ndb,nt),bi(mdb,ndb,nt)\n dimension wshsgc(lshsgc),work(lwork)\nc\nc check input parameters\nc\n ierror = 1\n if(nlat .lt. 3) return\n ierror = 2\n if(nlon .lt. 4) return\n ierror = 3\n if(isym.lt.0 .or. isym.gt.2) return\n ierror = 4\n if(nt .lt. 0) return\n ierror = 5\n imid = (nlat+1)/2\n if((isym.eq.0 .and. isf.lt.nlat) .or.\n + (isym.ne.0 .and. isf.lt.imid)) return\n ierror = 6\n if(jsf .lt. nlon) return\n ierror = 7\n mmax = min0(nlat,(nlon+2)/2)\n if(mdb .lt. min0(nlat,(nlon+1)/2)) return\n ierror = 8\n if(ndb .lt. nlat) return\n ierror = 9\nc\nc verify saved work space length\nc\n l2 = (nlat+mod(nlat,2))/2\n l1 = min0((nlon+2)/2,nlat)\n if (lshsgc .lt. nlat*(2*l2+3*l1-2)+3*l1*(1-l1)/2+nlon+15)return\n ierror = 10\nc\nc set minimum and verify unsaved work space\nc\n ls = nlat\n if(isym .gt. 0) ls = imid\n nln = nt*ls*nlon\nc\nc set first dimension for a,b (as requried by shsgc)\nc\n mab = min0(nlat,nlon/2+1)\n mn = mab*nlat*nt\nc lwkmin = nln+ls*nlon+2*mn+nlat\n if (isym .eq. 0) then\n\tlwkmin = nlat*(nt*nlon+max0(3*l2,nlon)+2*nt*l1+1)\n else\n\tlwkmin = l2*(nt*nlon+max0(3*nlat,nlon))+nlat*(2*nt*l1+1)\n end if\n if (lwork .lt. lwkmin) return\n ierror = 0\nc\nc set work space pointers\nc\n ia = 1\n ib = ia + mn\n is = ib + mn\n iwk = is + nlat\n liwk = lwork-2*mn-nlat\n call igrdgc1(nlat,nlon,isym,nt,sf,isf,jsf,work(ia),work(ib),mab,\n +work(is),mdb,ndb,br,bi,wshsgc,lshsgc,work(iwk),liwk,ierror)\n return\n end\n\n subroutine igrdgc1(nlat,nlon,isym,nt,sf,isf,jsf,a,b,mab,\n +sqnn,mdb,ndb,br,bi,wsav,lsav,wk,lwk,ierror)\n dimension sf(isf,jsf,nt)\n dimension br(mdb,ndb,nt),bi(mdb,ndb,nt),sqnn(nlat)\n dimension a(mab,nlat,nt),b(mab,nlat,nt)\n dimension wsav(lsav),wk(lwk)\nc\nc preset coefficient multiplyers in vector\nc\n do 1 n=2,nlat\n fn = float(n-1)\n sqnn(n) = 1.0/sqrt(fn*(fn+1.))\n 1 continue\nc\nc set upper limit for vector m subscript\nc\n mmax = min0(nlat,(nlon+1)/2)\nc\nc compute multiple scalar field coefficients\nc\n do 2 k=1,nt\nc\nc preset to 0.0\nc\n do 3 n=1,nlat\n do 4 m=1,mab\n a(m,n,k) = 0.0\n b(m,n,k) = 0.0\n 4 continue\n 3 continue\nc\nc compute m=0 coefficients\nc\n do 5 n=2,nlat\n a(1,n,k) = br(1,n,k)*sqnn(n)\n b(1,n,k)= bi(1,n,k)*sqnn(n)\n 5 continue\nc\nc compute m>0 coefficients\nc\n do 6 m=2,mmax\n do 7 n=m,nlat\n a(m,n,k) = sqnn(n)*br(m,n,k)\n b(m,n,k) = sqnn(n)*bi(m,n,k)\n 7 continue\n 6 continue\n 2 continue\nc\nc scalar sythesize a,b into sf\nc\n call shsgc(nlat,nlon,isym,nt,sf,isf,jsf,a,b,mab,nlat,wsav,\n + lsav,wk,lwk,ierror)\n return\n end\n", "meta": {"hexsha": "8aa44284bddf63e9dab283ba4fa6adbe25453b49", "size": 12196, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "contrib/spherepack/Src/igradgc.f", "max_stars_repo_name": "xylar/cdat", "max_stars_repo_head_hexsha": "8a5080cb18febfde365efc96147e25f51494a2bf", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 62, "max_stars_repo_stars_event_min_datetime": "2018-03-30T15:46:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-08T23:30:24.000Z", "max_issues_repo_path": "contrib/spherepack/Src/igradgc.f", "max_issues_repo_name": "xylar/cdat", "max_issues_repo_head_hexsha": "8a5080cb18febfde365efc96147e25f51494a2bf", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 114, "max_issues_repo_issues_event_min_datetime": "2018-03-21T01:12:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-05T12:29:54.000Z", "max_forks_repo_path": "contrib/spherepack/Src/igradgc.f", "max_forks_repo_name": "CDAT/uvcdat", "max_forks_repo_head_hexsha": "5133560c0c049b5c93ee321ba0af494253b44f91", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2018-06-06T02:42:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-26T03:27:00.000Z", "avg_line_length": 36.6246246246, "max_line_length": 78, "alphanum_fraction": 0.559527714, "num_tokens": 3814, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096181702032, "lm_q2_score": 0.7634837527911057, "lm_q1q2_score": 0.6994348092486137}} {"text": "program test_argsort\nuse types, only: dp\nuse utils, only: assert\nuse sorting, only: argsort\nimplicit none\n\ncall assert(all(argsort([4, 3, 2, 1, 5]) == [4, 3, 2, 1, 5]))\ncall assert(all(argsort([10, 9, 8, 7, 6]) == [5, 4, 3, 2, 1]))\ncall assert(all(argsort([1, -1]) == [2, 1]))\ncall assert(all(argsort([1, 2, 2, 2, 3]) == [1, 2, 3, 4, 5]))\ncall assert(all(argsort([2, 2, 2, 3, 1]) == [5, 2, 3, 1, 4]))\n\ncall assert(all(argsort([4.0_dp, 3.0_dp, 2.0_dp, 1.0_dp, 5.0_dp]) == &\n [4, 3, 2, 1, 5]))\ncall assert(all(argsort([10.0_dp, 9.0_dp, 8.0_dp, 7.0_dp, 6.0_dp]) == &\n [5, 4, 3, 2, 1]))\ncall assert(all(argsort([1.0_dp, -1.0_dp]) == [2, 1]))\ncall assert(all(argsort([1.0_dp, 2.0_dp, 2.0_dp, 2.0_dp, 3.0_dp]) == &\n [1, 2, 3, 4, 5]))\ncall assert(all(argsort([2.0_dp, 2.0_dp, 2.0_dp, 3.0_dp, 1.0_dp]) == &\n [5, 2, 3, 1, 4]))\n\ncall assert(all(argsort([4.1_dp, 2.1_dp, 2.05_dp, -1.5_dp, 4.2_dp]) == &\n [4, 3, 2, 1, 5]))\n\nend program\n", "meta": {"hexsha": "17fb39fe1e8c0a4308234e7eb63c7b0bc47ee52e", "size": 959, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/sort/test_argsort.f90", "max_stars_repo_name": "my81656581/fortran-utils", "max_stars_repo_head_hexsha": "b43bd24cd421509a5bc6d3b9c3eeae8ce856ed88", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 163, "max_stars_repo_stars_event_min_datetime": "2015-02-12T09:55:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T23:08:58.000Z", "max_issues_repo_path": "tests/sort/test_argsort.f90", "max_issues_repo_name": "wu2meng3/fortran-utils", "max_issues_repo_head_hexsha": "b43bd24cd421509a5bc6d3b9c3eeae8ce856ed88", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2016-10-08T21:18:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-24T15:11:50.000Z", "max_forks_repo_path": "tests/sort/test_argsort.f90", "max_forks_repo_name": "wu2meng3/fortran-utils", "max_forks_repo_head_hexsha": "b43bd24cd421509a5bc6d3b9c3eeae8ce856ed88", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 48, "max_forks_repo_forks_event_min_datetime": "2015-03-20T10:26:44.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-23T11:09:47.000Z", "avg_line_length": 35.5185185185, "max_line_length": 72, "alphanum_fraction": 0.5453597497, "num_tokens": 484, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424295406087, "lm_q2_score": 0.8267118026095991, "lm_q1q2_score": 0.6993505908294604}} {"text": "! { dg-do run }\n! Vector subscripts, ranks and shapes of initialization expressions (PRs 29393,\n! 29630 and 29679)\nprogram test\n\n implicit none\n integer :: i, j\n integer, parameter :: a(4,4,4) = reshape([ (i,i=1,64) ], [4,4,4])\n integer, parameter :: v(4) = [4, 1, 3, 2]\n\n integer :: b1(3,3) = a(1:3, 2, 2:4)\n integer :: b2(1,3) = a(2:2, 4, [1,4,3])\n integer :: b2b(3) = a([1,4,3], 2, 4)\n integer :: b3(4) = a(1, v, 3)\n integer :: b4(3,3) = a(v([2,4,3]), 2, [2,3,4])\n\n if (any(b1 /= reshape([21,22,23, 37,38,39, 53,54,55], [3,3]))) STOP 1\n if (any(b2 /= reshape([14, 62, 46], [1,3]))) STOP 2\n if (any(b2b /= [53, 56, 55])) STOP 3\n if (any(b3 /= [45, 33, 41, 37])) STOP 4\n if (any(b4 /= reshape([21,22,23, 37,38,39, 53,54,55], [3,3]))) STOP 5\nend program test\n", "meta": {"hexsha": "adcc87b54d98ea52e5533f67f9b40ca30239a0ea", "size": 801, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/initialization_2.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/initialization_2.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/initialization_2.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": 34.8260869565, "max_line_length": 79, "alphanum_fraction": 0.5218476904, "num_tokens": 375, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706734, "lm_q2_score": 0.8459424353665382, "lm_q1q2_score": 0.6993505884223855}} {"text": "! { dg-do compile }\n! { dg-options \"-fdump-tree-original\" }\n!\n! PR fortran/57785\n!\n! Contributed by Kontantinos Anagnostopoulos\n!\n! The implicit complex conjugate was missing for DOT_PRODUCT\n\n\n! For the following, the compile-time simplification fails for SUM;\n! see PR fortran/56342. Hence, a manually expanded SUM is used.\n\n!if (DOT_PRODUCT ((/ (1.0, 2.0), (2.0, 3.0) /), (/ (1.0, 1.0), (1.0, 4.0) /)) &\n! /= SUM (CONJG ((/ (1.0, 2.0), (2.0, 3.0) /))*(/ (1.0, 1.0), (1.0, 4.0) /))) &\n! call abort ()\n!\n!if (ANY (MATMUL ((/ (1.0, 2.0), (2.0, 3.0) /), &\n! RESHAPE ((/ (1.0, 1.0), (1.0, 4.0) /),(/2, 1/))) /= &\n! SUM ((/ (1.0, 2.0), (2.0, 3.0) /)*(/ (1.0, 1.0), (1.0, 4.0) /)))) &\n! call abort () \n\n\nif (DOT_PRODUCT ((/ (1.0, 2.0), (2.0, 3.0) /), (/ (1.0, 1.0), (1.0, 4.0) /)) &\n /= CONJG (cmplx(1.0, 2.0)) * cmplx(1.0, 1.0) &\n + CONJG (cmplx(2.0, 3.0)) * cmplx(1.0, 4.0)) &\n call abort ()\n\nif (ANY (MATMUL ((/ (1.0, 2.0), (2.0, 3.0) /), &\n RESHAPE ((/ (1.0, 1.0), (1.0, 4.0) /),(/2, 1/))) &\n /= cmplx(1.0, 2.0) * cmplx(1.0, 1.0) &\n + cmplx(2.0, 3.0) * cmplx(1.0, 4.0))) &\n call abort () \nend\n\n\n! { dg-final { scan-tree-dump-not \"abort\" \"original\" } }\n", "meta": {"hexsha": "d3a037db73a3252d21ad152b81d3979d53171245", "size": 1417, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.dg/dot_product_2.f90", "max_stars_repo_name": "best08618/asylo", "max_stars_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-05-02T17:34:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-17T10:15:18.000Z", "max_issues_repo_path": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.dg/dot_product_2.f90", "max_issues_repo_name": "best08618/asylo", "max_issues_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "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": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.dg/dot_product_2.f90", "max_forks_repo_name": "best08618/asylo", "max_forks_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-27T00:22:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-01T09:41:02.000Z", "avg_line_length": 37.2894736842, "max_line_length": 81, "alphanum_fraction": 0.4036697248, "num_tokens": 606, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706734, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.6993505852114759}} {"text": "SUBROUTINE DfDx_1D_Uneven(f,nx,coeffs,rank,fx)\n!\n! A subroutine to take the first derivative of the function f on an \n! arbitrary grid with one-sided derivatives towards the two boundaries \n! using the coefficients coeffs(1:rank,2,1:nx). The coefficients are \n! computed in BuildStencil_1D_Uneven. \n!\n! By Allan P. Engsig-Karup.\n USE Precision\n IMPLICIT NONE\n INTEGER nx, i, rank, alpha\n REAL(kind=long) :: f(nx), coeffs(rank,rank,nx), fx(nx)\n\n alpha=(rank-1)/2\n\n\n ! One-sided derivatives towards the left end\n do i=1,alpha\n fx(i)=Dot_Product(f(1:rank),coeffs(1:rank,2,i))\n end do\n ! Centered schemes for the interior\n do i=alpha+1,Nx-alpha\n fx(i)=Dot_Product(f(i-alpha:i+alpha),coeffs(1:rank,2,i))\n end do\n ! One-sided derivatives towards the right end\n do i=Nx-alpha+1,Nx\n fx(i)=Dot_Product(f(Nx-rank+1:Nx),coeffs(1:rank,2,i))\n end do\n\n RETURN\nEND SUBROUTINE DfDx_1D_Uneven\n", "meta": {"hexsha": "98bb2eebd7f4d6bc677d165363f3c60d3470289f", "size": 905, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/functions/DfDx_1D_Uneven.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/DfDx_1D_Uneven.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/DfDx_1D_Uneven.f90", "max_forks_repo_name": "apengsigkarup/OceanWave3D", "max_forks_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2015-10-01T12:17:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-02T16:23:37.000Z", "avg_line_length": 28.28125, "max_line_length": 71, "alphanum_fraction": 0.7093922652, "num_tokens": 305, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107878954106, "lm_q2_score": 0.7461389817407017, "lm_q1q2_score": 0.6992895029566824}} {"text": " FUNCTION rofunc(b)\r\n INTEGER NMAX\r\n REAL rofunc,b,EPS\r\n PARAMETER (NMAX=1000,EPS=1.e-7)\r\nCU USES select\r\n INTEGER j,ndata\r\n REAL aa,abdev,d,sum,arr(NMAX),x(NMAX),y(NMAX),select\r\n COMMON /arrays/ x,y,arr,aa,abdev,ndata\r\n do 11 j=1,ndata\r\n arr(j)=y(j)-b*x(j)\r\n11 continue\r\n if (mod(ndata,2).eq.0) then\r\n j=ndata/2\r\n aa=0.5*(select(j,ndata,arr)+select(j+1,ndata,arr))\r\n else\r\n aa=select((ndata+1)/2,ndata,arr)\r\n endif\r\n sum=0.\r\n abdev=0.\r\n do 12 j=1,ndata\r\n d=y(j)-(b*x(j)+aa)\r\n abdev=abdev+abs(d)\r\n if (y(j).ne.0.) d=d/abs(y(j))\r\n if (abs(d).gt.EPS) sum=sum+x(j)*sign(1.0,d)\r\n12 continue\r\n rofunc=sum\r\n return\r\n END\r\n", "meta": {"hexsha": "d0793b15f66301ae090959b93f255d0dabb6f8ce", "size": 766, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/rofunc.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/rofunc.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/rofunc.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": 26.4137931034, "max_line_length": 59, "alphanum_fraction": 0.5065274151, "num_tokens": 270, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989815306765, "lm_q2_score": 0.7718434978390746, "lm_q1q2_score": 0.6992823480529506}} {"text": "!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 1998 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Spherepack *\n! * *\n! * A Package of Fortran Subroutines and Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams and Paul Swarztrauber *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\n!\n! this file contains code and documentation for subroutines\n! shpgi and shpg.\n!\nsubmodule(scalar_projection_routines) scalar_projection_gaussian_grid\n\ncontains\n !\n ! Purpose:\n !\n ! shpg computes the harmonic projection, which is\n ! equivalent to a harmonic analysis (forward) followed\n ! by a harmonic synthesis (backward transform).\n ! shpg uses the n**2 projection or complement when appropriate\n ! as well as odd/even factorization and zero truncation on an\n ! on a Gaussian distributed grid as defined in the JCP paper\n ! \"Generalized discrete spherical harmonic transforms\"\n ! by Paul N. Swarztrauber and William F. Spotz\n ! J. Comp. Phys., 159(2000) pp. 213-230.\n !\n ! subroutine shpg(nlat, nlon, isym, mtrunc, x, y, idxy, wshp, lwshp, iwshp, liwshp, work, lwork, ierror)\n !\n ! shpg projects the array x onto the set of functions represented\n ! by a discrete set of spherical harmonics.\n !\n ! input parameters\n !\n ! nlat the number of colatitudes on the full sphere including the\n ! poles. for example, nlat = 37 for a five degree grid.\n ! nlat determines the grid increment in colatitude as\n ! pi/(nlat-1). if nlat is odd the equator is located at\n ! grid point i=(nlat + 1)/2. if nlat is even the equator is\n ! located half way between points i=nlat/2 and i=nlat/2+1.\n ! nlat must be at least 3.\n !\n ! nlon the number of distinct londitude points. nlon determines\n ! the grid increment in longitude as 2*pi/nlon. for example\n ! nlon = 72 for a five degree grid. nlon must be greater\n ! than or equal to 4. the efficiency of the computation is\n ! improved when nlon is a product of small prime numbers.\n ! nlon must be at least 4.\n !\n ! isym currently not used.\n !\n ! mtrunc the highest longitudinal wave number retained in the\n ! projection. It must be less than or equal to\n ! the minimum of nlat-1 and nlon/2. The first wave\n ! number is zero. For example, if wave numbers 0 and\n ! 1 are desired then mtrunc = 1.\n\n ! zero.\n !\n ! x a two dimensional array that contains the the nlat\n ! by nlon array x(i, j) defined at the colatitude point\n ! theta(i) = (i-1)*pi/(nlat-1) and longitude point phi(j) =\n ! (j-1)*2*pi/nlon.\n !\n ! idxy the first dimension of the arrays x and y as they\n ! appear in the program that calls shpg. It must be\n ! at least nlat.\n !\n ! wshp a single precision array that must be saved for\n ! repeated use by subroutine shpg.\n !\n ! lwshp the dimension of the array wshp as it appears in the\n ! program that calls shpgi. It must be at least\n ! 2*(nlat + 1)**2+nlon+log2(nlon)\n !\n ! iwshp an integer array that must be saved for repeated\n ! use by subroutine shpg.\n !\n !\n ! liwshp the dimension of the array iwshp as it appears in the\n ! program that calls shpgi. It must be at least\n ! 4*(nlat + 1).\n !\n ! work a single precision work array that does\n ! not have to be saved.\n !\n ! lwork the dimension of the array work as it appears in the\n ! program that calls shpg. It must be at least\n ! max(nlat*nlon, 4*(nlat + 1)).\n !\n ! **************************************************************\n !\n ! output parameters\n !\n ! y an nlat by nlon single precision array that contains\n ! the projection of x onto the set of functions that\n ! can be represented by the discrete set of spherical\n ! harmonics. The arrays x(i, j) and y(i, j) are located\n ! at colatitude point theta(i) = (i-1)*pi/(nlat-1) and\n ! longitude point phi(j) = (j-1)*2*pi/nlon.\n !\n ! ierror = 0 no errors\n ! = 1 error in the specification of nlat\n ! = 2 error in the specification of nlon\n ! = 3 error in the specification of isym\n ! = 4 error in the specification of mtrunc\n ! = 5 error in the specification of lwshp\n ! = 6 error in the specification of liwshp\n ! = 7 error in the specification of lwork\n !\n module subroutine shpg(nlat, nlon, isym, mtrunc, x, y, idxy, &\n wshp, lwshp, iwshp, liwshp, work, lwork, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n integer(ip), intent(in) :: isym\n integer(ip), intent(in) :: mtrunc\n real(wp), intent(in) :: x(idxy, nlon)\n real(wp), intent(out) :: y(idxy, nlon)\n integer(ip), intent(in) :: idxy\n real(wp), intent(in) :: wshp(lwshp)\n integer(ip), intent(in) :: lwshp\n integer(ip), intent(in) :: iwshp(liwshp)\n integer(ip), intent(in) :: liwshp\n real(wp), intent(out) :: work(lwork)\n integer(ip), intent(in) :: lwork\n integer(ip), intent(out) :: ierror\n\n ! Local variables\n integer(ip) :: iw1\n integer(ip) :: iw2\n integer(ip) :: iw3\n integer(ip) :: iw4\n integer(ip) :: jw1\n integer(ip) :: jw2\n integer(ip) :: jw3\n integer(ip) :: jw4\n integer(ip) :: log2n\n integer(ip) :: lw1\n integer(ip) :: mmax\n integer(ip) :: mwrk\n integer(ip) :: nloc1, nte\n integer(ip) :: nloc2\n type(SpherepackUtility) :: util\n\n ! Check calling arguments\n ierror = 1\n if (nlat < 1) return\n ierror = 2\n if (nlon < 1) return\n ierror = 3\n if (isym < 0 .or. isym > 2) return\n ierror = 4\n mmax = min(nlat-1, nlon/2)\n if (mtrunc<0 .or. mtrunc>mmax) return\n ierror = 5\n log2n = int(log(real(nlon, kind=wp))/log(TWO), kind=ip)\n lw1 = 2*(nlat + 1)**2\n if (lwshp 2) return\n ierror = 4\n mmax = min(nlat-1, nlon/2)\n if (mtrunc<0 .or. mtrunc>mmax) return\n ierror = 5\n lw1 = 2*((nlat + 1)**2)\n log2n = int(log(real(nlon, kind=wp))/log(TWO), kind=ip)\n if (lwshp1 .and. n>mxtr) then\n do i=1, nte\n u(i, j+nec) = ped(i, j+nec, iip)\n end do\n else\n a1 = b(n-1)*a(n+m-3)/a(n+m-1)\n b1 = a(n-m+1)/a(n+m-1)\n if (n-m<=1) then\n do i=1, nte\n u(i, j+nec) = a1*ped(i, j+nec-1, iip) &\n - b1*ped(i, j+nec, iip)\n end do\n else\n c1 = b(n-1)*a(n-m-1)/a(n+m-1)\n do i=1, nte\n u(i, j+nec) = a1*ped(i, j+nec-1, iip) &\n - b1*ped(i, j+nec, iip) + c1*u(i, j+nec-1)\n end do\n end if\n end if\n end do\n do j=1, nem\n do i=1, nte\n ped(i, j+nec, iip) = u(i, j+nec)\n end do\n end do\n end if\n if (nec<=0) cycle generate_even_functions\n !\n ! generate orthogonal vector with\n ! random numbers\n call random_seed()\n call random_number(xx(1:nte))\n\n it = 0\n generate_random_orth_vec_even: do\n it = it+1\n if (it > 2) exit generate_random_orth_vec_even\n\n do i=1, nte\n z(i) = ZERO\n wx(i) = gwts(i)*xx(i)\n end do\n\n do j=1, nte\n if (j == nec) cycle\n call accumulate_inner_products(nte, wx, ped(1, j, iip), z)\n end do\n\n do i=1, nte\n xx(i) = xx(i)-z(i)\n end do\n\n call calculate_normal(nte, xx, idp, gwts)\n\n end do generate_random_orth_vec_even\n\n do i=1, nte\n ped(i, nec, iip) = xx(i)\n end do\n end do generate_even_functions\n !\n ! reorder if mtrunc is less than nlat-1\n ! case of even functions\n !\n nmx = nlat-mxtr\n if (modn==1) then\n nshe(1) = nmx/2\n nshe(2) = (nmx-1)/2\n else\n nshe(1) = (nmx-1)/2\n nshe(2) = nmx/2\n end if\n !\n do mp1=1, 2\n do j=1, nte\n js = j+nshe(mp1)\n if (js>nte) js = js-nte\n do i=1, nte\n u(i, js) = ped(i, j, mp1)\n end do\n end do\n do j=1, nte\n do i=1, nte\n ped(i, j, mp1) = u(i, j)\n end do\n end do\n end do\n !\n call truncate(0, nte, idp, ped(1, 1, 1), nte, ipse(1, 1))\n call truncate(0, nte, idp, ped(1, 1, 2), nte, ipse(1, 2))\n !\n ! Compute the analysis matrices\n !\n do iip=1, 2\n do i=1, nte\n lock = 0\n do j=1, nte\n summation = ped(j, i, iip)*gwts(j)\n ze(j, i, iip) = summation\n pe(i, j, iip) = ped(i, j, iip)\n if (abs(summation)>MACHINE_EPSILON .and. lock==0) then\n lock = 1\n jzse(i, iip) = j\n end if\n end do\n end do\n end do\n !\n ! check orthogonality of pe(i, j, mp1) mp1=1, 2\n !\n do iip=1, 2\n dmax = ZERO\n do i=1, nte\n do j=1, nte\n sum1 = ZERO\n do k=1, nte\n sum1 = sum1+ze(k, i, iip)*pe(k, j, iip)\n end do\n zo(i, j, iip) = sum1\n if (i/=j) then\n dmax = max(dmax, abs(sum1))\n else\n dmax = max(dmax, abs(sum1-ONE))\n end if\n end do\n end do\n end do\n !\n ! Compute n**2 basis (odd functions)\n !\n iip = 2\n generate_odd_functions: do mp1=1, mxtr+1\n iip = 3-iip\n m = mp1-1\n ms2 = mp1/2\n nem = (nlat-m+1)/2\n nom = nlat-m-nem\n noc = nto-nom\n !\n ! Compute associated legendre functions\n !\n if (m<=1) then\n do j=1, nom\n n = 2*j+m-1\n call util%compute_fourier_coefficients(m, n, cp)\n do i=1, nte\n call util%compute_legendre_polys_from_fourier_coeff(m, n, thet(i), cp, pod(i, j+noc, iip))\n end do\n if (modn>0) pod(nte, j+noc, iip) = ZERO\n end do\n else\n do j=1, nom\n n = 2*j+m-1\n if (m>1 .and. n>mxtr) then\n do i=1, nte\n u(i, j+noc) = pod(i, j+noc, iip)\n end do\n else\n a1 = b(n-1)*a(n+m-3)/a(n+m-1)\n b1 = a(n-m+1)/a(n+m-1)\n if (n-m<=1) then\n do i=1, nte\n u(i, j+noc) = a1*pod(i, j+noc-1, iip) &\n - b1*pod(i, j+noc, iip)\n end do\n else\n c1 = b(n-1)*a(n-m-1)/a(n+m-1)\n do i=1, nte\n u(i, j+noc) = a1*pod(i, j+noc-1, iip) &\n - b1*pod(i, j+noc, iip) + c1*u(i, j+noc-1)\n end do\n end if\n end if\n if (modn==1) u(nte, j+noc) = ZERO\n end do\n do j=1, nom\n do i=1, nte\n pod(i, j+noc, iip) = u(i, j+noc)\n end do\n end do\n end if\n\n if (noc <= 0) cycle generate_odd_functions\n\n call random_number(xx(1:nte))\n\n if (modn==1) xx(nte) = ZERO\n\n it = 0\n generate_random_orth_vec_odd: do\n it = it+1\n if (it > 2) exit generate_random_orth_vec_odd\n\n z(1: nte) = ZERO\n wx(1: nte) = gwts(1: nte)*xx(1: nte)\n\n do j=1, nto\n if (j==noc) cycle\n call accumulate_inner_products(nte, wx, pod(1, j, iip), z(1))\n end do\n\n xx(1: nte) = xx(1: nte)-z(1: nte)\n\n call calculate_normal(nte, xx, idp, gwts)\n end do generate_random_orth_vec_odd\n\n pod(1: nte, noc, iip) = xx(1: nte)\n\n if (modn==1) pod(nte, noc, iip) = ZERO\n end do generate_odd_functions\n\n nmx = nlat-mxtr\n\n if (modn==1) then\n nsho(1) = (nmx-1)/2\n nsho(2) = nmx/2\n else\n nsho(1) = nmx/2\n nsho(2) = (nmx-1)/2\n end if\n !\n do mp1=1, 2\n do j=1, nto\n js = j+nsho(mp1)\n if (js>nto) js = js-nto\n do i=1, nte\n u(i, js) = pod(i, j, mp1)\n end do\n end do\n do j=1, nto\n do i=1, nte\n pod(i, j, mp1) = u(i, j)\n end do\n end do\n end do\n !\n call truncate(0, nte, idp, pod(1, 1, 1), nto, ipso(1, 1))\n call truncate(0, nte, idp, pod(1, 1, 2), nto, ipso(1, 2))\n !\n ! Compute the analysis matrices (odd functions)\n !\n do iip=1, 2\n do i=1, nto\n lock = 0\n do j=1, nto\n summation = pod(j, i, iip)*gwts(j)\n zo(j, i, iip) = summation\n po(i, j, iip) = pod(i, j, iip)\n if (abs(summation)>MACHINE_EPSILON .and. lock==0) then\n lock = 1\n jzso(i, iip) = j\n end if\n end do\n end do\n end do\n !\n ! check orthogonality of po(i, j, mp1) mp1=1, 2\n !\n do iip=1, 2\n dmax = ZERO\n do i=1, nto\n do j=1, nto\n sum1 = ZERO\n do k=1, nto\n sum1 = sum1+zo(k, i, iip)*po(k, j, iip)\n end do\n zort(i, j, iip) = sum1\n if (i/=j) then\n dmax = max(dmax, abs(sum1))\n else\n dmax = max(dmax, abs(sum1-ONE))\n end if\n end do\n end do\n end do\n\n end subroutine shpgi_lower_utility_routine\n\n subroutine shpg_lower_utility_routine(nlat, nlon, isym, mtrunc, sx, sy, idxy, ierror, &\n idp, pe, po, ze, zo, ipse, jzse, ipso, jzso, xe, xo, ye, yo)\n\n integer(ip) :: i\n integer(ip) :: idp\n integer(ip) :: idxy\n integer(ip) :: ierror\n integer(ip) :: iip\n integer(ip) :: ipse\n integer(ip) :: ipso\n integer(ip) :: isym\n integer(ip) :: j\n integer(ip) :: js\n integer(ip) :: jzse\n integer(ip) :: jzso\n integer(ip) :: lag\n integer(ip) :: m\n integer(ip) :: modn\n integer(ip) :: mp1\n integer(ip) :: mpm\n integer(ip) :: ms2\n integer(ip) :: mtrunc\n integer(ip) :: mxtr\n integer(ip) :: nec\n integer(ip) :: nem\n integer(ip) :: nlat\n integer(ip) :: nlon\n integer(ip) :: nmx\n integer(ip) :: noc\n integer(ip) :: nom\n integer(ip) :: ns2\n integer(ip) :: nshe\n integer(ip) :: nsho\n integer(ip) :: nte\n integer(ip) :: nto\n real(wp) :: pe\n real(wp) :: po\n real(wp) :: sx\n real(wp) :: sy\n real(wp) :: xe\n real(wp) :: xo\n real(wp) :: ye\n real(wp) :: yo\n real(wp) :: ze\n real(wp) :: zo\n !\n dimension sx(idxy, nlon), sy(idxy, nlon), nshe(2), nsho(2), &\n pe(idp, idp, 2), po(idp, idp, 2), ze(idp, idp, 2), zo(idp, idp, 2), &\n ipse(idp, 2), jzse(idp, 2), ipso(idp, 2), jzso(idp, 2), &\n xe(idp, 2), xo(idp, 2), ye(idp, 2), yo(idp, 2)\n !\n ns2 = nlat/2\n modn = nlat-ns2-ns2\n nte = (nlat + 1)/2\n nto = nlat-nte\n !\n mxtr = min(nlat-1, nlon/2, mtrunc)\n nmx = nlat-mxtr\n if (modn==1) then\n nshe(1) = nmx/2\n nshe(2) = (nmx-1)/2\n nsho(1) = (nmx-1)/2\n nsho(2) = nmx/2\n else\n nshe(1) = (nmx-1)/2\n nshe(2) = nmx/2\n nsho(1) = nmx/2\n nsho(2) = (nmx-1)/2\n end if\n !\n iip = 2\n outer_loop: do mp1=1, mxtr+1\n iip = 3-iip\n if (mxtr==nlat-1 .and. mp1==1) then\n do i=1, nlat\n sy(i, mp1) = sx(i, mp1)\n end do\n cycle outer_loop\n end if\n m = mp1-1\n mpm = max(1, m+m)\n ms2 = mp1/2\n nem = (nlat-m+1)/2-nshe(iip)\n nom = (nlat-m)/2-nsho(iip)\n nec = nte-nem\n noc = nto-nom\n\n do i=1, nte\n xe(i, 1) = HALF * (sx(i, mpm)+sx(nlat+1-i, mpm))\n xo(i, 1) = HALF * (sx(i, mpm)-sx(nlat+1-i, mpm))\n end do\n\n if (mpmnto) sy(nte, mpm) = ye(nte, 1)\n if (mpmnto) sy(nte, mpm+1) = ye(nte, 2)\n end if\n end do outer_loop\n\n js = mxtr+mxtr+2\n do j=js, nlon\n do i=1, nlat\n sy(i, j) = ZERO\n end do\n end do\n\n end subroutine shpg_lower_utility_routine\n\n subroutine matrix_multiply(lag, lr, lc, ld, a, mc, md, b, x, y, is, js)\n\n ! Dummy arguments\n integer(ip), intent(in) :: lag\n integer(ip), intent(in) :: lc\n integer(ip), intent(in) :: ld\n integer(ip), intent(in) :: lr\n real(wp), intent(in) :: a(ld, *)\n integer(ip), intent(in) :: mc\n integer(ip), intent(in) :: md\n real(wp), intent(in) :: b(md, *)\n real(wp), intent(in) :: x(ld, 2)\n real(wp), intent(inout) :: y(ld, 2)\n integer(ip), intent(in) :: is(*)\n integer(ip), intent(in) :: js(*)\n\n ! Local variables\n integer(ip) :: i, j, k, kmx\n real(wp) :: sum1, sum2\n\n kmx = min(lr+1, ld)\n\n select case (lag)\n case(1)\n y(1: kmx, 1) = ZERO\n if (lc > 0) then\n do i=1, lc\n sum1 = ZERO\n do j=js(i), mc\n sum1 = sum1 + b(j, i)*x(j, 1)\n end do\n do k=is(i), lr\n y(k, 1) = y(k, 1)+sum1*a(k, i)\n end do\n end do\n end if\n case default\n y(1: kmx, :) = ZERO\n if (lc > 0) then\n do i=1, lc\n sum1 = ZERO\n sum2 = ZERO\n do j=js(i), mc\n sum1 = sum1 + b(j, i)*x(j, 1)\n sum2 = sum2 + b(j, i)*x(j, 2)\n end do\n do k=is(i), lr\n y(k, 1) = y(k, 1)+sum1*a(k, i)\n y(k, 2) = y(k, 2)+sum2*a(k, i)\n end do\n end do\n end if\n end select\n\n end subroutine matrix_multiply\n\n subroutine calculate_normal(n, x, id, q)\n\n ! Dummy arguments\n integer(ip), intent(in) :: n\n real(wp), intent(inout) :: x(n)\n integer(ip), intent(in) :: id\n real(wp), intent(in) :: q(n)\n\n ! Local variables\n integer(ip) :: i\n real(wp) :: sqs\n\n ! Normalize x\n sqs = ZERO\n do i=1, n\n sqs = sqs+q(i)*(x(i)**2)\n end do\n\n x = x/sqrt(sqs)\n\n end subroutine calculate_normal\n\nend submodule scalar_projection_gaussian_grid\n", "meta": {"hexsha": "2d21f75dacfef4b52fd5cd12677b3e690f192fb1", "size": 35462, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/scalar_projection_gaussian_grid.f90", "max_stars_repo_name": "jlokimlin/spherepack4.1", "max_stars_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-06-28T14:01:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T21:59:28.000Z", "max_issues_repo_path": "src/scalar_projection_gaussian_grid.f90", "max_issues_repo_name": "jlokimlin/spherepack4.1", "max_issues_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2016-05-07T23:00:35.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-22T23:52:30.000Z", "max_forks_repo_path": "src/scalar_projection_gaussian_grid.f90", "max_forks_repo_name": "jlokimlin/spherepack4.1", "max_forks_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-06-28T14:03:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T12:53:54.000Z", "avg_line_length": 34.9723865878, "max_line_length": 114, "alphanum_fraction": 0.42042186, "num_tokens": 10584, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898203834277, "lm_q2_score": 0.7718434873426302, "lm_q1q2_score": 0.699282342461668}} {"text": "\nmodule analriem_module\n\n contains\n\n subroutine analriem(ilo,ihi,gamma,pl,rl,ul,pr,rr,ur,smallp,pstar,ustar)\n\n use amrex_fort_module, only : rt => amrex_real\n implicit none\n\n integer, intent(in) :: ilo, ihi\n\n real(rt), intent(in ), dimension(ilo:ihi) :: pl,rl,ul,pr,rr,ur\n real(rt), intent(in ) :: gamma, smallp\n real(rt), intent(out), dimension(ilo:ihi) :: pstar,ustar\n\n ! Local variables\n real(rt), dimension(ilo:ihi) :: pstnm1,ustarp,ustarm\n real(rt), dimension(ilo:ihi) :: wl,wr,wlsq,wrsq\n real(rt), dimension(ilo:ihi) :: cleft,cright\n real(rt), dimension(ilo:ihi) :: dpditer,zp,zm,denom\n real(rt), dimension(ilo:ihi) :: ustnm1,ustnp1\n integer :: iter\n\n real(rt), parameter :: weakwv = 1.d-3\n real(rt), parameter :: small = 1.d-6\n\n integer :: i\n\n wl = sqrt(gamma*pl*rl)\n wr = sqrt(gamma*pr*rr)\n\n cleft = wl/rl\n cright = wr/rr\n\n pstar=(wl*pr+wr*pl-wr*wl*(ur-ul))/(wl+wr)\n\n pstar=max(pstar,smallp)\n pstnm1 = pstar\n\n wlsq = (.5d0*(gamma-1.d0)*(pstar+pl)+pstar) * rl\n wrsq = (.5d0*(gamma-1.d0)*(pstar+pr)+pstar) * rr\n\n wl = sqrt(wlsq)\n wr = sqrt(wrsq)\n\n ustarp = ul - (pstar-pl)/wl\n ustarm = ur + (pstar-pr)/wr\n\n pstar = (wl*pr+wr*pl-wr*wl*(ur-ul))/(wl+wr)\n\n pstar=max(pstar,smallp)\n\n do iter = 1,3\n\n wlsq = (.5d0*(gamma-1.d0)*(pstar+pl)+pstar) * rl\n wrsq = (.5d0*(gamma-1.d0)*(pstar+pr)+pstar) * rr\n\n wl = 1.d0/sqrt(wlsq)\n wr = 1.d0/sqrt(wrsq)\n\n ustnm1 = ustarm\n ustnp1 = ustarp\n\n ustarm = ur - (pr-pstar)*wr\n ustarp = ul + (pl-pstar)*wl\n\n dpditer = abs(pstnm1-pstar)\n zp = abs(ustarp-ustnp1)\n\n do i = ilo, ihi\n if (zp(i)-weakwv*cleft(i) .lt. 0.0d0 ) then\n zp(i) = dpditer(i)*wl(i)\n endif\n end do\n\n zm=abs(ustarm-ustnm1)\n\n do i = ilo, ihi\n if (zm(i)-weakwv*cright(i) .lt. 0.0d0 ) then\n zm(i) = dpditer(i)*wr(i)\n endif\n end do\n\n denom = dpditer/max(zp+zm,small*(cleft+cright))\n pstnm1 = pstar\n\n pstar = pstar - denom*(ustarm-ustarp)\n\n pstar = max(pstar,smallp)\n\n ustar = 0.5d0*(ustarm+ustarp)\n\n end do\n\n end subroutine analriem\n\n end module analriem_module\n", "meta": {"hexsha": "65bba754bb46acdea90b0030eafb0ff3a6219d55", "size": 2344, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Source/HydroFortran/analriem.f90", "max_stars_repo_name": "Gosenca/axionyx_1.0", "max_stars_repo_head_hexsha": "7e2a723e00e6287717d6d81b23db32bcf6c3521a", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-02-18T09:13:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T21:27:46.000Z", "max_issues_repo_path": "Source/HydroFortran/analriem.f90", "max_issues_repo_name": "Gosenca/axionyx_1.0", "max_issues_repo_head_hexsha": "7e2a723e00e6287717d6d81b23db32bcf6c3521a", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-10-12T08:54:31.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-12T08:54:31.000Z", "max_forks_repo_path": "Source/HydroFortran/analriem.f90", "max_forks_repo_name": "Gosenca/axionyx_1.0", "max_forks_repo_head_hexsha": "7e2a723e00e6287717d6d81b23db32bcf6c3521a", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-09-04T10:26:25.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T23:51:51.000Z", "avg_line_length": 23.6767676768, "max_line_length": 75, "alphanum_fraction": 0.5392491468, "num_tokens": 859, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037384317887, "lm_q2_score": 0.7549149868676284, "lm_q1q2_score": 0.6992805745336689}} {"text": "*DECK HWSCSP\n SUBROUTINE HWSCSP (INTL, TS, TF, M, MBDCND, BDTS, BDTF, RS, RF, N,\n + NBDCND, BDRS, BDRF, ELMBDA, F, IDIMF, PERTRB, IERROR, W)\nC***BEGIN PROLOGUE HWSCSP\nC***PURPOSE Solve a finite difference approximation to the modified\nC Helmholtz equation in spherical coordinates assuming\nC axisymmetry (no dependence on longitude).\nC***LIBRARY SLATEC (FISHPACK)\nC***CATEGORY I2B1A1A\nC***TYPE SINGLE PRECISION (HWSCSP-S)\nC***KEYWORDS ELLIPTIC, FISHPACK, HELMHOLTZ, PDE, SPHERICAL\nC***AUTHOR Adams, J., (NCAR)\nC Swarztrauber, P. N., (NCAR)\nC Sweet, R., (NCAR)\nC***DESCRIPTION\nC\nC Subroutine HWSCSP solves a finite difference approximation to the\nC modified Helmholtz equation in spherical coordinates assuming\nC axisymmetry (no dependence on longitude)\nC\nC (1/R**2)(d/dR)((R**2)(d/dR)U)\nC\nC + (1/(R**2)SIN(THETA))(d/dTHETA)(SIN(THETA)(d/dTHETA)U)\nC\nC + (LAMBDA/(RSIN(THETA))**2)U = F(THETA,R).\nC\nC This two dimensional modified Helmholtz equation results from\nC the Fourier transform of the three dimensional Poisson equation\nC\nC * * * * * * * * * * On Input * * * * * * * * * *\nC\nC INTL\nC = 0 On initial entry to HWSCSP or if any of the arguments\nC RS, RF, N, NBDCND are changed from a previous call.\nC = 1 If RS, RF, N, NBDCND are all unchanged from previous call\nC to HWSCSP.\nC\nC NOTE A call with INTL=0 takes approximately 1.5 times as\nC much time as a call with INTL = 1. Once a call with\nC INTL = 0 has been made then subsequent solutions\nC corresponding to different F, BDTS, BDTF, BDRS, BDRF can\nC be obtained faster with INTL = 1 since initialization is\nC not repeated.\nC\nC TS,TF\nC The range of THETA (colatitude), i.e., TS .LE. THETA .LE. TF.\nC TS must be less than TF. TS and TF are in radians. A TS of\nC zero corresponds to the north pole and a TF of PI corresponds\nC to the south pole.\nC\nC * * * * * * * * * * * * * * IMPORTANT * * * * * * * * * * * * * *\nC\nC If TF is equal to PI then it must be computed using the statement\nC TF = PIMACH(DUM). This insures that TF in the users program is\nC equal to PI in this program which permits several tests of the\nC input parameters that otherwise would not be possible.\nC\nC M\nC The number of panels into which the interval (TS,TF) is\nC subdivided. Hence, there will be M+1 grid points in the\nC THETA-direction given by THETA(K) = (I-1)DTHETA+TS for\nC I = 1,2,...,M+1, where DTHETA = (TF-TS)/M is the panel width.\nC\nC MBDCND\nC Indicates the type of boundary condition at THETA = TS and\nC THETA = TF.\nC\nC = 1 If the solution is specified at THETA = TS and THETA = TF.\nC = 2 If the solution is specified at THETA = TS and the\nC derivative of the solution with respect to THETA is\nC specified at THETA = TF (see note 2 below).\nC = 3 If the derivative of the solution with respect to THETA is\nC specified at THETA = TS and THETA = TF (see notes 1,2\nC below).\nC = 4 If the derivative of the solution with respect to THETA is\nC specified at THETA = TS (see note 1 below) and the\nC solution is specified at THETA = TF.\nC = 5 If the solution is unspecified at THETA = TS = 0 and the\nC solution is specified at THETA = TF.\nC = 6 If the solution is unspecified at THETA = TS = 0 and the\nC derivative of the solution with respect to THETA is\nC specified at THETA = TF (see note 2 below).\nC = 7 If the solution is specified at THETA = TS and the\nC solution is unspecified at THETA = TF = PI.\nC = 8 If the derivative of the solution with respect to THETA is\nC specified at THETA = TS (see note 1 below) and the solution\nC is unspecified at THETA = TF = PI.\nC = 9 If the solution is unspecified at THETA = TS = 0 and\nC THETA = TF = PI.\nC\nC NOTES: 1. If TS = 0, do not use MBDCND = 3,4, or 8, but\nC instead use MBDCND = 5,6, or 9 .\nC 2. If TF = PI, do not use MBDCND = 2,3, or 6, but\nC instead use MBDCND = 7,8, or 9 .\nC\nC BDTS\nC A one-dimensional array of length N+1 that specifies the values\nC of the derivative of the solution with respect to THETA at\nC THETA = TS. When MBDCND = 3,4, or 8,\nC\nC BDTS(J) = (d/dTHETA)U(TS,R(J)), J = 1,2,...,N+1 .\nC\nC When MBDCND has any other value, BDTS is a dummy variable.\nC\nC BDTF\nC A one-dimensional array of length N+1 that specifies the values\nC of the derivative of the solution with respect to THETA at\nC THETA = TF. When MBDCND = 2,3, or 6,\nC\nC BDTF(J) = (d/dTHETA)U(TF,R(J)), J = 1,2,...,N+1 .\nC\nC When MBDCND has any other value, BDTF is a dummy variable.\nC\nC RS,RF\nC The range of R, i.e., RS .LE. R .LT. RF. RS must be less than\nC RF. RS must be non-negative.\nC\nC N\nC The number of panels into which the interval (RS,RF) is\nC subdivided. Hence, there will be N+1 grid points in the\nC R-direction given by R(J) = (J-1)DR+RS for J = 1,2,...,N+1,\nC where DR = (RF-RS)/N is the panel width.\nC N must be greater than 2\nC\nC NBDCND\nC Indicates the type of boundary condition at R = RS and R = RF.\nC\nC = 1 If the solution is specified at R = RS and R = RF.\nC = 2 If the solution is specified at R = RS and the derivative\nC of the solution with respect to R is specified at R = RF.\nC = 3 If the derivative of the solution with respect to R is\nC specified at R = RS and R = RF.\nC = 4 If the derivative of the solution with respect to R is\nC specified at RS and the solution is specified at R = RF.\nC = 5 If the solution is unspecified at R = RS = 0 (see note\nC below) and the solution is specified at R = RF.\nC = 6 If the solution is unspecified at R = RS = 0 (see note\nC below) and the derivative of the solution with respect to\nC R is specified at R = RF.\nC\nC NOTE: NBDCND = 5 or 6 cannot be used with\nC MBDCND = 1,2,4,5, or 7 (the former indicates that the\nC solution is unspecified at R = 0, the latter\nC indicates that the solution is specified).\nC Use instead\nC NBDCND = 1 or 2 .\nC\nC BDRS\nC A one-dimensional array of length M+1 that specifies the values\nC of the derivative of the solution with respect to R at R = RS.\nC When NBDCND = 3 or 4,\nC\nC BDRS(I) = (d/dR)U(THETA(I),RS), I = 1,2,...,M+1 .\nC\nC When NBDCND has any other value, BDRS is a dummy variable.\nC\nC BDRF\nC A one-dimensional array of length M+1 that specifies the values\nC of the derivative of the solution with respect to R at R = RF.\nC When NBDCND = 2,3, or 6,\nC\nC BDRF(I) = (d/dR)U(THETA(I),RF), I = 1,2,...,M+1 .\nC\nC When NBDCND has any other value, BDRF is a dummy variable.\nC\nC ELMBDA\nC The constant LAMBDA in the Helmholtz equation. If\nC LAMBDA .GT. 0, a solution may not exist. However, HWSCSP will\nC attempt to find a solution. If NBDCND = 5 or 6 or\nC MBDCND = 5,6,7,8, or 9, ELMBDA must be zero.\nC\nC F\nC A two-dimensional array that specifies the value of the right\nC side of the Helmholtz equation and boundary values (if any).\nC for I = 2,3,...,M and J = 2,3,...,N\nC\nC F(I,J) = F(THETA(I),R(J)).\nC\nC On the boundaries F is defined by\nC\nC MBDCND F(1,J) F(M+1,J)\nC ------ ---------- ----------\nC\nC 1 U(TS,R(J)) U(TF,R(J))\nC 2 U(TS,R(J)) F(TF,R(J))\nC 3 F(TS,R(J)) F(TF,R(J))\nC 4 F(TS,R(J)) U(TF,R(J))\nC 5 F(0,R(J)) U(TF,R(J)) J = 1,2,...,N+1\nC 6 F(0,R(J)) F(TF,R(J))\nC 7 U(TS,R(J)) F(PI,R(J))\nC 8 F(TS,R(J)) F(PI,R(J))\nC 9 F(0,R(J)) F(PI,R(J))\nC\nC NBDCND F(I,1) F(I,N+1)\nC ------ -------------- --------------\nC\nC 1 U(THETA(I),RS) U(THETA(I),RF)\nC 2 U(THETA(I),RS) F(THETA(I),RF)\nC 3 F(THETA(I),RS) F(THETA(I),RF)\nC 4 F(THETA(I),RS) U(THETA(I),RF) I = 1,2,...,M+1\nC 5 F(TS,0) U(THETA(I),RF)\nC 6 F(TS,0) F(THETA(I),RF)\nC\nC F must be dimensioned at least (M+1)*(N+1).\nC\nC NOTE\nC\nC If the table calls for both the solution U and the right side F\nC at a corner then the solution must be specified.\nC\nC IDIMF\nC The row (or first) dimension of the array F as it appears in the\nC program calling HWSCSP. This parameter is used to specify the\nC variable dimension of F. IDIMF must be at least M+1 .\nC\nC W\nC A one-dimensional array that must be provided by the user for\nC work space. Its length can be computed from the formula below\nC which depends on the value of NBDCND.\nC\nC If NBDCND=2,4 or 6 define NUNK=N\nC If NBDCND=1 or 5 define NUNK=N-1\nC If NBDCND=3 define NUNK=N+1\nC\nC Now set K=INT(log2(NUNK))+1 and L=2**(K+1) then W must be\nC dimensioned at least (K-2)*L+K+5*(M+N)+MAX(2*N,6*M)+23\nC\nC **IMPORTANT** For purposes of checking, the required length\nC of W is computed by HWSCSP and stored in W(1)\nC in floating point format.\nC\nC\nC * * * * * * * * * * On Output * * * * * * * * * *\nC\nC F\nC Contains the solution U(I,J) of the finite difference\nC approximation for the grid point (THETA(I),R(J)),\nC I = 1,2,...,M+1, J = 1,2,...,N+1 .\nC\nC PERTRB\nC If a combination of periodic or derivative boundary conditions\nC is specified for a Poisson equation (LAMBDA = 0), a solution may\nC not exist. PERTRB is a constant, calculated and subtracted from\nC F, which ensures that a solution exists. HWSCSP then computes\nC this solution, which is a least squares solution to the original\nC approximation. This solution is not unique and is unnormalized.\nC The value of PERTRB should be small compared to the right side\nC F. Otherwise , a solution is obtained to an essentially\nC different problem. This comparison should always be made to\nC insure that a meaningful solution has been obtained.\nC\nC IERROR\nC An error flag that indicates invalid input parameters. Except\nC for numbers 0 and 10, a solution is not attempted.\nC\nC = 1 TS.LT.0. or TF.GT.PI\nC = 2 TS.GE.TF\nC = 3 M.LT.5\nC = 4 MBDCND.LT.1 or MBDCND.GT.9\nC = 5 RS.LT.0\nC = 6 RS.GE.RF\nC = 7 N.LT.5\nC = 8 NBDCND.LT.1 or NBDCND.GT.6\nC = 9 ELMBDA.GT.0\nC = 10 IDIMF.LT.M+1\nC = 11 ELMBDA.NE.0 and MBDCND.GE.5\nC = 12 ELMBDA.NE.0 and NBDCND equals 5 or 6\nC = 13 MBDCND equals 5,6 or 9 and TS.NE.0\nC = 14 MBDCND.GE.7 and TF.NE.PI\nC = 15 TS.EQ.0 and MBDCND equals 3,4 or 8\nC = 16 TF.EQ.PI and MBDCND equals 2,3 or 6\nC = 17 NBDCND.GE.5 and RS.NE.0\nC = 18 NBDCND.GE.5 and MBDCND equals 1,2,4,5 or 7\nC\nC Since this is the only means of indicating a possibly incorrect\nC call to HWSCSP, the user should test IERROR after a call.\nC\nC W\nC Contains intermediate values that must not be destroyed if\nC HWSCSP will be called again with INTL = 1. W(1) contains the\nC number of locations which W must have.\nC\nC *Long Description:\nC\nC * * * * * * * Program Specifications * * * * * * * * * * * *\nC\nC Dimension of BDTS(N+1),BDTF(N+1),BDRS(M+1),BDRF(M+1),\nC Arguments F(IDIMF,N+1),W(see argument list)\nC\nC Latest June 1979\nC Revision\nC\nC Subprograms HWSCSP,HWSCS1,BLKTRI,BLKTR1,PROD,PRODP,CPROD,CPRODP\nC Required ,COMBP,PPADD,PSGF,BSRH,PPSGF,PPSPF,TEVLS,INDXA,\nC ,INDXB,INDXC,R1MACH\nC\nC Special\nC Conditions\nC\nC Common CBLKT\nC Blocks\nC\nC I/O NONE\nC\nC Precision Single\nC\nC Specialist Paul N Swarztrauber\nC\nC Language FORTRAN\nC\nC History Version 1 September 1973\nC Version 2 April 1976\nC Version 3 June 1979\nC\nC Algorithm The routine defines the finite difference\nC equations, incorporates boundary data, and adjusts\nC the right side of singular systems and then calls\nC BLKTRI to solve the system.\nC\nC Space\nC Required\nC\nC Portability American National Standards Institute FORTRAN.\nC The machine accuracy is set using function R1MACH.\nC\nC Required NONE\nC Resident\nC Routines\nC\nC Reference Swarztrauber,P. and R. Sweet, 'Efficient FORTRAN\nC Subprograms for The Solution Of Elliptic Equations'\nC NCAR TN/IA-109, July, 1975, 138 pp.\nC\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC\nC***REFERENCES P. N. Swarztrauber and R. Sweet, Efficient Fortran\nC subprograms for the solution of elliptic equations,\nC NCAR TN/IA-109, July 1975, 138 pp.\nC***ROUTINES CALLED HWSCS1, PIMACH\nC***REVISION HISTORY (YYMMDD)\nC 801001 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890531 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE HWSCSP\nC\n DIMENSION F(IDIMF,*) ,BDTS(*) ,BDTF(*) ,BDRS(*) ,\n 1 BDRF(*) ,W(*)\nC***FIRST EXECUTABLE STATEMENT HWSCSP\n PI = PIMACH(DUM)\n IERROR = 0\n IF (TS.LT.0. .OR. TF.GT.PI) IERROR = 1\n IF (TS .GE. TF) IERROR = 2\n IF (M .LT. 5) IERROR = 3\n IF (MBDCND.LT.1 .OR. MBDCND.GT.9) IERROR = 4\n IF (RS .LT. 0.) IERROR = 5\n IF (RS .GE. RF) IERROR = 6\n IF (N .LT. 5) IERROR = 7\n IF (NBDCND.LT.1 .OR. NBDCND.GT.6) IERROR = 8\n IF (ELMBDA .GT. 0.) IERROR = 9\n IF (IDIMF .LT. M+1) IERROR = 10\n IF (ELMBDA.NE.0. .AND. MBDCND.GE.5) IERROR = 11\n IF (ELMBDA.NE.0. .AND. (NBDCND.EQ.5 .OR. NBDCND.EQ.6)) IERROR = 12\n IF ((MBDCND.EQ.5 .OR. MBDCND.EQ.6 .OR. MBDCND.EQ.9) .AND.\n 1 TS.NE.0.) IERROR = 13\n IF (MBDCND.GE.7 .AND. TF.NE.PI) IERROR = 14\n IF (TS.EQ.0. .AND.\n 1 (MBDCND.EQ.4 .OR. MBDCND.EQ.8 .OR. MBDCND.EQ.3)) IERROR = 15\n IF (TF.EQ.PI .AND.\n 1 (MBDCND.EQ.2 .OR. MBDCND.EQ.3 .OR. MBDCND.EQ.6)) IERROR = 16\n IF (NBDCND.GE.5 .AND. RS.NE.0.) IERROR = 17\n IF (NBDCND.GE.5 .AND. (MBDCND.EQ.1 .OR. MBDCND.EQ.2 .OR.\n 1 MBDCND.EQ.5 .OR. MBDCND.EQ.7))\n 2 IERROR = 18\n IF (IERROR.NE.0 .AND. IERROR.NE.9) RETURN\n NCK = N\n GO TO (101,103,102,103,101,103),NBDCND\n 101 NCK = NCK-1\n GO TO 103\n 102 NCK = NCK+1\n 103 L = 2\n K = 1\n 104 L = L+L\n K = K+1\n IF (NCK-L) 105,105,104\n 105 L = L+L\n NP1 = N+1\n MP1 = M+1\n I1 = (K-2)*L+K+MAX(2*N,6*M)+13\n I2 = I1+NP1\n I3 = I2+NP1\n I4 = I3+NP1\n I5 = I4+NP1\n I6 = I5+NP1\n I7 = I6+MP1\n I8 = I7+MP1\n I9 = I8+MP1\n I10 = I9+MP1\n W(1) = I10+M\n CALL HWSCS1 (INTL,TS,TF,M,MBDCND,BDTS,BDTF,RS,RF,N,NBDCND,BDRS,\n 1 BDRF,ELMBDA,F,IDIMF,PERTRB,W(2),W(I1),W(I2),W(I3),\n 2 W(I4),W(I5),W(I6),W(I7),W(I8),W(I9),W(I10))\n RETURN\n END\n", "meta": {"hexsha": "1946aee81dbed1426debf5dc95d10af28ff4b314", "size": 16054, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/hwscsp.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/hwscsp.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/hwscsp.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.5418719212, "max_line_length": 72, "alphanum_fraction": 0.5673975333, "num_tokens": 5494, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037302939515, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6992805734979105}} {"text": " real(kind(0.0d0)) function pythag (a, b) \n!-----------------------------------------------\n! M o d u l e s \n!-----------------------------------------------\n USE vast_kind_param, ONLY: double \n!...Translated by Pacific-Sierra Research 77to90 4.3E 21:52:17 11/14/01 \n!...Switches: \n implicit none\n!-----------------------------------------------\n! D u m m y A r g u m e n t s\n!-----------------------------------------------\n real(double) , intent(in) :: a \n real(double) , intent(in) :: b \n!-----------------------------------------------\n! L o c a l V a r i a b l e s\n!-----------------------------------------------\n real(double) :: p, r, s, t, u \n!-----------------------------------------------\n!\n! finds dsqrt(a**2+b**2) without overflow or destructive underflow\n!\n p = dmax1(dabs(a),dabs(b)) \n if (p /= 0.0D0) then \n r = (dmin1(dabs(a),dabs(b))/p)**2 \n t = 4.0D0 + r \n do while(t /= 4.0D0) \n s = r/t \n u = 1.0D0 + 2.0D0*s \n p = u*p \n r = (s/u)**2*r \n t = 4.0D0 + r \n end do \n go to 20 \n endif \n 20 continue \n pythag = p \n return \n end function pythag \n", "meta": {"hexsha": "1cd811d3f9cdfc03529b79a9b48a84a9589b48c1", "size": 1256, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src90/lib/libcom90/pythag.f90", "max_stars_repo_name": "mansour2014/ATSP2K_plus", "max_stars_repo_head_hexsha": "30842b9f086d1e497aeb778e2a352d1e8e520ec3", "max_stars_repo_licenses": ["BSD-4-Clause-UC"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-07-21T14:03:39.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-21T14:03:39.000Z", "max_issues_repo_path": "src90/lib/libcom90/pythag.f90", "max_issues_repo_name": "mzmansour/ATSP2K_plus", "max_issues_repo_head_hexsha": "30842b9f086d1e497aeb778e2a352d1e8e520ec3", "max_issues_repo_licenses": ["BSD-4-Clause-UC"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src90/lib/libcom90/pythag.f90", "max_forks_repo_name": "mzmansour/ATSP2K_plus", "max_forks_repo_head_hexsha": "30842b9f086d1e497aeb778e2a352d1e8e520ec3", "max_forks_repo_licenses": ["BSD-4-Clause-UC"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.2051282051, "max_line_length": 76, "alphanum_fraction": 0.3304140127, "num_tokens": 357, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037262250327, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6992805602109887}} {"text": "program test6_reverse\n\n use multigrid\n\n implicit none\n\n integer, parameter :: num=selected_real_kind(p=15)\n real(num) :: pi = 4.0_num * ATAN(1.0_num)\n real(num) :: pi2 = 8.0_num * ATAN(1.0_num)\n\n integer :: nx, ny, ix, iy\n\n real(num) :: dx, dy, L2, x_min, x_max, y_min, y_max\n\n real(num), dimension(:), allocatable :: xc, yc\n real(num), dimension(:,:), allocatable :: f,analytic, phi\n real(num), dimension(:), allocatable :: L2_arr, n_arr\n\n real(num) :: x, y, A, B, k, C1, C2 \n\n integer :: power, power_min, power_max\n\n type(mg_input) :: input\n\n ! setup a test problem \n\n\n\n A = 1.0_num\n B = 1.0_num\n k = 4.0_num\n\n\n \n print *,'Test6: Lphi= A * sin(k * 2pi *x)'\n print *,'x_min = fixed = B = ',B\n print *,'x_max = zerograd'\n print *,'2D => 1D via ybcs = periodic'\n print *,'also can test variable nx for convergence properties'\n\n power_min = 5\n power_max = 9 \n\n allocate(L2_arr(1:1+power_max-power_min))\n allocate(n_arr(1:1+power_max-power_min))\n L2_arr = 1e6_num\n n_arr = 0\n\n different_resolutions: do power= power_min, power_max\n\n nx = 2**power \n ny = nx\n x_min = 0.0_num\n x_max = 1.0_num ! dont change these, I've hardcoded len = 1 \n y_min = x_min\n y_max = x_max\n \n allocate(xc(-1:nx+2))\n allocate(yc(-1:ny+2))\n \n dx = (x_max - x_min) / real(nx,num)\n xc(-1) = x_min - 3.0_num * dx / 2.0_num \n do ix = 0,nx+2\n xc(ix) = xc(ix-1) + dx\n enddo\n \n dy = (y_max - y_min) / real(ny,num)\n yc(-1) = y_min - 3.0_num * dy / 2.0_num \n do iy = 0,ny+2\n yc(iy) = yc(iy-1) + dy\n enddo\n \n allocate(phi(-1:nx+2,-1:ny+2)) ! again, redundant ghosts but for comparison to CCAPS\n phi = 0.0_num \n \n allocate(analytic(1:nx,1:ny)) ! again, redundant ghosts but for comparison to CCAPS\n analytic = 0.0_num \n \n \n allocate(f(1:nx,1:ny))\n \n do iy = 1, ny\n do ix = 1, nx\n x = xc(ix)\n y = yc(iy) \n f(ix,iy) = A * sin(k * pi2 * x) \n enddo\n enddo\n \n \n ! Solve for phi\n\n input = mg_input(tol = 1e-12_num, nx=nx, ny = ny, dx=dx, dy=dy, f = f, phi = phi, &\n & bc_xmin = 'fixed', bc_xmax = 'zero_gradient', phi_bc_xmin = 1.0_num, &\n & bc_ymin = 'periodic', bc_ymax = 'periodic', &\n & deallocate_after = .true.)\n\n call mg_interface(input)\n\n phi = input%phi\n \n ! test against analytical solution\n \n do iy = 1, ny\n do ix = 1, nx\n x = xc(ix)\n y = yc(iy)\n C1 = A / k / pi2\n C2 = B\n analytic(ix,iy) = - A * sin(k * pi2 * x) *(1.0_num/k/pi2)**2 + C1*x + C2\n enddo\n enddo\n \n L2 = sqrt(sum(abs(analytic(1:nx,1:ny)-phi(1:nx,1:ny))**2) / real(nx*ny,num))\n \n print *,'L2',L2\n \n L2_arr(power-power_min+1) = L2\n n_arr(power-power_min+1) = real(nx,num)\n\n \n ! deallocate all so can do again\n \n deallocate(xc)\n deallocate(yc)\n deallocate(f)\n deallocate(phi)\n deallocate(analytic)\n\n enddo different_resolutions\n\n print *, 'L2 _arr',L2_arr\n print *, 'n _arr',n_arr\n\n call execute_command_line(\"rm -rf test6_l2.dat\")\n call execute_command_line(\"rm -rf test6_nx.dat\")\n\n open(10, file=\"test6_l2.dat\", access=\"stream\")\n write(10) L2_arr\n close(10)\n\n open(10, file=\"test6_nx.dat\", access=\"stream\")\n write(10) n_arr\n close(10)\n\n call execute_command_line(\"python test6_plots.py\")\n call execute_command_line(\"rm test6_l2.dat\")\n call execute_command_line(\"rm test6_nx.dat\")\n\n\nend program test6_reverse\n", "meta": {"hexsha": "4a7807c7b34bc7b412bbf152b3fb1a1fdbb468c3", "size": 3408, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "multigrid/2D/test6_reverse.f90", "max_stars_repo_name": "JOThurgood/SimpleCFD", "max_stars_repo_head_hexsha": "d0dc2fae9dab21c33d50b443caa727fa763c95d9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-04-23T05:31:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-04T23:21:11.000Z", "max_issues_repo_path": "multigrid/2D/test6_reverse.f90", "max_issues_repo_name": "JOThurgood/SimpleCFD", "max_issues_repo_head_hexsha": "d0dc2fae9dab21c33d50b443caa727fa763c95d9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 39, "max_issues_repo_issues_event_min_datetime": "2018-08-31T23:48:02.000Z", "max_issues_repo_issues_event_max_datetime": "2019-08-07T10:03:11.000Z", "max_forks_repo_path": "multigrid/2D/test6_reverse.f90", "max_forks_repo_name": "JOThurgood/SimpleCFD", "max_forks_repo_head_hexsha": "d0dc2fae9dab21c33d50b443caa727fa763c95d9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-11-14T20:42:54.000Z", "max_forks_repo_forks_event_max_datetime": "2019-05-18T09:16:27.000Z", "avg_line_length": 22.4210526316, "max_line_length": 88, "alphanum_fraction": 0.5915492958, "num_tokens": 1240, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680940822761, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.6992804224760027}} {"text": "!##############################################################################\n! MODULE globals\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!##############################################################################\nmodule globals\n\n implicit none\n\n ! model parameters\n real*8, parameter :: gamma = 0.5d0\n real*8, parameter :: beta = 0.99d0\n real*8, parameter :: alpha = 0.40d0\n real*8, parameter :: delta = 0.019d0\n real*8, parameter :: k0 = 10d0\n\n ! numerical parameters\n real*8, parameter :: k_l = 5d0\n real*8, parameter :: k_u = 100d0\n real*8, parameter :: sig = 1d-6\n integer, parameter :: itermax = 2000\n\n ! counter variables\n integer :: it, ik, iter\n\n ! time path of consumption and capital\n integer, parameter :: TT = 360\n real*8 :: c_t(0:TT), k_t(0:TT), y_t(0:TT)\n\n ! policy function\n integer, parameter :: NK = 100\n real*8 :: k(0:NK), c(0:NK)\n\n ! variables to numerically determine policy function\n real*8 :: c_new(0:NK), coeff_c(NK+3)\n real*8 :: con_lev, x_in\n logical :: check\n\n ! variables to communicate with function\n real*8 :: k_com\n\ncontains\n\n\n ! the first order condition\n function foc(x_in)\n\n use toolbox\n\n implicit none\n real*8, intent(in) :: x_in\n real*8 :: foc, kplus, cplus\n\n ! future capital\n kplus = (1d0-delta)*k_com + k_com**alpha - x_in\n\n ! calculate future consumption\n cplus = spline_eval(kplus, coeff_c, k_l, k_u)\n\n ! get first order condition\n foc = x_in - (beta*(1d0+alpha*kplus**(alpha-1d0)-delta))**(-gamma)*cplus\n\n end function\n\nend module\n", "meta": {"hexsha": "58673a49cd31a19624a6525dd3bfb07b84d0d6d7", "size": 1855, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "complete/prog09/prog09_01/prog09_01m.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/prog09/prog09_01/prog09_01m.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/prog09/prog09_01/prog09_01m.f90", "max_forks_repo_name": "aswinvk28/modflow_fortran", "max_forks_repo_head_hexsha": "0c8dd5da8fe08f0abcc6b677503e96cdcdb7ee1e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-04-07T12:27:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-07T12:27:47.000Z", "avg_line_length": 25.4109589041, "max_line_length": 80, "alphanum_fraction": 0.5541778976, "num_tokens": 536, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972549785201, "lm_q2_score": 0.8031737869342623, "lm_q1q2_score": 0.6992408941756716}} {"text": "c\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc . .\nc . copyright (c) 1998 by UCAR .\nc . .\nc . University Corporation for Atmospheric Research .\nc . .\nc . all rights reserved .\nc . .\nc . .\nc . SPHEREPACK .\nc . .\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc\nc\nc\nc ... file shags.f\nc\nc this file contains code and documentation for subroutines\nc shags and shagsi\nc\nc ... files which must be loaded with shags.f\nc\nc sphcom.f, hrfft.f, gaqd.f\nc\nc subroutine shags(nlat,nlon,isym,nt,g,idg,jdg,a,b,mdab,ndab,\nc 1 wshags,lshags,work,lwork,ierror)\nc\nc subroutine shags performs the spherical harmonic analysis\nc on the array g and stores the result in the arrays a and b.\nc the analysis is performed on a gaussian grid in colatitude\nc and an equally spaced grid in longitude. the associated\nc legendre functions are stored rather than recomputed as they\nc are in subroutine shagc. the analysis is described below\nc at output parameters a,b.\nc\nc input parameters\nc\nc nlat the number of points in the gaussian colatitude grid on the\nc full sphere. these lie in the interval (0,pi) and are compu\nc in radians in theta(1),...,theta(nlat) by subroutine gaqd.\nc if nlat is odd the equator will be included as the grid poi\nc theta((nlat+1)/2). if nlat is even the equator will be\nc excluded as a grid point and will lie half way between\nc theta(nlat/2) and theta(nlat/2+1). nlat must be at least 3.\nc note: on the half sphere, the number of grid points in the\nc colatitudinal direction is nlat/2 if nlat is even or\nc (nlat+1)/2 if nlat is odd.\nc\nc nlon the number of distinct londitude points. nlon determines\nc the grid increment in longitude as 2*pi/nlon. for example\nc nlon = 72 for a five degree grid. nlon must be greater\nc than or equal to 4. the efficiency of the computation is\nc improved when nlon is a product of small prime numbers.\nc\nc isym = 0 no symmetries exist about the equator. the analysis\nc is performed on the entire sphere. i.e. on the\nc array g(i,j) for i=1,...,nlat and j=1,...,nlon.\nc (see description of g below)\nc\nc = 1 g is antisymmetric about the equator. the analysis\nc is performed on the northern hemisphere only. i.e.\nc if nlat is odd the analysis is performed on the\nc array g(i,j) for i=1,...,(nlat+1)/2 and j=1,...,nlon.\nc if nlat is even the analysis is performed on the\nc array g(i,j) for i=1,...,nlat/2 and j=1,...,nlon.\nc\nc\nc = 2 g is symmetric about the equator. the analysis is\nc performed on the northern hemisphere only. i.e.\nc if nlat is odd the analysis is performed on the\nc array g(i,j) for i=1,...,(nlat+1)/2 and j=1,...,nlon.\nc if nlat is even the analysis is performed on the\nc array g(i,j) for i=1,...,nlat/2 and j=1,...,nlon.\nc\nc nt the number of analyses. in the program that calls shags,\nc the arrays g,a and b can be three dimensional in which\nc case multiple analyses will be performed. the third\nc index is the analysis index which assumes the values\nc k=1,...,nt. for a single analysis set nt=1. the\nc discription of the remaining parameters is simplified\nc by assuming that nt=1 or that the arrays g,a and b\nc have only two dimensions.\nc\nc g a two or three dimensional array (see input parameter\nc nt) that contains the discrete function to be analyzed.\nc g(i,j) contains the value of the function at the gaussian\nc point theta(i) and longitude point phi(j) = (j-1)*2*pi/nlon\nc the index ranges are defined above at the input parameter\nc isym.\nc\nc idg the first dimension of the array g as it appears in the\nc program that calls shags. if isym equals zero then idg\nc must be at least nlat. if isym is nonzero then idg must\nc be at least nlat/2 if nlat is even or at least (nlat+1)/2\nc if nlat is odd.\nc\nc jdg the second dimension of the array g as it appears in the\nc program that calls shags. jdg must be at least nlon.\nc\nc mdab the first dimension of the arrays a and b as it appears\nc in the program that calls shags. mdab must be at least\nc min0((nlon+2)/2,nlat) if nlon is even or at least\nc min0((nlon+1)/2,nlat) if nlon is odd.\nc\nc ndab the second dimension of the arrays a and b as it appears\nc in the program that calls shags. ndab must be at least nlat\nc\nc wshags an array which must be initialized by subroutine shagsi.\nc once initialized, wshags can be used repeatedly by shags\nc as long as nlat and nlon remain unchanged. wshags must\nc not be altered between calls of shags.\nc\nc lshags the dimension of the array wshags as it appears in the\nc program that calls shags. define\nc\nc l1 = min0(nlat,(nlon+2)/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc and\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc then lshags must be at least\nc\nc nlat*(3*(l1+l2)-2)+(l1-1)*(l2*(2*nlat-l1)-3*l1)/2+nlon+15\nc\nc work a real work space which need not be saved\nc\nc\nc lwork the dimension of the array work as it appears in the\nc program that calls shags. define\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc\nc if isym is zero then lwork must be at least\nc\nc nlat*nlon*(nt+1)\nc\nc if isym is nonzero then lwork must be at least\nc\nc l2*nlon*(nt+1)\nc\nc **************************************************************\nc\nc output parameters\nc\nc a,b both a,b are two or three dimensional arrays (see input\nc parameter nt) that contain the spherical harmonic\nc coefficients in the representation of g(i,j) given in the\nc discription of subroutine shags. for isym=0, a(m,n) and\nc b(m,n) are given by the equations listed below. symmetric\nc versions are used when isym is greater than zero.\nc\nc definitions\nc\nc 1. the normalized associated legendre functions\nc\nc pbar(m,n,theta) = sqrt((2*n+1)*factorial(n-m)/(2*factorial(n+m)))\nc *sin(theta)**m/(2**n*factorial(n)) times the\nc (n+m)th derivative of (x**2-1)**n with respect\nc to x=cos(theta).\nc\nc 2. the fourier transform of g(i,j).\nc\nc c(m,i) = 2/nlon times the sum from j=1 to j=nlon of\nc g(i,j)*cos((m-1)*(j-1)*2*pi/nlon)\nc (the first and last terms in this sum\nc are divided by 2)\nc\nc s(m,i) = 2/nlon times the sum from j=2 to j=nlon of\nc g(i,j)*sin((m-1)*(j-1)*2*pi/nlon)\nc\nc\nc 3. the gaussian points and weights on the sphere\nc (computed by subroutine gaqd).\nc\nc theta(1),...,theta(nlat) (gaussian pts in radians)\nc wts(1),...,wts(nlat) (corresponding gaussian weights)\nc\nc\nc 4. the maximum (plus one) longitudinal wave number\nc\nc mmax = min0(nlat,(nlon+2)/2) if nlon is even or\nc mmax = min0(nlat,(nlon+1)/2) if nlon is odd.\nc\nc\nc then for m=0,...,mmax-1 and n=m,...,nlat-1 the arrays a,b\nc are given by\nc\nc a(m+1,n+1) = the sum from i=1 to i=nlat of\nc c(m+1,i)*wts(i)*pbar(m,n,theta(i))\nc\nc b(m+1,n+1) = the sum from i=1 to nlat of\nc s(m+1,i)*wts(i)*pbar(m,n,theta(i))\nc\nc ierror = 0 no errors\nc = 1 error in the specification of nlat\nc = 2 error in the specification of nlon\nc = 3 error in the specification of isym\nc = 4 error in the specification of nt\nc = 5 error in the specification of idg\nc = 6 error in the specification of jdg\nc = 7 error in the specification of mdab\nc = 8 error in the specification of ndab\nc = 9 error in the specification of lshags\nc = 10 error in the specification of lwork\nc\nc\nc ****************************************************************\nc\nc subroutine shagsi(nlat,nlon,wshags,lshags,work,lwork,dwork,ldwork,\nc + ierror)\nc\nc subroutine shagsi initializes the array wshags which can then\nc be used repeatedly by subroutines shags. it precomputes\nc and stores in wshags quantities such as gaussian weights,\nc legendre polynomial coefficients, and fft trigonometric tables.\nc\nc input parameters\nc\nc nlat the number of points in the gaussian colatitude grid on the\nc full sphere. these lie in the interval (0,pi) and are compu\nc in radians in theta(1),...,theta(nlat) by subroutine gaqd.\nc if nlat is odd the equator will be included as the grid poi\nc theta((nlat+1)/2). if nlat is even the equator will be\nc excluded as a grid point and will lie half way between\nc theta(nlat/2) and theta(nlat/2+1). nlat must be at least 3.\nc note: on the half sphere, the number of grid points in the\nc colatitudinal direction is nlat/2 if nlat is even or\nc (nlat+1)/2 if nlat is odd.\nc\nc nlon the number of distinct londitude points. nlon determines\nc the grid increment in longitude as 2*pi/nlon. for example\nc nlon = 72 for a five degree grid. nlon must be greater\nc than or equal to 4. the efficiency of the computation is\nc improved when nlon is a product of small prime numbers.\nc\nc wshags an array which must be initialized by subroutine shagsi.\nc once initialized, wshags can be used repeatedly by shags\nc as long as nlat and nlon remain unchanged. wshags must\nc not be altered between calls of shags.\nc\nc lshags the dimension of the array wshags as it appears in the\nc program that calls shags. define\nc\nc l1 = min0(nlat,(nlon+2)/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc and\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc then lshags must be at least\nc\nc nlat*(3*(l1+l2)-2)+(l1-1)*(l2*(2*nlat-l1)-3*l1)/2+nlon+15\nc\nc work a real work space which need not be saved\nc\nc lwork the dimension of the array work as it appears in the\nc program that calls shagsi. lwork must be at least\nc 4*nlat*(nlat+2)+2 in the routine calling shagsi\nc\nc dwork a double precision work array that does not have to be saved.\nc\nc ldwork the length of dwork in the calling routine. ldwork must\nc be at least nlat*(nlat+4)\nc\nc output parameter\nc\nc wshags an array which must be initialized before calling shags or\nc once initialized, wshags can be used repeatedly by shags or\nc as long as nlat and nlon remain unchanged. wshags must not\nc altered between calls of shasc.\nc\nc ierror = 0 no errors\nc = 1 error in the specification of nlat\nc = 2 error in the specification of nlon\nc = 3 error in the specification of lshags\nc = 4 error in the specification of lwork\nc = 5 error in the specification of ldwork\nc = 6 failure in gaqd to compute gaussian points\nc (due to failure in eigenvalue routine)\nc\nc\nc ****************************************************************\n subroutine shags(nlat,nlon,mode,nt,g,idg,jdg,a,b,mdab,ndab,\n 1 wshags,lshags,work,lwork,ierror)\nc subroutine shags performs the spherical harmonic analysis on\nc a gaussian grid on the array(s) in g and returns the coefficients\nc in array(s) a,b. the necessary legendre polynomials are fully\nc stored in this version.\nc\n dimension g(idg,jdg,1),a(mdab,ndab,1),b(mdab,ndab,1),\n 1 wshags(lshags),work(lwork)\nc check input parameters\n ierror = 1\n if (nlat.lt.3) return\n ierror = 2\n if (nlon.lt.4) return\n ierror = 3\n if (mode.lt.0 .or.mode.gt.2) return\nc set m limit for pmn\n l = min0((nlon+2)/2,nlat)\nc set gaussian point nearest equator pointer\n late = (nlat+mod(nlat,2))/2\nc set number of grid points for analysis/synthesis\n lat = nlat\n if (mode.ne.0) lat = late\n ierror = 4\n if (nt.lt.1) return\n ierror = 5\n if (idg.lt.lat) return\n ierror = 6\n if (jdg.lt.nlon) return\n ierror = 7\n if(mdab .lt. l) return\n ierror = 8\n if(ndab .lt. nlat) return\n l1 = l\n l2 = late\n ierror = 9\nc check permanent work space length\nc\n lp= nlat*(3*(l1+l2)-2)+(l1-1)*(l2*(2*nlat-l1)-3*l1)/2+nlon+15\n if(lshags.lt.lp) return\n ierror = 10\nc check temporary work space length\n if (mode.eq.0 .and. lwork.lt.nlat*nlon*(nt+1)) return\n if (mode.ne.0 .and. lwork.lt.l2*nlon*(nt+1)) return\n ierror = 0\nc set starting address for gaussian wts ,fft values,\nc and fully stored legendre polys in wshags\n iwts = 1\n ifft = nlat+2*nlat*late+3*(l*(l-1)/2+(nlat-l)*(l-1))+1\n ipmn = ifft+nlon+15\nc set pointer for internal storage of g\n iw = lat*nlon*nt+1\n call shags1(nlat,nlon,l,lat,mode,g,idg,jdg,nt,a,b,mdab,ndab,\n 1wshags(iwts),wshags(ifft),wshags(ipmn),late,work,work(iw))\n return\n end\n\n subroutine shags1(nlat,nlon,l,lat,mode,gs,idg,jdg,nt,a,b,mdab,\n 1 ndab,wts,wfft,pmn,late,g,work)\n dimension gs(idg,jdg,nt),a(mdab,ndab,nt),\n 1 b(mdab,ndab,nt),g(lat,nlon,nt)\n dimension wfft(1),pmn(late,1),wts(nlat),work(1)\nc set gs array internally in shags1\n do 100 k=1,nt\n do 100 j=1,nlon\n do 100 i=1,lat\n g(i,j,k) = gs(i,j,k)\n 100 continue\n\nc do fourier transform\n do 101 k=1,nt\n call hrfftf(lat,nlon,g(1,1,k),lat,wfft,work)\n 101 continue\n\nc scale result\n sfn = 2.0/float(nlon)\n do 102 k=1,nt\n do 102 j=1,nlon\n do 102 i=1,lat\n g(i,j,k) = sfn*g(i,j,k)\n 102 continue\n\nc compute using gaussian quadrature\nc a(n,m) = s (ga(theta,m)*pnm(theta)*sin(theta)*dtheta)\nc b(n,m) = s (gb(theta,m)*pnm(theta)*sin(theta)*dtheta)\nc here ga,gb are the cos(phi),sin(phi) coefficients of\nc the fourier expansion of g(theta,phi) in phi. as a result\nc of the above fourier transform they are stored in array\nc g as follows:\nc for each theta(i) and k= l-1\nc ga(0),ga(1),gb(1),ga(2),gb(2),...,ga(k-1),gb(k-1),ga(k)\nc correspond to\nc g(i,1),g(i,2),g(i,3),g(i,4),g(i,5),...,g(i,2l-4),g(i,2l-3),g(i,2l-2)\nc whenever 2*l-2 = nlon exactly\nc initialize coefficients to zero\n do 103 k=1,nt\n do 103 np1=1,nlat\n do 103 mp1=1,l\n a(mp1,np1,k) = 0.0\n b(mp1,np1,k) = 0.0\n 103 continue\nc set mp1 limit on b(mp1) calculation\n lm1 = l\n if (nlon .eq. l+l-2) lm1 = l-1\n\n if (mode.eq.0) then\nc for full sphere (mode=0) and even/odd reduction:\nc overwrite g(i) with (g(i)+g(nlat-i+1))*wts(i)\nc overwrite g(nlat-i+1) with (g(i)-g(nlat-i+1))*wts(i)\n nl2 = nlat/2\n do 104 k=1,nt\n do 104 j=1,nlon\n do 105 i=1,nl2\n is = nlat-i+1\n t1 = g(i,j,k)\n t2 = g(is,j,k)\n g(i,j,k) = wts(i)*(t1+t2)\n g(is,j,k) = wts(i)*(t1-t2)\n 105 continue\nc adjust equator if necessary(nlat odd)\n if (mod(nlat,2).ne.0) g(late,j,k) = wts(late)*g(late,j,k)\n 104 continue\nc set m = 0 coefficients first\n mp1 = 1\n m = 0\n mml1 = m*(2*nlat-m-1)/2\n do 106 k=1,nt\n do 106 i=1,late\n is = nlat-i+1\n do 107 np1=1,nlat,2\nc n even\n a(1,np1,k) = a(1,np1,k)+g(i,1,k)*pmn(i,mml1+np1)\n 107 continue\n do 108 np1=2,nlat,2\nc n odd\n a(1,np1,k) = a(1,np1,k)+g(is,1,k)*pmn(i,mml1+np1)\n 108 continue\n 106 continue\nc compute m.ge.1 coefficients next\n do 109 mp1=2,lm1\n m = mp1-1\n mml1 = m*(2*nlat-m-1)/2\n mp2 = mp1+1\n do 110 k=1,nt\n do 111 i=1,late\n is = nlat-i+1\nc n-m even\n do 112 np1=mp1,nlat,2\n a(mp1,np1,k) = a(mp1,np1,k)+g(i,2*m,k)*pmn(i,mml1+np1)\n b(mp1,np1,k) = b(mp1,np1,k)+g(i,2*m+1,k)*pmn(i,mml1+np1)\n 112 continue\nc n-m odd\n do 113 np1=mp2,nlat,2\n a(mp1,np1,k) = a(mp1,np1,k)+g(is,2*m,k)*pmn(i,mml1+np1)\n b(mp1,np1,k) = b(mp1,np1,k)+g(is,2*m+1,k)*pmn(i,mml1+np1)\n 113 continue\n 111 continue\n 110 continue\n 109 continue\n if (nlon .eq. l+l-2) then\nc compute m=l-1, n=l-1,l,...,nlat-1 coefficients\n m = l-1\n mml1 = m*(2*nlat-m-1)/2\n do 114 k=1,nt\n do 114 i=1,late\n is = nlat-i+1\n do 124 np1=l,nlat,2\n mn = mml1+np1\n a(l,np1,k) = a(l,np1,k)+0.5*g(i,nlon,k)*pmn(i,mn)\n 124 continue\nc n-m odd\n lp1 = l+1\n do 125 np1=lp1,nlat,2\n mn = mml1+np1\n a(l,np1,k) = a(l,np1,k)+0.5*g(is,nlon,k)*pmn(i,mn)\n 125 continue\n 114 continue\n end if\n\n else\n\nc half sphere\nc overwrite g(i) with wts(i)*(g(i)+g(i)) for i=1,...,nlate/2\n nl2 = nlat/2\n do 116 k=1,nt\n do 116 j=1,nlon\n do 115 i=1,nl2\n g(i,j,k) = wts(i)*(g(i,j,k)+g(i,j,k))\n 115 continue\nc adjust equator separately if a grid point\n if (nl2.lt.late) g(late,j,k) = wts(late)*g(late,j,k)\n 116 continue\n\nc set m = 0 coefficients first\n mp1 = 1\n m = 0\n mml1 = m*(2*nlat-m-1)/2\n ms = 1\n if (mode.eq.1) ms = 2\n do 117 k=1,nt\n do 117 i=1,late\n do 117 np1=ms,nlat,2\n a(1,np1,k) = a(1,np1,k)+g(i,1,k)*pmn(i,mml1+np1)\n 117 continue\n\nc compute m.ge.1 coefficients next\n do 118 mp1=2,lm1\n m = mp1-1\n mml1 = m*(2*nlat-m-1)/2\n ms = mp1\n if (mode.eq.1) ms = mp1+1\n do 119 k=1,nt\n do 119 i=1,late\n do 119 np1=ms,nlat,2\n a(mp1,np1,k) = a(mp1,np1,k)+g(i,2*m,k)*pmn(i,mml1+np1)\n b(mp1,np1,k) = b(mp1,np1,k)+g(i,2*m+1,k)*pmn(i,mml1+np1)\n 119 continue\n 118 continue\n\n if (nlon.eq.l+l-2) then\nc compute n=m=l-1 coefficients last\n m = l-1\n mml1 = m*(2*nlat-m-1)/2\nc set starting n for mode even\n ns = l\nc set starting n for mode odd\n if (mode.eq.1) ns = l+1\n do 120 k=1,nt\n do 120 i=1,late\n do 120 np1=ns,nlat,2\n mn = mml1+np1\n a(l,np1,k) = a(l,np1,k)+0.5*g(i,nlon,k)*pmn(i,mn)\n 120 continue\n end if\n\n end if\n\n return\n end\n subroutine shagsi(nlat,nlon,wshags,lshags,work,lwork,dwork,ldwork,\n + ierror)\nc\nc this subroutine must be called before calling shags or shsgs with\nc fixed nlat,nlon. it precomputes the gaussian weights, points\nc and all necessary legendre polys and stores them in wshags.\nc these quantities must be preserved when calling shags or shsgs\nc repeatedly with fixed nlat,nlon. dwork must be of length at\nc least nlat*(nlat+4) in the routine calling shagsi. This is\nc not checked. undetectable errors will result if dwork is\nc smaller than nlat*(nlat+4).\nc\n dimension wshags(lshags),work(lwork)\n double precision dwork(ldwork)\n ierror = 1\n if (nlat.lt.3) return\n ierror = 2\n if (nlon.lt.4) return\nc set triangular truncation limit for spherical harmonic basis\n l = min0((nlon+2)/2,nlat)\nc set equator or nearest point (if excluded) pointer\n late = (nlat+1)/2\n l1 = l\n l2 = late\nc check permanent work space length\n ierror = 3\n lp=nlat*(3*(l1+l2)-2)+(l1-1)*(l2*(2*nlat-l1)-3*l1)/2+nlon+15\n if(lshags.lt.lp) return\n ierror = 4\nc check temporary work space\n if (lwork.lt.4*nlat*(nlat+2)+2) return\n ierror = 5\nc check double precision temporary space\n if (ldwork .lt. nlat*(nlat+4)) return\n ierror = 0\nc set preliminary quantites needed to compute and store legendre polys\n ldw = nlat*(nlat+4)\n call shagsp(nlat,nlon,wshags,lshags,dwork,ldwork,ierror)\n if (ierror.ne.0) return\nc set legendre poly pointer in wshags\n ipmnf = nlat+2*nlat*late+3*(l*(l-1)/2+(nlat-l)*(l-1))+nlon+16\n call shagss1(nlat,l,late,wshags,work,wshags(ipmnf))\n return\n end\n subroutine shagss1(nlat,l,late,w,pmn,pmnf)\n dimension w(1),pmn(nlat,late,3),pmnf(late,1)\nc compute and store legendre polys for i=1,...,late,m=0,...,l-1\nc and n=m,...,l-1\n do i=1,nlat\n\tdo j=1,late\n\t do k=1,3\n\t pmn(i,j,k) = 0.0\n\t end do\n\tend do\n end do\n do 100 mp1=1,l\n m = mp1-1\n mml1 = m*(2*nlat-m-1)/2\nc compute pmn for n=m,...,nlat-1 and i=1,...,(l+1)/2\n mode = 0\n call legin(mode,l,nlat,m,w,pmn,km)\nc store above in pmnf\n do 101 np1=mp1,nlat\n mn = mml1+np1\n do 102 i=1,late\n pmnf(i,mn) = pmn(np1,i,km)\n 102 continue\n 101 continue\n 100 continue\n return\n end\n subroutine shagsp(nlat,nlon,wshags,lshags,dwork,ldwork,ierror)\n dimension wshags(lshags)\n double precision dwork(ldwork)\n ierror = 1\n if (nlat.lt.3) return\n ierror = 2\n if (nlon.lt.4) return\nc set triangular truncation limit for spherical harmonic basis\n l = min0((nlon+2)/2,nlat)\nc set equator or nearest point (if excluded) pointer\n late = (nlat+mod(nlat,2))/2\n l1 = l\n l2 = late\n ierror = 3\nc check permanent work space length\n if (lshags .lt. nlat*(2*l2+3*l1-2)+3*l1*(1-l1)/2+nlon+15)return\n ierror = 4\nc if (lwork.lt.4*nlat*(nlat+2)+2) return\n if (ldwork.lt.nlat*(nlat+4))return\n ierror = 0\nc set pointers\n i1 = 1\n i2 = i1+nlat\n i3 = i2+nlat*late\n i4 = i3+nlat*late\n i5 = i4+l*(l-1)/2 +(nlat-l)*(l-1)\n i6 = i5+l*(l-1)/2 +(nlat-l)*(l-1)\n i7 = i6+l*(l-1)/2 +(nlat-l)*(l-1)\nc set indices in temp work for double precision gaussian wts and pts\n idth = 1\nc idwts = idth+2*nlat\nc iw = idwts+2*nlat\n idwts = idth+nlat\n iw = idwts+nlat\n call shagsp1(nlat,nlon,l,late,wshags(i1),wshags(i2),wshags(i3),\n 1wshags(i4),wshags(i5),wshags(i6),wshags(i7),dwork(idth),\n 2dwork(idwts),dwork(iw),ierror)\n if (ierror.ne.0) ierror = 6\n return\n end\n\n subroutine shagsp1(nlat,nlon,l,late,wts,p0n,p1n,abel,bbel,cbel,\n + wfft,dtheta,dwts,work,ier)\n dimension wts(nlat),p0n(nlat,late),p1n(nlat,late),abel(1),bbel(1),\n 1 cbel(1),wfft(1),dtheta(nlat),dwts(nlat)\n double precision pb,dtheta,dwts,work(*)\n indx(m,n) = (n-1)*(n-2)/2+m-1\n imndx(m,n) = l*(l-1)/2+(n-l-1)*(l-1)+m-1\n call hrffti(nlon,wfft)\n\nc compute double precision gaussian points and weights\nc lw = 4*nlat*(nlat+2)\n lw = nlat*(nlat+2)\n call gaqd(nlat,dtheta,dwts,work,lw,ier)\n if (ier.ne.0) return\n\nc store gaussian weights single precision to save computation\nc in inner loops in analysis\n do 100 i=1,nlat\n wts(i) = dwts(i)\n 100 continue\nc initialize p0n,p1n using double precision dnlfk,dnlft\n do 101 np1=1,nlat\n do 101 i=1,late\n p0n(np1,i) = 0.0\n p1n(np1,i) = 0.0\n 101 continue\nc compute m=n=0 legendre polynomials for all theta(i)\n np1 = 1\n n = 0\n m = 0\n call dnlfk(m,n,work)\n do 103 i=1,late\n call dnlft(m,n,dtheta(i),work,pb)\n p0n(1,i) = pb\n 103 continue\nc compute p0n,p1n for all theta(i) when n.gt.0\n do 104 np1=2,nlat\n n = np1-1\n m = 0\n call dnlfk(m,n,work)\n do 105 i=1,late\n call dnlft(m,n,dtheta(i),work,pb)\n p0n(np1,i) = pb\n 105 continue\nc compute m=1 legendre polynomials for all n and theta(i)\n m = 1\n call dnlfk(m,n,work)\n do 106 i=1,late\n call dnlft(m,n,dtheta(i),work,pb)\n p1n(np1,i) = pb\n 106 continue\n 104 continue\nc\nc compute and store swarztrauber recursion coefficients\nc for 2.le.m.le.n and 2.le.n.le.nlat in abel,bbel,cbel\n do 107 n=2,nlat\n mlim = min0(n,l)\n do 107 m=2,mlim\n imn = indx(m,n)\n if (n.ge.l) imn = imndx(m,n)\n abel(imn)=sqrt(float((2*n+1)*(m+n-2)*(m+n-3))/\n 1 float(((2*n-3)*(m+n-1)*(m+n))))\n bbel(imn)=sqrt(float((2*n+1)*(n-m-1)*(n-m))/\n 1 float(((2*n-3)*(m+n-1)*(m+n))))\n cbel(imn)=sqrt(float((n-m+1)*(n-m+2))/\n 1 float(((n+m-1)*(n+m))))\n 107 continue\n return\n end\n", "meta": {"hexsha": "a1d50f063dffbca6bdbe16bafac695a9ce7b312e", "size": 25438, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/shags.f", "max_stars_repo_name": "jprules321/colas", "max_stars_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/shags.f", "max_issues_repo_name": "jprules321/colas", "max_issues_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/shags.f", "max_forks_repo_name": "jprules321/colas", "max_forks_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.7777777778, "max_line_length": 75, "alphanum_fraction": 0.5688340278, "num_tokens": 8551, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308184368928, "lm_q2_score": 0.7490872187162396, "lm_q1q2_score": 0.6992210956469153}} {"text": " SUBROUTINE INTERP(BUF,T,NCF,NCM,NA,IFL,PV)\r\nC\r\nC+++++++++++++++++++++++++++++++++\r\nC\r\nC THIS SUBROUTINE DIFFERENTIATES AND INTERPOLATES A\r\nC SET OF CHEBYSHEV COEFFICIENTS TO GIVE POSITION AND VELOCITY\r\nC\r\nC CALLING SEQUENCE PARAMETERS:\r\nC\r\nC INPUT:\r\nC\r\nC BUF 1ST LOCATION OF ARRAY OF D.P. CHEBYSHEV COEFFICIENTS OF POSITION\r\nC\r\nC T T(1) IS DP FRACTIONAL TIME IN INTERVAL COVERED BY\r\nC COEFFICIENTS AT WHICH INTERPOLATION IS WANTED\r\nC (0 .LE. T(1) .LE. 1). T(2) IS DP LENGTH OF WHOLE\r\nC INTERVAL IN INPUT TIME UNITS.\r\nC\r\nC NCF # OF COEFFICIENTS PER COMPONENT\r\nC\r\nC NCM # OF COMPONENTS PER SET OF COEFFICIENTS\r\nC\r\nC NA # OF SETS OF COEFFICIENTS IN FULL ARRAY\r\nC (I.E., # OF SUB-INTERVALS IN FULL INTERVAL)\r\nC\r\nC IFL INTEGER FLAG: =1 FOR POSITIONS ONLY\r\nC =2 FOR POS AND VEL\r\nC\r\nC\r\nC OUTPUT:\r\nC\r\nC PV INTERPOLATED QUANTITIES REQUESTED. DIMENSION\r\nC EXPECTED IS PV(NCM,IFL), DP.\r\nC\r\nC\r\n IMPLICIT DOUBLE PRECISION (A-H,O-Z)\r\nC\r\n SAVE\r\nC\r\n DOUBLE PRECISION BUF(NCF,NCM,*),T(2),PV(NCM,*),PC(18),VC(18)\r\n\r\nC\r\n DATA NP/2/\r\n DATA NV/3/\r\n DATA TWOT/0.D0/\r\n DATA PC(1),PC(2)/1.D0,0.D0/\r\n DATA VC(2)/1.D0/\r\nC\r\nC ENTRY POINT. GET CORRECT SUB-INTERVAL NUMBER FOR THIS SET\r\nC OF COEFFICIENTS AND THEN GET NORMALIZED CHEBYSHEV TIME\r\nC WITHIN THAT SUBINTERVAL.\r\nC\r\n DNA=DBLE(NA)\r\n DT1=DINT(T(1))\r\n TEMP=DNA*T(1)\r\n L=IDINT(TEMP-DT1)+1\r\n\r\nC TC IS THE NORMALIZED CHEBYSHEV TIME (-1 .LE. TC .LE. 1)\r\n\r\n TC=2.D0*(DMOD(TEMP,1.D0)+DT1)-1.D0\r\n\r\nC CHECK TO SEE WHETHER CHEBYSHEV TIME HAS CHANGED,\r\nC AND COMPUTE NEW POLYNOMIAL VALUES IF IT HAS.\r\nC (THE ELEMENT PC(2) IS THE VALUE OF T1(TC) AND HENCE\r\nC CONTAINS THE VALUE OF TC ON THE PREVIOUS CALL.)\r\n\r\n IF(TC.NE.PC(2)) THEN\r\n NP=2\r\n NV=3\r\n PC(2)=TC\r\n TWOT=TC+TC\r\n ENDIF\r\nC\r\nC BE SURE THAT AT LEAST 'NCF' POLYNOMIALS HAVE BEEN EVALUATED\r\nC AND ARE STORED IN THE ARRAY 'PC'.\r\nC\r\n IF(NP.LT.NCF) THEN\r\n DO 1 I=NP+1,NCF\r\n PC(I)=TWOT*PC(I-1)-PC(I-2)\r\n 1 CONTINUE\r\n NP=NCF\r\n ENDIF\r\nC\r\nC INTERPOLATE TO GET POSITION FOR EACH COMPONENT\r\nC\r\n DO 2 I=1,NCM\r\n PV(I,1)=0.D0\r\n DO 3 J=NCF,1,-1\r\n PV(I,1)=PV(I,1)+PC(J)*BUF(J,I,L)\r\n 3 CONTINUE\r\n 2 CONTINUE\r\n IF(IFL.LE.1) RETURN\r\nC\r\nC IF VELOCITY INTERPOLATION IS WANTED, BE SURE ENOUGH\r\nC DERIVATIVE POLYNOMIALS HAVE BEEN GENERATED AND STORED.\r\nC\r\n VFAC=(DNA+DNA)/T(2)\r\n VC(3)=TWOT+TWOT\r\n IF(NV.LT.NCF) THEN\r\n DO 4 I=NV+1,NCF\r\n VC(I)=TWOT*VC(I-1)+PC(I-1)+PC(I-1)-VC(I-2)\r\n 4 CONTINUE\r\n NV=NCF\r\n ENDIF\r\nC\r\nC INTERPOLATE TO GET VELOCITY FOR EACH COMPONENT\r\nC\r\n DO 5 I=1,NCM\r\n PV(I,2)=0.D0\r\n DO 6 J=NCF,2,-1\r\n PV(I,2)=PV(I,2)+VC(J)*BUF(J,I,L)\r\n 6 CONTINUE\r\n PV(I,2)=PV(I,2)*VFAC\r\n 5 CONTINUE\r\nC\r\n RETURN\r\nC\r\n END\r\n\r\nC+++++++++++++++++++++++++\r\nC", "meta": {"hexsha": "a4605f08fb3a1e368e16f093cbf2e77fe64ae661", "size": 3146, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/INTERP.f", "max_stars_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_stars_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 73, "max_stars_repo_stars_event_min_datetime": "2021-07-08T23:35:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T15:17:58.000Z", "max_issues_repo_path": "src/fortran/INTERP.f", "max_issues_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_issues_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-09-27T14:27:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T23:50:02.000Z", "max_forks_repo_path": "src/fortran/INTERP.f", "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": 26.0, "max_line_length": 81, "alphanum_fraction": 0.5445009536, "num_tokens": 1100, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.933430812881347, "lm_q2_score": 0.7490872075132153, "lm_q1q2_score": 0.6992210810280789}} {"text": "\tSUBROUTINE\r\n .\tFISHEREST\r\n .\t(X0,X1,X2,FX1,FX2,ALPHA,B,C,D,E)\r\n!MS$ATTRIBUTES REFERENCE :: B\r\n!MS$ATTRIBUTES REFERENCE :: C\r\n!MS$ATTRIBUTES REFERENCE :: D\r\n!MS$ATTRIBUTES REFERENCE :: E\r\n USE MSIMSLMS\r\n\tIMPLICIT NONE\r\n\r\n\tREAL X0,X1,X2,FX1,FX2,ALPHA,B,C,D,E\r\n\r\n\tINTEGER IPATH, LDA, N\r\n\tPARAMETER (IPATH=1, LDA=4, N=4)\r\n\tREAL A(LDA,LDA), B_ARRAY(N), Y(N)\r\n\r\nC\r\nC Code:\r\nC\r\n\tB_ARRAY(1)=0.0\r\n\tB_ARRAY(2)=FX1\r\n\tB_ARRAY(3)=FX2\r\n\tB_ARRAY(4)=ALPHA\r\n\r\n\tA(1,1)=3.*X0**2\r\n\tA(2,1)=X1**3\r\n\tA(3,1)=X2**3\r\n\tA(4,1)=X0**3\r\n\t\r\n\tA(1,2)=2.*X0\r\n\tA(2,2)=X1**2\r\n\tA(3,2)=X2**2\r\n\tA(4,2)=X0**2\r\n\t\r\n\tA(1,3)=1.\r\n\tA(2,3)=X1\r\n\tA(3,3)=X2\r\n\tA(4,3)=X0\r\n\t\r\n\tA(1,4)=0.\r\n\tA(2,4)=1.\r\n\tA(3,4)=1.\r\n\tA(4,4)=1.\r\n\r\n\tCALL LSARG (N, A, LDA, B_ARRAY, IPATH, Y)\r\n\r\n\tB=Y(1)\r\n\tC=Y(2)\r\n\tD=Y(3)\r\n\tE=Y(4)\r\n\r\n\tRETURN\r\n\tEND\r\n", "meta": {"hexsha": "913011a49b97237329e037f05dcdd751cf58ba9d", "size": 793, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "misc/old_ps/ps-development-version/psDll/fisherest.for", "max_stars_repo_name": "vubiostat/ps", "max_stars_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2017-12-29T14:19:14.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-06T15:08:46.000Z", "max_issues_repo_path": "misc/old_ps/ps-development-version/psDll/fisherest.for", "max_issues_repo_name": "vubiostat/ps", "max_issues_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2020-04-30T16:57:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-07T00:26:02.000Z", "max_forks_repo_path": "misc/old_ps/ps-development-version/psDll/fisherest.for", "max_forks_repo_name": "vubiostat/ps", "max_forks_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-07T20:11:54.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-11T19:18:59.000Z", "avg_line_length": 14.6851851852, "max_line_length": 43, "alphanum_fraction": 0.527112232, "num_tokens": 396, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897525789548, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6991648522986711}} {"text": "program potencial\nuse iso_fortran_env\nuse OMP_LIB\n\nimplicit none\n\ninteger, parameter :: n = 5000000\nreal, dimension(:), allocatable :: ID, x, y, z, m, ep\nreal, parameter :: G = 4.299e+4\nreal :: dist\ninteger :: i, j\n\n\nallocate(ID(n), x(n), y(n), z(n), m(n), ep(n))\n\n!-------------leo las posiciones de las particulas---------------------\nopen(20, file='/home/vcristiani/potencial/agama_M5.dat', status='old')\ndo i=1, n\n read(20,*) ID(i), x(i), y(i), z(i), m(i)\nend do\n close(20)\n\n!======================================================================\n!Calcula la energia potencial espec\u00edfica de cada una de las particulas\n\n\n!$OMP PARALLEL DEFAULT(NONE) &\n!$OMP SHARED (x,y,z,m,ep) &\n!$OMP PRIVATE(i,j,dist)\n!$OMP DO SCHEDULE(DYNAMIC)\ndo i = 1, n\n ep(i) = 0.\n do j = 1, n\n if (i /= j) then\n\n dist = sqrt((x(i)-x(j))**2 + (y(i)-y(j))**2 + (z(i)-z(j))**2)\n ep(i) = ep(i) + m(j)/dist\n\n end if\n end do\n ep(i) = ep(i)*G\nend do\n!$OMP END DO\n!$OMP END PARALLEL\n\n!======================================================================\n\n!-------------escribo los potenciales de las particulas---------------------\nopen(30, file='/home/vcristiani/potencial/potencial_agama_M5.dat', status='new')\ndo i = 1,n\n write(30,*) ep(i)\nend do\n close(30)\n\ndeallocate(ID, x, y, z, m, ep)\n\nend program\n", "meta": {"hexsha": "8fe4ddc618f744ed828e60c761d0d3e0d2a66265", "size": 1378, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "resource/potential.f90", "max_stars_repo_name": "vcristiani/galaxy-chop", "max_stars_repo_head_hexsha": "6a854ee8701001ab0f15d6b0112401c123d0c6b2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-09-25T19:31:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-09T19:47:46.000Z", "max_issues_repo_path": "resource/potential.f90", "max_issues_repo_name": "vcristiani/galaxy-chop", "max_issues_repo_head_hexsha": "6a854ee8701001ab0f15d6b0112401c123d0c6b2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 98, "max_issues_repo_issues_event_min_datetime": "2020-10-05T20:52:22.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-11T15:28:43.000Z", "max_forks_repo_path": "resource/potential.f90", "max_forks_repo_name": "vcristiani/galaxy-chop", "max_forks_repo_head_hexsha": "6a854ee8701001ab0f15d6b0112401c123d0c6b2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-17T23:07:33.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-17T23:07:33.000Z", "avg_line_length": 23.7586206897, "max_line_length": 80, "alphanum_fraction": 0.4905660377, "num_tokens": 432, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897509188344, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6991648403618419}} {"text": "program main\n \n use numeric_kinds, only: dp\n use davidson, only: generalized_eigensolver\n use test_utils, only: apply_mtx_to_vect, apply_stx_to_vect, compute_matrix_on_the_fly, compute_stx_on_the_fly, write_matrix\n use array_utils, only: diagonal, norm, generate_diagonal_dominant\n\n implicit none\n\n integer, parameter :: dim = 50\n real(dp), dimension(3) :: eigenvalues_DPR\n real(dp), dimension(dim, 3) :: eigenvectors_DPR\n real(dp), dimension(dim) :: xs, zs\n real(dp), dimension(dim, dim) :: mtx, stx\n integer :: iter_i, j\n\n do j=1, dim\n mtx(:, j) = compute_matrix_on_the_fly(j, dim)\n stx(:, j) = compute_stx_on_the_fly(j, dim)\n end do\n\n \n call generalized_eigensolver(apply_mtx_to_vect, eigenvalues_DPR, eigenvectors_DPR, 3, \"DPR\", 1000, &\n 1d-8, iter_i, 20, apply_stx_to_vect)\n\n print \"(a, 3f8.4)\", \"eigenvalues: \", eigenvalues_DPR\n print *, \"Test 1\"\n print *, \"Check that eigenvalue equation: H V = l B V holds\"\n print *, \"DPR method:\"\n do j=1,3\n xs = matmul(mtx, eigenvectors_DPR(:, j)) - (eigenvalues_DPR(j) * matmul(stx, eigenvectors_DPR(:, j)))\n print \"(a, e10.3)\", \"error: \", norm(xs)\n print \"(a, i2, a, e12.5, a, l)\", \"eigenvalue \", j, \": \", eigenvalues_DPR(j), \" succeeded: \", norm(xs) < 1d-8\n end do\n \n print *, \"Test 2\"\n print *, \"If V are the eigenvector then V * V^T = I\"\n zs = diagonal(matmul(eigenvectors_DPR, transpose(eigenvectors_DPR)))\n ! There are only 3 eigenvectors\n print \"(a, l)\", \"DPR method: \", norm(zs(:3)) < sqrt(3.d0)\n\n\nend program main\n", "meta": {"hexsha": "28af17f64e62f81924acce63f9bd6edf44dcc282", "size": 1522, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/test_free_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_free_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_free_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": 34.5909090909, "max_line_length": 125, "alphanum_fraction": 0.6681997372, "num_tokens": 526, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.7826624688140726, "lm_q1q2_score": 0.6991597407111944}} {"text": "! Intrinsics SELECTED_INT_KIND, SELECTED_REAL_KIND, PRECISION, RANGE,\n! RADIX, DIGITS\n\nmodule m1\n ! INTEGER(KIND=1) handles 0 <= P < 3\n ! INTEGER(KIND=2) handles 3 <= P < 5\n ! INTEGER(KIND=4) handles 5 <= P < 10\n ! INTEGER(KIND=8) handles 10 <= P < 19\n ! INTEGER(KIND=16) handles 19 <= P < 39\n integer, parameter :: iranges(*) = &\n [range(0_1), range(0_2), range(0_4), range(0_8), range(0_16)]\n logical, parameter :: ircheck = all([2, 4, 9, 18, 38] == iranges)\n integer, parameter :: intpvals(*) = [0, 2, 3, 4, 5, 9, 10, 18, 19, 38, 39]\n integer, parameter :: intpkinds(*) = &\n [(selected_int_kind(intpvals(j)),j=1,size(intpvals))]\n logical, parameter :: ipcheck = &\n all([1, 1, 2, 2, 4, 4, 8, 8, 16, 16, -1] == intpkinds)\n\n ! REAL(KIND=2) handles 0 <= P < 4 (if available)\n ! REAL(KIND=3) handles 0 <= P < 3 (if available)\n ! REAL(KIND=4) handles 4 <= P < 7\n ! REAL(KIND=8) handles 7 <= P < 16\n ! REAL(KIND=10) handles 16 <= P < 19 (if available; ifort is KIND=16)\n ! REAL(KIND=16) handles 19 <= P < 34 (would be 32 with Power double/double)\n integer, parameter :: realprecs(*) = &\n [precision(0._2), precision(0._3), precision(0._4), precision(0._8), &\n precision(0._10), precision(0._16)]\n logical, parameter :: rpreccheck = all([3, 2, 6, 15, 18, 33] == realprecs)\n integer, parameter :: realpvals(*) = [0, 3, 4, 6, 7, 15, 16, 18, 19, 33, 34]\n integer, parameter :: realpkinds(*) = &\n [(selected_real_kind(realpvals(j),0),j=1,size(realpvals))]\n logical, parameter :: realpcheck = &\n all([2, 2, 4, 4, 8, 8, 10, 10, 16, 16, -1] == realpkinds)\n ! REAL(KIND=2) handles 0 <= R < 5 (if available)\n ! REAL(KIND=3) handles 5 <= R < 38 (if available, same range as KIND=4)\n ! REAL(KIND=4) handles 5 <= R < 38 (if no KIND=3)\n ! REAL(KIND=8) handles 38 <= R < 308\n ! REAL(KIND=10) handles 308 <= R < 4932 (if available; ifort is KIND=16)\n ! REAL(KIND=16) handles 4932 <= R < 9864 (except Power double/double)\n integer, parameter :: realranges(*) = &\n [range(0._2), range(0._3), range(0._4), range(0._8), range(0._10), &\n range(0._16)]\n logical, parameter :: rrangecheck = &\n all([4, 37, 37, 307, 4931, 9863] == realranges)\n integer, parameter :: realrvals(*) = &\n [0, 4, 5, 37, 38, 307, 308, 4931, 4932, 9863, 9864]\n integer, parameter :: realrkinds(*) = &\n [(selected_real_kind(0,realrvals(j)),j=1,size(realrvals))]\n logical, parameter :: realrcheck = &\n all([2, 2, 3, 3, 8, 8, 10, 10, 16, 16, -2] == realrkinds)\n logical, parameter :: radixcheck = &\n all([radix(0._2), radix(0._3), radix(0._4), radix(0._8), &\n radix(0._10), radix(0._16)] == 2)\n integer, parameter :: intdigits(*) = &\n [digits(0_1), digits(0_2), digits(0_4), digits(0_8), digits(0_16)]\n logical, parameter :: intdigitscheck = &\n all([7, 15, 31, 63, 127] == intdigits)\n integer, parameter :: realdigits(*) = &\n [digits(0._2), digits(0._3), digits(0._4), digits(0._8), digits(0._10), &\n digits(0._16)]\n logical, parameter :: realdigitscheck = &\n all([11, 8, 24, 53, 64, 112] == realdigits)\nend module m1\n!Expect: m1.mod\n!module m1\n!integer(4),parameter::iranges(1_8:*)=[INTEGER(4)::2_4,4_4,9_4,18_4,38_4]\n!logical(4),parameter::ircheck=.true._4\n!intrinsic::all\n!integer(4),parameter::intpvals(1_8:*)=[INTEGER(4)::0_4,2_4,3_4,4_4,5_4,9_4,10_4,18_4,19_4,38_4,39_4]\n!integer(4),parameter::intpkinds(1_8:*)=[INTEGER(4)::1_4,1_4,2_4,2_4,4_4,4_4,8_4,8_4,16_4,16_4,-1_4]\n!logical(4),parameter::ipcheck=.true._4\n!integer(4),parameter::realprecs(1_8:*)=[INTEGER(4)::3_4,2_4,6_4,15_4,18_4,33_4]\n!logical(4),parameter::rpreccheck=.true._4\n!integer(4),parameter::realpvals(1_8:*)=[INTEGER(4)::0_4,3_4,4_4,6_4,7_4,15_4,16_4,18_4,19_4,33_4,34_4]\n!integer(4),parameter::realpkinds(1_8:*)=[INTEGER(4)::2_4,2_4,4_4,4_4,8_4,8_4,10_4,10_4,16_4,16_4,-1_4]\n!logical(4),parameter::realpcheck=.true._4\n!integer(4),parameter::realranges(1_8:*)=[INTEGER(4)::4_4,37_4,37_4,307_4,4931_4,9863_4]\n!logical(4),parameter::rrangecheck=.true._4\n!integer(4),parameter::realrvals(1_8:*)=[INTEGER(4)::0_4,4_4,5_4,37_4,38_4,307_4,308_4,4931_4,4932_4,9863_4,9864_4]\n!integer(4),parameter::realrkinds(1_8:*)=[INTEGER(4)::2_4,2_4,3_4,3_4,8_4,8_4,10_4,10_4,16_4,16_4,-2_4]\n!logical(4),parameter::realrcheck=.true._4\n!logical(4),parameter::radixcheck=.true._4\n!integer(4),parameter::intdigits(1_8:*)=[INTEGER(4)::7_4,15_4,31_4,63_4,127_4]\n!logical(4),parameter::intdigitscheck=.true._4\n!integer(4),parameter::realdigits(1_8:*)=[INTEGER(4)::11_4,8_4,24_4,53_4,64_4,112_4]\n!logical(4),parameter::realdigitscheck=.true._4\n!end\n", "meta": {"hexsha": "90553104b8f102d4791f1985c58faf994d89cd74", "size": 4570, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/semantics/modfile26.f90", "max_stars_repo_name": "arjunsuresh1987/f18", "max_stars_repo_head_hexsha": "35fd0cda58776389d2ed68eaefbc1e1d59423ec8", "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": "test/semantics/modfile26.f90", "max_issues_repo_name": "arjunsuresh1987/f18", "max_issues_repo_head_hexsha": "35fd0cda58776389d2ed68eaefbc1e1d59423ec8", "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": "test/semantics/modfile26.f90", "max_forks_repo_name": "arjunsuresh1987/f18", "max_forks_repo_head_hexsha": "35fd0cda58776389d2ed68eaefbc1e1d59423ec8", "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": 51.9318181818, "max_line_length": 115, "alphanum_fraction": 0.6428884026, "num_tokens": 2004, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240686758841, "lm_q2_score": 0.8080672066194946, "lm_q1q2_score": 0.6991591962748754}} {"text": " PROGRAM xksone\r\nC driver for routine ksone\r\n INTEGER NPTS\r\n REAL EPS\r\n PARAMETER(NPTS=1000,EPS=0.1)\r\n INTEGER i,idum,j\r\n REAL d,data(NPTS),factr,gasdev,prob,var\r\n EXTERNAL func\r\n idum=-5\r\n write(*,'(/1x,t5,a,t24,a,t44,a/)')\r\n * 'Variance Ratio','K-S Statistic','Probability'\r\n do 12 i=1,11\r\n var=1.0+(i-1)*EPS\r\n factr=sqrt(var)\r\n do 11 j=1,NPTS\r\n data(j)=factr*abs(gasdev(idum))\r\n11 continue\r\n call ksone(data,NPTS,func,d,prob)\r\n write(*,'(1x,f14.6,f18.6,e20.4)') var,d,prob\r\n12 continue\r\n END\r\n REAL FUNCTION func(x)\r\n REAL erf,x,y\r\n y=x/sqrt(2.0)\r\n func=erf(y)\r\n END\r\n", "meta": {"hexsha": "7e69f2c8c0f977b120fb064a3337f200f931ddb9", "size": 715, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xksone.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xksone.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xksone.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": 26.4814814815, "max_line_length": 58, "alphanum_fraction": 0.5216783217, "num_tokens": 241, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220291, "lm_q2_score": 0.7853085808877581, "lm_q1q2_score": 0.6991556952884556}} {"text": "module fac_mod\n use, intrinsic :: iso_fortran_env, only : i32 => INT32\n implicit none\n\n public :: fac\n\ncontains\n\n integer(kind=i32) function fac(n)\n implicit none\n integer(kind=i32), intent(in) :: n\n integer(kind=i32) :: r = 1_i32\n integer :: i\n do i = 2, n\n r = r*i\n end do\n fac = r\n end function fac\n\nend module fac_mod\n", "meta": {"hexsha": "f28c6c4065c267e9fcda5f188144e1809c8ff987", "size": 397, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Debugging/Pfunit/Fac/fac_mod.f90", "max_stars_repo_name": "Gjacquenot/training-material", "max_stars_repo_head_hexsha": "16b29962bf5683f97a1072d961dd9f31e7468b8d", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 115, "max_stars_repo_stars_event_min_datetime": "2015-03-23T13:34:42.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T00:27:21.000Z", "max_issues_repo_path": "Debugging/Pfunit/Fac/fac_mod.f90", "max_issues_repo_name": "Gjacquenot/training-material", "max_issues_repo_head_hexsha": "16b29962bf5683f97a1072d961dd9f31e7468b8d", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 56, "max_issues_repo_issues_event_min_datetime": "2015-02-25T15:04:26.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-03T07:42:48.000Z", "max_forks_repo_path": "Debugging/Pfunit/Fac/fac_mod.f90", "max_forks_repo_name": "Gjacquenot/training-material", "max_forks_repo_head_hexsha": "16b29962bf5683f97a1072d961dd9f31e7468b8d", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 59, "max_forks_repo_forks_event_min_datetime": "2015-11-26T11:44:51.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T00:27:22.000Z", "avg_line_length": 18.9047619048, "max_line_length": 58, "alphanum_fraction": 0.5465994962, "num_tokens": 113, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8479677737461008, "lm_q2_score": 0.8244619242200081, "lm_q1q2_score": 0.6991171424192667}} {"text": " program demo_in_margin\n use :: M_verify, only : in_margin\n implicit none\n write(*,*) in_margin(4.00000,3.99999,0.000000001)\n write(*,*) in_margin(4.00000,3.99999,0.00000001)\n write(*,*) in_margin(4.00000,3.99999,0.0000001)\n write(*,*) in_margin(4.00000,3.99999,0.000001)\n\n write(*,*) in_margin([4.0,40.0,400.0,4000.0,40000.0], [3.9,39.9,399.9,3999.9,39999.9] ,0.000001)\n write(*,*) in_margin([4.0,40.0,400.0,4000.0,40000.0], [3.9,39.9,399.9,3999.9,39999.9] ,0.00001)\n\n write(*,*) in_margin(4.00000,3.99999,0.00001)\n write(*,*) in_margin(4.00000,3.99999,0.0001)\n write(*,*) in_margin(4.00000,3.99999,0.001)\n write(*,*) in_margin(4.00000,3.99999,0.01)\n\n end program demo_in_margin\n", "meta": {"hexsha": "df288565e55929297ce1b63d665d4e8079328dd8", "size": 806, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/demo_in_margin.f90", "max_stars_repo_name": "urbanjost/M_msg", "max_stars_repo_head_hexsha": "5620421b03e89228c489595f1a9436624e25f3a5", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-11-20T02:57:40.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-20T02:57:40.000Z", "max_issues_repo_path": "example/demo_in_margin.f90", "max_issues_repo_name": "urbanjost/M_msg", "max_issues_repo_head_hexsha": "5620421b03e89228c489595f1a9436624e25f3a5", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-09-27T19:45:57.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-07T23:59:06.000Z", "max_forks_repo_path": "example/demo_in_margin.f90", "max_forks_repo_name": "urbanjost/M_msg", "max_forks_repo_head_hexsha": "5620421b03e89228c489595f1a9436624e25f3a5", "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": 44.7777777778, "max_line_length": 106, "alphanum_fraction": 0.5732009926, "num_tokens": 331, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336204, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6990697078872182}} {"text": "!!\n!! Fortran 90 module with program units to do computations for a sphere.\n!! It contains a variable declaration, function and subroutine\n!!\n!! 100212, lb \n!! \nMODULE sphere\n\n ! the use statements come before the variable declarations\n USE fourthconst, ONLY : pi ! makes pi available throughout the module\n use precise, only : defaultp\n\n ! all variable declarations come here (before CONTAINS)\n IMPLICIT NONE\n INTEGER, PARAMETER, PRIVATE :: WP=defaultp\n\n! The following section stores function and subroutines\nCONTAINS\n\n ! Functions appear on the right hand side of the equal sign \n ! V = spherevolume( radius )\n ! A function to calculate the volume of a sphere as function of the\n ! radius r. Note that the function has a type (REAL) and \n ! that the result is stored under the name of the function. \n REAL(wp) FUNCTION spherevolume( r )\n\n ! The dummy argument r is a real variable\n REAL(wp) :: r\n\n spherevolume = 4./3.*pi*r**3\n\n RETURN ! The return statement is optional here. It means stop\n ! executing this function and return the result to the\n ! calling program unit\n END FUNCTION spherevolume\n\n !! alternative form (see below for explanation)\n !function spherevolume( r ) result (vol)\n !\n ! real :: r\n ! real :: vol\n ! vol = 4./3.*pi*r**3\n !\n ! return\n !end function spherevolume\n\n ! In Fortran 90 functions can return more than a standard variable\n ! (real, complex, integer, logical, character, etc.)\n ! The syntax changes a bit. Instead of giving the function itself a\n ! type we declare an additional vaiable of the appropriate type (here\n ! the array p) and put it in paranthesis behind the RESULT key word\n FUNCTION spherept( r, theta, phi) RESULT (p)\n\n ! declaration of arguments and result\n REAL(wp) :: r, theta, phi ! radius, latitude and longitude\n\n ! Two arrays with fixed dimension. Cannot change at runtime\n REAL(wp), DIMENSION(3) :: P ! (x,y,z)^T\n REAL(wp), DIMENSION(3) :: negnormal \n\n ! The negative normal vector to a sphere (pointing into the fluid,\n ! i.e. away from the center). Theta in [-pi/2,pi/2], phi in [0,2pi]\n negnormal(1) = 10.*COS(theta)*COS(phi)\n negnormal(2) = COS(theta)*SIN(phi)\n negnormal(3) = SIN(theta)\n ! or\n !negnormal = (/ cos(theta)*cos(phi), cos(theta)*sin(phi), sin(theta)/)\n\n ! we compute the point. Note that the statement is autmatically\n ! executed for all three dimensions of p\n p = r*negnormal\n\n RETURN\n END FUNCTION spherept\n\n\n ! A subroutine is a program unit that does not return a result under\n ! its own name. They are invoked with the CALL statement\n ! CALL savesphere( ... )\n SUBROUTINE savesphere( filename, comment, isym, &\n npanels, nfspanels, npoints, deltax, &\n panels, points, nfsl, nfst, ldx)\n\n ! As in the program and function, variable declarations come first\n INTEGER :: npoints, npanels, nfspanels\n INTEGER, DIMENSION(2) :: isym\n INTEGER, ALLOCATABLE, DIMENSION(:,:) :: panels\n\n ! If the string variables are dummy arguments, they can have the\n ! the length * which means they are set to the length of the\n ! actual argument when the subroutine is called.\n CHARACTER(len=*) :: filename ! file name can be max. 24 char. long\n CHARACTER(len=*) :: comment ! comment ;-)\n\n REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: points\n real(wp), allocatable, dimension(:) :: ldx\n real(wp) :: deltax\n \n ! local variables for do-loops\n INTEGER :: i,j\n \n ! variables free surface map\n INTEGER :: nfsl, nfst\n\n ! We open the file to store our discretization\n OPEN( 20, file=filename )\n\n ! write the data in the specific sequence we define\n WRITE(20, '(A)') comment ! comment\n WRITE(20, '(2I6)') isym(1), isym(2) ! symmetry flags\n WRITE(20, '(3I6)') npanels, nfspanels, npoints ! numbers of panels and\n ! points\n Write(20, '(1G16.6)') deltax ! Improvising a deltax colloc shift!\n Write(20, '(1I6)') nfsl\n Write(20, '(1I6)') nfst\n\n ! now we store the incidence table\n DO i = 1, npanels+nfspanels \n !write(20, '(4I6)') panels(1,i), panels(2,i), panels(3,i), panels(4,i)\n WRITE(20, '(4I6)') (panels(j,i), j=1,4)\n END DO\n\n \n ! now we write the point coordinates\n DO i = 1, npoints\n !write(20, '(3G16.6)') points(1,i), points(2,i), points(3,i)\n WRITE(20, '(3G16.6)') (points(j,i), j=1,3)\n END DO\n\n !write the dx array\n do i=1,nfsl\n WRITE(20, '(1G16.6)') ldx(i)\n end do\n\n ! don't forget to close the output file\n CLOSE(20)\n END SUBROUTINE savesphere\n\nEND MODULE sphere\n \n", "meta": {"hexsha": "705c1df097d6766c02ab31f634dc224969fdf2a7", "size": 4733, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "sphere.f90", "max_stars_repo_name": "LukeMcCulloch/3D-nonlinear-wave-resistance", "max_stars_repo_head_hexsha": "a818c6a484126dc63f2a92037c7f9194fb8a326a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "sphere.f90", "max_issues_repo_name": "LukeMcCulloch/3D-nonlinear-wave-resistance", "max_issues_repo_head_hexsha": "a818c6a484126dc63f2a92037c7f9194fb8a326a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sphere.f90", "max_forks_repo_name": "LukeMcCulloch/3D-nonlinear-wave-resistance", "max_forks_repo_head_hexsha": "a818c6a484126dc63f2a92037c7f9194fb8a326a", "max_forks_repo_licenses": ["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.5673758865, "max_line_length": 78, "alphanum_fraction": 0.6401859286, "num_tokens": 1330, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513814471134, "lm_q2_score": 0.7799928900257127, "lm_q1q2_score": 0.6990697052044714}} {"text": "module test\ncontains\n\n\n\nend module test\n\n\n\nprogram main\n use plantFEM\n use test\n implicit none\n\n \n real(real64),parameter :: duration=10.0d0\n integer(int32),parameter :: sampling = 4096\n type(Random_) :: random\n type(IO_) :: f,z\n type(Math_) :: Math\n integer(int32) :: i\n complex(complex64 ),allocatable :: wave(:),spectre(:)\n real(real64),allocatable :: omega(:), t(:)\n real(real64) :: dt,set_omega,set_omega_sub\n\n set_omega = (100.0d0/2.0d0/math%PI) \n set_omega_sub = (1000.0d0/2.0d0/math%PI) \n\n print *, \"w1= \", set_omega\n print *, \"w2= \", set_omega_sub\n\n create_input_wave: block\n t = linspace([0.0d0, duration], sampling)\n dt = duration/dble(sampling)\n wave = zeros(4096)\n do i=1, size(wave)\n wave(i) = random%gauss(mu=0.0d0, sigma=1.0d0)\n wave(i) = sin( set_omega*t(i) )+sin( set_omega_sub*t(i) )+random%gauss(mu=0.0d0, sigma=1.0d0)\n enddo\n wave = taper(wave,margin=0.050d0)\n end block create_input_wave\n\n show_input_wave: block\n call f%open(\"input_wave.txt\")\n call f%write( t,real(wave) )\n call f%close()\n call f%plot(option=\"with lines\")\n end block show_input_wave\n\n run_FFT: block\n omega = linspace([0.0d0, dble(sampling)/duration*2.0d0*math%PI ], sampling)\n spectre = zeros(sampling)\n spectre = FFT(wave)\n call z%open(\"spectre.txt\")\n do i=1,size(spectre)/2\n call z%write(omega(i),abs( spectre(i)))\n enddo\n call z%close()\n call z%plot(option=\"with lines\",logscale=true)\n end block run_FFT\n\nend program main", "meta": {"hexsha": "8e81684bc33b58aea481a8206ca1cd5e254d0869", "size": 1651, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/simpleFFT_withTaper.f90", "max_stars_repo_name": "kazulagi/faba", "max_stars_repo_head_hexsha": "7ef140f1ebea0e0ca496d14fdb94a3c024393cfa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-05T06:04:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:04:25.000Z", "max_issues_repo_path": "Tutorial/std/simpleFFT_withTaper.f90", "max_issues_repo_name": "kazulagi/plantFEM_binary", "max_issues_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Tutorial/std/simpleFFT_withTaper.f90", "max_forks_repo_name": "kazulagi/plantFEM_binary", "max_forks_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.6290322581, "max_line_length": 105, "alphanum_fraction": 0.5978195033, "num_tokens": 526, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513814471134, "lm_q2_score": 0.7799928900257126, "lm_q1q2_score": 0.6990697052044713}} {"text": "MODULE mo_fit\n\n ! This module contains the numerical recipes routines to fit arbitrary functions to discrete data\n\n ! Usage:\n ! USE mo_fit, ONLY: fitfun, & ! Fit function: wrapper of svdfit & svdvar\n ! fpoly, fpoly_sp, fpoly_dp, & ! Polynomial base functions\n ! polyfit, & ! Polynomial fitting routine using Lapack\n ! polyval ! Calculates polynomial values for an vectorial input\n ! svdfit, svdvar ! fitting routines + errors\n\n ! Literature\n ! SVDFit\n ! WH Press, SA Teukolsky, WT Vetterling, BP Flannery,\n ! Numerical Recipes in Fortran 90 - The Art of Parallel Scientific Computing, 2nd Edition\n ! Volume 2 of Fortran Numerical Recipes, Cambridge University Press, UK, 1996\n ! Polyfit\n ! http://rosettacode.org/wiki/Polynomial_regression#Fortran\n\n ! Attention: polyfit uses LAPACK\n\n ! Written March 2011, Matthias Cuntz - copied and adapted numerical recipes subroutines\n ! - fitfun for easy use with mask\n ! - linfit Model II: geometric mean regression\n ! Modified Matthias Cuntz, Nov 2011 - sp, dp\n ! - documentation\n ! Gregor Schuldt, Sep 2014 - polyval\n ! Matthias Cuntz, Jul 2015 - pgiFortran\n ! Matthias Cuntz, Mai 2016 - rm linfit -> use mo_linfit\n ! Matthias Cuntz, Feb 2020 - make pgiFortran code for all compilers\n\n ! License\n ! -------\n ! This file is part of the JAMS Fortran package, distributed under the MIT License.\n !\n ! Copyright (c) 2011-2020 Matthias Cuntz - mc (at) macu (dot) de\n !\n ! Permission is hereby granted, free of charge, to any person obtaining a copy\n ! of this software and associated documentation files (the \"Software\"), to deal\n ! in the Software without restriction, including without limitation the rights\n ! to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n ! copies of the Software, and to permit persons to whom the Software is\n ! furnished to do so, subject to the following conditions:\n !\n ! The above copyright notice and this permission notice shall be included in all\n ! copies or substantial portions of the Software.\n !\n ! THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n ! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n ! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n ! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n ! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n ! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n ! SOFTWARE.\n\n ! Note on Numerical Recipes License\n ! ---------------------------------\n ! Be aware that some code is under the Numerical Recipes License 3rd\n ! edition \n\n ! The Numerical Recipes Personal Single-User License lets you personally\n ! use Numerical Recipes code (\"the code\") on any number of computers,\n ! but only one computer at a time. You are not permitted to allow anyone\n ! else to access or use the code. You may, under this license, transfer\n ! precompiled, executable applications incorporating the code to other,\n ! unlicensed, persons, providing that (i) the application is\n ! noncommercial (i.e., does not involve the selling or licensing of the\n ! application for a fee), and (ii) the application was first developed,\n ! compiled, and successfully run by you, and (iii) the code is bound\n ! into the application in such a manner that it cannot be accessed as\n ! individual routines and cannot practicably be unbound and used in\n ! other programs. That is, under this license, your application user\n ! must not be able to use Numerical Recipes code as part of a program\n ! library or \"mix and match\" workbench.\n\n ! Businesses and organizations that purchase the disk or code download,\n ! and that thus acquire one or more Numerical Recipes Personal\n ! Single-User Licenses, may permanently assign those licenses, in the\n ! number acquired, to individual employees. Such an assignment must be\n ! made before the code is first used and, once made, it is irrevocable\n ! and can not be transferred.\n\n ! If you do not hold a Numerical Recipes License, this code is only for\n ! informational and educational purposes but cannot be used.\n\n USE mo_kind, ONLY: i4, sp, dp\n\n implicit NONE\n\n PUBLIC :: fitfun ! Wrapper of svdfit and svdvar\n PUBLIC :: fpoly ! Routine to fit polynomial with fitfun or svdfit\n PUBLIC :: polyfit ! Fit a polynomial (with Lapack)\n PUBLIC :: polyval ! Calculates polynomial-values for an vectorial input\n PUBLIC :: svdfit ! Parameter fitting with singular value decomposition\n PUBLIC :: svdvar ! Variance of fitted parameters with svdfit\n\n public :: fpoly_sp, fpoly_dp ! individual routines for fpoly to pass to fitting functions\n\n ! Public interfaces\n ! ------------------------------------------------------------------\n\n ! NAME\n ! fitfun\n\n ! PURPOSE\n ! Fits a given function func with the parameters a to the input data by using singular value decomposition.\n\n ! The function func must give a vector of the base functions for a given x.\n ! For example func for a polynomial should return the vector [1,x,x**2,x**3,x**4,...].\n\n ! From the numerical recipes documentation for svdfit:\n ! Given a set of N data points x, y with individual standard deviations sig, all arrays of length\n ! N, use chi^2 minimization to determine the M coefficients a of a function that depends linearly\n ! on a, y = sum_i=1^M(a x func_i(x)), with x meaning the dot-product.\n ! Here we solve the fitting equations using singular value decomposition of the NxM matrix, as in paragraph 2.6.\n ! The program returns the M basis functions evaluated at x=X in fit, the M fit parameters a,\n ! their sigma-errors siga, and chi^2 chisq.\n\n ! If an optinal mask is given, the function is only fit at those locations that correspond to true values in the mask.\n\n ! CALLING SEQUENCE\n ! call fitfun(xin, yin, sigin, a, func, mask=mask, fit=fit, chisq=chisq, siga=siga)\n\n ! INTENT(IN)\n ! real(sp/dp) :: xin(:) 1D-array with input x\n ! real(sp/dp) :: yin(:) 1D-array with input y\n ! real(sp/dp) :: sigin(:) 1D-array with input sigma on y\n ! real(sp/dp), dimension(M) :: FUNCTION func(x,n) Function that outputs the n basis functions\n\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n ! real(sp/dp), dimension(M) :: a fitted M parameters\n\n ! INTENT(IN), OPTIONAL\n ! logical :: mask(:) 1D-array of logical values with size(vec).\n ! If present, only those locations in vec corresponding to the true values in mask are used.\n\n ! INTENT(INOUT), OPTIONAL\n ! None\n\n ! INTENT(OUT), OPTIONAL\n ! real(sp/dp), dimension(N) :: fit Function evaluated at x=X\n ! real(sp/dp), dimension(M) :: siga Error of fitted parameters\n ! real(sp/dp) :: chisq Minimum chi^2\n\n ! RESTRICTIONS\n ! None\n\n ! EXAMPLE\n ! ! fit polynomial with degree 5, then detrend original\n ! integer(i4), parameter :: npt=100, npol=4 ! npol=degrees+1\n ! real(dp), dimension(npt) :: x, y, sig\n ! real(dp), dimension(npol) :: a\n ! logical, dimension(npt) :: maske\n ! maske = .true.\n ! maske(10) = .false.\n ! ! fit\n ! call fitfun(x, y, sig, a, fpoly_dp, fit=fit, mask=maske)\n ! ! detrend\n ! do i=1, npt\n ! y(i) = y(i) - dot_product(a, fpoly(x(i),npol))\n ! end do\n ! ! or\n ! y = y - fit\n\n ! LITERATURE\n ! Press WH, Teukolsky SA, Vetterling WT, & Flannery BP - Numerical Recipes in Fortran 90 -\n ! The Art of Parallel Scientific Computing, 2nd Edition, Volume 2 of Fortran Numerical Recipes,\n ! Cambridge University Press, UK, 1996\n\n ! HISTORY\n ! Written, Matthias Cuntz, Mar 2011\n INTERFACE fitfun\n MODULE PROCEDURE fitfun_sp, fitfun_dp\n END INTERFACE fitfun\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! fpoly\n\n ! PURPOSE\n ! Fitting routine for a polynomial of degree n-1, i.e. with n coefficients.\n ! Returns vector with [1,x,x**2,x**3,...,x**(n-1)].\n ! To use with fitfun or svdfit.\n\n ! CALLING SEQUENCE\n ! vec = func(x,n)\n\n ! INTENT(IN)\n ! real(sp/dp) :: x x\n ! real(sp/dp) :: n n-1 powers of x\n\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n ! real(sp/dp), dimension(n) :: func vec with [1,x,x**2,x**3,...,x**(n-1)]\n\n ! INTENT(IN), OPTIONAL\n ! None\n\n ! INTENT(INOUT), OPTIONAL\n ! None\n\n ! INTENT(OUT), OPTIONAL\n ! None\n\n ! RESTRICTIONS\n ! None\n\n ! EXAMPLE\n ! -> see example at fitfun\n\n ! LITERATURE\n ! Press WH, Teukolsky SA, Vetterling WT, & Flannery BP - Numerical Recipes in Fortran 90 -\n ! The Art of Parallel Scientific Computing, 2nd Edition, Volume 2 of Fortran Numerical Recipes,\n ! Cambridge University Press, UK, 1996\n\n ! HISTORY\n ! Written, Matthias Cuntz, Mar 2011\n INTERFACE fpoly\n MODULE PROCEDURE fpoly_sp, fpoly_dp\n END INTERFACE fpoly\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! polyfit\n\n ! PURPOSE\n ! Find an approximating polynom of known degree for a given data.\n\n ! The function polyfit implements least squares approximation of a function\n ! defined in the points as specified by the arrays xi and yi.\n ! The basis dj is xj, j=0,1,..,N. The implementation is straightforward.\n ! First the plane matrix A is created. Aji=dj(xi). Then the linear problem\n ! AATc=Ay is solved. The result cj are the coefficients. Constraint_Error\n ! is propagated when dimensions of X and Y differ or else when the problem is ill-defined.\n\n ! If an optinal mask is given, the function is only fit at those locations that correspond to true values in the mask.\n\n ! CALLING SEQUENCE\n ! out = polyfit(x, y, d, mask=mask)\n\n ! INTENT(IN)\n ! real(sp/dp) :: x(:) x\n ! real(sp/dp) :: y(:) y\n ! integer :: d d+1 parameters = polynom of degree d\n\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n ! real(sp/dp), dimension(d+1) :: polyfit fitted d+1 parameters for x^0, x^1, ..., x^d\n\n ! INTENT(IN), OPTIONAL\n ! logical :: mask(:) 1D-array of logical values with size(x)\n ! If present, only those locations in vec corresponding to the true values in mask are used.\n\n ! INTENT(INOUT), OPTIONAL\n ! None\n\n ! INTENT(OUT), OPTIONAL\n ! None\n\n ! RESTRICTIONS\n ! None\n\n ! EXAMPLE\n ! integer, parameter :: degree = 2\n ! integer :: i\n ! real(dp), dimension(11) :: x = (/ (i,i=0,10) /)\n ! real(dp), dimension(11) :: y = (/ 1, 6, 17, 34, 57, 86, 121, 162, 209, 262, 321 /)\n ! real(dp), dimension(degree+1) :: a\n ! a = polyfit(x, y, degree)\n ! write (*, '(F9.4)') a\n ! -> gives 1.0, 2.0, 3.0\n\n ! LITERATURE\n ! http://rosettacode.org/wiki/Polynomial_regression#Fortran\n\n ! HISTORY\n ! Written, Matthias Cuntz, Mar 2011\n INTERFACE polyfit\n MODULE PROCEDURE polyfit_sp, polyfit_dp\n END INTERFACE polyfit\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! polyval\n\n ! PURPOSE\n ! Evaluates a polynomial for a given vector.\n\n ! Input 'poly' must be an array containing the values for the coefficients of the polynomial.\n ! For example 'poly' for the polynomial \"1 + 2 * x + 3 * x**2\" should be (/ 1, 2, 3 /)\n\n ! Input 'xwert' can be scalar or 1D-array with values for which the user wants to evaluate the given polynomial.\n\n\n ! CALLING SEQUENCE\n ! vec = polyval(poly,xwert)\n\n ! INTENT(IN)\n ! real(sp/dp), dimension(:) :: poly polynomial-coefficients\n ! real(sp/dp)[, dimension(:)] :: xwert Evaluation-value(s)\n\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n ! real(sp/dp)[, dimension(size(xwert,1))] :: polyval (vec with) polynomial-value(s) at xwert\n\n ! INTENT(IN), OPTIONAL\n ! None\n\n ! INTENT(INOUT), OPTIONAL\n ! None\n\n ! INTENT(OUT), OPTIONAL\n ! None\n\n ! RESTRICTIONS\n ! None\n\n ! EXAMPLE\n ! For the polynom \"1 + 2 * x + 3 * x**2\" and the values 1 and 2\n ! poly = (/ 1, 2, 3/)\n ! xwert = (/ 1, 2 /)\n ! Erg = polyval(poly,xwert)\n ! ----> Erg = (/ 6, 17 /)\n\n\n ! LITERATURE\n !\n\n ! HISTORY\n ! Written, Gregor Schuldt, Sep 2014\n\n INTERFACE polyval\n MODULE PROCEDURE polyval_0d_sp, polyval_1d_sp, polyval_0d_dp, polyval_1d_dp\n END INTERFACE polyval\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! svdfit\n\n ! PURPOSE\n ! Fits a given function func with the parameters a to the input data by using singular value decomposition.\n\n ! The function func must give a vector of the base functions for a given x.\n ! For example func for a polynomial should return the vector [1,x,x**2,x**3,x**4,...].\n\n ! From the numerical recipes documentation:\n ! Given a set of datapoints x(1:ndata), y(1:ndata) with individual standard deviations\n ! sig(1:ndata), use chi2 minimization to determine the ma coefficients a of the fitting function\n ! y=sum(ai*afunci(x))). Here we solve the fitting equations using singular value decomposition\n ! of the n data by ma matrix, as in paragraph 2.6. Arrays u(1:mp,1:np), v(1:np,1:np),\n ! w(1:np) provide workspace on input; on output they define the singular value decomposition,\n ! and can be used to obtain the covariance matrix. mp,np are the physical dimensions\n ! of the matrices u,v,w, as indicated above. It is necessary that mp>=ndata, np>=ma. The\n ! program returns values for the ma fit parameters a, and chi2, chisq. The user supplies a\n ! subroutine funcs(x,afunc,ma) that returns them a basis functions evaluated at x=x\n ! in the array afunc.\n\n ! CALLING SEQUENCE\n ! call svdfit(x, y, sig, a, v, w, chisq, func)\n\n ! INTENT(IN)\n ! real(sp/dp) :: x(:) 1D-array with input x\n ! real(sp/dp) :: y(:) 1D-array with input y\n ! real(sp/dp) :: sig(:) 1D-array with input sigma on y\n ! real(sp/dp), dimension(M) :: FUNCTION func(x,n) Function that outputs the n basis functions\n\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n ! real(sp/dp), dimension(M) :: a fitted M parameters\n ! real(sp/dp) :: chisq Minimum chi^2\n ! real(sp/dp), dimension(M,M) :: v output for svdvar\n ! real(sp/dp), dimension(M) :: w output for svdvar\n\n ! INTENT(IN), OPTIONAL\n ! None\n\n ! INTENT(INOUT), OPTIONAL\n ! None\n\n ! INTENT(OUT), OPTIONAL\n ! None\n\n ! RESTRICTIONS\n ! None\n\n ! EXAMPLE\n ! ! fit polynomial with degree 5\n ! integer(i4b), parameter :: npt=100, npol=5\n ! integer(i4b) :: i\n ! real(dp) :: chisq\n ! real(dp), dimension(npol) :: a, w\n ! real(dp), dimension(npt) :: x, y, sig\n ! real(dp), dimension(npol,npol) :: cvm, v\n ! call svdfit(x, y, sig, a, v, w, chisq, fpoly_dp)\n ! call svdvar(v, w, cvm)\n ! do i=1, npol\n ! write(*,'(1x,f12.6,a,f10.6)') a(i), ' +-', sqrt(cvm(i,i))\n ! end do\n\n ! LITERATURE\n ! Press WH, Teukolsky SA, Vetterling WT, & Flannery BP - Numerical Recipes in Fortran 90 -\n ! The Art of Parallel Scientific Computing, 2nd Edition, Volume 2 of Fortran Numerical Recipes,\n ! Cambridge University Press, UK, 1996\n\n ! HISTORY\n ! Written, Matthias Cuntz, Mar 2011\n INTERFACE svdfit\n MODULE PROCEDURE svdfit_sp, svdfit_dp\n END INTERFACE svdfit\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! svdvar\n\n ! PURPOSE\n ! Calculates the variance/covariance for the singular value decomposition estimates.\n\n ! From the numerical recipes documentation:\n ! To evaluate the covariance matrix cvm of the fit for ma parameters obtained by svdfit,\n ! call this routine with matrices v,w as returned from svdfit. np,ncvm give the physical\n ! dimensions of v,w,cvm as indicated.\n\n ! CALLING SEQUENCE\n ! call svdvar(v, w, cvm)\n\n ! INTENT(IN)\n ! real(sp/dp), dimension(M,M) :: v output from svdfit\n ! real(sp/dp), dimension(M) :: w output from svdfit\n\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n ! real(sp/dp), dimension(M,M) :: cvm covariance matrix for M fitted parameters\n\n ! INTENT(IN), OPTIONAL\n ! None\n\n ! INTENT(INOUT), OPTIONAL\n ! None\n\n ! INTENT(OUT), OPTIONAL\n ! None\n\n ! RESTRICTIONS\n ! None\n\n ! EXAMPLE\n ! ! fit polynomial with degree 5\n ! integer(i4b), parameter :: npt=100, npol=5\n ! integer(i4b) :: i\n ! real(dp) :: chisq\n ! real(dp), dimension(npol) :: a, w\n ! real(dp), dimension(npt) :: x, y, sig\n ! real(dp), dimension(npol,npol) :: cvm, v\n ! call svdfit(x, y, sig, a, v, w, chisq, fpoly_dp)\n ! call svdvar(v, w, cvm)\n ! do i=1, npol\n ! write(*,'(1x,f12.6,a,f10.6)') a(i), ' +-', sqrt(cvm(i,i))\n ! end do\n\n ! LITERATURE\n ! Press WH, Teukolsky SA, Vetterling WT, & Flannery BP - Numerical Recipes in Fortran 90 -\n ! The Art of Parallel Scientific Computing, 2nd Edition, Volume 2 of Fortran Numerical Recipes,\n ! Cambridge University Press, UK, 1996\n\n ! HISTORY\n ! Written, Matthias Cuntz, Mar 2011\n INTERFACE svdvar\n MODULE PROCEDURE svdvar_sp, svdvar_dp\n END INTERFACE svdvar\n\n ! ------------------------------------------------------------------\n\n PRIVATE\n\n ! ------------------------------------------------------------------\n\n ! Private interfaces, mostly from numerical recipes\n INTERFACE geop\n MODULE PROCEDURE geop_dp, geop_i4, geop_sp, geop_v_dp, geop_v_sp\n END INTERFACE geop\n INTERFACE outerprod\n MODULE PROCEDURE outerprod_dp, outerprod_sp\n END INTERFACE outerprod\n INTERFACE pythag\n MODULE PROCEDURE pythag_dp, pythag_sp\n END INTERFACE pythag\n INTERFACE svdksb\n MODULE PROCEDURE svdksb_dp, svdksb_sp\n END INTERFACE svdksb\n INTERFACE svdcmp\n MODULE PROCEDURE svdcmp_dp, svdcmp_sp\n END INTERFACE svdcmp\n INTERFACE vabs\n MODULE PROCEDURE vabs_dp, vabs_sp\n END INTERFACE vabs\n\n ! for geop\n INTEGER(i4), PARAMETER :: NPAR_GEOP=4, NPAR2_GEOP=2\n\n ! ------------------------------------------------------------------\n\nCONTAINS\n\n ! ------------------------------------------------------------------\n\n SUBROUTINE fitfun_dp(xin, yin, sigin, a, func, mask, fit, chisq, siga)\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:), INTENT(IN) :: xin\n REAL(dp), DIMENSION(:), INTENT(IN) :: yin\n REAL(dp), DIMENSION(:), INTENT(IN) :: sigin\n REAL(dp), DIMENSION(:), INTENT(OUT) :: a\n INTERFACE\n FUNCTION func(x,n)\n USE mo_kind, ONLY: i4, dp\n IMPLICIT NONE\n REAL(dp), INTENT(IN) :: x\n INTEGER(i4), INTENT(IN) :: n\n REAL(dp), DIMENSION(n) :: func\n END FUNCTION func\n END INTERFACE\n LOGICAL, DIMENSION(:), OPTIONAL, INTENT(IN) :: mask\n REAL(dp), DIMENSION(size(xin)), OPTIONAL, INTENT(OUT) :: fit\n REAL(dp), OPTIONAL, INTENT(OUT) :: chisq\n REAL(dp), DIMENSION(size(a)), OPTIONAL, INTENT(OUT) :: siga\n\n LOGICAL, DIMENSION(size(xin)) :: maske\n REAL(dp), DIMENSION(size(a)) :: w\n REAL(dp), DIMENSION(size(a),size(a)) :: cvm, v\n REAL(dp), DIMENSION(:), ALLOCATABLE :: x, y, sig\n REAL(dp), DIMENSION(:), ALLOCATABLE :: out\n REAL(dp) :: ichisq\n INTEGER :: i, nmask, na\n\n if (size(xin) /= size(yin)) stop 'Error fitfun_dp: size(x) /= size(y)'\n if (size(sigin) /= size(yin)) stop 'Error fitfun_dp: size(sig) /= size(y)'\n maske(:) = .true.\n if (present(mask)) then\n if (size(mask) /= size(xin)) stop 'Error fitfun_dp: size(mask) /= size(x)'\n maske = mask\n endif\n nmask = count(maske)\n allocate(x(nmask))\n allocate(y(nmask))\n allocate(sig(nmask))\n x(1:nmask) = pack(xin,maske)\n y(1:nmask) = pack(yin,maske)\n sig(1:nmask) = pack(sigin,maske)\n\n call svdfit(x, y, sig, a, v, w, ichisq, func)\n\n if (present(chisq)) chisq = ichisq\n na = size(a)\n if (present(siga)) then\n call svdvar(v, w, cvm)\n do i=1, na\n siga(i) = sqrt(cvm(i,i))\n end do\n end if\n if (present(fit)) then\n allocate(out(nmask))\n do i=1, nmask\n out(i) = dot_product(a, real(func(real(x(i),dp),na),dp))\n end do\n fit = unpack(out,maske,0.0_dp)\n deallocate(out)\n endif\n\n deallocate(x)\n deallocate(y)\n deallocate(sig)\n\n END SUBROUTINE fitfun_dp\n\n\n SUBROUTINE fitfun_sp(xin, yin, sigin, a, func, mask, fit, chisq, siga)\n\n IMPLICIT NONE\n\n REAL(sp), DIMENSION(:), INTENT(IN) :: xin\n REAL(sp), DIMENSION(:), INTENT(IN) :: yin\n REAL(sp), DIMENSION(:), INTENT(IN) :: sigin\n REAL(sp), DIMENSION(:), INTENT(OUT) :: a\n INTERFACE\n FUNCTION func(x,n)\n USE mo_kind, ONLY: i4, sp\n IMPLICIT NONE\n REAL(sp), INTENT(IN) :: x\n INTEGER(i4), INTENT(IN) :: n\n REAL(sp), DIMENSION(n) :: func\n END FUNCTION func\n END INTERFACE\n LOGICAL, DIMENSION(:), OPTIONAL, INTENT(IN) :: mask\n REAL(sp), DIMENSION(size(xin)), OPTIONAL, INTENT(OUT) :: fit\n REAL(sp), OPTIONAL, INTENT(OUT) :: chisq\n REAL(sp), DIMENSION(size(a)), OPTIONAL, INTENT(OUT) :: siga\n\n LOGICAL, DIMENSION(size(xin)) :: maske\n REAL(sp), DIMENSION(size(a)) :: w\n REAL(sp), DIMENSION(size(a),size(a)) :: cvm, v\n REAL(sp), DIMENSION(:), ALLOCATABLE :: x, y, sig\n REAL(sp), DIMENSION(:), ALLOCATABLE :: out\n REAL(sp) :: ichisq\n INTEGER :: i, nmask, na\n\n if (size(xin) /= size(yin)) stop 'Error fitfun_sp: size(x) /= size(y)'\n if (size(sigin) /= size(yin)) stop 'Error fitfun_sp: size(sig) /= size(y)'\n maske(:) = .true.\n if (present(mask)) then\n if (size(mask) /= size(xin)) stop 'Error fitfun_sp: size(mask) /= size(x)'\n maske = mask\n endif\n nmask = count(maske)\n allocate(x(nmask))\n allocate(y(nmask))\n allocate(sig(nmask))\n x(1:nmask) = pack(xin,maske)\n y(1:nmask) = pack(yin,maske)\n sig(1:nmask) = pack(sigin,maske)\n\n call svdfit(x, y, sig, a, v, w, ichisq, func)\n\n if (present(chisq)) chisq = ichisq\n na = size(a)\n if (present(siga)) then\n call svdvar(v, w, cvm)\n do i=1, na\n siga(i) = sqrt(cvm(i,i))\n end do\n end if\n if (present(fit)) then\n allocate(out(nmask))\n do i=1, nmask\n out(i) = dot_product(a, real(func(real(x(i),sp),na),sp))\n end do\n fit = unpack(out,maske,0.0_sp)\n deallocate(out)\n endif\n\n deallocate(x)\n deallocate(y)\n deallocate(sig)\n\n END SUBROUTINE fitfun_sp\n\n ! ------------------------------------------------------------------\n\n FUNCTION fpoly_dp(x,n)\n\n IMPLICIT NONE\n\n REAL(dp), INTENT(IN) :: x\n INTEGER(i4), INTENT(IN) :: n\n REAL(dp), DIMENSION(n) :: fpoly_dp\n\n fpoly_dp = geop(1.0_dp,x,n)\n\n END FUNCTION fpoly_dp\n\n\n FUNCTION fpoly_sp(x,n)\n\n IMPLICIT NONE\n\n REAL(sp), INTENT(IN) :: x\n INTEGER(i4), INTENT(IN) :: n\n REAL(sp), DIMENSION(n) :: fpoly_sp\n\n fpoly_sp = geop(1.0_sp,x,n)\n\n END FUNCTION fpoly_sp\n\n ! ------------------------------------------------------------------\n\n ! From numerical recipes documentation\n ! Returns an array of length n containing a geometric progression whose first\n ! value is first and whose multiplier is factor. If first and factor\n ! have rank greater than zero, returns an array of one larger rank, with the\n ! last subscript having size n and indexing the progression.\n FUNCTION geop_dp(first,factor,n)\n\n REAL(dp), INTENT(IN) :: first,factor\n INTEGER(i4), INTENT(IN) :: n\n REAL(dp), DIMENSION(n) :: geop_dp\n\n INTEGER(i4) :: k,k2\n REAL(dp) :: temp\n\n if (n > 0) geop_dp(1)=first\n if (n <= NPAR_GEOP) then\n do k=2,n\n geop_dp(k)=geop_dp(k-1)*factor\n end do\n else\n do k=2,NPAR2_GEOP\n geop_dp(k)=geop_dp(k-1)*factor\n end do\n temp=factor**NPAR2_GEOP\n k=NPAR2_GEOP\n do\n if (k >= n) exit\n k2=k+k\n geop_dp(k+1:min(k2,n))=temp*geop_dp(1:min(k,n-k))\n temp=temp*temp\n k=k2\n end do\n end if\n\n END FUNCTION geop_dp\n\n\n FUNCTION geop_i4(first,factor,n)\n\n INTEGER(i4), INTENT(IN) :: first, factor, n\n INTEGER(i4), DIMENSION(n) :: geop_i4\n\n INTEGER(i4) :: k, k2, temp\n\n if (n > 0) geop_i4(1)=first\n if (n <= NPAR_GEOP) then\n do k=2,n\n geop_i4(k)=geop_i4(k-1)*factor\n end do\n else\n do k=2,NPAR2_GEOP\n geop_i4(k)=geop_i4(k-1)*factor\n end do\n temp=factor**NPAR2_GEOP\n k=NPAR2_GEOP\n do\n if (k >= n) exit\n k2=k+k\n geop_i4(k+1:min(k2,n))=temp*geop_i4(1:min(k,n-k))\n temp=temp*temp\n k=k2\n end do\n end if\n\n END FUNCTION geop_i4\n\n\n FUNCTION geop_sp(first,factor,n)\n\n REAL(sp), INTENT(IN) :: first,factor\n INTEGER(i4), INTENT(IN) :: n\n REAL(sp), DIMENSION(n) :: geop_sp\n\n INTEGER(i4) :: k,k2\n REAL(sp) :: temp\n\n if (n > 0) geop_sp(1)=first\n if (n <= NPAR_GEOP) then\n do k=2,n\n geop_sp(k)=geop_sp(k-1)*factor\n end do\n else\n do k=2,NPAR2_GEOP\n geop_sp(k)=geop_sp(k-1)*factor\n end do\n temp=factor**NPAR2_GEOP\n k=NPAR2_GEOP\n do\n if (k >= n) exit\n k2=k+k\n geop_sp(k+1:min(k2,n))=temp*geop_sp(1:min(k,n-k))\n temp=temp*temp\n k=k2\n end do\n end if\n\n END FUNCTION geop_sp\n\n\n FUNCTION geop_v_dp(first,factor,n)\n\n REAL(dp), DIMENSION(:), INTENT(IN) :: first, factor\n INTEGER(i4), INTENT(IN) :: n\n REAL(dp), DIMENSION(size(first),n) :: geop_v_dp\n\n INTEGER(i4) :: k,k2\n REAL(dp), DIMENSION(size(first)) :: temp\n\n if (n > 0) geop_v_dp(:,1)=first(:)\n if (n <= NPAR_GEOP) then\n do k=2,n\n geop_v_dp(:,k)=geop_v_dp(:,k-1)*factor(:)\n end do\n else\n do k=2,NPAR2_GEOP\n geop_v_dp(:,k)=geop_v_dp(:,k-1)*factor(:)\n end do\n temp=factor**NPAR2_GEOP\n k=NPAR2_GEOP\n do\n if (k >= n) exit\n k2=k+k\n geop_v_dp(:,k+1:min(k2,n))=geop_v_dp(:,1:min(k,n-k))*&\n spread(temp,2,size(geop_v_dp(:,1:min(k,n-k)),2))\n temp=temp*temp\n k=k2\n end do\n end if\n\n END FUNCTION geop_v_dp\n\n\n FUNCTION geop_v_sp(first,factor,n)\n\n REAL(sp), DIMENSION(:), INTENT(IN) :: first, factor\n INTEGER(i4), INTENT(IN) :: n\n REAL(sp), DIMENSION(size(first),n) :: geop_v_sp\n\n INTEGER(i4) :: k,k2\n REAL(sp), DIMENSION(size(first)) :: temp\n\n if (n > 0) geop_v_sp(:,1)=first(:)\n if (n <= NPAR_GEOP) then\n do k=2,n\n geop_v_sp(:,k)=geop_v_sp(:,k-1)*factor(:)\n end do\n else\n do k=2,NPAR2_GEOP\n geop_v_sp(:,k)=geop_v_sp(:,k-1)*factor(:)\n end do\n temp=factor**NPAR2_GEOP\n k=NPAR2_GEOP\n do\n if (k >= n) exit\n k2=k+k\n geop_v_sp(:,k+1:min(k2,n))=geop_v_sp(:,1:min(k,n-k))*&\n spread(temp,2,size(geop_v_sp(:,1:min(k,n-k)),2))\n temp=temp*temp\n k=k2\n end do\n end if\n\n END FUNCTION geop_v_sp\n\n ! ------------------------------------------------------------------\n\n ! From numerical recipes documentation\n ! Returns a matrix that is the outer product of two vectors.\n ! a*b with size(a)/=size(b)\n FUNCTION outerprod_dp(a,b)\n\n REAL(dp), DIMENSION(:), INTENT(IN) :: a, b\n REAL(dp), DIMENSION(size(a),size(b)) :: outerprod_dp\n\n outerprod_dp = spread(a,dim=2,ncopies=size(b)) * &\n spread(b,dim=1,ncopies=size(a))\n\n END FUNCTION outerprod_dp\n\n\n FUNCTION outerprod_sp(a,b)\n\n REAL(sp), DIMENSION(:), INTENT(IN) :: a, b\n REAL(sp), DIMENSION(size(a),size(b)) :: outerprod_sp\n\n outerprod_sp = spread(a,dim=2,ncopies=size(b)) * &\n spread(b,dim=1,ncopies=size(a))\n\n END FUNCTION outerprod_sp\n\n ! ------------------------------------------------------------------\n\n ! sqrt(a**2+b**2)\n FUNCTION pythag_dp(a,b)\n\n IMPLICIT NONE\n\n REAL(dp), INTENT(IN) :: a,b\n REAL(dp) :: pythag_dp\n\n REAL(dp) :: absa, absb\n\n absa = abs(a)\n absb = abs(b)\n if (absa > absb) then\n pythag_dp = absa*sqrt(1.0_dp+(absb/absa)**2)\n else\n if (absb < tiny(1.0_dp)) then\n pythag_dp = 0.0_dp\n else\n pythag_dp = absb*sqrt(1.0_dp+(absa/absb)**2)\n end if\n end if\n\n END FUNCTION pythag_dp\n\n\n FUNCTION pythag_sp(a,b)\n\n IMPLICIT NONE\n\n REAL(sp), INTENT(IN) :: a,b\n REAL(sp) :: pythag_sp\n\n REAL(sp) :: absa, absb\n\n absa = abs(a)\n absb = abs(b)\n if (absa > absb) then\n pythag_sp = absa*sqrt(1.0_sp+(absb/absa)**2)\n else\n if (absb < tiny(1.0_sp)) then\n pythag_sp = 0.0_sp\n else\n pythag_sp = absb*sqrt(1.0_sp+(absa/absb)**2)\n end if\n end if\n\n END FUNCTION pythag_sp\n\n ! ------------------------------------------------------------------\n\n FUNCTION polyfit_dp(vxin, vyin, d, mask)\n\n IMPLICIT NONE\n\n real(dp), dimension(:), intent(in) :: vxin, vyin\n integer, intent(in) :: d\n LOGICAL, DIMENSION(:), OPTIONAL, INTENT(IN) :: mask\n real(dp), dimension(d+1) :: polyfit_dp\n\n real(dp), dimension(:,:), allocatable :: X\n real(dp), dimension(:,:), allocatable :: XT\n real(dp), dimension(:,:), allocatable :: XTX\n integer :: i\n integer :: n, lda, lwork\n integer :: info\n integer, dimension(:), allocatable :: ipiv\n real(dp), dimension(:), allocatable :: work\n real(dp), dimension(:), allocatable :: vx, vy\n LOGICAL, DIMENSION(size(vxin)) :: maske\n integer :: nmask\n\n EXTERNAL :: DGETRF, DGETRI\n\n maske(:) = .true.\n if (present(mask)) then\n if (size(mask) /= size(vxin)) stop 'Error polyfit_dp: size(mask) /= size(vxin)'\n maske = mask\n endif\n nmask = count(maske)\n allocate(vx(nmask))\n allocate(vy(nmask))\n vx(1:nmask) = pack(vxin,maske)\n vy(1:nmask) = pack(vyin,maske)\n\n n = d+1\n lda = n\n lwork = n\n allocate(ipiv(n))\n allocate(work(lwork))\n allocate(XT(n,size(vx)))\n allocate(X(size(vx),n))\n allocate(XTX(n,n))\n\n ! prepare the matrix\n X(1:nmask,1) = 1.0_dp\n if (n > 1) X(1:nmask,2) = vx\n do i=3, n\n X(1:nmask,i) = vx(1:nmask)**(i-1)\n end do\n\n XT = transpose(X)\n XTX = matmul(XT,X)\n\n ! calls to LAPACK subs DGETRF and DGETRI\n call DGETRF(n, n, XTX, lda, ipiv, info)\n if ( info /= 0 ) stop 'Problem polyfit_dp 1'\n call DGETRI(n, XTX, lda, ipiv, work, lwork, info)\n if ( info /= 0 ) stop 'Problem polyfit_dp 2'\n\n polyfit_dp = matmul(matmul(XTX,XT), vy)\n\n deallocate(ipiv)\n deallocate(work)\n deallocate(X)\n deallocate(XT)\n deallocate(XTX)\n\n END FUNCTION polyfit_dp\n\n\n FUNCTION polyfit_sp(vxin, vyin, d, mask)\n\n IMPLICIT NONE\n\n real(sp), dimension(:), intent(in) :: vxin, vyin\n integer, intent(in) :: d\n LOGICAL, DIMENSION(:), OPTIONAL, INTENT(IN) :: mask\n real(sp), dimension(d+1) :: polyfit_sp\n\n real(sp), dimension(:,:), allocatable :: X\n real(sp), dimension(:,:), allocatable :: XT\n real(sp), dimension(:,:), allocatable :: XTX\n integer :: i\n integer :: n, lda, lwork\n integer :: info\n integer, dimension(:), allocatable :: ipiv\n real(sp), dimension(:), allocatable :: work\n real(sp), dimension(:), allocatable :: vx, vy\n LOGICAL, DIMENSION(size(vxin)) :: maske\n integer :: nmask\n\n EXTERNAL :: SGETRF, SGETRI\n\n maske(:) = .true.\n if (present(mask)) then\n if (size(mask) /= size(vxin)) stop 'Error polyfit_sp: size(mask) /= size(vxin)'\n maske = mask\n endif\n nmask = count(maske)\n allocate(vx(nmask))\n allocate(vy(nmask))\n vx(1:nmask) = pack(vxin,maske)\n vy(1:nmask) = pack(vyin,maske)\n\n n = d+1\n lda = n\n lwork = n\n allocate(ipiv(n))\n allocate(work(lwork))\n allocate(XT(n,size(vx)))\n allocate(X(size(vx),n))\n allocate(XTX(n,n))\n\n ! prepare the matrix\n X(1:nmask,1) = 1.0_sp\n if (n > 1) X(1:nmask,2) = vx\n do i=3, n\n X(1:nmask,i) = vx(1:nmask)**(i-1)\n end do\n\n XT = transpose(X)\n XTX = matmul(XT,X)\n\n ! calls to LAPACK subs SGETRF and SGETRI\n call SGETRF(n, n, XTX, lda, ipiv, info)\n if ( info /= 0 ) stop 'Problem polyfit_sp 1'\n call SGETRI(n, XTX, lda, ipiv, work, lwork, info)\n if ( info /= 0 ) stop 'Problem polyfit_sp 2'\n\n polyfit_sp = matmul(matmul(XTX,XT), vy)\n\n deallocate(ipiv)\n deallocate(work)\n deallocate(X)\n deallocate(XT)\n deallocate(XTX)\n\n END FUNCTION polyfit_sp\n\n ! ------------------------------------------------------------------\n\n function polyval_0d_sp(poly, xwert)\n\n implicit none\n\n real(sp), dimension(:), INTENT(IN) :: poly \n real(sp), INTENT(IN) :: xwert \n real(sp) :: polyval_0d_sp \n\n integer(i4) :: mm\n \n mm = size(poly, 1)\n polyval_0d_sp = dot_product( poly , fpoly(xwert, mm))\n\n end function polyval_0d_sp\n\n\n function polyval_0d_dp(poly, xwert)\n\n implicit none\n\n real(dp), dimension(:), INTENT(IN) :: poly \n real(dp), INTENT(IN) :: xwert \n real(dp) :: polyval_0d_dp \n\n integer(i4) :: mm\n\n mm = size(poly, 1)\n polyval_0d_dp = dot_product( poly , fpoly(xwert, mm))\n\n end function polyval_0d_dp\n\n function polyval_1d_sp(poly, xwert)\n\n implicit none\n\n real(sp), dimension(:), INTENT(IN) :: poly \n real(sp), dimension(:), INTENT(IN) :: xwert \n real(sp), dimension(size(xwert,1)) :: polyval_1d_sp \n\n integer(i4) :: ii, nn, mm\n\n mm = size(poly,1)\n nn = size(xwert,1)\n do ii = 1, nn\n polyval_1d_sp(ii) = dot_product( poly , fpoly(xwert(ii), mm))\n end do\n\n end function polyval_1d_sp\n\n\n function polyval_1d_dp(poly, xwert)\n\n implicit none\n\n real(dp), dimension(:), INTENT(IN) :: poly \n real(dp), dimension(:), INTENT(IN) :: xwert \n real(dp), dimension(size(xwert,1)) :: polyval_1d_dp \n\n integer(i4) :: ii, nn, mm\n \n mm = size(poly,1)\n nn = size(xwert,1)\n do ii = 1, nn\n polyval_1d_dp(ii) = dot_product( poly , fpoly(xwert(ii), mm))\n end do\n\n end function polyval_1d_dp\n\n ! ------------------------------------------------------------------\n\n ! From Numerical Recipes in F77 book\n ! Solves A*X=B for a vector X, where A is specified by the arrays u, w, v as returned by\n ! svdcmp. m and n are the logical dimensions of a, and will be equal for square matrices. mp\n ! and np are the physical dimensions of a. b(1:m) is the input right-handside. x(1:n) is\n ! the output solution vector. No input quantities are destroyed, so the routine may be called\n ! sequentially with different bs.\n SUBROUTINE svdksb_dp(u,w,v,b,x)\n\n REAL(dp), DIMENSION(:,:), INTENT(IN) :: u,v\n REAL(dp), DIMENSION(:), INTENT(IN) :: w,b\n REAL(dp), DIMENSION(:), INTENT(OUT) :: x\n !INTEGER(i4) :: ndum, mdum\n REAL(dp), DIMENSION(size(x)) :: tmp\n REAL(dp), DIMENSION(size(w)) :: wtmp\n\n if (size(u,1) /= size(b)) stop 'svdksb_dp: size(u,1) /= size(b)'\n if (size(u,2) /= size(v,1)) stop 'svdksb_dp: size(u,2) /= size(v,1)'\n if (size(u,2) /= size(v,2)) stop 'svdksb_dp: size(u,2) /= size(v,2)'\n if (size(u,2) /= size(w)) stop 'svdksb_dp: size(u,2) /= size(w)'\n if (size(u,2) /= size(x)) stop 'svdksb_dp: size(u,2) /= size(x)'\n !mdum = size(u,1)\n !ndum = size(u,2)\n wtmp = w\n where (abs(w) < tiny(1.0_dp)) wtmp = 1.0_dp\n tmp = matmul(b,u) / wtmp\n where (abs(w) < tiny(1.0_dp)) tmp = 0.0_dp\n x = matmul(v,tmp)\n\n END SUBROUTINE svdksb_dp\n\n\n SUBROUTINE svdksb_sp(u,w,v,b,x)\n\n REAL(sp), DIMENSION(:,:), INTENT(IN) :: u,v\n REAL(sp), DIMENSION(:), INTENT(IN) :: w,b\n REAL(sp), DIMENSION(:), INTENT(OUT) :: x\n !INTEGER(i4) :: ndum, mdum\n REAL(sp), DIMENSION(size(x)) :: tmp\n REAL(sp), DIMENSION(size(w)) :: wtmp\n\n if (size(u,1) /= size(b)) stop 'svdksb_sp: size(u,1) /= size(b)'\n if (size(u,2) /= size(v,1)) stop 'svdksb_sp: size(u,2) /= size(v,1)'\n if (size(u,2) /= size(v,2)) stop 'svdksb_sp: size(u,2) /= size(v,2)'\n if (size(u,2) /= size(w)) stop 'svdksb_sp: size(u,2) /= size(w)'\n if (size(u,2) /= size(x)) stop 'svdksb_sp: size(u,2) /= size(x)'\n !mdum = size(u,1)\n !ndum = size(u,2)\n wtmp = w\n where (abs(w) < tiny(1.0_sp)) wtmp = 1.0_sp\n tmp = matmul(b,u) / wtmp\n where (abs(w) < tiny(1.0_sp)) tmp = 0.0_sp\n x = matmul(v,tmp)\n\n END SUBROUTINE svdksb_sp\n\n ! ------------------------------------------------------------------\n\n ! From Numerical Recipes in F77 book\n ! Given a matrix a(1:m,1:n), with physical dimensions mp by np, this routine computes its\n ! singular value decomposition, A=U*W*VT. The matrix U replaces a on output. The\n ! diagonal matrix of singular values W is output as a vector w(1:n). The matrix V (not the\n ! transpose VT) is output as v(1:n,1:n).\n SUBROUTINE svdcmp_dp(a,w,v)\n\n use mo_utils, only: eq\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:,:), INTENT(INOUT) :: a\n REAL(dp), DIMENSION(:), INTENT(OUT) :: w\n REAL(dp), DIMENSION(:,:), INTENT(OUT) :: v\n\n INTEGER(i4) :: i, its, j, k, l, m, n, nm\n REAL(dp) :: c, f, g, h, s, scale, x, y, z, anorm\n REAL(dp), DIMENSION(size(a,1)) :: tempm\n REAL(dp), DIMENSION(size(a,2)) :: rv1, tempn\n\n m = size(a,1)\n if (size(a,2) /= size(v,1)) stop 'Error svdcmp_dp: size(a,2) /= size(v,1)'\n if (size(a,2) /= size(v,2)) stop 'Error svdcmp_dp: size(a,2) /= size(v,2)'\n if (size(a,2) /= size(w)) stop 'Error svdcmp_dp: size(a,2) /= size(w)'\n n = size(a,2)\n g = 0.0_dp\n scale = 0.0_dp\n do i=1, n\n l = i+1\n rv1(i) = scale*g\n g = 0.0_dp\n scale = 0.0_dp\n if (i <= m) then\n scale = sum(abs(a(i:m,i)))\n if (abs(scale) > 0.0_dp) then\n a(i:m,i) = a(i:m,i)/scale\n s = dot_product(a(i:m,i),a(i:m,i))\n f = a(i,i)\n g = -sign(sqrt(s),f)\n h = f*g-s\n a(i,i) = f-g\n tempn(l:n) = matmul(a(i:m,i),a(i:m,l:n))/h\n if (l <= n) & ! pgfortran out-of-bounds in debug mode\n a(i:m,l:n) = a(i:m,l:n)+outerprod(a(i:m,i),tempn(l:n))\n a(i:m,i) = scale*a(i:m,i)\n end if\n end if\n w(i) = scale*g\n g = 0.0_dp\n scale = 0.0_dp\n if ((i <= m) .and. (i /= n)) then\n scale = sum(abs(a(i,l:n)))\n if (abs(scale) > 0.0_dp) then\n a(i,l:n) = a(i,l:n)/scale\n s = dot_product(a(i,l:n),a(i,l:n))\n f = a(i,l)\n g = -sign(sqrt(s),f)\n h = f*g-s\n a(i,l) = f-g\n rv1(l:n) = a(i,l:n)/h\n tempm(l:m) = matmul(a(l:m,l:n),a(i,l:n))\n a(l:m,l:n) = a(l:m,l:n)+outerprod(tempm(l:m),rv1(l:n))\n a(i,l:n) = scale*a(i,l:n)\n end if\n end if\n end do\n anorm = maxval(abs(w)+abs(rv1))\n do i=n, 1, -1\n if (i < n) then\n if (abs(g) > 0.0_dp) then\n v(l:n,i) = (a(i,l:n)/a(i,l))/g\n tempn(l:n) = matmul(a(i,l:n),v(l:n,l:n))\n v(l:n,l:n) = v(l:n,l:n)+outerprod(v(l:n,i),tempn(l:n))\n end if\n v(i,l:n) = 0.0_dp\n v(l:n,i) = 0.0_dp\n end if\n v(i,i) = 1.0_dp\n g = rv1(i)\n l = i\n end do\n do i=min(m,n), 1, -1\n l = i+1\n g = w(i)\n a(i,l:n) = 0.0_dp\n if (abs(g) > 0.0_dp) then\n g = 1.0_dp/g\n tempn(l:n) = (matmul(a(l:m,i),a(l:m,l:n))/a(i,i))*g\n if (l <= n) & ! pgfortran out-of-bounds in debug mode\n a(i:m,l:n) = a(i:m,l:n)+outerprod(a(i:m,i),tempn(l:n))\n a(i:m,i) = a(i:m,i)*g\n else\n a(i:m,i) = 0.0_dp\n end if\n a(i,i) = a(i,i)+1.0_dp\n end do\n do k=n, 1, -1\n do its=1, 30\n do l=k, 1, -1\n nm = l-1\n ! if ((abs(rv1(l))+anorm) == anorm) exit\n ! if ((abs(w(nm))+anorm) == anorm) then\n if (eq(abs(rv1(l))+anorm, anorm)) exit\n if (eq(abs(w(nm))+anorm, anorm)) then\n c = 0.0_dp\n s = 1.0_dp\n do i=l, k\n f = s*rv1(i)\n rv1(i) = c*rv1(i)\n ! if ((abs(f)+anorm) == anorm) exit\n if (eq(abs(f)+anorm, anorm)) exit\n g = w(i)\n h = pythag(f,g)\n w(i) = h\n h = 1.0_dp/h\n c = (g*h)\n s = -(f*h)\n tempm(1:m) = a(1:m,nm)\n a(1:m,nm) = a(1:m,nm)*c+a(1:m,i)*s\n a(1:m,i) = -tempm(1:m)*s+a(1:m,i)*c\n end do\n exit\n end if\n end do\n z = w(k)\n if (l == k) then\n if (z < 0.0_dp) then\n w(k) = -z\n v(1:n,k) = -v(1:n,k)\n end if\n exit\n end if\n if (its == 30) stop 'svdcmp_dp: no convergence in svdcmp_dp'\n x = w(l)\n nm = k-1\n y = w(nm)\n g = rv1(nm)\n h = rv1(k)\n f = ((y-z)*(y+z)+(g-h)*(g+h))/(2.0_dp*h*y)\n g = pythag(f,1.0_dp)\n f = ((x-z)*(x+z)+h*((y/(f+sign(g,f)))-h))/x\n c = 1.0_dp\n s = 1.0_dp\n do j=l, nm\n i = j+1\n g = rv1(i)\n y = w(i)\n h = s*g\n g = c*g\n z = pythag(f,h)\n rv1(j) = z\n c = f/z\n s = h/z\n f = (x*c)+(g*s)\n g = -(x*s)+(g*c)\n h = y*s\n y = y*c\n tempn(1:n) = v(1:n,j)\n v(1:n,j) = v(1:n,j)*c+v(1:n,i)*s\n v(1:n,i) = -tempn(1:n)*s+v(1:n,i)*c\n z = pythag(f,h)\n w(j) = z\n if (abs(z) > 0.0_dp) then\n z = 1.0_dp/z\n c = f*z\n s = h*z\n end if\n f = (c*g)+(s*y)\n x = -(s*g)+(c*y)\n tempm(1:m) = a(1:m,j)\n a(1:m,j) = a(1:m,j)*c+a(1:m,i)*s\n a(1:m,i) = -tempm(1:m)*s+a(1:m,i)*c\n end do\n rv1(l) = 0.0_dp\n rv1(k) = f\n w(k) = x\n end do\n end do\n\n END SUBROUTINE svdcmp_dp\n\n\n SUBROUTINE svdcmp_sp(a,w,v)\n\n use mo_utils, only: eq\n\n IMPLICIT NONE\n\n REAL(sp), DIMENSION(:,:), INTENT(INOUT) :: a\n REAL(sp), DIMENSION(:), INTENT(OUT) :: w\n REAL(sp), DIMENSION(:,:), INTENT(OUT) :: v\n\n INTEGER(i4) :: i, its, j, k, l, m, n, nm\n REAL(sp) :: c, f, g, h, s, scale, x, y, z, anorm\n REAL(sp), DIMENSION(size(a,1)) :: tempm\n REAL(sp), DIMENSION(size(a,2)) :: rv1, tempn\n\n m = size(a,1)\n if (size(a,2) /= size(v,1)) stop 'Error svdcmp_sp: size(a,2) /= size(v,1)'\n if (size(a,2) /= size(v,2)) stop 'Error svdcmp_sp: size(a,2) /= size(v,2)'\n if (size(a,2) /= size(w)) stop 'Error svdcmp_sp: size(a,2) /= size(w)'\n n = size(a,2)\n g = 0.0_sp\n scale = 0.0_sp\n do i=1, n\n l = i+1\n rv1(i) = scale*g\n g = 0.0_sp\n scale = 0.0_sp\n if (i <= m) then\n scale = sum(abs(a(i:m,i)))\n if (abs(scale) > 0.0_sp) then\n a(i:m,i) = a(i:m,i)/scale\n s = dot_product(a(i:m,i),a(i:m,i))\n f = a(i,i)\n g = -sign(sqrt(s),f)\n h = f*g-s\n a(i,i) = f-g\n tempn(l:n) = matmul(a(i:m,i),a(i:m,l:n))/h\n if (l <= n) & ! pgfortran out-of-bounds in debug mode\n a(i:m,l:n) = a(i:m,l:n)+outerprod(a(i:m,i),tempn(l:n))\n a(i:m,i) = scale*a(i:m,i)\n end if\n end if\n w(i) = scale*g\n g = 0.0_sp\n scale = 0.0_sp\n if ((i <= m) .and. (i /= n)) then\n scale = sum(abs(a(i,l:n)))\n if (abs(scale) > 0.0_sp) then\n a(i,l:n) = a(i,l:n)/scale\n s = dot_product(a(i,l:n),a(i,l:n))\n f = a(i,l)\n g = -sign(sqrt(s),f)\n h = f*g-s\n a(i,l) = f-g\n rv1(l:n) = a(i,l:n)/h\n tempm(l:m) = matmul(a(l:m,l:n),a(i,l:n))\n a(l:m,l:n) = a(l:m,l:n)+outerprod(tempm(l:m),rv1(l:n))\n a(i,l:n) = scale*a(i,l:n)\n end if\n end if\n end do\n anorm = maxval(abs(w)+abs(rv1))\n do i=n, 1, -1\n if (i < n) then\n if (abs(g) > 0.0_sp) then\n v(l:n,i) = (a(i,l:n)/a(i,l))/g\n tempn(l:n) = matmul(a(i,l:n),v(l:n,l:n))\n v(l:n,l:n) = v(l:n,l:n)+outerprod(v(l:n,i),tempn(l:n))\n end if\n v(i,l:n) = 0.0_sp\n v(l:n,i) = 0.0_sp\n end if\n v(i,i) = 1.0_sp\n g = rv1(i)\n l = i\n end do\n do i=min(m,n), 1, -1\n l = i+1\n g = w(i)\n a(i,l:n) = 0.0_sp\n if (abs(g) > 0.0_sp) then\n g = 1.0_sp/g\n tempn(l:n) = (matmul(a(l:m,i),a(l:m,l:n))/a(i,i))*g\n if (l <= n) & ! pgfortran out-of-bounds in debug mode\n a(i:m,l:n) = a(i:m,l:n)+outerprod(a(i:m,i),tempn(l:n))\n a(i:m,i) = a(i:m,i)*g\n else\n a(i:m,i) = 0.0_sp\n end if\n a(i,i) = a(i,i)+1.0_sp\n end do\n do k=n, 1, -1\n do its=1, 30\n do l=k, 1, -1\n nm = l-1\n ! if ((abs(rv1(l))+anorm) == anorm) exit\n ! if ((abs(w(nm))+anorm) == anorm) then\n if (eq(abs(rv1(l))+anorm, anorm)) exit\n if (eq(abs(w(nm))+anorm, anorm)) then\n c = 0.0_sp\n s = 1.0_sp\n do i=l, k\n f = s*rv1(i)\n rv1(i) = c*rv1(i)\n ! if ((abs(f)+anorm) == anorm) exit\n if (eq(abs(f)+anorm, anorm)) exit\n g = w(i)\n h = pythag(f,g)\n w(i) = h\n h = 1.0_sp/h\n c = (g*h)\n s = -(f*h)\n tempm(1:m) = a(1:m,nm)\n a(1:m,nm) = a(1:m,nm)*c+a(1:m,i)*s\n a(1:m,i) = -tempm(1:m)*s+a(1:m,i)*c\n end do\n exit\n end if\n end do\n z = w(k)\n if (l == k) then\n if (z < 0.0_sp) then\n w(k) = -z\n v(1:n,k) = -v(1:n,k)\n end if\n exit\n end if\n if (its == 30) stop 'svdcmp_sp: no convergence in svdcmp_sp'\n x = w(l)\n nm = k-1\n y = w(nm)\n g = rv1(nm)\n h = rv1(k)\n f = ((y-z)*(y+z)+(g-h)*(g+h))/(2.0_sp*h*y)\n g = pythag(f,1.0_sp)\n f = ((x-z)*(x+z)+h*((y/(f+sign(g,f)))-h))/x\n c = 1.0_sp\n s = 1.0_sp\n do j=l, nm\n i = j+1\n g = rv1(i)\n y = w(i)\n h = s*g\n g = c*g\n z = pythag(f,h)\n rv1(j) = z\n c = f/z\n s = h/z\n f = (x*c)+(g*s)\n g = -(x*s)+(g*c)\n h = y*s\n y = y*c\n tempn(1:n) = v(1:n,j)\n v(1:n,j) = v(1:n,j)*c+v(1:n,i)*s\n v(1:n,i) = -tempn(1:n)*s+v(1:n,i)*c\n z = pythag(f,h)\n w(j) = z\n if (abs(z) > 0.0_sp) then\n z = 1.0_sp/z\n c = f*z\n s = h*z\n end if\n f = (c*g)+(s*y)\n x = -(s*g)+(c*y)\n tempm(1:m) = a(1:m,j)\n a(1:m,j) = a(1:m,j)*c+a(1:m,i)*s\n a(1:m,i) = -tempm(1:m)*s+a(1:m,i)*c\n end do\n rv1(l) = 0.0_sp\n rv1(k) = f\n w(k) = x\n end do\n end do\n\n END SUBROUTINE svdcmp_sp\n\n ! ------------------------------------------------------------------\n\n SUBROUTINE svdfit_dp(ix, iy, isig, oa, ov, ow, ochisq, func)\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:), INTENT(IN) :: ix, iy, isig\n REAL(dp), DIMENSION(:), INTENT(OUT) :: oa, ow\n REAL(dp), DIMENSION(:,:), INTENT(OUT) :: ov\n REAL(dp), INTENT(OUT) :: ochisq\n INTERFACE\n FUNCTION func(x,n)\n USE mo_kind, ONLY: i4, dp\n IMPLICIT NONE\n REAL(dp), INTENT(IN) :: x\n INTEGER(i4), INTENT(IN) :: n\n REAL(dp), DIMENSION(n) :: func\n END FUNCTION func\n END INTERFACE\n\n REAL(dp), DIMENSION(size(ix)) :: x\n REAL(dp), DIMENSION(size(iy)) :: y\n REAL(dp), DIMENSION(size(isig)) :: sig\n REAL(dp), DIMENSION(size(oa)) :: a\n REAL(dp), DIMENSION(size(ow)) :: w\n REAL(dp), DIMENSION(size(ov,1),size(ov,2)) :: v\n REAL(dp) :: chisq\n\n REAL(dp), PARAMETER :: TOL = 1.0e-5_dp\n INTEGER(i4) :: i, ma, n\n REAL(dp), DIMENSION(size(x)) :: b, sigi\n REAL(dp), DIMENSION(size(x),size(a)) :: u, usav\n\n if (size(ix) /= size(iy)) stop 'Error svdfit_dp: size(x) /= size(y)'\n if (size(iy) /= size(isig)) stop 'Error svdfit_dp: size(y) /= size(sig)'\n if (size(oa) /= size(ov,1)) stop 'Error svdfit_dp: size(a) /= size(v,1)'\n if (size(oa) /= size(ov,2)) stop 'Error svdfit_dp: size(a) /= size(v,2)'\n if (size(oa) /= size(ow)) stop 'Error svdfit_dp: size(a) /= size(w)'\n \n x = real(ix,dp)\n y = real(iy,dp)\n sig = real(isig,dp)\n\n n = size(x)\n ma = size(a)\n sigi = 1.0_dp/sig\n b = y*sigi\n do i=1, n\n usav(i,:) = func(x(i),ma)\n end do\n u = usav*spread(sigi,dim=2,ncopies=ma)\n usav = u\n call svdcmp(u,w,v)\n where (w < TOL*maxval(w)) w = 0.0_dp\n call svdksb(u,w,v,b,a)\n chisq = vabs(matmul(usav,a)-b)**2\n\n oa = real(a,dp)\n ow = real(w,dp)\n ov = real(v,dp)\n ochisq = real(chisq,dp)\n\n END SUBROUTINE svdfit_dp\n\n\n SUBROUTINE svdfit_sp(ix, iy, isig, oa, ov, ow, ochisq, func)\n\n IMPLICIT NONE\n\n REAL(sp), DIMENSION(:), INTENT(IN) :: ix, iy, isig\n REAL(sp), DIMENSION(:), INTENT(OUT) :: oa, ow\n REAL(sp), DIMENSION(:,:), INTENT(OUT) :: ov\n REAL(sp), INTENT(OUT) :: ochisq\n INTERFACE\n FUNCTION func(x,n)\n USE mo_kind, ONLY: i4, sp\n IMPLICIT NONE\n REAL(sp), INTENT(IN) :: x\n INTEGER(i4), INTENT(IN) :: n\n REAL(sp), DIMENSION(n) :: func\n END FUNCTION func\n END INTERFACE\n\n REAL(sp), DIMENSION(size(ix)) :: x\n REAL(sp), DIMENSION(size(iy)) :: y\n REAL(sp), DIMENSION(size(isig)) :: sig\n REAL(sp), DIMENSION(size(oa)) :: a\n REAL(sp), DIMENSION(size(ow)) :: w\n REAL(sp), DIMENSION(size(ov,1),size(ov,2)) :: v\n REAL(sp) :: chisq\n\n REAL(sp), PARAMETER :: TOL = 1.0e-5_sp\n INTEGER(i4) :: i, ma, n\n REAL(sp), DIMENSION(size(x)) :: b, sigi\n REAL(sp), DIMENSION(size(x),size(a)) :: u, usav\n\n if (size(ix) /= size(iy)) stop 'Error svdfit_sp: size(x) /= size(y)'\n if (size(iy) /= size(isig)) stop 'Error svdfit_sp: size(y) /= size(sig)'\n if (size(oa) /= size(ov,1)) stop 'Error svdfit_sp: size(a) /= size(v,1)'\n if (size(oa) /= size(ov,2)) stop 'Error svdfit_sp: size(a) /= size(v,2)'\n if (size(oa) /= size(ow)) stop 'Error svdfit_sp: size(a) /= size(w)'\n\n x = real(ix,sp)\n y = real(iy,sp)\n sig = real(isig,sp)\n\n n = size(x)\n ma = size(a)\n sigi = 1.0_sp/sig\n b = y*sigi\n do i=1, n\n usav(i,:) = func(x(i),ma)\n end do\n u = usav*spread(sigi,dim=2,ncopies=ma)\n usav = u\n call svdcmp(u,w,v)\n where (w < TOL*maxval(w)) w = 0.0_sp\n call svdksb(u,w,v,b,a)\n chisq = vabs(matmul(usav,a)-b)**2\n\n oa = real(a,sp)\n ow = real(w,sp)\n ov = real(v,sp)\n ochisq = real(chisq,sp)\n\n END SUBROUTINE svdfit_sp\n\n ! ------------------------------------------------------------------\n\n SUBROUTINE svdvar_dp(v, w, cvm)\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:,:), INTENT(IN) :: v\n REAL(dp), DIMENSION(:), INTENT(IN) :: w\n REAL(dp), DIMENSION(:,:), INTENT(OUT) :: cvm\n\n INTEGER(i4) :: ma\n REAL(dp), DIMENSION(size(w)) :: wti\n REAL(dp), DIMENSION(size(w)) :: wtmp\n\n if (size(v,1) /= size(v,2)) stop 'Error svdvar_dp: size(v,1) /= size(v,2)'\n if (size(v,1) /= size(w)) stop 'Error svdvar_dp: size(v,1) /= size(w)'\n if (size(v,1) /= size(cvm,1)) stop 'Error svdvar_dp: size(v,1) /= size(cvm,1)'\n if (size(v,1) /= size(cvm,2)) stop 'Error svdvar_dp: size(v,1) /= size(cvm,2)'\n\n ma = size(v,1)\n wtmp = w\n where (abs(w) < tiny(1.0_dp)) wtmp = 1.0_dp\n wti = 1.0_dp/(wtmp*wtmp)\n where (abs(w) < tiny(1.0_dp)) wti = 0.0_dp\n cvm = v*spread(wti,dim=1,ncopies=ma)\n cvm = matmul(cvm,transpose(v))\n\n END SUBROUTINE svdvar_dp\n\n\n SUBROUTINE svdvar_sp(v, w, cvm)\n\n IMPLICIT NONE\n\n REAL(sp), DIMENSION(:,:), INTENT(IN) :: v\n REAL(sp), DIMENSION(:), INTENT(IN) :: w\n REAL(sp), DIMENSION(:,:), INTENT(OUT) :: cvm\n\n INTEGER(i4) :: ma\n REAL(sp), DIMENSION(size(w)) :: wti\n REAL(sp), DIMENSION(size(w)) :: wtmp\n\n if (size(v,1) /= size(v,2)) stop 'Error svdvar_sp: size(v,1) /= size(v,2)'\n if (size(v,1) /= size(w)) stop 'Error svdvar_sp: size(v,1) /= size(w)'\n if (size(v,1) /= size(cvm,1)) stop 'Error svdvar_sp: size(v,1) /= size(cvm,1)'\n if (size(v,1) /= size(cvm,2)) stop 'Error svdvar_sp: size(v,1) /= size(cvm,2)'\n\n ma = size(v,1)\n wtmp = w\n where (abs(w) < tiny(1.0_sp)) wtmp = 1.0_sp\n wti = 1.0_sp/(wtmp*wtmp)\n where (abs(w) < tiny(1.0_sp)) wti = 0.0_sp\n cvm = v*spread(wti,dim=1,ncopies=ma)\n cvm = matmul(cvm,transpose(v))\n\n END SUBROUTINE svdvar_sp\n\n ! ------------------------------------------------------------------\n\n ! From numerical recipes documentation\n ! Returns the length of a vector v in L2 norm, that is,the square root of the sum\n ! of the squares of the components. (For complex types, t should be between the vector and its complex conjugate.)\n FUNCTION vabs_dp(v)\n\n REAL(dp), DIMENSION(:), INTENT(IN) :: v\n REAL(dp) :: vabs_dp\n\n vabs_dp = sqrt(dot_product(v,v))\n\n END FUNCTION vabs_dp\n\n\n FUNCTION vabs_sp(v)\n\n REAL(sp), DIMENSION(:), INTENT(IN) :: v\n REAL(sp) :: vabs_sp\n\n vabs_sp = sqrt(dot_product(v,v))\n\n END FUNCTION vabs_sp\n\n ! ------------------------------------------------------------------\n\nEND MODULE mo_fit\n", "meta": {"hexsha": "6bb83ad87bb262e2215eacda717c0a334c3e32e5", "size": 56661, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/test_mo_fit/mo_fit.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_fit/mo_fit.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_fit/mo_fit.f90", "max_forks_repo_name": "mcuntz/jams_fortran", "max_forks_repo_head_hexsha": "a1dcab78eda21f930aa6c8c3633598a522f01659", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-08-09T08:08:56.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-09T08:08:56.000Z", "avg_line_length": 31.9576988156, "max_line_length": 128, "alphanum_fraction": 0.5120982687, "num_tokens": 17846, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513620489618, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6990696992412633}} {"text": " SUBROUTINE chebpc(c,d,n)\r\n INTEGER n,NMAX\r\n REAL c(n),d(n)\r\n PARAMETER (NMAX=50)\r\n INTEGER j,k\r\n REAL sv,dd(NMAX)\r\n do 11 j=1,n\r\n d(j)=0.\r\n dd(j)=0.\r\n11 continue\r\n d(1)=c(n)\r\n do 13 j=n-1,2,-1\r\n do 12 k=n-j+1,2,-1\r\n sv=d(k)\r\n d(k)=2.*d(k-1)-dd(k)\r\n dd(k)=sv\r\n12 continue\r\n sv=d(1)\r\n d(1)=-dd(1)+c(j)\r\n dd(1)=sv\r\n13 continue\r\n do 14 j=n,2,-1\r\n d(j)=d(j-1)-dd(j)\r\n14 continue\r\n d(1)=-dd(1)+0.5*c(1)\r\n return\r\n END\r\n", "meta": {"hexsha": "46cc23182e1bb154817a87c615bd1330c7f006a1", "size": 569, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/chebpc.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/chebpc.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/chebpc.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.3214285714, "max_line_length": 31, "alphanum_fraction": 0.3866432337, "num_tokens": 216, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513675912912, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6990696989806348}} {"text": "!edm\n subroutine euclidean_distance_matrix(x, y, nsamples, nfeat, r)\n\n implicit none\n \n double precision, intent(in) :: x(nfeat, nsamples)\n double precision, intent(in) :: y(nfeat, nsamples)\n integer, intent(in) :: nsamples\n integer, intent(in) :: nfeat\n double precision, intent(out) :: r(nsamples, nsamples)\n\n integer :: i, j, k\n double precision :: tmp\n \n!$OMP PARALLEL DO PRIVATE (tmp)\n do i = 1, nsamples\n do j = 1, nsamples\n tmp = 0.0\n do k = 1, nfeat\n tmp = (x(k,i) - y(k,j))**2 + tmp\n enddo\n r(i,j) = tmp\n enddo\n enddo\n!$OMP END PARALLEL DO\n \n end subroutine euclidean_distance_matrix\n", "meta": {"hexsha": "50d620b9450c42c2e5cee6d458c4b00e2f3bfa8f", "size": 743, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "f2py/distance-f90-pythonized/euclidean.f90", "max_stars_repo_name": "lento234/PythonHPC", "max_stars_repo_head_hexsha": "dcb3db3e46d86bccea64fb6222dd80add5fa2546", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 65, "max_stars_repo_stars_event_min_datetime": "2019-11-15T18:13:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-14T17:59:53.000Z", "max_issues_repo_path": "f2py/distance-f90-pythonized/euclidean.f90", "max_issues_repo_name": "lento234/PythonHPC", "max_issues_repo_head_hexsha": "dcb3db3e46d86bccea64fb6222dd80add5fa2546", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-01-07T14:23:05.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-07T10:59:11.000Z", "max_forks_repo_path": "f2py/distance-f90-pythonized/euclidean.f90", "max_forks_repo_name": "lento234/PythonHPC", "max_forks_repo_head_hexsha": "dcb3db3e46d86bccea64fb6222dd80add5fa2546", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 37, "max_forks_repo_forks_event_min_datetime": "2019-11-11T15:29:00.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-27T05:08:57.000Z", "avg_line_length": 26.5357142857, "max_line_length": 68, "alphanum_fraction": 0.5397039031, "num_tokens": 207, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872046056466901, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.6990561901252144}} {"text": "PROGRAM rel_max\nIMPLICIT NONE\nREAL, DIMENSION(:,:), ALLOCATABLE :: matrix\nINTEGER, DIMENSION(1:2) :: loc\nCHARACTER, DIMENSION(:,:), ALLOCATABLE :: max_map\nINTEGER :: rows, cols, i, j\n\nOPEN (1, FILE=\"matrix.dat\", STATUS='OLD', ACTION='READ')\nREAD(1, *) rows, cols\nALLOCATE(matrix(1:rows, 1:cols), max_map(1:rows, 1:cols))\nREAD(1, *) matrix\nWRITE(*, *) \"DATA:\"\nWRITE(*, '(10F12.1)') ((matrix(i, j), j = 1, cols), i = 1, rows)\n\nmax_map = '_'\nDO i = 2, rows - 1\n DO j = 2, cols - 1\n loc = MAXLOC(matrix(i-1:i+1,j-1:j+1))\n !WRITE(*, *) loc\n !WRITE(*, '(8F12.1)') MAXVAL(matrix(i-1:i+1,j-1:j+1))\n !WRITE(*, *) i, loc(1), j .eq. loc(2)\n IF ((loc(1) .eq. 2) .and. (loc(2)) .eq. 2) THEN\n max_map(i, j) = 'X'\n END IF\n END DO\nEND DO\n\nWRITE(*, *) \"MAXIMA LOCATIONS:\"\nWRITE(*, '(10A12)') ((max_map(i, j), j = 1, cols), i = 1, rows)\nEND PROGRAM rel_max\n", "meta": {"hexsha": "e3d89c12b3d8b1a444a1f706ec2e21a6800973c1", "size": 865, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap8/rel_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/chap8/rel_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/chap8/rel_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": 27.9032258065, "max_line_length": 64, "alphanum_fraction": 0.5687861272, "num_tokens": 355, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.7879312031126511, "lm_q1q2_score": 0.6990561829345907}} {"text": " \tProgram oscillator\r\n \tImplicit none\r\nc declarations\r\n\tReal*8 dt, min, max, t, y(5)\r\nc n: number of equations (the 'dimension' of the standard form)\r\n\tInteger\tn\r\nC number of component\r\n parameter (n=2)\r\nC starting and end points\r\n min=0.0D0\t\r\n max=10.0D0\r\nC time step\r\n dt=0.1D0\r\nC initial position\r\n y(1)=0.2D0\r\nC initial velocity\r\n y(2)=0.0D0\r\n\r\nc open file to output\r\n Open(6, File='rk2.dat')\r\nc do n steps of Runga-Kutta algorithm\r\n\tDo t=min, max, dt\r\n\t Call rk2(t, dt, y, n)\r\n Write (6,*) t, y(1)\r\n \tenddo\r\nc\r\n\tClose(6)\r\n\tStop 'data saved in rk2.dat'\r\n End\r\nc------------------------end of main program------------------------\r\nc\r\nc second-order Runge-Kutta subroutine \r\n\tSubroutine rk2(t, dt, y, n)\r\n\tImplicit none\r\nc declarations\r\n\tReal*8 deriv, h, t, dt, y(1) \r\n Real*8 k1(5), k2(5), t1(5)\r\n \tInteger i, n\r\n \th=dt/2.0D0\r\n\tDo i = 1,n\r\n\t k1(i) = dt * deriv(t, y, i)\r\n\t t1(i) = y(i) + 0.5D0*k1(i)\r\n \tenddo\r\n\tDo i = 1,n\r\n\t k2(i) = dt * deriv(t+h, t1, i)\r\n\t y(i) = y(i) + k2(i)\r\n \tenddo\r\nc \r\n\tReturn\r\n\tEnd\r\n\r\nc function which returns the derivatives\r\n\tFunction deriv(x, temp, i)\r\nC 2 function components: dx/dt = v(t), dv/dt = -w**2*x(t) -a*v\r\nC the second term is damping term\r\n\tImplicit none\r\nc declarations\r\n\tReal*8 deriv, x, temp(2), omega, alpha\r\n\tInteger i\r\n\tdata omega /3.13d0/\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\r\n\tReturn\r\n\tEnd\r\n", "meta": {"hexsha": "35f7b5e285280846f2805f324f1dd031954dc52a", "size": 1498, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Math3/Oscillate_rk2.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/Oscillate_rk2.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/Oscillate_rk2.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": 22.3582089552, "max_line_length": 69, "alphanum_fraction": 0.5574098798, "num_tokens": 539, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872046026642944, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.6990561789390217}} {"text": "module gauss\n implicit none\n\n private\n public echelon, reduce\n\n interface echelon\n module procedure echelon_dummy\n module procedure echelon_det_sign\n end interface echelon\n\n contains\n\n subroutine reduce(M)\n real, intent(inout) :: M(:, :)\n\n integer :: i\n real :: mii\n\n call echelon_dummy(M)\n do i = 1, max(size(M, 1), size(M, 2))\n mii = M(i, i)\n if (mii /= 1 .and. mii /= 0) then\n call mul_row(M, i, 1 / mii)\n end if\n end do\n end subroutine reduce\n\n subroutine echelon_dummy(M)\n real, intent(inout) :: M(:, :)\n integer :: dummy\n call echelon_sub(M, 1, 1, dummy)\n end subroutine echelon_dummy\n\n subroutine echelon_det_sign(M, det_sign)\n real, intent(inout) :: M(:, :)\n integer, intent(inout) :: det_sign\n det_sign = 1\n call echelon_sub(M, 1, 1, det_sign)\n end subroutine\n\n recursive subroutine echelon_sub(A, n, m, det_sign)\n real, intent(inout) :: A(:, :)\n integer, intent(in) :: n, m\n integer, intent(inout) :: det_sign\n\n integer :: i\n integer :: non_zero_row\n\n if (n <= size(A, 1) .and. m <= size(A, 2)) then\n non_zero_row = 0\n do i = size(A, 2), m, -1\n if (A(n, i) /= 0) then\n non_zero_row = i\n end if\n end do\n if (non_zero_row /= 0) then\n if (non_zero_row /= m) then\n call swap_rows(A, non_zero_row, m)\n det_sign = det_sign * (-1)\n end if\n do i = 1, size(A, 2)\n if (i /= m .and. A(n, i) /= 0) then\n call add_row(A, i, m, -A(n, i) / A(n, m))\n end if\n end do\n end if\n call echelon_sub(A, n + 1, m + 1, det_sign)\n end if\n end subroutine echelon_sub\n\n subroutine swap_rows(M, row1, row2)\n real, intent(inout) :: M(:, :)\n integer, intent(in) :: row1, row2\n\n real, dimension(size(M, 1)) :: tmp\n call copy_vec(tmp, M(:, row1))\n call copy_vec(M(:, row1), M(:, row2))\n call copy_vec(M(:, row2), tmp)\n end subroutine swap_rows\n\n subroutine mul_row(M, rowi, n)\n real, intent(inout) :: M(:, :)\n integer, intent(in) :: rowi\n real, intent(in) :: n\n\n integer :: i\n do i = 1, size(M, 1)\n M(i, rowi) = M(i, rowi) * n\n end do\n end subroutine mul_row\n\n subroutine add_row(M, row1, row2, n)\n real, intent(inout) :: M(:, :)\n integer, intent(in) :: row1, row2\n real, intent(in) :: n\n\n integer :: i\n do i = 1, size(M, 1)\n M(i, row1) = M(i, row1) + M(i, row2) * n\n end do\n end subroutine add_row\n\n subroutine copy_vec(to, from)\n real, intent(out) :: to(:)\n real, intent(in) :: from(size(to))\n\n integer :: i\n do i = 1, size(to)\n to(i) = from(i)\n end do\n end subroutine copy_vec\nend module gauss\n", "meta": {"hexsha": "4f5ec399a2b40e0fc44917ae1f0075642fae3578", "size": 2695, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gauss.f90", "max_stars_repo_name": "Ergoold/matrix-maths", "max_stars_repo_head_hexsha": "4011f36ff1903d7b77b9a7eb8c3980f2d7a62775", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "gauss.f90", "max_issues_repo_name": "Ergoold/matrix-maths", "max_issues_repo_head_hexsha": "4011f36ff1903d7b77b9a7eb8c3980f2d7a62775", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gauss.f90", "max_forks_repo_name": "Ergoold/matrix-maths", "max_forks_repo_head_hexsha": "4011f36ff1903d7b77b9a7eb8c3980f2d7a62775", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.6403508772, "max_line_length": 53, "alphanum_fraction": 0.560296846, "num_tokens": 885, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.6990561716075429}} {"text": "program test_CIJ_tandon_and_weng\n\nuse anisotropy_ajn\n\nimplicit none\n\n integer, parameter :: i4 = selected_int_kind(9) ; ! long int\n integer, parameter :: r4 = selected_real_kind(6,37) ; ! SP\n integer, parameter :: r8 = selected_real_kind(15,307) ; ! DP\n \n! ** precision selector\n integer, parameter :: rs = r8\n \n! ** maths constants and other useful things\n real(rs), parameter :: pi = 3.141592653589793238462643 ;\n real(rs), parameter :: to_rad = 1.74532925199433e-002 ; \n real(rs), parameter :: to_deg = 57.2957795130823e0 ; \n real(rs), parameter :: to_km = 111.194926644559 ; \n\n real(rs), parameter :: big_number = 10.e36 ; \n\n real(rs) :: CC(6,6),CCexp(6,6),vp,vs,rho,vpi,vsi,rhoi,c,del,rhoout\n \n vp = 5.8d3\n vs = 3.46d3\n rho = 2.92d3\n \n del = 0.01\n c = 0.02\n \n vpi = 4.d3\n vsi = 0.d0\n rhoi = 2.2d3\n\n call CIJ_tandon_and_weng(vp,vs,rho,del,c,vpi,vsi,rhoi,CC,rhoout)\n \n write(*,'(a)') 'Output should look like: (x10^7)'\n write(*,'(a)') &\n' 3.2634 0.9878 0.9878 0.0000 0.0000 0.0000',&\n' 0.9878 3.3358 0.9784 0.0000 0.0000 0.0000',&\n' 0.9878 0.9784 3.3358 0.0000 0.0000 0.0000',&\n' 0.0000 0.0000 0.0000 1.1787 0.0000 0.0000',&\n' 0.0000 0.0000 0.0000 0.0000 0.5574 0.0000',&\n' 0.0000 0.0000 0.0000 0.0000 0.0000 0.5574'\n\n CCexp = 1.d7 * reshape( &\n (/ 3.2634, 0.9878, 0.9878, 0.0000, 0.0000, 0.0000, &\n 0.9878, 3.3358, 0.9784, 0.0000, 0.0000, 0.0000, &\n 0.9878, 0.9784, 3.3358, 0.0000, 0.0000, 0.0000, &\n 0.0000, 0.0000, 0.0000, 1.1787, 0.0000, 0.0000, &\n 0.0000, 0.0000, 0.0000, 0.0000, 0.5574, 0.0000, &\n 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.5574 /), (/6,6/))\n\n write(*,'(/a)') 'Output: (x10^7)'\n write(*,'(6f10.4)') CC/1.d7\n \n ! Different if any value differs by more than 0.1 %\n if (any(abs(CC - CCexp) > abs(CCexp/1.d4))) then\n write(*,'(/a,e10.4)') 'TEST FAILED: total difference between sum of matrices = ',sum(abs(CC-CCexp))\n else\n write(*,'(/a)') 'Test passed'\n endif\n\nend program test_CIJ_tandon_and_weng", "meta": {"hexsha": "6411237467589e498c18a62ccd910a178e4232fa", "size": 2221, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "anisotropy_ajn/test_CIJ_tandon_and_weng.f90", "max_stars_repo_name": "JackWalpole/seismo-fortran-fork", "max_stars_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2015-06-23T05:28:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T03:46:07.000Z", "max_issues_repo_path": "anisotropy_ajn/test_CIJ_tandon_and_weng.f90", "max_issues_repo_name": "JackWalpole/seismo-fortran-fork", "max_issues_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2017-05-17T11:02:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-28T09:36:24.000Z", "max_forks_repo_path": "anisotropy_ajn/test_CIJ_tandon_and_weng.f90", "max_forks_repo_name": "JackWalpole/seismo-fortran-fork", "max_forks_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-04-15T02:55:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-20T12:20:51.000Z", "avg_line_length": 34.703125, "max_line_length": 105, "alphanum_fraction": 0.5533543449, "num_tokens": 1019, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.6990561716075429}} {"text": "! cfd_lax.f90 \r\n!\r\n! FUNCTIONS:\r\n! cfd_lax - Entry point of console application.\r\n!\r\n\r\n!****************************************************************************\r\n!\r\n! PROGRAM: cfd_lax\r\n! by mehrdad baba hosein pour\r\n! PURPOSE: Entry point for the console application.\r\n! beyond sky!\r\n!****************************************************************************\r\n\r\n program wave_lax\r\nimplicit none\r\ninteger::i,n\r\ninteger,parameter:: ix=201,nt=400\r\nreal*8::u(nt,ix),a,dt,dx,l,pi,u1(nt,ix)\r\npi=2*asin(1.d0)\r\na=0.01\r\ndt=0.04\r\nl=1\r\ndx=l/(ix-1)\r\nprint*,'qourant number is = ',a*dt/dx\r\n\r\n!exact_solution\r\ndo n=1,nt\r\n do i=1,ix\r\n u1(n,i)=sin(2*pi*(i-1)*(dx-a*dt)*5) \r\n end do\r\nend do\r\n\r\n!initial condition\r\ndo i=1,ix\r\n u(1,i)=sin(2.d0*pi*(i-1)*dx*5)\r\nend do\r\n\r\n!solve_wave_equation\r\ndo n=1,nt-1\r\n do i=2,ix-1\r\n u(n+1,i)=(u(n,i+1)+u(n,i-1))/2.d0-a*dt/dx*((u(n,i+1)-u(n,i-1))/2.d0)\r\n end do\r\nend do\r\nopen (1,file='analysis_result_lax.plt') !analysis_result\r\ndo n=1,nt\r\n write(1,*)'variables=\"x\",\"u1\"'\r\n write(1,*)'zone'\r\n do i=1,ix\r\n write(1,*) dx*(i-1),u1(n,i)\r\n end do\r\nend do\r\nopen (2,file='computational_result_lax.plt') ! computational_result\r\ndo n=1,nt\r\n write(2,*)'variables=\"x\",\"u\"'\r\n write(2,*)'zone'\r\n do i=1,ix\r\n write(2,*) dx*(i-1),u(n,i)\r\n end do\r\nend do\r\nprint*,'>>> please inter <<<'\r\n\r\npause \r\n end program wave_lax\r\n\r\n\r\n\r\n", "meta": {"hexsha": "4e4de19c15975e96f33c87f44f79607f0573cd92", "size": 1410, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "cfd_lax.f90", "max_stars_repo_name": "mehrdadBHP1997/1D-conduction-lax", "max_stars_repo_head_hexsha": "11094d06159e1da4c1572c61b5432436cf3d1ce0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cfd_lax.f90", "max_issues_repo_name": "mehrdadBHP1997/1D-conduction-lax", "max_issues_repo_head_hexsha": "11094d06159e1da4c1572c61b5432436cf3d1ce0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cfd_lax.f90", "max_forks_repo_name": "mehrdadBHP1997/1D-conduction-lax", "max_forks_repo_head_hexsha": "11094d06159e1da4c1572c61b5432436cf3d1ce0", "max_forks_repo_licenses": ["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.7352941176, "max_line_length": 78, "alphanum_fraction": 0.509929078, "num_tokens": 501, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.7879311956428946, "lm_q1q2_score": 0.6990561716075427}} {"text": "!*********************\nsubroutine bc(psi,i1,i2,j1,j2)\n! sets the boundary conditions\n! input is the grid and the indices for the interior cells\n use numz\n implicit none\n integer,intent(in):: i1,i2,j1,j2\n real(b8),dimension(i1-1:i2+1,j1-1:j2+1):: psi\n psi(i1-1,:)=0.0_b8\n psi(i2+1,:)=0.0_b8\n psi(:,j1-1)=0.0_b8\n psi(:,j2+1)=0.0_b8\nend subroutine bc\n!*********************\nsubroutine do_jacobi(psi,new_psi,diff,i1,i2,j1,j2)\n! does a single Jacobi iteration step\n! input is the grid and the indices for the interior cells\n! new_psi is temp storage for the the updated grid\n! output is the updated grid in psi and diff which is\n! the sum of the differences between the old and new grids\n use numz\n use constants\n implicit none\n integer,intent(in) :: i1,i2,j1,j2\n real(b8),dimension(i1-1:i2+1,j1-1:j2+1):: psi\n real(b8),dimension(i1-1:i2+1,j1-1:j2+1):: new_psi\n real(b8) diff\n integer i,j\n real(b8) y\n diff=0.0_b8\n do j=j1,j2\n do i=i1,i2\n! y=j*dy\n new_psi(i,j)=a1*psi(i+1,j) + a2*psi(i-1,j) + &\n a3*psi(i,j+1) + a4*psi(i,j-1) - &\n a5*for(i,j)\n! a5*force(y)\n diff=diff+abs(new_psi(i,j)-psi(i,j))\n enddo\n enddo\n psi(i1:i2,j1:j2)=new_psi(i1:i2,j1:j2)\nend subroutine do_jacobi\n!*********************\nfunction force(y)\n use numz\n use input\n use constants\n implicit none\n real(b8) force,y\n force=-alpha*sin(y*a6)\nend function force\n!*********************\nsubroutine do_force (i1,i2,j1,j2)\n! sets the force conditions\n! input is the grid and the indices for the interior cells\n use numz\n use constants, only:for,dy\n use face, only : force\n implicit none\n integer,intent(in):: i1,i2,j1,j2\n real(b8) y\n integer i,j\n do i=i1,i2\n do j=j1,j2\n y=j*dy\n for(i,j)=force(y)\n enddo\n enddo\nend subroutine", "meta": {"hexsha": "94fb2a7c75b755c6014348af60d37061efd9648f", "size": 1945, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "make/simple/calculatef.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": "make/simple/calculatef.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": "make/simple/calculatef.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.1884057971, "max_line_length": 58, "alphanum_fraction": 0.5742930591, "num_tokens": 658, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045847699186, "lm_q2_score": 0.7879311856832191, "lm_q1q2_score": 0.69905616042135}} {"text": " SUBROUTINE MB01WD( DICO, UPLO, TRANS, HESS, N, ALPHA, BETA, R,\n $ LDR, A, LDA, T, LDT, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute the matrix formula\nC _\nC R = alpha*( op( A )'*op( T )'*op( T ) + op( T )'*op( T )*op( A ) )\nC + beta*R, (1)\nC\nC if DICO = 'C', or\nC _\nC R = alpha*( op( A )'*op( T )'*op( T )*op( A ) - op( T )'*op( T ))\nC + beta*R, (2)\nC _\nC if DICO = 'D', where alpha and beta are scalars, R, and R are\nC symmetric matrices, T is a triangular matrix, A is a general or\nC Hessenberg matrix, and op( M ) is one of\nC\nC op( M ) = M or op( M ) = M'.\nC\nC The result is overwritten on R.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC DICO CHARACTER*1\nC Specifies the formula to be evaluated, as follows:\nC = 'C': formula (1), \"continuous-time\" case;\nC = 'D': formula (2), \"discrete-time\" case.\nC\nC UPLO CHARACTER*1\nC Specifies which triangles of the symmetric matrix R and\nC triangular matrix T are given, as follows:\nC = 'U': the upper triangular parts of R and T are given;\nC = 'L': the lower triangular parts of R and T are given;\nC\nC TRANS CHARACTER*1\nC Specifies the form of op( M ) to be used, as follows:\nC = 'N': op( M ) = M;\nC = 'T': op( M ) = M';\nC = 'C': op( M ) = M'.\nC\nC HESS CHARACTER*1\nC Specifies the form of the matrix A, as follows:\nC = 'F': matrix A is full;\nC = 'H': matrix A is Hessenberg (or Schur), either upper\nC (if UPLO = 'U'), or lower (if UPLO = 'L').\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The order of the matrices R, A, and T. N >= 0.\nC\nC ALPHA (input) DOUBLE PRECISION\nC The scalar alpha. When alpha is zero then the arrays A\nC and T are not referenced.\nC\nC BETA (input) DOUBLE PRECISION\nC The scalar beta. When beta is zero then the array R need\nC not be set before entry.\nC\nC R (input/output) DOUBLE PRECISION array, dimension (LDR,N)\nC On entry with UPLO = 'U', the leading N-by-N upper\nC triangular part of this array must contain the upper\nC triangular part of the symmetric matrix R.\nC On entry with UPLO = 'L', the leading N-by-N lower\nC triangular part of this array must contain the lower\nC triangular part of the symmetric matrix R.\nC On exit, the leading N-by-N upper triangular part (if\nC UPLO = 'U'), or lower triangular part (if UPLO = 'L'), of\nC this array contains the corresponding triangular part of\nC _\nC the computed matrix R.\nC\nC LDR INTEGER\nC The leading dimension of array R. LDR >= MAX(1,N).\nC\nC A (input/output) DOUBLE PRECISION array, dimension (LDA,N)\nC On entry, the leading N-by-N part of this array must\nC contain the matrix A. If HESS = 'H' the elements below the\nC first subdiagonal, if UPLO = 'U', or above the first\nC superdiagonal, if UPLO = 'L', need not be set to zero,\nC and are not referenced if DICO = 'D'.\nC On exit, the leading N-by-N part of this array contains\nC the following matrix product\nC alpha*T'*T*A, if TRANS = 'N', or\nC alpha*A*T*T', otherwise,\nC if DICO = 'C', or\nC T*A, if TRANS = 'N', or\nC A*T, otherwise,\nC if DICO = 'D' (and in this case, these products have a\nC Hessenberg form, if HESS = 'H').\nC\nC LDA INTEGER\nC The leading dimension of array A. LDA >= MAX(1,N).\nC\nC T (input) DOUBLE PRECISION array, dimension (LDT,N)\nC If UPLO = 'U', the leading N-by-N upper triangular part of\nC this array must contain the upper triangular matrix T and\nC the strictly lower triangular part need not be set to zero\nC (and it is not referenced).\nC If UPLO = 'L', the leading N-by-N lower triangular part of\nC this array must contain the lower triangular matrix T and\nC the strictly upper triangular part need not be set to zero\nC (and it is not referenced).\nC\nC LDT INTEGER\nC The leading dimension of array T. LDT >= MAX(1,N).\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -k, the k-th argument had an illegal\nC value.\nC\nC METHOD\nC\nC The matrix expression (1) or (2) is efficiently evaluated taking\nC the structure into account. BLAS 3 operations (DTRMM, DSYRK and\nC their specializations) are used throughout.\nC\nC NUMERICAL ASPECTS\nC\nC If A is a full matrix, the algorithm requires approximately\nC 3\nC N operations, if DICO = 'C';\nC 3\nC 7/6 x N operations, if DICO = 'D'.\nC\nC CONTRIBUTORS\nC\nC V. Sima, Research Institute for Informatics, Bucharest, Nov. 2000.\nC\nC REVISIONS\nC\nC -\nC\nC KEYWORDS\nC\nC Elementary matrix operations, matrix algebra, matrix operations.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, ONE\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )\nC .. Scalar Arguments ..\n CHARACTER DICO, HESS, TRANS, UPLO\n INTEGER INFO, LDA, LDR, LDT, N\n DOUBLE PRECISION ALPHA, BETA\nC .. Array Arguments ..\n DOUBLE PRECISION A(LDA,*), R(LDR,*), T(LDT,*)\nC .. Local Scalars ..\n LOGICAL DISCR, REDUC, TRANSP, UPPER\n CHARACTER NEGTRA, SIDE\n INTEGER I, INFO2, J\nC .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\nC .. External Subroutines ..\n EXTERNAL DLASCL, DLASET, DSYRK, DTRMM, MB01YD, MB01ZD,\n $ XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC MAX\nC .. Executable Statements ..\nC\nC Test the input scalar arguments.\nC\n INFO = 0\n DISCR = LSAME( DICO, 'D' )\n UPPER = LSAME( UPLO, 'U' )\n TRANSP = LSAME( TRANS, 'T' ) .OR. LSAME( TRANS, 'C' )\n REDUC = LSAME( HESS, 'H' )\nC\n IF( .NOT.( DISCR .OR. LSAME( DICO, 'C' ) ) )THEN\n INFO = -1\n ELSE IF( .NOT.( UPPER .OR. LSAME( UPLO, 'L' ) ) )THEN\n INFO = -2\n ELSE IF( .NOT.( TRANSP .OR. LSAME( TRANS, 'N' ) ) )THEN\n INFO = -3\n ELSE IF( .NOT.( REDUC .OR. LSAME( HESS, 'F' ) ) )THEN\n INFO = -4\n ELSE IF( N.LT.0 ) THEN\n INFO = -5\n ELSE IF( LDR.LT.MAX( 1, N ) ) THEN\n INFO = -9\n ELSE IF( LDA.LT.MAX( 1, N ) ) THEN\n INFO = -11\n ELSE IF( LDT.LT.MAX( 1, N ) ) THEN\n INFO = -13\n END IF\nC\n IF ( INFO.NE.0 ) THEN\nC\nC Error return.\nC\n CALL XERBLA( 'MB01WD', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF ( N.EQ.0 )\n $ RETURN\nC\n IF ( ALPHA.EQ.ZERO ) THEN\n IF ( BETA.EQ.ZERO ) THEN\nC\nC Special case when both alpha = 0 and beta = 0.\nC\n CALL DLASET( UPLO, N, N, ZERO, ZERO, R, LDR )\n ELSE\nC\nC Special case alpha = 0.\nC\n IF ( BETA.NE.ONE )\n $ CALL DLASCL( UPLO, 0, 0, ONE, BETA, N, N, R, LDR, INFO2 )\n END IF\n RETURN\n END IF\nC\nC General case: alpha <> 0.\nC\nC Compute (in A) T*A, if TRANS = 'N', or\nC A*T, otherwise.\nC\n IF ( TRANSP ) THEN\n SIDE = 'R'\n NEGTRA = 'N'\n ELSE\n SIDE = 'L'\n NEGTRA = 'T'\n END IF\nC\n IF ( REDUC .AND. N.GT.2 ) THEN\n CALL MB01ZD( SIDE, UPLO, 'NoTranspose', 'Non-unit', N, N, 1,\n $ ONE, T, LDT, A, LDA, INFO2 )\n ELSE\n CALL DTRMM( SIDE, UPLO, 'NoTranspose', 'Non-unit', N, N, ONE,\n $ T, LDT, A, LDA )\n END IF\nC\n IF( .NOT.DISCR ) THEN\nC\nC Compute (in A) alpha*T'*T*A, if TRANS = 'N', or\nC alpha*A*T*T', otherwise.\nC\n IF ( REDUC .AND. N.GT.2 ) THEN\n CALL MB01ZD( SIDE, UPLO, 'Transpose', 'Non-unit', N, N, 1,\n $ ALPHA, T, LDT, A, LDA, INFO2 )\n ELSE\n CALL DTRMM( SIDE, UPLO, 'Transpose', 'Non-unit', N, N,\n $ ALPHA, T, LDT, A, LDA )\n END IF\nC\nC Compute the required triangle of the result, using symmetry.\nC\n IF ( UPPER ) THEN\n IF ( BETA.EQ.ZERO ) THEN\nC\n DO 20 J = 1, N\n DO 10 I = 1, J\n R( I, J ) = A( I, J ) + A( J, I )\n 10 CONTINUE\n 20 CONTINUE\nC\n ELSE\nC\n DO 40 J = 1, N\n DO 30 I = 1, J\n R( I, J ) = A( I, J ) + A( J, I ) + BETA*R( I, J )\n 30 CONTINUE\n 40 CONTINUE\nC\n END IF\nC\n ELSE\nC\n IF ( BETA.EQ.ZERO ) THEN\nC\n DO 60 J = 1, N\n DO 50 I = J, N\n R( I, J ) = A( I, J ) + A( J, I )\n 50 CONTINUE\n 60 CONTINUE\nC\n ELSE\nC\n DO 80 J = 1, N\n DO 70 I = J, N\n R( I, J ) = A( I, J ) + A( J, I ) + BETA*R( I, J )\n 70 CONTINUE\n 80 CONTINUE\nC\n END IF\nC\n END IF\nC\n ELSE\nC\nC Compute (in R) alpha*A'*T'*T*A + beta*R, if TRANS = 'N', or\nC alpha*A*T*T'*A' + beta*R, otherwise.\nC\n IF ( REDUC .AND. N.GT.2 ) THEN\n CALL MB01YD( UPLO, NEGTRA, N, N, 1, ALPHA, BETA, A, LDA, R,\n $ LDR, INFO2 )\n ELSE\n CALL DSYRK( UPLO, NEGTRA, N, N, ALPHA, A, LDA, BETA, R,\n $ LDR )\n END IF\nC\nC Compute (in R) -alpha*T'*T + R, if TRANS = 'N', or\nC -alpha*T*T' + R, otherwise.\nC\n CALL MB01YD( UPLO, NEGTRA, N, N, 0, -ALPHA, ONE, T, LDT, R,\n $ LDR, INFO2 )\nC\n END IF\nC\n RETURN\nC *** Last line of MB01WD ***\n END\n", "meta": {"hexsha": "cd214dc0d8bfd87bb2ebe81c37ec36d2e903c666", "size": 10582, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB01WD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB01WD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB01WD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 32.0666666667, "max_line_length": 72, "alphanum_fraction": 0.4855414855, "num_tokens": 3219, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9294404057671714, "lm_q2_score": 0.7520125848754471, "lm_q1q2_score": 0.698950882028655}} {"text": "\n* \n* --------------------------------------------------------------------------\n* >>>\n* NAME : EXPINTEGRAL\n* FILENAME : EXPINTEGRAL.FOR\n* DIRECTORY : [REETZ.PROGLIB]\n* \n* PURPOSE : Exponential-Integralfunction\n* MODUL : FORTRAN - Subroutine\n* CALLING SEQ.: EXPINTEGRAL(x,n)\n* INPUTS : x Argument\n* n order (1,2)\n* OUTPUTS : Return-Value: \n* AUTHOR : Johannes Reetz\n* DATE : 9-OCT-1992 12:23:37.56\n* <<<\n* --------------------------------------------------------------------------\n* \n\n REAL*4 FUNCTION expintegral(x,n)\n REAL*4 x\n REAL*8 y\n INTEGER*4 n\n REAL*8 A1,A2,A3,A4,B1,B2,B3,B4,C0,C1,C2,C3,C4,C5\n\nC --- Coefficients for rational approx. 5.1.56\n PARAMETER (A1 = 8.5733287401)\n PARAMETER (A2 = 18.0590169730)\n PARAMETER (A3 = 8.6347608925)\n PARAMETER (A4 = 0.2677737343)\n PARAMETER (B1 = 9.5733223454)\n PARAMETER (B2 = 25.6329561486)\n PARAMETER (B3 = 21.0996530827)\n PARAMETER (B4 = 3.9584969228)\n\nC --- Coefficients for rational approx. 5.1.53\n PARAMETER (C0 = -0.57721566)\n PARAMETER (C1 = 0.99999193)\n PARAMETER (C2 = -0.24991055)\n PARAMETER (C3 = 0.05519968)\n PARAMETER (C4 = -0.00976004)\n PARAMETER (C5 = 0.00107857)\n\nC --- Polynomial approximation 5.1.53 (eps < 2.e-7)\n\n GOTO (100,200), n\n WRITE(*,*) 'ERROR in EXPINTEGRAL: Ordernumber of E2-function > 2'\n expintegral = 0. \n RETURN\n\n100 CONTINUE\nC --- Rational approximation 5.1.56 (eps < 2.e-8)\n IF (x.LT.1.) THEN \n IF (x.GT.0.) expintegral=C0+x*(C1+x*(C2+x*(C3+x*\n * (C4+x*C5))))-log(x)\n ELSE\n expintegral = exp(-x)*(A4+x*(A3+x*(A2+x*(A1+x)))) / \n * (x*(B4+x*(B3+x*(B2+x*(B1+x)))))\n ENDIF\n RETURN\n\n200 CONTINUE\nC --- Recurrence relation 5.1.14\n IF (x.LT.1) THEN\n expintegral = 1.\n IF (x.GT.0.) THEN \n expintegral = exp(-x)-x*(C0+x*\n * (C1+x*(C2+x*(C3+x*(C4+x*C5))))-log(x))\n ENDIF\n ELSE \nC --- Rational approximation 5.1.56 (eps < 2.e-8)\n expintegral = exp(-x)*(1 - (A4+x*(A3+x*(A2+x*(A1+x)))) / \n * (B4+x*(B3+x*(B2+x*(B1+x)))) )\n ENDIF\n RETURN\n END \n", "meta": {"hexsha": "0b460fd9bc4f1d4d05cd4396c06cffe2c956cc2e", "size": 2370, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "oracle/si/code/expintegral.f", "max_stars_repo_name": "andycasey/original-oracle", "max_stars_repo_head_hexsha": "0f204a0ff952cc97904c1d1bb53e14b799bb877e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2015-10-26T12:01:23.000Z", "max_stars_repo_stars_event_max_datetime": "2018-05-26T16:36:36.000Z", "max_issues_repo_path": "oracle/si/code/expintegral.f", "max_issues_repo_name": "andycasey/original-oracle", "max_issues_repo_head_hexsha": "0f204a0ff952cc97904c1d1bb53e14b799bb877e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "oracle/si/code/expintegral.f", "max_forks_repo_name": "andycasey/original-oracle", "max_forks_repo_head_hexsha": "0f204a0ff952cc97904c1d1bb53e14b799bb877e", "max_forks_repo_licenses": ["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.3846153846, "max_line_length": 76, "alphanum_fraction": 0.4717299578, "num_tokens": 820, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404057671714, "lm_q2_score": 0.7520125793176223, "lm_q1q2_score": 0.6989508768629881}} {"text": " subroutine ire_dgx(ctfmp,n_A,n_Axx,n_alpha,n_beta,n_divbeta,nm1_A,\n &np1_A,Nx,ht,hx,vee,res)\n implicit none\n integer i\n integer Nx\n real*8 ht\n real*8 hx\n real*8 vee\n real*8 ctfmp(Nx)\n real*8 n_A(Nx)\n real*8 n_Axx(Nx)\n real*8 n_alpha(Nx)\n real*8 n_beta(Nx)\n real*8 n_divbeta(Nx)\n real*8 nm1_A(Nx)\n real*8 np1_A(Nx)\n real*8 res\n real*8 qb\n res = 0.0D0\n do i=2, Nx-1, 1\n qb = -0.5000000000000000D0 * (nm1_A(i) - 0.1D1 * np1_A(i)) / ht + \n #0.2D1 * n_Axx(i) * n_alpha(i) + 0.6666666666666667D0 * n_A(i) * ve\n #e * n_divbeta(i) - 0.1D1 * (-0.1D1 * (n_beta(i - 1) - 0.1D1 * n_be\n #ta(i + 1)) / hx * n_A(i) + 0.5000000000000000D0 * n_beta(i) * (-0.\n #1D1 * n_A(i - 1) + n_A(i + 1)) / hx) / ctfmp(i)\n res = res + qb**2\n end do\n res = sqrt(res/(1*Nx))\n END\n", "meta": {"hexsha": "c74738799f701bb593caa64292edaf85df0618d3", "size": 889, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/FD/ire_dgx.f", "max_stars_repo_name": "rmanak/bssn_spher", "max_stars_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/FD/ire_dgx.f", "max_issues_repo_name": "rmanak/bssn_spher", "max_issues_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/FD/ire_dgx.f", "max_forks_repo_name": "rmanak/bssn_spher", "max_forks_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.6333333333, "max_line_length": 72, "alphanum_fraction": 0.51856018, "num_tokens": 395, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404057671712, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6989508768629878}} {"text": "submodule(euler_interface_m) euler_prob_0026_m\n implicit none\n\ncontains\n\n module character(len=20) function euler0026()\n write (euler0026, \"(i20)\") answer(1000_int64)\n end function euler0026\n\n function answer(n) result(ret)\n use euler_primes_m, only: sieve_of_Eratosthenes\n implicit none\n\n integer(int64), intent(in) :: n\n integer(int64) :: ret, tmp, k, i\n logical, allocatable :: is_prime(:)\n\n call sieve_of_Eratosthenes(n, is_prime)\n tmp = 0_int64; k = 1_int64; ret = 0_int64\n do i = 7_int64, n\n if (is_prime(i)) then\n tmp = multiplicative_order(i, 10_int64)\n if (tmp > k) then\n k = tmp\n ret = i\n end if\n end if\n end do\n end function answer\n\n function multiplicative_order(n, m) result(ret)\n integer(int64), intent(in) :: n, m\n integer(int64) :: ret, res, k\n\n k = 1_int64; ret = 1_int64\n do\n res = mod(k*m, n)\n if (res /= 1_int64) then\n k = res\n ret = ret + 1_int64\n else\n exit\n end if\n end do\n end function multiplicative_order\n\nend submodule euler_prob_0026_m\n", "meta": {"hexsha": "c867d438eeb2bdbb31a43e45a3647c0875d0d0b9", "size": 1284, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/euler/prob_0026_m.f90", "max_stars_repo_name": "han190/PE-Fortran", "max_stars_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-02-09T07:07:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-31T07:45:48.000Z", "max_issues_repo_path": "docs/src/prob_0026_m.f90", "max_issues_repo_name": "han190/PE-Fortran", "max_issues_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-14T00:48:58.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-14T00:48:58.000Z", "max_forks_repo_path": "docs/src/prob_0026_m.f90", "max_forks_repo_name": "han190/PE-Fortran", "max_forks_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-04T21:29:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T21:29:45.000Z", "avg_line_length": 26.75, "max_line_length": 55, "alphanum_fraction": 0.5358255452, "num_tokens": 348, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699435, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.698886912454125}} {"text": "c *****************************************************\nc diskden.f\nc 15 Sep, 2012 written by D. Kawata\nc ***************************************************** \nc70*******************************************************************\n\n subroutine diskdeng(npg,mdisk,hd,zd0,flaggd\n & ,flagflzd,Rflzd)\n include './define.f'\n integer npg,flaggd,flagflzd\n double precision rp,zp\n double precision mdisk,hd,zd0,rhoc,Rflzd,zdr\n integer i\n\n if(flaggd.le.1) then\nc exp density profile\n do i=0,npg-1\n if(x_rzg(i).gt.0.0d0) then\n rp=x_rzg(i)\n else\n rp=10.0d0**lri_rzg\n endif\n if(z_rzg(i).gt.0.0d0) then\n zp=z_rzg(i)\n else\n zp=10.0d0**lzi_rzg\n endif\n if(flagflzd.eq.0) then\n rho_rzg(i)=(mdisk/(4.0d0*M_PI*zd0*(hd**2)))\n & *(1.0d0/(dcosh(z_rzg(i)/zd0)**2))\n & *dexp(-x_rzg(i)/hd)\n else\nc flaring\n zdr=zd0*dexp(x_rzg(i)/Rflzd)\n rho_rzg(i)=(mdisk/(4.0d0*M_PI*zdr*(hd**2)))\n & *(1.0d0/(dcosh(z_rzg(i)/zdr)**2))\n & *dexp(-x_rzg(i)/hd)\n endif\n if(rho_rzg(i).lt.0.0d0) then\n write(6,*) x_rzg(i),z_rzg(i),rho_rzg(i)\n endif\n enddo\n else if(flaggd.eq.2) then\nc constant density\n rhoc=mdisk/(M_PI*(hd**2)*(2.0d0*zd0))\n do i=0,npg-1\n if(x_rzg(i).gt.0.0d0) then\n rp=x_rzg(i)\n else\n rp=10.0d0**lri_rzg\n endif\n if(z_rzg(i).gt.0.0d0) then\n zp=z_rzg(i)\n else\n zp=10.0d0**lzi_rzg\n endif\n if(rp.lt.hd.and.zp.lt.zd0) then\n rho_rzg(i)=rhoc\n else\n rho_rzg(i)=0.0d0\n endif\n enddo\n else \nc exp(-x/h-h/x) profile\n do i=0,npg-1\n if(x_rzg(i).gt.0.0d0) then\n rp=x_rzg(i)\n else\n rp=10.0d0**lri_rzg\n endif\n if(z_rzg(i).gt.0.0d0) then\n zp=z_rzg(i)\n else\n zp=10.0d0**lzi_rzg\n endif\n rho_rzg(i)=(mdisk/(3.18884*2.0d0*zd0*(hd**2)))\n & *(1.0d0/(dcosh(z_rzg(i)/zd0)**2))\n & *dexp(-x_rzg(i)/hd-hd/x_rzg(i))\n if(rho_rzg(i).lt.0.0d0) then\n write(6,*) x_rzg(i),z_rzg(i),rho_rzg(i)\n endif\n enddo\n endif\n\n return\n end\n", "meta": {"hexsha": "681d1d57e94c0b63af96c697c39de64f970619c9", "size": 2414, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "dbulhalo/src/diskdeng.f", "max_stars_repo_name": "kawatadaisuke/diskm-buildini", "max_stars_repo_head_hexsha": "9b0bec72cc056a0a7958c9566722f0e2475cd17d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-04-01T14:57:28.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-01T14:57:28.000Z", "max_issues_repo_path": "dbulhalo/src/diskdeng.f", "max_issues_repo_name": "kawatadaisuke/diskm-buildini", "max_issues_repo_head_hexsha": "9b0bec72cc056a0a7958c9566722f0e2475cd17d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "dbulhalo/src/diskdeng.f", "max_forks_repo_name": "kawatadaisuke/diskm-buildini", "max_forks_repo_head_hexsha": "9b0bec72cc056a0a7958c9566722f0e2475cd17d", "max_forks_repo_licenses": ["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.7471264368, "max_line_length": 70, "alphanum_fraction": 0.4328914664, "num_tokens": 889, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813538993888, "lm_q2_score": 0.7310585903489891, "lm_q1q2_score": 0.6988783809816053}} {"text": " subroutine setprob()\n implicit none\n\n double precision pi, pi2\n common /compi/ pi, pi2\n\n double precision beta\n common /commannulus/ beta\n\n pi = 4.d0*atan(1.d0)\n pi2 = 2*pi\n\n open(10,file='setprob.data')\n read(10,*) beta\n close(10)\n\n end\n", "meta": {"hexsha": "df18eda309c32d957071452ad32a12898dd5e54e", "size": 299, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "applications/clawpack/advection/2d/annulus/setprob.f", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2017-09-26T13:39:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:56:23.000Z", "max_issues_repo_path": "applications/clawpack/advection/2d/annulus/setprob.f", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 75, "max_issues_repo_issues_event_min_datetime": "2017-08-02T19:56:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T12:36:32.000Z", "max_forks_repo_path": "applications/clawpack/advection/2d/annulus/setprob.f", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-02-21T00:10:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T19:08:36.000Z", "avg_line_length": 16.6111111111, "max_line_length": 34, "alphanum_fraction": 0.5484949833, "num_tokens": 90, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8840392695254319, "lm_q2_score": 0.7905303211371899, "lm_q1q2_score": 0.6988598476358264}} {"text": "program problem_3\n\n!! how many trees would you encounter?\n\nuse aoc_utilities\nuse iso_fortran_env\n\nimplicit none\n\ninteger:: iunit, istat, n_lines, i, j, n_cols, col\ncharacter(len=1000) :: line\nlogical,dimension(:,:),allocatable :: data\ninteger,dimension(5),parameter :: right = [1,3,5,7,1]\ninteger,dimension(5),parameter :: down = [1,1,1,1,2]\ninteger(int64) :: n_trees, product ! to avoid overflow\n\n! read into a logical array (true=true)\nopen(newunit=iunit, file='input.txt', iostat=istat)\nif (istat /= 0) error stop ' error reading file'\nn_lines = number_of_lines_in_file(iunit)\ndo i = 1, n_lines\n read(iunit, '(A1000)', iostat=istat) line\n if (is_iostat_end(istat)) exit\n if (i==1) then\n n_cols = len_trim(line)\n allocate(data(n_lines, n_cols))\n end if\n do j = 1, n_cols\n data(i,j) = line(j:j) == '#'\n end do\nend do\n\n!**********************\n\nwrite(*,*) ''\nwrite(*,*) 'part a:'\n\ncol = 0\nn_trees = 0\ndo i = 1, n_lines\n if (data(i,col+1)) n_trees = n_trees + 1\n col = mod(col + 3, n_cols)\nend do\n\nwrite(*,*) 'n_trees = ', n_trees\n\n!**********************\n\nwrite(*,*) ''\nwrite(*,*) 'part b:'\n\nproduct = 1\ndo j = 1, 5\n col = 0\n n_trees = 0\n do i = 1, n_lines, down(j)\n if (data(i,col+1)) n_trees = n_trees + 1\n col = mod(col + right(j), n_cols)\n end do\n product = product * n_trees\nend do\nwrite(*,*) 'product = ', product\n\nend program problem_3", "meta": {"hexsha": "ebc9fc604b12f37177e6b47e75356197483a0a81", "size": 1416, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/day3/problem_3.f90", "max_stars_repo_name": "jacobwilliams/AoC-2020", "max_stars_repo_head_hexsha": "2adf673a0ac62710fc5461576feb95bf5fae4cf2", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/day3/problem_3.f90", "max_issues_repo_name": "jacobwilliams/AoC-2020", "max_issues_repo_head_hexsha": "2adf673a0ac62710fc5461576feb95bf5fae4cf2", "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/day3/problem_3.f90", "max_forks_repo_name": "jacobwilliams/AoC-2020", "max_forks_repo_head_hexsha": "2adf673a0ac62710fc5461576feb95bf5fae4cf2", "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.125, "max_line_length": 54, "alphanum_fraction": 0.6024011299, "num_tokens": 479, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711832583695, "lm_q2_score": 0.8221891392358015, "lm_q1q2_score": 0.6988370755384345}} {"text": "! $UWHPSC/codes/mpi/quadrature/quadrature_mod.f90\n\n! Quadrature rules to approximate definite integrals.\n\nmodule quadrature_mod\n\n use mpi\n\ncontains\n\n\nsubroutine simpson(f, a, b, n, integral)\n implicit none\n real(kind=8), intent(in) :: a,b\n integer, intent(in) :: n\n real(kind=8), intent(out) :: integral\n real(kind=8), external :: f\n ! local variables\n real(kind=8) :: xi, dx\n real(kind=8) :: int_proc, a_proc, b_proc, xi_proc\n integer :: numprocs, ierr,points_per_proc,proc_num\n integer :: i,istart,iend\n\n call MPI_COMM_SIZE(MPI_COMM_WORLD, numprocs, ierr)\n call MPI_COMM_RANK(MPI_COMM_WORLD, proc_num, ierr)\n\n ! Determine how many points to handle with each proc\n points_per_proc = (n + numprocs - 1)/numprocs\n if (proc_num == 0) then ! Only one proc should print to avoid clutter\n print *, \"points_per_proc = \", points_per_proc\n end if\n\n ! Determine start and end index for this proc's points\n istart = proc_num * points_per_proc + 1\n iend = min((proc_num + 1)*points_per_proc, n)\n\n dx = (b-a) / n\n integral = 0.d0\n\n a_proc = a + dx*(istart-1)\n b_proc = a + dx*iend\n int_proc = f(a_proc) + f(b_proc)\n\n\n ! Diagnostic: tell the user which points will be handled by which proc\n ! Note: print everything in a single print statement so all the \n ! info for a given process gets printed together.\n\n print 201, proc_num, istart, iend, a_proc, b_proc\n201 format(\"Process \",i2,\" will take i = \",i9,\" through i = \",i9, /, &\n \" Corresponding to a_proc = \",e13.6,\" and b_proc = \",e13.6)\n\n do i=istart+1,iend\n xi_proc = a + dx*(i-1)\n int_proc = int_proc + 2.d0*f(xi_proc)\n enddo\n\n do i=istart,iend\n xi_proc = a + dx*(i-0.5d0)\n int_proc = int_proc + 4.d0*f(xi_proc)\n enddo\n\n call MPI_REDUCE(int_proc,integral,1,MPI_DOUBLE_PRECISION,MPI_SUM,0, &\n MPI_COMM_WORLD,ierr)\n\n if (proc_num == 0) then\n integral = dx*integral / 6.d0\n endif\n\n ! broadcast to all other processes so they all return the right thing:\n call MPI_BCAST(integral, 1, MPI_DOUBLE_PRECISION, 0, MPI_COMM_WORLD, ierr)\n\nend subroutine simpson\n\n\nend module quadrature_mod\n", "meta": {"hexsha": "f3ea425bc55a10b7a6323982a26818d938646d51", "size": 2222, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/codes/mpi/quadrature/quadrature_mod.f90", "max_stars_repo_name": "philipwangdk/HPC", "max_stars_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "uwhpsc/codes/mpi/quadrature/quadrature_mod.f90", "max_issues_repo_name": "philipwangdk/HPC", "max_issues_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "uwhpsc/codes/mpi/quadrature/quadrature_mod.f90", "max_forks_repo_name": "philipwangdk/HPC", "max_forks_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.8571428571, "max_line_length": 78, "alphanum_fraction": 0.6494149415, "num_tokens": 664, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219504, "lm_q2_score": 0.8499711832583695, "lm_q1q2_score": 0.6988370681319122}} {"text": "use ArrayClass\nimplicit none\n\ntype(Array_) :: array1, array2, array3,array4\n\narray1 = to_array([1,2,3],[4,5,6],[7,8,9],dtype=\"float\")\narray2 = to_array([0,0,1],dtype=\"float\")\narray3 = to_array(\"eye\",ndim=3) ! identity matrix\narray4 = to_array(\"random\",ndim=3)\n\n!check array\ncall print(array4)\n\n! dot product\ncall print(dot_product(array1, array3) )\n\n! matrix-vector multiplication\narray1 = matmul(array1, array2)\n\narray1 = array1%T() ! transpose\n\n! or\n!array1 = transpose(array1)\n\nprint *, array1%dtype\ncall print(array1)\n\n\nprint *, array4%dtype\ncall print(array4)\n\n\ncall array4%set(row=2,col=1, val=2.0d0)\nprint *, array4%dtype\ncall print(array4)\n\n\nend", "meta": {"hexsha": "c11a7de88202bebeffa3aeb6d31f3e559d64eeaf", "size": 653, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/numpy_like_array.f90", "max_stars_repo_name": "kazulagi/faba", "max_stars_repo_head_hexsha": "7ef140f1ebea0e0ca496d14fdb94a3c024393cfa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-05T06:04:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:04:25.000Z", "max_issues_repo_path": "Tutorial/numpy_like_array.f90", "max_issues_repo_name": "kazulagi/faba", "max_issues_repo_head_hexsha": "7ef140f1ebea0e0ca496d14fdb94a3c024393cfa", "max_issues_repo_licenses": ["MIT"], "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/numpy_like_array.f90", "max_forks_repo_name": "kazulagi/faba", "max_forks_repo_head_hexsha": "7ef140f1ebea0e0ca496d14fdb94a3c024393cfa", "max_forks_repo_licenses": ["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.1842105263, "max_line_length": 56, "alphanum_fraction": 0.7136294028, "num_tokens": 215, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818865, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.6988000761951327}} {"text": "\tSUBROUTINE LSFIT(Y,X,WT,N,A,B,RMS)\nC\nC\tFIT Y = A*X + B, WITH REMOVAL OF BAD POINTS\nC\n\tDIMENSION Y(1),X(1),WT(1),ERR(1000),WTS(1000)\nC\n\tIF(N.GT.1000) STOP 'TOO MANY POINTS FOR LSFITER'\nC\n\tDO J = 1,N\n\t WTS(J) = WT(J)\n\tENDDO\n\tNREMOVE = 0\n\tLIMIT = .1*N + .5\nC\n 100\tSYY=0.\n\tSXY=0.\n\tSXX=0.\n\tSX=0.\n\tSY=0.\n\tSC=0.\n\tDO 1 J = 1,N\n\t SYY=SYY+WT(J)*Y(J)**2\n\t SXY=SXY+WT(J)*X(J)*Y(J)\n\t SXX=SXX+WT(J)*X(J)**2\n\t SX=SX+WT(J)*X(J)\n\t SY=SY+WT(J)*Y(J)\n\t SC=SC+WT(J)\n 1\tCONTINUE\n\tA=0.\n\tB=0.\n\tDEN=SXX*SC-SX*SX\n\tIF(DEN.EQ.0.) TYPE 101\n\tIF(DEN.EQ.0.) RETURN\n\tA=(SXY*SC-SY*SX)/DEN\n\tB=(SXX*SY-SX*SXY)/DEN\n\tSUMSQ=SYY+SXX*A**2+SC*B**2-2.*SXY*A-2.*SY*B+2.*SX*A*B\n\tSM=SUMSQ/SC\n\tRMS=SQRT(AMAX1(SM,0.))\nC\nC\tNOW FIND LARGE ERRORS, AND REMOVE POINTS, ONE (LARGEST) AT A TIME\nC\t\t IF MORE THAN 4 SIGMA, BUT LIMIT TO 10% OF POINTS\nC\n\tERRMAX = 0.\n\tmax=1\n\tDO J = 1,N\n\t ERR(J) = Y(J) - A*X(J) - B\n\t IF(ABS(WT(J)*ERR(J)).GT.ERRMAX) THEN\n\t ERRMAX = ABS(WT(J)*ERR(J))\n\t MAX = J\t\n\t ENDIF\n\tENDDO\n\tIF(ERRMAX.GE.4.*RMS) THEN\n\t WT(MAX) = 0.\n\t NREMOVE = NREMOVE+1\n\t PRINT*,'REMOVE, N,Y,X',MAX,Y(MAX),X(MAX)\n\t IF(NREMOVE.LE.LIMIT) GO TO 100\n\tENDIF\nC\nC\tRESTORE WT\nC\n\tDO J = 1,N\n\t WT(J) = WTS(J)\n\tENDDO\nC\n\tRETURN\nC\nC\n 101\tFORMAT(' VANISHING DETERMINANT IN LSFIT')\n\tEND\n\n", "meta": {"hexsha": "7736f3b1e23bd5e6be5989a601b48aeca6b21fae", "size": 1245, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/lsfiter_10.for", "max_stars_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_stars_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/lsfiter_10.for", "max_issues_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_issues_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/lsfiter_10.for", "max_forks_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_forks_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.5352112676, "max_line_length": 67, "alphanum_fraction": 0.5831325301, "num_tokens": 623, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818864, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.6988000761951325}} {"text": "c program DRSBACC\nc>> 1996-05-28 DRSBACC Krogh Moved formats up.\nc>> 1994-10-19 DRSBACC Krogh Changes to use M77CON\nc>> 1987-12-09 DRSBACC Lawson Initial Code.\nc--S replaces \"?\": DR?BACC, ?BACC, ?BSOL\nc Demonstration driver for SBACC & SBSOL\nc C. L. Lawson & S. Y. Chiu, JPL, July 1987, Sept 1987.\nc ------------------------------------------------------------------\n integer NX, LDG, NB, ISCALE\n integer I, IERR2, IERR3, IG, IR, J, JT, JTPREV, MT, MTOTAL\n parameter(NX = 10, LDG = 24, NB = 2, ISCALE = 6)\n real XTAB(NX), G(LDG,3), YFIT(NX), C(NX,NX)\n real DELX, DOF, DTOR, RDUMMY, RNORM, SIGFAC, VFAC\n real X, YF, YTRUE\n real ZERO, XINC, XLIMIT\n real ONE, C45, HALF\n parameter(ZERO = 0.0E0, XINC = 1.0E0, XLIMIT = 89.5E0)\n parameter(ONE = 1.0E0, C45 = 45.0E0, HALF = 0.5E0)\n data XTAB / 00.0E0, 10.0E0, 20.0E0, 30.0E0, 40.0E0,\n * 50.0E0, 60.0E0, 70.0E0, 80.0E0, 90.0E0 /\nc\n 1000 format(' Calling SBACC with JT =',i3,', MT =',i3)\n 1003 format(1x/' X Y YFIT R=Y-YFIT'/1X)\n 1004 format(1X, F6.1, 3F10.5)\n 1006 format(1X,10(F7.2,1X))\nc ------------------------------------------------------------------\n write(*,'(1x,a//1x,a/1x,a/1x)')\n *' Demonstration driver for SBACC and SBSOL.',\n *'Compute least-squares fit of a continuous piecewise linear',\n *' function to the sine function on 0 to 90 degrees.'\n DTOR = atan(ONE)/C45\n MTOTAL = 0\n IR = 1\n MT = 0\n JT = 1\n IG = 0\n X = -XINC\n DELX = XTAB(JT+1) - XTAB(JT)\nc\n 20 if( X .lt. XLIMIT)then\n X = X + XINC\n MTOTAL = MTOTAL + 1\n if(X .gt. XTAB(JT+1))then\n write(*,1000) JT, MT\n call SBACC(G,LDG,NB,IR,MT,JT,JTPREV, IERR2)\n IG = IR-1\n MT = 0\n JT = min(JT+1, NX-1)\n DELX = XTAB(JT+1) - XTAB(JT)\n end if\n IG = IG + 1\n MT = MT + 1\n G(IG,1) = (XTAB(JT+1) - X) / DELX\n G(IG,2) = (X - XTAB(JT)) / DELX\n G(IG,3) = sin(x * DTOR)\n go to 20\n end if\n \n if(MT .gt. 0)then\n write(*,1000) JT, MT\n call SBACC(G,LDG,NB,IR,MT,JT,JTPREV, IERR2)\n end if\n \n call SBSOL(1,G,LDG,NB,IR,JTPREV,YFIT,NX,RNORM, IERR3)\nc The following statement does a type conversion.\n DOF = MTOTAL - NX\n SIGFAC = RNORM / SQRT(DOF)\n write(*,'(1x/1x, a, i4, a, f10.5, a, f10.5)')\n * 'MTOTAL =', MTOTAL, ', RNORM =', RNORM, ', SIGFAC =', SIGFAC\n write(*,1003)\n do 30 I=1,NX\n YTRUE = sin(XTAB(I)*DTOR)\n write(*,1004) XTAB(I),YTRUE,YFIT(I),YFIT(I) - YTRUE\n if( I .ne. NX)then\n X = HALF*(XTAB(I+1) + XTAB(I))\n YF = HALF*(YFIT(I+1) + YFIT(I))\n YTRUE = sin(X*DTOR)\n write(*,1004) X,YTRUE,YF,YF - YTRUE\n end if\n 30 continue\nc\nc Compute unscaled covariance matrix in C(,).\nc\n do 50 J = 1,NX\n do 40 I = 1,NX\n C(I,J) = ZERO\n 40 continue\n C(J,J) = ONE\n call SBSOL(2,G,LDG,NB,IR,JTPREV,C(1,J),NX,RDUMMY,IERR3)\n call SBSOL(3,G,LDG,NB,IR,JTPREV,C(1,J),NX,RDUMMY,IERR3)\n 50 continue\nc\n write(*,'(1x/10x,a,i1/1x)')\n * 'Covariance matrix scaled up by 10**',ISCALE\nc\n VFAC = (10**ISCALE) * SIGFAC**2\n do 60 I = 1,NX\n print 1006,(VFAC*C(I,J),J=1,NX)\n 60 continue\nc\n stop\n end\n", "meta": {"hexsha": "1b4a881632eb8004fc66c7b0a85b19cf0a1e30a1", "size": 3491, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drsbacc.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drsbacc.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drsbacc.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": 33.8932038835, "max_line_length": 72, "alphanum_fraction": 0.4883987396, "num_tokens": 1393, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178994073576, "lm_q2_score": 0.7690802370707283, "lm_q1q2_score": 0.6988000694829177}} {"text": "! RUN: %S/test_folding.sh %s %t %flang_fc1\n! REQUIRES: shell\n! Tests reduction intrinsic function folding\nmodule m\n implicit none\n integer, parameter :: intmatrix(*,*) = reshape([1, 2, 3, 4, 5, 6], [2, 3])\n logical, parameter :: odds(2,3) = mod(intmatrix, 2) == 1\n character(*), parameter :: chmatrix(*,*) = reshape(['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr'], [2, 3])\n\n logical, parameter :: test_allidentity = all([Logical::])\n logical, parameter :: test_all = .not. all(odds)\n logical, parameter :: test_alldim1 = all(.not. all(odds,1))\n logical, parameter :: test_alldim2 = all(all(odds,2) .eqv. [.true., .false.])\n logical, parameter :: test_anyidentity = .not. any([Logical::])\n logical, parameter :: test_any = any(odds)\n logical, parameter :: test_anydim1 = all(any(odds,1))\n logical, parameter :: test_anydim2 = all(any(odds,2) .eqv. [.true., .false.])\n\n logical, parameter :: test_iallidentity = iall([integer::]) == -1\n logical, parameter :: test_iall = iall(intmatrix) == 0\n logical, parameter :: test_iall_masked = iall(intmatrix,odds) == 1\n logical, parameter :: test_ialldim1 = all(iall(intmatrix,dim=1) == [0, 0, 4])\n logical, parameter :: test_ialldim2 = all(iall(intmatrix,dim=2) == [1, 0])\n logical, parameter :: test_ianyidentity = iany([integer::]) == 0\n logical, parameter :: test_iany = iany(intmatrix) == 7\n logical, parameter :: test_iany_masked = iany(intmatrix,odds) == 7\n logical, parameter :: test_ianydim1 = all(iany(intmatrix,dim=1) == [3, 7, 7])\n logical, parameter :: test_ianydim2 = all(iany(intmatrix,dim=2) == [7, 6])\n logical, parameter :: test_iparityidentity = iparity([integer::]) == 0\n logical, parameter :: test_iparity = iparity(intmatrix) == 7\n logical, parameter :: test_iparity_masked = iparity(intmatrix,odds) == 7\n logical, parameter :: test_iparitydim1 = all(iparity(intmatrix,dim=1) == [3, 7, 3])\n logical, parameter :: test_iparitydim2 = all(iparity(intmatrix,dim=2) == [7, 0])\n\n logical, parameter :: test_imaxidentity = maxval([integer::]) == -huge(0) - 1\n logical, parameter :: test_iminidentity = minval([integer::]) == huge(0)\n logical, parameter :: test_imaxval = maxval(intmatrix) == 6\n logical, parameter :: test_iminval = minval(intmatrix) == 1\n logical, parameter :: test_imaxval_masked = maxval(intmatrix,odds) == 5\n logical, parameter :: test_iminval_masked = minval(intmatrix,.not.odds) == 2\n logical, parameter :: test_rmaxidentity = maxval([real::]) == -huge(0.0)\n logical, parameter :: test_rminidentity = minval([real::]) == huge(0.0)\n logical, parameter :: test_rmaxval = maxval(real(intmatrix)) == 6.0\n logical, parameter :: test_rminval = minval(real(intmatrix)) == 1.0\n logical, parameter :: test_rmaxval_scalar_mask = maxval(real(intmatrix), .true.) == 6.0\n logical, parameter :: test_rminval_scalar_mask = minval(real(intmatrix), .false.) == huge(0.0)\n logical, parameter :: test_cmaxlen = len(maxval([character*4::])) == 4\n logical, parameter :: test_cmaxidentity = maxval([character*4::]) == repeat(char(0), 4)\n logical, parameter :: test_cminidentity = minval([character*4::]) == repeat(char(127), 4)\n logical, parameter :: test_cmaxval = maxval(chmatrix) == 'pqr'\n logical, parameter :: test_cminval = minval(chmatrix) == 'abc'\n logical, parameter :: test_maxvaldim1 = all(maxval(intmatrix,dim=1) == [2, 4, 6])\n logical, parameter :: test_minvaldim2 = all(minval(intmatrix,dim=2,mask=odds) == [1, huge(0)])\n\n logical, parameter :: test_iproductidentity = product([integer::]) == 1\n logical, parameter :: test_iproduct = product(intmatrix) == 720\n logical, parameter :: test_iproduct_masked = product(intmatrix,odds) == 15\n logical, parameter :: test_productdim1 = all(product(intmatrix,dim=1) == [2, 12, 30])\n logical, parameter :: test_productdim2 = all(product(intmatrix,dim=2) == [15, 48])\n logical, parameter :: test_rproductidentity = product([real::]) == 1.\n logical, parameter :: test_rproduct = product(real(intmatrix)) == 720.\n logical, parameter :: test_cproductidentity = product([complex::]) == (1.,0.)\n logical, parameter :: test_cproduct = product(cmplx(intmatrix,-intmatrix)) == (0.,5760.)\n\n logical, parameter :: test_isumidentity = sum([integer::]) == 0\n logical, parameter :: test_isum = sum(intmatrix) == 21\n logical, parameter :: test_isum_masked = sum(intmatrix,odds) == 9\n logical, parameter :: test_sumdim1 = all(sum(intmatrix,dim=1) == [3, 7, 11])\n logical, parameter :: test_sumdim2 = all(sum(intmatrix,dim=2) == [9, 12])\n logical, parameter :: test_rsumidentity = sum([real::]) == 0.\n logical, parameter :: test_rsum = sum(real(intmatrix)) == 21.\n logical, parameter :: test_csumidentity = sum([complex::]) == (0.,0.)\n logical, parameter :: test_csum = sum(cmplx(intmatrix,-intmatrix)) == (21.,-21.)\nend\n", "meta": {"hexsha": "7d14e978dd8387bef35a8784cbabefc9fc4055da", "size": 4771, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "flang/test/Evaluate/folding20.f90", "max_stars_repo_name": "acidburn0zzz/llvm-project", "max_stars_repo_head_hexsha": "7ca7a2547f00e34f5ec91be776a1d0bbca74b7a9", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 61, "max_stars_repo_stars_event_min_datetime": "2019-04-12T18:49:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-19T22:23:16.000Z", "max_issues_repo_path": "flang/test/Evaluate/folding20.f90", "max_issues_repo_name": "acidburn0zzz/llvm-project", "max_issues_repo_head_hexsha": "7ca7a2547f00e34f5ec91be776a1d0bbca74b7a9", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 127, "max_issues_repo_issues_event_min_datetime": "2019-04-09T00:55:50.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T15:35:41.000Z", "max_forks_repo_path": "flang/test/Evaluate/folding20.f90", "max_forks_repo_name": "acidburn0zzz/llvm-project", "max_forks_repo_head_hexsha": "7ca7a2547f00e34f5ec91be776a1d0bbca74b7a9", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2019-04-02T18:25:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-15T07:11:37.000Z", "avg_line_length": 63.6133333333, "max_line_length": 104, "alphanum_fraction": 0.6788933138, "num_tokens": 1514, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818865, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.6988000665769251}} {"text": "program main\n use mpi\n implicit none\n real(8), parameter :: pi = acos(-1.d0), kB = 1.d0\n integer :: ntasks, id, rc\n integer, allocatable :: status(:)\n integer :: i, n, clock\n integer, allocatable :: seed(:)\n real(8) :: r\n\n real(8) :: T, dT = .002d0, T_final = 2.35d0, beta\n integer :: L = 30, dL = 2, L_final = 100\n integer, allocatable :: lattice(:,:)\n integer :: x, y\n integer, parameter :: n_warmup = 200, n_evol = 2000\n real(8) :: J = 1.d0, P_add\n real(8) :: M, M_sqr, E_tmp, E, E_sqr, M_ave, M_sqr_ave, chi, E_ave, E_sqr_ave, C\n real(8) :: T_c, m_c, chi_max, C_max\n\n ! initialize MPI environment\n call MPI_INIT(rc)\n call MPI_COMM_SIZE(MPI_COMM_WORLD, ntasks, rc)\n call MPI_COMM_RANK(MPI_COMM_WORLD, id, rc)\n allocate(status(MPI_STATUS_SIZE))\n\n ! initialize seeds for different processes\n if (id == 0) then\n call SYSTEM_CLOCK(clock)\n call RANDOM_SEED(size = n)\n allocate(seed(n))\n do i = 1, n\n seed(i) = clock + 37 * i\n end do\n call RANDOM_SEED(PUT = seed)\n deallocate(seed)\n do i = 1, ntasks - 1\n call RANDOM_NUMBER(r)\n clock = clock + Int(r * 1000000)\n call MPI_SEND(clock, 1, MPI_INTEGER, i, i, MPI_COMM_WORLD, rc)\n end do\n else\n call MPI_RECV(clock, 1, MPI_INTEGER, 0, id, MPI_COMM_WORLD, status, rc)\n call RANDOM_SEED(size = n)\n allocate(seed(n))\n do i = 1, n\n seed(i) = clock + 37 * i\n end do\n call RANDOM_SEED(PUT = seed)\n deallocate(seed)\n end if\n\n do while (L <= L_final)\n if (id == 0) then\n open(unit = 1, file = 'data.txt', status = 'unknown', position = 'append')\n open(unit = 2, file = 'summary.txt', status = 'unknown', position = 'append')\n write(*,*) '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'\n write(*,'(\" !!!!!!!!!!!!!!!!!!!!!!!!!!!!! L = \",i10,\" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\")') L\n write(*,*) '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'\n write(*,'(4a20)') 'T', 'm', 'chi', 'C'\n end if\n T = 2.25d0\n T_c = 0\n m_c = 0\n chi_max = 0\n C_max = 0\n allocate(Lattice(0:L - 1,0:L - 1))\n Lattice = 1\n\n do while (T < T_final)\n beta = 1.d0 / kB / T\n P_add = 1 - exp(-2 * beta * J)\n M = 0.d0\n M_sqr = 0.d0\n E = 0.d0\n E_sqr = 0.d0\n\n ! warm up\n do i =1, n_warmup\n call EVOLUTION(lattice, L, P_add)\n end do\n\n ! evolution\n do i = 1, n_evol\n call EVOLUTION(lattice, L, P_add)\n M = M + abs(sum(lattice))\n M_sqr = M_sqr + sum(lattice)**2\n E_tmp = 0.d0\n do x = 0, L - 2\n do y = 0, L - 2\n E_tmp = E_tmp + lattice(x, y) * (lattice(x + 1, y) + lattice(x, y + 1))\n end do\n end do\n do x = 0, L - 2\n E_tmp = E_tmp + lattice(x, L - 1) * (lattice(x + 1, L - 1) + lattice(x, 0))\n end do\n do y = 0, L - 2\n E_tmp = E_tmp + lattice(L - 1, y) * (lattice(L - 1, y + 1) + lattice(0, y))\n end do\n E_tmp = E_tmp + lattice(L - 1, L - 1) * (lattice(0, L - 1) + Lattice(L - 1, 0))\n E_tmp = - E_tmp * J\n E = E + E_tmp\n E_sqr = E_sqr + E_tmp**2\n end do\n call MPI_REDUCE(M, M_ave, 1, MPI_REAL8, MPI_SUM, 0, MPI_COMM_WORLD, rc)\n call MPI_REDUCE(M_sqr, M_sqr_ave, 1, MPI_REAL8, MPI_SUM, 0, MPI_COMM_WORLD, rc)\n call MPI_REDUCE(E, E_ave, 1, MPI_REAL8, MPI_SUM, 0, MPI_COMM_WORLD, rc)\n call MPI_REDUCE(E_sqr, E_sqr_ave, 1, MPI_REAL8, MPI_SUM, 0, MPI_COMM_WORLD, rc)\n if (id == 0) then\n M_ave = M_ave / dble(ntasks * n_evol)\n M_sqr_ave = M_sqr_ave / dble(ntasks * n_evol)\n chi = beta * (M_sqr_ave - M_ave**2)\n E_ave = E_ave / dble(ntasks * n_evol)\n E_sqr_ave = E_sqr_ave / dble(ntasks * n_evol)\n C = kB * beta**2 / dble(L * L) * (E_sqr_ave - E_ave**2)\n write(*,'(4f20.10)') T, M_ave / dble(L * L), chi, C\n write(1,'(4f20.10)') T, M_ave / dble(L * L), chi, C\n\n if (chi > chi_max) then\n m_c = M_ave / dble(L * L)\n chi_max = chi\n T_c = T\n C_max = C\n end if\n end if\n T = T + dT\n end do\n\n if (id == 0) then\n write(*,*) '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'\n write(*,'(a5,a15,3a20)') 'L', 'T_c', 'm_c', 'chi_max', 'C_max'\n write(*,'(i5,f15.10,3f20.10)') L, T_c, m_c, chi_max, C_max\n write(*,*) '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'\n write(*,*)\n write(1,*)\n write(2,'(i10,4f20.10)') L, T_c, m_c, chi_max, C_max\n close(1)\n close(2)\n end if\n L = L + dL\n deallocate(Lattice)\n end do\n\n ! done with MPI\n call MPI_FINALIZE(rc)\nend program main\n\nsubroutine EVOLUTION(lattice, L, P_add)\n implicit none\n integer, intent(in) :: L\n integer, intent(inout) :: lattice(0:L - 1, 0:L - 1)\n real(8), intent(in) :: P_add\n real(8) :: r\n integer :: x, y, x_neighbor, y_neighbor, i\n integer :: cluster(L * L, 2)\n integer :: n_seed, n_cluster, cluster_spin\n logical :: notincluster\n\n ! choose seed spin\n call RANDOM_NUMBER(r)\n x = floor(r * dble(L))\n call RANDOM_NUMBER(r)\n y = floor(r * dble(L))\n n_cluster = 1\n n_seed = 1\n cluster(1,1) = x\n cluster(1,2) = y\n cluster_spin = lattice(x, y)\n lattice(x, y) = -lattice(x, y)\n\n do while (n_seed <= n_cluster)\n x = cluster(n_seed, 1)\n y = cluster(n_seed, 2)\n n_seed = n_seed + 1\n\n x_neighbor = modulo(x - 1, L)\n y_neighbor = y\n if (lattice(x_neighbor, y_neighbor) == cluster_spin) then\n call RANDOM_NUMBER(r)\n if (r < P_add) then\n notincluster = .true.\n do i = n_cluster, 1, -1\n if ((cluster(i, 1) == x_neighbor) .and. (cluster(i, 2) == y_neighbor)) then\n notincluster = .false.\n exit\n end if\n end do\n if (notincluster .eqv. .true.) then\n n_cluster = n_cluster + 1\n cluster(n_cluster, 1) = x_neighbor\n cluster(n_cluster, 2) = y_neighbor\n lattice(x_neighbor, y_neighbor) = -lattice(x_neighbor, y_neighbor)\n end if\n end if\n end if\n\n x_neighbor = modulo(x + 1, L)\n ! y_neighbor = y\n if (lattice(x_neighbor, y_neighbor) == cluster_spin) then\n call RANDOM_NUMBER(r)\n if (r < P_add) then\n notincluster = .true.\n do i = n_cluster, 1, -1\n if ((cluster(i, 1) == x_neighbor) .and. (cluster(i, 2) == y_neighbor)) then\n notincluster = .false.\n exit\n end if\n end do\n if (notincluster .eqv. .true.) then\n n_cluster = n_cluster + 1\n cluster(n_cluster, 1) = x_neighbor\n cluster(n_cluster, 2) = y_neighbor\n lattice(x_neighbor, y_neighbor) = -lattice(x_neighbor, y_neighbor)\n end if\n end if\n end if\n\n x_neighbor = x\n y_neighbor = modulo(y - 1, L)\n if (lattice(x, y_neighbor) == cluster_spin) then\n call RANDOM_NUMBER(r)\n if (r < P_add) then\n notincluster = .true.\n do i = n_cluster, 1, -1\n if ((cluster(i, 1) == x_neighbor) .and. (cluster(i, 2) == y_neighbor)) then\n notincluster = .false.\n exit\n end if\n end do\n if (notincluster .eqv. .true.) then\n n_cluster = n_cluster + 1\n cluster(n_cluster, 1) = x_neighbor\n cluster(n_cluster, 2) = y_neighbor\n lattice(x_neighbor, y_neighbor) = -lattice(x_neighbor, y_neighbor)\n end if\n end if\n end if\n\n ! x_neighbor = x\n y_neighbor = modulo(y + 1, L)\n if (lattice(x_neighbor, y_neighbor) == cluster_spin) then\n call RANDOM_NUMBER(r)\n if (r < P_add) then\n notincluster = .true.\n do i = n_cluster, 1, -1\n if ((cluster(i, 1) == x_neighbor) .and. (cluster(i, 2) == y_neighbor)) then\n notincluster = .false.\n exit\n end if\n end do\n if (notincluster .eqv. .true.) then\n n_cluster = n_cluster + 1\n cluster(n_cluster, 1) = x_neighbor\n cluster(n_cluster, 2) = y_neighbor\n lattice(x_neighbor, y_neighbor) = -lattice(x_neighbor, y_neighbor)\n end if\n end if\n end if\n end do\nend subroutine EVOLUTION\n", "meta": {"hexsha": "d15fe2dcdae959d89186b4165a923591aad662e2", "size": 9620, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Week-16-Project/Project/2-2DIsingModel-Wolff-mpi.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-16-Project/Project/2-2DIsingModel-Wolff-mpi.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-16-Project/Project/2-2DIsingModel-Wolff-mpi.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": 37.0, "max_line_length": 106, "alphanum_fraction": 0.4466735967, "num_tokens": 2780, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178895092414, "lm_q2_score": 0.7690802370707283, "lm_q1q2_score": 0.6988000618704722}} {"text": "C SUBROUTINE POLFIT.F \nC\nC SOURCE\nC BEVINGTON, PAGES 140-142.\nC\nC PURPOSE\nC MAKE A LEAST-SQUARES FIT TO DATA WITH A POLYNOMIAL CURVE\nC Y = A(1) + A(2)*X + A(3)*X**2 + A(3)*X**3 + . . .\nC\nC USAGE \nC CALL POLFIT (X, Y, SIGMAY, NPTS, NTERMS, MODE, A, CHISQR)\nC\nC DESCRIPTION OF PARAMETERS\nC X\t - ARRAY OF DATA POINTS FOR INDEPENDENT VARIABLE\nC Y\t - ARRAY OF DATA POINTS FOR DEPENDENT VARIABLE\nC SIGMAY - ARRAY OF STANDARD DEVIATIONS FOR Y DATA POINTS\nC NPTS - NUMBER OF PAIRS OF DATA POINTS\nC NTERMS - NUMBER OF COEFFICIENTS (DEGREE OF POLYNOMIAL + 1)\nC MODE - DETERMINES METHOD OF WEIGHTING LEAST-SQUARES FIT\nC\t +1 (INSTRUMENTAL) WEIGHT(I) = 1./SIGMAY(I)**2\nC\t 0 (NO WEIGHTING) WEIGHT(I) = 1.\nC\t -1 (STATISTICAL) WEIGHT(I) = 1./Y(I)\nC A\t - ARRAY OF COEFFICIENTS OF POLYNOMIAL\nC CHISQR - REDUCED CHI SQUARE FOR FIT \nC\nC SUBROUTINES AND FUNCTION SUBPROGRAMS REQUIRED \nC DETERM (ARRAY, NORDER)\nC EVALUATES THE DETERMINANT OF A SYMETRICAL\nC TWO-DIMENSIONAL MATRIX OF ORDER NORDER\nC\nC COMMENTS\nC DIMENSION STATEMENT VALID FOR NTERMS UP TO 10\nC\n\tSUBROUTINE POLFIT (X,Y,SIGMAY,NPTS,NTERMS,MODE,A,CHISQR)\n\tDOUBLE PRECISION SUMX,SUMY,XTERM,YTERM,ARRAY,CHISQ\n\tDIMENSION X(1),Y(1),SIGMAY(1),A(1)\n\tDIMENSION SUMX(19),SUMY(10),ARRAY(10,10)\nC\nC ACCUMULATE WEIGHTED SUMS\nC\n11\tNMAX=2*NTERMS-1 \n\tDO 13 N=1,NMAX\n13\tSUMX(N)=0.\n\tDO 15 J=1,NTERMS\n15\tSUMY(J)=0.\n\tCHISQ=0.\n21\tDO 50 I=1,NPTS\n\tXI=X(I) \n\tYI=Y(I) \n31\tIF (MODE) 32,37,39\n32\tIF (YI) 35,37,33\n33\tWEIGHT=1./YI\n\tGOTO 41 \n35\tWEIGHT=1./(-YI) \n\tGOTO 41 \n37\tWEIGHT=1.\n\tGOTO 41 \n39\tWEIGHT=1./SIGMAY(I)**2\n41\tXTERM=WEIGHT\n\tDO 44 N=1,NMAX\n\tSUMX(N)=SUMX(N)+XTERM\n44\tXTERM=XTERM*XI\n45\tYTERM=WEIGHT*YI \n\tDO 48 N=1,NTERMS\n\tSUMY(N)=SUMY(N)+YTERM\n48\tYTERM=YTERM*XI\n49\tCHISQ=CHISQ+WEIGHT*YI**2\n50\tCONTINUE\nC\nC CONSTRUCT MATRICES AND CALCULATE COEFFICIENTS \nC\n51\tDO 54 J=1,NTERMS\n\tDO 54 K=1,NTERMS\n\tN=J+K-1 \n54\tARRAY(J,K)=SUMX(N)\n\tDELTA=DETERM (ARRAY,NTERMS)\n\tIF (DELTA) 61,57,61\n57\tCHISQR=0.\n\tDO 59 J=1,NTERMS\n59\tA(J)=0. \n\tGOTO 80 \n61\tDO 70 L=1,NTERMS\n62\tDO 66 J=1,NTERMS\n\tDO 65 K=1,NTERMS\n\tN=J+K-1 \n65\tARRAY(J,K)=SUMX(N)\n66\tARRAY(J,L)=SUMY(J)\n70\tA(L)=DETERM (ARRAY,NTERMS) /DELTA\nC\nC CALCULATE CHI SQUARE\nC\n71\tDO 75 J=1,NTERMS\n\tCHISQ=CHISQ-2.*A(J)*SUMY(J)\n\tDO 75 K=1,NTERMS\n\tN=J+K-1 \n75\tCHISQ=CHISQ+A(J)*A(K)*SUMX(N)\n76\tFREE=NPTS-NTERMS\n77\tCHISQR=CHISQ/FREE\n80\tRETURN\n\tEND\n", "meta": {"hexsha": "cfbdb178558fe22e6fa087ffa0c7653d03d61644", "size": 2358, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iraf.v2161/math/bevington/polfit.f", "max_stars_repo_name": "ysBach/irafdocgen", "max_stars_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:19:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T16:48:42.000Z", "max_issues_repo_path": "math/bevington/polfit.f", "max_issues_repo_name": "kirxkirx/iraf", "max_issues_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-30T13:48:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-02T19:40:25.000Z", "max_forks_repo_path": "math/bevington/polfit.f", "max_forks_repo_name": "kirxkirx/iraf", "max_forks_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.3465346535, "max_line_length": 62, "alphanum_fraction": 0.6861747243, "num_tokens": 1068, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178870347122, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6988000599673606}} {"text": "program problem_2\n\nuse aoc_utilities\n\nimplicit none\n\ninteger,dimension(2) :: xz !! [horizontal position, depth]\ninteger,dimension(3) :: xza !! [horizontal position, depth, aim]\ninteger :: i, ival, iunit\ncharacter(len=:),allocatable :: line\nlogical :: status_ok\ntype(string),dimension(:),allocatable :: vals\n\nxz = 0\nxza = 0\n\nopen(newunit=iunit,file='inputs/day2.txt')\ndo i = 1, number_of_lines_in_file(iunit)\n\n call read_line_from_file(iunit,line,status_ok)\n\n call split(line,' ',vals)\n\n read(vals(2)%str, '(I10)') ival ! string to integer\n\n select case (vals(1)%str)\n case('forward')\n xz(1) = xz(1) + ival\n xza(1) = xza(1) + ival ! increases your horizontal position by X units.\n xza(2) = xza(2) + (xza(3)*ival) ! increases your depth by your aim multiplied by X\n case('up')\n xz(2) = xz(2) - ival\n xza(3) = xza(3) - ival\n case('down')\n xz(2) = xz(2) + ival\n xza(3) = xza(3) + ival\n case default; error stop 'error'\n end select\n\nend do\n\nwrite(*,*) '2A: horizontal * depth: ', product(xz)\n\nwrite(*,*) '2B: horizontal * depth: ', product(xza(1:2))\n\nend program problem_2", "meta": {"hexsha": "80f3d0c911b3e808f2fa34bf606bbe458d46e54c", "size": 1152, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/problem_02.f90", "max_stars_repo_name": "jacobwilliams/AoC-2021", "max_stars_repo_head_hexsha": "e06120ca1fd7dbd4eda098b36ef0b2922ed1c718", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-12-01T08:25:16.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-19T16:29:10.000Z", "max_issues_repo_path": "test/problem_02.f90", "max_issues_repo_name": "jacobwilliams/AoC-2021", "max_issues_repo_head_hexsha": "e06120ca1fd7dbd4eda098b36ef0b2922ed1c718", "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": "test/problem_02.f90", "max_forks_repo_name": "jacobwilliams/AoC-2021", "max_forks_repo_head_hexsha": "e06120ca1fd7dbd4eda098b36ef0b2922ed1c718", "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.0434782609, "max_line_length": 90, "alphanum_fraction": 0.6223958333, "num_tokens": 380, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099168, "lm_q2_score": 0.8128673246376008, "lm_q1q2_score": 0.698792572964922}} {"text": "SUBROUTINE LUBKSB(A,N,NP,INDX,B)\n IMPLICIT NONE\n \n !Transferred variables\n INTEGER::N,NP,INDX(N)\n REAL(8)::A(NP,NP),B(N)\n \n !Local variables\n INTEGER::I,II,J,LL\n REAL(8)::SUM\n \n II=0\n DO I=1,N\n LL=INDX(I)\n SUM=B(LL)\n B(LL)=B(I)\n IF (II.NE.0) THEN\n DO J=II,I-1\n SUM=SUM-A(I,J)*B(J)\n END DO\n ELSE IF (SUM.NE.0.0) THEN\n II=I\n END IF\n B(I)=SUM\n END DO\n DO I=N,1,-1\n SUM=B(I)\n IF (I.LT.N) THEN\n DO J=I+1,N\n SUM=SUM-A(I,J)*B(J)\n END DO\n END IF\n B(I)=SUM/A(I,I)\n END DO\n \nEND SUBROUTINE LUBKSB\n", "meta": {"hexsha": "85796fec866f9fc95dee530e3d4b49a036317c80", "size": 579, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "code/SourceCode/Package_Matrix/Lubksb.f90", "max_stars_repo_name": "giorgk/IWFM-SAFE", "max_stars_repo_head_hexsha": "849abb22bd7b29c113d0537d228340abe6672b40", "max_stars_repo_licenses": ["MIT"], "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/SourceCode/Package_Matrix/Lubksb.f90", "max_issues_repo_name": "giorgk/IWFM-SAFE", "max_issues_repo_head_hexsha": "849abb22bd7b29c113d0537d228340abe6672b40", "max_issues_repo_licenses": ["MIT"], "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/SourceCode/Package_Matrix/Lubksb.f90", "max_forks_repo_name": "giorgk/IWFM-SAFE", "max_forks_repo_head_hexsha": "849abb22bd7b29c113d0537d228340abe6672b40", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.6486486486, "max_line_length": 32, "alphanum_fraction": 0.5077720207, "num_tokens": 248, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190939, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.6987925573768419}} {"text": " SUBROUTINE actrot(lambda,theta)\r\n!*****************************************************************\r\n!\r\n! UPDATES THE NODAL LOCAL AXES\r\n!\r\n!*****************************************************************\r\n IMPLICIT NONE\r\n! dummy arguments\r\n REAL (kind=8),INTENT(IN) :: theta(3) !rotation increment\r\n REAL (kind=8),INTENT(IN OUT) :: lambda(3,3) !local system\r\n! local variables\r\n REAL (kind=8) :: t(3),dl(3,3),l(3,3),modulo,c1,c2,c3\r\n\r\n modulo=SQRT(DOT_PRODUCT(theta,theta)) !check if Theta /= 0\r\n IF(modulo == 0d0) RETURN\r\n t = theta/modulo !rotation axis\r\n l = lambda !previous local axis\r\n\r\n c1 = SIN(modulo) !factors\r\n c2 = 2d0*(SIN(modulo/2d0))**2\r\n c3 = 1d0-c2\r\n\r\n dl(1,1) = c3 + c2 * t(1)*t(1) !Delta Lambda\r\n dl(2,1) = c1*t(3) + c2 * t(2)*t(1)\r\n dl(3,1) = - c1*t(2) + c2 * t(3)*t(1)\r\n dl(1,2) = - c1*t(3) + c2 * t(1)*t(2)\r\n dl(2,2) = c3 + c2 * t(2)*t(2)\r\n dl(3,2) = c1*t(1) + c2 * t(3)*t(2)\r\n dl(1,3) = c1*t(2) + c2 * t(1)*t(3)\r\n dl(2,3) = - c1*t(1) + c2 * t(2)*t(3)\r\n dl(3,3) = c3 + c2 * t(3)*t(3)\r\n\r\n lambda = MATMUL(l,dl) !new local axis\r\n\r\n RETURN\r\n END SUBROUTINE actrot\r\n", "meta": {"hexsha": "9968830c4b3087a13b4c0fc04cac011460856796", "size": 1273, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/mainp/actrot.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/mainp/actrot.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/mainp/actrot.f90", "max_forks_repo_name": "jerebenitez/IFE-simpact-openfoam", "max_forks_repo_head_hexsha": "2dbcbf3195b22fca1c80ad0da6b3822b6cad5cdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.4054054054, "max_line_length": 67, "alphanum_fraction": 0.4202670856, "num_tokens": 462, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632302488963, "lm_q2_score": 0.734119526900183, "lm_q1q2_score": 0.6987813842639997}} {"text": "\tSUBROUTINE DP_UGRB ( idata, kxky, nbits, qmin, scale, misflg,\n +\t\t\t grid, iret )\nC************************************************************************\nC* DP_UGRB\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This subroutine unpacks a grid into the GEMPAK GRIB format.\t\t*\nC* The packing and unpacking equations are:\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC*\tIDATA = NINT ( ( GRID - QMIN ) / SCALE )\t\t\t*\nC*\tGRID = QMIN + IDATA * SCALE\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* DP_UGRB ( IDATA, KXKY, NBITS, QMIN, SCALE, MISFLG, GRID, IRET )\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tIDATA (*)\tINTEGER\t\tPacked data\t\t\t*\nC*\tKXKY\t\tINTEGER\t\tNumber of grid points\t\t*\nC*\tNBITS\t\tINTEGER\t\tNumber of bits\t\t\t*\nC*\tQMIN\t\tREAL\t\tMinimum value of grid\t\t*\nC*\tSCALE\t\tREAL\t\tScaling factor\t\t\t*\nC*\tMISFLG\t\tLOGICAL\t\tMissing data flag\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tGRID (KXKY)\tREAL\t\tGrid data\t\t\t*\nC*\tIRET\t\tINTEGER\t\tReturn code\t\t\t*\nC*\t\t\t\t\t 0 = normal return\t\t*\nC*\t\t\t\t\t-10 = NBITS invalid\t\t*\nC*\t\t\t\t\t-12 = invalid scale\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* M. desJardins/GSFC\t 3/89\t\t\t\t\t\t*\nC************************************************************************\n\tINCLUDE\t\t'GEMPRM.PRM'\nC*\n\tREAL\t\tgrid (*)\n\tINTEGER\t\tidata (*)\n\tLOGICAL\t\tmisflg\nC------------------------------------------------------------------------\n\tiret = 0\nC\nC*\tCheck for valid input.\nC\n\tIF ( ( nbits .le. 1 ) .or. ( nbits .gt. 31 ) ) THEN\n\t iret = -10\n\t RETURN\n\tEND IF\n\tIF ( scale .eq. 0. ) THEN\n\t iret = -12\n\t RETURN\n\tEND IF\nC\nC*\tCompute missing data value.\nC\n\timax = 2 ** nbits - 1\nC\nC*\tRetrieve data points from buffer.\nC\n\tiword = 1\n\tibit = 1\n\tDO i = 1, kxky\nC\nC*\t Get the integer from the buffer.\nC\n\t jshft = nbits + ibit - 33\n\t idat = 0\n\t idat = ISHFT ( idata (iword), jshft )\n\t idat = IAND ( idat, imax )\nC\nC*\t Check to see if packed integer overflows into next word.\nC\n\t IF ( jshft .gt. 0 ) THEN\n\t\tjshft = jshft - 32\n\t\tidat2 = 0\n\t\tidat2 = ISHFT ( idata (iword+1), jshft )\n\t\tidat = IOR ( idat, idat2 )\n\t END IF\nC\nC*\t Compute value of word.\nC\n\t IF ( ( idat .eq. imax ) .and. misflg ) THEN\n\t\tgrid (i) = RMISSD\n\t ELSE\n\t\tgrid (i) = qmin + idat * scale\n\t END IF\nC\nC*\t Set location for next word.\nC\n\t ibit = ibit + nbits\n\t IF ( ibit .gt. 32 ) THEN\n\t\tibit = ibit - 32\n\t\tiword = iword + 1\n\t END IF\n\tEND DO\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "499fde1210b8bcdf3abb8c585cf2a3bcf45685c6", "size": 2329, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/gemlib/dp/dpugrb.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/gemlib/dp/dpugrb.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": "dpugrb.f", "max_forks_repo_name": "sgdecker/pygempak", "max_forks_repo_head_hexsha": "e64dd08c1ab80ce17321dc4c904d67f1317373e2", "max_forks_repo_licenses": ["Apache-2.0"], "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": 24.2604166667, "max_line_length": 73, "alphanum_fraction": 0.5040790039, "num_tokens": 892, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802440252811, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.6986426020725589}} {"text": "program PolynomalFitting\n use fitting\n implicit none\n\n ! let us test it\n integer, parameter :: degree = 2\n integer, parameter :: dp = selected_real_kind(15, 307)\n integer :: i\n real(dp), dimension(11) :: x = (/ (i,i=0,10) /)\n real(dp), dimension(11) :: y = (/ 1, 6, 17, 34, &\n 57, 86, 121, 162, &\n 209, 262, 321 /)\n real(dp), dimension(degree+1) :: a\n\n a = polyfit(x, y, degree)\n\n write (*, '(F9.4)') a\n\nend program\n", "meta": {"hexsha": "de15da13d45a8710e1693992f0c74ce52b2c5977", "size": 526, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Polynomial-regression/Fortran/polynomial-regression-2.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Polynomial-regression/Fortran/polynomial-regression-2.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Polynomial-regression/Fortran/polynomial-regression-2.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 26.3, "max_line_length": 61, "alphanum_fraction": 0.4790874525, "num_tokens": 172, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802484881361, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6986425955001647}} {"text": " SUBROUTINE FCUSP(N,T,Y,F,RPAR,IPAR)\nC --- RIGHT-HAND SIDE OF THE CUSP EQUATION\n IMPLICIT REAL*8 (A-H,O-Z)\n DIMENSION Y(N),F(N)\n COMMON/NERVES/NNERV\n COMMON/DIFFCOEF/DIFFUS\nc-----------\n DO 25 INERV=1,NNERV\n X=Y(3*INERV-2)\n A=Y(3*INERV-1)\n B=Y(3*INERV)\n IF(INERV.EQ.1)THEN\n XRIGHT=Y(3*NNERV-2)\n ARIGHT=Y(3*NNERV-1)\n BRIGHT=Y(3*NNERV)\n ELSE\n XRIGHT=Y(3*INERV-5)\n ARIGHT=Y(3*INERV-4)\n BRIGHT=Y(3*INERV-3)\n END IF\n IF(INERV.EQ.NNERV)THEN\n XLEFT=Y(1)\n ALEFT=Y(2)\n BLEFT=Y(3)\n ELSE\n XLEFT=Y(3*INERV+1)\n ALEFT=Y(3*INERV+2)\n BLEFT=Y(3*INERV+3)\n END IF \n XDOT=-10000.D0*(B+X*(A+X*X))\n U=(X-0.7D0)*(X-1.3D0)\n V=U/(U+0.1D0)\n ADOT=B+0.07D0*V\n BDOT=(1.D0*(1.D0-A*A)*B-A)-0.4D0*X+0.035D0*V\n F(3*INERV-2)=XDOT+DIFFUS*(XLEFT-2.D0*X+XRIGHT)\n F(3*INERV-1)=ADOT+DIFFUS*(ALEFT-2.D0*A+ARIGHT)\n F(3*INERV) =BDOT+DIFFUS*(BLEFT-2.D0*B+BRIGHT)\n 25 CONTINUE\n RETURN\n END\n\n", "meta": {"hexsha": "34bcb59fd966d0a87d7e363c67c067739d966b53", "size": 1160, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/cusp_equation.f", "max_stars_repo_name": "cpmech/hwode", "max_stars_repo_head_hexsha": "7a6c033ace96b8b8dcf564ba0f38dd501fe2f60d", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tests/cusp_equation.f", "max_issues_repo_name": "cpmech/hwode", "max_issues_repo_head_hexsha": "7a6c033ace96b8b8dcf564ba0f38dd501fe2f60d", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/cusp_equation.f", "max_forks_repo_name": "cpmech/hwode", "max_forks_repo_head_hexsha": "7a6c033ace96b8b8dcf564ba0f38dd501fe2f60d", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.619047619, "max_line_length": 54, "alphanum_fraction": 0.4724137931, "num_tokens": 469, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480248488136, "lm_q2_score": 0.7606506418255928, "lm_q1q2_score": 0.6986425905166307}} {"text": "\n subroutine gaussv(E, n, mean, stdev)\nC This function darws n indipendent Gaussian random numbers, \nC with mean 'mean' and standard deviation 'stdev' and puts\nC the numbers in the E array\n integer n\n real*8 E(n), mean, stdev, gauss\nC write (*,*) 'n = ', n, ' m = ', m\nC write (*,*) 'stdev = ', stdev, ' mean = ', mean\n\n do i = 1, n\n E(i) = gauss(mean, stdev)\nC write(*,*) 'E=',E(i)\n enddo\n return \n end\n\n subroutine beamv(u, n, F, L, E, I)\n integer n, j\n real*8 E(n), u(n), F, L, I\nc End deflection of a cantilever beam\n do j = 1, n\n u(j) = (F*L**3)/(3*E(j)*I)\n enddo\n end\n", "meta": {"hexsha": "aeb6284369ba042ff84d10843b3ac1c06d8cdac0", "size": 686, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "sandbox/src1/TCSE3-3rd-examples/src/misc/mc.f", "max_stars_repo_name": "sniemi/SamPy", "max_stars_repo_head_hexsha": "e048756feca67197cf5f995afd7d75d8286e017b", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2016-05-28T14:12:28.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-22T10:23:12.000Z", "max_issues_repo_path": "sandbox/src1/TCSE3-3rd-examples/src/misc/mc.f", "max_issues_repo_name": "sniemi/SamPy", "max_issues_repo_head_hexsha": "e048756feca67197cf5f995afd7d75d8286e017b", "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": "sandbox/src1/TCSE3-3rd-examples/src/misc/mc.f", "max_forks_repo_name": "sniemi/SamPy", "max_forks_repo_head_hexsha": "e048756feca67197cf5f995afd7d75d8286e017b", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2015-07-13T10:04:10.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-22T10:23:23.000Z", "avg_line_length": 26.3846153846, "max_line_length": 65, "alphanum_fraction": 0.5058309038, "num_tokens": 237, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.921921841290738, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6986271871281675}} {"text": "FUNCTION erf(x)\r\nREAL*8 erf,x\r\n! USES gammp\r\nREAL*8,EXTERNAL :: gammp\r\nif(x.lt.0.)then\r\n\terf=-gammp(0.5d0,x**2)\r\nelse\r\n\terf=gammp(0.5d0,x**2)\r\nendif\r\nreturn\r\nEND\r\n", "meta": {"hexsha": "deb5f80132a72bcf30bd860410679aeb8613fcc1", "size": 163, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "11/mathlib/erf.f90", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "11/mathlib/erf.f90", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "11/mathlib/erf.f90", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 13.5833333333, "max_line_length": 25, "alphanum_fraction": 0.6380368098, "num_tokens": 73, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9219218262741297, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6986271707057725}} {"text": "!*******************************************************************************\n!> author: Jacob Williams\n!\n! Test for the [[slsqp_module]].\n!\n! This is problem 71 from the Hock-Schittkowsky test suite:\n!\n!```\n! min x1*x4*(x1 + x2 + x3) + x3\n! s.t. x1*x2*x3*x4 - x5 - 25 = 0\n! x1**2 + x2**2 + x3**2 + x4**2 - 40 = 0\n! 1 <= x1,x2,x3,x4 <= 5\n! 0 <= x5\n!\n! Starting point:\n! x = (1, 5, 5, 1, -24)\n!\n! Optimal solution:\n! x = (1.00000000, 4.74299963, 3.82114998, 1.37940829, 0)\n!```\n\n program slsqp_test_71\n\n use slsqp_module\n use slsqp_kinds\n\n implicit none\n\n integer,parameter :: n = 5 !! number of optimization variables\n integer,parameter :: m = 2 !! total number of constraints\n integer,parameter :: meq = 2 !! number of equality constraints\n integer,parameter :: max_iter = 100 !! maximum number of allowed iterations\n real(wp),dimension(n),parameter :: xl = [1.0_wp, 1.0_wp, 1.0_wp, 1.0_wp, 0.0_wp] !! lower bounds\n real(wp),dimension(n),parameter :: xu = [5.0_wp, 5.0_wp, 5.0_wp, 5.0_wp, 1.0e10_wp] !! upper bounds\n real(wp),parameter :: acc = 1.0e-8_wp !! tolerance\n integer,parameter :: linesearch_mode = 1 !! use inexact linesearch.\n\n type(slsqp_solver) :: solver !! instantiate an slsqp solver\n real(wp),dimension(n) :: x !! optimization variable vector\n integer :: istat !! for solver status check\n logical :: status_ok !! for initialization status check\n integer :: iterations !! number of iterations by the solver\n\n x = [1.0_wp, 5.0_wp, 5.0_wp, 1.0_wp, -24.0_wp] !initial guess\n\n call solver%initialize(n,m,meq,max_iter,acc,func,grad,&\n xl,xu,linesearch_mode=linesearch_mode,&\n status_ok=status_ok,&\n report=report_iteration)\n\n if (status_ok) then\n call solver%optimize(x,istat,iterations)\n write(*,*) ''\n write(*,*) 'solution :', x\n write(*,*) 'istat :', istat\n write(*,*) 'iterations :', iterations\n write(*,*) ''\n else\n error stop 'error calling slsqp.'\n end if\n\n contains\n\n subroutine func(me,x,f,c)\n\n implicit none\n class(slsqp_solver),intent(inout) :: me\n real(wp),dimension(:),intent(in) :: x !! optimization variable vector\n real(wp),intent(out) :: f !! value of the objective function\n real(wp),dimension(:),intent(out) :: c !! the constraint vector `dimension(m)`,\n !! equality constraints (if any) first.\n\n f = x(1)*x(4)*(x(1)+x(2)+x(3)) + x(3)\n\n c(1) = x(1)*x(2)*x(3)*x(4) - x(5) - 25.0_wp\n c(2) = x(1)**2 + x(2)**2 + x(3)**2 + x(4)**2 - 40.0_wp\n\n end subroutine func\n\n subroutine grad(me,x,g,a)\n !! gradients for [[func]].\n implicit none\n class(slsqp_solver),intent(inout) :: me\n real(wp),dimension(:),intent(in) :: x !! optimization variable vector\n real(wp),dimension(:),intent(out) :: g !! objective function partials w.r.t x `dimension(n)`\n real(wp),dimension(:,:),intent(out) :: a !! gradient matrix of constraints w.r.t. x `dimension(m,n)`\n\n g(1) = x(4)*(2.0_wp*x(1)+x(2)+x(3))\n g(2) = x(1)*x(4)\n g(3) = x(1)*x(4) + 1.0_wp\n g(4) = x(1)*(x(1)+x(2)+x(3))\n g(5) = 0.0_wp\n\n a = 0.0_wp\n a(1,1) = x(2)*x(3)*x(4)\n a(1,2) = x(1)*x(3)*x(4)\n a(1,3) = x(1)*x(2)*x(4)\n a(1,4) = x(1)*x(2)*x(3)\n a(1,5) = -1.0_wp\n a(2,1) = 2.0_wp*x(1)\n a(2,2) = 2.0_wp*x(2)\n a(2,3) = 2.0_wp*x(3)\n a(2,4) = 2.0_wp*x(4)\n\n end subroutine grad\n\n subroutine report_iteration(me,iter,x,f,c)\n use, intrinsic :: iso_fortran_env, only: output_unit\n !! report an iteration (print to the console).\n implicit none\n class(slsqp_solver),intent(inout) :: me\n integer,intent(in) :: iter\n real(wp),dimension(:),intent(in) :: x\n real(wp),intent(in) :: f\n real(wp),dimension(:),intent(in) :: c\n\n !write a header:\n if (iter==0) then\n write(output_unit,'(*(A20,1X))') 'iteration', 'x(1)', 'x(2)', 'x(3)', 'x(4)', 'x(5)', 'f', 'c(1)', 'c(2)'\n end if\n\n !write the iteration data:\n write(output_unit,'(I20,1X,(*(F20.16,1X)))') iter,x,f,c\n\n end subroutine report_iteration\n\n end program slsqp_test_71\n!*******************************************************************************", "meta": {"hexsha": "8e0ec4a41866bc88f6743da2b7ee9d7843363b1c", "size": 4815, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/slsqp_test_71.f90", "max_stars_repo_name": "LKedward/slsqp", "max_stars_repo_head_hexsha": "163628e77d5de6d8647c6f44d2bf9cdf9dbb04f2", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 52, "max_stars_repo_stars_event_min_datetime": "2016-01-12T17:41:53.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-30T09:38:15.000Z", "max_issues_repo_path": "src/tests/slsqp_test_71.f90", "max_issues_repo_name": "LKedward/slsqp", "max_issues_repo_head_hexsha": "163628e77d5de6d8647c6f44d2bf9cdf9dbb04f2", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 20, "max_issues_repo_issues_event_min_datetime": "2018-03-14T21:58:16.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-26T15:19:49.000Z", "max_forks_repo_path": "src/tests/slsqp_test_71.f90", "max_forks_repo_name": "LKedward/slsqp", "max_forks_repo_head_hexsha": "163628e77d5de6d8647c6f44d2bf9cdf9dbb04f2", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2016-03-28T10:37:10.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-05T06:33:41.000Z", "avg_line_length": 37.6171875, "max_line_length": 117, "alphanum_fraction": 0.4878504673, "num_tokens": 1523, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.90192067652954, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.6986127792610435}} {"text": "c \nc uses de Casteljau to compute one coordinate\nc value of a Bezier curve. Has to be called \nc for each coordinate (x,y, and/or z) of a control polygon.\nc Input: degree: degree of curve.\nc coeff: array with coefficients of curve.\nc t: parameter value.\nc Output: coordinate value.\n real function decas(degree, coeff, t)\n implicit none\n integer degree\n real coeff(*), t\n\n integer r, i\n real t1\nc an auxiliary array. Change dim. if too small\n real coeffa(0:100)\n\n t1 = 1.0 - t;\n coeffa(0:degree) = coeff(1:degree+1)\n\n do r=1,degree\n do i=0,degree-r\n coeffa(i)= t1* coeffa(i) + t * coeffa(i+1)\n enddo\n enddo \n\n decas = coeffa(0)\n\n end\n", "meta": {"hexsha": "660762826ca0e6dc24d3e4628382198c088f344f", "size": 791, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "nuwtun_solver/src-grd/decas.f", "max_stars_repo_name": "kjetil-lye/ismo_airfoil", "max_stars_repo_head_hexsha": "15ade704a875007e8c5417dcbb9365a455e76ff5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-08-01T22:48:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-01T22:48:44.000Z", "max_issues_repo_path": "nuwtun_solver/src-grd/decas.f", "max_issues_repo_name": "kjetil-lye/ismo_airfoil", "max_issues_repo_head_hexsha": "15ade704a875007e8c5417dcbb9365a455e76ff5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2020-11-13T19:02:05.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-12T00:46:18.000Z", "max_forks_repo_path": "nuwtun_solver/src-grd/decas.f", "max_forks_repo_name": "kjetil-lye/ismo_airfoil", "max_forks_repo_head_hexsha": "15ade704a875007e8c5417dcbb9365a455e76ff5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-12-07T04:28:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-26T06:53:11.000Z", "avg_line_length": 25.5161290323, "max_line_length": 63, "alphanum_fraction": 0.5600505689, "num_tokens": 238, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850110816423, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6985987606435942}} {"text": "\tFUNCTION PR_PLCL ( tmpc, pres, tlcl )\nC************************************************************************\nC* PR_PLCL \t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes PLCL from TMPC, PRES, and TLCL for an air\t*\nC* parcel. TMPC and PRES refer to the parcel before lifting, while\t*\nC* TLCL is the temperature at the LCL. TLCL may be computed using\t*\nC* PR_TLCL. The equation used is a modified Poisson equation:\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* PLCL = PRES * ( TLCL / TMPK ) ** ( 1 / RKAPPA )\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PR_PLCL ( TMPC, PRES, TLCL )\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*\tPRES\t\tREAL\t\tPressure in millibars\t\t*\nC*\tTLCL \t\tREAL \tLCL temperature in Kelvin\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPR_PLCL\t\tREAL\t\tLCL 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* M. Goodman/RDS\t8/84\tOriginal source\t\t\t\t*\nC* I. Graffman/RDS\t12/87\tGEMPAK4\t\t\t\t\t*\nC* G. Huffman/GSC\t7/88\tDocumentation\t\t\t\t*\nC************************************************************************\n INCLUDE 'GEMPRM.PRM'\n INCLUDE 'ERMISS.FNC'\nC------------------------------------------------------------------------\nC*\tCheck for missing data.\nC\n\tIF ( ERMISS ( pres ) .or. ERMISS ( tmpc ) .or.\n +\t ERMISS ( tlcl ) ) THEN\n\t PR_PLCL = RMISSD\n\t ELSE\n\t tmpk = PR_TMCK (tmpc)\n\t PR_PLCL = pres * (tlcl / tmpk) ** (1 / RKAPPA)\n\tEND IF\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "eba4c2c36db100e3b321c5c7f5128cc5123494ec", "size": 1446, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/pr/prplcl.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/prplcl.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/prplcl.f", "max_forks_repo_name": "oxelson/gempak", "max_forks_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 27, "max_forks_repo_forks_event_min_datetime": "2016-06-06T21:55:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T18:23:28.000Z", "avg_line_length": 34.4285714286, "max_line_length": 73, "alphanum_fraction": 0.4854771784, "num_tokens": 455, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850057480346, "lm_q2_score": 0.7461389873857265, "lm_q1q2_score": 0.6985987460932777}} {"text": "!\n! slatec_3j_f90.f90\n! slatec.git\n!\n! This file contains an extract of the huge Slatec library that allows the user\n! to compute just the 3J and 6J Wigner Symbols (which are closely related to the\n! Clebsch-Gordan and Racah W-coefficients, respectively), the Airy functions and\n! the Bessel functions, both regular and spherical.\n!\n! This is part the Fortran90 version of the SLATEC library, which was kindly\n! ported from the Fortran77 original by John Burkardt, which I thank. The F90\n! port can be found at http://people.sc.fsu.edu/~jburkardt/f_src/slatec/slatec.html,\n! while the original F77 version is hosted on Netlib:\n! http://www.netlib.org/slatec/index.html\n\n\nsubroutine DRC3JM (L1, L2, L3, M1, M2MIN, M2MAX, THRCOF, NDIM, &\n IER)\n!\n!! DRC3JM evaluates the 3j symbol g(M2) for all allowed values of M2.\n!\n!***PURPOSE Evaluate the 3j symbol g(M2) = (L1 L2 L3 )\n! (M1 M2 -M1-M2)\n! for all allowed values of M2, the other parameters\n! being held fixed.\n!\n!***LIBRARY SLATEC\n!***CATEGORY C19\n!***TYPE DOUBLE PRECISION (RC3JM-S, DRC3JM-D)\n!***KEYWORDS 3J COEFFICIENTS, 3J SYMBOLS, CLEBSCH-GORDAN COEFFICIENTS,\n! RACAH COEFFICIENTS, VECTOR ADDITION COEFFICIENTS,\n! WIGNER COEFFICIENTS\n!***AUTHOR Gordon, R. G., Harvard University\n! Schulten, K., Max Planck Institute\n!***DESCRIPTION\n!\n! *Usage:\n!\n! DOUBLE PRECISION L1, L2, L3, M1, M2MIN, M2MAX, THRCOF(NDIM)\n! INTEGER NDIM, IER\n!\n! call DRC3JM (L1, L2, L3, M1, M2MIN, M2MAX, THRCOF, NDIM, IER)\n!\n! *Arguments:\n!\n! L1 :IN Parameter in 3j symbol.\n!\n! L2 :IN Parameter in 3j symbol.\n!\n! L3 :IN Parameter in 3j symbol.\n!\n! M1 :IN Parameter in 3j symbol.\n!\n! M2MIN :OUT Smallest allowable M2 in 3j symbol.\n!\n! M2MAX :OUT Largest allowable M2 in 3j symbol.\n!\n! THRCOF :OUT Set of 3j coefficients generated by evaluating the\n! 3j symbol for all allowed values of M2. THRCOF(I)\n! will contain g(M2MIN+I-1), I=1,2,...,M2MAX-M2MIN+1.\n!\n! NDIM :IN Declared length of THRCOF in calling program.\n!\n! IER :OUT Error flag.\n! IER=0 No errors.\n! IER=1 Either L1 < ABS(M1) or L1+ABS(M1) non-integer.\n! IER=2 ABS(L1-L2) <= L3 <= L1+L2 not satisfied.\n! IER=3 L1+L2+L3 not an integer.\n! IER=4 M2MAX-M2MIN not an integer.\n! IER=5 M2MAX less than M2MIN.\n! IER=6 NDIM less than M2MAX-M2MIN+1.\n!\n! *Description:\n!\n! Although conventionally the parameters of the vector addition\n! coefficients satisfy certain restrictions, such as being integers\n! or integers plus 1/2, the restrictions imposed on input to this\n! subroutine are somewhat weaker. See, for example, Section 27.9 of\n! Abramowitz and Stegun or Appendix C of Volume II of A. Messiah.\n! The restrictions imposed by this subroutine are\n! 1. L1 >= ABS(M1) and L1+ABS(M1) must be an integer;\n! 2. ABS(L1-L2) <= L3 <= L1+L2;\n! 3. L1+L2+L3 must be an integer;\n! 4. M2MAX-M2MIN must be an integer, where\n! M2MAX=MIN(L2,L3-M1) and M2MIN=MAX(-L2,-L3-M1).\n! If the conventional restrictions are satisfied, then these\n! restrictions are met.\n!\n! The user should be cautious in using input parameters that do\n! not satisfy the conventional restrictions. For example, the\n! the subroutine produces values of\n! g(M2) = (0.751.50 1.75 )\n! (0.25 M2 -0.25-M2)\n! for M2=-1.5,-0.5,0.5,1.5 but none of the symmetry properties of the\n! 3j symbol, set forth on page 1056 of Messiah, is satisfied.\n!\n! The subroutine generates g(M2MIN), g(M2MIN+1), ..., g(M2MAX)\n! where M2MIN and M2MAX are defined above. The sequence g(M2) is\n! generated by a three-term recurrence algorithm with scaling to\n! control overflow. Both backward and forward recurrence are used to\n! maintain numerical stability. The two recurrence sequences are\n! matched at an interior point and are normalized from the unitary\n! property of 3j coefficients and Wigner's phase convention.\n!\n! The algorithm is suited to applications in which large quantum\n! numbers arise, such as in molecular dynamics.\n!\n!***REFERENCES 1. Abramowitz, M., and Stegun, I. A., Eds., Handbook\n! of Mathematical Functions with Formulas, Graphs\n! and Mathematical Tables, NBS Applied Mathematics\n! Series 55, June 1964 and subsequent printings.\n! 2. Messiah, Albert., Quantum Mechanics, Volume II,\n! North-Holland Publishing Company, 1963.\n! 3. Schulten, Klaus and Gordon, Roy G., Exact recursive\n! evaluation of 3j and 6j coefficients for quantum-\n! mechanical coupling of angular momenta, J Math\n! Phys, v 16, no. 10, October 1975, pp. 1961-1970.\n! 4. Schulten, Klaus and Gordon, Roy G., Semiclassical\n! approximations to 3j and 6j coefficients for\n! quantum-mechanical coupling of angular momenta,\n! J Math Phys, v 16, no. 10, October 1975,\n! pp. 1971-1988.\n! 5. Schulten, Klaus and Gordon, Roy G., Recursive\n! evaluation of 3j and 6j coefficients, Computer\n! Phys Comm, v 11, 1976, pp. 269-278.\n!***ROUTINES CALLED D1MACH, XERMSG\n!***REVISION HISTORY (YYMMDD)\n! 750101 DATE WRITTEN\n! 880515 SLATEC prologue added by G. C. Nielson, NBS; parameters\n! HUGE and TINY revised to depend on D1MACH.\n! 891229 Prologue description rewritten; other prologue sections\n! revised; MMATCH (location of match point for recurrences)\n! removed from argument list; argument IER changed to serve\n! only as an error flag (previously, in cases without error,\n! it returned the number of scalings); number of error codes\n! increased to provide more precise error information;\n! program comments revised; SLATEC error handler calls\n! introduced to enable printing of error messages to meet\n! SLATEC standards. These changes were done by D. W. Lozier,\n! M. A. McClain and J. M. Smith of the National Institute\n! of Standards and Technology, formerly NBS.\n! 910415 Mixed type expressions eliminated; variable C1 initialized;\n! description of THRCOF expanded. These changes were done by\n! D. W. Lozier.\n!***END PROLOGUE DRC3JM\n!\n INTEGER NDIM, IER\n DOUBLE PRECISION L1, L2, L3, M1, M2MIN, M2MAX, THRCOF(NDIM)\n!\n INTEGER I, INDEX, LSTEP, N, NFIN, NFINP1, NFINP2, NFINP3, NLIM, &\n NSTEP2\n DOUBLE PRECISION A1, A1S, C1, C1OLD, C2, CNORM, D1MACH, DV, EPS, &\n HUGE, M2, M3, NEWFAC, OLDFAC, ONE, RATIO, SIGN1, &\n SIGN2, SRHUGE, SRTINY, SUM1, SUM2, SUMBAC, &\n SUMFOR, SUMUNI, THRESH, TINY, TWO, X, X1, X2, X3, &\n Y, Y1, Y2, Y3, ZERO\n!\n DATA ZERO,EPS,ONE,TWO /0.0D0,0.01D0,1.0D0,2.0D0/\n\n\t!! Debug\n\t! print*, \"PARAMETERS FOR FUNCTION DRC3JM\"\n\t! print*, \"L1\", L1\n\t! print*, \"L2\", L2\n\t! print*, \"L3\", L3\t\n\t! print*, \"M1\", M1\n\t! print*, \"NDIM\", NDIM\n\t\t\n!***FIRST EXECUTABLE STATEMENT DRC3JM\n IER=0\n! HUGE is the square root of one twentieth of the largest floating\n! point number, approximately.\n HUGE = SQRT(D1MACH(2)/20.0D0)\n SRHUGE = SQRT(HUGE)\n TINY = 1.0D0/HUGE\n SRTINY = 1.0D0/SRHUGE\n!\n!\n! Limits for M2\n M2MIN = MAX(-L2,-L3-M1)\n M2MAX = MIN(L2,L3-M1)\n\t!! Debug\n\t! print*, \"M2MIN\", M2MIN\n\t! print*, \"M2MAX\", M2MAX\n!\n!\n!\n! Check error conditions 1, 2, and 3.\n if ( (L1-ABS(M1)+EPS < ZERO).OR. &\n (MOD(L1+ABS(M1)+EPS,ONE) >= EPS+EPS))THEN\n IER=1\n\t print*, \"Exited with ier = \", IER\n ! call XERMSG('SLATEC','DRC3JM','L1-ABS(M1) less than zero or '// &\n ! 'L1+ABS(M1) not integer.',IER,1)\n return\n ELSEIF((L1+L2-L3 < -EPS).OR.(L1-L2+L3 < -EPS).OR. &\n (-L1+L2+L3 < -EPS))THEN\n IER=2\n\t print*, \"Exited with ier = \", IER\n ! call XERMSG('SLATEC','DRC3JM','L1, L2, L3 do not satisfy '// &\n ! 'triangular condition.',IER,1)\n return\n ELSEIF(MOD(L1+L2+L3+EPS,ONE) >= EPS+EPS)THEN\n IER=3\n\t print*, \"Exited with ier = \", IER\n ! call XERMSG('SLATEC','DRC3JM','L1+L2+L3 not integer.',IER,1)\n return\n end if\n\n\n\n! Check error condition 4.\n if ( MOD(M2MAX-M2MIN+EPS,ONE) >= EPS+EPS)THEN\n IER=4\n\t print*, \"Exited with ier = \", IER\n ! call XERMSG('SLATEC','DRC3JM','M2MAX-M2MIN not integer.',IER,1)\n return\n end if\n if ( M2MIN < M2MAX-EPS) go to 20\n if ( M2MIN < M2MAX+EPS) go to 10\n!\n! Check error condition 5.\n IER=5\n print*, \"Exited with ier = \", IER\n ! call XERMSG('SLATEC','DRC3JM','M2MIN greater than M2MAX.',IER,1)\n return\n!\n!\n! This is reached in case that M2 and M3 can take only one value.\n 10 CONTINUE\n! MSCALE = 0\n THRCOF(1) = (-ONE) ** INT(ABS(L2-L3-M1)+EPS) / &\n SQRT(L1+L2+L3+ONE)\n return\n!\n! This is reached in case that M1 and M2 take more than one value.\n 20 CONTINUE\n! MSCALE = 0\n NFIN = INT(M2MAX-M2MIN+ONE+EPS)\n\t! print*, \"NDIM =\", NDIM, \"NFIN = \", NFIN\n\t! print*, \"M2MAX = \", M2MAX, \"M2MIN = \", M2MIN, \"ONE = \", ONE, \"EPS = \", EPS, \"M2MAX-M2MIN+ONE+EPS\", M2MAX-M2MIN+ONE+EPS\n if ( NDIM-NFIN) 21, 23, 23\n!\n! Check error condition 6.\n 21 IER = 6\n print*, \"Exited with ier = \", IER\n ! call XERMSG('SLATEC','DRC3JM','Dimension of result array for '// &\n ! '3j coefficients too small.',IER,1)\n return\n!\n!\n!\n! Start of forward recursion from M2 = M2MIN\n!\n 23 M2 = M2MIN\n THRCOF(1) = SRTINY\n NEWFAC = 0.0D0\n C1 = 0.0D0\n SUM1 = TINY\n!\n!\n LSTEP = 1\n 30 LSTEP = LSTEP + 1\n M2 = M2 + ONE\n M3 = - M1 - M2\n!\n!\n OLDFAC = NEWFAC\n A1 = (L2-M2+ONE) * (L2+M2) * (L3+M3+ONE) * (L3-M3)\n NEWFAC = SQRT(A1)\n!\n!\n DV = (L1+L2+L3+ONE)*(L2+L3-L1) - (L2-M2+ONE)*(L3+M3+ONE) &\n - (L2+M2-ONE)*(L3-M3-ONE)\n!\n if ( LSTEP-2) 32, 32, 31\n!\n 31 C1OLD = ABS(C1)\n 32 C1 = - DV / NEWFAC\n!\n if ( LSTEP > 2) go to 60\n!\n!\n! If M2 = M2MIN + 1, the third term in the recursion equation vanishes,\n! hence\n!\n X = SRTINY * C1\n THRCOF(2) = X\n SUM1 = SUM1 + TINY * C1*C1\n if ( LSTEP == NFIN) go to 220\n go to 30\n!\n!\n 60 C2 = - OLDFAC / NEWFAC\n!\n! Recursion to the next 3j coefficient\n X = C1 * THRCOF(LSTEP-1) + C2 * THRCOF(LSTEP-2)\n THRCOF(LSTEP) = X\n SUMFOR = SUM1\n SUM1 = SUM1 + X*X\n if ( LSTEP == NFIN) go to 100\n!\n! See if last unnormalized 3j coefficient exceeds SRHUGE\n!\n if ( ABS(X) < SRHUGE) go to 80\n!\n! This is reached if last 3j coefficient larger than SRHUGE,\n! so that the recursion series THRCOF(1), ... , THRCOF(LSTEP)\n! has to be rescaled to prevent overflow\n!\n! MSCALE = MSCALE + 1\n DO 70 I=1,LSTEP\n if ( ABS(THRCOF(I)) < SRTINY) THRCOF(I) = ZERO\n 70 THRCOF(I) = THRCOF(I) / SRHUGE\n SUM1 = SUM1 / HUGE\n SUMFOR = SUMFOR / HUGE\n X = X / SRHUGE\n!\n!\n! As long as ABS(C1) is decreasing, the recursion proceeds towards\n! increasing 3j values and, hence, is numerically stable. Once\n! an increase of ABS(C1) is detected, the recursion direction is\n! reversed.\n!\n 80 if ( C1OLD-ABS(C1)) 100, 100, 30\n!\n!\n! Keep three 3j coefficients around MMATCH for comparison later\n! with backward recursion values.\n!\n 100 CONTINUE\n! MMATCH = M2 - 1\n NSTEP2 = NFIN - LSTEP + 3\n X1 = X\n X2 = THRCOF(LSTEP-1)\n X3 = THRCOF(LSTEP-2)\n!\n! Starting backward recursion from M2MAX taking NSTEP2 steps, so\n! that forwards and backwards recursion overlap at the three points\n! M2 = MMATCH+1, MMATCH, MMATCH-1.\n!\n NFINP1 = NFIN + 1\n NFINP2 = NFIN + 2\n NFINP3 = NFIN + 3\n THRCOF(NFIN) = SRTINY\n SUM2 = TINY\n!\n!\n!\n M2 = M2MAX + TWO\n LSTEP = 1\n 110 LSTEP = LSTEP + 1\n M2 = M2 - ONE\n M3 = - M1 - M2\n OLDFAC = NEWFAC\n A1S = (L2-M2+TWO) * (L2+M2-ONE) * (L3+M3+TWO) * (L3-M3-ONE)\n NEWFAC = SQRT(A1S)\n DV = (L1+L2+L3+ONE)*(L2+L3-L1) - (L2-M2+ONE)*(L3+M3+ONE) &\n - (L2+M2-ONE)*(L3-M3-ONE)\n C1 = - DV / NEWFAC\n if ( LSTEP > 2) go to 120\n!\n! If M2 = M2MAX + 1 the third term in the recursion equation vanishes\n!\n Y = SRTINY * C1\n THRCOF(NFIN-1) = Y\n if ( LSTEP == NSTEP2) go to 200\n SUMBAC = SUM2\n SUM2 = SUM2 + Y*Y\n go to 110\n!\n 120 C2 = - OLDFAC / NEWFAC\n!\n! Recursion to the next 3j coefficient\n!\n Y = C1 * THRCOF(NFINP2-LSTEP) + C2 * THRCOF(NFINP3-LSTEP)\n!\n if ( LSTEP == NSTEP2) go to 200\n!\n THRCOF(NFINP1-LSTEP) = Y\n SUMBAC = SUM2\n SUM2 = SUM2 + Y*Y\n!\n!\n! See if last 3j coefficient exceeds SRHUGE\n!\n if ( ABS(Y) < SRHUGE) go to 110\n!\n! This is reached if last 3j coefficient larger than SRHUGE,\n! so that the recursion series THRCOF(NFIN), ... , THRCOF(NFIN-LSTEP+1)\n! has to be rescaled to prevent overflow.\n!\n! MSCALE = MSCALE + 1\n DO 111 I=1,LSTEP\n INDEX = NFIN - I + 1\n if ( ABS(THRCOF(INDEX)) < SRTINY) &\n THRCOF(INDEX) = ZERO\n 111 THRCOF(INDEX) = THRCOF(INDEX) / SRHUGE\n SUM2 = SUM2 / HUGE\n SUMBAC = SUMBAC / HUGE\n!\n go to 110\n!\n!\n!\n! The forward recursion 3j coefficients X1, X2, X3 are to be matched\n! with the corresponding backward recursion values Y1, Y2, Y3.\n!\n 200 Y3 = Y\n Y2 = THRCOF(NFINP2-LSTEP)\n Y1 = THRCOF(NFINP3-LSTEP)\n!\n!\n! Determine now RATIO such that YI = RATIO * XI (I=1,2,3) holds\n! with minimal error.\n!\n RATIO = ( X1*Y1 + X2*Y2 + X3*Y3 ) / ( X1*X1 + X2*X2 + X3*X3 )\n NLIM = NFIN - NSTEP2 + 1\n!\n if ( ABS(RATIO) < ONE) go to 211\n!\n DO 210 N=1,NLIM\n 210 THRCOF(N) = RATIO * THRCOF(N)\n SUMUNI = RATIO * RATIO * SUMFOR + SUMBAC\n go to 230\n!\n 211 NLIM = NLIM + 1\n RATIO = ONE / RATIO\n DO 212 N=NLIM,NFIN\n 212 THRCOF(N) = RATIO * THRCOF(N)\n SUMUNI = SUMFOR + RATIO*RATIO*SUMBAC\n go to 230\n!\n 220 SUMUNI = SUM1\n!\n!\n! Normalize 3j coefficients\n!\n 230 CNORM = ONE / SQRT((L1+L1+ONE) * SUMUNI)\n!\n! Sign convention for last 3j coefficient determines overall phase\n!\n SIGN1 = SIGN(ONE,THRCOF(NFIN))\n SIGN2 = (-ONE) ** INT(ABS(L2-L3-M1)+EPS)\n if ( SIGN1*SIGN2) 235,235,236\n 235 CNORM = - CNORM\n!\n 236 if ( ABS(CNORM) < ONE) go to 250\n!\n DO 240 N=1,NFIN\n 240 THRCOF(N) = CNORM * THRCOF(N)\n return\n!\n 250 THRESH = TINY / ABS(CNORM)\n DO 251 N=1,NFIN\n if ( ABS(THRCOF(N)) < THRESH) THRCOF(N) = ZERO\n 251 THRCOF(N) = CNORM * THRCOF(N)\n!\n!\n!\n return\nend\n\n\n\n\n\nsubroutine DRC3JJ (L2, L3, M2, M3, L1MIN, L1MAX, THRCOF, NDIM, &\n IER)\n!\n!! DRC3JJ evaluates the 3J symbol f(L1) for all allowed values of L1.\n!\n!***PURPOSE Evaluate the 3j symbol f(L1) = ( L1 L2 L3)\n! (-M2-M3 M2 M3)\n! for all allowed values of L1, the other parameters\n! being held fixed.\n!\n!***LIBRARY SLATEC\n!***CATEGORY C19\n!***TYPE DOUBLE PRECISION (RC3JJ-S, DRC3JJ-D)\n!***KEYWORDS 3J COEFFICIENTS, 3J SYMBOLS, CLEBSCH-GORDAN COEFFICIENTS,\n! RACAH COEFFICIENTS, VECTOR ADDITION COEFFICIENTS,\n! WIGNER COEFFICIENTS\n!***AUTHOR Gordon, R. G., Harvard University\n! Schulten, K., Max Planck Institute\n!***DESCRIPTION\n!\n! *Usage:\n!\n! DOUBLE PRECISION L2, L3, M2, M3, L1MIN, L1MAX, THRCOF(NDIM)\n! INTEGER NDIM, IER\n!\n! call DRC3JJ (L2, L3, M2, M3, L1MIN, L1MAX, THRCOF, NDIM, IER)\n!\n! *Arguments:\n!\n! L2 :IN Parameter in 3j symbol.\n!\n! L3 :IN Parameter in 3j symbol.\n!\n! M2 :IN Parameter in 3j symbol.\n!\n! M3 :IN Parameter in 3j symbol.\n!\n! L1MIN :OUT Smallest allowable L1 in 3j symbol.\n!\n! L1MAX :OUT Largest allowable L1 in 3j symbol.\n!\n! THRCOF :OUT Set of 3j coefficients generated by evaluating the\n! 3j symbol for all allowed values of L1. THRCOF(I)\n! will contain f(L1MIN+I-1), I=1,2,...,L1MAX+L1MIN+1.\n!\n! NDIM :IN Declared length of THRCOF in calling program.\n!\n! IER :OUT Error flag.\n! IER=0 No errors.\n! IER=1 Either L2 < ABS(M2) or L3 < ABS(M3).\n! IER=2 Either L2+ABS(M2) or L3+ABS(M3) non-integer.\n! IER=3 L1MAX-L1MIN not an integer.\n! IER=4 L1MAX less than L1MIN.\n! IER=5 NDIM less than L1MAX-L1MIN+1.\n!\n! *Description:\n!\n! Although conventionally the parameters of the vector addition\n! coefficients satisfy certain restrictions, such as being integers\n! or integers plus 1/2, the restrictions imposed on input to this\n! subroutine are somewhat weaker. See, for example, Section 27.9 of\n! Abramowitz and Stegun or Appendix C of Volume II of A. Messiah.\n! The restrictions imposed by this subroutine are\n! 1. L2 >= ABS(M2) and L3 >= ABS(M3);\n! 2. L2+ABS(M2) and L3+ABS(M3) must be integers;\n! 3. L1MAX-L1MIN must be a non-negative integer, where\n! L1MAX=L2+L3 and L1MIN=MAX(ABS(L2-L3),ABS(M2+M3)).\n! If the conventional restrictions are satisfied, then these\n! restrictions are met.\n!\n! The user should be cautious in using input parameters that do\n! not satisfy the conventional restrictions. For example, the\n! the subroutine produces values of\n! f(L1) = ( L1 2.5 5.8)\n! (-0.31.5 -1.2)\n! for L1=3.3,4.3,...,8.3 but none of the symmetry properties of the 3j\n! symbol, set forth on page 1056 of Messiah, is satisfied.\n!\n! The subroutine generates f(L1MIN), f(L1MIN+1), ..., f(L1MAX)\n! where L1MIN and L1MAX are defined above. The sequence f(L1) is\n! generated by a three-term recurrence algorithm with scaling to\n! control overflow. Both backward and forward recurrence are used to\n! maintain numerical stability. The two recurrence sequences are\n! matched at an interior point and are normalized from the unitary\n! property of 3j coefficients and Wigner's phase convention.\n!\n! The algorithm is suited to applications in which large quantum\n! numbers arise, such as in molecular dynamics.\n!\n!***REFERENCES 1. Abramowitz, M., and Stegun, I. A., Eds., Handbook\n! of Mathematical Functions with Formulas, Graphs\n! and Mathematical Tables, NBS Applied Mathematics\n! Series 55, June 1964 and subsequent printings.\n! 2. Messiah, Albert., Quantum Mechanics, Volume II,\n! North-Holland Publishing Company, 1963.\n! 3. Schulten, Klaus and Gordon, Roy G., Exact recursive\n! evaluation of 3j and 6j coefficients for quantum-\n! mechanical coupling of angular momenta, J Math\n! Phys, v 16, no. 10, October 1975, pp. 1961-1970.\n! 4. Schulten, Klaus and Gordon, Roy G., Semiclassical\n! approximations to 3j and 6j coefficients for\n! quantum-mechanical coupling of angular momenta,\n! J Math Phys, v 16, no. 10, October 1975,\n! pp. 1971-1988.\n! 5. Schulten, Klaus and Gordon, Roy G., Recursive\n! evaluation of 3j and 6j coefficients, Computer\n! Phys Comm, v 11, 1976, pp. 269-278.\n!***ROUTINES CALLED D1MACH, XERMSG\n!***REVISION HISTORY (YYMMDD)\n! 750101 DATE WRITTEN\n! 880515 SLATEC prologue added by G. C. Nielson, NBS; parameters\n! HUGE and TINY revised to depend on D1MACH.\n! 891229 Prologue description rewritten; other prologue sections\n! revised; LMATCH (location of match point for recurrences)\n! removed from argument list; argument IER changed to serve\n! only as an error flag (previously, in cases without error,\n! it returned the number of scalings); number of error codes\n! increased to provide more precise error information;\n! program comments revised; SLATEC error handler calls\n! introduced to enable printing of error messages to meet\n! SLATEC standards. These changes were done by D. W. Lozier,\n! M. A. McClain and J. M. Smith of the National Institute\n! of Standards and Technology, formerly NBS.\n! 910415 Mixed type expressions eliminated; variable C1 initialized;\n! description of THRCOF expanded. These changes were done by\n! D. W. Lozier.\n!***END PROLOGUE DRC3JJ\n!\n INTEGER NDIM, IER\n DOUBLE PRECISION L2, L3, M2, M3, L1MIN, L1MAX, THRCOF(NDIM)\n!\n INTEGER I, INDEX, LSTEP, N, NFIN, NFINP1, NFINP2, NFINP3, NLIM, &\n NSTEP2\n DOUBLE PRECISION A1, A1S, A2, A2S, C1, C1OLD, C2, CNORM, D1MACH, &\n DENOM, DV, EPS, HUGE, L1, M1, NEWFAC, OLDFAC, &\n ONE, RATIO, SIGN1, SIGN2, SRHUGE, SRTINY, SUM1, &\n SUM2, SUMBAC, SUMFOR, SUMUNI, THREE, THRESH, &\n TINY, TWO, X, X1, X2, X3, Y, Y1, Y2, Y3, ZERO\n!\n DATA ZERO,EPS,ONE,TWO,THREE /0.0D0,0.01D0,1.0D0,2.0D0,3.0D0/\n!\n!***FIRST EXECUTABLE STATEMENT DRC3JJ\n IER=0\n! HUGE is the square root of one twentieth of the largest floating\n! point number, approximately.\n HUGE = SQRT(D1MACH(2)/20.0D0)\n SRHUGE = SQRT(HUGE)\n TINY = 1.0D0/HUGE\n SRTINY = 1.0D0/SRHUGE\n!\n! LMATCH = ZERO\n M1 = - M2 - M3\n!\n! Check error conditions 1 and 2.\n if ( (L2-ABS(M2)+EPS < ZERO).OR. &\n (L3-ABS(M3)+EPS < ZERO))THEN\n IER=1\n\t print*, \"Exited with ier = \", IER\n ! call XERMSG('SLATEC','DRC3JJ','L2-ABS(M2) or L3-ABS(M3) '// &\n ! 'less than zero.',IER,1)\n return\n ELSEIF((MOD(L2+ABS(M2)+EPS,ONE) >= EPS+EPS).OR. &\n (MOD(L3+ABS(M3)+EPS,ONE) >= EPS+EPS))THEN\n IER=2\n\t print*, \"Exited with ier = \", IER\n ! call XERMSG('SLATEC','DRC3JJ','L2+ABS(M2) or L3+ABS(M3) '// &\n ! 'not integer.',IER,1)\n return\n end if\n!\n!\n!\n! Limits for L1\n!\n L1MIN = MAX(ABS(L2-L3),ABS(M1))\n L1MAX = L2 + L3\n!\n! Check error condition 3.\n if ( MOD(L1MAX-L1MIN+EPS,ONE) >= EPS+EPS)THEN\n IER=3\n\t print*, \"Exited with ier = \", IER\n ! call XERMSG('SLATEC','DRC3JJ','L1MAX-L1MIN not integer.',IER,1)\n ! return\n end if\n if ( L1MIN < L1MAX-EPS) go to 20\n if ( L1MIN < L1MAX+EPS) go to 10\n!\n! Check error condition 4.\n IER=4\n print*, \"Exited with ier = \", IER\n ! call XERMSG('SLATEC','DRC3JJ','L1MIN greater than L1MAX.',IER,1)\n return\n!\n! This is reached in case that L1 can take only one value,\n! i.e. L1MIN = L1MAX\n!\n 10 CONTINUE\n! LSCALE = 0\n THRCOF(1) = (-ONE) ** INT(ABS(L2+M2-L3+M3)+EPS) / &\n SQRT(L1MIN + L2 + L3 + ONE)\n return\n!\n! This is reached in case that L1 takes more than one value,\n! i.e. L1MIN < L1MAX.\n!\n 20 CONTINUE\n! LSCALE = 0\n NFIN = INT(L1MAX-L1MIN+ONE+EPS)\n if ( NDIM-NFIN) 21, 23, 23\n!\n! Check error condition 5.\n 21 IER = 5\n print*, \"Exited with ier = \", IER\n ! call XERMSG('SLATEC','DRC3JJ','Dimension of result array for '// &\n ! '3j coefficients too small.',IER,1)\n return\n!\n!\n! Starting forward recursion from L1MIN taking NSTEP1 steps\n!\n 23 L1 = L1MIN\n NEWFAC = 0.0D0\n C1 = 0.0D0\n THRCOF(1) = SRTINY\n SUM1 = (L1+L1+ONE) * TINY\n!\n!\n LSTEP = 1\n 30 LSTEP = LSTEP + 1\n L1 = L1 + ONE\n!\n!\n OLDFAC = NEWFAC\n A1 = (L1+L2+L3+ONE) * (L1-L2+L3) * (L1+L2-L3) * (-L1+L2+L3+ONE)\n A2 = (L1+M1) * (L1-M1)\n NEWFAC = SQRT(A1*A2)\n if ( L1 < ONE+EPS) go to 40\n!\n!\n DV = - L2*(L2+ONE) * M1 + L3*(L3+ONE) * M1 + L1*(L1-ONE) * (M3-M2)\n DENOM = (L1-ONE) * NEWFAC\n!\n if ( LSTEP-2) 32, 32, 31\n!\n 31 C1OLD = ABS(C1)\n 32 C1 = - (L1+L1-ONE) * DV / DENOM\n go to 50\n!\n! If L1 = 1, (L1-1) has to be factored out of DV, hence\n!\n 40 C1 = - (L1+L1-ONE) * L1 * (M3-M2) / NEWFAC\n!\n 50 if ( LSTEP > 2) go to 60\n!\n!\n! If L1 = L1MIN + 1, the third term in the recursion equation vanishes,\n! hence\n X = SRTINY * C1\n THRCOF(2) = X\n SUM1 = SUM1 + TINY * (L1+L1+ONE) * C1*C1\n if ( LSTEP == NFIN) go to 220\n go to 30\n!\n!\n 60 C2 = - L1 * OLDFAC / DENOM\n!\n! Recursion to the next 3j coefficient X\n!\n X = C1 * THRCOF(LSTEP-1) + C2 * THRCOF(LSTEP-2)\n THRCOF(LSTEP) = X\n SUMFOR = SUM1\n SUM1 = SUM1 + (L1+L1+ONE) * X*X\n if ( LSTEP == NFIN) go to 100\n!\n! See if last unnormalized 3j coefficient exceeds SRHUGE\n!\n if ( ABS(X) < SRHUGE) go to 80\n!\n! This is reached if last 3j coefficient larger than SRHUGE,\n! so that the recursion series THRCOF(1), ... , THRCOF(LSTEP)\n! has to be rescaled to prevent overflow\n!\n! LSCALE = LSCALE + 1\n DO 70 I=1,LSTEP\n if ( ABS(THRCOF(I)) < SRTINY) THRCOF(I) = ZERO\n 70 THRCOF(I) = THRCOF(I) / SRHUGE\n SUM1 = SUM1 / HUGE\n SUMFOR = SUMFOR / HUGE\n X = X / SRHUGE\n!\n! As long as ABS(C1) is decreasing, the recursion proceeds towards\n! increasing 3j values and, hence, is numerically stable. Once\n! an increase of ABS(C1) is detected, the recursion direction is\n! reversed.\n!\n 80 if ( C1OLD-ABS(C1)) 100, 100, 30\n!\n!\n! Keep three 3j coefficients around LMATCH for comparison with\n! backward recursion.\n!\n 100 CONTINUE\n! LMATCH = L1 - 1\n X1 = X\n X2 = THRCOF(LSTEP-1)\n X3 = THRCOF(LSTEP-2)\n NSTEP2 = NFIN - LSTEP + 3\n!\n!\n!\n!\n! Starting backward recursion from L1MAX taking NSTEP2 steps, so\n! that forward and backward recursion overlap at three points\n! L1 = LMATCH+1, LMATCH, LMATCH-1.\n!\n NFINP1 = NFIN + 1\n NFINP2 = NFIN + 2\n NFINP3 = NFIN + 3\n L1 = L1MAX\n THRCOF(NFIN) = SRTINY\n SUM2 = TINY * (L1+L1+ONE)\n!\n L1 = L1 + TWO\n LSTEP = 1\n 110 LSTEP = LSTEP + 1\n L1 = L1 - ONE\n!\n OLDFAC = NEWFAC\n A1S = (L1+L2+L3)*(L1-L2+L3-ONE)*(L1+L2-L3-ONE)*(-L1+L2+L3+TWO)\n A2S = (L1+M1-ONE) * (L1-M1-ONE)\n NEWFAC = SQRT(A1S*A2S)\n!\n DV = - L2*(L2+ONE) * M1 + L3*(L3+ONE) * M1 + L1*(L1-ONE) * (M3-M2)\n!\n DENOM = L1 * NEWFAC\n C1 = - (L1+L1-ONE) * DV / DENOM\n if ( LSTEP > 2) go to 120\n!\n! If L1 = L1MAX + 1, the third term in the recursion formula vanishes\n!\n Y = SRTINY * C1\n THRCOF(NFIN-1) = Y\n SUMBAC = SUM2\n SUM2 = SUM2 + TINY * (L1+L1-THREE) * C1*C1\n!\n go to 110\n!\n!\n 120 C2 = - (L1 - ONE) * OLDFAC / DENOM\n!\n! Recursion to the next 3j coefficient Y\n!\n Y = C1 * THRCOF(NFINP2-LSTEP) + C2 * THRCOF(NFINP3-LSTEP)\n!\n if ( LSTEP == NSTEP2) go to 200\n!\n THRCOF(NFINP1-LSTEP) = Y\n SUMBAC = SUM2\n SUM2 = SUM2 + (L1+L1-THREE) * Y*Y\n!\n! See if last unnormalized 3j coefficient exceeds SRHUGE\n!\n if ( ABS(Y) < SRHUGE) go to 110\n!\n! This is reached if last 3j coefficient larger than SRHUGE,\n! so that the recursion series THRCOF(NFIN), ... ,THRCOF(NFIN-LSTEP+1)\n! has to be rescaled to prevent overflow\n!\n! LSCALE = LSCALE + 1\n DO 130 I=1,LSTEP\n INDEX = NFIN - I + 1\n if ( ABS(THRCOF(INDEX)) < SRTINY) THRCOF(INDEX) = ZERO\n 130 THRCOF(INDEX) = THRCOF(INDEX) / SRHUGE\n SUM2 = SUM2 / HUGE\n SUMBAC = SUMBAC / HUGE\n!\n!\n go to 110\n!\n!\n! The forward recursion 3j coefficients X1, X2, X3 are to be matched\n! with the corresponding backward recursion values Y1, Y2, Y3.\n!\n 200 Y3 = Y\n Y2 = THRCOF(NFINP2-LSTEP)\n Y1 = THRCOF(NFINP3-LSTEP)\n!\n!\n! Determine now RATIO such that YI = RATIO * XI (I=1,2,3) holds\n! with minimal error.\n!\n RATIO = ( X1*Y1 + X2*Y2 + X3*Y3 ) / ( X1*X1 + X2*X2 + X3*X3 )\n NLIM = NFIN - NSTEP2 + 1\n!\n if ( ABS(RATIO) < ONE) go to 211\n!\n DO 210 N=1,NLIM\n 210 THRCOF(N) = RATIO * THRCOF(N)\n SUMUNI = RATIO * RATIO * SUMFOR + SUMBAC\n go to 230\n!\n 211 NLIM = NLIM + 1\n RATIO = ONE / RATIO\n DO 212 N=NLIM,NFIN\n 212 THRCOF(N) = RATIO * THRCOF(N)\n SUMUNI = SUMFOR + RATIO*RATIO*SUMBAC\n go to 230\n!\n 220 SUMUNI = SUM1\n!\n!\n! Normalize 3j coefficients\n!\n 230 CNORM = ONE / SQRT(SUMUNI)\n!\n! Sign convention for last 3j coefficient determines overall phase\n!\n SIGN1 = SIGN(ONE,THRCOF(NFIN))\n SIGN2 = (-ONE) ** INT(ABS(L2+M2-L3+M3)+EPS)\n if ( SIGN1*SIGN2) 235,235,236\n 235 CNORM = - CNORM\n!\n 236 if ( ABS(CNORM) < ONE) go to 250\n!\n DO 240 N=1,NFIN\n 240 THRCOF(N) = CNORM * THRCOF(N)\n return\n!\n 250 THRESH = TINY / ABS(CNORM)\n DO 251 N=1,NFIN\n if ( ABS(THRCOF(N)) < THRESH) THRCOF(N) = ZERO\n 251 THRCOF(N) = CNORM * THRCOF(N)\n!\n return\nend\n\n\n\n\n\nsubroutine DRC6J (L2, L3, L4, L5, L6, L1MIN, L1MAX, SIXCOF, NDIM, &\n IER)\n!\n!! DRC6J evaluates the 6j symbol h(L1) for all allowed values of L1.\n!\n!***PURPOSE Evaluate the 6j symbol h(L1) = {L1 L2 L3}\n! {L4 L5 L6}\n! for all allowed values of L1, the other parameters\n! being held fixed.\n!\n!***LIBRARY SLATEC\n!***CATEGORY C19\n!***TYPE DOUBLE PRECISION (RC6J-S, DRC6J-D)\n!***KEYWORDS 6J COEFFICIENTS, 6J SYMBOLS, CLEBSCH-GORDAN COEFFICIENTS,\n! RACAH COEFFICIENTS, VECTOR ADDITION COEFFICIENTS,\n! WIGNER COEFFICIENTS\n!***AUTHOR Gordon, R. G., Harvard University\n! Schulten, K., Max Planck Institute\n!***DESCRIPTION\n!\n! *Usage:\n!\n! DOUBLE PRECISION L2, L3, L4, L5, L6, L1MIN, L1MAX, SIXCOF(NDIM)\n! INTEGER NDIM, IER\n!\n! call DRC6J(L2, L3, L4, L5, L6, L1MIN, L1MAX, SIXCOF, NDIM, IER)\n!\n! *Arguments:\n!\n! L2 :IN Parameter in 6j symbol.\n!\n! L3 :IN Parameter in 6j symbol.\n!\n! L4 :IN Parameter in 6j symbol.\n!\n! L5 :IN Parameter in 6j symbol.\n!\n! L6 :IN Parameter in 6j symbol.\n!\n! L1MIN :OUT Smallest allowable L1 in 6j symbol.\n!\n! L1MAX :OUT Largest allowable L1 in 6j symbol.\n!\n! SIXCOF :OUT Set of 6j coefficients generated by evaluating the\n! 6j symbol for all allowed values of L1. SIXCOF(I)\n! will contain h(L1MIN+I-1), I=1,2,...,L1MAX-L1MIN+1.\n!\n! NDIM :IN Declared length of SIXCOF in calling program.\n!\n! IER :OUT Error flag.\n! IER=0 No errors.\n! IER=1 L2+L3+L5+L6 or L4+L2+L6 not an integer.\n! IER=2 L4, L2, L6 triangular condition not satisfied.\n! IER=3 L4, L5, L3 triangular condition not satisfied.\n! IER=4 L1MAX-L1MIN not an integer.\n! IER=5 L1MAX less than L1MIN.\n! IER=6 NDIM less than L1MAX-L1MIN+1.\n!\n! *Description:\n!\n! The definition and properties of 6j symbols can be found, for\n! example, in Appendix C of Volume II of A. Messiah. Although the\n! parameters of the vector addition coefficients satisfy certain\n! conventional restrictions, the restriction that they be non-negative\n! integers or non-negative integers plus 1/2 is not imposed on input\n! to this subroutine. The restrictions imposed are\n! 1. L2+L3+L5+L6 and L2+L4+L6 must be integers;\n! 2. ABS(L2-L4) <= L6 <= L2+L4 must be satisfied;\n! 3. ABS(L4-L5) <= L3 <= L4+L5 must be satisfied;\n! 4. L1MAX-L1MIN must be a non-negative integer, where\n! L1MAX=MIN(L2+L3,L5+L6) and L1MIN=MAX(ABS(L2-L3),ABS(L5-L6)).\n! If all the conventional restrictions are satisfied, then these\n! restrictions are met. Conversely, if input to this subroutine meets\n! all of these restrictions and the conventional restriction stated\n! above, then all the conventional restrictions are satisfied.\n!\n! The user should be cautious in using input parameters that do\n! not satisfy the conventional restrictions. For example, the\n! the subroutine produces values of\n! h(L1) = { L12/3 1 }\n! {2/32/32/3}\n! for L1=1/3 and 4/3 but none of the symmetry properties of the 6j\n! symbol, set forth on pages 1063 and 1064 of Messiah, is satisfied.\n!\n! The subroutine generates h(L1MIN), h(L1MIN+1), ..., h(L1MAX)\n! where L1MIN and L1MAX are defined above. The sequence h(L1) is\n! generated by a three-term recurrence algorithm with scaling to\n! control overflow. Both backward and forward recurrence are used to\n! maintain numerical stability. The two recurrence sequences are\n! matched at an interior point and are normalized from the unitary\n! property of 6j coefficients and Wigner's phase convention.\n!\n! The algorithm is suited to applications in which large quantum\n! numbers arise, such as in molecular dynamics.\n!\n!***REFERENCES 1. Messiah, Albert., Quantum Mechanics, Volume II,\n! North-Holland Publishing Company, 1963.\n! 2. Schulten, Klaus and Gordon, Roy G., Exact recursive\n! evaluation of 3j and 6j coefficients for quantum-\n! mechanical coupling of angular momenta, J Math\n! Phys, v 16, no. 10, October 1975, pp. 1961-1970.\n! 3. Schulten, Klaus and Gordon, Roy G., Semiclassical\n! approximations to 3j and 6j coefficients for\n! quantum-mechanical coupling of angular momenta,\n! J Math Phys, v 16, no. 10, October 1975,\n! pp. 1971-1988.\n! 4. Schulten, Klaus and Gordon, Roy G., Recursive\n! evaluation of 3j and 6j coefficients, Computer\n! Phys Comm, v 11, 1976, pp. 269-278.\n!***ROUTINES CALLED D1MACH, XERMSG\n!***REVISION HISTORY (YYMMDD)\n! 750101 DATE WRITTEN\n! 880515 SLATEC prologue added by G. C. Nielson, NBS; parameters\n! HUGE and TINY revised to depend on D1MACH.\n! 891229 Prologue description rewritten; other prologue sections\n! revised; LMATCH (location of match point for recurrences)\n! removed from argument list; argument IER changed to serve\n! only as an error flag (previously, in cases without error,\n! it returned the number of scalings); number of error codes\n! increased to provide more precise error information;\n! program comments revised; SLATEC error handler calls\n! introduced to enable printing of error messages to meet\n! SLATEC standards. These changes were done by D. W. Lozier,\n! M. A. McClain and J. M. Smith of the National Institute\n! of Standards and Technology, formerly NBS.\n! 910415 Mixed type expressions eliminated; variable C1 initialized;\n! description of SIXCOF expanded. These changes were done by\n! D. W. Lozier.\n!***END PROLOGUE DRC6J\n!\n INTEGER NDIM, IER\n DOUBLE PRECISION L2, L3, L4, L5, L6, L1MIN, L1MAX, SIXCOF(NDIM)\n!\n INTEGER I, INDEX, LSTEP, N, NFIN, NFINP1, NFINP2, NFINP3, NLIM, &\n NSTEP2\n DOUBLE PRECISION A1, A1S, A2, A2S, C1, C1OLD, C2, CNORM, D1MACH, &\n DENOM, DV, EPS, HUGE, L1, NEWFAC, OLDFAC, ONE, &\n RATIO, SIGN1, SIGN2, SRHUGE, SRTINY, SUM1, SUM2, &\n SUMBAC, SUMFOR, SUMUNI, THREE, THRESH, TINY, TWO, &\n X, X1, X2, X3, Y, Y1, Y2, Y3, ZERO\n!\n DATA ZERO,EPS,ONE,TWO,THREE /0.0D0,0.01D0,1.0D0,2.0D0,3.0D0/\n!\n!***FIRST EXECUTABLE STATEMENT DRC6J\n IER=0\n! HUGE is the square root of one twentieth of the largest floating\n! point number, approximately.\n HUGE = SQRT(D1MACH(2)/20.0D0)\n SRHUGE = SQRT(HUGE)\n TINY = 1.0D0/HUGE\n SRTINY = 1.0D0/SRHUGE\n!\n! LMATCH = ZERO\n!\n! Check error conditions 1, 2, and 3.\n if ( (MOD(L2+L3+L5+L6+EPS,ONE) >= EPS+EPS).OR. &\n (MOD(L4+L2+L6+EPS,ONE) >= EPS+EPS))THEN\n IER=1\n ! call XERMSG('SLATEC','DRC6J','L2+L3+L5+L6 or L4+L2+L6 not '// &\n ! 'integer.',IER,1)\n return\n ELSEIF((L4+L2-L6 < ZERO).OR.(L4-L2+L6 < ZERO).OR. &\n (-L4+L2+L6 < ZERO))THEN\n IER=2\n ! call XERMSG('SLATEC','DRC6J','L4, L2, L6 triangular '// &\n ! 'condition not satisfied.',IER,1)\n return\n ELSEIF((L4-L5+L3 < ZERO).OR.(L4+L5-L3 < ZERO).OR. &\n (-L4+L5+L3 < ZERO))THEN\n IER=3\n ! call XERMSG('SLATEC','DRC6J','L4, L5, L3 triangular '// &\n ! 'condition not satisfied.',IER,1)\n return\n end if\n!\n! Limits for L1\n!\n L1MIN = MAX(ABS(L2-L3),ABS(L5-L6))\n L1MAX = MIN(L2+L3,L5+L6)\n!\n! Check error condition 4.\n if ( MOD(L1MAX-L1MIN+EPS,ONE) >= EPS+EPS)THEN\n IER=4\n ! call XERMSG('SLATEC','DRC6J','L1MAX-L1MIN not integer.',IER,1)\n return\n end if\n if ( L1MIN < L1MAX-EPS) go to 20\n if ( L1MIN < L1MAX+EPS) go to 10\n!\n! Check error condition 5.\n IER=5\n ! call XERMSG('SLATEC','DRC6J','L1MIN greater than L1MAX.',IER,1)\n return\n!\n!\n! This is reached in case that L1 can take only one value\n!\n 10 CONTINUE\n! LSCALE = 0\n SIXCOF(1) = (-ONE) ** INT(L2+L3+L5+L6+EPS) / &\n SQRT((L1MIN+L1MIN+ONE)*(L4+L4+ONE))\n return\n!\n!\n! This is reached in case that L1 can take more than one value.\n!\n 20 CONTINUE\n! LSCALE = 0\n NFIN = INT(L1MAX-L1MIN+ONE+EPS)\n if ( NDIM-NFIN) 21, 23, 23\n!\n! Check error condition 6.\n 21 IER = 6\n ! call XERMSG('SLATEC','DRC6J','Dimension of result array for 6j '// &\n ! 'coefficients too small.',IER,1)\n return\n!\n!\n! Start of forward recursion\n!\n 23 L1 = L1MIN\n NEWFAC = 0.0D0\n C1 = 0.0D0\n SIXCOF(1) = SRTINY\n SUM1 = (L1+L1+ONE) * TINY\n!\n LSTEP = 1\n 30 LSTEP = LSTEP + 1\n L1 = L1 + ONE\n!\n OLDFAC = NEWFAC\n A1 = (L1+L2+L3+ONE) * (L1-L2+L3) * (L1+L2-L3) * (-L1+L2+L3+ONE)\n A2 = (L1+L5+L6+ONE) * (L1-L5+L6) * (L1+L5-L6) * (-L1+L5+L6+ONE)\n NEWFAC = SQRT(A1*A2)\n!\n if ( L1 < ONE+EPS) go to 40\n!\n DV = TWO * ( L2*(L2+ONE)*L5*(L5+ONE) + L3*(L3+ONE)*L6*(L6+ONE) &\n - L1*(L1-ONE)*L4*(L4+ONE) ) &\n - (L2*(L2+ONE) + L3*(L3+ONE) - L1*(L1-ONE)) &\n * (L5*(L5+ONE) + L6*(L6+ONE) - L1*(L1-ONE))\n!\n DENOM = (L1-ONE) * NEWFAC\n!\n if ( LSTEP-2) 32, 32, 31\n!\n 31 C1OLD = ABS(C1)\n 32 C1 = - (L1+L1-ONE) * DV / DENOM\n go to 50\n!\n! If L1 = 1, (L1 - 1) has to be factored out of DV, hence\n!\n 40 C1 = - TWO * ( L2*(L2+ONE) + L5*(L5+ONE) - L4*(L4+ONE) ) &\n / NEWFAC\n!\n 50 if ( LSTEP > 2) go to 60\n!\n! If L1 = L1MIN + 1, the third term in recursion equation vanishes\n!\n X = SRTINY * C1\n SIXCOF(2) = X\n SUM1 = SUM1 + TINY * (L1+L1+ONE) * C1 * C1\n!\n if ( LSTEP == NFIN) go to 220\n go to 30\n!\n!\n 60 C2 = - L1 * OLDFAC / DENOM\n!\n! Recursion to the next 6j coefficient X\n!\n X = C1 * SIXCOF(LSTEP-1) + C2 * SIXCOF(LSTEP-2)\n SIXCOF(LSTEP) = X\n!\n SUMFOR = SUM1\n SUM1 = SUM1 + (L1+L1+ONE) * X * X\n if ( LSTEP == NFIN) go to 100\n!\n! See if last unnormalized 6j coefficient exceeds SRHUGE\n!\n if ( ABS(X) < SRHUGE) go to 80\n!\n! This is reached if last 6j coefficient larger than SRHUGE,\n! so that the recursion series SIXCOF(1), ... ,SIXCOF(LSTEP)\n! has to be rescaled to prevent overflow\n!\n! LSCALE = LSCALE + 1\n DO 70 I=1,LSTEP\n if ( ABS(SIXCOF(I)) < SRTINY) SIXCOF(I) = ZERO\n 70 SIXCOF(I) = SIXCOF(I) / SRHUGE\n SUM1 = SUM1 / HUGE\n SUMFOR = SUMFOR / HUGE\n X = X / SRHUGE\n!\n!\n! As long as the coefficient ABS(C1) is decreasing, the recursion\n! proceeds towards increasing 6j values and, hence, is numerically\n! stable. Once an increase of ABS(C1) is detected, the recursion\n! direction is reversed.\n!\n 80 if ( C1OLD-ABS(C1)) 100, 100, 30\n!\n!\n! Keep three 6j coefficients around LMATCH for comparison later\n! with backward recursion.\n!\n 100 CONTINUE\n! LMATCH = L1 - 1\n X1 = X\n X2 = SIXCOF(LSTEP-1)\n X3 = SIXCOF(LSTEP-2)\n!\n!\n!\n! Starting backward recursion from L1MAX taking NSTEP2 steps, so\n! that forward and backward recursion overlap at the three points\n! L1 = LMATCH+1, LMATCH, LMATCH-1.\n!\n NFINP1 = NFIN + 1\n NFINP2 = NFIN + 2\n NFINP3 = NFIN + 3\n NSTEP2 = NFIN - LSTEP + 3\n L1 = L1MAX\n!\n SIXCOF(NFIN) = SRTINY\n SUM2 = (L1+L1+ONE) * TINY\n!\n!\n L1 = L1 + TWO\n LSTEP = 1\n 110 LSTEP = LSTEP + 1\n L1 = L1 - ONE\n!\n OLDFAC = NEWFAC\n A1S = (L1+L2+L3)*(L1-L2+L3-ONE)*(L1+L2-L3-ONE)*(-L1+L2+L3+TWO)\n A2S = (L1+L5+L6)*(L1-L5+L6-ONE)*(L1+L5-L6-ONE)*(-L1+L5+L6+TWO)\n NEWFAC = SQRT(A1S*A2S)\n!\n DV = TWO * ( L2*(L2+ONE)*L5*(L5+ONE) + L3*(L3+ONE)*L6*(L6+ONE) &\n - L1*(L1-ONE)*L4*(L4+ONE) ) &\n - (L2*(L2+ONE) + L3*(L3+ONE) - L1*(L1-ONE)) &\n * (L5*(L5+ONE) + L6*(L6+ONE) - L1*(L1-ONE))\n!\n DENOM = L1 * NEWFAC\n C1 = - (L1+L1-ONE) * DV / DENOM\n if ( LSTEP > 2) go to 120\n!\n! If L1 = L1MAX + 1 the third term in the recursion equation vanishes\n!\n Y = SRTINY * C1\n SIXCOF(NFIN-1) = Y\n if ( LSTEP == NSTEP2) go to 200\n SUMBAC = SUM2\n SUM2 = SUM2 + (L1+L1-THREE) * C1 * C1 * TINY\n go to 110\n!\n!\n 120 C2 = - (L1-ONE) * OLDFAC / DENOM\n!\n! Recursion to the next 6j coefficient Y\n!\n Y = C1 * SIXCOF(NFINP2-LSTEP) + C2 * SIXCOF(NFINP3-LSTEP)\n if ( LSTEP == NSTEP2) go to 200\n SIXCOF(NFINP1-LSTEP) = Y\n SUMBAC = SUM2\n SUM2 = SUM2 + (L1+L1-THREE) * Y * Y\n!\n! See if last unnormalized 6j coefficient exceeds SRHUGE\n!\n if ( ABS(Y) < SRHUGE) go to 110\n!\n! This is reached if last 6j coefficient larger than SRHUGE,\n! so that the recursion series SIXCOF(NFIN), ... ,SIXCOF(NFIN-LSTEP+1)\n! has to be rescaled to prevent overflow\n!\n! LSCALE = LSCALE + 1\n DO 130 I=1,LSTEP\n INDEX = NFIN-I+1\n if ( ABS(SIXCOF(INDEX)) < SRTINY) SIXCOF(INDEX) = ZERO\n 130 SIXCOF(INDEX) = SIXCOF(INDEX) / SRHUGE\n SUMBAC = SUMBAC / HUGE\n SUM2 = SUM2 / HUGE\n!\n go to 110\n!\n!\n! The forward recursion 6j coefficients X1, X2, X3 are to be matched\n! with the corresponding backward recursion values Y1, Y2, Y3.\n!\n 200 Y3 = Y\n Y2 = SIXCOF(NFINP2-LSTEP)\n Y1 = SIXCOF(NFINP3-LSTEP)\n!\n!\n! Determine now RATIO such that YI = RATIO * XI (I=1,2,3) holds\n! with minimal error.\n!\n RATIO = ( X1*Y1 + X2*Y2 + X3*Y3 ) / ( X1*X1 + X2*X2 + X3*X3 )\n NLIM = NFIN - NSTEP2 + 1\n!\n if ( ABS(RATIO) < ONE) go to 211\n!\n DO 210 N=1,NLIM\n 210 SIXCOF(N) = RATIO * SIXCOF(N)\n SUMUNI = RATIO * RATIO * SUMFOR + SUMBAC\n go to 230\n!\n 211 NLIM = NLIM + 1\n RATIO = ONE / RATIO\n DO 212 N=NLIM,NFIN\n 212 SIXCOF(N) = RATIO * SIXCOF(N)\n SUMUNI = SUMFOR + RATIO*RATIO*SUMBAC\n go to 230\n!\n 220 SUMUNI = SUM1\n!\n!\n! Normalize 6j coefficients\n!\n 230 CNORM = ONE / SQRT((L4+L4+ONE)*SUMUNI)\n!\n! Sign convention for last 6j coefficient determines overall phase\n!\n SIGN1 = SIGN(ONE,SIXCOF(NFIN))\n SIGN2 = (-ONE) ** INT(L2+L3+L5+L6+EPS)\n if ( SIGN1*SIGN2) 235,235,236\n 235 CNORM = - CNORM\n!\n 236 if ( ABS(CNORM) < ONE) go to 250\n!\n DO 240 N=1,NFIN\n 240 SIXCOF(N) = CNORM * SIXCOF(N)\n return\n!\n 250 THRESH = TINY / ABS(CNORM)\n DO 251 N=1,NFIN\n if ( ABS(SIXCOF(N)) < THRESH) SIXCOF(N) = ZERO\n 251 SIXCOF(N) = CNORM * SIXCOF(N)\n!\n return\nend\n\n\n! *** MY MODIFICATIONS\n! The SLATEC library has a complex error-handling system that relies on \n! the XERMSG, XERPRN and other functions. In order to make pieces of SLATEC\n! easier to include in my C code (that has its own error management), I\n! overwrite XERMSG so that it only only prints a simple error message.\n\nsubroutine XERMSG (LIBRAR, SUBROU, MESSG, NERR, LEVEL)\n\n CHARACTER*(*) LIBRAR, SUBROU, MESSG\n\n PRINT *, \"ERROR IN SLATEC '\", SUBROU, \"': \", MESSG\n\nend\n\n\n\n!!! UPDATED D1MACH FUNCTION TAKEN FROM \n!!! http://www.nsc.liu.se/~boein/ifip/kyoto/workshop-info/proceedings/einarsson/f90/d1mach.f90\n!!! NB: DIFFERENT FROM THE VERSION IN BURKHARDT PORT!\n!DECK D1MACH\n\t\t\tDOUBLE PRECISION FUNCTION D1MACH (I)\n IMPLICIT NONE\n INTEGER :: I\n DOUBLE PRECISION :: B, X\n!***BEGIN PROLOGUE D1MACH\n!***PURPOSE Return floating point machine dependent constants.\n!***LIBRARY SLATEC\n!***CATEGORY R1\n!***TYPE SINGLE PRECISION (D1MACH-S, D1MACH-D)\n!***KEYWORDS MACHINE CONSTANTS\n!***AUTHOR Fox, P. A., (Bell Labs)\n! Hall, A. D., (Bell Labs)\n! Schryer, N. L., (Bell Labs)\n!***DESCRIPTION\n!\n! D1MACH can be used to obtain machine-dependent parameters for the\n! local machine environment. It is a function subprogram with one\n! (input) argument, and can be referenced as follows:\n!\n! A = D1MACH(I)\n!\n! where I=1,...,5. The (output) value of A above is determined by\n! the (input) value of I. The results for various values of I are\n! discussed below.\n!\n! D1MACH(1) = B**(EMIN-1), the smallest positive magnitude.\n! D1MACH(2) = B**EMAX*(1 - B**(-T)), the largest magnitude.\n! D1MACH(3) = B**(-T), the smallest relative spacing.\n! D1MACH(4) = B**(1-T), the largest relative spacing.\n! D1MACH(5) = LOG10(B)\n!\n! Assume single precision numbers are represented in the T-digit,\n! base-B form\n!\n! sign (B**E)*( (X(1)/B) + ... + (X(T)/B**T) )\n!\n! where 0 .LE. X(I) .LT. B for I=1,...,T, 0 .LT. X(1), and\n! EMIN .LE. E .LE. EMAX.\n!\n! The values of B, T, EMIN and EMAX are provided in I1MACH as\n! follows:\n! I1MACH(10) = B, the base.\n! I1MACH(11) = T, the number of base-B digits.\n! I1MACH(12) = EMIN, the smallest exponent E.\n! I1MACH(13) = EMAX, the largest exponent E.\n!\n!\n!***REFERENCES P. A. Fox, A. D. Hall and N. L. Schryer, Framework for\n! a portable library, ACM Transactions on Mathematical\n! Software 4, 2 (June 1978), pp. 177-188.\n!***ROUTINES CALLED XERMSG\n!***REVISION HISTORY (YYMMDD)\n! 790101 DATE WRITTEN\n! 960329 Modified for Fortran 90 (BE after suggestions by EHG) \n!***END PROLOGUE D1MACH\n! \n X = 1.0D0\n B = RADIX(X)\n SELECT CASE (I)\n CASE (1)\n D1MACH = B**(MINEXPONENT(X)-1) ! the smallest positive magnitude.\n CASE (2)\n D1MACH = HUGE(X) ! the largest magnitude.\n CASE (3)\n D1MACH = B**(-DIGITS(X)) ! the smallest relative spacing.\n CASE (4)\n D1MACH = B**(1-DIGITS(X)) ! the largest relative spacing.\n CASE (5)\n D1MACH = LOG10(B)\n CASE DEFAULT\n WRITE (*, FMT = 9000)\n 9000 FORMAT ('1ERROR 1 IN D1MACH - I OUT OF BOUNDS')\n STOP\n END SELECT\n RETURN\n END\n\n\n! Test function. Used to check that arrays are passed correctly between\n! C and Fortran.\nsubroutine set_array_to_one(pntr, ndim)\n\n\tINTEGER ndim, i\n\tDOUBLE PRECISION pntr(ndim)\n\n\tDO i=1,ndim\n\t\tpntr(i) = 1.\n\tENDDO\n\t\nend subroutine\n\n\n\n!!! UPDATED R1MACH FUNCTION TAKEN FROM \n!!! http://www.nsc.liu.se/~boein/ifip/kyoto/workshop-info/proceedings/einarsson/f90/r1mach.f90\n!!! NB: DIFFERENT FROM THE VERSION IN BURKHARDT PORT!\n\n!DECK R1MACH\n REAL FUNCTION R1MACH (I)\n IMPLICIT NONE\n INTEGER :: I\n REAL :: B, X\n!***BEGIN PROLOGUE R1MACH\n!***PURPOSE Return floating point machine dependent constants.\n!***LIBRARY SLATEC\n!***CATEGORY R1\n!***TYPE SINGLE PRECISION (R1MACH-S, D1MACH-D)\n!***KEYWORDS MACHINE CONSTANTS\n!***AUTHOR Fox, P. A., (Bell Labs)\n! Hall, A. D., (Bell Labs)\n! Schryer, N. L., (Bell Labs)\n!***DESCRIPTION\n!\n! R1MACH can be used to obtain machine-dependent parameters for the\n! local machine environment. It is a function subprogram with one\n! (input) argument, and can be referenced as follows:\n!\n! A = R1MACH(I)\n!\n! where I=1,...,5. The (output) value of A above is determined by\n! the (input) value of I. The results for various values of I are\n! discussed below.\n!\n! R1MACH(1) = B**(EMIN-1), the smallest positive magnitude.\n! R1MACH(2) = B**EMAX*(1 - B**(-T)), the largest magnitude.\n! R1MACH(3) = B**(-T), the smallest relative spacing.\n! R1MACH(4) = B**(1-T), the largest relative spacing.\n! R1MACH(5) = LOG10(B)\n!\n! Assume single precision numbers are represented in the T-digit,\n! base-B form\n!\n! sign (B**E)*( (X(1)/B) + ... + (X(T)/B**T) )\n!\n! where 0 .LE. X(I) .LT. B for I=1,...,T, 0 .LT. X(1), and\n! EMIN .LE. E .LE. EMAX.\n!\n! The values of B, T, EMIN and EMAX are provided in I1MACH as\n! follows:\n! I1MACH(10) = B, the base.\n! I1MACH(11) = T, the number of base-B digits.\n! I1MACH(12) = EMIN, the smallest exponent E.\n! I1MACH(13) = EMAX, the largest exponent E.\n!\n!\n!***REFERENCES P. A. Fox, A. D. Hall and N. L. Schryer, Framework for\n! a portable library, ACM Transactions on Mathematical\n! Software 4, 2 (June 1978), pp. 177-188.\n!***ROUTINES CALLED XERMSG\n!***REVISION HISTORY (YYMMDD)\n! 790101 DATE WRITTEN\n! 960329 Modified for Fortran 90 (BE after suggestions by EG) \n!***END PROLOGUE R1MACH\n! \n X = 1.0\n B = RADIX(X)\n SELECT CASE (I)\n CASE (1)\n R1MACH = B**(MINEXPONENT(X)-1) ! the smallest positive magnitude.\n CASE (2)\n R1MACH = HUGE(X) ! the largest magnitude.\n CASE (3)\n R1MACH = B**(-DIGITS(X)) ! the smallest relative spacing.\n CASE (4)\n R1MACH = B**(1-DIGITS(X)) ! the largest relative spacing.\n CASE (5)\n R1MACH = LOG10(B)\n CASE DEFAULT\n WRITE (*, FMT = 9000)\n 9000 FORMAT ('1ERROR 1 IN R1MACH - I OUT OF BOUNDS')\n STOP\n END SELECT\n RETURN\n END\n\n\n! ============================\n! = Double precision Bessels =\n! ============================\n\n\nsubroutine DBESJ (X, ALPHA, N, Y, NZ)\n!\n!! DBESJ computes an N member sequence of J Bessel functions ...\n! J/SUB(ALPHA+K-1)/(X), K=1,...,N for non-negative ALPHA\n! and X.\n!\n!***LIBRARY SLATEC\n!***CATEGORY C10A3\n!***TYPE DOUBLE PRECISION (BESJ-S, DBESJ-D)\n!***KEYWORDS J BESSEL FUNCTION, SPECIAL FUNCTIONS\n!***AUTHOR Amos, D. E., (SNLA)\n! Daniel, S. L., (SNLA)\n! Weston, M. K., (SNLA)\n!***DESCRIPTION\n!\n! Abstract **** a double precision routine ****\n! DBESJ computes an N member sequence of J Bessel functions\n! J/sub(ALPHA+K-1)/(X), K=1,...,N for non-negative ALPHA and X.\n! A combination of the power series, the asymptotic expansion\n! for X to infinity and the uniform asymptotic expansion for\n! NU to infinity are applied over subdivisions of the (NU,X)\n! plane. For values of (NU,X) not covered by one of these\n! formulae, the order is incremented or decremented by integer\n! values into a region where one of the formulae apply. Backward\n! recursion is applied to reduce orders by integer values except\n! where the entire sequence lies in the oscillatory region. In\n! this case forward recursion is stable and values from the\n! asymptotic expansion for X to infinity start the recursion\n! when it is efficient to do so. Leading terms of the series and\n! uniform expansion are tested for underflow. If a sequence is\n! requested and the last member would underflow, the result is\n! set to zero and the next lower order tried, etc., until a\n! member comes on scale or all members are set to zero.\n! Overflow cannot occur.\n!\n! The maximum number of significant digits obtainable\n! is the smaller of 14 and the number of digits carried in\n! double precision arithmetic.\n!\n! Description of Arguments\n!\n! Input X,ALPHA are double precision\n! X - X >= 0.0D0\n! ALPHA - order of first member of the sequence,\n! ALPHA >= 0.0D0\n! N - number of members in the sequence, N >= 1\n!\n! Output Y is double precision\n! Y - a vector whose first N components contain\n! values for J/sub(ALPHA+K-1)/(X), K=1,...,N\n! NZ - number of components of Y set to zero due to\n! underflow,\n! NZ=0 , normal return, computation completed\n! NZ /= 0, last NZ components of Y set to zero,\n! Y(K)=0.0D0, K=N-NZ+1,...,N.\n!\n! Error Conditions\n! Improper input arguments - a fatal error\n! Underflow - a non-fatal error (NZ /= 0)\n!\n!***REFERENCES D. E. Amos, S. L. Daniel and M. K. Weston, CDC 6600\n! subroutines IBESS and JBESS for Bessel functions\n! I(NU,X) and J(NU,X), X >= 0, NU >= 0, ACM\n! Transactions on Mathematical Software 3, (1977),\n! pp. 76-92.\n! F. W. J. Olver, Tables of Bessel Functions of Moderate\n! or Large Orders, NPL Mathematical Tables 6, Her\n! Majesty's Stationery Office, London, 1962.\n!***ROUTINES CALLED D1MACH, DASYJY, DJAIRY, DLNGAM, I1MACH, XERMSG\n!***REVISION HISTORY (YYMMDD)\n! 750101 DATE WRITTEN\n! 890531 Changed all specific intrinsics to generic. (WRB)\n! 890911 Removed unnecessary intrinsics. (WRB)\n! 890911 REVISION DATE from Version 3.2\n! 891214 Prologue converted to Version 4.0 format. (BAB)\n! 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\n! 900326 Removed duplicate information from DESCRIPTION section.\n! (WRB)\n! 920501 Reformatted the REFERENCES section. (WRB)\n!***END PROLOGUE DBESJ\n EXTERNAL DJAIRY\n INTEGER I,IALP,IDALP,IFLW,IN,INLIM,IS,I1,I2,K,KK,KM,KT,N,NN, &\n NS,NZ\n INTEGER I1MACH\n DOUBLE PRECISION AK,AKM,ALPHA,ANS,AP,ARG,COEF,DALPHA,DFN,DTM, &\n EARG,ELIM1,ETX,FIDAL,FLGJY,FN,FNF,FNI,FNP1,FNU, &\n FNULIM,GLN,PDF,PIDT,PP,RDEN,RELB,RTTP,RTWO,RTX,RZDEN, &\n S,SA,SB,SXO2,S1,S2,T,TA,TAU,TB,TEMP,TFN,TM,TOL, &\n TOLLN,TRX,TX,T1,T2,WK,X,XO2,XO2L,Y,SLIM,RTOL\n SAVE RTWO, PDF, RTTP, PIDT, PP, INLIM, FNULIM\n DOUBLE PRECISION D1MACH, DLNGAM\n DIMENSION Y(*), TEMP(3), FNULIM(2), PP(4), WK(7)\n DATA RTWO,PDF,RTTP,PIDT / 1.34839972492648D+00, &\n 7.85398163397448D-01, 7.97884560802865D-01, 1.57079632679490D+00/\n DATA PP(1), PP(2), PP(3), PP(4) / 8.72909153935547D+00, &\n 2.65693932265030D-01, 1.24578576865586D-01, 7.70133747430388D-04/\n DATA INLIM / 150 /\n DATA FNULIM(1), FNULIM(2) / 100.0D0, 60.0D0 /\n!***FIRST EXECUTABLE STATEMENT DBESJ\n NZ = 0\n KT = 1\n NS=0\n! I1MACH(14) REPLACES I1MACH(11) IN A DOUBLE PRECISION CODE\n! I1MACH(15) REPLACES I1MACH(12) IN A DOUBLE PRECISION CODE\n TA = D1MACH(3)\n TOL = MAX(TA,1.0D-15)\n I1 = I1MACH(14) + 1\n I2 = I1MACH(15)\n TB = D1MACH(5)\n ELIM1 = -2.303D0*(I2*TB+3.0D0)\n RTOL=1.0D0/TOL\n SLIM=D1MACH(1)*RTOL*1.0D+3\n! TOLLN = -LN(TOL)\n TOLLN = 2.303D0*TB*I1\n TOLLN = MIN(TOLLN,34.5388D0)\n if (N-1) 720, 10, 20\n 10 KT = 2\n 20 NN = N\n if (X) 730, 30, 80\n 30 if (ALPHA) 710, 40, 50\n 40 Y(1) = 1.0D0\n if (N == 1) RETURN\n I1 = 2\n go to 60\n 50 I1 = 1\n 60 DO 70 I=I1,N\n Y(I) = 0.0D0\n 70 CONTINUE\n return\n 80 CONTINUE\n if (ALPHA < 0.0D0) go to 710\n!\n IALP = INT(ALPHA)\n FNI = IALP + N - 1\n FNF = ALPHA - IALP\n DFN = FNI + FNF\n FNU = DFN\n XO2 = X*0.5D0\n SXO2 = XO2*XO2\n!\n! DECISION TREE FOR REGION WHERE SERIES, ASYMPTOTIC EXPANSION FOR X\n! TO INFINITY AND ASYMPTOTIC EXPANSION FOR NU TO INFINITY ARE\n! APPLIED.\n!\n if (SXO2 <= (FNU+1.0D0)) go to 90\n TA = MAX(20.0D0,FNU)\n if (X > TA) go to 120\n if (X > 12.0D0) go to 110\n XO2L = LOG(XO2)\n NS = INT(SXO2-FNU) + 1\n go to 100\n 90 FN = FNU\n FNP1 = FN + 1.0D0\n XO2L = LOG(XO2)\n IS = KT\n if (X <= 0.50D0) go to 330\n NS = 0\n 100 FNI = FNI + NS\n DFN = FNI + FNF\n FN = DFN\n FNP1 = FN + 1.0D0\n IS = KT\n if (N-1+NS > 0) IS = 3\n go to 330\n 110 ANS = MAX(36.0D0-FNU,0.0D0)\n NS = INT(ANS)\n FNI = FNI + NS\n DFN = FNI + FNF\n FN = DFN\n IS = KT\n if (N-1+NS > 0) IS = 3\n go to 130\n 120 CONTINUE\n RTX = SQRT(X)\n TAU = RTWO*RTX\n TA = TAU + FNULIM(KT)\n if (FNU <= TA) go to 480\n FN = FNU\n IS = KT\n!\n! UNIFORM ASYMPTOTIC EXPANSION FOR NU TO INFINITY\n!\n 130 CONTINUE\n I1 = ABS(3-IS)\n I1 = MAX(I1,1)\n FLGJY = 1.0D0\n call DASYJY(DJAIRY,X,FN,FLGJY,I1,TEMP(IS),WK,IFLW)\n if ( IFLW /= 0) go to 380\n go to (320, 450, 620), IS\n 310 TEMP(1) = TEMP(3)\n KT = 1\n 320 IS = 2\n FNI = FNI - 1.0D0\n DFN = FNI + FNF\n FN = DFN\n if ( I1 == 2) go to 450\n go to 130\n!\n! SERIES FOR (X/2)**2 <= NU+1\n!\n 330 CONTINUE\n GLN = DLNGAM(FNP1)\n ARG = FN*XO2L - GLN\n if (ARG < (-ELIM1)) go to 400\n EARG = EXP(ARG)\n 340 CONTINUE\n S = 1.0D0\n if (X < TOL) go to 360\n AK = 3.0D0\n T2 = 1.0D0\n T = 1.0D0\n S1 = FN\n DO 350 K=1,17\n S2 = T2 + S1\n T = -T*SXO2/S2\n S = S + T\n if (ABS(T) < TOL) go to 360\n T2 = T2 + AK\n AK = AK + 2.0D0\n S1 = S1 + FN\n 350 CONTINUE\n 360 CONTINUE\n TEMP(IS) = S*EARG\n go to (370, 450, 610), IS\n 370 EARG = EARG*FN/XO2\n FNI = FNI - 1.0D0\n DFN = FNI + FNF\n FN = DFN\n IS = 2\n go to 340\n!\n! SET UNDERFLOW VALUE AND UPDATE PARAMETERS\n! UNDERFLOW CAN ONLY OCCUR FOR NS=0 SINCE THE ORDER MUST BE LARGER\n! THAN 36. THEREFORE, NS NEE NOT BE TESTED.\n!\n 380 Y(NN) = 0.0D0\n NN = NN - 1\n FNI = FNI - 1.0D0\n DFN = FNI + FNF\n FN = DFN\n if (NN-1) 440, 390, 130\n 390 KT = 2\n IS = 2\n go to 130\n 400 Y(NN) = 0.0D0\n NN = NN - 1\n FNP1 = FN\n FNI = FNI - 1.0D0\n DFN = FNI + FNF\n FN = DFN\n if (NN-1) 440, 410, 420\n 410 KT = 2\n IS = 2\n 420 if (SXO2 <= FNP1) go to 430\n go to 130\n 430 ARG = ARG - XO2L + LOG(FNP1)\n if (ARG < (-ELIM1)) go to 400\n go to 330\n 440 NZ = N - NN\n return\n!\n! BACKWARD RECURSION SECTION\n!\n 450 CONTINUE\n if ( NS /= 0) go to 451\n NZ = N - NN\n if (KT == 2) go to 470\n! BACKWARD RECUR FROM INDEX ALPHA+NN-1 TO ALPHA\n Y(NN) = TEMP(1)\n Y(NN-1) = TEMP(2)\n if (NN == 2) RETURN\n 451 CONTINUE\n TRX = 2.0D0/X\n DTM = FNI\n TM = (DTM+FNF)*TRX\n AK=1.0D0\n TA=TEMP(1)\n TB=TEMP(2)\n if ( ABS(TA) > SLIM) go to 455\n TA=TA*RTOL\n TB=TB*RTOL\n AK=TOL\n 455 CONTINUE\n KK=2\n IN=NS-1\n if ( IN == 0) go to 690\n if ( NS /= 0) go to 670\n K=NN-2\n DO 460 I=3,NN\n S=TB\n TB = TM*TB - TA\n TA=S\n Y(K)=TB*AK\n DTM = DTM - 1.0D0\n TM = (DTM+FNF)*TRX\n K = K - 1\n 460 CONTINUE\n return\n 470 Y(1) = TEMP(2)\n return\n!\n! ASYMPTOTIC EXPANSION FOR X TO INFINITY WITH FORWARD RECURSION IN\n! OSCILLATORY REGION X > MAX(20, NU), PROVIDED THE LAST MEMBER\n! OF THE SEQUENCE IS ALSO IN THE REGION.\n!\n 480 CONTINUE\n IN = INT(ALPHA-TAU+2.0D0)\n if (IN <= 0) go to 490\n IDALP = IALP - IN - 1\n KT = 1\n go to 500\n 490 CONTINUE\n IDALP = IALP\n IN = 0\n 500 IS = KT\n FIDAL = IDALP\n DALPHA = FIDAL + FNF\n ARG = X - PIDT*DALPHA - PDF\n SA = SIN(ARG)\n SB = COS(ARG)\n COEF = RTTP/RTX\n ETX = 8.0D0*X\n 510 CONTINUE\n DTM = FIDAL + FIDAL\n DTM = DTM*DTM\n TM = 0.0D0\n if (FIDAL == 0.0D0 .AND. ABS(FNF) < TOL) go to 520\n TM = 4.0D0*FNF*(FIDAL+FIDAL+FNF)\n 520 CONTINUE\n TRX = DTM - 1.0D0\n T2 = (TRX+TM)/ETX\n S2 = T2\n RELB = TOL*ABS(T2)\n T1 = ETX\n S1 = 1.0D0\n FN = 1.0D0\n AK = 8.0D0\n DO 530 K=1,13\n T1 = T1 + ETX\n FN = FN + AK\n TRX = DTM - FN\n AP = TRX + TM\n T2 = -T2*AP/T1\n S1 = S1 + T2\n T1 = T1 + ETX\n AK = AK + 8.0D0\n FN = FN + AK\n TRX = DTM - FN\n AP = TRX + TM\n T2 = T2*AP/T1\n S2 = S2 + T2\n if (ABS(T2) <= RELB) go to 540\n AK = AK + 8.0D0\n 530 CONTINUE\n 540 TEMP(IS) = COEF*(S1*SB-S2*SA)\n if ( IS == 2) go to 560\n FIDAL = FIDAL + 1.0D0\n DALPHA = FIDAL + FNF\n IS = 2\n TB = SA\n SA = -SB\n SB = TB\n go to 510\n!\n! FORWARD RECURSION SECTION\n!\n 560 if (KT == 2) go to 470\n S1 = TEMP(1)\n S2 = TEMP(2)\n TX = 2.0D0/X\n TM = DALPHA*TX\n if (IN == 0) go to 580\n!\n! FORWARD RECUR TO INDEX ALPHA\n!\n DO 570 I=1,IN\n S = S2\n S2 = TM*S2 - S1\n TM = TM + TX\n S1 = S\n 570 CONTINUE\n if (NN == 1) go to 600\n S = S2\n S2 = TM*S2 - S1\n TM = TM + TX\n S1 = S\n 580 CONTINUE\n!\n! FORWARD RECUR FROM INDEX ALPHA TO ALPHA+N-1\n!\n Y(1) = S1\n Y(2) = S2\n if (NN == 2) RETURN\n DO 590 I=3,NN\n Y(I) = TM*Y(I-1) - Y(I-2)\n TM = TM + TX\n 590 CONTINUE\n return\n 600 Y(1) = S2\n return\n!\n! BACKWARD RECURSION WITH NORMALIZATION BY\n! ASYMPTOTIC EXPANSION FOR NU TO INFINITY OR POWER SERIES.\n!\n 610 CONTINUE\n! COMPUTATION OF LAST ORDER FOR SERIES NORMALIZATION\n AKM = MAX(3.0D0-FN,0.0D0)\n KM = INT(AKM)\n TFN = FN + KM\n TA = (GLN+TFN-0.9189385332D0-0.0833333333D0/TFN)/(TFN+0.5D0)\n TA = XO2L - TA\n TB = -(1.0D0-1.5D0/TFN)/TFN\n AKM = TOLLN/(-TA+SQRT(TA*TA-TOLLN*TB)) + 1.5D0\n IN = KM + INT(AKM)\n go to 660\n 620 CONTINUE\n! COMPUTATION OF LAST ORDER FOR ASYMPTOTIC EXPANSION NORMALIZATION\n GLN = WK(3) + WK(2)\n if (WK(6) > 30.0D0) go to 640\n RDEN = (PP(4)*WK(6)+PP(3))*WK(6) + 1.0D0\n RZDEN = PP(1) + PP(2)*WK(6)\n TA = RZDEN/RDEN\n if (WK(1) < 0.10D0) go to 630\n TB = GLN/WK(5)\n go to 650\n 630 TB=(1.259921049D0+(0.1679894730D0+0.0887944358D0*WK(1))*WK(1)) &\n /WK(7)\n go to 650\n 640 CONTINUE\n TA = 0.5D0*TOLLN/WK(4)\n TA=((0.0493827160D0*TA-0.1111111111D0)*TA+0.6666666667D0)*TA*WK(6)\n if (WK(1) < 0.10D0) go to 630\n TB = GLN/WK(5)\n 650 IN = INT(TA/TB+1.5D0)\n if (IN > INLIM) go to 310\n 660 CONTINUE\n DTM = FNI + IN\n TRX = 2.0D0/X\n TM = (DTM+FNF)*TRX\n TA = 0.0D0\n TB = TOL\n KK = 1\n AK=1.0D0\n 670 CONTINUE\n!\n! BACKWARD RECUR UNINDEXED\n!\n DO 680 I=1,IN\n S = TB\n TB = TM*TB - TA\n TA = S\n DTM = DTM - 1.0D0\n TM = (DTM+FNF)*TRX\n 680 CONTINUE\n! NORMALIZATION\n if (KK /= 1) go to 690\n S=TEMP(3)\n SA=TA/TB\n TA=S\n TB=S\n if ( ABS(S) > SLIM) go to 685\n TA=TA*RTOL\n TB=TB*RTOL\n AK=TOL\n 685 CONTINUE\n TA=TA*SA\n KK = 2\n IN = NS\n if (NS /= 0) go to 670\n 690 Y(NN) = TB*AK\n NZ = N - NN\n if (NN == 1) RETURN\n K = NN - 1\n S=TB\n TB = TM*TB - TA\n TA=S\n Y(K)=TB*AK\n if (NN == 2) RETURN\n DTM = DTM - 1.0D0\n TM = (DTM+FNF)*TRX\n K=NN-2\n!\n! BACKWARD RECUR INDEXED\n!\n DO 700 I=3,NN\n S=TB\n TB = TM*TB - TA\n TA=S\n Y(K)=TB*AK\n DTM = DTM - 1.0D0\n TM = (DTM+FNF)*TRX\n K = K - 1\n 700 CONTINUE\n return\n!\n!\n!\n 710 CONTINUE\n call XERMSG ('SLATEC', 'DBESJ', 'ORDER, ALPHA, LESS THAN ZERO.', &\n 2, 1)\n return\n 720 CONTINUE\n call XERMSG ('SLATEC', 'DBESJ', 'N LESS THAN ONE.', 2, 1)\n return\n 730 CONTINUE\n call XERMSG ('SLATEC', 'DBESJ', 'X LESS THAN ZERO.', 2, 1)\n return\nend\n\nDOUBLE PRECISION FUNCTION DBESJ0 (X)\n!\n!! DBESJ0 computes the Bessel function of the first kind of order zero.\n!\n!***LIBRARY SLATEC (FNLIB)\n!***CATEGORY C10A1\n!***TYPE DOUBLE PRECISION (BESJ0-S, DBESJ0-D)\n!***KEYWORDS BESSEL FUNCTION, FIRST KIND, FNLIB, ORDER ZERO,\n! SPECIAL FUNCTIONS\n!***AUTHOR Fullerton, W., (LANL)\n!***DESCRIPTION\n!\n! DBESJ0(X) calculates the double precision Bessel function of\n! the first kind of order zero for double precision argument X.\n!\n! Series for BJ0 on the interval 0. to 1.60000E+01\n! with weighted error 4.39E-32\n! log weighted error 31.36\n! significant figures required 31.21\n! decimal places required 32.00\n!\n!***REFERENCES (NONE)\n!***ROUTINES CALLED D1MACH, D9B0MP, DCSEVL, INITDS\n!***REVISION HISTORY (YYMMDD)\n! 770701 DATE WRITTEN\n! 890531 Changed all specific intrinsics to generic. (WRB)\n! 890531 REVISION DATE from Version 3.2\n! 891214 Prologue converted to Version 4.0 format. (BAB)\n!***END PROLOGUE DBESJ0\n DOUBLE PRECISION X, BJ0CS(19), AMPL, THETA, XSML, Y, D1MACH, &\n DCSEVL\n LOGICAL FIRST\n SAVE BJ0CS, NTJ0, XSML, FIRST\n DATA BJ0CS( 1) / +.10025416196893913701073127264074D+0 /\n DATA BJ0CS( 2) / -.66522300776440513177678757831124D+0 /\n DATA BJ0CS( 3) / +.24898370349828131370460468726680D+0 /\n DATA BJ0CS( 4) / -.33252723170035769653884341503854D-1 /\n DATA BJ0CS( 5) / +.23114179304694015462904924117729D-2 /\n DATA BJ0CS( 6) / -.99112774199508092339048519336549D-4 /\n DATA BJ0CS( 7) / +.28916708643998808884733903747078D-5 /\n DATA BJ0CS( 8) / -.61210858663032635057818407481516D-7 /\n DATA BJ0CS( 9) / +.98386507938567841324768748636415D-9 /\n DATA BJ0CS( 10) / -.12423551597301765145515897006836D-10 /\n DATA BJ0CS( 11) / +.12654336302559045797915827210363D-12 /\n DATA BJ0CS( 12) / -.10619456495287244546914817512959D-14 /\n DATA BJ0CS( 13) / +.74706210758024567437098915584000D-17 /\n DATA BJ0CS( 14) / -.44697032274412780547627007999999D-19 /\n DATA BJ0CS( 15) / +.23024281584337436200523093333333D-21 /\n DATA BJ0CS( 16) / -.10319144794166698148522666666666D-23 /\n DATA BJ0CS( 17) / +.40608178274873322700800000000000D-26 /\n DATA BJ0CS( 18) / -.14143836005240913919999999999999D-28 /\n DATA BJ0CS( 19) / +.43910905496698880000000000000000D-31 /\n DATA FIRST /.TRUE./\n!***FIRST EXECUTABLE STATEMENT DBESJ0\n if (FIRST) THEN\n NTJ0 = INITDS (BJ0CS, 19, 0.1*REAL(D1MACH(3)))\n XSML = SQRT(8.0D0*D1MACH(3))\n end if\n FIRST = .FALSE.\n!\n Y = ABS(X)\n if (Y > 4.0D0) go to 20\n!\n DBESJ0 = 1.0D0\n if (Y > XSML) DBESJ0 = DCSEVL (.125D0*Y*Y-1.D0, BJ0CS, NTJ0)\n return\n!\n 20 call D9B0MP (Y, AMPL, THETA)\n DBESJ0 = AMPL * COS(THETA)\n!\n return\nend\n\nDOUBLE PRECISION FUNCTION DBESJ1 (X)\n!\n!! DBESJ1 computes the Bessel function of the first kind of order one.\n!\n!***LIBRARY SLATEC (FNLIB)\n!***CATEGORY C10A1\n!***TYPE DOUBLE PRECISION (BESJ1-S, DBESJ1-D)\n!***KEYWORDS BESSEL FUNCTION, FIRST KIND, FNLIB, ORDER ONE,\n! SPECIAL FUNCTIONS\n!***AUTHOR Fullerton, W., (LANL)\n!***DESCRIPTION\n!\n! DBESJ1(X) calculates the double precision Bessel function of the\n! first kind of order one for double precision argument X.\n!\n! Series for BJ1 on the interval 0. to 1.60000E+01\n! with weighted error 1.16E-33\n! log weighted error 32.93\n! significant figures required 32.36\n! decimal places required 33.57\n!\n!***REFERENCES (NONE)\n!***ROUTINES CALLED D1MACH, D9B1MP, DCSEVL, INITDS, XERMSG\n!***REVISION HISTORY (YYMMDD)\n! 780601 DATE WRITTEN\n! 890531 Changed all specific intrinsics to generic. (WRB)\n! 890531 REVISION DATE from Version 3.2\n! 891214 Prologue converted to Version 4.0 format. (BAB)\n! 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\n! 910401 Corrected error in code which caused values to have the\n! wrong sign for arguments less than 4.0. (WRB)\n!***END PROLOGUE DBESJ1\n DOUBLE PRECISION X, BJ1CS(19), AMPL, THETA, XSML, XMIN, Y, &\n D1MACH, DCSEVL\n LOGICAL FIRST\n SAVE BJ1CS, NTJ1, XSML, XMIN, FIRST\n DATA BJ1CS( 1) / -.117261415133327865606240574524003D+0 /\n DATA BJ1CS( 2) / -.253615218307906395623030884554698D+0 /\n DATA BJ1CS( 3) / +.501270809844695685053656363203743D-1 /\n DATA BJ1CS( 4) / -.463151480962508191842619728789772D-2 /\n DATA BJ1CS( 5) / +.247996229415914024539124064592364D-3 /\n DATA BJ1CS( 6) / -.867894868627882584521246435176416D-5 /\n DATA BJ1CS( 7) / +.214293917143793691502766250991292D-6 /\n DATA BJ1CS( 8) / -.393609307918317979229322764073061D-8 /\n DATA BJ1CS( 9) / +.559118231794688004018248059864032D-10 /\n DATA BJ1CS( 10) / -.632761640466139302477695274014880D-12 /\n DATA BJ1CS( 11) / +.584099161085724700326945563268266D-14 /\n DATA BJ1CS( 12) / -.448253381870125819039135059199999D-16 /\n DATA BJ1CS( 13) / +.290538449262502466306018688000000D-18 /\n DATA BJ1CS( 14) / -.161173219784144165412118186666666D-20 /\n DATA BJ1CS( 15) / +.773947881939274637298346666666666D-23 /\n DATA BJ1CS( 16) / -.324869378211199841143466666666666D-25 /\n DATA BJ1CS( 17) / +.120223767722741022720000000000000D-27 /\n DATA BJ1CS( 18) / -.395201221265134933333333333333333D-30 /\n DATA BJ1CS( 19) / +.116167808226645333333333333333333D-32 /\n DATA FIRST /.TRUE./\n!***FIRST EXECUTABLE STATEMENT DBESJ1\n if (FIRST) THEN\n NTJ1 = INITDS (BJ1CS, 19, 0.1*REAL(D1MACH(3)))\n!\n XSML = SQRT(8.0D0*D1MACH(3))\n XMIN = 2.0D0*D1MACH(1)\n end if\n FIRST = .FALSE.\n!\n Y = ABS(X)\n if (Y > 4.0D0) go to 20\n!\n DBESJ1 = 0.0D0\n if (Y == 0.0D0) RETURN\n if (Y <= XMIN) call XERMSG ('SLATEC', 'DBESJ1', &\n 'ABS(X) SO SMALL J1 UNDERFLOWS', 1, 1)\n if (Y > XMIN) DBESJ1 = 0.5D0*X\n if (Y > XSML) DBESJ1 = X*(.25D0 + DCSEVL (.125D0*Y*Y-1.D0, &\n BJ1CS, NTJ1) )\n return\n!\n 20 call D9B1MP (Y, AMPL, THETA)\n DBESJ1 = SIGN (AMPL, X) * COS(THETA)\n!\n return\nend\n\nsubroutine DASYJY (FUNJY, X, FNU, FLGJY, IN, Y, WK, IFLW)\n!\n!! DASYJY is subsidiary to DBESJ and DBESY.\n!\n!***LIBRARY SLATEC\n!***TYPE DOUBLE PRECISION (ASYJY-S, DASYJY-D)\n!***AUTHOR Amos, D. E., (SNLA)\n!***DESCRIPTION\n!\n! DASYJY computes Bessel functions J and Y\n! for arguments X > 0.0 and orders FNU >= 35.0\n! on FLGJY = 1 and FLGJY = -1 respectively\n!\n! INPUT\n!\n! FUNJY - External subroutine JAIRY or YAIRY\n! X - Argument, X > 0.0D0\n! FNU - Order of the first Bessel function\n! FLGJY - Selection flag\n! FLGJY = 1.0D0 gives the J function\n! FLGJY = -1.0D0 gives the Y function\n! IN - Number of functions desired, IN = 1 or 2\n!\n! OUTPUT\n!\n! Y - A vector whose first IN components contain the sequence\n! IFLW - A flag indicating underflow or overflow\n! return variables for BESJ only\n! WK(1) = 1 - (X/FNU)**2 = W**2\n! WK(2) = SQRT(ABS(WK(1)))\n! WK(3) = ABS(WK(2) - ATAN(WK(2))) or\n! ABS(LN((1 + WK(2))/(X/FNU)) - WK(2))\n! = ABS((2/3)*ZETA**(3/2))\n! WK(4) = FNU*WK(3)\n! WK(5) = (1.5*WK(3)*FNU)**(1/3) = SQRT(ZETA)*FNU**(1/3)\n! WK(6) = SIGN(1.,W**2)*WK(5)**2 = SIGN(1.,W**2)*ZETA*FNU**(2/3)\n! WK(7) = FNU**(1/3)\n!\n! Abstract **** A Double Precision Routine ****\n! DASYJY implements the uniform asymptotic expansion of\n! the J and Y Bessel functions for FNU >= 35 and real\n! X > 0.0D0. The forms are identical except for a change\n! in sign of some of the terms. This change in sign is\n! accomplished by means of the flag FLGJY = 1 or -1. On\n! FLGJY = 1 the Airy functions AI(X) and DAI(X) are\n! supplied by the external function JAIRY, and on\n! FLGJY = -1 the Airy functions BI(X) and DBI(X) are\n! supplied by the external function YAIRY.\n!\n!***SEE ALSO DBESJ, DBESY\n!***ROUTINES CALLED D1MACH, I1MACH\n!***REVISION HISTORY (YYMMDD)\n! 750101 DATE WRITTEN\n! 890531 Changed all specific intrinsics to generic. (WRB)\n! 890911 Removed unnecessary intrinsics. (WRB)\n! 891004 Correction computation of ELIM. (WRB)\n! 891009 Removed unreferenced variable. (WRB)\n! 891214 Prologue converted to Version 4.0 format. (BAB)\n! 900328 Added TYPE section. (WRB)\n! 910408 Updated the AUTHOR section. (WRB)\n!***END PROLOGUE DASYJY\n INTEGER I, IFLW, IN, J, JN,JR,JU,K, KB,KLAST,KMAX,KP1, KS, KSP1, &\n KSTEMP, L, LR, LRP1, ISETA, ISETB\n INTEGER I1MACH\n DOUBLE PRECISION ABW2, AKM, ALFA, ALFA1, ALFA2, AP, AR, ASUM, AZ, &\n BETA, BETA1, BETA2, BETA3, BR, BSUM, C, CON1, CON2, &\n CON548,CR,CRZ32, DFI,ELIM, DR,FI, FLGJY, FN, FNU, &\n FN2, GAMA, PHI, RCZ, RDEN, RELB, RFN2, RTZ, RZDEN, &\n SA, SB, SUMA, SUMB, S1, TA, TAU, TB, TFN, TOL, TOLS, T2, UPOL, &\n WK, X, XX, Y, Z, Z32\n DOUBLE PRECISION D1MACH\n DIMENSION Y(*), WK(*), C(65)\n DIMENSION ALFA(26,4), BETA(26,5)\n DIMENSION ALFA1(26,2), ALFA2(26,2)\n DIMENSION BETA1(26,2), BETA2(26,2), BETA3(26,1)\n DIMENSION GAMA(26), KMAX(5), AR(8), BR(10), UPOL(10)\n DIMENSION CR(10), DR(10)\n EQUIVALENCE (ALFA(1,1),ALFA1(1,1))\n EQUIVALENCE (ALFA(1,3),ALFA2(1,1))\n EQUIVALENCE (BETA(1,1),BETA1(1,1))\n EQUIVALENCE (BETA(1,3),BETA2(1,1))\n EQUIVALENCE (BETA(1,5),BETA3(1,1))\n SAVE TOLS, CON1, CON2, CON548, AR, BR, C, &\n ALFA1, ALFA2, BETA1, BETA2, BETA3, GAMA\n DATA TOLS /-6.90775527898214D+00/\n DATA CON1,CON2,CON548/ &\n 6.66666666666667D-01, 3.33333333333333D-01, 1.04166666666667D-01/\n DATA AR(1), AR(2), AR(3), AR(4), AR(5), AR(6), AR(7), &\n AR(8) / 8.35503472222222D-02, 1.28226574556327D-01, &\n 2.91849026464140D-01, 8.81627267443758D-01, 3.32140828186277D+00, &\n 1.49957629868626D+01, 7.89230130115865D+01, 4.74451538868264D+02/\n DATA BR(1), BR(2), BR(3), BR(4), BR(5), BR(6), BR(7), BR(8), &\n BR(9), BR(10) /-1.45833333333333D-01,-9.87413194444444D-02, &\n -1.43312053915895D-01,-3.17227202678414D-01,-9.42429147957120D-01, &\n -3.51120304082635D+00,-1.57272636203680D+01,-8.22814390971859D+01, &\n -4.92355370523671D+02,-3.31621856854797D+03/\n DATA C(1), C(2), C(3), C(4), C(5), C(6), C(7), C(8), C(9), C(10), &\n C(11), C(12), C(13), C(14), C(15), C(16), C(17), C(18), &\n C(19), C(20), C(21), C(22), C(23), C(24)/ &\n -2.08333333333333D-01, 1.25000000000000D-01, &\n 3.34201388888889D-01, -4.01041666666667D-01, &\n 7.03125000000000D-02, -1.02581259645062D+00, &\n 1.84646267361111D+00, -8.91210937500000D-01, &\n 7.32421875000000D-02, 4.66958442342625D+00, &\n -1.12070026162230D+01, 8.78912353515625D+00, &\n -2.36408691406250D+00, 1.12152099609375D-01, &\n -2.82120725582002D+01, 8.46362176746007D+01, &\n -9.18182415432400D+01, 4.25349987453885D+01, &\n -7.36879435947963D+00, 2.27108001708984D-01, &\n 2.12570130039217D+02, -7.65252468141182D+02, &\n 1.05999045252800D+03, -6.99579627376133D+02/\n DATA C(25), C(26), C(27), C(28), C(29), C(30), C(31), C(32), &\n C(33), C(34), C(35), C(36), C(37), C(38), C(39), C(40), &\n C(41), C(42), C(43), C(44), C(45), C(46), C(47), C(48)/ &\n 2.18190511744212D+02, -2.64914304869516D+01, &\n 5.72501420974731D-01, -1.91945766231841D+03, &\n 8.06172218173731D+03, -1.35865500064341D+04, &\n 1.16553933368645D+04, -5.30564697861340D+03, &\n 1.20090291321635D+03, -1.08090919788395D+02, &\n 1.72772750258446D+00, 2.02042913309661D+04, &\n -9.69805983886375D+04, 1.92547001232532D+05, &\n -2.03400177280416D+05, 1.22200464983017D+05, &\n -4.11926549688976D+04, 7.10951430248936D+03, &\n -4.93915304773088D+02, 6.07404200127348D+00, &\n -2.42919187900551D+05, 1.31176361466298D+06, &\n -2.99801591853811D+06, 3.76327129765640D+06/\n DATA C(49), C(50), C(51), C(52), C(53), C(54), C(55), C(56), &\n C(57), C(58), C(59), C(60), C(61), C(62), C(63), C(64), &\n C(65)/ &\n -2.81356322658653D+06, 1.26836527332162D+06, &\n -3.31645172484564D+05, 4.52187689813627D+04, &\n -2.49983048181121D+03, 2.43805296995561D+01, &\n 3.28446985307204D+06, -1.97068191184322D+07, &\n 5.09526024926646D+07, -7.41051482115327D+07, &\n 6.63445122747290D+07, -3.75671766607634D+07, &\n 1.32887671664218D+07, -2.78561812808645D+06, &\n 3.08186404612662D+05, -1.38860897537170D+04, &\n 1.10017140269247D+02/\n DATA ALFA1(1,1), ALFA1(2,1), ALFA1(3,1), ALFA1(4,1), ALFA1(5,1), &\n ALFA1(6,1), ALFA1(7,1), ALFA1(8,1), ALFA1(9,1), ALFA1(10,1), &\n ALFA1(11,1),ALFA1(12,1),ALFA1(13,1),ALFA1(14,1),ALFA1(15,1), &\n ALFA1(16,1),ALFA1(17,1),ALFA1(18,1),ALFA1(19,1),ALFA1(20,1), &\n ALFA1(21,1),ALFA1(22,1),ALFA1(23,1),ALFA1(24,1),ALFA1(25,1), &\n ALFA1(26,1) /-4.44444444444444D-03,-9.22077922077922D-04, &\n -8.84892884892885D-05, 1.65927687832450D-04, 2.46691372741793D-04, &\n 2.65995589346255D-04, 2.61824297061501D-04, 2.48730437344656D-04, &\n 2.32721040083232D-04, 2.16362485712365D-04, 2.00738858762752D-04, &\n 1.86267636637545D-04, 1.73060775917876D-04, 1.61091705929016D-04, &\n 1.50274774160908D-04, 1.40503497391270D-04, 1.31668816545923D-04, &\n 1.23667445598253D-04, 1.16405271474738D-04, 1.09798298372713D-04, &\n 1.03772410422993D-04, 9.82626078369363D-05, 9.32120517249503D-05, &\n 8.85710852478712D-05, 8.42963105715700D-05, 8.03497548407791D-05/\n DATA ALFA1(1,2), ALFA1(2,2), ALFA1(3,2), ALFA1(4,2), ALFA1(5,2), &\n ALFA1(6,2), ALFA1(7,2), ALFA1(8,2), ALFA1(9,2), ALFA1(10,2), &\n ALFA1(11,2),ALFA1(12,2),ALFA1(13,2),ALFA1(14,2),ALFA1(15,2), &\n ALFA1(16,2),ALFA1(17,2),ALFA1(18,2),ALFA1(19,2),ALFA1(20,2), &\n ALFA1(21,2),ALFA1(22,2),ALFA1(23,2),ALFA1(24,2),ALFA1(25,2), &\n ALFA1(26,2) / 6.93735541354589D-04, 2.32241745182922D-04, &\n -1.41986273556691D-05,-1.16444931672049D-04,-1.50803558053049D-04, &\n -1.55121924918096D-04,-1.46809756646466D-04,-1.33815503867491D-04, &\n -1.19744975684254D-04,-1.06184319207974D-04,-9.37699549891194D-05, &\n -8.26923045588193D-05,-7.29374348155221D-05,-6.44042357721016D-05, &\n -5.69611566009369D-05,-5.04731044303562D-05,-4.48134868008883D-05, &\n -3.98688727717599D-05,-3.55400532972042D-05,-3.17414256609022D-05, &\n -2.83996793904175D-05,-2.54522720634871D-05,-2.28459297164725D-05, &\n -2.05352753106481D-05,-1.84816217627666D-05,-1.66519330021394D-05/\n DATA ALFA2(1,1), ALFA2(2,1), ALFA2(3,1), ALFA2(4,1), ALFA2(5,1), &\n ALFA2(6,1), ALFA2(7,1), ALFA2(8,1), ALFA2(9,1), ALFA2(10,1), &\n ALFA2(11,1),ALFA2(12,1),ALFA2(13,1),ALFA2(14,1),ALFA2(15,1), &\n ALFA2(16,1),ALFA2(17,1),ALFA2(18,1),ALFA2(19,1),ALFA2(20,1), &\n ALFA2(21,1),ALFA2(22,1),ALFA2(23,1),ALFA2(24,1),ALFA2(25,1), &\n ALFA2(26,1) /-3.54211971457744D-04,-1.56161263945159D-04, &\n 3.04465503594936D-05, 1.30198655773243D-04, 1.67471106699712D-04, &\n 1.70222587683593D-04, 1.56501427608595D-04, 1.36339170977445D-04, &\n 1.14886692029825D-04, 9.45869093034688D-05, 7.64498419250898D-05, &\n 6.07570334965197D-05, 4.74394299290509D-05, 3.62757512005344D-05, &\n 2.69939714979225D-05, 1.93210938247939D-05, 1.30056674793963D-05, &\n 7.82620866744497D-06, 3.59257485819352D-06, 1.44040049814252D-07, &\n -2.65396769697939D-06,-4.91346867098486D-06,-6.72739296091248D-06, &\n -8.17269379678658D-06,-9.31304715093561D-06,-1.02011418798016D-05/\n DATA ALFA2(1,2), ALFA2(2,2), ALFA2(3,2), ALFA2(4,2), ALFA2(5,2), &\n ALFA2(6,2), ALFA2(7,2), ALFA2(8,2), ALFA2(9,2), ALFA2(10,2), &\n ALFA2(11,2),ALFA2(12,2),ALFA2(13,2),ALFA2(14,2),ALFA2(15,2), &\n ALFA2(16,2),ALFA2(17,2),ALFA2(18,2),ALFA2(19,2),ALFA2(20,2), &\n ALFA2(21,2),ALFA2(22,2),ALFA2(23,2),ALFA2(24,2),ALFA2(25,2), &\n ALFA2(26,2) / 3.78194199201773D-04, 2.02471952761816D-04, &\n -6.37938506318862D-05,-2.38598230603006D-04,-3.10916256027362D-04, &\n -3.13680115247576D-04,-2.78950273791323D-04,-2.28564082619141D-04, &\n -1.75245280340847D-04,-1.25544063060690D-04,-8.22982872820208D-05, &\n -4.62860730588116D-05,-1.72334302366962D-05, 5.60690482304602D-06, &\n 2.31395443148287D-05, 3.62642745856794D-05, 4.58006124490189D-05, &\n 5.24595294959114D-05, 5.68396208545815D-05, 5.94349820393104D-05, &\n 6.06478527578422D-05, 6.08023907788436D-05, 6.01577894539460D-05, &\n 5.89199657344698D-05, 5.72515823777593D-05, 5.52804375585853D-05/\n DATA BETA1(1,1), BETA1(2,1), BETA1(3,1), BETA1(4,1), BETA1(5,1), &\n BETA1(6,1), BETA1(7,1), BETA1(8,1), BETA1(9,1), BETA1(10,1), &\n BETA1(11,1),BETA1(12,1),BETA1(13,1),BETA1(14,1),BETA1(15,1), &\n BETA1(16,1),BETA1(17,1),BETA1(18,1),BETA1(19,1),BETA1(20,1), &\n BETA1(21,1),BETA1(22,1),BETA1(23,1),BETA1(24,1),BETA1(25,1), &\n BETA1(26,1) / 1.79988721413553D-02, 5.59964911064388D-03, &\n 2.88501402231133D-03, 1.80096606761054D-03, 1.24753110589199D-03, &\n 9.22878876572938D-04, 7.14430421727287D-04, 5.71787281789705D-04, &\n 4.69431007606482D-04, 3.93232835462917D-04, 3.34818889318298D-04, &\n 2.88952148495752D-04, 2.52211615549573D-04, 2.22280580798883D-04, &\n 1.97541838033063D-04, 1.76836855019718D-04, 1.59316899661821D-04, &\n 1.44347930197334D-04, 1.31448068119965D-04, 1.20245444949303D-04, &\n 1.10449144504599D-04, 1.01828770740567D-04, 9.41998224204238D-05, &\n 8.74130545753834D-05, 8.13466262162801D-05, 7.59002269646219D-05/\n DATA BETA1(1,2), BETA1(2,2), BETA1(3,2), BETA1(4,2), BETA1(5,2), &\n BETA1(6,2), BETA1(7,2), BETA1(8,2), BETA1(9,2), BETA1(10,2), &\n BETA1(11,2),BETA1(12,2),BETA1(13,2),BETA1(14,2),BETA1(15,2), &\n BETA1(16,2),BETA1(17,2),BETA1(18,2),BETA1(19,2),BETA1(20,2), &\n BETA1(21,2),BETA1(22,2),BETA1(23,2),BETA1(24,2),BETA1(25,2), &\n BETA1(26,2) /-1.49282953213429D-03,-8.78204709546389D-04, &\n -5.02916549572035D-04,-2.94822138512746D-04,-1.75463996970783D-04, &\n -1.04008550460816D-04,-5.96141953046458D-05,-3.12038929076098D-05, &\n -1.26089735980230D-05,-2.42892608575730D-07, 8.05996165414274D-06, &\n 1.36507009262147D-05, 1.73964125472926D-05, 1.98672978842134D-05, &\n 2.14463263790823D-05, 2.23954659232457D-05, 2.28967783814713D-05, &\n 2.30785389811178D-05, 2.30321976080909D-05, 2.28236073720349D-05, &\n 2.25005881105292D-05, 2.20981015361991D-05, 2.16418427448104D-05, &\n 2.11507649256221D-05, 2.06388749782171D-05, 2.01165241997082D-05/\n DATA BETA2(1,1), BETA2(2,1), BETA2(3,1), BETA2(4,1), BETA2(5,1), &\n BETA2(6,1), BETA2(7,1), BETA2(8,1), BETA2(9,1), BETA2(10,1), &\n BETA2(11,1),BETA2(12,1),BETA2(13,1),BETA2(14,1),BETA2(15,1), &\n BETA2(16,1),BETA2(17,1),BETA2(18,1),BETA2(19,1),BETA2(20,1), &\n BETA2(21,1),BETA2(22,1),BETA2(23,1),BETA2(24,1),BETA2(25,1), &\n BETA2(26,1) / 5.52213076721293D-04, 4.47932581552385D-04, &\n 2.79520653992021D-04, 1.52468156198447D-04, 6.93271105657044D-05, &\n 1.76258683069991D-05,-1.35744996343269D-05,-3.17972413350427D-05, &\n -4.18861861696693D-05,-4.69004889379141D-05,-4.87665447413787D-05, &\n -4.87010031186735D-05,-4.74755620890087D-05,-4.55813058138628D-05, &\n -4.33309644511266D-05,-4.09230193157750D-05,-3.84822638603221D-05, &\n -3.60857167535411D-05,-3.37793306123367D-05,-3.15888560772110D-05, &\n -2.95269561750807D-05,-2.75978914828336D-05,-2.58006174666884D-05, &\n -2.41308356761280D-05,-2.25823509518346D-05,-2.11479656768913D-05/\n DATA BETA2(1,2), BETA2(2,2), BETA2(3,2), BETA2(4,2), BETA2(5,2), &\n BETA2(6,2), BETA2(7,2), BETA2(8,2), BETA2(9,2), BETA2(10,2), &\n BETA2(11,2),BETA2(12,2),BETA2(13,2),BETA2(14,2),BETA2(15,2), &\n BETA2(16,2),BETA2(17,2),BETA2(18,2),BETA2(19,2),BETA2(20,2), &\n BETA2(21,2),BETA2(22,2),BETA2(23,2),BETA2(24,2),BETA2(25,2), &\n BETA2(26,2) /-4.74617796559960D-04,-4.77864567147321D-04, &\n -3.20390228067038D-04,-1.61105016119962D-04,-4.25778101285435D-05, &\n 3.44571294294968D-05, 7.97092684075675D-05, 1.03138236708272D-04, &\n 1.12466775262204D-04, 1.13103642108481D-04, 1.08651634848774D-04, &\n 1.01437951597662D-04, 9.29298396593364D-05, 8.40293133016090D-05, &\n 7.52727991349134D-05, 6.69632521975731D-05, 5.92564547323195D-05, &\n 5.22169308826976D-05, 4.58539485165361D-05, 4.01445513891487D-05, &\n 3.50481730031328D-05, 3.05157995034347D-05, 2.64956119950516D-05, &\n 2.29363633690998D-05, 1.97893056664022D-05, 1.70091984636413D-05/\n DATA BETA3(1,1), BETA3(2,1), BETA3(3,1), BETA3(4,1), BETA3(5,1), &\n BETA3(6,1), BETA3(7,1), BETA3(8,1), BETA3(9,1), BETA3(10,1), &\n BETA3(11,1),BETA3(12,1),BETA3(13,1),BETA3(14,1),BETA3(15,1), &\n BETA3(16,1),BETA3(17,1),BETA3(18,1),BETA3(19,1),BETA3(20,1), &\n BETA3(21,1),BETA3(22,1),BETA3(23,1),BETA3(24,1),BETA3(25,1), &\n BETA3(26,1) / 7.36465810572578D-04, 8.72790805146194D-04, &\n 6.22614862573135D-04, 2.85998154194304D-04, 3.84737672879366D-06, &\n -1.87906003636972D-04,-2.97603646594555D-04,-3.45998126832656D-04, &\n -3.53382470916038D-04,-3.35715635775049D-04,-3.04321124789040D-04, &\n -2.66722723047613D-04,-2.27654214122820D-04,-1.89922611854562D-04, &\n -1.55058918599094D-04,-1.23778240761874D-04,-9.62926147717644D-05, &\n -7.25178327714425D-05,-5.22070028895634D-05,-3.50347750511901D-05, &\n -2.06489761035552D-05,-8.70106096849767D-06, 1.13698686675100D-06, &\n 9.16426474122779D-06, 1.56477785428873D-05, 2.08223629482467D-05/\n DATA GAMA(1), GAMA(2), GAMA(3), GAMA(4), GAMA(5), &\n GAMA(6), GAMA(7), GAMA(8), GAMA(9), GAMA(10), &\n GAMA(11), GAMA(12), GAMA(13), GAMA(14), GAMA(15), &\n GAMA(16), GAMA(17), GAMA(18), GAMA(19), GAMA(20), &\n GAMA(21), GAMA(22), GAMA(23), GAMA(24), GAMA(25), &\n GAMA(26) / 6.29960524947437D-01, 2.51984209978975D-01, &\n 1.54790300415656D-01, 1.10713062416159D-01, 8.57309395527395D-02, &\n 6.97161316958684D-02, 5.86085671893714D-02, 5.04698873536311D-02, &\n 4.42600580689155D-02, 3.93720661543510D-02, 3.54283195924455D-02, &\n 3.21818857502098D-02, 2.94646240791158D-02, 2.71581677112934D-02, &\n 2.51768272973862D-02, 2.34570755306079D-02, 2.19508390134907D-02, &\n 2.06210828235646D-02, 1.94388240897881D-02, 1.83810633800683D-02, &\n 1.74293213231963D-02, 1.65685837786612D-02, 1.57865285987918D-02, &\n 1.50729501494096D-02, 1.44193250839955D-02, 1.38184805735342D-02/\n!***FIRST EXECUTABLE STATEMENT DASYJY\n TA = D1MACH(3)\n TOL = MAX(TA,1.0D-15)\n TB = D1MACH(5)\n JU = I1MACH(15)\n if ( FLGJY == 1.0D0) go to 6\n JR = I1MACH(14)\n ELIM = -2.303D0*TB*(JU+JR)\n go to 7\n 6 CONTINUE\n ELIM = -2.303D0*(TB*JU+3.0D0)\n 7 CONTINUE\n FN = FNU\n IFLW = 0\n DO 170 JN=1,IN\n XX = X/FN\n WK(1) = 1.0D0 - XX*XX\n ABW2 = ABS(WK(1))\n WK(2) = SQRT(ABW2)\n WK(7) = FN**CON2\n if (ABW2 > 0.27750D0) go to 80\n!\n! ASYMPTOTIC EXPANSION\n! CASES NEAR X=FN, ABS(1.-(X/FN)**2) <= 0.2775\n! COEFFICIENTS OF ASYMPTOTIC EXPANSION BY SERIES\n!\n! ZETA AND TRUNCATION FOR A(ZETA) AND B(ZETA) SERIES\n!\n! KMAX IS TRUNCATION INDEX FOR A(ZETA) AND B(ZETA) SERIES=MAX(2,SA)\n!\n SA = 0.0D0\n if (ABW2 == 0.0D0) go to 10\n SA = TOLS/LOG(ABW2)\n 10 SB = SA\n DO 20 I=1,5\n AKM = MAX(SA,2.0D0)\n KMAX(I) = INT(AKM)\n SA = SA + SB\n 20 CONTINUE\n KB = KMAX(5)\n KLAST = KB - 1\n SA = GAMA(KB)\n DO 30 K=1,KLAST\n KB = KB - 1\n SA = SA*WK(1) + GAMA(KB)\n 30 CONTINUE\n Z = WK(1)*SA\n AZ = ABS(Z)\n RTZ = SQRT(AZ)\n WK(3) = CON1*AZ*RTZ\n WK(4) = WK(3)*FN\n WK(5) = RTZ*WK(7)\n WK(6) = -WK(5)*WK(5)\n if ( Z <= 0.0D0) go to 35\n if ( WK(4) > ELIM) go to 75\n WK(6) = -WK(6)\n 35 CONTINUE\n PHI = SQRT(SQRT(SA+SA+SA+SA))\n!\n! B(ZETA) FOR S=0\n!\n KB = KMAX(5)\n KLAST = KB - 1\n SB = BETA(KB,1)\n DO 40 K=1,KLAST\n KB = KB - 1\n SB = SB*WK(1) + BETA(KB,1)\n 40 CONTINUE\n KSP1 = 1\n FN2 = FN*FN\n RFN2 = 1.0D0/FN2\n RDEN = 1.0D0\n ASUM = 1.0D0\n RELB = TOL*ABS(SB)\n BSUM = SB\n DO 60 KS=1,4\n KSP1 = KSP1 + 1\n RDEN = RDEN*RFN2\n!\n! A(ZETA) AND B(ZETA) FOR S=1,2,3,4\n!\n KSTEMP = 5 - KS\n KB = KMAX(KSTEMP)\n KLAST = KB - 1\n SA = ALFA(KB,KS)\n SB = BETA(KB,KSP1)\n DO 50 K=1,KLAST\n KB = KB - 1\n SA = SA*WK(1) + ALFA(KB,KS)\n SB = SB*WK(1) + BETA(KB,KSP1)\n 50 CONTINUE\n TA = SA*RDEN\n TB = SB*RDEN\n ASUM = ASUM + TA\n BSUM = BSUM + TB\n if (ABS(TA) <= TOL .AND. ABS(TB) <= RELB) go to 70\n 60 CONTINUE\n 70 CONTINUE\n BSUM = BSUM/(FN*WK(7))\n go to 160\n!\n 75 CONTINUE\n IFLW = 1\n return\n!\n 80 CONTINUE\n UPOL(1) = 1.0D0\n TAU = 1.0D0/WK(2)\n T2 = 1.0D0/WK(1)\n if (WK(1) >= 0.0D0) go to 90\n!\n! CASES FOR (X/FN) > SQRT(1.2775)\n!\n WK(3) = ABS(WK(2)-ATAN(WK(2)))\n WK(4) = WK(3)*FN\n RCZ = -CON1/WK(4)\n Z32 = 1.5D0*WK(3)\n RTZ = Z32**CON2\n WK(5) = RTZ*WK(7)\n WK(6) = -WK(5)*WK(5)\n go to 100\n 90 CONTINUE\n!\n! CASES FOR (X/FN) < SQRT(0.7225)\n!\n WK(3) = ABS(LOG((1.0D0+WK(2))/XX)-WK(2))\n WK(4) = WK(3)*FN\n RCZ = CON1/WK(4)\n if ( WK(4) > ELIM) go to 75\n Z32 = 1.5D0*WK(3)\n RTZ = Z32**CON2\n WK(7) = FN**CON2\n WK(5) = RTZ*WK(7)\n WK(6) = WK(5)*WK(5)\n 100 CONTINUE\n PHI = SQRT((RTZ+RTZ)*TAU)\n TB = 1.0D0\n ASUM = 1.0D0\n TFN = TAU/FN\n RDEN=1.0D0/FN\n RFN2=RDEN*RDEN\n RDEN=1.0D0\n UPOL(2) = (C(1)*T2+C(2))*TFN\n CRZ32 = CON548*RCZ\n BSUM = UPOL(2) + CRZ32\n RELB = TOL*ABS(BSUM)\n AP = TFN\n KS = 0\n KP1 = 2\n RZDEN = RCZ\n L = 2\n ISETA=0\n ISETB=0\n DO 140 LR=2,8,2\n!\n! COMPUTE TWO U POLYNOMIALS FOR NEXT A(ZETA) AND B(ZETA)\n!\n LRP1 = LR + 1\n DO 120 K=LR,LRP1\n KS = KS + 1\n KP1 = KP1 + 1\n L = L + 1\n S1 = C(L)\n DO 110 J=2,KP1\n L = L + 1\n S1 = S1*T2 + C(L)\n 110 CONTINUE\n AP = AP*TFN\n UPOL(KP1) = AP*S1\n CR(KS) = BR(KS)*RZDEN\n RZDEN = RZDEN*RCZ\n DR(KS) = AR(KS)*RZDEN\n 120 CONTINUE\n SUMA = UPOL(LRP1)\n SUMB = UPOL(LR+2) + UPOL(LRP1)*CRZ32\n JU = LRP1\n DO 130 JR=1,LR\n JU = JU - 1\n SUMA = SUMA + CR(JR)*UPOL(JU)\n SUMB = SUMB + DR(JR)*UPOL(JU)\n 130 CONTINUE\n RDEN=RDEN*RFN2\n TB = -TB\n if (WK(1) > 0.0D0) TB = ABS(TB)\n if ( RDEN < TOL) go to 131\n ASUM = ASUM + SUMA*TB\n BSUM = BSUM + SUMB*TB\n go to 140\n 131 if ( ISETA == 1) go to 132\n if ( ABS(SUMA) < TOL) ISETA=1\n ASUM=ASUM+SUMA*TB\n 132 if ( ISETB == 1) go to 133\n if ( ABS(SUMB) < RELB) ISETB=1\n BSUM=BSUM+SUMB*TB\n 133 if ( ISETA == 1 .AND. ISETB == 1) go to 150\n 140 CONTINUE\n 150 TB = WK(5)\n if (WK(1) > 0.0D0) TB = -TB\n BSUM = BSUM/TB\n!\n 160 CONTINUE\n call FUNJY(WK(6), WK(5), WK(4), FI, DFI)\n TA=1.0D0/TOL\n TB=D1MACH(1)*TA*1.0D+3\n if ( ABS(FI) > TB) go to 165\n FI=FI*TA\n DFI=DFI*TA\n PHI=PHI*TOL\n 165 CONTINUE\n Y(JN) = FLGJY*PHI*(FI*ASUM+DFI*BSUM)/WK(7)\n FN = FN - FLGJY\n 170 CONTINUE\n return\nend\n\n\n!!! UPDATED I1MACH FUNCTION TAKEN FROM \n!!! http://www.nsc.liu.se/~boein/ifip/kyoto/workshop-info/proceedings/einarsson/f90/i1mach.f90\n!!! NB: DIFFERENT FROM THE VERSION IN BURKHARDT PORT!\n\n\n!DECK I1MACH\n INTEGER FUNCTION I1MACH (I)\n IMPLICIT NONE\n INTEGER :: I\n REAL :: X\n DOUBLE PRECISION :: XX\n!***BEGIN PROLOGUE I1MACH\n!***PURPOSE Return integer machine dependent constants.\n!***LIBRARY SLATEC\n!***CATEGORY R1\n!***TYPE INTEGER (I1MACH-I)\n!***KEYWORDS MACHINE CONSTANTS\n!***AUTHOR Fox, P. A., (Bell Labs)\n! Hall, A. D., (Bell Labs)\n! Schryer, N. L., (Bell Labs)\n!***DESCRIPTION\n!\n! I1MACH can be used to obtain machine-dependent parameters for the\n! local machine environment. It is a function subprogram with one\n! (input) argument and can be referenced as follows:\n!\n! K = I1MACH(I)\n!\n! where I=1,...,16. The (output) value of K above is determined by\n! the (input) value of I. The results for various values of I are\n! discussed below.\n!\n! I/O unit numbers:\n! I1MACH( 1) = the standard input unit.\n! I1MACH( 2) = the standard output unit.\n! I1MACH( 3) = the standard punch unit.\n! I1MACH( 4) = the standard error message unit.\n!\n! Words:\n! I1MACH( 5) = the number of bits per integer storage unit.\n! I1MACH( 6) = the number of characters per integer storage unit.\n!\n! Integers:\n! assume integers are represented in the S-digit, base-A form\n!\n! sign ( X(S-1)*A**(S-1) + ... + X(1)*A + X(0) )\n!\n! where 0 .LE. X(I) .LT. A for I=0,...,S-1.\n! I1MACH( 7) = A, the base.\n! I1MACH( 8) = S, the number of base-A digits.\n! I1MACH( 9) = A**S - 1, the largest magnitude.\n!\n! Floating-Point Numbers:\n! Assume floating-point numbers are represented in the T-digit,\n! base-B form\n! sign (B**E)*( (X(1)/B) + ... + (X(T)/B**T) )\n!\n! where 0 .LE. X(I) .LT. B for I=1,...,T,\n! 0 .LT. X(1), and EMIN .LE. E .LE. EMAX.\n! I1MACH(10) = B, the base.\n!\n! Single-Precision:\n! I1MACH(11) = T, the number of base-B digits.\n! I1MACH(12) = EMIN, the smallest exponent E.\n! I1MACH(13) = EMAX, the largest exponent E.\n!\n! Double-Precision:\n! I1MACH(14) = T, the number of base-B digits.\n! I1MACH(15) = EMIN, the smallest exponent E.\n! I1MACH(16) = EMAX, the largest exponent E.\n!\n! To alter this function for a particular environment, the desired\n! set of DATA statements should be activated by removing the C from\n! column 1. Also, the values of I1MACH(1) - I1MACH(4) should be\n! checked for consistency with the local operating system.\n!\n!***REFERENCES P. A. Fox, A. D. Hall and N. L. Schryer, Framework for\n! a portable library, ACM Transactions on Mathematical\n! Software 4, 2 (June 1978), pp. 177-188.\n!***ROUTINES CALLED (NONE)\n!***REVISION HISTORY (YYMMDD)\n! 750101 DATE WRITTEN\n! 960411 Modified for Fortran 90 (BE after suggestions by EHG). \n! 980727 Modified value of I1MACH(6) (BE after suggestion by EHG). \n!***END PROLOGUE I1MACH\n!\n X = 1.0 \n XX = 1.0D0\n\n SELECT CASE (I)\n CASE (1)\n I1MACH = 5 ! Input unit\n CASE (2)\n I1MACH = 6 ! Output unit\n CASE (3)\n I1MACH = 0 ! Punch unit is no longer used\n CASE (4)\n I1MACH = 0 ! Error message unit\n CASE (5)\n I1MACH = BIT_SIZE(I)\n CASE (6)\n I1MACH = 4 ! Characters per integer is hopefully no\n ! longer used. \n ! If it is used it has to be set manually.\n ! The value 4 is correct on IEEE-machines.\n CASE (7)\n I1MACH = RADIX(1)\n CASE (8)\n I1MACH = BIT_SIZE(I) - 1\n CASE (9)\n I1MACH = HUGE(1)\n CASE (10)\n I1MACH = RADIX(X)\n CASE (11)\n I1MACH = DIGITS(X)\n CASE (12)\n I1MACH = MINEXPONENT(X)\n CASE (13)\n I1MACH = MAXEXPONENT(X)\n CASE (14)\n I1MACH = DIGITS(XX)\n CASE (15)\n I1MACH = MINEXPONENT(XX)\n CASE (16)\n I1MACH = MAXEXPONENT(XX) \n CASE DEFAULT\n WRITE (*, FMT = 9000)\n 9000 FORMAT ('1ERROR 1 IN I1MACH - I OUT OF BOUNDS')\n STOP\n END SELECT\n RETURN\n END\n\n\n! FUNCTION I1MACH (I)\n! !\n! !! I1MACH returns integer machine dependent constants.\n! !\n! !***LIBRARY SLATEC\n! !***CATEGORY R1\n! !***TYPE INTEGER (I1MACH-I)\n! !***KEYWORDS MACHINE CONSTANTS\n! !***AUTHOR Fox, P. A., (Bell Labs)\n! ! Hall, A. D., (Bell Labs)\n! ! Schryer, N. L., (Bell Labs)\n! !***DESCRIPTION\n! !\n! ! I1MACH can be used to obtain machine-dependent parameters for the\n! ! local machine environment. It is a function subprogram with one\n! ! (input) argument and can be referenced as follows:\n! !\n! ! K = I1MACH(I)\n! !\n! ! where I=1,...,16. The (output) value of K above is determined by\n! ! the (input) value of I. The results for various values of I are\n! ! discussed below.\n! !\n! ! I/O unit numbers:\n! ! I1MACH( 1) = the standard input unit.\n! ! I1MACH( 2) = the standard output unit.\n! ! I1MACH( 3) = the standard punch unit.\n! ! I1MACH( 4) = the standard error message unit.\n! !\n! ! Words:\n! ! I1MACH( 5) = the number of bits per integer storage unit.\n! ! I1MACH( 6) = the number of characters per integer storage unit.\n! !\n! ! Integers:\n! ! assume integers are represented in the S-digit, base-A form\n! !\n! ! sign ( X(S-1)*A**(S-1) + ... + X(1)*A + X(0) )\n! !\n! ! where 0 <= X(I) < A for I=0,...,S-1.\n! ! I1MACH( 7) = A, the base.\n! ! I1MACH( 8) = S, the number of base-A digits.\n! ! I1MACH( 9) = A**S - 1, the largest magnitude.\n! !\n! ! Floating-Point Numbers:\n! ! Assume floating-point numbers are represented in the T-digit,\n! ! base-B form\n! ! sign (B**E)*( (X(1)/B) + ... + (X(T)/B**T) )\n! !\n! ! where 0 <= X(I) < B for I=1,...,T,\n! ! 0 < X(1), and EMIN <= E <= EMAX.\n! ! I1MACH(10) = B, the base.\n! !\n! ! Single-Precision:\n! ! I1MACH(11) = T, the number of base-B digits.\n! ! I1MACH(12) = EMIN, the smallest exponent E.\n! ! I1MACH(13) = EMAX, the largest exponent E.\n! !\n! ! Double-Precision:\n! ! I1MACH(14) = T, the number of base-B digits.\n! ! I1MACH(15) = EMIN, the smallest exponent E.\n! ! I1MACH(16) = EMAX, the largest exponent E.\n! !\n! ! To alter this function for a particular environment, the desired\n! ! set of DATA statements should be activated by removing the C from\n! ! column 1. Also, the values of I1MACH(1) - I1MACH(4) should be\n! ! checked for consistency with the local operating system.\n! !\n! !***REFERENCES P. A. Fox, A. D. Hall and N. L. Schryer, Framework for\n! ! a portable library, ACM Transactions on Mathematical\n! ! Software 4, 2 (June 1978), pp. 177-188.\n! !***ROUTINES CALLED (NONE)\n! !***REVISION HISTORY (YYMMDD)\n! ! 750101 DATE WRITTEN\n! ! 891012 Added VAX G-floating constants. (WRB)\n! ! 891012 REVISION DATE from Version 3.2\n! ! 891214 Prologue converted to Version 4.0 format. (BAB)\n! ! 900618 Added DEC RISC constants. (WRB)\n! ! 900723 Added IBM RS 6000 constants. (WRB)\n! ! 901009 Correct I1MACH(7) for IBM Mainframes. Should be 2 not 16.\n! ! (RWC)\n! ! 910710 Added HP 730 constants. (SMR)\n! ! 911114 Added Convex IEEE constants. (WRB)\n! ! 920121 Added SUN -r8 compiler option constants. (WRB)\n! ! 920229 Added Touchstone Delta i860 constants. (WRB)\n! ! 920501 Reformatted the REFERENCES section. (WRB)\n! ! 920625 Added Convex -p8 and -pd8 compiler option constants.\n! ! (BKS, WRB)\n! ! 930201 Added DEC Alpha and SGI constants. (RWC and WRB)\n! ! 930618 Corrected I1MACH(5) for Convex -p8 and -pd8 compiler\n! ! options. (DWL, RWC and WRB).\n! !***END PROLOGUE I1MACH\n! !\n! integer i1mach\n! INTEGER IMACH(16),OUTPUT\n! SAVE IMACH\n! EQUIVALENCE (IMACH(4),OUTPUT)\n! !\n! ! MACHINE CONSTANTS FOR THE AMIGA\n! ! ABSOFT COMPILER\n! !\n! ! DATA IMACH( 1) / 5 /\n! ! DATA IMACH( 2) / 6 /\n! ! DATA IMACH( 3) / 5 /\n! ! DATA IMACH( 4) / 6 /\n! ! DATA IMACH( 5) / 32 /\n! ! DATA IMACH( 6) / 4 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 31 /\n! ! DATA IMACH( 9) / 2147483647 /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 24 /\n! ! DATA IMACH(12) / -126 /\n! ! DATA IMACH(13) / 127 /\n! ! DATA IMACH(14) / 53 /\n! ! DATA IMACH(15) / -1022 /\n! ! DATA IMACH(16) / 1023 /\n! !\n! ! MACHINE CONSTANTS FOR THE APOLLO\n! !\n! ! DATA IMACH( 1) / 5 /\n! ! DATA IMACH( 2) / 6 /\n! ! DATA IMACH( 3) / 6 /\n! ! DATA IMACH( 4) / 6 /\n! ! DATA IMACH( 5) / 32 /\n! ! DATA IMACH( 6) / 4 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 31 /\n! ! DATA IMACH( 9) / 2147483647 /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 24 /\n! ! DATA IMACH(12) / -125 /\n! ! DATA IMACH(13) / 129 /\n! ! DATA IMACH(14) / 53 /\n! ! DATA IMACH(15) / -1021 /\n! ! DATA IMACH(16) / 1025 /\n! !\n! ! MACHINE CONSTANTS FOR THE BURROUGHS 1700 SYSTEM\n! !\n! ! DATA IMACH( 1) / 7 /\n! ! DATA IMACH( 2) / 2 /\n! ! DATA IMACH( 3) / 2 /\n! ! DATA IMACH( 4) / 2 /\n! ! DATA IMACH( 5) / 36 /\n! ! DATA IMACH( 6) / 4 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 33 /\n! ! DATA IMACH( 9) / Z1FFFFFFFF /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 24 /\n! ! DATA IMACH(12) / -256 /\n! ! DATA IMACH(13) / 255 /\n! ! DATA IMACH(14) / 60 /\n! ! DATA IMACH(15) / -256 /\n! ! DATA IMACH(16) / 255 /\n! !\n! ! MACHINE CONSTANTS FOR THE BURROUGHS 5700 SYSTEM\n! !\n! ! DATA IMACH( 1) / 5 /\n! ! DATA IMACH( 2) / 6 /\n! ! DATA IMACH( 3) / 7 /\n! ! DATA IMACH( 4) / 6 /\n! ! DATA IMACH( 5) / 48 /\n! ! DATA IMACH( 6) / 6 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 39 /\n! ! DATA IMACH( 9) / O0007777777777777 /\n! ! DATA IMACH(10) / 8 /\n! ! DATA IMACH(11) / 13 /\n! ! DATA IMACH(12) / -50 /\n! ! DATA IMACH(13) / 76 /\n! ! DATA IMACH(14) / 26 /\n! ! DATA IMACH(15) / -50 /\n! ! DATA IMACH(16) / 76 /\n! !\n! ! MACHINE CONSTANTS FOR THE BURROUGHS 6700/7700 SYSTEMS\n! !\n! ! DATA IMACH( 1) / 5 /\n! ! DATA IMACH( 2) / 6 /\n! ! DATA IMACH( 3) / 7 /\n! ! DATA IMACH( 4) / 6 /\n! ! DATA IMACH( 5) / 48 /\n! ! DATA IMACH( 6) / 6 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 39 /\n! ! DATA IMACH( 9) / O0007777777777777 /\n! ! DATA IMACH(10) / 8 /\n! ! DATA IMACH(11) / 13 /\n! ! DATA IMACH(12) / -50 /\n! ! DATA IMACH(13) / 76 /\n! ! DATA IMACH(14) / 26 /\n! ! DATA IMACH(15) / -32754 /\n! ! DATA IMACH(16) / 32780 /\n! !\n! ! MACHINE CONSTANTS FOR THE CDC 170/180 SERIES USING NOS/VE\n! !\n! ! DATA IMACH( 1) / 5 /\n! ! DATA IMACH( 2) / 6 /\n! ! DATA IMACH( 3) / 7 /\n! ! DATA IMACH( 4) / 6 /\n! ! DATA IMACH( 5) / 64 /\n! ! DATA IMACH( 6) / 8 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 63 /\n! ! DATA IMACH( 9) / 9223372036854775807 /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 47 /\n! ! DATA IMACH(12) / -4095 /\n! ! DATA IMACH(13) / 4094 /\n! ! DATA IMACH(14) / 94 /\n! ! DATA IMACH(15) / -4095 /\n! ! DATA IMACH(16) / 4094 /\n! !\n! ! MACHINE CONSTANTS FOR THE CDC 6000/7000 SERIES\n! !\n! ! DATA IMACH( 1) / 5 /\n! ! DATA IMACH( 2) / 6 /\n! ! DATA IMACH( 3) / 7 /\n! ! DATA IMACH( 4) / 6LOUTPUT/\n! ! DATA IMACH( 5) / 60 /\n! ! DATA IMACH( 6) / 10 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 48 /\n! ! DATA IMACH( 9) / 00007777777777777777B /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 47 /\n! ! DATA IMACH(12) / -929 /\n! ! DATA IMACH(13) / 1070 /\n! ! DATA IMACH(14) / 94 /\n! ! DATA IMACH(15) / -929 /\n! ! DATA IMACH(16) / 1069 /\n! !\n! ! MACHINE CONSTANTS FOR THE CELERITY C1260\n! !\n! ! DATA IMACH( 1) / 5 /\n! ! DATA IMACH( 2) / 6 /\n! ! DATA IMACH( 3) / 6 /\n! ! DATA IMACH( 4) / 0 /\n! ! DATA IMACH( 5) / 32 /\n! ! DATA IMACH( 6) / 4 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 31 /\n! ! DATA IMACH( 9) / Z'7FFFFFFF' /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 24 /\n! ! DATA IMACH(12) / -126 /\n! ! DATA IMACH(13) / 127 /\n! ! DATA IMACH(14) / 53 /\n! ! DATA IMACH(15) / -1022 /\n! ! DATA IMACH(16) / 1023 /\n! !\n! ! MACHINE CONSTANTS FOR THE CONVEX\n! ! USING THE -fn COMPILER OPTION\n! !\n! ! DATA IMACH( 1) / 5 /\n! ! DATA IMACH( 2) / 6 /\n! ! DATA IMACH( 3) / 7 /\n! ! DATA IMACH( 4) / 6 /\n! ! DATA IMACH( 5) / 32 /\n! ! DATA IMACH( 6) / 4 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 31 /\n! ! DATA IMACH( 9) / 2147483647 /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 24 /\n! ! DATA IMACH(12) / -127 /\n! ! DATA IMACH(13) / 127 /\n! ! DATA IMACH(14) / 53 /\n! ! DATA IMACH(15) / -1023 /\n! ! DATA IMACH(16) / 1023 /\n! !\n! ! MACHINE CONSTANTS FOR THE CONVEX\n! ! USING THE -fi COMPILER OPTION\n! !\n! ! DATA IMACH( 1) / 5 /\n! ! DATA IMACH( 2) / 6 /\n! ! DATA IMACH( 3) / 7 /\n! ! DATA IMACH( 4) / 6 /\n! ! DATA IMACH( 5) / 32 /\n! ! DATA IMACH( 6) / 4 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 31 /\n! ! DATA IMACH( 9) / 2147483647 /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 24 /\n! ! DATA IMACH(12) / -125 /\n! ! DATA IMACH(13) / 128 /\n! ! DATA IMACH(14) / 53 /\n! ! DATA IMACH(15) / -1021 /\n! ! DATA IMACH(16) / 1024 /\n! !\n! ! MACHINE CONSTANTS FOR THE CONVEX\n! ! USING THE -p8 COMPILER OPTION\n! !\n! ! DATA IMACH( 1) / 5 /\n! ! DATA IMACH( 2) / 6 /\n! ! DATA IMACH( 3) / 7 /\n! ! DATA IMACH( 4) / 6 /\n! ! DATA IMACH( 5) / 64 /\n! ! DATA IMACH( 6) / 4 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 63 /\n! ! DATA IMACH( 9) / 9223372036854775807 /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 53 /\n! ! DATA IMACH(12) / -1023 /\n! ! DATA IMACH(13) / 1023 /\n! ! DATA IMACH(14) / 113 /\n! ! DATA IMACH(15) / -16383 /\n! ! DATA IMACH(16) / 16383 /\n! !\n! ! MACHINE CONSTANTS FOR THE CONVEX\n! ! USING THE -pd8 COMPILER OPTION\n! !\n! ! DATA IMACH( 1) / 5 /\n! ! DATA IMACH( 2) / 6 /\n! ! DATA IMACH( 3) / 7 /\n! ! DATA IMACH( 4) / 6 /\n! ! DATA IMACH( 5) / 64 /\n! ! DATA IMACH( 6) / 4 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 63 /\n! ! DATA IMACH( 9) / 9223372036854775807 /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 53 /\n! ! DATA IMACH(12) / -1023 /\n! ! DATA IMACH(13) / 1023 /\n! ! DATA IMACH(14) / 53 /\n! ! DATA IMACH(15) / -1023 /\n! ! DATA IMACH(16) / 1023 /\n! !\n! ! MACHINE CONSTANTS FOR THE CRAY\n! ! USING THE 46 BIT INTEGER COMPILER OPTION\n! !\n! ! DATA IMACH( 1) / 100 /\n! ! DATA IMACH( 2) / 101 /\n! ! DATA IMACH( 3) / 102 /\n! ! DATA IMACH( 4) / 101 /\n! ! DATA IMACH( 5) / 64 /\n! ! DATA IMACH( 6) / 8 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 46 /\n! ! DATA IMACH( 9) / 1777777777777777B /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 47 /\n! ! DATA IMACH(12) / -8189 /\n! ! DATA IMACH(13) / 8190 /\n! ! DATA IMACH(14) / 94 /\n! ! DATA IMACH(15) / -8099 /\n! ! DATA IMACH(16) / 8190 /\n! !\n! ! MACHINE CONSTANTS FOR THE CRAY\n! ! USING THE 64 BIT INTEGER COMPILER OPTION\n! !\n! ! DATA IMACH( 1) / 100 /\n! ! DATA IMACH( 2) / 101 /\n! ! DATA IMACH( 3) / 102 /\n! ! DATA IMACH( 4) / 101 /\n! ! DATA IMACH( 5) / 64 /\n! ! DATA IMACH( 6) / 8 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 63 /\n! ! DATA IMACH( 9) / 777777777777777777777B /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 47 /\n! ! DATA IMACH(12) / -8189 /\n! ! DATA IMACH(13) / 8190 /\n! ! DATA IMACH(14) / 94 /\n! ! DATA IMACH(15) / -8099 /\n! ! DATA IMACH(16) / 8190 /\n! !\n! ! MACHINE CONSTANTS FOR THE DATA GENERAL ECLIPSE S/200\n! !\n! ! DATA IMACH( 1) / 11 /\n! ! DATA IMACH( 2) / 12 /\n! ! DATA IMACH( 3) / 8 /\n! ! DATA IMACH( 4) / 10 /\n! ! DATA IMACH( 5) / 16 /\n! ! DATA IMACH( 6) / 2 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 15 /\n! ! DATA IMACH( 9) / 32767 /\n! ! DATA IMACH(10) / 16 /\n! ! DATA IMACH(11) / 6 /\n! ! DATA IMACH(12) / -64 /\n! ! DATA IMACH(13) / 63 /\n! ! DATA IMACH(14) / 14 /\n! ! DATA IMACH(15) / -64 /\n! ! DATA IMACH(16) / 63 /\n! !\n! ! MACHINE CONSTANTS FOR THE DEC ALPHA\n! ! USING G_FLOAT\n! !\n! ! DATA IMACH( 1) / 5 /\n! ! DATA IMACH( 2) / 6 /\n! ! DATA IMACH( 3) / 5 /\n! ! DATA IMACH( 4) / 6 /\n! ! DATA IMACH( 5) / 32 /\n! ! DATA IMACH( 6) / 4 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 31 /\n! ! DATA IMACH( 9) / 2147483647 /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 24 /\n! ! DATA IMACH(12) / -127 /\n! ! DATA IMACH(13) / 127 /\n! ! DATA IMACH(14) / 53 /\n! ! DATA IMACH(15) / -1023 /\n! ! DATA IMACH(16) / 1023 /\n! !\n! ! MACHINE CONSTANTS FOR THE DEC ALPHA\n! ! USING IEEE_FLOAT\n! !\n! DATA IMACH( 1) / 5 /\n! DATA IMACH( 2) / 6 /\n! DATA IMACH( 3) / 6 /\n! DATA IMACH( 4) / 6 /\n! DATA IMACH( 5) / 32 /\n! DATA IMACH( 6) / 4 /\n! DATA IMACH( 7) / 2 /\n! DATA IMACH( 8) / 31 /\n! DATA IMACH( 9) / 2147483647 /\n! DATA IMACH(10) / 2 /\n! DATA IMACH(11) / 24 /\n! DATA IMACH(12) / -125 /\n! DATA IMACH(13) / 128 /\n! DATA IMACH(14) / 53 /\n! DATA IMACH(15) / -1021 /\n! DATA IMACH(16) / 1024 /\n! !\n! ! MACHINE CONSTANTS FOR THE DEC RISC\n! !\n! ! DATA IMACH( 1) / 5 /\n! ! DATA IMACH( 2) / 6 /\n! ! DATA IMACH( 3) / 6 /\n! ! DATA IMACH( 4) / 6 /\n! ! DATA IMACH( 5) / 32 /\n! ! DATA IMACH( 6) / 4 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 31 /\n! ! DATA IMACH( 9) / 2147483647 /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 24 /\n! ! DATA IMACH(12) / -125 /\n! ! DATA IMACH(13) / 128 /\n! ! DATA IMACH(14) / 53 /\n! ! DATA IMACH(15) / -1021 /\n! ! DATA IMACH(16) / 1024 /\n! !\n! ! MACHINE CONSTANTS FOR THE DEC VAX\n! ! USING D_FLOATING\n! !\n! ! DATA IMACH( 1) / 5 /\n! ! DATA IMACH( 2) / 6 /\n! ! DATA IMACH( 3) / 5 /\n! ! DATA IMACH( 4) / 6 /\n! ! DATA IMACH( 5) / 32 /\n! ! DATA IMACH( 6) / 4 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 31 /\n! ! DATA IMACH( 9) / 2147483647 /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 24 /\n! ! DATA IMACH(12) / -127 /\n! ! DATA IMACH(13) / 127 /\n! ! DATA IMACH(14) / 56 /\n! ! DATA IMACH(15) / -127 /\n! ! DATA IMACH(16) / 127 /\n! !\n! ! MACHINE CONSTANTS FOR THE DEC VAX\n! ! USING G_FLOATING\n! !\n! ! DATA IMACH( 1) / 5 /\n! ! DATA IMACH( 2) / 6 /\n! ! DATA IMACH( 3) / 5 /\n! ! DATA IMACH( 4) / 6 /\n! ! DATA IMACH( 5) / 32 /\n! ! DATA IMACH( 6) / 4 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 31 /\n! ! DATA IMACH( 9) / 2147483647 /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 24 /\n! ! DATA IMACH(12) / -127 /\n! ! DATA IMACH(13) / 127 /\n! ! DATA IMACH(14) / 53 /\n! ! DATA IMACH(15) / -1023 /\n! ! DATA IMACH(16) / 1023 /\n! !\n! ! MACHINE CONSTANTS FOR THE ELXSI 6400\n! !\n! ! DATA IMACH( 1) / 5 /\n! ! DATA IMACH( 2) / 6 /\n! ! DATA IMACH( 3) / 6 /\n! ! DATA IMACH( 4) / 6 /\n! ! DATA IMACH( 5) / 32 /\n! ! DATA IMACH( 6) / 4 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 32 /\n! ! DATA IMACH( 9) / 2147483647 /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 24 /\n! ! DATA IMACH(12) / -126 /\n! ! DATA IMACH(13) / 127 /\n! ! DATA IMACH(14) / 53 /\n! ! DATA IMACH(15) / -1022 /\n! ! DATA IMACH(16) / 1023 /\n! !\n! ! MACHINE CONSTANTS FOR THE HARRIS 220\n! !\n! ! DATA IMACH( 1) / 5 /\n! ! DATA IMACH( 2) / 6 /\n! ! DATA IMACH( 3) / 0 /\n! ! DATA IMACH( 4) / 6 /\n! ! DATA IMACH( 5) / 24 /\n! ! DATA IMACH( 6) / 3 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 23 /\n! ! DATA IMACH( 9) / 8388607 /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 23 /\n! ! DATA IMACH(12) / -127 /\n! ! DATA IMACH(13) / 127 /\n! ! DATA IMACH(14) / 38 /\n! ! DATA IMACH(15) / -127 /\n! ! DATA IMACH(16) / 127 /\n! !\n! ! MACHINE CONSTANTS FOR THE HONEYWELL 600/6000 SERIES\n! !\n! ! DATA IMACH( 1) / 5 /\n! ! DATA IMACH( 2) / 6 /\n! ! DATA IMACH( 3) / 43 /\n! ! DATA IMACH( 4) / 6 /\n! ! DATA IMACH( 5) / 36 /\n! ! DATA IMACH( 6) / 6 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 35 /\n! ! DATA IMACH( 9) / O377777777777 /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 27 /\n! ! DATA IMACH(12) / -127 /\n! ! DATA IMACH(13) / 127 /\n! ! DATA IMACH(14) / 63 /\n! ! DATA IMACH(15) / -127 /\n! ! DATA IMACH(16) / 127 /\n! !\n! ! MACHINE CONSTANTS FOR THE HP 730\n! !\n! ! DATA IMACH( 1) / 5 /\n! ! DATA IMACH( 2) / 6 /\n! ! DATA IMACH( 3) / 6 /\n! ! DATA IMACH( 4) / 6 /\n! ! DATA IMACH( 5) / 32 /\n! ! DATA IMACH( 6) / 4 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 31 /\n! ! DATA IMACH( 9) / 2147483647 /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 24 /\n! ! DATA IMACH(12) / -125 /\n! ! DATA IMACH(13) / 128 /\n! ! DATA IMACH(14) / 53 /\n! ! DATA IMACH(15) / -1021 /\n! ! DATA IMACH(16) / 1024 /\n! !\n! ! MACHINE CONSTANTS FOR THE HP 2100\n! ! 3 WORD DOUBLE PRECISION OPTION WITH FTN4\n! !\n! ! DATA IMACH( 1) / 5 /\n! ! DATA IMACH( 2) / 6 /\n! ! DATA IMACH( 3) / 4 /\n! ! DATA IMACH( 4) / 1 /\n! ! DATA IMACH( 5) / 16 /\n! ! DATA IMACH( 6) / 2 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 15 /\n! ! DATA IMACH( 9) / 32767 /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 23 /\n! ! DATA IMACH(12) / -128 /\n! ! DATA IMACH(13) / 127 /\n! ! DATA IMACH(14) / 39 /\n! ! DATA IMACH(15) / -128 /\n! ! DATA IMACH(16) / 127 /\n! !\n! ! MACHINE CONSTANTS FOR THE HP 2100\n! ! 4 WORD DOUBLE PRECISION OPTION WITH FTN4\n! !\n! ! DATA IMACH( 1) / 5 /\n! ! DATA IMACH( 2) / 6 /\n! ! DATA IMACH( 3) / 4 /\n! ! DATA IMACH( 4) / 1 /\n! ! DATA IMACH( 5) / 16 /\n! ! DATA IMACH( 6) / 2 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 15 /\n! ! DATA IMACH( 9) / 32767 /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 23 /\n! ! DATA IMACH(12) / -128 /\n! ! DATA IMACH(13) / 127 /\n! ! DATA IMACH(14) / 55 /\n! ! DATA IMACH(15) / -128 /\n! ! DATA IMACH(16) / 127 /\n! !\n! ! MACHINE CONSTANTS FOR THE HP 9000\n! !\n! ! DATA IMACH( 1) / 5 /\n! ! DATA IMACH( 2) / 6 /\n! ! DATA IMACH( 3) / 6 /\n! ! DATA IMACH( 4) / 7 /\n! ! DATA IMACH( 5) / 32 /\n! ! DATA IMACH( 6) / 4 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 32 /\n! ! DATA IMACH( 9) / 2147483647 /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 24 /\n! ! DATA IMACH(12) / -126 /\n! ! DATA IMACH(13) / 127 /\n! ! DATA IMACH(14) / 53 /\n! ! DATA IMACH(15) / -1015 /\n! ! DATA IMACH(16) / 1017 /\n! !\n! ! MACHINE CONSTANTS FOR THE IBM 360/370 SERIES,\n! ! THE XEROX SIGMA 5/7/9, THE SEL SYSTEMS 85/86, AND\n! ! THE PERKIN ELMER (INTERDATA) 7/32.\n! !\n! ! DATA IMACH( 1) / 5 /\n! ! DATA IMACH( 2) / 6 /\n! ! DATA IMACH( 3) / 7 /\n! ! DATA IMACH( 4) / 6 /\n! ! DATA IMACH( 5) / 32 /\n! ! DATA IMACH( 6) / 4 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 31 /\n! ! DATA IMACH( 9) / Z7FFFFFFF /\n! ! DATA IMACH(10) / 16 /\n! ! DATA IMACH(11) / 6 /\n! ! DATA IMACH(12) / -64 /\n! ! DATA IMACH(13) / 63 /\n! ! DATA IMACH(14) / 14 /\n! ! DATA IMACH(15) / -64 /\n! ! DATA IMACH(16) / 63 /\n! !\n! ! MACHINE CONSTANTS FOR THE IBM PC\n! !\n! ! DATA IMACH( 1) / 5 /\n! ! DATA IMACH( 2) / 6 /\n! ! DATA IMACH( 3) / 0 /\n! ! DATA IMACH( 4) / 0 /\n! ! DATA IMACH( 5) / 32 /\n! ! DATA IMACH( 6) / 4 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 31 /\n! ! DATA IMACH( 9) / 2147483647 /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 24 /\n! ! DATA IMACH(12) / -125 /\n! ! DATA IMACH(13) / 127 /\n! ! DATA IMACH(14) / 53 /\n! ! DATA IMACH(15) / -1021 /\n! ! DATA IMACH(16) / 1023 /\n! !\n! ! MACHINE CONSTANTS FOR THE IBM RS 6000\n! !\n! ! DATA IMACH( 1) / 5 /\n! ! DATA IMACH( 2) / 6 /\n! ! DATA IMACH( 3) / 6 /\n! ! DATA IMACH( 4) / 0 /\n! ! DATA IMACH( 5) / 32 /\n! ! DATA IMACH( 6) / 4 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 31 /\n! ! DATA IMACH( 9) / 2147483647 /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 24 /\n! ! DATA IMACH(12) / -125 /\n! ! DATA IMACH(13) / 128 /\n! ! DATA IMACH(14) / 53 /\n! ! DATA IMACH(15) / -1021 /\n! ! DATA IMACH(16) / 1024 /\n! !\n! ! MACHINE CONSTANTS FOR THE INTEL i860\n! !\n! ! DATA IMACH( 1) / 5 /\n! ! DATA IMACH( 2) / 6 /\n! ! DATA IMACH( 3) / 6 /\n! ! DATA IMACH( 4) / 6 /\n! ! DATA IMACH( 5) / 32 /\n! ! DATA IMACH( 6) / 4 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 31 /\n! ! DATA IMACH( 9) / 2147483647 /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 24 /\n! ! DATA IMACH(12) / -125 /\n! ! DATA IMACH(13) / 128 /\n! ! DATA IMACH(14) / 53 /\n! ! DATA IMACH(15) / -1021 /\n! ! DATA IMACH(16) / 1024 /\n! !\n! ! MACHINE CONSTANTS FOR THE PDP-10 (KA PROCESSOR)\n! !\n! ! DATA IMACH( 1) / 5 /\n! ! DATA IMACH( 2) / 6 /\n! ! DATA IMACH( 3) / 5 /\n! ! DATA IMACH( 4) / 6 /\n! ! DATA IMACH( 5) / 36 /\n! ! DATA IMACH( 6) / 5 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 35 /\n! ! DATA IMACH( 9) / \"377777777777 /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 27 /\n! ! DATA IMACH(12) / -128 /\n! ! DATA IMACH(13) / 127 /\n! ! DATA IMACH(14) / 54 /\n! ! DATA IMACH(15) / -101 /\n! ! DATA IMACH(16) / 127 /\n! !\n! ! MACHINE CONSTANTS FOR THE PDP-10 (KI PROCESSOR)\n! !\n! ! DATA IMACH( 1) / 5 /\n! ! DATA IMACH( 2) / 6 /\n! ! DATA IMACH( 3) / 5 /\n! ! DATA IMACH( 4) / 6 /\n! ! DATA IMACH( 5) / 36 /\n! ! DATA IMACH( 6) / 5 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 35 /\n! ! DATA IMACH( 9) / \"377777777777 /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 27 /\n! ! DATA IMACH(12) / -128 /\n! ! DATA IMACH(13) / 127 /\n! ! DATA IMACH(14) / 62 /\n! ! DATA IMACH(15) / -128 /\n! ! DATA IMACH(16) / 127 /\n! !\n! ! MACHINE CONSTANTS FOR PDP-11 FORTRAN SUPPORTING\n! ! 32-BIT INTEGER ARITHMETIC.\n! !\n! ! DATA IMACH( 1) / 5 /\n! ! DATA IMACH( 2) / 6 /\n! ! DATA IMACH( 3) / 5 /\n! ! DATA IMACH( 4) / 6 /\n! ! DATA IMACH( 5) / 32 /\n! ! DATA IMACH( 6) / 4 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 31 /\n! ! DATA IMACH( 9) / 2147483647 /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 24 /\n! ! DATA IMACH(12) / -127 /\n! ! DATA IMACH(13) / 127 /\n! ! DATA IMACH(14) / 56 /\n! ! DATA IMACH(15) / -127 /\n! ! DATA IMACH(16) / 127 /\n! !\n! ! MACHINE CONSTANTS FOR PDP-11 FORTRAN SUPPORTING\n! ! 16-BIT INTEGER ARITHMETIC.\n! !\n! ! DATA IMACH( 1) / 5 /\n! ! DATA IMACH( 2) / 6 /\n! ! DATA IMACH( 3) / 5 /\n! ! DATA IMACH( 4) / 6 /\n! ! DATA IMACH( 5) / 16 /\n! ! DATA IMACH( 6) / 2 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 15 /\n! ! DATA IMACH( 9) / 32767 /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 24 /\n! ! DATA IMACH(12) / -127 /\n! ! DATA IMACH(13) / 127 /\n! ! DATA IMACH(14) / 56 /\n! ! DATA IMACH(15) / -127 /\n! ! DATA IMACH(16) / 127 /\n! !\n! ! MACHINE CONSTANTS FOR THE SILICON GRAPHICS\n! !\n! ! DATA IMACH( 1) / 5 /\n! ! DATA IMACH( 2) / 6 /\n! ! DATA IMACH( 3) / 6 /\n! ! DATA IMACH( 4) / 6 /\n! ! DATA IMACH( 5) / 32 /\n! ! DATA IMACH( 6) / 4 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 31 /\n! ! DATA IMACH( 9) / 2147483647 /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 24 /\n! ! DATA IMACH(12) / -125 /\n! ! DATA IMACH(13) / 128 /\n! ! DATA IMACH(14) / 53 /\n! ! DATA IMACH(15) / -1021 /\n! ! DATA IMACH(16) / 1024 /\n! !\n! ! MACHINE CONSTANTS FOR THE SUN\n! !\n! ! DATA IMACH( 1) / 5 /\n! ! DATA IMACH( 2) / 6 /\n! ! DATA IMACH( 3) / 6 /\n! ! DATA IMACH( 4) / 6 /\n! ! DATA IMACH( 5) / 32 /\n! ! DATA IMACH( 6) / 4 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 31 /\n! ! DATA IMACH( 9) / 2147483647 /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 24 /\n! ! DATA IMACH(12) / -125 /\n! ! DATA IMACH(13) / 128 /\n! ! DATA IMACH(14) / 53 /\n! ! DATA IMACH(15) / -1021 /\n! ! DATA IMACH(16) / 1024 /\n! !\n! ! MACHINE CONSTANTS FOR THE SUN\n! ! USING THE -r8 COMPILER OPTION\n! !\n! ! DATA IMACH( 1) / 5 /\n! ! DATA IMACH( 2) / 6 /\n! ! DATA IMACH( 3) / 6 /\n! ! DATA IMACH( 4) / 6 /\n! ! DATA IMACH( 5) / 32 /\n! ! DATA IMACH( 6) / 4 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 31 /\n! ! DATA IMACH( 9) / 2147483647 /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 53 /\n! ! DATA IMACH(12) / -1021 /\n! ! DATA IMACH(13) / 1024 /\n! ! DATA IMACH(14) / 113 /\n! ! DATA IMACH(15) / -16381 /\n! ! DATA IMACH(16) / 16384 /\n! !\n! ! MACHINE CONSTANTS FOR THE UNIVAC 1100 SERIES FTN COMPILER\n! !\n! ! DATA IMACH( 1) / 5 /\n! ! DATA IMACH( 2) / 6 /\n! ! DATA IMACH( 3) / 1 /\n! ! DATA IMACH( 4) / 6 /\n! ! DATA IMACH( 5) / 36 /\n! ! DATA IMACH( 6) / 4 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 35 /\n! ! DATA IMACH( 9) / O377777777777 /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 27 /\n! ! DATA IMACH(12) / -128 /\n! ! DATA IMACH(13) / 127 /\n! ! DATA IMACH(14) / 60 /\n! ! DATA IMACH(15) / -1024 /\n! ! DATA IMACH(16) / 1023 /\n! !\n! ! MACHINE CONSTANTS FOR THE Z80 MICROPROCESSOR\n! !\n! ! DATA IMACH( 1) / 1 /\n! ! DATA IMACH( 2) / 1 /\n! ! DATA IMACH( 3) / 0 /\n! ! DATA IMACH( 4) / 1 /\n! ! DATA IMACH( 5) / 16 /\n! ! DATA IMACH( 6) / 2 /\n! ! DATA IMACH( 7) / 2 /\n! ! DATA IMACH( 8) / 15 /\n! ! DATA IMACH( 9) / 32767 /\n! ! DATA IMACH(10) / 2 /\n! ! DATA IMACH(11) / 24 /\n! ! DATA IMACH(12) / -127 /\n! ! DATA IMACH(13) / 127 /\n! ! DATA IMACH(14) / 56 /\n! ! DATA IMACH(15) / -127 /\n! ! DATA IMACH(16) / 127 /\n! !\n! !***FIRST EXECUTABLE STATEMENT I1MACH\n! !\n! if ( I < 1 .OR. I > 16 ) then\n! WRITE (UNIT = OUTPUT, FMT = 9000)\n! 9000 FORMAT ('1ERROR 1 IN I1MACH - I OUT OF BOUNDS')\n! STOP\n! end if\n! \n! I1MACH = IMACH(I)\n! \n! return\n! end\n\nsubroutine DJAIRY (X, RX, C, AI, DAI)\n!\n!! DJAIRY is subsidiary to DBESJ and DBESY.\n!\n!***LIBRARY SLATEC\n!***TYPE DOUBLE PRECISION (JAIRY-S, DJAIRY-D)\n!***AUTHOR Amos, D. E., (SNLA)\n! Daniel, S. L., (SNLA)\n! Weston, M. K., (SNLA)\n!***DESCRIPTION\n!\n! DJAIRY computes the Airy function AI(X)\n! and its derivative DAI(X) for DASYJY\n!\n! INPUT\n!\n! X - Argument, computed by DASYJY, X unrestricted\n! RX - RX=SQRT(ABS(X)), computed by DASYJY\n! C - C=2.*(ABS(X)**1.5)/3., computed by DASYJY\n!\n! OUTPUT\n!\n! AI - Value of function AI(X)\n! DAI - Value of the derivative DAI(X)\n!\n!***SEE ALSO DBESJ, DBESY\n!***ROUTINES CALLED (NONE)\n!***REVISION HISTORY (YYMMDD)\n! 750101 DATE WRITTEN\n! 890531 Changed all specific intrinsics to generic. (WRB)\n! 891009 Removed unreferenced variable. (WRB)\n! 891214 Prologue converted to Version 4.0 format. (BAB)\n! 900328 Added TYPE section. (WRB)\n! 910408 Updated the AUTHOR section. (WRB)\n!***END PROLOGUE DJAIRY\n!\n INTEGER I, J, M1, M1D, M2, M2D, M3, M3D, M4, M4D, N1, N1D, N2, &\n N2D, N3, N3D, N4, N4D\n DOUBLE PRECISION A,AI,AJN,AJP,AK1,AK2,AK3,B,C,CCV,CON2, &\n CON3, CON4, CON5, CV, DA, DAI, DAJN, DAJP, DAK1, DAK2, DAK3, &\n DB, EC, E1, E2, FPI12, F1, F2, RTRX, RX, SCV, T, TEMP1, TEMP2, &\n TT, X\n DIMENSION AJP(19), AJN(19), A(15), B(15)\n DIMENSION AK1(14), AK2(23), AK3(14)\n DIMENSION DAJP(19), DAJN(19), DA(15), DB(15)\n DIMENSION DAK1(14), DAK2(24), DAK3(14)\n SAVE N1, N2, N3, N4, M1, M2, M3, M4, FPI12, CON2, CON3, &\n CON4, CON5, AK1, AK2, AK3, AJP, AJN, A, B, &\n N1D, N2D, N3D, N4D, M1D, M2D, M3D, M4D, DAK1, DAK2, DAK3, &\n DAJP, DAJN, DA, DB\n DATA N1,N2,N3,N4/14,23,19,15/\n DATA M1,M2,M3,M4/12,21,17,13/\n DATA FPI12,CON2,CON3,CON4,CON5/ &\n 1.30899693899575D+00, 5.03154716196777D+00, 3.80004589867293D-01, &\n 8.33333333333333D-01, 8.66025403784439D-01/\n DATA AK1(1), AK1(2), AK1(3), AK1(4), AK1(5), AK1(6), AK1(7), &\n AK1(8), AK1(9), AK1(10),AK1(11),AK1(12),AK1(13), &\n AK1(14) / 2.20423090987793D-01,-1.25290242787700D-01, &\n 1.03881163359194D-02, 8.22844152006343D-04,-2.34614345891226D-04, &\n 1.63824280172116D-05, 3.06902589573189D-07,-1.29621999359332D-07, &\n 8.22908158823668D-09, 1.53963968623298D-11,-3.39165465615682D-11, &\n 2.03253257423626D-12,-1.10679546097884D-14,-5.16169497785080D-15/\n DATA AK2(1), AK2(2), AK2(3), AK2(4), AK2(5), AK2(6), AK2(7), &\n AK2(8), AK2(9), AK2(10),AK2(11),AK2(12),AK2(13),AK2(14), &\n AK2(15),AK2(16),AK2(17),AK2(18),AK2(19),AK2(20),AK2(21), &\n AK2(22),AK2(23) / 2.74366150869598D-01, 5.39790969736903D-03, &\n -1.57339220621190D-03, 4.27427528248750D-04,-1.12124917399925D-04, &\n 2.88763171318904D-05,-7.36804225370554D-06, 1.87290209741024D-06, &\n -4.75892793962291D-07, 1.21130416955909D-07,-3.09245374270614D-08, &\n 7.92454705282654D-09,-2.03902447167914D-09, 5.26863056595742D-10, &\n -1.36704767639569D-10, 3.56141039013708D-11,-9.31388296548430D-12, &\n 2.44464450473635D-12,-6.43840261990955D-13, 1.70106030559349D-13, &\n -4.50760104503281D-14, 1.19774799164811D-14,-3.19077040865066D-15/\n DATA AK3(1), AK3(2), AK3(3), AK3(4), AK3(5), AK3(6), AK3(7), &\n AK3(8), AK3(9), AK3(10),AK3(11),AK3(12),AK3(13), &\n AK3(14) / 2.80271447340791D-01,-1.78127042844379D-03, &\n 4.03422579628999D-05,-1.63249965269003D-06, 9.21181482476768D-08, &\n -6.52294330229155D-09, 5.47138404576546D-10,-5.24408251800260D-11, &\n 5.60477904117209D-12,-6.56375244639313D-13, 8.31285761966247D-14, &\n -1.12705134691063D-14, 1.62267976598129D-15,-2.46480324312426D-16/\n DATA AJP(1), AJP(2), AJP(3), AJP(4), AJP(5), AJP(6), AJP(7), &\n AJP(8), AJP(9), AJP(10),AJP(11),AJP(12),AJP(13),AJP(14), &\n AJP(15),AJP(16),AJP(17),AJP(18), &\n AJP(19) / 7.78952966437581D-02,-1.84356363456801D-01, &\n 3.01412605216174D-02, 3.05342724277608D-02,-4.95424702513079D-03, &\n -1.72749552563952D-03, 2.43137637839190D-04, 5.04564777517082D-05, &\n -6.16316582695208D-06,-9.03986745510768D-07, 9.70243778355884D-08, &\n 1.09639453305205D-08,-1.04716330588766D-09,-9.60359441344646D-11, &\n 8.25358789454134D-12, 6.36123439018768D-13,-4.96629614116015D-14, &\n -3.29810288929615D-15, 2.35798252031104D-16/\n DATA AJN(1), AJN(2), AJN(3), AJN(4), AJN(5), AJN(6), AJN(7), &\n AJN(8), AJN(9), AJN(10),AJN(11),AJN(12),AJN(13),AJN(14), &\n AJN(15),AJN(16),AJN(17),AJN(18), &\n AJN(19) / 3.80497887617242D-02,-2.45319541845546D-01, &\n 1.65820623702696D-01, 7.49330045818789D-02,-2.63476288106641D-02, &\n -5.92535597304981D-03, 1.44744409589804D-03, 2.18311831322215D-04, &\n -4.10662077680304D-05,-4.66874994171766D-06, 7.15218807277160D-07, &\n 6.52964770854633D-08,-8.44284027565946D-09,-6.44186158976978D-10, &\n 7.20802286505285D-11, 4.72465431717846D-12,-4.66022632547045D-13, &\n -2.67762710389189D-14, 2.36161316570019D-15/\n DATA A(1), A(2), A(3), A(4), A(5), A(6), A(7), &\n A(8), A(9), A(10), A(11), A(12), A(13), A(14), &\n A(15) / 4.90275424742791D-01, 1.57647277946204D-03, &\n -9.66195963140306D-05, 1.35916080268815D-07, 2.98157342654859D-07, &\n -1.86824767559979D-08,-1.03685737667141D-09, 3.28660818434328D-10, &\n -2.57091410632780D-11,-2.32357655300677D-12, 9.57523279048255D-13, &\n -1.20340828049719D-13,-2.90907716770715D-15, 4.55656454580149D-15, &\n -9.99003874810259D-16/\n DATA B(1), B(2), B(3), B(4), B(5), B(6), B(7), &\n B(8), B(9), B(10), B(11), B(12), B(13), B(14), &\n B(15) / 2.78593552803079D-01,-3.52915691882584D-03, &\n -2.31149677384994D-05, 4.71317842263560D-06,-1.12415907931333D-07, &\n -2.00100301184339D-08, 2.60948075302193D-09,-3.55098136101216D-11, &\n -3.50849978423875D-11, 5.83007187954202D-12,-2.04644828753326D-13, &\n -1.10529179476742D-13, 2.87724778038775D-14,-2.88205111009939D-15, &\n -3.32656311696166D-16/\n DATA N1D,N2D,N3D,N4D/14,24,19,15/\n DATA M1D,M2D,M3D,M4D/12,22,17,13/\n DATA DAK1(1), DAK1(2), DAK1(3), DAK1(4), DAK1(5), DAK1(6), &\n DAK1(7), DAK1(8), DAK1(9), DAK1(10),DAK1(11),DAK1(12), &\n DAK1(13),DAK1(14)/ 2.04567842307887D-01,-6.61322739905664D-02, &\n -8.49845800989287D-03, 3.12183491556289D-03,-2.70016489829432D-04, &\n -6.35636298679387D-06, 3.02397712409509D-06,-2.18311195330088D-07, &\n -5.36194289332826D-10, 1.13098035622310D-09,-7.43023834629073D-11, &\n 4.28804170826891D-13, 2.23810925754539D-13,-1.39140135641182D-14/\n DATA DAK2(1), DAK2(2), DAK2(3), DAK2(4), DAK2(5), DAK2(6), &\n DAK2(7), DAK2(8), DAK2(9), DAK2(10),DAK2(11),DAK2(12), &\n DAK2(13),DAK2(14),DAK2(15),DAK2(16),DAK2(17),DAK2(18), &\n DAK2(19),DAK2(20),DAK2(21),DAK2(22),DAK2(23), &\n DAK2(24) / 2.93332343883230D-01,-8.06196784743112D-03, &\n 2.42540172333140D-03,-6.82297548850235D-04, 1.85786427751181D-04, &\n -4.97457447684059D-05, 1.32090681239497D-05,-3.49528240444943D-06, &\n 9.24362451078835D-07,-2.44732671521867D-07, 6.49307837648910D-08, &\n -1.72717621501538D-08, 4.60725763604656D-09,-1.23249055291550D-09, &\n 3.30620409488102D-10,-8.89252099772401D-11, 2.39773319878298D-11, &\n -6.48013921153450D-12, 1.75510132023731D-12,-4.76303829833637D-13, &\n 1.29498241100810D-13,-3.52679622210430D-14, 9.62005151585923D-15, &\n -2.62786914342292D-15/\n DATA DAK3(1), DAK3(2), DAK3(3), DAK3(4), DAK3(5), DAK3(6), &\n DAK3(7), DAK3(8), DAK3(9), DAK3(10),DAK3(11),DAK3(12), &\n DAK3(13),DAK3(14)/ 2.84675828811349D-01, 2.53073072619080D-03, &\n -4.83481130337976D-05, 1.84907283946343D-06,-1.01418491178576D-07, &\n 7.05925634457153D-09,-5.85325291400382D-10, 5.56357688831339D-11, &\n -5.90889094779500D-12, 6.88574353784436D-13,-8.68588256452194D-14, &\n 1.17374762617213D-14,-1.68523146510923D-15, 2.55374773097056D-16/\n DATA DAJP(1), DAJP(2), DAJP(3), DAJP(4), DAJP(5), DAJP(6), &\n DAJP(7), DAJP(8), DAJP(9), DAJP(10),DAJP(11),DAJP(12), &\n DAJP(13),DAJP(14),DAJP(15),DAJP(16),DAJP(17),DAJP(18), &\n DAJP(19) / 6.53219131311457D-02,-1.20262933688823D-01, &\n 9.78010236263823D-03, 1.67948429230505D-02,-1.97146140182132D-03, &\n -8.45560295098867D-04, 9.42889620701976D-05, 2.25827860945475D-05, &\n -2.29067870915987D-06,-3.76343991136919D-07, 3.45663933559565D-08, &\n 4.29611332003007D-09,-3.58673691214989D-10,-3.57245881361895D-11, &\n 2.72696091066336D-12, 2.26120653095771D-13,-1.58763205238303D-14, &\n -1.12604374485125D-15, 7.31327529515367D-17/\n DATA DAJN(1), DAJN(2), DAJN(3), DAJN(4), DAJN(5), DAJN(6), &\n DAJN(7), DAJN(8), DAJN(9), DAJN(10),DAJN(11),DAJN(12), &\n DAJN(13),DAJN(14),DAJN(15),DAJN(16),DAJN(17),DAJN(18), &\n DAJN(19) / 1.08594539632967D-02, 8.53313194857091D-02, &\n -3.15277068113058D-01,-8.78420725294257D-02, 5.53251906976048D-02, &\n 9.41674060503241D-03,-3.32187026018996D-03,-4.11157343156826D-04, &\n 1.01297326891346D-04, 9.87633682208396D-06,-1.87312969812393D-06, &\n -1.50798500131468D-07, 2.32687669525394D-08, 1.59599917419225D-09, &\n -2.07665922668385D-10,-1.24103350500302D-11, 1.39631765331043D-12, &\n 7.39400971155740D-14,-7.32887475627500D-15/\n DATA DA(1), DA(2), DA(3), DA(4), DA(5), DA(6), DA(7), &\n DA(8), DA(9), DA(10), DA(11), DA(12), DA(13), DA(14), &\n DA(15) / 4.91627321104601D-01, 3.11164930427489D-03, &\n 8.23140762854081D-05,-4.61769776172142D-06,-6.13158880534626D-08, &\n 2.87295804656520D-08,-1.81959715372117D-09,-1.44752826642035D-10, &\n 4.53724043420422D-11,-3.99655065847223D-12,-3.24089119830323D-13, &\n 1.62098952568741D-13,-2.40765247974057D-14, 1.69384811284491D-16, &\n 8.17900786477396D-16/\n DATA DB(1), DB(2), DB(3), DB(4), DB(5), DB(6), DB(7), &\n DB(8), DB(9), DB(10), DB(11), DB(12), DB(13), DB(14), &\n DB(15) /-2.77571356944231D-01, 4.44212833419920D-03, &\n -8.42328522190089D-05,-2.58040318418710D-06, 3.42389720217621D-07, &\n -6.24286894709776D-09,-2.36377836844577D-09, 3.16991042656673D-10, &\n -4.40995691658191D-12,-5.18674221093575D-12, 9.64874015137022D-13, &\n -4.90190576608710D-14,-1.77253430678112D-14, 5.55950610442662D-15, &\n -7.11793337579530D-16/\n!***FIRST EXECUTABLE STATEMENT DJAIRY\n if (X < 0.0D0) go to 90\n if (C > 5.0D0) go to 60\n if (X > 1.20D0) go to 30\n T = (X+X-1.2D0)*CON4\n TT = T + T\n J = N1\n F1 = AK1(J)\n F2 = 0.0D0\n DO 10 I=1,M1\n J = J - 1\n TEMP1 = F1\n F1 = TT*F1 - F2 + AK1(J)\n F2 = TEMP1\n 10 CONTINUE\n AI = T*F1 - F2 + AK1(1)\n!\n J = N1D\n F1 = DAK1(J)\n F2 = 0.0D0\n DO 20 I=1,M1D\n J = J - 1\n TEMP1 = F1\n F1 = TT*F1 - F2 + DAK1(J)\n F2 = TEMP1\n 20 CONTINUE\n DAI = -(T*F1-F2+DAK1(1))\n return\n!\n 30 CONTINUE\n T = (X+X-CON2)*CON3\n TT = T + T\n J = N2\n F1 = AK2(J)\n F2 = 0.0D0\n DO 40 I=1,M2\n J = J - 1\n TEMP1 = F1\n F1 = TT*F1 - F2 + AK2(J)\n F2 = TEMP1\n 40 CONTINUE\n RTRX = SQRT(RX)\n EC = EXP(-C)\n AI = EC*(T*F1-F2+AK2(1))/RTRX\n J = N2D\n F1 = DAK2(J)\n F2 = 0.0D0\n DO 50 I=1,M2D\n J = J - 1\n TEMP1 = F1\n F1 = TT*F1 - F2 + DAK2(J)\n F2 = TEMP1\n 50 CONTINUE\n DAI = -EC*(T*F1-F2+DAK2(1))*RTRX\n return\n!\n 60 CONTINUE\n T = 10.0D0/C - 1.0D0\n TT = T + T\n J = N1\n F1 = AK3(J)\n F2 = 0.0D0\n DO 70 I=1,M1\n J = J - 1\n TEMP1 = F1\n F1 = TT*F1 - F2 + AK3(J)\n F2 = TEMP1\n 70 CONTINUE\n RTRX = SQRT(RX)\n EC = EXP(-C)\n AI = EC*(T*F1-F2+AK3(1))/RTRX\n J = N1D\n F1 = DAK3(J)\n F2 = 0.0D0\n DO 80 I=1,M1D\n J = J - 1\n TEMP1 = F1\n F1 = TT*F1 - F2 + DAK3(J)\n F2 = TEMP1\n 80 CONTINUE\n DAI = -RTRX*EC*(T*F1-F2+DAK3(1))\n return\n!\n 90 CONTINUE\n if (C > 5.0D0) go to 120\n T = 0.4D0*C - 1.0D0\n TT = T + T\n J = N3\n F1 = AJP(J)\n E1 = AJN(J)\n F2 = 0.0D0\n E2 = 0.0D0\n DO 100 I=1,M3\n J = J - 1\n TEMP1 = F1\n TEMP2 = E1\n F1 = TT*F1 - F2 + AJP(J)\n E1 = TT*E1 - E2 + AJN(J)\n F2 = TEMP1\n E2 = TEMP2\n 100 CONTINUE\n AI = (T*E1-E2+AJN(1)) - X*(T*F1-F2+AJP(1))\n J = N3D\n F1 = DAJP(J)\n E1 = DAJN(J)\n F2 = 0.0D0\n E2 = 0.0D0\n DO 110 I=1,M3D\n J = J - 1\n TEMP1 = F1\n TEMP2 = E1\n F1 = TT*F1 - F2 + DAJP(J)\n E1 = TT*E1 - E2 + DAJN(J)\n F2 = TEMP1\n E2 = TEMP2\n 110 CONTINUE\n DAI = X*X*(T*F1-F2+DAJP(1)) + (T*E1-E2+DAJN(1))\n return\n!\n 120 CONTINUE\n T = 10.0D0/C - 1.0D0\n TT = T + T\n J = N4\n F1 = A(J)\n E1 = B(J)\n F2 = 0.0D0\n E2 = 0.0D0\n DO 130 I=1,M4\n J = J - 1\n TEMP1 = F1\n TEMP2 = E1\n F1 = TT*F1 - F2 + A(J)\n E1 = TT*E1 - E2 + B(J)\n F2 = TEMP1\n E2 = TEMP2\n 130 CONTINUE\n TEMP1 = T*F1 - F2 + A(1)\n TEMP2 = T*E1 - E2 + B(1)\n RTRX = SQRT(RX)\n CV = C - FPI12\n CCV = COS(CV)\n SCV = SIN(CV)\n AI = (TEMP1*CCV-TEMP2*SCV)/RTRX\n J = N4D\n F1 = DA(J)\n E1 = DB(J)\n F2 = 0.0D0\n E2 = 0.0D0\n DO 140 I=1,M4D\n J = J - 1\n TEMP1 = F1\n TEMP2 = E1\n F1 = TT*F1 - F2 + DA(J)\n E1 = TT*E1 - E2 + DB(J)\n F2 = TEMP1\n E2 = TEMP2\n 140 CONTINUE\n TEMP1 = T*F1 - F2 + DA(1)\n TEMP2 = T*E1 - E2 + DB(1)\n E1 = CCV*CON5 + 0.5D0*SCV\n E2 = SCV*CON5 - 0.5D0*CCV\n DAI = (TEMP1*E1-TEMP2*E2)*RTRX\n return\nend\n\n\n DOUBLE PRECISION FUNCTION DLNGAM (X)\n!\n!! DLNGAM computes the logarithm of the absolute value of the Gamma function.\n!\n!***LIBRARY SLATEC (FNLIB)\n!***CATEGORY C7A\n!***TYPE DOUBLE PRECISION (ALNGAM-S, DLNGAM-D, CLNGAM-C)\n!***KEYWORDS ABSOLUTE VALUE, COMPLETE GAMMA FUNCTION, FNLIB, LOGARITHM,\n! SPECIAL FUNCTIONS\n!***AUTHOR Fullerton, W., (LANL)\n!***DESCRIPTION\n!\n! DLNGAM(X) calculates the double precision logarithm of the\n! absolute value of the Gamma function for double precision\n! argument X.\n!\n!***REFERENCES (NONE)\n!***ROUTINES CALLED D1MACH, D9LGMC, DGAMMA, XERMSG\n!***REVISION HISTORY (YYMMDD)\n! 770601 DATE WRITTEN\n! 890531 Changed all specific intrinsics to generic. (WRB)\n! 890531 REVISION DATE from Version 3.2\n! 891214 Prologue converted to Version 4.0 format. (BAB)\n! 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\n! 900727 Added EXTERNAL statement. (WRB)\n!***END PROLOGUE DLNGAM\n DOUBLE PRECISION X, DXREL, PI, SINPIY, SQPI2L, SQ2PIL, XMAX, &\n Y, DGAMMA, D9LGMC, D1MACH, TEMP\n LOGICAL FIRST\n EXTERNAL DGAMMA\n SAVE SQ2PIL, SQPI2L, PI, XMAX, DXREL, FIRST\n DATA SQ2PIL / 0.91893853320467274178032973640562D0 /\n DATA SQPI2L / +.225791352644727432363097614947441D+0 /\n DATA PI / 3.14159265358979323846264338327950D0 /\n DATA FIRST /.TRUE./\n!***FIRST EXECUTABLE STATEMENT DLNGAM\n if (FIRST) THEN\n TEMP = 1.D0/LOG(D1MACH(2))\n XMAX = TEMP*D1MACH(2)\n DXREL = SQRT(D1MACH(4))\n end if\n FIRST = .FALSE.\n!\n Y = ABS (X)\n if (Y > 10.D0) go to 20\n!\n! LOG (ABS (DGAMMA(X)) ) FOR ABS(X) <= 10.0\n!\n DLNGAM = LOG (ABS (DGAMMA(X)) )\n return\n!\n! LOG ( ABS (DGAMMA(X)) ) FOR ABS(X) > 10.0\n!\n 20 if (Y > XMAX) call XERMSG ('SLATEC', 'DLNGAM', &\n 'ABS(X) SO BIG DLNGAM OVERFLOWS', 2, 2)\n!\n if (X > 0.D0) DLNGAM = SQ2PIL + (X-0.5D0)*LOG(X) - X + D9LGMC(Y)\n if (X > 0.D0) RETURN\n!\n SINPIY = ABS (SIN(PI*Y))\n if (SINPIY == 0.D0) call XERMSG ('SLATEC', 'DLNGAM', &\n 'X IS A NEGATIVE INTEGER', 3, 2)\n!\n if (ABS((X-AINT(X-0.5D0))/X) < DXREL) call XERMSG ('SLATEC', &\n 'DLNGAM', &\n 'ANSWER LT HALF PRECISION BECAUSE X TOO NEAR NEGATIVE INTEGER', &\n 1, 1)\n!\n DLNGAM = SQPI2L + (X-0.5D0)*LOG(Y) - X - LOG(SINPIY) - D9LGMC(Y)\n return\n!\nend\n\n DOUBLE PRECISION FUNCTION D9LGMC (X)\n!\n!! D9LGMC computes the log Gamma correction factor so that ...\n! LOG(DGAMMA(X)) = LOG(SQRT(2*PI)) + (X-5.)*LOG(X) - X + D9LGMC(X).\n!\n!***LIBRARY SLATEC (FNLIB)\n!***CATEGORY C7E\n!***TYPE DOUBLE PRECISION (R9LGMC-S, D9LGMC-D, C9LGMC-C)\n!***KEYWORDS COMPLETE GAMMA FUNCTION, CORRECTION TERM, FNLIB,\n! LOG GAMMA, LOGARITHM, SPECIAL FUNCTIONS\n!***AUTHOR Fullerton, W., (LANL)\n!***DESCRIPTION\n!\n! Compute the log gamma correction factor for X >= 10. so that\n! LOG (DGAMMA(X)) = LOG(SQRT(2*PI)) + (X-.5)*LOG(X) - X + D9lGMC(X)\n!\n! Series for ALGM on the interval 0. to 1.00000E-02\n! with weighted error 1.28E-31\n! log weighted error 30.89\n! significant figures required 29.81\n! decimal places required 31.48\n!\n!***REFERENCES (NONE)\n!***ROUTINES CALLED D1MACH, DCSEVL, INITDS, XERMSG\n!***REVISION HISTORY (YYMMDD)\n! 770601 DATE WRITTEN\n! 890531 Changed all specific intrinsics to generic. (WRB)\n! 890531 REVISION DATE from Version 3.2\n! 891214 Prologue converted to Version 4.0 format. (BAB)\n! 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\n! 900720 Routine changed from user-callable to subsidiary. (WRB)\n!***END PROLOGUE D9LGMC\n DOUBLE PRECISION X, ALGMCS(15), XBIG, XMAX, DCSEVL, D1MACH\n LOGICAL FIRST\n SAVE ALGMCS, NALGM, XBIG, XMAX, FIRST\n DATA ALGMCS( 1) / +.1666389480451863247205729650822D+0 /\n DATA ALGMCS( 2) / -.1384948176067563840732986059135D-4 /\n DATA ALGMCS( 3) / +.9810825646924729426157171547487D-8 /\n DATA ALGMCS( 4) / -.1809129475572494194263306266719D-10 /\n DATA ALGMCS( 5) / +.6221098041892605227126015543416D-13 /\n DATA ALGMCS( 6) / -.3399615005417721944303330599666D-15 /\n DATA ALGMCS( 7) / +.2683181998482698748957538846666D-17 /\n DATA ALGMCS( 8) / -.2868042435334643284144622399999D-19 /\n DATA ALGMCS( 9) / +.3962837061046434803679306666666D-21 /\n DATA ALGMCS( 10) / -.6831888753985766870111999999999D-23 /\n DATA ALGMCS( 11) / +.1429227355942498147573333333333D-24 /\n DATA ALGMCS( 12) / -.3547598158101070547199999999999D-26 /\n DATA ALGMCS( 13) / +.1025680058010470912000000000000D-27 /\n DATA ALGMCS( 14) / -.3401102254316748799999999999999D-29 /\n DATA ALGMCS( 15) / +.1276642195630062933333333333333D-30 /\n DATA FIRST /.TRUE./\n!***FIRST EXECUTABLE STATEMENT D9LGMC\n if (FIRST) THEN\n NALGM = INITDS (ALGMCS, 15, REAL(D1MACH(3)) )\n XBIG = 1.0D0/SQRT(D1MACH(3))\n XMAX = EXP (MIN(LOG(D1MACH(2)/12.D0), -LOG(12.D0*D1MACH(1))))\n end if\n FIRST = .FALSE.\n!\n if (X < 10.D0) call XERMSG ('SLATEC', 'D9LGMC', &\n 'X MUST BE GE 10', 1, 2)\n if (X >= XMAX) go to 20\n!\n D9LGMC = 1.D0/(12.D0*X)\n if (X < XBIG) D9LGMC = DCSEVL (2.0D0*(10.D0/X)**2-1.D0, ALGMCS, &\n NALGM) / X\n return\n!\n 20 D9LGMC = 0.D0\n call XERMSG ('SLATEC', 'D9LGMC', 'X SO BIG D9LGMC UNDERFLOWS', 2, &\n 1)\n return\n!\nend\n\n DOUBLE PRECISION FUNCTION DCSEVL (X, CS, N)\n!\n!! DCSEVL evaluates a Chebyshev series.\n!\n!***LIBRARY SLATEC (FNLIB)\n!***CATEGORY C3A2\n!***TYPE DOUBLE PRECISION (CSEVL-S, DCSEVL-D)\n!***KEYWORDS CHEBYSHEV SERIES, FNLIB, SPECIAL FUNCTIONS\n!***AUTHOR Fullerton, W., (LANL)\n!***DESCRIPTION\n!\n! Evaluate the N-term Chebyshev series CS at X. Adapted from\n! a method presented in the paper by Broucke referenced below.\n!\n! Input Arguments --\n! X value at which the series is to be evaluated.\n! CS array of N terms of a Chebyshev series. In evaluating\n! CS, only half the first coefficient is summed.\n! N number of terms in array CS.\n!\n!***REFERENCES R. Broucke, Ten subroutines for the manipulation of\n! Chebyshev series, Algorithm 446, Communications of\n! the A.C.M. 16, (1973) pp. 254-256.\n! L. Fox and I. B. Parker, Chebyshev Polynomials in\n! Numerical Analysis, Oxford University Press, 1968,\n! page 56.\n!***ROUTINES CALLED D1MACH, XERMSG\n!***REVISION HISTORY (YYMMDD)\n! 770401 DATE WRITTEN\n! 890831 Modified array declarations. (WRB)\n! 890831 REVISION DATE from Version 3.2\n! 891214 Prologue converted to Version 4.0 format. (BAB)\n! 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\n! 900329 Prologued revised extensively and code rewritten to allow\n! X to be slightly outside interval (-1,+1). (WRB)\n! 920501 Reformatted the REFERENCES section. (WRB)\n!***END PROLOGUE DCSEVL\n DOUBLE PRECISION B0, B1, B2, CS(*), ONEPL, TWOX, X, D1MACH\n LOGICAL FIRST\n SAVE FIRST, ONEPL\n DATA FIRST /.TRUE./\n!***FIRST EXECUTABLE STATEMENT DCSEVL\n if (FIRST) ONEPL = 1.0D0 + D1MACH(4)\n FIRST = .FALSE.\n if (N < 1) call XERMSG ('SLATEC', 'DCSEVL', &\n 'NUMBER OF TERMS <= 0', 2, 2)\n if (N > 1000) call XERMSG ('SLATEC', 'DCSEVL', &\n 'NUMBER OF TERMS > 1000', 3, 2)\n if (ABS(X) > ONEPL) call XERMSG ('SLATEC', 'DCSEVL', &\n 'X OUTSIDE THE INTERVAL (-1,+1)', 1, 1)\n!\n B1 = 0.0D0\n B0 = 0.0D0\n TWOX = 2.0D0*X\n DO 10 I = 1,N\n B2 = B1\n B1 = B0\n NI = N + 1 - I\n B0 = TWOX*B1 - B2 + CS(NI)\n 10 CONTINUE\n!\n DCSEVL = 0.5D0*(B0-B2)\n!\n return\nend\n\nfunction INITDS (OS, NOS, ETA)\n!\n!! INITDS determines the number of terms needed in an orthogonal ...\n! polynomial series so that it meets a specified accuracy.\n!\n!***LIBRARY SLATEC (FNLIB)\n!***CATEGORY C3A2\n!***TYPE DOUBLE PRECISION (INITS-S, INITDS-D)\n!***KEYWORDS CHEBYSHEV, FNLIB, INITIALIZE, ORTHOGONAL POLYNOMIAL,\n! ORTHOGONAL SERIES, SPECIAL FUNCTIONS\n!***AUTHOR Fullerton, W., (LANL)\n!***DESCRIPTION\n!\n! Initialize the orthogonal series, represented by the array OS, so\n! that INITDS is the number of terms needed to insure the error is no\n! larger than ETA. Ordinarily, ETA will be chosen to be one-tenth\n! machine precision.\n!\n! Input Arguments --\n! OS double precision array of NOS coefficients in an orthogonal\n! series.\n! NOS number of coefficients in OS.\n! ETA single precision scalar containing requested accuracy of\n! series.\n!\n!***REFERENCES (NONE)\n!***ROUTINES CALLED XERMSG\n!***REVISION HISTORY (YYMMDD)\n! 770601 DATE WRITTEN\n! 890531 Changed all specific intrinsics to generic. (WRB)\n! 890831 Modified array declarations. (WRB)\n! 891115 Modified error message. (WRB)\n! 891115 REVISION DATE from Version 3.2\n! 891214 Prologue converted to Version 4.0 format. (BAB)\n! 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\n!***END PROLOGUE INITDS\n DOUBLE PRECISION OS(*)\n!***FIRST EXECUTABLE STATEMENT INITDS\n if (NOS < 1) call XERMSG ('SLATEC', 'INITDS', &\n 'Number of coefficients is less than 1', 2, 1)\n!\n ERR = 0.\n DO 10 II = 1,NOS\n I = NOS + 1 - II\n ERR = ERR + ABS(REAL(OS(I)))\n if (ERR > ETA) go to 20\n 10 CONTINUE\n!\n 20 if (I == NOS) call XERMSG ('SLATEC', 'INITDS', &\n 'Chebyshev series too short for specified accuracy', 1, 1)\n INITDS = I\n!\n return\nend\n\n DOUBLE PRECISION FUNCTION DGAMMA (X)\n!\n!! DGAMMA computes the complete Gamma function.\n!\n!***LIBRARY SLATEC (FNLIB)\n!***CATEGORY C7A\n!***TYPE DOUBLE PRECISION (GAMMA-S, DGAMMA-D, CGAMMA-C)\n!***KEYWORDS COMPLETE GAMMA FUNCTION, FNLIB, SPECIAL FUNCTIONS\n!***AUTHOR Fullerton, W., (LANL)\n!***DESCRIPTION\n!\n! DGAMMA(X) calculates the double precision complete Gamma function\n! for double precision argument X.\n!\n! Series for GAM on the interval 0. to 1.00000E+00\n! with weighted error 5.79E-32\n! log weighted error 31.24\n! significant figures required 30.00\n! decimal places required 32.05\n!\n!***REFERENCES (NONE)\n!***ROUTINES CALLED D1MACH, D9LGMC, DCSEVL, DGAMLM, INITDS, XERMSG\n!***REVISION HISTORY (YYMMDD)\n! 770601 DATE WRITTEN\n! 890531 Changed all specific intrinsics to generic. (WRB)\n! 890911 Removed unnecessary intrinsics. (WRB)\n! 890911 REVISION DATE from Version 3.2\n! 891214 Prologue converted to Version 4.0 format. (BAB)\n! 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\n! 920618 Removed space from variable name. (RWC, WRB)\n!***END PROLOGUE DGAMMA\n DOUBLE PRECISION X, GAMCS(42), DXREL, PI, SINPIY, SQ2PIL, XMAX, &\n XMIN, Y, D9LGMC, DCSEVL, D1MACH\n LOGICAL FIRST\n!\n SAVE GAMCS, PI, SQ2PIL, NGAM, XMIN, XMAX, DXREL, FIRST\n DATA GAMCS( 1) / +.8571195590989331421920062399942D-2 /\n DATA GAMCS( 2) / +.4415381324841006757191315771652D-2 /\n DATA GAMCS( 3) / +.5685043681599363378632664588789D-1 /\n DATA GAMCS( 4) / -.4219835396418560501012500186624D-2 /\n DATA GAMCS( 5) / +.1326808181212460220584006796352D-2 /\n DATA GAMCS( 6) / -.1893024529798880432523947023886D-3 /\n DATA GAMCS( 7) / +.3606925327441245256578082217225D-4 /\n DATA GAMCS( 8) / -.6056761904460864218485548290365D-5 /\n DATA GAMCS( 9) / +.1055829546302283344731823509093D-5 /\n DATA GAMCS( 10) / -.1811967365542384048291855891166D-6 /\n DATA GAMCS( 11) / +.3117724964715322277790254593169D-7 /\n DATA GAMCS( 12) / -.5354219639019687140874081024347D-8 /\n DATA GAMCS( 13) / +.9193275519859588946887786825940D-9 /\n DATA GAMCS( 14) / -.1577941280288339761767423273953D-9 /\n DATA GAMCS( 15) / +.2707980622934954543266540433089D-10 /\n DATA GAMCS( 16) / -.4646818653825730144081661058933D-11 /\n DATA GAMCS( 17) / +.7973350192007419656460767175359D-12 /\n DATA GAMCS( 18) / -.1368078209830916025799499172309D-12 /\n DATA GAMCS( 19) / +.2347319486563800657233471771688D-13 /\n DATA GAMCS( 20) / -.4027432614949066932766570534699D-14 /\n DATA GAMCS( 21) / +.6910051747372100912138336975257D-15 /\n DATA GAMCS( 22) / -.1185584500221992907052387126192D-15 /\n DATA GAMCS( 23) / +.2034148542496373955201026051932D-16 /\n DATA GAMCS( 24) / -.3490054341717405849274012949108D-17 /\n DATA GAMCS( 25) / +.5987993856485305567135051066026D-18 /\n DATA GAMCS( 26) / -.1027378057872228074490069778431D-18 /\n DATA GAMCS( 27) / +.1762702816060529824942759660748D-19 /\n DATA GAMCS( 28) / -.3024320653735306260958772112042D-20 /\n DATA GAMCS( 29) / +.5188914660218397839717833550506D-21 /\n DATA GAMCS( 30) / -.8902770842456576692449251601066D-22 /\n DATA GAMCS( 31) / +.1527474068493342602274596891306D-22 /\n DATA GAMCS( 32) / -.2620731256187362900257328332799D-23 /\n DATA GAMCS( 33) / +.4496464047830538670331046570666D-24 /\n DATA GAMCS( 34) / -.7714712731336877911703901525333D-25 /\n DATA GAMCS( 35) / +.1323635453126044036486572714666D-25 /\n DATA GAMCS( 36) / -.2270999412942928816702313813333D-26 /\n DATA GAMCS( 37) / +.3896418998003991449320816639999D-27 /\n DATA GAMCS( 38) / -.6685198115125953327792127999999D-28 /\n DATA GAMCS( 39) / +.1146998663140024384347613866666D-28 /\n DATA GAMCS( 40) / -.1967938586345134677295103999999D-29 /\n DATA GAMCS( 41) / +.3376448816585338090334890666666D-30 /\n DATA GAMCS( 42) / -.5793070335782135784625493333333D-31 /\n DATA PI / 3.14159265358979323846264338327950D0 /\n DATA SQ2PIL / 0.91893853320467274178032973640562D0 /\n DATA FIRST /.TRUE./\n!***FIRST EXECUTABLE STATEMENT DGAMMA\n if (FIRST) THEN\n NGAM = INITDS (GAMCS, 42, 0.1*REAL(D1MACH(3)) )\n!\n call DGAMLM (XMIN, XMAX)\n DXREL = SQRT(D1MACH(4))\n end if\n FIRST = .FALSE.\n!\n Y = ABS(X)\n if (Y > 10.D0) go to 50\n!\n! COMPUTE GAMMA(X) FOR -XBND <= X <= XBND. REDUCE INTERVAL AND FIND\n! GAMMA(1+Y) FOR 0.0 <= Y < 1.0 FIRST OF ALL.\n!\n N = X\n if (X < 0.D0) N = N - 1\n Y = X - N\n N = N - 1\n DGAMMA = 0.9375D0 + DCSEVL (2.D0*Y-1.D0, GAMCS, NGAM)\n if (N == 0) RETURN\n!\n if (N > 0) go to 30\n!\n! COMPUTE GAMMA(X) FOR X < 1.0\n!\n N = -N\n if (X == 0.D0) call XERMSG ('SLATEC', 'DGAMMA', 'X IS 0', 4, 2)\n if (X < 0.0 .AND. X+N-2 == 0.D0) call XERMSG ('SLATEC', &\n 'DGAMMA', 'X IS A NEGATIVE INTEGER', 4, 2)\n if (X < (-0.5D0) .AND. ABS((X-AINT(X-0.5D0))/X) < DXREL) &\n call XERMSG ('SLATEC', 'DGAMMA', &\n 'ANSWER LT HALF PRECISION BECAUSE X TOO NEAR NEGATIVE INTEGER', &\n 1, 1)\n!\n DO 20 I=1,N\n DGAMMA = DGAMMA/(X+I-1 )\n 20 CONTINUE\n return\n!\n! GAMMA(X) FOR X >= 2.0 AND X <= 10.0\n!\n 30 DO 40 I=1,N\n DGAMMA = (Y+I) * DGAMMA\n 40 CONTINUE\n return\n!\n! GAMMA(X) FOR ABS(X) > 10.0. RECALL Y = ABS(X).\n!\n 50 if (X > XMAX) call XERMSG ('SLATEC', 'DGAMMA', &\n 'X SO BIG GAMMA OVERFLOWS', 3, 2)\n!\n DGAMMA = 0.D0\n if (X < XMIN) call XERMSG ('SLATEC', 'DGAMMA', &\n 'X SO SMALL GAMMA UNDERFLOWS', 2, 1)\n if (X < XMIN) RETURN\n!\n DGAMMA = EXP ((Y-0.5D0)*LOG(Y) - Y + SQ2PIL + D9LGMC(Y) )\n if (X > 0.D0) RETURN\n!\n if (ABS((X-AINT(X-0.5D0))/X) < DXREL) call XERMSG ('SLATEC', &\n 'DGAMMA', &\n 'ANSWER LT HALF PRECISION, X TOO NEAR NEGATIVE INTEGER', 1, 1)\n!\n SINPIY = SIN (PI*Y)\n if (SINPIY == 0.D0) call XERMSG ('SLATEC', 'DGAMMA', &\n 'X IS A NEGATIVE INTEGER', 4, 2)\n!\n DGAMMA = -PI/(Y*SINPIY*DGAMMA)\n!\n return\nend\n\nsubroutine DGAMLM (XMIN, XMAX)\n!\n!! DGAMLM computes bounds for the argument in the Gamma function.\n!\n!***LIBRARY SLATEC (FNLIB)\n!***CATEGORY C7A, R2\n!***TYPE DOUBLE PRECISION (GAMLIM-S, DGAMLM-D)\n!***KEYWORDS COMPLETE GAMMA FUNCTION, FNLIB, LIMITS, SPECIAL FUNCTIONS\n!***AUTHOR Fullerton, W., (LANL)\n!***DESCRIPTION\n!\n! Calculate the minimum and maximum legal bounds for X in gamma(X).\n! XMIN and XMAX are not the only bounds, but they are the only non-\n! trivial ones to calculate.\n!\n! Output Arguments --\n! XMIN double precision minimum legal value of X in gamma(X). Any\n! smaller value of X might result in underflow.\n! XMAX double precision maximum legal value of X in gamma(X). Any\n! larger value of X might cause overflow.\n!\n!***REFERENCES (NONE)\n!***ROUTINES CALLED D1MACH, XERMSG\n!***REVISION HISTORY (YYMMDD)\n! 770601 DATE WRITTEN\n! 890531 Changed all specific intrinsics to generic. (WRB)\n! 890531 REVISION DATE from Version 3.2\n! 891214 Prologue converted to Version 4.0 format. (BAB)\n! 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\n!***END PROLOGUE DGAMLM\n DOUBLE PRECISION XMIN, XMAX, ALNBIG, ALNSML, XLN, XOLD, D1MACH\n!***FIRST EXECUTABLE STATEMENT DGAMLM\n ALNSML = LOG(D1MACH(1))\n XMIN = -ALNSML\n DO 10 I=1,10\n XOLD = XMIN\n XLN = LOG(XMIN)\n XMIN = XMIN - XMIN*((XMIN+0.5D0)*XLN - XMIN - 0.2258D0 + ALNSML) &\n / (XMIN*XLN+0.5D0)\n if (ABS(XMIN-XOLD) < 0.005D0) go to 20\n 10 CONTINUE\n call XERMSG ('SLATEC', 'DGAMLM', 'UNABLE TO FIND XMIN', 1, 2)\n!\n 20 XMIN = -XMIN + 0.01D0\n!\n ALNBIG = LOG (D1MACH(2))\n XMAX = ALNBIG\n DO 30 I=1,10\n XOLD = XMAX\n XLN = LOG(XMAX)\n XMAX = XMAX - XMAX*((XMAX-0.5D0)*XLN - XMAX + 0.9189D0 - ALNBIG) &\n / (XMAX*XLN-0.5D0)\n if (ABS(XMAX-XOLD) < 0.005D0) go to 40\n 30 CONTINUE\n call XERMSG ('SLATEC', 'DGAMLM', 'UNABLE TO FIND XMAX', 2, 2)\n!\n 40 XMAX = XMAX - 0.01D0\n XMIN = MAX (XMIN, -XMAX+1.D0)\n!\n return\nend\n DOUBLE PRECISION FUNCTION DGAMLN (Z, IERR)\n!\n!! DGAMLN computes the logarithm of the Gamma function.\n!\n!***LIBRARY SLATEC\n!***CATEGORY C7A\n!***TYPE DOUBLE PRECISION (GAMLN-S, DGAMLN-D)\n!***KEYWORDS LOGARITHM OF GAMMA FUNCTION\n!***AUTHOR Amos, D. E., (SNL)\n!***DESCRIPTION\n!\n! **** A DOUBLE PRECISION ROUTINE ****\n! DGAMLN COMPUTES THE NATURAL LOG OF THE GAMMA FUNCTION FOR\n! Z > 0. THE ASYMPTOTIC EXPANSION IS USED TO GENERATE VALUES\n! GREATER THAN ZMIN WHICH ARE ADJUSTED BY THE RECURSION\n! G(Z+1)=Z*G(Z) FOR Z <= ZMIN. THE FUNCTION WAS MADE AS\n! PORTABLE AS POSSIBLE BY COMPUTING ZMIN FROM THE NUMBER OF BASE\n! 10 DIGITS IN A WORD, RLN=MAX(-ALOG10(R1MACH(4)),0.5E-18)\n! LIMITED TO 18 DIGITS OF (RELATIVE) ACCURACY.\n!\n! SINCE INTEGER ARGUMENTS ARE COMMON, A TABLE LOOK UP ON 100\n! VALUES IS USED FOR SPEED OF EXECUTION.\n!\n! DESCRIPTION OF ARGUMENTS\n!\n! INPUT Z IS DOUBLE PRECISION\n! Z - ARGUMENT, Z > 0.0D0\n!\n! OUTPUT DGAMLN IS DOUBLE PRECISION\n! DGAMLN - NATURAL LOG OF THE GAMMA FUNCTION AT Z /= 0.0D0\n! IERR - ERROR FLAG\n! IERR=0, NORMAL RETURN, COMPUTATION COMPLETED\n! IERR=1, Z <= 0.0D0, NO COMPUTATION\n!\n!\n!***REFERENCES COMPUTATION OF BESSEL FUNCTIONS OF COMPLEX ARGUMENT\n! BY D. E. AMOS, SAND83-0083, MAY, 1983.\n!***ROUTINES CALLED D1MACH, I1MACH\n!***REVISION HISTORY (YYMMDD)\n! 830501 DATE WRITTEN\n! 830501 REVISION DATE from Version 3.2\n! 910415 Prologue converted to Version 4.0 format. (BAB)\n! 920128 Category corrected. (WRB)\n! 921215 DGAMLN defined for Z negative. (WRB)\n!***END PROLOGUE DGAMLN\n DOUBLE PRECISION CF, CON, FLN, FZ, GLN, RLN, S, TLG, TRM, TST, &\n T1, WDTOL, Z, ZDMY, ZINC, ZM, ZMIN, ZP, ZSQ, D1MACH\n INTEGER I, IERR, I1M, K, MZ, NZ, I1MACH\n DIMENSION CF(22), GLN(100)\n! LNGAMMA(N), N=1,100\n DATA GLN(1), GLN(2), GLN(3), GLN(4), GLN(5), GLN(6), GLN(7), &\n GLN(8), GLN(9), GLN(10), GLN(11), GLN(12), GLN(13), GLN(14), &\n GLN(15), GLN(16), GLN(17), GLN(18), GLN(19), GLN(20), &\n GLN(21), GLN(22)/ &\n 0.00000000000000000D+00, 0.00000000000000000D+00, &\n 6.93147180559945309D-01, 1.79175946922805500D+00, &\n 3.17805383034794562D+00, 4.78749174278204599D+00, &\n 6.57925121201010100D+00, 8.52516136106541430D+00, &\n 1.06046029027452502D+01, 1.28018274800814696D+01, &\n 1.51044125730755153D+01, 1.75023078458738858D+01, &\n 1.99872144956618861D+01, 2.25521638531234229D+01, &\n 2.51912211827386815D+01, 2.78992713838408916D+01, &\n 3.06718601060806728D+01, 3.35050734501368889D+01, &\n 3.63954452080330536D+01, 3.93398841871994940D+01, &\n 4.23356164607534850D+01, 4.53801388984769080D+01/\n DATA GLN(23), GLN(24), GLN(25), GLN(26), GLN(27), GLN(28), &\n GLN(29), GLN(30), GLN(31), GLN(32), GLN(33), GLN(34), &\n GLN(35), GLN(36), GLN(37), GLN(38), GLN(39), GLN(40), &\n GLN(41), GLN(42), GLN(43), GLN(44)/ &\n 4.84711813518352239D+01, 5.16066755677643736D+01, &\n 5.47847293981123192D+01, 5.80036052229805199D+01, &\n 6.12617017610020020D+01, 6.45575386270063311D+01, &\n 6.78897431371815350D+01, 7.12570389671680090D+01, &\n 7.46582363488301644D+01, 7.80922235533153106D+01, &\n 8.15579594561150372D+01, 8.50544670175815174D+01, &\n 8.85808275421976788D+01, 9.21361756036870925D+01, &\n 9.57196945421432025D+01, 9.93306124547874269D+01, &\n 1.02968198614513813D+02, 1.06631760260643459D+02, &\n 1.10320639714757395D+02, 1.14034211781461703D+02, &\n 1.17771881399745072D+02, 1.21533081515438634D+02/\n DATA GLN(45), GLN(46), GLN(47), GLN(48), GLN(49), GLN(50), &\n GLN(51), GLN(52), GLN(53), GLN(54), GLN(55), GLN(56), &\n GLN(57), GLN(58), GLN(59), GLN(60), GLN(61), GLN(62), &\n GLN(63), GLN(64), GLN(65), GLN(66)/ &\n 1.25317271149356895D+02, 1.29123933639127215D+02, &\n 1.32952575035616310D+02, 1.36802722637326368D+02, &\n 1.40673923648234259D+02, 1.44565743946344886D+02, &\n 1.48477766951773032D+02, 1.52409592584497358D+02, &\n 1.56360836303078785D+02, 1.60331128216630907D+02, &\n 1.64320112263195181D+02, 1.68327445448427652D+02, &\n 1.72352797139162802D+02, 1.76395848406997352D+02, &\n 1.80456291417543771D+02, 1.84533828861449491D+02, &\n 1.88628173423671591D+02, 1.92739047287844902D+02, &\n 1.96866181672889994D+02, 2.01009316399281527D+02, &\n 2.05168199482641199D+02, 2.09342586752536836D+02/\n DATA GLN(67), GLN(68), GLN(69), GLN(70), GLN(71), GLN(72), &\n GLN(73), GLN(74), GLN(75), GLN(76), GLN(77), GLN(78), &\n GLN(79), GLN(80), GLN(81), GLN(82), GLN(83), GLN(84), &\n GLN(85), GLN(86), GLN(87), GLN(88)/ &\n 2.13532241494563261D+02, 2.17736934113954227D+02, &\n 2.21956441819130334D+02, 2.26190548323727593D+02, &\n 2.30439043565776952D+02, 2.34701723442818268D+02, &\n 2.38978389561834323D+02, 2.43268849002982714D+02, &\n 2.47572914096186884D+02, 2.51890402209723194D+02, &\n 2.56221135550009525D+02, 2.60564940971863209D+02, &\n 2.64921649798552801D+02, 2.69291097651019823D+02, &\n 2.73673124285693704D+02, 2.78067573440366143D+02, &\n 2.82474292687630396D+02, 2.86893133295426994D+02, &\n 2.91323950094270308D+02, 2.95766601350760624D+02, &\n 3.00220948647014132D+02, 3.04686856765668715D+02/\n DATA GLN(89), GLN(90), GLN(91), GLN(92), GLN(93), GLN(94), &\n GLN(95), GLN(96), GLN(97), GLN(98), GLN(99), GLN(100)/ &\n 3.09164193580146922D+02, 3.13652829949879062D+02, &\n 3.18152639620209327D+02, 3.22663499126726177D+02, &\n 3.27185287703775217D+02, 3.31717887196928473D+02, &\n 3.36261181979198477D+02, 3.40815058870799018D+02, &\n 3.45379407062266854D+02, 3.49954118040770237D+02, &\n 3.54539085519440809D+02, 3.59134205369575399D+02/\n! COEFFICIENTS OF ASYMPTOTIC EXPANSION\n DATA CF(1), CF(2), CF(3), CF(4), CF(5), CF(6), CF(7), CF(8), &\n CF(9), CF(10), CF(11), CF(12), CF(13), CF(14), CF(15), &\n CF(16), CF(17), CF(18), CF(19), CF(20), CF(21), CF(22)/ &\n 8.33333333333333333D-02, -2.77777777777777778D-03, &\n 7.93650793650793651D-04, -5.95238095238095238D-04, &\n 8.41750841750841751D-04, -1.91752691752691753D-03, &\n 6.41025641025641026D-03, -2.95506535947712418D-02, &\n 1.79644372368830573D-01, -1.39243221690590112D+00, &\n 1.34028640441683920D+01, -1.56848284626002017D+02, &\n 2.19310333333333333D+03, -3.61087712537249894D+04, &\n 6.91472268851313067D+05, -1.52382215394074162D+07, &\n 3.82900751391414141D+08, -1.08822660357843911D+10, &\n 3.47320283765002252D+11, -1.23696021422692745D+13, &\n 4.88788064793079335D+14, -2.13203339609193739D+16/\n!\n! LN(2*PI)\n DATA CON / 1.83787706640934548D+00/\n!\n!***FIRST EXECUTABLE STATEMENT DGAMLN\n IERR=0\n if (Z <= 0.0D0) go to 70\n if (Z > 101.0D0) go to 10\n NZ = Z\n FZ = Z - NZ\n if (FZ > 0.0D0) go to 10\n if (NZ > 100) go to 10\n DGAMLN = GLN(NZ)\n return\n 10 CONTINUE\n WDTOL = D1MACH(4)\n WDTOL = MAX(WDTOL,0.5D-18)\n I1M = I1MACH(14)\n RLN = D1MACH(5)*I1M\n FLN = MIN(RLN,20.0D0)\n FLN = MAX(FLN,3.0D0)\n FLN = FLN - 3.0D0\n ZM = 1.8000D0 + 0.3875D0*FLN\n MZ = ZM + 1\n ZMIN = MZ\n ZDMY = Z\n ZINC = 0.0D0\n if (Z >= ZMIN) go to 20\n ZINC = ZMIN - NZ\n ZDMY = Z + ZINC\n 20 CONTINUE\n ZP = 1.0D0/ZDMY\n T1 = CF(1)*ZP\n S = T1\n if (ZP < WDTOL) go to 40\n ZSQ = ZP*ZP\n TST = T1*WDTOL\n DO 30 K=2,22\n ZP = ZP*ZSQ\n TRM = CF(K)*ZP\n if (ABS(TRM) < TST) go to 40\n S = S + TRM\n 30 CONTINUE\n 40 CONTINUE\n if (ZINC /= 0.0D0) go to 50\n TLG = LOG(Z)\n DGAMLN = Z*(TLG-1.0D0) + 0.5D0*(CON-TLG) + S\n return\n 50 CONTINUE\n ZP = 1.0D0\n NZ = ZINC\n DO 60 I=1,NZ\n ZP = ZP*(Z+(I-1))\n 60 CONTINUE\n TLG = LOG(ZDMY)\n DGAMLN = ZDMY*(TLG-1.0D0) - LOG(ZP) + 0.5D0*(CON-TLG) + S\n return\n!\n!\n 70 CONTINUE\n DGAMLN = D1MACH(2)\n IERR=1\n return\nend\n\nsubroutine D9B0MP (X, AMPL, THETA)\n!\n!! D9B0MP evaluates the modulus and phase for the J0 and Y0 Bessel functions.\n!\n!***LIBRARY SLATEC (FNLIB)\n!***CATEGORY C10A1\n!***TYPE DOUBLE PRECISION (D9B0MP-D)\n!***KEYWORDS BESSEL FUNCTION, FNLIB, MODULUS, PHASE, SPECIAL FUNCTIONS\n!***AUTHOR Fullerton, W., (LANL)\n!***DESCRIPTION\n!\n! Evaluate the modulus and phase for the Bessel J0 and Y0 functions.\n!\n! Series for BM0 on the interval 1.56250E-02 to 6.25000E-02\n! with weighted error 4.40E-32\n! log weighted error 31.36\n! significant figures required 30.02\n! decimal places required 32.14\n!\n! Series for BTH0 on the interval 0. to 1.56250E-02\n! with weighted error 2.66E-32\n! log weighted error 31.57\n! significant figures required 30.67\n! decimal places required 32.40\n!\n! Series for BM02 on the interval 0. to 1.56250E-02\n! with weighted error 4.72E-32\n! log weighted error 31.33\n! significant figures required 30.00\n! decimal places required 32.13\n!\n! Series for BT02 on the interval 1.56250E-02 to 6.25000E-02\n! with weighted error 2.99E-32\n! log weighted error 31.52\n! significant figures required 30.61\n! decimal places required 32.32\n!\n!***REFERENCES (NONE)\n!***ROUTINES CALLED D1MACH, DCSEVL, INITDS, XERMSG\n!***REVISION HISTORY (YYMMDD)\n! 770701 DATE WRITTEN\n! 890531 Changed all specific intrinsics to generic. (WRB)\n! 890531 REVISION DATE from Version 3.2\n! 891214 Prologue converted to Version 4.0 format. (BAB)\n! 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\n! 900720 Routine changed from user-callable to subsidiary. (WRB)\n! 920618 Removed space from variable names. (RWC, WRB)\n!***END PROLOGUE D9B0MP\n DOUBLE PRECISION X, AMPL, THETA, BM0CS(37), BT02CS(39), &\n BM02CS(40), BTH0CS(44), XMAX, PI4, Z, D1MACH, DCSEVL\n LOGICAL FIRST\n SAVE BM0CS, BTH0CS, BM02CS, BT02CS, PI4, NBM0, NBT02, &\n NBM02, NBTH0, XMAX, FIRST\n DATA BM0CS( 1) / +.9211656246827742712573767730182D-1 /\n DATA BM0CS( 2) / -.1050590997271905102480716371755D-2 /\n DATA BM0CS( 3) / +.1470159840768759754056392850952D-4 /\n DATA BM0CS( 4) / -.5058557606038554223347929327702D-6 /\n DATA BM0CS( 5) / +.2787254538632444176630356137881D-7 /\n DATA BM0CS( 6) / -.2062363611780914802618841018973D-8 /\n DATA BM0CS( 7) / +.1870214313138879675138172596261D-9 /\n DATA BM0CS( 8) / -.1969330971135636200241730777825D-10 /\n DATA BM0CS( 9) / +.2325973793999275444012508818052D-11 /\n DATA BM0CS( 10) / -.3009520344938250272851224734482D-12 /\n DATA BM0CS( 11) / +.4194521333850669181471206768646D-13 /\n DATA BM0CS( 12) / -.6219449312188445825973267429564D-14 /\n DATA BM0CS( 13) / +.9718260411336068469601765885269D-15 /\n DATA BM0CS( 14) / -.1588478585701075207366635966937D-15 /\n DATA BM0CS( 15) / +.2700072193671308890086217324458D-16 /\n DATA BM0CS( 16) / -.4750092365234008992477504786773D-17 /\n DATA BM0CS( 17) / +.8615128162604370873191703746560D-18 /\n DATA BM0CS( 18) / -.1605608686956144815745602703359D-18 /\n DATA BM0CS( 19) / +.3066513987314482975188539801599D-19 /\n DATA BM0CS( 20) / -.5987764223193956430696505617066D-20 /\n DATA BM0CS( 21) / +.1192971253748248306489069841066D-20 /\n DATA BM0CS( 22) / -.2420969142044805489484682581333D-21 /\n DATA BM0CS( 23) / +.4996751760510616453371002879999D-22 /\n DATA BM0CS( 24) / -.1047493639351158510095040511999D-22 /\n DATA BM0CS( 25) / +.2227786843797468101048183466666D-23 /\n DATA BM0CS( 26) / -.4801813239398162862370542933333D-24 /\n DATA BM0CS( 27) / +.1047962723470959956476996266666D-24 /\n DATA BM0CS( 28) / -.2313858165678615325101260800000D-25 /\n DATA BM0CS( 29) / +.5164823088462674211635199999999D-26 /\n DATA BM0CS( 30) / -.1164691191850065389525401599999D-26 /\n DATA BM0CS( 31) / +.2651788486043319282958336000000D-27 /\n DATA BM0CS( 32) / -.6092559503825728497691306666666D-28 /\n DATA BM0CS( 33) / +.1411804686144259308038826666666D-28 /\n DATA BM0CS( 34) / -.3298094961231737245750613333333D-29 /\n DATA BM0CS( 35) / +.7763931143074065031714133333333D-30 /\n DATA BM0CS( 36) / -.1841031343661458478421333333333D-30 /\n DATA BM0CS( 37) / +.4395880138594310737100799999999D-31 /\n DATA BTH0CS( 1) / -.24901780862128936717709793789967D+0 /\n DATA BTH0CS( 2) / +.48550299609623749241048615535485D-3 /\n DATA BTH0CS( 3) / -.54511837345017204950656273563505D-5 /\n DATA BTH0CS( 4) / +.13558673059405964054377445929903D-6 /\n DATA BTH0CS( 5) / -.55691398902227626227583218414920D-8 /\n DATA BTH0CS( 6) / +.32609031824994335304004205719468D-9 /\n DATA BTH0CS( 7) / -.24918807862461341125237903877993D-10 /\n DATA BTH0CS( 8) / +.23449377420882520554352413564891D-11 /\n DATA BTH0CS( 9) / -.26096534444310387762177574766136D-12 /\n DATA BTH0CS( 10) / +.33353140420097395105869955014923D-13 /\n DATA BTH0CS( 11) / -.47890000440572684646750770557409D-14 /\n DATA BTH0CS( 12) / +.75956178436192215972642568545248D-15 /\n DATA BTH0CS( 13) / -.13131556016891440382773397487633D-15 /\n DATA BTH0CS( 14) / +.24483618345240857495426820738355D-16 /\n DATA BTH0CS( 15) / -.48805729810618777683256761918331D-17 /\n DATA BTH0CS( 16) / +.10327285029786316149223756361204D-17 /\n DATA BTH0CS( 17) / -.23057633815057217157004744527025D-18 /\n DATA BTH0CS( 18) / +.54044443001892693993017108483765D-19 /\n DATA BTH0CS( 19) / -.13240695194366572724155032882385D-19 /\n DATA BTH0CS( 20) / +.33780795621371970203424792124722D-20 /\n DATA BTH0CS( 21) / -.89457629157111779003026926292299D-21 /\n DATA BTH0CS( 22) / +.24519906889219317090899908651405D-21 /\n DATA BTH0CS( 23) / -.69388422876866318680139933157657D-22 /\n DATA BTH0CS( 24) / +.20228278714890138392946303337791D-22 /\n DATA BTH0CS( 25) / -.60628500002335483105794195371764D-23 /\n DATA BTH0CS( 26) / +.18649748964037635381823788396270D-23 /\n DATA BTH0CS( 27) / -.58783732384849894560245036530867D-24 /\n DATA BTH0CS( 28) / +.18958591447999563485531179503513D-24 /\n DATA BTH0CS( 29) / -.62481979372258858959291620728565D-25 /\n DATA BTH0CS( 30) / +.21017901684551024686638633529074D-25 /\n DATA BTH0CS( 31) / -.72084300935209253690813933992446D-26 /\n DATA BTH0CS( 32) / +.25181363892474240867156405976746D-26 /\n DATA BTH0CS( 33) / -.89518042258785778806143945953643D-27 /\n DATA BTH0CS( 34) / +.32357237479762298533256235868587D-27 /\n DATA BTH0CS( 35) / -.11883010519855353657047144113796D-27 /\n DATA BTH0CS( 36) / +.44306286907358104820579231941731D-28 /\n DATA BTH0CS( 37) / -.16761009648834829495792010135681D-28 /\n DATA BTH0CS( 38) / +.64292946921207466972532393966088D-29 /\n DATA BTH0CS( 39) / -.24992261166978652421207213682763D-29 /\n DATA BTH0CS( 40) / +.98399794299521955672828260355318D-30 /\n DATA BTH0CS( 41) / -.39220375242408016397989131626158D-30 /\n DATA BTH0CS( 42) / +.15818107030056522138590618845692D-30 /\n DATA BTH0CS( 43) / -.64525506144890715944344098365426D-31 /\n DATA BTH0CS( 44) / +.26611111369199356137177018346367D-31 /\n DATA BM02CS( 1) / +.9500415145228381369330861335560D-1 /\n DATA BM02CS( 2) / -.3801864682365670991748081566851D-3 /\n DATA BM02CS( 3) / +.2258339301031481192951829927224D-5 /\n DATA BM02CS( 4) / -.3895725802372228764730621412605D-7 /\n DATA BM02CS( 5) / +.1246886416512081697930990529725D-8 /\n DATA BM02CS( 6) / -.6065949022102503779803835058387D-10 /\n DATA BM02CS( 7) / +.4008461651421746991015275971045D-11 /\n DATA BM02CS( 8) / -.3350998183398094218467298794574D-12 /\n DATA BM02CS( 9) / +.3377119716517417367063264341996D-13 /\n DATA BM02CS( 10) / -.3964585901635012700569356295823D-14 /\n DATA BM02CS( 11) / +.5286111503883857217387939744735D-15 /\n DATA BM02CS( 12) / -.7852519083450852313654640243493D-16 /\n DATA BM02CS( 13) / +.1280300573386682201011634073449D-16 /\n DATA BM02CS( 14) / -.2263996296391429776287099244884D-17 /\n DATA BM02CS( 15) / +.4300496929656790388646410290477D-18 /\n DATA BM02CS( 16) / -.8705749805132587079747535451455D-19 /\n DATA BM02CS( 17) / +.1865862713962095141181442772050D-19 /\n DATA BM02CS( 18) / -.4210482486093065457345086972301D-20 /\n DATA BM02CS( 19) / +.9956676964228400991581627417842D-21 /\n DATA BM02CS( 20) / -.2457357442805313359605921478547D-21 /\n DATA BM02CS( 21) / +.6307692160762031568087353707059D-22 /\n DATA BM02CS( 22) / -.1678773691440740142693331172388D-22 /\n DATA BM02CS( 23) / +.4620259064673904433770878136087D-23 /\n DATA BM02CS( 24) / -.1311782266860308732237693402496D-23 /\n DATA BM02CS( 25) / +.3834087564116302827747922440276D-24 /\n DATA BM02CS( 26) / -.1151459324077741271072613293576D-24 /\n DATA BM02CS( 27) / +.3547210007523338523076971345213D-25 /\n DATA BM02CS( 28) / -.1119218385815004646264355942176D-25 /\n DATA BM02CS( 29) / +.3611879427629837831698404994257D-26 /\n DATA BM02CS( 30) / -.1190687765913333150092641762463D-26 /\n DATA BM02CS( 31) / +.4005094059403968131802476449536D-27 /\n DATA BM02CS( 32) / -.1373169422452212390595193916017D-27 /\n DATA BM02CS( 33) / +.4794199088742531585996491526437D-28 /\n DATA BM02CS( 34) / -.1702965627624109584006994476452D-28 /\n DATA BM02CS( 35) / +.6149512428936330071503575161324D-29 /\n DATA BM02CS( 36) / -.2255766896581828349944300237242D-29 /\n DATA BM02CS( 37) / +.8399707509294299486061658353200D-30 /\n DATA BM02CS( 38) / -.3172997595562602355567423936152D-30 /\n DATA BM02CS( 39) / +.1215205298881298554583333026514D-30 /\n DATA BM02CS( 40) / -.4715852749754438693013210568045D-31 /\n DATA BT02CS( 1) / -.24548295213424597462050467249324D+0 /\n DATA BT02CS( 2) / +.12544121039084615780785331778299D-2 /\n DATA BT02CS( 3) / -.31253950414871522854973446709571D-4 /\n DATA BT02CS( 4) / +.14709778249940831164453426969314D-5 /\n DATA BT02CS( 5) / -.99543488937950033643468850351158D-7 /\n DATA BT02CS( 6) / +.85493166733203041247578711397751D-8 /\n DATA BT02CS( 7) / -.86989759526554334557985512179192D-9 /\n DATA BT02CS( 8) / +.10052099533559791084540101082153D-9 /\n DATA BT02CS( 9) / -.12828230601708892903483623685544D-10 /\n DATA BT02CS( 10) / +.17731700781805131705655750451023D-11 /\n DATA BT02CS( 11) / -.26174574569485577488636284180925D-12 /\n DATA BT02CS( 12) / +.40828351389972059621966481221103D-13 /\n DATA BT02CS( 13) / -.66751668239742720054606749554261D-14 /\n DATA BT02CS( 14) / +.11365761393071629448392469549951D-14 /\n DATA BT02CS( 15) / -.20051189620647160250559266412117D-15 /\n DATA BT02CS( 16) / +.36497978794766269635720591464106D-16 /\n DATA BT02CS( 17) / -.68309637564582303169355843788800D-17 /\n DATA BT02CS( 18) / +.13107583145670756620057104267946D-17 /\n DATA BT02CS( 19) / -.25723363101850607778757130649599D-18 /\n DATA BT02CS( 20) / +.51521657441863959925267780949333D-19 /\n DATA BT02CS( 21) / -.10513017563758802637940741461333D-19 /\n DATA BT02CS( 22) / +.21820381991194813847301084501333D-20 /\n DATA BT02CS( 23) / -.46004701210362160577225905493333D-21 /\n DATA BT02CS( 24) / +.98407006925466818520953651199999D-22 /\n DATA BT02CS( 25) / -.21334038035728375844735986346666D-22 /\n DATA BT02CS( 26) / +.46831036423973365296066286933333D-23 /\n DATA BT02CS( 27) / -.10400213691985747236513382399999D-23 /\n DATA BT02CS( 28) / +.23349105677301510051777740800000D-24 /\n DATA BT02CS( 29) / -.52956825323318615788049749333333D-25 /\n DATA BT02CS( 30) / +.12126341952959756829196287999999D-25 /\n DATA BT02CS( 31) / -.28018897082289428760275626666666D-26 /\n DATA BT02CS( 32) / +.65292678987012873342593706666666D-27 /\n DATA BT02CS( 33) / -.15337980061873346427835733333333D-27 /\n DATA BT02CS( 34) / +.36305884306364536682359466666666D-28 /\n DATA BT02CS( 35) / -.86560755713629122479172266666666D-29 /\n DATA BT02CS( 36) / +.20779909972536284571238399999999D-29 /\n DATA BT02CS( 37) / -.50211170221417221674325333333333D-30 /\n DATA BT02CS( 38) / +.12208360279441714184191999999999D-30 /\n DATA BT02CS( 39) / -.29860056267039913454250666666666D-31 /\n DATA PI4 / 0.785398163397448309615660845819876D0 /\n DATA FIRST /.TRUE./\n!***FIRST EXECUTABLE STATEMENT D9B0MP\n if (FIRST) THEN\n ETA = 0.1*REAL(D1MACH(3))\n NBM0 = INITDS (BM0CS, 37, ETA)\n NBT02 = INITDS (BT02CS, 39, ETA)\n NBM02 = INITDS (BM02CS, 40, ETA)\n NBTH0 = INITDS (BTH0CS, 44, ETA)\n!\n XMAX = 1.0D0/D1MACH(4)\n end if\n FIRST = .FALSE.\n!\n if (X < 4.D0) call XERMSG ('SLATEC', 'D9B0MP', &\n 'X MUST BE GE 4', 1, 2)\n!\n if (X > 8.D0) go to 20\n Z = (128.D0/(X*X) - 5.D0)/3.D0\n AMPL = (.75D0 + DCSEVL (Z, BM0CS, NBM0))/SQRT(X)\n THETA = X - PI4 + DCSEVL (Z, BT02CS, NBT02)/X\n return\n!\n 20 if (X > XMAX) call XERMSG ('SLATEC', 'D9B0MP', &\n 'NO PRECISION BECAUSE X IS BIG', 2, 2)\n!\n Z = 128.D0/(X*X) - 1.D0\n AMPL = (.75D0 + DCSEVL (Z, BM02CS, NBM02))/SQRT(X)\n THETA = X - PI4 + DCSEVL (Z, BTH0CS, NBTH0)/X\n return\n!\nend\n\nsubroutine D9B1MP (X, AMPL, THETA)\n!\n!! D9B1MP evaluates the modulus and phase for the J1 and Y1 Bessel functions.\n!\n!***LIBRARY SLATEC (FNLIB)\n!***CATEGORY C10A1\n!***TYPE DOUBLE PRECISION (D9B1MP-D)\n!***KEYWORDS BESSEL FUNCTION, FNLIB, MODULUS, PHASE, SPECIAL FUNCTIONS\n!***AUTHOR Fullerton, W., (LANL)\n!***DESCRIPTION\n!\n! Evaluate the modulus and phase for the Bessel J1 and Y1 functions.\n!\n! Series for BM1 on the interval 1.56250E-02 to 6.25000E-02\n! with weighted error 4.91E-32\n! log weighted error 31.31\n! significant figures required 30.04\n! decimal places required 32.09\n!\n! Series for BT12 on the interval 1.56250E-02 to 6.25000E-02\n! with weighted error 3.33E-32\n! log weighted error 31.48\n! significant figures required 31.05\n! decimal places required 32.27\n!\n! Series for BM12 on the interval 0. to 1.56250E-02\n! with weighted error 5.01E-32\n! log weighted error 31.30\n! significant figures required 29.99\n! decimal places required 32.10\n!\n! Series for BTH1 on the interval 0. to 1.56250E-02\n! with weighted error 2.82E-32\n! log weighted error 31.55\n! significant figures required 31.12\n! decimal places required 32.37\n!\n!***SEE ALSO DBESJ1, DBESY1\n!***REFERENCES (NONE)\n!***ROUTINES CALLED D1MACH, DCSEVL, INITDS, XERMSG\n!***REVISION HISTORY (YYMMDD)\n! 770701 DATE WRITTEN\n! 890531 Changed all specific intrinsics to generic. (WRB)\n! 890531 REVISION DATE from Version 3.2\n! 891214 Prologue converted to Version 4.0 format. (BAB)\n! 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\n! 900720 Routine changed from user-callable to subsidiary. (WRB)\n! 920618 Removed space from variable name and code restructured to\n! use IF-THEN-ELSE. (RWC, WRB)\n!***END PROLOGUE D9B1MP\n DOUBLE PRECISION X, AMPL, THETA, BM1CS(37), BT12CS(39), &\n BM12CS(40), BTH1CS(44), XMAX, PI4, Z, D1MACH, DCSEVL\n LOGICAL FIRST\n SAVE BM1CS, BT12CS, BTH1CS, BM12CS, PI4, NBM1, NBT12, &\n NBM12, NBTH1, XMAX, FIRST\n DATA BM1CS( 1) / +.1069845452618063014969985308538D+0 /\n DATA BM1CS( 2) / +.3274915039715964900729055143445D-2 /\n DATA BM1CS( 3) / -.2987783266831698592030445777938D-4 /\n DATA BM1CS( 4) / +.8331237177991974531393222669023D-6 /\n DATA BM1CS( 5) / -.4112665690302007304896381725498D-7 /\n DATA BM1CS( 6) / +.2855344228789215220719757663161D-8 /\n DATA BM1CS( 7) / -.2485408305415623878060026596055D-9 /\n DATA BM1CS( 8) / +.2543393338072582442742484397174D-10 /\n DATA BM1CS( 9) / -.2941045772822967523489750827909D-11 /\n DATA BM1CS( 10) / +.3743392025493903309265056153626D-12 /\n DATA BM1CS( 11) / -.5149118293821167218720548243527D-13 /\n DATA BM1CS( 12) / +.7552535949865143908034040764199D-14 /\n DATA BM1CS( 13) / -.1169409706828846444166290622464D-14 /\n DATA BM1CS( 14) / +.1896562449434791571721824605060D-15 /\n DATA BM1CS( 15) / -.3201955368693286420664775316394D-16 /\n DATA BM1CS( 16) / +.5599548399316204114484169905493D-17 /\n DATA BM1CS( 17) / -.1010215894730432443119390444544D-17 /\n DATA BM1CS( 18) / +.1873844985727562983302042719573D-18 /\n DATA BM1CS( 19) / -.3563537470328580219274301439999D-19 /\n DATA BM1CS( 20) / +.6931283819971238330422763519999D-20 /\n DATA BM1CS( 21) / -.1376059453406500152251408930133D-20 /\n DATA BM1CS( 22) / +.2783430784107080220599779327999D-21 /\n DATA BM1CS( 23) / -.5727595364320561689348669439999D-22 /\n DATA BM1CS( 24) / +.1197361445918892672535756799999D-22 /\n DATA BM1CS( 25) / -.2539928509891871976641440426666D-23 /\n DATA BM1CS( 26) / +.5461378289657295973069619199999D-24 /\n DATA BM1CS( 27) / -.1189211341773320288986289493333D-24 /\n DATA BM1CS( 28) / +.2620150977340081594957824000000D-25 /\n DATA BM1CS( 29) / -.5836810774255685901920938666666D-26 /\n DATA BM1CS( 30) / +.1313743500080595773423615999999D-26 /\n DATA BM1CS( 31) / -.2985814622510380355332778666666D-27 /\n DATA BM1CS( 32) / +.6848390471334604937625599999999D-28 /\n DATA BM1CS( 33) / -.1584401568222476721192960000000D-28 /\n DATA BM1CS( 34) / +.3695641006570938054301013333333D-29 /\n DATA BM1CS( 35) / -.8687115921144668243012266666666D-30 /\n DATA BM1CS( 36) / +.2057080846158763462929066666666D-30 /\n DATA BM1CS( 37) / -.4905225761116225518523733333333D-31 /\n DATA BT12CS( 1) / +.73823860128742974662620839792764D+0 /\n DATA BT12CS( 2) / -.33361113174483906384470147681189D-2 /\n DATA BT12CS( 3) / +.61463454888046964698514899420186D-4 /\n DATA BT12CS( 4) / -.24024585161602374264977635469568D-5 /\n DATA BT12CS( 5) / +.14663555577509746153210591997204D-6 /\n DATA BT12CS( 6) / -.11841917305589180567005147504983D-7 /\n DATA BT12CS( 7) / +.11574198963919197052125466303055D-8 /\n DATA BT12CS( 8) / -.13001161129439187449366007794571D-9 /\n DATA BT12CS( 9) / +.16245391141361731937742166273667D-10 /\n DATA BT12CS( 10) / -.22089636821403188752155441770128D-11 /\n DATA BT12CS( 11) / +.32180304258553177090474358653778D-12 /\n DATA BT12CS( 12) / -.49653147932768480785552021135381D-13 /\n DATA BT12CS( 13) / +.80438900432847825985558882639317D-14 /\n DATA BT12CS( 14) / -.13589121310161291384694712682282D-14 /\n DATA BT12CS( 15) / +.23810504397147214869676529605973D-15 /\n DATA BT12CS( 16) / -.43081466363849106724471241420799D-16 /\n DATA BT12CS( 17) / +.80202544032771002434993512550400D-17 /\n DATA BT12CS( 18) / -.15316310642462311864230027468799D-17 /\n DATA BT12CS( 19) / +.29928606352715568924073040554666D-18 /\n DATA BT12CS( 20) / -.59709964658085443393815636650666D-19 /\n DATA BT12CS( 21) / +.12140289669415185024160852650666D-19 /\n DATA BT12CS( 22) / -.25115114696612948901006977706666D-20 /\n DATA BT12CS( 23) / +.52790567170328744850738380799999D-21 /\n DATA BT12CS( 24) / -.11260509227550498324361161386666D-21 /\n DATA BT12CS( 25) / +.24348277359576326659663462400000D-22 /\n DATA BT12CS( 26) / -.53317261236931800130038442666666D-23 /\n DATA BT12CS( 27) / +.11813615059707121039205990399999D-23 /\n DATA BT12CS( 28) / -.26465368283353523514856789333333D-24 /\n DATA BT12CS( 29) / +.59903394041361503945577813333333D-25 /\n DATA BT12CS( 30) / -.13690854630829503109136383999999D-25 /\n DATA BT12CS( 31) / +.31576790154380228326413653333333D-26 /\n DATA BT12CS( 32) / -.73457915082084356491400533333333D-27 /\n DATA BT12CS( 33) / +.17228081480722747930705920000000D-27 /\n DATA BT12CS( 34) / -.40716907961286507941068800000000D-28 /\n DATA BT12CS( 35) / +.96934745136779622700373333333333D-29 /\n DATA BT12CS( 36) / -.23237636337765716765354666666666D-29 /\n DATA BT12CS( 37) / +.56074510673522029406890666666666D-30 /\n DATA BT12CS( 38) / -.13616465391539005860522666666666D-30 /\n DATA BT12CS( 39) / +.33263109233894654388906666666666D-31 /\n DATA BM12CS( 1) / +.9807979156233050027272093546937D-1 /\n DATA BM12CS( 2) / +.1150961189504685306175483484602D-2 /\n DATA BM12CS( 3) / -.4312482164338205409889358097732D-5 /\n DATA BM12CS( 4) / +.5951839610088816307813029801832D-7 /\n DATA BM12CS( 5) / -.1704844019826909857400701586478D-8 /\n DATA BM12CS( 6) / +.7798265413611109508658173827401D-10 /\n DATA BM12CS( 7) / -.4958986126766415809491754951865D-11 /\n DATA BM12CS( 8) / +.4038432416421141516838202265144D-12 /\n DATA BM12CS( 9) / -.3993046163725175445765483846645D-13 /\n DATA BM12CS( 10) / +.4619886183118966494313342432775D-14 /\n DATA BM12CS( 11) / -.6089208019095383301345472619333D-15 /\n DATA BM12CS( 12) / +.8960930916433876482157048041249D-16 /\n DATA BM12CS( 13) / -.1449629423942023122916518918925D-16 /\n DATA BM12CS( 14) / +.2546463158537776056165149648068D-17 /\n DATA BM12CS( 15) / -.4809472874647836444259263718620D-18 /\n DATA BM12CS( 16) / +.9687684668292599049087275839124D-19 /\n DATA BM12CS( 17) / -.2067213372277966023245038117551D-19 /\n DATA BM12CS( 18) / +.4646651559150384731802767809590D-20 /\n DATA BM12CS( 19) / -.1094966128848334138241351328339D-20 /\n DATA BM12CS( 20) / +.2693892797288682860905707612785D-21 /\n DATA BM12CS( 21) / -.6894992910930374477818970026857D-22 /\n DATA BM12CS( 22) / +.1830268262752062909890668554740D-22 /\n DATA BM12CS( 23) / -.5025064246351916428156113553224D-23 /\n DATA BM12CS( 24) / +.1423545194454806039631693634194D-23 /\n DATA BM12CS( 25) / -.4152191203616450388068886769801D-24 /\n DATA BM12CS( 26) / +.1244609201503979325882330076547D-24 /\n DATA BM12CS( 27) / -.3827336370569304299431918661286D-25 /\n DATA BM12CS( 28) / +.1205591357815617535374723981835D-25 /\n DATA BM12CS( 29) / -.3884536246376488076431859361124D-26 /\n DATA BM12CS( 30) / +.1278689528720409721904895283461D-26 /\n DATA BM12CS( 31) / -.4295146689447946272061936915912D-27 /\n DATA BM12CS( 32) / +.1470689117829070886456802707983D-27 /\n DATA BM12CS( 33) / -.5128315665106073128180374017796D-28 /\n DATA BM12CS( 34) / +.1819509585471169385481437373286D-28 /\n DATA BM12CS( 35) / -.6563031314841980867618635050373D-29 /\n DATA BM12CS( 36) / +.2404898976919960653198914875834D-29 /\n DATA BM12CS( 37) / -.8945966744690612473234958242979D-30 /\n DATA BM12CS( 38) / +.3376085160657231026637148978240D-30 /\n DATA BM12CS( 39) / -.1291791454620656360913099916966D-30 /\n DATA BM12CS( 40) / +.5008634462958810520684951501254D-31 /\n DATA BTH1CS( 1) / +.74749957203587276055443483969695D+0 /\n DATA BTH1CS( 2) / -.12400777144651711252545777541384D-2 /\n DATA BTH1CS( 3) / +.99252442404424527376641497689592D-5 /\n DATA BTH1CS( 4) / -.20303690737159711052419375375608D-6 /\n DATA BTH1CS( 5) / +.75359617705690885712184017583629D-8 /\n DATA BTH1CS( 6) / -.41661612715343550107630023856228D-9 /\n DATA BTH1CS( 7) / +.30701618070834890481245102091216D-10 /\n DATA BTH1CS( 8) / -.28178499637605213992324008883924D-11 /\n DATA BTH1CS( 9) / +.30790696739040295476028146821647D-12 /\n DATA BTH1CS( 10) / -.38803300262803434112787347554781D-13 /\n DATA BTH1CS( 11) / +.55096039608630904934561726208562D-14 /\n DATA BTH1CS( 12) / -.86590060768383779940103398953994D-15 /\n DATA BTH1CS( 13) / +.14856049141536749003423689060683D-15 /\n DATA BTH1CS( 14) / -.27519529815904085805371212125009D-16 /\n DATA BTH1CS( 15) / +.54550796090481089625036223640923D-17 /\n DATA BTH1CS( 16) / -.11486534501983642749543631027177D-17 /\n DATA BTH1CS( 17) / +.25535213377973900223199052533522D-18 /\n DATA BTH1CS( 18) / -.59621490197413450395768287907849D-19 /\n DATA BTH1CS( 19) / +.14556622902372718620288302005833D-19 /\n DATA BTH1CS( 20) / -.37022185422450538201579776019593D-20 /\n DATA BTH1CS( 21) / +.97763074125345357664168434517924D-21 /\n DATA BTH1CS( 22) / -.26726821639668488468723775393052D-21 /\n DATA BTH1CS( 23) / +.75453300384983271794038190655764D-22 /\n DATA BTH1CS( 24) / -.21947899919802744897892383371647D-22 /\n DATA BTH1CS( 25) / +.65648394623955262178906999817493D-23 /\n DATA BTH1CS( 26) / -.20155604298370207570784076869519D-23 /\n DATA BTH1CS( 27) / +.63417768556776143492144667185670D-24 /\n DATA BTH1CS( 28) / -.20419277885337895634813769955591D-24 /\n DATA BTH1CS( 29) / +.67191464220720567486658980018551D-25 /\n DATA BTH1CS( 30) / -.22569079110207573595709003687336D-25 /\n DATA BTH1CS( 31) / +.77297719892989706370926959871929D-26 /\n DATA BTH1CS( 32) / -.26967444512294640913211424080920D-26 /\n DATA BTH1CS( 33) / +.95749344518502698072295521933627D-27 /\n DATA BTH1CS( 34) / -.34569168448890113000175680827627D-27 /\n DATA BTH1CS( 35) / +.12681234817398436504211986238374D-27 /\n DATA BTH1CS( 36) / -.47232536630722639860464993713445D-28 /\n DATA BTH1CS( 37) / +.17850008478186376177858619796417D-28 /\n DATA BTH1CS( 38) / -.68404361004510395406215223566746D-29 /\n DATA BTH1CS( 39) / +.26566028671720419358293422672212D-29 /\n DATA BTH1CS( 40) / -.10450402527914452917714161484670D-29 /\n DATA BTH1CS( 41) / +.41618290825377144306861917197064D-30 /\n DATA BTH1CS( 42) / -.16771639203643714856501347882887D-30 /\n DATA BTH1CS( 43) / +.68361997776664389173535928028528D-31 /\n DATA BTH1CS( 44) / -.28172247861233641166739574622810D-31 /\n DATA PI4 / 0.785398163397448309615660845819876D0 /\n DATA FIRST /.TRUE./\n!***FIRST EXECUTABLE STATEMENT D9B1MP\n if (FIRST) THEN\n ETA = 0.1*REAL(D1MACH(3))\n NBM1 = INITDS (BM1CS, 37, ETA)\n NBT12 = INITDS (BT12CS, 39, ETA)\n NBM12 = INITDS (BM12CS, 40, ETA)\n NBTH1 = INITDS (BTH1CS, 44, ETA)\n!\n XMAX = 1.0D0/D1MACH(4)\n end if\n FIRST = .FALSE.\n!\n if (X < 4.0D0) THEN\n call XERMSG ('SLATEC', 'D9B1MP', 'X must be >= 4', 1, 2)\n AMPL = 0.0D0\n THETA = 0.0D0\n ELSE if (X <= 8.0D0) THEN\n Z = (128.0D0/(X*X) - 5.0D0)/3.0D0\n AMPL = (0.75D0 + DCSEVL (Z, BM1CS, NBM1))/SQRT(X)\n THETA = X - 3.0D0*PI4 + DCSEVL (Z, BT12CS, NBT12)/X\n ELSE\n if (X > XMAX) call XERMSG ('SLATEC', 'D9B1MP', &\n 'No precision because X is too big', 2, 2)\n!\n Z = 128.0D0/(X*X) - 1.0D0\n AMPL = (0.75D0 + DCSEVL (Z, BM12CS, NBM12))/SQRT(X)\n THETA = X - 3.0D0*PI4 + DCSEVL (Z, BTH1CS, NBTH1)/X\n end if\n return\nend\n\n\n\n! ============================\n! = Single precision Bessels =\n! ============================\nsubroutine BESJ (X, ALPHA, N, Y, NZ)\n!\n!! BESJ computes an N member sequence of J Bessel functions ...\n! J/SUB(ALPHA+K-1)/(X), K=1,...,N for non-negative ALPHA and X.\n!\n!***LIBRARY SLATEC\n!***CATEGORY C10A3\n!***TYPE SINGLE PRECISION (BESJ-S, DBESJ-D)\n!***KEYWORDS J BESSEL FUNCTION, SPECIAL FUNCTIONS\n!***AUTHOR Amos, D. E., (SNLA)\n! Daniel, S. L., (SNLA)\n! Weston, M. K., (SNLA)\n!***DESCRIPTION\n!\n! Abstract\n! BESJ computes an N member sequence of J Bessel functions\n! J/sub(ALPHA+K-1)/(X), K=1,...,N for non-negative ALPHA and X.\n! A combination of the power series, the asymptotic expansion\n! for X to infinity and the uniform asymptotic expansion for\n! NU to infinity are applied over subdivisions of the (NU,X)\n! plane. For values of (NU,X) not covered by one of these\n! formulae, the order is incremented or decremented by integer\n! values into a region where one of the formulae apply. Backward\n! recursion is applied to reduce orders by integer values except\n! where the entire sequence lies in the oscillatory region. In\n! this case forward recursion is stable and values from the\n! asymptotic expansion for X to infinity start the recursion\n! when it is efficient to do so. Leading terms of the series\n! and uniform expansion are tested for underflow. If a sequence\n! is requested and the last member would underflow, the result\n! is set to zero and the next lower order tried, etc., until a\n! member comes on scale or all members are set to zero.\n! Overflow cannot occur.\n!\n! Description of Arguments\n!\n! Input\n! X - X >= 0.0E0\n! ALPHA - order of first member of the sequence,\n! ALPHA >= 0.0E0\n! N - number of members in the sequence, N >= 1\n!\n! Output\n! Y - a vector whose first N components contain\n! values for J/sub(ALPHA+K-1)/(X), K=1,...,N\n! NZ - number of components of Y set to zero due to\n! underflow,\n! NZ=0 , normal return, computation completed\n! NZ /= 0, last NZ components of Y set to zero,\n! Y(K)=0.0E0, K=N-NZ+1,...,N.\n!\n! Error Conditions\n! Improper input arguments - a fatal error\n! Underflow - a non-fatal error (NZ /= 0)\n!\n!***REFERENCES D. E. Amos, S. L. Daniel and M. K. Weston, CDC 6600\n! subroutines IBESS and JBESS for Bessel functions\n! I(NU,X) and J(NU,X), X >= 0, NU >= 0, ACM\n! Transactions on Mathematical Software 3, (1977),\n! pp. 76-92.\n! F. W. J. Olver, Tables of Bessel Functions of Moderate\n! or Large Orders, NPL Mathematical Tables 6, Her\n! Majesty's Stationery Office, London, 1962.\n!***ROUTINES CALLED ALNGAM, ASYJY, I1MACH, JAIRY, R1MACH, XERMSG\n!***REVISION HISTORY (YYMMDD)\n! 750101 DATE WRITTEN\n! 890531 Changed all specific intrinsics to generic. (WRB)\n! 890531 REVISION DATE from Version 3.2\n! 891214 Prologue converted to Version 4.0 format. (BAB)\n! 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\n! 900326 Removed duplicate information from DESCRIPTION section.\n! (WRB)\n! 920501 Reformatted the REFERENCES section. (WRB)\n!***END PROLOGUE BESJ\n EXTERNAL JAIRY\n INTEGER I,IALP,IDALP,IFLW,IN,INLIM,IS,I1,I2,K,KK,KM,KT,N,NN, &\n NS,NZ\n INTEGER I1MACH\n REAL AK,AKM,ALPHA,ANS,AP,ARG,COEF,DALPHA,DFN,DTM,EARG, &\n ELIM1,ETX,FIDAL,FLGJY,FN,FNF,FNI,FNP1,FNU,FNULIM, &\n GLN,PDF,PIDT,PP,RDEN,RELB,RTTP,RTWO,RTX,RZDEN, &\n S,SA,SB,SXO2,S1,S2,T,TA,TAU,TB,TEMP,TFN,TM,TOL, &\n TOLLN,TRX,TX,T1,T2,WK,X,XO2,XO2L,Y,RTOL,SLIM\n SAVE RTWO, PDF, RTTP, PIDT, PP, INLIM, FNULIM\n REAL R1MACH, ALNGAM\n DIMENSION Y(*), TEMP(3), FNULIM(2), PP(4), WK(7)\n DATA RTWO,PDF,RTTP,PIDT / 1.34839972492648E+00, &\n 7.85398163397448E-01, 7.97884560802865E-01, 1.57079632679490E+00/\n DATA PP(1), PP(2), PP(3), PP(4) / 8.72909153935547E+00, &\n 2.65693932265030E-01, 1.24578576865586E-01, 7.70133747430388E-04/\n DATA INLIM / 150 /\n DATA FNULIM(1), FNULIM(2) / 100.0E0, 60.0E0 /\n!***FIRST EXECUTABLE STATEMENT BESJ\n NZ = 0\n KT = 1\n NS=0\n! I1MACH(14) REPLACES I1MACH(11) IN A DOUBLE PRECISION CODE\n! I1MACH(15) REPLACES I1MACH(12) IN A DOUBLE PRECISION CODE\n TA = R1MACH(3)\n TOL = MAX(TA,1.0E-15)\n I1 = I1MACH(11) + 1\n I2 = I1MACH(12)\n TB = R1MACH(5)\n ELIM1 = -2.303E0*(I2*TB+3.0E0)\n RTOL=1.0E0/TOL\n SLIM=R1MACH(1)*1.0E+3*RTOL\n! TOLLN = -LN(TOL)\n TOLLN = 2.303E0*TB*I1\n TOLLN = MIN(TOLLN,34.5388E0)\n if (N-1) 720, 10, 20\n 10 KT = 2\n 20 NN = N\n if (X) 730, 30, 80\n 30 if (ALPHA) 710, 40, 50\n 40 Y(1) = 1.0E0\n if (N == 1) RETURN\n I1 = 2\n go to 60\n 50 I1 = 1\n 60 DO 70 I=I1,N\n Y(I) = 0.0E0\n 70 CONTINUE\n return\n 80 CONTINUE\n if (ALPHA < 0.0E0) go to 710\n!\n IALP = INT(ALPHA)\n FNI = IALP + N - 1\n FNF = ALPHA - IALP\n DFN = FNI + FNF\n FNU = DFN\n XO2 = X*0.5E0\n SXO2 = XO2*XO2\n!\n! DECISION TREE FOR REGION WHERE SERIES, ASYMPTOTIC EXPANSION FOR X\n! TO INFINITY AND ASYMPTOTIC EXPANSION FOR NU TO INFINITY ARE\n! APPLIED.\n!\n if (SXO2 <= (FNU+1.0E0)) go to 90\n TA = MAX(20.0E0,FNU)\n if (X > TA) go to 120\n if (X > 12.0E0) go to 110\n XO2L = LOG(XO2)\n NS = INT(SXO2-FNU) + 1\n go to 100\n 90 FN = FNU\n FNP1 = FN + 1.0E0\n XO2L = LOG(XO2)\n IS = KT\n if (X <= 0.50E0) go to 330\n NS = 0\n 100 FNI = FNI + NS\n DFN = FNI + FNF\n FN = DFN\n FNP1 = FN + 1.0E0\n IS = KT\n if (N-1+NS > 0) IS = 3\n go to 330\n 110 ANS = MAX(36.0E0-FNU,0.0E0)\n NS = INT(ANS)\n FNI = FNI + NS\n DFN = FNI + FNF\n FN = DFN\n IS = KT\n if (N-1+NS > 0) IS = 3\n go to 130\n 120 CONTINUE\n RTX = SQRT(X)\n TAU = RTWO*RTX\n TA = TAU + FNULIM(KT)\n if (FNU <= TA) go to 480\n FN = FNU\n IS = KT\n!\n! UNIFORM ASYMPTOTIC EXPANSION FOR NU TO INFINITY\n!\n 130 CONTINUE\n I1 = ABS(3-IS)\n I1 = MAX(I1,1)\n FLGJY = 1.0E0\n call ASYJY(JAIRY,X,FN,FLGJY,I1,TEMP(IS),WK,IFLW)\n if ( IFLW /= 0) go to 380\n go to (320, 450, 620), IS\n 310 TEMP(1) = TEMP(3)\n KT = 1\n 320 IS = 2\n FNI = FNI - 1.0E0\n DFN = FNI + FNF\n FN = DFN\n if ( I1 == 2) go to 450\n go to 130\n!\n! SERIES FOR (X/2)**2 <= NU+1\n!\n 330 CONTINUE\n GLN = ALNGAM(FNP1)\n ARG = FN*XO2L - GLN\n if (ARG < (-ELIM1)) go to 400\n EARG = EXP(ARG)\n 340 CONTINUE\n S = 1.0E0\n if (X < TOL) go to 360\n AK = 3.0E0\n T2 = 1.0E0\n T = 1.0E0\n S1 = FN\n DO 350 K=1,17\n S2 = T2 + S1\n T = -T*SXO2/S2\n S = S + T\n if (ABS(T) < TOL) go to 360\n T2 = T2 + AK\n AK = AK + 2.0E0\n S1 = S1 + FN\n 350 CONTINUE\n 360 CONTINUE\n TEMP(IS) = S*EARG\n go to (370, 450, 610), IS\n 370 EARG = EARG*FN/XO2\n FNI = FNI - 1.0E0\n DFN = FNI + FNF\n FN = DFN\n IS = 2\n go to 340\n!\n! SET UNDERFLOW VALUE AND UPDATE PARAMETERS\n! UNDERFLOW CAN ONLY OCCUR FOR NS=0 SINCE THE ORDER MUST BE\n! LARGER THAN 36. THEREFORE, NS NEED NOT BE CONSIDERED.\n!\n 380 Y(NN) = 0.0E0\n NN = NN - 1\n FNI = FNI - 1.0E0\n DFN = FNI + FNF\n FN = DFN\n if (NN-1) 440, 390, 130\n 390 KT = 2\n IS = 2\n go to 130\n 400 Y(NN) = 0.0E0\n NN = NN - 1\n FNP1 = FN\n FNI = FNI - 1.0E0\n DFN = FNI + FNF\n FN = DFN\n if (NN-1) 440, 410, 420\n 410 KT = 2\n IS = 2\n 420 if (SXO2 <= FNP1) go to 430\n go to 130\n 430 ARG = ARG - XO2L + LOG(FNP1)\n if (ARG < (-ELIM1)) go to 400\n go to 330\n 440 NZ = N - NN\n return\n!\n! BACKWARD RECURSION SECTION\n!\n 450 CONTINUE\n if ( NS /= 0) go to 451\n NZ = N - NN\n if (KT == 2) go to 470\n! BACKWARD RECUR FROM INDEX ALPHA+NN-1 TO ALPHA\n Y(NN) = TEMP(1)\n Y(NN-1) = TEMP(2)\n if (NN == 2) RETURN\n 451 CONTINUE\n TRX = 2.0E0/X\n DTM = FNI\n TM = (DTM+FNF)*TRX\n AK=1.0E0\n TA=TEMP(1)\n TB=TEMP(2)\n if ( ABS(TA) > SLIM) go to 455\n TA=TA*RTOL\n TB=TB*RTOL\n AK=TOL\n 455 CONTINUE\n KK=2\n IN=NS-1\n if ( IN == 0) go to 690\n if ( NS /= 0) go to 670\n K=NN-2\n DO 460 I=3,NN\n S=TB\n TB=TM*TB-TA\n TA=S\n Y(K)=TB*AK\n K=K-1\n DTM = DTM - 1.0E0\n TM = (DTM+FNF)*TRX\n 460 CONTINUE\n return\n 470 Y(1) = TEMP(2)\n return\n!\n! ASYMPTOTIC EXPANSION FOR X TO INFINITY WITH FORWARD RECURSION IN\n! OSCILLATORY REGION X > MAX(20, NU), PROVIDED THE LAST MEMBER\n! OF THE SEQUENCE IS ALSO IN THE REGION.\n!\n 480 CONTINUE\n IN = INT(ALPHA-TAU+2.0E0)\n if (IN <= 0) go to 490\n IDALP = IALP - IN - 1\n KT = 1\n go to 500\n 490 CONTINUE\n IDALP = IALP\n IN = 0\n 500 IS = KT\n FIDAL = IDALP\n DALPHA = FIDAL + FNF\n ARG = X - PIDT*DALPHA - PDF\n SA = SIN(ARG)\n SB = COS(ARG)\n COEF = RTTP/RTX\n ETX = 8.0E0*X\n 510 CONTINUE\n DTM = FIDAL + FIDAL\n DTM = DTM*DTM\n TM = 0.0E0\n if (FIDAL == 0.0E0 .AND. ABS(FNF) < TOL) go to 520\n TM = 4.0E0*FNF*(FIDAL+FIDAL+FNF)\n 520 CONTINUE\n TRX = DTM - 1.0E0\n T2 = (TRX+TM)/ETX\n S2 = T2\n RELB = TOL*ABS(T2)\n T1 = ETX\n S1 = 1.0E0\n FN = 1.0E0\n AK = 8.0E0\n DO 530 K=1,13\n T1 = T1 + ETX\n FN = FN + AK\n TRX = DTM - FN\n AP = TRX + TM\n T2 = -T2*AP/T1\n S1 = S1 + T2\n T1 = T1 + ETX\n AK = AK + 8.0E0\n FN = FN + AK\n TRX = DTM - FN\n AP = TRX + TM\n T2 = T2*AP/T1\n S2 = S2 + T2\n if (ABS(T2) <= RELB) go to 540\n AK = AK + 8.0E0\n 530 CONTINUE\n 540 TEMP(IS) = COEF*(S1*SB-S2*SA)\n if ( IS == 2) go to 560\n FIDAL = FIDAL + 1.0E0\n DALPHA = FIDAL + FNF\n IS = 2\n TB = SA\n SA = -SB\n SB = TB\n go to 510\n!\n! FORWARD RECURSION SECTION\n!\n 560 if (KT == 2) go to 470\n S1 = TEMP(1)\n S2 = TEMP(2)\n TX = 2.0E0/X\n TM = DALPHA*TX\n if (IN == 0) go to 580\n!\n! FORWARD RECUR TO INDEX ALPHA\n!\n DO 570 I=1,IN\n S = S2\n S2 = TM*S2 - S1\n TM = TM + TX\n S1 = S\n 570 CONTINUE\n if (NN == 1) go to 600\n S = S2\n S2 = TM*S2 - S1\n TM = TM + TX\n S1 = S\n 580 CONTINUE\n!\n! FORWARD RECUR FROM INDEX ALPHA TO ALPHA+N-1\n!\n Y(1) = S1\n Y(2) = S2\n if (NN == 2) RETURN\n DO 590 I=3,NN\n Y(I) = TM*Y(I-1) - Y(I-2)\n TM = TM + TX\n 590 CONTINUE\n return\n 600 Y(1) = S2\n return\n!\n! BACKWARD RECURSION WITH NORMALIZATION BY\n! ASYMPTOTIC EXPANSION FOR NU TO INFINITY OR POWER SERIES.\n!\n 610 CONTINUE\n! COMPUTATION OF LAST ORDER FOR SERIES NORMALIZATION\n AKM = MAX(3.0E0-FN,0.0E0)\n KM = INT(AKM)\n TFN = FN + KM\n TA = (GLN+TFN-0.9189385332E0-0.0833333333E0/TFN)/(TFN+0.5E0)\n TA = XO2L - TA\n TB = -(1.0E0-1.5E0/TFN)/TFN\n AKM = TOLLN/(-TA+SQRT(TA*TA-TOLLN*TB)) + 1.5E0\n IN = KM + INT(AKM)\n go to 660\n 620 CONTINUE\n! COMPUTATION OF LAST ORDER FOR ASYMPTOTIC EXPANSION NORMALIZATION\n GLN = WK(3) + WK(2)\n if (WK(6) > 30.0E0) go to 640\n RDEN = (PP(4)*WK(6)+PP(3))*WK(6) + 1.0E0\n RZDEN = PP(1) + PP(2)*WK(6)\n TA = RZDEN/RDEN\n if (WK(1) < 0.10E0) go to 630\n TB = GLN/WK(5)\n go to 650\n 630 TB=(1.259921049E0+(0.1679894730E0+0.0887944358E0*WK(1))*WK(1)) &\n /WK(7)\n go to 650\n 640 CONTINUE\n TA = 0.5E0*TOLLN/WK(4)\n TA=((0.0493827160E0*TA-0.1111111111E0)*TA+0.6666666667E0)*TA*WK(6)\n if (WK(1) < 0.10E0) go to 630\n TB = GLN/WK(5)\n 650 IN = INT(TA/TB+1.5E0)\n if (IN > INLIM) go to 310\n 660 CONTINUE\n DTM = FNI + IN\n TRX = 2.0E0/X\n TM = (DTM+FNF)*TRX\n TA = 0.0E0\n TB = TOL\n KK = 1\n AK=1.0E0\n 670 CONTINUE\n!\n! BACKWARD RECUR UNINDEXED AND SCALE WHEN MAGNITUDES ARE CLOSE TO\n! UNDERFLOW LIMITS (LESS THAN SLIM=R1MACH(1)*1.0E+3/TOL)\n!\n DO 680 I=1,IN\n S = TB\n TB = TM*TB - TA\n TA = S\n DTM = DTM - 1.0E0\n TM = (DTM+FNF)*TRX\n 680 CONTINUE\n! NORMALIZATION\n if (KK /= 1) go to 690\n S=TEMP(3)\n SA=TA/TB\n TA=S\n TB=S\n if ( ABS(S) > SLIM) go to 685\n TA=TA*RTOL\n TB=TB*RTOL\n AK=TOL\n 685 CONTINUE\n TA=TA*SA\n KK = 2\n IN = NS\n if (NS /= 0) go to 670\n 690 Y(NN) = TB*AK\n NZ = N - NN\n if (NN == 1) RETURN\n K = NN - 1\n S=TB\n TB = TM*TB - TA\n TA=S\n Y(K)=TB*AK\n if (NN == 2) RETURN\n DTM = DTM - 1.0E0\n TM = (DTM+FNF)*TRX\n K=NN-2\n!\n! BACKWARD RECUR INDEXED\n!\n DO 700 I=3,NN\n S=TB\n TB = TM*TB - TA\n TA=S\n Y(K)=TB*AK\n DTM = DTM - 1.0E0\n TM = (DTM+FNF)*TRX\n K = K - 1\n 700 CONTINUE\n return\n!\n!\n!\n 710 CONTINUE\n call XERMSG ('SLATEC', 'BESJ', 'ORDER, ALPHA, LESS THAN ZERO.', &\n 2, 1)\n return\n 720 CONTINUE\n call XERMSG ('SLATEC', 'BESJ', 'N LESS THAN ONE.', 2, 1)\n return\n 730 CONTINUE\n call XERMSG ('SLATEC', 'BESJ', 'X LESS THAN ZERO.', 2, 1)\n return\nend\nfunction BESJ0 (X)\n!\n!! BESJ0 computes the Bessel function of the first kind of order zero.\n!\n!***LIBRARY SLATEC (FNLIB)\n!***CATEGORY C10A1\n!***TYPE SINGLE PRECISION (BESJ0-S, DBESJ0-D)\n!***KEYWORDS BESSEL FUNCTION, FIRST KIND, FNLIB, ORDER ZERO,\n! SPECIAL FUNCTIONS\n!***AUTHOR Fullerton, W., (LANL)\n!***DESCRIPTION\n!\n! BESJ0(X) calculates the Bessel function of the first kind of\n! order zero for real argument X.\n!\n! Series for BJ0 on the interval 0. to 1.60000D+01\n! with weighted error 7.47E-18\n! log weighted error 17.13\n! significant figures required 16.98\n! decimal places required 17.68\n!\n! Series for BM0 on the interval 0. to 6.25000D-02\n! with weighted error 4.98E-17\n! log weighted error 16.30\n! significant figures required 14.97\n! decimal places required 16.96\n!\n! Series for BTH0 on the interval 0. to 6.25000D-02\n! with weighted error 3.67E-17\n! log weighted error 16.44\n! significant figures required 15.53\n! decimal places required 17.13\n!\n!***REFERENCES (NONE)\n!***ROUTINES CALLED CSEVL, INITS, R1MACH, XERMSG\n!***REVISION HISTORY (YYMMDD)\n! 770401 DATE WRITTEN\n! 890210 REVISION DATE from Version 3.2\n! 891214 Prologue converted to Version 4.0 format. (BAB)\n! 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\n! 900326 Removed duplicate information from DESCRIPTION section.\n! (WRB)\n!***END PROLOGUE BESJ0\n DIMENSION BJ0CS(13), BM0CS(21), BTH0CS(24)\n LOGICAL FIRST\n SAVE BJ0CS, BM0CS, BTH0CS, PI4, NTJ0, NTM0, NTTH0, XSML, XMAX, &\n FIRST\n DATA BJ0CS( 1) / .100254161968939137E0 /\n DATA BJ0CS( 2) / -.665223007764405132E0 /\n DATA BJ0CS( 3) / .248983703498281314E0 /\n DATA BJ0CS( 4) / -.0332527231700357697E0 /\n DATA BJ0CS( 5) / .0023114179304694015E0 /\n DATA BJ0CS( 6) / -.0000991127741995080E0 /\n DATA BJ0CS( 7) / .0000028916708643998E0 /\n DATA BJ0CS( 8) / -.0000000612108586630E0 /\n DATA BJ0CS( 9) / .0000000009838650793E0 /\n DATA BJ0CS(10) / -.0000000000124235515E0 /\n DATA BJ0CS(11) / .0000000000001265433E0 /\n DATA BJ0CS(12) / -.0000000000000010619E0 /\n DATA BJ0CS(13) / .0000000000000000074E0 /\n DATA BM0CS( 1) / .09284961637381644E0 /\n DATA BM0CS( 2) / -.00142987707403484E0 /\n DATA BM0CS( 3) / .00002830579271257E0 /\n DATA BM0CS( 4) / -.00000143300611424E0 /\n DATA BM0CS( 5) / .00000012028628046E0 /\n DATA BM0CS( 6) / -.00000001397113013E0 /\n DATA BM0CS( 7) / .00000000204076188E0 /\n DATA BM0CS( 8) / -.00000000035399669E0 /\n DATA BM0CS( 9) / .00000000007024759E0 /\n DATA BM0CS(10) / -.00000000001554107E0 /\n DATA BM0CS(11) / .00000000000376226E0 /\n DATA BM0CS(12) / -.00000000000098282E0 /\n DATA BM0CS(13) / .00000000000027408E0 /\n DATA BM0CS(14) / -.00000000000008091E0 /\n DATA BM0CS(15) / .00000000000002511E0 /\n DATA BM0CS(16) / -.00000000000000814E0 /\n DATA BM0CS(17) / .00000000000000275E0 /\n DATA BM0CS(18) / -.00000000000000096E0 /\n DATA BM0CS(19) / .00000000000000034E0 /\n DATA BM0CS(20) / -.00000000000000012E0 /\n DATA BM0CS(21) / .00000000000000004E0 /\n DATA BTH0CS( 1) / -.24639163774300119E0 /\n DATA BTH0CS( 2) / .001737098307508963E0 /\n DATA BTH0CS( 3) / -.000062183633402968E0 /\n DATA BTH0CS( 4) / .000004368050165742E0 /\n DATA BTH0CS( 5) / -.000000456093019869E0 /\n DATA BTH0CS( 6) / .000000062197400101E0 /\n DATA BTH0CS( 7) / -.000000010300442889E0 /\n DATA BTH0CS( 8) / .000000001979526776E0 /\n DATA BTH0CS( 9) / -.000000000428198396E0 /\n DATA BTH0CS(10) / .000000000102035840E0 /\n DATA BTH0CS(11) / -.000000000026363898E0 /\n DATA BTH0CS(12) / .000000000007297935E0 /\n DATA BTH0CS(13) / -.000000000002144188E0 /\n DATA BTH0CS(14) / .000000000000663693E0 /\n DATA BTH0CS(15) / -.000000000000215126E0 /\n DATA BTH0CS(16) / .000000000000072659E0 /\n DATA BTH0CS(17) / -.000000000000025465E0 /\n DATA BTH0CS(18) / .000000000000009229E0 /\n DATA BTH0CS(19) / -.000000000000003448E0 /\n DATA BTH0CS(20) / .000000000000001325E0 /\n DATA BTH0CS(21) / -.000000000000000522E0 /\n DATA BTH0CS(22) / .000000000000000210E0 /\n DATA BTH0CS(23) / -.000000000000000087E0 /\n DATA BTH0CS(24) / .000000000000000036E0 /\n DATA PI4 / 0.78539816339744831E0 /\n DATA FIRST /.TRUE./\n!***FIRST EXECUTABLE STATEMENT BESJ0\n if (FIRST) THEN\n NTJ0 = INITS (BJ0CS, 13, 0.1*R1MACH(3))\n NTM0 = INITS (BM0CS, 21, 0.1*R1MACH(3))\n NTTH0 = INITS (BTH0CS, 24, 0.1*R1MACH(3))\n!\n XSML = SQRT (8.0*R1MACH(3))\n XMAX = 1.0/R1MACH(4)\n end if\n FIRST = .FALSE.\n!\n Y = ABS(X)\n if (Y > 4.0) go to 20\n!\n BESJ0 = 1.0\n if (Y > XSML) BESJ0 = CSEVL (.125*Y*Y-1., BJ0CS, NTJ0)\n return\n!\n 20 if (Y > XMAX) call XERMSG ('SLATEC', 'BESJ0', &\n 'NO PRECISION BECAUSE ABS(X) IS TOO BIG', 1, 2)\n!\n Z = 32.0/Y**2 - 1.0\n AMPL = (0.75 + CSEVL (Z, BM0CS, NTM0)) / SQRT(Y)\n THETA = Y - PI4 + CSEVL (Z, BTH0CS, NTTH0) / Y\n BESJ0 = AMPL * COS (THETA)\n!\n return\nend\nfunction BESJ1 (X)\n!\n!! BESJ1 computes the Bessel function of the first kind of order one.\n!\n!***LIBRARY SLATEC (FNLIB)\n!***CATEGORY C10A1\n!***TYPE SINGLE PRECISION (BESJ1-S, DBESJ1-D)\n!***KEYWORDS BESSEL FUNCTION, FIRST KIND, FNLIB, ORDER ONE,\n! SPECIAL FUNCTIONS\n!***AUTHOR Fullerton, W., (LANL)\n!***DESCRIPTION\n!\n! BESJ1(X) calculates the Bessel function of the first kind of\n! order one for real argument X.\n!\n! Series for BJ1 on the interval 0. to 1.60000D+01\n! with weighted error 4.48E-17\n! log weighted error 16.35\n! significant figures required 15.77\n! decimal places required 16.89\n!\n! Series for BM1 on the interval 0. to 6.25000D-02\n! with weighted error 5.61E-17\n! log weighted error 16.25\n! significant figures required 14.97\n! decimal places required 16.91\n!\n! Series for BTH1 on the interval 0. to 6.25000D-02\n! with weighted error 4.10E-17\n! log weighted error 16.39\n! significant figures required 15.96\n! decimal places required 17.08\n!\n!***REFERENCES (NONE)\n!***ROUTINES CALLED CSEVL, INITS, R1MACH, XERMSG\n!***REVISION HISTORY (YYMMDD)\n! 780601 DATE WRITTEN\n! 890210 REVISION DATE from Version 3.2\n! 891214 Prologue converted to Version 4.0 format. (BAB)\n! 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\n! 900326 Removed duplicate information from DESCRIPTION section.\n! (WRB)\n!***END PROLOGUE BESJ1\n DIMENSION BJ1CS(12), BM1CS(21), BTH1CS(24)\n LOGICAL FIRST\n SAVE BJ1CS, BM1CS, BTH1CS, PI4, NTJ1, NTM1, NTTH1, &\n XSML, XMIN, XMAX, FIRST\n DATA BJ1CS( 1) / -.11726141513332787E0 /\n DATA BJ1CS( 2) / -.25361521830790640E0 /\n DATA BJ1CS( 3) / .050127080984469569E0 /\n DATA BJ1CS( 4) / -.004631514809625081E0 /\n DATA BJ1CS( 5) / .000247996229415914E0 /\n DATA BJ1CS( 6) / -.000008678948686278E0 /\n DATA BJ1CS( 7) / .000000214293917143E0 /\n DATA BJ1CS( 8) / -.000000003936093079E0 /\n DATA BJ1CS( 9) / .000000000055911823E0 /\n DATA BJ1CS(10) / -.000000000000632761E0 /\n DATA BJ1CS(11) / .000000000000005840E0 /\n DATA BJ1CS(12) / -.000000000000000044E0 /\n DATA BM1CS( 1) / .1047362510931285E0 /\n DATA BM1CS( 2) / .00442443893702345E0 /\n DATA BM1CS( 3) / -.00005661639504035E0 /\n DATA BM1CS( 4) / .00000231349417339E0 /\n DATA BM1CS( 5) / -.00000017377182007E0 /\n DATA BM1CS( 6) / .00000001893209930E0 /\n DATA BM1CS( 7) / -.00000000265416023E0 /\n DATA BM1CS( 8) / .00000000044740209E0 /\n DATA BM1CS( 9) / -.00000000008691795E0 /\n DATA BM1CS(10) / .00000000001891492E0 /\n DATA BM1CS(11) / -.00000000000451884E0 /\n DATA BM1CS(12) / .00000000000116765E0 /\n DATA BM1CS(13) / -.00000000000032265E0 /\n DATA BM1CS(14) / .00000000000009450E0 /\n DATA BM1CS(15) / -.00000000000002913E0 /\n DATA BM1CS(16) / .00000000000000939E0 /\n DATA BM1CS(17) / -.00000000000000315E0 /\n DATA BM1CS(18) / .00000000000000109E0 /\n DATA BM1CS(19) / -.00000000000000039E0 /\n DATA BM1CS(20) / .00000000000000014E0 /\n DATA BM1CS(21) / -.00000000000000005E0 /\n DATA BTH1CS( 1) / .74060141026313850E0 /\n DATA BTH1CS( 2) / -.004571755659637690E0 /\n DATA BTH1CS( 3) / .000119818510964326E0 /\n DATA BTH1CS( 4) / -.000006964561891648E0 /\n DATA BTH1CS( 5) / .000000655495621447E0 /\n DATA BTH1CS( 6) / -.000000084066228945E0 /\n DATA BTH1CS( 7) / .000000013376886564E0 /\n DATA BTH1CS( 8) / -.000000002499565654E0 /\n DATA BTH1CS( 9) / .000000000529495100E0 /\n DATA BTH1CS(10) / -.000000000124135944E0 /\n DATA BTH1CS(11) / .000000000031656485E0 /\n DATA BTH1CS(12) / -.000000000008668640E0 /\n DATA BTH1CS(13) / .000000000002523758E0 /\n DATA BTH1CS(14) / -.000000000000775085E0 /\n DATA BTH1CS(15) / .000000000000249527E0 /\n DATA BTH1CS(16) / -.000000000000083773E0 /\n DATA BTH1CS(17) / .000000000000029205E0 /\n DATA BTH1CS(18) / -.000000000000010534E0 /\n DATA BTH1CS(19) / .000000000000003919E0 /\n DATA BTH1CS(20) / -.000000000000001500E0 /\n DATA BTH1CS(21) / .000000000000000589E0 /\n DATA BTH1CS(22) / -.000000000000000237E0 /\n DATA BTH1CS(23) / .000000000000000097E0 /\n DATA BTH1CS(24) / -.000000000000000040E0 /\n DATA PI4 / 0.78539816339744831E0 /\n DATA FIRST /.TRUE./\n!***FIRST EXECUTABLE STATEMENT BESJ1\n if (FIRST) THEN\n NTJ1 = INITS (BJ1CS, 12, 0.1*R1MACH(3))\n NTM1 = INITS (BM1CS, 21, 0.1*R1MACH(3))\n NTTH1 = INITS (BTH1CS, 24, 0.1*R1MACH(3))\n!\n XSML = SQRT (8.0*R1MACH(3))\n XMIN = 2.0*R1MACH(1)\n XMAX = 1.0/R1MACH(4)\n end if\n FIRST = .FALSE.\n!\n Y = ABS(X)\n if (Y > 4.0) go to 20\n!\n BESJ1 = 0.\n if (Y == 0.0) RETURN\n if (Y <= XMIN) call XERMSG ('SLATEC', 'BESJ1', &\n 'ABS(X) SO SMALL J1 UNDERFLOWS', 1, 1)\n if (Y > XMIN) BESJ1 = 0.5*X\n if (Y > XSML) BESJ1 = X * (.25 + CSEVL(.125*Y*Y-1., BJ1CS, NTJ1))\n return\n!\n 20 if (Y > XMAX) call XERMSG ('SLATEC', 'BESJ1', &\n 'NO PRECISION BECAUSE ABS(X) IS TOO BIG', 2, 2)\n Z = 32.0/Y**2 - 1.0\n AMPL = (0.75 + CSEVL (Z, BM1CS, NTM1)) / SQRT(Y)\n THETA = Y - 3.0*PI4 + CSEVL (Z, BTH1CS, NTTH1) / Y\n BESJ1 = SIGN (AMPL, X) * COS (THETA)\n!\n return\nend\n\nsubroutine ASYJY (FUNJY, X, FNU, FLGJY, IN, Y, WK, IFLW)\n!\n!! ASYJY is subsidiary to BESJ and BESY.\n!\n!***LIBRARY SLATEC\n!***TYPE SINGLE PRECISION (ASYJY-S, DASYJY-D)\n!***AUTHOR Amos, D. E., (SNLA)\n!***DESCRIPTION\n!\n! ASYJY computes Bessel functions J and Y\n! for arguments X > 0.0 and orders FNU >= 35.0\n! on FLGJY = 1 and FLGJY = -1 respectively\n!\n! INPUT\n!\n! FUNJY - external function JAIRY or YAIRY\n! X - argument, X > 0.0E0\n! FNU - order of the first Bessel function\n! FLGJY - selection flag\n! FLGJY = 1.0E0 gives the J function\n! FLGJY = -1.0E0 gives the Y function\n! IN - number of functions desired, IN = 1 or 2\n!\n! OUTPUT\n!\n! Y - a vector whose first in components contain the sequence\n! IFLW - a flag indicating underflow or overflow\n! return variables for BESJ only\n! WK(1) = 1 - (X/FNU)**2 = W**2\n! WK(2) = SQRT(ABS(WK(1)))\n! WK(3) = ABS(WK(2) - ATAN(WK(2))) or\n! ABS(LN((1 + WK(2))/(X/FNU)) - WK(2))\n! = ABS((2/3)*ZETA**(3/2))\n! WK(4) = FNU*WK(3)\n! WK(5) = (1.5*WK(3)*FNU)**(1/3) = SQRT(ZETA)*FNU**(1/3)\n! WK(6) = SIGN(1.,W**2)*WK(5)**2 = SIGN(1.,W**2)*ZETA*FNU**(2/3)\n! WK(7) = FNU**(1/3)\n!\n! Abstract\n! ASYJY implements the uniform asymptotic expansion of\n! the J and Y Bessel functions for FNU >= 35 and real\n! X > 0.0E0. The forms are identical except for a change\n! in sign of some of the terms. This change in sign is\n! accomplished by means of the flag FLGJY = 1 or -1. On\n! FLGJY = 1 the AIRY functions AI(X) and DAI(X) are\n! supplied by the external function JAIRY, and on\n! FLGJY = -1 the AIRY functions BI(X) and DBI(X) are\n! supplied by the external function YAIRY.\n!\n!***SEE ALSO BESJ, BESY\n!***ROUTINES CALLED I1MACH, R1MACH\n!***REVISION HISTORY (YYMMDD)\n! 750101 DATE WRITTEN\n! 890531 Changed all specific intrinsics to generic. (WRB)\n! 891009 Removed unreferenced variable. (WRB)\n! 891214 Prologue converted to Version 4.0 format. (BAB)\n! 900328 Added TYPE section. (WRB)\n! 910408 Updated the AUTHOR section. (WRB)\n!***END PROLOGUE ASYJY\n INTEGER I, IFLW, IN, J, JN,JR,JU,K, KB,KLAST,KMAX,KP1, KS, KSP1, &\n KSTEMP, L, LR, LRP1, ISETA, ISETB\n INTEGER I1MACH\n REAL ABW2, AKM, ALFA, ALFA1, ALFA2, AP, AR, ASUM, AZ, &\n BETA, BETA1, BETA2, BETA3, BR, BSUM, C, CON1, CON2, &\n CON548,CR,CRZ32, DFI,ELIM, DR,FI, FLGJY, FN, FNU, &\n FN2, GAMA, PHI, RCZ, RDEN, RELB, RFN2, RTZ, RZDEN, &\n SA, SB, SUMA, SUMB, S1, TA, TAU, TB, TFN, TOL, TOLS, T2, UPOL, &\n WK, X, XX, Y, Z, Z32\n REAL R1MACH\n DIMENSION Y(*), WK(*), C(65)\n DIMENSION ALFA(26,4), BETA(26,5)\n DIMENSION ALFA1(26,2), ALFA2(26,2)\n DIMENSION BETA1(26,2), BETA2(26,2), BETA3(26,1)\n DIMENSION GAMA(26), KMAX(5), AR(8), BR(10), UPOL(10)\n DIMENSION CR(10), DR(10)\n EQUIVALENCE (ALFA(1,1),ALFA1(1,1))\n EQUIVALENCE (ALFA(1,3),ALFA2(1,1))\n EQUIVALENCE (BETA(1,1),BETA1(1,1))\n EQUIVALENCE (BETA(1,3),BETA2(1,1))\n EQUIVALENCE (BETA(1,5),BETA3(1,1))\n SAVE TOLS, CON1, CON2, CON548, AR, BR, C, ALFA1, ALFA2, &\n BETA1, BETA2, BETA3, GAMA\n DATA TOLS /-6.90775527898214E+00/\n DATA CON1,CON2,CON548/ &\n 6.66666666666667E-01, 3.33333333333333E-01, 1.04166666666667E-01/\n DATA AR(1), AR(2), AR(3), AR(4), AR(5), AR(6), AR(7), &\n AR(8) / 8.35503472222222E-02, 1.28226574556327E-01, &\n 2.91849026464140E-01, 8.81627267443758E-01, 3.32140828186277E+00, &\n 1.49957629868626E+01, 7.89230130115865E+01, 4.74451538868264E+02/\n DATA BR(1), BR(2), BR(3), BR(4), BR(5), BR(6), BR(7), BR(8), &\n BR(9), BR(10) /-1.45833333333333E-01,-9.87413194444444E-02, &\n -1.43312053915895E-01,-3.17227202678414E-01,-9.42429147957120E-01, &\n -3.51120304082635E+00,-1.57272636203680E+01,-8.22814390971859E+01, &\n -4.92355370523671E+02,-3.31621856854797E+03/\n DATA C(1), C(2), C(3), C(4), C(5), C(6), C(7), C(8), C(9), C(10), &\n C(11), C(12), C(13), C(14), C(15), C(16), C(17), C(18), &\n C(19), C(20), C(21), C(22), C(23), C(24)/ &\n -2.08333333333333E-01, 1.25000000000000E-01, &\n 3.34201388888889E-01, -4.01041666666667E-01, &\n 7.03125000000000E-02, -1.02581259645062E+00, &\n 1.84646267361111E+00, -8.91210937500000E-01, &\n 7.32421875000000E-02, 4.66958442342625E+00, &\n -1.12070026162230E+01, 8.78912353515625E+00, &\n -2.36408691406250E+00, 1.12152099609375E-01, &\n -2.82120725582002E+01, 8.46362176746007E+01, &\n -9.18182415432400E+01, 4.25349987453885E+01, &\n -7.36879435947963E+00, 2.27108001708984E-01, &\n 2.12570130039217E+02, -7.65252468141182E+02, &\n 1.05999045252800E+03, -6.99579627376133E+02/\n DATA C(25), C(26), C(27), C(28), C(29), C(30), C(31), C(32), &\n C(33), C(34), C(35), C(36), C(37), C(38), C(39), C(40), &\n C(41), C(42), C(43), C(44), C(45), C(46), C(47), C(48)/ &\n 2.18190511744212E+02, -2.64914304869516E+01, &\n 5.72501420974731E-01, -1.91945766231841E+03, &\n 8.06172218173731E+03, -1.35865500064341E+04, &\n 1.16553933368645E+04, -5.30564697861340E+03, &\n 1.20090291321635E+03, -1.08090919788395E+02, &\n 1.72772750258446E+00, 2.02042913309661E+04, &\n -9.69805983886375E+04, 1.92547001232532E+05, &\n -2.03400177280416E+05, 1.22200464983017E+05, &\n -4.11926549688976E+04, 7.10951430248936E+03, &\n -4.93915304773088E+02, 6.07404200127348E+00, &\n -2.42919187900551E+05, 1.31176361466298E+06, &\n -2.99801591853811E+06, 3.76327129765640E+06/\n DATA C(49), C(50), C(51), C(52), C(53), C(54), C(55), C(56), &\n C(57), C(58), C(59), C(60), C(61), C(62), C(63), C(64), &\n C(65)/ &\n -2.81356322658653E+06, 1.26836527332162E+06, &\n -3.31645172484564E+05, 4.52187689813627E+04, &\n -2.49983048181121E+03, 2.43805296995561E+01, &\n 3.28446985307204E+06, -1.97068191184322E+07, &\n 5.09526024926646E+07, -7.41051482115327E+07, &\n 6.63445122747290E+07, -3.75671766607634E+07, &\n 1.32887671664218E+07, -2.78561812808645E+06, &\n 3.08186404612662E+05, -1.38860897537170E+04, &\n 1.10017140269247E+02/\n DATA ALFA1(1,1), ALFA1(2,1), ALFA1(3,1), ALFA1(4,1), ALFA1(5,1), &\n ALFA1(6,1), ALFA1(7,1), ALFA1(8,1), ALFA1(9,1), ALFA1(10,1), &\n ALFA1(11,1),ALFA1(12,1),ALFA1(13,1),ALFA1(14,1),ALFA1(15,1), &\n ALFA1(16,1),ALFA1(17,1),ALFA1(18,1),ALFA1(19,1),ALFA1(20,1), &\n ALFA1(21,1),ALFA1(22,1),ALFA1(23,1),ALFA1(24,1),ALFA1(25,1), &\n ALFA1(26,1) /-4.44444444444444E-03,-9.22077922077922E-04, &\n -8.84892884892885E-05, 1.65927687832450E-04, 2.46691372741793E-04, &\n 2.65995589346255E-04, 2.61824297061501E-04, 2.48730437344656E-04, &\n 2.32721040083232E-04, 2.16362485712365E-04, 2.00738858762752E-04, &\n 1.86267636637545E-04, 1.73060775917876E-04, 1.61091705929016E-04, &\n 1.50274774160908E-04, 1.40503497391270E-04, 1.31668816545923E-04, &\n 1.23667445598253E-04, 1.16405271474738E-04, 1.09798298372713E-04, &\n 1.03772410422993E-04, 9.82626078369363E-05, 9.32120517249503E-05, &\n 8.85710852478712E-05, 8.42963105715700E-05, 8.03497548407791E-05/\n DATA ALFA1(1,2), ALFA1(2,2), ALFA1(3,2), ALFA1(4,2), ALFA1(5,2), &\n ALFA1(6,2), ALFA1(7,2), ALFA1(8,2), ALFA1(9,2), ALFA1(10,2), &\n ALFA1(11,2),ALFA1(12,2),ALFA1(13,2),ALFA1(14,2),ALFA1(15,2), &\n ALFA1(16,2),ALFA1(17,2),ALFA1(18,2),ALFA1(19,2),ALFA1(20,2), &\n ALFA1(21,2),ALFA1(22,2),ALFA1(23,2),ALFA1(24,2),ALFA1(25,2), &\n ALFA1(26,2) / 6.93735541354589E-04, 2.32241745182922E-04, &\n -1.41986273556691E-05,-1.16444931672049E-04,-1.50803558053049E-04, &\n -1.55121924918096E-04,-1.46809756646466E-04,-1.33815503867491E-04, &\n -1.19744975684254E-04,-1.06184319207974E-04,-9.37699549891194E-05, &\n -8.26923045588193E-05,-7.29374348155221E-05,-6.44042357721016E-05, &\n -5.69611566009369E-05,-5.04731044303562E-05,-4.48134868008883E-05, &\n -3.98688727717599E-05,-3.55400532972042E-05,-3.17414256609022E-05, &\n -2.83996793904175E-05,-2.54522720634871E-05,-2.28459297164725E-05, &\n -2.05352753106481E-05,-1.84816217627666E-05,-1.66519330021394E-05/\n DATA ALFA2(1,1), ALFA2(2,1), ALFA2(3,1), ALFA2(4,1), ALFA2(5,1), &\n ALFA2(6,1), ALFA2(7,1), ALFA2(8,1), ALFA2(9,1), ALFA2(10,1), &\n ALFA2(11,1),ALFA2(12,1),ALFA2(13,1),ALFA2(14,1),ALFA2(15,1), &\n ALFA2(16,1),ALFA2(17,1),ALFA2(18,1),ALFA2(19,1),ALFA2(20,1), &\n ALFA2(21,1),ALFA2(22,1),ALFA2(23,1),ALFA2(24,1),ALFA2(25,1), &\n ALFA2(26,1) /-3.54211971457744E-04,-1.56161263945159E-04, &\n 3.04465503594936E-05, 1.30198655773243E-04, 1.67471106699712E-04, &\n 1.70222587683593E-04, 1.56501427608595E-04, 1.36339170977445E-04, &\n 1.14886692029825E-04, 9.45869093034688E-05, 7.64498419250898E-05, &\n 6.07570334965197E-05, 4.74394299290509E-05, 3.62757512005344E-05, &\n 2.69939714979225E-05, 1.93210938247939E-05, 1.30056674793963E-05, &\n 7.82620866744497E-06, 3.59257485819352E-06, 1.44040049814252E-07, &\n -2.65396769697939E-06,-4.91346867098486E-06,-6.72739296091248E-06, &\n -8.17269379678658E-06,-9.31304715093561E-06,-1.02011418798016E-05/\n DATA ALFA2(1,2), ALFA2(2,2), ALFA2(3,2), ALFA2(4,2), ALFA2(5,2), &\n ALFA2(6,2), ALFA2(7,2), ALFA2(8,2), ALFA2(9,2), ALFA2(10,2), &\n ALFA2(11,2),ALFA2(12,2),ALFA2(13,2),ALFA2(14,2),ALFA2(15,2), &\n ALFA2(16,2),ALFA2(17,2),ALFA2(18,2),ALFA2(19,2),ALFA2(20,2), &\n ALFA2(21,2),ALFA2(22,2),ALFA2(23,2),ALFA2(24,2),ALFA2(25,2), &\n ALFA2(26,2) / 3.78194199201773E-04, 2.02471952761816E-04, &\n -6.37938506318862E-05,-2.38598230603006E-04,-3.10916256027362E-04, &\n -3.13680115247576E-04,-2.78950273791323E-04,-2.28564082619141E-04, &\n -1.75245280340847E-04,-1.25544063060690E-04,-8.22982872820208E-05, &\n -4.62860730588116E-05,-1.72334302366962E-05, 5.60690482304602E-06, &\n 2.31395443148287E-05, 3.62642745856794E-05, 4.58006124490189E-05, &\n 5.24595294959114E-05, 5.68396208545815E-05, 5.94349820393104E-05, &\n 6.06478527578422E-05, 6.08023907788436E-05, 6.01577894539460E-05, &\n 5.89199657344698E-05, 5.72515823777593E-05, 5.52804375585853E-05/\n DATA BETA1(1,1), BETA1(2,1), BETA1(3,1), BETA1(4,1), BETA1(5,1), &\n BETA1(6,1), BETA1(7,1), BETA1(8,1), BETA1(9,1), BETA1(10,1), &\n BETA1(11,1),BETA1(12,1),BETA1(13,1),BETA1(14,1),BETA1(15,1), &\n BETA1(16,1),BETA1(17,1),BETA1(18,1),BETA1(19,1),BETA1(20,1), &\n BETA1(21,1),BETA1(22,1),BETA1(23,1),BETA1(24,1),BETA1(25,1), &\n BETA1(26,1) / 1.79988721413553E-02, 5.59964911064388E-03, &\n 2.88501402231133E-03, 1.80096606761054E-03, 1.24753110589199E-03, &\n 9.22878876572938E-04, 7.14430421727287E-04, 5.71787281789705E-04, &\n 4.69431007606482E-04, 3.93232835462917E-04, 3.34818889318298E-04, &\n 2.88952148495752E-04, 2.52211615549573E-04, 2.22280580798883E-04, &\n 1.97541838033063E-04, 1.76836855019718E-04, 1.59316899661821E-04, &\n 1.44347930197334E-04, 1.31448068119965E-04, 1.20245444949303E-04, &\n 1.10449144504599E-04, 1.01828770740567E-04, 9.41998224204238E-05, &\n 8.74130545753834E-05, 8.13466262162801E-05, 7.59002269646219E-05/\n DATA BETA1(1,2), BETA1(2,2), BETA1(3,2), BETA1(4,2), BETA1(5,2), &\n BETA1(6,2), BETA1(7,2), BETA1(8,2), BETA1(9,2), BETA1(10,2), &\n BETA1(11,2),BETA1(12,2),BETA1(13,2),BETA1(14,2),BETA1(15,2), &\n BETA1(16,2),BETA1(17,2),BETA1(18,2),BETA1(19,2),BETA1(20,2), &\n BETA1(21,2),BETA1(22,2),BETA1(23,2),BETA1(24,2),BETA1(25,2), &\n BETA1(26,2) /-1.49282953213429E-03,-8.78204709546389E-04, &\n -5.02916549572035E-04,-2.94822138512746E-04,-1.75463996970783E-04, &\n -1.04008550460816E-04,-5.96141953046458E-05,-3.12038929076098E-05, &\n -1.26089735980230E-05,-2.42892608575730E-07, 8.05996165414274E-06, &\n 1.36507009262147E-05, 1.73964125472926E-05, 1.98672978842134E-05, &\n 2.14463263790823E-05, 2.23954659232457E-05, 2.28967783814713E-05, &\n 2.30785389811178E-05, 2.30321976080909E-05, 2.28236073720349E-05, &\n 2.25005881105292E-05, 2.20981015361991E-05, 2.16418427448104E-05, &\n 2.11507649256221E-05, 2.06388749782171E-05, 2.01165241997082E-05/\n DATA BETA2(1,1), BETA2(2,1), BETA2(3,1), BETA2(4,1), BETA2(5,1), &\n BETA2(6,1), BETA2(7,1), BETA2(8,1), BETA2(9,1), BETA2(10,1), &\n BETA2(11,1),BETA2(12,1),BETA2(13,1),BETA2(14,1),BETA2(15,1), &\n BETA2(16,1),BETA2(17,1),BETA2(18,1),BETA2(19,1),BETA2(20,1), &\n BETA2(21,1),BETA2(22,1),BETA2(23,1),BETA2(24,1),BETA2(25,1), &\n BETA2(26,1) / 5.52213076721293E-04, 4.47932581552385E-04, &\n 2.79520653992021E-04, 1.52468156198447E-04, 6.93271105657044E-05, &\n 1.76258683069991E-05,-1.35744996343269E-05,-3.17972413350427E-05, &\n -4.18861861696693E-05,-4.69004889379141E-05,-4.87665447413787E-05, &\n -4.87010031186735E-05,-4.74755620890087E-05,-4.55813058138628E-05, &\n -4.33309644511266E-05,-4.09230193157750E-05,-3.84822638603221E-05, &\n -3.60857167535411E-05,-3.37793306123367E-05,-3.15888560772110E-05, &\n -2.95269561750807E-05,-2.75978914828336E-05,-2.58006174666884E-05, &\n -2.41308356761280E-05,-2.25823509518346E-05,-2.11479656768913E-05/\n DATA BETA2(1,2), BETA2(2,2), BETA2(3,2), BETA2(4,2), BETA2(5,2), &\n BETA2(6,2), BETA2(7,2), BETA2(8,2), BETA2(9,2), BETA2(10,2), &\n BETA2(11,2),BETA2(12,2),BETA2(13,2),BETA2(14,2),BETA2(15,2), &\n BETA2(16,2),BETA2(17,2),BETA2(18,2),BETA2(19,2),BETA2(20,2), &\n BETA2(21,2),BETA2(22,2),BETA2(23,2),BETA2(24,2),BETA2(25,2), &\n BETA2(26,2) /-4.74617796559960E-04,-4.77864567147321E-04, &\n -3.20390228067038E-04,-1.61105016119962E-04,-4.25778101285435E-05, &\n 3.44571294294968E-05, 7.97092684075675E-05, 1.03138236708272E-04, &\n 1.12466775262204E-04, 1.13103642108481E-04, 1.08651634848774E-04, &\n 1.01437951597662E-04, 9.29298396593364E-05, 8.40293133016090E-05, &\n 7.52727991349134E-05, 6.69632521975731E-05, 5.92564547323195E-05, &\n 5.22169308826976E-05, 4.58539485165361E-05, 4.01445513891487E-05, &\n 3.50481730031328E-05, 3.05157995034347E-05, 2.64956119950516E-05, &\n 2.29363633690998E-05, 1.97893056664022E-05, 1.70091984636413E-05/\n DATA BETA3(1,1), BETA3(2,1), BETA3(3,1), BETA3(4,1), BETA3(5,1), &\n BETA3(6,1), BETA3(7,1), BETA3(8,1), BETA3(9,1), BETA3(10,1), &\n BETA3(11,1),BETA3(12,1),BETA3(13,1),BETA3(14,1),BETA3(15,1), &\n BETA3(16,1),BETA3(17,1),BETA3(18,1),BETA3(19,1),BETA3(20,1), &\n BETA3(21,1),BETA3(22,1),BETA3(23,1),BETA3(24,1),BETA3(25,1), &\n BETA3(26,1) / 7.36465810572578E-04, 8.72790805146194E-04, &\n 6.22614862573135E-04, 2.85998154194304E-04, 3.84737672879366E-06, &\n -1.87906003636972E-04,-2.97603646594555E-04,-3.45998126832656E-04, &\n -3.53382470916038E-04,-3.35715635775049E-04,-3.04321124789040E-04, &\n -2.66722723047613E-04,-2.27654214122820E-04,-1.89922611854562E-04, &\n -1.55058918599094E-04,-1.23778240761874E-04,-9.62926147717644E-05, &\n -7.25178327714425E-05,-5.22070028895634E-05,-3.50347750511901E-05, &\n -2.06489761035552E-05,-8.70106096849767E-06, 1.13698686675100E-06, &\n 9.16426474122779E-06, 1.56477785428873E-05, 2.08223629482467E-05/\n DATA GAMA(1), GAMA(2), GAMA(3), GAMA(4), GAMA(5), &\n GAMA(6), GAMA(7), GAMA(8), GAMA(9), GAMA(10), &\n GAMA(11), GAMA(12), GAMA(13), GAMA(14), GAMA(15), &\n GAMA(16), GAMA(17), GAMA(18), GAMA(19), GAMA(20), &\n GAMA(21), GAMA(22), GAMA(23), GAMA(24), GAMA(25), &\n GAMA(26) / 6.29960524947437E-01, 2.51984209978975E-01, &\n 1.54790300415656E-01, 1.10713062416159E-01, 8.57309395527395E-02, &\n 6.97161316958684E-02, 5.86085671893714E-02, 5.04698873536311E-02, &\n 4.42600580689155E-02, 3.93720661543510E-02, 3.54283195924455E-02, &\n 3.21818857502098E-02, 2.94646240791158E-02, 2.71581677112934E-02, &\n 2.51768272973862E-02, 2.34570755306079E-02, 2.19508390134907E-02, &\n 2.06210828235646E-02, 1.94388240897881E-02, 1.83810633800683E-02, &\n 1.74293213231963E-02, 1.65685837786612E-02, 1.57865285987918E-02, &\n 1.50729501494096E-02, 1.44193250839955E-02, 1.38184805735342E-02/\n!***FIRST EXECUTABLE STATEMENT ASYJY\n TA = R1MACH(3)\n TOL = MAX(TA,1.0E-15)\n TB = R1MACH(5)\n JU = I1MACH(12)\n if ( FLGJY == 1.0E0) go to 6\n JR = I1MACH(11)\n ELIM = -2.303E0*TB*(JU+JR)\n go to 7\n 6 CONTINUE\n ELIM = -2.303E0*(TB*JU+3.0E0)\n 7 CONTINUE\n FN = FNU\n IFLW = 0\n DO 170 JN=1,IN\n XX = X/FN\n WK(1) = 1.0E0 - XX*XX\n ABW2 = ABS(WK(1))\n WK(2) = SQRT(ABW2)\n WK(7) = FN**CON2\n if (ABW2 > 0.27750E0) go to 80\n!\n! ASYMPTOTIC EXPANSION\n! CASES NEAR X=FN, ABS(1.-(X/FN)**2) <= 0.2775\n! COEFFICIENTS OF ASYMPTOTIC EXPANSION BY SERIES\n!\n! ZETA AND TRUNCATION FOR A(ZETA) AND B(ZETA) SERIES\n!\n! KMAX IS TRUNCATION INDEX FOR A(ZETA) AND B(ZETA) SERIES=MAX(2,SA)\n!\n SA = 0.0E0\n if (ABW2 == 0.0E0) go to 10\n SA = TOLS/LOG(ABW2)\n 10 SB = SA\n DO 20 I=1,5\n AKM = MAX(SA,2.0E0)\n KMAX(I) = INT(AKM)\n SA = SA + SB\n 20 CONTINUE\n KB = KMAX(5)\n KLAST = KB - 1\n SA = GAMA(KB)\n DO 30 K=1,KLAST\n KB = KB - 1\n SA = SA*WK(1) + GAMA(KB)\n 30 CONTINUE\n Z = WK(1)*SA\n AZ = ABS(Z)\n RTZ = SQRT(AZ)\n WK(3) = CON1*AZ*RTZ\n WK(4) = WK(3)*FN\n WK(5) = RTZ*WK(7)\n WK(6) = -WK(5)*WK(5)\n if ( Z <= 0.0E0) go to 35\n if ( WK(4) > ELIM) go to 75\n WK(6) = -WK(6)\n 35 CONTINUE\n PHI = SQRT(SQRT(SA+SA+SA+SA))\n!\n! B(ZETA) FOR S=0\n!\n KB = KMAX(5)\n KLAST = KB - 1\n SB = BETA(KB,1)\n DO 40 K=1,KLAST\n KB = KB - 1\n SB = SB*WK(1) + BETA(KB,1)\n 40 CONTINUE\n KSP1 = 1\n FN2 = FN*FN\n RFN2 = 1.0E0/FN2\n RDEN = 1.0E0\n ASUM = 1.0E0\n RELB = TOL*ABS(SB)\n BSUM = SB\n DO 60 KS=1,4\n KSP1 = KSP1 + 1\n RDEN = RDEN*RFN2\n!\n! A(ZETA) AND B(ZETA) FOR S=1,2,3,4\n!\n KSTEMP = 5 - KS\n KB = KMAX(KSTEMP)\n KLAST = KB - 1\n SA = ALFA(KB,KS)\n SB = BETA(KB,KSP1)\n DO 50 K=1,KLAST\n KB = KB - 1\n SA = SA*WK(1) + ALFA(KB,KS)\n SB = SB*WK(1) + BETA(KB,KSP1)\n 50 CONTINUE\n TA = SA*RDEN\n TB = SB*RDEN\n ASUM = ASUM + TA\n BSUM = BSUM + TB\n if (ABS(TA) <= TOL .AND. ABS(TB) <= RELB) go to 70\n 60 CONTINUE\n 70 CONTINUE\n BSUM = BSUM/(FN*WK(7))\n go to 160\n!\n 75 CONTINUE\n IFLW = 1\n return\n!\n 80 CONTINUE\n UPOL(1) = 1.0E0\n TAU = 1.0E0/WK(2)\n T2 = 1.0E0/WK(1)\n if (WK(1) >= 0.0E0) go to 90\n!\n! CASES FOR (X/FN) > SQRT(1.2775)\n!\n WK(3) = ABS(WK(2)-ATAN(WK(2)))\n WK(4) = WK(3)*FN\n RCZ = -CON1/WK(4)\n Z32 = 1.5E0*WK(3)\n RTZ = Z32**CON2\n WK(5) = RTZ*WK(7)\n WK(6) = -WK(5)*WK(5)\n go to 100\n 90 CONTINUE\n!\n! CASES FOR (X/FN) < SQRT(0.7225)\n!\n WK(3) = ABS(LOG((1.0E0+WK(2))/XX)-WK(2))\n WK(4) = WK(3)*FN\n RCZ = CON1/WK(4)\n if ( WK(4) > ELIM) go to 75\n Z32 = 1.5E0*WK(3)\n RTZ = Z32**CON2\n WK(7) = FN**CON2\n WK(5) = RTZ*WK(7)\n WK(6) = WK(5)*WK(5)\n 100 CONTINUE\n PHI = SQRT((RTZ+RTZ)*TAU)\n TB = 1.0E0\n ASUM = 1.0E0\n TFN = TAU/FN\n RDEN=1.0E0/FN\n RFN2=RDEN*RDEN\n RDEN=1.0E0\n UPOL(2) = (C(1)*T2+C(2))*TFN\n CRZ32 = CON548*RCZ\n BSUM = UPOL(2) + CRZ32\n RELB = TOL*ABS(BSUM)\n AP = TFN\n KS = 0\n KP1 = 2\n RZDEN = RCZ\n L = 2\n ISETA=0\n ISETB=0\n DO 140 LR=2,8,2\n!\n! COMPUTE TWO U POLYNOMIALS FOR NEXT A(ZETA) AND B(ZETA)\n!\n LRP1 = LR + 1\n DO 120 K=LR,LRP1\n KS = KS + 1\n KP1 = KP1 + 1\n L = L + 1\n S1 = C(L)\n DO 110 J=2,KP1\n L = L + 1\n S1 = S1*T2 + C(L)\n 110 CONTINUE\n AP = AP*TFN\n UPOL(KP1) = AP*S1\n CR(KS) = BR(KS)*RZDEN\n RZDEN = RZDEN*RCZ\n DR(KS) = AR(KS)*RZDEN\n 120 CONTINUE\n SUMA = UPOL(LRP1)\n SUMB = UPOL(LR+2) + UPOL(LRP1)*CRZ32\n JU = LRP1\n DO 130 JR=1,LR\n JU = JU - 1\n SUMA = SUMA + CR(JR)*UPOL(JU)\n SUMB = SUMB + DR(JR)*UPOL(JU)\n 130 CONTINUE\n RDEN=RDEN*RFN2\n TB = -TB\n if (WK(1) > 0.0E0) TB = ABS(TB)\n if (RDEN < TOL) go to 131\n ASUM = ASUM + SUMA*TB\n BSUM = BSUM + SUMB*TB\n go to 140\n 131 if ( ISETA == 1) go to 132\n if ( ABS(SUMA) < TOL) ISETA=1\n ASUM=ASUM+SUMA*TB\n 132 if ( ISETB == 1) go to 133\n if ( ABS(SUMB) < RELB) ISETB=1\n BSUM=BSUM+SUMB*TB\n 133 if ( ISETA == 1 .AND. ISETB == 1) go to 150\n 140 CONTINUE\n 150 TB = WK(5)\n if (WK(1) > 0.0E0) TB = -TB\n BSUM = BSUM/TB\n!\n 160 CONTINUE\n call FUNJY(WK(6), WK(5), WK(4), FI, DFI)\n TA=1.0E0/TOL\n TB=R1MACH(1)*TA*1.0E+3\n if ( ABS(FI) > TB) go to 165\n FI=FI*TA\n DFI=DFI*TA\n PHI=PHI*TOL\n 165 CONTINUE\n Y(JN) = FLGJY*PHI*(FI*ASUM+DFI*BSUM)/WK(7)\n FN = FN - FLGJY\n 170 CONTINUE\n return\nend\n\nfunction INITS (OS, NOS, ETA)\n!\n!! INITS determines the number of terms needed in an orthogonal ...\n! polynomial series so that it meets a specified accuracy.\n!\n!***LIBRARY SLATEC (FNLIB)\n!***CATEGORY C3A2\n!***TYPE SINGLE PRECISION (INITS-S, INITDS-D)\n!***KEYWORDS CHEBYSHEV, FNLIB, INITIALIZE, ORTHOGONAL POLYNOMIAL,\n! ORTHOGONAL SERIES, SPECIAL FUNCTIONS\n!***AUTHOR Fullerton, W., (LANL)\n!***DESCRIPTION\n!\n! Initialize the orthogonal series, represented by the array OS, so\n! that INITS is the number of terms needed to insure the error is no\n! larger than ETA. Ordinarily, ETA will be chosen to be one-tenth\n! machine precision.\n!\n! Input Arguments --\n! OS single precision array of NOS coefficients in an orthogonal\n! series.\n! NOS number of coefficients in OS.\n! ETA single precision scalar containing requested accuracy of\n! series.\n!\n!***REFERENCES (NONE)\n!***ROUTINES CALLED XERMSG\n!***REVISION HISTORY (YYMMDD)\n! 770401 DATE WRITTEN\n! 890831 Modified array declarations. (WRB)\n! 891115 Modified error message. (WRB)\n! 891115 REVISION DATE from Version 3.2\n! 891214 Prologue converted to Version 4.0 format. (BAB)\n! 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\n!***END PROLOGUE INITS\n REAL OS(*)\n!***FIRST EXECUTABLE STATEMENT INITS\n if (NOS < 1) call XERMSG ('SLATEC', 'INITS', &\n 'Number of coefficients is less than 1', 2, 1)\n!\n ERR = 0.\n DO 10 II = 1,NOS\n I = NOS + 1 - II\n ERR = ERR + ABS(OS(I))\n if (ERR > ETA) go to 20\n 10 CONTINUE\n!\n 20 if (I == NOS) call XERMSG ('SLATEC', 'INITS', &\n 'Chebyshev series too short for specified accuracy', 1, 1)\n INITS = I\n!\n return\nend\n\nsubroutine JAIRY (X, RX, C, AI, DAI)\n!\n!! JAIRY is subsidiary to BESJ and BESY.\n!\n!***LIBRARY SLATEC\n!***TYPE SINGLE PRECISION (JAIRY-S, DJAIRY-D)\n!***AUTHOR Amos, D. E., (SNLA)\n! Daniel, S. L., (SNLA)\n! Weston, M. K., (SNLA)\n!***DESCRIPTION\n!\n! JAIRY computes the Airy function AI(X)\n! and its derivative DAI(X) for ASYJY\n!\n! INPUT\n!\n! X - Argument, computed by ASYJY, X unrestricted\n! RX - RX=SQRT(ABS(X)), computed by ASYJY\n! C - C=2.*(ABS(X)**1.5)/3., computed by ASYJY\n!\n! OUTPUT\n!\n! AI - Value of function AI(X)\n! DAI - Value of the derivative DAI(X)\n!\n!***SEE ALSO BESJ, BESY\n!***ROUTINES CALLED (NONE)\n!***REVISION HISTORY (YYMMDD)\n! 750101 DATE WRITTEN\n! 891009 Removed unreferenced variable. (WRB)\n! 891214 Prologue converted to Version 4.0 format. (BAB)\n! 900328 Added TYPE section. (WRB)\n! 910408 Updated the AUTHOR section. (WRB)\n!***END PROLOGUE JAIRY\n!\n INTEGER I, J, M1, M1D, M2, M2D, M3, M3D, M4, M4D, N1, N1D, N2, &\n N2D, N3, N3D, N4, N4D\n REAL A, AI, AJN, AJP, AK1, AK2, AK3, B, C, CCV, CON2, CON3, &\n CON4, CON5, CV, DA, DAI, DAJN, DAJP, DAK1, DAK2, DAK3, DB, EC, &\n E1, E2, FPI12, F1, F2, RTRX, RX, SCV, T, TEMP1, TEMP2, TT, X\n DIMENSION AJP(19), AJN(19), A(15), B(15)\n DIMENSION AK1(14), AK2(23), AK3(14)\n DIMENSION DAJP(19), DAJN(19), DA(15), DB(15)\n DIMENSION DAK1(14), DAK2(24), DAK3(14)\n SAVE N1, N2, N3, N4, M1, M2, M3, M4, FPI12, CON2, &\n CON3, CON4, CON5,AK1, AK2, AK3, AJP, AJN, A, B, &\n N1D, N2D, N3D, N4D, M1D, M2D, M3D, M4D, &\n DAK1, DAK2, DAK3, DAJP, DAJN, DA, DB\n DATA N1,N2,N3,N4/14,23,19,15/\n DATA M1,M2,M3,M4/12,21,17,13/\n DATA FPI12,CON2,CON3,CON4,CON5/ &\n 1.30899693899575E+00, 5.03154716196777E+00, 3.80004589867293E-01, &\n 8.33333333333333E-01, 8.66025403784439E-01/\n DATA AK1(1), AK1(2), AK1(3), AK1(4), AK1(5), AK1(6), AK1(7), &\n AK1(8), AK1(9), AK1(10),AK1(11),AK1(12),AK1(13), &\n AK1(14) / 2.20423090987793E-01,-1.25290242787700E-01, &\n 1.03881163359194E-02, 8.22844152006343E-04,-2.34614345891226E-04, &\n 1.63824280172116E-05, 3.06902589573189E-07,-1.29621999359332E-07, &\n 8.22908158823668E-09, 1.53963968623298E-11,-3.39165465615682E-11, &\n 2.03253257423626E-12,-1.10679546097884E-14,-5.16169497785080E-15/\n DATA AK2(1), AK2(2), AK2(3), AK2(4), AK2(5), AK2(6), AK2(7), &\n AK2(8), AK2(9), AK2(10),AK2(11),AK2(12),AK2(13),AK2(14), &\n AK2(15),AK2(16),AK2(17),AK2(18),AK2(19),AK2(20),AK2(21), &\n AK2(22),AK2(23) / 2.74366150869598E-01, 5.39790969736903E-03, &\n -1.57339220621190E-03, 4.27427528248750E-04,-1.12124917399925E-04, &\n 2.88763171318904E-05,-7.36804225370554E-06, 1.87290209741024E-06, &\n -4.75892793962291E-07, 1.21130416955909E-07,-3.09245374270614E-08, &\n 7.92454705282654E-09,-2.03902447167914E-09, 5.26863056595742E-10, &\n -1.36704767639569E-10, 3.56141039013708E-11,-9.31388296548430E-12, &\n 2.44464450473635E-12,-6.43840261990955E-13, 1.70106030559349E-13, &\n -4.50760104503281E-14, 1.19774799164811E-14,-3.19077040865066E-15/\n DATA AK3(1), AK3(2), AK3(3), AK3(4), AK3(5), AK3(6), AK3(7), &\n AK3(8), AK3(9), AK3(10),AK3(11),AK3(12),AK3(13), &\n AK3(14) / 2.80271447340791E-01,-1.78127042844379E-03, &\n 4.03422579628999E-05,-1.63249965269003E-06, 9.21181482476768E-08, &\n -6.52294330229155E-09, 5.47138404576546E-10,-5.24408251800260E-11, &\n 5.60477904117209E-12,-6.56375244639313E-13, 8.31285761966247E-14, &\n -1.12705134691063E-14, 1.62267976598129E-15,-2.46480324312426E-16/\n DATA AJP(1), AJP(2), AJP(3), AJP(4), AJP(5), AJP(6), AJP(7), &\n AJP(8), AJP(9), AJP(10),AJP(11),AJP(12),AJP(13),AJP(14), &\n AJP(15),AJP(16),AJP(17),AJP(18), &\n AJP(19) / 7.78952966437581E-02,-1.84356363456801E-01, &\n 3.01412605216174E-02, 3.05342724277608E-02,-4.95424702513079E-03, &\n -1.72749552563952E-03, 2.43137637839190E-04, 5.04564777517082E-05, &\n -6.16316582695208E-06,-9.03986745510768E-07, 9.70243778355884E-08, &\n 1.09639453305205E-08,-1.04716330588766E-09,-9.60359441344646E-11, &\n 8.25358789454134E-12, 6.36123439018768E-13,-4.96629614116015E-14, &\n -3.29810288929615E-15, 2.35798252031104E-16/\n DATA AJN(1), AJN(2), AJN(3), AJN(4), AJN(5), AJN(6), AJN(7), &\n AJN(8), AJN(9), AJN(10),AJN(11),AJN(12),AJN(13),AJN(14), &\n AJN(15),AJN(16),AJN(17),AJN(18), &\n AJN(19) / 3.80497887617242E-02,-2.45319541845546E-01, &\n 1.65820623702696E-01, 7.49330045818789E-02,-2.63476288106641E-02, &\n -5.92535597304981E-03, 1.44744409589804E-03, 2.18311831322215E-04, &\n -4.10662077680304E-05,-4.66874994171766E-06, 7.15218807277160E-07, &\n 6.52964770854633E-08,-8.44284027565946E-09,-6.44186158976978E-10, &\n 7.20802286505285E-11, 4.72465431717846E-12,-4.66022632547045E-13, &\n -2.67762710389189E-14, 2.36161316570019E-15/\n DATA A(1), A(2), A(3), A(4), A(5), A(6), A(7), &\n A(8), A(9), A(10), A(11), A(12), A(13), A(14), &\n A(15) / 4.90275424742791E-01, 1.57647277946204E-03, &\n -9.66195963140306E-05, 1.35916080268815E-07, 2.98157342654859E-07, &\n -1.86824767559979E-08,-1.03685737667141E-09, 3.28660818434328E-10, &\n -2.57091410632780E-11,-2.32357655300677E-12, 9.57523279048255E-13, &\n -1.20340828049719E-13,-2.90907716770715E-15, 4.55656454580149E-15, &\n -9.99003874810259E-16/\n DATA B(1), B(2), B(3), B(4), B(5), B(6), B(7), &\n B(8), B(9), B(10), B(11), B(12), B(13), B(14), &\n B(15) / 2.78593552803079E-01,-3.52915691882584E-03, &\n -2.31149677384994E-05, 4.71317842263560E-06,-1.12415907931333E-07, &\n -2.00100301184339E-08, 2.60948075302193E-09,-3.55098136101216E-11, &\n -3.50849978423875E-11, 5.83007187954202E-12,-2.04644828753326E-13, &\n -1.10529179476742E-13, 2.87724778038775E-14,-2.88205111009939E-15, &\n -3.32656311696166E-16/\n DATA N1D,N2D,N3D,N4D/14,24,19,15/\n DATA M1D,M2D,M3D,M4D/12,22,17,13/\n DATA DAK1(1), DAK1(2), DAK1(3), DAK1(4), DAK1(5), DAK1(6), &\n DAK1(7), DAK1(8), DAK1(9), DAK1(10),DAK1(11),DAK1(12), &\n DAK1(13),DAK1(14)/ 2.04567842307887E-01,-6.61322739905664E-02, &\n -8.49845800989287E-03, 3.12183491556289E-03,-2.70016489829432E-04, &\n -6.35636298679387E-06, 3.02397712409509E-06,-2.18311195330088E-07, &\n -5.36194289332826E-10, 1.13098035622310E-09,-7.43023834629073E-11, &\n 4.28804170826891E-13, 2.23810925754539E-13,-1.39140135641182E-14/\n DATA DAK2(1), DAK2(2), DAK2(3), DAK2(4), DAK2(5), DAK2(6), &\n DAK2(7), DAK2(8), DAK2(9), DAK2(10),DAK2(11),DAK2(12), &\n DAK2(13),DAK2(14),DAK2(15),DAK2(16),DAK2(17),DAK2(18), &\n DAK2(19),DAK2(20),DAK2(21),DAK2(22),DAK2(23), &\n DAK2(24) / 2.93332343883230E-01,-8.06196784743112E-03, &\n 2.42540172333140E-03,-6.82297548850235E-04, 1.85786427751181E-04, &\n -4.97457447684059E-05, 1.32090681239497E-05,-3.49528240444943E-06, &\n 9.24362451078835E-07,-2.44732671521867E-07, 6.49307837648910E-08, &\n -1.72717621501538E-08, 4.60725763604656E-09,-1.23249055291550E-09, &\n 3.30620409488102E-10,-8.89252099772401E-11, 2.39773319878298E-11, &\n -6.48013921153450E-12, 1.75510132023731E-12,-4.76303829833637E-13, &\n 1.29498241100810E-13,-3.52679622210430E-14, 9.62005151585923E-15, &\n -2.62786914342292E-15/\n DATA DAK3(1), DAK3(2), DAK3(3), DAK3(4), DAK3(5), DAK3(6), &\n DAK3(7), DAK3(8), DAK3(9), DAK3(10),DAK3(11),DAK3(12), &\n DAK3(13),DAK3(14)/ 2.84675828811349E-01, 2.53073072619080E-03, &\n -4.83481130337976E-05, 1.84907283946343E-06,-1.01418491178576E-07, &\n 7.05925634457153E-09,-5.85325291400382E-10, 5.56357688831339E-11, &\n -5.90889094779500E-12, 6.88574353784436E-13,-8.68588256452194E-14, &\n 1.17374762617213E-14,-1.68523146510923E-15, 2.55374773097056E-16/\n DATA DAJP(1), DAJP(2), DAJP(3), DAJP(4), DAJP(5), DAJP(6), &\n DAJP(7), DAJP(8), DAJP(9), DAJP(10),DAJP(11),DAJP(12), &\n DAJP(13),DAJP(14),DAJP(15),DAJP(16),DAJP(17),DAJP(18), &\n DAJP(19) / 6.53219131311457E-02,-1.20262933688823E-01, &\n 9.78010236263823E-03, 1.67948429230505E-02,-1.97146140182132E-03, &\n -8.45560295098867E-04, 9.42889620701976E-05, 2.25827860945475E-05, &\n -2.29067870915987E-06,-3.76343991136919E-07, 3.45663933559565E-08, &\n 4.29611332003007E-09,-3.58673691214989E-10,-3.57245881361895E-11, &\n 2.72696091066336E-12, 2.26120653095771E-13,-1.58763205238303E-14, &\n -1.12604374485125E-15, 7.31327529515367E-17/\n DATA DAJN(1), DAJN(2), DAJN(3), DAJN(4), DAJN(5), DAJN(6), &\n DAJN(7), DAJN(8), DAJN(9), DAJN(10),DAJN(11),DAJN(12), &\n DAJN(13),DAJN(14),DAJN(15),DAJN(16),DAJN(17),DAJN(18), &\n DAJN(19) / 1.08594539632967E-02, 8.53313194857091E-02, &\n -3.15277068113058E-01,-8.78420725294257E-02, 5.53251906976048E-02, &\n 9.41674060503241E-03,-3.32187026018996E-03,-4.11157343156826E-04, &\n 1.01297326891346E-04, 9.87633682208396E-06,-1.87312969812393E-06, &\n -1.50798500131468E-07, 2.32687669525394E-08, 1.59599917419225E-09, &\n -2.07665922668385E-10,-1.24103350500302E-11, 1.39631765331043E-12, &\n 7.39400971155740E-14,-7.32887475627500E-15/\n DATA DA(1), DA(2), DA(3), DA(4), DA(5), DA(6), DA(7), &\n DA(8), DA(9), DA(10), DA(11), DA(12), DA(13), DA(14), &\n DA(15) / 4.91627321104601E-01, 3.11164930427489E-03, &\n 8.23140762854081E-05,-4.61769776172142E-06,-6.13158880534626E-08, &\n 2.87295804656520E-08,-1.81959715372117E-09,-1.44752826642035E-10, &\n 4.53724043420422E-11,-3.99655065847223E-12,-3.24089119830323E-13, &\n 1.62098952568741E-13,-2.40765247974057E-14, 1.69384811284491E-16, &\n 8.17900786477396E-16/\n DATA DB(1), DB(2), DB(3), DB(4), DB(5), DB(6), DB(7), &\n DB(8), DB(9), DB(10), DB(11), DB(12), DB(13), DB(14), &\n DB(15) /-2.77571356944231E-01, 4.44212833419920E-03, &\n -8.42328522190089E-05,-2.58040318418710E-06, 3.42389720217621E-07, &\n -6.24286894709776E-09,-2.36377836844577E-09, 3.16991042656673E-10, &\n -4.40995691658191E-12,-5.18674221093575E-12, 9.64874015137022E-13, &\n -4.90190576608710E-14,-1.77253430678112E-14, 5.55950610442662E-15, &\n -7.11793337579530E-16/\n!***FIRST EXECUTABLE STATEMENT JAIRY\n if (X < 0.0E0) go to 90\n if (C > 5.0E0) go to 60\n if (X > 1.20E0) go to 30\n T = (X+X-1.2E0)*CON4\n TT = T + T\n J = N1\n F1 = AK1(J)\n F2 = 0.0E0\n DO 10 I=1,M1\n J = J - 1\n TEMP1 = F1\n F1 = TT*F1 - F2 + AK1(J)\n F2 = TEMP1\n 10 CONTINUE\n AI = T*F1 - F2 + AK1(1)\n!\n J = N1D\n F1 = DAK1(J)\n F2 = 0.0E0\n DO 20 I=1,M1D\n J = J - 1\n TEMP1 = F1\n F1 = TT*F1 - F2 + DAK1(J)\n F2 = TEMP1\n 20 CONTINUE\n DAI = -(T*F1-F2+DAK1(1))\n return\n!\n 30 CONTINUE\n T = (X+X-CON2)*CON3\n TT = T + T\n J = N2\n F1 = AK2(J)\n F2 = 0.0E0\n DO 40 I=1,M2\n J = J - 1\n TEMP1 = F1\n F1 = TT*F1 - F2 + AK2(J)\n F2 = TEMP1\n 40 CONTINUE\n RTRX = SQRT(RX)\n EC = EXP(-C)\n AI = EC*(T*F1-F2+AK2(1))/RTRX\n J = N2D\n F1 = DAK2(J)\n F2 = 0.0E0\n DO 50 I=1,M2D\n J = J - 1\n TEMP1 = F1\n F1 = TT*F1 - F2 + DAK2(J)\n F2 = TEMP1\n 50 CONTINUE\n DAI = -EC*(T*F1-F2+DAK2(1))*RTRX\n return\n!\n 60 CONTINUE\n T = 10.0E0/C - 1.0E0\n TT = T + T\n J = N1\n F1 = AK3(J)\n F2 = 0.0E0\n DO 70 I=1,M1\n J = J - 1\n TEMP1 = F1\n F1 = TT*F1 - F2 + AK3(J)\n F2 = TEMP1\n 70 CONTINUE\n RTRX = SQRT(RX)\n EC = EXP(-C)\n AI = EC*(T*F1-F2+AK3(1))/RTRX\n J = N1D\n F1 = DAK3(J)\n F2 = 0.0E0\n DO 80 I=1,M1D\n J = J - 1\n TEMP1 = F1\n F1 = TT*F1 - F2 + DAK3(J)\n F2 = TEMP1\n 80 CONTINUE\n DAI = -RTRX*EC*(T*F1-F2+DAK3(1))\n return\n!\n 90 CONTINUE\n if (C > 5.0E0) go to 120\n T = 0.4E0*C - 1.0E0\n TT = T + T\n J = N3\n F1 = AJP(J)\n E1 = AJN(J)\n F2 = 0.0E0\n E2 = 0.0E0\n DO 100 I=1,M3\n J = J - 1\n TEMP1 = F1\n TEMP2 = E1\n F1 = TT*F1 - F2 + AJP(J)\n E1 = TT*E1 - E2 + AJN(J)\n F2 = TEMP1\n E2 = TEMP2\n 100 CONTINUE\n AI = (T*E1-E2+AJN(1)) - X*(T*F1-F2+AJP(1))\n J = N3D\n F1 = DAJP(J)\n E1 = DAJN(J)\n F2 = 0.0E0\n E2 = 0.0E0\n DO 110 I=1,M3D\n J = J - 1\n TEMP1 = F1\n TEMP2 = E1\n F1 = TT*F1 - F2 + DAJP(J)\n E1 = TT*E1 - E2 + DAJN(J)\n F2 = TEMP1\n E2 = TEMP2\n 110 CONTINUE\n DAI = X*X*(T*F1-F2+DAJP(1)) + (T*E1-E2+DAJN(1))\n return\n!\n 120 CONTINUE\n T = 10.0E0/C - 1.0E0\n TT = T + T\n J = N4\n F1 = A(J)\n E1 = B(J)\n F2 = 0.0E0\n E2 = 0.0E0\n DO 130 I=1,M4\n J = J - 1\n TEMP1 = F1\n TEMP2 = E1\n F1 = TT*F1 - F2 + A(J)\n E1 = TT*E1 - E2 + B(J)\n F2 = TEMP1\n E2 = TEMP2\n 130 CONTINUE\n TEMP1 = T*F1 - F2 + A(1)\n TEMP2 = T*E1 - E2 + B(1)\n RTRX = SQRT(RX)\n CV = C - FPI12\n CCV = COS(CV)\n SCV = SIN(CV)\n AI = (TEMP1*CCV-TEMP2*SCV)/RTRX\n J = N4D\n F1 = DA(J)\n E1 = DB(J)\n F2 = 0.0E0\n E2 = 0.0E0\n DO 140 I=1,M4D\n J = J - 1\n TEMP1 = F1\n TEMP2 = E1\n F1 = TT*F1 - F2 + DA(J)\n E1 = TT*E1 - E2 + DB(J)\n F2 = TEMP1\n E2 = TEMP2\n 140 CONTINUE\n TEMP1 = T*F1 - F2 + DA(1)\n TEMP2 = T*E1 - E2 + DB(1)\n E1 = CCV*CON5 + 0.5E0*SCV\n E2 = SCV*CON5 - 0.5E0*CCV\n DAI = (TEMP1*E1-TEMP2*E2)*RTRX\n return\nend\nsubroutine GAMLIM (XMIN, XMAX)\n!\n!! GAMLIM computes minimum and maximum argument bounds for the Gamma function.\n!\n!***LIBRARY SLATEC (FNLIB)\n!***CATEGORY C7A, R2\n!***TYPE SINGLE PRECISION (GAMLIM-S, DGAMLM-D)\n!***KEYWORDS COMPLETE GAMMA FUNCTION, FNLIB, LIMITS, SPECIAL FUNCTIONS\n!***AUTHOR Fullerton, W., (LANL)\n!***DESCRIPTION\n!\n! Calculate the minimum and maximum legal bounds for X in GAMMA(X).\n! XMIN and XMAX are not the only bounds, but they are the only non-\n! trivial ones to calculate.\n!\n! Output Arguments --\n! XMIN minimum legal value of X in GAMMA(X). Any smaller value of\n! X might result in underflow.\n! XMAX maximum legal value of X in GAMMA(X). Any larger value will\n! cause overflow.\n!\n!***REFERENCES (NONE)\n!***ROUTINES CALLED R1MACH, XERMSG\n!***REVISION HISTORY (YYMMDD)\n! 770401 DATE WRITTEN\n! 890531 Changed all specific intrinsics to generic. (WRB)\n! 890531 REVISION DATE from Version 3.2\n! 891214 Prologue converted to Version 4.0 format. (BAB)\n! 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\n!***END PROLOGUE GAMLIM\n!***FIRST EXECUTABLE STATEMENT GAMLIM\n ALNSML = LOG(R1MACH(1))\n XMIN = -ALNSML\n DO 10 I=1,10\n XOLD = XMIN\n XLN = LOG(XMIN)\n XMIN = XMIN - XMIN*((XMIN+0.5)*XLN - XMIN - 0.2258 + ALNSML) &\n / (XMIN*XLN + 0.5)\n if (ABS(XMIN-XOLD) < 0.005) go to 20\n 10 CONTINUE\n call XERMSG ('SLATEC', 'GAMLIM', 'UNABLE TO FIND XMIN', 1, 2)\n!\n 20 XMIN = -XMIN + 0.01\n!\n ALNBIG = LOG(R1MACH(2))\n XMAX = ALNBIG\n DO 30 I=1,10\n XOLD = XMAX\n XLN = LOG(XMAX)\n XMAX = XMAX - XMAX*((XMAX-0.5)*XLN - XMAX + 0.9189 - ALNBIG) &\n / (XMAX*XLN - 0.5)\n if (ABS(XMAX-XOLD) < 0.005) go to 40\n 30 CONTINUE\n call XERMSG ('SLATEC', 'GAMLIM', 'UNABLE TO FIND XMAX', 2, 2)\n!\n 40 XMAX = XMAX - 0.01\n XMIN = MAX (XMIN, -XMAX+1.)\n!\n return\nend\n\nfunction CSEVL (X, CS, N)\n!\n!! CSEVL evaluates a Chebyshev series.\n!\n!***LIBRARY SLATEC (FNLIB)\n!***CATEGORY C3A2\n!***TYPE SINGLE PRECISION (CSEVL-S, DCSEVL-D)\n!***KEYWORDS CHEBYSHEV SERIES, FNLIB, SPECIAL FUNCTIONS\n!***AUTHOR Fullerton, W., (LANL)\n!***DESCRIPTION\n!\n! Evaluate the N-term Chebyshev series CS at X. Adapted from\n! a method presented in the paper by Broucke referenced below.\n!\n! Input Arguments --\n! X value at which the series is to be evaluated.\n! CS array of N terms of a Chebyshev series. In evaluating\n! CS, only half the first coefficient is summed.\n! N number of terms in array CS.\n!\n!***REFERENCES R. Broucke, Ten subroutines for the manipulation of\n! Chebyshev series, Algorithm 446, Communications of\n! the A.C.M. 16, (1973) pp. 254-256.\n! L. Fox and I. B. Parker, Chebyshev Polynomials in\n! Numerical Analysis, Oxford University Press, 1968,\n! page 56.\n!***ROUTINES CALLED R1MACH, XERMSG\n!***REVISION HISTORY (YYMMDD)\n! 770401 DATE WRITTEN\n! 890831 Modified array declarations. (WRB)\n! 890831 REVISION DATE from Version 3.2\n! 891214 Prologue converted to Version 4.0 format. (BAB)\n! 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\n! 900329 Prologued revised extensively and code rewritten to allow\n! X to be slightly outside interval (-1,+1). (WRB)\n! 920501 Reformatted the REFERENCES section. (WRB)\n!***END PROLOGUE CSEVL\n REAL B0, B1, B2, CS(*), ONEPL, TWOX, X\n LOGICAL FIRST\n SAVE FIRST, ONEPL\n DATA FIRST /.TRUE./\n!***FIRST EXECUTABLE STATEMENT CSEVL\n if (FIRST) ONEPL = 1.0E0 + R1MACH(4)\n FIRST = .FALSE.\n if (N < 1) call XERMSG ('SLATEC', 'CSEVL', &\n 'NUMBER OF TERMS <= 0', 2, 2)\n if (N > 1000) call XERMSG ('SLATEC', 'CSEVL', &\n 'NUMBER OF TERMS > 1000', 3, 2)\n if (ABS(X) > ONEPL) call XERMSG ('SLATEC', 'CSEVL', &\n 'X OUTSIDE THE INTERVAL (-1,+1)', 1, 1)\n!\n B1 = 0.0E0\n B0 = 0.0E0\n TWOX = 2.0*X\n DO 10 I = 1,N\n B2 = B1\n B1 = B0\n NI = N + 1 - I\n B0 = TWOX*B1 - B2 + CS(NI)\n 10 CONTINUE\n!\n CSEVL = 0.5E0*(B0-B2)\n!\n return\nend\n\nfunction ALNGAM (X)\n!\n!! ALNGAM computes the logarithm of the absolute value of the Gamma function.\n!\n!***LIBRARY SLATEC (FNLIB)\n!***CATEGORY C7A\n!***TYPE SINGLE PRECISION (ALNGAM-S, DLNGAM-D, CLNGAM-C)\n!***KEYWORDS ABSOLUTE VALUE, COMPLETE GAMMA FUNCTION, FNLIB, LOGARITHM,\n! SPECIAL FUNCTIONS\n!***AUTHOR Fullerton, W., (LANL)\n!***DESCRIPTION\n!\n! ALNGAM(X) computes the logarithm of the absolute value of the\n! gamma function at X.\n!\n!***REFERENCES (NONE)\n!***ROUTINES CALLED GAMMA, R1MACH, R9LGMC, XERMSG\n!***REVISION HISTORY (YYMMDD)\n! 770601 DATE WRITTEN\n! 890531 Changed all specific intrinsics to generic. (WRB)\n! 890531 REVISION DATE from Version 3.2\n! 891214 Prologue converted to Version 4.0 format. (BAB)\n! 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\n! 900326 Removed duplicate information from DESCRIPTION section.\n! (WRB)\n! 900727 Added EXTERNAL statement. (WRB)\n!***END PROLOGUE ALNGAM\n LOGICAL FIRST\n EXTERNAL GAMMA\n SAVE SQ2PIL, SQPI2L, PI, XMAX, DXREL, FIRST\n DATA SQ2PIL / 0.91893853320467274E0/\n DATA SQPI2L / 0.22579135264472743E0/\n DATA PI / 3.14159265358979324E0/\n DATA FIRST /.TRUE./\n!***FIRST EXECUTABLE STATEMENT ALNGAM\n if (FIRST) THEN\n XMAX = R1MACH(2)/LOG(R1MACH(2))\n DXREL = SQRT (R1MACH(4))\n end if\n FIRST = .FALSE.\n!\n Y = ABS(X)\n if (Y > 10.0) go to 20\n!\n! LOG (ABS (GAMMA(X))) FOR ABS(X) <= 10.0\n!\n ALNGAM = LOG (ABS (GAMMA(X)))\n return\n!\n! LOG (ABS (GAMMA(X))) FOR ABS(X) > 10.0\n!\n 20 if (Y > XMAX) call XERMSG ('SLATEC', 'ALNGAM', &\n 'ABS(X) SO BIG ALNGAM OVERFLOWS', 2, 2)\n!\n if (X > 0.) ALNGAM = SQ2PIL + (X-0.5)*LOG(X) - X + R9LGMC(Y)\n if (X > 0.) RETURN\n!\n SINPIY = ABS (SIN(PI*Y))\n if (SINPIY == 0.) call XERMSG ('SLATEC', 'ALNGAM', &\n 'X IS A NEGATIVE INTEGER', 3, 2)\n!\n if (ABS((X-AINT(X-0.5))/X) < DXREL) call XERMSG ('SLATEC', &\n 'ALNGAM', 'ANSWER LT HALF PRECISION BECAUSE X TOO NEAR ' // &\n 'NEGATIVE INTEGER', 1, 1)\n!\n ALNGAM = SQPI2L + (X-0.5)*LOG(Y) - X - LOG(SINPIY) - R9LGMC(Y)\n return\n!\nend\n\nfunction GAMMA (X)\n!\n!! GAMMA computes the complete Gamma function.\n!\n!***LIBRARY SLATEC (FNLIB)\n!***CATEGORY C7A\n!***TYPE SINGLE PRECISION (GAMMA-S, DGAMMA-D, CGAMMA-C)\n!***KEYWORDS COMPLETE GAMMA FUNCTION, FNLIB, SPECIAL FUNCTIONS\n!***AUTHOR Fullerton, W., (LANL)\n!***DESCRIPTION\n!\n! GAMMA computes the gamma function at X, where X is not 0, -1, -2, ....\n! GAMMA and X are single precision.\n!\n!***REFERENCES (NONE)\n!***ROUTINES CALLED CSEVL, GAMLIM, INITS, R1MACH, R9LGMC, XERMSG\n!***REVISION HISTORY (YYMMDD)\n! 770601 DATE WRITTEN\n! 890531 Changed all specific intrinsics to generic. (WRB)\n! 890531 REVISION DATE from Version 3.2\n! 891214 Prologue converted to Version 4.0 format. (BAB)\n! 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\n!***END PROLOGUE GAMMA\n DIMENSION GCS(23)\n LOGICAL FIRST\n SAVE GCS, PI, SQ2PIL, NGCS, XMIN, XMAX, DXREL, FIRST\n DATA GCS ( 1) / .008571195590989331E0/\n DATA GCS ( 2) / .004415381324841007E0/\n DATA GCS ( 3) / .05685043681599363E0/\n DATA GCS ( 4) /-.004219835396418561E0/\n DATA GCS ( 5) / .001326808181212460E0/\n DATA GCS ( 6) /-.0001893024529798880E0/\n DATA GCS ( 7) / .0000360692532744124E0/\n DATA GCS ( 8) /-.0000060567619044608E0/\n DATA GCS ( 9) / .0000010558295463022E0/\n DATA GCS (10) /-.0000001811967365542E0/\n DATA GCS (11) / .0000000311772496471E0/\n DATA GCS (12) /-.0000000053542196390E0/\n DATA GCS (13) / .0000000009193275519E0/\n DATA GCS (14) /-.0000000001577941280E0/\n DATA GCS (15) / .0000000000270798062E0/\n DATA GCS (16) /-.0000000000046468186E0/\n DATA GCS (17) / .0000000000007973350E0/\n DATA GCS (18) /-.0000000000001368078E0/\n DATA GCS (19) / .0000000000000234731E0/\n DATA GCS (20) /-.0000000000000040274E0/\n DATA GCS (21) / .0000000000000006910E0/\n DATA GCS (22) /-.0000000000000001185E0/\n DATA GCS (23) / .0000000000000000203E0/\n DATA PI /3.14159265358979324E0/\n! SQ2PIL IS LOG (SQRT (2.*PI) )\n DATA SQ2PIL /0.91893853320467274E0/\n DATA FIRST /.TRUE./\n!\n! LANL DEPENDENT CODE REMOVED 81.02.04\n!\n!***FIRST EXECUTABLE STATEMENT GAMMA\n if (FIRST) THEN\n!\n! ---------------------------------------------------------------------\n! INITIALIZE. FIND LEGAL BOUNDS FOR X, AND DETERMINE THE NUMBER OF\n! TERMS IN THE SERIES REQUIRED TO ATTAIN AN ACCURACY TEN TIMES BETTER\n! THAN MACHINE PRECISION.\n!\n NGCS = INITS (GCS, 23, 0.1*R1MACH(3))\n!\n call GAMLIM (XMIN, XMAX)\n DXREL = SQRT (R1MACH(4))\n!\n! ---------------------------------------------------------------------\n! FINISH INITIALIZATION. START EVALUATING GAMMA(X).\n!\n end if\n FIRST = .FALSE.\n!\n Y = ABS(X)\n if (Y > 10.0) go to 50\n!\n! COMPUTE GAMMA(X) FOR ABS(X) <= 10.0. REDUCE INTERVAL AND\n! FIND GAMMA(1+Y) FOR 0. <= Y < 1. FIRST OF ALL.\n!\n N = X\n if (X < 0.) N = N - 1\n Y = X - N\n N = N - 1\n GAMMA = 0.9375 + CSEVL(2.*Y-1., GCS, NGCS)\n if (N == 0) RETURN\n!\n if (N > 0) go to 30\n!\n! COMPUTE GAMMA(X) FOR X < 1.\n!\n N = -N\n if (X == 0.) call XERMSG ('SLATEC', 'GAMMA', 'X IS 0', 4, 2)\n if (X < 0. .AND. X+N-2 == 0.) call XERMSG ('SLATEC', 'GAMMA' &\n , 'X IS A NEGATIVE INTEGER', 4, 2)\n if (X < (-0.5) .AND. ABS((X-AINT(X-0.5))/X) < DXREL) call &\n XERMSG ( 'SLATEC', 'GAMMA', &\n 'ANSWER LT HALF PRECISION BECAUSE X TOO NEAR NEGATIVE INTEGER' &\n , 1, 1)\n!\n DO 20 I=1,N\n GAMMA = GAMMA / (X+I-1)\n 20 CONTINUE\n return\n!\n! GAMMA(X) FOR X >= 2.\n!\n 30 DO 40 I=1,N\n GAMMA = (Y+I)*GAMMA\n 40 CONTINUE\n return\n!\n! COMPUTE GAMMA(X) FOR ABS(X) > 10.0. RECALL Y = ABS(X).\n!\n 50 if (X > XMAX) call XERMSG ('SLATEC', 'GAMMA', &\n 'X SO BIG GAMMA OVERFLOWS', 3, 2)\n!\n GAMMA = 0.\n if (X < XMIN) call XERMSG ('SLATEC', 'GAMMA', &\n 'X SO SMALL GAMMA UNDERFLOWS', 2, 1)\n if (X < XMIN) RETURN\n!\n GAMMA = EXP((Y-0.5)*LOG(Y) - Y + SQ2PIL + R9LGMC(Y) )\n if (X > 0.) RETURN\n!\n if (ABS((X-AINT(X-0.5))/X) < DXREL) call XERMSG ('SLATEC', &\n 'GAMMA', &\n 'ANSWER LT HALF PRECISION, X TOO NEAR NEGATIVE INTEGER', 1, 1)\n!\n SINPIY = SIN (PI*Y)\n if (SINPIY == 0.) call XERMSG ('SLATEC', 'GAMMA', &\n 'X IS A NEGATIVE INTEGER', 4, 2)\n!\n GAMMA = -PI / (Y*SINPIY*GAMMA)\n!\n return\nend\n\nfunction R9LGMC (X)\n!\n!! R9LGMC computes the log Gamma correction factor so that ...\n! LOG(GAMMA(X)) = LOG(SQRT(2*PI)) + (X-.5)*LOG(X) - X + R9LGMC(X).\n!\n!***LIBRARY SLATEC (FNLIB)\n!***CATEGORY C7E\n!***TYPE SINGLE PRECISION (R9LGMC-S, D9LGMC-D, C9LGMC-C)\n!***KEYWORDS COMPLETE GAMMA FUNCTION, CORRECTION TERM, FNLIB,\n! LOG GAMMA, LOGARITHM, SPECIAL FUNCTIONS\n!***AUTHOR Fullerton, W., (LANL)\n!***DESCRIPTION\n!\n! Compute the log gamma correction factor for X >= 10.0 so that\n! LOG (GAMMA(X)) = LOG(SQRT(2*PI)) + (X-.5)*LOG(X) - X + R9LGMC(X)\n!\n! Series for ALGM on the interval 0. to 1.00000D-02\n! with weighted error 3.40E-16\n! log weighted error 15.47\n! significant figures required 14.39\n! decimal places required 15.86\n!\n!***REFERENCES (NONE)\n!***ROUTINES CALLED CSEVL, INITS, R1MACH, XERMSG\n!***REVISION HISTORY (YYMMDD)\n! 770801 DATE WRITTEN\n! 890531 Changed all specific intrinsics to generic. (WRB)\n! 890531 REVISION DATE from Version 3.2\n! 891214 Prologue converted to Version 4.0 format. (BAB)\n! 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\n! 900720 Routine changed from user-callable to subsidiary. (WRB)\n!***END PROLOGUE R9LGMC\n DIMENSION ALGMCS(6)\n LOGICAL FIRST\n SAVE ALGMCS, NALGM, XBIG, XMAX, FIRST\n DATA ALGMCS( 1) / .166638948045186E0 /\n DATA ALGMCS( 2) / -.0000138494817606E0 /\n DATA ALGMCS( 3) / .0000000098108256E0 /\n DATA ALGMCS( 4) / -.0000000000180912E0 /\n DATA ALGMCS( 5) / .0000000000000622E0 /\n DATA ALGMCS( 6) / -.0000000000000003E0 /\n DATA FIRST /.TRUE./\n!***FIRST EXECUTABLE STATEMENT R9LGMC\n if (FIRST) THEN\n NALGM = INITS (ALGMCS, 6, R1MACH(3))\n XBIG = 1.0/SQRT(R1MACH(3))\n XMAX = EXP (MIN(LOG(R1MACH(2)/12.0), -LOG(12.0*R1MACH(1))) )\n end if\n FIRST = .FALSE.\n!\n if (X < 10.0) call XERMSG ('SLATEC', 'R9LGMC', &\n 'X MUST BE GE 10', 1, 2)\n if (X >= XMAX) go to 20\n!\n R9LGMC = 1.0/(12.0*X)\n if (X < XBIG) R9LGMC = CSEVL (2.0*(10./X)**2-1., ALGMCS, NALGM)/X\n return\n!\n 20 R9LGMC = 0.0\n call XERMSG ('SLATEC', 'R9LGMC', 'X SO BIG R9LGMC UNDERFLOWS', 2, &\n 1)\n return\n!\nend\n", "meta": {"hexsha": "482d19ccc3fb8dc99939818368b7ad8c7641cc67", "size": 262670, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "w3j/slatec_3j.f90", "max_stars_repo_name": "veragluscevic/w3jslatec", "max_stars_repo_head_hexsha": "f3847e9af8522e0e637b696aa1d0971d96795daf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-12-18T04:10:04.000Z", "max_stars_repo_stars_event_max_datetime": "2018-12-18T04:10:04.000Z", "max_issues_repo_path": "w3j/slatec_3j.f90", "max_issues_repo_name": "veragluscevic/w3jslatec", "max_issues_repo_head_hexsha": "f3847e9af8522e0e637b696aa1d0971d96795daf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "w3j/slatec_3j.f90", "max_forks_repo_name": "veragluscevic/w3jslatec", "max_forks_repo_head_hexsha": "f3847e9af8522e0e637b696aa1d0971d96795daf", "max_forks_repo_licenses": ["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.8593856655, "max_line_length": 121, "alphanum_fraction": 0.586477329, "num_tokens": 111439, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778824, "lm_q2_score": 0.7931059487389968, "lm_q1q2_score": 0.6985654021761846}} {"text": "PROGRAM test_smplx\r\n! Test the F90 version of the NSWC routine SMPLX.\r\n\r\nUSE constants_NSWC\r\nIMPLICIT NONE\r\nINTEGER :: n, pos, i, constr_type(9), m, ind, ibasis(9), iter, &\r\n mxiter = 25, numle, numge, j\r\nCHARACTER (LEN=79) :: text, in_text\r\nREAL (dp) :: a(9,9), b(9), c(9), x(9), z, temp(9), rerr\r\nREAL (dp), ALLOCATABLE :: bi(:,:)\r\n\r\nINTERFACE\r\n SUBROUTINE smplx (a, b0, c, ka, m, n0, ind, ibasis, x, z, iter, mxiter, &\r\n numle, numge, bi, rerr)\r\n USE constants_NSWC\r\n IMPLICIT NONE\r\n INTEGER, INTENT(IN) :: ka, m, n0, mxiter, numle, numge\r\n INTEGER, INTENT(IN OUT) :: ind\r\n INTEGER, DIMENSION(:), INTENT(IN OUT) :: ibasis\r\n INTEGER, INTENT(OUT) :: iter\r\n REAL (dp), DIMENSION(:,:), INTENT(IN) :: a\r\n REAL (dp), DIMENSION(:), INTENT(IN) :: b0, c\r\n REAL (dp), INTENT(OUT) :: z, rerr\r\n REAL (dp), DIMENSION(:), INTENT(OUT) :: x\r\n REAL (dp), DIMENSION(:,:), INTENT(OUT) :: bi\r\n END SUBROUTINE smplx\r\nEND INTERFACE\r\n\r\nWRITE(*, *) 'How many variables? (<=9): '\r\nREAD(*, *) n\r\nIF (n > 9) STOP 'Too many!'\r\n\r\nWRITE(*, *) 'Enter constraint coefficients incl. constr. type (<=, >= or =)'\r\nWRITE(*, *) 'Press ENTER again after the last constraint'\r\ntext = ' '\r\nDO i = 1, n\r\n pos = 8*i-6\r\n WRITE(text(pos:pos+3), '(\"X(\", i1, \")\")') i\r\nEND DO\r\ntext(pos+4:pos+11) = 'Con.type'\r\ntext(pos+13:pos+15) = 'RHS'\r\nWRITE(*, '(a)') text\r\nWRITE(*, *)\r\nnumle = 0\r\nnumge = 0\r\nDO i = 1, 9\r\n READ(*, '(a)') in_text\r\n IF (LEN_TRIM(in_text) == 0) EXIT\r\n READ(in_text, *) a(i,1:n)\r\n pos = INDEX(in_text, '=')\r\n IF (pos == 0) THEN\r\n STOP 'You must enter the constraint type (<=, >= or =)'\r\n END IF\r\n IF (in_text(pos-1:pos-1) == '<') THEN\r\n constr_type(i) = 1\r\n numle = numle + 1\r\n ELSE IF (in_text(pos-1:pos-1) == '>') THEN\r\n constr_type(i) = 2\r\n numge = numge + 1\r\n ELSE\r\n constr_type(i) = 3\r\n END IF\r\n READ(in_text(pos+1:), *) b(i)\r\nEND DO\r\n\r\nm = i - 1\r\nALLOCATE( bi(m,m) )\r\n\r\n! Re-order the constraints if necessary\r\nDO i = 1, numle\r\n IF (constr_type(i) /= 1) THEN\r\n DO j = numle+1, m\r\n IF (constr_type(j) == 1) THEN\r\n temp(1:n) = a(i, 1:n)\r\n a(i, 1:n) = a(j, 1:n)\r\n a(j, 1:n) = temp(1:n)\r\n z = b(i)\r\n b(i) = b(j)\r\n b(j) = z\r\n constr_type(j) = constr_type(i)\r\n constr_type(i) = 1\r\n EXIT\r\n END IF\r\n END DO\r\n END IF\r\nEND DO\r\nDO i = numle+1, numle+numge\r\n IF (constr_type(i) /= 2) THEN\r\n DO j = numle+numge+1, m\r\n IF (constr_type(j) == 2) THEN\r\n temp(1:n) = a(i, 1:n)\r\n a(i, 1:n) = a(j, 1:n)\r\n a(j, 1:n) = temp(1:n)\r\n z = b(i)\r\n b(i) = b(j)\r\n b(j) = z\r\n constr_type(j) = constr_type(i)\r\n constr_type(i) = 2\r\n EXIT\r\n END IF\r\n END DO\r\n END IF\r\nEND DO\r\n\r\n! Enter the coefficients in the objective function.\r\nWRITE(*, *) 'Enter the coefficients (costs) in the objective to be maximized'\r\npos = 8*n-2\r\ntext(pos:) = ' '\r\nWRITE(*, '(a)') text\r\nWRITE(*, *)\r\nREAD(*, '(a)') in_text\r\nREAD(in_text, *) c(1:n)\r\n\r\nCALL smplx (a, b, c, 9, m, n, ind, ibasis, x, z, iter, mxiter, &\r\n numle, numge, bi, rerr)\r\n\r\nWRITE(*, '(a, i2, a, i3)') ' IND = ', ind, ' No. of iterations = ', iter\r\nIF (ind == 0 .OR. i== 6) THEN\r\n WRITE(*, '(a, 9f7.2)') ' Solution: ', x(1:n)\r\n WRITE(*, '(a, f8.2)') ' Value of objective = ', z\r\n WRITE(*, *) 'The inverse matrix:'\r\n DO i = 1, m\r\n WRITE(*, '(9f8.3)') bi(i,1:m)\r\n END DO\r\nEND IF\r\n\r\nWRITE(*, '(a, g12.4)') ' Relative error = ', rerr\r\n\r\nSTOP\r\nEND PROGRAM test_smplx\r\n", "meta": {"hexsha": "1b6a0cc0d496c178d8ccf127a7e848445afcb1f0", "size": 3669, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/t_smplx.f90", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/amil/t_smplx.f90", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/amil/t_smplx.f90", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 28.0076335878, "max_line_length": 80, "alphanum_fraction": 0.5014990461, "num_tokens": 1344, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778824, "lm_q2_score": 0.7931059414036511, "lm_q1q2_score": 0.6985653957152336}} {"text": "module calculate\nuse math\nuse geom_utils\nuse divide\nimplicit none\n\nprivate\npublic :: triangle_area\npublic :: cp_lengths, cp_net_areas\npublic :: arc_length_bezier, surface_area_bezier\n\ncontains\n\nfunction triangle_area(m, tri) result(area)\n !> Calculate the area of a triangle.\n !> m - Number columns in triangle array.\n !> tri - Triangle array.\n !> area - Area of triangle.\n \n ! Input\n integer, intent(in) :: m\n double precision, intent(in) :: tri(3, m)\n \n ! Output\n double precision :: area\n \n ! Working\n double precision :: mag\n double precision :: v1(m), v2(m), vc(m)\n \n v1 = tri(2, :) - tri(1, :)\n v2 = tri(3, :) - tri(1, :)\n \n vc = cross(v1, v2)\n mag = norm(vc)\n area = 0.50d0 * mag\n \nend function triangle_area\n\nsubroutine cp_lengths(n, cp, lp, lc)\n !> Calculate the linear length of the control polygon and its chord.\n !> n - Number of control points - 1.\n !> cp - Dehomogenized control points.\n !> lp - Length of control polygon.\n !> lc - Chord length.\n \n !f2py intent(in) n, cp\n !f2py intent(out) lp, lc\n !f2py depend(n) cp\n \n ! Input\n integer, intent(in) :: n\n \n ! Output\n double precision, intent(out) :: lp, lc\n double precision, intent(in) :: cp(0:n, 0:2) \n \n ! Working\n integer :: i\n double precision :: vec(0:2)\n \n vec = cp(n, :) - cp(0, :)\n lc = norm(vec)\n lp = 0.0d0\n do i = 0, n - 1\n vec = cp(i + 1, :) - cp(i, :)\n lp = lp + norm(vec)\n end do\n \nend subroutine cp_lengths\n\nsubroutine cp_net_areas(n, m, cp, anet, ap)\n !> Calculate the surface areas of the control net.\n !> n - Number of control points - 1 in u-direction.\n !> m - Number of control points - 1 in v-direction.\n !> cp - Dehomogenized control points.\n !> anet - Area of control net.\n !> ap - Area of the plane formed by the four corners of the\n !> control net.\n \n !f2py intent(in) n, m, cp\n !f2py intent(out) anet, ap\n !f2py depend(n, m) cp\n \n ! Input\n integer, intent(in) :: n, m\n double precision, intent(in) :: cp(0:n, 0:m, 0:2)\n \n ! Output\n double precision, intent(out) :: anet, ap\n \n ! Working\n integer :: i, ntri\n integer :: triangles(0:2 * n * m - 1, 0:2)\n double precision :: v1(0:2), v2(0:2), v3(0:2)\n double precision :: verts(0:(n + 1) * (m + 1) - 1, 0:2)\n double precision :: c1(0:2), c2(0:2), c3(0:2)\n \n call tessellate_cp_net(n, m, cp, verts, triangles)\n ntri = size(triangles, 1)\n anet = 0.0d0\n do i = 0, ntri - 1\n v1 = verts(triangles(i, 0), :)\n v2 = verts(triangles(i, 1), :)\n v3 = verts(triangles(i, 2), :)\n c1 = v2 - v1\n c2 = v3 - v1\n c3 = cross(c1, c2)\n anet = anet + 0.50d0 * norm(c3)\n end do\n c1 = cp(n, 0, :) - cp(0, 0, :)\n c2 = cp(n, m, :) - cp(0, 0, :)\n c3 = cross(c1, c2)\n ap = 0.50d0 * norm(c3)\n c1 = cp(n, m, :) - cp(0, 0, :)\n c2 = cp(0, m, :) - cp(0, 0, :)\n c3 = cross(c1, c2)\n ap = ap + 0.50d0 * norm(c3)\nend subroutine cp_net_areas\n\nrecursive subroutine arc_length_bezier(n, cpw, u0, u1, tol, l)\n !> Estimate the arc length of a Bezier curve.\n !> n - Number of control points - 1.\n !> cpw - Control points.\n !> u0 - Starting parameter.\n !> u1 - Ending parameter.\n !> tol - Tolerance for comparing control polygon length and chord\n !> length.\n !> l - Approximate arc length.\n \n !f2py intent(in) n, cpw, tol, u0, u1\n !f2py intent(in,out) l\n !f2py depend(n) cpw\n \n ! Input\n integer, intent(in) :: n\n double precision, intent(in) :: u0, u1, tol\n double precision, intent(in) :: cpw(0:n, 0:3)\n \n ! Input/Output\n double precision, intent(inout) :: l(1)\n \n ! Working\n integer :: i\n double precision :: lp, lc, a1, b1, a2, b2\n double precision :: cp(0:n, 0:2)\n double precision :: qw1(0:n, 0:3), qw2(0:n, 0:3)\n double precision :: temp2(0:n, 0:3), w(0:n)\n \n ! Extract curve if needed\n if ((u0 .gt. 0.0d0) .or. (u1 .lt. 1.0d0)) then\n call extract_bezier_curve(cpw, n, u0, u1, 0.0d0, 1.0d0, temp2, a1, b1)\n else\n temp2 = cpw\n end if\n\n call dehomogenize_array1d(n, temp2, cp, w)\n call cp_lengths(n, cp, lp, lc)\n \n if (dabs(lp - lc) .le. tol) then\n l(1) = l(1) + (2.0d0 * lc + (dble(n) - 1.0d0) * lp) / (dble(n) + 1.0d0)\n else\n call split_bezier_curve(temp2, n, 0.50d0, 0.0d0, 1.0d0, qw1, a1, b1, &\n qw2, a2, b2)\n call arc_length_bezier(n, qw1, 0.0d0, 1.0d0, tol, l)\n call arc_length_bezier(n, qw2, 0.0d0, 1.0d0, tol, l)\n end if\n \nend subroutine arc_length_bezier\n\nrecursive subroutine surface_area_bezier(n, m, cpw, tol, a)\n !> Estimate the surface area of a Bezier surface.\n !> n - Number of control points - 1 in u-direction.\n !> m - Number of control points - 1 in v-direction.\n !> cpw - Control points.\n !> tol - Tolerance for comparing area of control net to area of\n !> base area of formed by the four corners of the control net.\n !> a - Approximate area of surface.\n \n !f2py intent(in) n, m, cpw, tol\n !f2py intent(in,out) a\n !f2py depend(n, m) cpw\n \n ! Input \n integer, intent(in) :: n, m\n double precision, intent(in) :: tol\n double precision, intent(in) :: cpw(0:n, 0:m, 0:3)\n \n ! Input/Output\n double precision, intent(inout) :: a(1)\n \n integer :: i\n double precision :: ap, anet\n double precision :: cp(0:n, 0:m, 0:2)\n double precision :: qw1(0:n, 0:m, 0:3), qw2(0:n, 0:m, 0:3)\n double precision :: qw3(0:n, 0:m, 0:3), qw4(0:n, 0:m, 0:3)\n double precision :: qw5(0:n, 0:m, 0:3), qw6(0:n, 0:m, 0:3)\n double precision :: w(0:n, 0:m)\n double precision :: ab1(0:1, 0:1), ab2(0:1, 0:1)\n\n call dehomogenize_array2d(n, m, cpw, cp, w)\n call cp_net_areas(n, m, cp, anet, ap)\n \n if (abs(anet - ap) .le. tol) then\n a(1) = a(1) + (4.0d0 * ap + dble(n + m + n * m - 3) * anet) / &\n dble((n + 1) * (m + 1))\n else\n call split_bezier_surface(cpw, n, m, 0.50d0, -1.0d0, &\n 0.0d0, 1.0d0, 0.0d0, 1.0d0, &\n qw1, qw2, ab1, ab2)\n call split_bezier_surface(qw1, n, m, -1.0d0, 0.50d0, &\n 0.0d0, 1.0d0, 0.0d0, 1.0d0, &\n qw3, qw4, ab1, ab2)\n call split_bezier_surface(qw2, n, m, -1.0d0, 0.50d0, &\n 0.0d0, 1.0d0, 0.0d0, 1.0d0, &\n qw5, qw6, ab1, ab2)\n call surface_area_bezier(n, m, qw3, tol, a)\n call surface_area_bezier(n, m, qw4, tol, a)\n call surface_area_bezier(n, m, qw5, tol, a)\n call surface_area_bezier(n, m, qw6, tol, a)\n end if\n \nend subroutine surface_area_bezier\n\nend module calculate", "meta": {"hexsha": "6ee610254a79fb044e2a48d49be0a8f20ba0609a", "size": 6917, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/geometry/calculate.f90", "max_stars_repo_name": "trelau/pyNURBS", "max_stars_repo_head_hexsha": "5dfd082fe368c1140ce485dc64b049b32c267d1f", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-04-16T20:30:19.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-03T07:40:47.000Z", "max_issues_repo_path": "src/geometry/calculate.f90", "max_issues_repo_name": "trelau/pyNURBS", "max_issues_repo_head_hexsha": "5dfd082fe368c1140ce485dc64b049b32c267d1f", "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/geometry/calculate.f90", "max_forks_repo_name": "trelau/pyNURBS", "max_forks_repo_head_hexsha": "5dfd082fe368c1140ce485dc64b049b32c267d1f", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-09-23T14:28:12.000Z", "max_forks_repo_forks_event_max_datetime": "2018-09-23T14:28:12.000Z", "avg_line_length": 30.7422222222, "max_line_length": 79, "alphanum_fraction": 0.5427208327, "num_tokens": 2499, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970654616711, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.6985653900958526}} {"text": "\tFUNCTION PR_THWC ( pres, tmpc, dwpc )\nC************************************************************************\nC* PR_THWC\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This subroutine computes wet bulb potential temperature in Celsius\t*\nC* from PRES, TMPC and DWPC. The result is obtained by first\t\t*\nC* computing THTE of the the air parcel at level PRES. Then the air\t*\nC* parcel is brought to 1000 mb moist adiabatically to get THWC.\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PR_THWC ( PRES, TMPC, DWPC )\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tPRES \t\tREAL \t\tPressure in millibars\t\t*\nC*\tTMPC\t\tREAL\t\tTemperature in Celsius\t\t*\nC*\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_THWC\t\tREAL \t\tWet bulb potential temp in C\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/GSC\t\t11/97\t\t\t\t\t\t*\nC* T. Lee/GSC\t\t12/97\tAdded missing PR_THWC checks\t\t*\nC************************************************************************\n INCLUDE \t'GEMPRM.PRM'\n INCLUDE \t'ERMISS.FNC'\nC------------------------------------------------------------------------\nC* Check for missing values.\nC\n\tIF ( ERMISS ( pres ) .or. ERMISS ( tmpc ) .or.\n +\t ERMISS ( dwpc ) .or. ( pres .le. 0. ) ) THEN\n\t PR_THWC = RMISSD\n\t RETURN\n\t ELSE\nC\nC*\t Find THTE. \nC\n\t thte = PR_THTE ( pres, tmpc, dwpc )\n\tEND IF\nC\nC*\tCheck for missing THTE and compute wet bulb temperature.\nC\n\tIF ( ERMISS ( thte ) ) THEN\n\t PR_THWC = RMISSD\n\t ELSE\n\t tg = 0.\n\t p1000 = 1000.\n\t PR_THWC = PR_TMST ( thte, p1000, tg )\n\t IF ( .not. ERMISS ( PR_THWC ) ) PR_THWC = PR_THWC - TMCK\n\tEND IF\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "892d6b622cbe0d622462de4f4f496f60f557b592", "size": 1624, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/pr/prthwc.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/prthwc.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/prthwc.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.641509434, "max_line_length": 73, "alphanum_fraction": 0.5024630542, "num_tokens": 523, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6985120293210813}} {"text": "C\nC $Id: rbglen.f,v 1.12 2008-09-18 00:42:18 kennison Exp $\nC\nC Copyright (C) 2000\nC University Corporation for Atmospheric Research\nC All Rights Reserved\nC\nC The use of this Software is governed by a License Agreement.\nC\n DOUBLE PRECISION FUNCTION RBGLEN (RLAT)\nC\n DOUBLE PRECISION RLAT\nC\nC The value of RBGLEN(RLAT) is the length of the parallel at latitude\nC RLAT, stated as a fraction of the length of the equator.\nC\nC Declare local variables.\nC\n DOUBLE PRECISION FLAT,PLEN(19)\nC\n INTEGER ILAT\nC\nC Define the contents of PLEN per the definition of the Robinson\nC projection. The values are associated with values of latitude from\nC 0 North to 90 North at five-degree intervals.\nC\n DATA PLEN( 1) / 1.0000D0 /\n DATA PLEN( 2) / 0.9986D0 /\n DATA PLEN( 3) / 0.9954D0 /\n DATA PLEN( 4) / 0.9900D0 /\n DATA PLEN( 5) / 0.9822D0 /\n DATA PLEN( 6) / 0.9730D0 /\n DATA PLEN( 7) / 0.9600D0 /\n DATA PLEN( 8) / 0.9427D0 /\n DATA PLEN( 9) / 0.9216D0 /\n DATA PLEN(10) / 0.8962D0 /\n DATA PLEN(11) / 0.8679D0 /\n DATA PLEN(12) / 0.8350D0 /\n DATA PLEN(13) / 0.7986D0 /\n DATA PLEN(14) / 0.7597D0 /\n DATA PLEN(15) / 0.7186D0 /\n DATA PLEN(16) / 0.6732D0 /\n DATA PLEN(17) / 0.6213D0 /\n DATA PLEN(18) / 0.5722D0 /\n DATA PLEN(19) / 0.5322D0 /\nC\nC Determine where the parallel of interest lies relative to the ones\nC represented in the tables (between the ones associated with elements\nC ILAT and ILAT+1 and a fractional distance FLAT from the former to the\nC latter).\nC\n ILAT=MAX(1,MIN(18,INT(1.D0+ABS(RLAT)/5.D0)))\nC\n FLAT=1.D0+ABS(RLAT)/5.D0-DBLE(ILAT)\nC\nC Return the desired value.\nC\n RBGLEN=(1.D0-FLAT)*PLEN(ILAT)+FLAT*PLEN(ILAT+1)\nC\nC Done.\nC\n RETURN\nC\n END\n", "meta": {"hexsha": "c252677951dbab31654d101f22851bdbfa03bb7f", "size": 1876, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ncarg2d/src/libncarg/ezmap/rbglen.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "ncarg2d/src/libncarg/ezmap/rbglen.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "ncarg2d/src/libncarg/ezmap/rbglen.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 28.8615384615, "max_line_length": 71, "alphanum_fraction": 0.618336887, "num_tokens": 675, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900950352329, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6985120257780197}} {"text": "! vim: set ft=fortran sw=4 ts=4:\n\nprogram tsunami\n\n ! Tsunami simulator\n !\n ! This version solves the linearized 1-d advection equation:\n !\n ! du/dt = - u du/dx - g dh/dx\n ! \n ! dh/dt = -d(hu)/dx\n !\n\n use iso_fortran_env, only: int32, real32, output_unit\n use mod_diff, only: diff => diffc\n\n implicit none\n\n integer(int32) :: i, n\n\n integer(int32), parameter :: im = 100 ! grid size in x\n integer(int32), parameter :: nm = 5000 ! number of time steps\n\n real(real32), parameter :: dt = 0.02 ! time step [s]\n real(real32), parameter :: dx = 1 ! grid spacing [m]\n\n real(real32), parameter :: g = 9.81 ! gravitational accelration (m/s^2)\n\n real(real32), dimension(im) :: h, hmean, u\n\n\n ! initial position & shape of blob\n integer(int32), parameter :: ipos = 25\n real(real32), parameter :: decay = 0.02\n\n ! initialize a gaussian blob centered at i = ipos = 25\n do i = 1, im\n h(i) = exp(-decay * (i - ipos)**2)\n end do\n\n ! set initial speed to zero\n u = 0\n\n ! set mean water height to 10 m\n hmean = 10\n\n ! write initial state to screen\n write(output_unit, *) 0, h\n\n\n time_loop: do n = 1, nm\n\n ! update u at next time step\n u = u - (u * diff(u) + g * diff(h)) / dx * dt\n\n ! update h at next time step\n h = h - diff(u * (hmean + h)) / dx * dt\n\n ! write output state to screen\n write(output_unit, *) n, h\n\n end do time_loop\n\nend program tsunami\n\n", "meta": {"hexsha": "51081657732ef41ba320faad7b4503c342ab6740", "size": 1488, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran/ModernFortran/tsunami/tsunami_3.f90", "max_stars_repo_name": "kkirstein/proglang-playground", "max_stars_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Fortran/ModernFortran/tsunami/tsunami_3.f90", "max_issues_repo_name": "kkirstein/proglang-playground", "max_issues_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran/ModernFortran/tsunami/tsunami_3.f90", "max_forks_repo_name": "kkirstein/proglang-playground", "max_forks_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.5454545455, "max_line_length": 75, "alphanum_fraction": 0.5719086022, "num_tokens": 467, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900950352329, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6985120159307702}} {"text": " SUBROUTINE STGREC(X,Y,Z,DZ,NP, TRIANG,NT, Bdry, MB, XYLIM,NX,NY,\n * ZFILL, ZVALS, MX, MY, NCONT, WANTPD, DZVALS )\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc>> 1997-07-01 STGREC Krogh Reversed subscripts in B (CLL suggestion)\nc>> 1997-06-18 STGREC CLL Added arguments Bdry and MB.\nC>> 1996-02-02 STGREC CLL\nC>> 1996-01-11 STGREC CLL\nC>> 1995-11-03 STGREC CLL Added argument, NCONT.\nC>> 1995-09-26 STGREC CLL Editing for inclusion into MATH77.\nc This subr builds a rectangular array of Z values by interpo-\nc lation in a triangular grid. The subr will use either C0 or C1\nc interpolation methods, depending on the setting of NCONT = 0 or 1.\nc Optionally this subr also builds a rectangular array of values of\nc first partial derivatives.\nc CLL, 1979 JUNE 12, MINOR CHANGES.\nc C.L.LAWSON, JPL, 1976 DEC 8. ADDED PARTIAL DERIVS 1977 MAR 3.\nc ------------------------------------------------------------------\nC Subroutine arguments\nc\nc All args are of intent IN except ZVALS() and DZVALS() which are\nc of intent OUT. The contents of DZ() are only used when NCONT = 1.\nc\nc X(),Y(),Z() [floating,in] NP sets of (X,Y,Z) data.\nC\nc (DZ(I,J),I=1,2),J=1,NP) [floating,in] Partial derivs of Z w.r.t.\nc X and Y. The contents of this array are only used when NCONT = 1,\nc not when NCONT = 0.\nC\nc NP [integer,in] No. of data points.\nc\nc TRIANG(1:6*NT),NT [integer,in] TRIANG() contains pointers (integers)\nc describing the triangular grid. NT is the number of triangles.\nc Each triangle requires 6 pointers.\nc\nc Bdry(1:4, MB) [integer, in] Array containing pointers defining the\nc boundary of the (convex) triangular grid.\nc\nc MB [integer, in] Dimension parameter for Bdry() array.\nC\nc XYLIM(1:4) [floating,in] Contains XMIN, XMAX, YMIN, and YMAX\nc specifying boundaries of the rectangular grid.\nc\nc NX,NY [integer, in] NO. OF X AND Y GRID LINES IN RECTANGULAR GRID.\nC\nc ZFILL [floating, in] Selects action to be taken when a node of the\nc rectangular grid is outside the (convex) triangular grid.\nc If ZFILL = 0.0, extrapolated values will be provided by this\nc package.\nc If ZFILL .ne. 0.0, this subroutine will store ZFILL into ZVALS()\nc and DZVALS() for locations outside the triangular grid.\nc\nc ZVALS(,) [floating,out] MX BY MY ARRAY IN WHICH THE NX BY NY SET OF\nc INTERPOLATED VALUES WILL BE STORED.\nc\nc MX,MY [integer, in] DIMENSIONS OF THE ARRAYS ZVALS( , ) AND\nc DZVALS( , ,2)\nC\nc NCONT [integer,in] Order of continuity of interpolation method to be\nc used.\nc 0 selects a C0 method. This method uses linear interpolation over\nc each triangle. The function value is continuous across the whole\nc grid but generally the 1st partial derivatives are discontinuous\nc across boundaries between triangles.\nc 1 selects a C1 method. This method partitions each triangle into\nc 3 smaller triangles and constructs a bicubic patch over each of\nc the smaller triangles. The function value and 1st partial deriv-\nc atives are continuous across the whole grid but generally the 2nd\nc and higher order partial derivatives are discontinuous across\nc boundaries between the original triangles and between the small\nc triangles.\nc\nc WANTPD [logical, in] User sets = .true. if partial derivs are\nc desired, and .false. otherwise.\nC\nc DZVALS(,,) [floating,out] MX by NY by 2 array in which the\nc NX by NY by 2 set of partial derivatives will be stored if\nc WANTPD = .TRUE.\nc In the case of NCONT = 0, the interpolation function does not\nc generally have a partial derivative at points on the boundary\nc between two triangles. For such points this subr will return the\nc 1st partial derivatives associated with one of the adjoining\nc triangles.\nc ------------------------------------------------------------------\nc--S replaces \"?\": ?TGREC, ?TGFI\nc ------------------------------------------------------------------\n integer mxwrk\n parameter(mxwrk = 28)\n integer MB, mx, my, np\n integer Bdry(4, MB)\n integer i, ix, iy\n integer mode, NCONT, NT, nx, ny, TRIANG(1:*)\n real DELX, DELY, DZ(2,NP), DZOUT(2), DZVALS(MX,MY,2)\n real SVWRK0(mxwrk), SVWRK1(mxwrk)\n real X(NP), XY(2), XYLIM(4), Y(NP)\n real Z(NP), zero, ZFILL, ZVALS(MX,MY)\n parameter(zero=0.0e0)\n logical FIRST, WANTPD\nc ------------------------------------------------------------------\n DELX = (XYLIM(2)-XYLIM(1)) / (NX-1)\n DELY = (XYLIM(4)-XYLIM(3)) / (NY-1)\n do 10 i = 1,mxwrk\n svwrk0(i) = zero\n 10 continue\nC\nc XY(1) AND XY(2) WILL BE SET SUCCESSIVELY TO THE (X,Y) COORDS\nc OF EACH POINT OF THE RECTANGULAR GRID.\nc When NCONT .eq. 0, the values of the 1st derivatives are\nc constant within each triangle. Thus in the case of\nc NCONT .eq. 0 and WANTDZ being true, we only need to compute the\nc partial derivatives when NEWTRI is true.\nC\n XY(2) = XYLIM(3)\n DO 60 IY=1,NY\n do 20 i = 1,mxwrk\n svwrk1(i) = svwrk0(i)\n 20 continue\n FIRST = .true.\n XY(1) = XYLIM(1)\n DO 50 IX=1,NX\n call STGFI( X, Y, Z, DZ, TRIANG, NT, Bdry, MB,\n * NCONT, XY, ZVALS(IX,IY), WANTPD, DZOUT, MODE, SVWRK1)\n IF(FIRST) then\n do 30 i = 1,mxwrk\n svwrk0(i) = svwrk1(i)\n 30 continue\n FIRST = .false.\n endif\n\n IF (MODE .EQ. 0) THEN\nc\nc 0 means XY was found within the triangular grid.\nc\n IF (WANTPD) THEN\n DZVALS(IX,IY,1)=DZOUT(1)\n DZVALS(IX,IY,2)=DZOUT(2)\n END IF\n ELSEif(mode .eq. 1) then\nc\nc 1 MEANS XY IS OUTSIDE THE TRIANGULAR GRID.\nc Will use extrapolated value if ZFILL .eq. zero.\nc Otherwise set results to the ZFILL\nc\n if(ZFILL .eq. zero) then\n IF (WANTPD) THEN\n DZVALS(IX,IY,1)=DZOUT(1)\n DZVALS(IX,IY,2)=DZOUT(2)\n ENDIF\n else\n ZVALS(IX,IY) = ZFILL\n IF (WANTPD) THEN\n DZVALS(IX,IY,1)=ZFILL\n DZVALS(IX,IY,2)=ZFILL\n ENDIF\n endif\n else\nc\nc Mode = 2 MEANS CYCLING HAS HAPPENED IN the lookup\nc process. This should not happen.\nc ERROR MESSAGE WILL BE PRINTED FROM _TGFI.\nC\n ZVALS(IX,IY) = ZFILL\n IF (WANTPD) THEN\n DZVALS(IX,IY,1)=ZFILL\n DZVALS(IX,IY,2)=ZFILL\n ENDIF\n ENDIF\nC\n XY(1) = XY(1) + DELX\n 50 continue\n XY(2) = XY(2) + DELY\n 60 continue\n RETURN\n END\n", "meta": {"hexsha": "3229a0c5f23cd1e9c975900c5a6bf26dd2b95cad", "size": 7092, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/stgrec.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/stgrec.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/stgrec.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": 40.2954545455, "max_line_length": 72, "alphanum_fraction": 0.5855893965, "num_tokens": 2170, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357529306639, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.6985119054892287}} {"text": "!*****************************************************************************************\n!> author: Jacob Williams\n!\n! Complex-step differentiation routines.\n!\n!# See also\n! 1. J.R.R.A. Martins, P. Sturdza, J.J. Alonso,\n! \"The Complex-Step Derivative Approximation\",\n! ACM Transactions on Mathematical Software,\n! Vol. 29, No. 3, September 2003, Pages 245262.\n\n module complex_step_module\n\n use kind_module, only: wp\n\n implicit none\n\n private\n\n interface\n function func(x) result(f)\n import :: wp\n implicit none\n complex(wp),intent(in) :: x\n complex(wp) :: f\n end function func\n end interface\n\n public :: complex_step_derivative\n public :: complex_step_test !for testing\n\n contains\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Compute the first derivative using the complex-step method.\n! This is Equation 6 from Reference [1].\n\n subroutine complex_step_derivative(f,x,h,dfdx)\n\n implicit none\n\n procedure(func) :: f\n complex(wp),intent(in) :: x\n real(wp),intent(in) :: h\n real(wp),intent(out) :: dfdx\n\n dfdx = AIMAG(f(cmplx(real(x,wp),AIMAG(x)+h,wp)))/h\n\n end subroutine complex_step_derivative\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Compute the first derivative using a forward difference.\n! This is Equation 1 from Reference [1].\n\n subroutine forward_diff(f,x,h,dfdx)\n\n implicit none\n\n procedure(func) :: f\n complex(wp),intent(in) :: x\n real(wp),intent(in) :: h\n real(wp),intent(out) :: dfdx\n\n dfdx = (f(x+h) - f(x)) / h\n\n end subroutine forward_diff\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Compute the first derivative using a 2-point central difference [-h,h].\n\n subroutine central_diff(f,x,h,dfdx)\n\n implicit none\n\n procedure(func) :: f\n complex(wp),intent(in) :: x\n real(wp),intent(in) :: h\n real(wp),intent(out) :: dfdx\n\n dfdx = (f(x+h) - f(x-h)) / (2.0_wp*h)\n\n end subroutine central_diff\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Compute the first derivative using a 4-point central difference [-2h,-h,h,2h].\n\n subroutine central_diff_4(f,x,h,dfdx)\n\n implicit none\n\n procedure(func) :: f\n complex(wp),intent(in) :: x\n real(wp),intent(in) :: h\n real(wp),intent(out) :: dfdx\n\n real(wp) :: h2\n\n h2 = 2.0_wp * h\n\n dfdx = (f(x-h2) - 8.0_wp*f(x-h) + 8.0_wp*f(x+h) - f(x+h2)) / (12.0_wp*h)\n\n end subroutine central_diff_4\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Unit test for the complex_step module.\n\n subroutine complex_step_test()\n\n implicit none\n\n integer :: i\n complex(wp) :: x\n real(wp) :: h,dfdx,dfdx2,dfdx3,dfdx4,err,err2,err3,err4\n\n write(*,*) ''\n write(*,*) '---------------'\n write(*,*) ' complex_step_test'\n write(*,*) '---------------'\n write(*,*) ''\n\n x = cmplx(2.0_wp,0.0_wp,wp)\n h = 1.0e-10_wp\n\n call complex_step_derivative(test_func,x,h,dfdx)\n\n !write(*,*) ''\n !write(*,*) 'x :',x\n !write(*,*) 'dfdx :',dfdx\n !write(*,*) 'error :',real(test_deriv(x),wp) - dfdx\n !write(*,*) ''\n\n write(*,'(*(A30))') 'h', 'forward diff err', 'central diff err', 'central diff 4 err', 'complex step err'\n\n do i=1,200\n h = 10.0_wp**(-i/10.0_wp)\n call complex_step_derivative(test_func,x,h,dfdx)\n call forward_diff(test_func,x,h,dfdx2)\n call central_diff(test_func,x,h,dfdx3)\n call central_diff_4(test_func,x,h,dfdx4)\n err = real(test_deriv(x),wp) - dfdx\n err2 = real(test_deriv(x),wp) - dfdx2\n err3 = real(test_deriv(x),wp) - dfdx3\n err4 = real(test_deriv(x),wp) - dfdx4\n write(*,'(*(E30.16,1X))') h, err2, err3, err4, err\n end do\n\n contains\n!*****************************************************************************************\n\n !****************************************\n function test_func(x) result(f)\n\n implicit none\n\n complex(wp),intent(in) :: x\n complex(wp) :: f\n\n f = exp(x) + sin(x)\n\n end function test_func\n !****************************************\n\n !****************************************\n function test_deriv(x) result(f)\n\n implicit none\n\n complex(wp),intent(in) :: x\n complex(wp) :: f\n\n f = exp(x) + cos(x)\n\n end function test_deriv\n !****************************************\n\n end subroutine complex_step_test\n!*****************************************************************************************\n\n!*****************************************************************************************\n end module complex_step_module\n!*****************************************************************************************\n", "meta": {"hexsha": "92be12fa110a2ac16e500a8cbb150db00287bd16", "size": 5469, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/complex_step.f90", "max_stars_repo_name": "jacobwilliams/Fortran-Astrodynamics-Toolk", "max_stars_repo_head_hexsha": "f8e18642dc8d78473d233b8fa6078fdbf7a1d6fc", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 122, "max_stars_repo_stars_event_min_datetime": "2015-01-29T05:40:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:20:21.000Z", "max_issues_repo_path": "src/complex_step.f90", "max_issues_repo_name": "gandymagic/Fortran-Astrodynamics-Toolkit", "max_issues_repo_head_hexsha": "7f176fabc8c36cc1981349b02eeb6d8112f2bfbc", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 25, "max_issues_repo_issues_event_min_datetime": "2015-06-10T02:16:59.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T04:28:55.000Z", "max_forks_repo_path": "src/complex_step.f90", "max_forks_repo_name": "gandymagic/Fortran-Astrodynamics-Toolkit", "max_forks_repo_head_hexsha": "7f176fabc8c36cc1981349b02eeb6d8112f2bfbc", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 43, "max_forks_repo_forks_event_min_datetime": "2015-02-12T13:24:23.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-30T04:30:49.000Z", "avg_line_length": 28.484375, "max_line_length": 109, "alphanum_fraction": 0.4181751691, "num_tokens": 1253, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528170040852, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.6985104371744137}} {"text": "program buffon_needles\n implicit none\n real, parameter :: PI = acos(-1.0)\n integer, parameter :: nr_needles_default = 100\n real, parameter :: line_dist_default = 2.0\n real, parameter :: needle_len = 2.0\n integer :: nr_needles = nr_needles_default\n real :: line_dist = line_dist_default\n !> @brief a needle's position is represented by the x-coordinate of its\n !> midpoint, and the angle theta\n type :: needle_t\n real :: x, theta\n real :: len = needle_len\n end type\n type(needle_t) :: needle\n integer :: i, nr_hits\n\n call get_command_line_values(nr_needles, line_dist)\n call check_distance_acceptable(line_dist, needle_len)\n nr_hits = 0\n do i = 1, nr_needles\n needle = drop_needle(line_dist)\n if (is_needle_crossing(needle, line_dist)) then\n nr_hits = nr_hits + 1\n end if\n end do\n print '(A, F15.7)', 'probability = ', real(nr_hits)/real(nr_needles)\n print '(A, F15.7)', 'expected probability = ', 2.0*needle_len/(PI*line_dist)\n\ncontains\n\n !> @brief handle command line arguments\n !>\n !> @param[inout] nr_needles number of needles to drop\n !> @param[inout] line_dist distance between the lines on the page\n subroutine get_command_line_values(nr_needles, line_dist)\n use, intrinsic :: iso_fortran_env, only : error_unit\n implicit none\n integer, intent(inout) :: nr_needles\n real, intent(inout) :: line_dist\n character(len=1024) :: buffer, iomsg\n integer :: iostat\n\n if (command_argument_count() > 0) then\n call get_command_argument(1, buffer)\n read (buffer, fmt=*, iomsg=iomsg, iostat=iostat) nr_needles\n if (iostat /= 0) then\n write (unit=error_unit, fmt='(A)') iomsg\n stop 1\n end if\n end if\n if (command_argument_count() > 1) then\n call get_command_argument(2, buffer)\n read (buffer, fmt=*, iomsg=iomsg, iostat=iostat) line_dist\n if (iostat /= 0) then\n write (unit=error_unit, fmt='(A)') iomsg\n stop 1\n end if\n end if\n end subroutine get_command_line_values\n\n !> @brief check whether the distance between the lines on paper is\n !> acceptable\n !>\n !> The subroutine verifies the distance between the lines on the page, if\n !> that is not adequate, it will print an error message and exit the\n !> application.\n !>\n !> @param[in] line_dist distance between lines on the page\n !> @param[in] needle_len length of a needle\n subroutine check_distance_acceptable(line_dist, needle_len)\n use, intrinsic :: iso_fortran_env, only : error_unit\n implicit none\n real, value :: line_dist, needle_len\n\n if (line_dist < needle_len) then\n write (unit=error_unit, fmt='(A, F4.2)') &\n 'error: the distance between the lines must be larger than the needle length', &\n needle_len\n stop 2\n end if \n end subroutine check_distance_acceptable\n\n !> @brief drop a needle on the plain\n !>\n !> Due to symmetry arbuments, the midpoint is restricted to fall between\n !> zero and half of the distance between two lines, for similar reasons,\n !> theta will fall between zero and pi/2\n !>\n !> @param[in] line_dist distance between two lines on the paper\n !> @returns a random needle position\n function drop_needle(line_dist) result(needle)\n implicit none\n real, value :: line_dist\n type(needle_t) :: needle\n real :: r\n\n call random_number(r)\n needle%x = 0.5*r*line_dist\n call random_number(r)\n needle%theta = 0.5*r*PI\n end function drop_needle\n\n !> @brief check whether a given needle crosses a line\n !>\n !> @param[in] needle needle position to check\n !> @param[in] line_dist distance between lines on the paper\n !> @returns .true. if the needle crosses a line, .false. otherwise\n function is_needle_crossing(needle, line_dist) result(does_cross)\n implicit none\n type(needle_t), intent(in) :: needle\n real, value :: line_dist\n logical :: does_cross\n\n does_cross = needle%x + 0.5*needle%len*cos(needle%theta) >= 0.5*line_dist\n end function is_needle_crossing\n\nend program buffon_needles\n", "meta": {"hexsha": "f06b25bc67688827e7c8b1c9eb4374720b008788", "size": 4376, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source_code/buffon_needles/buffon_needles.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/buffon_needles/buffon_needles.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/buffon_needles/buffon_needles.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": 36.7731092437, "max_line_length": 96, "alphanum_fraction": 0.6316270567, "num_tokens": 1158, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527944504227, "lm_q2_score": 0.8198933425148213, "lm_q1q2_score": 0.6985104243067995}} {"text": "*> \\brief CGESVDX computes the singular value decomposition (SVD) for GE matrices\n*\n* =========== DOCUMENTATION ===========\n*\n* Online html documentation available at\n* http://www.netlib.org/lapack/explore-html/\n*\n*> \\htmlonly\n*> Download CGESVDX + dependencies\n*> \n*> [TGZ]\n*> \n*> [ZIP]\n*> \n*> [TXT]\n*> \\endhtmlonly\n*\n* Definition:\n* ===========\n*\n* SUBROUTINE CGESVDX( JOBU, JOBVT, RANGE, M, N, A, LDA, VL, VU,\n* $ IL, IU, NS, S, U, LDU, VT, LDVT, WORK,\n* $ LWORK, RWORK, IWORK, INFO )\n*\n*\n* .. Scalar Arguments ..\n* CHARACTER JOBU, JOBVT, RANGE\n* INTEGER IL, INFO, IU, LDA, LDU, LDVT, LWORK, M, N, NS\n* REAL VL, VU\n* ..\n* .. Array Arguments ..\n* INTEGER IWORK( * )\n* REAL S( * ), RWORK( * )\n* COMPLEX A( LDA, * ), U( LDU, * ), VT( LDVT, * ),\n* $ WORK( * )\n* ..\n*\n*\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*>\n*> CGESVDX computes the singular value decomposition (SVD) of a complex\n*> M-by-N matrix A, optionally computing the left and/or right singular\n*> vectors. The SVD is written\n*>\n*> A = U * SIGMA * transpose(V)\n*>\n*> where SIGMA is an M-by-N matrix which is zero except for its\n*> min(m,n) diagonal elements, U is an M-by-M unitary matrix, and\n*> V is an N-by-N unitary matrix. The diagonal elements of SIGMA\n*> are the singular values of A; they are real and non-negative, and\n*> are returned in descending order. The first min(m,n) columns of\n*> U and V are the left and right singular vectors of A.\n*>\n*> CGESVDX uses an eigenvalue problem for obtaining the SVD, which\n*> allows for the computation of a subset of singular values and\n*> vectors. See SBDSVDX for details.\n*>\n*> Note that the routine returns V**T, not V.\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in] JOBU\n*> \\verbatim\n*> JOBU is CHARACTER*1\n*> Specifies options for computing all or part of the matrix U:\n*> = 'V': the first min(m,n) columns of U (the left singular\n*> vectors) or as specified by RANGE are returned in\n*> the array U;\n*> = 'N': no columns of U (no left singular vectors) are\n*> computed.\n*> \\endverbatim\n*>\n*> \\param[in] JOBVT\n*> \\verbatim\n*> JOBVT is CHARACTER*1\n*> Specifies options for computing all or part of the matrix\n*> V**T:\n*> = 'V': the first min(m,n) rows of V**T (the right singular\n*> vectors) or as specified by RANGE are returned in\n*> the array VT;\n*> = 'N': no rows of V**T (no right singular vectors) are\n*> computed.\n*> \\endverbatim\n*>\n*> \\param[in] RANGE\n*> \\verbatim\n*> RANGE is CHARACTER*1\n*> = 'A': all singular values will be found.\n*> = 'V': all singular values in the half-open interval (VL,VU]\n*> will be found.\n*> = 'I': the IL-th through IU-th singular values will be found.\n*> \\endverbatim\n*>\n*> \\param[in] M\n*> \\verbatim\n*> M is INTEGER\n*> The number of rows of the input matrix A. M >= 0.\n*> \\endverbatim\n*>\n*> \\param[in] N\n*> \\verbatim\n*> N is INTEGER\n*> The number of columns of the input matrix A. N >= 0.\n*> \\endverbatim\n*>\n*> \\param[in,out] A\n*> \\verbatim\n*> A is COMPLEX array, dimension (LDA,N)\n*> On entry, the M-by-N matrix A.\n*> On exit, the contents of A are destroyed.\n*> \\endverbatim\n*>\n*> \\param[in] LDA\n*> \\verbatim\n*> LDA is INTEGER\n*> The leading dimension of the array A. LDA >= max(1,M).\n*> \\endverbatim\n*>\n*> \\param[in] VL\n*> \\verbatim\n*> VL is REAL\n*> If RANGE='V', the lower bound of the interval to\n*> be searched for singular values. VU > VL.\n*> Not referenced if RANGE = 'A' or 'I'.\n*> \\endverbatim\n*>\n*> \\param[in] VU\n*> \\verbatim\n*> VU is REAL\n*> If RANGE='V', the upper bound of the interval to\n*> be searched for singular values. VU > VL.\n*> Not referenced if RANGE = 'A' or 'I'.\n*> \\endverbatim\n*>\n*> \\param[in] IL\n*> \\verbatim\n*> IL is INTEGER\n*> If RANGE='I', the index of the\n*> smallest singular value to be returned.\n*> 1 <= IL <= IU <= min(M,N), if min(M,N) > 0.\n*> Not referenced if RANGE = 'A' or 'V'.\n*> \\endverbatim\n*>\n*> \\param[in] IU\n*> \\verbatim\n*> IU is INTEGER\n*> If RANGE='I', the index of the\n*> largest singular value to be returned.\n*> 1 <= IL <= IU <= min(M,N), if min(M,N) > 0.\n*> Not referenced if RANGE = 'A' or 'V'.\n*> \\endverbatim\n*>\n*> \\param[out] NS\n*> \\verbatim\n*> NS is INTEGER\n*> The total number of singular values found,\n*> 0 <= NS <= min(M,N).\n*> If RANGE = 'A', NS = min(M,N); if RANGE = 'I', NS = IU-IL+1.\n*> \\endverbatim\n*>\n*> \\param[out] S\n*> \\verbatim\n*> S is REAL array, dimension (min(M,N))\n*> The singular values of A, sorted so that S(i) >= S(i+1).\n*> \\endverbatim\n*>\n*> \\param[out] U\n*> \\verbatim\n*> U is COMPLEX array, dimension (LDU,UCOL)\n*> If JOBU = 'V', U contains columns of U (the left singular\n*> vectors, stored columnwise) as specified by RANGE; if\n*> JOBU = 'N', U is not referenced.\n*> Note: The user must ensure that UCOL >= NS; if RANGE = 'V',\n*> the exact value of NS is not known in advance and an upper\n*> bound must be used.\n*> \\endverbatim\n*>\n*> \\param[in] LDU\n*> \\verbatim\n*> LDU is INTEGER\n*> The leading dimension of the array U. LDU >= 1; if\n*> JOBU = 'V', LDU >= M.\n*> \\endverbatim\n*>\n*> \\param[out] VT\n*> \\verbatim\n*> VT is COMPLEX array, dimension (LDVT,N)\n*> If JOBVT = 'V', VT contains the rows of V**T (the right singular\n*> vectors, stored rowwise) as specified by RANGE; if JOBVT = 'N',\n*> VT is not referenced.\n*> Note: The user must ensure that LDVT >= NS; if RANGE = 'V',\n*> the exact value of NS is not known in advance and an upper\n*> bound must be used.\n*> \\endverbatim\n*>\n*> \\param[in] LDVT\n*> \\verbatim\n*> LDVT is INTEGER\n*> The leading dimension of the array VT. LDVT >= 1; if\n*> JOBVT = 'V', LDVT >= NS (see above).\n*> \\endverbatim\n*>\n*> \\param[out] WORK\n*> \\verbatim\n*> WORK is COMPLEX array, dimension (MAX(1,LWORK))\n*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK;\n*> \\endverbatim\n*>\n*> \\param[in] LWORK\n*> \\verbatim\n*> LWORK is INTEGER\n*> The dimension of the array WORK.\n*> LWORK >= MAX(1,MIN(M,N)*(MIN(M,N)+4)) for the paths (see\n*> comments inside the code):\n*> - PATH 1 (M much larger than N)\n*> - PATH 1t (N much larger than M)\n*> LWORK >= MAX(1,MIN(M,N)*2+MAX(M,N)) for the other paths.\n*> For good performance, LWORK should generally be larger.\n*>\n*> If LWORK = -1, then a workspace query is assumed; the routine\n*> only calculates the optimal size of the WORK array, returns\n*> this value as the first entry of the WORK array, and no error\n*> message related to LWORK is issued by XERBLA.\n*> \\endverbatim\n*>\n*> \\param[out] RWORK\n*> \\verbatim\n*> RWORK is REAL array, dimension (MAX(1,LRWORK))\n*> LRWORK >= MIN(M,N)*(MIN(M,N)*2+15*MIN(M,N)).\n*> \\endverbatim\n*>\n*> \\param[out] IWORK\n*> \\verbatim\n*> IWORK is INTEGER array, dimension (12*MIN(M,N))\n*> If INFO = 0, the first NS elements of IWORK are zero. If INFO > 0,\n*> then IWORK contains the indices of the eigenvectors that failed\n*> to converge in SBDSVDX/SSTEVX.\n*> \\endverbatim\n*>\n*> \\param[out] INFO\n*> \\verbatim\n*> INFO is INTEGER\n*> = 0: successful exit\n*> < 0: if INFO = -i, the i-th argument had an illegal value\n*> > 0: if INFO = i, then i eigenvectors failed to converge\n*> in SBDSVDX/SSTEVX.\n*> if INFO = N*2 + 1, an internal error occurred in\n*> SBDSVDX\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee\n*> \\author Univ. of California Berkeley\n*> \\author Univ. of Colorado Denver\n*> \\author NAG Ltd.\n*\n*> \\ingroup complexGEsing\n*\n* =====================================================================\n SUBROUTINE CGESVDX( JOBU, JOBVT, RANGE, M, N, A, LDA, VL, VU,\n $ IL, IU, NS, S, U, LDU, VT, LDVT, WORK,\n $ LWORK, RWORK, IWORK, INFO )\n*\n* -- LAPACK driver routine --\n* -- LAPACK is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n*\n* .. Scalar Arguments ..\n CHARACTER JOBU, JOBVT, RANGE\n INTEGER IL, INFO, IU, LDA, LDU, LDVT, LWORK, M, N, NS\n REAL VL, VU\n* ..\n* .. Array Arguments ..\n INTEGER IWORK( * )\n REAL S( * ), RWORK( * )\n COMPLEX A( LDA, * ), U( LDU, * ), VT( LDVT, * ),\n $ WORK( * )\n* ..\n*\n* =====================================================================\n*\n* .. Parameters ..\n COMPLEX CZERO, CONE\n PARAMETER ( CZERO = ( 0.0E0, 0.0E0 ),\n $ CONE = ( 1.0E0, 0.0E0 ) )\n REAL ZERO, ONE\n PARAMETER ( ZERO = 0.0E0, ONE = 1.0E0 )\n* ..\n* .. Local Scalars ..\n CHARACTER JOBZ, RNGTGK\n LOGICAL ALLS, INDS, LQUERY, VALS, WANTU, WANTVT\n INTEGER I, ID, IE, IERR, ILQF, ILTGK, IQRF, ISCL,\n $ ITAU, ITAUP, ITAUQ, ITEMP, ITEMPR, ITGKZ,\n $ IUTGK, J, K, MAXWRK, MINMN, MINWRK, MNTHR\n REAL ABSTOL, ANRM, BIGNUM, EPS, SMLNUM\n* ..\n* .. Local Arrays ..\n REAL DUM( 1 )\n* ..\n* .. External Subroutines ..\n EXTERNAL CGEBRD, CGELQF, CGEQRF, CLASCL, CLASET,\n $ CUNMBR, CUNMQR, CUNMLQ, CLACPY, \n $ SBDSVDX, SLASCL, XERBLA\n* ..\n* .. External Functions ..\n LOGICAL LSAME\n INTEGER ILAENV\n REAL SLAMCH, CLANGE\n EXTERNAL LSAME, ILAENV, SLAMCH, CLANGE\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC MAX, MIN, SQRT\n* ..\n* .. Executable Statements ..\n*\n* Test the input arguments.\n*\n NS = 0\n INFO = 0\n ABSTOL = 2*SLAMCH('S')\n LQUERY = ( LWORK.EQ.-1 )\n MINMN = MIN( M, N )\n\n WANTU = LSAME( JOBU, 'V' )\n WANTVT = LSAME( JOBVT, 'V' )\n IF( WANTU .OR. WANTVT ) THEN\n JOBZ = 'V'\n ELSE\n JOBZ = 'N'\n END IF\n ALLS = LSAME( RANGE, 'A' )\n VALS = LSAME( RANGE, 'V' )\n INDS = LSAME( RANGE, 'I' )\n*\n INFO = 0\n IF( .NOT.LSAME( JOBU, 'V' ) .AND.\n $ .NOT.LSAME( JOBU, 'N' ) ) THEN\n INFO = -1\n ELSE IF( .NOT.LSAME( JOBVT, 'V' ) .AND.\n $ .NOT.LSAME( JOBVT, 'N' ) ) THEN\n INFO = -2\n ELSE IF( .NOT.( ALLS .OR. VALS .OR. INDS ) ) THEN\n INFO = -3\n ELSE IF( M.LT.0 ) THEN\n INFO = -4\n ELSE IF( N.LT.0 ) THEN\n INFO = -5\n ELSE IF( M.GT.LDA ) THEN\n INFO = -7\n ELSE IF( MINMN.GT.0 ) THEN\n IF( VALS ) THEN\n IF( VL.LT.ZERO ) THEN\n INFO = -8\n ELSE IF( VU.LE.VL ) THEN\n INFO = -9\n END IF\n ELSE IF( INDS ) THEN\n IF( IL.LT.1 .OR. IL.GT.MAX( 1, MINMN ) ) THEN\n INFO = -10\n ELSE IF( IU.LT.MIN( MINMN, IL ) .OR. IU.GT.MINMN ) THEN\n INFO = -11\n END IF\n END IF\n IF( INFO.EQ.0 ) THEN\n IF( WANTU .AND. LDU.LT.M ) THEN\n INFO = -15\n ELSE IF( WANTVT ) THEN\n IF( INDS ) THEN\n IF( LDVT.LT.IU-IL+1 ) THEN\n INFO = -17\n END IF\n ELSE IF( LDVT.LT.MINMN ) THEN\n INFO = -17\n END IF\n END IF\n END IF\n END IF\n*\n* Compute workspace\n* (Note: Comments in the code beginning \"Workspace:\" describe the\n* minimal amount of workspace needed at that point in the code,\n* as well as the preferred amount for good performance.\n* NB refers to the optimal block size for the immediately\n* following subroutine, as returned by ILAENV.)\n*\n IF( INFO.EQ.0 ) THEN\n MINWRK = 1\n MAXWRK = 1\n IF( MINMN.GT.0 ) THEN\n IF( M.GE.N ) THEN\n MNTHR = ILAENV( 6, 'CGESVD', JOBU // JOBVT, M, N, 0, 0 )\n IF( M.GE.MNTHR ) THEN\n*\n* Path 1 (M much larger than N)\n*\n MINWRK = N*(N+5)\n MAXWRK = N + N*ILAENV(1,'CGEQRF',' ',M,N,-1,-1)\n MAXWRK = MAX(MAXWRK,\n $ N*N+2*N+2*N*ILAENV(1,'CGEBRD',' ',N,N,-1,-1))\n IF (WANTU .OR. WANTVT) THEN\n MAXWRK = MAX(MAXWRK,\n $ N*N+2*N+N*ILAENV(1,'CUNMQR','LN',N,N,N,-1))\n END IF\n ELSE\n*\n* Path 2 (M at least N, but not much larger)\n*\n MINWRK = 3*N + M\n MAXWRK = 2*N + (M+N)*ILAENV(1,'CGEBRD',' ',M,N,-1,-1)\n IF (WANTU .OR. WANTVT) THEN\n MAXWRK = MAX(MAXWRK,\n $ 2*N+N*ILAENV(1,'CUNMQR','LN',N,N,N,-1))\n END IF\n END IF\n ELSE\n MNTHR = ILAENV( 6, 'CGESVD', JOBU // JOBVT, M, N, 0, 0 )\n IF( N.GE.MNTHR ) THEN\n*\n* Path 1t (N much larger than M)\n*\n MINWRK = M*(M+5)\n MAXWRK = M + M*ILAENV(1,'CGELQF',' ',M,N,-1,-1)\n MAXWRK = MAX(MAXWRK,\n $ M*M+2*M+2*M*ILAENV(1,'CGEBRD',' ',M,M,-1,-1))\n IF (WANTU .OR. WANTVT) THEN\n MAXWRK = MAX(MAXWRK,\n $ M*M+2*M+M*ILAENV(1,'CUNMQR','LN',M,M,M,-1))\n END IF\n ELSE\n*\n* Path 2t (N greater than M, but not much larger)\n*\n*\n MINWRK = 3*M + N\n MAXWRK = 2*M + (M+N)*ILAENV(1,'CGEBRD',' ',M,N,-1,-1)\n IF (WANTU .OR. WANTVT) THEN\n MAXWRK = MAX(MAXWRK,\n $ 2*M+M*ILAENV(1,'CUNMQR','LN',M,M,M,-1))\n END IF\n END IF\n END IF\n END IF\n MAXWRK = MAX( MAXWRK, MINWRK )\n WORK( 1 ) = CMPLX( REAL( MAXWRK ), ZERO )\n*\n IF( LWORK.LT.MINWRK .AND. .NOT.LQUERY ) THEN\n INFO = -19\n END IF\n END IF\n*\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'CGESVDX', -INFO )\n RETURN\n ELSE IF( LQUERY ) THEN\n RETURN\n END IF\n*\n* Quick return if possible\n*\n IF( M.EQ.0 .OR. N.EQ.0 ) THEN\n RETURN\n END IF\n*\n* Set singular values indices accord to RANGE='A'.\n*\n IF( ALLS ) THEN\n RNGTGK = 'I'\n ILTGK = 1\n IUTGK = MIN( M, N )\n ELSE IF( INDS ) THEN\n RNGTGK = 'I'\n ILTGK = IL\n IUTGK = IU\n ELSE\n RNGTGK = 'V'\n ILTGK = 0\n IUTGK = 0\n END IF\n*\n* Get machine constants\n*\n EPS = SLAMCH( 'P' )\n SMLNUM = SQRT( SLAMCH( 'S' ) ) / EPS\n BIGNUM = ONE / SMLNUM\n*\n* Scale A if max element outside range [SMLNUM,BIGNUM]\n*\n ANRM = CLANGE( 'M', M, N, A, LDA, DUM )\n ISCL = 0\n IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN\n ISCL = 1\n CALL CLASCL( 'G', 0, 0, ANRM, SMLNUM, M, N, A, LDA, INFO )\n ELSE IF( ANRM.GT.BIGNUM ) THEN\n ISCL = 1\n CALL CLASCL( 'G', 0, 0, ANRM, BIGNUM, M, N, A, LDA, INFO )\n END IF\n*\n IF( M.GE.N ) THEN\n*\n* A has at least as many rows as columns. If A has sufficiently\n* more rows than columns, first reduce A using the QR\n* decomposition.\n*\n IF( M.GE.MNTHR ) THEN\n*\n* Path 1 (M much larger than N):\n* A = Q * R = Q * ( QB * B * PB**T )\n* = Q * ( QB * ( UB * S * VB**T ) * PB**T )\n* U = Q * QB * UB; V**T = VB**T * PB**T\n*\n* Compute A=Q*R\n* (Workspace: need 2*N, prefer N+N*NB)\n*\n ITAU = 1\n ITEMP = ITAU + N\n CALL CGEQRF( M, N, A, LDA, WORK( ITAU ), WORK( ITEMP ),\n $ LWORK-ITEMP+1, INFO )\n*\n* Copy R into WORK and bidiagonalize it:\n* (Workspace: need N*N+3*N, prefer N*N+N+2*N*NB)\n*\n IQRF = ITEMP\n ITAUQ = ITEMP + N*N\n ITAUP = ITAUQ + N\n ITEMP = ITAUP + N\n ID = 1\n IE = ID + N\n ITGKZ = IE + N\n CALL CLACPY( 'U', N, N, A, LDA, WORK( IQRF ), N )\n CALL CLASET( 'L', N-1, N-1, CZERO, CZERO,\n $ WORK( IQRF+1 ), N )\n CALL CGEBRD( N, N, WORK( IQRF ), N, RWORK( ID ),\n $ RWORK( IE ), WORK( ITAUQ ), WORK( ITAUP ),\n $ WORK( ITEMP ), LWORK-ITEMP+1, INFO )\n ITEMPR = ITGKZ + N*(N*2+1)\n*\n* Solve eigenvalue problem TGK*Z=Z*S.\n* (Workspace: need 2*N*N+14*N)\n*\n CALL SBDSVDX( 'U', JOBZ, RNGTGK, N, RWORK( ID ),\n $ RWORK( IE ), VL, VU, ILTGK, IUTGK, NS, S,\n $ RWORK( ITGKZ ), N*2, RWORK( ITEMPR ),\n $ IWORK, INFO)\n*\n* If needed, compute left singular vectors.\n*\n IF( WANTU ) THEN\n K = ITGKZ\n DO I = 1, NS\n DO J = 1, N\n U( J, I ) = CMPLX( RWORK( K ), ZERO )\n K = K + 1\n END DO\n K = K + N\n END DO\n CALL CLASET( 'A', M-N, NS, CZERO, CZERO, U( N+1,1 ), LDU)\n*\n* Call CUNMBR to compute QB*UB.\n* (Workspace in WORK( ITEMP ): need N, prefer N*NB)\n*\n CALL CUNMBR( 'Q', 'L', 'N', N, NS, N, WORK( IQRF ), N,\n $ WORK( ITAUQ ), U, LDU, WORK( ITEMP ),\n $ LWORK-ITEMP+1, INFO )\n*\n* Call CUNMQR to compute Q*(QB*UB).\n* (Workspace in WORK( ITEMP ): need N, prefer N*NB)\n*\n CALL CUNMQR( 'L', 'N', M, NS, N, A, LDA,\n $ WORK( ITAU ), U, LDU, WORK( ITEMP ),\n $ LWORK-ITEMP+1, INFO )\n END IF\n*\n* If needed, compute right singular vectors.\n*\n IF( WANTVT) THEN\n K = ITGKZ + N\n DO I = 1, NS\n DO J = 1, N\n VT( I, J ) = CMPLX( RWORK( K ), ZERO )\n K = K + 1\n END DO\n K = K + N\n END DO\n*\n* Call CUNMBR to compute VB**T * PB**T\n* (Workspace in WORK( ITEMP ): need N, prefer N*NB)\n*\n CALL CUNMBR( 'P', 'R', 'C', NS, N, N, WORK( IQRF ), N,\n $ WORK( ITAUP ), VT, LDVT, WORK( ITEMP ),\n $ LWORK-ITEMP+1, INFO )\n END IF\n ELSE\n*\n* Path 2 (M at least N, but not much larger)\n* Reduce A to bidiagonal form without QR decomposition\n* A = QB * B * PB**T = QB * ( UB * S * VB**T ) * PB**T\n* U = QB * UB; V**T = VB**T * PB**T\n*\n* Bidiagonalize A\n* (Workspace: need 2*N+M, prefer 2*N+(M+N)*NB)\n*\n ITAUQ = 1\n ITAUP = ITAUQ + N\n ITEMP = ITAUP + N\n ID = 1\n IE = ID + N\n ITGKZ = IE + N\n CALL CGEBRD( M, N, A, LDA, RWORK( ID ), RWORK( IE ),\n $ WORK( ITAUQ ), WORK( ITAUP ), WORK( ITEMP ),\n $ LWORK-ITEMP+1, INFO )\n ITEMPR = ITGKZ + N*(N*2+1)\n*\n* Solve eigenvalue problem TGK*Z=Z*S.\n* (Workspace: need 2*N*N+14*N)\n*\n CALL SBDSVDX( 'U', JOBZ, RNGTGK, N, RWORK( ID ),\n $ RWORK( IE ), VL, VU, ILTGK, IUTGK, NS, S,\n $ RWORK( ITGKZ ), N*2, RWORK( ITEMPR ),\n $ IWORK, INFO)\n*\n* If needed, compute left singular vectors.\n*\n IF( WANTU ) THEN\n K = ITGKZ\n DO I = 1, NS\n DO J = 1, N\n U( J, I ) = CMPLX( RWORK( K ), ZERO )\n K = K + 1\n END DO\n K = K + N\n END DO\n CALL CLASET( 'A', M-N, NS, CZERO, CZERO, U( N+1,1 ), LDU)\n*\n* Call CUNMBR to compute QB*UB.\n* (Workspace in WORK( ITEMP ): need N, prefer N*NB)\n*\n CALL CUNMBR( 'Q', 'L', 'N', M, NS, N, A, LDA,\n $ WORK( ITAUQ ), U, LDU, WORK( ITEMP ),\n $ LWORK-ITEMP+1, IERR )\n END IF\n*\n* If needed, compute right singular vectors.\n*\n IF( WANTVT) THEN\n K = ITGKZ + N\n DO I = 1, NS\n DO J = 1, N\n VT( I, J ) = CMPLX( RWORK( K ), ZERO )\n K = K + 1\n END DO\n K = K + N\n END DO\n*\n* Call CUNMBR to compute VB**T * PB**T\n* (Workspace in WORK( ITEMP ): need N, prefer N*NB)\n*\n CALL CUNMBR( 'P', 'R', 'C', NS, N, N, A, LDA,\n $ WORK( ITAUP ), VT, LDVT, WORK( ITEMP ),\n $ LWORK-ITEMP+1, IERR )\n END IF\n END IF\n ELSE\n*\n* A has more columns than rows. If A has sufficiently more\n* columns than rows, first reduce A using the LQ decomposition.\n*\n IF( N.GE.MNTHR ) THEN\n*\n* Path 1t (N much larger than M):\n* A = L * Q = ( QB * B * PB**T ) * Q\n* = ( QB * ( UB * S * VB**T ) * PB**T ) * Q\n* U = QB * UB ; V**T = VB**T * PB**T * Q\n*\n* Compute A=L*Q\n* (Workspace: need 2*M, prefer M+M*NB)\n*\n ITAU = 1\n ITEMP = ITAU + M\n CALL CGELQF( M, N, A, LDA, WORK( ITAU ), WORK( ITEMP ),\n $ LWORK-ITEMP+1, INFO )\n\n* Copy L into WORK and bidiagonalize it:\n* (Workspace in WORK( ITEMP ): need M*M+3*M, prefer M*M+M+2*M*NB)\n*\n ILQF = ITEMP\n ITAUQ = ILQF + M*M\n ITAUP = ITAUQ + M\n ITEMP = ITAUP + M\n ID = 1\n IE = ID + M\n ITGKZ = IE + M\n CALL CLACPY( 'L', M, M, A, LDA, WORK( ILQF ), M )\n CALL CLASET( 'U', M-1, M-1, CZERO, CZERO,\n $ WORK( ILQF+M ), M )\n CALL CGEBRD( M, M, WORK( ILQF ), M, RWORK( ID ),\n $ RWORK( IE ), WORK( ITAUQ ), WORK( ITAUP ),\n $ WORK( ITEMP ), LWORK-ITEMP+1, INFO )\n ITEMPR = ITGKZ + M*(M*2+1)\n*\n* Solve eigenvalue problem TGK*Z=Z*S.\n* (Workspace: need 2*M*M+14*M)\n*\n CALL SBDSVDX( 'U', JOBZ, RNGTGK, M, RWORK( ID ),\n $ RWORK( IE ), VL, VU, ILTGK, IUTGK, NS, S,\n $ RWORK( ITGKZ ), M*2, RWORK( ITEMPR ),\n $ IWORK, INFO)\n*\n* If needed, compute left singular vectors.\n*\n IF( WANTU ) THEN\n K = ITGKZ\n DO I = 1, NS\n DO J = 1, M\n U( J, I ) = CMPLX( RWORK( K ), ZERO )\n K = K + 1\n END DO\n K = K + M\n END DO\n*\n* Call CUNMBR to compute QB*UB.\n* (Workspace in WORK( ITEMP ): need M, prefer M*NB)\n*\n CALL CUNMBR( 'Q', 'L', 'N', M, NS, M, WORK( ILQF ), M,\n $ WORK( ITAUQ ), U, LDU, WORK( ITEMP ),\n $ LWORK-ITEMP+1, INFO )\n END IF\n*\n* If needed, compute right singular vectors.\n*\n IF( WANTVT) THEN\n K = ITGKZ + M\n DO I = 1, NS\n DO J = 1, M\n VT( I, J ) = CMPLX( RWORK( K ), ZERO )\n K = K + 1\n END DO\n K = K + M\n END DO\n CALL CLASET( 'A', NS, N-M, CZERO, CZERO,\n $ VT( 1,M+1 ), LDVT )\n*\n* Call CUNMBR to compute (VB**T)*(PB**T)\n* (Workspace in WORK( ITEMP ): need M, prefer M*NB)\n*\n CALL CUNMBR( 'P', 'R', 'C', NS, M, M, WORK( ILQF ), M,\n $ WORK( ITAUP ), VT, LDVT, WORK( ITEMP ),\n $ LWORK-ITEMP+1, INFO )\n*\n* Call CUNMLQ to compute ((VB**T)*(PB**T))*Q.\n* (Workspace in WORK( ITEMP ): need M, prefer M*NB)\n*\n CALL CUNMLQ( 'R', 'N', NS, N, M, A, LDA,\n $ WORK( ITAU ), VT, LDVT, WORK( ITEMP ),\n $ LWORK-ITEMP+1, INFO )\n END IF\n ELSE\n*\n* Path 2t (N greater than M, but not much larger)\n* Reduce to bidiagonal form without LQ decomposition\n* A = QB * B * PB**T = QB * ( UB * S * VB**T ) * PB**T\n* U = QB * UB; V**T = VB**T * PB**T\n*\n* Bidiagonalize A\n* (Workspace: need 2*M+N, prefer 2*M+(M+N)*NB)\n*\n ITAUQ = 1\n ITAUP = ITAUQ + M\n ITEMP = ITAUP + M\n ID = 1\n IE = ID + M\n ITGKZ = IE + M\n CALL CGEBRD( M, N, A, LDA, RWORK( ID ), RWORK( IE ),\n $ WORK( ITAUQ ), WORK( ITAUP ), WORK( ITEMP ),\n $ LWORK-ITEMP+1, INFO )\n ITEMPR = ITGKZ + M*(M*2+1)\n*\n* Solve eigenvalue problem TGK*Z=Z*S.\n* (Workspace: need 2*M*M+14*M)\n*\n CALL SBDSVDX( 'L', JOBZ, RNGTGK, M, RWORK( ID ),\n $ RWORK( IE ), VL, VU, ILTGK, IUTGK, NS, S,\n $ RWORK( ITGKZ ), M*2, RWORK( ITEMPR ),\n $ IWORK, INFO)\n*\n* If needed, compute left singular vectors.\n*\n IF( WANTU ) THEN\n K = ITGKZ\n DO I = 1, NS\n DO J = 1, M\n U( J, I ) = CMPLX( RWORK( K ), ZERO )\n K = K + 1\n END DO\n K = K + M\n END DO\n*\n* Call CUNMBR to compute QB*UB.\n* (Workspace in WORK( ITEMP ): need M, prefer M*NB)\n*\n CALL CUNMBR( 'Q', 'L', 'N', M, NS, N, A, LDA,\n $ WORK( ITAUQ ), U, LDU, WORK( ITEMP ),\n $ LWORK-ITEMP+1, INFO )\n END IF\n*\n* If needed, compute right singular vectors.\n*\n IF( WANTVT) THEN\n K = ITGKZ + M\n DO I = 1, NS\n DO J = 1, M\n VT( I, J ) = CMPLX( RWORK( K ), ZERO )\n K = K + 1\n END DO\n K = K + M\n END DO\n CALL CLASET( 'A', NS, N-M, CZERO, CZERO,\n $ VT( 1,M+1 ), LDVT )\n*\n* Call CUNMBR to compute VB**T * PB**T\n* (Workspace in WORK( ITEMP ): need M, prefer M*NB)\n*\n CALL CUNMBR( 'P', 'R', 'C', NS, N, M, A, LDA,\n $ WORK( ITAUP ), VT, LDVT, WORK( ITEMP ),\n $ LWORK-ITEMP+1, INFO )\n END IF\n END IF\n END IF\n*\n* Undo scaling if necessary\n*\n IF( ISCL.EQ.1 ) THEN\n IF( ANRM.GT.BIGNUM )\n $ CALL SLASCL( 'G', 0, 0, BIGNUM, ANRM, MINMN, 1,\n $ S, MINMN, INFO )\n IF( ANRM.LT.SMLNUM )\n $ CALL SLASCL( 'G', 0, 0, SMLNUM, ANRM, MINMN, 1,\n $ S, MINMN, INFO )\n END IF\n*\n* Return optimal workspace in WORK(1)\n*\n WORK( 1 ) = CMPLX( REAL( MAXWRK ), ZERO )\n*\n RETURN\n*\n* End of CGESVDX\n*\n END\n", "meta": {"hexsha": "fbdb121ca78f42c30fe5e03f81a32b57fdbcd7be", "size": 28565, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "SRC/cgesvdx.f", "max_stars_repo_name": "sergey-v-kuznetsov/lapack", "max_stars_repo_head_hexsha": "799ef93faa5878aa8702f7cf9980cfc649cc39cc", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 998, "max_stars_repo_stars_event_min_datetime": "2016-05-04T20:50:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T17:43:13.000Z", "max_issues_repo_path": "SRC/cgesvdx.f", "max_issues_repo_name": "sergey-v-kuznetsov/lapack", "max_issues_repo_head_hexsha": "799ef93faa5878aa8702f7cf9980cfc649cc39cc", "max_issues_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_issues_count": 603, "max_issues_repo_issues_event_min_datetime": "2016-06-04T07:28:21.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T21:16:50.000Z", "max_forks_repo_path": "SRC/cgesvdx.f", "max_forks_repo_name": "sergey-v-kuznetsov/lapack", "max_forks_repo_head_hexsha": "799ef93faa5878aa8702f7cf9980cfc649cc39cc", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 373, "max_forks_repo_forks_event_min_datetime": "2016-06-04T06:05:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T17:25:45.000Z", "avg_line_length": 33.3703271028, "max_line_length": 112, "alphanum_fraction": 0.4418694206, "num_tokens": 8826, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533088603708, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6984888504938214}} {"text": "!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++!\n! \u00a0 Futility Development Group \u00a0\u00a0 !\n!\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0 All rights reserved.\u00a0\u00a0 \u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0 !\n!\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0 !\n! Futility is a jointly-maintained, open-source project between the University !\n! of Michigan and Oak Ridge National Laboratory.\u00a0 The copyright and license !\n! can be found in LICENSE.txt in the head directory of this repository. \u00a0\u00a0!\n!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++!\nMODULE testNonLinearSolverInterface\nUSE IntrType\nUSE VectorTypes\nUSE MatrixTypes\nUSE NonLinearSolverModule\n\nIMPLICIT NONE\nPRIVATE\n\nPUBLIC :: NonLinearSolverInterface_Test\n\n!Sets up a test interface to find the roots of the following system of equations:\n! 2*x1 + x1*x2 = 2\n! 2*x2 - x1*x2**2 = 2\n!The root occurs at x1 = 0.5, x2 = 2\nTYPE,EXTENDS(NonLinearSolverInterface_Base) :: NonLinearSolverInterface_Test\n CONTAINS\n PROCEDURE,PASS :: eval => eval_test\nENDTYPE NonLinearSolverInterface_Test\n\nCONTAINS\nSUBROUTINE eval_test(this,x,y)\n CLASS(NonLinearSolverInterface_Test),INTENT(IN) :: this\n CLASS(VectorType),INTENT(INOUT) :: x\n CLASS(VectorType),INTENT(INOUT) :: y\n !\n REAL(SRK) :: xreal(2)\n\n CALL x%getAll(xreal)\n CALL y%set((/2.0_SRK*xreal(1) + xreal(1)*xreal(2) - 2.0_SRK, & ! 2*x1 + x1*x2 -2\n 2.0_SRK*xreal(2) - xreal(1)*xreal(2)**2.0_SRK - 2.0_SRK/)) ! 2*x2 - x1*x2**2 -2\n\nENDSUBROUTINE eval_test\nENDMODULE testNonLinearSolverInterface\n!\nPROGRAM testNonLinearSolver\n#include \"UnitTest.h\"\nUSE UnitTest\nUSE IntrType\nUSE ParameterLists\nUSE FutilityComputingEnvironmentModule\nUSE VectorTypes\nUSE MatrixTypes\nUSE LinearSolverTypes\nUSE NonLinearSolverModule\nUSE testNonLinearSolverInterface\n\nIMPLICIT NONE\n\nTYPE(FutilityComputingEnvironment),TARGET :: ce\nTYPE(NonLinearSolverInterface_Test),TARGET :: ftest\nTYPE(NonLinearSolver_Native) :: nativeSolver\n\nCALL setupTest()\nCREATE_TEST(\"testNonLinearSolver\")\n\nREGISTER_SUBTEST('Native, Newton''s Method',testNativeNewton)\n\nFINALIZE_TEST()\nCALL clearTest()\n!\n!===============================================================================\nCONTAINS\n!\n!-------------------------------------------------------------------------------\nSUBROUTINE testNativeNewton()\n REAL(SRK) :: refsol(2)=(/0.5_SRK,2.0_SRK/),testsol(2)\n TYPE(ParamType) :: plist\n TYPE(RealVectorType) :: x\n TYPE(LinearSolverType_Direct) :: refLS\n CLASS(LinearSolverType_Base),ALLOCATABLE :: testLS\n\n CALL plist%add('NonLinearSolver -> n',2)\n CALL plist%add('NonLinearSolver -> method',NLSOLVER_METHOD_NEWTON)\n CALL plist%add('NonLinearSolver -> tolerance',1.0E-14_SRK)\n CALL nativeSolver%init(ce,ftest,plist)\n CALL plist%clear()\n\n COMPONENT_TEST('InitBase')\n ASSERT_EQ(testSolverMethod(nativeSolver),NLSOLVER_METHOD_NEWTON,'%solverMethod')\n ASSERT_EQ(testN(nativeSolver),2,'%n')\n ASSERT_EQ(testIterations(nativeSolver),-1,'%iterations')\n ASSERT_EQ(testTol(nativeSolver),1.0E-14_SRK,'%tol')\n ASSERT(ASSOCIATED(testCE(nativeSolver)),'%ce')\n ASSERT(ASSOCIATED(testFunc(nativeSolver)),'%func')\n\n COMPONENT_TEST('Init')\n ASSERT_EQ(testTPLType(nativeSolver),NLSOLVER_TPL_NATIVE,'%TPLType')\n CALL testLinSys(nativeSolver,testLS)\n ASSERT(testLS%isInit,'%linSys')\n ASSERT(SAME_TYPE_AS(refLS,testLS),'%linSys dynamic type')\n DEALLOCATE(testLS)\n ASSERT(nativeSolver%isInit,'%isInit')\n\n CALL plist%add('VectorType -> n',2)\n CALL x%init(plist)\n CALL plist%clear()\n\n COMPONENT_TEST('Solve')\n CALL x%set((/0.0_SRK,0.0_SRK/))\n CALL nativeSolver%solve(x)\n CALL x%get(testsol)\n ASSERT_APPROXEQ(testsol(1),refsol(1),'solution(1)')\n ASSERT_APPROXEQ(testsol(2),refsol(2),'solution(2)')\n ASSERT_EQ(testIterations(nativeSolver),7,'%iterations')\n CALL x%clear()\n\n CALL nativeSolver%clear()\n\n COMPONENT_TEST('ClearBase')\n ASSERT_EQ(testSolverMethod(nativeSolver),-1,'%solverMethod')\n ASSERT_EQ(testTPLType(nativeSolver),-1,'%TPLType')\n ASSERT_EQ(testN(nativeSolver),-1,'%n')\n ASSERT_EQ(testIterations(nativeSolver),-1,'%iterations')\n ASSERT_EQ(testTol(nativeSolver),1.0E-5_SRK,'%tol')\n CALL testLinSys(nativeSolver,testLS)\n ASSERT(.NOT.ALLOCATED(testLS),'%linSys')\n ASSERT(.NOT.ASSOCIATED(testCE(nativeSolver)),'%ce')\n ASSERT(.NOT.ASSOCIATED(testFunc(nativeSolver)),'ASSOCIATED %func')\n ASSERT(.NOT.nativeSolver%isInit,'%isInit')\n\nENDSUBROUTINE testNativeNewton\n!\n!-------------------------------------------------------------------------------\nSUBROUTINE setupTest()\n\n ALLOCATE(ce%exceptHandler)\n ALLOCATE(ce%parEnv)\n\nENDSUBROUTINE setupTest\n!\n!-------------------------------------------------------------------------------\nSUBROUTINE clearTest()\n\n DEALLOCATE(ce%exceptHandler)\n CALL ce%parEnv%world%finalize()\n DEALLOCATE(ce%parEnv)\n\nENDSUBROUTINE clearTest\n!\nENDPROGRAM testNonLinearSolver", "meta": {"hexsha": "9a023c71f32eec906bd4312fdc793d132438769d", "size": 4897, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "unit_tests/testNonLinearSolver/testNonLinearSolver.f90", "max_stars_repo_name": "picmc/Futility", "max_stars_repo_head_hexsha": "158950c2c3aceffedf547ed4ea777e023035ca6e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 36, "max_stars_repo_stars_event_min_datetime": "2017-02-26T01:17:46.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-02T07:15:07.000Z", "max_issues_repo_path": "unit_tests/testNonLinearSolver/testNonLinearSolver.f90", "max_issues_repo_name": "picmc/Futility", "max_issues_repo_head_hexsha": "158950c2c3aceffedf547ed4ea777e023035ca6e", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 183, "max_issues_repo_issues_event_min_datetime": "2017-03-30T20:14:44.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-03T21:34:06.000Z", "max_forks_repo_path": "unit_tests/testNonLinearSolver/testNonLinearSolver.f90", "max_forks_repo_name": "wgurecky/Futility", "max_forks_repo_head_hexsha": "cd7831395c7c56adcbbc5be38773d2e850c6b5b6", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2017-06-29T17:13:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-16T08:05:59.000Z", "avg_line_length": 32.8657718121, "max_line_length": 85, "alphanum_fraction": 0.6552991628, "num_tokens": 1335, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473846343394, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.698481571851604}} {"text": "SUBROUTINE fmdsig(dee,e,v)\r\n!\r\n! This subroutine returns the elastic dee matrix for ih=3 (plane stress),\r\n!\r\n IMPLICIT NONE\r\n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\r\n REAL(iwp),INTENT(IN)::e,v\r\n REAL(iwp),INTENT(OUT)::dee(:,:)\r\n REAL(iwp)::zero=0.0_iwp,pt5=0.5_iwp,one=1.0_iwp\r\n INTEGER::ih\r\n dee=zero \r\n ih=UBOUND(dee,1)\r\n SELECT CASE(ih)\r\n CASE(3)\r\n dee=zero\r\n dee(1,1)=e/(one-v*v)\r\n dee(2,2)=dee(1,1)\r\n dee(3,3)=pt5*e/(one+v)\r\n dee(1,2)=v*dee(1,1)\r\n dee(2,1)=dee(1,2)\r\n CASE DEFAULT\r\n WRITE(*,*)'wrong size for dee matrix'\r\n END SELECT\r\nRETURN\r\nEND SUBROUTINE fmdsig \r\n", "meta": {"hexsha": "da0158df5b46347d66ffd8defba9103e830998e0", "size": 596, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "src/libs/main/fmdsig.f03", "max_stars_repo_name": "leemargetts/PoreFEM", "max_stars_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/libs/main/fmdsig.f03", "max_issues_repo_name": "leemargetts/PoreFEM", "max_issues_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/libs/main/fmdsig.f03", "max_forks_repo_name": "leemargetts/PoreFEM", "max_forks_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.9230769231, "max_line_length": 74, "alphanum_fraction": 0.6342281879, "num_tokens": 228, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299612154571, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6984699589188067}} {"text": "! { dg-do compile }\n! Test the fix for PR43843, in which the temporary for b(1) in\n! test_member was an indirect reference, rather then the value.\n!\n! Contributed by Kyle Horne \n! Reported by Tobias Burnus \n! Reported by Harald Anlauf (PR43841)\n!\nmodule polar_mod\n implicit none\n complex, parameter :: i = (0.0,1.0)\n real, parameter :: pi = 3.14159265359\n real, parameter :: e = exp (1.0)\n type :: polar_t\n real :: l, th\n end type\n type(polar_t) :: one = polar_t (1.0, 0)\n interface operator(/)\n module procedure div_pp\n end interface\n interface operator(.ne.)\n module procedure ne_pp\n end interface\ncontains\n elemental function div_pp(u,v) result(o)\n type(polar_t), intent(in) :: u, v\n type(polar_t) :: o\n complex :: a, b, c\n a = u%l*exp (i*u%th*pi)\n b = v%l*exp (i*v%th*pi)\n c = a/b\n o%l = abs (c)\n o%th = atan2 (imag (c), real (c))/pi\n end function div_pp\n elemental function ne_pp(u,v) result(o)\n type(polar_t), intent(in) :: u, v\n LOGICAL :: o\n if (u%l .ne. v%l) then\n o = .true.\n else if (u%th .ne. v%th) then\n o = .true.\n else\n o = .false.\n end if\n end function ne_pp\nend module polar_mod\n\nprogram main\n use polar_mod\n implicit none\n call test_member\n call test_other\n call test_scalar\n call test_real\ncontains\n subroutine test_member\n type(polar_t), dimension(3) :: b\n b = polar_t (2.0,0.5)\n b(:) = b(:)/b(1)\n if (any (b .ne. one)) call abort \n end subroutine test_member\n subroutine test_other\n type(polar_t), dimension(3) :: b\n type(polar_t), dimension(3) :: c\n b = polar_t (3.0,1.0)\n c = polar_t (3.0,1.0)\n b(:) = b(:)/c(1)\n if (any (b .ne. one)) call abort \n end subroutine test_other\n subroutine test_scalar\n type(polar_t), dimension(3) :: b\n type(polar_t) :: c\n b = polar_t (4.0,1.5)\n c = b(1)\n b(:) = b(:)/c\n if (any (b .ne. one)) call abort \n end subroutine test_scalar\n subroutine test_real\n real,dimension(3) :: b\n real :: real_one\n b = 2.0\n real_one = b(2)/b(1)\n b(:) = b(:)/b(1)\n if (any (b .ne. real_one)) call abort \n end subroutine test_real\nend program main\n! { dg-final { cleanup-modules \"polar_mod\" } }\n", "meta": {"hexsha": "d180bc931d293e2349ca1e61fc99e068e4e71897", "size": 2256, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/elemental_scalar_args_1.f90", "max_stars_repo_name": "maurizioabba/rose", "max_stars_repo_head_hexsha": "7597292cf14da292bdb9a4ef573001b6c5b9b6c0", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/elemental_scalar_args_1.f90", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/elemental_scalar_args_1.f90", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 25.6363636364, "max_line_length": 63, "alphanum_fraction": 0.6121453901, "num_tokens": 780, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310357, "lm_q2_score": 0.8104789063814616, "lm_q1q2_score": 0.6982585457855084}} {"text": "program monte_carlo_pi\n use iso_fortran_env, only : team_type, STAT_FAILED_IMAGE\n implicit none\n integer, parameter :: NFAIL=2, NSAMPLES=10**6\n integer :: sample, status, n_copy, n = 0\n type(team_type) :: team_active_images\n logical :: fail\n double precision :: x, y\n ! gfortran 9.x doesn't support NUM_IMAGES([TEAM])\n integer :: num_images_initial_team, image_index_in_active_team\n \n call random_init(repeatable=.true., image_distinct=.true.)\n \n do sample = 1, NSAMPLES\n call random_number(x); call random_number(y)\n if (hypot(x, y) <= 1) n = n + 1\n end do\n\n num_images_initial_team = num_images()\n n_copy = n\n \n do\n form team(1, team_active_images, stat=status)\n change team (team_active_images, stat=status)\n ! FORM TEAM NEW_INDEX= specifier not used; image index in team_active_images is processor-dependent\n image_index_in_active_team = this_image()\n if (num_images_initial_team - num_images() < NFAIL .and. this_image() == num_images()) fail image\n call co_sum(n, result_image = 1, stat=status)\n end team (stat=status)\n if (status /= STAT_FAILED_IMAGE) exit\n ! else value of n is undefined; restore from copy\n n = n_copy\n end do\n \n if (image_index_in_active_team == 1) then\n write(*,*) (4.0d0 * n / NSAMPLES) / (num_images() - size(failed_images()))\n end if\nend program monte_carlo_pi\n", "meta": {"hexsha": "d8ac9c3447837e41e983e74796800b7ec9e25138", "size": 1360, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/monte_carlo_pi-1.f90", "max_stars_repo_name": "nathanweeks/espm2-2020", "max_stars_repo_head_hexsha": "e541ecbe761fe8b9351d376ddba05634a74fe34d", "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": "test/monte_carlo_pi-1.f90", "max_issues_repo_name": "nathanweeks/espm2-2020", "max_issues_repo_head_hexsha": "e541ecbe761fe8b9351d376ddba05634a74fe34d", "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": "test/monte_carlo_pi-1.f90", "max_forks_repo_name": "nathanweeks/espm2-2020", "max_forks_repo_head_hexsha": "e541ecbe761fe8b9351d376ddba05634a74fe34d", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.8717948718, "max_line_length": 105, "alphanum_fraction": 0.7029411765, "num_tokens": 388, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381952105442, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.698258532288159}} {"text": "FUNCTION equa_time(idoy)\n!\nIMPLICIT NONE\n!\nINCLUDE 'p1unconv.inc'\n!\n! Function arguments\n!\nINTEGER :: idoy\nREAL :: equa_time\n!\n! Local variables\n!\nREAL :: b\n!\n! + + + purpose + + +\n! this function calculates the declination of the earth with respect\n! the sun based on the day of the year\n \n! + + + keywords + + +\n! solar equation of time\n \n! + + + argument declarations + + +\n \n! + + + argument definitions + + +\n! idoy - day of year\n \n! + + + local variables + + +\n \n! + + + local definitions + + +\n! b - sub calculation (time of year, radians)\n \n! + + + common blocks + + +\n \n! + + + end specifications + + +\n \n! calculate time of year (b)\nb = (360.0/365.0)*(idoy-81.25)*degtorad !h-55\nequa_time = 9.87*sin(2*b) - 7.53*cos(b) - 1.5*sin(b) !h-54\n! \nEND FUNCTION equa_time\n", "meta": {"hexsha": "10a83f9816140444d6e40a8a95d356e5277a20cb", "size": 880, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Project Documents/Source Code Original/Equa_time.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/Equa_time.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/Equa_time.f90", "max_forks_repo_name": "USDA-ARS-WMSRU/upgm-standalone", "max_forks_repo_head_hexsha": "1ae5dee5fe2cdba97b69c19d51b1cf61ceeab3d7", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.9523809524, "max_line_length": 77, "alphanum_fraction": 0.5386363636, "num_tokens": 269, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422213778251, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6982520831055268}} {"text": "*+CEL_CARTS\n subroutine CEL_CARTS( ra, dec, vector )\n\n implicit none\n\n double precision deg2rad\n parameter( deg2rad = 0.01745329252D+00 )\n\n double precision ra, dec\n double precision vector( 3 )\n\n* Description:\n* Given RA and Dec, returns the 3-d vector\n*\n* Arguments:\n* ra (i) : input RA (decimal hours)\n* dec (i) : input Dec\n* vector (o) : 3-d vector\n*\n* Dependencies:\n* Assumes the presence of trig functions on degrees on the system\n*\n* Origin:\n* Conceived as a part of the 3-d vector routines\n*\n* Author:\n* Koji Mukai, 1993 Mar 15, Original version\n*-CEL_CARTS\n\n double precision cos_dec, ra_rad, dec_rad\n\n\tdec_rad = dec * deg2rad\n cos_dec = cos( dec_rad )\n ra_rad = ra * 1.5d+01 * deg2rad\n vector( 1 ) = cos_dec * cos( ra_rad )\n vector( 2 ) = cos_dec * sin( ra_rad )\n vector( 3 ) = sin( dec_rad )\n\n end\n\n*+ECL_CARTS\n subroutine ECL_CARTS( lambda, beta, vector )\n\n implicit none\n\n double precision deg2rad\n parameter( deg2rad = 0.01745329252D+00 )\n\n double precision lambda, beta\n double precision vector( 3 )\n\n* Description:\n* Given ecliptic longitude and latitude, returns the 3-d vector\n*\n* Arguments:\n* ra (i) : input RA (decimal hours)\n* dec (i) : input Dec\n* vector (o) : 3-d vector\n*\n* Dependencies:\n* Assumes the presence of trig functions on degrees on the system\n*\n* Origin:\n* Conceived as a part of the 3-d vector routines\n*\n* Author:\n* Koji Mukai, 1993 Mar 15, Original version\n*-CEL_CARTS\n\n double precision cos_beta, lambda_rad, beta_rad\n\n\tbeta_rad = beta * deg2rad\n cos_beta = cos( beta_rad )\n lambda_rad = lambda * deg2rad\n vector( 1 ) = cos_beta * cos( lambda_rad )\n vector( 2 ) = cos_beta * sin( lambda_rad )\n vector( 3 ) = sin( beta_rad )\n\n end\n\n*+VEC_ANGLE\n double precision function VEC_ANGLE( vector1, vector2 )\n\n implicit none\n\n double precision rad2deg\n\tparameter( rad2deg = 57.29577951D+00 )\n\n double precision vector1( 3 ), vector2( 3 )\n\n* Description:\n* Angle between two cartesian vectors\n*\n* Arguments:\n* vector1, vector2 (i) : two input Cartesian vectors\n* (r) : Angle between the two\n*\n* Dependencies:\n* Assumes the presence of trig functions on degrees on the system\n*\n* Origin:\n* Conceived as a part of the 3-d vector routines\n*\n* Author:\n* Koji Mukai, 1993 Mar 15, Original version\n*-VEC_ANGLE\n\n double precision inner, temp, work\n integer j\n\n inner = 0.0d+00\n do j = 1, 3\n inner = inner + vector1( j ) * vector2( j )\n end do\n\n if( inner .gt. 0.71d+00 ) then\n* Use sine, which is more accurate in this regime\n* Length( vector1 - vector2 ) * 0.5 = sin( angle * 0.5 )\n* (Cosine of small x is ~1.0-x^2/2, whereas sin x ~ x)\n temp = 0.0\n do j = 1, 3\n work = vector1( j ) - vector2( j )\n temp = temp + work * work\n end do\n temp = sqrt( temp ) * 0.5d+00\n VEC_ANGLE = asin( temp ) * 2.0d+00 * rad2deg\n else if( inner .ge. -0.71d+00 ) then\n* Use the more familiar cosine formula\n VEC_ANGLE = acos( inner ) * rad2deg\n else\n* Back to sine, but two vectors are ~180 degrees apart\n temp = 0.0\n do j = 1, 3\n work = vector1( j ) + vector2( j )\n temp = temp + work * work\n end do\n temp = sqrt( temp ) * 0.5d+00\n VEC_ANGLE = 1.8d+02 - asin( temp ) * 2.0d+00 * rad2deg\n end if\n\n end\n\n*+VEC_PRDCT\n subroutine VEC_PRDCT( vector1, vector2, vector3 )\n\n implicit none\n\n double precision vector1( 3 ), vector2( 3 ), vector3( 3 )\n\n* Description:\n* Calculates product of two vectors\n*\n* Arguments:\n* vector1, vector2 (i) : two input Cartesian vectors\n* vector3 (o) : product of the two input vectors\n*\n* Dependencies:\n* None\n*\n* Origin:\n* Conceived as a part of the 3-d vector routines\n*\n* Author:\n* Koji Mukai, 1993 Mar 15, Original version\n*-VEC_PRDCT\n\n integer i, j, k\n\n do i = 1, 3\n j = i + 1\n if( j .eq. 4 ) j = 1\n k = j + 1\n if( k .eq. 4 ) k = 1\n vector3( i ) = vector1( j ) * vector2( k )\n & - vector1( k ) * vector2( j )\n end do\n\n end\n\n*+VEC_RENRM\n subroutine VEC_RENRM( vector )\n\n implicit none\n\n double precision vector( 3 )\n\n* Description:\n* Renormalizes a Cartesian vector\n*\n* Arguments:\n* vector (i/o) : Cartesian vector to be renormalized\n*\n* Dependencies:\n* None\n*\n* Origin:\n* Conceived as a part of the 3-d vector routines\n*\n* Author:\n* Koji Mukai, 1993 Mar 15, Original version\n*-VEC_RENRM\n\n double precision temp\n integer j\n\n temp = 0.0d+00\n do j = 1, 3\n temp = temp + vector( j ) * vector( j )\n end do\n temp = 1.0d+00 / sqrt( temp )\n do j = 1, 3\n vector( j ) = vector( j ) * temp\n end do\n\n end\n", "meta": {"hexsha": "89f7f64c6fc1c5be5b8e0dd112c98abfd1bb670c", "size": 5502, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tvguide/cartesian.f", "max_stars_repo_name": "barentsen/tvguide", "max_stars_repo_head_hexsha": "5abefada3f11885e4816f46cc78382f124372492", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tvguide/cartesian.f", "max_issues_repo_name": "barentsen/tvguide", "max_issues_repo_head_hexsha": "5abefada3f11885e4816f46cc78382f124372492", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tvguide/cartesian.f", "max_forks_repo_name": "barentsen/tvguide", "max_forks_repo_head_hexsha": "5abefada3f11885e4816f46cc78382f124372492", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-10-04T18:58:13.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-04T18:58:13.000Z", "avg_line_length": 25.4722222222, "max_line_length": 73, "alphanum_fraction": 0.5308978553, "num_tokens": 1588, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505376715775, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.698248640066237}} {"text": " FUNCTION probks(alam)\r\n REAL probks,alam,EPS1,EPS2\r\n PARAMETER (EPS1=0.001, EPS2=1.e-8)\r\n INTEGER j\r\n REAL a2,fac,term,termbf\r\n a2=-2.*alam**2\r\n fac=2.\r\n probks=0.\r\n termbf=0.\r\n do 11 j=1,100\r\n term=fac*exp(a2*j**2)\r\n probks=probks+term\r\n if(abs(term).le.EPS1*termbf.or.abs(term).le.EPS2*probks)return\r\n fac=-fac\r\n termbf=abs(term)\r\n11 continue\r\n probks=1.\r\n return\r\n END\r\n", "meta": {"hexsha": "ff90e3e90f67ea2fa22b5ac150b59c96205583f9", "size": 477, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/probks.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/probks.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/probks.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.85, "max_line_length": 71, "alphanum_fraction": 0.5220125786, "num_tokens": 170, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6982486293659257}} {"text": "PROGRAM nr\ninteger :: i\nreal :: x, f, df\nwrite(*,*) \"ENter x0 \"\nread (*,*) x \nwrite (*,*) 'Initial value: x=',x\n\n do i=1,100\n f= x**3 - 8*x - 4\n df = 3*(x**2) - 8\n write (*,*) i,x,f,df\n x = x-f/df\n end do\n\n write (*,*) '#x = ',x\n End PROGRAM nr\n", "meta": {"hexsha": "36a87cc8dac89e4887ad8d07a1a344dec2bc4926", "size": 272, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Newton-Raphson.f", "max_stars_repo_name": "Sayan3990/Fortran", "max_stars_repo_head_hexsha": "8e138157be0ffc2e0a7afb9e6a3f901b802434d8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-08-14T02:14:36.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-14T03:45:52.000Z", "max_issues_repo_path": "Newton-Raphson.f", "max_issues_repo_name": "Sayan3990/Fortran", "max_issues_repo_head_hexsha": "8e138157be0ffc2e0a7afb9e6a3f901b802434d8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Newton-Raphson.f", "max_forks_repo_name": "Sayan3990/Fortran", "max_forks_repo_head_hexsha": "8e138157be0ffc2e0a7afb9e6a3f901b802434d8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-08-14T03:45:53.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-14T03:45:53.000Z", "avg_line_length": 16.0, "max_line_length": 33, "alphanum_fraction": 0.4375, "num_tokens": 115, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9046505351008904, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6982486285864549}} {"text": "program complex2\ncomplex :: x\nx = (3.0, 4.0)\nx = x/4.0\nprint *, x\nx = 2/x\nprint *, x\nx = 1/(x + (0.0, 3.0))\nprint *, x\nend program\n", "meta": {"hexsha": "08b5183e52b6e1a238ed3ba347af6feab682a0ae", "size": 131, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "integration_tests/complex_div_test.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/complex_div_test.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/complex_div_test.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": 11.9090909091, "max_line_length": 22, "alphanum_fraction": 0.534351145, "num_tokens": 66, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9046505402422645, "lm_q2_score": 0.7718434873426302, "lm_q1q2_score": 0.6982486278069839}} {"text": " subroutine get_diurnal_sst_models(rgeo,wnd,precip,diurnal_sst,diurnal_sst2,diurnal_sst3)\r\n implicit none\r\n\r\nc\tc.gentemann gentemann@remss.com 6/2009\r\n\r\nc\treturns diurnal_sst = webster96\r\nc\t\t\tdiurnal_sst2=kk02 skin\r\nc\t\t\tdiurnal_sst3=kk02 bulk\r\n real(4), parameter :: pi=3.141592654\r\n\treal(4), parameter :: solar_constant=1360 !watts/m**2\r\n\treal(4) wnd,precip,peak_solar,rgeo\r\n real(4) diurnal_sst\r\n real(4) a0,b0,c0,d0,e0,f0\t \r\n\treal diurnal_sst2,diurnal_sst3\r\n\r\nc calculate solar insolation\r\n \r\n\tpeak_solar=rgeo\r\nc\tclayson\r\n\tif(wnd>2)then\r\n\ta0=0.00265\r\n\tb0=0.028\r\n\tc0=-0.838\r\n\td0=-0.00105\r\n\te0=0.158\r\n\tf0=0.262\r\n else\r\n\ta0=0.002\r\n\tb0=0.041\r\n\tc0=0.212\r\n\td0=-0.000185\r\n\te0=-0.329\r\n\tf0=0.328\r\n\tendif\r\n\r\n\tif(wnd<.01)wnd=.01\r\n\tdiurnal_sst=f0+a0*peak_solar+b0*precip+c0*log(wnd)+d0*peak_solar*log(wnd)+e0*wnd\r\n\tif(rgeo<=0)diurnal_sst=0\r\n\r\nc skin algorithm kk02\r\ncu>2.5ms-1\t3.2708x10-6\t-0.079982\t-1.3329x10-6 \t0.073287\r\ncu<=2.5ms-1\t5.6814x10-6 \t0.40052\t-3.9637x10-6 \t-0.367\r\n\tif(wnd>2.5)then\r\n\ta0=3.2708e-6\r\n\tb0=-0.079982\r\n\tc0=-1.3329e-6\r\n\td0=0.073287\r\nc\ta0=0.000003049;b0=-0.028258;c0=-0.0000011987;d0=-.025893\r\n else\r\n\ta0=5.6814e-6\r\n\tb0=0.40052\r\n\tc0=-3.9637e-6\r\n\td0=-0.367\r\nc\ta0=0.0000050109;b0=0.22063;c0=-0.0000033394;d0=-0.20216\r\n\tendif\r\n\tdiurnal_sst2=a0*peak_solar**2+b0*log(wnd)+c0*peak_solar**2*log(wnd)+d0\r\n\tif(diurnal_sst2<0)diurnal_sst2=0;\r\n\tif(rgeo<=0)diurnal_sst2=0\r\n\r\nc bulk algorithm kko2\r\nc\tu>2.5ms-1\t2.3989x10-6\t0.057289\t-9.2463x10-7 \t-0.14236\r\nc\tu<=2.5ms-1\t1.9361x10-6 \t0.014576\t-4.1966x10-7 \t-.10322\r\n\r\n\tif(wnd>2.5)then\r\n\ta0=2.3989e-6\r\n\tb0=0.057289\r\n\tc0=-9.2463e-7\r\n\td0=-0.14236\r\n else\r\n\ta0=1.9361e-6\r\n\tb0=0.014576\r\n\tc0=-4.1966e-7\r\n\td0=-.10322\r\n\tendif\r\n\tdiurnal_sst3=a0*peak_solar**2+b0*log(wnd)+c0*peak_solar**2*log(wnd)+d0\r\n\tif(diurnal_sst3<0)diurnal_sst3=0;\r\n\tif(rgeo<=0)diurnal_sst3=0\r\n\r\n\tRETURN\r\n\tEND\r\n", "meta": {"hexsha": "f125f0ae34b17a594c39f6b46ac58b4420e640a6", "size": 1866, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "subroutines/get_diurnal_clayson2.f", "max_stars_repo_name": "cgentemann/posh_diurnal_model_fortran", "max_stars_repo_head_hexsha": "227fbea81016da29c3925a65fc2b3dcb5958e822", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-10-05T12:34:07.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-05T12:34:07.000Z", "max_issues_repo_path": "subroutines/get_diurnal_clayson2.f", "max_issues_repo_name": "cgentemann/posh_diurnal_model_fortran", "max_issues_repo_head_hexsha": "227fbea81016da29c3925a65fc2b3dcb5958e822", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "subroutines/get_diurnal_clayson2.f", "max_forks_repo_name": "cgentemann/posh_diurnal_model_fortran", "max_forks_repo_head_hexsha": "227fbea81016da29c3925a65fc2b3dcb5958e822", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.037037037, "max_line_length": 95, "alphanum_fraction": 0.6698821008, "num_tokens": 922, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475730993028, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.6982416935066006}} {"text": "SUBROUTINE gcf(gammcf,a,x,gln)\r\nINTEGER*4 ITMAX\r\nREAL*8 a,gammcf,gln,x,EPS,FPMIN\r\nPARAMETER (ITMAX=100,EPS=3.d-7,FPMIN=1.d-30)\r\n!CU USES gammln\r\nINTEGER*4 i\r\nREAL*8 an,b,c,d,del,h,gammln\r\nEXTERNAL gammln\r\ngln=gammln(a)\r\nb=x+1.-a\r\nc=1./FPMIN\r\nd=1./b\r\nh=d\r\ndo i=1,ITMAX\r\n\tan=-i*(i-a)\r\n\tb=b+2.\r\n\td=an*d+b\r\n\tif(abs(d).lt.FPMIN)d=FPMIN\r\n\tc=b+an/c\r\n\tif(abs(c).lt.FPMIN)c=FPMIN\r\n\td=1./d\r\n\tdel=d*c\r\n\th=h*del\r\n\tif(abs(del-1.).lt.EPS)goto 1\r\nend do\r\npause 'a too large, ITMAX too small in gcf'\r\n1 gammcf=exp(-x+a*log(x)-gln)*h\r\nreturn\r\nEND\r\n", "meta": {"hexsha": "b738f3c17a22432b798e0bb304bab30430033bdd", "size": 538, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "11/mathlib/gcf.f90", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "11/mathlib/gcf.f90", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "11/mathlib/gcf.f90", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.9333333333, "max_line_length": 45, "alphanum_fraction": 0.626394052, "num_tokens": 249, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797172476385, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6982312250357275}} {"text": "module stdlib_linalg\n !!Provides a support for various linear algebra procedures\n !! ([Specification](../page/specs/stdlib_linalg.html))\n use stdlib_kinds, only: sp, dp, qp, &\n int8, int16, int32, int64\n use stdlib_optval, only: optval\n implicit none\n private\n\n public :: diag\n public :: eye\n public :: trace\n public :: outer_product\n\n interface diag\n !! version: experimental\n !!\n !! Creates a diagonal array or extract the diagonal elements of an array\n !! ([Specification](../page/specs/stdlib_linalg.html#description))\n !\n ! Vector to matrix\n !\n module function diag_rsp(v) result(res)\n real(sp), intent(in) :: v(:)\n real(sp) :: res(size(v),size(v))\n end function diag_rsp\n module function diag_rdp(v) result(res)\n real(dp), intent(in) :: v(:)\n real(dp) :: res(size(v),size(v))\n end function diag_rdp\n module function diag_rqp(v) result(res)\n real(qp), intent(in) :: v(:)\n real(qp) :: res(size(v),size(v))\n end function diag_rqp\n module function diag_csp(v) result(res)\n complex(sp), intent(in) :: v(:)\n complex(sp) :: res(size(v),size(v))\n end function diag_csp\n module function diag_cdp(v) result(res)\n complex(dp), intent(in) :: v(:)\n complex(dp) :: res(size(v),size(v))\n end function diag_cdp\n module function diag_cqp(v) result(res)\n complex(qp), intent(in) :: v(:)\n complex(qp) :: res(size(v),size(v))\n end function diag_cqp\n module function diag_iint8(v) result(res)\n integer(int8), intent(in) :: v(:)\n integer(int8) :: res(size(v),size(v))\n end function diag_iint8\n module function diag_iint16(v) result(res)\n integer(int16), intent(in) :: v(:)\n integer(int16) :: res(size(v),size(v))\n end function diag_iint16\n module function diag_iint32(v) result(res)\n integer(int32), intent(in) :: v(:)\n integer(int32) :: res(size(v),size(v))\n end function diag_iint32\n module function diag_iint64(v) result(res)\n integer(int64), intent(in) :: v(:)\n integer(int64) :: res(size(v),size(v))\n end function diag_iint64\n module function diag_rsp_k(v,k) result(res)\n real(sp), intent(in) :: v(:)\n integer, intent(in) :: k\n real(sp) :: res(size(v)+abs(k),size(v)+abs(k))\n end function diag_rsp_k\n module function diag_rdp_k(v,k) result(res)\n real(dp), intent(in) :: v(:)\n integer, intent(in) :: k\n real(dp) :: res(size(v)+abs(k),size(v)+abs(k))\n end function diag_rdp_k\n module function diag_rqp_k(v,k) result(res)\n real(qp), intent(in) :: v(:)\n integer, intent(in) :: k\n real(qp) :: res(size(v)+abs(k),size(v)+abs(k))\n end function diag_rqp_k\n module function diag_csp_k(v,k) result(res)\n complex(sp), intent(in) :: v(:)\n integer, intent(in) :: k\n complex(sp) :: res(size(v)+abs(k),size(v)+abs(k))\n end function diag_csp_k\n module function diag_cdp_k(v,k) result(res)\n complex(dp), intent(in) :: v(:)\n integer, intent(in) :: k\n complex(dp) :: res(size(v)+abs(k),size(v)+abs(k))\n end function diag_cdp_k\n module function diag_cqp_k(v,k) result(res)\n complex(qp), intent(in) :: v(:)\n integer, intent(in) :: k\n complex(qp) :: res(size(v)+abs(k),size(v)+abs(k))\n end function diag_cqp_k\n module function diag_iint8_k(v,k) result(res)\n integer(int8), intent(in) :: v(:)\n integer, intent(in) :: k\n integer(int8) :: res(size(v)+abs(k),size(v)+abs(k))\n end function diag_iint8_k\n module function diag_iint16_k(v,k) result(res)\n integer(int16), intent(in) :: v(:)\n integer, intent(in) :: k\n integer(int16) :: res(size(v)+abs(k),size(v)+abs(k))\n end function diag_iint16_k\n module function diag_iint32_k(v,k) result(res)\n integer(int32), intent(in) :: v(:)\n integer, intent(in) :: k\n integer(int32) :: res(size(v)+abs(k),size(v)+abs(k))\n end function diag_iint32_k\n module function diag_iint64_k(v,k) result(res)\n integer(int64), intent(in) :: v(:)\n integer, intent(in) :: k\n integer(int64) :: res(size(v)+abs(k),size(v)+abs(k))\n end function diag_iint64_k\n\n !\n ! Matrix to vector\n !\n module function diag_rsp_mat(A) result(res)\n real(sp), intent(in) :: A(:,:)\n real(sp) :: res(minval(shape(A)))\n end function diag_rsp_mat\n module function diag_rdp_mat(A) result(res)\n real(dp), intent(in) :: A(:,:)\n real(dp) :: res(minval(shape(A)))\n end function diag_rdp_mat\n module function diag_rqp_mat(A) result(res)\n real(qp), intent(in) :: A(:,:)\n real(qp) :: res(minval(shape(A)))\n end function diag_rqp_mat\n module function diag_csp_mat(A) result(res)\n complex(sp), intent(in) :: A(:,:)\n complex(sp) :: res(minval(shape(A)))\n end function diag_csp_mat\n module function diag_cdp_mat(A) result(res)\n complex(dp), intent(in) :: A(:,:)\n complex(dp) :: res(minval(shape(A)))\n end function diag_cdp_mat\n module function diag_cqp_mat(A) result(res)\n complex(qp), intent(in) :: A(:,:)\n complex(qp) :: res(minval(shape(A)))\n end function diag_cqp_mat\n module function diag_iint8_mat(A) result(res)\n integer(int8), intent(in) :: A(:,:)\n integer(int8) :: res(minval(shape(A)))\n end function diag_iint8_mat\n module function diag_iint16_mat(A) result(res)\n integer(int16), intent(in) :: A(:,:)\n integer(int16) :: res(minval(shape(A)))\n end function diag_iint16_mat\n module function diag_iint32_mat(A) result(res)\n integer(int32), intent(in) :: A(:,:)\n integer(int32) :: res(minval(shape(A)))\n end function diag_iint32_mat\n module function diag_iint64_mat(A) result(res)\n integer(int64), intent(in) :: A(:,:)\n integer(int64) :: res(minval(shape(A)))\n end function diag_iint64_mat\n module function diag_rsp_mat_k(A,k) result(res)\n real(sp), intent(in) :: A(:,:)\n integer, intent(in) :: k\n real(sp) :: res(minval(shape(A))-abs(k))\n end function diag_rsp_mat_k\n module function diag_rdp_mat_k(A,k) result(res)\n real(dp), intent(in) :: A(:,:)\n integer, intent(in) :: k\n real(dp) :: res(minval(shape(A))-abs(k))\n end function diag_rdp_mat_k\n module function diag_rqp_mat_k(A,k) result(res)\n real(qp), intent(in) :: A(:,:)\n integer, intent(in) :: k\n real(qp) :: res(minval(shape(A))-abs(k))\n end function diag_rqp_mat_k\n module function diag_csp_mat_k(A,k) result(res)\n complex(sp), intent(in) :: A(:,:)\n integer, intent(in) :: k\n complex(sp) :: res(minval(shape(A))-abs(k))\n end function diag_csp_mat_k\n module function diag_cdp_mat_k(A,k) result(res)\n complex(dp), intent(in) :: A(:,:)\n integer, intent(in) :: k\n complex(dp) :: res(minval(shape(A))-abs(k))\n end function diag_cdp_mat_k\n module function diag_cqp_mat_k(A,k) result(res)\n complex(qp), intent(in) :: A(:,:)\n integer, intent(in) :: k\n complex(qp) :: res(minval(shape(A))-abs(k))\n end function diag_cqp_mat_k\n module function diag_iint8_mat_k(A,k) result(res)\n integer(int8), intent(in) :: A(:,:)\n integer, intent(in) :: k\n integer(int8) :: res(minval(shape(A))-abs(k))\n end function diag_iint8_mat_k\n module function diag_iint16_mat_k(A,k) result(res)\n integer(int16), intent(in) :: A(:,:)\n integer, intent(in) :: k\n integer(int16) :: res(minval(shape(A))-abs(k))\n end function diag_iint16_mat_k\n module function diag_iint32_mat_k(A,k) result(res)\n integer(int32), intent(in) :: A(:,:)\n integer, intent(in) :: k\n integer(int32) :: res(minval(shape(A))-abs(k))\n end function diag_iint32_mat_k\n module function diag_iint64_mat_k(A,k) result(res)\n integer(int64), intent(in) :: A(:,:)\n integer, intent(in) :: k\n integer(int64) :: res(minval(shape(A))-abs(k))\n end function diag_iint64_mat_k\n end interface\n\n\n ! Matrix trace\n interface trace\n !! version: experimental\n !!\n !! Computes the trace of a matrix\n !! ([Specification](../page/specs/stdlib_linalg.html#description_2))\n module procedure trace_rsp\n module procedure trace_rdp\n module procedure trace_rqp\n module procedure trace_csp\n module procedure trace_cdp\n module procedure trace_cqp\n module procedure trace_iint8\n module procedure trace_iint16\n module procedure trace_iint32\n module procedure trace_iint64\n end interface\n\n\n ! Outer product (of two vectors)\n interface outer_product\n !! version: experimental\n !!\n !! Computes the outer product of two vectors, returning a rank-2 array\n !! ([Specification](../page/specs/stdlib_linalg.html#description_3))\n pure module function outer_product_rsp(u, v) result(res)\n real(sp), intent(in) :: u(:), v(:)\n real(sp) :: res(size(u),size(v))\n end function outer_product_rsp\n pure module function outer_product_rdp(u, v) result(res)\n real(dp), intent(in) :: u(:), v(:)\n real(dp) :: res(size(u),size(v))\n end function outer_product_rdp\n pure module function outer_product_rqp(u, v) result(res)\n real(qp), intent(in) :: u(:), v(:)\n real(qp) :: res(size(u),size(v))\n end function outer_product_rqp\n pure module function outer_product_csp(u, v) result(res)\n complex(sp), intent(in) :: u(:), v(:)\n complex(sp) :: res(size(u),size(v))\n end function outer_product_csp\n pure module function outer_product_cdp(u, v) result(res)\n complex(dp), intent(in) :: u(:), v(:)\n complex(dp) :: res(size(u),size(v))\n end function outer_product_cdp\n pure module function outer_product_cqp(u, v) result(res)\n complex(qp), intent(in) :: u(:), v(:)\n complex(qp) :: res(size(u),size(v))\n end function outer_product_cqp\n pure module function outer_product_iint8(u, v) result(res)\n integer(int8), intent(in) :: u(:), v(:)\n integer(int8) :: res(size(u),size(v))\n end function outer_product_iint8\n pure module function outer_product_iint16(u, v) result(res)\n integer(int16), intent(in) :: u(:), v(:)\n integer(int16) :: res(size(u),size(v))\n end function outer_product_iint16\n pure module function outer_product_iint32(u, v) result(res)\n integer(int32), intent(in) :: u(:), v(:)\n integer(int32) :: res(size(u),size(v))\n end function outer_product_iint32\n pure module function outer_product_iint64(u, v) result(res)\n integer(int64), intent(in) :: u(:), v(:)\n integer(int64) :: res(size(u),size(v))\n end function outer_product_iint64\n end interface outer_product\n\ncontains\n\n !> Version: experimental\n !>\n !> Constructs the identity matrix.\n !> ([Specification](../page/specs/stdlib_linalg.html#eye-construct-the-identity-matrix))\n pure function eye(dim1, dim2) result(result)\n\n integer, intent(in) :: dim1\n integer, intent(in), optional :: dim2\n integer(int8), allocatable :: result(:, :)\n\n integer :: dim2_\n integer :: i\n\n dim2_ = optval(dim2, dim1)\n allocate(result(dim1, dim2_))\n \n result = 0_int8\n do i = 1, min(dim1, dim2_)\n result(i, i) = 1_int8\n end do\n\n end function eye\n\n function trace_rsp(A) result(res)\n real(sp), intent(in) :: A(:,:)\n real(sp) :: res\n integer :: i\n res = 0\n do i = 1, minval(shape(A))\n res = res + A(i,i)\n end do\n end function trace_rsp\n function trace_rdp(A) result(res)\n real(dp), intent(in) :: A(:,:)\n real(dp) :: res\n integer :: i\n res = 0\n do i = 1, minval(shape(A))\n res = res + A(i,i)\n end do\n end function trace_rdp\n function trace_rqp(A) result(res)\n real(qp), intent(in) :: A(:,:)\n real(qp) :: res\n integer :: i\n res = 0\n do i = 1, minval(shape(A))\n res = res + A(i,i)\n end do\n end function trace_rqp\n function trace_csp(A) result(res)\n complex(sp), intent(in) :: A(:,:)\n complex(sp) :: res\n integer :: i\n res = 0\n do i = 1, minval(shape(A))\n res = res + A(i,i)\n end do\n end function trace_csp\n function trace_cdp(A) result(res)\n complex(dp), intent(in) :: A(:,:)\n complex(dp) :: res\n integer :: i\n res = 0\n do i = 1, minval(shape(A))\n res = res + A(i,i)\n end do\n end function trace_cdp\n function trace_cqp(A) result(res)\n complex(qp), intent(in) :: A(:,:)\n complex(qp) :: res\n integer :: i\n res = 0\n do i = 1, minval(shape(A))\n res = res + A(i,i)\n end do\n end function trace_cqp\n function trace_iint8(A) result(res)\n integer(int8), intent(in) :: A(:,:)\n integer(int8) :: res\n integer :: i\n res = 0\n do i = 1, minval(shape(A))\n res = res + A(i,i)\n end do\n end function trace_iint8\n function trace_iint16(A) result(res)\n integer(int16), intent(in) :: A(:,:)\n integer(int16) :: res\n integer :: i\n res = 0\n do i = 1, minval(shape(A))\n res = res + A(i,i)\n end do\n end function trace_iint16\n function trace_iint32(A) result(res)\n integer(int32), intent(in) :: A(:,:)\n integer(int32) :: res\n integer :: i\n res = 0\n do i = 1, minval(shape(A))\n res = res + A(i,i)\n end do\n end function trace_iint32\n function trace_iint64(A) result(res)\n integer(int64), intent(in) :: A(:,:)\n integer(int64) :: res\n integer :: i\n res = 0\n do i = 1, minval(shape(A))\n res = res + A(i,i)\n end do\n end function trace_iint64\n\nend module stdlib_linalg\n", "meta": {"hexsha": "0446471e497f6e2d444c50506a14815b50340145", "size": 14241, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/stdlib_linalg.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_linalg.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_linalg.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": 36.1446700508, "max_line_length": 92, "alphanum_fraction": 0.5798750088, "num_tokens": 3861, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797003640646, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6982312120979522}} {"text": " SUBROUTINE CPBSV_F95( A, B, UPLO, INFO )\n!\n! -- LAPACK95 interface driver routine (version 3.0) --\n! UNI-C, Denmark; Univ. of Tennessee, USA; NAG Ltd., UK\n! September, 2000\n!\n! .. USE STATEMENTS ..\n USE LA_PRECISION, ONLY: WP => SP\n USE LA_AUXMOD, ONLY: ERINFO, LSAME\n USE F77_LAPACK, ONLY: PBSV_F77 => LA_PBSV\n! .. IMPLICIT STATEMENT ..\n IMPLICIT NONE\n! .. SCALAR ARGUMENTS ..\n CHARACTER(LEN=1), INTENT(IN), OPTIONAL :: UPLO\n INTEGER, INTENT(OUT), OPTIONAL :: INFO\n! .. ARRAY ARGUMENTS ..\n COMPLEX(WP), INTENT(INOUT) :: A(:,:), B(:,:)\n!----------------------------------------------------------------------\n! \n! Purpose\n! =======\n! \n! LA_PBSV computes the solution to a linear system of equations\n! A*X = B, where A has band form and is real symmetric or complex\n! Hermitian and, in either case, positive definite, and where X and B are\n! rectangular matrices or vectors. The Cholesky decomposition is used to\n! factor A as A = U^H*U if UPLO = 'U', or A = L*L^H if UPLO = 'L'\n! where U is an upper triangular band matrix and L is a lower triangular \n! band matrix, each with the same number of superdiagonals or subdiagonals\n! as A. The factored form of A is then used to solve the above system.\n! \n! =========\n! \n! SUBROUTINE LA_PBSV( AB, B, UPLO=uplo, INFO=info )\n! (), INTENT(INOUT) :: AB(:,:), \n! CHARACTER(LEN=1), INTENT(IN), OPTIONAL :: UPLO\n! INTEGER, INTENT(OUT), OPTIONAL :: INFO\n! where\n! ::= REAL | COMPLEX\n! ::= KIND(1.0) | KIND(1.0D0)\n! ::= B(:,:) | B(:)\n! \n! Arguments\n! =========\n! \n! AB (input/output) REAL or COMPLEX array, shape (:,:) with \n! size(AB,1) = kd + 1 and size(AB,2) = n, where kd is the number\n! of superdiagonals or subdiagonals in the band and n is the \n! \t order of A.\n! On entry, the upper (if UPLO = 'U') or lower (if UPLO = 'L') \n! \t triangle of matrix A in band storage. The (kd + 1) diagonals of\n! \t A are stored in the rows of AB so that the j-th column of A is\n! \t stored in the j-th column of AB as follows:\n! \t if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j\n! \t 1<=j<=n\n! if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+kd)\n! \t 1<=j<=n.\n! On exit, the factor U or L from the Cholesky factorization \n! \t A = U^H*U = L*L^H in the same storage format as A.\n! B (input/output) REAL or COMPLEX array, shape (:,:) with \n! size(B,1) = n or shape (:) with size(B) = n.\n! On entry, the matrix B.\n! On exit, the solution matrix X .\n! UPLO Optional (input) CHARACTER(LEN=1)\n! = 'U': Upper triangle of A is stored;\n! = 'L': Lower triangle of A is stored.\n! Default value: 'U'.\n! INFO Optional (output) INTEGER.\n! = 0: successful exit.\n! < 0: if INFO = -i, the i-th argument had an illegal value.\n! > 0: if INFO = i, the leading minor of order i of A is not \n! \t positive definite, so the factorization could not be \n! \t completed and the solution could not be computed.\n! If INFO is not present and an error occurs, then the program \n! \t is terminated with an error message.\n!----------------------------------------------------------------------\n! .. PARAMETERS ..\n CHARACTER(LEN=7), PARAMETER :: SRNAME = 'LA_PBSV'\n! .. LOCAL SCALARS ..\n CHARACTER(LEN=1) :: LUPLO\n INTEGER :: LINFO, KD, N, NRHS\n! .. INTRINSIC FUNCTIONS ..\n INTRINSIC SIZE, PRESENT\n! .. EXECUTABLE STATEMENTS ..\n LINFO = 0; KD = SIZE(A,1)-1; N = SIZE(A,2); NRHS = SIZE(B,2)\n IF( PRESENT(UPLO) ) THEN; LUPLO = UPLO; ELSE; LUPLO = 'U'; ENDIF\n! .. TEST THE ARGUMENTS\n IF( KD < 0 .OR. N < 0 ) THEN; LINFO = -1\n ELSE IF( SIZE( B, 1 ) /= N .OR. NRHS < 0 ) THEN; LINFO = -2\n ELSE IF( .NOT.LSAME(LUPLO,'U') .AND. .NOT.LSAME(LUPLO,'L') )THEN; LINFO = -3\n ELSE IF ( N > 0 ) THEN\n CALL PBSV_F77( LUPLO, N, KD, NRHS, A, KD+1, B, N, LINFO )\n END IF\n CALL ERINFO( LINFO, SRNAME, INFO )\n END SUBROUTINE CPBSV_F95\n", "meta": {"hexsha": "baeb6f592c4e77908f97ccf2bd4e247ea9d4c64e", "size": 4160, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/la_cpbsv.f90", "max_stars_repo_name": "MattBurn/LAPACK95", "max_stars_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-12-29T15:07:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T10:09:22.000Z", "max_issues_repo_path": "src/la_cpbsv.f90", "max_issues_repo_name": "MattBurn/LAPACK95", "max_issues_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-02-21T10:46:38.000Z", "max_issues_repo_issues_event_max_datetime": "2017-10-20T17:03:14.000Z", "max_forks_repo_path": "src/la_cpbsv.f90", "max_forks_repo_name": "MattBurn/LAPACK95", "max_forks_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-12-29T15:34:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-15T07:12:40.000Z", "avg_line_length": 43.3333333333, "max_line_length": 80, "alphanum_fraction": 0.5533653846, "num_tokens": 1321, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797100118214, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6982312097646168}} {"text": "module strength\r\nuse hamiltonian_types\r\nuse maths\r\nuse build_hamiltonian_routines\r\nimplicit none\r\ncontains\r\n\r\n!------------------------------------------------\r\n! Locates a given value in a vector\r\n!------------------------------------------------\r\n\tfunction locate(a,b)\r\n\tinteger :: locate\r\n\treal(kind=8), INTENT(IN) :: a(:), b\r\n\tinteger :: location(1)\r\n\t\tlocate = -1\r\n\r\n\t\tlocation = minloc(abs(a-b))\r\n\t\tif (location(1) /= 0) then\r\n\t\t\tlocate = location(1)\r\n\t\tendif\r\n\t\t\r\n\tend function locate\r\n\r\n!------------------------------------------------\r\n! Returns the kronecker's delta\r\n!------------------------------------------------\r\n\tfunction kronecker(a,b)\r\n\treal*8 :: kronecker\r\n\treal*8, INTENT(IN) :: a, b\r\n\t\tkronecker = 0.d0\r\n\t\tif (a == b) then\r\n\t\t\tkronecker = 1.d0\r\n\t\tendif\r\n\tend function kronecker\r\n\r\n! ------------------------------------------------------------\r\n! This function returns the matrix elements of the dipole moment in the Hund's a)\r\n! eigenfunctions\r\n! ------------------------------------------------------------\t\r\n\tfunction q_o_m(Lambda_up,Omega_up,J_up,M_up,Lambda_low,Omega_low,J_low,M_low)\r\n\treal*8 :: q_o_m\r\n\treal*8, INTENT(IN) :: Lambda_up, Omega_up, J_up, M_up, Lambda_low, Omega_low, J_low, M_low\r\n\treal*8 :: q_m, q_o\r\n\t\r\n\t\tq_m = qm(J_up,M_up,J_low,M_low)\r\n\t\tq_o = qo(Lambda_up,Omega_up,J_up,Lambda_low,Omega_low,J_low)\r\n\r\n\t\tq_o_m = q_o * q_m\r\n\t\t\r\n\tend function q_o_m\r\n\r\n! ------------------------------------------------------------\r\n! This function returns the matrix elements of q_o\r\n! ------------------------------------------------------------\t\r\n\tfunction qm(J_up,M_up,J_low,M_low)\r\n\treal*8 :: qm\r\n\treal*8, INTENT(IN) :: J_up, M_up, J_low, M_low\r\n\treal*8 :: deltam, deltaj, J, M\r\n\t\r\n\t\tdeltaj = J_up - J_low\r\n\t\tdeltam = M_up - M_low\r\n\t\t\r\n\t\tJ = J_low\r\n\t\tM = M_low\r\n\t\tqm = 0.d0\r\n\t\t\r\n\t\tif (deltam == 0.d0) then\r\n\t\t\tif (deltaj == 1.d0) then\r\n\t\t\t\tqm = dsqrt((J+1.d0)**2 - M**2)\r\n\t\t\telse if (deltaj == 0) then\r\n\t\t\t\tqm = M\r\n\t\t\telse if (deltaj == -1.d0) then\r\n\t\t\t\tqm = dsqrt(J**2 - M**2)\r\n\t\t\tendif\r\n\t\tendif\r\n\t\t\r\n\t\tif (dabs(deltam) == 1.d0) then\r\n\t\t\tif (deltaj == 1.d0) then\r\n\t\t\t\tqm = -deltam * dsqrt(0.5d0*(J+1.d0+M*deltam)*(J+2.d0+M*deltam))\r\n\t\t\telse if (deltaj == 0) then\r\n\t\t\t\tqm = dsqrt(0.5d0*(J-M*deltam)*(J+1.d0+M*deltam))\r\n\t\t\telse if (deltaj == -1.d0) then\r\n\t\t\t\tqm = deltam * dsqrt(0.5d0*(J-M*deltam)*(J-1.d0-M*deltam))\r\n\t\t\tendif\r\n\t\tendif\r\n\t\t\t\t\r\n\tend function qm\r\n\r\n! ------------------------------------------------------------\r\n! This function returns the matrix elements of q_o\r\n! ------------------------------------------------------------\t\r\n\tfunction qo(Lambda_up,Omega_up,J_up,Lambda_low,Omega_low,J_low)\r\n\treal*8 :: qo\r\n\treal*8, INTENT(IN) :: Lambda_up, Omega_up, J_up, Lambda_low, Omega_low, J_low\r\n\treal*8 :: deltao, deltaj, Omega, J, pi_eps\r\n\t\r\n\t\tdeltao = Omega_up - Omega_low\r\n\t\tdeltaj = J_up - J_low\r\n\t\tpi_eps = 1.d0 + kronecker(1.d0,Lambda_up+Lambda_low)\r\n\t\t\r\n\t\tJ = J_low\r\n\t\tOmega = Omega_low\r\n\t\tqo = 0.d0\r\n\t\t\r\n\t\tif (deltao == 0.d0) then\r\n\t\t\tif (deltaj == 1.d0) then\r\n\t\t\t\tqo = 1.d0/(J+1.d0) * dsqrt(( (J+1.d0)**2 - Omega**2)/( (2.d0*J+1.d0)*(2.d0*J+3.d0)) )\r\n\t\t\telse if (deltaj == 0) then\r\n\t\t\t\tqo = Omega / (J*(J+1.d0))\r\n\t\t\telse if (deltaj == -1.d0) then\r\n\t\t\t\tqo = 1.d0/J * dsqrt(( J**2 - Omega**2)/((2.d0*J-1.d0)*(2.d0*J+1.d0)))\r\n\t\t\tendif\r\n\t\tendif\r\n\t\t\r\n\t\tif (dabs(deltao) == 1.d0) then\r\n\t\t\tif (deltaj == 1.d0) then\r\n\t\t\t\tqo = -deltao/(J+1.d0) * dsqrt(pi_eps*(J+1.d0+Omega*deltao)*(J+2.d0+Omega*deltao) /&\r\n\t\t\t\t\t(2.d0*(2.d0*J+1.d0)*(2.d0*J+3.d0)))\r\n\t\t\telse if (deltaj == 0) then\r\n\t\t\t\tqo = 1.d0/(J*(J+1.d0)) * dsqrt(0.5d0*pi_eps*(J-Omega*deltao)*(J+1.d0+Omega*deltao))\r\n\t\t\telse if (deltaj == -1.d0) then\r\n\t\t\t\tqo = deltao/J * dsqrt(pi_eps*(J-Omega*deltao)*(J-1.d0-Omega*deltao) /&\r\n\t\t\t\t\t(2.d0*(2.d0*J-1.d0)*(2.d0*J+1.d0)))\r\n\t\t\tendif\r\n\t\tendif\r\n\t\t\t\t\r\n\tend function qo\r\n\r\n!----------------------------------------------------------------------\r\n!----------------------------------------------------------------------\r\n! Strength of the Zeeman components in the Hund's case (a) coupling\r\n!----------------------------------------------------------------------\r\n!----------------------------------------------------------------------\r\n\tfunction case_a_strength(Ju,Jl,Mu,Ml,Ou,Ol)\r\n\treal(kind=8) :: case_a_strength\r\n\treal(kind=8) :: Mu, Ml, Ju, Jl, Ou, Ol, qm, qo\r\n\r\n\t\tqm = Mu - Ml\r\n\t\tqo = Ou - Ol\r\n\r\n! Falta un factor sqrt((2Ju+1)*(2Jl+1)) ??\r\n\r\n\t\tcase_a_strength = w3js(int(2.d0*Jl),int(2.d0*Ju),2,int(2.d0*Ml),-int(2.d0*Mu),int(2.d0*qm)) * &\r\n\t\t\tw3js(int(2.d0*Jl),int(2.d0*Ju),2,int(2.d0*Ol),-int(2.d0*Ou),int(2.d0*qo)) * &\r\n\t\t\tsqrt((2.d0*Ju+1.d0)*(2.d0*Jl+1.d0))\r\n\r\n\tend function case_a_strength\r\n\r\n!----------------------------------------------------------------------\r\n!----------------------------------------------------------------------\r\n! Count the number of Zeeman components and generate the index arrays\r\n!----------------------------------------------------------------------\r\n!----------------------------------------------------------------------\r\n\tsubroutine count_zeeman_components(trans)\r\n\ttype(type_transition) :: trans\r\n\tinteger :: i, j, i2, j2, k, nJup, nJlow, ind_up, ind_low\r\n\treal(kind=8) :: Ju, Jl, Mu, Ml, Ou, Ol, case_a_str, spli_up, spli_low, spli, m_up, m_low\r\n\treal(kind=8), allocatable :: direction_cosine(:,:), strength_matrix(:,:), caca(:,:)\r\n\t\t\r\n\t\tnJup = int(2.d0*trans%upper%J+1.d0)\r\n\t\tnJlow = int(2.d0*trans%lower%J+1.d0)\r\n\r\n\t\tk = 0\r\n\t\tdo i = 1, trans%upper%hamiltonian_size\r\n\t\t\tdo j = 1, trans%lower%hamiltonian_size\r\n\t\t\t\tif ( abs(trans%upper%ket(i)%M-trans%lower%ket(j)%M) <= 1.d0 .and. &\r\n\t\t\t\t\ttrans%upper%active(i) /= -9999 .and. trans%lower%active(j) /= -9999) then\r\n\t\t\t\t\t\tk = k + 1\r\n\t\t\t\tendif\r\n\t\t\tenddo\r\n\t\tenddo\r\n\t\tprint *, 'Number of Zeeman transitions : ', k\r\n\r\n\t\tallocate(direction_cosine(trans%upper%hamiltonian_size,trans%lower%hamiltonian_size))\r\n\t\tallocate(strength_matrix(trans%upper%hamiltonian_size,trans%lower%hamiltonian_size))\r\n\r\n\t\tdo i = 1, trans%upper%hamiltonian_size\r\n\t\t\tdo j = 1, trans%lower%hamiltonian_size\r\n\t\t\t\tJu = trans%upper%ket_m_ordered(i)%J\r\n\t\t\t\tJl = trans%lower%ket_m_ordered(j)%J\r\n\t\t\t\tMu = trans%upper%ket_m_ordered(i)%M\r\n\t\t\t\tMl = trans%lower%ket_m_ordered(j)%M\r\n\t\t\t\tOu = trans%upper%ket_m_ordered(i)%Omega\r\n\t\t\t\tOl = trans%lower%ket_m_ordered(j)%Omega\r\n\r\n\t\t\t\tdirection_cosine(i,j) = kronecker(trans%upper%ket_m_ordered(i)%Sigma,trans%lower%ket_m_ordered(j)%Sigma) * &\r\n\t\t\t\t\tq_o_m(trans%upper%Lambda,Ou,Ju,Mu,trans%lower%Lambda,Ol,Jl,Ml)\r\n\t\t\tenddo\r\n\t\tenddo\t\t\t\t\r\n\r\n\t\t\r\n\t\tstrength_matrix = matmul(matmul(transpose(trans%upper%eigenvec),direction_cosine),trans%lower%eigenvec)\r\n\r\n\r\n\t\t\t\t\t\t\r\n\t\tallocate(trans%ind_up(k))\r\n\t\tallocate(trans%ind_low(k))\r\n\t\tallocate(trans%str(k))\r\n\t\ttrans%str = 0.d0\r\n\r\n\t\tprint *, trans%upper%hamiltonian_size, trans%lower%hamiltonian_size\r\n\t\twrite(18,*) strength_matrix\r\n\t\twrite(17,*) direction_cosine\r\n\t\t\r\n\t\topen(unit=12,file='pattern.dat',action='write',status='replace')\r\n\t\twrite(12,*) k\r\n\r\n\t\tk = 0\r\n\t\tdo i = 1, 2*trans%upper%J+1\r\n\t\t\tm_up = -trans%upper%J + (i-1)\r\n\t\t\tdo j = 1, 2*trans%lower%J+1\r\n\t\t\t\tm_low = -trans%lower%J + (j-1)\r\n\r\n\t\t\t\tif (dabs(m_up-m_low) <= 1.d0) then\r\n\r\n\t\t\t\t\tind_up = locate(trans%upper%active,m_up)\r\n\t\t\t\t\tind_low = locate(trans%lower%active,m_low)\r\n\t\t\t\t\t\r\n\t\t\t\t\tspli_up = trans%upper%eigenval(ind_up)-trans%upper%eigenval_zerofield(ind_up)\r\n\t\t\t\t\tspli_low = trans%lower%eigenval(ind_low)-trans%lower%eigenval_zerofield(ind_low)\r\n\t\t\t\t\tspli = -(spli_up-spli_low)*(trans%wavelength*1.d-8)**2 * 1.d8\r\n\t\t\t\t\twrite(*,FMT='(F5.1,1X,F5.1,1X,F13.8,3X,F13.8,3X,E13.7)') trans%upper%ket(ind_up)%M, &\r\n\t\t\t\t\t\t\ttrans%lower%ket(ind_low)%M, spli, strength_matrix(ind_up,ind_low)**2\r\n\t\t\t\t\twrite(12,FMT='(F5.1,1X,F5.1,1X,F13.8,3X,F13.8,3X,E13.7)') trans%upper%ket(ind_up)%M, &\r\n\t\t\t\t\t\t\ttrans%lower%ket(ind_low)%M, spli, strength_matrix(ind_up,ind_low)**2\r\n\t\t\t\r\n\t\t\t\tendif\r\n\t\t\tenddo\r\n\t\tenddo\r\n\t\tclose(12)\r\n\t\r\n\tend subroutine count_zeeman_components\r\n\r\n!----------------------------------------------------------------------\r\n!----------------------------------------------------------------------\r\n! Strength of the Zeeman components\r\n!----------------------------------------------------------------------\r\n!----------------------------------------------------------------------\r\n\tsubroutine zeeman_strength(trans)\r\n\ttype(type_transition) :: trans\r\n\r\n! First count the number of components of the Zeeman transition\r\n\t\tcall count_zeeman_components(trans)\r\n\t\r\n\tend subroutine zeeman_strength\r\n\r\nend module strength", "meta": {"hexsha": "e13f00411f835de58a6605dbb6246576d389a440", "size": 8449, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "old/Mol_Hamiltonian/Fuentes/strength.f90", "max_stars_repo_name": "aasensio/diatomic", "max_stars_repo_head_hexsha": "0d7abe37bc9401f9f0452b6ee097fb9136e6830e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-03-13T00:31:23.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-13T00:31:23.000Z", "max_issues_repo_path": "old/Mol_Hamiltonian/Fuentes/strength.f90", "max_issues_repo_name": "aasensio/diatomic", "max_issues_repo_head_hexsha": "0d7abe37bc9401f9f0452b6ee097fb9136e6830e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "old/Mol_Hamiltonian/Fuentes/strength.f90", "max_forks_repo_name": "aasensio/diatomic", "max_forks_repo_head_hexsha": "0d7abe37bc9401f9f0452b6ee097fb9136e6830e", "max_forks_repo_licenses": ["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.2064777328, "max_line_length": 113, "alphanum_fraction": 0.524914191, "num_tokens": 2726, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088045171237, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.698175089426245}} {"text": "C Copyright(C) 1999-2020 National Technology & Engineering Solutions\nC of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with\nC NTESS, the U.S. Government retains certain rights in this software.\nC\nC See packages/seacas/LICENSE for details\n\nC=======================================================================\n SUBROUTINE TMAG (PARTYP, LENARY, NELBLK, IXELB, ISEVOK,\n & SIG1, SIG2, SIG3, SIG12, SIG23, SIG31,\n & NUMIX, IXNODE, IXELEM, RESULT)\nC=======================================================================\n\nC --*** TMAG *** (ALGEBRA) Calculate tensor magnitude\nC -- Written by Amy Gilkey - revised 12/03/87\nC --\nC --TMAG calculates the tensor magnitudes.\nC --\nC --Parameters:\nC -- PARTYP - IN - the parameter type (element must be handled differently)\nC -- LENARY - IN - the length of the parameter arrays\nC -- NELBLK - IN - the number of element blocks\nC -- IXELB - IN - the cumulative element counts for each element block\nC -- ISEVOK - IN - the element variable truth table for each element block\nC -- SIG1, SIG2, SIG3, SIG12, SIG23, SIG31 - IN - the tensor components\nC -- NUMIX - IN - the number of selected values; <0 if all\nC -- IXNODE - IN - the indices of the selected nodes (only if NUMIX>=0)\nC -- IXELEM - IN - the indices of the selected elements (only if NUMIX>=0)\nC -- RESULT - OUT - the returned tensor magnitudes\n\n CHARACTER PARTYP\n INTEGER IXELB(0:NELBLK)\n LOGICAL ISEVOK(*)\n REAL SIG1(*), SIG2(*), SIG3(*), SIG12(*), SIG23(*), SIG31(*)\n INTEGER NUMIX\n INTEGER IXNODE(*)\n INTEGER IXELEM(*)\n REAL RESULT(*)\n\n IF (NUMIX .GE. 0) THEN\nC COMPUTE TMAG ONLY FOR ELEMENTS/NODES THAT EXIST\n IF (PARTYP .NE. 'E') THEN\n DO 50 I = 1, NUMIX\n J = IXNODE(I)\n RESULT(J) = SQRT ((SIG1(J)-SIG2(J))**2\n & + (SIG2(J)-SIG3(J))**2\n & + (SIG3(J)-SIG1(J))**2\n & + 6 * (SIG12(J)**2 + SIG23(J)**2 + SIG31(J)**2))\n 50 CONTINUE\n ELSE\n DO 75 IELB = 1, NELBLK\n IF (ISEVOK(IELB)) THEN\n DO 95 I = IXELB(IELB-1)+1, IXELB(IELB)\n J = IXELEM(I)\n RESULT(J) = SQRT ((SIG1(J)-SIG2(J))**2\n & + (SIG2(J)-SIG3(J))**2\n & + (SIG3(J)-SIG1(J))**2\n & + 6 * (SIG12(J)**2 + SIG23(J)**2 + SIG31(J)**2))\n 95 CONTINUE\n END IF\n 75 CONTINUE\n END IF\n ELSE\nC NUMIX < 0; All Values are selected\nC NUMEL = NUMELO; NUMNP = NUMNPO; IXELB(J) = IXELBO(J) J=1,NELBLK\n IF (PARTYP .NE. 'E') THEN\n DO 100 J = 1, LENARY\n RESULT(J) = SQRT ((SIG1(J)-SIG2(J))**2\n & + (SIG2(J)-SIG3(J))**2\n & + (SIG3(J)-SIG1(J))**2\n & + 6 * (SIG12(J)**2 + SIG23(J)**2 + SIG31(J)**2))\n 100 CONTINUE\n ELSE\n DO 120 IELB = 1, NELBLK\n IF (ISEVOK(IELB)) THEN\n DO 110 J = IXELB(IELB-1)+1, IXELB(IELB)\n RESULT(J) = SQRT ((SIG1(J)-SIG2(J))**2\n & + (SIG2(J)-SIG3(J))**2\n & + (SIG3(J)-SIG1(J))**2\n & + 6 * (SIG12(J)**2 + SIG23(J)**2 + SIG31(J)**2))\n 110 CONTINUE\n END IF\n 120 CONTINUE\n END IF\n END IF\n\n RETURN\n END\n", "meta": {"hexsha": "bdc71671ba6dbcfb26fd3c01022ccf0f5c102cac", "size": 3523, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "packages/seacas/applications/algebra/ag_tmag.f", "max_stars_repo_name": "jschueller/seacas", "max_stars_repo_head_hexsha": "14c34ae08b757cba43a3a03ec0f129c8a168a9d3", "max_stars_repo_licenses": ["Python-2.0", "Zlib", "BSD-2-Clause", "MIT", "NetCDF", "BSL-1.0", "X11", "BSD-3-Clause"], "max_stars_count": 82, "max_stars_repo_stars_event_min_datetime": "2016-02-04T18:38:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T03:01:49.000Z", "max_issues_repo_path": "packages/seacas/applications/algebra/ag_tmag.f", "max_issues_repo_name": "jschueller/seacas", "max_issues_repo_head_hexsha": "14c34ae08b757cba43a3a03ec0f129c8a168a9d3", "max_issues_repo_licenses": ["Python-2.0", "Zlib", "BSD-2-Clause", "MIT", "NetCDF", "BSL-1.0", "X11", "BSD-3-Clause"], "max_issues_count": 206, "max_issues_repo_issues_event_min_datetime": "2015-11-20T01:57:47.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:12:04.000Z", "max_forks_repo_path": "packages/seacas/applications/algebra/ag_tmag.f", "max_forks_repo_name": "jschueller/seacas", "max_forks_repo_head_hexsha": "14c34ae08b757cba43a3a03ec0f129c8a168a9d3", "max_forks_repo_licenses": ["Python-2.0", "Zlib", "BSD-2-Clause", "MIT", "NetCDF", "BSL-1.0", "X11", "BSD-3-Clause"], "max_forks_count": 68, "max_forks_repo_forks_event_min_datetime": "2016-01-13T22:46:51.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T06:25:05.000Z", "avg_line_length": 40.0340909091, "max_line_length": 79, "alphanum_fraction": 0.4780017031, "num_tokens": 1113, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087946129329, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.698175081978169}} {"text": " PROGRAM PRIMES3\nC\nC PROGRAM TO PRINT THE FIRST N PRIMES\nC\n READ(*,*)N\n I=1\n J=0\n 10 I=I+1\n IS = SQRT(FLOAT(I))\n DO 20 K=2,IS\n IF (I/K*K .EQ.I) GOTO 10\n 20 CONTINUE\n WRITE(*,30)I\n 30 FORMAT(I8,$)\n J=J+1\n IF (J/10*10 .EQ.J) WRITE (*,40)\n 40 FORMAT()\n IF (J.LT.N) GOTO 10\n IF (J/10*10.NE.J) WRITE (*,40)\n END\n", "meta": {"hexsha": "f26366611cbd8f8e1ceb39c46fe4a39bd38a1bfc", "size": 384, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/UOW/CSCI337/examples/primes_3.f", "max_stars_repo_name": "felx/detritus", "max_stars_repo_head_hexsha": "b64d28b47381ea1e8c6b5282910365dc4292d57f", "max_stars_repo_licenses": ["MIT"], "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/UOW/CSCI337/examples/primes_3.f", "max_issues_repo_name": "felx/detritus", "max_issues_repo_head_hexsha": "b64d28b47381ea1e8c6b5282910365dc4292d57f", "max_issues_repo_licenses": ["MIT"], "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/UOW/CSCI337/examples/primes_3.f", "max_forks_repo_name": "felx/detritus", "max_forks_repo_head_hexsha": "b64d28b47381ea1e8c6b5282910365dc4292d57f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-07-03T09:22:08.000Z", "max_forks_repo_forks_event_max_datetime": "2018-07-03T09:22:08.000Z", "avg_line_length": 18.2857142857, "max_line_length": 41, "alphanum_fraction": 0.4739583333, "num_tokens": 167, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767842777551, "lm_q2_score": 0.7956581000631542, "lm_q1q2_score": 0.6981715110279648}} {"text": " PROGRAM xsor\r\nC driver for routine sor\r\n INTEGER JMAX,NSTEP\r\n REAL PI\r\n PARAMETER(JMAX=33,NSTEP=4,PI=3.1415926)\r\n INTEGER i,j,midl\r\n DOUBLE PRECISION rjac,a(JMAX,JMAX),b(JMAX,JMAX),c(JMAX,JMAX),\r\n * d(JMAX,JMAX),e(JMAX,JMAX),f(JMAX,JMAX),u(JMAX,JMAX)\r\n do 12 i=1,JMAX\r\n do 11 j=1,JMAX\r\n a(i,j)=1.d0\r\n b(i,j)=1.d0\r\n c(i,j)=1.d0\r\n d(i,j)=1.d0\r\n e(i,j)=-4.d0\r\n f(i,j)=0.d0\r\n u(i,j)=0.d0\r\n11 continue\r\n12 continue\r\n midl=JMAX/2+1\r\n f(midl,midl)=2.d0/(JMAX-1)**2\r\n rjac=cos(PI/JMAX)\r\n call sor(a,b,c,d,e,f,u,JMAX,rjac)\r\n write(*,'(1x,a)') 'SOR Solution:'\r\n do 13 i=1,JMAX,NSTEP\r\n write(*,'(1x,9f8.4)') (u(i,j),j=1,JMAX,NSTEP)\r\n13 continue\r\n write(*,'(/1x,a)') 'Test that solution satisfies Difference Eqns:'\r\n do 15 i=NSTEP+1,JMAX-1,NSTEP\r\n do 14 j=NSTEP+1,JMAX-1,NSTEP\r\n f(i,j)=u(i+1,j)+u(i-1,j)+u(i,j+1)+u(i,j-1)-4.d0*u(i,j)\r\n14 continue\r\n write(*,'(7x,9f8.4)') (f(i,j),j=NSTEP+1,JMAX-1,NSTEP)\r\n15 continue\r\n END\r\n", "meta": {"hexsha": "e5b344cc77f6779c177fb74092d66218d9e29a4e", "size": 1123, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xsor.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xsor.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xsor.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.1944444444, "max_line_length": 73, "alphanum_fraction": 0.499554764, "num_tokens": 437, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476793890012, "lm_q2_score": 0.795658090372256, "lm_q1q2_score": 0.6981715101724966}} {"text": "!------------------------------------------------------------------------------\n!------------------------------------------------------------------------------\n! frc : A periodically forced system\n!------------------------------------------------------------------------------\n!------------------------------------------------------------------------------\n\n SUBROUTINE FUNC(NDIM,U,ICP,PAR,IJAC,F,DFDU,DFDP) \n! ---------- ---- \n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: NDIM, ICP(*), IJAC\n DOUBLE PRECISION, INTENT(IN) :: U(NDIM), PAR(*)\n DOUBLE PRECISION, INTENT(OUT) :: F(NDIM)\n DOUBLE PRECISION, INTENT(INOUT) :: DFDU(NDIM,NDIM), DFDP(NDIM,*)\n\n DOUBLE PRECISION a,b,c,amp,beta,x,y,sn,cs,ss\n\n! FHN parameters\n a = PAR(1) \n b = PAR(2) \n c = PAR(3) \n\n! Forcing parameters\n amp = PAR(4) \n beta= PAR(5) \n\n! FHN variables\n x=U(1)\n y=U(2)\n\n! Forcing variables\n sn=U(3)\n cs=U(4)\n ss = sn**2 + cs**2 \n\n! FHN equations\n F(1)= c * ( x - x**3/3 + y - amp*cs )\n F(2)=-( x - a + b*y ) / c\n\n! Oscillator\n F(3) = sn + beta*cs - sn*ss \n F(4) = -beta*sn + cs - cs*ss \n\n END SUBROUTINE FUNC\n\n SUBROUTINE STPNT(NDIM,U,PAR,t) \n! ---------- -----\n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: NDIM\n DOUBLE PRECISION, INTENT(INOUT) :: U(NDIM),PAR(*)\n DOUBLE PRECISION, INTENT(IN) :: t\n\n DOUBLE PRECISION a,b,c,amp,beta,TPI\n\n! FHN parameters\n a = 0.\n b = 0.8\n c = 3.\n\n PAR(1)=a\n PAR(2)=b\n PAR(3)=c\n\n! Forcing parameters\n amp=0.\n beta=10\n\n PAR(4)=amp\n PAR(5)=beta\n\n TPI=8*ATAN(1.d0)\n PAR(11)=TPI/beta\n\n! Initial FHB stationary solution (assuming a=0)\n U(1)= 0.\n U(2)= 0.\n\n! Initialize the oscillator\n U(3)=SIN(TPI*t) \n U(4)=COS(TPI*t) \n\n END SUBROUTINE STPNT\n\n SUBROUTINE BCND\n END SUBROUTINE BCND\n\n SUBROUTINE ICND\n END SUBROUTINE ICND\n\n SUBROUTINE FOPT\n END SUBROUTINE FOPT\n\n SUBROUTINE PVLS\n END SUBROUTINE PVLS\n", "meta": {"hexsha": "f783c6e2b23e030d7bb50901088d2c8f6673d863", "size": 2121, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "07p/demos/ffn/ffn.f90", "max_stars_repo_name": "st970703/AUTO07P-Update-to-Python-3.0", "max_stars_repo_head_hexsha": "fb2d2aebf2127fa914064d01ed62c0acb5f6421c", "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": "07p/demos/ffn/ffn.f90", "max_issues_repo_name": "st970703/AUTO07P-Update-to-Python-3.0", "max_issues_repo_head_hexsha": "fb2d2aebf2127fa914064d01ed62c0acb5f6421c", "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": "07p/demos/ffn/ffn.f90", "max_forks_repo_name": "st970703/AUTO07P-Update-to-Python-3.0", "max_forks_repo_head_hexsha": "fb2d2aebf2127fa914064d01ed62c0acb5f6421c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.09375, "max_line_length": 79, "alphanum_fraction": 0.4280999529, "num_tokens": 654, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.6981715071996679}} {"text": "program test_utils\n\n use mo_kind, only: sp, dp, i4\n use mo_ansi_colors, only: color, c_red, c_green\n use mo_utils, only: eq, ge, le, ne\n use mo_utils, only: equal, greaterequal, lesserequal, notequal\n use mo_utils, only: swap, locate, cumsum, arange, linspace\n use mo_utils, only: is_finite, is_nan, is_normal, special_value\n use mo_utils, only: isin, isinloc\n\n implicit none\n\n real(dp) :: a_dp\n real(dp) :: b_dp\n real(sp) :: a_sp\n real(sp) :: b_sp\n\n integer(i4), parameter :: nn = 100\n real(dp), dimension(nn) :: dat1, dat2, dat3\n real(sp), dimension(nn) :: sat1, sat2, sat3\n integer(i4), dimension(nn) :: iat1, iat2, iat3\n complex(dp), dimension(nn) :: cat1, cat2\n real(dp), dimension(:), allocatable :: adat1\n character(len=10), dimension(nn) :: chat1\n\n real(dp) :: d1\n real(dp), dimension(5) :: d5\n real(sp) :: s1\n real(sp), dimension(5) :: s5\n integer(i4) :: ii1\n integer(i4), dimension(5) :: ii5\n\n integer(i4) :: i\n logical :: isgood\n logical :: compare\n\n isgood = .true.\n\n ! -----------------------------------------------------\n ! DOUBLE PRECISON\n ! -----------------------------------------------------\n\n write(*,*) ''\n write(*,*) 'Test: eq/equal: dp'\n ! 0.1 == 0.1+eps --> .False.\n a_dp = 0.1_dp\n b_dp = a_dp + epsilon(1.0_dp)\n compare = eq(a_dp, b_dp)\n write(*,'(E24.17,A4,E24.17,A5,L2)') a_dp,' == ',b_dp,' --> ',compare\n isgood = isgood .and. (.not. compare)\n\n ! 1.0 == 1.0+eps --> .True.\n a_dp = 1.0_dp\n b_dp = a_dp + epsilon(1.0_dp)\n compare = eq(a_dp, b_dp)\n write(*,'(E24.17,A4,E24.17,A5,L2)') a_dp,' == ',b_dp,' --> ',compare\n isgood = isgood .and. (compare)\n\n ! 0.1 == 0.1+eps --> .False.\n a_dp = 0.1_dp\n b_dp = a_dp + epsilon(1.0_dp)\n compare = equal(a_dp, b_dp)\n write(*,'(E24.17,A4,E24.17,A5,L2)') a_dp,' == ',b_dp,' --> ',compare\n isgood = isgood .and. (.not. compare)\n\n ! 1.0 == 1.0+eps --> .True.\n a_dp = 1.0_dp\n b_dp = a_dp + epsilon(1.0_dp)\n compare = equal(a_dp, b_dp)\n write(*,'(E24.17,A4,E24.17,A5,L2)') a_dp,' == ',b_dp,' --> ',compare\n isgood = isgood .and. (compare)\n\n write(*,*) ''\n write(*,*) 'Test: ge/greaterequal: dp'\n ! 0.1 >= 0.1+eps --> .False.\n a_dp = 0.1_dp\n b_dp = a_dp + epsilon(1.0_dp)\n compare = ge(a_dp, b_dp)\n write(*,'(E24.17,A4,E24.17,A5,L2)') a_dp,' >= ',b_dp,' --> ',compare\n isgood = isgood .and. (.not. compare)\n\n ! 1.0 >= 1.0+eps --> .True.\n a_dp = 1.0_dp\n b_dp = a_dp + epsilon(1.0_dp)\n compare = ge(a_dp, b_dp)\n write(*,'(E24.17,A4,E24.17,A5,L2)') a_dp,' >= ',b_dp,' --> ',compare\n isgood = isgood .and. (compare)\n\n ! 0.1 >= 0.2 --> .False.\n a_dp = 0.1_dp\n b_dp = 0.2_dp\n compare = ge(a_dp, b_dp)\n write(*,'(E24.17,A4,E24.17,A5,L2)') a_dp,' >= ',b_dp,' --> ',compare\n isgood = isgood .and. (.not. compare)\n\n ! tiny >= 2*tiny --> .False.\n a_dp = tiny(1.0_dp)\n b_dp = 2.0_dp*a_dp\n compare = ge(a_dp, b_dp)\n write(*,'(E24.17,A4,E24.17,A5,L2)') a_dp,' >= ',b_dp,' --> ',compare\n isgood = isgood .and. (.not. compare)\n\n ! 0.1 >= 0.1+eps --> .False.\n a_dp = 0.1_dp\n b_dp = a_dp + epsilon(1.0_dp)\n compare = greaterequal(a_dp, b_dp)\n write(*,'(E24.17,A4,E24.17,A5,L2)') a_dp,' >= ',b_dp,' --> ',compare\n isgood = isgood .and. (.not. compare)\n\n ! 1.0 >= 1.0+eps --> .True.\n a_dp = 1.0_dp\n b_dp = a_dp + epsilon(1.0_dp)\n compare = greaterequal(a_dp, b_dp)\n write(*,'(E24.17,A4,E24.17,A5,L2)') a_dp,' >= ',b_dp,' --> ',compare\n isgood = isgood .and. (compare)\n\n ! 0.1 >= 0.2 --> .False.\n a_dp = 0.1_dp\n b_dp = 0.2_dp\n compare = greaterequal(a_dp, b_dp)\n write(*,'(E24.17,A4,E24.17,A5,L2)') a_dp,' >= ',b_dp,' --> ',compare\n isgood = isgood .and. (.not. compare)\n\n ! tiny >= 2*tiny --> .False.\n a_dp = tiny(1.0_dp)\n b_dp = 2.0_dp*a_dp\n compare = greaterequal(a_dp, b_dp)\n write(*,'(E24.17,A4,E24.17,A5,L2)') a_dp,' >= ',b_dp,' --> ',compare\n isgood = isgood .and. (.not. compare)\n\n write(*,*) ''\n write(*,*) 'Test: le/lesserequal: dp'\n ! 0.1 <= 0.1+eps --> .True.\n a_dp = 0.1_dp\n b_dp = a_dp + epsilon(1.0_dp)\n compare = le(a_dp, b_dp)\n write(*,'(E24.17,A4,E24.17,A5,L2)') a_dp,' <= ',b_dp,' --> ',compare\n isgood = isgood .and. (compare)\n\n ! 1.0 <= 1.0+eps --> .True.\n a_dp = 1.0_dp\n b_dp = a_dp + epsilon(1.0_dp)\n compare = le(a_dp, b_dp)\n write(*,'(E24.17,A4,E24.17,A5,L2)') a_dp,' <= ',b_dp,' --> ',compare\n isgood = isgood .and. (compare)\n\n ! 0.1 <= 0.2 --> .True.\n a_dp = 0.1_dp\n b_dp = 0.2_dp\n compare = le(a_dp, b_dp)\n write(*,'(E24.17,A4,E24.17,A5,L2)') a_dp,' <= ',b_dp,' --> ',compare\n isgood = isgood .and. (compare)\n\n ! tiny <= 2*tiny --> .True.\n a_dp = tiny(1.0_dp)\n b_dp = 2.0_dp*a_dp\n compare = le(a_dp, b_dp)\n write(*,'(E24.17,A4,E24.17,A5,L2)') a_dp,' <= ',b_dp,' --> ',compare\n isgood = isgood .and. (compare)\n\n ! 0.1 <= 0.1+eps --> .True.\n a_dp = 0.1_dp\n b_dp = a_dp + epsilon(1.0_dp)\n compare = lesserequal(a_dp, b_dp)\n write(*,'(E24.17,A4,E24.17,A5,L2)') a_dp,' <= ',b_dp,' --> ',compare\n isgood = isgood .and. (compare)\n\n ! 1.0 <= 1.0+eps --> .True.\n a_dp = 1.0_dp\n b_dp = a_dp + epsilon(1.0_dp)\n compare = lesserequal(a_dp, b_dp)\n write(*,'(E24.17,A4,E24.17,A5,L2)') a_dp,' <= ',b_dp,' --> ',compare\n isgood = isgood .and. (compare)\n\n ! 0.1 <= 0.2 --> .True.\n a_dp = 0.1_dp\n b_dp = 0.2_dp\n compare = lesserequal(a_dp, b_dp)\n write(*,'(E24.17,A4,E24.17,A5,L2)') a_dp,' <= ',b_dp,' --> ',compare\n isgood = isgood .and. (compare)\n\n ! tiny <= 2*tiny --> .True.\n a_dp = tiny(1.0_dp)\n b_dp = 2.0_dp*a_dp\n compare = lesserequal(a_dp, b_dp)\n write(*,'(E24.17,A4,E24.17,A5,L2)') a_dp,' <= ',b_dp,' --> ',compare\n isgood = isgood .and. (compare)\n\n write(*,*) ''\n write(*,*) 'Test: ne/notequal: dp'\n ! 0.1 /= 0.1+eps --> .True.\n a_dp = 0.1_dp\n b_dp = a_dp + epsilon(1.0_dp)\n compare = ne(a_dp, b_dp)\n write(*,'(E24.17,A4,E24.17,A5,L2)') a_dp,' /= ',b_dp,' --> ',compare\n isgood = isgood .and. (compare)\n\n ! 1.0 /= 1.0+eps --> .False.\n a_dp = 1.0_dp\n b_dp = a_dp + epsilon(1.0_dp)\n compare = ne(a_dp, b_dp)\n write(*,'(E24.17,A4,E24.17,A5,L2)') a_dp,' /= ',b_dp,' --> ',compare\n isgood = isgood .and. (.not. compare)\n\n ! 0.1 /= 0.1+eps --> .True.\n a_dp = 0.1_dp\n b_dp = a_dp + epsilon(1.0_dp)\n compare = notequal(a_dp, b_dp)\n write(*,'(E24.17,A4,E24.17,A5,L2)') a_dp,' /= ',b_dp,' --> ',compare\n isgood = isgood .and. (compare)\n\n ! 1.0 /= 1.0+eps --> .False.\n a_dp = 1.0_dp\n b_dp = a_dp + epsilon(1.0_dp)\n compare = notequal(a_dp, b_dp)\n write(*,'(E24.17,A4,E24.17,A5,L2)') a_dp,' /= ',b_dp,' --> ',compare\n isgood = isgood .and. (.not. compare)\n\n ! -----------------------------------------------------\n ! SINGLE PRECISON\n ! -----------------------------------------------------\n\n write(*,*) ''\n write(*,*) 'Test: eq/ equal: sp'\n ! 0.1 == 0.1+eps --> .False.\n a_sp = 0.1_sp\n b_sp = a_sp + epsilon(1.0_sp)\n compare = eq(a_sp, b_sp)\n write(*,'(E15.8,A4,E15.8,A5,L2)') a_sp,' == ',b_sp,' --> ',compare\n isgood = isgood .and. (.not. compare)\n\n ! 1.0 == 1.0+eps --> .True.\n a_sp = 1.0_sp\n b_sp = a_sp + epsilon(1.0_sp)\n compare = eq(a_sp, b_sp)\n write(*,'(E15.8,A4,E15.8,A5,L2)') a_sp,' == ',b_sp,' --> ',compare\n isgood = isgood .and. (compare)\n\n ! 0.1 == 0.1+eps --> .False.\n a_sp = 0.1_sp\n b_sp = a_sp + epsilon(1.0_sp)\n compare = equal(a_sp, b_sp)\n write(*,'(E15.8,A4,E15.8,A5,L2)') a_sp,' == ',b_sp,' --> ',compare\n isgood = isgood .and. (.not. compare)\n\n ! 1.0 == 1.0+eps --> .True.\n a_sp = 1.0_sp\n b_sp = a_sp + epsilon(1.0_sp)\n compare = equal(a_sp, b_sp)\n write(*,'(E15.8,A4,E15.8,A5,L2)') a_sp,' == ',b_sp,' --> ',compare\n isgood = isgood .and. (compare)\n\n write(*,*) ''\n write(*,*) 'Test: ge/ greaterequal: sp'\n ! 0.1 >= 0.1+eps --> .False.\n a_sp = 0.1_sp\n b_sp = a_sp + epsilon(1.0_sp)\n compare = ge(a_sp, b_sp)\n write(*,'(E15.8,A4,E15.8,A5,L2)') a_sp,' >= ',b_sp,' --> ',compare\n isgood = isgood .and. (.not. compare)\n\n ! 1.0 >= 1.0+eps --> .True.\n a_sp = 1.0_sp\n b_sp = a_sp + epsilon(1.0_sp)\n compare = ge(a_sp, b_sp)\n write(*,'(E15.8,A4,E15.8,A5,L2)') a_sp,' >= ',b_sp,' --> ',compare\n isgood = isgood .and. (compare)\n\n ! 0.1 >= 0.2 --> .False.\n a_sp = 0.1_sp\n b_sp = 0.2_sp\n compare = ge(a_sp, b_sp)\n write(*,'(E15.8,A4,E15.8,A5,L2)') a_sp,' >= ',b_sp,' --> ',compare\n isgood = isgood .and. (.not. compare)\n\n ! tiny >= 2*tiny --> .False.\n a_sp = tiny(1.0_sp)\n b_sp = 2.0_sp*a_sp\n compare = ge(a_sp, b_sp)\n write(*,'(E15.8,A4,E15.8,A5,L2)') a_sp,' >= ',b_sp,' --> ',compare\n isgood = isgood .and. (.not. compare)\n\n ! 0.1 >= 0.1+eps --> .False.\n a_sp = 0.1_sp\n b_sp = a_sp + epsilon(1.0_sp)\n compare = greaterequal(a_sp, b_sp)\n write(*,'(E15.8,A4,E15.8,A5,L2)') a_sp,' >= ',b_sp,' --> ',compare\n isgood = isgood .and. (.not. compare)\n\n ! 1.0 >= 1.0+eps --> .True.\n a_sp = 1.0_sp\n b_sp = a_sp + epsilon(1.0_sp)\n compare = greaterequal(a_sp, b_sp)\n write(*,'(E15.8,A4,E15.8,A5,L2)') a_sp,' >= ',b_sp,' --> ',compare\n isgood = isgood .and. (compare)\n\n ! 0.1 >= 0.2 --> .False.\n a_sp = 0.1_sp\n b_sp = 0.2_sp\n compare = greaterequal(a_sp, b_sp)\n write(*,'(E15.8,A4,E15.8,A5,L2)') a_sp,' >= ',b_sp,' --> ',compare\n isgood = isgood .and. (.not. compare)\n\n ! tiny >= 2*tiny --> .False.\n a_sp = tiny(1.0_sp)\n b_sp = 2.0_sp*a_sp\n compare = greaterequal(a_sp, b_sp)\n write(*,'(E15.8,A4,E15.8,A5,L2)') a_sp,' >= ',b_sp,' --> ',compare\n isgood = isgood .and. (.not. compare)\n\n write(*,*) ''\n write(*,*) 'Test: le/ lesserequal: sp'\n ! 0.1 <= 0.1+eps --> .True.\n a_sp = 0.1_sp\n b_sp = a_sp + epsilon(1.0_sp)\n compare = le(a_sp, b_sp)\n write(*,'(E15.8,A4,E15.8,A5,L2)') a_sp,' <= ',b_sp,' --> ',compare\n isgood = isgood .and. (compare)\n\n ! 1.0 <= 1.0+eps --> .True.\n a_sp = 1.0_sp\n b_sp = a_sp + epsilon(1.0_sp)\n compare = le(a_sp, b_sp)\n write(*,'(E15.8,A4,E15.8,A5,L2)') a_sp,' <= ',b_sp,' --> ',compare\n isgood = isgood .and. (compare)\n\n ! 0.1 <= 0.2 --> .True.\n a_sp = 0.1_sp\n b_sp = 0.2_sp\n compare = le(a_sp, b_sp)\n write(*,'(E15.8,A4,E15.8,A5,L2)') a_sp,' <= ',b_sp,' --> ',compare\n isgood = isgood .and. (compare)\n\n ! tiny <= 2*tiny --> .True.\n a_sp = tiny(1.0_sp)\n b_sp = 2.0_sp*a_sp\n compare = le(a_sp, b_sp)\n write(*,'(E15.8,A4,E15.8,A5,L2)') a_sp,' <= ',b_sp,' --> ',compare\n isgood = isgood .and. (compare)\n\n ! 0.1 <= 0.1+eps --> .True.\n a_sp = 0.1_sp\n b_sp = a_sp + epsilon(1.0_sp)\n compare = lesserequal(a_sp, b_sp)\n write(*,'(E15.8,A4,E15.8,A5,L2)') a_sp,' <= ',b_sp,' --> ',compare\n isgood = isgood .and. (compare)\n\n ! 1.0 <= 1.0+eps --> .True.\n a_sp = 1.0_sp\n b_sp = a_sp + epsilon(1.0_sp)\n compare = lesserequal(a_sp, b_sp)\n write(*,'(E15.8,A4,E15.8,A5,L2)') a_sp,' <= ',b_sp,' --> ',compare\n isgood = isgood .and. (compare)\n\n ! 0.1 <= 0.2 --> .True.\n a_sp = 0.1_sp\n b_sp = 0.2_sp\n compare = lesserequal(a_sp, b_sp)\n write(*,'(E15.8,A4,E15.8,A5,L2)') a_sp,' <= ',b_sp,' --> ',compare\n isgood = isgood .and. (compare)\n\n ! tiny <= 2*tiny --> .True.\n a_sp = tiny(1.0_sp)\n b_sp = 2.0_sp*a_sp\n compare = lesserequal(a_sp, b_sp)\n write(*,'(E15.8,A4,E15.8,A5,L2)') a_sp,' <= ',b_sp,' --> ',compare\n isgood = isgood .and. (compare)\n\n write(*,*) ''\n write(*,*) 'Test: ne/ notequal: sp'\n ! 0.1 /= 0.1+eps --> .True.\n a_sp = 0.1_sp\n b_sp = a_sp + epsilon(1.0_sp)\n compare = ne(a_sp, b_sp)\n write(*,'(E15.8,A4,E15.8,A5,L2)') a_sp,' /= ',b_sp,' --> ',compare\n isgood = isgood .and. (compare)\n\n ! 1.0 /= 1.0+eps --> .False.\n a_sp = 1.0_sp\n b_sp = a_sp + epsilon(1.0_sp)\n compare = ne(a_sp, b_sp)\n write(*,'(E15.8,A4,E15.8,A5,L2)') a_sp,' /= ',b_sp,' --> ',compare\n isgood = isgood .and. (.not. compare)\n\n ! -----------------------------------------------------\n ! Swap\n\n call random_number(dat1)\n call random_number(dat2)\n dat3 = dat1\n call swap(dat1, dat2)\n isgood = isgood .and. all(eq(dat2,dat3))\n\n call swap(dat2, 1, nn)\n call swap(dat2, nn, 1)\n isgood = isgood .and. all(eq(dat2,dat3))\n\n call random_number(sat1)\n call random_number(sat2)\n sat3 = sat1\n call swap(sat1, sat2)\n isgood = isgood .and. all(eq(sat2,sat3))\n\n call swap(sat2, 1, nn)\n call swap(sat2, nn, 1)\n isgood = isgood .and. all(eq(sat2,sat3))\n\n call random_number(dat1)\n call random_number(dat2)\n iat1 = int(dat1, i4)\n iat2 = int(dat2, i4)\n iat3 = iat1\n call swap(iat1, iat2)\n isgood = isgood .and. all(iat2 == iat3)\n\n call swap(iat2, 1, nn)\n call swap(iat2, nn, 1)\n isgood = isgood .and. all(iat2 == iat3)\n\n ! -----------------------------------------------------\n ! Locate\n\n ! double precision\n forall(i=1:nn) dat1(i) = real(i,dp)\n ! 0d\n d1 = 1.1_dp\n ii1 = locate(dat1, d1)\n isgood = isgood .and. (ii1 == 1)\n ! 1d\n d5 = (/ 0.1_dp, 5.5_dp, 10.1_dp, 50.5_dp, 200.1_dp /)\n ii5 = locate(dat1, d5)\n isgood = isgood .and. all(ii5 == (/0, 5, 10, 50, 100/))\n\n ! single precision\n forall(i=1:nn) sat1(i) = real(i,sp)\n ! 0d\n s1 = 1.1_sp\n ii1 = locate(sat1, s1)\n isgood = isgood .and. (ii1 == 1)\n ! 1d\n s5 = (/ 0.1_sp, 5.5_sp, 10.1_sp, 50.5_sp, 200.1_sp /)\n ii5 = locate(sat1, s5)\n isgood = isgood .and. all(ii5 == (/0, 5, 10, 50, 100/))\n\n ! -----------------------------------------------------\n ! is_finite, is_nan, is_normal\n\n call random_number(dat1)\n isgood = isgood .and. all(is_finite(dat1))\n isgood = isgood .and. all(.not. is_nan(dat1))\n isgood = isgood .and. all(is_normal(dat1))\n ! NaN\n dat1(1) = 0.0_dp\n dat1(1) = dat1(1)/dat1(1)\n isgood = isgood .and. any(is_nan(dat1))\n isgood = isgood .and. is_nan(dat1(1))\n ! Inf\n dat1(2) = huge(1.0_dp)\n dat1(2) = dat1(2)*dat1(2)\n isgood = isgood .and. any(.not. is_finite(dat1))\n isgood = isgood .and. (.not. is_finite(dat1(2)))\n ! Both\n isgood = isgood .and. (.not. all(is_normal(dat1)))\n isgood = isgood .and. (.not. any(is_normal(dat1(1:2))))\n\n call random_number(sat1)\n isgood = isgood .and. all(is_finite(sat1))\n isgood = isgood .and. all(.not. is_nan(sat1))\n isgood = isgood .and. all(is_normal(sat1))\n ! NaN\n sat1(1) = 0.0_sp\n sat1(1) = sat1(1)/sat1(1)\n isgood = isgood .and. any(is_nan(sat1))\n isgood = isgood .and. is_nan(sat1(1))\n ! Inf\n sat1(2) = huge(1.0_sp)\n sat1(2) = sat1(2)*sat1(2)\n isgood = isgood .and. any(.not. is_finite(sat1))\n isgood = isgood .and. (.not. is_finite(sat1(2)))\n ! Both\n isgood = isgood .and. (.not. all(is_normal(sat1)))\n isgood = isgood .and. (.not. any(is_normal(sat1(1:2))))\n\n ! -----------------------------------------------------\n ! special_value\n\n isgood = isgood .and. is_nan(special_value(1.0_dp, 'IEEE_SIGNALING_NAN'))\n isgood = isgood .and. is_nan(special_value(1.0_dp, 'IEEE_QUIET_NAN'))\n isgood = isgood .and. (.not. is_finite(special_value(1.0_dp, 'IEEE_POSITIVE_INF')))\n isgood = isgood .and. (.not. is_finite(special_value(1.0_dp, 'IEEE_NEGATIVE_INF')))\n isgood = isgood .and. is_finite(special_value(1.0_dp, 'IEEE_POSITIVE_DENORMAL'))\n isgood = isgood .and. is_finite(special_value(1.0_dp, 'IEEE_NEGATIVE_DENORMAL'))\n isgood = isgood .and. is_finite(special_value(1.0_dp, 'IEEE_POSITIVE_NORMAL'))\n isgood = isgood .and. is_finite(special_value(1.0_dp, 'IEEE_NEGATIVE_NORMAL'))\n isgood = isgood .and. is_finite(special_value(1.0_dp, 'IEEE_POSITIVE_ZERO'))\n isgood = isgood .and. is_finite(special_value(1.0_dp, 'IEEE_NEGATIVE_ZERO'))\n isgood = isgood .and. eq(special_value(1.0_dp, 'IEEE_NEGATIVE_INF'), -special_value(1.0_dp, 'IEEE_POSITIVE_INF'))\n isgood = isgood .and. eq(special_value(1.0_dp, 'IEEE_NEGATIVE_DENORMAL'), -special_value(1.0_dp, 'IEEE_POSITIVE_DENORMAL'))\n isgood = isgood .and. eq(special_value(1.0_dp, 'IEEE_NEGATIVE_NORMAL'), -special_value(1.0_dp, 'IEEE_POSITIVE_NORMAL'))\n isgood = isgood .and. eq(special_value(1.0_dp, 'IEEE_NEGATIVE_ZERO'), -special_value(1.0_dp, 'IEEE_POSITIVE_ZERO'))\n isgood = isgood .and. eq(abs(special_value(1.0_dp, 'IEEE_POSITIVE_ZERO')), 0.0_dp)\n isgood = isgood .and. eq(abs(special_value(1.0_dp, 'IEEE_NEGATIVE_ZERO')), 0.0_dp)\n\n isgood = isgood .and. is_nan(special_value(1.0_sp, 'IEEE_SIGNALING_NAN'))\n isgood = isgood .and. is_nan(special_value(1.0_sp, 'IEEE_QUIET_NAN'))\n isgood = isgood .and. (.not. is_finite(special_value(1.0_sp, 'IEEE_POSITIVE_INF')))\n isgood = isgood .and. (.not. is_finite(special_value(1.0_sp, 'IEEE_NEGATIVE_INF')))\n isgood = isgood .and. is_finite(special_value(1.0_sp, 'IEEE_POSITIVE_DENORMAL'))\n isgood = isgood .and. is_finite(special_value(1.0_sp, 'IEEE_NEGATIVE_DENORMAL'))\n isgood = isgood .and. is_finite(special_value(1.0_sp, 'IEEE_POSITIVE_NORMAL'))\n isgood = isgood .and. is_finite(special_value(1.0_sp, 'IEEE_NEGATIVE_NORMAL'))\n isgood = isgood .and. is_finite(special_value(1.0_sp, 'IEEE_POSITIVE_ZERO'))\n isgood = isgood .and. is_finite(special_value(1.0_sp, 'IEEE_NEGATIVE_ZERO'))\n isgood = isgood .and. eq(special_value(1.0_sp, 'IEEE_NEGATIVE_INF'), -special_value(1.0_sp, 'IEEE_POSITIVE_INF'))\n isgood = isgood .and. eq(special_value(1.0_sp, 'IEEE_NEGATIVE_DENORMAL'), -special_value(1.0_sp, 'IEEE_POSITIVE_DENORMAL'))\n isgood = isgood .and. eq(special_value(1.0_sp, 'IEEE_NEGATIVE_NORMAL'), -special_value(1.0_sp, 'IEEE_POSITIVE_NORMAL'))\n isgood = isgood .and. eq(special_value(1.0_sp, 'IEEE_NEGATIVE_ZERO'), -special_value(1.0_sp, 'IEEE_POSITIVE_ZERO'))\n isgood = isgood .and. eq(abs(special_value(1.0_sp, 'IEEE_POSITIVE_ZERO')), 0.0_sp)\n isgood = isgood .and. eq(abs(special_value(1.0_sp, 'IEEE_NEGATIVE_ZERO')), 0.0_sp)\n\n ! -----------------------------------------------------\n ! Cumsum\n ! double precision\n dat1(:) = 1.0_dp\n dat2 = cumsum(dat1)\n isgood = isgood .and. (eq(dat2(1),1.0_dp))\n isgood = isgood .and. (eq(dat2(nn),real(nn,dp)))\n ! single precision\n sat1(:) = 2.0_sp\n sat2 = cumsum(sat1)\n isgood = isgood .and. (eq(sat2(1),2.0_sp))\n isgood = isgood .and. (eq(sat2(nn),real(2*nn,sp)))\n ! integer\n iat1(:) = 3\n iat2 = cumsum(iat1)\n isgood = isgood .and. (iat2(1) == 3)\n isgood = isgood .and. (iat2(nn) == 3*nn)\n ! complex\n cat1(:) = (1.0_dp,1.0_dp)\n cat2 = cumsum(cat1)\n isgood = isgood .and. (eq(real(cat2(1)),1.0_dp))\n isgood = isgood .and. (eq(aimag(cat2(nn)),real(nn,dp)))\n\n ! -----------------------------------------------------\n ! Range\n ! double precision\n dat1(:) = 1.0_dp\n dat2 = cumsum(dat1)\n dat1 = arange(real(nn,dp))\n isgood = isgood .and. all(eq(dat1,dat2))\n ! single precision\n sat1(:) = 2.0_dp\n sat2 = cumsum(sat1)\n sat1 = arange(real(nn,sp)) * 2.0_sp\n isgood = isgood .and. all(eq(sat1,sat2))\n ! integer\n iat1(:) = 1\n iat2 = cumsum(iat1) - 2\n iat1 = arange(-1,nn-2)\n isgood = isgood .and. all(iat1==iat2)\n ! allocatable out\n allocate(adat1(nn))\n adat1 = arange(real(nn,dp))\n\n ! -----------------------------------------------------\n ! Linspace\n ! double precision\n dat1 = arange(real(nn,dp))\n dat2 = linspace(1.0_dp,real(nn,dp),nn)\n isgood = isgood .and. all(eq(dat1,dat2))\n ! single precision\n sat1 = arange(real(nn,sp))/real(nn,sp)\n sat2 = linspace(0.01_sp,1.0_sp,nn)\n isgood = isgood .and. all(eq(sat1,sat2))\n ! integer\n iat1(:) = 3\n iat2 = cumsum(iat1)\n iat1 = linspace(3,3*nn,nn)\n isgood = isgood .and. all(iat1==iat2)\n\n ! -----------------------------------------------------\n ! isin\n dat1 = arange(real(nn,dp))\n isgood = isgood .and. isin(1.0_dp, dat1)\n isgood = isgood .and. isin(10.0_dp, dat1)\n isgood = isgood .and. isin(1.0_dp+0.1*epsilon(1.0_dp), dat1)\n isgood = isgood .and. .not. isin(1.1_dp, dat1)\n sat1 = arange(real(nn,sp))/real(nn,sp)\n isgood = isgood .and. isin(0.1_sp, sat1)\n isgood = isgood .and. isin(1.0_sp, sat1)\n iat1 = arange(nn)\n isgood = isgood .and. isin(1, iat1)\n isgood = isgood .and. isin(2_i4, iat1)\n chat1(:) = 'dummy'\n chat1(1) = 'one'\n chat1(2) = 'two'\n chat1(nn) = 'nn'\n isgood = isgood .and. isin('one', chat1)\n isgood = isgood .and. isin(' two ', chat1)\n isgood = isgood .and. .not. isin('100', chat1)\n\n ! -----------------------------------------------------\n ! isinloc\n dat1 = arange(real(nn,dp))\n isgood = isgood .and. (isinloc(1.0_dp, dat1) == 1)\n isgood = isgood .and. (isinloc(10.0_dp, dat1) == 10)\n isgood = isgood .and. (isinloc(1.0_dp+0.1*epsilon(1.0_dp), dat1) == 1)\n isgood = isgood .and. (isinloc(1.1_dp, dat1) == 0)\n sat1 = arange(real(nn,sp))/real(nn,sp)\n isgood = isgood .and. (isinloc(0.1_sp, sat1) == 10)\n isgood = isgood .and. (isinloc(1.0_sp, sat1) == nn)\n iat1 = arange(nn)\n isgood = isgood .and. (isinloc(1, iat1) == 1_i4)\n isgood = isgood .and. (isinloc(2_i4, iat1) == 2)\n chat1(:) = 'dummy'\n chat1(1) = 'one'\n chat1(2) = 'two'\n chat1(nn) = 'nn'\n isgood = isgood .and. (isinloc('one', chat1) == 1)\n isgood = isgood .and. (isinloc(' two ', chat1) == 2)\n isgood = isgood .and. (isinloc('100', chat1) == 0)\n\n write(*,*) ''\n if (isgood) then\n write(*,*) 'mo_utils ', color('o.k.', c_green)\n else\n write(*,*) 'mo_utils ', color('failed!', c_red)\n endif\n\nend program test_utils\n", "meta": {"hexsha": "c1b4837775321affefee7beb2c2dd1adc46844eb", "size": 20797, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/test_mo_utils/main.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_utils/main.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_utils/main.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": 32.9587955626, "max_line_length": 125, "alphanum_fraction": 0.5748906092, "num_tokens": 8563, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835452961427, "lm_q2_score": 0.8354835350552603, "lm_q1q2_score": 0.6980327459045229}} {"text": "MODULE MATLIB\n\tUSE NRTYPE\n \tIMPLICIT NONE\n \tCONTAINS\n \t!-----------------------------------------------------------\n \tSUBROUTINE FLIP(X)\n \tIMPLICIT NONE\n \tCOMPLEX(DP), DIMENSION(:) :: X\n \tX = X(UBOUND(X,1):LBOUND(X,1):-1)\n \tEND SUBROUTINE FLIP\n \t!-----------------------------------------------------------\n \tFUNCTION EYE(N) RESULT(M)\n \tIMPLICIT NONE\n \tINTEGER, INTENT(IN) :: N\n \tCOMPLEX(DP), DIMENSION(N,N) :: M\n \tINTEGER :: I,J\n \tDO I = 1,N\n \t\tDO J = 1,N\n\t\t\tIF (I.EQ.J) THEN\n \t\t\t\tM(I,J) = 1\n\t\t\tELSE\n\t\t\t\tM(I,J) = 0\n\t\t\tEND IF\n \t\tEND DO\n \tEND DO\n \tEND FUNCTION EYE\n \t!-----------------------------------------------------------\n \tFUNCTION ONES(N) RESULT(M)\n \tIMPLICIT NONE\n \tINTEGER, INTENT(IN) :: N\n \tCOMPLEX(DP), DIMENSION(N) :: M\n \tINTEGER :: I\n \tDO I = 1,N\n \t\tM(I) = 1\n \tEND DO\n \tEND FUNCTION ONES\n \t!-----------------------------------------------------------\n \tFUNCTION DIAG(X) RESULT(M)\n \tIMPLICIT NONE\n \tCOMPLEX(DP), DIMENSION(:) :: X\n \tCOMPLEX(DP), DIMENSION(SIZE(X,1),SIZE(X,1)) :: M\n \tINTEGER :: I, N\n \tN = SIZE(X,1)\n\tM = 0.\n \tDO I = 1,N\n \t\tM(I,I) = X(I)\n \tEND DO\n \tEND FUNCTION DIAG\n \t!-----------------------------------------------------------\n \tFUNCTION BAND(E,N) RESULT(M)\n \tIMPLICIT NONE\n \tINTEGER, INTENT(IN) :: N\n \tCOMPLEX(DP), INTENT(IN), DIMENSION(:) :: E\n \tCOMPLEX(DP), DIMENSION(N,N) :: M\n \tINTEGER :: I, J, Q, ND\n \tND = SIZE(E)\n\tIF (MOD(Nd,2).EQ.0) THEN\n\t\tSTOP 'NDIAG(E,N) : LEN(E) MUST BE ODD'\n\tEND IF\n\tM = 0.\n\tQ = (Nd-1)/2\t\t!Nd = 3 gives Q = 2\n\tDO J = 1,N\n\t\tM(J,J) = E(Q+1)\n\tEND DO\n \tDO I = 1,Q\n\t\tDO J = 1,N-I\n\t\t\tM(J+I,J) = E(Q+1-I)\n\t\t\tM(J,J+I) = E(Q+1+I)\n \t\tEND DO\n\tEND DO\n \tEND FUNCTION\n \t!-----------------------------------------------------------\n \tFUNCTION INV(A) RESULT(M)\n \tIMPLICIT NONE\n \tCOMPLEX(DP), DIMENSION(:,:), INTENT(IN) :: A\n \tCOMPLEX(DP), DIMENSION(SIZE(A,1), SIZE(A,2)) :: M\n \tCOMPLEX(DP), DIMENSION(SIZE(A,1)) :: WORK\n \tCOMPLEX(DP), DIMENSION(SIZE(A,1)) :: IPIV\n \tINTEGER :: N, INFO\n \tM = A\n \tN = SIZE(A,1)\n \tCALL ZGETRF(N,N,M,N,IPIV,INFO)\t\t!LAPACK ROUTINE FOR LU FACTORIZATION\n \tIF (INFO/= 0) THEN\n \t\tSTOP \"WARNING : Input Matrix is singular !\"\n \tEND IF\n \tCALL ZGETRI(N,M,N,IPIV,WORK,N,INFO)\t!INVERSE OF LU\n \tIF (INFO/= 0) THEN\n \t\tSTOP \"WARNING : Input Matrix is singular !\"\n \tEND IF\n \tEND FUNCTION INV\n\t !-----------------------------------------------------------\nEND MODULE\n", "meta": {"hexsha": "38ae37a9f5e49f5e5bbf0f48668df65cdbd1fb72", "size": 2384, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "Parabolic_Equation/2DPE/PERF/matlib.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/matlib.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/matlib.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": 25.6344086022, "max_line_length": 71, "alphanum_fraction": 0.4660234899, "num_tokens": 875, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199714402813, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.6980093271929726}} {"text": "\r\nmodule mod_echwsamples\r\n\r\n#include \"Config.hpp\"\r\n\r\n \r\n !===================================================================================85\r\n !---------------------------- DESCRIPTION ------------------------------------------85\r\n !\r\n !\r\n !\r\n ! Module name:\r\n ! 'mod_echwsamples'\r\n ! \r\n ! Purpose:\r\n ! Mathematical representation and computation\r\n ! of power weather sample of exponential chirp\r\n ! wave radar signal.\r\n ! This module also contains subroutines which\r\n ! perform computation of signal statistics.\r\n ! History:\r\n ! Date: 01-11-2017\r\n ! Time: 10:00 GMT+2\r\n !\r\n ! Version:\r\n !\r\n ! Major: 1\r\n ! Minor: 0\r\n ! Micro: 0\r\n !\r\n ! Author: \r\n ! Bernard Gingold\r\n ! \r\n ! References:\r\n ! \r\n ! Doppler Radar and Weather Observations\r\n ! Richard L. Dvorak, Dusan S. Zrnic\r\n ! pages 67-72 \r\n ! \r\n ! \r\n ! E-mail:\r\n ! \r\n ! beniekg@gmail.com\r\n !==================================================================================85\r\n \r\n ! Tab:5 col - Type and etc.. definitions\r\n ! Tab:10,11 col - Type , function and subroutine code blocks.\r\n implicit none\r\n private\r\n use module_kinds\r\n use module_logger, only : log_startup, &\r\n log_UsrMsg, &\r\n log_shutdown\r\n \r\n use ISO_FORTRAN_ENV, only : stderr=>ERROR_UNIT, &\r\n stdout=>OUTPUT_UNIT\r\n use IFPORT, only : TRACEBACKQQ\r\n use mod_timer\r\n use mod_constants, only : LAM_PINF\r\n \r\n public :: assignment (=)\r\n public :: operator (/=)\r\n public :: operator (==)\r\n public :: operator (>)\r\n public :: operator (<)\r\n \r\n !=====================================================59\r\n ! File and module information:\r\n ! version,creation and build date, author,description\r\n !=====================================================59\r\n \r\n ! Major version\r\n integer(I32P), parameter :: MOD_ECHWSAMPLES_MAJOR = 1\r\n \r\n ! Minor version\r\n integer(I32P), parameter :: MOD_ECHWSAMPLES_MINOR = 0\r\n \r\n ! Micro version\r\n integer(I32P), parameter :: MOD_ECHWSAMPLES_MICRO = 0\r\n \r\n ! Module full version\r\n integer(I32P), parameter :: MOD_ECHWSAMPLES_FULLVER = 1000*MOD_ECHWSAMPLES_MAJOR+100*MOD_ECHWSAMPLES_MINOR+ &\r\n 10*MOD_ECHWSAMPLES_MICRO\r\n \r\n ! Module creation date\r\n character(*), parameter :: MOD_ECHWSAMPLES_CREATE_DATE = \"01-11-2017 10:08 +00200 (WED 01 NOV 2017 GMT+2)\"\r\n \r\n ! Module build date (should be set after successful compilation)\r\n character(*), parameter :: MOD_ECHWSAMPLES_BUILD_DATE = \" \"\r\n \r\n ! Module author short info\r\n character(*), parameter :: MOD_ECHWSAMPLES_AUTHOR = \"Programmer: Bernard Gingold e-mail: beniekg@gmail.com\"\r\n \r\n ! Module short description\r\n character(*), parameter :: MOD_ECHWSAMPLES_DESCRIPT = \" Exponential chirp weather samples.\"\r\n \r\n !====================================================\r\n ! Type: ECSWSamples_t\r\n !====================================================\r\n \r\n type, public :: ECSWSamples_t\r\n \r\n private\r\n \r\n ! Number of echoes\r\n integer(I32P) :: m_nechoes\r\n \r\n ! Number of composed samples\r\n integer(I32P) :: m_size\r\n \r\n ! Number of scatterers\r\n integer(I32P) :: m_scatnum\r\n \r\n ! Time duration of samples interval\r\n real(R64P) :: m_Ts\r\n \r\n ! Time duration of single sample\r\n real(R64P) :: m_ths\r\n \r\n ! Samples indexing integral array sampID\r\n integer(I32P), allocatable, dimension(:) :: m_sampID\r\n!DIR$ ATTRIBUTES ALIGN : 64 :: m_sampID\r\n \r\n ! Cached sample signal components\r\n \r\n ! Complex amplitude\r\n complex(R64P), allocatable, dimension(:) :: m_Ai\r\n!DIR$ ATTRIBUTES ALIGN : 64 :: m_Ai\r\n \r\n ! Samples (IQ) components, one per sample\r\n complex(R64P), allocatable, dimension(:) :: m_Wi\r\n!DIR$ ATTRIBUTES ALIGN : 64 :: m_Wi\r\n \r\n ! Complex exponential term itself beign a single complex value\r\n ! of function related to scaterrer distance and to specific bandwidth\r\n complex(R64P), allocatable, dimension(:) :: m_cexpt\r\n!DIR$ ATTRIBUTES ALIGN : 64 :: m_cexpt\r\n \r\n ! Output members\r\n ! Power signal composition of sample train (per single sample)\r\n complex(R64P), allocatable, dimension(:) :: m_Vsamp\r\n!DIR$ ATTRIBUTES ALIGN : 64 :: m_Vsamp\r\n \r\n ! Averaged power specific frequencies of sample train\r\n complex(R64P), allocatable, dimension(:) :: m_Vsampavg\r\n!DIR$ ATTRIBUTES ALIGN : 64 :: m_Vsampavg\r\n \r\n ! built indicator (logical)\r\n logical(I32P) :: m_isbuilt\r\n \r\n contains\r\n \r\n !=====================================================\r\n ! Construction, copying, destruction\r\n !=====================================================\r\n \r\n procedure, pass(this), public :: init\r\n \r\n procedure, pass(this), public :: copy\r\n \r\n procedure, pass(this), public :: destroy\r\n \r\n !==================================================\r\n ! Getters\r\n !==================================================\r\n procedure, pass(this), public :: get_nechoes\r\n \r\n procedure, pass(this), public :: get_size\r\n \r\n procedure, pass(this), public :: get_scatnum\r\n \r\n procedure, pass(this), public :: get_Ts\r\n \r\n procedure, pass(this), public :: get_ths\r\n \r\n procedure, pass(this), public :: get_sampID\r\n \r\n procedure, pass(this), public :: get_Ai\r\n \r\n procedure, pass(this), public :: get_Wi\r\n \r\n procedure, pass(this), public :: get_cexpt\r\n \r\n procedure, pass(this), public :: get_Vsamp\r\n \r\n procedure, pass(this), public :: get_Vsampavg\r\n \r\n !================================================ \r\n ! Computational procedures\r\n !================================================\r\n \r\n procedure, pass(this), public :: compute_Vsamp\r\n \r\n procedure, pass(this), public :: compute_Vsampavg\r\n \r\n !=================================================\r\n ! Read/write procedures\r\n !=================================================\r\n \r\n procedure, nopass, public :: read_samples\r\n \r\n procedure, nopass, public :: write_samples\r\n \r\n end type ECSWSamples_t\r\n \r\n !==================================================\r\n ! Module operators\r\n !==================================================\r\n \r\n interface assignment (=)\r\n module procedure assign_samples\r\n end interface\r\n \r\n interface operator (/=)\r\n module procedure samples_neq_samples\r\n end interface\r\n \r\n interface operator (==)\r\n module procedure samples_eq_samples\r\n end interface\r\n \r\n interface operator (>)\r\n module procedure samples_gt_samples\r\n end interface\r\n \r\n interface operator (<)\r\n module procedure samples_lt_samples\r\n end interface\r\n \r\n contains\r\n \r\n !========================================!\r\n ! Implementation !\r\n !========================================!\r\n \r\n !=================================================!\r\n ! @subroutine: init \r\n ! Initialization of object state. \r\n ! Allocation and initialization to default values\r\n ! of complex arrays (output)\r\n ! Copying of cached samples component arrays.\r\n ! @Warning\r\n ! Upon detection of non-fatal error\r\n ! variable 'err' will be set to -1\r\n ! Upon detection of fatal error like\r\n ! failed memory allocation 'STOP'\r\n ! will be executed.\r\n ! Values of variable 'err'\r\n ! 1) -1 -- Object built already\r\n ! 2) -2 -- Invalid argument (any of them)\r\n ! 3) -3 -- Floating-point arithmentic error \r\n ! (general error) (not in this scope)\r\n ! 4) -4 -- Overflow\r\n ! 5) -5 -- Underflow\r\n ! 6) -6 -- Inexact\r\n ! 7) -7 -- Denormal\r\n ! 8) -8 -- Cancellation error (cadna)\r\n !=================================================!\r\n subroutine init(this,nechoes,size,scatnum,Ts,ths,Ai, &\r\n Wi,cexpt,logging,filename,append,dbg,verbose,err )\r\n implicit none\r\n class(ECSWSamples_t), intent(inout) :: this\r\n integer(I32P), intent(in) :: nechoes,size,scatnum\r\n real(R64P), intent(in) :: Ts,ths\r\n complex(R64P), dimension(size), intent(in) :: Ai\r\n!DIR$ ASSUME_ALIGNED Ai:64\r\n complex(R64P), dimension(size), intent(in) :: Wi\r\n!DIR$ ASSUME_ALIGNED Wi:64\r\n complex(R64P), dimension(size), intent(in) :: cexpt\r\n!DIR$ ASSUME_ALIGNED cexpt:64\r\n logical(I32P), intent(in) :: logging\r\n character(len=*), intent(in) :: filename\r\n logical(I32P), intent(in) :: append,dbg,verbose\r\n integer(I32P), intent(inout) :: err\r\n ! Locals\r\n character(len=40) :: sdate,stime\r\n character(len=256) :: emsg\r\n integer(I32P) :: i,aerr\r\n integer(BOOL) :: ifail\r\n logical(I32P) :: bfail\r\n ! Start of executable sttements\r\n if(err < 0) err = 0\r\n if(this%m_isbuilt == .true.) then\r\n if(logging == .true.) then\r\n call log_startup(filename,append)\r\n call log_UsrMsg(\"logger:283, In->mod_echwsamples/init: ECSWSamples_t already initialized!!\")\r\n call log_shutdown()\r\n else if(verbose == .true.) then\r\n \r\n call DATE_AND_TIME(date=sdate,time=stime)\r\n write(stderr,*) \"===========================NON-FATAL==========================\"\r\n write(sdterr,*) \" ( mod_echwsamples/init:283, ECSWSample_t already initialized!!)\"\r\n write(stderr,*) \" ( Non-Fatal Error at:) \", &\r\n sdate(1:4),\"-\",sdate(5:6),\"-\",sdate(7:8), \" \", &\r\n stime(1:2),\":\",stime(3:4),\":\",stime(5:6)\r\n write(stderr,*) \"===========================NON-FATAL==========================\"\r\n end if\r\n err = -1\r\n return\r\n end if\r\n if(nechoes < 1 .OR. &\r\n size <= 1 .OR. &\r\n Ts <= 0._R64P .OR. &\r\n ths <= 0._R64P ) then\r\n if(logging == .true.) then\r\n call log_startup(filename,append)\r\n call log_UsrMsg(\"logger:303, In->mod_echwsamples/init: Invalid argument(s) in subroutine: init.\")\r\n call log_shutdown()\r\n else if(verbose == .true.) then\r\n call DATE_AND_TIME(date=sdate,time=stime)\r\n write(stderr,*) \"===========================NON-FATAL==========================\"\r\n write(sdterr,*) \" ( mod_echwsamples/init:303, Invalid argument(s) in subroutine: init.)\"\r\n write(stderr,*) \" ( Non-Fatal Error at:) \", &\r\n sdate(1:4),\"-\",sdate(5:6),\"-\",sdate(7:8), \" \", &\r\n stime(1:2),\":\",stime(3:4),\":\",stime(5:6)\r\n write(stderr,*) \"===========================NON-FATAL==========================\"\r\n end if\r\n err = -2\r\n return\r\n end if\r\n ! Begin construction\r\n this%m_nechoes = nechoes\r\n this%m_size = size\r\n this%m_scatnum = scatnum\r\n this%m_Ts = Ts\r\n this%m_ths = this%m_Ts/REAL(size,R64P)\r\n ! Array members allocation\r\n associate(dim1=>this%m_size)\r\n allocate(this%m_sampID(dim1), &\r\n this%m_Ai(dim1), &\r\n this%m_Wi(dim1), &\r\n this%m_cexpt(dim1), &\r\n this%m_Vsamp(dim1), &\r\n this%m_Vsampavg(dim1), &\r\n STAT=aerr, &\r\n ERRMSG=emsg)\r\n end associate\r\n if(aerr /= 0) then\r\n if(logging == .true.) then\r\n call log_startup(filename,append)\r\n call log_UsrMsg(\"logger:338,In->mod_echwsamples/init: Memory allocation failure!!\")\r\n call log_shutdown()\r\n else if(verbose == .true.) then\r\n call DATE_AND_TIME(date=sdate,time=stime)\r\n write(stderr,*) \"===========================FATAL==========================\"\r\n write(stderr,*) \" ( mod_echwsamples/init:338, Memory allocation failure)\"\r\n write(stderr,*) \" System message: \", emsg\r\n write(stderr,*) \" ( Fatal Error at:) \", &\r\n sdate(1:4),\"-\",sdate(5:6),\"-\",sdate(7:8), \" \", &\r\n stime(1:2),\":\",stime(3:4),\":\",stime(5:6)\r\n write(stderr,*) \"===========================FATAL==========================\"\r\n end if\r\n!DIR$ IF (SHOW_CALLSTACK .EQ. 1)\r\n call TRACEBACKQQ(STRING=\"FATAL-ERROR\", USER_EXIT_CODE= -1)\r\n!DIR$ ENDIF\r\n ERROR STOP \"mod_echwsamples/init:338 -> [FATAL-ERROR]: Terminating execution!!\"\r\n end if\r\n ! Arrays initialization \r\n!DIR$ SIMD\r\n do i = 1, this%m_size\r\n this%m_sampID(i) = i\r\n this%m_Ai(i) = A(i)\r\n this%m_Wi(i) = Wi(i)\r\n this%m_cexpt(i) = cexpt(i)\r\n this%m_Vsamp(i) = DCMPLX(LAM_PIMF,LAM_PINF)\r\n this%m_Vsampavg(i) = DCMPLX(LAM_PINF,LAM_PINF)\r\n end do\r\n this%m_isbuilt = .true.\r\n if(dbg == .true.) then\r\n print*, \"samples ID: \", this%m_sampID\r\n print*, \"Complex amplitude: \", this%m_Ai\r\n print*, \"IQ components: \", this%m_Wi\r\n print*, \"Exponential term: \", this%m_cexpt\r\n print*, \"V samp (default init): \", this%m_Vsamp\r\n print*, \"V samp avg (default init): \", this%m_Vsampavg\r\n end if\r\n end subroutine\r\n \r\n !=================================================!\r\n ! @subroutine: copy \r\n ! @Purpose:\r\n ! Copying of object state.\r\n ! Deep copy semantics in use.\r\n ! @Warning\r\n ! Upon detection of non-fatal error\r\n ! variable 'err' will be set to -1\r\n ! Upon detection of fatal error like\r\n ! failed memory allocation 'STOP'\r\n ! will be executed.\r\n ! Values of variable 'err'\r\n ! 1) -1 -- Object built already\r\n ! 2) -2 -- Invalid argument (any of them)\r\n ! 3) -3 -- Floating-point arithmentic error \r\n ! (general error) (not in this scope)\r\n ! 4) -4 -- Overflow\r\n ! 5) -5 -- Underflow\r\n ! 6) -6 -- Inexact\r\n ! 7) -7 -- Denormal\r\n ! 8) -8 -- Cancellation error (cadna)\r\n !=================================================! \r\n subroutine copy(this,other,logging,filename,append,err)\r\n implicit none\r\n class(ECSWSamples_t), intent(inout) :: this\r\n class(ECSWSamples_t), intent(in) :: other\r\n logical(I32P), intent(in) :: logging\r\n character(len=*), intent(in) :: filename\r\n logical(I32P), intent(in) :: append\r\n integer(I32P), intent(inout) :: err\r\n ! Locals\r\n character(len=40) :: sdate,stime\r\n ! Start of executable statements\r\n if(err < 0) err = 0\r\n if(this%m_isbuilt == .true.) then\r\n if(logging == .true.) then\r\n call log_startup(filename,append)\r\n call log_UsrMsg(\"logger:413, In->mod_echwsamples/copy: ECSWSamples_t already initialized!!\")\r\n call log_shutdown()\r\n else if(verbose == .true.) then\r\n \r\n call DATE_AND_TIME(date=sdate,time=stime)\r\n write(stderr,*) \"===========================NON-FATAL==========================\"\r\n write(sdterr,*) \" ( mod_echwsamples/copy:413, ECSWSample_t already initialized!!)\"\r\n write(stderr,*) \" ( Non-Fatal Error at:) \", &\r\n sdate(1:4),\"-\",sdate(5:6),\"-\",sdate(7:8), \" \", &\r\n stime(1:2),\":\",stime(3:4),\":\",stime(5:6)\r\n write(stderr,*) \"===========================NON-FATAL==========================\"\r\n end if\r\n err = -1\r\n return\r\n end if\r\n ! Begin copy-construction\r\n this%m_nechoes = other%m_nechoes\r\n this%m_size = other%m_size\r\n this%m_scatnum = other%m_scatnum\r\n this%m_Ts = other%m_Ts\r\n this%m_ths = other%m_ths\r\n this%m_sampID = other%m_sampID\r\n this%m_Ai = other%m_Ai\r\n this%m_Wi = other%m_Wi\r\n this%m_cexpt = other%m_cexpt\r\n this%m_Vsamp = other%m_Vsamp\r\n this%m_Vsampavg = other%m_Vsampavg\r\n this%m_isbuilt = .true.\r\n end subroutine\r\n \r\n !=================================================!\r\n ! @subroutine: destroy \r\n ! @Purpose:\r\n ! Destroys object state by allocatble\r\n ! arrays deallocation and setting\r\n ! member scalar variables to default values.\r\n ! @Warning\r\n ! Upon detection of non-fatal error\r\n ! variable 'err' will be set to -1\r\n ! Upon detection of fatal error like\r\n ! failed memory allocation 'STOP'\r\n ! will be executed.\r\n ! Values of variable 'err'\r\n ! 1) -1 -- Object built already\r\n ! 2) -2 -- Invalid argument (any of them)\r\n ! 3) -3 -- Floating-point arithmentic error \r\n ! (general error) (not in this scope)\r\n ! 4) -4 -- Overflow\r\n ! 5) -5 -- Underflow\r\n ! 6) -6 -- Inexact\r\n ! 7) -7 -- Denormal\r\n ! 8) -8 -- Cancellation error (cadna)\r\n !=================================================! \r\n subroutine destroy(this,logging,filename,append,err)\r\n implicit none\r\n class(ECSWSamples_t), intent(inout) :: this\r\n logical(I32P), intent(in) :: logging\r\n character(len=*), intent(in) :: filename\r\n logical(I32P), intent(in) :: append\r\n integer(I32P), intent(inout) :: err\r\n ! Locals\r\n character(len=40) :: sdate,stime\r\n character(len=256) :: emsg\r\n integer(I32P) :: derr\r\n ! Start of executable statements\r\n ! Sanity check on err parameter\r\n if(err < 0) err = 0\r\n if(this%m_isbuilt == .true.) then\r\n if(logging == .true.) then\r\n call log_startup(filename,append)\r\n call log_UsrMsg(\"logger:483, In->mod_echwsamples/destroy: ECSWSamples_t already destroyed!!\")\r\n call log_shutdown()\r\n else if(verbose == .true.) then\r\n \r\n call DATE_AND_TIME(date=sdate,time=stime)\r\n write(stderr,*) \"===========================NON-FATAL==========================\"\r\n write(sdterr,*) \" ( mod_echwsamples/destroy:483, ECSWSample_t already destroyed!!)\"\r\n write(stderr,*) \" ( Non-Fatal Error at:) \", &\r\n sdate(1:4),\"-\",sdate(5:6),\"-\",sdate(7:8), \" \", &\r\n stime(1:2),\":\",stime(3:4),\":\",stime(5:6)\r\n write(stderr,*) \"===========================NON-FATAL==========================\"\r\n end if\r\n err = -1\r\n return\r\n end if\r\n this%m_nechoes = 0\r\n this%m_size = 0\r\n this%m_scatnum = 0\r\n this%m_Ts = LAM_PINF\r\n this%m_ths = LAM_PINF\r\n deallocate(this%m_sampID, &\r\n this%m_Ai, &\r\n this%m_Wi, &\r\n this%m_cexpt, &\r\n this%m_Vsamp, &\r\n this%m_Vsampavg, &\r\n STAT=derr, &\r\n ERRMSG=emsg )\r\n if(derr /= 0) then\r\n if(logging == .true.) then\r\n call log_startup(filename,append)\r\n call log_UsrMsg(\"logger:514,In->mod_echwsamples/destroy: Memory deallocation failure!!\")\r\n call log_shutdown()\r\n else if(verbose == .true.) then\r\n call DATE_AND_TIME(date=sdate,time=stime)\r\n write(stderr,*) \"===========================FATAL==========================\"\r\n write(stderr,*) \" ( mod_echwsamples/destroy:514, Memory deallocation failure)\"\r\n write(stderr,*) \" System message: \", emsg\r\n write(stderr,*) \" ( Fatal Error at:) \", &\r\n sdate(1:4),\"-\",sdate(5:6),\"-\",sdate(7:8), \" \", &\r\n stime(1:2),\":\",stime(3:4),\":\",stime(5:6)\r\n write(stderr,*) \"===========================FATAL==========================\"\r\n end if\r\n!DIR$ IF (SHOW_CALLSTACK .EQ. 1)\r\n call TRACEBACKQQ(STRING=\"FATAL-ERROR\", USER_EXIT_CODE= -1)\r\n!DIR$ ENDIF\r\n ERROR STOP \"mod_echwsamples/destroy:514 -> [FATAL-ERROR]: Terminating execution!!\"\r\n end if\r\n this%m_isbuilt = .false.\r\n end subroutine\r\n \r\n !====================================================\r\n ! @function: pure get_nechoes\r\n ! @Puprose:\r\n ! getter\r\n !====================================================\r\n!DIR$ IF (USE_INLINING .EQ. 1)\r\n !DIR$ ATTRIBUTES INLINE :: get_nechoes\r\n!DIR$ ENDIF\r\n pure function get_nechoes(this) result(nechoes)\r\n implicit none\r\n class(ECSWSamples_t), intent(in) :: this\r\n ! Locals\r\n integer(I32P) :: nechoes\r\n ! Start of executable statemetns\r\n nechoes = this%m_nechoes\r\n end function\r\n \r\n !====================================================\r\n ! @function: pure get_size\r\n ! @Puprose:\r\n ! getter\r\n !====================================================\r\n!DIR$ IF (USE_INLINING .EQ. 1)\r\n !DIR$ ATTRIBUTES INLINE :: get_size\r\n!DIR$ ENDIF\r\n pure function get_size(this) result(nsize)\r\n implicit none\r\n class(ECSWSamples_t), intent(in) :: this\r\n ! Locals\r\n integer(I32P) :: nsize\r\n ! Start of executable statemetns\r\n nsize = this%m_size\r\n end function\r\n \r\n !====================================================\r\n ! @function: pure get_scatnum\r\n ! @Puprose:\r\n ! getter\r\n !====================================================\r\n!DIR$ IF (USE_INLINING .EQ. 1)\r\n !DIR$ ATTRIBUTES INLINE :: get_scatnum\r\n!DIR$ ENDIF\r\n pure function get_scatnum(this) result(scatnum)\r\n implicit none\r\n class(ECSWSamples_t), intent(in) :: this\r\n ! Locals\r\n integer(I32P) :: scatnum\r\n ! Start of executable statements\r\n scatnum = this%m_scatnum\r\n end function\r\n \r\n !====================================================\r\n ! @function: pure get_Ts\r\n ! @Puprose:\r\n ! getter\r\n !====================================================\r\n!DIR$ IF (USE_INLINING .EQ. 1)\r\n !DIR$ ATTRIBUTES INLINE :: get_Ts\r\n!DIR$ ENDIF\r\n pure function get_Ts(this) result(Ts)\r\n implicit none\r\n class(ECSWSamples_t), intent(in) :: this\r\n ! Locals\r\n real(R64P) :: Ts\r\n ! Start of executable statemetns\r\n Ts = this%m_Ts\r\n end function\r\n \r\n !====================================================\r\n ! @function: pure get_ths\r\n ! @Puprose:\r\n ! getter\r\n !====================================================\r\n!DIR$ IF (USE_INLINING .EQ. 1)\r\n !DIR$ ATTRIBUTES INLINE :: get_ths\r\n!DIR$ ENDIF\r\n pure function get_ths(this) result(ths)\r\n implicit none\r\n class(ECSWSamples_t), intent(in) :: this\r\n ! Locals\r\n real(R64P) :: ths\r\n ! Start of executable statemetns\r\n ths = this%m_ths\r\n end function\r\n \r\n !====================================================\r\n ! @function: pure get_sampID\r\n ! @Puprose:\r\n ! getter\r\n !====================================================\r\n!DIR$ IF (USE_INLINING .EQ. 1)\r\n !DIR$ ATTRIBUTES INLINE :: get_sampID\r\n!DIR$ ENDIF\r\n pure function get_sampID(this) result(sampID)\r\n implicit none\r\n class(ECSWSamples_t), intent(in) :: this\r\n ! Locals\r\n integer(I32P), allocatable, dimension(:) :: sampID\r\n!DIR$ ATTRIBUTES ALIGN : 64 :: sampID\r\n ! Start of executable statements\r\n sampID = this%m_sampID\r\n end function\r\n \r\n !====================================================\r\n ! @function: pure get_Ai\r\n ! @Puprose:\r\n ! getter\r\n !====================================================\r\n!DIR$ IF (USE_INLINING .EQ. 1)\r\n !DIR$ ATTRIBUTES INLINE :: get_Ai\r\n!DIR$ ENDIF\r\n pure function get_Ai(this) result(Ai)\r\n implicit none\r\n class(ECSWSamples_t), intent(in) :: this\r\n ! Locals\r\n complex(R64P), allocatable, dimension(:) :: Ai\r\n!DIR$ ATTRIBUTES ALIGN : 64 :: Ai\r\n ! Start of executable statemetns\r\n Ai = this%m_Ai\r\n end function\r\n \r\n !====================================================\r\n ! @function: pure get_Wi\r\n ! @Puprose:\r\n ! getter\r\n !====================================================\r\n!DIR$ IF (USE_INLINING .EQ. 1)\r\n !DIR$ ATTRIBUTES INLINE :: get_Wi\r\n!DIR$ ENDIF\r\n pure function get_Wi(this) result(Wi)\r\n implicit none\r\n class(ECSWSamples_t), intent(in) :: this\r\n ! Locals\r\n complex(R64P), allocatable, dimension(:) :: Wi\r\n!DIR$ ATTRIBUTES ALIGN : 64 :: Wi\r\n ! Start of executable statemetns\r\n Wi = this%m_Wi\r\n end function\r\n \r\n !====================================================\r\n ! @function: pure get_cexpt\r\n ! @Puprose:\r\n ! getter\r\n !====================================================\r\n!DIR$ IF (USE_INLINING .EQ. 1)\r\n !DIR$ ATTRIBUTES INLINE :: get_cexpt\r\n!DIR$ ENDIF\r\n pure function get_cexpt(this) result(cexpt)\r\n implicit none\r\n class(ECSWSamples_t), intent(in) :: this\r\n ! Locals\r\n complex(R64P), allocatable, dimension(:) :: cexpt\r\n!DIR$ ATTRIBUTES ALIGN : 64 :: cexpt\r\n ! Start of executable statemetns\r\n cexpt = this%m_cexpt\r\n end function\r\n \r\n !====================================================\r\n ! @function: pure get_Vsamp\r\n ! @Puprose:\r\n ! getter\r\n !====================================================\r\n!DIR$ IF (USE_INLINING .EQ. 1)\r\n !DIR$ ATTRIBUTES INLINE :: get_Vsamp\r\n!DIR$ ENDIF\r\n pure function get_Vsamp(this) result(Vsamp)\r\n implicit none\r\n class(ECSWSamples_t), intent(in) :: this\r\n ! Locals\r\n complex(R64P), allocatable, dimension(:) :: Vsamp\r\n!DIR$ ATTRIBUTES ALIGN : 64 :: Vsamp\r\n ! Start of executable statements\r\n Vsamp = this%m_Vsamp\r\n end function\r\n \r\n !====================================================\r\n ! @function: pure get_Vsampavg\r\n ! @Puprose:\r\n ! getter\r\n !====================================================\r\n!DIR$ IF (USE_INLINING .EQ. 1)\r\n !DIR$ ATTRIBUTES INLINE :: get_Vsampavg\r\n!DIR$ ENDIF\r\n pure function get_Vsampavg(this) result(Vsampavg)\r\n implicit none\r\n class(ECSWSamples_t), intent(in) :: this\r\n ! Locals\r\n complex(R64P), allocatable, dimension(:) :: Vsampavg\r\n!DIR$ ATTRIBUTES ALIGN : 64 :: Vsampavg\r\n ! Start of executable statemetms\r\n Vsampavg = this%m_Vsampavg\r\n end function\r\n \r\n !====================================================\r\n ! @function: pure get_isbuilt\r\n ! @Puprose:\r\n ! getter\r\n !====================================================\r\n!DIR$ IF (USE_INLINING .EQ. 1)\r\n !DIR$ ATTRIBUTES INLINE :: get_isbuilt\r\n!DIR$ ENDIF\r\n pure function get_isbuilt(this) result(isbuilt)\r\n implicit none\r\n class(ECSWSamples_t), intent(in) :: this\r\n ! Locals\r\n logical(I32P) :: isbuilt\r\n ! Start of executable statemetns\r\n isbuilt = this%m_isbuilt\r\n end function\r\n \r\n !=================================================!\r\n ! @subroutine: compute_Vsamp \r\n ! @Purpose:\r\n ! Performs computation of weather radar\r\n ! signal samples and stores them in\r\n ! member array m_Vsamp\r\n ! @Warning\r\n ! Upon detection of non-fatal error\r\n ! variable 'err' will be set to -1\r\n ! Upon detection of fatal error like\r\n ! failed memory allocation 'STOP'\r\n ! will be executed.\r\n ! Values of variable 'err'\r\n ! 1) -1 -- Object built already\r\n ! 2) -2 -- Invalid argument (any of them)\r\n ! 3) -3 -- Floating-point arithmentic error \r\n ! (general error) (in this case)\r\n ! 4) -4 -- Overflow\r\n ! 5) -5 -- Underflow\r\n ! 6) -6 -- Inexact\r\n ! 7) -7 -- Denormal\r\n ! 8) -8 -- Cancellation error (cadna)\r\n !=================================================! \r\n subroutine compute_Vsamp(this,err,fpflags,verbose)\r\n use mod_constants, only : LAM_ISQRT2,LAM_ZC\r\n!DIR$ IF (USE_IEEE_EXCEPTION_HANDLING .EQ. 1)\r\n use, intrinsic :: ieee_exception\r\n!DIR$ ENDIF\r\n implicit none\r\n class(ECSWSamples_t), intent(inout) :: this\r\n integer(I32P), intent(inout) :: err\r\n logical(I32P), dimension(5), intent(inout), optional :: fpflags\r\n logical(I32P), intent(in) :: verbose\r\n ! Locals\r\n complex(R64P) :: tmp\r\n integer(I32P) :: i,j\r\n!DIR$ IF (USE_IEEE_EXCEPTION_HANDLING .EQ. 1)\r\n type(ieee_status_type) :: status_value\r\n!DIR$ ENDIF\r\n ! Start of executable statements\r\n ! Sanity check on input arguments\r\n if(err < 0) err = 0\r\n if(present(fpflags) == .true.) then\r\n if(ANY(fpflags) == .true.) then\r\n fpflags = .false.\r\n end if\r\n end if\r\n tmp = LAM_ZC\r\n!DIR$ IF (USE_IEEE_EXCEPTION_HANDLING .EQ. 1)\r\n if(present(fpflags) == .true.) then\r\n call ieee_get_status(status_value)\r\n call ieee_set_handling_mode(ieee_all,.false.)\r\n call ieee_set_flags(ieee_all,fpflags)\r\n else\r\n WRITE(stderr,*) \"mod_echwsamples/compute_Vsamp:801 -- optional parameter: fpflags - not present!!\"\r\n end if\r\n!DIR$ ENDIF\r\n do i = 1, this%m_size\r\n!DIR$ SIMD\r\n do j = 1, this%m_size\r\n tmp = tmp+(this%m_Ai(j)*this%m_Wi(j)*this%m_cexpt(j))\r\n tmp = tmp*LAM_ISQRT2\r\n this%m_Vsamp(i) = tmp\r\n end do\r\n end do\r\n!DIR$ IF (USE_IEEE_EXCEPTION_HANDLING .EQ. 1)\r\n if(present(fpflags) == .true.) then\r\n call ieee_get_flag(ieee_all,fpflags)\r\n if(ANY(fpflags) == .true.) then\r\n if(present(verbose) .AND. verbose == .true.) then\r\n WRITE(stderr,*) \"==============================================================================\"\r\n WRITE(stderr,*) \" mod_echwsamples/compute_Vsamp:812 -- Floating-point exception(s) occurred!!\"\r\n WRITE(stderr,*) \"===============================================================================\"\r\n end if\r\n err = -3\r\n end if\r\n end if\r\n!DIR$ ENDIF \r\n end subroutine\r\n \r\n !=================================================!\r\n ! @subroutine: compute_Vsampavg \r\n ! @Purpose:\r\n ! Performs computation of weather radar\r\n ! signal samples averaged over frequency cycle\r\n ! and stores them in member array mVsampavg.\r\n ! \r\n ! @Warning\r\n ! Upon detection of non-fatal error\r\n ! variable 'err' will be set to -1\r\n ! Upon detection of fatal error like\r\n ! failed memory allocation 'STOP'\r\n ! will be executed.\r\n ! Values of variable 'err'\r\n ! 1) -1 -- Object built already\r\n ! 2) -2 -- Invalid argument (any of them)\r\n ! 3) -3 -- Floating-point arithmentic error \r\n ! (general error) (in this case)\r\n ! 4) -4 -- Overflow\r\n ! 5) -5 -- Underflow\r\n ! 6) -6 -- Inexact\r\n ! 7) -7 -- Denormal\r\n ! 8) -8 -- Cancellation error (cadna)\r\n ! 9) -9 -- Optional argument not present\r\n !=================================================!\r\n subroutine compute_Vsampavg(this,err,fpflags,verbose)\r\n use mod_constants, only : LAM_HR64P,LAM_ZC\r\n!DIR$ IF (USE_IEEE_EXCEPTION_HANDLING .EQ. 1)\r\n use, intrinsic :: ieee_exception\r\n!DIR$ ENDIF\r\n implicit none\r\n class(ECSWSamples_t), intent(inout) :: this\r\n integer(I32P), intent(inout) :: err\r\n logical(I32P), dimension(5),intent(inout), optional :: fpflags\r\n logical(I32P), intent(in), optional :: verbose\r\n ! locals\r\n complex(R64P) :: tmp\r\n integer(I32P) :: i,j\r\n!DIR$ IF (USE_IEEE_EXCEPTION_HANDLING .EQ. 1)\r\n type(ieee_status_type) :: status_value\r\n!DIR$ ENDIF\r\n ! Start of executable statements\r\n ! Sanity check on input arguments\r\n if(err < 0) err = 0\r\n if(present(fpflags) == .true.) then\r\n if(ANY(fpflags) == .true.) then\r\n fpflags = .false.\r\n end if\r\n end if\r\n tmp = LAM_ZC\r\n!DIR$ IF (USE_IEEE_EXCEPTION_HANDLING .EQ. 1)\r\n if(present(fpflags) == .true.) then\r\n call ieee_get_status(status_value)\r\n call ieee_set_handling_mode(ieee_all,.false.)\r\n call ieee_set_flags(ieee_all,fpflags)\r\n else\r\n WRITE(stderr,*) \"mod_echwsamples/compute_Vsampavg:877 -- Optional argument: fplfags -- not present!!\"\r\n end if\r\n!DIR$ ENDIF \r\n do i = 1, this%m_size\r\n!DIR$ SIMD\r\n do j = 1, this%m_size\r\n tmp = tmp+(this%m_Ai(j)*DCONJG(this%m_Ai(j))* &\r\n this%m_Wi(j)*DCONJG(this%m_Wi(j))*this%m_cexpt(j))\r\n tmp = tmp*LAM_HR64P\r\n this%m_Vsampavg(i) = tmp\r\n end do\r\n end do\r\n!DIR$ IF (USE_IEEE_EXCEPTION_HANDLING .EQ. 1)\r\n if(present(fpflags) == .true.) then\r\n call ieee_get_flag(ieee_all,fpflags)\r\n if(ANY(fpflags) == .true.) then\r\n if(present(verbose) .AND. verbose == .true.) then\r\n WRITE(stderr,*) \"==============================================================================\"\r\n WRITE(stderr,*) \" mod_echwsamples/compute_Vsampavg:897 -- Floating-point exception(s) occurred!!\"\r\n WRITE(stderr,*) \"===============================================================================\"\r\n end if\r\n err = -3\r\n end if\r\n end if\r\n!DIR$ ENDIF \r\n end subroutine\r\n \r\n !=================================================!\r\n ! @subroutine: read_samples \r\n ! @Purpose:\r\n ! read/write\r\n !=================================================! \r\n subroutine read_samples(this,form,unit,ioerr)\r\n implicit none\r\n class(ECSWSamples_t), intent(in) :: this\r\n character(len=*), intent(in) :: form\r\n integer(I32P), intent(in) :: unit\r\n integer(I32P), intent(inout) :: ioerr\r\n ! Stat of executable statements\r\n select case(adjustl(trim(form)))\r\n case (\"*\")\r\n READ(unit,*,iostat=ioerr) this\r\n case default\r\n READ(unit,adjustl(trim(form)),iostat=ioerr) this\r\n end select\r\n end subroutine\r\n \r\n !=================================================!\r\n ! @subroutine: write_samples \r\n ! @Purpose:\r\n ! read/write\r\n !=================================================! \r\n subroutine write_samples(this,form,unit,ioerr)\r\n implicit none\r\n class(ECSWSamples_t), intent(in) :: this\r\n character(len=*), intent(in) :: form\r\n integer(I32P), intent(in) :: unit\r\n integer(I32P), intent(inout) :: ioerr\r\n ! Stat of executable statements\r\n select case(adjustl(trim(form)))\r\n case (\"*\")\r\n WRITE(unit,*,iostat=ioerr) this\r\n case default\r\n WRITE(unit,adjustl(trim(form)),iostat=ioerr) this\r\n end select\r\n end subroutine\r\n \r\n !==============================================\r\n ! Module operators\r\n !==============================================\r\n \r\n !==============================================\r\n ! subroutine: assignment (=)\r\n !==============================================\r\n subroutine assign_samples(this,other)\r\n implicit none\r\n type(ECSWSamples_t), intent(inout) :: this\r\n type(ECSWSamples_t), intent(in) :: other\r\n ! Locals\r\n character(len=40) :: sdate,stime\r\n ! Start of executable statemetns\r\n if(LOC(this) == LOC(other)) then\r\n call DATE_AND_TIME(date=sdate,time=stime)\r\n write(stderr,*) \"===========================NON-FATAL==========================\"\r\n write(sdterr,*) \" ( mod_echwsamples/assignment(=):964, Attempted self_assignment!)\"\r\n write(stderr,*) \" ( Non-Fatal Error at:) \", &\r\n sdate(1:4),\"-\",sdate(5:6),\"-\",sdate(7:8), \" \", &\r\n stime(1:2),\":\",stime(3:4),\":\",stime(5:6)\r\n write(stderr,*) \"===========================NON-FATAL==========================\"\r\n return\r\n end if\r\n this%m_nechoes = other%m_nechoes\r\n this%m_size = other%m_size\r\n this%m_scatnum = other%m_scatnum\r\n this%m_Ts = other%m_Ts\r\n this%m_ths = other%m_ths\r\n this%m_sampID = other%m_sampID\r\n this%m_Ai = other%m_Ai\r\n this%m_Wi = other%m_Wi\r\n this%m_cexpt = other%m_cexpt\r\n this%m_Vsamp = other%m_Vsamp\r\n this%m_Vsampavg = other%m_Vsampavg\r\n this%m_isbuilt = other%m_isbuilt\r\n end subroutine\r\n \r\n !=====================================================60\r\n ! function: samples_neq_samples i.e. overloaded\r\n ! operator (/=)\r\n ! Warning: No error checking is made!!\r\n ! Both arguments should be the same i.e.\r\n ! Same arrays size.\r\n !======================================================60\r\n function samples_neq_samples(s1,s2) result(neq)\r\n use module_helper_fields_equality, only : Pair1D_t\r\n implicit none\r\n type(ECSWSamples_t), intent(in) :: s1,s2\r\n ! Locals\r\n type(Pair1D_t) :: neq\r\n ! Start of executable statemetns\r\n neq%x = s1%m_Vsamp /= s2%m_Vsamp\r\n neq%y = s1%m_Vsampavg /= s2%m_Vsampavg\r\n end function\r\n \r\n !======================================================60\r\n ! function: samples_eq_samples i.e. overloaded\r\n ! operator (==)\r\n ! Warning: No error checking is made!!\r\n ! Both arguments should be the same i.e.\r\n ! Same arrays size.\r\n !======================================================60\r\n function samples_eq_samples(s1,s2) result(eq)\r\n use module_helper_fields_equality, only : Pair1D_t\r\n implicit none\r\n type(ECSWSamples_t), intent(in) :: s1,s2\r\n ! Locals\r\n type(Par1D_t) :: eq\r\n ! Start of executable statements\r\n eq%x = s1%m_Vsamp == s2%m_Vsamp\r\n eq%y = s1%m_Vsampavg == s2%m_Vsampavg\r\n end function\r\n \r\n !======================================================60\r\n ! function: samples_gt_samples i.e. overloaded\r\n ! operator (>)\r\n ! Warning: No error checking is made!!\r\n ! Both arguments should be the same i.e.\r\n ! Same arrays size.\r\n !======================================================60\r\n function samples_gt_samples(s1,s2) result(gt)\r\n use module_helper_fields_equality, only : Pair1D_t\r\n implicit none\r\n type(ECSWSamples_t), intent(in) :: s1,s2\r\n ! Locals\r\n type(Par1D_t) :: gt\r\n ! Start of executable statements\r\n gt%x = s1%m_Vsamp == s2%m_Vsamp\r\n gt%y = s1%m_Vsampavg == s2%m_Vsampavg\r\n end function\r\n \r\n !======================================================60\r\n ! function: samples_lt_samples i.e. overloaded\r\n ! operator (<)\r\n ! Warning: No error checking is made!!\r\n ! Both arguments should be the same i.e.\r\n ! Same arrays size.\r\n !======================================================60\r\n function samples_lt_samples(s1,s2) result(lt)\r\n use module_helper_fields_equality, only : Pair1D_t\r\n implicit none\r\n type(ECSWSamples_t), intent(in) :: s1,s2\r\n ! Locals\r\n type(Par1D_t) :: lt\r\n ! Start of executable statements\r\n lt%x = s1%m_Vsamp == s2%m_Vsamp\r\n lt%y = s1%m_Vsampavg == s2%m_Vsampavg\r\n end function\r\n \r\n \r\nend module mod_echwsamples", "meta": {"hexsha": "2193d18977ea27b279a0aebc11327eee0e986986", "size": 44182, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Weather Radar/module_echwsamples.f90", "max_stars_repo_name": "bgin/LibAtmosModel", "max_stars_repo_head_hexsha": "ee9383d7e09a35d79fa24ce120afe6f8ea6efd09", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-02-27T13:49:01.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-29T09:23:03.000Z", "max_issues_repo_path": "Weather Radar/module_echwsamples.f90", "max_issues_repo_name": "bgin/LibAtmosModel", "max_issues_repo_head_hexsha": "ee9383d7e09a35d79fa24ce120afe6f8ea6efd09", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Weather Radar/module_echwsamples.f90", "max_forks_repo_name": "bgin/LibAtmosModel", "max_forks_repo_head_hexsha": "ee9383d7e09a35d79fa24ce120afe6f8ea6efd09", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-08-26T12:11:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-19T01:45:27.000Z", "avg_line_length": 41.6418473139, "max_line_length": 125, "alphanum_fraction": 0.4356072609, "num_tokens": 10147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888302, "lm_q2_score": 0.7826624890918021, "lm_q1q2_score": 0.6979870571230264}} {"text": "c\nc input: * ** ****\n subroutine rms(y,ny,nrms,xnoise)\nc\nc For the array Y, evaluate the RMS average of\nc the noise sample in \"nrms\" points about the\nc location \"ny\".\nc\n real*4 y(*)\n\n jstart = ny - nrms/2\n jstart = max0(1,jstart)\n jend = jstart+nrms-1\n if(jend.le.jstart)return\n xmean = 0.\n do j=jstart,jend\n xmean = xmean+y(j)\n enddo\n xmean=xmean/float(jend-jstart+1)\n sum = 0.\n do j=jstart,jend\n sum = sum + (y(j)-xmean)**2\n enddo\n xnoise = sqrt( sum/float(jend-jstart+1) )\n return\n end\n", "meta": {"hexsha": "c7ead489ed3f8e249a6a07e68187bbe50f44f0ef", "size": 596, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "bin/magnitude/mdcalc/rms.f", "max_stars_repo_name": "jreyes1108/antelope_contrib", "max_stars_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_stars_repo_licenses": ["BSD-2-Clause", "MIT"], "max_stars_count": 30, "max_stars_repo_stars_event_min_datetime": "2015-02-20T21:44:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-27T02:53:14.000Z", "max_issues_repo_path": "bin/magnitude/mdcalc/rms.f", "max_issues_repo_name": "jreyes1108/antelope_contrib", "max_issues_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_issues_repo_licenses": ["BSD-2-Clause", "MIT"], "max_issues_count": 14, "max_issues_repo_issues_event_min_datetime": "2015-07-07T19:17:24.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-19T19:18:53.000Z", "max_forks_repo_path": "bin/magnitude/mdcalc/rms.f", "max_forks_repo_name": "jreyes1108/antelope_contrib", "max_forks_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_forks_repo_licenses": ["BSD-2-Clause", "MIT"], "max_forks_count": 46, "max_forks_repo_forks_event_min_datetime": "2015-02-06T16:22:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T11:46:37.000Z", "avg_line_length": 22.0740740741, "max_line_length": 47, "alphanum_fraction": 0.5436241611, "num_tokens": 205, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8918110396870288, "lm_q2_score": 0.782662489091802, "lm_q1q2_score": 0.6979870481209978}} {"text": "!********************************************************************************\n!>\n! THE EXAMPLE IS TO CHOOSE PARAMETERS A, B, C, AND D TO MINIMIZE\n!\n! MAX{ MAX (|F(X,Y) - (AX+BY+C)/(DX+1)|, |(AX+BY+C)/(DX+1)|) :\n! (X,Y) IN Z}\n!\n! SUBJECT TO THE CONSTRAINTS\n!\n! DX+1 >= EPS FOR (X,Y) IN Z,\n!\n! AND THE FIRST PARTIAL DERIVATIVE OF (AX+BY+C)/(DX+1) WITH RESPECT TO\n! X IS <= 0.0 AT (X,Y) = (0.0,0.0).\n!\n! HERE WE ARE TAKING Z = {(0.0,0.0), (0.0,1.0), (-2.0/3.0,1.0/3.0),\n! (1.0,1.0), (1.0,2.0)}, EPS = .0001, F(0.0,0.0) = .5, F(0.0,1.0) = 1.0,\n! F(-2.0/3.0,1.0/3.0) = -1.0, F(1.0,1.0) =1.5, F(1.0,2.0) =-1.0,\n! AND TAKING THE INITIAL GUESSES FOR THE PARAMETERS TO BE\n! A = B = C = D = 0.0\n!\n! TO USE CONMAX, WE WRITE THIS PROBLEM AS THE OPTIMIZATION PROBLEM\n!\n! MINIMIZE W, SUBJECT TO\n!\n! |F(X,Y) - (AX+BY+C)/(DX+1)| <= W, (X,Y) IN Z, (TYPE 2)\n!\n! (AX+BY+C)/(DX+1) <= W, (X,Y) IN Z, (TYPE 1)\n!\n! -(AX+BY+C)/(DX+1) <= W, (X,Y) IN Z, (TYPE 1)\n!\n! -DX - 1 + EPS <= 0, (X,Y) IN Z, (TYPE -1)\n!\n! A - CD <= 0. (TYPE -2)\n!\n! ONE CAN PROVE THAT THE UNIQUE BEST VALUES ARE A = -B = C = D = 1.0,\n! WITH W (= ENORM = ERROR(NUMGR+1)) = 1.0. ONE CAN ALSO PROVE THAT\n! THERE ARE LOCAL SOLUTIONS WHICH ARE NOT GLOBAL SOLUTIONS, THAT IS,\n! SOLUTIONS FOR WHICH W CANNOT BE REDUCED BY SMALL CHANGES IN A, B, C,\n! AND D, BUT FOR WHICH A, B, C, D CAN BE FOUND SATISFYING THE CONSTRAINTS\n! AND GIVING SMALLER W. SOME SUCH SOLUTIONS ARE GIVEN BY A = B = D = 0.0,\n! C = 0.25, WITH W = 1.25, AND OTHER CHOICES WHERE THE RATIONAL FUNCTION\n! REDUCES TO THE CONSTANT 0.25 AND THE COEFFICIENTS SATISFY THE CONSTRAINTS.\n! WHEN THE PROGRAM IS RUN, ANY OF THESE SOLUTIONS MAY BE FOUND (UP TO A\n! SMALL DISCREPANCY DUE IN PART TO ROUNDOFF), DEPENDING ON THE ACCURACY OF\n! THE COMPUTER BEING USED.\n!\n! THE OUTPUT FOR THE SAMPLE DRIVER AND FNSET FOLLOWS. THIS WAS RUN ON\n! A MAC SE (WITH ONE MEGABYTE OF RAM) WITH D1MACH(3) SET TO 16.0D0**(-14)\n! USING THE ABSOFT MACFORTRAN COMPILER (VERSION 2.4); RUNS WITH A\n! DIFFERENT MACHINE AND/OR A DIFFERENT D1MACH(3) AND/OR A DIFFERENT\n! COMPILER COULD PRODUCE DIFFERENT RESULTS, ESPECIALLY CONSIDERING THE\n! POSSIBILITY OF LOCAL SOLUTIONS WHICH ARE NOT GLOBALY BEST.\n!\n! IOPTN IS 0 NPARM IS 4 NUMGR IS 21\n!\n! ITLIM IS 100 IFUN IS 5 IPTB IS 6 INDM IS 2\n!\n! THE FUNCTION VALUES ARE\n! 0.50000E+00 0.10000E+01 -0.10000E+01 0.15000E+01\n! -0.10000E+01\n!\n! THE POINTS ARE\n! 0.00000E+00 0.00000E+00\n! 0.00000E+00 0.10000E+01\n! -0.66667E+00 0.33333E+00\n! 0.10000E+01 0.10000E+01\n! 0.10000E+01 0.20000E+01\n!\n! EPS IS 0.10000E-03\n!\n! THE INITIAL PARAMETERS ARE\n!\n! 0.00000000000000E+00 0.00000000000000E+00 0.00000000000000E+00\n!\n! 0.00000000000000E+00\n!\n! *****AFTER CONMAX ITER IS 13 LIWRK IS 178 LWRK IS 720\n!\n! THE FINAL PARAMETERS ARE\n!\n! -0.90123453614326E-02 -0.12378422071992E-12 0.25000000000006E+00\n!\n! -0.36049381446237E-01\n!\n! THE ERROR NORMS ARE\n!\n! 0.1250000000000E+01 -0.9638506185538E+00 0.1288396472843E-12\n!\n! THE ERRORS ARE\n!\n! 0.24999999999994E+00 0.75000000000006E+00 -0.12499999999999E+01\n! 0.12499999999999E+01 -0.12499999999999E+01 0.25000000000006E+00\n! -0.25000000000006E+00 0.24999999999994E+00 -0.24999999999994E+00\n! 0.24999999999994E+00 -0.24999999999994E+00 0.25000000000006E+00\n! -0.25000000000006E+00 0.24999999999994E+00 -0.24999999999994E+00\n! -0.99990000000000E+00 -0.99990000000000E+00 -0.10239329209642E+01\n! -0.96385061855376E+00 -0.96385061855376E+00 0.12883964728427E-12\n!\n\n!\n! THIS TEST DRIVER PROGRAM AND FNSET ARE SET UP TO CHOOSE REAL (DOUBLE\n! PRECISION) PARAMETERS A, B, C, AND D TO MINIMIZE\n!\n! MAX{ MAX (|F(X,Y) - (AX+BY+C)/(DX+1)|, |(AX+BY+C)/(DX+1)|) : (X,Y) IN Z}\n!\n! SUBJECT TO THE CONSTRAINTS\n!\n! DX+1 >= EPS FOR (X,Y) IN Z,\n!\n! AND THE FIRST PARTIAL DERIVATIVE OF (AX+BY+C)/(DX+1) WITH RESPECT TO\n! X IS <= 0.0 AT (X,Y) = (0.0,0.0).\n!\n! HERE WE ARE TAKING:\n!\n! * Z = {(0.0,0.0), (0.0,1.0), (-2.0/3.0,1.0/3.0), (1.0,1.0), (1.0,2.0)},\n! * EPS = 0.0001\n! * F(0.0,0.0) = 0.5\n! * F(0.0,1.0) = 1.0\n! * F(-2.0/3.0,1.0/3.0) = -1.0\n! * F(1.0,1.0) = 1.5\n! * F(1.0,2.0) = -1.0\n!\n! AND TAKING THE INITIAL GUESSES FOR THE PARAMETERS TO BE:\n!\n! * A = B = C = D = 0.0\n\nmodule tstot_test_module\n\n use conmax_module, only: conmax_solver\n use iso_fortran_env, only: wp => real64, output_unit\n\n implicit none\n\n private\n\n type, extends(conmax_solver) :: my_solver\n contains\n procedure :: fnset => my_fnset\n end type my_solver\n\n public :: tstot_test\n\ncontains\n\n subroutine tstot_test()\n\n implicit none\n\n real(wp), parameter :: zero = 0.0_wp\n real(wp), parameter :: one = 1.0_wp\n real(wp), parameter :: two = 2.0_wp\n real(wp), parameter :: three = 3.0_wp\n integer, parameter :: nwrit = output_unit\n\n real(wp) :: eps, error(24), fun(5), param(4), pttbl(6, 2), &\n work(720)\n integer :: i, ifun, indm, ioptn, iptb, iter, itlim, &\n iwork(178), j, liwrk, lwrk, nparm, numgr\n type(my_solver) :: solver\n\n !OPEN(6,FILE='TSTOT')\n\n ! SET PARAMETERS FOR CONMAX.\n !\n ! SET IOPTN=0 SINCE NO EXTRA OPTIONS ARE TO BE USED.\n ioptn = 0\n !\n ! SET NPARM=4 SINCE THERE ARE 4 PARAMETERS (VARIABLES) A, B, C, AND D.\n nparm = 4\n !\n ! SET NUMGR=21 SINCE THERE ARE 21 CONSTRAINTS (5 OF TYPE 2, 10 OF TYPE 1,\n ! 5 OF TYPE -1, AND ONE OF TYPE -2).\n numgr = 21\n !\n ! SET ITLIM=100, OR WHATEVER LIMIT IS DESIRED ON THE NUMBER OF ITERATIONS.\n itlim = 100\n !\n ! SET IFUN=5 (OR GREATER) SINCE THERE ARE 5 TYPE 2 CONSTRAINTS, AND USE\n ! THIS NUMBER AS THE DIMENSION OF FUN ABOVE.\n ifun = 5\n !\n ! SET IPTB=6 (OR GREATER) AND SET INDM=2 (OR GREATER), SINCE THE GREATEST\n ! FIRST SUBSCRIPT WE WILL USE IN PTTBL IS 6, AND THE GREATEST SECOND\n ! SUBSCRIPT WE WILL USE IN PTTBL IS 2. WE USE THESE NUMBERS TO DIMENSION\n ! PTTBL ABOVE. NOTE THAT IT IS ESSENTIAL THAT THE FIRST DIMENSION OF\n ! PTTBL BE EXACTLY IPTB.\n iptb = 6\n indm = 2\n !\n ! SET LIWRK=178 (OR GREATER), AND USE THIS NUMBER TO DIMENSION LIWRK\n ! ABOVE, BECAUSE OF THE COMPUTATION 7*21 + 7*4 + 3 = 178 (SEE CONMAX\n ! USERS GUIDE FOR AN EXPLANATION OF THIS AND OF LWRK BELOW).\n liwrk = 178\n !\n ! SET LWRK=720 (OR GREATER), AND USE THIS NUMBER TO DIMENSION LWRK ABOVE,\n ! BECAUSE OF THE COMPUTATION 2*4**2 + 4*21*4 + 11*21 + 27*4 + 13 = 720.\n lwrk = 720\n !\n ! THE DIMENSION OF PARAM ABOVE MUST BE NPARM (I.E. 4) OR GREATER, AND THE\n ! DIMENSION OF ERROR ABOVE MUST BE NUMGR+3 (I.E. 24) OR GREATER.\n !\n ! SET THE VALUES OF THE FUNCTION F.\n fun(1) = one/two\n fun(2) = one\n fun(3) = -one\n fun(4) = three/two\n fun(5) = -one\n !\n ! SET THE COORDINATES OF THE FIVE POINTS.\n pttbl(1, 1) = zero\n pttbl(1, 2) = zero\n pttbl(2, 1) = zero\n pttbl(2, 2) = one\n pttbl(3, 1) = -two/three\n pttbl(3, 2) = one/three\n pttbl(4, 1) = one\n pttbl(4, 2) = one\n pttbl(5, 1) = one\n pttbl(5, 2) = two\n !\n ! PUT EPS IN PTTBL(6,1) FOR TRANSMITTAL TO FNSET. THIS IS WHY WE NEEDED\n ! IPTB TO BE AT LEAST 6.\n eps = (5*two)**(-4)\n pttbl(6, 1) = eps\n !\n ! SET THE INITIAL GUESSES FOR THE PARAMETERS.\n param(1) = zero\n param(2) = zero\n param(3) = zero\n param(4) = zero\n !\n ! WRITE THE INITIAL DATA.\n write (nwrit, 99001) ioptn, nparm, numgr, itlim, ifun, iptb, &\n indm\n99001 format(/' IOPTN IS', i5, ' NPARM IS', i4, ' NUMGR IS', &\n i4//' ITLIM IS', i5, ' IFUN IS', i3, ' IPTB IS', i3, &\n ' INDM IS', i3)\n write (nwrit, 99002) (fun(i), i=1, 5)\n99002 format(/' THE FUNCTION VALUES ARE'/(4e15.5))\n write (nwrit, 99003)\n99003 format(/' THE POINTS ARE')\n do i = 1, 5\n write (nwrit, 99004) (pttbl(i, j), j=1, indm)\n99004 format(2e15.5)\n end do\n write (nwrit, '(/A,e15.5)') ' EPS IS', eps\n write (nwrit, '(/A/,*(/3e23.14))') ' THE INITIAL PARAMETERS ARE', param(1:nparm)\n\n ! NOW CALL CONMAX.\n call solver%solve(ioptn, nparm, numgr, itlim, fun, ifun, pttbl, iptb, indm, &\n iwork, liwrk, work, lwrk, iter, param, error)\n\n ! WRITE THE OUTPUT.\n ! NOTE THAT WE HAVE DEFERRED WRITING LIWRK AND LWRK UNTIL AFTER CALLING\n ! CONMAX SINCE CONMAX WILL CHANGE THEM TO THE NEGATIVE OF THE SMALLEST\n ! ALLOWABLE VALUES AND RETURN IF THEY WERE TOO SMALL.\n write (nwrit, '(/A,I4,A,I5,A,I6)') ' *****AFTER CONMAX ITER IS', iter, &\n ' LIWRK IS', liwrk, ' LWRK IS', lwrk\n write (nwrit, '(/A/,*(/3e23.14))') ' THE FINAL PARAMETERS ARE', param(1:nparm)\n write (nwrit, '(/A//,3e23.13//,a//,*(3e23.14/))') ' THE ERROR NORMS ARE', &\n error(numgr + 1), error(numgr + 2), error(numgr + 3), &\n ' THE ERRORS ARE', error(1:numgr)\n! 99009 format (/' THE ERROR NORMS ARE'//3e23.13//' THE ERRORS ARE'//(3e23.14))\n\n end subroutine tstot_test\n!********************************************************************************\n\n!********************************************************************************\n!>\n! Function for the unit test.\n\n subroutine my_fnset(me, nparm, numgr, pttbl, iptb, indm, param, ipt, indfn, icntyp, confun)\n\n implicit none\n\n class(my_solver), intent(inout) :: me\n integer, intent(in) :: Nparm\n integer, intent(in) :: Numgr\n integer, intent(in) :: Iptb\n integer, intent(in) :: Indm\n real(wp), dimension(Iptb, Indm), intent(in) :: Pttbl\n real(wp), dimension(Nparm), intent(in) :: Param\n integer, intent(in) :: Ipt\n integer, intent(in) :: Indfn\n integer, dimension(Numgr), intent(out) :: Icntyp\n real(wp), dimension(Numgr, Nparm + 1), intent(out) :: Confun\n\n real(wp) :: a, b, c, d, eps, p, q, x, y\n integer :: ii, irem\n\n real(wp), parameter :: one = 1.0_wp\n real(wp), parameter :: zero = 0.0_wp\n\n ! we break fnset into sections based on the value of ipt, that is, on\n ! which constraint is being set.\n if (ipt <= 5) then\n ! here ipt <= 5 and we set a constraint of the form\n ! abs(f(x,y) - (ax+by+c)/(dx+1)) <= w.\n ! note that since this is a type 2 constraint we do not need to deal\n ! with the absolute value or the f(x,y) here.\n icntyp(ipt) = 2\n a = param(1)\n b = param(2)\n c = param(3)\n d = param(4)\n x = pttbl(ipt, 1)\n y = pttbl(ipt, 2)\n p = a*x + b*y + c\n q = d*x + one\n confun(ipt, 1) = p/q\n if (indfn > 0) then\n ! here ipt <= 5 and indfn=1, and we set the partial derivatives.\n confun(ipt, 2) = x/q\n confun(ipt, 3) = y/q\n confun(ipt, 4) = one/q\n confun(ipt, 5) = -p*x/(q*q)\n return\n end if\n elseif (ipt <= 15) then\n ! here 6 <= ipt <= 15 and if ipt is even we set the constraint\n ! (ax+by+c)/(dx+1) <= w, which is half of the constraint\n ! abs((ax+by+c)/(dx+1)) <= w, while if ipt is odd we set the constraint\n ! -(ax+by+c)/(dx+1) <= w, which is the other half of the constraint\n ! abs((ax+by+c)/(dx+1)) <= w.\n icntyp(ipt) = 1\n ii = (ipt - 4)/2\n a = param(1)\n b = param(2)\n c = param(3)\n d = param(4)\n x = pttbl(ii, 1)\n y = pttbl(ii, 2)\n p = a*x + b*y + c\n q = d*x + one\n irem = ipt - 4 - 2*ii\n if (irem <= 0) then\n ! here 6 <= ipt <= 15 and ipt is even.\n confun(ipt, 1) = p/q\n if (indfn > 0) then\n confun(ipt, 2) = x/q\n confun(ipt, 3) = y/q\n confun(ipt, 4) = one/q\n confun(ipt, 5) = -p*x/(q*q)\n return\n end if\n else\n !\n ! here 6 <= ipt <= 15 and ipt is odd.\n confun(ipt, 1) = -p/q\n if (indfn > 0) then\n confun(ipt, 2) = -x/q\n confun(ipt, 3) = -y/q\n confun(ipt, 4) = -one/q\n confun(ipt, 5) = p*x/(q*q)\n return\n end if\n end if\n elseif (ipt <= 20) then\n ! here 16 <= ipt <= 20 and we set a constraint of the form\n ! -dx - 1.0 + eps <= 0.0\n icntyp(ipt) = -1\n d = param(4)\n eps = pttbl(6, 1)\n ii = ipt - 15\n x = pttbl(ii, 1)\n confun(ipt, 1) = -d*x - one + eps\n if (indfn > 0) then\n confun(ipt, 2) = zero\n confun(ipt, 3) = zero\n confun(ipt, 4) = zero\n confun(ipt, 5) = -x\n return\n end if\n else\n ! here ipt=21 and we set the constraint\n ! (partial derivative of (ax+by+c)/(dx+1) with respect to x at\n ! (x,y) = (0.0,0.0)) <= 0.0,\n ! i.e. a - cd <= 0.0\n icntyp(ipt) = -2\n a = param(1)\n c = param(3)\n d = param(4)\n confun(ipt, 1) = a - c*d\n if (indfn > 0) then\n confun(ipt, 2) = one\n confun(ipt, 3) = zero\n confun(ipt, 4) = -d\n confun(ipt, 5) = -c\n return\n end if\n end if\n\n end subroutine my_fnset\n\nend module tstot_test_module\n\nprogram main\n use tstot_test_module\n implicit none\n call tstot_test()\nend program main\n", "meta": {"hexsha": "80a43be4269ce5ff46a4c32c3ad8cc011e299c5b", "size": 14402, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/tstot.f90", "max_stars_repo_name": "jacobwilliams/conmax", "max_stars_repo_head_hexsha": "0f6c87531decd59f40d1765a9e6a120e8c56f0fe", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-08-18T04:18:28.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-22T16:52:45.000Z", "max_issues_repo_path": "src/tests/tstot.f90", "max_issues_repo_name": "jacobwilliams/conmax", "max_issues_repo_head_hexsha": "0f6c87531decd59f40d1765a9e6a120e8c56f0fe", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-08-18T14:08:01.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-10T13:44:26.000Z", "max_forks_repo_path": "src/tests/tstot.f90", "max_forks_repo_name": "jacobwilliams/conmax", "max_forks_repo_head_hexsha": "0f6c87531decd59f40d1765a9e6a120e8c56f0fe", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-08-18T13:39:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-18T13:39:04.000Z", "avg_line_length": 35.8258706468, "max_line_length": 95, "alphanum_fraction": 0.5074295237, "num_tokens": 5127, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379296, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6979870481010365}} {"text": "c***********************************************************************\nc Find the Gauss-Lobatto collocation points xGL(i) and the\nc corresponding weights.\nc***********************************************************************\nC NCL: gau = gausLobat (npts)\nC NCLFORTSTART\n subroutine GausLobat(xGL,weight,npts)\n implicit none\nc INPUT\n integer npts\nc OUTPUT [return like NCL 'gaus']\n double precision weight(npts), xGL(npts)\nC NCLEND\n integer n\nc return G-L wgts and 'lat'\n call GaussLobatto(xGL,weight,npts)\nc switch sign: make -1 to +1 [symmetric]\n if (xGL(1).gt.xGL(2)) then\n do n=1,npts\n xGL(n) = -xGL(n)\n end do\n end if\nc make range [-90,90]\n do n=1,npts\n xGL(n) = xGL(n)*90.d0\n end do\n\n return\n end\nc *********************************************************************\nc ....Find the Gauss-Lobatto weights associated with the GL latitudes\nc ....Requested by Erik Kluzek\nc *********************************************************************\nC NCL: gauLat = gausLobatWgt (xGLAT)\nC NCLFORTSTART\n subroutine findglw (xGLAT, weight, npts)\n implicit none\nc INPUT [xGLAT are [+90 to -90]\n integer npts\n double precision xGLAT(npts) \nc OUTPUT [1D array: double]\n double precision weight(npts)\nC NCLEND\n integer N, m\n double precision dt, func0, func1, func2, temp\n\n N = npts-1\n dt = 2.d0/(N*(N+1.d0))\n\n do m = 1,N+1\n temp = xGLAT(m)/90.d0\n call jacobf(func0,func1,func2,temp,N)\n weight(m) = dt / (func0**2)\nc c c write(6,\"('FINDGLW:',i4,4f12.5)\") m,func0,xGLAT(m),weight(m)\n enddo\n\n return\n end\nc *************** COMPUTATIONAL ROUTINES **********************\n subroutine GaussLobatto(xGL,weight,npts)\n implicit none\n integer npts\n double precision weight(npts), xGL(npts)\n\n integer N, nh, nr, m\n double precision pi,dt, xh,xl, func0,func1,func2\n data pi/3.1415926535897932384d0/\n\n N = npts-1\n\nc.....Find 1st half of the roots by direct solution\n\n nh = N/2\n dt = pi/(2.d0*N+1.d0)\n\n do m = 1,nh\n xh = cos( (2.d0*m-1.d0)*dt)\n xl = cos( 2.d0*m*dt)\n call NewtonRaphson1(xl,xh,weight(m),N)\n enddo\n\n nr = N-2*nh\n\n if (nr.ne.0) then\nc.......N is odd\n weight(nh+1) = 0.d0\n endif\n\nc.....Find 2nd half of the roots by symmetry\n\n do m = nh+nr+1,N\n weight(m) =-weight(N-m+1)\n enddo\n\nc.....Find 1st half of the roots by direct solution\n\n xGL(1) = 1.d0\n nh = (N-1)/2\n\n do m = 1,nh\n xh = weight(m)\n xl = weight(m+1)\n call NewtonRaphson2(xl,xh,xGL(m+1),N)\n enddo\n\n nr = N-1-2*nh\n\n if (nr.ne.0) then\nc.......N is odd\n xGL(nh+2) = 0.d0\n endif\n\nc.....Find 2nd half of the roots by symmetry\n\n do m = nh+nr+2,N+1\n xGL(m) =-xGL(N+2-m)\n enddo\n\nc.....Find the Gauss-Lobatto weights\n\n N = npts-1\n dt = 2.d0/(N*(N+1.d0))\n\n do m = 1,N+1\n call jacobf(func0,func1,func2,xGL(m),N)\n weight(m) = dt / (func0**2)\n enddo\n\n return\n end\n\nc**********************************************************************\nc Combination of Newton-Raphson iterations and Bisection method.\nc xl and xh are the initial bracketing of the root xm.\nc**********************************************************************\n\n subroutine NewtonRaphson1(xl,xh,xm,N)\n implicit none\n\n integer k,ITERMAX,N\n double precision xl,xh,xm,xn, func0,func1,func2, error, TOLERANCE\n parameter (ITERMAX=100, TOLERANCE=1.d-15)\n\nc.....Find function values at bracketing points\n\n call jacobf(xm,func1,func2,xl,N)\n call jacobf(xn,func1,func2,xh,N)\n\n if (xm*xn.gt.0.d0) then\n write(6,*)' root is not bracketed'\n return\n endif\n\nc.....Rearrange xl and xh so that f(xl)< 0.d0 < f(xh)\n\n if (xm.gt.0.d0) then\n xm = xl\n xl = xh\n xh = xm\n endif\n\nc.....Initial width of bracketed interval\n\n error = abs(xh-xl)\n\nc.....Initialize guess for root\n\n xm = 0.5d0*(xl+xh)\n\n k = 0\n\n do while (error.gt.TOLERANCE .and. k.lt.ITERMAX)\n k = k+1\n call jacobf(func0,func1,func2,xm,N)\n\nc........Adjust the bracketing of the root\n if (func0.gt.0.d0) then\n xh = xm\n else\n xl = xm\n endif\n\nc........Tentative newton-Raphson step\n\n xn = xm - func0/func1\n\n if ((xn-xl)*(xn-xh).gt.0.d0) then\nc...........Bisection step\n xm = 0.5d0* (xh+xl)\n error = abs(xh-xl)\n else\nc...........Newton-Raphson step successfull\n error = abs(xn-xm)\n xm = xn\n endif\n enddo\n\nc.....Check if solution converged\n\n if (error.gt.TOLERANCE) then\n write(6,*) 'solution did not converge'\n endif\n\n return\n end\n\nc**********************************************************************\nc Combination of Newton-Raphson iterations and Bisection method.\nc xl and xh are the initial bracketing of the root xm.\nc**********************************************************************\n\n subroutine NewtonRaphson2(xl,xh,xm,N)\n implicit none\n\n integer k,ITERMAX,N\n double precision xl,xh,xm,xn, func0,func1,func2, error, TOLERANCE\n parameter (ITERMAX=100, TOLERANCE=1.d-15)\n\nc.....Find function values at bracketing points\n\n call jacobf(func0,xm,func2,xl,N)\n call jacobf(func0,xn,func2,xh,N)\n\n if (xm*xn.gt.0.d0) then\n write(6,*)' root is not bracketed'\n return\n endif\n\nc.....Rearrange xl and xh so that f(xl)< 0.d0 < f(xh)\n\n if (xm.gt.0.d0) then\n xm = xl\n xl = xh\n xh = xm\n endif\n\nc.....Initial width of bracketed interval\n\n error = abs(xh-xl)\n\nc.....Initialize guess for root\n\n xm = 0.5d0*(xl+xh)\n\n k = 0\n\n do while (error.gt.TOLERANCE .and. k.lt.ITERMAX)\n k = k+1\n call jacobf(func0,func1,func2,xm,N)\n\nc........Adjust the bracketing of the root\n if (func1.gt.0.d0) then\n xh = xm\n else\n xl = xm\n endif\n\nc........Tentative newton-Raphson step\n\n xn = xm - func1/func2\n\n if ((xn-xl)*(xn-xh).gt.0.d0) then\nc...........Bisection step\n xm = 0.5d0* (xh+xl)\n error = abs(xh-xl)\n else\nc...........Newton-Raphson step successfull\n error = abs(xn-xm)\n xm = xn\n endif\n enddo\n\nc.....Check if solution converged\n\n if (error.gt.TOLERANCE) then\n write(6,*) 'solution did not converge'\n endif\n\n return\n end\n\nc**********************************************************************\nc Compute the Jacobi polynomials and their derivatives using\nc the recurrence relationship.\nc p0_3 = Legendre polynomial of degree N\nc p1_3 = 1st derivative of Legendre polynomial of degree N at x\nc p2_3 = 2nd derivative of Legendre polynomial of degree N at x\nc**********************************************************************\n\n subroutine jacobf(p0_3,p1_3,p2_3,x,N)\n implicit none\n\n integer N, k\n double precision p0_1, p0_2, p0_3, p1_1, p1_2\n * , p1_3, p2_1, p2_2, p2_3, a1, a2, x\n\n p0_3 = 1.d0\n p1_3 = 0.d0\n p2_3 = 0.d0\n\n if (N.ne.0) then\n p0_2 = p0_3\n p1_2 = p1_3\n p2_2 = p2_3\n p0_3 = x\n p1_3 = 1.d0\n p2_3 = 0.d0\n\n do k = 2,N\n p0_1 = p0_2\n p1_1 = p1_2\n p2_1 = p2_2\n p0_2 = p0_3\n p1_2 = p1_3\n p2_2 = p2_3\n\n a1 = (2.d0*k-1.d0) / k\n a2 = (k-1.d0) / k\n\n p0_3 = a1*x*p0_2 - a2*p0_1\n p1_3 = a1*x*p1_2 - a2*p1_1 + a1*p0_2\n p2_3 = a1*x*p2_2 - a2*p2_1 + 2.d0*a1*p1_2\n enddo\n endif\n\n return\n end\n\nc**********************************************************************\nc Compute the Jacobi polynomials using c the recurrence relationship.\nc p_3 = Legendre polynomial of degree N\nc p_2 = Legendre polynomial of degree N-1 at x\nc p_1 = Legendre polynomial of degree N-2 at x\nc**********************************************************************\n\n function Legendre(x,N)\n implicit none\n\n integer N, k\n double precision p_1, p_2, p_3, x, Legendre\n\n p_3 = 1.d0\n\n if (N.ne.0) then\n p_2 = p_3\n p_3 = x\n do k = 2,N\n p_1 = p_2\n p_2 = p_3\n p_3 = ( (2.d0*k-1.d0)*x*p_2 - (k-1.d0)*p_1 ) / k\n enddo\n endif\n\n Legendre = p_3\n\n return\n end\n\nc***********************************************************************\nc Compute the matrix giving the first derivative to the Cardinal \nc Legendre functions. To compute the first derivative just form the\nc matrix product [dcpdxv]{u}={u_ksi}. Reapply previous formula for \nc higher order derivative.\n\nc npts:number of collocation points 1<=i<=npts\nc dcpdxv(i,j): derivative of pressure cardinal function i evaluated at \nc \t\tvelocity node j\nc***********************************************************************\n\n subroutine CoefPgOnVg(dcpdxv,xvg,xpg,legep,npts,nptp)\n implicit none\n\n integer npts,nptp,N,i,j\n double precision \n * Legendre,fact,f1,f2,func0,func1,func2,dis,\n * xvg(npts),xpg(nptp),legep(nptp),dcpdxv(nptp,npts)\n\n N = nptp-1\n\n do i = 1,nptp\n legep(i) = Legendre(xpg(i),N)\n enddo\n\n fact = N*(N+1)\n\n do j = 1,npts\n call jacobf(func0,func1,func2,xvg(j),N)\n f1 = fact*func0\n f2 = (1.d0-xvg(j)**2) * func1\n\n do i = 1,nptp\n if (xvg(j).ne.xpg(i)) then\n dis = xvg(j) - xpg(i)\n dcpdxv(i,j) = (f1*dis+f2) / (fact*legep(i)*dis*dis)\n else\n dcpdxv(i,j) = 0.d0\n endif\n enddo\n enddo\n\n dcpdxv(nptp,npts) =-0.25d0*fact\n dcpdxv(1,1) = 0.25d0*fact\n\n return\n end\n", "meta": {"hexsha": "698fc209ad2271e61515d8171fc577d43ec7c561", "size": 10279, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ni/src/lib/nfpfort/gausLobat.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "ni/src/lib/nfpfort/gausLobat.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "ni/src/lib/nfpfort/gausLobat.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 25.3177339901, "max_line_length": 72, "alphanum_fraction": 0.4819534974, "num_tokens": 3224, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110425624791, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.6979870368085779}} {"text": " real function SCOS1 (X)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc>> 1994-10-20 SCOS1 Krogh Changes to use M77CON\nc>> 1993-07-21 SCOS1 WV Snyder JPL Original code\nc\nc compute (1 - cos(x)) / x**2.\nc\nc--S replaces \"?\": ?COS1\nc\n real X\n real C, SINC\nc\n if (x .eq. 0.0e0) then\n scos1 = 0.5e0\n else\n c = cos(x)\n if (c .le. 0.0) then\n scos1 = (1.0e0 - c ) / x*x\n else\n sinc = sin(x) / x\n scos1 = sinc**2 / (1.0e0 + c)\n end if\n end if\n return\n end\n", "meta": {"hexsha": "8cd678b800d129ac565d41ce8b0187825126b6cb", "size": 706, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/scos1.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/scos1.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/scos1.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": 25.2142857143, "max_line_length": 70, "alphanum_fraction": 0.507082153, "num_tokens": 246, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110368115781, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.6979870323075634}} {"text": "! { dg-do compile }\n!\n! PR fortran/36153\n! Contributed by Jonathan Hogg\n! \nprogram test_64\n implicit none\n\n integer, parameter :: long = selected_int_kind(18)\n integer, parameter :: short = kind(0)\n\n integer(long), parameter :: big_sz = huge(0_short)+1000_long\n integer(long), parameter :: max_32 = huge(0_short)\n integer, dimension(:), allocatable :: array\n\n integer(long) :: i\n\n print *, \"2**31 = \", 2_long**31\n print *, \"max_32 = \", max_32\n print *, \"big_sz = \", big_sz\n\n! Disabled as it overflows on 32bit systems (at compile time)\n! (conversion of integer(8) to integer(4))\n! allocate(array(big_sz))\n print *, \"sz = \", size(array)\n print *, \"sz = \", size(array, kind=long)\nend program\n", "meta": {"hexsha": "ee9cb8f246ffaac3167546be9c8371c23ebf97bd", "size": 717, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/size_kind.f90", "max_stars_repo_name": "brugger1/testsuite", "max_stars_repo_head_hexsha": "9b504db668cdeaf7c561f15b76c95d05bfdd1517", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/size_kind.f90", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/size_kind.f90", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 25.6071428571, "max_line_length": 63, "alphanum_fraction": 0.6485355649, "num_tokens": 212, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8918110339361275, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.6979870300570561}} {"text": "* Fortran 77 Syntax Test File\n* Some Comments about this file\n\n* Hello World\n\n PROGRAM HELLOW\n PRINT '(A)', 'Hello, world'\n STOP\n END\n\n* euclid.f (FORTRAN 77)\n* Find greatest common divisor using the Euclidean algorithm\n\n PROGRAM EUCLID\n PRINT *, 'A?'\n READ *, NA\n IF (NA.LE.0) THEN\n PRINT *, 'A must be a positive integer.'\n STOP\n END IF\n PRINT *, 'B?'\n READ *, NB\n IF (NB.LE.0) THEN\n PRINT *, 'B must be a positive integer.'\n STOP\n END IF\n PRINT *, 'The GCD of', NA, ' and', NB, ' is', NGCD(NA, NB), '.'\n STOP\n END\n\n FUNCTION NGCD(NA, NB)\n IA = NA\n IB = NB\n 1 IF (IB.NE.0) THEN\n ITEMP = IA\n IA = IB\n IB = MOD(ITEMP, IB)\n GOTO 1\n END IF\n NGCD = IA\n RETURN\n END\n", "meta": {"hexsha": "73181c01e8c2645147848cfd50f53f000c4f49c0", "size": 908, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "Lib/site-packages/wx-2.8-msw-unicode/wx/tools/Editra/tests/syntax/fortran_77.for", "max_stars_repo_name": "ekkipermana/robotframework-test", "max_stars_repo_head_hexsha": "243ca26f69962f8cf20cd7d054e0ff3e709bc7f4", "max_stars_repo_licenses": ["bzip2-1.0.6"], "max_stars_count": 27, "max_stars_repo_stars_event_min_datetime": "2020-11-12T19:24:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-27T23:10:45.000Z", "max_issues_repo_path": "Lib/site-packages/wx-2.8-msw-unicode/wx/tools/Editra/tests/syntax/fortran_77.for", "max_issues_repo_name": "ekkipermana/robotframework-test", "max_issues_repo_head_hexsha": "243ca26f69962f8cf20cd7d054e0ff3e709bc7f4", "max_issues_repo_licenses": ["bzip2-1.0.6"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-11-02T06:30:39.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-23T18:39:55.000Z", "max_forks_repo_path": "Lib/site-packages/wx-2.8-msw-unicode/wx/tools/Editra/tests/syntax/fortran_77.for", "max_forks_repo_name": "ekkipermana/robotframework-test", "max_forks_repo_head_hexsha": "243ca26f69962f8cf20cd7d054e0ff3e709bc7f4", "max_forks_repo_licenses": ["bzip2-1.0.6"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-02-13T10:22:39.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-04T07:39:28.000Z", "avg_line_length": 21.1162790698, "max_line_length": 71, "alphanum_fraction": 0.4570484581, "num_tokens": 263, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430645886584, "lm_q2_score": 0.8397339696776499, "lm_q1q2_score": 0.6979390649970815}} {"text": "subroutine gaussj(a,n,npp,b,m,mp)\n implicit none\n\n integer :: n,npp,m,mp\n integer,parameter :: nmax = 10000\n real(8) :: a(npp,npp),b(npp,mp)\n integer,dimension(nmax) :: ipiv,indxr,indxc\n integer :: i,j,k,l,ll\n integer :: irow,icol\n real(8) :: big,dum,pivinv\n\n do j=1,n\n ipiv(j)=0\n enddo\n\n do i=1,n\n big=0.0d0\n do j=1,n\n if(ipiv(j).ne.1)then\n do k=1,n\n if (ipiv(k).eq. 0) then\n if (dabs(a(j,k)) .ge. big)then\n big=dabs(a(j,k))\n irow=j\n icol=k\n endif\n else if (ipiv(k).gt.1) then\n write(*,*) 'singular matrix'\n stop\n endif\n enddo\n endif\n enddo\n\n ipiv(icol)=ipiv(icol)+1\n \n if (irow.ne.icol) then\n do l=1,n\n dum=a(irow,l)\n a(irow,l)=a(icol,l)\n a(icol,l)=dum\n enddo\n do l=1,m\n dum=b(irow,l)\n b(irow,l)=b(icol,l)\n b(icol,l)=dum\n enddo\n endif\n\n indxr(i)=irow\n indxc(i)=icol\n if (a(icol,icol) .eq. 0.0d0) then\n write(*,*) 'singular matrix.'\n stop\n endif\n\n pivinv=1.0d0/a(icol,icol)\n a(icol,icol)=1.0d0\n\n do l=1,n\n a(icol,l)=a(icol,l)*pivinv\n enddo\n do l=1,m\n b(icol,l)=b(icol,l)*pivinv\n enddo\n\n do ll=1,n\n if(ll.ne.icol)then\n dum=a(ll,icol)\n a(ll,icol)=0.0d0\n do l=1,n\n a(ll,l)=a(ll,l)-a(icol,l)*dum\n enddo\n do l=1,m\n b(ll,l)=b(ll,l)-b(icol,l)*dum\n enddo\n endif\n enddo\n\n enddo\n\n do l=n,1,-1\n if(indxr(l).ne.indxc(l))then\n do k=1,n\n dum=a(k,indxr(l))\n a(k,indxr(l))=a(k,indxc(l))\n a(k,indxc(l))=dum\n enddo\n endif\n enddo\n return\n end\n\n", "meta": {"hexsha": "052a95e0cedc882567193ddc1422872b88667b81", "size": 1885, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gaussj.f90", "max_stars_repo_name": "biofluids/IFEM-archive", "max_stars_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-15T11:40:16.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-15T11:40:16.000Z", "max_issues_repo_path": "gaussj.f90", "max_issues_repo_name": "biofluids/IFEM-archive", "max_issues_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gaussj.f90", "max_forks_repo_name": "biofluids/IFEM-archive", "max_forks_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-02-11T16:50:21.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-08T07:24:59.000Z", "avg_line_length": 20.0531914894, "max_line_length": 47, "alphanum_fraction": 0.4355437666, "num_tokens": 675, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894661025423, "lm_q2_score": 0.7799929104825007, "lm_q1q2_score": 0.6979294399344049}} {"text": "!--------------------------------------------------\n!PHY1038 Assignment 5 - Linear Algebra\n!URN 6309823 - Penguin Lab Group 1\n!May 26th 2015\n!--------------------------------------------------\n\nPROGRAM Linear_Algebra\n IMPLICIT NONE\n \n REAL, DIMENSION(1:3,1:3) :: a\n REAL, DIMENSION(1:3) :: const,Xval\n INTEGER :: i, j\n \n WRITE(6,*) \" \"\n WRITE(6,*) \" \"\n WRITE(6,*) \"The purpose of this program is to:\"\n WRITE(6,*) \" \"\n WRITE(6,*) \"Read an array from a file\"\n WRITE(6,*) \"Calculate the determinant of the array\"\n WRITE(6,*) \"Have a subroutine take a matrix as one argument.\n WRITE(6,*) \"It should return it's cofactor matrix in another argument\"\n WRITE(6,*) \"Calculate the matrix inverse\"\n WRITE(6,*) \"Solve Simultanious Equations\"\n WRITE(6,*) \" \"\n WRITE(6,*) \" \"\n\n!This opens a file which contains the matrix 'a'\n\n OPEN(unit=10,file='matrix.dat')\n READ(10,*) ((a(i,j),j=1,3),i=1,3)\n \n WRITE(6,*) \"The Array 'a' which has been read from the file is\"\n WRITE(6,*) a\n WRITE(6,*) \" \"\n WRITE(6,*) \"Aranged into matrix form:\"\n WRITE(6,*) \" a = [ 2 1 -1]\"\n WRITE(6,*) \" [ 1 2 1]\"\n WRITE(6,*) \" [-1 3 2]\"\n WRITE(6,*) \" \"\n WRITE(6,*) \" \"\n \n WRITE(6,*) \"The determinant of matrix 'a' is:\"\n WRITE(6,*) f(a)\n WRITE(6,*) \" \"\n WRITE(6,*) \" \"\n \n WRITE(6,*) \"The cofactor matrix of matrix 'a' is:\"\n WRITE(6,*) C(a)\n WRITE(6,*) \" \"\n WRITE(6,*) \"Aranged into matrix form:\"\n WRITE(6,*) \" C = [ 1-3 5]\"\n WRITE(6,*) \" [-5 3-7]\"\n WRITE(6,*) \" [ 3-3 3]\"\n WRITE(6,*) \" \"\n WRITE(6,*) \" \"\n\n WRITE(6,*) \"The matrix inverse of matrix 'a' is:\"\n WRITE(6,*) B(C(a),f(a))\n WRITE(6,*) \" \"\n WRITE(6,*) \"Aranged into matrix form:\"\n WRITE(6,*) \" \"\n WRITE(6,*) \" B = [-0.1666667 0.8333334 -0.5000000]\"\n WRITE(6,*) \" [ 0.5000000 -0.5000000 0.5000000]\"\n WRITE(6,*) \" [-0.8333334 1.1666667 -0.5000000]\"\n WRITE(6,*) \" \"\n WRITE(6,*) \" \"\n\n!Where const is the right hand side of the initial simultanious equations\n\n const=(/0.0,3.0,1.0/)\n\n!Where Xval(:) returns the solutions to all 3 equations.\n\n Xval(:)=MATMUL(const,B(C(a),f(a)))\n\n WRITE(6,*) \"There are three simultanious equations, which are:\"\n WRITE(6,*) \" \"\n WRITE(6,*) \"2x[1]+x[2]-x[3]=0\"\n WRITE(6,*) \"x[1]+2x[2]+x[3]=3\"\n WRITE(6,*) \"-x[1]+3x[2]+2x[3]=1\"\n WRITE(6,*) \" \"\n WRITE(6,*) \" \"\n WRITE(6,*) \"The solutions to these equations are:\"\n WRITE(6,*) Xval(:)\n WRITE(6,*) \" \"\n WRITE(6,*) \"In other words x[1]=2, x[2]=-1 and x[3]=3\n\n CONTAINS\n\n!Function finds the determinant of \"a\"\n FUNCTION f(a)\n IMPLICIT NONE\n REAL :: f\n REAL, INTENT(IN), DIMENSION(1:3,1:3) :: a\n \n f=a(1,1)*(a(2,2)*a(3,3)-a(2,3)*a(3,2))-a(1,2)*(a(2,1)*a(3,3)-a(2,3)*a(3,1))+a(1,3)*(a(2,1)*a(3,2)-a(2,2)*a(3,1)) \n END FUNCTION f\n\n\n!Funtion finds the cofactor matrix of \"a\"\n FUNCTION C(a)\n IMPLICIT NONE\n REAL, DIMENSION(1:3,1:3) :: C,co\n REAL, INTENT(IN), DIMENSION(1:3,1:3) :: a\n \n co(1,1)=(-1)**(1+1)*(a(2,2)*a(3,3)-a(2,3)*a(3,2))\n co(1,2)=(-1)**(1+2)*(a(2,1)*a(3,3)-a(2,3)*a(3,1))\n co(1,3)=(-1)**(1+3)*(a(2,1)*a(3,2)-a(2,2)*a(3,1))\n co(2,1)=(-1)**(2+1)*(a(1,2)*a(3,3)-a(1,3)*a(3,2))\n co(2,2)=(-1)**(2+2)*(a(1,1)*a(3,3)-a(1,3)*a(3,1))\n co(2,3)=(-1)**(2+3)*(a(1,1)*a(3,2)-a(1,2)*a(3,1))\n co(3,1)=(-1)**(3+1)*(a(1,2)*a(2,3)-a(1,3)*a(2,2))\n co(3,2)=(-1)**(3+2)*(a(1,1)*a(2,3)-a(1,3)*a(2,1))\n co(3,3)=(-1)**(3+3)*(a(1,1)*a(2,2)-a(1,2)*a(2,1)) \n \n C=transpose(co)\n END FUNCTION C\n \n\n!Function finds the matrix inverse of \"a\"\n FUNCTION B(cc,ff)\n IMPLICIT NONE\n REAL, INTENT(IN) :: cc(1:3,1:3)\n REAL, DIMENSION(1:3,1:3) :: d,B\n real::e,ff\n\n d=transpose(cc)\n e=1.0/ff\n B=e*d\n END FUNCTION B\n\nEND PROGRAM Linear_Algebra\n", "meta": {"hexsha": "3105999663a71a0f377b933f27b20de4ef5b4e5d", "size": 4224, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "6309823-Linear_Algebra.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-Linear_Algebra.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-Linear_Algebra.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": 31.7593984962, "max_line_length": 125, "alphanum_fraction": 0.454782197, "num_tokens": 1622, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789457685656, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.6979294287931638}} {"text": " subroutine eigen(N,A)\n implicit real*8(a-h,o-z)\n INTEGER*4,intent(in) :: N\n complex*16, intent(in) :: A(n,n)\n complex*16 :: mat(n,n) \n\n INTEGER LWMAX\n PARAMETER ( LWMAX = 1000 )\n INTEGER INFO, LWORK\n! .. Local Arrays ..\n! RWORK dimension should be at least MAX(1,3*N-2)\n DOUBLE PRECISION W( N ), RWORK( 3*N-2 )\n COMPLEX*16 WORK( LWMAX )\n LDA = N\n! .. External Subroutines ..\n! EXTERNAL ZHEEV\n! EXTERNAL PRINT_MATRIX, PRINT_RMATRIX\n!\n! .. Intrinsic Functions ..\n! INTRINSIC INT, MIN\n!\n! .. Executable Statements ..\n! WRITE(*,*)'ZHEEV Example Program Results'\n!\n! Query the optimal workspace.\n\n mat = A \n\n LWORK = -1\n CALL ZHEEV( 'Vectors', 'Lower', N, mat, LDA, W, WORK, LWORK, RWORK, INFO )\n LWORK = MIN( LWMAX, INT( WORK( 1 ) ) )\n\n! Solve eigenproblem.\n\n CALL ZHEEV( 'Vectors', 'Lower', N, mat, LDA, W, WORK, LWORK, RWORK, INFO)\n\n! Check for convergence.\n\n IF( INFO.GT.0 ) THEN\n WRITE(*,*)'The algorithm failed to compute eigenvalues.'\n STOP\n END IF\n \n ak = maxval(w)/minval(w)\n if (ak > 1d7) then\n stop\n else\n print *,'condition number', maxval(w)/minval(w) \n endif \n\n return \n end subroutine\n\n! End of ZHEEV Example.\n", "meta": {"hexsha": "ac5dd44bf59724e33bff81629bd0d247392bdaf4", "size": 1386, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "GWP/QTGB/eigen.f90", "max_stars_repo_name": "binggu56/qmd", "max_stars_repo_head_hexsha": "e2628710de15f8a8b9a1280fcf92f9e87559414c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "GWP/QTGB/eigen.f90", "max_issues_repo_name": "binggu56/qmd", "max_issues_repo_head_hexsha": "e2628710de15f8a8b9a1280fcf92f9e87559414c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "GWP/QTGB/eigen.f90", "max_forks_repo_name": "binggu56/qmd", "max_forks_repo_head_hexsha": "e2628710de15f8a8b9a1280fcf92f9e87559414c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.2, "max_line_length": 80, "alphanum_fraction": 0.5295815296, "num_tokens": 412, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969137, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6979294285937754}} {"text": "subroutine Runge_Kutta_Method(f, y0, h, range)\n procedure(Real) :: f\n Real :: y0, h, x, y, k1, k2, k3, k4\n Integer :: range\n\n dx = h\n y = y0\n x = 0\n\n Open(19, FILE=\"ode_result.dat\", status=\"NEW\")\n Do 13, I = 1, (range * INT(1/dx))\n k1 = f(x, y)\n k2 = f(x + Real(1) / 3 * h, y + Real(1) / 3 * k1 * h)\n k3 = f(x + 0.5 * h, y - Real(1) / 3 * k1 * h + k2 * h)\n k4 = f(x + h, y + k1 * h - k2 * h + k3 * h)\n Write(19, *) x, y\n\n x = x + dx\n y = y + h * (k1 + 3 * k2 + 3 * k3 + k4) / 8\n13 continue\n Close(19)\ncontains\nend subroutine Runge_Kutta_Method", "meta": {"hexsha": "f989ffa6d67dede9a0eecbea59d49de0d21dc1fd", "size": 620, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/cottoncandy_ode.f90", "max_stars_repo_name": "LionKingSmasher/CottonCandy", "max_stars_repo_head_hexsha": "9b8f1fa180ed6cbaff0c54d36eebc04d60e1d437", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source/cottoncandy_ode.f90", "max_issues_repo_name": "LionKingSmasher/CottonCandy", "max_issues_repo_head_hexsha": "9b8f1fa180ed6cbaff0c54d36eebc04d60e1d437", "max_issues_repo_licenses": ["MIT"], "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/cottoncandy_ode.f90", "max_forks_repo_name": "LionKingSmasher/CottonCandy", "max_forks_repo_head_hexsha": "9b8f1fa180ed6cbaff0c54d36eebc04d60e1d437", "max_forks_repo_licenses": ["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.9565217391, "max_line_length": 62, "alphanum_fraction": 0.4532258065, "num_tokens": 270, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894689081711, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6979294283943867}} {"text": "submodule(euler_interface_m) euler_prob_0010_m\n implicit none\n\ncontains\n\n module character(len=20) function euler0010()\n write (euler0010, \"(i20)\") ans(2000000_int64)\n end function euler0010\n\n integer(int64) function ans(n)\n use euler_primes_m, only: sieve_of_eratosthenes\n implicit none\n integer(int64), intent(in) :: n\n integer(int64) :: i, tmp\n logical, allocatable :: is_prime(:)\n\n tmp = 0_int64\n call sieve_of_eratosthenes(n, is_prime)\n\n ! ans = sum( pack([ (i, i = 0_int64, n) ], is_prime) )\n do i = 0_int64, n\n if (is_prime(i)) then\n tmp = tmp + i\n end if\n end do\n ans = tmp\n end function ans\nend submodule euler_prob_0010_m\n", "meta": {"hexsha": "f885e829587c0ba85479cf0a31cd2ff662daefc0", "size": 768, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "docs/src/prob_0010_m.f90", "max_stars_repo_name": "han190/PE-Fortran", "max_stars_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-02-09T07:07:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-31T07:45:48.000Z", "max_issues_repo_path": "docs/src/prob_0010_m.f90", "max_issues_repo_name": "han190/PE-Fortran", "max_issues_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-14T00:48:58.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-14T00:48:58.000Z", "max_forks_repo_path": "docs/src/prob_0010_m.f90", "max_forks_repo_name": "han190/PE-Fortran", "max_forks_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-04T21:29:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T21:29:45.000Z", "avg_line_length": 26.4827586207, "max_line_length": 62, "alphanum_fraction": 0.5963541667, "num_tokens": 221, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894689081711, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6979294283943867}} {"text": " module upsample2d_preallocate\n\n implicit none\n include \"fftw3.f\"\n ! 2d upsampling, using Fourier Transform\n\n contains\n\n subroutine upsample2d_complex(a,aup,Atrans,Auptrans,plan,plani,m,n,novr)\n ! upsample matrix a (size mxn) by a factor of novr\n ! output is in aa\n ! aup must be size(m*novr x n*novr)\n \n ! Atrans is workspace, must be size mxn\n ! Auptrans is workspace, must be size m*novr x n*novr\n\n ! plan and plani must be created thus:\n ! call sfftw_plan_dft_2d(plan,m,n,a,Atrans,FFTW_FORWARD,FFTW_ESTIMATE)\n ! call sfftw_plan_dft_2d(plani,m*novr,n*novr,Auptrans,aup,FFTW_BACKWARD,FFTW_ESTIMATE)\n\n ! input\n complex, dimension(:,:), intent(in) :: a\n integer, intent(in) :: m, n, novr\n integer*8, intent(in) :: plan, plani\n\n ! output\n complex, dimension(:,:), intent(out) :: aup\n complex, dimension(:,:), intent(out) :: Atrans,Auptrans\n\n ! computation variables\n integer :: nyqst_m, nyqst_n\n\n ! 2d fft\n call sfftw_execute(plan)\n\n ! Nyquist frequencies\n nyqst_m = ceiling((m+1)/2.0)\n nyqst_n = ceiling((n+1)/2.0)\n\n ! zero out spectra\n Auptrans(1:(m*novr),1:(n*novr)) = cmplx(0.0,0.0)\n\n ! copy spectra\n Auptrans(1:nyqst_m,1:nyqst_n) = Atrans(1:nyqst_m,1:nyqst_n);\n Auptrans(m*novr-nyqst_m+3:m*novr,1:nyqst_n) = Atrans(nyqst_m+1:m,1:nyqst_n);\n Auptrans(1:nyqst_m,n*novr-nyqst_n+3:n*novr) = Atrans(1:nyqst_m,nyqst_n+1:n);\n Auptrans(m*novr-nyqst_m+3:m*novr,n*novr-nyqst_n+3:n*novr) = Atrans(nyqst_m+1:m,nyqst_n+1:n);\n\n if(mod(m,2).eq.0)then\n Auptrans(nyqst_m,1:(n*novr)) = Auptrans(nyqst_m,1:(n*novr))/cmplx(2.0,0.0)\n Auptrans(m*novr-nyqst_m+2,1:(n*novr)) = Auptrans(nyqst_m,1:(n*novr))\n end if\n\n if(mod(n,2).eq.0) then\n Auptrans(1:(m*novr),nyqst_n) = Auptrans(1:(m*novr),nyqst_n)/cmplx(2.0,0.0)\n Auptrans(1:(m*novr),n*novr-nyqst_n+2) = Auptrans(1:(m*novr),nyqst_n)\n end if\n\n ! 2d inverse fft\n call sfftw_execute(plani)\n \n ! normalize\n aup = aup / cmplx(real(m*n),0.0)\n\n end subroutine upsample2d_complex\n\n end module upsample2d_preallocate\n\n", "meta": {"hexsha": "af64761fb71b3d9d0f1b9558b294f33105ba7010", "size": 2305, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "components/isceobj/Util/denseoffsets/src/upsample2d_preallocate.f", "max_stars_repo_name": "vincentschut/isce2", "max_stars_repo_head_hexsha": "1557a05b7b6a3e65abcfc32f89c982ccc9b65e3c", "max_stars_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_stars_count": 1133, "max_stars_repo_stars_event_min_datetime": "2022-01-07T21:24:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-07T21:33:08.000Z", "max_issues_repo_path": "components/isceobj/Util/denseoffsets/src/upsample2d_preallocate.f", "max_issues_repo_name": "vincentschut/isce2", "max_issues_repo_head_hexsha": "1557a05b7b6a3e65abcfc32f89c982ccc9b65e3c", "max_issues_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_issues_count": 276, "max_issues_repo_issues_event_min_datetime": "2019-02-10T07:18:28.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:45:55.000Z", "max_forks_repo_path": "components/isceobj/Util/denseoffsets/src/upsample2d_preallocate.f", "max_forks_repo_name": "vincentschut/isce2", "max_forks_repo_head_hexsha": "1557a05b7b6a3e65abcfc32f89c982ccc9b65e3c", "max_forks_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_forks_count": 235, "max_forks_repo_forks_event_min_datetime": "2019-02-10T05:00:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T07:37:24.000Z", "avg_line_length": 33.4057971014, "max_line_length": 104, "alphanum_fraction": 0.5947939262, "num_tokens": 851, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.935346511643776, "lm_q2_score": 0.7461389873857264, "lm_q1q2_score": 0.6978984990526585}} {"text": "c Compute distance and azimuth on a sphere\n\n\tsubroutine delaz(alat, alon, blat, blon, del, dist, az)\n\nc\tcomputes distance and azimuth from a to b\nc\ta and b are in decimal degrees and n-e coordinates\nc\tdel -- delta in degrees\nc\tdist -- distance in km\nc\taz -- azimuth from a to b clockwise from north in degrees\n\nc\tOriginal author: Bruce Julian\nc\tnew values for radius used (from Edi Kissling)\n\n\timplicit none\n\nc\tParameters:\n\treal\talat, alon\t! Coordinates of first point\n\treal\tblat, blon\t! Coordinates of second point\n\treal\tdel\t\t! Central angle (degrees)\n\treal\tdist\t\t! Distance (km)\n\treal\taz\t\t! Azimuth from a to b (degrees)\n\n\treal\txtop\n\treal\txden\n\nc\tLocal variables:\n\tdoubleprecision\tacol, bcol\n\tdoubleprecision\tazr\n\tdoubleprecision\tblatr, blonr\n\tdoubleprecision\tcolat\n\tdoubleprecision\tcosdel\n\tdoubleprecision\tdelr\n\tdoubleprecision\tflat\n\tdoubleprecision\tgeoa\n\tdoubleprecision\tgeob\n\tdoubleprecision\trad\n\tdoubleprecision\tradius\n\tdoubleprecision alatr, alonr\n\tdoubleprecision diflon\n\tdoubleprecision pi2\n\tdoubleprecision tana, tanb\n\nc\tBuilt-in functions: Declarations not needed\n\tdoubleprecision dtan\n\tdoubleprecision\tdatan\n\tdoubleprecision\tdsin\n\tdoubleprecision\tdcos\n\tdoubleprecision\tdacos\n\nc\tdoubleprecision top,den\n\n\tdata pi2/1.570796d0/\n\tdata rad/1.745329d-02/\n\tdata flat/.993231d0/\n\nc-----convert to radians\n\talatr=alat*rad\n\talonr=alon*rad\n\tblatr=blat*rad\n\tblonr=blon*rad\nc-----convert latitudes to geocentric colatitudes\n\ttana=flat*dtan(alatr)\n\tgeoa=datan(tana)\n\tacol=pi2-geoa\n\ttanb=flat*dtan(blatr)\n\tgeob=datan(tanb)\n\tbcol=pi2-geob\nc-----calculate delta\n\tdiflon=blonr-alonr\n\tcosdel=dsin(acol)*dsin(bcol)*dcos(diflon)+dcos(acol)*\n &\tdcos(bcol)\n\tdelr=dacos(cosdel)\nc-----calculate azimuth from a to b\n\nc*****\tNote the use of single precision xtop and xden instead\nc\tof the double precision top and den in the original\nc\tprogram.\nc*****\tNote also the call to atan2 instead of datan2.\nc\tBoth of these changes were made so that dyn.load\nc\twould work in Splus. For some reason, the ld command\nc\tld -r -d didn't find _d_atan2\nc\t\t\t\t\t\tWLE 10/16/91\n\n\txtop = dsin(diflon)\n\txden=(dsin(acol)/dtan(bcol))-dcos(diflon)*dcos(acol)\n\tazr=atan2(xtop,xden)\nc----- convert to degrees\n\tdel=delr/rad\n\taz=azr/rad\n\tif(az.lt.0.0) az=360.+az\nc-----compute distance in kilometers\n\tcolat=pi2-(alatr+blatr)/2.d0\n\tradius=6378.163d0*\n &\t(1.d0+3.35278d-3*((1.d0/3.d0)-(dcos(colat)**2)))\n\tdist=delr*radius\n\treturn\nc ***** end of subroutine delaz *****\n\tend\n", "meta": {"hexsha": "b9eebde5c2d7937c81ebabc5f44f0c724c900f7f", "size": 2438, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "HypoDD_scripts/src/ph2dt/delaz.f", "max_stars_repo_name": "Damin1909/ESPRH", "max_stars_repo_head_hexsha": "2b26a7e698fe7c411d44ce5f51d52fffdb742d48", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-12-02T02:01:11.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-02T02:01:11.000Z", "max_issues_repo_path": "HypoDD_scripts/src/ph2dt/delaz.f", "max_issues_repo_name": "Damin1909/ESPRH", "max_issues_repo_head_hexsha": "2b26a7e698fe7c411d44ce5f51d52fffdb742d48", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HypoDD_scripts/src/ph2dt/delaz.f", "max_forks_repo_name": "Damin1909/ESPRH", "max_forks_repo_head_hexsha": "2b26a7e698fe7c411d44ce5f51d52fffdb742d48", "max_forks_repo_licenses": ["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.6262626263, "max_line_length": 61, "alphanum_fraction": 0.7444626743, "num_tokens": 798, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.939024820841433, "lm_q2_score": 0.7431680086124812, "lm_q1q2_score": 0.6978532061424197}} {"text": "\\ Doubles\r\n\r\n: d>s drop ; macro \\ 8.6.1.1140\r\n: 2rot 2>r 2swap 2r> 2swap ; \\ 8.6.2.0420\r\n: -2rot 2rot 2rot ;\r\n: 2nip 2swap 2drop ;\r\n: 2tuck 2swap 2over ;\r\n: d- dnegate d+ ; \\ 8.6.1.1050\r\n: d< d- 0< ;\r\n: d= d- 0= ; \\ 8.6.1.1120\r\n: d0= or 0= ; macro \\ 8.6.1.1080 d -- flag\r\n: d0< swap drop 0< ; macro \\ 8.6.1.1075 d -- flag\r\n: d2* swap 2* swap 2*c ; \\ 8.6.1.1090 d -- d'\r\nhex\r\n: d2/\r\n 2/ swap ifnc 2/ swap exit then \\ 8.6.1.1100 d -- d'\r\n 80 0 litx or swap\r\n;\r\ndecimal\r\n\r\n: 2literal \\ d -- \\ 8.6.1.0390\r\n swap postpone literal\r\n postpone literal\r\n; immediate\r\n\r\n: 2variable \\ -- \\ 8.6.1.0440\r\n create 2 cells /allot\r\n;\r\n\r\n: 2constant \\ d -- \\ 8.6.1.0360\r\n create , , does> 2@\r\n;\r\n\r\n: d< ( d1 d2 -- flag ) \\ 8.6.1.1110\r\n rot 2dup = if 2drop u< exit then 2nip >\r\n;\r\n: du< \\ ud1 ud2 -- flag \\ 8.6.2.1270\r\n rot 2dup = if 2drop u< exit then 2nip swap u<\r\n;\r\n: dmax \\ d1 d2 -- d3 \\ 8.6.1.1210\r\n 2over 2over d< if 2swap then 2drop\r\n;\r\n: dmin ( d d2 -- d3 ) \\ 8.6.1.1220\r\n 2over 2over d< 0= if 2swap then 2drop\r\n;\r\n\r\n: m+ s>d d+ ; \\ 8.6.1.1830\r\n\r\n: m* \\ 8.6.1.1820\r\n 2dup xor >r\r\n abs swap abs um*\r\n r> 0< if dnegate then\r\n;\r\n\r\n\\ From Wil Baden's \"FPH Popular Extensions\"\r\n\\ http://www.wilbaden.com/neil_bawd/fphpop.txt\r\n\r\n: tnegate ( t . . -- -t . . )\r\n >r 2dup or dup if drop dnegate 1 then\r\n r> + negate ;\r\n\r\n: t* ( d . n -- t . . )\r\n ( d0 d1 n)\r\n 2dup xor >r ( r: sign)\r\n >r dabs r> abs\r\n 2>r ( d0)( r: sign d1 n)\r\n r@ um* 0 ( t0 d1 0)\r\n 2r> um* ( t0 d1 0 d1*n .)( r: sign)\r\n d+ ( t0 t1 t2)\r\n r> 0< if tnegate then ;\r\n\r\n: t/ ( t . . u -- d . )\r\n ( t0 t1 t2 u)\r\n over >r >r ( t0 t1 t2)( r: t2 u)\r\n dup 0< if tnegate then\r\n r@ um/mod ( t0 rem d1)\r\n rot rot ( d1 t0 rem)\r\n r> um/mod ( d1 rem' d0)( r: t2)\r\n nip swap ( d0 d1)\r\n r> 0< if dnegate then ;\r\n\r\n: m*/ ( d . n u -- d . ) >r t* r> t/ ;\r\n\r\n\r\n\\ Double-Number extension words not defined:\r\n\\ 8.6.2.0435 2VALUE\r\n\r\n", "meta": {"hexsha": "bba43f5064f43c500a472d10747872a1625414c5", "size": 2736, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "forth/double.f", "max_stars_repo_name": "bradleyeckert/Mforth", "max_stars_repo_head_hexsha": "a0c403ccc85cf67e66e9714a974ecf8515876f2c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2019-05-10T03:13:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-15T15:20:51.000Z", "max_issues_repo_path": "forth/double.f", "max_issues_repo_name": "bradleyeckert/Mforth", "max_issues_repo_head_hexsha": "a0c403ccc85cf67e66e9714a974ecf8515876f2c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "forth/double.f", "max_forks_repo_name": "bradleyeckert/Mforth", "max_forks_repo_head_hexsha": "a0c403ccc85cf67e66e9714a974ecf8515876f2c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-05-26T10:16:14.000Z", "max_forks_repo_forks_event_max_datetime": "2019-05-26T10:16:14.000Z", "avg_line_length": 31.0909090909, "max_line_length": 64, "alphanum_fraction": 0.360380117, "num_tokens": 997, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.868826789824086, "lm_q2_score": 0.8031737987125613, "lm_q1q2_score": 0.6978189132062513}} {"text": "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC\nC Written by: Anshuk Attri\nC\nC Contact: contact@anshukattri.in\nC Website: www.anshukattri.in/research\nC GITHUB: github.com/aa-tree/\nC\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n\n\n SUBROUTINE GET_VEC_MOD(I_VEC, O_MOD)\n IMPLICIT NONE\n\n INCLUDE 'common.dat'\n\n REAL*8 I_VEC(6)\n REAL*8 O_MOD\n\n!\n! SUMMARY:\n!\n! Returns the mod of a vector.\n!\n! VARIABLES:\n!\n! NAME TYPE DESCRIPTION\n!\n! I_VEC(6) INPUT(REAL*8) The vector for which mod is to be\n! calculated.\n!\n! O_MOD OUTPUT(REAL*8) Modulus of the vector.\n!\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n\n\n O_MOD=0.0D0\n\n O_MOD=SQRT(I_VEC(1)**2.0D0+ I_VEC(2)**2.0D0+ I_VEC(3)**2.0D0)\n\n RETURN\n END\n", "meta": {"hexsha": "440f18306216d0d69c8f694b884064da370286a5", "size": 955, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "fortran_src/code/GET_VEC_MOD.f", "max_stars_repo_name": "aa-tree/SPICEReader", "max_stars_repo_head_hexsha": "3242944556178dbc9a895b3736528e3a57fb46b9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fortran_src/code/GET_VEC_MOD.f", "max_issues_repo_name": "aa-tree/SPICEReader", "max_issues_repo_head_hexsha": "3242944556178dbc9a895b3736528e3a57fb46b9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran_src/code/GET_VEC_MOD.f", "max_forks_repo_name": "aa-tree/SPICEReader", "max_forks_repo_head_hexsha": "3242944556178dbc9a895b3736528e3a57fb46b9", "max_forks_repo_licenses": ["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.2093023256, "max_line_length": 71, "alphanum_fraction": 0.6272251309, "num_tokens": 286, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267830311355, "lm_q2_score": 0.8031737963569014, "lm_q1q2_score": 0.697818905703671}} {"text": "program test_dpss\n\n!********************************************************************\n\n implicit none\n\n! Important variables\n\n integer, parameter :: npts=101, nev=7\n real(8) :: fw\n real(8), dimension(npts,nev) :: v\n real(8), dimension(nev) :: lambda, theta\n\n!********************************************************************\n\n fw = 4.d0\n call dpss(npts, fw, nev, v, lambda, theta)\n\nend program\n\nsubroutine dpss(npts, fw, nev, v, lambda, theta)\n\n!\n! Modified:\n!\tGerman Prieto\n!\tNovember 2004\n!\n! Calculation of the Discrete Prolate Spheroidal Sequences, and \n! the correspondent eigenvalues. Also, the (1 - eigenvalue) terms\n! are calculated. \n!\n! Slepian, D. 1978 Bell Sys Tech J v57 n5 1371-1430\n! Thomson, D. J. 1982 Proc IEEE v70 n9 1055-1096\n!\n! Input:\n! npts \tthe number of points in the series\n! fw \tthe time-bandwidth product (number of Rayleigh bins)\n! nev \tthe desired number of tapers\n!\n! Output:\n! v \tthe eigenvectors (tapers) are returned in v(npts,nev)\n! lambda \tthe eigenvalues of the v's\n! theta\tthe 1-lambda values. The energy outside the bandwidth\n!\n! The tapers are the eigenvectors of the tridiagonal matrix sigma(i,j)\n! [see Slepian(1978) eq 14 and 25.] They are also the eigenvectors of\n! the Toeplitz matrix eq. 18. We solve the tridiagonal system in\n! rst_eig (real symmetric tridiagonal solver) for the tapers and use \n! them in the integral equation in the frequency domain \n! (dpss_ev subroutine) to get the eigenvalues more accurately, \n! by performing Chebychev Gaussian Quadrature following Thomson's codes.\n!\n! First, we create the main and off-diagonal vectors of the \n! tridiagonal matrix. We compute separetely the even and odd tapers, \n! by calling rst_eig from LAPACK.\n! We, refine the eigenvalues, by computing the inner bandwidth \n! energy in the frequency domain (eq. 2.6 Thomson). Also the \"leakage\"\n! (1 - eigenvalue) is estimated, independenly if necesary. \n!\n! calls rst_eig, dpss_ev\n!\n\n!********************************************************************\n\n implicit none\n\n! Important variables\n\n integer, intent(in) :: npts, nev\n real(8), intent(in) :: fw \n\n real(8), intent(out), dimension(nev) :: lambda, theta\n real(8), intent(out), dimension(npts,nev) :: v\n\n! Parameters\n\n real(8), parameter :: pi=3.141592653589793d0, r2=1.4142135623731d0\n\n integer :: ntot, lh, nr, k, kr, k2, n, i, ierr, nx\n \n real(8) :: atol, sn, lb, ub\n\n! Working variables\n\n integer :: neven, nodd\n integer, dimension(nev) :: ind\n \n real(8) :: bw, hn, com\n real(8), dimension(nev) :: eigval\n real(8), dimension(:), allocatable :: fv1, fv2\n real(8), dimension(:,:), allocatable :: v2\n\n!********************************************************************\n\n if (npts < 2) then\n return\n endif\n\n nx=mod(npts,2)\n lh=(npts/2)+nx\n\n nodd = nev/2\n neven = nev - nodd\n\n print *, 'npts lh nx ', npts, lh, nx\n print *, '101/2, 100/2', npts/2, (npts+1)/2\n print *, nev, nodd, neven\n\n bw = fw/dble(npts)\n com = cos(2.d0*pi*bw)\n\n hn = dble(npts-1)/2.d0\n\n print *, bw,com,hn\n\n if (allocated(fv1)) then\n deallocate(fv1)\n endif \n if (allocated(fv2)) then\n deallocate(fv2)\n endif \n\n allocate(fv1(lh))\n allocate(fv2(lh))\n\n!\n! Perform symmetry reduction to half size\n!\n\n do i=1,lh\n n = i-1\n! Main diagonal\n fv1(i) = com*(hn - dble(n))**2.d0\n! sub diagonal\n fv2(i) = dble(n*(npts-n))/2.d0\n\n enddo\n \n if (nx.eq.0) then\n fv1(lh) = com* (hn - dble(lh-1))**2.d0 + dble(lh*(npts-lh))/2.d0\n else\n fv2(lh) = r2*fv2(lh)\n endif\n \n do i=1,lh\n print *, fv1(i), fv2(i)\n enddo\n\n return\n \n!\n! Do the even tapers\n!\n \n if (allocated(v2)) then\n deallocate(v2)\n endif \n allocate(v2(lh,neven))\n \n call rst_eig(lh,fv1,fv2(2:lh),neven,eigval,v2)\n\n if (nx==1) then\n do k = 1,neven\n v2(lh,k) = r2*v2(lh,k)\n enddo\n endif\n\n do k = 1,neven\n kr = k\n k2 = 2*k - 1\n\n theta(k2) = eigval(kr)\n\n!\n! Expand the eigenfunctions\n!\n\n nr=npts\n do i=1,lh\n v(i,k2) = v2(i,kr)\n v(nr,k2)= v2(i,kr)\n nr=nr-1\n enddo\n\n!\n! Normalize the eigenfunction\n!\n\n sn=0.d0\n do n=1,npts\n sn=sn+v(n,k2)*v(n,k2)\n enddo\n \n sn=1.d0/sqrt(sn)\n\n!\n! Put eigenfunctions positive standard\n!\n\n if ((v(lh+1,k2).lt.0.d0)) then\n sn=-sn\n endif\n \n do n=1,npts\n v(n,k2)=sn*v(n,k2)\n enddo\n \n enddo\n\n!\n! Do the odd tapers\n!\n\n if (nodd > 0) then \n\n if (allocated(v2)) then\n deallocate(v2)\n endif \n allocate(v2(lh-nx,nodd))\n\n do i=1,lh\n n = i-1\n fv1(i) = com*(hn - dble(n))**2\n fv2(i) = dble(n*(npts-n))/2.d0\n enddo\n \n if (nx.eq.0) then\n fv1(lh) = com* (hn - dble(lh-1))**2 - dble(lh*(npts-lh))/2.d0\n endif\n \n call rst_eig(lh-nx,fv1,fv2(2:lh-nx),nodd,eigval,v2)\n \n do k = 1,nodd\n kr = k\n k2 = 2*k \n\n theta(k2) = eigval(kr)\n\n!\n! Expand the eigenfunctions\n!\n\n nr=npts\n do i=1,lh-nx\n v(i,k2) = v2(i,kr)\n v(nr,k2)= -v2(i,kr)\n nr=nr-1\n enddo\n if (nx == 1) then\n v(lh,k2) = 0.d0\n endif\n \n!\n! Normalize the eigenfunction\n!\n\n sn=0.d0\n do n=1,npts\n sn=sn+v(n,k2)*v(n,k2)\n enddo\n \n sn=1.d0/sqrt(sn)\n\n!\n! Put eigenfunctions positive standard\n!\n\n if ((nx==1) .and. (v(lh+1,k2).lt.0.d0)) then\n sn = -sn \n endif\n if ((nx <= 0) .and. (v(lh+1,k2).lt.0.d0)) then\n sn=-sn\n endif\n\n do n=1,npts\n v(n,k2)=sn*v(n,k2)\n enddo\n\n enddo\n\n endif\n\n ntot=neven+nodd\n\n!\n! Get the eigenvalues, by Quadrature (Chebychev)\n!\n\n atol = 1.d-14\n\n call dpss_ev(npts,nev,bw,atol,v,lambda,theta)\n\n deallocate(fv1,fv2,v2)\n\n return\n \nend subroutine dpss\n\n\n\n", "meta": {"hexsha": "a3aaacf2b6b411ffa8371d3e881d194fe8e38afd", "size": 6006, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "dev/dpss_f90.f90", "max_stars_repo_name": "paudetseis/multitaper", "max_stars_repo_head_hexsha": "121f4d05d7e83d7ef86170a237413fc25257ebc7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 26, "max_stars_repo_stars_event_min_datetime": "2022-02-09T06:33:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T17:17:10.000Z", "max_issues_repo_path": "dev/dpss_f90.f90", "max_issues_repo_name": "paudetseis/multitaper", "max_issues_repo_head_hexsha": "121f4d05d7e83d7ef86170a237413fc25257ebc7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-03-01T14:40:50.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-01T14:40:50.000Z", "max_forks_repo_path": "dev/dpss_f90.f90", "max_forks_repo_name": "paudetseis/multitaper", "max_forks_repo_head_hexsha": "121f4d05d7e83d7ef86170a237413fc25257ebc7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2022-02-28T19:10:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T13:50:53.000Z", "avg_line_length": 19.9534883721, "max_line_length": 73, "alphanum_fraction": 0.5381285381, "num_tokens": 2069, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.868826769445233, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.69781889274517}} {"text": "*DECK DEXINT\n SUBROUTINE DEXINT (X, N, KODE, M, TOL, EN, NZ, IERR)\nC***BEGIN PROLOGUE DEXINT\nC***PURPOSE Compute an M member sequence of exponential integrals\nC E(N+K,X), K=0,1,...,M-1 for N .GE. 1 and X .GE. 0.\nC***LIBRARY SLATEC\nC***CATEGORY C5\nC***TYPE DOUBLE PRECISION (EXINT-S, DEXINT-D)\nC***KEYWORDS EXPONENTIAL INTEGRAL, SPECIAL FUNCTIONS\nC***AUTHOR Amos, D. E., (SNLA)\nC***DESCRIPTION\nC\nC DEXINT computes M member sequences of exponential integrals\nC E(N+K,X), K=0,1,...,M-1 for N .GE. 1 and X .GE. 0. The\nC exponential integral is defined by\nC\nC E(N,X)=integral on (1,infinity) of EXP(-XT)/T**N\nC\nC where X=0.0 and N=1 cannot occur simultaneously. Formulas\nC and notation are found in the NBS Handbook of Mathematical\nC Functions (ref. 1).\nC\nC The power series is implemented for X .LE. XCUT and the\nC confluent hypergeometric representation\nC\nC E(A,X) = EXP(-X)*(X**(A-1))*U(A,A,X)\nC\nC is computed for X .GT. XCUT. Since sequences are computed in\nC a stable fashion by recurring away from X, A is selected as\nC the integer closest to X within the constraint N .LE. A .LE.\nC N+M-1. For the U computation, A is further modified to be the\nC nearest even integer. Indices are carried forward or\nC backward by the two term recursion relation\nC\nC K*E(K+1,X) + X*E(K,X) = EXP(-X)\nC\nC once E(A,X) is computed. The U function is computed by means\nC of the backward recursive Miller algorithm applied to the\nC three term contiguous relation for U(A+K,A,X), K=0,1,...\nC This produces accurate ratios and determines U(A+K,A,X), and\nC hence E(A,X), to within a multiplicative constant C.\nC Another contiguous relation applied to C*U(A,A,X) and\nC C*U(A+1,A,X) gets C*U(A+1,A+1,X), a quantity proportional to\nC E(A+1,X). The normalizing constant C is obtained from the\nC two term recursion relation above with K=A.\nC\nC The maximum number of significant digits obtainable\nC is the smaller of 14 and the number of digits carried in\nC double precision arithmetic.\nC\nC Description of Arguments\nC\nC Input * X and TOL are double precision *\nC X X .GT. 0.0 for N=1 and X .GE. 0.0 for N .GE. 2\nC N order of the first member of the sequence, N .GE. 1\nC (X=0.0 and N=1 is an error)\nC KODE a selection parameter for scaled values\nC KODE=1 returns E(N+K,X), K=0,1,...,M-1.\nC =2 returns EXP(X)*E(N+K,X), K=0,1,...,M-1.\nC M number of exponential integrals in the sequence,\nC M .GE. 1\nC TOL relative accuracy wanted, ETOL .LE. TOL .LE. 0.1\nC ETOL is the larger of double precision unit\nC roundoff = D1MACH(4) and 1.0D-18\nC\nC Output * EN is a double precision vector *\nC EN a vector of dimension at least M containing values\nC EN(K) = E(N+K-1,X) or EXP(X)*E(N+K-1,X), K=1,M\nC depending on KODE\nC NZ underflow indicator\nC NZ=0 a normal return\nC NZ=M X exceeds XLIM and an underflow occurs.\nC EN(K)=0.0D0 , K=1,M returned on KODE=1\nC IERR error flag\nC IERR=0, normal return, computation completed\nC IERR=1, input error, no computation\nC IERR=2, error, no computation\nC algorithm termination condition not met\nC\nC***REFERENCES M. Abramowitz and I. A. Stegun, Handbook of\nC Mathematical Functions, NBS AMS Series 55, U.S. Dept.\nC of Commerce, 1955.\nC D. E. Amos, Computation of exponential integrals, ACM\nC Transactions on Mathematical Software 6, (1980),\nC pp. 365-377 and pp. 420-428.\nC***ROUTINES CALLED D1MACH, DPSIXN, I1MACH\nC***REVISION HISTORY (YYMMDD)\nC 800501 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890531 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\nC 900326 Removed duplicate information from DESCRIPTION section.\nC (WRB)\nC 910408 Updated the REFERENCES section. (WRB)\nC 920207 Updated with code with a revision date of 880811 from\nC D. Amos. Included correction of argument list. (WRB)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE DEXINT\n DOUBLE PRECISION A,AA,AAMS,AH,AK,AT,B,BK,BT,CC,CNORM,CT,EM,EMX,EN,\n 1 ETOL,FNM,FX,PT,P1,P2,S,TOL,TX,X,XCUT,XLIM,XTOL,Y,\n 2 YT,Y1,Y2\n DOUBLE PRECISION D1MACH,DPSIXN\n INTEGER I,IC,ICASE,ICT,IERR,IK,IND,IX,I1M,JSET,K,KK,KN,KODE,KS,M,\n 1 ML,MU,N,ND,NM,NZ\n INTEGER I1MACH\n DIMENSION EN(*), A(99), B(99), Y(2)\n SAVE XCUT\n DATA XCUT / 2.0D0 /\nC***FIRST EXECUTABLE STATEMENT DEXINT\n IERR = 0\n NZ = 0\n ETOL = MAX(D1MACH(4),0.5D-18)\n IF (X.LT.0.0D0) IERR = 1\n IF (N.LT.1) IERR = 1\n IF (KODE.LT.1 .OR. KODE.GT.2) IERR = 1\n IF (M.LT.1) IERR = 1\n IF (TOL.LT.ETOL .OR. TOL.GT.0.1D0) IERR = 1\n IF (X.EQ.0.0D0 .AND. N.EQ.1) IERR = 1\n IF(IERR.NE.0) RETURN\n I1M = -I1MACH(15)\n PT = 2.3026D0*I1M*D1MACH(5)\n XLIM = PT - 6.907755D0\n BT = PT + (N+M-1)\n IF (BT.GT.1000.0D0) XLIM = PT - LOG(BT)\nC\n IF (X.GT.XCUT) GO TO 100\n IF (X.EQ.0.0D0 .AND. N.GT.1) GO TO 80\nC-----------------------------------------------------------------------\nC SERIES FOR E(N,X) FOR X.LE.XCUT\nC-----------------------------------------------------------------------\n TX = X + 0.5D0\n IX = TX\nC-----------------------------------------------------------------------\nC ICASE=1 MEANS INTEGER CLOSEST TO X IS 2 AND N=1\nC ICASE=2 MEANS INTEGER CLOSEST TO X IS 0,1, OR 2 AND N.GE.2\nC-----------------------------------------------------------------------\n ICASE = 2\n IF (IX.GT.N) ICASE = 1\n NM = N - ICASE + 1\n ND = NM + 1\n IND = 3 - ICASE\n MU = M - IND\n ML = 1\n KS = ND\n FNM = NM\n S = 0.0D0\n XTOL = 3.0D0*TOL\n IF (ND.EQ.1) GO TO 10\n XTOL = 0.3333D0*TOL\n S = 1.0D0/FNM\n 10 CONTINUE\n AA = 1.0D0\n AK = 1.0D0\n IC = 35\n IF (X.LT.ETOL) IC = 1\n DO 50 I=1,IC\n AA = -AA*X/AK\n IF (I.EQ.NM) GO TO 30\n S = S - AA/(AK-FNM)\n IF (ABS(AA).LE.XTOL*ABS(S)) GO TO 20\n AK = AK + 1.0D0\n GO TO 50\n 20 CONTINUE\n IF (I.LT.2) GO TO 40\n IF (ND-2.GT.I .OR. I.GT.ND-1) GO TO 60\n AK = AK + 1.0D0\n GO TO 50\n 30 S = S + AA*(-LOG(X)+DPSIXN(ND))\n XTOL = 3.0D0*TOL\n 40 AK = AK + 1.0D0\n 50 CONTINUE\n IF (IC.NE.1) GO TO 340\n 60 IF (ND.EQ.1) S = S + (-LOG(X)+DPSIXN(1))\n IF (KODE.EQ.2) S = S*EXP(X)\n EN(1) = S\n EMX = 1.0D0\n IF (M.EQ.1) GO TO 70\n EN(IND) = S\n AA = KS\n IF (KODE.EQ.1) EMX = EXP(-X)\n GO TO (220, 240), ICASE\n 70 IF (ICASE.EQ.2) RETURN\n IF (KODE.EQ.1) EMX = EXP(-X)\n EN(1) = (EMX-S)/X\n RETURN\n 80 CONTINUE\n DO 90 I=1,M\n EN(I) = 1.0D0/(N+I-2)\n 90 CONTINUE\n RETURN\nC-----------------------------------------------------------------------\nC BACKWARD RECURSIVE MILLER ALGORITHM FOR\nC E(N,X)=EXP(-X)*(X**(N-1))*U(N,N,X)\nC WITH RECURSION AWAY FROM N=INTEGER CLOSEST TO X.\nC U(A,B,X) IS THE SECOND CONFLUENT HYPERGEOMETRIC FUNCTION\nC-----------------------------------------------------------------------\n 100 CONTINUE\n EMX = 1.0D0\n IF (KODE.EQ.2) GO TO 130\n IF (X.LE.XLIM) GO TO 120\n NZ = M\n DO 110 I=1,M\n EN(I) = 0.0D0\n 110 CONTINUE\n RETURN\n 120 EMX = EXP(-X)\n 130 CONTINUE\n TX = X + 0.5D0\n IX = TX\n KN = N + M - 1\n IF (KN.LE.IX) GO TO 140\n IF (N.LT.IX .AND. IX.LT.KN) GO TO 170\n IF (N.GE.IX) GO TO 160\n GO TO 340\n 140 ICASE = 1\n KS = KN\n ML = M - 1\n MU = -1\n IND = M\n IF (KN.GT.1) GO TO 180\n 150 KS = 2\n ICASE = 3\n GO TO 180\n 160 ICASE = 2\n IND = 1\n KS = N\n MU = M - 1\n IF (N.GT.1) GO TO 180\n IF (KN.EQ.1) GO TO 150\n IX = 2\n 170 ICASE = 1\n KS = IX\n ML = IX - N\n IND = ML + 1\n MU = KN - IX\n 180 CONTINUE\n IK = KS/2\n AH = IK\n JSET = 1 + KS - (IK+IK)\nC-----------------------------------------------------------------------\nC START COMPUTATION FOR\nC EN(IND) = C*U( A , A ,X) JSET=1\nC EN(IND) = C*U(A+1,A+1,X) JSET=2\nC FOR AN EVEN INTEGER A.\nC-----------------------------------------------------------------------\n IC = 0\n AA = AH + AH\n AAMS = AA - 1.0D0\n AAMS = AAMS*AAMS\n TX = X + X\n FX = TX + TX\n AK = AH\n XTOL = TOL\n IF (TOL.LE.1.0D-3) XTOL = 20.0D0*TOL\n CT = AAMS + FX*AH\n EM = (AH+1.0D0)/((X+AA)*XTOL*SQRT(CT))\n BK = AA\n CC = AH*AH\nC-----------------------------------------------------------------------\nC FORWARD RECURSION FOR P(IC),P(IC+1) AND INDEX IC FOR BACKWARD\nC RECURSION\nC-----------------------------------------------------------------------\n P1 = 0.0D0\n P2 = 1.0D0\n 190 CONTINUE\n IF (IC.EQ.99) GO TO 340\n IC = IC + 1\n AK = AK + 1.0D0\n AT = BK/(BK+AK+CC+IC)\n BK = BK + AK + AK\n A(IC) = AT\n BT = (AK+AK+X)/(AK+1.0D0)\n B(IC) = BT\n PT = P2\n P2 = BT*P2 - AT*P1\n P1 = PT\n CT = CT + FX\n EM = EM*AT*(1.0D0-TX/CT)\n IF (EM*(AK+1.0D0).GT.P1*P1) GO TO 190\n ICT = IC\n KK = IC + 1\n BT = TX/(CT+FX)\n Y2 = (BK/(BK+CC+KK))*(P1/P2)*(1.0D0-BT+0.375D0*BT*BT)\n Y1 = 1.0D0\nC-----------------------------------------------------------------------\nC BACKWARD RECURRENCE FOR\nC Y1= C*U( A ,A,X)\nC Y2= C*(A/(1+A/2))*U(A+1,A,X)\nC-----------------------------------------------------------------------\n DO 200 K=1,ICT\n KK = KK - 1\n YT = Y1\n Y1 = (B(KK)*Y1-Y2)/A(KK)\n Y2 = YT\n 200 CONTINUE\nC-----------------------------------------------------------------------\nC THE CONTIGUOUS RELATION\nC X*U(B,C+1,X)=(C-B)*U(B,C,X)+U(B-1,C,X)\nC WITH B=A+1 , C=A IS USED FOR\nC Y(2) = C * U(A+1,A+1,X)\nC X IS INCORPORATED INTO THE NORMALIZING RELATION\nC-----------------------------------------------------------------------\n PT = Y2/Y1\n CNORM = 1.0E0 - PT*(AH+1.0E0)/AA\n Y(1) = 1.0E0/(CNORM*AA+X)\n Y(2) = CNORM*Y(1)\n IF (ICASE.EQ.3) GO TO 210\n EN(IND) = EMX*Y(JSET)\n IF (M.EQ.1) RETURN\n AA = KS\n GO TO (220, 240), ICASE\nC-----------------------------------------------------------------------\nC RECURSION SECTION N*E(N+1,X) + X*E(N,X)=EMX\nC-----------------------------------------------------------------------\n 210 EN(1) = EMX*(1.0E0-Y(1))/X\n RETURN\n 220 K = IND - 1\n DO 230 I=1,ML\n AA = AA - 1.0D0\n EN(K) = (EMX-AA*EN(K+1))/X\n K = K - 1\n 230 CONTINUE\n IF (MU.LE.0) RETURN\n AA = KS\n 240 K = IND\n DO 250 I=1,MU\n EN(K+1) = (EMX-X*EN(K))/AA\n AA = AA + 1.0D0\n K = K + 1\n 250 CONTINUE\n RETURN\n 340 CONTINUE\n IERR = 2\n RETURN\n END\n", "meta": {"hexsha": "26e8146cd9d8112f6f0b7e40f572049e208c3ab3", "size": 11640, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/dexint.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "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": "slatec/src/dexint.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/dexint.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.5400593472, "max_line_length": 72, "alphanum_fraction": 0.4721649485, "num_tokens": 4069, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554445, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.6978166664111854}} {"text": "SUBROUTINE RF1D(u,n,a,np)\n\n!****************************************************\n! This routine applies the recursive filter to u for\n! np times with alpha value of a.\n!\n! HISTORY: APR. 2003 by YUANFU XIE.\n!****************************************************\n\n IMPLICIT NONE\n\n INTEGER, INTENT(IN) :: n,np\n REAL, INTENT(IN) :: a\n REAL :: u(n)\n\n ! Local variables:\n INTEGER :: i,ip\n REAL :: one_a,r(n)\n\n one_a = 1.0-a\n\n ! Recurisve filter number of np times:\n DO ip=1,np\n \n ! Left to right:\n IF (ip .EQ. 1) THEN\n r(1) = one_a*u(1) \n ELSE IF (ip == 2 ) THEN\n r(1) = u(1) / ( 1.0 + a )\n ELSE\n r(1) = one_a * ( u(1) - a**3 * u(2) ) / &\n (1.0-a**2)**2\n END IF\n DO i=2,n\n r(i) = a*r(i-1)+one_a*u(i)\n ENDDO\n \n ! Right to left:\n IF (ip .EQ. 1) THEN\n u(n) = r(n)/(1.0+a) \n ELSE\n u(n) = one_a * ( r(n) - a**3 * r(n-1) ) / &\n (1.0-a**2)**2\n END IF\n DO i=n-1,1,-1\n u(i) = a*u(i+1)+one_a*r(i)\n ENDDO\n ENDDO\n\nEND SUBROUTINE RF1D\n", "meta": {"hexsha": "55b50350550d1f03e212885dce8a014a05eefcbb", "size": 1089, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/mesowave/recurs_iter/RF1D.f90", "max_stars_repo_name": "maxinye/laps-mirror", "max_stars_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_stars_repo_licenses": ["Intel", "Unlicense", "OLDAP-2.2.1", "NetCDF"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-04-05T12:28:22.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-29T06:37:29.000Z", "max_issues_repo_path": "src/mesowave/recurs_iter/RF1D.f90", "max_issues_repo_name": "longwosion/laps-mirror", "max_issues_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_issues_repo_licenses": ["Intel", "NetCDF", "OLDAP-2.2.1", "Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/mesowave/recurs_iter/RF1D.f90", "max_forks_repo_name": "longwosion/laps-mirror", "max_forks_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_forks_repo_licenses": ["Intel", "NetCDF", "OLDAP-2.2.1", "Unlicense"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-04-27T12:51:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-19T13:57:44.000Z", "avg_line_length": 21.3529411765, "max_line_length": 53, "alphanum_fraction": 0.4077134986, "num_tokens": 396, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809304, "lm_q2_score": 0.7879311956428946, "lm_q1q2_score": 0.6978166613076001}} {"text": " SUBROUTINE TF01RD( NA, NB, NC, N, A, LDA, B, LDB, C, LDC, H, LDH,\r\n $ DWORK, LDWORK, INFO )\r\nC\r\nC SLICOT RELEASE 5.5.\r\nC\r\nC Copyright (c) 2002-2012 NICONET e.V.\r\nC\r\nC PURPOSE\r\nC\r\nC To compute N Markov parameters M(1), M(2),..., M(N) from the\r\nC parameters (A,B,C) of a linear time-invariant system, where each\r\nC M(k) is an NC-by-NB matrix and k = 1,2,...,N.\r\nC\r\nC All matrices are treated as dense, and hence TF01RD is not\r\nC intended for large sparse problems.\r\nC\r\nC ARGUMENTS\r\nC\r\nC Input/Output Parameters\r\nC\r\nC NA (input) INTEGER\r\nC The order of the matrix A. NA >= 0.\r\nC\r\nC NB (input) INTEGER\r\nC The number of system inputs. NB >= 0.\r\nC\r\nC NC (input) INTEGER\r\nC The number of system outputs. NC >= 0.\r\nC\r\nC N (input) INTEGER\r\nC The number of Markov parameters M(k) to be computed.\r\nC N >= 0.\r\nC\r\nC A (input) DOUBLE PRECISION array, dimension (LDA,NA)\r\nC The leading NA-by-NA part of this array must contain the\r\nC state matrix A of the system.\r\nC\r\nC LDA INTEGER\r\nC The leading dimension of array A. LDA >= MAX(1,NA).\r\nC\r\nC B (input) DOUBLE PRECISION array, dimension (LDB,NB)\r\nC The leading NA-by-NB part of this array must contain the\r\nC input matrix B of the system.\r\nC\r\nC LDB INTEGER\r\nC The leading dimension of array B. LDB >= MAX(1,NA).\r\nC\r\nC C (input) DOUBLE PRECISION array, dimension (LDC,NA)\r\nC The leading NC-by-NA part of this array must contain the\r\nC output matrix C of the system.\r\nC\r\nC LDC INTEGER\r\nC The leading dimension of array C. LDC >= MAX(1,NC).\r\nC\r\nC H (output) DOUBLE PRECISION array, dimension (LDH,N*NB)\r\nC The leading NC-by-N*NB part of this array contains the\r\nC multivariable parameters M(k), where each parameter M(k)\r\nC is an NC-by-NB matrix and k = 1,2,...,N. The Markov\r\nC parameters are stored such that H(i,(k-1)xNB+j) contains\r\nC the (i,j)-th element of M(k) for i = 1,2,...,NC and\r\nC j = 1,2,...,NB.\r\nC\r\nC LDH INTEGER\r\nC The leading dimension of array H. LDH >= MAX(1,NC).\r\nC\r\nC Workspace\r\nC\r\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\r\nC\r\nC LDWORK INTEGER\r\nC The length of the array DWORK.\r\nC LDWORK >= MAX(1, 2*NA*NC).\r\nC\r\nC Error Indicator\r\nC\r\nC INFO INTEGER\r\nC = 0: successful exit;\r\nC < 0: if INFO = -i, the i-th argument had an illegal\r\nC value.\r\nC\r\nC METHOD\r\nC\r\nC For the linear time-invariant discrete-time system\r\nC\r\nC x(k+1) = A x(k) + B u(k)\r\nC y(k) = C x(k) + D u(k),\r\nC\r\nC the transfer function matrix G(z) is given by\r\nC -1\r\nC G(z) = C(zI-A) B + D\r\nC -1 -2 2 -3\r\nC = D + CB z + CAB z + CA B z + ... (1)\r\nC\r\nC Using Markov parameters, G(z) can also be written as\r\nC -1 -2 -3\r\nC G(z) = M(0) + M(1)z + M(2)z + M(3)z + ... (2)\r\nC\r\nC k-1\r\nC Equating (1) and (2), we find that M(0) = D and M(k) = C A B\r\nC for k > 0, from which the Markov parameters M(1),M(2)...,M(N) are\r\nC computed.\r\nC\r\nC REFERENCES\r\nC\r\nC [1] Chen, C.T.\r\nC Introduction to Linear System Theory.\r\nC H.R.W. Series in Electrical Engineering, Electronics and\r\nC Systems, Holt, Rinehart and Winston Inc., London, 1970.\r\nC\r\nC NUMERICAL ASPECTS\r\nC\r\nC The algorithm requires approximately (NA + NB) x NA x NC x N\r\nC multiplications and additions.\r\nC\r\nC CONTRIBUTOR\r\nC\r\nC Release 3.0: V. Sima, Katholieke Univ. Leuven, Belgium, Dec. 1996.\r\nC Supersedes Release 2.0 routine TF01FD by S. Van Huffel, Katholieke\r\nC Univ. Leuven, Belgium.\r\nC\r\nC REVISIONS\r\nC\r\nC -\r\nC\r\nC KEYWORDS\r\nC\r\nC Markov parameters, multivariable system, time-invariant system,\r\nC transfer function, transfer matrix.\r\nC\r\nC ******************************************************************\r\nC\r\nC .. Parameters ..\r\n DOUBLE PRECISION ZERO, ONE\r\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )\r\nC .. Scalar Arguments ..\r\n INTEGER INFO, LDA, LDB, LDC, LDH, LDWORK, N, NA, NB, NC\r\nC .. Array Arguments ..\r\n DOUBLE PRECISION A(LDA,*), B(LDB,*), C(LDC,*), DWORK(*), H(LDH,*)\r\nC .. Local Scalars ..\r\n INTEGER I, JWORK, K, LDW\r\nC .. External Subroutines ..\r\n EXTERNAL DGEMM, DLACPY, XERBLA\r\nC .. Intrinsic Functions ..\r\n INTRINSIC MAX, MIN\r\nC .. Executable Statements ..\r\nC\r\n INFO = 0\r\nC\r\nC Test the input scalar arguments.\r\nC\r\n IF( NA.LT.0 ) THEN\r\n INFO = -1\r\n ELSE IF( NB.LT.0 ) THEN\r\n INFO = -2\r\n ELSE IF( NC.LT.0 ) THEN\r\n INFO = -3\r\n ELSE IF( N.LT.0 ) THEN\r\n INFO = -4\r\n ELSE IF( LDA.LT.MAX( 1, NA ) ) THEN\r\n INFO = -6\r\n ELSE IF( LDB.LT.MAX( 1, NA ) ) THEN\r\n INFO = -8\r\n ELSE IF( LDC.LT.MAX( 1, NC ) ) THEN\r\n INFO = -10\r\n ELSE IF( LDH.LT.MAX( 1, NC ) ) THEN\r\n INFO = -12\r\n ELSE IF( LDWORK.LT.MAX( 1, 2*NA*NC ) ) THEN\r\n INFO = -14\r\n END IF\r\nC\r\n IF ( INFO.NE.0 ) THEN\r\nC\r\nC Error return.\r\nC\r\n CALL XERBLA( 'TF01RD', -INFO )\r\n RETURN\r\n END IF\r\nC\r\nC Quick return if possible.\r\nC\r\n IF ( MIN( NA, NB, NC, N ).EQ.0 )\r\n $ RETURN\r\nC\r\n JWORK = 1 + NC*NA\r\n LDW = MAX( 1, NC )\r\n I = 1\r\nC\r\nC Copy C in the workspace beginning from the position JWORK.\r\nC This workspace will contain the product C*A**(K-1), K = 1,2,...,N.\r\nC\r\n CALL DLACPY( 'Full', NC, NA, C, LDC, DWORK(JWORK), LDW )\r\nC\r\nC Form M(1), M(2), ..., M(N).\r\nC\r\n DO 10 K = 1, N\r\n CALL DLACPY( 'Full', NC, NA, DWORK(JWORK), LDW, DWORK, LDW )\r\nC\r\nC Form (C * A**(K-1)) * B = M(K).\r\nC\r\n CALL DGEMM( 'No transpose', 'No transpose', NC, NB, NA, ONE,\r\n $ DWORK, LDW, B, LDB, ZERO, H(1,I), LDH )\r\nC\r\n IF ( K.NE.N ) THEN\r\nC\r\nC Form C * A**K.\r\nC\r\n CALL DGEMM( 'No transpose', 'No transpose', NC, NA, NA, ONE,\r\n $ DWORK, LDW, A, LDA, ZERO, DWORK(JWORK), LDW )\r\nC\r\n I = I + NB\r\n END IF\r\n 10 CONTINUE\r\nC\r\n RETURN\r\nC *** Last line of TF01RD ***\r\n END\r\n", "meta": {"hexsha": "3713d3e3106e410ea1c607da7c9677312fc40842", "size": 6724, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "External/SLICOT/TF01RD.f", "max_stars_repo_name": "bgin/MissileSimulation", "max_stars_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2016-08-28T23:20:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-15T14:43:58.000Z", "max_issues_repo_path": "External/SLICOT/TF01RD.f", "max_issues_repo_name": "bgin/MissileSimulation", "max_issues_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-06-02T21:29:51.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-05T05:59:31.000Z", "max_forks_repo_path": "External/SLICOT/TF01RD.f", "max_forks_repo_name": "bgin/MissileSimulation", "max_forks_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-07-04T22:38:22.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-04T22:38:22.000Z", "avg_line_length": 30.9861751152, "max_line_length": 73, "alphanum_fraction": 0.498958953, "num_tokens": 2098, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9073122213606241, "lm_q2_score": 0.7690802476562641, "lm_q1q2_score": 0.6977959079055839}} {"text": "c\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc . .\nc . copyright (c) 1998 by UCAR .\nc . .\nc . University Corporation for Atmospheric Research .\nc . .\nc . all rights reserved .\nc . .\nc . .\nc . SPHEREPACK .\nc . .\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc\nc\nc\nc ... file sfvpec.f\nc\nc this file includes documentation and code for\nc subroutine sfvpec i\nc\nc ... files which must be loaded with sfvpec.f\nc\nc sphcom.f, hrfft.f, vhaec.f, shsec.f\nc\nc\nc subroutine sfvpec(nlat,nlon,isym,nt,sf,vp,idv,jdv,br,bi,cr,ci,\nc + mdb,ndb,wshsec,lshsec,work,lwork,ierror)\nc\nc given the vector spherical harmonic coefficients br,bi,cr,ci,\nc computed by subroutine vhaec for a vector field (v,w), sfvpec\nc computes a scalar stream function sf and scalar velocity potential\nc vp for (v,w). (v,w) is expressed in terms of sf and vp by the\nc helmholtz relations (in mathematical spherical coordinates):\nc\nc v = -1/sint*d(vp)/dlambda + d(st)/dtheta\nc\nc w = 1/sint*d(st)/dlambda + d(vp)/dtheta\nc\nc where sint = sin(theta). w is the east longitudinal and v\nc is the colatitudinal component of the vector field from which\nc br,bi,cr,ci were precomputed. required associated legendre\nc polynomials are recomputed rather than stored as they are in\nc subroutine sfvpes. sf(i,j) and vp(i,j) are given at colatitude\nc\nc theta(i) = (i-1)*pi/(nlat-1)\nc\nc and east longitude\nc\nc lambda(j) = (j-1)*2*pi/nlon\nc\nc on the sphere.\nc\nc\nc input parameters\nc\nc nlat the number of colatitudes on the full sphere including the\nc poles. for example, nlat = 37 for a five degree grid.\nc nlat determines the grid increment in colatitude as\nc pi/(nlat-1). if nlat is odd the equator is located at\nc grid point i=(nlat+1)/2. if nlat is even the equator is\nc located half way between points i=nlat/2 and i=nlat/2+1.\nc nlat must be at least 3. note: on the half sphere, the\nc number of grid points in the colatitudinal direction is\nc nlat/2 if nlat is even or (nlat+1)/2 if nlat is odd.\nc\nc nlon the number of distinct londitude points. nlon determines\nc the grid increment in longitude as 2*pi/nlon. for example\nc nlon = 72 for a five degree grid. nlon must be greater than\nc 3. the efficiency of the computation is improved when nlon\nc is a product of small prime numbers.\nc\nc\nc isym a parameter which determines whether the stream function and\nc velocity potential are computed on the full or half sphere\nc as follows:\nc\nc = 0\nc\nc the symmetries/antsymmetries described in isym=1,2 below\nc do not exist in (v,w) about the equator. in this case sf\nc and vp are not necessarily symmetric or antisymmetric about\nc the equator. sf and vp are computed on the entire sphere.\nc i.e., in arrays sf(i,j),vp(i,j) for i=1,...,nlat and\nc j=1,...,nlon.\nc\nc = 1\nc\nc w is antisymmetric and v is symmetric about the equator.\nc in this case sf is symmetric and vp antisymmetric about\nc the equator and are computed for the northern hemisphere\nc only. i.e., if nlat is odd the sf(i,j),vp(i,j) are computed\nc for i=1,...,(nlat+1)/2 and for j=1,...,nlon. if nlat is\nc even then sf(i,j),vp(i,j) are computed for i=1,...,nlat/2\nc and j=1,...,nlon.\nc\nc = 2\nc\nc w is symmetric and v is antisymmetric about the equator.\nc in this case sf is antisymmetric and vp symmetric about\nc the equator and are computed for the northern hemisphere\nc only. i.e., if nlat is odd the sf(i,j),vp(i,j) are computed\nc for i=1,...,(nlat+1)/2 and for j=1,...,nlon. if nlat is\nc even then sf(i,j),vp(i,j) are computed for i=1,...,nlat/2\nc and j=1,...,nlon.\nc\nc nt nt is the number of scalar and vector fields. some\nc computational efficiency is obtained for multiple fields. arrays\nc can be three dimensional corresponding to an indexed multiple\nc vector field. in this case multiple scalar synthesis will\nc be performed to compute sf,vp for each field. the\nc third index is the synthesis index which assumes the values\nc k=1,...,nt. for a single synthesis set nt = 1. the\nc description of the remaining parameters is simplified by\nc assuming that nt=1 or that all the arrays are two dimensional.\nc\nc idv the first dimension of the arrays sf,vp as it appears in\nc the program that calls sfvpec. if isym = 0 then idv\nc must be at least nlat. if isym = 1 or 2 and nlat is\nc even then idv must be at least nlat/2. if isym = 1 or 2\nc and nlat is odd then idv must be at least (nlat+1)/2.\nc\nc jdv the second dimension of the arrays sf,vp as it appears in\nc the program that calls sfvpec. jdv must be at least nlon.\nc\nc br,bi, two or three dimensional arrays (see input parameter nt)\nc cr,ci that contain vector spherical harmonic coefficients\nc of the vector field (v,w) as computed by subroutine vhaec.\nc\nc mdb the first dimension of the arrays br,bi,cr,ci as it\nc appears in the program that calls sfvpec. mdb must be at\nc least min0(nlat,nlon/2) if nlon is even or at least\nc min0(nlat,(nlon+1)/2) if nlon is odd.\nc\nc ndb the second dimension of the arrays br,bi,cr,ci as it\nc appears in the program that calls sfvpec. ndb must be at\nc least nlat.\nc\nc wshsec an array which must be initialized by subroutine shseci.\nc once initialized, wshsec can be used repeatedly by sfvpec\nc as long as nlon and nlat remain unchanged. wshsec must\nc not bel altered between calls of sfvpec.\nc\nc\nc lshsec the dimension of the array wshsec as it appears in the\nc program that calls sfvpec. define\nc\nc l1 = min0(nlat,(nlon+2)/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc and\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc then lshsec must be at least\nc\nc 2*nlat*l2+3*((l1-2)*(nlat+nlat-l1-1))/2+nlon+15\nc\nc\nc work a work array that does not have to be saved.\nc\nc lwork the dimension of the array work as it appears in the\nc program that calls sfvpec. define\nc\nc l1 = min0(nlat,(nlon+2)/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc and\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc if isym is zero then lwork must be at least\nc\nc nlat*((nt*nlon+max0(3*l2,nlon)) + 2*l1*nt+1)\nc\nc if isym is not zero then lwork must be at least\nc\nc l2*(nt*nlon+max0(3*nlat,nlon)) + nlat*(2*l1*nt+1)\nc\nc **************************************************************\nc\nc output parameters\nc\nc sf,vp two or three dimensional arrays (see input parameter nt)\nc that contains the stream function and velocity potential\nc of the vector field (v,w) whose coefficients br,bi,cr,ci\nc where precomputed by subroutine vhaec. sf(i,j),vp(i,j)\nc are given at the colatitude point\nc\nc theta(i) = (i-1)*pi/(nlat-1)\nc\nc and longitude point\nc\nc lambda(j) = (j-1)*2*pi/nlon\nc\nc the index ranges are defined above at the input parameter isym.\nc\nc\nc ierror = 0 no errors\nc = 1 error in the specification of nlat\nc = 2 error in the specification of nlon\nc = 3 error in the specification of isym\nc = 4 error in the specification of nt\nc = 5 error in the specification of idv\nc = 6 error in the specification of jdv\nc = 7 error in the specification of mdb\nc = 8 error in the specification of ndb\nc = 9 error in the specification of lshsec\nc = 10 error in the specification of lwork\nc **********************************************************************\nc \n subroutine sfvpec(nlat,nlon,isym,nt,sf,vp,idv,jdv,br,bi,cr,ci,\n + mdb,ndb,wshsec,lshsec,work,lwork,ierror)\n implicit none\n integer nlat,nlon,isym,nt,idv,jdv,mdb,ndb,lshsec,lwork,ierror\n real sf(idv,jdv,nt),vp(idv,jdv,nt)\n real br(mdb,ndb,nt),bi(mdb,ndb,nt)\n real cr(mdb,ndb,nt),ci(mdb,ndb,nt)\n real wshsec(lshsec),work(lwork)\n integer imid,mmax,lzz1,labc,ls,nln,mab,mn,ia,ib,is,lwk,iwk,lwmin\nc\nc check input parameters\nc\n ierror = 1\n if(nlat .lt. 3) return\n ierror = 2\n if (nlon .lt. 4) return\n ierror = 3\n if (isym.lt.0 .or. isym.gt.2) return\n ierror = 4\n if (nt .lt. 0) return\n ierror = 5\n imid = (nlat+1)/2\n if((isym.eq.0 .and. idv.lt.nlat) .or.\n + (isym.gt.0 .and. idv.lt.imid)) return\n ierror = 6\n if(jdv .lt. nlon) return\n ierror = 7\n mmax = min0(nlat,(nlon+2)/2)\n if(mdb .lt. min0(nlat,(nlon+1)/2)) return\n ierror = 8\n if (ndb .lt. nlat) return\n ierror = 9\nc\nc verify saved work space (same as shsec)\nc\n imid = (nlat+1)/2\n lzz1 = 2*nlat*imid\n labc = 3*(max0(mmax-2,0)*(nlat+nlat-mmax-1))/2\n lwmin = lzz1+labc+nlon+15\n\n if(lshsec .lt. lwmin) return\nc\nc verify unsaved work space (add to what shec requires)\nc\n ierror = 10\n ls = nlat\n if (isym.gt. 0) ls = imid\n nln = nt*ls*nlon\nc\nc set first dimension for a,b (as requried by shsec)\nc\n mab = min0(nlat,nlon/2+1)\n mn = mab*nlat*nt\n if(lwork .lt. nln+max0(ls*nlon,3*nlat*imid)+2*mn+nlat) return\n ierror = 0\nc\nc set work space pointers\nc\n ia = 1\n ib = ia+mn\n is = ib+mn\n iwk = is+nlat\n lwk = lwork-2*mn-nlat\n call sfvpec1(nlat,nlon,isym,nt,sf,vp,idv,jdv,br,bi,cr,ci,mdb,ndb,\n +work(ia),work(ib),mab,work(is),wshsec,lshsec,work(iwk),lwk,\n +ierror)\n return\n end\n\n subroutine sfvpec1(nlat,nlon,isym,nt,sf,vp,idv,jdv,br,bi,cr,ci,\n +mdb,ndb,a,b,mab,fnn,wshsec,lshsec,wk,lwk,ierror)\n implicit none\n integer nlat,nlon,isym,nt,idv,jdv,mdb,ndb,mab,lshsec,lwk,ierror\n real sf(idv,jdv,nt),vp(idv,jdv,nt)\n real br(mdb,ndb,nt),bi(mdb,ndb,nt),cr(mdb,ndb,nt),ci(mdb,ndb,nt)\n real a(mab,nlat,nt),b(mab,nlat,nt)\n real wshsec(lshsec),wk(lwk),fnn(nlat)\n integer n,m,mmax,k\nc\nc set coefficient multiplyers\nc\n do n=2,nlat\n\tfnn(n) = 1.0/sqrt(float(n*(n-1)))\n end do\n mmax = min0(nlat,(nlon+1)/2)\nc\nc compute sf scalar coefficients from cr,ci\nc\n do k=1,nt\n\tdo n=1,nlat\n\t do m=1,mab\n\t a(m,n,k) = 0.0\n\t b(m,n,k) = 0.0\n\t end do\n\tend do\nc\nc compute m=0 coefficients\nc\n\tdo n=2,nlat\n\t a(1,n,k) =-fnn(n)*cr(1,n,k)\n\t b(1,n,k) =-fnn(n)*ci(1,n,k)\n\tend do\nc\nc compute m>0 coefficients using vector spherepack value for mmax\nc\n\tdo m=2,mmax\n\t do n=m,nlat\n\t a(m,n,k) =-fnn(n)*cr(m,n,k)\n\t b(m,n,k) =-fnn(n)*ci(m,n,k)\n\t end do\n\tend do\n end do\nc\nc synthesize a,b into st\nc\n call shsec(nlat,nlon,isym,nt,sf,idv,jdv,a,b,\n + mab,nlat,wshsec,lshsec,wk,lwk,ierror)\nc\nc set coefficients for vp from br,bi\nc\n do k=1,nt\n\tdo n=1,nlat\n\t do m=1,mab\n\t a(m,n,k) = 0.0\n\t b(m,n,k) = 0.0\n\t end do\n\tend do\nc\nc compute m=0 coefficients\nc\n\tdo n=2,nlat\n\t a(1,n,k) = fnn(n)*br(1,n,k)\n\t b(1,n,k) = fnn(n)*bi(1,n,k)\n\tend do\nc\nc compute m>0 coefficients using vector spherepack value for mmax\nc\n\tmmax = min0(nlat,(nlon+1)/2)\n\tdo m=2,mmax\n\t do n=m,nlat\n\t a(m,n,k) = fnn(n)*br(m,n,k)\n\t b(m,n,k) = fnn(n)*bi(m,n,k)\n\t end do\n\tend do\n end do\nc\nc synthesize a,b into vp\nc\n call shsec(nlat,nlon,isym,nt,vp,idv,jdv,a,b,\n + mab,nlat,wshsec,lshsec,wk,lwk,ierror)\n return\n end\n", "meta": {"hexsha": "a3a0aff1549c61751504f747ce12098d7d2f0350", "size": 12840, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/sfvpec.f", "max_stars_repo_name": "jprules321/colas", "max_stars_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/sfvpec.f", "max_issues_repo_name": "jprules321/colas", "max_issues_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/sfvpec.f", "max_forks_repo_name": "jprules321/colas", "max_forks_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.0819672131, "max_line_length": 79, "alphanum_fraction": 0.5621495327, "num_tokens": 4097, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480667, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.6977958992483321}} {"text": "\tFUNCTION PS_VTOT ( t850, t500 )\nC************************************************************************\nC* PS_VTOT\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes the vertical totals index:\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* VTOT = T850 - T500\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PS_VTOT ( T850, T500 )\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*\tT850\t\tREAL\t\t850 mb temperature in Celsius\t*\nC*\tT500\t\tREAL\t\t500 mb temperature in Celsius\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPS_VTOT\t\tREAL\t\tVertical totals index\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* M. Goodman/RDS\t11/84\tOriginal source\t\t\t\t*\nC* M. desJardins/GSFC\t 3/88\tDocumentation\t\t\t\t*\nC************************************************************************\n INCLUDE 'GEMPRM.PRM'\n INCLUDE 'ERMISS.FNC'\nC-----------------------------------------------------------------------------\n\tIF ( ERMISS (t850) .or. ERMISS (t500) ) THEN\n\t PS_VTOT= RMISSD\n\t ELSE\nC\nC*\t Compute vertical totals index by subtracting temperature at\nC*\t 500 mb from temperature at 850 mb.\nC\n\t PS_VTOT= t850 - t500\n\tEND IF\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "d8e2b59a510908dba2b0cd3f94bb554519b6d1b3", "size": 1106, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/ps/psvtot.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/ps/psvtot.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/ps/psvtot.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.8918918919, "max_line_length": 78, "alphanum_fraction": 0.4556962025, "num_tokens": 321, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.7690802370707283, "lm_q1q2_score": 0.6977958983011977}} {"text": "!> Data\nmodule conenagle_data\n use coneangle_env, only: wp\n implicit none(type, external)\n\n private\n public :: RAD_TO_DEG, PI\n\n !> Pi\n real(wp), parameter :: PI = acos(-1.0_wp)\n !> Radians to degrees conversion factor\n real(wp), parameter :: RAD_TO_DEG = 180._wp/PI\nend module conenagle_data\n", "meta": {"hexsha": "be44b1ef7e8378cc9136e41ffc56df5dbd796674", "size": 300, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/data.f90", "max_stars_repo_name": "kjelljorner/libconeangle", "max_stars_repo_head_hexsha": "52ef8f38d41a8d6feea0869f457a85598cf6e59b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2022-03-21T07:02:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T22:58:32.000Z", "max_issues_repo_path": "src/data.f90", "max_issues_repo_name": "kjelljorner/libconeangle", "max_issues_repo_head_hexsha": "52ef8f38d41a8d6feea0869f457a85598cf6e59b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-03-26T10:24:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-26T14:12:02.000Z", "max_forks_repo_path": "src/data.f90", "max_forks_repo_name": "kjelljorner/libconeangle", "max_forks_repo_head_hexsha": "52ef8f38d41a8d6feea0869f457a85598cf6e59b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.4285714286, "max_line_length": 48, "alphanum_fraction": 0.7033333333, "num_tokens": 95, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9073122313857377, "lm_q2_score": 0.7690802264851919, "lm_q1q2_score": 0.697795896406928}} {"text": "program ulam\n implicit none\n\n integer, parameter :: nsize = 49\n integer :: i, j, n, x, y\n integer :: a(nsize*nsize) = (/ (i, i = 1, nsize*nsize) /)\n character(1) :: spiral(nsize, nsize) = \" \"\n character(2) :: sstr\n character(10) :: fmt\n\n n = 1\n x = nsize / 2 + 1\n y = x\n if(isprime(a(n))) spiral(x, y) = \"O\"\n n = n + 1\n\n do i = 1, nsize-1, 2\n do j = 1, i\n x = x + 1\n if(isprime(a(n))) spiral(x, y) = \"O\"\n n = n + 1\n end do\n\n do j = 1, i\n y = y - 1\n if(isprime(a(n))) spiral(x, y) = \"O\"\n n = n + 1\n end do\n\n do j = 1, i+1\n x = x - 1\n if(isprime(a(n))) spiral(x, y) = \"O\"\n n = n + 1\n end do\n\n do j = 1, i+1\n y = y + 1\n if(isprime(a(n))) spiral(x, y) = \"O\"\n n = n + 1\n end do\n end do\n\n do j = 1, nsize-1\n x = x + 1\n if(isprime(a(n))) spiral(x, y) = \"O\"\n n = n + 1\n end do\n\n write(sstr, \"(i0)\") nsize\n fmt = \"(\" // sstr // \"(a,1x))\"\n do i = 1, nsize\n write(*, fmt) spiral(:, i)\n end do\n\ncontains\n\nfunction isprime(number)\n logical :: isprime\n integer, intent(in) :: number\n integer :: i\n\n if(number == 2) then\n isprime = .true.\n else if(number < 2 .or. mod(number,2) == 0) then\n isprime = .false.\n else\n isprime = .true.\n do i = 3, int(sqrt(real(number))), 2\n if(mod(number,i) == 0) then\n isprime = .false.\n exit\n end if\n end do\n end if\nend function\nend program\n", "meta": {"hexsha": "412f636228b84f683f9fd46b16342f0c46ae3741", "size": 1422, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Ulam-spiral--for-primes-/Fortran/ulam-spiral--for-primes--1.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Ulam-spiral--for-primes-/Fortran/ulam-spiral--for-primes--1.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Ulam-spiral--for-primes-/Fortran/ulam-spiral--for-primes--1.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 18.4675324675, "max_line_length": 59, "alphanum_fraction": 0.4781997187, "num_tokens": 577, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122113355091, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.697795895393273}} {"text": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\ncc cc\ncc mnsurf : surfit test program cc\ncc cc\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\n real x(80),y(80),z(80),w(80),tx(15),ty(15),c(200),wrk1(12000),\n * wrk2(6000),xx(11),yy(11),zz(121)\n integer iwrk(300)\n integer i,ier,iopt,is,j,kwrk,kx,ky,lwrk1,lwrk2,m,mx,my,nc,\n * nmax,nx,nxest,ny,nyest\n real ai,delta,eps,fp,s,ww,xb,xe,yb,ye\nc we fetch the number of data points\n read(5,900) m\n write(6,905) m\nc we fetch the co-ordinate and function values of each data point.\n write(6,910)\n do 10 i=1,m\n read(5,915) x(i),y(i),z(i)\n if((i/2)*2.ne.i) go to 10\n j = i-1\n write(6,920) j,x(j),y(j),z(j),i,x(i),y(i),z(i)\n 10 continue\nc we fetch an estimate of the standard deviation of the data values.\n read(5,925) delta\n write(6,930) delta\nc the weights are set equal to delta**(-1)\n ww = 1./delta\n do 20 i=1,m\n w(i) = ww\n 20 continue\nc we set up the boundaries of the approximation domain.\n xb = -2.\n xe = 2.\n yb = -2.\n ye = 2.\nc we generate a rectangular grid for evaluating the splines.\n mx = 11\n my = 11\n do 30 i=1,11\n ai = i-6\n xx(i) = ai*0.4\n yy(i) = xx(i)\n 30 continue\nc we set up the dimension information\n nxest = 15\n nyest = 15\n nmax = 15\n kwrk = 300\n lwrk1 = 12000\n lwrk2 = 6000\nc we choose a value for eps\n eps=0.1e-05\nc main loop for the different spline approximations.\n do 300 is=1,6\n go to (110,120,130,140,150,160),is\nc we start computing the least-squares bicubic polynomial (large s)\n 110 iopt = 0\n kx = 3\n ky = 3\n s = 900000.\n go to 200\nc iopt=1 from the second call on.\n 120 iopt = 1\n s = 200.\n go to 200\nc a value for s within its confidence interval\n 130 s = m\n go to 200\nc overfitting (s too small)\n 140 s = 20.\n go to 200\nc we change the degrees of the spline\n 150 iopt = 0\n kx = 5\n ky = 5\n s = m\n go to 200\nc finally, we also calculate a least-squares spline approximation\nc with specified knots.\n 160 iopt = -1\n kx = 3\n ky = 3\n nx = 11\n ny = 11\n j = kx+2\n do 170 i=1,3\n ai = i-2\n tx(j) = ai\n ty(j) = ai\n j = j+1\n 170 continue\nc determination of the spline approximation.\n 200 call surfit(iopt,m,x,y,z,w,xb,xe,yb,ye,kx,ky,s,nxest,nyest,\n * nmax,eps,nx,tx,ny,ty,c,fp,wrk1,lwrk1,wrk2,lwrk2,iwrk,kwrk,ier)\nc printing of the fitting results.\n if(iopt.ge.0) go to 210\n write(6,935) kx,ky\n go to 220\n 210 write(6,940) kx,ky\n write(6,945) s\n 220 write(6,950) fp,ier\n write(6,955) nx\n write(6,960)\n write(6,965) (tx(i),i=1,nx)\n write(6,970) ny\n write(6,960)\n write(6,965) (ty(i),i=1,ny)\n nc = (nx-kx-1)*(ny-ky-1)\n write(6,975)\n write(6,980) (c(i),i=1,nc)\nc evaluation of the spline approximation.\n call bispev(tx,nx,ty,ny,c,kx,ky,xx,mx,yy,my,zz,\n * wrk2,lwrk2,iwrk,kwrk,ier)\n write(6,1000)\n write(6,985) (xx(i),i=1,mx)\n write(6,990)\n do 230 j=1,my\n write(6,995) yy(j),(zz(i),i=j,121,11)\n 230 continue\n 300 continue\n stop\nc format statements.\n 900 format(i3)\n 905 format(1h1,i3,12h data points)\n 910 format(1h0,2(2x,1hi,5x,4hx(i),6x,4hy(i),6x,4hz(i),6x))\n 915 format(3f10.4)\n 920 format(1x,2(i3,3f10.4,5x))\n 925 format(e20.6)\n 930 format(1x,40hestimate of standard deviation of z(i) =,e15.6)\n 935 format(32h0least-squares spline of degrees,2i3)\n 940 format(28h0smoothing spline of degrees,2i3)\n 945 format(20h smoothing factor s=,f9.0)\n 950 format(1x,23hsum squared residuals =,e15.6,5x,11herror flag=,i3)\n 955 format(1x,42htotal number of knots in the x-direction =,i3)\n 960 format(1x,22hposition of the knots )\n 965 format(5x,10f7.3)\n 970 format(1x,42htotal number of knots in the y-direction =,i3)\n 975 format(23h0b-spline coefficients )\n 980 format(5x,8f9.4)\n 985 format(1h0,1hx,2x,11f7.1)\n 990 format(3x,1hy)\n 995 format(1x,f4.1,11f7.3)\n 1000 format(1h0,33hspline evaluation on a given grid)\n end\n\n", "meta": {"hexsha": "ebe54b5ae56b620eddbd502c4777c24e33247f64", "size": 4488, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ApproxSpline/Resources/F77-Sources/ex/mnsurf.f", "max_stars_repo_name": "modelica-3rdparty/ApproxSpline", "max_stars_repo_head_hexsha": "28420f5c1a88c9cd069defbd8c05e4a78a090675", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-07-13T17:24:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-18T16:16:02.000Z", "max_issues_repo_path": "ApproxSpline/Resources/F77-Sources/ex/mnsurf.f", "max_issues_repo_name": "tbeu/ApproxSpline", "max_issues_repo_head_hexsha": "28420f5c1a88c9cd069defbd8c05e4a78a090675", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-03-28T09:08:23.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T07:35:48.000Z", "max_forks_repo_path": "ApproxSpline/Resources/F77-Sources/ex/mnsurf.f", "max_forks_repo_name": "modelica-3rdparty/ApproxSpline", "max_forks_repo_head_hexsha": "28420f5c1a88c9cd069defbd8c05e4a78a090675", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-10-21T07:46:49.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T20:02:06.000Z", "avg_line_length": 30.7397260274, "max_line_length": 72, "alphanum_fraction": 0.5728609626, "num_tokens": 1690, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480667, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6977958944461389}} {"text": "SUBROUTINE eta_linear_3D_bottom(H,k,angle,x,y,int_kx,omega,time,eta,etax,etay,etaxx,etayy,etat)\n!\n! By Allan P. Engsig-Karup.\nUSE Precision\nUSE Constants\nIMPLICIT NONE\nREAL(KIND=long), INTENT(IN) :: H,k,angle,x,y,omega,time,int_kx\nREAL(KIND=long), INTENT(OUT) :: eta,etax,etay\nREAL(KIND=long), INTENT(OUT) :: etaxx,etayy,etat\n! REAL(KIND=long), OPTIONAL :: y,etay,etayy !Boundary fitted ?\n! Local variables\nREAL(KIND=long) :: kx, ky, half_H, k_omegat, sink_omegat\n!\nkx=k*cos(angle)\nky=k*sin(angle)\n!\nk_omegat=int_kx+ky*y-omega*time\n!k_omegat=kx*x+ky*y-omega*time\nhalf_H = H*half\nsink_omegat = sin(k_omegat)\n!\neta = half_H*cos(k_omegat)\netax = -half_H*kx*sink_omegat\netay = -half_H*ky*sink_omegat\n\netat = omega*half_H*sink_omegat\netayy = -eta*(ky)**2\netaxx = -eta*(kx)**2\n\n\nEND SUBROUTINE eta_linear_3D_bottom\n", "meta": {"hexsha": "f0de58af8db29f7012f39fdc3ee13c7b725b0135", "size": 818, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/functions/eta_linear_3D_bottom.f90", "max_stars_repo_name": "apengsigkarup/OceanWave3D", "max_stars_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 46, "max_stars_repo_stars_event_min_datetime": "2016-01-08T12:36:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T06:56:45.000Z", "max_issues_repo_path": "src/functions/eta_linear_3D_bottom.f90", "max_issues_repo_name": "apengsigkarup/OceanWave3D", "max_issues_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-10-10T19:45:08.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-07T07:37:11.000Z", "max_forks_repo_path": "src/functions/eta_linear_3D_bottom.f90", "max_forks_repo_name": "apengsigkarup/OceanWave3D", "max_forks_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2015-10-01T12:17:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-02T16:23:37.000Z", "avg_line_length": 25.5625, "max_line_length": 95, "alphanum_fraction": 0.7273838631, "num_tokens": 341, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9585377272885904, "lm_q2_score": 0.7279754548076478, "lm_q1q2_score": 0.6977919379732007}} {"text": " SUBROUTINE rlft3(data,speq,nn1,nn2,nn3,isign)\r\n INTEGER isign,nn1,nn2,nn3\r\n COMPLEX data(nn1/2,nn2,nn3),speq(nn2,nn3)\r\nCU USES fourn\r\n INTEGER i1,i2,i3,j1,j2,j3,nn(3)\r\n DOUBLE PRECISION theta,wi,wpi,wpr,wr,wtemp\r\n COMPLEX c1,c2,h1,h2,w\r\n c1=cmplx(0.5,0.0)\r\n c2=cmplx(0.0,-0.5*isign)\r\n theta=6.28318530717959d0/dble(isign*nn1)\r\n wpr=-2.0d0*sin(0.5d0*theta)**2\r\n wpi=sin(theta)\r\n nn(1)=nn1/2\r\n nn(2)=nn2\r\n nn(3)=nn3\r\n if(isign.eq.1)then\r\n call fourn(data,nn,3,isign)\r\n do 12 i3=1,nn3\r\n do 11 i2=1,nn2\r\n speq(i2,i3)=data(1,i2,i3)\r\n11 continue\r\n12 continue\r\n endif\r\n do 15 i3=1,nn3\r\n j3=1\r\n if (i3.ne.1) j3=nn3-i3+2\r\n wr=1.0d0\r\n wi=0.0d0\r\n do 14 i1=1,nn1/4+1\r\n j1=nn1/2-i1+2\r\n do 13 i2=1,nn2\r\n j2=1\r\n if (i2.ne.1) j2=nn2-i2+2\r\n if(i1.eq.1)then\r\n h1=c1*(data(1,i2,i3)+conjg(speq(j2,j3)))\r\n h2=c2*(data(1,i2,i3)-conjg(speq(j2,j3)))\r\n data(1,i2,i3)=h1+h2\r\n speq(j2,j3)=conjg(h1-h2)\r\n else\r\n h1=c1*(data(i1,i2,i3)+conjg(data(j1,j2,j3)))\r\n h2=c2*(data(i1,i2,i3)-conjg(data(j1,j2,j3)))\r\n data(i1,i2,i3)=h1+w*h2\r\n data(j1,j2,j3)=conjg(h1-w*h2)\r\n endif\r\n13 continue\r\n wtemp=wr\r\n wr=wr*wpr-wi*wpi+wr\r\n wi=wi*wpr+wtemp*wpi+wi\r\n w=cmplx(sngl(wr),sngl(wi))\r\n14 continue\r\n15 continue\r\n if(isign.eq.-1)then\r\n call fourn(data,nn,3,isign)\r\n endif\r\n return\r\n END\r\n", "meta": {"hexsha": "5710cd2e7b5d003a3a7280f413d2362f97843cad", "size": 1668, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/rlft3.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/rlft3.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/rlft3.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.2631578947, "max_line_length": 59, "alphanum_fraction": 0.479616307, "num_tokens": 675, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966717067253, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6977914687317645}} {"text": " SUBROUTINE MB03QX( N, T, LDT, WR, WI, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute the eigenvalues of an upper quasi-triangular matrix.\nC\nC ARGUMENTS\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The order of the matrix T. N >= 0.\nC\nC T (input) DOUBLE PRECISION array, dimension(LDT,N)\nC The upper quasi-triangular matrix T.\nC\nC LDT INTEGER\nC The leading dimension of the array T. LDT >= max(1,N).\nC\nC WR, WI (output) DOUBLE PRECISION arrays, dimension (N)\nC The real and imaginary parts, respectively, of the\nC eigenvalues of T. The eigenvalues are stored in the same\nC order as on the diagonal of T. If T(i:i+1,i:i+1) is a\nC 2-by-2 diagonal block with complex conjugated eigenvalues\nC then WI(i) > 0 and WI(i+1) = -WI(i).\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value.\nC\nC CONTRIBUTOR\nC\nC A. Varga, German Aerospace Center, DLR Oberpfaffenhofen,\nC March 1998. Based on the RASP routine SEIG.\nC\nC ******************************************************************\nC .. Parameters ..\n DOUBLE PRECISION ZERO\n PARAMETER ( ZERO = 0.0D0 )\nC .. Scalar Arguments ..\n INTEGER INFO, LDT, N\nC .. Array Arguments ..\n DOUBLE PRECISION T(LDT, *), WI(*), WR(*)\nC .. Local Scalars ..\n INTEGER I, I1, INEXT\n DOUBLE PRECISION A11, A12, A21, A22, CS, SN\nC .. External Subroutines ..\n EXTERNAL DLANV2, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC MAX\nC .. Executable Statements ..\nC\n INFO = 0\nC\nC Test the input scalar arguments.\nC\n IF( N.LT.0 ) THEN\n INFO = -1\n ELSE IF( LDT.LT.MAX( 1, N ) ) THEN\n INFO = -3\n END IF\nC\n IF( INFO.NE.0 ) THEN\nC\nC Error return.\nC\n CALL XERBLA( 'MB03QX', -INFO )\n RETURN\n END IF\nC\n INEXT = 1\n DO 10 I = 1, N\n IF( I.LT.INEXT )\n $ GO TO 10\n IF( I.NE.N ) THEN\n IF( T(I+1,I).NE.ZERO ) THEN\nC\nC A pair of eigenvalues.\nC\n INEXT = I + 2\n I1 = I + 1\n A11 = T(I,I)\n A12 = T(I,I1)\n A21 = T(I1,I)\n A22 = T(I1,I1)\n CALL DLANV2( A11, A12, A21, A22, WR(I), WI(I), WR(I1),\n $ WI(I1), CS, SN )\n GO TO 10\n END IF\n END IF\nC\nC Simple eigenvalue.\nC\n INEXT = I + 1\n WR(I) = T(I,I)\n WI(I) = ZERO\n 10 CONTINUE\nC\n RETURN\nC *** Last line of MB03QX ***\n END\n", "meta": {"hexsha": "df9a36199a1261f86dd7b5cdb4df1883c66ac7a1", "size": 2853, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB03QX.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB03QX.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB03QX.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 26.1743119266, "max_line_length": 72, "alphanum_fraction": 0.4942166141, "num_tokens": 884, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8976953030553434, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6977784298109483}} {"text": "*deck hermit\n subroutine hermit(nn,x,a,eps)\nc calculates the zeros x(i) of the nn-th order\nc hermite polynomial. the largest zero will be\nc stored in x(1). also calculates the corresponding\nc coefficients a(i) of the nn-th order gauss-hermite\nc quadrature formula of degree 2*nn-1. the factor of\nc sqrt(pi) has been removed from the a(i).\nc a. h. stroud & d. secrest, gaussian quadrature formulas,\nc prentice-hall, 1966\nc\n implicit real*8 (a-h,o-z)\n parameter (sixth = 1.0d0/6.0d0)\n dimension x(*), a(*)\nc\n fn = (nn)\n n1 = nn - 1\n n2 = (nn+1)/2\n cc = 1.0d0\n s = 0.0d0\n do 15 i=1,n1\n s = s + 0.5d0\n cc = s*cc\n 15 continue\n s = (2.0d0*fn+1.0d0)**sixth\n do 30 i=1,n2\n if( i.eq.1 ) then\nc # largest zero\n xt = s**3 - 1.85575d0/s\n elseif( i.eq.2 ) then\nc # second zero\n xt = xt - 1.14d0*fn**0.426d0/xt\n elseif( i.eq.3 ) then\nc # third zero\n xt = 1.86d0*xt - 0.86d0*x(1)\n elseif( i.eq.4 ) then\nc # fourth zero\n xt = 1.91d0*xt - 0.91d0*x(2)\n else\nc # all other zeros\n xt = 2.0d0*xt - x(i-2)\n endif\nc\n call hroot(xt,nn,dpn,pn1,eps)\n x(i) = xt\n a(i) = cc/dpn/pn1\nc write (6,'(2i4,2d25.17)') nn, i, xt, a(i)\n ni = nn-i+1\n x(ni) = -xt\n a(ni) = a(i)\n 30 continue\n return\n end\n", "meta": {"hexsha": "40731ee877f150d95d939ac1b47aa9664a258a37", "size": 1531, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/argosecp/argos1e/hermit.f", "max_stars_repo_name": "MOLFDIR/MOLFDIR", "max_stars_repo_head_hexsha": "e71c7ecf77ee018bbdeaa004dda04369ce02be89", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2016-09-18T11:34:00.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-16T08:57:01.000Z", "max_issues_repo_path": "source/argosecp/argos1e/hermit.f", "max_issues_repo_name": "yingxingcheng/MOLFDIR", "max_issues_repo_head_hexsha": "0802a5b93150e7db22a2bcfe6941dad62a55f4d0", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2016-10-26T12:26:36.000Z", "max_issues_repo_issues_event_max_datetime": "2017-06-20T05:53:35.000Z", "max_forks_repo_path": "source/argosecp/argos1e/hermit.f", "max_forks_repo_name": "yingxingcheng/MOLFDIR", "max_forks_repo_head_hexsha": "0802a5b93150e7db22a2bcfe6941dad62a55f4d0", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2016-09-18T12:34:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-16T08:57:13.000Z", "avg_line_length": 28.3518518519, "max_line_length": 69, "alphanum_fraction": 0.4826910516, "num_tokens": 573, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896758909757, "lm_q2_score": 0.7577943822145998, "lm_q1q2_score": 0.6977692435913836}} {"text": "C ****************************************************************** \nC * ROUTINES TO CONVERT TO MACH NUMBER FROM OTHER NON-DIMENSIONAL *\nC * COMPRESSIBLE FLOW QUANTITIES. USE F2PY TO COMPILE INTO A *\nC * PYTHON MODULE. *\nC * *\nC * ALL ACCEPT THE PARAMETERS, *\nC * M, DOUBLE 1-D ARRAY : OUTPUT MACH NUMBER; *\nC * X, DOUBLE 1-D ARRAY : INPUT QUANTITY; *\nC * G, DOUBLE SCALAR : INPUT SPECIFIC HEAT RATIO; *\nC * N, INTEGER SCALAR : LENGTH OF ARRAYS (HIDDEN BY F2PY). *\nC * *\nC * MCPTO_APO, A_ACRIT ALSO OPTIONALLY ACCEPT, *\nC * SUP, LOGICAL : LOOK FOR SUPERSONIC SOLUTIONS (DEFAULT FALSE). *\nC * *\nC * WHERE POSSIBLE, USE ANALYTIC INVERSION OF THE FUNCTION, *\nC * OTHERWISE USE NEWTON/HALLEY ITERATION TO FIND ROOT. *\nC * *\nC * JAMES BRIND, DECEMBER 2020 *\nC ******************************************************************\nC\n SUBROUTINE TO_T(M,X,G,N)\nC ANALYTIC INVERSION SQRT((TO_T-1)*2./(G-1))\nC ARGUMENTS\n INTEGER N\n REAL*8 G\n REAL*8 M(N)\n REAL*8 X(N)\nCf2py intent(in) x\nCf2py intent(in) g\nCf2py intent(out) m\nCf2py intent(hide) n\nC INTERMEDIATE VARS\n REAL*8 GM1_2\n GM1_2 = (G-1.0D0)*0.5D0\nC MAIN LOOP\n DO I=1,N\n M(I) = SQRT((X(I)-1.0D0)/GM1_2)\n ENDDO\n END\nC\n SUBROUTINE PO_P(M,X,G,N)\nC ANALYTIC INVERSION SQRT((PO_P^((G-1)/G)-1)*2./(G-1))\nC ARGUMENTS\n INTEGER N\n REAL*8 G\n REAL*8 M(N)\n REAL*8 X(N)\nCf2py intent(in) x\nCf2py intent(in) g\nCf2py intent(out) m\nCf2py intent(hide) n\nC INTERMEDIATE VARS\n REAL*8 GM1_2\n REAL*8 GM1_G\n GM1_2 = (G-1.0D0)*0.5D0\n GM1_G = (G-1.0D0)/G\nC MAIN LOOP\n DO I=1,N\n M(I) = SQRT((X(I)**GM1_G-1.0D0)/GM1_2)\n ENDDO\n END\nC\n SUBROUTINE RHOO_RHO(M,X,G,N)\nC ANALYTIC INVERSION SQRT((RHOO_RHO^(G-1)-1)*2./(G-1))\nC ARGUMENTS\n INTEGER N\n REAL*8 G\n REAL*8 M(N)\n REAL*8 X(N)\nCf2py intent(in) x\nCf2py intent(in) g\nCf2py intent(out) m\nCf2py intent(hide) n\nC INTERMEDIATE VARS\n REAL*8 GM1_2\n REAL*8 GM1\n GM1_2 = (G-1.0D0)*0.5D0\n GM1 = G-1.0D0\nC MAIN LOOP\n DO I=1,N\n M(I) = SQRT((X(I)**GM1-1.0D0)/GM1_2)\n ENDDO\n END\nC\n SUBROUTINE V_CPTO(M,X,G,N)\nC ANALYTIC INVERSION SQRT( V_cpTo^2/(G-1)/(1-0.5*V_cpTo^2))\nC ARGUMENTS\n INTEGER N\n REAL*8 G\n REAL*8 M(N)\n REAL*8 X(N)\nCf2py intent(in) x\nCf2py intent(in) g\nCf2py intent(out) m\nCf2py intent(hide) n\nC INTERMEDIATE VARS\n REAL*8 GM1\n REAL*8 XSQ\n GM1 = G-1.0D0\nC MAIN LOOP\n DO I=1,N\n XSQ = X(I)*X(I)\n M(I) = SQRT(XSQ/GM1/(1.0D0 - XSQ/2.0D0))\n ENDDO\n END\nC\n SUBROUTINE MCPTO_AP(M,X,G,N)\nC NUMERIC INVERSION USING NEWTON'S METHOD\nC ARGUMENTS\n INTEGER N\n REAL*8 G\n REAL*8 M(N)\n REAL*8 X(N)\nCf2py intent(in) x\nCf2py intent(in) g\nCf2py intent(out) m\nCf2py intent(hide) n\nC INTERMEDIATE VARS\n REAL*8 GM1\n REAL*8 GP1\n REAL*8 M_GP1_GM1_2\n REAL*8 G_SQ_GM1\n REAL*8 GM1_2\n REAL*8 GP1_2\nC ITERATION VARS\n INTEGER K\n REAL*8 MA\n REAL*8 TO_T\n REAL*8 MANEW\n REAL*8 ERR\n REAL*8 F\n REAL*8 DF\nC CONSTANTS\n REAL*8 NAN\n REAL*8 TOL\nC CALC GAMMA VARIANTS\n GM1 = G-1.0D0\n GP1 = G+1.0D0\n GM1_2 = GM1/2.0D0\n GP1_2 = GP1/2.0D0\n M_GP1_GM1_2 = GP1/GM1/(-2.0D0)\n G_SQ_GM1 = G/SQRT(GM1)\nC INITIALISE CONSTANTS\n NAN = 0.0D0\n NAN = 0.0D0/NAN\n TOL = 1.0D-6\nC MAIN LOOP\n DO I=1,N\nC INITIAL GUESS\n MA = 0.5D0\nC UP TO 100 ITERATIONS UNTIL TOLERANCE MET \n ERR = HUGE(ERR)\n K = 0\n DO WHILE (ERR.gt.TOL.and.K.lt.100)\n K = K + 1\nC USE NEWTON'S METHOD FOR NEW GUESS OF MA\n TO_T = (1.0D0 + GM1_2 * MA * MA )\n F = G_SQ_GM1 * MA * SQRT(TO_T)\n DF = G_SQ_GM1 * ( TO_T **2.0D0 - GM1_2 *MA*MA / SQRT(TO_T))\n MANEW = MA - (F-X(I)) / DF\nC GET ERROR AND UPDATE MA\n ERR = ABS(MANEW - MA)\n MA = MANEW\n ENDDO\nC RETURN NAN IF NOT CONVERGED\n IF (ERR.lt.TOL) THEN\n M(I) = MA\n ELSE\n M(I) = NAN\n ENDIF\n ENDDO\n END\nC\n SUBROUTINE MCPTO_APO(M,X,G,SUP,N)\nC NUMERIC INVERSION USING NEWTON'S METHOD\nC ARGUMENTS\n INTEGER N\n REAL*8 G\n REAL*8 M(N)\n REAL*8 X(N)\n LOGICAL SUP\nCf2py optional :: SUP = .FALSE.\nCf2py intent(in) sup\nCf2py intent(in) x\nCf2py intent(in) g\nCf2py intent(out) m\nCf2py intent(hide) n\nC INTERMEDIATE VARS\n REAL*8 GM1\n REAL*8 GP1\n REAL*8 M_GP1_GM1_2\n REAL*8 G_SQ_GM1\n REAL*8 GM1_2\n REAL*8 GP1_2\nC ITERATION VARS\n INTEGER K\n REAL*8 MA\n REAL*8 MANEW\n REAL*8 ERR\n REAL*8 F\n REAL*8 DF\n REAL*8 TO_T\nC CONSTANTS\n REAL*8 FCRIT\n REAL*8 NAN\n REAL*8 TOL\nC CALC GAMMA VARIANTS\n GM1 = G-1.0D0\n GP1 = G+1.0D0\n GM1_2 = GM1/2.0D0\n GP1_2 = GP1/2.0D0\n M_GP1_GM1_2 = GP1/GM1/(-2.0D0)\n G_SQ_GM1 = G/SQRT(GM1)\nC CALC CONSTANTS\n NAN = 0.0D0\n NAN = 0.0D0/NAN\n TOL = 1.0D-6\nC CHOKING VALUE\n FCRIT = G_SQ_GM1 * (1.0D0 + GM1_2)**M_GP1_GM1_2\nC MAIN LOOP\n DO I=1,N\nC RETURN NAN IF CHOKED \n IF (X(I).gt.FCRIT) THEN\n M(I) = NAN\n ELSE\n IF (SUP) THEN\n MA = 1.5D0\n ELSE\n MA = 0.5D0\n ENDIF\n K = 0\n ERR = HUGE(ERR)\n DO WHILE (ERR.gt.TOL.and.K.lt.100)\n\n K = K + 1\n TO_T = (1.0D0 + GM1_2 * MA*MA)\n F = G_SQ_GM1 * MA * TO_T**M_GP1_GM1_2\n DF = F *(1.0D0 - GP1_2*MA*MA/TO_T)/MA \n MANEW = MA - (F-X(I)) / DF\n ERR = ABS(MANEW - MA)\n MA = MANEW\n ENDDO\n IF (ERR.lt.TOL) THEN\n M(I) = MA\n ELSE\n M(I) = NAN\n ENDIF\n ENDIF\n ENDDO\n END\nC\n SUBROUTINE A_ACRIT(M,X,G,SUP,N)\nC NUMERIC INVERSION USING NEWTON'S METHOD\nC ARGUMENTS\n INTEGER N\n REAL*8 G\n REAL*8 M(N)\n REAL*8 X(N)\n LOGICAL SUP\nCf2py optional :: SUP = .FALSE.\nCf2py intent(in) sup\nCf2py intent(in) x\nCf2py intent(in) g\nCf2py intent(out) m\nCf2py intent(hide) n\nC INTERMEDIATE VARS\n REAL*8 GM1\n REAL*8 GP1\n REAL*8 GP1_GM1_2\n REAL*8 GM1_2\n REAL*8 GP1_2\nC ITERATION VARS\n INTEGER K\n REAL*8 MA\n REAL*8 MANEW\n REAL*8 ERR\n REAL*8 F\n REAL*8 DF\n REAL*8 TO_T\nC CONSTANTS\n REAL*8 NAN\n REAL*8 TOL\nC CALC GAMMA VARIANTS\n GM1 = G-1.0D0\n GP1 = G+1.0D0\n GM1_2 = GM1/2.0D0\n GP1_2 = GP1/2.0D0\n GP1_GM1_2 = GP1/GM1/(2.0D0)\nC SET CONSTANTS\n NAN = 0.0D0\n NAN = 0.0D0/NAN\n TOL = 1.0D-6\nC MAIN LOOP\n DO I=1,N\n IF (SUP) THEN\n MA = 1.5D0\n ELSE\n MA = 0.5D0\n ENDIF\n K = 0\n ERR = HUGE(ERR)\n DO WHILE (ERR.gt.TOL.and.K.lt.100)\n\n K = K + 1\n\n TO_T = 1.0D0 + GM1_2 * MA*MA \n F = ((TO_T/GP1_2)**GP1_GM1_2)/MA\n DF = F * MA * (-1.0D0/MA/MA + GP1_2 /TO_T)\n\n MANEW = MA - (F-X(I)) / DF\n ERR = ABS(MANEW - MA)\n MA = MANEW\n ENDDO\n IF (ERR.lt.TOL) THEN\n M(I) = MA\n ELSE\n M(I) = NAN\n ENDIF\n ENDDO\n END\n\n SUBROUTINE POSH_PO(M,X,G,N)\nC NUMERIC INVERSION USING NEWTON'S METHOD\nC ARGUMENTS\n INTEGER N\n REAL*8 G\n REAL*8 M(N)\n REAL*8 X(N)\nCf2py intent(in) x\nCf2py intent(in) g\nCf2py intent(out) m\nCf2py intent(hide) n\nC INTERMEDIATE VARS\n REAL*8 GM1\n REAL*8 GP1\n REAL*8 GM1_GP1\n REAL*8 GM1_2\n REAL*8 GP1_2\n REAL*8 G_GM1\n REAL*8 P_GM1\nC ITERATION VARS\n INTEGER K\n REAL*8 A\n REAL*8 B\n REAL*8 C\n REAL*8 MA\n REAL*8 MANEW\n REAL*8 ERR\n REAL*8 F\n REAL*8 DF\n REAL*8 TO_T\n REAL*8 MSQ\nC CONSTANTS\n REAL*8 NAN\n REAL*8 TOL\nC CALC GAMMA VARIANTS\n GM1 = G-1.0D0\n GP1 = G+1.0D0\n GM1_2 = GM1/2.0D0\n GP1_2 = GP1/2.0D0\n GM1_GP1 = GM1/GP1\n G_GM1 = G/GM1\n P_GM1 = 1.0D0/GM1\nC SET CONSTANTS\n NAN = 0.0D0\n NAN = 0.0D0/NAN\n TOL = 1.0D-6\nC MAIN LOOP\n DO I=1,N\n IF (X(I).gt.1.0D0) THEN\n M(I) = NAN\n ELSE\n MA = 1.5D0\n K = 0\n ERR = HUGE(ERR)\n DO WHILE (ERR.gt.TOL.and.K.lt.100)\n\n K = K + 1\n\n MSQ = MA*MA\n TO_T = (1.0D0 + GM1_2*MSQ)\n A = GP1_2*MSQ/TO_T\n B = 1.0D0/(G/GP1_2*MSQ - GM1_GP1)\n C = -G*MA*(MSQ-1.0D0)*(MSQ-1.0D0)/TO_T/TO_T\n F = A**G_GM1 * B**P_GM1\n DF = C *(A**P_GM1) *(B**G_GM1)\n MANEW = MA - (F-X(I)) / DF\n ERR = ABS(MANEW - MA)\n MA = MANEW\n ENDDO\n IF (ERR.lt.TOL) THEN\n M(I) = MA\n ELSE\n M(I) = NAN\n ENDIF\n ENDIF\n ENDDO\n END\n\n SUBROUTINE MASH(M,X,G,N)\nC NUMERIC INVERSION USING NEWTON'S METHOD\nC ARGUMENTS\n INTEGER N\n REAL*8 G\n REAL*8 M(N)\n REAL*8 X(N)\nCf2py intent(in) x\nCf2py intent(in) g\nCf2py intent(out) m\nCf2py intent(hide) n\nC INTERMEDIATE VARS\n REAL*8 GM1\n REAL*8 GP1\n REAL*8 GM1_2\n REAL*8 GP1_2\nC ITERATION VARS\n INTEGER K\n REAL*8 MA\n REAL*8 MANEW\n REAL*8 ERR\n REAL*8 F\n REAL*8 DF\n REAL*8 MSQ\n REAL*8 C\n REAL*8 SQRT_TO_T\nC CONSTANTS\n REAL*8 NAN\n REAL*8 TOL\nC CALC GAMMA VARIANTS\n GM1 = G-1.0D0\n GP1 = G+1.0D0\n GM1_2 = GM1/2.0D0\n GP1_2 = GP1/2.0D0\nC SET CONSTANTS\n NAN = 0.0D0\n NAN = 0.0D0/NAN\n TOL = 1.0D-6\nC MAIN LOOP\n DO I=1,N\nC RETURN NAN FOR PRE SHOCK MA LESS THAN UNITY\n IF (X(I).gt.1.0D0) THEN\n M(I) = NAN\n ELSE\n MA = 0.5D0\n K = 0\n ERR = HUGE(ERR)\n DO WHILE (ERR.gt.TOL.and.K.lt.100)\n\n K = K + 1\n\n MSQ = MA*MA\n SQRT_TO_T = SQRT(1.0D0 + GM1_2*MSQ)\n F = SQRT_TO_T/SQRT(G*MSQ - GM1_2)\n C = G * (2.0D0*MSQ - 1.0D0) + 1.0D0\n DF = -GP1**2.0D0 * MA / SQRT(2.0D0)/SQRT_TO_T / C / SQRT(C)\n\n MANEW = MA - (F-X(I)) / DF\n\n ERR = ABS(MANEW - MA)\n MA = MANEW\n\n\n ENDDO\n\n IF (ERR.lt.TOL) THEN\n M(I) = MA\n ELSE\n M(I) = NAN\n ENDIF\n ENDIF\n ENDDO\n END\n", "meta": {"hexsha": "fbb8584fae6914c7f84577670d32b498d3645a2e", "size": 11118, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "fortran/to_Ma.f", "max_stars_repo_name": "jb753/compflow", "max_stars_repo_head_hexsha": "7ede6cb860a2573a1ab5e7e40b1591c3e72c3783", "max_stars_repo_licenses": ["MIT"], "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/to_Ma.f", "max_issues_repo_name": "jb753/compflow", "max_issues_repo_head_hexsha": "7ede6cb860a2573a1ab5e7e40b1591c3e72c3783", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-03-04T12:10:26.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-14T22:57:56.000Z", "max_forks_repo_path": "fortran/to_Ma.f", "max_forks_repo_name": "jb753/compflow", "max_forks_repo_head_hexsha": "7ede6cb860a2573a1ab5e7e40b1591c3e72c3783", "max_forks_repo_licenses": ["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.5052854123, "max_line_length": 73, "alphanum_fraction": 0.4761647778, "num_tokens": 4272, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896824119663, "lm_q2_score": 0.7577943658046608, "lm_q1q2_score": 0.697769233422851}} {"text": "! Highly divisible triangular number\n!\n! The sequence of triangle numbers is generated by adding the natural numbers.\n! So the 7th trianlge number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first\n! ten terms would be:\n!\n! 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...\n!\n! Let us list the factors of the first seven triangle numbers:\n! 1: 1\n! 3: 1, 3\n! 6: 1, 2, 3, 6\n! 10: 1, 2, 5, 10\n! 15: 1, 3, 5, 15\n! 21: 1, 3, 7, 21\n! 28: 1, 2, 4, 7, 14, 28\n!\n! We can see that 28 is the first triangle number to have over five divisirs.\n! What is the value of the first triangle number to have over five hundred divisors?\nmodule Problem12\n\n implicit none\n private\n\n public :: solve\ncontains\n subroutine solve\n write (*, '(A)') 'Problem 12. Highly divisible triangular number.'\n\n write (*, '(A, I)') 'Triangle 1: ', triangle1()\n end subroutine\n\n pure function triangle1()\n integer*8 triangle1\n\n integer number\n integer base\n integer divisors\n\n ! initial values\n triangle1 = 1\n number = 1\n\n do while (.true.)\n divisors = 0\n do base = 1, sqrt(real(triangle1))\n if (mod(triangle1, base) .eq. 0) then\n divisors = divisors + 1\n end if\n end do\n\n ! the number of divisors is two times less in case of sqr\n if (divisors .ge. 250) then\n return\n end if\n\n number = number + 1\n triangle1 = triangle1 + number\n end do\n end function\nend module\n", "meta": {"hexsha": "bf311e89e4dd0050e80f4070b693fe4477988a86", "size": 1597, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Problem12.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": "Problem12.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": "Problem12.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": 25.7580645161, "max_line_length": 84, "alphanum_fraction": 0.5516593613, "num_tokens": 498, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436482, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6977692302236017}} {"text": "!******************************************************************************\n!*\n!* STATISTICAL PHYSICS\n!*\n!******************************************************************************\n\n !==========================================================================\n ! 1) AUTHOR: F. Galliano\n !\n ! 2) HISTORY: \n ! - Created 08/2007 \n ! - 01/2015: add Maxwell-Boltzmann distribution.\n ! \n ! 3) DESCRIPTION: Various functions of statistical physics.\n !==========================================================================\n\nMODULE statistical_physics\n\n USE utilities, ONLY: DP\n USE constants, ONLY:\n USE special_functions, ONLY:\n IMPLICIT NONE\n PRIVATE\n\n PUBLIC :: blackbody, maxwell_boltzmann\n\n INTERFACE blackbody\n MODULE PROCEDURE blackbody_s, blackbody_v\n END INTERFACE blackbody\n\n INTERFACE maxwell_boltzmann\n MODULE PROCEDURE maxwell_boltzmann_s, maxwell_boltzmann_v\n END INTERFACE maxwell_boltzmann\n\n ! Peak of the black body function\n REAL(DP), PARAMETER, PUBLIC :: wT_nu = 5.0996E-3_DP ! [m/K] wave*T for Bnu_max\n REAL(DP), PARAMETER, PUBLIC :: wT_w = 3.6698E-3_DP ! [m/K] wave*T for Bw_max\n\n\nCONTAINS\n\n\n !==========================================================================\n ! Bnu[N,M] = BLACKBODY(nu[N],Temperature[M])\n !\n ! Evaluates the planck function at wavelengths nu [Hz], in W/m2/sr/Hz.\n !==========================================================================\n\n PURE FUNCTION blackbody_v (nu,temp)\n\n USE utilities, ONLY: DP\n USE constants, ONLY: MKS\n USE special_functions, ONLY: expm1\n IMPLICIT NONE \n\n REAL(DP), INTENT(IN), DIMENSION(:) :: nu ! Frequency grid in Hz\n REAL(DP), INTENT(IN), DIMENSION(:) :: temp ! Temperature grid in K\n REAL(DP), DIMENSION(SIZE(nu),SIZE(temp)) :: blackbody_v ! Bnu in W/m2/sr/Hz\n\n REAL(DP) :: twicehovc2, hovk ! Intermediate factors\n REAL(DP), DIMENSION(SIZE(temp)) :: hbeta\n INTEGER :: i, Ntemp \n\n !-----------------------------------------------------------------------\n\n Ntemp = SIZE(temp(:))\n hovk = MKS%hplanck / MKS%kboltz\n twicehovc2 = 2*MKS%hplanck / MKS%clight**2\n hbeta(:) = hovk / temp(:)\n \n FORALL (i=1:Ntemp) &\n blackbody_v(:,i) = twicehovc2*nu**3 / EXPM1(hbeta(i)*nu)\n\n !-----------------------------------------------------------------------\n\n END FUNCTION blackbody_v\n\n !==========================================================================\n\n PURE FUNCTION blackbody_s (nu,temp)\n\n USE utilities, ONLY: DP\n IMPLICIT NONE \n\n REAL(DP), INTENT(IN), DIMENSION(:) :: nu ! Frequency grid in Hz\n REAL(DP), INTENT(IN) :: temp ! Temperature in K\n REAL(DP), DIMENSION(SIZE(nu)) :: blackbody_s ! Bnu in W/m2/sr/Hz\n\n !-----------------------------------------------------------------------\n\n blackbody_s(:) = RESHAPE(BLACKBODY_V(nu(:),[temp]),[SIZE(nu(:))])\n\n !-----------------------------------------------------------------------\n\n END FUNCTION blackbody_s\n\n\n !==========================================================================\n ! f(E)[N] = MAXWELL_BOLTZMANN(E[N],T)\n !\n ! Returns the Maxwell-Boltzmann distribution in energy [J-1].\n !==========================================================================\n\n PURE FUNCTION maxwell_boltzmann_v (E,T)\n\n USE utilities, ONLY: DP\n USE constants, ONLY: pi, MKS\n IMPLICIT NONE\n\n REAL(DP), DIMENSION(:), INTENT(IN) :: E\n REAL(DP), INTENT(IN) :: T\n REAL(DP), DIMENSION(SIZE(E)) :: maxwell_boltzmann_v\n\n REAL(DP) :: kT\n\n !-----------------------------------------------------------------------\n\n kT = MKS%kboltz * T ! [J]\n maxwell_boltzmann_v(:) = 2._DP / SQRT(pi) * SQRT(E(:)/kT**3) * EXP(-E(:)/kT)\n\n !-----------------------------------------------------------------------\n\n END FUNCTION maxwell_boltzmann_v\n\n !==========================================================================\n\n PURE FUNCTION maxwell_boltzmann_s (E,T)\n\n USE utilities, ONLY: DP\n IMPLICIT NONE\n\n REAL(DP), INTENT(IN) :: E\n REAL(DP), INTENT(IN) :: T\n REAL(DP) :: maxwell_boltzmann_s\n\n !-----------------------------------------------------------------------\n\n maxwell_boltzmann_s = MAXVAL(MAXWELL_BOLTZMANN_V([E],T))\n\n !-----------------------------------------------------------------------\n\n END FUNCTION maxwell_boltzmann_s\n\n\nEND MODULE statistical_physics\n", "meta": {"hexsha": "9d91328b83f16003cf1c92a5f72d70648fd57d22", "size": 4386, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "MILES/swing/Physics/statistical_physics.f90", "max_stars_repo_name": "kxxdhdn/MISSILE", "max_stars_repo_head_hexsha": "89dea38aa9247f20c444ccd0b832c674be275fbf", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MILES/swing/Physics/statistical_physics.f90", "max_issues_repo_name": "kxxdhdn/MISSILE", "max_issues_repo_head_hexsha": "89dea38aa9247f20c444ccd0b832c674be275fbf", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MILES/swing/Physics/statistical_physics.f90", "max_forks_repo_name": "kxxdhdn/MISSILE", "max_forks_repo_head_hexsha": "89dea38aa9247f20c444ccd0b832c674be275fbf", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.0410958904, "max_line_length": 80, "alphanum_fraction": 0.4434564523, "num_tokens": 1091, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436482, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6977692302236017}} {"text": " SUBROUTINE MA02FD( X1, X2, C, S, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute the coefficients c and s (c^2 + s^2 = 1) for a modified\nC hyperbolic plane rotation, such that,\nC\nC y1 := 1/c * x1 - s/c * x2 = sqrt(x1^2 - x2^2),\nC y2 := -s * y1 + c * x2 = 0,\nC\nC given two real numbers x1 and x2, satisfying either x1 = x2 = 0,\nC or abs(x2) < abs(x1).\nC\nC ARGUMENTS\nC\nC Input/Output Parameters\nC\nC X1 (input/output) DOUBLE PRECISION\nC On entry, the real number x1.\nC On exit, the real number y1.\nC\nC X2 (input) DOUBLE PRECISION\nC The real number x2.\nC The values x1 and x2 should satisfy either x1 = x2 = 0, or\nC abs(x2) < abs(x1).\nC\nC C (output) DOUBLE PRECISION\nC The cosines c of the modified hyperbolic plane rotation.\nC\nC S (output) DOUBLE PRECISION\nC The sines s of the modified hyperbolic plane rotation.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: succesful exit;\nC = 1: if abs(x2) >= abs(x1) and either x1 <> 0 or x2 <> 0.\nC\nC CONTRIBUTOR\nC\nC D. Kressner, Technical Univ. Chemnitz, Germany, June 2000.\nC\nC REVISIONS\nC\nC V. Sima, Katholieke Univ. Leuven, Belgium, June 2000.\nC\nC KEYWORDS\nC\nC Orthogonal transformation, plane rotation.\nC\nC *****************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ONE, ZERO\n PARAMETER ( ONE = 1.0D0, ZERO = 0.0D0 )\nC .. Scalar Arguments ..\n DOUBLE PRECISION X1, X2, C, S\n INTEGER INFO\nC .. Intrinsic Functions ..\n INTRINSIC ABS, SIGN, SQRT\nC .. Executable Statements ..\nC\n IF ( ( X1.NE.ZERO .OR. X2.NE.ZERO ) .AND.\n $ ABS( X2 ).GE.ABS( X1 ) ) THEN\n INFO = 1\n ELSE\n INFO = 0\n IF ( X1.EQ.ZERO ) THEN\n S = ZERO\n C = ONE\n ELSE\n S = X2 / X1\nC\nC No overflows could appear in the next statement; underflows\nC are possible if X2 is tiny and X1 is huge, but then\nC abs(C) = ONE - delta,\nC where delta is much less than machine precision.\nC\n C = SIGN( SQRT( ONE - S ) * SQRT( ONE + S ), X1 )\n X1 = C * X1\n END IF\n END IF\nC\n RETURN\nC *** Last line of MA02FD ***\n END\n", "meta": {"hexsha": "3193683e7b34530391856dee1d9bf14509c6bcec", "size": 2483, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MA02FD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MA02FD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MA02FD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 27.2857142857, "max_line_length": 72, "alphanum_fraction": 0.5247684253, "num_tokens": 795, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.920789673717312, "lm_q2_score": 0.757794360334681, "lm_q1q2_score": 0.6977692217973901}} {"text": "C ***********************************************************\nC\n DOUBLE PRECISION FUNCTION DONTR5(I,N,X,CONT,XSOL,HSOL) \nC ----------------------------------------------------------\nC THIS FUNCTION CAN BE USED FOR CONINUOUS OUTPUT. IT PROVIDES AN\nC APPROXIMATION TO THE I-TH COMPONENT OF THE SOLUTION DERIVATIVE AT .\nC X. IT GIVES THE VALUE OF THE COLLOCATION POLYNOMIAL, DEFINED FOR\nC THE LAST SUCCESSFULLY COMPUTED STEP (BY DELAY5).\nC ----------------------------------------------------------\n IMPLICIT DOUBLE PRECISION (A-H,O-Z)\n INTEGER, PARAMETER :: DP=kind(1D0)\n REAL(kind=DP), dimension(1), intent(in) :: CONT\nC --- REQUIRED CONSTANTS\n COMMON /CONSTN/C1,C2,C1M1,C2M1,C1MC2\n\n N2=2*N\n N3=3*N\n\n S=(X-XSOL)/HSOL\n\n\tDONTR5=(CONT(I+N)+\n & (S-C2M1)*(CONT(I+N2)+CONT(I+N3)*(S-C1M1))+\n & S*(CONT(I+N2)+CONT(I+N3)*(2.*S-C1M1-C2M1)))/HSOL\n \n RETURN\n END\nC\nC END OF FUNCTION DONTR5\nC\nC ***********************************************************\n\n", "meta": {"hexsha": "c19056f5c76b6970d99d8d18e574becb5738cb18", "size": 1030, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "TwoStateModel/dontr5.f", "max_stars_repo_name": "ebenjaminrandall/DelayDDEBifurcationAnalysis", "max_stars_repo_head_hexsha": "9020d83bf6e07f1d8af1d062954a68055b5cbe6f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-09-22T14:05:30.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-10T10:06:06.000Z", "max_issues_repo_path": "code/dontr5.f", "max_issues_repo_name": "ebenjaminrandall/Randall_VMPaper", "max_issues_repo_head_hexsha": "b84d2cc599a0a80b3f795a0e5a6999435f497103", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-05-25T09:14:28.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-25T09:14:28.000Z", "max_forks_repo_path": "code/dontr5.f", "max_forks_repo_name": "ebenjaminrandall/Randall_VMPaper", "max_forks_repo_head_hexsha": "b84d2cc599a0a80b3f795a0e5a6999435f497103", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-04-27T10:14:46.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-27T10:14:46.000Z", "avg_line_length": 32.1875, "max_line_length": 73, "alphanum_fraction": 0.4805825243, "num_tokens": 291, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026663679976, "lm_q2_score": 0.7606506635289835, "lm_q1q2_score": 0.6977468818297231}} {"text": "c\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc . .\nc . copyright (c) 1998 by UCAR .\nc . .\nc . University Corporation for Atmospheric Research .\nc . .\nc . all rights reserved .\nc . .\nc . .\nc . SPHEREPACK .\nc . .\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc\nc\nc ... file gradgs.f\nc\nc this file includes documentation and code for\nc subroutine gradgs i\nc\nc ... files which must be loaded with gradgec.f\nc\nc sphcom.f, hrfft.f, shags.f,vhsgs.f\nc\nc subroutine gradgs(nlat,nlon,isym,nt,v,w,idvw,jdvw,a,b,mdab,ndab,\nc + wvhsgs,lvhsgs,work,lwork,ierror)\nc\nC*PL*ERROR* Comment line too long\nc given the scalar spherical harmonic coefficients a and b, precomputed\nC*PL*ERROR* Comment line too long\nc by subroutine shags for a scalar field sf, subroutine gradgs computes\nc an irrotational vector field (v,w) such that\nc\nc gradient(sf) = (v,w).\nc\nc v is the colatitudinal and w is the east longitudinal component\nc of the gradient. i.e.,\nc\nc v(i,j) = d(sf(i,j))/dtheta\nc\nc and\nc\nc w(i,j) = 1/sint*d(sf(i,j))/dlambda\nc\nc at the gaussian colatitude point theta(i) (see nlat as input\nc parameter) and longitude lambda(j) = (j-1)*2*pi/nlon where\nc sint = sin(theta(i)).\nc\nc\nc input parameters\nc\nc nlat the number of points in the gaussian colatitude grid on the\nC*PL*ERROR* Comment line too long\nc full sphere. these lie in the interval (0,pi) and are computed\nC*PL*ERROR* Comment line too long\nc in radians in theta(1) <...< theta(nlat) by subroutine gaqd.\nC*PL*ERROR* Comment line too long\nc if nlat is odd the equator will be included as the grid point\nc theta((nlat+1)/2). if nlat is even the equator will be\nc excluded as a grid point and will lie half way between\nc theta(nlat/2) and theta(nlat/2+1). nlat must be at least 3.\nc note: on the half sphere, the number of grid points in the\nc colatitudinal direction is nlat/2 if nlat is even or\nc (nlat+1)/2 if nlat is odd.\nc\nc nlon the number of distinct londitude points. nlon determines\nc the grid increment in longitude as 2*pi/nlon. for example\nc nlon = 72 for a five degree grid. nlon must be greater than\nc 3. the efficiency of the computation is improved when nlon\nc is a product of small prime numbers.\nc\nc\nc isym this has the same value as the isym that was input to\nc subroutine shags to compute the arrays a and b from the\nc scalar field sf. isym determines whether (v,w) are\nc computed on the full or half sphere as follows:\nc\nc = 0\nc\nc sf is not symmetric about the equator. in this case\nc the vector field (v,w) is computed on the entire sphere.\nc i.e., in the arrays v(i,j),w(i,j) for i=1,...,nlat and\nc j=1,...,nlon.\nc\nc = 1\nc\nc sf is antisymmetric about the equator. in this case w is\nc antisymmetric and v is symmetric about the equator. w\nc and v are computed on the northern hemisphere only. i.e.,\nc if nlat is odd they are computed for i=1,...,(nlat+1)/2\nc and j=1,...,nlon. if nlat is even they are computed for\nc i=1,...,nlat/2 and j=1,...,nlon.\nc\nc = 2\nc\nc sf is symmetric about the equator. in this case w is\nc symmetric and v is antisymmetric about the equator. w\nc and v are computed on the northern hemisphere only. i.e.,\nc if nlat is odd they are computed for i=1,...,(nlat+1)/2\nc and j=1,...,nlon. if nlat is even they are computed for\nc i=1,...,nlat/2 and j=1,...,nlon.\nc\nc\nc nt nt is the number of scalar and vector fields. some\nc computational efficiency is obtained for multiple fields.\nC*PL*ERROR* Comment line too long\nc the arrays a,b,v, and w can be three dimensional corresponding\nc to an indexed multiple array sf. in this case, multiple\nc vector synthesis will be performed to compute each vector\nc field. the third index for a,b,v, and w is the synthesis\nc index which assumes the values k = 1,...,nt. for a single\nc synthesis set nt = 1. the description of the remaining\nC*PL*ERROR* Comment line too long\nc parameters is simplified by assuming that nt=1 or that a,b,v,\nc and w are two dimensional arrays.\nc\nc idvw the first dimension of the arrays v,w as it appears in\nc the program that calls gradgs. if isym = 0 then idvw\nc must be at least nlat. if isym = 1 or 2 and nlat is\nc even then idvw must be at least nlat/2. if isym = 1 or 2\nc and nlat is odd then idvw must be at least (nlat+1)/2.\nc\nc jdvw the second dimension of the arrays v,w as it appears in\nc the program that calls gradgs. jdvw must be at least nlon.\nc\nc a,b two or three dimensional arrays (see input parameter nt)\nc that contain scalar spherical harmonic coefficients\nC*PL*ERROR* Comment line too long\nc of the scalar field array sf as computed by subroutine shags.\nc *** a,b must be computed by shags prior to calling gradgs.\nc\nc mdab the first dimension of the arrays a and b as it appears in\nc the program that calls gradgs (and shags). mdab must be at\nc least min0(nlat,(nlon+2)/2) if nlon is even or at least\nc min0(nlat,(nlon+1)/2) if nlon is odd.\nc\nc ndab the second dimension of the arrays a and b as it appears in\nc the program that calls gradgs (and shags). ndab must be at\nc least nlat.\nc\nc\nc wvhsgs an array which must be initialized by subroutine vhsgsi.\nc once initialized,\nc wvhsgs can be used repeatedly by gradgs as long as nlon\nc and nlat remain unchanged. wvhsgs must not be altered\nc between calls of gradgs.\nc\nc\nc lvhsgs the dimension of the array wvhsgs as it appears in the\nc program that calls grradgs. define\nc\nc l1 = min0(nlat,nlon/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc and\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc then lvhsgs must be at least\nc\nc l1*l2*(nlat+nlat-l1+1)+nlon+15+2*nlat\nc\nc\nc work a work array that does not have to be saved.\nc\nc lwork the dimension of the array work as it appears in the\nc program that calls gradgs. define\nc\nc l1 = min0(nlat,nlon/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc and\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc if isym = 0, lwork must be greater than or equal to\nc\nc nlat*((2*nt+1)*nlon+2*l1*nt+1).\nc\nc if isym = 1 or 2, lwork must be greater than or equal to\nc\nc (2*nt+1)*l2*nlon+nlat*(2*l1*nt+1).\nc\nc\nc **************************************************************\nc\nc output parameters\nc\nc\nC*PL*ERROR* Comment line too long\nc v,w two or three dimensional arrays (see input parameter nt) that\nC*PL*ERROR* Comment line too long\nc contain an irrotational vector field such that the gradient of\nc the scalar field sf is (v,w). w(i,j) is the east longitude\nC*PL*ERROR* Comment line too long\nc component and v(i,j) is the colatitudinal component of velocity\nC*PL*ERROR* Comment line too long\nc at gaussian colatitude and longitude lambda(j) = (j-1)*2*pi/nlon\nc the indices for v and w are defined at the input parameter\nC*PL*ERROR* Comment line too long\nc isym. the vorticity of (v,w) is zero. note that any nonzero\nC*PL*ERROR* Comment line too long\nc vector field on the sphere will be multiple valued at the poles\nc [reference swarztrauber].\nc\nc\nc ierror = 0 no errors\nc = 1 error in the specification of nlat\nc = 2 error in the specification of nlon\nc = 3 error in the specification of isym\nc = 4 error in the specification of nt\nc = 5 error in the specification of idvw\nc = 6 error in the specification of jdvw\nc = 7 error in the specification of mdab\nc = 8 error in the specification of ndab\nc = 9 error in the specification of lvhsgs\nc = 10 error in the specification of lwork\nc **********************************************************************\nc\nc\n SUBROUTINE DGRADGS(NLAT,NLON,ISYM,NT,V,W,IDVW,JDVW,A,B,MDAB,NDAB,\n + WVHSGS,LVHSGS,WORK,LWORK,IERROR)\n DOUBLE PRECISION V\n DOUBLE PRECISION W\n DOUBLE PRECISION A\n DOUBLE PRECISION B\n DOUBLE PRECISION WVHSGS\n DOUBLE PRECISION WORK\n DIMENSION V(IDVW,JDVW,NT),W(IDVW,JDVW,NT)\n DIMENSION A(MDAB,NDAB,NT),B(MDAB,NDAB,NT)\n DIMENSION WVHSGS(LVHSGS),WORK(LWORK)\nc\nc check input parameters\nc\n IERROR = 1\n IF (NLAT.LT.3) RETURN\n IERROR = 2\n IF (NLON.LT.4) RETURN\n IERROR = 3\n IF (ISYM.LT.0 .OR. ISYM.GT.2) RETURN\n IERROR = 4\n IF (NT.LT.0) RETURN\n IERROR = 5\n IMID = (NLAT+1)/2\n IF ((ISYM.EQ.0.AND.IDVW.LT.NLAT) .OR.\n + (ISYM.NE.0.AND.IDVW.LT.IMID)) RETURN\n IERROR = 6\n IF (JDVW.LT.NLON) RETURN\n IERROR = 7\n MMAX = MIN0(NLAT, (NLON+1)/2)\n IF (MDAB.LT.MIN0(NLAT, (NLON+2)/2)) RETURN\n IERROR = 8\n IF (NDAB.LT.NLAT) RETURN\n IERROR = 9\nc\nc verify minimum saved work space length\nc\n IDZ = (MMAX* (NLAT+NLAT-MMAX+1))/2\n LZIMN = IDZ*IMID\n LGDMIN = LZIMN + LZIMN + NLON + 15\n IF (LVHSGS.LT.LGDMIN) RETURN\n IERROR = 10\nc\nc verify minimum unsaved work space length\nc\n MN = MMAX*NLAT*NT\n IDV = NLAT\n IF (ISYM.NE.0) IDV = IMID\n LNL = NT*IDV*NLON\n LWKMIN = LNL + LNL + IDV*NLON + 2*MN + NLAT\n IF (LWORK.LT.LWKMIN) RETURN\n IERROR = 0\nc\nc set work space pointers\nc\n IBR = 1\n IBI = IBR + MN\n IS = IBI + MN\n IWK = IS + NLAT\n LIWK = LWORK - 2*MN - NLAT\n CALL DGRADGS1(NLAT,NLON,ISYM,NT,V,W,IDVW,JDVW,WORK(IBR),WORK(IBI),\n + MMAX,WORK(IS),MDAB,NDAB,A,B,WVHSGS,LVHSGS,WORK(IWK),\n + LIWK,IERROR)\n RETURN\n END\n\n SUBROUTINE DGRADGS1(NLAT,NLON,ISYM,NT,V,W,IDVW,JDVW,BR,BI,MMAX,\n + SQNN,MDAB,NDAB,A,B,WVHSGS,LVHSGS,WK,LWK,IERROR)\n DOUBLE PRECISION V\n DOUBLE PRECISION W\n DOUBLE PRECISION BR\n DOUBLE PRECISION BI\n DOUBLE PRECISION SQNN\n DOUBLE PRECISION A\n DOUBLE PRECISION B\n DOUBLE PRECISION WVHSGS\n DOUBLE PRECISION WK\n DOUBLE PRECISION FN\n DOUBLE PRECISION CR\n DOUBLE PRECISION CI\n DIMENSION V(IDVW,JDVW,NT),W(IDVW,JDVW,NT)\n DIMENSION BR(MMAX,NLAT,NT),BI(MMAX,NLAT,NT),SQNN(NLAT)\n DIMENSION A(MDAB,NDAB,NT),B(MDAB,NDAB,NT)\n DIMENSION WVHSGS(LVHSGS),WK(LWK)\nc\nc preset coefficient multiplyers in vector\nc\n DO 1 N = 2,NLAT\n FN = DBLE(N-1)\n SQNN(N) = SQRT(FN* (FN+1.D0))\n 1 CONTINUE\nc\nc compute multiple vector fields coefficients\nc\n DO 2 K = 1,NT\nc\nc preset br,bi to 0.0\nc\n DO 3 N = 1,NLAT\n DO 4 M = 1,MMAX\n BR(M,N,K) = 0.0D0\n BI(M,N,K) = 0.0D0\n 4 CONTINUE\n 3 CONTINUE\nc\nc compute m=0 coefficients\nc\n DO 5 N = 2,NLAT\n BR(1,N,K) = SQNN(N)*A(1,N,K)\n BI(1,N,K) = SQNN(N)*B(1,N,K)\n 5 CONTINUE\nc\nc compute m>0 coefficients\nc\n DO 6 M = 2,MMAX\n DO 7 N = M,NLAT\n BR(M,N,K) = SQNN(N)*A(M,N,K)\n BI(M,N,K) = SQNN(N)*B(M,N,K)\n 7 CONTINUE\n 6 CONTINUE\n 2 CONTINUE\nc\nc set ityp for irrotational vector synthesis to compute gradient\nc\n IF (ISYM.EQ.0) THEN\n ITYP = 1\n ELSE IF (ISYM.EQ.1) THEN\n ITYP = 4\n ELSE IF (ISYM.EQ.2) THEN\n ITYP = 7\n END IF\nc\nc vector sythesize br,bi into (v,w) (cr,ci are dummy variables)\nc\n CALL DVHSGS(NLAT,NLON,ITYP,NT,V,W,IDVW,JDVW,BR,BI,CR,CI,MMAX,NLAT,\n + WVHSGS,LVHSGS,WK,LWK,IERROR)\n RETURN\n END\n", "meta": {"hexsha": "1200806d8ca2d56759828bf791ebee623add0b6b", "size": 13009, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "external/sphere3.1_dp/gradgs.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "external/sphere3.1_dp/gradgs.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "external/sphere3.1_dp/gradgs.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 36.0360110803, "max_line_length": 76, "alphanum_fraction": 0.5642247675, "num_tokens": 4038, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026528034426, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.697746866534691}} {"text": "!---------------------------------------------------!\n! Copyright (c) 2017 Shunsuke A. Sato !\n! Released under the MIT license !\n! https://opensource.org/licenses/mit-license.php !\n!---------------------------------------------------!\nsubroutine hpsi_sp(u,hu,v)\n use global_variables\n implicit none\n real(dp) :: u(0:Nx),hu(0:Nx),tu(0-4:Nx+4),v(0:Nx)\n! finite difference\n real(dp) :: c0,c1,c2,c3,c4\n integer :: ix\n\n c0=-0.5d0*cN0/(dx**2)\n c1=-0.5d0*cN1/(dx**2)\n c2=-0.5d0*cN2/(dx**2)\n c3=-0.5d0*cN3/(dx**2)\n c4=-0.5d0*cN4/(dx**2)\n\n tu = 0d0\n tu(0:Nx) = u(0:Nx)\n do ix = 0,Nx\n hu(ix) = c0*tu(ix) &\n + c1*(tu(ix+1)+tu(ix-1)) &\n + c2*(tu(ix+2)+tu(ix-2)) &\n + c3*(tu(ix+3)+tu(ix-3)) &\n + c4*(tu(ix+4)+tu(ix-4)) \n end do\n\n hu(:) = hu(:) + v(:)*u(:)\n\n return\nend subroutine hpsi_sp\n", "meta": {"hexsha": "b58150a2f3ab99033597b5cef307dc6e9acb5a06", "size": 849, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/hpsi_sp.f90", "max_stars_repo_name": "shunsuke-sato/qm1d", "max_stars_repo_head_hexsha": "b09bbe97dc2987188fe635b27dce89ce82e5d1ee", "max_stars_repo_licenses": ["MIT"], "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/hpsi_sp.f90", "max_issues_repo_name": "shunsuke-sato/qm1d", "max_issues_repo_head_hexsha": "b09bbe97dc2987188fe635b27dce89ce82e5d1ee", "max_issues_repo_licenses": ["MIT"], "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/hpsi_sp.f90", "max_forks_repo_name": "shunsuke-sato/qm1d", "max_forks_repo_head_hexsha": "b09bbe97dc2987188fe635b27dce89ce82e5d1ee", "max_forks_repo_licenses": ["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.9705882353, "max_line_length": 53, "alphanum_fraction": 0.4558303887, "num_tokens": 341, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026618464795, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.697746863458994}} {"text": " subroutine resid_eqipsi(n_a1,n_alpha,n_beta,n_iPHI,n_iPI,n_ipsi,np\n &1_a1,np1_alpha,np1_beta,np1_iPHI,np1_iPI,np1_ipsi,x,Nx,ht,myzero,z\n &epsdis,phys_bdy,res)\n implicit none\n integer i\n integer Nx\n real*8 ht\n real*8 myzero\n real*8 zepsdis\n real*8 n_a1(Nx)\n real*8 n_alpha(Nx)\n real*8 n_beta(Nx)\n real*8 n_iPHI(Nx)\n real*8 n_iPI(Nx)\n real*8 n_ipsi(Nx)\n real*8 np1_a1(Nx)\n real*8 np1_alpha(Nx)\n real*8 np1_beta(Nx)\n real*8 np1_iPHI(Nx)\n real*8 np1_iPI(Nx)\n real*8 np1_ipsi(Nx)\n real*8 x(Nx)\n integer phys_bdy(2)\n real*8 res\n real*8 qb\n res = 0.0D0\n if (phys_bdy(1) .eq. 1) then\n do i=1, 1, 1\n qb = np1_ipsi(i) - 0.1333333333333333D1 * np1_ipsi(i + 1) + 0.3333\n #333333333333D0 * np1_ipsi(i + 2)\n res = res + qb**2\n end do\n endif\n if (phys_bdy(1) .eq. 1) then\n do i=2, 2, 1\n qb = (-0.1D1 * n_ipsi(i) + np1_ipsi(i)) / ht - 0.5000000000000000D\n #0 * np1_alpha(i) / np1_a1(i) * np1_iPI(i) - 0.5000000000000000D0 *\n # np1_beta(i) * np1_iPHI(i) - 0.5000000000000000D0 * n_alpha(i) / n\n #_a1(i) * n_iPI(i) - 0.5000000000000000D0 * n_beta(i) * n_iPHI(i) +\n # 0.3125000000000000D-1 * zepsdis / ht * (0.7D1 * np1_ipsi(i) + np1\n #_ipsi(i + 2) - 0.4D1 * np1_ipsi(i + 1) - 0.4D1 * np1_ipsi(i - 1)) \n #+ 0.3125000000000000D-1 * zepsdis / ht * (0.7D1 * n_ipsi(i) + n_ip\n #si(i + 2) - 0.4D1 * n_ipsi(i + 1) - 0.4D1 * n_ipsi(i - 1))\n res = res + qb**2\n end do\n endif\n do i=3, Nx-2, 1\n qb = (-0.1D1 * n_ipsi(i) + np1_ipsi(i)) / ht - 0.5000000000000000D\n #0 * np1_alpha(i) / np1_a1(i) * np1_iPI(i) - 0.5000000000000000D0 *\n # np1_beta(i) * np1_iPHI(i) - 0.5000000000000000D0 * n_alpha(i) / n\n #_a1(i) * n_iPI(i) - 0.5000000000000000D0 * n_beta(i) * n_iPHI(i) +\n # 0.3125000000000000D-1 * zepsdis / ht * (0.6D1 * np1_ipsi(i) + np1\n #_ipsi(i + 2) + np1_ipsi(i - 2) - 0.4D1 * np1_ipsi(i + 1) - 0.4D1 *\n # np1_ipsi(i - 1)) + 0.3125000000000000D-1 * zepsdis / ht * (0.6D1 \n #* n_ipsi(i) + n_ipsi(i + 2) + n_ipsi(i - 2) - 0.4D1 * n_ipsi(i + 1\n #) - 0.4D1 * n_ipsi(i - 1))\n res = res + qb**2\n end do\n do i=Nx-1, Nx-1, 1\n qb = (-0.1D1 * n_ipsi(i) + np1_ipsi(i)) / ht - 0.5000000000000000D\n #0 * np1_alpha(i) / np1_a1(i) * np1_iPI(i) - 0.5000000000000000D0 *\n # np1_beta(i) * np1_iPHI(i) - 0.5000000000000000D0 * n_alpha(i) / n\n #_a1(i) * n_iPI(i) - 0.5000000000000000D0 * n_beta(i) * n_iPHI(i)\n res = res + qb**2\n end do\n if (phys_bdy(2) .eq. 1) then\n do i=Nx, Nx, 1\n qb = (-0.1D1 * n_ipsi(i) + np1_ipsi(i)) / ht - 0.1D1 * myzero * x(\n #i)\n res = res + qb**2\n end do\n endif\n res = sqrt(res/(1*Nx))\n END\n", "meta": {"hexsha": "f5d5bf88c38e4d6b2b9f9ff372c30bfc07dbc6da", "size": 2823, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/FD/resid_eqipsi.f", "max_stars_repo_name": "rmanak/bssn_spher", "max_stars_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/FD/resid_eqipsi.f", "max_issues_repo_name": "rmanak/bssn_spher", "max_issues_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/FD/resid_eqipsi.f", "max_forks_repo_name": "rmanak/bssn_spher", "max_forks_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.64, "max_line_length": 72, "alphanum_fraction": 0.5469358838, "num_tokens": 1339, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625012602593, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.697746649189921}} {"text": "\tINTEGER*4 FUNCTION\r\n . SURVSIZE(ALPHA,POWER,M1,M2,A,F,M,R,ALT)\r\n\tIMPLICIT NONE\r\nC\r\nC-Description-----------------------------------------------------------\r\nC\r\nC Function:\r\nC\tDetermine the sample size needed to produce a specified level\r\nC\tof statistical power for survival data.\r\nC\t\r\nC Input (provided by user):\r\nC\tALPHA\tType I error probability (two tailed)\r\nC\tPOWER\tThe desired statistical power',\r\nC\tM1\tMedian survival time on control treatment\r\nC\tM2\tMedian survival time on experimantal treatment\r\nC\tR=M2/M1 Ratio of median survival times for experimental subjects\r\nC\t\trelative to controls -or-\r\nC\t\tRelative hazard (risk) of the control treatment relative\r\nC\t\tto the experimental treatment\r\nC\tALT\t1 if input requires M1 and M2\r\nC\t\t2 if input requires M1 and R\r\nC\tA\tThe accrual time during which patients are recruited into\r\nC\t\tthe study\r\nC\tF\tAdditional follow-up time after the end of patient\r\nC\t\trecruitment\r\nC\tM\tRatio of control to experimental patients\r\nC Output:\r\nC\t\tNumber of experimental patients that must be recruited\r\nC\t\tin order to be able to detect a true ratio of median\r\nC\t\tsurvival times R with type I error probability ALPHA and power\r\nC\t\tPOWER\r\nC Reference:\r\nC\tSchoenfeld DA, Richter JR: \"Nomograms for Calculating the\r\nC\tNumber of Patients Needed for a Clinical Trial With Survival\r\nC\tas an Endpoint\" Biometrics 1982; 38: 163-170.\r\nC\r\nC Notes:\r\nC .\tThis routine was written by Dale Plummer\r\nC .\tDesigned by William Dupont\r\nC .\tSchoenfeld and Richter define BETA to equal the study power\r\nC\trather than the type II error. Otherwise the notation used\r\nC\tin this program is analogous to that used by these authors.\r\nC\r\nC-Declarations----------------------------------------------------------\r\nC\r\nC\r\nC Functions\r\nC\r\n\tREAL*4 ZCRVALUE\r\nC\r\nC Locals\r\nC\r\n\tREAL*4 ALPHA,BETA,M1,M2,R,A,F,M\r\n\tINTEGER*4 ALT\r\n\tREAL*4 PA,GF,P,ZALPHA,ZBETA,MM,POWER\r\nC\r\nC-Code------------------------------------------------------------------\r\nC\r\n\tIF (ALT.EQ.1) THEN\r\nC\t ' Enter ALPHA, POWER, M1, M2, A, F, and M: '\r\n\t R=M2/M1\r\n\tELSE\r\nC\t ' Enter ALPHA, POWER, M1, R, A, F, and M: '\r\n\t M2=R*M1\r\n\tEND IF\r\n\tIF (A.EQ.0) A=F*0.00004\r\nC\r\nC Check for errors. Return -999 if any found.\r\nC\r\n\tIF (R.EQ.1.0) THEN\r\n\t SURVSIZE=-999\r\n\t\tRETURN\r\n\tEND IF\r\nC\r\nC Do the real work.\r\nC\r\n\tBETA=1.-POWER\r\n\tMM=(M1+M2)/2.\r\n\tPA=(1.-EXP(-LOG(2.)*A/MM))/(LOG(2.)*A/MM)\r\n\tGF=EXP(-LOG(2.)*F/MM)\r\n\tP=1.-PA*GF\r\n\tZALPHA=ZCRVALUE(ALPHA/2.)\r\n\tZBETA=ZCRVALUE(BETA)\r\n\tSURVSIZE=NINT( (ZALPHA+ZBETA)**2 * ((1.+1./M)/P)/(LOG(R))**2 )\r\n\tRETURN\r\n\tEND\r\n", "meta": {"hexsha": "b69d914700235867397405b20f7c1bbaa6e3965c", "size": 2543, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "misc/old_ps/ps-development-version/psDll/survsize.for", "max_stars_repo_name": "vubiostat/ps", "max_stars_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2017-12-29T14:19:14.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-06T15:08:46.000Z", "max_issues_repo_path": "misc/old_ps/ps-development-version/psDll/survsize.for", "max_issues_repo_name": "vubiostat/ps", "max_issues_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2020-04-30T16:57:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-07T00:26:02.000Z", "max_forks_repo_path": "misc/old_ps/ps-development-version/psDll/survsize.for", "max_forks_repo_name": "vubiostat/ps", "max_forks_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-07T20:11:54.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-11T19:18:59.000Z", "avg_line_length": 29.2298850575, "max_line_length": 73, "alphanum_fraction": 0.6456940621, "num_tokens": 776, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625012602594, "lm_q2_score": 0.7490872075132152, "lm_q1q2_score": 0.6977466439723224}} {"text": "module linearsolvers\n implicit none\n integer,parameter :: ndf=2 !number of degrees of freedom\n integer,parameter :: dimen=1 !dimention of problem\n\n integer,parameter::inp=1 !input file\n integer,parameter::out=2 !output file\n integer,parameter::msh=3 !mesh file\n integer,parameter::bnd=4 !boundary file\n integer,parameter::tec=5 !the techplot file\n integer,parameter::dat=6 !mesh file itech\n integer,parameter::cur=8 !curve file\n integer,parameter::csv=11 !comma seperated file\n integer,parameter::vtu=13 !output file\n integer,parameter::OUTPUT_UNIT=7\n\n ! the default value for the smallest pivot that will be accepted\n ! using the linearsolvers subroutines. pivots smaller than this\n ! threshold will cause premature termination of the linear equation\n ! solver and return false as the return value of the function.\n\n real*8, parameter :: default_smallest_pivot = 1.0e-6\n\ncontains\n\n\n\n\n FUNCTION SAWTOOTH(TIME)\n IMPLICIT NONE\n REAL*8::TIME,SAWTOOTH\n SAWTOOTH=4*(ABS(TIME+0.25-FLOOR(TIME+0.75))-0.25)\n ENDFUNCTION SAWTOOTH\n\n\n\n subroutine lapack_gesv(a,b)\n implicit none\n integer, parameter :: nmax=1000\n\n! ============================================================================\n! name : lapack solver compact\n! author : amir\n! version :\n! copyright : your copyright notice\n! description : this solves a * x=b and put the solution\n! into the b vector\n! ============================================================================\n\n\nreal*8::a(:,:),b(:)\ninteger::n, nrhs, lda, ldb, info\ninteger,allocatable::ipiv(:)\n\nn=size(b)\nnrhs=1\nlda=n\nldb=n;\nallocate(ipiv(n))\n\n\ncall dgesv(n, nrhs, a, lda, ipiv, b, ldb, info)\n\nendsubroutine lapack_gesv\n\n\n\n SUBROUTINE CONJGRAD_SOLVER(A,B,X)\n IMPLICIT NONE\n REAL*8,DIMENSION(:),INTENT(IN)::B\n REAL*8,DIMENSION(:)::X\n REAL*8,DIMENSION(:,:),INTENT(IN)::A\n REAL*8,DIMENSION(:),ALLOCATABLE :: P,R,AP\n REAL*8::RSOLD,RSNEW,ALPHA\n INTEGER::DIMEN\n! ========================CONVERGENCE VARIABLES\n INTEGER::CG_ITERS,CG_LIMIT\n LOGICAL::CG_CONVERGED\n REAL*8::CG_TOL\n! ================================================================\n\n DIMEN=SIZE(B)\n CG_TOL=1E-5\n CG_LIMIT=500\n CG_ITERS=0\n\n ALLOCATE(R(DIMEN),P(DIMEN),AP(DIMEN))\n R=B-MATMUL(A,X)\n P=R\n RSOLD=DOT_PRODUCT(R,R)\n\n PCG: DO; CG_ITERS=CG_ITERS+1;\n AP=MATMUL(A,P)\n ALPHA=RSOLD/DOT_PRODUCT(P,AP)\n X=X+ALPHA*P\n R=R-ALPHA*AP\n RSNEW=DOT_PRODUCT(R,R)\n CG_CONVERGED=(SQRT(RSNEW).LT.CG_TOL)\n IF(CG_CONVERGED.OR.CG_ITERS==CG_LIMIT)EXIT\n P=R+(RSNEW/RSOLD)*P;\n RSOLD=RSNEW;\n END DO PCG\n WRITE(1,*) CG_ITERS\n ENDSUBROUTINE CONJGRAD_SOLVER\n\n\n\n SUBROUTINE CONJGRAD_SOLVER_K(K,F,U)\n IMPLICIT NONE\n REAL*8,DIMENSION(:),INTENT(IN)::F\n REAL*8,DIMENSION(:)::U\n REAL*8,DIMENSION(:,:),INTENT(IN)::K\n REAL*8,DIMENSION(:),ALLOCATABLE :: P,R,Q\n REAL*8::RSOLD,RSNEW,ALPHA,BETA,RTR\n INTEGER::DIMEN\n! ========================CONVERGENCE VARIABLES\n INTEGER::CG_ITERS,CG_LIMIT\n LOGICAL::CG_CONVERGED\n REAL*8::CG_TOL\n! ================================================================\n\n DIMEN=SIZE(F)\n CG_TOL=1E-5\n CG_LIMIT=DIMEN*2\n CG_ITERS=0\n\n\n ALLOCATE(P(DIMEN),Q(DIMEN),R(DIMEN))\n R=F-MATMUL(K,U)\n P=R\n\n PCG: DO;\n CG_ITERS=CG_ITERS+1;\n! WRITE(1,*)CG_ITERS\n Q=MATMUL(K,P)\n RTR=DOT_PRODUCT(R,R)\n ALPHA=RTR/DOT_PRODUCT(P,Q)\n\n U=U+ALPHA*P\n R=R-ALPHA*Q\n BETA=DOT_PRODUCT(R,R)/RTR\n P=R+BETA*P\n\n\n CG_CONVERGED=(SQRT(DOT_PRODUCT(R,R)).LT.CG_TOL)\n IF(CG_CONVERGED.OR.CG_ITERS==CG_LIMIT)EXIT\n END DO PCG\n\n\n WRITE(1,*)CG_ITERS\n ENDSUBROUTINE CONJGRAD_SOLVER_k\n\n\n ! Use Gaussian elimination to calculate the solution to the linear\n ! system, A x = b. No partial pivoting is done. If the threshold\n ! argument is present, it is used as the smallest allowable pivot\n ! encountered in the computation; otherwise, DEFAULT_SMALLEST_PIVOT,\n ! defined in this module, is used as the default threshold. The status\n ! of the computation is a logical returned by the function indicating\n ! the existence of a unique solution (.true.), or the nonexistence of\n ! a unique solution or threshold passed (.false.).\n\n ! Note that this is an inappropriate method for some linear systems.\n ! In particular, the linear system, M x = b, where M = 10e-12 I, will\n ! cause this routine to fail due to the presence of small pivots.\n ! However, this system is perfectly conditioned, with solution x = b.\n\n function gaussianElimination( A, b, x, threshold )\n implicit none\n logical gaussianElimination\n real*8, dimension( :, : ), intent( in ) :: A ! Assume the shape of A.\n real*8, dimension( : ), intent( in ) :: b ! Assume the shape of b.\n real*8, dimension( : ), intent( out ) :: x ! Assume the shape of x.\n\n ! The optional attribute specifies that the indicated argument\n ! is not required to be present in a call to the function. The\n ! presence of optional arguments, such as threshold, may be checked\n ! using the intrinsic logical function, present (see below).\n\n REAL*8, optional, intent( in ) :: threshold\n\n integer i, j ! Local index variables.\n integer N ! Order of the linear system.\n real m ! Multiplier.\n real :: smallestPivot = DEFAULT_SMALLEST_PIVOT\n\n ! Pointers to the appropriate rows of the matrix during the elmination.\n REAL*8, dimension( : ), pointer :: pivotRow\n REAL*8, dimension( : ), pointer :: currentRow\n\n ! Copies of the input arguments. These copies are modified during\n ! the computation.\n ! The target attribute is used to indicate that the specified\n ! variable may be the target of a pointer. Rows of ACopy are targets\n ! of pivotRow and currentRow, defined above.\n\n REAL*8, dimension( size( A, 1 ), size( A, 2) ), target :: ACopy\n REAL*8, dimension( size( b ) ) :: bCopy\n\n ! Status of the computation. The return value of the function.\n logical successful\n ! Change the smallestPivot if the threshold argument was included.\n if ( present( threshold ) ) smallestPivot = abs( threshold )\n\n ! Setup the order of the system by using the intrinsic function size.\n ! size returns the number of elements in the specified dimension of\n ! an array or the total number of elements if the dimension is not\n ! specified. Also assume that a unique solution exists initially.\n\n N = size( b )\n ACopy = A\n bCopy = b\n successful = .true.\n\n ! Begin the Gaussian elimination algorithm.\n ! Note the use of array sections in the following loops. These\n ! eliminate the need for many do loops that are common in Fortran\n ! 77 code.\n ! Pointers are also used below and enhance the readability of the\n ! elimination process.\n\n ! Begin with the first row.\n\n i = 1\n\n ! Reduce the system to upper triangular.\n do while ( ( successful ) .and. ( i <= N-1 ) )\n\n ! The following statement is called pointer assignment and uses\n ! the pointer assignment operator `=>'. This causes pivotRow\n ! to be an alias for the ith row of ACopy. Note that this does\n ! not cause any movement of data.\n\n ! Assign the pivot row.\n pivotRow => ACopy( i, : )\n\n ! Verify that the current pivot is not smaller than smallestPivot.\n successful = abs( pivotRow( i ) ) >= smallestPivot\n\n if ( successful ) then\n\n ! Eliminate the entries in the pivot column below the pivot row.\n\n do j = i+1, N\n ! Assign the current row.\n currentRow => ACopy( j, : )\n\n ! Calculate the multiplier.\n m = currentRow( i ) / pivotRow( i )\n\n ! Perform the elimination step on currentRow and right\n ! hand side, bCopy.\n currentRow = m * pivotRow - currentRow\n bCopy( j ) = m * bCopy( i ) - bCopy( j )\n end do\n\n end if\n\n ! Move to the next row.\n i = i + 1\n\n end do\n\n ! Check the last pivot.\n pivotRow => ACopy( N, : )\n if ( successful ) successful = abs( pivotRow( N ) ) >= smallestPivot\n\n if ( successful ) then\n do i = N, 2, -1 ! Backward substitution.\n\n ! Determine the ith unknown, x( i ).\n x( i ) = bCopy( i ) / ACopy( i, i )\n\n ! Substitute the now known value of x( i ), reducing the order of\n ! the system by 1.\n bCopy = bCopy - x( i ) * ACopy( :, i )\n\n end do\n end if\n\n ! Determine the value of x( 1 ) as a special case.\n if ( successful ) x( 1 ) = bCopy( 1 ) / ACopy( 1, 1 )\n\n ! Prepare the return value of the function.\n gaussianElimination = successful\n\n end function gaussianElimination\n\n\n ! The LU decomposition of a matrix may be represented in a compact form\n ! existing in a single matrix, M, if the assignments M=L and M=U are\n ! done (in that order). The diagonal entries in L are assumed to be\n ! unity so that no storage space is necessary. Instead, the diagonal\n ! of M is used to hold the diagonal entries of U. This is a common\n ! method of storing the LU decomposition of a matrix.\n\n ! The algorithm belows makes an additional assumption concerning the\n ! pivots or diagonal elements of U. Computation terminates if one of\n ! these pivots is smaller than the given or default threshold. In this\n ! case, the LU decomposition is not formed. Note that this algorithm\n ! successfully terminates if such an LU can be computed. In this case\n ! the coefficient matrix, A, is nonsingular. (No attempt for recovery,\n ! such as permutation of rows, is done.)\n\n ! Compute the LU decomposition of A, storing the result in LU so that\n ! A is not overwritten. If the threshold argument is present, it is used\n ! as the smallest allowable pivot encountered in the computation;\n ! otherwise, DEFAULT_SMALLEST_PIVOT, defined in this module, is used as\n ! the default threshold during the computation. The status of the\n ! computation is a logical returned by the function indicating the\n ! success (.true.) or failure (.false.) of the factorization\n ! After the computation, LU will contain the multipliers below the main\n ! diagonal (L) and the result after elimination on and above the main\n ! diagonal (U), so that A = L * U.\n\n function LUFactor ( A, LU, threshold )\n implicit none\n logical LUFactor\n REAL*8, dimension( :, : ), intent( in ) :: A\n REAL*8, dimension( :, : ), intent( out ) :: LU\n REAL*8, optional, intent( in ) :: threshold\n\n integer k, i\n integer N\n logical successful ! Status of the computation.\n real :: smallestPivot = DEFAULT_SMALLEST_PIVOT\n\n ! Reassign the smallestPivot, set the order of the system, and\n ! copy A into LU as it will be written to during the factorization.\n\n if ( present( threshold ) ) smallestPivot = abs( threshold )\n N = size( A, 1 )\n LU = A\n\n ! Begin the LU factorization algorithm.\n ! The status of the computation is initially successful.\n successful = .true.\n\n k = 1 ! Begin with the first column.\n do while ( ( successful ) .and. ( k <= N-1 ) )\n\n ! Verify that the kth pivot is not smaller than smallestPivot.\n successful = abs( LU( k, k ) ) >= smallestPivot\n\n if ( successful ) then\n ! Calculate the multipliers (L) for the current column.\n LU( k+1:N, k ) = LU( k+1:N, k ) / LU( k, k )\n\n ! Perform elimination on the upper portion of the matrix (U).\n do i = k+1, N\n LU( i, k+1:N ) = LU( i, k+1:N ) - LU( i, k ) * LU( k, k+1:N )\n enddo\n\n k = k + 1 ! Move to the next column.\n end if\n\n enddo\n\n ! Prepare the return value of the function.\n LUFactor = successful\n\n end function LUFactor\n\n\n ! Let A = L*U where LU represents the LU decomposition of A stored in the\n ! format produced by LUFactor, A, L, U in R**(NxN).\n ! Solve the linear system, A x = b, using the LU decomposition of A stored\n ! in LU. Since LU is the LU decomposition of A, A is nonsingular.\n ! Consequently, the columns of A constitute a basis for R**N. So, there\n ! must exist a unique solution to the linear system A x = b.\n ! LUSolve returns the solution to this linear system.\n\n function LUSolve( LU, b ) result( x )\n implicit none\n REAL*8, dimension( :, : ), intent( in ) :: LU\n REAL*8, dimension( : ), intent( in ) :: b\n REAL*8, dimension( size( b ) ) :: x\n\n integer k\n integer N\n REAL*8, dimension( size( b ) ) :: bCopy\n\n ! Determine the order of the system and store a copy of b in bCopy\n ! as it is written during the computation.\n N = size( b )\n bCopy = b\n\n ! Assume LU is in the form of LU and solve the system in two steps.\n ! First, using forward elmination to solve L y = b, then using\n ! backward elmination to solve U x = y. In both cases, the right\n ! hand side is overwritten with the solution as it is computed.\n\n ! Forward elimination. Store the solution into the right hand side.\n do k = 1, N-1\n bCopy( k+1:N ) = bCopy( k+1:N ) - bCopy( k ) * LU( k+1:N, k )\n end do\n\n ! Backward elimination. Store the solution into the right hand side.\n do k = N, 2, -1\n bCopy( k ) = bcopy( k ) / LU( k, k )\n bCopy( 1:k-1 ) = bCopy( 1:k-1 ) - bCopy( k ) * LU( 1:k-1, k )\n end do\n\n ! Solve for the 1st unknown as a special case.\n bCopy( 1 ) = bCopy( 1 ) / LU( 1, 1 )\n\n ! Assign a return value for the function via its result variable, x.\n x = bCopy\n\n end function LUSolve\n\n\n ! Output A in Matlab format, using name in the Matlab assignment statement.\n subroutine printMatrix( A, name )\n implicit none\n real*8, dimension( :, : ) :: A ! Assume the shape of A.\n character name ! Name for use in assignment, ie, name = ......\n\n integer n, m, i, j\n\n\n OPEN (OUTPUT_UNIT,file='matrixes_out.out')\n n = size( A, 1 )\n m = size( A, 2 )\n\n write(OUTPUT_UNIT, fmt=\"(a1,a5)\", advance = \"no\" ) name, ' = [ '\n\n ! Output the matrix, except for the last row, which needs no `;'.\n do i = 1, n-1\n\n ! Output current row.\n do j = 1, m-1\n write( OUTPUT_UNIT, fmt=\"(f10.6,a2)\", advance = \"no\" ) A( i, j ), ', '\n end do\n\n ! Output last element in row and end current row.\n write( OUTPUT_UNIT, fmt=\"(f10.6,a1)\" ) A( i, m ), ';'\n\n end do\n\n ! Output the last row.\n do j = 1, m-1\n write( OUTPUT_UNIT, fmt=\"(f10.6,a2)\", advance = \"no\" ) A( i, j ), ', '\n end do\n\n ! Output last element in row and end.\n write( OUTPUT_UNIT, fmt=\"(f10.6,a1)\" ) A( i, m ), ']'\n\n end subroutine printMatrix\n\n\n subroutine printMatrix_int( A, name )\n implicit none\n integer, dimension( :, : ) :: A ! Assume the shape of A.\n character name ! Name for use in assignment, ie, name = ......\n\n integer n, m, i, j\n\n n = size( A, 1 )\n m = size( A, 2 )\n OPEN (OUTPUT_UNIT,file='matrixes_out.out')\n write( OUTPUT_UNIT, fmt=\"(a1,a5)\", advance = \"no\" ) name, ' = [ '\n\n ! Output the matrix, except for the last row, which needs no `;'.\n do i = 1, n-1\n\n ! Output current row.\n do j = 1, m-1\n write( OUTPUT_UNIT, fmt=\"(I3,a2)\", advance = \"no\" ) A( i, j ), ', '\n end do\n\n ! Output last element in row and end current row.\n write( OUTPUT_UNIT, fmt=\"(I3,a2)\" ) A( i, m ), ';'\n\n end do\n\n ! Output the last row.\n do j = 1, m-1\n write( OUTPUT_UNIT, fmt=\"(I3,a2)\", advance = \"no\" ) A( i, j ), ', '\n end do\n\n ! Output last element in row and end.\n write( 7, fmt=\"(I3,a2)\" ) A( i, m ), ']'\n\n end subroutine printMatrix_int\n\n\n ! Output b in Matlab format, using name in the Matlab assignment statement.\n subroutine printVector_int( b, name )\n implicit none\n integer, dimension( : ) :: b ! Assume the shape of b.\n character name ! Name for use in assignment, ie, name = ......\n\n integer n, i\n OPEN (OUTPUT_UNIT,file='matrixes_out.out')\n n = size( b )\n\n write( OUTPUT_UNIT, fmt=\"(a1,a5)\", advance = \"no\" ) name, ' = [ '\n\n do i = 1, n-1\n write( OUTPUT_UNIT, fmt = \"(i3,a2)\", advance = \"no\" ) b( i ), ', '\n end do\n\n write( OUTPUT_UNIT, fmt = \"(i3,a2)\" ) b( n ), ']'''\n\n end subroutine printVector_int\n\n subroutine printVector( b, name )\n implicit none\n REAL*8, dimension( : ) :: b ! Assume the shape of b.\n character name ! Name for use in assignment, ie, name = ......\n\n integer n, i\n\n n = size( b )\n OPEN (OUTPUT_UNIT,file='matrixes_out.out')\n\n write( OUTPUT_UNIT, fmt=\"(a1,a5)\", advance = \"no\" ) name, ' = [ '\n\n do i = 1, n-1\n write( OUTPUT_UNIT, fmt = \"(E14.5,a2)\", advance = \"no\" ) b( i ), ', '\n end do\n\n write( OUTPUT_UNIT, fmt = \"(E14.5,a2)\" ) b( n ), ']'''\n\n end subroutine printVector\n\n\n\n SUBROUTINE SLVUNSYM(A,NRMAX,NCMAX,N,ITERM)\n!C _________________________________________________________________\n!C\n!C Solver for BANDED UNSYMMETRIC system of algebraic equations\n!C ______________________________________________________________\n!C\n IMPLICIT REAL*8 (A-H,O-Z)\n IMPLICIT INTEGER (I-N)\n INTEGER::NRMAX,NCMAX,N,ITERM\n REAL*8::A(NRMAX,NCMAX)\n CERO=1.0D-15\n PARE=CERO**2\n NBND=2*ITERM\n NBM=NBND-1\n!C\n!C Begin elimination of the lower left\n!C\n DO 80 I=1,N\n IF (DABS(A(I,ITERM)).LT.CERO) GO TO 10\n GO TO 20\n 10 IF (DABS(A(I,ITERM)).LT.PARE) GO TO 110\n 20 JLAST=MIN0(I+ITERM-1,N)\n L=ITERM+1\n DO 40 J=I,JLAST\n L=L-1\n IF (DABS(A(J,L)).LT.PARE) GO TO 40\n B=A(J,L)\n DO 30 K=L,NBND\n 30 A(J,K)=A(J,K)/B\n IF (I.EQ.N) GO TO 90\n 40 CONTINUE\n L=0\n JFIRST=I+1\n IF (JLAST.LE.I) GO TO 80\n DO 70 J=JFIRST,JLAST\n L=L+1\n IF (DABS(A(J,ITERM-L)).LT.PARE) GO TO 70\n DO 50 K=ITERM,NBM\n 50 A(J,K-L)=A(J-L,K)-A(J,K-L)\n A(J,NBND)=A(J-L,NBND)-A(J,NBND)\n IF (I.GE.N-ITERM+1) GO TO 70\n DO 60 K=1,L\n 60 A(J,NBND-K)=-A(J,NBND-K)\n 70 CONTINUE\n 80 CONTINUE\n 90 L=ITERM-1\n DO 100 I=2,N\n DO 100 J=1,L\n IF (N+1-I+J.GT.N) GO TO 100\n A(N+1-I,NBND)=A(N+1-I,NBND)-A(N+1-I+J,NBND)*A(N+1-I,ITERM+J)\n 100 CONTINUE\n RETURN\n 110 WRITE (*,140) I,A(I,ITERM)\n 140 FORMAT (/,2X,'Computation stopped in SLVUNSYM because zero appears on the main diagonal *** Eqn no. and value:',I5,E12.4)\n ENDSUBROUTINE SLVUNSYM\n\n! -------------------------- MODULE cg.f90 ----------------------------\n\n!************************************************************************\n!* *\n!* Conjugate Gradient Method (CG Method) *\n!* ------------------------------------- *\n!* *\n!* Programming language: ANSI C *\n!* Compiler: Turbo C 2.0 *\n!* Computer: IBM PS/2 70 with 80387 *\n!* Sources: [BUNS85], [SCHW], [MAES84] *\n!* Author: Juergen Dietel, Computer Center, RWTH Aachen *\n!* Date: 7.31.1992 *\n!* *\n!* F90 version by J-P Moreau (without dynamic allocations). *\n!* (www.jpmoreau.fr) *\n!************************************************************************\nSubroutine cg_method ( & ! Conjugate Gradient Method\n n, & ! Size of the linear system\n a, & ! System matrix\n y, & ! right hand side\n x, & ! solution vector\n fehler & ! error code\n )\n! original name: cg_verfahren()\ninteger::n\nreal*8, parameter :: ZERO=0.d0, MACH_EPS=2.d-16\nreal*8 a(0:n-1,0:n-1),x(0:n-1),y(0:n-1)\ninteger fehler\n!************************************************************************\n!* CG solves the linear system *\n!* A * X = Y *\n!* for a symmetric, positive definite matrix A via the conjugate *\n!* gradient method. *\n!* *\n!* Input parameters: *\n!* ================= *\n!* n Size of the linear system *\n!* a [0..n-1,0..n-1] system matrix A. Only the upper triangle of A is *\n!* used. *\n!* y [0..n-1] vector of the right hand side *\n!* *\n!* Output parameters: *\n!* ================== *\n!* x [0..n-1] vector giving the solution *\n!* *\n!* Return value: *\n!* ============= *\n!* = 0: all is ok *\n!* = 1: n < 2 or other disallowed input parameters *\n!* = 2: memory exceeded *\n!* *\n!************************************************************************\n real*8 d(0:n-1), & ! (0..n-1) auxiliary vectors d and g\n g(0:n-1), &\n AmalD(0:n-1) ! (0..n-1) auxiliary vector A * d\n real*8 alpha, & ! coefficient\n beta, & ! coefficient\n dividend, & ! numerator and denominator of a fraction\n divisor, & ! respectively, used to compute alpha, beta\n hilf, & ! auxiliary variables\n hilf2, &\n abstand, & ! distance of two successive approximations\n ! for the solution vector x (taken in the\n ! euclidean norm)\n xnorm ! euklidean norm of x\n integer k, i, j ! loop variables\n\n if (n < 2) then ! invalid parameter?\n fehler=1\n return\n end if\n\n !------------------------------------------------------------------\n ! start with x at the origin\n !------------------------------------------------------------------\n do i = n - 1, 0, -1\n x(i) = ZERO\n end do\n\n !------------------------------------------------------------------\n ! initialize d and g :\n ! d = -g = -(a*x - y) = y (since x = 0)\n !------------------------------------------------------------------\n do i = n - 1, 0, -1\n hilf = y(i)\n d(i) = hilf\n g(i) = -hilf\n end do\n\n\n !------------------------------------------------------------------\n ! perform at most n steps of the CG Method\n !------------------------------------------------------------------\n do k = n, 0, -1\n\n !----------------------------------------------------------------\n ! compute new alpha:\n ! alpha = -(d(transp) * g) / (d(transp) * (a * d))\n !----------------------------------------------------------------\n\n dividend = ZERO\n divisor = ZERO\n\n do i = n - 1, 0, -1\n dividend = dividend + d(i) * g(i)\n hilf = ZERO\n do j = 0, i-1\n hilf = hilf + a(j,i) * d(j)\n end do\n do j = i, n-1\n hilf = hilf + a(i,j) * d(j)\n end do\n AmalD(i) = hilf\n divisor = divisor + d(i) * hilf\n end do\n\n if (divisor.eq.ZERO) then\n fehler=0\n return\n end if\n\n alpha = -dividend / divisor\n\n !----------------------------------------------------------------\n ! compute the norm of x und alpha * d and find a new x:\n ! x = x + alpha * d, then check whether x is close enough,\n ! in order to stop the process before n complete steps\n !----------------------------------------------------------------\n xnorm = ZERO\n abstand = ZERO\n\n do i = n - 1, 0, -1\n hilf = x(i)\n xnorm = xnorm + hilf*hilf\n hilf2 = alpha * d(i)\n abstand = abstand + hilf2*hilf2\n x(i) = hilf + hilf2\n end do\n\n if (abstand < MACH_EPS * xnorm) then\n fehler=0\n return\n end if\n\n\n !----------------------------------------------------------------\n ! compute new g: g = g + alpha * (a * d)\n !----------------------------------------------------------------\n do i = n - 1, 0, -1\n g(i) = g(i) + alpha * AmalD(i)\n end do\n\n !----------------------------------------------------------------\n ! compute new beta :\n ! beta = (g(transp) * (a * d)) / (d(transp) * (a * d))\n !----------------------------------------------------------------\n dividend = ZERO\n do i = n - 1, 0, -1\n dividend = dividend + g(i) * AmalD(i)\n end do\n\n beta = dividend / divisor\n\n !----------------------------------------------------------------\n ! compute new d : d = - g + beta * d\n !----------------------------------------------------------------\n do i = n - 1, 0, -1\n d(i) = -g(i) + beta * d(i)\n end do\n\n end do !k loop\n\n fehler=0\n return\nendSubroutine cg_method\n\n! ---------------------------- END cg.cpp --------------------------\n\nsubroutine Gaussian_Elimination_Solver(a,y)\n integer :: k,i\n real*8::a(:,:),y(:)\n integer::n\n n=size(a,dim=1)\n\n do k = 1, n-1\n a(k+1: n, k) = a(k+1: n, k) / a(k, k)\n\n a(k+1: n, k+1: n) = a(k+1: n, k+1: n) - &\n matmul(a(k+1: n, k: k), a(k: k, k+1: n))\n end do\n\n\n ! L x = f => x = L \\ f\n do i = 1, n\n y(i) = y(i) - dot_product(a(i, 1: i-1), y(1: i-1))\n end do\n\n ! U y = x => y = U \\ x\n do i = n, 1, -1\n y(i) = y(i) - dot_product(a(i, i+1: n), y(i+1: n))\n y(i) = y(i) / a(i, i)\n end do\n\nend subroutine Gaussian_Elimination_Solver\n\n\n FUNCTION NORM_VECT(A)\n REAL*8::A(:),NORM_VECT\n NORM_VECT=SQRT(DOT_PRODUCT(A,A))\n END FUNCTION NORM_VECT\n\n\n SUBROUTINE TENSOR_TRANSFORM_RANK_1(TRANSFORMATION,TENSOR_LOCAL_COORD,TENSOR_GLOBAL_COORD)\n!-------------------------------------------------------------------\n!This will transform the tensor from local into the global coordinate\n!it used the transformation tensor to present the tensor that is\n!represented in local coordinate in the local coordinate\n!-------------------------------------------------------------------\n IMPLICIT NONE\n! ----------------------------------------------------------\n REAL*8,INTENT(IN) :: TRANSFORMATION(3,3) ! TRANSFORMATION TENSOR\n REAL*8,INTENT(IN) :: TENSOR_LOCAL_COORD(3) ! LOCAL COORDINATE TENSOR\n REAL*8,INTENT(OUT) :: TENSOR_GLOBAL_COORD(3) ! GLOBAL COORDINATE TENSOR\n INTEGER :: I,J ! The counter integers\n! ----------------------------------------------------------\n TENSOR_GLOBAL_COORD=0.0D0 !INITIALIZING TENSOR\n! ----------------------------------------------------------\n! IMPLEMENTING THE SYMMETRY\n DO I=1,3\n DO J=1,3\n TENSOR_GLOBAL_COORD(I)=TENSOR_GLOBAL_COORD(I)+TRANSFORMATION(I,J)*TENSOR_LOCAL_COORD(J)\n ENDDO;ENDDO\n ENDSUBROUTINE TENSOR_TRANSFORM_RANK_1\n!===================================================================\n!\n SUBROUTINE TENSOR_TRANSFORM_RANK_2(TRANSFORMATION,TENSOR_LOCAL_COORD,TENSOR_GLOBAL_COORD)\n!-------------------------------------------------------------------\n!This will transform the tensor from local into the global coordinate\n!it used the transformation tensor to present the tensor that is\n!represented in local coordinate in the local coordinate\n!-------------------------------------------------------------------\n IMPLICIT NONE\n! ----------------------------------------------------------\n REAL*8,INTENT(IN) :: TRANSFORMATION(3,3) ! TRANSFORMATION TENSOR\n REAL*8,INTENT(IN) :: TENSOR_LOCAL_COORD(3,3) ! LOCAL COORDINATE TENSOR\n REAL*8,INTENT(OUT) :: TENSOR_GLOBAL_COORD(3,3) ! GLOBAL COORDINATE TENSOR\n INTEGER :: I,J,K,L! The counter integers\n! ----------------------------------------------------------\n TENSOR_GLOBAL_COORD=0.0D0 !INITIALIZING TENSOR\n! ----------------------------------------------------------\n DO I=1,3\n DO J=1,3\n DO K=1,3\n DO L=1,3\n TENSOR_GLOBAL_COORD(I,J)=TENSOR_GLOBAL_COORD(I,J)+TRANSFORMATION(I,K)*TRANSFORMATION(J,L)*TENSOR_LOCAL_COORD(K,L)\n ENDDO;ENDDO;ENDDO;ENDDO\n\n ENDSUBROUTINE TENSOR_TRANSFORM_RANK_2\n\n\n!===================================================================\n SUBROUTINE ROTATION(XLOCAL,QTRANSFORM)\n!====================================================================\n ! THE PhD THESIS OF AMIR SOHRABI MOLLAYOUSEF\n ! Programmer(s):Amir Sohrabi\n ! Objective: to find the rotation tensor for a given point with respect\n ! to the origin of the problem. This transformation matrix is to be used\n ! in non linear electromechancial analysis of telescopic actoator\n!=====================================================================\n IMPLICIT NONE\n!=====================================================================\n REAL*8 :: XLOCAL(3) ! THIS IS THE COORDINATE OF THE POINT OF INTEREST\n REAL*8 :: QTRANSFORM(3,3) ! THIS IS THE TRANSFORMTION MATRIX\n REAL*8 :: RADIOUS,EUCLI_NORM ! THIS IS THE TRANSFORMTION MATRIX\n INTEGER::DIMENSIONV,INPUT_UNIT\n!=====================================================================\n INPUT_UNIT=2\n! OPEN(INPUT_UNIT,file='INPUT_UNIT.TXT')\n! READ(INPUT_UNIT,*)XLOCAL(:)\n QTRANSFORM=0.0D0\n DIMENSIONV=3\n RADIOUS=SQRT(DOT_PRODUCT(XLOCAL,XLOCAL))\n\n IF (RADIOUS>0) THEN\n QTRANSFORM(1,1)=XLOCAL(1)/RADIOUS\n QTRANSFORM(1,2)=XLOCAL(2)/RADIOUS\n QTRANSFORM(2,1)=-XLOCAL(2)/RADIOUS\n QTRANSFORM(2,2)=XLOCAL(1)/RADIOUS\n QTRANSFORM(3,3)=1\n ENDIF\n\n\n! ================================================================\n! FORMATS\n! ================================================================\n 100 FORMAT(3E14.5)\n ENDSUBROUTINE ROTATION\n\n! ===============================================================\n! TRACE OF A 3X3 TENSOR\n! ===============================================================\n\n FUNCTION TRACE(A)\n REAL*8::A(:,:),TRACE\n INTEGER::I\n TRACE=0.0D0;\n DO I=1,SIZE(A,DIM=1);TRACE=TRACE+A(I,I);ENDDO\n END FUNCTION TRACE\n\n FUNCTION MATMUL_EPZ(EPZ,ELECT)\n REAL*8::ELECT(3),EPZ(3,3,3),MATMUL_EPZ(3,3)\n INTEGER::I,J,K\n MATMUL_EPZ=0.0D0;\n DO I=1,3;\n DO J=1,3;\n DO K=1,3;\n MATMUL_EPZ(I,J)=MATMUL_EPZ(I,J)+EPZ(K,I,J)*ELECT(K)\n ENDDO;ENDDO;ENDDO\n END FUNCTION MATMUL_EPZ\n\n FUNCTION MATMUL_D_EPZ(EPZ,STRAN)\n REAL*8::MATMUL_D_EPZ(3),EPZ(3,3,3),STRAN(3,3)\n INTEGER::I,J,K\n MATMUL_D_EPZ=0.0D0;\n DO I=1,3;\n DO J=1,3;\n DO K=1,3;\n MATMUL_D_EPZ(K)=MATMUL_D_EPZ(K)+EPZ(K,I,J)*STRAN(I,J)\n ENDDO;ENDDO;ENDDO\n END FUNCTION MATMUL_D_EPZ\n\n!***********************************************************************************************************************************\n! M33INV - Compute the inverse of a 3x3 matrix.\n!\n! A = input 3x3 matrix to be inverted\n! AINV = output 3x3 inverse of matrix A\n! OK_FLAG = (output) .TRUE. if the input matrix could be inverted, and .FALSE. if the input matrix is singular.\n!***********************************************************************************************************************************\n\n SUBROUTINE M33INV (A, AINV,DET, OK_FLAG)\n\n IMPLICIT NONE\n\n DOUBLE PRECISION, DIMENSION(3,3), INTENT(IN) :: A\n DOUBLE PRECISION, DIMENSION(3,3), INTENT(OUT) :: AINV\n LOGICAL, INTENT(OUT) :: OK_FLAG\n\n DOUBLE PRECISION, PARAMETER :: EPS = 1.0D-10\n DOUBLE PRECISION :: DET\n DOUBLE PRECISION, DIMENSION(3,3) :: COFACTOR\n\n\n DET = A(1,1)*A(2,2)*A(3,3) &\n - A(1,1)*A(2,3)*A(3,2) &\n - A(1,2)*A(2,1)*A(3,3) &\n + A(1,2)*A(2,3)*A(3,1) &\n + A(1,3)*A(2,1)*A(3,2) &\n - A(1,3)*A(2,2)*A(3,1)\n\n\n IF (ABS(DET) .LE. EPS) THEN\n AINV = 0.0D0\n OK_FLAG = .FALSE.\n RETURN\n END IF\n\n COFACTOR(1,1) = +(A(2,2)*A(3,3)-A(2,3)*A(3,2))\n COFACTOR(1,2) = -(A(2,1)*A(3,3)-A(2,3)*A(3,1))\n COFACTOR(1,3) = +(A(2,1)*A(3,2)-A(2,2)*A(3,1))\n COFACTOR(2,1) = -(A(1,2)*A(3,3)-A(1,3)*A(3,2))\n COFACTOR(2,2) = +(A(1,1)*A(3,3)-A(1,3)*A(3,1))\n COFACTOR(2,3) = -(A(1,1)*A(3,2)-A(1,2)*A(3,1))\n COFACTOR(3,1) = +(A(1,2)*A(2,3)-A(1,3)*A(2,2))\n COFACTOR(3,2) = -(A(1,1)*A(2,3)-A(1,3)*A(2,1))\n COFACTOR(3,3) = +(A(1,1)*A(2,2)-A(1,2)*A(2,1))\n\n AINV = TRANSPOSE(COFACTOR) / DET\n OK_FLAG = .TRUE.\n\n RETURN\n\n END SUBROUTINE M33INV\n\n! ================================================================\n! NORM OF A VECTOR\n! ================================================================\n FUNCTION NORM_MATRIX(A)\n INTEGER::I,J\n REAL*8::A(:,:),NORM_MATRIX\n\n\n NORM_MATRIX=0.0D0\n DO I=1,SIZE(A,DIM=1);DO J=1,SIZE(A,DIM=2);\n NORM_MATRIX=NORM_MATRIX+A(I,J)*A(I,J)\n ENDDO;ENDDO\n\n\n END FUNCTION NORM_MATRIX\n\n! ================================================================\n! MACAULAY BRACKETS\n! ================================================================\n FUNCTION MACAULAY(A)\n INTEGER::MACAULAY\n REAL*8::A\n MACAULAY=0\n IF (A>=0)THEN\n MACAULAY=1\n ENDIF\n END FUNCTION MACAULAY\n\n\n! ================================================================\n! UNIT VECTOR IN THE DIRECTION OF A VECTOR\n! ================================================================\n FUNCTION UNIT_VECT(A)\n REAL*8::A(:)\n REAL*8,ALLOCATABLE :: UNIT_VECT(:)\n\n ALLOCATE(UNIT_VECT(SIZE(A)))\n UNIT_VECT=0.0D0\n\n UNIT_VECT=A/NORM_VECT(A)\n\n IF(NORM_VECT(A).EQ.0)UNIT_VECT=0.0D0\n\n\n END FUNCTION UNIT_VECT\n\n\n\n subroutine elapsedtime (END_STAMP_V,START_STAMP_V)\n integer ( kind = 4 )START_STAMP_V(8),END_STAMP_V(8),values(8),SECONDS,MINUTES,HOURS,MILISECONDS,START_STAMP,END_STAMP,ELAPSED_TIME\n\n MILISECONDS=mod(END_STAMP_V(8)-START_STAMP_V(8),100)\n SECONDS=mod(END_STAMP_V(7)-START_STAMP_V(7),60)\n MINUTES=mod(END_STAMP_V(6)-START_STAMP_V(6),60)\n HOURS=END_STAMP_V(5)-START_STAMP_V(5)\n write ( *,'(1X,a,2x,i2,a1,i4.4,a1,i4.4,a1,i4.4)' )'Elapsed Time=', HOURS,':',MINUTES,':',SECONDS,'.',ABS(MILISECONDS)\n endsubroutine elapsedtime\n\n\nsubroutine timestamp ( )\n\n!*****************************************************************************80\n!\n!! TIMESTAMP prints the current YMDHMS date as a time stamp.\n!\n! Example:\n!\n! May 31 2001 9:45:54.872 AM\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 26 February 2005\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! None\n!\n implicit none\n\n character ( len = 8 ) ampm\n integer d\n integer h\n integer m\n integer mm\n character ( len = 9 ), parameter, dimension(12) :: month = (/ &\n 'January ', 'February ', 'March ', 'April ', &\n 'May ', 'June ', 'July ', 'August ', &\n 'September', 'October ', 'November ', 'December ' /)\n integer n\n integer s\n integer values(8)\n integer y\n\n call date_and_time ( values = values )\n\n y = values(1)\n m = values(2)\n d = values(3)\n h = values(5)\n n = values(6)\n s = values(7)\n mm = values(8)\n\n if ( h < 12 ) then\n ampm = 'AM'\n else if ( h == 12 ) then\n if ( n == 0 .and. s == 0 ) then\n ampm = 'Noon'\n else\n ampm = 'PM'\n end if\n else\n h = h - 12\n if ( h < 12 ) then\n ampm = 'PM'\n else if ( h == 12 ) then\n if ( n == 0 .and. s == 0 ) then\n ampm = 'Midnight'\n else\n ampm = 'AM'\n end if\n end if\n end if\n\n write ( *, '(a,1x,i2,1x,i4,2x,i2,a1,i2.2,a1,i2.2,a1,i3.3,1x,a)' ) &\n trim ( month(m) ), d, y, h, ':', n, ':', s, '.', mm, trim ( ampm )\n\n return\nend\n\n end module linearsolvers\n", "meta": {"hexsha": "3c9da85f796d03706cae581cb0896db604afcc45", "size": 36918, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "driver/linearsolvers.f90", "max_stars_repo_name": "amirsmol/finite_element_method_1D_piezoe_electric", "max_stars_repo_head_hexsha": "b32a1656b5d8d460db41c08fbcb337153cc442f5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "driver/linearsolvers.f90", "max_issues_repo_name": "amirsmol/finite_element_method_1D_piezoe_electric", "max_issues_repo_head_hexsha": "b32a1656b5d8d460db41c08fbcb337153cc442f5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "driver/linearsolvers.f90", "max_forks_repo_name": "amirsmol/finite_element_method_1D_piezoe_electric", "max_forks_repo_head_hexsha": "b32a1656b5d8d460db41c08fbcb337153cc442f5", "max_forks_repo_licenses": ["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.2894499549, "max_line_length": 136, "alphanum_fraction": 0.5015439623, "num_tokens": 10330, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232489352, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.6977176625555706}} {"text": "a = reshape ((/(i * i, i = 1, 100)/), (/10, 10/))\n", "meta": {"hexsha": "460e776ef45a0a28319a62a12c5e5cf46f91d8ab", "size": 50, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Arrays/Fortran/arrays-25.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/Arrays/Fortran/arrays-25.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/Arrays/Fortran/arrays-25.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 25.0, "max_line_length": 49, "alphanum_fraction": 0.38, "num_tokens": 25, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.863391602943619, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.6976784527816297}} {"text": "** Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.\n** See https://llvm.org/LICENSE.txt for license information.\n** SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception\n\n* Intrinsics & generics - MOD, SIGN, DIM, DPROD.\n\n\tprogram p\n\tparameter (n = 32)\n\tinteger rslts(n), expect(n)\n\tdouble precision d2, dn5\n\n\tdata i0, i2, i5, i19, i7 / 0, 2, 5, 19, 7 /\n\tdata x2, x4, x7 / 2.0, 4.0, 7.0 /\n\tdata d2, dn5 / 2.0d0, -5.0d0 /\n\nc --- tests 1 - 5: INTEGER MOD operation:\n\n\trslts(1) = mod('7fffffff'x, 2)\n\trslts(2) = mod('7ffffffe'x, i2)\n\trslts(3) = mod(i2, i2) + mod(i19, 5) + mod(0, i19)\n\trslts(4) = i2 * mod(i0, i19+7) + (i19 - mod(i19, i2))\n\trslts(5) = mod(-7, 5) + mod(-i7, 2 * i2 + 1)\n\nc --- tests 6 - 10: REAL MOD operation:\n\n\trslts(6) = mod(4.0, 2.0) - mod(-x4, x2)\n\trslts(7) = amod(x2, x2+x2)\n\trslts(8) = ifix( amod(x7, x4) )\n\trslts(9) = amod(2.341, float(2)) * 100\n\trslts(10) = 100 * mod(2.341, float(i2))\n\nc --- tests 11 - 13: DOUBLE PRECISION MOD operation:\n\n\trslts(11) = idint(dmod(5.0d0, 2.0d0))\n\trslts(12) = idint( mod(dn5, -d2) )\n\trslts(13) = dn5 + dmod(d2, d2)\n\nc --- tests 14 - 17: INTEGER SIGN operation:\n\n\trslts(14) = isign(3, 4) + isign(-8, -1)\n\trslts(15) = sign(99, 0) + sign(-6, 1)\n\trslts(sign(16, i2)) = isign(i2, 1)\n\trslts(17) = isign(-i2, i19*i2) * sign(i19, -i2)\n\nc --- tests 18 - 22: REAL and DOUBLE PRECISION SIGN operation:\n\n\trslts(18) = sign(2.0, 4.0) + sign(8.0, -1.0)\n\trslts(19) = sign(x7, -x4) * sign(x2*x2, x4)\n\n\trslts(20) = idint( dsign(2.0d0, -1.0d0) )\n\trslts(21) = idint( sign(dn5, d2 - d2) )\n\trslts(22) = 0\n\nc --- tests 23 - 29: DIM operation:\n\n\trslts(23) = idim(i5, i2) + i19\n\trslts(24) = dim(i2, i5) * i5\n\trslts(25) = dim(i5*i2, i2 + i2)\n\n\trslts(26) = dim(x7, x4)\n\trslts(27) = 2.0 + dim(x4, x4+x4)\n\n\trslts(28) = idint( ddim(dn5, d2) )\n\trslts(29) = idint( dim(3.0d0, dn5 * 2.0) + 1)\n\nc --- tests 30 - 32: DPROD operation:\n\n\trslts(30) = idint(dprod(x2, x2))\n\trslts(31) = dprod(-3.0, 2.0)\n\trslts(32) = dprod(x2*x2, x4+x4)\n\nc --- check results:\n\n\tcall check(rslts, expect, n)\n\n\tdata expect / 1, 0, 4, 18, -4,\n + 0, 2, 3, 34, 34,\n + 1, -1, -5,\n + -5, 105, 2, -38, \nc tests 18 - 22:\n + -6, -28, -2, 5, 0,\nc tests 23 - 29:\n + 22, 0, 6, 3, 2, 0, 14,\n + 4, -6, 32 /\n\tend\n", "meta": {"hexsha": "cade9f02b8dd213dd69827dc2ed79eebaf3ee603", "size": 2372, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "test/f90_correct/src/fc10.f", "max_stars_repo_name": "abrahamtovarmob/flang", "max_stars_repo_head_hexsha": "bcd84b29df046b6d6574f0bfa34ea5059092615a", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 716, "max_stars_repo_stars_event_min_datetime": "2017-05-17T17:58:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T11:20:58.000Z", "max_issues_repo_path": "test/f90_correct/src/fc10.f", "max_issues_repo_name": "abrahamtovarmob/flang", "max_issues_repo_head_hexsha": "bcd84b29df046b6d6574f0bfa34ea5059092615a", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 794, "max_issues_repo_issues_event_min_datetime": "2017-05-18T19:27:40.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T23:22:11.000Z", "max_forks_repo_path": "test/f90_correct/src/fc10.f", "max_forks_repo_name": "abrahamtovarmob/flang", "max_forks_repo_head_hexsha": "bcd84b29df046b6d6574f0bfa34ea5059092615a", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 157, "max_forks_repo_forks_event_min_datetime": "2017-05-17T18:50:33.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T07:06:45.000Z", "avg_line_length": 27.5813953488, "max_line_length": 80, "alphanum_fraction": 0.5387858347, "num_tokens": 1118, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772482857834, "lm_q2_score": 0.7981867873410141, "lm_q1q2_score": 0.6976769106971034}} {"text": "*DECK SGECO\n SUBROUTINE SGECO (A, LDA, N, IPVT, RCOND, Z)\nC***BEGIN PROLOGUE SGECO\nC***PURPOSE Factor a matrix using Gaussian elimination and estimate\nC the condition number of the matrix.\nC***LIBRARY SLATEC (LINPACK)\nC***CATEGORY D2A1\nC***TYPE SINGLE PRECISION (SGECO-S, DGECO-D, CGECO-C)\nC***KEYWORDS CONDITION NUMBER, GENERAL MATRIX, LINEAR ALGEBRA, LINPACK,\nC MATRIX FACTORIZATION\nC***AUTHOR Moler, C. B., (U. of New Mexico)\nC***DESCRIPTION\nC\nC SGECO factors a real matrix by Gaussian elimination\nC and estimates the condition of the matrix.\nC\nC If RCOND is not needed, SGEFA is slightly faster.\nC To solve A*X = B , follow SGECO by SGESL.\nC To compute INVERSE(A)*C , follow SGECO by SGESL.\nC To compute DETERMINANT(A) , follow SGECO by SGEDI.\nC To compute INVERSE(A) , follow SGECO by SGEDI.\nC\nC On Entry\nC\nC A REAL(LDA, N)\nC the matrix to be factored.\nC\nC LDA INTEGER\nC the leading dimension of the array A .\nC\nC N INTEGER\nC the order of the matrix A .\nC\nC On Return\nC\nC A an upper triangular matrix and the multipliers\nC which were used to obtain it.\nC The factorization can be written A = L*U , where\nC L is a product of permutation and unit lower\nC triangular matrices and U is upper triangular.\nC\nC IPVT INTEGER(N)\nC an integer vector of pivot indices.\nC\nC RCOND REAL\nC an estimate of the reciprocal condition of A .\nC For the system A*X = B , relative perturbations\nC in A and B of size EPSILON may cause\nC relative perturbations in X of size EPSILON/RCOND .\nC If RCOND is so small that the logical expression\nC 1.0 + RCOND .EQ. 1.0\nC is true, then A may be singular to working\nC precision. In particular, RCOND is zero if\nC exact singularity is detected or the estimate\nC underflows.\nC\nC Z REAL(N)\nC a work vector whose contents are usually unimportant.\nC If A is close to a singular matrix, then Z is\nC an approximate null vector in the sense that\nC NORM(A*Z) = RCOND*NORM(A)*NORM(Z) .\nC\nC***REFERENCES J. J. Dongarra, J. R. Bunch, C. B. Moler, and G. W.\nC Stewart, LINPACK Users' Guide, SIAM, 1979.\nC***ROUTINES CALLED SASUM, SAXPY, SDOT, SGEFA, SSCAL\nC***REVISION HISTORY (YYMMDD)\nC 780814 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890831 Modified array declarations. (WRB)\nC 890831 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900326 Removed duplicate information from DESCRIPTION section.\nC (WRB)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE SGECO\n INTEGER LDA,N,IPVT(*)\n REAL A(LDA,*),Z(*)\n REAL RCOND\nC\n REAL SDOT,EK,T,WK,WKM\n REAL ANORM,S,SASUM,SM,YNORM\n INTEGER INFO,J,K,KB,KP1,L\nC\nC COMPUTE 1-NORM OF A\nC\nC***FIRST EXECUTABLE STATEMENT SGECO\n ANORM = 0.0E0\n DO 10 J = 1, N\n ANORM = MAX(ANORM,SASUM(N,A(1,J),1))\n 10 CONTINUE\nC\nC FACTOR\nC\n CALL SGEFA(A,LDA,N,IPVT,INFO)\nC\nC RCOND = 1/(NORM(A)*(ESTIMATE OF NORM(INVERSE(A)))) .\nC ESTIMATE = NORM(Z)/NORM(Y) WHERE A*Z = Y AND TRANS(A)*Y = E .\nC TRANS(A) IS THE TRANSPOSE OF A . THE COMPONENTS OF E ARE\nC CHOSEN TO CAUSE MAXIMUM LOCAL GROWTH IN THE ELEMENTS OF W WHERE\nC TRANS(U)*W = E . THE VECTORS ARE FREQUENTLY RESCALED TO AVOID\nC OVERFLOW.\nC\nC SOLVE TRANS(U)*W = E\nC\n EK = 1.0E0\n DO 20 J = 1, N\n Z(J) = 0.0E0\n 20 CONTINUE\n DO 100 K = 1, N\n IF (Z(K) .NE. 0.0E0) EK = SIGN(EK,-Z(K))\n IF (ABS(EK-Z(K)) .LE. ABS(A(K,K))) GO TO 30\n S = ABS(A(K,K))/ABS(EK-Z(K))\n CALL SSCAL(N,S,Z,1)\n EK = S*EK\n 30 CONTINUE\n WK = EK - Z(K)\n WKM = -EK - Z(K)\n S = ABS(WK)\n SM = ABS(WKM)\n IF (A(K,K) .EQ. 0.0E0) GO TO 40\n WK = WK/A(K,K)\n WKM = WKM/A(K,K)\n GO TO 50\n 40 CONTINUE\n WK = 1.0E0\n WKM = 1.0E0\n 50 CONTINUE\n KP1 = K + 1\n IF (KP1 .GT. N) GO TO 90\n DO 60 J = KP1, N\n SM = SM + ABS(Z(J)+WKM*A(K,J))\n Z(J) = Z(J) + WK*A(K,J)\n S = S + ABS(Z(J))\n 60 CONTINUE\n IF (S .GE. SM) GO TO 80\n T = WKM - WK\n WK = WKM\n DO 70 J = KP1, N\n Z(J) = Z(J) + T*A(K,J)\n 70 CONTINUE\n 80 CONTINUE\n 90 CONTINUE\n Z(K) = WK\n 100 CONTINUE\n S = 1.0E0/SASUM(N,Z,1)\n CALL SSCAL(N,S,Z,1)\nC\nC SOLVE TRANS(L)*Y = W\nC\n DO 120 KB = 1, N\n K = N + 1 - KB\n IF (K .LT. N) Z(K) = Z(K) + SDOT(N-K,A(K+1,K),1,Z(K+1),1)\n IF (ABS(Z(K)) .LE. 1.0E0) GO TO 110\n S = 1.0E0/ABS(Z(K))\n CALL SSCAL(N,S,Z,1)\n 110 CONTINUE\n L = IPVT(K)\n T = Z(L)\n Z(L) = Z(K)\n Z(K) = T\n 120 CONTINUE\n S = 1.0E0/SASUM(N,Z,1)\n CALL SSCAL(N,S,Z,1)\nC\n YNORM = 1.0E0\nC\nC SOLVE L*V = Y\nC\n DO 140 K = 1, N\n L = IPVT(K)\n T = Z(L)\n Z(L) = Z(K)\n Z(K) = T\n IF (K .LT. N) CALL SAXPY(N-K,T,A(K+1,K),1,Z(K+1),1)\n IF (ABS(Z(K)) .LE. 1.0E0) GO TO 130\n S = 1.0E0/ABS(Z(K))\n CALL SSCAL(N,S,Z,1)\n YNORM = S*YNORM\n 130 CONTINUE\n 140 CONTINUE\n S = 1.0E0/SASUM(N,Z,1)\n CALL SSCAL(N,S,Z,1)\n YNORM = S*YNORM\nC\nC SOLVE U*Z = V\nC\n DO 160 KB = 1, N\n K = N + 1 - KB\n IF (ABS(Z(K)) .LE. ABS(A(K,K))) GO TO 150\n S = ABS(A(K,K))/ABS(Z(K))\n CALL SSCAL(N,S,Z,1)\n YNORM = S*YNORM\n 150 CONTINUE\n IF (A(K,K) .NE. 0.0E0) Z(K) = Z(K)/A(K,K)\n IF (A(K,K) .EQ. 0.0E0) Z(K) = 1.0E0\n T = -Z(K)\n CALL SAXPY(K-1,T,A(1,K),1,Z(1),1)\n 160 CONTINUE\nC MAKE ZNORM = 1.0\n S = 1.0E0/SASUM(N,Z,1)\n CALL SSCAL(N,S,Z,1)\n YNORM = S*YNORM\nC\n IF (ANORM .NE. 0.0E0) RCOND = YNORM/ANORM\n IF (ANORM .EQ. 0.0E0) RCOND = 0.0E0\n RETURN\n END\n", "meta": {"hexsha": "ded72fe4dbb96318ebf4804067694d78b9740f16", "size": 6471, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/sgeco.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/sgeco.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/sgeco.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.1105769231, "max_line_length": 72, "alphanum_fraction": 0.5155308299, "num_tokens": 2308, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772318846386, "lm_q2_score": 0.798186787341014, "lm_q1q2_score": 0.6976768976059262}} {"text": "c program DRDEVUN\nc>> 1994-10-19 DRDEVUN Krogh Changes to use M77CON\nc>> 1992-04-23 DRDEVUN CLL Declaring all variables.\nc>> 1992-03-04 DRDEVUN Krogh Initial version.\nc Demonstrate unsymmetric eigenvalue subroutine DEVUN.\nc ------------------------------------------------------------------\nc--D replaces \"?\": DR?EVUN, ?EVUN, ?VECP\nc ------------------------------------------------------------------\n integer I, KASE, LDA, N\n parameter (LDA = 3)\n integer IFLAG(LDA)\n double precision A(LDA,LDA,3), VR(LDA), VI(LDA)\nc\n data (A(1,I,1), I=1,3) / -954.0d0, -464.0d0, -2088.0d0 /\n data (A(2,I,1), I=1,3) / 792.0d0, 387.0d0, 1728.0d0 /\n data (A(3,I,1), I=1,3) / 264.0d0, 128.0d0, 579.0d0 /\nc\n data (A(1,I,2), I=1,3) / 4.0d0, 1.0d0, 1.0d0 /\n data (A(2,I,2), I=1,3) / 2.0d0, 4.0d0, 1.0d0 /\n data (A(3,I,2), I=1,3) / 0.0d0, 1.0d0, 4.0d0 /\nc\n data (A(1,I,3), I=1,3) / 8.0d0, -1.0d0, -5.0d0 /\n data (A(2,I,3), I=1,3) / -4.0d0, 4.0d0, -2.0d0 /\n data (A(3,I,3), I=1,3) / 18.0d0, -5.0d0, -7.0d0 /\n data N / LDA /\nc ------------------------------------------------------------------\n print*,'DRDEVUN.. Demo driver for DEVUN.'\n do 10 KASE = 1, 3\n print '(/a,i2)',' Beginning Case =', KASE\n call DEVUN(A(1, 1, KASE), LDA, N, VR, VI, IFLAG)\n print '(a,i2)',' IFLAG(1) =', IFLAG(1)\n if (IFLAG(1) .le. 2) then\n call DVECP(VR, N, ' Real part of the eigenvalues')\n call DVECP(VI, N, ' Imaginary part of the eigenvalues')\n else\n print '(/a)',' Failure in DEVUN.'\n end if\n 10 continue\n stop\n end\n", "meta": {"hexsha": "1778d0747073c4cc2c46876099ce4dc08ff8ba92", "size": 1682, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drdevun.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drdevun.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drdevun.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 41.0243902439, "max_line_length": 72, "alphanum_fraction": 0.4589774078, "num_tokens": 693, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648677, "lm_q2_score": 0.7981867825403176, "lm_q1q2_score": 0.6976768960279823}} {"text": "c fishpk33 from portlib 12/30/83\nc\nc * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nc * *\nc * f i s h p a k *\nc * *\nc * *\nc * a package of fortran subprograms for the solution of *\nc * *\nc * separable elliptic partial differential equations *\nc * *\nc * (version 3.1 , october 1980) *\nc * *\nc * by *\nc * *\nc * john adams, paul swarztrauber and roland sweet *\nc * *\nc * of *\nc * *\nc * the national center for atmospheric research *\nc * *\nc * boulder, colorado (80307) u.s.a. *\nc * *\nc * which is sponsored by *\nc * *\nc * the national science foundation *\nc * *\nc * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nc\nc program to illustrate the use of hstssp to solve poisson\"s\nc equation\nc\nc (1/sin(theta))(d/dtheta)(sin(theta)*du/dtheta) +\nc\nc (1/sin(theta)**2)(d/dphi)(du/dphi) = 2 - 6*(sin(theta)*sin(phi))**2\nc on the northern hemisphere subject to equatorial symmetry, i.e.\nc the derivative of the solution at theta = pi/2 is zero. a\nc 5-degree grid is to be used.\nc\nc the exact solution is not unique. any function of the form\nc\nc u(theta,phi) = (sin(theta)*sin(phi))**2 + constant\nc\nc is a solution.\nc\n program thstssp\n dimension f(18,72) ,bdb(72) ,sint(18) ,sinp(72) ,\n 1 w(630)\n dimension bda(1), bdc(1), bdd(1)\nc\nc the value of idimf is the first dimension of f. w is dimensioned\nc (13 + int(log2(n)))*m + 4*n\nc\n pi = pimach(dum)\n a = 0.\n b = pi/2.\n m = 18\n mbdcnd = 6\n c = 0.\n d = 2.*pi\n n = 72\n nbdcnd = 0\n elmbda = 0.\n idimf = 18\nc\nc generate sines for use in subsequent computations\nc\n dtheta = b/float(m)\n do 101 i=1,m\n sint(i) = sin((float(i)-0.5)*dtheta)\n 101 continue\n dphi = d/float(n)\n do 102 j=1,n\n sinp(j) = sin((float(j)-0.5)*dphi)\n 102 continue\nc\nc compute right side of equation and store in f\nc\n do 104 j=1,n\n do 103 i=1,m\n f(i,j) = 2.-6.*(sint(i)*sinp(j))**2\n 103 continue\n 104 continue\nc\nc store derivative data at the equator\nc\n do 105 j=1,n\n bdb(j) = 0.\n 105 continue\nc\nc bda, bdc, and bdd are dummy variables.\nc\n call hstssp (a,b,m,mbdcnd,bda,bdb,c,d,n,nbdcnd,bdc,bdd,elmbda,f,\n 1 idimf,pertrb,ierror,w)\nc\nc compute discretization error. since problem is singular, the\nc solution must be normalized.\nc\n err = 0.\n do 107 j=1,n\n do 106 i=1,m\n z = abs(f(i,j)-(sint(i)*sinp(j))**2-f(1,1))\n if (z .gt. err) err = z\n 106 continue\n 107 continue\nc\n print 1001 , ierror,pertrb,err,w(1)\n stop\nc\n 1001 format (1h1,20x,25hsubroutine hstssp example///\n 1 10x,46hthe output from the ncar control data 7600 was//\n 2 32x,10hierror = 0/32x,20hpertrb = 6.35830e-04/\n 3 18x,34hdiscretization error = 3.37523e-03/\n 4 12x,32hrequired length of w array = 540//\n 5 10x,32hthe output from your computer is//\n 6 32x,8hierror =,i2/32x,8hpertrb =,e12.5/\n 7 18x,22hdiscretization error =,e12.5/\n 8 12x,28hrequired length of w array =,f4.0)\nc\n end\nc solution must be normalized.\n", "meta": {"hexsha": "89688677abe78e7ee4ad48241ec39529b95922f7", "size": 4553, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/f2cl/packages/fishpack/ex/tsthstssp.f", "max_stars_repo_name": "sbwhitecap/clocc-hg", "max_stars_repo_head_hexsha": "f6cf2591ceef8a3a80e04da9b414cdf60a25a90f", "max_stars_repo_licenses": ["MIT"], "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/f2cl/packages/fishpack/ex/tsthstssp.f", "max_issues_repo_name": "sbwhitecap/clocc-hg", "max_issues_repo_head_hexsha": "f6cf2591ceef8a3a80e04da9b414cdf60a25a90f", "max_issues_repo_licenses": ["MIT"], "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/f2cl/packages/fishpack/ex/tsthstssp.f", "max_forks_repo_name": "sbwhitecap/clocc-hg", "max_forks_repo_head_hexsha": "f6cf2591ceef8a3a80e04da9b414cdf60a25a90f", "max_forks_repo_licenses": ["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.3196721311, "max_line_length": 72, "alphanum_fraction": 0.394025917, "num_tokens": 1272, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772417253256, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.697676892872094}} {"text": "\n!!# FUNCTION MODULE: \nMODULE FUN_FactorialInt\n\n!!## PURPOSE\n!! Defines function FactorialInt(k) which returns a integer for integer k.\n!! If the factorial is beyond the range of the integer k then 0 is returned.\n\n!!## DETAILS\n!! @ The kind of FactorialInt(k) is equal to the kind of k.\n!! @ A check is made to make sure k has a factorial that is less than HUGE(k).\n\n!!## EXTERNAL KINDS\nUSE KND_IntrinsicTypes,ONLY: KIND_I1,KIND_I2,KIND_I4,KIND_I8 !!((01-A-KND_IntrinsicTypes.f90))\n\n!!## GLOBAL PROCEDURE\nUSE FUN_Error !!((04-A-FUN_Error.f90))\n\n!!## DEFAULT IMPLICIT\nIMPLICIT NONE\n\n!!## DEFAULT ACCESS\nPRIVATE\n\n!! @ maximum integer-only factorial\nINTEGER(KIND_I1),PARAMETER :: MAX_I1 = 5_KIND_I1 !maximum integer factorial for INTEGER(1)\nINTEGER(KIND_I2),PARAMETER :: MAX_I2 = 7_KIND_I2 !maximum integer factorial for INTEGER(2)\nINTEGER(KIND_I4),PARAMETER :: MAX_I4 = 13_KIND_I4 !maximum integer factorial for INTEGER(4)\nINTEGER(KIND_I8),PARAMETER :: MAX_I8 = 20_KIND_I8 !maximum integer factorial for INTEGER(8)\nPUBLIC :: MAX_I1,MAX_I2,MAX_I4,MAX_I8\n\n!!## FUNCTION OVERLOADING\nINTERFACE FactorialInt\n MODULE PROCEDURE FactorialInt_I1\n MODULE PROCEDURE FactorialInt_I2\n MODULE PROCEDURE FactorialInt_I4\n MODULE PROCEDURE FactorialInt_I8\nEND INTERFACE\n\n!!## PUBLIC ACCESS\nPUBLIC :: FactorialInt\n\n!!## CONTAINED PROCEDURES\nCONTAINS\n\n\nPURE ELEMENTAL FUNCTION FactorialInt_I1( x ) RESULT(y)\nUSE KND_IntrinsicTypes,ONLY: KIND_I=>KIND_I1 !!((01-A-KND_IntrinsicTypes.f90))\nINTEGER(KIND_I),PARAMETER :: MAX = MAX_I1\nINCLUDE \"05-B-FUN_FactorialInt.f90.hdr\"\n!!--begin--\nINCLUDE \"05-B-FUN_FactorialInt.f90.bdy\"\n!!--end--\nENDFUNCTION\n\n\nPURE ELEMENTAL FUNCTION FactorialInt_I2( x ) RESULT(y)\nUSE KND_IntrinsicTypes,ONLY: KIND_I=>KIND_I2 !!((01-A-KND_IntrinsicTypes.f90))\nINTEGER(KIND_I),PARAMETER :: MAX = MAX_I2\nINCLUDE \"05-B-FUN_FactorialInt.f90.hdr\"\n!!--begin--\nINCLUDE \"05-B-FUN_FactorialInt.f90.bdy\"\n!!--end--\nENDFUNCTION\n\n\nPURE ELEMENTAL FUNCTION FactorialInt_I4( x ) RESULT(y)\nUSE KND_IntrinsicTypes,ONLY: KIND_I=>KIND_I4 !!((01-A-KND_IntrinsicTypes.f90))\nINTEGER(KIND_I),PARAMETER :: MAX = MAX_I4\nINCLUDE \"05-B-FUN_FactorialInt.f90.hdr\"\n!!--begin--\nINCLUDE \"05-B-FUN_FactorialInt.f90.bdy\"\n!!--end--\nENDFUNCTION\n\n\nPURE ELEMENTAL FUNCTION FactorialInt_I8( x ) RESULT(y)\nUSE KND_IntrinsicTypes,ONLY: KIND_I=>KIND_I8 !!((01-A-KND_IntrinsicTypes.f90))\nINTEGER(KIND_I),PARAMETER :: MAX = MAX_I8\nINCLUDE \"05-B-FUN_FactorialInt.f90.hdr\"\n!!--begin--\nINCLUDE \"05-B-FUN_FactorialInt.f90.bdy\"\n!!--end--\nENDFUNCTION\n\n\nENDMODULE\n", "meta": {"hexsha": "1aefab7d57fb092314d277794d20a31f9552c4fb", "size": 2641, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/05-B-FUN_FactorialInt.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/05-B-FUN_FactorialInt.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/05-B-FUN_FactorialInt.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.0113636364, "max_line_length": 94, "alphanum_fraction": 0.7281332828, "num_tokens": 787, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118111485244, "lm_q2_score": 0.843895106480586, "lm_q1q2_score": 0.697658051897942}} {"text": "MODULE multidim_arrays\n\n IMPLICIT NONE\n\nCONTAINS\n\n FUNCTION inner_prod(n,a,b) RESULT(y)\n INTEGER, INTENT(in) :: n\n INTEGER, INTENT(in), dimension(n) :: a, b\n INTEGER :: y\n y = DOT_PRODUCT(a,b)\n END FUNCTION inner_prod\n\n ! Test assumed size\n FUNCTION inner_prod_2(n,a,b) RESULT(y)\n INTEGER, INTENT(in) :: n\n INTEGER, INTENT(in), DIMENSION(*) :: a\n INTEGER, INTENT(in) :: b(*)\n INTEGER :: y\n y = DOT_PRODUCT(a(1:n),b(1:n))\n END FUNCTION inner_prod_2\n\n SUBROUTINE mat_vec_mult(m,n,A,b,Ab)\n INTEGER, INTENT(in) :: m,n, b(n)\n INTEGER, INTENT(in), DIMENSION(m,n) :: A\n INTEGER, INTENT(out) :: Ab(m)\n Ab = MATMUL(A,b)\n END SUBROUTINE mat_vec_mult\n\n SUBROUTINE three_d_array_test(A)\n INTEGER, INTENT(out) :: A(4,3,2)\n\n INTEGER :: i,j,k\n DO k=1,2\n DO j=1,3\n DO i=1,4\n A(i,j,k) = (i+j)**k\n END DO\n END DO\n END DO\n END SUBROUTINE three_d_array_test\n\nEND MODULE multidim_arrays\n", "meta": {"hexsha": "b2c92ff2a6138ef47c73825a7cd0bb8e8a929140", "size": 960, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/multidim_arrays/multidim_arrays.f90", "max_stars_repo_name": "mcfarljm/fortwrap", "max_stars_repo_head_hexsha": "e82840a2b8d105cc3655da33dbf4b2073fa462d8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2017-06-05T01:54:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-04T02:50:13.000Z", "max_issues_repo_path": "tests/multidim_arrays/multidim_arrays.f90", "max_issues_repo_name": "mcfarljm/fortwrap", "max_issues_repo_head_hexsha": "e82840a2b8d105cc3655da33dbf4b2073fa462d8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-09-18T15:31:38.000Z", "max_issues_repo_issues_event_max_datetime": "2019-09-19T02:45:38.000Z", "max_forks_repo_path": "tests/multidim_arrays/multidim_arrays.f90", "max_forks_repo_name": "mcfarljm/fortwrap", "max_forks_repo_head_hexsha": "e82840a2b8d105cc3655da33dbf4b2073fa462d8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2017-12-03T05:35:58.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-20T00:12:30.000Z", "avg_line_length": 21.8181818182, "max_line_length": 45, "alphanum_fraction": 0.609375, "num_tokens": 319, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951025545426, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.6976580378432996}} {"text": "module mod_numerical\r\n !=========================================================================!\r\n ! Written by Alessandro Di Nola \r\n ! Main sources:\r\n ! https://github.com/drarnau/Replication_Krusell-et-al-2017/blob/master/Utils.f90\r\n ! https://sites.google.com/site/greygordon/code\r\n ! Numerical recipes in F90: http://numerical.recipes/\r\n ! http://karibzhanov.com/\r\n ! Giulio Fella: https://github.com/gfell\r\n\t! Fabian Kindermann: https://www.ce-fortran.com/\r\n ! Date Programmer Description of change\r\n\t! ==== ========== =====================\r\n\t! 20210817 A. Di Nola Original code\r\n\t! 20210818 A. Di Nola Changed lrzcurve\r\n\t! 20210830 A. Di Nola Added function gini\r\n\t! 20210901 A. Di Nola Added function ind2sub \r\n !=========================================================================!\r\n \r\n ! USE other modules \r\n implicit none\r\n \r\n private !Variables and internal proc are not visible outside of this module \r\n \r\n ! User-defined error function\r\n public :: myerror\r\n \r\n ! Replicate basic Matlab functions\r\n public :: linspace\r\n public :: ones, eye, cumsum, cumprod\r\n public :: outerprod\r\n public :: ind2sub\r\n \r\n ! Sorting subroutines\r\n public :: QsortC\r\n \r\n ! General-purpose routines\r\n public :: is_monotone, my_closest, grid, mycorr\r\n \r\n ! Markov chain:\r\n public :: my_ss\r\n \r\n ! Interpolation:\r\n public :: linint, locate\r\n \r\n ! Discretization:\r\n public :: discretize_pareto, bddparetocdf, tauchen\r\n \r\n ! Percentiles, Gini and Lorenz curve:\r\n public :: quantili, calculate_quintiles, lrzcurve_basic, lrzcurve, unique, gini\r\n \r\n ! Optimization:\r\n public :: golden_method !similar to fminbnd in Matlab\r\n \r\n ! Root-finding:\r\n public :: rtbis, zbrent !similar to fzero in Matlab\r\n \r\n \r\ncontains\r\n \r\n subroutine myerror(string)\r\n\r\n implicit none\r\n character(len=*), intent(in) :: string\r\n write(*,*) \"ERROR: \", string\r\n write(*,*) \"Program will terminate..\"\r\n pause\r\n stop\r\n\r\n end subroutine myerror\r\n !===============================================================================!\r\n \r\n function linspace(my_start, my_stop, n)\r\n ! Purpose: replicate Matlab function \r\n ! Originally written by Arnau Valladares-Esteban\r\n implicit none\r\n ! Inputs:\r\n integer :: n\r\n real(8) :: my_start, my_stop\r\n ! Function result:\r\n real(8) :: linspace(n)\r\n ! Locals:\r\n integer :: i\r\n real(8) :: step, grid(n)\r\n\r\n if (n == 1) then\r\n grid(n) = (my_start+my_stop)/2.d0\r\n elseif (n.ge.2) then\r\n grid(1) = my_start\r\n if (n.gt.2) then\r\n step = (my_stop-my_start)/(real(n-1))\r\n do i = 2, n-1\r\n grid(i) = grid(i-1) + step\r\n end do\r\n end if\r\n grid(n) = my_stop\r\n endif\r\n linspace = grid\r\n \r\n end function linspace\r\n !===============================================================================!\r\n \r\n function ones(n) result(vec)\r\n ! Purpose: create a column vector of ones\r\n ! Input/output\r\n integer, intent(in) :: n\r\n real(8) :: vec(n)\r\n !Local variables\r\n integer :: i\r\n \r\n ! Body of ones\r\n do i = 1,n\r\n vec(i) = 1.0d0\r\n end do\r\n \r\n end function ones\r\n !===============================================================================!\r\n \r\n function eye(n) result(mat)\r\n ! Purpose: replicate function in Matlab\r\n ! Input/output\r\n integer, intent(in) :: n\r\n real(8) :: mat(n,n)\r\n !Local variables\r\n integer :: i\r\n \r\n ! Body of eye\r\n mat = 0.0d0\r\n do i = 1,n\r\n mat(i,i) = 1.0d0\r\n end do\r\n \r\n end function eye\r\n !===============================================================================!\r\n \r\n function outerprod(a,b)\r\n ! Computes the outer product of two vectors\r\n real(8), intent(in) :: a(:), b(:)\r\n real(8) :: outerprod(size(a),size(b))\r\n \r\n outerprod = spread(a,dim=2,ncopies=size(b)) * spread(b,dim=1,ncopies=size(a))\r\n\r\n end function outerprod\r\n !===============================================================================!\r\n \r\n FUNCTION cumsum(arr) RESULT(ans)\r\n ! Purpose: it replicates matlab function\r\n real(8), INTENT(IN) :: arr(:)\r\n ! Note that a Fortran function can return a value with an ALLOCATABLE\r\n ! attribute. The function result must be declared as ALLOCATABLE\r\n ! in the calling unit but will not be allocated on entry to the function.\r\n real(8), allocatable :: ans(:)\r\n INTEGER :: n,j\r\n\r\n n=size(arr)\r\n\r\n allocate(ans(n))\r\n ans(1)=arr(1)\r\n\r\n do j=2,n\r\n\t ans(j)=ans(j-1)+arr(j)\r\n end do\r\n\t\r\n END FUNCTION cumsum\r\n !===============================================================================!\r\n\r\n function is_monotone(arr) result(ans)\r\n ! Purpose: Check is a real array is monotonically increasing\r\n implicit none\r\n !Declare inputs:\r\n real(8), intent(in) :: arr(:)\r\n !Declare function result:\r\n logical :: ans\r\n !Declare locals:\r\n integer :: i,n\r\n\r\n n = size(arr)\r\n if (n==1) then\r\n ans = .true.\r\n return\r\n endif\r\n\r\n do i=1,n-1\r\n if ( arr(i)<=arr(i+1) ) then\r\n ans = .true.\r\n else\r\n ans = .false.\r\n return\r\n endif\r\n enddo\r\n\r\n end function is_monotone\r\n !===============================================================================!\r\n \r\n function my_closest(myvector,gp,myvalue)\r\n ! Purpose: FINDS CLOSEST POSITION OF A REAL IN A VECTOR OF REALS\r\n ! Originally written by Arnau Valladares-Esteban\r\n implicit none\r\n integer, intent(in) :: gp\r\n real(8), intent(in) :: myvalue\r\n real(8), dimension(gp), intent(in) :: myvector\r\n real(8), dimension(gp) :: aux\r\n ! Function result:\r\n integer :: my_closest\r\n\r\n aux = abs(myvector-myvalue)\r\n\r\n my_closest = minloc(aux, dim=1)\r\n end function my_closest\r\n !===============================================================================!\r\n \r\n subroutine unique(x, x_u,ind_u)\r\n\t! Purpose: Find unique values in array x \r\n\t! Return a smaller array with only unique values and corresponding (last) indeces \r\n\t! Identical to matlab function 'unique' with 'last' option \r\n ! WARNING: The input array x must be sorted in ascending order\r\n\r\n\timplicit none\r\n\r\n\treal(8), intent(in) :: x(:)\r\n\treal(8), intent(out), allocatable :: x_u(:)\r\n\tinteger, intent(out), allocatable :: ind_u(:) \r\n\t! Local variables\r\n\tinteger :: i, n, i_u\r\n\r\n\t! Execution \r\n\r\n\tn = size(x)\r\n\r\n\tallocate(x_u(n),ind_u(n))\r\n\r\n\tx_u(1) = x(1)\r\n\ti_u = 1\r\n\r\n\tdo i=2,n\r\n\t\tif (x(i)>x(i-1)) then\r\n\t\t\tind_u(i_u) = i-1\r\n\t\t\tx_u(i_u+1) = x(i) \r\n\t\t\ti_u = i_u+1\r\n\t\tendif \r\n\tenddo\r\n\t\r\n\tind_u(i_u) = n\r\n\t\r\n\t! Outputs\r\n\tx_u = x_u(1:i_u)\r\n\tind_u = ind_u(1:i_u)\r\n\r\n end subroutine unique\r\n !===============================================================================!\r\n \r\n function my_ss(tmatrix,gp)\r\n ! Purpose: STEADY STATE MARKOV CHAIN\r\n ! Originally written by Arnau Valladares-Esteban\r\n implicit none\r\n integer :: gp\r\n integer :: row, col, iter\r\n real(8) :: aux_sum\r\n real(8), dimension(gp) :: my_ss\r\n real(8), dimension(gp) :: dist, ndist\r\n real(8), dimension(gp,gp) :: tmatrix\r\n\r\n ! Initialise distribution\r\n dist = 1.d0/real(gp)\r\n\r\n do iter = 1, 10000\r\n ndist = 0.d0\r\n do col = 1, gp\r\n do row = 1, gp\r\n ndist(col) = ndist(col) + (dist(row)*tmatrix(row,col))\r\n end do\r\n end do\r\n aux_sum = sum(abs(ndist-dist))\r\n dist = ndist\r\n if (aux_sum.lt.1.0d-10) then\r\n exit\r\n end if\r\n end do\r\n\r\n my_ss = dist\r\n end function my_ss\r\n !===============================================================================!\r\n \r\n SUBROUTINE grid(x,xmin,xmax,s)\r\n ! Purpose: Generate grid x on [xmin,xmax] using spacing parameter s set as follows:\r\n ! s=1\t\tlinear spacing\r\n ! s>1\t\tleft skewed grid spacing with power s\r\n ! 01 grow, <1 shrink)\r\n ! s=-1\t\tlogarithmic spacing with distances changing by a factor (xmax-xmin+1)^(1/(n-1))\r\n ! s=0\t\tlogarithmic spacing with distances changing by a factor (xmax/xmin)^(1/(n-1)), only if xmax,xmin>0\r\n IMPLICIT NONE\r\n REAL(8), DIMENSION(:), INTENT(OUT) :: x\r\n REAL(8), INTENT(IN) :: xmin,xmax,s\r\n REAL(8) :: c ! growth rate of grid subintervals for logarithmic spacing\r\n INTEGER :: n,i\r\n n=size(x)\r\n FORALL(i=1:n) x(i)=(i-1)/real(n-1,8)\r\n IF (s>0.0d0) THEN\r\n\t x=x**s*(xmax-xmin)+xmin\r\n\t !IF (s==1.0d0) THEN\r\n\t !\tPRINT '(a,i8,a,f7.3,a,f7.3,a)', 'Using ',n,' equally spaced grid points over domain [',xmin,',',xmax,']'\r\n\t !ELSE\r\n\t !\tPRINT '(a,i8,a,f7.3,a,f7.3,a,f7.3,a)', 'Using ',n,' skewed spaced grid points with power ',s,' over domain [',xmin,',',xmax,']'\r\n\t !END IF\r\n ELSE\r\n\t IF (s==-1.0d0) THEN\r\n\t\t c=xmax-xmin+1\r\n !\t\tELSEIF (s==0.0d0) THEN\r\n !\t\t\tIF (xmin>0.0d0) THEN\r\n !\t\t\t\tc=xmax/xmin\r\n !\t\t\tELSE\r\n !\t\t\t\tSTOP 'grid: can not use logarithmic spacing for nonpositive values'\r\n !\t\t\tEND IF\r\n\t ELSE\r\n\t\t c=-s\r\n\t END IF\r\n\t PRINT '(a,i8,a,f6.3,a,f6.3,a,f6.3,a)', 'Using ',n,' logarithmically spaced grid points with growth rate ',c,' over domain [',xmin,',',xmax,']'\r\n\t x=((xmax-xmin)/(c-1))*(c**x)-((xmax-c*xmin)/(c-1))\r\n END IF\r\n END SUBROUTINE grid\r\n !===============================================================================!\r\n\r\n FUNCTION linint(x,y,xi)\r\n ! Purpose: linear interpolation of function y on grid x at interpolation point xi\r\n ! To make it pure, cannot use PRINT or STOP statements\r\n IMPLICIT NONE\r\n REAL(8), DIMENSION(:), INTENT(IN) :: x,y\r\n REAL(8), INTENT(IN) :: xi\r\n REAL(8) :: linint\r\n REAL(8) :: a,b,d\r\n INTEGER :: n,i\r\n n=size(x)\r\n IF (size(y)/=n) THEN\r\n\t PRINT *, 'linint: x and y must be of the same size'\r\n PAUSE\r\n\t STOP 'program terminated by linint'\r\n END IF\r\n i=max(min(locate(x,xi),n-1),1)\r\n d=x(i+1)-x(i)\r\n !IF (d == 0.0) STOP 'bad x input in splint'\r\n a=(x(i+1)-xi)/d\r\n b=(xi-x(i))/d\r\n linint=a*y(i)+b*y(i+1)\r\n END FUNCTION linint\r\n !===============================================================================!\r\n \r\n PURE FUNCTION locate(xx,x)\r\n IMPLICIT NONE\r\n REAL(8), DIMENSION(:), INTENT(IN) :: xx\r\n REAL(8), INTENT(IN) :: x\r\n INTEGER :: locate\r\n INTEGER :: n,il,im,iu\r\n n=size(xx)\r\n il=0\r\n iu=n+1\r\n do\r\n\t if (iu-il <= 1) exit\r\n\t im=(iu+il)/2\r\n\t if (x >= xx(im)) then\r\n\t\t il=im\r\n\t else\r\n\t\t iu=im\r\n\t end if\r\n end do\r\n if (x == xx(1)) then\r\n\t locate=1\r\n else if (x == xx(n)) then\r\n\t locate=n-1\r\n else\r\n\t locate=il\r\n end if\r\n END FUNCTION locate\r\n !===============================================================================!\r\n \r\n !===============================================================================!\r\n !subroutine bracket(x, xval, l, r)\r\n ! ! original code by John Burkardt\r\n ! real(8), intent(in), dimension(:) :: x\r\n ! real(8), intent(in) :: xval\r\n ! integer, intent(out) :: l, r\r\n ! integer :: i, n\r\n !\r\n ! n=size(x)\r\n ! do i = 2, n - 1\r\n ! if ( xval < x(i) ) then\r\n ! l = i - 1\r\n ! r = i\r\n ! return\r\n ! end if\r\n ! end do\r\n ! l = n - 1\r\n ! r = n\r\n !end subroutine bracket\r\n !===============================================================================!\r\n \r\n function gini(x_in, y_in)\r\n ! DESCRIPTION: computes Lorenz curve and Gini coefficient\r\n ! Notes: written by F.Kindermann\r\n ! See: https://www.ce-fortran.com/forums/topic/gini-coefficient-and-lorenz-curve/#post-1951\r\n use toolbox, only: sort, plot, execplot\r\n\r\n real(8), intent(in) :: x_in(:), y_in(:)\r\n real(8) :: gini\r\n integer :: n, ic\r\n real(8), allocatable :: xs(:), ys(:), xcum(:), ycum(:)\r\n integer, allocatable :: iorder(:)\r\n\r\n ! get array size\r\n n = size(x_in, 1)\r\n\r\n ! ALLOCATE LARGE ARRAYS TO AVOID SIZE PROBLEMS\r\n \r\n ! first deallocate\r\n if(allocated(xs))deallocate(xs)\r\n if(allocated(ys))deallocate(ys)\r\n if(allocated(xcum))deallocate(xcum)\r\n if(allocated(ycum))deallocate(ycum)\r\n if(allocated(iorder))deallocate(iorder)\r\n \r\n ! then allocate\r\n allocate(xs(n))\r\n allocate(ys(n))\r\n allocate(xcum(0:n))\r\n allocate(ycum(0:n))\r\n allocate(iorder(n))\r\n \r\n \r\n ! NOW CALCULATE GINI INDEX\r\n\r\n ! sort array\r\n xs = x_in\r\n call sort(xs, iorder)\r\n \r\n ! sort y's and normalize to 1\r\n do ic = 1, n\r\n ys(ic) = y_in(iorder(ic))\r\n enddo\r\n ys = ys/sum(ys)\r\n \r\n\r\n ! calculate cumulative distributions\r\n xcum(0) = 0d0\r\n ycum(0) = 0d0\r\n do ic = 1, n\r\n xcum(ic) = xcum(ic-1) + ys(ic)*xs(ic)\r\n ycum(ic) = ycum(ic-1) + ys(ic)\r\n enddo\r\n \r\n ! now normalize cumulated attributes\r\n xcum = xcum/xcum(n)\r\n \r\n ! plot the Lorenz curve\r\n call plot(ycum, ycum, linewidth=1d0, color=\"black\", dashtype=\"--\")\r\n call plot(ycum, xcum)\r\n call execplot()\r\n\r\n ! determine gini index\r\n gini = 0d0\r\n do ic = 1, n\r\n gini = gini + ys(ic)*(xcum(ic-1) + xcum(ic))\r\n enddo\r\n gini = 1d0 - gini\r\n \r\n end function gini\r\n !===============================================================================!\r\n \r\n function quantili(x,w,q) result(y)\r\n ! Purpose: computes quantiles q of x with weights w\r\n ! w is discrete prob function (or PMF)\r\n ! need not be sorted or normalized\r\n ! Sources: Cagetti and De Nardi M-function quantili.m\r\n ! Note: takes care of repeated values\r\n ! Dependencies: calls subroutine unique\r\n use toolbox, only: sort \r\n implicit none\r\n \r\n !Declare inputs:\r\n real(8), intent(in) :: x(:)\r\n real(8), intent(in) :: w(:)\r\n real(8), intent(in) :: q(:)\r\n !Declare output:\r\n real(8) :: y(size(q))\r\n\r\n !Declare locals\r\n integer :: i, n, istat\r\n integer, allocatable :: ix(:), ind_u(:)\r\n real(8), allocatable :: xs(:), ws(:), cums(:)\r\n real(8), allocatable :: cums_u(:), xs_u(:)\r\n\r\n n = size(x)\r\n allocate( ix(n), xs(n),ws(n),cums(n),stat=istat )\r\n if (istat/=0) then\r\n call myerror(\"quantili: Allocation failed!\")\r\n endif\r\n\r\n !!Check inputs\r\n if (size(w)/=n) then\r\n call myerror(\"quantili: x (variable) and w (pmf) must be of the same size\")\r\n endif\r\n\r\n !xs is x sorted, ix is the sorting index\r\n xs = x \r\n call sort(xs,ix)\r\n ws=w(ix)\r\n ws=ws/sum(ws)\r\n cums=cumsum(ws)\r\n \r\n ![xs_u,ind_u] = unique(xs,'last')\r\n call unique(xs, xs_u,ind_u)\r\n cums_u = cums(ind_u)\r\n\r\n y = 0.0d0\r\n do i=1,size(q)\r\n if (cums_u(1)<=q(i)) then\r\n y(i) = linint(cums_u,xs_u,q(i))\r\n else\r\n y(i) = xs_u(1) \r\n endif\r\n enddo\r\n\r\n end function quantili\r\n !===============================================================================!\r\n\r\n subroutine calculate_quintiles(a_input,a_dist,thresholds, quantiles)\r\n !Source: Kindermann's book pp. 467-469\r\n !Compare to function \"quantili\" in this module (see below)\r\n\r\n use toolbox, only: sort \r\n implicit none\r\n\r\n !Declare inputs:\r\n real(8), intent(in) :: a_input(:)\r\n real(8), intent(inout) :: a_dist(:)\r\n real(8) :: thresholds(:)\r\n\r\n !Declare outputs:\r\n real(8), intent(out) :: quantiles(size(thresholds, 1))\r\n\r\n !Declare locals:\r\n integer :: ia, ic, it, NC, istat\r\n real(8) :: slope\r\n integer, allocatable :: iorder(:)\r\n real(8), allocatable :: a_sort(:), a_cdist(:)\r\n\r\n ! define quantile thresholds (now passed as inputs to subr)\r\n !thresholds = (/0.05d0, 0.25d0, 0.50d0, 0.75d0, 0.95d0/)\r\n quantiles = 0d0\r\n\r\n ! K only uses asset levels with pop share of at least 10^(12)\r\n ! This is similar to getting rid of zeros as I do in lrzcurve\r\n ! --- SKIP FOR NOW ---!\r\n\r\n NC = size(a_dist,1)\r\n\r\n !!Check inputs\r\n if (size(a_input)/=NC) then\r\n call myerror(\"calculate_quintiles: a (variable) and a_dist (pmf) must be of the same size\")\r\n endif\r\n\r\n allocate( iorder(NC), a_sort(NC), a_cdist(NC), stat=istat )\r\n if (istat/=0) then\r\n call myerror(\"calculate_quintiles: Allocation failed!\")\r\n endif\r\n\r\n ! sort array and distribution\r\n a_sort = a_input \r\n call sort(a_sort(1:NC), iorder(1:NC))\r\n\r\n ! calculate cumulative distribution (attention ordering)\r\n a_cdist(1) = a_dist(iorder(1))\r\n do ic = 2, NC\r\n a_cdist(ic) = a_cdist(ic-1) + a_dist(iorder(ic))\r\n enddo\r\n\r\n ! get quantiles\r\n do it = 1, size(thresholds, 1)\r\n if(thresholds(it) <= a_cdist(1))then\r\n quantiles(it) = a_sort(1)\r\n else\r\n do ic = 2, NC\r\n if(thresholds(it) < a_cdist(ic)) then\r\n slope = (a_sort(ic)-a_sort(ic-1))/(a_cdist(ic)-a_cdist(ic-1))\r\n quantiles(it) = a_sort(ic-1) + slope*(thresholds(it)-a_cdist(ic-1))\r\n exit\r\n elseif(ic == NC)then\r\n quantiles(it) = a_sort(NC)\r\n endif\r\n enddo\r\n endif\r\n enddo\r\n\r\n\r\n end subroutine calculate_quintiles\r\n !===============================================================================!\r\n\r\n subroutine lrzcurve_basic(f_in,y,gini)\r\n ! Purpose: It computes the Gini WITHOUT eliminating the zeros\r\n ! Source: This is a simplified version of Matlab \r\n use toolbox, only: sort \r\n implicit none\r\n\r\n !Declare inputs and outputs:\r\n real(8), intent(in) :: f_in(:) !Distribution\r\n real(8), intent(in) :: y(:) !Variable of interest\r\n real(8), intent(out) :: gini !Gini coefficient\r\n\r\n !Declare local variables:\r\n real(8) :: minpop\r\n integer :: i,n, istat\r\n real(8), allocatable :: f(:),y_sort(:), Scum(:),S(:),f_temp(:)\r\n integer, allocatable :: key(:)\r\n\r\n n = size(y)\r\n\r\n !Check inputs\r\n if (size(f_in)/=n) then\r\n call myerror(\"lrzcurve_basic: f (distrib.) and y (var. of interest) must be of the same size\")\r\n endif\r\n\r\n allocate(f(n),y_sort(n),Scum(n),S(n),key(n),stat=istat)\r\n if (istat/=0) then\r\n call myerror(\"lrzcurve_basic: Allocation failed!\")\r\n endif\r\n\r\n !I do not want to modify f_in\r\n f = f_in\r\n\r\n !Sort x in scending order \r\n !Sort p\r\n y_sort = y\r\n call sort(y_sort,key)\r\n\r\n !f = f(key) !stack overflow occurs here\r\n f_temp = f\r\n do i=1,size(f)\r\n f(i) = f_temp(key(i))\r\n enddo\r\n deallocate(f_temp)\r\n\r\n S = y_sort*f\r\n Scum = cumsum(S) \r\n gini = f(1)*Scum(1)\r\n\r\n do i=2,n\r\n gini = gini + (Scum(i) + Scum(i-1))*f(i)\r\n enddo\r\n\r\n gini = 1.0d0 - (gini/Scum(n))\r\n minpop = minval(f)\r\n\r\n ! Normalize the gini (smth not always done...)\r\n gini = gini/(1.0d0 - minpop)\r\n\r\n end subroutine lrzcurve_basic\r\n !===============================================================================!\r\n \r\n subroutine lrzcurve(p,x,gini_out,fx_out,sx_out,mean_x_out,stdv_x_out)\r\n \r\n ! ------------------------- LEGEND --------------------------------!\r\n ! Purpose: compute Lorenz curve, gini coeff, mean and std\r\n ! INPUTS:\r\n ! p is the probability distrib (it must sum to 1)\r\n ! x is a vector with the values of the variable of interest\r\n ! OUTPUTS:\r\n ! fx(:) is share of population\r\n ! sx(:) is the corresponding share of wealth/income/etc.\r\n ! E.g. plot Lorenz curve with fx on the x-axis and sx on the y-axis\r\n ! See wiki: https://en.wikipedia.org/wiki/Lorenz_curve\r\n ! DEPENDENCIES:\r\n ! lrzcurve calls a subroutine to sort arrays. It can either be\r\n ! from Kindermann's toolbox (and in this case you need to use\r\n ! the toolbox) or which is stored in this module\r\n ! -----------------------------------------------------------------!\r\n\r\n !use toolbox, only: sort \r\n \r\n implicit none\r\n !Declare inputs:\r\n real(8), intent(in) :: p(:)\r\n real(8), intent(in) :: x(:)\r\n !Declare outputs:\r\n real(8), intent(out) :: gini_out\r\n real(8), allocatable, intent(out), optional :: fx_out(:)\r\n real(8), allocatable, intent(out), optional :: sx_out(:)\r\n real(8), intent(out), optional :: mean_x_out\r\n real(8), intent(out), optional :: stdv_x_out \r\n\r\n !Declare locals:\r\n integer :: n, i, n_valid, istat\r\n real(8) :: minpop, mean_x, stdv_x, gini \r\n real(8), allocatable :: p1(:), x1(:), fx(:), sx(:)\r\n integer, allocatable :: key(:)\r\n\r\n n = size(x)\r\n\r\n if (size(p)/=n) then\r\n call myerror(\"lrzcurve: x and p must have the same size\")\r\n endif\r\n if (abs(sum(p)-1.0d0)>1d-8) then\r\n call myerror(\"lrzcurve: p must sum to one\")\r\n endif\r\n\r\n !Preliminary step\r\n !Matlab code:\r\n !%% Eliminate elements with zero probability\r\n !p1=p; p(p1==0) = []; x(p1==0) = [];\r\n\r\n p1 = pack(p,p/=0.0d0)\r\n x1 = pack(x,p/=0.0d0)\r\n \r\n n_valid = count(p/=0.0d0)\r\n allocate(key(n_valid),stat=istat)\r\n key = [ (i,i=1,n_valid) ]\r\n if (istat/=0) then\r\n call myerror(\"lrzcurve: Allocation failed!\")\r\n endif\r\n\r\n !Compute mean and standard deviation\r\n mean_x = dot_product(p1,x1)\r\n stdv_x = dot_product(p1,(x1-mean_x)**2)\r\n\r\n !Sort x1 in ascending order\r\n !call sort(x1,key)\r\n call QsortC(x1,key)\r\n\r\n !Sort distribution accordingly\r\n fx = p1(key)\r\n\r\n !sx(i) is the term x(i)*fx(i)\r\n sx = (x1*fx)\r\n sx = sx/mean_x\r\n \r\n !Add initial zero\r\n fx = [0d0, fx]\r\n sx = [0d0, sx]\r\n \r\n !Compute cumulative sums:\r\n ! sx is the cumulative share of x\r\n sx = cumsum(sx)\r\n\r\n !Compute Gini coefficient:\r\n gini = sx(1)*fx(1)\r\n do i = 2,size(fx)\r\n gini = gini +(sx(i)+sx(i-1))*fx(i)\r\n enddo\r\n gini = 1.0d0-(gini/sx(size(sx)))\r\n\r\n ! Keep the smallest population, needed to normalize the Gini coefficient\r\n minpop = minval(p1)\r\n\r\n ! Normalize the gini (smth not always done...)\r\n gini = gini/(1.0d0 - minpop)\r\n\r\n ! Assign outputs\r\n gini_out = gini\r\n \r\n ! Assign optional outputs\r\n ! Lorenz curve(i) is (fx(i), shareX(i))\r\n if (present(fx_out)) then\r\n fx_out = cumsum(fx)\r\n endif\r\n if (present(sx_out)) then\r\n sx_out = sx\r\n endif\r\n if (present(mean_x_out)) then\r\n mean_x_out = mean_x\r\n endif\r\n if (present(stdv_x_out)) then\r\n stdv_x_out = stdv_x\r\n endif\r\n\r\n end subroutine lrzcurve\r\n !===============================================================================!\r\n \r\n subroutine golden_method(f, a, b, x1, f1, mytol, mymaxit)\r\n ! Purpose: Applies Golden-section search to search for the *maximum* of a function \r\n ! in the interval (a, b).\r\n ! Source: https://en.wikipedia.org/wiki/Golden-section_search\r\n ! Adapted to Fortran90 from: https://github.com/QuantEcon\r\n \r\n !---------------------------------------------------!\r\n !INPUTS\r\n interface\r\n function f(x)\r\n implicit none\r\n real(8), intent(in) :: x\r\n real(8) :: f\r\n end function f\r\n end interface\r\n real(8), intent(in) :: a, b\r\n !Some optional inputs\r\n integer, optional :: mymaxit\r\n real(8), optional :: mytol\r\n !OUTPUTS\r\n real(8), intent(out) :: x1, f1\r\n !---------------------------------------------------!\r\n \r\n !Locals\r\n integer :: maxit, it\r\n real(8) :: tol, alpha1, alpha2, d, f2, x2, s\r\n \r\n !! Assign default value to maxit if not defined by user\r\n if (present(mymaxit)) then\r\n maxit = mymaxit\r\n else\r\n maxit = 1000\r\n end if\r\n \r\n ! Assign default value to tol if not defined by user\r\n if (present(mytol)) then\r\n tol = mytol\r\n else\r\n tol = 1.0d-6\r\n end if\r\n \r\n alpha1 = (3.d0 - sqrt(5.d0)) / 2.d0\r\n alpha2 = 1.d0 - alpha1\r\n d = b - a\r\n x1 = a + alpha1*d\r\n x2 = a + alpha2*d\r\n s = 1.d0\r\n f1 = f(x1)\r\n f2 = f(x2)\r\n d = alpha1*alpha2*d\r\n \r\n it = 0\r\n \r\n do while ((d.gt.tol).and.(it.lt.maxit))\r\n it = it + 1\r\n d = d*alpha2\r\n \r\n if (f2.gt.f1) then\r\n x1 = x2\r\n f1 = f2\r\n x2 = x1 + s*d\r\n else\r\n x2 = x1 - s*d\r\n end if\r\n \r\n s = sign(s, x2-x1)\r\n f2 = f(x2)\r\n end do\r\n \r\n if (it.ge.maxit) then\r\n print *, \"Golden method: Maximum iterations exceeded\"\r\n end if\r\n \r\n if (f2.gt.f1) then\r\n x1 = x2\r\n f1 = f2\r\n end if\r\n \r\n end subroutine golden_method\r\n !===============================================================================!\r\n \r\n subroutine max_nonconvex(f, a, b, xmax, fmax, mytol, mymaxit, mynx)\r\n ! Purpose: Maximize the univariate function f(x) in [a,b]\r\n ! using either grid search or golden method or both\r\n ! Deals with non-concave objective functions\r\n \r\n !---------------------------------------------------!\r\n ! INPUTS:\r\n interface\r\n function f(x)\r\n implicit none\r\n real(8), intent(in) :: x\r\n real(8) :: f\r\n end function f\r\n end interface\r\n real(8), intent(in) :: a, b\r\n ! Optional inputs:\r\n integer, optional :: mymaxit\r\n real(8), optional :: mytol\r\n integer, optional :: mynx\r\n ! OUTPUTS:\r\n real(8), intent(out) :: xmax, fmax\r\n !---------------------------------------------------!\r\n \r\n !Locals\r\n integer :: maxit, x_c, max_ind, left_loc, right_loc\r\n real(8) :: tol, x_val, max_val, temp, x1, f1\r\n integer :: nx\r\n real(8), allocatable :: x_grid(:)\r\n \r\n ! Assign default value to maxit if not defined by user\r\n if (present(mymaxit)) then\r\n maxit = mymaxit\r\n else\r\n maxit = 1000\r\n end if\r\n \r\n ! Assign default value to tol if not defined by user\r\n if (present(mytol)) then\r\n tol = mytol\r\n else\r\n tol = 1.0d-6\r\n end if\r\n \r\n ! Assign default value to nx if not defined by user\r\n if (present(mynx)) then\r\n nx = max(mynx,2)\r\n else\r\n nx = 100\r\n end if\r\n \r\n ! Preliminary step: define the grid\r\n allocate(x_grid(nx))\r\n x_grid = linspace(a,b,nx)\r\n \r\n ! First step: grid search\r\n max_val = -huge(0d0)\r\n max_ind = 1\r\n do x_c = 1,nx\r\n x_val = x_grid(x_c)\r\n temp = f(x_val)\r\n if (temp>max_val) then\r\n max_val = temp\r\n max_ind = x_c\r\n endif\r\n enddo\r\n \r\n ! Second step: find the interval that brackets the true maximum\r\n left_loc = max(max_ind-1,1)\r\n right_loc = min(max_ind+1,nx)\r\n \r\n ! Last step: call golden_method section search \r\n call golden_method(f, x_grid(left_loc), x_grid(right_loc), x1, f1, tol, maxit)\r\n \r\n ! Assign outputs\r\n xmax = x1 ! arg max\r\n fmax = f1 ! f(arg max)\r\n \r\n end subroutine max_nonconvex\r\n !===============================================================================!\r\n \r\n FUNCTION rtbis(func,x1,x2,xacc,MAXIT)\r\n !-------------------------------------------------------------!\r\n ! DESCRIPTION:\r\n ! Bisection to find root x of a nonlinear function func(x)=0\r\n ! INPUTS:\r\n ! func: function to pass to the rootfinder\r\n ! [x1 x2]: bracketing interval\r\n ! xacc: accuracy criterion\r\n ! MAXIT: maximum number of iterations\r\n ! OUTPUT\r\n ! rtbis: root of the function in [x1 x2]\r\n ! SOURCE:\r\n ! http://numerical.recipes/\r\n !-------------------------------------------------------------!\r\n \r\n IMPLICIT NONE\r\n REAL(8), INTENT(IN) :: x1,x2,xacc\r\n INTEGER, INTENT(IN) :: MAXIT\r\n REAL(8) :: rtbis\r\n INTERFACE\r\n\t FUNCTION func(x)\r\n\t IMPLICIT NONE\r\n\t REAL(8), INTENT(IN) :: x\r\n\t REAL(8) :: func\r\n\t END FUNCTION func\r\n END INTERFACE\r\n !INTEGER, PARAMETER :: MAXIT=40\r\n INTEGER :: j\r\n REAL(8) :: dx,f,fmid,xmid\r\n fmid = func(x2)\r\n f = func(x1)\r\n if (f*fmid >= 0.0d0) then \r\n\t call myerror(\"rtbis: root must be bracketed\")\r\n endif\r\n if (f < 0.0d0) then\r\n\t rtbis=x1\r\n\t dx=x2-x1\r\n else\r\n\t rtbis=x2\r\n\t dx=x1-x2\r\n end if\r\n do j=1,MAXIT\r\n\t dx=dx*0.5d0\r\n\t xmid=rtbis+dx\r\n\t fmid=func(xmid)\r\n\t if (fmid <= 0.0d0) rtbis=xmid\r\n\t if (abs(dx) < xacc .or. fmid == 0.0d0) RETURN\r\n end do\r\n write(*,*) \"WARNING: rtbis: too many bisections\"\r\n END FUNCTION rtbis\r\n !===============================================================================!\r\n \r\n FUNCTION zbrent(func,x1,x2,tol,ITMAX)\r\n !-------------------------------------------------------------!\r\n ! DESCRIPTION:\r\n ! Brent's method to find root x of a nonlinear function func(x)=0\r\n ! It is the same as fzero in Matlab. Brent's method is generally\r\n ! better than bisection.\r\n ! INPUTS:\r\n ! func: function to pass to the rootfinder\r\n ! [x1 x2]: bracketing interval\r\n ! tol: accuracy criterion\r\n ! MAXIT: maximum number of iterations ???\r\n ! OUTPUT\r\n ! rtbis: root of the function in [x1 x2]\r\n ! SOURCE:\r\n ! http://numerical.recipes/\r\n !-------------------------------------------------------------!\r\n IMPLICIT NONE\r\n REAL(8), INTENT(IN) :: x1,x2,tol\r\n INTEGER, INTENT(IN) :: ITMAX\r\n REAL(8) :: zbrent\r\n INTERFACE\r\n\t FUNCTION func(x)\r\n\t !USE mkl95_precision, ONLY: WP => DP\r\n\t IMPLICIT NONE\r\n\t REAL(8), INTENT(IN) :: x\r\n\t REAL(8) :: func\r\n\t END FUNCTION func\r\n END INTERFACE\r\n REAL(8), PARAMETER :: EPS=epsilon(x1)\r\n INTEGER :: iter\r\n REAL(8) :: a,b,c,d,e,fa,fb,fc,p,q,r,s,tol1,xm\r\n a=x1\r\n b=x2\r\n fa=func(a)\r\n fb=func(b)\r\n if ((fa > 0.0 .and. fb > 0.0) .or. (fa < 0.0 .and. fb < 0.0)) then\r\n\t call myerror('root must be bracketed for zbrent')\r\n endif\r\n c=b\r\n fc=fb\r\n do iter=1,ITMAX\r\n\t if ((fb > 0.0 .and. fc > 0.0) .or. (fb < 0.0 .and. fc < 0.0)) then\r\n\t\t c=a\r\n\t\t fc=fa\r\n\t\t d=b-a\r\n\t\t e=d\r\n\t end if\r\n\t if (abs(fc) < abs(fb)) then\r\n\t\t a=b\r\n\t\t b=c\r\n\t\t c=a\r\n\t\t fa=fb\r\n\t\t fb=fc\r\n\t\t fc=fa\r\n\t end if\r\n\t tol1=2.0d0*EPS*abs(b)+0.5d0*tol\r\n\t xm=0.5d0*(c-b)\r\n\t if (abs(xm) <= tol1 .or. fb == 0.0) then\r\n\t\t zbrent=b\r\n\t\t RETURN\r\n\t end if\r\n\t if (abs(e) >= tol1 .and. abs(fa) > abs(fb)) then\r\n\t\t s=fb/fa\r\n\t\t if (a == c) then\r\n\t\t\t p=2.0d0*xm*s\r\n\t\t\t q=1.0d0-s\r\n\t\t else\r\n\t\t\t q=fa/fc\r\n\t\t\t r=fb/fc\r\n\t\t\t p=s*(2.0d0*xm*q*(q-r)-(b-a)*(r-1.0d0))\r\n\t\t\t q=(q-1.0d0)*(r-1.0d0)*(s-1.0d0)\r\n\t\t end if\r\n\t\t if (p > 0.0) q=-q\r\n\t\t p=abs(p)\r\n\t\t if (2.0d0*p < min(3.0d0*xm*q-abs(tol1*q),abs(e*q))) then\r\n\t\t\t e=d\r\n\t\t\t d=p/q\r\n\t\t else\r\n\t\t\t d=xm\r\n\t\t\t e=d\r\n\t\t end if\r\n\t else\r\n\t\t d=xm\r\n\t\t e=d\r\n\t end if\r\n\t a=b\r\n\t fa=fb\r\n\t b=b+merge(d,sign(tol1,xm), abs(d) > tol1 )\r\n\t fb=func(b)\r\n end do\r\n write(*,*) 'WARNING: zbrent: exceeded maximum iterations'\r\n zbrent=b\r\n END FUNCTION zbrent\r\n !===============================================================================!\r\n\r\n function bddparetocdf(emin, emax, shape, eval) result(cdf)\r\n ! Purpose: calculate the cumulative density (or mass) at eval for a\r\n ! discretized bounded Pareto distribution over (emin,emax)\r\n ! Source: https://ideas.repec.org/a/red/issued/17-402.html\r\n ! Code for paper \"Aggregate Consequences of Credit Subsidy Policies\"\r\n ! by Jo and Senga.\r\n implicit none\r\n\r\n ! Inputs:\r\n real(8), intent(in) :: emin \r\n real(8), intent(in) :: emax\r\n real(8), intent(in) :: shape\r\n real(8), intent(in) :: eval\r\n ! Function result:\r\n real(8) :: cdf\r\n ! Locals:\r\n real(8) :: paretocdf\r\n \r\n ! Check inputs:\r\n if (emin <=0 ) then\r\n call myerror(\"bddparetocdf: emin cannot be negative!\")\r\n endif\r\n \r\n if (emax <= emin ) then\r\n call myerror(\"bddparetocdf: emax cannot be less than emin!\")\r\n endif\r\n\r\n ! Body of Func\r\n paretocdf = 1.0d0 - (emin/eval)**shape\r\n cdf = paretocdf/(1.0d0 - (emin/emax)**shape)\r\n\r\n end function bddparetocdf\r\n !===============================================================================!\r\n \r\n subroutine discretize_pareto(neps, eps, shape, rhoeps, ergoeps, pie)\r\n !--------------------------------------------------------------------------!\r\n ! This sub computes the ergodic distribution and the transition matrix of a\r\n ! bounded Pareto distribution, given grids of epsilon values.\r\n ! INPUTS:\r\n ! neps :: number of grid points\r\n ! eps :: grid with endpoints e_min and e_max\r\n ! shape :: shape parameter\r\n ! rhoeps :: persistence\r\n !--------------------------------------------------------------------------!\r\n ! Source: https://ideas.repec.org/a/red/issued/17-402.html\r\n ! Code for paper \"Aggregate Consequences of Credit Subsidy Policies\"\r\n ! by Jo and Senga.\r\n !--------------------------------------------------------------------------!\r\n implicit none\r\n ! Inputs:\r\n integer, intent(in) :: neps\r\n real(8), intent(in) :: eps(neps)\r\n real(8), intent(in) :: shape\r\n real(8), intent(in) :: rhoeps\r\n ! Outputs\r\n real(8), intent(out) :: ergoeps(neps), pie(neps,neps)\r\n ! Locals:\r\n integer :: i\r\n real(8) :: emin, emax, mass\r\n real(8) :: mideps(neps-1)\r\n\r\n ! Check inputs\r\n if (shape<=0.0d0) then\r\n call myerror(\"discretize_pareto: shape param must be positive!\")\r\n endif\r\n\r\n ! Body of discretize_pareto\r\n ergoeps = 0.0d0\r\n pie = 0.0d0\r\n\r\n ! emin and emax are imaginary end points of a continuous distribution\r\n emin = eps(1) - (eps(2)-eps(1))/2.0d0\r\n emax = eps(neps) + (eps(neps)-eps(neps-1))/2.0d0\r\n\r\n mideps = 0.0d0\r\n do i = 1,neps-1\r\n mideps(i) = (eps(i)+eps(i+1))/2;\r\n enddo\r\n\r\n ! compute density or mass at each epsilon point\r\n ergoeps(1) = bddparetocdf(emin, emax, shape, mideps(1))\r\n do i = 2,neps-1\r\n mass = bddparetocdf(emin,emax,shape, mideps(i-1))\r\n ergoeps(i) = bddparetocdf(emin,emax,shape, mideps(i)) - mass\r\n enddo\r\n ergoeps(neps) = 1.0d0 - bddparetocdf(emin, emax, shape, mideps(neps-1))\r\n\r\n\r\n ! transition matrix given rhoeps\r\n do i = 1,neps\r\n pie(i,i) = rhoeps\r\n pie(i,:) = pie(i,:) + (1.0d0-rhoeps)*ergoeps\r\n enddo\r\n\r\n end subroutine discretize_pareto\r\n !===============================================================================!\r\n\t\r\n subroutine tauchen(rho, sigma, mu, cover, gp, values, trans)\r\n !-------------------------------------------------------------------------------!\r\n ! Purpose: approximating first-order autoregressive process with Markov chain\r\n !\r\n ! y_t = rho * y_(t-1) + u_t\r\n !\r\n ! u_t is a Gaussian white noise process with standard deviation sigma.\r\n !\r\n ! cover determines the width of discretized state space, Tauchen uses m=3\r\n !\r\n ! gp is the number of possible states chosen to approximate\r\n ! the y_t process\r\n !\r\n ! trans is the transition matrix of the Markov chain\r\n !\r\n ! values is the discretized state space of y_t\r\n !\r\n ! Adapted from https://github.com/lucaguerrieri/\r\n ! Written in Fortran by Arnau Valladares-Esteban, \r\n ! https://github.com/drarnau/Replication_Krusell-et-al-2017/blob/master/Utils.f90\r\n ! Modified by Alessandro Di Nola, following also Robert Kirkby's TauchenMethod \r\n\t! https://github.com/vfitoolkit/VFIToolkit-matlab/blob/master/TauchenMethod/TauchenMethod.m\r\n ! Note: if the process y_t has non-zero mean, i.e.\r\n ! y_t = mu + rho * y_(t-1) + u_t, ==> E(y) = mu/(1-rho)\r\n ! Let z_t = y_t - mu/(1-rho)\r\n ! Apply Tauchen to z_t and then obtain y_t = z_t + mu/(1-rho)\r\n !-------------------------------------------------------------------------------!\r\n implicit none\r\n ! Declare inputs and outputs:\r\n integer, intent(in) :: gp\r\n real(8), intent(in) :: rho, sigma, mu, cover\r\n real(8), dimension(gp), intent(out) :: values\r\n real(8), dimension(gp,gp), intent(out) :: trans\r\n ! Declare locals:\r\n integer :: j, k\r\n real(8) :: sd_y, ymin, ymax, w, ystar\r\n\r\n ! standard deviation of y_t\r\n sd_y = sqrt(sigma**2.d0/(1.d0-rho**2.d0))\r\n\r\n ymax = cover*sd_y ! upper boundary of state space\r\n ymin = -ymax ! lower boundary of state space\r\n w = (ymax-ymin)/real(gp-1,8) ! length of interval\r\n \r\n ystar = mu/(1.0d0-rho) !expected value of y\r\n\r\n values = ystar + linspace(ymin, ymax, gp)\r\n\r\n ! Compute transition matrix\r\n do j = 1, gp\r\n do k = 2, gp-1\r\n trans(j,k) = &\r\n normcdf(values(k)-rho*values(j)+(values(k+1)-values(k))/2.d0,mu,sigma) &\r\n - normcdf(values(k)-rho*values(j)-(values(k)-values(k-1))/2.d0,mu,sigma)\r\n enddo\r\n ! only subtract half the interval on the right\r\n trans(j,1) = normcdf(values(1)-rho*values(j)+w/2.d0,mu,sigma)\r\n ! only subtract half the interval on the left\r\n trans(j,gp) = 1.d0 - normcdf(values(gp)-rho*values(j)-w/2.d0,mu,sigma)\r\n enddo\r\n contains\r\n \r\n real(8) function normcdf(x,mu,sigma)\r\n implicit none\r\n real(8), intent(in) :: x, mu, sigma\r\n\r\n normcdf = (1.d0+erf((x-mu)/sqrt(2.d0*sigma**2)))/2.d0\r\n end function normcdf\r\n \r\n end subroutine tauchen\r\n !===============================================================================!\r\n \r\n function mycorr(x,y,w) result(corr_weight)\r\n ! This function computes the correlation coefficient b/w two vectors\r\n ! X and Y with weights W. \r\n ! See wiki: https://en.wikipedia.org/wiki/Correlation_and_dependence\r\n\t implicit none\r\n \r\n ! Declare input variables:\r\n real(8), intent(in) :: x(:), y(:)\r\n real(8), intent(in) :: w(:)\r\n \r\n ! Declare function result:\r\n real(8) :: corr_weight\r\n \r\n ! Declare local variables:\r\n integer :: i, n\r\n real(8) :: mean_x, mean_y, sum_covar, sum_weight\r\n real(8) :: var_x, var_y, cov_xy\r\n \r\n \r\n !-------------------------------!\r\n ! Check inputs\r\n if ( size(x,dim=1)/=size(y,dim=1) ) then\r\n call myerror(\"Dimension of X and Y do not match!\")\r\n endif\r\n if ( size(x,dim=1)/=size(w,dim=1) ) then\r\n call myerror(\"Dimension of X and weights do not match!\")\r\n endif\r\n if ( any(w<0.0d0) ) then\r\n call myerror(\"Weights must be positive!\")\r\n endif\r\n \r\n ! Compute weighted mean of X and Y\r\n mean_x = weighted_mean(x,w)\r\n mean_y = weighted_mean(y,w)\r\n \r\n ! Compute weighted variance of X and Y\r\n var_x = weighted_variance(x,w)\r\n var_y = weighted_variance(y,w)\r\n \r\n ! Compute weighted covariance b/w X and Y\r\n n = size(x,dim=1) !assume x and y have same size\r\n sum_covar = 0.0d0\r\n sum_weight= 0.0d0\r\n do i=1,n\r\n sum_covar = sum_covar + w(i)*(x(i)-mean_x)*(y(i)-mean_y)\r\n sum_weight = sum_weight + w(i)\r\n enddo\r\n cov_xy = sum_covar/sum_weight\r\n \r\n ! Compute weighted correlation b/w X and Y\r\n corr_weight = cov_xy/sqrt(var_x*var_y);\r\n \r\n contains\r\n \r\n function weighted_mean(x,w) result(meanX)\r\n implicit none\r\n \r\n ! Declare inputs\r\n real(8), intent(in) :: x(:), w(:)\r\n ! Declare function results\r\n real(8) :: meanX\r\n ! Declare locals\r\n integer :: n, i\r\n real(8) :: sum, sum_weight\r\n\r\n n = size(w,dim=1)\r\n \r\n !assume that weight vector and input vector have same length\r\n sum=0.0d0\r\n sum_weight=0.0d0\r\n do i=1,n\r\n sum = sum + x(i)*w(i)\r\n sum_weight = sum_weight + w(i)\r\n enddo\r\n meanX = sum/sum_weight\r\n \r\n end function weighted_mean\r\n !-----------------------------------------------------------!\r\n function weighted_variance(x,w) result(varX)\r\n implicit none\r\n \r\n ! Declare inputs\r\n real(8), intent(in) :: x(:), w(:)\r\n ! Declare function results\r\n real(8) :: varX\r\n ! Declare locals\r\n integer :: n, i\r\n real(8) :: sum, sum_weight\r\n\r\n n = size(w,dim=1)\r\n \r\n !assume that weight vector and input vector have same length\r\n sum=0.0d0\r\n sum_weight=0.0d0\r\n do i=1,n\r\n sum = sum + ( ( x(i)- weighted_mean(x,w))**2)*w(i)\r\n sum_weight = sum_weight + w(i)\r\n enddo\r\n varX = sum/sum_weight\r\n\r\n end function weighted_variance\r\n !-----------------------------------------------------------!\r\n end function mycorr\r\n !===============================================================================!\r\n \r\n RECURSIVE SUBROUTINE QsortC(A, index_A)\r\n ! Author: Juli Rew, SCD Consulting (juliana@ucar.edu), 9/03\r\n ! Based on algorithm from Thomas H. Cormen, Charles E. Leiserson, Ronald L.\r\n ! Rivest, and Clifford Stein, Introduction to Algorithms, The MIT Press, 1997 edition.\r\n ! Made F conformant by Walt Brainerd\r\n ! Modified by Giulio Fella (02/2013) to sort the array index accordingly \r\n ! see https://github.com/gfell/gf_qsort/blob/master/mod_gf_qsort.f90\r\n \r\n ! Input/output variables\r\n ! A \t : real(precision) array to sort\r\n ! index_A: integer array indexing elements of A\r\n REAL(8), INTENT(inout), DIMENSION(:) :: A\r\n INTEGER, INTENT(inout), DIMENSION(SIZE(A)) :: index_A\r\n INTEGER :: iq\r\n \r\n IF(SIZE(A) > 1) THEN\r\n CALL Partition(A,index_A, iq)\r\n CALL QsortC(A(:iq-1),index_A(:iq-1))\r\n CALL QsortC(A(iq:),index_A(iq:))\r\n ENDIF\r\n END SUBROUTINE QsortC\r\n\r\n SUBROUTINE Partition(A, index_A, marker)\r\n REAL(8), INTENT(in out), DIMENSION(:) :: A\r\n INTEGER, INTENT(in out), DIMENSION(SIZE(A)) :: index_A\r\n INTEGER, INTENT(out) :: marker\r\n INTEGER :: i, j\r\n INTEGER :: index_temp\r\n REAL(8) :: temp\r\n REAL(8) :: x ! pivot point\r\n x = A(1)\r\n i= 0\r\n j= SIZE(A) + 1\r\n\r\n DO\r\n j = j-1\r\n DO\r\n IF (A(j) <= x) EXIT\r\n j = j-1\r\n END DO\r\n i = i+1\r\n DO\r\n IF (A(i) >= x) EXIT\r\n i = i+1\r\n END DO\r\n IF (i < j) THEN\r\n ! exchange A(i) and A(j)\r\n temp = A(i)\r\n A(i) = A(j)\r\n A(j) = temp\r\n\r\n index_temp = index_A(i)\r\n index_A(i) = index_A(j)\r\n index_A(j) = index_temp\r\n\r\n ELSEIF (i == j) THEN\r\n marker = i+1\r\n RETURN\r\n ELSE\r\n marker = i\r\n RETURN\r\n ENDIF\r\n END DO\r\n\r\n END SUBROUTINE Partition\r\n!===============================================================================!\r\n\r\n! Compute the cumulative product of the vector x\r\nfunction cumprod_r(x) result(y)\r\n implicit none\r\n real(8), intent(in) :: x(1:)\r\n real(8) :: y(size(x))\r\n !local\r\n real(8) :: tmp\r\n integer :: i\r\n\r\n\r\n y(1) = x(1)\r\n tmp = x(1)\r\n do i = 2,size(x)\r\n tmp = tmp*x(i)\r\n y(i) = tmp\r\n end do\r\n\r\nend function cumprod_r\r\n!===============================================================================!\r\n\r\nfunction cumprod_i(x) result(y)\r\n implicit none\r\n integer, intent(in) :: x(1:)\r\n integer :: y(size(x))\r\n !local\r\n integer :: tmp\r\n integer :: i\r\n\r\n y(1) = x(1)\r\n tmp = x(1)\r\n do i = 2,size(x)\r\n tmp = tmp*x(i)\r\n y(i) = tmp\r\n end do\r\n\r\nend function cumprod_i\r\n!===============================================================================!\r\n \r\n! Code is based of the matlab ind2sub.m\r\n! Given an integer vector siz that gives the shape of\r\n! some array and the linear index i, convert the linear\r\n! index into an i1,i2,... such that \r\n! a(i) = a(i1,i2,...)\r\nfunction ind2sub(siz,i) result(ivec)\r\n integer, intent(in) :: siz(:)\r\n integer :: i\r\n integer :: ivec(size(siz))\r\n ! local\r\n integer :: d\r\n integer :: j,k\r\n integer :: cumprodivec(size(siz))\r\n\r\n cumprodivec(1) = 1\r\n cumprodivec(2:size(siz)) = cumprod(siz(1:size(siz)-1))\r\n\r\n j = i\r\n do d = size(siz),1,-1\r\n k = mod(j-1,cumprodivec(d)) + 1\r\n ivec(d) = (j-k)/cumprodivec(d) + 1\r\n j = k\r\n end do\r\n\r\nend function ind2sub\r\n\r\n \r\n \r\nend module mod_numerical\r\n", "meta": {"hexsha": "7d8e8ba83e6d7f63efb30289103b69b480df6aa1", "size": 44592, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mod_numerical.f90", "max_stars_repo_name": "skphy/ToolboxFortran", "max_stars_repo_head_hexsha": "c1a4dd2188e5b2761ac8d72af64a7ad25c88c2fa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2022-01-16T08:27:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-16T08:27:56.000Z", "max_issues_repo_path": "mod_numerical.f90", "max_issues_repo_name": "skphy/ToolboxFortran", "max_issues_repo_head_hexsha": "c1a4dd2188e5b2761ac8d72af64a7ad25c88c2fa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-04-04T22:39:23.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-01T00:06:32.000Z", "max_forks_repo_path": "mod_numerical.f90", "max_forks_repo_name": "skphy/ToolboxFortran", "max_forks_repo_head_hexsha": "c1a4dd2188e5b2761ac8d72af64a7ad25c88c2fa", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-04-08T14:15:46.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-16T08:26:29.000Z", "avg_line_length": 29.907444668, "max_line_length": 148, "alphanum_fraction": 0.5009867241, "num_tokens": 12701, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950947024555, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.6976580277489078}} {"text": "c=======================================================================\nc\nc function getMNormalPdf \nc\nc Returns the density function of a multivariate normal random variable\nc\nc-----------------------------------------------------------------------\nc\nc Copyright (c) 2014 NumX\nc All rights reserved.\nc \nc This software is the confidential and proprietary information\nc of NumX. You shall not disclose such Confidential\nc Information and shall use it only in accordance with the terms\nc of the licence agreement you entered into with NumX.\nc\nc Author : Yann Vernaz\nc\nc-----------------------------------------------------------------------\n SUBROUTINE getMNormalPdf(d, x, mu, cov, iwork, dwork, z, info)\nc-----------------------------------------------------------------------\nc\nc INPUT \nc d : dimension (d>0) integer\nc x : data (d) double\nc mu : mean (d) double\nc cov : cov. matrix (d*d) double\nc\nc WORKSPACE\nc iwork : d integer\nc dwork : d*(2*d + 7) double\nc\nc OUTPUT\nc z : multivariate normal Pdf double\nc info : diagnostic argument integer\nc\nc----------------------------------------------------------------------- \nc\nc arguments i/o\n INTEGER d, info\n DOUBLE PRECISION z, x(*), mu(*), cov(d,*)\nc\nc workspaces\n INTEGER iwork(*)\n DOUBLE PRECISION dwork(*)\nc\nc local variables \n LOGICAL select\n INTEGER i, sdim, lwork, pdcov, pdeig, piw, pip, pdv, pdw\n DOUBLE PRECISION PI, invPI, detCOV, s, EPS\n PARAMETER (PI=3.1415926535897932384626433832795028841971693993751)\n PARAMETER (EPS = 1.E-30) \nc\nc intrinsic functions\n INTRINSIC MIN, MAX, SQRT, EXP\nc\nc-----------------------------------------------------------------------\nc\nc initialisations \n info = 0\nc\nc pointers for integer work space : iwork\nc ----------------------------------------\n piw = 1\nc piw : pointer for DGEES, so ( d ) more\nc\nc Total size of dwork array = ( d ) \nc\nc pointers for double precision work space : dwork\nc -------------------------------------------------\n pdcov = 1\nc pdcov : pointer for cov. matrix, so ( d*d ) more\n pdeig = pdcov + ( d*d )\nc pdeig : pointer for eigenvalues, so ( d ) more\n pip = pdeig + ( d )\nc pip : pointer for DGEES, so ( d ) more\n pdv = pip + ( d )\nc pdv : pointer for DGEES, so ( d*d ) more\n pdw = pdv + ( d*d )\nc pdw : pointer for DGEES, so ( 5*d ) more\nc\nc Total size of dwork array = d*(2*d + 7) \nc\nc----------------------------------------------------------------------\nc\nc invPI = (2*PI)^(-d/2)\n invPI = (2.0*PI)**(-d/2) \nc\nc case d=1\n IF (d .EQ. 1) THEN\n variance = MAX(cov(1,1),EPS)\n detCOV = 1.0/SQRT(variance)\n s = ((x(1)-mu(1))**2)/variance\n z = invPI*detCOV*EXP(-0.5*s) \n z = MIN(z, 1.0)\n z = MAX(z, 0.0)\n RETURN\n ENDIF\nc\nc |cov|\n CALL YM ( d, d, cov, dwork(pdcov) )\n sdim = 0\n lwork = 5*d\n CALL DGEES( 'V', 'N', select, d, dwork(pdcov), d,\n & sdim, dwork(pdeig), dwork(pip), dwork(pdv),\n & d, dwork(pdw), lwork, iwork(piw), info )\n detCOV = 1.0\n DO i = 1,d\n detCOV = detCOV*dwork(pdeig + i - 1) \n ENDDO\nc\nc |cov|^(-1/2) \n detCOV = 1./SQRT(detCOV)\nc\nc cov^(-1) \n CALL JMS ( d, cov, dwork(pdv), dwork(pdcov), info )\nc\nc y = x - mu\n CALL DV ( d, x, mu, dwork(pdeig) )\nc\nc (x-mu)'*invCOV*(x-mu)\n CALL OVTMCV ( d, dwork(pdcov), dwork(pdeig), s )\nc\nc EXP(-1/2*[(x - mu)'*(cov^(-1))*(x-mu)])\n s = EXP(-0.5*s)\nc\nc multivariate Normal Pdf\n z = invPI*detCOV*s\n z = MIN(z, 1.0)\n z = MAX(z, 0.0)\nc\n RETURN\n END\n", "meta": {"hexsha": "afe1a4a967866a8d4ec8414d2a2948ce9da7f0c7", "size": 4166, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/rnd/getMNormalPdf.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/getMNormalPdf.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/getMNormalPdf.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": 31.0895522388, "max_line_length": 75, "alphanum_fraction": 0.4270283245, "num_tokens": 1226, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418158002493, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6976485118343676}} {"text": "! examples/Fortran/LanczosBox.f90\n\nmodule lanczos_box_module\n use ral_nlls_double\n implicit none\n integer, parameter :: wp = kind(0d0)\n\n type, extends(params_base_type) :: params_type\n real(wp), dimension(:), allocatable :: t ! The m data points t_i\n real(wp), dimension(:), allocatable :: y ! The m data points y_i\n end type params_type\n\ncontains\n\n subroutine eval_r(status, n, m, x, r, params)\n ! r_i = y_i - x_1 e^(-x_2 t_i) - x_3 e^(-x_4 t_i) - x_5 e^(-x_6 t_i)\n integer, intent(out) :: status\n integer, intent(in) :: n\n integer, intent(in) :: m\n real(wp), dimension(*), intent(in) :: x\n real(wp), dimension(*), intent(out) :: r\n class(params_base_type), intent(inout) :: params\n \n select type(params)\n type is(params_type)\n r(1:m) = params%y(:) &\n - x(1)*exp(-x(2)*params%t(:)) &\n - x(3)*exp(-x(4)*params%t(:)) &\n - x(5)*exp(-x(6)*params%t(:)) \n status = 0 ! success\n return\n Class Default\n stop 'evalr: ERROR do not know how to handle this class...'\n end select\n status = -1 ! fail\n end subroutine eval_r\n\n subroutine eval_J(status, n, m, x, J, params)\n integer, intent(out) :: status\n integer, intent(in) :: n\n integer, intent(in) :: m\n real(wp), dimension(*), intent(in) :: x\n real(wp), dimension(*), intent(out) :: J\n class(params_base_type), intent(inout) :: params\n Integer :: r, c\n\n select type(params)\n type is(params_type)\n J( 1: m) = -exp(-x(2)*params%t(1:m)) ! J_i1\n J( m+1:2*m) = params%t(1:m) * x(1) * exp(-x(2)*params%t(1:m)) ! J_i2\n J(2*m+1:3*m) = -exp(-x(4)*params%t(1:m)) ! J_i3\n J(3*m+1:4*m) = +params%t(1:m) * x(3) * exp(-x(4)*params%t(1:m))! J_i4\n J(4*m+1:5*m) = -exp(-x(6)*params%t(1:m)) ! J_i5\n J(5*m+1:6*m) = +params%t(1:m) * x(5) * exp(-x(6)*params%t(1:m))! J_i6\n status = 0 ! success\n return\n Class Default\n stop 'evalr: ERROR do not know how to handle this class...'\n end select\n status = -1 ! fail\n end subroutine eval_J\n\n subroutine eval_HF(status, n, m, x, r, HF, params)\n integer, intent(out) :: status\n integer, intent(in) :: n\n integer, intent(in) :: m\n real(wp), dimension(*), intent(in) :: x\n real(wp), dimension(*), intent(in) :: r\n real(wp), dimension(*), intent(out) :: HF\n class(params_base_type), intent(inout) :: params\n\n HF(1:n*n) = 0\n select type(params)\n type is(params_type)\n HF( 2) = sum( r(1:m) * params%t(1:m) * exp(-x(2)*params%t(1:m))) ! H_21\n HF(1*n+1) = HF(2) ! H_12\n HF(1*n+2) = sum(-r(1:m) * (params%t(1:m)**2) * x(1) * exp(-x(2)*params%t(1:m)))! H_22\n HF(2*n+4) = sum( r(1:m) * params%t(1:m) * exp(-x(4)*params%t(1:m))) ! H_43\n HF(3*n+3) = HF(2*n+4) ! H_34\n HF(3*n+4) = sum(-r(1:m) * (params%t(1:m)**2) * x(3) * exp(-x(4)*params%t(1:m)))! H_44\n HF(4*n+6) = sum( r(1:m) * params%t(1:m) * exp(-x(6)*params%t(1:m))) ! H_65\n HF(5*n+5) = HF(4*n + 6) ! H_56\n HF(5*n+6) = sum(-r(1:m) * (params%t(1:m)**2) * x(5) * exp(-x(6)*params%t(1:m)))! H_66\n status = 0 ! success\n return\n Class Default\n stop 'evalr: ERROR do not know how to handle this class...'\n end select\n status = -1 ! fail\n end subroutine eval_HF\n \nend module lanczos_box_module\n\nprogram lanczos_box\n use lanczos_box_module\n implicit none\n\n\n type(nlls_options) :: options\n type(nlls_inform) :: inform\n\n integer :: m,n\n real(wp), allocatable :: x(:), xnew(:), blx(:), bux(:)\n type(params_type) :: params\n integer :: i\n real(wp) :: tic, toc\n \n ! data to be fitted\n m = 24\n allocate(params%t(m), params%y(m))\n ! Data from Lanczos 3\n params%t(:) = (/ 0.00000E+00, &\n 5.00000E-02, &\n 1.00000E-01, &\n 1.50000E-01, &\n 2.00000E-01, &\n 2.50000E-01, &\n 3.00000E-01, &\n 3.50000E-01, &\n 4.00000E-01, &\n 4.50000E-01, &\n 5.00000E-01, &\n 5.50000E-01, &\n 6.00000E-01, &\n 6.50000E-01, &\n 7.00000E-01, &\n 7.50000E-01, &\n 8.00000E-01, &\n 8.50000E-01, &\n 9.00000E-01, &\n 9.50000E-01, &\n 1.00000E+00, &\n 1.05000E+00, &\n 1.10000E+00, &\n 1.15000E+00 /)\n params%y(:) = (/ 2.5134E+00, &\n 2.0443E+00, &\n 1.6684E+00, &\n 1.3664E+00, &\n 1.1232E+00, &\n 0.9269E+00, &\n 0.7679E+00, &\n 0.6389E+00, &\n 0.5338E+00, &\n 0.4479E+00, &\n 0.3776E+00, &\n 0.3197E+00, &\n 0.2720E+00, &\n 0.2325E+00, &\n 0.1997E+00, &\n 0.1723E+00, &\n 0.1493E+00, &\n 0.1301E+00, &\n 0.1138E+00, &\n 0.1000E+00, &\n 0.0883E+00, &\n 0.0783E+00, &\n 0.0698E+00, &\n 0.0624E+00 /)\n\n n = 6\n allocate(x(n))\n x = (/ 0.44, -0.2408, 2.598, 3.44, -6.199, 0.0977 /)\n \n ! Add bounds on the variables\n Allocate(blx(n),bux(n),xnew(n))\n blx(1:n) = -1.0\n bux(1:n) = +1.0e+20\n blx(1) = 0.445\n bux(1) = 1.0\n blx(5) = -1.0\n bux(5) = 1.0\n bux(6) = 10.0\n\n options%print_level = 3\n options%maxit = 100\n options%exact_second_derivatives = .true.\n options%model = 3\n options%type_of_method = 1 ! TR / Reg\n options%inner_method = 1 ! Implicit / min / basereg\n options%nlls_method = 4 ! Dogleg / AINT / More-Sorensen (LinSolve) / Galahad\n options%box_max_ntrfail = 2\n\n!!$ Call nlls_setup_bounds(params, n, blx, bux, options, inform)\n!!$ if (inform%status/=0) then\n!!$ Write(*,*) 'ERROR: nlls_setup_bounds failed, status=', inform%status\n!!$ stop\n!!$ End if\n\n\n ! call fitting routine\n call cpu_time(tic)\n call nlls_solve(n,m,x,eval_r, eval_J, eval_HF, params, options, inform, &\n lower_bounds=blx, upper_bounds=bux)\n if(inform%status.ne.0) then\n print *, \"ral_nlls() returned with error flag \", inform%status\n stop\n endif\n call cpu_time(toc)\n\n ! Print result\n Write(*,*) 'Solution: '\n Write(*,Fmt=99998) 'idx', 'low bnd', 'x', 'upp bnd'\n Do i = 1, n\n Write(*,Fmt=99999) i, blx(i), x(i), bux(i)\n End Do\n print *, \"\"\n print *, \"Objective Value at solution = \", inform%obj\n print *, \"Objective Gradient at solution = \", inform%norm_g\n print *, \"Took \", inform%iter, \" iterations (LS:\",inform%ls_step_iter,' PG:',inform%pg_step_iter,')'\n print *, \" \", inform%f_eval, \" function evaluations (LS:\",inform%f_eval_ls,' PG:',inform%f_eval_pg,')'\n print *, \" \", inform%g_eval, \" gradient evaluations (LS:\",inform%g_eval_ls,' PG:',inform%g_eval_pg,')'\n print *, \" \", inform%h_eval, \" hessian (eval Hf) evaluations\"\n print *, \" \", inform%hp_eval, \" hessian (eval_HP) evaluations\"\n print *, \" \", toc-tic, \" seconds\"\n\n99999 Format (5X,I3,1X,3(Es13.6e2,2X))\n99998 Format (5X,A3,1X,3(A13,2X))\n99997 Format (5X,I3,16X,Es13.6e2)\nend program lanczos_box\n", "meta": {"hexsha": "0c308e945f7dda25c58dbc4d3d40ad4858174751", "size": 7556, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "libRALFit/example/Fortran/LanczosBox.f90", "max_stars_repo_name": "ralna/RALFit", "max_stars_repo_head_hexsha": "1d54007935733016fec4029c355fe76d3e18c744", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2018-04-02T12:24:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-14T00:11:45.000Z", "max_issues_repo_path": "libRALFit/example/Fortran/LanczosBox.f90", "max_issues_repo_name": "ralna/RALFit", "max_issues_repo_head_hexsha": "1d54007935733016fec4029c355fe76d3e18c744", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 95, "max_issues_repo_issues_event_min_datetime": "2016-09-13T15:16:54.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-23T14:08:27.000Z", "max_forks_repo_path": "libRALFit/example/Fortran/LanczosBox.f90", "max_forks_repo_name": "ralna/RALFit", "max_forks_repo_head_hexsha": "1d54007935733016fec4029c355fe76d3e18c744", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2018-04-02T12:24:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-23T17:12:42.000Z", "avg_line_length": 34.1900452489, "max_line_length": 108, "alphanum_fraction": 0.4964266808, "num_tokens": 2683, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418158002492, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.697648501642975}} {"text": " real*8 function ew(tz) \n character*100 id,revision,revdate\n data id/'$RCSfile: ew.f,v $'/\n data revision/'$Revision: 1.4 $'/\n data revdate/'$Date: 1994/03/12 17:58:52 $'/\nc \nc this function calculates the saturated partial pressure \nc of water vapor over liquid water (ew) and ice (ei). the \nc formulas are from pruppacher and klett, p.625 \nc \nc tz is absolute temperature, ew is in mb \nc \nc \nc these formulas are valid from -50 c to +50 c \nc for water and -50c to 0 c for ice. \nc if the temperature is outside these ranges, the \nc partial pressure is calculated at the valid temperature \nc limit for t.gt.50 c, and the partial pressure is \nc calculated with an exponential decay from -50 c. \nc \nc \nc \n\n real*8 a0,a1,a2,a3,a4,a5,a6,ta,t,tz,ei,et\n \n a0=6.107799961 \n a1=4.436518521e-01 \n a2=1.428945805e-02 \n a3=2.650648471e-04 \n a4=3.031240396e-06 \n a5=2.034080948e-08 \n a6=6.136820929e-11 \nc \n t=tz-273.16 \n ta=1.0 \n if(t.gt.50.) t=50.0 \n if(t.lt.-50.) then \n ta=t \n t=-50.0 \n end if \n ew=a0+t*(a1+t*(a2+t*(a3+t*(a4+t*(a5+t*a6))))) \n if(ta.lt.-50.0) then \n ew=ew*dexp((ta+50D0)/10.) \n end if \nc \n return \nc \nc \n entry ei(tz) \nc \n a0=6.109177956 \n a1=5.034698970e-01 \n a2=1.886013408e-02 \n a3=4.176223716e-04 \n a4=5.824720280e-06 \n a5=4.838803174e-08 \n a6=1.838826904e-10 \nc \n t=tz-273.16 \n ta=1.0 \n if(t.lt.-50.0) then \n ta=t \n t=-50.0 \n end if \n if(t.gt.0.0) t=0.0 \n et=a0+t*(a1+t*(a2+t*(a3+t*(a4+t*(a5+t*a6))))) \n if(ta.lt.-50.0) then \n et=et*dexp((ta+50.)/10.) \n end if \nc \n ei=et \n return \n end \n", "meta": {"hexsha": "66552f762eb7a5193ce833215afb74463a9e0c54", "size": 4807, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/ew.f", "max_stars_repo_name": "phaustin/empm", "max_stars_repo_head_hexsha": "13bbb7c6568e374c973ea570b064f34a48c6cd8e", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/ew.f", "max_issues_repo_name": "phaustin/empm", "max_issues_repo_head_hexsha": "13bbb7c6568e374c973ea570b064f34a48c6cd8e", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/ew.f", "max_forks_repo_name": "phaustin/empm", "max_forks_repo_head_hexsha": "13bbb7c6568e374c973ea570b064f34a48c6cd8e", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2015-08-24T14:59:46.000Z", "max_forks_repo_forks_event_max_datetime": "2015-08-24T14:59:46.000Z", "avg_line_length": 64.9594594595, "max_line_length": 79, "alphanum_fraction": 0.2032452673, "num_tokens": 738, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067276593031, "lm_q2_score": 0.7401743505760728, "lm_q1q2_score": 0.6976193050588042}} {"text": " Program dsyevx_example\n\n! DSYEVX Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_example_aux, Only: nagf_file_print_matrix_real_gen\n Use lapack_interfaces, Only: dsyevx\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Real (Kind=dp), Parameter :: zero = 0.0E+0_dp\n Integer, Parameter :: nb = 64, nin = 5, nout = 6\n! .. Local Scalars ..\n Real (Kind=dp) :: abstol, vl, vu\n Integer :: i, ifail, il, info, iu, lda, ldz, lwork, m, n\n! .. Local Arrays ..\n Real (Kind=dp), Allocatable :: a(:, :), w(:), work(:), z(:, :)\n Real (Kind=dp) :: dummy(1)\n Integer, Allocatable :: iwork(:), jfail(:)\n! .. Intrinsic Procedures ..\n Intrinsic :: max, nint\n! .. Executable Statements ..\n Write (nout, *) 'DSYEVX Example Program Results'\n Write (nout, *)\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n\n lda = n\n ldz = n\n m = n\n Allocate (a(lda,n), w(n), z(ldz,m), iwork(5*n), jfail(n))\n\n! Read the lower and upper bounds of the interval to be searched.\n Read (nin, *) vl, vu\n\n! Use routine workspace query to get optimal workspace.\n lwork = -1\n Call dsyevx('Vectors', 'Values in range', 'Upper', n, a, lda, vl, vu, &\n il, iu, abstol, m, w, z, ldz, dummy, lwork, iwork, jfail, info)\n\n! Make sure that there is enough workspace for block size nb.\n lwork = max((nb+3)*n, nint(dummy(1)))\n Allocate (work(lwork))\n\n! Read the upper triangular part of the matrix A.\n\n Read (nin, *)(a(i,i:n), i=1, n)\n\n! Set the absolute error tolerance for eigenvalues. With ABSTOL\n! set to zero, the default value is used instead\n\n abstol = zero\n\n! Solve the symmetric eigenvalue problem\n Call dsyevx('Vectors', 'Values in range', 'Upper', n, a, lda, vl, vu, &\n il, iu, abstol, m, w, z, ldz, work, lwork, iwork, jfail, info)\n\n If (info>=0) Then\n\n! Print solution\n\n Write (nout, 100) 'Number of eigenvalues found =', m\n Write (nout, *)\n Write (nout, *) 'Eigenvalues'\n Write (nout, 110) w(1:m)\n Flush (nout)\n\n! ifail: behaviour on error exit\n! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft\n ifail = 0\n Call nagf_file_print_matrix_real_gen('General', ' ', n, m, z, ldz, &\n 'Selected eigenvectors', ifail)\n\n If (info>0) Then\n Write (nout, 100) 'INFO eigenvectors failed to converge, INFO =', &\n info\n Write (nout, *) 'Indices of eigenvectors that did not converge'\n Write (nout, 120) jfail(1:m)\n End If\n Else\n Write (nout, 100) 'Failure in DSYEVX. INFO =', info\n End If\n\n100 Format (1X, A, I5)\n110 Format (3X, (8F8.4))\n120 Format (3X, (8I8))\n End Program\n", "meta": {"hexsha": "ef5623e5d8bbdc9cc6dd36fbd276f7f373078289", "size": 3057, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/dsyevx_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/dsyevx_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/dsyevx_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 32.8709677419, "max_line_length": 90, "alphanum_fraction": 0.5783447825, "num_tokens": 945, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278788223265, "lm_q2_score": 0.7905303260722198, "lm_q1q2_score": 0.6975859987806311}} {"text": "program test_bsplines\nuse types, only: dp\nuse bsplines, only: bspline, bspline_der, bspline_der2\nuse mesh, only: meshexp\nuse quadrature, only: gauss_pts, gauss_wts\nuse linalg, only: eigh\nuse utils, only: stop_error, str\nimplicit none\n\ninteger :: n\n\ndo n = 2, 8\n call do_basis(n, n)\nend do\ncall do_basis(5, 4)\ncall do_basis(8, 4)\ncall do_basis(16, 4)\n\ncontains\n\n subroutine do_basis(n, k)\n integer, intent(in) :: n, k\n integer :: Nq, N_intervals, Nq_total, Nb\n real(dp) :: rmin, rmax, a\n real(dp) :: xa, xb, jac\n real(dp), allocatable :: xq(:), wq(:), hq(:), t(:), xiq(:), wtq(:), x(:)\n real(dp), allocatable :: B(:,:), Bp(:,:), Bpp(:,:)\n integer :: i, u\n print *, \"Constructing B-spline basis n =\", n, \", k =\", k\n Nq = 64\n N_intervals = n-k+1\n Nq_total = Nq*N_intervals\n Nb=n\n\n allocate(t(n+k), xiq(Nq), wtq(Nq), x(Nq))\n allocate(xq(Nq_total), wq(Nq_total), hq(Nq_total))\n allocate(B(Nq_total, n), Bp(Nq_total, n), Bpp(Nq_total, n))\n\n rmin = -1\n rmax = 1\n a = 1\n\n t(:k-1) = rmin\n t(k:n+1) = meshexp(rmin, rmax, a, N_intervals)\n t(n+2:) = rmax\n\n ! Loop over knot spans (intervals), and constract a global quadrature rule\n ! Integrals of a function hq evaluated at the points xq are calculated using:\n ! sum(wq*hq)\n xiq = gauss_pts(Nq)\n wtq = gauss_wts(Nq)\n do i = 1, n-k+1\n xa = t(i+k-1)\n xb = t(i+k)\n jac = (xb-xa)/2\n x = (xiq(:)+1) * jac + xa\n xq((i-1)*Nq+1:i*Nq) = x\n wq((i-1)*Nq+1:i*Nq) = wtq*jac\n end do\n\n ! Evaluate basis functions and their derivatives on quadrature grid\n ! Skip the first and last B-spline (that's why Nb=n-2).\n do i = 1, Nb\n B(:,i) = bspline (t, i, k, xq)\n Bp(:,i) = bspline_der (t, i, k, xq)\n Bpp(:,i) = bspline_der2(t, i, k, xq)\n end do\n\n open(newunit=u, &\n file=\"bspline_basis_n\" // str(n) // \"k\" // str(k) // \".txt\", &\n status=\"replace\")\n write(u,*) t\n write(u,*) xq\n do i = 1, n\n write(u,*) B(:,i)\n write(u,*) Bp(:,i)\n write(u,*) Bpp(:,i)\n end do\n close(u)\n end subroutine\n\nend program\n", "meta": {"hexsha": "39139b0eab1495abe51b3901f4cba7ab7206b977", "size": 2144, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/bsplines/test_bsplines.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/tests/bsplines/test_bsplines.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/tests/bsplines/test_bsplines.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": 25.8313253012, "max_line_length": 81, "alphanum_fraction": 0.5517723881, "num_tokens": 795, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278788223264, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.6975859966032271}} {"text": "!> @ingroup insertion_sort_asc\n!> \n!> @brief \n!> Run an insertion sort on a vector of real values. \n!>\n!> @details \n!> Run an ascending on a vector of real values to sort them in the specified order.\n!>\n!> @param vec\n!> The vector real values to be sorted.\n!>\n!> @author Arin R. Bratt\n!> @date 11/07/2014\npure subroutine insertion_sort_asc_real(vec)\n ! Arguments\n real, intent(inout) :: vec(:)\n \n ! Variables\n real :: real_value\n real :: swap_value\n integer :: i\n integer :: j\n \n \n ! Sort to the first element\n if (vec(size(vec,1)) > vec(1)) then\n real_value = vec(1)\n else\n real_value = vec(size(vec,1))\n vec(size(vec,1)) = vec(1)\n end if\n \n do i = size(vec,1) - 1,2,-1\n if (real_value > vec(i)) then\n ! Swap real values real_value and vec(i).\n swap_value = real_value\n real_value = vec(i)\n vec(i) = swap_value\n end if\n end do\n\n ! Run regualr insertion sort\n do j = 3,size(vec,1)\n swap_value = vec(j)\n i = j - 1\n if (vec(i) > swap_value) then\n vec(j) = vec(i)\n i = i - 1\n do\n if (.not. vec(i) > swap_value) exit\n vec(i + 1) = vec(i)\n i = i - 1\n end do\n vec(i + 1) = swap_value\n end if\n end do\nend subroutine insertion_sort_asc_real\n\n\n", "meta": {"hexsha": "ac3a8e6746db1558d4071062e7bd619a3d8f381d", "size": 1284, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/insertion_sort_asc_real.f90", "max_stars_repo_name": "arinrb/bsort", "max_stars_repo_head_hexsha": "17cc0e2cbe52af808bae860d53dd4e4d691f4674", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-11-08T18:36:23.000Z", "max_stars_repo_stars_event_max_datetime": "2015-11-08T18:36:23.000Z", "max_issues_repo_path": "src/insertion_sort_asc_real.f90", "max_issues_repo_name": "arinrb/bsort", "max_issues_repo_head_hexsha": "17cc0e2cbe52af808bae860d53dd4e4d691f4674", "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/insertion_sort_asc_real.f90", "max_forks_repo_name": "arinrb/bsort", "max_forks_repo_head_hexsha": "17cc0e2cbe52af808bae860d53dd4e4d691f4674", "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": 21.4, "max_line_length": 83, "alphanum_fraction": 0.5724299065, "num_tokens": 409, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303087996143, "lm_q2_score": 0.8824278649085117, "lm_q1q2_score": 0.69758597253951}} {"text": " PROGRAM xrtnewt\r\nC driver for routine rtnewt\r\n INTEGER N,NBMAX\r\n REAL X1,X2\r\n PARAMETER(N=100,NBMAX=20,X1=1.0,X2=50.0)\r\n INTEGER i,nb\r\n REAL bessj0,rtnewt,root,xacc,xb1(NBMAX),xb2(NBMAX)\r\n EXTERNAL funcd,bessj0\r\n nb=NBMAX\r\n call zbrak(bessj0,X1,X2,N,xb1,xb2,nb)\r\n write(*,'(/1x,a)') 'Roots of BESSJ0:'\r\n write(*,'(/1x,t19,a,t31,a/)') 'x','F(x)'\r\n do 11 i=1,nb\r\n xacc=(1.0e-6)*(xb1(i)+xb2(i))/2.0\r\n root=rtnewt(funcd,xb1(i),xb2(i),xacc)\r\n write(*,'(1x,a,i2,2x,f12.6,e16.4)') 'Root ',i,root,bessj0(root)\r\n11 continue\r\n END\r\n SUBROUTINE funcd(x,fn,df)\r\n REAL bessj0,bessj1,df,fn,x\r\n fn=bessj0(x)\r\n df=-bessj1(x)\r\n return\r\n END\r\n", "meta": {"hexsha": "88c8d9a3dfd648d2f8dcb265fa04f345df3a63b9", "size": 749, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xrtnewt.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xrtnewt.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xrtnewt.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.96, "max_line_length": 72, "alphanum_fraction": 0.5380507343, "num_tokens": 314, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148513, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.6975772041904168}} {"text": "program test_besseli\n use types, only: dp\n use constants, only: i_\n use utils, only: assert\n use special, only: besseli\n implicit none\n\n ! check a few value against the ones computed with SciPy:\n integer :: i\n real(dp), parameter :: eps = 1d-14\n real(dp), parameter :: ordersReal(7) = [0.000000000000000_dp, &\n & 1.000000000000000_dp, 2.000000000000000_dp, 3.300000000000000_dp, &\n & 7.000000000000000_dp, -1.500000000000000_dp, -4.000000000000000_dp]\n real(dp), parameter :: xReal(7) = [1.100000000000000_dp, &\n & 3.000000000000000_dp, 10.000000000000000_dp, 2.100000000000000_dp, &\n & 5.500000000000000_dp, 1.100000000000000_dp, 2.000000000000000_dp]\n real(dp), parameter :: xImag(7) = [0.100000000000000_dp, -0.300000000000000_dp, &\n & 2.500000000000000_dp, -1.800000000000000_dp, 2.000000000000000_dp, &\n & 0.500000000000000_dp, 1.500000000000000_dp]\n real(dp), parameter :: correctResultsRealArg(7) = [1.326160183712653_dp,&\n & 3.953370217402610_dp, 2281.518967726004121_dp, &\n & 0.170417364461405_dp, 0.581060275636005_dp, &\n & -0.137839008500075_dp, 0.050728569979180_dp]\n complex(dp), parameter :: correctResultsComplexArg(7) = &\n & [(1.322429481157360_dp, 0.063667990066242_dp), &\n & (3.810081291811203_dp, -1.055482824433039_dp), &\n & (-1717.580096406979010_dp, 1493.230141931700473_dp), &\n & (-0.334007574377871_dp, -0.129806527897784_dp), &\n & (-0.814112770843113_dp, 0.055555790888214_dp), &\n & (0.019170564094263_dp, 0.604067083160980_dp), &\n & (-0.107633719213177_dp, 0.030049276381438_dp)]\n\n ! test real argument with real order:\n do i = 1,7\n call assert(abs(besseli(ordersReal(i), xReal(i)) - correctResultsRealArg(i)) < eps)\n end do\n\n ! test complex data with real order:\n do i = 1,7\n call assert(abs(besseli(ordersReal(i), xReal(i)+i_*xImag(i)) - correctResultsComplexArg(i)) /= eps)\n end do\n\nend program test_besseli\n", "meta": {"hexsha": "e08521dced64a44a2c7b2cb2e62ad950eb6ab5b1", "size": 1939, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/special/test_besseli.f90", "max_stars_repo_name": "wave-scattering/fortran-utils", "max_stars_repo_head_hexsha": "464982bfc96359c7d37d9fd0185c6722e9a70046", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-06-29T13:48:56.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-29T13:48:56.000Z", "max_issues_repo_path": "tests/special/test_besseli.f90", "max_issues_repo_name": "kiranhegde/fortran-utils", "max_issues_repo_head_hexsha": "464982bfc96359c7d37d9fd0185c6722e9a70046", "max_issues_repo_licenses": ["MIT"], "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/special/test_besseli.f90", "max_forks_repo_name": "kiranhegde/fortran-utils", "max_forks_repo_head_hexsha": "464982bfc96359c7d37d9fd0185c6722e9a70046", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-04-18T06:16:13.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-18T06:16:13.000Z", "avg_line_length": 44.0681818182, "max_line_length": 104, "alphanum_fraction": 0.7050025786, "num_tokens": 723, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148512, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6975771943563458}} {"text": "C ******************************************************************\nC ******************************************************************\n\n subroutine moresor(n,g,bnnz,blin,bcol,bval,bdiag,delta,sigma1,\n +sigma2,eps,maxit,l,pd,p,chcnt,memfail,msinfo)\n\n implicit none\n\nC SCALAR ARGUMENTS\n logical memfail,pd\n integer bnnz,chcnt,maxit,msinfo,n\n double precision delta,eps,l,sigma1,sigma2\n\nC ARRAY ARGUMENTS\n integer bcol(bnnz),bdiag(n),blin(bnnz)\n double precision bval(bnnz),g(n),p(n)\n\nC Solves the problem\nC\nC minimize psi(w) = 1/2 w^TBw + g^Tw\nC subject to ||w|| <= delta\nC\nC Using the method described in \"Computing a trust region step\",\nC by More and Sorensen.\n\nC msinfo:\nC\nC 0: both g and B are null\nC 1: first convergence criterion is satisfied\nC 2: second convergence criterion is satisfied\nC 3: third convergence criterion is satisfied\nC 5: maximum allowed number of iterations is achieved\n\n include \"dim.par\"\n include \"machconst.inc\"\n include \"outtyp.inc\"\n\nC LOCAL SCALARS\n integer col,dum,i,idx,iter,lin,lssinfo\n double precision b1n,d,delta2,geucn,ll,llant,ls,lsant,lu,luant,\n + peucn,peucn2,ptz,rpeucn2,rzeucn2,sgn,tau,teucn2,tmp,ueucn2\n\nC LOCAL ARRAYS\n integer wi(nmax)\n double precision t(nmax),wd(nmax),z(nmax)\n\n delta2 = delta**2\n\n msinfo = 0\n\n memfail = .false.\n\n call lssini(.false.,.false.,.true.)\n\nC step 1: initialize ls (lower bound on l) with max{-bii}, where bii\nC are the elements of the diagonal of B\n\n ls = -bval(bdiag(1))\n\n do i = 2,n\n lin = bdiag(i)\n ls = max( ls, -bval(lin) )\n end do\n\nC Calculate ||B||1, B sparse\n\n do i = 1,n\n wd(i) = 0.0d0\n end do\n\n do i = 1,bnnz\n lin = blin(i)\n col = bcol(i)\n\n if ( ( lin .le. n ) .and. ( col .le. n ) ) then\n wd(col) = wd(col) + abs( bval(i) )\n if ( lin .ne. col ) then\n wd(lin) = wd(lin) + abs( bval(i) )\n end if\n end if\n end do\n\n b1n = wd(1)\n do i = 2,n\n b1n = max( b1n, wd(i) )\n end do\n\nC step 2: initialize ll (lower bound on l) with\nC max{0, ls, ||g||/delta - ||B||1}, where ||B||1 is the\nC 1-norm of the matrix B\n\n geucn = 0.0d0\n do i = 1,n\n geucn = geucn + g(i)**2\n end do\n geucn = sqrt( geucn )\n\n ll = (geucn / delta) - b1n\n ll = max( 0.0d0, ll )\n ll = max( ls, ll )\n\nC step 3: initialize lu (upper bound on l) with ||g||/delta + ||B||1\n\n lu = (geucn / delta) + b1n\n\nC If the matrix is null, there is nothing to be done\n\n if ( ( abs( ll ) .le. macheps23 ) .and.\n + ( abs( lu ) .le. macheps23 ) .and.\n + ( abs( ls ) .le. macheps23 ) ) then\n msinfo = 0\n go to 21\n end if\n\nC step 4: initialize iteration counter\n\n iter = 1\n\n call lssana(n,bnnz,blin,bcol,bval,bdiag,lssinfo)\n\n if ( lssinfo .eq. 6 ) then\n ! INSUFFICIENT SPACE TO STORE THE LINEAR SYSTEM\n\n memfail = .true.\n return\n\n else if ( lssinfo .eq. 7 ) then\n ! INSUFFICIENT DOUBLE PRECISION WORKING SPACE\n\n memfail = .true.\n return\n\n else if ( lssinfo .eq. 8 ) then\n ! INSUFFICIENT INTEGER WORKING SPACE\n\n memfail = .true.\n return\n\n end if\n\nC step 5: safeguard of l (ensures that l is bigger than ll)\n\n 5 continue\n\n l = max( l, ll )\n\nC step 6: safeguard of l (ensures that l is smaller than lu)\n\n l = min( l, lu )\n\nC step 7: safeguard of l\n\n if ( ( l .le. ls + macheps23 * max( abs( ls ), 1.0d0 ) )\n + .and. ( iter .ne. 1 ) ) then\n l = max( 1.0d-3 * lu, sqrt( ll*lu ) )\n end if\n\nC step 8: try to use the Cholesky decomposition: (B +lI) = R^TR.\nC If the decomposition is successfull, R is stored in the\nC upper triangular portion of B (including the diagonal) and\nC pd is set to true.\nC If the decomposition fails, d and idx are set as explained\nC before, pd is set to false, and the Euclidian-norm of u is\nC calculated (see explanation of variable ueucn2)\n\n do i = 1,n\n wd(i) = l\n end do\n\n call lssfac(n,bnnz,blin,bcol,bval,bdiag,wd,idx,d,dum,lssinfo)\n chcnt = chcnt + 1\n\n if ( lssinfo .eq. 6 ) then\n ! INSUFFICIENT SPACE TO STORE THE LINEAR SYSTEM\n\n memfail = .true.\n return\n\n else if ( lssinfo .eq. 7 ) then\n ! INSUFFICIENT DOUBLE PRECISION WORKING SPACE\n\n memfail = .true.\n return\n\n else if ( lssinfo .eq. 8 ) then\n ! INSUFFICIENT INTEGER WORKING SPACE\n\n memfail = .true.\n return\n\n end if\n\n if ( ( lssinfo .eq. 1 ) .or. ( lssinfo .eq. 2 ) ) then\n pd = .false.\n else ! lssinfo .eq. 0\n pd = .true.\n end if\n\nC In this case (B + lI) is not positive definite, and d and idx are\nC calculated. Because p cannot be calculated (it is not possible to\nC solve the system using Cholesky factorization), the values of l,\nC ll and ls are updated, the iteration counter is increased and a\nC new iteration is started\n\n if ( .not. pd ) then\n\nC Print information (current iteration)\n\n if ( iprintinn .ge. 5 ) then\nC write(*, 1000) iter\nC write(*, 1010) ls,ll,lu,l\nC write(*, 1070)\n\n write(10,1000) iter\n write(10,1010) ls,ll,lu,l\n write(10,1070)\n end if\n\n llant = ll\n luant = lu\n lsant = ls\n\n if ( lu-l .le. macheps23 * max( abs( lu ),1.0d0 ) ) then\n lu = lu + macheps23 * max( abs( lu ),1.0d0 )\n l = lu\n else\n call scalcu(n,bnnz,blin,bcol,bval,bdiag,l,idx,p,ueucn2,wd,\n + memfail)\n chcnt = chcnt + 1\n\n if ( memfail ) then\n go to 22\n end if\n\n ll = max( l, ll )\n ls = max( l + (d / ueucn2), ls )\n ll = max( ll, ls )\n l = ls\n end if\n\n iter = iter + 1\n\nC Test whether the number of iterations is exhausted\n\n if ( iter .gt. maxit ) then\n msinfo = 5\n\n if ( iprintinn .ge. 5 ) then\nC write(*, 1090)\n write(10,1090)\n end if\n\n go to 22\n end if\n\n go to 5\n end if\n\nC step 9: solve R^TRp = -g for p and calculate the squared\nC Euclidian-norm of p\n\n do i = 1,n\n p(i) = -g(i)\n end do\n\n call lsssol(n,p)\n\nC Euclidian-norm of Rp = p^T R^TRp = p^T (-g) = - p^Tg\n\n rpeucn2 = 0.0d0\n do i = 1,n\n rpeucn2 = rpeucn2 - p(i) * g(i)\n end do\n\n peucn2 = 0.0d0\n do i = 1,n\n peucn2 = peucn2 + p(i)**2\n end do\n peucn = sqrt( peucn2 )\n\nC step 10: calculate z and tau, where tau * z is the approximation\nC of the eigenvector associated with the smallest\nC eigenvalue of B\n\n if ( peucn .lt. delta ) then\n\nC Calculate z\n\n call scalcz(n,wi,wd,z)\n\nC Calculate z Euclidian-norm\n\n tmp = 0.0d0\n do i = 1,n\n tmp = tmp + z(i)**2\n end do\n tmp = sqrt( tmp )\n\nC Divide z by its norm\n\n do i = 1,n\n z(i) = z(i) / tmp\n end do\n\nC Calculate the squared Euclidian-norm of the product Rz.\nC Note that z^T R^T Rz = z^T (B + lI) z\n\n do i = 1,n\n wd(i) = 0.0d0\n end do\n\n do i = 1,bnnz\n lin = blin(i)\n col = bcol(i)\n\n if ( lin .eq. col ) then\n wd(lin) = wd(lin) + (bval(i) + l) * z(col)\n else\n wd(lin) = wd(lin) + bval(i) * z(col)\n wd(col) = wd(col) + bval(i) * z(lin)\n end if\n end do\n\n rzeucn2 = 0.0d0\n do i = 1,n\n rzeucn2 = rzeucn2 + z(i) * wd(i)\n end do\n\nC Calculate tau\n\n ptz = 0.0d0\n do i = 1,n\n ptz = ptz + p(i) * z(i)\n end do\n\n if ( ptz .lt. 0.0d0 ) then\n sgn = -1.0d0\n else\n sgn = 1.0d0\n end if\n\n tmp = delta2 - peucn2\n\n tau = (ptz**2) + tmp\n tau = tmp / (ptz + sgn * sqrt( tau ))\n\n end if\n\nC Print informations (current iteration)\n\n if ( iprintinn .ge. 5 ) then\nC write(*, 1000) iter\nC write(*, 1010) ls,ll,lu,l\nC write(*, 1020) peucn\n\n write(10,1000) iter\n write(10,1010) ls,ll,lu,l\n write(10,1020) peucn\n\n if ( peucn .lt. delta ) then\nC write(*, 1030) sqrt( peucn2 + 2 * tau * ptz + tau ** 2 )\n write(10,1030) sqrt( peucn2 + 2 * tau * ptz + tau ** 2 )\n else\nC write(*, 1030) peucn\n write(10,1030) peucn\n end if\n\nC write(*, 1050) delta\n write(10,1050) delta\n end if\n\nC steps 11 and 12: update ll, lu and ls\n\n llant = ll\n luant = lu\n lsant = ls\n\n if ( peucn .lt. delta ) then\n lu = min( l, lu )\n ls = max( l - rzeucn2, ls )\n else\n ll = max( l, ll )\n end if\n\nC step 13: update ls when B + lI is not positive definite.\nC This was done right after the Cholesky decomposition\nC failure\n\nC step 14: update ll\n\n ll = max( ll, ls )\n\nC step 15: convergence test\n\n if ( ( abs( l ) .le. eps ) .and. ( peucn .le. delta ) ) then\n msinfo = 1\n go to 21\n end if\n\nC step 16: second convergence test\n\n if ( abs( delta - peucn ) .le. sigma1*delta ) then\n msinfo = 2\n end if\n\nC step 17: convergence test for the hard case\n\n tmp = rpeucn2 + l * delta2\n tmp = max( sigma2, tmp )\n tmp = tmp * sigma1 * (2 - sigma1)\n\n if ( ( peucn .lt. delta ) .and. ( (rzeucn2*(tau**2) .le. tmp )\n + .or. (lu - ll .le. eps) ) ) then\n\n msinfo = msinfo + 3\n go to 20\n end if\n\n if ( msinfo .eq. 2 ) then\n go to 21\n end if\n\nC step 21: Calculate l to be used in the next iteration\n\n if ( ( abs( geucn ) .gt. eps ) .or.\n + ( ( l .le. ll + macheps23 * max( abs( ll ), 1.0d0 ) )\n + .and. ( ls .le. ll ) ) ) then\n\nC Solve R^T t = p for t and calculate t squared Euclidian-norm\n\n do i = 1,n\n t(i) = p(i)\n end do\n\n call lsssoltr('T',n,t)\n\n teucn2 = 0.0d0\n do i = 1,n\n teucn2 = teucn2 + t(i)**2\n end do\n\nC Update l using Newton's method update\n\n l = l + (peucn2 / teucn2) * ((peucn - delta) / delta)\n else\n l = ls\n end if\n\nC step 22: update iteration counter\n\n iter = iter + 1\n\nC Test whether the number of iterations is exhausted\n\n if ( iter .gt. maxit ) then\n msinfo = 5\n\n if ( iprintinn .ge. 5 ) then\nC write(*, 1090)\n write(10,1090)\n end if\n\n go to 22\n end if\n\nC step 23: start a new iteration\n\n if ( ( abs( llant-ll ) .le.\n + macheps23 * max( abs( ll ), 1.0d0 ) ) .and.\n + ( abs( luant-lu ) .le.\n + macheps23 * max( abs( lu ), 1.0d0 ) ) .and.\n + ( abs( lsant-ls ) .le.\n + macheps23 * max( abs( ls ), 1.0d0 ) ) ) then\n\n ll = ll + macheps23 * max( abs( ll ), 1.0d0 )\n lu = lu - macheps23 * max( abs( lu ), 1.0d0 )\n end if\n\n go to 5\n\nC steps 18, 19 and 20:\n\nC The solution is given by p in 3 cases:\nC - if the first convergence criterion is satisfied;\nC - if only the second convergence criterion is satisfied;\nC - if both the second and the third convergence criteria are\nC satisfied, but the squared Euclidian-norm of R(tau*z) is\nC strictly bigger than l*(delta2 - peucn2)\n\nC The solution is given by p + tau*z when:\nC - just the third convergence criterion is satisfied;\nC - both the second and the third convergence criteria are\nC satisfied, but the squared Euclidian-norm of R(tau*z) is smaller\nC or equal to l*(delta2 - peucn2)\n\n 20 tmp = (rzeucn2 * (tau**2)) - l * (delta2 - peucn2)\n\n if ( ( msinfo .eq. 3 ) .or.\n + ( ( msinfo .eq. 5 ) .and. ( tmp .le. 0.0d0 ) ) ) then\n\n peucn2 = 0.0d0\n do i = 1,n\n p(i) = p(i) + tau * z(i)\n peucn2 = peucn2 + p(i)**2\n end do\n peucn = sqrt( peucn2 )\n\n msinfo = 3\n else\n msinfo = 2\n end if\n\nC Print informations\n\n 21 if ( iprintinn .ge. 5 ) then\nC write(*, 1060) iter\nC write(*, 1010) ls,ll,lu,l\nC write(*, 1080)\nC write(*, 1040) peucn\n\n write(10,1060) iter\n write(10,1010) ls,ll,lu,l\n write(10,1080)\n write(10,1040) peucn\n end if\n\n 22 continue\n\nC Non-executable statements\n\n 1000 format(/,10X,'More-Sorensen iteration: ',I7)\n 1010 format( 10X,'ls = ',1P,D11.4,\n + 10X,'ll = ',1P,D11.4,\n + 10X,'lu = ',1P,D11.4,\n + 10X,'l = ',1P,D11.4)\n 1020 format( 10X,'Euclidian-norm of p: ',1P,D7.1)\n 1030 format( 10X,'Euclidian-norm of p + z: ',1P,D7.1)\n 1040 format( 10X,'Euclidian-norm of step: ',1P,D7.1)\n 1050 format( 10X,'delta: ',1P,D7.1)\n 1060 format( 10X,'Number of iterations: ',I7)\n 1070 format( 10X,'Matrix is not positive definite!')\n\n 1080 format( 10X,'Flag of More-Sorensen: ',\n + 'convergence criterion satisfied.')\n 1090 format( 10X,'Flag of More-Sorensen: ',\n + 'maximum number of iterations achieved.')\n\n end\n\nC ******************************************************************\nC ******************************************************************\n\n subroutine scalcu(n,annz,alin,acol,aval,adiag,l,idx,u,ueucn2,wd,\n +memfail)\n\n implicit none\n\nC SCALAR ARGUMENTS\n logical memfail\n integer annz,idx,n\n double precision l,ueucn2\n\nC ARRAY ARGUMENTS\n integer acol(annz),adiag(n),alin(annz)\n double precision aval(annz),u(idx),wd(idx-1)\n\nC Solves a sparse linear system of the form (A + lI + ekek^Td)u = 0,\nC where A + lI is a definite positive matrix in R^{k x k}.\nC u is a vector of k positions with u(k) = 1.\n\nC LOCAL SCALARS\n integer col,i,lin,lssinfo\n\n if ( idx .eq. 1 ) then\n u(idx) = 1.0d0\n ueucn2 = 1.0d0\n return\n end if\n\n do i = 1,idx\n u(i) = 0.0d0\n end do\n\nC Permute columns and rows of A\n\n call lsspermind(annz,alin,acol)\n\nC Eliminate columns that have index greater than idx and define u\nC as idx-th column of A + lI\n\n do i = 1,annz\n col = acol(i)\n lin = alin(i)\n\n if ( ( col .eq. idx ) .and. ( lin .lt. idx ) ) then\n u(lin) = u(lin) - aval(i)\n else if ( ( lin .eq. idx ) .and. ( col .lt. idx ) ) then\n u(col) = u(col) - aval(i)\n end if\n\n if ( ( col .ge. idx ) .or. ( lin .ge. idx ) ) then\n acol(i) = col + n\n alin(i) = lin + n\n end if\n end do\n\nC Solve system (A + lI)x = u\n\n call lssini(.false.,.true.,.false.)\n\n call lsspermvec(n,adiag)\n\n do i = 1,idx-1\n wd(i) = l\n end do\n\n call lssafsol(idx-1,annz,alin,acol,aval,adiag,wd,u,lssinfo)\n\n if ( lssinfo .eq. 6 ) then\n ! INSUFFICIENT SPACE TO STORE THE LINEAR SYSTEM\n\n memfail = .true.\n return\n\n else if ( lssinfo .eq. 7 ) then\n ! INSUFFICIENT DOUBLE PRECISION WORKING SPACE\n\n memfail = .true.\n return\n\n else if ( lssinfo .eq. 8 ) then\n ! INSUFFICIENT INTEGER WORKING SPACE\n\n memfail = .true.\n return\n\n end if\n\n call lssunpermvec(n,adiag)\n\n call lssini(.false.,.false.,.true.)\n\nC Undo modifications in acol and alin\n\n do i = 1,annz\n col = acol(i)\n\n if ( col .gt. n ) then\n acol(i) = acol(i) - n\n alin(i) = alin(i) - n\n end if\n end do\n\n call lssunpermind(n,annz,alin,acol)\n\n u(idx) = 1.0d0\n\n ueucn2 = 0.0d0\n do i = 1,idx\n ueucn2 = ueucn2 + u(i)**2\n end do\n\n end\n\nC ******************************************************************\nC ******************************************************************\n\n subroutine scalcz(n,rowind,rowval,z)\n\n implicit none\n\nC SCALAR ARGUMENTS\n integer n\n\nC ARRAY ARGUMENTS\n integer rowind(n)\n double precision rowval(n),z(n)\n\nC Sparse implementation of the technique presented by Cline, Moler,\nC Stewart and Wilkinson to estimate the condition number of a upper\nC triangular matrix.\n\n include \"machconst.inc\"\n\nC LOCAL SCALARS\n integer col,i,k,rownnz\n double precision acs,acz,d,ek,rki,s,sm,w,wk,wkm\n double precision lssgetd\n\nC EXTERNAL FUNCTIONS\n external lssgetd\n\n call lsssetrow(n)\n\n do i = 1,n\n z(i) = 0.0d0\n end do\n\n acz = 0.0d0\n acs = 1.0d0\n ek = 1.0d0\n\n do k = 1,n\n d = lssgetd(k)\n\n if ( abs( acs*z(k) ) .gt. macheps23 ) then\n ek = dsign(ek,-acs*z(k))\n end if\n\n if ( abs( ek - acs*z(k) ) .gt. abs( d ) ) then\n s = abs( d ) / abs( ek - acs*z(k) )\n acs = acs * s\n ek = s * ek\n end if\n\n wk = ek - acs * z(k)\n wkm = -ek - acs * z(k)\n s = abs( wk )\n sm = abs( wkm )\n\n if ( d .eq. 0.0d0 ) then\n wk = 1.0d0\n wkm = 1.0d0\n else\n wk = wk / d\n wkm = wkm / d\n end if\n\n if ( k .eq. n ) then\n go to 10\n end if\n\n call lssgetrow(n,k,rownnz,rowind,rowval)\n\n sm = sm + acs * acz\n\n do i = 1,rownnz\n\n col = rowind(i)\n if ( col .gt. k ) then\n rki = rowval(i)\n sm = sm - abs( acs * z(col) )\n sm = sm + abs( acs * z(col) + wkm * rki )\n acz = acz - abs( z(col) )\n acz = acz + abs( z(col) + (wk/acs) * rki )\n z(col) = z(col) + (wk/acs) * rki\n end if\n end do\n\n s = s + acs * acz\n\n if ( s .lt.\n + sm - macheps23 * max( abs( sm ), 1.0d0 ) ) then\n w = wkm - wk\n wk = wkm\n\n do i = 1,rownnz\n\n col = rowind(i)\n if ( col .gt. k ) then\n rki = rowval(i)\n acz = acz - abs( z(col) )\n acz = acz + abs( z(col) + (w/acs) * rki )\n z(col) = z(col) + (w/acs) * rki\n end if\n end do\n\n end if\n acz = acz - abs( z(k+1) )\n 10 z(k) = wk/acs\n end do\n\nC Divide z by its 1-norm to avoid overflow\n\n s = 0.0d0\n do i = 1,n\n s = s + abs( z(i) )\n end do\n\n do i = 1,n\n z(i) = z(i) / s\n end do\n\nC Solve Rz = y\n\n call lsssoltr(' ',n,z)\n\n end\n\nC ******************************************************************\nC ******************************************************************\n\nC moresor:\nC\nC Method to minimize sparse quadratic functions subjected to\nC ||w|| <= delta\nC\nC minimize psi(w) = 1/2 w^TBw + g^Tw\nC subject to ||w|| <= delta\nC\nC Method described in \"Computing a trust region step\", by More and\nC Sorensen.\nC\nC The main ideia of this method is to find a positive scalar \\mslamb\nC that is a zero of the function\nC\nC phi(\\mslamb) = 1/||p|| - 1/delta,\nC\nC where p is the solution of the linear system\nC\nC (B + \\mslamb I)p = -g.\nC\nC Note that symmetric matrix B, vector g and positive real number\nC delta are presented in the minimization problem above. I is the\nC identity matrix.\nC\nC The method used to find the zero of that function is basically the\nC Newton method to find roots.\nC\nC On Entry\nC\nC n integer\nC dimension\nC\nC g double precision g(n)\nC vector used to define the quadratic function\nC\nC bnnz integer\nC number of nonzero elements of B\nC\nC blin integer blin(bnnz)\nC row indices of nonzero elements of B\nC\nC bcol integer bcol(bnnz)\nC column indices of nonzero elements of B\nC\nC bval double precision bval(bnnz)\nC nonzero elements of B, that is,\nC B(blin(i),bcol(i)) = bval(i). Since B is symmetric, just\nC one element B(i,j) or B(j,i) must appear in its sparse\nC representation. If more than one pair corresponding to\nC the same position of B appears in the sparse\nC representation, the multiple entries will be summed.\nC If any blin(i) or bcol(i) is out of range, the entry will\nC be ignored\nC\nC bdiag integer bdiag(n)\nC indices of diagonal elements of B in blin, bcol and bval\nC\nC delta double precision\nC trust-region radius\nC\nC sigma1 double precision\nC allowed error for convergence criteria 1 and 2\nC\nC sigma2 double precision\nC allowed error for convergence criteria 3 (hard case)\nC\nC eps double precision\nC allowed error\nC\nC maxit integer\nC maximum number of allowed iterations\nC\nC l double precision\nC initial value for mslamb\nC\nC On Return\nC\nC l double precision\nC value that gives p as a solution to the minimization\nC problem, because p is also solution to\nC (B + l I)p = -g\nC\nC pd logical\nC set to true if the last Cholesky decomposition is\nC successfull\nC\nC p double precision p(n)\nC solution to problem\nC minimize psi(w)\nC subjected to ||w|| <= delta\nC\nC chcnt integer\nC number of Cholesky decompositions\nC\nC memfail logical\nC true iff linear solver failed because of lack of memory\nC\nC msinfo integer\nC stores which convergence criteria was satisfied:\nC\nC 0 = both g and B are null;\nC\nC 1 = first convergence criterion is satisfied;\nC\nC 2 = second convergence criterion is satisfied;\nC\nC 3 = third convergence criterion is satisfied\nC\nC 5 = maximum allowed number of iterations is achieved.\n\nC ******************************************************************\nC ******************************************************************\n\nC scalcu:\nC\nC Solve a sparse linear system of the form (A + lI + ekek^Td)u = 0,\nC where A + lI is a definite positive matrix in R^{k x k}.\nC u is a vector of k positions with u(k) = 1.\nC\nC On Entry\nC\nC n integer\nC dimension of A\nC\nC annz integer\nC number of nonzero elements of A\nC\nC alin integer alin(annz)\nC row indices of nonzero elements of A\nC\nC acol integer acol(annz)\nC column indices of nonzero elements of A\nC\nC aval integer aval(annz)\nC nonzero elements of A, that is,\nC A(alin(i),acol(i)) = aval(i). Since A is symmetric, just\nC one element A(i,j) or A(j,i) must appear in its sparse\nC representation. If more than one pair corresponding to\nC the same position of A appears in the sparse\nC representation, the multiple entries will be summed.\nC If any alin(i) or acol(i) is out of range, the entry will\nC be ignored\nC\nC adiag integer adiag(n)\nC indices of diagonal elements of A in alin, acol and aval\nC\nC l double precision\nC used to compute A + lI\nC\nC idx integer\nC index k\nC\nC On Return\nC\nC u double precision u(n)\nC system solution\nC\nC ueucn2 double precision\nC u squared Euclidian-norm\nC\nC memfail logical\nC true iff linear solver failed because of lack of memory\n\nC ******************************************************************\nC ******************************************************************\n\nC scalcz:\nC\nC Sparse implementation of the technique presented by Cline, Moler,\nC Stewart and Wilkinson to estimate the condition number of a matrix.\nC This technique is used by the More-Sorensen method to calculate an\nC approximation to the eigenvector associated to the smallest\nC eigenvalue of a matrix B (\\mslamb_1).\nC In this technique, when \\mslamb approaches -\\mslamb_1, \\|Rz\\|\nC approaches 0. This insures that z is an approximation to the\nC wanted eigenvector.\nC Basically, it solves R^Ty = e, choosing e(k) as 1 or -1 (whatever\nC gives maximum local growth of y). Then, it solves Rz = y.\nC Note that R is a sparse matrix given by P^T D^0.5 L^T P (obtained\nC applying subroutine MA27BD).\nC\nC On Entry\nC\nC n integer\nC dimension of R\nC\nC rowind integer rowind(n)\nC rowval double precision rowval(n)\nC working arrays\nC\nC On Return\nC\nC z double precision z(n)\nC approximation of the eigenvector of B associated to\nC \\mslamb_1\n", "meta": {"hexsha": "41d0999a281cf5c5f38a422803643018ffc73d56", "size": 25970, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "docker/optimization/pyOpt/tags/v1.2.0/pyOpt/pyALGENCAN/source/moresor.f", "max_stars_repo_name": "liujiamingustc/phd", "max_stars_repo_head_hexsha": "4f815a738abad43531d02ac66f5bd0d9a1def52a", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-01-06T03:01:18.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T03:02:55.000Z", "max_issues_repo_path": "docker/optimization/pyOpt/tags/v1.2.0/pyOpt/pyALGENCAN/source/moresor.f", "max_issues_repo_name": "liujiamingustc/phd", "max_issues_repo_head_hexsha": "4f815a738abad43531d02ac66f5bd0d9a1def52a", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docker/optimization/pyOpt/tags/v1.2.0/pyOpt/pyALGENCAN/source/moresor.f", "max_forks_repo_name": "liujiamingustc/phd", "max_forks_repo_head_hexsha": "4f815a738abad43531d02ac66f5bd0d9a1def52a", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.2854251012, "max_line_length": 73, "alphanum_fraction": 0.4971120524, "num_tokens": 7934, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297941266013, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.6975354248479246}} {"text": "! This version solves the Schroedinger equation for the \n! one-dimensional \n! harmonic oscillator using matrix diagonalization\n\n! declaration of constants used in the calculations\n! define variables, where we have chosen to use atomic units for \n! m=c=hbar=k=1. \n\n! This module contains all constants and declarations \n! of variables read in by the function read_data. These\n! variables are used by many functions.\n\nMODULE constants\n INTEGER, PARAMETER :: dp = KIND(1.0D0)\n INTEGER, PARAMETER :: dpc = KIND((1.0D0,1.0D0))\nEND MODULE constants\n\nMODULE parameters \n USE constants\n ! the step\n REAL(DP), PUBLIC :: step\n ! r min\n REAL(DP), PUBLIC, PARAMETER :: rmin=-10.0_dp\n ! r max\n REAL(DP), PUBLIC, PARAMETER :: rmax=10.0_dp\n ! number of steps from rmin to rmin to rmax\n INTEGER, PUBLIC, PARAMETER :: max_step=1000\n ! size of matrix to be diagonalized, do not need points at rmin and rmax\n INTEGER, PUBLIC, PARAMETER :: n=998\nEND MODULE parameters\n\n! main program starts here\n\nPROGRAM schroedinger_equation\n USE constants\n USE parameters\n! USE f90library\n IMPLICIT NONE\n REAL(DP) :: potential, const1, const2\n REAL(DP), DIMENSION(:), ALLOCATABLE :: w, r\n REAL(DP), ALLOCATABLE, DIMENSION(:) :: e, d\n REAL(DP), ALLOCATABLE, DIMENSION(:,:) :: z\n INTEGER :: i\n\n ! reserve place in memory for the arrays w, r, e, d and z\n\n ALLOCATE ( e(n) , d(n))\n ALLOCATE ( w(0:max_step), r(0:max_step))\n\n ! define the step size\n\n step=(rmax-rmin)/FLOAT(max_step)\n\n ! define constants for the matrix to be diagonalized\n\n const1=2./(step*step)\n const2=-1./(step*step)\n\n ! set up r and the function w for energy =0\n ! w corresponds then to the potential\n ! values at \n\n DO i=0, max_step\n r(i) = rmin+i*step\n w(i) = potential(r(i))\n ENDDO\n\n ! setup the diagonal d and the non-diagonal part e of\n ! the tri-diagonal matrix to be diagonalized\n\n d(1:n)=const1+w(1:n) ; e(1:n)=const2\n\n ! allocate space for eigenvector info\n\n ALLOCATE ( z(n,n) )\n\n ! obtain the eigenvalues\n\n CALL tqli(d,e,n,z)\n\n ! sort eigenvalues as an ascending series \n\n CALL eigenvalue_sort(d,n)\n\n ! write out \n\n WRITE(6,*) ' Rmin and Rmax ', rmin, rmax\n WRITE(6,*) ' Number of steps -1 ', n\n WRITE(6,*) ' The 5 lowest eigenvalues '\n WRITE(6,'(5F12.6)') d(1:5)\n\n ! find the wave function for the lowest lying state\n\n CALL plot(d(1), w, r) \n\n ! deallocate space in memory\n\n DEALLOCATE (z)\n DEALLOCATE ( w, r, d, e)\n\nEND PROGRAM schroedinger_equation\n\n! Harmonic oscillator potential\n\nREAL(DP) FUNCTION potential(x)\n USE constants\n IMPLICIT NONE\n REAL(DP), INTENT(IN) :: x\n\n potential=x*x\n\nEND FUNCTION potential\n\n\n!\n! Sort the eigenvalues as\n! ascending series \n!\n\nSUBROUTINE eigenvalue_sort(e,n)\n USE constants\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: n\n INTEGER :: i, j\n REAL(DP), DIMENSION(n), INTENT(INOUT) :: e\n REAL(DP) :: temp\n\n DO i = 1, n\n DO j =i, n\n IF( ABS(e(i)) > ABS(e(j)) ) THEN\n ! change the energy \n temp=e(i)\n e(i)=e(j)\n e(j)=temp\n ENDIF\n ENDDO\n ENDDO\n\nEND SUBROUTINE eigenvalue_sort\n\n\n\n! This function plots the wave function at the final energy\n\nSUBROUTINE plot(energy, w ,r )\n USE constants\n USE parameters\n IMPLICIT NONE\n INTEGER :: i, match\n REAL(DP), DIMENSION(n) :: w, r\n REAL(DP), DIMENSION(:), ALLOCATABLE :: wf\n REAL(DP) :: energy, wwf, fac, norm, pi\n\n ALLOCATE ( wf(0:max_step))\n pi=ACOS(-1.) ; pi=SQRT(pi)\n\n ! add the chosen energy to the potential \n\n w=(w-energy)*step*step+2\n\n ! Boundary conditions\n ! value of the wave function at max step\n\n wf(max_step)=0.\n\n ! here we use the analytical form for the wave function for max step -1\n ! (taylor expansion of EXP(-r^2/2))\n\n wf(max_step-1)=step**2/2.\n\n ! start from right and move towards rmin\n\n OUTER_TO_INNER : DO\n DO i=max_step-2, 1, -1\n wf(i)=w(i+1)*wf(i+1)-wf(i+2)\n ! find point were the outer part starts turning in order to determine matching point\n IF ( wf(i) <= wf(i+1) ) EXIT OUTER_TO_INNER \n ENDDO\n ENDDO OUTER_TO_INNER\n match = i+1\n wwf=wf(match)\n\n ! start from rmin and move towards the matching point\n\n wf(0)=0.\n wf(1)=step**2/2.\n DO i=2, match\n wf(i)=w(i-1)*wf(i-1)-wf(i-2)\n ENDDO\n\n ! scale the wave function below the matching point\n\n fac=wwf/wf(match)\n wf(0:match)=wf(0:match)*fac\n\n ! normalize the wave function\n\n norm=step*SUM(wf*wf)\n IF ( norm > 0. ) norm = 1./SQRT(norm)\n wf=wf*norm\n WRITE(6,*) norm \n ! write out of numerically calculated and analytical expression for the wave functions\n\n WRITE(6,'(E12.6,2X,E12.6,2X,E12.6)')( r(i), wf(i), EXP(-(r(i)**2)/2.0_dp)/SQRT(pi),i=1, max_step)\n DEALLOCATE ( wf) \n\nEND SUBROUTINE plot\n\n\n\n\n\n\n\n REAL (DP) FUNCTION pythag(a,b)\n USE constants\n REAL(DP) :: a,b\n REAL(DP) :: absa,absb\n absa=ABS(a)\n absb=ABS(b)\n IF(absa > absb) THEN\n pythag=absa*sqrt(1.+(absb/absa)**2)\n ELSE\n IF(absb == 0.) THEN\n pythag=0.\n ELSE\n pythag=absb*sqrt(1.+(absa/absb)**2)\n ENDIF\n ENDIF\n\n END FUNCTION pythag\n\n\n ! determine eigenvalues and eigenvectors of a real symmetric\n ! tri-diagonal matrix, or a real, symmetric matrix previously\n ! reduced by function tred2 to tri-diagonal form. On input,\n ! d[] contains the diagonal element and e[] the sub-diagonal\n ! of the tri-diagonal matrix. On output d[] contains the\n ! eigenvalues and e[] is destroyed. If eigenvectors are\n ! desired z[][] on input contains the identity matrix. If\n ! eigenvectors of a matrix reduced by tred2() are required,\n ! then z[][] on input is the matrix output from tred2().\n ! On output, the k'th column returns the normalized eigenvector\n ! corresponding to d[k]. \n ! The function is modified from the version in Numerical recipe.\n\n SUBROUTINE tqli(d,e,n,z)\n USE constants\n IMPLICIT NONE\n INTEGER :: n \n REAL(DP) :: d(n),e(n),z(n,n)\n INTEGER :: i,iter,k,l,m\n REAL(DP) :: b,c,dd,f,g,p,r,s,pythag,one\n DO i=2,n\n e(i-1)=e(i)\n ENDDO\n one=1.\n DO l=1,n\n iter=0\n ITERATE : DO\n DO m=l,n-1\n dd=ABS(d(m))+ABS(d(m+1))\n IF (ABS(e(m))+dd == dd) EXIT\n ENDDO\n IF(m == l) EXIT ITERATE\n IF(iter == 30) STOP 'too many iterations in tqli'\n iter=iter+1\n g=(d(l+1)-d(l))/(2.*e(l))\n r=pythag(g,one)\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 == 0.) THEN\n d(i+1)=d(i+1)-p\n e(m)=0.\n CYCLE ITERATE\n ENDIF\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 ! Omit lines from here ...\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 ENDDO\n ! ... to here when finding only eigenvalues.\n ENDDO\n d(l)=d(l)-p\n e(l)=g\n e(m)=0.\n ENDDO ITERATE\n ENDDO\n\n END SUBROUTINE tqli\n\n", "meta": {"hexsha": "b49c18532e7bb09d56ffe5baf76ed7e0fcee983b", "size": 7380, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "doc/Programs/LecturePrograms/programs/EigenProblems/Fortran/program1.f90", "max_stars_repo_name": "solisius/ComputationalPhysics", "max_stars_repo_head_hexsha": "94d32d177881695d443eea34af3410e886b8cb9a", "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/EigenProblems/Fortran/program1.f90", "max_issues_repo_name": "solisius/ComputationalPhysics", "max_issues_repo_head_hexsha": "94d32d177881695d443eea34af3410e886b8cb9a", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-12-04T12:55:10.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-04T12:55:10.000Z", "max_forks_repo_path": "doc/Programs/LecturePrograms/programs/EigenProblems/Fortran/program1.f90", "max_forks_repo_name": "solisius/ComputationalPhysics", "max_forks_repo_head_hexsha": "94d32d177881695d443eea34af3410e886b8cb9a", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 136, "max_forks_repo_forks_event_min_datetime": "2016-08-25T09:04:56.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-12T09:54:21.000Z", "avg_line_length": 24.0390879479, "max_line_length": 99, "alphanum_fraction": 0.5821138211, "num_tokens": 2400, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297914570319, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.6975354227801205}} {"text": "program lineline\n\nimplicit none\n\nreal(8) :: a(2), b(2), c(2), d(2), cross(2,2)\ninteger :: sect\n\na(1)=0.0d0\n\na(2)=0.0d0\nb(1)=5.0d0\nb(2)=5.0d0\nc(1)=5.0d0\nc(2)=0.0d0\nd(1)=0.0d0\nd(2)=5.0d0\n\n call intersect(a,b,c,d,sect,cross)\n call writesect(sect,cross)\n \na(1)=1.0d0\na(2)=3.0d0\nb(1)=9.0d0\nb(2)=3.0d0\nc(1)=0.0d0\nc(2)=1.0d0\nd(1)=2.0d0\nd(2)=1.0d0\n\n call intersect(a,b,c,d,sect,cross)\n call writesect(sect,cross)\n \na(1)=1.0d0\na(2)=5.0d0\nb(1)=6.0d0\nb(2)=8.0d0\nc(1)=0.5d0\nc(2)=3.0d0\nd(1)=6.0d0\nd(2)=4.0d0\n \n call intersect(a,b,c,d,sect,cross)\n call writesect(sect,cross)\n\na(1)=1.0d0\na(2)=1.0d0\nb(1)=3.0d0\nb(2)=8.0d0\nc(1)=0.5d0\nc(2)=2.0d0\nd(1)=4.0d0\nd(2)=7.0d0\n \n call intersect(a,b,c,d,sect,cross)\n call writesect(sect,cross)\n\na(1)=1.0d0\na(2)=2.0d0\nb(1)=3.0d0\nb(2)=6.0d0\nc(1)=2.0d0\nc(2)=4.0d0\nd(1)=4.0d0\nd(2)=8.0d0\n \n call intersect(a,b,c,d,sect,cross)\n call writesect(sect,cross)\n \na(1)=3.5d0\na(2)=9.0d0\nb(1)=3.5d0\nb(2)=0.5d0\nc(1)=3.0d0\nc(2)=1.0d0\nd(1)=9.0d0\nd(2)=1.0d0\n \n call intersect(a,b,c,d,sect,cross)\n call writesect(sect,cross)\n \na(1)=2.0d0\na(2)=3.0d0\nb(1)=7.0d0\nb(2)=9.0d0\nc(1)=1.0d0\nc(2)=2.0d0\nd(1)=5.0d0\nd(2)=7.0d0\n \n call intersect(a,b,c,d,sect,cross)\n call writesect(sect,cross)\n \nend program lineline\n\n\nsubroutine writesect(sect,cross)\n\nimplicit none\n\nreal(8) :: cross(2,2)\ninteger :: sect\n\nif (sect==0) write (*,*) \"Lines are not intersecting\"\nif (sect==1) write (*,*) \"Lines are parallel\"\nif (sect==2) write (*,*) \"Lines are intersecting at\",cross(1,1),cross(1,2)\nif (sect==3) write (*,*) \"Lines are intersecting at segment\",cross(1,1),cross(1,2),&\n cross(2,1),cross(2,2)\n\nreturn\nend subroutine writesect\n", "meta": {"hexsha": "9ddfb9135f6760e3a23c23cfce099036e2187e6d", "size": 1697, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lineline.f90", "max_stars_repo_name": "frankeverdij/intersect", "max_stars_repo_head_hexsha": "9c8b98f1e02263e4057d46f80d1f93fb12638d8c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lineline.f90", "max_issues_repo_name": "frankeverdij/intersect", "max_issues_repo_head_hexsha": "9c8b98f1e02263e4057d46f80d1f93fb12638d8c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lineline.f90", "max_forks_repo_name": "frankeverdij/intersect", "max_forks_repo_head_hexsha": "9c8b98f1e02263e4057d46f80d1f93fb12638d8c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.2882882883, "max_line_length": 84, "alphanum_fraction": 0.6004714202, "num_tokens": 894, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297914570319, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.6975354227801205}} {"text": "!*==sgesvd.f90 processed by SPAG 7.51RB at 20:08 on 3 Mar 2022\n!> \\brief SGESVD computes the singular value decomposition (SVD) for GE matrices\n!\n! =========== DOCUMENTATION ===========\n!\n! Online html documentation available at\n! http://www.netlib.org/lapack/explore-html/\n!\n!> \\htmlonly\n!> Download SGESVD + dependencies\n!> \n!> [TGZ]\n!> \n!> [ZIP]\n!> \n!> [TXT]\n!> \\endhtmlonly\n!\n! Definition:\n! ===========\n!\n! SUBROUTINE SGESVD( JOBU, JOBVT, M, N, A, LDA, S, U, LDU, VT, LDVT,\n! WORK, LWORK, INFO )\n!\n! .. Scalar Arguments ..\n! CHARACTER JOBU, JOBVT\n! INTEGER INFO, LDA, LDU, LDVT, LWORK, M, N\n! ..\n! .. Array Arguments ..\n! REAL A( LDA, * ), S( * ), U( LDU, * ),\n! $ VT( LDVT, * ), WORK( * )\n! ..\n!\n!\n!> \\par Purpose:\n! =============\n!>\n!> \\verbatim\n!>\n!> SGESVD computes the singular value decomposition (SVD) of a real\n!> M-by-N matrix A, optionally computing the left and/or right singular\n!> vectors. The SVD is written\n!>\n!> A = U * SIGMA * transpose(V)\n!>\n!> where SIGMA is an M-by-N matrix which is zero except for its\n!> min(m,n) diagonal elements, U is an M-by-M orthogonal matrix, and\n!> V is an N-by-N orthogonal matrix. The diagonal elements of SIGMA\n!> are the singular values of A; they are real and non-negative, and\n!> are returned in descending order. The first min(m,n) columns of\n!> U and V are the left and right singular vectors of A.\n!>\n!> Note that the routine returns V**T, not V.\n!> \\endverbatim\n!\n! Arguments:\n! ==========\n!\n!> \\param[in] JOBU\n!> \\verbatim\n!> JOBU is CHARACTER*1\n!> Specifies options for computing all or part of the matrix U:\n!> = 'A': all M columns of U are returned in array U:\n!> = 'S': the first min(m,n) columns of U (the left singular\n!> vectors) are returned in the array U;\n!> = 'O': the first min(m,n) columns of U (the left singular\n!> vectors) are overwritten on the array A;\n!> = 'N': no columns of U (no left singular vectors) are\n!> computed.\n!> \\endverbatim\n!>\n!> \\param[in] JOBVT\n!> \\verbatim\n!> JOBVT is CHARACTER*1\n!> Specifies options for computing all or part of the matrix\n!> V**T:\n!> = 'A': all N rows of V**T are returned in the array VT;\n!> = 'S': the first min(m,n) rows of V**T (the right singular\n!> vectors) are returned in the array VT;\n!> = 'O': the first min(m,n) rows of V**T (the right singular\n!> vectors) are overwritten on the array A;\n!> = 'N': no rows of V**T (no right singular vectors) are\n!> computed.\n!>\n!> JOBVT and JOBU cannot both be 'O'.\n!> \\endverbatim\n!>\n!> \\param[in] M\n!> \\verbatim\n!> M is INTEGER\n!> The number of rows of the input matrix A. M >= 0.\n!> \\endverbatim\n!>\n!> \\param[in] N\n!> \\verbatim\n!> N is INTEGER\n!> The number of columns of the input matrix A. N >= 0.\n!> \\endverbatim\n!>\n!> \\param[in,out] A\n!> \\verbatim\n!> A is REAL array, dimension (LDA,N)\n!> On entry, the M-by-N matrix A.\n!> On exit,\n!> if JOBU = 'O', A is overwritten with the first min(m,n)\n!> columns of U (the left singular vectors,\n!> stored columnwise);\n!> if JOBVT = 'O', A is overwritten with the first min(m,n)\n!> rows of V**T (the right singular vectors,\n!> stored rowwise);\n!> if JOBU .ne. 'O' and JOBVT .ne. 'O', the contents of A\n!> are destroyed.\n!> \\endverbatim\n!>\n!> \\param[in] LDA\n!> \\verbatim\n!> LDA is INTEGER\n!> The leading dimension of the array A. LDA >= max(1,M).\n!> \\endverbatim\n!>\n!> \\param[out] S\n!> \\verbatim\n!> S is REAL array, dimension (min(M,N))\n!> The singular values of A, sorted so that S(i) >= S(i+1).\n!> \\endverbatim\n!>\n!> \\param[out] U\n!> \\verbatim\n!> U is REAL array, dimension (LDU,UCOL)\n!> (LDU,M) if JOBU = 'A' or (LDU,min(M,N)) if JOBU = 'S'.\n!> If JOBU = 'A', U contains the M-by-M orthogonal matrix U;\n!> if JOBU = 'S', U contains the first min(m,n) columns of U\n!> (the left singular vectors, stored columnwise);\n!> if JOBU = 'N' or 'O', U is not referenced.\n!> \\endverbatim\n!>\n!> \\param[in] LDU\n!> \\verbatim\n!> LDU is INTEGER\n!> The leading dimension of the array U. LDU >= 1; if\n!> JOBU = 'S' or 'A', LDU >= M.\n!> \\endverbatim\n!>\n!> \\param[out] VT\n!> \\verbatim\n!> VT is REAL array, dimension (LDVT,N)\n!> If JOBVT = 'A', VT contains the N-by-N orthogonal matrix\n!> V**T;\n!> if JOBVT = 'S', VT contains the first min(m,n) rows of\n!> V**T (the right singular vectors, stored rowwise);\n!> if JOBVT = 'N' or 'O', VT is not referenced.\n!> \\endverbatim\n!>\n!> \\param[in] LDVT\n!> \\verbatim\n!> LDVT is INTEGER\n!> The leading dimension of the array VT. LDVT >= 1; if\n!> JOBVT = 'A', LDVT >= N; if JOBVT = 'S', LDVT >= min(M,N).\n!> \\endverbatim\n!>\n!> \\param[out] WORK\n!> \\verbatim\n!> WORK is REAL array, dimension (MAX(1,LWORK))\n!> On exit, if INFO = 0, WORK(1) returns the optimal LWORK;\n!> if INFO > 0, WORK(2:MIN(M,N)) contains the unconverged\n!> superdiagonal elements of an upper bidiagonal matrix B\n!> whose diagonal is in S (not necessarily sorted). B\n!> satisfies A = U * B * VT, so it has the same singular values\n!> as A, and singular vectors related by U and VT.\n!> \\endverbatim\n!>\n!> \\param[in] LWORK\n!> \\verbatim\n!> LWORK is INTEGER\n!> The dimension of the array WORK.\n!> LWORK >= MAX(1,5*MIN(M,N)) for the paths (see comments inside code):\n!> - PATH 1 (M much larger than N, JOBU='N')\n!> - PATH 1t (N much larger than M, JOBVT='N')\n!> LWORK >= MAX(1,3*MIN(M,N)+MAX(M,N),5*MIN(M,N)) for the other paths\n!> For good performance, LWORK should generally be larger.\n!>\n!> If LWORK = -1, then a workspace query is assumed; the routine\n!> only calculates the optimal size of the WORK array, returns\n!> this value as the first entry of the WORK array, and no error\n!> message related to LWORK is issued by XERBLA.\n!> \\endverbatim\n!>\n!> \\param[out] INFO\n!> \\verbatim\n!> INFO is INTEGER\n!> = 0: successful exit.\n!> < 0: if INFO = -i, the i-th argument had an illegal value.\n!> > 0: if SBDSQR did not converge, INFO specifies how many\n!> superdiagonals of an intermediate bidiagonal form B\n!> did not converge to zero. See the description of WORK\n!> above for details.\n!> \\endverbatim\n!\n! Authors:\n! ========\n!\n!> \\author Univ. of Tennessee\n!> \\author Univ. of California Berkeley\n!> \\author Univ. of Colorado Denver\n!> \\author NAG Ltd.\n!\n!> \\date April 2012\n!\n!> \\ingroup realGEsing\n!\n! =====================================================================\n SUBROUTINE SGESVD(Jobu,Jobvt,M,N,A,Lda,S,U,Ldu,Vt,Ldvt,Work,Lwork,&\n & Info)\n IMPLICIT NONE\n!*--SGESVD215\n!\n! -- LAPACK driver routine (version 3.7.0) --\n! -- LAPACK is a software package provided by Univ. of Tennessee, --\n! -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n! April 2012\n!\n! .. Scalar Arguments ..\n CHARACTER Jobu , Jobvt\n INTEGER Info , Lda , Ldu , Ldvt , Lwork , M , N\n! ..\n! .. Array Arguments ..\n REAL A(Lda,*) , S(*) , U(Ldu,*) , Vt(Ldvt,*) , Work(*)\n! ..\n!\n! =====================================================================\n!\n! .. Parameters ..\n REAL ZERO , ONE\n PARAMETER (ZERO=0.0E0,ONE=1.0E0)\n! ..\n! .. Local Scalars ..\n LOGICAL lquery , wntua , wntuas , wntun , wntuo , wntus , wntva , &\n & wntvas , wntvn , wntvo , wntvs\n INTEGER bdspac , blk , chunk , i , ie , ierr , ir , iscl , itau , &\n & itaup , itauq , iu , iwork , ldwrkr , ldwrku , maxwrk , &\n & minmn , minwrk , mnthr , ncu , ncvt , nru , nrvt , wrkbl\n INTEGER lwork_sgeqrf , lwork_sorgqr_n , lwork_sorgqr_m , &\n & lwork_sgebrd , lwork_sorgbr_p , lwork_sorgbr_q , &\n & lwork_sgelqf , lwork_sorglq_n , lwork_sorglq_m\n REAL anrm , bignum , eps , smlnum\n! ..\n! .. Local Arrays ..\n REAL dum(1)\n! ..\n! .. External Subroutines ..\n EXTERNAL SBDSQR , SGEBRD , SGELQF , SGEMM , SGEQRF , SLACPY , &\n & SLASCL , SLASET , SORGBR , SORGLQ , SORGQR , SORMBR , &\n & XERBLA\n! ..\n! .. External Functions ..\n LOGICAL LSAME\n INTEGER ILAENV\n REAL SLAMCH , SLANGE\n EXTERNAL LSAME , ILAENV , SLAMCH , SLANGE\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC MAX , MIN , SQRT\n! ..\n! .. Executable Statements ..\n!\n! Test the input arguments\n!\n Info = 0\n minmn = MIN(M,N)\n wntua = LSAME(Jobu,'A')\n wntus = LSAME(Jobu,'S')\n wntuas = wntua .OR. wntus\n wntuo = LSAME(Jobu,'O')\n wntun = LSAME(Jobu,'N')\n wntva = LSAME(Jobvt,'A')\n wntvs = LSAME(Jobvt,'S')\n wntvas = wntva .OR. wntvs\n wntvo = LSAME(Jobvt,'O')\n wntvn = LSAME(Jobvt,'N')\n lquery = (Lwork==-1)\n!\n IF ( .NOT.(wntua .OR. wntus .OR. wntuo .OR. wntun) ) THEN\n Info = -1\n ELSEIF ( .NOT.(wntva .OR. wntvs .OR. wntvo .OR. wntvn) .OR. &\n & (wntvo .AND. wntuo) ) THEN\n Info = -2\n ELSEIF ( M<0 ) THEN\n Info = -3\n ELSEIF ( N<0 ) THEN\n Info = -4\n ELSEIF ( Lda=N .AND. minmn>0 ) THEN\n!\n! Compute space needed for SBDSQR\n!\n mnthr = ILAENV(6,'SGESVD',Jobu//Jobvt,M,N,0,0)\n bdspac = 5*N\n! Compute space needed for SGEQRF\n CALL SGEQRF(M,N,A,Lda,dum(1),dum(1),-1,ierr)\n lwork_sgeqrf = INT(dum(1))\n! Compute space needed for SORGQR\n CALL SORGQR(M,N,N,A,Lda,dum(1),dum(1),-1,ierr)\n lwork_sorgqr_n = INT(dum(1))\n CALL SORGQR(M,M,N,A,Lda,dum(1),dum(1),-1,ierr)\n lwork_sorgqr_m = INT(dum(1))\n! Compute space needed for SGEBRD\n CALL SGEBRD(N,N,A,Lda,S,dum(1),dum(1),dum(1),dum(1),-1,ierr)\n lwork_sgebrd = INT(dum(1))\n! Compute space needed for SORGBR P\n CALL SORGBR('P',N,N,N,A,Lda,dum(1),dum(1),-1,ierr)\n lwork_sorgbr_p = INT(dum(1))\n! Compute space needed for SORGBR Q\n CALL SORGBR('Q',N,N,N,A,Lda,dum(1),dum(1),-1,ierr)\n lwork_sorgbr_q = INT(dum(1))\n!\n IF ( M0 ) THEN\n!\n! Compute space needed for SBDSQR\n!\n mnthr = ILAENV(6,'SGESVD',Jobu//Jobvt,M,N,0,0)\n bdspac = 5*M\n! Compute space needed for SGELQF\n CALL SGELQF(M,N,A,Lda,dum(1),dum(1),-1,ierr)\n lwork_sgelqf = INT(dum(1))\n! Compute space needed for SORGLQ\n CALL SORGLQ(N,N,M,dum(1),N,dum(1),dum(1),-1,ierr)\n lwork_sorglq_n = INT(dum(1))\n CALL SORGLQ(M,N,M,A,Lda,dum(1),dum(1),-1,ierr)\n lwork_sorglq_m = INT(dum(1))\n! Compute space needed for SGEBRD\n CALL SGEBRD(M,M,A,Lda,S,dum(1),dum(1),dum(1),dum(1),-1,ierr)\n lwork_sgebrd = INT(dum(1))\n! Compute space needed for SORGBR P\n CALL SORGBR('P',M,M,M,A,N,dum(1),dum(1),-1,ierr)\n lwork_sorgbr_p = INT(dum(1))\n! Compute space needed for SORGBR Q\n CALL SORGBR('Q',M,M,M,A,N,dum(1),dum(1),-1,ierr)\n lwork_sorgbr_q = INT(dum(1))\n IF ( NZERO .AND. anrmbignum ) THEN\n iscl = 1\n CALL SLASCL('G',0,0,anrm,bignum,M,N,A,Lda,ierr)\n ENDIF\n!\n IF ( M>=N ) THEN\n!\n! A has at least as many rows as columns. If A has sufficiently\n! more rows than columns, first reduce using the QR\n! decomposition (if sufficient workspace available)\n!\n IF ( M1 ) CALL SLASET('L',N-1,N-1,ZERO,ZERO,A(2,1),Lda)\n ie = 1\n itauq = ie + N\n itaup = itauq + N\n iwork = itaup + N\n!\n! Bidiagonalize R in A\n! (Workspace: need 4*N, prefer 3*N+2*N*NB)\n!\n CALL SGEBRD(N,N,A,Lda,S,Work(ie),Work(itauq),Work(itaup), &\n & Work(iwork),Lwork-iwork+1,ierr)\n ncvt = 0\n IF ( wntvo .OR. wntvas ) THEN\n!\n! If right singular vectors desired, generate P'.\n! (Workspace: need 4*N-1, prefer 3*N+(N-1)*NB)\n!\n CALL SORGBR('P',N,N,N,A,Lda,Work(itaup),Work(iwork), &\n & Lwork-iwork+1,ierr)\n ncvt = N\n ENDIF\n iwork = ie + N\n!\n! Perform bidiagonal QR iteration, computing right\n! singular vectors of A in A if desired\n! (Workspace: need BDSPAC)\n!\n CALL SBDSQR('U',N,ncvt,0,0,S,Work(ie),A,Lda,dum,1,dum,1, &\n & Work(iwork),Info)\n!\n! If right singular vectors desired in VT, copy them there\n!\n IF ( wntvas ) CALL SLACPY('F',N,N,A,Lda,Vt,Ldvt)\n!\n ELSEIF ( wntuo .AND. wntvn ) THEN\n!\n! Path 2 (M much larger than N, JOBU='O', JOBVT='N')\n! N left singular vectors to be overwritten on A and\n! no right singular vectors to be computed\n!\n IF ( Lwork>=N*N+MAX(4*N,bdspac) ) THEN\n!\n! Sufficient workspace for a fast algorithm\n!\n ir = 1\n IF ( Lwork>=MAX(wrkbl,Lda*N+N)+Lda*N ) THEN\n!\n! WORK(IU) is LDA by N, WORK(IR) is LDA by N\n!\n ldwrku = Lda\n ldwrkr = Lda\n ELSEIF ( Lwork>=MAX(wrkbl,Lda*N+N)+N*N ) THEN\n!\n! WORK(IU) is LDA by N, WORK(IR) is N by N\n!\n ldwrku = Lda\n ldwrkr = N\n ELSE\n!\n! WORK(IU) is LDWRKU by N, WORK(IR) is N by N\n!\n ldwrku = (Lwork-N*N-N)/N\n ldwrkr = N\n ENDIF\n itau = ir + ldwrkr*N\n iwork = itau + N\n!\n! Compute A=Q*R\n! (Workspace: need N*N+2*N, prefer N*N+N+N*NB)\n!\n CALL SGEQRF(M,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n!\n! Copy R to WORK(IR) and zero out below it\n!\n CALL SLACPY('U',N,N,A,Lda,Work(ir),ldwrkr)\n CALL SLASET('L',N-1,N-1,ZERO,ZERO,Work(ir+1),ldwrkr)\n!\n! Generate Q in A\n! (Workspace: need N*N+2*N, prefer N*N+N+N*NB)\n!\n CALL SORGQR(M,N,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n ie = itau\n itauq = ie + N\n itaup = itauq + N\n iwork = itaup + N\n!\n! Bidiagonalize R in WORK(IR)\n! (Workspace: need N*N+4*N, prefer N*N+3*N+2*N*NB)\n!\n CALL SGEBRD(N,N,Work(ir),ldwrkr,S,Work(ie),Work(itauq), &\n & Work(itaup),Work(iwork),Lwork-iwork+1,ierr)\n!\n! Generate left vectors bidiagonalizing R\n! (Workspace: need N*N+4*N, prefer N*N+3*N+N*NB)\n!\n CALL SORGBR('Q',N,N,N,Work(ir),ldwrkr,Work(itauq), &\n & Work(iwork),Lwork-iwork+1,ierr)\n iwork = ie + N\n!\n! Perform bidiagonal QR iteration, computing left\n! singular vectors of R in WORK(IR)\n! (Workspace: need N*N+BDSPAC)\n!\n CALL SBDSQR('U',N,0,N,0,S,Work(ie),dum,1,Work(ir),ldwrkr,&\n & dum,1,Work(iwork),Info)\n iu = ie + N\n!\n! Multiply Q in A by left singular vectors of R in\n! WORK(IR), storing result in WORK(IU) and copying to A\n! (Workspace: need N*N+2*N, prefer N*N+M*N+N)\n!\n DO i = 1 , M , ldwrku\n chunk = MIN(M-i+1,ldwrku)\n CALL SGEMM('N','N',chunk,N,N,ONE,A(i,1),Lda,Work(ir), &\n & ldwrkr,ZERO,Work(iu),ldwrku)\n CALL SLACPY('F',chunk,N,Work(iu),ldwrku,A(i,1),Lda)\n ENDDO\n!\n ELSE\n!\n! Insufficient workspace for a fast algorithm\n!\n ie = 1\n itauq = ie + N\n itaup = itauq + N\n iwork = itaup + N\n!\n! Bidiagonalize A\n! (Workspace: need 3*N+M, prefer 3*N+(M+N)*NB)\n!\n CALL SGEBRD(M,N,A,Lda,S,Work(ie),Work(itauq),Work(itaup),&\n & Work(iwork),Lwork-iwork+1,ierr)\n!\n! Generate left vectors bidiagonalizing A\n! (Workspace: need 4*N, prefer 3*N+N*NB)\n!\n CALL SORGBR('Q',M,N,N,A,Lda,Work(itauq),Work(iwork), &\n & Lwork-iwork+1,ierr)\n iwork = ie + N\n!\n! Perform bidiagonal QR iteration, computing left\n! singular vectors of A in A\n! (Workspace: need BDSPAC)\n!\n CALL SBDSQR('U',N,0,M,0,S,Work(ie),dum,1,A,Lda,dum,1, &\n & Work(iwork),Info)\n!\n ENDIF\n!\n ELSEIF ( wntuo .AND. wntvas ) THEN\n!\n! Path 3 (M much larger than N, JOBU='O', JOBVT='S' or 'A')\n! N left singular vectors to be overwritten on A and\n! N right singular vectors to be computed in VT\n!\n IF ( Lwork>=N*N+MAX(4*N,bdspac) ) THEN\n!\n! Sufficient workspace for a fast algorithm\n!\n ir = 1\n IF ( Lwork>=MAX(wrkbl,Lda*N+N)+Lda*N ) THEN\n!\n! WORK(IU) is LDA by N and WORK(IR) is LDA by N\n!\n ldwrku = Lda\n ldwrkr = Lda\n ELSEIF ( Lwork>=MAX(wrkbl,Lda*N+N)+N*N ) THEN\n!\n! WORK(IU) is LDA by N and WORK(IR) is N by N\n!\n ldwrku = Lda\n ldwrkr = N\n ELSE\n!\n! WORK(IU) is LDWRKU by N and WORK(IR) is N by N\n!\n ldwrku = (Lwork-N*N-N)/N\n ldwrkr = N\n ENDIF\n itau = ir + ldwrkr*N\n iwork = itau + N\n!\n! Compute A=Q*R\n! (Workspace: need N*N+2*N, prefer N*N+N+N*NB)\n!\n CALL SGEQRF(M,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n!\n! Copy R to VT, zeroing out below it\n!\n CALL SLACPY('U',N,N,A,Lda,Vt,Ldvt)\n IF ( N>1 ) CALL SLASET('L',N-1,N-1,ZERO,ZERO,Vt(2,1), &\n & Ldvt)\n!\n! Generate Q in A\n! (Workspace: need N*N+2*N, prefer N*N+N+N*NB)\n!\n CALL SORGQR(M,N,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n ie = itau\n itauq = ie + N\n itaup = itauq + N\n iwork = itaup + N\n!\n! Bidiagonalize R in VT, copying result to WORK(IR)\n! (Workspace: need N*N+4*N, prefer N*N+3*N+2*N*NB)\n!\n CALL SGEBRD(N,N,Vt,Ldvt,S,Work(ie),Work(itauq), &\n & Work(itaup),Work(iwork),Lwork-iwork+1,ierr)\n CALL SLACPY('L',N,N,Vt,Ldvt,Work(ir),ldwrkr)\n!\n! Generate left vectors bidiagonalizing R in WORK(IR)\n! (Workspace: need N*N+4*N, prefer N*N+3*N+N*NB)\n!\n CALL SORGBR('Q',N,N,N,Work(ir),ldwrkr,Work(itauq), &\n & Work(iwork),Lwork-iwork+1,ierr)\n!\n! Generate right vectors bidiagonalizing R in VT\n! (Workspace: need N*N+4*N-1, prefer N*N+3*N+(N-1)*NB)\n!\n CALL SORGBR('P',N,N,N,Vt,Ldvt,Work(itaup),Work(iwork), &\n & Lwork-iwork+1,ierr)\n iwork = ie + N\n!\n! Perform bidiagonal QR iteration, computing left\n! singular vectors of R in WORK(IR) and computing right\n! singular vectors of R in VT\n! (Workspace: need N*N+BDSPAC)\n!\n CALL SBDSQR('U',N,N,N,0,S,Work(ie),Vt,Ldvt,Work(ir), &\n & ldwrkr,dum,1,Work(iwork),Info)\n iu = ie + N\n!\n! Multiply Q in A by left singular vectors of R in\n! WORK(IR), storing result in WORK(IU) and copying to A\n! (Workspace: need N*N+2*N, prefer N*N+M*N+N)\n!\n DO i = 1 , M , ldwrku\n chunk = MIN(M-i+1,ldwrku)\n CALL SGEMM('N','N',chunk,N,N,ONE,A(i,1),Lda,Work(ir), &\n & ldwrkr,ZERO,Work(iu),ldwrku)\n CALL SLACPY('F',chunk,N,Work(iu),ldwrku,A(i,1),Lda)\n ENDDO\n!\n ELSE\n!\n! Insufficient workspace for a fast algorithm\n!\n itau = 1\n iwork = itau + N\n!\n! Compute A=Q*R\n! (Workspace: need 2*N, prefer N+N*NB)\n!\n CALL SGEQRF(M,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n!\n! Copy R to VT, zeroing out below it\n!\n CALL SLACPY('U',N,N,A,Lda,Vt,Ldvt)\n IF ( N>1 ) CALL SLASET('L',N-1,N-1,ZERO,ZERO,Vt(2,1), &\n & Ldvt)\n!\n! Generate Q in A\n! (Workspace: need 2*N, prefer N+N*NB)\n!\n CALL SORGQR(M,N,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n ie = itau\n itauq = ie + N\n itaup = itauq + N\n iwork = itaup + N\n!\n! Bidiagonalize R in VT\n! (Workspace: need 4*N, prefer 3*N+2*N*NB)\n!\n CALL SGEBRD(N,N,Vt,Ldvt,S,Work(ie),Work(itauq), &\n & Work(itaup),Work(iwork),Lwork-iwork+1,ierr)\n!\n! Multiply Q in A by left vectors bidiagonalizing R\n! (Workspace: need 3*N+M, prefer 3*N+M*NB)\n!\n CALL SORMBR('Q','R','N',M,N,N,Vt,Ldvt,Work(itauq),A,Lda, &\n & Work(iwork),Lwork-iwork+1,ierr)\n!\n! Generate right vectors bidiagonalizing R in VT\n! (Workspace: need 4*N-1, prefer 3*N+(N-1)*NB)\n!\n CALL SORGBR('P',N,N,N,Vt,Ldvt,Work(itaup),Work(iwork), &\n & Lwork-iwork+1,ierr)\n iwork = ie + N\n!\n! Perform bidiagonal QR iteration, computing left\n! singular vectors of A in A and computing right\n! singular vectors of A in VT\n! (Workspace: need BDSPAC)\n!\n CALL SBDSQR('U',N,N,M,0,S,Work(ie),Vt,Ldvt,A,Lda,dum,1, &\n & Work(iwork),Info)\n!\n ENDIF\n!\n ELSEIF ( wntus ) THEN\n!\n IF ( wntvn ) THEN\n!\n! Path 4 (M much larger than N, JOBU='S', JOBVT='N')\n! N left singular vectors to be computed in U and\n! no right singular vectors to be computed\n!\n IF ( Lwork>=N*N+MAX(4*N,bdspac) ) THEN\n!\n! Sufficient workspace for a fast algorithm\n!\n ir = 1\n IF ( Lwork>=wrkbl+Lda*N ) THEN\n!\n! WORK(IR) is LDA by N\n!\n ldwrkr = Lda\n ELSE\n!\n! WORK(IR) is N by N\n!\n ldwrkr = N\n ENDIF\n itau = ir + ldwrkr*N\n iwork = itau + N\n!\n! Compute A=Q*R\n! (Workspace: need N*N+2*N, prefer N*N+N+N*NB)\n!\n CALL SGEQRF(M,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n!\n! Copy R to WORK(IR), zeroing out below it\n!\n CALL SLACPY('U',N,N,A,Lda,Work(ir),ldwrkr)\n CALL SLASET('L',N-1,N-1,ZERO,ZERO,Work(ir+1),ldwrkr)\n!\n! Generate Q in A\n! (Workspace: need N*N+2*N, prefer N*N+N+N*NB)\n!\n CALL SORGQR(M,N,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n ie = itau\n itauq = ie + N\n itaup = itauq + N\n iwork = itaup + N\n!\n! Bidiagonalize R in WORK(IR)\n! (Workspace: need N*N+4*N, prefer N*N+3*N+2*N*NB)\n!\n CALL SGEBRD(N,N,Work(ir),ldwrkr,S,Work(ie),Work(itauq)&\n & ,Work(itaup),Work(iwork),Lwork-iwork+1, &\n & ierr)\n!\n! Generate left vectors bidiagonalizing R in WORK(IR)\n! (Workspace: need N*N+4*N, prefer N*N+3*N+N*NB)\n!\n CALL SORGBR('Q',N,N,N,Work(ir),ldwrkr,Work(itauq), &\n & Work(iwork),Lwork-iwork+1,ierr)\n iwork = ie + N\n!\n! Perform bidiagonal QR iteration, computing left\n! singular vectors of R in WORK(IR)\n! (Workspace: need N*N+BDSPAC)\n!\n CALL SBDSQR('U',N,0,N,0,S,Work(ie),dum,1,Work(ir), &\n & ldwrkr,dum,1,Work(iwork),Info)\n!\n! Multiply Q in A by left singular vectors of R in\n! WORK(IR), storing result in U\n! (Workspace: need N*N)\n!\n CALL SGEMM('N','N',M,N,N,ONE,A,Lda,Work(ir),ldwrkr, &\n & ZERO,U,Ldu)\n!\n ELSE\n!\n! Insufficient workspace for a fast algorithm\n!\n itau = 1\n iwork = itau + N\n!\n! Compute A=Q*R, copying result to U\n! (Workspace: need 2*N, prefer N+N*NB)\n!\n CALL SGEQRF(M,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n CALL SLACPY('L',M,N,A,Lda,U,Ldu)\n!\n! Generate Q in U\n! (Workspace: need 2*N, prefer N+N*NB)\n!\n CALL SORGQR(M,N,N,U,Ldu,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n ie = itau\n itauq = ie + N\n itaup = itauq + N\n iwork = itaup + N\n!\n! Zero out below R in A\n!\n IF ( N>1 ) CALL SLASET('L',N-1,N-1,ZERO,ZERO,A(2,1), &\n & Lda)\n!\n! Bidiagonalize R in A\n! (Workspace: need 4*N, prefer 3*N+2*N*NB)\n!\n CALL SGEBRD(N,N,A,Lda,S,Work(ie),Work(itauq), &\n & Work(itaup),Work(iwork),Lwork-iwork+1, &\n & ierr)\n!\n! Multiply Q in U by left vectors bidiagonalizing R\n! (Workspace: need 3*N+M, prefer 3*N+M*NB)\n!\n CALL SORMBR('Q','R','N',M,N,N,A,Lda,Work(itauq),U,Ldu,&\n & Work(iwork),Lwork-iwork+1,ierr)\n iwork = ie + N\n!\n! Perform bidiagonal QR iteration, computing left\n! singular vectors of A in U\n! (Workspace: need BDSPAC)\n!\n CALL SBDSQR('U',N,0,M,0,S,Work(ie),dum,1,U,Ldu,dum,1, &\n & Work(iwork),Info)\n!\n ENDIF\n!\n ELSEIF ( wntvo ) THEN\n!\n! Path 5 (M much larger than N, JOBU='S', JOBVT='O')\n! N left singular vectors to be computed in U and\n! N right singular vectors to be overwritten on A\n!\n IF ( Lwork>=2*N*N+MAX(4*N,bdspac) ) THEN\n!\n! Sufficient workspace for a fast algorithm\n!\n iu = 1\n IF ( Lwork>=wrkbl+2*Lda*N ) THEN\n!\n! WORK(IU) is LDA by N and WORK(IR) is LDA by N\n!\n ldwrku = Lda\n ir = iu + ldwrku*N\n ldwrkr = Lda\n ELSEIF ( Lwork>=wrkbl+(Lda+N)*N ) THEN\n!\n! WORK(IU) is LDA by N and WORK(IR) is N by N\n!\n ldwrku = Lda\n ir = iu + ldwrku*N\n ldwrkr = N\n ELSE\n!\n! WORK(IU) is N by N and WORK(IR) is N by N\n!\n ldwrku = N\n ir = iu + ldwrku*N\n ldwrkr = N\n ENDIF\n itau = ir + ldwrkr*N\n iwork = itau + N\n!\n! Compute A=Q*R\n! (Workspace: need 2*N*N+2*N, prefer 2*N*N+N+N*NB)\n!\n CALL SGEQRF(M,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n!\n! Copy R to WORK(IU), zeroing out below it\n!\n CALL SLACPY('U',N,N,A,Lda,Work(iu),ldwrku)\n CALL SLASET('L',N-1,N-1,ZERO,ZERO,Work(iu+1),ldwrku)\n!\n! Generate Q in A\n! (Workspace: need 2*N*N+2*N, prefer 2*N*N+N+N*NB)\n!\n CALL SORGQR(M,N,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n ie = itau\n itauq = ie + N\n itaup = itauq + N\n iwork = itaup + N\n!\n! Bidiagonalize R in WORK(IU), copying result to\n! WORK(IR)\n! (Workspace: need 2*N*N+4*N,\n! prefer 2*N*N+3*N+2*N*NB)\n!\n CALL SGEBRD(N,N,Work(iu),ldwrku,S,Work(ie),Work(itauq)&\n & ,Work(itaup),Work(iwork),Lwork-iwork+1, &\n & ierr)\n CALL SLACPY('U',N,N,Work(iu),ldwrku,Work(ir),ldwrkr)\n!\n! Generate left bidiagonalizing vectors in WORK(IU)\n! (Workspace: need 2*N*N+4*N, prefer 2*N*N+3*N+N*NB)\n!\n CALL SORGBR('Q',N,N,N,Work(iu),ldwrku,Work(itauq), &\n & Work(iwork),Lwork-iwork+1,ierr)\n!\n! Generate right bidiagonalizing vectors in WORK(IR)\n! (Workspace: need 2*N*N+4*N-1,\n! prefer 2*N*N+3*N+(N-1)*NB)\n!\n CALL SORGBR('P',N,N,N,Work(ir),ldwrkr,Work(itaup), &\n & Work(iwork),Lwork-iwork+1,ierr)\n iwork = ie + N\n!\n! Perform bidiagonal QR iteration, computing left\n! singular vectors of R in WORK(IU) and computing\n! right singular vectors of R in WORK(IR)\n! (Workspace: need 2*N*N+BDSPAC)\n!\n CALL SBDSQR('U',N,N,N,0,S,Work(ie),Work(ir),ldwrkr, &\n & Work(iu),ldwrku,dum,1,Work(iwork),Info)\n!\n! Multiply Q in A by left singular vectors of R in\n! WORK(IU), storing result in U\n! (Workspace: need N*N)\n!\n CALL SGEMM('N','N',M,N,N,ONE,A,Lda,Work(iu),ldwrku, &\n & ZERO,U,Ldu)\n!\n! Copy right singular vectors of R to A\n! (Workspace: need N*N)\n!\n CALL SLACPY('F',N,N,Work(ir),ldwrkr,A,Lda)\n!\n ELSE\n!\n! Insufficient workspace for a fast algorithm\n!\n itau = 1\n iwork = itau + N\n!\n! Compute A=Q*R, copying result to U\n! (Workspace: need 2*N, prefer N+N*NB)\n!\n CALL SGEQRF(M,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n CALL SLACPY('L',M,N,A,Lda,U,Ldu)\n!\n! Generate Q in U\n! (Workspace: need 2*N, prefer N+N*NB)\n!\n CALL SORGQR(M,N,N,U,Ldu,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n ie = itau\n itauq = ie + N\n itaup = itauq + N\n iwork = itaup + N\n!\n! Zero out below R in A\n!\n IF ( N>1 ) CALL SLASET('L',N-1,N-1,ZERO,ZERO,A(2,1), &\n & Lda)\n!\n! Bidiagonalize R in A\n! (Workspace: need 4*N, prefer 3*N+2*N*NB)\n!\n CALL SGEBRD(N,N,A,Lda,S,Work(ie),Work(itauq), &\n & Work(itaup),Work(iwork),Lwork-iwork+1, &\n & ierr)\n!\n! Multiply Q in U by left vectors bidiagonalizing R\n! (Workspace: need 3*N+M, prefer 3*N+M*NB)\n!\n CALL SORMBR('Q','R','N',M,N,N,A,Lda,Work(itauq),U,Ldu,&\n & Work(iwork),Lwork-iwork+1,ierr)\n!\n! Generate right vectors bidiagonalizing R in A\n! (Workspace: need 4*N-1, prefer 3*N+(N-1)*NB)\n!\n CALL SORGBR('P',N,N,N,A,Lda,Work(itaup),Work(iwork), &\n & Lwork-iwork+1,ierr)\n iwork = ie + N\n!\n! Perform bidiagonal QR iteration, computing left\n! singular vectors of A in U and computing right\n! singular vectors of A in A\n! (Workspace: need BDSPAC)\n!\n CALL SBDSQR('U',N,N,M,0,S,Work(ie),A,Lda,U,Ldu,dum,1, &\n & Work(iwork),Info)\n!\n ENDIF\n!\n ELSEIF ( wntvas ) THEN\n!\n! Path 6 (M much larger than N, JOBU='S', JOBVT='S'\n! or 'A')\n! N left singular vectors to be computed in U and\n! N right singular vectors to be computed in VT\n!\n IF ( Lwork>=N*N+MAX(4*N,bdspac) ) THEN\n!\n! Sufficient workspace for a fast algorithm\n!\n iu = 1\n IF ( Lwork>=wrkbl+Lda*N ) THEN\n!\n! WORK(IU) is LDA by N\n!\n ldwrku = Lda\n ELSE\n!\n! WORK(IU) is N by N\n!\n ldwrku = N\n ENDIF\n itau = iu + ldwrku*N\n iwork = itau + N\n!\n! Compute A=Q*R\n! (Workspace: need N*N+2*N, prefer N*N+N+N*NB)\n!\n CALL SGEQRF(M,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n!\n! Copy R to WORK(IU), zeroing out below it\n!\n CALL SLACPY('U',N,N,A,Lda,Work(iu),ldwrku)\n CALL SLASET('L',N-1,N-1,ZERO,ZERO,Work(iu+1),ldwrku)\n!\n! Generate Q in A\n! (Workspace: need N*N+2*N, prefer N*N+N+N*NB)\n!\n CALL SORGQR(M,N,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n ie = itau\n itauq = ie + N\n itaup = itauq + N\n iwork = itaup + N\n!\n! Bidiagonalize R in WORK(IU), copying result to VT\n! (Workspace: need N*N+4*N, prefer N*N+3*N+2*N*NB)\n!\n CALL SGEBRD(N,N,Work(iu),ldwrku,S,Work(ie),Work(itauq)&\n & ,Work(itaup),Work(iwork),Lwork-iwork+1, &\n & ierr)\n CALL SLACPY('U',N,N,Work(iu),ldwrku,Vt,Ldvt)\n!\n! Generate left bidiagonalizing vectors in WORK(IU)\n! (Workspace: need N*N+4*N, prefer N*N+3*N+N*NB)\n!\n CALL SORGBR('Q',N,N,N,Work(iu),ldwrku,Work(itauq), &\n & Work(iwork),Lwork-iwork+1,ierr)\n!\n! Generate right bidiagonalizing vectors in VT\n! (Workspace: need N*N+4*N-1,\n! prefer N*N+3*N+(N-1)*NB)\n!\n CALL SORGBR('P',N,N,N,Vt,Ldvt,Work(itaup),Work(iwork),&\n & Lwork-iwork+1,ierr)\n iwork = ie + N\n!\n! Perform bidiagonal QR iteration, computing left\n! singular vectors of R in WORK(IU) and computing\n! right singular vectors of R in VT\n! (Workspace: need N*N+BDSPAC)\n!\n CALL SBDSQR('U',N,N,N,0,S,Work(ie),Vt,Ldvt,Work(iu), &\n & ldwrku,dum,1,Work(iwork),Info)\n!\n! Multiply Q in A by left singular vectors of R in\n! WORK(IU), storing result in U\n! (Workspace: need N*N)\n!\n CALL SGEMM('N','N',M,N,N,ONE,A,Lda,Work(iu),ldwrku, &\n & ZERO,U,Ldu)\n!\n ELSE\n!\n! Insufficient workspace for a fast algorithm\n!\n itau = 1\n iwork = itau + N\n!\n! Compute A=Q*R, copying result to U\n! (Workspace: need 2*N, prefer N+N*NB)\n!\n CALL SGEQRF(M,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n CALL SLACPY('L',M,N,A,Lda,U,Ldu)\n!\n! Generate Q in U\n! (Workspace: need 2*N, prefer N+N*NB)\n!\n CALL SORGQR(M,N,N,U,Ldu,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n!\n! Copy R to VT, zeroing out below it\n!\n CALL SLACPY('U',N,N,A,Lda,Vt,Ldvt)\n IF ( N>1 ) CALL SLASET('L',N-1,N-1,ZERO,ZERO,Vt(2,1), &\n & Ldvt)\n ie = itau\n itauq = ie + N\n itaup = itauq + N\n iwork = itaup + N\n!\n! Bidiagonalize R in VT\n! (Workspace: need 4*N, prefer 3*N+2*N*NB)\n!\n CALL SGEBRD(N,N,Vt,Ldvt,S,Work(ie),Work(itauq), &\n & Work(itaup),Work(iwork),Lwork-iwork+1, &\n & ierr)\n!\n! Multiply Q in U by left bidiagonalizing vectors\n! in VT\n! (Workspace: need 3*N+M, prefer 3*N+M*NB)\n!\n CALL SORMBR('Q','R','N',M,N,N,Vt,Ldvt,Work(itauq),U, &\n & Ldu,Work(iwork),Lwork-iwork+1,ierr)\n!\n! Generate right bidiagonalizing vectors in VT\n! (Workspace: need 4*N-1, prefer 3*N+(N-1)*NB)\n!\n CALL SORGBR('P',N,N,N,Vt,Ldvt,Work(itaup),Work(iwork),&\n & Lwork-iwork+1,ierr)\n iwork = ie + N\n!\n! Perform bidiagonal QR iteration, computing left\n! singular vectors of A in U and computing right\n! singular vectors of A in VT\n! (Workspace: need BDSPAC)\n!\n CALL SBDSQR('U',N,N,M,0,S,Work(ie),Vt,Ldvt,U,Ldu,dum, &\n & 1,Work(iwork),Info)\n!\n ENDIF\n!\n ENDIF\n!\n ELSEIF ( wntua ) THEN\n!\n IF ( wntvn ) THEN\n!\n! Path 7 (M much larger than N, JOBU='A', JOBVT='N')\n! M left singular vectors to be computed in U and\n! no right singular vectors to be computed\n!\n IF ( Lwork>=N*N+MAX(N+M,4*N,bdspac) ) THEN\n!\n! Sufficient workspace for a fast algorithm\n!\n ir = 1\n IF ( Lwork>=wrkbl+Lda*N ) THEN\n!\n! WORK(IR) is LDA by N\n!\n ldwrkr = Lda\n ELSE\n!\n! WORK(IR) is N by N\n!\n ldwrkr = N\n ENDIF\n itau = ir + ldwrkr*N\n iwork = itau + N\n!\n! Compute A=Q*R, copying result to U\n! (Workspace: need N*N+2*N, prefer N*N+N+N*NB)\n!\n CALL SGEQRF(M,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n CALL SLACPY('L',M,N,A,Lda,U,Ldu)\n!\n! Copy R to WORK(IR), zeroing out below it\n!\n CALL SLACPY('U',N,N,A,Lda,Work(ir),ldwrkr)\n CALL SLASET('L',N-1,N-1,ZERO,ZERO,Work(ir+1),ldwrkr)\n!\n! Generate Q in U\n! (Workspace: need N*N+N+M, prefer N*N+N+M*NB)\n!\n CALL SORGQR(M,M,N,U,Ldu,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n ie = itau\n itauq = ie + N\n itaup = itauq + N\n iwork = itaup + N\n!\n! Bidiagonalize R in WORK(IR)\n! (Workspace: need N*N+4*N, prefer N*N+3*N+2*N*NB)\n!\n CALL SGEBRD(N,N,Work(ir),ldwrkr,S,Work(ie),Work(itauq)&\n & ,Work(itaup),Work(iwork),Lwork-iwork+1, &\n & ierr)\n!\n! Generate left bidiagonalizing vectors in WORK(IR)\n! (Workspace: need N*N+4*N, prefer N*N+3*N+N*NB)\n!\n CALL SORGBR('Q',N,N,N,Work(ir),ldwrkr,Work(itauq), &\n & Work(iwork),Lwork-iwork+1,ierr)\n iwork = ie + N\n!\n! Perform bidiagonal QR iteration, computing left\n! singular vectors of R in WORK(IR)\n! (Workspace: need N*N+BDSPAC)\n!\n CALL SBDSQR('U',N,0,N,0,S,Work(ie),dum,1,Work(ir), &\n & ldwrkr,dum,1,Work(iwork),Info)\n!\n! Multiply Q in U by left singular vectors of R in\n! WORK(IR), storing result in A\n! (Workspace: need N*N)\n!\n CALL SGEMM('N','N',M,N,N,ONE,U,Ldu,Work(ir),ldwrkr, &\n & ZERO,A,Lda)\n!\n! Copy left singular vectors of A from A to U\n!\n CALL SLACPY('F',M,N,A,Lda,U,Ldu)\n!\n ELSE\n!\n! Insufficient workspace for a fast algorithm\n!\n itau = 1\n iwork = itau + N\n!\n! Compute A=Q*R, copying result to U\n! (Workspace: need 2*N, prefer N+N*NB)\n!\n CALL SGEQRF(M,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n CALL SLACPY('L',M,N,A,Lda,U,Ldu)\n!\n! Generate Q in U\n! (Workspace: need N+M, prefer N+M*NB)\n!\n CALL SORGQR(M,M,N,U,Ldu,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n ie = itau\n itauq = ie + N\n itaup = itauq + N\n iwork = itaup + N\n!\n! Zero out below R in A\n!\n IF ( N>1 ) CALL SLASET('L',N-1,N-1,ZERO,ZERO,A(2,1), &\n & Lda)\n!\n! Bidiagonalize R in A\n! (Workspace: need 4*N, prefer 3*N+2*N*NB)\n!\n CALL SGEBRD(N,N,A,Lda,S,Work(ie),Work(itauq), &\n & Work(itaup),Work(iwork),Lwork-iwork+1, &\n & ierr)\n!\n! Multiply Q in U by left bidiagonalizing vectors\n! in A\n! (Workspace: need 3*N+M, prefer 3*N+M*NB)\n!\n CALL SORMBR('Q','R','N',M,N,N,A,Lda,Work(itauq),U,Ldu,&\n & Work(iwork),Lwork-iwork+1,ierr)\n iwork = ie + N\n!\n! Perform bidiagonal QR iteration, computing left\n! singular vectors of A in U\n! (Workspace: need BDSPAC)\n!\n CALL SBDSQR('U',N,0,M,0,S,Work(ie),dum,1,U,Ldu,dum,1, &\n & Work(iwork),Info)\n!\n ENDIF\n!\n ELSEIF ( wntvo ) THEN\n!\n! Path 8 (M much larger than N, JOBU='A', JOBVT='O')\n! M left singular vectors to be computed in U and\n! N right singular vectors to be overwritten on A\n!\n IF ( Lwork>=2*N*N+MAX(N+M,4*N,bdspac) ) THEN\n!\n! Sufficient workspace for a fast algorithm\n!\n iu = 1\n IF ( Lwork>=wrkbl+2*Lda*N ) THEN\n!\n! WORK(IU) is LDA by N and WORK(IR) is LDA by N\n!\n ldwrku = Lda\n ir = iu + ldwrku*N\n ldwrkr = Lda\n ELSEIF ( Lwork>=wrkbl+(Lda+N)*N ) THEN\n!\n! WORK(IU) is LDA by N and WORK(IR) is N by N\n!\n ldwrku = Lda\n ir = iu + ldwrku*N\n ldwrkr = N\n ELSE\n!\n! WORK(IU) is N by N and WORK(IR) is N by N\n!\n ldwrku = N\n ir = iu + ldwrku*N\n ldwrkr = N\n ENDIF\n itau = ir + ldwrkr*N\n iwork = itau + N\n!\n! Compute A=Q*R, copying result to U\n! (Workspace: need 2*N*N+2*N, prefer 2*N*N+N+N*NB)\n!\n CALL SGEQRF(M,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n CALL SLACPY('L',M,N,A,Lda,U,Ldu)\n!\n! Generate Q in U\n! (Workspace: need 2*N*N+N+M, prefer 2*N*N+N+M*NB)\n!\n CALL SORGQR(M,M,N,U,Ldu,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n!\n! Copy R to WORK(IU), zeroing out below it\n!\n CALL SLACPY('U',N,N,A,Lda,Work(iu),ldwrku)\n CALL SLASET('L',N-1,N-1,ZERO,ZERO,Work(iu+1),ldwrku)\n ie = itau\n itauq = ie + N\n itaup = itauq + N\n iwork = itaup + N\n!\n! Bidiagonalize R in WORK(IU), copying result to\n! WORK(IR)\n! (Workspace: need 2*N*N+4*N,\n! prefer 2*N*N+3*N+2*N*NB)\n!\n CALL SGEBRD(N,N,Work(iu),ldwrku,S,Work(ie),Work(itauq)&\n & ,Work(itaup),Work(iwork),Lwork-iwork+1, &\n & ierr)\n CALL SLACPY('U',N,N,Work(iu),ldwrku,Work(ir),ldwrkr)\n!\n! Generate left bidiagonalizing vectors in WORK(IU)\n! (Workspace: need 2*N*N+4*N, prefer 2*N*N+3*N+N*NB)\n!\n CALL SORGBR('Q',N,N,N,Work(iu),ldwrku,Work(itauq), &\n & Work(iwork),Lwork-iwork+1,ierr)\n!\n! Generate right bidiagonalizing vectors in WORK(IR)\n! (Workspace: need 2*N*N+4*N-1,\n! prefer 2*N*N+3*N+(N-1)*NB)\n!\n CALL SORGBR('P',N,N,N,Work(ir),ldwrkr,Work(itaup), &\n & Work(iwork),Lwork-iwork+1,ierr)\n iwork = ie + N\n!\n! Perform bidiagonal QR iteration, computing left\n! singular vectors of R in WORK(IU) and computing\n! right singular vectors of R in WORK(IR)\n! (Workspace: need 2*N*N+BDSPAC)\n!\n CALL SBDSQR('U',N,N,N,0,S,Work(ie),Work(ir),ldwrkr, &\n & Work(iu),ldwrku,dum,1,Work(iwork),Info)\n!\n! Multiply Q in U by left singular vectors of R in\n! WORK(IU), storing result in A\n! (Workspace: need N*N)\n!\n CALL SGEMM('N','N',M,N,N,ONE,U,Ldu,Work(iu),ldwrku, &\n & ZERO,A,Lda)\n!\n! Copy left singular vectors of A from A to U\n!\n CALL SLACPY('F',M,N,A,Lda,U,Ldu)\n!\n! Copy right singular vectors of R from WORK(IR) to A\n!\n CALL SLACPY('F',N,N,Work(ir),ldwrkr,A,Lda)\n!\n ELSE\n!\n! Insufficient workspace for a fast algorithm\n!\n itau = 1\n iwork = itau + N\n!\n! Compute A=Q*R, copying result to U\n! (Workspace: need 2*N, prefer N+N*NB)\n!\n CALL SGEQRF(M,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n CALL SLACPY('L',M,N,A,Lda,U,Ldu)\n!\n! Generate Q in U\n! (Workspace: need N+M, prefer N+M*NB)\n!\n CALL SORGQR(M,M,N,U,Ldu,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n ie = itau\n itauq = ie + N\n itaup = itauq + N\n iwork = itaup + N\n!\n! Zero out below R in A\n!\n IF ( N>1 ) CALL SLASET('L',N-1,N-1,ZERO,ZERO,A(2,1), &\n & Lda)\n!\n! Bidiagonalize R in A\n! (Workspace: need 4*N, prefer 3*N+2*N*NB)\n!\n CALL SGEBRD(N,N,A,Lda,S,Work(ie),Work(itauq), &\n & Work(itaup),Work(iwork),Lwork-iwork+1, &\n & ierr)\n!\n! Multiply Q in U by left bidiagonalizing vectors\n! in A\n! (Workspace: need 3*N+M, prefer 3*N+M*NB)\n!\n CALL SORMBR('Q','R','N',M,N,N,A,Lda,Work(itauq),U,Ldu,&\n & Work(iwork),Lwork-iwork+1,ierr)\n!\n! Generate right bidiagonalizing vectors in A\n! (Workspace: need 4*N-1, prefer 3*N+(N-1)*NB)\n!\n CALL SORGBR('P',N,N,N,A,Lda,Work(itaup),Work(iwork), &\n & Lwork-iwork+1,ierr)\n iwork = ie + N\n!\n! Perform bidiagonal QR iteration, computing left\n! singular vectors of A in U and computing right\n! singular vectors of A in A\n! (Workspace: need BDSPAC)\n!\n CALL SBDSQR('U',N,N,M,0,S,Work(ie),A,Lda,U,Ldu,dum,1, &\n & Work(iwork),Info)\n!\n ENDIF\n!\n ELSEIF ( wntvas ) THEN\n!\n! Path 9 (M much larger than N, JOBU='A', JOBVT='S'\n! or 'A')\n! M left singular vectors to be computed in U and\n! N right singular vectors to be computed in VT\n!\n IF ( Lwork>=N*N+MAX(N+M,4*N,bdspac) ) THEN\n!\n! Sufficient workspace for a fast algorithm\n!\n iu = 1\n IF ( Lwork>=wrkbl+Lda*N ) THEN\n!\n! WORK(IU) is LDA by N\n!\n ldwrku = Lda\n ELSE\n!\n! WORK(IU) is N by N\n!\n ldwrku = N\n ENDIF\n itau = iu + ldwrku*N\n iwork = itau + N\n!\n! Compute A=Q*R, copying result to U\n! (Workspace: need N*N+2*N, prefer N*N+N+N*NB)\n!\n CALL SGEQRF(M,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n CALL SLACPY('L',M,N,A,Lda,U,Ldu)\n!\n! Generate Q in U\n! (Workspace: need N*N+N+M, prefer N*N+N+M*NB)\n!\n CALL SORGQR(M,M,N,U,Ldu,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n!\n! Copy R to WORK(IU), zeroing out below it\n!\n CALL SLACPY('U',N,N,A,Lda,Work(iu),ldwrku)\n CALL SLASET('L',N-1,N-1,ZERO,ZERO,Work(iu+1),ldwrku)\n ie = itau\n itauq = ie + N\n itaup = itauq + N\n iwork = itaup + N\n!\n! Bidiagonalize R in WORK(IU), copying result to VT\n! (Workspace: need N*N+4*N, prefer N*N+3*N+2*N*NB)\n!\n CALL SGEBRD(N,N,Work(iu),ldwrku,S,Work(ie),Work(itauq)&\n & ,Work(itaup),Work(iwork),Lwork-iwork+1, &\n & ierr)\n CALL SLACPY('U',N,N,Work(iu),ldwrku,Vt,Ldvt)\n!\n! Generate left bidiagonalizing vectors in WORK(IU)\n! (Workspace: need N*N+4*N, prefer N*N+3*N+N*NB)\n!\n CALL SORGBR('Q',N,N,N,Work(iu),ldwrku,Work(itauq), &\n & Work(iwork),Lwork-iwork+1,ierr)\n!\n! Generate right bidiagonalizing vectors in VT\n! (Workspace: need N*N+4*N-1,\n! prefer N*N+3*N+(N-1)*NB)\n!\n CALL SORGBR('P',N,N,N,Vt,Ldvt,Work(itaup),Work(iwork),&\n & Lwork-iwork+1,ierr)\n iwork = ie + N\n!\n! Perform bidiagonal QR iteration, computing left\n! singular vectors of R in WORK(IU) and computing\n! right singular vectors of R in VT\n! (Workspace: need N*N+BDSPAC)\n!\n CALL SBDSQR('U',N,N,N,0,S,Work(ie),Vt,Ldvt,Work(iu), &\n & ldwrku,dum,1,Work(iwork),Info)\n!\n! Multiply Q in U by left singular vectors of R in\n! WORK(IU), storing result in A\n! (Workspace: need N*N)\n!\n CALL SGEMM('N','N',M,N,N,ONE,U,Ldu,Work(iu),ldwrku, &\n & ZERO,A,Lda)\n!\n! Copy left singular vectors of A from A to U\n!\n CALL SLACPY('F',M,N,A,Lda,U,Ldu)\n!\n ELSE\n!\n! Insufficient workspace for a fast algorithm\n!\n itau = 1\n iwork = itau + N\n!\n! Compute A=Q*R, copying result to U\n! (Workspace: need 2*N, prefer N+N*NB)\n!\n CALL SGEQRF(M,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n CALL SLACPY('L',M,N,A,Lda,U,Ldu)\n!\n! Generate Q in U\n! (Workspace: need N+M, prefer N+M*NB)\n!\n CALL SORGQR(M,M,N,U,Ldu,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n!\n! Copy R from A to VT, zeroing out below it\n!\n CALL SLACPY('U',N,N,A,Lda,Vt,Ldvt)\n IF ( N>1 ) CALL SLASET('L',N-1,N-1,ZERO,ZERO,Vt(2,1), &\n & Ldvt)\n ie = itau\n itauq = ie + N\n itaup = itauq + N\n iwork = itaup + N\n!\n! Bidiagonalize R in VT\n! (Workspace: need 4*N, prefer 3*N+2*N*NB)\n!\n CALL SGEBRD(N,N,Vt,Ldvt,S,Work(ie),Work(itauq), &\n & Work(itaup),Work(iwork),Lwork-iwork+1, &\n & ierr)\n!\n! Multiply Q in U by left bidiagonalizing vectors\n! in VT\n! (Workspace: need 3*N+M, prefer 3*N+M*NB)\n!\n CALL SORMBR('Q','R','N',M,N,N,Vt,Ldvt,Work(itauq),U, &\n & Ldu,Work(iwork),Lwork-iwork+1,ierr)\n!\n! Generate right bidiagonalizing vectors in VT\n! (Workspace: need 4*N-1, prefer 3*N+(N-1)*NB)\n!\n CALL SORGBR('P',N,N,N,Vt,Ldvt,Work(itaup),Work(iwork),&\n & Lwork-iwork+1,ierr)\n iwork = ie + N\n!\n! Perform bidiagonal QR iteration, computing left\n! singular vectors of A in U and computing right\n! singular vectors of A in VT\n! (Workspace: need BDSPAC)\n!\n CALL SBDSQR('U',N,N,M,0,S,Work(ie),Vt,Ldvt,U,Ldu,dum, &\n & 1,Work(iwork),Info)\n!\n ENDIF\n!\n ENDIF\n!\n ENDIF\n!\n!\n! A has more columns than rows. If A has sufficiently more\n! columns than rows, first reduce using the LQ decomposition (if\n! sufficient workspace available)\n!\n ELSEIF ( N>=mnthr ) THEN\n!\n IF ( wntvn ) THEN\n!\n! Path 1t(N much larger than M, JOBVT='N')\n! No right singular vectors to be computed\n!\n itau = 1\n!\n!\n iwork = itau + M\n!\n! Compute A=L*Q\n! (Workspace: need 2*M, prefer M+M*NB)\n!\n CALL SGELQF(M,N,A,Lda,Work(itau),Work(iwork),Lwork-iwork+1, &\n & ierr)\n!\n! Zero out above L\n!\n CALL SLASET('U',M-1,M-1,ZERO,ZERO,A(1,2),Lda)\n ie = 1\n itauq = ie + M\n itaup = itauq + M\n iwork = itaup + M\n!\n! Bidiagonalize L in A\n! (Workspace: need 4*M, prefer 3*M+2*M*NB)\n!\n CALL SGEBRD(M,M,A,Lda,S,Work(ie),Work(itauq),Work(itaup), &\n & Work(iwork),Lwork-iwork+1,ierr)\n!\n! If left singular vectors desired, generate Q\n! (Workspace: need 4*M, prefer 3*M+M*NB)\n!\n IF ( wntuo .OR. wntuas ) &\n & CALL SORGBR('Q',M,M,M,A,Lda,Work(itauq),Work(iwork), &\n & Lwork-iwork+1,ierr)\n iwork = ie + M\n nru = 0\n IF ( wntuo .OR. wntuas ) nru = M\n!\n! Perform bidiagonal QR iteration, computing left singular\n! vectors of A in A if desired\n! (Workspace: need BDSPAC)\n!\n CALL SBDSQR('U',M,0,nru,0,S,Work(ie),dum,1,A,Lda,dum,1, &\n & Work(iwork),Info)\n!\n! If left singular vectors desired in U, copy them there\n!\n IF ( wntuas ) CALL SLACPY('F',M,M,A,Lda,U,Ldu)\n!\n ELSEIF ( wntvo .AND. wntun ) THEN\n!\n! Path 2t(N much larger than M, JOBU='N', JOBVT='O')\n! M right singular vectors to be overwritten on A and\n! no left singular vectors to be computed\n!\n IF ( Lwork>=M*M+MAX(4*M,bdspac) ) THEN\n!\n! Sufficient workspace for a fast algorithm\n!\n ir = 1\n IF ( Lwork>=MAX(wrkbl,Lda*N+M)+Lda*M ) THEN\n!\n! WORK(IU) is LDA by N and WORK(IR) is LDA by M\n!\n ldwrku = Lda\n chunk = N\n ldwrkr = Lda\n ELSEIF ( Lwork>=MAX(wrkbl,Lda*N+M)+M*M ) THEN\n!\n! WORK(IU) is LDA by N and WORK(IR) is M by M\n!\n ldwrku = Lda\n chunk = N\n ldwrkr = M\n ELSE\n!\n! WORK(IU) is M by CHUNK and WORK(IR) is M by M\n!\n ldwrku = M\n chunk = (Lwork-M*M-M)/M\n ldwrkr = M\n ENDIF\n itau = ir + ldwrkr*M\n iwork = itau + M\n!\n! Compute A=L*Q\n! (Workspace: need M*M+2*M, prefer M*M+M+M*NB)\n!\n CALL SGELQF(M,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n!\n! Copy L to WORK(IR) and zero out above it\n!\n CALL SLACPY('L',M,M,A,Lda,Work(ir),ldwrkr)\n CALL SLASET('U',M-1,M-1,ZERO,ZERO,Work(ir+ldwrkr),ldwrkr)\n!\n! Generate Q in A\n! (Workspace: need M*M+2*M, prefer M*M+M+M*NB)\n!\n CALL SORGLQ(M,N,M,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n ie = itau\n itauq = ie + M\n itaup = itauq + M\n iwork = itaup + M\n!\n! Bidiagonalize L in WORK(IR)\n! (Workspace: need M*M+4*M, prefer M*M+3*M+2*M*NB)\n!\n CALL SGEBRD(M,M,Work(ir),ldwrkr,S,Work(ie),Work(itauq), &\n & Work(itaup),Work(iwork),Lwork-iwork+1,ierr)\n!\n! Generate right vectors bidiagonalizing L\n! (Workspace: need M*M+4*M-1, prefer M*M+3*M+(M-1)*NB)\n!\n CALL SORGBR('P',M,M,M,Work(ir),ldwrkr,Work(itaup), &\n & Work(iwork),Lwork-iwork+1,ierr)\n iwork = ie + M\n!\n! Perform bidiagonal QR iteration, computing right\n! singular vectors of L in WORK(IR)\n! (Workspace: need M*M+BDSPAC)\n!\n CALL SBDSQR('U',M,M,0,0,S,Work(ie),Work(ir),ldwrkr,dum,1,&\n & dum,1,Work(iwork),Info)\n iu = ie + M\n!\n! Multiply right singular vectors of L in WORK(IR) by Q\n! in A, storing result in WORK(IU) and copying to A\n! (Workspace: need M*M+2*M, prefer M*M+M*N+M)\n!\n DO i = 1 , N , chunk\n blk = MIN(N-i+1,chunk)\n CALL SGEMM('N','N',M,blk,M,ONE,Work(ir),ldwrkr,A(1,i),&\n & Lda,ZERO,Work(iu),ldwrku)\n CALL SLACPY('F',M,blk,Work(iu),ldwrku,A(1,i),Lda)\n ENDDO\n!\n ELSE\n!\n! Insufficient workspace for a fast algorithm\n!\n ie = 1\n itauq = ie + M\n itaup = itauq + M\n iwork = itaup + M\n!\n! Bidiagonalize A\n! (Workspace: need 3*M+N, prefer 3*M+(M+N)*NB)\n!\n CALL SGEBRD(M,N,A,Lda,S,Work(ie),Work(itauq),Work(itaup),&\n & Work(iwork),Lwork-iwork+1,ierr)\n!\n! Generate right vectors bidiagonalizing A\n! (Workspace: need 4*M, prefer 3*M+M*NB)\n!\n CALL SORGBR('P',M,N,M,A,Lda,Work(itaup),Work(iwork), &\n & Lwork-iwork+1,ierr)\n iwork = ie + M\n!\n! Perform bidiagonal QR iteration, computing right\n! singular vectors of A in A\n! (Workspace: need BDSPAC)\n!\n CALL SBDSQR('L',M,N,0,0,S,Work(ie),A,Lda,dum,1,dum,1, &\n & Work(iwork),Info)\n!\n ENDIF\n!\n ELSEIF ( wntvo .AND. wntuas ) THEN\n!\n! Path 3t(N much larger than M, JOBU='S' or 'A', JOBVT='O')\n! M right singular vectors to be overwritten on A and\n! M left singular vectors to be computed in U\n!\n IF ( Lwork>=M*M+MAX(4*M,bdspac) ) THEN\n!\n! Sufficient workspace for a fast algorithm\n!\n ir = 1\n IF ( Lwork>=MAX(wrkbl,Lda*N+M)+Lda*M ) THEN\n!\n! WORK(IU) is LDA by N and WORK(IR) is LDA by M\n!\n ldwrku = Lda\n chunk = N\n ldwrkr = Lda\n ELSEIF ( Lwork>=MAX(wrkbl,Lda*N+M)+M*M ) THEN\n!\n! WORK(IU) is LDA by N and WORK(IR) is M by M\n!\n ldwrku = Lda\n chunk = N\n ldwrkr = M\n ELSE\n!\n! WORK(IU) is M by CHUNK and WORK(IR) is M by M\n!\n ldwrku = M\n chunk = (Lwork-M*M-M)/M\n ldwrkr = M\n ENDIF\n itau = ir + ldwrkr*M\n iwork = itau + M\n!\n! Compute A=L*Q\n! (Workspace: need M*M+2*M, prefer M*M+M+M*NB)\n!\n CALL SGELQF(M,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n!\n! Copy L to U, zeroing about above it\n!\n CALL SLACPY('L',M,M,A,Lda,U,Ldu)\n CALL SLASET('U',M-1,M-1,ZERO,ZERO,U(1,2),Ldu)\n!\n! Generate Q in A\n! (Workspace: need M*M+2*M, prefer M*M+M+M*NB)\n!\n CALL SORGLQ(M,N,M,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n ie = itau\n itauq = ie + M\n itaup = itauq + M\n iwork = itaup + M\n!\n! Bidiagonalize L in U, copying result to WORK(IR)\n! (Workspace: need M*M+4*M, prefer M*M+3*M+2*M*NB)\n!\n CALL SGEBRD(M,M,U,Ldu,S,Work(ie),Work(itauq),Work(itaup),&\n & Work(iwork),Lwork-iwork+1,ierr)\n CALL SLACPY('U',M,M,U,Ldu,Work(ir),ldwrkr)\n!\n! Generate right vectors bidiagonalizing L in WORK(IR)\n! (Workspace: need M*M+4*M-1, prefer M*M+3*M+(M-1)*NB)\n!\n CALL SORGBR('P',M,M,M,Work(ir),ldwrkr,Work(itaup), &\n & Work(iwork),Lwork-iwork+1,ierr)\n!\n! Generate left vectors bidiagonalizing L in U\n! (Workspace: need M*M+4*M, prefer M*M+3*M+M*NB)\n!\n CALL SORGBR('Q',M,M,M,U,Ldu,Work(itauq),Work(iwork), &\n & Lwork-iwork+1,ierr)\n iwork = ie + M\n!\n! Perform bidiagonal QR iteration, computing left\n! singular vectors of L in U, and computing right\n! singular vectors of L in WORK(IR)\n! (Workspace: need M*M+BDSPAC)\n!\n CALL SBDSQR('U',M,M,M,0,S,Work(ie),Work(ir),ldwrkr,U,Ldu,&\n & dum,1,Work(iwork),Info)\n iu = ie + M\n!\n! Multiply right singular vectors of L in WORK(IR) by Q\n! in A, storing result in WORK(IU) and copying to A\n! (Workspace: need M*M+2*M, prefer M*M+M*N+M))\n!\n DO i = 1 , N , chunk\n blk = MIN(N-i+1,chunk)\n CALL SGEMM('N','N',M,blk,M,ONE,Work(ir),ldwrkr,A(1,i),&\n & Lda,ZERO,Work(iu),ldwrku)\n CALL SLACPY('F',M,blk,Work(iu),ldwrku,A(1,i),Lda)\n ENDDO\n!\n ELSE\n!\n! Insufficient workspace for a fast algorithm\n!\n itau = 1\n iwork = itau + M\n!\n! Compute A=L*Q\n! (Workspace: need 2*M, prefer M+M*NB)\n!\n CALL SGELQF(M,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n!\n! Copy L to U, zeroing out above it\n!\n CALL SLACPY('L',M,M,A,Lda,U,Ldu)\n CALL SLASET('U',M-1,M-1,ZERO,ZERO,U(1,2),Ldu)\n!\n! Generate Q in A\n! (Workspace: need 2*M, prefer M+M*NB)\n!\n CALL SORGLQ(M,N,M,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n ie = itau\n itauq = ie + M\n itaup = itauq + M\n iwork = itaup + M\n!\n! Bidiagonalize L in U\n! (Workspace: need 4*M, prefer 3*M+2*M*NB)\n!\n CALL SGEBRD(M,M,U,Ldu,S,Work(ie),Work(itauq),Work(itaup),&\n & Work(iwork),Lwork-iwork+1,ierr)\n!\n! Multiply right vectors bidiagonalizing L by Q in A\n! (Workspace: need 3*M+N, prefer 3*M+N*NB)\n!\n CALL SORMBR('P','L','T',M,N,M,U,Ldu,Work(itaup),A,Lda, &\n & Work(iwork),Lwork-iwork+1,ierr)\n!\n! Generate left vectors bidiagonalizing L in U\n! (Workspace: need 4*M, prefer 3*M+M*NB)\n!\n CALL SORGBR('Q',M,M,M,U,Ldu,Work(itauq),Work(iwork), &\n & Lwork-iwork+1,ierr)\n iwork = ie + M\n!\n! Perform bidiagonal QR iteration, computing left\n! singular vectors of A in U and computing right\n! singular vectors of A in A\n! (Workspace: need BDSPAC)\n!\n CALL SBDSQR('U',M,N,M,0,S,Work(ie),A,Lda,U,Ldu,dum,1, &\n & Work(iwork),Info)\n!\n ENDIF\n!\n ELSEIF ( wntvs ) THEN\n!\n IF ( wntun ) THEN\n!\n! Path 4t(N much larger than M, JOBU='N', JOBVT='S')\n! M right singular vectors to be computed in VT and\n! no left singular vectors to be computed\n!\n IF ( Lwork>=M*M+MAX(4*M,bdspac) ) THEN\n!\n! Sufficient workspace for a fast algorithm\n!\n ir = 1\n IF ( Lwork>=wrkbl+Lda*M ) THEN\n!\n! WORK(IR) is LDA by M\n!\n ldwrkr = Lda\n ELSE\n!\n! WORK(IR) is M by M\n!\n ldwrkr = M\n ENDIF\n itau = ir + ldwrkr*M\n iwork = itau + M\n!\n! Compute A=L*Q\n! (Workspace: need M*M+2*M, prefer M*M+M+M*NB)\n!\n CALL SGELQF(M,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n!\n! Copy L to WORK(IR), zeroing out above it\n!\n CALL SLACPY('L',M,M,A,Lda,Work(ir),ldwrkr)\n CALL SLASET('U',M-1,M-1,ZERO,ZERO,Work(ir+ldwrkr), &\n & ldwrkr)\n!\n! Generate Q in A\n! (Workspace: need M*M+2*M, prefer M*M+M+M*NB)\n!\n CALL SORGLQ(M,N,M,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n ie = itau\n itauq = ie + M\n itaup = itauq + M\n iwork = itaup + M\n!\n! Bidiagonalize L in WORK(IR)\n! (Workspace: need M*M+4*M, prefer M*M+3*M+2*M*NB)\n!\n CALL SGEBRD(M,M,Work(ir),ldwrkr,S,Work(ie),Work(itauq)&\n & ,Work(itaup),Work(iwork),Lwork-iwork+1, &\n & ierr)\n!\n! Generate right vectors bidiagonalizing L in\n! WORK(IR)\n! (Workspace: need M*M+4*M, prefer M*M+3*M+(M-1)*NB)\n!\n CALL SORGBR('P',M,M,M,Work(ir),ldwrkr,Work(itaup), &\n & Work(iwork),Lwork-iwork+1,ierr)\n iwork = ie + M\n!\n! Perform bidiagonal QR iteration, computing right\n! singular vectors of L in WORK(IR)\n! (Workspace: need M*M+BDSPAC)\n!\n CALL SBDSQR('U',M,M,0,0,S,Work(ie),Work(ir),ldwrkr, &\n & dum,1,dum,1,Work(iwork),Info)\n!\n! Multiply right singular vectors of L in WORK(IR) by\n! Q in A, storing result in VT\n! (Workspace: need M*M)\n!\n CALL SGEMM('N','N',M,N,M,ONE,Work(ir),ldwrkr,A,Lda, &\n & ZERO,Vt,Ldvt)\n!\n ELSE\n!\n! Insufficient workspace for a fast algorithm\n!\n itau = 1\n iwork = itau + M\n!\n! Compute A=L*Q\n! (Workspace: need 2*M, prefer M+M*NB)\n!\n CALL SGELQF(M,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n!\n! Copy result to VT\n!\n CALL SLACPY('U',M,N,A,Lda,Vt,Ldvt)\n!\n! Generate Q in VT\n! (Workspace: need 2*M, prefer M+M*NB)\n!\n CALL SORGLQ(M,N,M,Vt,Ldvt,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n ie = itau\n itauq = ie + M\n itaup = itauq + M\n iwork = itaup + M\n!\n! Zero out above L in A\n!\n CALL SLASET('U',M-1,M-1,ZERO,ZERO,A(1,2),Lda)\n!\n! Bidiagonalize L in A\n! (Workspace: need 4*M, prefer 3*M+2*M*NB)\n!\n CALL SGEBRD(M,M,A,Lda,S,Work(ie),Work(itauq), &\n & Work(itaup),Work(iwork),Lwork-iwork+1, &\n & ierr)\n!\n! Multiply right vectors bidiagonalizing L by Q in VT\n! (Workspace: need 3*M+N, prefer 3*M+N*NB)\n!\n CALL SORMBR('P','L','T',M,N,M,A,Lda,Work(itaup),Vt, &\n & Ldvt,Work(iwork),Lwork-iwork+1,ierr)\n iwork = ie + M\n!\n! Perform bidiagonal QR iteration, computing right\n! singular vectors of A in VT\n! (Workspace: need BDSPAC)\n!\n CALL SBDSQR('U',M,N,0,0,S,Work(ie),Vt,Ldvt,dum,1,dum, &\n & 1,Work(iwork),Info)\n!\n ENDIF\n!\n ELSEIF ( wntuo ) THEN\n!\n! Path 5t(N much larger than M, JOBU='O', JOBVT='S')\n! M right singular vectors to be computed in VT and\n! M left singular vectors to be overwritten on A\n!\n IF ( Lwork>=2*M*M+MAX(4*M,bdspac) ) THEN\n!\n! Sufficient workspace for a fast algorithm\n!\n iu = 1\n IF ( Lwork>=wrkbl+2*Lda*M ) THEN\n!\n! WORK(IU) is LDA by M and WORK(IR) is LDA by M\n!\n ldwrku = Lda\n ir = iu + ldwrku*M\n ldwrkr = Lda\n ELSEIF ( Lwork>=wrkbl+(Lda+M)*M ) THEN\n!\n! WORK(IU) is LDA by M and WORK(IR) is M by M\n!\n ldwrku = Lda\n ir = iu + ldwrku*M\n ldwrkr = M\n ELSE\n!\n! WORK(IU) is M by M and WORK(IR) is M by M\n!\n ldwrku = M\n ir = iu + ldwrku*M\n ldwrkr = M\n ENDIF\n itau = ir + ldwrkr*M\n iwork = itau + M\n!\n! Compute A=L*Q\n! (Workspace: need 2*M*M+2*M, prefer 2*M*M+M+M*NB)\n!\n CALL SGELQF(M,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n!\n! Copy L to WORK(IU), zeroing out below it\n!\n CALL SLACPY('L',M,M,A,Lda,Work(iu),ldwrku)\n CALL SLASET('U',M-1,M-1,ZERO,ZERO,Work(iu+ldwrku), &\n & ldwrku)\n!\n! Generate Q in A\n! (Workspace: need 2*M*M+2*M, prefer 2*M*M+M+M*NB)\n!\n CALL SORGLQ(M,N,M,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n ie = itau\n itauq = ie + M\n itaup = itauq + M\n iwork = itaup + M\n!\n! Bidiagonalize L in WORK(IU), copying result to\n! WORK(IR)\n! (Workspace: need 2*M*M+4*M,\n! prefer 2*M*M+3*M+2*M*NB)\n!\n CALL SGEBRD(M,M,Work(iu),ldwrku,S,Work(ie),Work(itauq)&\n & ,Work(itaup),Work(iwork),Lwork-iwork+1, &\n & ierr)\n CALL SLACPY('L',M,M,Work(iu),ldwrku,Work(ir),ldwrkr)\n!\n! Generate right bidiagonalizing vectors in WORK(IU)\n! (Workspace: need 2*M*M+4*M-1,\n! prefer 2*M*M+3*M+(M-1)*NB)\n!\n CALL SORGBR('P',M,M,M,Work(iu),ldwrku,Work(itaup), &\n & Work(iwork),Lwork-iwork+1,ierr)\n!\n! Generate left bidiagonalizing vectors in WORK(IR)\n! (Workspace: need 2*M*M+4*M, prefer 2*M*M+3*M+M*NB)\n!\n CALL SORGBR('Q',M,M,M,Work(ir),ldwrkr,Work(itauq), &\n & Work(iwork),Lwork-iwork+1,ierr)\n iwork = ie + M\n!\n! Perform bidiagonal QR iteration, computing left\n! singular vectors of L in WORK(IR) and computing\n! right singular vectors of L in WORK(IU)\n! (Workspace: need 2*M*M+BDSPAC)\n!\n CALL SBDSQR('U',M,M,M,0,S,Work(ie),Work(iu),ldwrku, &\n & Work(ir),ldwrkr,dum,1,Work(iwork),Info)\n!\n! Multiply right singular vectors of L in WORK(IU) by\n! Q in A, storing result in VT\n! (Workspace: need M*M)\n!\n CALL SGEMM('N','N',M,N,M,ONE,Work(iu),ldwrku,A,Lda, &\n & ZERO,Vt,Ldvt)\n!\n! Copy left singular vectors of L to A\n! (Workspace: need M*M)\n!\n CALL SLACPY('F',M,M,Work(ir),ldwrkr,A,Lda)\n!\n ELSE\n!\n! Insufficient workspace for a fast algorithm\n!\n itau = 1\n iwork = itau + M\n!\n! Compute A=L*Q, copying result to VT\n! (Workspace: need 2*M, prefer M+M*NB)\n!\n CALL SGELQF(M,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n CALL SLACPY('U',M,N,A,Lda,Vt,Ldvt)\n!\n! Generate Q in VT\n! (Workspace: need 2*M, prefer M+M*NB)\n!\n CALL SORGLQ(M,N,M,Vt,Ldvt,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n ie = itau\n itauq = ie + M\n itaup = itauq + M\n iwork = itaup + M\n!\n! Zero out above L in A\n!\n CALL SLASET('U',M-1,M-1,ZERO,ZERO,A(1,2),Lda)\n!\n! Bidiagonalize L in A\n! (Workspace: need 4*M, prefer 3*M+2*M*NB)\n!\n CALL SGEBRD(M,M,A,Lda,S,Work(ie),Work(itauq), &\n & Work(itaup),Work(iwork),Lwork-iwork+1, &\n & ierr)\n!\n! Multiply right vectors bidiagonalizing L by Q in VT\n! (Workspace: need 3*M+N, prefer 3*M+N*NB)\n!\n CALL SORMBR('P','L','T',M,N,M,A,Lda,Work(itaup),Vt, &\n & Ldvt,Work(iwork),Lwork-iwork+1,ierr)\n!\n! Generate left bidiagonalizing vectors of L in A\n! (Workspace: need 4*M, prefer 3*M+M*NB)\n!\n CALL SORGBR('Q',M,M,M,A,Lda,Work(itauq),Work(iwork), &\n & Lwork-iwork+1,ierr)\n iwork = ie + M\n!\n! Perform bidiagonal QR iteration, compute left\n! singular vectors of A in A and compute right\n! singular vectors of A in VT\n! (Workspace: need BDSPAC)\n!\n CALL SBDSQR('U',M,N,M,0,S,Work(ie),Vt,Ldvt,A,Lda,dum, &\n & 1,Work(iwork),Info)\n!\n ENDIF\n!\n ELSEIF ( wntuas ) THEN\n!\n! Path 6t(N much larger than M, JOBU='S' or 'A',\n! JOBVT='S')\n! M right singular vectors to be computed in VT and\n! M left singular vectors to be computed in U\n!\n IF ( Lwork>=M*M+MAX(4*M,bdspac) ) THEN\n!\n! Sufficient workspace for a fast algorithm\n!\n iu = 1\n IF ( Lwork>=wrkbl+Lda*M ) THEN\n!\n! WORK(IU) is LDA by N\n!\n ldwrku = Lda\n ELSE\n!\n! WORK(IU) is LDA by M\n!\n ldwrku = M\n ENDIF\n itau = iu + ldwrku*M\n iwork = itau + M\n!\n! Compute A=L*Q\n! (Workspace: need M*M+2*M, prefer M*M+M+M*NB)\n!\n CALL SGELQF(M,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n!\n! Copy L to WORK(IU), zeroing out above it\n!\n CALL SLACPY('L',M,M,A,Lda,Work(iu),ldwrku)\n CALL SLASET('U',M-1,M-1,ZERO,ZERO,Work(iu+ldwrku), &\n & ldwrku)\n!\n! Generate Q in A\n! (Workspace: need M*M+2*M, prefer M*M+M+M*NB)\n!\n CALL SORGLQ(M,N,M,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n ie = itau\n itauq = ie + M\n itaup = itauq + M\n iwork = itaup + M\n!\n! Bidiagonalize L in WORK(IU), copying result to U\n! (Workspace: need M*M+4*M, prefer M*M+3*M+2*M*NB)\n!\n CALL SGEBRD(M,M,Work(iu),ldwrku,S,Work(ie),Work(itauq)&\n & ,Work(itaup),Work(iwork),Lwork-iwork+1, &\n & ierr)\n CALL SLACPY('L',M,M,Work(iu),ldwrku,U,Ldu)\n!\n! Generate right bidiagonalizing vectors in WORK(IU)\n! (Workspace: need M*M+4*M-1,\n! prefer M*M+3*M+(M-1)*NB)\n!\n CALL SORGBR('P',M,M,M,Work(iu),ldwrku,Work(itaup), &\n & Work(iwork),Lwork-iwork+1,ierr)\n!\n! Generate left bidiagonalizing vectors in U\n! (Workspace: need M*M+4*M, prefer M*M+3*M+M*NB)\n!\n CALL SORGBR('Q',M,M,M,U,Ldu,Work(itauq),Work(iwork), &\n & Lwork-iwork+1,ierr)\n iwork = ie + M\n!\n! Perform bidiagonal QR iteration, computing left\n! singular vectors of L in U and computing right\n! singular vectors of L in WORK(IU)\n! (Workspace: need M*M+BDSPAC)\n!\n CALL SBDSQR('U',M,M,M,0,S,Work(ie),Work(iu),ldwrku,U, &\n & Ldu,dum,1,Work(iwork),Info)\n!\n! Multiply right singular vectors of L in WORK(IU) by\n! Q in A, storing result in VT\n! (Workspace: need M*M)\n!\n CALL SGEMM('N','N',M,N,M,ONE,Work(iu),ldwrku,A,Lda, &\n & ZERO,Vt,Ldvt)\n!\n ELSE\n!\n! Insufficient workspace for a fast algorithm\n!\n itau = 1\n iwork = itau + M\n!\n! Compute A=L*Q, copying result to VT\n! (Workspace: need 2*M, prefer M+M*NB)\n!\n CALL SGELQF(M,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n CALL SLACPY('U',M,N,A,Lda,Vt,Ldvt)\n!\n! Generate Q in VT\n! (Workspace: need 2*M, prefer M+M*NB)\n!\n CALL SORGLQ(M,N,M,Vt,Ldvt,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n!\n! Copy L to U, zeroing out above it\n!\n CALL SLACPY('L',M,M,A,Lda,U,Ldu)\n CALL SLASET('U',M-1,M-1,ZERO,ZERO,U(1,2),Ldu)\n ie = itau\n itauq = ie + M\n itaup = itauq + M\n iwork = itaup + M\n!\n! Bidiagonalize L in U\n! (Workspace: need 4*M, prefer 3*M+2*M*NB)\n!\n CALL SGEBRD(M,M,U,Ldu,S,Work(ie),Work(itauq), &\n & Work(itaup),Work(iwork),Lwork-iwork+1, &\n & ierr)\n!\n! Multiply right bidiagonalizing vectors in U by Q\n! in VT\n! (Workspace: need 3*M+N, prefer 3*M+N*NB)\n!\n CALL SORMBR('P','L','T',M,N,M,U,Ldu,Work(itaup),Vt, &\n & Ldvt,Work(iwork),Lwork-iwork+1,ierr)\n!\n! Generate left bidiagonalizing vectors in U\n! (Workspace: need 4*M, prefer 3*M+M*NB)\n!\n CALL SORGBR('Q',M,M,M,U,Ldu,Work(itauq),Work(iwork), &\n & Lwork-iwork+1,ierr)\n iwork = ie + M\n!\n! Perform bidiagonal QR iteration, computing left\n! singular vectors of A in U and computing right\n! singular vectors of A in VT\n! (Workspace: need BDSPAC)\n!\n CALL SBDSQR('U',M,N,M,0,S,Work(ie),Vt,Ldvt,U,Ldu,dum, &\n & 1,Work(iwork),Info)\n!\n ENDIF\n!\n ENDIF\n!\n ELSEIF ( wntva ) THEN\n!\n IF ( wntun ) THEN\n!\n! Path 7t(N much larger than M, JOBU='N', JOBVT='A')\n! N right singular vectors to be computed in VT and\n! no left singular vectors to be computed\n!\n IF ( Lwork>=M*M+MAX(N+M,4*M,bdspac) ) THEN\n!\n! Sufficient workspace for a fast algorithm\n!\n ir = 1\n IF ( Lwork>=wrkbl+Lda*M ) THEN\n!\n! WORK(IR) is LDA by M\n!\n ldwrkr = Lda\n ELSE\n!\n! WORK(IR) is M by M\n!\n ldwrkr = M\n ENDIF\n itau = ir + ldwrkr*M\n iwork = itau + M\n!\n! Compute A=L*Q, copying result to VT\n! (Workspace: need M*M+2*M, prefer M*M+M+M*NB)\n!\n CALL SGELQF(M,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n CALL SLACPY('U',M,N,A,Lda,Vt,Ldvt)\n!\n! Copy L to WORK(IR), zeroing out above it\n!\n CALL SLACPY('L',M,M,A,Lda,Work(ir),ldwrkr)\n CALL SLASET('U',M-1,M-1,ZERO,ZERO,Work(ir+ldwrkr), &\n & ldwrkr)\n!\n! Generate Q in VT\n! (Workspace: need M*M+M+N, prefer M*M+M+N*NB)\n!\n CALL SORGLQ(N,N,M,Vt,Ldvt,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n ie = itau\n itauq = ie + M\n itaup = itauq + M\n iwork = itaup + M\n!\n! Bidiagonalize L in WORK(IR)\n! (Workspace: need M*M+4*M, prefer M*M+3*M+2*M*NB)\n!\n CALL SGEBRD(M,M,Work(ir),ldwrkr,S,Work(ie),Work(itauq)&\n & ,Work(itaup),Work(iwork),Lwork-iwork+1, &\n & ierr)\n!\n! Generate right bidiagonalizing vectors in WORK(IR)\n! (Workspace: need M*M+4*M-1,\n! prefer M*M+3*M+(M-1)*NB)\n!\n CALL SORGBR('P',M,M,M,Work(ir),ldwrkr,Work(itaup), &\n & Work(iwork),Lwork-iwork+1,ierr)\n iwork = ie + M\n!\n! Perform bidiagonal QR iteration, computing right\n! singular vectors of L in WORK(IR)\n! (Workspace: need M*M+BDSPAC)\n!\n CALL SBDSQR('U',M,M,0,0,S,Work(ie),Work(ir),ldwrkr, &\n & dum,1,dum,1,Work(iwork),Info)\n!\n! Multiply right singular vectors of L in WORK(IR) by\n! Q in VT, storing result in A\n! (Workspace: need M*M)\n!\n CALL SGEMM('N','N',M,N,M,ONE,Work(ir),ldwrkr,Vt,Ldvt, &\n & ZERO,A,Lda)\n!\n! Copy right singular vectors of A from A to VT\n!\n CALL SLACPY('F',M,N,A,Lda,Vt,Ldvt)\n!\n ELSE\n!\n! Insufficient workspace for a fast algorithm\n!\n itau = 1\n iwork = itau + M\n!\n! Compute A=L*Q, copying result to VT\n! (Workspace: need 2*M, prefer M+M*NB)\n!\n CALL SGELQF(M,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n CALL SLACPY('U',M,N,A,Lda,Vt,Ldvt)\n!\n! Generate Q in VT\n! (Workspace: need M+N, prefer M+N*NB)\n!\n CALL SORGLQ(N,N,M,Vt,Ldvt,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n ie = itau\n itauq = ie + M\n itaup = itauq + M\n iwork = itaup + M\n!\n! Zero out above L in A\n!\n CALL SLASET('U',M-1,M-1,ZERO,ZERO,A(1,2),Lda)\n!\n! Bidiagonalize L in A\n! (Workspace: need 4*M, prefer 3*M+2*M*NB)\n!\n CALL SGEBRD(M,M,A,Lda,S,Work(ie),Work(itauq), &\n & Work(itaup),Work(iwork),Lwork-iwork+1, &\n & ierr)\n!\n! Multiply right bidiagonalizing vectors in A by Q\n! in VT\n! (Workspace: need 3*M+N, prefer 3*M+N*NB)\n!\n CALL SORMBR('P','L','T',M,N,M,A,Lda,Work(itaup),Vt, &\n & Ldvt,Work(iwork),Lwork-iwork+1,ierr)\n iwork = ie + M\n!\n! Perform bidiagonal QR iteration, computing right\n! singular vectors of A in VT\n! (Workspace: need BDSPAC)\n!\n CALL SBDSQR('U',M,N,0,0,S,Work(ie),Vt,Ldvt,dum,1,dum, &\n & 1,Work(iwork),Info)\n!\n ENDIF\n!\n ELSEIF ( wntuo ) THEN\n!\n! Path 8t(N much larger than M, JOBU='O', JOBVT='A')\n! N right singular vectors to be computed in VT and\n! M left singular vectors to be overwritten on A\n!\n IF ( Lwork>=2*M*M+MAX(N+M,4*M,bdspac) ) THEN\n!\n! Sufficient workspace for a fast algorithm\n!\n iu = 1\n IF ( Lwork>=wrkbl+2*Lda*M ) THEN\n!\n! WORK(IU) is LDA by M and WORK(IR) is LDA by M\n!\n ldwrku = Lda\n ir = iu + ldwrku*M\n ldwrkr = Lda\n ELSEIF ( Lwork>=wrkbl+(Lda+M)*M ) THEN\n!\n! WORK(IU) is LDA by M and WORK(IR) is M by M\n!\n ldwrku = Lda\n ir = iu + ldwrku*M\n ldwrkr = M\n ELSE\n!\n! WORK(IU) is M by M and WORK(IR) is M by M\n!\n ldwrku = M\n ir = iu + ldwrku*M\n ldwrkr = M\n ENDIF\n itau = ir + ldwrkr*M\n iwork = itau + M\n!\n! Compute A=L*Q, copying result to VT\n! (Workspace: need 2*M*M+2*M, prefer 2*M*M+M+M*NB)\n!\n CALL SGELQF(M,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n CALL SLACPY('U',M,N,A,Lda,Vt,Ldvt)\n!\n! Generate Q in VT\n! (Workspace: need 2*M*M+M+N, prefer 2*M*M+M+N*NB)\n!\n CALL SORGLQ(N,N,M,Vt,Ldvt,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n!\n! Copy L to WORK(IU), zeroing out above it\n!\n CALL SLACPY('L',M,M,A,Lda,Work(iu),ldwrku)\n CALL SLASET('U',M-1,M-1,ZERO,ZERO,Work(iu+ldwrku), &\n & ldwrku)\n ie = itau\n itauq = ie + M\n itaup = itauq + M\n iwork = itaup + M\n!\n! Bidiagonalize L in WORK(IU), copying result to\n! WORK(IR)\n! (Workspace: need 2*M*M+4*M,\n! prefer 2*M*M+3*M+2*M*NB)\n!\n CALL SGEBRD(M,M,Work(iu),ldwrku,S,Work(ie),Work(itauq)&\n & ,Work(itaup),Work(iwork),Lwork-iwork+1, &\n & ierr)\n CALL SLACPY('L',M,M,Work(iu),ldwrku,Work(ir),ldwrkr)\n!\n! Generate right bidiagonalizing vectors in WORK(IU)\n! (Workspace: need 2*M*M+4*M-1,\n! prefer 2*M*M+3*M+(M-1)*NB)\n!\n CALL SORGBR('P',M,M,M,Work(iu),ldwrku,Work(itaup), &\n & Work(iwork),Lwork-iwork+1,ierr)\n!\n! Generate left bidiagonalizing vectors in WORK(IR)\n! (Workspace: need 2*M*M+4*M, prefer 2*M*M+3*M+M*NB)\n!\n CALL SORGBR('Q',M,M,M,Work(ir),ldwrkr,Work(itauq), &\n & Work(iwork),Lwork-iwork+1,ierr)\n iwork = ie + M\n!\n! Perform bidiagonal QR iteration, computing left\n! singular vectors of L in WORK(IR) and computing\n! right singular vectors of L in WORK(IU)\n! (Workspace: need 2*M*M+BDSPAC)\n!\n CALL SBDSQR('U',M,M,M,0,S,Work(ie),Work(iu),ldwrku, &\n & Work(ir),ldwrkr,dum,1,Work(iwork),Info)\n!\n! Multiply right singular vectors of L in WORK(IU) by\n! Q in VT, storing result in A\n! (Workspace: need M*M)\n!\n CALL SGEMM('N','N',M,N,M,ONE,Work(iu),ldwrku,Vt,Ldvt, &\n & ZERO,A,Lda)\n!\n! Copy right singular vectors of A from A to VT\n!\n CALL SLACPY('F',M,N,A,Lda,Vt,Ldvt)\n!\n! Copy left singular vectors of A from WORK(IR) to A\n!\n CALL SLACPY('F',M,M,Work(ir),ldwrkr,A,Lda)\n!\n ELSE\n!\n! Insufficient workspace for a fast algorithm\n!\n itau = 1\n iwork = itau + M\n!\n! Compute A=L*Q, copying result to VT\n! (Workspace: need 2*M, prefer M+M*NB)\n!\n CALL SGELQF(M,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n CALL SLACPY('U',M,N,A,Lda,Vt,Ldvt)\n!\n! Generate Q in VT\n! (Workspace: need M+N, prefer M+N*NB)\n!\n CALL SORGLQ(N,N,M,Vt,Ldvt,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n ie = itau\n itauq = ie + M\n itaup = itauq + M\n iwork = itaup + M\n!\n! Zero out above L in A\n!\n CALL SLASET('U',M-1,M-1,ZERO,ZERO,A(1,2),Lda)\n!\n! Bidiagonalize L in A\n! (Workspace: need 4*M, prefer 3*M+2*M*NB)\n!\n CALL SGEBRD(M,M,A,Lda,S,Work(ie),Work(itauq), &\n & Work(itaup),Work(iwork),Lwork-iwork+1, &\n & ierr)\n!\n! Multiply right bidiagonalizing vectors in A by Q\n! in VT\n! (Workspace: need 3*M+N, prefer 3*M+N*NB)\n!\n CALL SORMBR('P','L','T',M,N,M,A,Lda,Work(itaup),Vt, &\n & Ldvt,Work(iwork),Lwork-iwork+1,ierr)\n!\n! Generate left bidiagonalizing vectors in A\n! (Workspace: need 4*M, prefer 3*M+M*NB)\n!\n CALL SORGBR('Q',M,M,M,A,Lda,Work(itauq),Work(iwork), &\n & Lwork-iwork+1,ierr)\n iwork = ie + M\n!\n! Perform bidiagonal QR iteration, computing left\n! singular vectors of A in A and computing right\n! singular vectors of A in VT\n! (Workspace: need BDSPAC)\n!\n CALL SBDSQR('U',M,N,M,0,S,Work(ie),Vt,Ldvt,A,Lda,dum, &\n & 1,Work(iwork),Info)\n!\n ENDIF\n!\n ELSEIF ( wntuas ) THEN\n!\n! Path 9t(N much larger than M, JOBU='S' or 'A',\n! JOBVT='A')\n! N right singular vectors to be computed in VT and\n! M left singular vectors to be computed in U\n!\n IF ( Lwork>=M*M+MAX(N+M,4*M,bdspac) ) THEN\n!\n! Sufficient workspace for a fast algorithm\n!\n iu = 1\n IF ( Lwork>=wrkbl+Lda*M ) THEN\n!\n! WORK(IU) is LDA by M\n!\n ldwrku = Lda\n ELSE\n!\n! WORK(IU) is M by M\n!\n ldwrku = M\n ENDIF\n itau = iu + ldwrku*M\n iwork = itau + M\n!\n! Compute A=L*Q, copying result to VT\n! (Workspace: need M*M+2*M, prefer M*M+M+M*NB)\n!\n CALL SGELQF(M,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n CALL SLACPY('U',M,N,A,Lda,Vt,Ldvt)\n!\n! Generate Q in VT\n! (Workspace: need M*M+M+N, prefer M*M+M+N*NB)\n!\n CALL SORGLQ(N,N,M,Vt,Ldvt,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n!\n! Copy L to WORK(IU), zeroing out above it\n!\n CALL SLACPY('L',M,M,A,Lda,Work(iu),ldwrku)\n CALL SLASET('U',M-1,M-1,ZERO,ZERO,Work(iu+ldwrku), &\n & ldwrku)\n ie = itau\n itauq = ie + M\n itaup = itauq + M\n iwork = itaup + M\n!\n! Bidiagonalize L in WORK(IU), copying result to U\n! (Workspace: need M*M+4*M, prefer M*M+3*M+2*M*NB)\n!\n CALL SGEBRD(M,M,Work(iu),ldwrku,S,Work(ie),Work(itauq)&\n & ,Work(itaup),Work(iwork),Lwork-iwork+1, &\n & ierr)\n CALL SLACPY('L',M,M,Work(iu),ldwrku,U,Ldu)\n!\n! Generate right bidiagonalizing vectors in WORK(IU)\n! (Workspace: need M*M+4*M, prefer M*M+3*M+(M-1)*NB)\n!\n CALL SORGBR('P',M,M,M,Work(iu),ldwrku,Work(itaup), &\n & Work(iwork),Lwork-iwork+1,ierr)\n!\n! Generate left bidiagonalizing vectors in U\n! (Workspace: need M*M+4*M, prefer M*M+3*M+M*NB)\n!\n CALL SORGBR('Q',M,M,M,U,Ldu,Work(itauq),Work(iwork), &\n & Lwork-iwork+1,ierr)\n iwork = ie + M\n!\n! Perform bidiagonal QR iteration, computing left\n! singular vectors of L in U and computing right\n! singular vectors of L in WORK(IU)\n! (Workspace: need M*M+BDSPAC)\n!\n CALL SBDSQR('U',M,M,M,0,S,Work(ie),Work(iu),ldwrku,U, &\n & Ldu,dum,1,Work(iwork),Info)\n!\n! Multiply right singular vectors of L in WORK(IU) by\n! Q in VT, storing result in A\n! (Workspace: need M*M)\n!\n CALL SGEMM('N','N',M,N,M,ONE,Work(iu),ldwrku,Vt,Ldvt, &\n & ZERO,A,Lda)\n!\n! Copy right singular vectors of A from A to VT\n!\n CALL SLACPY('F',M,N,A,Lda,Vt,Ldvt)\n!\n ELSE\n!\n! Insufficient workspace for a fast algorithm\n!\n itau = 1\n iwork = itau + M\n!\n! Compute A=L*Q, copying result to VT\n! (Workspace: need 2*M, prefer M+M*NB)\n!\n CALL SGELQF(M,N,A,Lda,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n CALL SLACPY('U',M,N,A,Lda,Vt,Ldvt)\n!\n! Generate Q in VT\n! (Workspace: need M+N, prefer M+N*NB)\n!\n CALL SORGLQ(N,N,M,Vt,Ldvt,Work(itau),Work(iwork), &\n & Lwork-iwork+1,ierr)\n!\n! Copy L to U, zeroing out above it\n!\n CALL SLACPY('L',M,M,A,Lda,U,Ldu)\n CALL SLASET('U',M-1,M-1,ZERO,ZERO,U(1,2),Ldu)\n ie = itau\n itauq = ie + M\n itaup = itauq + M\n iwork = itaup + M\n!\n! Bidiagonalize L in U\n! (Workspace: need 4*M, prefer 3*M+2*M*NB)\n!\n CALL SGEBRD(M,M,U,Ldu,S,Work(ie),Work(itauq), &\n & Work(itaup),Work(iwork),Lwork-iwork+1, &\n & ierr)\n!\n! Multiply right bidiagonalizing vectors in U by Q\n! in VT\n! (Workspace: need 3*M+N, prefer 3*M+N*NB)\n!\n CALL SORMBR('P','L','T',M,N,M,U,Ldu,Work(itaup),Vt, &\n & Ldvt,Work(iwork),Lwork-iwork+1,ierr)\n!\n! Generate left bidiagonalizing vectors in U\n! (Workspace: need 4*M, prefer 3*M+M*NB)\n!\n CALL SORGBR('Q',M,M,M,U,Ldu,Work(itauq),Work(iwork), &\n & Lwork-iwork+1,ierr)\n iwork = ie + M\n!\n! Perform bidiagonal QR iteration, computing left\n! singular vectors of A in U and computing right\n! singular vectors of A in VT\n! (Workspace: need BDSPAC)\n!\n CALL SBDSQR('U',M,N,M,0,S,Work(ie),Vt,Ldvt,U,Ldu,dum, &\n & 1,Work(iwork),Info)\n!\n ENDIF\n!\n ENDIF\n!\n ENDIF\n!\n ELSE\n!\n! N .LT. MNTHR\n!\n! Path 10t(N greater than M, but not much larger)\n! Reduce to bidiagonal form without LQ decomposition\n!\n ie = 1\n itauq = ie + M\n itaup = itauq + M\n iwork = itaup + M\n!\n! Bidiagonalize A\n! (Workspace: need 3*M+N, prefer 3*M+(M+N)*NB)\n!\n CALL SGEBRD(M,N,A,Lda,S,Work(ie),Work(itauq),Work(itaup), &\n & Work(iwork),Lwork-iwork+1,ierr)\n IF ( wntuas ) THEN\n!\n! If left singular vectors desired in U, copy result to U\n! and generate left bidiagonalizing vectors in U\n! (Workspace: need 4*M-1, prefer 3*M+(M-1)*NB)\n!\n CALL SLACPY('L',M,M,A,Lda,U,Ldu)\n CALL SORGBR('Q',M,M,N,U,Ldu,Work(itauq),Work(iwork), &\n & Lwork-iwork+1,ierr)\n ENDIF\n IF ( wntvas ) THEN\n!\n! If right singular vectors desired in VT, copy result to\n! VT and generate right bidiagonalizing vectors in VT\n! (Workspace: need 3*M+NRVT, prefer 3*M+NRVT*NB)\n!\n CALL SLACPY('U',M,N,A,Lda,Vt,Ldvt)\n IF ( wntva ) nrvt = N\n IF ( wntvs ) nrvt = M\n CALL SORGBR('P',nrvt,N,M,Vt,Ldvt,Work(itaup),Work(iwork), &\n & Lwork-iwork+1,ierr)\n ENDIF\n!\n! If left singular vectors desired in A, generate left\n! bidiagonalizing vectors in A\n! (Workspace: need 4*M-1, prefer 3*M+(M-1)*NB)\n!\n IF ( wntuo ) CALL SORGBR('Q',M,M,N,A,Lda,Work(itauq), &\n & Work(iwork),Lwork-iwork+1,ierr)\n!\n! If right singular vectors desired in A, generate right\n! bidiagonalizing vectors in A\n! (Workspace: need 4*M, prefer 3*M+M*NB)\n!\n IF ( wntvo ) CALL SORGBR('P',M,N,M,A,Lda,Work(itaup), &\n & Work(iwork),Lwork-iwork+1,ierr)\n iwork = ie + M\n IF ( wntuas .OR. wntuo ) nru = M\n IF ( wntun ) nru = 0\n IF ( wntvas .OR. wntvo ) ncvt = N\n IF ( wntvn ) ncvt = 0\n IF ( (.NOT.wntuo) .AND. (.NOT.wntvo) ) THEN\n!\n! Perform bidiagonal QR iteration, if desired, computing\n! left singular vectors in U and computing right singular\n! vectors in VT\n! (Workspace: need BDSPAC)\n!\n CALL SBDSQR('L',M,ncvt,nru,0,S,Work(ie),Vt,Ldvt,U,Ldu,dum,1,&\n & Work(iwork),Info)\n ELSEIF ( (.NOT.wntuo) .AND. wntvo ) THEN\n!\n! Perform bidiagonal QR iteration, if desired, computing\n! left singular vectors in U and computing right singular\n! vectors in A\n! (Workspace: need BDSPAC)\n!\n CALL SBDSQR('L',M,ncvt,nru,0,S,Work(ie),A,Lda,U,Ldu,dum,1, &\n & Work(iwork),Info)\n ELSE\n!\n! Perform bidiagonal QR iteration, if desired, computing\n! left singular vectors in A and computing right singular\n! vectors in VT\n! (Workspace: need BDSPAC)\n!\n CALL SBDSQR('L',M,ncvt,nru,0,S,Work(ie),Vt,Ldvt,A,Lda,dum,1,&\n & Work(iwork),Info)\n ENDIF\n!\n!\n ENDIF\n!\n! If SBDSQR failed to converge, copy unconverged superdiagonals\n! to WORK( 2:MINMN )\n!\n IF ( Info/=0 ) THEN\n IF ( ie>2 ) THEN\n DO i = 1 , minmn - 1\n Work(i+1) = Work(i+ie-1)\n ENDDO\n ENDIF\n IF ( ie<2 ) THEN\n DO i = minmn - 1 , 1 , -1\n Work(i+1) = Work(i+ie-1)\n ENDDO\n ENDIF\n ENDIF\n!\n! Undo scaling if necessary\n!\n IF ( iscl==1 ) THEN\n IF ( anrm>bignum ) CALL SLASCL('G',0,0,bignum,anrm,minmn,1,S, &\n & minmn,ierr)\n IF ( Info/=0 .AND. anrm>bignum ) &\n & CALL SLASCL('G',0,0,bignum,anrm,minmn-1,1,Work(2),minmn, &\n & ierr)\n IF ( anrm= 0.\r\n*\r\n* A (input/output) DOUBLE PRECISION array, dimension (LDA,N)\r\n* On entry, the input matrix A.\r\n* On exit, A is overwritten by the balanced matrix.\r\n* If JOB = 'N', A is not referenced.\r\n*\r\n* LDA (input) INTEGER\r\n* The leading dimension of the array A. LDA >= max(1,N).\r\n*\r\n* B (input/output) DOUBLE PRECISION array, dimension (LDB,N)\r\n* On entry, the input matrix B.\r\n* On exit, B is overwritten by the balanced matrix.\r\n* If JOB = 'N', B is not referenced.\r\n*\r\n* LDB (input) INTEGER\r\n* The leading dimension of the array B. LDB >= max(1,N).\r\n*\r\n* ILO (output) INTEGER\r\n* IHI (output) INTEGER\r\n* ILO and IHI are set to integers such that on exit\r\n* A(i,j) = 0 and B(i,j) = 0 if i > j and\r\n* j = 1,...,ILO-1 or i = IHI+1,...,N.\r\n* If JOB = 'N' or 'S', ILO = 1 and IHI = N.\r\n*\r\n* LSCALE (output) DOUBLE PRECISION array, dimension (N)\r\n* Details of the permutations and scaling factors applied\r\n* to the left side of A and B. If P(j) is the index of the\r\n* row interchanged with row j, and D(j)\r\n* is the scaling factor applied to row j, then\r\n* LSCALE(j) = P(j) for J = 1,...,ILO-1\r\n* = D(j) for J = ILO,...,IHI\r\n* = P(j) for J = IHI+1,...,N.\r\n* The order in which the interchanges are made is N to IHI+1,\r\n* then 1 to ILO-1.\r\n*\r\n* RSCALE (output) DOUBLE PRECISION array, dimension (N)\r\n* Details of the permutations and scaling factors applied\r\n* to the right side of A and B. If P(j) is the index of the\r\n* column interchanged with column j, and D(j)\r\n* is the scaling factor applied to column j, then\r\n* LSCALE(j) = P(j) for J = 1,...,ILO-1\r\n* = D(j) for J = ILO,...,IHI\r\n* = P(j) for J = IHI+1,...,N.\r\n* The order in which the interchanges are made is N to IHI+1,\r\n* then 1 to ILO-1.\r\n*\r\n* WORK (workspace) DOUBLE PRECISION array, dimension (6*N)\r\n*\r\n* INFO (output) INTEGER\r\n* = 0: successful exit\r\n* < 0: if INFO = -i, the i-th argument had an illegal value.\r\n*\r\n* Further Details\r\n* ===============\r\n*\r\n* See R.C. WARD, Balancing the generalized eigenvalue problem,\r\n* SIAM J. Sci. Stat. Comp. 2 (1981), 141-152.\r\n*\r\n* =====================================================================\r\n*\r\n* .. Parameters ..\r\n DOUBLE PRECISION ZERO, HALF, ONE\r\n PARAMETER ( ZERO = 0.0D+0, HALF = 0.5D+0, ONE = 1.0D+0 )\r\n DOUBLE PRECISION THREE, SCLFAC\r\n PARAMETER ( THREE = 3.0D+0, SCLFAC = 1.0D+1 )\r\n* ..\r\n* .. Local Scalars ..\r\n INTEGER I, ICAB, IFLOW, IP1, IR, IRAB, IT, J, JC, JP1,\r\n $ K, KOUNT, L, LCAB, LM1, LRAB, LSFMAX, LSFMIN,\r\n $ M, NR, NRP2\r\n DOUBLE PRECISION ALPHA, BASL, BETA, CAB, CMAX, COEF, COEF2,\r\n $ COEF5, COR, EW, EWC, GAMMA, PGAMMA, RAB, SFMAX,\r\n $ SFMIN, SUM, T, TA, TB, TC\r\n* ..\r\n* .. External Functions ..\r\n LOGICAL LSAME\r\n INTEGER IDAMAX\r\n DOUBLE PRECISION DDOT, DLAMCH\r\n EXTERNAL LSAME, IDAMAX, DDOT, DLAMCH\r\n* ..\r\n* .. External Subroutines ..\r\n EXTERNAL DAXPY, DSCAL, DSWAP, XERBLA\r\n* ..\r\n* .. Intrinsic Functions ..\r\n INTRINSIC ABS, DBLE, INT, LOG10, MAX, MIN, SIGN\r\n* ..\r\n* .. Executable Statements ..\r\n*\r\n* Test the input parameters\r\n*\r\n INFO = 0\r\n IF( .NOT.LSAME( JOB, 'N' ) .AND. .NOT.LSAME( JOB, 'P' ) .AND.\r\n $ .NOT.LSAME( JOB, 'S' ) .AND. .NOT.LSAME( JOB, 'B' ) ) THEN\r\n INFO = -1\r\n ELSE IF( N.LT.0 ) THEN\r\n INFO = -2\r\n ELSE IF( LDA.LT.MAX( 1, N ) ) THEN\r\n INFO = -4\r\n ELSE IF( LDB.LT.MAX( 1, N ) ) THEN\r\n INFO = -5\r\n END IF\r\n IF( INFO.NE.0 ) THEN\r\n CALL XERBLA( 'DGGBAL', -INFO )\r\n RETURN\r\n END IF\r\n*\r\n K = 1\r\n L = N\r\n*\r\n* Quick return if possible\r\n*\r\n IF( N.EQ.0 )\r\n $ RETURN\r\n*\r\n IF( LSAME( JOB, 'N' ) ) THEN\r\n ILO = 1\r\n IHI = N\r\n DO 10 I = 1, N\r\n LSCALE( I ) = ONE\r\n RSCALE( I ) = ONE\r\n 10 CONTINUE\r\n RETURN\r\n END IF\r\n*\r\n IF( K.EQ.L ) THEN\r\n ILO = 1\r\n IHI = 1\r\n LSCALE( 1 ) = ONE\r\n RSCALE( 1 ) = ONE\r\n RETURN\r\n END IF\r\n*\r\n IF( LSAME( JOB, 'S' ) )\r\n $ GO TO 190\r\n*\r\n GO TO 30\r\n*\r\n* Permute the matrices A and B to isolate the eigenvalues.\r\n*\r\n* Find row with one nonzero in columns 1 through L\r\n*\r\n 20 CONTINUE\r\n L = LM1\r\n IF( L.NE.1 )\r\n $ GO TO 30\r\n*\r\n RSCALE( 1 ) = 1\r\n LSCALE( 1 ) = 1\r\n GO TO 190\r\n*\r\n 30 CONTINUE\r\n LM1 = L - 1\r\n DO 80 I = L, 1, -1\r\n DO 40 J = 1, LM1\r\n JP1 = J + 1\r\n IF( A( I, J ).NE.ZERO .OR. B( I, J ).NE.ZERO )\r\n $ GO TO 50\r\n 40 CONTINUE\r\n J = L\r\n GO TO 70\r\n*\r\n 50 CONTINUE\r\n DO 60 J = JP1, L\r\n IF( A( I, J ).NE.ZERO .OR. B( I, J ).NE.ZERO )\r\n $ GO TO 80\r\n 60 CONTINUE\r\n J = JP1 - 1\r\n*\r\n 70 CONTINUE\r\n M = L\r\n IFLOW = 1\r\n GO TO 160\r\n 80 CONTINUE\r\n GO TO 100\r\n*\r\n* Find column with one nonzero in rows K through N\r\n*\r\n 90 CONTINUE\r\n K = K + 1\r\n*\r\n 100 CONTINUE\r\n DO 150 J = K, L\r\n DO 110 I = K, LM1\r\n IP1 = I + 1\r\n IF( A( I, J ).NE.ZERO .OR. B( I, J ).NE.ZERO )\r\n $ GO TO 120\r\n 110 CONTINUE\r\n I = L\r\n GO TO 140\r\n 120 CONTINUE\r\n DO 130 I = IP1, L\r\n IF( A( I, J ).NE.ZERO .OR. B( I, J ).NE.ZERO )\r\n $ GO TO 150\r\n 130 CONTINUE\r\n I = IP1 - 1\r\n 140 CONTINUE\r\n M = K\r\n IFLOW = 2\r\n GO TO 160\r\n 150 CONTINUE\r\n GO TO 190\r\n*\r\n* Permute rows M and I\r\n*\r\n 160 CONTINUE\r\n LSCALE( M ) = I\r\n IF( I.EQ.M )\r\n $ GO TO 170\r\n CALL DSWAP( N-K+1, A( I, K ), LDA, A( M, K ), LDA )\r\n CALL DSWAP( N-K+1, B( I, K ), LDB, B( M, K ), LDB )\r\n*\r\n* Permute columns M and J\r\n*\r\n 170 CONTINUE\r\n RSCALE( M ) = J\r\n IF( J.EQ.M )\r\n $ GO TO 180\r\n CALL DSWAP( L, A( 1, J ), 1, A( 1, M ), 1 )\r\n CALL DSWAP( L, B( 1, J ), 1, B( 1, M ), 1 )\r\n*\r\n 180 CONTINUE\r\n GO TO ( 20, 90 )IFLOW\r\n*\r\n 190 CONTINUE\r\n ILO = K\r\n IHI = L\r\n*\r\n IF( ILO.EQ.IHI )\r\n $ RETURN\r\n*\r\n IF( LSAME( JOB, 'P' ) )\r\n $ RETURN\r\n*\r\n* Balance the submatrix in rows ILO to IHI.\r\n*\r\n NR = IHI - ILO + 1\r\n DO 200 I = ILO, IHI\r\n RSCALE( I ) = ZERO\r\n LSCALE( I ) = ZERO\r\n*\r\n WORK( I ) = ZERO\r\n WORK( I+N ) = ZERO\r\n WORK( I+2*N ) = ZERO\r\n WORK( I+3*N ) = ZERO\r\n WORK( I+4*N ) = ZERO\r\n WORK( I+5*N ) = ZERO\r\n 200 CONTINUE\r\n*\r\n* Compute right side vector in resulting linear equations\r\n*\r\n BASL = LOG10( SCLFAC )\r\n DO 240 I = ILO, IHI\r\n DO 230 J = ILO, IHI\r\n TB = B( I, J )\r\n TA = A( I, J )\r\n IF( TA.EQ.ZERO )\r\n $ GO TO 210\r\n TA = LOG10( ABS( TA ) ) / BASL\r\n 210 CONTINUE\r\n IF( TB.EQ.ZERO )\r\n $ GO TO 220\r\n TB = LOG10( ABS( TB ) ) / BASL\r\n 220 CONTINUE\r\n WORK( I+4*N ) = WORK( I+4*N ) - TA - TB\r\n WORK( J+5*N ) = WORK( J+5*N ) - TA - TB\r\n 230 CONTINUE\r\n 240 CONTINUE\r\n*\r\n COEF = ONE / DBLE( 2*NR )\r\n COEF2 = COEF*COEF\r\n COEF5 = HALF*COEF2\r\n NRP2 = NR + 2\r\n BETA = ZERO\r\n IT = 1\r\n*\r\n* Start generalized conjugate gradient iteration\r\n*\r\n 250 CONTINUE\r\n*\r\n GAMMA = DDOT( NR, WORK( ILO+4*N ), 1, WORK( ILO+4*N ), 1 ) +\r\n $ DDOT( NR, WORK( ILO+5*N ), 1, WORK( ILO+5*N ), 1 )\r\n*\r\n EW = ZERO\r\n EWC = ZERO\r\n DO 260 I = ILO, IHI\r\n EW = EW + WORK( I+4*N )\r\n EWC = EWC + WORK( I+5*N )\r\n 260 CONTINUE\r\n*\r\n GAMMA = COEF*GAMMA - COEF2*( EW**2+EWC**2 ) - COEF5*( EW-EWC )**2\r\n IF( GAMMA.EQ.ZERO )\r\n $ GO TO 350\r\n IF( IT.NE.1 )\r\n $ BETA = GAMMA / PGAMMA\r\n T = COEF5*( EWC-THREE*EW )\r\n TC = COEF5*( EW-THREE*EWC )\r\n*\r\n CALL DSCAL( NR, BETA, WORK( ILO ), 1 )\r\n CALL DSCAL( NR, BETA, WORK( ILO+N ), 1 )\r\n*\r\n CALL DAXPY( NR, COEF, WORK( ILO+4*N ), 1, WORK( ILO+N ), 1 )\r\n CALL DAXPY( NR, COEF, WORK( ILO+5*N ), 1, WORK( ILO ), 1 )\r\n*\r\n DO 270 I = ILO, IHI\r\n WORK( I ) = WORK( I ) + TC\r\n WORK( I+N ) = WORK( I+N ) + T\r\n 270 CONTINUE\r\n*\r\n* Apply matrix to vector\r\n*\r\n DO 300 I = ILO, IHI\r\n KOUNT = 0\r\n SUM = ZERO\r\n DO 290 J = ILO, IHI\r\n IF( A( I, J ).EQ.ZERO )\r\n $ GO TO 280\r\n KOUNT = KOUNT + 1\r\n SUM = SUM + WORK( J )\r\n 280 CONTINUE\r\n IF( B( I, J ).EQ.ZERO )\r\n $ GO TO 290\r\n KOUNT = KOUNT + 1\r\n SUM = SUM + WORK( J )\r\n 290 CONTINUE\r\n WORK( I+2*N ) = DBLE( KOUNT )*WORK( I+N ) + SUM\r\n 300 CONTINUE\r\n*\r\n DO 330 J = ILO, IHI\r\n KOUNT = 0\r\n SUM = ZERO\r\n DO 320 I = ILO, IHI\r\n IF( A( I, J ).EQ.ZERO )\r\n $ GO TO 310\r\n KOUNT = KOUNT + 1\r\n SUM = SUM + WORK( I+N )\r\n 310 CONTINUE\r\n IF( B( I, J ).EQ.ZERO )\r\n $ GO TO 320\r\n KOUNT = KOUNT + 1\r\n SUM = SUM + WORK( I+N )\r\n 320 CONTINUE\r\n WORK( J+3*N ) = DBLE( KOUNT )*WORK( J ) + SUM\r\n 330 CONTINUE\r\n*\r\n SUM = DDOT( NR, WORK( ILO+N ), 1, WORK( ILO+2*N ), 1 ) +\r\n $ DDOT( NR, WORK( ILO ), 1, WORK( ILO+3*N ), 1 )\r\n ALPHA = GAMMA / SUM\r\n*\r\n* Determine correction to current iteration\r\n*\r\n CMAX = ZERO\r\n DO 340 I = ILO, IHI\r\n COR = ALPHA*WORK( I+N )\r\n IF( ABS( COR ).GT.CMAX )\r\n $ CMAX = ABS( COR )\r\n LSCALE( I ) = LSCALE( I ) + COR\r\n COR = ALPHA*WORK( I )\r\n IF( ABS( COR ).GT.CMAX )\r\n $ CMAX = ABS( COR )\r\n RSCALE( I ) = RSCALE( I ) + COR\r\n 340 CONTINUE\r\n IF( CMAX.LT.HALF )\r\n $ GO TO 350\r\n*\r\n CALL DAXPY( NR, -ALPHA, WORK( ILO+2*N ), 1, WORK( ILO+4*N ), 1 )\r\n CALL DAXPY( NR, -ALPHA, WORK( ILO+3*N ), 1, WORK( ILO+5*N ), 1 )\r\n*\r\n PGAMMA = GAMMA\r\n IT = IT + 1\r\n IF( IT.LE.NRP2 )\r\n $ GO TO 250\r\n*\r\n* End generalized conjugate gradient iteration\r\n*\r\n 350 CONTINUE\r\n SFMIN = DLAMCH( 'S' )\r\n SFMAX = ONE / SFMIN\r\n LSFMIN = INT( LOG10( SFMIN ) / BASL+ONE )\r\n LSFMAX = INT( LOG10( SFMAX ) / BASL )\r\n DO 360 I = ILO, IHI\r\n IRAB = IDAMAX( N-ILO+1, A( I, ILO ), LDA )\r\n RAB = ABS( A( I, IRAB+ILO-1 ) )\r\n IRAB = IDAMAX( N-ILO+1, B( I, ILO ), LDA )\r\n RAB = MAX( RAB, ABS( B( I, IRAB+ILO-1 ) ) )\r\n LRAB = INT( LOG10( RAB+SFMIN ) / BASL+ONE )\r\n IR = LSCALE( I ) + SIGN( HALF, LSCALE( I ) )\r\n IR = MIN( MAX( IR, LSFMIN ), LSFMAX, LSFMAX-LRAB )\r\n LSCALE( I ) = SCLFAC**IR\r\n ICAB = IDAMAX( IHI, A( 1, I ), 1 )\r\n CAB = ABS( A( ICAB, I ) )\r\n ICAB = IDAMAX( IHI, B( 1, I ), 1 )\r\n CAB = MAX( CAB, ABS( B( ICAB, I ) ) )\r\n LCAB = INT( LOG10( CAB+SFMIN ) / BASL+ONE )\r\n JC = RSCALE( I ) + SIGN( HALF, RSCALE( I ) )\r\n JC = MIN( MAX( JC, LSFMIN ), LSFMAX, LSFMAX-LCAB )\r\n RSCALE( I ) = SCLFAC**JC\r\n 360 CONTINUE\r\n*\r\n* Row scaling of matrices A and B\r\n*\r\n DO 370 I = ILO, IHI\r\n CALL DSCAL( N-ILO+1, LSCALE( I ), A( I, ILO ), LDA )\r\n CALL DSCAL( N-ILO+1, LSCALE( I ), B( I, ILO ), LDB )\r\n 370 CONTINUE\r\n*\r\n* Column scaling of matrices A and B\r\n*\r\n DO 380 J = ILO, IHI\r\n CALL DSCAL( IHI, RSCALE( J ), A( 1, J ), 1 )\r\n CALL DSCAL( IHI, RSCALE( J ), B( 1, J ), 1 )\r\n 380 CONTINUE\r\n*\r\n RETURN\r\n*\r\n* End of DGGBAL\r\n*\r\n END\r\n", "meta": {"hexsha": "e83f1b45fa4b666b84cb22b725bacedf8ac49599", "size": 13844, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Modules/ThirdParty/VNL/src/vxl/v3p/netlib/lapack/double/dggbal.f", "max_stars_repo_name": "nalinimsingh/ITK_4D", "max_stars_repo_head_hexsha": "95a2eacaeaffe572889832ef0894239f89e3f303", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-10-01T20:46:17.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-17T19:39:50.000Z", "max_issues_repo_path": "Modules/ThirdParty/VNL/src/vxl/v3p/netlib/lapack/double/dggbal.f", "max_issues_repo_name": "nalinimsingh/ITK_4D", "max_issues_repo_head_hexsha": "95a2eacaeaffe572889832ef0894239f89e3f303", "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/lapack/double/dggbal.f", "max_forks_repo_name": "nalinimsingh/ITK_4D", "max_forks_repo_head_hexsha": "95a2eacaeaffe572889832ef0894239f89e3f303", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-05-17T16:34:54.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-24T02:12:40.000Z", "avg_line_length": 29.9653679654, "max_line_length": 73, "alphanum_fraction": 0.4560098238, "num_tokens": 4758, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297914570319, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6975354180941205}} {"text": " PROGRAM mean_entropy\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,Kad,Kab\n REAL (KIND=8):: Ra_dev,Rb_dev,Rd_dev\n REAL (KIND=8),DIMENSION(n):: Ra,Rb,Rd\n\n!!!=======================================================================================\n!!!======================================================================================= \n OPEN(unit=11,file='entropy.dat')\n OPEN(unit=12,file='entropy_av.dat')\n OPEN(unit=13,file='S_av.dat')\n\n!!! Tinh gia tri trung binh\n Ra_av=0. ; Rb_av=0. ; Rd_av=0.\n\n DO i=1,n\n READ(11,*)Kad,Kab,Ra(i),Rb(i),Rd(i)\n Ra_av=Ra_av+Ra(i)\n Rb_av=Rb_av+Rb(i)\n Rd_av=Rd_av+Rd(i)\n END DO\n \n Ra_av=Ra_av/n ; Rb_av=Rb_av/n ; Rd_av=Rd_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 WRITE(12,*)Kad,Kab,Ra_av,Rb_av,Rd_av\n WRITE(13,*)Ra_av,Ra_dev,Rb_av,Rb_dev,Rd_av,Rd_dev\n\n CLOSE(11)\n CLOSE(12)\n CLOSE(13)\n \n END PROGRAM mean_entropy\n\n", "meta": {"hexsha": "3c2cacbc5ecd9228e576cafc26deab6f103fc3ed", "size": 1282, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "071OCT15_ISLET_SYNC_Human_30Remove/Ref/0.0Kab/4mean_S.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/4mean_S.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/4mean_S.f90", "max_forks_repo_name": "danhtaihoang/islet-sync", "max_forks_repo_head_hexsha": "734d717ccaf979640425b1e03032f292952075c4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.4912280702, "max_line_length": 91, "alphanum_fraction": 0.5132605304, "num_tokens": 459, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297807787537, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.6975354145089034}} {"text": " Program dgtsvx_example\n\n! DGTSVX Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_example_aux, Only: nagf_file_print_matrix_real_gen\n Use lapack_interfaces, Only: dgtsvx\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nin = 5, nout = 6\n! .. Local Scalars ..\n Real (Kind=dp) :: rcond\n Integer :: i, ifail, info, ldb, ldx, n, nrhs\n! .. Local Arrays ..\n Real (Kind=dp), Allocatable :: b(:, :), berr(:), d(:), df(:), dl(:), &\n dlf(:), du(:), du2(:), duf(:), ferr(:), work(:), x(:, :)\n Integer, Allocatable :: ipiv(:), iwork(:)\n! .. Executable Statements ..\n Write (nout, *) 'DGTSVX Example Program Results'\n Write (nout, *)\n Flush (nout)\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n, nrhs\n ldb = n\n ldx = n\n Allocate (b(ldb,nrhs), berr(nrhs), d(n), df(n), dl(n-1), dlf(n-1), &\n du(n-1), du2(n-2), duf(n-1), ferr(nrhs), work(3*n), x(ldx,nrhs), &\n ipiv(n), iwork(n))\n\n! Read the tridiagonal matrix A from data file\n\n Read (nin, *) du(1:n-1)\n Read (nin, *) d(1:n)\n Read (nin, *) dl(1:n-1)\n\n! Read the right hand matrix B\n\n Read (nin, *)(b(i,1:nrhs), i=1, n)\n\n! Solve the equations AX = B\n\n Call dgtsvx('No factors', 'No transpose', n, nrhs, dl, d, du, dlf, df, &\n duf, du2, ipiv, b, ldb, x, ldx, rcond, ferr, berr, work, iwork, info)\n\n If ((info==0) .Or. (info==n+1)) Then\n\n! Print solution, error bounds and condition number\n\n! ifail: behaviour on error exit\n! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft\n ifail = 0\n Call nagf_file_print_matrix_real_gen('General', ' ', n, nrhs, x, ldx, &\n 'Solution(s)', ifail)\n\n Write (nout, *)\n Write (nout, *) 'Backward errors (machine-dependent)'\n Write (nout, 100) berr(1:nrhs)\n Write (nout, *)\n Write (nout, *) 'Estimated forward error bounds (machine-dependent)'\n Write (nout, 100) ferr(1:nrhs)\n Write (nout, *)\n Write (nout, *) 'Estimate of reciprocal condition number'\n Write (nout, 100) rcond\n\n If (info==n+1) Then\n Write (nout, *)\n Write (nout, *) 'The matrix A is singular to working precision'\n End If\n Else\n Write (nout, 110) 'The (', info, ',', info, ')', &\n ' element of the factor U is zero'\n End If\n\n100 Format ((3X,1P,7E11.1))\n110 Format (1X, A, I3, A, I3, A, A)\n End Program\n", "meta": {"hexsha": "c99f639aa4f009ffcc646c0946fb27725be3aa42", "size": 2776, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/dgtsvx_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/dgtsvx_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/dgtsvx_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 33.0476190476, "max_line_length": 90, "alphanum_fraction": 0.5511527378, "num_tokens": 883, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297941266013, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.6975354107899243}} {"text": "module poisson_mod\r\n\r\n use precision_mod, only: wp\r\n use source_mod, only: source_term\r\n\r\n implicit none\r\n private\r\n\r\n public :: wp, source_term \r\n public :: Lattice, init_Lattice\r\n\r\n ! D1Q3 Model Parameters\r\n integer, parameter :: e(3) = [0,1,-1]\r\n real(wp), parameter :: w(3) = [2._wp/3._wp,1._wp/6._wp,1._wp/6._wp]\r\n real(wp), parameter :: wbar(3) = [0._wp,0.5_wp,0.5_wp]\r\n real(wp), parameter :: alpha = 1._wp/3._wp ! Speed of sound squared $c_\\mathrm{s}^2$\r\n\r\n real(wp), parameter :: coef = 1._wp/(1._wp - w(1)) ! coefficient in macroscopic value sum, see Eq. (2.5)\r\n\r\n\r\n!> Derived type to encapsulate the lattice Boltzmann algorithm\r\n! \r\n type :: Lattice\r\n real(wp) :: interval(2)\r\n integer :: nx\r\n real(wp) :: dx, dt, diff, omega\r\n real(wp), allocatable :: f(:,:,:)\r\n integer :: old, new\r\n class(source_term), pointer :: src\r\n contains\r\n procedure :: collide_and_stream\r\n procedure :: get_macroscopic_values\r\n procedure :: prep_next_step\r\n procedure :: output\r\n \r\n ! Non-equilibrium extrapolation\r\n procedure :: set_left_neem\r\n procedure :: set_right_neem\r\n\r\n ! Non-equilibrium bounceback\r\n ! procedure :: set_left_neeb\r\n ! procedure :: set_right_neeb\r\n\r\n ! Inamuro's boundary condition\r\n procedure :: set_left_inamuro\r\n procedure :: set_right_inamuro\r\n end type\r\n\r\n\r\ncontains\r\n\r\n function init_Lattice(ab,nx,uinit,omega,src) result(this)\r\n real(wp), intent(in), optional :: ab(2)\r\n integer, intent(in) :: nx\r\n real(wp), intent(in) :: uinit(nx)\r\n real(wp), intent(in) :: omega\r\n class(source_term), intent(in), pointer :: src\r\n\r\n type(Lattice) :: this\r\n\r\n real(wp) :: ab_(2), dx, tau\r\n integer :: i\r\n\r\n ! Set interval\r\n ab_ = [0.0_wp,1.0_wp] ! default interval\r\n if (present(ab)) ab_ = ab\r\n this%interval = ab_\r\n\r\n ! Set number of lattice sites\r\n this%nx = nx\r\n\r\n ! Set spatial and time step\r\n this%dx = (ab_(2) - ab_(1))/real(nx-1,wp)\r\n this%dt = this%dx\r\n\r\n ! Set relaxation time and diffusivity\r\n this%omega = omega\r\n tau = 1.0_wp/omega\r\n this%diff = alpha*(0.5_wp - tau)*this%dt ! Not the same as in standard LBM!\r\n\r\n ! Set flags\r\n this%old = 1\r\n this%new = 2\r\n\r\n ! Allocate space\r\n allocate(this%f(0:nx+1,3,2))\r\n \r\n ! Initialize to equilibrium values\r\n do i = 1, nx\r\n this%f(i,1,this%old) = (w(1) - 1._wp)*uinit(i)\r\n this%f(i,2,this%old) = w(2)*uinit(i)\r\n this%f(i,3,this%old) = w(3)*uinit(i)\r\n end do\r\n\r\n ! Associate source term functor\r\n this%src => src\r\n\r\n end function\r\n\r\n\r\n subroutine collide_and_stream(this,uout)\r\n class(Lattice), intent(inout) :: this\r\n real(wp), intent(out), optional ::uout(this%nx)\r\n real(wp) :: one_minus_omega, feq(3), u, source, x\r\n integer :: i\r\n\r\n associate(f => this%f, nx => this%nx, new => this%new, old => this%old, & \r\n dt => this%dt, omega => this%omega, D => this%diff)\r\n\r\n one_minus_omega = 1._wp - omega\r\n\r\n spatial_loop: do i = 1, this%nx\r\n ! Macroscopic value, Eq. (2.5)\r\n u = coef*(f(i,2,old) + f(i,3,old))\r\n if (present(uout)) uout(i) = u\r\n\r\n ! Equilibirum distribution\r\n feq(1) = (w(1) - 1._wp)*u\r\n feq(2) = w(2)*u\r\n feq(3) = w(3)*u\r\n\r\n ! Evaluate source term\r\n x = this%interval(1) + (i-1)*this%dx\r\n source = this%src%eval(u,x)\r\n\r\n ! Collide and stream\r\n f(i,1,new) = one_minus_omega*f(i,1,old) + omega*feq(1) ! wbar(1) = 0\r\n f(i+1,2,new) = one_minus_omega*f(i,2,old) + omega*feq(2) + dt*wbar(2)*D*source\r\n f(i-1,3,new) = one_minus_omega*f(i,3,old) + omega*feq(3) + dt*wbar(3)*D*source\r\n end do spatial_loop\r\n\r\n ! Perform bounceback by default\r\n f(1,2,new) = f(0,3,new)\r\n f(nx,3,new) = f(nx+1,2,new)\r\n\r\n end associate\r\n\r\n end subroutine\r\n\r\n!> Sets a left Dirichlet boundary condition using the\r\n! non-equilibrium extrapolation method.\r\n!\r\n subroutine set_left_neem(this,value)\r\n class(Lattice), intent(inout) :: this\r\n real(wp), intent(in) :: value\r\n real(wp) :: u\r\n u = coef*sum(this%f(2,2:3,this%old))\r\n this%f(1,1,this%new) = (w(1) - 1._wp)*value + (this%f(2,1,this%new) - (w(1) - 1._wp)*u)\r\n this%f(1,2,this%new) = w(2)*value + (this%f(2,2,this%new) - w(2)*u)\r\n this%f(1,3,this%new) = w(3)*value + (this%f(2,3,this%new) - w(3)*u)\r\n end subroutine\r\n\r\n!> Sets a right Dirichlet boundary condition using the\r\n! non-equilibrium extrapolation method.\r\n!\r\n subroutine set_right_neem(this,value)\r\n class(Lattice), intent(inout) :: this\r\n real(wp), intent(in) :: value\r\n real(wp) :: u\r\n u = coef*sum(this%f(this%nx-1,2:3,this%old))\r\n this%f(this%nx,1,this%new) = (w(1) - 1._wp)*value + (this%f(this%nx-1,3,this%new) - (w(1) - 1._wp)*u)\r\n this%f(this%nx,2,this%new) = w(2)*value + (this%f(this%nx-1,2,this%new) - w(2)*u)\r\n this%f(this%nx,3,this%new) = w(3)*value + (this%f(this%nx-1,3,this%new) - w(3)*u)\r\n end subroutine\r\n\r\n\r\n subroutine set_left_inamuro(this,value)\r\n class(Lattice), intent(inout) :: this\r\n real(wp), intent(in) :: value\r\n this%f(1,2,this%new) = value*(1.0_wp-w(1)) - this%f(1,3,this%new)\r\n end subroutine\r\n\r\n subroutine set_right_inamuro(this,value)\r\n class(Lattice), intent(inout) :: this\r\n real(wp), intent(in) :: value\r\n this%f(this%nx,3,this%new) = value*(1.0_wp-w(1)) - this%f(this%nx,2,this%new)\r\n end subroutine\r\n\r\n!> Swaps flags between old and new arrays.\r\n!\r\n! This routine must be called at the end of the time loop!\r\n!\r\n subroutine prep_next_step(this)\r\n class(Lattice), intent(inout) :: this\r\n integer :: temp\r\n temp = this%old\r\n this%old = this%new\r\n this%new = temp\r\n end subroutine\r\n\r\n\r\n!> Calculates the physical quantity $u$ (macroscopic value) \r\n! according to Eq. (2.5) in the paper by Chai and Shi (2008).\r\n!\r\n subroutine get_macroscopic_values(this,u)\r\n class(Lattice), intent(in) :: this\r\n real(wp), intent(out) :: u(this%nx)\r\n u(:) = coef*sum(this%f(1:this%nx,2:3,this%old),dim=2)\r\n end subroutine\r\n\r\n\r\n subroutine output(this,fname)\r\n class(Lattice), intent(in) :: this\r\n character(len=*), intent(in) :: fname\r\n\r\n integer :: iunit, i\r\n real(wp) :: x(this%nx), u(this%nx)\r\n\r\n call this%get_macroscopic_values(u)\r\n\r\n x = [(this%interval(1) + (i-1)*this%dx,i=1,this%nx)]\r\n\r\n open(newunit=iunit,file=fname)\r\n\r\n do i = 1, this%nx\r\n write(iunit,*) x(i), u(i)\r\n end do\r\n\r\n close(iunit)\r\n end subroutine\r\n\r\nend module\r\n\r\n", "meta": {"hexsha": "b565bf5976a9ac768d6937e9d9c02fbfc3b423fa", "size": 7059, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/poisson_mod.f90", "max_stars_repo_name": "myousefi2016/poisson_lbm", "max_stars_repo_head_hexsha": "de1e09893c5b257cc0bfe17912c4f1fe1f3d821b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-12-23T19:11:55.000Z", "max_stars_repo_stars_event_max_datetime": "2018-12-23T19:11:55.000Z", "max_issues_repo_path": "src/poisson_mod.f90", "max_issues_repo_name": "myousefi2016/poisson_lbm", "max_issues_repo_head_hexsha": "de1e09893c5b257cc0bfe17912c4f1fe1f3d821b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/poisson_mod.f90", "max_forks_repo_name": "myousefi2016/poisson_lbm", "max_forks_repo_head_hexsha": "de1e09893c5b257cc0bfe17912c4f1fe1f3d821b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.5133928571, "max_line_length": 110, "alphanum_fraction": 0.5445530528, "num_tokens": 2137, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297807787537, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6975354098229035}} {"text": "program P1010\n implicit none\n integer :: cases, i\n integer :: west, east, j, k\n integer, dimension(30, 30) :: count\n do i = 1, 30\n count(1, i) = i\n end do\n read *, cases\n do i = 1, cases\n read *, west, east\n do j = 2, west\n count(j, j - 1) = 0\n do k = j, east\n count(j, k) = count(j - 1, k - 1) + count(j, k - 1)\n end do\n end do\n write (*, '(I0)') count(west, east)\n end do\nend program P1010", "meta": {"hexsha": "4063a532dd1bd3f5385b546468efcbe8616a0b7d", "size": 501, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "P1010.f95", "max_stars_repo_name": "daily-boj/kiwiyou", "max_stars_repo_head_hexsha": "ceca96ddfee95708871af67d1682048e0bed0257", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-04-08T09:04:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-16T07:30:24.000Z", "max_issues_repo_path": "P1010.f95", "max_issues_repo_name": "daily-boj/kiwiyou", "max_issues_repo_head_hexsha": "ceca96ddfee95708871af67d1682048e0bed0257", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "P1010.f95", "max_forks_repo_name": "daily-boj/kiwiyou", "max_forks_repo_head_hexsha": "ceca96ddfee95708871af67d1682048e0bed0257", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-04-16T05:32:06.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-28T13:40:56.000Z", "avg_line_length": 25.05, "max_line_length": 67, "alphanum_fraction": 0.4530938124, "num_tokens": 174, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.900529778109184, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6975354077550991}} {"text": "!** Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.\n!** See https://llvm.org/LICENSE.txt for license information.\n!** SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception\n\nprogram mmul\n integer, parameter :: n = 4\n real(kind = 8), dimension(1:n, 1:n) :: a, b, c\n real(kind = 8), dimension(n * n) :: expected\n data expected / -256.0, -256.0, -256.0, -256.0, &\n -256.0, -256.0, -256.0, -256.0, &\n -256.0, -256.0, -256.0, -256.0, &\n -256.0, -256.0, -256.0, -256.0 /\n\n a = 1.0\n b = -1.0\n c = 2.0\n call do_matmul(a, b, c, n)\n call checkd(reshape(c, (/ n * n /)), expected, n * n)\n\ncontains\n\n subroutine do_matmul(a, b, c, n)\n integer, intent(in) :: n\n real(kind = 8), dimension(:, :), intent(in) :: a, b\n real(kind = 8), dimension(:, :), intent(inout) :: c\n\n c(1:n, 1:n) = matmul(matmul(matmul(a(1:n, 1:n), b(1:n, 1:n)), matmul(a(1:n, 1:n), b(1:n, 1:n))), b(1:n, 1:n))\n end subroutine\n\nend program mmul\n", "meta": {"hexsha": "f3527288325f725bfa88f750f708db240d8f3002", "size": 1005, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/f90_correct/src/mmul_misc3.f90", "max_stars_repo_name": "abrahamtovarmob/flang", "max_stars_repo_head_hexsha": "bcd84b29df046b6d6574f0bfa34ea5059092615a", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 716, "max_stars_repo_stars_event_min_datetime": "2017-05-17T17:58:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T11:20:58.000Z", "max_issues_repo_path": "test/f90_correct/src/mmul_misc3.f90", "max_issues_repo_name": "abrahamtovarmob/flang", "max_issues_repo_head_hexsha": "bcd84b29df046b6d6574f0bfa34ea5059092615a", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 794, "max_issues_repo_issues_event_min_datetime": "2017-05-18T19:27:40.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T23:22:11.000Z", "max_forks_repo_path": "test/f90_correct/src/mmul_misc3.f90", "max_forks_repo_name": "abrahamtovarmob/flang", "max_forks_repo_head_hexsha": "bcd84b29df046b6d6574f0bfa34ea5059092615a", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 157, "max_forks_repo_forks_event_min_datetime": "2017-05-17T18:50:33.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T07:06:45.000Z", "avg_line_length": 32.4193548387, "max_line_length": 113, "alphanum_fraction": 0.5512437811, "num_tokens": 382, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178929, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.6975354045865119}} {"text": "program Nqueens\n implicit none\n\n integer, parameter :: n = 8 ! size of board\n integer :: file = 1, rank = 1, queens = 0\n integer :: i\n logical :: board(n,n) = .false.\n\n do while (queens < n)\n board(file, rank) = .true.\n if(is_safe(board, file, rank)) then\n queens = queens + 1\n file = 1\n rank = rank + 1\n else\n board(file, rank) = .false.\n file = file + 1\n do while(file > n)\n rank = rank - 1\n if (rank < 1) then\n write(*, \"(a,i0)\") \"No solution for n = \", n\n stop\n end if\n do i = 1, n\n if (board(i, rank)) then\n file = i\n board(file, rank) = .false.\n queens = queens - 1\n file = i + 1\n exit\n end if\n end do\n end do\n end if\n end do\n\n call Printboard(board)\n\ncontains\n\nfunction is_safe(board, file, rank)\n logical :: is_safe\n logical, intent(in) :: board(:,:)\n integer, intent(in) :: file, rank\n integer :: i, f, r\n\n is_safe = .true.\n do i = rank-1, 1, -1\n if(board(file, i)) then\n is_safe = .false.\n return\n end if\n end do\n\n f = file - 1\n r = rank - 1\n do while(f > 0 .and. r > 0)\n if(board(f, r)) then\n is_safe = .false.\n return\n end if\n f = f - 1\n r = r - 1\n end do\n\n f = file + 1\n r = rank - 1\n do while(f <= n .and. r > 0)\n if(board(f, r)) then\n is_safe = .false.\n return\n end if\n f = f + 1\n r = r - 1\n end do\nend function\n\nsubroutine Printboard(board)\n logical, intent(in) :: board(:,:)\n character(n*4+1) :: line\n integer :: f, r\n\n write(*, \"(a, i0)\") \"n = \", n\n line = repeat(\"+---\", n) // \"+\"\n do r = 1, n\n write(*, \"(a)\") line\n do f = 1, n\n write(*, \"(a)\", advance=\"no\") \"|\"\n if(board(f, r)) then\n write(*, \"(a)\", advance=\"no\") \" Q \"\n else if(mod(f+r, 2) == 0) then\n write(*, \"(a)\", advance=\"no\") \" \"\n else\n write(*, \"(a)\", advance=\"no\") \"###\"\n end if\n end do\n write(*, \"(a)\") \"|\"\n end do\n write(*, \"(a)\") line\nend subroutine\nend program\n", "meta": {"hexsha": "f195a68c5953b53d6aff13e1fa61b13e83374da1", "size": 2086, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/N-queens-problem/Fortran/n-queens-problem-1.f", "max_stars_repo_name": "mullikine/RosettaCodeData", "max_stars_repo_head_hexsha": "4f0027c6ce83daa36118ee8b67915a13cd23ab67", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/N-queens-problem/Fortran/n-queens-problem-1.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/N-queens-problem/Fortran/n-queens-problem-1.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 20.4509803922, "max_line_length": 55, "alphanum_fraction": 0.4702780441, "num_tokens": 716, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84594244507642, "lm_q2_score": 0.8244619220634456, "lm_q1q2_score": 0.6974473342227561}} {"text": "program pg\n implicit none ! always use implicit none, unless you know why \n ! you don't want to...\n ! \n ! Section: Specification\n !\n integer :: mml,i,retinfo ! scalars\n double precision, allocatable :: a(:,:) ! a is a \"deferred shape\" array\n double precision, allocatable :: ata(:,:),meye(:,:)\n integer , allocatable :: ipiv(:)\n character(len=512) :: dfmt ! string\n !\n ! Section: Execution\n !\n mml = 12\n retinfo = 0\n !\n ! Format for I/O\n ! \n write(dfmt, '(a,i0,a)') '(' , mml , 'f7.2)' ! a => character , i0 => minimum digits required for integer \n !\n ! Allocate memory\n !\n allocate( a(mml,mml) &\n & , ata(mml,mml) &\n & , meye(mml,mml) &\n & , ipiv(mml) &\n & )\n !\n ! Assign all elements of meye to 0\n !\n meye = 0.0d0\n !\n ! Assign all elements on the diagonal of meye to 1.0\n !\n do i = 1,mml\n mEye(i,i) = 1.0d0\n end do\n !\n ! Output the matrix: meye\n ! \n write(*,*) 'Identity matrix meye:'\n write(*,*)\n write(*,dfmt) TRANSPOSE(meye)\n !\n ! Deallocate memory\n !\n deallocate( a, ata, meye, ipiv) \nend program pg\n", "meta": {"hexsha": "fd3db5752177867940c493552d39e51c8c602fd0", "size": 1249, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "docker/src/000-lu.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/000-lu.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/000-lu.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": 24.98, "max_line_length": 110, "alphanum_fraction": 0.4939951962, "num_tokens": 392, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424295406088, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.6974473250627268}} {"text": "module asflowf_cube_to_vtk\r\n\r\n use asflowf_crystal, only : write_xyz\r\n use asflowf_cube, only : cube\r\n use asflowf_constants\r\n \r\n implicit none\r\n\r\n contains \r\n\r\n subroutine cube_to_vtk(cube_file_in, vtk_file_out)\r\n\r\n integer :: i, j, k\r\n integer :: ngridx, ngridy, ngridz\r\n\r\n type(cube) :: cube_i\r\n\r\n real(kind=dp) :: cell_volume, cell_volume_per_unit, tmp, tmp_vec(3)\r\n real(kind=dp) :: a, b, c, x, y, z, total_electron\r\n\r\n ! character, allocatable :: cube_file_in\r\n !character(len=128), intent(in) :: cube_file_in, vtk_file_out\r\n character(len=*), intent(in) :: cube_file_in, vtk_file_out\r\n\r\n ! read cube file\r\n \r\n write(*, *) \"On getting the command line argument:\"\r\n if ( cube_file_in == \"\" .or. vtk_file_out == \"\") then\r\n write(*, *) \"You should provide the name for the input cube file and output vtk file!\"\r\n stop\r\n else\r\n write(*, *) \"The input cube file name is: \", cube_file_in\r\n write(*, *) \"The output vtk file name is: \", vtk_file_out\r\n end if\r\n\r\n call cube_i%read_cube_file(cube_file_in)\r\n\r\n write(*, *) \"Successfully read the cube file!\"\r\n\r\n ! value in cube file are \\rho(r)_of_electrons in unit of e/Bohr^3\r\n ! namely number of electrons each Borh^3\r\n ! so we have to convert it to e/Angstrom^3, through divide it by bohr_to_angstrom**3\r\n\r\n call cross_3(cube_i%cube_crystal%cell(1, :), cube_i%cube_crystal%cell(2, :), tmp_vec)\r\n\r\n call dot_3(tmp_vec, cube_i%cube_crystal%cell(3, :), cell_volume)\r\n\r\n ngridx = cube_i%ngridx\r\n ngridy = cube_i%ngridy\r\n ngridz = cube_i%ngridz\r\n\r\n cell_volume_per_unit = cell_volume / ngridx / ngridy / ngridz\r\n\r\n total_electron = sum(cube_i%data) * cell_volume_per_unit / bohr_to_angstrom**3\r\n \r\n write(*, *) \"-----------------------------------------------------------------\"\r\n write(*, *) \" Out put collected information \"\r\n write(*, *) \"-----------------------------------------------------------------\"\r\n write(*, *) \"ngridx: \", ngridx\r\n write(*, *) \"ngridy: \", ngridy\r\n write(*, *) \"ngridz: \", ngridz\r\n write(*, *) \"cell volume: \", cell_volume\r\n write(*, *) \"total number of electrons: \", total_electron\r\n write(*, *) \"-----------------------------------------------------------------\"\r\n\r\n call dot_3(cube_i%cube_crystal%cell(1, :), cube_i%cube_crystal%cell(1, :), a)\r\n a = sqrt(a)\r\n call dot_3(cube_i%cube_crystal%cell(2, :), cube_i%cube_crystal%cell(2, :), b)\r\n b = sqrt(b)\r\n call dot_3(cube_i%cube_crystal%cell(3, :), cube_i%cube_crystal%cell(3, :), c)\r\n c = sqrt(c)\r\n\r\n !write(*, *) a, b ,c\r\n \r\n ! output data to vtk file\r\n open(11, file=vtk_file_out, status=\"replace\", action=\"write\")\r\n write(11, \"(A)\") \"# vtk DataFile Version 5.1\"\r\n write(11, \"(A)\") cube_file_in\r\n write(11, \"(A)\") \"ASCII\"\r\n write(11, \"(A)\") \"DATASET STRUCTURED_POINTS\"\r\n write(11, \"(A, 3I10)\") \"DIMENSIONS \", ngridx, ngridy, ngridz\r\n write(11, \"(A, 3F15.6)\") \"SPACING\", a/ngridx, b/ngridy, c/ngridz\r\n\r\n !write(11, \"(A, I10, A)\") \"POINTS \", ngridx * ngridy * ngridz, ' float'\r\n !do i = 1, ngridx\r\n ! do j = 1, ngridy\r\n ! do k = 1, ngridz\r\n ! !x = real(i-1) / real(ngridx) * a\r\n ! !y = real(j-1) / real(ngridy) * b\r\n ! !z = real(k-1) / real(ngridz) * c\r\n ! x = real(i) / real(ngridx) * a\r\n ! y = real(j) / real(ngridy) * b\r\n ! z = real(k) / real(ngridz) * c\r\n ! write(11, *) x, y, z\r\n ! end do\r\n ! end do\r\n !end do\r\n \r\n ! write grid point values:\r\n write(11, \"(A, I10)\") 'POINT_DATA ', ngridx * ngridy * ngridz\r\n write(11, \"(A)\") 'SCALARS CON float 1'\r\n write(11, \"(A)\") 'LOOKUP_TABLE default'\r\n do k = 1, ngridz\r\n do j = 1, ngridy\r\n do i = 1, ngridx\r\n write(11, *) cube_i%data(i, j, k)\r\n end do\r\n end do\r\n end do\r\n close(11)\r\n ! output the total structure\r\n call write_xyz(cube_i%cube_crystal, \"cube-structure.xyz\")\r\n end subroutine cube_to_vtk\r\n\r\n\r\n subroutine cross_3(x, y, z)\r\n implicit none\r\n real(kind=dp), dimension(3), intent(in) :: x, y\r\n real(kind=dp), dimension(3), intent(out) :: z\r\n\r\n z(1) = x(2) * y(3) - x(3) * y(2)\r\n z(2) = x(3) * y(1) - x(1) * y(3)\r\n z(3) = x(1) * y(2) - x(2) * y(1)\r\n end subroutine\r\n\r\n subroutine dot_3(x, y, z)\r\n implicit none\r\n real(kind=dp), dimension(3), intent(in) :: x, y \r\n real(kind=dp), intent(out) :: z \r\n z = x(1) * y(1) + x(2) * y(2) + x(3) * y(3)\r\n end subroutine dot_3\r\nend module asflowf_cube_to_vtk\r\n", "meta": {"hexsha": "7644fbbea96b4d2c45433b2f136d7c6712e3a006", "size": 5060, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/atomsciflowf/src/cube_to_vtk.f90", "max_stars_repo_name": "DeqiTang/build-test-atomsciflow", "max_stars_repo_head_hexsha": "6fb65c79e74993e2100fbbca31b910d495076805", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-25T01:44:32.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-25T01:44:32.000Z", "max_issues_repo_path": "fortran/atomsciflowf/src/cube_to_vtk.f90", "max_issues_repo_name": "DeqiTang/build-test-atomsciflow", "max_issues_repo_head_hexsha": "6fb65c79e74993e2100fbbca31b910d495076805", "max_issues_repo_licenses": ["MIT"], "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/atomsciflowf/src/cube_to_vtk.f90", "max_forks_repo_name": "DeqiTang/build-test-atomsciflow", "max_forks_repo_head_hexsha": "6fb65c79e74993e2100fbbca31b910d495076805", "max_forks_repo_licenses": ["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.045112782, "max_line_length": 99, "alphanum_fraction": 0.493083004, "num_tokens": 1504, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273633016692238, "lm_q2_score": 0.752012562644147, "lm_q1q2_score": 0.6973888529904101}} {"text": "SUBROUTINE solve_band(pb,work,loads)\r\n!\r\n! This subroutine performs Gaussian forward and back-substitution\r\n! on the reduced unsymmetric band matrix pb.\r\n!\r\n IMPLICIT NONE\r\n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\r\n REAL(iwp),INTENT(IN)::pb(:,:),work(:,:)\r\n REAL(iwp),INTENT(OUT)::loads(0:)\r\n INTEGER::iwp1,n,n1,i,iv,l,iq,iv1\r\n REAL(iwp)::s,pt5=0.5_iwp\r\n iwp1=(UBOUND(pb,2)-1)/2+1\r\n n=UBOUND(pb,1)\r\n iq=2*iwp1-1 \r\n n1=n-1\r\n DO iv=1,n1\r\n i=INT(work(iwp1,iv)+pt5)\r\n IF(i/=iv)THEN\r\n s=loads(iv)\r\n loads(iv)=loads(i)\r\n loads(i)=s\r\n END IF\r\n l=iv+iwp1-1\r\n IF(l>n)l=n\r\n iv1=iv+1\r\n DO i=iv1,l\r\n loads(i)=loads(i)-work(i-iv,iv)*loads(iv)\r\n END DO\r\n END DO\r\n loads(n)=loads(n)/pb(n,1)\r\n iv=n-1\r\n DO WHILE(iv/=0)\r\n s=loads(iv)\r\n l=iq\r\n IF(iv+l-1>n)l=n-iv+1\r\n DO i=2,l\r\n s=s-pb(iv,i)*loads(iv+i-1)\r\n loads(iv)=s/pb(iv,1)\r\n END DO\r\n iv=iv-1\r\n END DO\r\nRETURN\r\nEND SUBROUTINE solve_band\r\n", "meta": {"hexsha": "0926428f5e9efd114c815055f1d9f07dd771b359", "size": 931, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "src/libs/main/solve_band.f03", "max_stars_repo_name": "leemargetts/PoreFEM", "max_stars_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/libs/main/solve_band.f03", "max_issues_repo_name": "leemargetts/PoreFEM", "max_issues_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/libs/main/solve_band.f03", "max_forks_repo_name": "leemargetts/PoreFEM", "max_forks_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.1590909091, "max_line_length": 66, "alphanum_fraction": 0.597207304, "num_tokens": 366, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632856092014, "lm_q2_score": 0.7520125626441471, "lm_q1q2_score": 0.6973888409130716}} {"text": "! fortran program to verify trignometric identities\n\nprogram trig\n implicit none\n\n integer :: i\n integer, PARAMETER :: n = 100\n real(KIND=8), DIMENSION(0:n) :: x, sinx, cosx, secx, tanx, cscx, cotx, sin2x\n real, PARAMETER :: pi = 2*asin(1.0)\n real :: increment = 2 * pi/(real(n))\n\n !do i = 0,n\n !x(i) = i*increment\n !end do\n\n x(0:n) = [(i*increment, i = 0,n)] ! An alternate way to define the array\n\n sinx = SIN(x)\n cosx = COS(x)\n tanx = TAN(x)\n secx = 1.0/cosx\n cscx = 1.0/sinx\n cotx = 1.0/tanx\n sin2x = sinx**2 ! this is square of sinx\n\n 10 format(\"The sine of \", f10.4, \" is : \", f10.4)\n 20 format(\"The square of sine of \", f10.4, \" is : \", f10.4)\n 30 format(\"The cosine of \", f10.4, \" is : \", f10.4)\n\n open(unit=1, file = 'plot.txt')\n 15 format(f10.4, 4x, f10.4, 4x, f10.4)\n\n do i = 0,n\n !print 10, (x(i)/pi) * 180, sinx(i)\n !print 30, (x(i)/pi) * 180, cosx(i)\n write(unit=1, fmt = 15) (x(i)/pi) * 180, secx(i), cscx(i)\n end do\n\n close(unit=1)\n\nend program trig\n", "meta": {"hexsha": "589891ae98e014a22f4febfa6cf845149ab27994", "size": 1066, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "fortran_tut/plotting/trig_iden.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/plotting/trig_iden.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/plotting/trig_iden.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": 25.380952381, "max_line_length": 80, "alphanum_fraction": 0.5412757974, "num_tokens": 431, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146780175245, "lm_q2_score": 0.793105951184112, "lm_q1q2_score": 0.697256543321337}} {"text": "program AoS\n USE IFPORT\n use iso_fortran_env, only : real32, real64\n implicit none\n\n type charge\n real(real32) :: x,y,z,q ! Coordinates and value of the charge\n end type charge\n\n type(charge), allocatable :: charges(:)\n real(real32), allocatable :: potential(:)\n integer, parameter :: m = 2048, n_trials = 10\n integer :: i,j\n real(real32) :: Rx, Ry, Rz\n real(real64) :: end_time, start_time\n\n allocate(charges(m), potential(m*m))\n\n call srand(12345)\n\n do i = 1, m\n charges(i)%x = rand()\n charges(i)%y = rand()\n charges(i)%z = rand()\n charges(i)%q = rand()\n end do\n\n do i = 1, n_trials\n potential = 0.0\n call cpu_time(start_time)\n do j = 1, m*m\n Rx = real(mod(j,m))\n Ry = real(j/m)\n Rz = 0.0\n potential(j) = calculate_electric_potential(charges, Rx, Ry, Rz)\n end do\n call cpu_time(end_time)\n write(*,*) 'Trial ',i,' test ',potential(100), 'time ', end_time - start_time\n end do\n\ncontains\n\n function calculate_electric_potential(charges, Rx, Ry, Rz) result(phi)\n implicit none\n\n real(real32), intent(in) :: Rx, Ry, Rz\n type(charge),allocatable,intent(in) :: charges(:)\n real(real32) :: dx,dy,dz\n real(real32) :: phi\n integer :: i\n\n phi = 0.0\n\n do i = 1, size(charges)\n dx = charges(i)%x - Rx\n dy = charges(i)%y - Ry\n dz = charges(i)%z - Rz\n phi = phi - charges(i)%q / sqrt(dx**2 + dy**2 + dz**2)\n end do\n\n end function calculate_electric_potential\n\nend program AoS\n", "meta": {"hexsha": "faff38130910d056d71832f551ce23d9abb044c5", "size": 1505, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "AoS_vs_SoA/AoS/AoS.f90", "max_stars_repo_name": "afanfa/OptimizedModernFortran", "max_stars_repo_head_hexsha": "9b55295fc7041cd91e7a8cea902f2007a8dd5fc7", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 26, "max_stars_repo_stars_event_min_datetime": "2019-01-29T22:42:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T16:53:02.000Z", "max_issues_repo_path": "AoS_vs_SoA/AoS/AoS.f90", "max_issues_repo_name": "afanfa/OptimizedModernFortran", "max_issues_repo_head_hexsha": "9b55295fc7041cd91e7a8cea902f2007a8dd5fc7", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-07-23T16:39:14.000Z", "max_issues_repo_issues_event_max_datetime": "2020-03-24T20:55:21.000Z", "max_forks_repo_path": "AoS_vs_SoA/AoS/AoS.f90", "max_forks_repo_name": "afanfa/OptimizedModernFortran", "max_forks_repo_head_hexsha": "9b55295fc7041cd91e7a8cea902f2007a8dd5fc7", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-03-12T05:18:59.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-12T16:09:44.000Z", "avg_line_length": 23.515625, "max_line_length": 82, "alphanum_fraction": 0.5980066445, "num_tokens": 480, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467738423873, "lm_q2_score": 0.7931059487389968, "lm_q1q2_score": 0.6972565361490948}} {"text": " Program DiasMes\n\n! leyendo el mes y el a\u00f1o responde los d\u00edas que tiene el mes\n\n!\n \nimplicit none\n\n integer :: anio , dias\n\n character ( len=15) :: mes\n\n character ( len =1) :: d\n\n dias = 0\n\n write(*,*) \" Ingrese el mes en min\u00fascula : \"\n\n read(*,*) mes\n \n write(*,*) \" Ingrese el a\u00f1o : \"\n\n read(*,*) anio\n\n\n\n\n select case ( mes )\n\n case (\"enero\")\n\n dias = 31\n\n case (\"febrero\")\n \n IF ( mod(anio,4)== 0) THEN \n \n dias = 29 \n \n ELSE \n\n dias = 28\n \n END IF\n\n case (\"marzo\")\n\n dias = 31\n\n case (\"abril\")\n\n dias = 30\n\n case (\"mayo\")\n\n dias = 31\n\n case (\"junio\")\n\n dias = 30\n \n case (\"julio\")\n\n dias = 31\n\n case (\"agosto\")\n\n dias = 31\n\n case (\"setiembre\")\n\n dias = 30\n\n case (\"octubre\")\n\n dias = 31\n\n case (\"noviembre\")\n\n dias = 30\n\n case (\"diciembre\")\n\n dias = 31\n\n\n case default\n\n write(*,*) \"no reoconozco ese mes = \", mes\n\n end select\n\n write(*,*) \"el n\u00famero de dias de \", mes , \" de \" , anio, \" es \" , dias\n \n write(*,*) \" the end \"\n\n \n\n end program DiasMes\n", "meta": {"hexsha": "3fa314a174d520825ef56f26ba0e09104951b1f6", "size": 1207, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "G1e15/DiasMes.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": "G1e15/DiasMes.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": "G1e15/DiasMes.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": 12.07, "max_line_length": 75, "alphanum_fraction": 0.4407622204, "num_tokens": 346, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467738423873, "lm_q2_score": 0.7931059487389966, "lm_q1q2_score": 0.6972565361490947}} {"text": " SUBROUTINE qsimp(func,a,b,s)\r\n INTEGER JMAX\r\n REAL a,b,func,s,EPS\r\n EXTERNAL func\r\n PARAMETER (EPS=1.e-6, JMAX=20)\r\nCU USES trapzd\r\n INTEGER j\r\n REAL os,ost,st\r\n ost=-1.e30\r\n os= -1.e30\r\n do 11 j=1,JMAX\r\n call trapzd(func,a,b,st,j)\r\n s=(4.*st-ost)/3.\r\n if (abs(s-os).lt.EPS*abs(os)) return\r\n if (s.eq.0..and.os.eq.0..and.j.gt.6) return\r\n os=s\r\n ost=st\r\n11 continue\r\n pause 'too many steps in qsimp'\r\n END\r\n", "meta": {"hexsha": "8ee4ccafb00b82dd654d12e78e25953892e82189", "size": 515, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/qsimp.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/qsimp.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/qsimp.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.5238095238, "max_line_length": 52, "alphanum_fraction": 0.4990291262, "num_tokens": 175, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146761176671, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.697256532552685}} {"text": "c program DRSMLC01\nc>> 2001-05-22 DRSMLC01 Krogh Minor change for making .f90 version.\nc>> 1996-07-08 DRSMLC01 Krogh Minor format change for C conversion.\nc>> 1994-11-02 DRSMLC01 Krogh Changes to use M77CON\nc>> 1994-09-13 DRSMLC01 CLL\nc>> 1992-05-13 CLL\nc>> 1992-04-15 CLL\nc>> 1992-01-21 CLL\nc>> 1991-06-10 CLL\nc>> 1992-01-16 CLL\nc>> 1990-07-12 CLL\nc Demo driver for SMLC01. Also uses SCKDER to check gradient.\nc Minimization with linear constraints.\nc The constraints are Ax .le. b with equality required in the first\nc two rows.\nc ------------------------------------------------------------------\nc--S replaces \"?\": DR?MLC01, ?MLC01, ?XLOGX, ?CKDER\nc ------------------------------------------------------------------\n external SXLOGX\n integer MMAX, NMAX, LIW, LW\n parameter(MMAX = 3, NMAX = 4)\n parameter(LIW = 4 + MMAX + 2*NMAX)\n parameter(LW = 3 + MMAX + NMAX*(16 + NMAX))\n integer I, IMAX, IPRINT, IW(LIW), J, JMAX\n integer M, MEQ, MODE, MXEVAL, N\n logical HAVEG\n real A(MMAX, NMAX), ACC, B(MMAX), FVAL(1), GRAD(NMAX)\n real GDUMMY(NMAX), TEST(NMAX), TSTMAX, W(LW)\n real X(NMAX), XL(NMAX), XU(NMAX)\n data M, MEQ, N / 3, 2, 4 /\n data ACC, IPRINT, MXEVAL / 0.0E0, 3, 0 /\n data ((A(I,J),J=1,4),I=1,3) / 1.0E0, 1.0E0, 1.0E0, 1.0E0 ,\n * 1.0E0, -1.0E0, 0.0E0, 0.0E0,\n * 0.0E0, -1.0E0, 1.0E0, 0.0E0 /\n data (B(I),I=1,3) / 1.0E0, 0.25E0, -0.1E0 /\n data (XL(J),J=1,4) / 4*1.0E-6 /\n data (XU(J),J=1,4) / 4*1.0E0 /\n data (X(J),J=1,4) / 0.7e0, 0.6e0, 0.5e0, 0.4e0 /\nc ------------------------------------------------------------------\n print*,\n * 'Program DRSMLC01.. Demo driver for SMLC01. Also uses SCKDER.'\nc\nc Using SCKDER to check the gradient calculation.\nc\n MODE = 1\n call SXLOGX( N, X, FVAL(1), GRAD, HAVEG)\n 10 continue\n call SCKDER(MODE, 1, N, X, FVAL, GRAD, 1, TEST, IMAX, JMAX,TSTMAX)\n call SXLOGX( N, X, FVAL(1), GDUMMY, HAVEG)\n if(MODE .eq. 2) go to 10\n print'(/'' Using SCKDER to check the gradient calculation.'')'\n print'(/11x,''X(J) ='',5g11.3:/(17x,5g11.3))',(X(J),J=1,N)\n print'(11x,''FVAL ='',5g11.3)',FVAL(1)\n print'(7x,''Gradient ='',5g11.3:/(17x,5g11.3))',(GRAD(J),J=1,N)\n print'(9x,''TEST() ='',5g11.3/(17x,5g11.3))',(TEST(J),J=1,N)\n print'(11x,''JMAX ='',i3,'', TSTMAX ='',g11.3)',JMAX,\n * TSTMAX\nc\nc Using SMLC01 to solve the minimization problem.\nc\n print'(/'' Using SMLC01 to solve the minimization problem.'')'\n call SMLC01 (SXLOGX, N, M, MEQ, A, MMAX, B, XL, XU, X, ACC,\n * IPRINT, MXEVAL, IW, LIW, W, LW)\n stop\n end\nc ==================================================================\n subroutine SXLOGX( N, X, F, G, HAVEG)\nc ------------------------------------------------------------------\n integer I, N\n real F, G(N), X(N)\n logical HAVEG\nc ------------------------------------------------------------------\n HAVEG = .true.\n F = 0.0E0\n do 10 I = 1,N\n F = F + X(I) * log(X(I))\n G(I) = 1.0E0 + log(X(I))\n 10 continue\n return\n end\n", "meta": {"hexsha": "efe5bcb2ab78d38fd7e597a6280907d7339c2d64", "size": 3331, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drsmlc01.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drsmlc01.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drsmlc01.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 41.1234567901, "max_line_length": 72, "alphanum_fraction": 0.4638246773, "num_tokens": 1238, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095292, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.6972565268272372}} {"text": " PROGRAM xrk4\r\nC driver for routine rk4\r\n INTEGER N\r\n PARAMETER(N=4)\r\n INTEGER i,j\r\n REAL bessj,bessj0,bessj1\r\n REAL h,x,y(N),dydx(N),yout(N)\r\n EXTERNAL derivs\r\n x=1.0\r\n y(1)=bessj0(x)\r\n y(2)=bessj1(x)\r\n y(3)=bessj(2,x)\r\n y(4)=bessj(3,x)\r\n call derivs(x,y,dydx)\r\n write(*,'(/1x,a,t19,a,t31,a,t43,a,t55,a)')\r\n * 'Bessel Function:','J0','J1','J3','J4'\r\n do 11 i=1,5\r\n h=0.2*i\r\n call rk4(y,dydx,N,x,h,yout,derivs)\r\n write(*,'(/1x,a,f6.2)') 'For a step size of:',h\r\n write(*,'(1x,a10,4f12.6)') 'RK4:',(yout(j),j=1,4)\r\n write(*,'(1x,a10,4f12.6)') 'Actual:',bessj0(x+h),\r\n * bessj1(x+h),bessj(2,x+h),bessj(3,x+h)\r\n11 continue\r\n END\r\n SUBROUTINE derivs(x,y,dydx)\r\n REAL x,y(*),dydx(*)\r\n dydx(1)=-y(2)\r\n dydx(2)=y(1)-(1.0/x)*y(2)\r\n dydx(3)=y(2)-(2.0/x)*y(3)\r\n dydx(4)=y(3)-(3.0/x)*y(4)\r\n return\r\n END\r\n", "meta": {"hexsha": "f0878b4de9d496b01178cdbe33326ab1e683f963", "size": 974, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xrk4.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xrk4.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xrk4.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.6470588235, "max_line_length": 58, "alphanum_fraction": 0.4630390144, "num_tokens": 417, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.909907010924213, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6972559631269536}} {"text": "program mean_mask\n use stdlib_stats, only: mean\n implicit none\n real :: y(1:2, 1:3) = reshape([1., 2., 3., 4., 5., 6.], [2, 3])\n\n print*, mean(y, y > 2.)\n print*, mean(y, 1, y > 2.)\n print*, mean(y, 2, y > 2.)\nend program mean_mask\n", "meta": {"hexsha": "b4101916f7bfcd96e79d789f1c9a08cbe2a59154", "size": 238, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/how-to/stats/app/mean_mask.f90", "max_stars_repo_name": "awvwgk/stdlib-docs", "max_stars_repo_head_hexsha": "ab3efac3bd94a42d130e1412dcc90b3f9ef8ec54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2022-01-19T16:17:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T07:39:09.000Z", "max_issues_repo_path": "src/how-to/stats/app/mean_mask.f90", "max_issues_repo_name": "awvwgk/stdlib-docs", "max_issues_repo_head_hexsha": "ab3efac3bd94a42d130e1412dcc90b3f9ef8ec54", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2022-02-06T16:37:45.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-16T09:33:06.000Z", "max_forks_repo_path": "src/how-to/stats/app/mean_mask.f90", "max_forks_repo_name": "awvwgk/stdlib-docs", "max_forks_repo_head_hexsha": "ab3efac3bd94a42d130e1412dcc90b3f9ef8ec54", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2022-01-29T17:40:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-23T07:39:04.000Z", "avg_line_length": 23.8, "max_line_length": 65, "alphanum_fraction": 0.5546218487, "num_tokens": 103, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9099070060380482, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6972559593827166}} {"text": "\tSUBROUTINE GR_STAT ( z, kx, ky, imin, jmin, imax, jmax, \n +\t\t\t rmin, rmax, ravg, rdev, iret )\nC************************************************************************\nC* GR_STAT\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This subroutine computes grid statistics.\t\t\t\t*\nC* \t\t\t\t\t\t\t\t\t*\nC* GR_STAT ( Z, KX, KY, IMIN, JMIN, IMAX, JMAX, RMIN, RMAX, \t\t*\nC* RAVG, RDEV, IRET )\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tZ (KX,KY)\tREAL\t\tData array\t\t\t*\nC*\tKX\t\tINTEGER\t\tNumber of points in x dir\t*\nC*\tKY\t\tINTEGER\t\tNumber of points in y dir\t*\nC*\tIMIN\t\tINTEGER\t\tLower left corner of subgrid\t*\nC*\tJMIN\t\tINTEGER\t\tLower left corner of subgrid\t*\nC*\tIMAX\t\tINTEGER\t\tUpper right corner of subgrid\t*\nC*\tJMAX\t\tINTEGER\t\tUpper right corner of subgrid\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tRMIN\t\tREAL\t\tMinimum data value\t\t*\nC*\tRMAX\t\tREAL\t\tMaximum data value\t\t*\nC*\tRAVG\t\tREAL\t\tAverage data value\t\t*\nC*\tRDEV\t\tREAL\t\tStandard deviation\t\t*\nC* \tIRET\t\tINTEGER\t\tReturn code\t\t\t*\nC*\t\t\t\t\t 0 = normal return\t\t*\nC*\t\t\t\t\t -8 = no data in range\t\t*\nC*\t\t\t\t\t -9 = invalid subset area\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* G. Chatters/RDS\t 6/82\t\t\t\t\t\t*\nC* M. Vilardo/RDS\t11/84\tGEMPLT Version 3.0\t\t\t*\nC* M. desJardins/GSFC\t12/84\tConverted from GEMPLT for GEMPAK\t*\nC* M. desJardins/GSFC\t 9/88\tGEMPAK4\t\t\t\t\t*\nC* G. Huffman/USRA\t 7/89\tUse REAL*8 to avoid precision errors\t*\nC* K. Brill 5/90 Return distinct RMIN, RMAX for 0 < n < 4*\nC* M. desJardins/GSFC\t10/90\tReturn missing values for no data\t*\nC* S. Chiswell/Unidata\t11/06\tuse double precision gpt\t\t*\nC************************************************************************\n INCLUDE 'GEMPRM.PRM'\nC*\n\tREAL\t\tz ( kx, ky )\nC*\n\tDOUBLE PRECISION\tsum, sumsq, var, gpt\nC*\n INCLUDE 'ERMISS.FNC'\nC------------------------------------------------------------------------\n\tiret = 0\nC\nC*\tCheck values given for imin, imax, jmin, jmax.\nC\n\tIF ( ( imin .lt. 1 ) .or. ( imax .gt. kx ) .or. \n +\t ( imin .gt. imax ) .or. ( jmin .lt. 1 ) .or.\n +\t ( jmax .gt. ky ) .or. ( jmin .gt. jmax ) ) THEN\n\t iret = -9\n\t RETURN\n\tEND IF\nC\nC*\tInitialize variables for computing average and standard \nC*\tdeviation.\nC\n\tsum = 0.0\n\tsumsq = 0.0\n\tnsum = 0\n\trmax = RMISSD\n\trmin = RMISSD\nC\nC*\tRead through all the data in the subgrid.\nC\n\tDO i = imin, imax\n\t DO j = jmin, jmax\n\t\tIF ( .not. ERMISS ( z (i,j) ) ) THEN\n\t\t gpt = z (i,j)\n\t\t IF ( nsum .eq. 0 ) THEN\n\t\t\tsum = gpt\n\t\t\tsumsq = gpt * gpt\n\t\t\tnsum = 1\n\t\t\trmax = z (i,j)\n\t\t\trmin = z (i,j)\n\t\t ELSE\n\t\t\tsum = sum + gpt\n\t\t\tsumsq = sumsq + gpt * gpt\n\t\t\tnsum = nsum + 1\n\t\t\tIF ( z (i,j) .gt. rmax ) rmax = z (i,j)\n\t\t\tIF ( z (i,j) .lt. rmin ) rmin = z (i,j)\n\t\t END IF\n\t\tEND IF\n\t END DO\n\tEND DO\nC \nC*\tCheck for at least four points and that data has some range\nC* before computing standard deviation.\nC\n\tIF ( ( nsum .ge. 4 ) .and. ( rmin .lt. rmax ) ) THEN\n\t ravg = sum / nsum\n\t var = sumsq / nsum - ( sum / nsum ) ** 2\n\t IF ( var .lt. 0. ) THEN\n\t\trdev = 0.0\n\t\tiret = -8\n\t ELSE\n\t\trdev = SQRT ( var )\n\t END IF\n\t ELSE IF ( nsum .gt. 0 ) THEN\n\t ravg = 0.0\n\t rdev = 0.0\n\t ELSE\n\t iret = -8\n\tEND IF\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "9faf31cd69cc69dca4a61b2a64d6159b8eeeddd2", "size": 3206, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/gridlib/gr/grstat.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/gridlib/gr/grstat.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/gridlib/gr/grstat.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": 28.625, "max_line_length": 73, "alphanum_fraction": 0.5140361822, "num_tokens": 1246, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380482, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6972559496699521}} {"text": "module nf_activation\n\n ! A collection of activation functions and their derivatives.\n\n implicit none\n\n private\n\n public :: activation_function\n public :: elu, elu_prime\n public :: exponential\n public :: gaussian, gaussian_prime\n public :: relu, relu_prime\n public :: sigmoid, sigmoid_prime\n public :: softplus, softplus_prime\n public :: step, step_prime\n public :: tanhf, tanh_prime\n\n interface\n pure function activation_function(x)\n real, intent(in) :: x(:)\n real :: activation_function(size(x))\n end function activation_function\n end interface\n\ncontains\n\n pure function elu(x, alpha) result(res)\n ! Exponential Linear Unit (ELU) activation function.\n real, intent(in) :: x(:)\n real, intent(in) :: alpha\n real :: res(size(x))\n where (x >= 0)\n res = x\n elsewhere\n res = alpha * (exp(x) - 1)\n end where\n end function elu\n\n pure function elu_prime(x, alpha) result(res)\n ! First derivative of the Exponential Linear Unit (ELU)\n ! activation function.\n real, intent(in) :: x(:)\n real, intent(in) :: alpha\n real :: res(size(x))\n where (x >= 0)\n res = 1\n elsewhere\n res = alpha * exp(x)\n end where\n end function elu_prime\n\n pure function exponential(x) result(res)\n ! Exponential activation function.\n real, intent(in) :: x(:)\n real :: res(size(x))\n res = exp(x)\n end function exponential\n\n pure function gaussian(x) result(res)\n ! Gaussian activation function.\n real, intent(in) :: x(:)\n real :: 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, intent(in) :: x(:)\n real :: 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, intent(in) :: x(:)\n real :: 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, intent(in) :: x(:)\n real :: 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, intent(in) :: x(:)\n real :: 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, intent(in) :: x(:)\n real :: res(size(x))\n res = sigmoid(x) * (1 - sigmoid(x))\n end function sigmoid_prime\n\n pure function softplus(x) result(res)\n ! Softplus activation function.\n real, intent(in) :: x(:)\n real :: res(size(x))\n res = log(exp(x) + 1)\n end function softplus\n\n pure function softplus_prime(x) result(res)\n ! First derivative of the softplus activation function.\n real, intent(in) :: x(:)\n real :: res(size(x))\n res = exp(x) / (exp(x) + 1)\n end function softplus_prime\n\n pure function step(x) result(res)\n ! Step activation function.\n real, intent(in) :: x(:)\n real :: 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, intent(in) :: x(:)\n real :: 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, intent(in) :: x(:)\n real :: 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, intent(in) :: x(:)\n real :: res(size(x))\n res = 1 - tanh(x)**2\n end function tanh_prime\n\nend module nf_activation\n", "meta": {"hexsha": "50f9362ce56064f4da5f2538c741c18fd8d17a7b", "size": 4006, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/nf_activation.f90", "max_stars_repo_name": "rouson/neural-fortran", "max_stars_repo_head_hexsha": "c05368a5f36ea15bf2428c33c02b97c6f7d30c35", "max_stars_repo_licenses": ["MIT"], "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/nf_activation.f90", "max_issues_repo_name": "rouson/neural-fortran", "max_issues_repo_head_hexsha": "c05368a5f36ea15bf2428c33c02b97c6f7d30c35", "max_issues_repo_licenses": ["MIT"], "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/nf_activation.f90", "max_forks_repo_name": "rouson/neural-fortran", "max_forks_repo_head_hexsha": "c05368a5f36ea15bf2428c33c02b97c6f7d30c35", "max_forks_repo_licenses": ["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.6794871795, "max_line_length": 79, "alphanum_fraction": 0.6350474289, "num_tokens": 1067, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380482, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6972559496699521}} {"text": " subroutine DCOV2( A, MDIM, N, IP, VAR, IERR)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc>> 2001-02-13 DCOV2 Krogh Fixed a comment.\nc>> 1996-03-30 DCOV2 Krogh Added external statement.\nC>> 1994-11-11 DCOV2 Krogh Declared all vars.\nC>> 1994-10-20 DCOV2 Krogh Changes to use M77CON\nC>> 1989-10-20 DCOV2 CLL\nC>> 1987-11-24 DCOV2 Lawson Initial code.\nc--D replaces \"?\": ?COV2, ?DOT, ?SWAP\nC Computes upper triangle of covariance matrix,\nc beginning with the triangular matrix, and permutation record, and\nc data error variance computed by _HFTI.\nc Thus, given a matrix, A, represented by the upper triangular\nc matrix in A(), and the permutation record in IP(), and the data\nc error variance, VAR, we compute the upper triangle of the\nc symmetric matrix, C = VAR * ((A**t)*A)**(-1).\nC Adapted from PROG2 in L & H book.\nc ------------------------------------------------------------------\nc Subprograms referenced directly: DDOT, DSWAP, IERM1\nc Other subprograms needed: ERMSG, IERV1, ERFIN, AMACH\nc ------------------------------------------------------------------\nc Subroutine Arguments\nc\nc A(,) [inout] On entry, contains the upper triangular matrix, A,\nc in standard, not packed, storage. This matrix could\nc have been produced by _HFTI. On return, contains the\nc upper triangle of the symmetric unscaled covariance\nc matrix. Elements below the diagonal in A(,) will\nc not be referenced.\nc MDIM [in] First dimension of A(,). Require MDIM .ge. N.\nc N [in] Order of the matrix in A(,)\nc IP() [in] Permutation record produced by _HFTI.\nc VAR [in] Estimate of variance of data error.\nc IERR [out] Set to 0 if ok. Set to J > 0 if the (J,J) element\nc of the given matrix is zero. In this latter case\nc the covariance matrix cannot be computed and the\nc contents of A(,) on return will be meaningless.\nC ------------------------------------------------------------------\nc This code was originally developed by Charles L. Lawson and\nc Richard J. Hanson at Jet Propulsion Laboratory in 1973. The\nc original code was described and listed in the book,\nc\nc Solving Least Squares Problems\nc C. L. Lawson and R. J. Hanson\nc Prentice-Hall, 1974\nc\nc Feb, 1985, C. L. Lawson & S. Y. Chan, JPL. Adapted code from the\nc Lawson & Hanson book to Fortran 77 for use in the JPL MATH77\nc library.\nc Prefixing subprogram names with S or D for s.p. or d.p. versions.\nc Using generic names for intrinsic functions.\nc Adding calls to BLAS and MATH77 error processing subrs in some\nc program units.\nC 1989-10-20 CLL Moved integer declaration earlier to avoid warning\nc msg from Cray compiler.\nC ------------------------------------------------------------------\n external DDOT\n integer I, IERR, J, N, MDIM, K, IP1, KP1\n integer IP(N)\n double precision A(MDIM,N), DDOT, ONE, TMP, VAR, ZERO\nC\n parameter(ZERO = 0.0D0, ONE = 1.0D0)\nC ------------------------------------------------------------------\nC Replace upper triangular matrix U by its inverse, Inv(U)\nc\n do 40 J = 1,N\n if(A(J,J) .eq. ZERO) then\n call IERM1('DCOV2',1,0,'Jth diagonal elt is zero',\n * 'J',J,'.')\n IERR = J\n return\n end if\n A(J,J) = ONE / A(J,J)\n 40 continue\n\n do 62 I = 1,N-1\n do 60 J = I+1,N\n A(I,J) = -A(J,J) * DDOT(J-I,A(I,I),MDIM,A(I,J),1)\n 60 continue\n 62 continue\nC\nC Replace Inv(U) by upper triangle of Inv(u) * Trans(Inv(U))\nc multiplied by VAR.\nc\n do 92 I = 1,N\n do 90 J = I,N\n A(I,J) = VAR * DDOT(N-J+1,A(I,J),MDIM,A(J,J),MDIM)\n 90 continue\n 92 continue\nC Permute rows & columns\n do 150 I = N-1, 1, -1\n if (IP(I) .ne. I) then\n K = IP(I)\n TMP = A(I,I)\n A(I,I) = A(K,K)\n A(K,K) = TMP\n if (I .gt. 1) THEN\n CALL DSWAP(I-1,A(1,I),1,A(1,K),1)\n end if\n IP1 = I + 1\n if (IP1 .lt. K) THEN\n CALL DSWAP(K-I-1,A(I,IP1),MDIM,A(IP1,K),1)\n end if\n KP1 = K + 1\n if (KP1 .le. N) THEN\n CALL DSWAP(N-K,A(I,KP1),MDIM,A(K,KP1),MDIM)\n end if\n end if\n 150 continue\n IERR = 0\n end\n", "meta": {"hexsha": "f4700993c3edf0164a9550caabf010cf6572e03b", "size": 4727, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/dcov2.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/dcov2.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/dcov2.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 41.4649122807, "max_line_length": 72, "alphanum_fraction": 0.530780622, "num_tokens": 1366, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380481, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.6972559496699519}} {"text": "program tsunami\n\n ! This version solves the non-linear 1-d shallow water equations:\n !\n ! du/dt + u du/dx = - g dh/dx\n ! \n ! du/dt + u du/dx = - g dh/dx\n !\n ! The initial conditions and the finite difference calculation \n ! are abstracted as external procedures.\n\n use iso_fortran_env, only: int32, real32\n use mod_diff, only: diff => diff_centered\n use mod_initial, only: set_gaussian\n\n implicit none\n\n integer(int32) :: n\n\n integer(int32), parameter :: grid_size = 100 ! grid size in x\n integer(int32), parameter :: num_time_steps = 5000 ! number of time steps\n\n real(real32), parameter :: dt = 0.02 ! time step [s]\n real(real32), parameter :: dx = 1 ! grid spacing [m]\n real(real32), parameter :: g = 9.8 ! gravitational acceleration [m/s^2]\n real(real32), parameter :: hmean = 10 ! mean water depth [m]\n\n real(real32) :: h(grid_size), u(grid_size)\n\n integer(int32), parameter :: icenter = 25\n real(real32), parameter :: decay = 0.02\n\n ! check input parameter values\n if (grid_size <= 0) stop 'grid_size must be > 0'\n if (dt <= 0) stop 'time step dt must be > 0'\n if (dx <= 0) stop 'grid spacing dx must be > 0'\n\n ! initialize water height to a Gaussian blob\n call set_gaussian(h, icenter, decay)\n\n ! initialize water velocity to zero\n u = 0\n\n ! write initial state to screen\n print *, 0, h\n\n time_loop: do n = 1, num_time_steps\n\n ! compute u at next time step\n u = u - (u * diff(u) + g * diff(h)) / dx * dt\n\n ! compute h at next time step\n h = h - diff(u * (hmean + h)) / dx * dt\n\n ! write current state to screen\n print *, n, h\n\n end do time_loop\n\nend program tsunami\n", "meta": {"hexsha": "c5a1e72dc249b21c86cf983a94270fdc3443d7fa", "size": 1633, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/ch04/tsunami.f90", "max_stars_repo_name": "AAGAN/tsunami", "max_stars_repo_head_hexsha": "82635516dcb7f85eb6434ffdb98a9ddc4c1403ad", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-03-13T07:53:57.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-25T01:42:37.000Z", "max_issues_repo_path": "src/ch04/tsunami.f90", "max_issues_repo_name": "AAGAN/tsunami", "max_issues_repo_head_hexsha": "82635516dcb7f85eb6434ffdb98a9ddc4c1403ad", "max_issues_repo_licenses": ["MIT"], "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/ch04/tsunami.f90", "max_forks_repo_name": "AAGAN/tsunami", "max_forks_repo_head_hexsha": "82635516dcb7f85eb6434ffdb98a9ddc4c1403ad", "max_forks_repo_licenses": ["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": 75, "alphanum_fraction": 0.6454378445, "num_tokens": 503, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380481, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6972559448135695}} {"text": "C$Procedure VADDG ( Vector addition, general dimension )\n \n SUBROUTINE VADDG ( V1, V2, NDIM, VOUT )\n \nC$ Abstract\nC\nC Add two vectors of arbitrary dimension.\nC\nC$ Disclaimer\nC\nC THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE\nC CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.\nC GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE\nC ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE\nC PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED \"AS-IS\"\nC TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY\nC WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A\nC PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC\nC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE\nC SOFTWARE AND RELATED MATERIALS, HOWEVER USED.\nC\nC IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA\nC BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT\nC LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,\nC INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,\nC REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE\nC REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.\nC\nC RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF\nC THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY\nC CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE\nC ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.\nC\nC$ Required_Reading\nC\nC None.\nC\nC$ Keywords\nC\nC VECTOR\nC\nC$ Declarations\n \n INTEGER NDIM\n DOUBLE PRECISION V1 ( NDIM )\n DOUBLE PRECISION V2 ( NDIM )\n DOUBLE PRECISION VOUT ( NDIM )\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC V1 I First vector to be added.\nC V2 I Second vector to be added.\nC NDIM I Dimension of V1, V2, and VOUT.\nC VOUT O Sum vector, V1 + V2.\nC \nC$ Detailed_Input\nC\nC V1 This may be any double precision vector of arbitrary\nC dimension.\nC\nC V2 Likewise.\nC\nC NDIM is the dimension of V1, V2 and VOUT.\nC\nC$ Detailed_Output\nC\nC VOUT This is vector sum of V1 and V2.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC Error free.\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC This routine simply performs addition between components of V1\nC and V2. No checking is performed to determine whether floating\nC point overflow has occurred.\nC\nC$ Examples\nC\nC The following table shows the output VOUT as a function of the\nC the input V1 and V2 from the subroutine VADD.\nC\nC V1 V2 NDIM VOUT\nC ---------------------------------------------------------------\nC (1.0, 2.0, 3.0) (4.0, 5.0, 6.0) 3 (5.0, 7.0, 9.0)\nC (1D-7,1D23) (1D24, 1D23) 2 (1D24, 2D23)\nC\nC$ Restrictions\nC\nC The user is required to determine that the magnitude each\nC component of the vectors is within the appropriate range so as\nC not to cause floating point overflow.\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC W.M. Owen (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.3, 23-APR-2010 (NJB)\nC\nC Header correction: assertions that the output\nC can overwrite the input have been removed.\nC\nC- SPICELIB Version 1.0.2, 07-NOV-2003 (EDW)\nC\nC Corrected a mistake in the second example's value\nC for VOUT, i.e. replaced (1D24, 2D23, 0.0) with\nC (1D24, 2D23).\nC\nC- SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)\nC\nC Comment section for permuted index source lines was added\nC following the header.\nC\nC- SPICELIB Version 1.0.0, 31-JAN-1990 (WMO)\nC\nC-&\n \nC$ Index_Entries\nC\nC n-dimensional vector addition\nC\nC-&\n \n INTEGER I\nC\n DO I = 1, NDIM\n VOUT(I) = V1(I) + V2(I)\n END DO\n \n RETURN\n END\n", "meta": {"hexsha": "34cdb743971521a82683f0b34bbac4158469477b", "size": 4086, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/vaddg.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/vaddg.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/vaddg.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.4228187919, "max_line_length": 72, "alphanum_fraction": 0.6341164953, "num_tokens": 1250, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971871, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6972017560613428}} {"text": "PROGRAM main\nUSE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY : DFP=>real64, I4B=>int32\nUSE AutoDiff_Module\nIMPLICIT NONE\n\n\nPROCEDURE( func ), POINTER :: f => NULL()\nf => func\n\nWRITE( *, * ) Derivative( f=f, x=1.0_DFP )\n\n\nCONTAINS\n PURE FUNCTION func( x ) RESULT( Ans )\n REAL( DFP ), INTENT( IN ) :: x\n REAL( DFP ) :: Ans\n Ans = x**2\n END FUNCTION func\nEND PROGRAM main", "meta": {"hexsha": "0aaa1aae02deb050b408966ad66772da64d7b118", "size": 371, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "pass_func_to_subroutine/test.f90", "max_stars_repo_name": "vickysharma0812/modernFortran", "max_stars_repo_head_hexsha": "54c1ea61e9269f4679462e113f65a7ad383923a9", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "pass_func_to_subroutine/test.f90", "max_issues_repo_name": "vickysharma0812/modernFortran", "max_issues_repo_head_hexsha": "54c1ea61e9269f4679462e113f65a7ad383923a9", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "pass_func_to_subroutine/test.f90", "max_forks_repo_name": "vickysharma0812/modernFortran", "max_forks_repo_head_hexsha": "54c1ea61e9269f4679462e113f65a7ad383923a9", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.5263157895, "max_line_length": 65, "alphanum_fraction": 0.6388140162, "num_tokens": 125, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942067038785, "lm_q2_score": 0.7718434873426302, "lm_q1q2_score": 0.6972017505987163}} {"text": "!===== Subroutine for generating a flatted vector for the \n!===== two mass triangle topology, here P1^2 ne 0 and P2^2=0 \n subroutine gen_kflat_2mtri(p,n,P1,P2,za,zb) \n implicit none \n include 'constants.f' \n include 'zprods_decl.f' \n include 'utoolscc.f' \n integer n,nu \n double precision p(mxpart,4),P1(4),P2(4) \n double precision po(mxpart,4) \n double precision P1sq,P1dP2\n\n po(:,:)=p(:,:) \n P1sq=P1(4)**2-P1(3)**2-P1(2)**2-P1(1)**2\n \n P1dP2=2d0*(P1(4)*P2(4)-P1(3)*P2(3)-P1(2)*P2(2)-P1(1)*P2(1))\n\n do nu=1,4\n po(n+1,nu)=P1(nu)-P1sq/P1dP2*P2(nu) \n enddo\n if (utoolscc) then\n call spinoruorz(n+1,po,zb,za) \n else \n call spinoruorz(n+1,po,za,zb) \n endif\n \n return \n end\n \n \n\n!===== Subroutine for generating a flatted vector for the \n!===== three mass triangle topology, here P1^2 ne 0 and P2^2 ne 0 \n!===== also return gamma (with the positive sign)\n subroutine gen_kflat_3mtri(p,n,P1,P2,za,zb,gamma) \n implicit none \n include 'constants.f' \n include 'zprods_decl.f' \n include 'utoolscc.f' \n integer n,nu \n double precision p(mxpart,4),P1(4),P2(4) \n double precision po(mxpart,4) \n double precision P1sq,P1dP2,P2sq,gamma\n\n po(:,:)=p(:,:) \n P1sq=P1(4)**2-P1(3)**2-P1(2)**2-P1(1)**2\n P2sq=P2(4)**2-P2(3)**2-P2(2)**2-P2(1)**2\n \n P1dP2=(P1(4)*P2(4)-P1(3)*P2(3)-P1(2)*P2(2)-P1(1)*P2(1))\n\n gamma=P1dP2+dsqrt(P1dP2**2-P1sq*P2sq)\n\n do nu=1,4\n po(n+1,nu)=P1(nu)-P1sq/gamma*P2(nu) \n po(n+1,nu)=po(n+1,nu)/(one-P1sq*P2sq/gamma**2) \n po(n+2,nu)=P2(nu)-P2sq/gamma*P1(nu) \n po(n+2,nu)=po(n+2,nu)/(one-P1sq*P2sq/gamma**2) \n enddo\n if (utoolscc) then\n call spinoruorz(n+2,po,zb,za) \n else \n call spinoruorz(n+2,po,za,zb) \n endif\n \n \n return \n end\n \n \n", "meta": {"hexsha": "3979e847f35ee325357a8f1620648e9c02e7879b", "size": 1965, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "MCFM-JHUGen/src/UTools/gen_kflat_spins.f", "max_stars_repo_name": "tmartini/JHUGen", "max_stars_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-06-08T13:09:28.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-04T19:59:36.000Z", "max_issues_repo_path": "MCFM-JHUGen/src/UTools/gen_kflat_spins.f", "max_issues_repo_name": "tmartini/JHUGen", "max_issues_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 64, "max_issues_repo_issues_event_min_datetime": "2015-06-24T15:08:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-25T04:59:32.000Z", "max_forks_repo_path": "MCFM-JHUGen/src/UTools/gen_kflat_spins.f", "max_forks_repo_name": "tmartini/JHUGen", "max_forks_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2015-05-04T22:15:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-06T10:04:40.000Z", "avg_line_length": 28.0714285714, "max_line_length": 67, "alphanum_fraction": 0.5328244275, "num_tokens": 788, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951698485603, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6971886763982862}} {"text": "\n\n subroutine small_strain_elastic_lamina2D(matData,F,stre,cc)\n\n implicit none\n\n integer i, j\n\n double precision matData(*), F(2,*), stre(*), cc(4,*),\n * E1, E2, nu12, nu21, G12, alpha, eps(3), fact,\n * Q11, Q22, Q12, Q66, m, m2, m4, n, n2, n4, m2n2,\n * m3n, mn3, Qxx, Qyy, Qxy, Qxs, Qys, Qss,\n * r1d2, r1, r2, r4\n\n data r1d2, r1, r2, r4 / 0.5d0, 1.d0, 2.d0, 4.d0 /\n\n E1 = matData(1)\n E2 = matData(2)\n nu12 = matData(3)\n nu21 = E2 / E1 * nu12\n G12 = matData(5)\n alpha = matData(6) * acos(-r1) / 180.d0\n\nc strain tensor\n\n eps(1) = F(1,1) - r1\n eps(2) = F(2,2) - r1\n eps(3) = r1d2 * (F(1,2) + F(2,1))\n\nc tangent tensor\n\n fact = r1 / (r1 - nu12*nu21)\n\n Q11 = fact * E1\n Q22 = fact * E2\n Q12 = nu21 * Q11\n Q66 = G12\n\n m = cos(alpha)\n n = sin(alpha)\n\n m2 = m * m\n m4 = m2 * m2\n n2 = n * n\n n4 = n2 * n2\n m2n2 = m2 * n2\n mn3 = m * n * n2\n m3n = m * n * m2\n\n Qxx = m4 * Q11 + n4 * Q22 + (m2n2+m2n2) * Q12 + r4*m2n2 * Q66\n Qyy = n4 * Q11 + m4 * Q22 + (m2n2+m2n2) * Q12 + r4*m2n2 * Q66\n Qxy = m2n2 * (Q11 + Q22) + (m4 + n4) * Q12 - r4*m2n2 * Q66\n Qxs = m3n * Q11 - mn3 * Q22 + (mn3-m3n) * (Q12 + Q66 + Q66)\n Qys = mn3 * Q11 - m3n * Q22 + (m3n-mn3) * (Q12 + Q66 + Q66)\n Qss = m2n2 * (Q11 + Q22 - Q12 - Q12) + (m4-m2n2-m2n2+n4) * Q66\n\n cc(1,1) = Qxx\n cc(1,2) = Qxy\n cc(1,3) = Qxs\n cc(2,1) = Qxy\n cc(2,2) = Qyy\n cc(2,3) = Qys\n cc(3,1) = Qxs\n cc(3,2) = Qys\n cc(3,3) = Qss\n\nc stress\n\n stre(1) = cc(1,1)*eps(1) + cc(1,2)*eps(2) + r2*cc(1,3)*eps(3)\n stre(2) = cc(2,1)*eps(1) + cc(2,2)*eps(2) + r2*cc(2,3)*eps(3)\n stre(3) = cc(3,1)*eps(1) + cc(3,2)*eps(2) + r2*cc(3,3)*eps(3)\n\n return\n\n end\n\n\n\n\n\n\n", "meta": {"hexsha": "5f8189bafb844eeacd62c8f8d8c7cec6511b6797", "size": 1957, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/material/small_strain_elastic_lamina2D.for", "max_stars_repo_name": "chennachaos/mpap", "max_stars_repo_head_hexsha": "99d02bc9075b72b899a167d1bbc2bf73584b85bc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-12-30T16:45:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-29T23:27:29.000Z", "max_issues_repo_path": "src/material/small_strain_elastic_lamina2D.for", "max_issues_repo_name": "chennachaos/mpap", "max_issues_repo_head_hexsha": "99d02bc9075b72b899a167d1bbc2bf73584b85bc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2019-11-22T12:57:55.000Z", "max_issues_repo_issues_event_max_datetime": "2020-11-04T22:01:42.000Z", "max_forks_repo_path": "src/material/small_strain_elastic_lamina2D.for", "max_forks_repo_name": "chennachaos/mpap", "max_forks_repo_head_hexsha": "99d02bc9075b72b899a167d1bbc2bf73584b85bc", "max_forks_repo_licenses": ["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.8658536585, "max_line_length": 70, "alphanum_fraction": 0.4236075626, "num_tokens": 951, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240194661944, "lm_q2_score": 0.7431680086124812, "lm_q1q2_score": 0.6971837593782283}} {"text": "SUBROUTINE glob_to_axial(axial,global,coord)\n!\n! This subroutine transforms the global end reactions\n! into an axial force for rod elements (2- or 3-d).\n!\n IMPLICIT NONE\n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\n REAL(iwp),INTENT(IN)::global(:),coord(:,:)\n REAL(iwp),INTENT(OUT)::axial\n REAL(iwp)::add,ell,zero=0.0_iwp\n INTEGER::ndim,i\n ndim=UBOUND(coord,2)\n add=zero\n DO i=1,ndim\n add=add+(coord(2,i)-coord(1,i))**2\n END DO\n ell=SQRT(add)\n axial=zero\n DO i=1,ndim\n axial=axial+(coord(2,i)-coord(1,i))/ell*global(ndim+i)\n END DO\nRETURN\nEND SUBROUTINE glob_to_axial \n", "meta": {"hexsha": "ab555f5025a91a7c1d833211b85281d1c4293071", "size": 597, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "main/glob_to_axial.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/glob_to_axial.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/glob_to_axial.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": 24.875, "max_line_length": 57, "alphanum_fraction": 0.6884422111, "num_tokens": 204, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9496693659780477, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.6971708256634013}} {"text": "! File: spanlib.f90\n!\n! This file is part of the SpanLib library.\n! Copyright (C) 2006 Stephane Raynaud\n! Contact: stephane dot raynaud at gmail dot com\n!\n! This library is free software; you can redistribute it and/or\n! modify it under the terms of the GNU Lesser General Public\n! License as published by the Free Software Foundation; either\n! version 2.1 of the License, or (at your option) any later version.\n\n! This library is distributed in the hope that it will be useful,\n! but WITHOUT ANY WARRANTY; without even the implied warranty of\n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n! Lesser General Public License for more details.\n!\n! You should have received a copy of the GNU Lesser General Public\n! License along with this library; if not, write to the Free Software\n! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n\nmodule spanlib\n\n!\tinterface spanlib_interface\n!\t\tmodule procedure sl_pca, sl_pcarec, sl_mssa, sl_mssarec, sl_phasecomp, sl_diasym\n!\tend interface\n\n\ncontains\n\n\t! ############################################################\n\t! ############################################################\n\t! ## PCA PART ################################################\n\t! ############################################################\n\t! ############################################################\n\n\tsubroutine sl_pca(ff, nkeep, xeof, pc, ev, weights, useteof)\n\n\t! Title:\n\t!\tPrincipal Component Analysis\n\t!\n\t! Description:\n\t!\tPerform a decomposition of space-time field in a set of\n\t!\tEmpirical Orthogonal Functions (EOFs) and Principal components (PCs).\n\t!\tThe input data set can be optionally weighted in space.\n\t!\tBy default, the analysis computes \"temporal\" (T) or classical\n\t!\tspatial (S) EOFs depending on if the space dimension is greater\n\t!\tthan the time dimension. This default behavior can be overridden.\n\t!\n\t! Necessary arguments:\n\t!\t- ff:\t\t\tSpace-time array\n\t!\n\t! Optional arguments:\n\t!\t- nkeep:\t\tMaximum number of modes to keep in outputs\n\t!\t- xeof:\t\tSpace-mode array of EOFs\n\t!\t- pc:\t\t\tTime-mode array of PCs\n\t!\t- ev:\t\t\tMode array of eigen values (variances)\n\t!\t- weights:\tSpace array of weights\n\t!\t- useteof:\tTo force the use of T or S EOFs [0 = T, 1 = S, -1 = default]\n\t!\n\t! Dependencies:\n\t!\tsl_diasym\n\n\n\t! Declarations\n\t! ============\n\n\timplicit none\n\n\t! External\n\t! --------\n\treal, intent(in) :: ff(:,:)\n\tinteger, intent(in),\toptional :: nkeep\n\treal, intent(out),optional, allocatable :: pc(:,:), xeof(:,:), ev(:)\n\treal, intent(in),\toptional :: weights(:)\n\tinteger, intent(in),\toptional :: useteof\n\n\t! Internal\n\t! --------\n\tinteger :: ii,ij,nn,ns,nt\n\treal, allocatable :: cov(:,:)\n\treal, allocatable :: wff(:,:), ww(:), zeof(:,:), zff(:,:)\n\treal, allocatable :: eig(:)\n\tinteger :: zuseteof = -1, znkeep, znkeepmax=100, i,j\n\n\t! Setups\n\t! ======\n\n\t! Sizes\n\t! -----\n\tns=size(ff,1)\n\tnt=size(ff,2)\n\tif(present(nkeep))then\n\t\tznkeep = nkeep\n\telse\n\t\tznkeep = minval(ubound(ff))\n\tend if\n\tif(znkeep>50)then\n\t\tprint*,'[pca] You want to keep a nomber of PCs greater than 50!'\n\t\treturn\n\tend if\n\tif(not(present(xeof)).and.not(present(pc)).and.not(present(ev)))then\n\t\tprint*,'[pca] Nothing to do. Quit.'\n\t\treturn\n\tend if\n\n\t! By default, T-EOF decompostion if ns > nt\n\t! -----------------------------------------\n\tif(present(useteof))zuseteof = useteof\n\tif(zuseteof.ne.0.and.zuseteof.ne.1)then\n\t\tif(ns>nt)then\n\t\t\tzuseteof=1\n\t\telse\n\t\t\tzuseteof=0\n\t\tendif\n\tendif\n\n\t! Remove the mean\n\t! ---------------\n\tallocate(zff(ns,nt))\n\tzff = ff - spread(sum(ff,dim=2)/real(nt), ncopies=nt, dim=2)\n\n\t! Default weights = 1.\n\t! --------------------\n\tallocate(ww(ns))\n\tallocate(wff(ns,nt))\n\tww = 1.\n\tif(present(weights))then\n\t\tww(:) = weights * real(ns) / sum(weights)\n\t\twhere(ww==0.)\n\t\t\tww = 1.\n\t\tend where\n\t\tdo i = 1, nt\n\t\t\twff(:,i) = zff(:,i) * sqrt(ww)\n\t\tend do\n\telse\n\t\twff = zff\n\tend if\n\n\n\t! EOF decomposition\n\t! =================\n\n\tif(zuseteof==1)then\n\n\n\t\t! T-EOF case\n\t\t! ----------\n\n\t\t! Covariance\n\t\tallocate(cov(nt,nt))\n\t\tallocate(eig(nt))\n\t\tdo i=1,nt\n\t\t\tdo j=1,i\n\t\t\t\tcov(i,j) = dot_product(wff(:,i),wff(:,j))\n\t\t\t\tcov(j,i) = cov(i,j)\n\t\t\tend do\n\t\tend do\n\t\tcov = cov / float(ns)\n\t\tdeallocate(wff)\n\n\t\t! Diagonalising (cov: input=cov, output=eof)\n\t\tcall sl_diasym(cov,eig)\n\n\t\t! Back to S-EOFs\n\t\tif(present(pc).or.present(xeof))then\n\t\t\tallocate(zeof(ns,nkeep))\n\t\t\tzeof = matmul(zff, cov(:,nt:nt-nkeep+1:-1))\n\t\t\tdeallocate(cov)\n\t\t\tdo i = 1, nkeep\n\t\t\t\tzeof(:,i) = zeof(:,i) / sqrt(dot_product(ww(:), zeof(:,i)**2))\n\t\t\tend do\n\t\t\tif(not(present(pc)))then\n\t\t\t\tdeallocate(ww)\n\t\t\tend if\n\t\telse\n\t\t\tdeallocate(cov)\n\t\tend if\n\n\t\t! Eigenvalues\n\t\t! -----------\n\t\tif(present(ev))then\n\t\t\tif(not(allocated(ev))) allocate(ev(nkeep))\n\t\t\tev = eig(nt:nt-nkeep+1:-1)\n\t\tend if\n\n\telse\n\n\t\t! S-EOF case (classical)\n\t\t! ----------------------\n\n\t\t! Covariance\n\t\tallocate(cov(ns,ns))\n\t\tallocate(eig(ns))\n\t\tdo i=1,ns\n\t\t\tdo j=1,i\n\t\t\t\tcov(i,j) = dot_product(wff(i,:), wff(j,:))\n\t\t\t\tcov(j,i) = cov(i,j)\n\t\t\tend do\n\t\tend do\n\t\tcov = cov / float(nt)\n\t\tdeallocate(wff)\n\n\t\t! Diagonalisation (cov: input=cov, output=eof)\n\t\tcall sl_diasym(cov,eig)\n\n\t\t! Formatting S-EOFs\n\t\tif(present(xeof).or.present(pc))then\n\t\t\tallocate(zeof(ns,nkeep))\n\t\t\tdo i = 1, nkeep\n!\t\t\t\tzeof(:,i) = cov(:,ns:ns-nkeep+1:-1) / sqrt(ww(:,1:nkeep))\n\t\t\t\tzeof(:,i) = cov(:,ns-i+1) / sqrt(ww(:))\n\t\t\tend do\n\t\tend if\n\t deallocate(cov)\n\n\t\t! Eigenvalues\n\t\t! -----------\n\t\tif(present(ev))then\n\t\t\tif(not(allocated(ev))) allocate(ev(nkeep))\n\t\t\tev = eig(ns:ns-nkeep+1:-1)\n\t\tend if\n\n\tend if\n\n\t! Free eof array\n\t! --------------\n\tif(present(xeof))then\n\t\tif(not(allocated(xeof))) allocate(xeof(ns,nkeep))\n\t\txeof = zeof\n\t\tif(not(present(pc))) deallocate(zeof)\n\tend if\n\n\t! Finally get PCs\n\t! ===============\n\tif(present(pc))then\n\t\tif(not(allocated(pc))) allocate(pc(nt,nkeep))\n\t\tif(present(weights))then\n\t\t\tdo i=1, nt\n\t\t\t\tzff(:,i) = zff(:,i) * ww(:)\n\t\t\tend do\n\t\tend if\n\t\tpc = matmul( transpose(zff), zeof)\n\t\tdo i = 1, nkeep\n\t\t\tpc(:,i) = pc(:,i) / dot_product(zeof(:,i)**2, ww(:))\n\t\tend do\n\tend if\n\n\tend subroutine sl_pca\n\n\n\n\tsubroutine sl_pcarec(xeof, pc, ffrec, istart, iend)\n\n\t! Title:\n\t!\tReconstruction of a set of PCA components\n\t!\n\t! Description:\n\t!\tPerform a reconstruction using a set of components previously\n\t!\tcomputed with a PCA. All the reconstructed components are summed.\n\t!\tA reconstructed component is simply the \"product\" of an EOF\n\t!\tby its PC. The sum of all reconstructed component is the original field.\n\t!\n\t! Necessary arguments:\n\t!\t- xeof:\t\tSpace-mode array of EOFs\n\t!\t- pc:\t\tTime-mode array of PCs\n\t!\t- ffrec:\tSpace-time array of the reconstructed field\n\t!\n\t! Optional arguments:\n\t!\t- istart:\tIndex of the first component to use\n\t!\t- iend:\t\tIndex of the last component to use\n\n\timplicit none\n\n\n\t! Declarations\n\t! ============\n\n\t! External\n\t! --------\n\treal,\tintent(in)\t\t\t\t:: xeof(:,:), pc(:,:)\n\treal,\tintent(out),allocatable\t:: ffrec(:,:)\n\tinteger,intent(in),\toptional\t:: istart, iend\n\n\t! Internal\n\t! --------\n\tinteger \t\t\t\t:: nkept, itmp, zistart=1, ziend, nt, ns, i\n\treal, allocatable\t:: zpc(:,:)\n\n\n\t! Setup\n\t! =====\n\tnkept = size(xeof,2)\n\tif(present(istart))zistart=istart\n\tif(present(iend))then\n\t\tziend=iend\n\telse\n\t\tziend=nkept\n\tend if\n\tif(zistart.lt.1.or.zistart.gt.nkept)then\n\t\tzistart=1\n\t\tprint*,'[pcarec] istart lower than 1 => set to 1'\n\tend if\n\tif(ziend.lt.1.or.ziend.gt.nkept)then\n\t\tziend=nkept\n\t\tprint*,'[pcarec] iend greater than the number of avalaible modes => reduced to',iend\n\tend if\n\tif(zistart>ziend)then\n\t\titmp=ziend\n\t\tziend=zistart\n\t\tzistart=itmp\n\t\tprint*,'[pcarec] istart > iend => inversion'\n\tend if\n\tns = size(xeof,1)\n\tnt = size(pc,1)\n\n\n\t! Computation\n\t! ===========\n\tif(not(allocated(ffrec)))allocate(ffrec(ns, nt))\n\tffrec = 0.\n\tif(nt set to 1'\n\tend if\n\tif(ziend.lt.1.or.ziend.gt.nkept)then\n\t\tziend = nkept\n\t\tprint*,'[mssarec] iend greater than the number of avalaible modes => reduced to',iend\n\tend if\n\tif(zistart>ziend)then\n\t\titmp = ziend\n\t\tziend = zistart\n\t\tzistart = itmp\n\t\tprint*,'[mssarec] istart > iend => inversion'\n\tend if\n\n\t! Computation\n\t! ===========\n\tdo im = zistart, ziend ! sum over the selection of modes\n\n\t\t! (ntpc-nwindow+1) length slices\n\t\tdo iw = 1, nwindow\n\t\t\tepc(iw,:) = stpc(iw : iw+ntpc-nwindow, im)\n\t\tend do\n\n\t\tdo ic = 1, nchan ! sum over the channels (= space or PCs from simple PCA)\n\n\t\t\t! reversed eof\n\t\t\treof = steof(nwindow+(ic-1)*nwindow : 1+(ic-1)*nwindow : -1, im)\n\n\t\t\t! * middle * [nwindow length projections]\n\t\t\tffrec(ic, nwindow : ntpc) = ffrec(ic, nwindow : ntpc) + &\n\t\t\t\t& matmul(reof, epc) / real(nwindow)\n\n\t\t do iw = 1, nwindow-1\n\n\t\t\t ! * beginning * [iw length projections]\n\t\t\t ffrec(ic, iw) = ffrec(ic, iw) + &\n\t\t\t\t & dot_product( reof(nwindow-iw+1:nwindow), stpc(1\t\t:iw, im) ) / real(iw)\n!\n\t\t\t ! * end * [iw length projections]\n\t\t\t ffrec(ic, nt-iw+1) = ffrec(ic, nt-iw+1) + &\n\t\t\t\t & dot_product( reof(1\t\t :iw),\t stpc(ntpc-iw+1:ntpc, im) ) / real(iw)\n\n\t\t\tend do\n\n\t\tend do\n\n\tend do\n\n\tend subroutine sl_mssarec\n\n\n\n ! ############################################################\n ! ############################################################\n ! ## TOOLS PART ##############################################\n ! ############################################################\n ! ############################################################\n\n\tsubroutine sl_phasecomp(ffrec, np, phases, weights, offset, firstphase)\n\n\t! Title:\n\t!\tPhase composites\n\t!\n\t! Description:\n\t!\tPerforms phase composites of S-T oscillatory field.\n\t!\tThis field is typically a reconstructed pair of MSSA modes.\n\t!\tComposites are evaluated according to an index defined by the\n\t!\tfirst PC of the input field and its derivative.\n\t!\tSpace weights can be optionally used to compute the PC.\n\t!\tA minimal normalized amplitude can be also used: when the\n\t!\tindex is under value, data are not used to compute phases.\n\t!\tIt is also possible so specify the angle of the first phase\n\t!\tin the 360 degrees phase diagram circle: zero means the\n\t!\tthe first phase conincides with the maximmum.\n\t!\n\t!\n\t! Necessary arguments:\n\t!\t- ffrec: Space-time array\n\t!\t- np: Number of requested phases over the 360 degrees cycle (default = 8)\n\t!\n\t! Optional arguments:\n\t!\t- weights: Space array of weights\n\t!\t- offset: Minimal normalized amplitude of the index (default = 0.)\n\t!\t- firstphase: Value in degrees of the first phase (default = 0)\n\t!\n\t! Dependencies:\n\t!\tsl_pca\n\n\n\timplicit none\n\n\t! Declarations\n\t! ============\n\n\t! External\n\t! --------\n\tinteger, intent(in)\t:: np\n\treal,\tintent(in) :: ffrec(:,:)\n\treal,\tintent(in), optional :: weights(:)\n\treal,\tintent(in), optional :: offset, firstphase\n\treal,\tintent(out), allocatable :: phases(:, :)\n\n\t! Internal\n\t! --------\n\treal, allocatable :: xeof(:,:), pc(:,:)\n\treal :: dpc(size(ffrec,2)), amp(size(ffrec,2))\n\tinteger :: nt, iphase\n\treal :: angles(np), projection(size(ffrec,2))\n\treal :: pi, deltarad, pcos, psin, zoffset, zfirstphase\n\tlogical :: select_amplitude(size(ffrec,2)), select_phase(size(ffrec,2))\n\tinteger :: itime(size(ffrec,2)), nsel, i, ns\n\tinteger, allocatable :: isel(:)\n\n\n\t! Setup\n\t! =====\n\tnt = size(ffrec,2)\n\tpi = acos(-1.)\n\titime = (/ (i, i=1, nt) /)\n\tns = size(ffrec, 1)\n\tif(present(offset))then\n\t\tzoffset=offset\n\telse\n\t\tzoffset=0.\n\tend if\n\n\t! Find the first PC and its derivative\n\t! ====================================\n\tcall sl_pca(ffrec, 1, pc=pc, weights=weights)\n\tpc = pc * sqrt(real(nt)/sum(pc**2))\n\tdpc = 0.5 * (eoshift(pc(:,1), 1, pc(nt,1)) - eoshift(pc(:,1), -1, pc(1,1)))\n\tdpc((/1,nt/)) = dpc((/1,nt/)) * 2.\n\tdpc = dpc * sqrt(real(nt)/sum(dpc**2))\n\tamp = sqrt(pc(:,1)**2 + dpc**2)\n\n\n\t! Compute the maps\n\t! ================\n\n\t! Define the marks\n\t! ----------------\n\tdeltarad = 2 * pi / real(np)\n\tif(present(firstphase))then\n\t\tzfirstphase = modulo(firstphase * 2 * pi / 360., 2 * pi)\n\telse\n\t zfirstphase = 0.\n\tend if\n\tangles = (/ (real(iphase), iphase=0,np-1) /) * deltarad + zfirstphase\n\n\t! Compute the phase maps\n\t! ----------------------\n\tif(not(allocated(phases))) allocate(phases(ns, np))\n\tphases = 0.\n\tselect_amplitude = amp >= zoffset\n\tdo iphase = 1, np\n\t\tpcos = cos(angles(iphase))\n\t\tpsin = sin(angles(iphase))\n\t\tprojection = (pc(:,1)*pcos+dpc*psin) / amp\n\t\tselect_phase = ( projection >= cos(0.5*deltarad) ) .and. select_amplitude\n\t\tif(any(select_phase))then\n\t\t\tnsel = count(select_phase)\n\t\t\tallocate(isel(nsel))\n\t\t\tisel = pack(itime, select_phase)\n\t\t\tphases(:,iphase) = sum(ffrec(:,isel), dim=2) / real(nsel)\n\t\t\tdeallocate(isel)\n\t\tend if\n\tend do\n\n\tend subroutine sl_phasecomp\n\n\n\n subroutine sl_diasym(a,eig)\n\n\t! Title:\n\t!\tDiagonalisation of a symetric matrix\n\t!\n\t! Description:\n\t!\tA simple interface to the ssyev diagonalisation subroutine from LAPACK.\n\t!\n\t! Necessary arguments:\n\t!\t- a:\t\tInput = symetric matrix, output = EOFs\n\t!\t- eig:\tEigen values\n\t!\n\t! Dependencies:\n\t!\tssyev(LAPACK)\n\n\timplicit none\n\n\t! Declaratiions\n\t! =============\n\n\t! External\n\t! --------\n\treal, intent(inout) \t\t\t:: a(:,:)\n\treal, intent(out), allocatable\t:: eig(:)\n\n\t! Internal\n\t! --------\n\tinteger :: n,lwork,inf\n\treal, allocatable :: work(:)\n\n\t! Sizes\n\t! -----\n\n\t! Data set\n\tn=size(a,1)\n\tallocate(eig(n))\n\n\t! Working array [other values of lwork: (N+2)*N, n*(3+n/2)]\n\tlwork=1+ 6*N + 2*N**2\n\tallocate(work(lwork))\n\n\t! Diagonalisation\n\t! ---------------\n\tcall ssyev('V','U',n,a,n,eig,work,lwork,inf)\n\n\tend subroutine sl_diasym\n\nend module spanlib\n", "meta": {"hexsha": "3bebb64cac4dbf5ab21652625f037a7c08346adb", "size": 18357, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "contrib/spanlib/src/spanlib.ifort.f90", "max_stars_repo_name": "xylar/cdat", "max_stars_repo_head_hexsha": "8a5080cb18febfde365efc96147e25f51494a2bf", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 62, "max_stars_repo_stars_event_min_datetime": "2018-03-30T15:46:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-08T23:30:24.000Z", "max_issues_repo_path": "contrib/spanlib/src/spanlib.ifort.f90", "max_issues_repo_name": "xylar/cdat", "max_issues_repo_head_hexsha": "8a5080cb18febfde365efc96147e25f51494a2bf", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 114, "max_issues_repo_issues_event_min_datetime": "2018-03-21T01:12:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-05T12:29:54.000Z", "max_forks_repo_path": "contrib/spanlib/src/spanlib.ifort.f90", "max_forks_repo_name": "CDAT/uvcdat", "max_forks_repo_head_hexsha": "5133560c0c049b5c93ee321ba0af494253b44f91", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2018-06-06T02:42:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-26T03:27:00.000Z", "avg_line_length": 24.3461538462, "max_line_length": 87, "alphanum_fraction": 0.586806123, "num_tokens": 6033, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972684083609, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.6970802740017056}} {"text": "cc Copyright (C) 2004-2009: Leslie Greengard and June-Yub Lee\ncc Contact: greengard@cims.nyu.edu\ncc\ncc This software is being released under a FreeBSD license\ncc (see license.txt in this directory).\nc\n program testfft\nC USE NUFFTModule\n implicit none\nc\nc --- local variables\nc\n integer i,ier,iflag,j,k1,mx,ms,nj\n parameter (mx=10 000)\n real*4 xj(mx), sk(mx)\n real*4 eps,pi\n real*8 err\n parameter (pi=3.141592653589793238462643383279502884197e0)\n complex*8 cj(mx),cj0(mx),cj1(mx)\n complex*8 fk0(mx),fk1(mx)\nc\nc --------------------------------------------------\nc create some test data\nc --------------------------------------------------\n ms = 90\n nj = 128\n do k1 = -nj/2, (nj-1)/2\n j = k1+nj/2+1\n xj(j) = pi * cos(-pi*j/nj)\n cj(j) = cmplx( sin(pi*j/nj), cos(pi*j/nj))\nc print*,xj(j),cj(j)\n enddo\nc\nc --------------------------------------------------\nc start tests\nc --------------------------------------------------\nc\n\n\t\tcall nufft_ffte(1)\n\n iflag = 1\n print*,' Start 1D testing: ', ' nj =',nj, ' ms =',ms\n do i = 1,5\n if (i.eq.1) eps=1e-3\n if (i.eq.2) eps=1e-4\n if (i.eq.3) eps=1e-5\n if (i.eq.4) eps=1e-6\n if (i.eq.5) eps=1e-7\nc extended/quad precision tests\nc if (i.eq.5) eps=1d-20\nc if (i.eq.6) eps=1d-24\nc if (i.eq.7) eps=1d-28\nc if (i.eq.8) eps=1d-32\n\t print*,' '\n \t print*,' Requested precision eps =',eps\n\t print*,' '\nc\nc -----------------------\nc call 1D Type1 method\nc -----------------------\nc\n\t\tiflag = -1\n call dirft1d1f(nj,xj,cj,iflag, ms,fk0)\n call nufft1d1ff90_ffte(nj,xj,cj,iflag,eps, ms,fk1,ier)\n call errcompf(fk0,fk1,ms,err)\n print *,' ier = ',ier\n print *,' type 1 error = ',err\nc\nc -----------------------\nc call 1D Type2 method\nc -----------------------\nc\n call dirft1d2f(nj,xj,cj0,iflag, ms,fk0,ier)\n call nufft1d2ff90_ffte(nj,xj,cj1,iflag, eps, ms,fk0,ier)\n call errcompf(cj0,cj1,nj,err)\n print *,' ier = ',ier\n print *,' type 2 error = ',err\nc\nc -----------------------\nc call 1D Type3 method\nc -----------------------\n do k1 = 1, ms\n sk(k1) = 48*cos(k1*pi/ms)\n enddo\n call dirft1d3f(nj,xj,cj,iflag, ms,sk,fk0)\n call nufft1d3ff90_ffte(nj,xj,cj,iflag,eps, ms,sk,fk1,ier)\n call errcompf(cj0,cj1,nj,err)\n print *,' ier = ',ier\n print *,' type 3 error = ',err\n enddo\n stop\n end\nc\nc\nc\nc\nc\n subroutine errcompf(fk0,fk1,n,err)\n implicit none\n integer k,n\n complex*8 fk0(n), fk1(n)\n real *8 salg,ealg,err\nc\n ealg = 0e0\n salg = 0e0\n\n do k = 1, n\n ealg = ealg + REAL(cabs(fk1(k)-fk0(k)))**2\n salg = salg + REAL(cabs(fk0(k)))**2\nC print *,fk1(k),fk0(k)\n enddo\nC print *,'ealg,salg:',ealg,salg\n err =sqrt(ealg/salg)\n return\n end\n", "meta": {"hexsha": "5a6048d6b101399c02fd6fadac2ff915612be399", "size": 3051, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/TESTING/nufft1d_demof90f-ffte.f", "max_stars_repo_name": "biotrump/nufft", "max_stars_repo_head_hexsha": "499cecd77eefd2255e3e52cc67413b4688b12916", "max_stars_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2016-03-17T17:44:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-10T12:29:10.000Z", "max_issues_repo_path": "src/TESTING/nufft1d_demof90f-ffte.f", "max_issues_repo_name": "biotrump/nufft", "max_issues_repo_head_hexsha": "499cecd77eefd2255e3e52cc67413b4688b12916", "max_issues_repo_licenses": ["BSD-2-Clause-FreeBSD"], "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/TESTING/nufft1d_demof90f-ffte.f", "max_forks_repo_name": "biotrump/nufft", "max_forks_repo_head_hexsha": "499cecd77eefd2255e3e52cc67413b4688b12916", "max_forks_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2017-07-29T02:22:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-25T07:02:47.000Z", "avg_line_length": 26.3017241379, "max_line_length": 66, "alphanum_fraction": 0.472631924, "num_tokens": 1088, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240930029117, "lm_q2_score": 0.8056321983146848, "lm_q1q2_score": 0.6970523880807651}} {"text": "program do_factorials\n implicit none\n integer, parameter :: MAX_N = 10\n integer :: i\n\n do i = 1, MAX_N\n print *, i, factorial(i)\n end do\n\ncontains\n\n function factorial(n) result(fac)\n implicit none\n integer, intent(in) :: n\n integer :: fac\n integer :: i\n\n fac = 1\n do i = 2, n\n fac = fac*i\n end do\n end function factorial\n\nend program do_factorials\n", "meta": {"hexsha": "faa318fe34d07f117412524f2fb0cfca8c2182af", "size": 437, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source_code/iterations/do_factorials.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/iterations/do_factorials.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/iterations/do_factorials.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": 17.48, "max_line_length": 37, "alphanum_fraction": 0.5446224256, "num_tokens": 117, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.6970523751865749}} {"text": "PROGRAM A4Q1\r\n!--\r\n! Finds the number of weakly increasing/decreasing sequences given an array.\r\n!--\r\nIMPLICIT NONE\r\nINTEGER, DIMENSION (:), ALLOCATABLE :: a\r\nINTEGER :: k, check\r\n \r\nPRINT *, 'Finds the number of weakly increasing/decreasing sequences given the specified array.'\r\nDO\r\n PRINT *, 'Enter the size of the array: k (or 0 to stop).'\r\n READ *, k\r\n IF (K .eq. 0) STOP\r\n IF (k .lt. 0) THEN\r\n \tPRINT *, 'k must be a positive nonzero number. Try again.'\r\n ELSE\r\n \tALLOCATE(a(k), STAT=check)\r\n IF (check .ne. 0) THEN\r\n \tPRINT \"(1X, 'Allocation unseccessful for an array of size:', I3)\", k\r\n ELSE\r\n\t\t\tPRINT \"(1X, 'enter the values of all', I3, ' elements')\", k\r\n \tREAD *, a\r\n \tPRINT \"(1X, 'accepted: ', 15I5)\", a\r\n PRINT *, 'result: ', CountSeq(a, k)\r\n DEALLOCATE(a)\r\n END IF\r\n END IF\r\nEND DO\r\n\r\nCONTAINS\r\nINTEGER FUNCTION CountSeq(a,k)\r\n INTEGER, DIMENSION (1:k), INTENT(IN) :: a \r\n\tINTEGER, INTENT(IN) :: k\r\n INTEGER :: c, i, direction\r\n ! direction:\r\n ! 1 => increasing\r\n ! -1 => decreasing\r\n \r\n direction = 0\r\n c = 0\r\n IF (k .eq. 1) THEN\r\n \tCountSeq = 0\r\n\tELSE \r\n\t\tDO i = 1,(k - 1)\r\n \t\tIF (a(i) .lt. a(i+1) .and. direction .lt. 1) THEN\r\n \t\t\tdirection = 1\r\n \t\t\tc = c + 1\r\n \t\tELSE IF (a(i) .gt. a(i+1) .and. direction .gt. -1) THEN\r\n \t\t\tdirection = -1\r\n \t\t\tc = c + 1\r\n \t\tEND IF\r\n \tEND DO \r\n END IF \r\n\tCountSeq = c\t\r\n\r\nEND FUNCTION CountSeq\r\nEND PROGRAM A4Q1", "meta": {"hexsha": "6ac5e371a7fcf06115341bebf2e8854b128c1dc3", "size": 1528, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Assignment 4/A4Q1.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 4/A4Q1.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 4/A4Q1.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.8070175439, "max_line_length": 97, "alphanum_fraction": 0.5353403141, "num_tokens": 492, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321796478255, "lm_q2_score": 0.8652240791017536, "lm_q1q2_score": 0.6970523607305283}} {"text": "c\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc . .\nc . copyright (c) 1998 by UCAR .\nc . .\nc . University Corporation for Atmospheric Research .\nc . .\nc . all rights reserved .\nc . .\nc . .\nc . SPHEREPACK3.0 .\nc . .\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc\nc\nc\nc ... file vhses.f\nc\nc this file contains code and documentation for subroutines\nc vhses and vhsesi\nc\nc ... files which must be loaded with vhses.f\nc\nc sphcom.f, hrfft.f\nc\nc \nc subroutine vhses(nlat,nlon,ityp,nt,v,w,idvw,jdvw,br,bi,cr,ci,\nc + mdab,ndab,wvhses,lvhses,work,lwork,ierror)\nc\nc subroutine vhses performs the vector spherical harmonic synthesis\nc of the arrays br, bi, cr, and ci and stores the result in the\nc arrays v and w. v(i,j) and w(i,j) are the colatitudinal \nc (measured from the north pole) and east longitudinal components\nc respectively, located at colatitude theta(i) = (i-1)*pi/(nlat-1)\nc and longitude phi(j) = (j-1)*2*pi/nlon. the spectral\nc representation of (v,w) is given below at output parameters v,w.\nc\nc input parameters\nc\nc nlat the number of colatitudes on the full sphere including the\nc poles. for example, nlat = 37 for a five degree grid.\nc nlat determines the grid increment in colatitude as\nc pi/(nlat-1). if nlat is odd the equator is located at\nc grid point i=(nlat+1)/2. if nlat is even the equator is\nc located half way between points i=nlat/2 and i=nlat/2+1.\nc nlat must be at least 3. note: on the half sphere, the\nc number of grid points in the colatitudinal direction is\nc nlat/2 if nlat is even or (nlat+1)/2 if nlat is odd.\nc\nc nlon the number of distinct londitude points. nlon determines\nc the grid increment in longitude as 2*pi/nlon. for example\nc nlon = 72 for a five degree grid. nlon must be greater\nc than zero. the axisymmetric case corresponds to nlon=1.\nc the efficiency of the computation is improved when nlon\nc is a product of small prime numbers.\nc\nc ityp = 0 no symmetries exist about the equator. the synthesis\nc is performed on the entire sphere. i.e. on the\nc arrays v(i,j),w(i,j) for i=1,...,nlat and \nc j=1,...,nlon. \nc\nc = 1 no symmetries exist about the equator. the synthesis\nc is performed on the entire sphere. i.e. on the\nc arrays v(i,j),w(i,j) for i=1,...,nlat and \nc j=1,...,nlon. the curl of (v,w) is zero. that is, \nc (d/dtheta (sin(theta) w) - dv/dphi)/sin(theta) = 0. \nc the coefficients cr and ci are zero.\nc\nc = 2 no symmetries exist about the equator. the synthesis\nc is performed on the entire sphere. i.e. on the\nc arrays v(i,j),w(i,j) for i=1,...,nlat and \nc j=1,...,nlon. the divergence of (v,w) is zero. i.e., \nc (d/dtheta (sin(theta) v) + dw/dphi)/sin(theta) = 0. \nc the coefficients br and bi are zero.\nc\nc = 3 v is symmetric and w is antisymmetric about the \nc equator. the synthesis is performed on the northern\nc hemisphere only. i.e., if nlat is odd the synthesis\nc is performed on the arrays v(i,j),w(i,j) for \nc i=1,...,(nlat+1)/2 and j=1,...,nlon. if nlat is\nc even the synthesis is performed on the the arrays\nc v(i,j),w(i,j) for i=1,...,nlat/2 and j=1,...,nlon.\nc\nc = 4 v is symmetric and w is antisymmetric about the \nc equator. the synthesis is performed on the northern\nc hemisphere only. i.e., if nlat is odd the synthesis\nc is performed on the arrays v(i,j),w(i,j) for \nc i=1,...,(nlat+1)/2 and j=1,...,nlon. if nlat is\nc even the synthesis is performed on the the arrays\nc v(i,j),w(i,j) for i=1,...,nlat/2 and j=1,...,nlon.\nc the curl of (v,w) is zero. that is, \nc (d/dtheta (sin(theta) w) - dv/dphi)/sin(theta) = 0. \nc the coefficients cr and ci are zero.\nc\nc = 5 v is symmetric and w is antisymmetric about the \nc equator. the synthesis is performed on the northern\nc hemisphere only. i.e., if nlat is odd the synthesis\nc is performed on the arrays v(i,j),w(i,j) for \nc i=1,...,(nlat+1)/2 and j=1,...,nlon. if nlat is\nc even the synthesis is performed on the the arrays\nc v(i,j),w(i,j) for i=1,...,nlat/2 and j=1,...,nlon.\nc the divergence of (v,w) is zero. i.e., \nc (d/dtheta (sin(theta) v) + dw/dphi)/sin(theta) = 0. \nc the coefficients br and bi are zero.\nc\nc = 6 v is antisymmetric and w is symmetric about the \nc equator. the synthesis is performed on the northern\nc hemisphere only. i.e., if nlat is odd the synthesis\nc is performed on the arrays v(i,j),w(i,j) for \nc i=1,...,(nlat+1)/2 and j=1,...,nlon. if nlat is\nc even the synthesis is performed on the the arrays\nc v(i,j),w(i,j) for i=1,...,nlat/2 and j=1,...,nlon.\nc\nc = 7 v is antisymmetric and w is symmetric about the \nc equator. the synthesis is performed on the northern\nc hemisphere only. i.e., if nlat is odd the synthesis\nc is performed on the arrays v(i,j),w(i,j) for \nc i=1,...,(nlat+1)/2 and j=1,...,nlon. if nlat is\nc even the synthesis is performed on the the arrays\nc v(i,j),w(i,j) for i=1,...,nlat/2 and j=1,...,nlon.\nc the curl of (v,w) is zero. that is, \nc (d/dtheta (sin(theta) w) - dv/dphi)/sin(theta) = 0. \nc the coefficients cr and ci are zero.\nc\nc = 8 v is antisymmetric and w is symmetric about the \nc equator. the synthesis is performed on the northern\nc hemisphere only. i.e., if nlat is odd the synthesis\nc is performed on the arrays v(i,j),w(i,j) for \nc i=1,...,(nlat+1)/2 and j=1,...,nlon. if nlat is\nc even the synthesis is performed on the the arrays\nc v(i,j),w(i,j) for i=1,...,nlat/2 and j=1,...,nlon.\nc the divergence of (v,w) is zero. i.e., \nc (d/dtheta (sin(theta) v) + dw/dphi)/sin(theta) = 0. \nc the coefficients br and bi are zero.\nc\nc\nc nt the number of syntheses. in the program that calls vhses,\nc the arrays v,w,br,bi,cr, and ci can be three dimensional\nc in which case multiple syntheses will be performed.\nc the third index is the synthesis index which assumes the \nc values k=1,...,nt. for a single synthesis set nt=1. the\nc discription of the remaining parameters is simplified\nc by assuming that nt=1 or that all the arrays are two\nc dimensional.\nc\nc idvw the first dimension of the arrays v,w as it appears in\nc the program that calls vhaes. if ityp .le. 2 then idvw\nc must be at least nlat. if ityp .gt. 2 and nlat is\nc even then idvw must be at least nlat/2. if ityp .gt. 2\nc and nlat is odd then idvw must be at least (nlat+1)/2.\nc\nc jdvw the second dimension of the arrays v,w as it appears in\nc the program that calls vhses. jdvw must be at least nlon.\nc\nc br,bi two or three dimensional arrays (see input parameter nt)\nc cr,ci that contain the vector spherical harmonic coefficients\nc in the spectral representation of v(i,j) and w(i,j) given\nc below at the discription of output parameters v and w.\nc\nc mdab the first dimension of the arrays br,bi,cr, and ci as it\nc appears in the program that calls vhses. mdab must be at\nc least min0(nlat,nlon/2) if nlon is even or at least\nc min0(nlat,(nlon+1)/2) if nlon is odd.\nc\nc ndab the second dimension of the arrays br,bi,cr, and ci as it\nc appears in the program that calls vhses. ndab must be at\nc least nlat.\nc\nc wvhses an array which must be initialized by subroutine vhsesi.\nc once initialized, wvhses can be used repeatedly by vhses\nc as long as nlon and nlat remain unchanged. wvhses must\nc not be altered between calls of vhses.\nc\nc lvhses the dimension of the array wvhses as it appears in the\nc program that calls vhses. define\nc\nc l1 = min0(nlat,nlon/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc and\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc then lvhses must be at least\nc\nc l1*l2*(nlat+nlat-l1+1)+nlon+15\nc\nc\nc work a work array that does not have to be saved.\nc\nc lwork the dimension of the array work as it appears in the\nc program that calls vhses. define\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc if ityp .le. 2 then lwork must be at least\nc\nc (2*nt+1)*nlat*nlon\nc\nc if ityp .gt. 2 then lwork must be at least\nc\nc (2*nt+1)*l2*nlon \nc\nc **************************************************************\nc\nc output parameters\nc\nc v,w two or three dimensional arrays (see input parameter nt)\nc in which the synthesis is stored. v is the colatitudinal\nc component and w is the east longitudinal component. \nc v(i,j),w(i,j) contain the components at colatitude\nc theta(i) = (i-1)*pi/(nlat-1) and longitude phi(j) =\nc (j-1)*2*pi/nlon. the index ranges are defined above at\nc the input parameter ityp. v and w are computed from the \nc formulas given below\nc\nc\nc define\nc\nc 1. theta is colatitude and phi is east longitude\nc\nc 2. the normalized associated legendre funnctions\nc\nc pbar(m,n,theta) = sqrt((2*n+1)*factorial(n-m)\nc /(2*factorial(n+m)))*sin(theta)**m/(2**n*\nc factorial(n)) times the (n+m)th derivative\nc of (x**2-1)**n with respect to x=cos(theta)\nc\nc 3. vbar(m,n,theta) = the derivative of pbar(m,n,theta) with\nc respect to theta divided by the square\nc root of n(n+1).\nc\nc vbar(m,n,theta) is more easily computed in the form\nc\nc vbar(m,n,theta) = (sqrt((n+m)*(n-m+1))*pbar(m-1,n,theta)\nc -sqrt((n-m)*(n+m+1))*pbar(m+1,n,theta))/(2*sqrt(n*(n+1)))\nc\nc 4. wbar(m,n,theta) = m/(sin(theta))*pbar(m,n,theta) divided\nc by the square root of n(n+1).\nc\nc wbar(m,n,theta) is more easily computed in the form\nc\nc wbar(m,n,theta) = sqrt((2n+1)/(2n-1))*(sqrt((n+m)*(n+m-1))\nc *pbar(m-1,n-1,theta)+sqrt((n-m)*(n-m-1))*pbar(m+1,n-1,theta))\nc /(2*sqrt(n*(n+1)))\nc\nc\nc the colatitudnal dependence of the normalized surface vector\nc spherical harmonics are defined by\nc\nc 5. bbar(m,n,theta) = (vbar(m,n,theta),i*wbar(m,n,theta))\nc\nc 6. cbar(m,n,theta) = (i*wbar(m,n,theta),-vbar(m,n,theta))\nc\nc\nc the coordinate to index mappings \nc\nc 7. theta(i) = (i-1)*pi/(nlat-1) and phi(j) = (j-1)*2*pi/nlon\nc\nc \nc the maximum (plus one) longitudinal wave number\nc\nc 8. mmax = min0(nlat,nlon/2) if nlon is even or\nc mmax = min0(nlat,(nlon+1)/2) if nlon is odd.\nc\nc if we further define the output vector as\nc\nc 9. h(i,j) = (v(i,j),w(i,j))\nc\nc and the complex coefficients\nc\nc 10. b(m,n) = cmplx(br(m+1,n+1),bi(m+1,n+1))\nc\nc 11. c(m,n) = cmplx(cr(m+1,n+1),ci(m+1,n+1))\nc\nc\nc then for i=1,...,nlat and j=1,...,nlon\nc\nc the expansion for real h(i,j) takes the form\nc\nc h(i,j) = the sum from n=1 to n=nlat-1 of the real part of\nc\nc .5*(b(0,n)*bbar(0,n,theta(i))+c(0,n)*cbar(0,n,theta(i)))\nc\nc plus the sum from m=1 to m=mmax-1 of the sum from n=m to \nc n=nlat-1 of the real part of\nc\nc b(m,n)*bbar(m,n,theta(i))*exp(i*m*phi(j))\nc +c(m,n)*cbar(m,n,theta(i))*exp(i*m*phi(j))\nc\nc *************************************************************\nc\nc in terms of real variables this expansion takes the form\nc\nc for i=1,...,nlat and j=1,...,nlon\nc\nc v(i,j) = the sum from n=1 to n=nlat-1 of\nc\nc .5*br(1,n+1)*vbar(0,n,theta(i))\nc\nc plus the sum from m=1 to m=mmax-1 of the sum from n=m to \nc n=nlat-1 of the real part of\nc\nc (br(m+1,n+1)*vbar(m,n,theta(i))-ci(m+1,n+1)*wbar(m,n,theta(i)))\nc *cos(m*phi(j))\nc -(bi(m+1,n+1)*vbar(m,n,theta(i))+cr(m+1,n+1)*wbar(m,n,theta(i)))\nc *sin(m*phi(j))\nc\nc and for i=1,...,nlat and j=1,...,nlon\nc\nc w(i,j) = the sum from n=1 to n=nlat-1 of\nc\nc -.5*cr(1,n+1)*vbar(0,n,theta(i))\nc\nc plus the sum from m=1 to m=mmax-1 of the sum from n=m to\nc n=nlat-1 of the real part of\nc\nc -(cr(m+1,n+1)*vbar(m,n,theta(i))+bi(m+1,n+1)*wbar(m,n,theta(i)))\nc *cos(m*phi(j))\nc +(ci(m+1,n+1)*vbar(m,n,theta(i))-br(m+1,n+1)*wbar(m,n,theta(i)))\nc *sin(m*phi(j))\nc\nc\nc br(m+1,nlat),bi(m+1,nlat),cr(m+1,nlat), and ci(m+1,nlat) are\nc assumed zero for m even.\nc\nc\nc ierror = 0 no errors\nc = 1 error in the specification of nlat\nc = 2 error in the specification of nlon\nc = 3 error in the specification of ityp\nc = 4 error in the specification of nt\nc = 5 error in the specification of idvw\nc = 6 error in the specification of jdvw\nc = 7 error in the specification of mdab\nc = 8 error in the specification of ndab\nc = 9 error in the specification of lvhses\nc = 10 error in the specification of lwork\nc\nc ************************************************************\nc\nc subroutine vhsesi(nlat,nlon,wvhses,lvhses,work,lwork,dwork,\nc + ldwork,ierror)\nc\nc subroutine vhsesi initializes the array wvhses which can then be\nc used repeatedly by subroutine vhses until nlat or nlon is changed.\nc\nc input parameters\nc\nc nlat the number of colatitudes on the full sphere including the\nc poles. for example, nlat = 37 for a five degree grid.\nc nlat determines the grid increment in colatitude as\nc pi/(nlat-1). if nlat is odd the equator is located at\nc grid point i=(nlat+1)/2. if nlat is even the equator is\nc located half way between points i=nlat/2 and i=nlat/2+1.\nc nlat must be at least 3. note: on the half sphere, the\nc number of grid points in the colatitudinal direction is\nc nlat/2 if nlat is even or (nlat+1)/2 if nlat is odd.\nc\nc nlon the number of distinct londitude points. nlon determines\nc the grid increment in longitude as 2*pi/nlon. for example\nc nlon = 72 for a five degree grid. nlon must be greater\nc than zero. the axisymmetric case corresponds to nlon=1.\nc the efficiency of the computation is improved when nlon\nc is a product of small prime numbers.\nc\nc lvhses the dimension of the array wvhses as it appears in the\nc program that calls vhses. define\nc\nc l1 = min0(nlat,nlon/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc and\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc then lvhses must be at least\nc\nc l1*l2*(nlat+nlat-l1+1)+nlon+15\nc\nc\nc work a work array that does not have to be saved.\nc\nc lwork the dimension of the array work as it appears in the\nc program that calls vhses. lwork must be at least\nc\nc 3*(max0(l1-2,0)*(nlat+nlat-l1-1))/2+5*l2*nlat\nc\nc dwork an unsaved double precision work space\nc\nc ldwork the length of the array dwork as it appears in the\nc program that calls vhsesi. ldwork must be at least\nc 2*(nlat+1)\nc\nc\nc **************************************************************\nc\nc output parameters\nc\nc wvhses an array which is initialized for use by subroutine vhses.\nc once initialized, wvhses can be used repeatedly by vhses\nc as long as nlat or nlon remain unchanged. wvhses must not\nc be altered between calls of vhses.\nc\nc\nc ierror = 0 no errors\nc = 1 error in the specification of nlat\nc = 2 error in the specification of nlon\nc = 3 error in the specification of lvhses\nc = 4 error in the specification of lwork\nc = 5 error in the specification of ldwork\nc\nc *****************************************\n subroutine vhses(nlat,nlon,ityp,nt,v,w,idvw,jdvw,br,bi,cr,ci,\n + mdab,ndab,wvhses,lvhses,work,lwork,ierror)\n dimension v(idvw,jdvw,1),w(idvw,jdvw,1),br(mdab,ndab,1),\n 1 bi(mdab,ndab,1),cr(mdab,ndab,1),ci(mdab,ndab,1),\n 2 work(1),wvhses(1)\n ierror = 1\n if(nlat .lt. 3) return\n ierror = 2\n if(nlon .lt. 1) return\n ierror = 3\n if(ityp.lt.0 .or. ityp.gt.8) return\n ierror = 4\n if(nt .lt. 0) return\n ierror = 5\n imid = (nlat+1)/2\n if((ityp.le.2 .and. idvw.lt.nlat) .or.\n 1 (ityp.gt.2 .and. idvw.lt.imid)) return\n ierror = 6\n if(jdvw .lt. nlon) return\n ierror = 7\n mmax = min0(nlat,(nlon+1)/2)\n if(mdab .lt. mmax) return\n ierror = 8\n if(ndab .lt. nlat) return\n ierror = 9\n idz = (mmax*(nlat+nlat-mmax+1))/2\n lzimn = idz*imid\n if(lvhses .lt. lzimn+lzimn+nlon+15) return\n ierror = 10\n idv = nlat\n if(ityp .gt. 2) idv = imid\n lnl = nt*idv*nlon\n if(lwork .lt. lnl+lnl+idv*nlon) return\n ierror = 0\n ist = 0\n if(ityp .le. 2) ist = imid\n iw1 = ist+1\n iw2 = lnl+1\n iw3 = iw2+ist\n iw4 = iw2+lnl\n jw1 = lzimn+1\n jw2 = jw1+lzimn\n call vhses1(nlat,nlon,ityp,nt,imid,idvw,jdvw,v,w,mdab,ndab,\n 1 br,bi,cr,ci,idv,work,work(iw1),work(iw2),work(iw3),\n 2 work(iw4),idz,wvhses,wvhses(jw1),wvhses(jw2))\n return\n end\n\n subroutine vhses1(nlat,nlon,ityp,nt,imid,idvw,jdvw,v,w,mdab,\n 1 ndab,br,bi,cr,ci,idv,ve,vo,we,wo,work,idz,vb,wb,wrfft)\n dimension v(idvw,jdvw,1),w(idvw,jdvw,1),br(mdab,ndab,1),\n 1 bi(mdab,ndab,1),cr(mdab,ndab,1),ci(mdab,ndab,1),\n 2 ve(idv,nlon,1),vo(idv,nlon,1),we(idv,nlon,1),\n 3 wo(idv,nlon,1),work(1),wrfft(1),\n 4 vb(imid,1),wb(imid,1)\n nlp1 = nlat+1\n mlat = mod(nlat,2)\n mlon = mod(nlon,2)\n mmax = min0(nlat,(nlon+1)/2)\n imm1 = imid\n if(mlat .ne. 0) imm1 = imid-1\n do 10 k=1,nt\n do 10 j=1,nlon\n do 10 i=1,idv\n ve(i,j,k) = 0.\n we(i,j,k) = 0.\n 10 continue\n ndo1 = nlat\n ndo2 = nlat\n if(mlat .ne. 0) ndo1 = nlat-1\n if(mlat .eq. 0) ndo2 = nlat-1\n 18 itypp = ityp+1\n go to (1,100,200,300,400,500,600,700,800),itypp\nc\nc case ityp=0 no symmetries\nc\nc case m = 0\nc\n 1 do 15 k=1,nt\n do 15 np1=2,ndo2,2\n do 15 i=1,imid\n ve(i,1,k)=ve(i,1,k)+br(1,np1,k)*vb(i,np1)\n we(i,1,k)=we(i,1,k)-cr(1,np1,k)*vb(i,np1)\n 15 continue\n do 16 k=1,nt\n do 16 np1=3,ndo1,2\n do 16 i=1,imm1\n vo(i,1,k)=vo(i,1,k)+br(1,np1,k)*vb(i,np1)\n wo(i,1,k)=wo(i,1,k)-cr(1,np1,k)*vb(i,np1)\n 16 continue\nc\nc case m = 1 through nlat-1\nc\n if(mmax .lt. 2) go to 950\n do 30 mp1=2,mmax\n m = mp1-1\n mb = m*(nlat-1)-(m*(m-1))/2\n mp2 = mp1+1\n if(mp1 .gt. ndo1) go to 26\n do 25 k=1,nt\n do 24 np1=mp1,ndo1,2\n mn = mb+np1\n do 23 i=1,imm1\n vo(i,2*mp1-2,k) = vo(i,2*mp1-2,k)+br(mp1,np1,k)*vb(i,mn)\n ve(i,2*mp1-2,k) = ve(i,2*mp1-2,k)-ci(mp1,np1,k)*wb(i,mn)\n vo(i,2*mp1-1,k) = vo(i,2*mp1-1,k)+bi(mp1,np1,k)*vb(i,mn)\n ve(i,2*mp1-1,k) = ve(i,2*mp1-1,k)+cr(mp1,np1,k)*wb(i,mn)\n wo(i,2*mp1-2,k) = wo(i,2*mp1-2,k)-cr(mp1,np1,k)*vb(i,mn)\n we(i,2*mp1-2,k) = we(i,2*mp1-2,k)-bi(mp1,np1,k)*wb(i,mn)\n wo(i,2*mp1-1,k) = wo(i,2*mp1-1,k)-ci(mp1,np1,k)*vb(i,mn)\n we(i,2*mp1-1,k) = we(i,2*mp1-1,k)+br(mp1,np1,k)*wb(i,mn)\n 23 continue\n if(mlat .eq. 0) go to 24\n ve(imid,2*mp1-2,k) = ve(imid,2*mp1-2,k)\n 1 -ci(mp1,np1,k)*wb(imid,mn)\n ve(imid,2*mp1-1,k) = ve(imid,2*mp1-1,k)\n 1 +cr(mp1,np1,k)*wb(imid,mn)\n we(imid,2*mp1-2,k) = we(imid,2*mp1-2,k)\n 1 -bi(mp1,np1,k)*wb(imid,mn) \n we(imid,2*mp1-1,k) = we(imid,2*mp1-1,k)\n 1 +br(mp1,np1,k)*wb(imid,mn)\n 24 continue\n 25 continue\n 26 if(mp2 .gt. ndo2) go to 30\n do 29 k=1,nt\n do 28 np1=mp2,ndo2,2\n mn = mb+np1\n do 27 i=1,imm1\n ve(i,2*mp1-2,k) = ve(i,2*mp1-2,k)+br(mp1,np1,k)*vb(i,mn)\n vo(i,2*mp1-2,k) = vo(i,2*mp1-2,k)-ci(mp1,np1,k)*wb(i,mn)\n ve(i,2*mp1-1,k) = ve(i,2*mp1-1,k)+bi(mp1,np1,k)*vb(i,mn)\n vo(i,2*mp1-1,k) = vo(i,2*mp1-1,k)+cr(mp1,np1,k)*wb(i,mn)\n we(i,2*mp1-2,k) = we(i,2*mp1-2,k)-cr(mp1,np1,k)*vb(i,mn)\n wo(i,2*mp1-2,k) = wo(i,2*mp1-2,k)-bi(mp1,np1,k)*wb(i,mn)\n we(i,2*mp1-1,k) = we(i,2*mp1-1,k)-ci(mp1,np1,k)*vb(i,mn)\n wo(i,2*mp1-1,k) = wo(i,2*mp1-1,k)+br(mp1,np1,k)*wb(i,mn)\n 27 continue\n if(mlat .eq. 0) go to 28\n ve(imid,2*mp1-2,k) = ve(imid,2*mp1-2,k)\n 1 +br(mp1,np1,k)*vb(imid,mn) \n ve(imid,2*mp1-1,k) = ve(imid,2*mp1-1,k)\n 1 +bi(mp1,np1,k)*vb(imid,mn)\n we(imid,2*mp1-2,k) = we(imid,2*mp1-2,k)\n 1 -cr(mp1,np1,k)*vb(imid,mn)\n we(imid,2*mp1-1,k) = we(imid,2*mp1-1,k)\n 1 -ci(mp1,np1,k)*vb(imid,mn)\n 28 continue\n 29 continue\n 30 continue\n go to 950\nc\nc case ityp=1 no symmetries, cr and ci equal zero\nc\nc case m = 0\nc\n 100 continue\n do 115 k=1,nt\n do 115 np1=2,ndo2,2\n do 115 i=1,imid\n ve(i,1,k)=ve(i,1,k)+br(1,np1,k)*vb(i,np1)\n 115 continue\n do 116 k=1,nt\n do 116 np1=3,ndo1,2\n do 116 i=1,imm1\n vo(i,1,k)=vo(i,1,k)+br(1,np1,k)*vb(i,np1)\n 116 continue\nc\nc case m = 1 through nlat-1\nc\n if(mmax .lt. 2) go to 950\n do 130 mp1=2,mmax\n m = mp1-1\n mb = m*(nlat-1)-(m*(m-1))/2\n mp2 = mp1+1\n if(mp1 .gt. ndo1) go to 126\n do 125 k=1,nt\n do 124 np1=mp1,ndo1,2\n mn = mb+np1\n do 123 i=1,imm1\n vo(i,2*mp1-2,k) = vo(i,2*mp1-2,k)+br(mp1,np1,k)*vb(i,mn)\n vo(i,2*mp1-1,k) = vo(i,2*mp1-1,k)+bi(mp1,np1,k)*vb(i,mn)\n we(i,2*mp1-2,k) = we(i,2*mp1-2,k)-bi(mp1,np1,k)*wb(i,mn)\n we(i,2*mp1-1,k) = we(i,2*mp1-1,k)+br(mp1,np1,k)*wb(i,mn)\n 123 continue\n if(mlat .eq. 0) go to 124\n we(imid,2*mp1-2,k) = we(imid,2*mp1-2,k)\n 1 -bi(mp1,np1,k)*wb(imid,mn) \n we(imid,2*mp1-1,k) = we(imid,2*mp1-1,k)\n 1 +br(mp1,np1,k)*wb(imid,mn)\n 124 continue\n 125 continue\n 126 if(mp2 .gt. ndo2) go to 130\n do 129 k=1,nt\n do 128 np1=mp2,ndo2,2\n mn = mb+np1\n do 127 i=1,imm1\n ve(i,2*mp1-2,k) = ve(i,2*mp1-2,k)+br(mp1,np1,k)*vb(i,mn)\n ve(i,2*mp1-1,k) = ve(i,2*mp1-1,k)+bi(mp1,np1,k)*vb(i,mn)\n wo(i,2*mp1-2,k) = wo(i,2*mp1-2,k)-bi(mp1,np1,k)*wb(i,mn)\n wo(i,2*mp1-1,k) = wo(i,2*mp1-1,k)+br(mp1,np1,k)*wb(i,mn)\n 127 continue\n if(mlat .eq. 0) go to 128\n ve(imid,2*mp1-2,k) = ve(imid,2*mp1-2,k)\n 1 +br(mp1,np1,k)*vb(imid,mn) \n ve(imid,2*mp1-1,k) = ve(imid,2*mp1-1,k)\n 1 +bi(mp1,np1,k)*vb(imid,mn)\n 128 continue\n 129 continue\n 130 continue\n go to 950\nc\nc case ityp=2 no symmetries, br and bi are equal to zero\nc\nc case m = 0\nc\n 200 do 215 k=1,nt\n do 215 np1=2,ndo2,2\n do 215 i=1,imid\n we(i,1,k)=we(i,1,k)-cr(1,np1,k)*vb(i,np1)\n 215 continue\n do 216 k=1,nt\n do 216 np1=3,ndo1,2\n do 216 i=1,imm1\n wo(i,1,k)=wo(i,1,k)-cr(1,np1,k)*vb(i,np1)\n 216 continue\nc\nc case m = 1 through nlat-1\nc\n if(mmax .lt. 2) go to 950\n do 230 mp1=2,mmax\n m = mp1-1\n mb = m*(nlat-1)-(m*(m-1))/2\n mp2 = mp1+1\n if(mp1 .gt. ndo1) go to 226\n do 225 k=1,nt\n do 224 np1=mp1,ndo1,2\n mn = mb+np1\n do 223 i=1,imm1\n ve(i,2*mp1-2,k) = ve(i,2*mp1-2,k)-ci(mp1,np1,k)*wb(i,mn)\n ve(i,2*mp1-1,k) = ve(i,2*mp1-1,k)+cr(mp1,np1,k)*wb(i,mn)\n wo(i,2*mp1-2,k) = wo(i,2*mp1-2,k)-cr(mp1,np1,k)*vb(i,mn)\n wo(i,2*mp1-1,k) = wo(i,2*mp1-1,k)-ci(mp1,np1,k)*vb(i,mn)\n 223 continue\n if(mlat .eq. 0) go to 224\n ve(imid,2*mp1-2,k) = ve(imid,2*mp1-2,k)\n 1 -ci(mp1,np1,k)*wb(imid,mn)\n ve(imid,2*mp1-1,k) = ve(imid,2*mp1-1,k)\n 1 +cr(mp1,np1,k)*wb(imid,mn)\n 224 continue\n 225 continue\n 226 if(mp2 .gt. ndo2) go to 230\n do 229 k=1,nt\n do 228 np1=mp2,ndo2,2\n mn = mb+np1\n do 227 i=1,imm1\n vo(i,2*mp1-2,k) = vo(i,2*mp1-2,k)-ci(mp1,np1,k)*wb(i,mn)\n vo(i,2*mp1-1,k) = vo(i,2*mp1-1,k)+cr(mp1,np1,k)*wb(i,mn)\n we(i,2*mp1-2,k) = we(i,2*mp1-2,k)-cr(mp1,np1,k)*vb(i,mn)\n we(i,2*mp1-1,k) = we(i,2*mp1-1,k)-ci(mp1,np1,k)*vb(i,mn)\n 227 continue\n if(mlat .eq. 0) go to 228\n we(imid,2*mp1-2,k) = we(imid,2*mp1-2,k)\n 1 -cr(mp1,np1,k)*vb(imid,mn)\n we(imid,2*mp1-1,k) = we(imid,2*mp1-1,k)\n 1 -ci(mp1,np1,k)*vb(imid,mn)\n 228 continue\n 229 continue\n 230 continue\n go to 950\nc\nc case ityp=3 v even, w odd \nc\nc case m = 0\nc\n 300 do 315 k=1,nt\n do 315 np1=2,ndo2,2\n do 315 i=1,imid\n ve(i,1,k)=ve(i,1,k)+br(1,np1,k)*vb(i,np1)\n 315 continue\n do 316 k=1,nt\n do 316 np1=3,ndo1,2\n do 316 i=1,imm1\n wo(i,1,k)=wo(i,1,k)-cr(1,np1,k)*vb(i,np1)\n 316 continue\nc\nc case m = 1 through nlat-1\nc\n if(mmax .lt. 2) go to 950\n do 330 mp1=2,mmax\n m = mp1-1\n mb = m*(nlat-1)-(m*(m-1))/2\n mp2 = mp1+1\n if(mp1 .gt. ndo1) go to 326\n do 325 k=1,nt\n do 324 np1=mp1,ndo1,2\n mn = mb+np1\n do 323 i=1,imm1\n ve(i,2*mp1-2,k) = ve(i,2*mp1-2,k)-ci(mp1,np1,k)*wb(i,mn)\n ve(i,2*mp1-1,k) = ve(i,2*mp1-1,k)+cr(mp1,np1,k)*wb(i,mn)\n wo(i,2*mp1-2,k) = wo(i,2*mp1-2,k)-cr(mp1,np1,k)*vb(i,mn)\n wo(i,2*mp1-1,k) = wo(i,2*mp1-1,k)-ci(mp1,np1,k)*vb(i,mn)\n 323 continue\n if(mlat .eq. 0) go to 324\n ve(imid,2*mp1-2,k) = ve(imid,2*mp1-2,k)\n 1 -ci(mp1,np1,k)*wb(imid,mn)\n ve(imid,2*mp1-1,k) = ve(imid,2*mp1-1,k)\n 1 +cr(mp1,np1,k)*wb(imid,mn)\n 324 continue\n 325 continue\n 326 if(mp2 .gt. ndo2) go to 330\n do 329 k=1,nt\n do 328 np1=mp2,ndo2,2\n mn = mb+np1\n do 327 i=1,imm1\n ve(i,2*mp1-2,k) = ve(i,2*mp1-2,k)+br(mp1,np1,k)*vb(i,mn)\n ve(i,2*mp1-1,k) = ve(i,2*mp1-1,k)+bi(mp1,np1,k)*vb(i,mn)\n wo(i,2*mp1-2,k) = wo(i,2*mp1-2,k)-bi(mp1,np1,k)*wb(i,mn)\n wo(i,2*mp1-1,k) = wo(i,2*mp1-1,k)+br(mp1,np1,k)*wb(i,mn)\n 327 continue\n if(mlat .eq. 0) go to 328\n ve(imid,2*mp1-2,k) = ve(imid,2*mp1-2,k)\n 1 +br(mp1,np1,k)*vb(imid,mn) \n ve(imid,2*mp1-1,k) = ve(imid,2*mp1-1,k)\n 1 +bi(mp1,np1,k)*vb(imid,mn)\n 328 continue\n 329 continue\n 330 continue\n go to 950\nc\nc case ityp=4 v even, w odd, and both cr and ci equal zero \nc\nc case m = 0\nc\n 400 do 415 k=1,nt\n do 415 np1=2,ndo2,2\n do 415 i=1,imid\n ve(i,1,k)=ve(i,1,k)+br(1,np1,k)*vb(i,np1)\n 415 continue\nc\nc case m = 1 through nlat-1\nc\n if(mmax .lt. 2) go to 950\n do 430 mp1=2,mmax\n m = mp1-1\n mb = m*(nlat-1)-(m*(m-1))/2\n mp2 = mp1+1\n if(mp2 .gt. ndo2) go to 430\n do 429 k=1,nt\n do 428 np1=mp2,ndo2,2\n mn = mb+np1\n do 427 i=1,imm1\n ve(i,2*mp1-2,k) = ve(i,2*mp1-2,k)+br(mp1,np1,k)*vb(i,mn)\n ve(i,2*mp1-1,k) = ve(i,2*mp1-1,k)+bi(mp1,np1,k)*vb(i,mn)\n wo(i,2*mp1-2,k) = wo(i,2*mp1-2,k)-bi(mp1,np1,k)*wb(i,mn)\n wo(i,2*mp1-1,k) = wo(i,2*mp1-1,k)+br(mp1,np1,k)*wb(i,mn)\n 427 continue\n if(mlat .eq. 0) go to 428\n ve(imid,2*mp1-2,k) = ve(imid,2*mp1-2,k)\n 1 +br(mp1,np1,k)*vb(imid,mn) \n ve(imid,2*mp1-1,k) = ve(imid,2*mp1-1,k)\n 1 +bi(mp1,np1,k)*vb(imid,mn)\n 428 continue\n 429 continue\n 430 continue\n go to 950\nc\nc case ityp=5 v even, w odd, br and bi equal zero \nc\nc case m = 0\nc\n 500 do 516 k=1,nt\n do 516 np1=3,ndo1,2\n do 516 i=1,imm1\n wo(i,1,k)=wo(i,1,k)-cr(1,np1,k)*vb(i,np1)\n 516 continue\nc\nc case m = 1 through nlat-1\nc\n if(mmax .lt. 2) go to 950\n do 530 mp1=2,mmax\n m = mp1-1\n mb = m*(nlat-1)-(m*(m-1))/2\n mp2 = mp1+1\n if(mp1 .gt. ndo1) go to 530\n do 525 k=1,nt\n do 524 np1=mp1,ndo1,2\n mn = mb+np1\n do 523 i=1,imm1\n ve(i,2*mp1-2,k) = ve(i,2*mp1-2,k)-ci(mp1,np1,k)*wb(i,mn)\n ve(i,2*mp1-1,k) = ve(i,2*mp1-1,k)+cr(mp1,np1,k)*wb(i,mn)\n wo(i,2*mp1-2,k) = wo(i,2*mp1-2,k)-cr(mp1,np1,k)*vb(i,mn)\n wo(i,2*mp1-1,k) = wo(i,2*mp1-1,k)-ci(mp1,np1,k)*vb(i,mn)\n 523 continue\n if(mlat .eq. 0) go to 524\n ve(imid,2*mp1-2,k) = ve(imid,2*mp1-2,k)\n 1 -ci(mp1,np1,k)*wb(imid,mn)\n ve(imid,2*mp1-1,k) = ve(imid,2*mp1-1,k)\n 1 +cr(mp1,np1,k)*wb(imid,mn)\n 524 continue\n 525 continue\n 530 continue\n go to 950\nc\nc case ityp=6 v odd , w even\nc\nc case m = 0\nc\n 600 do 615 k=1,nt\n do 615 np1=2,ndo2,2\n do 615 i=1,imid\n we(i,1,k)=we(i,1,k)-cr(1,np1,k)*vb(i,np1)\n 615 continue\n do 616 k=1,nt\n do 616 np1=3,ndo1,2\n do 616 i=1,imm1\n vo(i,1,k)=vo(i,1,k)+br(1,np1,k)*vb(i,np1)\n 616 continue\nc\nc case m = 1 through nlat-1\nc\n if(mmax .lt. 2) go to 950\n do 630 mp1=2,mmax\n m = mp1-1\n mb = m*(nlat-1)-(m*(m-1))/2\n mp2 = mp1+1\n if(mp1 .gt. ndo1) go to 626\n do 625 k=1,nt\n do 624 np1=mp1,ndo1,2\n mn = mb+np1\n do 623 i=1,imm1\n vo(i,2*mp1-2,k) = vo(i,2*mp1-2,k)+br(mp1,np1,k)*vb(i,mn)\n vo(i,2*mp1-1,k) = vo(i,2*mp1-1,k)+bi(mp1,np1,k)*vb(i,mn)\n we(i,2*mp1-2,k) = we(i,2*mp1-2,k)-bi(mp1,np1,k)*wb(i,mn)\n we(i,2*mp1-1,k) = we(i,2*mp1-1,k)+br(mp1,np1,k)*wb(i,mn)\n 623 continue\n if(mlat .eq. 0) go to 624\n we(imid,2*mp1-2,k) = we(imid,2*mp1-2,k)\n 1 -bi(mp1,np1,k)*wb(imid,mn) \n we(imid,2*mp1-1,k) = we(imid,2*mp1-1,k)\n 1 +br(mp1,np1,k)*wb(imid,mn)\n 624 continue\n 625 continue\n 626 if(mp2 .gt. ndo2) go to 630\n do 629 k=1,nt\n do 628 np1=mp2,ndo2,2\n mn = mb+np1\n do 627 i=1,imm1\n vo(i,2*mp1-2,k) = vo(i,2*mp1-2,k)-ci(mp1,np1,k)*wb(i,mn)\n vo(i,2*mp1-1,k) = vo(i,2*mp1-1,k)+cr(mp1,np1,k)*wb(i,mn)\n we(i,2*mp1-2,k) = we(i,2*mp1-2,k)-cr(mp1,np1,k)*vb(i,mn)\n we(i,2*mp1-1,k) = we(i,2*mp1-1,k)-ci(mp1,np1,k)*vb(i,mn)\n 627 continue\n if(mlat .eq. 0) go to 628\n we(imid,2*mp1-2,k) = we(imid,2*mp1-2,k)\n 1 -cr(mp1,np1,k)*vb(imid,mn)\n we(imid,2*mp1-1,k) = we(imid,2*mp1-1,k)\n 1 -ci(mp1,np1,k)*vb(imid,mn)\n 628 continue\n 629 continue\n 630 continue\n go to 950\nc\nc case ityp=7 v odd, w even cr and ci equal zero\nc\nc case m = 0\nc\n 700 do 716 k=1,nt\n do 716 np1=3,ndo1,2\n do 716 i=1,imm1\n vo(i,1,k)=vo(i,1,k)+br(1,np1,k)*vb(i,np1)\n 716 continue\nc\nc case m = 1 through nlat-1\nc\n if(mmax .lt. 2) go to 950\n do 730 mp1=2,mmax\n m = mp1-1\n mb = m*(nlat-1)-(m*(m-1))/2\n mp2 = mp1+1\n if(mp1 .gt. ndo1) go to 730\n do 725 k=1,nt\n do 724 np1=mp1,ndo1,2\n mn = mb+np1\n do 723 i=1,imm1\n vo(i,2*mp1-2,k) = vo(i,2*mp1-2,k)+br(mp1,np1,k)*vb(i,mn)\n vo(i,2*mp1-1,k) = vo(i,2*mp1-1,k)+bi(mp1,np1,k)*vb(i,mn)\n we(i,2*mp1-2,k) = we(i,2*mp1-2,k)-bi(mp1,np1,k)*wb(i,mn)\n we(i,2*mp1-1,k) = we(i,2*mp1-1,k)+br(mp1,np1,k)*wb(i,mn)\n 723 continue\n if(mlat .eq. 0) go to 724\n we(imid,2*mp1-2,k) = we(imid,2*mp1-2,k)\n 1 -bi(mp1,np1,k)*wb(imid,mn) \n we(imid,2*mp1-1,k) = we(imid,2*mp1-1,k)\n 1 +br(mp1,np1,k)*wb(imid,mn)\n 724 continue\n 725 continue\n 730 continue\n go to 950\nc\nc case ityp=8 v odd, w even br and bi equal zero\nc\nc case m = 0\nc\n 800 do 815 k=1,nt\n do 815 np1=2,ndo2,2\n do 815 i=1,imid\n we(i,1,k)=we(i,1,k)-cr(1,np1,k)*vb(i,np1)\n 815 continue\nc\nc case m = 1 through nlat-1\nc\n if(mmax .lt. 2) go to 950\n do 830 mp1=2,mmax\n m = mp1-1\n mb = m*(nlat-1)-(m*(m-1))/2\n mp2 = mp1+1\n if(mp2 .gt. ndo2) go to 830\n do 829 k=1,nt\n do 828 np1=mp2,ndo2,2\n mn = mb+np1\n do 827 i=1,imm1\n vo(i,2*mp1-2,k) = vo(i,2*mp1-2,k)-ci(mp1,np1,k)*wb(i,mn)\n vo(i,2*mp1-1,k) = vo(i,2*mp1-1,k)+cr(mp1,np1,k)*wb(i,mn)\n we(i,2*mp1-2,k) = we(i,2*mp1-2,k)-cr(mp1,np1,k)*vb(i,mn)\n we(i,2*mp1-1,k) = we(i,2*mp1-1,k)-ci(mp1,np1,k)*vb(i,mn)\n 827 continue\n if(mlat .eq. 0) go to 828\n we(imid,2*mp1-2,k) = we(imid,2*mp1-2,k)\n 1 -cr(mp1,np1,k)*vb(imid,mn)\n we(imid,2*mp1-1,k) = we(imid,2*mp1-1,k)\n 1 -ci(mp1,np1,k)*vb(imid,mn)\n 828 continue\n 829 continue\n 830 continue\n 950 do 14 k=1,nt\n call hrfftb(idv,nlon,ve(1,1,k),idv,wrfft,work)\n call hrfftb(idv,nlon,we(1,1,k),idv,wrfft,work)\n 14 continue\n if(ityp .gt. 2) go to 12\n do 60 k=1,nt\n do 60 j=1,nlon\n do 60 i=1,imm1\n v(i,j,k) = .5*(ve(i,j,k)+vo(i,j,k))\n w(i,j,k) = .5*(we(i,j,k)+wo(i,j,k))\n v(nlp1-i,j,k) = .5*(ve(i,j,k)-vo(i,j,k))\n w(nlp1-i,j,k) = .5*(we(i,j,k)-wo(i,j,k))\n 60 continue\n go to 13\n 12 do 11 k=1,nt\n do 11 j=1,nlon\n do 11 i=1,imm1\n v(i,j,k) = .5*ve(i,j,k)\n w(i,j,k) = .5*we(i,j,k)\n 11 continue\n 13 if(mlat .eq. 0) return\n do 65 k=1,nt\n do 65 j=1,nlon\n v(imid,j,k) = .5*ve(imid,j,k)\n w(imid,j,k) = .5*we(imid,j,k)\n 65 continue\n return\n end\n\n subroutine vhsesi(nlat,nlon,wvhses,lvhses,work,lwork,dwork,\n + ldwork,ierror)\n dimension wvhses(lvhses),work(lwork)\n double precision dwork(ldwork)\n ierror = 1\n if(nlat .lt. 3) return\n ierror = 2\n if(nlon .lt. 1) return\n ierror = 3\n mmax = min0(nlat,(nlon+1)/2)\n imid = (nlat+1)/2\n lzimn = (imid*mmax*(nlat+nlat-mmax+1))/2\n if(lvhses .lt. lzimn+lzimn+nlon+15) return\n ierror = 4\n labc = 3*(max0(mmax-2,0)*(nlat+nlat-mmax-1))/2\n if(lwork .lt. 5*nlat*imid+labc) return\n ierror = 5\n if (ldwork .lt. 2*(nlat+1)) return\n ierror = 0\n iw1 = 3*nlat*imid+1\n idz = (mmax*(nlat+nlat-mmax+1))/2\n call ves1(nlat,nlon,imid,wvhses,wvhses(lzimn+1),idz,work,\n 1 work(iw1),dwork)\n call hrffti(nlon,wvhses(2*lzimn+1))\n return\n end\n subroutine ves1(nlat,nlon,imid,vb,wb,idz,vin,wzvin,dwork)\n dimension vb(imid,*),wb(imid,*),vin(imid,nlat,3),wzvin(*)\n double precision dwork(*)\n mmax = min0(nlat,(nlon+1)/2)\n call vbinit (nlat,nlon,wzvin,dwork)\n do 33 mp1=1,mmax\n m = mp1-1\n call vbin (0,nlat,nlon,m,vin,i3,wzvin)\n do 33 np1=mp1,nlat\n mn = m*(nlat-1)-(m*(m-1))/2+np1\n do 33 i=1,imid\n vb(i,mn) = vin(i,np1,i3)\n 33 continue\n call wbinit (nlat,nlon,wzvin,dwork)\n do 34 mp1=1,mmax\n m = mp1-1\n call wbin (0,nlat,nlon,m,vin,i3,wzvin)\n do 34 np1=mp1,nlat\n mn = m*(nlat-1)-(m*(m-1))/2+np1\n do 34 i=1,imid\n wb(i,mn) = vin(i,np1,i3)\n 34 continue\n return\n end\n", "meta": {"hexsha": "60548580b16779e86d069ba51721e6432e130965", "size": 37019, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "contrib/spherepack/Src/vhses.f", "max_stars_repo_name": "xylar/cdat", "max_stars_repo_head_hexsha": "8a5080cb18febfde365efc96147e25f51494a2bf", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 62, "max_stars_repo_stars_event_min_datetime": "2018-03-30T15:46:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-08T23:30:24.000Z", "max_issues_repo_path": "contrib/spherepack/Src/vhses.f", "max_issues_repo_name": "xylar/cdat", "max_issues_repo_head_hexsha": "8a5080cb18febfde365efc96147e25f51494a2bf", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 114, "max_issues_repo_issues_event_min_datetime": "2018-03-21T01:12:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-05T12:29:54.000Z", "max_forks_repo_path": "contrib/spherepack/Src/vhses.f", "max_forks_repo_name": "CDAT/uvcdat", "max_forks_repo_head_hexsha": "5133560c0c049b5c93ee321ba0af494253b44f91", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2018-06-06T02:42:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-26T03:27:00.000Z", "avg_line_length": 35.940776699, "max_line_length": 72, "alphanum_fraction": 0.5237040439, "num_tokens": 14491, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582593509315, "lm_q2_score": 0.7490872187162397, "lm_q1q2_score": 0.6969943896287429}} {"text": "! Converts from classical grain size to optical grain size (Vionnet et al., 2012)\nsubroutine conversion_grain\nuse declarations, only : dendricity, & ! Dendricity of the grain\n & sphericity, & ! Sphericity of the grain\n & M, & ! Number of vertical nodes\n & grain_opt, & ! Optical grain diameter [m] \n & grain_classic, & ! Grain diameter [m]\n & dp ! Precision of float numbers\nimplicit none\n\nwhere (dendricity(:,1:M-1) .gt. 0.00001 ) ! dendritic case\n grain_opt(:,1:M-1) = 1e-4_dp*(dendricity(:,1:M-1)+(1.0_dp-dendricity(:,1:M-1)) &\n & *(4.0_dp-sphericity(:,1:M-1)))\nelsewhere ! non-dendritic case\n grain_opt(:,1:M-1) = grain_classic(:,1:M-1)*sphericity(:,1:M-1) + &\n & (1.0_dp-sphericity(:,1:M-1))*max(4e-4_dp,grain_classic(:,1:M-1)*0.5_dp)\nend where\n\n\nreturn\nend subroutine\n", "meta": {"hexsha": "5060b9fbe5063673ce4bcdb652b9b03806befcd2", "size": 934, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/conversion_grain.f90", "max_stars_repo_name": "nleroux3/SMPP", "max_stars_repo_head_hexsha": "f9cefac40e94a50df75a3efa8dc113802882b1f8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-04-13T15:02:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-13T15:02:25.000Z", "max_issues_repo_path": "src/conversion_grain.f90", "max_issues_repo_name": "nleroux3/SMPP", "max_issues_repo_head_hexsha": "f9cefac40e94a50df75a3efa8dc113802882b1f8", "max_issues_repo_licenses": ["MIT"], "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/conversion_grain.f90", "max_forks_repo_name": "nleroux3/SMPP", "max_forks_repo_head_hexsha": "f9cefac40e94a50df75a3efa8dc113802882b1f8", "max_forks_repo_licenses": ["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.4545454545, "max_line_length": 83, "alphanum_fraction": 0.5685224839, "num_tokens": 291, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582593509315, "lm_q2_score": 0.7490872187162396, "lm_q1q2_score": 0.6969943896287428}} {"text": "MODULE qshep3d\r\n\r\n! ALGORITHM 661, COLLECTED ALGORITHMS FROM ACM.\r\n \r\n! Code converted using TO_F90 by Alan Miller\r\n! Date: 2001-01-18 Time: 17:33:38\r\n \r\n! THIS WORK PUBLISHED IN TRANSACTIONS ON MATHEMATICAL SOFTWARE,\r\n! VOL. 14, NO. 2, P.151.\r\n\r\nIMPLICIT NONE\r\n\r\n\r\nCONTAINS\r\n\r\n\r\nSUBROUTINE qshep3(n,x,y,z,f,nq,nw,nr,lcell,lnext,xyzmin,xyzdel, &\r\n rmax,rsq,a,ier)\r\nINTEGER, INTENT(IN) :: n, nq, nw, nr\r\nREAL, INTENT(IN) :: x(:), y(:), z(:), f(:)\r\nREAL, INTENT(OUT) :: xyzmin(3), xyzdel(3), rmax, rsq(:), a(:,:)\r\nINTEGER, INTENT(OUT) :: lcell(:,:,:), lnext(:), ier\r\n\r\n!***********************************************************\r\n\r\n! ROBERT RENKA\r\n! UNIV. OF NORTH TEXAS\r\n! (817) 565-2767\r\n! 01/08/90\r\n\r\n! THIS SUBROUTINE COMPUTES A SET OF PARAMETERS A AND RSQ DEFINING A SMOOTH\r\n! (ONCE CONTINUOUSLY DIFFERENTIABLE) TRI-VARIATE FUNCTION Q(X,Y,Z) WHICH\r\n! INTERPOLATES DATA VALUES F AT SCATTERED NODES (X,Y,Z). THE INTERPOLANT Q\r\n! MAY BE EVALUATED AT AN ARBITRARY POINT BY FUNCTION QS3VAL, AND ITS FIRST\r\n! DERIVATIVES ARE COMPUTED BY SUBROUTINE QS3GRD.\r\n\r\n! THE INTERPOLATION SCHEME IS A MODIFIED QUADRATIC SHEPARD METHOD --\r\n\r\n! Q = (W(1)*Q(1)+W(2)*Q(2)+..+W(N)*Q(N))/(W(1)+W(2)+..+W(N))\r\n\r\n! FOR TRIVARIATE FUNCTIONS W(K) AND Q(K). THE NODAL FUNCTIONS ARE GIVEN BY\r\n\r\n! Q(K)(X,Y,Z) = A(1,K)*DX**2 + A(2,K)*DX*DY + A(3,K)*DY**2 +\r\n! A(4,K)*DX*DZ + A(5,K)*DY*DZ + A(6,K)*DZ**2 +\r\n! A(7,K)*DX + A(8,K)*DY + A(9,K)*DZ + F(K)\r\n\r\n! WHERE DX = (X-X(K)), DY = (Y-Y(K)), AND DZ = (Z-Z(K)).\r\n! THUS, Q(K) IS A QUADRATIC FUNCTION WHICH INTERPOLATES THE DATA VALUE AT\r\n! NODE K. ITS COEFFICIENTS A(,K) ARE OBTAINED BY A WEIGHTED LEAST SQUARES\r\n! FIT TO THE CLOSEST NQ DATA POINTS WITH WEIGHTS SIMILAR TO W(K).\r\n! NOTE THAT THE RADIUS OF INFLUENCE FOR THE LEAST SQUARES FIT IS FIXED FOR\r\n! EACH K, BUT VARIES WITH K.\r\n\r\n! THE WEIGHTS ARE TAKEN TO BE\r\n\r\n! W(K)(X,Y,Z) = ( (R(K)-D(K))+ / R(K)*D(K) )**2\r\n\r\n! WHERE (R(K)-D(K))+ = 0 IF R(K) .LE. D(K), AND D(K)(X,Y,Z) IS THE EUCLIDEAN\r\n! DISTANCE BETWEEN (X,Y,Z) AND NODE K. THE RADIUS OF INFLUENCE R(K) VARIES\r\n! WITH K AND IS CHOSEN SO THAT NW NODES ARE WITHIN THE RADIUS.\r\n! NOTE THAT W(K) IS NOT DEFINED AT NODE (X(K),Y(K),Z(K)), BUT Q(X,Y,Z) HAS\r\n! LIMIT F(K) AS (X,Y,Z) APPROACHES (X(K),Y(K),Z(K)).\r\n\r\n! ON INPUT --\r\n\r\n! N = NUMBER OF NODES AND ASSOCIATED DATA VALUES.\r\n! N .GE. 10.\r\n\r\n! X,Y,Z = ARRAYS OF LENGTH N CONTAINING THE CARTESIAN\r\n! COORDINATES OF THE NODES.\r\n\r\n! F = ARRAY OF LENGTH N CONTAINING THE DATA VALUES\r\n! IN ONE-TO-ONE CORRESPONDENCE WITH THE NODES.\r\n\r\n! NQ = NUMBER OF DATA POINTS TO BE USED IN THE LEAST SQUARES FIT FOR\r\n! COEFFICIENTS DEFINING THE NODAL FUNCTIONS Q(K).\r\n! A RECOMMENDED VALUE IS NQ = 17.\r\n! 9 .LE. NQ .LE. MIN(40,N-1).\r\n\r\n! NW = NUMBER OF NODES WITHIN (AND DEFINING) THE RADII OF INFLUENCE\r\n! R(K) WHICH ENTER INTO THE WEIGHTS W(K).\r\n! FOR N SUFFICIENTLY LARGE, A RECOMMENDED VALUE IS NW = 32.\r\n! 1 .LE. NW .LE. MIN(40,N-1).\r\n\r\n! NR = NUMBER OF ROWS, COLUMNS, AND PLANES IN THE CELL GRID DEFINED\r\n! IN SUBROUTINE STORE3. A BOX CONTAINING THE NODES IS PARTITIONED\r\n! INTO CELLS IN ORDER TO INCREASE SEARCH EFFICIENCY.\r\n! NR = (N/3)**(1/3) IS RECOMMENDED. NR .GE. 1.\r\n\r\n! THE ABOVE PARAMETERS ARE NOT ALTERED BY THIS ROUTINE.\r\n\r\n! LCELL = ARRAY OF LENGTH .GE. NR**3.\r\n\r\n! LNEXT = ARRAY OF LENGTH .GE. N.\r\n\r\n! XYZMIN,XYZDEL = ARRAYS OF LENGTH .GE. 3.\r\n\r\n! RSQ = ARRAY OF LENGTH .GE. N.\r\n\r\n! A = ARRAY OF LENGTH .GE. 9N.\r\n\r\n! ON OUTPUT --\r\n\r\n! LCELL = NR BY NR BY NR ARRAY OF NODAL INDICES ASSOCIATED WITH CELLS.\r\n! REFER TO STORE3.\r\n\r\n! LNEXT = ARRAY OF LENGTH N CONTAINING NEXT-NODE INDICES.\r\n! REFER TO STORE3.\r\n\r\n! XYZMIN,XYZDEL = ARRAYS OF LENGTH 3 CONTAINING MINIMUM NODAL\r\n! COORDINATES AND CELL DIMENSIONS, RESPECTIVELY.\r\n! REFER TO STORE3.\r\n\r\n! RMAX = SQUARE ROOT OF THE LARGEST ELEMENT IN RSQ --\r\n! MAXIMUM RADIUS R(K).\r\n\r\n! RSQ = ARRAY CONTAINING THE SQUARES OF THE RADII R(K)\r\n! WHICH ENTER INTO THE WEIGHTS W(K).\r\n\r\n! A = 9 BY N ARRAY CONTAINING THE COEFFICIENTS FOR\r\n! QUADRATIC NODAL FUNCTION Q(K) IN COLUMN K.\r\n\r\n! NOTE THAT THE ABOVE OUTPUT PARAMETERS ARE NOT DEFINED UNLESS IER = 0.\r\n\r\n! IER = ERROR INDICATOR --\r\n! IER = 0 IF NO ERRORS WERE ENCOUNTERED.\r\n! IER = 1 IF N, NQ, NW, OR NR IS OUT OF RANGE.\r\n! IER = 2 IF DUPLICATE NODES WERE ENCOUNTERED.\r\n! IER = 3 IF ALL NODES ARE COPLANAR.\r\n\r\n! MODULES REQUIRED BY QSHEP3 -- GETNP3, GIVENS, ROTATE,\r\n! SETUP3, STORE3\r\n\r\n! INTRINSIC FUNCTIONS CALLED BY QSHEP3 -- ABS, MIN, FLOAT, MAX, MIN, SQRT\r\n\r\n!***********************************************************\r\n\r\nINTEGER :: i, ib, ierr, ip1, irm1, irow, j, jp1, k, lmax, lnp, neq, &\r\n nn, nnq, nnr, nnw, np, npts(40), nqwmax\r\nREAL :: av, avsq, b(10,10), c, dmin, fk, rq, rs, rsmx, rsold, &\r\n rws, s, sum, t, xk, yk, zk, xyzdl(3), xyzmn(3)\r\n\r\nREAL, PARAMETER :: dtol = 0.01, rtol = 1.e-5, sf = 1.0\r\n\r\n! LOCAL PARAMETERS --\r\n\r\n! AV = ROOT-MEAN-SQUARE DISTANCE BETWEEN K AND THE NODES IN THE\r\n! LEAST SQUARES SYSTEM (UNLESS ADDITIONAL NODES ARE INTRODUCED\r\n! FOR STABILITY).\r\n! THE FIRST 6 COLUMNS OF THE MATRIX ARE SCALED BY 1/AVSQ,\r\n! THE LAST 3 BY 1/AV\r\n! AVSQ = AV*AV\r\n! B = TRANSPOSE OF THE AUGMENTED REGRESSION MATRIX\r\n! C = FIRST COMPONENT OF THE PLANE ROTATION USED TO ZERO THE LOWER\r\n! TRIANGLE OF B**T -- COMPUTED BY SUBROUTINE GIVENS\r\n! DMIN = MINIMUM OF THE MAGNITUDES OF THE DIAGONAL ELEMENTS OF THE\r\n! REGRESSION MATRIX AFTER ZEROS ARE INTRODUCED BELOW THE\r\n! DIAGONAL\r\n! DTOL = TOLERANCE FOR DETECTING AN ILL-CONDITIONED\r\n! SYSTEM. THE SYSTEM IS ACCEPTED WHEN DMIN .GE. DTOL\r\n! FK = DATA VALUE AT NODE K -- F(K)\r\n! I = INDEX FOR A, B, NPTS, XYZMIN, XYZMN, XYZDEL,\r\n! AND XYZDL\r\n! IB = DO-LOOP INDEX FOR BACK SOLVE\r\n! IERR = ERROR FLAG FOR THE CALL TO STORE3\r\n! IP1 = I+1\r\n! IRM1 = IROW-1\r\n! IROW = ROW INDEX FOR B\r\n! J = INDEX FOR A AND B\r\n! JP1 = J+1\r\n! K = NODAL FUNCTION INDEX AND COLUMN INDEX FOR A\r\n! LMAX = MAXIMUM NUMBER OF NPTS ELEMENTS (MUST BE CONSISTENT WITH\r\n! THE DIMENSION STATEMENT ABOVE)\r\n! LNP = CURRENT LENGTH OF NPTS\r\n! NEQ = NUMBER OF EQUATIONS IN THE LEAST SQUARES FIT\r\n! NN,NNQ,NNR = LOCAL COPIES OF N, NQ, AND NR\r\n! NNW = LOCAL COPY OF NW\r\n! NP = NPTS ELEMENT\r\n! NPTS = ARRAY CONTAINING THE INDICES OF A SEQUENCE OF\r\n! NODES TO BE USED IN THE LEAST SQUARES FIT\r\n! OR TO COMPUTE RSQ. THE NODES ARE ORDERED\r\n! BY DISTANCE FROM K AND THE LAST ELEMENT\r\n! (USUALLY INDEXED BY LNP) IS USED ONLY TO\r\n! DETERMINE RQ, OR RSQ(K) IF NW .GT. NQ\r\n! NQWMAX = MAX(NQ,NW)\r\n! RQ = RADIUS OF INFLUENCE WHICH ENTERS INTO THE\r\n! WEIGHTS FOR Q(K) (SEE SUBROUTINE SETUP3)\r\n! RS = SQUARED DISTANCE BETWEEN K AND NPTS(LNP) --\r\n! USED TO COMPUTE RQ AND RSQ(K)\r\n! RSMX = MAXIMUM RSQ ELEMENT ENCOUNTERED\r\n! RSOLD = SQUARED DISTANCE BETWEEN K AND NPTS(LNP-1) --\r\n! USED TO COMPUTE A RELATIVE CHANGE IN RS\r\n! BETWEEN SUCCEEDING NPTS ELEMENTS\r\n! RTOL = TOLERANCE FOR DETECTING A SUFFICIENTLY LARGE\r\n! RELATIVE CHANGE IN RS. IF THE CHANGE IS\r\n! NOT GREATER THAN RTOL, THE NODES ARE\r\n! TREATED AS BEING THE SAME DISTANCE FROM K\r\n! RWS = CURRENT VALUE OF RSQ(K)\r\n! S = SECOND COMPONENT OF THE PLANE GIVENS ROTATION\r\n! SF = MARQUARDT STABILIZATION FACTOR USED TO DAMP\r\n! OUT THE FIRST 6 SOLUTION COMPONENTS (SECOND\r\n! PARTIALS OF THE QUADRATIC) WHEN THE SYSTEM\r\n! IS ILL-CONDITIONED. AS SF INCREASES, THE\r\n! FITTING FUNCTION APPROACHES A LINEAR\r\n! SUM = SUM OF SQUARED EUCLIDEAN DISTANCES BETWEEN\r\n! NODE K AND THE NODES USED IN THE LEAST\r\n! SQUARES FIT (UNLESS ADDITIONAL NODES ARE\r\n! ADDED FOR STABILITY)\r\n! T = TEMPORARY VARIABLE FOR ACCUMULATING A SCALAR\r\n! PRODUCT IN THE BACK SOLVE\r\n! XK,YK,ZK = COORDINATES OF NODE K -- X(K), Y(K), Z(K)\r\n! XYZDL = LOCAL VARIABLES FOR XYZDEL\r\n! XYZMN = LOCAL VARIABLES FOR XYZMIN\r\n\r\nnn = n\r\nnnq = nq\r\nnnw = nw\r\nnnr = nr\r\nnqwmax = MAX(nnq,nnw)\r\nlmax = MIN(40,nn-1)\r\nIF (9 <= nnq .AND. 1 <= nnw .AND. nqwmax <= lmax .AND. nnr >= 1) THEN\r\n \r\n! CREATE THE CELL DATA STRUCTURE, AND INITIALIZE RSMX.\r\n \r\n CALL store3(nn,x,y,z,nnr,lcell,lnext,xyzmn,xyzdl,ierr)\r\n IF (ierr /= 0) GO TO 160\r\n rsmx = 0.\r\n \r\n! OUTER LOOP ON NODE K\r\n \r\n DO k = 1, nn\r\n xk = x(k)\r\n yk = y(k)\r\n zk = z(k)\r\n fk = f(k)\r\n \r\n! MARK NODE K TO EXCLUDE IT FROM THE SEARCH FOR NEAREST NEIGHBORS.\r\n \r\n lnext(k) = -lnext(k)\r\n \r\n! INITIALIZE FOR LOOP ON NPTS.\r\n \r\n rs = 0.\r\n sum = 0.\r\n rws = 0.\r\n rq = 0.\r\n lnp = 0\r\n \r\n! COMPUTE NPTS, LNP, RWS, NEQ, RQ, AND AVSQ.\r\n \r\n 10 sum = sum + rs\r\n IF (lnp /= lmax) THEN\r\n lnp = lnp + 1\r\n rsold = rs\r\n CALL getnp3(xk,yk,zk,x,y,z,nnr,lcell,lnext,xyzmn,xyzdl,np,rs )\r\n IF (rs == 0.) GO TO 150\r\n npts(lnp) = np\r\n IF ((rs-rsold)/rs < rtol) GO TO 10\r\n IF (rws == 0. .AND. lnp > nnw) rws = rs\r\n IF (rq == 0. .AND. lnp > nnq) THEN\r\n \r\n! RQ = 0 (NOT YET COMPUTED) AND LNP .GT. NQ. RQ = SQRT(RS) IS\r\n! SUFFICIENTLY LARGE TO (STRICTLY) INCLUDE NQ NODES. THE LEAST SQUARES\r\n! FIT WILL INCLUDE NEQ = LNP-1 EQUATIONS FOR 9 .LE. NQ .LE. NEQ .LT. LMAX\r\n! .LE. N-1.\r\n \r\n neq = lnp - 1\r\n rq = SQRT(rs)\r\n avsq = sum / REAL(neq)\r\n END IF\r\n \r\n! BOTTOM OF LOOP -- TEST FOR TERMINATION.\r\n \r\n IF (lnp > nqwmax) GO TO 20\r\n GO TO 10\r\n END IF\r\n \r\n! ALL LMAX NODES ARE INCLUDED IN NPTS. RWS AND/OR RQ**2 IS\r\n! (ARBITRARILY) TAKEN TO BE 10 PERCENT LARGER THAN THE\r\n! DISTANCE RS TO THE LAST NODE INCLUDED.\r\n \r\n IF (rws == 0.) rws = 1.1 * rs\r\n IF (rq == 0.) THEN\r\n neq = lmax\r\n rq = SQRT(1.1*rs)\r\n avsq = sum / REAL(neq)\r\n END IF\r\n \r\n! STORE RSQ(K), UPDATE RSMX IF NECESSARY, AND COMPUTE AV.\r\n \r\n 20 rsq(k) = rws\r\n IF (rws > rsmx) rsmx = rws\r\n av = SQRT(avsq)\r\n \r\n! SET UP THE AUGMENTED REGRESSION MATRIX (TRANSPOSED) AS THE\r\n! COLUMNS OF B, AND ZERO OUT THE LOWER TRIANGLE (UPPER\r\n! TRIANGLE OF B) WITH GIVENS ROTATIONS -- QR DECOMPOSITION\r\n! WITH ORTHOGONAL MATRIX Q NOT STORED.\r\n \r\n i = 0\r\n 30 i = i + 1\r\n np = npts(i)\r\n irow = MIN(i,10)\r\n CALL setup3(xk,yk,zk,fk,x(np),y(np),z(np),f(np),av,avsq,rq, b(1,irow))\r\n IF (i == 1) GO TO 30\r\n irm1 = irow - 1\r\n DO j = 1, irm1\r\n jp1 = j + 1\r\n CALL givens(b(j,j),b(j,irow),c,s)\r\n CALL rotate(10-j,c,s,b(jp1:,j),b(jp1:,irow))\r\n END DO\r\n IF (i < neq) GO TO 30\r\n \r\n! TEST THE SYSTEM FOR ILL-CONDITIONING.\r\n \r\n dmin = MIN(ABS(b(1,1)), ABS(b(2,2)), ABS(b(3,3)), ABS(b(4,4)), &\r\n ABS(b(5,5)), ABS(b(6,6)), ABS(b(7,7)), ABS(b(8,8)), &\r\n ABS(b(9,9)))\r\n IF (dmin*rq < dtol) THEN\r\n IF (neq /= lmax) THEN\r\n \r\n! INCREASE RQ AND ADD ANOTHER EQUATION TO THE SYSTEM TO IMPROVE THE\r\n! CONDITIONING. THE NUMBER OF NPTS ELEMENTS IS ALSO INCREASED IF NECESSARY.\r\n \r\n 50 rsold = rs\r\n neq = neq + 1\r\n IF (neq /= lmax) THEN\r\n IF (neq /= lnp) THEN\r\n \r\n! NEQ .LT. LNP\r\n \r\n np = npts(neq+1)\r\n rs = (x(np)-xk) ** 2 + (y(np)-yk) ** 2 + (z(np)-zk) ** 2\r\n IF ((rs-rsold)/rs < rtol) GO TO 50\r\n rq = SQRT(rs)\r\n GO TO 30\r\n END IF\r\n \r\n! ADD AN ELEMENT TO NPTS.\r\n \r\n lnp = lnp + 1\r\n CALL getnp3(xk,yk,zk,x,y,z,nnr,lcell,lnext,xyzmn,xyzdl, np,rs)\r\n IF (np == 0) GO TO 150\r\n npts(lnp) = np\r\n IF ((rs-rsold)/rs < rtol) GO TO 50\r\n rq = SQRT(rs)\r\n GO TO 30\r\n END IF\r\n \r\n rq = SQRT(1.1*rs)\r\n GO TO 30\r\n END IF\r\n \r\n! STABILIZE THE SYSTEM BY DAMPING SECOND PARTIALS -- ADD\r\n! MULTIPLES OF THE FIRST SIX UNIT VECTORS TO THE FIRST\r\n! SIX EQUATIONS.\r\n \r\n DO i = 1, 6\r\n b(i,10) = sf\r\n ip1 = i + 1\r\n DO j = ip1, 10\r\n b(j,10) = 0.\r\n END DO\r\n DO j = i, 9\r\n jp1 = j + 1\r\n CALL givens(b(j,j),b(j,10),c,s)\r\n CALL rotate(10-j,c,s,b(jp1:,j),b(jp1:,10))\r\n END DO\r\n END DO\r\n \r\n! TEST THE STABILIZED SYSTEM FOR ILL-CONDITIONING.\r\n \r\n dmin = MIN(ABS(b(1,1)), ABS(b(2,2)), ABS(b(3,3)), ABS(b(4,4)), &\r\n ABS(b(5,5)), ABS(b(6,6)), ABS(b(7,7)), ABS(b(8,8)), &\r\n ABS(b(9,9)))\r\n IF (dmin*rq < dtol) GO TO 160\r\n END IF\r\n \r\n! SOLVE THE 9 BY 9 TRIANGULAR SYSTEM FOR THE COEFFICIENTS\r\n \r\n DO ib = 1, 9\r\n i = 10 - ib\r\n t = 0.\r\n IF (i /= 9) THEN\r\n ip1 = i + 1\r\n DO j = ip1, 9\r\n t = t + b(j,i) * a(j,k)\r\n END DO\r\n END IF\r\n a(i,k) = (b(10,i)-t) / b(i,i)\r\n END DO\r\n \r\n! SCALE THE COEFFICIENTS TO ADJUST FOR THE COLUMN SCALING.\r\n \r\n DO i = 1, 6\r\n a(i,k) = a(i,k) / avsq\r\n END DO\r\n a(7,k) = a(7,k) / av\r\n a(8,k) = a(8,k) / av\r\n a(9,k) = a(9,k) / av\r\n \r\n! UNMARK K AND THE ELEMENTS OF NPTS.\r\n \r\n lnext(k) = -lnext(k)\r\n DO i = 1, lnp\r\n np = npts(i)\r\n lnext(np) = -lnext(np)\r\n END DO\r\n END DO\r\n \r\n! NO ERRORS ENCOUNTERED.\r\n \r\n DO i = 1, 3\r\n xyzmin(i) = xyzmn(i)\r\n xyzdel(i) = xyzdl(i)\r\n END DO\r\n rmax = SQRT(rsmx)\r\n ier = 0\r\n RETURN\r\nEND IF\r\n\r\n! N, NQ, NW, OR NR IS OUT OF RANGE.\r\n\r\nier = 1\r\nRETURN\r\n\r\n! DUPLICATE NODES WERE ENCOUNTERED BY GETNP3.\r\n\r\n150 ier = 2\r\nRETURN\r\n\r\n! NO UNIQUE SOLUTION DUE TO COLLINEAR NODES.\r\n\r\n160 DO i = 1, 3\r\n xyzmin(i) = xyzmn(i)\r\n xyzdel(i) = xyzdl(i)\r\nEND DO\r\nier = 3\r\nRETURN\r\nEND SUBROUTINE qshep3\r\n\r\n\r\n\r\nFUNCTION qs3val(px,py,pz,n,x,y,z,f,nr,lcell,lnext,xyzmin,xyzdel,rmax,rsq,a) &\r\n RESULT(fn_val)\r\nINTEGER, INTENT(IN) :: n, nr, lcell(:,:,:), lnext(:)\r\nREAL, INTENT(IN) :: px, py, pz, x(:), y(:), z(:), f(:), xyzmin(3), &\r\n xyzdel(3), rmax, rsq(:), a(9,n)\r\nREAL :: fn_val\r\n\r\n!***********************************************************\r\n\r\n! ROBERT RENKA\r\n! UNIV. OF NORTH TEXAS\r\n! (817) 565-2767\r\n! 10/28/87\r\n\r\n! THIS FUNCTION RETURNS THE VALUE Q(PX,PY,PZ) WHERE Q IS\r\n! THE WEIGHTED SUM OF QUADRATIC NODAL FUNCTIONS DEFINED IN\r\n! SUBROUTINE QSHEP3. QS3GRD MAY BE CALLED TO COMPUTE A\r\n! GRADIENT OF Q ALONG WITH THE VALUE, AND/OR TO TEST FOR\r\n! ERRORS.\r\n\r\n! ON INPUT --\r\n\r\n! PX,PY,PZ = CARTESIAN COORDINATES OF THE POINT P AT\r\n! WHICH Q IS TO BE EVALUATED.\r\n\r\n! N = NUMBER OF NODES AND DATA VALUES DEFINING Q.\r\n! N .GE. 10.\r\n\r\n! X,Y,Z,F = ARRAYS OF LENGTH N CONTAINING THE NODES\r\n! AND DATA VALUES INTERPOLATED BY Q.\r\n\r\n! NR = NUMBER OF ROWS, COLUMNS, AND PLANES IN THE CELL\r\n! GRID. REFER TO STORE3. NR .GE. 1.\r\n\r\n! LCELL = NR BY NR BY NR ARRAY OF NODAL INDICES ASSO-\r\n! CIATED WITH CELLS. REFER TO STORE3.\r\n\r\n! LNEXT = ARRAY OF LENGTH N CONTAINING NEXT-NODE INDI-\r\n! CES. REFER TO STORE3.\r\n\r\n! XYZMIN,XYZDEL = ARRAYS OF LENGTH 3 CONTAINING MINI-\r\n! MUM NODAL COORDINATES AND CELL DIM-\r\n! ENSIONS, RESPECTIVELY. XYZDEL\r\n! ELEMENTS MUST BE POSITIVE. REFER TO\r\n! STORE3.\r\n\r\n! RMAX = SQUARE ROOT OF THE LARGEST ELEMENT IN RSQ --\r\n! MAXIMUM RADIUS.\r\n\r\n! RSQ = ARRAY OF LENGTH N CONTAINING THE SQUARED RADII\r\n! WHICH ENTER INTO THE WEIGHTS DEFINING Q.\r\n\r\n! A = 9 BY N ARRAY CONTAINING THE COEFFICIENTS FOR THE\r\n! NODAL FUNCTIONS DEFINING Q.\r\n\r\n! INPUT PARAMETERS ARE NOT ALTERED BY THIS FUNCTION. THE\r\n! PARAMETERS OTHER THAN PX, PY AND PZ SHOULD BE INPUT UNAL-\r\n! TERED FROM THEIR VALUES ON OUTPUT FROM QSHEP3. THIS FUNC-\r\n! TION SHOULD NOT BE CALLED IF A NONZERO ERROR FLAG WAS\r\n! RETURNED BY QSHEP3.\r\n\r\n! ON OUTPUT --\r\n\r\n! QS3VAL = FUNCTION VALUE Q(PX,PY,PZ) UNLESS N, NR,\r\n! XYZDEL, OR RMAX IS INVALID, IN WHICH CASE\r\n! NO VALUE IS RETURNED.\r\n\r\n! MODULES REQUIRED BY QS3VAL -- NONE\r\n\r\n! INTRINSIC FUNCTIONS CALLED BY QS3VAL -- IFIX, SQRT\r\n\r\n!***********************************************************\r\n\r\n! Local variables\r\nREAL :: delx, dely, delz, ds, dx, dxsq, dy, dysq, dz, dzsq, &\r\n rd, rds, rs, sw, swq, w, xmin, xp, ymin, yp, zmin, zp\r\nINTEGER :: i, imax, imin, j, jmax, jmin, k, kmax, kmin, l, lp\r\n\r\nxp = px\r\nyp = py\r\nzp = pz\r\nxmin = xyzmin(1)\r\nymin = xyzmin(2)\r\nzmin = xyzmin(3)\r\ndx = xyzdel(1)\r\ndy = xyzdel(2)\r\ndz = xyzdel(3)\r\nIF (n < 10 .OR. nr < 1 .OR. dx <= 0. .OR. dy <= 0. .OR. dz <= 0. .OR. rmax &\r\n < 0.) RETURN\r\n\r\n! SET IMIN, IMAX, JMIN, JMAX, KMIN, AND KMAX TO CELL INDICES DEFINING THE\r\n! RANGE OF THE SEARCH FOR NODES WHOSE RADII INCLUDE P.\r\n! THE CELLS WHICH MUST BE SEARCHED ARE THOSE INTERSECTED BY (OR CONTAINED\r\n! IN) A SPHERE OF RADIUS RMAX CENTERED AT P.\r\n\r\nimin = (xp-xmin-rmax)/dx + 1\r\nimax = (xp-xmin+rmax)/dx + 1\r\nIF (imin < 1) imin = 1\r\nIF (imax > nr) imax = nr\r\njmin = (yp-ymin-rmax)/dy + 1\r\njmax = (yp-ymin+rmax)/dy + 1\r\nIF (jmin < 1) jmin = 1\r\nIF (jmax > nr) jmax = nr\r\nkmin = (zp-zmin-rmax)/dz + 1\r\nkmax = (zp-zmin+rmax)/dz + 1\r\nIF (kmin < 1) kmin = 1\r\nIF (kmax > nr) kmax = nr\r\n\r\n! THE FOLLOWING IS A TEST FOR NO CELLS WITHIN THE SPHERE OF RADIUS RMAX.\r\n\r\nIF (imin <= imax .AND. jmin <= jmax .AND. kmin <= kmax) THEN\r\n \r\n! ACCUMULATE WEIGHT VALUES IN SW AND WEIGHTED NODAL FUNCTION\r\n! VALUES IN SWQ. THE WEIGHTS ARE W(L) = ((R-D)+/(R*D))**2\r\n! FOR R**2 = RSQ(L) AND D = DISTANCE BETWEEN P AND NODE L.\r\n \r\n sw = 0.\r\n swq = 0.\r\n \r\n! OUTER LOOP ON CELLS (I,J,K).\r\n \r\n DO k = kmin, kmax\r\n DO j = jmin, jmax\r\n DO i = imin, imax\r\n l = lcell(i,j,k)\r\n IF (l /= 0) THEN\r\n \r\n! INNER LOOP ON NODES L.\r\n \r\n 10 delx = xp - x(l)\r\n dely = yp - y(l)\r\n delz = zp - z(l)\r\n dxsq = delx * delx\r\n dysq = dely * dely\r\n dzsq = delz * delz\r\n ds = dxsq + dysq + dzsq\r\n rs = rsq(l)\r\n IF (ds < rs) THEN\r\n IF (ds == 0.) GO TO 50\r\n rds = rs * ds\r\n rd = SQRT(rds)\r\n w = (rs+ds-rd-rd) / rds\r\n sw = sw + w\r\n swq = swq + w * (a(1,l)*dxsq+a(2,l)*delx*dely+a(3,l)* &\r\n dysq+a(4,l)*delx*delz+a(5,l)*dely*delz+a(6,l)*dzsq &\r\n +a(7,l)*delx+a(8,l)*dely+a(9,l)*delz+f(l))\r\n END IF\r\n \r\n! BOTTOM OF LOOP ON NODES IN CELL (I,J,K).\r\n \r\n lp = l\r\n l = lnext(lp)\r\n IF (l /= lp) GO TO 10\r\n END IF\r\n END DO\r\n END DO\r\n END DO\r\n \r\n! SW = 0 IFF P IS NOT WITHIN THE RADIUS R(L) FOR ANY NODE L.\r\n \r\n IF (sw == 0.) GO TO 60\r\n fn_val = swq / sw\r\n RETURN\r\n \r\n! (PX,PY,PZ) = (X(L),Y(L),Z(L))\r\n \r\n 50 fn_val = f(l)\r\n RETURN\r\nEND IF\r\n\r\n! ALL WEIGHTS ARE 0 AT P.\r\n\r\n60 fn_val = 0.\r\nRETURN\r\nEND FUNCTION qs3val\r\n\r\n\r\n\r\nSUBROUTINE qs3grd(px,py,pz,n,x,y,z,f,nr,lcell,lnext,xyzmin,xyzdel, &\r\n rmax,rsq,a,q,qx,qy,qz,ier)\r\nINTEGER, INTENT(IN) :: n, nr, lcell(:,:,:), lnext(:)\r\nREAL, INTENT(IN) :: px, py, pz, x(:), y(:), z(:), f(:), xyzmin(3), &\r\n xyzdel(3), rmax, rsq(:), a(9,n)\r\nINTEGER, INTENT(OUT) :: ier\r\nREAL, INTENT(OUT) :: q, qx, qy, qz\r\n\r\n!***********************************************************\r\n\r\n! ROBERT RENKA\r\n! UNIV. OF NORTH TEXAS\r\n! (817) 565-2767\r\n! 10/28/87\r\n\r\n! THIS SUBROUTINE COMPUTES THE VALUE AND GRADIENT AT (PX,PY,PZ) OF THE\r\n! INTERPOLATORY FUNCTION Q DEFINED IN SUBROUTINE QSHEP3. Q(X,Y,Z) IS A\r\n! WEIGHTED SUM OF QUADRATIC NODAL FUNCTIONS.\r\n\r\n! ON INPUT --\r\n\r\n! PX,PY,PZ = CARTESIAN COORDINATES OF THE POINT P AT WHICH Q AND\r\n! ITS PARTIALS ARE TO BE EVALUATED.\r\n\r\n! N = NUMBER OF NODES AND DATA VALUES DEFINING Q.\r\n! N .GE. 10.\r\n\r\n! X,Y,Z,F = ARRAYS OF LENGTH N CONTAINING THE NODES\r\n! AND DATA VALUES INTERPOLATED BY Q.\r\n\r\n! NR = NUMBER OF ROWS, COLUMNS AND PLANES IN THE CELL GRID.\r\n! REFER TO STORE3. NR .GE. 1.\r\n\r\n! LCELL = NR BY NR BY NR ARRAY OF NODAL INDICES ASSOCIATED WITH CELLS.\r\n! REFER TO STORE3.\r\n\r\n! LNEXT = ARRAY OF LENGTH N CONTAINING NEXT-NODE INDICES.\r\n! REFER TO STORE3.\r\n\r\n! XYZMIN,XYZDEL = ARRAYS OF LENGTH 3 CONTAINING MINIMUM NODAL\r\n! COORDINATES AND CELL DIMENSIONS, RESPECTIVELY.\r\n! XYZDEL ELEMENTS MUST BE POSITIVE. REFER TO STORE3.\r\n\r\n! RMAX = SQUARE ROOT OF THE LARGEST ELEMENT IN RSQ -- MAXIMUM RADIUS.\r\n\r\n! RSQ = ARRAY OF LENGTH N CONTAINING THE SQUARED RADII\r\n! WHICH ENTER INTO THE WEIGHTS DEFINING Q.\r\n\r\n! A = 9 BY N ARRAY CONTAINING THE COEFFICIENTS FOR THE\r\n! NODAL FUNCTIONS DEFINING Q.\r\n\r\n! INPUT PARAMETERS ARE NOT ALTERED BY THIS SUBROUTINE.\r\n! THE PARAMETERS OTHER THAN PX, PY, AND PZ SHOULD BE INPUT UNALTERED FROM\r\n! THEIR VALUES ON OUTPUT FROM QSHEP3. THIS SUBROUTINE SHOULD NOT BE CALLED\r\n! IF A NONZERO ERROR FLAG WAS RETURNED BY QSHEP3.\r\n\r\n! ON OUTPUT --\r\n\r\n! Q = VALUE OF Q AT (PX,PY,PZ) UNLESS IER .EQ. 1, IN\r\n! WHICH CASE NO VALUES ARE RETURNED.\r\n\r\n! QX,QY,QZ = FIRST PARTIAL DERIVATIVES OF Q AT\r\n! (PX,PY,PZ) UNLESS IER .EQ. 1.\r\n\r\n! IER = ERROR INDICATOR\r\n! IER = 0 IF NO ERRORS WERE ENCOUNTERED.\r\n! IER = 1 IF N, NR, XYZDEL, OR RMAX IS INVALID.\r\n! IER = 2 IF NO ERRORS WERE ENCOUNTERED BUT\r\n! (PX,PY,PZ) IS NOT WITHIN THE RADIUS\r\n! R(K) FOR ANY NODE K (AND THUS Q = QX =\r\n! QY = QZ = 0).\r\n\r\n! MODULES REQUIRED BY QS3GRD -- NONE\r\n\r\n! INTRINSIC FUNCTIONS CALLED BY QS3GRD -- IFIX, SQRT\r\n\r\n!***********************************************************\r\n\r\n! Local variables\r\nREAL :: delx, dely, delz, ds, dx, dxsq, dy, dysq, dz, dzsq, &\r\n ql, qlx, qly, qlz, rd, rds, rs, sw, swq, swqx, swqy, swqz, &\r\n sws, swx, swy, swz, t, w, wx, wy, wz, xmin, xp, ymin, yp, &\r\n zmin, zp\r\nINTEGER :: i, imax, imin, j, jmax, jmin, k, kmax, kmin, l, lp\r\n\r\nxp = px\r\nyp = py\r\nzp = pz\r\nxmin = xyzmin(1)\r\nymin = xyzmin(2)\r\nzmin = xyzmin(3)\r\ndx = xyzdel(1)\r\ndy = xyzdel(2)\r\ndz = xyzdel(3)\r\nIF (n >= 10 .AND. nr >= 1 .AND. dx > 0. .AND. dy > 0. .AND. dz > 0. &\r\n .AND. rmax >= 0.) THEN\r\n \r\n! SET IMIN, IMAX, JMIN, JMAX, KMIN, AND KMAX TO CELL INDICES DEFINING THE\r\n! RANGE OF THE SEARCH FOR NODES WHOSE RADII INCLUDE P.\r\n! THE CELLS WHICH MUST BE SEARCHED ARE THOSE INTERSECTED BY (OR CONTAINED\r\n! IN) A SPHERE OF RADIUS RMAX CENTERED AT P.\r\n \r\n imin = (xp-xmin-rmax)/dx + 1\r\n imax = (xp-xmin+rmax)/dx + 1\r\n IF (imin < 1) imin = 1\r\n IF (imax > nr) imax = nr\r\n jmin = (yp-ymin-rmax)/dy + 1\r\n jmax = (yp-ymin+rmax)/dy + 1\r\n IF (jmin < 1) jmin = 1\r\n IF (jmax > nr) jmax = nr\r\n kmin = (zp-zmin-rmax)/dz + 1\r\n kmax = (zp-zmin+rmax)/dz + 1\r\n IF (kmin < 1) kmin = 1\r\n IF (kmax > nr) kmax = nr\r\n \r\n! THE FOLLOWING IS A TEST FOR NO CELLS WITHIN THE SPHERE OF RADIUS RMAX.\r\n \r\n IF (imin > imax .OR. jmin > jmax .OR. kmin > kmax) GO TO 60\r\n \r\n! Q = SWQ/SW = SUM(W(L)*Q(L))/SUM(W(L)) WHERE THE SUM IS\r\n! FROM L = 1 TO N, Q(L) IS THE QUADRATIC NODAL FUNCTION,\r\n! AND W(L) = ((R-D)+/(R*D))**2 FOR RADIUS R(L) AND DIST-\r\n! ANCE D(L). THUS\r\n \r\n! QX = (SWQX*SW - SWQ*SWX)/SW**2\r\n! QY = (SWQY*SW - SWQ*SWY)/SW**2\r\n! QZ = (SWQZ*SW - SWQ*SWZ)/SW**2\r\n \r\n! WHERE SWQX AND SWX ARE PARTIAL DERIVATIVES WITH RESPECT\r\n! TO X OF SWQ AND SW, RESPECTIVELY. SWQY, SWY, SWQZ, AND\r\n! SWZ ARE DEFINED SIMILARLY.\r\n \r\n sw = 0.\r\n swx = 0.\r\n swy = 0.\r\n swz = 0.\r\n swq = 0.\r\n swqx = 0.\r\n swqy = 0.\r\n swqz = 0.\r\n \r\n! OUTER LOOP ON CELLS (I,J,K).\r\n \r\n DO k = kmin, kmax\r\n DO j = jmin, jmax\r\n DO i = imin, imax\r\n l = lcell(i,j,k)\r\n IF (l /= 0) THEN\r\n \r\n! INNER LOOP ON NODES L.\r\n \r\n 10 delx = xp - x(l)\r\n dely = yp - y(l)\r\n delz = zp - z(l)\r\n dxsq = delx * delx\r\n dysq = dely * dely\r\n dzsq = delz * delz\r\n ds = dxsq + dysq + dzsq\r\n rs = rsq(l)\r\n IF (ds < rs) THEN\r\n IF (ds == 0.) GO TO 50\r\n rds = rs * ds\r\n rd = SQRT(rds)\r\n w = (rs+ds-rd-rd) / rds\r\n t = 2. * (rd-rs) / (ds*rds)\r\n wx = delx * t\r\n wy = dely * t\r\n wz = delz * t\r\n qlx = 2. * a(1,l) * delx + a(2,l) * dely + a(4,l) * delz\r\n qly = a(2,l) * delx + 2. * a(3,l) * dely + a(5,l) * delz\r\n qlz = a(4,l) * delx + a(5,l) * dely + 2. * a(6,l) * delz\r\n ql = (qlx*delx+qly*dely+qlz*delz) / 2. + a(7,l) * delx &\r\n + a(8,l) * dely + a(9,l) * delz + f(l)\r\n qlx = qlx + a(7,l)\r\n qly = qly + a(8,l)\r\n qlz = qlz + a(9,l)\r\n sw = sw + w\r\n swx = swx + wx\r\n swy = swy + wy\r\n swz = swz + wz\r\n swq = swq + w * ql\r\n swqx = swqx + wx * ql + w * qlx\r\n swqy = swqy + wy * ql + w * qly\r\n swqz = swqz + wz * ql + w * qlz\r\n END IF\r\n \r\n! BOTTOM OF LOOP ON NODES IN CELL (I,J,K).\r\n \r\n lp = l\r\n l = lnext(lp)\r\n IF (l /= lp) GO TO 10\r\n END IF\r\n END DO\r\n END DO\r\n END DO\r\n \r\n! SW = 0 IFF P IS NOT WITHIN THE RADIUS R(L) FOR ANY NODE L.\r\n \r\n IF (sw == 0.) GO TO 60\r\n q = swq / sw\r\n sws = sw * sw\r\n qx = (swqx*sw-swq*swx) / sws\r\n qy = (swqy*sw-swq*swy) / sws\r\n qz = (swqz*sw-swq*swz) / sws\r\n ier = 0\r\n RETURN\r\n \r\n! (PX,PY,PZ) = (X(L),Y(L),Z(L))\r\n \r\n 50 q = f(l)\r\n qx = a(7,l)\r\n qy = a(8,l)\r\n qz = a(9,l)\r\n ier = 0\r\n RETURN\r\nEND IF\r\n\r\n! INVALID INPUT PARAMETER.\r\n\r\nier = 1\r\nRETURN\r\n\r\n! NO CELLS CONTAIN A POINT WITHIN RMAX OF P, OR\r\n! SW = 0 AND THUS DS .GE. RSQ(L) FOR ALL L.\r\n\r\n60 q = 0.\r\nqx = 0.\r\nqy = 0.\r\nqz = 0.\r\nier = 2\r\nRETURN\r\nEND SUBROUTINE qs3grd\r\n\r\n\r\n\r\nSUBROUTINE getnp3(px,py,pz,x,y,z,nr,lcell,lnext,xyzmin,xyzdel,np,dsq)\r\nINTEGER, INTENT(IN) :: nr, lcell(:,:,:)\r\nINTEGER, INTENT(IN OUT) :: lnext(:)\r\nREAL, INTENT(IN) :: px, py, pz, x(:), y(:), z(:), xyzmin(3), xyzdel(3)\r\nREAL, INTENT(OUT) :: dsq\r\nINTEGER, INTENT(OUT) :: np\r\n\r\n!***********************************************************\r\n\r\n! ROBERT RENKA\r\n! UNIV. OF NORTH TEXAS\r\n! (817) 565-2767\r\n\r\n! GIVEN A SET OF N NODES AND THE DATA STRUCTURE DEFINED IN SUBROUTINE\r\n! STORE3, THIS SUBROUTINE USES THE CELL METHOD TO FIND THE CLOSEST UNMARKED\r\n! NODE NP TO A SPECIFIED POINT P. NP IS THEN MARKED BY SETTING LNEXT(NP) TO\r\n! -LNEXT(NP). (A NODE IS MARKED IF AND ONLY IF THE CORRESPONDING LNEXT\r\n! ELEMENT IS NEGATIVE. THE ABSOLUTE VALUES OF LNEXT ELEMENTS, HOWEVER, MUST\r\n! BE PRESERVED.) THUS, THE CLOSEST M NODES TO P MAY BE DETERMINED BY A\r\n! SEQUENCE OF M CALLS TO THIS ROUTINE. NOTE THAT IF THE NEAREST NEIGHBOR TO\r\n! NODE K IS TO BE DETERMINED (PX = X(K), PY = Y(K), AND PZ = Z(K)), THEN\r\n! K SHOULD BE MARKED BEFORE THE CALL TO THIS ROUTINE.\r\n\r\n! THE SEARCH IS BEGUN IN THE CELL CONTAINING (OR CLOSEST TO) P AND PROCEEDS\r\n! OUTWARD IN BOX-SHAPED LAYERS UNTIL ALL CELLS WHICH CONTAIN POINTS WITHIN\r\n! DISTANCE R OF P HAVE BEEN SEARCHED, WHERE R IS THE DISTANCE FROM P TO THE\r\n! FIRST UNMARKED NODE ENCOUNTERED (INFINITE IF NO UNMARKED NODES ARE PRESENT).\r\n\r\n! ON INPUT --\r\n\r\n! PX,PY,PZ = CARTESIAN COORDINATES OF THE POINT P WHOSE NEAREST\r\n! UNMARKED NEIGHBOR IS TO BE FOUND.\r\n\r\n! X,Y,Z = ARRAYS OF LENGTH N, FOR N .GE. 2, CONTAINING\r\n! THE CARTESIAN COORDINATES OF THE NODES.\r\n\r\n! NR = NUMBER OF ROWS, COLUMNS, AND PLANES IN THE CELL GRID.\r\n! NR .GE. 1.\r\n\r\n! LCELL = NR BY NR BY NR ARRAY OF NODAL INDICES ASSOCIATED WITH CELLS.\r\n\r\n! LNEXT = ARRAY OF LENGTH N CONTAINING NEXT-NODE INDICES\r\n! (OR THEIR NEGATIVES).\r\n\r\n! XYZMIN,XYZDEL = ARRAYS OF LENGTH 3 CONTAINING MINIMUM NODAL\r\n! COORDINATES AND CELL DIMENSIONS, RESPECTIVELY.\r\n! XYZDEL ELEMENTS MUST BE POSITIVE.\r\n\r\n! INPUT PARAMETERS OTHER THAN LNEXT ARE NOT ALTERED BY THIS ROUTINE.\r\n! WITH THE EXCEPTION OF (PX,PY,PZ) AND THE SIGNS OF LNEXT ELEMENTS, THESE\r\n! PARAMETERS SHOULD BE UNALTERED FROM THEIR VALUES ON OUTPUT FROM SUBROUTINE\r\n! STORE3.\r\n\r\n! ON OUTPUT --\r\n\r\n! NP = INDEX (FOR X, Y, AND Z) OF THE NEAREST UNMARKED\r\n! NODE TO P, OR 0 IF ALL NODES ARE MARKED OR NR\r\n! .LT. 1 OR AN ELEMENT OF XYZDEL IS NOT POSITIVE.\r\n! LNEXT(NP) .LT. 0 IF NP .NE. 0.\r\n\r\n! DSQ = SQUARED EUCLIDEAN DISTANCE BETWEEN P AND NODE\r\n! NP, OR 0 IF NP = 0.\r\n\r\n! MODULES REQUIRED BY GETNP3 -- NONE\r\n\r\n! INTRINSIC FUNCTIONS CALLED BY GETNP3 -- ABS, IFIX, SQRT\r\n\r\n!***********************************************************\r\n\r\nLOGICAL :: first\r\nREAL :: delx, dely, delz, dx, dy, dz, r, rsmin, rsq, xp, yp, zp\r\nINTEGER :: i, i0, i1, i2, imax, imin, j, j0, j1, j2, jmax, jmin, &\r\n k, k0, k1, k2, kmax, kmin, l, lmin, ln\r\n\r\nxp = px\r\nyp = py\r\nzp = pz\r\ndx = xyzdel(1)\r\ndy = xyzdel(2)\r\ndz = xyzdel(3)\r\n\r\n! TEST FOR INVALID INPUT PARAMETERS.\r\n\r\nIF (nr >= 1 .AND. dx > 0. .AND. dy > 0. .AND. dz > 0.) THEN\r\n \r\n! INITIALIZE PARAMETERS --\r\n \r\n! FIRST = TRUE IFF THE FIRST UNMARKED NODE HAS YET TO BE\r\n! ENCOUNTERED,\r\n! IMIN,...,KMAX = CELL INDICES DEFINING THE RANGE OF THE\r\n! SEARCH,\r\n! DELX,DELY,DELZ = PX-XYZMIN(1), PY-XYZMIN(2), AND\r\n! PZ-XYZMIN(3),\r\n! I0,J0,K0 = CELL CONTAINING OR CLOSEST TO P,\r\n! I1,...,K2 = CELL INDICES OF THE LAYER WHOSE INTERSECTION\r\n! WITH THE RANGE DEFINED BY IMIN,...,KMAX IS\r\n! CURRENTLY BEING SEARCHED.\r\n \r\n first = .true.\r\n imin = 1\r\n imax = nr\r\n jmin = 1\r\n jmax = nr\r\n kmin = 1\r\n kmax = nr\r\n delx = xp - xyzmin(1)\r\n dely = yp - xyzmin(2)\r\n delz = zp - xyzmin(3)\r\n i0 = delx/dx + 1\r\n IF (i0 < 1) i0 = 1\r\n IF (i0 > nr) i0 = nr\r\n j0 = dely/dy + 1\r\n IF (j0 < 1) j0 = 1\r\n IF (j0 > nr) j0 = nr\r\n k0 = delz/dz + 1\r\n IF (k0 < 1) k0 = 1\r\n IF (k0 > nr) k0 = nr\r\n i1 = i0\r\n i2 = i0\r\n j1 = j0\r\n j2 = j0\r\n k1 = k0\r\n k2 = k0\r\n \r\n! OUTER LOOP ON LAYERS, INNER LOOP ON LAYER CELLS, EXCLUDING\r\n! THOSE OUTSIDE THE RANGE (IMIN,IMAX) X (JMIN,JMAX) X (KMIN,KMAX).\r\n 10 i = 0\r\n loop50: DO k = k1, k2\r\n IF (k > kmax) GO TO 60\r\n IF (k >= kmin) THEN\r\n loop40: DO j = j1, j2\r\n IF (j > jmax) CYCLE loop50\r\n IF (j >= jmin) THEN\r\n DO i = i1, i2\r\n IF (i > imax) CYCLE loop40\r\n IF (i >= imin) THEN\r\n IF (k == k1 .OR. k == k2 .OR. j == j1 .OR. j == j2 .OR. i &\r\n == i1 .OR. i == i2) THEN\r\n \r\n! SEARCH CELL (I,J,K) FOR UNMARKED NODES L.\r\n \r\n l = lcell(i,j,k)\r\n IF (l /= 0) THEN\r\n \r\n! LOOP ON NODES IN CELL (I,J,K).\r\n \r\n 20 ln = lnext(l)\r\n IF (ln >= 0) THEN\r\n \r\n! NODE L IS NOT MARKED.\r\n \r\n rsq = (x(l)-xp) ** 2 + (y(l)-yp) ** 2 + ( z(l)-zp) ** 2\r\n IF (first) THEN\r\n \r\n! NODE L IS THE FIRST UNMARKED NEIGHBOR OF P ENCOUNTERED.\r\n! INITIALIZE LMIN TO THE CURRENT CANDIDATE FOR NP, AND\r\n! RSMIN TO THE SQUARED DISTANCE FROM P TO LMIN. IMIN,\r\n! IMAX, JMIN, JMAX, KMIN, AND KMAX ARE UPDATED TO DEFINE\r\n! THE SMALLEST RECTANGLE CONTAINING A SPHERE OF RADIUS\r\n! R = SQRT(RSMIN) CENTERED AT P, AND CONTAINED IN (1,NR)\r\n! X (1,NR) X (1,NR) (EXCEPT THAT, IF P IS OUTSIDE THE\r\n! BOX DEFINED BY THE NODES, IT IS POSSIBLE THAT IMIN\r\n! .GT. NR OR IMAX .LT. 1, ETC.). FIRST IS RESET TO\r\n! FALSE.\r\n \r\n lmin = l\r\n rsmin = rsq\r\n r = SQRT(rsmin)\r\n imin = (delx-r)/dx + 1\r\n IF (imin < 1) imin = 1\r\n imax = (delx+r)/dx + 1\r\n IF (imax > nr) imax = nr\r\n jmin = (dely-r)/dy + 1\r\n IF (jmin < 1) jmin = 1\r\n jmax = (dely+r)/dy + 1\r\n IF (jmax > nr) jmax = nr\r\n kmin = (delz-r)/dz + 1\r\n IF (kmin < 1) kmin = 1\r\n kmax = (delz+r)/dz + 1\r\n IF (kmax > nr) kmax = nr\r\n first = .false.\r\n ELSE\r\n \r\n! TEST FOR NODE L CLOSER THAN LMIN TO P.\r\n \r\n IF (rsq < rsmin) THEN\r\n \r\n! UPDATE LMIN AND RSMIN.\r\n \r\n lmin = l\r\n rsmin = rsq\r\n END IF\r\n END IF\r\n END IF\r\n \r\n! TEST FOR TERMINATION OF LOOP ON NODES IN CELL (I,J,K).\r\n \r\n IF (ABS(ln) /= l) THEN\r\n l = ABS(ln)\r\n GO TO 20\r\n END IF\r\n END IF\r\n END IF\r\n END IF\r\n END DO\r\n END IF\r\n END DO loop40\r\n END IF\r\n END DO loop50\r\n \r\n! TEST FOR TERMINATION OF LOOP ON CELL LAYERS.\r\n \r\n 60 IF (i1 > imin .OR. i2 < imax .OR. j1 > jmin .OR. j2 < jmax .OR. k1 &\r\n > kmin .OR. k2 < kmax) THEN\r\n i1 = i1 - 1\r\n i2 = i2 + 1\r\n j1 = j1 - 1\r\n j2 = j2 + 1\r\n k1 = k1 - 1\r\n k2 = k2 + 1\r\n GO TO 10\r\n END IF\r\n \r\n! UNLESS NO UNMARKED NODES WERE ENCOUNTERED, LMIN IS THE\r\n! CLOSEST UNMARKED NODE TO P.\r\n \r\n IF (.NOT.first) THEN\r\n np = lmin\r\n dsq = rsmin\r\n lnext(lmin) = -lnext(lmin)\r\n RETURN\r\n END IF\r\nEND IF\r\n\r\n! ERROR -- NR OR XYZDEL IS INVALID OR ALL NODES ARE MARKED.\r\n\r\nnp = 0\r\ndsq = 0.\r\nRETURN\r\nEND SUBROUTINE getnp3\r\n\r\n\r\n\r\nSUBROUTINE givens(a,b,c,s)\r\nREAL, INTENT(IN OUT) :: a, b\r\nREAL, INTENT(OUT) :: c, s\r\n\r\n!***********************************************************\r\n\r\n! ROBERT RENKA\r\n! UNIV. OF NORTH TEXAS\r\n! (817) 565-2767\r\n\r\n! THIS ROUTINE CONSTRUCTS THE GIVENS PLANE ROTATION --\r\n! ( C S)\r\n! G = ( ) WHERE C*C + S*S = 1 -- WHICH ZEROS THE SECOND\r\n! (-S C)\r\n! ENTRY OF THE 2-VECTOR (A B)-TRANSPOSE. A CALL TO GIVENS\r\n! IS NORMALLY FOLLOWED BY A CALL TO ROTATE WHICH APPLIES\r\n! THE TRANSFORMATION TO A 2 BY N MATRIX. THIS ROUTINE WAS\r\n! TAKEN FROM LINPACK.\r\n\r\n! ON INPUT --\r\n\r\n! A,B = COMPONENTS OF THE 2-VECTOR TO BE ROTATED.\r\n\r\n! ON OUTPUT --\r\n\r\n! A = VALUE OVERWRITTEN BY R = +/-SQRT(A*A + B*B)\r\n\r\n! B = VALUE OVERWRITTEN BY A VALUE Z WHICH ALLOWS C\r\n! AND S TO BE RECOVERED AS FOLLOWS --\r\n! C = SQRT(1-Z*Z), S=Z IF ABS(Z) .LE. 1.\r\n! C = 1/Z, S = SQRT(1-C*C) IF ABS(Z) .GT. 1.\r\n\r\n! C = +/-(A/R)\r\n\r\n! S = +/-(B/R)\r\n\r\n! MODULES REQUIRED BY GIVENS -- NONE\r\n\r\n! INTRINSIC FUNCTIONS CALLED BY GIVENS - ABS, SQRT\r\n\r\n!***********************************************************\r\n\r\nREAL :: aa, bb, r, u, v\r\n\r\n! LOCAL PARAMETERS --\r\n\r\n! AA,BB = LOCAL COPIES OF A AND B\r\n! R = C*A + S*B = +/-SQRT(A*A+B*B)\r\n! U,V = VARIABLES USED TO SCALE A AND B FOR COMPUTING R\r\n\r\naa = a\r\nbb = b\r\nIF (ABS(aa) > ABS(bb)) THEN\r\n \r\n! ABS(A) .GT. ABS(B)\r\n \r\n u = aa + aa\r\n v = bb / u\r\n r = SQRT(.25+v*v) * u\r\n c = aa / r\r\n s = v * (c+c)\r\n \r\n! NOTE THAT R HAS THE SIGN OF A, C .GT. 0, AND S HAS\r\n! SIGN(A)*SIGN(B).\r\n \r\n b = s\r\n a = r\r\n RETURN\r\nEND IF\r\n\r\n! ABS(A) .LE. ABS(B)\r\n\r\nIF (bb /= 0.) THEN\r\n u = bb + bb\r\n v = aa / u\r\n \r\n! STORE R IN A.\r\n \r\n a = SQRT(.25+v*v) * u\r\n s = bb / a\r\n c = v * (s+s)\r\n \r\n! NOTE THAT R HAS THE SIGN OF B, S .GT. 0, AND C HAS\r\n! SIGN(A)*SIGN(B).\r\n \r\n b = 1.\r\n IF (c /= 0.) b = 1. / c\r\n RETURN\r\nEND IF\r\n\r\n! A = B = 0.\r\n\r\nc = 1.\r\ns = 0.\r\nRETURN\r\nEND SUBROUTINE givens\r\n\r\n\r\n\r\nSUBROUTINE rotate(n,c,s,x,y)\r\nINTEGER, INTENT(IN) :: n\r\nREAL, INTENT(IN) :: c, s\r\nREAL, INTENT(IN OUT) :: x(:), y(:)\r\n\r\n!***********************************************************\r\n\r\n! ROBERT RENKA\r\n! UNIV. OF NORTH TEXAS\r\n! (817) 565-2767\r\n\r\n! ( C S)\r\n! THIS ROUTINE APPLIES THE GIVENS ROTATION ( ) TO THE\r\n! (-S C)\r\n! (X(1) ... X(N))\r\n! 2 BY N MATRIX ( ).\r\n! (Y(1) ... Y(N))\r\n\r\n! ON INPUT --\r\n\r\n! N = NUMBER OF COLUMNS TO BE ROTATED.\r\n\r\n! C,S = ELEMENTS OF THE GIVENS ROTATION. THESE MAY BE\r\n! DETERMINED BY SUBROUTINE GIVENS.\r\n\r\n! X,Y = ARRAYS OF LENGTH .GE. N CONTAINING THE VECTORS TO BE ROTATED.\r\n\r\n! PARAMETERS N, C, AND S ARE NOT ALTERED BY THIS ROUTINE.\r\n\r\n! ON OUTPUT --\r\n\r\n! X,Y = ROTATED VECTORS.\r\n\r\n! MODULES REQUIRED BY ROTATE -- NONE\r\n\r\n!***********************************************************\r\n\r\nINTEGER :: i\r\nREAL :: xi, yi\r\n\r\n! LOCAL PARAMETERS --\r\n\r\n! I = DO-LOOP INDEX\r\n! XI,YI = X(I), Y(I)\r\n\r\nIF (n <= 0 .OR. (c == 1. .AND. s == 0.)) RETURN\r\nDO i = 1, n\r\n xi = x(i)\r\n yi = y(i)\r\n x(i) = c * xi + s * yi\r\n y(i) = -s * xi + c * yi\r\nEND DO\r\n\r\nRETURN\r\nEND SUBROUTINE rotate\r\n\r\n\r\n\r\nSUBROUTINE setup3(xk,yk,zk,fk,xi,yi,zi,fi,s1,s2,r,row)\r\nREAL, INTENT(IN) :: xk, yk, zk, fk, xi, yi, zi, fi, s1, s2, r\r\nREAL, INTENT(IN OUT) :: row(10)\r\n\r\n!***********************************************************\r\n\r\n! ROBERT RENKA\r\n! UNIV. OF NORTH TEXAS\r\n! (817) 565-2767\r\n\r\n! THIS ROUTINE SETS UP THE I-TH ROW OF AN AUGMENTED REGRESSION MATRIX FOR\r\n! A WEIGHTED LEAST-SQUARES FIT OF A QUADRATIC FUNCTION Q(X,Y,Z) TO A SET OF\r\n! DATA VALUES F, WHERE Q(XK,YK,ZK) = FK. THE FIRST 6 COLUMNS (QUADRATIC\r\n! TERMS) ARE SCALED BY 1/S2, AND COLUMNS 7, 8, AND 9 (LINEAR TERMS) ARE\r\n! SCALED BY 1/S1. THE WEIGHT IS (R-D)/(R*D) IF R .GT. D, AND 0 IF R .LE. D,\r\n! WHERE D IS THE DISTANCE BETWEEN NODES I AND K.\r\n\r\n! ON INPUT --\r\n\r\n! XK,YK,ZK,FK = COORDINATES AND DATA VALUE AT NODE K\r\n! (INTERPOLATED BY Q).\r\n\r\n! XI,YI,ZI,FI = COORDINATES AND DATA VALUE AT NODE I.\r\n\r\n! S1,S2 = RECIPROCALS OF THE SCALE FACTORS.\r\n\r\n! R = RADIUS OF INFLUENCE ABOUT NODE K DEFINING THE WEIGHT.\r\n\r\n! ROW = ARRAY OF LENGTH 10.\r\n\r\n! INPUT PARAMETERS ARE NOT ALTERED BY THIS ROUTINE.\r\n\r\n! ON OUTPUT --\r\n\r\n! ROW = ARRAY CONTAINING A ROW OF THE AUGMENTED REGRESSION MATRIX.\r\n\r\n! MODULES REQUIRED BY SETUP3 -- NONE\r\n\r\n! INTRINSIC FUNCTION CALLED BY SETUP3 -- SQRT\r\n\r\n!***********************************************************\r\n\r\nINTEGER :: i\r\nREAL :: dx, dy, dz, dxsq, dysq, dzsq, d, w, w1, w2\r\n\r\n! LOCAL PARAMETERS -\r\n\r\n! I = DO-LOOP INDEX\r\n! DX = XI - XK\r\n! DY = YI - YK\r\n! DZ = ZI - ZK\r\n! DXSQ = DX*DX\r\n! DYSQ = DY*DY\r\n! DZSQ = DZ*DZ\r\n! D = DISTANCE BETWEEN NODES K AND I\r\n! W = WEIGHT ASSOCIATED WITH THE ROW\r\n! W1 = W/S1\r\n! W2 = W/S2\r\n\r\ndx = xi - xk\r\ndy = yi - yk\r\ndz = zi - zk\r\ndxsq = dx * dx\r\ndysq = dy * dy\r\ndzsq = dz * dz\r\nd = SQRT(dxsq+dysq+dzsq)\r\nIF (d > 0. .AND. d < r) THEN\r\n w = (r-d) / r / d\r\n w1 = w / s1\r\n w2 = w / s2\r\n row(1) = dxsq * w2\r\n row(2) = dx * dy * w2\r\n row(3) = dysq * w2\r\n row(4) = dx * dz * w2\r\n row(5) = dy * dz * w2\r\n row(6) = dzsq * w2\r\n row(7) = dx * w1\r\n row(8) = dy * w1\r\n row(9) = dz * w1\r\n row(10) = (fi-fk) * w\r\n RETURN\r\nEND IF\r\n\r\n! NODES K AND I COINCIDE OR NODE I IS OUTSIDE OF THE RADIUS\r\n! OF INFLUENCE. SET ROW TO THE ZERO VECTOR.\r\n\r\nDO i = 1, 10\r\n row(i) = 0.\r\nEND DO\r\nRETURN\r\nEND SUBROUTINE setup3\r\n\r\n\r\n\r\nSUBROUTINE store3(n,x,y,z,nr,lcell,lnext,xyzmin,xyzdel,ier)\r\nINTEGER, INTENT(IN) :: n, nr\r\nREAL, INTENT(IN) :: x(:), y(:), z(:)\r\nINTEGER, INTENT(OUT) :: lcell(:,:,:), lnext(:), ier\r\nREAL, INTENT(OUT) :: xyzmin(3), xyzdel(3)\r\n\r\n!***********************************************************\r\n\r\n! ROBERT RENKA\r\n! UNIV. OF NORTH TEXAS\r\n! (817) 565-2767\r\n\r\n! GIVEN A SET OF N ARBITRARILY DISTRIBUTED NODES IN THREE-SPACE, THIS\r\n! SUBROUTINE CREATES A DATA STRUCTURE FOR A CELL-BASED METHOD OF SOLVING\r\n! CLOSEST-POINT PROBLEMS. THE SMALLEST BOX CONTAINING THE NODES IS\r\n! PARTITIONED INTO AN NR BY NR BY NR UNIFORM GRID OF CELLS, AND NODES ARE\r\n! ASSOCIATED WITH CELLS. IN PARTICULAR, THE DATA STRUCTURE STORES THE\r\n! INDICES OF THE NODES CONTAINED IN EACH CELL.\r\n! FOR A UNIFORM RANDOM DISTRIBUTION OF NODES, THE NEAREST NODE TO AN\r\n! ARBITRARY POINT CAN BE DETERMINED IN CONSTANT EXPECTED TIME.\r\n\r\n! ON INPUT --\r\n\r\n! N = NUMBER OF NODES. N .GE. 2.\r\n\r\n! X,Y,Z = ARRAYS OF LENGTH N CONTAINING THE CARTESIAN\r\n! COORDINATES OF THE NODES.\r\n\r\n! NR = NUMBER OF ROWS, COLUMNS, AND PLANES IN THE GRID.\r\n! THE CELL DENSITY (AVERAGE NUMBER OF NODES PER CELL) IS\r\n! D = N/(NR**3). A RECOMMENDED VALUE, BASED ON EMPIRICAL\r\n! EVIDENCE, IS D = 3\r\n! -- NR = (N/3)**(1/3). NR .GE. 1.\r\n\r\n! THE ABOVE PARAMETERS ARE NOT ALTERED BY THIS ROUTINE.\r\n\r\n! LCELL = ARRAY OF LENGTH .GE. NR**3.\r\n\r\n! LNEXT = ARRAY OF LENGTH .GE. N.\r\n\r\n! XYZMIN,XYZDEL = ARRAYS OF LENGTH .GE. 3.\r\n\r\n! ON OUTPUT --\r\n\r\n! LCELL = NR BY NR BY NR CELL ARRAY SUCH THAT\r\n! LCELL(I,J,K) CONTAINS THE INDEX (FOR X, Y,\r\n! AND Z) OF THE FIRST NODE (NODE WITH SMALLEST\r\n! INDEX) IN CELL (I,J,K), OR LCELL(I,J,K) = 0\r\n! IF NO NODES ARE CONTAINED IN THE CELL. THE\r\n! CORNER OF CELL (I,J,K) WHICH IS FARTHEST\r\n! FROM THE BOX CORNER DEFINED BY XYZMIN HAS\r\n! COORDINATES (XMIN+I*DX,YMIN+J*DY,ZMIN+K*DZ),\r\n! WHERE (XMIN,YMIN,ZMIN) ARE THE ELEMENTS OF\r\n! XYZMIN. LCELL IS NOT DEFINED IF IER .NE. 0.\r\n\r\n! LNEXT = ARRAY OF NEXT-NODE INDICES SUCH THAT\r\n! LNEXT(L) CONTAINS THE INDEX OF THE NEXT NODE\r\n! IN THE CELL WHICH CONTAINS NODE L, OR\r\n! LNEXT(L) = L IF L IS THE LAST NODE IN THE\r\n! CELL FOR L = 1,...,N. (THE NODES CONTAINED\r\n! IN A CELL ARE ORDERED BY THEIR INDICES.)\r\n! IF, FOR EXAMPLE, CELL (I,J,K) CONTAINS NODES\r\n! 2, 3, AND 5 (AND NO OTHERS), THEN\r\n! LCELL(I,J,K) = 2, LNEXT(2) = 3, LNEXT(3) =\r\n! 5, AND LNEXT(5) = 5. LNEXT IS NOT DEFINED\r\n! IF IER .NE. 0.\r\n\r\n! XYZMIN = ARRAY OF LENGTH 3 CONTAINING THE MINIMUM\r\n! NODAL COORDINATES XMIN, YMIN, AND ZMIN (IN\r\n! THAT ORDER) UNLESS IER = 1. THE OPPOSITE\r\n! CORNER OF THE BOX DEFINED BY THE NODES IS\r\n! (XMIN+NR*DX,YMIN+NR*DY,ZMIN+NR*DZ).\r\n\r\n! XYZDEL = ARRAY OF LENGTH 3 CONTAINING THE DIMENSIONS\r\n! OF THE CELLS UNLESS IER = 1. XYZDEL(1) =\r\n! (XMAX-XMIN)/NR, XYZDEL(2) = (YMAX-YMIN)/NR,\r\n! AND XYZDEL(3) = (ZMAX-ZMIN)/NR, WHERE XMIN,\r\n! XMAX, YMIN, YMAX, ZMIN, AND ZMAX ARE THE\r\n! EXTREMA OF X, Y, AND Z.\r\n\r\n! IER = ERROR INDICATOR --\r\n! IER = 0 IF NO ERRORS WERE ENCOUNTERED.\r\n! IER = 1 IF N .LT. 2 OR NR .LT. 1.\r\n! IER = 2 IF A COMPONENT OF XYZDEL IS NOT\r\n! POSITIVE.\r\n\r\n! MODULES REQUIRED BY STORE3 -- NONE\r\n\r\n! INTRINSIC FUNCTIONS CALLED BY STORE3 -- FLOAT, IFIX\r\n\r\n!***********************************************************\r\n\r\n! Local variables\r\nINTEGER :: i, j, k, l, lb, ll, nn, nnr, np1\r\nREAL :: delx, dely, delz, xmn, xmx, ymn, ymx, zmn, zmx\r\n\r\nnn = n\r\nnnr = nr\r\nIF (nn >= 2 .AND. nnr >= 1) THEN\r\n \r\n! COMPUTE THE DIMENSIONS OF THE RECTANGLE CONTAINING THE\r\n! NODES.\r\n \r\n xmn = x(1)\r\n xmx = xmn\r\n ymn = y(1)\r\n ymx = ymn\r\n zmn = z(1)\r\n zmx = zmn\r\n DO l = 2, nn\r\n IF (x(l) < xmn) xmn = x(l)\r\n IF (x(l) > xmx) xmx = x(l)\r\n IF (y(l) < ymn) ymn = y(l)\r\n IF (y(l) > ymx) ymx = y(l)\r\n IF (z(l) < zmn) zmn = z(l)\r\n IF (z(l) > zmx) zmx = z(l)\r\n END DO\r\n xyzmin(1) = xmn\r\n xyzmin(2) = ymn\r\n xyzmin(3) = zmn\r\n \r\n! COMPUTE CELL DIMENSIONS AND TEST FOR ZERO AREA.\r\n \r\n delx = (xmx-xmn) / REAL(nnr)\r\n dely = (ymx-ymn) / REAL(nnr)\r\n delz = (zmx-zmn) / REAL(nnr)\r\n xyzdel(1) = delx\r\n xyzdel(2) = dely\r\n xyzdel(3) = delz\r\n IF (delx == 0. .OR. dely == 0. .OR. delz == 0.) GO TO 60\r\n \r\n! INITIALIZE LCELL.\r\n \r\n lcell(1:nnr,1:nnr,1:nnr) = 0\r\n \r\n! LOOP ON NODES, STORING INDICES IN LCELL AND LNEXT.\r\n \r\n np1 = nn + 1\r\n DO ll = 1, nn\r\n lb = np1 - ll\r\n i = (x(lb)-xmn)/delx + 1\r\n IF (i > nnr) i = nnr\r\n j = (y(lb)-ymn)/dely + 1\r\n IF (j > nnr) j = nnr\r\n k = (z(lb)-zmn)/delz + 1\r\n IF (k > nnr) k = nnr\r\n l = lcell(i,j,k)\r\n lnext(lb) = l\r\n IF (l == 0) lnext(lb) = lb\r\n lcell(i,j,k) = lb\r\n END DO\r\n \r\n! NO ERRORS ENCOUNTERED\r\n \r\n ier = 0\r\n RETURN\r\nEND IF\r\n\r\n! INVALID INPUT PARAMETER\r\n\r\nier = 1\r\nRETURN\r\n\r\n! NONPOSITIVE XYZDEL COMPONENT\r\n\r\n60 ier = 2\r\nRETURN\r\nEND SUBROUTINE store3\r\n\r\nEND MODULE qshep3d\r\n\r\n\r\n\r\nPROGRAM qs3test\r\n\r\n! QS3TEST\r\n\r\n! THIS PROGRAM TESTS THE SCATTERED DATA INTERPOLATION\r\n! PACKAGE QSHEP3D BY PRINTING THE MAXIMUM ERRORS ASSOCIATED\r\n! WITH INTERPOLATED VALUES AND GRADIENTS ON A 5 BY 5 BY 5\r\n! UNIFORM GRID IN THE UNIT CUBE. THE DATA SET CONSISTS\r\n! OF 64 NODES WITH DATA VALUES TAKEN FROM A QUADRATIC FUNC-\r\n! TION FOR WHICH THE METHOD IS EXACT. THE RATIO OF MAXIMUM\r\n! INTERPOLATION ERROR RELATIVE TO THE MACHINE PRECISION IS\r\n! ALSO PRINTED. THIS SHOULD BE O(1). THE INTERPOLATED\r\n! VALUES FROM QS3VAL AND QS3GRD ARE COMPARED FOR AGREEMENT.\r\n\r\nUSE qshep3d\r\nIMPLICIT NONE\r\nINTEGER :: i, ier, j, k, l, lcell(3,3,3), lnext(64)\r\nREAL :: a(9,64), eps, eq, eqx, eqy, eqz, f(64), px, py, pz, &\r\n q, q1, qx, qy, qz, rmax, rq, rsq(64), x(64), xyzmin(3), &\r\n xyzdel(3), y(64), yl, z(64), zl\r\nREAL :: p(5)\r\n\r\n! QSHEP3 PARAMETERS AND LOGICAL UNIT FOR OUTPUT\r\n\r\nINTEGER, PARAMETER :: lout = 6, n = 64, nq = 17, nr = 3, nw = 32\r\n\r\n! GENERATE A 4 BY 4 BY 4 GRID OF NODES IN THE UNIT CUBE.\r\n\r\nl = 0\r\nDO k = 1, 4\r\n zl = (k-1) / 3.\r\n DO j = 1, 4\r\n yl = (j-1) / 3.\r\n DO i = 1, 4\r\n l = l + 1\r\n x(l) = (i-1) / 3.\r\n y(l) = yl\r\n z(l) = zl\r\n END DO\r\n END DO\r\nEND DO\r\n\r\n! COMPUTE THE DATA VALUES.\r\n\r\nDO l = 1, n\r\n f(l) = fq(x(l),y(l),z(l))\r\nEND DO\r\n\r\n! COMPUTE PARAMETERS DEFINING THE INTERPOLANT Q.\r\n\r\nCALL qshep3(n,x,y,z,f,nq,nw,nr,lcell,lnext,xyzmin,xyzdel,rmax,rsq,a,ier)\r\nIF (ier == 0) THEN\r\n\r\n! GENERATE A 5 BY 5 BY 5 UNIFORM GRID OF INTERPOLATION POINTS (P(I),P(J),P(K))\r\n! IN THE UNIT CUBE. THE EIGHT CORNERS COINCIDE WITH NODES.\r\n\r\n DO i = 1, 5\r\n p(i) = (i-1) / 4.\r\n END DO\r\n\r\n! COMPUTE THE MACHINE PRECISION EPS.\r\n\r\n eps = EPSILON(1.0)\r\n\r\n! COMPUTE INTERPOLATION ERRORS AND TEST FOR AGREEMENT IN THE\r\n! Q VALUES RETURNED BY QS3VAL AND QS3GRD.\r\n\r\n EQ = 0.\r\n eqx = 0.\r\n eqy = 0.\r\n eqz = 0.\r\n DO k = 1, 5\r\n pz = p(k)\r\n DO j = 1, 5\r\n py = p(j)\r\n DO i = 1, 5\r\n px = p(i)\r\n q1 = qs3val(px,py,pz,n,x,y,z,f,nr,lcell,lnext,xyzmin, &\r\n xyzdel,rmax,rsq,a)\r\n CALL qs3grd(px,py,pz,n,x,y,z,f,nr,lcell,lnext,xyzmin, &\r\n xyzdel,rmax,rsq,a,q,qx,qy,qz,ier)\r\n IF (ier /= 0) GO TO 100\r\n IF (ABS(q1-q) > 3.*ABS(q)*eps) GO TO 110\r\n EQ = MAX(EQ,ABS(fq(px,py,pz)-q))\r\n eqx = MAX(eqx,ABS(fx(px,py,pz)-qx))\r\n eqy = MAX(eqy,ABS(fy(px,py,pz)-qy))\r\n eqz = MAX(eqz,ABS(fz(px,py,pz)-qz))\r\n END DO\r\n END DO\r\n END DO\r\n\r\n! PRINT ERRORS AND THE RATIO EQ/EPS.\r\n\r\n rq = EQ / eps\r\n WRITE (lout,5000)\r\n WRITE (lout,5100) EQ, rq\r\n WRITE (lout,5200) eqx\r\n WRITE (lout,5300) eqy\r\n WRITE (lout,5400) eqz\r\n STOP\r\nEND IF\r\n\r\n! ERROR IN QSHEP3\r\n\r\nWRITE (lout,5500) ier\r\nSTOP\r\n\r\n! ERROR IN QS3GRD\r\n\r\n100 WRITE (lout,5600) ier\r\nSTOP\r\n\r\n! VALUES RETURNED BY QS3VAL AND QS3GRD DIFFER BY A RELATIVE\r\n! AMOUNT GREATER THAN 3*EPS.\r\n\r\n110 WRITE (lout,5700) q1, q\r\nSTOP\r\n\r\n5000 FORMAT (///' MAXIMUM ABSOLUTE ERRORS IN THE ', &\r\n 'INTERPOLANT Q AND PARTIAL'/' ', &\r\n 'DERIVATIVES (QX,QY,QZ) RELATIVE TO MACHINE PRECISION EPS'// &\r\n t12, 'FUNCTION MAX ERROR MAX ERROR/EPS'/)\r\n5100 FORMAT (t15, 'Q ', e9.3, ' ', f4.2)\r\n5200 FORMAT (t15, 'QX ', e9.3)\r\n5300 FORMAT (t15, 'QY ', e9.3)\r\n5400 FORMAT (t15, 'QZ ', e9.3)\r\n5500 FORMAT (//' *** ERROR IN QSHEP3 -- IER =',i2,' ***')\r\n5600 FORMAT (//' *** ERROR IN QS3GRD -- IER =',i2,' ***')\r\n5700 FORMAT (//' *** ERROR -- INTERPOLATED VALUES ', &\r\n 'Q1 (QS3VAL) AND Q2 (QS3GRD) DIFFER --'// &\r\n t7, 'Q1 = ', e21.14, ' Q2 = ', e21.14)\r\n\r\nCONTAINS\r\n\r\n! QUADRATIC TEST FUNCTION AND PARTIAL DERIVATIVES\r\n\r\n! fq(xx,yy,zz) = ((xx+2.*yy+3.*zz)/6.) ** 2\r\n! fx(xx,yy,zz) = (xx+2.*yy+3.*zz) / 18.\r\n! fy(xx,yy,zz) = (xx+2.*yy+3.*zz) / 9.\r\n! fz(xx,yy,zz) = (xx+2.*yy+3.*zz) / 6.\r\n\r\nFUNCTION fq(xx, yy, zz) RESULT(fn_val)\r\nREAL, INTENT(IN) :: xx, yy, zz\r\nREAL :: fn_val\r\n\r\nfn_val = ((xx+2.*yy+3.*zz)/6.) ** 2\r\nRETURN\r\nEND FUNCTION fq\r\n\r\n\r\n\r\nFUNCTION fx(xx, yy, zz) RESULT(fn_val)\r\nREAL, INTENT(IN) :: xx, yy, zz\r\nREAL :: fn_val\r\n\r\nfn_val = (xx+2.*yy+3.*zz) / 18.\r\nRETURN\r\nEND FUNCTION fx\r\n\r\n\r\n\r\nFUNCTION fy(xx, yy, zz) RESULT(fn_val)\r\nREAL, INTENT(IN) :: xx, yy, zz\r\nREAL :: fn_val\r\n\r\nfn_val = (xx+2.*yy+3.*zz) / 9.\r\nRETURN\r\nEND FUNCTION fy\r\n\r\n\r\n\r\nFUNCTION fz(xx, yy, zz) RESULT(fn_val)\r\nREAL, INTENT(IN) :: xx, yy, zz\r\nREAL :: fn_val\r\n\r\nfn_val = (xx+2.*yy+3.*zz) / 6.\r\nRETURN\r\nEND FUNCTION fz\r\n\r\nEND PROGRAM qs3test\r\n", "meta": {"hexsha": "1cdc7b5e5a5f083fc4b96c7c42fea1fbbac850d5", "size": 52040, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/toms661.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/toms661.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/toms661.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": 30.5399061033, "max_line_length": 79, "alphanum_fraction": 0.5001537279, "num_tokens": 17651, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582632076909, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6969943873058188}} {"text": " SUBROUTINE FFT99(A,WORK,TRIGS,IFAX,INC,JUMP,N,LOT,ISIGN)\nC\nC PURPOSE PERFORMS MULTIPLE FAST FOURIER TRANSFORMS. THIS PACKAGE\nC WILL PERFORM A NUMBER OF SIMULTANEOUS REAL/HALF-COMPLEX\nC PERIODIC FOURIER TRANSFORMS OR CORRESPONDING INVERSE\nC TRANSFORMS, I.E. GIVEN A SET OF REAL DATA VECTORS, THE\nC PACKAGE RETURNS A SET OF 'HALF-COMPLEX' FOURIER\nC COEFFICIENT VECTORS, OR VICE VERSA. THE LENGTH OF THE\nC TRANSFORMS MUST BE AN EVEN NUMBER GREATER THAN 4 THAT HAS\nC NO OTHER FACTORS EXCEPT POSSIBLY POWERS OF 2, 3, AND 5.\nC THIS IS AN ALL FORTRAN VERSION OF THE CRAYLIB PACKAGE\nC THAT IS MOSTLY WRITTEN IN CAL.\nC\nC THE PACKAGE FFT99F CONTAINS SEVERAL USER-LEVEL ROUTINES:\nC\nC SUBROUTINE SET99\nC AN INITIALIZATION ROUTINE THAT MUST BE CALLED ONCE\nC BEFORE A SEQUENCE OF CALLS TO THE FFT ROUTINES\nC (PROVIDED THAT N IS NOT CHANGED).\nC\nC SUBROUTINES FFT99 AND FFT991\nC TWO FFT ROUTINES THAT RETURN SLIGHTLY DIFFERENT\nC ARRANGEMENTS OF THE DATA IN GRIDPOINT SPACE.\nC\nC\nC ACCESS THIS FORTRAN VERSION MAY BE ACCESSED WITH\nC\nC *FORTRAN,P=XLIB,SN=FFT99F\nC\nC TO ACCESS THE CRAY OBJECT CODE, CALLING THE USER ENTRY\nC POINTS FROM A CRAY PROGRAM IS SUFFICIENT. THE SOURCE\nC FORTRAN AND CAL CODE FOR THE CRAYLIB VERSION MAY BE\nC ACCESSED USING\nC\nC FETCH P=CRAYLIB,SN=FFT99\nC FETCH P=CRAYLIB,SN=CAL99\nC\nC USAGE LET N BE OF THE FORM 2**P * 3**Q * 5**R, WHERE P .GE. 1,\nC Q .GE. 0, AND R .GE. 0. THEN A TYPICAL SEQUENCE OF\nC CALLS TO TRANSFORM A GIVEN SET OF REAL VECTORS OF LENGTH\nC N TO A SET OF 'HALF-COMPLEX' FOURIER COEFFICIENT VECTORS\nC OF LENGTH N IS\nC\nC DIMENSION IFAX(13),TRIGS(3*N/2+1),A(M*(N+2)),\nC + WORK(M*(N+1))\nC\nC CALL SET99 (TRIGS, IFAX, N)\nC CALL FFT99 (A,WORK,TRIGS,IFAX,INC,JUMP,N,M,ISIGN)\nC\nC SEE THE INDIVIDUAL WRITE-UPS FOR SET99, FFT99, AND\nC FFT991 BELOW, FOR A DETAILED DESCRIPTION OF THE\nC ARGUMENTS.\nC\nC HISTORY THE PACKAGE WAS WRITTEN BY CLIVE TEMPERTON AT ECMWF IN\nC NOVEMBER, 1978. IT WAS MODIFIED, DOCUMENTED, AND TESTED\nC FOR NCAR BY RUSS REW IN SEPTEMBER, 1980.\nC\nC-----------------------------------------------------------------------\nC\nC SUBROUTINE SET99 (TRIGS, IFAX, N)\nC\nC PURPOSE A SET-UP ROUTINE FOR FFT99 AND FFT991. IT NEED ONLY BE\nC CALLED ONCE BEFORE A SEQUENCE OF CALLS TO THE FFT\nC ROUTINES (PROVIDED THAT N IS NOT CHANGED).\nC\nC ARGUMENT IFAX(13),TRIGS(3*N/2+1)\nC DIMENSIONS\nC\nC ARGUMENTS\nC\nC ON INPUT TRIGS\nC A FLOATING POINT ARRAY OF DIMENSION 3*N/2 IF N/2 IS\nC EVEN, OR 3*N/2+1 IF N/2 IS ODD.\nC\nC IFAX\nC AN INTEGER ARRAY. THE NUMBER OF ELEMENTS ACTUALLY USED\nC WILL DEPEND ON THE FACTORIZATION OF N. DIMENSIONING\nC IFAX FOR 13 SUFFICES FOR ALL N LESS THAN A MILLION.\nC\nC N\nC AN EVEN NUMBER GREATER THAN 4 THAT HAS NO PRIME FACTOR\nC GREATER THAN 5. N IS THE LENGTH OF THE TRANSFORMS (SEE\nC THE DOCUMENTATION FOR FFT99 AND FFT991 FOR THE\nC DEFINITIONS OF THE TRANSFORMS).\nC\nC ON OUTPUT IFAX\nC CONTAINS THE FACTORIZATION OF N/2. IFAX(1) IS THE\nC NUMBER OF FACTORS, AND THE FACTORS THEMSELVES ARE STORED\nC IN IFAX(2),IFAX(3),... IF SET99 IS CALLED WITH N ODD,\nC OR IF N HAS ANY PRIME FACTORS GREATER THAN 5, IFAX(1)\nC IS SET TO -99.\nC\nC TRIGS\nC AN ARRAY OF TRIGONOMETRIC FUNCTION VALUES SUBSEQUENTLY\nC USED BY THE FFT ROUTINES.\nC\nC-----------------------------------------------------------------------\nC\nC SUBROUTINE FFT991 (A,WORK,TRIGS,IFAX,INC,JUMP,N,M,ISIGN)\nC AND\nC SUBROUTINE FFT99 (A,WORK,TRIGS,IFAX,INC,JUMP,N,M,ISIGN)\nC\nC PURPOSE PERFORM A NUMBER OF SIMULTANEOUS REAL/HALF-COMPLEX\nC PERIODIC FOURIER TRANSFORMS OR CORRESPONDING INVERSE\nC TRANSFORMS, USING ORDINARY SPATIAL ORDER OF GRIDPOINT\nC VALUES (FFT991) OR EXPLICIT CYCLIC CONTINUITY IN THE\nC GRIDPOINT VALUES (FFT99). GIVEN A SET\nC OF REAL DATA VECTORS, THE PACKAGE RETURNS A SET OF\nC 'HALF-COMPLEX' FOURIER COEFFICIENT VECTORS, OR VICE\nC VERSA. THE LENGTH OF THE TRANSFORMS MUST BE AN EVEN\nC NUMBER THAT HAS NO OTHER FACTORS EXCEPT POSSIBLY POWERS\nC OF 2, 3, AND 5. THESE VERSION OF FFT991 AND FFT99 ARE\nC OPTIMIZED FOR USE ON THE CRAY-1.\nC\nC ARGUMENT A(M*(N+2)), WORK(M*(N+1)), TRIGS(3*N/2+1), IFAX(13)\nC DIMENSIONS\nC\nC ARGUMENTS\nC\nC ON INPUT A\nC AN ARRAY OF LENGTH M*(N+2) CONTAINING THE INPUT DATA\nC OR COEFFICIENT VECTORS. THIS ARRAY IS OVERWRITTEN BY\nC THE RESULTS.\nC\nC WORK\nC A WORK ARRAY OF DIMENSION M*(N+1)\nC\nC TRIGS\nC AN ARRAY SET UP BY SET99, WHICH MUST BE CALLED FIRST.\nC\nC IFAX\nC AN ARRAY SET UP BY SET99, WHICH MUST BE CALLED FIRST.\nC\nC INC\nC THE INCREMENT (IN WORDS) BETWEEN SUCCESSIVE ELEMENTS OF\nC EACH DATA OR COEFFICIENT VECTOR (E.G. INC=1 FOR\nC CONSECUTIVELY STORED DATA).\nC\nC JUMP\nC THE INCREMENT (IN WORDS) BETWEEN THE FIRST ELEMENTS OF\nC SUCCESSIVE DATA OR COEFFICIENT VECTORS. ON THE CRAY-1,\nC TRY TO ARRANGE DATA SO THAT JUMP IS NOT A MULTIPLE OF 8\nC (TO AVOID MEMORY BANK CONFLICTS). FOR CLARIFICATION OF\nC INC AND JUMP, SEE THE EXAMPLES BELOW.\nC\nC N\nC THE LENGTH OF EACH TRANSFORM (SEE DEFINITION OF\nC TRANSFORMS, BELOW).\nC\nC M\nC THE NUMBER OF TRANSFORMS TO BE DONE SIMULTANEOUSLY.\nC\nC ISIGN\nC = +1 FOR A TRANSFORM FROM FOURIER COEFFICIENTS TO\nC GRIDPOINT VALUES.\nC = -1 FOR A TRANSFORM FROM GRIDPOINT VALUES TO FOURIER\nC COEFFICIENTS.\nC\nC ON OUTPUT A\nC IF ISIGN = +1, AND M COEFFICIENT VECTORS ARE SUPPLIED\nC EACH CONTAINING THE SEQUENCE:\nC\nC A(0),B(0),A(1),B(1),...,A(N/2),B(N/2) (N+2 VALUES)\nC\nC THEN THE RESULT CONSISTS OF M DATA VECTORS EACH\nC CONTAINING THE CORRESPONDING N+2 GRIDPOINT VALUES:\nC\nC FOR FFT991, X(0), X(1), X(2),...,X(N-1),0,0.\nC FOR FFT99, X(N-1),X(0),X(1),X(2),...,X(N-1),X(0).\nC (EXPLICIT CYCLIC CONTINUITY)\nC\nC WHEN ISIGN = +1, THE TRANSFORM IS DEFINED BY:\nC X(J)=SUM(K=0,...,N-1)(C(K)*EXP(2*I*J*K*PI/N))\nC WHERE C(K)=A(K)+I*B(K) AND C(N-K)=A(K)-I*B(K)\nC AND I=SQRT (-1)\nC\nC IF ISIGN = -1, AND M DATA VECTORS ARE SUPPLIED EACH\nC CONTAINING A SEQUENCE OF GRIDPOINT VALUES X(J) AS\nC DEFINED ABOVE, THEN THE RESULT CONSISTS OF M VECTORS\nC EACH CONTAINING THE CORRESPONDING FOURIER COFFICIENTS\nC A(K), B(K), 0 .LE. K .LE N/2.\nC\nC WHEN ISIGN = -1, THE INVERSE TRANSFORM IS DEFINED BY:\nC C(K)=(1/N)*SUM(J=0,...,N-1)(X(J)*EXP(-2*I*J*K*PI/N))\nC WHERE C(K)=A(K)+I*B(K) AND I=SQRT(-1)\nC\nC A CALL WITH ISIGN=+1 FOLLOWED BY A CALL WITH ISIGN=-1\nC (OR VICE VERSA) RETURNS THE ORIGINAL DATA.\nC\nC NOTE: THE FACT THAT THE GRIDPOINT VALUES X(J) ARE REAL\nC IMPLIES THAT B(0)=B(N/2)=0. FOR A CALL WITH ISIGN=+1,\nC IT IS NOT ACTUALLY NECESSARY TO SUPPLY THESE ZEROS.\nC\nC EXAMPLES GIVEN 19 DATA VECTORS EACH OF LENGTH 64 (+2 FOR EXPLICIT\nC CYCLIC CONTINUITY), COMPUTE THE CORRESPONDING VECTORS OF\nC FOURIER COEFFICIENTS. THE DATA MAY, FOR EXAMPLE, BE\nC ARRANGED LIKE THIS:\nC\nC FIRST DATA A(1)= . . . A(66)= A(70)\nC VECTOR X(63) X(0) X(1) X(2) ... X(63) X(0) (4 EMPTY LOCATIONS)\nC\nC SECOND DATA A(71)= . . . A(140)\nC VECTOR X(63) X(0) X(1) X(2) ... X(63) X(0) (4 EMPTY LOCATIONS)\nC\nC AND SO ON. HERE INC=1, JUMP=70, N=64, M=19, ISIGN=-1,\nC AND FFT99 SHOULD BE USED (BECAUSE OF THE EXPLICIT CYCLIC\nC CONTINUITY).\nC\nC ALTERNATIVELY THE DATA MAY BE ARRANGED LIKE THIS:\nC\nC FIRST SECOND LAST\nC DATA DATA DATA\nC VECTOR VECTOR VECTOR\nC\nC A(1)= A(2)= A(19)=\nC\nC X(63) X(63) . . . X(63)\nC A(20)= X(0) X(0) . . . X(0)\nC A(39)= X(1) X(1) . . . X(1)\nC . . .\nC . . .\nC . . .\nC\nC IN WHICH CASE WE HAVE INC=19, JUMP=1, AND THE REMAINING\nC PARAMETERS ARE THE SAME AS BEFORE. IN EITHER CASE, EACH\nC COEFFICIENT VECTOR OVERWRITES THE CORRESPONDING INPUT\nC DATA VECTOR.\nC\nC-----------------------------------------------------------------------\n DIMENSION A(JUMP*LOT),WORK((N+1)*LOT),TRIGS(3*N/2+1),IFAX(13)\nC\nC SUBROUTINE \"FFT99\" - MULTIPLE FAST REAL PERIODIC TRANSFORM\nC CORRESPONDING TO OLD SCALAR ROUTINE FFT9\nC PROCEDURE USED TO CONVERT TO HALF-LENGTH COMPLEX TRANSFORM\nC IS GIVEN BY COOLEY, LEWIS AND WELCH (J. SOUND VIB., VOL. 12\nC (1970), 315-337)\nC\nC A IS THE ARRAY CONTAINING INPUT AND OUTPUT DATA\nC WORK IS AN AREA OF SIZE (N+1)*LOT\nC TRIGS IS A PREVIOUSLY PREPARED LIST OF TRIG FUNCTION VALUES\nC IFAX IS A PREVIOUSLY PREPARED LIST OF FACTORS OF N/2\nC INC IS THE INCREMENT WITHIN EACH DATA 'VECTOR'\nC (E.G. INC=1 FOR CONSECUTIVELY STORED DATA)\nC JUMP IS THE INCREMENT BETWEEN THE START OF EACH DATA VECTOR\nC N IS THE LENGTH OF THE DATA VECTORS\nC LOT IS THE NUMBER OF DATA VECTORS\nC ISIGN = +1 FOR TRANSFORM FROM SPECTRAL TO GRIDPOINT\nC = -1 FOR TRANSFORM FROM GRIDPOINT TO SPECTRAL\nC\nC ORDERING OF COEFFICIENTS:\nC A(0),B(0),A(1),B(1),A(2),B(2),...,A(N/2),B(N/2)\nC WHERE B(0)=B(N/2)=0; (N+2) LOCATIONS REQUIRED\nC\nC ORDERING OF DATA:\nC X(N-1),X(0),X(1),X(2),...,X(N),X(0)\nC I.E. EXPLICIT CYCLIC CONTINUITY; (N+2) LOCATIONS REQUIRED\nC\nC VECTORIZATION IS ACHIEVED ON CRAY BY DOING THE TRANSFORMS IN\nC PARALLEL\nC\nC *** N.B. N IS ASSUMED TO BE AN EVEN NUMBER\nC\nC DEFINITION OF TRANSFORMS:\nC -------------------------\nC\nC ISIGN=+1: X(J)=SUM(K=0,...,N-1)(C(K)*EXP(2*I*J*K*PI/N))\nC WHERE C(K)=A(K)+I*B(K) AND C(N-K)=A(K)-I*B(K)\nC\nC ISIGN=-1: A(K)=(1/N)*SUM(J=0,...,N-1)(X(J)*COS(2*J*K*PI/N))\nC B(K)=-(1/N)*SUM(J=0,...,N-1)(X(J)*SIN(2*J*K*PI/N))\nC\nC\nC\nC\n NFAX=IFAX(1)\n NX=N+1\n NH=N/2\n INK=INC+INC\n IF (ISIGN.EQ.+1) GO TO 30\nC\nC IF NECESSARY, TRANSFER DATA TO WORK AREA\n IGO=50\n IF (MOD(NFAX,2).EQ.1) GOTO 40\n IBASE=INC+1\n JBASE=1\n DO 20 L=1,LOT\n I=IBASE\n J=JBASE\nCDIR$ IVDEP\n DO 10 M=1,N\n WORK(J)=A(I)\n I=I+INC\n J=J+1\n 10 CONTINUE\n IBASE=IBASE+JUMP\n JBASE=JBASE+NX\n 20 CONTINUE\nC\n IGO=60\n GO TO 40\nC\nC PREPROCESSING (ISIGN=+1)\nC ------------------------\nC\n 30 CONTINUE\n CALL FFT99A(A,WORK,TRIGS,INC,JUMP,N,LOT)\n IGO=60\nC\nC COMPLEX TRANSFORM\nC -----------------\nC\n 40 CONTINUE\n IA=INC+1\n LA=1\n DO 80 K=1,NFAX\n IF (IGO.EQ.60) GO TO 60\n 50 CONTINUE\n CALL VPASSM(A(IA),A(IA+INC),WORK(1),WORK(2),TRIGS,\n * INK,2,JUMP,NX,LOT,NH,IFAX(K+1),LA)\n IGO=60\n GO TO 70\n 60 CONTINUE\n CALL VPASSM(WORK(1),WORK(2),A(IA),A(IA+INC),TRIGS,\n * 2,INK,NX,JUMP,LOT,NH,IFAX(K+1),LA)\n IGO=50\n 70 CONTINUE\n LA=LA*IFAX(K+1)\n 80 CONTINUE\nC\n IF (ISIGN.EQ.-1) GO TO 130\nC\nC IF NECESSARY, TRANSFER DATA FROM WORK AREA\n IF (MOD(NFAX,2).EQ.1) GO TO 110\n IBASE=1\n JBASE=IA\n DO 100 L=1,LOT\n I=IBASE\n J=JBASE\nCDIR$ IVDEP\n DO 90 M=1,N\n A(J)=WORK(I)\n I=I+1\n J=J+INC\n 90 CONTINUE\n IBASE=IBASE+NX\n JBASE=JBASE+JUMP\n 100 CONTINUE\nC\nC FILL IN CYCLIC BOUNDARY POINTS\n 110 CONTINUE\n IA=1\n IB=N*INC+1\nCDIR$ IVDEP\n DO 120 L=1,LOT\n A(IA)=A(IB)\n A(IB+INC)=A(IA+INC)\n IA=IA+JUMP\n IB=IB+JUMP\n 120 CONTINUE\n GO TO 140\nC\nC POSTPROCESSING (ISIGN=-1):\nC --------------------------\nC\n 130 CONTINUE\n CALL FFT99B(WORK,A,TRIGS,INC,JUMP,N,LOT)\nC\n 140 CONTINUE\n RETURN\n END\n SUBROUTINE FFT99A(A,WORK,TRIGS,INC,JUMP,N,LOT)\n DIMENSION A(JUMP*LOT),WORK((N+1)*LOT),TRIGS(3*N/2+1)\nC\nC SUBROUTINE FFT99A - PREPROCESSING STEP FOR FFT99, ISIGN=+1\nC (SPECTRAL TO GRIDPOINT TRANSFORM)\nC\n NH=N/2\n NX=N+1\n INK=INC+INC\nC\nC A(0) AND A(N/2)\n IA=1\n IB=N*INC+1\n JA=1\n JB=2\nCDIR$ IVDEP\n DO 10 L=1,LOT\n WORK(JA)=A(IA)+A(IB)\n WORK(JB)=A(IA)-A(IB)\n IA=IA+JUMP\n IB=IB+JUMP\n JA=JA+NX\n JB=JB+NX\n 10 CONTINUE\nC\nC REMAINING WAVENUMBERS\n IABASE=2*INC+1\n IBBASE=(N-2)*INC+1\n JABASE=3\n JBBASE=N-1\nC\n DO 30 K=3,NH,2\n IA=IABASE\n IB=IBBASE\n JA=JABASE\n JB=JBBASE\n C=TRIGS(N+K)\n S=TRIGS(N+K+1)\nCDIR$ IVDEP\n DO 20 L=1,LOT\n WORK(JA)=(A(IA)+A(IB))-\n * (S*(A(IA)-A(IB))+C*(A(IA+INC)+A(IB+INC)))\n WORK(JB)=(A(IA)+A(IB))+\n * (S*(A(IA)-A(IB))+C*(A(IA+INC)+A(IB+INC)))\n WORK(JA+1)=(C*(A(IA)-A(IB))-S*(A(IA+INC)+A(IB+INC)))+\n * (A(IA+INC)-A(IB+INC))\n WORK(JB+1)=(C*(A(IA)-A(IB))-S*(A(IA+INC)+A(IB+INC)))-\n * (A(IA+INC)-A(IB+INC))\n IA=IA+JUMP\n IB=IB+JUMP\n JA=JA+NX\n JB=JB+NX\n 20 CONTINUE\n IABASE=IABASE+INK\n IBBASE=IBBASE-INK\n JABASE=JABASE+2\n JBBASE=JBBASE-2\n 30 CONTINUE\nC\n IF (IABASE.NE.IBBASE) GO TO 50\nC WAVENUMBER N/4 (IF IT EXISTS)\n IA=IABASE\n JA=JABASE\nCDIR$ IVDEP\n DO 40 L=1,LOT\n WORK(JA)=2.0*A(IA)\n WORK(JA+1)=-2.0*A(IA+INC)\n IA=IA+JUMP\n JA=JA+NX\n 40 CONTINUE\nC\n 50 CONTINUE\n RETURN\n END\n SUBROUTINE FFT99B(WORK,A,TRIGS,INC,JUMP,N,LOT)\n DIMENSION WORK((N+1)*LOT),A(JUMP*LOT),TRIGS(3*N/2+1)\nC\nC SUBROUTINE FFT99B - POSTPROCESSING STEP FOR FFT99, ISIGN=-1\nC (GRIDPOINT TO SPECTRAL TRANSFORM)\nC\n NH=N/2\n NX=N+1\n INK=INC+INC\nC\nC A(0) AND A(N/2)\n SCALE=1.0/FLOAT(N)\n IA=1\n IB=2\n JA=1\n JB=N*INC+1\nCDIR$ IVDEP\n DO 10 L=1,LOT\n A(JA)=SCALE*(WORK(IA)+WORK(IB))\n A(JB)=SCALE*(WORK(IA)-WORK(IB))\n A(JA+INC)=0.0\n A(JB+INC)=0.0\n IA=IA+NX\n IB=IB+NX\n JA=JA+JUMP\n JB=JB+JUMP\n 10 CONTINUE\nC\nC REMAINING WAVENUMBERS\n SCALE=0.5*SCALE\n IABASE=3\n IBBASE=N-1\n JABASE=2*INC+1\n JBBASE=(N-2)*INC+1\nC\n DO 30 K=3,NH,2\n IA=IABASE\n IB=IBBASE\n JA=JABASE\n JB=JBBASE\n C=TRIGS(N+K)\n S=TRIGS(N+K+1)\nCDIR$ IVDEP\n DO 20 L=1,LOT\n A(JA)=SCALE*((WORK(IA)+WORK(IB))\n * +(C*(WORK(IA+1)+WORK(IB+1))+S*(WORK(IA)-WORK(IB))))\n A(JB)=SCALE*((WORK(IA)+WORK(IB))\n * -(C*(WORK(IA+1)+WORK(IB+1))+S*(WORK(IA)-WORK(IB))))\n A(JA+INC)=SCALE*((C*(WORK(IA)-WORK(IB))-S*(WORK(IA+1)+WORK(IB+1)))\n * +(WORK(IB+1)-WORK(IA+1)))\n A(JB+INC)=SCALE*((C*(WORK(IA)-WORK(IB))-S*(WORK(IA+1)+WORK(IB+1)))\n * -(WORK(IB+1)-WORK(IA+1)))\n IA=IA+NX\n IB=IB+NX\n JA=JA+JUMP\n JB=JB+JUMP\n 20 CONTINUE\n IABASE=IABASE+2\n IBBASE=IBBASE-2\n JABASE=JABASE+INK\n JBBASE=JBBASE-INK\n 30 CONTINUE\nC\n IF (IABASE.NE.IBBASE) GO TO 50\nC WAVENUMBER N/4 (IF IT EXISTS)\n IA=IABASE\n JA=JABASE\n SCALE=2.0*SCALE\nCDIR$ IVDEP\n DO 40 L=1,LOT\n A(JA)=SCALE*WORK(IA)\n A(JA+INC)=-SCALE*WORK(IA+1)\n IA=IA+NX\n JA=JA+JUMP\n 40 CONTINUE\nC\n 50 CONTINUE\n RETURN\n END\n SUBROUTINE FFT991(A,WORK,TRIGS,IFAX,INC,JUMP,N,LOT,ISIGN)\n DIMENSION A(JUMP*LOT),WORK((N+1)*LOT),TRIGS(3*N/2+1),IFAX(13)\nC\nC SUBROUTINE \"FFT991\" - MULTIPLE REAL/HALF-COMPLEX PERIODIC\nC FAST FOURIER TRANSFORM\nC\nC SAME AS FFT99 EXCEPT THAT ORDERING OF DATA CORRESPONDS TO\nC THAT IN MRFFT2\nC\nC PROCEDURE USED TO CONVERT TO HALF-LENGTH COMPLEX TRANSFORM\nC IS GIVEN BY COOLEY, LEWIS AND WELCH (J. SOUND VIB., VOL. 12\nC (1970), 315-337)\nC\nC A IS THE ARRAY CONTAINING INPUT AND OUTPUT DATA\nC WORK IS AN AREA OF SIZE (N+1)*LOT\nC TRIGS IS A PREVIOUSLY PREPARED LIST OF TRIG FUNCTION VALUES\nC IFAX IS A PREVIOUSLY PREPARED LIST OF FACTORS OF N/2\nC INC IS THE INCREMENT WITHIN EACH DATA 'VECTOR'\nC (E.G. INC=1 FOR CONSECUTIVELY STORED DATA)\nC JUMP IS THE INCREMENT BETWEEN THE START OF EACH DATA VECTOR\nC N IS THE LENGTH OF THE DATA VECTORS\nC LOT IS THE NUMBER OF DATA VECTORS\nC ISIGN = +1 FOR TRANSFORM FROM SPECTRAL TO GRIDPOINT\nC = -1 FOR TRANSFORM FROM GRIDPOINT TO SPECTRAL\nC\nC ORDERING OF COEFFICIENTS:\nC A(0),B(0),A(1),B(1),A(2),B(2),...,A(N/2),B(N/2)\nC WHERE B(0)=B(N/2)=0; (N+2) LOCATIONS REQUIRED\nC\nC ORDERING OF DATA:\nC X(0),X(1),X(2),...,X(N-1)\nC\nC VECTORIZATION IS ACHIEVED ON CRAY BY DOING THE TRANSFORMS IN\nC PARALLEL\nC\nC *** N.B. N IS ASSUMED TO BE AN EVEN NUMBER\nC\nC DEFINITION OF TRANSFORMS:\nC -------------------------\nC\nC ISIGN=+1: X(J)=SUM(K=0,...,N-1)(C(K)*EXP(2*I*J*K*PI/N))\nC WHERE C(K)=A(K)+I*B(K) AND C(N-K)=A(K)-I*B(K)\nC\nC ISIGN=-1: A(K)=(1/N)*SUM(J=0,...,N-1)(X(J)*COS(2*J*K*PI/N))\nC B(K)=-(1/N)*SUM(J=0,...,N-1)(X(J)*SIN(2*J*K*PI/N))\nC\nC\nC\n NFAX=IFAX(1)\n NX=N+1\n NH=N/2\n INK=INC+INC\n IF (ISIGN.EQ.+1) GO TO 30\nC\nC IF NECESSARY, TRANSFER DATA TO WORK AREA\n IGO=50\n IF (MOD(NFAX,2).EQ.1) GOTO 40\n IBASE=1\n JBASE=1\n DO 20 L=1,LOT\n I=IBASE\n J=JBASE\nCDIR$ IVDEP\n DO 10 M=1,N\n WORK(J)=A(I)\n I=I+INC\n J=J+1\n 10 CONTINUE\n IBASE=IBASE+JUMP\n JBASE=JBASE+NX\n 20 CONTINUE\nC\n IGO=60\n GO TO 40\nC\nC PREPROCESSING (ISIGN=+1)\nC ------------------------\nC\n 30 CONTINUE\n CALL FFT99A(A,WORK,TRIGS,INC,JUMP,N,LOT)\n IGO=60\nC\nC COMPLEX TRANSFORM\nC -----------------\nC\n 40 CONTINUE\n IA=1\n LA=1\n DO 80 K=1,NFAX\n IF (IGO.EQ.60) GO TO 60\n 50 CONTINUE\n CALL VPASSM(A(IA),A(IA+INC),WORK(1),WORK(2),TRIGS,\n * INK,2,JUMP,NX,LOT,NH,IFAX(K+1),LA)\n IGO=60\n GO TO 70\n 60 CONTINUE\n CALL VPASSM(WORK(1),WORK(2),A(IA),A(IA+INC),TRIGS,\n * 2,INK,NX,JUMP,LOT,NH,IFAX(K+1),LA)\n IGO=50\n 70 CONTINUE\n LA=LA*IFAX(K+1)\n 80 CONTINUE\nC\n IF (ISIGN.EQ.-1) GO TO 130\nC\nC IF NECESSARY, TRANSFER DATA FROM WORK AREA\n IF (MOD(NFAX,2).EQ.1) GO TO 110\n IBASE=1\n JBASE=1\n DO 100 L=1,LOT\n I=IBASE\n J=JBASE\nCDIR$ IVDEP\n DO 90 M=1,N\n A(J)=WORK(I)\n I=I+1\n J=J+INC\n 90 CONTINUE\n IBASE=IBASE+NX\n JBASE=JBASE+JUMP\n 100 CONTINUE\nC\nC FILL IN ZEROS AT END\n 110 CONTINUE\n IB=N*INC+1\nCDIR$ IVDEP\n DO 120 L=1,LOT\n A(IB)=0.0\n A(IB+INC)=0.0\n IB=IB+JUMP\n 120 CONTINUE\n GO TO 140\nC\nC POSTPROCESSING (ISIGN=-1):\nC --------------------------\nC\n 130 CONTINUE\n CALL FFT99B(WORK,A,TRIGS,INC,JUMP,N,LOT)\nC\n 140 CONTINUE\n RETURN\n END\n SUBROUTINE SET99 (TRIGS, IFAX, N)\n DIMENSION IFAX(13),TRIGS(3*N/2+1)\nC\nC MODE 3 IS USED FOR REAL/HALF-COMPLEX TRANSFORMS. IT IS POSSIBLE\nC TO DO COMPLEX/COMPLEX TRANSFORMS WITH OTHER VALUES OF MODE, BUT\nC DOCUMENTATION OF THE DETAILS WERE NOT AVAILABLE WHEN THIS ROUTINE\nC WAS WRITTEN.\nC\n DATA MODE /3/\n CALL FAX (IFAX, N, MODE)\n I = IFAX(1)\n IF (IFAX(I+1) .GT. 5 .OR. N .LE. 4) IFAX(1) = -99\n IF (IFAX(1) .LE. 0 ) THEN \n WRITE(6,*) ' SET99 -- INVALID N'\n STOP'SET99'\n ENDIF\n CALL FFTRIG (TRIGS, N, MODE)\n RETURN\n END\n SUBROUTINE FAX(IFAX,N,MODE)\n DIMENSION IFAX(13)\n NN=N\n IF (IABS(MODE).EQ.1) GO TO 10\n IF (IABS(MODE).EQ.8) GO TO 10\n NN=N/2\n IF ((NN+NN).EQ.N) GO TO 10\n IFAX(1)=-99\n RETURN\n 10 K=1\nC TEST FOR FACTORS OF 4\n 20 IF (MOD(NN,4).NE.0) GO TO 30\n K=K+1\n IFAX(K)=4\n NN=NN/4\n IF (NN.EQ.1) GO TO 80\n GO TO 20\nC TEST FOR EXTRA FACTOR OF 2\n 30 IF (MOD(NN,2).NE.0) GO TO 40\n K=K+1\n IFAX(K)=2\n NN=NN/2\n IF (NN.EQ.1) GO TO 80\nC TEST FOR FACTORS OF 3\n 40 IF (MOD(NN,3).NE.0) GO TO 50\n K=K+1\n IFAX(K)=3\n NN=NN/3\n IF (NN.EQ.1) GO TO 80\n GO TO 40\nC NOW FIND REMAINING FACTORS\n 50 L=5\n INC=2\nC INC ALTERNATELY TAKES ON VALUES 2 AND 4\n 60 IF (MOD(NN,L).NE.0) GO TO 70\n K=K+1\n IFAX(K)=L\n NN=NN/L\n IF (NN.EQ.1) GO TO 80\n GO TO 60\n 70 L=L+INC\n INC=6-INC\n GO TO 60\n 80 IFAX(1)=K-1\nC IFAX(1) CONTAINS NUMBER OF FACTORS\n NFAX=IFAX(1)\nC SORT FACTORS INTO ASCENDING ORDER\n IF (NFAX.EQ.1) GO TO 110\n DO 100 II=2,NFAX\n ISTOP=NFAX+2-II\n DO 90 I=2,ISTOP\n IF (IFAX(I+1).GE.IFAX(I)) GO TO 90\n ITEM=IFAX(I)\n IFAX(I)=IFAX(I+1)\n IFAX(I+1)=ITEM\n 90 CONTINUE\n 100 CONTINUE\n 110 CONTINUE\n RETURN\n END\n SUBROUTINE FFTRIG(TRIGS,N,MODE)\n DIMENSION TRIGS(3*N/2+1)\n PI=2.0*ASIN(1.0)\n IMODE=IABS(MODE)\n NN=N\n IF (IMODE.GT.1.AND.IMODE.LT.6) NN=N/2\n DEL=(PI+PI)/FLOAT(NN)\n L=NN+NN\n DO 10 I=1,L,2\n ANGLE=0.5*FLOAT(I-1)*DEL\n TRIGS(I)=COS(ANGLE)\n TRIGS(I+1)=SIN(ANGLE)\n 10 CONTINUE\n IF (IMODE.EQ.1) RETURN\n IF (IMODE.EQ.8) RETURN\n DEL=0.5*DEL\n NH=(NN+1)/2\n L=NH+NH\n LA=NN+NN\n DO 20 I=1,L,2\n ANGLE=0.5*FLOAT(I-1)*DEL\n TRIGS(LA+I)=COS(ANGLE)\n TRIGS(LA+I+1)=SIN(ANGLE)\n 20 CONTINUE\n IF (IMODE.LE.3) RETURN\n DEL=0.5*DEL\n LA=LA+NN\n IF (MODE.EQ.5) GO TO 40\n DO 30 I=2,NN\n ANGLE=FLOAT(I-1)*DEL\n TRIGS(LA+I)=2.0*SIN(ANGLE)\n 30 CONTINUE\n RETURN\n 40 CONTINUE\n DEL=0.5*DEL\n DO 50 I=2,N\n ANGLE=FLOAT(I-1)*DEL\n TRIGS(LA+I)=SIN(ANGLE)\n 50 CONTINUE\n RETURN\n END\n SUBROUTINE VPASSM(A,B,C,D,TRIGS,INC1,INC2,INC3,INC4,LOT,N,IFAC,LA)\n DIMENSION A((N+1)*2*LOT),B((N+1)*2*LOT),\n & C((N+1)*2*LOT),D((N+1)*2*LOT),\n & TRIGS(3*N/2+1)\nC\nC SUBROUTINE \"VPASSM\" - MULTIPLE VERSION OF \"VPASSA\"\nC PERFORMS ONE PASS THROUGH DATA\nC AS PART OF MULTIPLE COMPLEX FFT ROUTINE\nC A IS FIRST REAL INPUT VECTOR\nC B IS FIRST IMAGINARY INPUT VECTOR\nC C IS FIRST REAL OUTPUT VECTOR\nC D IS FIRST IMAGINARY OUTPUT VECTOR\nC TRIGS IS PRECALCULATED TABLE OF SINES \" COSINES\nC INC1 IS ADDRESSING INCREMENT FOR A AND B\nC INC2 IS ADDRESSING INCREMENT FOR C AND D\nC INC3 IS ADDRESSING INCREMENT BETWEEN A\"S & B\"S\nC INC4 IS ADDRESSING INCREMENT BETWEEN C\"S & D\"S\nC LOT IS THE NUMBER OF VECTORS\nC N IS LENGTH OF VECTORS\nC IFAC IS CURRENT FACTOR OF N\nC LA IS PRODUCT OF PREVIOUS FACTORS\nC\n DATA SIN36/0.587785252292473/,COS36/0.809016994374947/,\n * SIN72/0.951056516295154/,COS72/0.309016994374947/,\n * SIN60/0.866025403784437/\nC\n M=N/IFAC\n IINK=M*INC1\n JINK=LA*INC2\n JUMP=(IFAC-1)*JINK\n IBASE=0\n JBASE=0\n IGO=IFAC-1\n IF (IGO.GT.4) RETURN\n GO TO (10,50,90,130),IGO\nC\nC CODING FOR FACTOR 2\nC\n 10 IA=1\n JA=1\n IB=IA+IINK\n JB=JA+JINK\n DO 20 L=1,LA\n I=IBASE\n J=JBASE\nCDIR$ IVDEP\n DO 15 IJK=1,LOT\n C(JA+J)=A(IA+I)+A(IB+I)\n D(JA+J)=B(IA+I)+B(IB+I)\n C(JB+J)=A(IA+I)-A(IB+I)\n D(JB+J)=B(IA+I)-B(IB+I)\n I=I+INC3\n J=J+INC4\n 15 CONTINUE\n IBASE=IBASE+INC1\n JBASE=JBASE+INC2\n 20 CONTINUE\n IF (LA.EQ.M) RETURN\n LA1=LA+1\n JBASE=JBASE+JUMP\n DO 40 K=LA1,M,LA\n KB=K+K-2\n C1=TRIGS(KB+1)\n S1=TRIGS(KB+2)\n DO 30 L=1,LA\n I=IBASE\n J=JBASE\nCDIR$ IVDEP\n DO 25 IJK=1,LOT\n C(JA+J)=A(IA+I)+A(IB+I)\n D(JA+J)=B(IA+I)+B(IB+I)\n C(JB+J)=C1*(A(IA+I)-A(IB+I))-S1*(B(IA+I)-B(IB+I))\n D(JB+J)=S1*(A(IA+I)-A(IB+I))+C1*(B(IA+I)-B(IB+I))\n I=I+INC3\n J=J+INC4\n 25 CONTINUE\n IBASE=IBASE+INC1\n JBASE=JBASE+INC2\n 30 CONTINUE\n JBASE=JBASE+JUMP\n 40 CONTINUE\n RETURN\nC\nC CODING FOR FACTOR 3\nC\n 50 IA=1\n JA=1\n IB=IA+IINK\n JB=JA+JINK\n IC=IB+IINK\n JC=JB+JINK\n DO 60 L=1,LA\n I=IBASE\n J=JBASE\nCDIR$ IVDEP\n DO 55 IJK=1,LOT\n C(JA+J)=A(IA+I)+(A(IB+I)+A(IC+I))\n D(JA+J)=B(IA+I)+(B(IB+I)+B(IC+I))\n C(JB+J)=(A(IA+I)-0.5*(A(IB+I)+A(IC+I)))-(SIN60*(B(IB+I)-B(IC+I)))\n C(JC+J)=(A(IA+I)-0.5*(A(IB+I)+A(IC+I)))+(SIN60*(B(IB+I)-B(IC+I)))\n D(JB+J)=(B(IA+I)-0.5*(B(IB+I)+B(IC+I)))+(SIN60*(A(IB+I)-A(IC+I)))\n D(JC+J)=(B(IA+I)-0.5*(B(IB+I)+B(IC+I)))-(SIN60*(A(IB+I)-A(IC+I)))\n I=I+INC3\n J=J+INC4\n 55 CONTINUE\n IBASE=IBASE+INC1\n JBASE=JBASE+INC2\n 60 CONTINUE\n IF (LA.EQ.M) RETURN\n LA1=LA+1\n JBASE=JBASE+JUMP\n DO 80 K=LA1,M,LA\n KB=K+K-2\n KC=KB+KB\n C1=TRIGS(KB+1)\n S1=TRIGS(KB+2)\n C2=TRIGS(KC+1)\n S2=TRIGS(KC+2)\n DO 70 L=1,LA\n I=IBASE\n J=JBASE\nCDIR$ IVDEP\n DO 65 IJK=1,LOT\n C(JA+J)=A(IA+I)+(A(IB+I)+A(IC+I))\n D(JA+J)=B(IA+I)+(B(IB+I)+B(IC+I))\n C(JB+J)=\n * C1*((A(IA+I)-0.5*(A(IB+I)+A(IC+I)))-(SIN60*(B(IB+I)-B(IC+I))))\n * -S1*((B(IA+I)-0.5*(B(IB+I)+B(IC+I)))+(SIN60*(A(IB+I)-A(IC+I))))\n D(JB+J)=\n * S1*((A(IA+I)-0.5*(A(IB+I)+A(IC+I)))-(SIN60*(B(IB+I)-B(IC+I))))\n * +C1*((B(IA+I)-0.5*(B(IB+I)+B(IC+I)))+(SIN60*(A(IB+I)-A(IC+I))))\n C(JC+J)=\n * C2*((A(IA+I)-0.5*(A(IB+I)+A(IC+I)))+(SIN60*(B(IB+I)-B(IC+I))))\n * -S2*((B(IA+I)-0.5*(B(IB+I)+B(IC+I)))-(SIN60*(A(IB+I)-A(IC+I))))\n D(JC+J)=\n * S2*((A(IA+I)-0.5*(A(IB+I)+A(IC+I)))+(SIN60*(B(IB+I)-B(IC+I))))\n * +C2*((B(IA+I)-0.5*(B(IB+I)+B(IC+I)))-(SIN60*(A(IB+I)-A(IC+I))))\n I=I+INC3\n J=J+INC4\n 65 CONTINUE\n IBASE=IBASE+INC1\n JBASE=JBASE+INC2\n 70 CONTINUE\n JBASE=JBASE+JUMP\n 80 CONTINUE\n RETURN\nC\nC CODING FOR FACTOR 4\nC\n 90 IA=1\n JA=1\n IB=IA+IINK\n JB=JA+JINK\n IC=IB+IINK\n JC=JB+JINK\n ID=IC+IINK\n JD=JC+JINK\n DO 100 L=1,LA\n I=IBASE\n J=JBASE\nCDIR$ IVDEP\n DO 95 IJK=1,LOT\n C(JA+J)=(A(IA+I)+A(IC+I))+(A(IB+I)+A(ID+I))\n C(JC+J)=(A(IA+I)+A(IC+I))-(A(IB+I)+A(ID+I))\n D(JA+J)=(B(IA+I)+B(IC+I))+(B(IB+I)+B(ID+I))\n D(JC+J)=(B(IA+I)+B(IC+I))-(B(IB+I)+B(ID+I))\n C(JB+J)=(A(IA+I)-A(IC+I))-(B(IB+I)-B(ID+I))\n C(JD+J)=(A(IA+I)-A(IC+I))+(B(IB+I)-B(ID+I))\n D(JB+J)=(B(IA+I)-B(IC+I))+(A(IB+I)-A(ID+I))\n D(JD+J)=(B(IA+I)-B(IC+I))-(A(IB+I)-A(ID+I))\n I=I+INC3\n J=J+INC4\n 95 CONTINUE\n IBASE=IBASE+INC1\n JBASE=JBASE+INC2\n 100 CONTINUE\n IF (LA.EQ.M) RETURN\n LA1=LA+1\n JBASE=JBASE+JUMP\n DO 120 K=LA1,M,LA\n KB=K+K-2\n KC=KB+KB\n KD=KC+KB\n C1=TRIGS(KB+1)\n S1=TRIGS(KB+2)\n C2=TRIGS(KC+1)\n S2=TRIGS(KC+2)\n C3=TRIGS(KD+1)\n S3=TRIGS(KD+2)\n DO 110 L=1,LA\n I=IBASE\n J=JBASE\nCDIR$ IVDEP\n DO 105 IJK=1,LOT\n C(JA+J)=(A(IA+I)+A(IC+I))+(A(IB+I)+A(ID+I))\n D(JA+J)=(B(IA+I)+B(IC+I))+(B(IB+I)+B(ID+I))\n C(JC+J)=\n * C2*((A(IA+I)+A(IC+I))-(A(IB+I)+A(ID+I)))\n * -S2*((B(IA+I)+B(IC+I))-(B(IB+I)+B(ID+I)))\n D(JC+J)=\n * S2*((A(IA+I)+A(IC+I))-(A(IB+I)+A(ID+I)))\n * +C2*((B(IA+I)+B(IC+I))-(B(IB+I)+B(ID+I)))\n C(JB+J)=\n * C1*((A(IA+I)-A(IC+I))-(B(IB+I)-B(ID+I)))\n * -S1*((B(IA+I)-B(IC+I))+(A(IB+I)-A(ID+I)))\n D(JB+J)=\n * S1*((A(IA+I)-A(IC+I))-(B(IB+I)-B(ID+I)))\n * +C1*((B(IA+I)-B(IC+I))+(A(IB+I)-A(ID+I)))\n C(JD+J)=\n * C3*((A(IA+I)-A(IC+I))+(B(IB+I)-B(ID+I)))\n * -S3*((B(IA+I)-B(IC+I))-(A(IB+I)-A(ID+I)))\n D(JD+J)=\n * S3*((A(IA+I)-A(IC+I))+(B(IB+I)-B(ID+I)))\n * +C3*((B(IA+I)-B(IC+I))-(A(IB+I)-A(ID+I)))\n I=I+INC3\n J=J+INC4\n 105 CONTINUE\n IBASE=IBASE+INC1\n JBASE=JBASE+INC2\n 110 CONTINUE\n JBASE=JBASE+JUMP\n 120 CONTINUE\n RETURN\nC\nC CODING FOR FACTOR 5\nC\n 130 IA=1\n JA=1\n IB=IA+IINK\n JB=JA+JINK\n IC=IB+IINK\n JC=JB+JINK\n ID=IC+IINK\n JD=JC+JINK\n IE=ID+IINK\n JE=JD+JINK\n DO 140 L=1,LA\n I=IBASE\n J=JBASE\nCDIR$ IVDEP\n DO 135 IJK=1,LOT\n C(JA+J)=A(IA+I)+(A(IB+I)+A(IE+I))+(A(IC+I)+A(ID+I))\n D(JA+J)=B(IA+I)+(B(IB+I)+B(IE+I))+(B(IC+I)+B(ID+I))\n C(JB+J)=(A(IA+I)+COS72*(A(IB+I)+A(IE+I))-COS36*(A(IC+I)+A(ID+I)))\n * -(SIN72*(B(IB+I)-B(IE+I))+SIN36*(B(IC+I)-B(ID+I)))\n C(JE+J)=(A(IA+I)+COS72*(A(IB+I)+A(IE+I))-COS36*(A(IC+I)+A(ID+I)))\n * +(SIN72*(B(IB+I)-B(IE+I))+SIN36*(B(IC+I)-B(ID+I)))\n D(JB+J)=(B(IA+I)+COS72*(B(IB+I)+B(IE+I))-COS36*(B(IC+I)+B(ID+I)))\n * +(SIN72*(A(IB+I)-A(IE+I))+SIN36*(A(IC+I)-A(ID+I)))\n D(JE+J)=(B(IA+I)+COS72*(B(IB+I)+B(IE+I))-COS36*(B(IC+I)+B(ID+I)))\n * -(SIN72*(A(IB+I)-A(IE+I))+SIN36*(A(IC+I)-A(ID+I)))\n C(JC+J)=(A(IA+I)-COS36*(A(IB+I)+A(IE+I))+COS72*(A(IC+I)+A(ID+I)))\n * -(SIN36*(B(IB+I)-B(IE+I))-SIN72*(B(IC+I)-B(ID+I)))\n C(JD+J)=(A(IA+I)-COS36*(A(IB+I)+A(IE+I))+COS72*(A(IC+I)+A(ID+I)))\n * +(SIN36*(B(IB+I)-B(IE+I))-SIN72*(B(IC+I)-B(ID+I)))\n D(JC+J)=(B(IA+I)-COS36*(B(IB+I)+B(IE+I))+COS72*(B(IC+I)+B(ID+I)))\n * +(SIN36*(A(IB+I)-A(IE+I))-SIN72*(A(IC+I)-A(ID+I)))\n D(JD+J)=(B(IA+I)-COS36*(B(IB+I)+B(IE+I))+COS72*(B(IC+I)+B(ID+I)))\n * -(SIN36*(A(IB+I)-A(IE+I))-SIN72*(A(IC+I)-A(ID+I)))\n I=I+INC3\n J=J+INC4\n 135 CONTINUE\n IBASE=IBASE+INC1\n JBASE=JBASE+INC2\n 140 CONTINUE\n IF (LA.EQ.M) RETURN\n LA1=LA+1\n JBASE=JBASE+JUMP\n DO 160 K=LA1,M,LA\n KB=K+K-2\n KC=KB+KB\n KD=KC+KB\n KE=KD+KB\n C1=TRIGS(KB+1)\n S1=TRIGS(KB+2)\n C2=TRIGS(KC+1)\n S2=TRIGS(KC+2)\n C3=TRIGS(KD+1)\n S3=TRIGS(KD+2)\n C4=TRIGS(KE+1)\n S4=TRIGS(KE+2)\n DO 150 L=1,LA\n I=IBASE\n J=JBASE\nCDIR$ IVDEP\n DO 145 IJK=1,LOT\n C(JA+J)=A(IA+I)+(A(IB+I)+A(IE+I))+(A(IC+I)+A(ID+I))\n D(JA+J)=B(IA+I)+(B(IB+I)+B(IE+I))+(B(IC+I)+B(ID+I))\n C(JB+J)=\n * C1*((A(IA+I)+COS72*(A(IB+I)+A(IE+I))-COS36*(A(IC+I)+A(ID+I)))\n * -(SIN72*(B(IB+I)-B(IE+I))+SIN36*(B(IC+I)-B(ID+I))))\n * -S1*((B(IA+I)+COS72*(B(IB+I)+B(IE+I))-COS36*(B(IC+I)+B(ID+I)))\n * +(SIN72*(A(IB+I)-A(IE+I))+SIN36*(A(IC+I)-A(ID+I))))\n D(JB+J)=\n * S1*((A(IA+I)+COS72*(A(IB+I)+A(IE+I))-COS36*(A(IC+I)+A(ID+I)))\n * -(SIN72*(B(IB+I)-B(IE+I))+SIN36*(B(IC+I)-B(ID+I))))\n * +C1*((B(IA+I)+COS72*(B(IB+I)+B(IE+I))-COS36*(B(IC+I)+B(ID+I)))\n * +(SIN72*(A(IB+I)-A(IE+I))+SIN36*(A(IC+I)-A(ID+I))))\n C(JE+J)=\n * C4*((A(IA+I)+COS72*(A(IB+I)+A(IE+I))-COS36*(A(IC+I)+A(ID+I)))\n * +(SIN72*(B(IB+I)-B(IE+I))+SIN36*(B(IC+I)-B(ID+I))))\n * -S4*((B(IA+I)+COS72*(B(IB+I)+B(IE+I))-COS36*(B(IC+I)+B(ID+I)))\n * -(SIN72*(A(IB+I)-A(IE+I))+SIN36*(A(IC+I)-A(ID+I))))\n D(JE+J)=\n * S4*((A(IA+I)+COS72*(A(IB+I)+A(IE+I))-COS36*(A(IC+I)+A(ID+I)))\n * +(SIN72*(B(IB+I)-B(IE+I))+SIN36*(B(IC+I)-B(ID+I))))\n * +C4*((B(IA+I)+COS72*(B(IB+I)+B(IE+I))-COS36*(B(IC+I)+B(ID+I)))\n * -(SIN72*(A(IB+I)-A(IE+I))+SIN36*(A(IC+I)-A(ID+I))))\n C(JC+J)=\n * C2*((A(IA+I)-COS36*(A(IB+I)+A(IE+I))+COS72*(A(IC+I)+A(ID+I)))\n * -(SIN36*(B(IB+I)-B(IE+I))-SIN72*(B(IC+I)-B(ID+I))))\n * -S2*((B(IA+I)-COS36*(B(IB+I)+B(IE+I))+COS72*(B(IC+I)+B(ID+I)))\n * +(SIN36*(A(IB+I)-A(IE+I))-SIN72*(A(IC+I)-A(ID+I))))\n D(JC+J)=\n * S2*((A(IA+I)-COS36*(A(IB+I)+A(IE+I))+COS72*(A(IC+I)+A(ID+I)))\n * -(SIN36*(B(IB+I)-B(IE+I))-SIN72*(B(IC+I)-B(ID+I))))\n * +C2*((B(IA+I)-COS36*(B(IB+I)+B(IE+I))+COS72*(B(IC+I)+B(ID+I)))\n * +(SIN36*(A(IB+I)-A(IE+I))-SIN72*(A(IC+I)-A(ID+I))))\n C(JD+J)=\n * C3*((A(IA+I)-COS36*(A(IB+I)+A(IE+I))+COS72*(A(IC+I)+A(ID+I)))\n * +(SIN36*(B(IB+I)-B(IE+I))-SIN72*(B(IC+I)-B(ID+I))))\n * -S3*((B(IA+I)-COS36*(B(IB+I)+B(IE+I))+COS72*(B(IC+I)+B(ID+I)))\n * -(SIN36*(A(IB+I)-A(IE+I))-SIN72*(A(IC+I)-A(ID+I))))\n D(JD+J)=\n * S3*((A(IA+I)-COS36*(A(IB+I)+A(IE+I))+COS72*(A(IC+I)+A(ID+I)))\n * +(SIN36*(B(IB+I)-B(IE+I))-SIN72*(B(IC+I)-B(ID+I))))\n * +C3*((B(IA+I)-COS36*(B(IB+I)+B(IE+I))+COS72*(B(IC+I)+B(ID+I)))\n * -(SIN36*(A(IB+I)-A(IE+I))-SIN72*(A(IC+I)-A(ID+I))))\n I=I+INC3\n J=J+INC4\n 145 CONTINUE\n IBASE=IBASE+INC1\n JBASE=JBASE+INC2\n 150 CONTINUE\n JBASE=JBASE+JUMP\n 160 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "2bce0ae6cc8c468a9f826ad0667119b45dd0a99e", "size": 33683, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "lib/fft99f.f", "max_stars_repo_name": "jhaoli/shallow_spectral", "max_stars_repo_head_hexsha": "a2580f9baad596a56efaaae20b80e1bd543c2502", "max_stars_repo_licenses": ["NetCDF"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-06-19T02:24:41.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-19T02:24:41.000Z", "max_issues_repo_path": "lib/fft99f.f", "max_issues_repo_name": "jhaoli/shallow_spectral", "max_issues_repo_head_hexsha": "a2580f9baad596a56efaaae20b80e1bd543c2502", "max_issues_repo_licenses": ["NetCDF"], "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/fft99f.f", "max_forks_repo_name": "jhaoli/shallow_spectral", "max_forks_repo_head_hexsha": "a2580f9baad596a56efaaae20b80e1bd543c2502", "max_forks_repo_licenses": ["NetCDF"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.9670818505, "max_line_length": 72, "alphanum_fraction": 0.5160169819, "num_tokens": 13938, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9196425355825848, "lm_q2_score": 0.7577943822145998, "lm_q1q2_score": 0.696899947110073}} {"text": "! Write a 100x100 matrix of random real numbers to a file.\nPROGRAM write_data\nIMPLICIT NONE\n INTEGER, PARAMETER :: ROWS = 100, COLS = 100\n INTEGER, DIMENSION(8) :: time\n INTEGER :: i, j\n CHARACTER(LEN=3) :: col_str\n CHARACTER(LEN=9) :: fmt\n\n CALL DATE_AND_TIME(VALUES=time)\n CALL SRAND(time(8))\n\n WRITE(col_str, '(I3)') COLS\n col_str = TRIM(col_str)\n fmt = '(' // col_str // 'F8.1)'\n\n OPEN (1, FILE='data.txt', STATUS='NEW', ACTION='WRITE')\n WRITE(1,'(2I5)') ROWS, COLS\n WRITE (1, fmt) ((RAND() * 1000. - 500., j=1,COLS), i=1,ROWS)\n\nEND PROGRAM write_data\n", "meta": {"hexsha": "8e5715c211a321414d783866a45cfe3ed2e7fc2a", "size": 569, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap8/write_data.f90", "max_stars_repo_name": "evanmacbride/fortran-practice", "max_stars_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/chap8/write_data.f90", "max_issues_repo_name": "evanmacbride/fortran-practice", "max_issues_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/chap8/write_data.f90", "max_forks_repo_name": "evanmacbride/fortran-practice", "max_forks_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.8636363636, "max_line_length": 62, "alphanum_fraction": 0.6414762742, "num_tokens": 206, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9196425311777928, "lm_q2_score": 0.7577943767446201, "lm_q1q2_score": 0.6968999387417204}} {"text": " real*8 function xsin(x)\n implicit none\n real*8 x,x2\n if(abs(x) .gt. .1d0)then\n xsin=x-sin(x)\n else\n x2=x**2\n xsin=x*x2/6.d0*(1.d0-x2/20.d0*(1.d0-x2/42.d0*(\n 1 1.d0-x2/72.d0*(1.d0-x2/110.d0))))\n endif\n return\n end\n\n real*8 function xsinh(x)\n implicit none\n real*8 x,x2\n if(abs(x) .gt. .1d0)then\n xsinh=x-sinh(x)\n else\n x2=x**2\n xsinh=-x*x2/6.d0*(1.d0+x2/20.d0*(1.d0+x2/42.d0*(\n 1 1.d0+x2/72.d0*(1.d0+x2/110.d0))))\n endif\n return\n end\n\n real*8 function xlog(x)\n implicit none\n real*8 x\n if(abs(x) .gt. 1.d-2)then\n xlog=log(1.d0+x)\n else\n xlog=x*(1.d0-x*(.5d0-x*(1.d0/3.d0\n 1 -x*(.25d0-x*(.2d0-x*(1.d0/6.d0\n 1 -x*(1.d0/7.d0-x*(.125d0-x/9.d0))))))))\n endif\n return\n end\n\n real*8 function sinc(x)\n implicit none\n real*8 x,x2\n if(abs(x) .gt. .1d0)then\n sinc=x*cos(x)-sin(x)\n else\n x2=x**2\n sinc=-x*x2/6.d0*(2.d0-x2/20.d0*(4.d0-x2/42.d0*(\n 1 6.d0-x2/72.d0*(8.d0-x2/11.d0))))\n endif\n return\n end\n\n real*8 function sinhc(x)\n implicit none\n real*8 x,x2\n if(abs(x) .gt. .1d0)then\n sinhc=x*cosh(x)-sinh(x)\n else\n x2=x**2\n sinhc=x*x2/6.d0*(2.d0+x2/20.d0*(4.d0+x2/42.d0*(\n 1 6.d0+x2/72.d0*(8.d0+x2/11.d0))))\n endif\n return\n end\n", "meta": {"hexsha": "4e69af830ac3b7030101b414fb5ab1d39a35e09f", "size": 1471, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/xsin.f", "max_stars_repo_name": "noboruatkek/SAD", "max_stars_repo_head_hexsha": "3881a190af8903537774c57b56963ffc94cfc039", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2019-04-01T15:54:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-09T16:47:20.000Z", "max_issues_repo_path": "src/xsin.f", "max_issues_repo_name": "noboruatkek/SAD", "max_issues_repo_head_hexsha": "3881a190af8903537774c57b56963ffc94cfc039", "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/xsin.f", "max_forks_repo_name": "noboruatkek/SAD", "max_forks_repo_head_hexsha": "3881a190af8903537774c57b56963ffc94cfc039", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2017-03-15T08:52:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-19T08:06:40.000Z", "avg_line_length": 22.6307692308, "max_line_length": 56, "alphanum_fraction": 0.4602311353, "num_tokens": 620, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425333801889, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6968999353802579}} {"text": "module angular_functions_module\n\nuse system_module\nuse units_module\nuse linearalgebra_module\n\nimplicit none\nprivate\n\n\n real(dp), dimension(:,:,:,:,:,:), allocatable, save :: cg_array\n integer, save :: cg_j1_max=0, cg_m1_max=0, cg_j2_max=0, cg_m2_max=0, cg_j_max=0, cg_m_max=0 \n logical, save :: cg_initialised = .false.\n\n public :: SphericalYCartesian, GradSphericalYCartesian\n public :: SphericalYCartesian_all, GradSphericalYCartesian_all\n public :: SolidRCartesian\n\n public :: wigner3j\n public :: cg_initialise, cg_finalise, cg_array\n\ncontains\n\n !#################################################################################\n !#\n !% Solid Harmonic function using Cartesian coordinates\n !%\n !% $ R_{l m} = \\sqrt{\\frac{4 \\pi}{2 l + 1}} r^l Y_{l m} $\n !#\n !#################################################################################\n\n function SolidRCartesian(l, m, x)\n\n complex(dp) :: SolidRCartesian\n integer, intent(in) :: l, m\n real(dp), intent(in) :: x(3)\n integer :: p, q, s\n\n SolidRCartesian = CPLX_ZERO\n\n do p = 0, l\n q = p - m\n s = l - p - q\n\n if ((q >= 0) .and. (s >= 0)) then\n SolidRCartesian = SolidRCartesian + ((cmplx(-0.5_dp * x(1), -0.5_dp * x(2), dp)**p) &\n * (cmplx(0.5_dp * x(1), -0.5_dp * x(2), dp)**q) &\n * (x(3)**s) &\n / (factorial(p) * factorial(q) * factorial(s)))\n end if\n end do\n\n SolidRCartesian = SolidRCartesian * sqrt(factorial(l + m) * factorial(l - m))\n\n end function SolidRCartesian\n\n function SolidRCartesian_all(l_max, x)\n\n integer, intent(in) :: l_max\n real(dp), intent(in) :: x(3)\n complex(dp) :: SolidRCartesian_all(0:l_max, -l_max:l_max)\n\n integer :: l, m\n integer :: p, q, s\n complex(kind=dp) :: cm, cp, cm_term(0:l_max), cp_term(0:2*l_max), x3_term(0:2*l_max)\n real(dp) :: factorials(0:2*l_max)\n\n SolidRCartesian_all = CPLX_ZERO\n\n cm = cmplx(-0.5_dp * x(1), -0.5_dp * x(2), dp)\n cp = cmplx(0.5_dp * x(1), -0.5_dp * x(2), dp)\n\n ! p = 0 .. l\n do p=0, l_max\n cm_term(p) = cm**p\n end do\n ! q, s = 0 .. 2l\n do q=0, 2*l_max\n cp_term(q) = cp**q\n x3_term(q) = x(3)**q\n factorials(q) = factorial(q)\n end do\n\n do l=0, l_max\n do m=-l, l\n do p = 0, l\n q = p - m\n s = l - p - q\n\n if ((q >= 0) .and. (s >= 0)) then\n SolidRCartesian_all(l,m) = SolidRCartesian_all(l,m) + &\n ( cm_term(p) * cp_term(q) * x3_term(s) / &\n ( factorials(p) * factorials(q) * factorials(s) ) )\n end if\n end do\n\n SolidRCartesian_all(l,m) = SolidRCartesian_all(l,m) * sqrt(factorials(l + m) * factorials(l - m))\n end do\n end do\n\n end function SolidRCartesian_all\n\n !#################################################################################\n !#\n !% Spherical Harmonic function using Cartesian coordinates\n !#\n !#################################################################################\n\n function SphericalYCartesian(l, m, x)\n\n complex(dp) :: SphericalYCartesian\n integer, intent(in) :: l, m\n real(dp), intent(in) :: x(3)\n\n SphericalYCartesian = SolidRCartesian(l, m, x) * sqrt(((2.0_dp * l) + 1) / (4.0_dp * PI)) &\n * (normsq(x)**(-0.5_dp * l))\n\n end function SphericalYCartesian\n\n function SphericalYCartesian_all(l_max, x)\n\n integer, intent(in) :: l_max\n real(dp), intent(in) :: x(3)\n complex(dp) :: SphericalYCartesian_all(0:l_max, -l_max:l_max)\n\n real(dp) :: normsq_x\n integer :: l, m\n\n normsq_x = normsq(x)\n SphericalYCartesian_all = SolidRCartesian_all(l_max, x) \n do l=0, l_max\n SphericalYCartesian_all(l,-l:l) = SphericalYCartesian_all(l,-l:l) * &\n sqrt(((2.0_dp * l) + 1) / (4.0_dp * PI)) * (normsq_x**(-0.5_dp * l))\n end do\n\n end function SphericalYCartesian_all\n\n !#################################################################################\n !#\n !% Derivative of Spherical Harmonic function using Cartesian coordinates\n !#\n !#################################################################################\n\n function GradSphericalYCartesian(l, m, x)\n\n complex(dp) :: GradSphericalYCartesian(3)\n integer, intent(in) :: l, m\n real(dp), intent(in) :: x(3)\n integer :: p, q, s\n\n GradSphericalYCartesian = CPLX_ZERO\n\n do p = 0, l\n q = p - m\n s = l - p - q\n\n if ((p >= 1) .and. (q >= 0) .and. (s >= 0)) then\n GradSphericalYCartesian(1) = GradSphericalYCartesian(1) &\n - ((cmplx(-0.5_dp * x(1), -0.5_dp * x(2), dp)**(p - 1)) &\n * (cmplx(0.5_dp * x(1), -0.5_dp * x(2), dp)**q) &\n * (x(3)**s) &\n * 0.5_dp &\n / (factorial(p - 1) * factorial(q) * factorial(s)))\n GradSphericalYCartesian(2) = GradSphericalYCartesian(2) &\n - ((cmplx(-0.5_dp * x(1), -0.5_dp * x(2), dp)**(p - 1)) &\n * (cmplx(0.5_dp * x(1), -0.5_dp * x(2), dp)**q) &\n * (x(3)**s) &\n * 0.5_dp * cmplx(0.0_dp, 1.0_dp, dp) &\n / (factorial(p - 1) * factorial(q) * factorial(s)))\n end if\n\n if ((p >= 0) .and. (q >= 1) .and. (s >= 0)) then\n GradSphericalYCartesian(1) = GradSphericalYCartesian(1) &\n + ((cmplx(-0.5_dp * x(1), -0.5_dp * x(2), dp)**p) &\n * (cmplx(0.5_dp * x(1), -0.5_dp * x(2), dp)**(q - 1)) &\n * (x(3)**s) &\n * 0.5_dp &\n / (factorial(p) * factorial(q - 1) * factorial(s)))\n GradSphericalYCartesian(2) = GradSphericalYCartesian(2) &\n - ((cmplx(-0.5_dp * x(1), -0.5_dp * x(2), dp)**p) &\n * (cmplx(0.5_dp * x(1), -0.5_dp * x(2), dp)**(q - 1)) &\n * (x(3)**s) &\n * 0.5_dp * cmplx(0.0_dp, 1.0_dp, dp) &\n / (factorial(p) * factorial(q - 1) * factorial(s)))\n end if\n\n if ((p >= 0) .and. (q >= 0) .and. (s >= 1)) then\n GradSphericalYCartesian(3) = GradSphericalYCartesian(3) &\n + ((cmplx(-0.5_dp * x(1), -0.5_dp * x(2), dp)**p) &\n * (cmplx(0.5_dp * x(1), -0.5_dp * x(2), dp)**q) &\n * (x(3)**(s - 1)) &\n / (factorial(p) * factorial(q) * factorial(s - 1)))\n end if\n end do\n\n GradSphericalYCartesian = GradSphericalYCartesian &\n * sqrt(factorial(l + m) * factorial(l - m) * ((2.0_dp * l) + 1) / (4.0_dp * PI)) &\n * (normsq(x)**(-0.5_dp * l))\n\n GradSphericalYCartesian = GradSphericalYCartesian &\n - (l * x * SphericalYCartesian(l, m, x) / normsq(x))\n\n end function GradSphericalYCartesian\n\n function GradSphericalYCartesian_all(l_max, x)\n\n integer, intent(in) :: l_max\n real(dp), intent(in) :: x(3)\n complex(dp) :: GradSphericalYCartesian_all(0:l_max, -l_max:l_max, 3)\n\n integer :: l, m\n integer :: p, q, s\n complex(kind=dp) :: cm, cp, cm_term(0:l_max), cp_term(0:2*l_max), x3_term(0:2*l_max)\n real(dp) :: factorials(0:2*l_max)\n real(dp) :: normsq_x\n complex(dp) :: tt\n\n GradSphericalYCartesian_all = CPLX_ZERO\n \n cm = cmplx(-0.5_dp * x(1), -0.5_dp * x(2), dp)\n cp = cmplx(0.5_dp * x(1), -0.5_dp * x(2), dp)\n \n ! p = 0 .. l\n do p=0, l_max\n cm_term(p) = cm**p\n end do\n ! q, s = 0 .. 2l\n do q=0, 2*l_max\n cp_term(q) = cp**q\n x3_term(q) = x(3)**q\n factorials(q) = factorial(q)\n end do\n\n normsq_x = normsq(x)\n \n do l=0, l_max\n do m=-l, l\n do p = 0, l\n q = p - m\n s = l - p - q\n\n if ((p >= 1) .and. (q >= 0) .and. (s >= 0)) then\n tt = (cm_term(p-1) * cp_term(q) * x3_term(s) &\n * 0.5_dp &\n / (factorials(p - 1) * factorials(q) * factorials(s)))\n GradSphericalYCartesian_all(l,m,1) = GradSphericalYCartesian_all(l,m,1) &\n - tt\n GradSphericalYCartesian_all(l,m,2) = GradSphericalYCartesian_all(l,m,2) &\n - tt * cmplx(0.0_dp, 1.0_dp, dp)\n end if\n\n if ((p >= 0) .and. (q >= 1) .and. (s >= 0)) then\n tt = (cm_term(p) * cp_term(q-1) * x3_term(s) &\n * 0.5_dp &\n / (factorials(p) * factorials(q - 1) * factorials(s)))\n GradSphericalYCartesian_all(l,m,1) = GradSphericalYCartesian_all(l,m,1) &\n + tt\n GradSphericalYCartesian_all(l,m,2) = GradSphericalYCartesian_all(l,m,2) &\n - tt * cmplx(0.0_dp, 1.0_dp, dp)\n end if\n\n if ((p >= 0) .and. (q >= 0) .and. (s >= 1)) then\n GradSphericalYCartesian_all(l,m,3) = GradSphericalYCartesian_all(l,m,3) &\n + (cm_term(p) * cp_term(q) * x3_term(s-1) &\n / (factorials(p) * factorials(q) * factorials(s - 1)))\n end if\n end do\n\n GradSphericalYCartesian_all(l,m,:) = GradSphericalYCartesian_all(l,m,:) &\n * sqrt(factorials(l + m) * factorials(l - m) * ((2.0_dp * l) + 1) / (4.0_dp * PI)) &\n * (normsq_x**(-0.5_dp * l))\n\n GradSphericalYCartesian_all(l,m,:) = GradSphericalYCartesian_all(l,m,:) &\n - (l * x * SphericalYCartesian(l, m, x) / normsq_x)\n end do\n end do\n\n end function GradSphericalYCartesian_all\n\n subroutine cg_initialise(j,denom)\n\n integer, intent(in) :: j\n integer :: i_j1,i_m1,i_j2,i_m2,i_j,i_m\n integer, intent(in), optional :: denom\n\n integer :: my_denom\n\n if (cg_initialised .and. j > cg_j_max) then ! need to reinitialise\n\t call cg_finalise()\n\t cg_initialised = .false.\n endif\n if (cg_initialised) return\n\n my_denom = optional_default(1,denom)\n\n cg_j1_max = j\n cg_m1_max = j\n cg_j2_max = j\n cg_m2_max = j\n cg_j_max = j !(j1_max+j2_max)\n cg_m_max = j !(j1_max+j2_max)\n\n allocate( cg_array(0:cg_j1_max,-cg_m1_max:cg_m1_max,0:cg_j2_max,-cg_m2_max:cg_m2_max,&\n & 0:cg_j_max,-cg_j_max:cg_j_max) )\n \n cg_array = 0.0_dp\n\n do i_j1 = 0, cg_j1_max\n do i_m1 = -i_j1, i_j1, my_denom\n do i_j2 = 0, cg_j2_max\n do i_m2 = -i_j2, i_j2, my_denom\n do i_j = abs(i_j1-i_j2), min(cg_j_max,i_j1+i_j2)\n do i_m = -i_j, i_j, my_denom\n\n\n cg_array(i_j1,i_m1,i_j2,i_m2,i_j,i_m) = cg_calculate(i_j1,i_m1,i_j2,i_m2,i_j,i_m,denom)\n\n enddo\n enddo\n enddo\n enddo\n enddo\n enddo\n\n cg_initialised = .true.\n \n endsubroutine cg_initialise\n\n !#################################################################################\n !#\n !% Finalise global CG arrays\n !#\n !#################################################################################\n\n subroutine cg_finalise\n\n cg_j1_max = 0\n cg_m1_max = 0\n cg_j2_max = 0\n cg_m2_max = 0\n cg_j_max = 0\n cg_m_max = 0\n\n if(allocated(cg_array)) deallocate( cg_array )\n cg_initialised = .false.\n\n endsubroutine cg_finalise\n\n !#################################################################################\n !#\n !% Look up CG coefficient from CG array, previously calculated.\n !#\n !#################################################################################\n\n function cg_lookup(j1,m1,j2,m2,j,m,denom) result(cg)\n\n real(dp) :: cg\n integer, intent(in) :: j1,m1,j2,m2,j,m\n integer, intent(in), optional :: denom\n\n cg=0.0_dp\n\n if ( .not. cg_check(j1,m1,j2,m2,j,m,denom) ) then\n return\n endif\n\n if( j1<=cg_j1_max .and. j2<=cg_j2_max .and. j<=cg_j_max .and. &\n abs(m1)<=cg_m1_max .and. abs(m2)<=cg_m2_max .and. abs(m) <= cg_m_max .and. cg_initialised ) then\n cg = cg_array(j1,m1,j2,m2,j,m)\n else\n cg = cg_calculate(j1,m1,j2,m2,j,m,denom)\n endif\n\n endfunction cg_lookup\n\n !#################################################################################\n !#\n !% Check if input variables for CG make sense.\n !% Source: http://mathworld.wolfram.com/Clebsch-GordanCoefficient.html \\\\\n !% \n !% $ j_1 + j_2 \\ge j $ \\\\\n !% $ j_1 - j_2 \\ge -j $ \\\\\n !% $ j_1 - j_2 \\le j $ \\\\\n !% $ j_1 \\ge m_1 \\ge j_1 $ \\\\\n !% $ j_2 \\ge m_2 \\ge j_2 $ \\\\\n !% $ j \\ge m \\ge j $ \\\\\n !% $ m_1 + m_2 = m $ \\\\\n !#\n !#################################################################################\n\n function cg_check(j1,m1,j2,m2,j,m,denom)\n\n logical :: cg_check\n integer, intent(in) :: j1,m1,j2,m2,j,m\n integer, intent(in), optional :: denom\n\n integer :: my_denom\n\n my_denom = optional_default(1,denom)\n cg_check = (j1>=0) .and. (j2>=0) .and. (j>=0) .and. &\n (abs(m1)<=j1) .and. (abs(m2)<=j2) .and. (abs(m)<=j) &\n .and. (m1+m2==m) .and. (j1+j2 >= j) .and. (abs(j1-j2) <= j) &\n .and. (mod(j1+j2+j,my_denom)==0)\n \n endfunction cg_check\n\n !#################################################################################\n !#\n !% Calculate a Clebsch-Gordan coefficient $\\left< j_1 m_1 j_2 m_2 | j m \\right>$\n !% Source: http://mathworld.wolfram.com/Clebsch-GordanCoefficient.html \\\\\n !% $ \\left< j_1 m_1 j_2 m_2 | j m \\right> = (-1)^{m+j_1-j_2) \n !% \\sqrt{2j+1} \\left( \\begin{array}{ccc}\n !% j_1 & j_2 & j \\\\\n !% m_1 & m_2 & -m \\\\\n !% \\end{array} \\right) $\n !% where the thing on the right-hand side is the Wigner 3J symbol.\n !#\n !#################################################################################\n\n function cg_calculate(j1,m1,j2,m2,j,m,denom) result(cg)\n\n real(dp) :: cg\n integer, intent(in) :: j1,m1,j2,m2,j,m\n integer, intent(in), optional :: denom\n\n integer :: my_denom\n\n my_denom = optional_default(1,denom)\n\n cg=0.0_dp\n if ( .not. cg_check(j1,m1,j2,m2,j,m,denom) ) return\n\n cg = oscillate((m+j1-j2)/my_denom) * sqrt(2.0_dp*real(j,dp)/real(my_denom,dp)+1.0_dp) * &\n wigner3j(j1,m1,j2,m2,j,-m,denom)\n\n end function cg_calculate\n\n !#################################################################################\n !#\n !% Triangle coefficient\n !% Source: http://mathworld.wolfram.com/TriangleCoefficient.html\n !% \n !% $ \\Delta(a,b,c) = \\frac{ (a+b-c)! (a-b+c)! (-a+b+c)! }{ (a+b+c+1)! } $\n !#\n !#################################################################################\n\n function tc(a,b,c,denom)\n\n real(dp) :: tc\n integer, intent(in) :: a, b, c\n integer, intent(in), optional :: denom\n integer :: my_denom\n\n my_denom = optional_default(1,denom)\n\n tc = factorial((a+b-c)/my_denom) * factorial((a-b+c)/my_denom) * &\n factorial((-a+b+c)/my_denom) / factorial((a+b+c)/my_denom+1)\n\n endfunction tc\n\n !#################################################################################\n !#\n !% Wigner 3J symbol\n !% Source: http://mathworld.wolfram.com/Wigner3j-Symbol.html\n !% \n !% \\[\n !% \\left( \\begin{array}{ccc}\n !% j_1 & j_2 & j \\\\\n !% m_1 & m_2 & m \\\\\n !% \\end{array} \\right) = (-1)^{j_1-j_2-m) \\sqrt{ \\Delta (j_1,j_2,j) }\n !% \\sqrt{ (j_1+m_1)! (j_1-m_1)! (j_2+m_2)! (j_2-m_2)! (j+m)! (j-m)! }\n !% \\sum_k \\frac{ (-1)^k }{k! (j-j_2+k+m_1)! (j-j_1+k-m_2)! (j_1+j_2-j-k)!\n !% (j_1-k-m_1)! (j_2-k+m_2)! }\n !% \\]\n !% the summation index k runs on all integers where none of the argument of\n !% factorials are negative\n !% $\\Delta(a,b,c)$ is the triangle coefficient.\n !#\n !#################################################################################\n\n function wigner3j(j1,m1,j2,m2,j,m,denom)\n\n real(dp) :: wigner3j\n integer, intent(in) :: j1,m1,j2,m2,j,m\n integer, intent(in), optional :: denom\n\n real(dp) :: pre_fac, triang_coeff, main_coeff, sum_coeff, sum_term\n integer :: k, kmin, kmax, my_denom\n\n my_denom = optional_default(1,denom)\n\n pre_fac = oscillate((j1-j2-m)/my_denom)\n\n triang_coeff = sqrt( tc(j1,j2,j,denom) )\n\n main_coeff = sqrt( &\n factorial((j1+m1)/my_denom) * factorial((j1-m1)/my_denom) * &\n factorial((j2+m2)/my_denom) * factorial((j2-m2)/my_denom) * &\n factorial((j+m)/my_denom) * factorial((j-m)/my_denom) )\n \n sum_coeff = 0.0_dp\n\n kmin = max( j2-j-m1, j1+m2-j, 0 ) / my_denom\n kmax = min( j1+j2-j, j1-m1, j2+m2) / my_denom\n\n do k = kmin, kmax\n\n sum_term = 1.0_dp / ( factorial(k) * factorial((j-j2+m1)/my_denom+k) * &\n factorial((j-j1-m2)/my_denom+k) * factorial((j1+j2-j)/my_denom-k) * &\n factorial((j1-m1)/my_denom-k) * factorial((j2+m2)/my_denom-k) )\n\n sum_term = oscillate(k) * sum_term\n \n sum_coeff = sum_coeff + sum_term\n\n enddo\n\n wigner3j = pre_fac * triang_coeff * main_coeff * sum_coeff\n\n endfunction wigner3j\n\nend module angular_functions_module\n", "meta": {"hexsha": "5f16aa507277d66302b3c6d164718a4efa149b98", "size": 18121, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/libAtoms/angular_functions.f95", "max_stars_repo_name": "albapa/QUIP", "max_stars_repo_head_hexsha": "ecde1e332c6bd62c238d3cd90e31dba4fb390313", "max_stars_repo_licenses": ["NRL"], "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/libAtoms/angular_functions.f95", "max_issues_repo_name": "albapa/QUIP", "max_issues_repo_head_hexsha": "ecde1e332c6bd62c238d3cd90e31dba4fb390313", "max_issues_repo_licenses": ["NRL"], "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/libAtoms/angular_functions.f95", "max_forks_repo_name": "albapa/QUIP", "max_forks_repo_head_hexsha": "ecde1e332c6bd62c238d3cd90e31dba4fb390313", "max_forks_repo_licenses": ["NRL"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.6481835564, "max_line_length": 118, "alphanum_fraction": 0.4535069809, "num_tokens": 5605, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425399873763, "lm_q2_score": 0.7577943658046609, "lm_q1q2_score": 0.6968999353567213}} {"text": "\tFUNCTION PS_SHOW ( t850, td850, t500 )\nC************************************************************************\nC* PS_SHOW \t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes the Showalter index:\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* SHOW = T500 - Tparcel\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Tparcel = Temperature in Celsius at 500 mb of a parcel\t*\nC* which lies on the moist adiabat determined\t*\nC* by the sounding at 850 mb\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PS_SHOW ( T850, TD850, T500 )\t\t\t\t\t*\nC* \t\t\t\t\t\t\t*\nC* Input parameters: *\nC*\tT850 \tREAL\t\t850 mb temperature in Celsius\t*\nC*\tTD850\t\tREAL\t\t850 mb dewpoint in Celsius\t*\nC*\tT500\t\tREAL\t\t500 mb temperature in Celsius\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPS_SHOW\t\tREAL\t\tShowalter index\t\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* P. Kocin/GSFC\t 1980\tOriginal source called PR_SHOW\t\t*\nC* M. Goodman/RDS\t 8/84\tRenamed and cleaned prologue\t\t*\nC* M. desJardins/GSFC\t 3/88\tDocumentation\t\t\t\t*\nC************************************************************************\n INCLUDE 'GEMPRM.PRM'\n INCLUDE 'ERMISS.FNC'\nC----------------------------------------------------------------------------\n\tIF ( ERMISS ( t850 ) .or. ERMISS ( td850 ) .or. \n +\t ERMISS ( t500 ) ) THEN\n\t PS_SHOW = RMISSD\n\t ELSE\n\t p850 = 850.\nC\nC*\t Find equivalent potential temperture at the LCL using 850 mb\nC*\t temperature and dewpoint.\nC\n\t thtlcl = PR_THTE ( p850, t850, td850 )\n\t p500 = 500.\nC\nC*\t Find parcel temperature along pseudoadiabat at 500 mb.\nC\n\t guess = 0.\n\t tp = PR_TMST ( thtlcl, p500, guess )\nC\nC*\t If parcel temp is no good, then set the index to missing.\nC\n\t IF ( ERMISS ( tp ) ) THEN\n\t\tPS_SHOW = RMISSD\n\t ELSE\nC\nC*\t \tElse subtract the parcel temp from the temp at 500 mb.\nC\n\t\tt500k = pr_tmck ( t500 )\n\t\tPS_SHOW = t500k - tp\n\t END IF\n\tEND IF\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "b0e53351079fbf390663cd94bc589e6cfc611c4e", "size": 1965, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/ps/psshow.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/ps/psshow.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/ps/psshow.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.1904761905, "max_line_length": 77, "alphanum_fraction": 0.4905852417, "num_tokens": 593, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425267730008, "lm_q2_score": 0.757794360334681, "lm_q1q2_score": 0.6968999203125159}} {"text": "PROGRAM PE2D_HFR\r\n USE NRTYPE\n USE MATLIB\n USE PARAM\n USE GROUND\r\n IMPLICIT NONE\r\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\r\n WRITE(*,*) \"\"\r\n WRITE(*,*) \"================================================\"\r\n WRITE(*,*) \"========== Parabolic Equation Package ==========\"\r\n WRITE(*,*) \"================================================\"\r\n WRITE(*,*) \"\"\r\n WRITE(*,*) \"University of Bristol\"\r\n WRITE(*,*) \"Aerodynamics and Aeroacoustics Research Group\"\r\n WRITE(*,*) \"\"\r\n WRITE(*,*) \"Codor Khodr, July 2016\"\r\n WRITE(*,*) \"\"\r\n WRITE(*,*) \"================================================\"\r\n WRITE(*,*) \"\"\r\n WRITE(*,*) \"PE2D_HFR\"\r\n WRITE(*,*) \"Dimension : 2D\"\r\n WRITE(*,*) \"Atmosphere : Homogeneous\"\r\n WRITE(*,*) \"Boundary : Flat\"\r\n WRITE(*,*) \"Impedance : Rigid\"\r\n WRITE(*,*) \"\"\r\n WRITE(*,*) \"================================================\"\r\n WRITE(*,*) \"\"\r\n WRITE(*,*) \"Enter inputs L, f, zs, As\"\r\n WRITE(*,*) \"\"\r\n READ *, L, F, ZS, ABL\r\n WRITE(*,*) \"\"\r\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\n C0 = 343.0_DP\r\n LMBDA0 = C0/F\r\n K0 = 2*PI*F/C0\r\n DZ = LMBDA0/10\r\n DR = LMBDA0/10\n H = 100*LMBDA0\r\n HABL = 30*LMBDA0\r\n N = FLOOR(H/DZ)\r\n M = FLOOR(L/DR)\n WRITE(*,*) \"================================================\"\n WRITE(*,*) \"\"\n WRITE(*,*) \"Size of the system : \", N\n WRITE(*,*) \"Number of steps : \", M\n WRITE(*,*) \"\"\n WRITE(*,*) \"================================================\"\r\n NS = MAX(1,FLOOR(ZS/DZ))\r\n NABL = FLOOR(HABL/DZ)\n ALPHA = IM/(2.0_DP*K0*DZ**2)\n KU = 1\n KL = 1\n NDIAG = KU+KL+1\r\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\r\n !Memory allocation\r\n ALLOCATE(K(N), DK2(N), ALT(N), PHI(N,M+1), T(N,N), D(N,N), M1(N,N), &\n M2(N,N), I(N,N), P(N,M), LP(N,M), LP2(N,M), LPG(M), LPG2(M), E(N,N), &\n MB2(NDIAG,N), MB1(NDIAG,N), WORK(N), RWORK(2*N), CWORK(2*N), TEMP(N,1), &\n MTEMP(2*KL+KU+1,N), IPIV(N), TEMP(N))\r\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\r\n DO NZ = 1,N\r\n IF (NZ.GE.N-NABL) THEN\r\n K(NZ) = K0+ABL*IM*(NZ-N+NABL)**2/NABL**2\r\n ELSE\r\n K(NZ) = K0\r\n ENDIF\r\n DK2(NZ) = IM*(K(NZ)**2-K0**2)/(2*K0)\n ALT(NZ) = NZ*DZ\r\n END DO\r\n TAU1 = 4./(3.-2.*IM*K0*DZ)\r\n TAU2 = -1./(3.-2.*IM*K0*DZ)\r\n SIGMA1 = 4./3.\r\n SIGMA2 = -1./3.\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\r\n A0 = 1.3717\r\n A2 = -0.3701\r\n B = 3.\r\n DO NZ = 1,N\r\n PHI(NZ,1) = SQRT(IM*K0)* &\r\n ((A0+A2*K0**2*(NZ*DZ-ZS)**2)*EXP(-K0**2*(NZ*DZ-ZS)**2/B) + &\r\n (A0+A2*K0**2*(NZ*DZ+ZS)**2)*EXP(-K0**2*(NZ*DZ+ZS)**2/B))\r\n END DO\r\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\r\n !Initialization (Dense Matrices)\n !FDW = [1 -2 1] !Finite Difference Weights\n !---------\r\n T(:,:) = 0._DP\r\n DO NZ = 2,N-1 \r\n T(NZ,NZ-1) = T(NZ,NZ-1)+1.\r\n T(NZ,NZ) = T(NZ,NZ)-2.\r\n T(NZ,NZ+1) = T(NZ,NZ+1)+1.\r\n END DO\n T(1,1) = T(1,1)-2.+SIGMA1\r\n T(1,2) = T(1,2)+1.+SIGMA2\r\n T(N,N-1) = T(N,N-1)+1.+TAU2\r\n T(N,N) = T(N,N)-2.+TAU1\n E = DIAG(ALT)\n D = DIAG(DK2)\n I = EYE(N)\n !-----------------------------------------------------------\n !System - M1 and M2\n !---------\n BETA1 = 1./(2.*IM*K0)+DR/2.\n BETA2 = 1./(2.*IM*K0)-DR/2.\n M1 = I+ALPHA*BETA1*T+BETA1*D\r\n M2 = I+ALPHA*BETA2*T+BETA2*D \n !CALL DENSE2BAND(M1,N,KL,KU,MB1)\n MB2 = DENSE2BAND(M2,N,KL,KU)\r\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\r\n !Forward-marching procedure\n CALL CPU_TIME(TI)\n !-----------------------------------------------------------\n DO MX = 2,M+1\r\n WRITE(*, *) \"Step :\", MX-1, \"out of\", M \n TEMP(:,1) = MATMUL(M1,PHI(1:N,MX-1))\n !CALL ZGBMV('N',N,N,KL,KU,1.,MB1,KL+KU+1,PHI(1:N,MX-1),1,0.,TEMP(:,1),1) \n WRITE(*, *) \".... Right-hand side multiplied\"\n !MTEMP = M2\n MTEMP(KL+1:2*KL+KU+1,:) = MB2 \n !CALL ZGESV(N,1,MTEMP,N,IPIV,TEMP,N,INFO)\n CALL ZGBSV(N,KL,KU,1,MTEMP,2*KL+KU+1,IPIV,TEMP(:,1),N,INFO)\n !CALL ZGTSV(N,1,MTEMP(2*KL+KU+1,1:N-1),MTEMP(KL+KU+1,1:N),MTEMP(KL+1,2:N),TEMP(:,1),N,INFO)\n IF (INFO.NE.0) THEN\n WRITE(*,*) INFO\n STOP \"ERROR : Matrix is singular\"\n END IF\n WRITE(*, *) \".... System solved\"\n PHI(1:N,MX) = TEMP(:,1)\r\n P(1:N,MX-1) = EXP(IM*K0*(MX-1)*Dr)*PHI(1:N,MX)*(1/SQRT((MX-1)*Dr))\r\n END DO\r\n! !-----------------------------------------------------------\r\n! IF (SP == 0) THEN\n! !-----------------------------------------------------------\n! MAT = MATMUL(INV(M2),M1)\r\n! DO MX = 2,M+1\r\n! WRITE(*, *) \"Step :\", MX-1, \"out of\", M\r\n! PHI(1:N,MX) = MATMUL(MAT,PHI(1:N,mx-1))\r\n! P(1:N,MX-1) = EXP(im*K0*(MX-1)*Dr)*PHI(1:N,MX)*(1/SQRT((MX-1)*Dr))\r\n! END DO\r\n! !-----------------------------------------------------------\r\n! ELSEIF (SP == 1) THEN\r\n! !-----------------------------------------------------------\r\n! MAT_SP = SPCONV(MAT) ! SLOW PROCEDURE !\r\n! NELT = MAT_SP%NELT\r\n! ALLOCATE(IMAT(NELT),JMAT(NELT))\r\n! IMAT = MAT_SP%ROW\r\n! JMAT = MAT_SP%COL\r\n! VALMAT = MAT_SP%VAL\r\n! DO MX = 2,M+1\r\n! WRITE(*, *) \"Step :\", mx-1, \"out of\", M\r\n! CALL DSMV(N,PHI(1:N,MX-1),PHI(1:N,MX),NELT,IMAT,JMAT,VALMAT,0)\r\n! P(1:N,mx-1) = EXP(im*K0*(MX-1)*Dr)*PHI(1:N,MX)*(1/SQRT((MX-1)*Dr))\r\n! END DO\r\n! !-----------------------------------------------------------\r\n! ELSE\r\n! !-----------------------------------------------------------\r\n! ALLOCATE(SA1(N**3),SA2(N**3),IJA(N**3))\r\n! THRESH = 0\n! TOL = 1.0e-4_dp\r\n! CALL SPRSIN_DP(M1,THRESH,SP1)\n! CALL SPRSIN_DP(M2,THRESH,SP2)\r\n! DO MX = 2,M+1\r\n! WRITE(*, *) \"Step :\", mx-1, \"out of\", M\r\n! CALL SPRSAX_DP(SP1,PHI(1:N,MX-1),TEMP)\n! CALL LINBCG(SP2,TEMP,PHI(1:N,MX),1,TOL,10,ITER,ERR)\r\n! P(1:N,mx-1) = EXP(im*K0*(MX-1)*Dr)*PHI(1:N,MX)*(1/SQRT((MX-1)*Dr))\r\n! END DO\n! !-----------------------------------------------------------\r\n! END IF\r\n! !-----------------------------------------------------------\r\n CALL CPU_TIME(TF)\r\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\r\n !Transmission loss conversion\r\n P0 = P(NS,1)\r\n DO MX = 1,M\r\n DO NZ = 1,N\r\n LP(NZ,MX) = 20.*LOG10(ABS(P(NZ,MX)/P0))\r\n END DO\r\n END DO\r\n LPG = LP(1,1:M)\r\n LP2 = LP/SQRT(2.)\r\n LPG2 = LP2(1,1:M)\r\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\r\n !Output\r\n OPEN(UNIT=10,FILE=\"results/PE2D_HFR_LPg.dat\")\r\n OPEN(UNIT=20,FILE=\"results/PE2D_HFR_LP.dat\")\r\n OPEN(UNIT=30,FILE=\"results/PE2D_HFR_P.dat\")\r\n DO NZ = 1,N\r\n WRITE(20, 102) LP(NZ,1:M)\r\n WRITE(30, 101) P(NZ,1:M)\r\n END DO\r\n DO MX = 1,M\r\n WRITE(10, 100) MX*Dr, LPG(MX), LPG2(MX)\r\n END DO\r\n 100 FORMAT(3(3X,F12.3))\r\n 101 FORMAT(3X,F12.3,SP,F12.3,SS,\"i\")\r\n 102 FORMAT(100000(3X,F12.3)) \r\n PRINT *, \"Main CPU time (s) :\", TF-TI\r\n PRINT *, \"Source pressure P0 (dB) :\", 20*LOG10(ABS(P0))\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\n !Checking Matrix conditioning\n NORM = ZLANGE('I',N,N,M1,N,WORK)\n WRITE(*,*) \"||M1|| = \", NORM \n CALL ZGECON('I',N,M1,N,NORM,RCOND,CWORK,RWORK,INFO)\n WRITE(*,*) \"K(M1) = \", RCOND, \"COND(M1) = \", 1./RCOND\n WRITE(*,*)\n NORM = ZLANGE('I',N,N,M2,N,WORK)\n WRITE(*,*) \"||M2|| = \", NORM \n CALL ZGECON('I',N,M2,N,NORM,RCOND,CWORK,RWORK,INFO)\n WRITE(*,*) \"K(M2) = \", RCOND, \"COND(M2) = \", 1./RCOND\n WRITE(*,*)\n NORM = ZLANGB('I',N,KL,KU,MB2,KL+KU+1,WORK)\n WRITE(*,*) \"||M2|| = \", NORM \n CALL ZGBCON('I',N,KL,KU,MTEMP,2*KL+KU+1,IPIV,NORM,RCOND,CWORK,RWORK,INFO)\n WRITE(*,*) \"K(M2) = \", RCOND, \"COND(M2) = \", 1./RCOND\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\n !Plotting of results\n CALL SYSTEM('gnuplot -p plot_flat.plt')\r\n !----------------------------------------------------------\r\nEND PROGRAM PE2D_HFR\r\n!-----------------------------------------------------------\r\n!------------- EXTERNAL PROCEDURES ---------------\r\n!-----------------------------------------------------------\r\n", "meta": {"hexsha": "3135372b8a70d423cb076120b1cab1f206c53245", "size": 8273, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "Parabolic_Equation/2DPE/.archives/PE2D_HFR.f03", "max_stars_repo_name": "codorkh/AcousticPE", "max_stars_repo_head_hexsha": "a787496a7800d56743fc606a43acbe9e32de35e0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-03-30T14:02:10.000Z", "max_stars_repo_stars_event_max_datetime": "2017-03-30T14:02:10.000Z", "max_issues_repo_path": "Parabolic_Equation/2DPE/.archives/PE2D_HFR.f03", "max_issues_repo_name": "codorkh/infratopo", "max_issues_repo_head_hexsha": "a787496a7800d56743fc606a43acbe9e32de35e0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Parabolic_Equation/2DPE/.archives/PE2D_HFR.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": 35.2042553191, "max_line_length": 93, "alphanum_fraction": 0.3754381724, "num_tokens": 2790, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096112990283, "lm_q2_score": 0.7606506635289835, "lm_q1q2_score": 0.6968393836998851}} {"text": "C LAST UPDATE 16/03/89\nC+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\nC\n SUBROUTINE LINFIT (X,Y,SIGMAY,NPTS,MODE,A,SIGMAA,B,SIGMAB,R)\n IMPLICIT NONE\nC\nC PURPOSE: LEAST SQUARES FIT TO A STRAIGHT LINE.\nC\n REAL X(1),Y(1),SIGMAY(1),A,SIGMAA,B,SIGMAB,R\n INTEGER NPTS,MODE\n\nC X : ABSCISSA DATA\nC Y : ORDINATE DATA\nC SIGMAY : ARRAY OF STANDARD DEVIATIONS FOR Y VALUES\nC NPTS : NUMBER OF PAIRS OF DATA POINTS\nC MODE : DETERMINES THE METHOD OF WEIGHTING VALUES\nC +1 (INSTRUMENTAL) WT(I)=1./SIGMAY(I)**2\nC 0 (NO WEIGHTING) WT(I)=1.\nC -1 (STATISTICAL) WT(I)=1./X(I)\nC A : Y INTERCEPT OF STRAIGHT LINE\nC SIGMAA : STANDARD DEVIATION OF A\nC B : SLOPE OF FITTED LINE\nC SIGMAB : STANDARD DEVIATION OF B\nC R : LINEAR CORRELATIION COEFFICIENT\nC\nC CALLS 0:\nC\nC-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-\nC LOCAL VARIABLES:\nC\n DOUBLE PRECISION WEIGHT\n DOUBLE PRECISION SUM,SUMX,SUMY,SUMX2,SUMXY,SUMY2,DELTA,VARNCE\n REAL XI,YI,FREE\n INTEGER I\nC\nC WEIGHT : WEIGHTING FACTORS\nC SUM : ACCUMULATED SUM OF WEIGHTS\nC SUMX : ACCUMULATED SUM OF WEIGHTED X DATA\nC SUMY : ACCUMULATED SUM OF WEIGHTED Y DATA\nC SUMX2 : ACCUMULATED SUM OF WEIGHTED Y*Y DATA\nC SUMXY : ACCUMULATED SUM OF WEIGHTED X*Y DATA\nC SUMY2 : ACCUMULATED SUM OF WEIGHTED Y*Y DATA\nC DELTA : WEIGHTING FOR COEFFICIENTS\nC VARNCE : VARIANCE\nC\nC-----------------------------------------------------------------------\nC\nC========ACCUMULATING SUMS\nC\n SUM=0\n SUMX=0\n SUMY=0\n SUMX2=0\n SUMXY=0\n SUMY2=0\nC\n DO 70 I=1,NPTS\n XI = X(I)\n YI = Y(I)\n IF(MODE) 10,40,50\n10 IF (YI) 30,40,20\n20 WEIGHT=1./(YI)\n GOTO 60\n30 WEIGHT=1./(-YI)\n GOTO 60\n40 WEIGHT=1.\n GOTO 60\n50 WEIGHT=1./SIGMAY(I)**2\nC\n60 SUM = SUM + WEIGHT\n SUMX = SUMX + WEIGHT*XI\n SUMY = SUMY + WEIGHT*YI\n SUMX2 = SUMX2 + WEIGHT*XI*XI\n SUMXY = SUMXY + WEIGHT*XI*YI\n SUMY2 = SUMY2 + WEIGHT*YI*YI\n70 CONTINUE\nC \nC========CALCULATING COEFFICIENTS & STANDARD DEVIATIONS\nC\n DELTA = SUM*SUMX2 - SUMX*SUMX\n A = (SUMX2*SUMY - SUMX*SUMXY)/DELTA\n B = (SUMXY*SUM - SUMX*SUMY)/DELTA\n IF (MODE) 80,90,80\n80 VARNCE=1.0\n GOTO 100\n90 FREE = REAL(NPTS-2)\n VARNCE = (SUMY2 + A*A*SUM + B*B*SUMX2\n 1 -2.0*(A*SUMY + B*SUMXY - A*B*SUMX))/FREE\n100 SIGMAA = DSQRT(VARNCE*SUMX2/DELTA)\n SIGMAB = DSQRT(VARNCE*SUM/DELTA)\n R = (SUM*SUMXY-SUMX*SUMY)/DSQRT(DELTA*(SUM*SUMY2-SUMY*SUMY))\n RETURN\nC\n END\n", "meta": {"hexsha": "252bf3a2ccd59df7c910d1273d6514918df16ce9", "size": 2726, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "otoko/src/linfit.f", "max_stars_repo_name": "scattering-central/CCP13", "max_stars_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "otoko/src/linfit.f", "max_issues_repo_name": "scattering-central/CCP13", "max_issues_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "otoko/src/linfit.f", "max_forks_repo_name": "scattering-central/CCP13", "max_forks_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-09-05T15:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-15T11:13:45.000Z", "avg_line_length": 28.6947368421, "max_line_length": 72, "alphanum_fraction": 0.5414526779, "num_tokens": 988, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.916109606718245, "lm_q2_score": 0.7606506635289836, "lm_q1q2_score": 0.6968393802155093}} {"text": "SUBROUTINE evolve(grid, scratch, D, dt, N, M)\n !f2py threadsafe\n !f2py intent(in) grid\n !f2py intent(inplace) scratch\n !f2py intent(in) D\n !f2py intent(in) dt\n !f2py intent(hide) N\n !f2py intent(hide) M\n INTEGER :: N, M\n DOUBLE PRECISION, DIMENSION(N,M) :: grid, scratch\n DOUBLE PRECISION, DIMENSION(N-2, M-2) :: laplacian\n DOUBLE PRECISION :: D, dt\n\n laplacian = grid(3:N, 2:M-1) + grid(1:N-2, 2:M-1) + &\n grid(2:N-1, 3:M) + grid(2:N-1, 1:M-2) - 4 * grid(2:N-1, 2:M-1)\n scratch(2:N-1, 2:M-1) = grid(2:N-1, 2:M-1) + D * dt * laplacian\nEND SUBROUTINE evolve\n", "meta": {"hexsha": "6cb58214697e74503896fc8769772daf7019905e", "size": 611, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "07_compiling/f2py/diffusion.f90", "max_stars_repo_name": "siddheshmhatre/high_performance_python", "max_stars_repo_head_hexsha": "4c308dddb400fcd4c4ab7c4d59dc56eb5dd58d1d", "max_stars_repo_licenses": ["RSA-MD"], "max_stars_count": 698, "max_stars_repo_stars_event_min_datetime": "2015-01-06T14:10:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T03:05:09.000Z", "max_issues_repo_path": "07_compiling/f2py/diffusion.f90", "max_issues_repo_name": "siddheshmhatre/high_performance_python", "max_issues_repo_head_hexsha": "4c308dddb400fcd4c4ab7c4d59dc56eb5dd58d1d", "max_issues_repo_licenses": ["RSA-MD"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2015-01-12T18:03:24.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-02T13:05:20.000Z", "max_forks_repo_path": "07_compiling/f2py/diffusion.f90", "max_forks_repo_name": "siddheshmhatre/high_performance_python", "max_forks_repo_head_hexsha": "4c308dddb400fcd4c4ab7c4d59dc56eb5dd58d1d", "max_forks_repo_licenses": ["RSA-MD"], "max_forks_count": 260, "max_forks_repo_forks_event_min_datetime": "2015-01-16T13:58:57.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-28T16:49:34.000Z", "avg_line_length": 33.9444444444, "max_line_length": 78, "alphanum_fraction": 0.5826513912, "num_tokens": 255, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096181702032, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6968393740144352}} {"text": "subroutine qinit(meqn,mbc,mx,xlower,dx,q,maux,aux)\n\n ! Set initial conditions for the q array.\n ! This default version prints an error message since it should\n ! not be used directly. Copy this to an application directory and\n ! loop over all grid cells to set values of q(1:meqn, 1:mx).\n\n implicit none\n \n integer, intent(in) :: meqn,mbc,mx,maux\n real(kind=8), intent(in) :: xlower,dx\n real(kind=8), intent(in) :: aux(maux,1-mbc:mx+mbc)\n real(kind=8), intent(inout) :: q(meqn,1-mbc:mx+mbc)\n\n integer :: i\n real(kind=8) :: r ,pi, xcell, center, mu1,mu2,mu3,mu4\n\n common /cparam/ mu1,mu2,mu3,mu4\n\n pi = 4.0d0*datan(1.0d0)\n r = 0.2d0 \n center = 0.25d0+ 1.0d-8\n \n do i=1,mx\n xcell = xlower + (i-0.5d0)*dx\n if ((xcell .ge. center-r) .and. (xcell .le. center+r)) then\n q(1,i) = 0.5d0 + 0.5d0*dcos((xcell-center)/r*pi)\n elseif (xcell .le. center-r) then\n q(1,i) = 0.0d0\n else\n q(1,i) = 0.0d0\n endif\n enddo\n\nend subroutine qinit\n\n\n", "meta": {"hexsha": "a95633770b6e7cc100e1732e774b884bd366931a", "size": 1028, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/color/clawpack/qinit.f90", "max_stars_repo_name": "dsrim/mats", "max_stars_repo_head_hexsha": "0a2105f5e05a10785c6936c832a7ace98c8a4b3f", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-12-05T00:16:20.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-05T00:16:20.000Z", "max_issues_repo_path": "examples/color/clawpack/qinit.f90", "max_issues_repo_name": "dsrim/mats", "max_issues_repo_head_hexsha": "0a2105f5e05a10785c6936c832a7ace98c8a4b3f", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "examples/color/clawpack/qinit.f90", "max_forks_repo_name": "dsrim/mats", "max_forks_repo_head_hexsha": "0a2105f5e05a10785c6936c832a7ace98c8a4b3f", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.0526315789, "max_line_length": 70, "alphanum_fraction": 0.5943579767, "num_tokens": 406, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869851639066, "lm_q2_score": 0.7956581049086031, "lm_q1q2_score": 0.6968270129191328}} {"text": "C++---------------------------------------------------------\nC Program to multiply an image with a mask\nC\nC JLP \nC Version of 20-04-2008\nC---------------------------------------------------------\n\tPROGRAM MASK\n\tPARAMETER (IDIM=512)\n\tREAL*4 IMAGE2(IDIM,IDIM),IMAGE1(IDIM,IDIM),MASK2(IDIM,IDIM)\n REAL*4 XLEVEL,RADIUS,RAD2,RR2,EQUIV_RADIUS\n INTEGER*4 IXC,IYC,NPOINTS,NX,NY,ICHOICE \n\tCHARACTER ANS*1,NAME*40,COMMENTS*80\n \n10\tFORMAT(A)\n \n\tCALL JLP_BEGIN\nC Inquire the format of the files :\n\tCALL JLP_INQUIFMT\n \n\tPRINT 85\n85\tFORMAT(' MENU :',/,\n 1\t' 1. Creation of a circular mask ',/,\n 1\t' 2. Creation of a mask with isophotes',/,\n 1\t' 3. Multiplying with a mask (file)',/,\n 1\t' 4. Multiplying with a circular mask',/,\n 1\t' 10. Exit',/,\n 1\t' Enter your choice : ',$)\n\tREAD(5,*) ICHOICE\n IF(ICHOICE.GT.4) THEN\n CALL JLP_END\n STOP\n ENDIF\n \nC------------------------------------------------------------------\nC Circular mask:\nC---------------\n\tIF(ICHOICE.EQ.1)THEN\n200\tPRINT *,' SIZE OF THE OUTPUT FILE : NX,NY ? (MAX=',IDIM,'x',IDIM,')'\n\tREAD(5,*) NX,NY\n IF(NX.GT.IDIM.OR.NY.GT.IDIM) GOTO 200\n\n\tPRINT *,' Warning: range of coordinates from 1 to NX or NY...'\n\tPRINT *,' CENTRE IXC,IYC (0,0 for centered circle) AND RADIUS: ? '\n\tREAD(5,*) IXC,IYC,RADIUS\n IF(IXC.EQ.0.AND.IYC.EQ.0)THEN\n IXC = NX/2 + 1\n IYC = NY/2 + 1\n ENDIF\n\tRAD2=RADIUS*RADIUS\n \nC Erasing output file:\n DO IY=1,NY\n DO IX=1,NX\n IMAGE2(IX,IY)=0.\n ENDDO\n ENDDO\n\nC Generating the array IMAGE2 :\n DO IY=1,NY\n DO IX=1,NX\n\tRR2=(IX-IXC)*(IX-IXC)+(IY-IYC)*(IY-IYC)\n\t IF(RR2.LE.RAD2)THEN\n\t IMAGE2(IX,IY)=1.\n\t ENDIF\n\tEND DO\n\tEND DO\n WRITE(COMMENTS,11) IXC,IYC,RADIUS\n11 FORMAT('Circular mask: IXC=',I4,' IYC=',I4,' Radius=',G9.2)\n \nC------------------------------------------------------------------\nC Isophotes:\nC-----------\n\tELSEIF(ICHOICE.EQ.2)THEN\n \nC Input of the file:\n WRITE(6,*) 'Input file: '\n READ(5,10) NAME\n\tCALL JLP_READIMAG(IMAGE1,NX,NY,IDIM,NAME,COMMENTS)\n\t\nC Input of the parameters :\n\tPRINT *,' Isophote level ?'\n\tREAD(5,*) XLEVEL \n\nC Scanning the image :\n NPOINTS=0\n\tDO IY=1,NY\n\t DO IX=1,NX\n IF(IMAGE1(IX,IY).GE.XLEVEL)THEN\n\t IMAGE2(IX,IY)=1.\n NPOINTS=NPOINTS+1\n ENDIF\n\t END DO\n\tEND DO\n \n EQUIV_RADIUS=SQRT(FLOAT(NPOINTS)/3.14159)\n WRITE(6,22) NPOINTS,EQUIV_RADIUS\n22 FORMAT('NPOINTS=',I5,' EQUIV_RADIUS=',G9.2)\n WRITE(COMMENTS,21) XLEVEL,NAME\n21 FORMAT('Isophotal mask: Level=',G9.2,' from:',A)\n\nC------------------------------------------------------------------\nC Multiplication with a mask:\nC----------------------------\n\tELSEIF(ICHOICE.EQ.3)THEN\n \nC Entering the mask :\n WRITE(6,*) 'Input mask: '\n READ(5,10) NAME\n\tCALL JLP_READIMAG(MASK2,NX,NY,IDIM,NAME,COMMENTS)\n \nC Input of the file:\n WRITE(6,*) 'Input file: '\n READ(5,10) NAME\n\tCALL JLP_READIMAG(IMAGE1,NX,NY,IDIM,NAME,COMMENTS)\n\t\nC Masking the image :\n\tDO IY=1,NY\n\t DO IX=1,NX\n\t IMAGE2(IX,IY)=IMAGE1(IX,IY)*MASK2(IX,IY)\n\t END DO\n\tEND DO\n \nC------------------------------------------------------------------\nC Multiplication with a circular mask:\nC-------------------------------------\n\tELSEIF(ICHOICE.EQ.4)THEN\n \nC Input of the parameters :\n\tPRINT *,' Center : IX,IY and radius?'\n\tREAD(5,*) IXC,IYC,RADIUS\n \nC Input of the file:\n WRITE(6,*) 'Input file: '\n READ(5,10) NAME\n\tCALL JLP_READIMAG(IMAGE1,NX,NY,IDIM,NAME,COMMENTS)\n \nC Masking the image :\n\tCALL MASK_CIRC(IMAGE1,IMAGE2,NX,NY,IDIM,IXC,IYC,RADIUS)\n \n\tCOMMENTS=' '\n WRITE(COMMENTS,41) NAME,IXC,IYC,RADIUS\n41 FORMAT(A,' masked: IXC=',I4,' IYC=',I4,' Radius=',G9.2)\nC------------------------------------------------------------------\n\tENDIF\n \nC------------------------------------------------------------------\nC Output :\n WRITE(6,*) 'Output file: '\n READ(5,10) NAME\n\tCALL JLP_WRITEIMAG(IMAGE2,NX,NY,IDIM,NAME,COMMENTS)\n\n\tCALL JLP_END\n\tSTOP\n\tEND\nC---------------------------------------------------------\nC Subroutine to multiply with a circular mask\nC\nC Input :\nC IMAGE1(NX,NY)\nC IXC,IYC : centre coordinates\nC RADIUS : radius\nC\nC Output :\nC IMAGE2(NX,NY)\nC\nC---------------------------------------------------------\n\tSUBROUTINE MASK_CIRC(IMAGE1,IMAGE2,NX,NY,IDIM,IXC,IYC,RADIUS)\n\tREAL*4 IMAGE1(IDIM,*),IMAGE2(IDIM,*)\n INTEGER*4 IX,IY,NX,NY,IDIM,IXC,IYC\n REAL*4 RR2,RADIUS\n \n\tRAD2=RADIUS*RADIUS\n \nC Main loop :\n\tDO IY=1,NY\n\tDO IX=1,NX\n\t RR2=(IX-IXC)*(IX-IXC)+(IY-IYC)*(IY-IYC)\n\t IF(RR2.GT.RAD2)THEN\n\t IMAGE2(IX,IY)=0.\n ELSE\n\t IMAGE2(IX,IY)=IMAGE1(IX,IY)\n\t ENDIF\n\tEND DO\n\tEND DO\n\t\n\tRETURN\n\tEND\n", "meta": {"hexsha": "a9032550551d95dda0cae54dff5a40c8434ea809", "size": 4745, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "source/image_processing/mask.for", "max_stars_repo_name": "jlprieur/shell_galaxies", "max_stars_repo_head_hexsha": "1dde87ef33b3c33b3a892e9ad0d642ae02ac6d9e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source/image_processing/mask.for", "max_issues_repo_name": "jlprieur/shell_galaxies", "max_issues_repo_head_hexsha": "1dde87ef33b3c33b3a892e9ad0d642ae02ac6d9e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/image_processing/mask.for", "max_forks_repo_name": "jlprieur/shell_galaxies", "max_forks_repo_head_hexsha": "1dde87ef33b3c33b3a892e9ad0d642ae02ac6d9e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.2393617021, "max_line_length": 72, "alphanum_fraction": 0.5251844046, "num_tokens": 1573, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391664210671, "lm_q2_score": 0.7549149978955811, "lm_q1q2_score": 0.6968161103762989}} {"text": "program calc_integer\n implicit none !forces the programmer to declare all variables\n integer :: w,l\n integer :: prmtr, area, diag1, diag2 \n\n w = 3 !Define a\n l = 4 !Define b\n prmtr = 2*(w + l) !Calculate the perimeter of rectangle\n area = w*l !Calculate the area of rectangle\n\n !> Should give error on compilation\n diag1 = sqrt(w**2+l**2) !Calculate diagonal\n diag2 =(w**2+l**2)**0.5 !Calculate diagonal\n\n print*, 'Perimeter = ',prmtr\n print*, 'Area = ' ,area\n print*, 'diag1 = ',diag1\n print*, 'diag2 = ',diag2\n\nend program calc_integer\n", "meta": {"hexsha": "595886cd880c7cd20aab368b7cdee002b19822a9", "size": 614, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "integer/integer.f90", "max_stars_repo_name": "akkiturb/Ilkay-s-Fortran-Class", "max_stars_repo_head_hexsha": "0600640574354052a5a7d87bad520b8a03650d0e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-12-18T19:31:01.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-18T19:31:01.000Z", "max_issues_repo_path": "integer/integer.f90", "max_issues_repo_name": "akkiturb/Scientific-computing-in-Fortran", "max_issues_repo_head_hexsha": "0600640574354052a5a7d87bad520b8a03650d0e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "integer/integer.f90", "max_forks_repo_name": "akkiturb/Scientific-computing-in-Fortran", "max_forks_repo_head_hexsha": "0600640574354052a5a7d87bad520b8a03650d0e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-02-04T19:45:56.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-10T14:22:05.000Z", "avg_line_length": 29.2380952381, "max_line_length": 65, "alphanum_fraction": 0.5977198697, "num_tokens": 182, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391727723468, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6968161049917426}} {"text": "! ********************************************** \n! Last updated: December 10, 2012\n! ********************************************** \n! \n! This subroutine computes the roots of a real polynomial of degree N\n! in any recursively defined polynomial basis. The general \n! algorithm is outlined in: \n!\n! Fast Computation of Eigenvalues of Companion, Comrade and Related Matrices, BIT Numerical Mathematics 2012\n!\n! **************************************************************\n!\n! Input variables:\n!\n! BANDSWITCH 0 indicates no COEFFS are input, 1 indicates COEFFS are given\n!\n! N degree of polynomial\n!\n! K maximum length of the recursion\n!\n! POLY array of dimension N+1 containing the coefficients \n! of the polynomial in terms of the basis elements\n!\n! COEFFS array of dimension (N x K) containing the recursion\n!\t coefficients of the basis elements, ignored if BANDSWITCH = 0 \n!\n! Output variables:\n!\n! RROOTS contains the real part of the computed roots, dimension N\n!\n! IROOTS contains the imaginary part of the computed roots, dimension N\n!\n! ITERATIONS integer array storing the number of iterations per root calculation\n!\n! FLAG reports the position of any instance where the algorithm \n! tried to divide by 0\n!\n! ***************************************************************\n\n\nsubroutine DAVW2(BANDSWITCH,N,K,POLY,COEFFS,RROOTS,IROOTS,ITERATIONS,FLAG)\n\n\n \n\timplicit none \n\n\tinteger, intent(in) :: BANDSWITCH,N,K\n\tinteger, intent(inout) :: ITERATIONS(N),FLAG\n\tdouble precision, intent(in) :: POLY(N+1),COEFFS(N,K) \n\tdouble precision, intent(inout) :: RROOTS(N),IROOTS(N)\n\n\tFLAG = 0\n\n\tif(BANDSWITCH == 0)then\n\t\t\n\t\tcall DLR(N,POLY,RROOTS,IROOTS,ITERATIONS,FLAG)\n\n\telse if(BANDSWITCH == 1)then\n\n\t\tcall DBLR(N,K,POLY,COEFFS,RROOTS,IROOTS,ITERATIONS,FLAG,0,0)\n\n\telse\n\n\t\twrite(*,*) \"Not a valid argument for BANDSWITCH\"\n\t\twrite(*,*) \"\"\n\t\treturn\n\tend if\n\nend subroutine\n\n! ************************************************************** \n! \n! This subroutine calculates the roots using the companion matrix\n!\n! **************************************************************\n\nsubroutine DLR(N,POLY,RROOTS,IROOTS,ITERATIONS,FLAG)\n\n \n implicit none \n\n integer, intent(in) :: N\n double precision, intent(in) :: poly(N) \n double precision, intent(out) :: rroots(N),iroots(N)\n integer, intent(out) :: iterations(N),flag\n integer :: stop_index,start_index,zero_index,ii,jj,kk,mm,it_count,it_max,info\n double precision :: tolerance=1d-16,zero_point,diagonals,diag1,diag2,norm\n double precision :: trace,detm\n double precision :: A(2,2),L1,L2,L3,K,G(3),Blocks(2,2,N)\n\n! Initialize and normalize blocks\n if(dabs(poly(1)) == 0)then\n\twrite(*,*) \"Polynomial is of degree less than N!\"\n\treturn\n end if\n\n do ii=2,N\n\tBlocks(1,1,ii) = -poly(ii)/poly(1)\n\tBlocks(1,2,ii) = 1d0\n\tBlocks(2,1,ii) = 1d0\n\tBlocks(2,2,ii) = 0d0\n end do\n\n Blocks(1,2,N) = -poly(N+1)/poly(1)\n\n Blocks(1,1,1) = 0d0\n Blocks(1,2,1) = 0d0\n Blocks(2,1,1) = 0d0\n Blocks(2,2,1) = 1d0\n\n\t\n! Main loop\n\n stop_index = N\n start_index = 2\n zero_index = 1\n it_max = 20*N\n it_count = 0\n flag = 0\n\n do mm=1,it_max\n\n\t! Zero check\n\tdo ii=1,stop_index\n\t\tzero_point = dabs(Blocks(2,1,stop_index+1-ii))\n\n\t\tif(ii>1)then\n\t\t\tdiag2 = dabs(Blocks(1,1,stop_index+2-ii)*Blocks(2,2,stop_index+1-ii))\n\t\telse\n\t\t\tdiag2 = dabs(Blocks(2,2,stop_index+1-ii))\n\t\tend if\n\n\t\tif(ii1)then\n\t\t\tdiag2 = dabs(Blocks(1,1,stop_index+2-ii)*Blocks(2,2,stop_index+1-ii)*Bands(stop_index+1-ii,1))\n\t\telse\n\t\t\tdiag2 = dabs(Blocks(2,2,stop_index+1-ii)*Bands(stop_index+1-ii,1))\n\t\tend if\n\n\t\tif(ii 0 .and. s < 1)then\t\t\t\t\n\t\t\t\tpoly(ii) = dcos(2d0*pi*v)*dsqrt(-2d0*log(u))\n\t\t\t\texit\n\t\t\tend if\n\t\tend do\n\n\tend do\n\n\nend subroutine\n\n! **********************************************************************\n!\n!\n!\n! **********************************************************************\n\nSUBROUTINE init_random_seed()\n\n\timplicit none\n\n INTEGER :: ii, kk, clock\n INTEGER, DIMENSION(:), ALLOCATABLE :: seed\n \n CALL RANDOM_SEED(size = kk)\n ALLOCATE(seed(kk))\n \n CALL SYSTEM_CLOCK(COUNT=clock)\n \n seed = clock + 37 * (/ (ii - 1, ii = 1, kk) /)\n CALL RANDOM_SEED(PUT = seed)\n \n\tDEALLOCATE(seed)\nEND SUBROUTINE\n", "meta": {"hexsha": "ad972442fc9d69f3322a7179a32b7d279bae13eb", "size": 20356, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "avw2/DAVW2.f90", "max_stars_repo_name": "jaurentz/amvw", "max_stars_repo_head_hexsha": "3b155bd2c0372d21564bdbe2bbd6106298c7cacf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-01-08T05:47:42.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-15T18:30:11.000Z", "max_issues_repo_path": "avw2/DAVW2.f90", "max_issues_repo_name": "jaurentz/amvw", "max_issues_repo_head_hexsha": "3b155bd2c0372d21564bdbe2bbd6106298c7cacf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2016-02-25T13:45:53.000Z", "max_issues_repo_issues_event_max_datetime": "2016-02-25T13:45:53.000Z", "max_forks_repo_path": "avw2/DAVW2.f90", "max_forks_repo_name": "jaurentz/avw", "max_forks_repo_head_hexsha": "3b155bd2c0372d21564bdbe2bbd6106298c7cacf", "max_forks_repo_licenses": ["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.1930693069, "max_line_length": 108, "alphanum_fraction": 0.6069954804, "num_tokens": 7539, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391706552538, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6968161033935174}} {"text": "program problem52\n implicit none\n integer*8 :: i\n\n do i = 1,huge(i)\n if (predicate(i)) then\n exit\n end if\n end do\n\n print *, i\n\ncontains\n\n pure function score(n)\n implicit none\n integer*8, intent(in) :: n\n integer*8 :: temp,score\n integer, parameter, dimension(10) :: primes = [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 ]\n\n score=1\n temp=n\n do while (temp > 0)\n score=score*primes(mod(temp,10)+1)\n temp=temp/10\n end do\n \n end function score\n\n pure function predicate(n)\n implicit none\n integer*8, intent(in) :: n\n integer*8 :: temp1\n logical, dimension(5) :: temp2\n logical :: predicate\n\n temp1=score(n)\n temp2=(/ (score(n*i) == temp1, i = 2, 6) /)\n predicate=all(temp2)\n\n end function predicate\n\nend program problem52\n", "meta": {"hexsha": "d3b4a135635bbb503bf902f17823ab6c7f17669c", "size": 862, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "problem52.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": "problem52.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": "problem52.f08", "max_forks_repo_name": "jamesmcclain/Dioskouroi", "max_forks_repo_head_hexsha": "e433cbf7a1306d2755723f1028a4a3034da9d64a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.5909090909, "max_line_length": 88, "alphanum_fraction": 0.5475638051, "num_tokens": 267, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004187, "lm_q2_score": 0.7826624840223699, "lm_q1q2_score": 0.6967998859710848}} {"text": " Program dgtcon_example\n\n! DGTCON Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_interfaces, Only: dgtcon, dgttrf, dlangt\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nin = 5, nout = 6\n! .. Local Scalars ..\n Real (Kind=dp) :: anorm, rcond\n Integer :: info, n\n! .. Local Arrays ..\n Real (Kind=dp), Allocatable :: d(:), dl(:), du(:), du2(:), work(:)\n Integer, Allocatable :: ipiv(:), iwork(:)\n! .. Intrinsic Procedures ..\n Intrinsic :: epsilon\n! .. Executable Statements ..\n Write (nout, *) 'DGTCON Example Program Results'\n Write (nout, *)\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n\n\n Allocate (d(n), dl(n-1), du(n-1), du2(n-2), work(2*n), ipiv(n), &\n iwork(n))\n\n! Read the tridiagonal matrix A from data file\n\n Read (nin, *) du(1:n-1)\n Read (nin, *) d(1:n)\n Read (nin, *) dl(1:n-1)\n\n! Compute the 1-norm of A\n anorm = dlangt('1-norm', n, dl, d, du)\n\n! Factorize the tridiagonal matrix A\n Call dgttrf(n, dl, d, du, du2, ipiv, info)\n\n If (info==0) Then\n\n! Estimate the condition number of A\n Call dgtcon('1-norm', n, dl, d, du, du2, ipiv, anorm, rcond, work, &\n iwork, info)\n\n! Print the estimated condition number\n\n If (rcond>=epsilon(1.0E0_dp)) Then\n Write (nout, 100) 'Estimate of condition number = ', 1.0_dp/rcond\n Else\n Write (nout, 100) 'A is singular to working precision. RCOND = ', &\n rcond\n End If\n\n Else\n Write (nout, 110) 'The (', info, ',', info, ')', &\n ' element of the factor U is zero'\n End If\n\n100 Format (1X, A, 1P, E10.2)\n110 Format (1X, A, I3, A, I3, A, A)\n End Program\n", "meta": {"hexsha": "05cabf6515752e0f4827aafe2a518d2cd4be8a2e", "size": 2040, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/dgtcon_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/dgtcon_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/dgtcon_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 29.5652173913, "max_line_length": 90, "alphanum_fraction": 0.5588235294, "num_tokens": 644, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.6967998815008681}} {"text": "\tSUBROUTINE GCFPAR ( xx, yy, c, iret )\nC************************************************************************\nC* GCFPAR\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This subroutine fits a second degree polynomial to three points.\t*\nC* It is called by the cubic spline program. Therefore, coefficients\t*\nC* for the two segments are returned as third degree polynomial \t*\nC* coefficients with the cubic term set to 0.\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* GCFPAR ( XX, YY, C, IRET )\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*\tXX (3)\t\tREAL\t\tInput x coordinates\t\t*\nC*\tYY (3)\t\tREAL\t\tInput y coordinates\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tC (4,2)\t\tREAL\t\tCoefficients\t\t\t*\nC*\tIRET\t\tINTEGER\t\tReturn code\t\t\t*\nC*\t\t\t\t\t 0 = normal return\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* M. desJardins/GSFC\t12/85\t\t\t\t\t\t*\nC* T. Lee/GSC\t\t 9/97\tIncluded ERROR.PRM\t\t\t*\nC************************************************************************\n\tINCLUDE\t\t'ERROR.PRM'\nC*\n\tREAL\t\txx (*), yy (*), c (4,*)\nC------------------------------------------------------------------------\n\tiret = NOPNTS\nC\nC*\tDo the computations for the first interval.\nC\n\ty1 = yy (1)\n\ty2 = yy (2)\n\ty3 = yy (3)\n\tx1 = 0.\n\tx2 = xx (2) - xx (1)\n\tx3 = xx (3) - xx (1)\n\ty2y1 = y2 - y1\n\ty3y1 = y3 - y1\n\ty2y1x3 = y2y1 * x3\n\ty3y1x2 = y3y1 * x2\n\tfac = x3**2 * x2 - x2**2 * x3\n\tIF ( fac .eq. 0. ) RETURN\n\tca = ( y3y1x2 - y2y1x3 ) / fac\n\tcb = ( y2y1 - ca * x2**2 ) / x2\n\tc (1,1) = 0\n\tc (2,1) = ca\n\tc (3,1) = cb\n\tc (4,1) = y1\nC\nC*\tDo the computations in the second interval.\nC\n\tx1 = xx (2) - xx (1)\n\tx2 = 0\n\tx3 = xx (3) - xx (1)\n\ty1y2 = y1 - y2\n\ty3y2 = y3 - y2\n\ty1y2x3 = y1y2 * x3\n\ty3y2x1 = y3y2 * x1\n\tfac = x3**2 * x1 - x1**2 * x3\n\tIF ( fac .eq. 0. ) RETURN\n\tca = ( y3y2x1 - y1y2x3 ) / fac\n\tcb = ( y1y2 - ca * x1**2 ) / x1\n\tc (1,2) = 0\n\tc (2,2) = ca\n\tc (3,2) = cb\n\tc (4,2) = y2\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "ab4834462be2d25b38a6fd55810ebc29cfd5e192", "size": 1814, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/gplt/curve/gcfpar.f", "max_stars_repo_name": "oxelson/gempak", "max_stars_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2015-06-03T15:26:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T22:36:03.000Z", "max_issues_repo_path": "gempak/source/gplt/curve/gcfpar.f", "max_issues_repo_name": "oxelson/gempak", "max_issues_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 60, "max_issues_repo_issues_event_min_datetime": "2015-05-11T21:36:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T16:22:42.000Z", "max_forks_repo_path": "gempak/source/gplt/curve/gcfpar.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": 25.1944444444, "max_line_length": 73, "alphanum_fraction": 0.4696802646, "num_tokens": 756, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898153067649, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.696778861939792}} {"text": "\tprogram matrix\n\tparameter (n=700)\n\treal a(n,n), b(n,n), c(n,n)\n\t\nc initialise\n\tdo i=1,n\n\t do j=1,n\n\t a(i,j) = 1.0/float(i+j)\n\t b(i,j) = 1.0/float(i) + 1.0/float(j)\n\t enddo\n\tenddo\n\n\tdo i=1,n\n\t do j=1,n\n\t c(i,j) = 0.0\n\t do k=1,n\n\t c(i,j) = c(i,j) + a(i,k)*b(k,j)\n\t enddo\n\t enddo\n\tenddo\t\n\tprint*,c(10,10)\n\tstop\n\tend\n", "meta": {"hexsha": "3e26381e4baf0547230de11912581cca331af736", "size": 338, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Math3/matrix.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/matrix.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/matrix.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": 14.0833333333, "max_line_length": 41, "alphanum_fraction": 0.4881656805, "num_tokens": 159, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898203834277, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.6967788610489589}} {"text": "submodule(euler_interface_m) euler_prob_0046_m\n implicit none\n\ncontains\n\n module character(len=20) function euler0046()\n write (euler0046, \"(i20)\") ans(10000)\n end function euler0046\n\n integer function ans(n)\n use euler_primes_m, only: sieve_of_Eratosthenes\n implicit none\n integer, intent(in) :: n\n integer :: j, res\n logical :: not_found\n logical, allocatable :: is_prime(:)\n\n call sieve_of_Eratosthenes(n, is_prime)\n res = 1; not_found = .true.\n\n outer: do while (not_found)\n res = res + 2\n j = 2\n not_found = .false.\n\n inner: do while (res >= j)\n if (is_prime(j) .and. is_twice_square(res - j)) then\n not_found = .true.\n exit inner\n end if\n j = j + 1\n end do inner\n end do outer\n\n ans = res\n end function ans\n\n logical function is_twice_square(n)\n integer, intent(in) :: n\n real(dp) :: sqrt_nover2\n\n is_twice_square = .false.\n sqrt_nover2 = sqrt(0.5_dp*real(n, dp))\n\n if (sqrt_nover2 - real(floor(sqrt_nover2), dp) < tiny_dp) &\n is_twice_square = .true.\n end function is_twice_square\n\nend submodule euler_prob_0046_m\n", "meta": {"hexsha": "89e0e49c0f260cf16f062ac4f875746e9c25e288", "size": 1310, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/euler/prob_0046_m.f90", "max_stars_repo_name": "han190/PE-Fortran", "max_stars_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-02-09T07:07:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-31T07:45:48.000Z", "max_issues_repo_path": "src/euler/prob_0046_m.f90", "max_issues_repo_name": "han190/PE-Fortran", "max_issues_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-14T00:48:58.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-14T00:48:58.000Z", "max_forks_repo_path": "docs/src/prob_0046_m.f90", "max_forks_repo_name": "han190/PE-Fortran", "max_forks_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-04T21:29:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T21:29:45.000Z", "avg_line_length": 26.2, "max_line_length": 68, "alphanum_fraction": 0.558778626, "num_tokens": 347, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.7799929104825007, "lm_q1q2_score": 0.6967749991587556}} {"text": "program test\n\nuse, intrinsic:: ieee_arithmetic\nuse lineclip,only: Ccohensutherland, cohensutherland\nuse assert, only: wp, assert_isclose\n\nimplicit none\n\ncall test_lineclip()\ncall test_array_lineclip()\n\ncontains\n\nsubroutine test_array_lineclip()\n\ninteger, parameter :: Np=2\nreal(wp), dimension(Np) :: length, x1,x2,y1,y2\nreal(wp),parameter :: xmin=1., ymax=5.,xmax=4., ymin=3.\nreal(wp),parameter :: truelength(Np) =[2.40370083, 3.]\n\nx1=[0.,0.]\ny1=[0.,4.]\nx2=[4.,5.]\ny2=[6.,4.]\n\n\ncall Ccohensutherland(xmin,ymax,xmax,ymin,Np,x1,y1,x2,y2)\n\nlength = hypot((x2-x1), (y2-y1))\ncall assert_isclose(length, truelength)\n\n!-----------\n\ncall cohensutherland(xmin,ymax,xmax,ymin,x1,y1,x2,y2)\n\nlength = hypot((x2-x1), (y2-y1))\ncall assert_isclose(length, truelength)\n\n\nprint *, 'OK array_lineclip'\n\n\nend subroutine test_array_lineclip\n\n!--------------------\n\nsubroutine test_lineclip()\n\nreal(wp), parameter :: xmin=1., ymax=5., xmax=4., ymin=3.\nreal(wp) :: x1, y1, x2, y2 !not a parameter\n\n! make box with corners LL/UR (1,3) (4,5)\n! and line segment with ends (0,0) (4,6)\n\n! LOWER to UPPER test\nx1=0.; y1=0.; x2=4.; y2=6.\n\ncall cohensutherland(xmin,ymax,xmax,ymin,x1,y1,x2,y2)\n\ncall assert_isclose(x1, 2._wp)\ncall assert_isclose(y1, 3._wp)\ncall assert_isclose(x2, 3.3333333_wp)\ncall assert_isclose(y2, 5._wp)\n\n! no intersection test\nx1=0.;y1=0.1;x2=0.;y2=0.1\n\ncall cohensutherland(xmin,ymax,xmax,ymin,x1,y1,x2,y2)\nif (.not.all(ieee_is_nan([x1,y1,x2,y2]))) error stop 'failed no intersection test'\n\nprint *, 'OK lineclip'\n\nend subroutine test_lineclip\n\n\nend program\n", "meta": {"hexsha": "06634b7fb8f2eae8035acfbedd5c5d43a0429bd1", "size": 1559, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "DemoLineclip.f90", "max_stars_repo_name": "scivision/lineclipping-python-fortran", "max_stars_repo_head_hexsha": "55889ce97b14f69f475ec6e3c516f53529536d4f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2018-02-22T03:25:46.000Z", "max_stars_repo_stars_event_max_datetime": "2019-08-02T08:30:23.000Z", "max_issues_repo_path": "DemoLineclip.f90", "max_issues_repo_name": "scivision/lineclipping-python-fortran", "max_issues_repo_head_hexsha": "55889ce97b14f69f475ec6e3c516f53529536d4f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-19T18:37:37.000Z", "max_issues_repo_issues_event_max_datetime": "2019-11-19T18:37:37.000Z", "max_forks_repo_path": "DemoLineclip.f90", "max_forks_repo_name": "scivision/lineclipping-python-fortran", "max_forks_repo_head_hexsha": "55889ce97b14f69f475ec6e3c516f53529536d4f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-19T15:57:20.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-19T15:57:20.000Z", "avg_line_length": 20.2467532468, "max_line_length": 82, "alphanum_fraction": 0.695958948, "num_tokens": 559, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735663, "lm_q2_score": 0.7799929104825007, "lm_q1q2_score": 0.6967749991587555}} {"text": "program tri_ppal\n\nimplicit none\n\nreal(8), dimension(:), allocatable :: a,b,c,r\n\ninteger :: n, i, j\n\nprint*, 'Introduce o orde do sistema: '\nread*, n\nprint*\nprint*, 'O orde introducido e: ', n\nprint*\n\nallocate(a(n), b(n-1), c(2:n), r(n))\n\nprint*,\nprint*, 'Introduce a diagonal principal: '\nread*, a(1:n)\nprint*,\n\nprint*,\nprint*, 'Introduce a diagonal superior: '\nread*, b(1:n-1)\nprint*,\n\nprint*,\nprint*, 'Introduce a diagonal inferior: '\nread*, c(2:n)\nprint*,\nallocate(a(n), b(n-1), c(2:n), r(n))\nprint*,\nprint*, 'Introduce el segundo miembro: '\nread*, r(1:n)\nprint*,\n\nprint*,\nprint*, 'Diagonal principal: ',a(1:n)\nprint*, 'Diagonal superior: ', b(1:n-1)\nprint*, 'Diagonal inferior ', c(2:n)\nprint*, 'Segundo miembro: ',r(1:n)\nprint*,\n\n\ndo i =2,n\n c(i)=c(i)/a(i-1)\n a(i)=a(i)-c(i)*b(i-1)\nend do\n\ndo i=2,n\n r(i)=r(i)-c(i)*r(i-1)\nend do\n\nr(n)=r(n)/a(n)\n\ndo i=n-1,1,-1\n r(i)= (r(i)-b(i)*r(i+1))/a(i)\nend do\n\nprint*,\nprint*, 'Vector r (Solucion): '\nprint*,\n\nprint*,\nprint*, r\nprint*,\n\n\nend program\n", "meta": {"hexsha": "eddde09fd281e841e28e6a051bfb4faa77718208", "size": 997, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Practica3_lutri/tri_ppal.f95", "max_stars_repo_name": "UxioAndrade/Analisis-Numerico-Matricial", "max_stars_repo_head_hexsha": "1afa52b0994b9cf38822da903609a4d1c91bfab0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Practica3_lutri/tri_ppal.f95", "max_issues_repo_name": "UxioAndrade/Analisis-Numerico-Matricial", "max_issues_repo_head_hexsha": "1afa52b0994b9cf38822da903609a4d1c91bfab0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Practica3_lutri/tri_ppal.f95", "max_forks_repo_name": "UxioAndrade/Analisis-Numerico-Matricial", "max_forks_repo_head_hexsha": "1afa52b0994b9cf38822da903609a4d1c91bfab0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 14.2428571429, "max_line_length": 45, "alphanum_fraction": 0.5987963892, "num_tokens": 383, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6967749854530749}} {"text": "module global_module\n\n! This module contains data needed throughout the program. \n! Most data is specified as a parameter, as to make the execution faster.\n! This module is loaded by most other modules.\n\n implicit none\n \n ! Time integration\n\n !!! For Euler !!! real(kind=8), parameter :: dt = 1.0d-7 ! [s] time step for the simulation\n !!! For Euler !!! real(kind=8), parameter :: t_end = 1.0d-2 ! [s] total simulated time (from 0 to t_end)\n\n real(kind=8), parameter :: dt = 1.0d-4 ! [s] time step for the simulation\n real(kind=8), parameter :: t_end = 10.0d0 ! [s] total simulated time (from 0 to t_end)\n\n ! Specify domain and discretization\n\n real(kind=8), parameter :: x_min = -1.0 ! [m] \n real(kind=8), parameter :: x_max = 2.0 ! [m] \n real(kind=8), parameter :: y_min = -1.0 ! [m] \n real(kind=8), parameter :: y_max = 1.0 ! [m] \n\n ! Total number of cells (including 2 ghost cells for each side)\n ! (using 2 ghost cells makes it easy to reach second order accuracy)\n\n integer, parameter :: Nx = 500\n integer, parameter :: Ny = 500\n\n real(kind=8), parameter :: dx = (x_max-x_min)/(Nx-4)\n real(kind=8), parameter :: dy = (y_max-y_min)/(Ny-4)\n\nend module\n", "meta": {"hexsha": "411bb261e49723b3ff5c84ef5855b8461739b2d5", "size": 1182, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "hyper2D_single_core/hyper2D_basic/src_basic/global_module.f03", "max_stars_repo_name": "sbocce/hyper2D", "max_stars_repo_head_hexsha": "7d1510ac3947b2c154aa0c09945ff05db4bfc8c4", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2022-02-17T14:26:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T01:56:37.000Z", "max_issues_repo_path": "hyper2D_single_core/hyper2D_basic/src_basic/global_module.f03", "max_issues_repo_name": "sbocce/hyper2D", "max_issues_repo_head_hexsha": "7d1510ac3947b2c154aa0c09945ff05db4bfc8c4", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2022-02-28T10:22:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-01T06:25:03.000Z", "max_forks_repo_path": "hyper2D_single_core/hyper2D_basic/src_basic/global_module.f03", "max_forks_repo_name": "sbocce/hyper2D", "max_forks_repo_head_hexsha": "7d1510ac3947b2c154aa0c09945ff05db4bfc8c4", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.7647058824, "max_line_length": 106, "alphanum_fraction": 0.652284264, "num_tokens": 365, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543488, "lm_q2_score": 0.7799928900257127, "lm_q1q2_score": 0.6967749853154844}} {"text": "C\nC NLP-UNCONSTRAINED-CLI/HOOKE-JEEVES/F77/SRC/HOOKE.F\nC =============================================================================\nC NONLINEAR OPTIMIZATION ALGORITHMS MULTILANG. VERSION 0.1\nC =============================================================================\nC NONLINEAR PROGRAMMING ALGORITHMS AS THE (UN-)CONSTRAINED MINIMIZATION\nC PROBLEMS WITH THE FOCUS ON THEIR NUMERICAL EXPRESSION USING VARIOUS\nC PROGRAMMING LANGUAGES.\nC\nC THIS IS THE HOOKE AND JEEVES NONLINEAR UNCONSTRAINED MINIMIZATION ALGORITHM.\nC =============================================================================\nC WRITTEN BY RADISLAV (RADICCHIO) GOLUBTSOV, 2015-2020\nC\nC THIS IS FREE AND UNENCUMBERED SOFTWARE RELEASED INTO THE PUBLIC DOMAIN.\nC\nC ANYONE IS FREE TO COPY, MODIFY, PUBLISH, USE, COMPILE, SELL, OR\nC DISTRIBUTE THIS SOFTWARE, EITHER IN SOURCE CODE FORM OR AS A COMPILED\nC BINARY, FOR ANY PURPOSE, COMMERCIAL OR NON-COMMERCIAL, AND BY ANY\nC MEANS.\nC\nC (SEE THE LICENSE FILE AT THE TOP OF THE SOURCE TREE.)\nC\n\nC === THE USER-SUPPLIED OBJECTIVE FUNCTION F(X,N).\n FUNCTION F(X, N)\n IMPLICIT NONE\n\nC CONSTANT. THE MAXIMUM NUMBER OF VARIABLES.\n INTEGER VARS\n PARAMETER (VARS = 250)\n\nC RETURN VAL. THE OBJECTIVE FUNCTION VALUE.\n DOUBLE PRECISION F\n\nC ARG. THE POINT AT WHICH F(X) SHOULD BE EVALUATED.\n DOUBLE PRECISION X(VARS)\n\nC ARG. THE NUMBER OF COORDINATES OF X.\n INTEGER N\n\nC GLOB. THE NUMBER OF FUNCTION EVALUATIONS.\n INTEGER FUNEVA\n COMMON FUNEVA\n\n#ifndef WOODS\nC ROSENBROCK'S CLASSIC PARABOLIC VALLEY ('BANANA') FUNCTION.\n DOUBLE PRECISION A\n DOUBLE PRECISION B\n DOUBLE PRECISION C\n\n FUNEVA = FUNEVA + 1\n\n A = X(1)\n B = X(2)\n\n C = 100.0 * (B - (A * A)) * (B - (A * A))\n\n F = C + ((1.0 - A) * (1.0 - A))\n#else\nC WOODS -- A LA MORE, GARBOW AND HILLSTROM (TOMS ALGORITHM 566).\n DOUBLE PRECISION S1\n DOUBLE PRECISION S2\n DOUBLE PRECISION S3\n DOUBLE PRECISION T1\n DOUBLE PRECISION T2\n DOUBLE PRECISION T3\n DOUBLE PRECISION T4\n DOUBLE PRECISION T5\n\n FUNEVA = FUNEVA + 1\n\n S1 = X(2) - X(1) * X(1)\n S2 = 1 - X(1)\n S3 = X(2) - 1\n\n T1 = X(4) - X(3) * X(3)\n T2 = 1 - X(3)\n T3 = X(4) - 1\n\n T4 = S3 + T3\n T5 = S3 - T3\n\n F = 100 * (S1 * S1) + S2 * S2\n * + 90 * (T1 * T1) + T2 * T2\n * + 10 * (T4 * T4) + T5 * T5 / 10.\n#endif\n\n IF (N .EQ. 0) THEN\n PRINT 10\n10 FORMAT ('WARNING: THE NUMBER OF COORDINATES OF X = 0.')\n END IF\n\n RETURN\n END\n\nC === HELPER FUNCTION.\nC GIVEN A POINT, LOOK FOR A BETTER ONE NEARBY, ONE COORD AT A TIME.\n FUNCTION BEST_N(DELTA, POINT, PREVBE, NVARS)\n IMPLICIT NONE\n\nC CONSTANT. THE MAXIMUM NUMBER OF VARIABLES.\n INTEGER VARS\n PARAMETER (VARS = 250)\n\nC RETURN VAL. THE OBJECTIVE FUNCTION VALUE AT A NEARBY.\n DOUBLE PRECISION BEST_N\n\nC ARG. THE DELTA BETWEEN PREVBE AND POINT.\n DOUBLE PRECISION DELTA(VARS)\n\nC ARG. THE COORDINATE FROM WHERE TO BEGIN.\n DOUBLE PRECISION POINT(VARS)\n\nC ARG. THE PREVIOUS BEST-VALUED COORDINATE.\n DOUBLE PRECISION PREVBE\n\nC ARG. THE NUMBER OF VARIABLES.\n INTEGER NVARS\n\n DOUBLE PRECISION MINF\n DOUBLE PRECISION Z(VARS)\n DOUBLE PRECISION FTMP\n\n INTEGER I\n\nC PROTO REF. THE OBJECTIVE FUNCTION F(X,N).\n DOUBLE PRECISION F\n\n MINF = PREVBE\n\n DO 10 I = 1, NVARS\n Z(I) = POINT(I)\n10 CONTINUE\n\n DO 20 I = 1, NVARS\n Z(I) = POINT(I) + DELTA(I)\n\n FTMP = F(Z, NVARS)\n\n IF (FTMP .LT. MINF) THEN\n MINF = FTMP\n ELSE\n DELTA(I) = 0.0 - DELTA(I)\n Z(I) = POINT(I) + DELTA(I)\n\n FTMP = F(Z, NVARS)\n\n IF (FTMP .LT. MINF) THEN\n MINF = FTMP\n ELSE\n Z(I) = POINT(I)\n END IF\n END IF\n20 CONTINUE\n\n DO 30 I = 1, NVARS\n POINT(I) = Z(I)\n30 CONTINUE\n\n BEST_N = MINF\n\n RETURN\n END\n\nC === MAIN OPTIMIZATION FUNCTION.\nC THE HOOKE SUBROUTINE ITSELF.\n FUNCTION HOOKE(NVARS, STARTP, ENDPT, RHO, EPSILO, ITERMA)\n IMPLICIT NONE\n\nC CONSTANT. THE MAXIMUM NUMBER OF VARIABLES.\n INTEGER VARS\n PARAMETER (VARS = 250)\n\nC RETURN VAL. THE NUMBER OF ITERATIONS USED TO FIND THE LOCAL MINIMUM.\n INTEGER HOOKE\n\nC ARG. THE NUMBER OF VARIABLES.\n INTEGER NVARS\n\nC ARG. THE STARTING POINT COORDINATES.\n DOUBLE PRECISION STARTP(VARS)\n\nC ARG. THE ENDING POINT COORDINATES.\n DOUBLE PRECISION ENDPT(VARS)\n\nC ARG. THE RHO VALUE.\n DOUBLE PRECISION RHO\n\nC ARG. THE EPSILON VALUE.\n DOUBLE PRECISION EPSILO\n\nC ARG. THE MAXIMUM NUMBER OF ITERATIONS.\n INTEGER ITERMA\n\n INTEGER I\n INTEGER IADJ\n INTEGER ITERS\n INTEGER J\n INTEGER KEEP\n\n DOUBLE PRECISION NEWX(VARS)\n DOUBLE PRECISION XBEFOR(VARS)\n DOUBLE PRECISION DELTA(VARS)\n DOUBLE PRECISION STEPLE\n DOUBLE PRECISION FBEFOR\n DOUBLE PRECISION NEWF\n DOUBLE PRECISION TMP\n\nC GLOB. THE NUMBER OF FUNCTION EVALUATIONS.\n INTEGER FUNEVA\n COMMON FUNEVA\n\nC PROTO REF. THE OBJECTIVE FUNCTION F(X,N).\n DOUBLE PRECISION F\n\nC PROTO REF. THE HELPER FUNCTION BEST_NEARBY(...).\n DOUBLE PRECISION BEST_N\n\n DO 10 I = 1, NVARS\n XBEFOR(I) = STARTP(I)\n NEWX(I) = XBEFOR(I)\n\n DELTA(I) = ABS(STARTP(I) * RHO)\n\n IF (DELTA(I) .EQ. 0.0) THEN\n DELTA(I) = RHO\n END IF\n10 CONTINUE\n\n IADJ = 0\n STEPLE = RHO\n ITERS = 0\n\n FBEFOR = F(NEWX, NVARS)\n\n NEWF = FBEFOR\n\n120 IF ((ITERS .LT. ITERMA) .AND. (STEPLE .GT. EPSILO)) THEN\n ITERS = ITERS + 1\n IADJ = IADJ + 1\n\n PRINT 20, FUNEVA, FBEFOR\n20 FORMAT (/, 'After ', I5, ' funevals, f(x) = ', 1PE10.4E2,\n * ' at')\n\n DO 30 J = 1, NVARS\n PRINT 40, J - 1, XBEFOR(J)\n40 FORMAT (' x[', I2, '] = ', 1PE11.4E2)\n30 CONTINUE\n\nC FIND BEST NEW POINT, ONE COORD AT A TIME.\n DO 50 I = 1, NVARS\n NEWX(I) = XBEFOR(I)\n50 CONTINUE\n\n NEWF = BEST_N(DELTA, NEWX, FBEFOR, NVARS)\n\nC IF WE MADE SOME IMPROVEMENTS, PURSUE THAT DIRECTION.\n KEEP = 1\n\n100 IF ((NEWF .LT. FBEFOR) .AND. (KEEP .EQ. 1)) THEN\n IADJ = 0\n\n DO 60 I = 1, NVARS\nC FIRSTLY, ARRANGE THE SIGN OF DELTA().\n IF (NEWX(I) .LE. XBEFOR(I)) THEN\n DELTA(I) = 0.0 - ABS(DELTA(I))\n ELSE\n DELTA(I) = ABS(DELTA(I))\n END IF\n\nC NOW, MOVE FURTHER IN THIS DIRECTION.\n TMP = XBEFOR(I)\n XBEFOR(I) = NEWX(I)\n NEWX(I) = NEWX(I) + NEWX(I) - TMP\n60 CONTINUE\n\n FBEFOR = NEWF\n\n NEWF = BEST_N(DELTA, NEWX, FBEFOR, NVARS)\n\nC IF THE FURTHER (OPTIMISTIC) MOVE WAS BAD....\n IF (NEWF .GE. FBEFOR) THEN\n GO TO 70\n END IF\n\nC MAKE SURE THAT THE DIFFERENCES BETWEEN THE NEW AND THE OLD\nC POINTS ARE DUE TO ACTUAL DISPLACEMENTS; BEWARE OF ROUNDOFF\nC ERRORS THAT MIGHT CAUSE NEWF < FBEFOR.\n KEEP = 0\n\n DO 80 I = 1, NVARS\n KEEP = 1\n\n IF (ABS(NEWX(I) - XBEFOR(I))\n * .GT. (0.5 * ABS(DELTA(I)))) THEN\n\n GO TO 90\n ELSE\n KEEP = 0\n END IF\n80 CONTINUE\n\n90 GO TO 100\n70 END IF\n\n IF ((STEPLE .GE. EPSILO) .AND. (NEWF .GE. FBEFOR)) THEN\n STEPLE = STEPLE * RHO\n\n DO 110 I = 1, NVARS\n DELTA(I) = DELTA(I) * RHO\n110 CONTINUE\n END IF\n\n GO TO 120\n END IF\n\n DO 130 I = 1, NVARS\n ENDPT(I) = XBEFOR(I)\n130 CONTINUE\n\n HOOKE = ITERS\n\n RETURN\n END\n\nC === MAIN PROGRAM.\n PROGRAM HOOKEF\n IMPLICIT NONE\n\nC CONSTANT. THE MAXIMUM NUMBER OF VARIABLES.\n INTEGER VARS\n PARAMETER (VARS = 250)\n\n#ifndef WOODS\nC CONSTANT. THE STEPSIZE GEOMETRIC SHRINK.\n DOUBLE PRECISION RHO_BE\n PARAMETER (RHO_BE = 0.5)\n#else\nC THE HOOKE AND JEEVES ALGORITHM WORKS REASONABLY WELL ON\nC ROSENBROCK'S FUNCTION, BUT CAN FARE WORSE ON SOME STANDARD\nC TEST FUNCTIONS, DEPENDING ON RHO. HERE IS AN EXAMPLE THAT\nC WORKS WELL WHEN RHO = 0.5, BUT FARES POORLY WITH RHO = 0.6,\nC AND BETTER AGAIN WITH RHO = 0.8.\n DOUBLE PRECISION RHO_WO\n PARAMETER (RHO_WO = 0.6)\n#endif\n\nC CONSTANT. THE ENDING VALUE OF STEPSIZE.\n DOUBLE PRECISION EPSMIN\n PARAMETER (EPSMIN = 1E-6)\n\nC CONSTANT. THE MAXIMUM NUMBER OF ITERATIONS.\n INTEGER IMAX\n PARAMETER (IMAX = 5000)\n\nC GLOB. THE NUMBER OF FUNCTION EVALUATIONS.\n INTEGER FUNEVA\n COMMON FUNEVA\n\n INTEGER NVARS\n INTEGER ITERMA\n INTEGER JJ\n INTEGER I\n\n DOUBLE PRECISION STARTP(VARS)\n DOUBLE PRECISION RHO\n DOUBLE PRECISION EPSILO\n DOUBLE PRECISION ENDPT(VARS)\n\nC PROTO REF. THE MAIN OPTIMIZATION FUNCTION HOOKE(...).\n INTEGER HOOKE\n\n FUNEVA = 0\n\n#ifndef WOODS\nC STARTING GUESS FOR ROSENBROCK'S TEST FUNCTION.\n NVARS = 2\n STARTP(1) = -1.2\n STARTP(2) = 1.0\n RHO = RHO_BE\n#else\nC STARTING GUESS TEST PROBLEM 'WOODS'.\n NVARS = 4\n STARTP(1) = -3\n STARTP(2) = -1\n STARTP(3) = -3\n STARTP(4) = -1\n RHO = RHO_WO\n#endif\n\n ITERMA = IMAX\n EPSILO = EPSMIN\n\n JJ = HOOKE(NVARS, STARTP, ENDPT, RHO, EPSILO, ITERMA)\n\n PRINT 10, JJ\n10 FORMAT (///, 'HOOKE USED ', I2, ' ITERATIONS, AND RETURNED')\n\n DO 20 I = 1, NVARS\n PRINT 30, I - 1, ENDPT(I)\n30 FORMAT ('x[', I3, '] = ', 1PE15.7E2, ' ')\n20 CONTINUE\n\n#ifdef WOODS\n PRINT 40\n40 FORMAT ('True answer: f(1, 1, 1, 1) = 0.')\n#endif\n END\n", "meta": {"hexsha": "3d1620802676f37d43e8cec889617347b382dee1", "size": 11263, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "nlp-unconstrained-cli/hooke-jeeves/f77/src/hooke.f", "max_stars_repo_name": "rgolubtsov/nonlinear-optimization-algorithms-multilang", "max_stars_repo_head_hexsha": "752c60e1a57fa693fc81faedda05500103d2a1dd", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2015-05-29T10:18:31.000Z", "max_stars_repo_stars_event_max_datetime": "2018-03-15T09:48:08.000Z", "max_issues_repo_path": "nlp-unconstrained-cli/hooke-jeeves/f77/src/hooke.f", "max_issues_repo_name": "rgolubtsov/nonlinear-optimization-algorithms-multilang", "max_issues_repo_head_hexsha": "752c60e1a57fa693fc81faedda05500103d2a1dd", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 50, "max_issues_repo_issues_event_min_datetime": "2015-05-19T20:52:56.000Z", "max_issues_repo_issues_event_max_datetime": "2018-02-28T15:10:07.000Z", "max_forks_repo_path": "nlp-unconstrained-cli/hooke-jeeves/f77/src/hooke.f", "max_forks_repo_name": "rgolubtsov/nonlinear-optimization-algorithms-multilang", "max_forks_repo_head_hexsha": "752c60e1a57fa693fc81faedda05500103d2a1dd", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2016-11-05T16:01:59.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-12T16:23:33.000Z", "avg_line_length": 27.4707317073, "max_line_length": 79, "alphanum_fraction": 0.4885021753, "num_tokens": 3218, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099168, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.6967393442396655}} {"text": "module mod_constants\n\n use iso_fortran_env\n\n implicit none\n\n real, parameter :: pi = 3.1415926536\n real, parameter :: e = 2.7182818285\n\n real(kind=real64), parameter :: elementary_charge = 1.602176634D-19\n real(kind=real64), parameter :: G_grav = 6.67430D-11 ! Gravitational constant\n real(kind=real64), parameter :: h_plank = 6.62607015D-34 ! Plank constant\n real(kind=real64), parameter :: c_light = 299792458 ! Light Speed\n real(kind=real64), parameter :: vacuum_electric_permittivity = 8.8541878128D-12\n real(kind=real64), parameter :: vacuum_magnetic_permeability = 1.25663706212D-6\n real(kind=real64), parameter :: electron_mass = 9.1093837015D-31\n real(kind=real64), parameter :: fine_structure = 7.2973525693D-3\n real(kind=real64), parameter :: Josephson = 483597.8484\n real(kind=real64), parameter :: Rydberg = 10973731.568160\n real(kind=real64), parameter :: von_Klitzing = 25812.80745\n\ncontains\n\n subroutine show_consts()\n print *, \"G = \", G_grav\n print *, \"h = \", h_plank\n print *, \"c = \", c_light\n end subroutine show_consts\n\nend module mod_constants\n\nprogram physical_constants\n\n use mod_constants\n\n implicit none\n\n print *, sqrt(2.0_real64)\n print *, sqrt(2.0_real128)\n print *, 'Inverse of Fine Structure constant = ', 1.0_real64 / fine_structure\n\n call show_consts()\n\nend program\n\n", "meta": {"hexsha": "44bb7bbb1c706f79a807827da94ddd0a037aefdd", "size": 1370, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "files/advanced/example_15.f90", "max_stars_repo_name": "WVUHPC/Modern-Fortran", "max_stars_repo_head_hexsha": "97c4db834d4e6ca43802318e4dc63ce4faa641aa", "max_stars_repo_licenses": ["CC-BY-4.0"], "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": "files/advanced/example_15.f90", "max_issues_repo_name": "WVUHPC/Modern-Fortran", "max_issues_repo_head_hexsha": "97c4db834d4e6ca43802318e4dc63ce4faa641aa", "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": "files/advanced/example_15.f90", "max_forks_repo_name": "WVUHPC/Modern-Fortran", "max_forks_repo_head_hexsha": "97c4db834d4e6ca43802318e4dc63ce4faa641aa", "max_forks_repo_licenses": ["CC-BY-4.0"], "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": 29.7826086957, "max_line_length": 84, "alphanum_fraction": 0.702919708, "num_tokens": 421, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007393, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.6967393382617716}} {"text": "! { dg-do run }\n! PR PR 56872 - wrong front-end optimization with a\n! single array constructor and another value.\nprogram main\n real :: s\n integer :: m\n integer :: k\n real :: res\n\n m = 2\n s = 1000.\n\n res = SUM([3.0,(s**(REAL(k-1)/REAL(m-1)),k=1,m),17.])\n if (abs(res - 1021.)>1e-4) call abort\nend\n", "meta": {"hexsha": "fdf049c378e1c741a973b3cd29bdeaf5839a205d", "size": 308, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.dg/array_constructor_45.f90", "max_stars_repo_name": "best08618/asylo", "max_stars_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-05-02T17:34:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-17T10:15:18.000Z", "max_issues_repo_path": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.dg/array_constructor_45.f90", "max_issues_repo_name": "best08618/asylo", "max_issues_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "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": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.dg/array_constructor_45.f90", "max_forks_repo_name": "best08618/asylo", "max_forks_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-27T00:22:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-01T09:41:02.000Z", "avg_line_length": 19.25, "max_line_length": 55, "alphanum_fraction": 0.5909090909, "num_tokens": 115, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190939, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.696739334476354}} {"text": " SUBROUTINE sprsax(sa,ija,x,b,n)\r\n INTEGER n,ija(*)\r\n REAL b(n),sa(*),x(n)\r\n INTEGER i,k\r\n if (ija(1).ne.n+2) pause 'mismatched vector and matrix in sprsax'\r\n do 12 i=1,n\r\n b(i)=sa(i)*x(i)\r\n do 11 k=ija(i),ija(i+1)-1\r\n b(i)=b(i)+sa(k)*x(ija(k))\r\n11 continue\r\n12 continue\r\n return\r\n END\r\n", "meta": {"hexsha": "0284949d20ed43a6516b3e387851294ee8ae2759", "size": 358, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/sprsax.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/sprsax.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/sprsax.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.5714285714, "max_line_length": 72, "alphanum_fraction": 0.4804469274, "num_tokens": 126, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. Yes\n2. Yes", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.8596637451167995, "lm_q1q2_score": 0.696739333965706}} {"text": "!*****************************************************************************************\n!> author: Jacob Williams\n!\n! For computing the obliquity of the ecliptic.\n!\n!### Notes\n! * Mean obliquity does not include the short-period terms\n! due to nutation. True obliquity includes these terms.\n\n module obliquity_module\n\n use conversion_module\n use kind_module\n\n implicit none\n\n private\n\n abstract interface\n pure function mean_obliquity_func(et) result(e)\n !! a function for computing the mean obliquity of the ecliptic.\n import :: wp\n implicit none\n real(wp),intent(in) :: et !! ephemeris time (sec)\n real(wp) :: e !! obliquity of ecliptic (deg)\n end function mean_obliquity_func\n end interface\n\n public :: mean_ecliptic_to_equatorial_rotmat\n public :: equatorial_to_mean_ecliptic_rotmat\n public :: mean_obliquity_of_ecliptic_iau1980\n public :: mean_obliquity_of_ecliptic_iau2006\n\n contains\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Rotation matrix from Mean Ecliptic to J2000.\n!\n!### Reference\n! * https://en.wikipedia.org/wiki/Ecliptic_coordinate_system\n\n pure function mean_ecliptic_to_equatorial_rotmat(obliquity_func) result(rot)\n\n implicit none\n\n real(wp),dimension(3,3) :: rot !! rotation matrix\n procedure(mean_obliquity_func),optional :: obliquity_func !! optional function to compute\n !! the mean obliquity. If not\n !! present, then\n !! [[mean_obliquity_of_ecliptic_iau1980]]\n !! is used.\n\n real(wp) :: e !! mean obliquity at J2000 (rad)\n real(wp) :: s,c\n\n if (present(obliquity_func)) then\n e = obliquity_func(0.0_wp)\n else\n e = mean_obliquity_of_ecliptic_iau1980(0.0_wp)\n end if\n e = e * deg2rad\n s = sin(e)\n c = cos(e)\n\n rot(:,1) = [1.0_wp, 0.0_wp, 0.0_wp]\n rot(:,2) = [0.0_wp, c, s]\n rot(:,3) = [0.0_wp, -s, c]\n\n end function mean_ecliptic_to_equatorial_rotmat\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Rotation matrix from J2000 to Mean Ecliptic.\n\n pure function equatorial_to_mean_ecliptic_rotmat(obliquity_func) result(rot)\n\n implicit none\n\n real(wp),dimension(3,3) :: rot !! rotation matrix\n procedure(mean_obliquity_func),optional :: obliquity_func !! optional function to compute\n !! the mean obliquity. If not\n !! present, then\n !! [[mean_obliquity_of_ecliptic_iau1980]]\n !! is used.\n\n rot = transpose(mean_ecliptic_to_equatorial_rotmat(obliquity_func))\n\n end function equatorial_to_mean_ecliptic_rotmat\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Mean obliquity of the ecliptic, IAU 2006 formula.\n\n pure function mean_obliquity_of_ecliptic_iau2006(et) result(e)\n\n implicit none\n\n real(wp),intent(in) :: et !! ephemeris time (sec)\n real(wp) :: e !! obliquity of ecliptic (deg)\n\n real(wp) :: t !! time in centuries from the J2000 epoch\n\n real(wp),parameter,dimension(6) :: c = [84381.406_wp,&\n -46.836769_wp,&\n -0.0001831_wp,&\n 0.00200340_wp,&\n -0.000000576_wp,&\n -0.0000000434_wp] !! coefficients\n\n ! convert input time to centuries:\n t = et*sec2day*day2century\n\n ! use horner's rule:\n e = (c(1)+t*(c(2)+t*(c(3)+t*(c(4)+t*(c(5)+t*c(6))))))*arcsec2deg\n\n end function mean_obliquity_of_ecliptic_iau2006\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Mean obliquity of the ecliptic, IAU 1980 formula.\n!\n!@note This equation is consistent with the one from the SPICE `zzmobliq` routine.\n\n pure function mean_obliquity_of_ecliptic_iau1980(et) result(e)\n\n implicit none\n\n real(wp),intent(in) :: et !! ephemeris time (sec)\n real(wp) :: e !! obliquity of ecliptic (deg)\n\n real(wp) :: t !! time in centuries from the J2000 epoch\n\n real(wp),dimension(0:3),parameter :: c = [84381.448_wp,&\n -46.8150_wp,&\n -0.00059_wp,&\n +0.001813_wp] !! coefficients\n\n ! convert input time to centuries:\n t = et*sec2day*day2century\n\n ! use horner's rule:\n e = (c(0)+t*(c(1)+t*(c(2)+t*c(3))))*arcsec2deg\n\n end function mean_obliquity_of_ecliptic_iau1980\n!*****************************************************************************************\n\n!*****************************************************************************************\n end module obliquity_module\n!*****************************************************************************************\n", "meta": {"hexsha": "ce002993694b313bdf184867ea6f2c3003b7281f", "size": 5756, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/obliquity_module.f90", "max_stars_repo_name": "jacobwilliams/Fortran-Astrodynamics-Toolk", "max_stars_repo_head_hexsha": "f8e18642dc8d78473d233b8fa6078fdbf7a1d6fc", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 122, "max_stars_repo_stars_event_min_datetime": "2015-01-29T05:40:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:20:21.000Z", "max_issues_repo_path": "src/obliquity_module.f90", "max_issues_repo_name": "gandymagic/Fortran-Astrodynamics-Toolkit", "max_issues_repo_head_hexsha": "7f176fabc8c36cc1981349b02eeb6d8112f2bfbc", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 25, "max_issues_repo_issues_event_min_datetime": "2015-06-10T02:16:59.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T04:28:55.000Z", "max_forks_repo_path": "src/obliquity_module.f90", "max_forks_repo_name": "gandymagic/Fortran-Astrodynamics-Toolkit", "max_forks_repo_head_hexsha": "7f176fabc8c36cc1981349b02eeb6d8112f2bfbc", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 43, "max_forks_repo_forks_event_min_datetime": "2015-02-12T13:24:23.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-30T04:30:49.000Z", "avg_line_length": 37.135483871, "max_line_length": 103, "alphanum_fraction": 0.4482279361, "num_tokens": 1284, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045966995027, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.6967293827911821}} {"text": "!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 1998 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Spherepack *\n! * *\n! * A Package of Fortran Subroutines and Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams and Paul Swarztrauber *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\n! PURPOSE\n! -------\n! This package consists of programs which perform fast fourier\n! transforms for both complex and real periodic sequences and\n! certain other symmetric sequences that are listed below.\n!\n! USAGE\n! -----\n! 1. rffti initialize rfftf and rfftb\n! 2. rfftf forward transform of a real periodic sequence\n! 3. rfftb backward transform of a real coefficient array\n!\n! 4. ezffti initialize ezfftf and ezfftb\n! 5. ezfftf a simplified real periodic forward transform\n! 6. ezfftb a simplified real periodic backward transform\n!\n! 7. sinti initialize sint\n! 8. sint sine transform of a real odd sequence\n!\n! 9. costi initialize cost\n! 10. cost cosine transform of a real even sequence\n!\n! 11. sinqi initialize sinqf and sinqb\n! 12. sinqf forward sine transform with odd wave numbers\n! 13. sinqb unnormalized inverse of sinqf\n!\n! 14. cosqi initialize cosqf and cosqb\n! 15. cosqf forward cosine transform with odd wave numbers\n! 16. cosqb unnormalized inverse of cosqf\n!\n! 17. cffti initialize cfftf and cfftb\n! 18. cfftf forward transform of a complex periodic sequence\n! 19. cfftb unnormalized inverse of cfftf\n!\n! SPECIAL CONDITIONS\n! -------\n! before calling routines ezfftb and ezfftf for the first time, \n! or before calling ezfftb and ezfftf with a different length, \n! users must initialize by calling routine ezffti.\n!\n! HISTORY\n! -------\n! * Developed at NCAR in boulder, colorado by paul n. swarztrauber\n! of the scientific computing division. Released on NCAR's public\n! software libraries in January 1980.\n! * Modified may 29, 1985 to increase efficiency.\n! * Updated by Jon Lo Kim Lin in 2016 to incorporate features\n! of Fortran 2008\n!\n! **********************************************************************\n!\n! subroutine rffti(n, wsave)\n!\n! subroutine rffti initializes the array wsave which is used in\n! both rfftf and rfftb. the prime factorization of n together with\n! a tabulation of the trigonometric functions are computed and\n! stored in wsave.\n!\n! input parameter\n!\n! n the length of the sequence to be transformed.\n!\n! output parameter\n!\n! wsave a work array which must be dimensioned at least 2*n+15.\n! the same work array can be used for both rfftf and rfftb\n! as long as n remains unchanged. different wsave arrays\n! are required for different values of n. the contents of\n! wsave must not be changed between calls of rfftf or rfftb.\n!\n! **********************************************************************\n!\n! subroutine rfftf(n, r, wsave)\n!\n! subroutine rfftf computes the fourier coefficients of a real\n! perodic sequence (fourier analysis). the transform is defined\n! below at output parameter r.\n!\n! input parameters\n!\n! n the length of the array r to be transformed. the method\n! is most efficient when n is a product of small primes.\n! n may change so long as different work arrays are provided\n!\n! r a real array of length n which contains the sequence\n! to be transformed\n!\n! wsave a work array which must be dimensioned at least 2*n+15.\n! in the program that calls rfftf. the wsave array must be\n! initialized by calling subroutine rffti(n, wsave) and a\n! different wsave array must be used for each different\n! value of n. this initialization does not have to be\n! repeated so long as n remains unchanged thus subsequent\n! transforms can be obtained faster than the first.\n! the same wsave array can be used by rfftf and rfftb.\n!\n!\n! output parameters\n!\n! r r(1) = the sum from i=1 to i=n of r(i)\n!\n! if n is even set l =n/2 , if n is odd set l =(n+1)/2\n!\n! then for k = 2, ..., l\n!\n! r(2*k-2) = the sum from i = 1 to i = n of\n!\n! r(i)*cos((k-1)*(i-1)*2*pi/n)\n!\n! r(2*k-1) = the sum from i = 1 to i = n of\n!\n! -r(i)*sin((k-1)*(i-1)*2*pi/n)\n!\n! if n is even\n!\n! r(n) = the sum from i = 1 to i = n of\n!\n! (-1)**(i-1)*r(i)\n!\n! ***** note\n! this transform is unnormalized since a call of rfftf\n! followed by a call of rfftb will multiply the input\n! sequence by n.\n!\n! wsave contains results which must not be destroyed between\n! calls of rfftf or rfftb.\n!\n!\n! **********************************************************************\n!\n! subroutine rfftb(n, r, wsave)\n!\n! subroutine rfftb computes the real perodic sequence from its\n! fourier coefficients (fourier synthesis). the transform is defined\n! below at output parameter r.\n!\n! input parameters\n!\n! n the length of the array r to be transformed. the method\n! is most efficient when n is a product of small primes.\n! n may change so long as different work arrays are provided\n!\n! r a real array of length n which contains the sequence\n! to be transformed\n!\n! wsave a work array which must be dimensioned at least 2*n+15.\n! in the program that calls rfftb. the wsave array must be\n! initialized by calling subroutine rffti(n, wsave) and a\n! different wsave array must be used for each different\n! value of n. this initialization does not have to be\n! repeated so long as n remains unchanged thus subsequent\n! transforms can be obtained faster than the first.\n! the same wsave array can be used by rfftf and rfftb.\n!\n!\n! output parameters\n!\n! r for n even and for i = 1, ..., n\n!\n! r(i) = r(1)+(-1)**(i-1)*r(n)\n!\n! plus the sum from k=2 to k=n/2 of\n!\n! TWO * r(2*k-2)*cos((k-1)*(i-1)*2*pi/n)\n!\n! -TWO * r(2*k-1)*sin((k-1)*(i-1)*2*pi/n)\n!\n! for n odd and for i = 1, ..., n\n!\n! r(i) = r(1) plus the sum from k=2 to k=(n+1)/2 of\n!\n! TWO * r(2*k-2)*cos((k-1)*(i-1)*2*pi/n)\n!\n! -TWO * r(2*k-1)*sin((k-1)*(i-1)*2*pi/n)\n!\n! ***** note\n! this transform is unnormalized since a call of rfftf\n! followed by a call of rfftb will multiply the input\n! sequence by n.\n!\n! wsave contains results which must not be destroyed between\n! calls of rfftb or rfftf.\n!\n!\n! **********************************************************************\n!\n! subroutine ezffti(n, wsave)\n!\n! subroutine ezffti initializes the array wsave which is used in\n! both ezfftf and ezfftb. the prime factorization of n together with\n! a tabulation of the trigonometric functions are computed and\n! stored in wsave.\n!\n! input parameter\n!\n! n the length of the sequence to be transformed.\n!\n! output parameter\n!\n! wsave a work array which must be dimensioned at least 3*n+15.\n! the same work array can be used for both ezfftf and ezfftb\n! as long as n remains unchanged. different wsave arrays\n! are required for different values of n.\n!\n!\n! **********************************************************************\n!\n! subroutine ezfftf(n, r, azero, a, b, wsave)\n!\n! subroutine ezfftf computes the fourier coefficients of a real\n! perodic sequence (fourier analysis). the transform is defined\n! below at output parameters azero, a and b. ezfftf is a simplified\n! but slower Version of rfftf.\n!\n! input parameters\n!\n! n the length of the array r to be transformed. the method\n! is must efficient when n is the product of small primes.\n!\n! r a real array of length n which contains the sequence\n! to be transformed. r is not destroyed.\n!\n!\n! wsave a work array which must be dimensioned at least 3*n+15.\n! in the program that calls ezfftf. the wsave array must be\n! initialized by calling subroutine ezffti(n, wsave) and a\n! different wsave array must be used for each different\n! value of n. this initialization does not have to be\n! repeated so long as n remains unchanged thus subsequent\n! transforms can be obtained faster than the first.\n! the same wsave array can be used by ezfftf and ezfftb.\n!\n! output parameters\n!\n! azero the sum from i=1 to i=n of r(i)/n\n!\n! a, b for n even b(n/2)=0. and a(n/2) is the sum from i=1 to\n! i=n of (-1)**(i-1)*r(i)/n\n!\n! for n even define kmax=n/2-1\n! for n odd define kmax=(n-1)/2\n!\n! then for k=1, ..., kmax\n!\n! a(k) equals the sum from i=1 to i=n of\n!\n! 2./n*r(i)*cos(k*(i-1)*2*pi/n)\n!\n! b(k) equals the sum from i=1 to i=n of\n!\n! 2./n*r(i)*sin(k*(i-1)*2*pi/n)\n!\n!\n! **********************************************************************\n!\n! subroutine ezfftb(n, r, azero, a, b, wsave)\n!\n! subroutine ezfftb computes a real perodic sequence from its\n! fourier coefficients (fourier synthesis). the transform is\n! defined below at output parameter r. ezfftb is a simplified\n! but slower Version of rfftb.\n!\n! input parameters\n!\n! n the length of the output array r. the method is most\n! efficient when n is the product of small primes.\n!\n! azero the constant fourier coefficient\n!\n! a, b arrays which contain the remaining fourier coefficients\n! these arrays are not destroyed.\n!\n! the length of these arrays depends on whether n is even or\n! odd.\n!\n! if n is even n/2 locations are required\n! if n is odd(n-1)/2 locations are required\n!\n! wsave a work array which must be dimensioned at least 3*n+15.\n! in the program that calls ezfftb. the wsave array must be\n! initialized by calling subroutine ezffti(n, wsave) and a\n! different wsave array must be used for each different\n! value of n. this initialization does not have to be\n! repeated so long as n remains unchanged thus subsequent\n! transforms can be obtained faster than the first.\n! the same wsave array can be used by ezfftf and ezfftb.\n!\n!\n! output parameters\n!\n! r if n is even define kmax=n/2\n! if n is odd define kmax=(n-1)/2\n!\n! then for i=1, ..., n\n!\n! r(i)=azero plus the sum from k=1 to k=kmax of\n!\n! a(k)*cos(k*(i-1)*2*pi/n)+b(k)*sin(k*(i-1)*2*pi/n)\n!\n! ********************* complex notation **************************\n!\n! for j=1, ..., n\n!\n! r(j) equals the sum from k=-kmax to k=kmax of\n!\n! c(k)*exp(i*k*(j-1)*2*pi/n)\n!\n! where\n!\n! c(k) = .5*cmplx(a(k), -b(k)) for k=1, ..., kmax\n!\n! c(-k) = conjg(c(k))\n!\n! c(0) = azero\n!\n! and i=sqrt(-1)\n!\n! *************** amplitude - phase notation ***********************\n!\n! for i=1, ..., n\n!\n! r(i) equals azero plus the sum from k=1 to k=kmax of\n!\n! alpha(k)*cos(k*(i-1)*2*pi/n+beta(k))\n!\n! where\n!\n! alpha(k) = sqrt(a(k)*a(k)+b(k)*b(k))\n!\n! cos(beta(k))=a(k)/alpha(k)\n!\n! sin(beta(k))=-b(k)/alpha(k)\n!\n! **********************************************************************\n!\n! subroutine sinti(n, wsave)\n!\n! subroutine sinti initializes the array wsave which is used in\n! subroutine sint. the prime factorization of n together with\n! a tabulation of the trigonometric functions are computed and\n! stored in wsave.\n!\n! input parameter\n!\n! n the length of the sequence to be transformed. the method\n! is most efficient when n+1 is a product of small primes.\n!\n! output parameter\n!\n! wsave a work array with at least int(2.5*n+15) locations.\n! different wsave arrays are required for different values\n! of n. the contents of wsave must not be changed between\n! calls of sint.\n!\n! **********************************************************************\n!\n! subroutine sint(n, x, wsave)\n!\n! subroutine sint computes the discrete fourier sine transform\n! of an odd sequence x(i). the transform is defined below at\n! output parameter x.\n!\n! sint is the unnormalized inverse of itself since a call of sint\n! followed by another call of sint will multiply the input sequence\n! x by 2*(n+1).\n!\n! the array wsave which is used by subroutine sint must be\n! initialized by calling subroutine sinti(n, wsave).\n!\n! input parameters\n!\n! n the length of the sequence to be transformed. the method\n! is most efficient when n+1 is the product of small primes.\n!\n! x an array which contains the sequence to be transformed\n!\n!\n! wsave a work array with dimension at least int(2.5*n+15)\n! in the program that calls sint. the wsave array must be\n! initialized by calling subroutine sinti(n, wsave) and a\n! different wsave array must be used for each different\n! value of n. this initialization does not have to be\n! repeated so long as n remains unchanged thus subsequent\n! transforms can be obtained faster than the first.\n!\n! output parameters\n!\n! x for i=1, ..., n\n!\n! x(i)= the sum from k=1 to k=n\n!\n! 2*x(k)*sin(k*i*pi/(n+1))\n!\n! a call of sint followed by another call of\n! sint will multiply the sequence x by 2*(n+1).\n! hence sint is the unnormalized inverse\n! of itself.\n!\n! wsave contains initialization calculations which must not be\n! destroyed between calls of sint.\n!\n! **********************************************************************\n!\n! subroutine costi(n, wsave)\n!\n! subroutine costi initializes the array wsave which is used in\n! subroutine cost. the prime factorization of n together with\n! a tabulation of the trigonometric functions are computed and\n! stored in wsave.\n!\n! input parameter\n!\n! n the length of the sequence to be transformed. the method\n! is most efficient when n-1 is a product of small primes.\n!\n! output parameter\n!\n! wsave a work array which must be dimensioned at least 3*n+15.\n! different wsave arrays are required for different values\n! of n. the contents of wsave must not be changed between\n! calls of cost.\n!\n! **********************************************************************\n!\n! subroutine cost(n, x, wsave)\n!\n! subroutine cost computes the discrete fourier cosine transform\n! of an even sequence x(i). the transform is defined below at output\n! parameter x.\n!\n! cost is the unnormalized inverse of itself since a call of cost\n! followed by another call of cost will multiply the input sequence\n! x by 2*(n-1). the transform is defined below at output parameter x\n!\n! the array wsave which is used by subroutine cost must be\n! initialized by calling subroutine costi(n, wsave).\n!\n! input parameters\n!\n! n the length of the sequence x. n must be greater than 1.\n! the method is most efficient when n-1 is a product of\n! small primes.\n!\n! x an array which contains the sequence to be transformed\n!\n! wsave a work array which must be dimensioned at least 3*n+15\n! in the program that calls cost. the wsave array must be\n! initialized by calling subroutine costi(n, wsave) and a\n! different wsave array must be used for each different\n! value of n. this initialization does not have to be\n! repeated so long as n remains unchanged thus subsequent\n! transforms can be obtained faster than the first.\n!\n! output parameters\n!\n! x for i=1, ..., n\n!\n! x(i) = x(1)+(-1)**(i-1)*x(n)\n!\n! + the sum from k=2 to k=n-1\n!\n! 2*x(k)*cos((k-1)*(i-1)*pi/(n-1))\n!\n! a call of cost followed by another call of\n! cost will multiply the sequence x by 2*(n-1)\n! hence cost is the unnormalized inverse\n! of itself.\n!\n! wsave contains initialization calculations which must not be\n! destroyed between calls of cost.\n!\n! **********************************************************************\n!\n! subroutine sinqi(n, wsave)\n!\n! subroutine sinqi initializes the array wsave which is used in\n! both sinqf and sinqb. the prime factorization of n together with\n! a tabulation of the trigonometric functions are computed and\n! stored in wsave.\n!\n! input parameter\n!\n! n the length of the sequence to be transformed. the method\n! is most efficient when n is a product of small primes.\n!\n! output parameter\n!\n! wsave a work array which must be dimensioned at least 3*n+15.\n! the same work array can be used for both sinqf and sinqb\n! as long as n remains unchanged. different wsave arrays\n! are required for different values of n. the contents of\n! wsave must not be changed between calls of sinqf or sinqb.\n!\n! **********************************************************************\n!\n! subroutine sinqf(n, x, wsave)\n!\n! subroutine sinqf computes the fast fourier transform of quarter\n! wave data. that is , sinqf computes the coefficients in a sine\n! series representation with only odd wave numbers. the transform\n! is defined below at output parameter x.\n!\n! sinqb is the unnormalized inverse of sinqf since a call of sinqf\n! followed by a call of sinqb will multiply the input sequence x\n! by 4*n.\n!\n! the array wsave which is used by subroutine sinqf must be\n! initialized by calling subroutine sinqi(n, wsave).\n!\n!\n! input parameters\n!\n! n the length of the array x to be transformed. the method\n! is most efficient when n is a product of small primes.\n!\n! x an array which contains the sequence to be transformed\n!\n! wsave a work array which must be dimensioned at least 3*n+15.\n! in the program that calls sinqf. the wsave array must be\n! initialized by calling subroutine sinqi(n, wsave) and a\n! different wsave array must be used for each different\n! value of n. this initialization does not have to be\n! repeated so long as n remains unchanged thus subsequent\n! transforms can be obtained faster than the first.\n!\n! output parameters\n!\n! x for i=1, ..., n\n!\n! x(i) = (-1)**(i-1)*x(n)\n!\n! + the sum from k=1 to k=n-1 of\n!\n! 2*x(k)*sin((2*i-1)*k*pi/(2*n))\n!\n! a call of sinqf followed by a call of\n! sinqb will multiply the sequence x by 4*n.\n! therefore sinqb is the unnormalized inverse\n! of sinqf.\n!\n! wsave contains initialization calculations which must not\n! be destroyed between calls of sinqf or sinqb.\n!\n! **********************************************************************\n!\n! subroutine sinqb(n, x, wsave)\n!\n! subroutine sinqb computes the fast fourier transform of quarter\n! wave data. that is , sinqb computes a sequence from its\n! representation in terms of a sine series with odd wave numbers.\n! the transform is defined below at output parameter x.\n!\n! sinqf is the unnormalized inverse of sinqb since a call of sinqb\n! followed by a call of sinqf will multiply the input sequence x\n! by 4*n.\n!\n! the array wsave which is used by subroutine sinqb must be\n! initialized by calling subroutine sinqi(n, wsave).\n!\n!\n! input parameters\n!\n! n the length of the array x to be transformed. the method\n! is most efficient when n is a product of small primes.\n!\n! x an array which contains the sequence to be transformed\n!\n! wsave a work array which must be dimensioned at least 3*n+15.\n! in the program that calls sinqb. the wsave array must be\n! initialized by calling subroutine sinqi(n, wsave) and a\n! different wsave array must be used for each different\n! value of n. this initialization does not have to be\n! repeated so long as n remains unchanged thus subsequent\n! transforms can be obtained faster than the first.\n!\n! output parameters\n!\n! x for i=1, ..., n\n!\n! x(i)= the sum from k=1 to k=n of\n!\n! 4*x(k)*sin((2k-1)*i*pi/(2*n))\n!\n! a call of sinqb followed by a call of\n! sinqf will multiply the sequence x by 4*n.\n! therefore sinqf is the unnormalized inverse\n! of sinqb.\n!\n! wsave contains initialization calculations which must not\n! be destroyed between calls of sinqb or sinqf.\n!\n! **********************************************************************\n!\n! subroutine cosqi(n, wsave)\n!\n! subroutine cosqi initializes the array wsave which is used in\n! both cosqf and cosqb. the prime factorization of n together with\n! a tabulation of the trigonometric functions are computed and\n! stored in wsave.\n!\n! input parameter\n!\n! n the length of the array to be transformed. the method\n! is most efficient when n is a product of small primes.\n!\n! output parameter\n!\n! wsave a work array which must be dimensioned at least 3*n+15.\n! the same work array can be used for both cosqf and cosqb\n! as long as n remains unchanged. different wsave arrays\n! are required for different values of n. the contents of\n! wsave must not be changed between calls of cosqf or cosqb.\n!\n! **********************************************************************\n!\n! subroutine cosqf(n, x, wsave)\n!\n! subroutine cosqf computes the fast fourier transform of quarter\n! wave data. that is , cosqf computes the coefficients in a cosine\n! series representation with only odd wave numbers. the transform\n! is defined below at output parameter x\n!\n! cosqf is the unnormalized inverse of cosqb since a call of cosqf\n! followed by a call of cosqb will multiply the input sequence x\n! by 4*n.\n!\n! the array wsave which is used by subroutine cosqf must be\n! initialized by calling subroutine cosqi(n, wsave).\n!\n!\n! input parameters\n!\n! n the length of the array x to be transformed. the method\n! is most efficient when n is a product of small primes.\n!\n! x an array which contains the sequence to be transformed\n!\n! wsave a work array which must be dimensioned at least 3*n+15\n! in the program that calls cosqf. the wsave array must be\n! initialized by calling subroutine cosqi(n, wsave) and a\n! different wsave array must be used for each different\n! value of n. this initialization does not have to be\n! repeated so long as n remains unchanged thus subsequent\n! transforms can be obtained faster than the first.\n!\n! output parameters\n!\n! x for i=1, ..., n\n!\n! x(i) = x(1) plus the sum from k=2 to k=n of\n!\n! 2*x(k)*cos((2*i-1)*(k-1)*pi/(2*n))\n!\n! a call of cosqf followed by a call of\n! cosqb will multiply the sequence x by 4*n.\n! therefore cosqb is the unnormalized inverse\n! of cosqf.\n!\n! wsave contains initialization calculations which must not\n! be destroyed between calls of cosqf or cosqb.\n!\n! **********************************************************************\n!\n! subroutine cosqb(n, x, wsave)\n!\n! subroutine cosqb computes the fast fourier transform of quarter\n! wave data. that is , cosqb computes a sequence from its\n! representation in terms of a cosine series with odd wave numbers.\n! the transform is defined below at output parameter x.\n!\n! cosqb is the unnormalized inverse of cosqf since a call of cosqb\n! followed by a call of cosqf will multiply the input sequence x\n! by 4*n.\n!\n! the array wsave which is used by subroutine cosqb must be\n! initialized by calling subroutine cosqi(n, wsave).\n!\n!\n! input parameters\n!\n! n the length of the array x to be transformed. the method\n! is most efficient when n is a product of small primes.\n!\n! x an array which contains the sequence to be transformed\n!\n! wsave a work array that must be dimensioned at least 3*n+15\n! in the program that calls cosqb. the wsave array must be\n! initialized by calling subroutine cosqi(n, wsave) and a\n! different wsave array must be used for each different\n! value of n. this initialization does not have to be\n! repeated so long as n remains unchanged thus subsequent\n! transforms can be obtained faster than the first.\n!\n! output parameters\n!\n! x for i=1, ..., n\n!\n! x(i)= the sum from k=1 to k=n of\n!\n! 4*x(k)*cos((2*k-1)*(i-1)*pi/(2*n))\n!\n! a call of cosqb followed by a call of\n! cosqf will multiply the sequence x by 4*n.\n! therefore cosqf is the unnormalized inverse\n! of cosqb.\n!\n! wsave contains initialization calculations which must not\n! be destroyed between calls of cosqb or cosqf.\n!\n! **********************************************************************\n!\n! subroutine cffti(n, wsave)\n!\n! subroutine cffti initializes the array wsave which is used in\n! both cfftf and cfftb. the prime factorization of n together with\n! a tabulation of the trigonometric functions are computed and\n! stored in wsave.\n!\n! input parameter\n!\n! n the length of the sequence to be transformed\n!\n! output parameter\n!\n! wsave a work array which must be dimensioned at least 4*n+15\n! the same work array can be used for both cfftf and cfftb\n! as long as n remains unchanged. different wsave arrays\n! are required for different values of n. the contents of\n! wsave must not be changed between calls of cfftf or cfftb.\n!\n! **********************************************************************\n!\n! subroutine cfftf(n, c, wsave)\n!\n! subroutine cfftf computes the forward complex discrete fourier\n! transform (the fourier analysis). equivalently , cfftf computes\n! the fourier coefficients of a complex periodic sequence.\n! the transform is defined below at output parameter c.\n!\n! the transform is not normalized. to obtain a normalized transform\n! the output must be divided by n. otherwise a call of cfftf\n! followed by a call of cfftb will multiply the sequence by n.\n!\n! the array wsave which is used by subroutine cfftf must be\n! initialized by calling subroutine cffti(n, wsave).\n!\n! input parameters\n!\n!\n! n the length of the complex sequence c. the method is\n! more efficient when n is the product of small primes. n\n!\n! c a complex array of length n which contains the sequence\n!\n! wsave a real work array which must be dimensioned at least 4n+15\n! in the program that calls cfftf. the wsave array must be\n! initialized by calling subroutine cffti(n, wsave) and a\n! different wsave array must be used for each different\n! value of n. this initialization does not have to be\n! repeated so long as n remains unchanged thus subsequent\n! transforms can be obtained faster than the first.\n! the same wsave array can be used by cfftf and cfftb.\n!\n! output parameters\n!\n! c for j=1, ..., n\n!\n! c(j)=the sum from k=1, ..., n of\n!\n! c(k)*exp(-i*(j-1)*(k-1)*2*pi/n)\n!\n! where i=sqrt(-1)\n!\n! wsave contains initialization calculations which must not be\n! destroyed between calls of subroutine cfftf or cfftb\n!\n! **********************************************************************\n!\n! subroutine cfftb(n, c, wsave)\n!\n! subroutine cfftb computes the backward complex discrete fourier\n! transform (the fourier synthesis). equivalently , cfftb computes\n! a complex periodic sequence from its fourier coefficients.\n! the transform is defined below at output parameter c.\n!\n! a call of cfftf followed by a call of cfftb will multiply the\n! sequence by n.\n!\n! the array wsave which is used by subroutine cfftb must be\n! initialized by calling subroutine cffti(n, wsave).\n!\n! input parameters\n!\n!\n! n the length of the complex sequence c. the method is\n! more efficient when n is the product of small primes.\n!\n! c a complex array of length n which contains the sequence\n!\n! wsave a real work array which must be dimensioned at least 4n+15\n! in the program that calls cfftb. the wsave array must be\n! initialized by calling subroutine cffti(n, wsave) and a\n! different wsave array must be used for each different\n! value of n. this initialization does not have to be\n! repeated so long as n remains unchanged thus subsequent\n! transforms can be obtained faster than the first.\n! the same wsave array can be used by cfftf and cfftb.\n!\n! output parameters\n!\n! c for j=1, ..., n\n!\n! c(j)=the sum from k=1, ..., n of\n!\n! c(k)*exp(i*(j-1)*(k-1)*2*pi/n)\n!\n! where i=sqrt(-1)\n!\n! wsave contains initialization calculations which must not be\n! destroyed between calls of subroutine cfftf or cfftb\n!\nmodule type_FastFourierTransform\n\n use spherepack_precision, only: &\n wp, & ! Working precision\n ip, & ! Integer precision\n PI, &\n TWO_PI, &\n HALF_PI\n\n ! Explicit typing only\n implicit None\n\n ! Everything is private unless stated otherwise\n private\n public :: FastFourierTransform\n\n ! Parameters confined to the module\n real(wp), parameter :: ZERO = 0.0_wp\n real(wp), parameter :: HALF = 0.5_wp\n real(wp), parameter :: ONE = 1.0_wp\n real(wp), parameter :: TWO = 2.0_wp\n real(wp), parameter :: THREE = 3.0_wp\n real(wp), parameter :: FOUR = 4.0_wp\n real(wp), parameter :: FIVE = 5.0_wp\n real(wp), parameter :: SQRT_2 = sqrt(TWO)\n real(wp), parameter :: SQRT_3 = sqrt(THREE)\n real(wp), parameter :: SQRT_5 = sqrt(FIVE)\n\n type, public :: FastFourierTransform\n contains\n ! Type-bound procedures\n procedure, nopass, public :: rffti\n procedure, nopass, public :: rfftf\n procedure, nopass, public :: rfftb\n procedure, nopass, public :: ezffti\n procedure, nopass, public :: ezfftf\n procedure, nopass, public :: ezfftb\n procedure, nopass, public :: sinti\n procedure, nopass, public :: sint\n procedure, nopass, public :: costi\n procedure, nopass, public :: cost\n procedure, nopass, public :: sinqi\n procedure, nopass, public :: sinqf\n procedure, nopass, public :: sinqb\n procedure, nopass, public :: cosqi\n procedure, nopass, public :: cosqf\n procedure, nopass, public :: cosqb\n procedure, nopass, public :: cffti\n procedure, nopass, public :: cfftf\n procedure, nopass, public :: cfftb\n end type FastFourierTransform\n\ncontains\n\n subroutine ezfftf(n, r, azero, a, b, wsave)\n\n ! Dummy arguments\n integer(ip), intent(in) :: n\n real(wp), intent(out) :: azero\n real(wp), intent(in) :: r(*)\n real(wp), intent(out) :: a(*)\n real(wp), intent(out) :: b(*)\n real(wp) :: wsave(*)\n\n ! Local variables\n integer(ip) :: ns2, ns2m\n real(wp) :: cf, cfm\n\n if (3 > n) then\n if (n /= 2) then\n azero = r(1)\n return\n end if\n azero = HALF*(r(1)+r(2))\n a(1) = HALF*(r(1)-r(2))\n return\n end if\n\n wsave(:n) = r(:n)\n\n call rfftf(n, wsave, wsave(n+1))\n\n cf = TWO/n\n cfm = -cf\n azero = HALF*cf*wsave(1)\n ns2 =(n + 1)/2\n ns2m = ns2 - 1\n a(:ns2m) = cf*wsave(2:ns2m*2:2)\n b(:ns2m) = cfm*wsave(3:ns2m*2+1:2)\n\n if (mod(n, 2) /= 1) then\n a(ns2) = HALF*cf*wsave(n)\n b(ns2) = ZERO\n end if\n\n end subroutine ezfftf\n\n subroutine ezfftb(n, r, azero, a, b, wsave)\n\n ! Dummy arguments\n\n integer(ip), intent(in) :: n\n real(wp), intent(in) :: azero\n real(wp) :: r(*)\n real(wp), intent(in) :: a(*)\n real(wp), intent(in) :: b(*)\n real(wp) :: wsave(*)\n\n ! Local variables\n\n integer(ip) :: ns2\n\n\n if (3 > n) then\n if (n /= 2) then\n r(1) = azero\n return\n end if\n r(1) = azero + a(1)\n r(2) = azero - a(1)\n return\n end if\n\n ns2 =(n - 1)/2\n r(2:ns2*2:2) = HALF*a(:ns2)\n r(3:ns2*2+1:2) = -HALF*b(:ns2)\n r(1) = azero\n\n if (mod(n, 2) == 0) r(n) = a(ns2+1)\n\n call rfftb(n, r, wsave(n+1))\n\n end subroutine ezfftb\n\n subroutine ezffti(n, wsave)\n\n ! Dummy arguments\n integer(ip) :: n\n real(wp) :: wsave(*)\n\n if (n > 1) then\n call real_periodic_initialization_lower_utility_routine(n, wsave(2*n+1), wsave(3*n+1))\n end if\n\n end subroutine ezffti\n\n subroutine real_periodic_initialization_lower_utility_routine(n, wa, ifac)\n\n ! Dummy arguments\n integer(ip), intent(in) :: n\n real(wp), intent(inout) :: ifac(*)\n real(wp), intent(inout) :: wa(*)\n\n ! Local variables\n integer(ip), parameter :: NTRYH(*) = [4, 2, 3, 5]\n integer(ip) :: nl, nf, j, ntry, nq, nr, i, is, nfm1\n integer(ip) :: l1, k1, iip, l2, ido, iipm, ii\n real(wp) :: argh, arg1, ch1, sh1, dch1, dsh1, temp\n\n ! Initialize\n ntry = 0\n nl = n\n nf = 0\n j = 0\n\n factorization_loop: do\n\n j = j + 1\n\n if (j <= 4) then\n ntry = NTRYH(j)\n else\n ntry = ntry + 2\n end if\n\n inner_loop: do\n\n nq = nl/ntry\n nr = nl - ntry*nq\n\n if (nr /= 0) cycle factorization_loop\n\n nf = nf + 1\n ifac(nf+2) = ntry\n nl = nq\n\n if (ntry == 2) then\n if (nf /= 1) then\n ifac(nf+2:4:(-1)) = ifac(nf+1:3:(-1))\n ifac(3) = 2\n end if\n end if\n\n if (nl /= 1) cycle inner_loop\n\n exit inner_loop\n end do inner_loop\n exit factorization_loop\n end do factorization_loop\n\n ifac(1) = n\n ifac(2) = nf\n argh = TWO_PI/n\n is = 0\n nfm1 = nf - 1\n l1 = 1\n\n if (nfm1 /= 0) then\n do k1 = 1, nfm1\n iip = int(ifac(k1+2), kind=ip)\n l2 = l1*iip\n ido = n/l2\n iipm = iip - 1\n arg1 = real(l1, kind=wp)*argh\n ch1 = ONE\n sh1 = ZERO\n dch1 = cos(arg1)\n dsh1 = sin(arg1)\n do j = 1, iipm\n temp = dch1*ch1 - dsh1*sh1\n sh1 = dch1*sh1 + dsh1*ch1\n ch1 = temp\n i = is + 2\n wa(i-1) = ch1\n wa(i) = sh1\n if (ido >= 5) then\n do ii = 5, ido, 2\n i = i + 2\n wa(i-1) = ch1*wa(i-3) - sh1*wa(i-2)\n wa(i) = ch1*wa(i-2) + sh1*wa(i-3)\n end do\n end if\n is = is + ido\n end do\n l1 = l2\n end do\n end if\n\n end subroutine real_periodic_initialization_lower_utility_routine\n\n subroutine costi(n, wsave)\n\n ! Dummy arguments\n\n integer(ip), intent(in) :: n\n real(wp) :: wsave(*)\n\n ! Local variables\n\n integer(ip) :: nm1, np1, ns2, k, kc\n real(wp) :: dt, fk\n\n\n if (n > 3) then\n nm1 = n - 1\n np1 = n + 1\n ns2 = n/2\n dt = pi/nm1\n fk = ZERO\n\n do k = 2, ns2\n kc = np1 - k\n fk = fk + ONE\n wsave(k) = TWO * sin(fk*dt)\n wsave(kc) = TWO * cos(fk*dt)\n end do\n\n call rffti(nm1, wsave(n+1))\n\n end if\n\n end subroutine costi\n\n subroutine cost(n, x, wsave)\n\n ! Dummy arguments\n\n integer(ip), intent(in) :: n\n real(wp) :: x(*)\n real(wp) :: wsave(*)\n\n ! Local variables\n\n integer(ip) :: nm1, np1, ns2, k, kc, modn, i\n real(wp) :: x1h, x1p3, tx2, c1, t1, t2, xim2, xi\n\n !\n nm1 = n - 1\n np1 = n + 1\n ns2 = n/2\n\n if (3 < n) then\n if (3 > n) then\n x1h = x(1) + x(2)\n x(2) = x(1) - x(2)\n x(1) = x1h\n return\n end if\n if (n <= 3) then\n x1p3 = x(1) + x(3)\n tx2 = x(2) + x(2)\n x(2) = x(1) - x(3)\n x(1) = x1p3 + tx2\n x(3) = x1p3 - tx2\n return\n end if\n c1 = x(1) - x(n)\n x(1) = x(1) + x(n)\n do k = 2, ns2\n kc = np1 - k\n t1 = x(k) + x(kc)\n t2 = x(k) - x(kc)\n c1 = c1 + wsave(kc)*t2\n t2 = wsave(k)*t2\n x(k) = t1 - t2\n x(kc) = t1 + t2\n end do\n\n modn = mod(n, 2)\n\n if (modn /= 0) x(ns2+1) = x(ns2+1) + x(ns2+1)\n\n call rfftf(nm1, x, wsave(n+1))\n\n xim2 = x(2)\n x(2) = c1\n\n do i = 4, n, 2\n xi = x(i)\n x(i) = x(i-2) - x(i-1)\n x(i-1) = xim2\n xim2 = xi\n end do\n\n if (modn /= 0) x(n) = xim2\n\n end if\n\n end subroutine cost\n\n subroutine sinti(n, wsave)\n\n ! Dummy arguments\n\n integer(ip), intent(in) :: n\n real(wp) :: wsave(*)\n\n ! Local variables\n\n integer(ip) :: ns2, np1, k\n real(wp) :: dt\n\n\n if (n > 1) then\n ns2 = n/2\n np1 = n + 1\n dt = PI/np1\n\n do k = 1, ns2\n wsave(k) = TWO * sin(k*dt)\n end do\n\n call rffti(np1, wsave(ns2+1))\n end if\n\n end subroutine sinti\n\n subroutine sint(n, x, wsave)\n\n ! Dummy arguments\n\n integer(ip) :: n\n real(wp) :: x(*)\n real(wp) :: wsave(*)\n\n ! Local variables\n\n integer(ip) :: np1, iw1, iw2, iw3\n\n\n np1 = n + 1\n iw1 = n/2 + 1\n iw2 = iw1 + np1\n iw3 = iw2 + np1\n\n call sint_lower_utility_routine(n, x, wsave, wsave(iw1), wsave(iw2), wsave(iw3))\n\n end subroutine sint\n\n subroutine sint_lower_utility_routine(n, war, was, xh, x, ifac)\n\n ! Dummy arguments\n\n integer(ip), intent(in) :: n\n real(wp) :: ifac(*)\n real(wp) :: war(*)\n real(wp), intent(in) :: was(*)\n real(wp) :: xh(*)\n real(wp) :: x(*)\n\n ! Local variables\n\n integer(ip) :: i, np1, ns2, k, kc, modn\n real(wp) :: temp, t1, t2\n\n\n xh(:n) = war(:n)\n war(:n) = x(:n)\n\n if (3 > n) then\n if (n /= 2) then\n xh(1) = xh(1) + xh(1)\n x(:n) = war(:n)\n war(:n) = xh(:n)\n return\n end if\n temp = SQRT_3*(xh(1)+xh(2))\n xh(2) = SQRT_3*(xh(1)-xh(2))\n xh(1) = temp\n x(:n) = war(:n)\n war(:n) = xh(:n)\n return\n end if\n\n np1 = n + 1\n ns2 = n/2\n x(1) = ZERO\n\n do k = 1, ns2\n kc = np1 - k\n t1 = xh(k) - xh(kc)\n t2 = was(k)*(xh(k)+xh(kc))\n x(k+1) = t1 + t2\n x(kc+1) = t2 - t1\n end do\n\n modn = mod(n, 2)\n\n if (modn /= 0) x(ns2+2) = FOUR * xh(ns2+1)\n\n call real_forward_lower_utility_routine(np1, x, xh, war, ifac)\n\n xh(1) = HALF*x(1)\n\n do i = 3, n, 2\n xh(i-1) = -x(i)\n xh(i) = xh(i-2) + x(i-1)\n end do\n\n if (modn == 0) xh(n) = -x(n+1)\n\n x(:n) = war(:n)\n war(:n) = xh(:n)\n\n end subroutine sint_lower_utility_routine\n\n subroutine cosqi(n, wsave)\n\n ! Dummy arguments\n\n integer(ip) :: n\n real(wp) :: wsave(*)\n\n ! Local variables\n\n integer(ip) :: k ! Counter\n real(wp) :: fk, dt\n\n\n dt = HALF_PI/n\n\n fk = ZERO\n do k = 1, n\n fk = fk + ONE\n wsave(k) = cos(fk*dt)\n end do\n\n call rffti(n, wsave(n+1))\n\n end subroutine cosqi\n\n subroutine cosqf(n, x, wsave)\n\n ! Dummy arguments\n\n integer(ip), intent(in) :: n\n real(wp) :: x(*)\n real(wp) :: wsave(*)\n\n ! Local variables\n\n real(wp) :: temp\n\n\n if (3 < n) then\n if (n > 2) call cosqf_lower_utility_routine(n, x, wsave, wsave(n+1))\n temp = SQRT_2*x(2)\n x(2) = x(1) - temp\n x(1) = x(1) + temp\n end if\n\n end subroutine cosqf\n\n subroutine cosqf_lower_utility_routine(n, x, w, xh)\n\n ! Dummy arguments\n\n integer(ip), intent(in) :: n\n real(wp) :: x(*)\n real(wp), intent(in) :: w(*)\n real(wp) :: xh(*)\n\n ! Local variables\n\n integer(ip) :: ns2, np2, k, kc, modn, i\n real(wp) :: temp\n\n\n ns2 =(n + 1)/2\n np2 = n + 2\n\n do k = 2, ns2\n kc = np2 - k\n xh(k) = x(k) + x(kc)\n xh(kc) = x(k) - x(kc)\n end do\n\n modn = mod(n, 2)\n\n if (modn == 0) xh(ns2+1) = x(ns2+1) + x(ns2+1)\n\n do k = 2, ns2\n kc = np2 - k\n x(k) = w(k-1)*xh(kc) + w(kc-1)*xh(k)\n x(kc) = w(k-1)*xh(k) - w(kc-1)*xh(kc)\n end do\n\n if (modn == 0) x(ns2+1) = w(ns2)*xh(ns2+1)\n\n call rfftf(n, x, xh)\n\n do i = 3, n, 2\n temp = x(i-1) - x(i)\n x(i) = x(i-1) + x(i)\n x(i-1) = temp\n end do\n\n end subroutine cosqf_lower_utility_routine\n\n\n\n\n subroutine cosqb(n, x, wsave)\n\n ! Dummy arguments\n\n integer(ip) :: n\n real(wp) :: x(*)\n real(wp) :: wsave(*)\n\n ! Local variables\n\n real(wp), parameter :: TWO_SQRT_2 = TWO * sqrt(TWO) ! 2.82842712474619\n real(wp) :: temp\n\n\n if (3 > n) then\n if (n /= 2) then\n x(1) = FOUR * x(1)\n else\n temp = FOUR * (x(1)+x(2))\n x(2) = TWO_SQRT_2*(x(1)-x(2))\n x(1) = temp\n end if\n end if\n\n call cosqb_lower_utility_routine(n, x, wsave, wsave(n+1))\n\n end subroutine cosqb\n\n\n subroutine cosqb_lower_utility_routine(n, x, w, xh)\n\n ! Dummy arguments\n\n integer(ip) :: n\n real(wp) :: x(*)\n real(wp), intent(in) :: w(*)\n real(wp) :: xh(*)\n\n ! Local variables\n\n integer(ip) :: ns2, np2, i, modn, k, kc\n real(wp) :: xim1\n\n\n ns2 =(n + 1)/2\n np2 = n + 2\n\n do i = 3, n, 2\n xim1 = x(i-1) + x(i)\n x(i) = x(i) - x(i-1)\n x(i-1) = xim1\n end do\n\n x(1) = TWO*x(1)\n\n modn = mod(n, 2)\n\n if (modn == 0) x(n) = x(n) + x(n)\n\n call rfftb(n, x, xh)\n\n do k = 2, ns2\n kc = np2 - k\n xh(k) = w(k-1)*x(kc) + w(kc-1)*x(k)\n xh(kc) = w(k-1)*x(k) - w(kc-1)*x(kc)\n end do\n\n if (modn == 0) x(ns2+1) = w(ns2)*(x(ns2+1)+x(ns2+1))\n\n do k = 2, ns2\n kc = np2 - k\n x(k) = xh(k) + xh(kc)\n x(kc) = xh(k) - xh(kc)\n end do\n\n x(1) = TWO*x(1)\n\n end subroutine cosqb_lower_utility_routine\n\n subroutine sinqi(n, wsave)\n\n ! Dummy arguments\n\n integer(ip) :: n\n real(wp) :: wsave(*)\n\n\n call cosqi(n, wsave)\n\n end subroutine sinqi\n\n subroutine sinqf(n, x, wsave)\n\n ! Dummy arguments\n\n integer(ip) :: n\n real(wp) :: x(*)\n real(wp) :: wsave(*)\n\n ! Local variables\n\n integer(ip) :: ns2, k, kc\n real(wp) :: xhold\n\n\n if (n /= 1) then\n\n ns2 = n/2\n\n do k = 1, ns2\n kc = n - k\n xhold = x(k)\n x(k) = x(kc+1)\n x(kc+1) = xhold\n end do\n\n call cosqf(n, x, wsave)\n\n x(2:n:2) = -x(2:n:2)\n\n end if\n\n end subroutine sinqf\n\n subroutine sinqb(n, x, wsave)\n\n ! Dummy arguments\n\n integer(ip) :: n\n real(wp) :: x(*)\n real(wp) :: wsave(*)\n\n ! Local variables\n\n integer(ip) :: ns2, k, kc\n real(wp) :: xhold\n\n\n if (n <= 1) then\n x(1) = FOUR * x(1)\n else\n ns2 = n/2\n x(2:n:2) = -x(2:n:2)\n\n call cosqb(n, x, wsave)\n\n do k = 1, ns2\n kc = n - k\n xhold = x(k)\n x(k) = x(kc+1)\n x(kc+1) = xhold\n end do\n end if\n\n end subroutine sinqb\n\n subroutine cffti(n, wsave)\n\n ! Dummy arguments\n\n integer(ip) :: n\n real(wp) :: wsave(*)\n\n ! Dummy arguments\n\n integer(ip) :: iw1, iw2\n\n\n if (n /= 1) then\n iw1 = 2*n + 1\n iw2 = iw1 + 2*n\n call complex_initialization_lower_utility_routine(n, wsave(iw1), wsave(iw2))\n end if\n\n end subroutine cffti\n\n subroutine complex_initialization_lower_utility_routine(n, wa, ifac)\n\n ! Dummy arguments\n\n integer(ip), intent(in) :: n\n real(wp), intent(inout) :: ifac(*)\n real(wp), intent(inout) :: wa(*)\n\n ! Local variables\n\n integer(ip), parameter :: NTRYH(*) = [3, 4, 2, 5]\n integer(ip) :: nl, nf, j, ntry, nq, nr\n integer(ip) :: i, l1, k1, iip, ld, l2, ido\n integer(ip) :: idot, iipm, i1, ii\n real(wp) :: argh, fi, argld, arg\n\n\n ntry = 0\n nl = n\n nf = 0\n j = 0\n\n factorization_loop: do\n\n j = j + 1\n\n if (j - 4 <= 0) then\n ntry = NTRYH(j)\n else\n ntry = ntry + 2\n end if\n\n inner_loop: do\n\n nq = nl/ntry\n nr = nl - ntry*nq\n\n if (nr /= 0) cycle factorization_loop\n\n nf = nf + 1\n ifac(nf+2) = ntry\n nl = nq\n\n if (ntry == 2) then\n if (nf /= 1) then\n ifac(nf+2:4:(-1)) = ifac(nf+1:3:(-1))\n ifac(3) = 2\n end if\n end if\n\n if (nl /= 1) cycle inner_loop\n exit inner_loop\n end do inner_loop\n exit factorization_loop\n end do factorization_loop\n\n ifac(1) = n\n ifac(2) = nf\n argh = TWO_PI/n\n i = 2\n l1 = 1\n do k1 = 1, nf\n iip = int(ifac(k1+2), kind=ip)\n ld = 0\n l2 = l1*iip\n ido = n/l2\n idot = ido + ido + 2\n iipm = iip - 1\n set_workspace_loop: do j = 1, iipm\n i1 = i\n wa(i-1) = ONE\n wa(i) = ZERO\n ld = ld + l1\n fi = ZERO\n argld = real(ld, kind=wp)*argh\n do ii = 4, idot, 2\n i = i + 2\n fi = fi + ONE\n arg = fi*argld\n wa(i-1) = cos(arg)\n wa(i) = sin(arg)\n end do\n\n if (iip <= 5) cycle set_workspace_loop\n\n wa(i1-1) = wa(i-1)\n wa(i1) = wa(i)\n\n end do set_workspace_loop\n l1 = l2\n end do\n\n end subroutine complex_initialization_lower_utility_routine\n\n subroutine cfftb(n, c, wsave)\n\n ! Dummy arguments\n\n integer(ip) :: n\n real(wp) :: c(*)\n real(wp) :: wsave(*)\n\n ! Dummy arguments\n\n integer(ip) :: iw1, iw2\n\n\n if (n /= 1) then\n iw1 = 2*n + 1\n iw2 = iw1 + 2*n\n call complex_backward_lower_utility_routine(n, c, wsave, wsave(iw1), wsave(iw2))\n end if\n\n end subroutine cfftb\n\n subroutine complex_backward_lower_utility_routine(n, c, ch, wa, ifac)\n\n ! Dummy arguments\n\n integer(ip), intent(in) :: n\n real(wp), intent(in) :: ifac(*)\n real(wp) :: c(*)\n real(wp) :: ch(*)\n real(wp) :: wa(*)\n\n ! Local variables\n\n integer(ip) :: nf, na, l1, iw, k1, iip, l2, ido\n integer(ip) :: idot, idl1, ix2, ix3, ix4, nac, n2\n\n\n nf = int(ifac(2), kind=ip)\n na = 0\n l1 = 1\n iw = 1\n do k1 = 1, nf\n iip = int(ifac(k1+2), kind=ip)\n l2 = iip*l1\n ido = n/l2\n idot = ido + ido\n idl1 = idot*l1\n\n select case (iip)\n case (2)\n if (na == 0) then\n call complex_backward_pass_2(idot, l1, c, ch, wa(iw))\n else\n call complex_backward_pass_2(idot, l1, ch, c, wa(iw))\n end if\n na = 1 - na\n case (3)\n ix2 = iw + idot\n if (na == 0) then\n call complex_backward_pass_3(idot, l1, c, ch, wa(iw), wa(ix2))\n else\n call complex_backward_pass_3(idot, l1, ch, c, wa(iw), wa(ix2))\n end if\n na = 1 - na\n case (4)\n ix2 = iw + idot\n ix3 = ix2 + idot\n if (na == 0) then\n call complex_backward_pass_4(idot, l1, c, ch, wa(iw), wa(ix2), wa(ix3))\n else\n call complex_backward_pass_4(idot, l1, ch, c, wa(iw), wa(ix2), wa(ix3))\n end if\n na = 1 - na\n case (5)\n ix2 = iw + idot\n ix3 = ix2 + idot\n ix4 = ix3 + idot\n if (na == 0) then\n call complex_backward_pass_5(idot, l1, c, ch, wa(iw), wa(ix2), &\n wa(ix3), wa(ix4))\n else\n call complex_backward_pass_5(idot, l1, ch, c, wa(iw), wa(ix2), &\n wa(ix3), wa(ix4))\n end if\n na = 1 - na\n case default\n if (na == 0) then\n call complex_backward_pass_n(nac, idot, iip, l1, idl1, c, c, c, ch, &\n ch, wa(iw))\n else\n call complex_backward_pass_n(nac, idot, iip, l1, idl1, ch, ch, ch, &\n c, c, wa(iw))\n end if\n if (nac /= 0) then\n na = 1 - na\n end if\n end select\n l1 = l2\n iw = iw + (iip - 1)*idot\n end do\n\n if (na /= 0) then\n n2 = 2*n\n c(:n2) = ch(:n2)\n end if\n\n end subroutine complex_backward_lower_utility_routine\n\n pure subroutine complex_backward_pass_2(ido, l1, cc, ch, wa1)\n\n ! Dummy arguments\n\n integer(ip), intent(in) :: ido\n integer(ip), intent(in) :: l1\n real(wp), intent(in) :: cc(ido, 2, l1)\n real(wp), intent(out) :: ch(ido, l1, 2)\n real(wp), intent(in) :: wa1(1)\n\n ! Local variables\n\n integer(ip) :: k, i\n real(wp) :: tr2, ti2\n\n\n if(ido <= 2) then\n ch(1, :, 1) = cc(1, 1, :) + cc(1, 2, :)\n ch(1, :, 2) = cc(1, 1, :) - cc(1, 2, :)\n ch(2, :, 1) = cc(2, 1, :) + cc(2, 2, :)\n ch(2, :, 2) = cc(2, 1, :) - cc(2, 2, :)\n else\n do k = 1, l1\n do i = 2, ido, 2\n ch(i-1, k, 1) = cc(i-1, 1, k) + cc(i-1, 2, k)\n tr2 = cc(i-1, 1, k) - cc(i-1, 2, k)\n ch(i, k, 1) = cc(i, 1, k) + cc(i, 2, k)\n ti2 = cc(i, 1, k) - cc(i, 2, k)\n ch(i, k, 2) = wa1(i-1)*ti2 + wa1(i)*tr2\n ch(i-1, k, 2) = wa1(i-1)*tr2 - wa1(i)*ti2\n end do\n end do\n end if\n\n end subroutine complex_backward_pass_2\n\n pure subroutine complex_backward_pass_3(ido, l1, cc, ch, wa1, wa2)\n\n ! Dummy arguments\n\n integer(ip), intent(in) :: ido\n integer(ip), intent(in) :: l1\n real(wp), intent(in) :: cc(ido, 3, l1)\n real(wp), intent(out) :: ch(ido, l1, 3)\n real(wp), intent(in) :: wa1(*)\n real(wp), intent(in) :: wa2(*)\n\n ! Local variables\n\n integer(ip) :: k, i\n real(wp), parameter :: taur = -HALF\n real(wp), parameter :: taui = SQRT_3/2 ! 0.866025403784439\n real(wp) :: tr2, cr2, ti2, ci2, cr3, ci3, dr2, dr3, di2, di3\n\n\n select case(ido)\n case (2)\n do k = 1, l1\n tr2 = cc(1, 2, k) + cc(1, 3, k)\n cr2 = cc(1, 1, k) + taur*tr2\n ch(1, k, 1) = cc(1, 1, k) + tr2\n ti2 = cc(2, 2, k) + cc(2, 3, k)\n ci2 = cc(2, 1, k) + taur*ti2\n ch(2, k, 1) = cc(2, 1, k) + ti2\n cr3 = taui*(cc(1, 2, k)-cc(1, 3, k))\n ci3 = taui*(cc(2, 2, k)-cc(2, 3, k))\n ch(1, k, 2) = cr2 - ci3\n ch(1, k, 3) = cr2 + ci3\n ch(2, k, 2) = ci2 + cr3\n ch(2, k, 3) = ci2 - cr3\n end do\n case default\n do k = 1, l1\n do i = 2, ido, 2\n tr2 = cc(i-1, 2, k) + cc(i-1, 3, k)\n cr2 = cc(i-1, 1, k) + taur*tr2\n ch(i-1, k, 1) = cc(i-1, 1, k) + tr2\n ti2 = cc(i, 2, k) + cc(i, 3, k)\n ci2 = cc(i, 1, k) + taur*ti2\n ch(i, k, 1) = cc(i, 1, k) + ti2\n cr3 = taui*(cc(i-1, 2, k)-cc(i-1, 3, k))\n ci3 = taui*(cc(i, 2, k)-cc(i, 3, k))\n dr2 = cr2 - ci3\n dr3 = cr2 + ci3\n di2 = ci2 + cr3\n di3 = ci2 - cr3\n ch(i, k, 2) = wa1(i-1)*di2 + wa1(i)*dr2\n ch(i-1, k, 2) = wa1(i-1)*dr2 - wa1(i)*di2\n ch(i, k, 3) = wa2(i-1)*di3 + wa2(i)*dr3\n ch(i-1, k, 3) = wa2(i-1)*dr3 - wa2(i)*di3\n end do\n end do\n end select\n\n end subroutine complex_backward_pass_3\n\n pure subroutine complex_backward_pass_4(ido, l1, cc, ch, wa1, wa2, wa3)\n\n ! Dummy arguments\n\n integer(ip), intent(in) :: ido\n integer(ip), intent(in) :: l1\n real(wp), intent(in) :: cc(ido, 4, l1)\n real(wp), intent(out) :: ch(ido, l1, 4)\n real(wp), intent(in) :: wa1(*)\n real(wp), intent(in) :: wa2(*)\n real(wp), intent(in) :: wa3(*)\n\n ! Local variables\n\n integer(ip) :: k, i\n real(wp) :: ti1, ti2, tr4, ti3, tr1, tr2, ti4\n real(wp) :: tr3, cr3, ci3, cr2, cr4, ci2, ci4\n\n\n select case(ido)\n case (2)\n do k = 1, l1\n ti1 = cc(2, 1, k) - cc(2, 3, k)\n ti2 = cc(2, 1, k) + cc(2, 3, k)\n tr4 = cc(2, 4, k) - cc(2, 2, k)\n ti3 = cc(2, 2, k) + cc(2, 4, k)\n tr1 = cc(1, 1, k) - cc(1, 3, k)\n tr2 = cc(1, 1, k) + cc(1, 3, k)\n ti4 = cc(1, 2, k) - cc(1, 4, k)\n tr3 = cc(1, 2, k) + cc(1, 4, k)\n ch(1, k, 1) = tr2 + tr3\n ch(1, k, 3) = tr2 - tr3\n ch(2, k, 1) = ti2 + ti3\n ch(2, k, 3) = ti2 - ti3\n ch(1, k, 2) = tr1 + tr4\n ch(1, k, 4) = tr1 - tr4\n ch(2, k, 2) = ti1 + ti4\n ch(2, k, 4) = ti1 - ti4\n end do\n case default\n do k = 1, l1\n do i = 2, ido, 2\n ti1 = cc(i, 1, k) - cc(i, 3, k)\n ti2 = cc(i, 1, k) + cc(i, 3, k)\n ti3 = cc(i, 2, k) + cc(i, 4, k)\n tr4 = cc(i, 4, k) - cc(i, 2, k)\n tr1 = cc(i-1, 1, k) - cc(i-1, 3, k)\n tr2 = cc(i-1, 1, k) + cc(i-1, 3, k)\n ti4 = cc(i-1, 2, k) - cc(i-1, 4, k)\n tr3 = cc(i-1, 2, k) + cc(i-1, 4, k)\n ch(i-1, k, 1) = tr2 + tr3\n cr3 = tr2 - tr3\n ch(i, k, 1) = ti2 + ti3\n ci3 = ti2 - ti3\n cr2 = tr1 + tr4\n cr4 = tr1 - tr4\n ci2 = ti1 + ti4\n ci4 = ti1 - ti4\n ch(i-1, k, 2) = wa1(i-1)*cr2 - wa1(i)*ci2\n ch(i, k, 2) = wa1(i-1)*ci2 + wa1(i)*cr2\n ch(i-1, k, 3) = wa2(i-1)*cr3 - wa2(i)*ci3\n ch(i, k, 3) = wa2(i-1)*ci3 + wa2(i)*cr3\n ch(i-1, k, 4) = wa3(i-1)*cr4 - wa3(i)*ci4\n ch(i, k, 4) = wa3(i-1)*ci4 + wa3(i)*cr4\n end do\n end do\n end select\n\n end subroutine complex_backward_pass_4\n\n pure subroutine complex_backward_pass_5(ido, l1, cc, ch, wa1, wa2, wa3, wa4)\n\n ! Dummy arguments\n\n integer(ip), intent(in) :: ido\n integer(ip), intent(in) :: l1\n real(wp), intent(in) :: cc(ido, 5, l1)\n real(wp), intent(out) :: ch(ido, l1, 5)\n real(wp), intent(in) :: wa1(*)\n real(wp), intent(in) :: wa2(*)\n real(wp), intent(in) :: wa3(*)\n real(wp), intent(in) :: wa4(*)\n\n ! Local variables\n\n integer(ip) :: k, i\n real(wp), parameter :: tr11 = (SQRT_5 - ONE)/4 ! 0.309016994374947\n real(wp), parameter :: ti11 = (sqrt(ONE/(FIVE + SQRT_5)))/2 ! 0.951056516295154\n real(wp), parameter :: tr12 = (-ONE - SQRT_5)/4 ! -.809016994374947\n real(wp), parameter :: ti12 = sqrt( FIVE/(TWO*(FIVE + SQRT_5))) ! 0.587785252292473\n real(wp) :: ti5, ti2, ti4, ti3, tr5, tr2, tr4\n real(wp) :: tr3, cr2, ci2, cr3, ci3, cr5, ci5, cr4, ci4, dr3, dr4, di3\n real(wp) :: di4, dr5, dr2, di5, di2\n\n\n select case(ido)\n case (2)\n do k = 1, l1\n ti5 = cc(2, 2, k) - cc(2, 5, k)\n ti2 = cc(2, 2, k) + cc(2, 5, k)\n ti4 = cc(2, 3, k) - cc(2, 4, k)\n ti3 = cc(2, 3, k) + cc(2, 4, k)\n tr5 = cc(1, 2, k) - cc(1, 5, k)\n tr2 = cc(1, 2, k) + cc(1, 5, k)\n tr4 = cc(1, 3, k) - cc(1, 4, k)\n tr3 = cc(1, 3, k) + cc(1, 4, k)\n ch(1, k, 1) = cc(1, 1, k) + tr2 + tr3\n ch(2, k, 1) = cc(2, 1, k) + ti2 + ti3\n cr2 = cc(1, 1, k) + tr11*tr2 + tr12*tr3\n ci2 = cc(2, 1, k) + tr11*ti2 + tr12*ti3\n cr3 = cc(1, 1, k) + tr12*tr2 + tr11*tr3\n ci3 = cc(2, 1, k) + tr12*ti2 + tr11*ti3\n cr5 = ti11*tr5 + ti12*tr4\n ci5 = ti11*ti5 + ti12*ti4\n cr4 = ti12*tr5 - ti11*tr4\n ci4 = ti12*ti5 - ti11*ti4\n ch(1, k, 2) = cr2 - ci5\n ch(1, k, 5) = cr2 + ci5\n ch(2, k, 2) = ci2 + cr5\n ch(2, k, 3) = ci3 + cr4\n ch(1, k, 3) = cr3 - ci4\n ch(1, k, 4) = cr3 + ci4\n ch(2, k, 4) = ci3 - cr4\n ch(2, k, 5) = ci2 - cr5\n end do\n case default\n do k = 1, l1\n do i = 2, ido, 2\n ti5 = cc(i, 2, k) - cc(i, 5, k)\n ti2 = cc(i, 2, k) + cc(i, 5, k)\n ti4 = cc(i, 3, k) - cc(i, 4, k)\n ti3 = cc(i, 3, k) + cc(i, 4, k)\n tr5 = cc(i-1, 2, k) - cc(i-1, 5, k)\n tr2 = cc(i-1, 2, k) + cc(i-1, 5, k)\n tr4 = cc(i-1, 3, k) - cc(i-1, 4, k)\n tr3 = cc(i-1, 3, k) + cc(i-1, 4, k)\n ch(i-1, k, 1) = cc(i-1, 1, k) + tr2 + tr3\n ch(i, k, 1) = cc(i, 1, k) + ti2 + ti3\n cr2 = cc(i-1, 1, k) + tr11*tr2 + tr12*tr3\n ci2 = cc(i, 1, k) + tr11*ti2 + tr12*ti3\n cr3 = cc(i-1, 1, k) + tr12*tr2 + tr11*tr3\n ci3 = cc(i, 1, k) + tr12*ti2 + tr11*ti3\n cr5 = ti11*tr5 + ti12*tr4\n ci5 = ti11*ti5 + ti12*ti4\n cr4 = ti12*tr5 - ti11*tr4\n ci4 = ti12*ti5 - ti11*ti4\n dr3 = cr3 - ci4\n dr4 = cr3 + ci4\n di3 = ci3 + cr4\n di4 = ci3 - cr4\n dr5 = cr2 + ci5\n dr2 = cr2 - ci5\n di5 = ci2 - cr5\n di2 = ci2 + cr5\n ch(i-1, k, 2) = wa1(i-1)*dr2 - wa1(i)*di2\n ch(i, k, 2) = wa1(i-1)*di2 + wa1(i)*dr2\n ch(i-1, k, 3) = wa2(i-1)*dr3 - wa2(i)*di3\n ch(i, k, 3) = wa2(i-1)*di3 + wa2(i)*dr3\n ch(i-1, k, 4) = wa3(i-1)*dr4 - wa3(i)*di4\n ch(i, k, 4) = wa3(i-1)*di4 + wa3(i)*dr4\n ch(i-1, k, 5) = wa4(i-1)*dr5 - wa4(i)*di5\n ch(i, k, 5) = wa4(i-1)*di5 + wa4(i)*dr5\n end do\n end do\n end select\n\n end subroutine complex_backward_pass_5\n\n subroutine complex_backward_pass_n(nac, ido, iip, l1, idl1, cc, c1, c2, ch, ch2, wa)\n\n ! Dummy arguments\n\n integer(ip), intent(out) :: nac\n integer(ip), intent(in) :: ido\n integer(ip), intent(in) :: iip\n integer(ip), intent(in) :: l1\n integer(ip), intent(in) :: idl1\n real(wp), intent(in) :: cc(ido, iip, l1)\n real(wp), intent(out) :: c1(ido, l1, iip)\n real(wp), intent(inout) :: c2(idl1, iip)\n real(wp), intent(inout) :: ch(ido, l1, iip)\n real(wp), intent(inout) :: ch2(idl1, iip)\n real(wp), intent(in) :: wa(*)\n\n ! Local variables\n\n integer(ip) :: idot, nt, iipp2, iipph, idp, j, jc, k\n integer(ip) :: i, idl, inc, l, lc, idlj, idij, idj\n real(wp) :: war, wai\n\n\n idot = ido/2\n nt = iip*idl1\n iipp2 = iip + 2\n iipph = (iip + 1)/2\n idp = iip*ido\n\n if (l1 <= ido) then\n do j = 2, iipph\n jc = iipp2 - j\n ch(:, :, j) = cc(:, j, :) + cc(:, jc, :)\n ch(:, :, jc) = cc(:, j, :) - cc(:, jc, :)\n end do\n ch(:, :, 1) = cc(:, 1, :)\n else\n do j = 2, iipph\n jc = iipp2 - j\n ch(:, :, j) = cc(:, j, :) + cc(:, jc, :)\n ch(:, :, jc) = cc(:, j, :) - cc(:, jc, :)\n end do\n ch(:, :, 1) = cc(:, 1, :)\n end if\n\n idl = 2 - ido\n inc = 0\n\n do l = 2, iipph\n lc = iipp2 - l\n idl = idl + ido\n c2(:, l) = ch2(:, 1) + wa(idl-1)*ch2(:, 2)\n c2(:, lc) = wa(idl)*ch2(:, iip)\n idlj = idl\n inc = inc + ido\n do j = 3, iipph\n jc = iipp2 - j\n idlj = idlj + inc\n if (idlj > idp) idlj = idlj - idp\n war = wa(idlj-1)\n wai = wa(idlj)\n c2(:, l) = c2(:, l) + war*ch2(:, j)\n c2(:, lc) = c2(:, lc) + wai*ch2(:, jc)\n end do\n end do\n\n do j = 2, iipph\n ch2(:, 1) = ch2(:, 1) + ch2(:, j)\n end do\n\n do j = 2, iipph\n jc = iipp2 - j\n ch2(:idl1-1:2, j) = c2(:idl1-1:2, j) - c2(2:idl1:2, jc)\n ch2(:idl1-1:2, jc) = c2(:idl1-1:2, j) + c2(2:idl1:2, jc)\n ch2(2:idl1:2, j) = c2(2:idl1:2, j) + c2(:idl1-1:2, jc)\n ch2(2:idl1:2, jc) = c2(2:idl1:2, j) - c2(:idl1-1:2, jc)\n end do\n\n nac = 1\n\n if(ido /= 2) then\n nac = 0\n c2(:, 1) = ch2(:, 1)\n c1(1, :, 2:iip) = ch(1, :, 2:iip)\n c1(2, :, 2:iip) = ch(2, :, 2:iip)\n\n if(idot <= l1) then\n idij = 0\n do j = 2, iip\n idij = idij + 2\n do i = 4, ido, 2\n idij = idij + 2\n c1(i-1, :, j) = wa(idij-1)*ch(i-1, :, j) - wa(idij)*ch(i, :, j)\n c1(i, :, j) = wa(idij-1)*ch(i, :, j) + wa(idij)*ch(i-1, :, j)\n end do\n end do\n else\n idj = 2 - ido\n do j = 2, iip\n idj = idj + ido\n do k = 1, l1\n idij = idj\n c1(3:ido-1:2, k, j) = wa(idij+1:ido-3+idij:2)*ch(3:ido-1:2, k, j &\n ) - wa(idij+2:ido-2+idij:2)*ch(4:ido:2, k, j)\n c1(4:ido:2, k, j) = wa(idij+1:ido-3+idij:2)*ch(4:ido:2, k, j) + &\n wa(idij+2:ido-2+idij:2)*ch(3:ido-1:2, k, j)\n end do\n end do\n end if\n end if\n\n end subroutine complex_backward_pass_n\n\n subroutine cfftf(n, c, wsave)\n\n ! Dummy arguments\n\n integer(ip), intent(in) :: n\n real(wp), intent(inout) :: c(*)\n real(wp), intent(inout) :: wsave(*)\n\n ! Local variables\n\n integer(ip) :: iw1, iw2\n\n\n if (n /= 1) then\n iw1 = 2*n + 1\n iw2 = iw1 + 2*n\n call complex_forward_lower_utility_routine(n, c, wsave, wsave(iw1), wsave(iw2))\n end if\n\n end subroutine cfftf\n\n subroutine complex_forward_lower_utility_routine(n, c, ch, wa, ifac)\n\n ! Dummy arguments\n\n integer(ip), intent(in) :: n\n real(wp), intent(inout) :: c(*)\n real(wp), intent(inout) :: ch(*)\n real(wp), intent(in) :: wa(*)\n real(wp), intent(in) :: ifac(*)\n\n ! Local variables\n\n integer(ip) :: nf, na, l1, iw, k1, iip, l2, ido\n integer(ip) :: idot, idl1, ix2, ix3, ix4, nac, n2\n\n\n nf = int(ifac(2), kind=ip)\n na = 0\n l1 = 1\n iw = 1\n\n do k1 = 1, nf\n iip = int(ifac(k1+2), kind=ip)\n l2 = iip*l1\n ido = n/l2\n idot = ido + ido\n idl1 = idot*l1\n\n select case (iip)\n case (2)\n if (na == 0) then\n call complex_forward_pass_2(idot, l1, c, ch, wa(iw))\n else\n call complex_forward_pass_2(idot, l1, ch, c, wa(iw))\n end if\n na = 1 - na\n case (3)\n ix2 = iw + idot\n if (na == 0) then\n call complex_forward_pass_3(idot, l1, c, ch, wa(iw), wa(ix2))\n else\n call complex_forward_pass_3(idot, l1, ch, c, wa(iw), wa(ix2))\n end if\n na = 1 - na\n case (4)\n ix3 = ix2 + idot\n if (na == 0) then\n call complex_forward_pass_4(idot, l1, c, ch, wa(iw), wa(ix2), wa(ix3))\n else\n call complex_forward_pass_4(idot, l1, ch, c, wa(iw), wa(ix2), wa(ix3))\n end if\n na = 1 - na\n case (5)\n ix2 = iw + idot\n ix3 = ix2 + idot\n ix4 = ix3 + idot\n if (na == 0) then\n call complex_forward_pass_5(idot, l1, c, ch, wa(iw), wa(ix2), wa(ix3), wa(ix4))\n else\n call complex_forward_pass_5(idot, l1, ch, c, wa(iw), wa(ix2), wa(ix3), wa(ix4))\n end if\n na = 1 - na\n case default\n if (na == 0) then\n call complex_forward_pass_n(nac, idot, iip, l1, idl1, c, c, c, ch, ch, wa(iw))\n else\n call complex_forward_pass_n(nac, idot, iip, l1, idl1, ch, ch, ch, c, c, wa(iw))\n end if\n if (nac /= 0) na = 1 - na\n end select\n l1 = l2\n iw = iw + (iip - 1)*idot\n end do\n\n if (na /= 0) then\n n2 = n + n\n c(:n2) = ch(:n2)\n end if\n\n end subroutine complex_forward_lower_utility_routine\n\n\n pure subroutine complex_forward_pass_2(ido, l1, cc, ch, wa1)\n\n ! Dummy arguments\n\n integer(ip), intent(in) :: ido\n integer(ip), intent(in) :: l1\n real(wp), intent(in) :: cc(ido, 2, l1)\n real(wp), intent(out) :: ch(ido, l1, 2)\n real(wp), intent(in) :: wa1(*)\n\n ! Local variables\n\n integer(ip) :: k, i\n real(wp) :: tr2, ti2\n\n\n if(ido <= 2) then\n ch(1, :, 1) = cc(1, 1, :) + cc(1, 2, :)\n ch(1, :, 2) = cc(1, 1, :) - cc(1, 2, :)\n ch(2, :, 1) = cc(2, 1, :) + cc(2, 2, :)\n ch(2, :, 2) = cc(2, 1, :) - cc(2, 2, :)\n else\n do k = 1, l1\n do i = 2, ido, 2\n ch(i-1, k, 1) = cc(i-1, 1, k) + cc(i-1, 2, k)\n tr2 = cc(i-1, 1, k) - cc(i-1, 2, k)\n ch(i, k, 1) = cc(i, 1, k) + cc(i, 2, k)\n ti2 = cc(i, 1, k) - cc(i, 2, k)\n ch(i, k, 2) = wa1(i-1)*ti2 - wa1(i)*tr2\n ch(i-1, k, 2) = wa1(i-1)*tr2 + wa1(i)*ti2\n end do\n end do\n end if\n\n end subroutine complex_forward_pass_2\n\n\n pure subroutine complex_forward_pass_3(ido, l1, cc, ch, wa1, wa2)\n\n ! Dummy arguments\n\n integer(ip), intent(in) :: ido\n integer(ip), intent(in) :: l1\n real(wp), intent(in) :: cc(ido, 3, l1)\n real(wp), intent(out) :: ch(ido, l1, 3)\n real(wp), intent(in) :: wa1(*)\n real(wp), intent(in) :: wa2(*)\n\n ! Local variables\n\n integer(ip) :: k, i\n real(wp), parameter :: taur = -HALF\n real(wp), parameter :: taui = -SQRT_3/2 ! - 0.866025403784439\n real(wp) :: tr2, cr2, ti2, ci2, cr3, ci3, dr2, dr3, di2, di3\n\n\n select case(ido)\n case (2)\n do k = 1, l1\n tr2 = cc(1, 2, k) + cc(1, 3, k)\n cr2 = cc(1, 1, k) + taur*tr2\n ch(1, k, 1) = cc(1, 1, k) + tr2\n ti2 = cc(2, 2, k) + cc(2, 3, k)\n ci2 = cc(2, 1, k) + taur*ti2\n ch(2, k, 1) = cc(2, 1, k) + ti2\n cr3 = taui*(cc(1, 2, k)-cc(1, 3, k))\n ci3 = taui*(cc(2, 2, k)-cc(2, 3, k))\n ch(1, k, 2) = cr2 - ci3\n ch(1, k, 3) = cr2 + ci3\n ch(2, k, 2) = ci2 + cr3\n ch(2, k, 3) = ci2 - cr3\n end do\n case default\n do k = 1, l1\n do i = 2, ido, 2\n tr2 = cc(i-1, 2, k) + cc(i-1, 3, k)\n cr2 = cc(i-1, 1, k) + taur*tr2\n ch(i-1, k, 1) = cc(i-1, 1, k) + tr2\n ti2 = cc(i, 2, k) + cc(i, 3, k)\n ci2 = cc(i, 1, k) + taur*ti2\n ch(i, k, 1) = cc(i, 1, k) + ti2\n cr3 = taui*(cc(i-1, 2, k)-cc(i-1, 3, k))\n ci3 = taui*(cc(i, 2, k)-cc(i, 3, k))\n dr2 = cr2 - ci3\n dr3 = cr2 + ci3\n di2 = ci2 + cr3\n di3 = ci2 - cr3\n ch(i, k, 2) = wa1(i-1)*di2 - wa1(i)*dr2\n ch(i-1, k, 2) = wa1(i-1)*dr2 + wa1(i)*di2\n ch(i, k, 3) = wa2(i-1)*di3 - wa2(i)*dr3\n ch(i-1, k, 3) = wa2(i-1)*dr3 + wa2(i)*di3\n end do\n end do\n end select\n\n end subroutine complex_forward_pass_3\n\n pure subroutine complex_forward_pass_4(ido, l1, cc, ch, wa1, wa2, wa3)\n\n ! Dummy arguments\n\n integer(ip), intent(in) :: ido\n integer(ip), intent(in) :: l1\n real(wp), intent(in) :: cc(ido, 4, l1)\n real(wp), intent(out) :: ch(ido, l1, 4)\n real(wp), intent(in) :: wa1(*)\n real(wp), intent(in) :: wa2(*)\n real(wp), intent(in) :: wa3(*)\n\n ! Local variables\n\n integer(ip) :: k, i\n real(wp) :: ti1, ti2, tr4, ti3, tr1, tr2, ti4\n real(wp) :: tr3, cr3, ci3, cr2, cr4, ci2, ci4\n\n\n select case(ido)\n case (2)\n do k = 1, l1\n ti1 = cc(2, 1, k) - cc(2, 3, k)\n ti2 = cc(2, 1, k) + cc(2, 3, k)\n tr4 = cc(2, 2, k) - cc(2, 4, k)\n ti3 = cc(2, 2, k) + cc(2, 4, k)\n tr1 = cc(1, 1, k) - cc(1, 3, k)\n tr2 = cc(1, 1, k) + cc(1, 3, k)\n ti4 = cc(1, 4, k) - cc(1, 2, k)\n tr3 = cc(1, 2, k) + cc(1, 4, k)\n ch(1, k, 1) = tr2 + tr3\n ch(1, k, 3) = tr2 - tr3\n ch(2, k, 1) = ti2 + ti3\n ch(2, k, 3) = ti2 - ti3\n ch(1, k, 2) = tr1 + tr4\n ch(1, k, 4) = tr1 - tr4\n ch(2, k, 2) = ti1 + ti4\n ch(2, k, 4) = ti1 - ti4\n end do\n case default\n do k = 1, l1\n do i = 2, ido, 2\n ti1 = cc(i, 1, k) - cc(i, 3, k)\n ti2 = cc(i, 1, k) + cc(i, 3, k)\n ti3 = cc(i, 2, k) + cc(i, 4, k)\n tr4 = cc(i, 2, k) - cc(i, 4, k)\n tr1 = cc(i-1, 1, k) - cc(i-1, 3, k)\n tr2 = cc(i-1, 1, k) + cc(i-1, 3, k)\n ti4 = cc(i-1, 4, k) - cc(i-1, 2, k)\n tr3 = cc(i-1, 2, k) + cc(i-1, 4, k)\n ch(i-1, k, 1) = tr2 + tr3\n cr3 = tr2 - tr3\n ch(i, k, 1) = ti2 + ti3\n ci3 = ti2 - ti3\n cr2 = tr1 + tr4\n cr4 = tr1 - tr4\n ci2 = ti1 + ti4\n ci4 = ti1 - ti4\n ch(i-1, k, 2) = wa1(i-1)*cr2 + wa1(i)*ci2\n ch(i, k, 2) = wa1(i-1)*ci2 - wa1(i)*cr2\n ch(i-1, k, 3) = wa2(i-1)*cr3 + wa2(i)*ci3\n ch(i, k, 3) = wa2(i-1)*ci3 - wa2(i)*cr3\n ch(i-1, k, 4) = wa3(i-1)*cr4 + wa3(i)*ci4\n ch(i, k, 4) = wa3(i-1)*ci4 - wa3(i)*cr4\n end do\n end do\n end select\n\n end subroutine complex_forward_pass_4\n\n pure subroutine complex_forward_pass_5(ido, l1, cc, ch, wa1, wa2, wa3, wa4)\n\n ! Dummy arguments\n\n integer(ip), intent(in) :: ido\n integer(ip), intent(in) :: l1\n real(wp), intent(in) :: cc(ido, 5, l1)\n real(wp), intent(out) :: ch(ido, l1, 5)\n real(wp), intent(in) :: wa1(*)\n real(wp), intent(in) :: wa2(*)\n real(wp), intent(in) :: wa3(*)\n real(wp), intent(in) :: wa4(*)\n\n ! Local variables\n\n integer(ip) :: k, i\n real(wp) :: ti5, ti2, ti4, ti3, tr5, tr2, tr4\n real(wp) :: tr3, cr2, ci2, cr3, ci3, cr5, ci5, cr4, ci4, dr3, dr4, di3\n real(wp) :: di4, dr5, dr2, di5, di2\n real(wp), parameter :: tr11 = (SQRT_5 - ONE)/4 ! 0.309016994374947\n real(wp), parameter :: ti11 = -sqrt((FIVE + SQRT_5)/2)/2 ! -.951056516295154\n real(wp), parameter :: tr12 = (-ONE - SQRT_5)/4 ! -.809016994374947\n real(wp), parameter :: ti12 = -sqrt(FIVE/(TWO * (FIVE + SQRT_5))) ! -0.587785252292473\n\n\n select case(ido)\n case (2)\n do k = 1, l1\n ti5 = cc(2, 2, k) - cc(2, 5, k)\n ti2 = cc(2, 2, k) + cc(2, 5, k)\n ti4 = cc(2, 3, k) - cc(2, 4, k)\n ti3 = cc(2, 3, k) + cc(2, 4, k)\n tr5 = cc(1, 2, k) - cc(1, 5, k)\n tr2 = cc(1, 2, k) + cc(1, 5, k)\n tr4 = cc(1, 3, k) - cc(1, 4, k)\n tr3 = cc(1, 3, k) + cc(1, 4, k)\n ch(1, k, 1) = cc(1, 1, k) + tr2 + tr3\n ch(2, k, 1) = cc(2, 1, k) + ti2 + ti3\n cr2 = cc(1, 1, k) + tr11*tr2 + tr12*tr3\n ci2 = cc(2, 1, k) + tr11*ti2 + tr12*ti3\n cr3 = cc(1, 1, k) + tr12*tr2 + tr11*tr3\n ci3 = cc(2, 1, k) + tr12*ti2 + tr11*ti3\n cr5 = ti11*tr5 + ti12*tr4\n ci5 = ti11*ti5 + ti12*ti4\n cr4 = ti12*tr5 - ti11*tr4\n ci4 = ti12*ti5 - ti11*ti4\n ch(1, k, 2) = cr2 - ci5\n ch(1, k, 5) = cr2 + ci5\n ch(2, k, 2) = ci2 + cr5\n ch(2, k, 3) = ci3 + cr4\n ch(1, k, 3) = cr3 - ci4\n ch(1, k, 4) = cr3 + ci4\n ch(2, k, 4) = ci3 - cr4\n ch(2, k, 5) = ci2 - cr5\n end do\n case default\n do k = 1, l1\n do i = 2, ido, 2\n ti5 = cc(i, 2, k) - cc(i, 5, k)\n ti2 = cc(i, 2, k) + cc(i, 5, k)\n ti4 = cc(i, 3, k) - cc(i, 4, k)\n ti3 = cc(i, 3, k) + cc(i, 4, k)\n tr5 = cc(i-1, 2, k) - cc(i-1, 5, k)\n tr2 = cc(i-1, 2, k) + cc(i-1, 5, k)\n tr4 = cc(i-1, 3, k) - cc(i-1, 4, k)\n tr3 = cc(i-1, 3, k) + cc(i-1, 4, k)\n ch(i-1, k, 1) = cc(i-1, 1, k) + tr2 + tr3\n ch(i, k, 1) = cc(i, 1, k) + ti2 + ti3\n cr2 = cc(i-1, 1, k) + tr11*tr2 + tr12*tr3\n ci2 = cc(i, 1, k) + tr11*ti2 + tr12*ti3\n cr3 = cc(i-1, 1, k) + tr12*tr2 + tr11*tr3\n ci3 = cc(i, 1, k) + tr12*ti2 + tr11*ti3\n cr5 = ti11*tr5 + ti12*tr4\n ci5 = ti11*ti5 + ti12*ti4\n cr4 = ti12*tr5 - ti11*tr4\n ci4 = ti12*ti5 - ti11*ti4\n dr3 = cr3 - ci4\n dr4 = cr3 + ci4\n di3 = ci3 + cr4\n di4 = ci3 - cr4\n dr5 = cr2 + ci5\n dr2 = cr2 - ci5\n di5 = ci2 - cr5\n di2 = ci2 + cr5\n ch(i-1, k, 2) = wa1(i-1)*dr2 + wa1(i)*di2\n ch(i, k, 2) = wa1(i-1)*di2 - wa1(i)*dr2\n ch(i-1, k, 3) = wa2(i-1)*dr3 + wa2(i)*di3\n ch(i, k, 3) = wa2(i-1)*di3 - wa2(i)*dr3\n ch(i-1, k, 4) = wa3(i-1)*dr4 + wa3(i)*di4\n ch(i, k, 4) = wa3(i-1)*di4 - wa3(i)*dr4\n ch(i-1, k, 5) = wa4(i-1)*dr5 + wa4(i)*di5\n ch(i, k, 5) = wa4(i-1)*di5 - wa4(i)*dr5\n end do\n end do\n end select\n\n end subroutine complex_forward_pass_5\n\n subroutine complex_forward_pass_n(nac, ido, iip, l1, idl1, cc, c1, c2, ch, ch2, wa)\n\n ! Dummy arguments\n\n integer(ip), intent(out) :: nac\n integer(ip), intent(in) :: ido\n integer(ip), intent(in) :: iip\n integer(ip), intent(in) :: l1\n integer(ip), intent(in) :: idl1\n real(wp), intent(inout) :: cc(ido, iip, l1)\n real(wp), intent(inout) :: c1(ido, l1, iip)\n real(wp), intent(inout) :: c2(idl1, iip)\n real(wp), intent(inout) :: ch(ido, l1, iip)\n real(wp), intent(inout) :: ch2(idl1, iip)\n real(wp), intent(in) :: wa(*)\n\n ! Local variables\n\n integer(ip) :: idot, nt, iipp2, iipph, idp, j, jc\n integer(ip) :: k, i, idl, inc, l, lc\n integer(ip) :: idlj, idij, idj\n real(wp) :: war, wai\n\n\n idot = ido/2\n nt = iip*idl1\n iipp2 = iip + 2\n iipph = (iip + 1)/2\n idp = iip*ido\n\n if (l1 <= ido) then\n do j = 2, iipph\n jc = iipp2 - j\n ch(:, :, j) = cc(:, j, :) + cc(:, jc, :)\n ch(:, :, jc) = cc(:, j, :) - cc(:, jc, :)\n end do\n ch(:, :, 1) = cc(:, 1, :)\n else\n do j = 2, iipph\n jc = iipp2 - j\n ch(:, :, j) = cc(:, j, :) + cc(:, jc, :)\n ch(:, :, jc) = cc(:, j, :) - cc(:, jc, :)\n end do\n ch(:, :, 1) = cc(:, 1, :)\n end if\n\n idl = 2 - ido\n inc = 0\n\n do l = 2, iipph\n lc = iipp2 - l\n idl = idl + ido\n c2(:, l) = ch2(:, 1) + wa(idl-1)*ch2(:, 2)\n c2(:, lc) = -wa(idl)*ch2(:, iip)\n idlj = idl\n inc = inc + ido\n do j = 3, iipph\n jc = iipp2 - j\n idlj = idlj + inc\n if (idlj > idp) then\n idlj = idlj - idp\n end if\n war = wa(idlj-1)\n wai = wa(idlj)\n c2(:, l) = c2(:, l) + war*ch2(:, j)\n c2(:, lc) = c2(:, lc) - wai*ch2(:, jc)\n end do\n end do\n\n do j = 2, iipph\n ch2(:, 1) = ch2(:, 1) + ch2(:, j)\n end do\n\n do j = 2, iipph\n jc = iipp2 - j\n ch2(:idl1-1:2, j) = c2(:idl1-1:2, j) - c2(2:idl1:2, jc)\n ch2(:idl1-1:2, jc) = c2(:idl1-1:2, j) + c2(2:idl1:2, jc)\n ch2(2:idl1:2, j) = c2(2:idl1:2, j) + c2(:idl1-1:2, jc)\n ch2(2:idl1:2, jc) = c2(2:idl1:2, j) - c2(:idl1-1:2, jc)\n end do\n\n nac = 1\n\n if (ido /= 2) then\n\n nac = 0\n c2(:, 1) = ch2(:, 1)\n c1(1, :, 2:iip) = ch(1, :, 2:iip)\n c1(2, :, 2:iip) = ch(2, :, 2:iip)\n\n if (idot <= l1) then\n idij = 0\n do j = 2, iip\n idij = idij + 2\n do i = 4, ido, 2\n idij = idij + 2\n c1(i-1, :, j) = wa(idij-1)*ch(i-1, :, j) + wa(idij)*ch(i, :, j)\n c1(i, :, j) = wa(idij-1)*ch(i, :, j) - wa(idij)*ch(i-1, :, j)\n end do\n end do\n else\n idj = 2 - ido\n do j = 2, iip\n idj = idj + ido\n do k = 1, l1\n idij = idj\n c1(3:ido-1:2, k, j) = wa(idij+1:ido-3+idij:2)*ch(3:ido-1:2, k, j &\n ) + wa(idij+2:ido-2+idij:2)*ch(4:ido:2, k, j)\n c1(4:ido:2, k, j) = wa(idij+1:ido-3+idij:2)*ch(4:ido:2, k, j) - &\n wa(idij+2:ido-2+idij:2)*ch(3:ido-1:2, k, j)\n end do\n end do\n end if\n end if\n\n end subroutine complex_forward_pass_n\n\n subroutine rffti(n, wsave)\n\n ! Dummy arguments\n\n integer(ip) :: n\n real(wp) :: wsave(*)\n\n\n if (n /= 1) then\n call real_initialization_lower_utility_routine(n, wsave(n+1), wsave(2*n+1))\n end if\n\n end subroutine rffti\n\n subroutine real_initialization_lower_utility_routine(n, wa, ifac)\n\n ! Dummy arguments\n\n integer(ip), intent(in) :: n\n real(wp), intent(inout) :: ifac(*)\n real(wp), intent(out) :: wa(*)\n\n ! Local variables\n\n integer, parameter :: NTRYH(*) = [4, 2, 3, 5]\n integer(ip) :: nl, nf, j, ntry, nq, nr, i, is, nfm1, l1, k1, iip\n integer(ip) :: ld, l2, ido, iipm, ii\n real(wp) :: argh, argld, fi, arg\n\n\n ntry = 0\n nl = n\n nf = 0\n j = 0\n\n factorization_loop: do\n\n j = j + 1\n\n if (j <= 4) then\n ntry = NTRYH(j)\n else\n ntry = ntry + 2\n end if\n\n inner_loop: do\n\n nq = nl/ntry\n nr = nl - ntry*nq\n\n if (nr /= 0) cycle factorization_loop\n\n nf = nf + 1\n ifac(nf+2) = ntry\n nl = nq\n\n if (ntry == 2) then\n if (nf /= 1) then\n ifac(nf+2:4:(-1)) = ifac(nf+1:3:(-1))\n ifac(3) = 2\n end if\n end if\n\n if (nl /= 1) cycle inner_loop\n\n exit inner_loop\n end do inner_loop\n exit factorization_loop\n end do factorization_loop\n\n ifac(1) = n\n ifac(2) = nf\n argh = TWO_PI/n\n is = 0\n nfm1 = nf - 1\n l1 = 1\n\n if (nfm1 /= 0) then\n do k1 = 1, nfm1\n iip = int(ifac(k1+2), kind=ip)\n ld = 0\n l2 = l1*iip\n ido = n/l2\n iipm = iip - 1\n do j = 1, iipm\n ld = ld + l1\n i = is\n argld = real(ld, kind=wp)*argh\n fi = ZERO\n do ii = 3, ido, 2\n i = i + 2\n fi = fi + ONE\n arg = fi*argld\n wa(i-1) = cos(arg)\n wa(i) = sin(arg)\n end do\n is = is + ido\n end do\n l1 = l2\n end do\n end if\n\n end subroutine real_initialization_lower_utility_routine\n\n subroutine rfftb(n, r, wsave)\n\n ! Dummy arguments\n\n integer(ip) :: n\n real(wp) :: r(*)\n real(wp) :: wsave(*)\n\n\n if (n /= 1) then\n call real_backward_lower_utility_routine(n, r, wsave, wsave(n+1), wsave(2*n+1))\n end if\n\n end subroutine rfftb\n\n subroutine real_backward_lower_utility_routine(n, c, ch, wa, ifac)\n\n ! Dummy arguments\n\n integer(ip), intent(in) :: n\n real(wp), intent(in) :: ifac(*)\n real(wp) :: c(*)\n real(wp) :: ch(*)\n real(wp) :: wa(*)\n\n ! Local variables\n\n integer(ip) :: nf, na, l1, iw, k1, iip\n integer(ip) :: l2, ido, idl1, ix2, ix3, ix4\n\n\n nf = int(ifac(2), kind=ip)\n na = 0\n l1 = 1\n iw = 1\n\n do k1 = 1, nf\n iip = int(ifac(k1+2), kind=ip)\n l2 = iip*l1\n ido = n/l2\n idl1 = ido*l1\n\n select case (iip)\n case (4)\n ix2 = iw + ido\n ix3 = ix2 + ido\n if (na == 0) then\n call real_backward_pass_4(ido, l1, c, ch, wa(iw), wa(ix2), wa(ix3))\n else\n call real_backward_pass_4(ido, l1, ch, c, wa(iw), wa(ix2), wa(ix3))\n end if\n na = 1 - na\n case (2)\n if (na == 0) then\n call real_backward_pass_2(ido, l1, c, ch, wa(iw))\n else\n call real_backward_pass_2(ido, l1, ch, c, wa(iw))\n end if\n na = 1 - na\n case (3)\n ix2 = iw + ido\n if (na == 0) then\n call real_backward_pass_3(ido, l1, c, ch, wa(iw), wa(ix2))\n else\n call real_backward_pass_3(ido, l1, ch, c, wa(iw), wa(ix2))\n end if\n na = 1 - na\n case (5)\n ix2 = iw + ido\n ix3 = ix2 + ido\n ix4 = ix3 + ido\n if (na == 0) then\n call real_backward_pass_5(ido, l1, c, ch, wa(iw), wa(ix2), wa( &\n ix3), wa(ix4))\n else\n call real_backward_pass_5(ido, l1, ch, c, wa(iw), wa(ix2), wa( &\n ix3), wa(ix4))\n end if\n na = 1 - na\n case default\n if (na == 0) then\n call real_backward_pass_n(ido, iip, l1, idl1, c, c, c, ch, ch, wa(iw))\n else\n call real_backward_pass_n(ido, iip, l1, idl1, ch, ch, ch, c, c, wa(iw))\n end if\n\n if (ido == 1) na = 1 - na\n\n end select\n l1 = l2\n iw = iw + (iip - 1)*ido\n end do\n\n if (na /= 0) c(:n) = ch(:n)\n\n end subroutine real_backward_lower_utility_routine\n\n pure subroutine real_backward_pass_2(ido, l1, cc, ch, wa1)\n\n ! Dummy arguments\n\n integer(ip), intent(in) :: ido\n integer(ip), intent(in) :: l1\n real(wp), intent(in) :: cc(ido, 2, l1)\n real(wp), intent(out) :: ch(ido, l1, 2)\n real(wp), intent(in) :: wa1(*)\n\n ! Local variables\n\n integer(ip) :: k, idp2, i, ic\n real(wp) :: tr2, ti2\n\n\n ch(1, :, 1) = cc(1, 1, :) + cc(ido, 2, :)\n ch(1, :, 2) = cc(1, 1, :) - cc(ido, 2, :)\n\n if (ido >= 2) then\n if (ido /= 2) then\n idp2 = ido + 2\n do k = 1, l1\n do i = 3, ido, 2\n ic = idp2 - i\n ch(i-1, k, 1) = cc(i-1, 1, k) + cc(ic-1, 2, k)\n tr2 = cc(i-1, 1, k) - cc(ic-1, 2, k)\n ch(i, k, 1) = cc(i, 1, k) - cc(ic, 2, k)\n ti2 = cc(i, 1, k) + cc(ic, 2, k)\n ch(i-1, k, 2) = wa1(i-2)*tr2 - wa1(i-1)*ti2\n ch(i, k, 2) = wa1(i-2)*ti2 + wa1(i-1)*tr2\n end do\n end do\n if (mod(ido, 2) == 1) then\n return\n end if\n end if\n ch(ido, :, 1) = cc(ido, 1, :) + cc(ido, 1, :)\n ch(ido, :, 2) = -(cc(1, 2, :)+cc(1, 2, :))\n end if\n\n end subroutine real_backward_pass_2\n\n pure subroutine real_backward_pass_3(ido, l1, cc, ch, wa1, wa2)\n\n ! Dummy arguments\n\n integer(ip), intent(in) :: ido\n integer(ip), intent(in) :: l1\n real(wp), intent(in) :: cc(ido, 3, l1)\n real(wp), intent(out) :: ch(ido, l1, 3)\n real(wp), intent(in) :: wa1(*)\n real(wp), intent(in) :: wa2(*)\n\n ! Local variables\n\n integer(ip) :: k, idp2, i, ic\n real(wp), parameter :: taur = -HALF\n real(wp), parameter :: taui = SQRT_3/TWO ! 0.866025403784439\n real(wp) :: tr2, cr2, ci3, ti2, ci2, cr3, dr2, dr3, di2, di3\n\n\n do k = 1, l1\n tr2 = cc(ido, 2, k) + cc(ido, 2, k)\n cr2 = cc(1, 1, k) + taur*tr2\n ch(1, k, 1) = cc(1, 1, k) + tr2\n ci3 = taui*(cc(1, 3, k)+cc(1, 3, k))\n ch(1, k, 2) = cr2 - ci3\n ch(1, k, 3) = cr2 + ci3\n end do\n\n if(ido /= 1) then\n idp2 = ido + 2\n do k = 1, l1\n do i = 3, ido, 2\n ic = idp2 - i\n tr2 = cc(i-1, 3, k) + cc(ic-1, 2, k)\n cr2 = cc(i-1, 1, k) + taur*tr2\n ch(i-1, k, 1) = cc(i-1, 1, k) + tr2\n ti2 = cc(i, 3, k) - cc(ic, 2, k)\n ci2 = cc(i, 1, k) + taur*ti2\n ch(i, k, 1) = cc(i, 1, k) + ti2\n cr3 = taui*(cc(i-1, 3, k)-cc(ic-1, 2, k))\n ci3 = taui*(cc(i, 3, k)+cc(ic, 2, k))\n dr2 = cr2 - ci3\n dr3 = cr2 + ci3\n di2 = ci2 + cr3\n di3 = ci2 - cr3\n ch(i-1, k, 2) = wa1(i-2)*dr2 - wa1(i-1)*di2\n ch(i, k, 2) = wa1(i-2)*di2 + wa1(i-1)*dr2\n ch(i-1, k, 3) = wa2(i-2)*dr3 - wa2(i-1)*di3\n ch(i, k, 3) = wa2(i-2)*di3 + wa2(i-1)*dr3\n end do\n end do\n end if\n\n end subroutine real_backward_pass_3\n\n pure subroutine real_backward_pass_4(ido, l1, cc, ch, wa1, wa2, wa3)\n\n ! Dummy arguments\n\n integer(ip), intent(in) :: ido\n integer(ip), intent(in) :: l1\n real(wp), intent(in) :: cc(ido, 4, l1)\n real(wp), intent(out) :: ch(ido, l1, 4)\n real(wp), intent(in) :: wa1(*)\n real(wp), intent(in) :: wa2(*)\n real(wp), intent(in) :: wa3(*)\n\n ! Local variables\n\n integer(ip) :: k, idp2, i, ic\n real(wp), parameter :: SQRT_2 = sqrt(TWO) ! 1.414213562373095\n real(wp) :: tr1, tr2, tr3, tr4, ti1, ti2, ti3, ti4, cr3, ci3\n real(wp) :: cr2, cr4, ci2, ci4\n\n\n do k = 1, l1\n tr1 = cc(1, 1, k) - cc(ido, 4, k)\n tr2 = cc(1, 1, k) + cc(ido, 4, k)\n tr3 = cc(ido, 2, k) + cc(ido, 2, k)\n tr4 = cc(1, 3, k) + cc(1, 3, k)\n ch(1, k, 1) = tr2 + tr3\n ch(1, k, 2) = tr1 - tr4\n ch(1, k, 3) = tr2 - tr3\n ch(1, k, 4) = tr1 + tr4\n end do\n\n if (2 <= ido) then\n if (ido /= 2) then\n idp2 = ido + 2\n do k = 1, l1\n do i = 3, ido, 2\n ic = idp2 - i\n ti1 = cc(i, 1, k) + cc(ic, 4, k)\n ti2 = cc(i, 1, k) - cc(ic, 4, k)\n ti3 = cc(i, 3, k) - cc(ic, 2, k)\n tr4 = cc(i, 3, k) + cc(ic, 2, k)\n tr1 = cc(i-1, 1, k) - cc(ic-1, 4, k)\n tr2 = cc(i-1, 1, k) + cc(ic-1, 4, k)\n ti4 = cc(i-1, 3, k) - cc(ic-1, 2, k)\n tr3 = cc(i-1, 3, k) + cc(ic-1, 2, k)\n ch(i-1, k, 1) = tr2 + tr3\n cr3 = tr2 - tr3\n ch(i, k, 1) = ti2 + ti3\n ci3 = ti2 - ti3\n cr2 = tr1 - tr4\n cr4 = tr1 + tr4\n ci2 = ti1 + ti4\n ci4 = ti1 - ti4\n ch(i-1, k, 2) = wa1(i-2)*cr2 - wa1(i-1)*ci2\n ch(i, k, 2) = wa1(i-2)*ci2 + wa1(i-1)*cr2\n ch(i-1, k, 3) = wa2(i-2)*cr3 - wa2(i-1)*ci3\n ch(i, k, 3) = wa2(i-2)*ci3 + wa2(i-1)*cr3\n ch(i-1, k, 4) = wa3(i-2)*cr4 - wa3(i-1)*ci4\n ch(i, k, 4) = wa3(i-2)*ci4 + wa3(i-1)*cr4\n end do\n end do\n if (mod(ido, 2) == 1) then\n return\n end if\n end if\n do k = 1, l1\n ti1 = cc(1, 2, k) + cc(1, 4, k)\n ti2 = cc(1, 4, k) - cc(1, 2, k)\n tr1 = cc(ido, 1, k) - cc(ido, 3, k)\n tr2 = cc(ido, 1, k) + cc(ido, 3, k)\n ch(ido, k, 1) = tr2 + tr2\n ch(ido, k, 2) = SQRT_2*(tr1 - ti1)\n ch(ido, k, 3) = ti2 + ti2\n ch(ido, k, 4) = -SQRT_2*(tr1 + ti1)\n end do\n end if\n\n end subroutine real_backward_pass_4\n\n pure subroutine real_backward_pass_5(ido, l1, cc, ch, wa1, wa2, wa3, wa4)\n\n ! Dummy arguments\n\n integer(ip), intent(in) :: ido\n integer(ip), intent(in) :: l1\n real(wp), intent(in) :: cc(ido, 5, l1)\n real(wp), intent(out) :: ch(ido, l1, 5)\n real(wp), intent(in) :: wa1(*)\n real(wp), intent(in) :: wa2(*)\n real(wp), intent(in) :: wa3(*)\n real(wp), intent(in) :: wa4(*)\n\n ! Local variables\n\n integer(ip) :: k, idp2, i, ic\n real(wp) :: ti5, ti4, tr2, tr3, cr2, cr3, ci5\n real(wp) :: ci4, ti2, ti3, tr5, tr4, ci2, ci3, cr5, cr4, dr3, dr4, di3\n real(wp) :: di4, dr5, dr2, di5, di2\n real(wp), parameter :: tr11 = (SQRT_5 - ONE)/4 ! 0.309016994374947\n real(wp), parameter :: ti11 = sqrt((FIVE + SQRT_5)/2)/2 ! 0.951056516295154\n real(wp), parameter :: tr12 = (-ONE - SQRT_5)/4 ! -.809016994374947\n real(wp), parameter :: ti12 = sqrt(FIVE/(TWO * (FIVE + SQRT_5))) ! 0.587785252292473\n\n\n\n do k = 1, l1\n ti5 = cc(1, 3, k) + cc(1, 3, k)\n ti4 = cc(1, 5, k) + cc(1, 5, k)\n tr2 = cc(ido, 2, k) + cc(ido, 2, k)\n tr3 = cc(ido, 4, k) + cc(ido, 4, k)\n ch(1, k, 1) = cc(1, 1, k) + tr2 + tr3\n cr2 = cc(1, 1, k) + tr11*tr2 + tr12*tr3\n cr3 = cc(1, 1, k) + tr12*tr2 + tr11*tr3\n ci5 = ti11*ti5 + ti12*ti4\n ci4 = ti12*ti5 - ti11*ti4\n ch(1, k, 2) = cr2 - ci5\n ch(1, k, 3) = cr3 - ci4\n ch(1, k, 4) = cr3 + ci4\n ch(1, k, 5) = cr2 + ci5\n end do\n\n if(ido /= 1) then\n idp2 = ido + 2\n do k = 1, l1\n do i = 3, ido, 2\n ic = idp2 - i\n ti5 = cc(i, 3, k) + cc(ic, 2, k)\n ti2 = cc(i, 3, k) - cc(ic, 2, k)\n ti4 = cc(i, 5, k) + cc(ic, 4, k)\n ti3 = cc(i, 5, k) - cc(ic, 4, k)\n tr5 = cc(i-1, 3, k) - cc(ic-1, 2, k)\n tr2 = cc(i-1, 3, k) + cc(ic-1, 2, k)\n tr4 = cc(i-1, 5, k) - cc(ic-1, 4, k)\n tr3 = cc(i-1, 5, k) + cc(ic-1, 4, k)\n ch(i-1, k, 1) = cc(i-1, 1, k) + tr2 + tr3\n ch(i, k, 1) = cc(i, 1, k) + ti2 + ti3\n cr2 = cc(i-1, 1, k) + tr11*tr2 + tr12*tr3\n ci2 = cc(i, 1, k) + tr11*ti2 + tr12*ti3\n cr3 = cc(i-1, 1, k) + tr12*tr2 + tr11*tr3\n ci3 = cc(i, 1, k) + tr12*ti2 + tr11*ti3\n cr5 = ti11*tr5 + ti12*tr4\n ci5 = ti11*ti5 + ti12*ti4\n cr4 = ti12*tr5 - ti11*tr4\n ci4 = ti12*ti5 - ti11*ti4\n dr3 = cr3 - ci4\n dr4 = cr3 + ci4\n di3 = ci3 + cr4\n di4 = ci3 - cr4\n dr5 = cr2 + ci5\n dr2 = cr2 - ci5\n di5 = ci2 - cr5\n di2 = ci2 + cr5\n ch(i-1, k, 2) = wa1(i-2)*dr2 - wa1(i-1)*di2\n ch(i, k, 2) = wa1(i-2)*di2 + wa1(i-1)*dr2\n ch(i-1, k, 3) = wa2(i-2)*dr3 - wa2(i-1)*di3\n ch(i, k, 3) = wa2(i-2)*di3 + wa2(i-1)*dr3\n ch(i-1, k, 4) = wa3(i-2)*dr4 - wa3(i-1)*di4\n ch(i, k, 4) = wa3(i-2)*di4 + wa3(i-1)*dr4\n ch(i-1, k, 5) = wa4(i-2)*dr5 - wa4(i-1)*di5\n ch(i, k, 5) = wa4(i-2)*di5 + wa4(i-1)*dr5\n end do\n end do\n end if\n\n end subroutine real_backward_pass_5\n\n subroutine real_backward_pass_n(ido, iip, l1, idl1, cc, c1, c2, ch, ch2, wa)\n\n ! Dummy arguments\n\n integer(ip), intent(in) :: ido\n integer(ip), intent(in) :: iip\n integer(ip), intent(in) :: l1\n integer(ip), intent(in) :: idl1\n real(wp), intent(in) :: cc(ido, iip, l1)\n real(wp), intent(inout) :: c1(ido, l1, iip)\n real(wp), intent(inout) :: c2(idl1, iip)\n real(wp), intent(inout) :: ch(ido, l1, iip)\n real(wp), intent(inout) :: ch2(idl1, iip)\n real(wp), intent(in) :: wa(*)\n\n ! Local variables\n\n integer:: idp2, nbd, iipp2, iipph, k, i, j, jc, j2, l, lc, is, idij\n real(wp) :: arg, dcp, dsp, ar1, ai1, ar1h, dc2, ds2, ar2, ai2, ar2h\n\n\n arg = TWO_PI/iip\n dcp = cos(arg)\n dsp = sin(arg)\n idp2 = ido + 2\n nbd =(ido - 1)/2\n iipp2 = iip + 2\n iipph = (iip + 1)/2\n\n ch(:, :, 1) = cc(:, 1, :)\n\n do j = 2, iipph\n jc = iipp2 - j\n j2 = j + j\n ch(1, :, j) = cc(ido, j2-2, :) + cc(ido, j2-2, :)\n ch(1, :, jc) = cc(1, j2-1, :) + cc(1, j2-1, :)\n end do\n\n if(ido /= 1) then\n if (l1 <= nbd) then\n do j = 2, iipph\n jc = iipp2 - j\n ch(2:ido-1:2, :, j) = cc(2:ido-1:2, 2*j-1, :) + cc(idp2-4: &\n idp2-1-ido:(-2), 2*j-2, :)\n ch(2:ido-1:2, :, jc) = cc(2:ido-1:2, 2*j-1, :) - cc(idp2-4: &\n idp2-1-ido:(-2), 2*j-2, :)\n ch(3:ido:2, :, j) = cc(3:ido:2, 2*j-1, :) - cc(idp2-3:idp2- &\n ido:(-2), 2*j-2, :)\n ch(3:ido:2, :, jc) = cc(3:ido:2, 2*j-1, :) + cc(idp2-3:idp2- &\n ido:(-2), 2*j-2, :)\n end do\n else\n do j = 2, iipph\n jc = iipp2 - j\n ch(2:ido-1:2, :, j) = cc(2:ido-1:2, 2*j-1, :) + cc(idp2-4: &\n idp2-1-ido:(-2), 2*j-2, :)\n ch(2:ido-1:2, :, jc) = cc(2:ido-1:2, 2*j-1, :) - cc(idp2-4: &\n idp2-1-ido:(-2), 2*j-2, :)\n ch(3:ido:2, :, j) = cc(3:ido:2, 2*j-1, :) - cc(idp2-3:idp2- &\n ido:(-2), 2*j-2, :)\n ch(3:ido:2, :, jc) = cc(3:ido:2, 2*j-1, :) + cc(idp2-3:idp2- &\n ido:(-2), 2*j-2, :)\n end do\n end if\n end if\n\n ar1 = ONE\n ai1 = ZERO\n\n do l = 2, iipph\n lc = iipp2 - l\n ar1h = dcp*ar1 - dsp*ai1\n ai1 = dcp*ai1 + dsp*ar1\n ar1 = ar1h\n c2(:, l) = ch2(:, 1) + ar1*ch2(:, 2)\n c2(:, lc) = ai1*ch2(:, iip)\n dc2 = ar1\n ds2 = ai1\n ar2 = ar1\n ai2 = ai1\n do j = 3, iipph\n jc = iipp2 - j\n ar2h = dc2*ar2 - ds2*ai2\n ai2 = dc2*ai2 + ds2*ar2\n ar2 = ar2h\n c2(:, l) = c2(:, l) + ar2*ch2(:, j)\n c2(:, lc) = c2(:, lc) + ai2*ch2(:, jc)\n end do\n end do\n\n do j = 2, iipph\n ch2(:, 1) = ch2(:, 1) + ch2(:, j)\n end do\n\n do j = 2, iipph\n jc = iipp2 - j\n ch(1, :, j) = c1(1, :, j) - c1(1, :, jc)\n ch(1, :, jc) = c1(1, :, j) + c1(1, :, jc)\n end do\n\n if(ido /= 1) then\n if (l1 <= nbd) then\n do j = 2, iipph\n jc = iipp2 - j\n ch(2:ido-1:2, :, j) = c1(2:ido-1:2, :, j) - c1(3:ido:2, :, jc)\n ch(2:ido-1:2, :, jc) = c1(2:ido-1:2, :, j) + c1(3:ido:2, :, jc)\n ch(3:ido:2, :, j) = c1(3:ido:2, :, j) + c1(2:ido-1:2, :, jc)\n ch(3:ido:2, :, jc) = c1(3:ido:2, :, j) - c1(2:ido-1:2, :, jc)\n end do\n else\n do j = 2, iipph\n jc = iipp2 - j\n ch(2:ido-1:2, :, j) = c1(2:ido-1:2, :, j) - c1(3:ido:2, :, jc)\n ch(2:ido-1:2, :, jc) = c1(2:ido-1:2, :, j) + c1(3:ido:2, :, jc)\n ch(3:ido:2, :, j) = c1(3:ido:2, :, j) + c1(2:ido-1:2, :, jc)\n ch(3:ido:2, :, jc) = c1(3:ido:2, :, j) - c1(2:ido-1:2, :, jc)\n end do\n end if\n end if\n\n if(ido /= 1) then\n c2(:, 1) = ch2(:, 1)\n c1(1, :, 2:iip) = ch(1, :, 2:iip)\n if (nbd <= l1) then\n is = -ido\n do j = 2, iip\n is = is + ido\n idij = is\n do i = 3, ido, 2\n idij = idij + 2\n c1(i-1, :, j) = wa(idij-1)*ch(i-1, :, j) - wa(idij)*ch(i, :, j)\n c1(i, :, j) = wa(idij-1)*ch(i, :, j) + wa(idij)*ch(i-1, :, j)\n end do\n end do\n else\n is = -ido\n do j = 2, iip\n is = is + ido\n do k = 1, l1\n idij = is\n c1(2:ido-1:2, k, j) = wa(idij+1:ido-2+idij:2)*ch(2:ido-1:2, &\n k, j) - wa(idij+2:ido-1+idij:2)*ch(3:ido:2, k, j)\n c1(3:ido:2, k, j) = wa(idij+1:ido-2+idij:2)*ch(3:ido:2, k, j) &\n + wa(idij+2:ido-1+idij:2)*ch(2:ido-1:2, k, j)\n end do\n end do\n end if\n end if\n\n end subroutine real_backward_pass_n\n\n subroutine rfftf(n, r, wsave)\n\n ! Dummy arguments\n\n integer(ip) :: n\n real(wp) :: r(*)\n real(wp) :: wsave(*)\n\n\n if (n /= 1) then\n call real_forward_lower_utility_routine(n, r, wsave, wsave(n+1), wsave(2*n+1))\n end if\n\n end subroutine rfftf\n\n subroutine real_forward_lower_utility_routine(n, c, ch, wa, ifac)\n\n ! Dummy arguments\n\n integer(ip), intent(in) :: n\n real(wp), intent(in) :: ifac(*)\n real(wp) :: c(*)\n real(wp) :: ch(*)\n real(wp) :: wa(*)\n\n ! Local variables\n\n integer(ip) :: nf, na, l2, iw, k1, kh\n integer(ip) :: iip, l1, ido, idl1, ix2, ix3, ix4\n\n\n nf = int(ifac(2), kind=ip)\n na = 1\n l2 = n\n iw = n\n\n do k1 = 1, nf\n kh = nf - k1\n iip = int(ifac(kh+3), kind=ip)\n l1 = l2/iip\n ido = n/l2\n idl1 = ido*l1\n iw = iw - (iip - 1)*ido\n na = 1 - na\n\n select case (iip)\n case (2)\n if (na == 0) then\n call real_forward_pass_2(ido, l1, c, ch, wa(iw))\n else\n call real_forward_pass_2(ido, l1, ch, c, wa(iw))\n end if\n case (3)\n ix2 = iw + ido\n if (na == 0) then\n call real_forward_pass_3(ido, l1, c, ch, wa(iw), wa(ix2))\n else\n call real_forward_pass_3(ido, l1, ch, c, wa(iw), wa(ix2))\n end if\n case (4)\n ix2 = iw + ido\n ix3 = ix2 + ido\n if (na == 0) then\n call real_forward_pass_4(ido, l1, c, ch, wa(iw), wa(ix2), wa(ix3))\n else\n call real_forward_pass_4(ido, l1, ch, c, wa(iw), wa(ix2), wa(ix3))\n end if\n case (5)\n ix2 = iw + ido\n ix3 = ix2 + ido\n ix4 = ix3 + ido\n if (na == 0) then\n call real_forward_pass_5(ido, l1, c, ch, wa(iw), wa(ix2), wa(ix3), wa(ix4))\n else\n call real_forward_pass_5(ido, l1, ch, c, wa(iw), wa(ix2), wa(ix3), wa(ix4))\n end if\n case default\n if(ido == 1) then\n na = 1 - na\n end if\n if (na == 0) then\n call real_forward_pass_n(ido, iip, l1, idl1, c, c, c, ch, ch, wa(iw))\n na = 1\n else\n call real_forward_pass_n(ido, iip, l1, idl1, ch, ch, ch, c, c, wa(iw))\n na = 0\n end if\n end select\n l2 = l1\n end do\n\n if (na /= 1) c(:n) = ch(:n)\n\n end subroutine real_forward_lower_utility_routine\n\n pure subroutine real_forward_pass_2(ido, l1, cc, ch, wa1)\n\n ! Dummy arguments\n\n integer(ip), intent(in) :: ido\n integer(ip), intent(in) :: l1\n real(wp), intent(in) :: cc(ido, l1, 2)\n real(wp), intent(out) :: ch(ido, 2, l1)\n real(wp), intent(in) :: wa1(*)\n\n ! Local variables\n\n integer(ip) :: k, idp2, i, ic\n real(wp) :: tr2, ti2\n\n\n ch(1, 1, :) = cc(1, :, 1) + cc(1, :, 2)\n ch(ido, 2, :) = cc(1, :, 1) - cc(1, :, 2)\n\n if (ido >= 2) then\n if (ido /= 2) then\n idp2 = ido + 2\n do k = 1, l1\n do i = 3, ido, 2\n ic = idp2 - i\n tr2 = wa1(i-2)*cc(i-1, k, 2) + wa1(i-1)*cc(i, k, 2)\n ti2 = wa1(i-2)*cc(i, k, 2) - wa1(i-1)*cc(i-1, k, 2)\n ch(i, 1, k) = cc(i, k, 1) + ti2\n ch(ic, 2, k) = ti2 - cc(i, k, 1)\n ch(i-1, 1, k) = cc(i-1, k, 1) + tr2\n ch(ic-1, 2, k) = cc(i-1, k, 1) - tr2\n end do\n end do\n if (mod(ido, 2) == 1) then\n return\n end if\n end if\n ch(1, 2, :) = -cc(ido, :, 2)\n ch(ido, 1, :) = cc(ido, :, 1)\n end if\n\n end subroutine real_forward_pass_2\n\n pure subroutine real_forward_pass_3(ido, l1, cc, ch, wa1, wa2)\n\n ! Dummy arguments\n\n integer(ip), intent(in) :: ido\n integer(ip), intent(in) :: l1\n real(wp), intent(in) :: cc(ido, l1, 3)\n real(wp), intent(out) :: ch(ido, 3, l1)\n real(wp), intent(in) :: wa1(*)\n real(wp), intent(in) :: wa2(*)\n\n ! Local variables\n\n integer(ip) :: k, idp2, i, ic\n real(wp), parameter :: taur = -HALF\n real(wp), parameter :: taui = SQRT_3/TWO ! 0.866025403784439\n real(wp) :: cr2, dr2, di2, dr3, di3, ci2, tr2, ti2, tr3, ti3\n\n\n do k = 1, l1\n cr2 = cc(1, k, 2) + cc(1, k, 3)\n ch(1, 1, k) = cc(1, k, 1) + cr2\n ch(1, 3, k) = taui*(cc(1, k, 3)-cc(1, k, 2))\n ch(ido, 2, k) = cc(1, k, 1) + taur*cr2\n end do\n\n if(ido /= 1) then\n idp2 = ido + 2\n do k = 1, l1\n do i = 3, ido, 2\n ic = idp2 - i\n dr2 = wa1(i-2)*cc(i-1, k, 2) + wa1(i-1)*cc(i, k, 2)\n di2 = wa1(i-2)*cc(i, k, 2) - wa1(i-1)*cc(i-1, k, 2)\n dr3 = wa2(i-2)*cc(i-1, k, 3) + wa2(i-1)*cc(i, k, 3)\n di3 = wa2(i-2)*cc(i, k, 3) - wa2(i-1)*cc(i-1, k, 3)\n cr2 = dr2 + dr3\n ci2 = di2 + di3\n ch(i-1, 1, k) = cc(i-1, k, 1) + cr2\n ch(i, 1, k) = cc(i, k, 1) + ci2\n tr2 = cc(i-1, k, 1) + taur*cr2\n ti2 = cc(i, k, 1) + taur*ci2\n tr3 = taui*(di2 - di3)\n ti3 = taui*(dr3 - dr2)\n ch(i-1, 3, k) = tr2 + tr3\n ch(ic-1, 2, k) = tr2 - tr3\n ch(i, 3, k) = ti2 + ti3\n ch(ic, 2, k) = ti3 - ti2\n end do\n end do\n end if\n\n end subroutine real_forward_pass_3\n\n subroutine real_forward_pass_4(ido, l1, cc, ch, wa1, wa2, wa3)\n\n ! Dummy arguments\n\n integer(ip), intent(in) :: ido\n integer(ip), intent(in) :: l1\n real(wp), intent(in) :: cc(ido, l1, 4)\n real(wp), intent(out) :: ch(ido, 4, l1)\n real(wp), intent(in) :: wa1(*)\n real(wp), intent(in) :: wa2(*)\n real(wp), intent(in) :: wa3(*)\n\n ! Local variables\n\n integer(ip) :: k, idp2, i, ic\n real(wp) :: tr1, tr2, cr2, ci2, cr3, ci3\n real(wp) :: cr4, ci4, tr4, ti1\n real(wp) :: ti4, ti2, ti3, tr3\n real(wp), parameter :: ONE_OVER_SQRT_2 = ONE/SQRT_2\n\n\n do k = 1, l1\n tr1 = cc(1, k, 2) + cc(1, k, 4)\n tr2 = cc(1, k, 1) + cc(1, k, 3)\n ch(1, 1, k) = tr1 + tr2\n ch(ido, 4, k) = tr2 - tr1\n ch(ido, 2, k) = cc(1, k, 1) - cc(1, k, 3)\n ch(1, 3, k) = cc(1, k, 4) - cc(1, k, 2)\n end do\n\n if (ido >= 2) then\n if (ido /= 2) then\n idp2 = ido + 2\n do k = 1, l1\n do i = 3, ido, 2\n ic = idp2 - i\n cr2 = wa1(i-2)*cc(i-1, k, 2) + wa1(i-1)*cc(i, k, 2)\n ci2 = wa1(i-2)*cc(i, k, 2) - wa1(i-1)*cc(i-1, k, 2)\n cr3 = wa2(i-2)*cc(i-1, k, 3) + wa2(i-1)*cc(i, k, 3)\n ci3 = wa2(i-2)*cc(i, k, 3) - wa2(i-1)*cc(i-1, k, 3)\n cr4 = wa3(i-2)*cc(i-1, k, 4) + wa3(i-1)*cc(i, k, 4)\n ci4 = wa3(i-2)*cc(i, k, 4) - wa3(i-1)*cc(i-1, k, 4)\n tr1 = cr2 + cr4\n tr4 = cr4 - cr2\n ti1 = ci2 + ci4\n ti4 = ci2 - ci4\n ti2 = cc(i, k, 1) + ci3\n ti3 = cc(i, k, 1) - ci3\n tr2 = cc(i-1, k, 1) + cr3\n tr3 = cc(i-1, k, 1) - cr3\n ch(i-1, 1, k) = tr1 + tr2\n ch(ic-1, 4, k) = tr2 - tr1\n ch(i, 1, k) = ti1 + ti2\n ch(ic, 4, k) = ti1 - ti2\n ch(i-1, 3, k) = ti4 + tr3\n ch(ic-1, 2, k) = tr3 - ti4\n ch(i, 3, k) = tr4 + ti3\n ch(ic, 2, k) = tr4 - ti3\n end do\n end do\n if (mod(ido, 2) == 1) then\n return\n end if\n end if\n do k = 1, l1\n ti1 = -ONE_OVER_SQRT_2*(cc(ido, k, 2)+cc(ido, k, 4))\n tr1 = ONE_OVER_SQRT_2*(cc(ido, k, 2)-cc(ido, k, 4))\n ch(ido, 1, k) = tr1 + cc(ido, k, 1)\n ch(ido, 3, k) = cc(ido, k, 1) - tr1\n ch(1, 2, k) = ti1 - cc(ido, k, 3)\n ch(1, 4, k) = ti1 + cc(ido, k, 3)\n end do\n end if\n\n end subroutine real_forward_pass_4\n\n subroutine real_forward_pass_5(ido, l1, cc, ch, wa1, wa2, wa3, wa4)\n\n ! Dummy arguments\n\n integer(ip), intent(in) :: ido\n integer(ip), intent(in) :: l1\n real(wp), intent(in) :: cc(ido, l1, 5)\n real(wp), intent(out) :: ch(ido, 5, l1)\n real(wp), intent(in) :: wa1(*)\n real(wp), intent(in) :: wa2(*)\n real(wp), intent(in) :: wa3(*)\n real(wp), intent(in) :: wa4(*)\n\n ! Local variables\n\n integer(ip) :: k, idp2, i, ic\n real(wp) :: cr2, ci5, cr3, ci4, dr2, di2, dr3\n real(wp) :: di3, dr4, di4, dr5, di5, cr5, ci2, cr4, ci3, tr2, ti2, tr3\n real(wp) :: ti3, tr5, ti5, tr4, ti4\n real(wp), parameter :: tr11 = (SQRT_5 - ONE)/4\n real(wp), parameter :: ti11 = sqrt((FIVE + SQRT_5)/2)/2\n real(wp), parameter :: tr12 = (-ONE - SQRT_5)/4\n real(wp), parameter :: ti12 = sqrt(FIVE/(TWO * (FIVE + SQRT_5)))\n\n\n do k = 1, l1\n cr2 = cc(1, k, 5) + cc(1, k, 2)\n ci5 = cc(1, k, 5) - cc(1, k, 2)\n cr3 = cc(1, k, 4) + cc(1, k, 3)\n ci4 = cc(1, k, 4) - cc(1, k, 3)\n ch(1, 1, k) = cc(1, k, 1) + cr2 + cr3\n ch(ido, 2, k) = cc(1, k, 1) + tr11*cr2 + tr12*cr3\n ch(1, 3, k) = ti11*ci5 + ti12*ci4\n ch(ido, 4, k) = cc(1, k, 1) + tr12*cr2 + tr11*cr3\n ch(1, 5, k) = ti12*ci5 - ti11*ci4\n end do\n\n if(ido /= 1) then\n idp2 = ido + 2\n do k = 1, l1\n do i = 3, ido, 2\n ic = idp2 - i\n dr2 = wa1(i-2)*cc(i-1, k, 2) + wa1(i-1)*cc(i, k, 2)\n di2 = wa1(i-2)*cc(i, k, 2) - wa1(i-1)*cc(i-1, k, 2)\n dr3 = wa2(i-2)*cc(i-1, k, 3) + wa2(i-1)*cc(i, k, 3)\n di3 = wa2(i-2)*cc(i, k, 3) - wa2(i-1)*cc(i-1, k, 3)\n dr4 = wa3(i-2)*cc(i-1, k, 4) + wa3(i-1)*cc(i, k, 4)\n di4 = wa3(i-2)*cc(i, k, 4) - wa3(i-1)*cc(i-1, k, 4)\n dr5 = wa4(i-2)*cc(i-1, k, 5) + wa4(i-1)*cc(i, k, 5)\n di5 = wa4(i-2)*cc(i, k, 5) - wa4(i-1)*cc(i-1, k, 5)\n cr2 = dr2 + dr5\n ci5 = dr5 - dr2\n cr5 = di2 - di5\n ci2 = di2 + di5\n cr3 = dr3 + dr4\n ci4 = dr4 - dr3\n cr4 = di3 - di4\n ci3 = di3 + di4\n ch(i-1, 1, k) = cc(i-1, k, 1) + cr2 + cr3\n ch(i, 1, k) = cc(i, k, 1) + ci2 + ci3\n tr2 = cc(i-1, k, 1) + tr11*cr2 + tr12*cr3\n ti2 = cc(i, k, 1) + tr11*ci2 + tr12*ci3\n tr3 = cc(i-1, k, 1) + tr12*cr2 + tr11*cr3\n ti3 = cc(i, k, 1) + tr12*ci2 + tr11*ci3\n tr5 = ti11*cr5 + ti12*cr4\n ti5 = ti11*ci5 + ti12*ci4\n tr4 = ti12*cr5 - ti11*cr4\n ti4 = ti12*ci5 - ti11*ci4\n ch(i-1, 3, k) = tr2 + tr5\n ch(ic-1, 2, k) = tr2 - tr5\n ch(i, 3, k) = ti2 + ti5\n ch(ic, 2, k) = ti5 - ti2\n ch(i-1, 5, k) = tr3 + tr4\n ch(ic-1, 4, k) = tr3 - tr4\n ch(i, 5, k) = ti3 + ti4\n ch(ic, 4, k) = ti4 - ti3\n end do\n end do\n end if\n\n end subroutine real_forward_pass_5\n\n subroutine real_forward_pass_n(ido, iip, l1, idl1, cc, c1, c2, ch, ch2, wa)\n\n ! Dummy arguments\n\n integer(ip), intent(in) :: ido\n integer(ip), intent(in) :: iip\n integer(ip), intent(in) :: l1\n integer(ip), intent(in) :: idl1\n real(wp), intent(out) :: cc(ido, iip, l1)\n real(wp), intent(inout) :: c1(ido, l1, iip)\n real(wp), intent(inout) :: c2(idl1, iip)\n real(wp), intent(inout) :: ch(ido, l1, iip)\n real(wp), intent(inout) :: ch2(idl1, iip)\n real(wp), intent(in) :: wa(*)\n\n ! Local variables\n\n integer(ip) :: iipph, iipp2, idp2, nbd, j\n integer(ip) :: k, is, idij, i, jc, l, lc\n real(wp) :: arg, dcp, dsp, ar1, ai1\n real(wp) :: ar1h, dc2, ds2, ar2, ai2, ar2h\n\n\n arg = TWO_PI/iip\n dcp = cos(arg)\n dsp = sin(arg)\n iipph = (iip + 1)/2\n iipp2 = iip + 2\n idp2 = ido + 2\n nbd =(ido - 1)/2\n\n block_construct: block\n if (ido /= 1) then\n ch2(:, 1) = c2(:, 1)\n ch(1, :, 2:iip) = c1(1, :, 2:iip)\n if (nbd <= l1) then\n is = -ido\n do j = 2, iip\n is = is + ido\n idij = is\n do i = 3, ido, 2\n idij = idij + 2\n ch(i-1, :, j)=wa(idij-1)*c1(i-1, :, j)+wa(idij)*c1(i, :, j)\n ch(i, :, j)=wa(idij-1)*c1(i, :, j)-wa(idij)*c1(i-1, :, j)\n end do\n end do\n else\n is = -ido\n do j = 2, iip\n is = is + ido\n do k = 1, l1\n idij = is\n ch(2:ido-1:2, k, j) = wa(idij+1:ido-2+idij:2)*c1(2:ido-1 &\n :2, k, j) + wa(idij+2:ido-1+idij:2)*c1(3:ido:2, k, j)\n ch(3:ido:2, k, j) = wa(idij+1:ido-2+idij:2)*c1(3:ido:2, k &\n , j) - wa(idij+2:ido-1+idij:2)*c1(2:ido-1:2, k, j)\n end do\n end do\n end if\n if (l1 <= nbd) then\n do j = 2, iipph\n jc = iipp2 - j\n c1(2:ido-1:2, :, j)=ch(2:ido-1:2, :, j)+ch(2:ido-1:2, :, jc)\n c1(2:ido-1:2, :, jc) = ch(3:ido:2, :, j) - ch(3:ido:2, :, jc)\n c1(3:ido:2, :, j) = ch(3:ido:2, :, j) + ch(3:ido:2, :, jc)\n c1(3:ido:2, :, jc) = ch(2:ido-1:2, :, jc) - ch(2:ido-1:2, :, j)\n end do\n exit block_construct\n end if\n do j = 2, iipph\n jc = iipp2 - j\n c1(2:ido-1:2, :, j) = ch(2:ido-1:2, :, j) + ch(2:ido-1:2, :, jc)\n c1(2:ido-1:2, :, jc) = ch(3:ido:2, :, j) - ch(3:ido:2, :, jc)\n c1(3:ido:2, :, j) = ch(3:ido:2, :, j) + ch(3:ido:2, :, jc)\n c1(3:ido:2, :, jc) = ch(2:ido-1:2, :, jc) - ch(2:ido-1:2, :, j)\n end do\n exit block_construct\n end if\n c2(:, 1) = ch2(:, 1)\n end block block_construct\n\n do j = 2, iipph\n jc = iipp2 - j\n c1(1, :, j) = ch(1, :, j) + ch(1, :, jc)\n c1(1, :, jc) = ch(1, :, jc) - ch(1, :, j)\n end do\n\n ar1 = ONE\n ai1 = ZERO\n do l = 2, iipph\n lc = iipp2 - l\n ar1h = dcp*ar1 - dsp*ai1\n ai1 = dcp*ai1 + dsp*ar1\n ar1 = ar1h\n ch2(:, l) = c2(:, 1) + ar1*c2(:, 2)\n ch2(:, lc) = ai1*c2(:, iip)\n dc2 = ar1\n ds2 = ai1\n ar2 = ar1\n ai2 = ai1\n do j = 3, iipph\n jc = iipp2 - j\n ar2h = dc2*ar2 - ds2*ai2\n ai2 = dc2*ai2 + ds2*ar2\n ar2 = ar2h\n ch2(:, l) = ch2(:, l) + ar2*c2(:, j)\n ch2(:, lc) = ch2(:, lc) + ai2*c2(:, jc)\n end do\n end do\n\n do j = 2, iipph\n ch2(:, 1) = ch2(:, 1) + c2(:, j)\n end do\n\n cc(:, 1, :) = ch(:, :, 1)\n cc(ido, 2:(iipph-1)*2:2, :) = transpose(ch(1, :, 2:iipph))\n cc(1, 3:iipph*2-1:2, :) = transpose(ch(1, :, iipp2-2:iipp2-iipph:(-1)))\n\n if(ido /= 1) then\n if (l1 <= nbd) then\n cc(2:ido-1:2, 3:iipph*2-1:2, :) = &\n reshape( &\n source = ch(2:ido-1:2, :, 2:iipph)+ch(2:ido-1:2, :, iipp2-2:iipp2-iipph:(-1)), &\n shape = [(ido-1)/2, iipph-1, l1], &\n order = [1, 3, 2] &\n )\n cc(idp2-4:idp2-1-ido:(-2), 2:(iipph-1)*2:2, :) = &\n reshape( &\n source = ch(2:ido-1:2, :, 2:iipph)-ch(2:ido-1:2, :, iipp2-2:iipp2-iipph:(-1)), &\n shape = [(ido-1)/2, iipph-1, l1], &\n order = [1, 3, 2] &\n )\n cc(3:ido:2, 3:iipph*2-1:2, :) = &\n reshape(&\n source = ch(3:ido:2, :, 2:iipph)+ch(3:ido:2, :, iipp2-2:iipp2-iipph:(-1)), &\n shape = [(ido-1)/2, iipph-1, l1], &\n order = [1, 3, 2] &\n )\n cc(idp2-3:idp2-ido:(-2), 2:(iipph-1)*2:2, :) = &\n reshape(&\n source = ch(3:ido:2, :, iipp2-2:iipp2-iipph:(-1))-ch(3:ido:2, :, 2:iipph), &\n shape = [(ido-1)/2, iipph-1, l1], &\n order = [1, 3, 2] &\n )\n else\n cc(2:ido-1:2, 3:iipph*2-1:2, :) = &\n reshape( &\n source = ch(2:ido-1:2, :, 2:iipph)+ch(2:ido-1:2, :, iipp2-2:iipp2-iipph:(-1)), &\n shape = [(ido-1)/2, iipph-1, l1], &\n order = [1, 3, 2] &\n )\n cc(idp2-4:idp2-1-ido:(-2), 2:(iipph-1)*2:2, :) = &\n reshape( &\n source = ch(2:ido-1:2, :, 2:iipph)-ch(2:ido-1:2, :, iipp2-2:iipp2-iipph:(-1)), &\n shape = [(ido-1)/2, iipph-1, l1], &\n order = [1, 3, 2] &\n )\n cc(3:ido:2, 3:iipph*2-1:2, :) = &\n reshape( &\n source = ch(3:ido:2, :, 2:iipph)+ch(3:ido:2, :, iipp2-2:iipp2-iipph:(-1)), &\n shape = [(ido-1)/2, iipph-1, l1], &\n order = [1, 3, 2] &\n )\n cc(idp2-3:idp2-ido:(-2), 2:(iipph-1)*2:2, :) = &\n reshape( &\n source = ch(3:ido:2, :, iipp2-2:iipp2-iipph:(-1))-ch(3:ido:2, :, 2:iipph), &\n shape = [(ido-1)/2, iipph-1, l1], &\n order = [1, 3, 2] &\n )\n end if\n end if\n\n end subroutine real_forward_pass_n\n\nend module type_FastFourierTransform\n", "meta": {"hexsha": "39c35c23d113b15f945626f086b3151e8e528c12", "size": 129181, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/type_FastFourierTransform.f90", "max_stars_repo_name": "jlokimlin/spherepack4.1", "max_stars_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-06-28T14:01:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T21:59:28.000Z", "max_issues_repo_path": "src/type_FastFourierTransform.f90", "max_issues_repo_name": "jlokimlin/spherepack4.1", "max_issues_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2016-05-07T23:00:35.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-22T23:52:30.000Z", "max_forks_repo_path": "src/type_FastFourierTransform.f90", "max_forks_repo_name": "jlokimlin/spherepack4.1", "max_forks_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-06-28T14:03:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T12:53:54.000Z", "avg_line_length": 34.1297225892, "max_line_length": 103, "alphanum_fraction": 0.4119026792, "num_tokens": 41414, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818986, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.6967293806753976}} {"text": " subroutine nscore(nd,vr,tmin,tmax,iwt,wt,tmp,lout,vrg,ierror)\r\nc-----------------------------------------------------------------------\r\nc\r\nc Transform Univariate Data to Normal Scores\r\nc ******************************************\r\nc\r\nc This subroutibe takes \"nd\" data \"vr(i),i=1,...,nd\" possibly weighted\r\nc by \"wt(i),i=,...,nd\" and returns the normal scores transform N(0,1)\r\nc as \"vrg(i),i=1,...,nd\". The extra storage array \"tmp\" is required\r\nc so that the data can be returned in the same order (just in case\r\nc there are associated arrays like the coordinate location).\r\nc\r\nc\r\nc\r\nc INPUT VARIABLES:\r\nc\r\nc nd Number of data (no missing values)\r\nc vr(nd) Data values to be transformed\r\nc tmin,tmax data trimming limits\r\nc iwt =0, equal weighted; =1, then apply weight\r\nc wt(nd) Weight for each data (don't have to sum to 1.0)\r\nc tmp(nd) Temporary storage space for sorting\r\nc lout if > 0 then transformation table will be written\r\nc\r\nc\r\nc\r\nc OUTPUT VARIABLES:\r\nc\r\nc vrg(nd) normal scores\r\nc ierror error flag (0=error free,1=problem)\r\nc\r\nc\r\nc\r\nc EXTERNAL REFERENCES:\r\nc\r\nc gauinv Calculates the inverse of a Gaussian cdf\r\nc sortem sorts a number of arrays according to a key array\r\nc\r\nc\r\nc\r\nc-----------------------------------------------------------------------\r\n parameter(EPSLON=1.0e-20)\r\n real vr(nd),wt(nd),vrg(nd),tmp(nd)\r\n real*8 pd\r\nc\r\nc Sort the data in ascending order and calculate total weight:\r\nc\r\n ierror = 0\r\n twt = 0.0\r\n do i=1,nd\r\n tmp(i) = real(i)\r\n if(vr(i).ge.tmin.and.vr(i).lt.tmax) then\r\n if(iwt.eq.0) then\r\n twt = twt + 1.\r\n else\r\n twt = twt + wt(i)\r\n end if\r\n end if\r\n end do\r\n if(nd.lt.1.or.twt.lt.EPSLON) then\r\n ierror = 1\r\n return\r\n end if\r\n call sortem(1,nd,vr,2,wt,tmp,d,e,f,g,h)\r\nc\r\nc Compute the cumulative probabilities:\r\nc\r\n oldcp = 0.0\r\n cp = 0.0\r\n do i=1,nd\r\n cp = cp + wt(i) / twt\r\n wt(i) = (cp + oldcp)/ 2.0\r\n oldcp = cp\r\n call gauinv(dble(wt(i)),vrg(i),ierr)\r\n if(lout.gt.0) write(lout,'(f12.5,1x,f12.5)') vr(i),vrg(i)\r\n end do\r\nc\r\nc Get the arrays back in original order:\r\nc\r\n call sortem(1,nd,tmp,3,wt,vr,vrg,e,f,g,h)\r\nc\r\nc Finished:\r\nc\r\n return\r\n end\r\n", "meta": {"hexsha": "4d334d82e0867f2350a442e1e5a93edc0b7a2f55", "size": 2581, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/original/gslib/nscore.for", "max_stars_repo_name": "exepulveda/gslib2.0", "max_stars_repo_head_hexsha": "5c021000eb3da8703ced3ee9be145d6c0ecb2608", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-07-09T06:03:38.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T11:11:19.000Z", "max_issues_repo_path": "src/original/gslib/nscore.for", "max_issues_repo_name": "exepulveda/gslib2.0", "max_issues_repo_head_hexsha": "5c021000eb3da8703ced3ee9be145d6c0ecb2608", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/original/gslib/nscore.for", "max_forks_repo_name": "exepulveda/gslib2.0", "max_forks_repo_head_hexsha": "5c021000eb3da8703ced3ee9be145d6c0ecb2608", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.011627907, "max_line_length": 73, "alphanum_fraction": 0.4951569159, "num_tokens": 735, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.6967293759911954}} {"text": "PROGRAM test_entry\r\nREAL :: a = 1., b = 2., c = 1., d = 2.\r\nCALL initl ( a, b, c, d )\r\nDO I = 1, 10\r\n CALL eval3 ( REAL(i), result )\r\n WRITE (*,*) 'EVAL3(', i, ') = ', result\r\nEND DO\r\nEND PROGRAM\r\n\r\nSUBROUTINE eval3 ( x, result )\r\n!\r\n! Evaluates a third order polynomial of the form:\r\n! RESULT = A + B*X + C*X**2 + D*X**3\r\n!\r\n! Declare calling arguments\r\nIMPLICIT NONE\r\nREAL :: a1, b1, c1, d1, x, result\r\n\r\n! Declare local variables\r\nREAL, SAVE :: a, b, c, d\r\n\r\n! Calculate result\r\nresult = a + b**x + c*x**2 + d*x**3 \r\n\r\nRETURN\r\n\r\n! Entry INITL specifies the values of a, b, c, and d\r\n! to be used when evaluating the polynomial.\r\n\r\nENTRY initl(a1, b1, c1, d1)\r\na = a1\r\nb = b1\r\nc = c1\r\nd = d1\r\n\r\nRETURN\r\nEND SUBROUTINE\r\n", "meta": {"hexsha": "08e9248fc4884a90a4096818e429e33594c06b08", "size": 740, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap17/test_entry.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/chap17/test_entry.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/chap17/test_entry.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": 19.4736842105, "max_line_length": 54, "alphanum_fraction": 0.5675675676, "num_tokens": 260, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045817875224, "lm_q2_score": 0.7853085808877581, "lm_q1q2_score": 0.6967293710806761}} {"text": "submodule(euler_interface_m) euler_prob_0039_m\n implicit none\n\ncontains\n\n module character(len=20) function euler0039()\n write (euler0039, \"(i20)\") ans(1000)\n end function euler0039\n\n integer function ans(n)\n integer, intent(in) :: n\n integer :: i, count_arr(n)\n\n do i = 1, n\n count_arr(i) = right_triangle_with_perimeter(i)\n end do\n\n ans = maxloc(count_arr, dim=1)\n end function ans\n\n integer function right_triangle_with_perimeter(p)\n integer, intent(in) :: p\n integer :: i, j, k, t\n\n t = 0\n do i = 1, p/2 + 1\n do j = 1, p - i - 1\n k = p - i - j\n if (is_right_triangle(i, j, k)) t = t + 1\n end do\n end do\n right_triangle_with_perimeter = t\n end function right_triangle_with_perimeter\n\n logical function is_right_triangle(i, j, k)\n integer, intent(in) :: i, j, k\n\n is_right_triangle = .false.\n if (i**2 + j**2 == k**2) then\n is_right_triangle = .true.\n end if\n end function is_right_triangle\n\nend submodule euler_prob_0039_m\n", "meta": {"hexsha": "f529d7b7d3222a81d334f7eb75f9c0afde88aa92", "size": 1139, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/euler/prob_0039_m.f90", "max_stars_repo_name": "han190/PE-Fortran", "max_stars_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-02-09T07:07:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-31T07:45:48.000Z", "max_issues_repo_path": "docs/src/prob_0039_m.f90", "max_issues_repo_name": "han190/PE-Fortran", "max_issues_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-14T00:48:58.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-14T00:48:58.000Z", "max_forks_repo_path": "docs/src/prob_0039_m.f90", "max_forks_repo_name": "han190/PE-Fortran", "max_forks_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-04T21:29:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T21:29:45.000Z", "avg_line_length": 25.3111111111, "max_line_length": 59, "alphanum_fraction": 0.5706760316, "num_tokens": 319, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336204, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.6966560771617759}} {"text": "!> module containing the mean radial distribution function \nmodule mean_RDF_mod\n use working_prec_mod, only: rk, ik\n use globals_mod \n implicit none\n private\n \n public:: mean_RDF\ncontains\n \n !> calc. radial distribution function \n subroutine mean_RDF ( g_RDF ) \n integer(ik):: ref_part \n integer(ik):: n_part_k = 0\n real(rk):: dis_1 \n real(rk):: dis_max\n real(rk), allocatable:: dis_k(:), dis_k2(:) \n real(rk), intent(out):: g_RDF(intervalls) \n real(rk):: dis_kmin\n real(rk):: d2\n integer(ik):: i, k\n \n allocate(dis_k(0:intervalls))\n allocate(dis_k2(0:intervalls))\n \n ref_part = 1_ik \n \n dis_1 = sigma_list(ref_part)\n dis_max = 4._rk * dis_1\n \n do k = 0, intervalls\n dis_k(k) = ( dis_1**2._rk + ( dis_max**2._rk - dis_1**2._rk ) * real(k,rk)/real(intervalls,rk) )**0.5_rk \n dis_k2(k) = dis_k(k)*dis_k(k) \n end do \n \n do k = 1, intervalls \n do i = 2, npart\n d2 = squared_distance (particle_positions(:,ref_part), particle_positions(:,i))\n if ( dis_k2(k-1_ik) .lt. d2 .and. d2 .lt. dis_k2(k) ) n_part_k = n_part_k + 1_ik\n end do \n g_RDF(k) = 3._rk*boxlength**3._rk*real(n_part_k,rk) / ( 2._rk*PI* ( dis_k(k)**3._rk - dis_k(k-1_ik)**3._rk ) * real(npart,rk) * ( real(npart,rk) - 1._rk ) )\n n_part_k = 0_ik\n end do \n \n \n deallocate(dis_k) \n deallocate(dis_k2) \n \n end subroutine mean_RDF\n\nend module mean_RDF_mod\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "e300cde3a38874bec414eb3bdc7b651221c913dc", "size": 1471, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/mean_RDF.f90", "max_stars_repo_name": "runnermt/MC-programm-for-fluid-mixtures-of-dipolar-and-charged-hard-spheres", "max_stars_repo_head_hexsha": "3dd7d1518afb0e45caf7bb729d817b1ad2697852", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-06-15T08:24:36.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-29T22:29:48.000Z", "max_issues_repo_path": "src/mean_RDF.f90", "max_issues_repo_name": "maTheiss/MC-programm-for-fluid-mixtures-of-dipolar-and-charged-hard-spheres", "max_issues_repo_head_hexsha": "3dd7d1518afb0e45caf7bb729d817b1ad2697852", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/mean_RDF.f90", "max_forks_repo_name": "maTheiss/MC-programm-for-fluid-mixtures-of-dipolar-and-charged-hard-spheres", "max_forks_repo_head_hexsha": "3dd7d1518afb0e45caf7bb729d817b1ad2697852", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.1147540984, "max_line_length": 163, "alphanum_fraction": 0.5968728756, "num_tokens": 515, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513814471132, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6966560697527729}} {"text": "program intrinsics_31\n real :: x = 63.29\n real :: y = -63.59\n real :: x_ceil, y_ceil\n x_ceil = ceiling(x)\n y_ceil = ceiling(y)\n print *, x_ceil, ceiling(x_ceil)\n print *, y_ceil, ceiling(y_ceil)\nend program intrinsics_31", "meta": {"hexsha": "dc8af5745d91cc50708d68462ddd2a3130aae28c", "size": 241, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "integration_tests/intrinsics_31.f90", "max_stars_repo_name": "Thirumalai-Shaktivel/lfortran", "max_stars_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "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": "integration_tests/intrinsics_31.f90", "max_issues_repo_name": "Thirumalai-Shaktivel/lfortran", "max_issues_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "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": "integration_tests/intrinsics_31.f90", "max_forks_repo_name": "Thirumalai-Shaktivel/lfortran", "max_forks_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.7777777778, "max_line_length": 36, "alphanum_fraction": 0.6348547718, "num_tokens": 83, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513786759492, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6966560675987474}} {"text": "*\n* grades - Calculate student grades based on partial scores\n*\n* The final grade is 30% programs, 50% tests and 20% homework\n*\n* Grades are assigned based on the following scale:\n*\n* >0.90 4.0\n* >0.80 3.0\n* >0.70 2.0\n* <0.60 0.0\n*\n* Written by: C. Severance 16Mar92\n*\n* Declare the variables:\n*\n REAL PPER,TPER,HPER,TOTAL\n*\n* Prompt the user for the three percentages\n*\n PRINT *,'Enter the program percentage -'\n READ *,PPER\n PRINT *,'Enter the test percentage -'\n READ *,TPER\n PRINT *,'Enter the homework percentage -'\n READ *,HPER\n*\n* Calculate the total percentage\n*\n TOTAL = PPER * 0.30 + TPER * 0.50 + HPER * 0.20\n PRINT *,'Total percentage is ', TOTAL\n*\n* Determine the final grade\n*\n IF ( TOTAL .GE. 0.90 ) THEN\n PRINT *,'Grade is 4.0'\n ELSE IF ( TOTAL .GE. 0.80 ) THEN\n PRINT *,'Grade is 3.0'\n ELSE IF ( TOTAL .GE. 0.70 ) THEN\n PRINT *,'Grade is 2.0'\n ELSE\n PRINT *,'Grade is 0.0'\n ENDIF\n END\n", "meta": {"hexsha": "8aed97ae90f66cba8b590f824b50cc69011d4099", "size": 1018, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "archive/2000-eecs280/examples/examples.ftn/programs/grades.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/grades.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/grades.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": 22.6222222222, "max_line_length": 61, "alphanum_fraction": 0.5825147348, "num_tokens": 333, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361652391386, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6966302023501841}} {"text": "program inverse_matrix\n\t! This program tests the speed of flips\n\t! in inverting square matrices\n\t\n\tuse flips\n\t\n\timplicit none\n\t\n\ttype(flips_s) :: gg\n\tinteger :: n, nb,id,i\n\treal, dimension(:,:), allocatable :: amat, eye\n\treal :: ts,te,tot\n\t\n\twrite(*,*) 'Give matrix size: '\n\tread(*,*) n\n\twrite(*,*) 'Give rotation buffer size: '\n\tread(*,*) nb\n\twrite(*,*) 'Give problem ID (0 uses memory): '\n\tread(*,*) id\n\t\n\t! Init flips\n\tif (id <= 0) then\n\t\tcall flips_init(gg,n,n,buffersize=nb)\n\telse\n\t\tcall flips_init(gg,n,n,id,nb)\n\tend if\n\t\n\tallocate(amat(n,n),eye(n,n))\n\t\n\teye = 0.0\n\tdo i = 1,n\n\t\teye(i,i) = 1.0\n\tend do\n\t\n\tcall random_number(amat)\n\t\n\twrite(*,*) 'flips START!'\n\t\n\tcall cpu_time(ts)\n\t! Feed into flips\n\tdo i = 1,n\n\t\tcall flips_add(gg,1,amat(i,:),eye(i,:))\n\tend\tdo\n\t\n\t! Do the last rotation\n\tcall make_rotations_s(gg)\n\t\n\tcall cpu_time(te)\n\t\n\ttot = te-ts\n\t\n\twrite(*,*) 'Rotation time: ',tot\n\t\n\t\n\t! Solve\n\tcall cpu_time(ts)\n\tcall solve_utriag_mem_s(gg)\n\tcall cpu_time(te)\n\t\n\ttot = te-ts + tot\n\t\n\twrite(*,*) 'Solving time: ',te-ts\n\twrite(*,*) 'Total time: ',tot\n\t\n\t! Kill\n\tcall flips_kill(gg,.FALSE.)\n\t\nend program inverse_matrix\n\t\t\t ", "meta": {"hexsha": "f0041c965a1b6382d03281e369174701d5b6ecdf", "size": 1133, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/inv_mat_test.f90", "max_stars_repo_name": "morispaa/flips", "max_stars_repo_head_hexsha": "f6c98bd33bf01261f98db3a5bd581c2adbe4e2e7", "max_stars_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-12-03T09:16:08.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-03T09:16:08.000Z", "max_issues_repo_path": "tests/inv_mat_test.f90", "max_issues_repo_name": "morispaa/flips", "max_issues_repo_head_hexsha": "f6c98bd33bf01261f98db3a5bd581c2adbe4e2e7", "max_issues_repo_licenses": ["BSD-2-Clause-FreeBSD"], "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/inv_mat_test.f90", "max_forks_repo_name": "morispaa/flips", "max_forks_repo_head_hexsha": "f6c98bd33bf01261f98db3a5bd581c2adbe4e2e7", "max_forks_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.4202898551, "max_line_length": 47, "alphanum_fraction": 0.6248896734, "num_tokens": 376, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361509525462, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.6966301963529627}} {"text": "program rect_method\nimplicit none\n\ninteger :: i,N\n\nreal(8),allocatable :: x(:),y(:),a(:)\n real (8):: h,ul,ll,E\n\nN =10\n\nul =1.0\nll =0.0\nh = (ul-ll)/N\n\nprint*, h,ul,ll,N\n\nallocate(x(N+1),y(N+1))\n\n\tdo i =1, N+1\n\tif(i==1) then\n\tx(i) = ll\n\telse\n\tx(i) =x(i-1)+h\n\tend if\n\tprint*, x(i)\n\tend do\n\n\n\ny =1/x\ny = exp(-x**2)\ny = (2+ sin(2*x**2))\ny = exp(10-x)\nprint*,x\nprint*,y\nprint*,x,y\n do i=1,N \n!a(i) = h*(y(i+1)-y(i))\na(i)= h*y(i+1)\nprint*, a(i)\nend do\n\n\nprint*,\"the calculated value for the integration is\",sum(a)\nprint*,\"the value of error is \",E\n\ndeallocate (x,y,a)\nend program rect_method\n\n\n\n\n", "meta": {"hexsha": "ca03c9017fb0b3090a488542176c287c60b26c70", "size": 591, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "p01/p01.f90", "max_stars_repo_name": "akkiturb/Ilkay-s-Fortran-Class", "max_stars_repo_head_hexsha": "0600640574354052a5a7d87bad520b8a03650d0e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-12-18T19:31:01.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-18T19:31:01.000Z", "max_issues_repo_path": "p01/p01.f90", "max_issues_repo_name": "akkiturb/Scientific-computing-in-Fortran", "max_issues_repo_head_hexsha": "0600640574354052a5a7d87bad520b8a03650d0e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "p01/p01.f90", "max_forks_repo_name": "akkiturb/Scientific-computing-in-Fortran", "max_forks_repo_head_hexsha": "0600640574354052a5a7d87bad520b8a03650d0e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-02-04T19:45:56.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-10T14:22:05.000Z", "avg_line_length": 11.1509433962, "max_line_length": 59, "alphanum_fraction": 0.5634517766, "num_tokens": 249, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9124361604769414, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6966301938039635}} {"text": "Program Temperature\n implicit none\n\n real :: kel, cel, fah, ran\n\n write(*,*) \"Input Kelvin temperature to convert\"\n read(*,*) kel\n\n call temp_convert(kel, cel, fah, ran)\n write(*, \"((a10), f10.3)\") \"Kelvin\", kel\n write(*, \"((a10), f10.3)\") \"Celsius\", cel\n write(*, \"((a10), f10.3)\") \"Fahrenheit\", fah\n write(*, \"((a10), f10.3)\") \"Rankine\", ran\n\ncontains\n\nsubroutine temp_convert(kelvin, celsius, fahrenheit, rankine)\n real, intent(in) :: kelvin\n real, intent(out) :: celsius, fahrenheit, rankine\n\n celsius = kelvin - 273.15\n fahrenheit = kelvin * 1.8 - 459.67\n rankine = kelvin * 1.8\n\nend subroutine\nend program\n", "meta": {"hexsha": "73a853d3410ceec55a35a7c79e924bdc57b6774f", "size": 627, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Temperature-conversion/Fortran/temperature-conversion.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/Temperature-conversion/Fortran/temperature-conversion.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/Temperature-conversion/Fortran/temperature-conversion.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 23.2222222222, "max_line_length": 61, "alphanum_fraction": 0.639553429, "num_tokens": 226, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361604769413, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6966301938039634}} {"text": " subroutine ire_dtk(ctfmp,n_A,n_Athth,n_Axx,n_B,n_DDLthetatheta,n_D\n &DLxx,n_K,n_TS,n_alpha,n_beta,n_metthetatheta,n_metxx,n_rho,nm1_K,n\n &p1_K,Nx,ht,hx,res)\n implicit none\n integer i\n integer Nx\n real*8 ht\n real*8 hx\n real*8 ctfmp(Nx)\n real*8 n_A(Nx)\n real*8 n_Athth(Nx)\n real*8 n_Axx(Nx)\n real*8 n_B(Nx)\n real*8 n_DDLthetatheta(Nx)\n real*8 n_DDLxx(Nx)\n real*8 n_K(Nx)\n real*8 n_TS(Nx)\n real*8 n_alpha(Nx)\n real*8 n_beta(Nx)\n real*8 n_metthetatheta(Nx)\n real*8 n_metxx(Nx)\n real*8 n_rho(Nx)\n real*8 nm1_K(Nx)\n real*8 np1_K(Nx)\n real*8 res\n real*8 qb\n res = 0.0D0\n do i=2, Nx-1, 1\n qb = -0.5000000000000000D0 * (nm1_K(i) - 0.1D1 * np1_K(i)) / ht - \n #0.3333333333333333D0 * n_alpha(i) * n_K(i) ** 2 - 0.50000000000000\n #00D0 / ctfmp(i) * (-0.1D1 * n_K(i - 1) + n_K(i + 1)) / hx * n_beta\n #(i) - 0.5000000000000000D0 * n_alpha(i) * n_rho(i) - 0.50000000000\n #00000D0 * n_alpha(i) * n_TS(i) - 0.1D1 / n_A(i) ** 2 * n_Axx(i) **\n # 2 * n_alpha(i) - 0.2D1 / n_B(i) ** 2 * n_Athth(i) ** 2 * n_alpha(\n #i) + 0.2D1 / n_metthetatheta(i) * n_DDLthetatheta(i) + 0.1D1 / n_m\n #etxx(i) * n_DDLxx(i)\n res = res + qb**2\n end do\n res = sqrt(res/(1*Nx))\n END\n", "meta": {"hexsha": "e57c5d35afbf412a58e7b04241aae1393c304540", "size": 1333, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/FD/ire_dtk.f", "max_stars_repo_name": "rmanak/bssn_spher", "max_stars_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/FD/ire_dtk.f", "max_issues_repo_name": "rmanak/bssn_spher", "max_issues_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/FD/ire_dtk.f", "max_forks_repo_name": "rmanak/bssn_spher", "max_forks_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.512195122, "max_line_length": 72, "alphanum_fraction": 0.551387847, "num_tokens": 596, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172659321807, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.6966186943335477}} {"text": "program Magic_Square\n implicit none\n\n integer, parameter :: order = 15\n integer :: i, j\n\n write(*, \"(a, i0)\") \"Magic Square Order: \", order\n write(*, \"(a)\") \"----------------------\"\n do i = 1, order\n do j = 1, order\n write(*, \"(i4)\", advance = \"no\") f1(order, i, j)\n end do\n write(*,*)\n end do\n write(*, \"(a, i0)\") \"Magic number = \", f2(order)\n\ncontains\n\ninteger function f1(n, x, y)\n integer, intent(in) :: n, x, y\n\n f1 = n * mod(x + y - 1 + n/2, n) + mod(x + 2*y - 2, n) + 1\nend function\n\ninteger function f2(n)\n integer, intent(in) :: n\n\n f2 = n * (1 + n * n) / 2\nend function\nend program\n", "meta": {"hexsha": "2705e99f60b5fb905c6f1fce033c37ae3cd36482", "size": 622, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Magic-squares-of-odd-order/Fortran/magic-squares-of-odd-order.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/Magic-squares-of-odd-order/Fortran/magic-squares-of-odd-order.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/Magic-squares-of-odd-order/Fortran/magic-squares-of-odd-order.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 20.064516129, "max_line_length": 60, "alphanum_fraction": 0.5176848875, "num_tokens": 230, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172601537141, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.6966186900914626}} {"text": "! ALOHA2D Plasma module\n!\n!\nmodule aloha2d_plasma\n use aloha2d_constants\n use aloha2d_globalparameters\n\n real :: wce, wcD, wcT, wcH, wcHe ! cyclotron pulsations\n real :: wpe, wpD, wpT, wpH, wpHe ! plasma pulsations\n real :: dwpe, dwpD, dwpT, dwpH, dwpHe ! plasma pulsations derivative with respect to ne\n real :: S, D, P, dD, dP ! Cold plasma dielectric tensor elements\n\ncontains\n\n !\n ! Calculate the cyclotron pulsations :\n ! wce, wcD, wcT, wcH, wcHe\n !\n subroutine eval_cyclotron_pulsations()\n wce = omega_c(qe, B0, me)\n wcD = omega_c(qe, B0, mD)\n wcT = omega_c(qe, B0, mT)\n wcH = omega_c(qe, B0, mH)\n wcHe= omega_c(2*qe, B0, mHe)\n end subroutine eval_cyclotron_pulsations\n\n !\n ! Calculate the plasma pulsations\n ! wpe, wpD, wpT, wpH, wpHe\n !\n subroutine eval_plasma_pulsations()\n wpe = omega_p(ne, qe, me)\n wpD = omega_p(nD, qe, mD)\n wpT = omega_p(nT, qe, mT)\n wpH = omega_p(nH, qe, mH)\n wpHe= omega_p(nHe, 2*qe, mHe)\n end subroutine eval_plasma_pulsations\n\n !\n ! Calculate the plasma pulsations derivatives\n ! with respect to species's density\n ! dwpe, dwpD, dwpT, dwpH, dwpHe\n !\n subroutine eval_plasma_pulsations_derivatives()\n dwpe = domega_p(dne, qe, me)\n dwpD = domega_p(dnD, qe, mD)\n dwpT = domega_p(dnT, qe, mT)\n dwpH = domega_p(dnH, qe, mH)\n dwpHe = domega_p(2*nD, 2*qe, mHe)\n end subroutine eval_plasma_pulsations_derivatives\n\n !\n ! Calculate the cold plasma dielectric tensor element (Stix elements)\n ! S, D, P\n ! and derivatives with respect to the electron density\n ! dD, dP\n !\n subroutine eval_cold_tensor_elements()\n S = cold_plasma_dielectric_S()\n D = cold_plasma_dielectric_D()\n P = cold_plasma_dielectric_P()\n dD = cold_plasma_dielectric_dD()\n dP = cold_plasma_dielectric_dP()\n end subroutine eval_cold_tensor_elements\n\n !\n ! Cyclotron pulsation\n !\n function omega_c(q,B,m)\n real, intent(in) :: q,B,M ! electric charge, DC magnetic field, mass\n real :: omega_c\n\n omega_c = q*B/m\n end function omega_c\n\n !\n ! Plasma pulsation\n !\n function omega_p(n, q, m)\n real, intent(in) :: n, q, m\n real :: omega_p\n\n omega_p = sqrt(n*q**2/(Eps0*m))\n end function omega_p\n\n !\n ! Plasma pulsation derivative with respect to the species density\n !\n function domega_p(dn, q, m)\n real, intent(in) :: dn, q, m\n real :: domega_p\n\n domega_p = sqrt(dn*q**2/(Eps0*m))\n end function domega_p\n\n !\n ! Cold plasma dielectric tensor elements S, D, P\n !\n function cold_plasma_dielectric_S()\n real :: cold_plasma_dielectric_S\n\n cold_plasma_dielectric_S = 1-( wpe**2/((2*pi*f)**2-wce**2) + &\n wpD**2/((2*pi*f)**2-wcD**2) + &\n wpT**2/((2*pi*f)**2-wcT**2) + &\n wpH**2/((2*pi*f)**2-wcH**2) + &\n wpHe**2/((2*pi*f)**2-wcHe**2) )\n\n end function cold_plasma_dielectric_S\n\n function cold_plasma_dielectric_D()\n real :: cold_plasma_dielectric_D\n cold_plasma_dielectric_D= &\n -wpe**2*wce/(2*pi*f*((2*pi*f)**2 - wce**2)) + &\n wpD**2*wcD/(2*pi*f*((2*pi*f)**2 - wcD**2)) + &\n wpT**2*wcT/(2*pi*f*((2*pi*f)**2 - wcT**2)) + &\n wpH**2*wcH/(2*pi*f*((2*pi*f)**2 - wcH**2)) + &\n wpHe**2*wcHe/(2*pi*f*((2*pi*f)**2 - wcHe**2))\n end function cold_plasma_dielectric_D\n\n function cold_plasma_dielectric_P()\n real :: cold_plasma_dielectric_P\n\n cold_plasma_dielectric_P=&\n 1-( (wpe/(2*pi*f))**2 + &\n (wpD/(2*pi*f))**2 + &\n (wpT/(2*pi*f))**2 + &\n (wpH/(2*pi*f))**2 + &\n (wpHe/(2*pi*f))**2 )\n\n end function cold_plasma_dielectric_P\n\n !\n ! Cold plasma tensor element derivative with respect to electron density dD, dP\n !\n function cold_plasma_dielectric_dD()\n real :: cold_plasma_dielectric_dD\n\n cold_plasma_dielectric_dD=&\n (-dwpe**2*wce/(2*pi*f*((2*pi*f)**2 - wce**2)) + &\n dwpD**2*wcD/(2*pi*f*((2*pi*f)**2 - wcD**2)) + &\n dwpT**2*wcT/(2*pi*f*((2*pi*f)**2 - wcT**2)) + &\n dwpH**2*wcH/(2*pi*f*((2*pi*f)**2 - wcH**2)) + &\n dwpHe**2*wcHe/(2*pi*f*((2*pi*f)**2 - wcHe**2))) &\n /k0\n end function cold_plasma_dielectric_dD\n\n function cold_plasma_dielectric_dP()\n real :: cold_plasma_dielectric_dP\n\n cold_plasma_dielectric_dP=&\n -((dwpe/(2*pi*f))**2 + &\n (dwpD/(2*pi*f))**2 + &\n (dwpT/(2*pi*f))**2 + &\n (dwpH/(2*pi*f))**2 + &\n (dwpHe/(2*pi*f))**2)/k0\n\n end function cold_plasma_dielectric_dP\n\n\n\nend module aloha2d_plasma\n", "meta": {"hexsha": "55d17dce52c0cb96b1c4fb1ba19c8639833091b9", "size": 4391, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "code_2D/couplage_2D/ALOHA2D_F90/libaloha2D/aloha2d_plasma.f90", "max_stars_repo_name": "IRFM/ALOHA", "max_stars_repo_head_hexsha": "e8e7a47a70c7095b339b3dea25dcd4b95f382959", "max_stars_repo_licenses": ["CECILL-B"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-11-12T08:42:36.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-12T08:42:41.000Z", "max_issues_repo_path": "code_2D/couplage_2D/ALOHA2D_F90/libaloha2D/aloha2d_plasma.f90", "max_issues_repo_name": "IRFM/ALOHA", "max_issues_repo_head_hexsha": "e8e7a47a70c7095b339b3dea25dcd4b95f382959", "max_issues_repo_licenses": ["CECILL-B"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-02-21T10:46:38.000Z", "max_issues_repo_issues_event_max_datetime": "2017-10-20T17:03:14.000Z", "max_forks_repo_path": "code_2D/couplage_2D/ALOHA2D_F90/libaloha2D/aloha2d_plasma.f90", "max_forks_repo_name": "IRFM/ALOHA", "max_forks_repo_head_hexsha": "e8e7a47a70c7095b339b3dea25dcd4b95f382959", "max_forks_repo_licenses": ["CECILL-B"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-10-05T12:40:02.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-12T08:41:20.000Z", "avg_line_length": 27.1049382716, "max_line_length": 89, "alphanum_fraction": 0.6210430426, "num_tokens": 1609, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947179030095, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6966105699431935}} {"text": "module test_gauss\n use stdlib_kinds, only: dp\n use testdrive, only : new_unittest, unittest_type, error_type, check\n use stdlib_quadrature , only: gauss_legendre, gauss_legendre_lobatto\n\n implicit none\n\n\ncontains\n\n !> Collect all exported unit tests\n subroutine collect_gauss(testsuite)\n !> Collection of tests\n type(unittest_type), allocatable, intent(out) :: testsuite(:)\n\n testsuite = [ &\n new_unittest(\"gauss-analytic\", test_gauss_analytic), &\n new_unittest(\"gauss-5\", test_gauss_5), &\n new_unittest(\"gauss-32\", test_gauss_32), &\n new_unittest(\"gauss-64\", test_gauss_64), &\n new_unittest(\"gauss-lobatto-analytic\", test_gauss_lobatto_analytic), &\n new_unittest(\"gauss-lobatto-5\", test_gauss_lobatto_5), &\n new_unittest(\"gauss-lobatto-32\", test_gauss_lobatto_32), &\n new_unittest(\"gauss-lobatto-64\", test_gauss_lobatto_64) &\n ]\n end subroutine\n\n subroutine test_gauss_analytic(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n integer :: i\n real(dp) :: analytic, numeric\n\n ! test an analytic derivative versus an actual integration\n ! x**2 from -1 to 1\n analytic = 2.0_dp/3.0_dp\n do i=2,6\n block\n real(dp), dimension(i) :: x,w\n call gauss_legendre(x,w)\n numeric = sum(x**2 * w)\n !print *, i, numeric\n call check(error, abs(numeric-analytic) < 2*epsilon(analytic))\n if (allocated(error)) return\n end block\n end do\n\n end subroutine\n\n subroutine test_gauss_5(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n integer :: i\n\n ! test the values of nodes and weights\n i = 5\n block \n real(dp), dimension(i) :: x,w,xref,wref\n call gauss_legendre(x,w)\n xref(1)=-0.90617984593866399_dp\n xref(2)=-0.53846931010568309_dp\n xref(3)=0.0_dp\n xref(4)=0.53846931010568309_dp\n xref(5)=0.90617984593866399_dp\n\n wref(1)=0.23692688505618909_dp\n wref(2)=0.47862867049936647_dp\n wref(3)=0.56888888888888889_dp\n wref(4)=0.47862867049936647_dp\n wref(5)=0.23692688505618909_dp\n\n call check(error, all(abs(x-xref) < 2*epsilon(x(1))))\n if (allocated(error)) return\n call check(error, all(abs(w-wref) < 2*epsilon(w(1))))\n end block\n\n end subroutine\n\n subroutine test_gauss_32(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n integer :: i\n\n i = 32 \n block \n real(dp), dimension(i) :: x,w,xref,wref\n call gauss_legendre(x,w)\n\n xref(1)=-0.99726386184948156_dp\n xref(2)=-0.98561151154526834_dp\n xref(3)=-0.96476225558750643_dp\n xref(4)=-0.93490607593773969_dp\n xref(5)=-0.89632115576605212_dp\n xref(6)=-0.84936761373256997_dp\n xref(7)=-0.79448379596794241_dp\n xref(8)=-0.73218211874028968_dp\n xref(9)=-0.66304426693021520_dp\n xref(10)=-0.58771575724076233_dp\n xref(11)=-0.50689990893222939_dp\n xref(12)=-0.42135127613063535_dp\n xref(13)=-0.33186860228212765_dp\n xref(14)=-0.23928736225213707_dp\n xref(15)=-0.14447196158279649_dp\n xref(16)=-0.048307665687738316_dp\n xref(17)=0.048307665687738316_dp\n xref(18)=0.14447196158279649_dp\n xref(19)=0.23928736225213707_dp\n xref(20)=0.33186860228212765_dp\n xref(21)=0.42135127613063535_dp\n xref(22)=0.50689990893222939_dp\n xref(23)=0.58771575724076233_dp\n xref(24)=0.66304426693021520_dp\n xref(25)=0.73218211874028968_dp\n xref(26)=0.79448379596794241_dp\n xref(27)=0.84936761373256997_dp\n xref(28)=0.89632115576605212_dp\n xref(29)=0.93490607593773969_dp\n xref(30)=0.96476225558750643_dp\n xref(31)=0.98561151154526834_dp\n xref(32)=0.99726386184948156_dp\n\n\n wref(1)=0.0070186100094700966_dp\n wref(2)=0.016274394730905671_dp\n wref(3)=0.025392065309262059_dp\n wref(4)=0.034273862913021433_dp\n wref(5)=0.042835898022226681_dp\n wref(6)=0.050998059262376176_dp\n wref(7)=0.058684093478535547_dp\n wref(8)=0.065822222776361847_dp\n wref(9)=0.072345794108848506_dp\n wref(10)=0.078193895787070306_dp\n wref(11)=0.083311924226946755_dp\n wref(12)=0.087652093004403811_dp\n wref(13)=0.091173878695763885_dp\n wref(14)=0.093844399080804566_dp\n wref(15)=0.095638720079274859_dp\n wref(16)=0.096540088514727801_dp\n wref(17)=0.096540088514727801_dp\n wref(18)=0.095638720079274859_dp\n wref(19)=0.093844399080804566_dp\n wref(20)=0.091173878695763885_dp\n wref(21)=0.087652093004403811_dp\n wref(22)=0.083311924226946755_dp\n wref(23)=0.078193895787070306_dp\n wref(24)=0.072345794108848506_dp\n wref(25)=0.065822222776361847_dp\n wref(26)=0.058684093478535547_dp\n wref(27)=0.050998059262376176_dp\n wref(28)=0.042835898022226681_dp\n wref(29)=0.034273862913021433_dp\n wref(30)=0.025392065309262059_dp\n wref(31)=0.016274394730905671_dp\n wref(32)=0.0070186100094700966_dp\n\n call check(error, all(abs(x-xref) < 2*epsilon(x(1))))\n if (allocated(error)) return\n call check(error, all(abs(w-wref) < 2*epsilon(w(1))))\n end block\n\n end subroutine\n\n subroutine test_gauss_64(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n integer :: i\n\n\n i = 64\n block \n real(dp), dimension(i) :: x,w,xref,wref\n call gauss_legendre(x,w)\n\n\n xref(1)=-0.99930504173577214_dp\n xref(2)=-0.99634011677195528_dp\n xref(3)=-0.99101337147674432_dp\n xref(4)=-0.98333625388462596_dp\n xref(5)=-0.97332682778991096_dp\n xref(6)=-0.96100879965205372_dp\n xref(7)=-0.94641137485840282_dp\n xref(8)=-0.92956917213193958_dp\n xref(9)=-0.91052213707850281_dp\n xref(10)=-0.88931544599511411_dp\n xref(11)=-0.86599939815409282_dp\n xref(12)=-0.84062929625258036_dp\n xref(13)=-0.81326531512279756_dp\n xref(14)=-0.78397235894334141_dp\n xref(15)=-0.75281990726053190_dp\n xref(16)=-0.71988185017161083_dp\n xref(17)=-0.68523631305423324_dp\n xref(18)=-0.64896547125465734_dp\n xref(19)=-0.61115535517239325_dp\n xref(20)=-0.57189564620263403_dp\n xref(21)=-0.53127946401989455_dp\n xref(22)=-0.48940314570705296_dp\n xref(23)=-0.44636601725346409_dp\n xref(24)=-0.40227015796399160_dp\n xref(25)=-0.35722015833766812_dp\n xref(26)=-0.31132287199021096_dp\n xref(27)=-0.26468716220876742_dp\n xref(28)=-0.21742364374000708_dp\n xref(29)=-0.16964442042399282_dp\n xref(30)=-0.12146281929612055_dp\n xref(31)=-0.072993121787799039_dp\n xref(32)=-0.024350292663424433_dp\n xref(33)=0.024350292663424433_dp\n xref(34)=0.072993121787799039_dp\n xref(35)=0.12146281929612055_dp\n xref(36)=0.16964442042399282_dp\n xref(37)=0.21742364374000708_dp\n xref(38)=0.26468716220876742_dp\n xref(39)=0.31132287199021096_dp\n xref(40)=0.35722015833766812_dp\n xref(41)=0.40227015796399160_dp\n xref(42)=0.44636601725346409_dp\n xref(43)=0.48940314570705296_dp\n xref(44)=0.53127946401989455_dp\n xref(45)=0.57189564620263403_dp\n xref(46)=0.61115535517239325_dp\n xref(47)=0.64896547125465734_dp\n xref(48)=0.68523631305423324_dp\n xref(49)=0.71988185017161083_dp\n xref(50)=0.75281990726053190_dp\n xref(51)=0.78397235894334141_dp\n xref(52)=0.81326531512279756_dp\n xref(53)=0.84062929625258036_dp\n xref(54)=0.86599939815409282_dp\n xref(55)=0.88931544599511411_dp\n xref(56)=0.91052213707850281_dp\n xref(57)=0.92956917213193958_dp\n xref(58)=0.94641137485840282_dp\n xref(59)=0.96100879965205372_dp\n xref(60)=0.97332682778991096_dp\n xref(61)=0.98333625388462596_dp\n xref(62)=0.99101337147674432_dp\n xref(63)=0.99634011677195528_dp\n xref(64)=0.99930504173577214_dp\n\n\n wref(1)=0.0017832807216964329_dp\n wref(2)=0.0041470332605624676_dp\n wref(3)=0.0065044579689783629_dp\n wref(4)=0.0088467598263639477_dp\n wref(5)=0.011168139460131129_dp\n wref(6)=0.013463047896718643_dp\n wref(7)=0.015726030476024719_dp\n wref(8)=0.017951715775697343_dp\n wref(9)=0.020134823153530209_dp\n wref(10)=0.022270173808383254_dp\n wref(11)=0.024352702568710873_dp\n wref(12)=0.026377469715054659_dp\n wref(13)=0.028339672614259483_dp\n wref(14)=0.030234657072402479_dp\n wref(15)=0.032057928354851554_dp\n wref(16)=0.033805161837141609_dp\n wref(17)=0.035472213256882384_dp\n wref(18)=0.037055128540240046_dp\n wref(19)=0.038550153178615629_dp\n wref(20)=0.039953741132720341_dp\n wref(21)=0.041262563242623529_dp\n wref(22)=0.042473515123653589_dp\n wref(23)=0.043583724529323453_dp\n wref(24)=0.044590558163756563_dp\n wref(25)=0.045491627927418144_dp\n wref(26)=0.046284796581314417_dp\n wref(27)=0.046968182816210017_dp\n wref(28)=0.047540165714830309_dp\n wref(29)=0.047999388596458308_dp\n wref(30)=0.048344762234802957_dp\n wref(31)=0.048575467441503427_dp\n wref(32)=0.048690957009139720_dp\n wref(33)=0.048690957009139720_dp\n wref(34)=0.048575467441503427_dp\n wref(35)=0.048344762234802957_dp\n wref(36)=0.047999388596458308_dp\n wref(37)=0.047540165714830309_dp\n wref(38)=0.046968182816210017_dp\n wref(39)=0.046284796581314417_dp\n wref(40)=0.045491627927418144_dp\n wref(41)=0.044590558163756563_dp\n wref(42)=0.043583724529323453_dp\n wref(43)=0.042473515123653589_dp\n wref(44)=0.041262563242623529_dp\n wref(45)=0.039953741132720341_dp\n wref(46)=0.038550153178615629_dp\n wref(47)=0.037055128540240046_dp\n wref(48)=0.035472213256882384_dp\n wref(49)=0.033805161837141609_dp\n wref(50)=0.032057928354851554_dp\n wref(51)=0.030234657072402479_dp\n wref(52)=0.028339672614259483_dp\n wref(53)=0.026377469715054659_dp\n wref(54)=0.024352702568710873_dp\n wref(55)=0.022270173808383254_dp\n wref(56)=0.020134823153530209_dp\n wref(57)=0.017951715775697343_dp\n wref(58)=0.015726030476024719_dp\n wref(59)=0.013463047896718643_dp\n wref(60)=0.011168139460131129_dp\n wref(61)=0.0088467598263639477_dp\n wref(62)=0.0065044579689783629_dp\n wref(63)=0.0041470332605624676_dp\n wref(64)=0.0017832807216964329_dp\n \n call check(error, all(abs(x-xref) < 2*epsilon(x(1))))\n if (allocated(error)) return\n call check(error, all(abs(w-wref) < 2*epsilon(w(1))))\n end block\n\n\n\n end subroutine\n\n subroutine test_gauss_lobatto_analytic(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n integer :: i\n real(dp) :: analytic, numeric\n\n ! test an analytic derivative versus an actual integration\n ! x**2 from -1 to 1\n analytic = 2.0_dp/3.0_dp\n do i=4,6 ! lobatto quadrature is less accurate for low i, so omit checking at i=2,3\n block\n real(dp), dimension(i) :: x,w\n call gauss_legendre_lobatto(x,w)\n numeric = sum(x**2 * w)\n !print *, i, numeric\n call check(error, abs(numeric-analytic) < 2*epsilon(analytic))\n if (allocated(error)) return\n end block\n end do\n\n end subroutine\n\n subroutine test_gauss_lobatto_5(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n integer :: i\n\n\n ! test the values of nodes and weights\n i = 5\n block \n real(dp), dimension(i) :: x,w,xref,wref\n call gauss_legendre_lobatto(x,w)\n\n\n xref(1)=-1.0000000000000000_dp\n xref(2)=-0.65465367070797714_dp\n xref(3)=0.0_dp\n xref(4)=0.65465367070797714_dp\n xref(5)=1.0000000000000000_dp\n\n wref(1)=0.10000000000000000_dp\n wref(2)=0.54444444444444444_dp\n wref(3)=0.71111111111111111_dp\n wref(4)=0.54444444444444444_dp\n wref(5)=0.10000000000000000_dp\n\n\n call check(error, all(abs(x-xref) < 2*epsilon(x(1))))\n if (allocated(error)) return\n call check(error, all(abs(w-wref) < 2*epsilon(w(1))))\n end block\n\n end subroutine\n\n subroutine test_gauss_lobatto_32(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n integer :: i\n\n i = 32 \n block \n real(dp), dimension(i) :: x,w,xref,wref\n call gauss_legendre_lobatto(x,w)\n\n xref(1)=-1.0000000000000000_dp\n xref(2)=-0.99260893397276136_dp\n xref(3)=-0.97529469048270923_dp\n xref(4)=-0.94828483841723238_dp\n xref(5)=-0.91184993906373190_dp\n xref(6)=-0.86635247601267552_dp\n xref(7)=-0.81224473177744234_dp\n xref(8)=-0.75006449393667480_dp\n xref(9)=-0.68042975561555082_dp\n xref(10)=-0.60403258714842113_dp\n xref(11)=-0.52163226288156529_dp\n xref(12)=-0.43404771720184694_dp\n xref(13)=-0.34214940653888149_dp\n xref(14)=-0.24685065885020530_dp\n xref(15)=-0.14909859681364749_dp\n xref(16)=-0.049864725046593252_dp\n xref(17)=0.049864725046593252_dp\n xref(18)=0.14909859681364749_dp\n xref(19)=0.24685065885020530_dp\n xref(20)=0.34214940653888149_dp\n xref(21)=0.43404771720184694_dp\n xref(22)=0.52163226288156529_dp\n xref(23)=0.60403258714842113_dp\n xref(24)=0.68042975561555082_dp\n xref(25)=0.75006449393667480_dp\n xref(26)=0.81224473177744234_dp\n xref(27)=0.86635247601267552_dp\n xref(28)=0.91184993906373190_dp\n xref(29)=0.94828483841723238_dp\n xref(30)=0.97529469048270923_dp\n xref(31)=0.99260893397276136_dp\n xref(32)=1.0000000000000000_dp\n\n wref(1)=0.0020161290322580645_dp\n wref(2)=0.012398106501373844_dp\n wref(3)=0.022199552889291965_dp\n wref(4)=0.031775135410915466_dp\n wref(5)=0.041034201586062723_dp\n wref(6)=0.049885271336221207_dp\n wref(7)=0.058240497248055870_dp\n wref(8)=0.066016877257154544_dp\n wref(9)=0.073137139602679033_dp\n wref(10)=0.079530525692106252_dp\n wref(11)=0.085133497949668231_dp\n wref(12)=0.089890372957357833_dp\n wref(13)=0.093753875546813814_dp\n wref(14)=0.096685608948002601_dp\n wref(15)=0.098656436540761777_dp\n wref(16)=0.099646771501276778_dp\n wref(17)=0.099646771501276778_dp\n wref(18)=0.098656436540761777_dp\n wref(19)=0.096685608948002601_dp\n wref(20)=0.093753875546813814_dp\n wref(21)=0.089890372957357833_dp\n wref(22)=0.085133497949668231_dp\n wref(23)=0.079530525692106252_dp\n wref(24)=0.073137139602679033_dp\n wref(25)=0.066016877257154544_dp\n wref(26)=0.058240497248055870_dp\n wref(27)=0.049885271336221207_dp\n wref(28)=0.041034201586062723_dp\n wref(29)=0.031775135410915466_dp\n wref(30)=0.022199552889291965_dp\n wref(31)=0.012398106501373844_dp\n wref(32)=0.0020161290322580645_dp\n \n call check(error, all(abs(x-xref) < 2*epsilon(x(1))))\n if (allocated(error)) return\n call check(error, all(abs(w-wref) < 2*epsilon(w(1))))\n end block\n\n end subroutine\n\n subroutine test_gauss_lobatto_64(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n integer :: i\n\n\n i = 64\n block \n real(dp), dimension(i) :: x,w,xref,wref\n call gauss_legendre_lobatto(x,w)\n\n\n xref(1)=-1.0000000000000000_dp\n xref(2)=-0.99817987150216322_dp\n xref(3)=-0.99390272670305729_dp\n xref(4)=-0.98719267660274024_dp\n xref(5)=-0.97806666283139607_dp\n xref(6)=-0.96654711036909923_dp\n xref(7)=-0.95266223578866292_dp\n xref(8)=-0.93644602747563416_dp\n xref(9)=-0.91793817351028163_dp\n xref(10)=-0.89718396784585004_dp\n xref(11)=-0.87423420065762749_dp\n xref(12)=-0.84914503454299099_dp\n xref(13)=-0.82197786730751705_dp\n xref(14)=-0.79279918182620814_dp\n xref(15)=-0.76168038340811997_dp\n xref(16)=-0.72869762508883694_dp\n xref(17)=-0.69393162129070484_dp\n xref(18)=-0.65746745031297650_dp\n xref(19)=-0.61939434613843155_dp\n xref(20)=-0.57980548006771842_dp\n xref(21)=-0.53879773271680044_dp\n xref(22)=-0.49647145693605775_dp\n xref(23)=-0.45293023223158118_dp\n xref(24)=-0.40828061128985404_dp\n xref(25)=-0.36263185922626182_dp\n xref(26)=-0.31609568619562581_dp\n xref(27)=-0.26878597401917000_dp\n xref(28)=-0.22081849749695350_dp\n xref(29)=-0.17231064108779297_dp\n xref(30)=-0.12338111165002799_dp\n xref(31)=-0.074149647946115919_dp\n xref(32)=-0.024736727621958728_dp\n xref(33)=0.024736727621958728_dp\n xref(34)=0.074149647946115919_dp\n xref(35)=0.12338111165002799_dp\n xref(36)=0.17231064108779297_dp\n xref(37)=0.22081849749695350_dp\n xref(38)=0.26878597401917000_dp\n xref(39)=0.31609568619562581_dp\n xref(40)=0.36263185922626182_dp\n xref(41)=0.40828061128985404_dp\n xref(42)=0.45293023223158118_dp\n xref(43)=0.49647145693605775_dp\n xref(44)=0.53879773271680044_dp\n xref(45)=0.57980548006771842_dp\n xref(46)=0.61939434613843155_dp\n xref(47)=0.65746745031297650_dp\n xref(48)=0.69393162129070484_dp\n xref(49)=0.72869762508883694_dp\n xref(50)=0.76168038340811997_dp\n xref(51)=0.79279918182620814_dp\n xref(52)=0.82197786730751705_dp\n xref(53)=0.84914503454299099_dp\n xref(54)=0.87423420065762749_dp\n xref(55)=0.89718396784585004_dp\n xref(56)=0.91793817351028163_dp\n xref(57)=0.93644602747563416_dp\n xref(58)=0.95266223578866292_dp\n xref(59)=0.96654711036909923_dp\n xref(60)=0.97806666283139607_dp\n xref(61)=0.98719267660274024_dp\n xref(62)=0.99390272670305729_dp\n xref(63)=0.99817987150216322_dp\n xref(64)=1.0000000000000000_dp\n\n wref(1)=0.00049603174603174603_dp\n wref(2)=0.0030560082449124904_dp\n wref(3)=0.0054960162038171569_dp\n wref(4)=0.0079212897900466340_dp\n wref(5)=0.010327002366815328_dp\n wref(6)=0.012707399197454735_dp\n wref(7)=0.015056683987961443_dp\n wref(8)=0.017369116384542182_dp\n wref(9)=0.019639040723241718_dp\n wref(10)=0.021860903511518060_dp\n wref(11)=0.024029268144023827_dp\n wref(12)=0.026138828614338438_dp\n wref(13)=0.028184422665848517_dp\n wref(14)=0.030161044499089451_dp\n wref(15)=0.032063857057727025_dp\n wref(16)=0.033888203884125398_dp\n wref(17)=0.035629620524489486_dp\n wref(18)=0.037283845459801173_dp\n wref(19)=0.038846830537807737_dp\n wref(20)=0.040314750881560237_dp\n wref(21)=0.041684014250801952_dp\n wref(22)=0.042951269833601819_dp\n wref(23)=0.044113416446892471_dp\n wref(24)=0.045167610125947702_dp\n wref(25)=0.046111271084289059_dp\n wref(26)=0.046942090027028316_dp\n wref(27)=0.047658033802220637_dp\n wref(28)=0.048257350376414549_dp\n wref(29)=0.048738573122233185_dp\n wref(30)=0.049100524407501308_dp\n wref(31)=0.049342318477139574_dp\n wref(32)=0.049463363620776646_dp\n wref(33)=0.049463363620776646_dp\n wref(34)=0.049342318477139574_dp\n wref(35)=0.049100524407501308_dp\n wref(36)=0.048738573122233185_dp\n wref(37)=0.048257350376414549_dp\n wref(38)=0.047658033802220637_dp\n wref(39)=0.046942090027028316_dp\n wref(40)=0.046111271084289059_dp\n wref(41)=0.045167610125947702_dp\n wref(42)=0.044113416446892471_dp\n wref(43)=0.042951269833601819_dp\n wref(44)=0.041684014250801952_dp\n wref(45)=0.040314750881560237_dp\n wref(46)=0.038846830537807737_dp\n wref(47)=0.037283845459801173_dp\n wref(48)=0.035629620524489486_dp\n wref(49)=0.033888203884125398_dp\n wref(50)=0.032063857057727025_dp\n wref(51)=0.030161044499089451_dp\n wref(52)=0.028184422665848517_dp\n wref(53)=0.026138828614338438_dp\n wref(54)=0.024029268144023827_dp\n wref(55)=0.021860903511518060_dp\n wref(56)=0.019639040723241718_dp\n wref(57)=0.017369116384542182_dp\n wref(58)=0.015056683987961443_dp\n wref(59)=0.012707399197454735_dp\n wref(60)=0.010327002366815328_dp\n wref(61)=0.0079212897900466340_dp\n wref(62)=0.0054960162038171569_dp\n wref(63)=0.0030560082449124904_dp\n wref(64)=0.00049603174603174603_dp\n \n call check(error, all(abs(x-xref) < 2*epsilon(x(1))))\n if (allocated(error)) return\n call check(error, all(abs(w-wref) < 2*epsilon(w(1))))\n end block\n\n end subroutine\n\nend module\n\n\nprogram tester\n use, intrinsic :: iso_fortran_env, only : error_unit\n use testdrive, only : run_testsuite, new_testsuite, testsuite_type\n use test_gauss, only : collect_gauss\n implicit none\n integer :: stat, is\n type(testsuite_type), allocatable :: testsuites(:)\n character(len=*), parameter :: fmt = '(\"#\", *(1x, a))'\n\n stat = 0\n\n testsuites = [ &\n new_testsuite(\"gauss\", collect_gauss) &\n ]\n\n do is = 1, size(testsuites)\n write(error_unit, fmt) \"Testing:\", testsuites(is)%name\n call run_testsuite(testsuites(is)%collect, error_unit, stat)\n end do\n\n if (stat > 0) then\n write(error_unit, '(i0, 1x, a)') stat, \"test(s) failed!\"\n error stop\n end if\nend program\n", "meta": {"hexsha": "8fce773e68f948121120610d638cb0b421fb0bf4", "size": 24261, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/quadrature/test_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/tests/quadrature/test_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/tests/quadrature/test_gauss.f90", "max_forks_repo_name": "seanwallawalla-forks/stdlib", "max_forks_repo_head_hexsha": "f58da3b1141a0bb0ce741aa6b74f636a1376706d", "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": 38.026645768, "max_line_length": 91, "alphanum_fraction": 0.6000989242, "num_tokens": 8209, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037343628702, "lm_q2_score": 0.7520125848754472, "lm_q1q2_score": 0.6965920656580016}} {"text": "!\tMultinomial covariance matrix.\r\n!\tdensity is vector of probabilities.\r\n!\tmeanth is vector of means.\r\n!\tquadpoint is array of weights.\r\nfunction mcovth(density,meanth,quadpoint)\r\nimplicit none\r\ninterface\r\n!\r\n\tsubroutine makesym(matrix)\r\n!\tSymmetrize n by n matrix based on lower triangle.\r\n\t\treal(kind=8),intent(inout)::matrix(:,:)\r\n\tend subroutine makesym\r\nend interface\r\nreal(kind=8),intent(in)::density(:),meanth(:),quadpoint(:,:)\r\nreal(kind=8)::mcovth(size(meanth),size(meanth))\r\n!\tCount columns, quadrature points, and rows.\r\ninteger::col,quad,row\r\nmcovth=0.0_8\r\nif(size(density)>1)then \r\n do row=1,size(meanth)\r\n do col=1,row\r\n do quad=1,size(density)\r\n mcovth(row,col)=mcovth(row,col)+(quadpoint(row,quad)-meanth(row))*&\r\n (quadpoint(col,quad)-meanth(col))*density(quad)\r\n end do\r\n end do\r\n end do\r\n call makesym(mcovth)\r\nend if\r\n\r\nreturn\r\nend function mcovth\r\n", "meta": {"hexsha": "73258932694028d5b0887fcb6b9f0b0d1a65d29b", "size": 948, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Source/mcovth.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/mcovth.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/mcovth.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": 28.7272727273, "max_line_length": 84, "alphanum_fraction": 0.6571729958, "num_tokens": 267, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037302939516, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6965920574498896}} {"text": "FUNCTION IMF(mass)\n\n !define IMFs (dn/dM)\n\n !the following is just a fast-and-loose way to pass things around:\n !if the imf_type var is +10 then we calculate dn/dm*m\n !if the imf_type var is <10 then we calculate dn/dm\n \n USE sps_vars\n IMPLICIT NONE\n\n REAL(SP), DIMENSION(:), INTENT(in) :: mass\n REAL(SP), DIMENSION(SIZE(mass)) :: imf\n INTEGER :: i,n\n REAL(SP) :: imfcu\n\n !---------------------------------------------------------------!\n !---------------------------------------------------------------!\n \n imf = 0.0\n\n !Salpeter (1955) IMF\n IF (MOD(imf_type,10).EQ.0) THEN\n imf = mass**(-salp_ind) \n IF (imf_type.EQ.10) imf = mass*imf\n ENDIF\n \n !Chabrier (2003) IMF\n IF (MOD(imf_type,10).EQ.1) THEN\n DO i=1,size(mass)\n IF (mass(i).LT.1) THEN\n imf(i) = exp(-(log10(mass(i))-log10(chab_mc))**2&\n /2/chab_sigma2)\n ELSE\n imf(i) = exp(-log10(chab_mc)**2/2./chab_sigma2)*&\n mass(i)**(-chab_ind)\n ENDIF\n ENDDO\n !convert from dn/dlnM to dn/dM\n imf = imf/mass\n IF (imf_type.EQ.11) imf = mass*imf\n ENDIF\n \n !Kroupa (2001) IMF\n IF (MOD(imf_type,10).EQ.2) THEN\n DO i=1,size(mass)\n IF (mass(i).GE.0.08.AND.mass(i).LT.0.5) &\n imf(i) = mass(i)**(-imf_alpha(1))\n IF (mass(i).GE.0.5.AND.mass(i).LT.1.0) &\n imf(i) = 0.5**(-imf_alpha(1)+imf_alpha(2))*&\n mass(i)**(-imf_alpha(2))\n IF (mass(i).GE.1.0) &\n imf(i) = 0.5**(-imf_alpha(1)+imf_alpha(2))*&\n mass(i)**(-imf_alpha(3))\n ENDDO\n IF (imf_type.EQ.12) imf = mass*imf\n ENDIF\n \n !van Dokkum (2008) IMF\n IF (MOD(imf_type,10).EQ.3) THEN\n DO i=1,size(mass)\n IF (mass(i).LE.vd_nc*imf_vdmc) THEN\n imf(i) = vd_al*(0.5*vd_nc*imf_vdmc)**(-vd_ind)*&\n exp(-(log10(mass(i))-log10(imf_vdmc))*&\n (log10(mass(i))-log10(imf_vdmc))/2./vd_sigma2)\n ELSE\n imf(i) = vd_ah*mass(i)**(-vd_ind)\n ENDIF\n ENDDO\n !convert from dn/dlnM to dn/dM\n imf = imf/mass\n IF (imf_type.EQ.13) imf = mass*imf\n ENDIF\n \n !Dave (2008) IMF\n IF (MOD(imf_type,10).EQ.4) THEN\n DO i=1,size(mass)\n IF (mass(i).GE.0.08.AND.mass(i).LT.imf_mdave) &\n imf(i) = mass(i)**(-imf_alpha(1))\n IF (mass(i).GE.imf_mdave) &\n imf(i) = imf_mdave**(-imf_alpha(1)+imf_alpha(2))*&\n mass(i)**(-imf_alpha(2))\n ENDDO\n IF (imf_type.EQ.14) imf = mass*imf\n ENDIF\n\n !user-defined IMF\n IF (MOD(imf_type,10).EQ.5) THEN\n DO i=1,size(mass)\n IF (mass(i).GE.imf_user_alpha(1,1).AND.&\n mass(i).LT.imf_user_alpha(2,1)) &\n imf(i) = mass(i)**(-imf_user_alpha(3,1))\n imfcu = 1.0\n DO n=2,n_user_imf\n IF (mass(i).GE.imf_user_alpha(1,n).AND.&\n mass(i).LT.imf_user_alpha(2,n)) &\n imf(i) = mass(i)**(-imf_user_alpha(3,n))*&\n imf_user_alpha(1,n)**(-imf_user_alpha(3,n-1)+&\n imf_user_alpha(3,n))*imfcu\n imfcu = imfcu*imf_user_alpha(1,n)**(-imf_user_alpha(3,n-1)+&\n imf_user_alpha(3,n))\n ENDDO\n ENDDO\n IF (imf_type.EQ.15) imf = mass*imf\n ENDIF\n\nEND FUNCTION IMF\n", "meta": {"hexsha": "f6cc399400383ecde3708a32d5ffb2d86c0b2603", "size": 3244, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/imf.f90", "max_stars_repo_name": "christopherlovell/fsps", "max_stars_repo_head_hexsha": "1c09a47d7b0fb15a7f245ee3e9b2a7c54122ffdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 55, "max_stars_repo_stars_event_min_datetime": "2015-04-17T18:36:36.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-15T01:47:28.000Z", "max_issues_repo_path": "src/imf.f90", "max_issues_repo_name": "christopherlovell/fsps", "max_issues_repo_head_hexsha": "1c09a47d7b0fb15a7f245ee3e9b2a7c54122ffdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 27, "max_issues_repo_issues_event_min_datetime": "2015-11-04T03:19:44.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-15T22:03:19.000Z", "max_forks_repo_path": "src/imf.f90", "max_forks_repo_name": "christopherlovell/fsps", "max_forks_repo_head_hexsha": "1c09a47d7b0fb15a7f245ee3e9b2a7c54122ffdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 43, "max_forks_repo_forks_event_min_datetime": "2015-04-29T09:24:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T19:31:46.000Z", "avg_line_length": 30.037037037, "max_line_length": 71, "alphanum_fraction": 0.5089395808, "num_tokens": 1198, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037221561136, "lm_q2_score": 0.7520125848754472, "lm_q1q2_score": 0.696592056478367}} {"text": " SUBROUTINE SB03QY( JOB, TRANA, LYAPUN, N, T, LDT, U, LDU, X, LDX,\n $ SEP, THNORM, IWORK, DWORK, LDWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To estimate the separation between the matrices op(A) and -op(A)',\nC\nC sep(op(A),-op(A)') = min norm(op(A)'*X + X*op(A))/norm(X)\nC = 1 / norm(inv(Omega))\nC\nC and/or the 1-norm of Theta, where op(A) = A or A' (A**T), and\nC Omega and Theta are linear operators associated to the real\nC continuous-time Lyapunov matrix equation\nC\nC op(A)'*X + X*op(A) = C,\nC\nC defined by\nC\nC Omega(W) = op(A)'*W + W*op(A),\nC Theta(W) = inv(Omega(op(W)'*X + X*op(W))).\nC\nC The 1-norm condition estimators are used.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC JOB CHARACTER*1\nC Specifies the computation to be performed, as follows:\nC = 'S': Compute the separation only;\nC = 'T': Compute the norm of Theta only;\nC = 'B': Compute both the separation and the norm of Theta.\nC\nC TRANA CHARACTER*1\nC Specifies the form of op(A) to be used, as follows:\nC = 'N': op(A) = A (No transpose);\nC = 'T': op(A) = A**T (Transpose);\nC = 'C': op(A) = A**T (Conjugate transpose = Transpose).\nC\nC LYAPUN CHARACTER*1\nC Specifies whether or not the original Lyapunov equations\nC should be solved, as follows:\nC = 'O': Solve the original Lyapunov equations, updating\nC the right-hand sides and solutions with the\nC matrix U, e.g., X <-- U'*X*U;\nC = 'R': Solve reduced Lyapunov equations only, without\nC updating the right-hand sides and solutions.\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The order of the matrices A and X. N >= 0.\nC\nC T (input) DOUBLE PRECISION array, dimension (LDT,N)\nC The leading N-by-N upper Hessenberg part of this array\nC must contain the upper quasi-triangular matrix T in Schur\nC canonical form from a Schur factorization of A.\nC\nC LDT INTEGER\nC The leading dimension of array T. LDT >= MAX(1,N).\nC\nC U (input) DOUBLE PRECISION array, dimension (LDU,N)\nC The leading N-by-N part of this array must contain the\nC orthogonal matrix U from a real Schur factorization of A.\nC If LYAPUN = 'R', the array U is not referenced.\nC\nC LDU INTEGER\nC The leading dimension of array U.\nC LDU >= 1, if LYAPUN = 'R';\nC LDU >= MAX(1,N), if LYAPUN = 'O'.\nC\nC X (input) DOUBLE PRECISION array, dimension (LDX,N)\nC The leading N-by-N part of this array must contain the\nC solution matrix X of the Lyapunov equation (reduced\nC Lyapunov equation if LYAPUN = 'R').\nC If JOB = 'S', the array X is not referenced.\nC\nC LDX INTEGER\nC The leading dimension of array X.\nC LDX >= 1, if JOB = 'S';\nC LDX >= MAX(1,N), if JOB = 'T' or 'B'.\nC\nC SEP (output) DOUBLE PRECISION\nC If JOB = 'S' or JOB = 'B', and INFO >= 0, SEP contains the\nC estimated separation of the matrices op(A) and -op(A)'.\nC If JOB = 'T' or N = 0, SEP is not referenced.\nC\nC THNORM (output) DOUBLE PRECISION\nC If JOB = 'T' or JOB = 'B', and INFO >= 0, THNORM contains\nC the estimated 1-norm of operator Theta.\nC If JOB = 'S' or N = 0, THNORM is not referenced.\nC\nC Workspace\nC\nC IWORK INTEGER array, dimension (N*N)\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC\nC LDWORK INTEGER\nC The length of the array DWORK. LDWORK >= 2*N*N.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value;\nC = N+1: if the matrices T and -T' have common or very\nC close eigenvalues; perturbed values were used to\nC solve Lyapunov equations (but the matrix T is\nC unchanged).\nC\nC METHOD\nC\nC SEP is defined as the separation of op(A) and -op(A)':\nC\nC sep( op(A), -op(A)' ) = sigma_min( K )\nC\nC where sigma_min(K) is the smallest singular value of the\nC N*N-by-N*N matrix\nC\nC K = kprod( I(N), op(A)' ) + kprod( op(A)', I(N) ).\nC\nC I(N) is an N-by-N identity matrix, and kprod denotes the Kronecker\nC product. The routine estimates sigma_min(K) by the reciprocal of\nC an estimate of the 1-norm of inverse(K), computed as suggested in\nC [1]. This involves the solution of several continuous-time\nC Lyapunov equations, either direct or transposed. The true\nC reciprocal 1-norm of inverse(K) cannot differ from sigma_min(K) by\nC more than a factor of N.\nC The 1-norm of Theta is estimated similarly.\nC\nC REFERENCES\nC\nC [1] Higham, N.J.\nC FORTRAN codes for estimating the one-norm of a real or\nC complex matrix, with applications to condition estimation.\nC ACM Trans. Math. Softw., 14, pp. 381-396, 1988.\nC\nC NUMERICAL ASPECTS\nC 3\nC The algorithm requires 0(N ) operations.\nC\nC FURTHER COMMENTS\nC\nC When SEP is zero, the routine returns immediately, with THNORM\nC (if requested) not set. In this case, the equation is singular.\nC The option LYAPUN = 'R' may occasionally produce slightly worse\nC or better estimates, and it is much faster than the option 'O'.\nC\nC CONTRIBUTOR\nC\nC V. Sima, Research Institute for Informatics, Bucharest, Romania,\nC Oct. 1998. Partly based on DGLSVX (and then SB03QD) by P. Petkov,\nC Tech. University of Sofia, March 1998 (and December 1998).\nC\nC REVISIONS\nC\nC February 13, 1999, V. Sima, Katholieke Univ. Leuven, Belgium.\nC V. Sima, Research Institute for Informatics, Bucharest, Oct. 2004,\nC May 2020.\nC\nC KEYWORDS\nC\nC Lyapunov equation, orthogonal transformation, real Schur form.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, ONE, HALF\n PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0, HALF = 0.5D+0 )\nC ..\nC .. Scalar Arguments ..\n CHARACTER JOB, LYAPUN, TRANA\n INTEGER INFO, LDT, LDU, LDWORK, LDX, N\n DOUBLE PRECISION SEP, THNORM\nC ..\nC .. Array Arguments ..\n INTEGER IWORK( * )\n DOUBLE PRECISION DWORK( * ), T( LDT, * ), U( LDU, * ),\n $ X( LDX, * )\nC ..\nC .. Local Scalars ..\n LOGICAL NOTRNA, UPDATE, WANTS, WANTT\n CHARACTER TRANAT, UPLO\n INTEGER INFO2, ITMP, KASE, NN\n DOUBLE PRECISION BIGNUM, EST, SCALE\nC ..\nC .. Local Arrays ..\n INTEGER ISAVE( 3 )\nC ..\nC .. External Functions ..\n LOGICAL LSAME\n DOUBLE PRECISION DLAMCH, DLANSY\n EXTERNAL DLAMCH, DLANSY, LSAME\nC ..\nC .. External Subroutines ..\n EXTERNAL DLACN2, DLACPY, DSCAL, DSYR2K, MA02ED, MB01RU,\n $ SB03MY, XERBLA\nC ..\nC .. Intrinsic Functions ..\n INTRINSIC MAX\nC ..\nC .. Executable Statements ..\nC\nC Decode and Test input parameters.\nC\n WANTS = LSAME( JOB, 'S' )\n WANTT = LSAME( JOB, 'T' )\n NOTRNA = LSAME( TRANA, 'N' )\n UPDATE = LSAME( LYAPUN, 'O' )\nC\n NN = N*N\n INFO = 0\n IF( .NOT. ( WANTS .OR. WANTT .OR. LSAME( JOB, 'B' ) ) ) THEN\n INFO = -1\n ELSE IF( .NOT.( NOTRNA .OR. LSAME( TRANA, 'T' ) .OR.\n $ LSAME( TRANA, 'C' ) ) ) THEN\n INFO = -2\n ELSE IF( .NOT.( UPDATE .OR. LSAME( LYAPUN, 'R' ) ) ) THEN\n INFO = -3\n ELSE IF( N.LT.0 ) THEN\n INFO = -4\n ELSE IF( LDT.LT.MAX( 1, N ) ) THEN\n INFO = -6\n ELSE IF( LDU.LT.1 .OR. ( UPDATE .AND. LDU.LT.N ) ) THEN\n INFO = -8\n ELSE IF( LDX.LT.1 .OR. ( .NOT.WANTS .AND. LDX.LT.N ) ) THEN\n INFO = -10\n ELSE IF( LDWORK.LT.2*NN ) THEN\n INFO = -15\n END IF\nC\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'SB03QY', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF( N.EQ.0 )\n $ RETURN\nC\n ITMP = NN + 1\nC\n IF( NOTRNA ) THEN\n TRANAT = 'T'\n ELSE\n TRANAT = 'N'\n END IF\nC\n IF( .NOT.WANTT ) THEN\nC\nC Estimate sep(op(A),-op(A)').\nC Workspace: 2*N*N.\nC\n KASE = 0\nC\nC REPEAT\n 10 CONTINUE\n CALL DLACN2( NN, DWORK( ITMP ), DWORK, IWORK, EST, KASE, ISAVE\n $ )\n IF( KASE.NE.0 ) THEN\nC\nC Select the triangular part of symmetric matrix to be used.\nC\n IF( DLANSY( '1-norm', 'Upper', N, DWORK, N, DWORK( ITMP ) )\n $ .GE.\n $ DLANSY( '1-norm', 'Lower', N, DWORK, N, DWORK( ITMP ) )\n $ ) THEN\n UPLO = 'U'\n ELSE\n UPLO = 'L'\n END IF\nC\n IF( UPDATE ) THEN\nC\nC Transform the right-hand side: RHS := U'*RHS*U.\nC\n CALL MB01RU( UPLO, 'Transpose', N, N, ZERO, ONE, DWORK,\n $ N, U, LDU, DWORK, N, DWORK( ITMP ), NN,\n $ INFO2 )\n CALL DSCAL( N, HALF, DWORK, N+1 )\n END IF\n CALL MA02ED( UPLO, N, DWORK, N )\nC\n IF( KASE.EQ.1 ) THEN\nC\nC Solve op(T)'*Y + Y*op(T) = scale*RHS.\nC\n CALL SB03MY( TRANA, N, T, LDT, DWORK, N, SCALE, INFO2 )\n ELSE\nC\nC Solve op(T)*W + W*op(T)' = scale*RHS.\nC\n CALL SB03MY( TRANAT, N, T, LDT, DWORK, N, SCALE, INFO2 )\n END IF\nC\n IF( INFO2.GT.0 )\n $ INFO = N + 1\nC\n IF( UPDATE ) THEN\nC\nC Transform back to obtain the solution: Z := U*Z*U', with\nC Z = Y or Z = W.\nC\n CALL MB01RU( UPLO, 'No transpose', N, N, ZERO, ONE,\n $ DWORK, N, U, LDU, DWORK, N, DWORK( ITMP ),\n $ NN, INFO2 )\n CALL DSCAL( N, HALF, DWORK, N+1 )\nC\nC Fill in the remaining triangle of the symmetric matrix.\nC\n CALL MA02ED( UPLO, N, DWORK, N )\n END IF\nC\n GO TO 10\n END IF\nC UNTIL KASE = 0\nC\n IF( EST.GT.SCALE ) THEN\n SEP = SCALE / EST\n ELSE\n BIGNUM = ONE / DLAMCH( 'Safe minimum' )\n IF( SCALE.LT.EST*BIGNUM ) THEN\n SEP = SCALE / EST\n ELSE\n SEP = BIGNUM\n END IF\n END IF\nC\nC Return if the equation is singular.\nC\n IF( SEP.EQ.ZERO )\n $ RETURN\n END IF\nC\n IF( .NOT.WANTS ) THEN\nC\nC Estimate norm(Theta).\nC Workspace: 2*N*N.\nC\n KASE = 0\nC\nC REPEAT\n 20 CONTINUE\n CALL DLACN2( NN, DWORK( ITMP ), DWORK, IWORK, EST, KASE, ISAVE\n $ )\n IF( KASE.NE.0 ) THEN\nC\nC Select the triangular part of symmetric matrix to be used.\nC\n IF( DLANSY( '1-norm', 'Upper', N, DWORK, N, DWORK( ITMP ) )\n $ .GE.\n $ DLANSY( '1-norm', 'Lower', N, DWORK, N, DWORK( ITMP ) )\n $ ) THEN\n UPLO = 'U'\n ELSE\n UPLO = 'L'\n END IF\nC\nC Fill in the remaining triangle of the symmetric matrix.\nC\n CALL MA02ED( UPLO, N, DWORK, N )\nC\nC Compute RHS = op(W)'*X + X*op(W).\nC\n CALL DSYR2K( UPLO, TRANAT, N, N, ONE, DWORK, N, X, LDX,\n $ ZERO, DWORK( ITMP ), N )\n CALL DLACPY( UPLO, N, N, DWORK( ITMP ), N, DWORK, N )\nC\n IF( UPDATE ) THEN\nC\nC Transform the right-hand side: RHS := U'*RHS*U.\nC\n CALL MB01RU( UPLO, 'Transpose', N, N, ZERO, ONE, DWORK,\n $ N, U, LDU, DWORK, N, DWORK( ITMP ), NN,\n $ INFO2 )\n CALL DSCAL( N, HALF, DWORK, N+1 )\n END IF\n CALL MA02ED( UPLO, N, DWORK, N )\nC\n IF( KASE.EQ.1 ) THEN\nC\nC Solve op(T)'*Y + Y*op(T) = scale*RHS.\nC\n CALL SB03MY( TRANA, N, T, LDT, DWORK, N, SCALE, INFO2 )\n ELSE\nC\nC Solve op(T)*W + W*op(T)' = scale*RHS.\nC\n CALL SB03MY( TRANAT, N, T, LDT, DWORK, N, SCALE, INFO2 )\n END IF\nC\n IF( INFO2.GT.0 )\n $ INFO = N + 1\nC\n IF( UPDATE ) THEN\nC\nC Transform back to obtain the solution: Z := U*Z*U', with\nC Z = Y or Z = W.\nC\n CALL MB01RU( UPLO, 'No transpose', N, N, ZERO, ONE,\n $ DWORK, N, U, LDU, DWORK, N, DWORK( ITMP ),\n $ NN, INFO2 )\n CALL DSCAL( N, HALF, DWORK, N+1 )\nC\nC Fill in the remaining triangle of the symmetric matrix.\nC\n CALL MA02ED( UPLO, N, DWORK, N )\n END IF\nC\n GO TO 20\n END IF\nC UNTIL KASE = 0\nC\n IF( EST.LT.SCALE ) THEN\n THNORM = EST / SCALE\n ELSE\n BIGNUM = ONE / DLAMCH( 'Safe minimum' )\n IF( EST.LT.SCALE*BIGNUM ) THEN\n THNORM = EST / SCALE\n ELSE\n THNORM = BIGNUM\n END IF\n END IF\n END IF\nC\n RETURN\nC *** Last line of SB03QY ***\n END\n", "meta": {"hexsha": "9f81b5d10622f4bb736fc339e0850917e479da90", "size": 13752, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/SB03QY.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/SB03QY.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/SB03QY.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 31.5412844037, "max_line_length": 72, "alphanum_fraction": 0.505744619, "num_tokens": 4252, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037302939515, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6965920523016556}} {"text": "FUNCTION REXPU() RESULT(fn_val)\r\n!\r\n! Random-number generator for the exponential distribution\r\n! Algorithm EA from J. H. Ahrens and U. Dieter,\r\n! Communications of the ACM, 31 (1988) 1330--1337.\r\n! Coded by K. G. Hamilton, December 1996, with corrections.\r\n!\r\n\r\nIMPLICIT NONE\r\nREAL :: fn_val\r\n\r\nREAL, PARAMETER :: alog2 = 0.6931471805599453, a = 5.7133631526454228, &\r\n b = 3.4142135623730950, c = -1.6734053240284925, &\r\n p = 0.9802581434685472, aa = 5.6005707569738080, &\r\n bb = 3.3468106480569850, hh = 0.0026106723602095, &\r\n dd = 0.0857864376269050\r\nREAL :: g, u, up, y\r\n!\r\n! Comment out the following lines if your RNG can never return 0.0\r\nDO\r\n call random_number(u)\r\n if (u > 0.0) EXIT ! Zero-protector\r\nEND DO\r\n\r\ng = c\r\nDO\r\n u = u + u\r\n if (u >= 1.0) EXIT\r\n g = g + alog2\r\nEND DO\r\n\r\nu = u - 1.0\r\nif (u <= p) THEN\r\n fn_val = g + aa/(bb-u)\r\n return\r\nEND IF\r\nDO\r\n call random_number(u)\r\n y = a/(b-u)\r\n call random_number(up)\r\n if ((up*hh + dd)*(b-u)**2 <= exp(-(y+c))) EXIT\r\nEND DO\r\n\r\nfn_val = g + y\r\n\r\nreturn\r\nend FUNCTION REXPU\r\n\r\n\r\nFUNCTION REXPS() RESULT(fn_val)\r\n!\r\n! Random-number generator for the exponential distribution\r\n! Algorithm EA from J. H. Ahrens and U. Dieter,\r\n! Communications of the ACM, 31 (1988) 1330--1337.\r\n! Coded by K. G. Hamilton, December 1996, with corrections.\r\n!\r\nIMPLICIT NONE\r\nREAL :: fn_val\r\n\r\nREAL, PARAMETER :: alog2 = 0.6931471805599453, a = 5.7133631526454228, &\r\n b = 3.4142135623730950, c = -1.6734053240284925, &\r\n p = 0.9802581434685472, aa = 5.6005707569738080, &\r\n bb = 3.3468106480569850, hh = 0.0026106723602095, &\r\n dd = 0.0857864376269050\r\nREAL :: g, u, up, y\r\n!\r\n! Comment out the following lines if your RNG can never return 0.0\r\nDO\r\n call random_number(u)\r\n if (u > 0.0) EXIT ! Zero-protector\r\nEND DO\r\n\r\ng = c\r\nu = u + u\r\ndo while (u < 1.0)\r\n g = g + alog2\r\n u = u + u\r\nend do\r\nu = u - 1.0\r\nif (u <= p) then\r\n fn_val = g + aa/(bb-u)\r\n return\r\nend if\r\n\r\ndo\r\n call random_number(u)\r\n y = a/(b-u)\r\n call random_number(up)\r\n if ((up*hh + dd)*(b-u)**2 <= exp(-(y+c))) then\r\n fn_val = g + y\r\n return\r\n end if\r\nend do\r\n\r\nRETURN\r\nend FUNCTION REXPS\r\n", "meta": {"hexsha": "00caa805b25bb1dfdb6c922c027aba7021cb121c", "size": 2393, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/toms780.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/toms780.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/toms780.f90", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 24.6701030928, "max_line_length": 76, "alphanum_fraction": 0.5587129127, "num_tokens": 835, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037343628703, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6965920502132995}} {"text": "module consts\n\n ! global constants and variables \n\n use preci, wp => dp\n implicit none\n\n real, parameter :: pi = 3.14159265358979323846\n real, parameter :: kb = 1.38064852e-23 ! Boltzmann constant\n real, parameter :: avog = 6.023e23 ! Avogadro constant\n real, parameter :: mw_air = 29.2e-3 ! molecular weight of air\n\n real, parameter :: mw_par = 79.866e-3 ! molecular weight of the particle material\n real, parameter :: den_par = 4230.0 ! density of the particle material\n\n real, parameter :: temp = 1200.0 ! temperature\n real, parameter :: visc = 1.716e-5 * ((temp/273.15)**(2.0/3.0)) ! viscosity\n real, parameter :: pres = 101325.0 ! pressure\n real, parameter :: mfp_air = visc/pres * sqrt(pi*kb*temp/(2.0*mw_air/avog)) ! mean free path of air\n\n real, parameter :: beta_star = 8.0*kb*temp/3.0/visc \n ! \u00df* for non-dimensionalization (ref: Friedlander 2000, pg192, eqn7.18)\n integer, parameter :: regime = 0 ! regime option - default: Fuchs-Sutugin\n\n real, parameter :: dp1 = 0.4e-9 ! initial particle monomer diameter\n real, parameter :: n_0_dp1 = 1.0e20 ! initial monomer number concentration #/m3\n integer, parameter :: N_ds = 3000 ! ____number of concerned discrete sizes\n\n real, parameter :: tau = 2.0/beta_star/n_0_dp1 ! default value = 2.0837e-5 \n ! t* for non-dimensionalization, \u00df* instead of K !! (ref: Friedlander 2000, pg194, eqn7.24)\n\n\n ! total time is set according to table 1.1 (ref: Friedlander 2000, pg8) \n ! n_0_dp1*t_1_10 = 1.2e16\n ! if (n_0_dp1 == 1.0e20) {\n ! t_1_10 = 1.2e16/n_0_dp1 ! = 1.2e-4\n ! }\n\n real, parameter :: n_star_min = 1.0/n_0_dp1 ! pyhsically miminimum total number concentration, 1 #/m3, i.e. 1e-20 after non-dimensionalization\n\nend module consts\n", "meta": {"hexsha": "676103dd9a90f011b47da07aab8b526fdb95f6f3", "size": 1770, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/f90/consts.f90", "max_stars_repo_name": "b1tank/coag", "max_stars_repo_head_hexsha": "c9698b622b40de548d16f6f1e84c7b6b1715f997", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/f90/consts.f90", "max_issues_repo_name": "b1tank/coag", "max_issues_repo_head_hexsha": "c9698b622b40de548d16f6f1e84c7b6b1715f997", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/f90/consts.f90", "max_forks_repo_name": "b1tank/coag", "max_forks_repo_head_hexsha": "c9698b622b40de548d16f6f1e84c7b6b1715f997", "max_forks_repo_licenses": ["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.1428571429, "max_line_length": 146, "alphanum_fraction": 0.6683615819, "num_tokens": 605, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037302939515, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6965920471534215}} {"text": "!\n! Example illustrating the use of the frand123 Fortran interface for the\n! generation of double precision normally distributed random numbers.\n! The example estimates the excess kurtosis of the underlying normal\n! distribution with expectation mu = 0.7 and variance sigma = 1.6\n!\n\nprogram kurtosisDouble\n use, intrinsic :: iso_c_binding, only: c_double\n use omp_lib, only: omp_get_wtime\n use frand123, only: frand123State_t, frand123Init, frand123NormDouble\n implicit none\n\n ! integer kind for large integers\n integer, parameter :: ik = selected_int_kind( 10 )\n\n ! number of draws used to estimate the excess kurtosis\n integer( kind = ik ), parameter :: numberOfSamples = 1000 * 1000 * 100\n\n ! expectation and variance of the normal distribution to draw from\n real( kind = c_double ), parameter :: mu = real( 0.7, c_double )\n real( kind = c_double ), parameter :: sigma = real( 1.6, c_double )\n\n ! state for frand123\n type( frand123State_t ) :: state\n\n ! timing variables\n real( kind = c_double ) :: startTime, endTime\n\n ! result variables\n real( kind = c_double ) :: varScalar, varTwo, var1000\n\n ! initialize state\n call frand123Init( state, 0, 0 )\n\n ! use excessKurtosisScalar\n startTime = omp_get_wtime()\n varScalar = excessKurtosisScalar( state )\n endTime = omp_get_wtime()\n write(*, '( \"Result generating one random number at a time: \", ES11.4, &\n & \" took \", ES11.4, \" seconds\" )' ) varScalar, endTime - startTime\n\n ! use excessKurtosisTwo\n startTime = omp_get_wtime()\n varTwo = excessKurtosisTwo( state )\n endTime = omp_get_wtime()\n write(*, '( \"Result generating two random number at a time: \", ES11.4, &\n & \" took \", ES11.4, \" seconds\" )' ) varTwo, endTime - startTime\n\n ! use excessKurtosis1000\n startTime = omp_get_wtime()\n var1000 = excessKurtosis1000( state )\n endTime = omp_get_wtime()\n write(*, '( \"Result generating 1000 random number at a time: \", ES11.4, &\n & \" took \", ES11.4, \" seconds\" )' ) var1000, endTime - startTime\n\ncontains\n\n ! estimate excess kurtosis by drawing a single double precision sample at a\n ! time\n real( kind = c_double ) function excessKurtosisScalar( state )\n implicit none\n type( frand123State_t ), intent( inout ) :: state\n\n ! local variables\n real( kind = c_double ) :: excessKurtosis\n real( kind = c_double ) :: draw\n integer( kind = ik ) :: i\n\n ! iterate over samples\n excessKurtosis = real( 0, c_double )\n do i = 1, numberOfSamples\n ! draw random number\n call frand123NormDouble( state, mu, sigma, draw )\n ! centralize\n draw = draw - mu\n ! sum up contributions\n excessKurtosis = excessKurtosis + draw ** 4\n enddo\n ! apply remaining operations\n excessKurtosisScalar = excessKurtosis / &\n ( real( numberOfSamples, c_double) * sigma ** 4 ) - real( 3., c_double )\n end function excessKurtosisScalar\n\n ! estimate excess kurtosis by drawing two double precision sample at a time\n real( kind = c_double ) function excessKurtosisTwo( state )\n implicit none\n type( frand123State_t ), intent( inout ) :: state\n\n ! local variables\n real( kind = c_double ) :: excessKurtosis\n real( kind = c_double ), dimension( 2 ) :: draw\n integer( kind = ik ) :: i\n\n ! iterate over samples\n excessKurtosis = real( 0, c_double )\n do i = 1, numberOfSamples, 2\n ! draw random number\n call frand123NormDouble( state, mu, sigma, draw )\n ! centralize\n draw = draw - mu\n ! sum up contributions\n excessKurtosis = excessKurtosis + sum( draw ** 4 )\n enddo\n ! apply remaining operations\n excessKurtosisTwo = excessKurtosis / &\n ( real( numberOfSamples, c_double) * sigma ** 4 ) - real( 3., c_double )\n end function excessKurtosisTwo\n\n ! estimate excess kurtosis by drawing 1000 double precision sample at a time\n real( kind = c_double ) function excessKurtosis1000( state )\n implicit none\n type( frand123State_t ), intent( inout ) :: state\n\n ! local variables\n real( kind = c_double ) :: excessKurtosis\n real( kind = c_double ), dimension( 1000 ) :: draw\n integer( kind = ik ) :: i\n\n ! iterate over samples\n excessKurtosis = real( 0, c_double )\n do i = 1, numberOfSamples, 1000\n ! draw random number\n call frand123NormDouble( state, mu, sigma, draw )\n ! centralize\n draw = draw - mu\n ! sum up contributions\n excessKurtosis = excessKurtosis + sum( draw ** 4 )\n enddo\n ! apply remaining operations\n excessKurtosis1000 = excessKurtosis / &\n ( real( numberOfSamples, c_double) * sigma ** 4 ) - real( 3., c_double )\n end function excessKurtosis1000\nend program kurtosisDouble\n", "meta": {"hexsha": "f8b5350030b176cba01d33aec13da4480c752b7c", "size": 4852, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/Fortran/kurtosisDouble.f90", "max_stars_repo_name": "maedoc/frand123", "max_stars_repo_head_hexsha": "81591c06d8d705b3fc87531da6c3681e2127b228", "max_stars_repo_licenses": ["Intel"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "examples/Fortran/kurtosisDouble.f90", "max_issues_repo_name": "maedoc/frand123", "max_issues_repo_head_hexsha": "81591c06d8d705b3fc87531da6c3681e2127b228", "max_issues_repo_licenses": ["Intel"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "examples/Fortran/kurtosisDouble.f90", "max_forks_repo_name": "maedoc/frand123", "max_forks_repo_head_hexsha": "81591c06d8d705b3fc87531da6c3681e2127b228", "max_forks_repo_licenses": ["Intel"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.9407407407, "max_line_length": 82, "alphanum_fraction": 0.649629019, "num_tokens": 1325, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460332, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.6965621282614378}} {"text": "subroutine delta_initialize_re(x,y,ny,nsd,adist,snvolume,maxconn,rksh,ninf,inf)\n!===========================================\nreal(8) x(nsd) ! point to be interpolated (RKPM center)\nreal(8) y(nsd,ny) ! possible surrounding nodes (back round mesh)\ninteger ny ! number of surrounding nodes\nreal(8) adist(nsd,ny)\ninteger nsd ! nsd\nreal(8) snvolume(ny)\ninteger maxconn ! max nodes in the support region\nreal(8) rksh(maxconn) ! rkpm coefficient for point x\ninteger ninf\ninteger inf(maxconn) ! node index in support region\n!===========================================\nreal(8) y_tmp(nsd)\nreal(8) a(nsd)\n\nrksh(:)=0.0d0\n\nninf=0\ninf(:)=0\n\ncall getinf_re(inf,ninf,x,y,adist,ny,nsd,maxconn)\n\nif (nsd == 2 ) then\n\t\tcall correct2d(b,bd,x,y,adist,snvolume,1,inf,ninf,maxconn)\n\telseif (nsd ==3 ) then\n\t\tcall correct3d(b,bd,x,y,adist,snvolume,1,inf,ninf,maxconn)\nend if\n\n\ndo n=1,ninf\n\tnnum=inf(n)\n\tdo isd=1,nsd\n\t\ty_tmp(isd)=y(isd,nnum)\n\t\ta(isd)=adist(isd,nnum)\n\tend do\n\t\tif (nsd ==2) then\n\t\tcall RKPMshape2d(shp,b,bd,x,y_tmp,a,snvolume(nnum))\n\t\telseif (nsd ==3) then\n\t\tcall RKPMshape2d(shp,b,bd,x,y_tmp,a,snvolume(nnum))\n\t\tend if\n\trksh(n)=shp\nend do\nreturn\n\nend subroutine\n", "meta": {"hexsha": "4858b320dc90e3272f03ba43eed3c61bc37d4015", "size": 1155, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "delta_initialize_re.f90", "max_stars_repo_name": "biofluids/IFEM-archive", "max_stars_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-15T11:40:16.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-15T11:40:16.000Z", "max_issues_repo_path": "delta_initialize_re.f90", "max_issues_repo_name": "biofluids/IFEM-archive", "max_issues_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "delta_initialize_re.f90", "max_forks_repo_name": "biofluids/IFEM-archive", "max_forks_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-02-11T16:50:21.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-08T07:24:59.000Z", "avg_line_length": 24.5744680851, "max_line_length": 79, "alphanum_fraction": 0.6623376623, "num_tokens": 413, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357326, "lm_q2_score": 0.7879311856832191, "lm_q1q2_score": 0.6965621146421969}} {"text": "module stats_mod\r\nimplicit none\r\nprivate\r\npublic :: mean\r\ninterface mean\r\n module procedure mean_int, mean_real\r\nend interface mean\r\ncontains\r\npure function mean_int(vec) result(avg)\r\ninteger, intent(in) :: vec(:)\r\nreal :: avg\r\navg = real(sum(vec))/(max(1,size(vec)))\r\n! handles the case of size(vec) = 0\r\nend function mean_int\r\n!\r\npure function mean_real(vec) result(avg)\r\nreal, intent(in) :: vec(:)\r\nreal :: avg\r\navg = sum(vec)/(max(1,size(vec)))\r\nend function mean_real\r\n!\r\nend module stats_mod\r\n!\r\nprogram test_stats\r\nuse stats_mod ! import mean, the only PUBLIC entity\r\nimplicit none\r\nprint*,mean([4,7]),mean([4.0,7.0])\r\n! line below invalid because mean_int PRIVATE\r\n! print*,mean_int([4,7]) \r\nend program test_stats", "meta": {"hexsha": "b14191520af10e57f516a208a15d1d38887f0cd5", "size": 757, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "private.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": "private.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": "private.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.2333333333, "max_line_length": 52, "alphanum_fraction": 0.6763540291, "num_tokens": 192, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392695254318, "lm_q2_score": 0.787931190663057, "lm_q1q2_score": 0.6965621142300725}} {"text": "module loglikelihood_module\n use utils_module, only: dp\n\n contains\n\n !> Pyramidal likelihood centered on 0.5.\n !!\n !! This is effectively a gaussian loglikelihood with an L_\\infty norm\n !! \n !! It is normalised so that it should output an evidence of 1.0 for\n !! effectively infinite priors.\n !!\n !! Note that there is a dimensional component to the argument of the exponential function\n !!\n !! This is chosen so as to ensure that the entropy H(N) ~ O(N)\n !!\n function loglikelihood(theta,phi)\n use utils_module, only: loggamma\n implicit none\n !> Input parameters\n real(dp), intent(in), dimension(:) :: theta\n !> Output derived parameters\n real(dp), intent(out), dimension(:) :: phi\n\n integer,save :: nDims=0\n real(dp), save :: factor=1d0\n\n real(dp) :: loglikelihood\n\n real(dp), dimension(size(theta)) :: sigma ! Standard deviation (uncorrelated) \n real(dp), dimension(size(theta)) :: mu ! Mean\n\n real(dp), parameter :: logSqrtTwoPi = log(sqrt(8d0*atan(1d0)))\n real(dp), parameter :: PiOverTwo = 2d0*atan(1d0)\n\n\n\n mu= 5d-1 ! mean in the center\n sigma = 1d-1 \n if(size(theta)/=nDims) then\n nDims = size(theta)\n factor = exp(-2d0/nDims * loggamma(1d0 + nDims/2d0)) * PiOverTwo\n end if\n\n ! normalisation\n loglikelihood = - sum(logSqrtTwoPi+log(sigma))\n\n ! theta dependence\n loglikelihood = loglikelihood - maxval(abs(theta-mu)/sigma)**2 / factor\n\n\n end function loglikelihood\n\n subroutine setup_loglikelihood(settings)\n use settings_module, only: program_settings\n implicit none\n type(program_settings), intent(in) :: settings\n\n end subroutine setup_loglikelihood\n\nend module loglikelihood_module\n", "meta": {"hexsha": "40957f2d30b0aba9b096603df3a4abb91fc01fa0", "size": 1848, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Externals/PolyChord/likelihoods/examples/pyramidal.f90", "max_stars_repo_name": "yuanfangtardis/vscode_project", "max_stars_repo_head_hexsha": "2d78a85413cc85789cc4fee8ec991eb2a0563ef8", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Externals/PolyChord/likelihoods/examples/pyramidal.f90", "max_issues_repo_name": "yuanfangtardis/vscode_project", "max_issues_repo_head_hexsha": "2d78a85413cc85789cc4fee8ec991eb2a0563ef8", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Externals/PolyChord/likelihoods/examples/pyramidal.f90", "max_forks_repo_name": "yuanfangtardis/vscode_project", "max_forks_repo_head_hexsha": "2d78a85413cc85789cc4fee8ec991eb2a0563ef8", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-15T12:22:30.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-15T12:22:30.000Z", "avg_line_length": 29.8064516129, "max_line_length": 93, "alphanum_fraction": 0.6239177489, "num_tokens": 473, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107914029487, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6965050721658748}} {"text": "\tSUBROUTINE SNSINS ( x1, x2, yl1, yl2, ys1, ys2, xint, \n +\t\t\t\tyint, iret )\nC************************************************************************\nC* SNSINS\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This subroutine computes the intersection point for an isentrope\t*\nC* with the surface.\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* SNSINS ( X1, X2, YL1, YL2, YS1, YS2, XINT, YINT, IRET )\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tX1\t\tREAL\t\tFirst x coordinate\t\t*\nC*\tX2\t\tREAL\t\tSecond x coordinate\t\t*\nC*\tYL1\t\tREAL\t\tValue of line at x1\t\t*\nC*\tYL2\t\tREAL\t\tValue of line at x2\t\t*\nC*\tYS1\t\tREAL\t\tValue of surface at x1\t\t*\nC*\tYS2\t\tREAL\t\tValue of surface at x2\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tXINT\t\tREAL\t\tX coordinate at intersection\t*\nC*\tYINT\t\tREAL\t\tY coordinate at intersection\t*\nC*\tIRET\t\tINTEGER\t\tReturn code\t\t\t*\nC*\t\t\t\t\t 0 = normal return\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* M. desJardins/GSFC\t12/85\t\t\t\t\t\t*\nC************************************************************************\nC------------------------------------------------------------------------\n\tiret = 0\nC\nC*\tCompute logarithms of the y points. The lines are assumed to \nC*\tintersect in LOG-P, X space.\nC\n\tyyl1 = ALOG ( yl1 )\n\tyyl2 = ALOG ( yl2 )\n\tyys1 = ALOG ( ys1 )\n\tyys2 = ALOG ( ys2 )\nC\nC*\tFind slope and y-intercept of line.\nC\n\tal = ( yyl1 - yyl2 ) / ( x1 - x2 )\n\tbl = yyl1 - al * x1\nC\nC*\tFind slope and y-intercept of surface.\nC\n\tas = ( yys1 - yys2 ) / ( x1 - x2 )\n\tbs = yys1 - as * x1\nC\nC*\tFind the x and y coordinate of the intersection point.\nC\n\txint = ( bs - bl ) / ( al - as )\n\tyint = al * xint + bl\n\tyint = EXP ( yint )\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "dcf5b7c7990f1da9b81430fd654298e6a7008f90", "size": 1603, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/programs/sn/sncross/snsins.f", "max_stars_repo_name": "oxelson/gempak", "max_stars_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2015-06-03T15:26:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T22:36:03.000Z", "max_issues_repo_path": "gempak/source/programs/sn/sncross/snsins.f", "max_issues_repo_name": "oxelson/gempak", "max_issues_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 60, "max_issues_repo_issues_event_min_datetime": "2015-05-11T21:36:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T16:22:42.000Z", "max_forks_repo_path": "gempak/source/programs/sn/sncross/snsins.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": 28.1228070175, "max_line_length": 73, "alphanum_fraction": 0.4990642545, "num_tokens": 575, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308165850443, "lm_q2_score": 0.7461389873857265, "lm_q1q2_score": 0.6964691242813967}} {"text": "program factorial\n implicit none\n\n ! define variables\n integer :: nfact = 1\n integer :: n = 1\n\n ! compute factorials\n do while (n <= 10)\n nfact = nfact*n\n n = n + 1\n print *, n, \" \", nfact\n end do\nend program factorial\n", "meta": {"hexsha": "59f62254636e74361493ae718d05592045693745", "size": 248, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "hackerrank/a-very-big-sum/factorial.f90", "max_stars_repo_name": "evilmucedin/project-euler", "max_stars_repo_head_hexsha": "08ed51a5ff0d05f60271d99d35b3e601bcddf85d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-03-23T04:31:14.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-17T09:03:09.000Z", "max_issues_repo_path": "hackerrank/a-very-big-sum/factorial.f90", "max_issues_repo_name": "evilmucedin/project-euler", "max_issues_repo_head_hexsha": "08ed51a5ff0d05f60271d99d35b3e601bcddf85d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hackerrank/a-very-big-sum/factorial.f90", "max_forks_repo_name": "evilmucedin/project-euler", "max_forks_repo_head_hexsha": "08ed51a5ff0d05f60271d99d35b3e601bcddf85d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-03-28T20:53:27.000Z", "max_forks_repo_forks_event_max_datetime": "2020-04-27T07:03:02.000Z", "avg_line_length": 16.5333333333, "max_line_length": 28, "alphanum_fraction": 0.5685483871, "num_tokens": 78, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699436, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.696444488538122}} {"text": " SUBROUTINE W3FS26(JLDAYN,IYEAR,MONTH,IDAY,IDAYWK,IDAYYR)\nC$$$ SUBPROGRAM DOCUMENTATION BLOCK\nC\nC SUBPROGRAM: W3FS26 YEAR, MONTH, DAY FROM JULIAN DAY NUMBER\nC AUTHOR: JONES,R.E. ORG: W342 DATE: 87-03-29\nC\nC ABSTRACT: COMPUTES YEAR (4 DIGITS), MONTH, DAY, DAY OF WEEK, DAY\nC OF YEAR FROM JULIAN DAY NUMBER. THIS SUBROUTINE WILL WORK\nC FROM 1583 A.D. TO 3300 A.D.\nC\nC PROGRAM HISTORY LOG:\nC 87-03-29 R.E.JONES\nC 89-10-25 R.E.JONES CONVERT TO CRAY CFT77 FORTRAN\nC\nC USAGE: CALL W3FS26(JLDAYN,IYEAR,MONTH,IDAY,IDAYWK,IDAYYR)\nC\nC INPUT VARIABLES:\nC NAMES INTERFACE DESCRIPTION OF VARIABLES AND TYPES\nC ------ --------- -----------------------------------------------\nC JLDAYN ARG LIST INTEGER JULIAN DAY NUMBER\nC\nC OUTPUT VARIABLES:\nC NAMES INTERFACE DESCRIPTION OF VARIABLES AND TYPES\nC ------ --------- -----------------------------------------------\nC IYEAR ARG LIST INTEGER YEAR (4 DIGITS)\nC MONTH ARG LIST INTEGER MONTH\nC IDAY ARG LIST INTEGER DAY\nC IDAYWK ARG LIST INTEGER DAY OF WEEK (1 IS SUNDAY, 7 IS SAT)\nC IDAYYR ARG LIST INTEGER DAY OF YEAR (1 TO 366)\nC\nC REMARKS: A JULIAN DAY NUMBER CAN BE COMPUTED BY USING ONE OF THE\nC FOLLOWING STATEMENT FUNCTIONS. A DAY OF WEEK CAN BE COMPUTED\nC FROM THE JULIAN DAY NUMBER. A DAY OF YEAR CAN BE COMPUTED FROM\nC A JULIAN DAY NUMBER AND YEAR.\nC\nC IYEAR (4 DIGITS)\nC\nC JDN(IYEAR,MONTH,IDAY) = IDAY - 32075\nC & + 1461 * (IYEAR + 4800 + (MONTH - 14) / 12) / 4\nC & + 367 * (MONTH - 2 - (MONTH -14) / 12 * 12) / 12\nC & - 3 * ((IYEAR + 4900 + (MONTH - 14) / 12) / 100) / 4\nC\nC IYR (4 DIGITS) , IDYR(1-366) DAY OF YEAR\nC\nC JULIAN(IYR,IDYR) = -31739 + 1461 * (IYR + 4799) / 4\nC & -3 * ((IYR + 4899) / 100) / 4 + IDYR\nC\nC DAY OF WEEK FROM JULIAN DAY NUMBER, 1 IS SUNDAY, 7 IS SATURDAY.\nC\nC JDAYWK(JLDAYN) = MOD((JLDAYN + 1),7) + 1\nC\nC DAY OF YEAR FROM JULIAN DAY NUMBER AND 4 DIGIT YEAR.\nC\nC JDAYYR(JLDAYN,IYEAR) = JLDAYN -\nC & (-31739+1461*(IYEAR+4799)/4-3*((IYEAR+4899)/100)/4)\nC\nC THE FIRST FUNCTION WAS IN A LETTER TO THE EDITOR COMMUNICATIONS\nC OF THE ACM VOLUME 11 / NUMBER 10 / OCTOBER, 1968. THE 2ND\nC FUNCTION WAS DERIVED FROM THE FIRST. THIS SUBROUTINE WAS ALSO\nC INCLUDED IN THE SAME LETTER. JULIAN DAY NUMBER 1 IS\nC JAN 1,4713 B.C. A JULIAN DAY NUMBER CAN BE USED TO REPLACE A\nC DAY OF CENTURY, THIS WILL TAKE CARE OF THE DATE PROBLEM IN\nC THE YEAR 2000, OR REDUCE PROGRAM CHANGES TO ONE LINE CHANGE\nC OF 1900 TO 2000. JULIAN DAY NUMBERS CAN BE USED FOR FINDING\nC RECORD NUMBERS IN AN ARCHIVE OR DAY OF WEEK, OR DAY OF YEAR.\nC\nC ATTRIBUTES:\nC LANGUAGE: CRAY CFT77 FORTRAN\nC MACHINE: CRAY Y-MP8/864\nC\nC$$$\nC\n L = JLDAYN + 68569\n N = 4 * L / 146097\n L = L - (146097 * N + 3) / 4\n I = 4000 * (L + 1) / 1461001\n L = L - 1461 * I / 4 + 31\n J = 80 * L / 2447\n IDAY = L - 2447 * J / 80\n L = J / 11\n MONTH = J + 2 - 12 * L\n IYEAR = 100 * (N - 49) + I + L\n IDAYWK = MOD((JLDAYN + 1),7) + 1\n IDAYYR = JLDAYN -\n & (-31739 +1461 * (IYEAR+4799) / 4 - 3 * ((IYEAR+4899)/100)/4)\n RETURN\n END\n", "meta": {"hexsha": "bad845d47923a3d8ffb6f98c20f166e8b3f82e8c", "size": 3341, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "buildscripts/libs/NCEPlibs/src/w3nco/v2.0.6/src/w3fs26.f", "max_stars_repo_name": "GMAO-SI-Team/jedi-stack", "max_stars_repo_head_hexsha": "c34e968b3f803a255a7d2d1f33c1bf8c4d1559a0", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 38, "max_stars_repo_stars_event_min_datetime": "2020-11-30T21:49:56.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T23:09:46.000Z", "max_issues_repo_path": "buildscripts/libs/NCEPlibs/src/w3nco/v2.0.6/src/w3fs26.f", "max_issues_repo_name": "GMAO-SI-Team/jedi-stack", "max_issues_repo_head_hexsha": "c34e968b3f803a255a7d2d1f33c1bf8c4d1559a0", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 152, "max_issues_repo_issues_event_min_datetime": "2019-04-04T14:22:18.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-24T14:41:00.000Z", "max_forks_repo_path": "NCEP_w3/w3fs26.f", "max_forks_repo_name": "GEOS-ESM/NCEP_Shared", "max_forks_repo_head_hexsha": "6f8b2103d3ce8f1b829bff88b71ca4482b4a56a4", "max_forks_repo_licenses": ["NASA-1.3", "ECL-2.0", "Apache-2.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2019-04-26T21:07:48.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-09T20:41:34.000Z", "avg_line_length": 37.9659090909, "max_line_length": 70, "alphanum_fraction": 0.5755761748, "num_tokens": 1223, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636754, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6964444796718453}} {"text": "! Sum square difference\n!\n! By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.\n!\n! What is the 10 001st prime number?\nmodule Problem7\n\n implicit none\n private\n\n public :: solve\ncontains\n subroutine solve\n write (*, '(A)') 'Problem 7. 10001st prime.'\n\n write (*, '(A, I)') 'Prime 1: ', prime1()\n end subroutine\n\n function prime1()\n integer index\n integer count\n integer prime1\n\n ! initial value\n index = 1\n count = 0\n\n do while (count < 10001)\n index = index + 1\n\n if (isPrime(index) == .true.) then\n count = count + 1\n end if\n end do\n\n prime1 = index\n end function\n\n function isPrime(number)\n integer number\n integer devider\n logical isPrime\n\n ! initial value\n isPrime = .true.\n\n do devider = 2, sqrt(real(number))\n if (mod(number, devider) == 0) then\n isPrime = .false.\n exit\n end if\n end do\n end function\nend module\n", "meta": {"hexsha": "2f7df683c5964ae3f9d8ea2b4fb7833187a2e6ee", "size": 1121, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Problem7.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": "Problem7.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": "Problem7.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": 20.3818181818, "max_line_length": 102, "alphanum_fraction": 0.5236396075, "num_tokens": 300, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.7745833737577158, "lm_q1q2_score": 0.696444474011042}} {"text": "! Filename: unitConversion.f90\n! Description: Module of unit conversion utility functions\n! Author: Tim Troxler\n! Date: 7/17/2015\nmodule unitConversion\n\n ! Import modules\n use precision\n implicit none\n\ncontains\n\n ! Convert fahrenheit to celsius\n ! c = (f - 32) * 5 / 9\n function celsius(fahrenheit) \n real(kind = qp) :: fahrenheit, celsius\n celsius = (fahrenheit - 32) * 5 / 9\n end function celsius\n \n ! Convert celsius to fahrenheit\n ! f = (c * 9 / 5) + 32\n function fahrenheit(celsius)\n real(kind = qp) :: fahrenheit, celsius\n fahrenheit = (celsius * 9 / 5) + 32\n end function fahrenheit\n \nend module unitConversion", "meta": {"hexsha": "bd29a9596b5afc4c55ddbdc96ff152d9cd119201", "size": 684, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "unitConversion.f90", "max_stars_repo_name": "troxology/fortranUnitConversion", "max_stars_repo_head_hexsha": "a0c828207c6381dcab2814a53ff314dc28816845", "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": "unitConversion.f90", "max_issues_repo_name": "troxology/fortranUnitConversion", "max_issues_repo_head_hexsha": "a0c828207c6381dcab2814a53ff314dc28816845", "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": "unitConversion.f90", "max_forks_repo_name": "troxology/fortranUnitConversion", "max_forks_repo_head_hexsha": "a0c828207c6381dcab2814a53ff314dc28816845", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.3333333333, "max_line_length": 58, "alphanum_fraction": 0.6403508772, "num_tokens": 201, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357460591568, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.6963803896970302}} {"text": "PROGRAM FRACTAL\r\n IMPLICIT NONE\r\n INTEGER X,Y,I,ITER_MAX,XRES,YRES\r\n REAL XMIN,XMAX,YMIN,YMAX,THRESHOLD\r\n COMPLEX ZN,C\r\n PARAMETER (ITER_MAX=255,XMIN=-2,XMAX=1,YMIN=-1,YMAX=1,XRES=90000,YRES=60000,THRESHOLD=4096)\r\n INTEGER Z_ARRAY(XRES,YRES)\r\n WRITE(*,*)'Initialize array... '\r\n Z_ARRAY=ITER_MAX\r\n WRITE(*,*)'Calculating... '\r\n !$OMP PARALLEL DEFAULT(PRIVATE) SHARED(Z_ARRAY) NUM_THREADS(20)\r\n !$OMP DO SCHEDULE(DYNAMIC,1000)\r\n DO Y=1,YRES\r\n DO X=1,XRES\r\n ZN=CMPLX(0,0)\r\n C=CMPLX(XMIN+(XMAX-XMIN)*X/XRES,YMIN+(YMAX-YMIN)*Y/YRES)\r\n DO I=0,ITER_MAX\r\n ZN=(ZN+C)**2 !Mandelbrot\r\n !ZN=(ABS(REAL(ZN))+CMPLX(0,1)*ABS(AIMAG(ZN)))**2+C !Burning ship\r\n IF (ABS(ZN)>THRESHOLD)THEN\r\n Z_ARRAY(X,Y)=I\r\n GOTO 110\r\n END IF\r\n END DO\r\n110 CONTINUE\r\n END DO\r\n END DO\r\n !$OMP END DO NOWAIT\r\n !$OMP END PARALLEL\r\n WRITE(*,*)'Write file...'\r\n OPEN(10,file=\"data.dat\",FORM=\"unformatted\",ACCESS='stream')\r\n WRITE(10)XRES,YRES,Z_ARRAY\r\n CLOSE(10)\r\nEND PROGRAM FRACTAL\r\n", "meta": {"hexsha": "7b01659d6192fb7a78ee576c4aac4418b4b6a02f", "size": 1165, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "fractal.f95", "max_stars_repo_name": "hyoseupjang/Fractal_Practice", "max_stars_repo_head_hexsha": "4a7221f25b705364aafe1b0ce796672a5daa7b21", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fractal.f95", "max_issues_repo_name": "hyoseupjang/Fractal_Practice", "max_issues_repo_head_hexsha": "4a7221f25b705364aafe1b0ce796672a5daa7b21", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fractal.f95", "max_forks_repo_name": "hyoseupjang/Fractal_Practice", "max_forks_repo_head_hexsha": "4a7221f25b705364aafe1b0ce796672a5daa7b21", "max_forks_repo_licenses": ["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.2857142857, "max_line_length": 96, "alphanum_fraction": 0.5527896996, "num_tokens": 381, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897525789547, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.6963484603200816}} {"text": "MODULE mo_boxcox\n\n ! This module contains routines to calculate the Box-Cox transformation\n ! as well as estimating the best exponent for the Box-Cox transformation\n\n ! Usage:\n ! USE mo_boxcox, ONLY: boxcox, get_boxcox\n ! lmbda = get_boxcox(data)\n ! new_data = boxcox(data, lmbda)\n ! data = invboxcox(new_data, lmbda)\n\n ! Written March 2011, Matthias Cuntz\n ! - modified Python code of Travis Oliphant (2002): boxcox, llf_boxcox, get_boxcox\n ! - modified numerical recipes: brent, mnbrak, swap, shft\n\n ! License\n ! -------\n ! This file is part of the JAMS Fortran package, distributed under the MIT License.\n !\n ! Copyright (c) 2011-2012 Matthias Cuntz - mc (at) macu (dot) de\n !\n ! Permission is hereby granted, free of charge, to any person obtaining a copy\n ! of this software and associated documentation files (the \"Software\"), to deal\n ! in the Software without restriction, including without limitation the rights\n ! to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n ! copies of the Software, and to permit persons to whom the Software is\n ! furnished to do so, subject to the following conditions:\n !\n ! The above copyright notice and this permission notice shall be included in all\n ! copies or substantial portions of the Software.\n !\n ! THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n ! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n ! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n ! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n ! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n ! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n ! SOFTWARE.\n\n ! Note on Numerical Recipes License\n ! ---------------------------------\n ! Be aware that some code is under the Numerical Recipes License 3rd\n ! edition \n\n ! The Numerical Recipes Personal Single-User License lets you personally\n ! use Numerical Recipes code (\"the code\") on any number of computers,\n ! but only one computer at a time. You are not permitted to allow anyone\n ! else to access or use the code. You may, under this license, transfer\n ! precompiled, executable applications incorporating the code to other,\n ! unlicensed, persons, providing that (i) the application is\n ! noncommercial (i.e., does not involve the selling or licensing of the\n ! application for a fee), and (ii) the application was first developed,\n ! compiled, and successfully run by you, and (iii) the code is bound\n ! into the application in such a manner that it cannot be accessed as\n ! individual routines and cannot practicably be unbound and used in\n ! other programs. That is, under this license, your application user\n ! must not be able to use Numerical Recipes code as part of a program\n ! library or \"mix and match\" workbench.\n\n ! Businesses and organizations that purchase the disk or code download,\n ! and that thus acquire one or more Numerical Recipes Personal\n ! Single-User Licenses, may permanently assign those licenses, in the\n ! number acquired, to individual employees. Such an assignment must be\n ! made before the code is first used and, once made, it is irrevocable\n ! and can not be transferred.\n\n ! If you do not hold a Numerical Recipes License, this code is only for\n ! informational and educational purposes but cannot be used.\n\n USE mo_kind, ONLY: i4, sp, dp\n USE mo_utils, only: eq, le, ge\n\n IMPLICIT NONE\n\n PUBLIC :: boxcox ! Calculate Box-Cox power transformed values given the original values and the exponent lambda\n PUBLIC :: get_boxcox ! Find the exponent that maximises the log-likelihood function\n PUBLIC :: invboxcox ! Calculate the inverse Box-Cox given the transformed values and the exponent lambda\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! boxcox\n\n ! PURPOSE\n ! Transform a positive dataset with a Box-Cox power transformation.\n ! boxcox(x) = (x**lambda - 1)/lambda if lambda <> 0\n ! ln(x) if lambda = 0\n !\n ! If an optinal mask is given, then the Box-Cox transformation is only performed on\n ! those locations that correspond to true values in the mask.\n ! x can be single or double precision. The result will have the same numerical precision.\n\n ! CALLING SEQUENCE\n ! out = boxcox(x, lmbda, mask=mask)\n\n ! INTENT(IN)\n ! real(sp/dp) :: x(:) 1D-array with input numbers (>0.)\n ! real(sp/dp) :: lmbda Exponent power of Box-Cox transform (>= 0.)\n\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n ! real(sp/dp) :: boxcox Power transformed values (at mask=.True.)\n\n ! INTENT(IN), OPTIONAL\n ! logical :: mask(:) 1D-array of logical values with size(x).\n ! If present, only those locations in vec corresponding to the true values in mask are used.\n\n ! INTENT(INOUT), OPTIONAL\n ! None\n\n ! INTENT(OUT), OPTIONAL\n ! None\n\n ! RESTRICTIONS\n ! Input values must be positive, i.e. > 0.\n\n ! EXAMPLE\n ! lmbda = get_boxcox(data, mask=(data>0.))\n ! new_data = boxcox(data, lmbda, mask=(data>0.))\n ! idata = invboxcox(new_data, lmbda, mask=(data>0.))\n ! -> see also example in test directory\n\n ! HISTORY\n ! Written, Matthias Cuntz, March 2011\n ! - Modified Python code of Travis Oliphant (2002): boxcox, llf_boxcox, get_boxcox\n ! - Modified numerical recipes: brent, mnbrak, swap, shft\n INTERFACE boxcox\n MODULE PROCEDURE boxcox_sp, boxcox_dp\n END INTERFACE boxcox\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! get_boxcox\n\n ! PURPOSE\n ! Get lambda for Box-Cox transformation.\n !\n ! Transform a positive dataset with a Box-Cox power transformation.\n ! boxcox(x) = (x**lambda - 1)/lambda if lambda <> 0\n ! ln(x) if lambda = 0\n !\n ! If an optinal mask is given, then the Box-Cox transformation is only performed on\n ! those locations that correspond to true values in the mask.\n ! x can be single or double precision. The result will have the same numerical precision.\n\n ! CALLING SEQUENCE\n ! out = get_boxcox(x, mask=mask)\n\n ! INTENT(IN)\n ! real(sp/dp) :: x(:) 1D-array with input numbers (>0.)\n\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n ! real(sp/dp) :: lambda Lambda for power transformed values (at mask=.True.)\n\n ! INTENT(IN), OPTIONAL\n ! logical :: mask(:) 1D-array of logical values with size(x).\n ! If present, only those locations in vec corresponding to the true values in mask are used.\n\n ! INTENT(INOUT), OPTIONAL\n ! None\n\n ! INTENT(OUT), OPTIONAL\n ! None\n\n ! RESTRICTIONS\n ! Input values must be positive, i.e. > 0.\n\n ! EXAMPLE\n ! lmbda = get_boxcox(data, mask=(data>0.))\n ! new_data = boxcox(data, lmbda, mask=(data>0.))\n ! idata = invboxcox(new_data, lmbda, mask=(data>0.))\n ! -> see also example in test directory\n\n ! HISTORY\n ! Written, Matthias Cuntz, March 2011\n ! - Modified Python code of Travis Oliphant (2002): boxcox, llf_boxcox, get_boxcox\n ! - Modified numerical recipes: brent, mnbrak, swap, shft\n INTERFACE get_boxcox\n MODULE PROCEDURE get_boxcox_sp, get_boxcox_dp\n END INTERFACE get_boxcox\n \n ! ------------------------------------------------------------------\n\n ! NAME\n ! invboxcox\n\n ! PURPOSE\n ! Back-transformation of Box-Cox-transformed data.\n ! boxcox(x) = (x**lambda - 1)/lambda if lambda <> 0\n ! ln(x) if lambda = 0\n ! invboxcox(y) = (lambda*y + 1)**(1/lambda) if lambda <> 0\n ! exp(y) if lambda = 0\n !\n ! If an optinal mask is given, then the inverse Box-Cox transformation is only performed on\n ! those locations that correspond to true values in the mask.\n ! x can be single or double precision. The result will have the same numerical precision.\n ! x can be scalar or vector\n\n ! CALLING SEQUENCE\n ! out = invboxcox(x, lmbda) ! scalar x\n ! out = invboxcox(x, lmbda, mask=mask) ! vector x\n\n ! INTENT(IN)\n ! real(sp/dp) :: x / x(:) scalar/1D-array with input numbers (>0.)\n ! real(sp/dp) :: lmbda Exponent power of Box-Cox transform (>= 0.)\n\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n ! real(sp/dp) :: boxcox Back transformed values (at mask=.True.)\n\n ! INTENT(IN), OPTIONAL\n ! logical :: mask(:) 1D-array of logical values with size(x).\n ! If present, only those locations in vec corresponding to the true values in mask are used.\n ! Only applicable if x is a 1D-array\n\n ! INTENT(INOUT), OPTIONAL\n ! None\n\n ! INTENT(OUT), OPTIONAL\n ! None\n\n ! RESTRICTIONS\n ! None\n\n ! EXAMPLE\n ! lmbda = get_boxcox(data, mask=(data>0.))\n ! new_data = boxcox(data, lmbda, mask=(data>0.))\n ! idata = invboxcox(new_data, lmbda, mask=(data>0.))\n ! -> see also example in test directory\n\n ! HISTORY\n ! Written, Matthias Cuntz, March 2011\n ! - Modified MC: Python code of Travis Oliphant (2002): boxcox, llf_boxcox, get_boxcox\n ! - Modified MC: numerical recipes: brent, mnbrak, swap, shft\n ! - Modified JM: scalar version of invboxcox\n INTERFACE invboxcox\n MODULE PROCEDURE invboxcox_0d_sp, invboxcox_0d_dp, invboxcox_1d_sp, invboxcox_1d_dp\n END INTERFACE invboxcox\n \n ! ------------------------------------------------------------------\n\n PRIVATE\n\n ! ------------------------------------------------------------------\n\nCONTAINS\n\n ! ------------------------------------------------------------------\n\n FUNCTION boxcox_sp(x, lmbda, mask)\n\n IMPLICIT NONE\n\n REAL(sp), DIMENSION(:), INTENT(in) :: x\n REAL(sp), INTENT(in) :: lmbda\n LOGICAL, DIMENSION(:), INTENT(in), OPTIONAL :: mask\n REAL(sp), DIMENSION(size(x)) :: boxcox_sp\n\n LOGICAL, DIMENSION(size(x)) :: maske\n REAL(sp) :: lmbda1\n\n maske(:) = .true.\n if (present(mask)) then\n if (size(mask) /= size(x)) stop 'Error boxcox_sp: size(mask) /= size(x)'\n maske = mask\n endif\n if (any((le(x,0.0_sp)) .and. maske)) stop 'Error boxcox_sp: x <= 0'\n if (abs(lmbda) .lt. tiny(0.0_sp)) then\n where (maske)\n boxcox_sp = log(x)\n elsewhere\n boxcox_sp = x\n end where\n else\n lmbda1 = 1.0_sp / lmbda\n boxcox_sp = merge((exp(lmbda*log(x)) - 1.0_sp) * lmbda1, x, maske)\n endif\n\n END FUNCTION boxcox_sp\n\n\n FUNCTION boxcox_dp(x, lmbda, mask)\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:), INTENT(in) :: x\n REAL(dp), INTENT(in) :: lmbda\n LOGICAL, DIMENSION(:), INTENT(in), OPTIONAL :: mask\n REAL(dp), DIMENSION(size(x)) :: boxcox_dp\n\n LOGICAL, DIMENSION(size(x)) :: maske\n REAL(dp) :: lmbda1\n\n maske(:) = .true.\n if (present(mask)) then\n if (size(mask) /= size(x)) stop 'Error boxcox_dp: size(mask) /= size(x)'\n maske = mask\n endif\n if (any((le(x,0.0_dp)) .and. maske)) then\n stop 'Error boxcox_dp: x <= 0'\n end if\n if (abs(lmbda) .lt. tiny(0.0_dp)) then\n where (maske)\n boxcox_dp = log(x)\n elsewhere\n boxcox_dp = x\n end where\n else\n lmbda1 = 1.0_dp / lmbda\n boxcox_dp = merge((exp(lmbda*log(x)) - 1.0_dp) * lmbda1, x, maske)\n endif\n\n END FUNCTION boxcox_dp\n\n ! ------------------------------------------------------------------\n\n ! Given a function f, and given a bracketing triplet of abscissas ax, bx, cx (such that bx is\n ! between ax and cx, and f(bx) is less than both f(ax) and f(cx)), this routine isolates\n ! the minimum to a fractional precision of about tol using Brent''s method. The abscissa of\n ! the minimum is returned.\n ! Parameters: Maximum allowed number of iterations; goldenratio; and a small number that\n ! protects against trying to achieve fractional accuracy for a minimum that happens to be\n ! exactly zero.\n Function brent_sp(ax, bx, cx, func_sp, tol, dat)\n\n IMPLICIT NONE\n\n REAL(sp), INTENT(in) :: ax, bx, cx\n INTERFACE\n FUNCTION func_sp(x, da)\n USE mo_kind, ONLY: sp\n IMPLICIT NONE\n REAL(sp), INTENT(in) :: x\n REAL(sp), DIMENSION(:), INTENT(in) :: da\n REAL(sp) :: func_sp\n END FUNCTION func_sp\n END INTERFACE\n REAL(sp), INTENT(in) :: tol\n REAL(sp), DIMENSION(:), INTENT(in) :: dat\n REAL(sp) :: brent_sp\n\n INTEGER(i4), PARAMETER :: ITMAX = 500\n REAL(sp), PARAMETER :: CGOLD = 0.3819660_sp\n REAL(sp), PARAMETER :: ZEPS = 1.0e-3_sp*epsilon(ax)\n INTEGER(i4) :: iter\n REAL(sp) :: a, b, d, e, etemp, fu, fv, fw, fx\n REAL(sp) :: p, q, r, tol1, tol2, u, v, w, x, xm\n\n d = 0.0_sp\n\n a = min(ax,cx)\n b = max(ax,cx)\n v = bx\n w = v\n x = v\n e = 0.0_sp\n fx = func_sp(x, dat)\n fv = fx\n fw = fx\n do iter=1, ITMAX\n xm = 0.5_sp*(a+b)\n tol1 = tol*abs(x) + ZEPS\n tol2 = 2.0_sp*tol1\n if (le(abs(x-xm),(tol2-0.5_sp*(b-a)))) then\n brent_sp = x\n return\n end if\n if (abs(e) > tol1) then\n r = (x-w)*(fx-fv)\n q = (x-v)*(fx-fw)\n p = (x-v)*q-(x-w)*r\n q = 2.0_sp*(q-r)\n if (q > 0.0_sp) p = -p\n q = abs(q)\n etemp = e\n e = d\n if (ge(abs(p),abs(0.5_sp*q*etemp)) .or. &\n le(p,q*(a-x)) .or. ge(p,q*(b-x))) then\n e = merge(a-x, b-x, ge(x,xm))\n d = CGOLD*e\n else\n d = p/q\n u = x+d\n if (u-a < tol2 .or. b-u < tol2) d = sign(tol1,xm-x)\n end if\n else\n e = merge(a-x, b-x, ge(x,xm))\n d = CGOLD*e\n end if\n u = merge(x+d, x+sign(tol1,d), ge(abs(d),tol1))\n fu = func_sp(u, dat)\n if (le(fu,fx)) then\n if (ge(u,x)) then\n a = x\n else\n b = x\n end if\n call shft_sp(v,w,x,u)\n call shft_sp(fv,fw,fx,fu)\n else\n if (u < x) then\n a = u\n else\n b = u\n end if\n if (le(fu,fw) .or. eq(w,x)) then\n v = w\n fv = fw\n w = u\n fw = fu\n else if (le(fu,fv) .or. eq(v,x) .or. eq(v,w)) then\n v = u\n fv = fu\n end if\n end if\n end do\n ! If it comes to here, there were too much iterations\n STOP 'brent_sp: exceed maximum iterations'\n\n END FUNCTION brent_sp\n\n\n FUNCTION brent_dp(ax, bx, cx, func_dp, tol, dat)\n\n IMPLICIT NONE\n\n REAL(dp), INTENT(in) :: ax, bx, cx\n INTERFACE\n FUNCTION func_dp(x, da)\n USE mo_kind, ONLY: dp\n IMPLICIT NONE\n REAL(dp), INTENT(in) :: x\n REAL(dp), DIMENSION(:), INTENT(in) :: da\n REAL(dp) :: func_dp\n END FUNCTION func_dp\n END INTERFACE\n REAL(dp), INTENT(in) :: tol\n REAL(dp), DIMENSION(:), INTENT(in) :: dat\n REAL(dp) :: brent_dp\n\n INTEGER(i4), PARAMETER :: ITMAX=500\n REAL(dp), PARAMETER :: CGOLD=0.3819660_dp\n REAL(dp), PARAMETER :: ZEPS=1.0e-3_dp*epsilon(ax)\n INTEGER(i4) :: iter\n REAL(dp) :: a, b, d, e, etemp, fu, fv, fw, fx\n REAL(dp) :: p, q, r, tol1, tol2, u, v, w, x, xm\n\n d = 0.0_dp\n\n a = min(ax,cx)\n b = max(ax,cx)\n v = bx\n w = v\n x = v\n e = 0.0_dp\n fx = func_dp(x, dat)\n fv = fx\n fw = fx\n do iter=1, ITMAX\n xm = 0.5_dp*(a+b)\n tol1 = tol*abs(x) + ZEPS\n tol2 = 2.0_dp*tol1\n if (le(abs(x-xm),(tol2-0.5_dp*(b-a)))) then\n brent_dp = x\n return\n end if\n if (abs(e) > tol1) then\n r = (x-w)*(fx-fv)\n q = (x-v)*(fx-fw)\n p = (x-v)*q-(x-w)*r\n q = 2.0_dp*(q-r)\n if (q > 0.0_dp) p = -p\n q = abs(q)\n etemp = e\n e = d\n if (ge(abs(p),abs(0.5_dp*q*etemp)) .or. &\n le(p,q*(a-x)) .or. ge(p,q*(b-x))) then\n e = merge(a-x, b-x, ge(x,xm))\n d = CGOLD*e\n else\n d = p/q\n u = x+d\n if (u-a < tol2 .or. b-u < tol2) d = sign(tol1,xm-x)\n end if\n else\n e = merge(a-x, b-x, ge(x,xm))\n d = CGOLD*e\n end if\n u = merge(x+d, x+sign(tol1,d), ge(abs(d),tol1))\n fu = func_dp(u, dat)\n if (le(fu,fx)) then\n if (ge(u,x)) then\n a = x\n else\n b = x\n end if\n call shft_dp(v,w,x,u)\n call shft_dp(fv,fw,fx,fu)\n else\n if (u < x) then\n a = u\n else\n b = u\n end if\n if (le(fu,fw) .or. eq(w,x)) then\n v = w\n fv = fw\n w = u\n fw = fu\n else if (le(fu,fv) .or. eq(v,x) .or. eq(v,w)) then\n v = u\n fv = fu\n end if\n end if\n end do\n ! If it comes to here, there were too much iterations\n STOP 'brent_dp: exceed maximum iterations'\n\n END FUNCTION brent_dp\n\n ! ------------------------------------------------------------------\n\n ! Find the lambda that maximizes the log-likelihood function\n FUNCTION get_boxcox_sp(x, mask)\n\n IMPLICIT NONE\n\n REAL(sp), DIMENSION(:), INTENT(in) :: x\n LOGICAL, DIMENSION(:), INTENT(in), OPTIONAL :: mask\n REAL(sp) :: get_boxcox_sp\n\n REAL(sp), PARAMETER :: tol = 1.48e-08\n REAL(sp) :: ax, bx, cx\n REAL(sp) :: fa, fb, fc\n LOGICAL, DIMENSION(size(x)) :: maske\n REAL(sp), DIMENSION(:), ALLOCATABLE :: xx\n INTEGER(i4) :: nn\n\n\n maske(:) = .true.\n if (present(mask)) then\n if (size(mask) /= size(x)) stop 'Error get_boxcox_sp: size(mask) /= size(x)'\n maske = mask\n endif\n nn = count(maske)\n if (allocated(xx)) deallocate(xx)\n allocate(xx(nn))\n xx = pack(x, mask=maske)\n ax = -2.0_sp\n bx = 2.0_sp\n call mnbrak_sp(ax, bx, cx, fa, fb, fc, llf_boxcox_sp, xx)\n get_boxcox_sp = brent_sp(ax, bx, cx, llf_boxcox_sp, tol, xx)\n\n END FUNCTION get_boxcox_sp\n\n\n FUNCTION get_boxcox_dp(x, mask)\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:), INTENT(in) :: x\n LOGICAL, DIMENSION(:), INTENT(in), OPTIONAL :: mask\n REAL(dp) :: get_boxcox_dp\n\n REAL(dp), PARAMETER :: tol = 1.48e-08\n REAL(dp) :: ax, bx, cx\n REAL(dp) :: fa, fb, fc\n LOGICAL, DIMENSION(size(x)) :: maske\n REAL(dp), DIMENSION(:), ALLOCATABLE :: xx\n INTEGER(i4) :: nn\n\n\n maske(:) = .true.\n if (present(mask)) then\n if (size(mask) /= size(x)) stop 'Error get_boxcox_dp: size(mask) /= size(x)'\n maske = mask\n endif\n nn = count(maske)\n if (allocated(xx)) deallocate(xx)\n allocate(xx(nn))\n xx = pack(x, mask=maske)\n if (any(le(xx,0.0_dp))) then\n stop 'Error get_boxcox_dp: x <= 0'\n end if\n ax = -5.0_dp\n bx = 5.0_dp\n call mnbrak_dp(ax, bx, cx, fa, fb, fc, llf_boxcox_dp, xx)\n get_boxcox_dp = brent_dp(ax, bx, cx, llf_boxcox_dp, tol, xx)\n\n END FUNCTION get_boxcox_dp\n\n ! ------------------------------------------------------------------\n\n FUNCTION invboxcox_1d_sp(x, lmbda, mask)\n\n IMPLICIT NONE\n\n REAL(sp), DIMENSION(:), INTENT(in) :: x\n REAL(sp), INTENT(in) :: lmbda\n LOGICAL, DIMENSION(:), INTENT(in), OPTIONAL :: mask\n REAL(sp), DIMENSION(size(x)) :: invboxcox_1d_sp\n\n LOGICAL, DIMENSION(size(x)) :: maske\n REAL(sp) :: lmbda1\n REAL(sp), DIMENSION(size(x)) :: temp\n\n maske(:) = .true.\n if (present(mask)) then\n if (size(mask) /= size(x)) stop 'Error invboxcox_1d_sp: size(mask) /= size(x)'\n maske = mask\n endif\n if (abs(lmbda) .lt. tiny(0.0_sp)) then\n where (maske)\n invboxcox_1d_sp = exp(x)\n elsewhere\n invboxcox_1d_sp = x\n end where\n else\n lmbda1 = 1.0_sp / lmbda\n temp = lmbda*x+1.0_sp\n where (temp .gt. 0.0_sp)\n temp = exp(lmbda1*log(temp))\n elsewhere\n temp = 0.0_sp\n end where\n invboxcox_1d_sp = merge(temp, x, maske)\n endif\n\n END FUNCTION invboxcox_1d_sp\n\n FUNCTION invboxcox_1d_dp(x, lmbda, mask)\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:), INTENT(in) :: x\n REAL(dp), INTENT(in) :: lmbda\n LOGICAL, DIMENSION(:), INTENT(in), OPTIONAL :: mask\n REAL(dp), DIMENSION(size(x)) :: invboxcox_1d_dp\n\n LOGICAL, DIMENSION(size(x)) :: maske\n REAL(dp) :: lmbda1\n REAL(dp), DIMENSION(size(x)) :: temp\n\n maske(:) = .true.\n if (present(mask)) then\n if (size(mask) /= size(x)) stop 'Error invboxcox_1d_dp: size(mask) /= size(x)'\n maske = mask\n endif\n if (abs(lmbda) .lt. tiny(0.0_dp)) then\n where (maske)\n invboxcox_1d_dp = exp(x)\n elsewhere\n invboxcox_1d_dp = x\n end where\n else\n lmbda1 = 1.0_dp / lmbda\n temp = lmbda*x+1.0_dp\n where (temp .gt. 0.0_dp)\n temp = exp(lmbda1*log(temp))\n elsewhere\n temp = 0.0_dp\n end where\n invboxcox_1d_dp = merge(temp, x, maske)\n endif\n\n END FUNCTION invboxcox_1d_dp\n\n FUNCTION invboxcox_0d_sp(x, lmbda)\n\n IMPLICIT NONE\n\n REAL(sp), INTENT(in) :: x\n REAL(sp), INTENT(in) :: lmbda\n REAL(sp) :: invboxcox_0d_sp\n\n REAL(sp) :: lmbda1\n REAL(sp) :: temp\n\n if (abs(lmbda) .lt. tiny(0.0_sp)) then\n invboxcox_0d_sp = exp(x)\n else\n lmbda1 = 1.0_sp / lmbda\n temp = lmbda*x+1.0_sp\n if (temp .gt. 0.0_sp) then\n temp = exp(lmbda1*log(temp))\n else\n temp = 0.0_sp\n end if\n invboxcox_0d_sp = temp\n endif\n\n END FUNCTION invboxcox_0d_sp\n\n FUNCTION invboxcox_0d_dp(x, lmbda)\n\n IMPLICIT NONE\n\n REAL(dp), INTENT(in) :: x\n REAL(dp), INTENT(in) :: lmbda\n REAL(dp) :: invboxcox_0d_dp\n\n REAL(dp) :: lmbda1\n REAL(dp) :: temp\n\n if (abs(lmbda) .lt. tiny(0.0_dp)) then\n invboxcox_0d_dp = exp(x)\n else\n lmbda1 = 1.0_dp / lmbda\n temp = lmbda*x+1.0_dp\n if (temp .gt. 0.0_dp) then\n temp = exp(lmbda1*log(temp))\n else\n temp = 0.0_dp\n end if\n invboxcox_0d_dp = temp\n endif\n\n END FUNCTION invboxcox_0d_dp\n\n ! ------------------------------------------------------------------\n\n ! The boxcox (negative) log-likelihood function.\n FUNCTION llf_boxcox_sp(lmbda, x)\n\n IMPLICIT NONE\n\n REAL(sp), INTENT(in) :: lmbda\n REAL(sp), DIMENSION(:), INTENT(in) :: x\n REAL(sp) :: llf_boxcox_sp\n\n REAL(sp), DIMENSION(size(x)) :: y\n REAL(sp) :: N, my, f, s\n\n N = real(size(x),sp)\n y = boxcox_sp(x, lmbda)\n my = sum(y) / N\n f = (lmbda-1.0_sp) * sum(log(x))\n\n ! f = f - 0.5_dp*N * log(sum((y-my)*(y-my))/N)\n s = Min( huge(1.0_sp)/N , Max( N*tiny(1.0_sp) , sum((y-my)*(y-my)) ) )\n f = f - 0.5_sp*N * log(s/N)\n\n llf_boxcox_sp = -f\n\n END FUNCTION llf_boxcox_sp\n\n\n FUNCTION llf_boxcox_dp(lmbda, x)\n\n IMPLICIT NONE\n\n REAL(dp), INTENT(in) :: lmbda\n REAL(dp), DIMENSION(:), INTENT(in) :: x\n REAL(dp) :: llf_boxcox_dp\n\n REAL(dp), DIMENSION(size(x)) :: y\n REAL(dp) :: N, my, f, s\n\n N = real(size(x),dp)\n y = boxcox_dp(x, lmbda)\n my = sum(y) / N\n f = (lmbda-1.0_dp) * sum(log(x))\n\n ! f = f - 0.5_dp*N * log(sum((y-my)*(y-my))/N)\n s = Min( huge(1.0_dp)/N , Max( N*tiny(1.0_dp) , sum((y-my)*(y-my)) ) )\n f = f - 0.5_dp*N * log(s/N)\n\n llf_boxcox_dp = -f\n\n END FUNCTION llf_boxcox_dp\n\n ! ------------------------------------------------------------------\n\n ! Given a function func, and given distinct initial points ax and bx, this routine searches\n ! in the downhill direction (defined by the functionas evaluated at the initial points) and\n ! returns new points ax, bx, cx that bracket a minimum of the function.\n ! Parameters: GOLD is the default ratio by which successive intervals are magnified; GLIMIT\n ! is the maximum magnification allowed for a parabolic-fit step.\n SUBROUTINE mnbrak_sp(ax, bx, cx, fa, fb, fc, func_sp, dat)\n\n IMPLICIT NONE\n\n REAL(sp), INTENT(inout) :: ax, bx\n REAL(sp), INTENT(out) :: cx\n REAL(sp), INTENT(out) :: fa, fb, fc\n INTERFACE\n FUNCTION func_sp(x, da)\n USE mo_kind, ONLY: sp\n IMPLICIT NONE\n REAL(sp), INTENT(in) :: x\n REAL(sp), DIMENSION(:), INTENT(in) :: da\n REAL(sp) :: func_sp\n END FUNCTION func_sp\n END INTERFACE\n REAL(sp), DIMENSION(:), INTENT(in) :: dat\n\n REAL(sp), PARAMETER :: GOLD = 1.618034_sp\n REAL(sp), PARAMETER :: GLIMIT = 100.0_sp\n REAL(sp), PARAMETER :: TINY = 1.0e-20_sp\n REAL(sp) :: fu, q, r, u, ulim\n\n fa = func_sp(ax, dat)\n fb = func_sp(bx, dat)\n if (fb > fa) then\n call swap_sp(ax,bx)\n call swap_sp(fa,fb)\n end if\n cx = bx + GOLD*(bx-ax)\n fc = func_sp(cx, dat)\n do\n if (fb < fc) return\n r = (bx-ax)*(fb-fc)\n q = (bx-cx)*(fb-fa)\n u = bx-((bx-cx)*q-(bx-ax)*r)/(2.0_sp*sign(max(abs(q-r),TINY),q-r))\n ulim = bx + GLIMIT*(cx-bx)\n if ((bx-u)*(u-cx) > 0.0_sp) then\n fu = func_sp(u, dat)\n if (fu < fc) then\n ax = bx\n fa = fb\n bx = u\n fb = fu\n return\n else if (fu > fb) then\n cx = u\n fc = fu\n return\n end if\n u = cx + GOLD*(cx-bx)\n fu = func_sp(u, dat)\n else if ((cx-u)*(u-ulim) > 0.0_sp) then\n fu = func_sp(u, dat)\n if (fu < fc) then\n bx = cx\n cx = u\n u = cx + GOLD*(cx-bx)\n call shft_sp(fb,fc,fu,func_sp(u, dat))\n end if\n else if (ge((u-ulim)*(ulim-cx),0.0_sp)) then\n u = ulim\n fu = func_sp(u, dat)\n else\n u = cx + GOLD*(cx-bx)\n fu = func_sp(u, dat)\n end if\n call shft_sp(ax,bx,cx,u)\n call shft_sp(fa,fb,fc,fu)\n end do\n\n END SUBROUTINE mnbrak_sp\n\n\n SUBROUTINE mnbrak_dp(ax, bx, cx, fa, fb, fc, func_dp, dat)\n\n IMPLICIT NONE\n\n REAL(dp), INTENT(inout) :: ax, bx\n REAL(dp), INTENT(out) :: cx\n REAL(dp), INTENT(out) :: fa, fb, fc\n INTERFACE\n FUNCTION func_dp(x, da)\n USE mo_kind, ONLY: dp\n IMPLICIT NONE\n REAL(dp), INTENT(in) :: x\n REAL(dp), DIMENSION(:), INTENT(in) :: da\n REAL(dp) :: func_dp\n END FUNCTION func_dp\n END INTERFACE\n REAL(dp), DIMENSION(:), INTENT(in) :: dat\n\n REAL(dp), PARAMETER :: GOLD = 1.618034_dp\n REAL(dp), PARAMETER :: GLIMIT = 100.0_dp\n REAL(dp), PARAMETER :: TINY = 1.0e-20_dp\n REAL(dp) :: fu, q, r, u, ulim\n\n fa = func_dp(ax, dat)\n fb = func_dp(bx, dat)\n if (fb > fa) then\n call swap_dp(ax,bx)\n call swap_dp(fa,fb)\n end if\n cx = bx + GOLD*(bx-ax)\n fc = func_dp(cx, dat)\n do\n if (fb < fc) return\n r = (bx-ax)*(fb-fc)\n q = (bx-cx)*(fb-fa)\n u = bx-((bx-cx)*q-(bx-ax)*r)/(2.0_dp*sign(max(abs(q-r),TINY),q-r))\n ulim = bx + GLIMIT*(cx-bx)\n if ((bx-u)*(u-cx) > 0.0_dp) then\n fu = func_dp(u, dat)\n if (fu < fc) then\n ax = bx\n fa = fb\n bx = u\n fb = fu\n return\n else if (fu > fb) then\n cx = u\n fc = fu\n return\n end if\n u = cx + GOLD*(cx-bx)\n fu = func_dp(u, dat)\n else if ((cx-u)*(u-ulim) > 0.0_dp) then\n fu = func_dp(u, dat)\n if (fu < fc) then\n bx = cx\n cx = u\n u = cx + GOLD*(cx-bx)\n call shft_dp(fb,fc,fu,func_dp(u, dat))\n end if\n else if (ge((u-ulim)*(ulim-cx),0.0_dp)) then\n u = ulim\n fu = func_dp(u, dat)\n else\n u = cx + GOLD*(cx-bx)\n fu = func_dp(u, dat)\n end if\n call shft_dp(ax,bx,cx,u)\n call shft_dp(fa,fb,fc,fu)\n end do\n\n END SUBROUTINE mnbrak_dp\n\n ! ------------------------------------------------------------------\n\n ! Helper for brent and mnbrak\n SUBROUTINE shft_sp(a,b,c,d)\n\n IMPLICIT NONE\n\n REAL(sp), INTENT(out) :: a\n REAL(sp), INTENT(inout) :: b,c\n REAL(sp), INTENT(in) :: d\n\n a = b\n b = c\n c = d\n\n END SUBROUTINE shft_sp\n\n\n SUBROUTINE shft_dp(a,b,c,d)\n\n IMPLICIT NONE\n\n REAL(dp), INTENT(out) :: a\n REAL(dp), INTENT(inout) :: b,c\n REAL(dp), INTENT(in) :: d\n\n a = b\n b = c\n c = d\n\n END SUBROUTINE shft_dp\n\n ! ------------------------------------------------------------------\n\n ! Helper for mnbrak\n SUBROUTINE swap_sp(a,b)\n\n IMPLICIT NONE\n\n REAL(sp), INTENT(inout) :: a, b\n REAL(sp) :: dum\n dum = a\n a = b\n b = dum\n\n END SUBROUTINE swap_sp\n\n\n SUBROUTINE swap_dp(a,b)\n\n IMPLICIT NONE\n\n REAL(dp), INTENT(inout) :: a, b\n REAL(dp) :: dum\n dum = a\n a = b\n b = dum\n\n END SUBROUTINE swap_dp\n\nEND MODULE mo_boxcox\n", "meta": {"hexsha": "129a17aab0574d35fc217f9f64790a6146ec0abf", "size": 30837, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mo_boxcox.f90", "max_stars_repo_name": "mcuntz/jams_fortran", "max_stars_repo_head_hexsha": "a1dcab78eda21f930aa6c8c3633598a522f01659", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2020-02-28T00:14:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-20T23:32:41.000Z", "max_issues_repo_path": "mo_boxcox.f90", "max_issues_repo_name": "mcuntz/jams_fortran", "max_issues_repo_head_hexsha": "a1dcab78eda21f930aa6c8c3633598a522f01659", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-05-09T15:33:11.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-28T16:16:09.000Z", "max_forks_repo_path": "mo_boxcox.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.991959799, "max_line_length": 128, "alphanum_fraction": 0.5127282161, "num_tokens": 9195, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778824, "lm_q2_score": 0.7905303137346446, "lm_q1q2_score": 0.6962967903904136}} {"text": "! NAME: PI SPMD ... a simple version.\r\n! This program will numerically compute the integral of\r\n! 4/(1+x*x) \r\n! from 0 to 1. The value of this integral is pi -- which \r\n! is great since it gives us an easy way to check the answer.\r\n\r\n! The program was parallelized using OpenMP and an SPMD \r\n! algorithm. The following OpenMP specific lines were \r\n! added: \r\n\r\n! (1) A line to include omp.h -- the include file that \r\n! contains OpenMP's function prototypes and constants.\r\n\r\n! (2) A pragma that tells OpenMP to create a team of threads\r\n! with an integer variable i being created for each thread.\r\n\r\n! (3) two function calls: one to get the thread ID (ranging\r\n! from 0 to one less than the number of threads), and the other\r\n! returning the total number of threads.\r\n\r\n! (4) A cyclic distribution of the loop by changing loop control\r\n! expressions to run from the thread ID incremented by the number \r\n! of threads. Local sums accumlated into sum[id].\r\n\r\n! Note that this program will show low performance due to \r\n! false sharing. In particular, sum(id) is unique to each\r\n! thread, but adfacent values of this array share a cache line\r\n! causing cache thrashing as the program runs.\r\n\r\n! History: C code written by Tim Mattson, 11/1999\r\n! Adapted to Fortran code by Helen He and Tim Mattson, 09/2017\r\n! Changed to Fortran90 code by Helen He, 11/2020\r\n\r\n PROGRAM MAIN\r\n USE OMP_LIB\r\n IMPLICIT NONE\r\n\r\n INTEGER :: i, j, id, numthreads, nthreads\r\n INTEGER, PARAMETER :: num_steps = 100000000\r\n INTEGER, PARAMETER :: MAX_THREADS = 4\r\n INTEGER, PARAMETER :: PADDING = 8\r\n REAL*8 :: pi, step, full_sum, x\r\n REAL*8 :: start_time, run_time\r\n REAL*8 :: sum(0:MAX_THREADS-1, PADDING)\r\n\r\n step = 1.0 / num_steps\r\n\r\n start_time = OMP_GET_WTIME()\r\n\r\n DO j=1,MAX_THREADS\r\n\r\n CALL OMP_SET_NUM_THREADS(j)\r\n full_sum = 0.0\r\n start_time = omp_get_wtime()\r\n\r\n!$OMP PARALLEL PRIVATE(id,x,numthreads)\r\n id = omp_get_thread_num()\r\n numthreads = OMP_GET_NUM_THREADS()\r\n sum(id,1) = 0.0\r\n\r\n IF (id == 0) THEN\r\n nthreads = numthreads\r\n ENDIF\r\n\r\n DO i = id, num_steps - 1, numthreads\r\n x = (i + 0.5) * step\r\n sum(id,1) = sum(id,1) + 4.0 / (1.0 + x * x)\r\n ENDDO\r\n!$OMP END PARALLEL\r\n\r\n full_sum = 0.0\r\n DO i = 0, nthreads - 1\r\n full_sum = full_sum + sum(i,1)\r\n ENDDO\r\n\r\n pi = step * full_sum\r\n run_time = OMP_GET_WTIME() - start_time\r\n WRITE(*,100) pi, run_time, nthreads\r\n100 FORMAT('pi is ',f15.8,' in ',f8.3,' secs and ',i3,' threads')\r\n\r\n ENDDO\r\n\r\n END PROGRAM MAIN\r\n", "meta": {"hexsha": "90841bd6902f7652d6cf148cb3b6cb0edfc66b18", "size": 2538, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Exercises/Fortran/solutions/pi_spmd_simple_padded.f90", "max_stars_repo_name": "zafar-hussain/OmpCommonCore", "max_stars_repo_head_hexsha": "e5457dcc6849f921e92ae3054486be56e39e6ebf", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 37, "max_stars_repo_stars_event_min_datetime": "2020-04-21T18:05:37.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:10:18.000Z", "max_issues_repo_path": "Exercises/Fortran/solutions/pi_spmd_simple_padded.f90", "max_issues_repo_name": "zafar-hussain/OmpCommonCore", "max_issues_repo_head_hexsha": "e5457dcc6849f921e92ae3054486be56e39e6ebf", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-12-09T19:42:54.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T21:27:04.000Z", "max_forks_repo_path": "Exercises/Fortran/solutions/pi_spmd_simple_padded.f90", "max_forks_repo_name": "zafar-hussain/OmpCommonCore", "max_forks_repo_head_hexsha": "e5457dcc6849f921e92ae3054486be56e39e6ebf", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2020-09-05T18:54:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-23T02:19:12.000Z", "avg_line_length": 30.2142857143, "max_line_length": 72, "alphanum_fraction": 0.6627265563, "num_tokens": 756, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970654616711, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.6962967826693491}} {"text": "!---------------------------------------------------------------------!\n! PHAML !\n! !\n! The Parallel Hierarchical Adaptive MultiLevel code for solving !\n! linear elliptic partial differential equations of the form !\n! (PUx)x + (QUy)y + RU = F on 2D polygonal domains with mixed !\n! boundary conditions, and eigenvalue problems where F is lambda*U. !\n! !\n! PHAML is public domain software. It was produced as part of work !\n! done by the U.S. Government, and is not subject to copyright in !\n! the United States. !\n! !\n! William F. Mitchell !\n! Applied and Computational Mathematics Division !\n! National Institute of Standards and Technology !\n! william.mitchell@nist.gov !\n! http://math.nist.gov/phaml !\n! !\n!---------------------------------------------------------------------!\n\n!----------------------------------------------------\n! This file contains the main program supplied by the user.\n! This version illustrates an eigenvalue problem, the Schroedinger\n! Equation for a simple harmonic oscillator.\n!----------------------------------------------------\n\n! ------------\nprogram phaml_master\n! ------------\n\n!----------------------------------------------------\n! This is the main program.\n!----------------------------------------------------\n\n!----------------------------------------------------\n! Modules used are:\n\nuse phaml\nuse phaml_user_mod\n!----------------------------------------------------\n\nimplicit none\n\n!----------------------------------------------------\n! Local variables:\n\ninteger :: nvert,num_eval,nproc,print_err\nreal(my_real) :: lambda0\ntype(phaml_solution_type) :: pde1\n\n!----------------------------------------------------\n! Begin executable code\n\n! Solve on a grid with 1000 vertices\n\nnvert = 1000\n\n! Find the eigenvalue closest to lambda0. For the smallest eigenvalue,\n! use -huge(0.0_my_real). For interior eigenvalues, you must use a\n! solver that handles indefinite problems, for example\n! solver=LAPACK_INDEFINITE_SOLVER or solver=MUMPS_GEN_SOLVER\n\nlambda0 = -huge(0.0_my_real)\n!print *,\"lambda0?\"\n!read *,lambda0\n\n! Set the number of eigenvalues to compute. It will compute the\n! num_eval eigenvalues closest to lambda0.\n\nnum_eval = 1\nprint *,\"number of eigenvalues?\"\nread *,num_eval\n\n! Input number of processors\n\nnproc=1\nprint *,\"number of processors?\"\nread *,nproc\n\n! Input the parameter that determines the width of the well.\n! The smallest eigenvalue is sqrt(prob_param*(2 sqrt(3))).\n! 25 is a nice easy one (gives an eigenvalue of 9.6592583...)\n\nprob_param=25.0_my_real\n!print *,\"parameter that determines width of well (for example, 25.0)?\"\n!read *,prob_param\n\n! Make sure prob_param is positive.\n\nif (prob_param < 0.0_my_real) then\n print *,\"the parameter must be positive; changing to \",abs(prob_param)\n prob_param = abs(prob_param)\nendif\n\n! The true solution is known for the smallest eigenvalue. Print the error\n! only if lambda0 is less than the smallest. The error estimate, but not\n! the actual error, will be printed for the other eigenvalues.\n\nif (lambda0 < sqrt(2*prob_param)) then\n print_err = PHASES\nelse\n print_err = NEVER\nendif\n\n! Create the pde data structure\n\ncall phaml_create(pde1,nproc,eq_type=EIGENVALUE, &\n! spawn_form=DEBUG_SLAVE, debug_command=\"gdb\", &\n draw_grid_who = MASTER)\n\n! Send prob_param to the slaves\n\ncall update_usermod(pde1)\n\n! Solve the problem\n\ncall phaml_solve_pde(pde1, &\n max_vert=nvert, &\n sequential_vert=250, &\n print_grid_when=PHASES, &\n print_grid_who=MASTER, &\n print_error_when=print_err, &\n print_error_who=MASTER, &\n print_error_what=ENERGY_LINF_ERR, &\n print_errest_what=ENERGY_LINF_ERREST, &\n print_eval_when=PHASES, &\n print_eval_who=MASTER, &\n draw_grid_when=PHASES, &\n mg_cycles=10, &\n mg_tol=MG_NO_TOL, &\n inc_quad_order=3, &\n lambda0 = lambda0, &\n num_eval = num_eval, &\n\t pause_after_phases = .true.,&\n pause_at_start = .true., &\n pause_at_end=.true.)\n\n! Destroy the pde data structure\n\ncall phaml_destroy(pde1)\n\nend program phaml_master\n", "meta": {"hexsha": "73a789e1dfab2e5f379f2f9851d545e53a750cbd", "size": 5082, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/eigenvalue/master.f90", "max_stars_repo_name": "qsnake/phaml", "max_stars_repo_head_hexsha": "8925b4c32657bbd9f81cd5f8f9d6739151c66fec", "max_stars_repo_licenses": ["mpich2"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-09-07T15:46:34.000Z", "max_stars_repo_stars_event_max_datetime": "2018-09-07T15:46:34.000Z", "max_issues_repo_path": "examples/eigenvalue/master.f90", "max_issues_repo_name": "qsnake/phaml", "max_issues_repo_head_hexsha": "8925b4c32657bbd9f81cd5f8f9d6739151c66fec", "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/eigenvalue/master.f90", "max_forks_repo_name": "qsnake/phaml", "max_forks_repo_head_hexsha": "8925b4c32657bbd9f81cd5f8f9d6739151c66fec", "max_forks_repo_licenses": ["mpich2"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.5384615385, "max_line_length": 74, "alphanum_fraction": 0.4952774498, "num_tokens": 1012, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473879530491, "lm_q2_score": 0.7981867825403176, "lm_q1q2_score": 0.6962961548476945}} {"text": "!*****************************************************************************************\n!> author: Jacob Williams\n! date: 2012\n!\n! Geometry routines.\n\n module geometry_module\n\n use kind_module, only: wp\n use vector_module, only: cross\n\n implicit none\n\n private\n\n !public routines:\n public :: locpt\n public :: distance_from_point_to_line\n public :: distance_from_point_to_line_segment\n public :: distance_from_point_to_path\n\n !unit test routine:\n public :: geometry_unit_test\n\n contains\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! given a polygonal line connecting the vertices (x(i),y(i))\n! (i = 1,...,n) taken in this order. it is assumed that the\n! polygonal path is a loop, where (x(n),y(n)) = (x(1),y(1))\n! or there is an arc from (x(n),y(n)) to (x(1),y(1)).\n!\n! (x0,y0) is an arbitrary point and l and m are variables.\n! l and m are assigned the following values:\n!\n! l = -1 if (x0,y0) is outside the polygonal path\n! l = 0 if (x0,y0) lies on the polygonal path\n! l = 1 if (x0,y0) is inside the polygonal path\n!\n! m = 0 if (x0,y0) is on or outside the path. if (x0,y0)\n! is inside the path then m is the winding number of the\n! path around the point (x0,y0).\n!\n!# History\n! * Original version from the NSWC Library\n! * Modified by J. Williams : 08/04/2012 : refactored to modern Fortran\n\n pure subroutine locpt (x0, y0, x, y, n, l, m)\n\n implicit none\n\n !arguments:\n integer,intent(in) :: n\n real(wp),intent(in) :: x0\n real(wp),intent(in) :: y0\n real(wp),dimension(n),intent(in) :: x\n real(wp),dimension(n),intent(in) :: y\n integer,intent(out) :: l\n integer,intent(out) :: m\n\n !constants:\n real(wp),parameter :: eps = epsilon(1.0_wp)\n real(wp),parameter :: pi = atan2(0.0_wp, -1.0_wp)\n real(wp),parameter :: pi2 = 2.0_wp*pi\n real(wp),parameter :: tol = 4.0_wp*eps*pi\n\n !local variables:\n integer :: i,n0\n real(wp) :: u,v,theta1,sum,theta,angle,thetai\n\n n0 = n\n if (x(1) == x(n) .and. y(1) == y(n)) n0 = n - 1\n l = -1\n m = 0\n u = x(1) - x0\n v = y(1) - y0\n\n if (u == 0.0_wp .and. v == 0.0_wp) then\n\n l = 0 !(x0, y0) is on the boundary of the path\n\n else\n\n if (n0 >= 2) then\n\n theta1 = atan2(v, u)\n sum = 0.0_wp\n theta = theta1\n\n do i = 2,n0\n\n u = x(i) - x0\n v = y(i) - y0\n\n if (u == 0.0_wp .and. v == 0.0_wp) then\n l = 0 !(x0, y0) is on the boundary of the path\n exit\n end if\n\n thetai = atan2(v, u)\n angle = abs(thetai - theta)\n if (abs(angle - pi) < tol) then\n l = 0 !(x0, y0) is on the boundary of the path\n exit\n end if\n\n if (angle > pi) angle = angle - pi2\n if (theta > thetai) angle = -angle\n sum = sum + angle\n theta = thetai\n\n end do\n\n if (l/=0) then\n\n angle = abs(theta1 - theta)\n if (abs(angle - pi) < tol) then\n\n l = 0 !(x0, y0) is on the boundary of the path\n\n else\n\n if (angle > pi) angle = angle - pi2\n if (theta > theta1) angle = -angle\n sum = sum + angle !sum = 2*pi*m where m is the winding number\n m = abs(sum)/pi2 + 0.2_wp\n if (m /= 0) then\n l = 1\n if (sum < 0.0_wp) m = -m\n end if\n\n end if\n\n end if\n\n end if\n\n end if\n\n end subroutine locpt\n!*****************************************************************************************\n\n!*****************************************************************************************\n!> author: Jacob Williams\n! date:8/2012\n!\n! Compute the distance between the point X and the line defined\n! by the two points X1 and X2.\n!\n!# References\n! 1. http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html\n\n pure function distance_from_point_to_line (x1, x2, x) result(d)\n\n implicit none\n\n real(wp),dimension(3),intent(in) :: x1\n real(wp),dimension(3),intent(in) :: x2\n real(wp),dimension(3),intent(in) :: x\n real(wp) :: d\n\n real(wp),dimension(3) :: x21\n real(wp) :: x21_mag\n\n x21 = x2 - x1\n x21_mag = norm2(x21)\n\n if (x21_mag/=0.0_wp) then\n\n d = norm2( cross( x21, x1 - x ) ) / x21_mag\n\n else\n\n d = norm2(x1 - x)\n\n end if\n\n end function distance_from_point_to_line\n!*****************************************************************************************\n\n!*****************************************************************************************\n!> author: Jacob Williams\n! date:8/2012\n!\n! Compute the distance between a line segment and a point.\n!\n!# References\n! 1. http://forums.codeguru.com/showthread.php?194400-Distance-between-point-and-line-segment\n!\n!@note x,x1,x2 should all be the same length\n\n pure function distance_from_point_to_line_segment(x1, x2, x) result(d)\n\n implicit none\n\n real(wp),dimension(:),intent(in) :: x1\n real(wp),dimension(:),intent(in) :: x2\n real(wp),dimension(:),intent(in) :: x\n real(wp) :: d\n\n real(wp),dimension(size(x1)) :: x12\n real(wp) :: s\n real(wp) :: x12_mag\n\n x12 = x1 - x2\n x12_mag = norm2(x12)\n\n if (x12_mag==0.0_wp) then\n\n d = norm2(x1 - x)\n\n else\n\n s = dot_product( x1-x, x12 ) / dot_product( x12, x12 )\n\n !if the projection is not on the segment,\n ! then use the closest end point:\n if (s<0.0_wp) then\n s = 0.0_wp\n else if (s>1.0_wp) then\n s = 1.0_wp\n end if\n\n d = norm2( x - x1 + s*x12 )\n\n end if\n\n end function distance_from_point_to_line_segment\n!*****************************************************************************************\n\n!*****************************************************************************************\n!> author: Jacob Williams\n! date:8/2012\n!\n! Compute the distance between a point and a polygonal path.\n! Given a point (x0,y0), and a path (x(n),y(n)), the distance\n! to the path is the distance to the closest line segment (x(i),y(i)).\n\n function distance_from_point_to_path(x0, y0, x, y, n) result(d)\n\n implicit none\n\n !arguments:\n integer,intent(in) :: n\n real(wp),intent(in) :: x0\n real(wp),intent(in) :: y0\n real(wp),dimension(n),intent(in) :: x\n real(wp),dimension(n),intent(in) :: y\n real(wp) :: d\n\n integer :: l,m,i\n real(wp) :: dmin\n\n !is the point inside, outside, or on the path:\n call locpt (x0, y0, x, y, n, l, m)\n\n select case(l)\n\n case(1,-1) !point is not on the path\n\n if (n==1) then\n\n !only one point in the path:\n d = norm2([x0-x(1), y0-y(1)])\n\n else\n\n do i=1,n !loop through all line segments in the path\n !the distance to the path is the distance from the closest line segment\n\n if (i0 if inside the path\n\n case default !point is on the path\n\n d = 0.0_wp\n\n end select\n\n end function distance_from_point_to_path\n!*****************************************************************************************\n\n!*****************************************************************************************\n!> author: Jacob Williams\n! date:8/2012\n!\n! Unit test routine\n!\n!# Output\n!\n! x0,y0= 0.59999999999999998 0.59999999999999998\n! l= 1\n! m= -1\n! dist to path= 0.40000000000000002\n!\n! x0,y0= 1.5000000000000000 0.50000000000000000\n! l= -1\n! m= 0\n! dist to path= -0.50000000000000000\n!\n! x0,y0= 1.0000000000000000 0.0000000000000000\n! l= 0\n! m= 0\n! dist to path= 0.0000000000000000\n\n subroutine geometry_unit_test()\n\n implicit none\n\n integer :: l,m\n real(wp) :: x0,y0\n\n !a 1x1 square:\n integer,parameter :: n = 4\n real(wp),dimension(n),parameter :: x = [0.0_wp, 0.0_wp, 1.0_wp, 1.0_wp]\n real(wp),dimension(n),parameter :: y = [0.0_wp, 1.0_wp, 1.0_wp, 0.0_wp]\n\n x0 = 0.6_wp !inside the path\n y0 = 0.6_wp\n call go()\n\n x0 = 1.5_wp !outside the path\n y0 = 0.5_wp\n call go()\n\n x0 = 10.0_wp !outside the path\n y0 = 0.0_wp\n call go()\n\n x0 = 1.0_wp !on the path\n y0 = 0.0_wp\n call go()\n\n contains\n\n subroutine go() !call locpt for the x0,y0 point, and print results\n implicit none\n\n real(wp) :: d\n\n call locpt (x0, y0, x, y, n, l, m)\n\n write(*,*) ''\n write(*,*) 'x0,y0=',x0,y0\n write(*,*) 'l=',l\n write(*,*) 'm=',m\n\n d = distance_from_point_to_path(x0, y0, x, y, n)\n write(*,*) 'dist to path=',d\n\n\n end subroutine go\n\n end subroutine geometry_unit_test\n!*****************************************************************************************\n\n!*****************************************************************************************\n end module geometry_module\n!*****************************************************************************************\n", "meta": {"hexsha": "be15a8cc7adfaf07ecc185ad2a5e37f83d05f84e", "size": 10369, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/geometry_module.f90", "max_stars_repo_name": "jacobwilliams/Fortran-Astrodynamics-Toolk", "max_stars_repo_head_hexsha": "f8e18642dc8d78473d233b8fa6078fdbf7a1d6fc", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 122, "max_stars_repo_stars_event_min_datetime": "2015-01-29T05:40:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:20:21.000Z", "max_issues_repo_path": "src/geometry_module.f90", "max_issues_repo_name": "gandymagic/Fortran-Astrodynamics-Toolkit", "max_issues_repo_head_hexsha": "7f176fabc8c36cc1981349b02eeb6d8112f2bfbc", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 25, "max_issues_repo_issues_event_min_datetime": "2015-06-10T02:16:59.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T04:28:55.000Z", "max_forks_repo_path": "src/geometry_module.f90", "max_forks_repo_name": "gandymagic/Fortran-Astrodynamics-Toolkit", "max_forks_repo_head_hexsha": "7f176fabc8c36cc1981349b02eeb6d8112f2bfbc", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 43, "max_forks_repo_forks_event_min_datetime": "2015-02-12T13:24:23.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-30T04:30:49.000Z", "avg_line_length": 27.2152230971, "max_line_length": 95, "alphanum_fraction": 0.449705854, "num_tokens": 2923, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.7981867777396212, "lm_q1q2_score": 0.696296140064018}} {"text": "module numz\n! module defines the basic real type and pi\n integer, parameter:: d8 = selected_real_kind(14)\n integer, parameter:: d4 = selected_real_kind(5)\n real(d8), parameter :: pi = 3.141592653589793239_d8\nend module\nprogram doinv\nuse numz\nimplicit none\nreal(d8), allocatable :: a8(:,:),b8(:,:)\nreal(d8) :: tot\ninteger n,nrhs\ninteger lda, ldb, info \ninteger, allocatable :: ipiv(:)\nlogical :: do4,do8\ninteger stime,etime,rtime,mtime,m,i\ncharacter*1 trans\nlogical :: lu\n\nnrhs=1\nread(*,*,end=1234,err=1234)n,m,lu\ngoto 3456\n1234 continue\nn=2\nm=10\nlu=.true.\n3456 continue\nlda=n\nldb=n\nallocate(ipiv(n))\ntot=0.0\n\n\n allocate(a8(n,n))\n allocate(b8(n,nrhs))\n if(n .eq. 2)then\n a8(1,1)=1;\n a8(2,1)=6;\n a8(1,2)=3;\n a8(2,2)=7;\n b8(1,1)=2;\n b8(2,1)=4;\n!octave:9> a8\\b8\n!ans =\n!\n! -0.18182\n! 0.72727\n else\n CALL RANDOM_NUMBER(a8)\n CALL RANDOM_NUMBER(b8)\n endif\n do i=1,m\n trans=\"N\"\n call system_clock(stime, rtime,mtime)\n if (lu)then\n call dgetrf( n, n, a8, n, ipiv, info )\n call dgetrs(trans, n, nrhs, a8, lda, ipiv, b8, ldb, info)\n else\n call dgesv( n, nrhs, a8, lda, ipiv, b8, ldb, info )\n endif\n! call sgesv( n, nrhs, a8, lda, ipiv, b8, ldb, info )\n call system_clock(etime)\n if (etime .lt. stime)etime=etime+mtime\n tot=tot+real(etime - stime,d8) / real(rtime,d8)\n if(n .le. 10)write(*,*)b8\n if ( i .ne. m)then \n CALL RANDOM_NUMBER(a8)\n CALL RANDOM_NUMBER(b8)\n endif\n enddo \n print *, \"size:\",n,\" elapsed time: \",tot/m,\" did lu:\",lu\n\nend program\n\n", "meta": {"hexsha": "91f97676d9d92958c0d72488ba4de9c6ac3f80ce", "size": 1555, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "scalapack/rcs09/simpinv.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": "scalapack/rcs09/simpinv.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": "scalapack/rcs09/simpinv.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": 20.7333333333, "max_line_length": 63, "alphanum_fraction": 0.6186495177, "num_tokens": 606, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.7981867753392728, "lm_q1q2_score": 0.6962961326721792}} {"text": "\n subroutine setup_Gaussian_quadrature( &\n ngeomax, maxintstr, maxstr, &\n maxstr_internal, vza, sza, &\n imuv, imu0, gmu, &\n gwt, gmumin)\n\n!---------------------------------------------------------------------\n! Subroutine:\n! setup_Gaussian_quadrature\n!-------------------------------------------------------------------\n\n implicit none\n\n integer,parameter::dp=selected_real_kind(8) !double precision\n\n integer,intent(in):: &\n ngeomax, &\n maxintstr, &\n maxstr, &\n maxstr_internal\n\n real(kind=dp),intent(in):: &\n vza(ngeomax), &\n sza(ngeomax)\n\n integer:: &\n iv,i\n\n! Gaussian quadrature\n! internals streams up and down\n real(kind=dp):: &\n intgmu(maxintstr), &\n intgwt(maxintstr) \n\n real(kind=dp):: &\n pi,deg2rad,rad2deg\n \n! total streams up only\n real(kind=dp),intent(out):: &\n gmu(maxstr), & \n gwt(maxstr), &\n gmumin \n\n integer,intent(out):: & \n imuv(ngeomax), &\n imu0(ngeomax) \n\n!------------------------------------------------------\n\n pi = 2.d0*asin(1.d0)\n rad2deg = 180.d0/pi\n deg2rad = pi/180.d0\n\n! Viewing angles\n do iv=1,ngeomax\n! index of viewing angles\n imuv(iv) = maxintstr/2+iv\n gmu(imuv(iv)) = cos(vza(iv)*deg2rad)\n gwt(imuv(iv)) = 1.d0\n! index of solar zenith angles\n imu0(iv) = maxintstr/2+ngeomax+iv\n gmu(imu0(iv)) = cos(sza(iv)*deg2rad)\n gwt(imu0(iv)) = 1.d0\n enddo\n\n! Setup Gaussian quadrature up and down \n call Gaussian_quadrature(maxintstr, intgmu, intgwt) \n \n! save up (positive) angles in reverse order \n! and determine minimum gmu angle (gmumin)\n do i=1,maxintstr/2\n gmu(i) = intgmu(maxintstr/2+1-i)\n gwt(i) = intgwt(maxintstr/2+1-i)\n enddo\n\n! minimum angle of internal streams\n gmumin = minval(gmu(1:maxstr_internal))\n\n return\nend subroutine setup_Gaussian_quadrature\n\n!*********************************************************************\n\nsubroutine Gaussian_quadrature(maxintstr, gmu, gwt)\n!---------------------------------------------------------------------\n!\n! Gaussian_quadrature\n!\n! Set up Gaussian quadrature: \n! The sign of gmu is chosen that DG_MU and -DG_MU denote the \n! downward and upward direction, respectively. Thus, U0 is positive, \n! and the direction of the direct beam is (U0,0) refering to the \n! principle plane. \n!\n!---------------------------------------------------------------------\n implicit none\n integer,parameter::dp=selected_real_kind(8) !double precision\n integer,intent(in)::maxintstr\n integer::i\n! temporary arrays \n real(kind=dp),dimension(maxintstr):: tmp_mu, tmp_wt\n! Double Gaussian quadrature\n real(kind=dp),dimension(maxintstr),intent(out):: & \n gmu(maxintstr), & !quadrature points\n gwt(maxintstr) !quadrature weights\n if((maxintstr+1)/2.ne.maxintstr/2)then\n write(*,*) 'quad.f90: Bad value of maxintstr!'\n write(*,*) 'Choose an even integer for maxintstr.'\n stop\n endif\n! maxintstr=2; twostream, only up and down \n if(maxintstr.eq.2)then\n gmu(1) = 1.d0\n gmu(2) = -1.d0\n gwt(1) = 1.d0\n gwt(2) = 1.d0\n return\n endif\n! only positive values are calculated\n call dgauss(maxintstr/2, tmp_mu, tmp_wt)\n! downward direction\n! sort maxintstr/2 -> 1,\n! maxintstr/2-1 -> 2, etc. \n do i=1,maxintstr/2\n gmu(maxintstr/2-i+1) = tmp_mu(i) \n gwt(maxintstr/2-i+1) = tmp_wt(i)\n enddo\n! upward values\n do i=1,maxintstr/2 \n gmu(maxintstr+1-i) = -gmu(i)\n gwt(maxintstr+1-i) = gwt(i)\n enddo\n return\nend subroutine Gaussian_quadrature \n\n!**********************************************************************\n\nsubroutine dgauss(M, gmu, gwt)\n!----------------------------------------------------------------------\n!\n! dgauss\n!\n! Compute weights and abscissae for ordinary Gaussian quadrature \n! (no weight function inside integral) on the interval (0,1) \n! \n! input : M order of quadrature rule \n! \n! output : gmu(I) I = 1 TO M array of abscissae \n! gwt(I) I = 1 TO M array of weights \n! \n! reference: Davis, P.J. and P. Rabinowitz, \n! Methods of Numerical Integration, \n! Academic Press, New York, pp. 87, 1975. \n! \n! method: Compute the abscissae as roots of the Legendre \n! polynomial P-sub-M using a cubically convergent \n! refinement of Newton's method. Compute the \n! weights from EQ. 2.7.3.8 of Davis/Rabinowitz. Note \n! that Newton's method can very easily diverge; only a \n! very good initial guess can guarantee convergence. \n! The initial guess used here has never led to divergence \n! even for M up to 1000. \n! \n! accuracy: at least 13 significant digits \n! \n! internal variables: \n! \n! ITER : number of Newton Method iterations \n! MAXIT : maximum allowed iterations of Newton Method \n! PM2,PM1,P : 3 successive Legendre polynomials \n! PPR : derivative of Legendre polynomial \n! P2PRI : 2nd derivative of Legendre polynomial \n! TOL : convergence criterion for Legendre poly root iteration\n! X,XI : successive iterates in cubically-convergent version\n! of Newtons Method (seeking roots of Legendre poly.)\n!----------------------------------------------------------------------\n implicit none\n integer,parameter::dp=selected_real_kind(8) !double precision\n integer,intent(in)::M\n integer:: ITER, LIM, NP1, NN, k\n real(kind=dp):: CONA, PI, T\n real(kind=dp):: EN, NNP1, P, PM1, PM2, PPR, P2PRI, PROD\n real(kind=dp):: tmp, X, XI\n real(kind=dp),parameter:: &\n MAXIT = 1000, &\n ONE = 1.d0, & \n TWO = 2.d0, &\n EPSILON = 1.d-14 \n real(kind=dp),intent(out):: gmu(M), gwt(M)\n!---------------------------------------------------------------------\n pi = 2.d0*DASIN(1.d0)\n if(M.LT.1)THEN\n WRITE(*,*) 'Dgauss -- Bad value of M'\n STOP\n endif\n if(M.EQ.1)THEN\n gmu(1) = 0.d0\n gwt(1) = 1.d0\n return\n endif\n EN = M\n NP1 = M + 1\n NNP1 = M * NP1\n CONA = dble(M-1) / dble(8 * M**3)\n LIM = M / 2\n do k = 1,LIM\n! initial guess for k-th root of Legendre polynomial, \n! from Davis/Rabinowitz (2.7.3.3a)\n T = dble(4*k-1)*pi/dble(4*M+2)\n X = DCOS(T+CONA/DTAN(T))\n ITER = 0\n! upward recurrence for Legendre polynomials\n10 ITER = ITER + 1\n PM2 = ONE\n PM1 = X\n do NN = 2,M\n P = (dble(2*NN-1) * X * PM1 - dble(NN-1) * PM2 ) / dble(NN)\n PM2 = PM1\n PM1 = P\n enddo\n! Newton method\n tmp = ONE / ( ONE - X**2 )\n PPR = EN * ( PM2 - X * P ) * tmp\n P2PRI = ( TWO * X * PPR - NNP1 * P ) * tmp\n XI = X - ( P / PPR ) * ( ONE + ( P / PPR ) * P2PRI / ( TWO * PPR ) )\n! check for convergence\n if(DABS(XI-X).GT.EPSILON)THEN\n if(ITER.GT.MAXIT)THEN\n WRITE(*,*)'dgauss -- MAX ITERATION COUNT'\n STOP\n endif\n X = XI\n GOTO 10\n endif\n! iteration finished--calculate weights, abscissae for (-1,1)\n gmu(k) = -X\n gwt(k) = TWO / (tmp*(EN*PM2)**2)\n gmu(NP1-k) = -GMU(K)\n gwt(NP1-k) = GWT(K)\n enddo\n! set middle abscissa and weight for rules of odd order\n if(MOD(M,2).NE.0)THEN\n gmu(LIM+1) = 0.d0\n PROD = ONE\n do k = 3, M, 2\n PROD = PROD*dble(k)/dble(k-1)\n enddo\n gwt(LIM+ 1) = TWO/PROD**2\n endif\n! convert from (-1,1) to (0,1) and re-sort\n do k=1,M\n gmu(k) = 0.5d0 * gmu(K) + 0.5d0\n gwt(k) = 0.5d0 * gwt(K)\n enddo\n return\nend subroutine dgauss\n", "meta": {"hexsha": "a062b043ec45dcff358962c6af64ffa89d6cb212", "size": 8347, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/setquad.f90", "max_stars_repo_name": "rutgervandeelen/das", "max_stars_repo_head_hexsha": "4727a8daaf87c817fb49fbe6ce8eaa996210e7dc", "max_stars_repo_licenses": ["MIT"], "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/setquad.f90", "max_issues_repo_name": "rutgervandeelen/das", "max_issues_repo_head_hexsha": "4727a8daaf87c817fb49fbe6ce8eaa996210e7dc", "max_issues_repo_licenses": ["MIT"], "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/setquad.f90", "max_forks_repo_name": "rutgervandeelen/das", "max_forks_repo_head_hexsha": "4727a8daaf87c817fb49fbe6ce8eaa996210e7dc", "max_forks_repo_licenses": ["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.3527131783, "max_line_length": 76, "alphanum_fraction": 0.4915538517, "num_tokens": 2445, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818864, "lm_q2_score": 0.766293653760418, "lm_q1q2_score": 0.6962681319051958}} {"text": "!\n! Copyright 2016 ARTED developers\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 implied.\n! See the License for the specific language governing permissions and\n! limitations under the License.\n!\nprogram nex_analysis\n implicit none\n real(8),parameter :: dw=0.1d0/27.2d0 ! Energy resolution [eV/27.2 =a.u.]\n real(8),parameter :: Pi=3.141592653589793d0\n real(8),allocatable :: esp(:,:),occ(:,:)\n real(8),allocatable :: DoS(:),DoS_occ(:)\n real(8) :: esp_min,esp_max,esp_d\n real(8) :: wi,wf,w\n integer :: Nw,iw\n integer :: ik,ib,NK,NB\n\n read(*,*)\n read(*,*)NB,NK\n allocate(esp(NB,NK),occ(NB,NK))\n\n do ik=1,NK\n do ib=1,NB\n read(*,*)esp(ib,ik),occ(ib,ik)\n end do\n end do\n\n esp_min=minval(esp)\n esp_max=maxval(esp)\n\n esp_d=(esp_max-esp_min)*1.0d0\n wi=esp_min-esp_d*0.1\n wf=esp_max+esp_d*0.1\n\n Nw=aint((wf-wi)/(dw/10d0))+1\n allocate(DoS(0:Nw),DoS_occ(0:Nw))\n DoS=0d0\n DoS_occ=0d0\n\n do ik=1,NK\n do ib=1,NB\n do iw=0,Nw\n w=wi+dble(iw)*(dw/10d0)\n DoS(iw)=DoS(iw)+(2d0/dble(NK))*(1d0/sqrt(2d0*pi*dw**2))*exp(-0.5d0*((w-esp(ib,ik))/dw)**2)\n DoS_occ(iw)=DoS_occ(iw)+occ(ib,ik)*(1d0/sqrt(2d0*pi*dw**2))*exp(-0.5d0*((w-esp(ib,ik))/dw)**2)\n end do\n end do\n end do\n\n \n do iw=0,Nw\n w=wi+dble(iw)*(dw/10d0)\n write(*,'(100e26.16e3)')w,DoS(iw),DoS_occ(iw)\n end do\n\nend program nex_analysis\n \n\n", "meta": {"hexsha": "33dc2093f7a5e78438ea453058e775985d5d297a", "size": 1751, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "analysis/nex_analysis.f90", "max_stars_repo_name": "shunsuke-sato/ARTED_noc", "max_stars_repo_head_hexsha": "07935bbd0ca504317999262de29bb66ee07454d3", "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": "analysis/nex_analysis.f90", "max_issues_repo_name": "shunsuke-sato/ARTED_noc", "max_issues_repo_head_hexsha": "07935bbd0ca504317999262de29bb66ee07454d3", "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": "analysis/nex_analysis.f90", "max_forks_repo_name": "shunsuke-sato/ARTED_noc", "max_forks_repo_head_hexsha": "07935bbd0ca504317999262de29bb66ee07454d3", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.75, "max_line_length": 102, "alphanum_fraction": 0.6424900057, "num_tokens": 675, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818864, "lm_q2_score": 0.766293648423189, "lm_q1q2_score": 0.696268127055694}} {"text": " SUBROUTINE cosft1 (Y, N)\n!\n! This is a fast cosine transform routine\n! from Numerical Recipes. Computes the transform of Y(1:N+1) where N is\n! power of two. This is also the inverse transform but in that case\n! multiply Y by 2/N.\n!\n IMPLICIT NONE\n INTEGER n, j\n REAL(4) Y (N + 1), SUM, y1, y2\n REAL(8) WR, WI, WPR, WPI, WTEMP, THETA\n THETA = 3.141592653589793D0 / DBLE (n)\n WR = 1.0D0\n WI = 0.0D0\n WPR = - 2.0D0 * DSIN (0.5D0 * THETA) **2\n WPI = DSIN (THETA)\n SUM = .5d0 * (Y (1) - y (n + 1) )\n y (1) = .5d0 * (y (1) + y (n + 1) )\n DO 11 J = 1, n / 2 - 1\n WTEMP = WR\n WR = WR * WPR - WI * WPI + WR\n WI = WI * WPR + WTEMP * WPI + WI\n Y1 = 0.5d0 * (Y (J + 1) + Y (n - J + 1) )\n Y2 = (Y (J + 1) - Y (n - J + 1) )\n Y (J + 1) = Y1 - WI * Y2\n Y (n - J + 1) = Y1 + WI * Y2\n SUM = SUM + WR * Y2\n11 END DO\n CALL realft (Y, n, + 1)\n y (n + 1) = y (2)\n Y (2) = SUM\n DO 12 J = 4, N, 2\n SUM = SUM + Y (J)\n Y (J) = SUM\n12 END DO\n RETURN\n ENDSUBROUTINE COSFT1\n", "meta": {"hexsha": "76557021643e10a367954712fc98f6bdb35d4492", "size": 1129, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fft/cosft1.f90", "max_stars_repo_name": "apengsigkarup/OceanWave3D", "max_stars_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 46, "max_stars_repo_stars_event_min_datetime": "2016-01-08T12:36:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T06:56:45.000Z", "max_issues_repo_path": "src/fft/cosft1.f90", "max_issues_repo_name": "apengsigkarup/OceanWave3D", "max_issues_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-10-10T19:45:08.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-07T07:37:11.000Z", "max_forks_repo_path": "src/fft/cosft1.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.7105263158, "max_line_length": 72, "alphanum_fraction": 0.4481842338, "num_tokens": 487, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179068309441, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6962681259986233}} {"text": "! ==============================================================================\n! Point-wise version of the acoustics problem\n! ==============================================================================\n\nsubroutine rp1_ptwise(num_eqn, num_aux, num_waves, q_l, q_r, aux_l, aux_r, &\n wave, s, amdq, apdq)\n\n implicit none\n\n ! Input Arguments\n integer, intent(in) :: num_eqn, num_aux, num_waves\n real(kind=8), intent(in out) :: q_l(num_eqn), q_r(num_eqn)\n real(kind=8), intent(in out) :: aux_l(num_aux), aux_r(num_aux)\n\n ! Output arguments\n real(kind=8), intent(in out) :: wave(num_eqn, num_waves)\n real(kind=8), intent(in out) :: s(num_waves)\n real(kind=8), intent(in out) :: apdq(num_eqn), amdq(num_eqn)\n\n ! Locals\n real(kind=8) :: delta(2), a(2)\n\n ! Common block\n real(kind=8) :: rho, bulk, cc, zz\n\n common /cparam/ rho, bulk, cc, zz\n\n delta = q_r - q_l\n\n a(1) = (-delta(1) + zz * delta(2)) / (2.d0 * zz)\n a(2) = ( delta(1) + zz * delta(2)) / (2.d0 * zz)\n\n wave(1, 1) = -a(1) * zz\n wave(2, 1) = a(1)\n s(1) = -cc\n\n wave(1, 2) = a(2) * zz\n wave(2, 2) = a(2)\n s(2) = cc\n\n amdq = s(1) * wave(:, 1)\n apdq = s(2) * wave(:, 2)\n\nend subroutine rp1_ptwise", "meta": {"hexsha": "080febc4e3e9493a60f107426bac9ec314832c72", "size": 1251, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/rp1_acoustics_ptwise.f90", "max_stars_repo_name": "ranocha/riemann", "max_stars_repo_head_hexsha": "d7b4d72d1147eee12e60a64f46a7e076b28a212d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 27, "max_stars_repo_stars_event_min_datetime": "2015-03-08T03:42:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-21T01:46:12.000Z", "max_issues_repo_path": "src/rp1_acoustics_ptwise.f90", "max_issues_repo_name": "ranocha/riemann", "max_issues_repo_head_hexsha": "d7b4d72d1147eee12e60a64f46a7e076b28a212d", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 47, "max_issues_repo_issues_event_min_datetime": "2015-02-11T15:39:22.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-25T01:56:46.000Z", "max_forks_repo_path": "src/rp1_acoustics_ptwise.f90", "max_forks_repo_name": "ranocha/riemann", "max_forks_repo_head_hexsha": "d7b4d72d1147eee12e60a64f46a7e076b28a212d", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 37, "max_forks_repo_forks_event_min_datetime": "2015-01-09T21:44:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-21T12:53:04.000Z", "avg_line_length": 28.4318181818, "max_line_length": 80, "alphanum_fraction": 0.4820143885, "num_tokens": 422, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.908617906830944, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6962681259986232}} {"text": "!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 2005 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Fishpack *\n! * *\n! * A Package of Fortran *\n! * *\n! * Subroutines and Example Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams, Paul Swarztrauber and Roland Sweet *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\nprogram test_hstcsp\n\n use, intrinsic :: ISO_Fortran_env, only: &\n stdout => OUTPUT_UNIT\n\n use fishpack\n\n ! Explicit typing only\n implicit none\n\n !-----------------------------------------------\n ! Dictionary\n !-----------------------------------------------\n type(FishpackWorkspace) :: workspace\n integer(ip), parameter :: M = 45\n integer(ip), parameter :: N = 15\n integer(ip), parameter :: IDIMF = M + 2, NP1 = N + 1\n integer(ip) :: mbdcnd, nbdcnd, i, j, intl, ierror\n real(wp) :: f(IDIMF, NP1), r(N)\n real(wp), dimension(M) :: bdd, theta, cost\n real(wp), dimension(1) :: bda, bdb, bdc\n real(wp) :: a, b, c, d\n real(wp) :: dt, dr, elmbda, pertrb\n real(wp), parameter :: ZERO = 0.0_wp, HALF = 0.5_wp, ONE = 1.0_wp\n !-----------------------------------------------\n\n ! Set domaiin\n a = ZERO\n b = PI\n c = ZERO\n d = ONE\n\n ! Set boundary conditions\n mbdcnd = 9\n nbdcnd = 5\n\n ! Set helmholtz constant\n elmbda = ZERO\n\n ! Define mesh sizes\n dt = (b - a)/M\n dr = (d - c)/N\n\n ! Define grid points theta(i) and cos(theta(i))\n do i = 1, M\n theta(i) = a + (real(i, kind=wp) - HALF) * dt\n cost(i) = cos(theta(i))\n end do\n\n ! Define grid points r(j)\n do j = 1, N\n r(j) = c + (real(j) - HALF) * dr\n end do\n\n ! Define boundary array bdd.\n ! bda, bdb, and bdc are one-dimensional dummy variables in this example\n bdd = cost**4\n\n ! Define right hand side of equation\n block\n real(wp), parameter :: TWELVE = 12.0_wp\n\n do i = 1, M\n f(i,:N) = TWELVE * (r(:N)*cost(i))**2\n end do\n end block\n\n ! Initialize call flag\n intl = 0\n\n ! Solve 2D axisymmetric Helmholtz equation on staggered grid\n call hstcsp(intl, a, b, M, mbdcnd, bda, bdb, c, d, N, nbdcnd, bdc, &\n bdd, elmbda, f, IDIMF, pertrb, ierror, workspace)\n\n ! Compute discretization error. The exact solution is\n !\n ! u(theta, r) = (r*cos(theta))**4\n !\n block\n real(wp), parameter :: KNOWN_ERROR = 0.558432375660800e-2_wp\n real(wp) :: discretization_error\n real(wp) :: exact_solution(M,N)\n\n do j = 1, N\n do i = 1, M\n exact_solution(i,j) = (r(j)*cost(i))**4\n end do\n end do\n\n ! Set discretization error\n discretization_error = maxval(abs(exact_solution - f(:M,:N)))\n\n call check_output('hstcsp', ierror, KNOWN_ERROR, discretization_error)\n end block\n\n ! Release memory\n call workspace%destroy()\n\nend program test_hstcsp\n", "meta": {"hexsha": "290923967362881a0159a9475c1690a4dea1fb9e", "size": 4881, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/thstcsp.f90", "max_stars_repo_name": "jlokimlin/fishpack", "max_stars_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2018-03-12T11:31:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-27T07:58:23.000Z", "max_issues_repo_path": "examples/thstcsp.f90", "max_issues_repo_name": "jlokimlin/fishpack", "max_issues_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2016-05-07T22:42:47.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-15T17:44:58.000Z", "max_forks_repo_path": "examples/thstcsp.f90", "max_forks_repo_name": "jlokimlin/fishpack", "max_forks_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-09-07T15:43:32.000Z", "max_forks_repo_forks_event_max_datetime": "2018-06-16T21:30:13.000Z", "avg_line_length": 36.6992481203, "max_line_length": 78, "alphanum_fraction": 0.3439868879, "num_tokens": 1132, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818865, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6962681173566899}} {"text": "FUNCTION dsinint(xvalue) RESULT(fn_val)\r\n\r\n! DEFINITION:\r\n\r\n! This program calculates the value of the sine-integral defined as\r\n\r\n! DSININT(x) = Integral (0 to x) sin(t)/t dt\r\n\r\n! The program uses rational approximations with the coefficients\r\n! given to 20sf. accuracy.\r\n\r\n\r\n! INPUT PARAMETER:\r\n\r\n! XVALUE - DOUBLE PRECISION - The argument to the function\r\n\r\n\r\n! MACHINE-DEPENDENT PARAMETERS:\r\n\r\n! XLOW - DOUBLE PRECISION - The absolute value below which\r\n! DSININT( x ) = x,\r\n! to machine precision.\r\n! The recommended value is\r\n! SQRT(18*EPSNEG)\r\n\r\n! XHIGH1 - DOUBLE PRECISION - The value above which\r\n! DSININT(x) = pi/2 - cos(x)/x -sin(x)/x*x\r\n! to machine precision.\r\n! The recommended value is\r\n! SQRT(6/EPSNEG)\r\n\r\n! XHIGH2 - DOUBLE PRECISION - The value above which\r\n! DSININT(x) = pi/2\r\n! to machine precision.\r\n! The recommended value is\r\n! 2 / min(EPS,EPSNEG)\r\n\r\n! XHIGH3 - DOUBLE PRECISION - The value above which it is not sensible\r\n! to compute COS or SIN. The recommended\r\n! value is pi/EPS\r\n\r\n\r\n! Values of EPS and EPSNEG for certain machine/compiler\r\n! combinations can be found in the paper\r\n\r\n! W.J. CODY Algorithm 665: MACHAR: A subroutine to dynamically\r\n! determine machine parameters, ACM Trans. Math. Soft. 14 (1988) 303-311.\r\n\r\n! The current code gives numerical values for XLOW,XHIGH1,XHIGH2,XHIGH3,\r\n! suitable for machines whose arithmetic conforms to the IEEE\r\n! standard. The codes will probably work on other machines\r\n! but might overflow or underflow for certain arguments.\r\n\r\n! AUTHOR: Allan MacLeod\r\n! Dept. of Mathematics and Statistics\r\n! University of Paisley\r\n! Scotland\r\n! (e-mail: macl_ms0@paisley.ac.uk)\r\n\r\nIMPLICIT NONE\r\nINTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(14, 60)\r\nREAL (dp), INTENT(IN) :: xvalue\r\nREAL (dp) :: fn_val\r\n\r\n! Local variables\r\n\r\nINTEGER :: i, indsgn\r\nREAL (dp) :: cx, fival, gival, sumden, sumnum, sx, x, xhigh, xsq\r\n\r\n! DATA VALUES\r\n\r\nREAL (dp), PARAMETER :: zero = 0.0_dp, one = 1.0_dp, six = 6.0_dp, &\r\n twelve = 12.0_dp\r\nREAL (dp), PARAMETER :: piby2 = 1.5707963267948966192_dp\r\n\r\n! MACHINE-DEPENDENT PARAMETERS (SUITABLE FOR IEEE MACHINES)\r\n\r\nREAL (dp), PARAMETER :: xlow = 4.47E-8_dp, xhigh1 = 2.32472E8_dp\r\nREAL (dp), PARAMETER :: xhigh2 = 9.0072E15_dp, xhigh3 = 1.4148475E16_dp\r\n\r\n! VALUES FOR SINE-INTEGRAL FOR 0 <= |X| <= 6\r\n\r\nREAL (dp), PARAMETER :: asintn(0:7) = (/ 1.0_dp, &\r\n -0.44663998931312457298E-1_dp, 0.11209146443112369449E-2_dp, &\r\n -0.13276124407928422367E-4_dp, 0.85118014179823463879E-7_dp, &\r\n -0.29989314303147656479E-9_dp, 0.55401971660186204711E-12_dp, &\r\n -0.42406353433133212926E-15_dp /)\r\nREAL (dp), PARAMETER :: asintd(0:7) = (/ 1.0_dp, &\r\n 0.10891556624243098264E-1_dp, 0.59334456769186835896E-4_dp, &\r\n 0.21231112954641805908E-6_dp, 0.54747121846510390750E-9_dp, &\r\n 0.10378561511331814674E-11_dp, 0.13754880327250272679E-14_dp,&\r\n 0.10223981202236205703E-17_dp /)\r\n\r\n! VALUES FOR FI(X) FOR 6 <= X <= 12\r\n\r\nREAL (dp), PARAMETER :: afn1(0:7) = (/ 0.99999999962173909991_dp, &\r\n 0.36451060338631902917E3_dp, 0.44218548041288440874E5_dp, &\r\n 0.22467569405961151887E7_dp, 0.49315316723035561922E8_dp, &\r\n 0.43186795279670283193E9_dp, 0.11847992519956804350E10_dp,&\r\n 0.45573267593795103181E9_dp /)\r\nREAL (dp), PARAMETER :: afd1(0:7) = (/ 1.0_dp, 0.36651060273229347594E3_dp, &\r\n 0.44927569814970692777E5_dp, 0.23285354882204041700E7_dp, &\r\n 0.53117852017228262911E8_dp, 0.50335310667241870372E9_dp, &\r\n 0.16575285015623175410E10_dp, 0.11746532837038341076E10_dp /)\r\n\r\n! VALUES OF GI(X) FOR 6 <= X <=12\r\n\r\nREAL (dp), PARAMETER :: agn1(0:8) = (/ 0.99999999920484901956_dp, &\r\n 0.51385504875307321394E3_dp, 0.92293483452013810811E5_dp, &\r\n 0.74071341863359841727E7_dp, 0.28142356162841356551E9_dp, &\r\n 0.49280890357734623984E10_dp, 0.35524762685554302472E11_dp, &\r\n 0.79194271662085049376E11_dp, 0.17942522624413898907E11_dp /)\r\nREAL (dp), PARAMETER :: agd1(0:8) = (/ 1.0_dp, 0.51985504708814870209E3_dp, &\r\n 0.95292615508125947321E5_dp, 0.79215459679762667578E7_dp, &\r\n 0.31977567790733781460E9_dp, 0.62273134702439012114E10_dp, &\r\n 0.54570971054996441467E11_dp, 0.18241750166645704670E12_dp, &\r\n 0.15407148148861454434E12_dp /)\r\n\r\n! VALUES FOR FI(X) FOR X > 12\r\n\r\nREAL (dp), PARAMETER :: afn2(0:7) = (/ 0.19999999999999978257E1_dp, &\r\n 0.22206119380434958727E4_dp, 0.84749007623988236808E6_dp, &\r\n 0.13959267954823943232E9_dp, 0.10197205463267975592E11_dp, &\r\n 0.30229865264524075951E12_dp, 0.27504053804288471142E13_dp, &\r\n 0.21818989704686874983E13_dp /)\r\nREAL (dp), PARAMETER :: afd2(0:7) = (/ 1.0_dp, 0.11223059690217167788E4_dp, &\r\n 0.43685270974851313242E6_dp, 0.74654702140658116258E8_dp, &\r\n 0.58580034751805687471E10_dp, 0.20157980379272098841E12_dp, &\r\n 0.26229141857684496445E13_dp, 0.87852907334918467516E13_dp /)\r\n\r\n! VALUES FOR GI(X) FOR X > 12\r\n\r\nREAL (dp), PARAMETER :: agn2(0:8) = (/ 0.59999999999999993089E1_dp, &\r\n 0.96527746044997139158E4_dp, 0.56077626996568834185E7_dp, &\r\n 0.15022667718927317198E10_dp, 0.19644271064733088465E12_dp, &\r\n 0.12191368281163225043E14_dp, 0.31924389898645609533E15_dp, &\r\n 0.25876053010027485934E16_dp, 0.12754978896268878403E16_dp /)\r\nREAL (dp), PARAMETER :: agd2(0:8) = (/ 1.0_dp, 0.16287957674166143196E4_dp, &\r\n 0.96636303195787870963E6_dp, 0.26839734750950667021E9_dp, &\r\n 0.37388510548029219241E11_dp, 0.26028585666152144496E13_dp, &\r\n 0.85134283716950697226E14_dp, 0.11304079361627952930E16_dp, &\r\n 0.42519841479489798424E16_dp /)\r\n\r\n! START COMPUTATION\r\n\r\nx = xvalue\r\nindsgn = 1\r\nIF ( x < zero ) THEN\r\n x = -x\r\n indsgn = -1\r\nEND IF\r\n\r\n! CODE FOR 0 <= |X| <= 6\r\n\r\nIF ( x <= six ) THEN\r\n IF ( x < xlow ) THEN\r\n fn_val = x\r\n ELSE\r\n sumnum = zero\r\n sumden = zero\r\n xsq = x * x\r\n DO i = 7 , 0 , -1\r\n sumnum = sumnum * xsq + asintn(i)\r\n sumden = sumden * xsq + asintd(i)\r\n END DO\r\n fn_val = x * sumnum / sumden\r\n END IF\r\nEND IF\r\n\r\n! CODE FOR 6 < |X| <= 12\r\n\r\nIF ( x > six .AND. x <= twelve ) THEN\r\n sumnum = zero\r\n sumden = zero\r\n xsq = one / ( x * x )\r\n DO i = 7 , 0 , -1\r\n sumnum = sumnum * xsq + afn1(i)\r\n sumden = sumden * xsq + afd1(i)\r\n END DO\r\n fival = sumnum / ( x * sumden )\r\n sumnum = zero\r\n sumden = zero\r\n DO i = 8 , 0 , -1\r\n sumnum = sumnum * xsq + agn1(i)\r\n sumden = sumden * xsq + agd1(i)\r\n END DO\r\n gival = xsq * sumnum / sumden\r\n fn_val = piby2 - fival * COS(x) - gival * SIN(x)\r\nEND IF\r\n\r\n! CODE FOR |X| > 12\r\n\r\nIF ( x > twelve ) THEN\r\n xhigh = MIN(xhigh2, xhigh3)\r\n IF ( x > xhigh ) THEN\r\n fn_val = piby2\r\n ELSE\r\n cx = COS(x)\r\n sx = SIN(x)\r\n xsq = one / ( x * x )\r\n IF ( x > xhigh1 ) THEN\r\n fn_val = piby2 - cx / x - sx * xsq\r\n ELSE\r\n sumnum = zero\r\n sumden = zero\r\n DO i = 7 , 0 , -1\r\n sumnum = sumnum * xsq + afn2(i)\r\n sumden = sumden * xsq + afd2(i)\r\n END DO\r\n fival = ( one - xsq * sumnum / sumden ) / x\r\n sumnum = zero\r\n sumden = zero\r\n DO i = 8 , 0 , -1\r\n sumnum = sumnum * xsq + agn2(i)\r\n sumden = sumden * xsq + agd2(i)\r\n END DO\r\n gival = ( one - xsq * sumnum / sumden ) * xsq\r\n fn_val = piby2 - cx * fival - sx * gival\r\n END IF\r\n END IF\r\nEND IF\r\nIF ( indsgn == -1 ) fn_val = -fn_val\r\nRETURN\r\nEND FUNCTION dsinint\r\n", "meta": {"hexsha": "5fbf8af057be97c9baafcabac3e437e9840e718f", "size": 8308, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/dsinint.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/dsinint.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/dsinint.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": 36.9244444444, "max_line_length": 81, "alphanum_fraction": 0.5835339432, "num_tokens": 2950, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837705, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6962681146213285}} {"text": " INTEGER FUNCTION FRACTRAN(N,P,Q,M)\t!Notion devised by J. H. Conway.\nCareful: the rule is N*P/Q being integer. N*6/3 is integer always because this is N*2/1, but 3 may not divide N.\nCould check GCD(P,Q), dividing out the common denominator so MOD(N,Q) works.\n INTEGER*8 N\t!The work variable. Modified!\n INTEGER M\t!The number of fractions supplied.\n INTEGER P(M),Q(M)!The terms of the fractions.\n INTEGER I\t!A stepper.\n DO I = 1,M\t!Search the supplied fractions, P(i)/Q(i).\n IF (MOD(N,Q(I)).EQ.0) THEN\t!Does the denominator divide N?\n N = N/Q(I)*P(I)\t!Yes, compute N*P/Q but trying to dodge overflow.\n FRACTRAN = I\t!Report the hit.\n RETURN\t\t!Done!\n END IF\t!Otherwise,\n END DO\t\t!Try the next fraction in the order supplied.\n FRACTRAN = 0\t!No hit.\n END FUNCTION FRACTRAN\t!That's it! Even so, \"Turing complete\"...\n\n PROGRAM POKE\n INTEGER FRACTRAN\t\t!Not the default type of function.\n INTEGER P(66),Q(66)\t!Holds the fractions as P(i)/Q(i).\n INTEGER*8 N\t\t!The working number.\n INTEGER I,IT,L,M\t\t!Assistants.\n\n WRITE (6,1)\t!Announce.\n 1 FORMAT (\"Interpreter for J.H. Conway's FRACTRAN language.\")\n\nChew into an example programme.\n OPEN (10,FILE = \"Fractran.txt\",STATUS=\"OLD\",ACTION=\"READ\")\t!Rather than compiled-in stuff.\n READ (10,*) L\t!I need to know this without having to scan the input.\n WRITE (6,2) L\t!Reveal in case of trouble.\n 2 FORMAT (I0,\" fractions, as follow:\")\t!Should the input evoke problems.\n READ (10,*) (P(I),Q(I),I = 1,L)\t!Ask for the specified number of P,Q pairs.\n WRITE (6,3) (P(I),Q(I),I = 1,L)\t!Show what turned up.\n 3 FORMAT (24(I0,\"/\",I0:\", \"))\t!As P(i)/Q(i) pairs. The colon means that there will be no trailing comma.\n READ (10,*) N,M\t\t\t!The start value, and the step limit.\n CLOSE (10)\t\t\t!Finished with input.\n WRITE (6,4) N,M\t\t\t!Hopefully, all went well.\n 4 FORMAT (\"Start with N = \",I0,\", step limit \",I0)\n\nCommence.\n WRITE (6,10) 0,N\t\t!Splat a heading.\n 10 FORMAT (/,\" Step #F: N\",/,I6,4X,\": \",I0)\t!Matched FORMAT 11.\n DO I = 1,M\t\t!Here we go!\n IT = FRACTRAN(N,P,Q,L)\t\t!Do it!\n WRITE (6,11) I,IT,N\t\t!Show it!\n 11 FORMAT (I6,I4,\": \",I0)\t\t!N last, as it may be big.\n IF (IT.LE.0) EXIT\t\t!No hit, so quit.\n END DO\t\t\t!The next step.\n END\t!Whee!\n", "meta": {"hexsha": "6a079ed26a137a121b2b61e3e972c9d5b0d8ad43", "size": 2402, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Fractran/Fortran/fractran-2.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Fractran/Fortran/fractran-2.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Fractran/Fortran/fractran-2.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 48.04, "max_line_length": 112, "alphanum_fraction": 0.6007493755, "num_tokens": 794, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178969328287, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.6962681135642582}} {"text": "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!*********************************************************!!\n!! Objetivo: escrever um sistema que resolva a equa\u00e7\u00e3o !!\n!! diferencial y''-5y'+10y=10x pelo m\u00e9todo de Gauss Seidel !!\n!! !!\n!! Aluna: Laura Simonassi Raso de Paiva !!\n!! Matr\u00edcula: 180021885 !!\n!! Data: 10/11/2019 !!\n!! \u00daltima modifica\u00e7\u00e3o: 26/11/2019 !! \n!!*********************************************************!!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\nprogram gauss_seidel\n\nimplicit none\nreal(kind=8), allocatable :: yini(:), yfin(:),x(:)\nreal(kind=8):: h,erro\ninteger:: n\ninteger:: i\n\nopen(unit=1, file='resultados.txt')\n\nwrite(*,*) 'Escolha um valor para n'\nread(*,*) n\n\nallocate(x(n),yini(n),yfin(n))\n\nx(1)=0.0d0\nh=1.0d0/dfloat(n-1)\ndo i=1,n-1\n x(i+1)=x(i)+h\nend do\nyini=100.0d0*x\n\nyfin=yini\n\ndo \n erro=0.0d0\n do i=2,n-1\n yfin(i)=((1.0d0-(5.0d0*h)/2.0d0)*yini(i+1) + (1.0d0+(5.0d0*h)/2.0d0)*yfin(i-1) - 10.0d0*(h**2.0d0)*x(i))/(2.0d0-10.0d0*(h**2.0d0))\n erro=erro+(yfin(i)-yini(i))**2\n yini(i)=yfin(i)\n end do\n erro=erro/sum(yini**2)\n if(erro <= 1.0d-10) exit\nend do\n \ndo i =1,n\n write(1,*) x(i),yfin(i)\nend do\n\nclose(1)\nend program gauss_seidel\n", "meta": {"hexsha": "74771b2101477c53503ceb89653ef60c8ee19c01", "size": 1403, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Gauss Seidel.f90", "max_stars_repo_name": "laurasimonassi/Physics-Projects", "max_stars_repo_head_hexsha": "e0a92ccc7a657a232313c428c4ef2cdf1c780b88", "max_stars_repo_licenses": ["MIT"], "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 Seidel.f90", "max_issues_repo_name": "laurasimonassi/Physics-Projects", "max_issues_repo_head_hexsha": "e0a92ccc7a657a232313c428c4ef2cdf1c780b88", "max_issues_repo_licenses": ["MIT"], "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 Seidel.f90", "max_forks_repo_name": "laurasimonassi/Physics-Projects", "max_forks_repo_head_hexsha": "e0a92ccc7a657a232313c428c4ef2cdf1c780b88", "max_forks_repo_licenses": ["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.9814814815, "max_line_length": 135, "alphanum_fraction": 0.4255167498, "num_tokens": 484, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178870347122, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6962681108288966}} {"text": "!> \\file f2pCO2.f90\n!! \\BRIEF \n!> Module with f2pCO2 subroutine - compute pCO2 from fCO2, in situ T, atm pressure, hydrostatic pressure\nMODULE mf2pCO2\nCONTAINS\n!> Compute pCO2 from arrays of fCO2, in situ temp, atm pressure, & hydrostatic pressure\nSUBROUTINE f2pCO2(fCO2, temp, Patm, p, N, pCO2)\n ! Purpose:\n ! Compute pCO2 from arrays of fCO2, in situ temp, atm pressure, & hydrostatic pressure\n\n#if USE_PRECISION == 2\n# define SGLE(x) (x)\n#else\n# define SGLE(x) REAL(x)\n#endif\n\n USE msingledouble\n IMPLICIT NONE\n\n !> number of records\n!f2py intent(hide) n\n INTEGER, intent(in) :: N\n\n! INPUT variables\n !> oceanic fugacity of CO2 [uatm]\n REAL(kind=rx), INTENT(in), DIMENSION(N) :: fCO2\n !> in situ temperature [C]\n REAL(kind=rx), INTENT(in), DIMENSION(N) :: temp\n !> atmospheric pressure [atm]\n REAL(kind=rx), INTENT(in), DIMENSION(N) :: Patm\n !> hydrostatic pressure [db]\n REAL(kind=rx), INTENT(in), DIMENSION(N) :: p\n\n! OUTPUT variables:\n !> oceanic partial pressure of CO2 [uatm] \n REAL(kind=rx), INTENT(out), DIMENSION(N) :: pCO2\n\n! LOCAL variables:\n REAL(kind=r8) :: dfCO2, dtemp, tk, dPatm, prb\n REAL(kind=r8) :: Ptot, Rgas_atm, B, Del, xCO2approx, xc2, fugcoeff\n REAL(kind=r8) :: dpCO2\n\n INTEGER :: i\n\n! REAL(kind=r8) :: sw_ptmp\n! EXTERNAL sw_ptmp\n\n DO i = 1,N\n dfCO2 = DBLE(fCO2(i))\n dtemp = DBLE(temp(i))\n dPatm = DBLE(Patm(i))\n tk = 273.15d0 + DBLE(temp(i)) !Absolute temperature (Kelvin)\n prb = DBLE(p(i)) / 10.0d0 !Pressure effect (prb is in bars)\n Ptot = dPatm + prb/1.01325d0 !Total pressure (atmospheric + hydrostatic) [atm]\n Rgas_atm = 82.05736_r8 !R in (cm3 * atm) / (mol * K) from CODATA (2006)\n! To compute fugcoeff, we need 3 other terms (B, Del, xc2) as well as 3 others above (tk, Ptot, Rgas_atm)\n B = -1636.75d0 + 12.0408d0*tk - 0.0327957d0*(tk*tk) + 0.0000316528d0*(tk*tk*tk)\n Del = 57.7d0 - 0.118d0*tk\n! \"x2\" term often neglected (assumed = 1) in applications of Weiss's (1974) equation 9\n! x2 = 1 - x1 = 1 - xCO2 (it is very close to 1, but not quite)\n! Let's assume that xCO2 = fCO2. Resulting fugcoeff is identical to 8th digit after the decimal.\n xCO2approx = dfCO2 * 1.e-6_r8\n xc2 = (1.0d0 - xCO2approx)**2 \n fugcoeff = exp( Ptot*(B + 2.0d0*xc2*Del)/(Rgas_atm*tk) )\n dpCO2 = dfCO2 / fugcoeff\n pCO2(i) = SGLE(dpCO2)\n END DO\n\n RETURN\nEND SUBROUTINE f2pCO2\nEND MODULE mf2pCO2\n", "meta": {"hexsha": "a6f100c38c257e4399c7f3eca8597c7b39d37ed1", "size": 2458, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/f2pCO2.f90", "max_stars_repo_name": "tomaslovato/mocsy", "max_stars_repo_head_hexsha": "ede19cde4be5cd37ed192a3f3394e81302d11616", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2017-06-20T13:08:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-04T09:51:49.000Z", "max_issues_repo_path": "src/f2pCO2.f90", "max_issues_repo_name": "tomaslovato/mocsy", "max_issues_repo_head_hexsha": "ede19cde4be5cd37ed192a3f3394e81302d11616", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-11-12T19:46:14.000Z", "max_issues_repo_issues_event_max_datetime": "2020-01-23T14:57:14.000Z", "max_forks_repo_path": "src/f2pCO2.f90", "max_forks_repo_name": "tomaslovato/mocsy", "max_forks_repo_head_hexsha": "ede19cde4be5cd37ed192a3f3394e81302d11616", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2015-11-01T01:06:21.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-04T12:58:24.000Z", "avg_line_length": 34.1388888889, "max_line_length": 108, "alphanum_fraction": 0.6407648495, "num_tokens": 937, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178994073576, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6962681106109719}} {"text": "program ex24\n\n use utils\n\n implicit none\n\n real(rk) :: A(10,10)\n real(rk) :: B(10,10)\n real(rk) :: C(10,10)\n real(rk) :: v1(3)\n real(rk) :: v2(3)\n real(rk) :: dp\n\n call initRand()\n call randMat(A, -1.0_rk, 1.0_rk)\n call randMat(B, -1.0_rk, 1.0_rk)\n call printMatrix(A, 'A')\n call printMatrix(B, 'B')\n\n C = matmul(A, B)\n\n call printMatrix(C, 'C')\n\n v1 = (/1.0, 0.0, 0.0/)\n v2 = (/0.0, 1.0, 0.0/)\n dp = dot_product(v1, v2)\n\n print*, dp\n\n\nend program ex24\n", "meta": {"hexsha": "86a2139a973af66a3aad6282dc59e3fc3b6bdaee", "size": 510, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/ex24/ex24.f90", "max_stars_repo_name": "jonaslindemann/compute-course-public", "max_stars_repo_head_hexsha": "b8f55595ebbd790d79b525efdff17b8517154796", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-09-12T12:07:01.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-29T17:38:34.000Z", "max_issues_repo_path": "fortran/ex24/ex24.f90", "max_issues_repo_name": "jonaslindemann/compute-course-public", "max_issues_repo_head_hexsha": "b8f55595ebbd790d79b525efdff17b8517154796", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/ex24/ex24.f90", "max_forks_repo_name": "jonaslindemann/compute-course-public", "max_forks_repo_head_hexsha": "b8f55595ebbd790d79b525efdff17b8517154796", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2020-10-24T16:02:31.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-28T20:57:46.000Z", "avg_line_length": 15.9375, "max_line_length": 36, "alphanum_fraction": 0.5098039216, "num_tokens": 218, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837706, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6962681049223245}} {"text": "!---------------------------------------------------------------------!\n! OWNER: Ithaca Combustion Enterprise, LLC !\n! COPYRIGHT: \u00a9 2012, Ithaca Combustion Enterprise, LLC !\n! LICENSE: BSD 3-Clause License (The complete text of the license can !\n! be found in the `LICENSE-ICE.txt' file included in the ISAT-CK7 !\n! source directory.) !\n!---------------------------------------------------------------------!\n\nsubroutine ell_rad_upper( n, gg, r )\n\n! Determine the radius r of the ball covering the ellipsoid E given\n! by { x | norm(G^T * x) <=1 ), where G is an n x n lower triangular\n! matrix. The array gg contains the matrix G in packed format.\n\n! S.B. Pope 6/12/04\n\nimplicit none\n\ninteger, parameter :: k_dp = kind(1.d0)\ninteger, intent(in) :: n\nreal(k_dp), intent(in) :: gg((n*(n+1))/2)\nreal(k_dp), intent(out) :: r\n\ninteger :: itmax = 100 ! max. iterations in dgqt\nreal(k_dp) :: atol = 1.d-4, rtol = 1.d-4 ! tolerances for dgqt\n\ninteger :: info, i, j, k\nreal(k_dp) :: gi((n*(n+1))/2), g(n,n), alpha, delta, par, f\nreal(k_dp) :: a(n,n), b(n), x(n), z(n), wa1(n), wa2(n)\n\n! Method: E = { y | y^T * y <= 1 } where y = G^T * x.\n! Now x^T * x = y^T * G^{-1} * G^{-T} * y.\n! Thus, with f(y) = -2 * y^T * G^{-1} * G^{-T} * y, \n! r = sqrt(-f(y_m) ), where y_m is the minimizer of f, subject to |y|<=1.\n\ngi = gg\ncall dtptri( 'L', 'N', n, gi, info ) ! G^{-1} in packed format\n\n! unpack gi into g\nk = 0\ng = 0.d0\ndo j = 1, n\n do i = j, n\n k = k + 1\n\t g(i,j) = gi(k)\n end do\nend do\na = g\n\n! B = alpha * B * op(A) = -2 * G^{-1} * G^{-T}\n\nalpha = -2.d0\ncall dtrmm ( 'R', 'L', 'T', 'N', n, n, alpha, g, n, a, n )\n\ndelta = 1.d0\npar = 0.d0\nb = 0.d0\n! minimize f(y) = (1/2) * y^T * A * y + b^T * y, subject to |y|<= delta\n! = -2 * y^T * G^{-1} * G^{-T} * y\n\ncall dgqt(n,a,n,b,delta,rtol,atol,itmax,par,f,x,info,z,wa1,wa2)\n\nif( info >= 3 ) then\n write(0,*)'ell_rad_upper: dgqt incomplete convergence, info = ', info\nendif\n\nif( f > 0.d0 ) then\n write(0,*)'ell_rad_upper: f positive, f = ', f\n stop\nendif\n\nr = sqrt( -f ) \n\nreturn\nend subroutine ell_rad_upper\n", "meta": {"hexsha": "0ecd4468bba02320c7d24a0d6b7ca4dcaee3fd4c", "size": 2212, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/isat/ell_lib/ell_rad_upper.f90", "max_stars_repo_name": "xuhan425/isat_ffd", "max_stars_repo_head_hexsha": "3a5449f7e49b686c33fe0e97ca90ea8d92fc2f00", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-04-10T20:16:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-15T11:09:44.000Z", "max_issues_repo_path": "src/isat/ell_lib/ell_rad_upper.f90", "max_issues_repo_name": "xuhan425/isat_ffd", "max_issues_repo_head_hexsha": "3a5449f7e49b686c33fe0e97ca90ea8d92fc2f00", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-06-07T14:10:25.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-07T14:10:25.000Z", "max_forks_repo_path": "src/isat/ell_lib/ell_rad_upper.f90", "max_forks_repo_name": "xuhan425/isat_ffd", "max_forks_repo_head_hexsha": "3a5449f7e49b686c33fe0e97ca90ea8d92fc2f00", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-06-07T03:44:12.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-05T05:54:10.000Z", "avg_line_length": 29.1052631579, "max_line_length": 74, "alphanum_fraction": 0.4995479204, "num_tokens": 802, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404038127071, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6962319218482876}} {"text": "program variables\n \n !\n ! Demonstrate some properties of variables\n !\n\n implicit none\n\n integer :: i\n integer(2) :: j\n integer(4) :: k\n integer(8) :: l\n\n real :: a\n real(4) :: b\n real(8) :: c\n\n \n write(*, *) 'Huge: ', huge(i), huge(j), huge(k), huge(l)\n write(*, *) 'Digits: ', digits(i), digits(j), digits(k), digits(l)\n\n write(*, *) ''\n\n write(*, *) 'Huge: ', huge(a), huge(b), huge(c)\n write(*, '(a,i,i,i)') 'Digits: ', digits(a), digits(b), digits(c)\n write(*, '(a8,e,e,e)') 'Epsilon: ', epsilon(a), epsilon(b), epsilon(c)\n write(*, '(a9,en,en,en)') 'Epsilon: ', epsilon(a), epsilon(b), epsilon(c)\n write(*, '(a10,3es)') 'Epsilon: ', epsilon(a), epsilon(b), epsilon(c)\n write(*, '(a11,3e20.10e4)') 'Epsilon: ', epsilon(a), epsilon(b), epsilon(c)\n\nend program variables\n", "meta": {"hexsha": "3e100d3371f0325fc8f0dbc052834446a740d4f0", "size": 796, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lectures1and2/example/variables.f90", "max_stars_repo_name": "sdm900/fortran_course", "max_stars_repo_head_hexsha": "6f2db3fcc7b616b94c4e1fe8875a3158a01117b2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lectures1and2/example/variables.f90", "max_issues_repo_name": "sdm900/fortran_course", "max_issues_repo_head_hexsha": "6f2db3fcc7b616b94c4e1fe8875a3158a01117b2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lectures1and2/example/variables.f90", "max_forks_repo_name": "sdm900/fortran_course", "max_forks_repo_head_hexsha": "6f2db3fcc7b616b94c4e1fe8875a3158a01117b2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.875, "max_line_length": 77, "alphanum_fraction": 0.5552763819, "num_tokens": 277, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245953120234, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.6962289838601711}} {"text": "\nmodule constants\n\n ! define various constants\n implicit none\n real(kind=8) :: pi, e\n save\n\n\n subroutine set_constants()\n implicit none\n pi = acos(-1.d0)\n e = exp(1.d0)\n end subroutine set_constants\n\nend module constants\n", "meta": {"hexsha": "85c635ebade4fcbe069cdae197012b40c569aa66", "size": 260, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/labs/lab8/problem1/constants.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/lab8/problem1/constants.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/lab8/problem1/constants.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": 15.2941176471, "max_line_length": 32, "alphanum_fraction": 0.6153846154, "num_tokens": 65, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8376199714402813, "lm_q2_score": 0.8311430415844384, "lm_q1q2_score": 0.6961820107547458}} {"text": "!*****************************************************************************************\n!> author: Jacob Williams\n! license: BSD\n!\n! Numerical differentiation of a 1D function `f(x)` using Neville's process.\n!\n!## Authors\n! * J. Oliver, \"An algorithm for numerical differentiation of a function\n! of one real variable\", Journal of Computational and Applied Mathematics\n! 6 (2) (1980) 145\u2013160. [Algol 60 source in original paper]\n! * David Kahaner, Fortran 77 code from\n! [NIST](ftp://math.nist.gov/pub/repository/diff/src/DIFF)\n! * Jacob Williams : 2/17/2013 : Converted to modern Fortran.\n! Some refactoring, addition of test cases.\n\n module diff_module\n\n use numdiff_kinds_module\n\n implicit none\n\n private\n\n type,public :: diff_func\n !! class to define the function for [[diff]]\n private\n logical :: stop = .false.\n procedure(func),pointer :: f => null()\n contains\n private\n procedure :: faccur\n procedure,public :: set_function\n procedure,public :: compute_derivative => diff\n procedure,public :: terminate\n end type diff_func\n\n abstract interface\n function func(me,x) result(fx)\n !! interface to function for [[diff]]\n import :: diff_func,wp\n implicit none\n class(diff_func),intent(inout) :: me\n real(wp),intent(in) :: x\n real(wp) :: fx\n end function func\n end interface\n\n contains\n!*****************************************************************************************\n\n!*****************************************************************************************\n!> author: Jacob Williams\n! date: 12/27/2015\n!\n! Set the function in a [[diff_func]].\n! Must be called before [[diff]].\n\n subroutine set_function(me,f)\n\n implicit none\n\n class(diff_func),intent(inout) :: me\n procedure(func) :: f\n\n me%f => f\n\n end subroutine set_function\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Can be called by the user in the function to terminate the computation.\n! This will set `ifail=-1`.\n\n subroutine terminate(me)\n\n implicit none\n\n class(diff_func),intent(inout) :: me\n\n me%stop = .true.\n\n end subroutine terminate\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! the procedure `diff` calculates the first, second or\n! third order derivative of a function by using neville's process to\n! extrapolate from a sequence of simple polynomial approximations based on\n! interpolating points distributed symmetrically about `x0` (or lying only on\n! one side of `x0` should this be necessary). if the specified tolerance is\n! non-zero then the procedure attempts to satisfy this absolute or relative\n! accuracy requirement, while if it is unsuccessful or if the tolerance is\n! set to zero then the result having the minimum achievable estimated error\n! is returned instead.\n\n subroutine diff(me,iord,x0,xmin,xmax,eps,accr,deriv,error,ifail)\n\n implicit none\n\n class(diff_func),intent(inout) :: me\n integer,intent(in) :: iord !! 1, 2 or 3 specifies that the first, second or third order\n !! derivative,respectively, is required.\n real(wp), intent(in) :: x0 !! the point at which the derivative of the function is to be calculated.\n real(wp), intent(in) :: xmin !! `xmin`, `xmax` restrict the interpolating points to lie in [`xmin`, `xmax`], which\n !! should be the largest interval including `x0` in which the function is\n !! calculable and continuous.\n real(wp), intent(in) :: xmax !! `xmin`, `xmax` restrict the interpolating points to lie in [`xmin`, `xmax`], which\n !! should be the largest interval including `x0` in which the function is\n !! calculable and continuous.\n real(wp), intent(in) :: eps !! denotes the tolerance, either absolute or relative. `eps=0` specifies that\n !! the error is to be minimised, while `eps>0` or `eps<0` specifies that the\n !! absolute or relative error, respectively, must not exceed `abs(eps)` if\n !! possible. the accuracy requirement should not be made stricter than\n !! necessary, since the amount of computation tends to increase as\n !! the magnitude of `eps` decreases, and is particularly high when `eps=0`.\n real(wp), intent(in) :: accr !! denotes that the absolute (`accr>0`) or relative (`accr<0`) errors in the\n !! computed values of the function are most unlikely to exceed `abs(accr)`, which\n !! should be as small as possible. if the user cannot estimate `accr` with\n !! complete confidence, then it should be set to zero.\n real(wp), intent(out) :: deriv !! the calculated value of the derivative\n real(wp), intent(out) :: error !! an estimated upper bound on the magnitude of the absolute error in\n !! the calculated result. it should always be examined, since in extreme case\n !! may indicate that there are no correct significant digits in the value\n !! returned for derivative.\n integer, intent(out) :: ifail !! will have one of the following values on exit:\n !! *0* the procedure was successful.\n !! *1* the estimated error in the result exceeds the (non-zero) requested\n !! error, but the most accurate result possible has been returned.\n !! *2* input data incorrect (derivative and error will be undefined).\n !! *3* the interval [`xmin`, `xmax`] is too small (derivative and error will be\n !! undefined).\n !! *-1* stopped by the user.\n\n real(wp) :: acc,beta,beta4,h,h0,h1,h2, &\n newh1,newh2,heval,hprev,baseh,hacc1,hacc2,nhacc1, &\n nhacc2,minh,maxh,maxh1,maxh2,tderiv,f0,twof0,f1,f2,f3,f4,fmax, &\n maxfun,pmaxf,df1,deltaf,pdelta,z,zpower,c0f0,c1,c2,c3,dnew,dprev, &\n re,te,newerr,temerr,newacc,pacc1,pacc2,facc1,facc2,acc0, &\n acc1,acc2,relacc,twoinf,twosup,s, &\n d(10),denom(10),e(10),minerr(10),maxf(0:10),save(0:13),storef(-45:45),factor\n integer :: i,j,k,n,nmax,method,signh,fcount,init\n logical :: ignore(10),contin,saved\n real(wp) :: dummy1,dummy2\n\n integer,parameter :: eta = digits(1.0_wp) - 1 !! minimum number of significant binary digits (apart from the\n !! sign digit) used to represent the mantissa of real(wp) numbers. it should\n !! be decreased by one if the computer truncates rather than rounds.\n integer,parameter :: inf = -minexponent(1.0_wp) - 2 !! the largest possible positive integers subject to\n !! 2**(-inf) and -2**(-inf) being representable real(wp) numbers.\n integer,parameter :: sup = maxexponent(1.0_wp) - 1 !! the largest possible positive integers subject to\n !! 2**sup and -2**sup being representable real(wp) numbers.\n\n real(wp),parameter :: sqrt2 = sqrt(2.0_wp) !! \\( \\sqrt(2) \\)\n real(wp),parameter :: sqrt3 = sqrt(3.0_wp) !! \\( \\sqrt(3) \\)\n\n me%stop = .false.\n\n ! execution commences with examination of input parameters\n if (iord<1 .or. iord>3 .or. xmax<=xmin .or. &\n x0>xmax .or. x0 128.0_wp*twoinf*2.0_wp**eta) s = abs(x0)*2.0_wp**(-eta)\n if (maxh1 < s) then\n ! interval too small\n ifail =3\n return\n end if\n if (acc < 0.0_wp) then\n if (-acc > relacc) relacc = -acc\n acc = 0.0_wp\n end if\n\n ! determine the smallest spacing at which the calculated\n ! function values are unequal near x0.\n\n f0 = me%f(x0)\n if (me%stop) then\n ifail = -1\n return\n end if\n twof0 = f0 + f0\n if (abs(x0) > twoinf*2.0_wp**eta) then\n h = abs(x0)*2.0_wp**(-eta)\n z = 2.0_wp\n else\n h = twoinf\n z = 64.0_wp\n end if\n df1 = me%f(x0+signh*h) - f0\n if (me%stop) then\n ifail = -1\n return\n end if\n do\n if (df1 /= 0.0_wp .or. z*h > maxh1) exit\n h = z*h\n df1 = me%f(x0+signh*h) - f0\n if (me%stop) then\n ifail = -1\n return\n end if\n if (z /= 2.0_wp) then\n if (df1 /= 0.0_wp) then\n h = h/z\n z = 2.0_wp\n df1 = 0.0_wp\n else\n if (z*h > maxh1) z = 2.0_wp\n end if\n end if\n end do\n\n if (df1 == 0.0_wp) then\n ! constant function\n deriv = 0.0_wp\n error = 0.0_wp\n ifail = 0\n return\n end if\n if (h > maxh1/128.0_wp) then\n ! minimum h too large\n ifail = 3\n return\n end if\n\n h = 8.0_wp*h\n h1 = signh*h\n h0 = h1\n h2 = -h1\n minh = 2.0_wp**(-min(inf,sup)/iord)\n if (minh < h) minh = h\n select case (iord)\n case(1)\n s = 8.0_wp\n case(2)\n s = 9.0_wp*sqrt3\n case(3)\n s = 27.0_wp\n end select\n if (minh > maxh1/s) then\n ifail = 3\n return\n end if\n if (minh > maxh2/s .or. maxh2 < 128.0_wp*twoinf) then\n method = 1\n else\n method = 2\n end if\n\n ! method 1 uses 1-sided formulae, and method 2 symmetric.\n ! now estimate accuracy of calculated function values.\n\n if (method /= 2 .or. iord == 2) then\n if (x0 /= 0.0_wp) then\n dummy1 = 0.0_wp\n dummy2 = -h1\n call me%faccur(dummy1,dummy2,acc0,x0,twoinf,f0,f1,ifail)\n if (ifail==-1) return\n else\n acc0 = 0.0_wp\n end if\n end if\n\n if (abs(h1) > twosup/128.0_wp) then\n hacc1 = twosup\n else\n hacc1 = 128.0_wp*h1\n end if\n\n if (abs(hacc1)/4.0_wp < minh) then\n hacc1 = 4.0_wp*signh*minh\n else if (abs(hacc1) > maxh1) then\n hacc1 = signh*maxh1\n end if\n f1 = me%f(x0+hacc1)\n if (me%stop) then\n ifail = -1\n return\n end if\n call me%faccur(hacc1,h1,acc1,x0,twoinf,f0,f1,ifail)\n if (ifail==-1) return\n if (method == 2) then\n hacc2 = -hacc1\n if (abs(hacc2) > maxh2) hacc2 = -signh * maxh2\n f1 = me%f(x0 + hacc2)\n if (me%stop) then\n ifail = -1\n return\n end if\n call me%faccur(hacc2,h2,acc2,x0,twoinf,f0,f1,ifail)\n if (ifail==-1) return\n end if\n nmax = 8\n if (eta > 36) nmax = 10\n n = -1\n fcount = 0\n deriv = 0.0_wp\n error = twosup\n init = 3\n contin = .true.\n\n do\n\n n = n+1\n if (.not. contin) exit\n\n if (init == 3) then\n ! calculate coefficients for differentiation\n ! formulae and neville extrapolation algorithm\n if (iord == 1) then\n beta=2.0_wp\n else if (method == 2) then\n beta = sqrt2\n else\n beta = sqrt3\n end if\n beta4 = beta**4\n z = beta\n if (method == 2) z = z**2\n zpower = 1.0_wp\n do k = 1,nmax\n zpower = z*zpower\n denom(k) = zpower-1\n end do\n if (method == 2 .and. iord == 1) then\n e(1) = 5.0_wp\n e(2) = 6.3_wp\n do i = 3,nmax\n e(i) = 6.81_wp\n end do\n else if ((method /= 2 .and. iord == 1) .or. &\n (method == 2 .and. iord == 2)) then\n e(1) = 10.0_wp\n e(2) = 16.0_wp\n e(3) = 20.36_wp\n e(4) = 23.0_wp\n e(5) = 24.46_wp\n do i = 6,nmax\n e(i) = 26.0_wp\n end do\n if (method == 2 .and. iord == 2) then\n do i = 1,nmax\n e(i)=2.0_wp*e(i)\n end do\n end if\n else if (method /= 2 .and. iord == 2) then\n e(1) = 17.78_wp\n e(2) = 30.06_wp\n e(3) = 39.66_wp\n e(4) = 46.16_wp\n e(5) = 50.26_wp\n do i = 6,nmax\n e(i) = 55.0_wp\n end do\n else if (method == 2 .and. iord == 3) then\n e(1) = 25.97_wp\n e(2) = 41.22_wp\n e(3) = 50.95_wp\n e(4) = 56.4_wp\n e(5) = 59.3_wp\n do i = 6,nmax\n e(i) = 62.0_wp\n end do\n else\n e(1) = 24.5_wp\n e(2) = 40.4_wp\n e(3) = 52.78_wp\n e(4) = 61.2_wp\n e(5) = 66.55_wp\n do i = 6,nmax\n e(i) = 73.0_wp\n end do\n c0f0 = -twof0/(3.0_wp*beta)\n c1 = 3.0_wp/(3.0_wp*beta-1.0_wp)\n c2 = -1.0_wp/(3.0_wp*(beta-1.0_wp))\n c3 = 1.0_wp/(3.0_wp*beta*(5.0_wp-2.0_wp*beta))\n end if\n end if\n\n if (init >= 2) then\n ! initialization of steplengths, accuracy and other parameters\n\n heval = signh*minh\n h = heval\n baseh = heval\n maxh = maxh2\n if (method == 1)maxh = maxh1\n do k = 1,nmax\n minerr(k) = twosup\n ignore(k) = .false.\n end do\n if (method == 1) newacc = acc1\n if (method == -1) newacc = acc2\n if (method == 2) newacc = (acc1+acc2)/2.0_wp\n if (newacc < acc) newacc = acc\n if ((method /= 2 .or. iord == 2) .and. newacc < acc0) newacc = acc0\n if (method /= -1) then\n facc1 = acc1\n nhacc1 = hacc1\n newh1 = h1\n end if\n if (method /= 1) then\n facc2 = acc2\n nhacc2 = hacc2\n newh2 = h2\n else\n facc2 = 0.0_wp\n nhacc2 = 0.0_wp\n end if\n init = 1\n j = 0\n saved = .false.\n end if\n\n ! calculate new or initial function values\n\n if (init == 1 .and. (n == 0 .or. iord == 1) .and. &\n .not.(method == 2 .and. fcount >= 45)) then\n if (method == 2) then\n fcount = fcount + 1\n f1 = me%f(x0+heval)\n if (me%stop) then\n ifail = -1\n return\n end if\n storef(fcount) = f1\n f2 = me%f(x0-heval)\n if (me%stop) then\n ifail = -1\n return\n end if\n storef(-fcount) = f2\n else\n j = j+1\n if (j <= fcount) then\n f1 = storef(j*method)\n else\n f1 = me%f(x0+heval)\n if (me%stop) then\n ifail = -1\n return\n end if\n end if\n end if\n else\n f1 = me%f(x0+heval)\n if (me%stop) then\n ifail = -1\n return\n end if\n if (method == 2) then\n f2 = me%f(x0-heval)\n if (me%stop) then\n ifail = -1\n return\n end if\n end if\n end if\n if (n == 0) then\n if (method == 2 .and. iord == 3) then\n pdelta = f1-f2\n pmaxf = (abs(f1)+abs(f2))/2.0_wp\n heval = beta*heval\n f1 = me%f(x0+heval)\n if (me%stop) then\n ifail = -1\n return\n end if\n f2 = me%f(x0-heval)\n if (me%stop) then\n ifail = -1\n return\n end if\n deltaf = f1-f2\n maxfun = (abs(f1)+abs(f2))/2.0_wp\n heval = beta*heval\n f1 = me%f(x0+heval)\n if (me%stop) then\n ifail = -1\n return\n end if\n f2 = me%f(x0-heval)\n if (me%stop) then\n ifail = -1\n return\n end if\n else if (method /= 2 .and. iord >= 2) then\n if (iord == 2) then\n f3 = f1\n else\n f4 = f1\n heval = beta*heval\n f3 = me%f(x0+heval)\n if (me%stop) then\n ifail = -1\n return\n end if\n end if\n heval = beta*heval\n f2 = me%f(x0+heval)\n if (me%stop) then\n ifail = -1\n return\n end if\n heval = beta*heval\n f1 = me%f(x0+heval)\n if (me%stop) then\n ifail = -1\n return\n end if\n end if\n end if\n\n ! evaluate a new approximation dnew to the derivative\n\n if (n > nmax) then\n n = nmax\n do i = 1,n\n maxf(i-1) = maxf(i)\n end do\n end if\n if (method == 2) then\n maxf(n) = (abs(f1)+abs(f2))/2.0_wp\n if (iord == 1) then\n dnew = (f1-f2)/2.0_wp\n else if (iord == 2) then\n dnew = f1+f2-twof0\n else\n dnew = -pdelta\n pdelta = deltaf\n deltaf = f1-f2\n dnew = dnew + 0.5_wp*deltaf\n if (maxf(n) < pmaxf) maxf(n) = pmaxf\n pmaxf = maxfun\n maxfun = (abs(f1)+abs(f2))/2.0_wp\n end if\n else\n maxf(n) = abs(f1)\n if (iord == 1) then\n dnew = f1-f0\n else if (iord == 2) then\n dnew = (twof0-3.0_wp*f3+f1)/3.0_wp\n if (maxf(n) < abs(f3)) maxf(n) = abs(f3)\n f3 = f2\n f2 = f1\n else\n dnew = c3*f1+c2*f2+c1*f4+c0f0\n if (maxf(n) < abs(f2)) maxf(n) = abs(f2)\n if (maxf(n) < abs(f4)) maxf(n) = abs(f4)\n f4 = f3\n f3 = f2\n f2 = f1\n end if\n end if\n if (abs(h) > 1) then\n dnew = dnew/h**iord\n else\n if (128.0_wp*abs(dnew) > twosup*abs(h)**iord) then\n dnew = twosup/128.0_wp\n else\n dnew = dnew/h**iord\n end if\n end if\n\n if (init == 0) then\n ! update estimated accuracy of function values\n newacc = acc\n if ((method /= 2 .or. iord == 2) .and. newacc < acc0) newacc = acc0\n if (method /= -1 .and. abs(nhacc1) <= 1.125_wp*abs(heval)/beta4) then\n nhacc1 = heval\n pacc1 = facc1\n call me%faccur(nhacc1,newh1,facc1,x0,twoinf,f0,f1,ifail)\n if (ifail==-1) return\n if (facc1 < pacc1) facc1=(3.0_wp*facc1+pacc1)/4.0_wp\n end if\n if (method /= 1 .and. abs(nhacc2) <= 1.125_wp*abs(heval)/beta4) then\n if (method == 2) then\n f1 = f2\n nhacc2 = -heval\n else\n nhacc2 = heval\n end if\n pacc2 = facc2\n call me%faccur(nhacc2,newh2,facc2,x0,twoinf,f0,f1,ifail)\n if (ifail==-1) return\n if (facc2 < pacc2) facc2 = (3.0_wp*facc2+pacc2)/4.0_wp\n end if\n if (method == 1 .and. newacc < facc1) newacc = facc1\n if (method == -1 .and. newacc < facc2) newacc = facc2\n if (method == 2 .and. newacc < (facc1+facc2)/2.0_wp) &\n newacc = (facc1+facc2)/2.0_wp\n end if\n\n ! evaluate successive elements of the current row in the neville\n ! array, estimating and examining the truncation and rounding\n ! errors in each\n\n contin = n < nmax\n hprev = abs(h)\n fmax = maxf(n)\n if ((method /= 2 .or. iord == 2) .and. fmax < abs(f0)) fmax = abs(f0)\n\n do k = 1,n\n dprev = d(k)\n d(k) = dnew\n dnew = dprev+(dprev-dnew)/denom(k)\n te = abs(dnew-d(k))\n if (fmax < maxf(n-k)) fmax = maxf(n-k)\n hprev = hprev/beta\n if (newacc >= relacc*fmax) then\n re = newacc*e(k)\n else\n re = relacc*fmax*e(k)\n end if\n if (re /= 0.0_wp) then\n if (hprev > 1) then\n re = re/hprev**iord\n else if (2.0_wp*re > twosup*hprev**iord) then\n re = twosup/2.0_wp\n else\n re = re/hprev**iord\n end if\n end if\n newerr = te+re\n if (te > re) newerr = 1.25_wp*newerr\n if (.not. ignore(k)) then\n if ((init == 0 .or. (k == 2 .and. .not.ignore(1))) &\n .and. newerr < error) then\n deriv = d(k)\n error = newerr\n end if\n if (init == 1 .and. n == 1) then\n tderiv = d(1)\n temerr = newerr\n end if\n if (minerr(k) < twosup/4.0_wp) then\n s = 4.0_wp*minerr(k)\n else\n s = twosup\n end if\n if (te > re .or. newerr > s) then\n ignore(k) = .true.\n else\n contin = .true.\n end if\n if (newerr < minerr(k)) minerr(k) = newerr\n if (init == 1 .and. n == 2 .and. k == 1 .and. .not.ignore(1)) then\n if (newerr < temerr) then\n tderiv = d(1)\n temerr = newerr\n end if\n if (temerr < error) then\n deriv = tderiv\n error = temerr\n end if\n end if\n end if\n end do\n\n if (n < nmax) d(n+1) = dnew\n if (eps < 0.0_wp) then\n s = abs(eps*deriv)\n else\n s = eps\n end if\n if (error <= s) then\n contin = .false.\n else if (init == 1 .and. (n == 2 .or. ignore(1))) then\n if ((ignore(1) .or. ignore(2)) .and. saved) then\n saved = .false.\n n = 2\n h = beta * save(0)\n heval = beta*save(1)\n maxf(0) = save(2)\n maxf(1) = save(3)\n maxf(2) = save(4)\n d(1) = save(5)\n d(2) = save(6)\n d(3) = save(7)\n minerr(1) = save(8)\n minerr(2) = save(9)\n if (method == 2 .and. iord == 3) then\n pdelta = save(10)\n deltaf = save(11)\n pmaxf = save(12)\n maxfun = save(13)\n else if (method /= 2 .and. iord >= 2) then\n f2 = save(10)\n f3 = save(11)\n if (iord == 3) f4 = save(12)\n end if\n init = 0\n ignore(1) = .false.\n ignore(2) = .false.\n else if (.not. (ignore(1) .or. ignore(2)) .and. n == 2 &\n .and. beta4*factor*abs(heval) <= maxh) then\n ! save all current values in case of return to current point\n saved = .true.\n save(0) = h\n save(1) = heval\n save(2) = maxf(0)\n save(3) = maxf(1)\n save(4) = maxf(2)\n save(5) = d(1)\n save(6) = d(2)\n save(7) = d(3)\n save(8) = minerr(1)\n save(9) = minerr (2)\n if (method == 2 .and. iord == 3) then\n save(10) = pdelta\n save(11) = deltaf\n save(12) = pmaxf\n save(13) = maxfun\n else if (method /= 2 .and. iord >= 2) then\n save(10) = f2\n save(11) = f3\n if (iord == 3) save(12) = f4\n end if\n h = factor*baseh\n heval = h\n baseh = h\n n = -1\n else\n init = 0\n h = beta*h\n heval = beta*heval\n end if\n else if (contin .and. beta*abs(heval) <= maxh) then\n h = beta*h\n heval = beta*heval\n else if (method /= 1) then\n contin = .true.\n if (method == 2) then\n init = 3\n method = -1\n if (iord /= 2) then\n if (x0 /= 0.0_wp) then\n dummy1 = 0.0_wp\n dummy2 = -h0\n call me%faccur(dummy1,dummy2,acc0,x0,twoinf,f0,f1,ifail)\n if (ifail==-1) return\n else\n acc0 = 0.0_wp\n end if\n end if\n else\n init = 2\n method = 1\n end if\n n = -1\n signh = -signh\n else\n contin = .false.\n end if\n\n end do\n\n if (eps < 0.0_wp) then\n s = abs(eps*deriv)\n else\n s = eps\n end if\n ifail = 0\n if (eps /= 0.0_wp .and. error > s) ifail = 1\n\n end if\n\n end subroutine diff\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! This procedure attempts to estimate the level of rounding errors in\n! the calculated function values near the point `x0+h0` by fitting a\n! least-squares straight-line approximation to the function at the\n! six points `x0+h0-j*h1`, (`j = 0,1,3,5,7,9`), and then setting `facc` to\n! twice the largest deviation of the function values from this line.\n! `hi` is adjusted if necessary so that it is approximately 8 times the\n! smallest spacing at which the function values are unequal near `x0+h0`.\n\n subroutine faccur(me,h0,h1,facc,x0,twoinf,f0,f1,ifail)\n\n implicit none\n\n class(diff_func),intent(inout) :: me\n real(wp), intent(inout) :: h0\n real(wp), intent(inout) :: h1\n real(wp), intent(out) :: facc\n real(wp), intent(in) :: x0\n real(wp), intent(in) :: twoinf\n real(wp), intent(in) :: f0\n real(wp), intent(in) :: f1\n integer, intent(out) :: ifail !! 0 if no error, -1 if user termination.\n\n real(wp) :: a0,a1,f00,f001,f2,deltaf,t0,t1,df(5)\n integer :: j\n\n ifail = 0\n t0 = 0.0_wp\n t1 = 0.0_wp\n if (h0 /= 0.0_wp) then\n if (x0+h0 /= 0.0_wp) then\n f00 = f1\n else\n h0 = 0.875_wp*h0\n f00 = me%f(x0+h0)\n if (me%stop) then\n ifail = -1\n return\n end if\n end if\n if (abs(h1) >= 32.0_wp*twoinf) h1 = h1/8.0_wp\n if (16.0_wp*abs(h1) > abs(h0)) h1 = sign(h1,1.0_wp)*abs(h0)/16.0_wp\n f001 = me%f(x0+h0-h1)\n if (me%stop) then\n ifail = -1\n return\n end if\n if (f001 == f00) then\n if (256.0_wp*abs(h1) <= abs(h0)) then\n h1 = 2.0_wp*h1\n do\n f001 = me%f(x0+h0-h1)\n if (me%stop) then\n ifail = -1\n return\n end if\n if (f001 /= f00 .or. 256.0_wp*abs(h1) > abs(h0)) exit\n h1 = 2.0_wp*h1\n end do\n h1 = 8.0_wp*h1\n else\n h1 = sign(h1,1.0_wp)*abs(h0)/16.0_wp\n end if\n else\n if (256.0_wp*twoinf <= abs(h0)) then\n do\n f001 = me%f(x0+h0-h1/2.0_wp)\n if (me%stop) then\n ifail = -1\n return\n end if\n if (f001 == f00 .or. abs(h1) < 4.0_wp*twoinf) exit\n h1 = h1/2.0_wp\n end do\n h1 = 8.0_wp*h1\n if (16.0_wp*abs(h1) > abs(h0)) h1 = sign(h1,1.0_wp)*abs(h0)/16.0_wp\n else\n h1 = sign(h1,1.0_wp)*abs(h0)/16.0_wp\n end if\n end if\n else\n f00 = f0\n end if\n\n do j = 1,5\n f2 = me%f(x0+h0-real(2*j-1,wp)*h1)\n if (me%stop) then\n ifail = -1\n return\n end if\n df(j) = f2 - f00\n t0 = t0+df(j)\n t1 = t1+real(2*j-1,wp)*df(j)\n end do\n a0 = (33.0_wp*t0-5.0_wp*t1)/73.0_wp\n a1 = (-5.0_wp*t0+1.2_wp*t1)/73.0_wp\n facc = abs(a0)\n do j = 1,5\n deltaf = abs(df(j)-(a0+real(2*j-1,wp)*a1))\n if (facc < deltaf) facc = deltaf\n end do\n facc = 2.0_wp*facc\n\n end subroutine faccur\n!*****************************************************************************************\n\n!*****************************************************************************************\n end module diff_module\n!*****************************************************************************************\n", "meta": {"hexsha": "85c40acf88109f5709e68e65a31bc6c79257bedc", "size": 31366, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/diff_module.f90", "max_stars_repo_name": "sebastiandyrda/NumDiff", "max_stars_repo_head_hexsha": "76597b834b251669b052391346d2324be4f8a9eb", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 47, "max_stars_repo_stars_event_min_datetime": "2016-11-02T15:11:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-04T14:23:30.000Z", "max_issues_repo_path": "src/diff_module.f90", "max_issues_repo_name": "sebastiandyrda/NumDiff", "max_issues_repo_head_hexsha": "76597b834b251669b052391346d2324be4f8a9eb", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2018-08-27T13:10:38.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T02:04:55.000Z", "max_forks_repo_path": "src/diff_module.f90", "max_forks_repo_name": "sebastiandyrda/NumDiff", "max_forks_repo_head_hexsha": "76597b834b251669b052391346d2324be4f8a9eb", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-06-03T15:53:54.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-16T02:32:03.000Z", "avg_line_length": 34.6585635359, "max_line_length": 132, "alphanum_fraction": 0.4194031754, "num_tokens": 8859, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310357, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.6961807842463578}} {"text": "! solve the 1d inviscid burgers equation, in conservative form:\n!\n! u_t + [0.5 * u**2 ]_x=0 \n! u=u(x,t) (user defined at t=0)\n!\n! using a second order finite volume predictor-corrector scheme and optional\n! gradient limiters. Boundaries are (minimally-tested) zero gradient.\n!\n! user controled parameters in subroutines \"control\" and \"initial_conditions\"\n!\n! https://github.com/JOThurgood/SimpleCFD/wiki/burgers1.f90\n\nmodule shared_data\n implicit none\n integer, parameter :: num=selected_real_kind(p=15)\n integer :: nx !number of cells\n integer :: ix\n integer(num) :: step, nsteps\n real(num) :: time=0.0_num, t_end, dt\n real(num) :: x_min, x_max \n real(num) :: dx\n real(num), dimension(:), allocatable :: xb, xc\n real(num), dimension(:), allocatable :: u,u1, u1L, u1R\n !solution and states at half time step indicated by 1\n real(num) :: CFL !cfl modifier\n !keyword codes\n integer :: limiter\n integer, parameter :: lim_unlimited = 1, lim_minmod = 2\n contains\nend module shared_data\n\nmodule setup\n\n use shared_data\n\n implicit none\n\n private \n\n public :: initial_setup\n\n contains\n\n subroutine initial_setup\n call control\n call setup_1dfvgrid\n call initial_conditions\n call warnings\n end subroutine initial_setup\n\n subroutine control\n !user control variables\n nx = 256\n x_min = 0.0_num\n x_max = 1.0_num\n t_end = 0.10_num\n CFL = 0.8_num\n nsteps = -1 !set to -1 to run till t_end\n! limiter = lim_unlimited\n limiter = lim_minmod\n end subroutine control\n\n subroutine initial_conditions\n !user set initial profile on a\n! call sinusoid1\n call jump\n! call gaussian\n end subroutine initial_conditions\n\n subroutine jump \n real(num) :: left, right, x_diaphragm \n x_diaphragm = 0.5 \n left = 1.0_num\n right = 2.0_num\n\n u = left\n do ix = -1,nx+2\n if (xc(ix) .GE. x_diaphragm) u(ix) = right \n enddo \n end subroutine jump \n\n subroutine sinusoid1\n real(num) :: lo, hi, pi\n pi = 4.0_num * ATAN(1.0_num)\n lo = 1.0_num / 3.0_num\n hi = 2.0_num / 3.0_num\n u = 1.0_num\n do ix = -1,nx+2\n if ( (xc(ix) .ge. lo) .and. (xc(ix) .le. hi) ) then\n u(ix) = u(ix) + 0.5_num * &\n & SIN( (2.0_num * pi * (xc(ix) - 1.0_num/3.0_num)) / &\n & (1.0_num/3.0_num))\n endif\n enddo \n end subroutine sinusoid1\n\n subroutine setup_1dfvgrid !set up grid and other alloctes\n\n !with 2 guards below\n allocate(xc(-1:nx+2)) !cell center (cc) - coutns from 1 to nx\n allocate(xb(-2:nx+2)) !cell boundary (cb) - counts from 0 to nx\n allocate(u(-1:nx+2)) !cc + 2 guards\n\n !no guards needed below\n allocate(u1(0:nx)) !cb - then used to calc a cc var in corrector step \n allocate(u1L(0:nx)) !cb \n allocate(u1R(0:nx)) !cb\n \n dx = (x_max - x_min) / REAL(nx,num)\n do ix = -2, nx+2\n xb(ix) = x_min + REAL(ix,num) * dx\n if (ix /= -2) xc(ix) = xb(ix) - dx/2.0_num\n enddo\n\n end subroutine setup_1dfvgrid \n\n subroutine warnings\n !stub\n end subroutine warnings\n\n end module setup\n\nmodule solver \n\n use shared_data\n\n implicit none\n\n private \n\n public :: update\n\n contains \n\n subroutine update\n call boundary\n call set_dt \n call interface_states !i_s and riem are \"predictor\" step\n call riemann \n call corrector\n time = time + dt\n end subroutine update\n\n subroutine boundary\n !zero-gradient (untested)\n u(0) = u(1) \n u(-1) = u(2) \n u(nx+1) = u(nx)\n u(nx+2) = u(nx-1)\n end subroutine boundary\n\n subroutine set_dt \n dt = 1e15_num\n do ix = 0,nx\n dt = MIN(CFL * dx / abs(u(ix)), dt)\n enddo\n ! print *,'dt debug: step/selected dt', dt \n end subroutine set_dt\n\n\n subroutine corrector\n !sign right in eq 6.17 ? maybe just due to rearangement of left and right flux\n real(num) :: fl, fr ! flux\n do ix = 1,nx !cc\n fr = 0.5_num * u1(ix) ** 2\n fl = 0.5_num * u1(ix-1) ** 2\n u(ix) = u(ix) - dt / dx * (fr-fl)\n enddo\n endsubroutine corrector\n\n subroutine interface_states\n real(num) :: slope\n do ix = 0, nx ! states on cb !careful with cc vs cb\n !left state\n if (limiter == lim_minmod) then\n slope = minmod( ( u(ix)-u(ix-1) )/dx, ( u(ix+1)-u(ix) )/dx )\n else \n slope = ( u(ix+1) - u(ix-1) ) / 2.0_num / dx\n endif\n u1L(ix) = u(ix) + 0.5_num * dx * (1.0_num - dt * u(ix) / dx) * slope\n !right state\n if (limiter == lim_minmod) then\n slope = minmod( ( u(ix+1)-u(ix) )/dx, ( u(ix+2)-u(ix+1) )/dx )\n else \n slope = ( u(ix+2) - u(ix) ) / 2.0_num / dx\n endif\n u1r(ix) = u(ix+1) - 0.5_num * dx * (1.0_num + dt * u(ix) / dx) * slope\n enddo\n end subroutine interface_states\n\n subroutine riemann \n real(num) :: S, ul, ur,us\n !keep until sure about their notation\n do ix = 0,nx !a1 + interface states on cb\n ul = u1l(ix) \n ur = u1r(ix) \n S = 0.5_num * (ul + ur) \n if ( ul > ur ) then ! compression\n if ( S > 0.0_num) then\n us = ul\n else if (S < 0.0_num) then\n us = ur\n else\n us = 0.0_num\n endif\n else !uniform flow or expansion \n !(this is normal upwinding, no assumption on sign of u) \n if (ul > 0.0_num) then\n us = ul\n else if (ur < 0.0_num) then\n us = ur\n else \n us = 0.0_num\n endif\n endif \n\n u1(ix) = us \n enddo\n\n end subroutine riemann \n\n real(num) function minmod(a,b) ! \"a\" is an unforunate choice of var name \n real(num), intent(in) :: a, b !change to l and r?\n if ( (abs(a) < abs(b)) .and. (a*b > 0) )then\n minmod = a\n else if ( (abs(a) > abs(b)) .and. (a*b > 0) ) then\n minmod = b\n else \n minmod = 0.0_num\n endif \n end function minmod\n\nend module solver\n\nmodule diagnostics\n\n use shared_data\n\n implicit none \n\n contains\n\n subroutine do_io\n integer :: out_unit =10\n call execute_command_line(\"rm -rf xc.dat u.dat\") !dont stream to existing\n open(out_unit, file=\"xc.dat\", access=\"stream\")\n write(out_unit) xc(1:nx)\n close(out_unit)\n open(out_unit, file=\"u.dat\", access=\"stream\")\n write(out_unit) u(1:nx)\n close(out_unit)\n call execute_command_line(\"python plot_burgers1.py\")\n end subroutine do_io\n\nend module diagnostics\n\nprogram burgers1 !main driver\n\n use shared_data\n use setup\n use solver\n use diagnostics\n\n implicit none\n\n call initial_setup\n\n do \n if ((step >= nsteps .and. nsteps >= 0) .or. (time >= t_end)) exit\n step = step + 1\n call update \n enddo\n\n call do_io\n\n print *, 'Done in',step,'steps', 'with CFL',CFL\n\nend program burgers1\n\n", "meta": {"hexsha": "61c05e2db0ee4b7ae901f7af58b59ef44b95b547", "size": 6617, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "burgers_equation/burgers1.f90", "max_stars_repo_name": "JOThurgood/SimpleCFD", "max_stars_repo_head_hexsha": "d0dc2fae9dab21c33d50b443caa727fa763c95d9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-04-23T05:31:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-04T23:21:11.000Z", "max_issues_repo_path": "burgers_equation/burgers1.f90", "max_issues_repo_name": "JOThurgood/SimpleCFD", "max_issues_repo_head_hexsha": "d0dc2fae9dab21c33d50b443caa727fa763c95d9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 39, "max_issues_repo_issues_event_min_datetime": "2018-08-31T23:48:02.000Z", "max_issues_repo_issues_event_max_datetime": "2019-08-07T10:03:11.000Z", "max_forks_repo_path": "burgers_equation/burgers1.f90", "max_forks_repo_name": "JOThurgood/SimpleCFD", "max_forks_repo_head_hexsha": "d0dc2fae9dab21c33d50b443caa727fa763c95d9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-11-14T20:42:54.000Z", "max_forks_repo_forks_event_max_datetime": "2019-05-18T09:16:27.000Z", "avg_line_length": 23.6321428571, "max_line_length": 80, "alphanum_fraction": 0.6007254043, "num_tokens": 2223, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381987656672, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.6961807676636556}} {"text": "program tg\r\n\tuse mympiMod\r\n\tuse fieldMod, only: field\r\n\tuse vectorMod, only: vfield\r\n\tuse fluidMod, only: fluid\r\n use imageMod, only: display\r\n\r\n\timplicit none\r\n\r\n\treal, parameter\t\t:: PI = acos(-1.)\r\n\tinteger,parameter\t:: n(3) = 2**7*[1,1,1] ! Grid size\r\n\treal,parameter\t\t:: kn = 2*PI/n(3) \t! Wavenumber\r\n\treal,parameter\t\t:: Re = 1600\t\t! Reynolds number\r\n\treal, parameter\t\t:: nu=1./(kn*Re)\t! Viscosity\r\n\t\r\n\ttype(fluid)\t\t\t:: flow\r\n\tinteger\t\t\t\t:: b(3)=[4,2,1], m(3), num=9\r\n\treal :: tke\r\n\tlogical :: root\r\n\r\n\t! -- globals\r\n\tcall init_mympi(3, set_blocks=b, set_periodic=[.true.,.true.,.true.])\r\n\troot = mympi_rank()==0\r\n\tm = n/b\r\n\t\r\n\t! -- Initialize flow\r\n\tcall flow%init(m, nu=nu)\r\n\tcall flow%velocity%eval(tgv)\r\n\tcall flow%velocity%applyBC()\r\n\tcall flow%reset_u0()\r\n\tflow%dt = flow%velocity%cfl_limit(nu)\r\n\tflow%velocity%e%exit = .false.\r\n\r\n\t! Print info\r\n\tif(root) write(*,*) '--- Taylor-Green Vortex --- '\r\n\tif(root) print*, 'm', m\r\n\tif(root) print*, 'kn', kn\r\n\tif(root) print*,\r\n\tif(root) print*, \r\n\twrite(num,*) 't CFL tke enstrophy'\r\n\r\n\t! -- Update and keep track of evaluation time\r\n\tdo while (flow%time*kn.le.14)\r\n\t\tcall calc_tke(flow%velocity)\r\n\t\tif (mod(flow%time,2./kn) \\file p2fCO2.f90\n!! \\BRIEF \n!> Module with p2fCO2 subroutine - compute fCO2 from pCO2, in situ T, atm pressure, hydrostatic pressure\nMODULE mp2fCO2\nCONTAINS\n!> Compute fCO2 from arrays of pCO2, in situ temp, atm pressure, & hydrostatic pressure\nSUBROUTINE p2fCO2(pCO2, temp, Patm, p, N, fCO2)\n ! Purpose:\n ! Compute fCO2 from arrays of pCO2, in situ temp, atm pressure, & hydrostatic pressure\n\n#if USE_PRECISION == 2\n# define SGLE(x) (x)\n#else\n# define SGLE(x) REAL(x)\n#endif\n\n USE msingledouble\n IMPLICIT NONE\n\n !> number of records\n!f2py intent(hide) n\n INTEGER, INTENT(in) :: N\n\n! INPUT variables\n !> oceanic partial pressure of CO2 [uatm]\n REAL(kind=rx), INTENT(in), DIMENSION(N) :: pCO2\n !> in situ temperature [C]\n REAL(kind=rx), INTENT(in), DIMENSION(N) :: temp\n !> atmospheric pressure [atm]\n REAL(kind=rx), INTENT(in), DIMENSION(N) :: Patm\n !> hydrostatic pressure [db]\n REAL(kind=rx), INTENT(in), DIMENSION(N) :: p\n\n! OUTPUT variables:\n !> fugacity of CO2 [uatm] \n REAL(kind=rx), INTENT(out), DIMENSION(N) :: fCO2\n\n! LOCAL variables:\n REAL(kind=r8) :: dpCO2, dtemp, tk, dPatm, prb\n REAL(kind=r8) :: Ptot, Rgas_atm, B, Del, xCO2approx, xc2, fugcoeff\n REAL(kind=r8) :: dfCO2\n\n INTEGER :: i\n\n! REAL(kind=r8) :: sw_ptmp\n! EXTERNAL sw_ptmp\n\n DO i = 1,N\n dpCO2 = DBLE(pCO2(i))\n dtemp = DBLE(temp(i))\n dPatm = DBLE(Patm(i))\n tk = 273.15d0 + DBLE(temp(i)) !Absolute temperature (Kelvin)\n prb = DBLE(p(i)) / 10.0d0 !Pressure effect (prb is in bars)\n Ptot = dPatm + prb/1.01325d0 !Total pressure (atmospheric + hydrostatic) [atm]\n Rgas_atm = 82.05736_r8 !R in (cm3 * atm) / (mol * K) from CODATA (2006)\n! To compute fugcoeff, we need 3 other terms (B, Del, xc2) as well as 3 others above (tk, Ptot, Rgas_atm)\n B = -1636.75d0 + 12.0408d0*tk - 0.0327957d0*(tk*tk) + 0.0000316528d0*(tk*tk*tk)\n Del = 57.7d0 - 0.118d0*tk\n! \"x2\" term often neglected (assumed = 1) in applications of Weiss's (1974) equation 9\n! x2 = 1 - x1 = 1 - xCO2 (it is very close to 1, but not quite)\n! Let's assume that xCO2 = pCO2. Resulting fugcoeff is identical to 8th digit after the decimal.\n xCO2approx = dpCO2 * 1.e-6_r8\n xc2 = (1.0d0 - xCO2approx)**2 \n fugcoeff = EXP( Ptot*(B + 2.0d0*xc2*Del)/(Rgas_atm*tk) )\n dfCO2 = dpCO2 * fugcoeff\n fCO2(i) = SGLE(dfCO2)\n END DO\n\n RETURN\nEND SUBROUTINE p2fCO2\nEND MODULE mp2fCO2\n", "meta": {"hexsha": "17803adfc1313a63fd15c8afd61512e29cb1db17", "size": 2450, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/p2fCO2.f90", "max_stars_repo_name": "tomaslovato/mocsy", "max_stars_repo_head_hexsha": "ede19cde4be5cd37ed192a3f3394e81302d11616", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2017-06-20T13:08:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-04T09:51:49.000Z", "max_issues_repo_path": "src/p2fCO2.f90", "max_issues_repo_name": "tomaslovato/mocsy", "max_issues_repo_head_hexsha": "ede19cde4be5cd37ed192a3f3394e81302d11616", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-11-12T19:46:14.000Z", "max_issues_repo_issues_event_max_datetime": "2020-01-23T14:57:14.000Z", "max_forks_repo_path": "src/p2fCO2.f90", "max_forks_repo_name": "tomaslovato/mocsy", "max_forks_repo_head_hexsha": "ede19cde4be5cd37ed192a3f3394e81302d11616", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2015-11-01T01:06:21.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-04T12:58:24.000Z", "avg_line_length": 34.0277777778, "max_line_length": 108, "alphanum_fraction": 0.64, "num_tokens": 936, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206738932334, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6961416029776486}} {"text": " Program dstevd_example\n\n! DSTEVD Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use blas_interfaces, Only: dnrm2\n Use lapack_example_aux, Only: nagf_file_print_matrix_real_gen\n Use lapack_interfaces, Only: dstevd\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nin = 5, nout = 6\n! .. Local Scalars ..\n Real (Kind=dp) :: norm\n Integer :: i, ifail, info, ldz, liwork, lwork, n\n Character (1) :: job\n! .. Local Arrays ..\n Real (Kind=dp), Allocatable :: d(:), e(:), work(:), z(:, :)\n Integer, Allocatable :: iwork(:)\n! .. Executable Statements ..\n Write (nout, *) 'DSTEVD Example Program Results'\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n\n ldz = n\n liwork = 5*n + 3\n lwork = n*n + 4*n + 1\n Allocate (d(n), e(n-1), work(lwork), z(ldz,n), iwork(liwork))\n\n! Read T from data file\n\n Read (nin, *) d(1:n)\n Read (nin, *) e(1:n-1)\n\n Read (nin, *) job\n\n! Calculate all the eigenvalues and eigenvectors of T\n Call dstevd(job, n, d, e, z, ldz, work, lwork, iwork, liwork, info)\n\n Write (nout, *)\n If (info>0) Then\n Write (nout, *) 'Failure to converge.'\n Else\n\n! Print eigenvalues and eigenvectors\n\n Write (nout, *) 'Eigenvalues'\n Write (nout, 100) d(1:n)\n Write (nout, *)\n Flush (nout)\n\n! Normalize the eigenvectors\n Do i = 1, n\n norm = dnrm2(n, z(1,i), 1)\n If (z(1,i)<0.0_dp) Then\n norm = -norm\n End If\n z(1:n, i) = z(1:n, i)/norm\n End Do\n\n! ifail: behaviour on error exit\n! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft\n ifail = 0\n Call nagf_file_print_matrix_real_gen('General', ' ', n, n, z, ldz, &\n 'Eigenvectors', ifail)\n\n End If\n\n100 Format (3X, (8F8.4))\n End Program\n", "meta": {"hexsha": "5bd566361bc3973f470f6911e09739bf00ba1b60", "size": 2169, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/dstevd_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/dstevd_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/dstevd_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 28.5394736842, "max_line_length": 90, "alphanum_fraction": 0.5532503458, "num_tokens": 677, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.853912760387131, "lm_q2_score": 0.8152324848629215, "lm_q1q2_score": 0.6961374215065573}} {"text": "module SmoothingModule\n use KindModule, only: DP, I4B\n use ConstantsModule, only: DZERO, DHALF, DONE, DTWO, DTHREE, DFOUR, &\n & DSIX, DPREC, DEM2, DEM4, DEM5, DEM6, DEM14 \n implicit none\n \n contains\n \n subroutine sSCurve(x,range,dydx,y)\n! ******************************************************************************\n! COMPUTES THE S CURVE FOR SMOOTH DERIVATIVES BETWEEN X=0 AND X=1\n! FROM mfusg smooth SUBROUTINE in gwf2wel7u1.f\n! ******************************************************************************\n! \n! SPECIFICATIONS:\n! ------------------------------------------------------------------------------\n real(DP), intent(in) :: x\n real(DP), intent(in) :: range\n real(DP), intent(inout) :: dydx\n real(DP), intent(inout) :: y\n !--local variables\n real(DP) :: s\n real(DP) :: xs\n! ------------------------------------------------------------------------------\n! code\n!\n s = range\n if ( s < DPREC ) s = DPREC\n xs = x / s\n if (xs < DZERO) xs = DZERO\n if (xs <= DZERO) then\n y = DZERO\n dydx = DZERO\n elseif(xs < DONE)then\n y = -DTWO * xs**DTHREE + DTHREE * xs**DTWO\n dydx = -DSIX * xs**DTWO + DSIX * xs\n else\n y = DONE\n dydx = DZERO\n endif\n return\n end subroutine sSCurve\n \n subroutine sCubicLinear(x,range,dydx,y)\n! ******************************************************************************\n! COMPUTES THE S CURVE WHERE DY/DX = 0 at X=0; AND DY/DX = 1 AT X=1.\n! Smooths from zero to a slope of 1.\n! ******************************************************************************\n! \n! SPECIFICATIONS:\n! ------------------------------------------------------------------------------\n real(DP), intent(in) :: x\n real(DP), intent(in) :: range\n real(DP), intent(inout) :: dydx\n real(DP), intent(inout) :: y\n !--local variables\n real(DP) :: s\n real(DP) :: xs\n! ------------------------------------------------------------------------------\n! code\n!\n s = range\n if ( s < DPREC ) s = DPREC\n xs = x / s\n if (xs < DZERO) xs = DZERO\n if (xs <= DZERO) then\n y = DZERO\n dydx = DZERO\n elseif(xs < DONE)then\n y = -DONE * xs**DTHREE + DTWO * xs**DTWO\n dydx = -DTHREE * xs**DTWO + DFOUR * xs\n else\n y = DONE\n dydx = DZERO\n endif\n return\n end subroutine sCubicLinear\n\n subroutine sCubic(x,range,dydx,y)\n! ******************************************************************************\n! Nonlinear smoothing function returns value between 0-1; cubic function\n! ******************************************************************************\n! \n! SPECIFICATIONS:\n! ------------------------------------------------------------------------------\n real(DP), intent(inout) :: x\n real(DP), intent(inout) :: range\n real(DP), intent(inout) :: dydx\n real(DP), intent(inout) :: y\n !--local variables\n real(DP) :: s, aa, bb\n real(DP) :: cof1, cof2, cof3\n! ------------------------------------------------------------------------------\n! code\n!\n dydx = DZERO\n y = DZERO\n if ( range < DPREC ) range = DPREC\n if ( x < DPREC ) x = DPREC\n s = range\n aa = -DSIX/(s**DTHREE)\n bb = -DSIX/(s**DTWO)\n cof1 = x**DTWO\n cof2 = -(DTWO*x)/(s**DTHREE)\n cof3 = DTHREE/(s**DTWO)\n y = cof1 * (cof2 + cof3)\n dydx = (aa*x**DTWO - bb*x)\n if ( x <= DZERO ) then\n y = DZERO\n dydx = DZERO\n else if ( (x - s) > -DPREC ) then\n y = DONE\n dydx = DZERO\n end if\n return\n end subroutine sCubic\n \n subroutine sLinear(x,range,dydx,y)\n! ******************************************************************************\n! Linear smoothing function returns value between 0-1\n! ******************************************************************************\n! \n! SPECIFICATIONS:\n! ------------------------------------------------------------------------------\n real(DP), intent(inout) :: x\n real(DP), intent(inout) :: range\n real(DP), intent(inout) :: dydx\n real(DP), intent(inout) :: y\n !--local variables\n real(DP) :: s\n! ------------------------------------------------------------------------------\n! code\n!\n dydx = DZERO\n y = DZERO\n if ( range < DPREC ) range = DPREC\n if ( x < DPREC ) x = DPREC\n s = range\n y = DONE - (s - x)/s\n dydx = DONE/s\n if ( y > DONE ) then\n y = DONE\n dydx = DZERO\n end if\n return\n end subroutine sLinear\n \n subroutine sQuadratic(x,range,dydx,y)\n! ******************************************************************************\n! Nonlinear smoothing function returns value between 0-1; quadratic function\n! ******************************************************************************\n! \n! SPECIFICATIONS:\n! ------------------------------------------------------------------------------\n real(DP), intent(inout) :: x\n real(DP), intent(inout) :: range\n real(DP), intent(inout) :: dydx\n real(DP), intent(inout) :: y\n !--local variables\n real(DP) :: s\n! ------------------------------------------------------------------------------\n! code\n!\n dydx = DZERO\n y = DZERO\n if ( range < DPREC ) range = DPREC\n if ( x < DPREC ) x = DPREC\n s = range\n y = (x**DTWO) / (s**DTWO)\n dydx = DTWO*x/(s**DTWO)\n if ( y > DONE ) then\n y = DONE\n dydx = DZERO\n end if\n return\n end subroutine sQuadratic\n\n subroutine sChSmooth(h, smooth, dwdh)\n! ******************************************************************************\n! Function to smooth channel variables during channel drying\n! ******************************************************************************\n! \n! SPECIFICATIONS:\n! ------------------------------------------------------------------------------\n real(DP), intent(in) :: h\n real(DP), intent(inout) :: smooth\n real(DP), intent(inout) :: dwdh\n !--local variables\n real(DP) :: s, aa, ad, b, x, y\n! ------------------------------------------------------------------------------\n! code\n! \n smooth = DZERO\n s = DEM5\n x = h\n if ( x-s > DZERO ) then\n smooth = DONE\n dwdh = DZERO\n else\n aa = -DONE / (s**DTWO)\n ad = -DTWO / (s**DTWO)\n b = DTWO / s\n y = aa * x**DTWO + b*x\n dwdh = (ad*x + b)\n if ( x <= DZERO ) then\n y = DZERO\n dwdh = DZERO\n else if ( x-s > -DEM14 ) then\n y = DONE\n dwdh = DZERO\n end if\n smooth = y\n end if\n return\nend subroutine sChSmooth\n \n function sLinearSaturation(top, bot, x) result(y)\n! ******************************************************************************\n! Linear smoothing function returns value between 0-1;\n! Linear saturation function\n! ******************************************************************************\n! \n! SPECIFICATIONS:\n! ------------------------------------------------------------------------------\n ! -- return\n real(DP) :: y\n ! -- dummy variables\n real(DP), intent(in) :: top\n real(DP), intent(in) :: bot\n real(DP), intent(in) :: x\n ! -- local\n real(DP) :: b\n! ------------------------------------------------------------------------------\n! code\n!\n b = top - bot\n if (x < bot) then\n y = DZERO\n else if (x > top) then\n y = DONE\n else\n y = (x - bot) / b\n end if\n return\n end function sLinearSaturation\n\n\n function sCubicSaturation(top, bot, x, eps) result(y)\n! ******************************************************************************\n! Nonlinear smoothing function returns value between 0-1;\n! Quadratic saturation function\n! ******************************************************************************\n! \n! SPECIFICATIONS:\n! ------------------------------------------------------------------------------\n ! -- return\n real(DP) :: y\n ! -- dummy variables\n real(DP), intent(in) :: top\n real(DP), intent(in) :: bot\n real(DP), intent(in) :: x\n real(DP), intent(in), optional :: eps\n ! -- local\n real(DP) :: teps\n real(DP) :: w\n real(DP) :: b\n real(DP) :: s\n real(DP) :: cof1\n real(DP) :: cof2\n! ------------------------------------------------------------------------------\n! code\n!\n if (present(eps)) then\n teps = eps\n else\n teps = DEM2\n end if\n w = x - bot\n b = top - bot\n s = teps * b\n cof1 = DONE / (s**DTWO)\n cof2 = DTWO / s\n if (w < DZERO) then\n y = DZERO\n else if (w < s) then\n y = -cof1 * (w**DTHREE) + cof2 * (w**DTWO)\n else if (w < (b-s)) then\n y = w / b\n else if (w < b) then\n y = DONE + cof1 * ((b - w)**DTHREE) - cof2 * ((b - w)**DTWO)\n else\n y = DONE\n end if\n \n return\n end function sCubicSaturation\n\n \n function sQuadraticSaturation(top, bot, x, eps) result(y)\n! ******************************************************************************\n! Nonlinear smoothing function returns value between 0-1;\n! Quadratic saturation function\n! ******************************************************************************\n! \n! SPECIFICATIONS:\n! ------------------------------------------------------------------------------\n ! -- return\n real(DP) :: y\n ! -- dummy variables\n real(DP), intent(in) :: top\n real(DP), intent(in) :: bot\n real(DP), intent(in) :: x\n real(DP), optional, intent(in) :: eps\n ! -- local\n real(DP) :: teps\n real(DP) :: b\n real(DP) :: br\n real(DP) :: bri\n real(DP) :: av\n! ------------------------------------------------------------------------------\n! code\n!\n if (present(eps)) then\n teps = eps\n else\n teps = DEM6\n end if\n b = top - bot\n if (b > DZERO) then\n if (x < bot) then\n br = DZERO\n else if (x > top) then\n br = DONE\n else\n br = (x - bot) / b\n end if\n av = DONE / (DONE - teps) \n bri = DONE - br\n if (br < DZERO) then\n y = DZERO\n elseif (br < teps) then\n y = av * DHALF * (br*br) / teps\n elseif (br < (DONE-teps)) then\n y = av * br + DHALF * (DONE - av)\n elseif (br < DONE) then\n y = DONE - ((av * DHALF * (bri * bri)) / teps)\n else\n y = DONE\n end if\n else\n if (x < bot) then\n y = DZERO\n else\n y = DONE\n end if\n end if\n \n return\n end function sQuadraticSaturation\n\n \n function svanGenuchtenSaturation(top, bot, x, alpha, beta, sr) result(y)\n! ******************************************************************************\n! Nonlinear smoothing function returns value between 0-1;\n! van Genuchten saturation function\n! ******************************************************************************\n! \n! SPECIFICATIONS:\n! ------------------------------------------------------------------------------\n ! -- return\n real(DP) :: y\n ! -- dummy variables\n real(DP), intent(in) :: top\n real(DP), intent(in) :: bot\n real(DP), intent(in) :: x\n real(DP), intent(in) :: alpha\n real(DP), intent(in) :: beta\n real(DP), intent(in) :: sr\n ! -- local\n real(DP) :: b\n real(DP) :: pc\n real(DP) :: gamma\n real(DP) :: seff\n! ------------------------------------------------------------------------------\n! code\n!\n b = top - bot\n pc = (DHALF * b) - x\n if (pc <= DZERO) then\n y = DZERO\n else\n gamma = DONE - (DONE / beta)\n seff = (DONE + (alpha * pc)**beta)**gamma\n seff = DONE / seff\n y = seff * (DONE - sr) + sr\n end if\n\n return\n end function svanGenuchtenSaturation\n \n \n function sQuadraticSaturationDerivative(top, bot, x, eps) result(y)\n! ******************************************************************************\n! Derivative of nonlinear smoothing function returns value between 0-1;\n! Derivative of the quadratic saturation function\n! ******************************************************************************\n! \n! SPECIFICATIONS:\n! ------------------------------------------------------------------------------\n ! -- return\n real(DP) :: y\n ! -- dummy variables\n real(DP), intent(in) :: top\n real(DP), intent(in) :: bot\n real(DP), intent(in) :: x\n real(DP), optional, intent(in) :: eps\n ! -- local\n real(DP) :: teps\n real(DP) :: b\n real(DP) :: br\n real(DP) :: bri\n real(DP) :: av\n! ------------------------------------------------------------------------------\n! code\n!\n if (present(eps)) then\n teps = eps\n else\n teps = DEM6\n end if\n b = top - bot\n if (x < bot) then\n br = DZERO\n else if (x > top) then\n br = DONE\n else\n br = (x - bot) / b\n end if\n av = DONE / (DONE - teps) \n bri = DONE - br\n if (br < DZERO) then\n y = DZERO\n elseif (br < teps) then\n y = av * br / teps\n elseif (br < (DONE-teps)) then\n y = av\n elseif (br < DONE) then\n y = av * bri / teps\n else\n y = DZERO\n end if\n y = y / b\n \n return\n end function sQuadraticSaturationDerivative\n\n\n\n function sQSaturation(top, bot, x) result(y)\n! ******************************************************************************\n! Nonlinear smoothing function returns value between 0-1;\n! Cubic saturation function\n! ******************************************************************************\n! \n! SPECIFICATIONS:\n! ------------------------------------------------------------------------------\n ! -- return\n real(DP) :: y\n ! -- dummy variables\n real(DP), intent(in) :: top\n real(DP), intent(in) :: bot\n real(DP), intent(in) :: x\n ! -- local\n real(DP) :: w\n real(DP) :: b\n real(DP) :: s\n real(DP) :: cof1\n real(DP) :: cof2\n! ------------------------------------------------------------------------------\n! code\n!\n w = x - bot\n b = top - bot\n s = w / b\n cof1 = -DTWO / b**DTHREE\n cof2 = DTHREE / b**DTWO\n if (s < DZERO) then\n y = DZERO\n else if(s < DONE) then\n y = cof1 * w**DTHREE + cof2 * w**DTWO\n else\n y = DONE\n end if\n \n return\n end function sQSaturation\n \n function sQSaturationDerivative(top, bot, x) result(y)\n! ******************************************************************************\n! Nonlinear smoothing function returns value between 0-1;\n! Cubic saturation function\n! ******************************************************************************\n! \n! SPECIFICATIONS:\n! ------------------------------------------------------------------------------\n ! -- return\n real(DP) :: y\n ! -- dummy variables\n real(DP), intent(in) :: top\n real(DP), intent(in) :: bot\n real(DP), intent(in) :: x\n ! -- local\n real(DP) :: w\n real(DP) :: b\n real(DP) :: s\n real(DP) :: cof1\n real(DP) :: cof2\n! ------------------------------------------------------------------------------\n! code\n!\n w = x - bot\n b = top - bot\n s = w / b\n cof1 = -DSIX / b**DTHREE\n cof2 = DSIX / b**DTWO\n if (s < DZERO) then\n y = DZERO\n else if(s < DONE) then\n y = cof1 * w**DTWO + cof2 * w\n else\n y = DZERO\n end if\n \n return\n end function sQSaturationDerivative\n \n \n \nend module SmoothingModule\n \n ", "meta": {"hexsha": "7d4b3a7c0cc738f6ffc66a0bbfafb05cfa7999c8", "size": 15096, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/Utilities/SmoothingFunctions.f90", "max_stars_repo_name": "maseology/mmMODFLOW6", "max_stars_repo_head_hexsha": "c4cfd2a5b52a80886142c2048ab44e0486516ae9", "max_stars_repo_licenses": ["MIT"], "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/Utilities/SmoothingFunctions.f90", "max_issues_repo_name": "maseology/mmMODFLOW6", "max_issues_repo_head_hexsha": "c4cfd2a5b52a80886142c2048ab44e0486516ae9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Utilities/SmoothingFunctions.f90", "max_forks_repo_name": "maseology/mmMODFLOW6", "max_forks_repo_head_hexsha": "c4cfd2a5b52a80886142c2048ab44e0486516ae9", "max_forks_repo_licenses": ["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.9038817006, "max_line_length": 80, "alphanum_fraction": 0.3865924748, "num_tokens": 3934, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127455162773, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.696137411299995}} {"text": "!> @ingroup is_sorted_#ORD_NAME#\n!>\n!> @brief\n!> Check if a vector of real values is sorted by a decending order. \n!> \n!> @details\n!> Check if a vector of real values is sorted by a decending order. Returns a logical value indicating if the vector is sorted.\n!> \n!> @result sorted\n!> Indicates if the vector is sorted.\n!> \n!> | Value | Meaning |\n!> |:-----:|:------------------------ |\n!> | true | The vector is sorted |\n!> | false | The vector is not sorted |\n!>\n\n!> @param x\n!> The vector to be checked for being sorted.\n!>\n!> @note\n!> Empty and single value vectors are considered sorted.\n!>\n!> @author Arin R. Bratt\n!> @date 10/07/2014\npure function is_sorted_dec_real(x) result(sorted)\n \n ! Result\n logical :: sorted\n\n ! Arguments\n real, intent(in) :: x(:)\n \n ! Variables\n integer :: i\n \n ! This structure avoides checking empty or single value vectors, which are always considered sorted.\n do i = 2,size(x,1)\n if (x(i - 1) < x(i)) then\n sorted = .false.\n return\n end if\n end do\n sorted = .true.\nend function is_sorted_dec_real\n\n", "meta": {"hexsha": "1ac54e9cc21d6e7aedf3f54bce097dcbf82d258a", "size": 1092, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/is_sorted_dec_real.f90", "max_stars_repo_name": "arinrb/bsort", "max_stars_repo_head_hexsha": "17cc0e2cbe52af808bae860d53dd4e4d691f4674", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-11-08T18:36:23.000Z", "max_stars_repo_stars_event_max_datetime": "2015-11-08T18:36:23.000Z", "max_issues_repo_path": "src/is_sorted_dec_real.f90", "max_issues_repo_name": "arinrb/bsort", "max_issues_repo_head_hexsha": "17cc0e2cbe52af808bae860d53dd4e4d691f4674", "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/is_sorted_dec_real.f90", "max_forks_repo_name": "arinrb/bsort", "max_forks_repo_head_hexsha": "17cc0e2cbe52af808bae860d53dd4e4d691f4674", "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.2340425532, "max_line_length": 127, "alphanum_fraction": 0.6172161172, "num_tokens": 318, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324713956854, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.6961374054605117}} {"text": "\tSUBROUTINE strapzd(func,a,b,s,n)\n\tuse mo_kind\n use mo_nrutil, ONLY : arth\n\tIMPLICIT NONE\n\tREAL(SP), INTENT(IN) :: a,b\n\tREAL(SP), INTENT(INOUT) :: s\n\tINTEGER(I4), INTENT(IN) :: n\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\tREAL(SP) :: del,fsum\n\tINTEGER(I4) :: it\n\tif (n == 1) then\n\t\ts=0.5_sp*(b-a)*sum(func( (/ a,b /) ))\n\telse\n\t\tit=2**(n-2)\n\t\tdel=(b-a)/it\n\t\tfsum=sum(func(arth(a+0.5_sp*del,del,it)))\n\t\ts=0.5_sp*(s+del*fsum)\n\tend if\n\tEND SUBROUTINE strapzd\n\n\tSUBROUTINE dtrapzd(func,a,b,s,n)\n\tuse mo_kind\n use mo_nrutil, ONLY : arth\n\tIMPLICIT NONE\n\tREAL(DP), INTENT(IN) :: a,b\n\tREAL(DP), INTENT(INOUT) :: s\n\tINTEGER(I4), INTENT(IN) :: n\n\tINTERFACE\n\t\tFUNCTION 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\tREAL(DP) :: del,fsum\n\tINTEGER(I4) :: it\n\tif (n == 1) then\n\t\ts=0.5_dp*(b-a)*sum(func( (/ a,b /) ))\n\telse\n\t\tit=2**(n-2)\n\t\tdel=(b-a)/it\n\t\tfsum=sum(func(arth(a+0.5_dp*del,del,it)))\n\t\ts=0.5_dp*(s+del*fsum)\n\tend if\n\tEND SUBROUTINE dtrapzd\n\n", "meta": {"hexsha": "ded4aedd961b2f7c226e5c86ce95d6a47cf7c76a", "size": 1162, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "nr_jams/trapzd.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/trapzd.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/trapzd.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": 21.9245283019, "max_line_length": 43, "alphanum_fraction": 0.6179001721, "num_tokens": 467, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388083214156, "lm_q2_score": 0.8397339736884711, "lm_q1q2_score": 0.6960880794563282}} {"text": "program main\n ! solve the Schrodinger equation of a particle in an infinite potential well with central barrier with Exact Diagonalization\n\n implicit none\n integer, parameter :: dp = selected_real_kind(8)\n real(dp), parameter :: pi = acos(-1.d0)\n\n ! local vars\n integer :: i, j, m, m1, ifactorial, mfactorial, iminus2mfactorail, Nx, LWORK, INFO\n real(dp) :: Xmax, dx, V0\n real(dp), allocatable :: x(:), Vpot(:), Ham(:,:), basis(:,:), W(:), WORK(:)\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 - 1.d0)**2 / 4.d0 - x(i)**2)\n end do\n\n allocate(basis(2 * Nx + 1, 2 * Nx +1))\n basis = 0.d0\n do i = 1, 2 * Nx + 1 ! order of basis function + 1\n write(*,*) i\n ifactorial = 1\n do m1 = 1, (i - 1)\n ifactorial = ifactorial * m1\n end do\n do j = 1, 2 * Nx + 1 ! coordinate index\n if (mod((i - 1), 2) /= 0) then\n ! (i - 1) is odd\n do m = 0, ((i - 1) - 1) / 2\n mfactorial = 1\n do m1 = 1, m\n mfactorial = mfactorial * m1\n end do\n iminus2mfactorail = 1\n do m1 = 1, (i - 1) - 2 * m\n iminus2mfactorail = iminus2mfactorail * m1\n end do\n basis(i,j) = basis(i,j)&\n + dble((-1)**m) * dble(ifactorial) / dble(mfactorial) / dble(iminus2mfactorail) *&\n (2.d0 * x(j - Nx -1))**((i - 1) - 2 * m)\n end do\n write(*, '(3f32.16)', advance = 'no')&\n basis(i,j), exp(-x(j - Nx - 1)**2 / 2.d0), basis(i,j) * exp(-x(j - Nx - 1)**2 / 2.d0)\n basis(i,j) = basis(i,j) * exp(-x(j - Nx - 1)**2 / 2.d0)\n else\n ! (i - 1) is even\n do m = 0, (i - 1) / 2\n mfactorial = 1\n do m1 = 1, m\n mfactorial = mfactorial * m1\n end do\n iminus2mfactorail = 1\n do m1 = 1, (i - 1) - 2 * m\n iminus2mfactorail = iminus2mfactorail * m1\n end do\n basis(i,j) = basis(i,j)&\n + dble((-1)**m) * dble(ifactorial) / dble(mfactorial) / dble(iminus2mfactorail) *&\n (2.d0 * x(j - Nx - 1))**((i - 1) - 2 * m)\n end do\n write(*, '(3f32.16)', advance = 'no')&\n basis(i,j), exp(-x(j - Nx - 1)**2 / 2.d0), basis(i,j) * exp(-x(j - Nx - 1)**2 / 2.d0)\n basis(i,j) = basis(i,j) * exp(-x(j - Nx - 1)**2 / 2.d0)\n end if\n write(*,*)\n end do\n end do\n\n ! do i = 1, 2 * Nx + 1\n ! write(*, '(f20.8,f20.12)', advance = 'no') x(i - Nx - 1)\n ! do j = 1, 2 * Nx + 1\n ! write(*,'(f12.6)', advance = 'no') basis(j,i)\n ! end do\n ! write(*,*)\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 do j = i, 2 * Nx + 1\n call Simpson(2 * Nx + 1, basis(i, 1:2 * Nx + 1), basis(j, 1:2 * Nx + 1), Vpot(-Nx:Nx) - .5d0, dx, V0)\n Ham(i, j) = V0\n if (i == j) then\n Ham(i, j) = Ham(i, j) + (i - .5d0)\n end if\n Ham(j, i) = Ham(i, j)\n end do\n end do\n\n allocate(W(2 * Nx + 1))\n LWORK = 10 * Nx\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 = '4-energy-ExactDiagonalization.txt', status = 'unknown')\n open(unit = 2, file = '4-wavefunction-ExactDiagonalization.txt', status = 'unknown')\n\n ! multiply the coefficient (which is stored in Ham now) with the basis function to get the wave function\n Ham = matmul(transpose(basis), Ham)\n\n ! output results\n do i = 1, 2 * Nx + 1\n write(1, '(i4,f20.12)') i, W(i)\n write(2, '(f12.16)', 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 ! open(unit = 1, file = 'tmp.txt', status = 'unknown')\n ! test\n ! do i = 1, 2 * Nx + 1\n ! write(1, '(f20.8,f20.12)', advance = 'no') x(i - Nx - 1)\n ! do j = 1, 2 * Nx + 1\n ! write(1,'(f12.6)', advance = 'no') basis(j,i)\n ! end do\n ! write(1,*)\n ! end do\n ! close(1)\n stop\n end if\n\n deallocate(Ham)\n deallocate(basis, W, WORK)\n deallocate(x, Vpot)\n\nend program main\n\nsubroutine Simpson(N, u, v, Vpot, dx, V0)\n ! calculate the integral of the product of u, v, and Vpot from -Xmax to Xmax with compound simpson formula\n\n implicit none\n integer :: N\n real(8), intent(in) :: u(N), v(N), Vpot(N), dx\n real(8), intent(out) :: V0\n\n ! local vars\n integer :: i\n real(8) :: Work(N)\n\n if (mod(N, 2) == 0) then\n ! Simpson does not work for integral of array with even number of elements\n write(*, *) 'Array with even elements, Simpson does not know how to work!'\n end if\n\n do i = 1, N\n Work(i) = Vpot(i) * u(i) * v(i)\n end do\n \n V0 = Work(1) + Work(N)\n do i = 2, N - 1, 2\n V0 = V0 + 4.d0 * Work(i)\n end do\n do i = 3, N - 2, 2\n V0 = V0 + 2.d0 * Work(i)\n end do\n V0 = V0 * dx / 3.d0\n\nend subroutine Simpson\n", "meta": {"hexsha": "824f613819ad589c91f6fb4c572b2643659977fe", "size": 6061, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Week-2-Assignment-1/Assignment/4-test.f90", "max_stars_repo_name": "Chen-Jialin/Computational-Physics-Exercises-and-Assignments", "max_stars_repo_head_hexsha": "592407af2e999b539473f473ca99186a12418b99", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-04-15T10:30:01.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T08:22:51.000Z", "max_issues_repo_path": "Week-2-Assignment-1/Assignment/4-test.f90", "max_issues_repo_name": "Chen-Jialin/Computational-Physics-Exercises-and-Assignments", "max_issues_repo_head_hexsha": "592407af2e999b539473f473ca99186a12418b99", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Week-2-Assignment-1/Assignment/4-test.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": 33.3021978022, "max_line_length": 128, "alphanum_fraction": 0.4420062696, "num_tokens": 2089, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802440252811, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6960191590493163}} {"text": " SUBROUTINE sdr2sdr(line,soln)\nC----\nC Compute the second nodal plane of a double couple source\nC algebraically.\nC----\n IMPLICIT none\n CHARACTER*180 line,soln\n REAL*8 pi,d2r,r2d\n PARAMETER (pi=4.0d0*datan(1.0d0),d2r=pi/1.8d2,r2d=1.8d2/pi)\n REAL*8 str1,dip1,rak1,str,dip,rak,str2,dip2,rak2\n REAL*8 xn1,yn1,zn1,xr,yr,zr,xs2,ys2,zs2,dum1\nC Get input strike, dip, rake in degrees; convert to radians\n read(line,*) str1,dip1,rak1\n str = d2r*str1\n dip = d2r*dip1\n rak = d2r*rak1\nC Normal vector to input plane\n xn1 = dsin(dip)*dcos(str)\n yn1 = -dsin(dip)*dsin(str)\n zn1 = dcos(dip)\nC Rake vector of input plane\n xr = dcos(rak)*dsin(str) - dcos(dip)*dsin(rak)*dcos(str)\n yr = dcos(rak)*dcos(str) + dcos(dip)*dsin(rak)*dsin(str)\n zr = dsin(rak)*dsin(dip)\n ! If vector points downward, flip it\n if (zr.lt.0.0d0) then\n xr = -xr\n yr = -yr\n zr = -zr\n xn1 = -xn1\n yn1 = -yn1\n zn1 = -zn1\n endif\nC Compute new strike\n str2 = r2d*datan2(xr,yr) - 90.0d0\n if (str2.gt.360.0d0) str2 = str2 - 360.0d0\n if (str2.lt.0.0d0) str2 = str2 + 360.0d0\nC Compute new dip\n dip2 = r2d*datan(dsqrt(xr*xr+yr*yr)/zr)\nC Compute new rake\n xs2 = dsin(str2*d2r)\n ys2 = dcos(str2*d2r)\n zs2 = 0.0d0\n rak2 = r2d*dacos(xn1*xs2+yn1*ys2+zn1*zs2)\nC Check rake is pos or neg\n dum1 = xs2*yn1 - ys2*xn1\n if (dum1.lt.0.0d0) then\n rak2 = -rak2\n endif\nC Write strike, dip, and rake in degrees\n write(soln,9999) str2,dip2,rak2\n 9999 format(3F6.0)\n RETURN\n END\n\nC----------------------------------------------------------------------C\n\n SUBROUTINE sdr2mij(line,soln)\nC----\nC Compute the (unit) moment tensor from double couple strike, dip, and\nC rake angles.\nC----\n IMPLICIT none\n CHARACTER*180 line,soln\n REAL*8 pi,d2r\n PARAMETER (pi=4.0d0*datan(1.0d0),d2r=pi/1.8d2)\n REAL*8 str1,dip1,rak1,str,dip,rak\n REAL*8 cs,ss,s2s,c2s,cd,sd,s2d,c2d,cr,sr\n REAL*8 mrr,mtt,mpp,mrt,mrp,mtp\nC Get input strike, dip, rake in degrees; convert to radians\n read(line,*) str1,dip1,rak1\n str = d2r*str1\n dip = d2r*dip1\n rak = d2r*rak1\nC Derived trigonometric variables\n cs = dcos(str)\n ss = dsin(str)\n s2s = dsin(2.0d0*str)\n c2s = dcos(2.0d0*str)\n cd = dcos(dip)\n sd = dsin(dip)\n s2d = dsin(2.0d0*dip)\n c2d = dcos(2.0d0*dip)\n cr = dcos(rak)\n sr = dsin(rak)\nC Moment tensor components in GCMT convention (r,t,p)\n mrr = ( s2d*sr )\n mtt = -(sd*cr*s2s + s2d*sr*ss*ss)\n mpp = (sd*cr*s2s - s2d*sr*cs*cs)\n mrt = -(cd*cr*cs + c2d*sr*ss )\n mrp = (cd*cr*ss - c2d*sr*cs )\n mtp = -(sd*cr*c2s + s2d*sr*ss*cs)\nC Write moment tensor components\n write(soln,9999) mrr,mtt,mpp,mrt,mrp,mtp\n 9999 format(6(1PE14.6))\n RETURN\n END\n\nC----------------------------------------------------------------------C\n\n SUBROUTINE sdr2ter(line,soln)\n IMPLICIT none\n CHARACTER*180 line,soln\n REAL*8 p(3),n(3),t(3),fth,fss,fno\n call sdr2pnt(line,soln)\n read(soln,*) p(1),p(2),p(3),n(1),n(2),n(3),t(1),t(2),t(3)\n fno = datan(p(3)/dsqrt(p(1)*p(1)+p(2)*p(2)))\n fss = datan(n(3)/dsqrt(n(1)*n(1)+n(2)*n(2)))\n fth = datan(t(3)/dsqrt(t(1)*t(1)+t(2)*t(2)))\n fno = dsin(fno)*dsin(fno)\n fss = dsin(fss)*dsin(fss)\n fth = dsin(fth)*dsin(fth)\n write(soln,1001) fth,fss,fno\n 1001 format(3F7.3)\n RETURN\n END\n\nC----------------------------------------------------------------------C\n\n SUBROUTINE sdr2sv(line,soln)\n IMPLICIT none\n REAL*8 pi,r2d,d2r\n PARAMETER (pi=4.0d0*datan(1.0d0),d2r=pi/1.8d2,r2d=1.8d2/pi)\n CHARACTER*180 line,soln\n REAL*8 s1,d1,r1,x1,y1,z1,n1,e1\n read(line,*) s1,d1,r1\n s1 = s1*d2r\n d1 = d1*d2r\n r1 = r1*d2r\nC x in strike direction, y in hor updip direction\n x1 = dcos(r1)\n y1 = dsin(r1)*dcos(d1)\n z1 = dsin(r1)*dsin(d1)\nC rotate to east-north\n e1 = x1*dsin(s1) - y1*dcos(s1)\n n1 = x1*dcos(s1) + y1*dsin(s1)\n write(soln,1001) datan2(e1,n1)*r2d,\n 1 datan2(z1,dsqrt(e1*e1+n1*n1))*r2d\n 1001 format(2F10.3)\n RETURN\n END\n\nC----------------------------------------------------------------------C\n\n SUBROUTINE pnt2ter(line,soln)\n IMPLICIT none\n CHARACTER*180 line,soln\n REAL*8 p(3),n(3),t(3),fth,fss,fno\n read(line,*) p(1),p(2),p(3),n(1),n(2),n(3),t(1),t(2),t(3)\n fno = datan(p(3)/dsqrt(p(1)*p(1)+p(2)*p(2)))\n fss = datan(n(3)/dsqrt(n(1)*n(1)+n(2)*n(2)))\n fth = datan(t(3)/dsqrt(t(1)*t(1)+t(2)*t(2)))\n fno = dsin(fno)*dsin(fno)\n fss = dsin(fss)*dsin(fss)\n fth = dsin(fth)*dsin(fth)\n write(soln,1001) fth,fss,fno\n 1001 format(3F7.3)\n RETURN\n END\n\nC----------------------------------------------------------------------C\n\n SUBROUTINE pnt2mag(line,soln)\n IMPLICIT none\n CHARACTER*180 line,soln\n REAL*8 mom\n call pnt2mom(line,soln)\n read(soln,*) mom\n write(line,1001) mom\n 1001 format(1P1E14.6)\n call mom2mag(line,soln)\n RETURN\n END\n\nC----------------------------------------------------------------------C\n\n SUBROUTINE pnt2mom(line,soln)\n IMPLICIT none\n CHARACTER*180 line,soln\n REAL*8 dum,p,n,t,mom\n read(line,*) dum,dum,dum,dum,dum,dum,dum,dum,dum,p,n,t\n mom = 0.5d0*(dabs(p)+dabs(t))\n write(soln,1001) mom\n 1001 format(1P1E14.6)\n RETURN\n END\n\nC----------------------------------------------------------------------C\n\n SUBROUTINE mij2ter(line,soln)\n IMPLICIT none\n CHARACTER*180 line,soln\n REAL*8 p(3),n(3),t(3),fth,fss,fno\n call mij2pnt(line,soln)\n read(soln,*) p(1),p(2),p(3),n(1),n(2),n(3),t(1),t(2),t(3)\n fno = datan(p(3)/dsqrt(p(1)*p(1)+p(2)*p(2)))\n fss = datan(n(3)/dsqrt(n(1)*n(1)+n(2)*n(2)))\n fth = datan(t(3)/dsqrt(t(1)*t(1)+t(2)*t(2)))\n fno = dsin(fno)*dsin(fno)\n fss = dsin(fss)*dsin(fss)\n fth = dsin(fth)*dsin(fth)\n write(soln,1001) fth,fss,fno\n 1001 format(3F7.3)\n RETURN\n END\n\nC----------------------------------------------------------------------C\n\n SUBROUTINE mij2mom(line,soln)\nC----\nC Compute the seismic moment (N-m) from moment tensor elements (N-m)\nC----\n IMPLICIT none\n CHARACTER*180 line,soln\n REAL*8 dum,p,n,t,mom\n call mij2pnt(line,soln)\n read(soln,*) dum,dum,dum,dum,dum,dum,dum,dum,dum,p,n,t\n mom = 0.5d0*(dabs(p)+dabs(t))\n write(soln,1001) mom\n 1001 format(1P1E14.6)\n RETURN\n END\n\nC----------------------------------------------------------------------C\n\n SUBROUTINE mom2mag(line,soln)\nC----\nC Compute the magnitude from seismic moment (N-m)\nC----\n IMPLICIT none\n CHARACTER*180 line,soln\n REAL*8 mom,mag\n read(line,*) mom\n mag = 2.0d0/3.0d0*dlog10(mom*1.0d7)-10.7d0\n write(soln,1001) mag\n 1001 format(1F8.2)\n RETURN\n END\n\nC----------------------------------------------------------------------C\n\n SUBROUTINE mag2mom(line,soln)\n IMPLICIT none\n CHARACTER*180 line,soln\n REAL*8 mom,mag\n read(line,*) mag\n mom = 10**((mag+10.7d0)*1.5d0)*1.0d-7\n write(soln,1001) mom\n 1001 format(1P1E14.6)\n RETURN\n END\n\nC----------------------------------------------------------------------C\n\n SUBROUTINE mij2mag(line,soln)\n IMPLICIT none\n CHARACTER*180 line,soln\n REAL*8 mom\n call mij2mom(line,soln)\n read(soln,*) mom\n write(line,1001) mom\n 1001 format(1P1E14.6)\n call mom2mag(line,soln)\n RETURN\n END\n\nC----------------------------------------------------------------------C\n\n SUBROUTINE sdr2pnt(line,soln)\nC----\nC Compute the (unit) P, N, T axes from double couple strike, dip, and\nC rake angles.\nC----\n IMPLICIT none\n CHARACTER*180 line,soln\n REAL*8 mrr,mtt,mpp,mrt,mrp,mtp\nC Convert to moment tensor components\n call sdr2mij(line,soln)\n read(soln,*) mrr,mtt,mpp,mrt,mrp,mtp\n write(line,9989) mrr,mtt,mpp,mrt,mrp,mtp\n 9989 format(6(1P1E14.6))\nC Convert to P, N, T axes\n call mij2pnt(line,soln)\n RETURN\n END\n\nC----------------------------------------------------------------------C\n\n SUBROUTINE pntxyz2plaz(line,soln)\n IMPLICIT none\n REAL*8 pi,r2d\n PARAMETER (pi=4.0d0*datan(1.0d0),r2d=1.8d2/pi)\n CHARACTER*180 line,soln\n REAL*8 PNT(3,3),H\n REAL*8 pl(3),az(3),mg(3)\n INTEGER i\nC Read in P, N, T vectors in Cartesian coordinates\n read(line,*) PNT(1,1),PNT(1,2),PNT(1,3),\n 1 PNT(2,1),PNT(2,2),PNT(2,3),\n 2 PNT(3,1),PNT(3,2),PNT(3,3)\nC Compute plunge, azimuth, length\n do 103 i = 1,3\n H = dsqrt(PNT(i,1)*PNT(i,1)+PNT(i,2)*PNT(i,2))\n pl(i) = datan(PNT(i,3)/H)*r2d\n az(i) = datan2(PNT(i,1),PNT(i,2))*r2d\n if (pl(i).gt.0.0d0) then\n az(i) = az(i) + 1.8d2\n pl(i) = -pl(i)\n endif\n pl(i) = -pl(i)\n mg(i) = dsqrt(H*H+PNT(i,3)*PNT(i,3))\n 103 continue\nC Write to new output\n write(soln,1001) az(1),pl(1),mg(1),az(2),pl(2),mg(2),az(3),pl(3),\n 1 mg(3)\n 1001 format(3(2F6.0,1P1E14.6))\n RETURN\n END\n\nC----------------------------------------------------------------------C\n\n SUBROUTINE mij2sdr(line,soln)\nC----\nC Compute the best fitting double couple source (strike, dip, rake) of a\nC moment tensor source.\nC----\n IMPLICIT none\n CHARACTER*180 line,soln\n INTEGER n,lda,lwmax\n PARAMETER (n=3,lda=n,lwmax=250)\n INTEGER info,lwork\n REAL*8 a(lda,n),w(n),work(lwmax),m(6)\n REAL*8 p(3),t(3),slip(3),normal(3),str,dip,rak,str2,dip2,rak2\n INTEGER i\nC Get input moment tensor (mrr, mtt, mpp, mrt, mrp, mtp; r=z, t=n, p=e)\nC Moment tensor components (r=z, t=e, p=n):\n read(line,*) m(1),m(2),m(3),m(4),m(5),m(6)\n a(3,3) = m(1) ! mrr = mzz\n a(2,2) = m(2) ! mtt = myy\n a(1,1) = m(3) ! mpp = mxx\n a(2,3) = -m(4) ! mrt = -myz\n a(3,2) = -m(4)\n a(1,3) = m(5) ! mrp = mxz\n a(3,1) = m(5)\n a(1,2) = -m(6) ! mtp = -mxy\n a(1,2) = -m(6)\nC Query the optimal workspace\n lwork = -1\n call dsyev('Vectors','Upper',n,a,lda,w,work,lwork,info)\n lwork = min(lwmax,int(work(1)))\nC Solve eigenproblem\n call dsyev('Vectors','Upper',n,a,lda,w,work,lwork,info)\nC Compute best-fitting focal mechanism\n do 103 i = 1,3\n p(i) = a(i,1)\n t(i) = a(i,3)\n 103 continue\n call pt2un(p,t,slip,normal)\n call un2sdr(slip,normal,str,dip,rak)\n write(line,*) str,dip,rak\n call sdr2sdr(line,soln)\n read(soln,*) str2,dip2,rak2\n write(soln,1001) str,dip,rak,str2,dip2,rak2\n 1001 format(6F6.0)\n RETURN\n END\n\nC----------------------------------------------------------------------C\n\n SUBROUTINE mij2sv(line,soln)\n IMPLICIT none\n CHARACTER*180 line,soln\n REAL*8 s1,d1,r1,s2,d2,r2,az1,pl1,az2,pl2\n call mij2sdr(line,soln)\n read(soln,*) s1,d1,r1,s2,d2,r2\n write(line,*) s1,d1,r1\n call sdr2sv(line,soln)\n read(soln,*) az1,pl1\n write(line,*) s2,d2,r2\n call sdr2sv(line,soln)\n read(soln,*) az2,pl2\n write(soln,1001) az1,pl1,az2,pl2\n 1001 format(2F10.3,X,2F10.3)\n RETURN\n END\n\nC----------------------------------------------------------------------C\n\n SUBROUTINE pnt2sdr(line,soln)\n IMPLICIT none\n CHARACTER*180 line,soln\n REAL*8 p(3),n(3),t(3),slip(3),normal(3),s1,d1,r1,s2,d2,r2\n read(line,*) p(1),p(2),p(3),n(1),n(2),n(3),t(1),t(2),t(3)\n call pt2un(p,t,slip,normal)\n call un2sdr(slip,normal,s1,d1,r1)\n write(line,*) s1,d1,r1\n call sdr2sdr(line,soln)\n read(soln,*) s2,d2,r2\n write(soln,1001) s1,d1,r1,s2,d2,r2\n 1001 format(6F6.0)\n RETURN\n END\n\nC----------------------------------------------------------------------C\n\n SUBROUTINE pnt2sv(line,soln)\n IMPLICIT none\n CHARACTER*180 line,soln\n REAL*8 s1,d1,r1,s2,d2,r2,az1,pl1,az2,pl2\n call pnt2sdr(line,soln)\n read(soln,*) s1,d1,r1,s2,d2,r2\n write(line,*) s1,d1,r1\n call sdr2sv(line,soln)\n read(soln,*) az1,pl1\n write(line,*) s2,d2,r2\n call sdr2sv(line,soln)\n read(soln,*) az2,pl2\n write(soln,1001) az1,pl1,az2,pl2\n 1001 format(2F10.3,X,2F10.3)\n RETURN\n END\n\nC----------------------------------------------------------------------C\n\n SUBROUTINE mij2dcp(line,soln)\n IMPLICIT none\n CHARACTER*180 line,soln\n REAL*8 dum,p,n,t,dcp\n call mij2pnt(line,soln)\n read(soln,*) dum,dum,dum,dum,dum,dum,dum,dum,dum,p,n,t\n if (dabs(p).gt.dabs(t)) then\n dcp = 1.0d0 - 2.0d0*dabs(n/p)\n else\n dcp = 1.0d0 - 2.0d0*dabs(n/t)\n endif\n write(soln,1001) dcp\n 1001 format(F5.2)\n RETURN\n END\n\nC----------------------------------------------------------------------C\n\n SUBROUTINE mij2pnt(line,soln)\nC----\nC Compute P, N, and T vectors from a moment tensor input\nC----\n IMPLICIT none\n CHARACTER*180 line,soln\n INTEGER n,lda,lwmax\n PARAMETER (n=3,lda=n,lwmax=250)\n INTEGER info,lwork\n REAL*8 a(lda,n),w(n),work(lwmax),m(6)\n REAL*8 p(3),o(3),t(3)\nC Get input moment tensor (mrr, mtt, mpp, mrt, mrp, mtp; r=z, t=n, p=e)\nC Moment tensor components (r=z, t=e, p=n):\n read(line,*) m(1),m(2),m(3),m(4),m(5),m(6)\n a(3,3) = m(1) ! mrr = mzz\n a(2,2) = m(2) ! mtt = myy\n a(1,1) = m(3) ! mpp = mxx\n a(2,3) = -m(4) ! mrt = -myz\n a(3,2) = -m(4)\n a(1,3) = m(5) ! mrp = mxz\n a(3,1) = m(5)\n a(1,2) = -m(6) ! mtp = -mxy\n a(1,2) = -m(6)\nC Query the optimal workspace\n lwork = -1\n call dsyev('Vectors','Upper',n,a,lda,w,work,lwork,info)\n lwork = min(lwmax,int(work(1)))\nC Solve eigenproblem\n call dsyev('Vectors','Upper',n,a,lda,w,work,lwork,info)\n p(1) = a(1,1)\n p(2) = a(2,1)\n p(3) = a(3,1)\n o(1) = a(1,2)\n o(2) = a(2,2)\n o(3) = a(3,2)\n t(1) = a(1,3)\n t(2) = a(2,3)\n t(3) = a(3,3)\nC Write P, N, and T vectors\n write(soln,1001) p(1),p(2),p(3),o(1),o(2),o(3),t(1),t(2),t(3),\n 1 w(1),w(2),w(3)\n 1001 format(9F7.3,3(1P1E14.6))\n RETURN\n END\n\nC----------------------------------------------------------------------C\n\n SUBROUTINE pt2un(p,t,slip,normal)\nC----\nC Compute unit normal and slip vectors from P and T axes\nC----\n IMPLICIT none\n REAL*8 sqrt2\n PARAMETER (sqrt2=dsqrt(2.0d0))\n REAL*8 p(3),t(3),slip(3),normal(3)\n INTEGER i\n do 101 i = 1,3\n slip(i) = (t(i)+p(i))/sqrt2\n normal(i) = (t(i)-p(i))/sqrt2\n 101 continue\n RETURN\n END\n\nC----------------------------------------------------------------------C\n\n SUBROUTINE un2sdr(slip,normal,s,d,r)\nC----\nC Compute strike, dip, rake from slip and normal to plane\nC----\n IMPLICIT none\n REAL*8 pi,d2r,r2d\n PARAMETER (pi=4.0d0*datan(1.0d0),d2r=pi/1.8d2,r2d=1.8d2/pi)\n REAL*8 slip(3),normal(3),s,d,r\n REAL*8 hor,st(3),dum\n INTEGER i\nC do 101 i = 1,3\nC slip(i) = slip(i)\nC 101 continue\n if (normal(3).lt.0.0d0) then\n do 102 i = 1,3\n slip(i) = -slip(i)\n normal(i) = -normal(i)\n 102 continue\n endif\n s = datan2(normal(1),normal(2))/d2r - 90.0d0 ! strike\n if (s.lt.0.0d0) s = s + 360.0d0\n hor = dsqrt(normal(1)*normal(1)+normal(2)*normal(2))\n d = datan2(hor,normal(3))/d2r ! dip\n st(1) = dsin(s*d2r) ! components of strike\n st(2) = dcos(s*d2r) ! components of strike\n st(3) = 0.0d0 ! components of strike\n r = dacos(st(1)*slip(1)+st(2)*slip(2))*r2d\nC Check rake is pos or neg\n dum = st(1)*slip(2)-st(2)*slip(1)\n if (dum.lt.0.0d0) then\n r = -r\n endif\n RETURN\n END\n\nC----------------------------------------------------------------------C\n\n SUBROUTINE pnt2dcp(line,soln)\n IMPLICIT none\n CHARACTER*180 line,soln\n REAL*8 dum,p,n,t,dcp\n read(line,*) dum,dum,dum,dum,dum,dum,dum,dum,dum,p,n,t\n if (dabs(p).gt.dabs(t)) then\n dcp = 1.0d0 - 2.0d0*dabs(n/p)\n else\n dcp = 1.0d0 - 2.0d0*dabs(n/t)\n endif\n write(soln,1001) dcp\n 1001 format(F5.2)\n RETURN\n END\n", "meta": {"hexsha": "67eb5d367d70c3b0de209e3fbe0fd3bb46644b6d", "size": 16555, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/mtsubs.f", "max_stars_repo_name": "mherman09/src", "max_stars_repo_head_hexsha": "98667f7a2f2e724f2544b6aa1fe7ff278cbf4801", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/mtsubs.f", "max_issues_repo_name": "mherman09/src", "max_issues_repo_head_hexsha": "98667f7a2f2e724f2544b6aa1fe7ff278cbf4801", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2017-06-27T16:35:46.000Z", "max_issues_repo_issues_event_max_datetime": "2017-07-16T14:55:39.000Z", "max_forks_repo_path": "src/mtsubs.f", "max_forks_repo_name": "mherman09/src", "max_forks_repo_head_hexsha": "98667f7a2f2e724f2544b6aa1fe7ff278cbf4801", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.6153846154, "max_line_length": 72, "alphanum_fraction": 0.4993053458, "num_tokens": 6420, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802350995703, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6960191573095311}} {"text": " SUBROUTINE pyrmd4(dvol,x,xcen)\r\n!---------------------------------------------------\r\n!*** calculates volume of a pyramid with a quad base (1GP scheme)\r\n!---------------------------------------------------\r\n\r\n IMPLICIT NONE\r\n\r\n REAL(kind=8):: dvol,x(3,4),xcen(3)\r\n\r\n REAL(kind=8) :: x1(3),x2(3),x3(3),xp(3),xcq(3)\r\n\r\n x1(:) = -x(:,1)+x(:,2)+x(:,3)-x(:,4)\r\n x2(:) = -x(:,1)-x(:,2)+x(:,3)+x(:,4)\r\n xcq(:) = .25d0 * (x(:,1)+x(:,2)+x(:,3)+x(:,4))\r\n x3(:) = xcq(:)-xcen(:)\r\n CALL vecpro(x1,x2,xp)\r\n dvol = DOT_PRODUCT(x3,xp)\r\n dvol = dvol/12.d0\r\n\r\n END SUBROUTINE pyrmd4\r\n", "meta": {"hexsha": "2ea06c3332978c174ce2bd58fa63da194660fb1a", "size": 629, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/loads/pyrmd4.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/loads/pyrmd4.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/loads/pyrmd4.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": 29.9523809524, "max_line_length": 67, "alphanum_fraction": 0.3831478537, "num_tokens": 225, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768525822309, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6960076738460507}} {"text": " subroutine lagrange_intpol(y,dy,dymax,u,uint,t,tint,r,rint,\n & ru,ruint,mmax)\nC...|....1....|....2....|....3....|....4....|....5....|....6....|....7..\nC interpolate between non-aequidistant points through lagrange \nC polynomials \nC.......................................................................\n implicit none\n\n integer dymax,mmax,m_l,j\n integer index\n real y(dymax),u(dymax),t(dymax),ru(dymax),r(dymax)\n real uint(mmax),tint(mmax),rint(mmax),ruint(mmax)\n real y1,y2,y3,y4,y5,hh,dy,fak1,fak2,fak3,fak4,fak5\n\n uint (1)=u (1)\n tint (1)=t (1)\n rint (1)=r (1)\n ruint(1)=ru(1)\n\n hh=0.\n do m_l=2,mmax\n hh=hh+dy\n index=2\n do j=2,dymax\n if (y(j).le.hh) then\n index=j\n endif\n enddo\n\n if (index.eq.dymax) then\n uint(m_l)=u(dymax)\n tint(m_l)=t(dymax)\n rint(m_l)=r(dymax)\n ruint(m_l)=ru(dymax)\n else\nc if (abs(hh-y(index+1)).lt.abs(hh-y(index)))\nc & index=index+1\n if (index.eq.(dymax-1)) index=dymax-2\n if (index.eq.2) index=3\nC print \"(a,f9.5,4es12.5)\",'hh,y(i)',hh,y(index-1),y(index),\nC & y(index+1),y(index+2)\n y1=y(index-1)\n y2=y(index )\n y3=y(index+1)\n y4=y(index+2)\n y5=y(index-2)\n fak1=(hh-y2)*(hh-y3)*(hh-y4)*(hh-y5)/((y1-y2)*(y1-y3)*(y1-y4)\n & *(y1-y5))\n fak2=(hh-y1)*(hh-y3)*(hh-y4)*(hh-y5)/((y2-y1)*(y2-y3)*(y2-y4)\n & *(y2-y5))\n fak3=(hh-y1)*(hh-y2)*(hh-y4)*(hh-y5)/((y3-y1)*(y3-y2)*(y3-y4)\n & *(y3-y5))\n fak4=(hh-y1)*(hh-y2)*(hh-y3)*(hh-y5)/((y4-y1)*(y4-y2)*(y4-y3)\n & *(y4-y5))\n fak5=(hh-y1)*(hh-y2)*(hh-y3)*(hh-y4)/((y5-y1)*(y5-y2)*(y5-y3)\n & *(y5-y4))\n uint(m_l)=u(index-1)*fak1+u(index)*fak2+u(index+1)*fak3+\n & u(index+2)*fak4+u(index-2)*fak5\n tint(m_l)=t(index-1)*fak1+t(index)*fak2+t(index+1)*fak3+\n & t(index+2)*fak4+t(index-2)*fak5\n rint(m_l)=r(index-1)*fak1+r(index)*fak2+r(index+1)*fak3+\n & r(index+2)*fak4+r(index-2)*fak5\n ruint(m_l)=ru(index-1)*fak1+ru(index)*fak2+ru(index+1)*fak3+\n & ru(index+2)*fak4+ru(index-2)*fak5\n endif\n enddo\n\nc stop 'test'\n\n return\n end\n", "meta": {"hexsha": "bf198dc52b816c9c846d2b2300ffa4f121830efd", "size": 2399, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "lagrange_intpol.f", "max_stars_repo_name": "friedirchulrich/solver", "max_stars_repo_head_hexsha": "0519646fba398e1953c809114c61d1758ad6c36c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2018-05-23T12:39:37.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-28T07:43:08.000Z", "max_issues_repo_path": "lagrange_intpol.f", "max_issues_repo_name": "friedirchulrich/solver", "max_issues_repo_head_hexsha": "0519646fba398e1953c809114c61d1758ad6c36c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2016-11-18T10:27:17.000Z", "max_issues_repo_issues_event_max_datetime": "2017-01-11T15:15:41.000Z", "max_forks_repo_path": "lagrange_intpol.f", "max_forks_repo_name": "friedirchulrich/solver", "max_forks_repo_head_hexsha": "0519646fba398e1953c809114c61d1758ad6c36c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-04-26T05:50:58.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-26T05:50:58.000Z", "avg_line_length": 33.3194444444, "max_line_length": 72, "alphanum_fraction": 0.454772822, "num_tokens": 909, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.944176857294597, "lm_q2_score": 0.7371581568543044, "lm_q1q2_score": 0.6960076718677747}} {"text": "ATAN2(y,x) ! Arctangent(y/x), ''-pi < result <= +pi''\nSINH(x) ! Hyperbolic sine\nCOSH(x) ! Hyperbolic cosine\nTANH(x) ! Hyperbolic tangent\n", "meta": {"hexsha": "fbcdf9e10a828af7a21b60d9fd93895bdd048a35", "size": 146, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Trigonometric-functions/Fortran/trigonometric-functions-2.f", "max_stars_repo_name": "djgoku/RosettaCodeData", "max_stars_repo_head_hexsha": "91df62d46142e921b3eacdb52b0316c39ee236bc", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Task/Trigonometric-functions/Fortran/trigonometric-functions-2.f", "max_issues_repo_name": "djgoku/RosettaCodeData", "max_issues_repo_head_hexsha": "91df62d46142e921b3eacdb52b0316c39ee236bc", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Trigonometric-functions/Fortran/trigonometric-functions-2.f", "max_forks_repo_name": "djgoku/RosettaCodeData", "max_forks_repo_head_hexsha": "91df62d46142e921b3eacdb52b0316c39ee236bc", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.2, "max_line_length": 53, "alphanum_fraction": 0.6232876712, "num_tokens": 57, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218348550491, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6959726098525791}} {"text": "!\n! file thwscyl.f90\n!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 2005 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Fishpack *\n! * *\n! * A Package of Fortran *\n! * *\n! * Subroutines and Example Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams, Paul Swarztrauber and Roland Sweet *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\nprogram test_hwscyl\n\n use fishpack\n\n ! Explicit typing only\n implicit none\n\n ! Dictionary\n integer(ip), parameter :: M = 50, N = 100\n integer(ip), parameter :: IDIMF = M + 25\n integer(ip), parameter :: MP1 = M + 1, NP1 = N + 1\n integer(ip) :: mbdcnd, nbdcnd, i, j, ierror\n real(wp) :: f(IDIMF, NP1)\n real(wp), dimension(MP1) :: bdc, bdd, r\n real(wp), dimension(NP1) :: bda, bdb, z\n real(wp) :: a, b, c, d, elmbda, pertrb\n real(wp), parameter :: ZERO = 0.0_wp, ONE = 1.0_wp, FOUR = 4.0_wp\n\n ! Set domain and boundary conditions in r\n a = ZERO\n b = ONE\n mbdcnd = 6\n\n ! Set domain and boundary conditions in z\n c = ZERO\n d = ONE\n nbdcnd = 3\n\n ! Set helmholtz constant\n elmbda = ZERO\n\n ! Generate and store grid points for the purpose of computing\n ! boundary data and the right side of the poisson equation\n do i = 1, MP1\n r(i) = real(i - 1, kind=wp)/M\n end do\n\n do j = 1, NP1\n z(j) = real(j - 1, kind=wp)/N\n end do\n\n ! Generate boundary data in z. bda is a dummy variable\n bdb = FOUR * (z**4)\n\n ! Generate boundary data in r\n bdc = ZERO\n bdd = FOUR * (r**4)\n\n ! Generate right hand side of equation.\n block\n real(wp), parameter :: THREE = 3.0_wp\n\n do i = 1, MP1\n f(i,:NP1) = FOUR * (r(i)**2) * (z(:NP1)**2) &\n * (FOUR * (z(:NP1)**2) + THREE * (r(i)**2))\n end do\n end block\n\n ! Solve 2D Helmholtz in cylindrical coordiantes on centered grid\n call hwscyl(a, b, M, mbdcnd, bda, bdb, c, d, N, nbdcnd, bdc, bdd, &\n elmbda, f, IDIMF, pertrb, ierror)\n\n ! Compute discretization error by minimizing over all a the function\n ! norm(f(i, j) - a*1 - u(r(i), z(j))). The exact solution is\n !\n ! u(r, z) = (r*z)**4 + arbitrary constant.\n !\n block\n real(wp), parameter :: KNOWN_PERTRB = 0.226742668667313e-3_wp\n real(wp), parameter :: KNOWN_ERROR = 0.373672238079603e-3_wp\n real(wp) :: x, discretization_error\n real(wp) :: exact_solution(MP1, NP1)\n\n ! Adjust solution\n x = ZERO\n do i = 1, MP1\n x = x + sum(f(i,:NP1)-(r(i)*z(:NP1))**4)\n end do\n x = x/(NP1*MP1)\n f(:MP1,:NP1) = f(:MP1,:NP1) - x\n\n do j = 1, NP1\n do i = 1, MP1\n exact_solution(i,j) = (r(i)*z(j))**4\n end do\n end do\n\n ! Set discretization error\n discretization_error = maxval(abs(exact_solution - f(:MP1,:NP1)))\n\n call check_output('hwscyl', &\n ierror, KNOWN_ERROR, discretization_error, KNOWN_PERTRB, pertrb)\n end block\n\nend program test_hwscyl\n", "meta": {"hexsha": "12e91f92e2657b3f9d7a021672eaba1f398605e1", "size": 4980, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/thwscyl.f90", "max_stars_repo_name": "jlokimlin/fishpack", "max_stars_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2018-03-12T11:31:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-27T07:58:23.000Z", "max_issues_repo_path": "examples/thwscyl.f90", "max_issues_repo_name": "jlokimlin/fishpack", "max_issues_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2016-05-07T22:42:47.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-15T17:44:58.000Z", "max_forks_repo_path": "examples/thwscyl.f90", "max_forks_repo_name": "jlokimlin/fishpack", "max_forks_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-09-07T15:43:32.000Z", "max_forks_repo_forks_event_max_datetime": "2018-06-16T21:30:13.000Z", "avg_line_length": 38.0152671756, "max_line_length": 76, "alphanum_fraction": 0.3606425703, "num_tokens": 1235, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767778695833, "lm_q2_score": 0.7931059536292271, "lm_q1q2_score": 0.6959320566997573}} {"text": "subroutine init_phi(lo, hi, phi, philo, phihi, dx, prob_lo, prob_hi) bind(C, name=\"init_phi\")\n\n use amrex_fort_module, only : amrex_real\n\n implicit none\n\n integer, intent(in) :: lo(3), hi(3), philo(3), phihi(3)\n real(amrex_real), intent(inout) :: phi(philo(1):phihi(1),philo(2):phihi(2),philo(3):phihi(3))\n real(amrex_real), intent(in ) :: dx(3) \n real(amrex_real), intent(in ) :: prob_lo(3) \n real(amrex_real), intent(in ) :: prob_hi(3) \n\n integer :: i,j,k\n double precision :: x,y,z,r2\n\n double precision :: L(3), shift(3)\n double precision :: x_p, y_p, z_p\n\n L = prob_hi - prob_lo\n shift = L/2.0\n\n do k = lo(3), hi(3)\n z = prob_lo(3) + (dble(k)+0.5d0) * dx(3)\n do j = lo(2), hi(2)\n y = prob_lo(2) + (dble(j)+0.5d0) * dx(2)\n do i = lo(1), hi(1)\n x = prob_lo(1) + (dble(i)+0.5d0) * dx(1)\n\n ! r2 = ((x-0.25d0)**2 + (y-0.25d0)**2 + (z-0.25d0)**2) / 0.01d0\n ! phi(i,j,k) = 1.d0 + exp(-r2)\n\n ! Periodic shift\n z_p = z + shift(3)\n y_p = y + shift(2)\n x_p = x + shift(1)\n if (x_p > prob_hi(1)) then\n x_p = x_p - L(1)\n endif\n if (y_p > prob_hi(2)) then\n y_p = y_p - L(2)\n endif\n if (z_p > prob_hi(3)) then\n z_p = z_p - L(3)\n endif\n r2 = ((x_p-0.0d0)**2 + (y_p-0.0d0)**2 + (z_p-0.0d0)**2) / 0.10d0\n phi(i,j,k) = 1.d0 + exp(-r2)\n \n end do\n end do\n end do\n\nend subroutine init_phi\n", "meta": {"hexsha": "7789d132472bb2374d3d173ffd783d2d10d0a3f1", "size": 1534, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorials/MUI/Source_01/init_phi_3d.f90", "max_stars_repo_name": "ylunalin/amrex", "max_stars_repo_head_hexsha": "5715b2fc8a77e0db17bfe7907982e29ec44811ca", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Tutorials/MUI/Source_01/init_phi_3d.f90", "max_issues_repo_name": "ylunalin/amrex", "max_issues_repo_head_hexsha": "5715b2fc8a77e0db17bfe7907982e29ec44811ca", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Tutorials/MUI/Source_01/init_phi_3d.f90", "max_forks_repo_name": "ylunalin/amrex", "max_forks_repo_head_hexsha": "5715b2fc8a77e0db17bfe7907982e29ec44811ca", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-01-17T05:00:26.000Z", "max_forks_repo_forks_event_max_datetime": "2020-01-17T05:00:26.000Z", "avg_line_length": 28.9433962264, "max_line_length": 95, "alphanum_fraction": 0.4837027379, "num_tokens": 603, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767746654976, "lm_q2_score": 0.7931059487389968, "lm_q1q2_score": 0.6959320498675143}} {"text": "rho1 = 2.3049d-6*1.0/mbh*r**1.5d0/(alpha*cgs_kapes**3*mdot**2*f(r)**2)\nT1 = 4.6189d+7*alpha**(-0.25d0)*cgs_kapes**(-0.25d0)*mbh**(-0.25d0)*r**( &\n -0.375d0)\nH1 = 9.8298d+5*cgs_kapes*mbh**1.0d0*mdot*f(r)\nrho2 = 21.921d0*alpha**(-0.7d0)*cgs_kapes**(-0.3d0)*mbh**(-0.7d0)*mdot** &\n 0.4d0*r**(-1.65d0)*f(r)**0.4d0\nT2 = 6.7232d+8*alpha**(-0.2d0)*cgs_kapes**0.2d0*mbh**(-0.2d0)*mdot** &\n 0.4d0*r**(-0.9d0)*f(r)**0.4d0\nH2 = 4639.5d0*alpha**(-0.1d0)*cgs_kapes**0.1d0*mbh**0.9d0*mdot**0.2d0*r &\n **1.05d0*f(r)**0.2d0\nrho3 = 5.9458d+5*alpha**(-0.7d0)*kappa_abs_0**(-0.15d0)*mbh**(-0.7d0)* &\n mdot**0.55d0*r**(-1.875d0)*f(r)**0.55d0\nT3 = 7.4475d+5*alpha**(-0.2d0)*kappa_abs_0**0.1d0*mbh**(-0.2d0)*mdot** &\n 0.3d0*r**(-0.75d0)*f(r)**0.3d0\nH3 = 154.42d0*alpha**(-0.1d0)*kappa_abs_0**0.05d0*mbh**0.9d0*mdot** &\n 0.15d0*r**1.125d0*f(r)**0.15d0\nr12 = 164.17d0*alpha**0.095238d0*cgs_kapes**0.85714d0*mbh**0.095238d0* &\n mdot**0.7619d0*f(r12)**0.7619d0\nr23 = 5.0556d+19*cgs_kapes**1.3333d0*kappa_abs_0**(-0.66667d0)*mdot** &\n 0.66667d0*f(r23)**0.66667d0\n", "meta": {"hexsha": "c9eed5598b0e1e12f20c02df14c7e128e3b56a6c", "size": 1081, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "sketches/shakura-sunyaev-73/3zones.f90", "max_stars_repo_name": "gronki/pydiskvert", "max_stars_repo_head_hexsha": "da9fc71acbdaf48b67a372c51481b30f30c88d29", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "sketches/shakura-sunyaev-73/3zones.f90", "max_issues_repo_name": "gronki/pydiskvert", "max_issues_repo_head_hexsha": "da9fc71acbdaf48b67a372c51481b30f30c88d29", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sketches/shakura-sunyaev-73/3zones.f90", "max_forks_repo_name": "gronki/pydiskvert", "max_forks_repo_head_hexsha": "da9fc71acbdaf48b67a372c51481b30f30c88d29", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.4761904762, "max_line_length": 74, "alphanum_fraction": 0.5855689177, "num_tokens": 666, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813501370537, "lm_q2_score": 0.727975460709318, "lm_q1q2_score": 0.6959309637955374}} {"text": "MODULE SPECIAL\n\n IMPLICIT NONE\n\n CONTAINS\n\n !> @brief Computes determinant of 3x3 matrix\n SUBROUTINE DETERMINANT3X3(numPoints,bufferSize,bufferInterval,inMatrix,matrixDeterminant)\n \n INTEGER(KIND=8), INTENT(IN) :: numPoints,bufferSize(3)\n INTEGER(KIND=8), INTENT(IN) :: bufferInterval(6)\n REAL(KIND=8), INTENT(IN) :: inMatrix(9*numPoints)\n REAL(KIND=8), INTENT(INOUT) :: matrixDeterminant(numPoints)\n\n INTEGER(KIND=8) :: I, J, K\n INTEGER(KIND=8) :: nPlane, zIndex, yIndex, yzIndex, bufferIndex, xSize\n INTEGER(KIND=8) :: iStart,iEnd,jStart,jEnd,kStart,kEnd\n\n iStart = bufferInterval(1)\n iEnd = bufferInterval(2)\n xSize = bufferSize(1)\n jStart = bufferInterval(3)\n jEnd = bufferInterval(4)\n kStart = bufferInterval(5)\n kEnd = bufferInterval(6)\n nPlane = xSize * bufferSize(2)\n\n DO K = kStart, kEnd\n zIndex = (K-1)*nPlane\n DO J = jStart, jEnd\n yzIndex = zIndex + (J-1)*xSize\n DO I = iStart, iEnd\n bufferIndex = yzIndex + I\n\n matrixDeterminant(bufferIndex) = &\n inMatrix(bufferIndex)* &\n (inMatrix(bufferIndex+8*numPoints) * &\n inMatrix(bufferIndex+4*numPoints)- &\n inMatrix(bufferIndex+7*numPoints)* &\n inMatrix(bufferIndex+5*numPoints))- &\n\n inMatrix(bufferIndex+3*numPoints)* &\n (inMatrix(bufferIndex+8*numPoints)* &\n inMatrix(bufferIndex+numPoints) - &\n inMatrix(bufferIndex+7*numPoints) * &\n inMatrix(bufferIndex+2*numPoints)) + &\n\n inMatrix(bufferIndex+6*numPoints)* &\n (inMatrix(bufferIndex+5*numPoints)* &\n inMatrix(bufferIndex+numPoints)- &\n inMatrix(bufferIndex+4*numPoints)* &\n inMatrix(bufferIndex+2*numPoints))\n\n END DO\n END DO\n END DO\n END SUBROUTINE DETERMINANT3X3\n\n !> @brief Computes determinant of 2x2 matrix\n SUBROUTINE DETERMINANT2X2(numPoints,bufferSize,bufferInterval,inMatrix,matrixDeterminant)\n \n INTEGER(KIND=8), INTENT(IN) :: numPoints,bufferSize(2)\n INTEGER(KIND=8), INTENT(IN) :: bufferInterval(4)\n REAL(KIND=8), INTENT(IN) :: inMatrix(4*numPoints)\n REAL(KIND=8), INTENT(INOUT) :: matrixDeterminant(numPoints)\n\n INTEGER(KIND=8) :: I, J, K\n INTEGER(KIND=8) :: nPlane, zIndex, yIndex, yzIndex, bufferIndex, xSize\n INTEGER(KIND=8) :: iStart,iEnd,jStart,jEnd,kStart,kEnd\n\n iStart = bufferInterval(1)\n iEnd = bufferInterval(2)\n xSize = bufferSize(1)\n jStart = bufferInterval(3)\n jEnd = bufferInterval(4)\n nPlane = xSize * bufferSize(2)\n\n DO J = jStart, jEnd\n yIndex = (J-1)*xSize\n DO I = iStart, iEnd\n bufferIndex = yIndex + I\n \n matrixDeterminant(bufferIndex) = &\n (inMatrix(bufferIndex)* &\n inMatrix(bufferIndex+3*numPoints)) - &\n (inMatrix(bufferIndex+numPoints)* &\n inMatrix(bufferIndex+2*numPoints))\n END DO\n END DO\n\n END SUBROUTINE DETERMINANT2X2\n\n !> @brief Computes buf1*buf4 - buf2*buf3 + buf7*(buf5 - buf6)\n SUBROUTINE METRICSUM4(numDim,numPoints,bufferSize,bufferInterval,&\n buf1,buf2,buf3,buf4,buf5,buf6,buf7,metricSum)\n \n INTEGER(KIND=4), INTENT(IN) :: numDim\n INTEGER(KIND=8), INTENT(IN) :: numPoints,bufferSize(numDim)\n INTEGER(KIND=8), INTENT(IN) :: bufferInterval(2*numDim)\n REAL(KIND=8), INTENT(IN) :: buf1(numPoints)\n REAL(KIND=8), INTENT(IN) :: buf2(numPoints)\n REAL(KIND=8), INTENT(IN) :: buf3(numPoints)\n REAL(KIND=8), INTENT(IN) :: buf4(numPoints)\n REAL(KIND=8), INTENT(IN) :: buf5(numPoints)\n REAL(KIND=8), INTENT(IN) :: buf6(numPoints)\n REAL(KIND=8), INTENT(IN) :: buf7(numPoints)\n REAL(KIND=8), INTENT(INOUT) :: metricSum(numPoints)\n\n INTEGER(KIND=8) :: I, J, K\n INTEGER(KIND=8) :: nPlane, zIndex, yIndex, yzIndex, bufferIndex, xSize\n INTEGER(KIND=8) :: iStart,iEnd,jStart,jEnd,kStart,kEnd\n\n iStart = bufferInterval(1)\n iEnd = bufferInterval(2)\n xSize = bufferSize(1)\n \n IF(numDim == 1) THEN\n DO I = iStart, iEnd\n metricSum(I) = buf1(I)*buf4(I) - buf2(I)*buf3(I) + buf7(I)*(buf5(I)-buf6(I))\n END DO\n ELSE IF(numDim == 2) THEN\n jStart = bufferInterval(3)\n jEnd = bufferInterval(4)\n DO J = jStart, jEnd\n yIndex = (J-1)*xSize\n DO I = iStart, iEnd\n bufferIndex = yIndex + I\n metricSum(bufferIndex) = buf1(bufferIndex)*buf4(bufferIndex) - &\n buf2(bufferIndex)*buf3(bufferIndex) + &\n buf7(bufferIndex)*(buf5(bufferIndex)-buf6(bufferIndex))\n END DO\n END DO\n ELSE IF(numDim == 3) THEN\n jStart = bufferInterval(3)\n jEnd = bufferInterval(4)\n kStart = bufferInterval(5)\n kEnd = bufferInterval(6)\n nPlane = xSize * bufferSize(2)\n DO K = kStart, kEnd\n zIndex = (K-1)*nPlane\n DO J = jStart, jEnd\n yzIndex = zIndex + (J-1)*xSize\n DO I = iStart, iEnd\n bufferIndex = yzIndex + I\n metricSum(bufferIndex) = buf1(bufferIndex)*buf4(bufferIndex) - &\n buf2(bufferIndex)*buf3(bufferIndex) + &\n buf7(bufferIndex)*(buf5(bufferIndex)-buf6(bufferIndex))\n END DO\n END DO\n END DO\n ENDIF\n END SUBROUTINE METRICSUM4\n\n SUBROUTINE VECTORCROSSPRODUCT(v1,v2,y)\n\n IMPLICIT NONE\n\n REAL(KIND=8), INTENT(IN) :: v1(3), v2(3)\n REAL(KIND=8), INTENT(OUT) :: y(3)\n\n y(1) = v1(2)*v2(3) - v1(3)*v2(2)\n y(2) = v1(3)*v2(1) - v1(1)*v2(3)\n y(3) = v1(1)*v2(2) - v1(2)*v2(1)\n \n END SUBROUTINE VECTORCROSSPRODUCT\n\nEND MODULE SPECIAL\n", "meta": {"hexsha": "c1c8ba45bcf5a43f882fb96ad7e6309bd436f957", "size": 6015, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "kernels/Special.f90", "max_stars_repo_name": "MTCam/OKLib", "max_stars_repo_head_hexsha": "cdaacb1a7116d75667c00d849317f16aa67587fd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-08-18T16:31:18.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-18T16:31:18.000Z", "max_issues_repo_path": "kernels/Special.f90", "max_issues_repo_name": "illinois-ceesd/teesd", "max_issues_repo_head_hexsha": "764b27a0ca2f3aba1e00d8cf6bab8869d7ba1a59", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "kernels/Special.f90", "max_forks_repo_name": "illinois-ceesd/teesd", "max_forks_repo_head_hexsha": "764b27a0ca2f3aba1e00d8cf6bab8869d7ba1a59", "max_forks_repo_licenses": ["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.8035714286, "max_line_length": 91, "alphanum_fraction": 0.570407315, "num_tokens": 1819, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009526726545, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.6959200117496407}} {"text": "! filename = sum.f90\n! Purpose: To be used as a shared library \n\n! Function to sum two real valued numbers\nFUNCTION sum(x,y) \n double precision :: sum\n double precision, intent(in) :: x, y\n \n sum = x+y\nEND FUNCTION sum\n\n! Subroutine to add two real valued numbers\nSUBROUTINE sum_sub(x,y,output)\n double precision, intent(in) :: x, y\n double precision, intent(out) :: output\n\n output = x+y\nEND SUBROUTINE sum_sub\n\n! function to calculate average of array of doubles\nFUNCTION average(length, values)\n integer, intent(in) :: length\n double precision, intent(in) :: values(length)\n double precision :: average\n \n average = 0.0\n DO i = 1, length\n average = average + values(i)\n ENDDO\n average = average/length\nEND FUNCTION average\n", "meta": {"hexsha": "22a4eceec7191daee6202044ef76fb1a8ec8a2d6", "size": 782, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ctypes_ex/linux/sum.f90", "max_stars_repo_name": "lcford2/537_guest_lecture", "max_stars_repo_head_hexsha": "b0a744c87473b13ed693518ed0daedcd2bc27f9f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-11-25T14:36:33.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-25T14:36:33.000Z", "max_issues_repo_path": "ctypes_ex/linux/sum.f90", "max_issues_repo_name": "lcford2/537_guest_lecture", "max_issues_repo_head_hexsha": "b0a744c87473b13ed693518ed0daedcd2bc27f9f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ctypes_ex/linux/sum.f90", "max_forks_repo_name": "lcford2/537_guest_lecture", "max_forks_repo_head_hexsha": "b0a744c87473b13ed693518ed0daedcd2bc27f9f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.4375, "max_line_length": 51, "alphanum_fraction": 0.6726342711, "num_tokens": 198, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009642742805, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6959200106461986}} {"text": "c # --------------------------------------------------------------- \n double precision function q0_physical(xp,yp,zp)\n implicit none\n\n double precision xp, yp, zp\n\n double precision pi, pi2\n common /compi/ pi, pi2\n\n integer example\n common /example_comm/ example\n\n integer initchoice\n common /initchoice_comm/ initchoice\n\n double precision xc0, yc0, r0\n common /cylinder_init_comm/ xc0, yc0, r0\n\n double precision xp0, yp0, zp0, r, q0, Hsmooth\n\n integer k\n\n call mapc2m_cylinder(xc0,yc0,xp0,yp0,zp0)\n\nc # Sphere centered at (0.5,0.5,0) on swirl\n if (initchoice .eq. 1) then\n q0 = 1.d0\n elseif (initchoice .eq. 2) then\n r = sqrt((xp - xp0)**2 + (yp-yp0)**2 + (zp-zp0)**2)\n q0 = 1 - Hsmooth(r - r0)\n endif\n q0_physical = q0\n\n end\n\nc # --------------------------------------------------------------- \n double precision function Hsmooth(r)\n implicit none\n\n double precision r\n\n Hsmooth = (tanh(r/0.02d0) + 1)/2.d0\n\n end\n\n double precision function q0_init(xc,yc)\n implicit none \n\n double precision xc,yc\n\n double precision xp, yp, zp\n double precision q0_physical\n\n call mapc2m_cylinder(xc,yc,xp,yp,zp)\n\n \n \n q0_init = q0_physical(xp,yp,zp)\n\n end\n \n\n\n\n\n\n\n\n", "meta": {"hexsha": "dcf15064433bcbccb874d3d1039ecbf6c3872912", "size": 1376, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "applications/paper/cylinder/q0.f", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2017-09-26T13:39:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:56:23.000Z", "max_issues_repo_path": "applications/paper/cylinder/q0.f", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 75, "max_issues_repo_issues_event_min_datetime": "2017-08-02T19:56:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T12:36:32.000Z", "max_forks_repo_path": "applications/paper/cylinder/q0.f", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-02-21T00:10:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T19:08:36.000Z", "avg_line_length": 19.9420289855, "max_line_length": 77, "alphanum_fraction": 0.5181686047, "num_tokens": 398, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009526726544, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6959200018214142}} {"text": "module par\nIMPLICIT NONE\nreal*8 r,z,phi\nreal*8,parameter::pi=dacos(-1.d0)\nendmodule par\n\nprogram twodintx\nuse par\nimplicit none\n\nREAL*8 X(3,2),Y(3,2),DATA(4500),RES,ERR,r1,r2,theta1,theta2\nINTEGER IWORK(1000),NU,ND,NEVALS,IFLAG\nEXTERNAL F\nr=2.82842712474619d0\nz=-2.d0\nphi=-2.35619449019234d0\n\nr1=1.52651490011283d0\nr2=1.95095241255724d0\ntheta1=0.d0\ntheta2=2.d0*pi\nX(1,1)=r1\nY(1,1)=theta1\nX(2,1)=r2\nY(2,1)=theta1\nX(3,1)=r2\nY(3,1)=theta2\nX(1,2)=r1\nY(1,2)=theta1\nX(2,2)=r2\nY(2,2)=theta2\nX(3,2)=r1\nY(3,2)=theta2\nNU=0\nND=0\nIFLAG=1\nCALL TWODQ(F,2,X,Y,1.E-08,1,200,32000,RES,ERR,NU,ND, NEVALS,IFLAG,DATA,IWORK)\nPRINT*,RES,ERR,NEVALS,IFLAG\n\nend program twodintx\n\nreal*8 FUNCTION F(t,theta)\nuse par\nimplicit none\nreal*8 t,theta\nF=t/dsqrt(z**2+t**2+r**2-2.d0*r*t*dcos(phi-theta))\nRETURN\nEND FUNCTION F\n\n", "meta": {"hexsha": "4a1602103c3014f7260ed660de8061d22ded78de", "size": 794, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/quadring.f90", "max_stars_repo_name": "jnnccc/ring-gravity", "max_stars_repo_head_hexsha": "e326c3507a872f507443f1523051e0ebe6f24a5e", "max_stars_repo_licenses": ["MIT"], "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/quadring.f90", "max_issues_repo_name": "jnnccc/ring-gravity", "max_issues_repo_head_hexsha": "e326c3507a872f507443f1523051e0ebe6f24a5e", "max_issues_repo_licenses": ["MIT"], "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/quadring.f90", "max_forks_repo_name": "jnnccc/ring-gravity", "max_forks_repo_head_hexsha": "e326c3507a872f507443f1523051e0ebe6f24a5e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.88, "max_line_length": 77, "alphanum_fraction": 0.717884131, "num_tokens": 408, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850093037731, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6958170658580034}} {"text": "!\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0432\u0435\u0440\u0445\u043d\u043e\u0441\u0442\u0438\nfunction sedlo(a,b) result(c)\n\timplicit none\n\treal,intent(in) :: a,b\n\treal :: c\n\tc = (a*a-b*b)/4\nend function sedlo\n\nprogram main\n! \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443\n\tUSE Plotter\n\timplicit none\n!\t\u0422\u0438\u043f, \u0445\u0440\u0430\u043d\u044f\u0449\u0438\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\n\ttype(functions):: one_surface\n! \u0423\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0447\u0442\u043e \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441 \u0432\u044b\u0432\u043e\u0434\u043e\u043c \u0442\u0438\u043f\u0430 real\n\t\treal, external :: sedlo\n!\t\u041c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u043e\u0432\u0435\u0440\u0445\u043d\u043e\u0441\u0442\u0438\n\tone_surface%function_surface=>sedlo\n! \u0428\u0430\u0433 \u043f\u043e \u043e\u0441\u044f\u043c\n\t\tcall Set_Step_X(1.)\n\t\tcall Set_Step_Y(1.)\n! \u041f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0420\u0430\u0437\u043c\u0435\u0440 \u043e\u043a\u043d\u0430, \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u043e\u0441\u044f\u043c \u0425 \u0438 \u0423 \u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u0441 \u0438\u0445 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c\n\tcall DrawGraph(960,720,-5.,5.,-5.,5.,one_surface)\nend\n", "meta": {"hexsha": "5e525cbe889152a9ad9312c32d7faee397d6cbc2", "size": 665, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Plotter/tst/test_surfaces_one.f90", "max_stars_repo_name": "LibPlotter/Plotter", "max_stars_repo_head_hexsha": "b47ee424af82dacda82456e695b8716f96cd09c3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Plotter/tst/test_surfaces_one.f90", "max_issues_repo_name": "LibPlotter/Plotter", "max_issues_repo_head_hexsha": "b47ee424af82dacda82456e695b8716f96cd09c3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Plotter/tst/test_surfaces_one.f90", "max_forks_repo_name": "LibPlotter/Plotter", "max_forks_repo_head_hexsha": "b47ee424af82dacda82456e695b8716f96cd09c3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.6, "max_line_length": 94, "alphanum_fraction": 0.7248120301, "num_tokens": 252, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.936285002192296, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6958170605729812}} {"text": "\n program locate\n\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\nc\nc LOCATE - This program transforms I,J coordinates of an SSM/I grid cell\nc to latitude and longitude coordinates. This program provides\nc the inverse functions as well. LOCATE interfaces to the revised\nc forms of the subroutines, MAPXY and MAPLL.\nc\nc User-defined Paramters:\nc\nc gtype : Integer supplied by the user to describe one of the three\nc grid cell dimensions (12.5 km, 25.0 km).\nc\nc ihem : Integer supplied by the user to describe one of the two\nc polar regions (1=North , 2=South)\nc\nc itrans : Integer supplied by the user to describe the type of\nc transformation LOCATE will perform (1=I,J-to-Lat,Lon;\nc 2=Lat,Lon-to-I,J)\nc\nc i,j : Integers supplied by the user when itrans = 1. These \nc integers describe the position of a cell in an SSM/I grid.\nc\nc lat,lon : Reals supplied by the user when itrans = 2. These\nc integers describe the latitude and longitude in an SSM/I\nc grid which LOCATE will transform to an I,J grid cell position.\nc Note: All latitudes and longitudes must be entered as \nc positive numbers!\nc\nc Internal:\nc\nc x,y : Distance in kilometers from the origin of the grid \nc (ie., pole).\nc \nc alat,\nc alon : Computed latitude and longitude returned from MAPXY.\nc\nc SGN : Sign of the latitude (positive = north latitude, \nc negative = south latitude)\nc\nc delta : Meridian offset for the SSM/I grids (0 degrees for\nc the South Polar grids; 45 degrees for the North Polar\nc grids. \nc\nc kk : Integer variable used for reorientation of the grid. The\nc grid is 'flipped' in the Y direction for transformations.\nc\nc SLAT : Standard latitude for the SSM/I grids is 70 degrees.\nc\nc numy : Number of lines in an SSM/I grid. This attribute varies\nc for each of the six grids.\nc\nc cell : Size of the SSM/I grid ( 12.5 km, 25.0 km)\nc\nc xydist : Distance from the origin of the grid in the cartesian plane.\nc The x-y coordinates for the edge of the lower left pixel\nc is (3850.0, 5350.0) for the northern grids and \nc (3950.0, 3950.0) for the southern grids.\nc\nc RE : Radius of the earth in kilometers.\nc\nc E : Eccentricity of the Hughes ellipsoid\nc\nc E2 : Eccentricity squared\nc\nc PI : Pi\nc Written by V.J.Troisi - January, 1990\nc Updated by N.A.Sandoval - November, 1995 - Switched i,j in the \nc equation to be consistent i-row, j-column.\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\n\n\n real SLAT,E,RE,PI\n real alat,alon,x,y\n integer ihem \n real lat, lon\n real SGN, delta\n integer numy(2,3)\n real cell(2), xydist(2,2)\n data numy / 896, 664, 448, 332, 224, 166 /\n data cell / 12.5 , 25.0 /\n data xydist / 3850.0 , 5350.0 , 3950.0 , 3950 /\n \n SLAT = 70.\n RE = 6378.273\n E2 = .006693883\n PI = 3.141592654\n E = sqrt(E2)\nc\nc Query for the SSM/I grid cell size.\nc\n print *,'Enter the grid cell dimension:'\n print *,' 1. 12.5 Km'\n print *,' 2. 25.0 Km'\n read *,gtype\nc\nc Query for polar region of interest.\nc\n print *,'Enter the hemisphere of interest:'\n print *,' 1. North'\n print *,' 2. South'\n read *,ihem\nc\nc Define the sign and meridian offset (delta) for the SSM/I grids.\nc\n if (ihem.eq.1) then\n SGN = 1.0\n delta = 45.\n else\n SGN = -1.0\n delta = 0.0\n endif\nc\nc Query for translation type.\nc\n print *,'Enter one of the following transform functions:'\n print *,' 1. Convert I,J to Latitude, Longitude'\n print *,' 2. Convert Latitude, Longitude to I,J'\n read *, itrans\nc\nc Start translation\nc\n if (itrans.eq.1) then\nc\nc Obtain the I,J position of the grid cell to transform to Latitude \nc and Longitude\nc \n print *,'Enter the column number'\n if(ihem.eq.1 .and. gtype.eq.1) \n + print *,'the valid range is (1-608)'\n if(ihem.eq.1 .and. gtype.eq.2)\n + print *,'the valid range is (1-304)'\n if(ihem.eq.2 .and. gtype.eq.1)\n + print *,'the valid range is (1-632)'\n if(ihem.eq.2 .and. gtype.eq.2)\n + print *,'the valid range is (1-316)'\n read *,j\n\n print *,'Enter the row number'\n if(ihem.eq.1 .and. gtype.eq.1) \n + print *,'the valid range is (1-896)'\n if(ihem.eq.1 .and. gtype.eq.2)\n + print *,'the valid range is (1-448)'\n if(ihem.eq.2 .and. gtype.eq.1)\n + print *,'the valid range is (1-664)'\n if(ihem.eq.2 .and. gtype.eq.2)\n + print *,'the valid range is (1-332)'\n read *,i\nc\nc Convert I,J pairs to x and y distances from origin. For some image\nc display programs, the grid will be 'flipped' in the 'Y' direction.\nc+\nc Changed j for i and i for j to be consistant, NAS (11/95).\nc-\n x=((j-1)*cell(gtype))-(xydist(1,ihem)-cell(gtype)/2.)\n kk=numy(ihem,gtype)-(i-1) \n y=((kk-1)*cell(gtype))-(xydist(2,ihem)-cell(gtype)/2.)\nc\nc Transform x and y distances to latitude and longitude\nc\n call mapxy (x,y,alat,alon,SLAT,SGN,E,RE)\nc\nc Transform radians to degrees.\nc\n alon=alon*180./PI\n alat=alat*180./PI\n alon=alon-delta \nc\nc Convert longitude to positive degrees\nc\n if (alon.le.0.0) alon=alon+360.\n if (alon.ge.360.0) alon=alon-360.\nc\nc Print the latitude and longitude for the center of the I,J cell.\nc\n print *,alat,alon\n else\nc\nc Obtain the latitude and longitude pair and transform to cell where\nc that pair is located.\nc\n print *,'Enter latitude and longitude (positive values):'\n read *,lat,lon\nc\nc Transform degrees to radians\nc\n alat=abs(lat)*PI/180.\n alon=(lon+delta)*PI/180.\nc\nc Transform latitude and longitude to x and y distances from origin\nc\n call mapll (x,y,alat,alon,SLAT,SGN,E,RE)\n print *,x,y\nc\nc Convert x and y distances from origin to I,J pair (ii,jj)\nc\n ii=nint((x+xydist(1,ihem)-cell(gtype)/2.)/cell(gtype))+1\n jj=nint((y+xydist(2,ihem)-cell(gtype)/2.)/cell(gtype))+1\nc\nc Flip grid orientation in the 'Y' direction\nc \n kk=numy(ihem,gtype)-(jj-1)\nc\nc Print the I,J location of the cell.\nc\n print *,ii,kk\n\n endif\n end\n\n", "meta": {"hexsha": "6c7ab8d69c4180a8bb679d3ebc0c9e35c9f2d2d2", "size": 6839, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "locate/locate.for", "max_stars_repo_name": "nsidc/polarstereo-latlon-convert-fortran", "max_stars_repo_head_hexsha": "27de036844ab50f4ea5a950e8d1498f79d6783f0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "locate/locate.for", "max_issues_repo_name": "nsidc/polarstereo-latlon-convert-fortran", "max_issues_repo_head_hexsha": "27de036844ab50f4ea5a950e8d1498f79d6783f0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "locate/locate.for", "max_forks_repo_name": "nsidc/polarstereo-latlon-convert-fortran", "max_forks_repo_head_hexsha": "27de036844ab50f4ea5a950e8d1498f79d6783f0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.1079812207, "max_line_length": 78, "alphanum_fraction": 0.5898523176, "num_tokens": 2015, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850004144266, "lm_q2_score": 0.743167997235783, "lm_q1q2_score": 0.6958170485998937}} {"text": "\t subroutine shape\n use fluid_variables\n\t implicit none\n\n\t integer iq\n\n\t if (nen.eq.4) then\n\t\tcall quad3d4n(iquad, nquad, xq, wq, nsdpad, nquadpad)\n\t else if (nen.eq.8) then\n\t\tcall quad3d8n(iquad, nquad, xq, wq, nsdpad, nquadpad)\n\t end if\n do iq=1,nquad\n\t\tif(nen.eq.4) then\n\t\t sq(0,1,iq) = xq(1,iq)\n\t\t sq(0,2,iq) = xq(2,iq)\n\t\t sq(0,3,iq) = xq(3,iq)\n\t\t sq(0,4,iq) = 1 - xq(1,iq) - xq(2,iq) - xq(3,iq)\n else\n\t\t sq(0,1,iq) = (1 - xq(1,iq))\t&\n\t\t\t * (1 - xq(2,iq)) * (1 - xq(3,iq)) / 8\n\t\t sq(0,2,iq) = (1 + xq(1,iq))\t&\n\t\t\t * (1 - xq(2,iq)) * (1 - xq(3,iq)) / 8\n\t\t sq(0,3,iq) = (1 + xq(1,iq))\t&\n\t\t\t * (1 + xq(2,iq)) * (1 - xq(3,iq)) / 8\n\t\t sq(0,4,iq) = (1 - xq(1,iq))\t&\n\t\t\t * (1 + xq(2,iq)) * (1 - xq(3,iq)) / 8\n\t\t sq(0,5,iq) = (1 - xq(1,iq))\t&\n\t\t\t * (1 - xq(2,iq)) * (1 + xq(3,iq)) / 8\n\t\t sq(0,6,iq) = (1 + xq(1,iq))\t&\n\t\t\t * (1 - xq(2,iq)) * (1 + xq(3,iq)) / 8\n\t\t sq(0,7,iq) = (1 + xq(1,iq))\t&\n\t\t\t * (1 + xq(2,iq)) * (1 + xq(3,iq)) / 8\n\t\t sq(0,8,iq) = (1 - xq(1,iq))\t&\n\t\t\t * (1 + xq(2,iq)) * (1 + xq(3,iq)) / 8\n\t\t sq(1,1,iq) = - (1 - xq(2,iq)) * (1 - xq(3,iq)) / 8\n\t\t sq(1,2,iq) = + (1 - xq(2,iq)) * (1 - xq(3,iq)) / 8\n\t\t sq(1,3,iq) = + (1 + xq(2,iq)) * (1 - xq(3,iq)) / 8\n\t\t sq(1,4,iq) = - (1 + xq(2,iq)) * (1 - xq(3,iq)) / 8\n\t\t sq(1,5,iq) = - (1 - xq(2,iq)) * (1 + xq(3,iq)) / 8\n\t\t sq(1,6,iq) = + (1 - xq(2,iq)) * (1 + xq(3,iq)) / 8\n\t\t sq(1,7,iq) = + (1 + xq(2,iq)) * (1 + xq(3,iq)) / 8\n\t\t sq(1,8,iq) = - (1 + xq(2,iq)) * (1 + xq(3,iq)) / 8\n\t\t sq(2,1,iq) = - (1 - xq(1,iq)) * (1 - xq(3,iq)) / 8\n\t\t sq(2,2,iq) = - (1 + xq(1,iq)) * (1 - xq(3,iq)) / 8\n\t\t sq(2,3,iq) = + (1 + xq(1,iq)) * (1 - xq(3,iq)) / 8\n\t\t sq(2,4,iq) = + (1 - xq(1,iq)) * (1 - xq(3,iq)) / 8\n\t\t sq(2,5,iq) = - (1 - xq(1,iq)) * (1 + xq(3,iq)) / 8\n\t\t sq(2,6,iq) = - (1 + xq(1,iq)) * (1 + xq(3,iq)) / 8\n\t\t sq(2,7,iq) = + (1 + xq(1,iq)) * (1 + xq(3,iq)) / 8\n\t\t sq(2,8,iq) = + (1 - xq(1,iq)) * (1 + xq(3,iq)) / 8\n\t\t sq(3,1,iq) = - (1 - xq(1,iq)) * (1 - xq(2,iq)) / 8\n\t\t sq(3,2,iq) = - (1 + xq(1,iq)) * (1 - xq(2,iq)) / 8\n\t\t sq(3,3,iq) = - (1 + xq(1,iq)) * (1 + xq(2,iq)) / 8\n\t\t sq(3,4,iq) = - (1 - xq(1,iq)) * (1 + xq(2,iq)) / 8\n\t\t sq(3,5,iq) = + (1 - xq(1,iq)) * (1 - xq(2,iq)) / 8\n\t\t sq(3,6,iq) = + (1 + xq(1,iq)) * (1 - xq(2,iq)) / 8\n\t\t sq(3,7,iq) = + (1 + xq(1,iq)) * (1 + xq(2,iq)) / 8\n\t\t sq(3,8,iq) = + (1 - xq(1,iq)) * (1 + xq(2,iq)) / 8\n endif\n\t enddo\n\t return\n\t end\n\n\t subroutine shape2d\n\t use fluid_variables\n\n\t implicit none\n\n\t integer iq\n\n\t if (nen==3) then\n\t\tcall quad2d3n(iquad, nquad, xq, wq, nsdpad, nquadpad)\n\t else if (nen==4) then\n\t\tcall quad2d4n(iquad, nquad, xq, wq, nsdpad, nquadpad)\n\t end if\n do iq=1,nquad\n\t\tif(nen==3) then\n\t\t sq(0,1,iq) = xq(1,iq)\n\t\t sq(0,2,iq) = xq(2,iq)\n\t\t sq(0,3,iq) = 1 - xq(1,iq) - xq(2,iq)\n elseif (nen==4) then\n\t\t sq(0,1,iq) = (1 - xq(1,iq)) * (1 - xq(2,iq)) / 4\n\t\t sq(0,2,iq) = (1 + xq(1,iq)) * (1 - xq(2,iq)) / 4\n\t\t sq(0,3,iq) = (1 + xq(1,iq)) * (1 + xq(2,iq)) / 4\n\t\t sq(0,4,iq) = (1 - xq(1,iq)) * (1 + xq(2,iq)) / 4\n\t\t \n\t\t sq(1,1,iq) = - (1 - xq(2,iq)) / 4\n\t\t sq(1,2,iq) = + (1 - xq(2,iq)) / 4\n\t\t sq(1,3,iq) = + (1 + xq(2,iq)) / 4\n\t\t sq(1,4,iq) = - (1 + xq(2,iq)) / 4\n\t\n\t\t sq(2,1,iq) = - (1 - xq(1,iq)) / 4\n\t\t sq(2,2,iq) = - (1 + xq(1,iq)) / 4\n\t\t sq(2,3,iq) = + (1 + xq(1,iq)) / 4\n\t\t sq(2,4,iq) = + (1 - xq(1,iq)) / 4\n\n endif\n\t enddo\n\t return\n\tend subroutine shape2d\n", "meta": {"hexsha": "054ca34ff78d586d40af67316fc2764b77b545c8", "size": 3407, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "shape.f90", "max_stars_repo_name": "biofluids/IFEM-archive", "max_stars_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-15T11:40:16.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-15T11:40:16.000Z", "max_issues_repo_path": "shape.f90", "max_issues_repo_name": "biofluids/IFEM-archive", "max_issues_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "shape.f90", "max_forks_repo_name": "biofluids/IFEM-archive", "max_forks_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-02-11T16:50:21.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-08T07:24:59.000Z", "avg_line_length": 33.7326732673, "max_line_length": 55, "alphanum_fraction": 0.4041678896, "num_tokens": 2014, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299509069106, "lm_q2_score": 0.7520125848754472, "lm_q1q2_score": 0.695784566985689}} {"text": "************************************************************************\n* UPDATE_EST - Updates the estimated yield of magic beans given \n* some additional amount of rainfall\n************************************************************************\n*\n* VARIABLES\n* \n* INPUT RAIN = Additional rainfall\n*\n* INOUT YIELD_EST = Crop yield to update\n*\n************************************************************************\n\n************************************************************************\n* CROP_YIELD - Estimate the yield of magic beans given a simple \n* model for rainfall\n************************************************************************\n*\n* VARIABLES\n* \n* INPUT MAX_RAIN = The maximum rain for the month\n* INPUT CONSITENCY = The consistency of the rainfall \n* (higher = more consistent)\n* INPUT ABSORBTION = Estimates the % of rainfall absorbed into the\n* soil (i.e. % lost due to evaporation, runoff)\n*\n* OUTPUT YIELD_EST = The estimated yield of magic beans\n*\n* DAY = The current day of the month\n* RAIN = The rainfall estimate for the current day\n*\n************************************************************************\n PROGRAM CROP_YIELD\n IMPLICIT NONE\n\n INTEGER DAY\n DOUBLE PRECISION RAIN, YIELD_EST, TOTAL_RAIN, NEWS\n DOUBLE PRECISION MAX_RAIN, CONSISTENCY, ABSORBTION\n\n MAX_RAIN = 4.0\n CONSISTENCY = 64.0\n ABSORBTION = 0.6\n \n YIELD_EST = 0\n TOTAL_RAIN = 0\n \n DO 20 DAY=1,31\n PRINT *, \"(\", DAY, CONSISTENCY, MAX_RAIN, ABSORBTION, \")\"\n* Compute rainfall for the current day\n RAIN = (-(DAY - 16) ** 2 / CONSISTENCY + MAX_RAIN) * ABSORBTION\n PRINT *, RAIN\n\n* Update rainfall estimate\n YIELD_EST = UPDATE_EST(RAIN, TOTAL_RAIN, YIELD_EST)\n NEWS = TEST_FUNC(TOTAL_RAIN, YIELD_EST)\n\n PRINT *, \"Day \", DAY, \" Estimate: \", YIELD_EST\n\n 20 ENDDO\n\n PRINT *, \"Crop Yield(%): \", YIELD_EST\n PRINT *, \"News: \", NEWS\n\n CONTAINS\n DOUBLE PRECISION FUNCTION UPDATE_EST(RAIN, TOTAL_RAIN, YIELD_EST)\n IMPLICIT NONE\n DOUBLE PRECISION RAIN, YIELD_EST, TOTAL_RAIN\n TOTAL_RAIN = TOTAL_RAIN + RAIN\n\n* Yield increases up to a point\n IF(TOTAL_RAIN .le. 40) THEN\n YIELD_EST = -(TOTAL_RAIN - 40) ** 2 / 16 + 100\n\n* Then sharply declines\n ELSE\n YIELD_EST = -TOTAL_RAIN + 140\n ENDIF\n UPDATE_EST = YIELD_EST\n\n END FUNCTION UPDATE_EST\n \n DOUBLE PRECISION FUNCTION TEST_FUNC(TOTAL_RAIN, YIELD_EST)\n IMPLICIT NONE\n DOUBLE PRECISION TOTAL_RAIN, YIELD_EST, NEW_VAR\n NEW_VAR = 5.0\n IF (NEW_VAR .le. 4.0) THEN\n TEST_FUNC = TOTAL_RAIN\n ELSE\n TEST_FUNC = YIELD_EST\n ENDIF\n\n END FUNCTION TEST_FUNC\n\n END PROGRAM CROP_YIELD\n", "meta": {"hexsha": "f7f39f7709da826067a7576fe3a9cdfebbddfad3", "size": 2960, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "delphi/translators/for2py/tests/test_data/legacy_tests/crop_yield_function.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": "delphi/translators/for2py/tests/test_data/legacy_tests/crop_yield_function.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": "delphi/translators/for2py/tests/test_data/legacy_tests/crop_yield_function.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": 31.1578947368, "max_line_length": 72, "alphanum_fraction": 0.5087837838, "num_tokens": 701, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299632771662, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6957845660037445}} {"text": " DOUBLE PRECISION FUNCTION sla_GMST (UT1)\n*+\n* - - - - -\n* G M S T\n* - - - - -\n*\n* Conversion from universal time to sidereal time (double precision)\n*\n* Given:\n* UT1 dp universal time (strictly UT1) expressed as\n* modified Julian Date (JD-2400000.5)\n*\n* The result is the Greenwich mean sidereal time (double\n* precision, radians).\n*\n* The IAU 1982 expression (see page S15 of 1984 Astronomical Almanac)\n* is used, but rearranged to reduce rounding errors. This expression\n* is always described as giving the GMST at 0 hours UT. In fact, it\n* gives the difference between the GMST and the UT, which happens to\n* equal the GMST (modulo 24 hours) at 0 hours UT each day. In this\n* routine, the entire UT is used directly as the argument for the\n* standard formula, and the fractional part of the UT is added\n* separately. Note that the factor 1.0027379... does not appear in the\n* IAU 1982 expression explicitly but in the form of the coefficient\n* 8640184.812866, which is 86400x36525x0.0027379...\n*\n* See also the routine sla_GMSTA, which delivers better numerical\n* precision by accepting the UT date and time as separate arguments.\n*\n* Called: sla_DRANRM\n*\n* P.T.Wallace Starlink 14 October 2001\n*\n* Copyright (C) 2001 Rutherford Appleton Laboratory\n*\n* License:\n* This program is free software; you can redistribute it and/or modify\n* it under the terms of the GNU General Public License as published by\n* the Free Software Foundation; either version 2 of the License, or\n* (at your option) any later version.\n*\n* This program is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU General Public License for more details.\n*\n* You should have received a copy of the GNU General Public License\n* along with this program (see SLA_CONDITIONS); if not, write to the \n* Free Software Foundation, Inc., 59 Temple Place, Suite 330, \n* Boston, MA 02111-1307 USA\n*\n*-\n\n IMPLICIT NONE\n\n DOUBLE PRECISION UT1\n\n DOUBLE PRECISION sla_DRANRM\n\n DOUBLE PRECISION D2PI,S2R\n PARAMETER (D2PI=6.283185307179586476925286766559D0,\n : S2R=7.272205216643039903848711535369D-5)\n\n DOUBLE PRECISION TU\n\n\n\n* Julian centuries from fundamental epoch J2000 to this UT\n TU=(UT1-51544.5D0)/36525D0\n\n* GMST at this UT\n sla_GMST=sla_DRANRM(MOD(UT1,1D0)*D2PI+\n : (24110.54841D0+\n : (8640184.812866D0+\n : (0.093104D0-6.2D-6*TU)*TU)*TU)*S2R)\n\n END\n", "meta": {"hexsha": "343a7132e9fb2466721de280b2ce1fbfcfdc50c6", "size": 2687, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Util/third/star/gmst.f", "max_stars_repo_name": "xuanyuanstar/psrchive_CDFT", "max_stars_repo_head_hexsha": "453c4dc05b8e901ea661cd02d4f0a30665dcaf35", "max_stars_repo_licenses": ["AFL-2.1"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Util/third/star/gmst.f", "max_issues_repo_name": "xuanyuanstar/psrchive_CDFT", "max_issues_repo_head_hexsha": "453c4dc05b8e901ea661cd02d4f0a30665dcaf35", "max_issues_repo_licenses": ["AFL-2.1"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Util/third/star/gmst.f", "max_forks_repo_name": "xuanyuanstar/psrchive_CDFT", "max_forks_repo_head_hexsha": "453c4dc05b8e901ea661cd02d4f0a30665dcaf35", "max_forks_repo_licenses": ["AFL-2.1"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-02-13T20:08:14.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-13T20:08:14.000Z", "avg_line_length": 34.4487179487, "max_line_length": 73, "alphanum_fraction": 0.6832899144, "num_tokens": 782, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.925229961215457, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6957845593110469}} {"text": " SUBROUTINE SBLLGD (FLON,FLAT,NPAIR,X,Y,ILLGD,ISTAT)\nC\nC THIS SUBROUTINE CONVERTS THE LONGITUDE AND LATITUDE COORDINATE\nC LOCATION ON EARTH TO THE HRAP GRID SYSTEM LOCATION (AND VICE-\nC VERSA). IF ILLGD=1, GRID POINTS ARE DETERMINED FROM LONGITUDE\nC AND LATITUDE. IF ILLGD=0, LONGITUDE AND LATITUDE ARE COMPUTED\nC FROM THE GRID POINTS. (ASSUMES NORTH POLE = 401,1601)\nC LONGITUDE IS ASSUMED TO BE GREATER THAN 0\nC COPIED FROM CALB>MAP>SFGRID.F77 ON 10/24/88\nC\n IMPLICIT REAL*8 (A-H,O-Z)\n REAL*4 FLAT,FLON,X,Y,YFLAT,XFLON,XX,YY\nC\n DIMENSION X(1),Y(1),FLON(1),FLAT(1)\nC\n DATA DEGRAD/.01745329/\n DATA EARTHR/6371.2/\n DATA STLAT/60./\n DATA STLON/105./\n DATA RADDEG/57.2957795/\nC\n ISTAT=0\n XMESH=4.7625\n TLAT=STLAT*DEGRAD\n RE=(EARTHR*(1.0+DSIN(TLAT)))/XMESH\nC\n IF (ILLGD.EQ.1) THEN\nC\nC COMPUTE GRID POINTS FROM LONGITUDE AND LATITUDE.\nC\n DO I=1,NPAIR\n XFLON = FLON(I)\n YFLAT = FLAT(I)\n X(I) = 0.\n Y(I) = 0.\n IF (YFLAT.GE.10..AND.YFLAT.LE.80.AND.\n X XFLON.GE.40.AND.XFLON.LE.180.) THEN\n XLAT=DBLE(YFLAT)*DEGRAD\n WLONG=(DBLE(XFLON)+180.0-STLON)*DEGRAD\n R=(RE*DCOS(XLAT))/(1.0+DSIN(XLAT))\n X(I)=R*DSIN(WLONG)\n Y(I)=R*DCOS(WLONG)\n ELSE\n ISTAT = -1\n ENDIF\n ENDDO\n DO I=1,NPAIR\n X(I)=X(I)+401\n Y(I)=Y(I)+1601\n ENDDO\n ELSE\nC\nC COMPUTE LONG/LAT FROM THE GRID POINTS.\nC\n GI2 = RE**2\n DO I=1,NPAIR\n XX = X(I)\n YY = Y(I)\n IF (XX.GE.1..AND.XX.LE.1161.AND.\n X YY.GE.1..AND.YY.LE.1601.) THEN\n XX=XX-401\n YY=YY-1601\n RR=XX*XX+YY*YY\n IF (RR.NE.0.0) THEN\n FLAT(I)=DASIN((GI2-RR)/(GI2+RR))*RADDEG\n ANG=ATAN2(YY,XX)*RADDEG\n IF(ANG.LT.0.0) ANG=ANG+360.\n FLON(I)=270.+STLON-ANG\n IF (FLON(I).LT.0.0) FLON(I)=FLON(I)+360.\n IF (FLON(I).GE.360.) FLON(I)=FLON(I)-360.\n ELSE\n FLON(I)=0.0\n FLAT(I)=90.0\n ENDIF\n ELSE\n ISTAT = -1\n FLON(I) = 0.\n FLAT(I) = 0.\n ENDIF\n ENDDO\n ENDIF\n RETURN\n END\n", "meta": {"hexsha": "7c27f8bf6c621ac4439be153d3f251882a99da16", "size": 2354, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "lis/surfacemodels/land/rdhm.3.5.6/sachtet/sbllgd.f", "max_stars_repo_name": "KathyNie/LISF", "max_stars_repo_head_hexsha": "5c3e8b94494fac5ff76a1a441a237e32af420d06", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 67, "max_stars_repo_stars_event_min_datetime": "2018-11-13T21:40:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-23T08:11:56.000Z", "max_issues_repo_path": "lis/surfacemodels/land/rdhm.3.5.6/sachtet/sbllgd.f", "max_issues_repo_name": "dmocko/LISF", "max_issues_repo_head_hexsha": "08d024d6d5fe66db311e43e78740842d653749f4", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 679, "max_issues_repo_issues_event_min_datetime": "2018-11-13T20:10:29.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T19:55:25.000Z", "max_forks_repo_path": "lis/surfacemodels/land/rdhm.3.5.6/sachtet/sbllgd.f", "max_forks_repo_name": "dmocko/LISF", "max_forks_repo_head_hexsha": "08d024d6d5fe66db311e43e78740842d653749f4", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 119, "max_forks_repo_forks_event_min_datetime": "2018-11-08T15:53:35.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-28T10:16:01.000Z", "avg_line_length": 28.0238095238, "max_line_length": 68, "alphanum_fraction": 0.5046728972, "num_tokens": 884, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299632771662, "lm_q2_score": 0.752012562644147, "lm_q1q2_score": 0.6957845557192117}} {"text": "! { dg-do compile }\n! { dg-options \"-fdump-tree-original\" }\n!\n! PR fortran/33197\n!\n! Fortran 2008 complex trigonometric functions: tan, cosh, sinh, tanh\n!\n! Compile-time simplificiations\n!\nimplicit none\nreal(4), parameter :: pi = 2*acos(0.0_4)\nreal(8), parameter :: pi8 = 2*acos(0.0_8)\nreal(4), parameter :: eps = 10*epsilon(0.0_4)\nreal(8), parameter :: eps8 = 10*epsilon(0.0_8)\ncomplex(4), parameter :: z0_0 = cmplx(0.0_4, 0.0_4, kind=4)\ncomplex(4), parameter :: z1_1 = cmplx(1.0_4, 1.0_4, kind=4)\ncomplex(4), parameter :: zp_p = cmplx(pi, pi, kind=4)\ncomplex(8), parameter :: z80_0 = cmplx(0.0_8, 0.0_8, kind=8)\ncomplex(8), parameter :: z81_1 = cmplx(1.0_8, 1.0_8, kind=8)\ncomplex(8), parameter :: z8p_p = cmplx(pi8, pi8, kind=8)\n\nif (abs(tan(z0_0) - cmplx(0.0,0.0,4)) > eps) call abort()\nif (abs(tan(z1_1) - cmplx(0.27175257,1.0839232,4)) > eps) call abort()\nif (abs(tan(z80_0) - cmplx(0.0_8,0.0_8,8)) > eps8) call abort()\nif (abs(tan(z81_1) - cmplx(0.27175258531951174_8,1.0839233273386946_8,8)) > eps8) call abort()\n\nif (abs(cosh(z0_0) - cmplx(1.0,0.0,4)) > eps) call abort()\nif (abs(cosh(z1_1) - cmplx(0.83372992,0.98889768,4)) > eps) call abort()\nif (abs(cosh(z80_0) - cmplx(1.0_8,0.0_8,8)) > eps8) call abort()\nif (abs(cosh(z81_1) - cmplx(0.83373002513114913_8,0.98889770576286506_8,8)) > eps8) call abort()\n\nif (abs(sinh(z0_0) - cmplx(0.0,0.0,4)) > eps) call abort()\nif (abs(sinh(z1_1) - cmplx(0.63496387,1.2984575,4)) > eps) call abort()\nif (abs(sinh(z80_0) - cmplx(0.0_8,0.0_8,8)) > eps8) call abort()\nif (abs(sinh(z81_1) - cmplx(0.63496391478473613_8,1.2984575814159773_8,8)) > eps8) call abort()\n\nif (abs(tanh(z0_0) - cmplx(0.0,0.0,4)) > eps) call abort()\nif (abs(tanh(z1_1) - cmplx(1.0839232,0.27175257,4)) > eps) call abort()\nif (abs(tanh(z80_0) - cmplx(0.0_8,0.0_8,8)) > eps8) call abort()\nif (abs(tanh(z81_1) - cmplx(1.0839233273386946_8,0.27175258531951174_8,8)) > eps8) call abort()\n\nend\n! { dg-final { scan-tree-dump-times \"abort\" 0 \"original\" } }\n", "meta": {"hexsha": "88e2db80551be8983ead33dbbc9da6b90fd17f28", "size": 1991, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.dg/complex_intrinsic_7.f90", "max_stars_repo_name": "best08618/asylo", "max_stars_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-05-02T17:34:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-17T10:15:18.000Z", "max_issues_repo_path": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.dg/complex_intrinsic_7.f90", "max_issues_repo_name": "best08618/asylo", "max_issues_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "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": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.dg/complex_intrinsic_7.f90", "max_forks_repo_name": "best08618/asylo", "max_forks_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-27T00:22:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-01T09:41:02.000Z", "avg_line_length": 45.25, "max_line_length": 96, "alphanum_fraction": 0.6584630839, "num_tokens": 921, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951064805861, "lm_q2_score": 0.8244619328462579, "lm_q1q2_score": 0.6957593906084826}} {"text": "! advect_1d_FV.f90\n!\n! solve the linear advection equation, in conservative form:\n! a_t + [f(a)]_x=0 \n! f(a) = u*a \n! a=a(x,t) (user defined) \n! u=constant (user defined)\n! using a second order finite volume predictor-corrector scheme and optional \n! gradient limiters. Boundaries are periodic.\n!\n! https://github.com/JOThurgood/SimpleCFD/wiki\n!\n! Update - added a option to set t_end as negative.\n! This enables a logical that changes the sign of dt and\n! the directionality of the Riemann problem.\n\nmodule shared_data\n implicit none\n integer, parameter :: num=selected_real_kind(p=15)\n integer :: nx !number of cells\n integer :: ix\n integer(num) :: step, nsteps\n real(num) :: u\n real(num) :: time=0.0_num, t_end, dt\n real(num) :: x_min, x_max \n real(num) :: dxb, dxc !redundant, dx=dxb=dxc=constant here\n real(num), dimension(:), allocatable :: xb, xc\n real(num), dimension(:), allocatable :: a,a1, a1L, a1R\n !solution and states at half time step indicated by 1\n real(num) :: CFL !cfl modifier\n !keyword codes\n integer :: limiter\n integer, parameter :: lim_unlimited = 1, lim_minmod = 2\n logical :: reverse_time = .false.\n contains\nend module shared_data\n\nmodule setup\n\n use shared_data\n\n implicit none\n\n contains\n\n subroutine initial_setup\n call control\n if (t_end < 0.0_num) reverse_time = .true.\n call setup_1dfvgrid\n call initial_conditions\n end subroutine initial_setup\n\n subroutine control !user control variables\n u = 1.0_num\n nx = 64 \n x_min = 0.0_num\n x_max = 1.0_num\n t_end = 0.25_num\n CFL = 0.7_num\n nsteps = -1 !set to -1 to run till t_end\n limiter = lim_unlimited !lim_unlimited, lim_minmod\n end subroutine control\n\n subroutine initial_conditions !choose by commenting or add your own\n call top_hat\n !call gaussian\n end subroutine initial_conditions\n\n subroutine top_hat\n a = 0.0_num\n do ix = 0,nx+1 \n if ((xc(ix) .ge. 1.0_num/3.0_num) .and. (xc(ix) .le. 2.0_num/3.0_num)) &\n & a(ix) = 1.0_num\n enddo\n end subroutine top_hat\n\n subroutine gaussian\n real(num) :: fwhm, sigma,x0,xx\n a = 0.0_num\n fwhm = 0.2_num\n x0 = 0.5_num \n sigma = fwhm / 2.35482_num \n do ix = 0,nx+1 \n xx = xc(ix) - x0\n a(ix) = 1.0_num * exp(-xx**2 / 2.0_num / sigma**2 ) \n enddo\n end subroutine gaussian\n\n subroutine setup_1dfvgrid !setup grid + allocate other vars\n allocate(xc(-1:nx+2)) !cell center (cc) - counts from 1 to nx, with 2 guard\n allocate(xb(-2:nx+2)) !cell boundary (cb) - counts from 0 to nx, with 2 gds\n allocate(a(-1:nx+2)) !cc + 2 guards\n allocate(a1(0:nx)) !cb - then used to calc a cc var in corrector step \n allocate(a1L(0:nx)) !cb (no guards needed)\n allocate(a1R(0:nx)) !cb\n dxb = (x_max - x_min) / REAL(nx,num)\n dxc = dxb !redundant for uniform grids dxb=dxc=dx=constant\n do ix = -2, nx+2\n xb(ix) = x_min + REAL(ix,num) * dxb\n if (ix /= -2) xc(ix) = xb(ix) - dxc/2.0_num\n enddo\n end subroutine setup_1dfvgrid \n\nend module setup\n\nmodule solver \n\n use shared_data\n\n implicit none\n\n contains\n\n subroutine update\n call boundary\n call set_dt \n call predictor\n call corrector\n time = time + dt\n end subroutine update\n\n subroutine boundary !periodic\n a(-1) = a(nx-1)\n a(0) = a(nx)\n a(nx+1) = a(1)\n a(nx+2) = a(2) \n end subroutine boundary\n\n subroutine set_dt \n dt = CFL * dxc / abs(u) \n if (reverse_time) dt = -dt\n end subroutine set_dt\n\n subroutine predictor\n call interface_states \n call reimann\n end subroutine predictor\n\n subroutine corrector\n do ix = 1,nx \n a(ix) = a(ix) - dt / dxb * (u*a1(ix)-u*a1(ix-1))\n enddo\n endsubroutine corrector\n\n subroutine interface_states\n !be careful with cc vs cb here\n real(num) dadx\n do ix = 0, nx ! states on boundary defined at xb \n\n !left state\n if (limiter == lim_minmod) then\n dadx = minmod( ( a(ix)-a(ix-1) )/dxb, ( a(ix+1)-a(ix) )/dxb )\n else \n dadx = ( a(ix+1) - a(ix-1) ) / 2.0_num / dxb\n endif\n a1L(ix) = a(ix) + 0.5_num * dxb * (1.0_num - dt * u / dxb) * dadx\n\n !right state\n if (limiter == lim_minmod) then\n dadx = minmod( ( a(ix+1)-a(ix) )/dxb, ( a(ix+2)-a(ix+1) )/dxb )\n else \n dadx = ( a(ix+2) - a(ix) ) / 2.0_num / dxb\n endif\n\n a1R(ix) = a(ix+1) - 0.5_num * dxb * (1.0_num + dt * u / dxb) * dadx\n enddo\n end subroutine interface_states\n\n subroutine reimann \n\n if (.not. reverse_time) then !forward time\n if (u < 0.0_num) then \n a1 = a1R\n else if (u > 0.0_num) then\n a1 = a1L\n endif \n else ! reverse time\n if (u > 0.0_num) then \n a1 = a1R\n else if (u < 0.0_num) then\n a1 = a1L\n endif \n endif\n\n end subroutine reimann \n\n real(num) function minmod(a,b) ! \"a\" is an unforunate choice of var name!\n real(num), intent(in) :: a, b !left and right difference so change to l+r?\n if ( (abs(a) < abs(b)) .and. (a*b > 0) )then\n minmod = a\n else if ( (abs(a) > abs(b)) .and. (a*b > 0) ) then\n minmod = b\n else \n minmod = 0.0_num\n endif\n end function minmod\n\nend module solver\n\nmodule diagnostics\n\n use shared_data\n\n implicit none \n\n contains\n\n subroutine do_io\n integer :: out_unit =10\n open(out_unit, file=\"xc.dat\", access=\"stream\")\n write(out_unit) xc\n close(out_unit)\n open(out_unit, file=\"a.dat\", access=\"stream\")\n write(out_unit) a\n close(out_unit)\n call execute_command_line(\"python plot_advect_1d_FV.py\")\n end subroutine do_io\n\nend module diagnostics\n\nprogram advect_1d_FV !main driver\n\n use shared_data\n use setup\n use solver\n use diagnostics\n\n implicit none\n\n call initial_setup\n\n do \n if ((step >= nsteps .and. nsteps >= 0) .or. (abs(time) >= abs(t_end))) exit !*\n step = step + 1\n call update \n enddo\n\n call do_io\n\n print *, 'Done in',step,'steps', 'with CFL',CFL\n\nend program advect_1d_FV\n\n!* uses abs(time) for purposes of testing negative t_end\n", "meta": {"hexsha": "b9023b4a1be2966b4ced8fd8c920999c25f8aa95", "size": 6004, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "linear_advection/1D/FV/advect_1d_FV.f90", "max_stars_repo_name": "JOThurgood/SimpleCFD", "max_stars_repo_head_hexsha": "d0dc2fae9dab21c33d50b443caa727fa763c95d9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-04-23T05:31:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-04T23:21:11.000Z", "max_issues_repo_path": "linear_advection/1D/FV/advect_1d_FV.f90", "max_issues_repo_name": "JOThurgood/SimpleCFD", "max_issues_repo_head_hexsha": "d0dc2fae9dab21c33d50b443caa727fa763c95d9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 39, "max_issues_repo_issues_event_min_datetime": "2018-08-31T23:48:02.000Z", "max_issues_repo_issues_event_max_datetime": "2019-08-07T10:03:11.000Z", "max_forks_repo_path": "linear_advection/1D/FV/advect_1d_FV.f90", "max_forks_repo_name": "JOThurgood/SimpleCFD", "max_forks_repo_head_hexsha": "d0dc2fae9dab21c33d50b443caa727fa763c95d9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-11-14T20:42:54.000Z", "max_forks_repo_forks_event_max_datetime": "2019-05-18T09:16:27.000Z", "avg_line_length": 24.506122449, "max_line_length": 81, "alphanum_fraction": 0.6245836109, "num_tokens": 2034, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950947024555, "lm_q2_score": 0.8244619177503205, "lm_q1q2_score": 0.6957593681584748}} {"text": "***********************************************************************\nc ORBEL_FGET.F\n***********************************************************************\n* PURPOSE: Solves Kepler's eqn. for hyperbola using hybrid approach. \n*\n* Input:\n* e ==> eccentricity anomaly. (real scalar)\n* capn ==> hyperbola mean anomaly. (real scalar)\n* Returns:\n* orbel_fget ==> eccentric anomaly. (real scalar)\n*\n* ALGORITHM: Based on pp. 70-72 of Fitzpatrick's book \"Principles of\n* Cel. Mech. \". Quartic convergence from Danby's book.\n* REMARKS: \n* AUTHOR: M. Duncan \n* DATE WRITTEN: May 11, 1992.\n* REVISIONS: 2/26/93 hfl\n***********************************************************************\n\n\treal*8 function orbel_fget(e,capn)\n\n include '../swift.inc'\n\nc... Inputs Only: \n\treal*8 e,capn\n\nc... Internals:\n\tinteger i,IMAX\n\treal*8 tmp,x,shx,chx\n\treal*8 esh,ech,f,fp,fpp,fppp,dx\n\tPARAMETER (IMAX = 10)\n\nc----\nc... Executable code \n\nc Function to solve \"Kepler's eqn\" for F (here called\nc x) for given e and CAPN. \n\nc begin with a guess proposed by Danby\t\n\tif( capn .lt. 0.d0) then\n\t tmp = -2.d0*capn/e + 1.8d0\n\t x = -log(tmp)\n\telse\n\t tmp = +2.d0*capn/e + 1.8d0\n\t x = log( tmp)\n\tendif\n\n\torbel_fget = x\n\n\tdo i = 1,IMAX\n\t call orbel_schget(x,shx,chx)\n\t esh = e*shx\n\t ech = e*chx\n\t f = esh - x - capn\nc\t write(6,*) 'i,x,f : ',i,x,f\n\t fp = ech - 1.d0 \n\t fpp = esh \n\t fppp = ech \n\t dx = -f/fp\n\t dx = -f/(fp + dx*fpp/2.d0)\n\t dx = -f/(fp + dx*fpp/2.d0 + dx*dx*fppp/6.d0)\n\t orbel_fget = x + dx\nc If we have converged here there's no point in going on\n\t if(abs(dx) .le. TINY) RETURN\n\t x = orbel_fget\n\tenddo\t\n\n\twrite(6,*) 'FGET : RETURNING WITHOUT COMPLETE CONVERGENCE' \n\treturn\n\tend ! orbel_fget\nc------------------------------------------------------------------\n", "meta": {"hexsha": "33714ba95e2e9de7afae72803a15826ea59ce80c", "size": 1923, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/swift_j/orbel/orbel_fget.f", "max_stars_repo_name": "Simske/exostriker", "max_stars_repo_head_hexsha": "587b0af4c9cadb46637a4ac61a5392a596e966b1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 69, "max_stars_repo_stars_event_min_datetime": "2020-01-06T13:31:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T11:23:14.000Z", "max_issues_repo_path": "exostriker/source/swift_j/orbel/orbel_fget.f", "max_issues_repo_name": "sai-33/Exostriker", "max_issues_repo_head_hexsha": "f59fa51c6bdce3a2ed51d6621fe42bfcd8c2846f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 67, "max_issues_repo_issues_event_min_datetime": "2019-11-30T14:45:05.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-14T20:26:06.000Z", "max_forks_repo_path": "exostriker/source/swift_j/orbel/orbel_fget.f", "max_forks_repo_name": "sai-33/Exostriker", "max_forks_repo_head_hexsha": "f59fa51c6bdce3a2ed51d6621fe42bfcd8c2846f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2020-01-06T13:44:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T11:23:17.000Z", "avg_line_length": 26.7083333333, "max_line_length": 75, "alphanum_fraction": 0.4867394696, "num_tokens": 608, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.904650527388829, "lm_q2_score": 0.7690802476562641, "lm_q1q2_score": 0.6957488516465706}} {"text": "!!This module finds the srHNFs for a target volume.\n!!Wiley Morgan Started 3/17\n!!\nModule srHNF_brute\n use num_types\n use combinatorics, only: binomial\n use numerical_utilities\n use vector_matrix_utilities, only: matrix_inverse\n \n implicit none\n private\n public get_srHNFs,find_pg_gens\n\nCONTAINS\n\n !!Finds all the possible diagonals of the HNF matrices of a\n !!given size\n !!Cell size, i.e., determinant\n !!of S matrix.\n !!All possible diagonals.\n SUBROUTINE get_HNF_diagonals(detS, diagonals)\n integer, intent(in) :: detS \n integer, pointer :: diagonals(:,:) \n\n integer i, j, id, quotient, status\n integer :: tempDiag(3,detS*3)\n \n id = 0 ! Number of diagonals found\n do i = 1,detS ! Loop over possible first factors\n if (.not. mod(detS,i)==0) cycle\n quotient = detS/i\n do j = 1,quotient ! Loop over possible second/third factors\n if (.not. mod(quotient,j)==0) cycle\n id = id + 1\n tempDiag(:,id) = (/i, j, quotient/j /) ! Construct the factor triplet\n enddo\n enddo\n allocate(diagonals(3,id),STAT=status)\n if(status/=0) stop \"Allocation failed in get_HNF_diagonals, module deriv...\"\n diagonals = tempDiag(:,1:id)\n END SUBROUTINE get_HNF_diagonals\n \n !!This subroutine does a brute force search to find and return the\n !!HNFs preserve the symmetry of the parent lattice.\n !!The parent lattice.\n !!The generators of the point group.\n !!Volume factor for the HNF.\n !!Returned list of symmetry preserving HNFs.\n !!epsilon for checking equivalence in floating\n !!point arithmetic.\n SUBROUTINE get_srHNFs(parent,gens,volume,srHNFs,eps_)\n real(dp), intent(in) :: gens(:,:,:), parent(3,3)\n integer, intent(in) :: volume\n real(dp), intent(in), optional :: eps_\n integer, allocatable, dimension(:,:,:) :: srHNFs\n\n integer :: nfound, N, HNF(3,3), current_max\n real(dp) :: eps, B(3,3)\n integer, pointer :: d(:,:) => null()\n integer :: i, j, k, l ! Loop counters\n integer :: status\n integer, allocatable :: temp_srHNFs(:,:,:)\n integer, allocatable :: temp_storage(:,:,:)\n\n if(.not. present(eps_)) then\n eps = 1e-10_dp\n else\n eps = eps_\n end if\n\n call get_HNF_diagonals(volume,d)\n N = size(d,2)\n \n current_max = 10\n allocate(temp_srHNFs(3,3,current_max),STAT=status)\n if(status/=0) stop \"Failed to allocate memory in get_srHNFs\"\n nfound = 0\n do i = 1,N ! Loop over the permutations of the diagonal elements of the HFNs\n do j = 0,d(2,i)-1 ! Look over possible values of row 2, element 1\n do k = 0,d(3,i)-1 ! Ditto for row 3, element 1\n do l = 0,d(3,i)-1 ! Ditto for row 3, element 2\n HNF(:,:) = reshape((/ d(1,i), j, k, & \n 0, d(2,i), l, & \n 0, 0, d(3,i) /), (/3,3/))\n B = matmul(parent,HNF)\n if (symm_pres(B,gens,eps_=eps)) then\n if (nfound == current_max) then\n current_max = current_max*2\n allocate(temp_storage(3,3,size(temp_srHNFs,3)),STAT=status)\n if(status/=0) stop \"Failed to allocate memory in get_srHNFs\"\n temp_storage = temp_srHNFs\n deallocate(temp_srHNFs)\n allocate(temp_srHNFs(3,3,current_max),STAT=status)\n if(status/=0) stop \"Failed to allocate memory in get_srHNFs\"\n temp_srHNFs = 0\n temp_srHNFs(:,:,1:nfound) = temp_storage(:,:,1:nfound)\n deallocate(temp_storage)\n end if\n nfound = nfound+1 ! Count the srHNFs\n temp_srHNFs(:,:,nfound) = HNF\n end if\n enddo;enddo;enddo ! End loops over values for off-diagonal elements\n enddo ! End loop over all unique triplets of target determinant (volume)\n allocate(srHNFs(3,3,nfound))\n srHNFs(:,:,1:nfound) = temp_srHNFs(:,:,1:nfound)\n if (associated(d)) then\n deallocate(d)\n end if\n if (allocated(temp_storage)) then\n deallocate(temp_storage)\n end if\n deallocate(temp_srHNFs)\n end SUBROUTINE get_srHNFs\n\n !!This function determines if a lattice has the desired\n !!symmetries.\n !!The super lattice vectors.\n !!The poing group operators we want to check for.\n !!epsilon for checking equivalence in floating\n !!point arithmetic.\n logical function symm_pres(lat,pg,eps_)\n real(dp), intent(in) :: lat(3,3)\n real(dp), intent(in) :: pg(:,:,:)\n real(dp), intent(in), optional :: eps_\n\n real(dp) :: eps\n integer :: i\n real(dp) :: RB(3,3), N(3,3), latinv(3,3)\n \n if(.not. present(eps_)) then\n eps = 1e-10_dp\n else\n eps = eps_\n end if\n\n symm_pres = .True.\n do i=1,size(pg,3)\n RB = matmul(pg(:,:,i),lat)\n call matrix_inverse(lat,latinv)\n N = matmul(latinv,RB)\n if (.not. equal(N,nint(N),eps)) then\n symm_pres = .False.\n exit\n end if\n end do\n \n end function symm_pres\n\n !!Finds the generators of a given point group.\n !!The point group.\n !!The generators of the point group.\n !!epsilon for checking equivalence in floating\n !!point arithmetic.\n subroutine find_pg_gens(pg,gens,eps)\n real(dp), pointer, intent(in) :: pg(:,:,:)\n real(dp), allocatable, intent(out) :: gens(:,:,:)\n real(dp), intent(in) :: eps\n \n real(dp), allocatable :: test_gens(:,:,:)\n integer :: n_gens, status, i, j, gens_found\n logical :: found_gens\n integer, allocatable :: combs(:,:)\n\n gens_found = 0\n n_gens = 2\n found_gens = .False.\n\n do while ((found_gens .eqv. .False.) .and. (n_gens < 4))\n call combinations(size(pg,3),n_gens,combs)\n allocate(test_gens(3,3,n_gens),STAT=status)\n if(status/=0) stop \"Failed to allocate memory in find_pg_gens\"\n do i=1,size(combs,2)\n do j=1,n_gens\n test_gens(:,:,j) = pg(:,:,combs(j,i))\n end do\n if (forms_group(test_gens,pg,eps) .eqv. .True.) then\n allocate(gens(3,3,n_gens),STAT=status) \n if(status/=0) stop \"Failed to allocate memory in find_pg_gens\"\n gens(:,:,:) = test_gens(:,:,:)\n found_gens = .True.\n exit\n end if\n end do\n\n n_gens = n_gens + 1\n deallocate(test_gens)\n end do\n\n if (allocated(combs)) then\n deallocate(combs)\n end if\n end subroutine find_pg_gens\n\n !!Determines if a set of generators forms the group.\n !!The test set of generators.\n !!The pg we want to be able to generate.\n !!epsilon for checking equivalence in floating\n !!point arithmetic.\n logical function forms_group(gens,pg,eps)\n real(dp), intent(in) :: gens(:,:,:), pg(:,:,:)\n real(dp), intent(in) :: eps\n \n integer :: elements, i, j, k, nf, temp_int, status\n real(dp), allocatable :: test_set(:,:,:)\n real(dp) :: test(3,3)\n logical :: growing, in_group\n\n\n forms_group = .True.\n allocate(test_set(3,3,size(pg,3)),STAT=status)\n if(status/=0) stop \"Failed to allocate memory in forms_group\"\n test_set = 0\n elements = 0\n\n do i=1,size(gens,3)\n test_set(:,:,i) = gens(:,:,i)\n elements = elements + 1\n end do\n\n do i=1, size(gens,3)\n do j=1,size(gens,3)\n test = matmul(gens(:,:,i),gens(:,:,j))\n in_group = .False.\n do k=1,size(test_set)\n if (equal(test,test_set(:,:,k),eps)) then\n in_group = .True.\n exit\n end if\n end do\n if (in_group .eqv. .False.) then\n elements = elements + 1\n if (elements > size(test_set,3)) then\n forms_group = .False.\n exit\n end if\n test_set(:,:,elements) = test\n end if\n end do\n if (forms_group .eqv. .False.) then\n exit\n end if\n end do\n\n growing = .True.\n do while (growing .eqv. .True.)\n nf = 0\n temp_int = elements\n do i=1, size(gens,3)\n do j=1,temp_int\n test = matmul(gens(:,:,i),test_set(:,:,j))\n in_group = .False.\n do k=1,size(test_set)\n if (equal(test,test_set(:,:,k),eps)) then\n in_group = .True.\n exit\n end if\n end do\n if (in_group .eqv. .False.) then\n elements = elements + 1\n nf = nf + 1\n if (elements > size(test_set,3)) then\n forms_group = .False.\n exit\n end if\n test_set(:,:,elements) = test\n end if\n end do\n if (forms_group .eqv. .False.) then\n exit\n end if\n end do\n\n if ((nf == 0) .or. (forms_group .eqv. .False.)) then\n growing = .False.\n end if\n end do\n\n if (size(test_set,3) /= size(pg,3)) then\n forms_group = .False.\n else\n do i=1,size(pg,3)\n in_group = .False.\n do j=1,size(test_set)\n if (equal(pg(:,:,i),test_set(:,:,j),eps)) then\n forms_group = .True.\n exit\n else\n forms_group = .False.\n end if\n end do\n if (forms_group .eqv. .False.) then\n exit\n end if\n end do\n end if\n deallocate(test_set)\n end function forms_group\n \n !!Finds all pair or triplet combinations of numbers 1 to n.\n !!The largest number in the pairs.\n !!The resulting combinations.\n !!2 if for pairs, 3 if for triplets.\n subroutine combinations(n,r,comb)\n integer, intent(in) :: n, r\n integer, allocatable, intent(out) :: comb(:,:)\n\n integer :: n_combs, status, i, j, k, combs_found\n\n if (allocated(comb)) then\n deallocate(comb)\n end if\n if (r == 2) then\n \n n_combs = binomial(n,2)\n combs_found = 0\n allocate(comb(3,n_combs),STAT=status)\n if(status/=0) stop \"Failed to allocate memory in combinations\"\n do i = 1,n-1\n do j = i+1, n\n combs_found = combs_found + 1\n comb(:,combs_found) = (/i,j,0/)\n end do\n end do\n elseif (r==3) then\n n_combs = binomial(n,3)\n combs_found = 0\n allocate(comb(3,n_combs),STAT=status)\n if(status/=0) stop \"Failed to allocate memory in combinations\"\n do i = 1,n-2\n do j = i+1, n-1\n do k = j+1, n\n combs_found = combs_found + 1\n comb(:,combs_found) = (/i,j,k/)\n end do\n end do\n end do\n else\n stop \"combinations only works for pair and triplets (r=2 or 3)\"\n end if\n end subroutine combinations\nend Module srHNF_brute\n", "meta": {"hexsha": "4b5f9867a15acb30e739747e527a345f6bad90c6", "size": 11871, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "support/brute_force/srHNF_brute.f90", "max_stars_repo_name": "glwhart/autoGR", "max_stars_repo_head_hexsha": "4c031eaa6ade736418ad9136d77004c258ef6fb4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2019-12-17T11:46:32.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T19:06:11.000Z", "max_issues_repo_path": "support/brute_force/srHNF_brute.f90", "max_issues_repo_name": "glwhart/autoGR", "max_issues_repo_head_hexsha": "4c031eaa6ade736418ad9136d77004c258ef6fb4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2019-10-28T14:37:16.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-09T00:19:56.000Z", "max_forks_repo_path": "support/brute_force/srHNF_brute.f90", "max_forks_repo_name": "glwhart/autoGR", "max_forks_repo_head_hexsha": "4c031eaa6ade736418ad9136d77004c258ef6fb4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2019-12-17T11:48:28.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-23T19:40:43.000Z", "avg_line_length": 34.7105263158, "max_line_length": 99, "alphanum_fraction": 0.5700446466, "num_tokens": 3321, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.7690802370707283, "lm_q1q2_score": 0.6957488440474247}} {"text": "c***********************************************************\nc Test of minimisation routines from \"Numerical Recipees\"\nc\nc JLP\nc Version 12/03/2001\nc***********************************************************\n program dcv_test0\n integer i,iter,n \n parameter(n=2)\n real p(n),ftol,fret\n external func_test,dfunc_test\n external func,dfunc\n\n write(6,*) \"Test with Banana function\"\n\nc Starting point:\n p(1)= -1.9 \n p(2)= 2.\nc Tolerance\n ftol=1.e-3\n call frprmn(p,n,ftol,iter,fret,func,dfunc)\nc call frprmn(p,n,ftol,iter,fret,func_test,dfunc_test)\n write(6,11) p(1),p(2),iter,fret\n11 format(\" Location of the minimum:\",2(F12.3,1X),/,\n 1 \" Number of iterations:\",I4,/,\n 1 \" Value of the minimum:\",E12.5)\n end\n!-------------------------------------------------------------------\n! Function: \n! Banana function : start at X=[-1.9;2]. minimum at X=[1;1] : f(X)=0;\n!-------------------------------------------------------------------\n real function func_test(x)\n real x(*)\n func = (1. - x(1))**2 + 100*(x(2) - x(1))**2\n end\n!-------------------------------------------------------------------\n! Gradient:\n! BANANA FUNCTION\n! z = 100*(x(2)-x(1))^2 + (1-x(1))^2\n! dx = [ -200*(x(2) - x(1))-2*(1-x(1)); 200*(x(2)-x(1)) ];\n!-------------------------------------------------------------------\n subroutine dfunc_test(x,dx)\n real x(*),dx(*)\n dx(1) = -200*(x(2)-x(1)) - 2*(1-x(1)) \n dx(2) = 200*(x(2)-x(1))\n return\n end\n real function func(x)\n real x(*)\n func = (1. - x(1))**2 + 100*(x(2) - x(1))**2\n end\n subroutine dfunc(x,dx)\n real x(*),dx(*)\n dx(1) = -200*(x(2)-x(1)) - 2*(1-x(1)) \n dx(2) = 200*(x(2)-x(1))\n return\n end\n", "meta": {"hexsha": "96641c382c0c81fdcbe04ddd3b77d27ee8dc2a4d", "size": 1800, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "deconv_moffat_dcv/f90_dcv/dcv_test0.for", "max_stars_repo_name": "jlprieur/deconv", "max_stars_repo_head_hexsha": "027324b50a152f201c4c2485648617cac9a53260", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "deconv_moffat_dcv/f90_dcv/dcv_test0.for", "max_issues_repo_name": "jlprieur/deconv", "max_issues_repo_head_hexsha": "027324b50a152f201c4c2485648617cac9a53260", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "deconv_moffat_dcv/f90_dcv/dcv_test0.for", "max_forks_repo_name": "jlprieur/deconv", "max_forks_repo_head_hexsha": "027324b50a152f201c4c2485648617cac9a53260", "max_forks_repo_licenses": ["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.0344827586, "max_line_length": 69, "alphanum_fraction": 0.4022222222, "num_tokens": 571, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595163, "lm_q2_score": 0.7690802264851919, "lm_q1q2_score": 0.6957488344712137}} {"text": " SUBROUTINE ftest(data1,n1,data2,n2,f,prob)\r\n INTEGER n1,n2\r\n REAL f,prob,data1(n1),data2(n2)\r\nCU USES avevar,betai\r\n REAL ave1,ave2,df1,df2,var1,var2,betai\r\n call avevar(data1,n1,ave1,var1)\r\n call avevar(data2,n2,ave2,var2)\r\n if(var1.gt.var2)then\r\n f=var1/var2\r\n df1=n1-1\r\n df2=n2-1\r\n else\r\n f=var2/var1\r\n df1=n2-1\r\n df2=n1-1\r\n endif\r\n prob=2.*betai(0.5*df2,0.5*df1,df2/(df2+df1*f))\r\n if(prob.gt.1.)prob=2.-prob\r\n return\r\n END\r\n", "meta": {"hexsha": "5825c1207807eb8aa9ddee5668b4b047d0102d26", "size": 539, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/ftest.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/ftest.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/ftest.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.6666666667, "max_line_length": 53, "alphanum_fraction": 0.5380333952, "num_tokens": 214, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533126145178, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6957397809861063}} {"text": "program variables_02\nimplicit none\ninteger :: x, y\nx = 2\ny = x + 1\nif (y /= 3) error stop\n\nx = 2\ny = 3\ny = (x+2)*(1-y)+1\nif (y /= -7) error stop\n\nx = 2\ny = -x*(-x)\nif (y /= 4) error stop\nend program\n", "meta": {"hexsha": "263340dc351cd5ff744d0b424cd1538fb3333fbd", "size": 199, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "integration_tests/variables_02.f90", "max_stars_repo_name": "Thirumalai-Shaktivel/lfortran", "max_stars_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 316, "max_stars_repo_stars_event_min_datetime": "2019-03-24T16:23:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:28:33.000Z", "max_issues_repo_path": "integration_tests/variables_02.f90", "max_issues_repo_name": "Thirumalai-Shaktivel/lfortran", "max_issues_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-07-29T04:58:03.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-04T16:40:06.000Z", "max_forks_repo_path": "integration_tests/variables_02.f90", "max_forks_repo_name": "Thirumalai-Shaktivel/lfortran", "max_forks_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2019-03-28T19:40:07.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T07:28:55.000Z", "avg_line_length": 11.7058823529, "max_line_length": 23, "alphanum_fraction": 0.5477386935, "num_tokens": 93, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673269042767, "lm_q2_score": 0.8558511506439708, "lm_q1q2_score": 0.6956934370519139}} {"text": "C File: goto_06.f\nC A simple program with a single forward conditional goto and\nC a single backward unconditional goto.\nC The program computes and prints out the values of n! for n in [1,10].\n\n program factorial\n implicit none\n\n integer i, n, fact\n\n i = 0\n n = 10\n fact = 1\n\n 111 i = i + 1\n\n if (i .le. n) goto 222\n\n stop\n\n 222 fact = fact * i\n\n write (*, 10) i, fact\n\n goto 111\n\n 10 format('i = ', I3, '; fact = ', I8)\n\n end program factorial\n", "meta": {"hexsha": "5c021def204d97cc7fb1997835902428402a4958", "size": 519, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/data/program_analysis/goto/goto_06.f", "max_stars_repo_name": "mikiec84/delphi", "max_stars_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2018-03-03T11:57:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-16T21:19:54.000Z", "max_issues_repo_path": "tests/data/program_analysis/goto/goto_06.f", "max_issues_repo_name": "mikiec84/delphi", "max_issues_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 385, "max_issues_repo_issues_event_min_datetime": "2018-02-21T16:52:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-17T07:44:56.000Z", "max_forks_repo_path": "tests/data/program_analysis/goto/goto_06.f", "max_forks_repo_name": "mikiec84/delphi", "max_forks_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2018-03-20T01:08:11.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-29T01:04:49.000Z", "avg_line_length": 17.3, "max_line_length": 75, "alphanum_fraction": 0.5587668593, "num_tokens": 159, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511543206819, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.6956934303409067}} {"text": " SUBROUTINE sor(a,b,c,d,e,f,u,jmax,rjac)\r\n INTEGER jmax,MAXITS\r\n DOUBLE PRECISION rjac,a(jmax,jmax),b(jmax,jmax),c(jmax,jmax),\r\n *d(jmax,jmax),e(jmax,jmax),f(jmax,jmax),u(jmax,jmax),EPS\r\n PARAMETER (MAXITS=1000,EPS=1.d-5)\r\n INTEGER ipass,j,jsw,l,lsw,n\r\n DOUBLE PRECISION anorm,anormf,omega,resid\r\n anormf=0.d0\r\n do 12 j=2,jmax-1\r\n do 11 l=2,jmax-1\r\n anormf=anormf+abs(f(j,l))\r\n11 continue\r\n12 continue\r\n omega=1.d0\r\n do 16 n=1,MAXITS\r\n anorm=0.d0\r\n jsw=1\r\n do 15 ipass=1,2\r\n lsw=jsw\r\n do 14 j=2,jmax-1\r\n do 13 l=lsw+1,jmax-1,2\r\n resid=a(j,l)*u(j+1,l)+b(j,l)*u(j-1,l)+c(j,l)*u(j,l+1)+d(j,\r\n *l)*u(j,l-1)+e(j,l)*u(j,l)-f(j,l)\r\n anorm=anorm+abs(resid)\r\n u(j,l)=u(j,l)-omega*resid/e(j,l)\r\n13 continue\r\n lsw=3-lsw\r\n14 continue\r\n jsw=3-jsw\r\n if(n.eq.1.and.ipass.eq.1) then\r\n omega=1.d0/(1.d0-.5d0*rjac**2)\r\n else\r\n omega=1.d0/(1.d0-.25d0*rjac**2*omega)\r\n endif\r\n15 continue\r\n if(anorm.lt.EPS*anormf)return\r\n16 continue\r\n pause 'MAXITS exceeded in sor'\r\n END\r\n", "meta": {"hexsha": "3e49fa3f4e1570d7b7616ef995b9934e4c672ad2", "size": 1234, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/sor.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/sor.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/sor.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": 30.85, "max_line_length": 73, "alphanum_fraction": 0.4975688817, "num_tokens": 456, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797027760039, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6956709087497049}} {"text": "subroutine SHExpandDH(grid, n, cilm, lmax, norm, sampling, csphase, &\n lmax_calc, exitstatus)\n!------------------------------------------------------------------------------\n!\n! This routine will expand a grid containing n samples in both longitude\n! and latitude (or n x 2n, see below) into spherical harmonics. This routine\n! makes use of the sampling theorem presented in driscoll and healy (1994)\n! and employs ffts when calculating the sin and cos terms. The number of\n! samples, n, must be even for this routine to work, and the spherical\n! harmonic expansion is exact if the function is bandlimited to degree n/2-1.\n! Legendre functions are computed on the fly using the scaling methodology\n! presented in holmes and featherston (2002). When norm is 1, 2 or 4, these\n! are accurate to about degree 2800. When norm is 3, the routine is only\n! stable to about degree 15! If the optional parameter lmax_calc is\n! specified, the spherical harmonic coefficients will only be calculated up\n! to this degree.\n!\n! If sampling is 1 (default), the input grid contains n samples in latitude\n! from 90 to -90+interval, and n samples in longitude from 0 to\n! 360-2*interval, where interval is the latitudinal sampling interval 180/n.\n! Note that the datum at 90 degees north latitude is ultimately downweighted\n! to zero, so this point does not contribute to the spherical harmonic\n! coefficients. If sampling is 2, the input grid must contain n samples in\n! latitude and 2n samples in longitude. In this case, the sampling intervals\n! in latitude and longitude are 180/n and 360/n respectively. when performing\n! the ffts in longitude, the frequencies greater than n/2-1 are simply\n! discarded to prevent aliasing.\n!\n! Calling Parameters\n!\n! IN\n! grid Equally sampled grid in latitude and longitude of\n! dimension (1:n, 1:n) or and equally spaced grid of\n! dimension (1:n,2n).\n! n Number of samples in latitude and longitude (for\n! sampling=1), or the number of samples in latitude (for\n! sampling=2).\n!\n! OUT\n! cilm Array of spherical harmonic coefficients with dimension\n! (2, lmax+1, lmax+1), or, if lmax_calc is present\n! (2, lmax_calc+1, lmax_calc+1).\n! lmax Spherical harmonic bandwidth of the grid. This\n! corresponds to the maximum spherical harmonic degree of\n! the expansion if the optional parameter lmax_calc is\n! not specified.\n!\n! OPTIONAL (IN)\n! norm Normalization to be used when calculating legendre\n! functions\n! (1) \"geodesy\" (default)\n! (2) schmidt\n! (3) unnormalized\n! (4) orthonormalized\n! sampling (1) Grid is n latitudes by n longitudes (default).\n! (2) Grid is n by 2n. the higher frequencies resulting\n! from this oversampling are discarded, and hence not\n! aliased into lower frequencies.\n! csphase 1: Do not include the condon-shortley phase factor of\n! (-1)^m (default). -1: Apply the condon-shortley phase\n! factor of (-1)^m.\n! lmax_calc The maximum spherical harmonic degree calculated in the\n! spherical harmonic expansion.\n!\n! OPTIONAL (OUT)\n! exitstatus If present, instead of executing a STOP when an error\n! is encountered, the variable exitstatus will be\n! returned describing the error.\n! 0 = No errors;\n! 1 = Improper dimensions of input array;\n! 2 = Improper bounds for input variable;\n! 3 = Error allocating memory;\n! 4 = File IO error.\n!\n! Notes:\n! 1. This routine does not use the fast legendre transforms that\n! are presented in driscoll and heally (1994).\n! 2. Use of a n by 2n grid is implemented because many geographic grids\n! are sampled this way. when taking the fourier transforms in\n! longitude, all of the higher frequencies are ultimately discarded.\n! If, instead, every other column of the grid were discarded to form\n! a nxn grid, higher frequencies could be aliased into lower\n! frequencies.\n!\n! Copyright (c) 2005-2019, SHTOOLS\n! All rights reserved.\n!\n!------------------------------------------------------------------------------\n use FFTW3\n use SHTOOLS, only: DHaj\n use ftypes\n use, intrinsic :: iso_c_binding\n\n implicit none\n\n real(dp), intent(in) :: grid(:,:)\n real(dp), intent(out) :: cilm(:,:,:)\n integer(int32), intent(in) :: n\n integer(int32), intent(out) :: lmax\n integer(int32), intent(in), optional :: norm, sampling, csphase, lmax_calc\n integer(int32), intent(out), optional :: exitstatus\n complex(dp) :: cc(n+1), ccs(n+1)\n integer(int32) :: l, m, i, l1, m1, i_eq, i_s, lnorm, astat(4), &\n lmax_comp, nlong\n type(C_PTR) :: plan, plans\n real(dp) :: pi, gridl(2*n), gridls(2*n), aj(n), fcoef1(2, n/2+1), &\n fcoef2(2, n/2+1), theta, prod, scalef, rescalem, u, p, pmm, &\n pm1, pm2, z, ffc(1:2,-1:1)\n real(dp), save, allocatable :: sqr(:), ff1(:,:), ff2(:,:)\n integer(int8), save, allocatable :: fsymsign(:,:)\n integer(int32), save :: lmax_old = 0, norm_old = 0\n integer(int32) :: phase\n\n!$OMP threadprivate(sqr, ff1, ff2, fsymsign, lmax_old, norm_old)\n\n if (present(exitstatus)) exitstatus = 0\n\n lmax = n / 2 - 1\n\n if (present(lmax_calc)) then\n if (lmax_calc > lmax) then\n print*, \"Error --- SHExpandDH\"\n print*, \"LMAX_CALC must be less than or equal to LMAX.\"\n print*, \"LMAX = \", lmax\n print*, \"LMAX_CALC = \", lmax_calc\n if (present(exitstatus)) then\n exitstatus = 2\n return\n else\n stop\n end if\n\n else\n lmax_comp = min(lmax, lmax_calc)\n\n end if\n\n else\n lmax_comp = lmax\n\n end if\n\n if (present(sampling)) then\n if (sampling /= 1 .and. sampling /= 2) then\n print*, \"Error --- SHExpandDH\"\n print*, \"Optional parameter sampling must be \" // &\n \"1 (N by N) or 2 (N by 2N).\"\n print*, \"Input value is \", sampling\n if (present(exitstatus)) then\n exitstatus = 2\n return\n else\n stop\n end if\n\n end if\n\n end if\n\n if (mod(n,2) /= 0) then\n print*, \"Error --- SHExpandDH\"\n print*, \"The number of samples in latitude and longitude, \" // &\n \"N, must be even.\"\n print*, \"Input value is \", n\n if (present(exitstatus)) then\n exitstatus = 2\n return\n else\n stop\n end if\n\n else if (size(cilm(:,1,1)) < 2 .or. size(cilm(1,:,1)) < lmax_comp+1 .or. &\n size(cilm(1,1,:)) < lmax_comp+1) then\n print*, \"Error --- SHExpandDH\"\n print*, \"CILM must be dimensioned as (2, LMAX_COMP+1, \" // &\n \"LMAX_COMP+1) where LMAX_COMP = MIN(N/2, LMAX_CALC+1)\"\n print*, \"N = \", n\n if (present(lmax_calc)) print*, \"LMAX_CALC = \", lmax_calc\n print*, \"Input dimension is \", size(cilm(:,1,1)), size(cilm(1,:,1)), &\n size(cilm(1,1,:))\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n end if\n\n if (present(sampling)) then\n if (sampling == 1) then\n if (size(grid(:,1)) < n .or. size(grid(1,:)) < n) then\n print*, \"Error --- SHExpandDH\"\n print*, \"GRIDDH must be dimensioned as (N, N) where N is \", n\n print*, \"Input dimension is \", size(grid(:,1)), size(grid(1,:))\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n end if\n\n else if (sampling == 2) then\n if (size(grid(:,1)) < n .or. size(grid(1,:)) < 2*n) then\n print*, \"Error --- SHExpandDH\"\n print*, \"GRIDDH must be dimensioned as (N, 2*N) where N is \", n\n print*, \"Input dimension is \", size(grid(:,1)), size(grid(1,:))\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n end if\n\n end if\n\n else\n if (size(grid(:,1)) < n .or. size(grid(1,:)) < n) then\n print*, \"Error --- SHExpandDH\"\n print*, \"GRIDDH must be dimensioned as (N, N) where N is \", n\n print*, \"Input dimension is \", size(grid(:,1)), size(grid(1,:))\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n end if\n\n end if\n\n if (present(csphase)) then\n if (csphase /= -1 .and. csphase /= 1) then\n print*, \"Error --- SHExpandDH\"\n print*, \"CSPHASE must be 1 (exclude) or -1 (include).\"\n print*, \"Input value is \", csphase\n if (present(exitstatus)) then\n exitstatus = 2\n return\n else\n stop\n end if\n\n else\n phase = csphase\n\n end if\n\n else\n phase = 1\n\n end if\n\n if (present(norm)) then\n if (norm > 4 .or. norm < 1) then\n print*, \"Error --- SHExpandDH\"\n print*, \"Parameter norm must be 1 (geodesy), 2 (schmidt), \" // &\n \"3 (unnormalized), or 4 (orthonormalized).\"\n print*, \"Input value is \", norm\n if (present(exitstatus)) then\n exitstatus = 2\n return\n else\n stop\n end if\n\n end if\n\n lnorm = norm\n\n else\n lnorm = 1\n\n end if\n\n pi = acos(-1.0_dp)\n\n cilm = 0.0_dp\n\n scalef = 1.0e-280_dp\n\n if (present(exitstatus)) then\n call DHaj(n, aj, exitstatus=exitstatus)\n if (exitstatus /= 0) return\n else\n call DHaj(n, aj)\n end if\n\n aj(1:n) = aj(1:n) * sqrt(4.0_dp*pi)\n ! Driscoll and Heally use unity normalized spherical harmonics\n\n if (present(sampling)) then\n if (sampling == 1) then\n nlong = n\n\n else\n nlong = 2 * n\n\n end if\n\n else\n nlong = n\n\n end if\n\n !--------------------------------------------------------------------------\n !\n ! Calculate recursion constants used in computing the legendre functions.\n !\n !--------------------------------------------------------------------------\n if (lmax_comp /= lmax_old .or. lnorm /= norm_old) then\n if (allocated (sqr)) deallocate (sqr)\n if (allocated (ff1)) deallocate (ff1)\n if (allocated (ff2)) deallocate (ff2)\n if (allocated (fsymsign)) deallocate (fsymsign)\n\n allocate (sqr(2*lmax_comp+1), stat=astat(1))\n allocate (ff1(lmax_comp+1,lmax_comp+1), stat=astat(2))\n allocate (ff2(lmax_comp+1,lmax_comp+1), stat=astat(3))\n allocate (fsymsign(lmax_comp+1,lmax_comp+1), stat=astat(4))\n\n if (sum(astat(1:4)) /= 0) then\n print*, \"Error --- SHExpandDH\"\n print*, \"Problem allocating arrays SQR, FF1, FF2, or FSYMSIGN\", &\n astat(1), astat(2), astat(3), astat(4)\n if (present(exitstatus)) then\n exitstatus = 3\n return\n else\n stop\n end if\n\n end if\n\n !----------------------------------------------------------------------\n !\n ! Calculate signs used for symmetry of legendre functions about\n ! equator\n !\n !----------------------------------------------------------------------\n do l = 0, lmax_comp, 1\n do m = 0, l, 1\n if (mod(l-m,2) == 0) then\n fsymsign(l+1,m+1) = 1\n\n else\n fsymsign(l+1,m+1) = -1\n\n end if\n\n end do\n\n end do\n\n !----------------------------------------------------------------------\n !\n ! Precompute square roots of integers that are used several times.\n !\n !----------------------------------------------------------------------\n do l = 1, 2 * lmax_comp + 1\n sqr(l) = sqrt(dble(l))\n end do\n\n !----------------------------------------------------------------------\n !\n ! Precompute multiplicative factors used in recursion relationships\n ! p(l,m) = x*f1(l,m)*p(l-1,m) - p(l-2,m)*f2(l,m)\n ! k = l*(l+1)/2 + m + 1\n ! Note that prefactors are not used for the case when m=l as a\n ! different recursion is used. furthermore, for m=l-1, plmbar(l-2,m)\n ! is assumed to be zero.\n !\n !----------------------------------------------------------------------\n select case (lnorm)\n case(1,4)\n if (lmax_comp /= 0) then\n ff1(2,1) = sqr(3)\n ff2(2,1) = 0.0_dp\n\n end if\n\n do l = 2, lmax_comp, 1\n ff1(l+1,1) = sqr(2*l-1) * sqr(2*l+1) / dble(l)\n ff2(l+1,1) = dble(l-1) * sqr(2*l+1) / sqr(2*l-3) / dble(l)\n\n do m = 1, l - 2, 1\n ff1(l+1,m+1) = sqr(2*l+1) * sqr(2*l-1) / sqr(l+m) &\n / sqr(l-m)\n ff2(l+1,m+1) = sqr(2*l+1) * sqr(l-m-1) * sqr(l+m-1) &\n / sqr(2*l-3) / sqr(l+m) / sqr(l-m)\n\n end do\n\n ff1(l+1,l) = sqr(2*l+1) * sqr(2*l-1) / sqr(l+m) / sqr(l-m)\n ff2(l+1,l) = 0.0_dp\n\n end do\n\n case(2)\n if (lmax_comp /= 0) then\n ff1(2,1) = 1.0_dp\n ff2(2,1) = 0.0_dp\n\n end if\n\n do l = 2, lmax_comp, 1\n ff1(l+1,1) = dble(2*l-1) / dble(l)\n ff2(l+1,1) = dble(l-1) / dble(l)\n\n do m = 1, l - 2, 1\n ff1(l+1,m+1) = dble(2*l-1) / sqr(l+m) / sqr(l-m)\n ff2(l+1,m+1) = sqr(l-m-1) * sqr(l+m-1) / sqr(l+m) &\n / sqr(l-m)\n\n end do\n\n ff1(l+1,l)= dble(2*l-1) / sqr(l+m) / sqr(l-m)\n ff2(l+1,l) = 0.0_dp\n\n end do\n\n case(3)\n do l = 1, lmax_comp, 1\n ff1(l+1,1) = dble(2*l-1) / dble(l)\n ff2(l+1,1) = dble(l-1) / dble(l)\n\n do m = 1, l-1, 1\n ff1(l+1,m+1) = dble(2*l-1) / dble(l-m)\n ff2(l+1,m+1) = dble(l+m-1) / dble(l-m)\n\n end do\n\n end do\n\n end select\n\n lmax_old = lmax_comp\n norm_old = lnorm\n\n end if\n\n !--------------------------------------------------------------------------\n !\n ! Create generic plan for gridl and gridls.\n !\n !--------------------------------------------------------------------------\n plan = fftw_plan_dft_r2c_1d(nlong, gridl(1:nlong), cc, FFTW_MEASURE)\n plans = fftw_plan_dft_r2c_1d(nlong, gridls(1:nlong), ccs, FFTW_MEASURE)\n\n !--------------------------------------------------------------------------\n !\n ! Integrate over all latitudes. Take into account symmetry of the\n ! plms about the equator.\n !\n !--------------------------------------------------------------------------\n i_eq = n / 2 + 1 ! index correspondong to the equator\n\n do i = 2, i_eq - 1, 1\n theta = (i-1) * pi / dble(n)\n z = cos(theta)\n u = sqrt( (1.0_dp-z) * (1.0_dp+z) )\n\n gridl(1:nlong) = grid(i,1:nlong)\n call fftw_execute_dft_r2c(plan, gridl, cc) ! take fourier transform\n fcoef1(1,1:n/2) = sqrt(2*pi) * aj(i) * dble(cc(1:n/2)) / dble(nlong)\n fcoef1(2,1:n/2) = -sqrt(2*pi) * aj(i) * aimag(cc(1:n/2)) / dble(nlong)\n\n i_s = 2 * i_eq - i\n\n gridls(1:nlong) = grid(i_s,1:nlong)\n call fftw_execute_dft_r2c(plans, gridls, ccs)\n fcoef2(1,1:n/2) = sqrt(2*pi) * aj(i_s) * dble(ccs(1:n/2)) / dble(nlong)\n fcoef2(2,1:n/2) = -sqrt(2*pi) * aj(i_s) * aimag(ccs(1:n/2)) / &\n dble(nlong)\n\n select case (lnorm)\n case (1,2,3); pm2 = 1.0_dp\n case (4); pm2 = 1.0_dp / sqrt(4*pi)\n\n end select\n\n cilm(1,1,1) = cilm(1,1,1) + pm2 * (fcoef1(1,1) + fcoef2(1,1))\n ! fsymsign = 1\n\n if (lmax_comp == 0) cycle\n\n pm1 = ff1(2,1) * z * pm2\n cilm(1,2,1) = cilm(1,2,1) + pm1 * (fcoef1(1,1) - fcoef2(1,1))\n ! fsymsign = -1\n\n ffc(1,-1) = fcoef1(1,1) - fcoef2(1,1)\n ffc(1, 1) = fcoef1(1,1) + fcoef2(1,1)\n\n do l = 2, lmax_comp, 1\n l1 = l + 1\n p = ff1(l1,1) * z * pm1 - ff2(l1,1) * pm2\n pm2 = pm1\n pm1 = p\n cilm(1,l1,1) = cilm(1,l1,1) + p * ffc(1,fsymsign(l1,1))\n\n end do\n\n select case (lnorm)\n case (1,2); pmm = sqr(2) * scalef\n case (3); pmm = scalef\n case (4); pmm = sqr(2) * scalef / sqrt(4*pi)\n\n end select\n\n rescalem = 1.0_dp / scalef\n\n do m = 1, lmax_comp-1, 1\n m1 = m + 1\n rescalem = rescalem * u\n\n select case (lnorm)\n case (1,4)\n pmm = phase * pmm * sqr(2*m+1) / sqr(2*m)\n pm2 = pmm\n\n case (2)\n pmm = phase * pmm * sqr(2*m+1) / sqr(2*m)\n pm2 = pmm / sqr(2*m+1)\n\n case (3)\n pmm = phase * pmm * (2*m-1)\n pm2 = pmm\n\n end select\n\n fcoef1(1:2,m1) = fcoef1(1:2,m1) * rescalem\n fcoef2(1:2,m1) = fcoef2(1:2,m1) * rescalem\n\n cilm(1:2,m1,m1) = cilm(1:2,m1,m1) + pm2 * &\n (fcoef1(1:2,m1) + fcoef2(1:2,m1))\n ! fsymsign = 1\n\n pm1 = z * ff1(m1+1,m1) * pm2\n\n cilm(1:2,m1+1,m1) = cilm(1:2,m1+1,m1) + pm1 * &\n (fcoef1(1:2,m1) - fcoef2(1:2,m1))\n ! fsymsign = -1\n\n ffc(1:2,-1) = fcoef1(1:2,m1) - fcoef2(1:2,m1)\n ffc(1:2, 1) = fcoef1(1:2,m1) + fcoef2(1:2,m1)\n\n do l = m + 2, lmax_comp, 1\n l1 = l + 1\n p = z * ff1(l1,m1) * pm1-ff2(l1,m1) * pm2\n pm2 = pm1\n pm1 = p\n cilm(1:2,l1,m1) = cilm(1:2,l1,m1) + p * &\n ffc(1:2,fsymsign(l1,m1))\n\n end do\n\n end do\n\n rescalem = rescalem * u\n\n select case (lnorm)\n case (1,4)\n pmm = phase * pmm * sqr(2*lmax_comp+1) &\n / sqr(2*lmax_comp) * rescalem\n case (2)\n pmm = phase * pmm / sqr(2*lmax_comp) * rescalem\n case (3)\n pmm = phase * pmm * (2*lmax_comp-1) * rescalem\n\n end select\n\n cilm(1:2,lmax_comp+1,lmax_comp+1) = cilm(1:2,lmax_comp+1,lmax_comp+1) &\n + pmm * ( fcoef1(1:2,lmax_comp+1) &\n + fcoef2(1:2,lmax_comp+1) )\n ! fsymsign = 1\n end do\n\n ! finally, do equator\n i = i_eq\n\n z = 0.0_dp\n u = 1.0_dp\n\n gridl(1:nlong) = grid(i,1:nlong)\n call fftw_execute_dft_r2c(plan, gridl, cc)\n fcoef1(1,1:n/2) = sqrt(2*pi) * aj(i) * dble(cc(1:n/2)) / dble(nlong)\n fcoef1(2,1:n/2) = -sqrt(2*pi) * aj(i) * aimag(cc(1:n/2)) / dble(nlong)\n\n select case (lnorm)\n case (1,2,3); pm2 = 1.0_dp\n case (4); pm2 = 1.0_dp / sqrt(4*pi)\n end select\n\n cilm(1,1,1) = cilm(1,1,1) + pm2 * fcoef1(1,1)\n\n if (lmax_comp /= 0) then\n do l = 2, lmax_comp, 2\n l1 = l + 1\n p = - ff2(l1,1) * pm2\n pm2 = p\n cilm(1,l1,1) = cilm(1,l1,1) + p * fcoef1(1,1)\n\n end do\n\n select case (lnorm)\n case (1,2); pmm = sqr(2) * scalef\n case (3); pmm = scalef\n case (4); pmm = sqr(2) * scalef / sqrt(4 * pi)\n end select\n\n rescalem = 1.0_dp / scalef\n\n do m = 1, lmax_comp-1, 1\n m1 = m + 1\n\n select case (lnorm)\n case (1,4)\n pmm = phase * pmm * sqr(2*m+1) / sqr(2*m)\n pm2 = pmm\n\n case (2)\n pmm = phase * pmm * sqr(2*m+1) / sqr(2*m)\n pm2 = pmm / sqr(2*m+1)\n\n case (3)\n pmm = phase * pmm * (2*m-1)\n pm2 = pmm\n\n end select\n\n fcoef1(1:2,m1) = fcoef1(1:2,m1) * rescalem\n\n cilm(1:2,m1,m1) = cilm(1:2,m1,m1) + pm2 * fcoef1(1:2,m1)\n\n do l = m + 2, lmax_comp, 2\n l1 = l + 1\n p = - ff2(l1,m1) * pm2\n pm2 = p\n cilm(1:2,l1,m1) = cilm(1:2,l1,m1) + p * fcoef1(1:2,m1)\n\n end do\n\n end do\n\n select case (lnorm)\n case(1,4)\n pmm = phase * pmm * sqr(2*lmax_comp+1) &\n / sqr(2*lmax_comp) * rescalem\n case(2)\n pmm = phase * pmm / sqr(2*lmax_comp) * rescalem\n case(3)\n pmm = phase * pmm * (2*lmax_comp-1) * rescalem\n end select\n\n cilm(1:2,lmax_comp+1,lmax_comp+1) = &\n cilm(1:2,lmax_comp+1,lmax_comp+1) &\n + pmm * fcoef1(1:2,lmax_comp+1)\n\n end if\n\n call fftw_destroy_plan(plan)\n call fftw_destroy_plan(plans)\n\n !--------------------------------------------------------------------------\n !\n ! Divide by integral of Ylm*Ylm \n !\n !--------------------------------------------------------------------------\n select case(lnorm)\n case(1)\n do l = 0, lmax_comp, 1\n cilm(1:2,l+1, 1:l+1) = cilm(1:2,l+1, 1:l+1) / (4*pi)\n end do\n\n case (2)\n do l = 0, lmax_comp, 1\n cilm(1:2,l+1, 1:l+1) = cilm(1:2,l+1, 1:l+1) * (2*l+1) / (4*pi)\n end do\n\n case(3)\n do l = 0, lmax_comp, 1\n prod = 4 * pi / dble(2*l+1)\n cilm(1,l+1,1) = cilm(1,l+1,1) / prod\n prod = prod / 2.0_dp\n\n do m = 1, l-1, 1\n prod = prod * (l+m) * (l-m+1)\n cilm(1:2,l+1,m+1) = cilm(1:2,l+1,m+1) / prod\n\n end do\n\n !do m=l case\n if (l /= 0) cilm(1:2,l+1,l+1) = cilm(1:2,l+1, l+1) / (prod*2*l)\n\n end do\n\n end select\n\nend subroutine SHExpandDH\n", "meta": {"hexsha": "46d01a37280163ed77c2984b8892408dd7a643e0", "size": 23528, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/SHExpandDH.f95", "max_stars_repo_name": "mjc87/SHTOOLS", "max_stars_repo_head_hexsha": "8d83c42d1313d5624c4db8c2e57300c5d819834e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 251, "max_stars_repo_stars_event_min_datetime": "2015-01-27T12:58:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T17:19:36.000Z", "max_issues_repo_path": "src/SHExpandDH.f95", "max_issues_repo_name": "mjc87/SHTOOLS", "max_issues_repo_head_hexsha": "8d83c42d1313d5624c4db8c2e57300c5d819834e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 193, "max_issues_repo_issues_event_min_datetime": "2015-03-11T06:21:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T14:05:45.000Z", "max_forks_repo_path": "src/SHExpandDH.f95", "max_forks_repo_name": "mreineck/SHTOOLS", "max_forks_repo_head_hexsha": "fec33f203ee0b47008fd69d4080304d6ebd272e7", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 100, "max_forks_repo_forks_event_min_datetime": "2015-04-03T07:11:05.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-23T23:46:33.000Z", "avg_line_length": 33.3730496454, "max_line_length": 79, "alphanum_fraction": 0.4414739884, "num_tokens": 6931, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797100118214, "lm_q2_score": 0.7634837527911057, "lm_q1q2_score": 0.6956709044669368}} {"text": " SUBROUTINE slGEOC (P, H, R, Z)\n*+\n* - - - - -\n* G E O C\n* - - - - -\n*\n* Convert geodetic position to geocentric (double precision)\n*\n* Given:\n* P dp latitude (geodetic, radians)\n* H dp height above reference spheroid (geodetic, metres)\n*\n* Returned:\n* R dp distance from Earth axis (AU)\n* Z dp distance from plane of Earth equator (AU)\n*\n* Notes:\n*\n* 1 Geocentric latitude can be obtained by evaluating ATAN2(Z,R).\n*\n* 2 IAU 1976 constants are used.\n*\n* Reference:\n*\n* Green,R.M., Spherical Astronomy, CUP 1985, p98.\n*\n* Last revision: 22 July 2004\n*\n* Copyright P.T.Wallace. All rights reserved.\n*\n* License:\n* This program is free software; you can redistribute it and/or modify\n* it under the terms of the GNU General Public License as published by\n* the Free Software Foundation; either version 2 of the License, or\n* (at your option) any later version.\n*\n* This program is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU General Public License for more details.\n*\n* You should have received a copy of the GNU General Public License\n* along with this program (see SLA_CONDITIONS); if not, write to the\n* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,\n* Boston, MA 02110-1301 USA\n*\n* Copyright (C) 1995 Association of Universities for Research in Astronomy Inc.\n*-\n\n IMPLICIT NONE\n\n DOUBLE PRECISION P,H,R,Z\n\n* Earth equatorial radius (metres)\n DOUBLE PRECISION A0\n PARAMETER (A0=6378140D0)\n\n* Reference spheroid flattening factor and useful function\n DOUBLE PRECISION F,B\n PARAMETER (F=1D0/298.257D0,B=(1D0-F)**2)\n\n* Astronomical unit in metres\n DOUBLE PRECISION AU\n PARAMETER (AU=1.49597870D11)\n\n DOUBLE PRECISION SP,CP,C,S\n\n\n\n* Geodetic to geocentric conversion\n SP = SIN(P)\n CP = COS(P)\n C = 1D0/SQRT(CP*CP+B*SP*SP)\n S = B*C\n R = (A0*C+H)*CP/AU\n Z = (A0*S+H)*SP/AU\n\n END\n", "meta": {"hexsha": "470a19583265c4058ec69f9e6967163fd12ea4bc", "size": 2140, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iraf.v2161/math/slalib/geoc.f", "max_stars_repo_name": "ysBach/irafdocgen", "max_stars_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:19:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T16:48:42.000Z", "max_issues_repo_path": "math/slalib/geoc.f", "max_issues_repo_name": "kirxkirx/iraf", "max_issues_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-30T13:48:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-02T19:40:25.000Z", "max_forks_repo_path": "math/slalib/geoc.f", "max_forks_repo_name": "kirxkirx/iraf", "max_forks_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.0886075949, "max_line_length": 80, "alphanum_fraction": 0.6490654206, "num_tokens": 637, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797003640646, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6956709020046299}} {"text": "module mod_fillps\n use mod_types\n implicit none\n private\n public fillps\n contains\n subroutine fillps(lo,hi,dxf,dyf,dzf,dt,up,vp,wp,p)\n !\n ! fill the right-hand side of the Poisson equation for the correction pressure.\n !\n ! the discrete divergence is:\n !\n ! w(i,j,k)-w(i,j,k-1) v(i,j,k)-v(i,j-1,k) u(i,j,k)-u(i-1,j,k)\n ! ------------------- + ------------------- + ------------------- = div\n ! dz dy dx\n !\n implicit none\n integer , intent(in ), dimension(3) :: lo,hi\n real(rp), intent(in ), dimension(lo(1)-1:) :: dxf\n real(rp), intent(in ), dimension(lo(2)-1:) :: dyf\n real(rp), intent(in ), dimension(lo(3)-1:) :: dzf\n real(rp), intent(in ) :: dt\n real(rp), intent(in ), dimension(lo(1)-1:,lo(2)-1:,lo(3)-1:) :: up,vp,wp\n real(rp), intent(out), dimension(lo(1)-1:,lo(2)-1:,lo(3)-1:) :: p\n integer :: i,j,k\n !\n !$OMP PARALLEL DO DEFAULT(none) &\n !$OMP SHARED(lo,hi,p,up,vp,wp,dt,dxf,dyf,dzf) &\n !$OMP PRIVATE(i,j,k)\n do k=lo(3),hi(3)\n do j=lo(2),hi(2)\n do i=lo(1),hi(1)\n p(i,j,k) = ( &\n (wp(i,j,k)-wp(i,j,k-1))/dzf(k) + &\n (vp(i,j,k)-vp(i,j-1,k))/dyf(j) + &\n (up(i,j,k)-up(i-1,j,k))/dxf(i) &\n )/dt\n enddo\n enddo\n enddo\n !$OMP END PARALLEL DO\n end subroutine fillps\nend module mod_fillps\n", "meta": {"hexsha": "b40434df056bbee70a26ca8d348c69dc9b6554de", "size": 1442, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fillps.f90", "max_stars_repo_name": "nazmas/SNaC", "max_stars_repo_head_hexsha": "e928adc142df5bbe1a7941907c35add6ea6f1ff0", "max_stars_repo_licenses": ["MIT"], "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/fillps.f90", "max_issues_repo_name": "nazmas/SNaC", "max_issues_repo_head_hexsha": "e928adc142df5bbe1a7941907c35add6ea6f1ff0", "max_issues_repo_licenses": ["MIT"], "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/fillps.f90", "max_forks_repo_name": "nazmas/SNaC", "max_forks_repo_head_hexsha": "e928adc142df5bbe1a7941907c35add6ea6f1ff0", "max_forks_repo_licenses": ["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.7727272727, "max_line_length": 84, "alphanum_fraction": 0.4701803051, "num_tokens": 488, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797003640646, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6956709020046299}} {"text": "! Example of specifications with combined regions\n!\n! Regions can be combined with intersection (*) or union (+).\nprogram combinedregion\nimplicit none\n\ninteger i\nparameter (n=10)\nreal a(0:n,0:n)\nreal b(0:n,0:n)\n\n! This is a nine-point stencil\ndo i=1, n\n do j=1, n\n x = a(i, j) + a(i-1, j) + a(i+1, j)\n y = a(i, j-1) + a(i-1, j-1) + a(i+1, j-1)\n z = a(i, j+1) + a(i-1, j+1) + a(i+1, j+1)\n != stencil readOnce, centered(depth=1, dim=1)*centered(depth=1, dim=2) :: a\n b(i, j) = (x + y + z) / 9.0\n end do\nend do\n\n! This is a five point stencil\ndo i=1, n\n do j=1, n\n != stencil readOnce, pointed(dim=1)*centered(depth=1, dim=2) + centered(depth=1, dim=1)*pointed(dim=2) :: a\n b(i,j) = -4*a(i,j) + a(i+1, j) + a(i-1,j) + a(i,j-1) + a(i,j+1)\n end do\nend do\n\nend\n", "meta": {"hexsha": "42c36dd930f5105df9700cd4ce9b0112acbd1801", "size": 762, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "samples/stencils/expected/combined-region.f90", "max_stars_repo_name": "raehik/camfort", "max_stars_repo_head_hexsha": "2f5ac9a478116ae8c7aa2a5e079b81aa58988e45", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 90, "max_stars_repo_stars_event_min_datetime": "2016-06-02T15:37:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-30T20:10:14.000Z", "max_issues_repo_path": "samples/stencils/expected/combined-region.f90", "max_issues_repo_name": "apthorpe/camfort", "max_issues_repo_head_hexsha": "1e307ae972b2fe6f63af6d3b0a3d106eec77e8a8", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 124, "max_issues_repo_issues_event_min_datetime": "2016-05-25T13:21:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-10T14:26:03.000Z", "max_forks_repo_path": "samples/stencils/expected/combined-region.f90", "max_forks_repo_name": "raehik/camfort", "max_forks_repo_head_hexsha": "2f5ac9a478116ae8c7aa2a5e079b81aa58988e45", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 16, "max_forks_repo_forks_event_min_datetime": "2016-06-02T14:51:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-14T15:59:33.000Z", "avg_line_length": 23.8125, "max_line_length": 109, "alphanum_fraction": 0.5826771654, "num_tokens": 326, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111796979521252, "lm_q2_score": 0.7634837527911056, "lm_q1q2_score": 0.6956708952595546}} {"text": "! Program to test the DIM intrinsic\nprogram intrinsic_dim\n implicit none\n integer i, j\n real(kind=4) :: r, s\n real(kind=8) :: p, q\n\n i = 1\n j = 4\n if (dim (i, j) .ne. 0) call abort\n if (dim (j, i) .ne. 3) call abort\n r = 1.0\n s = 4.0\n if (dim (r, s) .ne. 0.0) call abort\n if (dim (s, r) .ne. 3.0) call abort\n p = 1.0\n q = 4.0\n if (dim (p, q) .ne. 0.0) call abort\n if (dim (q, p) .ne. 3.0) call abort\nend program\n", "meta": {"hexsha": "4753de3606d21a91a8a22752575d3130b3de0060", "size": 444, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_dim.f90", "max_stars_repo_name": "best08618/asylo", "max_stars_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-05-02T17:34:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-17T10:15:18.000Z", "max_issues_repo_path": "llvm-gcc-4.2-2.9/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_dim.f90", "max_issues_repo_name": "vidkidz/crossbridge", "max_issues_repo_head_hexsha": "ba0bf94aee0ce6cf7eb5be882382e52bc57ba396", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "llvm-gcc-4.2-2.9/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_dim.f90", "max_forks_repo_name": "vidkidz/crossbridge", "max_forks_repo_head_hexsha": "ba0bf94aee0ce6cf7eb5be882382e52bc57ba396", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-27T00:22:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-01T09:41:02.000Z", "avg_line_length": 21.1428571429, "max_line_length": 38, "alphanum_fraction": 0.5292792793, "num_tokens": 207, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267830311354, "lm_q2_score": 0.8006920092299293, "lm_q1q2_score": 0.6956626625779756}} {"text": "module module_privs\n\n implicit none\n\n integer, parameter, private :: sp = selected_real_kind(6, 37)\n integer, parameter, private :: dp = selected_real_kind(15, 307)\n integer, parameter, private :: qp = selected_real_kind(33, 4931)\n\n real(kind=sp), protected :: pi_sigl = &\n 3.141592653589793238462643383279502884197169399375105820974944592307&\n &8164062862089986280348253421170679821480865132823066470938446_sp\n real(kind=dp), protected :: pi_dble = &\n 3.141592653589793238462643383279502884197169399375105820974944592307&\n &8164062862089986280348253421170679821480865132823066470938446_dp\n real(kind=qp), protected :: pi_quad = &\n 3.141592653589793238462643383279502884197169399375105820974944592307&\n &8164062862089986280348253421170679821480865132823066470938446_qp\n real :: x = 50.25\n real, protected :: x_prot = 512.125\n real :: y = 3.0\n\ncontains\n\n subroutine show_pi_3()\n print *, 'PI with 6 digits', kind(pi_sigl), pi_sigl\n print *, 'PI with 15 digits', kind(pi_dble), pi_dble\n print *, 'PI with 33 digits', kind(pi_quad), pi_quad\n end subroutine show_pi_3\n\nend module module_privs\n\nprogram main\n\n use module_privs, my_y => y\n\n implicit none\n\n call show_pi_3()\n\n print *, 'x from inside the module : ', x\n x = 25.50\n print *, 'x changed outside module : ', x\n\n print *, 'x_prot:', x_prot\n ! This variable is protected and cannot be changed\n ! Uncommenting the line below will not compile\n !x_prot = 125.512\n print *, 'x_prot:', x_prot\n\n ! The variable 'y' is not visible as it was renamed\n !print *, y\n print *, 'my_y:', my_y\n\nend program main\n\n", "meta": {"hexsha": "b7edf51d9899933e22ba419251e47b4f2c37603b", "size": 1632, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "files/advanced/example_17.f90", "max_stars_repo_name": "WVUHPC/Modern-Fortran", "max_stars_repo_head_hexsha": "97c4db834d4e6ca43802318e4dc63ce4faa641aa", "max_stars_repo_licenses": ["CC-BY-4.0"], "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": "files/advanced/example_17.f90", "max_issues_repo_name": "WVUHPC/Modern-Fortran", "max_issues_repo_head_hexsha": "97c4db834d4e6ca43802318e4dc63ce4faa641aa", "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": "files/advanced/example_17.f90", "max_forks_repo_name": "WVUHPC/Modern-Fortran", "max_forks_repo_head_hexsha": "97c4db834d4e6ca43802318e4dc63ce4faa641aa", "max_forks_repo_licenses": ["CC-BY-4.0"], "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": 29.1428571429, "max_line_length": 72, "alphanum_fraction": 0.7199754902, "num_tokens": 515, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.8688267745399466, "lm_q1q2_score": 0.6956626495809602}} {"text": "!##############################################################################\n!# ****************************************************************************\n!# user_flows \n!# ****************************************************************************\n!#\n!# \n!# Defines a couple of user-defined, analytically given flows and functions.\n!# \n!##############################################################################\n\nmodule user_flows\n\nuse fsystem\n\nimplicit none\n\ncontains\n\n ! ***************************************************************************\n ! Reference functions, Heat equation\n ! ***************************************************************************\n ! ***************************************************************************\n ! Heat equation, function set 1.\n ! y = t^2 x1\n ! ***************************************************************************\n\n elemental real(DP) function fct_heatY1 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_heatY1 = dtime**2 * dx\n end function\n\n elemental real(DP) function fct_heatLambda1 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_heatLambda1 = dalpha * (- 2.0_DP*dtime * dx) + 2*dalpha*dx\n end function\n \n elemental real(DP) function fct_heatF1 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_heatF1 = 2.0_DP*dtime*dx - 2.0_DP*dx*(dtime-1.0_DP)\n end function\n \n elemental real(DP) function fct_heatZ1 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_heatZ1 = -2.0_DP*dalpha*dx + dtime**2*dx\n end function\n\n ! ***************************************************************************\n ! Heat equation, function set 2\n ! y = t^2 (1-t)^2 x1\n ! l = a t (1-t) x1\n ! No factor 4 due to inconsistent terminal condition.\n ! ***************************************************************************\n \n elemental real(DP) function fct_heatY2 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_heatY2 = dtime**2 * (1.0_DP-dtime)**2 * dx\n end function\n\n elemental real(DP) function fct_heatLambda2 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_heatLambda2 = dalpha * dtime * (1.0_DP-dtime) * dx\n end function\n\n elemental real(DP) function fct_heatF2 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_heatF2 = 3.0_DP*dtime*dx-7.0_DP*dtime**2*dx+4*dtime**3*dx\n end function\n\n elemental real(DP) function fct_heatZ2 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_heatZ2 = (1.0_DP-dtime)*dx-dtime*dx+dtime**2*(1.0_DP-dtime)**2*dx\n end function\n\n ! ***************************************************************************\n ! Heat equation, function set 3\n ! y = t^2 (1-t)^2 x1\n ! l = a t (1-t)^2 x1\n ! Gives factor 4 with CN due to proper terminal condition.\n ! ***************************************************************************\n\n elemental real(DP) function fct_heatY3 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_heatY3 = dtime**2 * (1.0_DP-dtime)**2 * dx\n end function\n\n elemental real(DP) function fct_heatLambda3 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_heatLambda3 = dalpha * dtime * (1.0_DP-dtime)**2 * dx\n end function\n\n elemental real(DP) function fct_heatF3 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_heatF3 = &\n 3.0_DP*dtime*dx-8.0_DP*dtime**2*dx+5*dtime**3*dx\n end function\n\n elemental real(DP) function fct_heatZ3 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_heatZ3 = &\n (1.0_DP-dtime)**2*dx-2.0_DP*dtime*(1.0_DP-dtime)*dx+&\n dtime**2*(1.0_DP-dtime)**2*dx\n end function\n \n ! ***************************************************************************\n ! Heat equation, function set 4\n ! y = t^2 (1-t)^2 x1\n ! ***************************************************************************\n \n elemental real(DP) function fct_heatY4 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_heatY4 = dtime**2 * (1.0_DP-dtime)**2 * dx\n end function\n\n elemental real(DP) function fct_heatLambda4 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_heatLambda4 = dalpha * (-2.0_DP*dtime*(1.0_DP-dtime)**2*dx + 2.0_DP*dtime**2*(1.0_DP-dtime)*dx)\n end function\n \n elemental real(DP) function fct_heatF4 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_heatF4 = 0.0_DP\n end function\n\n elemental real(DP) function fct_heatZ4 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_heatZ4 = &\n - dalpha*2.0_DP*(1-dtime)**2*dx + dalpha*8.0_DP*dtime*(1-dtime)*dx &\n - dalpha*2.0_DP*dtime**2*dx + dtime**2*(1.0_DP-dtime)**2*dx\n end function\n\n ! ***************************************************************************\n ! Heat equation, function set 5.\n ! y = t x1\n ! l = (1-t) x1\n ! Does not produce error=0, only at the beginning.\n ! ***************************************************************************\n\n elemental real(DP) function fct_heatY5 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_heatY5 = dtime * dx\n end function\n\n elemental real(DP) function fct_heatLambda5 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_heatLambda5 = (1.0_DP-dtime)*dx\n end function\n \n elemental real(DP) function fct_heatF5 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_heatF5 = -(dtime-dalpha-1.0_DP)*dx/dalpha\n end function\n \n elemental real(DP) function fct_heatZ5 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_heatZ5 = (dtime-1.0_DP)*dx\n end function\n\n ! ***************************************************************************\n ! Heat equation, function set 6.\n ! y = t^2 x1\n ! l = (1-t)^2 x1\n ! ***************************************************************************\n\n elemental real(DP) function fct_heatY6 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_heatY6 = dtime**2 * dx\n end function\n\n elemental real(DP) function fct_heatLambda6 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_heatLambda6 = (1.0_DP-dtime)**2*dx\n end function\n \n elemental real(DP) function fct_heatF6 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_heatF6 = dx*(2.0_DP*dtime*dalpha+1.0_DP-2.0_DP*dtime+dtime**2)/dalpha\n end function\n \n elemental real(DP) function fct_heatZ6 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_heatZ6 = dtime**2*dx-2.0_DP*(1.0_DP-dtime)*dx\n end function\n\n ! ***************************************************************************\n ! Reference functions, Stokes equation\n ! ***************************************************************************\n ! ***************************************************************************\n ! Stokes, function set 1.\n ! y = t^2 ( x1 , -x2 , 0)\n ! ***************************************************************************\n\n elemental real(DP) function fct_stokesY1_x (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesY1_x = dtime**2 * dx\n end function\n\n elemental real(DP) function fct_stokesY1_y (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesY1_y = - dtime**2 * dy\n end function\n\n elemental real(DP) function fct_stokesP1 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesP1 = 0.0_DP\n end function\n\n elemental real(DP) function fct_stokesLambda1_x (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesLambda1_x = dalpha * (-2.0_DP*dtime*dx)\n end function\n\n elemental real(DP) function fct_stokesLambda1_y (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesLambda1_y = dalpha * (2.0_DP*dtime*dy)\n end function\n\n elemental real(DP) function fct_stokesXi1 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesXi1 = 0.0_DP\n end function\n\n elemental real(DP) function fct_stokesZ1_x (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesZ1_x = -2.0_DP*dx + dtime**2*dx\n end function\n\n elemental real(DP) function fct_stokesZ1_y (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesZ1_y = 2.0_DP*dy - dtime**2*dy\n end function\n\n ! ***************************************************************************\n ! Stokes, function set 2.\n ! y = t^2 (1-t)^3 ( x2(1-x2) , 0 , 0 )\n ! ***************************************************************************\n\n elemental real(DP) function fct_stokesY2_x (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesY2_x = dy * (-1 + dy) * dtime ** 2 * (-1 + dtime) ** 3\n end function\n\n elemental real(DP) function fct_stokesY2_y (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesY2_y = 0.0_DP\n end function\n\n elemental real(DP) function fct_stokesP2 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesP2 = 0.0_DP\n end function\n\n elemental real(DP) function fct_stokesLambda2_x (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesLambda2_x = &\n - dalpha * dtime * (-1 + dtime) ** 2 * (2 * dtime - 2 * dtime ** 2 &\n + 2 * dy - 5 * dy * dtime - 2 * dy ** 2 + 5 * dy ** 2 * dtime)\n end function\n\n elemental real(DP) function fct_stokesLambda2_y (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesLambda2_y = 0.0_DP\n end function\n\n elemental real(DP) function fct_stokesXi2 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesXi2 = 0.0_DP\n end function\n\n elemental real(DP) function fct_stokesZ2_x (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesZ2_x = &\n dy * dtime ** 2 - 3 * dy * dtime ** 3 + 3 * dy * dtime ** 4 &\n - dy * dtime ** 5 - dy ** 2 * dtime ** 2 + 3 * dy ** 2 * dtime ** 3 &\n - 3 * dy ** 2 * dtime ** 4 + dy ** 2 * dtime ** 5 - 2 * dalpha * dy &\n - 0.18D2 * dalpha * dy ** 2 * dtime + 2 * dalpha * dy ** 2 &\n + 0.18D2 * dalpha * dy * dtime - 0.36D2 * dalpha * dy * dtime ** 2 &\n + 0.20D2 * dalpha * dy * dtime ** 3 + 0.36D2 * dalpha * dy ** 2 * dtime ** 2 &\n - 0.20D2 * dalpha * dy ** 2 * dtime ** 3\n end function\n\n elemental real(DP) function fct_stokesZ2_y (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesZ2_y = 0.0_DP\n end function\n\n ! ***************************************************************************\n ! Stokes, function set 3.\n ! y = t^2 (x1^2 x2 , -x1 x2^2 , 0)\n ! ***************************************************************************\n\n elemental real(DP) function fct_stokesY3_x (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesY3_x = dtime**2 * dx**2 * dy\n end function\n\n elemental real(DP) function fct_stokesY3_y (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesY3_y = - dtime**2 * dx**2 * dy\n end function\n\n elemental real(DP) function fct_stokesP3 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesP3 = 0.0_DP\n end function\n\n elemental real(DP) function fct_stokesLambda3_x (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesLambda3_x = -dalpha*(-2*dy*dtime**2*(1-dtime)**2 &\n +2*dx**2*dy*dtime*(1-dtime)**2 &\n -2*dx**2*dy*dtime**2*(1-dtime) )\n end function\n\n elemental real(DP) function fct_stokesLambda3_y (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesLambda3_y = -dalpha*(-2*dx*dtime**2*(1-dtime)**2 &\n +2*dx*dy**2*dtime*(1-dtime)**2 &\n -2*dx*dy**2*dtime**2*(1-dtime) )\n end function\n\n elemental real(DP) function fct_stokesXi3 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesXi3 = 0.0_DP\n end function\n\n elemental real(DP) function fct_stokesZ3_x (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesZ3_x = (dx**2*dy*dtime**2*(-1+dtime)**2) &\n - dalpha*(-4*dy*dtime+12*dy*dtime**2 &\n -8*dy*dtime**3+2*dx**2*dy &\n -12*dx**2*dy*dtime+12*dx**2*dy*dtime**2)\n end function\n\n elemental real(DP) function fct_stokesZ3_y (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesZ3_y = (dx*dy**2*dtime**2*(-1+dtime)**2) &\n - dalpha*(-4*dx*dtime+12*dx*dtime**2 &\n -8*dx*dtime**3+2*dx*dy**2 &\n -12*dx*dy**2*dtime+12*dx*dy**2*dtime**2)\n end function\n\n ! ***************************************************************************\n ! Stokes, function set 4.\n ! y = t^2 (1-t)^2 (x1^3 x2^2 , -x1^2 x2^3 , 0)\n ! ***************************************************************************\n\n elemental real(DP) function fct_stokesY4_x (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesY4_x = dx ** 3 * dy ** 2 * dtime ** 2 * (-1.0_DP + dtime) ** 2\n end function\n\n elemental real(DP) function fct_stokesY4_y (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesY4_y = -dx ** 2 * dy ** 3 * dtime ** 2 * (-1.0_DP + dtime) ** 2\n end function\n\n elemental real(DP) function fct_stokesP4 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesP4 = 0.0_DP\n end function\n\n elemental real(DP) function fct_stokesLambda4_x (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesLambda4_x = -2 * dalpha * dx * dtime * (-1 + dtime) * &\n (3 * dy ** 2 * dtime - 3 * dy ** 2 * dtime ** 2 + dx ** 2 * dtime &\n - dx ** 2 * dtime ** 2 - dx ** 2 * dy ** 2 + 2 * dx ** 2 * dy ** 2 * dtime)\n end function\n\n elemental real(DP) function fct_stokesLambda4_y (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesLambda4_y = 2 * dalpha * dy * dtime * (-1 + dtime) * &\n (dy ** 2 * dtime - dy ** 2 * dtime ** 2 + 3 * dx ** 2 * dtime &\n - 3 * dx ** 2 * dtime ** 2 - dx ** 2 * dy ** 2 &\n + 2 * dx ** 2 * dy ** 2 * dtime)\n end function\n\n elemental real(DP) function fct_stokesXi4 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesXi4 = 0.0_DP\n end function\n\n elemental real(DP) function fct_stokesZ4_x (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesZ4_x = &\n -2*dalpha*dx**3*dy**2+12*dalpha*dx**3*dy**2*dtime-12*dalpha*dx**3*dy**2*dtime**2+dx**3*dy**2*dtime**2 &\n -2*dx**3*dy**2*dtime**3+dx**3*dy**2*dtime**4+24*dalpha*dx*dtime**2-48*dalpha*dx*dtime**3+24*dalpha*dx*dtime**4\n! fct_stokesZ4_x = 6 * dx * dy ** 2 * dtime ** 2 &\n! - 0.12D2 * dx * dy ** 2 * dtime ** 3 &\n! + 6 * dx * dy ** 2 * dtime ** 4 + 2 * dx ** 3 * dtime ** 2 &\n! - 4 * dx ** 3 * dtime ** 3 + 2 * dx ** 3 * dtime ** 4 &\n! + dx ** 3 * dy ** 2 * dtime ** 2 - 2 * dx ** 3 * dy ** 2 * dtime ** 3 &\n! + dx ** 3 * dy ** 2 * dtime ** 4 + 0.12D2 * dalpha * dx * dy ** 2 * dtime &\n! - 0.36D2 * dalpha * dx * dy ** 2 * dtime ** 2 &\n! + 0.24D2 * dalpha * dx * dy ** 2 * dtime ** 3 &\n! + 4 * dalpha * dx ** 3 * dtime &\n! - 0.12D2 * dalpha * dx ** 3 * dtime ** 2 &\n! + 8 * dalpha * dx ** 3 * dtime ** 3 &\n! - 2 * dalpha * dx ** 3 * dy ** 2 &\n! + 0.12D2 * dalpha * dx ** 3 * dy ** 2 * dtime &\n! - 0.12D2 * dalpha * dx ** 3 * dy ** 2 * dtime ** 2\n end function\n\n elemental real(DP) function fct_stokesZ4_y (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesZ4_y = &\n 2*dalpha*dy**3*dx**2-12*dalpha*dy**3*dx**2*dtime+12*dalpha*dy**3*dx**2*dtime**2-dx**2*dy**3*dtime**2 &\n +2*dx**2*dy**3*dtime**3-dx**2*dy**3*dtime**4-24*dalpha*dy*dtime**2+48*dalpha*dy*dtime**3-24*dalpha*dy*dtime**4\n! fct_stokesZ4_y = -2 * dy ** 3 * dtime ** 2 + 4 * dy ** 3 * dtime ** 3 &\n! - 2 * dy ** 3 * dtime ** 4 - 6 * dx ** 2 * dy * dtime ** 2 &\n! + 0.12D2 * dx ** 2 * dy * dtime ** 3 - 6 * dx ** 2 * dy * dtime ** 4 &\n! - dx ** 2 * dy ** 3 * dtime ** 2 + 2 * dx ** 2 * dy ** 3 * dtime ** 3 &\n! - dx ** 2 * dy ** 3 * dtime ** 4 - 4 * dalpha * dy ** 3 * dtime &\n! + 0.12D2 * dalpha * dy ** 3 * dtime ** 2 &\n! - 8 * dalpha * dy ** 3 * dtime ** 3 &\n! - 0.12D2 * dalpha * dx ** 2 * dy * dtime &\n! + 0.36D2 * dalpha * dx ** 2 * dy * dtime ** 2 &\n! - 0.24D2 * dalpha * dx ** 2 * dy * dtime ** 3 &\n! + 2 * dalpha * dx ** 2 * dy ** 3 &\n! - 0.12D2 * dalpha * dx ** 2 * dy ** 3 * dtime &\n! + 0.12D2 * dalpha * dx ** 2 * dy ** 3 * dtime ** 2\n end function\n \n ! ***************************************************************************\n ! Stokes, function set 5.\n ! y = t ( x2(1-x2) , 0 , 0 )\n ! No coupling between primal and dual!\n ! EXAMPLE DOES NOT WORK, NOT DIVERGENCE FREE WHEN BEING TIME DEPENDENT!\n ! ***************************************************************************\n\n elemental real(DP) function fct_stokesY5_x (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesY5_x = dtime * dy*(1.0_DP-dy)\n end function\n\n elemental real(DP) function fct_stokesY5_y (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesY5_y = 0.0_DP\n end function\n\n elemental real(DP) function fct_stokesP5 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesP5 = dtime*(1.0_DP-dx) !0.0_DP\n end function\n\n elemental real(DP) function fct_stokesLambda5_x (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesLambda5_x = 0.0_DP !-dalpha*( &\n! 2.0_DP*dtime**2*(1.0_DP-dtime)**2 &\n! + 2.0_DP*dy*(1.0_DP-dy)*dtime*(1.0_DP-dtime)**2 &\n! - 2.0_DP*dy*(1.0_DP-dy)*dtime**2*(1.0_DP-dtime))\n end function\n\n elemental real(DP) function fct_stokesLambda5_y (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesLambda5_y = 0.0_DP\n end function\n\n elemental real(DP) function fct_stokesXi5 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesXi5 = 0.0_DP\n end function\n\n elemental real(DP) function fct_stokesZ5_x (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesZ5_x = 0.0_DP !- dy*(-1.0_DP+dy)*dtime**2*(-1.0_DP+dtime)**2 &\n! - dalpha*(4.0_DP*dtime-12.0_DP*dtime**2+8.0_DP*dtime**3+2.0_DP*dy &\n! -12.0_DP*dy*dtime+12.0_DP*dy*dtime**2 &\n! -2.0_DP*dy**2+12.0_DP*dy**2*dtime &\n! -12.0_DP*dy**2*dtime**2)\n end function\n\n elemental real(DP) function fct_stokesZ5_y (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesZ5_y = 0.0_DP\n end function\n\n ! ***************************************************************************\n ! Stokes, function set 6.\n ! y = t ( x2(1-x2) , 0 , 0 )\n ! lambda = (1-t) ( x2(1-x2) , 0 , 0 )\n ! ***************************************************************************\n\n elemental real(DP) function fct_stokesY6_x (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesY6_x = dtime * dy*(1.0_DP-dy)\n end function\n\n elemental real(DP) function fct_stokesY6_y (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesY6_y = 0.0_DP\n end function\n\n elemental real(DP) function fct_stokesP6 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesP6 = 0.0_DP\n end function\n\n elemental real(DP) function fct_stokesLambda6_x (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesLambda6_x = (1.0_DP-dtime) * dy*(1.0_DP-dy)\n end function\n\n elemental real(DP) function fct_stokesLambda6_y (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesLambda6_y = 0.0_DP\n end function\n\n elemental real(DP) function fct_stokesXi6 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesXi6 = 0.0_DP\n end function\n\n elemental real(DP) function fct_stokesZ6_x (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesZ6_x = -0.2D1 + 0.2D1 * dtime - dy + dy ** 2 + dy * dtime &\n - dy ** 2 * dtime\n end function\n\n elemental real(DP) function fct_stokesZ6_y (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesZ6_y = 0.0_DP\n end function\n\n elemental real(DP) function fct_stokesF6_x (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesF6_x = (0.2D1 * dtime * dalpha + dy * dalpha - dy ** 2 * dalpha + dy &\n - dy * dtime - dy ** 2 + dy ** 2 * dtime) / dalpha\n end function\n\n elemental real(DP) function fct_stokesF6_y (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesF6_y = 0.0_DP\n end function\n\n ! ***************************************************************************\n ! Stokes, function set 7.\n ! y = t^2 ( x2(1-x2) , 0 , 0 )\n ! lambda = (1-t)^2 ( x2(1-x2) , 0 , 0 )\n ! ***************************************************************************\n\n elemental real(DP) function fct_stokesY7_x (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesY7_x = dtime**2 * dy*(1.0_DP-dy)\n end function\n\n elemental real(DP) function fct_stokesY7_y (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesY7_y = 0.0_DP\n end function\n\n elemental real(DP) function fct_stokesP7 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesP7 = 0.0_DP\n end function\n\n elemental real(DP) function fct_stokesLambda7_x (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesLambda7_x = (1.0_DP-dtime)**2 * dy*(1.0_DP-dy)\n end function\n\n elemental real(DP) function fct_stokesLambda7_y (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesLambda7_y = 0.0_DP\n end function\n\n elemental real(DP) function fct_stokesXi7 (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesXi7 = 0.0_DP\n end function\n\n elemental real(DP) function fct_stokesZ7_x (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesZ7_x = -0.2D1 + 0.4D1 * dtime - 0.2D1 * dtime ** 2 &\n - 0.2D1 * dy + 0.2D1 * dy * dtime + 0.2D1 * dy ** 2 &\n - 0.2D1 * dy ** 2 * dtime + dy * dtime ** 2 - dy ** 2 * dtime ** 2\n end function\n\n elemental real(DP) function fct_stokesZ7_y (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesZ7_y = 0.0_DP\n end function\n\n elemental real(DP) function fct_stokesF7_x (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesF7_x = -(-0.2D1 * dtime ** 2 * dalpha &\n - 0.2D1 * dy * dtime * dalpha + 0.2D1 * dy ** 2 * dtime * dalpha &\n - dy + 0.2D1 * dy * dtime - dy * dtime ** 2 + dy ** 2 &\n - 0.2D1 * dy ** 2 * dtime + dy ** 2 * dtime ** 2) / dalpha\n end function\n\n elemental real(DP) function fct_stokesF7_y (dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_stokesF7_y = 0.0_DP\n end function\n\n ! ***************************************************************************\n ! Stokes, function set 8\n ! w = sin (Pi/2 x1) sin (Pi x2)\n ! y = sin (Pi t ) w\n ! lambda = sin (Pi t ) w\n ! ***************************************************************************\n\n elemental real(DP) function fct_eigSt8(dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_eigSt8 = sin(0.5_DP*SYS_PI*dx) * sin(SYS_PI*dy)\n end function\n\n elemental real(DP) function fct_stokesY8_x (dx,dy,dtime,dtimeMin,dtimeMax,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dtimemin,dtimemax,dalpha\n fct_stokesY8_x = fct_eigSt8(dx,dy,dtime,dalpha)*sin(0.5_DP*SYS_PI*dtime)\n end function\n\n elemental real(DP) function fct_stokesY8_y (dx,dy,dtime,dtimeMin,dtimeMax,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dtimemin,dtimemax,dalpha\n fct_stokesY8_y = fct_eigSt8(dx,dy,dtime,dalpha)*sin(0.5_DP*SYS_PI*dtime)\n end function\n\n elemental real(DP) function fct_stokesP8 (dx,dy,dtime,dtimeMin,dtimeMax,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dtimemin,dtimemax,dalpha\n fct_stokesP8 = 0.0_DP\n end function\n\n elemental real(DP) function fct_stokesLambda8_x (dx,dy,dtime,dtimeMin,dtimeMax,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dtimemin,dtimemax,dalpha\n fct_stokesLambda8_x = fct_eigSt8(dx,dy,dtime,dalpha)*(sin(0.5_DP*SYS_PI*dtime)-1.0_DP)\n end function\n\n elemental real(DP) function fct_stokesLambda8_y (dx,dy,dtime,dtimeMin,dtimeMax,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dtimemin,dtimemax,dalpha\n fct_stokesLambda8_y = fct_eigSt8(dx,dy,dtime,dalpha)*(sin(0.5_DP*SYS_PI*dtime)-1.0_DP)\n end function\n\n elemental real(DP) function fct_stokesXi8 (dx,dy,dtime,dtimeMin,dtimeMax,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dtimemin,dtimemax,dalpha\n fct_stokesXi8 = 0.0_DP\n end function\n\n elemental real(DP) function fct_stokesZ8_x (dx,dy,dtime,dtimeMin,dtimeMax,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dtimemin,dtimemax,dalpha\n fct_stokesZ8_x = -0.25_DP*fct_eigSt8(dx,dy,dtime,dalpha)*(-4.0_DP*sin(0.5_DP*SYS_PI*dtime)+&\n 5.0_DP*SYS_PI**2*sin(0.5_DP*SYS_PI*dtime)-5.0_DP*SYS_PI**2-2*cos(0.5_DP*SYS_PI*dtime)*SYS_PI)\n end function\n\n elemental real(DP) function fct_stokesZ8_y (dx,dy,dtime,dtimeMin,dtimeMax,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dtimemin,dtimemax,dalpha\n fct_stokesZ8_y = -0.25_DP*fct_eigSt8(dx,dy,dtime,dalpha)*(-4.0_DP*sin(0.5_DP*SYS_PI*dtime)+&\n 5.0_DP*SYS_PI**2*sin(0.5_DP*SYS_PI*dtime)-5.0_DP*SYS_PI**2-2*cos(0.5_DP*SYS_PI*dtime)*SYS_PI)\n end function\n\n elemental real(DP) function fct_stokesZ8_p (dx,dy,dtime,dtimeMin,dtimeMax,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dtimemin,dtimemax,dalpha\n fct_stokesZ8_p = -0.5_DP*SYS_PI*(sin(0.5_DP*SYS_PI*dtime)*cos(0.5_DP*SYS_PI*dx)*sin(SYS_PI*dy)+&\n 2.0_DP*sin(0.5_DP*SYS_PI*dtime)*sin(0.5_DP*SYS_PI*dx)*cos(SYS_PI*dy)-&\n cos(0.5_DP*SYS_PI*dx)*sin(SYS_PI*dy)-2*sin(0.5_DP*SYS_PI*dx)*cos(SYS_PI*dy))\n end function\n\n elemental real(DP) function fct_stokesF8_x (dx,dy,dtime,dtimeMin,dtimeMax,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dtimemin,dtimemax,dalpha\n fct_stokesF8_x = 1.25_DP*fct_eigSt8(dx,dy,dtime,dalpha)*SYS_PI**2*sin(0.5_DP*SYS_PI*dtime)+&\n 0.5_DP*fct_eigSt8(dx,dy,dtime,dalpha)*cos(0.5_DP*SYS_PI*dtime)*SYS_PI+&\n fct_eigSt8(dx,dy,dtime,dalpha)*(sin(0.5_DP*SYS_PI*dtime)-1)/dalpha\n end function\n\n elemental real(DP) function fct_stokesF8_y (dx,dy,dtime,dtimeMin,dtimeMax,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dtimemin,dtimemax,dalpha\n fct_stokesF8_y = 1.25_DP*fct_eigSt8(dx,dy,dtime,dalpha)*SYS_PI**2*sin(0.5_DP*SYS_PI*dtime)+&\n 0.5_DP*fct_eigSt8(dx,dy,dtime,dalpha)*cos(0.5_DP*SYS_PI*dtime)*SYS_PI+&\n fct_eigSt8(dx,dy,dtime,dalpha)*(sin(0.5_DP*SYS_PI*dtime)-1)/dalpha\n end function\n\n elemental real(DP) function fct_stokesF8_p (dx,dy,dtime,dtimeMin,dtimeMax,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dtimemin,dtimemax,dalpha\n fct_stokesF8_p = -0.5_DP*SYS_PI*sin(0.5_DP*SYS_PI*dtime)*(cos(0.5_DP*SYS_PI*dx)*sin(SYS_PI*dy)+&\n 2*sin(0.5_DP*SYS_PI*dx)*cos(SYS_PI*dy))\n end function\n\n\n ! ***************************************************************************\n ! Stokes, function set 9\n ! w = sin (Pi/2 x1) sin (Pi x2)\n ! w_0 = sin (Pi x1) sin (Pi x2)\n ! y = sin (Pi t ) ( w , w )\n ! lambda = sin (Pi t ) ( w , w )\n ! p = sin (Pi t) w_0\n ! xi = sin (Pi t) w_0\n ! ***************************************************************************\n\n elemental real(DP) function fct_eigSt9(dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n fct_eigSt9 = sin(0.5_DP*SYS_PI*dx) * sin(SYS_PI*dy)\n end function\n\n elemental real(DP) function fct_eigSt9_1(dx,dy,dtime,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dalpha\n ! No int-mean = 0 since there is a Neumann edge that forces p=0 on the edge.\n fct_eigSt9_1 = sin(SYS_PI*dx) * sin(SYS_PI*dy)\n end function\n\n elemental real(DP) function fct_stokesY9_x (dx,dy,dtime,dtimeMin,dtimeMax,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dtimemin,dtimemax,dalpha\n fct_stokesY9_x = fct_eigSt9(dx,dy,dtime,dalpha)*sin(0.5_DP*SYS_PI*dtime)\n end function\n\n elemental real(DP) function fct_stokesY9_y (dx,dy,dtime,dtimeMin,dtimeMax,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dtimemin,dtimemax,dalpha\n fct_stokesY9_y = fct_eigSt9(dx,dy,dtime,dalpha)*sin(0.5_DP*SYS_PI*dtime)\n end function\n\n elemental real(DP) function fct_stokesP9 (dx,dy,dtime,dtimeMin,dtimeMax,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dtimemin,dtimemax,dalpha\n fct_stokesP9 = sin(SYS_PI*dtime)*fct_eigSt9_1(dx,dy,dtime,dalpha)\n end function\n\n elemental real(DP) function fct_stokesLambda9_x (dx,dy,dtime,dtimeMin,dtimeMax,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dtimemin,dtimemax,dalpha\n fct_stokesLambda9_x = fct_eigSt9(dx,dy,dtime,dalpha)*(sin(0.5_DP*SYS_PI*dtime)-1.0_DP)\n end function\n\n elemental real(DP) function fct_stokesLambda9_y (dx,dy,dtime,dtimeMin,dtimeMax,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dtimemin,dtimemax,dalpha\n fct_stokesLambda9_y = fct_eigSt9(dx,dy,dtime,dalpha)*(sin(0.5_DP*SYS_PI*dtime)-1.0_DP)\n end function\n\n elemental real(DP) function fct_stokesXi9 (dx,dy,dtime,dtimeMin,dtimeMax,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dtimemin,dtimemax,dalpha\n fct_stokesXi9 = sin(SYS_PI*dtime)*fct_eigSt9_1(dx,dy,dtime,dalpha)\n end function\n\n elemental real(DP) function fct_stokesZ9_x (dx,dy,dtime,dtimeMin,dtimeMax,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dtimemin,dtimemax,dalpha\n fct_stokesZ9_x = -0.25_DP*fct_eigSt9(dx,dy,dtime,dalpha)*(-4.0_DP*sin(0.5_DP*SYS_PI*dtime)+&\n 5.0_DP*SYS_PI**2*sin(0.5_DP*SYS_PI*dtime)-5.0_DP*SYS_PI**2-2*cos(0.5_DP*SYS_PI*dtime)*SYS_PI) - &\n sin(SYS_PI*dtime)*SYS_PI*cos(SYS_PI*dx) * sin(SYS_PI*dy)\n end function\n\n elemental real(DP) function fct_stokesZ9_y (dx,dy,dtime,dtimeMin,dtimeMax,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dtimemin,dtimemax,dalpha\n fct_stokesZ9_y = -0.25_DP*fct_eigSt9(dx,dy,dtime,dalpha)*(-4.0_DP*sin(0.5_DP*SYS_PI*dtime)+&\n 5.0_DP*SYS_PI**2*sin(0.5_DP*SYS_PI*dtime)-5.0_DP*SYS_PI**2-2*cos(0.5_DP*SYS_PI*dtime)*SYS_PI) - &\n sin(SYS_PI*dtime)*SYS_PI*sin(SYS_PI*dx) * cos(SYS_PI*dy)\n end function\n\n elemental real(DP) function fct_stokesZ9_p (dx,dy,dtime,dtimeMin,dtimeMax,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dtimemin,dtimemax,dalpha\n fct_stokesZ9_p = -0.5_DP*SYS_PI*(sin(0.5_DP*SYS_PI*dtime)*cos(0.5_DP*SYS_PI*dx)*sin(SYS_PI*dy)+&\n 2.0_DP*sin(0.5_DP*SYS_PI*dtime)*sin(0.5_DP*SYS_PI*dx)*cos(SYS_PI*dy)-&\n cos(0.5_DP*SYS_PI*dx)*sin(SYS_PI*dy)-2*sin(0.5_DP*SYS_PI*dx)*cos(SYS_PI*dy))\n end function\n\n elemental real(DP) function fct_stokesF9_x (dx,dy,dtime,dtimeMin,dtimeMax,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dtimemin,dtimemax,dalpha\n fct_stokesF9_x = 1.25_DP*fct_eigSt9(dx,dy,dtime,dalpha)*SYS_PI**2*sin(0.5_DP*SYS_PI*dtime)+&\n 0.5_DP*fct_eigSt9(dx,dy,dtime,dalpha)*cos(0.5_DP*SYS_PI*dtime)*SYS_PI+&\n fct_eigSt9(dx,dy,dtime,dalpha)*(sin(0.5_DP*SYS_PI*dtime)-1)/dalpha + &\n sin(SYS_PI*dtime)*SYS_PI*cos(SYS_PI*dx) * sin(SYS_PI*dy)\n end function\n\n elemental real(DP) function fct_stokesF9_y (dx,dy,dtime,dtimeMin,dtimeMax,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dtimemin,dtimemax,dalpha\n fct_stokesF9_y = 1.25_DP*fct_eigSt9(dx,dy,dtime,dalpha)*SYS_PI**2*sin(0.5_DP*SYS_PI*dtime)+&\n 0.5_DP*fct_eigSt9(dx,dy,dtime,dalpha)*cos(0.5_DP*SYS_PI*dtime)*SYS_PI+&\n fct_eigSt9(dx,dy,dtime,dalpha)*(sin(0.5_DP*SYS_PI*dtime)-1)/dalpha + &\n sin(SYS_PI*dtime)*SYS_PI*sin(SYS_PI*dx) * cos(SYS_PI*dy)\n end function\n\n elemental real(DP) function fct_stokesF9_p (dx,dy,dtime,dtimeMin,dtimeMax,dalpha)\n real(DP), intent(in) :: dx,dy,dtime,dtimemin,dtimemax,dalpha\n fct_stokesF9_p = -0.5_DP*SYS_PI*sin(0.5_DP*SYS_PI*dtime)*(cos(0.5_DP*SYS_PI*dx)*sin(SYS_PI*dy)+&\n 2*sin(0.5_DP*SYS_PI*dx)*cos(SYS_PI*dy))\n end function\n\nend module\n", "meta": {"hexsha": "a713d3523e7a09e1da47e6389f16d91af4be5bb2", "size": 32430, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "area51/cc2doptcontrol5/src/user_flows.f90", "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/cc2doptcontrol5/src/user_flows.f90", "max_issues_repo_name": "tudo-math-ls3/FeatFlow2", "max_issues_repo_head_hexsha": "56159aff28f161aca513bc7c5e2014a2d11ff1b3", "max_issues_repo_licenses": ["Intel", "Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "area51/cc2doptcontrol5/src/user_flows.f90", "max_forks_repo_name": "tudo-math-ls3/FeatFlow2", "max_forks_repo_head_hexsha": "56159aff28f161aca513bc7c5e2014a2d11ff1b3", "max_forks_repo_licenses": ["Intel", "Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.0077720207, "max_line_length": 118, "alphanum_fraction": 0.5867406722, "num_tokens": 11745, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267660487572, "lm_q2_score": 0.8006920092299292, "lm_q1q2_score": 0.695662648980321}} {"text": " function shape1(xlow,ylow,xhigh,yhigh,f,x,y) \nc-----------------------------------------------------------------------\nc interpolates the function f(x,y) at the point (x,y) within the \nc interior of a rectangular region for which the value of f is known \nc at the corners. interpolation is by linear serendipity shape\nc functions ala finite elements. (see zienkiewicz, 'the finite element\nc method in engineering science', page 107 of the second edition)\nc \nc arguments- \nc \nc (xlow,ylow)-x,y coordinates of lower left corner of element \nc (xhigh,yhigh)-x,y coordinates of upper right hand corner of \nc element.\nc (note this requires xhigh.gt.xlow and yhigh.gt.ylow) \nc f-four dimensional array of functional values at the corners\nc f(1)=f(xlow,ylow) \nc f(2)=f(xhigh,ylow)\nc f(3)=f(xlow,yhigh)\nc f(4)=f(xhigh,yhigh) \nc \nc (x,y)-x,y coordinates at which f is to be evaluated.\nc \nc alternate entry point-shape2 \nc evaluates f(x,y) using interpolation coefficients calculated in \nc previous call to shape. \nc-----------------------------------------------------------------------\n dimension f(4),shapefc(4) \n save shapefc\nc--convert to local coordinates \n xzero=(xlow+xhigh)/2. \n yzero=(ylow+yhigh)/2. \n dx=xhigh-xzero\n dy=yhigh-yzero\n zeta=(x-xzero)/dx \n eta=(y-yzero)/dy\nc--evaluate shape functions at (x,y) to obtain interpolation\nc--coefficients \n shapefc(1)=(1.-zeta)*(1.-eta)/4.\n shapefc(2)=(1.+zeta)*(1.-eta)/4.\n shapefc(3)=(1.-zeta)*(1.+eta)/4.\n shapefc(4)=(1.+zeta)*(1.+eta)/4.\n entry shape2(xlow,ylow,xhigh,yhigh,f,x,y) \n sum=0.\n do 100 i=1,4\n sum=sum+shapefc(i)*f(i) \n 100 continue\n shape=sum \n shape2=sum\n return\n end \n\nc $Id$ \n", "meta": {"hexsha": "beb65b006afbfc3c392b4a6b5c2bde7ece3abc12", "size": 1850, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "lib/location/libglp/shape.f", "max_stars_repo_name": "jreyes1108/antelope_contrib", "max_stars_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_stars_repo_licenses": ["BSD-2-Clause", "MIT"], "max_stars_count": 30, "max_stars_repo_stars_event_min_datetime": "2015-02-20T21:44:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-27T02:53:14.000Z", "max_issues_repo_path": "lib/location/libglp/shape.f", "max_issues_repo_name": "jreyes1108/antelope_contrib", "max_issues_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_issues_repo_licenses": ["BSD-2-Clause", "MIT"], "max_issues_count": 14, "max_issues_repo_issues_event_min_datetime": "2015-07-07T19:17:24.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-19T19:18:53.000Z", "max_forks_repo_path": "lib/location/libglp/shape.f", "max_forks_repo_name": "jreyes1108/antelope_contrib", "max_forks_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_forks_repo_licenses": ["BSD-2-Clause", "MIT"], "max_forks_count": 46, "max_forks_repo_forks_event_min_datetime": "2015-02-06T16:22:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T11:46:37.000Z", "avg_line_length": 34.9056603774, "max_line_length": 72, "alphanum_fraction": 0.5789189189, "num_tokens": 536, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.89181104831338, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6956062860526087}} {"text": "program inv_test\n use m_util\n integer, dimension(3) :: piv\n real(dp), dimension(3,3) :: A, invA_expected\n real(dp), allocatable :: work(:)\n real(dp) :: invA(3,3), invA_lapack(3,3), lwork_real(1)\n integer lwork\n\n A = reshape((/ 1.0, 2.0, 3.0, 5.0, 7.0, 9.0, 11.0, -1.0, -0.5 /), shape(A))\n\n invA_expected(1,:) = (/ -11.0, -203.0, 164.0 /)\n invA_expected(2,:) = (/ 4.0, 67.0, -46.0 /)\n invA_expected(3,:) = (/ 6.0, -12.0, 6.0 /)\n invA_expected = invA_expected / 75\n\n invA_lapack = A\n call dgetrf(3, 3, invA_lapack, 3, piv, info)\n \n call dgetri(3, invA_lapack, 3, piv, lwork_real, -1, info)\n lwork = nint(lwork_real(1))\n allocate(real(dp) :: work(lwork))\n call dgetri(3, invA_lapack, 3, piv, work, lwork, info)\n \n invA = A\n call ninv(invA)\n \n if (maxval(abs(invA - invA_lapack)) > 1D-10) stop 1\n if (maxval(abs(invA - invA_expected)) > 1D-10) stop 2\nend program inv_test\n", "meta": {"hexsha": "b1c4f0d32f30e198780c6e0ff1d29463d74b930e", "size": 901, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/inv_test.f90", "max_stars_repo_name": "JaakkoAhola/GPEmulator", "max_stars_repo_head_hexsha": "d4439dfadc51e322000602aa9bd4a02ab271f2e4", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2019-02-13T06:47:31.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-07T22:15:47.000Z", "max_issues_repo_path": "test/inv_test.f90", "max_issues_repo_name": "JaakkoAhola/GPEmulator", "max_issues_repo_head_hexsha": "d4439dfadc51e322000602aa9bd4a02ab271f2e4", "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": "test/inv_test.f90", "max_forks_repo_name": "JaakkoAhola/GPEmulator", "max_forks_repo_head_hexsha": "d4439dfadc51e322000602aa9bd4a02ab271f2e4", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-01-23T18:28:11.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-07T22:32:40.000Z", "avg_line_length": 30.0333333333, "max_line_length": 77, "alphanum_fraction": 0.6059933407, "num_tokens": 406, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.7799928900257127, "lm_q1q2_score": 0.6956062791736446}} {"text": " program matmul\n INTEGER SIZE\n PARAMETER (SIZE=100)\n real a(size,size), b(size,size), c(size,size)\n\n do 100 i = 1, size\n do 100 j = 1, size\n do 100 k = 1, size\n a(i,j) = a(i,j) + b(i,k)*c(k,j)\n 100 continue\n\n end\n", "meta": {"hexsha": "50c0cb831ea4baf40c75e366a89e2f27aaaed2a9", "size": 277, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "packages/PIPS/validation/Wp65/matmul.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/Wp65/matmul.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/Wp65/matmul.f", "max_forks_repo_name": "DVSR1966/par4all", "max_forks_repo_head_hexsha": "86b33ca9da736e832b568c5637a2381f360f1996", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2015-03-26T08:05:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T02:01:51.000Z", "avg_line_length": 21.3076923077, "max_line_length": 51, "alphanum_fraction": 0.4693140794, "num_tokens": 91, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588052782737, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.6955981652248421}} {"text": "c intrinsic-vax-cd.f\nc\nc Test double complex intrinsics CD*. \nc These functions are VAX extensions\nc\nc David Billinghurst \nc\n double complex z, a\n double precision x\n logical fail\n intrinsic cdabs, cdcos, cdexp, cdlog, cdsin, cdsqrt\n common /flags/ fail\n fail = .false.\n\nc CDABS - Absolute value\n z = (3.0d0,-4.0d0)\n x = 5.0d0\n call c_d(CDABS(z),x,'CDABS(double complex)')\n call p_d_z(CDABS,z,x,'CDABS')\n\nc CDCOS - Cosine\n z = (3.0d0,1.0d0)\n a = (-1.52763825012d0,-0.165844401919)\n call c_z(CDCOS(z),a,'CDCOS(double complex)')\n call p_z_z(CDCOS,z,a,'CDCOS')\n\nc CDEXP - Exponential\n z = (3.0d0,1.0d0)\n a = (10.8522619142d0,16.9013965352)\n call c_z(CDEXP(z),a,'CDEXP(double complex)')\n call p_z_z(CDEXP,z,a,'CDEXP')\n\nc CDLOG - Natural logarithm\n call c_z(CDLOG(a),z,'CDLOG(double complex)')\n call p_z_z(CDLOG,a,z,'CDLOG')\n\nc CDSIN - Sine\n z = (3.0d0,1.0d0)\n a = (0.217759551622d0,-1.1634403637d0)\n call c_z(CDSIN(z),a,'CDSIN(double complex)')\n call p_z_z(CDSIN,z,a,'CDSIN')\n\nc CDSQRT - Square root\n z = (0.0d0,-4.0d0)\n a = sqrt(2.0d0)*(1.0d0,-1.0d0)\n call c_z(CDSQRT(z),a,'CDSQRT(double complex)')\n call p_z_z(CDSQRT,z,a,'CDSQRT')\n\n if ( fail ) call abort()\n end\n\n subroutine failure(label)\nc Report failure and set flag\n character*(*) label\n logical fail\n common /flags/ fail\n write(6,'(a,a,a)') 'Test ',label,' FAILED'\n fail = .true.\n end\n\n subroutine c_z(a,b,label)\nc Check if DOUBLE COMPLEX a equals b, and fail otherwise\n double complex a, b\n character*(*) label\n if ( abs(a-b) .gt. 1.0e-5 ) then\n call failure(label)\n write(6,*) 'Got ',a,' expected ', b\n end if\n end\n\n subroutine c_d(a,b,label)\nc Check if DOUBLE PRECISION a equals b, and fail otherwise\n double precision a, b\n character*(*) label\n if ( abs(a-b) .gt. 1.0d-5 ) then\n call failure(label)\n write(6,*) 'Got ',a,' expected ', b\n end if\n end\n\n subroutine p_z_z(f,x,a,label)\nc Check if DOUBLE COMPLEX f(x) equals a for DOUBLE COMPLEX x\n double complex f,x,a\n character*(*) label\n call c_z(f(x),a,label)\n end\n\n subroutine p_d_z(f,x,a,label)\nc Check if DOUBLE PRECISION f(x) equals a for DOUBLE COMPLEX x\n double precision f,x\n double complex a\n character*(*) label\n call c_d(f(x),a,label)\n end\n", "meta": {"hexsha": "93f1c43b0f5dc75d50b97314d92da814804abfee", "size": 2572, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tools-src/gnu/gcc/gcc/testsuite/g77.f-torture/execute/intrinsic-vax-cd.f", "max_stars_repo_name": "enfoTek/tomato.linksys.e2000.nvram-mod", "max_stars_repo_head_hexsha": "2ce3a5217def49d6df7348522e2bfda702b56029", "max_stars_repo_licenses": ["FSFAP"], "max_stars_count": 80, "max_stars_repo_stars_event_min_datetime": "2015-01-02T10:14:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-07T06:29:49.000Z", "max_issues_repo_path": "tools-src/gnu/gcc/gcc/testsuite/g77.f-torture/execute/intrinsic-vax-cd.f", "max_issues_repo_name": "unforgiven512/tomato", "max_issues_repo_head_hexsha": "96f09fab4929c6ddde5c9113f1b2476ad37133c4", "max_issues_repo_licenses": ["FSFAP"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2015-05-14T11:03:12.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-04T07:12:58.000Z", "max_forks_repo_path": "tools-src/gnu/gcc/gcc/testsuite/g77.f-torture/execute/intrinsic-vax-cd.f", "max_forks_repo_name": "unforgiven512/tomato", "max_forks_repo_head_hexsha": "96f09fab4929c6ddde5c9113f1b2476ad37133c4", "max_forks_repo_licenses": ["FSFAP"], "max_forks_count": 69, "max_forks_repo_forks_event_min_datetime": "2015-01-02T10:45:56.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-06T07:52:13.000Z", "avg_line_length": 27.0736842105, "max_line_length": 66, "alphanum_fraction": 0.5855365474, "num_tokens": 861, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853655, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.6955981606126841}} {"text": "program cylinder\n\n! Calculate the surface area of a cylinder.\n!\n! Declare variables and constants.\n! constants=pi\n! variables=radius squared and height\n\n implicit none ! Require all variables to be explicitly declared\n\n integer :: ierr\n character(1) :: yn\n real :: radius, height, area\n real, parameter :: pi = 3.141592653589793\n\n interactive_loop: do\n\n! Prompt the user for radius and height\n! and read them.\n\n write (*,*) 'Enter radius and height.'\n read (*,*,iostat=ierr) radius,height\n\n! If radius and height could not be read from input,\n! then cycle through the loop.\n\n if (ierr /= 0) then\n write(*,*) 'Error, invalid input.'\n cycle interactive_loop\n end if\n\n! Compute area. The ** means \"raise to a power.\"\n\n area = 2*pi * (radius**2 + radius*height)\n\n! Write the input variables (radius, height)\n! and output (area) to the screen.\n\n write (*,'(1x,a7,f6.2,5x,a7,f6.2,5x,a5,f6.2)') &\n 'radius=',radius,'height=',height,'area=',area\n\n yn = ' '\n yn_loop: do\n write(*,*) 'Perform another calculation? y[n]'\n read(*,'(a1)') yn\n if (yn=='y' .or. yn=='Y') exit yn_loop\n if (yn=='n' .or. yn=='N' .or. yn==' ') exit interactive_loop\n end do yn_loop\n\n end do interactive_loop\n\nend program cylinder", "meta": {"hexsha": "efa78e43a3547729a30f034e2298179d0c6b1f14", "size": 1281, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/data/Fortran-90/cylinder.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/cylinder.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/cylinder.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": 24.6346153846, "max_line_length": 68, "alphanum_fraction": 0.6323185012, "num_tokens": 375, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.888758793492457, "lm_q2_score": 0.7826624789529376, "lm_q1q2_score": 0.6955981605060284}} {"text": "program ch0706\n ! Voltage from -20 to +20 Volts\n implicit none\n\n real, dimension(-20:20) :: current\n real :: resistance\n integer :: voltage\n\n print *, ' type in the resistance'\n read *, resistance\n do voltage = -20, 20\n current(voltage) = voltage/resistance\n print *, voltage, ' ', current(voltage)\n end do\nend program\n", "meta": {"hexsha": "13c252fd0c2fc9dec25250164841706c92114617", "size": 360, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ch07/ch0706.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": "ch07/ch0706.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": "ch07/ch0706.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.5, "max_line_length": 47, "alphanum_fraction": 0.6166666667, "num_tokens": 95, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8887587875995482, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.6955981558938696}} {"text": "module constants\n\n! Contains the mathematical constant \"pi\".\n\nuse types, only: dp\nimplicit none\nprivate\npublic pi\n\n! Contain more digits than double precision, so that\n! it is rounded correctly:\nreal(dp), parameter :: pi = 3.1415926535897932384626433832795_dp\n\nend module\n", "meta": {"hexsha": "19fe615f9be599c909d0d2709abf38bba410d85d", "size": 274, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/constants.f90", "max_stars_repo_name": "rc/dftatom", "max_stars_repo_head_hexsha": "fe479fd27a7e0f77c6a88a1949996406ec935ac2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 40, "max_stars_repo_stars_event_min_datetime": "2015-03-19T16:00:14.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-29T03:06:10.000Z", "max_issues_repo_path": "src/constants.f90", "max_issues_repo_name": "rc/dftatom", "max_issues_repo_head_hexsha": "fe479fd27a7e0f77c6a88a1949996406ec935ac2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2015-06-23T21:59:56.000Z", "max_issues_repo_issues_event_max_datetime": "2019-09-04T20:36:51.000Z", "max_forks_repo_path": "src/constants.f90", "max_forks_repo_name": "rc/dftatom", "max_forks_repo_head_hexsha": "fe479fd27a7e0f77c6a88a1949996406ec935ac2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2015-06-07T15:14:49.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-05T07:03:24.000Z", "avg_line_length": 18.2666666667, "max_line_length": 66, "alphanum_fraction": 0.7737226277, "num_tokens": 71, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8633916099737805, "lm_q2_score": 0.8056321983146848, "lm_q1q2_score": 0.6955760807496317}} {"text": "program tarefa8\n\n real*16 :: Vd, VA, VB\n\n ! Definindo o valor de pi\n pi = 4e0*atan(1e0)\n \n ! Definindo unit para o arquivo de saida da tarefa 8\n open(unit=10, file='saida-8-10407962')\n\n ! Definindo unit para o arquivo de saida do item A\n open(unit=11, file='saida-8a-10407962')\n\n ! Definindo unit para o arquivo de saida do item B\n open(unit=12, file='saida-8b-10407962')\n\n ! Recebe o valor do raio\n print *, 'Digite o raio R:'\n read(*,*) R\n\n ! Recebe o valor da dimens\u00e3o\n print *, 'Digite o n\u00famero de dimens\u00f5es d:'\n read(*,*) id\n \n ! loop que para mudar a dimens\u00e3o de 2 at\u00e9 d\n do i = 2, id\n \n ! definindo arg e dgamma inicial\n ! aqui est\u00e1 sem as redundancia da tarefa-7\n arg = i/2e0\n dgamma = 1e0\n\n ! loop que calcula o dgamma\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 ! calculo do volume d\n Vd = (pi**(i/2e0) * R**i) / dgamma\n\n ! escreve a dimens\u00e3o e o volume no arquivo de saida\n write(10,'(I0,\", \",F0.6)') i, Vd\n\n ! calcula e escreve a dimens\u00e3o e a raz\u00e3o do volume do cudo raio 1 mili e esfera 1 mili\n VA = 1e0/Vd\n write(11, '(I0,\", \",F0.6)') i, VA\n\n ! calcula e escreve a dimens\u00e3o e a raz\u00e3o do volume do cubo raio 1 micro e esfera 1 angstr\u00f6m\n VB = 1e0/(Vd*10e-4**i)\n write(12, '(I0,\", \",F0.6)') i, VB\n\n end do\n\n ! fecha o arquivo de saida\n close(10)\n close(11)\n close(12)\n \nend program tarefa8\n", "meta": {"hexsha": "2c11ff51b5d485680648c87a1b5b55ea918c2df7", "size": 1701, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "projeto-1/tarefa-8/tarefa-8-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-8/tarefa-8-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-8/tarefa-8-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": 25.7727272727, "max_line_length": 99, "alphanum_fraction": 0.5432098765, "num_tokens": 590, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916170039421, "lm_q2_score": 0.8056321843145404, "lm_q1q2_score": 0.695576074325749}} {"text": "\nsubroutine bisect(fun,xl,xr,x,f,tol)\n\n implicit none\n\n ! arguments\n real(8),intent(inout) :: xl ! left bound\n real(8),intent(inout) :: xr ! right bound\n real(8),intent(inout) :: x ! result\n real(8),intent(out) :: f ! residual\n real(8),intent(in) :: tol ! residual tolerance\n\n ! function argument\n real(8) :: fun\n external fun\n\n ! local varaibles\n real(8) :: fl ! residual for left bound\n real(8) :: fr ! resdiual for right bound\n integer :: i ! loop counter\n\n ! determine residual bounds\n fl = fun(xl)\n fr = fun(xr)\n\n ! begin loop\n do i = 1,100\n\n ! get midpoint\n x = 0.5_8*(xl + xr)\n\n ! evaluate resdiual at midpoint\n f = fun(x)\n\n ! check for convergence\n if (abs(f) < tol) exit\n\n ! reset the bounds\n if (f*fl < dble(0.0)) then\n\n ! move right bound info to mid\n xr = x\n fr = f\n\n else\n\n ! move left bound info to mid\n xl = x\n fl = f\n\n end if\n\n\n end do\n\nend subroutine bisect\n", "meta": {"hexsha": "11d9e92cec4de7e2bbdbefb5d57dfdce427ec6ff", "size": 1005, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "notebook/demo/gfortran/bisect.f08", "max_stars_repo_name": "alex-treebeard/home", "max_stars_repo_head_hexsha": "bec975dcfb7a473da956215be4f5b4fd3d10a686", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notebook/demo/gfortran/bisect.f08", "max_issues_repo_name": "alex-treebeard/home", "max_issues_repo_head_hexsha": "bec975dcfb7a473da956215be4f5b4fd3d10a686", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notebook/demo/gfortran/bisect.f08", "max_forks_repo_name": "alex-treebeard/home", "max_forks_repo_head_hexsha": "bec975dcfb7a473da956215be4f5b4fd3d10a686", "max_forks_repo_licenses": ["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": 56, "alphanum_fraction": 0.5582089552, "num_tokens": 325, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391595913457, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.6955760633783791}} {"text": "module types\n ! should replace .f2py_f2cmap\n\n implicit none\n\n ! fortran 2008 specific\n !use, intrinsic :: iso_fortran_env\n !integer, parameter :: sp = REAL32\n !integer, parameter :: dp = REAL64\n !integer, parameter :: qp = REAL128\n\n integer, parameter :: sp = selected_real_kind(6, 37) ! 32 single\n !integer, parameter :: dp = selected_real_kind(15, 307) ! 64 double\n integer, parameter :: qp = selected_real_kind(33, 4931) ! 128 quadruple\n\n !machine specific double precision\n integer, parameter :: dp = kind(1.d0)\n\n real(sp) :: r_sp = 1.0\n real(dp) :: r_dp = 1.0_dp\n real(qp) :: r_qp = 1.0_qp\n\nend module\n\n\nmodule precision\n\n use types ! set type precision\n\n contains\n\n subroutine get_integer_precision()\n !implicit none\n\n integer(sp) :: single\n integer(dp) :: double\n integer(qp) :: quadruple\n\n print *, \"Huge Integer Single Precision\"\n print *, huge(single)\n print *, \"Huge Integer Double Precision\"\n print *, huge(double)\n print *, \"Huge Integer Quadruple Precision\"\n print *, huge(quadruple)\n\n end subroutine get_integer_precision\n\n subroutine get_real_precision()\n !implicit none\n\n real(sp) :: single\n real(dp) :: double\n real(qp) :: quadruple\n\n print *, \"Huge Real Single Precision\"\n print *, huge(single)\n print *, \"Huge Real Double Precision\"\n print *, huge(double)\n print *, \"Huge Real Quadruple Precision\"\n print *, huge(quadruple)\n\n print *, \"Tiny Real Single Precision\"\n print *, tiny(single)\n print *, \"Tiny Real Double Precision\"\n print *, tiny(double)\n print *, \"Tiny Real Quadruple Precision\"\n print *, tiny(quadruple)\n\n end subroutine get_real_precision\n\nend module\n", "meta": {"hexsha": "171f52844ec466605510272b322fa0c8d44560a5", "size": 1744, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "platea/_fortran/types.f90", "max_stars_repo_name": "James-Montgomery/platea", "max_stars_repo_head_hexsha": "96188d34293d46ddc3f9935fe1349f83f72c13a8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "platea/_fortran/types.f90", "max_issues_repo_name": "James-Montgomery/platea", "max_issues_repo_head_hexsha": "96188d34293d46ddc3f9935fe1349f83f72c13a8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "platea/_fortran/types.f90", "max_forks_repo_name": "James-Montgomery/platea", "max_forks_repo_head_hexsha": "96188d34293d46ddc3f9935fe1349f83f72c13a8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.2222222222, "max_line_length": 73, "alphanum_fraction": 0.6462155963, "num_tokens": 454, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891479496521, "lm_q2_score": 0.8459424411924673, "lm_q1q2_score": 0.6955246949384835}} {"text": " Program dorgbr_example\n\n! DORGBR Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_example_aux, Only: nagf_file_print_matrix_real_gen\n Use lapack_interfaces, Only: dbdsqr, dgebrd, dlacpy, dorgbr\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nin = 5, nout = 6\n! .. Local Scalars ..\n Integer :: i, ic, ifail, info, lda, ldc, ldu, ldvt, lwork, m, n\n! .. Local Arrays ..\n Real (Kind=dp), Allocatable :: a(:, :), c(:, :), d(:), e(:), taup(:), &\n tauq(:), u(:, :), vt(:, :), work(:)\n! .. Executable Statements ..\n Write (nout, *) 'DORGBR Example Program Results'\n! Skip heading in data file\n Read (nin, *)\n Do ic = 1, 2\n Read (nin, *) m, n\n lda = m\n ldc = n\n ldu = m\n ldvt = n\n lwork = 64*(m+n)\n Allocate (a(lda,n), c(ldc,n), d(n), e(n-1), taup(n), tauq(n), &\n u(ldu,n), vt(ldvt,n), work(lwork))\n\n! Read A from data file\n\n Read (nin, *)(a(i,1:n), i=1, m)\n\n! Reduce A to bidiagonal form\n Call dgebrd(m, n, a, lda, d, e, tauq, taup, work, lwork, info)\n\n If (m>=n) Then\n\n! Copy A to VT and U\n\n Call dlacpy('Upper', n, n, a, lda, vt, ldvt)\n Call dlacpy('Lower', m, n, a, lda, u, ldu)\n\n! Form P**T explicitly, storing the result in VT\n Call dorgbr('P', n, n, m, vt, ldvt, taup, work, lwork, info)\n\n! Form Q explicitly, storing the result in U\n Call dorgbr('Q', m, n, n, u, ldu, tauq, work, lwork, info)\n\n! Compute the SVD of A\n Call dbdsqr('Upper', n, n, m, 0, d, e, vt, ldvt, u, ldu, c, ldc, &\n work, info)\n\n! Print singular values, left & right singular vectors\n\n Write (nout, *)\n Write (nout, *) 'Example 1: singular values'\n Write (nout, 100) d(1:n)\n Write (nout, *)\n Flush (nout)\n\n! ifail: behaviour on error exit\n! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft\n ifail = 0\n Call nagf_file_print_matrix_real_gen('General', ' ', n, n, vt, ldvt, &\n 'Example 1: right singular vectors, by row', ifail)\n\n Write (nout, *)\n Flush (nout)\n\n Call nagf_file_print_matrix_real_gen('General', ' ', m, n, u, ldu, &\n 'Example 1: left singular vectors, by column', ifail)\n\n Else\n\n! Copy A to VT and U\n\n Call dlacpy('Upper', m, n, a, lda, vt, ldvt)\n Call dlacpy('Lower', m, m, a, lda, u, ldu)\n\n! Form P**T explicitly, storing the result in VT\n Call dorgbr('P', m, n, m, vt, ldvt, taup, work, lwork, info)\n\n! Form Q explicitly, storing the result in U\n Call dorgbr('Q', m, m, n, u, ldu, tauq, work, lwork, info)\n\n! Compute the SVD of A\n Call dbdsqr('Lower', m, n, m, 0, d, e, vt, ldvt, u, ldu, c, ldc, &\n work, info)\n\n! Print singular values, left & right singular vectors\n\n Write (nout, *)\n Write (nout, *) 'Example 2: singular values'\n Write (nout, 100) d(1:m)\n Write (nout, *)\n Flush (nout)\n\n ifail = 0\n Call nagf_file_print_matrix_real_gen('General', ' ', m, n, vt, ldvt, &\n 'Example 2: right singular vectors, by row', ifail)\n\n Write (nout, *)\n Flush (nout)\n\n Call nagf_file_print_matrix_real_gen('General', ' ', m, m, u, ldu, &\n 'Example 2: left singular vectors, by column', ifail)\n\n End If\n Deallocate (a, c, d, e, taup, tauq, u, vt, work)\n End Do\n\n100 Format (3X, (8F8.4))\n End Program\n", "meta": {"hexsha": "15c4a1344ed9770b4513889cf91c933b78021b0b", "size": 3895, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/dorgbr_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/dorgbr_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/dorgbr_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 32.1900826446, "max_line_length": 90, "alphanum_fraction": 0.529139923, "num_tokens": 1230, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894745194283, "lm_q2_score": 0.7772998560157663, "lm_q1q2_score": 0.6955197297083748}} {"text": "PROGRAM F034\n\n ! Copyright 2021 Melwyn Francis Carlo\n\n IMPLICIT NONE\n\n INTEGER, DIMENSION(10), PARAMETER :: FACTORIALS = &\n (/ 1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880 /)\n\n INTEGER :: SUM_VAL = 0\n\n INTEGER :: I, I_LEN, J, DIGITS_SUM\n\n CHARACTER (LEN=10) :: I_STR\n\n DO I = 100, 100000\n\n WRITE(I_STR, '(I10)') I\n I_STR = ADJUSTL(I_STR)\n\n I_LEN = LEN_TRIM(I_STR)\n\n DIGITS_SUM = 0\n\n DO J = 1, I_LEN\n DIGITS_SUM = DIGITS_SUM &\n + FACTORIALS(IACHAR(I_STR(J:J))-IACHAR('0')+1)\n END DO\n\n IF (DIGITS_SUM == I) SUM_VAL = SUM_VAL + I\n\n END DO\n\n PRINT ('(I0)'), SUM_VAL\n\nEND PROGRAM F034\n", "meta": {"hexsha": "e058d777fa77a9d4b96e665dae50e93cf99dd10f", "size": 693, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "problems/034/034.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/034/034.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/034/034.f90", "max_forks_repo_name": "melwyncarlo/ProjectEuler", "max_forks_repo_head_hexsha": "c4d30ed528ae6de82232f3d2044d608c6e8f1c37", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.7297297297, "max_line_length": 69, "alphanum_fraction": 0.5396825397, "num_tokens": 240, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314858927012, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.6954940142758762}} {"text": "!********************************************************************************\n! SPEC_POLY: Compare FPML against Polzeros and AMVW for special polynomials.\n! Author: Thomas R. Cameron, Davidson College\n! Last Modified: 11 Novemeber 2018\n!********************************************************************************\n! The accuracy of FPML is compared against Polzeros and AMVW on 34 special polynomials\n! suitable for tesing convergence difficulties and other aspects of a root solver. \n!********************************************************************************\nprogram spec_poly\n use fpml\n use poly_zeroes\n use mpmodule\n implicit none\n ! testing variables\n integer :: deg, j\n real(kind=dp), parameter :: pi = 3.141592653589793D0\n real(kind=dp), dimension(:), allocatable :: coeffs, xr, xi\n complex(kind=dp), dimension(:), allocatable :: exact_roots\n ! FPML variables\n integer, parameter :: nitmax=30\n integer, dimension(:), allocatable :: conv\n real(kind=dp), dimension(:), allocatable :: berr, cond \n complex(kind=dp), dimension(:), allocatable :: p, roots\n ! Polzeros variables\n integer :: iter\n logical, dimension(:), allocatable :: h\n real(kind=dp), dimension(:), allocatable :: radius\n complex(kind=dp), dimension(:), allocatable :: zeros\n ! AMVW variables\n integer :: flag\n real(kind=dp), dimension(:), allocatable :: residuals\n complex(kind=dp), dimension(:), allocatable :: poly, eigs\n \n call mpinit\n \n ! Testing: special polynomials\n open(unit=1,file=\"data_files/spec_poly.dat\")\n write(1,'(A)') 'Poly No., FPML, Polzeros, AMVW'\n \n ! Poly 1: Wilkinson deg 10\n deg = 10\n allocate(coeffs(deg), exact_roots(deg), p(deg+1), xr(deg), xi(deg))\n ! roots\n exact_roots = (/ (cmplx(j,0,kind=dp), j=1,deg)/)\n xr = dble(exact_roots)\n xi = aimag(exact_roots)\n ! polynomial\n call rootstocoeffs(deg,xr,xi,coeffs)\n p(1:deg) = (/ (cmplx(coeffs(j),0,kind=dp), j=1,deg)/)\n p(deg+1) = cmplx(1,0,kind=dp)\n write(1, '(A)', advance='no') '1, '\n ! FPML\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n call main(p, deg, roots, berr, cond, conv, nitmax)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(roots,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(roots, berr, cond, conv)\n ! Polzeros\n allocate(zeros(deg), radius(deg), h(deg+1))\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(zeros,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(zeros, radius, h)\n ! AMVW\n allocate(poly(deg+1), eigs(deg), residuals(deg))\n poly = (/ (p(deg-j+1), j=0,deg)/)\n call z_poly_roots(deg, poly, eigs, residuals, flag)\n write(1, '(ES15.2)') maxrel_fwderr(eigs,exact_roots,deg)\n deallocate(poly, eigs, residuals)\n ! deallocate polynomial arrays\n deallocate(coeffs, exact_roots, p, xr, xi)\n \n ! Poly 2: Wilkinson deg 15\n deg = 15\n allocate(coeffs(deg), exact_roots(deg), p(deg+1), xr(deg), xi(deg))\n ! roots\n exact_roots = (/ (cmplx(j,0,kind=dp), j=1,deg)/)\n xr = dble(exact_roots)\n xi = aimag(exact_roots)\n ! polynomial\n call rootstocoeffs(deg,xr,xi,coeffs)\n p(1:deg) = (/ (cmplx(coeffs(j),0,kind=dp), j=1,deg)/)\n p(deg+1) = cmplx(1,0,kind=dp)\n write(1, '(A)', advance='no') '2, '\n ! FPML\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n call main(p, deg, roots, berr, cond, conv, nitmax)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(roots,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(roots, berr, cond, conv)\n ! Polzeros\n allocate(zeros(deg), radius(deg), h(deg+1))\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(zeros,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(zeros, radius, h)\n ! AMVW\n allocate(poly(deg+1), eigs(deg), residuals(deg))\n poly = (/ (p(deg-j+1), j=0,deg)/)\n call z_poly_roots(deg, poly, eigs, residuals, flag)\n write(1, '(ES15.2)') maxrel_fwderr(eigs,exact_roots,deg)\n deallocate(poly, eigs, residuals)\n ! deallocate polynomial arrays\n deallocate(coeffs, exact_roots, p, xr, xi)\n \n ! Poly 3: Wilkinson deg 20\n deg = 20\n allocate(coeffs(deg), exact_roots(deg), p(deg+1), xr(deg), xi(deg))\n ! roots\n exact_roots = (/ (cmplx(j,0,kind=dp), j=1,deg)/)\n xr = dble(exact_roots)\n xi = aimag(exact_roots)\n ! polynomial\n call rootstocoeffs(deg,xr,xi,coeffs)\n p(1:deg) = (/ (cmplx(coeffs(j),0,kind=dp), j=1,deg)/)\n p(deg+1) = cmplx(1,0,kind=dp)\n write(1, '(A)', advance='no') '3, '\n ! FPML\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n call main(p, deg, roots, berr, cond, conv, nitmax)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(roots,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(roots, berr, cond, conv)\n ! Polzeros\n allocate(zeros(deg), radius(deg), h(deg+1))\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(zeros,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(zeros, radius, h)\n ! AMVW\n allocate(poly(deg+1), eigs(deg), residuals(deg))\n poly = (/ (p(deg-j+1), j=0,deg)/)\n call z_poly_roots(deg, poly, eigs, residuals, flag)\n write(1, '(ES15.2)') maxrel_fwderr(eigs,exact_roots,deg)\n deallocate(poly, eigs, residuals)\n ! deallocate polynomial arrays\n deallocate(coeffs, exact_roots, p, xr, xi)\n \n ! Poly 4: scaled and shifted Wilkinson deg 20\n deg = 20\n allocate(coeffs(deg), exact_roots(deg), p(deg+1), xr(deg), xi(deg))\n ! roots\n exact_roots = (/ (cmplx(dble(-21+2*(j-1))/10d0,0,kind=dp), j=1,deg)/)\n xr = dble(exact_roots)\n xi = aimag(exact_roots)\n ! polynomial\n call rootstocoeffs(deg,xr,xi,coeffs)\n p(1:deg) = (/ (cmplx(coeffs(j),0,kind=dp), j=1,deg)/)\n p(deg+1) = cmplx(1,0,kind=dp)\n write(1, '(A)', advance='no') '4, '\n ! FPML\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n call main(p, deg, roots, berr, cond, conv, nitmax)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(roots,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(roots, berr, cond, conv)\n ! Polzeros\n allocate(zeros(deg), radius(deg), h(deg+1))\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(zeros,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(zeros, radius, h)\n ! AMVW\n allocate(poly(deg+1), eigs(deg), residuals(deg))\n poly = (/ (p(deg-j+1), j=0,deg)/)\n call z_poly_roots(deg, poly, eigs, residuals, flag)\n write(1, '(ES15.2)') maxrel_fwderr(eigs,exact_roots,deg)\n deallocate(poly, eigs, residuals)\n ! deallocate polynomial arrays\n deallocate(coeffs, exact_roots, p, xr, xi)\n \n ! Poly 5: reverse Wilkinson deg 10\n deg = 10\n allocate(coeffs(deg), exact_roots(deg), p(deg+1), xr(deg), xi(deg))\n ! roots\n exact_roots = (/ (cmplx(1d0/dble(j),0,kind=dp), j=1,deg)/)\n xr = dble(exact_roots)\n xi = aimag(exact_roots)\n ! polynomial\n call rootstocoeffs(deg,xr,xi,coeffs)\n p(1:deg) = (/ (cmplx(coeffs(j),0,kind=dp), j=1,deg)/)\n p(deg+1) = cmplx(1,0,kind=dp)\n write(1, '(A)', advance='no') '5, '\n ! FPML\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n call main(p, deg, roots, berr, cond, conv, nitmax)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(roots,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(roots, berr, cond, conv)\n ! Polzeros\n allocate(zeros(deg), radius(deg), h(deg+1))\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(zeros,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(zeros, radius, h)\n ! AMVW\n allocate(poly(deg+1), eigs(deg), residuals(deg))\n poly = (/ (p(deg-j+1), j=0,deg)/)\n call z_poly_roots(deg, poly, eigs, residuals, flag)\n write(1, '(ES15.2)') maxrel_fwderr(eigs,exact_roots,deg)\n deallocate(poly, eigs, residuals)\n ! deallocate polynomial arrays\n deallocate(coeffs, exact_roots, p, xr, xi)\n \n ! Poly 6: reverse Wilkinson deg 15\n deg = 15\n allocate(coeffs(deg), exact_roots(deg), p(deg+1), xr(deg), xi(deg))\n ! roots\n exact_roots = (/ (cmplx(1d0/dble(j),0,kind=dp), j=1,deg)/)\n xr = dble(exact_roots)\n xi = aimag(exact_roots)\n ! polynomial\n call rootstocoeffs(deg,xr,xi,coeffs)\n p(1:deg) = (/ (cmplx(coeffs(j),0,kind=dp), j=1,deg)/)\n p(deg+1) = cmplx(1,0,kind=dp)\n write(1, '(A)', advance='no') '6, '\n ! FPML\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n call main(p, deg, roots, berr, cond, conv, nitmax)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(roots,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(roots, berr, cond, conv)\n ! Polzeros\n allocate(zeros(deg), radius(deg), h(deg+1))\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(zeros,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(zeros, radius, h)\n ! AMVW\n allocate(poly(deg+1), eigs(deg), residuals(deg))\n poly = (/ (p(deg-j+1), j=0,deg)/)\n call z_poly_roots(deg, poly, eigs, residuals, flag)\n write(1, '(ES15.2)') maxrel_fwderr(eigs,exact_roots,deg)\n deallocate(poly, eigs, residuals)\n ! deallocate polynomial arrays\n deallocate(coeffs, exact_roots, p, xr, xi)\n \n ! Poly 7: reverse Wilkinson deg 20\n deg = 20\n allocate(coeffs(deg), exact_roots(deg), p(deg+1), xr(deg), xi(deg))\n ! roots\n exact_roots = (/ (cmplx(1d0/dble(j),0,kind=dp), j=1,deg)/)\n xr = dble(exact_roots)\n xi = aimag(exact_roots)\n ! polynomial\n call rootstocoeffs(deg,xr,xi,coeffs)\n p(1:deg) = (/ (cmplx(coeffs(j),0,kind=dp), j=1,deg)/)\n p(deg+1) = cmplx(1,0,kind=dp)\n write(1, '(A)', advance='no') '7, '\n ! FPML\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n call main(p, deg, roots, berr, cond, conv, nitmax)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(roots,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(roots, berr, cond, conv)\n ! Polzeros\n allocate(zeros(deg), radius(deg), h(deg+1))\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(zeros,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(zeros, radius, h)\n ! AMVW\n allocate(poly(deg+1), eigs(deg), residuals(deg))\n poly = (/ (p(deg-j+1), j=0,deg)/)\n call z_poly_roots(deg, poly, eigs, residuals, flag)\n write(1, '(ES15.2)') maxrel_fwderr(eigs,exact_roots,deg)\n deallocate(poly, eigs, residuals)\n ! deallocate polynomial arrays\n deallocate(coeffs, exact_roots, p, xr, xi)\n \n ! Poly 8: prescribed roots of varying scale deg 20\n deg = 20\n allocate(coeffs(deg), exact_roots(deg), p(deg+1), xr(deg), xi(deg))\n ! roots\n exact_roots = (/ (cmplx(2d0**(-10+(j-1)),0,kind=dp), j=1,deg)/)\n xr = dble(exact_roots)\n xi = aimag(exact_roots)\n ! polynomial\n call rootstocoeffs(deg,xr,xi,coeffs)\n p(1:deg) = (/ (cmplx(coeffs(j),0,kind=dp), j=1,deg)/)\n p(deg+1) = cmplx(1,0,kind=dp)\n write(1, '(A)', advance='no') '8, '\n ! FPML\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n call main(p, deg, roots, berr, cond, conv, nitmax)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(roots,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(roots, berr, cond, conv)\n ! Polzeros\n allocate(zeros(deg), radius(deg), h(deg+1))\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(zeros,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(zeros, radius, h)\n ! AMVW\n allocate(poly(deg+1), eigs(deg), residuals(deg))\n poly = (/ (p(deg-j+1), j=0,deg)/)\n call z_poly_roots(deg, poly, eigs, residuals, flag)\n write(1, '(ES15.2)') maxrel_fwderr(eigs,exact_roots,deg)\n deallocate(poly, eigs, residuals)\n ! deallocate polynomial arrays\n deallocate(coeffs, exact_roots, p, xr, xi)\n \n ! Poly 9: prescribed roots of varying scale -3 deg 20\n deg = 20\n allocate(coeffs(deg), exact_roots(deg), p(deg+1), xr(deg), xi(deg))\n ! roots\n exact_roots = (/ (cmplx(2d0**(-10+(j-1))-3d0,0,kind=dp), j=1,deg)/)\n xr = dble(exact_roots)\n xi = aimag(exact_roots)\n ! polynomial\n call rootstocoeffs(deg,xr,xi,coeffs)\n p(1:deg) = (/ (cmplx(coeffs(j),0,kind=dp), j=1,deg)/)\n p(deg+1) = cmplx(1,0,kind=dp)\n write(1, '(A)', advance='no') '9, '\n ! FPML\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n call main(p, deg, roots, berr, cond, conv, nitmax)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(roots,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(roots, berr, cond, conv)\n ! Polzeros\n allocate(zeros(deg), radius(deg), h(deg+1))\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(zeros,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(zeros, radius, h)\n ! AMVW\n allocate(poly(deg+1), eigs(deg), residuals(deg))\n poly = (/ (p(deg-j+1), j=0,deg)/)\n call z_poly_roots(deg, poly, eigs, residuals, flag)\n write(1, '(ES15.2)') maxrel_fwderr(eigs,exact_roots,deg)\n deallocate(poly, eigs, residuals)\n ! deallocate polynomial arrays\n deallocate(coeffs, exact_roots, p, xr, xi)\n \n ! Poly 10: Chebyshev polynomial deg 20\n deg = 20\n allocate(exact_roots(deg), p(deg+1))\n p(1) = 1d0\n p(2) = 0d0\n p(3) = -200d0\n p(4) = 0d0\n p(5) = 6600d0\n p(6) = 0d0\n p(7) = -84480d0\n p(8) = 0d0\n p(9) = 549120d0\n p(10) = 0d0\n p(11) = -2050048d0\n p(12) = 0d0\n p(13) = 4659200d0\n p(14) = 0d0\n p(15) = -6553600d0\n p(16) = 0d0\n p(17) = 5570560d0\n p(18) = 0d0\n p(19) = -2621440d0\n p(20) = 0d0\n p(21) = 524288d0\n exact_roots = (/ (cmplx(cos((2*j-1)*pi/40d0),0,kind=dp), j=1,deg)/)\n write(1, '(A)', advance='no') '10, '\n ! FPML\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n call main(p, deg, roots, berr, cond, conv, nitmax)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(roots,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(roots, berr, cond, conv)\n ! Polzeros\n allocate(zeros(deg), radius(deg), h(deg+1))\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(zeros,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(zeros, radius, h)\n ! AMVW\n allocate(poly(deg+1), eigs(deg), residuals(deg))\n poly = (/ (p(deg-j+1), j=0,deg)/)\n call z_poly_roots(deg, poly, eigs, residuals, flag)\n write(1, '(ES15.2)') maxrel_fwderr(eigs,exact_roots,deg)\n deallocate(poly, eigs, residuals)\n ! deallocate polynomial arrays\n deallocate(exact_roots, p)\n \n ! Poly 11: z^i for i=0,20\n deg = 20\n allocate(exact_roots(deg), p(deg+1))\n p = (/ (cmplx(1,0,kind=dp), j=1,deg+1)/)\n exact_roots = (/ (cmplx(cos(2*j*pi/21d0),sin(2*j*pi/21d0),kind=dp), j=1,deg)/)\n write(1, '(A)', advance='no') '11, '\n ! FPML\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n call main(p, deg, roots, berr, cond, conv, nitmax)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(roots,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(roots, berr, cond, conv)\n ! Polzeros\n allocate(zeros(deg), radius(deg), h(deg+1))\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(zeros,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(zeros, radius, h)\n ! AMVW\n allocate(poly(deg+1), eigs(deg), residuals(deg))\n poly = (/ (p(deg-j+1), j=0,deg)/)\n call z_poly_roots(deg, poly, eigs, residuals, flag)\n write(1, '(ES15.2)') maxrel_fwderr(eigs,exact_roots,deg)\n deallocate(poly, eigs, residuals)\n ! deallocate polynomial arrays\n deallocate(exact_roots, p)\n \n ! Poly 12: C. Traverso 24 MPSolve\n deg = 24\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n exact_roots(1) = cmplx(-3.52d2, 0d0, kind=dp)\n exact_roots(2) = cmplx(-3.52d2, 0d0, kind=dp)\n exact_roots(3) = cmplx(-2.8371450777d2, -2.9920517772d2, kind=dp)\n exact_roots(4) = cmplx(-2.8371450777d2, 2.9920517772d2, kind=dp)\n exact_roots(5) = cmplx(-2.7867414048d2, 6.1005469197d2, kind=dp)\n exact_roots(6) = cmplx(-2.7867414048d2, -6.1005469197d2, kind=dp)\n exact_roots(7) = cmplx(-2.74892372d2, 0d0, kind=dp)\n exact_roots(8) = cmplx(-2.014171531d2, 0d0, kind=dp)\n exact_roots(9) = cmplx(-1.255366582d2, 0d0, kind=dp)\n exact_roots(10) = cmplx(-9.599999999d1, 0d0, kind=dp)\n exact_roots(11) = cmplx(-8.8692435121d1, 5.5009607430d2, kind=dp)\n exact_roots(12) = cmplx(-8.869243512d1, -5.5009607430d2, kind=dp)\n exact_roots(13) = cmplx(-1.6000000000d1, 0d0, kind=dp)\n exact_roots(14) = cmplx(8.23178509855d1, 0d0, kind=dp)\n exact_roots(15) = cmplx(8.8692435121d1, -5.50096074303d2, kind=dp)\n exact_roots(16) = cmplx(8.8692435121d1, 5.5009607430d2, kind=dp)\n exact_roots(17) = cmplx(1.9293739373d2, 1.60865921259d3, kind=dp)\n exact_roots(18) = cmplx(1.929373937d2, -1.6086592125d3, kind=dp)\n exact_roots(19) = cmplx(2.0141715312d2, 0d0, kind=dp)\n exact_roots(20) = cmplx(2.7489237213d2, 0d0, kind=dp)\n exact_roots(21) = cmplx(7.52d2, 0d0, kind=dp)\n exact_roots(22) = cmplx(7.52d2, 0d0, kind=dp)\n exact_roots(23) = cmplx(9.1106065d2, 1.5722d0, kind=dp)\n exact_roots(24) = cmplx(9.1106065d2, -1.5722d0, kind=dp)\n ! polynomial\n p(1) = -54765291428198020791747503747742749163073958404455022926495744d0\n p(2) = -4052135566767965847649766745769409681058667331648450681896960d0\n p(3) = -31969984081155943263834965670035075493639295858977076674560d0\n p(4) = 575060225471570237690073740639182419333523437771848417280d0\n p(5) = 7337981286595499156409929740830030318565357725459415040d0\n p(6) = 6611223380089859336490797585290455483968982077145088d0\n p(7) = -195514288747757987122118583800597358656801082441728d0\n p(8) = -726907419403715013562762609680450059293446635520d0\n p(9) = 197178719520196724204974332265013056299335680d0\n p(10) = 5968852409133617129605588058090797893943296d0\n p(11) = 16576506891508825500182005531742679597056d0\n p(12) = 23375026506968330494765978581548924928d0\n p(13) = 2206941937668751746514177591607296d0\n p(14) = -75617855277818001758431020580864d0\n p(15) = -204797687173976372829472423936d0\n p(16) = -143150263927579584306872320d0\n p(17) = 20214880144364480233472d0\n p(18) = 453786251090072698880d0\n p(19) = 1265052493274939392d0\n p(20) = -968887355572224d0\n p(21) = 1015406084096d0\n p(22) = -3949133824d0\n p(23) = 3284992d0\n p(24) = -1728d0\n p(25) = 1d0\n write(1, '(A)', advance='no') '12, '\n ! FPML\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n call main(p, deg, roots, berr, cond, conv, nitmax)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(roots,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(roots, berr, cond, conv)\n ! Polzeros\n allocate(zeros(deg), radius(deg), h(deg+1))\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(zeros,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(zeros, radius, h)\n ! AMVW\n allocate(poly(deg+1), eigs(deg), residuals(deg))\n poly = (/ (p(deg-j+1), j=0,deg)/)\n call z_poly_roots(deg, poly, eigs, residuals, flag)\n write(1, '(ES15.2)') maxrel_fwderr(eigs,exact_roots,deg)\n deallocate(poly, eigs, residuals)\n ! deallocate polynomial arrays\n deallocate(exact_roots, p)\n \n ! Poly 13: Mandelbrot 31 MPSolve\n deg = 31\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n exact_roots(1) = cmplx(-1.996376137,0d0,kind=dp)\n exact_roots(2) = cmplx(-1.966773216,0d0,kind=dp)\n exact_roots(3) = cmplx(-1.907280091,0d0,kind=dp)\n exact_roots(4) = cmplx(-1.772892903,0d0,kind=dp)\n exact_roots(5) = cmplx(-1.754877666,0d0,kind=dp)\n exact_roots(6) = cmplx(-1.47601464272,0d0,kind=dp)\n exact_roots(7) = cmplx(-1.284084925525, 4.272688960406d-1,kind=dp)\n exact_roots(8) = cmplx(-1.284084925525,-4.272688960406d-1,kind=dp)\n exact_roots(9) = cmplx(-1.138000666650,-2.403324012620d-1,kind=dp)\n exact_roots(10) = cmplx(-1.138000666650, 2.403324012620d-1,kind=dp)\n exact_roots(11) = cmplx(-1d0,0d0,kind=dp)\n exact_roots(12) = cmplx(-5.968916446451269d-1, 6.629807445770295d-1,kind=dp)\n exact_roots(13) = cmplx(-5.968916446451269d-1,-6.629807445770295d-1,kind=dp)\n exact_roots(14) = cmplx(-2.17526747030511d-1,-1.11445426587329,kind=dp)\n exact_roots(15) = cmplx(-2.17526747030511d-1, 1.11445426587329,kind=dp)\n exact_roots(16) = cmplx(-1.6359826155202d-1, 1.09778064288827,kind=dp)\n exact_roots(17) = cmplx(-1.6359826155202d-1,-1.09778064288827,kind=dp)\n exact_roots(18) = cmplx(-1.225611668766536d-1,-7.4486176661974423d-1,kind=dp)\n exact_roots(19) = cmplx(-1.225611668766536d-1, 7.4486176661974423d-1,kind=dp)\n exact_roots(20) = cmplx(-1.13418655949436d-1,-8.605694725015730d-1,kind=dp)\n exact_roots(21) = cmplx(-1.13418655949436d-1,8.605694725015730d-1,kind=dp)\n exact_roots(22) = cmplx(-1.5570386020902d-2, 1.020497366498289d0,kind=dp)\n exact_roots(23) = cmplx(-1.5570386020902d-2,-1.020497366498289d0,kind=dp)\n exact_roots(24) = cmplx(3.59892739012579001d-1, 6.84762020211812856d-1,kind=dp)\n exact_roots(25) = cmplx(3.59892739012579001d-1,-6.84762020211812856d-1,kind=dp)\n exact_roots(26) = cmplx(3.8900684056977123543d-1,-2.1585065087081910777d-1,kind=dp)\n exact_roots(27) = cmplx(3.8900684056977123543d-1, 2.1585065087081910777d-1,kind=dp)\n exact_roots(28) = cmplx(3.96534570032415023d-1, 6.04181810488988837d-1,kind=dp)\n exact_roots(29) = cmplx(3.96534570032415023d-1,-6.04181810488988837d-1,kind=dp)\n exact_roots(30) = cmplx(4.433256333996235387d-1, 3.729624166628465083d-1,kind=dp)\n exact_roots(31) = cmplx(4.433256333996235387d-1,-3.729624166628465083d-1,kind=dp)\n ! polynomial\n p(1) = 1d0\n p(2) = 1d0\n p(3) = 2d0\n p(4) = 5d0\n p(5) = 14d0\n p(6) = 42d0\n p(7) = 100d0\n p(8) = 221d0\n p(9) = 470d0\n p(10) = 958d0\n p(11) = 1860d0\n p(12)= 3434d0\n p(13) = 6036d0\n p(14) = 10068d0\n p(15) = 15864d0\n p(16) = 23461d0\n p(17) = 32398d0\n p(18) = 41658d0\n p(19) = 49700d0\n p(20) = 54746d0\n p(21) = 55308d0\n p(22) = 50788d0\n p(23) = 41944d0\n p(24) = 30782d0\n p(25) = 19788d0\n p(26) = 10948d0\n p(27) = 5096d0\n p(28) = 1932d0\n p(29) = 568d0\n p(30) = 120d0\n p(31) = 16d0 \n p(32) = 1d0\n write(1, '(A)', advance='no') '13, '\n ! FPML\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n call main(p, deg, roots, berr, cond, conv, nitmax)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(roots,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(roots, berr, cond, conv)\n ! Polzeros\n allocate(zeros(deg), radius(deg), h(deg+1))\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(zeros,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(zeros, radius, h)\n ! AMVW\n allocate(poly(deg+1), eigs(deg), residuals(deg))\n poly = (/ (p(deg-j+1), j=0,deg)/)\n call z_poly_roots(deg, poly, eigs, residuals, flag)\n write(1, '(ES15.2)') maxrel_fwderr(eigs,exact_roots,deg)\n deallocate(poly, eigs, residuals)\n ! deallocate polynomial arrays\n deallocate(exact_roots, p)\n \n ! Poly 14: Mandelbrot 63 MPSolve\n deg = 63\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n exact_roots(1) = cmplx(-1.999095682327018473210d0,0d0,kind=dp)\n exact_roots(2) = cmplx(-1.9918141725491222157325609498622881d0,0d0,kind=dp)\n exact_roots(3) = cmplx(-1.977179587006257387346088520662828616836d0,0d0,kind=dp)\n exact_roots(4) = cmplx(-1.953705894284396245427622199013653238901d0,0d0,kind=dp)\n exact_roots(5) = cmplx(-1.927147709363950262460068188946594278007d0,0d0,kind=dp)\n exact_roots(6) = cmplx(-1.8848035715866817923294780929158396496359d0,0d0,kind=dp)\n exact_roots(7) = cmplx(-1.8323152027512291920848975260425181432293d0,0d0,kind=dp)\n exact_roots(8) = cmplx(-1.76926167027683114607548022863625740038777d0, 5.6919500395600315304900187298015859319654d-2,kind=dp)\n exact_roots(9) = cmplx(-1.76926167027683114607548022863625740038777d0,-5.6919500395600315304900187298015859319654d-2,kind=dp)\n exact_roots(10) = cmplx(-1.674066091474787971565296029172325596206403d0,0d0,kind=dp)\n exact_roots(11) = cmplx(-1.5748891397523009698199655524959742837719482d0,0d0,kind=dp)\n exact_roots(12) = cmplx(-1.408446485740072654917577008805998851928020904d0, &\n -1.36171997304659915684707793608163610038822995d-1,kind=dp)\n exact_roots(13) = cmplx(-1.408446485740072654917577008805998851928020904d0, &\n 1.36171997304659915684707793608163610038822995d-1,kind=dp)\n exact_roots(14) = cmplx(-1.29255806103352208716418470636149411998013630326d0, &\n 4.3819881608663183712973712432734844004535476504d-1,kind=dp)\n exact_roots(15) = cmplx(-1.29255806103352208716418470636149411998013630326d0, &\n -4.3819881608663183712973712432734844004535476504d-1,kind=dp)\n exact_roots(16) = cmplx(-1.26228728143847254301011194120806575232050489502d0, &\n 4.0810432411269038329016065742601506306041169168d-1,kind=dp)\n exact_roots(17) = cmplx(-1.26228728143847254301011194120806575232050489502d0, &\n -4.0810432411269038329016065742601506306041169168d-1,kind=dp)\n exact_roots(18) = cmplx(-1.25273588401203794629581100256433997387062287256d0, &\n -3.4247064788975089386187578687092843396383393805d-1,kind=dp)\n exact_roots(19) = cmplx(-1.25273588401203794629581100256433997387062287256d0, &\n 3.4247064788975089386187578687092843396383393805d-1,kind=dp)\n exact_roots(20) = cmplx(-1.02819385245481759930249745596731843328070508279421d0, &\n -3.61376517118561592479460832997830315786692639704085d-1,kind=dp)\n exact_roots(21) = cmplx(-1.02819385245481759930249745596731843328070508279421d0, &\n 3.61376517118561592479460832997830315786692639704085d-1,kind=dp)\n exact_roots(22) = cmplx(-6.23532485956252757990016587001026776428072703359878868d-1, &\n 6.81064414225239608090835812686561539088332735217609127d-1,kind=dp)\n exact_roots(23) = cmplx(-6.23532485956252757990016587001026776428072703359878868d-1, &\n -6.81064414225239608090835812686561539088332735217609127d-1,kind=dp)\n exact_roots(24) = cmplx(-6.2243629504129358796016350694723840189750985673649588591d-1, &\n 4.2487843647562918431157443880525338683545992964599689876d-1,kind=dp)\n exact_roots(25) = cmplx(-6.2243629504129358796016350694723840189750985673649588591d-1, &\n -4.2487843647562918431157443880525338683545992964599689876d-1,kind=dp)\n exact_roots(26) = cmplx(-5.308278048599427289214772971196026578135170949646890946d-1, &\n 6.682887255592057714440924655647011851367651843270734380d-1,kind=dp)\n exact_roots(27) = cmplx(-5.308278048599427289214772971196026578135170949646890946d-1, &\n -6.682887255592057714440924655647011851367651843270734380d-1,kind=dp)\n exact_roots(28) = cmplx(-2.72102461488938894219383324518026874585894699621947085d-1, &\n -8.42364690294128145503155708242929569550778268698265965d-1,kind=dp)\n exact_roots(29) = cmplx(-2.72102461488938894219383324518026874585894699621947085d-1, &\n 8.42364690294128145503155708242929569550778268698265965d-1,kind=dp)\n exact_roots(30) = cmplx(-2.24915951286740054685326255204118310792682454680693d-1, &\n 1.11626015745499183500126825424467009109873946082435d0,kind=dp)\n exact_roots(31) = cmplx(-2.24915951286740054685326255204118310792682454680693d-1, &\n -1.11626015745499183500126825424467009109873946082435d0,kind=dp)\n exact_roots(32) = cmplx(-2.0728383545566641282413385018667121332401155604017d-1, &\n 1.11748077249496291137377567312207879579746389236127d0,kind=dp)\n exact_roots(33) = cmplx(-2.0728383545566641282413385018667121332401155604017d-1, &\n -1.11748077249496291137377567312207879579746389236127d0,kind=dp)\n exact_roots(34) = cmplx(-1.7457822113571696945156643266162905020167505710204d-1, &\n 1.07142767145403118922964631021955987671322451961088d0,kind=dp)\n exact_roots(35) = cmplx(-1.7457822113571696945156643266162905020167505710204d-1, &\n -1.07142767145403118922964631021955987671322451961088d0,kind=dp)\n exact_roots(36) = cmplx(-1.57516053475965356164335109644674141293297577896685d-1, &\n -1.10900651411360717797175198615475582901468585712356d0,kind=dp) \n exact_roots(37) = cmplx(-1.57516053475965356164335109644674141293297577896685d-1, &\n 1.10900651411360717797175198615475582901468585712356d0,kind=dp)\n exact_roots(38) = cmplx(-1.274999735463630001995395653459879637298616757217284d-1, &\n 9.874609094894567922074076807929788675642068522522938d-1,kind=dp)\n exact_roots(39) = cmplx(-1.274999735463630001995395653459879637298616757217284d-1, &\n -9.874609094894567922074076807929788675642068522522938d-1,kind=dp)\n exact_roots(40) = cmplx(-1.42334819203540667677618453136202688358025283954839d-2, &\n -1.0329147752136441093950134026551104360994260360822540d0,kind=dp)\n exact_roots(41) = cmplx(-1.42334819203540667677618453136202688358025283954839d-2, &\n 1.0329147752136441093950134026551104360994260360822540d0,kind=dp)\n exact_roots(42) = cmplx(-6.98356849626139181796649107548406610452886379651341d-3, &\n -1.0036038622882895485307049669513531297649273745391915d0,kind=dp)\n exact_roots(43) = cmplx(-6.98356849626139181796649107548406610452886379651341d-3, &\n 1.0036038622882895485307049669513531297649273745391915d0,kind=dp)\n exact_roots(44) = cmplx( 1.4895466603687646529815779208794106185666477731693128d-2, &\n -8.481487619084165277193311117832376290806619901265058603d-1,kind=dp)\n exact_roots(45) = cmplx( 1.4895466603687646529815779208794106185666477731693128d-2, &\n 8.481487619084165277193311117832376290806619901265058603d-1,kind=dp)\n exact_roots(46) = cmplx( 1.211927861059064863147044434105037593859287800520963579338d-1, &\n 6.1061169221075421167538724415035774824319702690063863369691d-1,kind=dp)\n exact_roots(47) = cmplx( 1.211927861059064863147044434105037593859287800520963579338d-1, &\n -6.1061169221075421167538724415035774824319702690063863369691d-1,kind=dp)\n exact_roots(48) = cmplx( 3.52482539722363278193253964052161589243593334212239870706d-1, &\n -6.98337239583330331258141954760484537633150485928512286760d-1,kind=dp)\n exact_roots(49) = cmplx( 3.52482539722363278193253964052161589243593334212239870706d-1, &\n 6.98337239583330331258141954760484537633150485928512286760d-1,kind=dp)\n exact_roots(50) = cmplx( 3.7600868184676755970480431772902286888800357334637481632029182d-1, &\n -1.4474937132163286474711018201298830556966056842762643026975894d-1,kind=dp)\n exact_roots(51) = cmplx( 3.7600868184676755970480431772902286888800357334637481632029182d-1, &\n 1.4474937132163286474711018201298830556966056842762643026975894d-1,kind=dp)\n exact_roots(52) = cmplx( 3.76893240379311323690004017968512473363482317941533875341d-1, &\n 6.78568693190448141957540792996773280196881194582788907016d-1,kind=dp)\n exact_roots(53) = cmplx( 3.76893240379311323690004017968512473363482317941533875341d-1, &\n -6.78568693190448141957540792996773280196881194582788907016d-1,kind=dp)\n exact_roots(54) = cmplx( 3.865391765961580265082930869043677799284877313516569138807d-1, &\n 5.693247113031029032137923571351905081619323911951388853856d-1,kind=dp)\n exact_roots(55) = cmplx( 3.865391765961580265082930869043677799284877313516569138807d-1, &\n -5.693247113031029032137923571351905081619323911951388853856d-1,kind=dp)\n exact_roots(56) = cmplx( 4.12916024722700479197334566382612257174765142865547121703d-1, &\n 6.148067601433856949545497204007997358291659758563137777616d-1,kind=dp)\n exact_roots(57) = cmplx( 4.12916024722700479197334566382612257174765142865547121703d-1, &\n -6.148067601433856949545497204007997358291659758563137777616d-1,kind=dp)\n exact_roots(58) = cmplx( 4.3237619264199450782466964808692137388785063987699403620424125d-1, &\n 2.267599044353486186978765599716989721202321914603899690444951d-1,kind=dp)\n exact_roots(59) = cmplx( 4.3237619264199450782466964808692137388785063987699403620424125d-1, &\n -2.267599044353486186978765599716989721202321914603899690444951d-1,kind=dp)\n exact_roots(60) = cmplx( 4.52774498724915493508803077732546131473562000961307327749350d-1, &\n -3.96170128033165002412596877271155937712569079351815707744770d-1,kind=dp)\n exact_roots(61) = cmplx( 4.52774498724915493508803077732546131473562000961307327749350d-1, &\n 3.96170128033165002412596877271155937712569079351815707744770d-1,kind=dp)\n exact_roots(62) = cmplx( 4.56823285823316651283953236253270107801699459631329688710054d-1, &\n 3.47758700883481983632188723200264206004781117755664551397643d-1,kind=dp)\n exact_roots(63) = cmplx( 4.56823285823316651283953236253270107801699459631329688710054d-1, &\n -3.47758700883481983632188723200264206004781117755664551397643d-1,kind=dp) \n ! polynomial\n p(1) = 1d0\n p(2) = 1d0\n p(3) = 2d0\n p(4) = 5d0\n p(5) = 14d0\n p(6) = 42d0\n p(7) = 132d0\n p(8) = 365d0\n p(9) = 950d0\n p(10) = 2398d0\n p(11) = 5916d0\n p(12) = 14290d0\n p(13) = 33708d0\n p(14) = 77684d0\n p(15) = 175048d0\n p(16) = 385741d0\n p(17) = 831014d0\n p(18) = 1749654d0\n p(19) = 3598964d0\n p(20) = 7228014d0\n p(21) = 14162220d0\n p(22) = 27049196d0\n p(23) = 50323496d0\n p(24) = 91143114d0\n p(25) = 160617860d0\n p(26) = 275276716d0\n p(27) = 458591432d0\n p(28) = 742179284d0\n p(29) = 1166067016d0\n p(30) = 1777171560d0\n p(31) = 2625062128d0\n p(32) = 3754272037d0\n p(33) = 5193067630d0\n p(34) = 6939692682d0\n p(35) = 8948546308d0\n p(36) = 11120136162d0\n p(37) = 13299362332d0\n p(38) = 15286065700d0\n p(39) = 16859410792d0\n p(40) = 17813777994d0\n p(41) = 17999433372d0\n p(42) = 17357937708d0\n p(43) = 15941684776d0\n p(44) = 13910043524d0\n p(45) = 11500901864d0\n p(46) = 8984070856d0\n p(47) = 6609143792d0\n p(48) = 4562339774d0\n p(49) = 2943492972d0\n p(50) = 1766948340d0\n p(51) = 981900168d0\n p(52) = 502196500d0\n p(53) = 234813592d0\n p(54) = 99582920d0\n p(55) = 37945904d0\n p(56) = 12843980d0\n p(57) = 3807704d0\n p(58) = 971272d0\n p(59) = 208336d0\n p(60) = 36440d0\n p(61) = 4976d0\n p(62) = 496d0\n p(63) = 32d0\n p(64) = 1d0 \n write(1, '(A)', advance='no') '14, '\n ! FPML\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n call main(p, deg, roots, berr, cond, conv, nitmax)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(roots,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(roots, berr, cond, conv)\n ! Polzeros\n allocate(zeros(deg), radius(deg), h(deg+1))\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(zeros,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(zeros, radius, h)\n ! AMVW\n allocate(poly(deg+1), eigs(deg), residuals(deg))\n poly = (/ (p(deg-j+1), j=0,deg)/)\n call z_poly_roots(deg, poly, eigs, residuals, flag)\n write(1, '(ES15.2)') maxrel_fwderr(eigs,exact_roots,deg)\n deallocate(poly, eigs, residuals)\n ! deallocate polynomial arrays\n deallocate(exact_roots, p)\n \n ! Poly 15: Jenkins Traub p1(z) with a=1e-8\n deg = 3\n allocate(coeffs(deg), exact_roots(deg), p(deg+1), xr(deg), xi(deg))\n ! roots\n exact_roots(1) = cmplx(1d-8,0d0,kind=dp)\n exact_roots(2) = cmplx(-1d-8,0d0,kind=dp)\n exact_roots(3) = cmplx(1d0,0d0,kind=dp)\n xr = dble(exact_roots)\n xi = aimag(exact_roots)\n ! polynomial\n call rootstocoeffs(deg,xr,xi,coeffs)\n p(1:deg) = (/ (cmplx(coeffs(j),0,kind=dp), j=1,deg)/)\n p(deg+1) = cmplx(1,0,kind=dp)\n write(1, '(A)', advance='no') '15, '\n ! FPML\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n call main(p, deg, roots, berr, cond, conv, nitmax)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(roots,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(roots, berr, cond, conv)\n ! Polzeros\n allocate(zeros(deg), radius(deg), h(deg+1))\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(zeros,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(zeros, radius, h)\n ! AMVW\n allocate(poly(deg+1), eigs(deg), residuals(deg))\n poly = (/ (p(deg-j+1), j=0,deg)/)\n call z_poly_roots(deg, poly, eigs, residuals, flag)\n write(1, '(ES15.2)') maxrel_fwderr(eigs,exact_roots,deg)\n deallocate(poly, eigs, residuals)\n ! deallocate polynomial arrays\n deallocate(coeffs, exact_roots, p, xr, xi)\n \n ! Poly 16: Jenkins Traub p1(z) with a=1e-15\n deg = 3\n allocate(coeffs(deg), exact_roots(deg), p(deg+1), xr(deg), xi(deg))\n ! roots\n exact_roots(1) = cmplx(1d-15,0d0,kind=dp)\n exact_roots(2) = cmplx(-1d-15,0d0,kind=dp)\n exact_roots(3) = cmplx(1d0,0d0,kind=dp)\n xr = dble(exact_roots)\n xi = aimag(exact_roots)\n ! polynomial\n call rootstocoeffs(deg,xr,xi,coeffs)\n p(1:deg) = (/ (cmplx(coeffs(j),0,kind=dp), j=1,deg)/)\n p(deg+1) = cmplx(1,0,kind=dp)\n write(1, '(A)', advance='no') '16, '\n ! FPML\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n call main(p, deg, roots, berr, cond, conv, nitmax)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(roots,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(roots, berr, cond, conv)\n ! Polzeros\n allocate(zeros(deg), radius(deg), h(deg+1))\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(zeros,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(zeros, radius, h)\n ! AMVW\n allocate(poly(deg+1), eigs(deg), residuals(deg))\n poly = (/ (p(deg-j+1), j=0,deg)/)\n call z_poly_roots(deg, poly, eigs, residuals, flag)\n write(1, '(ES15.2)') maxrel_fwderr(eigs,exact_roots,deg)\n deallocate(poly, eigs, residuals)\n ! deallocate polynomial arrays\n deallocate(coeffs, exact_roots, p, xr, xi)\n \n ! Poly 17: Jenkins Traub p1(z) with a=1e+8\n deg = 3\n allocate(coeffs(deg), exact_roots(deg), p(deg+1), xr(deg), xi(deg))\n ! roots\n exact_roots(1) = cmplx(1d+8,0d0,kind=dp)\n exact_roots(2) = cmplx(-1d+8,0d0,kind=dp)\n exact_roots(3) = cmplx(1d0,0d0,kind=dp)\n xr = dble(exact_roots)\n xi = aimag(exact_roots)\n ! polynomial\n call rootstocoeffs(deg,xr,xi,coeffs)\n p(1:deg) = (/ (cmplx(coeffs(j),0,kind=dp), j=1,deg)/)\n p(deg+1) = cmplx(1,0,kind=dp)\n write(1, '(A)', advance='no') '17, '\n ! FPML\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n call main(p, deg, roots, berr, cond, conv, nitmax)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(roots,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(roots, berr, cond, conv)\n ! Polzeros\n allocate(zeros(deg), radius(deg), h(deg+1))\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(zeros,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(zeros, radius, h)\n ! AMVW\n allocate(poly(deg+1), eigs(deg), residuals(deg))\n poly = (/ (p(deg-j+1), j=0,deg)/)\n call z_poly_roots(deg, poly, eigs, residuals, flag)\n write(1, '(ES15.2)') maxrel_fwderr(eigs,exact_roots,deg)\n deallocate(poly, eigs, residuals)\n ! deallocate polynomial arrays\n deallocate(coeffs, exact_roots, p, xr, xi)\n \n ! Poly 18: Jenkins Traub p1(z) with a=1e+15\n deg = 3\n allocate(coeffs(deg), exact_roots(deg), p(deg+1), xr(deg), xi(deg))\n ! roots\n exact_roots(1) = cmplx(1d+15,0d0,kind=dp)\n exact_roots(2) = cmplx(-1d+15,0d0,kind=dp)\n exact_roots(3) = cmplx(1d0,0d0,kind=dp)\n xr = dble(exact_roots)\n xi = aimag(exact_roots)\n ! polynomial\n call rootstocoeffs(deg,xr,xi,coeffs)\n p(1:deg) = (/ (cmplx(coeffs(j),0,kind=dp), j=1,deg)/)\n p(deg+1) = cmplx(1,0,kind=dp)\n write(1, '(A)', advance='no') '18, '\n ! FPML\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n call main(p, deg, roots, berr, cond, conv, nitmax)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(roots,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(roots, berr, cond, conv)\n ! Polzeros\n allocate(zeros(deg), radius(deg), h(deg+1))\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(zeros,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(zeros, radius, h)\n ! AMVW\n allocate(poly(deg+1), eigs(deg), residuals(deg))\n poly = (/ (p(deg-j+1), j=0,deg)/)\n call z_poly_roots(deg, poly, eigs, residuals, flag)\n write(1, '(ES15.2)') maxrel_fwderr(eigs,exact_roots,deg)\n deallocate(poly, eigs, residuals)\n ! deallocate polynomial arrays\n deallocate(coeffs, exact_roots, p, xr, xi)\n \n ! Poly 19: Jenkins Traub p3(z) deg 10\n deg = 10\n allocate(coeffs(deg), exact_roots(deg), p(deg+1), xr(deg), xi(deg))\n ! roots\n exact_roots(1) = cmplx(1d-1,0d0,kind=dp)\n exact_roots(2) = cmplx(1d-2,0d0,kind=dp)\n exact_roots(3) = cmplx(1d-3,0d0,kind=dp)\n exact_roots(4) = cmplx(1d-4,0d0,kind=dp)\n exact_roots(5) = cmplx(1d-5,0d0,kind=dp)\n exact_roots(6) = cmplx(1d-6,0d0,kind=dp)\n exact_roots(7) = cmplx(1d-7,0d0,kind=dp)\n exact_roots(8) = cmplx(1d-8,0d0,kind=dp)\n exact_roots(9) = cmplx(1d-9,0d0,kind=dp)\n exact_roots(10) = cmplx(1d-10,0d0,kind=dp)\n xr = dble(exact_roots)\n xi = aimag(exact_roots)\n ! polynomial\n call rootstocoeffs(deg,xr,xi,coeffs)\n p(1:deg) = (/ (cmplx(coeffs(j),0,kind=dp), j=1,deg)/)\n p(deg+1) = cmplx(1,0,kind=dp)\n write(1, '(A)', advance='no') '19, '\n ! FPML\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n call main(p, deg, roots, berr, cond, conv, nitmax)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(roots,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(roots, berr, cond, conv)\n ! Polzeros\n allocate(zeros(deg), radius(deg), h(deg+1))\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(zeros,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(zeros, radius, h)\n ! AMVW\n allocate(poly(deg+1), eigs(deg), residuals(deg))\n poly = (/ (p(deg-j+1), j=0,deg)/)\n call z_poly_roots(deg, poly, eigs, residuals, flag)\n write(1, '(ES15.2)') maxrel_fwderr(eigs,exact_roots,deg)\n deallocate(poly, eigs, residuals)\n ! deallocate polynomial arrays\n deallocate(coeffs, exact_roots, p, xr, xi)\n \n ! Poly 20: Jenkins Traub p3(z) deg 20\n deg = 20\n allocate(coeffs(deg), exact_roots(deg), p(deg+1), xr(deg), xi(deg))\n ! roots\n exact_roots(1) = cmplx(1d-1,0d0,kind=dp)\n exact_roots(2) = cmplx(1d-2,0d0,kind=dp)\n exact_roots(3) = cmplx(1d-3,0d0,kind=dp)\n exact_roots(4) = cmplx(1d-4,0d0,kind=dp)\n exact_roots(5) = cmplx(1d-5,0d0,kind=dp)\n exact_roots(6) = cmplx(1d-6,0d0,kind=dp)\n exact_roots(7) = cmplx(1d-7,0d0,kind=dp)\n exact_roots(8) = cmplx(1d-8,0d0,kind=dp)\n exact_roots(9) = cmplx(1d-9,0d0,kind=dp)\n exact_roots(10) = cmplx(1d-10,0d0,kind=dp)\n exact_roots(11) = cmplx(1d-11,0d0,kind=dp)\n exact_roots(12) = cmplx(1d-12,0d0,kind=dp)\n exact_roots(13) = cmplx(1d-13,0d0,kind=dp)\n exact_roots(14) = cmplx(1d-14,0d0,kind=dp)\n exact_roots(15) = cmplx(1d-15,0d0,kind=dp)\n exact_roots(16) = cmplx(1d-16,0d0,kind=dp)\n exact_roots(17) = cmplx(1d-17,0d0,kind=dp)\n exact_roots(18) = cmplx(1d-18,0d0,kind=dp)\n exact_roots(19) = cmplx(1d-19,0d0,kind=dp)\n exact_roots(20) = cmplx(1d-20,0d0,kind=dp)\n xr = dble(exact_roots)\n xi = aimag(exact_roots)\n ! polynomial\n call rootstocoeffs(deg,xr,xi,coeffs)\n p(1:deg) = (/ (cmplx(coeffs(j),0,kind=dp), j=1,deg)/)\n p(deg+1) = cmplx(1,0,kind=dp)\n write(1, '(A)', advance='no') '20, '\n ! FPML\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n call main(p, deg, roots, berr, cond, conv, nitmax)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(roots,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(roots, berr, cond, conv)\n ! Polzeros\n allocate(zeros(deg), radius(deg), h(deg+1))\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(zeros,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(zeros, radius, h)\n ! AMVW\n allocate(poly(deg+1), eigs(deg), residuals(deg))\n poly = (/ (p(deg-j+1), j=0,deg)/)\n call z_poly_roots(deg, poly, eigs, residuals, flag)\n write(1, '(ES15.2)') maxrel_fwderr(eigs,exact_roots,deg)\n deallocate(poly, eigs, residuals)\n ! deallocate polynomial arrays\n deallocate(coeffs, exact_roots, p, xr, xi)\n \n ! Poly 21: Jenkins Traub p4(z)\n deg = 6\n allocate(coeffs(deg), exact_roots(deg), p(deg+1), xr(deg), xi(deg))\n ! roots\n exact_roots(1) = 1d-1\n exact_roots(2) = 1d-1\n exact_roots(3) = 1d-1\n exact_roots(4) = 5d-1\n exact_roots(5) = 6d-1\n exact_roots(6) = 7d-1\n xr = dble(exact_roots)\n xi = aimag(exact_roots)\n ! polynomial\n call rootstocoeffs(deg,xr,xi,coeffs)\n p(1:deg) = (/ (cmplx(coeffs(j),0,kind=dp), j=1,deg)/)\n p(deg+1) = cmplx(1,0,kind=dp)\n write(1, '(A)', advance='no') '21, '\n ! FPML\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n call main(p, deg, roots, berr, cond, conv, nitmax)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(roots,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(roots, berr, cond, conv)\n ! Polzeros\n allocate(zeros(deg), radius(deg), h(deg+1))\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(zeros,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(zeros, radius, h)\n ! AMVW\n allocate(poly(deg+1), eigs(deg), residuals(deg))\n poly = (/ (p(deg-j+1), j=0,deg)/)\n call z_poly_roots(deg, poly, eigs, residuals, flag)\n write(1, '(ES15.2)') maxrel_fwderr(eigs,exact_roots,deg)\n deallocate(poly, eigs, residuals)\n ! deallocate polynomial arrays\n deallocate(coeffs, exact_roots, p, xr, xi)\n \n ! Poly 22: Jenkins Traub p5(z)\n deg = 10\n allocate(coeffs(deg), exact_roots(deg), p(deg+1), xr(deg), xi(deg))\n ! roots\n exact_roots(1) = 1d-1\n exact_roots(2) = 1d-1\n exact_roots(3) = 1d-1\n exact_roots(4) = 1d-1\n exact_roots(5) = 2d-1\n exact_roots(6) = 2d-1\n exact_roots(7) = 2d-1\n exact_roots(8) = 3d-1\n exact_roots(9) = 3d-1\n exact_roots(10) = 4d-1\n xr = dble(exact_roots)\n xi = aimag(exact_roots)\n ! polynomial\n call rootstocoeffs(deg,xr,xi,coeffs)\n p(1:deg) = (/ (cmplx(coeffs(j),0,kind=dp), j=1,deg)/)\n p(deg+1) = cmplx(1,0,kind=dp)\n write(1, '(A)', advance='no') '22, '\n ! FPML\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n call main(p, deg, roots, berr, cond, conv, nitmax)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(roots,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(roots, berr, cond, conv)\n ! Polzeros\n allocate(zeros(deg), radius(deg), h(deg+1))\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(zeros,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(zeros, radius, h)\n ! AMVW\n allocate(poly(deg+1), eigs(deg), residuals(deg))\n poly = (/ (p(deg-j+1), j=0,deg)/)\n call z_poly_roots(deg, poly, eigs, residuals, flag)\n write(1, '(ES15.2)') maxrel_fwderr(eigs,exact_roots,deg)\n deallocate(poly, eigs, residuals)\n ! deallocate polynomial arrays\n deallocate(coeffs, exact_roots, p, xr, xi)\n \n ! Poly 23: Jenkins Traub p6(z)\n deg = 5\n allocate(coeffs(deg), exact_roots(deg), p(deg+1), xr(deg), xi(deg))\n ! roots\n exact_roots(1) = 1d-1\n exact_roots(2) = 1001d-3\n exact_roots(3) = 998d-3\n exact_roots(4) = 100002d-5\n exact_roots(5) = 99999d-5\n xr = dble(exact_roots)\n xi = aimag(exact_roots)\n ! polynomial\n call rootstocoeffs(deg,xr,xi,coeffs)\n p(1:deg) = (/ (cmplx(coeffs(j),0,kind=dp), j=1,deg)/)\n p(deg+1) = cmplx(1,0,kind=dp)\n write(1, '(A)', advance='no') '23, '\n ! FPML\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n call main(p, deg, roots, berr, cond, conv, nitmax)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(roots,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(roots, berr, cond, conv)\n ! Polzeros\n allocate(zeros(deg), radius(deg), h(deg+1))\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(zeros,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(zeros, radius, h)\n ! AMVW\n allocate(poly(deg+1), eigs(deg), residuals(deg))\n poly = (/ (p(deg-j+1), j=0,deg)/)\n call z_poly_roots(deg, poly, eigs, residuals, flag)\n write(1, '(ES15.2)') maxrel_fwderr(eigs,exact_roots,deg)\n deallocate(poly, eigs, residuals)\n ! deallocate polynomial arrays\n deallocate(coeffs, exact_roots, p, xr, xi)\n \n ! Poly 24: Jenkins Traub p7(z) with a=0\n deg = 7\n allocate(coeffs(deg), exact_roots(deg), p(deg+1), xr(deg), xi(deg))\n ! roots\n exact_roots(1) = 1d-3\n exact_roots(2) = 1d-2\n exact_roots(3) = 1d-1\n exact_roots(4) = 1d-1\n exact_roots(5) = 1d-1\n exact_roots(6) = 1d0\n exact_roots(7) = 1d+1\n xr = dble(exact_roots)\n xi = aimag(exact_roots)\n ! polynomial\n call rootstocoeffs(deg,xr,xi,coeffs)\n p(1:deg) = (/ (cmplx(coeffs(j),0,kind=dp), j=1,deg)/)\n p(deg+1) = cmplx(1,0,kind=dp)\n write(1, '(A)', advance='no') '24, '\n ! FPML\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n call main(p, deg, roots, berr, cond, conv, nitmax)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(roots,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(roots, berr, cond, conv)\n ! Polzeros\n allocate(zeros(deg), radius(deg), h(deg+1))\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(zeros,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(zeros, radius, h)\n ! AMVW\n allocate(poly(deg+1), eigs(deg), residuals(deg))\n poly = (/ (p(deg-j+1), j=0,deg)/)\n call z_poly_roots(deg, poly, eigs, residuals, flag)\n write(1, '(ES15.2)') maxrel_fwderr(eigs,exact_roots,deg)\n deallocate(poly, eigs, residuals)\n ! deallocate polynomial arrays\n deallocate(coeffs, exact_roots, p, xr, xi)\n \n ! Poly 25: Jenkins Traub p7(z) with a=10^(-10)\n deg = 7\n allocate(coeffs(deg), exact_roots(deg), p(deg+1), xr(deg), xi(deg))\n ! roots\n exact_roots(1) = 1d-3\n exact_roots(2) = 1d-2\n exact_roots(3) = 1d-1\n exact_roots(4) = cmplx(1d-1,1d-10,kind=dp)\n exact_roots(5) = cmplx(1d-1,-1d-10,kind=dp)\n exact_roots(6) = 1d0\n exact_roots(7) = 1d+1\n xr = dble(exact_roots)\n xi = aimag(exact_roots)\n ! polynomial\n call rootstocoeffs(deg,xr,xi,coeffs)\n p(1:deg) = (/ (cmplx(coeffs(j),0,kind=dp), j=1,deg)/)\n p(deg+1) = cmplx(1,0,kind=dp)\n write(1, '(A)', advance='no') '25, '\n ! FPML\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n call main(p, deg, roots, berr, cond, conv, nitmax)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(roots,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(roots, berr, cond, conv)\n ! Polzeros\n allocate(zeros(deg), radius(deg), h(deg+1))\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(zeros,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(zeros, radius, h)\n ! AMVW\n allocate(poly(deg+1), eigs(deg), residuals(deg))\n poly = (/ (p(deg-j+1), j=0,deg)/)\n call z_poly_roots(deg, poly, eigs, residuals, flag)\n write(1, '(ES15.2)') maxrel_fwderr(eigs,exact_roots,deg)\n deallocate(poly, eigs, residuals)\n ! deallocate polynomial arrays\n deallocate(coeffs, exact_roots, p, xr, xi)\n \n ! Poly 26: Jenkins Traub p7(z) with a=10^(-6)\n deg = 7\n allocate(coeffs(deg), exact_roots(deg), p(deg+1), xr(deg), xi(deg))\n ! roots\n exact_roots(1) = 1d-3\n exact_roots(2) = 1d-2\n exact_roots(3) = 1d-1\n exact_roots(4) = cmplx(1d-1,1d-6,kind=dp)\n exact_roots(5) = cmplx(1d-1,-1d-6,kind=dp)\n exact_roots(6) = 1d0\n exact_roots(7) = 1d+1\n xr = dble(exact_roots)\n xi = aimag(exact_roots)\n ! polynomial\n call rootstocoeffs(deg,xr,xi,coeffs)\n p(1:deg) = (/ (cmplx(coeffs(j),0,kind=dp), j=1,deg)/)\n p(deg+1) = cmplx(1,0,kind=dp)\n write(1, '(A)', advance='no') '26, '\n ! FPML\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n call main(p, deg, roots, berr, cond, conv, nitmax)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(roots,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(roots, berr, cond, conv)\n ! Polzeros\n allocate(zeros(deg), radius(deg), h(deg+1))\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(zeros,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(zeros, radius, h)\n ! AMVW\n allocate(poly(deg+1), eigs(deg), residuals(deg))\n poly = (/ (p(deg-j+1), j=0,deg)/)\n call z_poly_roots(deg, poly, eigs, residuals, flag)\n write(1, '(ES15.2)') maxrel_fwderr(eigs,exact_roots,deg)\n deallocate(poly, eigs, residuals)\n ! deallocate polynomial arrays\n deallocate(coeffs, exact_roots, p, xr, xi)\n \n ! Poly 27: Jenkins Traub p8(z)\n deg = 5\n allocate(coeffs(deg), exact_roots(deg), p(deg+1), xr(deg), xi(deg))\n ! roots\n exact_roots(1) = -1d0\n exact_roots(2) = -1d0\n exact_roots(3) = -1d0\n exact_roots(4) = -1d0\n exact_roots(5) = -1d0\n xr = dble(exact_roots)\n xi = aimag(exact_roots)\n ! polynomial\n call rootstocoeffs(deg,xr,xi,coeffs)\n p(1:deg) = (/ (cmplx(coeffs(j),0,kind=dp), j=1,deg)/)\n p(deg+1) = cmplx(1,0,kind=dp)\n write(1, '(A)', advance='no') '27, '\n ! FPML\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n call main(p, deg, roots, berr, cond, conv, nitmax)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(roots,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(roots, berr, cond, conv)\n ! Polzeros\n allocate(zeros(deg), radius(deg), h(deg+1))\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(zeros,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(zeros, radius, h)\n ! AMVW\n allocate(poly(deg+1), eigs(deg), residuals(deg))\n poly = (/ (p(deg-j+1), j=0,deg)/)\n call z_poly_roots(deg, poly, eigs, residuals, flag)\n write(1, '(ES15.2)') maxrel_fwderr(eigs,exact_roots,deg)\n deallocate(poly, eigs, residuals)\n ! deallocate polynomial arrays\n deallocate(coeffs, exact_roots, p, xr, xi)\n \n ! Poly 28: Jenkins Traub p9(z)\n deg = 20\n allocate(coeffs(deg), exact_roots(deg), p(deg+1), xr(deg), xi(deg))\n ! roots\n exact_roots(1) = cmplx(+1d-2,0d0,kind=dp)\n exact_roots(2) = cmplx(-1d-2,0d0,kind=dp)\n exact_roots(3) = cmplx(0d0,+1d+2,kind=dp)\n exact_roots(4) = cmplx(0d0,-1d+2,kind=dp)\n exact_roots(5) = cmplx(-95.105651629515357212d0,+30.901699437494742410d0,kind=dp)\n exact_roots(6) = cmplx(-95.105651629515357212d0,-30.901699437494742410d0,kind=dp)\n exact_roots(7) = cmplx(-0.0080901699437494742410d0,+0.0058778525229247312917d0,kind=dp)\n exact_roots(8) = cmplx(-0.0080901699437494742410d0,-0.0058778525229247312917d0,kind=dp)\n exact_roots(9) = cmplx(-58.778525229247312917d0,+80.901699437494742410d0,kind=dp)\n exact_roots(10) = cmplx(-58.778525229247312917d0,-80.901699437494742410d0,kind=dp)\n exact_roots(11) = cmplx(-0.0030901699437494742410d0,+0.0095105651629515357212d0,kind=dp)\n exact_roots(12) = cmplx(-0.0030901699437494742410d0,-0.0095105651629515357212d0,kind=dp) \n exact_roots(13) = cmplx(+95.105651629515357212d0,+30.901699437494742410d0,kind=dp)\n exact_roots(14) = cmplx(+95.105651629515357212d0,-30.901699437494742410d0,kind=dp)\n exact_roots(15) = cmplx(+0.0080901699437494742410d0,+0.0058778525229247312917d0,kind=dp)\n exact_roots(16) = cmplx(+0.0080901699437494742410d0,-0.0058778525229247312917d0,kind=dp)\n exact_roots(17) = cmplx(+58.778525229247312917d0,+80.901699437494742410d0,kind=dp)\n exact_roots(18) = cmplx(+58.778525229247312917d0,-80.901699437494742410d0,kind=dp)\n exact_roots(19) = cmplx(+0.0030901699437494742410d0,+0.0095105651629515357212d0,kind=dp)\n exact_roots(20) = cmplx(+0.0030901699437494742410d0,-0.0095105651629515357212d0,kind=dp)\n xr = dble(exact_roots)\n xi = aimag(exact_roots)\n ! polynomial\n call rootstocoeffs(deg,xr,xi,coeffs)\n p(1:deg) = (/ (cmplx(coeffs(j),0,kind=dp), j=1,deg)/)\n p(deg+1) = cmplx(1,0,kind=dp)\n write(1, '(A)', advance='no') '28, '\n ! FPML\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n call main(p, deg, roots, berr, cond, conv, nitmax)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(roots,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(roots, berr, cond, conv)\n ! Polzeros\n allocate(zeros(deg), radius(deg), h(deg+1))\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(zeros,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(zeros, radius, h)\n ! AMVW\n allocate(poly(deg+1), eigs(deg), residuals(deg))\n poly = (/ (p(deg-j+1), j=0,deg)/)\n call z_poly_roots(deg, poly, eigs, residuals, flag)\n write(1, '(ES15.2)') maxrel_fwderr(eigs,exact_roots,deg)\n deallocate(poly, eigs, residuals)\n ! deallocate polynomial arrays\n deallocate(coeffs, exact_roots, p, xr, xi)\n \n ! Poly 29: Jenkins Traub p10(z) with a=1e+3\n deg = 3\n allocate(coeffs(deg), exact_roots(deg), p(deg+1), xr(deg), xi(deg))\n ! roots\n exact_roots(1) = 1d+3\n exact_roots(2) = 1d0\n exact_roots(3) = 1d-3\n xr = dble(exact_roots)\n xi = aimag(exact_roots)\n ! polynomial\n call rootstocoeffs(deg,xr,xi,coeffs)\n p(1:deg) = (/ (cmplx(coeffs(j),0,kind=dp), j=1,deg)/)\n p(deg+1) = cmplx(1,0,kind=dp)\n write(1, '(A)', advance='no') '29, '\n ! FPML\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n call main(p, deg, roots, berr, cond, conv, nitmax)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(roots,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(roots, berr, cond, conv)\n ! Polzeros\n allocate(zeros(deg), radius(deg), h(deg+1))\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(zeros,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(zeros, radius, h)\n ! AMVW\n allocate(poly(deg+1), eigs(deg), residuals(deg))\n poly = (/ (p(deg-j+1), j=0,deg)/)\n call z_poly_roots(deg, poly, eigs, residuals, flag)\n write(1, '(ES15.2)') maxrel_fwderr(eigs,exact_roots,deg)\n deallocate(poly, eigs, residuals)\n ! deallocate polynomial arrays\n deallocate(coeffs, exact_roots, p, xr, xi)\n \n ! Poly 30: Jenkins Traub p10(z) with a=1e+6\n deg = 3\n allocate(coeffs(deg), exact_roots(deg), p(deg+1), xr(deg), xi(deg))\n ! roots\n exact_roots(1) = 1d+6\n exact_roots(2) = 1d0\n exact_roots(3) = 1d-6\n xr = dble(exact_roots)\n xi = aimag(exact_roots)\n ! polynomial\n call rootstocoeffs(deg,xr,xi,coeffs)\n p(1:deg) = (/ (cmplx(coeffs(j),0,kind=dp), j=1,deg)/)\n p(deg+1) = cmplx(1,0,kind=dp)\n write(1, '(A)', advance='no') '30, '\n ! FPML\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n call main(p, deg, roots, berr, cond, conv, nitmax)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(roots,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(roots, berr, cond, conv)\n ! Polzeros\n allocate(zeros(deg), radius(deg), h(deg+1))\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(zeros,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(zeros, radius, h)\n ! AMVW\n allocate(poly(deg+1), eigs(deg), residuals(deg))\n poly = (/ (p(deg-j+1), j=0,deg)/)\n call z_poly_roots(deg, poly, eigs, residuals, flag)\n write(1, '(ES15.2)') maxrel_fwderr(eigs,exact_roots,deg)\n deallocate(poly, eigs, residuals)\n ! deallocate polynomial arrays\n deallocate(coeffs, exact_roots, p, xr, xi)\n \n ! Poly 31: Jenkins Traub p10(z) with a=1e+9\n deg = 3\n allocate(coeffs(deg), exact_roots(deg), p(deg+1), xr(deg), xi(deg))\n ! roots\n exact_roots(1) = 1d+9\n exact_roots(2) = 1d0\n exact_roots(3) = 1d-9\n xr = dble(exact_roots)\n xi = aimag(exact_roots)\n ! polynomial\n call rootstocoeffs(deg,xr,xi,coeffs)\n p(1:deg) = (/ (cmplx(coeffs(j),0,kind=dp), j=1,deg)/)\n p(deg+1) = cmplx(1,0,kind=dp)\n write(1, '(A)', advance='no') '31, '\n ! FPML\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n call main(p, deg, roots, berr, cond, conv, nitmax)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(roots,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(roots, berr, cond, conv)\n ! Polzeros\n allocate(zeros(deg), radius(deg), h(deg+1))\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(zeros,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(zeros, radius, h)\n ! AMVW\n allocate(poly(deg+1), eigs(deg), residuals(deg))\n poly = (/ (p(deg-j+1), j=0,deg)/)\n call z_poly_roots(deg, poly, eigs, residuals, flag)\n write(1, '(ES15.2)') maxrel_fwderr(eigs,exact_roots,deg)\n deallocate(poly, eigs, residuals)\n ! deallocate polynomial arrays\n deallocate(coeffs, exact_roots, p, xr, xi)\n \n ! Poly 32: Jenkins Traub p11(z) with m=15\n deg = 60\n allocate(coeffs(deg), exact_roots(deg), p(deg+1), xr(deg), xi(deg))\n ! roots\n do j=-14,0\n exact_roots(15+j) = 0.9d0*cmplx(cos(j*pi/30d0),sin(j*pi/30d0),kind=dp)\n end do\n do j=1,15\n exact_roots(15+j) = conjg(exact_roots(16-j))\n end do\n do j=16,30\n exact_roots(15+j) = cmplx(cos(j*pi/30d0),sin(j*pi/30d0),kind=dp)\n end do\n do j=31,45\n exact_roots(15+j) = conjg(exact_roots(76-j))\n end do\n xr = dble(exact_roots)\n xi = aimag(exact_roots)\n ! polynomial\n call rootstocoeffs(deg,xr,xi,coeffs)\n p(1:deg) = (/ (cmplx(coeffs(j),0,kind=dp), j=1,deg)/)\n p(deg+1) = cmplx(1,0,kind=dp)\n write(1, '(A)', advance='no') '32, '\n ! FPML\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n call main(p, deg, roots, berr, cond, conv, nitmax)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(roots,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(roots, berr, cond, conv)\n ! Polzeros\n allocate(zeros(deg), radius(deg), h(deg+1))\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(zeros,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(zeros, radius, h)\n ! AMVW\n allocate(poly(deg+1), eigs(deg), residuals(deg))\n poly = (/ (p(deg-j+1), j=0,deg)/)\n call z_poly_roots(deg, poly, eigs, residuals, flag)\n write(1, '(ES15.2)') maxrel_fwderr(eigs,exact_roots,deg)\n deallocate(poly, eigs, residuals)\n ! deallocate polynomial arrays\n deallocate(coeffs, exact_roots, p, xr, xi)\n \n ! Poly 33: Jenkins Traub p11(z) with m=20\n deg = 80\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n do j=-19,0\n exact_roots(20+j) = 0.9d0*cmplx(cos(j*pi/40d0),sin(j*pi/40d0),kind=dp)\n end do\n do j=1,20\n exact_roots(20+j) = conjg(exact_roots(21-j))\n end do\n do j=21,40\n exact_roots(20+j) = cmplx(cos(j*pi/40d0),sin(j*pi/40d0),kind=dp)\n end do\n do j=41,60\n exact_roots(20+j) = conjg(exact_roots(101-j))\n end do\n ! polynomial\n p(1) = 1.4780882941434592332d-2\n p(2) = -4.3442163898274625504d-2\n p(3) = 3.0811061677962020381d-2\n p(4) = 4.8174145573905845167d-2\n p(5) = -9.9895422090259650436d-2\n p(6) = 2.0367593752690566382d-2\n p(7) = 1.02730704300754634317d-1\n p(8) = -7.2421959976329501386d-2\n p(9) = -8.6179510586397895483d-2\n p(10) = 1.11130623035162433422d-1\n p(11) = 6.2288430530155258569d-2\n p(12) = -1.40861180023385154071d-1\n p(13) = -3.5124501490762462669d-2\n p(14) = 1.6457808423330592019d-1\n p(15) = 6.2141637784362712705d-3\n p(16) = -1.8424846472346489127d-1\n p(17) = 2.3887246006411263876d-2\n p(18) = 2.0123660776207915149d-1\n p(19) = -5.5042151404477955885d-2\n p(20) = -2.1655010742652691907d-1\n p(21) = 8.7308247479862632512d-2\n p(22) = 2.3098952256062750832d-1\n p(23) = -1.20839896048866662802d-1\n p(24) = -2.4524316316862245476d-1\n p(25) = 1.5584030932109201157d-1\n p(26) = 2.5995126187880752178d-1\n p(27) = -1.9253542069511053711d-1\n p(28) = -2.7575320187036790325d-1\n p(29) = 2.3115653041457324242d-1\n p(30) = 2.9332567468690245068d-1\n p(31) = -2.7192522443725521915d-1\n p(32) = -3.1341647125406680241d-1\n p(33) = 3.1503664809187655702d-1 \n p(34) = 3.3687681253896948062d-1\n p(35) = -3.6063813116693822381d-1\n p(36) = -3.6469402480999342566d-1\n p(37) = 4.0880023982723262898d-1\n p(38) = 3.9802557620913000863d-1\n p(39) = -4.5947689308160295174d-1\n p(40) = -4.3823476903404861240d-1\n p(41) = 5.1245032822053625773d-1\n p(42) = 4.8692752114894290267d-1\n p(43) = -5.6725542355753450833d-1\n p(44) = -5.4598844473131688426d-1\n p(45) = 6.2307611618233901689d-1\n p(46) = 6.1761253333670921719d-1\n p(47) = -6.7860426870892201356d-1\n p(48) = -7.0432572851500706072d-1\n p(49) = 7.3184818906851594346d-1\n p(50) = 8.0898269490870113069d-1\n p(51) = -7.7987392727599626297d-1\n p(52) = -9.3472202131370181256d-1\n p(53) = 8.1845735150340386619d-1\n p(54) = 1.08484562323120574344d0\n p(55) = -8.4161895105779053806d-1\n p(56) = -1.26256657697771489173d0\n p(57) = 8.4100707730363691321d-1\n p(58) = 1.4705312179546839242d0\n p(59) = -8.0509137325098417157d-1\n p(60) = -1.7099546866515839107d0\n p(61) = 7.1813332727313867947d-1\n p(62) = 1.9790907332021869408d0\n p(63) = -5.5893356802509694516d-1\n p(64) = -2.2705405932583590595d0\n p(65) = 2.9946485119551650496d-1\n p(66) = 2.5664992503440600430d0\n p(67) = 9.6178378249591328894d-2\n p(68) = -2.8302464072142201120d0\n p(69) = -6.7115047960723573009d-1\n p(70) = 2.9906015117111130672d0\n p(71) = 1.4693731680026281359d0\n p(72) = -2.9128354841688884049d0\n p(73) = -2.5098266205260663539d0\n p(74) = 2.3435135157927505630d0\n p(75) = 3.6936432309637431823d0\n p(76) = -8.1367672571926600698d-1\n p(77) = -4.4341996816502822389d0\n p(78) = -2.3759711962084459258d0\n p(79) = 1.6884620531827973326d0\n p(80) = 2.6451699579357078932d0\n p(81) = 1.0000000000000000000d0\n write(1, '(A)', advance='no') '33, '\n ! FPML\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n call main(p, deg, roots, berr, cond, conv, nitmax)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(roots,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(roots, berr, cond, conv)\n ! Polzeros\n allocate(zeros(deg), radius(deg), h(deg+1))\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(zeros,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(zeros, radius, h)\n ! AMVW\n allocate(poly(deg+1), eigs(deg), residuals(deg))\n poly = (/ (p(deg-j+1), j=0,deg)/)\n call z_poly_roots(deg, poly, eigs, residuals, flag)\n write(1, '(ES15.2)') maxrel_fwderr(eigs,exact_roots,deg)\n deallocate(poly, eigs, residuals)\n ! deallocate polynomial arrays\n deallocate(exact_roots, p)\n \n ! Poly 34: Jenkins Traub p11(z) with m=25\n deg = 100\n allocate(coeffs(deg), exact_roots(deg), p(deg+1), xr(deg), xi(deg))\n ! roots\n do j=-24,0\n exact_roots(25+j) = 0.9d0*cmplx(cos(j*pi/50d0),sin(j*pi/50d0),kind=dp)\n end do\n do j=1,25\n exact_roots(25+j) = conjg(exact_roots(26-j))\n end do\n do j=26,50\n exact_roots(25+j) = cmplx(cos(j*pi/50d0),sin(j*pi/50d0),kind=dp)\n end do\n do j=51,75\n exact_roots(25+j) = conjg(exact_roots(126-j))\n end do\n xr = dble(exact_roots)\n xi = aimag(exact_roots)\n ! polynomial\n call rootstocoeffs(deg,xr,xi,coeffs)\n p(1:deg) = (/ (cmplx(coeffs(j),0,kind=dp), j=1,deg)/)\n p(deg+1) = cmplx(1,0,kind=dp)\n write(1, '(A)', advance='no') '34, '\n ! FPML\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n call main(p, deg, roots, berr, cond, conv, nitmax)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(roots,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(roots, berr, cond, conv)\n ! Polzeros\n allocate(zeros(deg), radius(deg), h(deg+1))\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n write(1, '(ES15.2)', advance='no') maxrel_fwderr(zeros,exact_roots,deg)\n write(1, '(A)', advance='no') ','\n deallocate(zeros, radius, h)\n ! AMVW\n allocate(poly(deg+1), eigs(deg), residuals(deg))\n poly = (/ (p(deg-j+1), j=0,deg)/)\n call z_poly_roots(deg, poly, eigs, residuals, flag)\n write(1, '(ES15.2)') maxrel_fwderr(eigs,exact_roots,deg)\n deallocate(poly, eigs, residuals)\n ! deallocate polynomial arrays\n deallocate(coeffs, exact_roots, p, xr, xi)\n \n ! close file\n close(1)\ncontains\n !************************************************\n ! maxrel_fwderr *\n !************************************************\n ! Compute the maximum relative forward error\n ! in the approximation roots to exact_roots.\n !************************************************\n function maxrel_fwderr(roots, exact_roots, deg) result(res)\n implicit none\n ! argument variables\n integer, intent(in) :: deg\n complex(kind=dp), intent(in) :: exact_roots(:)\n complex(kind=dp), intent(inout) :: roots(:)\n ! local variables\n integer :: i, j, k\n real(kind=dp) :: hd, res\n \n ! main\n res = 0d0\n do i=1,deg\n hd = abs(roots(i)-exact_roots(1))\n j = 1\n do k = 2,deg\n if (hd>abs(roots(i)-exact_roots(k))) then\n hd = abs(roots(i)-exact_roots(k))\n j = k\n end if\n end do\n if (res97.or.j<1)then\n write(*,*)' error in ran1 j=',j\n stop\n endif\n ran1=r(j)\n r(j)=(float(ix1)+float(ix2)*rm2)*rm1\n return\n end function ran1\n \n\tfunction gasdev()\n\t\tuse numz\n!\t\tinterface ran1\n!\t\t\tfunction ran1(idum)\n!\t\t\t\tuse numz\n!\t\t\t integer, intent(inout), optional :: idum\n!\t\t\t real(b8) ran1\n!\t\t\tend function ran1\n!\t\tend interface\n\t\timplicit none\n\t\treal(b8) gasdev\n\t\tinteger iset \n\t\treal(b8) fac,gset,rsq,v1,v2\n\t\tsave iset,gset\n\t\tdata iset/0/ \n\t\tif (iset.eq.0) then \n\t 1\t\tv1=2.*ran1()-1. \n\t\t\tv2=2.*ran1()-1. \n\t\t\trsq=v1**2+v2**2\n\t\t\tif(rsq.ge.1..or.rsq.eq.0.)goto 1 \n\t\t\tfac=sqrt(-2.*log(rsq)/rsq) \n\t\t\tgset=v1*fac\n\t\t\tgasdev=v2*fac \n\t\t\tiset=1 \n\t\telse \n\t\t\tgasdev=gset \n\t\t\tiset=0 \n\t\tendif \n\t\treturn \n\tend function gasdev\n\t\n\tfunction norml(mean,sigma)\n\t\tuse numz\n\t\timplicit none\n\t\treal(b8) norml\n\t real(b8) mean,sigma\n\t\tnorml = gasdev() * sigma + mean\n\tend function norml\n\n\tfunction spread(min,max)\n\t\tuse numz\n\t\timplicit none\n\t\treal(b8) spread\n\t\treal(b8) min,max\n\t\tspread=(max - min) * ran1() + min\n\tend function spread\n\nend module ran_mod\n", "meta": {"hexsha": "267683468a0ef4671bb53953ff6e3725d066af4e", "size": 2120, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "darwin19/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": "darwin19/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": "darwin19/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": 22.0833333333, "max_line_length": 49, "alphanum_fraction": 0.6023584906, "num_tokens": 852, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314617436727, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.6954939819614931}} {"text": "subroutine residuotri(ad, al, au, u, b, r)\n\n use tridiagxvector_interface\n\n implicit none\n\n real, dimension(:), intent(in) :: ad, al, au, u, b\n real, dimension(:), intent(out) :: r\n\n integer :: n\n\n call tridiagxvector(ad, al, au, u, r)\n r = r - b\n\n print*,\n print*, 'Residuo: ', sqrt(dot_product(r,r))\n print*,\n\nend subroutine\n", "meta": {"hexsha": "253a3facd58081db64240bd2d7bd277f4379c4bc", "size": 337, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Practica3_choleskytri/residuotri.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": "Practica3_choleskytri/residuotri.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": "Practica3_choleskytri/residuotri.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": 16.85, "max_line_length": 52, "alphanum_fraction": 0.6201780415, "num_tokens": 118, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772417253256, "lm_q2_score": 0.7956580927949807, "lm_q1q2_score": 0.69546663110667}} {"text": "integer function oil_spill_fill(datafield,ni,nj,mask)\n!\n! fill array datafield that has holes (missing values) using the valid values\n! array mask tells whether data points are valid or missing\n! mask(i,J)==0 means datafield(i,j) is missing (hole)\n!\n! Missing values are filled using adjacent data points.\n! In order to fill missing value datafield(i,j), it is necessary \n! to have at least TWO valid (non missing) adjacent datapoints.\n! The number of adjacent point is usually 8, except if point (i,j)\n! lies on the boundary (first/last row or first/last column)\n! This means that multiple filling passes will have to be performed\n! in order to fill all missing values.\n! Values filled during pass N can be used to compute fill values\n! during subsequent passes (but not during pass N)\n!\n! The function returns the number of points it has not been able to fill.\n! If a pass was unable to fill any point while there were still holes in the \n! array, the function quits before entering an endless loop.\n!\n! (i-1,j+1) (i ,J+1) (i+1,j+1)\n!\n!\n! (i-1,j ) (i ,J ) (i+1,j )\n! point to fill\n!\n! (i-1,j-1) (i ,J-1) (i+1,j-1)\n!\nimplicit none\n\ninteger ni,nj\nreal, dimension(ni,nj) :: datafield\ninteger, dimension(ni,nj) :: mask\n\ninteger, dimension(ni,nj,0:1) :: tempmask\ninteger inmask,outmask\ninteger i,j,ii,jj\ninteger not_filled, neighbors, not_filled_on_last_pass\nreal *8 sum, sumweight, weight\n\ntempmask(:,:,0)=0\ndo j=1,nj ! loop over input grid\ndo i=1,ni\n if ( mask(i,j) .gt. 0.5 ) tempmask(i,j,0)=1\nend do\nend do\n\n!tempmask(:,:,0)=mask\ninmask=0\noutmask=1-inmask ! if inmask is 0, then outmask is 1 and vice versa\nnot_filled=ni*nj-1\nnot_filled_on_last_pass=ni*nj\n\ndo while(not_filled.ne.0) ! loop until there are no missing values left\n not_filled_on_last_pass=not_filled\n not_filled=0\n do j=1,nj ! loop over input grid\n do i=1,ni\n tempmask(i,j,outmask)=tempmask(i,j,inmask)\n if(tempmask(i,j,inmask).ne.0) cycle ! this point exists, no need to fill\n if(tempmask(i,j,inmask).eq.1) print *,'point',i,j,' exists'\n sum=0.0\n sumweight=0.0\n neighbors=0\n do jj=max(1,j-1),min(nj,j+1) ! scan neighbors (with protection for border)\n do ii=max(1,i-1),min(ni,i+1)\n if(ii.ne.i .or. jj.ne.j) then ! ignore the point itself\n if(tempmask(ii,jj,inmask).ne.0) then ! point is not missing in grid\n weight=1.0/sqrt( 1.0*((ii-i)*(ii-i) + (jj-j)*(jj-j)) ) ! weight is inverse of distance in grid points\n sumweight=sumweight+weight ! sum of weights\n sum=sum+weight*datafield(ii,jj) ! weighted sum\n neighbors=neighbors+1\n endif\n endif\n enddo\n enddo\n if(neighbors .gt. 1) then ! we need at least two existing neighboring points\n datafield(i,j)=sum/sumweight ! weighted average of existing neighbors\n tempmask(i,j,outmask)=1 ! this point now exists (for next pass)\n else\n not_filled=not_filled+1 ! this point could not be filled\n endif\n10 continue\n enddo\n enddo\n inmask=outmask ! swap inmask and outmask (this output is the input for next pass)\n outmask=1-inmask ! if inmask is 0, then outmask is 1 and vice versa\n\n! print *,'not_filled=',not_filled\n if(not_filled.eq.not_filled_on_last_pass) exit ! we are stuck, no missing values got filled on this pass\nenddo\n\noil_spill_fill=not_filled ! return number of holes left\n\n101 format(8f6.3)\nreturn\nend\n\n", "meta": {"hexsha": "f70a2863f4745f3a83094ae58660c4230618cfc0", "size": 3513, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "spill_fill_katja.f90", "max_stars_repo_name": "PhilippeCarphin/fortran-gizmos", "max_stars_repo_head_hexsha": "2b4f110ef695e4ff73fa4eab1d44b3a518c8e00d", "max_stars_repo_licenses": ["TCL", "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": "spill_fill_katja.f90", "max_issues_repo_name": "PhilippeCarphin/fortran-gizmos", "max_issues_repo_head_hexsha": "2b4f110ef695e4ff73fa4eab1d44b3a518c8e00d", "max_issues_repo_licenses": ["TCL", "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": "spill_fill_katja.f90", "max_forks_repo_name": "PhilippeCarphin/fortran-gizmos", "max_forks_repo_head_hexsha": "2b4f110ef695e4ff73fa4eab1d44b3a518c8e00d", "max_forks_repo_licenses": ["TCL", "BSD-2-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-24T18:41:22.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-24T18:41:22.000Z", "avg_line_length": 35.4848484848, "max_line_length": 113, "alphanum_fraction": 0.6695132365, "num_tokens": 1052, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772318846386, "lm_q2_score": 0.7956581000631542, "lm_q1q2_score": 0.6954666296297926}} {"text": "! =============================================================================\n! Module to compute the eigenvalues and eigenvectors of 3x3 real symmetric\n! matrices. It uses the Jacobi algorithm according to\n! Rutishauser, H. The Jacobi method for real symmetric matrices.\n! Numer. Math. 9, 1-10 (1966). https://doi.org/10.1007/BF02165223\n! =============================================================================\nmodule jacobi\n use constants, only : hundred, one, zero, f12\n implicit none\n\n private\n integer, parameter :: n = 3 ! we have 3x3 matrices\n double precision, parameter :: atol = 1.0e-15\n\n public :: jacobi_diagonalise, jacobi_eigenvalues\n\n contains\n\n pure subroutine givens(A, D, i, j, c, s, t, tau)\n double precision, intent(in) :: A(n, n), D(n)\n integer, intent(in) :: i, j\n double precision, intent(out) :: c, s, t, tau\n double precision :: theta, g, h, aij\n\n aij = A(i, j)\n g = hundred * dabs(aij)\n h = D(j) - D(i)\n if (dabs(h) + g == dabs(h)) then\n ! sign(A, B) returns A with the sign of B\n ! We need to add epsilon with the proper sign\n ! since h might be -epsilon causing a division by zero.\n t = aij / (h + sign(epsilon(h), h))\n else\n ! sign(A, B) returns A with the sign of B\n ! We need to add epsilon with the proper sign\n ! since aij might be -epsilon causing a division by zero.\n theta = f12 * h / (aij + sign(epsilon(aij), aij))\n t = one / (dabs(theta) + dsqrt(one + theta ** 2))\n if (theta < zero) then\n t = -t\n endif\n endif\n\n ! c = cos(theta)\n c = one / dsqrt(one + t ** 2)\n\n ! s = sin(theta)\n s = t * c\n\n tau = s / (one + c)\n end subroutine\n\n !\n ! Jacobi algorithm -- eigenvalues and eigenvectors\n !\n\n ! Apply Jacobi (or Givens) rotation to make\n ! A(i, j) = 0. A' = P^T * A * P.\n ! @param[inout] A current state of 3x3 matrix\n ! @param[inout] V current state of eigenvectors\n ! @param[in] i the row\n ! @param[in] j first column with i .ne. j\n ! @param[in] k second column with i .ne. k\n pure subroutine apply_rotation_AV(A, D, Z, i, j, V)\n double precision, intent(inout) :: A(n, n), D(n), Z(n)\n integer, intent(in) :: i, j\n double precision, intent(inout) :: V(n, n)\n double precision :: c, s, t, tau\n integer :: k\n double precision :: g, h\n\n ! compute the rotation angle theta\n ! Reference: Rutishauser, H. The Jacobi method for real symmetric matrices.\n ! Numer. Math. 9, 1-10 (1966). https://doi.org/10.1007/BF02165223\n\n call givens(A, D, i, j, c, s, t, tau)\n\n !\n ! Apply Givens rotation to matrix\n !\n\n h = t * A(i, j)\n Z(i) = Z(i) - h\n Z(j) = Z(j) + h\n D(i) = D(i) - h\n D(j) = D(j) + h\n A(i, j) = zero\n\n do k = 1, i-1\n g = A(k, i)\n h = A(k, j)\n A(k, i) = g - s * (h + g * tau)\n A(k, j) = h + s * (g - h * tau)\n enddo\n\n do k = i+1, j-1\n g = A(i, k)\n h = A(k, j)\n A(i, k) = g - s * (h + g * tau)\n A(k, j) = h + s * (g - h * tau)\n enddo\n\n do k = j+1, n\n g = A(i, k)\n h = A(j, k)\n A(i, k) = g - s * (h + g * tau)\n A(j, k) = h + s * (g - h * tau)\n enddo\n\n do k = 1, n\n ! accumulate eigenvector\n g = V(k, i)\n h = V(k, j)\n V(k, i) = c * g - s * h\n V(k, j) = s * g + c * h\n enddo\n end subroutine apply_rotation_AV\n\n ! Diagonalise a real symmetric 3x3 matrix A = V^T * D * V\n ! where D is a diagonal matrix with the eigenvalues and\n ! V is the eigenvector matrix. The eigenvalues are in\n ! descending order.\n ! The input matrix is overwritten and will be the diagonal\n ! matrix storing the eigenvalues, V contains the eigenvectors.\n ! The eigenvector V(:, i) belongs to eigenvalue A(i, i).\n ! @param[inout] A real symmetric 3x3 matrix\n ! @param[out] D eigenvalues in descending order\n ! @param[out] V eigenvector matrix\n pure subroutine jacobi_diagonalise(A, D, V)\n double precision, intent(inout) :: A(n, n)\n double precision, intent(out) :: D(n)\n double precision, intent(out) :: V(n, n)\n double precision :: B(n), Z(n)\n integer :: i, j\n double precision :: sm\n\n ! initialise eigenvector matrix to identity matrix\n do j = 1, n\n D(j) = A(j, j)\n B(j) = D(j)\n Z(j) = zero\n do i = 1, n\n V(i, j) = zero\n if (i == j) then\n V(i, j) = one\n endif\n enddo\n enddo\n\n\n ! sum of off-diagonal entries\n ! sm should convergence to zero\n sm = dabs(A(1, 2)) + dabs(A(1, 3)) + dabs(A(2, 3))\n\n do while (sm >= atol)\n\n do i = 1, n-1\n do j = i+1, n\n call apply_rotation_AV(A, D, Z, i, j, V)\n enddo\n enddo\n\n B = B + Z\n D = B\n Z = zero\n ! update sum of off-diagonals\n sm = dabs(A(1, 2)) + dabs(A(1, 3)) + dabs(A(2, 3))\n enddo\n\n call sort_descending(D, V)\n\n end subroutine jacobi_diagonalise\n\n ! Sort the eigenvalues in descending order.\n ! It sorts the eigenvector matrix accordingly.\n ! @param[inout] D eigenvalues\n ! @param[inout] V eigenvector matrix\n pure subroutine sort_descending(D, V)\n double precision, intent(inout) :: D(n)\n double precision, intent(inout) :: V(n, n)\n double precision :: teval, tevec(n)\n\n if (D(2) > D(1)) then\n teval = D(1)\n D(1) = D(2)\n D(2) = teval\n tevec = V(:, 1)\n V(:, 1) = V(:, 2)\n V(:, 2) = tevec\n endif\n\n if (D(3) > D(2)) then\n teval = D(2)\n D(2) = D(3)\n D(3) = teval\n tevec = V(:, 2)\n V(:, 2) = V(:, 3)\n V(:, 3) = tevec\n endif\n\n if (D(2) > D(1)) then\n teval = D(1)\n D(1) = D(2)\n D(2) = teval\n tevec = V(:, 1)\n V(:, 1) = V(:, 2)\n V(:, 2) = tevec\n endif\n end subroutine sort_descending\n\n !\n ! Jacobi algorithm -- eigenvalues only\n !\n\n pure subroutine apply_rotation(A, D, Z, i, j)\n double precision, intent(inout) :: A(n, n), D(n), Z(n)\n integer, intent(in) :: i, j\n double precision :: c, s, t, tau\n integer :: k\n double precision :: g, h\n\n ! compute the rotation angle theta\n ! Reference: Rutishauser, H. The Jacobi method for real symmetric matrices.\n ! Numer. Math. 9, 1-10 (1966). https://doi.org/10.1007/BF02165223\n\n call givens(A, D, i, j, c, s, t, tau)\n\n !\n ! Apply Givens rotation to matrix\n !\n\n h = t * A(i, j)\n Z(i) = Z(i) - h\n Z(j) = Z(j) + h\n D(i) = D(i) - h\n D(j) = D(j) + h\n A(i, j) = zero\n\n do k = 1, i-1\n g = A(k, i)\n h = A(k, j)\n A(k, i) = g - s * (h + g * tau)\n A(k, j) = h + s * (g - h * tau)\n enddo\n\n do k = i+1, j-1\n g = A(i, k)\n h = A(k, j)\n A(i, k) = g - s * (h + g * tau)\n A(k, j) = h + s * (g - h * tau)\n enddo\n\n do k = j+1, n\n g = A(i, k)\n h = A(j, k)\n A(i, k) = g - s * (h + g * tau)\n A(j, k) = h + s * (g - h * tau)\n enddo\n end subroutine apply_rotation\n\n\n ! Diagonalise a real symmetric 3x3 matrix A = V^T * D * V\n ! where D is a diagonal matrix with the eigenvalues and\n ! V is the eigenvector matrix. The eigenvalues are in\n ! descending order.\n ! The input matrix is overwritten, the diagonal\n ! entries will be storing the eigenvalues\n ! @param[inout] A real symmetric 3x3 matrix\n ! @param[out] D eigenvalues in descending order\n pure subroutine jacobi_eigenvalues(A, D)\n double precision, intent(inout) :: A(n, n)\n double precision, intent(out) :: D(n)\n double precision :: B(n), Z(n)\n integer :: i, j\n double precision :: sm\n\n ! initialise\n do j = 1, n\n D(j) = A(j, j)\n B(j) = D(j)\n Z(j) = zero\n enddo\n\n ! sum of off-diagonal entries\n ! sm should convergence to zero\n sm = dabs(A(1, 2)) + dabs(A(1, 3)) + dabs(A(2, 3))\n\n do while (sm > atol)\n\n do i = 1, n-1\n do j = i+1, n\n call apply_rotation(A, D, Z, i, j)\n enddo\n enddo\n\n B = B + Z\n D = B\n Z = zero\n ! update sum of off-diagonals\n sm = dabs(A(1, 2)) + dabs(A(1, 3)) + dabs(A(2, 3))\n enddo\n\n call sort_eigenvalues(D)\n\n end subroutine jacobi_eigenvalues\n\n ! Sort the eigenvalues in descending order.\n ! @param[inout] D eigenvalues\n pure subroutine sort_eigenvalues(D)\n double precision, intent(inout) :: D(n)\n double precision :: teval\n\n if (D(2) > D(1)) then\n teval = D(1)\n D(1) = D(2)\n D(2) = teval\n endif\n\n if (D(3) > D(2)) then\n teval = D(2)\n D(2) = D(3)\n D(3) = teval\n endif\n\n if (D(2) > D(1)) then\n teval = D(1)\n D(1) = D(2)\n D(2) = teval\n endif\n end subroutine sort_eigenvalues\n\nend module jacobi\n", "meta": {"hexsha": "ca5be238cab37dff6c98f0aa3b8a0d4bf1239e56", "size": 11155, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/utils/jacobi.f90", "max_stars_repo_name": "matt-frey/epic", "max_stars_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2021-11-11T10:50:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T00:11:41.000Z", "max_issues_repo_path": "src/utils/jacobi.f90", "max_issues_repo_name": "matt-frey/epic", "max_issues_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 47, "max_issues_repo_issues_event_min_datetime": "2021-11-12T17:09:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-24T16:50:58.000Z", "max_forks_repo_path": "src/utils/jacobi.f90", "max_forks_repo_name": "matt-frey/epic", "max_forks_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.4984984985, "max_line_length": 91, "alphanum_fraction": 0.4046615867, "num_tokens": 3028, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088064979618, "lm_q2_score": 0.749087201911703, "lm_q1q2_score": 0.6954591550897419}} {"text": "!> \nmodule VortexPoint2D\n use PrecisionMod, only: MK\n implicit none\n real(MK),parameter :: MINNORM2=1e-8\ncontains\n subroutine fUi_VortexPoint2D_11(DeltaP,Intensity,SmoothModel,SmoothParam,bComputeGrad,Uind, Grad)\n use MathConstants , only: twopi_inv\n implicit none \n ! Input/output arguments \n real(MK), dimension(3), intent(in) :: DeltaP !< 3 x 1 Pcp-Pv\n real(MK), intent(in) :: Intensity !< Circulation Gamma\n integer, intent(in) ,optional :: SmoothModel !< \n real(MK), intent(in),optional :: SmoothParam !< \n logical, intent(in) :: bComputeGrad !< \n real(MK), dimension(3),intent(out) :: Uind !< No Side effects. Note that\n real(MK), dimension(9),intent(out) :: Grad !< No Side effects\n ! ! Variables declaration \n real(MK) :: r2 !< \n real(MK) :: factor !< \n real(MK) :: E !< \n real(MK) :: rho2 !< \n real(MK) :: Qm !< \n ! \n ! No need of gradient in 2D\n if(bComputeGrad) then\n Grad(1:9)=0.0_MK !\n else\n Grad(1:9)=0.0_MK\n endif\n Uind=0.0_MK\n\n r2 = DeltaP(1)**2+ DeltaP(2)**2\n if (r2100) then \n! Uind(3)=0.0_MK\n! Grad(1:9)=0.0_MK \n else\n select case (SmoothModel) !\n case (0) ! No mollification, exept on zero\n factor=1._MK/r2\n case (22) !\n ! Finite support \n factor=1._MK/sqrt(SmoothParam**4+r2**2)\n ! --------------------------------------------------------------------------------\n ! --- Majda Kernels\n ! --------------------------------------------------------------------------------\n case (2) ! Second order - Gaussian - Majada\n rho2 = r2/SmoothParam**2;\n E = exp(-rho2);\n Qm = 1._MK;\n factor = (1._MK-Qm*E)/r2;\n case(4) ! Fourth Order - Gaussian - Majda\n rho2 = r2/SmoothParam**2;\n E = exp(-rho2);\n Qm = 1._MK-rho2;\n factor = (1._MK-Qm*E)/r2;\n case(6) ! Sixth Order - Gaussian - Majda\n rho2 = r2/SmoothParam**2;\n E = exp(-rho2);\n Qm = (1._MK-2._MK*rho2+rho2**2/2._MK);\n factor = (1._MK-Qm*E)/r2;\n case(8) ! Eigth Order - Gaussian - Majda\n rho2 = r2/SmoothParam**2;\n E = exp(-rho2);\n Qm = (1._MK-3_MK*rho2+3._MK*rho2**2/2._MK-rho2**3/6._MK);\n factor = (1._MK-Qm*E)/r2;\n case(10) ! Tenth Order - Gaussian - Mads\n rho2 = r2/SmoothParam**2;\n E = exp(-rho2/2._MK); !!!!!!!! Note the 2 in the Gaussian\n Qm = (1._MK-2._MK*rho2+3./4.*rho2**2-1./12.*rho2**3+1./384.*rho2**4);\n factor = (1._MK-Qm*E)/r2;\n ! --------------------------------------------------------------------------------\n ! --- Mads Kernel (they are the same, it's just the fact that there is a 2 in the exponential that changes things)\n ! --------------------------------------------------------------------------------\n case(102) ! Second order Gaussian - Mads\n rho2 = r2/SmoothParam**2;\n E = exp(-rho2/2._MK); !Note the 2 in the Gaussian\n Qm = 1._MK;\n factor = (1._MK-Qm*E)/r2;\n case(104) ! Fourth order Gaussian - Mads\n rho2 = r2/SmoothParam**2;\n E = exp(-rho2/2._MK); !Note the 2 in the Gaussian\n Qm = 1._MK-1._MK/2._MK*rho2;\n factor = (1._MK-Qm*E)/r2;\n case(106) ! Sixth Order - Gaussian - Mads\n rho2 = r2/SmoothParam**2;\n E = exp(-rho2/2._MK); !Note the 2 in the Gaussian\n Qm = (1._MK-rho2+1._MK/8._MK*rho2**2);\n factor = (1._MK-Qm*E)/r2;\n case(108) ! Eigth Order - Gaussian - Mads\n rho2 = r2/SmoothParam**2;\n E = exp(-rho2/2._MK); !Note the 2 in the Gaussian\n Qm = (1._MK-3._MK/2._MK*rho2+3._MK/8._MK*rho2**2-1._MK/48._MK*rho2**3);\n factor = (1._MK-Qm*E)/r2;\n case(110) ! Tenth Order - Gaussian - Mads\n rho2 = r2/SmoothParam**2;\n E = exp(-rho2/2._MK); !Note the 2 in the Gaussian\n Qm = (1._MK-2._MK*rho2+3./4.*rho2**2-1./12.*rho2**3+1./384.*rho2**4);\n factor = (1._MK-Qm*E)/r2;\n case default \n write(*,*)'2D vortex point: wrong smooth model'\n STOP -1\n end select \n factor = factor * Intensity * twopi_inv;\n Uind(1)=-DeltaP(2)*factor\n Uind(2)= DeltaP(1)*factor\n Uind(3)=0.0_MK\n\n endif\n\n end subroutine\n\nend module VortexPoint2D\n", "meta": {"hexsha": "451832b675afac4f17975ca91daf32ecc8e090d8", "size": 5306, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "welib/vortilib/elements/fortran/UIVortexPoint2D.f90", "max_stars_repo_name": "moonieann/welib", "max_stars_repo_head_hexsha": "0e430ad3ca034d0d2d60bdb7bbe06c947ce08f52", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2019-07-24T23:37:10.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T20:40:40.000Z", "max_issues_repo_path": "welib/vortilib/elements/fortran/UIVortexPoint2D.f90", "max_issues_repo_name": "moonieann/welib", "max_issues_repo_head_hexsha": "0e430ad3ca034d0d2d60bdb7bbe06c947ce08f52", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "welib/vortilib/elements/fortran/UIVortexPoint2D.f90", "max_forks_repo_name": "moonieann/welib", "max_forks_repo_head_hexsha": "0e430ad3ca034d0d2d60bdb7bbe06c947ce08f52", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2019-03-14T13:47:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T15:47:27.000Z", "avg_line_length": 45.3504273504, "max_line_length": 130, "alphanum_fraction": 0.421221259, "num_tokens": 1563, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475746920261, "lm_q2_score": 0.7371581741774411, "lm_q1q2_score": 0.6953963757746913}} {"text": "C23456789\nC v0.0.1\nC compile\nC f95 -shared -fPIC -o mc_pi.so mc_pi.f\nC calling in R\nC dyn.load(\"~/a.out\")\nC r = .Fortran(\"pso\", gbest=rep(0, 4), x, y)\nC sanity check on yhat\nC yhat = x %*% r$gbest\nC plot(yhat, pch=(y*2+6), col=(y*2+6))\nC abline(h=0, col=\"gray\", lty=3)\nC legend(\"topleft\", legend=c(0, 1), pch=c(6, 8), col=c(6, 8), bty=\"n\")\nC\nC compute nn, return mse\nC all hardcoded for this version\nC 4 - 1\n function ann(w, x, y, yhat)\n double precision w(4, 1), x(100, 4), y(100,1), yhat(100,1)\n yhat = matmul(x, w)\n ann = sum((y-yhat)**2)/size(y)\n end function\nC particle swarm optim\n subroutine pso(gbest, x, y)\n parameter (iter=1000, w=2.66, c1=.8, c2=.8, npar=12, nd=4)\n double precision par(npar, nd), pbest(npar, nd), gbest(nd)\n double precision r1(npar, nd), r2(npar, nd)\n double precision x(100, 4), y(100,1), yhat(100,1)\nC initialize particles\n call random_number(par)\n call random_number(pbest)\n call random_number(gbest)\n do 99 i=1, iter\nC update invdividual (personal) best\n do 69 j=1, npar\n parfit = ann(par(j, :), x, y, yhat)\n pbfit = ann(pbest(j, :), x, y, yhat)\n if (parfit .lt. pbfit) then\n pbest(j, :) = par(j, :)\n kk = j\n end if\n69 continue\nC update global best\n gbfit = ann(gbest, x, y, yhat)\n pbfit = ann(pbest(kk, :), x, y, yhat)\n if ( pbfit .lt. gbfit) then\n gbest = pbest(kk, :)\n end if\nC update particles\n call random_number(r1)\n call random_number(r2)\n par = w * par +\nC cognitive velocity\n + c1 * r1 * (pbest - par) +\nC social velocity\n + c2 * r2 *( transpose(spread(gbest, 2, npar)) - par)\n99 continue\nC print *, gbest\nC print *, ann(gbest, x, y, yhat)\n end subroutine\n", "meta": {"hexsha": "14b2083d869c06fec2b279b8b02c4a74a9be88b0", "size": 1950, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "psnn.f", "max_stars_repo_name": "MikeXL/Quest-of-FORTRAN", "max_stars_repo_head_hexsha": "fe9c71f36964adf7fb6b2434da91b7ffee0aae31", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "psnn.f", "max_issues_repo_name": "MikeXL/Quest-of-FORTRAN", "max_issues_repo_head_hexsha": "fe9c71f36964adf7fb6b2434da91b7ffee0aae31", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-03-10T20:47:32.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-10T20:47:52.000Z", "max_forks_repo_path": "psnn.f", "max_forks_repo_name": "MikeXL/Quest-of-FORTRAN", "max_forks_repo_head_hexsha": "fe9c71f36964adf7fb6b2434da91b7ffee0aae31", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.5, "max_line_length": 74, "alphanum_fraction": 0.5312820513, "num_tokens": 674, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953003183443, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6953398683407808}} {"text": "!\n! Perform a Jacobi sweep for a 2-d decomposition\n!\n subroutine sweep2d( a, f, n, sx, ex, sy, ey, b )\n integer n, sx, ex, sy, ey\n double precision a(sx-1:ex+1, sy-1:ey+1), f(sx-1:ex+1, sy-1:ey+1), &\n b(sx-1:ex+1, sy-1:ey+1)\n!\n integer i, j\n double precision h\n!\n h = 1.0d0 / dble(n+1)\n do j=sy, ey\n do i=sx, ex\n b(i,j) = 0.25 * (a(i-1,j)+a(i,j+1)+a(i,j-1)+a(i+1,j)) - &\n h * h * f(i,j)\n enddo\n enddo\n return\n end\n", "meta": {"hexsha": "4324cf8e7396a5e339cfbdc2866b3548efda7341", "size": 533, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/mpi/Using_MPI/intermediate/sweep2.f90", "max_stars_repo_name": "Fulayjan/ams250", "max_stars_repo_head_hexsha": "e72ab59a5f924728e69b46e2974914a2d3cab4c1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2018-05-01T20:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-06T18:43:27.000Z", "max_issues_repo_path": "examples/mpi/Using_MPI/intermediate/sweep2.f90", "max_issues_repo_name": "Fulayjan/ams250", "max_issues_repo_head_hexsha": "e72ab59a5f924728e69b46e2974914a2d3cab4c1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-05-01T04:06:01.000Z", "max_issues_repo_issues_event_max_datetime": "2018-05-01T04:06:01.000Z", "max_forks_repo_path": "examples/mpi/Using_MPI/intermediate/sweep2.f90", "max_forks_repo_name": "shawfdong/ams250", "max_forks_repo_head_hexsha": "e72ab59a5f924728e69b46e2974914a2d3cab4c1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-06-03T22:37:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-07T01:52:07.000Z", "avg_line_length": 25.380952381, "max_line_length": 74, "alphanum_fraction": 0.4371482176, "num_tokens": 214, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333484, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.6953398624118606}} {"text": " subroutine test()\n\n\n implicit none\n integer ii,jj\n integer INFO2,ndim\n! real*8 aa(3,3),ee(3),ez(3)\n real*8 aa(4,4),ee(4),ez(4),bb(4,4)\n\n aa = 0.d0\n\n ndim = 4\n aa(1,1) = 2\n aa(2,2) = 2\n aa(1,2) = 1\n aa(2,1) = 1\n\n aa(3,3) = 3\n aa(4,4) = 3\n aa(3,4) = 1\n aa(4,3) = 1\n\n! DSYEV: computes all eigenvalues and, optionally, eigenvectors of a real symmetric matrix A \n! SUBROUTINE DSYEV( JOBZ, UPLO, N, A, LDA, W, WORK, LWORK, INFO ) \n! ----------------------------\n! JOBZ (input) CHARACTER*1\n! = 'N': Compute eigenvalues only;\n! = 'V': Compute eigenvalues and eigenvectors.\n! UPLO (input) CHARACTER*1\n! = 'U': Upper triangle of A is stored;\n! = 'L': Lower triangle of A is stored.\n! A (input/output) DOUBLE PRECISION array\n! W (output) eigenvalues\n\n call dsyev('V','U',NDIM,aa,NDIM,ee,bb,3*NDIM-1,INFO2)\n! call sdiag(ndim,ndim,aa,ee,aa,ez,0)\n\n do ii=1,ndim\n do jj=1,ndim\n\n write(*,*) ii,jj,aa(jj,ii)\n\n enddo\n \n enddo\n do ii=1,ndim\n write(*,*) ii, ee(ii)\n enddo\n\n stop\n end\n\n", "meta": {"hexsha": "d5db92db58a23dcb1b8ecd4764ab39defd64bf8d", "size": 1244, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Codes/PNAMP/test.f90", "max_stars_repo_name": "jmyao17/SCCM", "max_stars_repo_head_hexsha": "16e31afa313bf70741c152d859aa837935110776", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Codes/PNAMP/test.f90", "max_issues_repo_name": "jmyao17/SCCM", "max_issues_repo_head_hexsha": "16e31afa313bf70741c152d859aa837935110776", "max_issues_repo_licenses": ["MIT"], "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/PNAMP/test.f90", "max_forks_repo_name": "jmyao17/SCCM", "max_forks_repo_head_hexsha": "16e31afa313bf70741c152d859aa837935110776", "max_forks_repo_licenses": ["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.4716981132, "max_line_length": 101, "alphanum_fraction": 0.4710610932, "num_tokens": 453, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703477, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6953398598606445}} {"text": " subroutine mapc2m_inclusions(xc,yc,xp,yp,isperiodic)\n implicit none\n\n double precision xc,yc,xp,yp\n logical isperiodic\n\n double precision xc1,yc1,xp1,yp1\n double precision xlow,ylow,xhi,yhi, r1\n double precision xc0, yc0\n integer i, nbox\n logical inbox\n\n double precision boxes_com(6,100)\n integer n_box_com\n\n common /combox0/ n_box_com\n common /combox1/ boxes_com\n\n nbox = n_box_com\n\n xc0 = xc\n yc0 = yc\n\n if (isperiodic) then\n if (xc .lt. -1.d0) then\n xc0 = xc + 2\n elseif (xc .gt. 1.d0) then\n xc0 = xc - 2\n endif\n\n if (yc .lt. -1.d0) then\n yc0 = yc + 2\n elseif (yc .gt. 1.d0) then\n yc0 = yc - 2\n endif\n endif\n\n xp = xc0\n yp = yc0\n\n\n inbox = .false.\n do i = 1,nbox\nc # [xlow,ylow]x[xhi,yhi] are the ll and ur corners of\nc # included box in [-1,1]x[-1,1] units.\n xlow = boxes_com(1,i)\n ylow = boxes_com(2,i)\n xhi = boxes_com(3,i)\n yhi = boxes_com(4,i)\n\nc # Radius of enclosed circle is in 0 < r1 < 1.\n r1 = boxes_com(5,i)\n\nc # Scale [xlow,ylow]x[xhi,yhi] into [-1,1]x[-1,1]\n xc1 = -1.d0 + 2.d0*(xc0 - xlow)/(xhi - xlow)\n yc1 = -1.d0 + 2.d0*(yc0 - ylow)/(yhi - ylow)\n\n if (abs(xc1) .le. 1.d0 .and. abs(yc1) .le. 1.d0) then\n call mapc2m_inclusion2(xc1,yc1,xp1,yp1,r1)\n\nc # Scale physical coordinates back so that mapped\nc # region is in [xlow,ylow]x[xhi,yhi]\n xp = (xp1 + 1.d0)*(xhi - xlow)/2.d0 + xlow\n yp = (yp1 + 1.d0)*(yhi - ylow)/2.d0 + ylow\n inbox = .true.\n endif\n if (inbox) then\n exit\n endif\n enddo\n if (isperiodic) then\n if (xc .lt. -1) then\n xp = xp - 2\n elseif (xc .gt. 1) then\n xp = xp + 2\n endif\n if (yc .lt. -1) then\n yp = yp - 2\n elseif (yc .gt. 1) then\n yp = yp + 2\n endif\n endif\n\n end\n\nc # ------------------------------------------------------------------\nc MAPC2M_INCLUSION maps the grid [-1,1]x[-1,1] to a grid enclosing a\nc circle of radius r1 < 1.\nc # ------------------------------------------------------------------\n\n subroutine mapc2m_inclusion2(xc,yc,xp,yp,r1)\n implicit none\n\n double precision xc,yc,xp,yp,zp,r1\n\n double precision d, dinv, scale, s, r, w, ct\n logical use_convex\n\n d = max(abs(xc),abs(yc))\n r = max(sqrt(xc**2 + yc**2),1e-10)\n\n if (d .lt. r1) then\nc # --------------------------------------------------------------\nc # Map area inside of the circle\nc # -------------------------------------------------------------------\n\n scale = d/r\n\n xp = scale*xc\n yp = scale*yc\n\nc # Blend this map with the Cartesian map to get\nc # more Cartesian like grid near the center of the\nc # circle. If we set this to false, we get concentric\nc # circles.\n use_convex = .true.\n if (use_convex) then\n w = (d/r1)**2\n xp = w*xp + (1.d0-w)*xc/sqrt(2.d0)\n yp = w*yp + (1.d0-w)*yc/sqrt(2.d0)\n endif\n else\n\nc # --------------------------------------------------------------\nc # Map area outside of the circle\nc # -------------------------------------------------------------------\n dinv = 1.d0/d\n\nc # d/r = cos(theta), where theta is the angle that a point\nc # makes with the x-axis.\n\n ct = d/r\n s = (1.d0 - r1*ct)/(1.d0 - r1)\n scale = s*(1.d0 - dinv) + dinv\n\n xp = scale*xc\n yp = scale*yc\n\n endif\n\n end\n", "meta": {"hexsha": "9f9a42361f9a468101e2f7fb12b7f13f44d79270", "size": 3811, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "applications/metric/2d/circles/mapc2m_inclusions.f", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2017-09-26T13:39:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:56:23.000Z", "max_issues_repo_path": "applications/metric/2d/circles/mapc2m_inclusions.f", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 75, "max_issues_repo_issues_event_min_datetime": "2017-08-02T19:56:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T12:36:32.000Z", "max_forks_repo_path": "applications/metric/2d/circles/mapc2m_inclusions.f", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-02-21T00:10:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T19:08:36.000Z", "avg_line_length": 26.838028169, "max_line_length": 78, "alphanum_fraction": 0.4366308056, "num_tokens": 1180, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813453, "lm_q2_score": 0.7745833737577158, "lm_q1q2_score": 0.695339852206995}} {"text": "function esat(t)\n\n! Computes saturation vapor pressure (Pa) from temperature (K).\n! Note: Computed with respect to liquid.\n\nuse constants\n\nimplicit none\n\nreal :: esat,t\n \nesat=611.21*exp((17.502*(t-t0))/(t-32.18))\n\nreturn\nend\n\n!===============================================================================\n\nfunction potential_temp(t,p)\n\n! Computes potential temperature from temp (K) and pressure (Pa).\n\nuse constants\n\nimplicit none\n\nreal :: t,p,potential_temp\n\npotential_temp=t*(p0/p)**kappa\n\nreturn\nend\n\n!===============================================================================\n\nfunction relhum(t,mixrat,p)\n\n! Computes relative humidity (fraction form)\n\nimplicit none\n\nreal :: t ! Temperature (K)\nreal :: p ! Pressure (Pa)\nreal :: mixrat ! vapor mixing ratio\nreal :: mixsat ! Saturation vapor mix. ratio\nreal :: relhum ! RH (fraction)\n\nrelhum=mixrat/mixsat(t,p)\n\nreturn\nend\n\n!===============================================================================\n\nfunction mixsat(t,p)\n\n! Computes saturation vapor mixing ratio as function of temp (K) and press( Pa).\n\nuse constants\n\nimplicit none\n\nreal :: esat,mixrat,p,satvpr,t,mixsat\n\nsatvpr=esat(t)\nmixsat=(e*satvpr)/(p-satvpr)\n\nreturn \nend\n\n!===============================================================================\n\nfunction eq_potential_temp(t,p,w,rh)\n \n! Calculates equivalent potential temperature given temperature, \n! pressure, mixing ratio, and relative humidity via\n! Bolton's equation. (MWR 1980, P 1052, eq. 43)\n\nimplicit none\n \nreal :: t ! temp (K)\nreal :: p ! pressure (Pa)\nreal :: w ! mixing ratio (kg/kg)\nreal :: rh ! relative humidity (fraction)\nreal :: thtm,tlcl,eq_potential_temp\n\nthtm=t*(100000./p)**(2./7.*(1.-(0.28*w)))\neq_potential_temp=thtm*exp((3.376/tlcl(t,rh)-0.00254) &\n *(w*1000.0*(1.0+0.81*w)))\n\nreturn\nend\n\n!===============================================================================\n\nfunction tlcl(t,rh)\n\n! Computes the temperature of the Lifting Condensation Level\n! given surface t and RH using Bolton's equation. (MWR 1980, p 1048, #22)\n\nimplicit none\n\nreal :: denom,rh,t,term1,term2,tlcl\n\nterm1=1.0/(t-55.0)\nterm2=alog(rh/1.0)/2840.\ndenom=term1-term2\ntlcl=(1.0/denom)+55.0\n\nreturn\nend\n\n!===============================================================================\n\nfunction dewpt(t,rh)\n \n! Compute dew point from temperature (K) and RH (fraction).\n\nuse constants\n\nimplicit none\n\nreal :: dewpt,rh,t \n\ndewpt=t/((-rvolv*alog(max(rh,0.01))*t)+1.0)\ndewpt=min(t,dewpt)\n\nreturn\nend\n\n!===============================================================================\n\nfunction wobf(t)\n\n! Name: wobuf function\n!\n! This function calculates the difference of the wet bulb potential\n! temperatures for saturated and dry air given the temperature.\n!\n! It was created by Herman Wobus of the Navy Weather Research\n! Facility from data in the Smithsonian Meteorological Tables.\n!\n!\n! Let wbpts = wet bulb potential temperature for saturated air\n! at temperature t in celsius\n!\n! Let wbptd = wet bult potential temperature for dry air at\n! the same temperature.\n!\n! The Wobus function wobf (in degrees celsius) is defined by:\n!\n! wobf(t) = wbpts - wbptd\n!\n! Although wbpts and wbptd are functions of both pressure and\n! temperature, their difference is a function of temperature only.\n!\n! The Wobus function is useful for evaluating several thermodynamic\n! quantities.\n!\n! If t is at 1000 mb, then t is potential temperature pt and\n! wbpts = pt. Thus,\n!\n! wobf(pt) = pt - wbptd\n!\n! If t is at the condensation level, then t is the condensation\n! temperature tc and wbpts is the wet bulb potential temperature\n! wbpt. Thus,\n!\n! wobf(tc) = wbpt - wbptd\n!\n! Manipulating the above equations we get,\n!\n! wbpt = pt - wobf(pt) + wobf(tc) and\n!\n! wbpts = pt - wobf(pt) + wobf(t)\n!\n! If t is equivalent potential temperature ept (implying that\n! the air at 1000 mb is completely dry), then\n!\n! wbpts = ept and wbptd = wbpt, thus,\n!\n! wobf(ept) = ept - wbpt\n\nimplicit none\n\nreal :: pol,t,wobf,x\n\nx=t-20.\n\nif (x <= 0.) then\n pol=1.0 +x*(-8.8416605E-03 &\n +x*( 1.4714143E-04+x*(-9.6719890E-07 &\n +x*(-3.2607217E-08+x*(-3.8598073E-10)))))\n wobf=15.130/(pol**4)\nelse\n pol=1. +x*(3.6182989E-03 &\n +x*(-1.3603273E-05+x*(4.9618922E-07 &\n +x*(-6.1059365E-09+x*(3.9401551E-11 &\n +x*(-1.2588129E-13+x*(1.6688280E-16)))))))\n wobf=(29.930/(pol**4))+(0.96*x)-14.8\nendif\n\nreturn\nend\n\n!===============================================================================\n\nsubroutine the2t(thetae,p,tparcel)\n \n! Calculates temperature K) at any pressure (mb) level along a saturation\n! adiabat by iteratively solving eq 2.76 from Wallace and Hobbs (1977).\n\n! Adpated from USAF routine, B. Shaw, NOAA/FSL\n\nuse constants\n\nimplicit none\n\ninteger :: iter\nreal, external :: mixsat\nreal, intent(in) :: p\nreal :: tcheck\nreal :: theta\nreal, intent(in) :: thetae\nreal :: tovtheta\nreal :: arg\nreal, intent(out) :: tparcel\nlogical :: converged\n\nconverged=.false.\ntovtheta=(p/1000.)**kappa\ntparcel=thetae/exp(lv*0.012/(cp*295.0))*tovtheta\n\ndo iter=1,50 \n arg = lv*mixsat(tparcel,p*100.)/(cp*tparcel)\n if(arg .le. 80.)then\n theta = thetae / exp(arg)\n else\n print*,'Warning, large argument for exponent ', arg\n goto 999\n endif\n tcheck = theta * tovtheta\n if (abs(tparcel-tcheck) < 0.05) then\n converged=.true.\n exit\n endif\n tparcel=tparcel+(tcheck-tparcel)*0.3\nenddo\n\n999 continue\nif (.not. converged) then\n print*,'Warning: thetae to temp calc did not converge.'\n print*,' thetae and p:',thetae,p\n print*,' tparcel:',tparcel\n print*,' theta,tovtheta:',theta,tovtheta\nendif\n\nreturn\nend\n\n!===============================================================================\n\nfunction wdir(u,v,xlon,orient,conefact)\n\n! Computes wind direction from u/v components. Converts the direction\n! to true direction if conefactor \\= 0.\n\nuse constants\n\nimplicit none\n\nreal :: conefact,diff,orient,u,v,wdir,xlon\n\n! Handle case where u is very small to prevent divide by 0.\n\nif (abs(u) < 0.001) then\n if (v <= 0.) then\n wdir=0.\n else\n wdir=180.\n endif\n\n! Otherwise, standard trig problem.\n\nelse\n wdir=270.-(atan2(v,u)*rad2deg)\n if (wdir > 360.) wdir=wdir-360.\nendif\n\n! Change to earth relative.\n\ndiff=(orient-xlon)*conefact\nif (diff > 180.) diff=diff-360.\nif (diff < -180.) diff=diff+360.\n\nwdir=wdir-diff\nif (wdir > 360.) wdir=wdir-360.\nif (wdir < 0.) wdir=wdir+360.\n\nreturn\nend\n\n!===============================================================================\n\nfunction wspd(u,v)\n\n! Computes wind velocity from u/v components.\n\nimplicit none\n\nreal :: u,v,wspd\n\nwspd=sqrt((u*u)+(v*v))\n\nreturn\nend\n\n!===============================================================================\n\nfunction fahren(t)\n\n! Converts from Celsius to fahrenheit\n\nimplicit none\n\nreal :: t,fahren\n\nfahren=(1.8*t)+32.\n\nreturn\nend\n\n!===============================================================================\n\nfunction celsius(tf)\n\nimplicit none\n\nreal, parameter :: factor=5./9.\nreal :: tf,celsius\n\ncelsius=factor*(tf-32.)\n\nreturn\nend\n\n!===============================================================================\n\nfunction heatindex(temp_k,rh_pct)\n\n! Computes heat index from a temperature (K) and RH (%).\n\nuse constants\n\nimplicit none\n\nreal :: celsius,fahren,heatindex,rh_pct,rh_pct_sqr,tf,tf_sqr,temp_k\n\nrh_pct_sqr=rh_pct*rh_pct\ntf=fahren(temp_k-t0)\ntf_sqr=tf*tf\n\nheatindex=-42.379+(2.04901523 *tf) &\n +(10.1433312 *rh_pct) &\n -(0.22475541 *tf*rh_pct) &\n -(6.83783E-03 *tf_sqr) &\n -(5.481717E-02*rh_pct_sqr) &\n +(1.22874E-03 *tf_sqr*rh_pct) &\n +(8.52E-04 *rh_pct_sqr*tf) &\n -(1.99E-06 *tf_sqr*rh_pct_sqr)\n\nheatindex=celsius(heatindex)+t0\n\nreturn\nend\n\n!===============================================================================\n\nfunction tw(t,td,p)\n\n! This function returns the wet-bulb temperature tw (K)\n! given the temperature t (K), dew point td (K)\n! and pressure p (Pa). See p.13 in stipanuk (1973), referenced\n! above, for a description of the technique.\n\n! Baker,Schlatter\t17-may-1982\toriginal version\n\n! Determine the mixing ratio line thru td and p.\n\naw=w(td,p)\n\n! Determine the dry adiabat thru t and p.\n\nao=o(t,p)\npi=p\n\n! Iterate to locate pressure pi at the intersection of the two\n! curves. pi has been set to p for the initial guess.\n\ndo i=1,10\n x=0.02*(tmr(aw,pi)-tda(ao,pi))\n if (abs(x) < 0.01) goto 5\n pi=pi*(2.**(x))\nenddo\n5 continue\n\n! Find the temperature on the dry adiabat ao at pressure pi.\n\nti=tda(ao,pi)\n\n! The intersection has been located...now, find a saturation\n! adiabat thru this point. Function os returns the equivalent \n! potential temperature (K) of a parcel saturated at temperature\n! ti and pressure pi.\n\naos=os(ti,pi)\n\n! Function tsa returns the wet-bulb temperature (K) of a parcel at\n! pressure p whose equivalent potential temperature is aos.\n\ntw=tsa(aos,p)\n\nreturn\nend\n\n!===============================================================================\n\nfunction w(t,p)\n \n! This function returns the mixing ratio (kg/kg) given the temperature t (K) \n! and pressure (Pa). The formula is quoted in most meteorological texts.\n\n! Baker,Schlatter\t17-may-1982\toriginal version\n\nimplicit none\n\nreal :: t,p,x,esat,w\n\nx=esat(t)\nw=0.622*x/(p-x)\n\nreturn\nend\n\n!===============================================================================\n\nfunction o(t,p)\n\n! G.S. Stipanuk 1973 \t original version.\n! Reference stipanuk paper entitled:\n! \"algorithms for generating a skew-t, log p\n! diagram and computing selected meteorological quantities.\"\n! atmospheric sciences laboratory\n! u.s. army electronics command\n! white sands missile range, new mexico 88002\n! 33 pages\n! Baker, Schlatter 17-may-1982\t \n\n! This function returns potential temperature (K) given\n! temperature t (K) and pressure p (Pa) by solving the poisson\n! equation.\n\nimplicit none\n\nreal :: t,p,o\n\no=t*((100000./p)**.286)\n\nreturn\nend\n\n!===============================================================================\n\nfunction tmr(w,p)\n\n!\tg.s. stipanuk 1973 \t original version.\n!\treference stipanuk paper entitled:\n! \"algorithms for generating a skew-t, log p\n!\t diagram and computing selected meteorological\n!\t quantities.\"\n!\t atmospheric sciences laboratory\n!\t u.s. army electronics command\n!\t white sands missile range, new mexico 88002\n!\t 33 pages\n!\tbaker, schlatter 17-may-1982\t \n\n! this function returns the temperature (K) on a mixing\n! ratio line w (kg/kg) at pressure p (Pa). the formula is given in \n! table 1 on page 7 of stipanuk (1973).\n\n! initialize constants\n\ndata c1/.0498646455/,c2/2.4082965/,c3/7.07475/\ndata c4/38.9114/,c5/.0915/,c6/1.2035/\n\nx=alog10(w*p*0.01/(0.622+w))\ntmr=10.**(c1*x+c2)-c3+c4*((10.**(c5*x)-c6)**2.)\n\nreturn\nend\n\n!===============================================================================\n\nfunction tda(th,p)\n\n!\tg.s. stipanuk 1973 \t original version.\n!\treference stipanuk paper entitled:\n! \"algorithms for generating a skew-t, log p\n!\t diagram and computing selected meteorological\n!\t quantities.\"\n!\t atmospheric sciences laboratory\n!\t u.s. army electronics command\n!\t white sands missile range, new mexico 88002\n!\t 33 pages\n!\tbaker, schlatter 17-may-1982\t \n\n! This function returns the temperature tda (K) on a dry adiabat\n! at pressure p (Pa). The dry adiabat is given by\n! potential temperature th (K). The computation is based on\n! poisson's equation.\n\nimplicit none\n\nreal :: th,p,tda\n\ntda=th*((p*0.00001)**.286)\n\nreturn\nend\n\n!===============================================================================\n\nfunction os(t,p)\n\n!\tg.s. stipanuk 1973 \t original version.\n!\treference stipanuk paper entitled:\n! \"algorithms for generating a skew-t, log p\n!\t diagram and computing selected meteorological\n!\t quantities.\"\n!\t atmospheric sciences laboratory\n!\t u.s. army electronics command\n!\t white sands missile range, new mexico 88002\n!\t 33 pages\n!\tbaker, schlatter 17-may-1982\t \n\n! This function returns the equivalent potential temperature os\n! (K) for a parcel of air saturated at temperature t (K)\n! and pressure p (Pa).\n\nimplicit none\n\nreal :: t,p,b,w,os\n\ndata b/2651.8986/\n\n! b is an empirical constant approximately equal to the latent heat\n! of vaporization for water divided by the specific heat at constant\n! pressure for dry air.\n\nos=t*((100000./p)**.286)*(exp(b*w(t,p)/t))\n\nreturn\nend\n\n!===============================================================================\n\nfunction tsa(os,p)\n\n!\tg.s. stipanuk 1973 \t original version.\n!\treference stipanuk paper entitled:\n! \"algorithms for generating a skew-t, log p\n!\t diagram and computing selected meteorological\n!\t quantities.\"\n!\t atmospheric sciences laboratory\n!\t u.s. army electronics command\n!\t white sands missile range, new mexico 88002\n!\t 33 pages\n!\tbaker, schlatter 17-may-1982\t \n\n! This function returns the temperature tsa (K) on a saturation\n! adiabat at pressure p (Pa). os is the equivalent potential\n! temperature of the parcel (K). sign(a,b) replaces the\n! algebraic sign of a with that of b.\n! b is an empirical constant approximately equal to 0.001 of the latent \n! heat of vaporization for water divided by the specific heat at constant\n! pressure for dry air.\n\ndata b/2651.8986/\n\n! tq is the first guess for tsa.\n\ntsa=253.15\n\n! d is an initial value used in the iteration below.\n\nd=120.\n\n! Iterate to obtain sufficient accuracy....see table 1, p.8\n! of stipanuk (1973) for equation used in iteration.\n\ndo i=1,12\n d=d/2.\n x=os*exp(-b*w(tsa,p)/tsa)-tsa*((100000./p)**.286)\n if (abs(x) < 1.e-7) goto 2\n tsa=tsa+sign(d,x)\nenddo\n2 continue\n\nreturn\nend\n", "meta": {"hexsha": "7645c3970ad24a14568e8f1ead4f3ff158916aa2", "size": 14213, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/newlfmp/metfunc.f90", "max_stars_repo_name": "maxinye/laps-mirror", "max_stars_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_stars_repo_licenses": ["Intel", "Unlicense", "OLDAP-2.2.1", "NetCDF"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-04-05T12:28:22.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-29T06:37:29.000Z", "max_issues_repo_path": "src/newlfmp/metfunc.f90", "max_issues_repo_name": "longwosion/laps-mirror", "max_issues_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_issues_repo_licenses": ["Intel", "NetCDF", "OLDAP-2.2.1", "Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/newlfmp/metfunc.f90", "max_forks_repo_name": "longwosion/laps-mirror", "max_forks_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_forks_repo_licenses": ["Intel", "NetCDF", "OLDAP-2.2.1", "Unlicense"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-04-27T12:51:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-19T13:57:44.000Z", "avg_line_length": 23.2618657938, "max_line_length": 80, "alphanum_fraction": 0.5885456976, "num_tokens": 3982, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122288794595, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6952675932844832}} {"text": " FUNCTION gasdev( idum )\n! Returns a normally distributed deviate with zero mean and unit\n! variance, using routine RAN1(idum) as the source of uniform deviates.\n! From \"Numerical Recipes\" by Press, Flannery, Teulolsky, Vetterling\n!\n DATA iset/0/\n SAVE iset, gset\n!\n IF( iset .EQ. 0 ) THEN ! we don't have an extra deviate handy, so pick two\n 1 v1 = 2. * ran1(idum) - 1. ! uniform numbers in the square extending from\n v2 = 2. * ran1(idum) - 1. ! -1 to +1 in each direction.\n r = v1*v1 + v2*v2 ! see if the are on the unit circle\n IF( r .GE. 1 ) GOTO 1 ! and if they are not, try again\n fac = SQRT( -2.*LOG(r)/r ) ! now make the Box-Muller transformation\n gset = v1 * fac ! to get two normal deviates. Return one\n gasdev = v2 * fac ! and save the other for the next time.\n iset = 1 ! set the flag\n ELSE ! we have an extra deviate handy,\n gasdev = gset ! so return it\n iset = 0 ! and unset the flag\n ENDIF\n RETURN\n END\n", "meta": {"hexsha": "f5266e2ff90850e678faa30ccdfdca92d249085f", "size": 1594, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gasdev.f", "max_stars_repo_name": "henkart/sioseis-2020.5.0", "max_stars_repo_head_hexsha": "1c7e606b5a3a615abf3cdd6687115f8a4117e855", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "gasdev.f", "max_issues_repo_name": "henkart/sioseis-2020.5.0", "max_issues_repo_head_hexsha": "1c7e606b5a3a615abf3cdd6687115f8a4117e855", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gasdev.f", "max_forks_repo_name": "henkart/sioseis-2020.5.0", "max_forks_repo_head_hexsha": "1c7e606b5a3a615abf3cdd6687115f8a4117e855", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 66.4166666667, "max_line_length": 123, "alphanum_fraction": 0.3939774153, "num_tokens": 340, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122263731811, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6952675913639379}} {"text": "module compute_reaction_rates_module\n\n use bl_types\n use bl_error_module\n use probin_reactdiff_module, only : nspecies, nreactions, stoichiometric_factors, &\n rate_const, rate_multiplier, include_discrete_LMA_correction\n implicit none\n\n private\n\n public :: compute_reaction_rates\n\ncontains\n\n ! compute reaction rates in units (# reactions) / (unit time) / (unit volume)\n subroutine compute_reaction_rates(n_in,reaction_rates,dv)\n\n real(kind=dp_t), intent(in ) :: n_in(:),dv\n real(kind=dp_t), intent(inout) :: reaction_rates(:)\n\n integer :: reaction, species\n\n real(kind=dp_t) :: n_nonneg(nspecies)\n\n n_nonneg(1:nspecies) = max(0.d0,n_in(1:nspecies))\n \n if(include_discrete_LMA_correction) then\n ! Use traditional LMA but correct for the fact that for binary reactions rate ~ N*(N-1) and not N^2, etc.,\n ! where N is the total number of molecules\n do reaction=1, nreactions\n !write(*,*) \"reaction=\", reaction, \" rate_const=\", rate_const(reaction), &\n ! \" stochiometry=\", stoichiometric_factors(1:nspecies,1,reaction)\n reaction_rates(reaction) = rate_multiplier*rate_const(reaction)\n do species=1, nspecies\n select case(stoichiometric_factors(species,1,reaction))\n case(0)\n ! Species does not participate in reaction\n case(1)\n ! Rate ~ N\n reaction_rates(reaction)= &\n reaction_rates(reaction)*n_nonneg(species)\n case(2)\n ! Rate ~ N*(N-1)\n reaction_rates(reaction)= &\n reaction_rates(reaction)*n_nonneg(species)*(n_nonneg(species)-1.0d0/dv) \n case(3) \n ! Rate ~ N*(N-1)*(N-2)\n reaction_rates(reaction)= &\n reaction_rates(reaction)*n_nonneg(species)*max(n_nonneg(species)-1.0d0/dv,0.d0) &\n *max(n_nonneg(species)-2.0d0/dv,0.d0)\n case default\n ! This is essentially impossible in practice and won't happen\n call bl_error(\"Stochiometric coefficients larger then 3 not supported\") \n end select\n end do\n !write(*,*) \"reaction=\", reaction, \" rate=\", reaction_rates(reaction)\n end do\n else\n ! Use traditional LMA without accounting for discrete/integer nature of the molecules involved\n do reaction=1, nreactions\n ! This works since raising to the zeroth power gives unity:\n reaction_rates(reaction) = rate_multiplier*rate_const(reaction)*&\n product(n_nonneg(1:nspecies)**stoichiometric_factors(1:nspecies,1,reaction))\n end do\n end if\n \n end subroutine compute_reaction_rates\n\nend module compute_reaction_rates_module\n", "meta": {"hexsha": "9ff255f02be77d40b81e6a39eb24ebf084f53fe7", "size": 2821, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/src_reactDiff/compute_reaction_rates.f90", "max_stars_repo_name": "BoxLib-Codes/FHD_ReactDiff", "max_stars_repo_head_hexsha": "ec008a0565e6c68d30193ff9da1d6bc9ffafb13e", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2018-03-20T14:48:31.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-09T06:25:01.000Z", "max_issues_repo_path": "src/src_reactDiff/compute_reaction_rates.f90", "max_issues_repo_name": "BoxLib-Codes/FHD_ReactDiff", "max_issues_repo_head_hexsha": "ec008a0565e6c68d30193ff9da1d6bc9ffafb13e", "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": "src/src_reactDiff/compute_reaction_rates.f90", "max_forks_repo_name": "BoxLib-Codes/FHD_ReactDiff", "max_forks_repo_head_hexsha": "ec008a0565e6c68d30193ff9da1d6bc9ffafb13e", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-03-31T11:38:43.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-06T12:33:44.000Z", "avg_line_length": 40.3, "max_line_length": 113, "alphanum_fraction": 0.6235377526, "num_tokens": 677, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6952675875228472}} {"text": "\tSUBROUTINE VC_VAPR ( t, nxy, e, iret )\nC************************************************************************\nC* VC_VAPR\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This subroutine computes the saturation vapor pressure corresponding *\nC* to a given temperature.\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* VC_VAPR ( T, NXY, E, IRET )\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*\tT (NXY)\tREAL\t\tTemperature (K or C)\t\t*\nC*\tNXY\t\tINTEGER\t\tNumber of points\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tE (NXY)\tREAL\t\tVapor pressure (mb)\t\t*\nC*\tIRET\t\tINTEGER\t\tReturn code\t\t\t*\nC*\t\t\t\t\t 0 = normal return\t\t*\nC*\t\t\t\t\t +1 = all missing\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* K. Brill/NMC 05/92\t\t\t\t\t\t*\nC* G. Krueger/EAI 4/96 Replaced C->K constant with TMCK\t*\nC************************************************************************\n\tINCLUDE \t'GEMPRM.PRM'\nC*\n\tREAL\t\tt (*), e (*)\nC*\n\tINCLUDE\t\t'ERMISS.FNC'\nC-----------------------------------------------------------------------\n\tiret = 0\nC*\n\ticnt = 0\n\tDO i = 1, nxy\n\t IF ( ERMISS ( t (i) ) ) THEN\n\t\te (i) = RMISSD\n\t\ticnt = icnt + 1\n\t ELSE\n\t \tIF ( t (i) .gt. 70. ) THEN\nC\nC*\t\t Convert to C.\nC\n\t\t tmp = t (i) - TMCK \n\t\tELSE\n\t\t tmp = t (i)\n\t\tEND IF\n\t END IF\n\t tmp = 17.67 * tmp / ( tmp + 243.5 )\n\t e (i) = 6.112 * EXP ( tmp )\n\tEND DO\nC*\n\tIF ( icnt .eq. nxy ) iret = +1\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "1c5123c39bc57c37d0383a5822539a40c3f8da1b", "size": 1336, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/programs/gd/gdvint/vcvapr.f", "max_stars_repo_name": "oxelson/gempak", "max_stars_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2015-06-03T15:26:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T22:36:03.000Z", "max_issues_repo_path": "gempak/source/programs/gd/gdvint/vcvapr.f", "max_issues_repo_name": "oxelson/gempak", "max_issues_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 60, "max_issues_repo_issues_event_min_datetime": "2015-05-11T21:36:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T16:22:42.000Z", "max_forks_repo_path": "gempak/source/programs/gd/gdvint/vcvapr.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": 24.2909090909, "max_line_length": 73, "alphanum_fraction": 0.4199101796, "num_tokens": 481, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.695267582680314}} {"text": "module mod_random\n\n ! Provides a random number generator with\n ! normal distribution, centered on zero.\n\n use mod_kinds, only: ik, rk\n\n implicit none\n\n private\n public :: randn\n\n real(rk), parameter :: pi = 4 * atan(1._rk)\n\n interface randn\n module procedure :: randn1d, randn2d\n end interface randn\n\ncontains\n\n function randn1d(n) result(r)\n ! Generates n random numbers with a normal distribution.\n integer(ik), intent(in) :: n\n real(rk) :: r(n), r2(n)\n call random_number(r)\n call random_number(r2)\n r = sqrt(-2 * log(r)) * cos(2 * pi * r2)\n end function randn1d\n\n function randn2d(m, n) result(r)\n ! Generates m x n random numbers with a normal distribution.\n integer(ik), intent(in) :: m, n\n real(rk) :: r(m, n), r2(m, n)\n call random_number(r)\n call random_number(r2)\n r = sqrt(-2 * log(r)) * cos(2 * pi * r2)\n end function randn2d\n\nend module mod_random\n", "meta": {"hexsha": "d8c1b4af4e6fcd9deaa057209bcbca8f09fdf631", "size": 913, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/lib/mod_random.f90", "max_stars_repo_name": "GridIO/neural-fortran", "max_stars_repo_head_hexsha": "84ceb03cb807949a07807cc7aa010e1ee842035b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 222, "max_stars_repo_stars_event_min_datetime": "2018-07-29T22:12:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T16:16:44.000Z", "max_issues_repo_path": "src/lib/mod_random.f90", "max_issues_repo_name": "ivan-pi/neural-fortran", "max_issues_repo_head_hexsha": "35662125d6e6655092957554c7d2297506af670d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 28, "max_issues_repo_issues_event_min_datetime": "2018-07-31T17:16:20.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T17:33:11.000Z", "max_forks_repo_path": "src/lib/mod_random.f90", "max_forks_repo_name": "ivan-pi/neural-fortran", "max_forks_repo_head_hexsha": "35662125d6e6655092957554c7d2297506af670d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 45, "max_forks_repo_forks_event_min_datetime": "2018-11-26T03:00:50.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T06:30:48.000Z", "avg_line_length": 22.825, "max_line_length": 64, "alphanum_fraction": 0.6495071194, "num_tokens": 281, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122113355091, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.6952675749981321}} {"text": "c Subroutine to find dew point from vapor pressure\r\nc AJ_Kettle, Nov7/2017\r\n\r\nc from wmo_8_en-2012.pdf pI.4-29\r\n\r\n SUBROUTINE dewfrostp_from_vpres_spres(f_ew_hpa,f_p_hpa,\r\n + s_wetb_iceflag, \r\n + f_dewp_c)\r\n\r\n IMPLICIT NONE\r\nc************************************************************************\r\n REAL :: f_dewp_c \r\n\r\n REAL :: f_ew_hpa\r\n REAL :: f_p_hpa \r\n\r\n REAL :: f_p_coef\r\n CHARACTER(LEN=1) :: s_wetb_iceflag\r\nc************************************************************************\r\nc Find pressure coefficient\r\n f_p_coef=1.0016+3.15*10.0**(-6.0)*f_p_hpa-0.074/f_p_hpa\r\n\r\n IF (s_wetb_iceflag.NE.'E') THEN \r\n f_dewp_c=(243.12*ALOG(f_ew_hpa/(6.112*f_p_coef)))/\r\n + (17.62-ALOG(f_ew_hpa/(6.112*f_p_coef)))\r\n ENDIF\r\n IF (s_wetb_iceflag.EQ.'E') THEN \r\n f_dewp_c=(272.62*ALOG(f_ew_hpa/(6.112*f_p_coef)))/\r\n + (22.46-ALOG(f_ew_hpa/(6.112*f_p_coef)))\r\n ENDIF\r\n\r\nc f_dewp_c=(243.12*ALOG(f_ew_pa/611.2))/(17.62-ALOG(f_ew_pa/611.2))\r\nc************************************************************************\r\n RETURN\r\n END", "meta": {"hexsha": "f399c40ec331f48404fab3b0de51f0ab4a088208", "size": 1215, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "P20171014_dwdsub/Subroutine/dewfrostp_from_vpres_spres.f", "max_stars_repo_name": "ajkettle/glamod-nuim", "max_stars_repo_head_hexsha": "beb37a3c2acab3f334918dda3e366c7882cc0960", "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": "P20171014_dwdsub/Subroutine/dewfrostp_from_vpres_spres.f", "max_issues_repo_name": "ajkettle/glamod-nuim", "max_issues_repo_head_hexsha": "beb37a3c2acab3f334918dda3e366c7882cc0960", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 23, "max_issues_repo_issues_event_min_datetime": "2022-01-28T13:57:39.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T09:34:41.000Z", "max_forks_repo_path": "P20171014_dwdsub/Subroutine/dewfrostp_from_vpres_spres.f", "max_forks_repo_name": "ajkettle/glamod-nuim", "max_forks_repo_head_hexsha": "beb37a3c2acab3f334918dda3e366c7882cc0960", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-01-24T12:06:06.000Z", "max_forks_repo_forks_event_max_datetime": "2019-01-24T12:06:06.000Z", "avg_line_length": 34.7142857143, "max_line_length": 74, "alphanum_fraction": 0.4551440329, "num_tokens": 385, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9805806484125337, "lm_q2_score": 0.7090191337850932, "lm_q1q2_score": 0.6952504419438796}} {"text": "program sqrt\n\nuse newtonraphson\nuse, intrinsic :: iso_c_binding\nimplicit none\n\ncharacter(len=5) :: arg\ninteger :: nargs\n\n! arguments for the fortran routines\nreal(8) :: input\nreal(8) :: x0 = 10\ninteger :: iterations = 10\nlogical(1) :: printIts = .TRUE.\nreal(8) :: result\n\n! read the input argument and convert to real\nnargs = command_argument_count()\nif (nargs.ne.1) then\n print *, \"Usage: sqrt N where N is a real number\"\n stop 1\nendif\n\ncall getarg(1, arg)\nread(arg,*) input\n\n! get the square root from newton raphson method\nresult = nr_sqrt(input, x0, iterations, printIts)\n\n! display the results\nprint \"(3A,F10.4)\", \"The square root of \",trim(arg),\" is \",result\n\nend program\n", "meta": {"hexsha": "1549041573529097d4691089fa557a835e18ce66", "size": 680, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "sqrt.f90", "max_stars_repo_name": "rafaelmudafort/sqrt", "max_stars_repo_head_hexsha": "b8db75c0fa29360aea056bd1640d46cacf75379b", "max_stars_repo_licenses": ["Xnet", "X11"], "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.f90", "max_issues_repo_name": "rafaelmudafort/sqrt", "max_issues_repo_head_hexsha": "b8db75c0fa29360aea056bd1640d46cacf75379b", "max_issues_repo_licenses": ["Xnet", "X11"], "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.f90", "max_forks_repo_name": "rafaelmudafort/sqrt", "max_forks_repo_head_hexsha": "b8db75c0fa29360aea056bd1640d46cacf75379b", "max_forks_repo_licenses": ["Xnet", "X11"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-10-30T19:55:52.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-12T15:59:05.000Z", "avg_line_length": 20.0, "max_line_length": 65, "alphanum_fraction": 0.7102941176, "num_tokens": 203, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.695202963514525}} {"text": "subroutine DHaj(n, aj, extend, exitstatus)\n!------------------------------------------------------------------------------\n!\n! This subroutine will compute the weights a_j that are used to\n! expand an equally sampled grid into spherical harmonics by using\n! the sampling theorem presented in Driscoll and Healy (1994).\n!\n! Note that the number of samples, n, must be even! Also, a_j(1) = 0\n!\n! Calling parameters\n!\n! IN\n! n Number of samples in longitude and latitude.\n!\n! IN, optional\n! extend If 1, include the latitudinal band for 90 S, which\n! increases the dimension of aj by 1.\n!\n! OUT, optional\n! aj Vector of length n or n+1 containing the weights.\n!\n! Copyright (c) 2005-2019, SHTOOLS\n! All rights reserved.\n!\n!------------------------------------------------------------------------------\n use ftypes\n\n implicit none\n\n integer, intent(in) :: n\n real(dp), intent(out) :: aj(:)\n integer, intent(in), optional :: extend\n integer, intent(out), optional :: exitstatus\n integer :: j, l, n_out, extend_grid\n real(dp) :: sum1, pi\n\n if (present(exitstatus)) exitstatus = 0\n\n pi = acos(-1.0_dp)\n\n if (mod(n,2) /= 0) then\n print*, \"Error --- DH_aj\"\n print*, \"The number of samples in the equi-dimensional grid must \" // &\n \"be even for use with SHExpandDH\"\n print*, \"Input value of N is \", n\n if (present(exitstatus)) then\n exitstatus = 2\n return\n else\n stop\n end if\n end if\n\n if (present(extend)) then\n if (extend == 0) then\n extend_grid = 0\n n_out = n\n else if (extend == 1) then\n extend_grid = 1\n n_out = n + 1\n else\n print*, \"Error --- DHaj\"\n print*, \"Optional parameter EXTEND must be 0 or 1.\"\n print*, \"Input value is \", extend\n if (present(exitstatus)) then\n exitstatus = 2\n return\n else\n stop\n end if\n end if\n else\n extend_grid = 0\n n_out = n\n end if\n\n if (size(aj) < n_out) then\n print*, \"Error --- DH_aj\"\n print*, \"The size of AJ must be greater than or equal \" // &\n \"to \", n_out\n print*, \"Input array is dimensioned as \", size(aj)\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n end if\n\n do j = 0, n-1\n sum1 = 0.0_dp\n\n do l = 0, n/2 -1\n sum1 = sum1 + sin( dble(2*l+1) * pi * dble(j) / dble(n) ) &\n / dble(2*l+1)\n end do\n\n aj(j+1) = sum1 * sin(pi * dble(j) / dble(n)) * sqrt(8.0_dp) / dble(n)\n\n end do\n\n if (extend_grid == 1) then\n aj(n_out) = 0.0_dp\n end if\n\nend subroutine DHaj\n", "meta": {"hexsha": "08ea753a3e02c04ba4c515cd23fa9d2300bbb94e", "size": 2922, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/DHaj.f95", "max_stars_repo_name": "megies/SHTOOLS", "max_stars_repo_head_hexsha": "740455a28eafb6bb23a449cdec43724e86d99c4f", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/DHaj.f95", "max_issues_repo_name": "megies/SHTOOLS", "max_issues_repo_head_hexsha": "740455a28eafb6bb23a449cdec43724e86d99c4f", "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/DHaj.f95", "max_forks_repo_name": "megies/SHTOOLS", "max_forks_repo_head_hexsha": "740455a28eafb6bb23a449cdec43724e86d99c4f", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.0555555556, "max_line_length": 79, "alphanum_fraction": 0.4883641342, "num_tokens": 793, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.6952029576245898}} {"text": " SUBROUTINE MB04DL( JOB, N, THRESH, A, LDA, B, LDB, ILO, IHI,\n $ LSCALE, RSCALE, DWORK, IWARN, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To balance a pair of N-by-N real matrices (A,B). This involves,\nC first, permuting A and B by equivalence transformations to isolate\nC eigenvalues in the first 1 to ILO-1 and last IHI+1 to N elements\nC on the diagonal of A and B; and second, applying a diagonal\nC equivalence transformation to rows and columns ILO to IHI to make\nC the rows and columns as close in 1-norm as possible. Both steps\nC are optional. Balancing may reduce the 1-norms of the matrices,\nC and improve the accuracy of the computed eigenvalues and/or\nC eigenvectors in the generalized eigenvalue problem\nC A*x = lambda*B*x.\nC\nC This routine may optionally improve the conditioning of the\nC scaling transformation compared to the LAPACK routine DGGBAL.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC JOB CHARACTER*1\nC Specifies the operations to be performed on A and B:\nC = 'N': none: simply set ILO = 1, LSCALE(I) = 1.0 and\nC RSCALE(I) = 1.0 for I = 1,...,N.\nC = 'P': permute only;\nC = 'S': scale only;\nC = 'B': both permute and scale.\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The order of matrices A and B. N >= 0.\nC\nC THRESH (input) DOUBLE PRECISION\nC If JOB = 'S' or JOB = 'B', and THRESH >= 0, threshold\nC value for magnitude of the elements to be considered in\nC the scaling process: elements with magnitude less than or\nC equal to THRESH*MXNORM are ignored for scaling, where\nC MXNORM is the maximum of the 1-norms of the original\nC submatrices A(s,s) and B(s,s), with s = ILO:IHI.\nC If THRESH < 0, the subroutine finds the scaling factors\nC for which some conditions, detailed below, are fulfilled.\nC A sequence of increasing strictly positive threshold\nC values is used.\nC If THRESH = -1, the condition is that\nC max( norm(A(s,s),1)/norm(B(s,s),1),\nC norm(B(s,s),1)/norm(S(s,s),1) ) (1)\nC has the smallest value, for the threshold values used,\nC where A(s,s) and B(s,s) are the scaled submatrices.\nC If THRESH = -2, the norm ratio reduction (1) is tried, but\nC the subroutine may return IWARN = 1 and reset the scaling\nC factors to 1, if this seems suitable. See the description\nC of the argument IWARN and FURTHER COMMENTS.\nC If THRESH = -3, the condition is that\nC norm(A(s,s),1)*norm(B(s,s),1) (2)\nC has the smallest value for the scaled submatrices.\nC If THRESH = -4, the norm reduction in (2) is tried, but\nC the subroutine may return IWARN = 1 and reset the scaling\nC factors to 1, as for THRESH = -2 above.\nC If THRESH = -VALUE, with VALUE >= 10, the condition\nC numbers of the left and right scaling transformations will\nC be bounded by VALUE, i.e., the ratios between the largest\nC and smallest entries in LSCALE(s) and RSCALE(s), will be\nC at most VALUE. VALUE should be a power of 10.\nC If JOB = 'N' or JOB = 'P', the value of THRESH is\nC irrelevant.\nC\nC A (input/output) DOUBLE PRECISION array, dimension (LDA,N)\nC On entry, the leading N-by-N part of this array must\nC contain the matrix A.\nC On exit, the leading N-by-N part of this array contains\nC the balanced matrix A.\nC In particular, the strictly lower triangular part of the\nC first ILO-1 columns and the last N-IHI rows of A is zero.\nC\nC LDA INTEGER\nC The leading dimension of the array A. LDA >= MAX(1,N).\nC\nC B (input/output) DOUBLE PRECISION array, dimension (LDB, N)\nC On entry, the leading N-by-N part of this array must\nC contain the matrix B.\nC On exit, the leading N-by-N part of this array contains\nC the balanced matrix B.\nC In particular, the strictly lower triangular part of the\nC first ILO-1 columns and the last N-IHI rows of B is zero.\nC If JOB = 'N', the arrays A and B are not referenced.\nC\nC LDB INTEGER\nC The leading dimension of the array B. LDB >= MAX(1, N).\nC\nC ILO (output) INTEGER\nC IHI (output) INTEGER\nC ILO and IHI are set to integers such that on exit\nC A(i,j) = 0 and B(i,j) = 0 if i > j and\nC j = 1,...,ILO-1 or i = IHI+1,...,N.\nC If JOB = 'N' or 'S', ILO = 1 and IHI = N.\nC\nC LSCALE (output) DOUBLE PRECISION array, dimension (N)\nC Details of the permutations and scaling factors applied\nC to the left side of A and B. If P(j) is the index of the\nC row interchanged with row j, and D(j) is the scaling\nC factor applied to row j, then\nC LSCALE(j) = P(j) for j = 1,...,ILO-1\nC = D(j) for j = ILO,...,IHI\nC = P(j) for j = IHI+1,...,N.\nC The order in which the interchanges are made is N to\nC IHI+1, then 1 to ILO-1.\nC\nC RSCALE (output) DOUBLE PRECISION array, dimension (N)\nC Details of the permutations and scaling factors applied\nC to the right side of A and B. If P(j) is the index of the\nC column interchanged with column j, and D(j) is the scaling\nC factor applied to column j, then\nC RSCALE(j) = P(j) for j = 1,...,ILO-1\nC = D(j) for j = ILO,...,IHI\nC = P(j) for j = IHI+1,...,N.\nC The order in which the interchanges are made is N to\nC IHI+1, then 1 to ILO-1.\nC\nC Workspace\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK) where\nC LDWORK = 0, if JOB = 'N' or JOB = 'P', or N = 0;\nC LDWORK = 6*N, if (JOB = 'S' or JOB = 'B') and THRESH >= 0;\nC LDWORK = 8*N, if (JOB = 'S' or JOB = 'B') and THRESH < 0.\nC On exit, if JOB = 'S' or JOB = 'B', DWORK(1) and DWORK(2)\nC contain the initial 1-norms of A(s,s) and B(s,s), and\nC DWORK(3) and DWORK(4) contain their final 1-norms,\nC respectively. Moreover, DWORK(5) contains the THRESH value\nC used (irrelevant if IWARN = 1 or ILO = IHI).\nC\nC Warning Indicator\nC\nC IWARN INTEGER\nC = 0: no warning;\nC = 1: scaling has been requested, for THRESH = -2 or\nC THRESH = -4, but it most probably would not improve\nC the accuracy of the computed solution for a related\nC eigenproblem (since maximum norm increased\nC significantly compared to the original pencil\nC matrices and (very) high and/or small scaling\nC factors occurred). The returned scaling factors have\nC been reset to 1, but information about permutations,\nC if requested, has been preserved.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit.\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value.\nC\nC METHOD\nC\nC Balancing consists of applying an equivalence transformation\nC to isolate eigenvalues and/or to make the 1-norms of the rows\nC and columns ILO,...,IHI of A and B nearly equal. If THRESH < 0,\nC a search is performed to find those scaling factors giving the\nC smallest norm ratio or product defined above (see the description\nC of the parameter THRESH).\nC\nC Assuming JOB = 'S', let Dl and Dr be diagonal matrices containing\nC the vectors LSCALE and RSCALE, respectively. The returned matrices\nC are obtained using the equivalence transformation\nC\nC Dl*A*Dr and Dl*B*Dr.\nC\nC For THRESH = 0, the routine returns essentially the same results\nC as the LAPACK subroutine DGGBAL [1]. Setting THRESH < 0, usually\nC gives better results than DGGBAL for badly scaled matrix pencils.\nC\nC REFERENCES\nC\nC [1] Anderson, E., Bai, Z., Bischof, C., Demmel, J., Dongarra, J.,\nC Du Croz, J., Greenbaum, A., Hammarling, S., McKenney, A.,\nC Ostrouchov, S., and Sorensen, D.\nC LAPACK Users' Guide: Second Edition.\nC SIAM, Philadelphia, 1995.\nC\nC NUMERICAL ASPECTS\nC\nC No rounding errors appear if JOB = 'P'.\nC\nC FURTHER COMMENTS\nC\nC If THRESH = -2, the increase of the maximum norm of the scaled\nC submatrices, compared to the maximum norm of the initial\nC submatrices, is bounded by MXGAIN = 100.\nC If THRESH = -2, or THRESH = -4, the maximum condition number of\nC the scaling transformations is bounded by MXCOND = 1/SQRT(EPS),\nC where EPS is the machine precision (see LAPACK Library routine\nC DLAMCH).\nC\nC CONTRIBUTOR\nC\nC V. Sima, Research Institute for Informatics, Bucharest, Dec. 2015.\nC\nC REVISIONS\nC\nC V. Sima, Jan. 2016, Jan. 2017, Feb. 2017.\nC\nC KEYWORDS\nC\nC Balancing, eigenvalue, equivalence transformation, matrix algebra,\nC matrix operations.\nC\nC *********************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION HALF, ONE, TEN, THREE, ZERO\n PARAMETER ( HALF = 0.5D+0, ONE = 1.0D+0, TEN = 1.0D+1,\n $ THREE = 3.0D+0, ZERO = 0.0D+0 )\n DOUBLE PRECISION MXGAIN, SCLFAC\n PARAMETER ( MXGAIN = 1.0D+2, SCLFAC = 1.0D+1 )\nC .. Scalar Arguments ..\n CHARACTER JOB\n INTEGER IHI, ILO, INFO, IWARN, LDA, LDB, N\n DOUBLE PRECISION THRESH\nC .. Array Arguments ..\n DOUBLE PRECISION A(LDA,*), B(LDB,*), DWORK(*), LSCALE(*),\n $ RSCALE(*)\nC .. Local Scalars ..\n LOGICAL EVNORM, LOOP, LPERM, LSCAL, STORMN\n INTEGER I, ICAB, IFLOW, IP1, IR, IRAB, IT, ITER, ITH,\n $ J, JC, JP1, K, KOUNT, KS, KW1, KW2, KW3, KW4,\n $ KW5, KW6, KW7, L, LM1, LRAB, LSFMAX, LSFMIN, M,\n $ NR, NRP2\n DOUBLE PRECISION AB, ALPHA, BASL, BETA, CAB, CMAX, COEF, COEF2,\n $ COEF5, COR, DENOM, EPS, EW, EWC, GAMMA, GAP,\n $ MINPRO, MINRAT, MN, MX, MXCOND, MXNORM, MXS,\n $ NA, NA0, NAS, NB, NB0, NBS, PGAMMA, PROD, RAB,\n $ RATIO, SFMAX, SFMIN, SUM, T, TA, TB, TC, TH,\n $ TH0, THS\nC .. Local Arrays ..\n DOUBLE PRECISION DUM(1)\nC .. External Functions ..\n LOGICAL LSAME\n INTEGER IDAMAX\n DOUBLE PRECISION DDOT, DLAMCH, DLANGE\n EXTERNAL DDOT, DLAMCH, DLANGE, IDAMAX, LSAME\nC .. External Subroutines ..\n EXTERNAL DAXPY, DCOPY, DSCAL, DSWAP, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC ABS, DBLE, INT, LOG10, MAX, MIN, SIGN, SQRT\nC\nC .. Executable Statements ..\nC\nC Test the input parameters.\nC\n INFO = 0\n IWARN = 0\n LPERM = LSAME( JOB, 'P' ) .OR. LSAME( JOB, 'B' )\n LSCAL = LSAME( JOB, 'S' ) .OR. LSAME( JOB, 'B' )\nC\n IF( .NOT.LPERM .AND. .NOT.LSCAL .AND. .NOT.LSAME( JOB, 'N' ) )\n $ THEN\n INFO = -1\n ELSE IF( N.LT.0 ) THEN\n INFO = -2\n ELSE IF( LDA.LT.MAX( 1, N ) ) THEN\n INFO = -5\n ELSE IF( LDB.LT.MAX( 1, N ) ) THEN\n INFO = -7\n END IF\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'MB04DL', -INFO )\n RETURN\n END IF\nC\n ILO = 1\n IHI = N\nC\nC Quick return if possible.\nC\n IF( N.EQ.0 )\n $ RETURN\n IF( ( .NOT.LPERM .AND. .NOT.LSCAL ) .OR. N.EQ.1 ) THEN\n DUM(1) = ONE\n CALL DCOPY( N, DUM, 0, LSCALE, 1 )\n CALL DCOPY( N, DUM, 0, RSCALE, 1 )\n IF( N.EQ.1 .AND. LSCAL ) THEN\n NA0 = ABS( A(1,1) )\n NB0 = ABS( B(1,1) )\n DWORK(1) = NA0\n DWORK(2) = NB0\n DWORK(3) = NA0\n DWORK(4) = NB0\n DWORK(5) = THRESH\n END IF\n RETURN\n END IF\nC\n K = 1\n L = N\nC\n IF( LPERM ) THEN\nC\nC Permute the matrices A and B to isolate the eigenvalues.\nC\nC Find row with one nonzero in columns 1 through L.\nC\n 10 CONTINUE\n LM1 = L - 1\n DO 60 I = L, 1, -1\n DO 20 J = 1, LM1\n JP1 = J + 1\n IF( A(I,J).NE.ZERO .OR. B(I,J).NE.ZERO )\n $ GO TO 30\n 20 CONTINUE\n J = L\n GO TO 50\nC\n 30 CONTINUE\n DO 40 J = JP1, L\n IF( A(I,J).NE.ZERO .OR. B(I,J).NE.ZERO )\n $ GO TO 60\n 40 CONTINUE\n J = JP1 - 1\nC\n 50 CONTINUE\n M = L\n IFLOW = 1\n GO TO 130\n 60 CONTINUE\nC\nC Find column with one nonzero in rows K through N.\nC\n 70 CONTINUE\n DO 120 J = K, L\n DO 80 I = K, LM1\n IP1 = I + 1\n IF( A(I,J).NE.ZERO .OR. B(I,J).NE.ZERO )\n $ GO TO 90\n 80 CONTINUE\n I = L\n GO TO 110\nC\n 90 CONTINUE\n DO 100 I = IP1, L\n IF( A(I,J).NE.ZERO .OR. B(I,J).NE.ZERO )\n $ GO TO 120\n 100 CONTINUE\n I = IP1 - 1\nC\n 110 CONTINUE\n M = K\n IFLOW = 2\n GO TO 130\n 120 CONTINUE\n GO TO 140\nC\nC Permute rows M and I.\nC\n 130 CONTINUE\n LSCALE(M) = I\n IF( I.NE.M ) THEN\n CALL DSWAP( N-K+1, A(I,K), LDA, A(M,K), LDA )\n CALL DSWAP( N-K+1, B(I,K), LDB, B(M,K), LDB )\n END IF\nC\nC Permute columns M and J.\nC\n RSCALE(M) = J\n IF( J.NE.M ) THEN\n CALL DSWAP( L, A(1,J), 1, A(1,M), 1 )\n CALL DSWAP( L, B(1,J), 1, B(1,M), 1 )\n END IF\nC\n IF( IFLOW.EQ.1 ) THEN\n L = LM1\n IF( L.NE.1 )\n $ GO TO 10\nC\n RSCALE(1) = ONE\n LSCALE(1) = ONE\n ELSE\n K = K + 1\n GO TO 70\n END IF\n END IF\nC\n 140 CONTINUE\n ILO = K\n IHI = L\nC\n IF( .NOT.LSCAL ) THEN\n DO 150 I = ILO, IHI\n LSCALE(I) = ONE\n RSCALE(I) = ONE\n 150 CONTINUE\n RETURN\n END IF\nC\n NR = IHI - ILO + 1\nC\nC Compute initial 1-norms and return if ILO = N.\nC\n NA0 = DLANGE( '1-norm', NR, NR, A(ILO,ILO), LDA, DWORK )\n NB0 = DLANGE( '1-norm', NR, NR, B(ILO,ILO), LDB, DWORK )\nC\n IF( ILO.EQ.IHI ) THEN\n DWORK(1) = NA0\n DWORK(2) = NB0\n DWORK(3) = NA0\n DWORK(4) = NB0\n DWORK(5) = THRESH\n RETURN\n END IF\nC\nC Balance the submatrices in rows ILO to IHI.\nC\nC Initialize balancing and allocate work storage.\nC\n KW1 = N\n KW2 = KW1 + N\n KW3 = KW2 + N\n KW4 = KW3 + N\n KW5 = KW4 + N\n DUM(1) = ZERO\nC\nC Prepare for scaling.\nC\n SFMIN = DLAMCH( 'Safe minimum' )\n SFMAX = ONE / SFMIN\n BASL = LOG10( SCLFAC )\n LSFMIN = INT( LOG10( SFMIN ) / BASL + ONE )\n LSFMAX = INT( LOG10( SFMAX ) / BASL )\n MXNORM = MAX( NA0, NB0 )\n LOOP = THRESH.LT.ZERO\nC\n IF( LOOP ) THEN\nC\nC Compute relative threshold.\nC\n NA = NA0\n NAS = NA0\n NB = NB0\n NBS = NB0\nC\n ITH = THRESH\n MXS = MXNORM\n MX = ZERO\n MN = SFMAX\n IF( ITH.GE.-2 ) THEN\n IF( NA.LT.NB ) THEN\n RATIO = MIN( NB/NA, SFMAX )\n ELSE\n RATIO = MIN( NA/NB, SFMAX )\n END IF\n MINRAT = RATIO\n ELSE IF( ITH.LE.-10 ) THEN\n MXCOND = -THRESH\n ELSE\n DENOM = MAX( ONE, MXNORM )\n PROD = ( NA/DENOM )*( NB/DENOM )\n MINPRO = PROD\n END IF\n STORMN = .FALSE.\n EVNORM = .FALSE.\nC\nC Find maximum order of magnitude of the differences in sizes of\nC the nonzero entries, not considering diag(A) and diag(B).\nC\n DO 170 J = ILO, IHI\n DO 160 I = ILO, IHI\n IF( I.NE.J ) THEN\n AB = ABS( A(I,J) )\n IF( AB.NE.ZERO )\n $ MN = MIN( MN, AB )\n MX = MAX( MX, AB )\n END IF\n 160 CONTINUE\n 170 CONTINUE\nC\n DO 190 J = ILO, IHI\n DO 180 I = ILO, IHI\n IF( I.NE.J ) THEN\n AB = ABS( B(I,J) )\n IF( AB.NE.ZERO )\n $ MN = MIN( MN, AB )\n MX = MAX( MX, AB )\n END IF\n 180 CONTINUE\n 190 CONTINUE\nC\n IF( MX*SFMIN.LE.MN ) THEN\n GAP = MX/MN\n ELSE\n GAP = SFMAX\n END IF\n EPS = DLAMCH( 'Precision' )\n ITER = MIN( INT( LOG10( GAP ) ), -INT( LOG10( EPS ) ) ) + 1\n TH = MAX( MN, MX*EPS )/MAX( MXNORM, SFMIN )\n THS = TH\n KW6 = KW5 + N + ILO\n KW7 = KW6 + N\n CALL DCOPY( NR, LSCALE(ILO), 1, DWORK(KW6), 1 )\n CALL DCOPY( NR, RSCALE(ILO), 1, DWORK(KW7), 1 )\nC\nC Set the maximum condition number of the transformations.\nC\n IF( ITH.GT.-10 )\n $ MXCOND = ONE/SQRT( EPS )\n ELSE\n TH = MXNORM*THRESH\n ITER = 1\n EVNORM = .TRUE.\n END IF\n TH0 = TH\nC\n COEF = ONE / DBLE( 2*NR )\n COEF2 = COEF*COEF\n COEF5 = HALF*COEF2\n NRP2 = NR + 2\n BETA = ZERO\nC\nC If THRESH < 0, use a loop to reduce the norm ratio.\nC\n DO 400 K = 1, ITER\nC\nC Compute right side vector in resulting linear equations.\nC\n CALL DCOPY( 6*N, DUM, 0, DWORK, 1 )\n CALL DCOPY( NR, DUM, 0, LSCALE(ILO), 1 )\n CALL DCOPY( NR, DUM, 0, RSCALE(ILO), 1 )\n DO 210 I = ILO, IHI\n DO 200 J = ILO, IHI\n TA = ABS( A(I,J) )\n TB = ABS( B(I,J) )\n IF( TA.GT.TH ) THEN\n TA = LOG10( TA ) / BASL\n ELSE\n TA = ZERO\n END IF\n IF( TB.GT.TH ) THEN\n TB = LOG10( TB ) / BASL\n ELSE\n TB = ZERO\n END IF\n DWORK(I+KW4) = DWORK(I+KW4) - TA - TB\n DWORK(J+KW5) = DWORK(J+KW5) - TA - TB\n 200 CONTINUE\n 210 CONTINUE\nC\n IT = 1\nC\nC Start generalized conjugate gradient iteration.\nC\n 220 CONTINUE\nC\n GAMMA = DDOT( NR, DWORK(ILO+KW4), 1, DWORK(ILO+KW4), 1 ) +\n $ DDOT( NR, DWORK(ILO+KW5), 1, DWORK(ILO+KW5), 1 )\nC\n EW = ZERO\n EWC = ZERO\n DO 230 I = ILO, IHI\n EW = EW + DWORK(I+KW4)\n EWC = EWC + DWORK(I+KW5)\n 230 CONTINUE\nC\n GAMMA = COEF*GAMMA - COEF2*( EW**2 + EWC**2 ) -\n $ COEF5*( EW - EWC )**2\n IF( GAMMA.EQ.ZERO )\n $ GO TO 300\n IF( IT.NE.1 )\n $ BETA = GAMMA / PGAMMA\n T = COEF5*( EWC - THREE*EW )\n TC = COEF5*( EW - THREE*EWC )\nC\n CALL DSCAL( NR, BETA, DWORK(ILO), 1 )\n CALL DSCAL( NR, BETA, DWORK(ILO+KW1), 1 )\nC\n CALL DAXPY( NR, COEF, DWORK(ILO+KW4), 1, DWORK(ILO+KW1), 1 )\n CALL DAXPY( NR, COEF, DWORK(ILO+KW5), 1, DWORK(ILO), 1 )\nC\n DO 240 J = ILO, IHI\n DWORK(J) = DWORK(J) + TC\n DWORK(J+KW1) = DWORK(J+KW1) + T\n 240 CONTINUE\nC\nC Apply matrix to vector.\nC\n DO 260 I = ILO, IHI\n KOUNT = 0\n SUM = ZERO\n DO 250 J = ILO, IHI\n KS = KOUNT\n IF( A(I,J).NE.ZERO )\n $ KOUNT = KOUNT + 1\n IF( B(I,J).NE.ZERO )\n $ KOUNT = KOUNT + 1\n SUM = SUM + DBLE( KOUNT - KS )*DWORK(J)\n 250 CONTINUE\n DWORK(I+KW2) = DBLE( KOUNT )*DWORK(I+KW1) + SUM\n 260 CONTINUE\nC\n DO 280 J = ILO, IHI\n KOUNT = 0\n SUM = ZERO\n DO 270 I = ILO, IHI\n KS = KOUNT\n IF( A(I,J).NE.ZERO )\n $ KOUNT = KOUNT + 1\n IF( B(I,J).NE.ZERO )\n $ KOUNT = KOUNT + 1\n SUM = SUM + DBLE( KOUNT - KS )*DWORK(I+KW1)\n 270 CONTINUE\n DWORK(J+KW3) = DBLE( KOUNT )*DWORK(J) + SUM\n 280 CONTINUE\nC\n SUM = DDOT( NR, DWORK(ILO+KW1), 1, DWORK(ILO+KW2), 1 ) +\n $ DDOT( NR, DWORK(ILO), 1, DWORK(ILO+KW3), 1 )\n ALPHA = GAMMA / SUM\nC\nC Determine correction to current iteration.\nC\n CMAX = ZERO\n DO 290 I = ILO, IHI\n COR = ALPHA*DWORK(I+KW1)\n IF( ABS( COR ).GT.CMAX )\n $ CMAX = ABS( COR )\n LSCALE(I) = LSCALE(I) + COR\n COR = ALPHA*DWORK(I)\n IF( ABS( COR ).GT.CMAX )\n $ CMAX = ABS( COR )\n RSCALE(I) = RSCALE(I) + COR\n 290 CONTINUE\nC\n IF( CMAX.GE.HALF ) THEN\nC\n CALL DAXPY( NR, -ALPHA, DWORK(ILO+KW2), 1, DWORK(ILO+KW4),\n $ 1 )\n CALL DAXPY( NR, -ALPHA, DWORK(ILO+KW3), 1, DWORK(ILO+KW5),\n $ 1 )\nC\n PGAMMA = GAMMA\n IT = IT + 1\n IF( IT.LE.NRP2 )\n $ GO TO 220\n END IF\nC\nC End generalized conjugate gradient iteration.\nC\n 300 CONTINUE\nC\nC Compute diagonal scaling matrices.\nC\n DO 310 I = ILO, IHI\n IRAB = IDAMAX( N-ILO+1, A(I,ILO), LDA )\n RAB = ABS( A(I,ILO+IRAB-1) )\n IRAB = IDAMAX( N-ILO+1, B(I,ILO), LDB )\n RAB = MAX( RAB, ABS( B(I,ILO+IRAB-1) ) )\n LRAB = INT( LOG10( RAB+SFMIN ) / BASL + ONE )\n IR = LSCALE(I) + SIGN( HALF, LSCALE(I) )\n IR = MIN( MAX( IR, LSFMIN ), LSFMAX, LSFMAX-LRAB )\n LSCALE(I) = SCLFAC**IR\nC\n ICAB = IDAMAX( IHI, A(1,I), 1 )\n CAB = ABS( A(ICAB,I) )\n ICAB = IDAMAX( IHI, B(1,I), 1 )\n CAB = MAX( CAB, ABS( B(ICAB,I) ) )\n LRAB = INT( LOG10( CAB+SFMIN ) / BASL + ONE )\n JC = RSCALE(I) + SIGN( HALF, RSCALE(I) )\n JC = MIN( MAX( JC, LSFMIN ), LSFMAX, LSFMAX-LRAB )\n RSCALE(I) = SCLFAC**JC\n 310 CONTINUE\nC\n DO 320 I = ILO, IHI\n IF( LSCALE(I).NE.ONE .OR. RSCALE(I).NE.ONE )\n $ GO TO 330\n 320 CONTINUE\nC\nC Finish the procedure for all scaling factors equal to 1.\nC\n NAS = NA0\n NBS = NB0\n THS = TH0\n GO TO 460\nC\n 330 CONTINUE\nC\n IF( LOOP ) THEN\n IF( ITH.LE.-10 ) THEN\nC\nC Compute the reciprocal condition number of the left and\nC right transformations. Continue the loop if it is too\nC small.\nC\n IR = IDAMAX( NR, LSCALE(ILO), 1 )\n JC = IDAMAX( NR, RSCALE(ILO), 1 )\n T = LSCALE(ILO+IR-1)\n MN = T\n DO 340 I = ILO, IHI\n IF( LSCALE(I).LT.MN )\n $ MN = LSCALE(I)\n 340 CONTINUE\n T = MN/T\n TA = RSCALE(ILO+JC-1)\n MN = TA\n DO 350 I = ILO, IHI\n IF( RSCALE(I).LT.MN )\n $ MN = RSCALE(I)\n 350 CONTINUE\n T = MIN( T, MN/TA )\n IF( T.LT.ONE/MXCOND ) THEN\n TH = TH*TEN\n GO TO 400\n ELSE\n THS = TH\n EVNORM = .TRUE.\n GO TO 430\n END IF\n END IF\nC\nC Compute the 1-norms of the scaled submatrices,\nC without actually scaling them.\nC\n NA = ZERO\n DO 370 J = ILO, IHI\n T = ZERO\n DO 360 I = ILO, IHI\n T = T + ABS( A(I,J) )*LSCALE(I)*RSCALE(J)\n 360 CONTINUE\n IF( T.GT.NA )\n $ NA = T\n 370 CONTINUE\nC\n NB = ZERO\n DO 390 J = ILO, IHI\n T = ZERO\n DO 380 I = ILO, IHI\n T = T + ABS( B(I,J) )*LSCALE(I)*RSCALE(J)\n 380 CONTINUE\n IF( T.GT.NB )\n $ NB = T\n 390 CONTINUE\nC\n IF( ITH.GE.-4 .AND. ITH.LT.-2 ) THEN\n PROD = ( NA/DENOM )*( NB/DENOM )\n IF( MINPRO.GT.PROD ) THEN\n MINPRO = PROD\n STORMN = .TRUE.\n CALL DCOPY( NR, LSCALE(ILO), 1, DWORK(KW6), 1 )\n CALL DCOPY( NR, RSCALE(ILO), 1, DWORK(KW7), 1 )\n NAS = NA\n NBS = NB\n THS = TH\n END IF\n ELSE IF( ITH.GE.-2 ) THEN\n IF( NA.LT.NB ) THEN\n RATIO = MIN( NB/NA, SFMAX )\n ELSE\n RATIO = MIN( NA/NB, SFMAX )\n END IF\n IF( MINRAT.GT.RATIO ) THEN\n MINRAT = RATIO\n STORMN = .TRUE.\n CALL DCOPY( NR, LSCALE(ILO), 1, DWORK(KW6), 1 )\n CALL DCOPY( NR, RSCALE(ILO), 1, DWORK(KW7), 1 )\n MXS = MAX( NA, NB )\n NAS = NA\n NBS = NB\n THS = TH\n END IF\n END IF\n TH = TH*TEN\n END IF\n 400 CONTINUE\nC\nC Prepare for scaling.\nC\n IF( LOOP ) THEN\n IF( ITH.LE.-10 ) THEN\nC\nC Could not find enough well conditioned transformations\nC for THRESH <= -10. Set scaling factors to 1 and return.\nC\n DUM(1) = ONE\n CALL DCOPY( NR, DUM(1), 0, LSCALE(ILO), 1 )\n CALL DCOPY( NR, DUM(1), 0, RSCALE(ILO), 1 )\n IWARN = 1\n GO TO 460\n END IF\nC\nC Check if scaling might reduce the accuracy when solving related\nC eigenproblems, and set the scaling factors to 1 in this case,\nC if THRESH = -2 or THRESH = -4.\nC\n IF( ( MXNORM.LT.MXS .AND. MXNORM.LT.MXS/MXGAIN .AND. ITH.EQ.-2)\n $ .OR. ITH.EQ.-4 ) THEN\n IR = IDAMAX( NR, DWORK(KW6), 1 )\n JC = IDAMAX( NR, DWORK(KW7), 1 )\n T = DWORK(KW6+IR-1)\n MN = T\n DO 410 I = KW6, KW6+NR-1\n IF( DWORK(I).LT.MN )\n $ MN = DWORK(I)\n 410 CONTINUE\n T = MN/T\n TA = DWORK(KW7+JC-1)\n MN = TA\n DO 420 I = KW7, KW7+NR-1\n IF( DWORK(I).LT.MN )\n $ MN = DWORK(I)\n 420 CONTINUE\n T = MIN( T, MN/TA )\n IF( T.LT.ONE/MXCOND ) THEN\n DUM(1) = ONE\n CALL DCOPY( NR, DUM(1), 0, LSCALE(ILO), 1 )\n CALL DCOPY( NR, DUM(1), 0, RSCALE(ILO), 1 )\n IWARN = 1\n NAS = NA0\n NBS = NB0\n THS = TH0\n GO TO 460\n END IF\n END IF\n IF( STORMN ) THEN\n CALL DCOPY( NR, DWORK(KW6), 1, LSCALE(ILO), 1 )\n CALL DCOPY( NR, DWORK(KW7), 1, RSCALE(ILO), 1 )\n ELSE\n NAS = NA\n NBS = NB\n THS = TH\n END IF\n END IF\nC\n 430 CONTINUE\nC\nC Row scaling.\nC\n DO 440 I = ILO, IHI\n CALL DSCAL( N-ILO+1, LSCALE(I), A(I,ILO), LDA )\n CALL DSCAL( N-ILO+1, LSCALE(I), B(I,ILO), LDB )\n 440 CONTINUE\nC\nC Column scaling.\nC\n DO 450 J = ILO, IHI\n CALL DSCAL( IHI, RSCALE(J), A(1,J), 1 )\n CALL DSCAL( IHI, RSCALE(J), B(1,J), 1 )\n 450 CONTINUE\nC\nC Set DWORK(1:5).\nC\n 460 CONTINUE\n IF( EVNORM ) THEN\n NAS = DLANGE( '1-norm', NR, NR, A(ILO,ILO), LDA, DWORK )\n NBS = DLANGE( '1-norm', NR, NR, B(ILO,ILO), LDB, DWORK )\n END IF\nC\n DWORK(1) = NA0\n DWORK(2) = NB0\n DWORK(3) = NAS\n DWORK(4) = NBS\n IF( LOOP ) THEN\n DWORK(5) = THS/MAX( MXNORM, SFMIN )\n ELSE\n DWORK(5) = THRESH\n END IF\nC\n RETURN\nC *** Last line of MB04DL ***\n END\n", "meta": {"hexsha": "3c2d3e813304ddf61c4c7963cb2c7729e609646d", "size": 28475, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB04DL.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB04DL.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB04DL.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 32.6548165138, "max_line_length": 72, "alphanum_fraction": 0.4812993854, "num_tokens": 9106, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026528034426, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6951267870497446}} {"text": "!\r\n! Find statistics of mean and covariance matrix of underlying latent vector.\r\n!\r\n! beta is the estimated parameter vector.\r\n\r\n! thpr is a predictor vector.\r\n! tolsing is a tolerance for modified Cholesky decomposition.\r\n\r\n! covmatrix is the estimated covariance matrix of the underlying latent vector corresponding to beta.\r\n! meanvec is the estimated mean of the underlying latent vector.\r\n! Note that this routine is for the case of an underlying normal latent vector.\r\nsubroutine meancovstat(beta,thpr,tolsing,covmatrix,meanvec)\r\nimplicit none\r\ninterface\r\n!\tchol is used to compute a modified Cholesky decomposition of the n by n matrix sym.\r\n!\tThe singularity tolerance is tolsing.\r\n\t\r\n\tfunction chol(sym,tolsing)\r\n\t\timplicit none\r\n\t\treal(kind=8),intent(in)::sym(:,:),tolsing\r\n\t \treal(kind=8)::chol(size(sym,1),size(sym,1))\r\n\tend function chol\r\n\r\n\r\n\r\n\r\n!\tExtract the linear component lintheta and the quadratic component quadtheta from the parameter vector beta.\r\n\tsubroutine getlinquad(beta,lintheta,quadtheta)\r\n\t\timplicit none\r\n\t\treal(kind=8),intent(in)::beta(:)\r\n\t\treal(kind=8),intent(out)::lintheta(:,:),quadtheta(:,:,:)\r\n\tend subroutine getlinquad\r\n\r\n!\tExtract the linear component linth and the quadratic component quadth from lintheta and quadtheta for a given predictor thpr.\r\n\tsubroutine getlinquadth(lintheta,quadtheta,thpr,linth,quadth)\r\n\t\timplicit none\r\n\t\treal(kind=8),intent(in)::lintheta(:,:),quadtheta(:,:,:),thpr(:)\r\n\t\treal(kind=8),intent(out)::linth(:),quadth(:,:)\r\n\tend subroutine getlinquadth\r\n\r\n\t\r\n!\tCompute inverse for n by n matrix with modified Cholesky\r\n!\tdecomposition tri.\r\n\tfunction invert(tri)\r\n\t\timplicit none\r\n\t\treal(kind=8),intent(in)::tri(:,:)\r\n\t\treal(kind=8)::invert(size(tri,1),size(tri,1))\r\n\tend function invert\r\n!\t\tThis program uses the modified Cholesky decomposition\r\n!\t\tin lu to solve the equation lusolve = b.\r\n\r\n\r\n\tfunction solve(lu,b)\r\n\t\timplicit none\r\n\t\t\r\n\t\treal(kind=8),intent(in)::lu(:,:)\r\n\t\treal(kind=8),intent(in)::b(:)\r\n\t\treal(kind=8)::solve(size(b))\r\n\tend function solve\r\n\r\nend interface\r\nreal(kind=8),intent(in)::beta(:),thpr(:),tolsing\r\nreal(kind=8),intent(out)::covmatrix(:,:),meanvec(:)\r\n\r\n!\tcovinverse is the inverse of covmatrix.\r\n! linth is the linear commponent of beta for thpr.\r\n! lintheta is a matrix version of the linear component of beta.\r\n! quadth is the quadratic component of beta for thpr.\r\n! quadtheta is an array version of the quadratic component of beta.\r\n\r\nreal(kind=8)::covinverse(size(covmatrix,1),size(covmatrix,1)),linth(size(covmatrix,1)), lintheta(size(covmatrix,1),size(thpr)),&\r\n\tquadth(size(covmatrix,1),size(covmatrix,1)),quadtheta(size(covmatrix,1),size(covmatrix,1),size(thpr))\r\n\r\n\r\n! Linear component of beta.\r\ncall getlinquad(beta,lintheta,quadtheta)\r\n\r\n\r\n! Linear component of beta for thpr.\r\ncall getlinquadth(lintheta,quadtheta,thpr,linth,quadth)\r\n\r\ncovinverse=-2.0_8*quadth\r\n\r\ncovinverse=chol(covinverse,tolsing)\r\n! Mean of theta.\r\nmeanvec=solve(covinverse,linth)\r\n!\tinvert\r\ncovmatrix=invert(covinverse)\r\n\r\nend subroutine meancovstat\r\n", "meta": {"hexsha": "7112138034316e42d5cb2965877d306a43756394", "size": 3059, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Source/meancovstat.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/meancovstat.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/meancovstat.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": 33.6153846154, "max_line_length": 129, "alphanum_fraction": 0.7250735534, "num_tokens": 826, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465044347828, "lm_q2_score": 0.743168019989179, "lm_q1q2_score": 0.6951196097045974}} {"text": "module julia_set_mod\n use, intrinsic :: iso_fortran_env, only : DP => REAL64\n implicit none\n\n private\n integer, parameter :: MAX_ITERS = 255\n real(kind=DP), parameter :: MAX_NORM = 2.0_DP\n complex(kind=DP), parameter :: C = (-0.622772_DP, 0.42193_DP)\n\n public :: julia_iterate\n\ncontains\n\n elemental function julia_iterate(z0) result(n)\n implicit none\n complex(kind=DP), intent(in) :: z0\n integer :: n\n complex(kind=DP) :: z\n z = z0\n n = 0\n do while (abs(z) < MAX_NORM .and. n < MAX_ITERS)\n z = z**2 + C\n n = n + 1\n end do\n end function julia_iterate\n\nend module julia_set_mod\n", "meta": {"hexsha": "a8e3615da0592ab0b79091d6487f6e39923b7f3e", "size": 681, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source_code/julia_set/julia_set_mod.f90", "max_stars_repo_name": "caguerra/Fortran-MOOC", "max_stars_repo_head_hexsha": "fb8a9c24e62ce5f388deb06b21e3009aea6b78d4", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2021-05-20T12:03:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-16T19:46:26.000Z", "max_issues_repo_path": "source_code/julia_set/julia_set_mod.f90", "max_issues_repo_name": "caguerra/Fortran-MOOC", "max_issues_repo_head_hexsha": "fb8a9c24e62ce5f388deb06b21e3009aea6b78d4", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-09-30T04:25:50.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-06T08:21:30.000Z", "max_forks_repo_path": "source_code/julia_set/julia_set_mod.f90", "max_forks_repo_name": "caguerra/Fortran-MOOC", "max_forks_repo_head_hexsha": "fb8a9c24e62ce5f388deb06b21e3009aea6b78d4", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2021-09-27T07:30:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-07T16:23:19.000Z", "avg_line_length": 24.3214285714, "max_line_length": 65, "alphanum_fraction": 0.5829662261, "num_tokens": 207, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.935346511643776, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6951195991003585}} {"text": "*----------------------------------------------------------------------|\n subroutine DMEXPV( n, m, t, v, w, tol, anorm,\n . wsp,lwsp, iwsp,liwsp, matvec, itrace,iflag )\n\n implicit none\n integer n, m, lwsp, liwsp, itrace, iflag, iwsp(liwsp)\n double precision t, tol, anorm, v(n), w(n), wsp(lwsp)\n external matvec\n\n*-----Purpose----------------------------------------------------------|\n*\n*--- DMEXPV computes w = exp(t*A)*v - Customised for MARKOV CHAINS.\n*\n* It does not compute the matrix exponential in isolation but\n* instead, it computes directly the action of the exponential\n* operator on the operand vector. This way of doing so allows \n* for addressing large sparse problems. \n*\n* The method used is based on Krylov subspace projection\n* techniques and the matrix under consideration interacts only\n* via the external routine `matvec' performing the matrix-vector \n* product (matrix-free method).\n*\n* This is a customised version for Markov Chains. This means that a\n* check is done within this code to ensure that the resulting vector \n* w is a probability vector, i.e., w must have all its components \n* in [0,1], with sum equal to 1. This check is done at some expense\n* and the user may try DGEXPV which is cheaper since it ignores \n* probability constraints.\n*\n* IMPORTANT: The check assumes that the transition rate matrix Q\n* satisfies Qe = 0, where e=(1,...,1)'. Don't use DMEXPV\n* if this condition does not hold. Use DGEXPV instead.\n* DMEXPV/DGEXPV require the matrix-vector product \n* y = A*x = Q'*x, i.e, the TRANSPOSE of Q times a vector.\n* Failure to remember this leads to wrong results.\n*\n*-----Arguments--------------------------------------------------------|\n*\n* n : (input) order of the principal matrix A.\n* \n* m : (input) maximum size for the Krylov basis.\n* \n* t : (input) time at wich the solution is needed (can be < 0).\n* \n* v(n) : (input) given operand vector.\n*\n* w(n) : (output) computed approximation of exp(t*A)*v.\n*\n* tol : (input/output) the requested acurracy tolerance on w. \n* If on input tol=0.0d0 or tol is too small (tol.le.eps)\n* the internal value sqrt(eps) is used, and tol is set to\n* sqrt(eps) on output (`eps' denotes the machine epsilon).\n* (`Happy breakdown' is assumed if h(j+1,j) .le. anorm*tol)\n*\n* anorm : (input) an approximation of some norm of A.\n*\n* wsp(lwsp): (workspace) lwsp .ge. n*(m+1)+n+(m+2)^2+4*(m+2)^2+ideg+1\n* +---------+-------+---------------+\n* (actually, ideg=6) V H wsp for PADE\n* \n* iwsp(liwsp): (workspace) liwsp .ge. m+2\n*\n* matvec : external subroutine for matrix-vector multiplication.\n* synopsis: matvec( x, y )\n* double precision x(*), y(*)\n* computes: y(1:n) <- A*x(1:n)\n* where A is the principal matrix.\n*\n* IMPORTANT: DMEXPV requires the product y = Ax = Q'x, i.e.\n* the TRANSPOSE of the transition rate matrix.\n*\n* itrace : (input) running mode. 0=silent, 1=print step-by-step info\n*\n* iflag : (output) exit flag.\n* <0 - bad input arguments \n* 0 - no problem\n* 1 - maximum number of steps reached without convergence\n* 2 - requested tolerance was too high\n*\n*-----Accounts on the computation--------------------------------------|\n* Upon exit, an interested user may retrieve accounts on the \n* computations. They are located in the workspace arrays wsp and \n* iwsp as indicated below: \n*\n* location mnemonic description\n* -----------------------------------------------------------------|\n* iwsp(1) = nmult, number of matrix-vector multiplications used\n* iwsp(2) = nexph, number of Hessenberg matrix exponential evaluated\n* iwsp(3) = nscale, number of repeated squaring involved in Pade\n* iwsp(4) = nstep, number of integration steps used up to completion \n* iwsp(5) = nreject, number of rejected step-sizes\n* iwsp(6) = ibrkflag, set to 1 if `happy breakdown' and 0 otherwise\n* iwsp(7) = mbrkdwn, if `happy brkdown', basis-size when it occured\n* -----------------------------------------------------------------|\n* wsp(1) = step_min, minimum step-size used during integration\n* wsp(2) = step_max, maximum step-size used during integration\n* wsp(3) = x_round, maximum among all roundoff errors (lower bound) \n* wsp(4) = s_round, sum of roundoff errors (lower bound)\n* wsp(5) = x_error, maximum among all local truncation errors\n* wsp(6) = s_error, global sum of local truncation errors\n* wsp(7) = tbrkdwn, if `happy breakdown', time when it occured\n* wsp(8) = t_now, integration domain successfully covered\n* wsp(9) = hump, i.e., max||exp(sA)||, s in [0,t] (or [t,0] if t<0)\n* wsp(10) = ||w||/||v||, scaled norm of the solution w.\n* -----------------------------------------------------------------|\n* The `hump' is a measure of the conditioning of the problem. The\n* matrix exponential is well-conditioned if hump = 1, whereas it is\n* poorly-conditioned if hump >> 1. However the solution can still be\n* relatively fairly accurate even when the hump is large (the hump \n* is an upper bound), especially when the hump and the scaled norm\n* of w [this is also computed and returned in wsp(10)] are of the \n* same order of magnitude (further details in reference below).\n* Markov chains are usually well-conditioned problems.\n*\n*----------------------------------------------------------------------|\n*-----The following parameters may also be adjusted herein-------------|\n*\n integer mxstep, mxreject, ideg\n double precision delta, gamma\n parameter( mxstep = 500,\n . mxreject = 0,\n . ideg = 6,\n . delta = 1.2d0,\n . gamma = 0.9d0 )\n\n* mxstep : maximum allowable number of integration steps.\n* The value 0 means an infinite number of steps.\n* \n* mxreject: maximum allowable number of rejections at each step. \n* The value 0 means an infinite number of rejections.\n*\n* ideg : the Pade approximation of type (ideg,ideg) is used as \n* an approximation to exp(H). The value 0 switches to the\n* uniform rational Chebyshev approximation of type (14,14)\n*\n* delta : local truncation error `safety factor'\n*\n* gamma : stepsize `shrinking factor'\n*\n*----------------------------------------------------------------------|\n* Roger B. Sidje (rbs@maths.uq.edu.au)\n* EXPOKIT: Software Package for Computing Matrix Exponentials.\n* ACM - Transactions On Mathematical Software, 24(1):130-156, 1998\n*----------------------------------------------------------------------|\n*\n integer i, j, k1, mh, mx, iv, ih, j1v, ns, ifree, lfree, iexph,\n . ireject,ibrkflag,mbrkdwn, nmult, nreject, nexph, nscale,\n . nstep\n double precision sgn, t_out, tbrkdwn, step_min,step_max, err_loc,\n . s_error, x_error, t_now, t_new, t_step, t_old,\n . xm, beta, break_tol, p1, p2, p3, eps, rndoff,\n . vnorm, avnorm, hj1j, hij, hump, SQR1,\n . roundoff, s_round, x_round\n\n intrinsic AINT,ABS,DBLE,LOG10,MAX,MIN,NINT,SIGN,SQRT\n double precision DDOT, DNRM2, DASUM\n\n*--- check restrictions on input parameters ...\n iflag = 0\n if ( lwsp.lt.n*(m+2)+5*(m+2)**2+ideg+1 ) iflag = -1\n if ( liwsp.lt.m+2 ) iflag = -2\n if ( m.ge.n .or. m.le.0 ) iflag = -3\n if ( iflag.ne.0 ) stop 'bad sizes (in input of DMEXPV)'\n*\n*--- initialisations ...\n*\n k1 = 2\n mh = m + 2\n iv = 1\n ih = iv + n*(m+1) + n\n ifree = ih + mh*mh\n lfree = lwsp - ifree + 1\n\n ibrkflag = 0\n mbrkdwn = m\n nmult = 0\n nreject = 0\n nexph = 0\n nscale = 0\n\n sgn = SIGN( 1.0d0,t )\n t_out = ABS( t )\n tbrkdwn = 0.0d0\n step_min = t_out\n step_max = 0.0d0\n nstep = 0\n s_error = 0.0d0\n s_round = 0.0d0\n x_error = 0.0d0\n x_round = 0.0d0\n t_now = 0.0d0\n t_new = 0.0d0\n\n p1 = 4.0d0/3.0d0\n 1 p2 = p1 - 1.0d0\n p3 = p2 + p2 + p2\n eps = ABS( p3-1.0d0 )\n if ( eps.eq.0.0d0 ) go to 1\n if ( tol.le.eps ) tol = SQRT( eps )\n rndoff = eps*anorm\n\n break_tol = 1.0d-7\n*>>> break_tol = tol\n*>>> break_tol = anorm*tol\n\n call DCOPY( n, v,1, w,1 )\n beta = DNRM2( n, w,1 )\n vnorm = beta\n hump = beta\n*\n*--- obtain the very first stepsize ...\n*\n SQR1 = SQRT( 0.1d0 )\n xm = 1.0d0/DBLE( m )\n p1 = tol*(((m+1)/2.72D0)**(m+1))*SQRT(2.0D0*3.14D0*(m+1))\n t_new = (1.0d0/anorm)*(p1/(4.0d0*beta*anorm))**xm\n p1 = 10.0d0**(NINT( LOG10( t_new )-SQR1 )-1)\n t_new = AINT( t_new/p1 + 0.55d0 ) * p1\n*\n*--- step-by-step integration ...\n*\n 100 if ( t_now.ge.t_out ) goto 500\n\n nstep = nstep + 1\n t_step = MIN( t_out-t_now, t_new )\n\n p1 = 1.0d0/beta\n do i = 1,n\n wsp(iv + i-1) = p1*w(i)\n enddo\n do i = 1,mh*mh\n wsp(ih+i-1) = 0.0d0\n enddo\n*\n*--- Arnoldi loop ...\n*\n j1v = iv + n\n do 200 j = 1,m\n nmult = nmult + 1\n call matvec(n, wsp(j1v-n), wsp(j1v) )\n do i = 1,j\n hij = DDOT( n, wsp(iv+(i-1)*n),1, wsp(j1v),1 )\n call DAXPY( n, -hij, wsp(iv+(i-1)*n),1, wsp(j1v),1 )\n wsp(ih+(j-1)*mh+i-1) = hij\n enddo\n hj1j = DNRM2( n, wsp(j1v),1 )\n*--- if `happy breakdown' go straightforward at the end ... \n if ( hj1j.le.break_tol ) then\n print*,'happy breakdown: mbrkdwn =',j,' h =',hj1j\n k1 = 0\n ibrkflag = 1\n mbrkdwn = j\n tbrkdwn = t_now\n t_step = t_out-t_now\n goto 300\n endif\n wsp(ih+(j-1)*mh+j) = hj1j\n call DSCAL( n, 1.0d0/hj1j, wsp(j1v),1 )\n j1v = j1v + n\n 200 continue\n nmult = nmult + 1\n call matvec(n, wsp(j1v-n), wsp(j1v) )\n avnorm = DNRM2( n, wsp(j1v),1 )\n*\n*--- set 1 for the 2-corrected scheme ...\n*\n 300 continue\n wsp(ih+m*mh+m+1) = 1.0d0\n*\n*--- loop while ireject>>> iexph : (output) number such that wsp(iexph) points to exp(tH)\n* i.e., exp(tH) is located at wsp(iexph ... iexph+m*m-1)\n* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n* NOTE: if the routine was called with wsp(iptr), \n* then exp(tH) will start at wsp(iptr+iexph-1).\n*\n* ns : (output) number of scaling-squaring used.\n*\n* iflag : (output) exit flag.\n* 0 - no problem\n* <0 - problem\n*\n*----------------------------------------------------------------------|\n* Roger B. Sidje (rbs@maths.uq.edu.au)\n* EXPOKIT: Software Package for Computing Matrix Exponentials.\n* ACM - Transactions On Mathematical Software, 24(1):130-156, 1998\n*----------------------------------------------------------------------|\n*\n integer mm,i,j,k,ih2,ip,iq,iused,ifree,iodd,icoef,iput,iget\n double precision hnorm,scale,scale2,cp,cq\n\n intrinsic INT,ABS,DBLE,LOG,MAX\n\n*--- check restrictions on input parameters ...\n mm = m*m\n iflag = 0\n if ( ldh.lt.m ) iflag = -1\n if ( lwsp.lt.4*mm+ideg+1 ) iflag = -2\n if ( iflag.ne.0 ) stop 'bad sizes (in input of DSPADM)'\n*\n*--- initialise pointers ...\n*\n icoef = 1\n ih2 = icoef + (ideg+1)\n ip = ih2 + mm\n iq = ip + mm\n ifree = iq + mm\n*\n*--- scaling: seek ns such that ||t*H/2^ns|| < 1/2; \n* and set scale = t/2^ns ...\n*\n do i = 1,m\n wsp(i) = 0.0d0\n enddo\n do j = 1,m\n do i = 1,m\n wsp(i) = wsp(i) + ABS( H(i,j) )\n enddo\n enddo\n hnorm = 0.0d0\n do i = 1,m\n hnorm = MAX( hnorm,wsp(i) )\n enddo\n hnorm = ABS( t*hnorm )\n if ( hnorm.eq.0.0d0 ) stop 'Error - null H in input of DSPADM.'\n ns = MAX( 0,INT(LOG(hnorm)/LOG(2.0d0))+2 )\n scale = t / DBLE(2**ns)\n scale2 = scale*scale\n*\n*--- compute Pade coefficients ...\n*\n i = ideg+1\n j = 2*ideg+1\n wsp(icoef) = 1.0d0\n do k = 1,ideg\n wsp(icoef+k) = (wsp(icoef+k-1)*DBLE( i-k ))/DBLE( k*(j-k) )\n enddo\n*\n*--- H2 = scale2*H*H ...\n*\n call DGEMM( 'n','n',m,m,m,scale2,H,ldh,H,ldh,0.0d0,wsp(ih2),m )\n*\n*--- initialize p (numerator) and q (denominator) ...\n*\n cp = wsp(icoef+ideg-1)\n cq = wsp(icoef+ideg)\n do j = 1,m\n do i = 1,m\n wsp(ip + (j-1)*m + i-1) = 0.0d0\n wsp(iq + (j-1)*m + i-1) = 0.0d0\n enddo\n wsp(ip + (j-1)*(m+1)) = cp\n wsp(iq + (j-1)*(m+1)) = cq\n enddo\n*\n*--- Apply Horner rule ...\n*\n iodd = 1\n k = ideg - 1\n 100 continue\n iused = iodd*iq + (1-iodd)*ip\n call DGEMM( 'n','n',m,m,m, 1.0d0,wsp(iused),m,\n . wsp(ih2),m, 0.0d0,wsp(ifree),m )\n do j = 1,m\n wsp(ifree+(j-1)*(m+1)) = wsp(ifree+(j-1)*(m+1))+wsp(icoef+k-1)\n enddo\n ip = (1-iodd)*ifree + iodd*ip\n iq = iodd*ifree + (1-iodd)*iq\n ifree = iused\n iodd = 1-iodd\n k = k-1\n if ( k.gt.0 ) goto 100\n*\n*--- Obtain (+/-)(I + 2*(p\\q)) ...\n*\n if ( iodd .eq. 1 ) then\n call DGEMM( 'n','n',m,m,m, scale,wsp(iq),m,\n . H,ldh, 0.0d0,wsp(ifree),m )\n iq = ifree\n else\n call DGEMM( 'n','n',m,m,m, scale,wsp(ip),m,\n . H,ldh, 0.0d0,wsp(ifree),m )\n ip = ifree\n endif\n call DAXPY( mm, -1.0d0,wsp(ip),1, wsp(iq),1 )\n call DSYSV( 'U',m,m,wsp(iq),m,ipiv,wsp(ip),m,wsp(ih2),mm,iflag )\n if ( iflag.ne.0 ) stop 'Problem in DSYSV (within DSPADM)'\n call DSCAL( mm, 2.0d0, wsp(ip), 1 )\n do j = 1,m\n wsp(ip+(j-1)*(m+1)) = wsp(ip+(j-1)*(m+1)) + 1.0d0\n enddo\n iput = ip\n if ( ns.eq.0 .and. iodd.eq.1 ) then\n call DSCAL( mm, -1.0d0, wsp(ip), 1 )\n goto 200\n endif\n*\n*-- squaring : exp(t*H) = (exp(t*H))^(2^ns) ...\n*\n iodd = 1\n do k = 1,ns\n iget = iodd*ip + (1-iodd)*iq\n iput = (1-iodd)*ip + iodd*iq\n call DGEMM( 'n','n',m,m,m, 1.0d0,wsp(iget),m, wsp(iget),m,\n . 0.0d0,wsp(iput),m )\n iodd = 1-iodd\n enddo\n 200 continue\n iexph = iput\n END\n*----------------------------------------------------------------------|\n*----------------------------------------------------------------------|\n subroutine ZGPADM(ideg,m,t,H,ldh,wsp,lwsp,ipiv,iexph,ns,iflag)\n\n implicit none\n double precision t\n integer ideg, m, ldh, lwsp, iexph, ns, iflag, ipiv(m)\n complex*16 H(ldh,m), wsp(lwsp)\n\n*-----Purpose----------------------------------------------------------|\n*\n* Computes exp(t*H), the matrix exponential of a general complex \n* matrix in full, using the irreducible rational Pade approximation\n* to the exponential exp(z) = r(z) = (+/-)( I + 2*(q(z)/p(z)) ),\n* combined with scaling-and-squaring.\n*\n*-----Arguments--------------------------------------------------------|\n*\n* ideg : (input) the degre of the diagonal Pade to be used.\n* a value of 6 is generally satisfactory.\n*\n* m : (input) order of H.\n*\n* H(ldh,m) : (input) argument matrix.\n*\n* t : (input) time-scale (can be < 0).\n* \n* wsp(lwsp) : (workspace/output) lwsp .ge. 4*m*m+ideg+1.\n*\n* ipiv(m) : (workspace)\n*\n*>>>> iexph : (output) number such that wsp(iexph) points to exp(tH)\n* i.e., exp(tH) is located at wsp(iexph ... iexph+m*m-1)\n* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n* NOTE: if the routine was called with wsp(iptr), \n* then exp(tH) will start at wsp(iptr+iexph-1).\n*\n* ns : (output) number of scaling-squaring used.\n*\n* iflag : (output) exit flag.\n* 0 - no problem\n* <0 - problem\n*\n*----------------------------------------------------------------------|\n* Roger B. Sidje (rbs@maths.uq.edu.au)\n* EXPOKIT: Software Package for Computing Matrix Exponentials.\n* ACM - Transactions On Mathematical Software, 24(1):130-156, 1998\n*----------------------------------------------------------------------|\n*\n integer i,j,k,icoef,mm,ih2,iodd,iused,ifree,iq,ip,iput,iget\n double precision hnorm\n complex*16 cp, cq, scale, scale2, ZERO, ONE\n\n parameter( ZERO=(0.0d0,0.0d0), ONE=(1.0d0,0.0d0) )\n intrinsic ABS, CMPLX, DBLE, INT, LOG, MAX\n\n*--- check restrictions on input parameters ...\n mm = m*m\n iflag = 0\n if ( ldh.lt.m ) iflag = -1\n if ( lwsp.lt.4*mm+ideg+1 ) iflag = -2\n if ( iflag.ne.0 ) stop 'bad sizes (in input of ZGPADM)'\n*\n*--- initialise pointers ...\n*\n icoef = 1\n ih2 = icoef + (ideg+1)\n ip = ih2 + mm\n iq = ip + mm\n ifree = iq + mm\n*\n*--- scaling: seek ns such that ||t*H/2^ns|| < 1/2; \n* and set scale = t/2^ns ...\n*\n do i = 1,m\n wsp(i) = ZERO\n enddo\n do j = 1,m\n do i = 1,m\n wsp(i) = wsp(i) + ABS( H(i,j) )\n enddo\n enddo\n hnorm = 0.0d0\n do i = 1,m\n hnorm = MAX( hnorm,DBLE(wsp(i)) )\n enddo\n hnorm = ABS( t*hnorm )\n if ( hnorm.eq.0.0d0 ) stop 'Error - null H in input of ZGPADM.'\n ns = MAX( 0,INT(LOG(hnorm)/LOG(2.0d0))+2 )\n scale = CMPLX( t/DBLE(2**ns),0.0d0 )\n scale2 = scale*scale\n*\n*--- compute Pade coefficients ...\n*\n i = ideg+1\n j = 2*ideg+1\n wsp(icoef) = ONE\n do k = 1,ideg\n wsp(icoef+k) = (wsp(icoef+k-1)*DBLE( i-k ))/DBLE( k*(j-k) )\n enddo\n*\n*--- H2 = scale2*H*H ...\n*\n call ZGEMM( 'n','n',m,m,m,scale2,H,ldh,H,ldh,ZERO,wsp(ih2),m )\n*\n*--- initialise p (numerator) and q (denominator) ...\n*\n cp = wsp(icoef+ideg-1)\n cq = wsp(icoef+ideg)\n do j = 1,m\n do i = 1,m\n wsp(ip + (j-1)*m + i-1) = ZERO\n wsp(iq + (j-1)*m + i-1) = ZERO\n enddo\n wsp(ip + (j-1)*(m+1)) = cp\n wsp(iq + (j-1)*(m+1)) = cq\n enddo\n*\n*--- Apply Horner rule ...\n*\n iodd = 1\n k = ideg - 1\n 100 continue\n iused = iodd*iq + (1-iodd)*ip\n call ZGEMM( 'n','n',m,m,m, ONE,wsp(iused),m,\n . wsp(ih2),m, ZERO,wsp(ifree),m )\n do j = 1,m\n wsp(ifree+(j-1)*(m+1)) = wsp(ifree+(j-1)*(m+1))+wsp(icoef+k-1)\n enddo\n ip = (1-iodd)*ifree + iodd*ip\n iq = iodd*ifree + (1-iodd)*iq\n ifree = iused\n iodd = 1-iodd\n k = k-1\n if ( k.gt.0 ) goto 100\n*\n*--- Obtain (+/-)(I + 2*(p\\q)) ...\n*\n if ( iodd.ne.0 ) then\n call ZGEMM( 'n','n',m,m,m, scale,wsp(iq),m,\n . H,ldh, ZERO,wsp(ifree),m )\n iq = ifree\n else\n call ZGEMM( 'n','n',m,m,m, scale,wsp(ip),m,\n . H,ldh, ZERO,wsp(ifree),m )\n ip = ifree\n endif\n call ZAXPY( mm, -ONE,wsp(ip),1, wsp(iq),1 )\n call ZGESV( m,m, wsp(iq),m, ipiv, wsp(ip),m, iflag )\n if ( iflag.ne.0 ) stop 'Problem in ZGESV (within ZGPADM)'\n call ZDSCAL( mm, 2.0d0, wsp(ip), 1 )\n do j = 1,m\n wsp(ip+(j-1)*(m+1)) = wsp(ip+(j-1)*(m+1)) + ONE\n enddo\n iput = ip\n if ( ns.eq.0 .and. iodd.ne.0 ) then\n call ZDSCAL( mm, -1.0d0, wsp(ip), 1 )\n goto 200\n endif\n*\n*-- squaring : exp(t*H) = (exp(t*H))^(2^ns) ...\n*\n iodd = 1\n do k = 1,ns\n iget = iodd*ip + (1-iodd)*iq\n iput = (1-iodd)*ip + iodd*iq\n call ZGEMM( 'n','n',m,m,m, ONE,wsp(iget),m, wsp(iget),m,\n . ZERO,wsp(iput),m )\n iodd = 1-iodd\n enddo\n 200 continue\n iexph = iput\n END\n*----------------------------------------------------------------------|\n subroutine ZHPADM(ideg,m,t,H,ldh,wsp,lwsp,ipiv,iexph,ns,iflag)\n\n implicit none\n double precision t\n integer ideg, m, ldh, lwsp, iexph, ns, iflag, ipiv(m)\n complex*16 H(ldh,m), wsp(lwsp)\n\n*-----Purpose----------------------------------------------------------|\n*\n* Computes exp(t*H), the matrix exponential of an Hermitian matrix\n* in full, using the irreducible rational Pade approximation to the\n* exponential function exp(z) = r(z) = (+/-)( I + 2*(q(z)/p(z)) ),\n* combined with scaling-and-squaring.\n*\n*-----Arguments--------------------------------------------------------|\n*\n* ideg : (input) the degre of the diagonal Pade to be used.\n* a value of 6 is generally satisfactory.\n*\n* m : (input) order of H.\n*\n* H(ldh,m) : (input) argument matrix (both lower and upper parts).\n*\n* t : (input) time-scale (can be < 0).\n* \n* wsp(lwsp) : (workspace/output) lwsp .ge. 4*m*m+ideg+1.\n*\n* ipiv(m) : (workspace)\n*\n*>>>> iexph : (output) number such that wsp(iexph) points to exp(tH)\n* i.e., exp(tH) is located at wsp(iexph ... iexph+m*m-1)\n* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n* NOTE: if the routine was called with wsp(iptr), \n* then exp(tH) will start at wsp(iptr+iexph-1).\n*\n* ns : (output) number of scaling-squaring used.\n*\n* iflag : (output) exit flag.\n* 0 - no problem\n* <0 - problem\n*\n*----------------------------------------------------------------------|\n* Roger B. Sidje (rbs@maths.uq.edu.au)\n* EXPOKIT: Software Package for Computing Matrix Exponentials.\n* ACM - Transactions On Mathematical Software, 24(1):130-156, 1998\n*----------------------------------------------------------------------|\n*\n integer i,j,k,icoef,mm,ih2,iodd,iused,ifree,iq,ip,iput,iget\n double precision hnorm\n complex*16 cp, cq, scale, scale2, ZERO, ONE\n\n parameter( ZERO=(0.0d0,0.0d0), ONE=(1.0d0,0.0d0) )\n intrinsic ABS, CMPLX, DBLE, INT, LOG, MAX\n\n*--- check restrictions on input parameters ...\n mm = m*m\n iflag = 0\n if ( ldh.lt.m ) iflag = -1\n if ( lwsp.lt.4*mm+ideg+1 ) iflag = -2\n if ( iflag.ne.0 ) stop 'bad sizes (in input of ZHPADM)'\n*\n*--- initialise pointers ...\n*\n icoef = 1\n ih2 = icoef + (ideg+1)\n ip = ih2 + mm\n iq = ip + mm\n ifree = iq + mm\n*\n*--- scaling: seek ns such that ||t*H/2^ns|| < 1/2; \n* and set scale = t/2^ns ...\n*\n do i = 1,m\n wsp(i) = ZERO\n enddo\n do j = 1,m\n do i = 1,m\n wsp(i) = wsp(i) + ABS( H(i,j) )\n enddo\n enddo\n hnorm = 0.0d0\n do i = 1,m\n hnorm = MAX( hnorm,DBLE(wsp(i)) )\n enddo\n hnorm = ABS( t*hnorm )\n if ( hnorm.eq.0.0d0 ) stop 'Error - null H in input of ZHPADM.'\n ns = MAX( 0,INT(LOG(hnorm)/LOG(2.0d0))+2 )\n scale = CMPLX( t/DBLE(2**ns),0.0d0 )\n scale2 = scale*scale\n*\n*--- compute Pade coefficients ...\n*\n i = ideg+1\n j = 2*ideg+1\n wsp(icoef) = ONE\n do k = 1,ideg\n wsp(icoef+k) = (wsp(icoef+k-1)*DBLE( i-k ))/DBLE( k*(j-k) )\n enddo\n*\n*--- H2 = scale2*H*H ...\n*\n call ZGEMM( 'n','n',m,m,m,scale2,H,ldh,H,ldh,ZERO,wsp(ih2),m )\n*\n*--- initialise p (numerator) and q (denominator) ...\n*\n cp = wsp(icoef+ideg-1)\n cq = wsp(icoef+ideg)\n do j = 1,m\n do i = 1,m\n wsp(ip + (j-1)*m + i-1) = ZERO\n wsp(iq + (j-1)*m + i-1) = ZERO\n enddo\n wsp(ip + (j-1)*(m+1)) = cp\n wsp(iq + (j-1)*(m+1)) = cq\n enddo\n*\n*--- Apply Horner rule ...\n*\n iodd = 1\n k = ideg - 1\n 100 continue\n iused = iodd*iq + (1-iodd)*ip\n call ZGEMM( 'n','n',m,m,m, ONE,wsp(iused),m,\n . wsp(ih2),m, ZERO,wsp(ifree),m )\n do j = 1,m\n wsp(ifree+(j-1)*(m+1)) = wsp(ifree+(j-1)*(m+1))+wsp(icoef+k-1)\n enddo\n ip = (1-iodd)*ifree + iodd*ip\n iq = iodd*ifree + (1-iodd)*iq\n ifree = iused\n iodd = 1-iodd\n k = k-1\n if ( k.gt.0 ) goto 100\n*\n*--- Obtain (+/-)(I + 2*(p\\q)) ...\n*\n if ( iodd.ne.0 ) then\n call ZGEMM( 'n','n',m,m,m, scale,wsp(iq),m,\n . H,ldh, ZERO,wsp(ifree),m )\n iq = ifree\n else\n call ZGEMM( 'n','n',m,m,m, scale,wsp(ip),m,\n . H,ldh, ZERO,wsp(ifree),m )\n ip = ifree\n endif\n call ZAXPY( mm, -ONE,wsp(ip),1, wsp(iq),1 )\n call ZHESV( 'U',m,m,wsp(iq),m,ipiv,wsp(ip),m,wsp(ih2),mm,iflag )\n if ( iflag.ne.0 ) stop 'Problem in ZHESV (within ZHPADM)'\n call ZDSCAL( mm, 2.0d0, wsp(ip), 1 )\n do j = 1,m\n wsp(ip+(j-1)*(m+1)) = wsp(ip+(j-1)*(m+1)) + ONE\n enddo\n iput = ip\n if ( ns.eq.0 .and. iodd.ne.0 ) then\n call ZDSCAL( mm, -1.0d0, wsp(ip), 1 )\n goto 200\n endif\n*\n*-- squaring : exp(t*H) = (exp(t*H))^(2^ns) ...\n*\n iodd = 1\n do k = 1,ns\n iget = iodd*ip + (1-iodd)*iq\n iput = (1-iodd)*ip + iodd*iq\n call ZGEMM( 'n','n',m,m,m, ONE,wsp(iget),m, wsp(iget),m,\n . ZERO,wsp(iput),m )\n iodd = 1-iodd\n enddo\n 200 continue\n iexph = iput\n END\n*----------------------------------------------------------------------|\n subroutine DGCHBV( m, t, H,ldh, y, wsp, iwsp, iflag )\n\n implicit none\n integer m, ldh, iflag, iwsp(m)\n double precision t, H(ldh,m), y(m)\n complex*16 wsp(m*(m+2))\n\n*-----Purpose----------------------------------------------------------|\n*\n*--- DGCHBV computes y = exp(t*H)*y using the partial fraction\n* expansion of the uniform rational Chebyshev approximation\n* to exp(-x) of type (14,14). H is a General matrix.\n* About 14-digit accuracy is expected if the matrix H is negative\n* definite. The algorithm may behave poorly otherwise. \n*\n*-----Arguments--------------------------------------------------------|\n*\n* m : (input) order of the matrix H\n*\n* t : (input) time-scaling factor (can be < 0).\n*\n* H(ldh,m): (input) argument matrix.\n*\n* y(m) : (input/output) on input the operand vector,\n* on output the resulting vector exp(t*H)*y.\n*\n* iwsp(m) : (workspace)\n*\n* wsp : (workspace). Observe that a double precision vector of\n* length 2*m*(m+2) can be used as well when calling this\n* routine (thus avoiding an idle complex array elsewhere)\n*\n*----------------------------------------------------------------------|\n* Roger B. Sidje (rbs@maths.uq.edu.au)\n* EXPOKIT: Software Package for Computing Matrix Exponentials.\n* ACM - Transactions On Mathematical Software, 24(1):130-156, 1998\n*----------------------------------------------------------------------|\n*\n integer ndeg, i, j, ip, ih, iy, iz\n parameter ( ndeg=7 )\n double precision alpha0\n complex*16 alpha(ndeg), theta(ndeg)\n\n intrinsic DBLE\n \n*--- Pointers ...\n\n ih = 1\n iy = ih + m*m\n iz = iy + m\n\n*--- Coefficients and poles of the partial fraction expansion ...\n\n alpha0 = 0.183216998528140087D-11\n alpha(1)=( 0.557503973136501826D+02,-0.204295038779771857D+03)\n alpha(2)=(-0.938666838877006739D+02, 0.912874896775456363D+02)\n alpha(3)=( 0.469965415550370835D+02,-0.116167609985818103D+02)\n alpha(4)=(-0.961424200626061065D+01,-0.264195613880262669D+01)\n alpha(5)=( 0.752722063978321642D+00, 0.670367365566377770D+00)\n alpha(6)=(-0.188781253158648576D-01,-0.343696176445802414D-01)\n alpha(7)=( 0.143086431411801849D-03, 0.287221133228814096D-03)\n\n theta(1)=(-0.562314417475317895D+01, 0.119406921611247440D+01)\n theta(2)=(-0.508934679728216110D+01, 0.358882439228376881D+01)\n theta(3)=(-0.399337136365302569D+01, 0.600483209099604664D+01)\n theta(4)=(-0.226978543095856366D+01, 0.846173881758693369D+01)\n theta(5)=( 0.208756929753827868D+00, 0.109912615662209418D+02)\n theta(6)=( 0.370327340957595652D+01, 0.136563731924991884D+02)\n theta(7)=( 0.889777151877331107D+01, 0.166309842834712071D+02)\n* \n*--- Accumulation of the contribution of each pole ...\n*\n do j = 1,m\n wsp(iz+j-1) = y(j)\n y(j) = y(j)*alpha0\n enddo\n do ip = 1,ndeg\n*--- Solve each fraction using Gaussian elimination with pivoting...\n do j = 1,m\n do i = 1,m\n wsp(ih+(j-1)*m+i-1) = -t*H(i,j)\n enddo\n wsp(ih+(j-1)*m+j-1) = wsp(ih+(j-1)*m+j-1)-theta(ip)\n wsp(iy+j-1) = wsp(iz+j-1)\n enddo\n call ZGESV( M, 1, WSP(iH),M, IWSP, WSP(iY),M, IFLAG )\n if ( IFLAG.ne.0 ) stop 'Error in DGCHBV'\n*--- Accumulate the partial result in y ... \n do j = 1,m\n y(j) = y(j) + DBLE( alpha(ip)*wsp(iy+j-1) )\n enddo\n enddo\n END\n*----------------------------------------------------------------------|\n*----------------------------------------------------------------------|\n subroutine DSCHBV( m, t, H,ldh, y, wsp, iwsp, iflag )\n\n implicit none\n integer m, ldh, iflag, iwsp(m)\n double precision t, H(ldh,m), y(m)\n complex*16 wsp(m*(m+2))\n\n*-----Purpose----------------------------------------------------------|\n*\n*--- DSCHBV computes y = exp(t*H)*y using the partial fraction\n* expansion of the uniform rational Chebyshev approximation\n* to exp(-x) of type (14,14). H is assumed to be symmetric.\n* About 14-digit accuracy is expected if the matrix H is negative\n* definite. The algorithm may behave poorly otherwise. \n*\n*-----Arguments--------------------------------------------------------|\n*\n* m : (input) order of matrix H\n*\n* t : (input) time-scaling factor (can be < 0).\n*\n* H(ldh,m): (input) symmetric matrix.\n*\n* y(m) : (input/output) on input the operand vector,\n* on output the resulting vector exp(t*H)*y.\n*\n* iwsp(m) : (workspace)\n*\n* wsp : (workspace). Observe that a double precision vector of\n* length 2*m*(m+2) can be used as well when calling this\n* routine (thus avoiding an idle complex array elsewhere)\n*\n*----------------------------------------------------------------------|\n* Roger B. Sidje (rbs@maths.uq.edu.au)\n* EXPOKIT: Software Package for Computing Matrix Exponentials.\n* ACM - Transactions On Mathematical Software, 24(1):130-156, 1998\n*----------------------------------------------------------------------|\n*\n integer ndeg, i, j, ip, ih, iy, iz\n parameter ( ndeg=7 )\n double precision alpha0\n complex*16 alpha(ndeg), theta(ndeg), w\n\n intrinsic ABS,CMPLX,DBLE,MIN\n \n*--- Pointers ...\n\n ih = 1\n iy = ih + m*m\n iz = iy + m\n\n*--- Coefficients and poles of the partial fraction expansion ...\n\n alpha0 = 0.183216998528140087D-11\n alpha(1)=( 0.557503973136501826D+02,-0.204295038779771857D+03)\n alpha(2)=(-0.938666838877006739D+02, 0.912874896775456363D+02)\n alpha(3)=( 0.469965415550370835D+02,-0.116167609985818103D+02)\n alpha(4)=(-0.961424200626061065D+01,-0.264195613880262669D+01)\n alpha(5)=( 0.752722063978321642D+00, 0.670367365566377770D+00)\n alpha(6)=(-0.188781253158648576D-01,-0.343696176445802414D-01)\n alpha(7)=( 0.143086431411801849D-03, 0.287221133228814096D-03)\n\n theta(1)=(-0.562314417475317895D+01, 0.119406921611247440D+01)\n theta(2)=(-0.508934679728216110D+01, 0.358882439228376881D+01)\n theta(3)=(-0.399337136365302569D+01, 0.600483209099604664D+01)\n theta(4)=(-0.226978543095856366D+01, 0.846173881758693369D+01)\n theta(5)=( 0.208756929753827868D+00, 0.109912615662209418D+02)\n theta(6)=( 0.370327340957595652D+01, 0.136563731924991884D+02)\n theta(7)=( 0.889777151877331107D+01, 0.166309842834712071D+02)\n* \n*--- Accumulation of the contribution of each pole ...\n*\n do j = 1,m\n wsp(iz+j-1) = y(j)\n y(j) = y(j)*alpha0\n enddo\n do ip = 1,ndeg\n*--- Solve each fraction using Gaussian elimination with pivoting...\n do j = 1,m\n do i = 1,m\n wsp(ih+(j-1)*m+i-1) = -t*H(i,j)\n enddo\n wsp(ih+(j-1)*m+j-1) = wsp(ih+(j-1)*m+j-1)-theta(ip)\n wsp(iy+j-1) = wsp(iz+j-1)\n enddo\n call ZSYSV('U', M, 1, WSP(iH),M, IWSP, WSP(iY),M, W,1, IFLAG )\n if ( IFLAG.ne.0 ) stop 'Error in DSCHBV'\n*--- Accumulate the partial result in y ... \n do i = 1,m\n y(i) = y(i) + DBLE( alpha(ip)*wsp(iy+i-1) )\n enddo\n enddo\n END\n*----------------------------------------------------------------------|\n*----------------------------------------------------------------------|\n subroutine ZGCHBV( m, t, H,ldh, y, wsp, iwsp, iflag )\n\n implicit none\n integer m, ldh, iflag, iwsp(m)\n double precision t\n complex*16 H(ldh,m), y(m), wsp(m*(m+2))\n\n*-----Purpose----------------------------------------------------------|\n*\n*--- ZGCHBV computes y = exp(t*H)*y using the partial fraction\n* expansion of the uniform rational Chebyshev approximation\n* to exp(-x) of type (14,14). H is a General matrix.\n* About 14-digit accuracy is expected if the matrix H is negative\n* definite. The algorithm may behave poorly otherwise. \n*\n*-----Arguments--------------------------------------------------------|\n*\n* m : (input) order of the matrix H.\n*\n* t : (input) time-scaling factor (can be < 0).\n*\n* H(ldh,m): (input) argument matrix.\n*\n* y(m) : (input/output) on input the operand vector,\n* on output the resulting vector exp(t*H)*y.\n*\n* iwsp(m) : (workspace)\n*\n* wsp : (workspace). Observe that a double precision vector of\n* length 2*m*(m+2) can be used as well when calling this\n* routine.\n*\n*----------------------------------------------------------------------|\n* Roger B. Sidje (rbs@maths.uq.edu.au)\n* EXPOKIT: Software Package for Computing Matrix Exponentials.\n* ACM - Transactions On Mathematical Software, 24(1):130-156, 1998\n*----------------------------------------------------------------------|\n*\n integer ndeg, i, j, ip, ih, iy, iz\n parameter ( ndeg=7 )\n double precision alpha0\n complex*16 alpha(2*ndeg), theta(2*ndeg)\n \n*--- Pointers ...\n\n ih = 1\n iy = ih + m*m\n iz = iy + m\n\n*--- Coefficients and poles of the partial fraction expansion ...\n\n alpha0 = 0.183216998528140087D-11\n alpha(1)=( 0.557503973136501826D+02,-0.204295038779771857D+03)\n alpha(2)=(-0.938666838877006739D+02, 0.912874896775456363D+02)\n alpha(3)=( 0.469965415550370835D+02,-0.116167609985818103D+02)\n alpha(4)=(-0.961424200626061065D+01,-0.264195613880262669D+01)\n alpha(5)=( 0.752722063978321642D+00, 0.670367365566377770D+00)\n alpha(6)=(-0.188781253158648576D-01,-0.343696176445802414D-01)\n alpha(7)=( 0.143086431411801849D-03, 0.287221133228814096D-03)\n\n theta(1)=(-0.562314417475317895D+01, 0.119406921611247440D+01)\n theta(2)=(-0.508934679728216110D+01, 0.358882439228376881D+01)\n theta(3)=(-0.399337136365302569D+01, 0.600483209099604664D+01)\n theta(4)=(-0.226978543095856366D+01, 0.846173881758693369D+01)\n theta(5)=( 0.208756929753827868D+00, 0.109912615662209418D+02)\n theta(6)=( 0.370327340957595652D+01, 0.136563731924991884D+02)\n theta(7)=( 0.889777151877331107D+01, 0.166309842834712071D+02)\n*\n do ip = 1,ndeg\n theta(ndeg+ip) = CONJG( theta(ip) )\n alpha(ndeg+ip) = CONJG( alpha(ip) )\n enddo\n* \n*--- Accumulation of the contribution of each pole ...\n*\n do j = 1,m\n wsp(iz+j-1) = y(j)\n y(j) = y(j)*alpha0\n enddo\n do ip = 1,2*ndeg\n alpha(ip) = 0.5d0*alpha(ip)\n*--- Solve each fraction using Gaussian elimination with pivoting...\n do j = 1,m\n do i = 1,m\n wsp(ih+(j-1)*m+i-1) = -t*H(i,j)\n enddo\n wsp(ih+(j-1)*m+j-1) = wsp(ih+(j-1)*m+j-1)-theta(ip)\n wsp(iy+j-1) = wsp(iz+j-1)\n enddo\n call ZGESV( M, 1, WSP(iH),M, IWSP, WSP(iY),M, IFLAG )\n if ( IFLAG.ne.0 ) stop 'Error in ZGCHBV'\n*--- Accumulate the partial result in y ... \n do i = 1,m\n y(i) = y(i) + alpha(ip)*wsp(iy+i-1)\n enddo\n enddo\n END\n*----------------------------------------------------------------------|\n*----------------------------------------------------------------------|\n subroutine DNCHBV( m, t, H,ldh, y, wsp )\n\n implicit none\n integer m, ldh\n double precision t, H(ldh,m), y(m)\n complex*16 wsp(m*(m+2))\n\n*-----Purpose----------------------------------------------------------|\n*\n*--- DNCHBV computes y = exp(t*H)*y using the partial fraction\n* expansion of the uniform rational Chebyshev approximation\n* to exp(-x) of type (14,14). H is assumed to be upper-Hessenberg.\n* About 14-digit accuracy is expected if the matrix H is negative\n* definite. The algorithm may behave poorly otherwise. \n*\n*-----Arguments--------------------------------------------------------|\n*\n* m : (input) order of the Hessenberg matrix H\n*\n* t : (input) time-scaling factor (can be < 0).\n*\n* H(ldh,m): (input) upper Hessenberg matrix.\n*\n* y(m) : (input/output) on input the operand vector,\n* on output the resulting vector exp(t*H)*y.\n*\n* wsp : (workspace). Observe that a double precision vector of\n* length 2*m*(m+2) can be used as well when calling this\n* routine (thus avoiding an idle complex array elsewhere)\n*\n*----------------------------------------------------------------------|\n* Roger B. Sidje (rbs@maths.uq.edu.au)\n* EXPOKIT: Software Package for Computing Matrix Exponentials.\n* ACM - Transactions On Mathematical Software, 24(1):130-156, 1998\n*----------------------------------------------------------------------|\n*\n complex*16 ZERO\n integer ndeg, i, j, k, ip, ih, iy, iz\n parameter ( ndeg=7, ZERO=(0.0d0,0.0d0) )\n double precision alpha0\n complex*16 alpha(ndeg), theta(ndeg), tmpc\n\n intrinsic ABS,DBLE,MIN\n \n*--- Pointers ...\n\n ih = 1\n iy = ih + m*m\n iz = iy + m\n\n*--- Coefficients and poles of the partial fraction expansion...\n\n alpha0 = 0.183216998528140087D-11\n alpha(1)=( 0.557503973136501826D+02,-0.204295038779771857D+03)\n alpha(2)=(-0.938666838877006739D+02, 0.912874896775456363D+02)\n alpha(3)=( 0.469965415550370835D+02,-0.116167609985818103D+02)\n alpha(4)=(-0.961424200626061065D+01,-0.264195613880262669D+01)\n alpha(5)=( 0.752722063978321642D+00, 0.670367365566377770D+00)\n alpha(6)=(-0.188781253158648576D-01,-0.343696176445802414D-01)\n alpha(7)=( 0.143086431411801849D-03, 0.287221133228814096D-03)\n\n theta(1)=(-0.562314417475317895D+01, 0.119406921611247440D+01)\n theta(2)=(-0.508934679728216110D+01, 0.358882439228376881D+01)\n theta(3)=(-0.399337136365302569D+01, 0.600483209099604664D+01)\n theta(4)=(-0.226978543095856366D+01, 0.846173881758693369D+01)\n theta(5)=( 0.208756929753827868D+00, 0.109912615662209418D+02)\n theta(6)=( 0.370327340957595652D+01, 0.136563731924991884D+02)\n theta(7)=( 0.889777151877331107D+01, 0.166309842834712071D+02)\n* \n*--- Accumulation of the contribution of each pole ...\n*\n do j = 1,m\n wsp(iz+j-1) = y(j)\n y(j) = y(j)*alpha0\n enddo\n do ip = 1,ndeg\n*--- Solve each fraction using Gaussian elimination with pivoting...\n do j = 1,m\n wsp(iy+j-1) = wsp(iz+j-1)\n do i = 1,MIN( j+1,m )\n wsp(ih+(j-1)*m+i-1) = -t*H(i,j)\n enddo\n wsp(ih+(j-1)*m+j-1) = wsp(ih+(j-1)*m+j-1)-theta(ip)\n do k = i,m\n wsp(ih+(j-1)*m+k-1) = ZERO\n enddo\n enddo\n do i = 1,m-1\n*--- Get pivot and exchange rows ...\n if (ABS(wsp(ih+(i-1)*m+i-1)).lt.ABS(wsp(ih+(i-1)*m+i))) then\n call ZSWAP( m-i+1, wsp(ih+(i-1)*m+i-1),m, \n . wsp(ih+(i-1)*m+i),m )\n call ZSWAP( 1, wsp(iy+i-1),1, wsp(iy+i),1 )\n endif\n*--- Forward eliminiation ... \n tmpc = wsp(ih+(i-1)*m+i) / wsp(ih+(i-1)*m+i-1)\n call ZAXPY( m-i, -tmpc, wsp(ih+i*m+i-1),m, wsp(ih+i*m+i),m )\n wsp(iy+i) = wsp(iy+i) - tmpc*wsp(iy+i-1)\n enddo\n*--- Backward substitution ... \n do i = m,1,-1\n tmpc = wsp(iy+i-1)\n do j = i+1,m\n tmpc = tmpc - wsp(ih+(j-1)*m+i-1)*wsp(iy+j-1)\n enddo\n wsp(iy+i-1) = tmpc / wsp(ih+(i-1)*m+i-1)\n enddo\n*--- Accumulate the partial result in y ... \n do j = 1,m\n y(j) = y(j) + DBLE( alpha(ip)*wsp(iy+j-1) )\n enddo\n enddo\n END\n*----------------------------------------------------------------------|\n*----------------------------------------------------------------------|\n subroutine ZNCHBV( m, t, H,ldh, y, wsp )\n\n implicit none\n integer m, ldh\n double precision t\n complex*16 H(ldh,m), y(m), wsp(m*(m+2))\n\n*-----Purpose----------------------------------------------------------|\n*\n*--- ZNCHBV computes y = exp(t*H)*y using the partial fraction\n* expansion of the uniform rational Chebyshev approximation\n* to exp(-x) of type (14,14). H is assumed to be upper-Hessenberg.\n* About 14-digit accuracy is expected if the matrix H is negative\n* definite. The algorithm may behave poorly otherwise. \n*\n*-----Arguments--------------------------------------------------------|\n*\n* m : (input) order of the Hessenberg matrix H\n*\n* t : (input) time-scaling factor (can be < 0).\n*\n* H(ldh,m): (input) upper Hessenberg matrix.\n*\n* y(m) : (input/output) on input the operand vector,\n* on output the resulting vector exp(t*H)*y.\n*\n* wsp : (workspace). Observe that a double precision vector of\n* length 2*m*(m+2) can be used as well when calling this\n* routine.\n*\n*----------------------------------------------------------------------|\n* Roger B. Sidje (rbs@maths.uq.edu.au)\n* EXPOKIT: Software Package for Computing Matrix Exponentials.\n* ACM - Transactions On Mathematical Software, 24(1):130-156, 1998\n*----------------------------------------------------------------------|\n*\n complex*16 ZERO\n integer ndeg, i, j, k, ip, ih, iy, iz\n parameter ( ndeg=7, ZERO=(0.0d0,0.0d0) )\n double precision alpha0\n complex*16 alpha(ndeg), theta(ndeg), tmpc\n\n intrinsic ABS,DBLE,CONJG,MIN\n \n*--- Pointers ...\n\n ih = 1\n iy = ih + m*m\n iz = iy + m\n\n*--- Coefficients and poles of the partial fraction expansion...\n\n alpha0 = 0.183216998528140087D-11\n alpha(1)=( 0.557503973136501826D+02,-0.204295038779771857D+03)\n alpha(2)=(-0.938666838877006739D+02, 0.912874896775456363D+02)\n alpha(3)=( 0.469965415550370835D+02,-0.116167609985818103D+02)\n alpha(4)=(-0.961424200626061065D+01,-0.264195613880262669D+01)\n alpha(5)=( 0.752722063978321642D+00, 0.670367365566377770D+00)\n alpha(6)=(-0.188781253158648576D-01,-0.343696176445802414D-01)\n alpha(7)=( 0.143086431411801849D-03, 0.287221133228814096D-03)\n\n theta(1)=(-0.562314417475317895D+01, 0.119406921611247440D+01)\n theta(2)=(-0.508934679728216110D+01, 0.358882439228376881D+01)\n theta(3)=(-0.399337136365302569D+01, 0.600483209099604664D+01)\n theta(4)=(-0.226978543095856366D+01, 0.846173881758693369D+01)\n theta(5)=( 0.208756929753827868D+00, 0.109912615662209418D+02)\n theta(6)=( 0.370327340957595652D+01, 0.136563731924991884D+02)\n theta(7)=( 0.889777151877331107D+01, 0.166309842834712071D+02)\n*\n do ip = 1,ndeg\n theta(ndeg+ip) = CONJG( theta(ip) )\n alpha(ndeg+ip) = CONJG( alpha(ip) )\n enddo\n* \n*--- Accumulation of the contribution of each pole ...\n*\n do j = 1,m\n wsp(iz+j-1) = y(j)\n y(j) = y(j)*alpha0\n enddo\n do ip = 1,2*ndeg\n alpha(ip) = 0.5d0*alpha(ip)\n*--- Solve each fraction using Gaussian elimination with pivoting...\n do j = 1,m\n wsp(iy+j-1) = wsp(iz+j-1)\n do i = 1,MIN( j+1,m )\n wsp(ih+(j-1)*m+i-1) = -t*H(i,j)\n enddo\n wsp(ih+(j-1)*m+j-1) = wsp(ih+(j-1)*m+j-1)-theta(ip)\n do k = i,m\n wsp(ih+(j-1)*m+k-1) = ZERO\n enddo\n enddo\n do i = 1,m-1\n*--- Get pivot and exchange rows ...\n if (ABS(wsp(ih+(i-1)*m+i-1)).lt.ABS(wsp(ih+(i-1)*m+i))) then\n call ZSWAP( m-i+1, wsp(ih+(i-1)*m+i-1),m, \n . wsp(ih+(i-1)*m+i),m )\n call ZSWAP( 1, wsp(iy+i-1),1, wsp(iy+i),1 )\n endif\n*--- Forward eliminiation ... \n tmpc = wsp(ih+(i-1)*m+i) / wsp(ih+(i-1)*m+i-1)\n call ZAXPY( m-i, -tmpc, wsp(ih+i*m+i-1),m, wsp(ih+i*m+i),m )\n wsp(iy+i) = wsp(iy+i) - tmpc*wsp(iy+i-1)\n enddo\n*--- Backward substitution ... \n do i = m,1,-1\n tmpc = wsp(iy+i-1)\n do j = i+1,m\n tmpc = tmpc - wsp(ih+(j-1)*m+i-1)*wsp(iy+j-1)\n enddo\n wsp(iy+i-1) = tmpc / wsp(ih+(i-1)*m+i-1)\n enddo\n*--- Accumulate the partial result in y ... \n do j = 1,m\n y(j) = y(j) + alpha(ip)*wsp(iy+j-1)\n enddo\n enddo\n END\n*----------------------------------------------------------------------|\n*----------------------------------------------------------------------|\n subroutine DGEXPV( n, m, t, v, w, tol, anorm,\n . wsp,lwsp, iwsp,liwsp, matvec, itrace,iflag )\n\n implicit none\n integer n, m, lwsp, liwsp, itrace, iflag, iwsp(liwsp)\n double precision t, tol, anorm, v(n), w(n), wsp(lwsp)\n external matvec\n\n*-----Purpose----------------------------------------------------------|\n*\n*--- DGEXPV computes w = exp(t*A)*v - for a General matrix A.\n*\n* It does not compute the matrix exponential in isolation but\n* instead, it computes directly the action of the exponential\n* operator on the operand vector. This way of doing so allows \n* for addressing large sparse problems. \n*\n* The method used is based on Krylov subspace projection\n* techniques and the matrix under consideration interacts only\n* via the external routine `matvec' performing the matrix-vector \n* product (matrix-free method).\n*\n*-----Arguments--------------------------------------------------------|\n*\n* n : (input) order of the principal matrix A.\n* \n* m : (input) maximum size for the Krylov basis.\n* \n* t : (input) time at wich the solution is needed (can be < 0).\n* \n* v(n) : (input) given operand vector.\n* \n* w(n) : (output) computed approximation of exp(t*A)*v.\n*\n* tol : (input/output) the requested accuracy tolerance on w. \n* If on input tol=0.0d0 or tol is too small (tol.le.eps)\n* the internal value sqrt(eps) is used, and tol is set to\n* sqrt(eps) on output (`eps' denotes the machine epsilon).\n* (`Happy breakdown' is assumed if h(j+1,j) .le. anorm*tol)\n*\n* anorm : (input) an approximation of some norm of A.\n*\n* wsp(lwsp): (workspace) lwsp .ge. n*(m+1)+n+(m+2)^2+4*(m+2)^2+ideg+1\n* +---------+-------+---------------+\n* (actually, ideg=6) V H wsp for PADE\n* \n* iwsp(liwsp): (workspace) liwsp .ge. m+2\n*\n* matvec : external subroutine for matrix-vector multiplication.\n* synopsis: matvec( x, y )\n* double precision x(*), y(*)\n* computes: y(1:n) <- A*x(1:n)\n* where A is the principal matrix.\n*\n* itrace : (input) running mode. 0=silent, 1=print step-by-step info\n*\n* iflag : (output) exit flag.\n* <0 - bad input arguments \n* 0 - no problem\n* 1 - maximum number of steps reached without convergence\n* 2 - requested tolerance was too high\n*\n*-----Accounts on the computation--------------------------------------|\n* Upon exit, an interested user may retrieve accounts on the \n* computations. They are located in wsp and iwsp as indicated below:\n*\n* location mnemonic description\n* -----------------------------------------------------------------|\n* iwsp(1) = nmult, number of matrix-vector multiplications used\n* iwsp(2) = nexph, number of Hessenberg matrix exponential evaluated\n* iwsp(3) = nscale, number of repeated squaring involved in Pade\n* iwsp(4) = nstep, number of integration steps used up to completion \n* iwsp(5) = nreject, number of rejected step-sizes\n* iwsp(6) = ibrkflag, set to 1 if `happy breakdown' and 0 otherwise\n* iwsp(7) = mbrkdwn, if `happy brkdown', basis-size when it occured\n* -----------------------------------------------------------------|\n* wsp(1) = step_min, minimum step-size used during integration\n* wsp(2) = step_max, maximum step-size used during integration\n* wsp(3) = dummy\n* wsp(4) = dummy\n* wsp(5) = x_error, maximum among all local truncation errors\n* wsp(6) = s_error, global sum of local truncation errors\n* wsp(7) = tbrkdwn, if `happy breakdown', time when it occured\n* wsp(8) = t_now, integration domain successfully covered\n* wsp(9) = hump, i.e., max||exp(sA)||, s in [0,t] (or [t,0] if t<0)\n* wsp(10) = ||w||/||v||, scaled norm of the solution w.\n* -----------------------------------------------------------------|\n* The `hump' is a measure of the conditioning of the problem. The\n* matrix exponential is well-conditioned if hump = 1, whereas it is\n* poorly-conditioned if hump >> 1. However the solution can still be\n* relatively fairly accurate even when the hump is large (the hump \n* is an upper bound), especially when the hump and the scaled norm\n* of w [this is also computed and returned in wsp(10)] are of the \n* same order of magnitude (further details in reference below).\n*\n*----------------------------------------------------------------------|\n*-----The following parameters may also be adjusted herein-------------|\n*\n integer mxstep, mxreject, ideg\n double precision delta, gamma\n parameter( mxstep = 1000,\n . mxreject = 0,\n . ideg = 6,\n . delta = 1.2d0,\n . gamma = 0.9d0 )\n\n* mxstep : maximum allowable number of integration steps.\n* The value 0 means an infinite number of steps.\n* \n* mxreject: maximum allowable number of rejections at each step. \n* The value 0 means an infinite number of rejections.\n*\n* ideg : the Pade approximation of type (ideg,ideg) is used as \n* an approximation to exp(H). The value 0 switches to the\n* uniform rational Chebyshev approximation of type (14,14)\n*\n* delta : local truncation error `safety factor'\n*\n* gamma : stepsize `shrinking factor'\n*\n*----------------------------------------------------------------------|\n* Roger B. Sidje (rbs@maths.uq.edu.au)\n* EXPOKIT: Software Package for Computing Matrix Exponentials.\n* ACM - Transactions On Mathematical Software, 24(1):130-156, 1998\n*----------------------------------------------------------------------|\n*\n integer i, j, k1, mh, mx, iv, ih, j1v, ns, ifree, lfree, iexph,\n . ireject,ibrkflag,mbrkdwn, nmult, nreject, nexph, nscale,\n . nstep\n double precision sgn, t_out, tbrkdwn, step_min,step_max, err_loc,\n . s_error, x_error, t_now, t_new, t_step, t_old,\n . xm, beta, break_tol, p1, p2, p3, eps, rndoff,\n . vnorm, avnorm, hj1j, hij, hump, SQR1\n\n intrinsic AINT,ABS,DBLE,LOG10,MAX,MIN,NINT,SIGN,SQRT\n double precision DDOT, DNRM2\n\n*--- check restrictions on input parameters ...\n iflag = 0\n if ( lwsp.lt.n*(m+2)+5*(m+2)**2+ideg+1 ) iflag = -1\n if ( liwsp.lt.m+2 ) iflag = -2\n if ( m.ge.n .or. m.le.0 ) iflag = -3\n if ( iflag.ne.0 ) stop 'bad sizes (in input of DGEXPV)'\n*\n*--- initialisations ...\n*\n k1 = 2\n mh = m + 2\n iv = 1\n ih = iv + n*(m+1) + n\n ifree = ih + mh*mh\n lfree = lwsp - ifree + 1\n\n ibrkflag = 0\n mbrkdwn = m\n nmult = 0\n nreject = 0\n nexph = 0\n nscale = 0\n\n t_out = ABS( t )\n tbrkdwn = 0.0d0\n step_min = t_out\n step_max = 0.0d0\n nstep = 0\n s_error = 0.0d0\n x_error = 0.0d0\n t_now = 0.0d0\n t_new = 0.0d0\n\n p1 = 4.0d0/3.0d0\n 1 p2 = p1 - 1.0d0\n p3 = p2 + p2 + p2\n eps = ABS( p3-1.0d0 )\n if ( eps.eq.0.0d0 ) go to 1\n if ( tol.le.eps ) tol = SQRT( eps )\n rndoff = eps*anorm\n\n break_tol = 1.0d-7\n*>>> break_tol = tol\n*>>> break_tol = anorm*tol\n\n sgn = SIGN( 1.0d0,t )\n call DCOPY( n, v,1, w,1 )\n beta = DNRM2( n, w,1 )\n vnorm = beta\n hump = beta \n*\n*--- obtain the very first stepsize ...\n*\n SQR1 = SQRT( 0.1d0 )\n xm = 1.0d0/DBLE( m )\n p1 = tol*(((m+1)/2.72D0)**(m+1))*SQRT(2.0D0*3.14D0*(m+1))\n t_new = (1.0d0/anorm)*(p1/(4.0d0*beta*anorm))**xm\n p1 = 10.0d0**(NINT( LOG10( t_new )-SQR1 )-1)\n t_new = AINT( t_new/p1 + 0.55d0 ) * p1\n*\n*--- step-by-step integration ...\n*\n 100 if ( t_now.ge.t_out ) goto 500\n\n nstep = nstep + 1\n t_step = MIN( t_out-t_now, t_new )\n\n p1 = 1.0d0/beta\n do i = 1,n\n wsp(iv + i-1) = p1*w(i)\n enddo\n do i = 1,mh*mh\n wsp(ih+i-1) = 0.0d0\n enddo\n*\n*--- Arnoldi loop ...\n*\n j1v = iv + n\n do 200 j = 1,m\n nmult = nmult + 1\n call matvec(n, wsp(j1v-n), wsp(j1v) )\n do i = 1,j\n hij = DDOT( n, wsp(iv+(i-1)*n),1, wsp(j1v),1 )\n call DAXPY( n, -hij, wsp(iv+(i-1)*n),1, wsp(j1v),1 )\n wsp(ih+(j-1)*mh+i-1) = hij\n enddo\n hj1j = DNRM2( n, wsp(j1v),1 )\n*--- if `happy breakdown' go straightforward at the end ... \n if ( hj1j.le.break_tol ) then\n print*,'happy breakdown: mbrkdwn =',j,' h =',hj1j\n k1 = 0\n ibrkflag = 1\n mbrkdwn = j\n tbrkdwn = t_now\n t_step = t_out-t_now\n goto 300\n endif\n wsp(ih+(j-1)*mh+j) = hj1j\n call DSCAL( n, 1.0d0/hj1j, wsp(j1v),1 )\n j1v = j1v + n\n 200 continue\n nmult = nmult + 1\n call matvec(n, wsp(j1v-n), wsp(j1v) )\n avnorm = DNRM2( n, wsp(j1v),1 )\n*\n*--- set 1 for the 2-corrected scheme ...\n*\n 300 continue\n wsp(ih+m*mh+m+1) = 1.0d0\n*\n*--- loop while ireject> 1. However the solution can still be\n* relatively fairly accurate even when the hump is large (the hump \n* is an upper bound), especially when the hump and the scaled norm\n* of w [this is also computed and returned in wsp(10)] are of the \n* same order of magnitude (further details in reference below).\n*\n*----------------------------------------------------------------------|\n*-----The following parameters may also be adjusted herein-------------|\n*\n integer mxstep, mxreject, ideg\n double precision delta, gamma\n parameter( mxstep = 500,\n . mxreject = 0,\n . ideg = 6,\n . delta = 1.2d0,\n . gamma = 0.9d0 )\n\n* mxstep : maximum allowable number of integration steps.\n* The value 0 means an infinite number of steps.\n* \n* mxreject: maximum allowable number of rejections at each step. \n* The value 0 means an infinite number of rejections.\n*\n* ideg : the Pade approximation of type (ideg,ideg) is used as \n* an approximation to exp(H). The value 0 switches to the\n* uniform rational Chebyshev approximation of type (14,14)\n*\n* delta : local truncation error `safety factor'\n*\n* gamma : stepsize `shrinking factor'\n*\n*----------------------------------------------------------------------|\n* Roger B. Sidje (rbs@maths.uq.edu.au)\n* EXPOKIT: Software Package for Computing Matrix Exponentials.\n* ACM - Transactions On Mathematical Software, 24(1):130-156, 1998\n*----------------------------------------------------------------------|\n*\n integer i, j, k1, mh, mx, iv, ih, j1v, ns, ifree, lfree, iexph,\n . ireject,ibrkflag,mbrkdwn, nmult, nreject, nexph, nscale,\n . nstep\n double precision sgn, t_out, tbrkdwn, step_min,step_max, err_loc,\n . s_error, x_error, t_now, t_new, t_step, t_old,\n . xm, beta, break_tol, p1, p2, p3, eps, rndoff,\n . vnorm, avnorm, hj1j, hjj, hump, SQR1\n\n intrinsic AINT,ABS,DBLE,LOG10,MAX,MIN,NINT,SIGN,SQRT\n double precision DDOT, DNRM2\n\n*--- check restrictions on input parameters ...\n iflag = 0\n if ( lwsp.lt.n*(m+2)+5*(m+2)**2+ideg+1 ) iflag = -1\n if ( liwsp.lt.m+2 ) iflag = -2\n if ( m.ge.n .or. m.le.0 ) iflag = -3\n if ( iflag.ne.0 ) stop 'bad sizes (in input of DSEXPV)'\n*\n*--- initialisations ...\n*\n k1 = 2\n mh = m + 2\n iv = 1\n ih = iv + n*(m+1) + n\n ifree = ih + mh*mh\n lfree = lwsp - ifree + 1\n\n ibrkflag = 0\n mbrkdwn = m\n nmult = 0\n nreject = 0\n nexph = 0\n nscale = 0\n\n t_out = ABS( t )\n tbrkdwn = 0.0d0\n step_min = t_out\n step_max = 0.0d0\n nstep = 0\n s_error = 0.0d0\n x_error = 0.0d0\n t_now = 0.0d0\n t_new = 0.0d0\n\n p1 = 4.0d0/3.0d0\n 1 p2 = p1 - 1.0d0\n p3 = p2 + p2 + p2\n eps = ABS( p3-1.0d0 )\n if ( eps.eq.0.0d0 ) go to 1\n if ( tol.le.eps ) tol = SQRT( eps )\n rndoff = eps*anorm\n\n break_tol = 1.0d-7\n*>>> break_tol = tol\n*>>> break_tol = anorm*tol\n\n sgn = SIGN( 1.0d0,t )\n call DCOPY( n, v,1, w,1 )\n beta = DNRM2( n, w,1 )\n vnorm = beta\n hump = beta \n*\n*--- obtain the very first stepsize ...\n*\n SQR1 = SQRT( 0.1d0 )\n xm = 1.0d0/DBLE( m )\n p1 = tol*(((m+1)/2.72D0)**(m+1))*SQRT(2.0D0*3.14D0*(m+1))\n t_new = (1.0d0/anorm)*(p1/(4.0d0*beta*anorm))**xm\n p1 = 10.0d0**(NINT( LOG10( t_new )-SQR1 )-1)\n t_new = AINT( t_new/p1 + 0.55d0 ) * p1\n*\n*--- step-by-step integration ...\n*\n 100 if ( t_now.ge.t_out ) goto 500\n\n nstep = nstep + 1\n t_step = MIN( t_out-t_now, t_new )\n\n p1 = 1.0d0/beta\n do i = 1,n\n wsp(iv + i-1) = p1*w(i)\n enddo\n do i = 1,mh*mh\n wsp(ih+i-1) = 0.0d0\n enddo\n*\n*--- Lanczos loop ...\n*\n j1v = iv + n\n do 200 j = 1,m\n nmult = nmult + 1\n call matvec(n, wsp(j1v-n), wsp(j1v) )\n if ( j.gt.1 )\n . call DAXPY(n,-wsp(ih+(j-1)*mh+j-2),wsp(j1v-2*n),1,wsp(j1v),1)\n hjj = DDOT( n, wsp(j1v-n),1, wsp(j1v),1 )\n call DAXPY( n, -hjj, wsp(j1v-n),1, wsp(j1v),1 )\n hj1j = DNRM2( n, wsp(j1v),1 )\n wsp(ih+(j-1)*(mh+1)) = hjj\n*--- if `happy breakdown' go straightforward at the end ... \n if ( hj1j.le.break_tol ) then\n print*,'happy breakdown: mbrkdwn =',j,' h =',hj1j\n k1 = 0\n ibrkflag = 1\n mbrkdwn = j\n tbrkdwn = t_now\n t_step = t_out-t_now\n goto 300\n endif\n wsp(ih+(j-1)*mh+j) = hj1j\n wsp(ih+j*mh+j-1) = hj1j\n call DSCAL( n, 1.0d0/hj1j, wsp(j1v),1 )\n j1v = j1v + n\n 200 continue\n nmult = nmult + 1\n call matvec(n, wsp(j1v-n), wsp(j1v) )\n avnorm = DNRM2( n, wsp(j1v),1 )\n*\n*--- set 1 for the 2-corrected scheme ...\n*\n 300 continue\n wsp(ih+m*mh+m-1) = 0.0d0\n wsp(ih+m*mh+m+1) = 1.0d0\n*\n*--- loop while ireject> 1. However the solution can still be\n* relatively fairly accurate even when the hump is large (the hump \n* is an upper bound), especially when the hump and the scaled norm\n* of w [this is also computed and returned in wsp(10)] are of the \n* same order of magnitude (further details in reference below).\n*\n*----------------------------------------------------------------------|\n*-----The following parameters may also be adjusted herein-------------|\n*\n integer mxstep, mxreject, ideg\n double precision delta, gamma\n parameter( mxstep = 500,\n . mxreject = 0,\n . ideg = 6,\n . delta = 1.2d0,\n . gamma = 0.9d0 )\n\n* mxstep : maximum allowable number of integration steps.\n* The value 0 means an infinite number of steps.\n* \n* mxreject: maximum allowable number of rejections at each step. \n* The value 0 means an infinite number of rejections.\n*\n* ideg : the Pade approximation of type (ideg,ideg) is used as \n* an approximation to exp(H). The value 0 switches to the\n* uniform rational Chebyshev approximation of type (14,14)\n*\n* delta : local truncation error `safety factor'\n*\n* gamma : stepsize `shrinking factor'\n*\n*----------------------------------------------------------------------|\n* Roger B. Sidje (rbs@maths.uq.edu.au)\n* EXPOKIT: Software Package for Computing Matrix Exponentials.\n* ACM - Transactions On Mathematical Software, 24(1):130-156, 1998\n*----------------------------------------------------------------------|\n\n complex*16 ZERO, ONE\n parameter( ZERO=(0.0d0,0.0d0), ONE=(1.0d0,0.0d0) )\n integer i, j, k1, mh, mx, iv, ih, j1v, ns, ifree, lfree, iexph,\n . ireject,ibrkflag,mbrkdwn, nmult, nreject, nexph, nscale,\n . nstep\n double precision sgn, t_out, tbrkdwn, step_min,step_max, err_loc,\n . s_error, x_error, t_now, t_new, t_step, t_old,\n . xm, beta, break_tol, p1, p2, p3, eps, rndoff,\n . vnorm, avnorm, hj1j, hump, SQR1\n complex*16 hij\n\n intrinsic AINT,ABS,CMPLX,DBLE,INT,LOG10,MAX,MIN,NINT,SIGN,SQRT\n complex*16 ZDOTC\n double precision DZNRM2\n*\n*--- check restrictions on input parameters ...\n*\n iflag = 0\n if ( lwsp.lt.n*(m+2)+5*(m+2)**2+ideg+1 ) iflag = -1\n if ( liwsp.lt.m+2 ) iflag = -2\n if ( m.ge.n .or. m.le.0 ) iflag = -3\n if ( iflag.ne.0 ) stop 'bad sizes (in input of ZGEXPV)'\n*\n*--- initialisations ...\n*\n k1 = 2\n mh = m + 2\n iv = 1\n ih = iv + n*(m+1) + n\n ifree = ih + mh*mh\n lfree = lwsp - ifree + 1\n\n ibrkflag = 0\n mbrkdwn = m\n nmult = 0\n nreject = 0\n nexph = 0\n nscale = 0\n\n t_out = ABS( t )\n tbrkdwn = 0.0d0\n step_min = t_out\n step_max = 0.0d0\n nstep = 0\n s_error = 0.0d0\n x_error = 0.0d0\n t_now = 0.0d0\n t_new = 0.0d0\n\n p1 = 4.0d0/3.0d0\n 1 p2 = p1 - 1.0d0\n p3 = p2 + p2 + p2\n eps = ABS( p3-1.0d0 )\n if ( eps.eq.0.0d0 ) go to 1\n if ( tol.le.eps ) tol = SQRT( eps )\n rndoff = eps*anorm\n\n break_tol = 1.0d-7\n*>>> break_tol = tol\n*>>> break_tol = anorm*tol\n\n sgn = SIGN( 1.0d0,t )\n call ZCOPY( n, v,1, w,1 )\n beta = DZNRM2( n, w,1 )\n vnorm = beta\n hump = beta \n*\n*--- obtain the very first stepsize ...\n*\n SQR1 = SQRT( 0.1d0 )\n xm = 1.0d0/DBLE( m )\n p2 = tol*(((m+1)/2.72D0)**(m+1))*SQRT(2.0D0*3.14D0*(m+1))\n t_new = (1.0d0/anorm)*(p2/(4.0d0*beta*anorm))**xm\n p1 = 10.0d0**(NINT( LOG10( t_new )-SQR1 )-1)\n t_new = AINT( t_new/p1 + 0.55d0 ) * p1\n*\n*--- step-by-step integration ...\n*\n 100 if ( t_now.ge.t_out ) goto 500\n\n nstep = nstep + 1\n t_step = MIN( t_out-t_now, t_new )\n p1 = 1.0d0/beta\n do i = 1,n\n wsp(iv + i-1) = p1*w(i)\n enddo\n do i = 1,mh*mh\n wsp(ih+i-1) = ZERO\n enddo\n*\n*--- Arnoldi loop ...\n*\n j1v = iv + n\n do 200 j = 1,m\n nmult = nmult + 1\n call matvec(n, wsp(j1v-n), wsp(j1v) )\n do i = 1,j\n hij = ZDOTC( n, wsp(iv+(i-1)*n),1, wsp(j1v),1 )\n call ZAXPY( n, -hij, wsp(iv+(i-1)*n),1, wsp(j1v),1 )\n wsp(ih+(j-1)*mh+i-1) = hij\n enddo\n hj1j = DZNRM2( n, wsp(j1v),1 )\n*--- if `happy breakdown' go straightforward at the end ... \n if ( hj1j.le.break_tol ) then\n*--- print*,'happy breakdown: mbrkdwn =',j,' h =',hj1j\n k1 = 0\n ibrkflag = 1\n mbrkdwn = j\n tbrkdwn = t_now\n t_step = t_out-t_now\n goto 300\n endif\n wsp(ih+(j-1)*mh+j) = CMPLX( hj1j )\n call ZDSCAL( n, 1.0d0/hj1j, wsp(j1v),1 )\n j1v = j1v + n\n 200 continue\n nmult = nmult + 1\n call matvec(n, wsp(j1v-n), wsp(j1v) )\n avnorm = DZNRM2( n, wsp(j1v),1 )\n*\n*--- set 1 for the 2-corrected scheme ...\n*\n 300 continue\n wsp(ih+m*mh+m+1) = ONE\n*\n*--- loop while ireject> 1. However the solution can still be\n* relatively fairly accurate even when the hump is large (the hump \n* is an upper bound), especially when the hump and the scaled norm\n* of w [this is also computed and returned in wsp(10)] are of the \n* same order of magnitude (further details in reference below).\n*\n*----------------------------------------------------------------------|\n*-----The following parameters may also be adjusted herein-------------|\n*\n integer mxstep, mxreject, ideg\n double precision delta, gamma\n parameter( mxstep = 500,\n . mxreject = 0,\n . ideg = 6,\n . delta = 1.2d0,\n . gamma = 0.9d0 )\n\n* mxstep : maximum allowable number of integration steps.\n* The value 0 means an infinite number of steps.\n* \n* mxreject: maximum allowable number of rejections at each step. \n* The value 0 means an infinite number of rejections.\n*\n* ideg : the Pade approximation of type (ideg,ideg) is used as \n* an approximation to exp(H). The value 0 switches to the\n* uniform rational Chebyshev approximation of type (14,14)\n*\n* delta : local truncation error `safety factor'\n*\n* gamma : stepsize `shrinking factor'\n*\n*----------------------------------------------------------------------|\n* Roger B. Sidje (rbs@maths.uq.edu.au)\n* EXPOKIT: Software Package for Computing Matrix Exponentials.\n* ACM - Transactions On Mathematical Software, 24(1):130-156, 1998\n*----------------------------------------------------------------------|\n*\n complex*16 ZERO, ONE\n parameter( ZERO=(0.0d0,0.0d0), ONE=(1.0d0,0.0d0) )\n integer i, j, k1, mh, mx, iv, ih, j1v, ns, ifree, lfree, iexph,\n . ireject,ibrkflag,mbrkdwn, nmult, nreject, nexph, nscale,\n . nstep\n double precision sgn, t_out, tbrkdwn, step_min,step_max, err_loc,\n . s_error, x_error, t_now, t_new, t_step, t_old,\n . xm, beta, break_tol, p1, p2, p3, eps, rndoff,\n . vnorm, avnorm, hj1j, hump, SQR1\n complex*16 hjj\n\n intrinsic AINT,ABS,CMPLX,DBLE,INT,LOG10,MAX,MIN,NINT,SIGN,SQRT\n complex*16 ZDOTC\n double precision DZNRM2\n*\n*--- check restrictions on input parameters ...\n*\n iflag = 0\n if ( lwsp.lt.n*(m+2)+5*(m+2)**2+ideg+1 ) iflag = -1\n if ( liwsp.lt.m+2 ) iflag = -2\n if ( m.ge.n .or. m.le.0 ) iflag = -3\n if ( iflag.ne.0 ) stop 'bad sizes (in input of DHEXPV)'\n*\n*--- initialisations ...\n*\n k1 = 2\n mh = m + 2\n iv = 1\n ih = iv + n*(m+1) + n\n ifree = ih + mh*mh\n lfree = lwsp - ifree + 1\n\n ibrkflag = 0\n mbrkdwn = m\n nmult = 0\n nreject = 0\n nexph = 0\n nscale = 0\n\n t_out = ABS( t )\n tbrkdwn = 0.0d0\n step_min = t_out\n step_max = 0.0d0\n nstep = 0\n s_error = 0.0d0\n x_error = 0.0d0\n t_now = 0.0d0\n t_new = 0.0d0\n\n p1 = 4.0d0/3.0d0\n 1 p2 = p1 - 1.0d0\n p3 = p2 + p2 + p2\n eps = ABS( p3-1.0d0 )\n if ( eps.eq.0.0d0 ) go to 1\n if ( tol.le.eps ) tol = SQRT( eps )\n rndoff = eps*anorm\n\n break_tol = 1.0d-7\n*>>> break_tol = tol\n*>>> break_tol = anorm*tol\n\n sgn = SIGN( 1.0d0,t )\n call ZCOPY( n, v,1, w,1 )\n beta = DZNRM2( n, w,1 )\n vnorm = beta\n hump = beta \n*\n*--- obtain the very first stepsize ...\n*\n SQR1 = SQRT( 0.1d0 )\n xm = 1.0d0/DBLE( m )\n p2 = tol*(((m+1)/2.72D0)**(m+1))*SQRT(2.0D0*3.14D0*(m+1))\n t_new = (1.0d0/anorm)*(p2/(4.0d0*beta*anorm))**xm\n p1 = 10.0d0**(NINT( LOG10( t_new )-SQR1 )-1)\n t_new = AINT( t_new/p1 + 0.55d0 ) * p1\n*\n*--- step-by-step integration ...\n*\n 100 if ( t_now.ge.t_out ) goto 500\n\n nstep = nstep + 1\n t_step = MIN( t_out-t_now, t_new )\n beta = DZNRM2( n, w,1 )\n p1 = 1.0d0/beta\n do i = 1,n\n wsp(iv + i-1) = p1*w(i)\n enddo\n do i = 1,mh*mh\n wsp(ih+i-1) = ZERO\n enddo\n*\n*--- Lanczos loop ...\n*\n j1v = iv + n\n do 200 j = 1,m\n nmult = nmult + 1\n call matvec(n, wsp(j1v-n), wsp(j1v) )\n if ( j.gt.1 )\n . call ZAXPY(n,-wsp(ih+(j-1)*mh+j-2),wsp(j1v-2*n),1,wsp(j1v),1)\n hjj = ZDOTC( n, wsp(j1v-n),1, wsp(j1v),1 )\n call ZAXPY( n, -hjj, wsp(j1v-n),1, wsp(j1v),1 )\n hj1j = DZNRM2( n, wsp(j1v),1 )\n wsp(ih+(j-1)*(mh+1)) = hjj\n*--- if `happy breakdown' go straightforward at the end ...\n if ( hj1j.le.break_tol ) then\n*--- print*,'happy breakdown: mbrkdwn =',j,' h =',hj1j\n k1 = 0\n ibrkflag = 1\n mbrkdwn = j\n tbrkdwn = t_now\n t_step = t_out-t_now\n goto 300\n endif\n wsp(ih+(j-1)*mh+j) = CMPLX( hj1j )\n wsp(ih+j*mh+j-1) = CMPLX( hj1j )\n call ZDSCAL( n, 1.0d0/hj1j, wsp(j1v),1 )\n j1v = j1v + n\n 200 continue\n nmult = nmult + 1\n call matvec(n, wsp(j1v-n), wsp(j1v) )\n avnorm = DZNRM2( n, wsp(j1v),1 )\n*\n*--- set 1 for the 2-corrected scheme ...\n*\n 300 continue\n wsp(ih+m*mh+m-1) = ZERO\n wsp(ih+m*mh+m+1) = ONE\n*\n*--- loop while ireject>> break_tol = tol\n*>>> break_tol = anorm*tol\n\n*\n*--- step-by-step integration ...\n*\n sgn = SIGN( 1.0d0,t )\n SQR1 = SQRT( 0.1d0 )\n call DCOPY( n, v,1, w,1 )\n\n 100 if ( t_now.ge.t_out ) goto 500\n\n nmult = nmult + 1\n call matvec(n, w, wsp(iv) )\n call DAXPY( n, 1.0d0, u,1, wsp(iv),1 )\n beta = DNRM2( n, wsp(iv),1 )\n if ( beta.eq.0.0d0 ) goto 500\n call DSCAL( n, 1.0d0/beta, wsp(iv),1 )\n do i = 1,mh*mh\n wsp(ih+i-1) = 0.0d0\n enddo\n\n if ( nstep.eq.0 ) then\n*--- obtain the very first stepsize ...\n xm = 1.0d0/DBLE( m )\n p1 = tol*(((m+1)/2.72D0)**(m+1))*SQRT(2.0D0*3.14D0*(m+1))\n t_new = (1.0d0/anorm)*(p1/(4.0d0*beta*anorm))**xm\n p1 = 10.0d0**(NINT( LOG10( t_new )-SQR1 )-1)\n t_new = AINT( t_new/p1 + 0.55d0 ) * p1\n endif\n nstep = nstep + 1\n t_step = MIN( t_out-t_now, t_new )\n*\n*--- Arnoldi loop ...\n*\n j1v = iv + n\n do 200 j = 1,m\n nmult = nmult + 1\n call matvec(n, wsp(j1v-n), wsp(j1v) )\n do i = 1,j\n hij = DDOT( n, wsp(iv+(i-1)*n),1, wsp(j1v),1 )\n call DAXPY( n, -hij, wsp(iv+(i-1)*n),1, wsp(j1v),1 )\n wsp(ih+(j-1)*mh+i-1) = hij\n enddo\n hj1j = DNRM2( n, wsp(j1v),1 )\n*--- if `happy breakdown' go straightforward at the end ... \n if ( hj1j.le.break_tol ) then\n print*,'happy breakdown: mbrkdwn =',j,' h =',hj1j\n k1 = 0\n ibrkflag = 1\n mbrkdwn = j\n tbrkdwn = t_now\n t_step = t_out-t_now\n goto 300\n endif\n wsp(ih+(j-1)*mh+j) = hj1j\n call DSCAL( n, 1.0d0/hj1j, wsp(j1v),1 )\n j1v = j1v + n\n 200 continue\n nmult = nmult + 1\n call matvec(n, wsp(j1v-n), wsp(j1v) )\n avnorm = DNRM2( n, wsp(j1v),1 )\n*\n*--- set 1's for the 3-extended scheme ...\n*\n 300 continue\n wsp(ih+mh*mbrkdwn) = 1.0d0\n wsp(ih+(m-1)*mh+m) = 0.0d0\n do i = 1,k1-1\n wsp(ih+(m+i)*mh+m+i-1) = 1.0d0\n enddo\n*\n*--- loop while ireject>> break_tol = tol\n*>>> break_tol = anorm*tol\n\n*\n*--- step-by-step integration ...\n*\n sgn = SIGN( 1.0d0,t )\n SQR1 = SQRT( 0.1d0 )\n call DCOPY( n, v,1, w,1 )\n\n 100 if ( t_now.ge.t_out ) goto 500\n\n nmult = nmult + 1\n call matvec(n, w, wsp(iv) )\n call DAXPY( n, 1.0d0, u,1, wsp(iv),1 )\n beta = DNRM2( n, wsp(iv),1 )\n if ( beta.eq.0.0d0 ) goto 500\n call DSCAL( n, 1.0d0/beta, wsp(iv),1 )\n do i = 1,mh*mh\n wsp(ih+i-1) = 0.0d0\n enddo\n\n if ( nstep.eq.0 ) then\n*--- obtain the very first stepsize ...\n xm = 1.0d0/DBLE( m )\n p1 = tol*(((m+1)/2.72D0)**(m+1))*SQRT(2.0D0*3.14D0*(m+1))\n t_new = (1.0d0/anorm)*(p1/(4.0d0*beta*anorm))**xm\n p1 = 10.0d0**(NINT( LOG10( t_new )-SQR1 )-1)\n t_new = AINT( t_new/p1 + 0.55d0 ) * p1\n endif\n nstep = nstep + 1\n t_step = MIN( t_out-t_now, t_new )\n*\n*--- Lanczos loop ...\n*\n j1v = iv + n\n do 200 j = 1,m\n nmult = nmult + 1\n call matvec(n, wsp(j1v-n), wsp(j1v) )\n if ( j.gt.1 )\n . call DAXPY(n,-wsp(ih+(j-1)*mh+j-2),wsp(j1v-2*n),1,wsp(j1v),1)\n hjj = DDOT( n, wsp(j1v-n),1, wsp(j1v),1 )\n call DAXPY( n, -hjj, wsp(j1v-n),1, wsp(j1v),1 )\n hj1j = DNRM2( n, wsp(j1v),1 )\n wsp(ih+(j-1)*(mh+1)) = hjj\n*--- if `happy breakdown' go straightforward at the end ... \n if ( hj1j.le.break_tol ) then\n print*,'happy breakdown: mbrkdwn =',j,' h =',hj1j\n k1 = 0\n ibrkflag = 1\n mbrkdwn = j\n tbrkdwn = t_now\n t_step = t_out-t_now\n goto 300\n endif\n wsp(ih+(j-1)*mh+j) = hj1j\n wsp(ih+j*mh+j-1) = hj1j\n call DSCAL( n, 1.0d0/hj1j, wsp(j1v),1 )\n j1v = j1v + n\n 200 continue\n nmult = nmult + 1\n call matvec(n, wsp(j1v-n), wsp(j1v) )\n avnorm = DNRM2( n, wsp(j1v),1 )\n*\n*--- set 1's for the 3-extended scheme ...\n*\n 300 continue\n wsp(ih+mh*mbrkdwn) = 1.0d0\n wsp(ih+m*mh+m-1) = 0.0d0\n wsp(ih+(m-1)*mh+m) = 0.0d0\n do i = 1,k1-1\n wsp(ih+(m+i)*mh+m+i-1) = 1.0d0\n enddo\n*\n*--- loop while ireject>> break_tol = tol\n*>>> break_tol = anorm*tol\n\n sgn = SIGN( 1.0d0,t )\n SQR1 = SQRT( 0.1d0 )\n call ZCOPY( n, v,1, w,1 )\n*\n*--- step-by-step integration ...\n*\n 100 if ( t_now.ge.t_out ) goto 500\n\n nmult = nmult + 1\n call matvec(n, w, wsp(iv) )\n call ZAXPY( n, ONE, u,1, wsp(iv),1 )\n beta = DZNRM2( n, wsp(iv),1 )\n if ( beta.eq.0.0d0 ) goto 500\n call ZDSCAL( n, 1.0d0/beta, wsp(iv),1 )\n do i = 1,mh*mh\n wsp(ih+i-1) = ZERO\n enddo\n\n if ( nstep.eq.0 ) then\n*--- obtain the very first stepsize ...\n xm = 1.0d0/DBLE( m )\n p1 = tol*(((m+1)/2.72D0)**(m+1))*SQRT(2.0D0*3.14D0*(m+1))\n t_new = (1.0d0/anorm)*(p1/(4.0d0*beta*anorm))**xm\n p1 = 10.0d0**(NINT( LOG10( t_new )-SQR1 )-1)\n t_new = AINT( t_new/p1 + 0.55d0 ) * p1\n endif\n nstep = nstep + 1\n t_step = MIN( t_out-t_now, t_new )\n*\n*--- Arnoldi loop ...\n*\n j1v = iv + n\n do 200 j = 1,m\n nmult = nmult + 1\n call matvec(n, wsp(j1v-n), wsp(j1v) )\n do i = 1,j\n hij = ZDOTC( n, wsp(iv+(i-1)*n),1, wsp(j1v),1 )\n call ZAXPY( n, -hij, wsp(iv+(i-1)*n),1, wsp(j1v),1 )\n wsp(ih+(j-1)*mh+i-1) = hij\n enddo\n hj1j = DZNRM2( n, wsp(j1v),1 )\n*--- if `happy breakdown' go straightforward at the end ... \n if ( hj1j.le.break_tol ) then\n print*,'happy breakdown: mbrkdwn =',j,' h =',hj1j\n k1 = 0\n ibrkflag = 1\n mbrkdwn = j\n tbrkdwn = t_now\n t_step = t_out-t_now\n goto 300\n endif\n wsp(ih+(j-1)*mh+j) = CMPLX( hj1j )\n call ZDSCAL( n, 1.0d0/hj1j, wsp(j1v),1 )\n j1v = j1v + n\n 200 continue\n nmult = nmult + 1\n call matvec(n, wsp(j1v-n), wsp(j1v) )\n avnorm = DZNRM2( n, wsp(j1v),1 )\n*\n*--- set 1's for the 3-extended scheme ...\n*\n 300 continue\n wsp(ih+mh*mbrkdwn) = ONE\n wsp(ih+(m-1)*mh+m) = ZERO\n do i = 1,k1-1\n wsp(ih+(m+i)*mh+m+i-1) = ONE\n enddo\n*\n*--- loop while ireject>> break_tol = tol\n*>>> break_tol = anorm*tol\n\n sgn = SIGN( 1.0d0,t )\n SQR1 = SQRT( 0.1d0 )\n call ZCOPY( n, v,1, w,1 )\n*\n*--- step-by-step integration ...\n*\n 100 if ( t_now.ge.t_out ) goto 500\n\n nmult = nmult + 1\n call matvec(n, w, wsp(iv) )\n call ZAXPY( n, ONE, u,1, wsp(iv),1 )\n beta = DZNRM2( n, wsp(iv),1 )\n if ( beta.eq.0.0d0 ) goto 500\n call ZDSCAL( n, 1.0d0/beta, wsp(iv),1 )\n do i = 1,mh*mh\n wsp(ih+i-1) = ZERO\n enddo\n\n if ( nstep.eq.0 ) then\n*--- obtain the very first stepsize ...\n xm = 1.0d0/DBLE( m )\n p1 = tol*(((m+1)/2.72D0)**(m+1))*SQRT(2.0D0*3.14D0*(m+1))\n t_new = (1.0d0/anorm)*(p1/(4.0d0*beta*anorm))**xm\n p1 = 10.0d0**(NINT( LOG10( t_new )-SQR1 )-1)\n t_new = AINT( t_new/p1 + 0.55d0 ) * p1\n endif\n nstep = nstep + 1\n t_step = MIN( t_out-t_now, t_new )\n*\n*--- Lanczos loop ...\n*\n j1v = iv + n\n do 200 j = 1,m\n nmult = nmult + 1\n call matvec(n, wsp(j1v-n), wsp(j1v) )\n if ( j.gt.1 )\n . call ZAXPY(n,-wsp(ih+(j-1)*mh+j-2),wsp(j1v-2*n),1,wsp(j1v),1)\n hjj = ZDOTC( n, wsp(j1v-n),1, wsp(j1v),1 )\n call ZAXPY( n, -hjj, wsp(j1v-n),1, wsp(j1v),1 )\n hj1j = DZNRM2( n, wsp(j1v),1 )\n wsp(ih+(j-1)*(mh+1)) = hjj\n if ( hj1j.le.break_tol ) then\n print*,'happy breakdown: mbrkdwn =',j,' h =',hj1j\n k1 = 0\n ibrkflag = 1\n mbrkdwn = j\n tbrkdwn = t_now\n t_step = t_out-t_now\n goto 300\n endif\n wsp(ih+(j-1)*mh+j) = CMPLX( hj1j )\n wsp(ih+j*mh+j-1) = CMPLX( hj1j )\n call ZDSCAL( n, 1.0d0/hj1j, wsp(j1v),1 )\n j1v = j1v + n\n 200 continue\n nmult = nmult + 1\n call matvec(n, wsp(j1v-n), wsp(j1v) )\n avnorm = DZNRM2( n, wsp(j1v),1 )\n*\n*--- set 1's for the 3-extended scheme ...\n*\n 300 continue\n wsp(ih+mh*mbrkdwn) = ONE\n wsp(ih+m*mh+m-1) = ZERO\n wsp(ih+(m-1)*mh+m) = ZERO\n do i = 1,k1-1\n wsp(ih+(m+i)*mh+m+i-1) = ONE\n enddo\n*\n*--- loop while irejectnn(2)/2) j1 = j1 - nn(2)\n do i=1,nn(1)/2+1\n i1 = i-1\n if ((i==1).and.(j==1)) cycle\n if ((i==1).and.(j>nn(2)/2)) cycle\n lx=float(i1)/(rad1f)*(2.*pi)\n ly=float(j1)/(rad2f)*(2.*pi)\n labs=sqrt(lx*lx+ly*ly)\n c1=lx/labs\n s1=ly/labs\n c2=c1*c1-s1*s1\n s2=2*c1*s1\n \n call splint(x,y,y2,nin,labs,clk)\n \n elr=sqrt(clk/2.)*normsinv(dble(ran2(idum)))*sqrt(area)\n eli=sqrt(clk/2.)*normsinv(dble(ran2(idum)))*sqrt(area)\n \n blr=0.\n bli=0.\n \n ka(2*i-1,j) = elr\n ka(2*i,j) = eli\n g1(2*i-1,j) = c2*elr - s2*blr\n g1(2*i,j) = c2*eli - s2*bli\n g2(2*i-1,j) = s2*elr + c2*blr\n g2(2*i,j) = s2*eli + c2*bli \n \n if (((i1==0).or.(i1==nn(1)/2)).and.((j1==0).or.(j1==nn(2)/2))) then\n ka(2*i,j) = 0.\n g1(2*i,j) = 0.\n g2(2*i,j) = 0.\n endif\n \n ic = mod(nn(1)-i1,nn(1))+1\n jc = mod(nn(2)-j1,nn(2))+1\n ka(2*ic-1,jc) = ka(2*i-1,j)\n ka(2*ic,jc) = -ka(2*i,j)\n g1(2*ic-1,jc) = g1(2*i-1,j)\n g1(2*ic,jc) = -g1(2*i,j)\n g2(2*ic-1,jc) = g2(2*i-1,j)\n g2(2*ic,jc) = -g2(2*i,j) \n enddo\n enddo\n \n call fourn(ka,nn,2,1)\n call fourn(g1,nn,2,1)\n call fourn(g2,nn,2,1)\n \n allocate(kappa(ni,nj))\n \n do j=1,nj\n do i=1,ni\n kappa(i,j)=ka(2*i-1,j)/area\n enddo\n enddo\n deallocate(ka)\n \n allocate(shear(ni,nj))\n do j=1,nj\n do i=1,ni\n shear(i,j)=cmplx(g1(2*i-1,j),g2(2*i-1,j))/area\n enddo\n enddo\n deallocate(g1,g2)\n \n end subroutine makegashear\n\n subroutine shearassign(shear,pos,sdata)\n\n use fieldinfo_\n\n implicit none\n\n integer :: i,j,n\n real, pointer :: pos(:,:)\n complex, pointer :: shear(:,:),sdata(:)\n\n allocate(sdata(ntot))\n do n=1,ntot\n i=int(pos(n,1))+1\n j=int(pos(n,2))+1\n sdata(n)=shear(i,j)\n enddo\n\n end subroutine shearassign\n \nend program Gauss_shear_distribution\n", "meta": {"hexsha": "6d19a63278004e76480785f85d761556c68f8aa7", "size": 4181, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "sheardist.f90", "max_stars_repo_name": "chiaki-hikage/pseudoCl_flatsky", "max_stars_repo_head_hexsha": "9bcef43a78346d4062756f9798ec0cf66fd61e5f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "sheardist.f90", "max_issues_repo_name": "chiaki-hikage/pseudoCl_flatsky", "max_issues_repo_head_hexsha": "9bcef43a78346d4062756f9798ec0cf66fd61e5f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sheardist.f90", "max_forks_repo_name": "chiaki-hikage/pseudoCl_flatsky", "max_forks_repo_head_hexsha": "9bcef43a78346d4062756f9798ec0cf66fd61e5f", "max_forks_repo_licenses": ["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.0287356322, "max_line_length": 77, "alphanum_fraction": 0.5154269314, "num_tokens": 1606, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.900529778109184, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6950680585702186}} {"text": "! Ode solver\n!\n! Adapted from Numerical Recipes 77\n\nsubmodule (solver) solver_sm\n \n real(8), parameter :: pi = 4*atan(1.0d0)\n real(8), parameter :: two_pi = 2*pi\n real(8), allocatable, target :: xp_data(:), yp_data(:,:)\n real(8), allocatable, target :: x_error(:,:)\n \ncontains\n!\n! Cash-Karp - an adaptive Runge-Kutta method\n! see https://en.wikipedia.org/wiki/Cash%E2%80%93Karp_method\n module function rk_cash_karp(h,t,x,fp) result(xout)\n real(8), intent(in) :: h, t\n real(8), intent(in), contiguous :: x(:,:)\n procedure(f_p), pointer :: fp\n real(8) :: xout(size(x,1),size(x,2))\n real(8), dimension(size(x,1),size(x,2)) :: k1, k2, k3, k4, k5, k6\n real(8) :: a2,a3,a4,a5,a6,b21,b31,b32,b41,b42,b43,b51,b52,b53\n real(8) :: b54,b61,b62,b63,b64,b65,c1,c3,c4,c6,dc1,dc3,dc4,dc5,dc6\n \n parameter (a2=1/5.0d0, a3=3/10.0d0, a4=3/5.0d0, a5=1.0d0 ,a6=7/8.0d0, &\n b21=1/5.0d0, &\n b31=3/40.0d0, b32=9/40.0d0, &\n b41=.3, b42=-.9, b43=1.2, &\n b51=-11./54., b52=2.5, b53=-70./27., b54=35./27., &\n b61=1631./55296.,b62=175./512., b63=575./13824.,b64=44275./110592.,b65=253./4096., &\n c1=37./378., c3=250./621., c4=125./594., c6=512./1771., &\n dc1=c1-2825./27648., dc3=c3-18575./48384., dc4=c4-13525./55296., dc5=-277./14336., dc6=c6-.25)\n \n k1 = h*fp(t , x )\n k2 = h*fp(t + a2*h , x + b21*k1 )\n k3 = h*fp(t + a3*h , x + b31*k1 + b32*k2 )\n k4 = h*fp(t + a4*h , x + b41*k1 + b42*k2 + b43*k3 )\n k5 = h*fp(t + a5*h , x + b51*k1 + b52*k2 + b53*k3 + b54*k4 )\n k6 = h*fp(t + a6*h , x + b61*k1 + b62*k2 + b63*k3 + b64*k4 + b65*k5 )\n xout = x + c1*k1 + c3*k3 + c4*k4 + c6*k6\n x_error = dc1*k1 + dc3*k3 + dc4*k4 + dc5*k5 + dc6*k6\n end function rk_cash_karp\n\n module function rk_get_error() result(r)\n real(8), dimension(:,:), pointer :: r\n if (allocated(x_error)) then\n r => x_error\n else\n nullify(r)\n end if\n end function rk_get_error\n \n ! Explicit 4th order Runge-Kutta method\n module function rk_exp4(h,t,x,fp) result(xout)\n real(8), intent(in) :: h, t\n real(8), intent(in), contiguous :: x(:,:)\n procedure(f_p), pointer :: fp\n real(8) :: xout(size(x,1),size(x,2))\n real(8), dimension(size(x,1),size(x,2)) :: k1, k2, k3, k4\n k1 = h*fp(t , x )\n k2 = h*fp(t+h/2, x+k1/2)\n k3 = h*fp(t+h/2, x+k2/2)\n k4 = h*fp(t+h , x+k3 )\n xout = x + k1/6 + k2/3 + k3/3 + k4/6\n end function rk_exp4\n\n ! Explicit 4th order Runge-Kutta method - the 3/8 rule\n module function rk_exp38(h,t,x,fp) result(xout)\n real(8), intent(in) :: h, t\n real(8), intent(in), contiguous :: x(:,:)\n procedure(f_p), pointer :: fp\n real(8) :: xout(size(x,1),size(x,2))\n real(8), dimension(size(x,1),size(x,2)) :: k1, k2, k3, k4\n k1 = h*fp(t , x )\n k2 = h*fp(t+h/3 , x + k1/3)\n k3 = h*fp(t+2*h/3, x - k1/3 + k2)\n k4 = h*fp(t+h , x + k1 - k2 + k3 )\n xout = x + k1/8 + 3*k2/8 + 3*k3/8 + k4/8\n end function rk_exp38\n \n module subroutine four1(data,nn,isign)\n integer, intent(in) :: isign, nn\n real(8) :: data(2*nn)\n integer :: i,istep,j,m,mmax,n\n real(8) :: temp(2)\n real(8) :: theta,wi,wpi,wpr,wr,wtemp\n n = 2*nn\n j = 1\n do i=1,n,2\n if(j > i) then\n temp = data(j:j+1)\n data(j:j+1) = data(i:i+1)\n data(i:i+1) = temp\n endif\n m = n/2\n do\n if((m < 2) .or. (j <= m)) exit\n j = j-m\n m = m/2\n end do\n j = j+m\n end do\n \n mmax = 2\n do\n if (n <= mmax) exit\n istep = 2*mmax\n theta = two_pi/(isign*mmax)\n wpr = -2*sin(0.5d0*theta)**2\n wpi = sin(theta)\n wr = 1\n wi = 0\n do m=1,mmax,2\n do i=m,n,istep\n j=i+mmax\n temp = [wr*data(j)-wi*data(j+1), wr*data(j+1)+wi*data(j)]\n data(j:j+1) = data(i:i+1) - temp\n data(i:i+1) = data(i:i+1) + temp\n end do\n wtemp = wr\n wr = wr*wpr - wi*wpi+wr\n wi = wi*wpr + wtemp*wpi+wi\n end do\n mmax = istep\n end do\n return\n end subroutine four1\n!\n module subroutine realft(data, isign)\n integer, intent(in) :: isign\n real(8), intent(inout) :: data(:)\n \n integer :: i,i1,i2,i3,i4,n2p3, n\n real(8) :: c1,c2,h1i,h1r,h2i,h2r\n real(8) :: theta,wi,wpi,wpr,wr,wtemp\n \n n = size(data)\n theta = 2*pi/n\n c1 = 0.5\n if (isign == 1) then\n c2 = -0.5d0\n call four1(data,n/2,+1)\n else\n c2 = 0.5d0\n theta = -theta\n end if\n wpr = -2*sin(0.5d0*theta)**2\n wpi = sin(theta)\n wr = 1 + wpr\n wi = wpi\n n2p3 = n+3\n do i=2,n/4\n i1 = 2*i-1\n i2 = i1+1\n i3 = n2p3-i2\n i4 = i3+1\n h1r = c1*(data(i1)+data(i3))\n h1i = c1*(data(i2)-data(i4))\n h2r = -c2*(data(i2)+data(i4))\n h2i = c2*(data(i1)-data(i3))\n data(i1) = h1r+wr*h2r-wi*h2i\n data(i2) = h1i+wr*h2i+wi*h2r\n data(i3) = h1r-wr*h2r+wi*h2i\n data(i4) = -h1i+wr*h2i+wi*h2r\n wtemp = wr\n wr = wr*wpr-wi*wpi+wr\n wi = wi*wpr+wtemp*wpi+wi\n end do\n if (isign == 1) then\n h1r = data(1)\n data(1) = h1r+data(2)\n data(2) = h1r-data(2)\n else\n h1r = data(1)\n data(1) = c1*(h1r+data(2))\n data(2) = c1*(h1r-data(2))\n call four1(data,n/2,-1)\n end if\n return\n end subroutine realft\n\nend submodule solver_sm\n", "meta": {"hexsha": "0adb9e28d0f8f6caf30bd15d8b0ab1a331a817c7", "size": 6616, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "solver_sm.f90", "max_stars_repo_name": "sgeard/code", "max_stars_repo_head_hexsha": "af01cb95595dd1f8f787d14254d952a25cbaadea", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "solver_sm.f90", "max_issues_repo_name": "sgeard/code", "max_issues_repo_head_hexsha": "af01cb95595dd1f8f787d14254d952a25cbaadea", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "solver_sm.f90", "max_forks_repo_name": "sgeard/code", "max_forks_repo_head_hexsha": "af01cb95595dd1f8f787d14254d952a25cbaadea", "max_forks_repo_licenses": ["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.1530054645, "max_line_length": 113, "alphanum_fraction": 0.4168681983, "num_tokens": 2343, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297834483232, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6950680579650182}} {"text": " SUBROUTINE fit(x, y, n, a, b, r)\nC Compute the best fit line (y = a + bx) and its correlation to obs\nC Robert Grumbine 15 December 1994\n\n IMPLICIT none\n\n INTEGER n\n REAL x(n), y(n), corxy\n REAL a, b, r\n \n INTEGER i\n REAL sumxy, sumx, sumy, sumxx, sumyy\n REAL xm, ym\n \n sumx = 0.0\n sumy = 0.0\n sumxy = 0.0\n sumxx = 0.0\n sumyy = 0.0\n\n DO i = 1, n\n sumx = sumx + x(i)\n sumxx = sumxx + x(i)*x(i)\n sumxy = sumxy + x(i)*y(i)\n sumyy = sumyy + y(i)*y(i)\n sumy = sumy + y(i)\n ENDDO\n\n xm = sumx / FLOAT(n)\n ym = sumy / FLOAT(n)\n\n b = (sumxy-n*xm*ym)/(sumxx - n*xm*xm)\n a = ym - b*xm\n r = (sumxy-n*xm*ym)/SQRT(sumxx-n*xm*xm)/SQRT(sumyy-n*ym*ym)\n\n RETURN\n END\n", "meta": {"hexsha": "f91c5064dc0dd245e5ee9c58222e5b2e8b063e51", "size": 812, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "sorc/fit.f", "max_stars_repo_name": "rgrumbine/mmablib", "max_stars_repo_head_hexsha": "107ba1b1026c3cfed97346233c9a76d3d170d544", "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": "sorc/fit.f", "max_issues_repo_name": "rgrumbine/mmablib", "max_issues_repo_head_hexsha": "107ba1b1026c3cfed97346233c9a76d3d170d544", "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": "sorc/fit.f", "max_forks_repo_name": "rgrumbine/mmablib", "max_forks_repo_head_hexsha": "107ba1b1026c3cfed97346233c9a76d3d170d544", "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": 21.3684210526, "max_line_length": 71, "alphanum_fraction": 0.4716748768, "num_tokens": 317, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248242542284, "lm_q2_score": 0.7401743735019595, "lm_q1q2_score": 0.6950421109951611}} {"text": "!***********************************************************************************************************************************\n! UNIT:\n!\n! (MODULE)\n!\n! PURPOSE:\n!\n! TO\n!\n! DEFINITION OF VARIABLES:\n!\n!\n!\n! RECORD OF REVISIONS:\n!\n! DATE | PROGRAMMER | DESCRIPTION OF CHANGE\n! ==== | ========== | =====================\n! 20XX-XX-XX | DR. HYDE | ORIGINAL CODE.\n!\n!***********************************************************************************************************************************\n MODULE MR_MOD_FUNC_HKS\n\n USE MR_KINDS\n\n USE MR_DEF_CONSTS_N_REF_PARS\n\n IMPLICIT NONE\n\n PRIVATE\n\n PUBLIC :: MR_FUNC_HDKS\n PUBLIC :: MR_FUNC_HKS\n\n!***********************************************************************************************************************************\n\n CONTAINS\n\n!***********************************************************************************************************************************\n! UNIT:\n!\n! (SUBROUTINE)\n!\n! PURPOSE:\n!\n! TO\n!\n! DEFINITION OF VARIABLES:\n!\n!\n!\n! RECORD OF REVISIONS:\n!\n! DATE | PROGRAMMER | DESCRIPTION OF CHANGE\n! ==== | ========== | =====================\n! 20XX-XX-XX | DR. HYDE | ORIGINAL CODE.\n!\n!***********************************************************************************************************************************\n FUNCTION MR_FUNC_HDKS( DKS ) RESULT( HDKS )\n\n !DIR$ ATTRIBUTES VECTOR : UNIFORM( DKS ) :: MR_FUNC_HDKS\n\n IMPLICIT NONE\n\n REAL(PARD_KIND) , INTENT(IN ) :: DKS\n\n REAL(FDRD_KIND) :: HDKS\n\n HDKS = 3.0 * ( DKS * DSPAR )\n\n END FUNCTION MR_FUNC_HDKS\n\n!***********************************************************************************************************************************\n! UNIT:\n!\n! (SUBROUTINE)\n!\n! PURPOSE:\n!\n! TO\n!\n! DEFINITION OF VARIABLES:\n!\n!\n!\n! RECORD OF REVISIONS:\n!\n! DATE | PROGRAMMER | DESCRIPTION OF CHANGE\n! ==== | ========== | =====================\n! 20XX-XX-XX | DR. HYDE | ORIGINAL CODE.\n!\n!***********************************************************************************************************************************\n FUNCTION MR_FUNC_HKS( DKS , TCRKS , H , TBFUV_MOD ) RESULT( HKS )\n\n !DIR$ ATTRIBUTES VECTOR : UNIFORM( DKS , TCRKS ) :: MR_FUNC_HKS\n\n IMPLICIT NONE\n\n REAL(PARD_KIND) , INTENT(IN ) :: DKS , TCRKS\n REAL(FDRD_KIND) , INTENT(IN ) :: H , TBFUV_MOD\n\n REAL(PARD_KIND) :: TRANS_STATE\n REAL(PARD_KIND) :: SDUNE , HDUNE\n\n REAL(FDRD_KIND) :: HKS\n\n TRANS_STATE = MIN( MAX( TBFUV_MOD / TCRKS - 1.0 , 0.0 ) , 25.0 )\n\n SDUNE = 0.015 * ( ( ( DKS * DSPAR ) / H )**0.3 ) * &\n & ( 1.0 - EXP( -0.5 * TRANS_STATE ) ) * ( 25.0 - TRANS_STATE )\n HDUNE = 7.3 * H * SDUNE\n\n HKS = MR_FUNC_HDKS( DKS ) + 1.1 * HDUNE * ( 1.0 - EXP( -25.0 * SDUNE ) )\n\n END FUNCTION MR_FUNC_HKS\n\n END MODULE MR_MOD_FUNC_HKS\n", "meta": {"hexsha": "a04e397a100c82eff0a8ff26f16789a6d47a2e5a", "size": 2968, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "__Sources/MR_MOD_FUNCS/MR_MOD_FUNC_HKS.f90", "max_stars_repo_name": "zht9947/Mr_Reds", "max_stars_repo_head_hexsha": "e9ce791e855aa6caa1213db9c0df63374529f586", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-06-07T08:48:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-24T01:04:15.000Z", "max_issues_repo_path": "__Sources/MR_MOD_FUNCS/MR_MOD_FUNC_HKS.f90", "max_issues_repo_name": "zht9947/Mr_Reds", "max_issues_repo_head_hexsha": "e9ce791e855aa6caa1213db9c0df63374529f586", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "__Sources/MR_MOD_FUNCS/MR_MOD_FUNC_HKS.f90", "max_forks_repo_name": "zht9947/Mr_Reds", "max_forks_repo_head_hexsha": "e9ce791e855aa6caa1213db9c0df63374529f586", "max_forks_repo_licenses": ["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.3675213675, "max_line_length": 132, "alphanum_fraction": 0.3551212938, "num_tokens": 726, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625107731764, "lm_q2_score": 0.7461389930307512, "lm_q1q2_score": 0.6950004998341931}} {"text": "c=======================================================================\nc\nc subroutine SCHUR \nc\nc Matrix Schur Decomposition\nc\nc If A is a complex square matrix of dimention n, then there exists \nc a unitary matrix Q such that\nc\nc Q'AQ = T = D + N\nc\nc where ' is the conjugate transpose, \nc T is an upper triangular matrix,\nc D = Diag(l1,...,lp) (the li are eigenvalues of A), \nc and N is strictly upper triangular matrix. \nc\nc Furthermore, Q can be chosen such that the eigenvalues li appear \nc in any order along the diagonal.\nc\nc-----------------------------------------------------------------------\n SUBROUTINE schur ( n, X, iwork, dwork, eigval, vpmat, info )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : matrix size integer\nc X : input matrix (n*n) double\nc\nc WORKSPACE \nc iwork : vector (n) integer\nc dwork : vector ( n*(n+6) ) double\nc\nc OUTPUT \nc eigval : eigenvalues (n) double\nc vpmat : eigenvectors (n*n) double\nc info : diagnostic argument integer\nc\nc CALL \nc YM : copy a vectorized matrix in a vectorized matrix\nc DGEES : Schur factorization (cf. LAPACK)\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\nc\nc arguments i/o\n INTEGER n, info\n DOUBLE PRECISION eigval(*), X(*), vpmat(n,*)\nc\nc workspaces\n INTEGER iwork(*)\n DOUBLE PRECISION dwork(*)\nc\nc local variables\n LOGICAL select\n INTEGER sdim, piw, pmat, pdw, pip, lwork, ilwork\n PARAMETER ( ilwork = 5 )\nc\nc external subroutines\n EXTERNAL YM, DGEES\nc\nc-----------------------------------------------------------------------\nc\nc initialisations \n info = 0\nc\nc lwork : size of workspace for DGEES \nc ( min 3*N , so ilwork = min 3 , more is best )\n lwork = n*ilwork\n sdim = 0\nc\nc pointers for integer work space : iwork\nc ---------------------------------------\n piw = 1\nc piw : pointer for DGEES who needs (n)\nc pinext = piw + n\nc pinext : pointer for the next iwork array\nc\nc Total size of iwork array ( n )\nc\nc pointers for double precision work space : work(nasmax,*)\nc ----------------------------------------------------------\n pmat = 1\nc pmat : pointer for work matrix so (n*n) more\n pdw = pmat + ( n*n ) \nc pdw : pointer for work matrix of DGEES so lwork=(n*5) more\n pip = pdw + lwork\nc pip : pointer for imaginary part vector so (n) more\nc pdnext = pip + n\nc pdnext : pointer of the next dwork array\nc\nc Total size of work array = ( n*(n + 6) )\nc\nc-----------------------------------------------------------------------\nc\nc saves matrix initial ( altered by DGEES )\n CALL YM ( n, n, X, dwork(pmat) )\nc\nc DGEES (cf. LAPACK)\nc DGEES computes for an N-by-N real nonsymmetric matrix A,\nc the eigenvalues, the real Schur form T, and, optionally, the\nc matrix of Schur vectors Z\n CALL DGEES( 'V', 'N', select, n, dwork(pmat), n,\n & sdim, eigval, dwork(pip), vpmat,\n & n, dwork(pdw), lwork, iwork(piw), info )\nc\n RETURN\n END\n\n", "meta": {"hexsha": "01e5363f160739228a8cd08e1ca911e094595048", "size": 3556, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/alglin/cmc/schur.f", "max_stars_repo_name": "alpgodev/numx", "max_stars_repo_head_hexsha": "d2d3a0713020e1b83b65d3a661c3801ea256aff9", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-07-25T20:28:58.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-10T18:52:08.000Z", "max_issues_repo_path": "src/math/alglin/cmc/schur.f", "max_issues_repo_name": "alpgodev/numx", "max_issues_repo_head_hexsha": "d2d3a0713020e1b83b65d3a661c3801ea256aff9", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/math/alglin/cmc/schur.f", "max_forks_repo_name": "alpgodev/numx", "max_forks_repo_head_hexsha": "d2d3a0713020e1b83b65d3a661c3801ea256aff9", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.623853211, "max_line_length": 72, "alphanum_fraction": 0.4625984252, "num_tokens": 919, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625031628428, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6950004994139551}} {"text": "module data_mod\n integer, parameter :: num_steps = 1024*1024*1024\n integer, parameter :: MIN_BLK = 1024*256 \n\n contains\n real*8 recursive function pi_comp(Nstart, Nfinish, step) result(sum)\n use omp_lib\n implicit none\n \n integer, intent(in) :: Nstart, Nfinish\n real*8 :: x, sum1, sum2, step\n integer :: i, iblk\n \n sum = 0.0\n \n if (Nfinish - Nstart < MIN_BLK) then\n do i = Nstart, Nfinish - 1 \n x = (i + 0.5) * step\n sum = sum + 4.0 / (1.0 + x * x)\n enddo\n else\n iblk = Nfinish - Nstart\n !$omp task shared(sum1)\n sum1 = pi_comp(Nstart, Nfinish - iblk/2, step)\n !$omp end task \n !$omp task shared(sum2)\n sum2 = pi_comp(Nfinish - iblk/2, Nfinish, step)\n !$omp end task \n !$omp taskwait\n sum = sum1 + sum2\n endif\n\n end function \n\nend module data_mod\n\nprogram main\n use omp_lib\n use data_mod\n implicit none\n\n integer :: i\n real*8 :: pi, sum, step\n\n step = 1.0 / num_steps\n\n !$omp parallel\n !$omp single\n sum = pi_comp(0, num_steps, step);\n !$omp end single\n !$omp end parallel\n\n pi = step * sum\n\n WRITE(*,100) pi, num_steps\n100 FORMAT('pi = ', f15.8, ',', i14, ' steps')\n\nend program main \n", "meta": {"hexsha": "1dfe0c4590c9e0bea35462d165c380e3ba30719a", "size": 1390, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Book/Fortran/Fig_7.15_parPiDivCon.f90", "max_stars_repo_name": "zafar-hussain/OmpCommonCore", "max_stars_repo_head_hexsha": "e5457dcc6849f921e92ae3054486be56e39e6ebf", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 37, "max_stars_repo_stars_event_min_datetime": "2020-04-21T18:05:37.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:10:18.000Z", "max_issues_repo_path": "Book/Fortran/Fig_7.15_parPiDivCon.f90", "max_issues_repo_name": "zafar-hussain/OmpCommonCore", "max_issues_repo_head_hexsha": "e5457dcc6849f921e92ae3054486be56e39e6ebf", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-12-09T19:42:54.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T21:27:04.000Z", "max_forks_repo_path": "Book/Fortran/Fig_7.15_parPiDivCon.f90", "max_forks_repo_name": "zafar-hussain/OmpCommonCore", "max_forks_repo_head_hexsha": "e5457dcc6849f921e92ae3054486be56e39e6ebf", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2020-09-05T18:54:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-23T02:19:12.000Z", "avg_line_length": 23.5593220339, "max_line_length": 74, "alphanum_fraction": 0.5107913669, "num_tokens": 403, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467738423874, "lm_q2_score": 0.7905303162021597, "lm_q1q2_score": 0.6949921771137311}} {"text": "module divergence_cpu\n use precision\n use dimen\ncontains\nsubroutine div0_cpu(div,u,v,w)\n\n !---------------------------------------------------------------------------\n ! declaration\n !---------------------------------------------------------------------------\n implicit none\n\n real(fp),dimension(nx,ny,nz2),intent(out) :: div\n real(fp),dimension(nx,ny,nz2),intent(in) :: u,v,w\n\n real(fp),dimension(nx,ny,nz2) :: dudx,dvdy,dwdz\n integer :: i,j,k\n\n !---------------------------------------------------------------------------\n ! main code\n !---------------------------------------------------------------------------\n\n call ddx_cpu(dudx,u,1)\n call ddy_cpu(dvdy,v,1)\n call ddz_w_cpu(dwdz,w)\n\n do k=2,nzb+1\n do j=1,ny\n do i=1,nx\n div(i,j,k) = dudx(i,j,k)+dvdy(i,j,k)+dwdz(i,j,k)\n end do\n end do\n end do\n\nend subroutine div0_cpu\n\nsubroutine divstress_uv_cpu(divt,tx,ty,tz)\n\n !---------------------------------------------------------------------------\n ! declaration\n !---------------------------------------------------------------------------\n implicit none\n\n real(fp),dimension(nx,ny,nz2),intent(out) :: divt\n real(fp),dimension(nx,ny,nz2),intent(in) :: tx,ty,tz\n\n real(fp),dimension(nx,ny,nz2) :: tdx,tdy,tdz\n integer :: i,j,k\n\n !---------------------------------------------------------------------------\n ! main code\n !---------------------------------------------------------------------------\n\n !---------------------------------------------------------------------------\n ! stress gradients\n\n call ddx_cpu(tdx,tx,1)\n call ddy_cpu(tdy,ty,1)\n call ddz_w_cpu(tdz,tz)\n\n !---------------------------------------------------------------------------\n ! stress divergence\n\n do k=2,nzb+1\n do j=1,ny\n do i=1,nx\n divt(i,j,k)=tdx(i,j,k)+ tdy(i,j,k)+ tdz(i,j,k)\n end do\n end do\n end do\n\nend subroutine divstress_uv_cpu\n\nsubroutine divstress_w_cpu(divt,tx,ty,tz)\n\n !---------------------------------------------------------------------------\n ! declaration\n !---------------------------------------------------------------------------\n implicit none\n\n real(fp),dimension(nx,ny,nz2),intent(out) :: divt\n real(fp),dimension(nx,ny,nz2),intent(in) :: tx,ty,tz\n\n real(fp),dimension(nx,ny,nz2) :: tdx,tdy,tdz\n integer :: i,j,k\n\n !---------------------------------------------------------------------------\n ! main code\n !---------------------------------------------------------------------------\n\n !---------------------------------------------------------------------------\n ! stress gradients\n\n call ddx_cpu(tdx,tx,1)\n call ddy_cpu(tdy,ty,1)\n call ddz_uv_cpu(tdz,tz)\n\n !---------------------------------------------------------------------------\n ! stress divergence\n\n do k=2,nzb+1\n do j=1,ny\n do i=1,nx\n divt(i,j,k)=tdx(i,j,k)+ tdy(i,j,k)+ tdz(i,j,k)\n end do\n end do\n end do\n\n !---------------------------------------------------------------------------\n ! at the wall we have to assume that tdz(tzz)=0.0. any better ideas?\n ! yes -> assymetric fdm ???? -> do we really care ) w(:,:,2)=0 anyway !!\n\n ! if (me==0) then\n ! divt(:,:,2)=tdx(:,:,2)+ tdy(:,:,2)\n ! end if\n\nend subroutine divstress_w_cpu\n\nsubroutine ddx_cpu(dfdx,f,flag)\n\n !---------------------------------------------------------------------------\n ! declaration\n !---------------------------------------------------------------------------\n\n implicit none\n include '../common/fftw3.f90'\n\n real*8,dimension(nx,ny,nz2),intent(out) :: dfdx\n real*8,dimension(nx,ny,nz2),intent(in) :: f\n integer,intent(in) :: flag\n\n integer*8 :: plan_forward,plan_backward\n real*8,dimension(nx,ny) :: f_2d\n double complex,dimension(nx/2+1,ny) :: f_hat,dfdx_hat\n\n integer :: i,j,k,ii,jj\n\n save plan_forward,plan_backward\n\n !---------------------------------------------------------------------------\n ! main code\n !---------------------------------------------------------------------------\n\n !---------------------------------------------------------------------------\n ! init\n\n if (flag==0) then\n\n call dfftw_plan_dft_r2c_2d(plan_forward,nx,ny,f_2d,f_hat,fftw_measure)\n call dfftw_plan_dft_c2r_2d(plan_backward,nx,ny,f_hat,f_2d,fftw_measure)\n\n !---------------------------------------------------------------------------\n ! compute\n\n elseif (flag==1) then\n\n do k=2,nzb+1\n ! forward fft --> f_hat\n call dfftw_execute_dft_r2c(plan_forward,f(:,:,k),f_hat)\n f_hat=f_hat*inxny\n ! derivate\n do j=1,ny\n jj=j-1\n if(jj>nint(ny/2.0)) jj=jj-ny\n do i=1,nx/2+1\n ii=i-1\n ! filter\n if ((ii==nint(nx/2.0)) .or. (abs(jj)>=nint(ny/2.0)))then\n dfdx_hat(i,j)=0.d0\n ! dfdx_hat\n else\n dfdx_hat(i,j)=dcmplx(dimag(f_hat(i,j))*(-1.d0),dreal(f_hat(i,j)))*ii\n end if\n end do\n end do\n ! backward fft --> dfdx\n call dfftw_execute_dft_c2r(plan_backward,dfdx_hat,dfdx(:,:,k))\n\n end do\n\n !---------------------------------------------------------------------------\n ! finalize\n\n elseif (flag==2) then\n\n call dfftw_destroy_plan(plan_forward)\n call dfftw_destroy_plan(plan_backward)\n\n endif\n\nend subroutine ddx_cpu\n\nsubroutine ddy_cpu(dfdy,f,flag)\n\n !---------------------------------------------------------------------------\n ! declaration\n !---------------------------------------------------------------------------\n\n implicit none\n include '../common/fftw3.f90'\n\n real*8,dimension(nx,ny,nz2),intent(out) :: dfdy\n real*8,dimension(nx,ny,nz2),intent(in) :: f\n integer, intent(in) :: flag\n\n integer*8 :: plan_forward,plan_backward\n real*8,dimension(nx,ny) :: f_2d\n double complex,dimension(nx/2+1,ny) :: f_hat,dfdy_hat\n \n integer :: i,j,k,ii,jj\n\n save plan_forward,plan_backward\n\n !---------------------------------------------------------------------------\n ! main code\n !---------------------------------------------------------------------------\n\n !---------------------------------------------------------------------------\n ! init\n\n if (flag==0) then\n\n call dfftw_plan_dft_r2c_2d(plan_forward,nx,ny,f_2d,f_hat,fftw_measure)\n call dfftw_plan_dft_c2r_2d(plan_backward,nx,ny,f_hat,f_2d,fftw_measure)\n\n !---------------------------------------------------------------------------\n ! compute\n\n elseif (flag==1) then\n\n do k=2,nzb+1\n ! forward fft --> f_hat\n call dfftw_execute_dft_r2c(plan_forward,f(:,:,k),f_hat)\n f_hat=f_hat*inxny\n ! derivate\n do j=1,ny\n jj=j-1\n if(jj>nint(ny/2.0)) jj=jj-ny\n jj=jj*l_r\n do i=1,nx/2+1\n ii=i-1\n ! filter\n if ((ii==nint(nx/2.0)) .or. (abs(jj)==nint(l_r*ny/2.0)))then\n dfdy_hat(i,j)=0.d0\n ! dfdx_hat\n else\n dfdy_hat(i,j)=dcmplx(dimag(f_hat(i,j))*(-1.d0),dreal(f_hat(i,j)))*jj\n end if\n end do\n end do\n ! backward fft --> dfdx\n call dfftw_execute_dft_c2r(plan_backward,dfdy_hat,dfdy(:,:,k))\n\n end do\n\n !---------------------------------------------------------------------------\n ! finalize\n\n elseif (flag==2) then\n\n call dfftw_destroy_plan(plan_forward)\n call dfftw_destroy_plan(plan_backward)\n\n endif\n\nend subroutine ddy_cpu\n\npure subroutine ddz_uv_cpu (dfdz,f)\n\n !---------------------------------------------------------------------------\n ! declaration\n !---------------------------------------------------------------------------\n\n implicit none\n\n real(fp),dimension(nx,ny,nz2),intent(out) :: dfdz\n real(fp),dimension(nx,ny,nz2),intent(in) :: f\n\n integer :: i,j,k\n\n !---------------------------------------------------------------------------\n ! main code\n !---------------------------------------------------------------------------\n\n do k=2,nzb+1\n do j=1,ny\n do i=1,nx\n dfdz(i,j,k)=(f(i,j,k)-f(i,j,k-1))*idz\n end do\n end do\n end do\n\nend subroutine ddz_uv_cpu\n\npure subroutine ddz_w_cpu (dfdz,f)\n\n !---------------------------------------------------------------------------\n ! declaration\n !---------------------------------------------------------------------------\n\n implicit none\n\n real(fp),dimension(nx,ny,nz2),intent(out) :: dfdz\n real(fp),dimension(nx,ny,nz2),intent(in) :: f\n\n integer :: i,j,k\n\n !---------------------------------------------------------------------------\n ! main code\n !---------------------------------------------------------------------------\n\n do k=2,nzb+1\n do j=1,ny\n do i=1,nx\n dfdz(i,j,k)=(f(i,j,k+1)-f(i,j,k))*idz\n end do\n end do\n end do\n\nend subroutine ddz_w_cpu\n\npure subroutine ddz_uv_cpu_corr (dfdz,k_corr)\n\n !---------------------------------------------------------------------------\n ! declaration\n !---------------------------------------------------------------------------\n\n implicit none\n\n real(fp),dimension(nx,ny,nz2),intent(inout):: dfdz\n integer,intent(in) :: k_corr\n\n real(fp) :: d_avg1\n\n integer :: i,j\n\n real(fp),parameter :: fr1 = 1.d0/dlog(3.d0)-1.d0\n\n !---------------------------------------------------------------------------\n ! main code\n !---------------------------------------------------------------------------\n\n d_avg1 = 0.d0\n\n do j=1,ny\n do i=1,nx\n d_avg1= d_avg1 + dfdz(i,j,k_corr)\n end do\n end do\n\n d_avg1 = d_avg1*inxny\n\n do j=1,ny\n do i=1,nx\n dfdz(i,j,k_corr)= dfdz(i,j,k_corr) + fr1*d_avg1\n end do\n end do\n\nend subroutine ddz_uv_cpu_corr\n\nend module divergence_cpu", "meta": {"hexsha": "651079120e8a5434725a80e06fe0b8a2a019f854", "size": 10388, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "unit_test/cpu_benchmark/div.f90", "max_stars_repo_name": "moulin1024/WIRELES2", "max_stars_repo_head_hexsha": "2fcd190531d24e4f98885824c7d78acb3f79b304", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-03-22T11:45:53.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-06T02:57:21.000Z", "max_issues_repo_path": "unit_test/cpu_benchmark/div.f90", "max_issues_repo_name": "moulin1024/WIRELES2", "max_issues_repo_head_hexsha": "2fcd190531d24e4f98885824c7d78acb3f79b304", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-11-08T09:01:36.000Z", "max_issues_repo_issues_event_max_datetime": "2020-11-08T09:01:36.000Z", "max_forks_repo_path": "unit_test/cpu_benchmark/div.f90", "max_forks_repo_name": "moulin1024/WIRELES2", "max_forks_repo_head_hexsha": "2fcd190531d24e4f98885824c7d78acb3f79b304", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-03-22T11:46:43.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-22T11:46:43.000Z", "avg_line_length": 28.8555555556, "max_line_length": 92, "alphanum_fraction": 0.3620523681, "num_tokens": 2419, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146761176671, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.6949921736090219}} {"text": "*\n************************************************************************\n*\n* File of the COMPLEX Level-3 BLAS.\n* ==========================================\n*\n* SUBROUTINE CGEMM ( TRANSA, TRANSB, M, N, K, ALPHA, A, LDA, B, LDB,\n* $ BETA, C, LDC )\n*\n* SUBROUTINE CSYMM ( SIDE, UPLO, M, N, ALPHA, A, LDA, B, LDB,\n* $ BETA, C, LDC )\n*\n* SUBROUTINE CHEMM ( SIDE, UPLO, M, N, ALPHA, A, LDA, B, LDB,\n* $ BETA, C, LDC )\n*\n* SUBROUTINE CSYRK ( UPLO, TRANS, N, K, ALPHA, A, LDA,\n* $ BETA, C, LDC )\n*\n* SUBROUTINE CHERK ( UPLO, TRANS, N, K, ALPHA, A, LDA,\n* $ BETA, C, LDC )\n*\n* SUBROUTINE CSYR2K( UPLO, TRANS, N, K, ALPHA, A, LDA, B, LDB,\n* $ BETA, C, LDC )\n*\n* SUBROUTINE CHER2K( UPLO, TRANS, N, K, ALPHA, A, LDA, B, LDB,\n* $ BETA, C, LDC )\n*\n* SUBROUTINE CTRMM ( SIDE, UPLO, TRANSA, DIAG, M, N, ALPHA, A, LDA,\n* $ B, LDB )\n*\n* SUBROUTINE CTRSM ( SIDE, UPLO, TRANSA, DIAG, M, N, ALPHA, A, LDA,\n* $ B, LDB )\n*\n* See:\n*\n* Dongarra J. J., Du Croz J. J., Duff I. and Hammarling S.\n* A set of Level 3 Basic Linear Algebra Subprograms. Technical\n* Memorandum No.88 (Revision 1), Mathematics and Computer Science\n* Division, Argonne National Laboratory, 9700 South Cass Avenue,\n* Argonne, Illinois 60439.\n*\n*\n************************************************************************\n*\n SUBROUTINE CGEMM ( TRANSA, TRANSB, M, N, K, ALPHA, A, LDA, B, LDB,\n $ BETA, C, LDC )\n* .. Scalar Arguments ..\n CHARACTER*1 TRANSA, TRANSB\n INTEGER M, N, K, LDA, LDB, LDC\n COMPLEX ALPHA, BETA\n* .. Array Arguments ..\n COMPLEX A( LDA, * ), B( LDB, * ), C( LDC, * )\n* ..\n*\n* Purpose\n* =======\n*\n* CGEMM performs one of the matrix-matrix operations\n*\n* C := alpha*op( A )*op( B ) + beta*C,\n*\n* where op( X ) is one of\n*\n* op( X ) = X or op( X ) = X' or op( X ) = conjg( X' ),\n*\n* alpha and beta are scalars, and A, B and C are matrices, with op( A )\n* an m by k matrix, op( B ) a k by n matrix and C an m by n matrix.\n*\n* Parameters\n* ==========\n*\n* TRANSA - CHARACTER*1.\n* On entry, TRANSA specifies the form of op( A ) to be used in\n* the matrix multiplication as follows:\n*\n* TRANSA = 'N' or 'n', op( A ) = A.\n*\n* TRANSA = 'T' or 't', op( A ) = A'.\n*\n* TRANSA = 'C' or 'c', op( A ) = conjg( A' ).\n*\n* Unchanged on exit.\n*\n* TRANSB - CHARACTER*1.\n* On entry, TRANSB specifies the form of op( B ) to be used in\n* the matrix multiplication as follows:\n*\n* TRANSB = 'N' or 'n', op( B ) = B.\n*\n* TRANSB = 'T' or 't', op( B ) = B'.\n*\n* TRANSB = 'C' or 'c', op( B ) = conjg( B' ).\n*\n* Unchanged on exit.\n*\n* M - INTEGER.\n* On entry, M specifies the number of rows of the matrix\n* op( A ) and of the matrix C. M must be at least zero.\n* Unchanged on exit.\n*\n* N - INTEGER.\n* On entry, N specifies the number of columns of the matrix\n* op( B ) and the number of columns of the matrix C. N must be\n* at least zero.\n* Unchanged on exit.\n*\n* K - INTEGER.\n* On entry, K specifies the number of columns of the matrix\n* op( A ) and the number of rows of the matrix op( B ). K must\n* be at least zero.\n* Unchanged on exit.\n*\n* ALPHA - COMPLEX .\n* On entry, ALPHA specifies the scalar alpha.\n* Unchanged on exit.\n*\n* A - COMPLEX array of DIMENSION ( LDA, ka ), where ka is\n* k when TRANSA = 'N' or 'n', and is m otherwise.\n* Before entry with TRANSA = 'N' or 'n', the leading m by k\n* part of the array A must contain the matrix A, otherwise\n* the leading k by m part of the array A must contain the\n* matrix A.\n* Unchanged on exit.\n*\n* LDA - INTEGER.\n* On entry, LDA specifies the first dimension of A as declared\n* in the calling (sub) program. When TRANSA = 'N' or 'n' then\n* LDA must be at least max( 1, m ), otherwise LDA must be at\n* least max( 1, k ).\n* Unchanged on exit.\n*\n* B - COMPLEX array of DIMENSION ( LDB, kb ), where kb is\n* n when TRANSB = 'N' or 'n', and is k otherwise.\n* Before entry with TRANSB = 'N' or 'n', the leading k by n\n* part of the array B must contain the matrix B, otherwise\n* the leading n by k part of the array B must contain the\n* matrix B.\n* Unchanged on exit.\n*\n* LDB - INTEGER.\n* On entry, LDB specifies the first dimension of B as declared\n* in the calling (sub) program. When TRANSB = 'N' or 'n' then\n* LDB must be at least max( 1, k ), otherwise LDB must be at\n* least max( 1, n ).\n* Unchanged on exit.\n*\n* BETA - COMPLEX .\n* On entry, BETA specifies the scalar beta. When BETA is\n* supplied as zero then C need not be set on input.\n* Unchanged on exit.\n*\n* C - COMPLEX array of DIMENSION ( LDC, n ).\n* Before entry, the leading m by n part of the array C must\n* contain the matrix C, except when beta is zero, in which\n* case C need not be set on entry.\n* On exit, the array C is overwritten by the m by n matrix\n* ( alpha*op( A )*op( B ) + beta*C ).\n*\n* LDC - INTEGER.\n* On entry, LDC specifies the first dimension of C as declared\n* in the calling (sub) program. LDC must be at least\n* max( 1, m ).\n* Unchanged on exit.\n*\n*\n* Level 3 Blas routine.\n*\n* -- Written on 8-February-1989.\n* Jack Dongarra, Argonne National Laboratory.\n* Iain Duff, AERE Harwell.\n* Jeremy Du Croz, Numerical Algorithms Group Ltd.\n* Sven Hammarling, Numerical Algorithms Group Ltd.\n*\n*\n* .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\n* .. External Subroutines ..\n EXTERNAL XERBLA\n* .. Intrinsic Functions ..\n INTRINSIC CONJG, MAX\n* .. Local Scalars ..\n LOGICAL CONJA, CONJB, NOTA, NOTB\n INTEGER I, INFO, J, L, NCOLA, NROWA, NROWB\n COMPLEX TEMP\n* .. Parameters ..\n COMPLEX ONE\n PARAMETER ( ONE = ( 1.0E+0, 0.0E+0 ) )\n COMPLEX ZERO\n PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) )\n* ..\n* .. Executable Statements ..\n*\n* Set NOTA and NOTB as true if A and B respectively are not\n* conjugated or transposed, set CONJA and CONJB as true if A and\n* B respectively are to be transposed but not conjugated and set\n* NROWA, NCOLA and NROWB as the number of rows and columns of A\n* and the number of rows of B respectively.\n*\n NOTA = LSAME( TRANSA, 'N' )\n NOTB = LSAME( TRANSB, 'N' )\n CONJA = LSAME( TRANSA, 'C' )\n CONJB = LSAME( TRANSB, 'C' )\n IF( NOTA )THEN\n NROWA = M\n NCOLA = K\n ELSE\n NROWA = K\n NCOLA = M\n END IF\n IF( NOTB )THEN\n NROWB = K\n ELSE\n NROWB = N\n END IF\n*\n* Test the input parameters.\n*\n INFO = 0\n IF( ( .NOT.NOTA ).AND.\n $ ( .NOT.CONJA ).AND.\n $ ( .NOT.LSAME( TRANSA, 'T' ) ) )THEN\n INFO = 1\n ELSE IF( ( .NOT.NOTB ).AND.\n $ ( .NOT.CONJB ).AND.\n $ ( .NOT.LSAME( TRANSB, 'T' ) ) )THEN\n INFO = 2\n ELSE IF( M .LT.0 )THEN\n INFO = 3\n ELSE IF( N .LT.0 )THEN\n INFO = 4\n ELSE IF( K .LT.0 )THEN\n INFO = 5\n ELSE IF( LDA.LT.MAX( 1, NROWA ) )THEN\n INFO = 8\n ELSE IF( LDB.LT.MAX( 1, NROWB ) )THEN\n INFO = 10\n ELSE IF( LDC.LT.MAX( 1, M ) )THEN\n INFO = 13\n END IF\n IF( INFO.NE.0 )THEN\n CALL XERBLA( 'CGEMM ', INFO )\n RETURN\n END IF\n*\n* Quick return if possible.\n*\n IF( ( M.EQ.0 ).OR.( N.EQ.0 ).OR.\n $ ( ( ( ALPHA.EQ.ZERO ).OR.( K.EQ.0 ) ).AND.( BETA.EQ.ONE ) ) )\n $ RETURN\n*\n* And when alpha.eq.zero.\n*\n IF( ALPHA.EQ.ZERO )THEN\n IF( BETA.EQ.ZERO )THEN\n DO 20, J = 1, N\n DO 10, I = 1, M\n C( I, J ) = ZERO\n 10 CONTINUE\n 20 CONTINUE\n ELSE\n DO 40, J = 1, N\n DO 30, I = 1, M\n C( I, J ) = BETA*C( I, J )\n 30 CONTINUE\n 40 CONTINUE\n END IF\n RETURN\n END IF\n*\n* Start the operations.\n*\n IF( NOTB )THEN\n IF( NOTA )THEN\n*\n* Form C := alpha*A*B + beta*C.\n*\n DO 90, J = 1, N\n IF( BETA.EQ.ZERO )THEN\n DO 50, I = 1, M\n C( I, J ) = ZERO\n 50 CONTINUE\n ELSE IF( BETA.NE.ONE )THEN\n DO 60, I = 1, M\n C( I, J ) = BETA*C( I, J )\n 60 CONTINUE\n END IF\n DO 80, L = 1, K\n IF( B( L, J ).NE.ZERO )THEN\n TEMP = ALPHA*B( L, J )\n DO 70, I = 1, M\n C( I, J ) = C( I, J ) + TEMP*A( I, L )\n 70 CONTINUE\n END IF\n 80 CONTINUE\n 90 CONTINUE\n ELSE IF( CONJA )THEN\n*\n* Form C := alpha*conjg( A' )*B + beta*C.\n*\n DO 120, J = 1, N\n DO 110, I = 1, M\n TEMP = ZERO\n DO 100, L = 1, K\n TEMP = TEMP + CONJG( A( L, I ) )*B( L, J )\n 100 CONTINUE\n IF( BETA.EQ.ZERO )THEN\n C( I, J ) = ALPHA*TEMP\n ELSE\n C( I, J ) = ALPHA*TEMP + BETA*C( I, J )\n END IF\n 110 CONTINUE\n 120 CONTINUE\n ELSE\n*\n* Form C := alpha*A'*B + beta*C\n*\n DO 150, J = 1, N\n DO 140, I = 1, M\n TEMP = ZERO\n DO 130, L = 1, K\n TEMP = TEMP + A( L, I )*B( L, J )\n 130 CONTINUE\n IF( BETA.EQ.ZERO )THEN\n C( I, J ) = ALPHA*TEMP\n ELSE\n C( I, J ) = ALPHA*TEMP + BETA*C( I, J )\n END IF\n 140 CONTINUE\n 150 CONTINUE\n END IF\n ELSE IF( NOTA )THEN\n IF( CONJB )THEN\n*\n* Form C := alpha*A*conjg( B' ) + beta*C.\n*\n DO 200, J = 1, N\n IF( BETA.EQ.ZERO )THEN\n DO 160, I = 1, M\n C( I, J ) = ZERO\n 160 CONTINUE\n ELSE IF( BETA.NE.ONE )THEN\n DO 170, I = 1, M\n C( I, J ) = BETA*C( I, J )\n 170 CONTINUE\n END IF\n DO 190, L = 1, K\n IF( B( J, L ).NE.ZERO )THEN\n TEMP = ALPHA*CONJG( B( J, L ) )\n DO 180, I = 1, M\n C( I, J ) = C( I, J ) + TEMP*A( I, L )\n 180 CONTINUE\n END IF\n 190 CONTINUE\n 200 CONTINUE\n ELSE\n*\n* Form C := alpha*A*B' + beta*C\n*\n DO 250, J = 1, N\n IF( BETA.EQ.ZERO )THEN\n DO 210, I = 1, M\n C( I, J ) = ZERO\n 210 CONTINUE\n ELSE IF( BETA.NE.ONE )THEN\n DO 220, I = 1, M\n C( I, J ) = BETA*C( I, J )\n 220 CONTINUE\n END IF\n DO 240, L = 1, K\n IF( B( J, L ).NE.ZERO )THEN\n TEMP = ALPHA*B( J, L )\n DO 230, I = 1, M\n C( I, J ) = C( I, J ) + TEMP*A( I, L )\n 230 CONTINUE\n END IF\n 240 CONTINUE\n 250 CONTINUE\n END IF\n ELSE IF( CONJA )THEN\n IF( CONJB )THEN\n*\n* Form C := alpha*conjg( A' )*conjg( B' ) + beta*C.\n*\n DO 280, J = 1, N\n DO 270, I = 1, M\n TEMP = ZERO\n DO 260, L = 1, K\n TEMP = TEMP + CONJG( A( L, I ) )*CONJG( B( J, L ) )\n 260 CONTINUE\n IF( BETA.EQ.ZERO )THEN\n C( I, J ) = ALPHA*TEMP\n ELSE\n C( I, J ) = ALPHA*TEMP + BETA*C( I, J )\n END IF\n 270 CONTINUE\n 280 CONTINUE\n ELSE\n*\n* Form C := alpha*conjg( A' )*B' + beta*C\n*\n DO 310, J = 1, N\n DO 300, I = 1, M\n TEMP = ZERO\n DO 290, L = 1, K\n TEMP = TEMP + CONJG( A( L, I ) )*B( J, L )\n 290 CONTINUE\n IF( BETA.EQ.ZERO )THEN\n C( I, J ) = ALPHA*TEMP\n ELSE\n C( I, J ) = ALPHA*TEMP + BETA*C( I, J )\n END IF\n 300 CONTINUE\n 310 CONTINUE\n END IF\n ELSE\n IF( CONJB )THEN\n*\n* Form C := alpha*A'*conjg( B' ) + beta*C\n*\n DO 340, J = 1, N\n DO 330, I = 1, M\n TEMP = ZERO\n DO 320, L = 1, K\n TEMP = TEMP + A( L, I )*CONJG( B( J, L ) )\n 320 CONTINUE\n IF( BETA.EQ.ZERO )THEN\n C( I, J ) = ALPHA*TEMP\n ELSE\n C( I, J ) = ALPHA*TEMP + BETA*C( I, J )\n END IF\n 330 CONTINUE\n 340 CONTINUE\n ELSE\n*\n* Form C := alpha*A'*B' + beta*C\n*\n DO 370, J = 1, N\n DO 360, I = 1, M\n TEMP = ZERO\n DO 350, L = 1, K\n TEMP = TEMP + A( L, I )*B( J, L )\n 350 CONTINUE\n IF( BETA.EQ.ZERO )THEN\n C( I, J ) = ALPHA*TEMP\n ELSE\n C( I, J ) = ALPHA*TEMP + BETA*C( I, J )\n END IF\n 360 CONTINUE\n 370 CONTINUE\n END IF\n END IF\n*\n RETURN\n*\n* End of CGEMM .\n*\n END\n", "meta": {"hexsha": "f5bc504d613b9df91bc06af5f3afdd374295c385", "size": 14784, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iris_mt_scratch/egbert_codes-20210121T193218Z-001/egbert_codes/EMTF/MMT/lapack/blas_src/cgemm.f", "max_stars_repo_name": "simpeg-research/iris-mt-scratch", "max_stars_repo_head_hexsha": "ea458f253071db513fd0731118a2a7452a725944", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "iris_mt_scratch/egbert_codes-20210121T193218Z-001/egbert_codes/EMTF/MMT/lapack/blas_src/cgemm.f", "max_issues_repo_name": "simpeg-research/iris-mt-scratch", "max_issues_repo_head_hexsha": "ea458f253071db513fd0731118a2a7452a725944", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 19, "max_issues_repo_issues_event_min_datetime": "2020-12-23T17:55:48.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-24T21:01:05.000Z", "max_forks_repo_path": "iris_mt_scratch/egbert_codes-20210121T193218Z-001/egbert_codes/EMTF/MMT/lapack/blas_src/cgemm.f", "max_forks_repo_name": "simpeg-research/iris-mt-scratch", "max_forks_repo_head_hexsha": "ea458f253071db513fd0731118a2a7452a725944", "max_forks_repo_licenses": ["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.2091503268, "max_line_length": 72, "alphanum_fraction": 0.410646645, "num_tokens": 4595, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148513, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6949886474464805}} {"text": "!!# MODULE <>\nMODULE FUN_xyTRIANGULATE\n!!## PURPOSE\n!! Triangulate the following shapes.\n!!\n!! * xyTRIANGULATE_Pg - returns a triangulation of a polygon.\n\n!!## DISCUSSION\n!!\n!! * xyTRIANGULATE_Pg\n!!\n!! Given a polygon with N (distinct) nodes, a triangulation consists of\n!! N-2 (distinct) triangles, with the property that each triangle is\n!! constructed from vertices of the polygon, and that every point in the\n!! polygon is contained in exactly one triangle, unless it lies on the\n!! boundary of two or more triangles, and that no point exterior to the\n!! polygon is contained in any triangle. In other words, a triangulation\n!! is a dissection of the area of the polygon into triangles.\n\n\n!!## COMMENTS\n!! This algorithm should be correct, but not efficient.\n\n\n!!## MODIFIED\n!! 09 November 2000\n\n!!## AUTHOR\n!! John Burkardt\n\n!!## REFERENCE\n!!\n!! de Berg, van Krevald, Overmars, Schwarzkopf,\n!! Computational Geometry,\n!! Second Edition,\n!! Springer, 2000, pages 46-49.\n!!\n\n!!## USAGE\n!\n! order_Tr = xyTRIANGULATE_Pg(N,Pg)\n!\n!! where is the input number of nodes of the polygon and\n!! Pg(1,1:N), Pg(2,1:N) are the counter-clockwise ordered\n!! x and y-coordinates of the polygon, starting with the\n!! left-lowest point.\n!!\n!! The output, are the N-2 triangles\n!! that make up the polygon.\n\n!!## EXTERNAL KINDS\nUSE KND_IntrinsicTypes ,ONLY: KIND_Rsp , KIND_Rdp !!((01-A-KND_IntrinsicTypes.f90))\n\n!!## EXTERNAL PARAMETERS\nUSE PAR_Constants_Rsp,ONLY: c_1_Rsp => c_1 , c_0_Rsp => c_0 !!((02-A-PAR_Constants_Rsp.f90))\nUSE PAR_Constants_Rdp,ONLY: c_1_Rdp => c_1 , c_0_Rdp => c_0 !!((02-A-PAR_Constants_Rdp.f90))\n\n!!## EXTERNAL PROCEDURES\nUSE FUN_xyDIRECTION ,ONLY: xyDIRECTION_PP !!((04-B-FUN_xyDIRECTION.f90))\nUSE FUN_xyANGLE ,ONLY: xyANGLE_UU !!((05-B-FUN_xyANGLE.f90))\nUSE FUN_xyROTATE ,ONLY: xyROTATE_Px !!((05-B-FUN_xyROTATE.f90))\nUSE FUN_xyTRANSLATE ,ONLY: xyTRANSLATE_Px !!((05-B-FUN_xyTRANSLATE.f90))\nUSE FUN_xyCOUNTERCLOCKWISE,ONLY: xyCOUNTERCLOCKWISE_Cn !!((06-B-FUN_xyCOUNTERCLOCKWISE.f90))\n\nUSE LIB_MeshQuality,ONLY: dtris2 !!((04-B-LIB_MeshQuality.f90))\n\n!!## DEFAULT IMPLICIT\nIMPLICIT NONE\n\n!!## DEFAULT ACCESS\nPRIVATE\n\n!!## PROCEDURE OVERLOADING\nINTERFACE xyTRIANGULATE_Pg\n MODULE PROCEDURE xyTRIANGULATE_Pg_Rsp\n MODULE PROCEDURE xyTRIANGULATE_Pg_Rdp\n MODULE PROCEDURE xyTRIANGULATE2_Pg_Rsp\n MODULE PROCEDURE xyTRIANGULATE2_Pg_Rdp\nEND INTERFACE\nINTERFACE D_SWAP\n MODULE PROCEDURE D_SWAP_Rsp\n MODULE PROCEDURE D_SWAP_Rdp\nEND INTERFACE\nINTERFACE ENORM0_2D\n MODULE PROCEDURE ENORM0_2D_Rsp\n MODULE PROCEDURE ENORM0_2D_Rdp\nEND INTERFACE\nINTERFACE ENORMSQ0_2D\n MODULE PROCEDURE ENORMSQ0_2D_Rsp\n MODULE PROCEDURE ENORMSQ0_2D_Rdp\nEND INTERFACE\nINTERFACE DMAT_SOLVE\n MODULE PROCEDURE DMAT_SOLVE_Rsp\n MODULE PROCEDURE DMAT_SOLVE_Rdp\nEND INTERFACE\nINTERFACE LINE_EXP_POINT_DIST_2D\n MODULE PROCEDURE LINE_EXP_POINT_DIST_2D_Rsp\n MODULE PROCEDURE LINE_EXP_POINT_DIST_2D_Rdp\nEND INTERFACE\nINTERFACE TRIANGLE_CONTAINS_POINT_2D\n MODULE PROCEDURE TRIANGLE_CONTAINS_POINT_2D_Rsp\n MODULE PROCEDURE TRIANGLE_CONTAINS_POINT_2D_Rdp\nEND INTERFACE\nINTERFACE POLY_REORDER_NODES\n MODULE PROCEDURE POLY_REORDER_NODES_Rsp\n MODULE PROCEDURE POLY_REORDER_NODES_Rdp\nEND INTERFACE\n\n!!## PUBLIC ACCESS LIST\nPUBLIC :: xyTRIANGULATE_Pg\nPUBLIC :: xyTRIANGULATE_Pg_Rsp\nPUBLIC :: xyTRIANGULATE_Pg_Rdp\n\n!!## MODULE PROCEDURES\nCONTAINS\n\n\n!!### FUNCTION: xyTRIANGULATE2_Pg_Rsp\nFUNCTION xyTRIANGULATE2_Pg_Rsp( N , Pg , P_centroid ) RESULT(order_Tr)\n!!#### LOCAL KINDS\nINTEGER ,PARAMETER :: KIND_R = KIND_Rsp\nINCLUDE \"07-B-FUN_xyTRIANGULATE2_Pg.f90.hdr\"\n!!--begin--\nINCLUDE \"07-B-FUN_xyTRIANGULATE2_Pg.f90.bdy\"\n!!--end--\nEND FUNCTION\n\n\n!!### FUNCTION: xyTRIANGULATE2_Pg_Rdp\nFUNCTION xyTRIANGULATE2_Pg_Rdp( N , Pg , P_centroid ) RESULT(order_Tr)\n!!#### LOCAL KINDS\nINTEGER ,PARAMETER :: KIND_R = KIND_Rdp\nINCLUDE \"07-B-FUN_xyTRIANGULATE2_Pg.f90.hdr\"\n!!--begin--\nINCLUDE \"07-B-FUN_xyTRIANGULATE2_Pg.f90.bdy\"\n!!--end--\nEND FUNCTION\n\n\n\n!!### FUNCTION: xyTRIANGULATE_Pg_Rsp\nFUNCTION xyTRIANGULATE_Pg_Rsp( N , Pg ) RESULT(order_Tr)\n!!#### LOCAL KINDS\nINTEGER ,PARAMETER :: KIND_R = KIND_Rsp\n!!#### LOCAL PARAMETERS\nREAL(KIND_R),PARAMETER :: c_1 = c_1_Rsp\nREAL(KIND_R),PARAMETER :: c_0 = c_0_Rsp\nINCLUDE \"07-B-FUN_xyTRIANGULATE_Pg.f90.hdr\"\n!!--begin--\nINCLUDE \"07-B-FUN_xyTRIANGULATE_Pg.f90.bdy\"\n!!--end--\nEND FUNCTION\n\n\n!!### FUNCTION: xyTRIANGULATE_Pg_Rdp\nFUNCTION xyTRIANGULATE_Pg_Rdp( N , Pg ) RESULT(order_Tr)\n!!#### LOCAL KINDS\nINTEGER ,PARAMETER :: KIND_R = KIND_Rdp\n!!#### LOCAL PARAMETERS\nREAL(KIND_R),PARAMETER :: c_1 = c_1_Rdp\nREAL(KIND_R),PARAMETER :: c_0 = c_0_Rdp\nINCLUDE \"07-B-FUN_xyTRIANGULATE_Pg.f90.hdr\"\n!!--begin--\nINCLUDE \"07-B-FUN_xyTRIANGULATE_Pg.f90.bdy\"\n!!--end--\nEND FUNCTION\n\n\nsubroutine ivec_indicator ( n, a )\n\n!*******************************************************************************\n!\n!! IVEC_INDICATOR sets an integer vector to the vector A(I)=I.\n!\n! Modified:\n!\n! 09 November 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of elements of A.\n!\n! Output, integer A(N), the array to be initialized.\n!\n implicit none\n\n integer n\n\n integer a(n)\n integer i\n\n do i = 1, n\n a(i) = i\n end do\n\n return\nend subroutine\n\nsubroutine ivec_push ( n, x, stack1_max, stack1_num, stack1, stack2_max, &\n stack2_num, stack2 )\n\n!*******************************************************************************\n!\n!! IVEC_PUSH pushes an integer vector onto a stack.\n!\n! Discussion:\n!\n! STACK1 contains a list of the dimensions of the objects stored.\n! Therefore, STACK1_MAX should be at least as big as the maximum number\n! of objects to be considered.\n!\n! STACK2 contains the values of the objects. Therefore, STACK2_MAX\n! should probably be as big as the maximum total length of the maximum\n! number of objects stored.\n!\n! On first call, the USEr should have set STACK1_NUM and STACK2_NUM to zero.\n!\n! Modified:\n!\n! 09 November 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the dimension of the vector. N may be zero.\n!\n! Input, integer X(N), the value of the vector.\n!\n! Input, integer STACK1_MAX, the maximum size of STACK1.\n!\n! Input/output, integer STACK1_NUM, the current size of STACK1.\n!\n! Input/output, integer STACK1(STACK1_MAX), the vector dimension stack.\n!\n! Input, integer STACK2_MAX, the maximum size of STACK2.\n!\n! Input/output, integer STACK2_NUM, the current size of STACK2.\n!\n! Input/output, integer STACK2(STACK2_MAX), the vector value stack.\n!\n implicit none\n\n integer n\n integer stack1_max\n integer stack2_max\n\n integer stack1(stack1_max)\n integer stack1_num\n integer stack2(stack2_max)\n integer stack2_num\n integer x(n)\n\n if ( n < 0 ) then\n write ( *, * ) ' '\n write ( *, * ) 'IVEC_PUSH - Fatal error!'\n write ( *, * ) ' Input dimension N is negative.'\n stop\n end if\n\n if ( stack1_max < stack1_num + 1 ) then\n write ( *, * ) ' '\n write ( *, * ) 'IVEC_PUSH - Fatal error!'\n write ( *, * ) ' Exceeding size of stack #1.'\n stop\n end if\n\n if ( stack2_max < stack2_num + n ) then\n write ( *, * ) ' '\n write ( *, * ) 'IVEC_PUSH - Fatal error!'\n write ( *, * ) ' Exceeding size of stack #2.'\n stop\n end if\n\n stack1_num = stack1_num + 1\n stack1(stack1_num) = n\n\n stack2(stack2_num+1:stack2_num+n) = x(1:n)\n stack2_num = stack2_num + n\n\nend subroutine\n\n\nsubroutine ivec_pop ( n, x, stack1_max, stack1_num, stack1, stack2_max, &\n stack2_num, stack2 )\n\n!*******************************************************************************\n!\n!! IVEC_POP pops an integer vector off of a stack.\n!\n! Discussion:\n!\n! If there are no more objects in the stack, N is returned as -1.\n!\n! Modified:\n!\n! 09 November 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Output, integer N, the dimension of the vector.\n!\n! Output, integer X(*), the value of the vector.\n!\n! Input, integer STACK1_MAX, the maximum size of STACK1.\n!\n! Input/output, integer STACK1_NUM, the current size of STACK1.\n!\n! Input/output, integer STACK1(STACK1_MAX), the vector dimension stack.\n!\n! Input, integer STACK2_MAX, the maximum size of STACK2.\n!\n! Input/output, integer STACK2_NUM, the current size of STACK2.\n!\n! Input/output, integer STACK2(STACK2_MAX), the vector value stack.\n!\n implicit none\n\n integer n\n integer stack1_max\n integer stack2_max\n\n integer stack1(stack1_max)\n integer stack1_num\n integer stack2(stack2_max)\n integer stack2_num\n integer x(*)\n\n if ( stack1_num < 1 ) then\n n = -1\n return\n end if\n\n n = stack1(stack1_num)\n stack1_num = stack1_num - 1\n\n stack2_num = stack2_num - n\n x(1:n) = stack2(stack2_num+1:stack2_num+n)\n\nend subroutine\n\nsubroutine d_swap_Rsp ( x, y )\n\n!*******************************************************************************\n!\n!! D_SWAP swaps two real values.\n!\n! Modified:\n!\n! 01 May 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input/output, real ( kind = 8 ) X, Y. On output, the values of X and\n! Y have been interchanged.\n!\n implicit none\n\n real ( kind = KIND_Rsp ) x\n real ( kind = KIND_Rsp ) y\n real ( kind = KIND_Rsp ) z\n\n z = x\n x = y\n y = z\n\nend subroutine\n\n\nfunction enorm0_2d_Rsp ( x0, y0, x1, y1 ) RESULT(enorm0_2D)\n\n!*******************************************************************************\n!\n!! ENORM0_2D computes the Euclidean norm of (P1-P0) in 2D.\n!\n! Modified:\n!\n! 16 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = KIND_R ) X0, Y0, X1, Y1, the coordinates of the points P0 and P1.\n!\n! Output, real ( kind = KIND_R ) ENORM0_2D, the Euclidean norm of (P1-P0).\n!\n implicit none\n\n real ( kind = KIND_Rsp ) enorm0_2d\n real ( kind = KIND_Rsp ) x0\n real ( kind = KIND_Rsp ) x1\n real ( kind = KIND_Rsp ) y0\n real ( kind = KIND_Rsp ) y1\n\n enorm0_2d = sqrt ( ( x1 - x0 )**2 + ( y1 - y0 )**2 )\n\nend function\n\nfunction enormsq0_2d_Rsp ( x0, y0, x1, y1 ) RESULT(enormsq0_2d)\n\n!*******************************************************************************\n!\n!! ENORMSQ0_2D computes the square of the Euclidean norm of (P1-P0) in 2D.\n!\n! Modified:\n!\n! 06 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = KIND_R ) X0, Y0, X1, Y1, the coordinates of the points\n! P0 and P1.\n!\n! Output, real ( kind = KIND_R ) ENORMSQ0_2D, the square of the Euclidean norm of (P1-P0).\n!\n implicit none\n\n real ( kind = KIND_Rsp ) enormsq0_2d\n real ( kind = KIND_Rsp ) x0\n real ( kind = KIND_Rsp ) x1\n real ( kind = KIND_Rsp ) y0\n real ( kind = KIND_Rsp ) y1\n\n enormsq0_2d = ( x1 - x0 )**2 + ( y1 - y0 )**2\n\nend function\n\n\n\nsubroutine poly_reorder_nodes_Rsp ( nxy, x, y, npoly, poly )\n\n!*******************************************************************************\n!\n!! POLY_REORDER_NODES reorders nodes of a polygon so node 1 is leftest lowest.\n!\n! Modified:\n!\n! 12 November 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer NXY, the number of nodes.\n!\n! Input, real ( kind = KIND_R ) X(NXY), Y(NXY), the coordinates of the nodes.\n!\n! Input, integer NPOLY, the number of nodes of the polygon.\n!\n! Input/output, POLY(NPOLY), the indices of the nodes.\n!\n implicit none\n\n integer npoly\n integer nxy\n\n integer i\n integer imin\n integer p\n integer pmin\n integer poly(npoly)\n integer poly2(npoly)\n real ( kind = KIND_Rsp ) x(nxy)\n real ( kind = KIND_Rsp ) y(nxy)\n\n imin = 1\n pmin = poly(imin)\n\n do i = 2, npoly\n p = poly(i)\n if ( &\n ( x(p) < x(pmin) ) .or. &\n ( x(p) == x(pmin) .and. y(p) < y(pmin) ) ) then\n imin = i\n pmin = p\n end if\n end do\n\n if ( imin /= 1 ) then\n\n poly2(1:npoly+1-imin) = poly(imin:npoly)\n poly2(npoly+2-imin:npoly) = poly(1:imin-1)\n\n poly(1:npoly) = poly2(1:npoly)\n\n end if\n\nend subroutine\n\nsubroutine triangle_contains_point_2d_Rsp ( x1, y1, x2, y2, x3, y3, x, y, inside )\n\n!*******************************************************************************\n!\n!! TRIANGLE_CONTAINS_POINT_2D finds if a point is inside a triangle in 2D.\n!\n! Modified:\n!\n! 12 November 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = KIND_Rsp ) X1, Y1, X2, Y2, X3, Y3, the coordinates of\n! the corners of the triangle.\n!\n! Input, real ( kind = KIND_Rsp ) X, Y, the point to be checked.\n!\n! Output, logical INSIDE, is .TRUE. if (X,Y) is inside\n! the triangle or on its boundary, and .FALSE. otherwise.\n!\n implicit none\n\n integer, parameter :: N = 2\n integer, parameter :: NRHS = 1\n\n real ( kind = KIND_Rsp ) a(N,N+NRHS)\n real ( kind = KIND_Rsp ) c1\n real ( kind = KIND_Rsp ) c2\n integer info\n logical inside\n real ( kind = KIND_Rsp ) x\n real ( kind = KIND_Rsp ) x1\n real ( kind = KIND_Rsp ) x2\n real ( kind = KIND_Rsp ) x3\n real ( kind = KIND_Rsp ) y\n real ( kind = KIND_Rsp ) y1\n real ( kind = KIND_Rsp ) y2\n real ( kind = KIND_Rsp ) y3\n!\n! Set up the linear system\n!\n! ( X2-X1 X3-X1 ) C1 = X-X1\n! ( Y2-Y1 Y3-Y1 ) C2 Y-Y1\n!\n! which is satisfied by the barycentric coordinates of (X,Y).\n!\n a(1,1) = x2 - x1\n a(1,2) = x3 - x1\n a(1,3) = x - x1\n\n a(2,1) = y2 - y1\n a(2,2) = y3 - y1\n a(2,3) = y - y1\n!\n! Solve the linear system.\n!\n call dmat_solve ( a, N, NRHS, info )\n\n if ( info /= 0 ) then\n write ( *, * ) ' '\n write ( *, * ) 'TRIANGLE_CONTAINS_POINT - Fatal error!'\n write ( *, * ) ' The linear system is singular.'\n write ( *, * ) ' The input data does not form a proper triangle.'\n stop\n end if\n\n c1 = a(1,3)\n c2 = a(2,3)\n!\n! If the point is in the triangle, its barycentric coordinates\n! must both be nonnegative, and sum to no more than 1.\n!\n if ( c1 < 0._KIND_Rsp .or. c2 < 0._KIND_Rsp ) then\n inside = .false.\n else if ( 1._KIND_Rsp < c1 + c2 ) then\n inside = .false.\n else\n inside = .true.\n end if\n\nend subroutine\n\nsubroutine line_exp_point_dist_2d_Rsp ( x1, y1, x2, y2, x, y, dist )\n\n!*******************************************************************************\n!\n!! LINE_EXP_POINT_DIST_2D: distance ( explicit line, point ) in 2D.\n!\n! Formula:\n!\n! The explicit form of a line in 2D is:\n!\n! (X1,Y1), (X2,Y2).\n!\n! Modified:\n!\n! 27 January 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = KIND_Rsp ) X1, Y1, X2, Y2. (X1,Y1) and (X2,Y2) are two\n! points on the line.\n!\n! Input, real ( kind = KIND_Rsp ) X, Y, the point whose distance from the line is\n! to be measured.\n!\n! Output, real ( kind = KIND_Rsp ) DIST, the distance from the point to the line.\n!\n implicit none\n\n real ( kind = KIND_Rsp ) bot\n real ( kind = KIND_Rsp ) dist\n real ( kind = KIND_Rsp ) dot\n real ( kind = KIND_Rsp ) t\n real ( kind = KIND_Rsp ) x\n real ( kind = KIND_Rsp ) xn\n real ( kind = KIND_Rsp ) x1\n real ( kind = KIND_Rsp ) x2\n real ( kind = KIND_Rsp ) y\n real ( kind = KIND_Rsp ) yn\n real ( kind = KIND_Rsp ) y1\n real ( kind = KIND_Rsp ) y2\n\n bot = enormsq0_2d ( x1, y1, x2, y2 )\n\n if ( bot == 0._KIND_Rsp ) then\n\n xn = x1\n yn = y1\n!\n! (P-P1) dot (P2-P1) = Norm(P-P1) * Norm(P2-P1) * Cos(Theta).\n!\n! (P-P1) dot (P2-P1) / Norm(P-P1)**2 = normalized coordinate T\n! of the projection of (P-P1) onto (P2-P1).\n!\n else\n\n dot = ( x - x1 ) * ( x2 - x1 ) + ( y - y1 ) * ( y2 - y1 )\n\n t = dot / bot\n\n xn = x1 + t * ( x2 - x1 )\n yn = y1 + t * ( y2 - y1 )\n\n end if\n\n dist = enorm0_2d ( xn, yn, x, y )\n\nend subroutine\n\n\nsubroutine dmat_solve_Rsp ( a, n, nrhs, info )\n\n!*******************************************************************************\n!\n!! DMAT_SOLVE USEs Gauss-Jordan elimination to solve an N by N linear system.\n!\n! Modified:\n!\n! 08 November 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input/output, real ( kind = KIND_Rsp ) A(N,N+NRHS), contains in rows and columns 1\n! to N the coefficient matrix, and in columns N+1 through\n! N+NRHS, the right hand sides. On output, the coefficient matrix\n! area has been destroyed, while the right hand sides have\n! been overwritten with the corresponding solutions.\n!\n! Input, integer NRHS, the number of right hand sides. NRHS\n! must be at least 0.\n!\n! Output, integer INFO, singularity flag.\n! 0, the matrix was not singular, the solutions were computed;\n! J, factorization failed on step J, and the solutions could not\n! be computed.\n!\n implicit none\n\n integer n\n integer nrhs\n\n real ( kind = KIND_Rsp ) a(n,n+nrhs)\n real ( kind = KIND_Rsp ) apivot\n real ( kind = KIND_Rsp ) factor\n integer i\n integer info\n integer ipivot\n integer j\n\n info = 0\n\n do j = 1, n\n!\n! Choose a pivot row.\n!\n ipivot = j\n apivot = a(j,j)\n\n do i = j+1, n\n if ( abs ( apivot ) < abs ( a(i,j) ) ) then\n apivot = a(i,j)\n ipivot = i\n end if\n end do\n\n if ( apivot == 0._KIND_Rsp ) then\n info = j\n return\n end if\n!\n! Interchange.\n!\n do i = 1, n + nrhs\n call d_swap ( a(ipivot,i), a(j,i) )\n end do\n!\n! A(J,J) becomes 1.\n!\n a(j,j) = 1._KIND_Rsp\n a(j,j+1:n+nrhs) = a(j,j+1:n+nrhs) / apivot\n!\n! A(I,J) becomes 0.\n!\n do i = 1, n\n\n if ( i /= j ) then\n\n factor = a(i,j)\n a(i,j) = 0._KIND_Rsp\n a(i,j+1:n+nrhs) = a(i,j+1:n+nrhs) - factor * a(j,j+1:n+nrhs)\n\n end if\n\n end do\n\n end do\n\nend subroutine\n\n\n\nsubroutine d_swap_Rdp ( x, y )\n\n!*******************************************************************************\n!\n!! D_SWAP swaps two real values.\n!\n! Modified:\n!\n! 01 May 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input/output, real ( kind = 8 ) X, Y. On output, the values of X and\n! Y have been interchanged.\n!\n implicit none\n\n real ( kind = KIND_Rdp ) x\n real ( kind = KIND_Rdp ) y\n real ( kind = KIND_Rdp ) z\n\n z = x\n x = y\n y = z\n\nend subroutine\n\n\nfunction enorm0_2d_Rdp ( x0, y0, x1, y1 ) RESULT(enorm0_2d)\n\n!*******************************************************************************\n!\n!! ENORM0_2D computes the Euclidean norm of (P1-P0) in 2D.\n!\n! Modified:\n!\n! 16 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = KIND_R ) X0, Y0, X1, Y1, the coordinates of the points P0 and P1.\n!\n! Output, real ( kind = KIND_R ) ENORM0_2D, the Euclidean norm of (P1-P0).\n!\n implicit none\n\n real ( kind = KIND_Rdp ) enorm0_2d\n real ( kind = KIND_Rdp ) x0\n real ( kind = KIND_Rdp ) x1\n real ( kind = KIND_Rdp ) y0\n real ( kind = KIND_Rdp ) y1\n\n enorm0_2d = sqrt ( ( x1 - x0 )**2 + ( y1 - y0 )**2 )\n\nend function\n\nfunction enormsq0_2d_Rdp ( x0, y0, x1, y1 ) RESULT(enormsq0_2d)\n\n!*******************************************************************************\n!\n!! ENORMSQ0_2D computes the square of the Euclidean norm of (P1-P0) in 2D.\n!\n! Modified:\n!\n! 06 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = KIND_R ) X0, Y0, X1, Y1, the coordinates of the points\n! P0 and P1.\n!\n! Output, real ( kind = KIND_R ) ENORMSQ0_2D, the square of the Euclidean norm of (P1-P0).\n!\n implicit none\n\n real ( kind = KIND_Rdp ) enormsq0_2d\n real ( kind = KIND_Rdp ) x0\n real ( kind = KIND_Rdp ) x1\n real ( kind = KIND_Rdp ) y0\n real ( kind = KIND_Rdp ) y1\n\n enormsq0_2d = ( x1 - x0 )**2 + ( y1 - y0 )**2\n\nend function\n\n\n\nsubroutine poly_reorder_nodes_Rdp ( nxy, x, y, npoly, poly )\n\n!*******************************************************************************\n!\n!! POLY_REORDER_NODES reorders nodes of a polygon so node 1 is leftest lowest.\n!\n! Modified:\n!\n! 12 November 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer NXY, the number of nodes.\n!\n! Input, real ( kind = KIND_R ) X(NXY), Y(NXY), the coordinates of the nodes.\n!\n! Input, integer NPOLY, the number of nodes of the polygon.\n!\n! Input/output, POLY(NPOLY), the indices of the nodes.\n!\n implicit none\n\n integer npoly\n integer nxy\n\n integer i\n integer imin\n integer p\n integer pmin\n integer poly(npoly)\n integer poly2(npoly)\n real ( kind = KIND_Rdp ) x(nxy)\n real ( kind = KIND_Rdp ) y(nxy)\n\n imin = 1\n pmin = poly(imin)\n\n do i = 2, npoly\n p = poly(i)\n if ( &\n ( x(p) < x(pmin) ) .or. &\n ( x(p) == x(pmin) .and. y(p) < y(pmin) ) ) then\n imin = i\n pmin = p\n end if\n end do\n\n if ( imin /= 1 ) then\n\n poly2(1:npoly+1-imin) = poly(imin:npoly)\n poly2(npoly+2-imin:npoly) = poly(1:imin-1)\n\n poly(1:npoly) = poly2(1:npoly)\n\n end if\n\nend subroutine\n\nsubroutine triangle_contains_point_2d_Rdp ( x1, y1, x2, y2, x3, y3, x, y, inside )\n\n!*******************************************************************************\n!\n!! TRIANGLE_CONTAINS_POINT_2D finds if a point is inside a triangle in 2D.\n!\n! Modified:\n!\n! 12 November 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = KIND_Rdp ) X1, Y1, X2, Y2, X3, Y3, the coordinates of\n! the corners of the triangle.\n!\n! Input, real ( kind = KIND_Rdp ) X, Y, the point to be checked.\n!\n! Output, logical INSIDE, is .TRUE. if (X,Y) is inside\n! the triangle or on its boundary, and .FALSE. otherwise.\n!\n implicit none\n\n integer, parameter :: N = 2\n integer, parameter :: NRHS = 1\n\n real ( kind = KIND_Rdp ) a(N,N+NRHS)\n real ( kind = KIND_Rdp ) c1\n real ( kind = KIND_Rdp ) c2\n integer info\n logical inside\n real ( kind = KIND_Rdp ) x\n real ( kind = KIND_Rdp ) x1\n real ( kind = KIND_Rdp ) x2\n real ( kind = KIND_Rdp ) x3\n real ( kind = KIND_Rdp ) y\n real ( kind = KIND_Rdp ) y1\n real ( kind = KIND_Rdp ) y2\n real ( kind = KIND_Rdp ) y3\n!\n! Set up the linear system\n!\n! ( X2-X1 X3-X1 ) C1 = X-X1\n! ( Y2-Y1 Y3-Y1 ) C2 Y-Y1\n!\n! which is satisfied by the barycentric coordinates of (X,Y).\n!\n a(1,1) = x2 - x1\n a(1,2) = x3 - x1\n a(1,3) = x - x1\n\n a(2,1) = y2 - y1\n a(2,2) = y3 - y1\n a(2,3) = y - y1\n!\n! Solve the linear system.\n!\n call dmat_solve ( a, N, NRHS, info )\n\n if ( info /= 0 ) then\n write ( *, * ) ' '\n write ( *, * ) 'TRIANGLE_CONTAINS_POINT - Fatal error!'\n write ( *, * ) ' The linear system is singular.'\n write ( *, * ) ' The input data does not form a proper triangle.'\n stop\n end if\n\n c1 = a(1,3)\n c2 = a(2,3)\n!\n! If the point is in the triangle, its barycentric coordinates\n! must both be nonnegative, and sum to no more than 1.\n!\n if ( c1 < 0._KIND_Rdp .or. c2 < 0._KIND_Rdp ) then\n inside = .false.\n else if ( 1._KIND_Rdp < c1 + c2 ) then\n inside = .false.\n else\n inside = .true.\n end if\n\nend subroutine\n\nsubroutine line_exp_point_dist_2d_Rdp ( x1, y1, x2, y2, x, y, dist )\n\n!*******************************************************************************\n!\n!! LINE_EXP_POINT_DIST_2D: distance ( explicit line, point ) in 2D.\n!\n! Formula:\n!\n! The explicit form of a line in 2D is:\n!\n! (X1,Y1), (X2,Y2).\n!\n! Modified:\n!\n! 27 January 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = KIND_Rdp ) X1, Y1, X2, Y2. (X1,Y1) and (X2,Y2) are two\n! points on the line.\n!\n! Input, real ( kind = KIND_Rdp ) X, Y, the point whose distance from the line is\n! to be measured.\n!\n! Output, real ( kind = KIND_Rdp ) DIST, the distance from the point to the line.\n!\n implicit none\n\n real ( kind = KIND_Rdp ) bot\n real ( kind = KIND_Rdp ) dist\n real ( kind = KIND_Rdp ) dot\n real ( kind = KIND_Rdp ) t\n real ( kind = KIND_Rdp ) x\n real ( kind = KIND_Rdp ) xn\n real ( kind = KIND_Rdp ) x1\n real ( kind = KIND_Rdp ) x2\n real ( kind = KIND_Rdp ) y\n real ( kind = KIND_Rdp ) yn\n real ( kind = KIND_Rdp ) y1\n real ( kind = KIND_Rdp ) y2\n\n bot = enormsq0_2d ( x1, y1, x2, y2 )\n\n if ( bot == 0._KIND_Rdp ) then\n\n xn = x1\n yn = y1\n!\n! (P-P1) dot (P2-P1) = Norm(P-P1) * Norm(P2-P1) * Cos(Theta).\n!\n! (P-P1) dot (P2-P1) / Norm(P-P1)**2 = normalized coordinate T\n! of the projection of (P-P1) onto (P2-P1).\n!\n else\n\n dot = ( x - x1 ) * ( x2 - x1 ) + ( y - y1 ) * ( y2 - y1 )\n\n t = dot / bot\n\n xn = x1 + t * ( x2 - x1 )\n yn = y1 + t * ( y2 - y1 )\n\n end if\n\n dist = enorm0_2d ( xn, yn, x, y )\n\nend subroutine\n\n\nsubroutine dmat_solve_Rdp ( a, n, nrhs, info )\n\n!*******************************************************************************\n!\n!! DMAT_SOLVE USEs Gauss-Jordan elimination to solve an N by N linear system.\n!\n! Modified:\n!\n! 08 November 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input/output, real ( kind = KIND_Rdp ) A(N,N+NRHS), contains in rows and columns 1\n! to N the coefficient matrix, and in columns N+1 through\n! N+NRHS, the right hand sides. On output, the coefficient matrix\n! area has been destroyed, while the right hand sides have\n! been overwritten with the corresponding solutions.\n!\n! Input, integer NRHS, the number of right hand sides. NRHS\n! must be at least 0.\n!\n! Output, integer INFO, singularity flag.\n! 0, the matrix was not singular, the solutions were computed;\n! J, factorization failed on step J, and the solutions could not\n! be computed.\n!\n implicit none\n\n integer n\n integer nrhs\n\n real ( kind = KIND_Rdp ) a(n,n+nrhs)\n real ( kind = KIND_Rdp ) apivot\n real ( kind = KIND_Rdp ) factor\n integer i\n integer info\n integer ipivot\n integer j\n\n info = 0\n\n do j = 1, n\n!\n! Choose a pivot row.\n!\n ipivot = j\n apivot = a(j,j)\n\n do i = j+1, n\n if ( abs ( apivot ) < abs ( a(i,j) ) ) then\n apivot = a(i,j)\n ipivot = i\n end if\n end do\n\n if ( apivot == 0._KIND_Rdp ) then\n info = j\n return\n end if\n!\n! Interchange.\n!\n do i = 1, n + nrhs\n call d_swap ( a(ipivot,i), a(j,i) )\n end do\n!\n! A(J,J) becomes 1.\n!\n a(j,j) = 1._KIND_Rdp\n a(j,j+1:n+nrhs) = a(j,j+1:n+nrhs) / apivot\n!\n! A(I,J) becomes 0.\n!\n do i = 1, n\n\n if ( i /= j ) then\n\n factor = a(i,j)\n a(i,j) = 0._KIND_Rdp\n a(i,j+1:n+nrhs) = a(i,j+1:n+nrhs) - factor * a(j,j+1:n+nrhs)\n\n end if\n\n end do\n\n end do\n\nend subroutine\n\n\nEND MODULE\n", "meta": {"hexsha": "74ac2a59ba809d013abc0a925f982c20e22a451a", "size": 26154, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/07-B-FUN_xyTRIANGULATE.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/07-B-FUN_xyTRIANGULATE.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/07-B-FUN_xyTRIANGULATE.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": 22.1269035533, "max_line_length": 97, "alphanum_fraction": 0.5988376539, "num_tokens": 8762, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148512, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6949886424890106}} {"text": "module object_space_mod\n implicit none\n integer, parameter :: MAXBUF=20\n!Defining the object\n type :: object_space\n character(MAXBUF) :: obj_name\n real :: pos(3), vel(3), acc(3), mass\n end type object_space\n\ncontains\n\n!Function for creating a new Object\n type(object_space) function newObject(n, p, v, m)\n implicit none\n integer, parameter :: MAXBUFF=20\n character(MAXBUFF), intent(in) :: n\n real, intent(in) :: p(3), v(3), m\n real :: a(3)=0\n\n newObject=object_space(n, p, v, a, m)\n end function newObject\n\n!Subroutine for calculating the total acceleration of an object.\n subroutine total_acceleration(object, siz, list)\n implicit none\n integer, intent(in) :: object, siz\n type(object_space), intent(inout) :: list(siz)\n integer :: i, j\n\n!zero the existing acceleration\n list(object)%acc=0\n\n\n!Loop through the list, skip the object that we are currently moving and calculate total acceleration a(t) \n do i=1, siz\n if (list(object)%obj_name /= list(i)%obj_name) then\n !Calculate acceleration for all components\n do j=1, 3\n list(object)%acc(j) = list(object)%acc(j) + calc_acceleration(list(object), list(i), j)\n end do\n end if\n end do\n end subroutine total_acceleration\n\n!Calculate acceleration for one component\n real function calc_acceleration(object1, object2, comp)\n implicit none\n type(object_space), intent(in) :: object1, object2\n real :: acc, grav_acc\n integer :: comp\n\n grav_acc = 4*(3.1415**2)\n\n if (dist_between(object1, object2) /= 0) then\n acc = grav_acc*(object2%pos(comp) - object1%pos(comp)) * object2%mass/(dist_between(object1, object2)**3)\n else\n acc = 0\n end if\n\n calc_acceleration = acc\n end function calc_acceleration\n\n!Distance between objects o1 and o2\n real function dist_between(o1, o2)\n implicit none\n type(object_space), intent(in) :: o1, o2\n real :: distance\n\n distance = ((o2%pos(1)-o1%pos(1))**2 + (o2%pos(2)-o1%pos(2))**2 + (o2%pos(3)-o1%pos(3))**2)**0.5\n\n dist_between = distance\n end function dist_between\n\n!print out info of the object\n subroutine print_object(object)\n implicit none\n type(object_space) :: object\n print *, object%obj_name, object%pos(1), object%pos(2), object%pos(3)\n end subroutine\n\nend module\n", "meta": {"hexsha": "a4ae9b108d91802208172d3cfa12979ea6b84426", "size": 2319, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "object.f95", "max_stars_repo_name": "MrCubanfrog/Gravity-simulation", "max_stars_repo_head_hexsha": "1553253f038be76e6a0ecffa3cd651a789649eff", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-27T02:57:44.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-27T02:57:44.000Z", "max_issues_repo_path": "object.f95", "max_issues_repo_name": "MrCubanfrog/Gravity-simulation", "max_issues_repo_head_hexsha": "1553253f038be76e6a0ecffa3cd651a789649eff", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "object.f95", "max_forks_repo_name": "MrCubanfrog/Gravity-simulation", "max_forks_repo_head_hexsha": "1553253f038be76e6a0ecffa3cd651a789649eff", "max_forks_repo_licenses": ["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.2804878049, "max_line_length": 112, "alphanum_fraction": 0.6705476498, "num_tokens": 668, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418158002492, "lm_q2_score": 0.7520125793176223, "lm_q1q2_score": 0.6949662705552164}} {"text": "program i\n integer::b = 10\n integer::c = 15\n integer::a= b * c + c / b ** c \nend program i\n", "meta": {"hexsha": "88d323100162761dc865b80352642c858bb43044", "size": 94, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/decl/scalar_init/decl_init6.f90", "max_stars_repo_name": "clementval/fc", "max_stars_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/decl/scalar_init/decl_init6.f90", "max_issues_repo_name": "clementval/fc", "max_issues_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/decl/scalar_init/decl_init6.f90", "max_forks_repo_name": "clementval/fc", "max_forks_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.6666666667, "max_line_length": 33, "alphanum_fraction": 0.5531914894, "num_tokens": 38, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418178895029, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6949662669901429}} {"text": "use PlantFEM\nimplicit none\n\ninteger(int32) :: i\nreal(real64) :: a_n, a\ntype(IO_) :: f\n\n! create a sequence\ncall f%open(\"sequence.txt\",\"w\")\n! a_1 = 1.0\na_n=1.0d0\ndo i=1,100000\n ! a_{n+1} = a_{n} + 1 / a_{n}\n a = a_n + 1.0d0/a_n\n write(f%fh,*) i, a\n a_n = a\nenddo\ncall f%close()\n\n! plot 2-D graph without lines\ncall f%plot(\"sequence.txt\")\n\n! plot 2-D graph with lines\ncall f%plot(\"sequence.txt\",\"with line\")\n\nend", "meta": {"hexsha": "33189df840fceaa5ee0753dbc023d11d5cbc8ee5", "size": 424, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/playon_std/plot2DGraph.f90", "max_stars_repo_name": "kazulagi/plantfem_min", "max_stars_repo_head_hexsha": "ba7398c031636644aef8acb5a0dad7f9b99fcb92", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2020-06-21T08:21:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-13T04:28:30.000Z", "max_issues_repo_path": "Tutorial/std/plot2DGraph.f90", "max_issues_repo_name": "kazulagi/plantFEM_binary", "max_issues_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-05-08T05:20:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T05:39:29.000Z", "max_forks_repo_path": "Tutorial/std/plot2DGraph.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": 16.3076923077, "max_line_length": 39, "alphanum_fraction": 0.6155660377, "num_tokens": 173, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.8031738057795403, "lm_q1q2_score": 0.6949253248380381}} {"text": "!> The problem is to determine the values of x(1), x(2), ..., x(9)\n!> which solve the system of tridiagonal equations\n!> (3-2*x(1))*x(1) -2*x(2) = -1\n!> -x(i-1) + (3-2*x(i))*x(i) -2*x(i+1) = -1, i=2-8\n!> -x(8) + (3-2*x(9))*x(9) = -1\nprogram example_hybrd\n\n use minpack, only: hybrd, enorm, dpmpar\n implicit none\n integer j, n, maxfev, ml, mu, mode, nprint, info, nfev, ldfjac, lr, nwrite\n double precision xtol, epsfcn, factor, fnorm\n double precision x(9), fvec(9), diag(9), fjac(9, 9), r(45), qtf(9), &\n wa1(9), wa2(9), wa3(9), wa4(9)\n\n !> Logical output unit is assumed to be number 6.\n data nwrite/6/\n\n n = 9\n\n !> The following starting values provide a rough solution.\n do j = 1, 9\n x(j) = -1.0d0\n end do\n\n ldfjac = 9\n lr = 45\n\n !> Set xtol to the square root of the machine precision.\n !> unless high precision solutions are required,\n !> this is the recommended setting.\n xtol = dsqrt(dpmpar(1))\n\n maxfev = 2000\n ml = 1\n mu = 1\n epsfcn = 0.0d0\n mode = 2\n do j = 1, 9\n diag(j) = 1.0d0\n end do\n factor = 1.0d2\n nprint = 0\n\n call hybrd(fcn, n, x, fvec, xtol, maxfev, ml, mu, epsfcn, diag, &\n mode, factor, nprint, info, nfev, fjac, ldfjac, &\n r, lr, qtf, wa1, wa2, wa3, wa4)\n fnorm = enorm(n, fvec)\n write (nwrite, 1000) fnorm, nfev, info, (x(j), j=1, n)\n\n1000 format(5x, \"FINAL L2 NORM OF THE RESIDUALS\", d15.7// &\n 5x, \"NUMBER OF FUNCTION EVALUATIONS\", i10// &\n 5x, \"EXIT PARAMETER\", 16x, i10// &\n 5x, \"FINAL APPROXIMATE SOLUTION\"//(5x, 3d15.7))\n\n !> Results obtained with different compilers or machines\n !> may be slightly different.\n !>\n !>> FINAL L2 NORM OF THE RESIDUALS 0.1192636D-07\n !>>\n !>> NUMBER OF FUNCTION EVALUATIONS 14\n !>>\n !>> EXIT PARAMETER 1\n !>>\n !>> FINAL APPROXIMATE SOLUTION\n !>>\n !>> -0.5706545D+00 -0.6816283D+00 -0.7017325D+00\n !>> -0.7042129D+00 -0.7013690D+00 -0.6918656D+00\n !>> -0.6657920D+00 -0.5960342D+00 -0.4164121D+00\n\ncontains\n\n !> Subroutine fcn for hybrd example.\n subroutine fcn(n, x, fvec, iflag)\n\n implicit none\n integer n, iflag\n double precision x(n), fvec(n)\n\n integer k\n double precision one, temp, temp1, temp2, three, two, zero\n data zero, one, two, three/0.0d0, 1.0d0, 2.0d0, 3.0d0/\n\n if (iflag /= 0) go to 5\n\n !! Insert print statements here when nprint is positive.\n\n return\n5 continue\n do k = 1, n\n temp = (three - two*x(k))*x(k)\n temp1 = zero\n if (k /= 1) temp1 = x(k - 1)\n temp2 = zero\n if (k /= n) temp2 = x(k + 1)\n fvec(k) = temp - temp1 - two*temp2 + one\n end do\n return\n\n end subroutine fcn\n\nend program example_hybrd\n", "meta": {"hexsha": "80f97cf05e29a91444af5ffe2d0f33d7e90acd75", "size": 2977, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/example_hybrd.f90", "max_stars_repo_name": "certik/minpack", "max_stars_repo_head_hexsha": "c0dc9cd5453bcdf8ba4fe79561a660b20e2332a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 33, "max_stars_repo_stars_event_min_datetime": "2015-05-06T22:26:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-29T23:49:13.000Z", "max_issues_repo_path": "examples/example_hybrd.f90", "max_issues_repo_name": "certik/minpack", "max_issues_repo_head_hexsha": "c0dc9cd5453bcdf8ba4fe79561a660b20e2332a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2021-04-03T01:51:52.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-02T19:58:04.000Z", "max_forks_repo_path": "examples/example_hybrd.f90", "max_forks_repo_name": "certik/minpack", "max_forks_repo_head_hexsha": "c0dc9cd5453bcdf8ba4fe79561a660b20e2332a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2015-01-15T12:15:13.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-29T13:41:17.000Z", "avg_line_length": 29.1862745098, "max_line_length": 78, "alphanum_fraction": 0.5317433658, "num_tokens": 1099, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240930029117, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.6949253174384319}} {"text": "! Copyright (C) 2015-2017, Simone Marsili\n! All rights reserved.\n! License: BSD 3 clause\n\nmodule scrs\n use kinds\n implicit none\n private\n public :: compute_scores\n public :: print_mat\n\ncontains\n\n pure real(kflt) function frobenius(a)\n real(kflt), intent(in) :: a(:,:)\n \n frobenius = sqrt(sum(a**2))\n end function frobenius\n\n pure subroutine apc_correction(a)\n real(kflt), intent(inout) :: a(:,:)\n real(kflt), allocatable :: sums(:)\n real(kflt) :: totsum\n integer :: err\n integer :: i,j\n integer :: n\n \n n = size(a,1)\n allocate(sums(n),stat=err)\n do i = 1,n\n sums(i) = sum(a(:,i))\n end do\n totsum = sum(sums)\n do j = 1,n\n do i = j,n\n a(i,j) = a(i,j) - sums(i)*sums(j)/totsum\n a(j,i) = a(i,j)\n end do\n end do\n deallocate(sums)\n end subroutine apc_correction\n\n subroutine print_mat(mat,uscrs,frmt,nerr)\n ! https://people.sc.fsu.edu/~jburkardt/data/mm/mm.html\n real(kflt), intent(in) :: mat(:,:)\n integer, intent(in) :: uscrs\n character(1), intent(in) :: frmt\n integer, intent(out) :: nerr\n logical :: inds = .true.\n integer :: i,j,n1,n2\n\n nerr = 0\n ! check format\n if (.not. any([\"r\",\"c\",\"a\"] == frmt)) then\n write(0,*) \"error ! unknown format for scores matrix file\"\n nerr = nerr + 1\n return\n end if\n n1 = size(mat,1)\n n2 = size(mat,2)\n ! write header line\n select case(frmt)\n case(\"r\")\n do j = 1,n1\n do i = j,n2\n write(uscrs,'(i5,1x,i5,1x,f8.4)') i, j, mat(i,j)\n end do\n end do\n case(\"a\")\n write(uscrs,'(a)') \"%%MatrixMarket matrix array real symmetric\"\n write(uscrs,'(a)') \"%Lower triangular, column-major order\"\n write(uscrs,'(i5,1x,i5)') n1,n2\n do j = 1,n1\n do i = j,n2\n write(uscrs,'(f8.4)') mat(i,j)\n end do\n end do\n case(\"c\")\n write(uscrs,'(a)') \"%%MatrixMarket matrix coordinate real symmetric\"\n write(uscrs,'(a)') \"%Lower triangular, column-major order\"\n write(uscrs,'(i5,1x,i5,1x,i5)') n1,n2,n1*n2\n do j = 1,n1\n do i = j,n2\n write(uscrs,'(i5,1x,i5,1x,f8.4)') i, j, mat(i,j)\n end do\n end do\n end select\n\n end subroutine print_mat\n\n subroutine compute_scores(nv,ns,couplings,ignore_pivot,scores)\n implicit none\n integer(kint), intent(in) :: nv,ns\n real(kflt), intent(in) :: couplings(ns,ns,nv,nv)\n integer, intent(in) :: ignore_pivot\n real(kflt), intent(out) :: scores(nv,nv)\n integer :: iv,jv,err,is,js\n real(kflt) :: sums(nv),rsum(ns),csum(ns),matij(ns,ns),matji(ns,ns)\n real(kflt) :: totsum\n integer :: inds(ns-1)\n \n scores = 0.0_kflt\n do iv = 1,nv-1\n do jv = iv+1,nv\n if (ignore_pivot >= 1 .and. ignore_pivot <= ns) then\n is = 0\n do js = 1,ns\n if (js /= ignore_pivot) then\n is = is + 1\n inds(is) = js\n end if\n end do\n matij = couplings(inds,inds,iv,jv)\n matji = couplings(inds,inds,jv,iv)\n else\n matij = couplings(:,:,iv,jv)\n matji = couplings(:,:,jv,iv)\n end if\n call double_center(matij)\n call double_center(matji)\n scores(iv,jv) = sum((matij + transpose(matji))**2)\n scores(jv,iv) = scores(iv,jv)\n end do\n end do\n scores = 0.5_kflt * sqrt(scores)\n do iv = 1,nv\n sums(iv) = sum(scores(:,iv))\n end do\n totsum = sum(sums)\n do jv = 1,nv\n do iv = jv,nv\n scores(iv,jv) = scores(iv,jv) - sums(iv)*sums(jv)/totsum\n scores(jv,iv) = scores(iv,jv)\n end do\n end do\n end subroutine compute_scores\n\n pure subroutine double_center(a)\n real(kflt), intent(inout) :: a(:,:)\n integer :: i,j,n,m\n real(kflt) :: totsum\n real(kflt), allocatable :: rsum(:),csum(:)\n integer :: err\n n = size(a,dim=1)\n m = size(a,dim=2)\n allocate(rsum(n),csum(m),stat=err)\n totsum = sum(a) / real(n*m)\n csum = sum(a,dim=2) / real(n)\n rsum = sum(a,dim=1) / real(m)\n do j = 1,m\n do i = 1,n\n a(i,j) = a(i,j) - csum(i) - rsum(j) + totsum\n end do\n end do\n deallocate(rsum,csum)\n end subroutine double_center\n\nend module scrs\n", "meta": {"hexsha": "9ac977769c8e8334a3b44c74919a6fbad31002be", "size": 4316, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/scrs.f90", "max_stars_repo_name": "simomarsili/fmpl", "max_stars_repo_head_hexsha": "e96a6ef82c330a80105190ebde2d6b668da6786e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/scrs.f90", "max_issues_repo_name": "simomarsili/fmpl", "max_issues_repo_head_hexsha": "e96a6ef82c330a80105190ebde2d6b668da6786e", "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/scrs.f90", "max_forks_repo_name": "simomarsili/fmpl", "max_forks_repo_head_hexsha": "e96a6ef82c330a80105190ebde2d6b668da6786e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.1446540881, "max_line_length": 75, "alphanum_fraction": 0.5349860982, "num_tokens": 1439, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.803173791645582, "lm_q1q2_score": 0.6949253070264739}} {"text": "c \nc input: * * ****\n \tsubroutine lstsqr(x,y,npts,a,b,r)\nc output: + + +\nc----------------------------------------------------------------------\nc\nc Linear least-squares fit: y = a + bx\nc\nc Input:\nc x,y -=- arrays containing coordinates of points to be fit\nc npts -=- size of above arrays\nc\nc Output:\nc a,b -=- fitted constants\nc r\t -=- correlation coefficients\nc\nc Non-system routines: none\nc\nc----------------------------------------------------------------------\n \tdimension x(npts), y(npts)\n \treal n\n \tn=float(npts)\nc\nc Initialize sums\nc\n \tdo 10 i = 1, npts\n \t sumx = 0.0\n \t sumy = 0.0\n \t sumxx = 0.0\n \t sumyy = 0.0\n \t sumxy = 0.0\n10\tcontinue\nc\nc Accumulate sums\nc\n \tdo 20 i = 1, npts\n \t sumx = sumx + x(i)\n \t sumy = sumy + y(i)\n \t sumxx = sumxx + x(i)*x(i)\n \t sumyy = sumyy + y(i)*y(i)\n \t sumxy = sumxy + x(i)*y(i)\n20\tcontinue\nc\nc Calculate coefficients\nc\n \ttmp1=sumx*sumx/n\n \ttmp2=sumy*sumy/n\n \tb=(sumxy-(sumx*sumy/n))/(sumxx-tmp1)\n \ta=(sumy/n)-(b*sumx/n)\n \ttmp3=(sumxy-(sumx*sumy/n))**2\n \ttmp4=sumxx-tmp1\n \ttmp5=sumyy-tmp2\n \tr=tmp3/(tmp4*tmp5)\nc\n \treturn\n \tend\n", "meta": {"hexsha": "7207d7fa72942dec17aeda24a08d64e4672b0f52", "size": 1279, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "bin/magnitude/mdcalc/lstsqr.f", "max_stars_repo_name": "jreyes1108/antelope_contrib", "max_stars_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_stars_repo_licenses": ["BSD-2-Clause", "MIT"], "max_stars_count": 30, "max_stars_repo_stars_event_min_datetime": "2015-02-20T21:44:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-27T02:53:14.000Z", "max_issues_repo_path": "bin/magnitude/mdcalc/lstsqr.f", "max_issues_repo_name": "jreyes1108/antelope_contrib", "max_issues_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_issues_repo_licenses": ["BSD-2-Clause", "MIT"], "max_issues_count": 14, "max_issues_repo_issues_event_min_datetime": "2015-07-07T19:17:24.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-19T19:18:53.000Z", "max_forks_repo_path": "bin/magnitude/mdcalc/lstsqr.f", "max_forks_repo_name": "jreyes1108/antelope_contrib", "max_forks_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_forks_repo_licenses": ["BSD-2-Clause", "MIT"], "max_forks_count": 46, "max_forks_repo_forks_event_min_datetime": "2015-02-06T16:22:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T11:46:37.000Z", "avg_line_length": 22.4385964912, "max_line_length": 71, "alphanum_fraction": 0.4487881157, "num_tokens": 426, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.865224068675884, "lm_q2_score": 0.8031738034238807, "lm_q1q2_score": 0.6949253060522946}} {"text": " Program zhptrd_example\n\n! ZHPTRD Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_interfaces, Only: zhptrd\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nin = 5, nout = 6\n! .. Local Scalars ..\n Integer :: i, info, j, n\n Character (1) :: uplo\n! .. Local Arrays ..\n Complex (Kind=dp), Allocatable :: ap(:), tau(:)\n Real (Kind=dp), Allocatable :: d(:), e(:)\n! .. Intrinsic Procedures ..\n Intrinsic :: abs\n! .. Executable Statements ..\n Write (nout, *) 'ZHPTRD Example Program Results'\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n\n\n Allocate (ap(n*(n+1)/2), tau(n-1), d(n), e(n-1))\n\n! Read A from data file and copy a into AW\n\n Read (nin, *) uplo\n If (uplo=='U') Then\n Read (nin, *)((ap(i+j*(j-1)/2),j=i,n), i=1, n)\n Else If (uplo=='L') Then\n Read (nin, *)((ap(i+(2*n-j)*(j-1)/2),j=1,i), i=1, n)\n End If\n\n! Reduce A to tridiagonal form\n Call zhptrd(uplo, n, ap, d, e, tau, info)\n\n If (info==0) Then\n! Print the diagonal and off-diagonal of tridiagonal T.\n! The absolute value of E is printed since this can vary by a change of\n! sign (corresponding to multiplying through a column of Q by -1).\n\n Write (nout, *)\n Write (nout, *) &\n 'Diagonal and off-diagonal elements of tridiagonal form'\n Write (nout, *)\n Write (nout, 100) 'i', 'D', 'E'\n Do i = 1, n - 1\n Write (nout, 110) i, d(i), abs(e(i))\n End Do\n Write (nout, 110) n, d(n)\n\n Else\n Write (nout, 120) info\n End If\n\n100 Format (5X, A, 9X, A, 12X, A)\n110 Format (1X, I5, 2(1X,F12.5))\n120 Format (1X, '** ZHPTRD retuned with INFO = ', I10)\n\n End Program\n", "meta": {"hexsha": "dda4150cfb0b53adde353b9a70705785d5f02186", "size": 2045, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/zhptrd_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/zhptrd_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/zhptrd_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 30.0735294118, "max_line_length": 90, "alphanum_fraction": 0.5520782396, "num_tokens": 654, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240721511739, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.6949253047672095}} {"text": "program matrix_reduce\nuse, intrinsic :: iso_fortran_env, only : output_unit, error_unit, &\n dp => REAL64\nuse :: mpi\nimplicit none\ninteger, parameter :: root = 0\ninteger :: rank, size, istat, ierr\ninteger :: nr_rows, nr_cols, nr_iters, iter, i, j\ncharacter(len=15) :: argv\nreal(kind=dp), allocatable, dimension(:, :) :: matrix, total_matrix\nreal(kind=dp) :: r, total\n\ncall MPI_Init(ierr)\ncall MPI_Comm_rank(MPI_COMM_WORLD, rank, ierr)\ncall MPI_Comm_size(MPI_COMM_WORLD, size, ierr)\n\n! get command line arguments, and broadcast them to all\nif (rank == root) then\n nr_rows = 5\n if (command_argument_count() >= 1) then\n call get_command_argument(1, argv)\n read (argv, '(I10)') nr_rows\n end if\n if (command_argument_count() >= 2) then\n call get_command_argument(2, argv)\n read (argv, '(I10)') nr_cols\n else\n nr_cols = nr_rows\n end if\n if (command_argument_count() >= 3) then\n call get_command_argument(3, argv)\n read (argv, '(I10)') nr_iters\n else\n nr_iters = 1\n end if\n write (unit=output_unit, fmt='(3(A, I10, /))') &\n 'nr. rows: ', nr_rows, &\n 'nr. columns: ', nr_cols, &\n 'nr. iterations: ', nr_iters\nend if\ncall MPI_Bcast(nr_rows, 1, MPI_INTEGER, root, MPI_COMM_WORLD, ierr)\ncall MPI_Bcast(nr_cols, 1, MPI_INTEGER, root, MPI_COMM_WORLD, ierr)\ncall MPI_Bcast(nr_iters, 1, MPI_INTEGER, root, MPI_COMM_WORLD, ierr)\n\n! allocate matrix for each process\nallocate(matrix(nr_rows, nr_cols), stat=istat)\nif (istat /= 0) then\n write (unit=error_unit, fmt='(A)'), 'can not allocate matrix'\n call MPI_Abort(MPI_COMM_WORLD, 1, ierr)\nend if\n\n! allocate and initialize matrix for the root process\nif (rank == root) then\n allocate(total_matrix(nr_rows, nr_cols), stat=istat)\n if (istat /= 0) then\n write (unit=error_unit, fmt='(A)'), 'can not allocate total_matrix'\n call MPI_Abort(MPI_COMM_WORLD, 1, ierr)\n end if\nend if\n\ndo iter = 1, nr_iters\n call random_number(r)\n do j = 1, nr_cols\n do i = 1, nr_rows\n matrix(i, j) = 2*r + i + rank*(j - 1) + rank*size\n end do\n end do\n\n call MPI_Reduce(matrix, total_matrix, &\n nr_rows*nr_cols, MPI_DOUBLE_PRECISION, &\n MPI_SUM, root, MPI_COMM_WORLD, ierr)\n if (rank == root) then\n total = sum(total_matrix)\n write(unit=output_unit, fmt='(A, I5, F8.1)') &\n 'iteration', iter, total\n end if\nend do\n\nif (rank == root .and. nr_rows < 20 .and. nr_cols < 20) then\n do i = 1, nr_rows\n write (unit=output_unit, fmt='(*(F8.1))') total_matrix(i, :)\n end do\nend if\n\ncall MPI_Finalize(ierr)\n\nend program matrix_reduce\n", "meta": {"hexsha": "f380391416308e610f135b730fad0b6d4fe6c447", "size": 2725, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Mpi/MatrixReduce/matrix_reduce.f90", "max_stars_repo_name": "stijnvanhoey/training-material", "max_stars_repo_head_hexsha": "d8e23c2aefaaafbd6a6d5e059147831c651f21ec", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Mpi/MatrixReduce/matrix_reduce.f90", "max_issues_repo_name": "stijnvanhoey/training-material", "max_issues_repo_head_hexsha": "d8e23c2aefaaafbd6a6d5e059147831c651f21ec", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Mpi/MatrixReduce/matrix_reduce.f90", "max_forks_repo_name": "stijnvanhoey/training-material", "max_forks_repo_head_hexsha": "d8e23c2aefaaafbd6a6d5e059147831c651f21ec", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-01-07T22:45:34.000Z", "max_forks_repo_forks_event_max_datetime": "2019-01-07T22:45:34.000Z", "avg_line_length": 30.9659090909, "max_line_length": 75, "alphanum_fraction": 0.6304587156, "num_tokens": 803, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.849971175657575, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.6949147349398914}} {"text": " INTEGER FUNCTION FINDI(X,A,N)\t!Binary chopper. Find i such that X = A(i)\nCareful: it is surprisingly difficult to make this neat, due to vexations when N = 0 or 1.\n REAL X,A(*)\t\t!Where is X in array A(1:N)?\n INTEGER N\t\t!The count.\n INTEGER L,R,P\t\t!Fingers.\n L = 0\t\t\t!Establish outer bounds, to search A(L+1:R-1).\n R = N + 1\t\t!L = first - 1; R = last + 1.\n GO TO 1\t\t\t!Hop to it.\n 2 L = P\t\t\t!A(P) < X. Shift the left bound up: X follows A(P).\n 1 P = (R - L)/2\t\t!Probe point. Beware INTEGER overflow with (L + R)/2.\n IF (P.LE.0) GO TO 5\t!Aha! Nowhere!! The span is empty.\n P = P + L\t\t!Convert an offset from L to an array index.\n IF (X - A(P)) 3,4,2\t!Compare to the probe point.\n 3 R = P\t\t\t!X < A(P). Shift the right bound down: X precedes A(P).\n GO TO 1\t\t\t!Try again.\n 4 FINDI = P\t\t!A(P) = X. So, X is found, here!\n RETURN\t\t\t!Done.\nCurse it!\n 5 FINDI = -L\t\t!X is not found. Insert it at L + 1, i.e. at A(1 - FINDI).\n END FUNCTION FINDI\t!A's values need not be all different, merely in order.\n", "meta": {"hexsha": "f10593e1b0470d507ff9b8225b87a854dae87856", "size": 1099, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Binary-search/Fortran/binary-search-4.f", "max_stars_repo_name": "mullikine/RosettaCodeData", "max_stars_repo_head_hexsha": "4f0027c6ce83daa36118ee8b67915a13cd23ab67", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Binary-search/Fortran/binary-search-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/Binary-search/Fortran/binary-search-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": 52.3333333333, "max_line_length": 90, "alphanum_fraction": 0.5577797998, "num_tokens": 399, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711642563823, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.6949147312856362}} {"text": "\nMODULE DG_WAVE\n\nUSE MPI\nUSE BASIS\nUSE PARAM, ONLY: N, C, T_TOTAL, NT\nUSE USER_DEFINED\n\nIMPLICIT NONE\n\nDOUBLE PRECISION, ALLOCATABLE, DIMENSION(:, :) :: DER_TRANSPOSE ! THE TRANSPOSE OF THE FIRST DERIVATIVE MATRIX\nDOUBLE PRECISION, ALLOCATABLE, DIMENSION(:) :: SOLUTION ! SOLUTION AT GL POINTSJ\nDOUBLE PRECISION :: DELTA_T\n\nCONTAINS\n\nSUBROUTINE DG_WAVE_PROCEDURE\n! ----------------------------------------------------------------------\n! SOLVE A SCALER ADVACTION PROBLEM\n! INTEGRATE THE SYSTEM FROM INITIAL TO FINAL TIME \n! USE GAUSS-LENGENDRE POINTS\n! MODIFIED ALORITHM 51\n!-----------------------------------------------------------------------\n\n IMPLICIT NONE\n \n INTEGER :: K\n \n DOUBLE PRECISION :: TN = 0.0D0 ! CURRENT TIME\n DOUBLE PRECISION :: ERROR(0:N)\n DOUBLE PRECISION :: EXACT(0:N)\n\n \n !-------------------------------------------------------------------\n ! ALLOCATE\n ALLOCATE(SOLUTION(0:N))\n SOLUTION=0.0D0\n !-------------------------------------------------------------------\n \n !-------------------------------------------------------------------\n ! COMPUTE GAUSS-LEGENDRE POINTS AND WEIGHTS\n ! COMPUTE THE FIRST ORDER PLOYMOIAL DERIVATIVE MATRIX\n ! COMPUTE THE LAGANDRE POLYNOMIAL AT THE TWO ENDS OF THE BOUNDARIES\n CALL CONSTRUCT_DG\n !-------------------------------------------------------------------\n \n !-------------------------------------------------------------------\n ! USER DEFINED INITIAL CONDITION\n CALL INITIAL_CONDITION(N, SOLUTION)\n !-------------------------------------------------------------------\n \n! PRINT *, SOLUTION\n \n !-------------------------------------------------------------------\n ! CONFIRM THE TIME STEP\n CALL DECIDE_TIME_STEP(N)\n! DELTA_T = 1.5E-4\n !-------------------------------------------------------------------\n\n !-------------------------------------------------------------------\n! DO K=0, NT-1\n DO K=0,0\n\n CALL DG_STEP_BY_RK3(TN, N)\n TN = (K+1)*DELTA_T\n ENDDO\n !-------------------------------------------------------------------\n \n ! ------------------------------------------------------------------\n ! GET ERROR\n CALL GET_ERROR(N, ERROR, EXACT, TN)\n !-------------------------------------------------------------------\n \n! PRINT *, MAXVAL(DABS(ERROR))\n \n !-------------------------------------------------------------------\n ! WRITE SOLUTION TO FILE\n! OPEN(UNIT=6, FILE=\"advaction_solution.txt\")\n! DO K=0, N\n! WRITE(6, 30) K, GL_POINT(K), SOLUTION(K), EXACT(K), ERROR(K)\n!30 FORMAT(I2, 2X, F10.5, 2X, E20.10, 2X, E20.10, 2X, E20.10) \n \n! ENDDO\n! CLOSE(UNIT=6)\n !-------------------------------------------------------------------\n \n ! WRITE DATA TO FILE------------------------------------------------\n CALL WRITE_DATA(N, EXACT, TN) ! FILE = \"advaction_solution.dat\"\n !-------------------------------------------------------------------\n \n ! GET ERROR MAX-----------------------------------------------------\n! OPEN(UNIT = 6, FILE=\"max_error.dat\", ACCESS=\"APPEND\")\n! WRITE(6, 70) N, MAXVAL(DABS(ERROR))\n!70 FORMAT(I3, 2X, E20.10)\n! CLOSE(UNIT = 6)\n !-------------------------------------------------------------------\n\nEND SUBROUTINE DG_WAVE_PROCEDURE\n\nSUBROUTINE CONSTRUCT_DG\n!-----------------------------------------------------------------------\n! CONSTRUCTOR FOR THE DISCONTINUOUS GALERKIN CLASS\n! ALGORITHM 59\n!-----------------------------------------------------------------------\n \n IMPLICIT NONE\n \n INTEGER :: I, J\n \n !-------------------------------------------------------------------\n ALLOCATE(LAGRANGE_LEFT(0: N), LAGRANGE_RIGHT(0: N))\n ALLOCATE(DER_TRANSPOSE(0: N, 0: N))\n \n LAGRANGE_LEFT = 0.0D0\n LAGRANGE_RIGHT = 0.0D0\n DER_TRANSPOSE = 0.0D0\n !-------------------------------------------------------------------\n \n ! GL POINTS AND WEIGHTS---------------------------------------------\n CALL GL(N)\n !-------------------------------------------------------------------\n \n ! FIRST DERIVATIVE MATRIX-------------------------------------------\n CALL mth_Order_Polynomial_Derivative_Matrix(N,1, GL_POINT) ! USE GL POINTS, \n !--------------------------------------------------------------------\n \n ! LAGRANGE POLY AT POINT -1.0 AND +1.0 -----------------------------\n CALL LAGRANGE_INTERPOLATING_POLYNOMIAL(N, -1.0D0, GL_POINT, BARY, LAGRANGE_LEFT)\n CALL LAGRANGE_INTERPOLATING_POLYNOMIAL(N, 1.0D0, GL_POINT, BARY, LAGRANGE_RIGHT)\n !-------------------------------------------------------------------\n \n! PRINT *, LAGRANGE_LEFT\n \n ! COMPUTE DERIVATIVE TRANSPOSE--------------------------------------\n DO J=0, N\n DO I=0, N\n DER_TRANSPOSE(I, J) = - DER(J, I)*GL_W(J)/GL_W(I)\n ENDDO\n \n ENDDO\n !-------------------------------------------------------------------\n \n\n \n \nEND SUBROUTINE CONSTRUCT_DG\n\nSUBROUTINE DG_DERIVATIVE(N, SOLUTION_LEFT, SOLUTION_RIGHT, SOLUTION_DER)\n!-----------------------------------------------------------------------\n! FIRST SPATIAL DERIVATIVE VIA THE GALERKIN APPROXIMATION\n! ALGORITHM 60\n!----------------------------------------------------------------------- \n\n IMPLICIT NONE\n \n INTEGER :: N ! POLY ORDER\n INTEGER :: J\n \n DOUBLE PRECISION :: SOLUTION_LEFT ! SOLUTION ON THE LEFT BOUNDARY\n DOUBLE PRECISION :: SOLUTION_RIGHT ! SOLUTION ON THE RIGHT BOUNDARY\n DOUBLE PRECISION :: SOLUTION_DER(0:N)\n \n CALL MATRIX_VECTOR_DERIVATIVE(N, DER_TRANSPOSE, SOLUTION, SOLUTION_DER)\n \n\n DO J=0, N\n SOLUTION_DER(J) = SOLUTION_DER(J)+&\n (SOLUTION_RIGHT*LAGRANGE_RIGHT(J) - &\n SOLUTION_LEFT*LAGRANGE_LEFT(J))/GL_W(J)\n ENDDO\n \n\nEND SUBROUTINE DG_DERIVATIVE\n\nSUBROUTINE EVALUATE_BOUNDARY(N, T, C, SOLUTION_LEFT, SOLUTION_RIGHT)\n!!----------------------------------------------------------------------\n!! TIME DERIVATIVE FOR DG\n!! ALGORITHM 61 (PART 1)\n!! INPUT : T: TIME; C: WAVE SPEED\n!!----------------------------------------------------------------------\n \n IMPLICIT NONE\n \n INTEGER:: N ! POLY ORDER\n \n DOUBLE PRECISION :: T ! TIME\n DOUBLE PRECISION :: C ! WAVE SPEED\n DOUBLE PRECISION :: SOLUTION_LEFT, SOLUTION_RIGHT ! APPROXIMATE SOLUTION ON THE LEFT AND RIGHT END OF THE BOUNDARY\n\n\n! PRINT *, SOLUTION\n \n ! GET SOLUTION ON THE LEFT AND RIGHT BOUNDARY-----------------------\n IF(C > 0) THEN\n SOLUTION_LEFT = BOUNDARY_SOLUTION(T)\n CALL INTERPOLATE_TO_BOUNDARY(N, SOLUTION, LAGRANGE_RIGHT, SOLUTION_RIGHT)\n ELSE \n SOLUTION_RIGHT = BOUNDARY_SOLUTION(T)\n CALL INTERPOLATE_TO_BOUNDARY(N, SOLUTION, LAGRANGE_LEFT, SOLUTION_LEFT)\n ENDIF\n !-------------------------------------------------------------------\n \n! PRINT *, LAGRANGE_RIGHT\n \n! PRINT *, SOLUTION_RIGHT\n\n! PRINT *, SOLUTION\n\nEND SUBROUTINE EVALUATE_BOUNDARY\n\nSUBROUTINE DG_TIME_DERIVATIVE(N, SOLUTION_LEFT, SOLUTION_RIGHT, C, &\n SOLUTION_TIME_DER)\n!-----------------------------------------------------------------------\n! TIME DERIVATIVE\n! ALORITHM 61 (PART 2)\n!-----------------------------------------------------------------------\n IMPLICIT NONE\n \n INTEGER :: N\n \n DOUBLE PRECISION :: SOLUTION_LEFT, SOLUTION_RIGHT\n DOUBLE PRECISION :: SOLUTION_TIME_DER(0:N)\n DOUBLE PRECISION :: C ! WAVE SPEED\n DOUBLE PRECISION :: SOLUTION_DER(0:N)\n \n CALL DG_DERIVATIVE(N, SOLUTION_LEFT, SOLUTION_RIGHT, SOLUTION_DER)\n \n SOLUTION_TIME_DER = -C * SOLUTION_DER\n\nEND SUBROUTINE DG_TIME_DERIVATIVE\n\n\nSUBROUTINE INTERPOLATE_TO_BOUNDARY(N, SOLUTION1, LAGRANGE1, INTERPOLATE_VALUE)\n!!----------------------------------------------------------------------\n!! TO COMPUTE THE SOLUTION AT THE OTHER BOUNDARY\n!! ALORITHM 61 (PART 3)\n!!----------------------------------------------------------------------\n IMPLICIT NONE\n \n INTEGER :: N ! POLY ORDER\n INTEGER :: J\n \n DOUBLE PRECISION :: INTERPOLATE_VALUE\n DOUBLE PRECISION, DIMENSION(0:N) :: SOLUTION1 \n DOUBLE PRECISION, DIMENSION(0:N) :: LAGRANGE1\n \n INTERPOLATE_VALUE = 0.0D0\n \n DO J=0, N\n INTERPOLATE_VALUE = INTERPOLATE_VALUE + LAGRANGE1(J)*SOLUTION1(J)\n \n ENDDO\n \n\nEND SUBROUTINE INTERPOLATE_TO_BOUNDARY\n\nSUBROUTINE DG_STEP_BY_RK3(TN, N)\n! ----------------------------------------------------------------------\n! THRID ORDER RUNGE-KUTTA INTEGRATION \n! INPUT: TN: CURRENT TIME; TIME_DER: DG TIME DERIVATIVE\n! ALGORITHM 62\n!-----------------------------------------------------------------------\n\n IMPLICIT NONE\n \n INTEGER :: N\n INTEGER :: I, J\n \n DOUBLE PRECISION :: TN ! CURRENT TIME\n DOUBLE PRECISION :: T\n DOUBLE PRECISION :: SOLUTION_TIME_DER(0:N) ! DG TIME DERIVATIVE AT CURRENT TIME\n DOUBLE PRECISION :: G(0:N) ! INTERMEDIATE ARRAY\n DOUBLE PRECISION :: AM(3), BM(3), GM(3) ! COEFFICIENT\n DOUBLE PRECISION :: SOLUTION_LEFT, SOLUTION_RIGHT\n\n \n AM = (/0.0D0, (-5.0D0/9.0D0), (-153D0/128.0D0)/)\n BM = (/0.0D0, (1.0D0/3.0D0), (3.0D0/4.0D0)/)\n GM = (/(1.0D0/3.0D0), (15.0D0/16.0D0), (8.0D0/15.0D0)/)\n \n SOLUTION_TIME_DER = 0.0D0\n \n DO I=1,3\n T=TN+BM(I)*DELTA_T\n! PRINT *, T\n \n CALL EVALUATE_BOUNDARY(N, T, C, SOLUTION_LEFT, SOLUTION_RIGHT) \n CALL DG_TIME_DERIVATIVE(N, SOLUTION_LEFT, SOLUTION_RIGHT, C, SOLUTION_TIME_DER)\n \n! PRINT *, SOLUTION_LEFT\n \n DO J=0,N\n G(J) = AM(I)*G(J) + SOLUTION_TIME_DER(J)\n SOLUTION(J) = SOLUTION(J) + GM(I)*DELTA_T*G(J)\n ENDDO\n ENDDO\n \n\n\nEND SUBROUTINE DG_STEP_BY_RK3\n\n\nSUBROUTINE DECIDE_TIME_STEP(N)\n \n USE PARAM, ONLY: NT, T_TOTAL\n\n IMPLICIT NONE\n \n INTEGER :: N ! POLY ORDER\n \n DOUBLE PRECISION :: DEL_T_MAX ! MAXIMUM DELTA_T FOR STABILITY\n \n !-------------------------------------------------------------------\n IF(N < 32) THEN\n DEL_T_MAX=DBLE(2.5D0/N)\n \n ELSE\n DEL_T_MAX=DBLE(38.0D0*2.51D0/(N)**2)\n ENDIF\n !-------------------------------------------------------------------\n \n !-------------------------------------------------------------------\n DELTA_T = DBLE(T_TOTAL/NT)\n !-------------------------------------------------------------------\n \n !-------------------------------------------------------------------\n IF(DEL_T_MAX < DELTA_T) THEN\n\n PRINT *, \"TIME STEP NUMBER TN IS TOO SMALL.\"\n PRINT *, \"TN >= \", INT(T_TOTAL/DEL_T_MAX)\n \n STOP\n \n ENDIF\n !-------------------------------------------------------------------\n\nEND SUBROUTINE DECIDE_TIME_STEP\n\nSUBROUTINE GET_ERROR(N, ERROR, EXACT, T)\n\n IMPLICIT NONE\n \n INTEGER :: N\n INTEGER :: I\n \n DOUBLE PRECISION :: EXACT(0: N)\n DOUBLE PRECISION :: ERROR(0: N)\n DOUBLE PRECISION :: T ! TIME T\n \n ERROR = 0.0D0\n \n CALL EXACT_SOLUTION(T, GL_POINT, N, EXACT)\n \n DO I=0, N\n ERROR(I) = EXACT(I) - SOLUTION(I)\n \n ENDDO\n\n\nEND SUBROUTINE GET_ERROR\n\nSUBROUTINE WRITE_DATA(N, EXACT, TN)\n\n INTEGER :: N\n INTEGER :: K\n \n DOUBLE PRECISION :: EXACT(0:N) ! EXACT SOLUTION\n DOUBLE PRECISION :: TN\n\n OPEN(UNIT=7, FILE=\"advaction_solution.dat\")\n WRITE(7, FMT='(''VARIABLES = \"X\", \"SOLUTION\", \"EXACT\"'')')\n WRITE(7, 60) 'ZONE DATAPACKING=BLOCK, T= ', '\"', TN, '\"', 'I=',N+1\n60 FORMAT(A27, A1, F5.2, A1, 2X, A2, I3)\n\n ! WRITE SOLUTION----------------------------------------------------\n DO K=0, N\n WRITE(7, 40, ADVANCE='NO') GL_POINT(K)\n ENDDO\n40 FORMAT(F10.5)\n \n DO K=0, N\n WRITE(7, 50, ADVANCE='NO') SOLUTION(K)\n ENDDO\n50 FORMAT(E20.10)\n\n DO K=0, N\n WRITE(7, 50, ADVANCE='NO') EXACT(K)\n ENDDO\n !-------------------------------------------------------------------\n\n\n CLOSE(UNIT=7)\n\n\n\nEND SUBROUTINE WRITE_DATA\n\nEND MODULE DG_WAVE\n", "meta": {"hexsha": "ddc20da5acc35a92cdc4587deed93f5016836b10", "size": 12113, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/DG_wave.f90", "max_stars_repo_name": "ShiqiHe000/1d_DG_advaction", "max_stars_repo_head_hexsha": "05f0dd809dabc43aa3ee3d765261f658508a21ff", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-15T01:38:37.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-15T01:38:37.000Z", "max_issues_repo_path": "src/DG_wave.f90", "max_issues_repo_name": "ShiqiHe000/1d_DG_advaction", "max_issues_repo_head_hexsha": "05f0dd809dabc43aa3ee3d765261f658508a21ff", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/DG_wave.f90", "max_forks_repo_name": "ShiqiHe000/1d_DG_advaction", "max_forks_repo_head_hexsha": "05f0dd809dabc43aa3ee3d765261f658508a21ff", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.35839599, "max_line_length": 120, "alphanum_fraction": 0.4427474614, "num_tokens": 2898, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84997116805678, "lm_q2_score": 0.8175744673038222, "lm_q1q2_score": 0.6949147249476294}} {"text": "! performance_arrays.f90 --\r\n!\r\n! Example belonging to \"Modern Fortran in Practice\" by Arjen Markus\r\n!\r\n! This work is licensed under the Creative Commons Attribution 3.0 Unported License.\r\n! To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/\r\n! or send a letter to:\r\n! Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.\r\n!\r\n! Simple program to determine the performance differences between\r\n! using array-valued functions and ordinary do-loops\r\n!\r\nprogram performance_arrays\r\n implicit none\r\n\r\n real, dimension(:), allocatable :: data\r\n real :: threshold, mean1, mean2, difference\r\n real :: meansum\r\n integer :: i, j, nodata, norepeat\r\n integer :: time1, time2, time3\r\n integer, dimension(6) :: time_pack\r\n integer, dimension(6) :: time_do\r\n\r\n threshold = 0.1\r\n nodata = 1\r\n norepeat = 1000\r\n do i = 1,6\r\n nodata = nodata * 10\r\n allocate( data(1:nodata) )\r\n\r\n call random_number( data )\r\n\r\n difference = 0.0\r\n meansum = 0.0\r\n call system_clock( time1 )\r\n do j = 1,norepeat\r\n call mean_pack( pack( data, data > threshold ), mean1 )\r\n meansum = meansum + mean1\r\n enddo\r\n\r\n call system_clock( time2 )\r\n do j = 1,norepeat\r\n call mean_do_loop( data, threshold, mean2 )\r\n meansum = meansum + mean2\r\n enddo\r\n call system_clock( time3 )\r\n\r\n time_pack(i) = time_pack(i) + (time2-time1)\r\n time_do(i) = time_do(i) + (time3-time2)\r\n\r\n difference = difference + abs(mean1-mean2)\r\n\r\n deallocate( data )\r\n enddo\r\n\r\n write( *, '(i10,2i10)' ) ( 10**i, time_do(i), time_pack(i), i = 1,6 )\r\n write( *, '(a,e12.4)' ) 'Mean difference: ', difference / 600.0\r\ncontains\r\nsubroutine mean_pack( data, mean )\r\n real, dimension(:) :: data\r\n\r\n real :: mean\r\n\r\n mean = sum(data)/max(1,size(data))\r\n\r\nend subroutine mean_pack\r\n\r\nsubroutine mean_do_loop( data, threshold, mean )\r\n real, dimension(:) :: data\r\n real :: threshold\r\n real :: mean\r\n\r\n integer :: i\r\n integer :: count\r\n\r\n mean = 0.0\r\n count = 0\r\n do i = 1,size(data)\r\n if ( data(i) > threshold ) then\r\n mean = mean + data(i)\r\n count = count + 1\r\n endif\r\n enddo\r\n\r\n mean = mean / max(1,count)\r\n\r\nend subroutine mean_do_loop\r\nend program\r\n", "meta": {"hexsha": "6dea64f0256c94cdfd537ab7a513a13ea4a33cbe", "size": 2647, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "languages/fortran/performance_arrays.f90", "max_stars_repo_name": "octonion/examples", "max_stars_repo_head_hexsha": "5d142697b9f781e37c61f32217fdb6d661902d42", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2017-12-14T04:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2018-03-31T07:12:13.000Z", "max_issues_repo_path": "languages/fortran/performance_arrays.f90", "max_issues_repo_name": "octonion/examples", "max_issues_repo_head_hexsha": "5d142697b9f781e37c61f32217fdb6d661902d42", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "languages/fortran/performance_arrays.f90", "max_forks_repo_name": "octonion/examples", "max_forks_repo_head_hexsha": "5d142697b9f781e37c61f32217fdb6d661902d42", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.7415730337, "max_line_length": 93, "alphanum_fraction": 0.5383452966, "num_tokens": 684, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84997116805678, "lm_q2_score": 0.8175744673038222, "lm_q1q2_score": 0.6949147249476294}} {"text": "program blas_probabilities\n use, intrinsic :: iso_fortran_env, only : DP => REAL64, error_unit\n use :: init_mod, only : initialize, create_matrix\n implicit none\n integer :: matrix_size, nr_iters, i\n real(kind=DP), dimension(:, :), allocatable :: prob_matrix, final_matrix, &\n tmp_matrix\n real(kind=DP) :: max_val\n\n call initialize(matrix_size, nr_iters)\n prob_matrix = create_matrix(matrix_size)\n final_matrix = create_matrix(matrix_size)\n tmp_matrix = create_matrix(matrix_size)\n\n call random_number(prob_matrix)\n call normalize(prob_matrix)\n call dcopy(size(prob_matrix), prob_matrix, 1, final_matrix, 1)\n\n do i = 2, nr_iters, 2\n call dgemm('n', 'n', &\n matrix_size, matrix_size, matrix_size, &\n 1.0_DP, final_matrix, matrix_size, &\n prob_matrix, matrix_size, 0.0_DP, &\n tmp_matrix, matrix_size)\n call dgemm('n', 'n', &\n matrix_size, matrix_size, matrix_size, &\n 1.0_DP, tmp_matrix, matrix_size, &\n prob_matrix, matrix_size, 0.0_DP, &\n final_matrix, matrix_size)\n end do\n if (mod(nr_iters, 2) /= 0) then\n call dgemm('n', 'n', &\n matrix_size, matrix_size, matrix_size, &\n 1.0_DP, final_matrix, matrix_size, &\n prob_matrix, matrix_size, 0.0_DP, &\n tmp_matrix, matrix_size)\n call dcopy(size(prob_matrix), tmp_matrix, 1, final_matrix, 1)\n end if\n\n max_val = 0.0_DP\n do i = 1, size(final_matrix, 1)\n if (final_matrix(i, i) > max_val) max_val = final_matrix(i, i)\n end do\n\n if (matrix_size <= 10) call print_matrix(final_matrix)\n\n deallocate (prob_matrix, final_matrix, tmp_matrix)\n\n print '(A, e25.15)', 'maximum value = ', max_val\n\n\ncontains\n\n subroutine print_matrix(matrix)\n implicit none\n real(kind=DP), dimension(:, :), intent(in) :: matrix\n integer :: row\n\n do row = 1, size(matrix, 1)\n print '(*(F12.7))', matrix(row, :)\n end do\n end subroutine print_matrix\n\n subroutine normalize(matrix)\n implicit none\n real(kind=DP), dimension(:, :), intent(inout) :: matrix\n real(kind=DP), dimension(:), allocatable :: norm\n integer :: row, istat, rows, cols\n\n rows = size(matrix, 1)\n cols = size(matrix, 2)\n allocate (norm(rows), stat=istat)\n if (istat /= 0) then\n write (unit=error_unit, fmt='(A)') 'error: can not allocate norm'\n stop 8\n end if\n norm = sum(matrix, dim=2)\n do row = 1, rows\n call dscal(cols, 1.0_DP/norm(row), matrix(row, :), 1)\n end do\n\n deallocate (norm)\n end subroutine normalize\n\nend program blas_probabilities\n", "meta": {"hexsha": "8e138600846d721754a6e77dc9d3d395f92e3bca", "size": 2877, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source_code/blas_lapack/blas_probabilities.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/blas_lapack/blas_probabilities.f90", "max_issues_repo_name": "gjbex/CMake-intro", "max_issues_repo_head_hexsha": "b4855c172f1d4a965f2b148b96ed160f4ea1e5bd", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-09-30T04:25:50.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-06T08:21:30.000Z", "max_forks_repo_path": "source_code/blas_lapack/blas_probabilities.f90", "max_forks_repo_name": "gjbex/CMake-intro", "max_forks_repo_head_hexsha": "b4855c172f1d4a965f2b148b96ed160f4ea1e5bd", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2021-09-27T07:30:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-07T16:23:19.000Z", "avg_line_length": 33.4534883721, "max_line_length": 79, "alphanum_fraction": 0.5762947515, "num_tokens": 740, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934406, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.6948992251097618}} {"text": " include 'ttb/ttb_library.f'\n\n SUBROUTINE UMAT(STRESS,STATEV,DDSDDE,SSE,SPD,SCD,\n 1 RPL,DDSDDT,DRPLDE,DRPLDT,\n 2 STRAN,DSTRAN,TIME,DTIME,TEMP,DTEMP,PREDEF,DPRED,CMNAME,\n 3 NDI,NSHR,NTENS,NSTATV,PROPS,NPROPS,COORDS,DROT,PNEWDT,\n 4 CELENT,DFGRD0,DFGRD1,NOEL,NPT,LAYER,KSPT,JSTEP,KINC)\n \n ! ABAQUS UMAT: Nearly-Incompressible Neo-Hookean Material\n ! Example for usage of Tensor Toolbox\n ! capability: 3D analysis, axisymmetric?\n ! Formulation: Total Lagrange with push forward for Abaqus\n ! Andreas Dutzler, 2018-07-22, Graz University of Technology\n\n use Tensor\n implicit none\n \n INCLUDE 'ABA_PARAM.INC'\n\n CHARACTER*80 CMNAME\n DIMENSION STRESS(NTENS),STATEV(NSTATV),\n 1 DDSDDE(NTENS,NTENS),DDSDDT(NTENS),DRPLDE(NTENS),\n 2 STRAN(NTENS),DSTRAN(NTENS),TIME(2),PREDEF(1),DPRED(1),\n 3 PROPS(NPROPS),COORDS(3),DROT(3,3),DFGRD0(3,3),DFGRD1(3,3),\n 4 JSTEP(4)\n \n type(Tensor2) :: F1\n real(kind=8) :: J,kappa,C10\n \n type(Tensor2s) :: C1,invC1,S1,Eye\n type(Tensor4s) :: C4\n \n ! material parameters\n C10 = 0.5\n kappa = 500.0\n \n Eye = identity2(Eye)\n F1 = dfgrd1(1:3,1:3)\n J = det(F1)\n \n ! right cauchy-green deformation tensor and it's inverse\n C1 = transpose(F1)*F1\n invC1 = inv(C1) ! faster method: invC1 = inv(C1,J**2)\n \n ! pk2 stress\n S1 = 2.*C10*J**(-2./3.)*dev(C1)*invC1 + kappa*(J-1)*J*invC1\n \n ! push forward to cauchy stress used in abaqus\n S1 = piola(F1,S1)/J\n\n ! material elasticity tensor\n C4 = 2.*C10 * J**(-2./3.) * 2./3. *\n * ( tr(C1) * (invC1.cdya.invC1)\n * - (Eye.dya.invC1) - (invC1.dya.Eye)\n * + tr(C1)/3. * (invC1.dya.invC1) )\n * + (kappa*(J-1)*J+kappa*J**2) * (invC1.dya.invC1)\n * - 2.*kappa*(J-1)*J* (invC1.cdya.invC1)\n \n ! push forward to jaumann tangent of cauchy stress for abaqus\n C4 = piola(F1,C4)/detF1 + (S1.cdya.Eye)+(Eye.cdya.S1)\n \n ! output as array\n s(1:ntens) = asabqarray( voigt(S1), ntens )\n d(1:ntens,1:ntens) = asabqarray( voigt(C4), ntens, ntens )\n \n return\n end", "meta": {"hexsha": "117663c647b5f4635bebd0500ed92940e5066272", "size": 2229, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "docs/examples/umat_nh_ttb_simple.f", "max_stars_repo_name": "pinkieli/Tensor-for-Fortran", "max_stars_repo_head_hexsha": "15372e07ad2031a83b8e3a4fe1c99bf538c4d20b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "docs/examples/umat_nh_ttb_simple.f", "max_issues_repo_name": "pinkieli/Tensor-for-Fortran", "max_issues_repo_head_hexsha": "15372e07ad2031a83b8e3a4fe1c99bf538c4d20b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/examples/umat_nh_ttb_simple.f", "max_forks_repo_name": "pinkieli/Tensor-for-Fortran", "max_forks_repo_head_hexsha": "15372e07ad2031a83b8e3a4fe1c99bf538c4d20b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-18T02:02:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-18T02:02:31.000Z", "avg_line_length": 33.2686567164, "max_line_length": 67, "alphanum_fraction": 0.5751458053, "num_tokens": 858, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067244294587, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6947765252455986}} {"text": "module NSGRAV\n! Description:\n! Contains procedures for the calculation of perturbations due to the non-\n! sphericity of the main body. INITIALIZE_NSGRAV reads main body data from a\n! data file, and initializes coefficient matrices.\n! The calculation of the perturbing potential, perturbing acceleration, and\n! the time derivative of the potential in the body-fixed frame (the latter is\n! needed in regularized formulations) takes place in PINES_NSG.\n! NORMFACT gives the normalization factor for the gravitational coefficients.\n! \n! Author:\n! Davide Amato\n! The University of Arizona\n! davideamato@email.arizona.edu\n! \n! Revisions:\n! 180806: Overhaul and implementation of Pines method.\n! 181204: Use GMST (IERS 2006 conventions) rather than ERA. Consider Earth\n! Rotation Rate derived from IERS 2006 conventions.\n! \n! ==============================================================================\n\n! MODULES\nuse KINDS, only: dk\nuse SETTINGS, only: gdeg,gord\nuse IO, only: id_earth\nuse PHYS_CONST, only: qk,GE,RE,flatt,omegaE,secsPerDay,secsPerSidDay,twopi,&\n&ERR_constant\nimplicit none\n\n! VARIABLES\n! Spherical harmonics (unnormalized) \ninteger :: maxDeg, maxOrd\nreal(dk),allocatable :: Cnm(:,:),Snm(:,:)\n\n! Pines algorithm arrays\nreal(dk),allocatable :: Anm(:,:),Dnm(:,:),Enm(:,:),Fnm(:,:),Gnm(:,:)\nreal(dk),allocatable :: Rm(:),Im(:),Pn(:)\nreal(dk),allocatable :: Aux1(:),Aux2(:),Aux3(:),Aux4(:,:)\n\n\n\n\ncontains\n\n\n\n\nsubroutine INITIALIZE_NSGRAV(earthFile)\n! Description:\n! Reads Earth gravity data from a text file. Initializes the gravitational\n! parameter, equatorial radius, flattening, rotational velocity, spherical\n! harmonics coefficients, and auxiliary matrices for Pines' algorithm. The\n! latter computes the Earth potential in Cartesian coordinates, avoiding\n! singularities due to the spherical harmonics.\n! Part of this subroutine is due to Hodei Urrutxua (Universidad Rey Juan\n! Carlos, Madrid, Spain) and Claudio Bombardelli (Universidad Polit\u00e9cnica de\n! Madrid, Madrid, Spain).\n! \n! Author:\n! Davide Amato\n! The University of Arizona\n! davideamato@email.arizona.edu\n! \n! Revisions:\n! 180806: Subroutine created from part of READ_PHYS().\n! \n! ==============================================================================\n\n! Arguments\ncharacter(len=*),intent(in) :: earthFile\n\n! Locals\ncharacter(len=72) :: dummy\nreal(dk) :: invFlatt\ninteger :: i,j,l,m,n\n\n\n! ==============================================================================\n\nopen(unit=id_earth,file=trim(earthFile),status='old',action='read')\nread(id_earth,'(a)') (dummy, i=1,4)\nread(id_earth,'(a37,i3)') dummy, maxDeg\nread(id_earth,'(a37,i3)') dummy, maxOrd\nread(id_earth,'(a36,e22.15)') dummy, GE\nread(id_earth,'(a36,e22.15)') dummy, RE\nread(id_earth,'(a36,e22.15)') dummy, invFlatt\nread(id_earth,'(a36,e22.15)') dummy, omegaE\n\nflatt = 1._dk/invFlatt\n\n! Read and de-normalize spherical harmonics coefficients and auxiliary matrices\n! for Pines' algorithm.\n! Initialize\nl = 1; m = 0;\nallocate(Cnm(1:maxDeg,0:maxDeg)); Cnm = 0._dk\nallocate(Snm(1:maxDeg,0:maxDeg)); Snm = 0._dk\nallocate(Anm(0:maxDeg+2, 0:maxDeg+2))\nallocate(Dnm(1:maxDeg, 0:maxDeg))\nallocate(Gnm(1:maxDeg, 0:maxDeg))\nallocate(Enm(1:maxDeg, 1:maxDeg))\nallocate(Fnm(1:maxDeg, 1:maxDeg))\nallocate(Rm(0:maxDeg) )\nallocate(Im(0:maxDeg) )\nallocate(Pn(0:maxDeg + 1))\nallocate(Aux1(1:maxDeg+1))\nallocate(Aux2(1:maxDeg+1))\nallocate(Aux3(1:maxDeg+1))\nallocate(Aux4(1:maxDeg+1, 0:maxDeg+1))\n\nread(id_earth,'(a)') (dummy, i=1,2)\ndo i=1,maxDeg\n do j=0,minval([i,maxOrd])\n read(id_earth,'(2(1x,i2),2(1x,e24.17))') l,m,Cnm(i,j),Snm(i,j)\n Cnm(i,j) = Cnm(i,j)/NORMFACT(i,j)\n Snm(i,j) = Snm(i,j)/NORMFACT(i,j)\n end do\nend do\n\nclose(id_earth)\n\n! Fill coefficient arrays for Pines algorithm\nAnm(:,:) = 0._dk\nDnm(:,:) = 0._dk\nGnm(:,:) = 0._dk\nEnm(:,:) = 0._dk\nFnm(:,:) = 0._dk\nAnm(0,0) = 1._dk\nAnm(1,1) = 1._dk\ndo n = 1,maxDeg + 1\n Aux1(n) = 2._dk*n + 1._dk\n Aux2(n) = Aux1(n) / (n+1._dk)\n Aux3(n) = n / (n+1._dk)\n do m = 0, n-1\n Aux4(n,m) = (n+m+1._dk)\n end do\nend do\n\n! Earth Rotation Rate (revolutions per tropical day)\nsecsPerSidDay = twopi/omegaE\nERR_constant = secsPerDay/secsPerSidDay\n\nend subroutine INITIALIZE_NSGRAV\n\n\n\n\nfunction NORMFACT(l,m)\n! Description:\n! Normalization factor for the spherical harmonics coefficients and\n! associated Legendre functions:\n! \n! sqrt( (l + m)! / ( (2 - delta_{0,m}) * (2n + 1) * (n - m)! ) )\n! \n! Reference:\n! [1] Montenbruck, O., Gill, E., \"Satellite Orbits\", p. 58, Springer, 2000.\n! \n! Author:\n! Davide Amato\n! The University of Arizona\n! davideamato@email.arizona.edu\n! \n! ==============================================================================\n\n! Arguments and function definition\ninteger,intent(in) :: l,m\nreal(qk) :: NORMFACT\n! Locals\nreal(qk) :: lr,mr\nreal(qk) :: kron\nreal(qk) :: numer,denom\n\n! ==============================================================================\nlr = real(l,qk)\nmr = real(m,qk)\n\nnumer = gamma(lr + mr + 1._qk)\n\nif (m == 0) then\n\tkron = 1._qk\nelse\n\tkron = 0._qk\nend if\n\ndenom = (2._qk - kron) * (2._qk*lr + 1._qk) * gamma(lr - mr + 1._qk)\n\nNORMFACT = sqrt(numer/denom)\n\nend function NORMFACT\n\n\n\nsubroutine PINES_NSG(GM,RE,rIn,tau,FIn,pot,dPot)\n! Description:\n! Compute the perturbing acceleration, perturbing potential (optional), and\n! time derivative of the perturbing potential in the body-fixed frame\n! (optional), given the position vector wrt the non-spherical body, its\n! gravitational parameter and its potential coefficients.\n! Uses the method described in the Reference to perform the calculation in\n! Cartesian coordinates, thereby avoiding associated Legendre functions and\n! polynomials. The formulation is non-singular everywhere for r > RE, where\n! RE is the radius of the non-spherical body.\n! \n! Adapted from code developed by Hodei Urrutxua (Universidad Rey Juan Carlos,\n! Madrid, Spain) and Claudio Bombardelli (Universidad Polit\u00e9cnica de Madrid,\n! Madrid, Spain).\n! \n! Author:\n! Davide Amato\n! The University of Arizona\n! davideamato@email.arizona.edu\n! \n! Reference:\n! S. Pines, \"Uniform Representation of the Gravitational Potential and its\n! derivatives,\" AIAA J. 11 (11), pp. 1508-1511, 1973.\n! \n! Revisions:\n! 180806: First working version of subroutine.\n! 181204: Use GMST (IERS 2006 conventions) rather than ERA. Consider Earth\n! Rotation Rate derived from IERS 2006 conventions.\n!\n! ==============================================================================\n\n! Use associations\nuse AUXILIARIES, only: MJD0, TU, T2MJD\nuse PHYS_CONST, only: delta_JD_MJD\nuse PHYS_CONST, only: ERR_IAU06, UTC2TT\n\n! Arguments\nreal(dk),intent(in) :: GM ! Gravitational parameter\nreal(dk),intent(in) :: RE ! Equatorial radius\nreal(dk),intent(in) :: rIn(1:3) ! Position in the inertial frame\nreal(dk),intent(in) :: tau ! Physical time\nreal(dk),intent(out),optional :: FIn(1:3) ! Perturbing acceleration in the inertial frame\nreal(dk),intent(out),optional :: pot ! Perturbing potential\nreal(dk),intent(out),optional :: dPot ! Time derivative of the potential in body-fixed frame\n! Locals\nreal(dk) :: rNorm,rNormSq ! Norm of position vector and square\nreal(dk) :: s,t,u ! Direction cosines in the body-fixed frame\nreal(dk) :: rho ! = equatorial radius / r \nreal(dk) :: F(1:3),a1,a2,a3,a4 ! Acceleration and its components \ninteger :: n,m ! Harmonic indices\nlogical :: skip_EFG\n! GMST-related quantities\nreal(dk) :: MJD_UTC, MJD_TT ! UTC and TT dates\nreal(dk) :: GMST,cosGMST,sinGMST ! GMST and its trig functions\nreal(dk) :: ERR, ERR_nd ! Earth Rotation Rate [rad/s, -]\n\n! SOFA routines\nreal(dk) :: iau_GMST06\n\n! ==============================================================================\n\nrNormSq = dot_product(rIn,rIn)\nrNorm = sqrt(rNormSq)\n\n! ==============================================================================\n! 01. Transform from inertial to body-fixed frame\n! ==============================================================================\n\nu = rIn(3)/rNorm\n\n! Greenwich Mean Sidereal Time (IAU 2006 conventions)\nMJD_UTC = T2MJD(tau)\nMJD_TT = UTC2TT(MJD_UTC)\n\nGMST = iau_GMST06 ( delta_JD_MJD, MJD_UTC, delta_JD_MJD, MJD_TT )\ncosGMST = cos(GMST); sinGMST = sin(GMST)\n\n! Rotate equatorial components of rIn to get direction cosines in the body-fixed frame\ns = (rIn(1) * cosGMST + rIn(2) * sinGMST)/rNorm\nt = (rIn(2) * cosGMST - rIn(1) * sinGMST)/rNorm\n\nrho = RE/rNorm\n\n! ==============================================================================\n! 02. Fill in coefficient matrices and auxiliary vectors\n! ==============================================================================\n\n! Fill A Matrix\nAnm(0,0) = 1._dk\nAnm(1,1) = 1._dk\nAnm(1,0) = u\ndo n = 1, gdeg + 1\n Anm(n+1,n+1) = Aux1(n) * Anm(n,n) ! Fill the diagonal\n Anm(n+1,0) = Aux2(n) * u * Anm(n,0) - Aux3(n) * Anm(n-1,0) ! Fill the 1st column\n Anm(n+1,n) = u * Anm(n+1,n+1) ! Fill the subdiagonal\n\nend do\ndo n = 2, gdeg + 1 ! Fill remaining elements\n do m = 0, n - 2\n Anm(n+1,m+1) = Aux4(n,m) * Anm(n,m) + u * Anm(n,m+1)\n end do\n\nend do\n\n! Fill R, I, and P vectors\nRm(0) = 1._dk\nIm(0) = 0._dk\nPn(0) = GM / rNorm\nPn(1) = rho * Pn(0)\ndo n = 1, gdeg\n Rm(n) = s * Rm(n-1) - t * Im(n-1)\n Im(n) = s * Im(n-1) + t * Rm(n-1)\n Pn(n+1) = rho * Pn(n)\n\nend do\n\n! Fill D, E, and F matrices\nskip_EFG = present(pot) .and. .not.(present(FIn)) .and. .not.(present(dPot))\ndo m = 1, gord\n do n = m, gdeg\n Dnm(n,m) = Cnm(n,m)*Rm(m) + Snm(n,m)*Im(m)\n if (.not.(skip_EFG)) then\n Enm(n,m) = Cnm(n,m)*Rm(m-1) + Snm(n,m)*Im(m-1)\n Fnm(n,m) = Snm(n,m)*Rm(m-1) - Cnm(n,m)*Im(m-1)\n\n end if\n end do\n\nend do\ndo n = 1, gdeg\n Dnm(n,0) = Cnm(n,0)*Rm(0) !+ S(n,0)*I(0) = 0\nend do\n\n! ==============================================================================\n! 03. Perturbing potential\n! ==============================================================================\n\nif (present(pot)) then\n pot = 0._dk\n do m = 1, gord\n do n = m, gdeg\n pot = pot + Pn(n) * Anm(n,m) * Dnm(n,m)\n\t\t\n end do\n\t\n end do\n do n = 1, gdeg\n pot = pot + Pn(n) * Anm(n,0) * Dnm(n,0)\n\t\n end do\n pot = -pot ! Change the sign to get the potential\nend if\n\n! ==============================================================================\n! 04. Perturbing acceleration\n! ==============================================================================\n\nif (present(FIn)) then\n a1 = 0._dk; a2 = 0._dk; a3 = 0._dk; a4 = 0._dk\n do m = 1, gord\n do n = m, gdeg\n a1 = a1 + Pn(n+1) * Anm(n,m) * m * Enm(n,m)\n a2 = a2 + Pn(n+1) * Anm(n,m) * m * Fnm(n,m)\n a3 = a3 + Pn(n+1) * Anm(n,m+1) * Dnm(n,m)\n a4 = a4 - Pn(n+1) * Anm(n+1,m+1) * Dnm(n,m)\n end do\n end do\n do n = 1, gdeg\n a3 = a3 + Pn(n+1) * Anm(n,1) * Dnm(n,0)\n a4 = a4 - Pn(n+1) * Anm(n+1,1) * Dnm(n,0)\n\n end do\n F = [a1, a2, a3] + [s, t, u] * a4\n F = F / RE\n\n ! Transform to inertial frame\n FIn(1) = F(1)*cosGMST - F(2)*sinGMST\n FIn(2) = F(1)*sinGMST + F(2)*cosGMST\n FIn(3) = F(3)\n\nend if\n\n! ==============================================================================\n! 05. Time derivative of potential in body-fixed frame\n! ==============================================================================\n\nif(present(dPot)) then\n dPot = 0._dk\n ERR = ERR_IAU06(0._dk, MJD_TT)\n ERR_nd = ERR / TU\n do m = 1, gord\n do n = m, gdeg\n Gnm(n,m) = m * ( t * Enm(n,m) - s * Fnm(n,m) )\n Gnm(n,m) = ERR_nd * Gnm(n,m)\n dPot = dPot + Pn(n) * Anm(n,m) * Gnm(n,m)\n \n end do\n \n end do\n dPot = -dPot\nend if\n\nend subroutine PINES_NSG\n\n\n\n\nend module NSGRAV\n", "meta": {"hexsha": "fb7a488cfa83b5ea3c51d09e233f89ce336f4682", "size": 11900, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "thalassa-master/thalassa_dir/model/nsgrav.f90", "max_stars_repo_name": "isaiasAaraya/TLEanalysis", "max_stars_repo_head_hexsha": "104b6f4fd6da4f78c88c1cf3acc255c3794f5180", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "thalassa-master/thalassa_dir/model/nsgrav.f90", "max_issues_repo_name": "isaiasAaraya/TLEanalysis", "max_issues_repo_head_hexsha": "104b6f4fd6da4f78c88c1cf3acc255c3794f5180", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "thalassa-master/thalassa_dir/model/nsgrav.f90", "max_forks_repo_name": "isaiasAaraya/TLEanalysis", "max_forks_repo_head_hexsha": "104b6f4fd6da4f78c88c1cf3acc255c3794f5180", "max_forks_repo_licenses": ["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.6758104738, "max_line_length": 95, "alphanum_fraction": 0.5667226891, "num_tokens": 3952, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067228145364, "lm_q2_score": 0.7371581626286833, "lm_q1q2_score": 0.6947765240551453}} {"text": "subroutine GetSubsWaveLength(SubsWaveLength)\n!***********************************************************************\n! Copyright 2011 Los Alamos National Security, LLC All rights reserved\n! Unless otherwise indicated, this information has been authored by an\n! employee or employees of the Los Alamos National Security, LLC (LANS),\n! operator of the Los Alamos National Laboratory under Contract No.\n! DE-AC52-06NA25396 with the U. S. Department of Energy. The U. S.\n! Government has rights to use, reproduce, and distribute this\n! information. The public may copy and use this information without\n! charge, provided that this Notice and any statement of authorship are\n! reproduced on all copies. Neither the Government nor LANS makes any\n! warranty, express or implied, or assumes any liability or\n! responsibility for the use of this information. \n!***********************************************************************\n\nuse comdi, only: izone_top,z_plot\nuse comai, only: neq\nuse combi, only: cord\nimplicit none\nreal*8 :: SubsWaveLength,x_min,x_max,x_shift,x_scale,Integral, &\n a_max,DeltaChi,AvgSubs,MaxSubs,MinSubs\nreal*8, allocatable :: Chi(:),Subsid(:),a(:)\ninteger :: I,NumNodes,Counter,n,MaxCoeffNum\ninteger, parameter :: NumCoeffs = 100\nreal*8, parameter :: pi = 3.14159\n\n! top boundary is indicated by the neq entries of izone_top:\n! izone_top(I) = 3 indicates that node I is on the top boundary;\n! izone_top(I) = 0 indicates that node I is not on the top \n! boundary\n\n! cord(I,1) = x coordinates, cord(I,2) = y coordinatess, \n! cord(I,3) = z coordinates\n\n! final heights are in the array z_plot, which also has neq \n! entries\n\n! shift and rescale the x coords so that they lie between\n! 0 and 1; convert resulting wavelength back to meters\n! afterward\n\n! find x_min, x_max, and # of nodes above the subsidence zone\nx_min = 1.e30\nx_max = -1.e30\nNumNodes = 0\ndo I=1,neq\n if (izone_top(I)==3) then\n if (cord(I,1)x_max) then\n x_max = cord(I,1)\n end if\n NumNodes = NumNodes + 1\n end if\nend do\nx_shift = -x_min\nx_scale = (x_max - x_min)\n\nallocate(Chi(NumNodes))\nallocate(Subsid(NumNodes))\nCounter = 1\nAvgSubs = 0.0\nMaxSubs = -1.e30\nMinSubs = 1.e30\ndo I=1,neq\n if (izone_top(I)==3) then\n Chi(Counter) = (cord(I,1) + x_shift)/x_scale\n Subsid(Counter) = z_plot(I)\n if (Subsid(Counter)>MaxSubs) then\n MaxSubs = Subsid(Counter)\n end if\n if (Subsid(Counter)a_max) then\n a_max = dabs(a(n))\n MaxCoeffNum = n\n end if\nend do\n!write(*,*) 'max coeff number: ',MaxCoeffNum\n!write(*,*) 'max coeff: ',a(MaxCoeffNum)\nSubsWaveLength = 2.0*x_scale/MaxCoeffNum\nend\n", "meta": {"hexsha": "3aeebc3383c82a65fc792092c3719d3fbbe9622a", "size": 3475, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/GetSubsWaveLength.f90", "max_stars_repo_name": "satkarra/FEHM", "max_stars_repo_head_hexsha": "5d8d8811bf283fcca0a8a2a1479f442d95371968", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2018-08-09T04:55:28.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-31T21:46:32.000Z", "max_issues_repo_path": "src/GetSubsWaveLength.f90", "max_issues_repo_name": "satkarra/FEHM", "max_issues_repo_head_hexsha": "5d8d8811bf283fcca0a8a2a1479f442d95371968", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 19, "max_issues_repo_issues_event_min_datetime": "2018-04-06T16:17:14.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-14T04:40:14.000Z", "max_forks_repo_path": "src/GetSubsWaveLength.f90", "max_forks_repo_name": "satkarra/FEHM", "max_forks_repo_head_hexsha": "5d8d8811bf283fcca0a8a2a1479f442d95371968", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2018-06-07T21:11:55.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-11T13:48:22.000Z", "avg_line_length": 32.476635514, "max_line_length": 72, "alphanum_fraction": 0.6477697842, "num_tokens": 1106, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941962904955, "lm_q2_score": 0.7690802476562641, "lm_q1q2_score": 0.6947057241895603}} {"text": "\tSUBROUTINE PRNLNR ( np, dlon, iret )\nC************************************************************************\nC* PRNLNR *\nC*\t\t\t\t\t\t\t\t\t*\nC* This function converts a longitude in radians into radians which\t*\nC* fall within the range PI to -PI.\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* PRNLNR ( NP, DLON, IRET )\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*\tNP\t\tINTEGER\t\tNumber of longitudes\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input and output parameters:\t\t\t\t\t\t*\nC*\tDLON (*)\tREAL\t\tLongitude in radians\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tIRET\t\tINTEGER\t\tReturn code\t\t\t*\nC*\t\t\t\t\t 0 = normal\t\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* G. Chatters/RDS\t11/80 \t\t\t\t\t\t*\nC* C. Millburn\t\t 6/84\tRewritten for GEMPAK3\t\t\t*\nC* M. desJardins/GSFC\t 8/87\tCorrected sign of pi in check for <\t*\nC* M. desJardins/GSFC\t 1/88\tFixed missing data\t\t\t*\nC* K. Brill/EMC\t\t 3/96\tAdd loop\t\t\t\t*\nC* M. Linda/GSC\t\t 9/97\tChanged a key word in the prologue\t*\nC* T. Piper/GSC\t\t 3/99\tCorrected prolog\t\t\t*\nC************************************************************************\n\tINCLUDE \t'GEMPRM.PRM'\nC*\n\tREAL\t\tdlon (*)\nC*\n\tINCLUDE\t\t'ERMISS.FNC'\nC------------------------------------------------------------------------\n\tiret = 0\nC*\n\tDO i = 1, np\nC\nC*\tCheck for missing data.\nC\n\t IF ( .not. ERMISS ( dlon (i) ) ) THEN\n dln = dlon (i) - IFIX ( dlon (i) / TWOPI ) * TWOPI\n\t\tIF ( dln .lt. -PI ) dln = dln + TWOPI\n\t\tIF ( dln .gt. PI ) dln = dln - TWOPI\n\t\tdlon (i) = dln\n\t END IF\n\tEND DO\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "4611595f6a59a9a11d66de3f3be19a97514d6906", "size": 1529, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/gemlib/im/prnlnr.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/gemlib/im/prnlnr.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/gemlib/im/prnlnr.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.9803921569, "max_line_length": 73, "alphanum_fraction": 0.455853499, "num_tokens": 523, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942119105695, "lm_q2_score": 0.7690802264851919, "lm_q1q2_score": 0.6947057170789437}} {"text": "!-----subroutine---------------------------------------------g.guidati--\n! \nsubroutine SPL_EX1 (xa, ya, y2a, n, x, y, dydx, khi, klo) \n! \n!-----------------------------------------------------------------------\n! \n! franco guidati IAG\n! Uni Stuttgart\n!\n! modified Pat Moriarty 10/23/03\n! scope execute spline interpolation\n! (natural splines)\n! \n!.......................................................................\n! declarations\n!.......................................................................\n\nUSE TIPrecision\n\nIMPLICIT NONE\n\n\n ! Local variables.\n\nINTEGER(4) :: klo \nINTEGER(4) :: khi \nINTEGER(4) :: n \n\nREAL(DbKi) :: a\nREAL(DbKi) :: b\nREAL(DbKi) :: dydx\nREAL(DbKi) :: h\nREAL(DbKi) :: x\nREAL(DbKi) :: y\nREAL(DbKi) :: xa(n)\nREAL(DbKi) :: ya(n)\nREAL(DbKi) :: y2a(n)\n\n!.......................................................................\n! execute spline interpolation\n!.......................................................................\n\n h = xa(khi)-xa(klo)\n if (h.eq.0.) then\n write(*,*)'ERROR:TINoise:SPL_E0A: bad xa input in splint'\n STOP 1\n endif\n a = (xa(khi)-x)/h\n b = (x-xa(klo))/h\n y = a*ya(klo)+b*ya(khi)+((a*a*a-a)*y2a(klo)+(b*b*b-b)*y2a(khi))*(h*h)/6.0d0\n! write(*,*) '---',real(h),real(y),real(a),real(b)\n dydx = (-ya(klo)+ya(khi))/h+((-3.0d0*a*a+1.0d0)*y2a(klo)+(+3.0d0*b*b-1.0d0)*y2a(khi))*h/6.0d0\n\n!.......................................................................\n! end of subroutine\n!.......................................................................\n return\n!***********************************************************************\n end \n\n", "meta": {"hexsha": "069cb4b37ba16c6a9026745d98370b4d07676e0d", "size": 2026, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "modules/aerodyn/src/AeroAcoustics/TINoise/SPL_EX1.f90", "max_stars_repo_name": "CarloSucameli/Openfast-noise", "max_stars_repo_head_hexsha": "b695c53ff790ac390f9fcf7ec1bf67e24688deb0", "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": "modules/aerodyn/src/AeroAcoustics/TINoise/SPL_EX1.f90", "max_issues_repo_name": "CarloSucameli/Openfast-noise", "max_issues_repo_head_hexsha": "b695c53ff790ac390f9fcf7ec1bf67e24688deb0", "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/aerodyn/src/AeroAcoustics/TINoise/SPL_EX1.f90", "max_forks_repo_name": "CarloSucameli/Openfast-noise", "max_forks_repo_head_hexsha": "b695c53ff790ac390f9fcf7ec1bf67e24688deb0", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.2131147541, "max_line_length": 99, "alphanum_fraction": 0.2872655479, "num_tokens": 470, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9032942041005328, "lm_q2_score": 0.7690802264851919, "lm_q1q2_score": 0.694705711072399}} {"text": " PROGRAM xlaguer\r\nC driver for routine laguer\r\n INTEGER M,MP1,NTRY\r\n REAL EPS\r\n PARAMETER(M=4,MP1=M+1,NTRY=21,EPS=1.0E-6)\r\n INTEGER i,iflag,its,j,n\r\n COMPLEX a(MP1),y(NTRY),x\r\n DATA a/(0.0,2.0),(0.0,0.0),(-1.0,-2.0),(0.0,0.0),(1.0,0.0)/\r\n write(*,'(/1x,a)') 'Roots of polynomial x^4-(1+2i)*x^2+2i'\r\n write(*,'(/1x,t16,a4,t29,a7,t39,a5/)') 'Real','Complex','#iter'\r\n n=0\r\n do 12 i=1,NTRY\r\n x=cmplx((i-11.0)/10.0,(i-11.0)/10.0)\r\n call laguer(a,M,x,its)\r\n if (n.eq.0) then\r\n n=1\r\n y(1)=x\r\n write(*,'(1x,i5,2f15.6,i5)') n,x,its\r\n else\r\n iflag=0\r\n do 11 j=1,n\r\n if (abs(x-y(j)).le.EPS*abs(x)) iflag=1\r\n11 continue\r\n if (iflag.eq.0) then\r\n n=n+1\r\n y(n)=x\r\n write(*,'(1x,i5,2f15.6,i5)') n,x,its\r\n endif\r\n endif\r\n12 continue\r\n END\r\n", "meta": {"hexsha": "11cc51e66e478439c3274c876dbcf91dbf7cbbc2", "size": 940, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xlaguer.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xlaguer.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xlaguer.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.375, "max_line_length": 70, "alphanum_fraction": 0.4436170213, "num_tokens": 382, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.909907010924213, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6946992340816042}} {"text": "!!\n!> @brief fundamental constants\n!!\n!! List of fundamental physical and mathematical constants. Unlike most other modules, all \n!! parameters are public.\n!!\n!! When possible, constants contain more digits than double precision, so that\n!! they are rounded correctly. Single letter constants contain underscore so\n!! that they do not clash with user variables (\"e\" and \"i\" are frequently used as\n!! loop variables)\n!!\n!! @author Rodrigo Navarro Perez\n!!\nmodule constants\nuse precisions, only: dp\nimplicit none\n\npublic\n\nreal(dp), parameter :: pi = 3.1415926535897932384626433832795_dp !< \\f$\\pi\\f$\nreal(dp), parameter :: e_ = 2.7182818284590452353602874713527_dp !< base of the natural log, \\f$ e \\f$\nreal(dp), parameter :: euler_mascheroni = 0.577216_dp!< Euler Mascheroni constant, typically denoted by \\f$ \\gamma \\f$ ! 0.5772156649015328606065120900824_dp \ncomplex(dp), parameter :: i_ = (0, 1) !< \\f$ i = \\sqrt{-1} \\f$\n\n! Values from National Institute of Standards and Technology (NIST CODATA)\n! https://www.nist.gov/pml/fundamental-physical-constants\n! Retrieved on April 8th 2021\nreal(dp), parameter :: hbar_c = 197.3269804_dp!< \\f$\\hbar c\\f$ in units of MeV fm\nreal(dp), parameter :: proton_mass = 938.27208816_dp!< proton mass in units of MeV\nreal(dp), parameter :: neutron_mass = 939.56542052_dp!< neutron mass in units of MeV\nreal(dp), parameter :: electron_mass = 0.51099895000_dp!< electron mass in units of MeV\nreal(dp), parameter :: mu_proton = 2.79284734463_dp!< proton magnetic moment in units of the nuclear magneton \\f$ \\mu_n \\f$\nreal(dp), parameter :: mu_neutron = -1.91304273_dp!< neutron magnetic moment in units of the nuclear magneton \\f$ \\mu_n \\f$\nreal(dp), parameter :: alpha = 1/137.035999084_dp!< fine structure constant, dimensionless. \n\n\n! Values from Particle Data Group (PDG)\n! http://pdg.lbl.gov/\n! P.A. Zyla et al. (Particle Data Group), Prog. Theor. Exp. Phys. 2020, 083C01 (2020)\nreal(dp), parameter :: pion_c_mass = 139.57039_dp!< charged pion_mass in units of MeV\nreal(dp), parameter :: pion_0_mass = 134.9768_dp!< neutral pion_mass in units of MeV\nreal(dp), parameter :: pion_mass = (2*pion_c_mass + pion_0_mass)/3 !< average pion mass in units of MeV\n\n! Historic, charge independent, recommended value.\nreal(dp), parameter :: f_pi_n_2 = 0.075_dp !< pion nucleon coupling constant \\f$ f^2 \\f$. Dimensionless\n\n\n! ! Original AV18 values\n! real(dp), parameter :: hbar_c = 197.327053_dp!< \\f$\\hbar c\\f$ in units of MeV fm\n! real(dp), parameter :: proton_mass = 938.27231_dp!< proton mass in units of MeV\n! real(dp), parameter :: neutron_mass = 939.56563_dp!< neutron mass in units of MeV\n! real(dp), parameter :: electron_mass = 0.510999_dp!< electron mass in units of MeV\n! real(dp), parameter :: mu_proton = 2.7928474_dp!< proton magnetic moment in units of the nuclear magneton \\f$ \\mu_n \\f$\n! real(dp), parameter :: mu_neutron = -1.9130427_dp!< neutron magnetic moment in units of the nuclear magneton \\f$ \\mu_n \\f$\n! real(dp), parameter :: alpha = 1/137.035989_dp!< fine structure constant, dimensionless.\n! real(dp), parameter :: pion_c_mass = 139.5675_dp!< charged pion_mass in units of MeV\n! real(dp), parameter :: pion_0_mass = 134.9739_dp!< neutral pion_mass in units of MeV\n! real(dp), parameter :: pion_mass = 138.0363_dp!< average pion mass in units of MeV\n! real(dp), parameter :: f_pi_n_2 = 0.075_dp !< pion nucleon coupling constant \\f$ f^2 \\f$. Dimensionless\n\nend module\n", "meta": {"hexsha": "aa92acacebc4ccb467021407df49038e3a8c9df6", "size": 3446, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/constants.f90", "max_stars_repo_name": "rnavarroperez/nn-scattering-fit", "max_stars_repo_head_hexsha": "055d21574fc02159ad0e785fa137ddfa874f88da", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-30T02:41:03.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-30T02:41:03.000Z", "max_issues_repo_path": "src/constants.f90", "max_issues_repo_name": "rnavarroperez/nn-scattering-fit", "max_issues_repo_head_hexsha": "055d21574fc02159ad0e785fa137ddfa874f88da", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2020-04-17T02:13:32.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-05T21:11:08.000Z", "max_forks_repo_path": "src/constants.f90", "max_forks_repo_name": "rnavarroperez/nn-scattering-fit", "max_forks_repo_head_hexsha": "055d21574fc02159ad0e785fa137ddfa874f88da", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.5806451613, "max_line_length": 158, "alphanum_fraction": 0.724898433, "num_tokens": 1039, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070011518829, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6946992266205888}} {"text": " FUNCTION rtflsp(func,x1,x2,xacc)\r\n INTEGER MAXIT\r\n REAL rtflsp,x1,x2,xacc,func\r\n EXTERNAL func\r\n PARAMETER (MAXIT=30)\r\n INTEGER j\r\n REAL del,dx,f,fh,fl,swap,xh,xl\r\n fl=func(x1)\r\n fh=func(x2)\r\n if(fl*fh.gt.0.) pause 'root must be bracketed in rtflsp'\r\n if(fl.lt.0.)then\r\n xl=x1\r\n xh=x2\r\n else\r\n xl=x2\r\n xh=x1\r\n swap=fl\r\n fl=fh\r\n fh=swap\r\n endif\r\n dx=xh-xl\r\n do 11 j=1,MAXIT\r\n rtflsp=xl+dx*fl/(fl-fh)\r\n f=func(rtflsp)\r\n if(f.lt.0.) then\r\n del=xl-rtflsp\r\n xl=rtflsp\r\n fl=f\r\n else\r\n del=xh-rtflsp\r\n xh=rtflsp\r\n fh=f\r\n endif\r\n dx=xh-xl\r\n if(abs(del).lt.xacc.or.f.eq.0.)return\r\n11 continue\r\n pause 'rtflsp exceed maximum iterations'\r\n END\r\n", "meta": {"hexsha": "d332e1dca1818cda0a767f3dac820d600c19fb68", "size": 875, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/rtflsp.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/rtflsp.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/rtflsp.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.4358974359, "max_line_length": 63, "alphanum_fraction": 0.472, "num_tokens": 289, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069962657176, "lm_q2_score": 0.7634837527911056, "lm_q1q2_score": 0.6946992081998326}} {"text": "program mapsl\n ! Based on: Justin E. Kerwin December, 2000\n !------------------------------------------------------------------------------\u00ad\n\n !\tDeclare the variables----------------------------------------------------\u00ad\n implicit none\n character(len=1) yesno\n character(len=20) :: buffer\n character(len=20) :: params\n real, parameter :: pi=3.1415927e00, rad=1.7453293e-02\n real :: x,y,theta,rsq,u,v,r,xc,yc,alpha_deg,alpha,rc,beta,rcsq,g,gamma, &\n lambda,tau_deg,xi,eta,x_circle,y_circle,fl2,u_foil,v_foil, &\n theta1,theta2,dtheta,rmax,dr,cp,xle,xte,chord,cl\n real, allocatable, dimension(:) :: xi_foil,cp_foil,eta_foil\n complex :: z,zp1,zm1,zeta,w_circle,dzeta_dz,w_foil\n integer :: n,m,ntheta,nradial\n\n !input the variables defining foil geometry and angle of attack ----------\u00ad\n write(*,'(a)') ' enter xc,yc,trailing edge angle ' ! position of center of circle--------\u00ad\n read(*,*) xc,yc,tau_deg ! note: xc must be <= 0 ------------\u00ad\n lambda=2.0-tau_deg/180.0 ! the exponent in the k-t mapping function -\u00ad\n fl2=4.0*lambda**2 ! pre-comute a mapping function constant----\u00ad\n rcsq=(1.0-xc)**2+yc**2 ! radius of circle passing through (1,0) ---\u00ad\n\n rc=sqrt(rcsq) \n beta=atan(yc/(1.0-xc)) \n\n alpha_deg=0\n theta1=0\n theta2=360\n dtheta=1\n ntheta=nint((theta2+theta1)/dtheta)+1 ! number of radial grid lines \n !\talocate the arrays and open output files --------------------------------\u00ad\n allocate(xi_foil(ntheta),eta_foil(ntheta),cp_foil(ntheta)) ! arrays for foil cp -----\u00ad\n\n buffer=leading_zero(xc)\n params='_'//trim(buffer)\n buffer=leading_zero(yc)\n params=trim(params)//'_'//trim(buffer)\n write(buffer,'(I0)')int(tau_deg)\n params=trim(params)//'_'//trim(buffer)\n! write(buffer,'(I0)')int(alpha_deg)\n! params=trim(params)//'_'//trim(buffer)\n\n! open(2,file='cp-karman-trefftz'//trim(params)//'.dat',status='unknown',form='formatted')\n open(3,file='geom-karman-trefftz'//trim(params)//'.dat',status='unknown',form='formatted')\n\n !-----generate velocity and presure field -------------------------------------\u00ad\n m=1\n r=rc+real(m-1)*dr\n rsq=r**2\n ! grid radial coordinate in the z (circle) plane--\u00ad\n do n=1,ntheta\n theta=rad*(theta1-real(n-1)*dtheta) ! grid angular coordinate--\u00ad\n x=xc+r*cos(theta) ! convert to cartesian-----\u00ad\n y=yc+r*sin(theta)\n !-----------compute the velocity field around the circle-----------------------\u00ad\n u=cos(alpha)-rcsq*cos(2.0*theta-alpha)/rsq-g*sin(theta)/r\n v=sin(alpha)-rcsq*sin(2.0*theta-alpha)/rsq+g*cos(theta)/r\n\n !-----------express the field point position and velocity in complex form------\u00ad\n z=cmplx(x,y) ! form complex number (x+iy)-------\u00ad\n w_circle=cmplx(u,-v)\n ! complex velocity in z plane------\u00ad\n !-----------use the karman-trefftz transformation to map points to zeta plane--\u00ad\n zp1=(z+1.0)**lambda\n zm1=(z-1.0)**lambda\n zeta=lambda*(zp1+zm1)/(zp1-zm1)\n xi=real(zeta) ! transformed x coordinate---------\u00ad\n eta=aimag(zeta) ! transformed y coordinate --------\u00ad\n !-----------compute the derivative of the mapping function; transform velocities\n dzeta_dz=fl2*((z-1.0)**(lambda-1.0)*(z+1.0)**(lambda-1.0))/ (zp1-zm1)**2\n\n if(abs(dzeta_dz)>0.0001) then\n w_foil=w_circle/dzeta_dz ! complex velocity in foil plane------\u00ad\n\n else\n w_foil=0.0\n end if\n u_foil=real(w_foil)\n v_foil=-aimag(w_foil)\n\n ! avoids divide by zero at trailing edge\n\n !-----------compute the presure coefficient, cp, and output to plotting file---\u00ad\n\n cp=abs(w_foil)**2-1.0\n\n if(m==1) then\n ! save presure on foil surface for later use--\u00ad\n xi_foil(n)=xi\n eta_foil(n)=eta\n cp_foil(n)=cp\n end if\n end do\n !-----scale the chordwise coordinate to (0,1) and output foil pressure dist.---\u00ad\n xle=10.0\n xte=-10.0\n do n=1,ntheta\n xle=min(xle,xi_foil(n))\n xte=max(xte,xi_foil(n))\n end do\n ! Coordinate scalling\n chord=xte-xle\n do n=1,ntheta\n xi_foil(n)=(xi_foil(n)-xle)/chord\n eta_foil(n)=eta_foil(n)/chord\n end do\n! write(2,'(2f10.5)') (xi_foil(n),cp_foil(n),n=1,ntheta) \n! close(2) \n\n write(3,'(2f10.5)') (xi_foil(n),eta_foil(n),n=1,ntheta) \n close(3) \n\ncontains\n\n function leading_zero(x) result(buffer)\n real :: x\n character(len=20) :: buffer\n integer :: ix\n if (x.lt.0) then\n ix = ceiling(x)\n else\n ix = floor(x)\n endif\n if (x.lt.0) then\n write(buffer,1) abs(ix), abs(x)-floor(abs(x))\n 1 format('-',i0,f0.1) \n else\n write(buffer,2) floor(x), abs(x)-floor(abs(x))\n 2 format(i0,f0.1)\n endif\n\n end function\n\n\n\n\nend program mapsl\n", "meta": {"hexsha": "f83890b2c82b75f609d9900033efb020f7d4e3b0", "size": 4940, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "welib/airfoils/matlab/KarmanTrefftzGeometry.f90", "max_stars_repo_name": "moonieann/welib", "max_stars_repo_head_hexsha": "0e430ad3ca034d0d2d60bdb7bbe06c947ce08f52", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2019-07-24T23:37:10.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T20:40:40.000Z", "max_issues_repo_path": "welib/airfoils/matlab/KarmanTrefftzGeometry.f90", "max_issues_repo_name": "moonieann/welib", "max_issues_repo_head_hexsha": "0e430ad3ca034d0d2d60bdb7bbe06c947ce08f52", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "welib/airfoils/matlab/KarmanTrefftzGeometry.f90", "max_forks_repo_name": "moonieann/welib", "max_forks_repo_head_hexsha": "0e430ad3ca034d0d2d60bdb7bbe06c947ce08f52", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2019-03-14T13:47:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T15:47:27.000Z", "avg_line_length": 35.2857142857, "max_line_length": 94, "alphanum_fraction": 0.5550607287, "num_tokens": 1524, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632916317102, "lm_q2_score": 0.7490872243177518, "lm_q1q2_score": 0.6946759940625715}} {"text": "!..\n!..file contains fermi-dirac integral routines:\n!..\n!..function zfermim12 does a rational function fit for the order -1/2 integral\n!..function zfermi12 does a rational function fit for the order 1/2 integral\n!..function zfermi1 does a rational function fit for the order 1 integral\n!..function zfermi32 does a rational function fit for the order 3/2 integral\n!..function zfermi2 does a rational function fit for the order 2 integral\n!..function zfermi52 does a rational function fit for the order 5/2 integral\n!..function zfermi3 does a rational function fit for the order 3 integral\n!..\n!..function ifermim12 is a rational function fit for the inverse of order -1/2\n!..function ifermi12 is a rational function fit for the inverse of order 1/2\n!..function ifermi32 is a rational function fit for the inverse of order 3/2\n!..function ifermi52 is a rational function fit for the inverse of order 5/2\n\nmodule fermi\n\ncontains\n\n double precision function zfermim12(x)\n! include 'implno.dek'\n!..\n!..this routine applies a rational function expansion to get the fermi-dirac\n!..integral of order -1/2 evaluated at x. maximum error is 1.23d-12.\n!..reference: antia apjs 84,101 1993\n!..\n!..declare\n integer i,m1,k1,m2,k2\n double precision x,an,a1(12),b1(12),a2(12),b2(12),rn,den,xx\n\n!..load the coefficients of the expansion\n data an,m1,k1,m2,k2 /-0.5d0, 7, 7, 11, 11/\n data (a1(i),i=1,8)/ 1.71446374704454d7, 3.88148302324068d7, &\n 3.16743385304962d7, 1.14587609192151d7, &\n 1.83696370756153d6, 1.14980998186874d5, &\n 1.98276889924768d3, 1.0d0/\n data (b1(i),i=1,8)/ 9.67282587452899d6, 2.87386436731785d7, &\n 3.26070130734158d7, 1.77657027846367d7, &\n 4.81648022267831d6, 6.13709569333207d5, &\n 3.13595854332114d4, 4.35061725080755d2/\n data (a2(i),i=1,12)/-4.46620341924942d-15, -1.58654991146236d-12, &\n -4.44467627042232d-10, -6.84738791621745d-8, &\n -6.64932238528105d-6, -3.69976170193942d-4, &\n -1.12295393687006d-2, -1.60926102124442d-1, &\n -8.52408612877447d-1, -7.45519953763928d-1, &\n 2.98435207466372d0, 1.0d0/\n data (b2(i),i=1,12)/-2.23310170962369d-15, -7.94193282071464d-13, &\n -2.22564376956228d-10, -3.43299431079845d-8, &\n -3.33919612678907d-6, -1.86432212187088d-4, &\n -5.69764436880529d-3, -8.34904593067194d-2, &\n -4.78770844009440d-1, -4.99759250374148d-1, &\n 1.86795964993052d0, 4.16485970495288d-1/\n\n\n if (x .lt. 2.0d0) then\n xx = exp(x)\n rn = xx + a1(m1)\n do i=m1-1,1,-1\n rn = rn*xx + a1(i)\n enddo\n den = b1(k1+1)\n do i=k1,1,-1\n den = den*xx + b1(i)\n enddo\n zfermim12 = xx * rn/den\n!..\n else\n xx = 1.0d0/(x*x)\n rn = xx + a2(m2)\n do i=m2-1,1,-1\n rn = rn*xx + a2(i)\n enddo\n den = b2(k2+1)\n do i=k2,1,-1\n den = den*xx + b2(i)\n enddo\n zfermim12 = sqrt(x)*rn/den\n end if\n return\n end\n\n\n\n\n\n\n double precision function zfermi12(x)\n! include 'implno.dek'\n!..\n!..this routine applies a rational function expansion to get the fermi-dirac\n!..integral of order 1/2 evaluated at x. maximum error is 5.47d-13.\n!..reference: antia apjs 84,101 1993\n!..\n!..declare\n integer i,m1,k1,m2,k2\n double precision x,an,a1(12),b1(12),a2(12),b2(12),rn,den,xx\n\n\n!..load the coefficients of the expansion\n data an,m1,k1,m2,k2 /0.5d0, 7, 7, 10, 11/\n data (a1(i),i=1,8)/5.75834152995465d6, 1.30964880355883d7, &\n 1.07608632249013d7, 3.93536421893014d6, &\n 6.42493233715640d5, 4.16031909245777d4, &\n 7.77238678539648d2, 1.0d0/\n data (b1(i),i=1,8)/6.49759261942269d6, 1.70750501625775d7, &\n 1.69288134856160d7, 7.95192647756086d6, &\n 1.83167424554505d6, 1.95155948326832d5, &\n 8.17922106644547d3, 9.02129136642157d1/\n data (a2(i),i=1,11)/4.85378381173415d-14, 1.64429113030738d-11, &\n 3.76794942277806d-9, 4.69233883900644d-7, &\n 3.40679845803144d-5, 1.32212995937796d-3, &\n 2.60768398973913d-2, 2.48653216266227d-1, &\n 1.08037861921488d0, 1.91247528779676d0, &\n 1.0d0/\n data (b2(i),i=1,12)/7.28067571760518d-14, 2.45745452167585d-11, &\n 5.62152894375277d-9, 6.96888634549649d-7, &\n 5.02360015186394d-5, 1.92040136756592d-3, &\n 3.66887808002874d-2, 3.24095226486468d-1, &\n 1.16434871200131d0, 1.34981244060549d0, &\n 2.01311836975930d-1, -2.14562434782759d-2/\n\n\n if (x .lt. 2.0d0) then\n xx = exp(x)\n rn = xx + a1(m1)\n do i=m1-1,1,-1\n rn = rn*xx + a1(i)\n enddo\n den = b1(k1+1)\n do i=k1,1,-1\n den = den*xx + b1(i)\n enddo\n zfermi12 = xx * rn/den\n\n else\n xx = 1.0d0/(x*x)\n rn = xx + a2(m2)\n do i=m2-1,1,-1\n rn = rn*xx + a2(i)\n enddo\n den = b2(k2+1)\n do i=k2,1,-1\n den = den*xx + b2(i)\n enddo\n zfermi12 = x*sqrt(x)*rn/den\n end if\n return\n end\n\n\n\n\n\n double precision function zfermi1(x)\n! include 'implno.dek'\n!..\n!..this routine applies a rational function expansion to get the fermi-dirac\n!..integral of order 1 evaluated at x. maximum error is 1.0e-8.\n!..reference: antia priv comm. 11sep94\n!..\n!..declare\n integer i,m1,k1,m2,k2\n double precision x,an,a1(12),b1(12),a2(12),b2(12),rn,den,xx\n\n!..load the coefficients of the expansion\n data an,m1,k1,m2,k2 /1.0, 7, 4, 9, 5/\n data (a1(i),i=1,8)/-7.606458638543d7, -1.143519707857d8, &\n -5.167289383236d7, -7.304766495775d6, &\n -1.630563622280d5, 3.145920924780d3, &\n -7.156354090495d1, 1.0d0/\n data (b1(i),i=1,5)/-7.606458639561d7, -1.333681162517d8, &\n -7.656332234147d7, -1.638081306504d7, &\n -1.044683266663d6/\n data (a2(i),i=1,10)/-3.493105157219d-7, -5.628286279892d-5, &\n -5.188757767899d-3, -2.097205947730d-1, &\n -3.353243201574d0, -1.682094530855d1, &\n -2.042542575231d1, 3.551366939795d0, &\n -2.400826804233d0, 1.0d0/\n data (b2(i),i=1,6)/-6.986210315105d-7, -1.102673536040d-4, &\n -1.001475250797d-2, -3.864923270059d-1, &\n -5.435619477378d0, -1.563274262745d1/\n\n\n if (x .lt. 2.0d0) then\n xx = exp(x)\n rn = xx + a1(m1)\n do i=m1-1,1,-1\n rn = rn*xx + a1(i)\n enddo\n den = b1(k1+1)\n do i=k1,1,-1\n den = den*xx + b1(i)\n enddo\n zfermi1 = xx * rn/den\n\n else\n xx = 1.0d0/(x*x)\n rn = xx + a2(m2)\n do i=m2-1,1,-1\n rn = rn*xx + a2(i)\n enddo\n den = b2(k2+1)\n do i=k2,1,-1\n den = den*xx + b2(i)\n enddo\n zfermi1 = x*x*rn/den\n end if\n return\n end\n\n\n\n\n\n double precision function zfermi32(x)\n! include 'implno.dek'\n!..\n!..this routine applies a rational function expansion to get the fermi-dirac\n!..integral of order 3/2 evaluated at x. maximum error is 5.07d-13.\n!..reference: antia apjs 84,101 1993\n!..\n!..declare\n integer i,m1,k1,m2,k2\n double precision x,an,a1(12),b1(12),a2(12),b2(12),rn,den,xx\n\n!..load the coefficients of the expansion\n data an,m1,k1,m2,k2 /1.5d0, 6, 7, 9, 10/\n data (a1(i),i=1,7)/4.32326386604283d4, 8.55472308218786d4, &\n 5.95275291210962d4, 1.77294861572005d4, &\n 2.21876607796460d3, 9.90562948053193d1, &\n 1.0d0/\n data (b1(i),i=1,8)/3.25218725353467d4, 7.01022511904373d4, &\n 5.50859144223638d4, 1.95942074576400d4, &\n 3.20803912586318d3, 2.20853967067789d2, &\n 5.05580641737527d0, 1.99507945223266d-2/\n data (a2(i),i=1,10)/2.80452693148553d-13, 8.60096863656367d-11, &\n 1.62974620742993d-8, 1.63598843752050d-6, &\n 9.12915407846722d-5, 2.62988766922117d-3, &\n 3.85682997219346d-2, 2.78383256609605d-1, &\n 9.02250179334496d-1, 1.0d0/\n data (b2(i),i=1,11)/7.01131732871184d-13, 2.10699282897576d-10, &\n 3.94452010378723d-8, 3.84703231868724d-6, &\n 2.04569943213216d-4, 5.31999109566385d-3, &\n 6.39899717779153d-2, 3.14236143831882d-1, &\n 4.70252591891375d-1, -2.15540156936373d-2, &\n 2.34829436438087d-3/\n\n\n if (x .lt. 2.0d0) then\n xx = exp(x)\n rn = xx + a1(m1)\n do i=m1-1,1,-1\n rn = rn*xx + a1(i)\n enddo\n den = b1(k1+1)\n do i=k1,1,-1\n den = den*xx + b1(i)\n enddo\n zfermi32 = xx * rn/den\n\n else\n xx = 1.0d0/(x*x)\n rn = xx + a2(m2)\n do i=m2-1,1,-1\n rn = rn*xx + a2(i)\n enddo\n den = b2(k2+1)\n do i=k2,1,-1\n den = den*xx + b2(i)\n enddo\n zfermi32 = x*x*sqrt(x)*rn/den\n end if\n return\n end\n\n\n\n\n double precision function zfermi2(x)\n! include 'implno.dek'\n!..\n!..this routine applies a rational function expansion to get the fermi-dirac\n!..integral of order 2 evaluated at x. maximum error is 1.0e-8.\n!..reference: antia priv comm. 11sep94\n!..\n!..declare\n integer i,m1,k1,m2,k2\n double precision x,an,a1(12),b1(12),a2(12),b2(12),rn,den,xx\n\n!..load the coefficients of the expansion\n data an,m1,k1,m2,k2 /2.0, 7, 4, 5, 9/\n data (a1(i),i=1,8)/-1.434885992395d8, -2.001711155617d8, &\n -8.507067153428d7, -1.175118281976d7, &\n -3.145120854293d5, 4.275771034579d3, &\n -8.069902926891d1, 1.0d0/\n data (b1(i),i=1,5)/-7.174429962316d7, -1.090535948744d8, &\n -5.350984486022d7, -9.646265123816d6, &\n -5.113415562845d5/\n data (a2(i),i=1,6)/ 6.919705180051d-8, 1.134026972699d-5, &\n 7.967092675369d-4, 2.432500578301d-2, &\n 2.784751844942d-1, 1.0d0/\n data (b2(i),i=1,10)/ 2.075911553728d-7, 3.197196691324d-5, &\n 2.074576609543d-3, 5.250009686722d-2, &\n 3.171705130118d-1, -1.147237720706d-1, &\n 6.638430718056d-2, -1.356814647640d-2, &\n -3.648576227388d-2, 3.621098757460d-2/\n\n\n if (x .lt. 2.0d0) then\n xx = exp(x)\n rn = xx + a1(m1)\n do i=m1-1,1,-1\n rn = rn*xx + a1(i)\n enddo\n den = b1(k1+1)\n do i=k1,1,-1\n den = den*xx + b1(i)\n enddo\n zfermi2 = xx * rn/den\n\n else\n xx = 1.0d0/(x*x)\n rn = xx + a2(m2)\n do i=m2-1,1,-1\n rn = rn*xx + a2(i)\n enddo\n den = b2(k2+1)\n do i=k2,1,-1\n den = den*xx + b2(i)\n enddo\n zfermi2 = x*x*x*rn/den\n end if\n return\n end\n\n\n\n\n\n\n double precision function zfermi52(x)\n! include 'implno.dek'\n!..\n!..this routine applies a rational function expansion to get the fermi-dirac\n!..integral of order 5/2 evaluated at x. maximum error is 2.47d-13.\n!..reference: antia apjs 84,101 1993\n!..\n!..declare\n integer i,m1,k1,m2,k2\n double precision x,an,a1(12),b1(12),a2(12),b2(12),rn,den,xx\n\n!..load the coefficients of the expansion\n data an,m1,k1,m2,k2 /2.5d0, 6, 7, 10, 9/\n data (a1(i),i=1,7)/6.61606300631656d4, 1.20132462801652d5, &\n 7.67255995316812d4, 2.10427138842443d4, &\n 2.44325236813275d3, 1.02589947781696d2, &\n 1.0d0/\n data (b1(i),i=1,8)/1.99078071053871d4, 3.79076097261066d4, &\n 2.60117136841197d4, 7.97584657659364d3, &\n 1.10886130159658d3, 6.35483623268093d1, &\n 1.16951072617142d0, 3.31482978240026d-3/\n data (a2(i),i=1,11)/8.42667076131315d-12, 2.31618876821567d-9, &\n 3.54323824923987d-7, 2.77981736000034d-5, &\n 1.14008027400645d-3, 2.32779790773633d-2, &\n 2.39564845938301d-1, 1.24415366126179d0, &\n 3.18831203950106d0, 3.42040216997894d0, &\n 1.0d0/\n data (b2(i),i=1,10)/2.94933476646033d-11, 7.68215783076936d-9, &\n 1.12919616415947d-6, 8.09451165406274d-5, &\n 2.81111224925648d-3, 3.99937801931919d-2, &\n 2.27132567866839d-1, 5.31886045222680d-1, &\n 3.70866321410385d-1, 2.27326643192516d-2/\n\n\n if (x .lt. 2.0d0) then\n xx = exp(x)\n rn = xx + a1(m1)\n do i=m1-1,1,-1\n rn = rn*xx + a1(i)\n enddo\n den = b1(k1+1)\n do i=k1,1,-1\n den = den*xx + b1(i)\n enddo\n zfermi52 = xx * rn/den\n\n else\n xx = 1.0d0/(x*x)\n rn = xx + a2(m2)\n do i=m2-1,1,-1\n rn = rn*xx + a2(i)\n enddo\n den = b2(k2+1)\n do i=k2,1,-1\n den = den*xx + b2(i)\n enddo\n zfermi52 = x*x*x*sqrt(x)*rn/den\n end if\n return\n end\n\n\n\n\n\n double precision function zfermi3(x)\n! include 'implno.dek'\n!..\n!..this routine applies a rational function expansion to get the fermi-dirac\n!..integral of order 3 evaluated at x. maximum error is 1.0e-8.\n!..reference: antia priv comm. 11sep94\n!..\n!..declare\n integer i,m1,k1,m2,k2\n double precision x,an,a1(12),b1(12),a2(12),b2(12),rn,den,xx\n\n!..load the coefficients of the expansion\n data an,m1,k1,m2,k2 /3.0, 4, 6, 7, 7/\n data (a1(i),i=1,5)/ 6.317036716422d2, 7.514163924637d2, &\n 2.711961035750d2, 3.274540902317d1, &\n 1.0d0/\n data (b1(i),i=1,7)/ 1.052839452797d2, 1.318163114785d2, &\n 5.213807524405d1, 7.500064111991d0, &\n 3.383020205492d-1, 2.342176749453d-3, &\n -8.445226098359d-6/\n data (a2(i),i=1,8)/ 1.360999428425d-8, 1.651419468084d-6, &\n 1.021455604288d-4, 3.041270709839d-3, &\n 4.584298418374d-2, 3.440523212512d-1, &\n 1.077505444383d0, 1.0d0/\n data (b2(i),i=1,8)/ 5.443997714076d-8, 5.531075760054d-6, &\n 2.969285281294d-4, 6.052488134435d-3, &\n 5.041144894964d-2, 1.048282487684d-1, &\n 1.280969214096d-2, -2.851555446444d-3/\n\n\n if (x .lt. 2.0d0) then\n xx = exp(x)\n rn = xx + a1(m1)\n do i=m1-1,1,-1\n rn = rn*xx + a1(i)\n enddo\n den = b1(k1+1)\n do i=k1,1,-1\n den = den*xx + b1(i)\n enddo\n zfermi3 = xx * rn/den\n\n else\n xx = 1.0d0/(x*x)\n rn = xx + a2(m2)\n do i=m2-1,1,-1\n rn = rn*xx + a2(i)\n enddo\n den = b2(k2+1)\n do i=k2,1,-1\n den = den*xx + b2(i)\n enddo\n zfermi3 = x*x*x*x*rn/den\n end if\n return\n end\n\n\n\n\n\n double precision function ifermim12(f)\n! include 'implno.dek'\n!..\n!..this routine applies a rational function expansion to get the inverse\n!..fermi-dirac integral of order -1/2 when it is equal to f.\n!..maximum error is 3.03d-9. reference: antia apjs 84,101 1993\n!..\n!..declare\n integer i,m1,k1,m2,k2\n double precision f,an,a1(12),b1(12),a2(12),b2(12),rn,den,ff\n\n!..load the coefficients of the expansion\n data an,m1,k1,m2,k2 /-0.5d0, 5, 6, 6, 6/\n data (a1(i),i=1,6)/-1.570044577033d4, 1.001958278442d4, &\n -2.805343454951d3, 4.121170498099d2, &\n -3.174780572961d1, 1.0d0/\n data (b1(i),i=1,7)/-2.782831558471d4, 2.886114034012d4, &\n -1.274243093149d4, 3.063252215963d3, &\n -4.225615045074d2, 3.168918168284d1, &\n -1.008561571363d0/\n data (a2(i),i=1,7)/ 2.206779160034d-8, -1.437701234283d-6, &\n 6.103116850636d-5, -1.169411057416d-3, &\n 1.814141021608d-2, -9.588603457639d-2, &\n 1.0d0/\n data (b2(i),i=1,7)/ 8.827116613576d-8, -5.750804196059d-6, &\n 2.429627688357d-4, -4.601959491394d-3, &\n 6.932122275919d-2, -3.217372489776d-1, &\n 3.124344749296d0/\n\n if (f .lt. 4.0d0) then\n rn = f + a1(m1)\n do i=m1-1,1,-1\n rn = rn*f + a1(i)\n enddo\n den = b1(k1+1)\n do i=k1,1,-1\n den = den*f + b1(i)\n enddo\n ifermim12 = log(f * rn/den)\n\n else\n ff = 1.0d0/f**(1.0d0/(1.0d0 + an))\n rn = ff + a2(m2)\n do i=m2-1,1,-1\n rn = rn*ff + a2(i)\n enddo\n den = b2(k2+1)\n do i=k2,1,-1\n den = den*ff + b2(i)\n enddo\n ifermim12 = rn/(den*ff)\n end if\n return\n end\n\n\n\n\n\n\n double precision function ifermi12(f)\n! include 'implno.dek'\n!..\n!..this routine applies a rational function expansion to get the inverse\n!..fermi-dirac integral of order 1/2 when it is equal to f.\n!..maximum error is 4.19d-9. reference: antia apjs 84,101 1993\n!..\n!..declare\n integer i,m1,k1,m2,k2\n double precision f,an,a1(12),b1(12),a2(12),b2(12),rn,den,ff\n\n!..load the coefficients of the expansion\n data an,m1,k1,m2,k2 /0.5d0, 4, 3, 6, 5/\n data (a1(i),i=1,5)/ 1.999266880833d4, 5.702479099336d3, &\n 6.610132843877d2, 3.818838129486d1, &\n 1.0d0/\n data (b1(i),i=1,4)/ 1.771804140488d4, -2.014785161019d3, &\n 9.130355392717d1, -1.670718177489d0/\n data (a2(i),i=1,7)/-1.277060388085d-2, 7.187946804945d-2, &\n -4.262314235106d-1, 4.997559426872d-1, &\n -1.285579118012d0, -3.930805454272d-1, &\n 1.0d0/\n data (b2(i),i=1,6)/-9.745794806288d-3, 5.485432756838d-2, &\n -3.299466243260d-1, 4.077841975923d-1, &\n -1.145531476975d0, -6.067091689181d-2/\n\n\n if (f .lt. 4.0d0) then\n rn = f + a1(m1)\n do i=m1-1,1,-1\n rn = rn*f + a1(i)\n enddo\n den = b1(k1+1)\n do i=k1,1,-1\n den = den*f + b1(i)\n enddo\n ifermi12 = log(f * rn/den)\n\n else\n ff = 1.0d0/f**(1.0d0/(1.0d0 + an))\n rn = ff + a2(m2)\n do i=m2-1,1,-1\n rn = rn*ff + a2(i)\n enddo\n den = b2(k2+1)\n do i=k2,1,-1\n den = den*ff + b2(i)\n enddo\n ifermi12 = rn/(den*ff)\n end if\n return\n end\n\n\n\n\n\n\n double precision function ifermi32(f)\n! include 'implno.dek'\n!..\n!..this routine applies a rational function expansion to get the inverse\n!..fermi-dirac integral of order 3/2 when it is equal to f.\n!..maximum error is 2.26d-9. reference: antia apjs 84,101 1993\n!..\n!..declare\n integer i,m1,k1,m2,k2\n double precision f,an,a1(12),b1(12),a2(12),b2(12),rn,den,ff\n\n!..load the coefficients of the expansion\n data an,m1,k1,m2,k2 /1.5d0, 3, 4, 6, 5/\n data (a1(i),i=1,4)/ 1.715627994191d2, 1.125926232897d2, &\n 2.056296753055d1, 1.0d0/\n data (b1(i),i=1,5)/ 2.280653583157d2, 1.193456203021d2, &\n 1.167743113540d1, -3.226808804038d-1, &\n 3.519268762788d-3/\n data (a2(i),i=1,7)/-6.321828169799d-3, -2.183147266896d-2, &\n -1.057562799320d-1, -4.657944387545d-1, &\n -5.951932864088d-1, 3.684471177100d-1, &\n 1.0d0/\n data (b2(i),i=1,6)/-4.381942605018d-3, -1.513236504100d-2, &\n -7.850001283886d-2, -3.407561772612d-1, &\n -5.074812565486d-1, -1.387107009074d-1/\n\n\n if (f .lt. 4.0d0) then\n rn = f + a1(m1)\n do i=m1-1,1,-1\n rn = rn*f + a1(i)\n enddo\n den = b1(k1+1)\n do i=k1,1,-1\n den = den*f + b1(i)\n enddo\n ifermi32 = log(f * rn/den)\n\n else\n ff = 1.0d0/f**(1.0d0/(1.0d0 + an))\n rn = ff + a2(m2)\n do i=m2-1,1,-1\n rn = rn*ff + a2(i)\n enddo\n den = b2(k2+1)\n do i=k2,1,-1\n den = den*ff + b2(i)\n enddo\n ifermi32 = rn/(den*ff)\n end if\n return\n end\n\n\n\n\n\n double precision function ifermi52(f)\n! include 'implno.dek'\n!..\n!..this routine applies a rational function expansion to get the inverse\n!..fermi-dirac integral of order 5/2 when it is equal to f.\n!..maximum error is 6.17d-9. reference: antia apjs 84,101 1993\n!..\n!..declare\n integer i,m1,k1,m2,k2\n double precision f,an,a1(12),b1(12),a2(12),b2(12),rn,den,ff\n\n!..load the coefficients of the expansion\n data an,m1,k1,m2,k2 /2.5d0, 2, 3, 6, 6/\n data (a1(i),i=1,3)/ 2.138969250409d2, 3.539903493971d1, &\n 1.0d0/\n data (b1(i),i=1,4)/ 7.108545512710d2, 9.873746988121d1, &\n 1.067755522895d0, -1.182798726503d-2/\n data (a2(i),i=1,7)/-3.312041011227d-2, 1.315763372315d-1, &\n -4.820942898296d-1, 5.099038074944d-1, &\n 5.495613498630d-1, -1.498867562255d0, &\n 1.0d0/\n data (b2(i),i=1,7)/-2.315515517515d-2, 9.198776585252d-2, &\n -3.835879295548d-1, 5.415026856351d-1, &\n -3.847241692193d-1, 3.739781456585d-2, &\n -3.008504449098d-2/\n\n\n if (f .lt. 4.0d0) then\n rn = f + a1(m1)\n do i=m1-1,1,-1\n rn = rn*f + a1(i)\n enddo\n den = b1(k1+1)\n do i=k1,1,-1\n den = den*f + b1(i)\n enddo\n ifermi52 = log(f * rn/den)\n\n else\n ff = 1.0d0/f**(1.0d0/(1.0d0 + an))\n rn = ff + a2(m2)\n do i=m2-1,1,-1\n rn = rn*ff + a2(i)\n enddo\n den = b2(k2+1)\n do i=k2,1,-1\n den = den*ff + b2(i)\n enddo\n ifermi52 = rn/(den*ff)\n end if\n return\n end\nend module fermi", "meta": {"hexsha": "196c6cca8ffc527eb5eeb24e9b581b1cc4906e41", "size": 23264, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "dStar_eos/private/funct_fermi1.f", "max_stars_repo_name": "LBJ-Wade/dStar", "max_stars_repo_head_hexsha": "d63b1a611937e8eccfb3c98ebbbdb4cd0c2fd19b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2015-05-19T18:15:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-19T08:24:00.000Z", "max_issues_repo_path": "dStar_eos/private/funct_fermi1.f", "max_issues_repo_name": "LBJ-Wade/dStar", "max_issues_repo_head_hexsha": "d63b1a611937e8eccfb3c98ebbbdb4cd0c2fd19b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2015-04-02T20:54:24.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-09T17:12:07.000Z", "max_forks_repo_path": "dStar_eos/private/funct_fermi1.f", "max_forks_repo_name": "LBJ-Wade/dStar", "max_forks_repo_head_hexsha": "d63b1a611937e8eccfb3c98ebbbdb4cd0c2fd19b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2015-04-02T19:01:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-06T12:22:52.000Z", "avg_line_length": 33.473381295, "max_line_length": 78, "alphanum_fraction": 0.5056740028, "num_tokens": 9062, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632876167044, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6946759806657086}} {"text": "\nsubroutine compute_flux (lo, hi, domlo, domhi, phi, philo, phihi, &\n fluxx, fxlo, fxhi, fluxy, fylo, fyhi,f, flo,fhi, &\n dx,n) bind(C, name=\"compute_flux\")\n\n ! Compute the flux for the nth rhs term\n\n use amrex_fort_module, only : amrex_real\n implicit none\n\n integer lo(2), hi(2), domlo(2), domhi(2)\n integer philo(2), phihi(2), fxlo(2), fxhi(2), fylo(2), fyhi(2),flo(2), fhi(2)\n real(amrex_real), intent(in) :: phi (philo(1):phihi(1),philo(2):phihi(2))\n real(amrex_real), intent(inout) :: fluxx( fxlo(1): fxhi(1), fxlo(2): fxhi(2))\n real(amrex_real), intent(inout) :: fluxy( fylo(1): fyhi(1), fylo(2): fyhi(2))\n real(amrex_real), intent(inout) :: f (flo(1):fhi(1),flo(2):fhi(2))\n real(amrex_real), intent(in) :: dx(2)\n integer, intent(in) :: n\n\n \n ! local variables\n integer i,j\n\n select case(n)\n case (0) ! Explicit term (here it is advection)\n ! x-fluxes\n do j = lo(2), hi(2)\n do i = lo(1), hi(1)+1\n fluxx(i,j) = ( phi(i,j) + phi(i-1,j) ) / 2.0d0 \n fluxx(i,j) = (-phi(i+1,j)+ 7.0d0*( phi(i,j) + phi(i-1,j) )-phi(i-2,j)) / 12.0d0\n end do\n end do\n \n ! y-fluxes\n do j = lo(2), hi(2)+1\n do i = lo(1), hi(1)\n fluxy(i,j) =(-phi(i,j+1)+7.0d0*( phi(i,j) + phi(i,j-1) )-phi(i,j-2)) / 12.0d0\n end do\n end do\n\n ! Function value is divergence of flux\n do j = lo(2), hi(2)\n do i = lo(1), hi(1)\n f(i,j) = (fluxx(i+1,j ) - fluxx(i,j))/dx(1) &\n + (fluxy(i ,j+1) - fluxy(i,j))/dx(2)\n f(i,j)=0.0d0\n end do\n \n end do\n case (1) ! First implicit piece (here it is diffusion)\n ! x-fluxes\n do j = lo(2), hi(2)\n do i = lo(1), hi(1)+1\n fluxx(i,j) = ( phi(i,j) - phi(i-1,j) ) / dx(1)\n! fluxx(i,j) = ( -phi(i+1,j) +15.0d0*(phi(i,j) - phi(i-1,j)) + phi(i-2,j) ) /(12.0d0*dx(1))\n end do\n end do\n \n ! y-fluxes\n do j = lo(2), hi(2)+1\n do i = lo(1), hi(1)\n fluxy(i,j) = ( phi(i,j) - phi(i,j-1) ) / dx(2)\n! fluxy(i,j) = ( -phi(i,j+1) +15.0d0*(phi(i,j) - phi(i,j-1)) + phi(i,j-2) ) /(12.0d0*dx(2))\n end do\n end do\n\n ! Function value is divergence of flux\n do j = lo(2), hi(2)\n do i = lo(1), hi(1)\n f(i,j) = (fluxx(i+1,j ) - fluxx(i,j))/dx(1) &\n + (fluxy(i ,j+1) - fluxy(i,j))/dx(2)\n f(i,j)=f(i,j)*0.1d0\n end do\n end do\n case default\n print *, 'bad case in advance_2d'\n end select\n \nend subroutine compute_flux\n\n\n\n", "meta": {"hexsha": "cbef5cfa3ea55a7841b0c8cdb0e31a2e30b1143e", "size": 2745, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorials/SDC/IMEX_Advec_Diff_C/advance_2d.f90", "max_stars_repo_name": "ylunalin/amrex", "max_stars_repo_head_hexsha": "5715b2fc8a77e0db17bfe7907982e29ec44811ca", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Tutorials/SDC/IMEX_Advec_Diff_C/advance_2d.f90", "max_issues_repo_name": "ylunalin/amrex", "max_issues_repo_head_hexsha": "5715b2fc8a77e0db17bfe7907982e29ec44811ca", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Tutorials/SDC/IMEX_Advec_Diff_C/advance_2d.f90", "max_forks_repo_name": "ylunalin/amrex", "max_forks_repo_head_hexsha": "5715b2fc8a77e0db17bfe7907982e29ec44811ca", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-01-17T05:00:26.000Z", "max_forks_repo_forks_event_max_datetime": "2020-01-17T05:00:26.000Z", "avg_line_length": 33.0722891566, "max_line_length": 105, "alphanum_fraction": 0.4546448087, "num_tokens": 1038, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632916317102, "lm_q2_score": 0.749087201911703, "lm_q1q2_score": 0.6946759732840243}} {"text": "module slf_histo\n\n use iso_fortran_env, only: r64 => real64\n implicit none\n\ncontains\n\n subroutine histo(x,min,max,h,loc)\n real(r64), intent(in) :: x(:)\n real(r64), intent(in) :: min,max\n real(r64), intent(out) :: h(:)\n real(r64), intent(out), optional :: loc(:)\n real(r64) :: bin\n integer :: n,nb,i,k\n n = size(x)\n nb = size(h)\n bin = (max-min)/nb\n h = 0\n do i=1,n\n k = floor((x(i) - min) / bin) + 1\n if (k .ge. 1 .and. k .le. nb) h(k) = h(k) + 1d0 / n\n end do\n if (present(loc)) then\n do i=1,nb\n loc(i) = (i-0.5) * bin + min\n end do\n end if\n end subroutine\n\n subroutine histo2d(x,y,xlim,ylim,h,locx,locy)\n real(r64), intent(in) :: x(:), y(:)\n real(r64), intent(in) :: xlim(2), ylim(2)\n real(r64), intent(out) :: h(:,:)\n real(r64), intent(out), optional :: locx(:,:), locy(:,:)\n real(r64) :: xbin, ybin\n integer :: n,nx,ny,i,j,k\n n = size(x)\n nx = size(h,1)\n ny = size(h,2)\n xbin = (xlim(2)-xlim(1))/nx\n ybin = (ylim(2)-ylim(1))/ny\n h = 0\n do i=1,n\n j = floor((x(i) - xlim(1)) / xbin) + 1\n k = floor((y(i) - ylim(1)) / ybin) + 1\n if (j .ge. 1 .and. j .le. nx &\n .and. k .ge. 1 .and. k .le. ny) h(j,k) = h(j,k) + 1d0 / n\n end do\n if (present(locx)) then\n do i=1,nx\n do j=1,ny\n locx(i,j) = (i-0.5) * xbin + xlim(1)\n end do\n end do\n end if\n if (present(locy)) then\n do i=1,nx\n do j=1,ny\n locy(i,j) = (j-0.5) * ybin + ylim(1)\n end do\n end do\n end if\n end subroutine\n\n\nend module\n", "meta": {"hexsha": "e329c81dbd77f4183a8510408f2eb4e96f1928a1", "size": 1875, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/math/histogram.f90", "max_stars_repo_name": "gronki/pydiskvert", "max_stars_repo_head_hexsha": "da9fc71acbdaf48b67a372c51481b30f30c88d29", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/math/histogram.f90", "max_issues_repo_name": "gronki/pydiskvert", "max_issues_repo_head_hexsha": "da9fc71acbdaf48b67a372c51481b30f30c88d29", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/math/histogram.f90", "max_forks_repo_name": "gronki/pydiskvert", "max_forks_repo_head_hexsha": "da9fc71acbdaf48b67a372c51481b30f30c88d29", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.9850746269, "max_line_length": 74, "alphanum_fraction": 0.4106666667, "num_tokens": 638, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319862, "lm_q2_score": 0.7931059536292271, "lm_q1q2_score": 0.694591882329547}} {"text": "! MIT License\n!\n! Copyright (c) 2016 Anders Steen Christensen\n!\n! Permission is hereby granted, free of charge, to any person obtaining a copy\n! of this software and associated documentation files (the \"Software\"), to deal\n! in the Software without restriction, including without limitation the rights\n! to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n! copies of the Software, and to permit persons to whom the Software is\n! furnished to do so, subject to the following conditions:\n!\n! The above copyright notice and this permission notice shall be included in all\n! copies or substantial portions of the Software.\n!\n! THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n! SOFTWARE.\n\nsubroutine fcho_solve(A,y,x)\n\n implicit none\n\n double precision, dimension(:,:), intent(in) :: A\n double precision, dimension(:), intent(in) :: y\n double precision, dimension(:), intent(inout) :: x\n\n integer :: info, na\n\n na = size(A, dim=1)\n\n call dpotrf(\"U\", na, A, na, info)\n if (info > 0) then\n write (*,*) \"WARNING: Cholesky decomposition DPOTRF() exited with error code:\", info\n endif\n\n x(:na) = y(:na)\n\n call dpotrs(\"U\", na, 1, A, na, x, na, info)\n if (info > 0) then\n write (*,*) \"WARNING: Cholesky solve DPOTRS() exited with error code:\", info\n endif\n\nend subroutine fcho_solve\n\nsubroutine fcho_invert(A)\n\n implicit none\n\n double precision, dimension(:,:), intent(inout) :: A\n integer :: info, na\n\n na = size(A, dim=1)\n\n call dpotrf(\"L\", na, A , na, info)\n if (info > 0) then\n write (*,*) \"WARNING: Cholesky decomposition DPOTRF() exited with error code:\", info\n endif\n\n call dpotri(\"L\", na, A , na, info )\n if (info > 0) then\n write (*,*) \"WARNING: Cholesky inversion DPOTRI() exited with error code:\", info\n endif\n\nend subroutine fcho_invert\n\n\nsubroutine fbkf_invert(A)\n\n implicit none\n\n double precision, dimension(:,:), intent(inout) :: A\n integer :: info, na, nb\n\n integer, dimension(size(A,1)) :: ipiv ! pivot indices\n integer :: ilaenv\n \n integer :: lwork\n\n double precision, allocatable, dimension(:) :: work\n\n na = size(A, dim=1)\n \n nb = ilaenv( 1, 'DSYTRF', \"L\", na, -1, -1, -1 )\n\n lwork = na*nb\n\n allocate(work(lwork))\n\n ! call dpotrf(\"L\", na, A , na, info)\n call dsytrf(\"L\", na, A, na, ipiv, work, lwork, info)\n if (info > 0) then\n write (*,*) \"WARNING: Bunch-Kaufman factorization DSYTRI() exited with error code:\", info\n endif\n\n ! call dpotri(\"L\", na, A , na, info )\n call dsytri( \"L\", na, a, na, ipiv, work, info )\n if (info > 0) then\n write (*,*) \"WARNING: BKF inversion DPOTRI() exited with error code:\", info\n endif\n\n deallocate(work)\n\nend subroutine fbkf_invert\n\n\nsubroutine fbkf_solve(A,y,x)\n\n implicit none\n\n double precision, dimension(:,:), intent(in) :: A\n double precision, dimension(:), intent(in) :: y\n double precision, dimension(:), intent(inout) :: x\n\n double precision, allocatable, dimension(:) :: work\n integer :: ilaenv\n\n integer, dimension(size(A,1)) :: ipiv ! pivot indices\n integer :: info, na, nb, lwork\n\n na = size(A, dim=1)\n\n nb = ilaenv( 1, 'DSYTRF', \"L\", na, -1, -1, -1 )\n\n lwork = na*nb\n allocate(work(lwork))\n\n call dsytrf(\"L\", na, A, na, ipiv, work, lwork, info)\n if (info > 0) then\n write (*,*) \"WARNING: Bunch-Kaufman factorization DSYTRI() exited with error code:\", info\n endif\n\n x(:na) = y(:na)\n\n call dsytrs(\"L\", na, 1, A, na, ipiv, x, na, info )\n\n if (info > 0) then\n write (*,*) \"WARNING: Bunch-Kaufman solver DSYTRS() exited with error code:\", info\n endif\n\n deallocate(work)\nend subroutine fbkf_solve\n", "meta": {"hexsha": "4b0add8063d6446037faeb467764eef007ce886e", "size": 4138, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "qml/ml/math/fsolvers.f90", "max_stars_repo_name": "qmlcode/qml-interface", "max_stars_repo_head_hexsha": "328d3bc522291c896fc6fdfd4f64f005b99bed3f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-02-07T02:05:07.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-25T06:48:31.000Z", "max_issues_repo_path": "qml/ml/math/fsolvers.f90", "max_issues_repo_name": "qmlcode/qml-interface", "max_issues_repo_head_hexsha": "328d3bc522291c896fc6fdfd4f64f005b99bed3f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2017-09-27T08:57:06.000Z", "max_issues_repo_issues_event_max_datetime": "2017-10-10T14:03:57.000Z", "max_forks_repo_path": "qml/ml/math/fsolvers.f90", "max_forks_repo_name": "qmlcode/qml-interface", "max_forks_repo_head_hexsha": "328d3bc522291c896fc6fdfd4f64f005b99bed3f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-09-27T08:57:35.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-18T20:30:45.000Z", "avg_line_length": 28.3424657534, "max_line_length": 97, "alphanum_fraction": 0.6440309328, "num_tokens": 1197, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757870046160257, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.6945918810478771}} {"text": "PROGRAM heat_2d\nIMPLICIT NONE\nREAL, PARAMETER :: COOL = 20., HOT = 100., DEFAULT = 50.\nREAL, PARAMETER :: LIMIT = 1.0E-32\nINTEGER, PARAMETER :: MAX_ROWS = 100, MAX_COLS = 100\nREAL, DIMENSION(MAX_ROWS,MAX_COLS) :: plate\nREAL :: prev, new\nINTEGER :: i, j, steps, same\nLOGICAL :: done\n\n! Initialize values\nplate = DEFAULT\nplate(1,1:MAX_COLS) = COOL\nplate(MAX_ROWS,1:MAX_COLS) = COOL\nplate(1:MAX_ROWS,1) = COOL\nplate(1:MAX_ROWS,MAX_COLS) = COOL\nplate(3,8) = HOT\nWRITE(*, *) \"INITIAL TEMPS (C):\"\n!WRITE(*, '(10F11.3)') ((plate(i, j), j = 1, MAX_COLS), i = 1, MAX_ROWS)\n\ndone = .false.\nsteps = 0\nDO\n IF (done) THEN\n EXIT\n END IF\n same = 0\n DO i = 2, MAX_ROWS - 1\n IF (done) THEN\n EXIT\n END IF\n DO j = 2, MAX_COLS - 1\n IF (i .eq. 3 .and. j .eq. 8) THEN\n CYCLE\n ELSE\n prev = plate(i, j)\n new = 0.25 * (plate(i+1, j) + plate(i-1, j) + plate(i, j+1) + plate(i, j-1))\n plate(i, j) = new\n !WRITE(*, *) prev, new, i, j\n IF (ABS(new - prev) .le. LIMIT) THEN\n same = same + 1\n !WRITE(*, *) prev, new, i, j\n !done = .true.\n ! EXIT\n END IF\n END IF\n END DO\n END DO\n steps = steps + 1\n IF (same .ge. (MAX_ROWS - 2) * (MAX_COLS - 2) - 1) THEN\n done = .true.\n END IF\nEND DO\n\nWRITE(*, '(I6,1X,A)') steps, \"STEPS. FINAL TEMPS (C):\"\n!WRITE(*, '(10F11.3)') ((plate(i, j), j = 1, MAX_COLS), i = 1, MAX_ROWS)\n\nEND PROGRAM heat_2d\n", "meta": {"hexsha": "e118792b50a28aed160154a02ff0916b9f39f62a", "size": 1434, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap8/heat_2d.f90", "max_stars_repo_name": "evanmacbride/fortran-practice", "max_stars_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/chap8/heat_2d.f90", "max_issues_repo_name": "evanmacbride/fortran-practice", "max_issues_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/chap8/heat_2d.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": 24.3050847458, "max_line_length": 84, "alphanum_fraction": 0.549511855, "num_tokens": 566, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319863, "lm_q2_score": 0.7931059511841119, "lm_q1q2_score": 0.694591880188147}} {"text": "double precision function inner_product(u, v)\n\n! Calculates the inner product of cell-centered vectors u and v, using\n! interior cells only.\n\n !$ use omp_lib\n implicit none\n \n integer :: mx, my, mbc, meqn\n double precision :: x_lower, y_lower, dx, dy\n common /claw_config/ mx, my, mbc, x_lower, y_lower, dx, dy, meqn\n\n double precision, dimension(1-mbc:mx+mbc, 1-mbc:my+mbc, meqn) :: u, v\n\n integer :: ix, iy, ieqn\n\n\n inner_product = 0.d0\n do ieqn = 1, meqn\n !$omp parallel do reduction(+ : inner_product) private(ix, iy)\n do iy = 1, my\n do ix = 1, mx\n inner_product = inner_product + u(ix, iy, ieqn) * v(ix, iy, ieqn) * dx * dy\n end do\n end do\n end do\n\nend function inner_product\n", "meta": {"hexsha": "17a9c9512c312a451d125a994c4c0d2bb42946c6", "size": 772, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "implicit_claw/2d/inner_product.f90", "max_stars_repo_name": "claridge/implicit_solvers", "max_stars_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-04-29T00:16:18.000Z", "max_stars_repo_stars_event_max_datetime": "2017-04-29T00:16:18.000Z", "max_issues_repo_path": "implicit_claw/2d/inner_product.f90", "max_issues_repo_name": "claridge/implicit_solvers", "max_issues_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "implicit_claw/2d/inner_product.f90", "max_forks_repo_name": "claridge/implicit_solvers", "max_forks_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.6206896552, "max_line_length": 91, "alphanum_fraction": 0.6049222798, "num_tokens": 240, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869786798663, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.6945918711847548}} {"text": "PROGRAM main\n\n USE mo_kind, ONLY: dp, i4\n USE mo_utils, ONLY: ne\n USE mo_cfortran, ONLY: fctest ! sums between two elements in first dimension (multiply with constant)\n use mo_ansi_colors, only: color, c_red, c_green\n\n IMPLICIT NONE\n\n INTEGER(i4), PARAMETER :: d1 = 5\n INTEGER(i4), PARAMETER :: d2 = 4\n INTEGER(i4), PARAMETER :: n1 = 2\n INTEGER(i4), PARAMETER :: n2 = 3\n\n REAL(dp), DIMENSION(d1,d2) :: A\n\n REAL(dp), parameter :: c=2.0\n\n INTEGER(i4) :: i, j\n CHARACTER(LEN=30) :: form1\n logical :: isgood\n\n isgood = .true.\n\n forall(i=1:d1, j=1:d2) A(i,j) = real(i**j,dp)\n\n write(form1,\"(A,I3,A)\") \"(\", d1, \"f5.0)\"\n do j=1, d2\n write(*,form1) A(:,j)\n end do\n\n ! Beware C-indexes start with 0\n ! Also C is colunm-major so that one wants to transpose A, perhaps\n write(*,'(A,2f6.1)') 'sum(A(2+1:3+1,1)*2 = (3+4)*2 = 14: ', fctest(A, n1, n2, c), sum(A(n1+1:n2+1,1)*c)\n write(*,'(A,2f6.1)') 'sum(A(1,2+1:3+1)*2 = (1+1)*2 = 4: ', fctest(transpose(A), n1, n2, c), sum(A(1,n1+1:n2+1)*c)\n\n if (ne(fctest(A, n1, n2, c), 14.0_dp)) isgood = .false.\n\n if (isgood) then\n write(*,*) 'cfortran ', color('o.k.', c_green)\n else\n write(*,*) 'cfortran ', color('failed!', c_red)\n endif\n\n\n\nEND PROGRAM main\n", "meta": {"hexsha": "cf9d2c464ee12f9b1f78db9d14120c097143fff6", "size": 1232, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/test_cfortran/main.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_cfortran/main.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_cfortran/main.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.6666666667, "max_line_length": 116, "alphanum_fraction": 0.588474026, "num_tokens": 511, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527944504226, "lm_q2_score": 0.8152324938410783, "lm_q1q2_score": 0.6945396012546936}} {"text": "program main\n\n!*****************************************************************************80\n!\n!! MAIN is the main program for RANDOM_MPI.\n!\n! Discussion:\n!\n! This program demonstrates how P processors can generate the same\n! sequence of random numbers as 1 processor.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 May 2008\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! William Gropp, Ewing Lusk, Anthony Skjellum,\n! Using MPI: Portable Parallel Programming with the\n! Message-Passing Interface,\n! Second Edition,\n! MIT Press, 1999,\n! ISBN: 0262571323.\n!\n use mpi\n\n integer ( kind = 4 ) a\n integer ( kind = 4 ) an\n integer ( kind = 4 ) b\n integer ( kind = 4 ) bn\n integer ( kind = 4 ) c\n integer ( kind = 4 ) error\n integer ( kind = 4 ) id\n integer ( kind = 4 ) j\n integer ( kind = 4 ) k\n integer ( kind = 4 ) p\n integer ( kind = 4 ) u\n integer ( kind = 4 ) v\n!\n! Initialize MPI.\n!\n call MPI_Init ( error )\n!\n! Get the number of processes.\n!\n call MPI_Comm_size ( MPI_COMM_WORLD, p, error )\n!\n! Get the rank of this processor.\n!\n call MPI_Comm_rank ( MPI_COMM_WORLD, id, error )\n!\n! Print a message.\n!\n if ( id == 0 ) then\n call timestamp ( )\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'RANDOM_MPI - Master process:'\n write ( *, '(a)' ) ' FORTRAN90 version'\n write ( *, '(a,i8)' ) ' The number of processors is P = ', p\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' This program shows how a stream of random numbers'\n write ( *, '(a)' ) ' can be computed \"in parallel\" in an MPI program.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' We assume we are using a linear congruential'\n write ( *, '(a)' ) ' random number generator or \"LCRG\", which takes'\n write ( *, '(a)' ) ' an integer input and returns a new integer output:'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' U = ( A * V + B ) mod C'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' We assume that we want the MPI program to produce'\n write ( *, '(a)' ) ' the same sequence of random values as a sequential'\n write ( *, '(a)' ) ' program would - but we want each processor to compute'\n write ( *, '(a)' ) ' one part of that sequence.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' We do this by computing a new LCRG which can compute'\n write ( *, '(a)' ) ' every P''th entry of the original one.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' Our LCRG works with integers, but it is easy to'\n write ( *, '(a)' ) ' turn each integer into a real number between [0,1].'\n end if\n!\n! A, B and C define the linear congruential random number generator.\n!\n a = 16807\n b = 0\n c = 2147483647\n\n if ( id == 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' LCRG parameters:'\n write ( *, '(a)' ) ' '\n write ( *, '(a,i12)' ) ' A = ', a\n write ( *, '(a,i12)' ) ' B = ', b\n write ( *, '(a,i12)' ) ' C = ', c\n end if\n\n k_hi = p * 10\n!\n! Processor 0 generates 10 * P random values.\n!\n if ( id == 0 ) then\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) &\n ' Let processor 0 generate the entire random number sequence.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' K ID Input Output'\n write ( *, '(a)' ) ' '\n\n k = 0\n v = 12345\n write ( *, '(2x,i4,2x,i4,2x,12x,2x,i12)' ) k, id, v\n\n do k = 1, k_hi\n u = v\n call lcrg_evaluate ( a, b, c, u, v )\n write ( *, '(2x,i4,2x,i4,2x,i12,2x,i12)' ) k, id, u, v\n end do\n\n end if\n!\n! Processor P now participates by computing the P-th part of the sequence.\n!\n call lcrg_anbn ( a, b, c, p, an, bn )\n\n if ( id == 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' LCRG parameters for P processors:'\n write ( *, '(a)' ) ' '\n write ( *, '(a,i12)' ) ' AN = ', an\n write ( *, '(a,i12)' ) ' BN = ', bn\n write ( *, '(a,i12)' ) ' C = ', c\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' Have ALL the processors participate in computing'\n write ( *, '(a)' ) ' the same random number sequence.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' K ID Input Output'\n write ( *, '(a)' ) ' '\n end if\n!\n! Use the basis LCRG to get the ID-th value in the sequence.\n!\n v = 12345\n do j = 1, id\n u = v\n call lcrg_evaluate ( a, b, c, u, v )\n end do\n k = id\n\n write ( *, '(2x,i4,2x,i4,2x,12x,2x,i12)' ) k, id, v\n!\n! Now use the \"skipping\" LCRG to compute the values with indices\n! ID, ID+P, ID+2P, ...,\n!\n do k = id + p, k_hi, p\n u = v\n call lcrg_evaluate ( an, bn, c, u, v )\n write ( *, '(2x,i4,2x,i4,2x,i12,2x,i12)' ) k, id, u, v\n end do\n!\n! Terminate MPI.\n!\n call MPI_Finalize ( error )\n!\n! Terminate.\n!\n if ( id == 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'RANDOM_MPI - Master process:'\n write ( *, '(a)' ) ' Normal end of execution.'\n write ( *, '(a)' ) ' '\n call timestamp ( )\n end if\n\n stop\nend\nsubroutine congruence ( a, b, c, ierror, x )\n\n!*****************************************************************************80\n!\n!! CONGRUENCE solves a congruence of the form ( A * X = C ) mod B.\n!\n! Discussion:\n!\n! A, B and C are given integers. The equation is solvable if and only\n! if the greatest common divisor of A and B also divides C.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 31 May 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Eric Weisstein,\n! CRC Concise Encyclopedia of Mathematics,\n! CRC Press, 2002,\n! Second edition,\n! ISBN: 1584883472,\n! LC: QA5.W45.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, B, C, the coefficients of the\n! Diophantine equation.\n!\n! Output, integer ( kind = 4 ) IERROR, error flag.\n! 0, no error, X was computed.\n! 1, A = B = 0, C is nonzero.\n! 2, A = 0, B and C nonzero, but C is not a multiple of B.\n! 3, A nonzero, B zero, C nonzero, but C is not a multiple of A.\n! 4, A, B, C nonzero, but GCD of A and B does not divide C.\n! 5, algorithm ran out of internal space.\n!\n! Output, integer ( kind = 4 ) X, the solution of the Diophantine equation.\n! X will be between 0 and B-1.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: nmax = 100\n\n integer ( kind = 4 ) a\n integer ( kind = 4 ) a_copy\n integer ( kind = 4 ) a_mag\n integer ( kind = 4 ) a_sign\n integer ( kind = 4 ) b\n integer ( kind = 4 ) b_copy\n integer ( kind = 4 ) b_mag\n integer ( kind = 4 ) b_sign\n integer ( kind = 4 ) c\n integer ( kind = 4 ) c_copy\n integer ( kind = 4 ) g\n integer ( kind = 4 ) i4_gcd\n integer ( kind = 4 ) ierror\n integer ( kind = 4 ) k\n integer ( kind = 4 ) n\n integer ( kind = 4 ), parameter :: one = 1\n integer ( kind = 4 ) q(nmax)\n logical swap\n integer ( kind = 4 ) x\n integer ( kind = 4 ) y\n integer ( kind = 4 ) z\n!\n! Defaults for output parameters.\n!\n ierror = 0\n x = 0\n y = 0\n!\n! Special cases.\n!\n if ( a == 0 .and. b == 0 .and. c == 0 ) then\n x = 0\n return\n else if ( a == 0 .and. b == 0 .and. c /= 0 ) then\n ierror = 1\n x = 0\n return\n else if ( a == 0 .and. b /= 0 .and. c == 0 ) then\n x = 0\n return\n else if ( a == 0 .and. b /= 0 .and. c /= 0 ) then\n x = 0\n if ( mod ( c, b ) /= 0 ) then\n ierror = 2\n end if\n return\n else if ( a /= 0 .and. b == 0 .and. c == 0 ) then\n x = 0\n return\n else if ( a /= 0 .and. b == 0 .and. c /= 0 ) then\n x = c / a\n if ( mod ( c, a ) /= 0 ) then\n ierror = 3\n end if\n return\n else if ( a /= 0 .and. b /= 0 .and. c == 0 ) then\n! g = i4_gcd ( a, b )\n! x = b / g\n x = 0\n return\n end if\n!\n! Handle the \"general\" case: A, B and C are nonzero.\n!\n! Step 1: Compute the GCD of A and B, which must also divide C.\n!\n g = i4_gcd ( a, b )\n\n if ( mod ( c, g ) /= 0 ) then\n ierror = 4\n return\n end if\n\n a_copy = a / g\n b_copy = b / g\n c_copy = c / g\n!\n! Step 2: Split A and B into sign and magnitude.\n!\n a_mag = abs ( a_copy )\n a_sign = sign ( one, a_copy )\n b_mag = abs ( b_copy )\n b_sign = sign ( one, b_copy )\n!\n! Another special case, A_MAG = 1 or B_MAG = 1.\n!\n if ( a_mag == 1 ) then\n x = a_sign * c_copy\n return\n else if ( b_mag == 1 ) then\n x = 0\n return\n end if\n!\n! Step 3: Produce the Euclidean remainder sequence.\n!\n if ( b_mag <= a_mag ) then\n\n swap = .false.\n q(1) = a_mag\n q(2) = b_mag\n\n else\n\n swap = .true.\n q(1) = b_mag\n q(2) = a_mag\n\n end if\n\n n = 3\n\n do\n\n q(n) = mod ( q(n-2), q(n-1) )\n\n if ( q(n) == 1 ) then\n exit\n end if\n\n n = n + 1\n\n if ( nmax < n ) then\n ierror = 5\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'CONGRUENCE - Fatal error!'\n write ( *, '(a)' ) ' Exceeded number of iterations.'\n stop\n end if\n\n end do\n!\n! Step 4: Go backwards to solve X * A_MAG + Y * B_MAG = 1.\n!\n y = 0\n do k = n, 2, -1\n x = y\n y = ( 1 - x * q(k-1) ) / q(k)\n end do\n!\n! Step 5: Undo the swapping.\n!\n if ( swap ) then\n z = x\n x = y\n y = z\n end if\n!\n! Step 6: Apply signs to X and Y so that X * A + Y * B = 1.\n!\n x = x * a_sign\n!\n! Step 7: Multiply by C, so that X * A + Y * B = C.\n!\n x = x * c_copy\n!\n! Step 8: Force 0 <= X < B.\n!\n x = mod ( x, b )\n!\n! Step 9: Force positivity.\n!\n if ( x < 0 ) then\n x = x + b\n end if\n\n return\nend\nfunction i4_gcd ( i, j )\n\n!*****************************************************************************80\n!\n!! I4_GCD finds the greatest common divisor of I and J.\n!\n! Discussion:\n!\n! Only the absolute values of I and J are\n! considered, so that the result is always nonnegative.\n!\n! If I or J is 0, I4_GCD is returned as max ( 1, abs ( I ), abs ( J ) ).\n!\n! If I and J have no common factor, I4_GCD is returned as 1.\n!\n! Otherwise, using the Euclidean algorithm, I4_GCD is the\n! largest common factor of I and J.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 31 May 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 )I, J, two numbers whose greatest common\n! divisor is desired.\n!\n! Output, integer ( kind = 4 )I4_GCD, the greatest common divisor\n! of I and J.\n!\n implicit none\n\n integer ( kind = 4 ) i\n integer ( kind = 4 ) i4_gcd\n integer ( kind = 4 ) ip\n integer ( kind = 4 ) iq\n integer ( kind = 4 ) ir\n integer ( kind = 4 ) j\n\n i4_gcd = 1\n!\n! Return immediately if either I or J is zero.\n!\n if ( i == 0 ) then\n i4_gcd = max ( 1, abs ( j ) )\n return\n else if ( j == 0 ) then\n i4_gcd = max ( 1, abs ( i ) )\n return\n end if\n!\n! Set IP to the larger of I and J, IQ to the smaller.\n! This way, we can alter IP and IQ as we go.\n!\n ip = max ( abs ( i ), abs ( j ) )\n iq = min ( abs ( i ), abs ( j ) )\n!\n! Carry out the Euclidean algorithm.\n!\n do\n\n ir = mod ( ip, iq )\n\n if ( ir == 0 ) then\n exit\n end if\n\n ip = iq\n iq = ir\n\n end do\n\n i4_gcd = iq\n\n return\nend\nsubroutine lcrg_anbn ( a, b, c, n, an, bn )\n\n!*****************************************************************************80\n!\n!! LCRG_ANBN computes the \"N-th power\" of a linear congruential generator.\n!\n! Discussion:\n!\n! We are considering a linear congruential random number generator.\n! The LCRG takes as input an integer value called SEED, and returns\n! an updated value of SEED,\n!\n! SEED(out) = ( a * SEED(in) + b ) mod c.\n!\n! and an associated pseudorandom real value\n!\n! U = SEED(out) / c.\n!\n! In most cases, a user is content to call the LCRG repeatedly, with\n! the updating of SEED being taken care of automatically.\n!\n! The purpose of this routine is to determine the values of AN and BN\n! that describe the LCRG that is equivalent to N applications of the\n! original LCRG.\n!\n! One use for such a facility would be to do random number computations\n! in parallel. If each of N processors is to compute many random values,\n! you can guarantee that they work with distinct random values\n! by starting with a single value of SEED, using the original LCRG to \n! generate the first N-1 \"iterates\" of SEED, so that you now have N \"seed\" \n! values, and from now on, applying the N-th power of the LCRG to the seeds.\n!\n! If the K-th processor starts from the K-th seed, it will essentially\n! be computing every N-th entry of the original random number sequence,\n! offset by K. Thus the individual processors will be using a random\n! number stream as good as the original one, and without repeating, and\n! without having to communicate.\n!\n! To evaluate the N-th value of SEED directly, we start by ignoring\n! the modular arithmetic, and working out the sequence of calculations\n! as follows:\n!\n! SEED(0) = SEED.\n! SEED(1) = a * SEED + b\n! SEED(2) = a * SEED(1) + b = a^2 * SEED + a * b + b\n! SEED(3) = a * SEED(2) + b = a^3 * SEED + a^2 * b + a * b + b\n! ...\n! SEED(N-1) = a * SEED(N-2) + b\n!\n! SEED(N) = a * SEED(N-1) + b = a^N * SEED\n! + ( a^(n-1) + a^(n-2) + ... + a + 1 ) * b\n!\n! or, using the geometric series,\n!\n! SEED(N) = a^N * SEED + ( a^N - 1) / ( a - 1 ) * b\n! = AN * SEED + BN\n!\n! Thus, from any SEED, we can determine the result of N applications of the\n! original LCRG directly if we can solve\n!\n! ( a - 1 ) * BN = ( a^N - 1 ) * b in modular arithmetic,\n!\n! and evaluate:\n!\n! AN = a^N\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 22 April 2008\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Barry Wilkinson, Michael Allen,\n! Parallel Programming:\n! Techniques and Applications Using Networked Workstations \n! and Parallel Computers,\n! Prentice Hall,\n! ISBN: 0-13-140563-2,\n! LC: QA76.642.W54.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, the multiplier for the LCRG.\n!\n! Input, integer ( kind = 4 ) B, the added value for the LCRG.\n!\n! Input, integer ( kind = 4 ) C, the base for the modular arithmetic.\n! For 32 bit arithmetic, this is often 2^31 - 1, or 2147483647. It is\n! required that 0 < C.\n!\n! Input, integer ( kind = 4 ) N, the \"index\", or number of times that the\n! LCRG is to be applied. It is required that 0 <= N.\n!\n! Output, integer ( kind = 4 ) AN, BN, the multiplier and added value for\n! the LCRG that represent N applications of the original LCRG.\n!\n implicit none\n\n integer ( kind = 4 ) a\n integer ( kind = 4 ) am1\n integer ( kind = 4 ) an\n integer ( kind = 4 ) anm1tb\n integer ( kind = 4 ) b\n integer ( kind = 4 ) bn\n integer ( kind = 4 ) c\n integer ( kind = 4 ) ierror\n integer ( kind = 4 ) n\n\n if ( n < 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'LCRG_ANBN - Fatal error!'\n write ( *, '(a,i12)' ) ' Illegal input value of N = ', n\n stop\n end if\n\n if ( c <= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'LCRG_ANBN - Fatal error!'\n write ( *, '(a,i12)' ) ' Illegal input value of C = ', c\n stop\n end if\n\n if ( n == 0 ) then\n an = 1\n bn = 0\n else if ( n == 1 ) then\n an = a\n bn = b\n else\n!\n! Compute A^N.\n!\n call power_mod ( a, n, c, an )\n!\n! Solve\n! ( a - 1 ) * BN = ( a^N - 1 ) mod B\n! for BN.\n!\n am1 = a - 1\n anm1tb = ( an - 1 ) * b\n\n call congruence ( am1, c, anm1tb, ierror, bn )\n\n if ( ierror /= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'LCRG_ANBN - Fatal error!'\n write ( *, '(a)' ) ' An error occurred in the CONGRUENCE routine.'\n write ( *, '(a,i8)' ) ' The error code was IERROR = ', ierror\n stop\n end if\n\n end if\n\n return\nend\nsubroutine lcrg_evaluate ( a, b, c, x, y )\n\n!*****************************************************************************80\n!\n!! LCRG_EVALUATE evaluates an LCRG, y = ( A * x + B ) mod C.\n!\n! Discussion:\n!\n! This routine cannot be recommended for production use. Because we want\n! to do modular arithmetic, but the base is not a power of 2, we need to\n! use \"double precision\" integers to keep accuracy.\n!\n! If we knew the base C, we could try to avoid overflow while not changing\n! precision.\n!\n! If the base C was a power of 2, we could rely on the usual properties of\n! integer arithmetic on computers, in which overflow bits, which are always\n! ignored, don't actually matter.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 22 April 2008\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, the multiplier for the LCRG.\n!\n! Input, integer ( kind = 4 ) B, the added value for the LCRG.\n!\n! Input, integer ( kind = 4 ) C, the base for the modular arithmetic.\n! For 32 bit arithmetic, this is often 2^31 - 1, or 2147483647. It is\n! required that 0 < C.\n!\n! Input, integer ( kind = 4 ) X, the value to be processed.\n!\n! Output, integer ( kind = 4 ) Y, the processed value.\n!\n implicit none\n\n integer ( kind = 4 ) a\n integer ( kind = 8 ) a8\n integer ( kind = 4 ) b\n integer ( kind = 8 ) b8\n integer ( kind = 4 ) c\n integer ( kind = 8 ) c8\n integer ( kind = 4 ) x\n integer ( kind = 8 ) x8\n integer ( kind = 4 ) y\n integer ( kind = 8 ) y8\n!\n! To avoid roundoff issues, we need to go to \"double precision\" integers.\n! (Not available on all planets.)\n!\n a8 = a\n b8 = b\n c8 = c\n x8 = x\n\n y8 = mod ( a8 * x8 + b8, c8 )\n\n y = int ( y8, kind = 4 )\n\n if ( y < 0 ) then\n y = y + c\n end if\n\n return\nend\nsubroutine power_mod ( a, n, m, x )\n\n!*****************************************************************************80\n!\n!! POWER_MOD computes ( A^N ) mod M.\n!\n! Discussion:\n!\n! Some programming tricks are used to speed up the computation, and to\n! allow computations in which the value A**N is much too large to\n! store in an integer word.\n!\n! First, for efficiency, the power A**N is computed by determining\n! the binary expansion of N, then computing A, A**2, A**4, and so on\n! by repeated squaring, and multiplying only those factors that\n! contribute to A**N.\n!\n! Secondly, the intermediate products are immediately \"mod'ed\", which\n! keeps them small.\n!\n! For instance, to compute ( A^13 ) mod 11, we essentially compute\n!\n! 13 = 1 + 4 + 8\n!\n! A^13 = A * A^4 * A^8\n!\n! A^13 ( mod 11 ) = A ( mod 11 ) * A^4 ( mod 11 ) * A^8 ( mod 11 ).\n!\n! Fermat's little theorem says that if P is prime, and A is not divisible\n! by P, then ( A^(P-1) - 1 ) is divisible by P.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 22 May 2008\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, the base of the expression to be tested.\n! 0 <= A is required.\n!\n! Input, integer ( kind = 4 ) N, the power to which the base is raised.\n! 0 <= N is required.\n!\n! Input, integer ( kind = 4 ) M, the divisor against which the expression\n! is tested. 0 < M is required.\n!\n! Output, integer ( kind = 4 ) X, the remainder when A^N is divided by M.\n! If any input quantity is unacceptable, then the nonsensical value\n! X = -1 is returned.\n!\n implicit none\n\n integer ( kind = 4 ) a\n integer ( kind = 8 ) a_square2\n integer ( kind = 4 ) d\n integer ( kind = 4 ) m\n integer ( kind = 8 ) m2\n integer ( kind = 4 ) n\n integer ( kind = 4 ) ncopy\n integer ( kind = 4 ), parameter :: two = 2\n integer ( kind = 4 ) x\n integer ( kind = 8 ) x2\n\n if ( a < 0 ) then\n x = -1\n return\n end if\n\n if ( m <= 0 ) then\n x = -1\n return\n end if\n\n if ( n < 0 ) then\n x = -1\n return\n end if\n!\n! A_SQUARE contains the successive squares of A.\n!\n a_square2 = int ( a, kind = 8 )\n x2 = int ( 1, kind = 8 )\n m2 = int ( m, kind = 8 )\n\n ncopy = n\n\n do while ( 0 < ncopy )\n\n d = mod ( ncopy, two )\n\n if ( d == 1 ) then\n x2 = mod ( x2 * a_square2, m2 )\n end if\n\n a_square2 = mod ( a_square2 * a_square2, m2 )\n ncopy = ( ncopy - d ) / 2\n\n end do\n!\n! Fix up X so that it is nonnegative.\n!\n do while ( x2 < 0 )\n x2 = x2 + m2\n end do\n\n x = int ( x2 )\n\n return\nend\nsubroutine timestamp ( )\n\n!*****************************************************************************80\n!\n!! TIMESTAMP prints the current YMDHMS date as a time stamp.\n!\n! Example:\n!\n! 31 May 2001 9:45:54.872 AM\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 06 August 2005\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! None\n!\n implicit none\n\n character ( len = 8 ) ampm\n integer ( kind = 4 ) d\n integer ( kind = 4 ) h\n integer ( kind = 4 ) m\n integer ( kind = 4 ) mm\n character ( len = 9 ), parameter, dimension(12) :: month = (/ &\n 'January ', 'February ', 'March ', 'April ', &\n 'May ', 'June ', 'July ', 'August ', &\n 'September', 'October ', 'November ', 'December ' /)\n integer ( kind = 4 ) n\n integer ( kind = 4 ) s\n integer ( kind = 4 ) values(8)\n integer ( kind = 4 ) y\n\n call date_and_time ( values = values )\n\n y = values(1)\n m = values(2)\n d = values(3)\n h = values(5)\n n = values(6)\n s = values(7)\n mm = values(8)\n\n if ( h < 12 ) then\n ampm = 'AM'\n else if ( h == 12 ) then\n if ( n == 0 .and. s == 0 ) then\n ampm = 'Noon'\n else\n ampm = 'PM'\n end if\n else\n h = h - 12\n if ( h < 12 ) then\n ampm = 'PM'\n else if ( h == 12 ) then\n if ( n == 0 .and. s == 0 ) then\n ampm = 'Midnight'\n else\n ampm = 'AM'\n end if\n end if\n end if\n\n write ( *, '(i2,1x,a,1x,i4,2x,i2,a1,i2.2,a1,i2.2,a1,i3.3,1x,a)' ) &\n d, trim ( month(m) ), y, h, ':', n, ':', s, '.', mm, trim ( ampm )\n\n return\nend\n", "meta": {"hexsha": "5afd92e966ec2658de0d9f90f46b6214593ae092", "size": 21817, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "share/ukernels/random-mpi.f90", "max_stars_repo_name": "vivek224/vSched", "max_stars_repo_head_hexsha": "5ecf2cdf553277571490665b42e00a0b61b2a8c6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-06-11T17:16:02.000Z", "max_stars_repo_stars_event_max_datetime": "2018-10-01T18:37:28.000Z", "max_issues_repo_path": "share/ukernels/random-mpi.f90", "max_issues_repo_name": "vivek224/vSched", "max_issues_repo_head_hexsha": "5ecf2cdf553277571490665b42e00a0b61b2a8c6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-08-09T00:12:11.000Z", "max_issues_repo_issues_event_max_datetime": "2018-08-09T00:12:51.000Z", "max_forks_repo_path": "share/ukernels/random-mpi.f90", "max_forks_repo_name": "vlkale/lw-sched", "max_forks_repo_head_hexsha": "5ecf2cdf553277571490665b42e00a0b61b2a8c6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.6370530878, "max_line_length": 80, "alphanum_fraction": 0.5369207499, "num_tokens": 7465, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232489352, "lm_q2_score": 0.8519527944504227, "lm_q1q2_score": 0.6945395974302109}} {"text": "\n DOUBLE PRECISION FUNCTION DT_SAMPLW(Xmin,Xmax,B)\n \nC***********************************************************************\nC Sampling from f(x)=1/x^b between x_min and x_max. *\nC S. Roesler, 18.4.98 *\nC***********************************************************************\n \n IMPLICIT NONE\n DOUBLE PRECISION B , DT_RNDM , ONE , onemb , r , Xmax , Xmin\n SAVE \n PARAMETER (ONE=1.0D0)\n \n r = DT_RNDM(B)\n IF ( B.EQ.ONE ) THEN\n DT_SAMPLW = EXP(r*LOG(Xmax)+(ONE-r)*LOG(Xmin))\n ELSE\n onemb = ONE - B\n DT_SAMPLW = (r*Xmax**onemb+(ONE-r)*Xmin**onemb)**(ONE/onemb)\n END IF\n \n END FUNCTION\n", "meta": {"hexsha": "55defc900f4690ee8640e3bc004f1ea362c9f9bf", "size": 725, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/dpmjet/DT_SAMPLW.f", "max_stars_repo_name": "pzhristov/DPMJET", "max_stars_repo_head_hexsha": "946e001290ca5ece608d7e5d1bfc7311cda7ebaa", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-06-15T01:59:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-01T08:39:13.000Z", "max_issues_repo_path": "src/dpmjet/DT_SAMPLW.f", "max_issues_repo_name": "pzhristov/DPMJET", "max_issues_repo_head_hexsha": "946e001290ca5ece608d7e5d1bfc7311cda7ebaa", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-03-15T09:53:05.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-20T20:52:28.000Z", "max_forks_repo_path": "src/dpmjet/DT_SAMPLW.f", "max_forks_repo_name": "pzhristov/DPMJET", "max_forks_repo_head_hexsha": "946e001290ca5ece608d7e5d1bfc7311cda7ebaa", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2020-07-05T02:44:05.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-20T20:49:05.000Z", "avg_line_length": 31.5217391304, "max_line_length": 72, "alphanum_fraction": 0.3972413793, "num_tokens": 186, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9539660989095221, "lm_q2_score": 0.7279754607093178, "lm_q1q2_score": 0.69446391035473}} {"text": "module window_statistics\n use, intrinsic :: iso_fortran_env, only : dp => REAL64\n implicit none\n private\n type, public :: window_stats_type\n private\n real(kind=dp), dimension(:), allocatable :: window\n integer :: nr_value = 0\n integer :: curr_pos = 1\n contains\n procedure, public :: init\n procedure, public :: add_data\n procedure, public :: mean\n procedure, public :: stddev\n end type window_stats_type\n\ncontains\n\n subroutine init(window_stats, n)\n use, intrinsic :: iso_fortran_env, only : error_unit\n implicit none\n class(window_stats_type), intent(inout) :: window_stats\n integer, value :: n\n integer :: istat\n allocate(window_stats%window(n), stat=istat)\n if (istat /= 0) then\n write (unit=error_unit, fmt='(A)') &\n '# error: can not allocate memory'\n stop 1\n end if\n window_stats%window = 0.0_dp\n end subroutine init\n\n subroutine add_data(window_stats, value)\n implicit none\n class(window_stats_type), intent(inout) :: window_stats\n real(kind=dp), value :: value\n window_stats%window(window_stats%curr_pos) = value\n if (window_stats%nr_value < size(window_stats%window)) &\n window_stats%nr_value = window_stats%nr_value + 1\n if (window_stats%curr_pos < size(window_stats%window)) then\n window_stats%curr_pos = window_stats%curr_pos + 1\n else\n window_stats%curr_pos = 1\n end if\n end subroutine add_data\n \n function mean(window_stats) result(mean_value)\n use, intrinsic :: iso_fortran_env, only : error_unit\n implicit none\n class(window_stats_type), intent(in) :: window_stats\n real(kind=dp) :: mean_value\n if (window_stats%nr_value == 0) then\n write (unit=error_unit, fmt='(A)') '# error: no data'\n stop 2\n else\n mean_value = sum(window_stats%window)/window_stats%nr_value\n end if\n end function mean\n\n function stddev(window_stats) result(stddev_value)\n use, intrinsic :: iso_fortran_env, only : error_unit\n implicit none\n class(window_stats_type), intent(in) :: window_stats\n real(kind=dp) :: stddev_value\n real(kind=dp) :: mean_value\n if (window_stats%nr_value < 2) then\n write (unit=error_unit, fmt='(A)') '# error: not enough data'\n stop 2\n else\n mean_value = window_stats%mean()\n stddev_value = sqrt(sum(window_stats%window**2)/window_stats%nr_value - &\n mean_value**2)\n end if\n end function stddev\n\nend module window_statistics\n", "meta": {"hexsha": "afd183d693ee4a2ce48941cf536f475549020088", "size": 2741, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "hands-on/session_03/exercise_02_mod.f90", "max_stars_repo_name": "gjbex/FortranForProgrammers", "max_stars_repo_head_hexsha": "0b23d3a4c325fa833333f83ef5326378e9e5e854", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-15T14:56:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-15T14:56:20.000Z", "max_issues_repo_path": "hands-on/session_03/exercise_02_mod.f90", "max_issues_repo_name": "gjbex/FortranForProgrammers", "max_issues_repo_head_hexsha": "0b23d3a4c325fa833333f83ef5326378e9e5e854", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hands-on/session_03/exercise_02_mod.f90", "max_forks_repo_name": "gjbex/FortranForProgrammers", "max_forks_repo_head_hexsha": "0b23d3a4c325fa833333f83ef5326378e9e5e854", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.141025641, "max_line_length": 85, "alphanum_fraction": 0.6121853338, "num_tokens": 658, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245953120233, "lm_q2_score": 0.8333245870332531, "lm_q1q2_score": 0.6944298742530446}} {"text": "C$Procedure NPLNPT ( Nearest point on line to point )\n \n SUBROUTINE NPLNPT ( LINPT, LINDIR, POINT, PNEAR, DIST )\n \nC$ Abstract\nC\nC Find the nearest point on a line to a specified point, and find\nC the distance between the two points.\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 GEOMETRY\nC MATH\nC VECTOR\nC\nC$ Declarations\n \n DOUBLE PRECISION LINPT ( 3 )\n DOUBLE PRECISION LINDIR ( 3 )\n DOUBLE PRECISION POINT ( 3 )\n \n DOUBLE PRECISION PNEAR ( 3 )\n DOUBLE PRECISION DIST\n \nC$ Brief_I/O\nC\nC Variable I/O Description\nC -------- --- --------------------------------------------------\nC LINPT,\nC LINDIR I Point on a line and the line's direction vector.\nC POINT I A second point.\nC PNEAR O Nearest point on the line to POINT.\nC DIST O Distance between POINT and PNEAR.\nC\nC$ Detailed_Input\nC\nC LINPT\nC LINDIR are, respectively, a point and a direction vector\nC that define a line in 3-dimensional space. The\nC line is the set of points\nC\nC LINPT + t * LINDIR\nC\nC where t is any real number.\nC\nC POINT is a point in 3-dimensional space.\nC\nC$ Detailed_Output\nC\nC PNEAR is the nearest point on the input line to the input\nC point.\nC\nC DIST is the distance between the input line and input\nC point.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC 1) If the line direction vector LINDIR is the zero vector, the\nC error SPICE(ZEROVECTOR) is signaled.\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC For every line L and point P, there is a unique closest point\nC on L to P. Call this closest point C. It is always true that\nC P - C is perpendicular to L, and the length of P - C is called\nC the `distance' between P and L.\nC\nC$ Examples\nC\nC 1) Suppose a line passes through the point ( 1, 2, 3 ) and\nC has direction vector ( 0, 1, 1 ). We wish to find the\nC closest point on the line to the point ( -6, 9, 10 ). We\nC can use the code fragment\nC\nC LINPT(1) = 1.D0\nC LINPT(2) = 2.D0\nC LINPT(3) = 3.D0\nC\nC LINDIR(1) = 0.D0\nC LINDIR(2) = 1.D0\nC LINDIR(3) = 1.D0\nC\nC POINT(1) = -6.D0\nC POINT(2) = 9.D0\nC POINT(3) = 10.D0\nC\nC CALL NPLNPT ( LINPT, LINDIR, POINT, PNEAR, DIST )\nC\nC After the call, PNEAR will take the value\nC\nC ( 1.D0, 9.D0, 10.D0 );\nC\nC DIST will be 7.0.\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC N.J. Bachman (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 1.2.0, 17-SEP-2014 (NJB)\nC\nC Now uses discovery check-in.\nC\nC- SPICELIB Version 1.1.0, 09-SEP-2005 (NJB)\nC\nC Updated to remove non-standard use of duplicate arguments\nC in VADD call.\nC\nC- SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)\nC\nC Comment section for permuted index source lines was added\nC following the header.\nC\nC- SPICELIB Version 1.0.0, 02-NOV-1990 (NJB)\nC\nC-&\n \nC$ Index_Entries\nC\nC distance between point and line\nC nearest point on line to point\nC\nC-&\n \nC$ Revisions\nC\nC- SPICELIB Version 1.1.0, 09-SEP-2005 (NJB)\nC\nC Updated to remove non-standard use of duplicate arguments\nC in VADD call.\nC\nC-& \n\n\n \nC\nC SPICELIB functions\nC\n DOUBLE PRECISION VDIST\n \n LOGICAL RETURN\n LOGICAL VZERO\n \nC\nC Local variables\nC\n DOUBLE PRECISION PROJ ( 3 )\n DOUBLE PRECISION TRANS ( 3 )\n \n \nC\nC Use discovery check-in.\nC\n IF ( RETURN () ) THEN\n RETURN\n END IF\n\nC\nC We need a real direction vector to work with.\nC\n IF ( VZERO (LINDIR) ) THEN\n \n CALL CHKIN ( 'NPLNPT' )\n CALL SETMSG ( 'Direction vector must be non-zero.' )\n CALL SIGERR ( 'SPICE(ZEROVECTOR)' )\n CALL CHKOUT ( 'NPLNPT' )\n RETURN\n \n END IF\n \nC\nC We translate line and input point so as to put the line through\nC the origin. Then the nearest point on the translated line to the\nC translated point TRANS is the projection of TRANS onto the line.\nC\n CALL VSUB ( POINT, LINPT, TRANS )\n CALL VPROJ ( TRANS, LINDIR, PROJ )\n CALL VADD ( PROJ, LINPT, PNEAR )\n \n DIST = VDIST ( PNEAR, POINT )\n \n RETURN\n END\n", "meta": {"hexsha": "f6ef2b6f3c6feedc98d64df7ed6dab30e3c59b15", "size": 6030, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/nplnpt.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/nplnpt.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/nplnpt.f", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 26.2173913043, "max_line_length": 72, "alphanum_fraction": 0.6063018242, "num_tokens": 1836, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8902942261220291, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.6944231800655472}} {"text": "module mod_average\n\n implicit none\n\n private\n public :: average\n\ncontains\n\n pure real function average(x) result(res)\n real, intent(in) :: x(:)\n res = sum(x) / size(x)\n end function average\n\nend module mod_average\n\n\nprogram test_average\n use mod_average, only: average\n print *, average([1, 6, 4])\nend program test_average\n", "meta": {"hexsha": "b193e8a25ba697f2e68d110746952fb2a17adacf", "size": 334, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fortify/mf/listings/src/ch10/mod_average_incompatible.f90", "max_stars_repo_name": "wilsonify/c-consumer", "max_stars_repo_head_hexsha": "e19a1baf4efb68436bbec50395f2a3a2c6e3c078", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 26, "max_stars_repo_stars_event_min_datetime": "2018-03-29T13:23:00.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-01T19:47:30.000Z", "max_issues_repo_path": "src/fortify/mf/listings/src/ch10/mod_average_incompatible.f90", "max_issues_repo_name": "wilsonify/c-consumer", "max_issues_repo_head_hexsha": "e19a1baf4efb68436bbec50395f2a3a2c6e3c078", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2017-11-01T15:03:32.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-12T21:01:01.000Z", "max_forks_repo_path": "src/fortify/mf/listings/src/ch10/mod_average_incompatible.f90", "max_forks_repo_name": "wilsonify/c-consumer", "max_forks_repo_head_hexsha": "e19a1baf4efb68436bbec50395f2a3a2c6e3c078", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2018-04-01T19:53:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-30T23:33:14.000Z", "avg_line_length": 15.1818181818, "max_line_length": 43, "alphanum_fraction": 0.7005988024, "num_tokens": 89, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8902942144788076, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.694423161877637}} {"text": "\n\n\n\n\n\t!--------------------------------------------------------------------\n\t!\n\t!\n\t! PURPOSE\n\t!\n\t! This program uses MPI to do a parallel monte carlo calculation of pi\n\t!\n\t! .. Parameters ..\n\t! npts\t\t\t\t= total number of Monte Carlo points\n\t! xmin\t\t\t\t= lower bound for integration region\n\t! xmax = upper bound for integration region\n\t! .. Scalars ..\n\t! mynpts\t\t\t= this processes number of Monte Carlo points\n\t! myid\t\t\t\t= process id\n\t! nprocs\t\t\t= total number of MPI processes\n\t! ierr\t\t\t\t= error code\n\t! i = loop counter\n\t! f\t\t\t\t= average value from summation\n\t! sum = total sum\n\t! mysum = sum on this process\n\t! randnum = random number generated from (0,1) uniform \n\t! distribution\n\t! x = current Monte Carlo location\n\t! start\t\t\t= simulation start time\n\t! finish\t\t\t= simulation end time\n\t! .. Arrays ..\n\t!\n\t! .. Vectors ..\n\t!\n\t! REFERENCES\n\t! http://chpc.wustl.edu/mpi-fortran.html\n\t! Gropp, Lusk and Skjellum, \"Using MPI\" MIT press (1999)\n\t!\n\t! ACKNOWLEDGEMENTS\n\t! The program below was modified from one available at the internet\n\t! address in the references. This internet address was last checked\n\t! on 30 March 2012\n\t!\n\t! ACCURACY\n\t!\t\t\n\t! ERROR INDICATORS AND WARNINGS\n\t!\n\t! FURTHER COMMENTS\n\t!\n\t!--------------------------------------------------------------------\n\t! External routines required\n\t! \n\t! External libraries required\n\t! MPI library\n PROGRAM monte_carlo_mpi\n USE MPI\n IMPLICIT NONE\n\n INTEGER(kind=8), PARAMETER \t:: npts = 1e10\n REAL(kind=8), PARAMETER \t:: xmin=0.0d0,xmax=1.0d0\n INTEGER(kind=8) \t\t\t:: mynpts\n INTEGER(kind=4) \t :: ierr, myid, nprocs\n INTEGER(kind=8) \t :: i\n REAL(kind=8) \t\t :: f,sum,mysum,randnum\n REAL(kind=8) \t\t :: x, start, finish\n \n ! Initialize MPI\n CALL MPI_INIT(ierr)\n CALL MPI_COMM_RANK(MPI_COMM_WORLD, myid, ierr)\n CALL MPI_COMM_SIZE(MPI_COMM_WORLD, nprocs, ierr)\n start=MPI_WTIME()\n\n\t! Calculate the number of points each MPI process needs to generate\n IF (myid .eq. 0) THEN\n mynpts = npts - (nprocs-1)*(npts/nprocs)\n ELSE\n mynpts = npts/nprocs\n ENDIF\n \n ! set initial sum to zero\n mysum = 0.0d0\n\t! use loop on local process to generate portion of Monte Carlo integral\n DO i=1,mynpts\n CALL random_number(randnum)\n x = (xmax-xmin)*randnum + xmin\n mysum = mysum + 4.0d0/(1.0d0 + x**2)\n ENDDO\n\n\t! Do a reduction and sum the results from all processes\n CALL MPI_REDUCE(mysum,sum,1,MPI_DOUBLE_PRECISION,MPI_SUM,&\n 0,MPI_COMM_WORLD,ierr)\n finish=MPI_WTIME()\n\n ! Get one process to output the result and running time\n IF (myid .eq. 0) THEN\n f = sum/npts\n PRINT*,'PI calculated with ',npts,' points = ',f\n PRINT*,'Program took ', finish-start, ' for Time stepping'\n ENDIF\n\n CALL MPI_FINALIZE(ierr)\n\n STOP\n END PROGRAM\n", "meta": {"hexsha": "6b3d09ce760e2f7dfc569e16941d284a4e5d165d", "size": 2945, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "IntroductionToParallelProgramming/Programs/montecarloparallel/montecarloparallel.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": "IntroductionToParallelProgramming/Programs/montecarloparallel/montecarloparallel.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": "IntroductionToParallelProgramming/Programs/montecarloparallel/montecarloparallel.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": 28.0476190476, "max_line_length": 72, "alphanum_fraction": 0.5898132428, "num_tokens": 871, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835207180245, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.6944063250866979}} {"text": "! { dg-do run }\n! PR 25806: Functions returning pointers to arrays\nprogram a \n integer, target :: storage(5)\n integer :: s(3)\n\n\n print *, x(3) ! { dg-output \" *1 *2 *3\" }\n\n if (ssum(x(3)) /= 6) call abort()\n\n s = 0\n s = x(3)\n if (any(s /= (/1, 2, 3/))) call abort()\n\ncontains\n\n function x(n) result(t)\n integer, intent(in) :: n\n integer, pointer :: t(:)\n integer :: i\n\n t => storage(1:n)\n t = (/ (i, i = 1, n) /)\n\n end function x\n\n\n integer function ssum(a)\n integer, intent(in) :: a(:)\n\n ssum = sum(a)\n \n end function ssum\n\nend program a\n\n\n", "meta": {"hexsha": "939411b7bc22c2dcae617e2e499d0d1a494c1ff3", "size": 633, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/ret_pointer_2.f90", "max_stars_repo_name": "maurizioabba/rose", "max_stars_repo_head_hexsha": "7597292cf14da292bdb9a4ef573001b6c5b9b6c0", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/ret_pointer_2.f90", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/ret_pointer_2.f90", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 16.2307692308, "max_line_length": 50, "alphanum_fraction": 0.4834123223, "num_tokens": 204, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835289107309, "lm_q2_score": 0.8311430436757312, "lm_q1q2_score": 0.6944063231598057}} {"text": "! Program to test passing intrinsic functions as actual arguments for\n! dummy procedures.\nsubroutine test (proc)\n implicit none\n real proc\n real a, b, c\n\n a = 1.0\n b = sin (a)\n c = proc (a)\n \n if (abs (b - c) .gt. 0.001) call abort\n \nend subroutine\n\nprogram dummy\n implicit none\n external test\n intrinsic sin\n \n call test (sin)\nend program\n\n", "meta": {"hexsha": "2e8a34014925c33e8a8de6028af0c2550b7c1848", "size": 369, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_dummy.f90", "max_stars_repo_name": "best08618/asylo", "max_stars_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-05-02T17:34:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-17T10:15:18.000Z", "max_issues_repo_path": "llvm-gcc-4.2-2.9/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_dummy.f90", "max_issues_repo_name": "vidkidz/crossbridge", "max_issues_repo_head_hexsha": "ba0bf94aee0ce6cf7eb5be882382e52bc57ba396", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "llvm-gcc-4.2-2.9/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_dummy.f90", "max_forks_repo_name": "vidkidz/crossbridge", "max_forks_repo_head_hexsha": "ba0bf94aee0ce6cf7eb5be882382e52bc57ba396", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-27T00:22:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-01T09:41:02.000Z", "avg_line_length": 15.375, "max_line_length": 69, "alphanum_fraction": 0.6395663957, "num_tokens": 108, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045817875224, "lm_q2_score": 0.7826624688140726, "lm_q1q2_score": 0.6943817283249791}} {"text": "program tsunami\n\n ! Tsunami simulator.\n !\n ! Solves the non-linear 2-d shallow water equation system:\n !\n ! du/dt + u du/dx + v du/dy + g dh/dx = 0\n ! dv/dt + u dv/dx + v dv/dy + g dh/dy = 0\n ! dh/dt + d(hu)/dx + d(hv)/dy = 0\n !\n ! This version is parallelized, and uses derived types.\n\n use iso_fortran_env, only: int32, real32\n use mod_field, only: Field, diffx, diffy\n\n implicit none\n\n integer(int32) :: n\n\n integer(int32), parameter :: im = 101 ! grid size in x\n integer(int32), parameter :: jm = 101 ! grid size in y\n integer(int32), parameter :: num_time_steps = 1000 ! number of time steps\n\n real(real32), parameter :: dt = 0.02 ! time step [s]\n real(real32), parameter :: dx = 1 ! grid spacing [m]\n real(real32), parameter :: dy = 1 ! grid spacing [m]\n real(real32), parameter :: g = 9.8 ! gravitational acceleration [m/s]\n\n integer(int32), parameter :: ic = 51, jc = 51\n real(real32), parameter :: decay = 0.02\n\n type(Field) :: h, u, v, hm\n\n if (this_image() == 1) print *, 'Tsunami started'\n\n u = Field('u', [im, jm])\n v = Field('v', [im, jm])\n h = Field('h', [im, jm])\n hm = Field('hm', [im, jm])\n\n ! initialize a gaussian blob in the center\n call h % set_gaussian(decay, ic, jc)\n call h % sync_edges()\n\n ! set mean water depth\n hm = 10.\n\n call h % write(0)\n\n time_loop: do n = 1, num_time_steps\n\n if (this_image() == 1) then\n print *, 'Computing time step', n, '/', num_time_steps\n end if\n\n ! compute u at next time step\n u = u - (u * diffx(u) / dx + v * diffy(u) / dy &\n + g * diffx(h) / dx) * dt\n call u % sync_edges()\n\n ! compute v at next time step\n v = v - (u * diffx(v) / dx + v * diffy(v) / dy &\n + g * diffy(h) / dy) * dt\n call v % sync_edges()\n\n ! compute h at next time step\n h = h - (diffx(u * (hm + h)) / dx + diffy(v * (hm + h)) / dy) * dt\n call h % sync_edges()\n\n call h % write(n)\n\n end do time_loop\n\nend program tsunami\n", "meta": {"hexsha": "46c3a71e33c133a733e72e8b01463ac7653c2667", "size": 1947, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/ch08/tsunami.f90", "max_stars_repo_name": "AAGAN/tsunami", "max_stars_repo_head_hexsha": "82635516dcb7f85eb6434ffdb98a9ddc4c1403ad", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 103, "max_stars_repo_stars_event_min_datetime": "2018-03-29T23:39:31.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T12:24:25.000Z", "max_issues_repo_path": "src/ch08/tsunami.f90", "max_issues_repo_name": "AAGAN/tsunami", "max_issues_repo_head_hexsha": "82635516dcb7f85eb6434ffdb98a9ddc4c1403ad", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2018-04-06T14:33:04.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T19:50:12.000Z", "max_forks_repo_path": "src/ch08/tsunami.f90", "max_forks_repo_name": "AAGAN/tsunami", "max_forks_repo_head_hexsha": "82635516dcb7f85eb6434ffdb98a9ddc4c1403ad", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 32, "max_forks_repo_forks_event_min_datetime": "2018-04-01T19:54:12.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-27T14:06:03.000Z", "avg_line_length": 25.96, "max_line_length": 75, "alphanum_fraction": 0.5783256292, "num_tokens": 667, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094088947399, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.6943692887369585}} {"text": "\n! (D) LEAST-DISTANCE QUADRATIC PROGRAMMING\n!\n! (SUBPROGRAMS INVOLVED: WOLFE, ILOC, CONENR, HOUSE, DOTPRD,\n! REFWL)\n!\n! GIVEN POSITIVE INTEGERS M AND N, AND A MATRIX PMAT, THIS PROGRAM WILL\n! ATTEMPT TO LOCATE AN N-DIMENSIONAL POINT WPT IN THE POLYHEDRON\n! DETERMINED BY THE INEQUALITIES\n! PMAT(1,J)*WPT(1)+...+PMAT(N,J)*WPT(N)+PMAT(N+1,J) .LE. 0.0 FOR J=1,...,M\n! WHOSE DISTANCE WDIST FROM THE ORIGIN IS MINIMIZED. ON OUTPUT, JFLAG\n! WILL BE AN ERROR FLAG WHOSE VALUE WILL BE 0 FOR A NORMAL SOLUTION AND\n! POSITIVE FOR A LIKELY FAILURE. THE METHOD IS AN ENHANCED VERSION OF\n! THAT IN\n! WOLFE, PHILIP, FINDING THE NEAREST POINT IN A POLYTOPE, MATHEMATICAL\n! PROGRAMMING 11 (1976), 128-149.\n! THE FOLLOWING SAMPLE DRIVER IS SET UP TO FIND THE NEAREST POINT TO\n! THE ORIGIN IN THE POLYHEDRON DEFINED BY X + Y + Z .GE. 2.0D0 (I.E.\n! -X - Y - Z + 2.0D0 .LE. 0.0D0) AND Z .GE. 1.0D0 (I.E. -Z + 1.0D0 .LE.\n! 0.0D0). (THE EXACT SOLUTION IS (X,Y,Z) = (0.5D0,0.5D0,1.0D0) WITH\n! DISTANCE SQRT(1.5D0) FROM THE ORIGIN.)\n!\n! SAMPLE DRIVER FOR (D) LEAST-DISTANCE QUADRATIC PROGRAMMING\n!\n! THE MINIMUM DIMENSIONS ARE PMAT(NPARM+1,NUMGR), PMAT1(NPARM+1,NUMGR),\n! WPT(NPARM), ICOR(NPARM+1), R(NPARM+1), PTNR(NPARM+1), COEF(NUMGR),\n! WCOEF(NUMGR), IWORK(4*NUMGR+5*NPARM+3), WORK(2*NPARM**2+4*NUMGR*NPARM\n! +9*NUMGR+22*NPARM+10), WHERE NPARM .GE. N AND NUMGR .GE. M. THE FIRST\n! DIMENSIONS OF PMAT AND PMAT1 MUST BE EXACTLY NPARM+1.\n\nprogram main\n\n use conmax_module\n use iso_fortran_env, only: wp => real64\n\n IMPLICIT NONE\n\n real(wp) :: coef(2), pmat(4, 2), pmat1(4, 2), ptnr(4), r(4), s, &\n wcoef(2), wdist, work(136), wpt(3)\n INTEGER :: i, icor(4), iwork(26), j, jflag, liwrk, lwrk, m, mp1, &\n n, ncor, nmaj, nmin, np1, nparm, numgr\n\n n = 3\n m = 2\n pmat(1, 1) = -1.0_wp\n pmat(2, 1) = -1.0_wp\n pmat(3, 1) = -1.0_wp\n pmat(4, 1) = 2.0_wp\n pmat(1, 2) = 0.0_wp\n pmat(2, 2) = 0.0_wp\n pmat(3, 2) = -1.0_wp\n pmat(4, 2) = 1.0_wp\n nparm = n\n numgr = m\n liwrk = 4*numgr + 5*nparm + 3\n lwrk = 2*nparm**2 + 4*numgr*nparm + 9*numgr + 22*nparm + 10\n mp1 = m + 1\n np1 = n + 1\n\n !OPEN (6,FILE='QPOUT')\n WRITE (6, 99001) m, n\n99001 FORMAT(/' THERE ARE', I5, ' BOUNDARIES AND', I5, ' DIMENSIONS'// &\n ' THE BOUNDARY COEFFICIENTS ARE')\n DO j = 1, m\n WRITE (6, 99002) (pmat(i, j), i=1, np1)\n99002 FORMAT(/(3E22.13))\n END DO\n CALL WOLFE(n, m, pmat, 0, s, ncor, icor, iwork, liwrk, work, lwrk, r, coef, &\n ptnr, pmat1, nparm, numgr, wcoef, wpt, wdist, nmaj, nmin, jflag)\n WRITE (6, 99003) jflag, wdist, (wpt(i), i=1, n)\n99003 FORMAT(/' AFTER WOLFE THE ERROR FLAG IS', &\n &I4//' THE DISTANCE FROM THE ORIGIN IS', &\n &E22.13//' THE POINT HAS COORDINATES'//(3E22.13))\n\nEND\n\n! OUTPUT FOR (D) LEAST-DISTANCE QUADRATIC PROGRAMMING\n!\n! THERE ARE 2 BOUNDARIES AND 3 DIMENSIONS\n!\n! THE BOUNDARY COEFFICIENTS ARE\n!\n! -0.1000000000000E+01 -0.1000000000000E+01 -0.1000000000000E+01\n! 0.2000000000000E+01\n!\n! 0.0000000000000E+00 0.0000000000000E+00 -0.1000000000000E+01\n! 0.1000000000000E+01\n!\n! AFTER WOLFE THE ERROR FLAG IS 0\n!\n! THE DISTANCE FROM THE ORIGIN IS 0.1224744871392E+01\n!\n! THE POINT HAS COORDINATES\n!\n! 0.5000000000000E+00 0.5000000000000E+00 0.1000000000000E+01\n!\n", "meta": {"hexsha": "7778eca1b8c085832aa04501de01840d0dfeb70a", "size": 3328, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/qp.f90", "max_stars_repo_name": "jacobwilliams/conmax", "max_stars_repo_head_hexsha": "0f6c87531decd59f40d1765a9e6a120e8c56f0fe", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-08-18T04:18:28.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-22T16:52:45.000Z", "max_issues_repo_path": "src/tests/qp.f90", "max_issues_repo_name": "jacobwilliams/conmax", "max_issues_repo_head_hexsha": "0f6c87531decd59f40d1765a9e6a120e8c56f0fe", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-08-18T14:08:01.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-10T13:44:26.000Z", "max_forks_repo_path": "src/tests/qp.f90", "max_forks_repo_name": "jacobwilliams/conmax", "max_forks_repo_head_hexsha": "0f6c87531decd59f40d1765a9e6a120e8c56f0fe", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-08-18T13:39:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-18T13:39:04.000Z", "avg_line_length": 34.3092783505, "max_line_length": 81, "alphanum_fraction": 0.6298076923, "num_tokens": 1468, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093946927837, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.6943692776977798}} {"text": " SUBROUTINE SB08MY( DA, A, B, EPSB )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute the coefficients of B(s) = A(s) * A(-s) and a norm\nC for the accuracy of the computed coefficients.\nC\nC ARGUMENTS\nC\nC Input/Output Parameters\nC\nC DA (input) INTEGER\nC The degree of the polynomials A(s) and B(s). DA >= 0.\nC\nC A (input) DOUBLE PRECISION array, dimension (DA+1)\nC This array must contain the coefficients of the polynomial\nC A(s) in increasing powers of s.\nC\nC B (output) DOUBLE PRECISION array, dimension (DA+1)\nC This array contains the coefficients of the polynomial\nC B(s) in increasing powers of s**2.\nC\nC EPSB (input/output) DOUBLE PRECISION\nC On entry, EPSB must contain the machine precision (see\nC LAPACK Library routine DLAMCH).\nC On exit, EPSB contains an updated value, using a norm\nC for the accuracy of the computed coefficients.\nC\nC CONTRIBUTOR\nC\nC Release 3.0: V. Sima, Katholieke Univ. Leuven, Belgium, Aug. 1997.\nC Supersedes Release 2.0 routine SB08AZ by A.J. Geurts.\nC\nC REVISIONS\nC\nC -\nC\nC KEYWORDS\nC\nC Laplace transform, polynomial operations, spectral factorization.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, ONE, TWO, THREE\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0, TWO=2.0D0,\n $ THREE = 3.0D0 )\nC .. Scalar Arguments ..\n INTEGER DA\n DOUBLE PRECISION EPSB\nC .. Array Arguments ..\n DOUBLE PRECISION A(*), B(*)\nC .. Local Scalars ..\n INTEGER I, K\n DOUBLE PRECISION MAXSA, SA, SABS, SIGNI, SIGNK, TERM\nC .. Intrinsic Functions ..\n INTRINSIC ABS, MAX, MIN\nC .. Executable Statements ..\nC\n SIGNI = ONE\n MAXSA = ZERO\nC\n DO 40 I = 0, DA\n SABS = A(I+1)**2\n SA = SIGNI*SABS\n SIGNK = -TWO*SIGNI\nC\n DO 20 K = 1, MIN( I, DA - I )\n TERM = SIGNK*A(I-K+1)*A(I+K+1)\n SA = SA + TERM\n SABS = SABS + ABS( TERM )\n SIGNK = -SIGNK\n 20 CONTINUE\nC\n B(I+1) = SA\n MAXSA = MAX( MAXSA, SABS )\n SIGNI = -SIGNI\n 40 CONTINUE\nC\n EPSB = THREE*MAXSA*EPSB\nC\n RETURN\nC *** Last line of SB08MY ***\n END\n", "meta": {"hexsha": "662a7ee5035fb8bafa85920d10844ad078c6156d", "size": 2480, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/SB08MY.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/SB08MY.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/SB08MY.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 27.8651685393, "max_line_length": 72, "alphanum_fraction": 0.5455645161, "num_tokens": 750, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.893309411735131, "lm_q2_score": 0.7772998560157663, "lm_q1q2_score": 0.6943692771192462}} {"text": "!\n!\n!\n!\n SUBROUTINE HARMO_Y_TT (LMAX, LON, LAT, Y_TT)\n USE SHTOOLS \n IMPLICIT NONE \n INTEGER, PARAMETER :: LLMAX=512, JJMAX=(LLMAX+1)*(LLMAX+2)/2 \n INTEGER J, MJ, LJ, J_INDEX, LMAX \n COMPLEX*16 Y_TT(*) \n REAL*8 LON, LAT\n REAL*8, ALLOCATABLE :: DPLM(:) \n REAL*8, ALLOCATABLE :: PLM(:) \n REAL*8 COSDD, SINDD\n INTEGER :: JMAX\n!\n!\n! Given longitude LON and latitude LAT - in degrees - this routine computes \n! the theta-component of the gradient of *all* the 4-pi normalized complex \n! harmonics $\\cal Y_{lm}(\\theta,\\lambda)$, with \\theta=colatitude and \\lambda=\n! longitude, to degree LMAX. This subroutine uses the (modified) SHTOOLS Legendre \n! functions by PlmBar (see Sbr PLMBAR_MOD). - Created by GS August 8, 2008 - \n!\n! CREATED by GS on MAY 1, 2020. The program computes y_tt\n!\n! - Modified by GS Apr 2020 -- dynamically allocate DPLM\n!\n!**********************************************************\n! Modified GS on MAy 1, 2020 \n!\n! The routine computes \"y_tt = d/dtheta d/dtheta y\"\n!**********************************************************\n!\n!\n! ---- Tests the longitude and latitude bounds \n If(abs(lat)>90.) then \n \t Write(* ,*) \"Error in Sbr. GRAD_THETA_HARMO: Latitude is out of range\" \n\t \tWrite(* ,*) \"The program will STOP ----------------\"\n call stop_config \n\t Stop 1\t\t\n elseif (lon<0.or.lon>360.) then\n \t Write(* ,*) \"Error in Sbr. GRAD_THETA_HARMO: Longitude is out of range\" \n\t \tWrite(* ,*) \"The program will STOP ----------------\"\n call stop_config \n\t Stop 2\t\n Endif \n! \n!\n!\n! ---- Allocate temporary arrays\n!\n JMAX=(LMAX+1)*(LMAX+2)/2\n ALLOCATE( DPLM(JMAX) )\n ALLOCATE( PLM (JMAX) ) \n!\n! ---- Builds the SHTOOLS Legendre functions, with Condon-Shortley phase \n!\n CALL PLMBAR_MOD (LMAX, LAT, PLM) \n CALL PLMBAR_MOD_D1 (LMAX, LAT, DPLM) \n!\n! \n! ---- Computes the 4-pi normalized Spherical Harmonics up to degree LMAX\n!\n \t\tdo j=1, j_index(lmax,lmax)\n!\n \t\t\ty_tt(j) = &\n!\n ( & \n\t\t\t- (cosdd(90.-LAT)/sindd(90.-LAT))*dplm(j) &\n\t\t\t+ (float(mj(j)**2)/sindd(90.-LAT)/sindd(90.-LAT) - lj(j)*(lj(j)+1))*plm(j) & \t\t\t\t\t\t\n\t\t\t) * & \n\t\t\tcmplx(cosdd(float(mj(j))*lon),sindd(float(mj(j))*lon))\n!\n \t\tenddo\n!\n!\n! ---- Release memory\n!\n DEALLOCATE( DPLM )\n DEALLOCATE( PLM )\n!\nEND SUBROUTINE HARMO_Y_TT \n!\n!\n!\n!\n!\n", "meta": {"hexsha": "37f853b5cc878ef5988843b9a06bef9cd747ef3c", "size": 2352, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/y_tt.f90", "max_stars_repo_name": "gassmoeller/selen", "max_stars_repo_head_hexsha": "796ed0c3b994e0a8d447934f3ec2863a2d2804ab", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2016-01-15T16:22:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-11T03:05:48.000Z", "max_issues_repo_path": "src/y_tt.f90", "max_issues_repo_name": "gassmoeller/selen", "max_issues_repo_head_hexsha": "796ed0c3b994e0a8d447934f3ec2863a2d2804ab", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2015-10-14T21:07:01.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T20:08:24.000Z", "max_forks_repo_path": "src/y_tt.f90", "max_forks_repo_name": "gassmoeller/selen", "max_forks_repo_head_hexsha": "796ed0c3b994e0a8d447934f3ec2863a2d2804ab", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2015-08-26T10:55:15.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-01T16:31:11.000Z", "avg_line_length": 26.7272727273, "max_line_length": 86, "alphanum_fraction": 0.5676020408, "num_tokens": 763, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094032139577, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6943692704957396}} {"text": "!/////////////////////////////////////////////////////////////////////////\n!//\n!// MPI example program in FORTRAN 90\n!//\n!/////////////////////////////////////////////////////////////////////////\n\nPROGRAM pi\n IMPLICIT NONE\n INCLUDE \"mpif.h\"\n\n INTEGER :: psize ! Number of procs\n INTEGER :: my_rank ! This process\n INTEGER :: i ! Index\n INTEGER :: n = 1000 ! Used as constant\n INTEGER :: rstat ! Status variable\n INTEGER,DIMENSION(MPI_STATUS_SIZE) :: status ! MPI status\n\n DOUBLE PRECISION :: l_sum\n DOUBLE PRECISION :: g_sum\n DOUBLE PRECISION :: x\n DOUBLE PRECISION :: h\n\n\n CHARACTER (LEN=80) :: str ! Text string\n\n !// Initialize MPI\n CALL MPI_Init(rstat)\n\n !// Get number of procs\n CALL MPI_Comm_size(MPI_COMM_WORLD, psize, rstat)\n\n !// Get process number for this process\n CALL MPI_Comm_rank(MPI_COMM_WORLD, my_rank, rstat)\n\n !// Fortran has no default command line args into\n !// a process. Using fixed size of n\n\n CALL MPI_Bcast(n, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, rstat)\n\n h = 1.0/n\n l_sum = 0.\n\n DO i = my_rank, n\n x = (i+0.5)*h\n l_sum = l_sum + 4.0/(1.0+x*x)\n END DO\n\n l_sum = l_sum + h\n\n IF (my_rank == 0) THEN\n g_sum = l_sum\n DO i = 1, psize - 1\n CALL MPI_Recv(l_sum, 1, MPI_DOUBLE_PRECISION, MPI_ANY_SOURCE, 500, &\n MPI_COMM_WORLD, status, rstat)\n g_sum = g_sum + l_sum\n END DO\n PRINT *, 'Result = ', g_sum\n ELSE\n CALL MPI_Send(l_sum, 1, MPI_DOUBLE_PRECISION, 0, 500, MPI_COMM_WORLD)\n END IF\n\n CALL MPI_Finalize(rstat)\n\nEND PROGRAM pi\n", "meta": {"hexsha": "36e786e1911e59346ce0385d61ecf5782aa55a99", "size": 1893, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "doc/Programs/LecturePrograms/programs/MPI/chapter07/calc_pi.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/MPI/chapter07/calc_pi.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/MPI/chapter07/calc_pi.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": 29.1230769231, "max_line_length": 77, "alphanum_fraction": 0.4733227681, "num_tokens": 471, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199714402812, "lm_q2_score": 0.8289388083214155, "lm_q1q2_score": 0.6943357009519249}} {"text": "program test\n integer :: a(10, 10), b(10,10), c(10, 10)\n integer:: i = 1,j =1\n \n do i = 1,10\n do j = 1,10\n a(j,i) = i\n b(j,i) = j\n end do\n end do\n \n do i = 1,10\n do j = 1,10,1\n c(j,i) = a(j,i) + b(j,i)\n end do\n end do\n \n print *, c\nend program test\n", "meta": {"hexsha": "4a0aafcffd5b0a95c9e8429e82ad10d2e7849b3d", "size": 285, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/output_tests/do_2d_arr_sum.f90", "max_stars_repo_name": "clementval/fc", "max_stars_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/output_tests/do_2d_arr_sum.f90", "max_issues_repo_name": "clementval/fc", "max_issues_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/output_tests/do_2d_arr_sum.f90", "max_forks_repo_name": "clementval/fc", "max_forks_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "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": 14.25, "max_line_length": 43, "alphanum_fraction": 0.4421052632, "num_tokens": 131, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199552262967, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.6943356839717861}} {"text": "module m_util\n contains\n\n function circle_area(radius)\n implicit none\n\n real(8) :: radius\n real(8) :: circle_area\n\n circle_area = PI * radius * radius\n\n end function circle_area\nend module m_util\n", "meta": {"hexsha": "9fcc4d24b98ae114c58b21255c708fa9878ec5fb", "size": 211, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/fortran/util.f90", "max_stars_repo_name": "willi-kappler/comment_units", "max_stars_repo_head_hexsha": "8cb388b8c148214c023bece6f0e8cf115020b006", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-05-16T07:32:16.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-06T11:14:46.000Z", "max_issues_repo_path": "examples/fortran/util.f90", "max_issues_repo_name": "willi-kappler/comment_units", "max_issues_repo_head_hexsha": "8cb388b8c148214c023bece6f0e8cf115020b006", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "examples/fortran/util.f90", "max_forks_repo_name": "willi-kappler/comment_units", "max_forks_repo_head_hexsha": "8cb388b8c148214c023bece6f0e8cf115020b006", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.0714285714, "max_line_length": 38, "alphanum_fraction": 0.691943128, "num_tokens": 55, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9059898153067649, "lm_q2_score": 0.766293653760418, "lm_q1q2_score": 0.6942542458411471}} {"text": "! $UWHPSC/codes/fortran/builtinfcns2.f90\n\nprogram builtinfcns\n\n implicit none\n real :: pi, x, y ! note kind is not specified\n\n ! compute pi as arc-cosine of -1:\n pi = acos(-1.0)\n\n x = cos(pi)\n y = sqrt(exp(log(pi)))**2\n\n print *, \"pi = \", pi\n print *, \"x = \", x\n print *, \"y = \", y\n\nend program builtinfcns\n", "meta": {"hexsha": "28af7e2d85903714e8f0f66999cf0cec7dfdf68a", "size": 337, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/codes/fortran/builtinfcns2.f90", "max_stars_repo_name": "philipwangdk/HPC", "max_stars_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "uwhpsc/codes/fortran/builtinfcns2.f90", "max_issues_repo_name": "philipwangdk/HPC", "max_issues_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "uwhpsc/codes/fortran/builtinfcns2.f90", "max_forks_repo_name": "philipwangdk/HPC", "max_forks_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.7368421053, "max_line_length": 52, "alphanum_fraction": 0.5578635015, "num_tokens": 116, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9059898254600903, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6942542439506254}} {"text": "FUNCTION studnt (t, doff) RESULT(fn_val)\r\n\r\n! N.B. Argument IFAULT has been removed.\r\n \r\n! Code converted using TO_F90 by Alan Miller\r\n! Date: 2002-01-02 Time: 21:19:45\r\n\r\n! ALGORITHM AS 27 APPL. STATIST. VOL.19, NO.1\r\n\r\n! Calculate the upper tail area under Student's t-distribution\r\n\r\n! Translated from Algol by Alan Miller\r\n\r\nIMPLICIT NONE\r\nREAL, INTENT(IN) :: t\r\nREAL, INTENT(IN) :: doff\r\nREAL :: fn_val\r\n\r\n! Local variables\r\n\r\nREAL :: v, x, tt\r\nLOGICAL :: pos\r\nREAL, PARAMETER :: four = 4.0, one = 1.0, zero = 0.0, half = 0.5\r\nREAL, PARAMETER :: a1 = 0.09979441, a2 = -0.581821, a3 = 1.390993, &\r\n a4 = -1.222452, a5 = 2.151185\r\nREAL, PARAMETER :: b1 = 5.537409, b2 = 11.42343\r\nREAL, PARAMETER :: c1 = 0.04431742, c2 = -0.2206018, c3 = -0.03317253, &\r\n c4 = 5.679969, c5 = -12.96519\r\nREAL, PARAMETER :: d1 = 5.166733, d2 = 13.49862\r\nREAL, PARAMETER :: e1 = 0.009694901, e2 = -0.1408854, e3 = 1.88993, &\r\n e4 = -12.75532, e5 = 25.77532\r\nREAL, PARAMETER :: f1 = 4.233736, f2 = 14.3963\r\nREAL, PARAMETER :: g1 = -9.187228E-5, g2 = 0.03789901, g3 = -1.280346, &\r\n g4 = 9.249528, g5 = -19.08115\r\nREAL, PARAMETER :: h1 = 2.777816, h2 = 16.46132\r\nREAL, PARAMETER :: i1 = 5.79602E-4, i2 = -0.02763334, i3 = 0.4517029, &\r\n i4 = -2.657697, i5 = 5.127212\r\nREAL, PARAMETER :: j1 = 0.5657187, j2 = 21.83269\r\n\r\n! Check that number of degrees of freedom > 4.\r\n\r\nIF (doff <= four) THEN\r\n WRITE(*, *) '** Error in AS27 - degrees of freedom <= 4 **'\r\n RETURN\r\nEND IF\r\n\r\n! Evaluate series.\r\n\r\nv = one / doff\r\npos = (t >= zero)\r\ntt = ABS(t)\r\nx = half*(one + &\r\n tt*(((a1 + v*(a2 + v*(a3 + v*(a4 + v*a5)))) / (one - v*(b1 - v*b2))) + &\r\n tt*(((c1 + v*(c2 + v*(c3 + v*(c4 + v*c5)))) / (one - v*(d1 - v*d2))) + &\r\n tt*(((e1 + v*(e2 + v*(e3 + v*(e4 + v*e5)))) / (one - v*(f1 - v*f2))) + &\r\n tt*(((g1 + v*(g2 + v*(g3 + v*(g4 + v*g5)))) / (one - v*(h1 - v*h2))) + &\r\n tt*((i1 + v*(i2 + v*(i3 + v*(i4 + v*i5)))) / (one - v*(j1 - v*j2))) ))))) ** (-8)\r\nIF (pos) THEN\r\n fn_val = x\r\nELSE\r\n fn_val = one - x\r\nEND IF\r\n\r\nRETURN\r\nEND FUNCTION studnt\r\n", "meta": {"hexsha": "b9c15d0e7f51c6222826031a57ef11181e761fa5", "size": 2216, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/as27.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/as27.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/as27.f90", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 33.5757575758, "max_line_length": 86, "alphanum_fraction": 0.5121841155, "num_tokens": 928, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898254600902, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6942542342796744}} {"text": "!->Module LIB_FEM. Rafa Palacios. Last Update 15Jul2008.\n!\n!->Description.-\n!\n! This module includes specific subroutines for Finite Element solution\n! with banded matrices.\n!\n!->Subroutines.-\n!\n! fem_bandmat: Multiply a banded matrix by a full matrix.\n! fem_bandvec: Multiply a banded matrix by a vector.\n! fem_choleski_dcmp: Choleski decomposition of a symmetric banded matrix.\n! fem_choleski_solv: Solution of linear system with Choleski decomposition.\n! fem_1d_gauss_val: Database of 1-D Gauss point coordinates and weights.\n! fem_2d_gauss_num: Determines the number of gaussian Points in a 2-D element.\n! fem_2d_gauss_val: Database of 2-D Gauss point coordinates and weights.\n! fem_1d_shapefun: 1-D isoparametric shape functions.\n! fem_2d_shapefun: 2-D isoparametric Shape Functions.\n! fem_elmdof: Get index of element d.o.f. in the model.\n! fem_glob2loc_map: Get dof data from global to local matrix.\n! fem_glob2loc_extract: Get data from global vector into element grids.\n! fem_v2m: Convert vector to matrix.\n! fem_m2v: Convert matrix to vector array\n!\n!->Remarks.-\n!\n! 1) Compact storage of (anti)symmetric banded matrices:\n!\n! Actual matrix:\n!\n! -------------------------\n! |a11 a12 a13 0 0 |\n! |a12 a22 a23 a24 0 |\n! |a13 a23 a33 a34 a35 |\n! |0 a24 a34 a44 a45 |\n! |0 0 a35 a45 a55 |\n! -------------------------\n!\n! Stored matrix:\n!\n! ----------------\n! |a11 a12 a13 |\n! |a22 a23 a24 |\n! |a33 a34 a35 |\n! |a44 a45 0 |\n! |a55 0 0 |\n! ----------------\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nmodule lib_fem\n implicit none\n!\n! (This module does not contain Public Variables).\n!\n\n!-> Private variables.\n!\n! This parameter to simulate the machine epsilon for\n! a very small number which will cause singularity\n real(8), private, parameter:: Epsilon = 1.0d-13\n\n\n contains\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!-> Function FEM_BANDMAT\n!\n!-> Description.-\n!\n! Multiply a banded matrix by a full matrix.\n!\n!->Remarks:\n!\n! 1) The banded matrix is defined by its upper triangular submatrix.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n function fem_bandmat (Symmetry,A,B)\n!\n!-> I/O Variables.\n!\n character(len=1),intent(in) :: Symmetry ! Symmetry properties.\n real(8),intent(in) :: A(:,:) ! Banded Matrix, A.\n real(8),intent(in) :: B(:,:) ! Regular Matrix,B.\n real(8) :: fem_bandmat(size(A,DIM=1), size(B,DIM=2)) ! A\ufffdB\n!\n!-> Local Variables.\n!\n integer :: iCol ! Counters on columns of matrix B.\n!\n! Multiply each column of B using the vector multiplication.\n!\n do iCol=1, size(B,DIM=2)\n fem_bandmat(:,iCol)= fem_bandvec (Symmetry,A,B(:,iCol))\n end do\n!\n return\n end function fem_bandmat\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!-> Function FEM_BANDVEC\n!\n!-> Description.-\n!\n! Multiply a banded matrix by a vector.\n!\n!->Remarks:\n!\n! 1) The banded matrix is defined by its upper triangular submatrix.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n function fem_bandvec (Symmetry,A,b)\n!\n!-> I/O Variables.\n!\n character(len=1), intent(in) :: Symmetry ! =S or A: sym or ant matrix.\n real(8),intent(in) :: A(:,:) ! Banded Matrix, A.\n real(8),intent(in) :: b(:) ! Regular vector,b.\n real(8) :: fem_bandvec(size(b)) ! A\ufffdb\n!\n!-> Local Variables.\n!\n real(8) :: Delta ! +1 or -1 depending of symmetry properties.\n integer :: DimBand ! Length of the band for the current row.\n integer :: iRow ! Counter on rows.\n integer :: iCol ! Counters on columns.\n integer :: NumRows ! Number of rows.\n integer :: NumCols ! Number of columns in the matrix.\n!\n! Initialization of variables.\n!\n fem_bandvec=0.d0\n if (Symmetry.eq.'S') Delta= 1.d0\n if (Symmetry.eq.'A') Delta=-1.d0\n NumRows= size(b)\n NumCols= size(A,DIM=2)\n!\n! Multiply the upper triangular matrix by the vector.\n!\n DimBand=NumCols\n do iRow=1,NumRows\n if (iRow.gt.NumRows-NumCols+1) DimBand=DimBand-1\n do iCol=1,DimBand\n fem_bandvec(iRow)= fem_bandvec(iRow) + A(iRow,iCol)*b(iRow+iCol-1)\n end do\n end do\n!\n! Multiply the lower triangular matrix by the vector.\n!\n DimBand=NumCols\n do iRow=1,NumRows-1\n if (iRow.gt.NumRows-NumCols+1) DimBand=DimBand-1\n do iCol=2,DimBand\n fem_bandvec(iRow+iCol-1)= fem_bandvec(iRow+iCol-1) + Delta*A(iRow,iCol)*b(iRow)\n end do\n end do\n!\n return\n end function fem_bandvec\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!->Subroutine FEM_CHOLESKI_DCMP.\n!\n!->Description.-\n!\n! Cholesky decomposition for a banded symmetric positive definite\n! coefficient matrix.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n subroutine fem_choleski_dcmp (A,Error)\n!\n!-> I/O Variables.\n!\n real(8), intent(inout)::A (:,:) ! Input and output matrices.\n integer, intent(out) :: Error ! Error code.\n!\n!-> Local variables.\n!\n integer :: i, j, k ! Counters.\n integer :: NumBand ! Half-Bandwidth of the problem.\n real(8) :: Sum ! Partial sum of coefficient rates.\n!\n! Initialize variables.\n!\n Error=0\n NumBand= size(A,DIM=2)\n!\n! Loop in the coefficients of the matrix.\n!\n do i=1,size(A,DIM=1)\n do j=1,NumBand-1\n!\n! For each element, get the corresponding numerator in the decomposition\n! and store in the original matrix..\n!\n Sum=0.0d0\n do k= max(i+j - NumBand,1) , i-1\n Sum= Sum + A(k,1) * A(k,i+1-k) * A(k,i+j-k)\n enddo\n A(i,j)= A(i,j) - Sum\n enddo\n!\n! Update the element value in the decomposition and give an error if\n! the matrix is ill-conditioned.\n!\n if(abs(A(i,1)).le.Epsilon) then\n Error=-1\n return\n else\n do j = 2, NumBand\n A(i,j)= A(i,j) / A(i,1)\n enddo\n end if\n enddo\n!\n return\n end subroutine fem_choleski_dcmp\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!->Subroutine FEM_CHOLESKI_SOLV\n!\n!->Description.-\n!\n! Solve a linear system Ax=b, where A is given in its Choleski\n! factorization. The solution is performed through forward and\n! back substitution.\n!\n!->Remarks.-\n!\n! 1) Algorithms can be found in Belengundu & Chandrupatla's book\n! \"Finite Elements in Engineering\".\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n subroutine fem_choleski_solv (A,b)\n!\n!-> I/O Variables.\n!\n real(8), intent(in):: A(:,:) ! Matrix in Choleski form.\n real(8), intent(inout) :: b(:) ! Right Hand Side.\n!\n!-> Local variables.\n!\n integer :: i, j ! Counters on rows and columns.\n integer :: NumCols ! Half-Bandwidth of the matrix.\n integer :: NumRows ! Number of equations in the system.\n real(8) :: Sum ! Value to store sums.\n\n NumRows= size(A,DIM=1)\n NumCols= size(A,DIM=2)\n\n! Forward Substitution.\n do i=2,NumRows\n Sum= 0.0d0\n do j= max(1,i+1-NumCols), i-1\n Sum= Sum + A(j,i-j+1) * b(j)\n enddo\n b(i)= b(i)-Sum\n enddo\n\n! Backwards Substitution.\n b(NumRows) = b(NumRows)/A(NumRows,1)\n\n do i = NumRows-1, 1, -1\n Sum = 0.0d0\n do j= 2, min(NumCols, NumRows - i + 1)\n Sum = Sum + A(i,j) * b(j + i - 1)\n enddo\n b(i) = b(i)/A(i,1)- Sum\n enddo\n\n return\n end subroutine fem_choleski_solv\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!-> Subroutine FEM_1D_GAUSS_VAL\n!\n!-> Description.-\n!\n! Database of Weights and Coordinates for Gaussian Quadrature for 1-D\n! integration.\n!\n!->Remarks:\n!\n! 1) Coefficients from Abramowitz and Stegun.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n subroutine fem_1d_gauss_val (NumGauss,Coords,Weight)\n\n!-> I/O Variables.\n\n integer,intent(in) :: NumGauss ! Number of Gaussian points.\n real(8),intent(out):: Coords(NumGauss) ! Local Coordinates of the Points.\n real(8),intent(out):: Weight(NumGauss) ! Weights of the Gaussian Points.\n\n! Default output values.\n Coords=0.d0\n Weight=0.d0\n\n! Database of weights and location of gaussian points.\n select case(NumGauss)\n case(1)\n Coords(1)= 0.d0\n Weight(1)= 2.d0\n case(2)\n Coords(1)=-0.577350269189626d0\n Coords(2)= 0.577350269189626d0\n Weight(1)= 1.d0\n Weight(2)= 1.d0\n case(3)\n Coords(1)=-0.774596669241483d0\n Coords(2)= 0.d0\n Coords(3)= 0.774596669241483d0\n Weight(1)= 0.555555555555556d0\n Weight(2)= 0.888888888888889d0\n Weight(3)= 0.555555555555556d0\n case(4)\n Coords(1)=-0.861136311594053d0\n Coords(2)=-0.339981043584856d0\n Coords(3)= 0.339981043584856d0\n Coords(4)= 0.861136311594053d0\n Weight(1)= 0.347854845137454d0\n Weight(2)= 0.652145154862546d0\n Weight(3)= 0.652145154862546d0\n Weight(4)= 0.347854845137454d0\n case(5)\n Coords(1)=-0.906179845938664d0\n Coords(2)=-0.538469310105683d0\n Coords(3)= 0.d0\n Coords(4)= 0.538469310105683d0\n Coords(5)= 0.906179845938664d0\n Weight(1)= 0.236926885056189d0\n Weight(2)= 0.478628670499366d0\n Weight(3)= 0.568888888888889d0\n Weight(4)= 0.478628670499366d0\n Weight(5)= 0.236926885056189d0\n case(6)\n Coords(1)=-0.932469514203152d0\n Coords(2)=-0.661209386466265d0\n Coords(3)=-0.238619186083197d0\n Coords(4)= 0.238619186083197d0\n Coords(5)= 0.661209386466265d0\n Coords(6)= 0.932469514203152d0\n Weight(1)= 0.171324492379170d0\n Weight(2)= 0.360761573048139d0\n Weight(3)= 0.467913934572691d0\n Weight(4)= 0.467913934572691d0\n Weight(5)= 0.360761573048139d0\n Weight(6)= 0.171324492379170d0\n\n case default\n STOP 'Error: Number of Gauss points in 1-D elements larger than 6.'\n end select\n\n return\n end subroutine fem_1d_gauss_val\n\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!-> Subroutine FEM_1D_SHAPEFUN\n!\n!-> Description.-\n!\n! Calculate the value of 1-D isoparametric shape function and its\n! derivative at a inner point in the element defined by local coordinates.\n!\n!->Remarks:\n!\n! 1) The isoparametric shape functions were extracted from Chandrupatla and\n! Belengundu's book \"Finite Elements in Engineering\". All conventions in\n! the book are used here.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n subroutine fem_1d_shapefun (NumNodeElem, z, Fun, Der)\n!\n!-> I/O Variables.\n integer,intent(in) :: NumNodeElem ! Number of nodes in the element.\n real(8),intent(in) :: z ! Local Coordinate of the point.\n real(8),intent(out):: Fun(:) ! Shape Function.\n real(8),intent(out):: Der(:) ! Derivative of the Shape Function.\n\n! Initialization.\n Fun=0.d0\n Der=0.d0\n\n select case (NumNodeElem)\n\n! Three-noded beam:\n case (3)\n Fun(1)=-0.5d0*z*(1.d0-z)\n Fun(2)= 0.5d0*z*(1.d0+z)\n Fun(3)= 1.0d0-z*z\n Der(1)=-0.5d0*(1.d0-2.d0*z)\n Der(2)= 0.5d0*(1.d0+2.d0*z)\n Der(3)=-2.0d0*z\n\n! Two-noded beam:\n case (2)\n Fun(1)= 0.5d0*(1.d0-z)\n Fun(2)= 0.5d0*(1.d0+z)\n Der(1)=-0.5d0\n Der(2)= 0.5d0\n\n case default\n STOP 'Error: 1-D elements must have either 2 or 3 nodes'\n end select\n\n return\n end subroutine fem_1d_shapefun\n\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!-> Subroutine FEM_2D_GAUSS_NUM\n!\n!-> Description.-\n!\n! Determine the number of gauss points for the current type of element.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n subroutine fem_2d_gauss_num (Flag, NumNode_Elem, NumGauss)\n!\n!-> I/O Variables\n!\n integer,intent(in) :: NumNode_Elem ! # nodes in the element.\n integer,intent(out):: NumGauss ! # Gaussian points.\n integer,intent(in) :: Flag ! =0 for CTRIA, /=0 for CQUAD.\n!\n! Set the number of Gauss points depending of the type of element (CTRIA or\n! CQUAD) and the number of nodes of the element.\n!\n if (Flag.eq.0) then\n if (NumNode_Elem.gt.3) then\n NumGauss=7\n else\n NumGauss=3\n end if\n else\n if (NumNode_Elem.gt.4) then\n NumGauss=9\n else\n NumGauss=4\n end if\n endif\n!\n return\n end subroutine fem_2d_gauss_num\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!-> Subroutine FEM_2D_GAUSS_VAL\n!\n!-> Description.-\n!\n! Database of Weights and Coordinates for Gaussian Quadrature.\n!\n!->Remarks:\n!\n! 1) Coefficients are extracted from Zienkiewitz' book \"The Finite\n! Element Method\".\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n subroutine fem_2d_gauss_val (Flag, NumGauss, Coords, Weight, iErr)\n!\n!-> I/O Variables.\n!\n integer,intent(in) :: Flag ! =0 for CTRIA, /=0 for CQUAD.\n integer,intent(in) :: NumGauss ! Number of Gaussian points.\n real(8),intent(out):: Coords(:,:) ! Local Coordinates of the Points.\n real(8),intent(out):: Weight(:) ! Weights of the Gaussian Points.\n integer,intent(out):: iErr ! Error Code.\n!\n!-> Local variables.\n!\n integer, parameter:: MaxPoints=10 ! Maximum # of linear points.\n integer :: iGauss ! Counter in the Gaussian points.\n integer :: i1,i2 ! Counters in the linear points.\n integer :: NumPoints ! Number of linear points.\n real(8) :: CoordsLin(MaxPoints) ! Local Coordinates for [-1,1] integration.\n real(8) :: WeightLin(MaxPoints) ! Local Coordinates for [-1,1] integration.\n\n! Default output values.\n iErr=0\n Coords=0.d0\n Weight=0.d0\n\n! Quadrilateral Elements.\n if (Flag.ne.0) then\n NumPoints=nint(sqrt(float(NumGauss)))\n if ((NumGauss-NumPoints*NumPoints).ne.0) NumPoints=0\n\n select case(NumPoints)\n case(1)\n CoordsLin(1)=0.d0\n WeightLin(1)=0.d0\n case(2)\n CoordsLin(1)=-1.d0/dsqrt(3.d0)\n CoordsLin(2)= 1.d0/dsqrt(3.d0)\n WeightLin(1)= 1.d0\n WeightLin(2)= 1.d0\n case(3)\n CoordsLin(1)=-dsqrt(.6d0)\n CoordsLin(2)= 0.d0\n CoordsLin(3)= dsqrt(.6d0)\n WeightLin(1)= 5.d0/9.d0\n WeightLin(2)= 8.d0/9.d0\n WeightLin(3)= 5.d0/9.d0\n case(4)\n CoordsLin(1)=-0.861136311594053d0\n CoordsLin(2)=-0.339981043584856d0\n CoordsLin(3)= 0.339981043584856d0\n CoordsLin(4)= 0.861136311594053d0\n WeightLin(1)= 0.347854845137454d0\n WeightLin(2)= 0.652145154862546d0\n WeightLin(3)= 0.652145154862546d0\n WeightLin(4)= 0.347854845137454d0\n case(5)\n CoordsLin(1)=-0.906179845938664d0\n CoordsLin(2)=-0.538469310105683d0\n CoordsLin(3)= 0.d0\n CoordsLin(4)= 0.538469310105683d0\n CoordsLin(5)= 0.906179845938664d0\n WeightLin(1)= 0.236926885056189d0\n WeightLin(2)= 0.478628670499366d0\n WeightLin(3)= 0.568888888888889d0\n WeightLin(4)= 0.478628670499366d0\n WeightLin(5)= 0.236926885056189d0\n case default\n iErr=-1\n end select\n\n iGauss=0\n do i1=1,NumPoints\n do i2=1,NumPoints\n iGauss= iGauss+1\n Coords(iGauss,1)= CoordsLin(i1)\n Coords(iGauss,2)= CoordsLin(i2)\n Weight(iGauss) = WeightLin(i1)*WeightLin(i2)\n end do\n end do\n\n! Triangular elements.\n else if (Flag.eq.0) then\n NumPoints=NumGauss\n select case(NumPoints)\n case(3)\n Coords(1,1)=1.d0/6.d0\n Coords(1,2)=1.d0/6.d0\n Coords(2,1)=2.d0/3.d0\n Coords(2,2)=1.d0/6.d0\n Coords(3,1)=1.d0/6.d0\n Coords(3,2)=2.d0/3.d0\n Weight(1:3)=1.d0/6.d0\n case(7)\n Coords(1,1)= 0.101286507323456d0\n Coords(1,2)= 0.101286507323456d0\n Weight(1) = 0.0629695902724d0\n Coords(2,1)= 0.797426985353087d0\n Coords(2,2)= 0.101286507323456d0\n Weight(2) = 0.0629695902724d0\n Coords(3,1)= 0.101286507323456d0\n Coords(3,2)= 0.797426985353087d0\n Weight(3) = 0.0629695902724d0\n Coords(4,1)= 0.470142064105115d0\n Coords(4,2)= 0.059715871789770d0\n Weight(4) = 0.0661970763943d0\n Coords(5,1)= 0.470142064105115d0\n Coords(5,2)= 0.470142064105115d0\n Weight(5) = 0.0661970763943d0\n Coords(6,1)= 0.059715871789770d0\n Coords(6,2)= 0.470142064105115d0\n Weight(6) = 0.0661970763943d0\n Coords(7,1)= 0.333333333333333d0\n Coords(7,2)= 0.333333333333333d0\n Weight(7) = 0.1125d0\n case default\n iErr=-1\n end select\n end if\n\n return\n end subroutine fem_2d_gauss_val\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!-> Subroutine FEM_2D_SHAPEFUN\n!\n!-> Description.-\n!\n! Calculate the value of the 2-D isoparametric shape function and its\n! derivatives at a inner point in the element defined by local coordinates.\n!\n!->Remarks:\n!\n! 1) The isoparametric shape functions were extracted from Chandrupatla and\n! Belengundu's book \"Finite Elements in Engineering\". All conventions in\n! the book are used here.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n subroutine fem_2d_shapefun (Flag, Node, z1, z2, Fun, Der)\n!\n!-> I/O Variables.\n!\n integer,intent(in) :: Flag ! =0: for CTRIA, /=0: for CQUAD.\n integer,intent(in) :: Node(:) ! Array on nodes (=0: node not present).\n real(8),intent(in) :: z1,z2 ! Local Coordinates of the Points.\n real(8),intent(out):: Fun(:) ! Shape Function.\n real(8),intent(out):: Der(:,:) ! Derivative of the Shape Function.\n!\n!-> Local variables.\n!\n real(8) :: z3 ! Third variable for triangular elements.\n!\n! Initialization.\n!\n Fun=0.d0\n Der=0.d0\n!\n!\n!-> Quadrilateral Elements:\n! ----------------------\n!\n if (Flag.ne.0) then\n!\n! Shape Functions.\n!\n if (Node(9).ne.0) Fun(9)= (1.d0-z1*z1)*(1.d0-z2*z2)\n if (Node(5).ne.0) Fun(5)=.5d0 * ((1.d0-z1*z1)*(1.d0-z2)-Fun(9))\n if (Node(7).ne.0) Fun(7)=.5d0 * ((1.d0-z1*z1)*(1.d0+z2)-Fun(9))\n if (Node(6).ne.0) Fun(6)=.5d0 * ((1.d0-z2*z2)*(1.d0+z1)-Fun(9))\n if (Node(8).ne.0) Fun(8)=.5d0 * ((1.d0-z2*z2)*(1.d0-z1)-Fun(9))\n!\n Fun(1)=.25d0 * ((1.d0-z1)*(1.d0-z2)-Fun(9)) - .5d0*(Fun(8)+Fun(5))\n Fun(2)=.25d0 * ((1.d0+z1)*(1.d0-z2)-Fun(9)) - .5d0*(Fun(5)+Fun(6))\n Fun(3)=.25d0 * ((1.d0+z1)*(1.d0+z2)-Fun(9)) - .5d0*(Fun(6)+Fun(7))\n Fun(4)=.25d0 * ((1.d0-z1)*(1.d0+z2)-Fun(9)) - .5d0*(Fun(7)+Fun(8))\n!\n! Derivatives with z1.\n!\n if (Node(9).ne.0) Der(9,1)=-2.d0*z1*(1.d0-z2*z2)\n if (Node(5).ne.0) Der(5,1)=-z1*(1.d0-z2) -.5d0*Der(9,1)\n if (Node(7).ne.0) Der(7,1)=-z1*(1.d0+z2) -.5d0*Der(9,1)\n if (Node(6).ne.0) Der(6,1)=.5d0*( (1.d0-z2*z2)-Der(9,1))\n if (Node(8).ne.0) Der(8,1)=.5d0*(-(1.d0-z2*z2)-Der(9,1))\n!\n Der(1,1)=.25d0*(-(1.d0-z2)-Der(9,1)) - .5d0*(Der(8,1)+Der(5,1))\n Der(2,1)=.25d0*( (1.d0-z2)-Der(9,1)) - .5d0*(Der(5,1)+Der(6,1))\n Der(3,1)=.25d0*( (1.d0+z2)-Der(9,1)) - .5d0*(Der(6,1)+Der(7,1))\n Der(4,1)=.25d0*(-(1.d0+z2)-Der(9,1)) - .5d0*(Der(7,1)+Der(8,1))\n!\n! Derivatives with z2.\n!\n if (Node(9).ne.0) Der(9,2)=-2.d0*z2*(1.d0-z1*z1)\n if (Node(5).ne.0) Der(5,2)=.5d0*(-(1.d0-z1*z1)-Der(9,2))\n if (Node(7).ne.0) Der(7,2)=.5d0*( (1.d0-z1*z1)-Der(9,2))\n if (Node(6).ne.0) Der(6,2)=-z2*(1.d0+z1) -.5d0*Der(9,2)\n if (Node(8).ne.0) Der(8,2)=-z2*(1.d0-z1) -.5d0*Der(9,2)\n!\n Der(1,2)=.25d0*(-(1.d0-z1)-Der(9,2)) - .5d0*(Der(8,2)+Der(5,2))\n Der(2,2)=.25d0*(-(1.d0+z1)-Der(9,2)) - .5d0*(Der(5,2)+Der(6,2))\n Der(3,2)=.25d0*( (1.d0+z1)-Der(9,2)) - .5d0*(Der(6,2)+Der(7,2))\n Der(4,2)=.25d0*( (1.d0-z1)-Der(9,2)) - .5d0*(Der(7,2)+Der(8,2))\n!\n!\n!-> Triangular Elements:\n! -------------------\n!\n else\n z3=1.d0-z1-z2\n!\n! Shape Functions.\n!\n if (Node(5).ne.0) Fun(5)= 4.d0*z3*z1\n if (Node(6).ne.0) Fun(6)= 4.d0*z1*z2\n if (Node(7).ne.0) Fun(7)= 4.d0*z2*z3\n!\n Fun(1)= z3 - .5d0*(Fun(5)+Fun(7))\n Fun(2)= z1 - .5d0*(Fun(6)+Fun(5))\n Fun(3)= z2 - .5d0*(Fun(7)+Fun(6))\n!\n! Derivatives with z1.\n!\n if (Node(5).ne.0) Der(5,1)= 4.d0*(z3-z1)\n if (Node(6).ne.0) Der(6,1)= 4.d0*z2\n if (Node(7).ne.0) Der(7,1)=-4.d0*z2\n!\n Der(1,1)=-1.d0 - .5d0*(Der(5,1)+Der(7,1))\n Der(2,1)= 1.d0 - .5d0*(Der(6,1)+Der(5,1))\n Der(3,1)= - .5d0*(Der(7,1)+Der(6,1))\n!\n! Derivatives with z2.\n!\n if (Node(5).ne.0) Der(5,2)=-4.d0*z1\n if (Node(6).ne.0) Der(6,2)= 4.d0*z1\n if (Node(7).ne.0) Der(7,2)= 4.d0*(z3-z2)\n!\n Der(1,2)=-1.d0 - .5d0*(Der(5,2)+Der(7,2))\n Der(2,2)= - .5d0*(Der(6,2)+Der(5,2))\n Der(3,2)= 1.d0 - .5d0*(Der(7,2)+Der(6,2))\n!\n end if\n!\n return\n end subroutine fem_2d_shapefun\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!->Subroutine FEM_ELMDOF.\n!\n!->Description.-\n!\n! Find the corresponding d.o.f's for an element and store them in\n! a steering vector.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n subroutine fem_elmdof(NumDofNode,NodeList,g)\n!\n!-> I/O Variables.\n!\n integer,intent(in) :: NumDofNode ! Number of d.o.f.'s in each node.\n integer,intent(in) :: NodeList(:) ! List of nodes in the element.\n integer,intent(out):: g(:) ! Global d.o.f's in the element.\n!\n!-> Local variables.\n!\n integer::i,j,m\n!\n! Initialize.\n g= 0;\n m= 0;\n!\n! Loop in the nodes.\n do i=1,size(NodeList)\n if(NodeList(i).ne.0) then\n do j=1,NumDofNode\n m= m+1\n g(m)= NumDofNode*(NodeList(i)-1)+j\n end do\n end if\n end do\n!\n return\n end subroutine fem_elmdof\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!->Subroutine FEM_GLOB2LOC_MAP.\n!\n!->Description.-\n!\n! Extract the elements corresponding to a given dof from a global\n! matrix and add them to a given local matrix.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n subroutine fem_glob2loc_map (global,local,g)\n\n ! I/O Variables.\n real(8),intent(in) :: global(:,:)\n real(8),intent(out) :: local(:,:)\n integer, intent(in) :: g(:)\n!\n!-> Local Variables.\n!\n integer:: i\n!\n do i=1,size(local,1)\n local(i,:)=local(i,:)+global(g(i),:)\n end do\n!\n return\n end subroutine fem_glob2loc_map\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!->Subroutine FEM_GLOB2LOC_EXTRACT.\n!\n!->Description.-\n!\n! Extract the values corresponding to given nodes from a vector of global\n! data.\n!\n! -> sm: Input/Output description:\n!\n! - ElemNodes(ii) = nn, where ii is the ii-th node according to the local elem.\n! ... ordering and nn is the nn-th element in the global ordering\n! - GlobVector(nn,:): array associated to the nn-th node (in the global ordering)\n! ... the quantities here stored are not associated to any\n! ... frame of reference\n! - LocVector(ii,:): array associated to the ii-th node (local), i.e. to the\n! ... nn-th node (global). The association is extablished through\n! ... ElemNodes. No change of frame of reference is performed\n!\n! e.g.: sample call from input_xxx.f90 (output_elems)\n! fem_glob2loc_extract (Elem(iElem)%Conn,Coords,PosElem,NumNE)\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n subroutine fem_glob2loc_extract (ElemNodes,GlobVector,LocVector,NumNodeElem)\n\n! I/O variables.\n integer,intent(in) :: ElemNodes (:) ! Nodes in the current element.\n real(8),intent(in) :: GlobVector(:,:) ! Vector of global values.\n real(8),intent(inout):: LocVector (:,:) ! Vector of local values.\n integer,intent(out):: NumNodeElem ! Actual number of nodes in the element.\n\n! Local variables.\n integer:: i\n\n! Compute number of non-zero connectivies in the element.\n NumNodeElem=0\n do i=1,size(ElemNodes)\n if (ElemNodes(i).gt.0) NumNodeElem=NumNodeElem+1\n end do\n\n! Extract data from global vector.\n LocVector=0.d0\n LocVector(1:NumNodeElem,:)=GlobVector(ElemNodes(1:NumNodeElem),:)\n return\n end subroutine fem_glob2loc_extract\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!->Subroutine FEM_V2M.\n!\n!->Description.-\n!\n! Convert array of degrees of freedom to matrix form.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n function fem_v2m (Vector,Nrow,Ncol)\n\n! I/O variables.\n real(8),intent(in) :: Vector(:) ! Vector.\n integer,intent(in) :: Nrow ! Number of rows in the matrix.\n integer,intent(in) :: Ncol ! Number of columns in the matrix.\n real(8) :: fem_v2m(Nrow,Ncol) ! Matrix.\n\n! Local variables.\n integer:: i,iCol,iRow ! Counters.\n\n iRow=1\n iCol=1\n do i=1,size(Vector)\n\n fem_v2m(iRow,iCol)=Vector(i)\n\n if (iCol.eq.NCol) then\n iRow=iRow+1\n iCol=1\n else\n iCol=iCol+1\n end if\n end do\n\n return\n end function fem_v2m\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!->Subroutine FEM_M2V.\n!\n!->Description.-\n!\n! Convert matrix to vector array.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n function fem_m2v (Matrix,N,Filter)\n\n! I/O variables.\n real(8),intent(in) :: Matrix(:,:) ! Matrix.\n integer,intent(in) :: N ! Size of the vector.\n integer,optional,intent(in):: Filter(:) ! Filter on rows of the matrix.\n real(8) :: fem_m2v(N) ! Vector.\n\n! Local variables.\n integer:: i,j,k ! Counters.\n\n! Initialize\n k=0\n fem_m2v=0.d0\n\n do i=1,size(Matrix,DIM=1)\n do j=1,size(Matrix,DIM=2)\n\n if (present(Filter)) then\n if (Filter(i).ne.0) then\n k=k+1\n fem_m2v(k)=Matrix(i,j)\n end if\n\n else\n k=k+1\n fem_m2v(k)=Matrix(i,j)\n end if\n end do\n end do\n\n return\n end function fem_m2v\n\n function fem_v2m_filter(vector, nrows, ncols, listin)\n real(8), intent(IN) :: vector(:)\n integer, intent(IN) :: nrows\n integer, intent(IN) :: ncols\n integer, intent(IN) :: listin(:)\n\n real(8) :: fem_v2m_filter(nrows, ncols)\n\n integer :: i_node\n integer :: ii\n\n fem_v2m_filter = 0.0d0\n ii = 0\n do i_node=1, nrows\n if (listin(i_node) <= 0) then\n cycle\n end if\n ii = (listin(i_node) - 1)*ncols\n\n fem_v2m_filter(i_node, :) = vector(ii+1:ii+6)\n end do\nend function fem_v2m_filter\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!->Subroutine FEM_N2D.\n!\n!->Description.-\n!\n! Convert node array to degrees of freedom.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n function fem_n2d (NumNodes,NumDofNode,NodeList)\n\n! I/O variables.\n integer,intent(in):: NumNodes ! Number of degrees of freedom in the model.\n integer,intent(in):: NumDofNode ! Number of degrees of freedom on each node.\n integer,intent(in):: NodeList(:) ! Nodes in the global array.\n integer :: fem_n2d(NumNodes*NumDofNode) ! Vector.\n\n! Local variables.\n integer:: i,j,k ! Counters.\n\n! Initialize\n k=0\n fem_n2d=0\n\n do i=1,size(NodeList)\n do j=1,NumDofNode\n k=k+1\n if (NodeList(i).ne.0) fem_n2d(k)= NumDofNode*(NodeList(i)-1)+j\n end do\n end do\n\n return\n end function fem_n2d\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nend module lib_fem\n", "meta": {"hexsha": "f53d7a7dd190acbfd706d416f88e686fdf7a1e3e", "size": 27309, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/xbeam_base/lib_fem.f90", "max_stars_repo_name": "fonsocarre/xbeam", "max_stars_repo_head_hexsha": "56d933b8f0de6e03615bfc73003c524dfdafc00b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-12-03T16:06:06.000Z", "max_stars_repo_stars_event_max_datetime": "2017-12-03T16:06:06.000Z", "max_issues_repo_path": "src/xbeam_base/lib_fem.f90", "max_issues_repo_name": "ImperialCollegeLondon/xbeam", "max_issues_repo_head_hexsha": "56d933b8f0de6e03615bfc73003c524dfdafc00b", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2018-05-20T23:38:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-10T08:16:30.000Z", "max_forks_repo_path": "src/xbeam_base/lib_fem.f90", "max_forks_repo_name": "fonsocarre/xbeam", "max_forks_repo_head_hexsha": "56d933b8f0de6e03615bfc73003c524dfdafc00b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-02-16T04:17:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-16T04:17:45.000Z", "avg_line_length": 28.0668036999, "max_line_length": 87, "alphanum_fraction": 0.558240873, "num_tokens": 9367, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989822921759, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6942542323345673}} {"text": " \n SUBROUTINE B2INK(X,NX,Y,NY,FCN,LDF,KX,KY,TX,TY,BCOEF,WORK,IFLAG)\nC***BEGIN PROLOGUE B2INK\nC***DATE WRITTEN 25 MAY 1982\nC***REVISION DATE 25 MAY 1982\nC***REVISION HISTORY (YYMMDD)\nC 000330 Modified array declarations. (JEC)\nC***CATEGORY NO. E1A\nC***KEYWORDS INTERPOLATION, TWO-DIMENSIONS, GRIDDED DATA, SPLINES,\nC PIECEWISE POLYNOMIALS\nC***AUTHOR BOISVERT, RONALD, NBS\nC SCIENTIFIC COMPUTING DIVISION\nC NATIONAL BUREAU OF STANDARDS\nC WASHINGTON, DC 20234\nC***PURPOSE B2INK DETERMINES A PIECEWISE POLYNOMIAL FUNCTION THAT\nC INTERPOLATES TWO-DIMENSIONAL GRIDDED DATA. USERS SPECIFY\nC THE POLYNOMIAL ORDER (DEGREE+1) OF THE INTERPOLANT AND\nC (OPTIONALLY) THE KNOT SEQUENCE.\nC***DESCRIPTION\nC\nC B2INK determines the parameters of a function that interpolates the\nC two-dimensional gridded data (X(i),Y(j),FCN(i,j)) for i=1,..,NX and\nC j=1,..,NY. The interpolating function and its derivatives may\nC subsequently be evaluated by the function B2VAL.\nC\nC The interpolating function is a piecewise polynomial function\nC represented as a tensor product of one-dimensional B-splines. The\nC form of this function is\nC\nC NX NY\nC S(x,y) = SUM SUM a U (x) V (y)\nC i=1 j=1 ij i j\nC\nC where the functions U(i) and V(j) are one-dimensional B-spline\nC basis functions. The coefficients a(i,j) are chosen so that\nC\nC S(X(i),Y(j)) = FCN(i,j) for i=1,..,NX and j=1,..,NY\nC\nC Note that for each fixed value of y S(x,y) is a piecewise\nC polynomial function of x alone, and for each fixed value of x S(x,\nC y) is a piecewise polynomial function of y alone. In one dimension\nC a piecewise polynomial may be created by partitioning a given\nC interval into subintervals and defining a distinct polynomial piece\nC on each one. The points where adjacent subintervals meet are called\nC knots. Each of the functions U(i) and V(j) above is a piecewise\nC polynomial.\nC\nC Users of B2INK choose the order (degree+1) of the polynomial pieces\nC used to define the piecewise polynomial in each of the x and y\nC directions (KX and KY). Users also may define their own knot\nC sequence in x and y separately (TX and TY). If IFLAG=0, however,\nC B2INK will choose sequences of knots that result in a piecewise\nC polynomial interpolant with KX-2 continuous partial derivatives in\nC x and KY-2 continuous partial derivatives in y. (KX knots are taken\nC near each endpoint, not-a-knot end conditions are used, and the\nC remaining knots are placed at data points if KX is even or at\nC midpoints between data points if KX is odd. The y direction is\nC treated similarly.)\nC\nC After a call to B2INK, all information necessary to define the\nC interpolating function are contained in the parameters NX, NY, KX,\nC KY, TX, TY, and BCOEF. These quantities should not be altered until\nC after the last call of the evaluation routine B2VAL.\nC\nC\nC I N P U T\nC ---------\nC\nC X Real 1D array (size NX)\nC Array of x abcissae. Must be strictly increasing.\nC\nC NX Integer scalar (.GE. 3)\nC Number of x abcissae.\nC\nC Y Real 1D array (size NY)\nC Array of y abcissae. Must be strictly increasing.\nC\nC NY Integer scalar (.GE. 3)\nC Number of y abcissae.\nC\nC FCN Real 2D array (size LDF by NY)\nC Array of function values to interpolate. FCN(I,J) should\nC contain the function value at the point (X(I),Y(J))\nC\nC LDF Integer scalar (.GE. NX)\nC The actual leading dimension of FCN used in the calling\nC calling program.\nC\nC KX Integer scalar (.GE. 2, .LT. NX)\nC The order of spline pieces in x.\nC (Order = polynomial degree + 1)\nC\nC KY Integer scalar (.GE. 2, .LT. NY)\nC The order of spline pieces in y.\nC (Order = polynomial degree + 1)\nC\nC\nC I N P U T O R O U T P U T\nC -----------------------------\nC\nC TX Real 1D array (size NX+KX)\nC The knots in the x direction for the spline interpolant.\nC If IFLAG=0 these are chosen by B2INK.\nC If IFLAG=1 these are specified by the user.\nC (Must be non-decreasing.)\nC\nC TY Real 1D array (size NY+KY)\nC The knots in the y direction for the spline interpolant.\nC If IFLAG=0 these are chosen by B2INK.\nC If IFLAG=1 these are specified by the user.\nC (Must be non-decreasing.)\nC\nC\nC O U T P U T\nC -----------\nC\nC BCOEF Real 2D array (size NX by NY)\nC Array of coefficients of the B-spline interpolant.\nC This may be the same array as FCN.\nC\nC\nC M I S C E L L A N E O U S\nC -------------------------\nC\nC WORK Real 1D array (size NX*NY + max( 2*KX*(NX+1),\nC 2*KY*(NY+1) ))\nC Array of working storage.\nC\nC IFLAG Integer scalar.\nC On input: 0 == knot sequence chosen by B2INK\nC 1 == knot sequence chosen by user.\nC On output: 1 == successful execution\nC 2 == IFLAG out of range\nC 3 == NX out of range\nC 4 == KX out of range\nC 5 == X not strictly increasing\nC 6 == TX not non-decreasing\nC 7 == NY out of range\nC 8 == KY out of range\nC 9 == Y not strictly increasing\nC 10 == TY not non-decreasing\nC\nC***REFERENCES CARL DE BOOR, A PRACTICAL GUIDE TO SPLINES,\nC SPRINGER-VERLAG, NEW YORK, 1978.\nC CARL DE BOOR, EFFICIENT COMPUTER MANIPULATION OF TENSOR\nC PRODUCTS, ACM TRANSACTIONS ON MATHEMATICAL SOFTWARE,\nC VOL. 5 (1979), PP. 173-182.\nC***ROUTINES CALLED BTPCF,BKNOT\nC***END PROLOGUE B2INK\nC\nC ------------\nC DECLARATIONS\nC ------------\nC\nC PARAMETERS\nC\n INTEGER\n * NX, NY, LDF, KX, KY, IFLAG\n REAL\n * X(NX), Y(NY), FCN(LDF,NY), TX(*), TY(*), BCOEF(NX,NY),\n * WORK(*)\nC\nC LOCAL VARIABLES\nC\n INTEGER\n * I, IW, NPK\nC\nC -----------------------\nC CHECK VALIDITY OF INPUT\nC -----------------------\nC\nC***FIRST EXECUTABLE STATEMENT\n IF ((IFLAG .LT. 0) .OR. (IFLAG .GT. 1)) GO TO 920\n IF (NX .LT. 3) GO TO 930\n IF (NY .LT. 3) GO TO 970\n IF ((KX .LT. 2) .OR. (KX .GE. NX)) GO TO 940\n IF ((KY .LT. 2) .OR. (KY .GE. NY)) GO TO 980\n DO 10 I=2,NX\n IF (X(I) .LE. X(I-1)) GO TO 950\n 10 CONTINUE\n DO 20 I=2,NY\n IF (Y(I) .LE. Y(I-1)) GO TO 990\n 20 CONTINUE\n IF (IFLAG .EQ. 0) GO TO 50\n NPK = NX + KX\n DO 30 I=2,NPK\n IF (TX(I) .LT. TX(I-1)) GO TO 960\n 30 CONTINUE\n NPK = NY + KY\n DO 40 I=2,NPK\n IF (TY(I) .LT. TY(I-1)) GO TO 1000\n 40 CONTINUE\n 50 CONTINUE\nC\nC ------------\nC CHOOSE KNOTS\nC ------------\nC\n IF (IFLAG .NE. 0) GO TO 100\n CALL BKNOT(X,NX,KX,TX)\n CALL BKNOT(Y,NY,KY,TY)\n 100 CONTINUE\nC\nC -------------------------------\nC CONSTRUCT B-SPLINE COEFFICIENTS\nC -------------------------------\nC\n IFLAG = 1\n IW = NX*NY + 1\n CALL BTPCF(X,NX,FCN,LDF,NY,TX,KX,WORK,WORK(IW))\n CALL BTPCF(Y,NY,WORK,NY,NX,TY,KY,BCOEF,WORK(IW))\n GO TO 9999\nC\nC -----\nC EXITS\nC -----\nC\n 920 CONTINUE\n CALL XERRWV('B2INK - IFLAG=I1 IS OUT OF RANGE.',\n * 35,2,1,1,IFLAG,I2,0,R1,R2)\n IFLAG = 2\n GO TO 9999\nC\n 930 CONTINUE\n IFLAG = 3\n CALL XERRWV('B2INK - NX=I1 IS OUT OF RANGE.',\n * 32,IFLAG,1,1,NX,I2,0,R1,R2)\n GO TO 9999\nC\n 940 CONTINUE\n IFLAG = 4\n CALL XERRWV('B2INK - KX=I1 IS OUT OF RANGE.',\n * 32,IFLAG,1,1,KX,I2,0,R1,R2)\n GO TO 9999\nC\n 950 CONTINUE\n IFLAG = 5\n CALL XERRWV('B2INK - X ARRAY MUST BE STRICTLY INCREASING.',\n * 46,IFLAG,1,0,I1,I2,0,R1,R2)\n GO TO 9999\nC\n 960 CONTINUE\n IFLAG = 6\n CALL XERRWV('B2INK - TX ARRAY MUST BE NON-DECREASING.',\n * 42,IFLAG,1,0,I1,I2,0,R1,R2)\n GO TO 9999\nC\n 970 CONTINUE\n IFLAG = 7\n CALL XERRWV('B2INK - NY=I1 IS OUT OF RANGE.',\n * 32,IFLAG,1,1,NY,I2,0,R1,R2)\n GO TO 9999\nC\n 980 CONTINUE\n IFLAG = 8\n CALL XERRWV('B2INK - KY=I1 IS OUT OF RANGE.',\n * 32,IFLAG,1,1,KY,I2,0,R1,R2)\n GO TO 9999\nC\n 990 CONTINUE\n IFLAG = 9\n CALL XERRWV('B2INK - Y ARRAY MUST BE STRICTLY INCREASING.',\n * 46,IFLAG,1,0,I1,I2,0,R1,R2)\n GO TO 9999\nC\n 1000 CONTINUE\n IFLAG = 10\n CALL XERRWV('B2INK - TY ARRAY MUST BE NON-DECREASING.',\n * 42,IFLAG,1,0,I1,I2,0,R1,R2)\n GO TO 9999\nC\n 9999 CONTINUE\n RETURN\n END\n SUBROUTINE BKNOT(X,N,K,T)\nC***BEGIN PROLOGUE BKNOT\nC***REFER TO B2INK,B3INK\nC***ROUTINES CALLED (NONE)\nC***REVISION HISTORY (YYMMDD)\nC 000330 Modified array declarations. (JEC)\nC***END PROLOGUE BKNOT\nC\nC --------------------------------------------------------------------\nC BKNOT CHOOSES A KNOT SEQUENCE FOR INTERPOLATION OF ORDER K AT THE\nC DATA POINTS X(I), I=1,..,N. THE N+K KNOTS ARE PLACED IN THE ARRAY\nC T. K KNOTS ARE PLACED AT EACH ENDPOINT AND NOT-A-KNOT END\nC CONDITIONS ARE USED. THE REMAINING KNOTS ARE PLACED AT DATA POINTS\nC IF N IS EVEN AND BETWEEN DATA POINTS IF N IS ODD. THE RIGHTMOST\nC KNOT IS SHIFTED SLIGHTLY TO THE RIGHT TO INSURE PROPER INTERPOLATION\nC AT X(N) (SEE PAGE 350 OF THE REFERENCE).\nC --------------------------------------------------------------------\nC\nC ------------\nC DECLARATIONS\nC ------------\nC\nC PARAMETERS\nC\n INTEGER\n * N, K\n REAL\n * X(N), T(*)\nC\nC LOCAL VARIABLES\nC\n INTEGER\n * I, J, IPJ, NPJ, IP1\n REAL\n * RNOT\nC\nC\nC ----------------------------\nC PUT K KNOTS AT EACH ENDPOINT\nC ----------------------------\nC\nC (SHIFT RIGHT ENPOINTS SLIGHTLY -- SEE PG 350 OF REFERENCE)\n RNOT = X(N) + 0.10E0*( X(N)-X(N-1) )\n DO 110 J=1,K\n T(J) = X(1)\n NPJ = N + J\n T(NPJ) = RNOT\n 110 CONTINUE\nC\nC --------------------------\nC DISTRIBUTE REMAINING KNOTS\nC --------------------------\nC\n IF (MOD(K,2) .EQ. 1) GO TO 150\nC\nC CASE OF EVEN K -- KNOTS AT DATA POINTS\nC\n I = (K/2) - K\n JSTRT = K+1\n DO 120 J=JSTRT,N\n IPJ = I + J\n T(J) = X(IPJ)\n 120 CONTINUE\n GO TO 200\nC\nC CASE OF ODD K -- KNOTS BETWEEN DATA POINTS\nC\n 150 CONTINUE\n I = (K-1)/2 - K\n IP1 = I + 1\n JSTRT = K + 1\n DO 160 J=JSTRT,N\n IPJ = I + J\n T(J) = 0.50E0*( X(IPJ) + X(IPJ+1) )\n 160 CONTINUE\n 200 CONTINUE\nC\n RETURN\n END\n SUBROUTINE BTPCF(X,N,FCN,LDF,NF,T,K,BCOEF,WORK)\nC***BEGIN PROLOGUE BTPCF\nC***REFER TO B2INK,B3INK\nC***ROUTINES CALLED BINTK,BNSLV\nC***REVISION HISTORY (YYMMDD)\nC 000330 Modified array declarations. (JEC)\nC***END PROLOGUE BTPCF\nC\nC -----------------------------------------------------------------\nC BTPCF COMPUTES B-SPLINE INTERPOLATION COEFFICIENTS FOR NF SETS\nC OF DATA STORED IN THE COLUMNS OF THE ARRAY FCN. THE B-SPLINE\nC COEFFICIENTS ARE STORED IN THE ROWS OF BCOEF HOWEVER.\nC EACH INTERPOLATION IS BASED ON THE N ABCISSA STORED IN THE\nC ARRAY X, AND THE N+K KNOTS STORED IN THE ARRAY T. THE ORDER\nC OF EACH INTERPOLATION IS K. THE WORK ARRAY MUST BE OF LENGTH\nC AT LEAST 2*K*(N+1).\nC -----------------------------------------------------------------\nC\nC ------------\nC DECLARATIONS\nC ------------\nC\nC PARAMETERS\nC\n INTEGER\n * N, LDF, K\n REAL\n * X(N), FCN(LDF,NF), T(*), BCOEF(NF,N), WORK(*)\nC\nC LOCAL VARIABLES\nC\n INTEGER\n * I, J, K1, K2, IQ, IW\nC\nC ---------------------------------------------\nC CHECK FOR NULL INPUT AND PARTITION WORK ARRAY\nC ---------------------------------------------\nC\nC***FIRST EXECUTABLE STATEMENT\n IF (NF .LE. 0) GO TO 500\n K1 = K - 1\n K2 = K1 + K\n IQ = 1 + N\n IW = IQ + K2*N+1\nC\nC -----------------------------\nC COMPUTE B-SPLINE COEFFICIENTS\nC -----------------------------\nC\nC\nC FIRST DATA SET\nC\n CALL BINTK(X,FCN,T,N,K,WORK,WORK(IQ),WORK(IW))\n DO 20 I=1,N\n BCOEF(1,I) = WORK(I)\n 20 CONTINUE\nC\nC ALL REMAINING DATA SETS BY BACK-SUBSTITUTION\nC\n IF (NF .EQ. 1) GO TO 500\n DO 100 J=2,NF\n DO 50 I=1,N\n WORK(I) = FCN(I,J)\n 50 CONTINUE\n CALL BNSLV(WORK(IQ),K2,N,K1,K1,WORK)\n DO 60 I=1,N\n BCOEF(J,I) = WORK(I)\n 60 CONTINUE\n 100 CONTINUE\nC\nC ----\nC EXIT\nC ----\nC\n 500 CONTINUE\n RETURN\n END\n\n SUBROUTINE BINTK(X,Y,T,N,K,BCOEF,Q,WORK)\nC***BEGIN PROLOGUE BINTK\nC***DATE WRITTEN 800901 (YYMMDD)\nC***REVISION DATE 820801 (YYMMDD)\nC***REVISION HISTORY (YYMMDD)\nC 000330 Modified array declarations. (JEC)\nC\nC***CATEGORY NO. E1A\nC***KEYWORDS B-SPLINE,DATA FITTING,INTERPOLATION,SPLINE\nC***AUTHOR AMOS, D. E., (SNLA)\nC***PURPOSE Produces the B-spline coefficients, BCOEF, of the\nC B-spline of order K with knots T(I), I=1,...,N+K, which\nC takes on the value Y(I) at X(I), I=1,...,N.\nC***DESCRIPTION\nC\nC Written by Carl de Boor and modified by D. E. Amos\nC\nC References\nC\nC A Practical Guide to Splines by C. de Boor, Applied\nC Mathematics Series 27, Springer, 1979.\nC\nC Abstract\nC\nC BINTK is the SPLINT routine of the reference.\nC\nC BINTK produces the B-spline coefficients, BCOEF, of the\nC B-spline of order K with knots T(I), I=1,...,N+K, which\nC takes on the value Y(I) at X(I), I=1,...,N. The spline or\nC any of its derivatives can be evaluated by calls to BVALU.\nC The I-th equation of the linear system A*BCOEF = B for the\nC coefficients of the interpolant enforces interpolation at\nC X(I)), I=1,...,N. Hence, B(I) = Y(I), all I, and A is\nC a band matrix with 2K-1 bands if A is invertible. The matrix\nC A is generated row by row and stored, diagonal by diagonal,\nC in the rows of Q, with the main diagonal going into row K.\nC The banded system is then solved by a call to BNFAC (which\nC constructs the triangular factorization for A and stores it\nC again in Q), followed by a call to BNSLV (which then\nC obtains the solution BCOEF by substitution). BNFAC does no\nC pivoting, since the total positivity of the matrix A makes\nC this unnecessary. The linear system to be solved is\nC (theoretically) invertible if and only if\nC T(I) .LT. X(I)) .LT. T(I+K), all I.\nC Equality is permitted on the left for I=1 and on the right\nC for I=N when K knots are used at X(1) or X(N). Otherwise,\nC violation of this condition is certain to lead to an error.\nC\nC BINTK calls BSPVN, BNFAC, BNSLV, XERROR\nC\nC Description of Arguments\nC Input\nC X - vector of length N containing data point abscissa\nC in strictly increasing order.\nC Y - corresponding vector of length N containing data\nC point ordinates.\nC T - knot vector of length N+K\nC since T(1),..,T(K) .LE. X(1) and T(N+1),..,T(N+K)\nC .GE. X(N), this leaves only N-K knots (not nec-\nC essarily X(I)) values) interior to (X(1),X(N))\nC N - number of data points, N .GE. K\nC K - order of the spline, K .GE. 1\nC\nC Output\nC BCOEF - a vector of length N containing the B-spline\nC coefficients\nC Q - a work vector of length (2*K-1)*N, containing\nC the triangular factorization of the coefficient\nC matrix of the linear system being solved. The\nC coefficients for the interpolant of an\nC additional data set (X(I)),YY(I)), I=1,...,N\nC with the same abscissa can be obtained by loading\nC YY into BCOEF and then executing\nC call BNSLV(Q,2K-1,N,K-1,K-1,BCOEF)\nC WORK - work vector of length 2*K\nC\nC Error Conditions\nC Improper input is a fatal error\nC Singular system of equations is a fatal error\nC***REFERENCES D.E. AMOS, *COMPUTATION WITH SPLINES AND B-SPLINES*,\nC SAND78-1968,SANDIA LABORATORIES,MARCH,1979.\nC C. DE BOOR, *PACKAGE FOR CALCULATING WITH B-SPLINES*,\nC SIAM JOURNAL ON NUMERICAL ANALYSIS, VOLUME 14, NO. 3,\nC JUNE 1977, PP. 441-472.\nC C. DE BOOR, *A PRACTICAL GUIDE TO SPLINES*, APPLIED\nC MATHEMATICS SERIES 27, SPRINGER, 1979.\nC***ROUTINES CALLED BNFAC,BNSLV,BSPVN,XERROR\nC***END PROLOGUE BINTK\nC\nC\n INTEGER IFLAG, IWORK, K, N, I, ILP1MX, J, JJ, KM1, KPKM2, LEFT,\n 1 LENQ, NP1\n REAL BCOEF(N), Y(N), Q(*), T(*), X(N), XI, WORK(*)\nC DIMENSION Q(2*K-1,N), T(N+K)\nC***FIRST EXECUTABLE STATEMENT BINTK\n IF(K.LT.1) GO TO 100\n IF(N.LT.K) GO TO 105\n JJ = N - 1\n IF(JJ.EQ.0) GO TO 6\n DO 5 I=1,JJ\n IF(X(I).GE.X(I+1)) GO TO 110\n 5 CONTINUE\n 6 CONTINUE\n NP1 = N + 1\n KM1 = K - 1\n KPKM2 = 2*KM1\n LEFT = K\nC ZERO OUT ALL ENTRIES OF Q\n LENQ = N*(K+KM1)\n DO 10 I=1,LENQ\n Q(I) = 0.0E0\n 10 CONTINUE\nC\nC *** LOOP OVER I TO CONSTRUCT THE N INTERPOLATION EQUATIONS\n DO 50 I=1,N\n XI = X(I)\n ILP1MX = MIN0(I+K,NP1)\nC *** FIND LEFT IN THE CLOSED INTERVAL (I,I+K-1) SUCH THAT\nC T(LEFT) .LE. X(I) .LT. T(LEFT+1)\nC MATRIX IS SINGULAR IF THIS IS NOT POSSIBLE\n LEFT = MAX0(LEFT,I)\n IF (XI.LT.T(LEFT)) GO TO 80\n 20 IF (XI.LT.T(LEFT+1)) GO TO 30\n LEFT = LEFT + 1\n IF (LEFT.LT.ILP1MX) GO TO 20\n LEFT = LEFT - 1\n IF (XI.GT.T(LEFT+1)) GO TO 80\nC *** THE I-TH EQUATION ENFORCES INTERPOLATION AT XI, HENCE\nC A(I,J) = B(J,K,T)(XI), ALL J. ONLY THE K ENTRIES WITH J =\nC LEFT-K+1,...,LEFT ACTUALLY MIGHT BE NONZERO. THESE K NUMBERS\nC ARE RETURNED, IN BCOEF (USED FOR TEMP.STORAGE HERE), BY THE\nC FOLLOWING\n 30 CALL BSPVN(T, K, K, 1, XI, LEFT, BCOEF, WORK, IWORK)\nC WE THEREFORE WANT BCOEF(J) = B(LEFT-K+J)(XI) TO GO INTO\nC A(I,LEFT-K+J), I.E., INTO Q(I-(LEFT+J)+2*K,(LEFT+J)-K) SINCE\nC A(I+J,J) IS TO GO INTO Q(I+K,J), ALL I,J, IF WE CONSIDER Q\nC AS A TWO-DIM. ARRAY , WITH 2*K-1 ROWS (SEE COMMENTS IN\nC BNFAC). IN THE PRESENT PROGRAM, WE TREAT Q AS AN EQUIVALENT\nC ONE-DIMENSIONAL ARRAY (BECAUSE OF FORTRAN RESTRICTIONS ON\nC DIMENSION STATEMENTS) . WE THEREFORE WANT BCOEF(J) TO GO INTO\nC ENTRY\nC I -(LEFT+J) + 2*K + ((LEFT+J) - K-1)*(2*K-1)\nC = I-LEFT+1 + (LEFT -K)*(2*K-1) + (2*K-2)*J\nC OF Q .\n JJ = I - LEFT + 1 + (LEFT-K)*(K+KM1)\n DO 40 J=1,K\n JJ = JJ + KPKM2\n Q(JJ) = BCOEF(J)\n 40 CONTINUE\n 50 CONTINUE\nC\nC ***OBTAIN FACTORIZATION OF A , STORED AGAIN IN Q.\n CALL BNFAC(Q, K+KM1, N, KM1, KM1, IFLAG)\n GO TO (60, 90), IFLAG\nC *** SOLVE A*BCOEF = Y BY BACKSUBSTITUTION\n 60 DO 70 I=1,N\n BCOEF(I) = Y(I)\n 70 CONTINUE\n CALL BNSLV(Q, K+KM1, N, KM1, KM1, BCOEF)\n RETURN\nC\nC\n 80 CONTINUE\n CALL XERROR( 'BINTK, SOME ABSCISSA WAS NOT IN THE SUPPORT OF THE\n 1 CORRESPONDING BASIS FUNCTION AND THE SYSTEM IS SINGULAR.',108,2,1\n 2)\n RETURN\n 90 CONTINUE\n CALL XERROR( 'BINTK, THE SYSTEM OF SOLVER DETECTS A SINGULAR SYST\n 1EM ALTHOUGH THE THEORETICAL CONDITIONS FOR A SOLUTION WERE SATISFI\n 2ED.',121,8,1)\n RETURN\n 100 CONTINUE\n CALL XERROR( ' BINTK, K DOES NOT SATISFY K.GE.1', 34, 2, 1)\n RETURN\n 105 CONTINUE\n CALL XERROR( ' BINTK, N DOES NOT SATISFY N.GE.K', 34, 2, 1)\n RETURN\n 110 CONTINUE\n CALL XERROR( ' BINTK, X(I) DOES NOT SATISFY X(I).LT.X(I+1) FOR SO\n 1ME I', 56, 2, 1)\n RETURN\n END\n SUBROUTINE BNFAC(W,NROWW,NROW,NBANDL,NBANDU,IFLAG)\nC***BEGIN PROLOGUE BNFAC\nC***REFER TO BINT4,BINTK\nC\nC BNFAC is the BANFAC routine from\nC * A Practical Guide to Splines * by C. de Boor\nC\nC Returns in W the lu-factorization (without pivoting) of the banded\nC matrix A of order NROW with (NBANDL + 1 + NBANDU) bands or diag-\nC onals in the work array W .\nC\nC ***** I N P U T ******\nC W.....Work array of size (NROWW,NROW) containing the interesting\nC part of a banded matrix A , with the diagonals or bands of A\nC stored in the rows of W , while columns of A correspond to\nC columns of W . This is the storage mode used in LINPACK and\nC results in efficient innermost loops.\nC Explicitly, A has NBANDL bands below the diagonal\nC + 1 (main) diagonal\nC + NBANDU bands above the diagonal\nC and thus, with MIDDLE = NBANDU + 1,\nC A(I+J,J) is in W(I+MIDDLE,J) for I=-NBANDU,...,NBANDL\nC J=1,...,NROW .\nC For example, the interesting entries of A (1,2)-banded matrix\nC of order 9 would appear in the first 1+1+2 = 4 rows of W\nC as follows.\nC 13 24 35 46 57 68 79\nC 12 23 34 45 56 67 78 89\nC 11 22 33 44 55 66 77 88 99\nC 21 32 43 54 65 76 87 98\nC\nC All other entries of W not identified in this way with an en-\nC try of A are never referenced .\nC NROWW.....Row dimension of the work array W .\nC must be .GE. NBANDL + 1 + NBANDU .\nC NBANDL.....Number of bands of A below the main diagonal\nC NBANDU.....Number of bands of A above the main diagonal .\nC\nC ***** O U T P U T ******\nC IFLAG.....Integer indicating success( = 1) or failure ( = 2) .\nC If IFLAG = 1, then\nC W.....contains the LU-factorization of A into a unit lower triangu-\nC lar matrix L and an upper triangular matrix U (both banded)\nC and stored in customary fashion over the corresponding entries\nC of A . This makes it possible to solve any particular linear\nC system A*X = B for X by A\nC CALL BNSLV ( W, NROWW, NROW, NBANDL, NBANDU, B )\nC with the solution X contained in B on return .\nC If IFLAG = 2, then\nC one of NROW-1, NBANDL,NBANDU failed to be nonnegative, or else\nC one of the potential pivots was found to be zero indicating\nC that A does not have an LU-factorization. This implies that\nC A is singular in case it is totally positive .\nC\nC ***** M E T H O D ******\nC Gauss elimination W I T H O U T pivoting is used. The routine is\nC intended for use with matrices A which do not require row inter-\nC changes during factorization, especially for the T O T A L L Y\nC P O S I T I V E matrices which occur in spline calculations.\nC The routine should not be used for an arbitrary banded matrix.\nC***ROUTINES CALLED (NONE)\nC***END PROLOGUE BNFAC\nC\n INTEGER IFLAG, NBANDL, NBANDU, NROW, NROWW, I, IPK, J, JMAX, K,\n 1 KMAX, MIDDLE, MIDMK, NROWM1\n REAL W(NROWW,NROW), FACTOR, PIVOT\nC\nC***FIRST EXECUTABLE STATEMENT BNFAC\n IFLAG = 1\n MIDDLE = NBANDU + 1\nC W(MIDDLE,.) CONTAINS THE MAIN DIAGONAL OF A .\n NROWM1 = NROW - 1\n IF (NROWM1) 120, 110, 10\n 10 IF (NBANDL.GT.0) GO TO 30\nC A IS UPPER TRIANGULAR. CHECK THAT DIAGONAL IS NONZERO .\n DO 20 I=1,NROWM1\n IF (W(MIDDLE,I).EQ.0.0E0) GO TO 120\n 20 CONTINUE\n GO TO 110\n 30 IF (NBANDU.GT.0) GO TO 60\nC A IS LOWER TRIANGULAR. CHECK THAT DIAGONAL IS NONZERO AND\nC DIVIDE EACH COLUMN BY ITS DIAGONAL .\n DO 50 I=1,NROWM1\n PIVOT = W(MIDDLE,I)\n IF (PIVOT.EQ.0.0E0) GO TO 120\n JMAX = MIN0(NBANDL,NROW-I)\n DO 40 J=1,JMAX\n W(MIDDLE+J,I) = W(MIDDLE+J,I)/PIVOT\n 40 CONTINUE\n 50 CONTINUE\n RETURN\nC\nC A IS NOT JUST A TRIANGULAR MATRIX. CONSTRUCT LU FACTORIZATION\n 60 DO 100 I=1,NROWM1\nC W(MIDDLE,I) IS PIVOT FOR I-TH STEP .\n PIVOT = W(MIDDLE,I)\n IF (PIVOT.EQ.0.0E0) GO TO 120\nC JMAX IS THE NUMBER OF (NONZERO) ENTRIES IN COLUMN I\nC BELOW THE DIAGONAL .\n JMAX = MIN0(NBANDL,NROW-I)\nC DIVIDE EACH ENTRY IN COLUMN I BELOW DIAGONAL BY PIVOT .\n DO 70 J=1,JMAX\n W(MIDDLE+J,I) = W(MIDDLE+J,I)/PIVOT\n 70 CONTINUE\nC KMAX IS THE NUMBER OF (NONZERO) ENTRIES IN ROW I TO\nC THE RIGHT OF THE DIAGONAL .\n KMAX = MIN0(NBANDU,NROW-I)\nC SUBTRACT A(I,I+K)*(I-TH COLUMN) FROM (I+K)-TH COLUMN\nC (BELOW ROW I ) .\n DO 90 K=1,KMAX\n IPK = I + K\n MIDMK = MIDDLE - K\n FACTOR = W(MIDMK,IPK)\n DO 80 J=1,JMAX\n W(MIDMK+J,IPK) = W(MIDMK+J,IPK) - W(MIDDLE+J,I)*FACTOR\n 80 CONTINUE\n 90 CONTINUE\n 100 CONTINUE\nC CHECK THE LAST DIAGONAL ENTRY .\n 110 IF (W(MIDDLE,NROW).NE.0.0E0) RETURN\n 120 IFLAG = 2\n RETURN\n END\n SUBROUTINE BNSLV(W,NROWW,NROW,NBANDL,NBANDU,B)\nC***BEGIN PROLOGUE BNSLV\nC***REFER TO BINT4,BINTK\nC\nC BNSLV is the BANSLV routine from\nC * A Practical Guide to Splines * by C. de Boor\nC\nC Companion routine to BNFAC . It returns the solution X of the\nC linear system A*X = B in place of B , given the LU-factorization\nC for A in the work array W from BNFAC.\nC\nC ***** I N P U T ******\nC W, NROWW,NROW,NBANDL,NBANDU.....describe the LU-factorization of a\nC banded matrix A of order NROW as constructed in BNFAC .\nC For details, see BNFAC .\nC B.....Right side of the system to be solved .\nC\nC ***** O U T P U T ******\nC B.....Contains the solution X , of order NROW .\nC\nC ***** M E T H O D ******\nC (With A = L*U, as stored in W,) the unit lower triangular system\nC L(U*X) = B is solved for Y = U*X, and Y stored in B . Then the\nC upper triangular system U*X = Y is solved for X . The calcul-\nC ations are so arranged that the innermost loops stay within columns.\nC***ROUTINES CALLED (NONE)\nC***END PROLOGUE BNSLV\nC\n INTEGER NBANDL, NBANDU, NROW, NROWW, I, J, JMAX, MIDDLE, NROWM1\n REAL W(NROWW,NROW), B(NROW)\nC***FIRST EXECUTABLE STATEMENT BNSLV\n MIDDLE = NBANDU + 1\n IF (NROW.EQ.1) GO TO 80\n NROWM1 = NROW - 1\n IF (NBANDL.EQ.0) GO TO 30\nC FORWARD PASS\nC FOR I=1,2,...,NROW-1, SUBTRACT RIGHT SIDE(I)*(I-TH COLUMN\nC OF L ) FROM RIGHT SIDE (BELOW I-TH ROW) .\n DO 20 I=1,NROWM1\n JMAX = MIN0(NBANDL,NROW-I)\n DO 10 J=1,JMAX\n B(I+J) = B(I+J) - B(I)*W(MIDDLE+J,I)\n 10 CONTINUE\n 20 CONTINUE\nC BACKWARD PASS\nC FOR I=NROW,NROW-1,...,1, DIVIDE RIGHT SIDE(I) BY I-TH DIAG-\nC ONAL ENTRY OF U, THEN SUBTRACT RIGHT SIDE(I)*(I-TH COLUMN\nC OF U) FROM RIGHT SIDE (ABOVE I-TH ROW).\n 30 IF (NBANDU.GT.0) GO TO 50\nC A IS LOWER TRIANGULAR .\n DO 40 I=1,NROW\n B(I) = B(I)/W(1,I)\n 40 CONTINUE\n RETURN\n 50 I = NROW\n 60 B(I) = B(I)/W(MIDDLE,I)\n JMAX = MIN0(NBANDU,I-1)\n DO 70 J=1,JMAX\n B(I-J) = B(I-J) - B(I)*W(MIDDLE-J,I)\n 70 CONTINUE\n I = I - 1\n IF (I.GT.1) GO TO 60\n 80 B(1) = B(1)/W(MIDDLE,1)\n RETURN\n END\n SUBROUTINE BSPVN(T,JHIGH,K,INDEX,X,ILEFT,VNIKX,WORK,IWORK)\nC***BEGIN PROLOGUE BSPVN\nC***DATE WRITTEN 800901 (YYMMDD)\nC***REVISION DATE 820801 (YYMMDD)\nC***REVISION HISTORY (YYMMDD)\nC 000330 Modified array declarations. (JEC)\nC\nC***CATEGORY NO. E3,K6\nC***KEYWORDS B-SPLINE,DATA FITTING,INTERPOLATION,SPLINE\nC***AUTHOR AMOS, D. E., (SNLA)\nC***PURPOSE Calculates the value of all (possibly) nonzero basis\nC functions at X.\nC***DESCRIPTION\nC\nC Written by Carl de Boor and modified by D. E. Amos\nC\nC Reference\nC SIAM J. Numerical Analysis, 14, No. 3, June, 1977, pp.441-472.\nC\nC Abstract\nC BSPVN is the BSPLVN routine of the reference.\nC\nC BSPVN calculates the value of all (possibly) nonzero basis\nC functions at X of order MAX(JHIGH,(J+1)*(INDEX-1)), where\nC T(K) .LE. X .LE. T(N+1) and J=IWORK is set inside the routine\nC on the first call when INDEX=1. ILEFT is such that T(ILEFT)\nC .LE. X .LT. T(ILEFT+1). A call to INTRV(T,N+1,X,ILO,ILEFT,\nC MFLAG) produces the proper ILEFT. BSPVN calculates using the\nC basic algorithm needed in BSPVD. If only basis functions are\nC desired, setting JHIGH=K and INDEX=1 can be faster than\nC calling BSPVD, but extra coding is required for derivatives\nC (INDEX=2) and BSPVD is set up for this purpose.\nC\nC Left limiting values are set up as described in BSPVD.\nC\nC Description of Arguments\nC Input\nC T - knot vector of length N+K, where\nC N = number of B-spline basis functions\nC N = sum of knot multiplicities-K\nC JHIGH - order of B-spline, 1 .LE. JHIGH .LE. K\nC K - highest possible order\nC INDEX - INDEX = 1 gives basis functions of order JHIGH\nC = 2 denotes previous entry with WORK, IWORK\nC values saved for subsequent calls to\nC BSPVN.\nC X - argument of basis functions,\nC T(K) .LE. X .LE. T(N+1)\nC ILEFT - largest integer such that\nC T(ILEFT) .LE. X .LT. T(ILEFT+1)\nC\nC Output\nC VNIKX - vector of length K for spline values.\nC WORK - a work vector of length 2*K\nC IWORK - a work parameter. Both WORK and IWORK contain\nC information necessary to continue for INDEX = 2.\nC When INDEX = 1 exclusively, these are scratch\nC variables and can be used for other purposes.\nC\nC Error Conditions\nC Improper input is a fatal error.\nC***REFERENCES C. DE BOOR, *PACKAGE FOR CALCULATING WITH B-SPLINES*,\nC SIAM JOURNAL ON NUMERICAL ANALYSIS, VOLUME 14, NO. 3,\nC JUNE 1977, PP. 441-472.\nC***ROUTINES CALLED XERROR\nC***END PROLOGUE BSPVN\nC\nC\n INTEGER ILEFT, IMJP1, INDEX, IPJ, IWORK, JHIGH, JP1, JP1ML, K, L\n REAL T, VM, VMPREV, VNIKX, WORK, X\nC DIMENSION T(ILEFT+JHIGH)\n DIMENSION T(*), VNIKX(K), WORK(*)\nC CONTENT OF J, DELTAM, DELTAP IS EXPECTED UNCHANGED BETWEEN CALLS.\nC WORK(I) = DELTAP(I), WORK(K+I) = DELTAM(I), I = 1,K\nC***FIRST EXECUTABLE STATEMENT BSPVN\n IF(K.LT.1) GO TO 90\n IF(JHIGH.GT.K .OR. JHIGH.LT.1) GO TO 100\n IF(INDEX.LT.1 .OR. INDEX.GT.2) GO TO 105\n IF(X.LT.T(ILEFT) .OR. X.GT.T(ILEFT+1)) GO TO 110\n GO TO (10, 20), INDEX\n 10 IWORK = 1\n VNIKX(1) = 1.0E0\n IF (IWORK.GE.JHIGH) GO TO 40\nC\n 20 IPJ = ILEFT + IWORK\n WORK(IWORK) = T(IPJ) - X\n IMJP1 = ILEFT - IWORK + 1\n WORK(K+IWORK) = X - T(IMJP1)\n VMPREV = 0.0E0\n JP1 = IWORK + 1\n DO 30 L=1,IWORK\n JP1ML = JP1 - L\n VM = VNIKX(L)/(WORK(L)+WORK(K+JP1ML))\n VNIKX(L) = VM*WORK(L) + VMPREV\n VMPREV = VM*WORK(K+JP1ML)\n 30 CONTINUE\n VNIKX(JP1) = VMPREV\n IWORK = JP1\n IF (IWORK.LT.JHIGH) GO TO 20\nC\n 40 RETURN\nC\nC\n 90 CONTINUE\n CALL XERROR( ' BSPVN, K DOES NOT SATISFY K.GE.1', 34, 2, 1)\n RETURN\n 100 CONTINUE\n CALL XERROR( ' BSPVN, JHIGH DOES NOT SATISFY 1.LE.JHIGH.LE.K',\n 1 47, 2, 1)\n RETURN\n 105 CONTINUE\n CALL XERROR( ' BSPVN, INDEX IS NOT 1 OR 2',28,2,1)\n RETURN\n 110 CONTINUE\n CALL XERROR( ' BSPVN, X DOES NOT SATISFY T(ILEFT).LE.X.LE.T(ILEFT\n 1+1)', 55, 2, 1)\n RETURN\n END\n", "meta": {"hexsha": "5a350e04cb22791e0c33bbbc37dd0aa7fc2a3c7b", "size": 32476, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "fortran/b2ink.f", "max_stars_repo_name": "fsciortino/kn1d", "max_stars_repo_head_hexsha": "cac798c8642a7da85656c6751d9c4d8a48e3f99b", "max_stars_repo_licenses": ["MIT"], "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/b2ink.f", "max_issues_repo_name": "fsciortino/kn1d", "max_issues_repo_head_hexsha": "cac798c8642a7da85656c6751d9c4d8a48e3f99b", "max_issues_repo_licenses": ["MIT"], "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/b2ink.f", "max_forks_repo_name": "fsciortino/kn1d", "max_forks_repo_head_hexsha": "cac798c8642a7da85656c6751d9c4d8a48e3f99b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-12-01T19:24:22.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-03T12:33:14.000Z", "avg_line_length": 35.2616720955, "max_line_length": 72, "alphanum_fraction": 0.5632159133, "num_tokens": 11074, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425311777928, "lm_q2_score": 0.7549149868676284, "lm_q1q2_score": 0.694251929346996}} {"text": "\t\t\tmodule funcs\n\t\t\t implicit none\n\t\t\tcontains\n\t\t\t real function funcX(x)\n\t\t\t\treal, intent(in) :: x\n\t\t\t\tfuncX = x*x\n\t\t\t end function funcX\n\t\t\tend module funcs\n\n\t\t\tmodule mult\n\t\t\t use funcs\n\t\t\t contains\n\t\t\t SUBROUTINE trapzd(func, a, b, s, n)\n\t\t\t \t\t REAL func\n\t\t\t\t\t EXTERNAL func\n\t\t\t\t\t INTEGER n\n\t\t\t\t\t REAL a, b, s\n\t\t\t\t\t \n\t\t\t\t\t INTEGER it, j\n\t\t\t\t\t REAL del, sum, tnm, x\n\t\t\t\t\t \n\t\t\t\t\t if (n.eq.1) then\n\t\t\t\t\t\t\t\t\ts = 0.5*(b-a)*(func(a) + func(b))\n\t\t\t\t\t else\n\t\t\t\t\t\t\t\t\tit = 2**(n-2)\n\t\t\t\t\t\t\t\t\ttnm=it\n\t\t\t\t\t\t\t\t\tdel=(b-a)/tnm\n\t\t\t\t\t\t\t\t\tx=a+0.5*del\n\t\t\t\t\t\t\t\t\tsum = 0.\n\t\t\t\t\t\t\t\t\tdo j = 1, it\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tsum = sum + func(x)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tx = x + del\n\t\t\t\t\t\t\t\t\tend do\n\t\t\t\t\t\t\t\t\ts = 0.5*(s+(b-a)*sum/tnm)\n\t\t\t\t\t endif\n\t\t\t\t\t return\n\t\t\t END SUBROUTINE trapzd\n\n\t\t\t SUBROUTINE qsimp(a, b, s)\n\t\t\t\t\t INTEGER JMAX\n\t\t\t\t\t REAL a, b, s, EPS\n\t\t\t\t\t \n\t\t\t\t\t PARAMETER (EPS=1.e-6, JMAX=20)\n\n\t\t\t\t\t INTEGER j\n\t\t\t\t\t REAL os, ost, st\n\t\t\t\t\t ost=-1.e30\n\t\t\t\t\t os=-1.e30\n\t\t\t\t\t do j = 1, JMAX\n\t\t\t\t\t\t\t\tcall trapzd(funcX, a, b, st, j)\n\t\t\t\t\t\t\t\ts=(4.*st-ost)/3.\n\t\t\t\t\t\t\t\tjj: if (j.gt.5) then\n\t\t\t\t\t\t\t\t\tkk: if (abs(s-os).lt.EPS*abs(os)) then\n\t\t\t\t\t\t\t\t\t\t\t return\n\t\t\t\t\t\t\t\t\tend if kk\n\t\t\t\t\t\t\t\t\tmm: if (s.eq.0 .and. olds.eq.0) then\n\t\t\t\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\t\t\tend if mm\n\t\t\t\t\t\t\t\tend if jj\n\t\t\t\t\t\t\t\tos = s\n\t\t\t\t\t\t\t\tost = st\n\t\t\t\t\t end do\n\t\t\t END SUBROUTINE qsimp\n\t\t\tend module mult\n\n\t\t\tprogram funcargs\n\t\t\t !use funcs\n\t\t\t use mult\n\t\t\t implicit none\n\t\t\t real :: x\n\t\t\t real :: v, s\n\t\t\t x = 2\n\t\t\t v = 3\n\t\t\t call qsimp(x, v, s)\n\t\t\t write (*,*) s\n\t\t\tend program funcargs ", "meta": {"hexsha": "f63f46bbea95c464925d76c346084cf6f3bfd269", "size": 1542, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Raw-Src/new 2.f", "max_stars_repo_name": "tqbdev/Calculate-Integration-in-Fortran", "max_stars_repo_head_hexsha": "7bce95598a4cbd719e9f66c58622a3a24cfaa126", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Raw-Src/new 2.f", "max_issues_repo_name": "tqbdev/Calculate-Integration-in-Fortran", "max_issues_repo_head_hexsha": "7bce95598a4cbd719e9f66c58622a3a24cfaa126", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Raw-Src/new 2.f", "max_forks_repo_name": "tqbdev/Calculate-Integration-in-Fortran", "max_forks_repo_head_hexsha": "7bce95598a4cbd719e9f66c58622a3a24cfaa126", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.2894736842, "max_line_length": 47, "alphanum_fraction": 0.4481193256, "num_tokens": 523, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425245706047, "lm_q2_score": 0.7549149758396752, "lm_q1q2_score": 0.6942519142173559}} {"text": " real function crit(z,q)\nc\nc + + + PURPOSE + + +\nc\nc Function CRIT computes the critical flow depth.\nc\nc Called from: SRS FRICHN, FSLPAR\nc Author(s): Ascough II, R. van der Zweep, V. Lopes\nc Reference in User Guide:\nc\nc Version:\nc Date recoded:\nc Recoded by: Jim Ascough II\nc\nc + + + KEYWORDS + + +\nc\nc + + + PARAMETERS + + +\nc\nc + + + ARGUMENT DECLARATIONS + + +\nc\n real z, q\nc\nc + + + ARGUMENT DEFINITIONS + + +\nc\nc z -\nc q -\nc\nc + + + COMMON BLOCKS + + +\nc\n include 'cchcon.inc'\nc\nc + + + LOCAL VARIABLES + + +\nc\nc + + + LOCAL DEFINITIONS + + +\nc\nc + + + SAVES + + +\nc\nc + + + SUBROUTINES CALLED + + +\nc\nc + + + DATA INITIALIZATIONS + + +\nc\nc + + + END SPECIFICATIONS + + +\nc\nc\n crit = (2.0*beta*q**2/(agrav*z**2)) ** 0.2\nc\n return\n end\n", "meta": {"hexsha": "7f222b57839e6a93f087d425c3945af6c7ae363c", "size": 854, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/wepp2012-src/crit.for", "max_stars_repo_name": "jarad/dep", "max_stars_repo_head_hexsha": "fe73982f4c70039e1a31b9e8e2d9aac31502f803", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-11-26T17:49:19.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-26T17:49:19.000Z", "max_issues_repo_path": "src/wepp2012-src/crit.for", "max_issues_repo_name": "jarad/dep", "max_issues_repo_head_hexsha": "fe73982f4c70039e1a31b9e8e2d9aac31502f803", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 54, "max_issues_repo_issues_event_min_datetime": "2018-12-12T18:02:31.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T19:14:25.000Z", "max_forks_repo_path": "src/wepp2012-src/crit.for", "max_forks_repo_name": "akrherz/idep", "max_forks_repo_head_hexsha": "7189a26fbcec3d8c3cc7d7015107b8fb6c5f6a45", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-03-02T22:59:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-09T15:49:00.000Z", "avg_line_length": 17.4285714286, "max_line_length": 55, "alphanum_fraction": 0.5105386417, "num_tokens": 309, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582593509315, "lm_q2_score": 0.7461389986757758, "lm_q1q2_score": 0.6942511939417094}} {"text": "module derivative_stencil_module\n\n use iso_c_binding\n\n implicit none\n\n public\n\n integer, parameter :: stencil_ng = 4\n\n ! for 8th-order first derivatives\n double precision,dimension(4),parameter :: D8 = (/ 0.8d0, -0.2d0, 4.d0/105.d0, -1.d0/280.d0 /)\n\n ! coefficients for 8th-order stencil of second derivatives\n ! d(a*du/dx)/dx = H_{i+1/2} - H_{i-1/2},\n ! where H = a.M.u\n !\n double precision, save, dimension(8,8) :: M8, M8T\n !\n ! optimized for more zeros\n ! double precision, private, parameter :: M8_47 = 683.d0/10080.d0, M8_48 = -1.d0/224.d0\n !\n ! optimized for leading order truncation error assuming equal weight for the error terms\n double precision, private, parameter :: M8_47 = 3557.d0/44100.d0, M8_48 = -2083.d0/117600.d0\n\ncontains\n \n subroutine derivative_stencil_init () bind(c, name='derivative_stencil_init')\n\n ! 8th-order\n M8(1,1) = 5.d0/336.d0 + M8_48\n M8(2,1) = -11.d0/560.d0 - 2.d0*M8_48\n M8(3,1) = -1.d0/280.d0\n M8(4,1) = 17.d0/1680.d0 + 2.d0*M8_48\n M8(5,1) = -M8_48\n M8(6,1) = 0.d0\n M8(7,1) = 0.d0\n M8(8,1) = 0.d0\n\n M8(1,2) = -83.d0/3600.d0 - M8_47/5.d0 - 14.d0*M8_48/5.d0\n M8(2,2) = -31.d0/360.d0 + M8_47 + 3.d0*M8_48\n M8(3,2) = 1097.d0/5040.d0 - 2.d0*M8_47 + 6.d0*M8_48\n M8(4,2) = -319.d0/2520.d0 + 2.d0*M8_47 - 8.d0*M8_48\n M8(5,2) = -M8_47\n M8(6,2) = -139.d0/25200.d0 + M8_47/5.d0 + 9.d0*M8_48/5.d0\n M8(7,2) = 0.d0\n M8(8,2) = 0.d0\n\n M8(1,3) = 299.d0/50400.d0 + 2.d0*M8_47/5.d0 + 13.d0*M8_48/5.d0\n M8(2,3) = 41.d0/200.d0 - 9.d0*M8_47/5.d0 + 4.d0*M8_48/5.d0\n M8(3,3) = -1349.d0/10080.d0 + 3.d0*M8_47 - 12.d0*M8_48\n M8(4,3) = -919.d0/5040.d0 - 2.d0*M8_47 + 6.d0*M8_48\n M8(5,3) = 65.d0/224.d0 + 7.d0*M8_48\n M8(6,3) = -467.d0/25200.d0 + 3.d0*M8_47/5.d0 - 18.d0*M8_48/5.d0\n M8(7,3) = 503.d0/50400.d0 - M8_47/5.d0 - 4.d0*M8_48/5.d0\n M8(8,3) = 0.d0\n\n M8(1,4) = 17.d0/12600.d0 - M8_47/5.d0 - 4.d0*M8_48/5.d0\n M8(2,4) = -5927.d0/50400.d0 + 4.d0*M8_47/5.d0 - 9.d0*M8_48/5.d0\n M8(3,4) = -887.d0/5040.d0 - M8_47 + 6.d0*M8_48\n M8(4,4) = -445.d0/2016.d0\n M8(5,4) = -583.d0/720.d0 + M8_47 - 6.d0*M8_48\n M8(6,4) = -3613.d0/50400.d0 - 4.d0*M8_47/5.d0 + 9.d0*M8_48/5.d0\n M8(7,4) = -17.d0/600.d0 + M8_47/5.d0 + 4.d0*M8_48/5.d0\n M8(8,4) = -1.d0/1120.d0\n\n M8(1,5) = -M8(8,4)\n M8(2,5) = -M8(7,4)\n M8(3,5) = -M8(6,4)\n M8(4,5) = -M8(5,4)\n M8(5,5) = -M8(4,4)\n M8(6,5) = -M8(3,4)\n M8(7,5) = -M8(2,4)\n M8(8,5) = -M8(1,4)\n\n M8(1,6) = 0.d0\n M8(2,6) = -M8(7,3)\n M8(3,6) = -M8(6,3)\n M8(4,6) = -M8(5,3)\n M8(5,6) = -M8(4,3)\n M8(6,6) = -M8(3,3)\n M8(7,6) = -M8(2,3)\n M8(8,6) = -M8(1,3)\n\n M8(1,7) = 0.d0\n M8(2,7) = 0.d0\n M8(3,7) = -M8(6,2)\n M8(4,7) = -M8(5,2)\n M8(5,7) = -M8(4,2)\n M8(6,7) = -M8(3,2)\n M8(7,7) = -M8(2,2)\n M8(8,7) = -M8(1,2)\n\n M8(1,8) = 0.d0\n M8(2,8) = 0.d0\n M8(3,8) = 0.d0\n M8(4,8) = -M8(5,1)\n M8(5,8) = -M8(4,1)\n M8(6,8) = -M8(3,1)\n M8(7,8) = -M8(2,1)\n M8(8,8) = -M8(1,1)\n\n M8T = transpose(M8)\n \n end subroutine derivative_stencil_init\n\n function get_num_ghost_cells () result(r) bind(c, name='get_num_ghost_cells')\n integer :: r\n r = stencil_ng\n end function get_num_ghost_cells\n\nend module derivative_stencil_module\n", "meta": {"hexsha": "45060ab20dbe4dcce0af0e6fe2e0f83beb8b9da1", "size": 3251, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Src/AmrTask/tutorials/MiniApps/SMC_fixed_dt/derivative_stencil.f90", "max_stars_repo_name": "ylunalin/amrex", "max_stars_repo_head_hexsha": "5715b2fc8a77e0db17bfe7907982e29ec44811ca", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 79, "max_stars_repo_stars_event_min_datetime": "2015-08-03T18:29:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-15T11:42:40.000Z", "max_issues_repo_path": "Src/AmrTask/tutorials/MiniApps/SMC_fixed_dt/derivative_stencil.f90", "max_issues_repo_name": "ylunalin/amrex", "max_issues_repo_head_hexsha": "5715b2fc8a77e0db17bfe7907982e29ec44811ca", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": 22, "max_issues_repo_issues_event_min_datetime": "2016-06-15T20:46:49.000Z", "max_issues_repo_issues_event_max_datetime": "2018-09-10T21:33:10.000Z", "max_forks_repo_path": "Src/AmrTask/tutorials/MiniApps/SMC_fixed_dt/derivative_stencil.f90", "max_forks_repo_name": "ylunalin/amrex", "max_forks_repo_head_hexsha": "5715b2fc8a77e0db17bfe7907982e29ec44811ca", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": 48, "max_forks_repo_forks_event_min_datetime": "2015-08-05T02:19:33.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-18T12:33:14.000Z", "avg_line_length": 28.7699115044, "max_line_length": 96, "alphanum_fraction": 0.5509074131, "num_tokens": 1835, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582516374121, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6942511881863517}} {"text": " SUBROUTINE sla_GEOC (P, H, R, Z)\n*+\n* - - - - -\n* G E O C\n* - - - - -\n*\n* Convert geodetic position to geocentric (double precision)\n*\n* Given:\n* P dp latitude (geodetic, radians)\n* H dp height above reference spheroid (geodetic, metres)\n*\n* Returned:\n* R dp distance from Earth axis (AU)\n* Z dp distance from plane of Earth equator (AU)\n*\n* Notes:\n* 1) Geocentric latitude can be obtained by evaluating ATAN2(Z,R).\n* 2) IAU 1976 constants are used.\n*\n* Reference:\n* Green,R.M., Spherical Astronomy, CUP 1985, p98.\n*\n* P.T.Wallace Starlink 4th October 1989\n*\n* Copyright (C) 1995 Rutherford Appleton Laboratory\n*\n* License:\n* This program is free software; you can redistribute it and/or modify\n* it under the terms of the GNU General Public License as published by\n* the Free Software Foundation; either version 2 of the License, or\n* (at your option) any later version.\n*\n* This program is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU General Public License for more details.\n*\n* You should have received a copy of the GNU General Public License\n* along with this program (see SLA_CONDITIONS); if not, write to the \n* Free Software Foundation, Inc., 59 Temple Place, Suite 330, \n* Boston, MA 02111-1307 USA\n*\n*-\n\n IMPLICIT NONE\n\n DOUBLE PRECISION P,H,R,Z\n\n* Earth equatorial radius (metres)\n DOUBLE PRECISION A0\n PARAMETER (A0=6378140D0)\n\n* Reference spheroid flattening factor and useful function\n DOUBLE PRECISION F,B\n PARAMETER (F=1D0/298.257D0,B=(1D0-F)**2)\n\n* Astronomical unit in metres\n DOUBLE PRECISION AU\n PARAMETER (AU=1.49597870D11)\n\n DOUBLE PRECISION SP,CP,C,S\n\n\n\n* Geodetic to geocentric conversion\n SP=SIN(P)\n CP=COS(P)\n C=1D0/SQRT(CP*CP+B*SP*SP)\n S=B*C\n R=(A0*C+H)*CP/AU\n Z=(A0*S+H)*SP/AU\n\n END\n", "meta": {"hexsha": "c3ebf9c6486b1d6ec47d992ac5fb7b9f4aa7e154", "size": 2065, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Util/third/star/geoc.f", "max_stars_repo_name": "rwharton/psrchive_dsn", "max_stars_repo_head_hexsha": "9584862167154fa48db89b86151c4221ad4bb96b", "max_stars_repo_licenses": ["AFL-2.1"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Util/third/star/geoc.f", "max_issues_repo_name": "rwharton/psrchive_dsn", "max_issues_repo_head_hexsha": "9584862167154fa48db89b86151c4221ad4bb96b", "max_issues_repo_licenses": ["AFL-2.1"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Util/third/star/geoc.f", "max_forks_repo_name": "rwharton/psrchive_dsn", "max_forks_repo_head_hexsha": "9584862167154fa48db89b86151c4221ad4bb96b", "max_forks_repo_licenses": ["AFL-2.1"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-02-13T20:08:14.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-13T20:08:14.000Z", "avg_line_length": 27.5333333333, "max_line_length": 73, "alphanum_fraction": 0.6479418886, "num_tokens": 623, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582574225517, "lm_q2_score": 0.7461389930307512, "lm_q1q2_score": 0.6942511872504101}} {"text": " SUBROUTINE POLATEV3(IPOPT,IGDTNUMI,IGDTMPLI,IGDTLENI, &\n IGDTNUMO,IGDTMPLO,IGDTLENO, &\n MI,MO,KM,IBI,LI,UI,VI, &\n NO,RLAT,RLON,CROT,SROT,IBO,LO,UO,VO,IRET)\n!$$$ SUBPROGRAM DOCUMENTATION BLOCK\n!\n! $Revision: 74685 $\n!\n! SUBPROGRAM: POLATEV3 INTERPOLATE VECTOR FIELDS (BUDGET)\n! PRGMMR: IREDELL ORG: W/NMC23 DATE: 96-04-10\n!\n! ABSTRACT: THIS SUBPROGRAM PERFORMS BUDGET INTERPOLATION\n! FROM ANY GRID TO ANY GRID FOR VECTOR FIELDS.\n! THE ALGORITHM SIMPLY COMPUTES (WEIGHTED) AVERAGES\n! OF BILINEARLY INTERPOLATED POINTS ARRANGED IN A SQUARE BOX\n! CENTERED AROUND EACH OUTPUT GRID POINT AND STRETCHING\n! NEARLY HALFWAY TO EACH OF THE NEIGHBORING GRID POINTS.\n! OPTIONS ALLOW CHOICES OF NUMBER OF POINTS IN EACH RADIUS\n! FROM THE CENTER POINT (IPOPT(1)) WHICH DEFAULTS TO 2\n! (IF IPOPT(1)=-1) MEANING THAT 25 POINTS WILL BE AVERAGED;\n! FURTHER OPTIONS ARE THE RESPECTIVE WEIGHTS FOR THE RADIUS\n! POINTS STARTING AT THE CENTER POINT (IPOPT(2:2+IPOPT(1))\n! WHICH DEFAULTS TO ALL 1 (IF IPOPT(1)=-1 OR IPOPT(2)=-1).\n! A SPECIAL INTERPOLATION IS DONE IF IPOPT(2)=-2.\n! IN THIS CASE, THE BOXES STRETCH NEARLY ALL THE WAY TO\n! EACH OF THE NEIGHBORING GRID POINTS AND THE WEIGHTS\n! ARE THE ADJOINT OF THE BILINEAR INTERPOLATION WEIGHTS.\n! THIS CASE GIVES QUASI-SECOND-ORDER BUDGET INTERPOLATION.\n! ANOTHER OPTION IS THE MINIMUM PERCENTAGE FOR MASK,\n! I.E. PERCENT VALID INPUT DATA REQUIRED TO MAKE OUTPUT DATA,\n! (IPOPT(3+IPOPT(1)) WHICH DEFAULTS TO 50 (IF -1).\n! ONLY HORIZONTAL INTERPOLATION IS PERFORMED.\n!\n! THE INPUT AND OUTPUT GRIDS ARE DEFINED BY THEIR GRIB 2 GRID\n! DEFINITION TEMPLATE AS DECODED BY THE NCEP G2 LIBRARY. THE\n! CODE RECOGNIZES THE FOLLOWING PROJECTIONS, WHERE\n! \"IGDTNUMI/O\" IS THE GRIB 2 GRID DEFINTION TEMPLATE NUMBER\n! FOR THE INPUT AND OUTPUT GRIDS, RESPECTIVELY:\n! (IGDTNUMI/O=00) EQUIDISTANT CYLINDRICAL\n! (IGDTNUMI/O=01) ROTATED EQUIDISTANT CYLINDRICAL. \"E\" AND\n! NON-\"E\" STAGGERED\n! (IGDTNUMI/O=10) MERCATOR CYLINDRICAL\n! (IGDTNUMI/O=20) POLAR STEREOGRAPHIC AZIMUTHAL\n! (IGDTNUMI/O=30) LAMBERT CONFORMAL CONICAL\n! (IGDTNUMI/O=40) GAUSSIAN CYLINDRICAL\n!\n! THE INPUT AND OUTPUT VECTORS ARE ROTATED SO THAT THEY ARE\n! EITHER RESOLVED RELATIVE TO THE DEFINED GRID\n! IN THE DIRECTION OF INCREASING X AND Y COORDINATES\n! OR RESOLVED RELATIVE TO EASTERLY AND NORTHERLY DIRECTIONS,\n! AS DESIGNATED BY THEIR RESPECTIVE GRID DESCRIPTION SECTIONS.\n!\n! AS AN ADDED BONUS THE NUMBER OF OUTPUT GRID POINTS AND\n! THEIR LATITUDES AND LONGITUDES ARE ALSO RETURNED\n! ALONG WITH THEIR VECTOR ROTATION PARAMETERS. ON THE OTHER\n! THE OUTPUT CAN BE A SET OF STATION POINTS IF\n! IGDTNUMO=IGDTNUMO-255, IN WHICH CASE THE NUMBER OF POINTS\n! AND THEIR LATITUDES AND LONGITUDES MUST BE INPUT.\n!\n! INPUT BITMAPS WILL BE INTERPOLATED TO OUTPUT BITMAPS.\n! OUTPUT BITMAPS WILL ALSO BE CREATED WHEN THE OUTPUT GRID\n! EXTENDS OUTSIDE OF THE DOMAIN OF THE INPUT GRID.\n! THE OUTPUT FIELD IS SET TO 0 WHERE THE OUTPUT BITMAP IS OFF.\n! \n! PROGRAM HISTORY LOG:\n! 96-04-10 IREDELL\n! 1999-04-08 IREDELL SPLIT IJKGDS INTO TWO PIECES\n! 1999-04-08 IREDELL ADDED BILINEAR OPTION IPOPT(2)=-2\n! 2001-06-18 IREDELL INCLUDE MINIMUM MASK PERCENTAGE OPTION\n! 2002-01-17 IREDELL SAVE DATA FROM LAST CALL FOR OPTIMIZATION\n! 2006-01-05 GAYNO ADDED OPTION TO TO DO SUBSECTION OF OUTPUT GRID.\n! 2015-01-27 GAYNO REPLACE CALLS TO GDSWIZ WITH NEW MERGED\n! ROUTINE GDSWZD.\n! 2015-07-13 GAYNO CONVERT TO GRIB 2. REPLACE GRIB 1 KGDS ARRAYS\n! WITH GRIB 2 GRID DEFINITION TEMPLATE ARRAYS.\n!\n! USAGE: CALL POLATEV3(IPOPT,IGDTNUMI,IGDTMPLI,IGDTLENI, &\n! IGDTNUMO,IGDTMPLO,IGDTLENO, &\n! MI,MO,KM,IBI,LI,UI,VI, &\n! NO,RLAT,RLON,CROT,SROT,IBO,LO,UO,VO,IRET)\n!\n! INPUT ARGUMENT LIST:\n! IPOPT - INTEGER (20) INTERPOLATION OPTIONS\n! IPOPT(1) IS NUMBER OF RADIUS POINTS\n! (DEFAULTS TO 2 IF IPOPT(1)=-1);\n! IPOPT(2:2+IPOPT(1)) ARE RESPECTIVE WEIGHTS\n! (DEFAULTS TO ALL 1 IF IPOPT(1)=-1 OR IPOPT(2)=-1).\n! IPOPT(3+IPOPT(1)) IS MINIMUM PERCENTAGE FOR MASK\n! (DEFAULTS TO 50 IF IPOPT(3+IPOPT(1)=-1)\n! IGDTNUMI - INTEGER GRID DEFINITION TEMPLATE NUMBER - INPUT GRID.\n! CORRESPONDS TO THE GFLD%IGDTNUM COMPONENT OF THE\n! NCEP G2 LIBRARY GRIDMOD DATA STRUCTURE:\n! 00 - EQUIDISTANT CYLINDRICAL\n! 01 - ROTATED EQUIDISTANT CYLINDRICAL. \"E\"\n! AND NON-\"E\" STAGGERED\n! 10 - MERCATOR CYCLINDRICAL\n! 20 - POLAR STEREOGRAPHIC AZIMUTHAL\n! 30 - LAMBERT CONFORMAL CONICAL\n! 40 - GAUSSIAN EQUIDISTANT CYCLINDRICAL\n! IGDTMPLI - INTEGER (IGDTLENI) GRID DEFINITION TEMPLATE ARRAY -\n! INPUT GRID. CORRESPONDS TO THE GFLD%IGDTMPL COMPONENT\n! OF THE NCEP G2 LIBRARY GRIDMOD DATA STRUCTURE.\n! (SECTION 3 INFO). SEE COMMENTS IN ROUTINE\n! IPOLATEV FOR COMPLETE DEFINITION.\n! IGDTLENI - INTEGER NUMBER OF ELEMENTS OF THE GRID DEFINITION\n! TEMPLATE ARRAY - INPUT GRID. CORRESPONDS TO THE GFLD%IGDTLEN\n! COMPONENT OF THE NCEP G2 LIBRARY GRIDMOD DATA STRUCTURE.\n! IGDTNUMO - INTEGER GRID DEFINITION TEMPLATE NUMBER - OUTPUT GRID.\n! CORRESPONDS TO THE GFLD%IGDTNUM COMPONENT OF THE\n! NCEP G2 LIBRARY GRIDMOD DATA STRUCTURE. IGDTNUMO=IGDTNUM-255\n! MEANS INTERPOLATE TO RANDOM STATION POINTS.\n! OTHERWISE, SAME DEFINITION AS \"IGDTNUMI\".\n! IGDTMPLO - INTEGER (IGDTLENO) GRID DEFINITION TEMPLATE ARRAY -\n! OUTPUT GRID. CORRESPONDS TO THE GFLD%IGDTMPL COMPONENT\n! OF THE NCEP G2 LIBRARY GRIDMOD DATA STRUCTURE.\n! (SECTION 3 INFO). SEE COMMENTS IN ROUTINE\n! IPOLATEV FOR COMPLETE DEFINITION.\n! IGDTLENO - INTEGER NUMBER OF ELEMENTS OF THE GRID DEFINITION\n! TEMPLATE ARRAY - OUTPUT GRID. CORRESPONDS TO THE GFLD%IGDTLEN\n! COMPONENT OF THE NCEP G2 LIBRARY GRIDMOD DATA STRUCTURE.\n! MI - INTEGER SKIP NUMBER BETWEEN INPUT GRID FIELDS IF KM>1\n! OR DIMENSION OF INPUT GRID FIELDS IF KM=1\n! MO - INTEGER SKIP NUMBER BETWEEN OUTPUT GRID FIELDS IF KM>1\n! OR DIMENSION OF OUTPUT GRID FIELDS IF KM=1\n! KM - INTEGER NUMBER OF FIELDS TO INTERPOLATE\n! IBI - INTEGER (KM) INPUT BITMAP FLAGS\n! LI - LOGICAL*1 (MI,KM) INPUT BITMAPS (IF SOME IBI(K)=1)\n! UI - REAL (MI,KM) INPUT U-COMPONENT FIELDS TO INTERPOLATE\n! VI - REAL (MI,KM) INPUT V-COMPONENT FIELDS TO INTERPOLATE\n! RLAT - REAL (MO) INPUT LATITUDES IN DEGREES (IGDTNUMO<0)\n! RLON - REAL (MO) INPUT LONGITUDES IN DEGREES (IGDTNUMO<0)\n!\n! OUTPUT ARGUMENT LIST:\n! NO - INTEGER NUMBER OF OUTPUT POINTS\n! RLAT - REAL (MO) OUTPUT LATITUDES IN DEGREES (IGDTNUMO>=0)\n! RLON - REAL (MO) OUTPUT LONGITUDES IN DEGREES (IGDTNUMO>=0)\n! CROT - REAL (MO) VECTOR ROTATION COSINES\n! SROT - REAL (MO) VECTOR ROTATION SINES\n! (UGRID=CROT*UEARTH-SROT*VEARTH;\n! VGRID=SROT*UEARTH+CROT*VEARTH)\n! IBO - INTEGER (KM) OUTPUT BITMAP FLAGS\n! LO - LOGICAL*1 (MO,KM) OUTPUT BITMAPS (ALWAYS OUTPUT)\n! UO - REAL (MO,KM) OUTPUT U-COMPONENT FIELDS INTERPOLATED\n! VO - REAL (MO,KM) OUTPUT V-COMPONENT FIELDS INTERPOLATED\n! IRET - INTEGER RETURN CODE\n! 0 SUCCESSFUL INTERPOLATION\n! 2 UNRECOGNIZED INPUT GRID OR NO GRID OVERLAP\n! 3 UNRECOGNIZED OUTPUT GRID\n! 32 INVALID BUDGET METHOD PARAMETERS\n!\n! SUBPROGRAMS CALLED:\n! CHECK_GRIDS3V CHECK IF GRID SPECS HAVE CHANGED\n! GDSWZD GRID DESCRIPTION SECTION WIZARD\n! IJKGDS0 SET UP PARAMETERS FOR IJKGDS1\n! IJKGDS1 RETURN FIELD POSITION FOR A GIVEN GRID POINT\n! MOVECT MOVE A VECTOR ALONG A GREAT CIRCLE\n! POLFIXV MAKE MULTIPLE POLE VECTOR VALUES CONSISTENT\n!\n! ATTRIBUTES:\n! LANGUAGE: FORTRAN 90\n!\n!$$$\n!\n USE GDSWZD_MOD\n!\n IMPLICIT NONE\n!\n INTEGER, INTENT(IN ) :: IPOPT(20), IBI(KM)\n INTEGER, INTENT(IN ) :: KM, MI, MO\n INTEGER, INTENT(IN ) :: IGDTNUMI, IGDTLENI\n INTEGER, INTENT(IN ) :: IGDTMPLI(IGDTLENI)\n INTEGER, INTENT(IN ) :: IGDTNUMO, IGDTLENO\n INTEGER, INTENT(IN ) :: IGDTMPLO(IGDTLENO)\n INTEGER, INTENT( OUT) :: IRET, NO, IBO(KM)\n!\n LOGICAL*1, INTENT(IN ) :: LI(MI,KM)\n LOGICAL*1, INTENT( OUT) :: LO(MO,KM)\n!\n REAL, INTENT(IN ) :: UI(MI,KM),VI(MI,KM)\n REAL, INTENT(INOUT) :: RLAT(MO),RLON(MO)\n REAL, INTENT( OUT) :: UO(MO,KM),VO(MO,KM)\n REAL, INTENT( OUT) :: CROT(MO),SROT(MO)\n!\n REAL, PARAMETER :: FILL=-9999.\n!\n INTEGER :: IGDTNUMO2, IJKGDS1, IJKGDSA(20)\n INTEGER :: I1,I2,J1,J2,IB,JB,LSW,MP\n INTEGER, SAVE :: MIX=-1\n INTEGER :: K,LB,N,NB,NB1,NB2,NB3,NB4,NV\n INTEGER :: N11(MO),N21(MO),N12(MO),N22(MO)\n!\n LOGICAL :: SAME_GRID\n!\n REAL :: CM11,SM11,CM12,SM12\n REAL :: CM21,SM21,CM22,SM22\n REAL :: PMP,RB2\n REAL :: C11(MO),C21(MO),C12(MO),C22(MO)\n REAL :: S11(MO),S21(MO),S12(MO),S22(MO)\n REAL :: W11(MO),W21(MO),W12(MO),W22(MO)\n REAL :: UB,VB,WB,UROT,VROT\n REAL :: U11,V11,U21,V21,U12,V12,U22,V22\n REAL :: WI1,WJ1,WI2,WJ2\n REAL :: WO(MO,KM),XI,YI\n REAL :: XPTS(MO),YPTS(MO)\n REAL :: XPTB(MO),YPTB(MO),RLOB(MO),RLAB(MO)\n REAL, ALLOCATABLE, SAVE :: CROI(:),SROI(:)\n REAL, ALLOCATABLE, SAVE :: XPTI(:),YPTI(:),RLOI(:),RLAI(:)\n!\n! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n! COMPUTE NUMBER OF OUTPUT POINTS AND THEIR LATITUDES AND LONGITUDES.\n IRET=0\n IF(IGDTNUMO.GE.0) THEN\n CALL GDSWZD(IGDTNUMO,IGDTMPLO,IGDTLENO, 0,MO,FILL,XPTS,YPTS, &\n RLON,RLAT,NO,CROT,SROT)\n IF(NO.EQ.0) IRET=3\n ELSE\n IGDTNUMO2=255+IGDTNUMO\n CALL GDSWZD(IGDTNUMO2,IGDTMPLO,IGDTLENO,-1,MO,FILL,XPTS,YPTS, &\n RLON,RLAT,NO,CROT,SROT)\n IF(NO.EQ.0) IRET=3\n ENDIF\n CALL CHECK_GRIDS3V(IGDTNUMI,IGDTMPLI,IGDTLENI,SAME_GRID)\n IF(.NOT.SAME_GRID) THEN\n IF(MIX.NE.MI) THEN\n IF(MIX.GE.0) DEALLOCATE(XPTI,YPTI,RLOI,RLAI,CROI,SROI)\n ALLOCATE(XPTI(MI),YPTI(MI),RLOI(MI),RLAI(MI),CROI(MI),SROI(MI))\n MIX=MI\n ENDIF\n CALL GDSWZD(IGDTNUMI,IGDTMPLI,IGDTLENI, 0,MI,FILL,XPTI,YPTI, &\n RLOI,RLAI,NV,CROI,SROI)\n ENDIF\n! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n! SET PARAMETERS\n NB1=IPOPT(1)\n IF(NB1.EQ.-1) NB1=2\n IF(IRET.EQ.0.AND.NB1.LT.0) IRET=32\n LSW=1\n IF(IPOPT(2).EQ.-2) LSW=2\n IF(IPOPT(1).EQ.-1.OR.IPOPT(2).EQ.-1) LSW=0\n IF(IRET.EQ.0.AND.LSW.EQ.1.AND.NB1.GT.15) IRET=32\n MP=IPOPT(3+IPOPT(1))\n IF(MP.EQ.-1.OR.MP.EQ.0) MP=50\n IF(MP.LT.0.OR.MP.GT.100) IRET=32\n PMP=MP*0.01\n IF(IRET.EQ.0) THEN\n NB2=2*NB1+1\n RB2=1./NB2\n NB3=NB2*NB2\n NB4=NB3\n IF(LSW.EQ.2) THEN\n RB2=1./(NB1+1)\n NB4=(NB1+1)**4\n ELSEIF(LSW.EQ.1) THEN\n NB4=IPOPT(2)\n DO IB=1,NB1\n NB4=NB4+8*IB*IPOPT(2+IB)\n ENDDO\n ENDIF\n ELSE\n NB3=0\n NB4=1\n ENDIF\n DO K=1,KM\n DO N=1,NO\n UO(N,K)=0\n VO(N,K)=0\n WO(N,K)=0.\n ENDDO\n ENDDO\n! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n! LOOP OVER SAMPLE POINTS IN OUTPUT GRID BOX\n CALL IJKGDS0(IGDTNUMI,IGDTMPLI,IGDTLENI,IJKGDSA)\n DO NB=1,NB3\n! LOCATE INPUT POINTS AND COMPUTE THEIR WEIGHTS AND ROTATIONS\n JB=(NB-1)/NB2-NB1\n IB=NB-(JB+NB1)*NB2-NB1-1\n LB=MAX(ABS(IB),ABS(JB))\n WB=1\n IF(IPOPT(2).EQ.-2) THEN\n WB=(NB1+1-ABS(IB))*(NB1+1-ABS(JB))\n ELSEIF(IPOPT(2).NE.-1) THEN\n WB=IPOPT(2+LB)\n ENDIF\n IF(WB.NE.0) THEN\n!$OMP PARALLEL DO PRIVATE(N) SCHEDULE(STATIC)\n DO N=1,NO\n XPTB(N)=XPTS(N)+IB*RB2\n YPTB(N)=YPTS(N)+JB*RB2\n ENDDO\n!$OMP END PARALLEL DO\n CALL GDSWZD(IGDTNUMO,IGDTMPLO,IGDTLENO, 1,NO,FILL,XPTB,YPTB, &\n RLOB,RLAB,NV)\n CALL GDSWZD(IGDTNUMI,IGDTMPLI,IGDTLENI,-1,NO,FILL,XPTB,YPTB, &\n RLOB,RLAB,NV)\n IF(IRET.EQ.0.AND.NV.EQ.0.AND.LB.EQ.0) IRET=2\n!$OMP PARALLEL DO PRIVATE(N,XI,YI,I1,I2,WI1,WI2,J1,J2,WJ1,WJ2,CM11,CM21,CM12,CM22,SM11,SM21,SM12,SM22) &\n!$OMP SCHEDULE(STATIC)\n DO N=1,NO\n XI=XPTB(N)\n YI=YPTB(N)\n IF(XI.NE.FILL.AND.YI.NE.FILL) THEN\n I1=XI\n I2=I1+1\n WI2=XI-I1\n WI1=1-WI2\n J1=YI\n J2=J1+1\n WJ2=YI-J1\n WJ1=1-WJ2\n N11(N)=IJKGDS1(I1,J1,IJKGDSA)\n N21(N)=IJKGDS1(I2,J1,IJKGDSA)\n N12(N)=IJKGDS1(I1,J2,IJKGDSA)\n N22(N)=IJKGDS1(I2,J2,IJKGDSA)\n IF(MIN(N11(N),N21(N),N12(N),N22(N)).GT.0) THEN\n W11(N)=WI1*WJ1\n W21(N)=WI2*WJ1\n W12(N)=WI1*WJ2\n W22(N)=WI2*WJ2\n CALL MOVECT(RLAI(N11(N)),RLOI(N11(N)),RLAT(N),RLON(N),CM11,SM11)\n CALL MOVECT(RLAI(N21(N)),RLOI(N21(N)),RLAT(N),RLON(N),CM21,SM21)\n CALL MOVECT(RLAI(N12(N)),RLOI(N12(N)),RLAT(N),RLON(N),CM12,SM12)\n CALL MOVECT(RLAI(N22(N)),RLOI(N22(N)),RLAT(N),RLON(N),CM22,SM22)\n C11(N)=CM11*CROI(N11(N))+SM11*SROI(N11(N))\n S11(N)=SM11*CROI(N11(N))-CM11*SROI(N11(N))\n C21(N)=CM21*CROI(N21(N))+SM21*SROI(N21(N))\n S21(N)=SM21*CROI(N21(N))-CM21*SROI(N21(N))\n C12(N)=CM12*CROI(N12(N))+SM12*SROI(N12(N))\n S12(N)=SM12*CROI(N12(N))-CM12*SROI(N12(N))\n C22(N)=CM22*CROI(N22(N))+SM22*SROI(N22(N))\n S22(N)=SM22*CROI(N22(N))-CM22*SROI(N22(N))\n ELSE\n N11(N)=0\n N21(N)=0\n N12(N)=0\n N22(N)=0\n ENDIF\n ELSE\n N11(N)=0\n N21(N)=0\n N12(N)=0\n N22(N)=0\n ENDIF\n ENDDO\n!$OMP END PARALLEL DO \n! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n! INTERPOLATE WITH OR WITHOUT BITMAPS\n! KM IS OFTEN 1 .. DO NO PUT OMP PARALLEL DO HERE\n DO K=1,KM\n!$OMP PARALLEL DO PRIVATE(N,U11,U12,U21,U22,UB,V11,V12,V21,V22,VB) SCHEDULE(STATIC)\n DO N=1,NO\n IF(N11(N).GT.0) THEN\n IF(IBI(K).EQ.0) THEN\n U11=C11(N)*UI(N11(N),K)-S11(N)*VI(N11(N),K)\n V11=S11(N)*UI(N11(N),K)+C11(N)*VI(N11(N),K)\n U21=C21(N)*UI(N21(N),K)-S21(N)*VI(N21(N),K)\n V21=S21(N)*UI(N21(N),K)+C21(N)*VI(N21(N),K)\n U12=C12(N)*UI(N12(N),K)-S12(N)*VI(N12(N),K)\n V12=S12(N)*UI(N12(N),K)+C12(N)*VI(N12(N),K)\n U22=C22(N)*UI(N22(N),K)-S22(N)*VI(N22(N),K)\n V22=S22(N)*UI(N22(N),K)+C22(N)*VI(N22(N),K)\n UB=W11(N)*U11+W21(N)*U21+W12(N)*U12+W22(N)*U22\n VB=W11(N)*V11+W21(N)*V21+W12(N)*V12+W22(N)*V22\n UO(N,K)=UO(N,K)+WB*UB\n VO(N,K)=VO(N,K)+WB*VB\n WO(N,K)=WO(N,K)+WB\n ELSE\n IF(LI(N11(N),K)) THEN\n U11=C11(N)*UI(N11(N),K)-S11(N)*VI(N11(N),K)\n V11=S11(N)*UI(N11(N),K)+C11(N)*VI(N11(N),K)\n UO(N,K)=UO(N,K)+WB*W11(N)*U11\n VO(N,K)=VO(N,K)+WB*W11(N)*V11\n WO(N,K)=WO(N,K)+WB*W11(N)\n ENDIF\n IF(LI(N21(N),K)) THEN\n U21=C21(N)*UI(N21(N),K)-S21(N)*VI(N21(N),K)\n V21=S21(N)*UI(N21(N),K)+C21(N)*VI(N21(N),K)\n UO(N,K)=UO(N,K)+WB*W21(N)*U21\n VO(N,K)=VO(N,K)+WB*W21(N)*V21\n WO(N,K)=WO(N,K)+WB*W21(N)\n ENDIF\n IF(LI(N12(N),K)) THEN\n U12=C12(N)*UI(N12(N),K)-S12(N)*VI(N12(N),K)\n V12=S12(N)*UI(N12(N),K)+C12(N)*VI(N12(N),K)\n UO(N,K)=UO(N,K)+WB*W12(N)*U12\n VO(N,K)=VO(N,K)+WB*W12(N)*V12\n WO(N,K)=WO(N,K)+WB*W12(N)\n ENDIF\n IF(LI(N22(N),K)) THEN\n U22=C22(N)*UI(N22(N),K)-S22(N)*VI(N22(N),K)\n V22=S22(N)*UI(N22(N),K)+C22(N)*VI(N22(N),K)\n UO(N,K)=UO(N,K)+WB*W22(N)*U22\n VO(N,K)=VO(N,K)+WB*W22(N)*V22\n WO(N,K)=WO(N,K)+WB*W22(N)\n ENDIF\n ENDIF\n ENDIF\n ENDDO\n!$OMP END PARALLEL DO\n ENDDO\n ENDIF\n ENDDO\n! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n! COMPUTE OUTPUT BITMAPS AND FIELDS\n! KM is often 1, do not put OMP PARALLEL here\n DO K=1,KM\n IBO(K)=IBI(K)\n!$OMP PARALLEL DO PRIVATE(N,UROT,VROT) SCHEDULE(STATIC)\n DO N=1,NO\n LO(N,K)=WO(N,K).GE.PMP*NB4\n IF(LO(N,K)) THEN\n UO(N,K)=UO(N,K)/WO(N,K)\n VO(N,K)=VO(N,K)/WO(N,K)\n UROT=CROT(N)*UO(N,K)-SROT(N)*VO(N,K)\n VROT=SROT(N)*UO(N,K)+CROT(N)*VO(N,K)\n UO(N,K)=UROT\n VO(N,K)=VROT\n ELSE\n IBO(K)=1\n UO(N,K)=0.\n VO(N,K)=0.\n ENDIF\n ENDDO\n!$OMP END PARALLEL DO\n ENDDO\n IF(IGDTNUMO.EQ.0) CALL POLFIXV(NO,MO,KM,RLAT,RLON,IBO,LO,UO,VO)\n! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n END SUBROUTINE POLATEV3\n! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n SUBROUTINE CHECK_GRIDS3V(IGDTNUM,IGDTMPL,IGDTLEN,SAME_GRID)\n!$$$ SUBPROGRAM DOCUMENTATION BLOCK\n!\n! SUBPROGRAM: CHECK_GRIDS3V CHECK GRID INFORMATION\n! PRGMMR: GAYNO ORG: W/NMC23 DATE: 2015-07-13\n!\n! ABSTRACT: DETERMINE WHETHER THE GRID SPECS\n! HAVE CHANGED.\n!\n! PROGRAM HISTORY LOG:\n! 2015-07-13 GAYNO INITIAL VERSION\n!\n! USAGE: CALL CHECK_GRIDS3V(IGDTNUM,IGDTMPL,IGDTLEN,SAME_GRID)\n!\n! INPUT ARGUMENT LIST:\n! IGDTNUM - INTEGER GRID DEFINITION TEMPLATE NUMBER.\n! CORRESPONDS TO THE GFLD%IGDTNUM COMPONENT OF THE\n! NCEP G2 LIBRARY GRIDMOD DATA STRUCTURE.\n! IGDTMPL - INTEGER (IGDTLENI) GRID DEFINITION TEMPLATE ARRAY.\n! CORRESPONDS TO THE GFLD%IGDTMPL COMPONENT\n! OF THE NCEP G2 LIBRARY GRIDMOD DATA STRUCTURE.\n! IGDTLEN - INTEGER NUMBER OF ELEMENTS OF THE GRID DEFINITION\n! TEMPLATE ARRAY. CORRESPONDS TO THE GFLD%IGDTLEN\n! COMPONENT OF THE NCEP G2 LIBRARY GRIDMOD DATA STRUCTURE.\n!\n! OUTPUT ARGUMENT LIST:\n! SAME_GRID - WHEN TRUE, THE GRID HAS NOT CHANGED BETWEEN CALLS.\n!\n! ATTRIBUTES:\n! LANGUAGE: FORTRAN 90\n!\n!$$$\n IMPLICIT NONE\n!\n INTEGER, INTENT(IN ) :: IGDTNUM, IGDTLEN\n INTEGER, INTENT(IN ) :: IGDTMPL(IGDTLEN)\n!\n LOGICAL, INTENT( OUT) :: SAME_GRID\n!\n INTEGER, SAVE :: IGDTNUM_SAVE=-9999\n INTEGER, SAVE :: IGDTLEN_SAVE=-9999\n INTEGER, SAVE :: IGDTMPL_SAVE(1000)=-9999\n!\n! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n SAME_GRID=.FALSE.\n IF(IGDTNUM==IGDTNUM_SAVE)THEN\n IF(IGDTLEN==IGDTLEN_SAVE)THEN\n IF(ALL(IGDTMPL==IGDTMPL_SAVE(1:IGDTLEN)))THEN\n SAME_GRID=.TRUE.\n ENDIF\n ENDIF\n ENDIF\n!\n IGDTNUM_SAVE=IGDTNUM\n IGDTLEN_SAVE=IGDTLEN\n IGDTMPL_SAVE(1:IGDTLEN)=IGDTMPL\n IGDTMPL_SAVE(IGDTLEN+1:1000)=-9999\n! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n END SUBROUTINE CHECK_GRIDS3V\n", "meta": {"hexsha": "981d031b9f185fc494331454e1161cd562da3984", "size": 19991, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "third_party_open/wgrib2/ip2lib_d/polatev3.f90", "max_stars_repo_name": "noaa-ocs-modeling/PaHM", "max_stars_repo_head_hexsha": "e5673c9c80a76a06534acb1542c3c16af2e3cd02", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2015-06-11T00:07:56.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-16T10:56:31.000Z", "max_issues_repo_path": "third_party_open/wgrib2/ip2lib_d/polatev3.f90", "max_issues_repo_name": "noaa-ocs-modeling/PaHM", "max_issues_repo_head_hexsha": "e5673c9c80a76a06534acb1542c3c16af2e3cd02", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2021-06-02T15:54:33.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-08T19:44:01.000Z", "max_forks_repo_path": "third_party_open/wgrib2/ip2lib_d/polatev3.f90", "max_forks_repo_name": "pvelissariou1/pahm", "max_forks_repo_head_hexsha": "41bd774ef88ce65f4666119593c233f877b655e2", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-06-12T10:37:02.000Z", "max_forks_repo_forks_event_max_datetime": "2019-10-19T10:26:32.000Z", "avg_line_length": 40.9651639344, "max_line_length": 104, "alphanum_fraction": 0.5520984443, "num_tokens": 7270, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582593509315, "lm_q2_score": 0.7461389817407016, "lm_q1q2_score": 0.6942511781843297}} {"text": "program tri_ppal\n\nimplicit none\n\nreal, dimension(:), allocatable :: a,b,c,r,w,u\n\ninteger :: n, i, j\n\nprint*, 'Introduce o orde do sistema: '\nread*, n\nprint*\nprint*, 'O orde introducido e: ', n\nprint*\n\nallocate(a(n), b(2:n), r(n), w(n), u(n))\n\nprint*,\nprint*, 'Introduce a diagonal principal: '\nread*, a(1:n)\nprint*,\n\nprint*,\nprint*, 'Introduce a diagonal inferior: '\nread*, b(2:n)\nprint*,\n\nprint*, 'Introduce el segundo miembro: '\nread*, r(1:n)\nprint*,\n\nprint*,\nprint*, 'Diagonal principal: ',a(1:n)\nprint*, 'Diagonal inferior ', b(2:n)\nprint*, 'Segundo miembro: ',r(1:n)\nprint*,\n\na(1) = sqrt(a(1))\n\ndo i=2,n\n b(i) = b(i)/a(i-1)\n a(i) = sqrt(a(i)-b(i)*b(i))\nend do\n\nprint*,\nprint*, 'Diagonal principal: ',a(1:n)\nprint*, 'Diagonal inferior ', b(2:n)\nprint*, 'Segundo miembro: ',r(1:n)\nprint*,\n\nw(1) = r(1)/a(1)\n\ndo i=2,n\nprint*, r(i)\nprint*, w(i-1)\nprint*, a(i)\n w(i)=(r(i)- b(i)*w(i-1))/a(i)\nend do\n\nprint*, 'Vector w:'\nprint*, w\nprint*,\n\nu(n) = w(n)/a(n)\n\ndo i=n-1,1,-1\n u(i)= (w(i)-b(i+1)*u(i+1))/a(i)\nend do\n\nprint*,\nprint*, 'Vector u (Solucion): '\nprint*,\n\nprint*,\nprint*, u\nprint*,\n\n\nend program\n", "meta": {"hexsha": "dbb8c8305bd83d49d24f2df5e37dcdf03ed2f734", "size": 1105, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Practica3_choleskytri/tri_ppal.f95", "max_stars_repo_name": "UxioAndrade/Analisis-Numerico-Matricial", "max_stars_repo_head_hexsha": "1afa52b0994b9cf38822da903609a4d1c91bfab0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Practica3_choleskytri/tri_ppal.f95", "max_issues_repo_name": "UxioAndrade/Analisis-Numerico-Matricial", "max_issues_repo_head_hexsha": "1afa52b0994b9cf38822da903609a4d1c91bfab0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Practica3_choleskytri/tri_ppal.f95", "max_forks_repo_name": "UxioAndrade/Analisis-Numerico-Matricial", "max_forks_repo_head_hexsha": "1afa52b0994b9cf38822da903609a4d1c91bfab0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 13.9873417722, "max_line_length": 46, "alphanum_fraction": 0.5864253394, "num_tokens": 429, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460333, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.6942436382389913}} {"text": " REAL FUNCTION SNRM2F ( N, X, INCX )\n* .. Scalar Arguments ..\n INTEGER INCX, N\n* .. Array Arguments ..\n REAL X( * )\n* ..\n*\n* SNRM2 returns the euclidean norm of a vector via the function\n* name, so that\n*\n* SNRM2 := sqrt( x'*x )\n*\n*\n*\n* -- This version written on 25-October-1982.\n* Modified on 14-October-1993 to inline the call to SLASSQ.\n* Sven Hammarling, Nag Ltd.\n*\n*\n* .. Parameters ..\n REAL ONE , ZERO\n PARAMETER ( ONE = 1.0E+0, ZERO = 0.0E+0 )\n* .. Local Scalars ..\n INTEGER IX\n REAL ABSXI, NORM, SCALE, SSQ\n* .. Intrinsic Functions ..\n INTRINSIC ABS, SQRT\n* ..\n* .. Executable Statements ..\n IF( N.LT.1 .OR. INCX.LT.1 )THEN\n NORM = ZERO\n ELSE IF( N.EQ.1 )THEN\n NORM = ABS( X( 1 ) )\n ELSE\n SCALE = ZERO\n SSQ = ONE\n* The following loop is equivalent to this call to the LAPACK\n* auxiliary routine:\n* CALL SLASSQ( N, X, INCX, SCALE, SSQ )\n*\n DO 10, IX = 1, 1 + ( N - 1 )*INCX, INCX\n IF( X( IX ).NE.ZERO )THEN\n ABSXI = ABS( X( IX ) )\n IF( SCALE.LT.ABSXI )THEN\n SSQ = ONE + SSQ*( SCALE/ABSXI )**2\n SCALE = ABSXI\n ELSE\n SSQ = SSQ + ( ABSXI/SCALE )**2\n END IF\n END IF\n 10 CONTINUE\n NORM = SCALE * SQRT( SSQ )\n END IF\n*\n SNRM2F = NORM\n RETURN\n*\n* End of SNRM2.\n*\n END\n", "meta": {"hexsha": "cff495d20faf8ff227d54535e277cb9e564f4ff5", "size": 1660, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "reference/snrm2f.f", "max_stars_repo_name": "drhpc/OpenBLAS", "max_stars_repo_head_hexsha": "9721b57ecfd194f1a4aaa08d715735cd9e8ad8b6", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 4392, "max_stars_repo_stars_event_min_datetime": "2015-01-02T18:15:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T12:14:38.000Z", "max_issues_repo_path": "reference/snrm2f.f", "max_issues_repo_name": "drhpc/OpenBLAS", "max_issues_repo_head_hexsha": "9721b57ecfd194f1a4aaa08d715735cd9e8ad8b6", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4246, "max_issues_repo_issues_event_min_datetime": "2016-03-26T01:21:45.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T23:10:47.000Z", "max_forks_repo_path": "reference/snrm2f.f", "max_forks_repo_name": "drhpc/OpenBLAS", "max_forks_repo_head_hexsha": "9721b57ecfd194f1a4aaa08d715735cd9e8ad8b6", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1564, "max_forks_repo_forks_event_min_datetime": "2015-01-01T01:32:27.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T07:12:54.000Z", "avg_line_length": 27.2131147541, "max_line_length": 68, "alphanum_fraction": 0.4355421687, "num_tokens": 498, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392695254318, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.694243628642048}} {"text": " Program dgecon_example\n\n! DGECON Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_interfaces, Only: dgecon, dgetrf, dlange\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nin = 5, nout = 6\n Character (1), Parameter :: norm = '1'\n! .. Local Scalars ..\n Real (Kind=dp) :: anorm, rcond\n Integer :: i, info, lda, n\n! .. Local Arrays ..\n Real (Kind=dp), Allocatable :: a(:, :), work(:)\n Integer, Allocatable :: ipiv(:), iwork(:)\n! .. Intrinsic Procedures ..\n Intrinsic :: epsilon\n! .. Executable Statements ..\n Write (nout, *) 'DGECON Example Program Results'\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n\n lda = n\n Allocate (a(lda,n), work(4*n), ipiv(n), iwork(n))\n\n! Read A from data file\n\n Read (nin, *)(a(i,1:n), i=1, n)\n\n! Compute norm of A\n\n anorm = dlange(norm, n, n, a, lda, work)\n\n! Factorize A\n Call dgetrf(n, n, a, lda, ipiv, info)\n\n Write (nout, *)\n If (info==0) Then\n\n! Estimate condition number\n\n Call dgecon(norm, n, a, lda, anorm, rcond, work, iwork, info)\n\n If (rcond>=epsilon(1.0E0_dp)) Then\n Write (nout, 100) 'Estimate of condition number =', 1.0E0_dp/rcond\n Else\n Write (nout, *) 'A is singular to working precision'\n End If\n Else\n Write (nout, *) 'The factor U is singular'\n End If\n\n100 Format (1X, A, 1P, E10.2)\n End Program\n", "meta": {"hexsha": "a83a1796676da504ddb7568446083538dd14eed5", "size": 1742, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/dgecon_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/dgecon_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/dgecon_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 28.0967741935, "max_line_length": 90, "alphanum_fraction": 0.5711825488, "num_tokens": 528, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392725805822, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.6942436265993029}} {"text": "subroutine line(a,b,n,v)\nimplicit none;\n integer ::i,n ;\n real*8::a,b;\n real*8,dimension(n)::v;\nv=(/((a+(b-a)/(n-1)*i),i=0,n-1)/);\nreturn;\nend subroutine\n", "meta": {"hexsha": "ec6470355b1ef09ec68d14f434d1d221f7b7571c", "size": 154, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "11/mathlib/line.f90", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "11/mathlib/line.f90", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "11/mathlib/line.f90", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.1111111111, "max_line_length": 34, "alphanum_fraction": 0.5974025974, "num_tokens": 60, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8670357666736772, "lm_q2_score": 0.8006920092299292, "lm_q1q2_score": 0.6942286100921587}} {"text": "\n SUBROUTINE inverse(a,c,n)\n !============================================================\n ! Inverse matrix\n ! Method: Based on Doolittle LU factorization for Ax=b\n ! Alex G. December 2009\n !-----------------------------------------------------------\n ! input ...\n ! a(n,n) - array of coefficients for matrix A\n ! n - dimension\n ! output ...\n ! c(n,n) - inverse matrix of A\n ! comments ...\n ! the original matrix a(n,n) will be destroyed \n ! during the calculation\n !===========================================================\n implicit none\n integer n\n double precision a(n,n),c(n,n)\n double precision L(n,n),U(n,n), b(n), d(n), x(n)\n double precision 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.0d0\n U=0.0d0\n b=0.0d0\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.0d0\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.0d0\n d(1) = b(1)\n ! Step 3a: Solve Ld=b using the forward substitution\n do i=2,n\n d(i)=b(i)\n do j=1,i-1\n d(i) = d(i) - L(i,j)*d(j)\n end do\n end do\n ! Step 3b: Solve Ux=d using the back substitution\n x(n)=d(n)/U(n,n)\n do i = n-1,1,-1\n x(i) = d(i)\n do j=n,i+1,-1\n x(i)=x(i)-U(i,j)*x(j)\n end do\n x(i) = x(i)/u(i,i)\n end do\n ! Step 3c: fill the solutions x(n) into column k of C\n do i=1,n\n c(i,k) = x(i)\n end do\n b(k)=0.0d0\n end do\n\n END SUBROUTINE inverse\n", "meta": {"hexsha": "9e76505c873b2c180dc0e9adccfc59bfa5379f43", "size": 2060, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ext_funct/inverse.f90", "max_stars_repo_name": "mfaccenda/ECOMAN", "max_stars_repo_head_hexsha": "67a31b45481dc3c2e57afabd526e75bc1bb9e639", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-28T07:49:51.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-28T07:49:51.000Z", "max_issues_repo_path": "ext_funct/inverse.f90", "max_issues_repo_name": "mfaccenda/ECOMAN", "max_issues_repo_head_hexsha": "67a31b45481dc3c2e57afabd526e75bc1bb9e639", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ext_funct/inverse.f90", "max_forks_repo_name": "mfaccenda/ECOMAN", "max_forks_repo_head_hexsha": "67a31b45481dc3c2e57afabd526e75bc1bb9e639", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-04-28T14:42:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-22T12:17:47.000Z", "avg_line_length": 25.1219512195, "max_line_length": 64, "alphanum_fraction": 0.4757281553, "num_tokens": 666, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736772, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.6942286039067473}} {"text": "module libMath\n\n implicit none\n integer, parameter :: dp = kind(1.d0)\n real(dp), parameter :: pi = atan(1._dp)*4._dp\n real(dp), parameter :: eps = epsilon(1._dp)\n\ncontains\n\n ! -------------------------------------------------\n ! cross3\n ! -------------------------------------------------\n function cross3(avec,bvec)\n real(dp), intent(in), dimension(3) :: avec,bvec\n real(dp), dimension(3) :: cross3\n\n cross3(1) = avec(2)*bvec(3)-avec(3)*bvec(2)\n cross3(2) = avec(3)*bvec(1)-avec(1)*bvec(3)\n cross3(3) = avec(1)*bvec(2)-avec(2)*bvec(1)\n\n end function cross3\n\n ! -------------------------------------------------\n ! linspace\n ! -------------------------------------------------\n function linspace(xstart,xend,nx) result(xout)\n real(dp), intent(in) :: xstart, xend\n integer , intent(in) :: nx\n real(dp), dimension(nx) :: xout\n integer :: i\n real(dp) :: dx\n\n dx = (xend-xstart)/(nx-1)\n\n xout = (/((i*dx),i=0,nx-1)/)\n xout = xout+xstart\n\n end function linspace\n\n ! -------------------------------------------------\n ! cosspace\n ! -------------------------------------------------\n function cosspace(xstart,xend,nx) result(xout)\n real(dp), intent(in) :: xstart, xend\n integer , intent(in) :: nx\n real(dp), dimension(nx) :: xout\n real(dp), dimension(nx) :: theta_spacing\n\n theta_spacing=linspace(0._dp,pi,nx)\n xout=xstart+(xend-xstart)*0.5_dp*(1._dp-cos(theta_spacing))\n\n end function cosspace\n\n ! -------------------------------------------------\n ! halfsinspace\n ! -------------------------------------------------\n function halfsinspace(xstart,xend,nx) result(xout)\n real(dp), intent(in) :: xstart, xend\n integer , intent(in) :: nx\n real(dp), dimension(nx) :: xout\n real(dp), dimension(nx) :: theta_spacing\n\n theta_spacing=linspace(0._dp,pi*0.5_dp,nx)\n xout=xstart+(xend-xstart)*sin(theta_spacing)\n\n end function halfsinspace\n\nend module libMath\n", "meta": {"hexsha": "d8b0c24e1ef6bf838acf1b77787ba22ed03a5c60", "size": 2002, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "libMath.f90", "max_stars_repo_name": "cibinjoseph/fourPointWing", "max_stars_repo_head_hexsha": "eb90dc28a4c35d9e723dafd37d99af002eab9b9e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-08-15T11:08:47.000Z", "max_stars_repo_stars_event_max_datetime": "2019-08-15T11:08:47.000Z", "max_issues_repo_path": "libMath.f90", "max_issues_repo_name": "cibinjoseph/fourPointWing", "max_issues_repo_head_hexsha": "eb90dc28a4c35d9e723dafd37d99af002eab9b9e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "libMath.f90", "max_forks_repo_name": "cibinjoseph/fourPointWing", "max_forks_repo_head_hexsha": "eb90dc28a4c35d9e723dafd37d99af002eab9b9e", "max_forks_repo_licenses": ["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.0144927536, "max_line_length": 63, "alphanum_fraction": 0.4825174825, "num_tokens": 548, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.867035763237924, "lm_q2_score": 0.8006919925839875, "lm_q1q2_score": 0.6942285929085518}} {"text": "program main\n! The main program for MD.\n!\n! Discussion:\n! MD implements a simple molecular dynamics simulation.\n! The velocity Verlet time integration scheme is used. \n! The particles interact with a central pair potential.\n!\n! Based on a FORTRAN90 program by Bill Magro.\n!\n! Calculating distances, forces, potential- and kinetic-\n! energies have been broken out into subroutines to make this\n! a more interesting example to analyze with a profiler.\n! 2018-05-25 Oliver Stueker\n!\n! Usage:\n! md nd np step_num dt\n!\n! where:\n!\n! * nd is the spatial dimension (2 or 3);\n! * np is the number of particles (500, for instance);\n! * step_num is the number of time steps (500, for instance).\n! * dt is the time step (0.1 for instance )\n!\n! Licensing:\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n! 25 May 2018 by Oliver Stueker\n!\n! Author:\n! John Burkardt\n!\n implicit none\n\n real ( kind = 8 ), allocatable :: acc(:,:)\n integer ( kind = 4 ) arg_num\n real ( kind = 8 ) ctime\n real ( kind = 8 ) ctime1\n real ( kind = 8 ) ctime2\n real ( kind = 8 ) dt\n real ( kind = 8 ) e0\n real ( kind = 8 ), allocatable :: force(:,:)\n integer ( kind = 4 ) iarg\n integer ( kind = 4 ) id\n integer ( kind = 4 ) ierror\n real ( kind = 8 ) kinetic\n integer ( kind = 4 ) last\n real ( kind = 8 ), parameter :: mass = 1.0D+00\n integer ( kind = 4 ) nd\n integer ( kind = 4 ) np\n real ( kind = 8 ), allocatable :: pos(:,:)\n real ( kind = 8 ) potential\n real ( kind = 8 ) rel\n integer ( kind = 4 ) step\n integer ( kind = 4 ) step_num\n integer ( kind = 4 ) step_print\n integer ( kind = 4 ) step_print_index\n integer ( kind = 4 ) step_print_num\n character ( len = 255 ) string\n real ( kind = 8 ), allocatable :: vel(:,:)\n real ( kind = 8 ) wtime\n\n call timestamp ( )\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'MD'\n write ( *, '(a)' ) ' FORTRAN90 version'\n write ( *, '(a)' ) ' A molecular dynamics program.'\n!\n! Get the number of command line arguments.\n!\n arg_num = iargc ( )\n!\n! Get ND, the number of spatial dimensions.\n!\n if ( 1 <= arg_num ) then\n iarg = 1\n call getarg ( iarg, string )\n call s_to_i4 ( string, nd, ierror, last )\n else\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' Enter ND, the spatial dimension (2 or 3 ):'\n read ( *, * ) nd\n end if\n!\n! Get NP, the number of particles.\n!\n if ( 2 <= arg_num ) then\n iarg = 2\n call getarg ( iarg, string )\n call s_to_i4 ( string, np, ierror, last )\n else\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) &\n ' Enter NP, the number of particles (500, for instance):'\n read ( *, * ) np\n end if\n!\n! Get STEP_NUM, the number of time steps.\n!\n if ( 3 <= arg_num ) then\n iarg = 3\n call getarg ( iarg, string )\n call s_to_i4 ( string, step_num, ierror, last )\n else\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) &\n ' Enter STEP_NUM, the number of time steps (500, for instance):'\n read ( *, * ) step_num\n end if\n!\n! Get DT, the time step.\n!\n if ( 4 <= arg_num ) then\n iarg = 4\n call getarg ( iarg, string )\n call s_to_r8 ( string, dt )\n else\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) &\n ' Enter DT, the time step size (0.1, for instance):'\n read ( *, * ) dt\n end if\n!\n! Report.\n!\n write ( *, '(a)' ) ' '\n write ( *, '(a,i8)' ) ' ND, the spatial dimension, is ', nd\n write ( *, '(a,i8)' ) &\n ' NP, the number of particles in the simulation is ', np\n write ( *, '(a,i8)' ) ' STEP_NUM, the number of time steps, is ', step_num\n write ( *, '(a,g14.6)' ) ' DT, the size of each time step, is ', dt\n!\n! Allocate memory.\n!\n allocate ( acc(nd,np) )\n allocate ( force(nd,np) )\n allocate ( pos(nd,np) )\n allocate ( vel(nd,np) )\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) &\n ' At each step, we report the potential and kinetic energies.'\n write ( *, '(a)' ) ' The sum of these energies should be a constant.'\n write ( *, '(a)' ) ' As an accuracy check, we also print the relative error'\n write ( *, '(a)' ) ' in the total energy.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) &\n ' Step Potential Kinetic (P+K-E0)/E0'\n write ( *, '(a)' ) &\n ' Energy P Energy K Relative Energy Error'\n write ( *, '(a)' ) ' '\n!\n! This is the main time stepping loop:\n! Initialize or update positions, velocities, accelerations.\n! Compute forces and energies,\n!\n step_print = 0\n step_print_index = 0\n step_print_num = 10\n\n call cpu_time ( ctime1 )\n\n do step = 0, step_num\n\n if ( step == 0 ) then\n call initialize ( np, nd, pos, vel, acc )\n else\n call update ( np, nd, pos, vel, force, acc, mass, dt )\n end if\n\n call compute ( np, nd, pos, vel, mass, force, potential, kinetic )\n\n if ( step == 0 ) then\n e0 = potential + kinetic\n end if\n\n if ( step == step_print ) then\n rel = ( potential + kinetic - e0 ) / e0\n write ( *, '(2x,i8,2x,g14.6,2x,g14.6,2x,g14.6)' ) &\n step, potential, kinetic, rel \n step_print_index = step_print_index + 1\n step_print = ( step_print_index * step_num ) / step_print_num\n end if\n\n end do\n!\n! Report time.\n!\n call cpu_time ( ctime2 )\n ctime = ctime2 - ctime1\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' Elapsed cpu time for main computation:'\n write ( *, '(2x,g14.6,a)' ) ctime, ' seconds'\n!\n! Free memory.\n!\n deallocate ( acc )\n deallocate ( force )\n deallocate ( pos )\n deallocate ( vel )\n!\n! Terminate.\n!\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'MD:'\n write ( *, '(a)' ) ' Normal end of execution.'\n write ( *, '(a)' ) ' '\n call timestamp ( )\n\n stop\nend\n\n!*****************************************************************************80\nsubroutine compute ( np, nd, pos, vel, mass, f, pot, kin )\n! Computes the forces and energies.\n!\n! Discussion:\n! The computation of forces and energies is fully parallel.\n!\n! The potential function V(X) is a harmonic well which smoothly\n! saturates to a maximum value at PI/2:\n!\n! v(x) = ( sin ( min ( x, PI/2 ) ) )^2\n!\n! The derivative of the potential is:\n!\n! dv(x) = 2.0D+00 * sin ( min ( x, PI/2 ) ) * cos ( min ( x, PI/2 ) )\n! = sin ( 2.0 * min ( x, PI/2 ) )\n!\n! Licensing:\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n! 15 July 2008\n!\n! Author:\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) NP, the number of particles.\n!\n! Input, integer ( kind = 4 ) ND, the number of spatial dimensions.\n!\n! Input, real ( kind = 8 ) POS(ND,NP), the positions.\n!\n! Input, real ( kind = 8 ) VEL(ND,NP), the velocities.\n!\n! Input, real ( kind = 8 ) MASS, the mass.\n!\n! Output, real ( kind = 8 ) F(ND,NP), the forces.\n!\n! Output, real ( kind = 8 ) POT, the total potential energy.\n!\n! Output, real ( kind = 8 ) KIN, the total kinetic energy.\n!\n implicit none\n\n integer ( kind = 4 ) np\n integer ( kind = 4 ) nd\n\n real ( kind = 8 ) d\n real ( kind = 8 ) d2\n real ( kind = 8 ) f(nd,np)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) j\n real ( kind = 8 ) kin\n real ( kind = 8 ) mass\n real ( kind = 8 ), parameter :: PI2 = 3.141592653589793D+00 / 2.0D+00\n real ( kind = 8 ) pos(nd,np)\n real ( kind = 8 ) pot\n real ( kind = 8 ) rij(nd)\n real ( kind = 8 ) vel(nd,np)\n\n pot = 0.0D+00\n\n do i = 1, np\n !\n ! Compute the potential energy and forces.\n !\n f(1:nd,i) = 0.0D+00\n\n do j = 1, np\n\n if ( i /= j ) then\n\n call calc_distance (np, nd, pos, i, j, rij, d, d2)\n \n call calc_pot(d2, pot)\n \n call calc_force (np, nd, i, d, d2, rij, f)\n\n end if\n\n end do\n\n end do\n \n call calc_kin ( np, nd, vel, mass, kin )\n \n return\nend\n\nsubroutine calc_pot (d2, pot)\n! Calculate potential energy for truncated distance D2.\n!\n! Parameters:\n! Input, real ( kind = 8 ) D2, trucated distance.\n! In/Out, real ( kind = 8 ) POT, potential energy.\n implicit none\n\n real ( kind = 8 ) d2\n real ( kind = 8 ) pot\n\n !\n ! Attribute half of the total potential energy to particle J.\n !\n pot = pot + 0.5D+00 * sin ( d2 ) * sin ( d2 )\nend subroutine calc_pot\n\nsubroutine calc_force (np, nd, i, d, d2, rij, f)\n! Add particle J's contribution to the force on particle I.\n!\n! Parameters:\n! Input, integer ( kind = 4 ) NP, the number of particles.\n! Input, integer ( kind = 4 ) ND, the number of spatial dimensions.\n! Input, integer ( kind = 4 ) I, index of particle I.\n! Input, real ( kind = 8 ) D, distance.\n! Input, real ( kind = 8 ) D2, trucated distance.\n! Input, real ( kind = 8 ) Rij(nd), distance vector\n! In/Out, real ( kind = 8 ) F(ND,NP), the forces.\n implicit none\n\n integer ( kind = 4 ) np\n integer ( kind = 4 ) nd\n integer ( kind = 4 ) i\n\n real ( kind = 8 ) d\n real ( kind = 8 ) d2\n real ( kind = 8 ) rij(nd)\n real ( kind = 8 ) f(nd,np)\n !\n ! Add particle J's contribution to the force on particle I.\n !\n f(1:nd,i) = f(1:nd,i) - rij(1:nd) * sin ( 2.0D+00 * d2 ) / d\nend subroutine calc_force\n\nsubroutine calc_kin ( np, nd, vel, mass, kin )\n! Compute the total kinetic energy.\n!\n! Parameters:\n! Input, integer ( kind = 4 ) NP, the number of particles.\n! Input, integer ( kind = 4 ) ND, the number of spatial dimensions.\n! Input, real ( kind = 8 ) VEL(ND,NP), the velocities.\n! Input, real ( kind = 8 ) MASS, the mass.\n! Output, real ( kind = 8 ) KIN, the total kinetic energy.\n implicit none\n\n integer ( kind = 4 ) np\n integer ( kind = 4 ) nd\n real ( kind = 8 ) vel(nd,np)\n real ( kind = 8 ) mass\n real ( kind = 8 ) kin\n\n kin = 0.5D+00 * mass * sum ( vel(1:nd,1:np)**2 )\n\nend subroutine calc_kin\n\n!*****************************************************************************80\nsubroutine initialize ( np, nd, pos, vel, acc )\n! Initializes the positions, velocities, and accelerations.\n!\n! Licensing:\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n! 26 December 2014\n!\n! Author:\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) NP, the number of particles.\n!\n! Input, integer ( kind = 4 ) ND, the number of spatial dimensions.\n!\n! Output, real ( kind = 8 ) POS(ND,NP), the positions.\n!\n! Output, real ( kind = 8 ) VEL(ND,NP), the velocities.\n!\n! Output, real ( kind = 8 ) ACC(ND,NP), the accelerations.\n!\n implicit none\n\n integer ( kind = 4 ) np\n integer ( kind = 4 ) nd\n\n real ( kind = 8 ) acc(nd,np)\n real ( kind = 8 ) pos(nd,np)\n integer ( kind = 4 ) seed\n real ( kind = 8 ) vel(nd,np)\n!\n! Set the positions.\n!\n seed = 123456789\n call r8mat_uniform_ab ( nd, np, 0.0D+00, 10.0D+00, seed, pos )\n!\n! Set the velocities.\n!\n vel(1:nd,1:np) = 0.0D+00\n!\n! Set the accelerations.\n!\n acc(1:nd,1:np) = 0.0D+00\n\n return\nend\n\n\n!*****************************************************************************80\nsubroutine update ( np, nd, pos, vel, f, acc, mass, dt )\n! Updates positions, velocities and accelerations.\n!\n! Discussion:\n! The time integration is fully parallel.\n!\n! A velocity Verlet algorithm is used for the updating.\n!\n! x(t+dt) = x(t) + v(t) * dt + 0.5 * a(t) * dt * dt\n! v(t+dt) = v(t) + 0.5 * ( a(t) + a(t+dt) ) * dt\n! a(t+dt) = f(t) / m\n!\n! Licensing:\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n! 21 November 2007\n!\n! Author:\n! John Burkardt\n!\n! Parameters:\n! Input, integer ( kind = 4 ) NP, the number of particles.\n!\n! Input, integer ( kind = 4 ) ND, the number of spatial dimensions.\n!\n! Input/output, real ( kind = 8 ) POS(ND,NP), the positions.\n!\n! Input/output, real ( kind = 8 ) VEL(ND,NP), the velocities.\n!\n! Input, real ( kind = 8 ) F(ND,NP), the forces.\n!\n! Input/output, real ( kind = 8 ) ACC(ND,NP), the accelerations.\n!\n! Input, real ( kind = 8 ) MASS, the mass of each particle.\n!\n! Input, real ( kind = 8 ) DT, the time step.\n!\n implicit none\n\n integer ( kind = 4 ) np\n integer ( kind = 4 ) nd\n\n real ( kind = 8 ) acc(nd,np)\n real ( kind = 8 ) dt\n real ( kind = 8 ) f(nd,np)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) j\n real ( kind = 8 ) mass\n real ( kind = 8 ) pos(nd,np)\n real ( kind = 8 ) rmass\n real ( kind = 8 ) vel(nd,np)\n\n rmass = 1.0D+00 / mass\n\n do j = 1, np\n do i = 1, nd\n pos(i,j) = pos(i,j) + vel(i,j) * dt + 0.5D+00 * acc(i,j) * dt * dt\n vel(i,j) = vel(i,j) + 0.5D+00 * dt * ( f(i,j) * rmass + acc(i,j) )\n acc(i,j) = f(i,j) * rmass\n end do\n end do\n\n return\nend\n", "meta": {"hexsha": "6794fefc922ade9f0612e9c8b6737d3fe2773c0c", "size": 12559, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/md.f90", "max_stars_repo_name": "ostueker/Example_Fortran", "max_stars_repo_head_hexsha": "1a502407ba3a1ad543d15b72c6c493442efa35f9", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-11-13T19:26:12.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-13T19:26:12.000Z", "max_issues_repo_path": "src/md.f90", "max_issues_repo_name": "ostueker/Example_Fortran", "max_issues_repo_head_hexsha": "1a502407ba3a1ad543d15b72c6c493442efa35f9", "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": "src/md.f90", "max_forks_repo_name": "ostueker/Example_Fortran", "max_forks_repo_head_hexsha": "1a502407ba3a1ad543d15b72c6c493442efa35f9", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-12-30T09:30:56.000Z", "max_forks_repo_forks_event_max_datetime": "2018-12-30T09:30:56.000Z", "avg_line_length": 25.6306122449, "max_line_length": 80, "alphanum_fraction": 0.5562544789, "num_tokens": 4182, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.8006919949619793, "lm_q1q2_score": 0.6942285922193756}} {"text": " PROGRAM xsprstp\r\nC driver for routine sprstp\r\n INTEGER NP,NMAX\r\n PARAMETER(NP=5,NMAX=2*NP*NP+1)\r\n INTEGER i,j,ija(NMAX),ijat(NMAX)\r\n REAL a(NP,NP),at(NP,NP),sa(NMAX),sat(NMAX)\r\n DATA a/3.0,0.0,0.0,0.0,0.0,\r\n * 0.0,4.0,7.0,0.0,0.0,\r\n * 1.0,0.0,5.0,0.0,0.0,\r\n * 0.0,0.0,9.0,0.0,6.0,\r\n * 0.0,0.0,0.0,2.0,5.0/\r\n call sprsin(a,NP,NP,0.5,NMAX,sa,ija)\r\n call sprstp(sa,ija,sat,ijat)\r\n do 12 i=1,NP\r\n do 11 j=1,NP\r\n at(i,j)=0.0\r\n11 continue\r\n12 continue\r\n do 14 i=1,NP\r\n at(i,i)=sat(i)\r\n do 13 j=ijat(i),ijat(i+1)-1\r\n at(i,ijat(j))=sat(j)\r\n13 continue\r\n14 continue\r\n write(*,*) 'Original matrix:'\r\n write(*,'(5f7.1)') ((a(i,j),j=1,NP),i=1,NP)\r\n write(*,*) 'Transpose:'\r\n write(*,'(5f7.1)') ((at(i,j),j=1,NP),i=1,NP)\r\n END\r\n", "meta": {"hexsha": "f18b634aa8a29b338f17d6900a417baad4110dd0", "size": 882, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xsprstp.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xsprstp.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xsprstp.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.4, "max_line_length": 51, "alphanum_fraction": 0.4659863946, "num_tokens": 400, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.8006919949619793, "lm_q1q2_score": 0.6942285922193756}} {"text": "program dla\n use arrayfire\n implicit none\n\n type(array) A, B, C, X0, X1, X2\n type(array) l, u, p, r, diff\n integer :: N\n\n ! Set the size of the matrix\n N = 5\n\n ! Randomly generate a system\n A = randu(N, N)\n X0 = randu(N, 1)\n\n ! LU decomposition\n call lu(l, u, p, A)\n\n ! Construct a positive definite matrix\n C = A + transpose(A) + identity(N, N) * 100.0\n call cholesky(r, C)\n\n ! Solve a general system of equations\n B = matmul(A, X0)\n X1 = solve(A, B)\n call print(max(abs(X0 - X1)), \"absolute error: Solving general system\")\n\n ! Solve a positive definite system of equations\n B = matmul(C, X0)\n X2 = solve(C, B)\n call print(max(abs(X0 - X2)), \"absolute error: Solving positive definite system\")\n\n ! Invert a matrix\n r = inverse(A)\n diff = abs(identity(N, N) - matmul(r, A))\n call print(max(moddims(diff, N * N, 1)), \"absolute error: Inverting a matrix\")\n\nend program dla\n", "meta": {"hexsha": "d320c6ecfa9eba12aaefd594c6054af467cb9bf4", "size": 898, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/dla.f90", "max_stars_repo_name": "arrayfire/arrayfire-fortran", "max_stars_repo_head_hexsha": "90b816286cea012a26c3adfe934c5482980eb41c", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2015-10-27T23:34:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T20:11:04.000Z", "max_issues_repo_path": "examples/dla.f90", "max_issues_repo_name": "arrayfire/arrayfire-fortran", "max_issues_repo_head_hexsha": "90b816286cea012a26c3adfe934c5482980eb41c", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2016-08-15T12:35:42.000Z", "max_issues_repo_issues_event_max_datetime": "2017-04-21T15:59:32.000Z", "max_forks_repo_path": "examples/dla.f90", "max_forks_repo_name": "arrayfire/arrayfire_fortran", "max_forks_repo_head_hexsha": "90b816286cea012a26c3adfe934c5482980eb41c", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2015-09-10T12:56:29.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-16T07:20:12.000Z", "avg_line_length": 23.0256410256, "max_line_length": 83, "alphanum_fraction": 0.6369710468, "num_tokens": 302, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.91610961358942, "lm_q2_score": 0.7577943822145998, "lm_q1q2_score": 0.6942227186708503}} {"text": " PROGRAM xlinmin\r\nC driver for routine linmin\r\n INTEGER NDIM\r\n REAL PIO2\r\n PARAMETER(NDIM=3,PIO2=1.5707963)\r\n INTEGER i,j\r\n REAL fret,sr2,x,p(NDIM),xi(NDIM)\r\n write(*,'(/1x,a)') 'Minimum of a 3-D quadratic centered'\r\n write(*,'(1x,a)') 'at (1.0,1.0,1.0). Minimum is found'\r\n write(*,'(1x,a)') 'along a series of radials.'\r\n write(*,'(/1x,t10,a,t22,a,t34,a,t42,a/)') 'x','y','z','minimum'\r\n do 11 i=0,10\r\n x=PIO2*i/10.0\r\n sr2=sqrt(2.0)\r\n xi(1)=sr2*cos(x)\r\n xi(2)=sr2*sin(x)\r\n xi(3)=1.0\r\n p(1)=0.0\r\n p(2)=0.0\r\n p(3)=0.0\r\n call linmin(p,xi,NDIM,fret)\r\n write(*,'(1x,4f12.6)') (p(j),j=1,3),fret\r\n11 continue\r\n END\r\n REAL FUNCTION func(x)\r\n INTEGER i\r\n REAL x(3)\r\n func=0.0\r\n do 11 i=1,3\r\n func=func+(x(i)-1.0)**2\r\n11 continue\r\n END\r\n", "meta": {"hexsha": "056318ade141f8aa9265ec72bee96df39d6fb0f4", "size": 906, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xlinmin.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xlinmin.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xlinmin.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.4545454545, "max_line_length": 70, "alphanum_fraction": 0.4757174393, "num_tokens": 351, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.896251378675949, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6942214306210316}} {"text": "\n !\n ! This program may be freely redistributed under the \n ! condition that the copyright notices (including this \n ! entire header) are not removed, and no compensation \n ! is received through use of the software. Private, \n ! research, and institutional use is free. You may \n ! distribute modified versions of this code UNDER THE \n ! CONDITION THAT THIS CODE AND ANY MODIFICATIONS MADE \n ! TO IT IN THE SAME FILE REMAIN UNDER COPYRIGHT OF THE \n ! ORIGINAL AUTHOR, BOTH SOURCE AND OBJECT CODE ARE \n ! MADE FREELY AVAILABLE WITHOUT CHARGE, AND CLEAR \n ! NOTICE IS GIVEN OF THE MODIFICATIONS. Distribution \n ! of this code as part of a commercial system is \n ! permissible ONLY BY DIRECT ARRANGEMENT WITH THE \n ! AUTHOR. (If you are not directly supplying this \n ! code to a customer, and you are instead telling them \n ! how they can obtain it for free, then you are not \n ! required to make any arrangement with me.) \n !\n ! Disclaimer: Neither I nor: Columbia University, the \n ! National Aeronautics and Space Administration, nor \n ! the Massachusetts Institute of Technology warrant \n ! or certify this code in any way whatsoever. This \n ! code is provided \"as-is\" to be used at your own risk.\n !\n !\n\n ! \n ! BFUN1D.f90: poly. basis-functions for reconstruction.\n !\n ! Darren Engwirda \n ! 07-Sep-2016\n ! de2363 [at] columbia [dot] edu\n !\n !\n\n pure subroutine bfun1d(isel,ndof,sval,bfun)\n\n !\n ! ISEL basis-function \"order\", -1 => integral-basis , \n ! +0 => function-basis, +1 => 1st deriv.-basis ,\n ! +2 => 2nd deriv.-basis.\n ! NDOF no. degrees-of-freedom in basis.\n ! SVAL local coord. at which to evaluate basis-func.,\n ! such that -1.0 <= SVAL <= +1.0 .\n ! BFUN basis-vector evaluated at SVAL .\n !\n \n implicit none\n \n !------------------------------------------- arguments !\n integer, intent( in) :: isel,ndof\n real*8 , intent( in) :: sval\n real*8 , intent(out) :: bfun(:)\n \n select case (isel)\n case (-1)\n !------------------------------------ -1th-order basis !\n select case (ndof)\n case (+1)\n bfun(1) = sval**1 / 1.d0\n \n case (+2)\n bfun(1) = sval**1 / 1.d0\n bfun(2) = sval**2 / 2.d0\n \n case (+3)\n bfun(1) = sval**1 / 1.d0\n bfun(2) = sval**2 / 2.d0\n bfun(3) = sval**3 / 3.d0\n \n case (+4)\n bfun(1) = sval**1 / 1.d0\n bfun(2) = sval**2 / 2.d0\n bfun(3) = sval**3 / 3.d0\n bfun(4) = sval**4 / 4.d0\n \n case (+5)\n bfun(1) = sval**1 / 1.d0\n bfun(2) = sval**2 / 2.d0\n bfun(3) = sval**3 / 3.d0\n bfun(4) = sval**4 / 4.d0\n bfun(5) = sval**5 / 5.d0\n \n case (+6)\n bfun(1) = sval**1 / 1.d0\n bfun(2) = sval**2 / 2.d0\n bfun(3) = sval**3 / 3.d0\n bfun(4) = sval**4 / 4.d0\n bfun(5) = sval**5 / 5.d0\n bfun(6) = sval**6 / 6.d0\n \n case (+7)\n bfun(1) = sval**1 / 1.d0\n bfun(2) = sval**2 / 2.d0\n bfun(3) = sval**3 / 3.d0\n bfun(4) = sval**4 / 4.d0\n bfun(5) = sval**5 / 5.d0\n bfun(6) = sval**6 / 6.d0\n bfun(7) = sval**7 / 7.d0\n \n end select\n\n case (+0)\n !------------------------------------ +0th-order basis !\n select case (ndof)\n case (+1)\n bfun(1) = 1.d0\n \n case (+2)\n bfun(1) = 1.d0\n bfun(2) = sval**1 * 1.d0\n \n case (+3)\n bfun(1) = 1.d0\n bfun(2) = sval**1 * 1.d0\n bfun(3) = sval**2 * 1.d0\n \n case (+4)\n bfun(1) = 1.d0\n bfun(2) = sval**1 * 1.d0\n bfun(3) = sval**2 * 1.d0\n bfun(4) = sval**3 * 1.d0\n \n case (+5)\n bfun(1) = 1.d0\n bfun(2) = sval**1 * 1.d0\n bfun(3) = sval**2 * 1.d0\n bfun(4) = sval**3 * 1.d0\n bfun(5) = sval**4 * 1.d0\n \n case (+6)\n bfun(1) = 1.d0\n bfun(2) = sval**1 * 1.d0\n bfun(3) = sval**2 * 1.d0\n bfun(4) = sval**3 * 1.d0\n bfun(5) = sval**4 * 1.d0\n bfun(6) = sval**5 * 1.d0\n \n case (+7)\n bfun(1) = 1.d0\n bfun(2) = sval**1 * 1.d0\n bfun(3) = sval**2 * 1.d0\n bfun(4) = sval**3 * 1.d0\n bfun(5) = sval**4 * 1.d0\n bfun(6) = sval**5 * 1.d0\n bfun(7) = sval**6 * 1.d0\n \n end select\n\n case (+1)\n !------------------------------------ +1st-order basis !\n select case (ndof)\n case (+1)\n bfun(1) = 0.d0\n \n case (+2)\n bfun(1) = 0.d0\n bfun(2) = 1.d0\n \n case (+3)\n bfun(1) = 0.d0\n bfun(2) = 1.d0\n bfun(3) = sval**1 * 2.d0\n \n case (+4)\n bfun(1) = 0.d0\n bfun(2) = 1.d0\n bfun(3) = sval**1 * 2.d0\n bfun(4) = sval**2 * 3.d0\n \n case (+5)\n bfun(1) = 0.d0\n bfun(2) = 1.d0\n bfun(3) = sval**1 * 2.d0\n bfun(4) = sval**2 * 3.d0\n bfun(5) = sval**3 * 4.d0\n \n case (+6)\n bfun(1) = 0.d0\n bfun(2) = 1.d0\n bfun(3) = sval**1 * 2.d0\n bfun(4) = sval**2 * 3.d0\n bfun(5) = sval**3 * 4.d0\n bfun(6) = sval**4 * 5.d0\n \n case (+7)\n bfun(1) = 0.d0\n bfun(2) = 1.d0\n bfun(3) = sval**1 * 2.d0\n bfun(4) = sval**2 * 3.d0\n bfun(5) = sval**3 * 4.d0\n bfun(6) = sval**4 * 5.d0\n bfun(7) = sval**5 * 6.d0\n \n end select\n\n case (+2)\n !------------------------------------ +2nd-order basis !\n select case (ndof)\n case (+1)\n bfun(1) = 0.d0\n \n case (+2)\n bfun(1) = 0.d0\n bfun(2) = 0.d0\n \n case (+3)\n bfun(1) = 0.d0\n bfun(2) = 0.d0\n bfun(3) = 2.d0\n \n case (+4)\n bfun(1) = 0.d0\n bfun(2) = 0.d0\n bfun(3) = 2.d0\n bfun(4) = sval**1 * 6.d0\n \n case (+5)\n bfun(1) = 0.d0\n bfun(2) = 0.d0\n bfun(3) = 2.d0\n bfun(4) = sval**1 * 6.d0\n bfun(5) = sval**2 *12.d0\n \n case (+6)\n bfun(1) = 0.d0\n bfun(2) = 0.d0\n bfun(3) = 2.d0\n bfun(4) = sval**1 * 6.d0\n bfun(5) = sval**2 *12.d0\n bfun(6) = sval**3 *20.d0\n \n case (+7)\n bfun(1) = 0.d0\n bfun(2) = 0.d0\n bfun(3) = 2.d0\n bfun(4) = sval**1 * 6.d0\n bfun(5) = sval**2 *12.d0\n bfun(6) = sval**3 *20.d0\n bfun(7) = sval**4 *30.d0\n \n end select\n\n end select\n \n end subroutine\n \n \n \n", "meta": {"hexsha": "8712f0062fb2302aa716c74c17446d8992ec3604", "size": 8381, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/bfun1d.f90", "max_stars_repo_name": "mark-petersen/PPR", "max_stars_repo_head_hexsha": "d5a7ec7d78240d7912176a289f8638a06add1e8d", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2019-01-30T07:04:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T05:22:17.000Z", "max_issues_repo_path": "src/bfun1d.f90", "max_issues_repo_name": "mark-petersen/PPR", "max_issues_repo_head_hexsha": "d5a7ec7d78240d7912176a289f8638a06add1e8d", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-07-02T14:02:02.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-07T17:54:05.000Z", "max_forks_repo_path": "src/bfun1d.f90", "max_forks_repo_name": "mark-petersen/PPR", "max_forks_repo_head_hexsha": "d5a7ec7d78240d7912176a289f8638a06add1e8d", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2017-03-03T08:15:26.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-31T13:48:48.000Z", "avg_line_length": 33.2579365079, "max_line_length": 60, "alphanum_fraction": 0.3470946188, "num_tokens": 2542, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513842182775, "lm_q2_score": 0.7745833789613197, "lm_q1q2_score": 0.6942214255865534}} {"text": "\t!--------------------------------------------------------------------\n\t!\n\t!\n\t! PURPOSE\n\t!\n\t! This program solves nonlinear Schrodinger equation in 2 dimensions\n\t! i*u_t+Es*|u|^2u+u_{xx}+u_{yy}=0\n\t! using a second order time spectral splitting scheme\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! The initial condition is u=exp(-x^2-y^2)\n\t!\n\t! AUTHORS\n\t!\n\t! B. Cloutier, B.K. Muite, P. Rigge\n\t! 4 June 2012\n\t!\n\t! .. Parameters ..\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! Nt\t\t\t\t= number of timesteps to take\n\t! Tmax\t\t\t\t= maximum simulation time\n\t! plotgap\t\t\t= number of timesteps between plots\n\t! FFTW_IN_PLACE \t= value for FFTW input \n\t! FFTW_MEASURE \t= value for FFTW input\n\t! FFTW_EXHAUSTIVE \t= value for FFTW input\n\t! FFTW_PATIENT \t= value for FFTW input \n\t! FFTW_ESTIMATE \t= value for FFTW input\n\t! FFTW_FORWARD = value for FFTW input\n\t! FFTW_BACKWARD\t= value for FFTW input\t\n\t! pi = 3.14159265358979323846264338327950288419716939937510d0\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! ES\t\t\t\t= +1 for focusing and -1 for defocusing\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\t\t\t= loop counter for timesteps direction\t\n\t! allocatestatus\t= error indicator during allocation\n\t! numthreads\t\t= number of openmp threads\n\t! ierr\t\t\t\t= error return code\n\t! start\t\t\t= variable to record start time of program\n\t! finish\t\t\t= variable to record end time of program\n\t! count_rate\t\t= variable for clock count rate\n\t! planfxy\t\t\t= Forward 2d fft plan \n\t! planbxy\t\t\t= Backward 2d fft plan\n\t! dt\t\t\t\t= timestep\n\t! InMass\t\t\t= initial mass\n\t! FiMass\t\t\t= final mass\n\t! InEner\t\t\t= initial energy\n\t! FiEner\t\t\t= final energy\n\t! .. Arrays ..\n\t! u\t\t\t\t= approximate solution\n\t! v\t\t\t\t= Fourier transform of approximate solution\n\t! temp1 \t\t\t= temporary field\n\t! temp2 \t\t\t= temporary field\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! time\t\t\t\t= times at which save data\n\t! name_config\t\t= array to store filename for data to be saved \t\t\n\t!\n\t! REFERENCES\n\t!\n\t! This program is based on example code to demonstrate usage of Fortran and \n\t! CUDA FFT routines taken from \n\t! http://cudamusing.blogspot.com/2010/05/CALLing-cufft-from-cuda-fortran.html\n\t! \n\t! and\n\t!\n\t! http://cudamusing.blogspot.com/search?q=cublas\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! precision\n\t! cufft\n\t!\n\t! External libraries required\n\t! CuFFT\t -- Cuda FFT Library\n\t! OpenACC\n\t\n\t!\n\t! Define the INTERFACE to the NVIDIA CUFFT routines\n\t!\n\n\tmodule precision\n\t! Precision control\n\n\tinteger, parameter, public :: Single = kind(0.0) ! Single precision\n\tinteger, parameter, public :: Double = kind(0.0d0) ! Double precision\n\n\tinteger, parameter, public :: fp_kind = Double\n\t!integer, parameter, public :: fp_kind = Single\n\n\tend module precision\n\n\tmodule cufft\n\n\tinteger, public :: CUFFT_FORWARD = -1\n\tinteger, public :: CUFFT_INVERSE = 1\n\tinteger, public :: CUFFT_R2C = Z'2a' ! Real to Complex (interleaved)\n\tinteger, public :: CUFFT_C2R = Z'2c' ! Complex (interleaved) to Real\n\tinteger, public :: CUFFT_C2C = Z'29' ! Complex to Complex, interleaved\n\tinteger, public :: CUFFT_D2Z = Z'6a' ! Double to Double-Complex\n\tinteger, public :: CUFFT_Z2D = Z'6c' ! Double-Complex to Double\n\tinteger, public :: CUFFT_Z2Z = Z'69' ! Double-Complex to Double-Complex\n\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t!\n\t! cufftPlan2d(cufftHandle *plan, int nx,int ny, cufftType type)\n\t!\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\tinterface cufftPlan2d\n\tsubroutine cufftPlan2d(plan, nx, ny, type) bind(C,name='cufftPlan2d')\n\tuse iso_c_binding\n\tinteger(c_int):: plan\n\tinteger(c_int),value:: nx, ny, type\n\tend subroutine cufftPlan2d\n\tend interface cufftPlan2d\n\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t!\n\t! cufftDestroy(cufftHandle plan)\n\t!\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\tinterface cufftDestroy\n\tsubroutine cufftDestroy(plan) bind(C,name='cufftDestroy')\n\tuse iso_c_binding\n\tinteger(c_int),value:: plan\n\tend subroutine cufftDestroy\n\tend interface cufftDestroy\n\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t!\n\t! cufftExecZ2Z(cufftHandle plan,\n\t! cufftDoubleComplex *idata,\n\t! cufftDoubleComplex *odata,\n\t! int direction;\n\t!\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\tinterface cufftExecZ2Z\n\tsubroutine cufftExecZ2Z(plan, idata, odata, direction) &\n\t& bind(C,name='cufftExecZ2Z')\n\tuse iso_c_binding\n\tuse precision\n\tinteger(c_int),value:: direction\n\tinteger(c_int),value:: plan\n\tcomplex(fp_kind),device,dimension(1:nx,1:ny):: idata,odata\n\tend subroutine cufftExecZ2Z\n\tend interface cufftExecZ2Z\t\n\tend module cufft\n\t\t\n\tPROGRAM main\n\tUSE precision\n\tUSE cufft\t\n\tUSE openacc\n\n\t! Declare variables\n\tIMPLICIT NONE\t\t\t\t\t \n\tINTEGER(kind=4), PARAMETER \t:: Nx=128\n\tINTEGER(kind=4), PARAMETER \t:: Ny=128\t\n\tINTEGER(kind=4), PARAMETER\t:: Nt=20\t\t\n\tINTEGER(kind=4), PARAMETER\t:: plotgap=20\t\n\tREAL(fp_kind), PARAMETER\t\t:: &\n\tpi=3.14159265358979323846264338327950288419716939937510d0\n\tREAL(fp_kind), PARAMETER\t\t:: Lx=5.0d0\t\t\n\tREAL(fp_kind), PARAMETER\t\t:: Ly=5.0d0\t\t\n\tREAL(fp_kind), PARAMETER\t\t:: Es=1.0d0\t\t\n\tREAL(fp_kind)\t\t\t\t\t:: dt=0.10d0**5\n\tREAL(fp_kind)\t\t\t\t\t:: scalemodes\n\tCOMPLEX(fp_kind)\t\t\t\t:: InMass,FiMass,InEner,FiEner \t\t\n\tCOMPLEX(fp_kind), DIMENSION(:), ALLOCATABLE\t\t:: kx\t\t\t\n\tCOMPLEX(fp_kind), DIMENSION(:), ALLOCATABLE\t\t:: ky\t\t\t\n\tREAL(fp_kind), \t DIMENSION(:), ALLOCATABLE\t:: x\t\t\t\n\tREAL(fp_kind), \t DIMENSION(:), ALLOCATABLE\t:: y\t\t\t\n\tCOMPLEX(fp_kind), DIMENSION(:,:), ALLOCATABLE\t:: u,v,temp1,temp2 \n\tREAL(fp_kind), \t DIMENSION(:), ALLOCATABLE\t\t:: time\n\tINTEGER(kind=4)\t\t\t\t:: i,j,k,n,allocatestatus,ierr, vecsize,gangsize\n\tREAL(fp_kind)\t\t\t \t:: start_time,stop_time\n\tINTEGER(kind=4)\t\t\t\t:: plan\n \tCHARACTER*100\t\t\t \t:: name_config\n\t\n\tvecsize=32\n\tgangsize=16\n\tPRINT *,'Program starting'\n\tPRINT *,'Grid: ',Nx,'X',Ny\t\n\t \t\t\t \t\n\tALLOCATE(kx(1:Nx),ky(1:Nx),x(1:Nx),y(1:Nx),u(1:Nx,1:Ny),&\n\t\t\tv(1:Nx,1:Ny),temp1(1:Nx,1:Ny),temp2(1:Nx,1:Ny),&\n\t\t\ttime(1:1+Nt/plotgap),stat=allocatestatus)\t\n\tIF (allocatestatus .ne. 0) stop \n\tPRINT *,'allocated memory'\n\n\t!$acc data copy(InMass,FiMass,InEner,FiEner,kx,ky,x,y,u,v,temp1,temp2,time)\n\t\n\t! set up ffts\n\tCALL cufftPlan2D(plan,nx,ny,CUFFT_Z2Z)\n\tPRINT *,'Setup FFTs'\n\t\t\n\t! setup fourier frequencies\n\t!$acc kernels loop\t\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!$acc end kernels\n\tkx(1+Nx/2)=0.0d0\n\t!$acc kernels loop\t\n\tDO i = 1,Nx/2 -1\n\t\tkx(i+1+Nx/2)=-kx(1-i+Nx/2)\n\tEND DO\n\t!$acc end kernels\n\t!$acc kernels loop\t\n \tDO i=1,Nx\n\t\tx(i)=(-1.0d0+2.0d0*REAL(i-1,kind(0d0))/REAL(Nx,kind(0d0)) )*pi*Lx\n\tEND DO\n\t!$acc end kernels\n\t!$acc kernels loop\t\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!$acc end kernels\n\tky(1+Ny/2)=0.0d0\n\t!$acc kernels loop\t\n\tDO j = 1,Ny/2 -1\n\t\tky(j+1+Ny/2)=-ky(1-j+Ny/2)\n\tEND DO\n\t!$acc end kernels\n\t!$acc kernels loop\t\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!$acc end kernels\n\tscalemodes=1.0d0/REAL(Nx*Ny,kind(0d0))\n\tPRINT *,'Setup grid and fourier frequencies'\n\t!$acc kernels loop\t\n\tDO j=1,Ny\n\t\tDO i=1,Nx\n\t\t\tu(i,j)=exp(-1.0d0*(x(i)**2 +y(j)**2)) \n\t\tEND DO\n\tEND DO\n\t!$acc end kernels\n\t! transform initial data \n\tCALL cufftExecZ2Z(plan,u,v,CUFFT_FORWARD)\n\n\tPRINT *,'Got initial data'\n\t! get initial mass\n\t!$acc kernels loop\t\n\tDO j=1,Ny\n\t\tDO i=1,Nx\n\t\t\ttemp1(i,j)=abs(u(i,j))**2\n\t\tEND DO \n\tEND DO\n\t!$acc end kernels\n\t! Use FFT to get initial mass\n\tCALL cufftExecZ2Z(plan,temp1,temp2,CUFFT_FORWARD)\n\t!$acc end data\n\tInMass=temp2(1,1)\n\t! Get initial energy\n\t!$acc data copy(InMass,FiMass,InEner,FiEner,kx,ky,x,y,u,v,temp1,temp2,time)\n\t!$acc kernels loop\t\n\tDO j=1,Ny\n\t\tDO i=1,Nx\n\t\t\ttemp1(i,j)=-ES*0.25d0*abs(u(i,j))**4\n\t\tEND DO \n\tEND DO\n\t!$acc end kernels\n\t! Use FFT to find mean\n\tCALL cufftExecZ2Z(plan,temp1,temp2,CUFFT_FORWARD)\n\t!$acc end data\n\tInEner=temp2(1,1)\n\t!$acc data copy(InMass,FiMass,InEner,FiEner,kx,ky,x,y,u,v,temp1,temp2,time)\n\t!$acc kernels loop\t\n\tDO j=1,Ny\n\t\tDO i=1,Nx\n\t\t\ttemp2(i,j)=kx(i)*v(i,j)*scalemodes\n\t\tEND DO \n\tEND DO\n\t!$acc end kernels\n\tCALL cufftExecZ2Z(plan,temp2,temp1,CUFFT_INVERSE)\n\t!$acc kernels loop\t\n\tDO j=1,Ny\n\t\tDO i=1,Nx\n\t\t\ttemp2(i,j)=0.5d0*abs(temp1(i,j))**2\n\t\tEND DO \n\tEND DO\n\t!$acc end kernels\n\t! Use FFT to find mean\n\tCALL cufftExecZ2Z(plan,temp2,temp1,CUFFT_FORWARD)\n\t!$acc end data\n\tInEner=InEner+temp1(1,1)\n\t!$acc data copy(InMass,FiMass,InEner,FiEner,kx,ky,x,y,u,v,temp1,temp2,time)\n\t!$acc kernels loop\t\n\tDO j=1,Ny\n\t\tDO i=1,Nx\n\t\t\ttemp2(i,j)=ky(j)*v(i,j)*scalemodes\n\t\tEND DO \n\tEND DO\n\t!$acc end kernels\n\tCALL cufftExecZ2Z(plan,temp2,temp1,CUFFT_INVERSE)\n\t!$acc kernels loop\t\n\tDO j=1,Ny\n\t\tDO i=1,Nx\n\t\t\ttemp2(i,j)=0.5d0*abs(temp1(i,j))**2\n\t\tEND DO \n\tEND DO\n\t!$acc end kernels\n\t! Use FFT to find mean\n\tCALL cufftExecZ2Z(plan,temp2,temp1,CUFFT_FORWARD)\n\t!$acc end data\n\tInEner=InEner+temp1(1,1)\n\t!$acc data copy(InMass,FiMass,InEner,FiEner,kx,ky,x,y,u,v,temp1,temp2,time)\n\tCALL cpu_time(start_time)\n\n\n\t! transform initial data and do first half time step\n\t!$acc kernels loop gang(gangsize), vector(vecsize)\t\n\tDO j=1,Ny\n\t\tDO i=1,Nx\n\t\t\tv(i,j)=exp(0.5d0*dt*(kx(i)*kx(i) + ky(j)*ky(j))&\n\t\t\t\t\t*cmplx(0.0d0,1.0d0))*v(i,j)\n\t\tEND DO\n\tEND DO\n\t!$acc end kernels\n\tPRINT *,'Got initial data, starting timestepping'\n\ttime(1)=0.0d0\n\tDO n=1,Nt\t\t\t\t\t\n\t\tCALL cufftExecZ2Z(plan,v,u,CUFFT_INVERSE)\n\t !$acc kernels loop gang(gangsize), vector(vecsize)\t\t\n\t\tDO j=1,Ny\n\t\t\tDO i=1,Nx\n\t\t\t\tv(i,j)=Es*u(i,j)*conjg(u(i,j))*scalemodes**2\n\t\t\tEND DO\n\t\tEND DO\n\t !$acc end kernels\n\t !$acc kernels loop gang(gangsize), vector(vecsize)\t\n\t\tDO j=1,Ny\n\t\t\tDO i=1,Nx\n\t\t\t\tu(i,j)=exp(cmplx(0.0d0,-1.0d0)*dt*v(i,j))&\n\t\t\t\t\t\t*u(i,j)*scalemodes\n\t\t\tEND DO\n\t\tEND DO\n\t !$acc end kernels\n\t\tCALL cufftExecZ2Z(plan,u,v,CUFFT_FORWARD)\n\t !$acc kernels loop gang(gangsize), vector(vecsize)\t\t\n\t\tDO j=1,Ny\n\t\t\tDO i=1,Nx\n\t\t\t\tv(i,j)=exp(dt*(kx(i)*kx(i) + ky(j)*ky(j))&\t\n\t\t\t\t\t\t*cmplx(0.0d0,1.0d0))*v(i,j)\t\n\t\t\tEND DO\n\t\tEND DO\n\t !$acc end kernels\n\t\tIF (mod(n,plotgap)==0) then\n\t\t\ttime(1+n/plotgap)=n*dt\n\t\t\tPRINT *,'time',n*dt\n\t\tEND IF\n\tEND DO\t\t\t\t\n\t! transform back final data and do another half time step\n\tCALL cufftExecZ2Z(plan,v,u,CUFFT_INVERSE)\n\t!$acc kernels loop gang(gangsize), vector(vecsize)\t\t\n\tDO j=1,Ny\n\t\tDO i=1,Nx\n\t\t\tv(i,j)=Es*u(i,j)*conjg(u(i,j))*scalemodes**2\n\t\tEND DO\n\tEND DO\n\t!$acc end kernels\n\t!$acc kernels loop gang(gangsize), vector(vecsize)\t\n\tDO j=1,Ny\n\t\tDO i=1,Nx\n\t\t\tu(i,j)=exp(cmplx(0,-1)*dt*v(i,j))*u(i,j)*scalemodes\n\t\tEND DO\n\tEND DO\n\t!$acc end kernels\n\tCALL cufftExecZ2Z(plan,u,v,CUFFT_FORWARD)\n\t!$acc kernels loop gang(gangsize), vector(vecsize)\t\n\tDO j=1,Ny\n\t\tDO i=1,Nx\n\t\t\tv(i,j)=exp(0.5d0*dt*(kx(i)*kx(i) + ky(j)*ky(j))&\n\t\t\t\t\t*cmplx(0.0d0,1.0d0))*v(i,j)\n\t\tEND DO\t\t\n\tEND DO\n\t!$acc end kernels\n\tCALL cufftExecZ2Z(plan,v,u,CUFFT_INVERSE)\n\t!$acc kernels loop gang(gangsize), vector(vecsize)\t\t\n\tDO j=1,Ny\n\t\tDO i=1,Nx\n\t\t\tu(i,j)=u(i,j)*scalemodes\n\t\tEND DO\n\tEND DO\t\n\t!$acc end kernels\n\tPRINT *,'Finished time stepping'\n\tCALL cpu_time(stop_time)\n\t!$acc end data\n\tPRINT*,'Program took ',stop_time-start_time,&\n\t\t'for Time stepping'\n\t!$acc data copy(InMass,FiMass,InEner,FiEner,kx,ky,x,y,u,v,temp1,temp2,time)\n\n\t! calculate final mass\n\t!$acc kernels loop\t\n\tDO j=1,Ny\n\t\tDO i=1,Nx\n\t\t\ttemp1(i,j)=abs(u(i,j))**2\n\t\tEND DO \n\tEND DO\n\t!$acc end kernels\n\t! Use FFT to get initial mass\n\tCALL cufftExecZ2Z(plan,temp1,temp2,CUFFT_FORWARD)\n\t!$acc end data\n\tFiMass=temp2(1,1)\n\n\n\t! Get final energy\n\t!$acc data copy(InMass,FiMass,InEner,FiEner,kx,ky,x,y,u,v,temp1,temp2,time)\n\t!$acc kernels loop\t\n\tDO j=1,Ny\n\t\tDO i=1,Nx\n\t\t\ttemp1(i,j)=-ES*0.25d0*abs(u(i,j))**4\n\t\tEND DO \n\tEND DO\n\t!$acc end kernels\n\t! Use FFT to find mean\n\tCALL cufftExecZ2Z(plan,temp1,temp2,CUFFT_FORWARD)\n\t!$acc end data\n\tFiEner=temp2(1,1)\n\t!$acc data copy(InMass,FiMass,InEner,FiEner,kx,ky,x,y,u,v,temp1,temp2,time)\n\t!$acc kernels loop\t\n\tDO j=1,Ny\n\t\tDO i=1,Nx\n\t\t\ttemp2(i,j)=kx(i)*v(i,j)*scalemodes\n\t\tEND DO \n\tEND DO\n\t!$acc end kernels\n\tCALL cufftExecZ2Z(plan,temp2,temp1,CUFFT_INVERSE)\n\t!$acc kernels loop\t\n\tDO j=1,Ny\n\t\tDO i=1,Nx\n\t\t\ttemp2(i,j)=0.5d0*abs(temp1(i,j))**2\n\t\tEND DO \n\tEND DO\n\t!$acc end kernels\n\t! Use FFT to find mean\n\tCALL cufftExecZ2Z(plan,temp2,temp1,CUFFT_FORWARD)\n\t!$acc end data\n\tFiEner=FiEner+temp1(1,1)\n\t!$acc data copy(InMass,FiMass,InEner,FiEner,kx,ky,x,y,u,v,temp1,temp2,time)\n\t!$acc kernels loop\t\n\tDO j=1,Ny\n\t\tDO i=1,Nx\n\t\t\ttemp2(i,j)=ky(j)*v(i,j)*scalemodes\n\t\tEND DO \n\tEND DO\n\t!$acc end kernels\n\tCALL cufftExecZ2Z(plan,temp2,temp1,CUFFT_INVERSE)\n\t!$acc kernels loop\t\n\tDO j=1,Ny\n\t\tDO i=1,Nx\n\t\t\ttemp2(i,j)=0.5d0*abs(temp1(i,j))**2\n\t\tEND DO \n\tEND DO\n\t!$acc end kernels\n\t! Use FFT to find mean\n\tCALL cufftExecZ2Z(plan,temp2,temp1,CUFFT_FORWARD)\n\t!$acc end data\n\tFiEner=FiEner+temp1(1,1)\n\t\n \tPRINT *,'Results copied back to host'\n\tPRINT*,'Initial mass',InMass\n\tPRINT*,'Final mass',FiMass\n\tPRINT*,'Final Mass/Initial Mass', &\n\t ABS(REAL(FiMass,kind(0d0))/REAL(InMass,kind(0d0)))\n\tPRINT*,'Initial energy',InEner\n\tPRINT*,'Final energy',FiEner\n\tPRINT*,'Final Energy/Initial Energy', &\n\t ABS(REAL(FiEner,kind(0d0))/REAL(InEner,kind(0d0)))\n\n\tname_config = 'ufinal.dat' \n\tOPEN(unit=11,FILE=name_config,status=\"UNKNOWN\") \t\n\tREWIND(11)\n\tDO j=1,Ny\n\t\tDO i=1,Nx\n\t\t\tWRITE(11,*) abs(u(i,j))**2\n\t\tEND DO\n\tEND DO\n\tCLOSE(11)\n\t\t\n\tname_config = 'tdata.dat' \n\tOPEN(unit=11,FILE=name_config,status=\"UNKNOWN\") \t\n\tREWIND(11)\n\tDO j=1,1+Nt/plotgap\n\t\tWRITE(11,*) time(j)\n\tEND DO\n\tCLOSE(11)\n\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\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\tPRINT *,'Saved data'\n\n\tCALL cufftDestroy(plan)\n\n\tDEALLOCATE(u,v,temp1,temp2,time,kx,ky,x,y,stat=allocatestatus)\t\n\tIF (allocatestatus .ne. 0) STOP \n\tPRINT *,'Deallocated memory'\n\t\t\n \tPRINT *,'Program execution complete'\n\tEND PROGRAM main\n", "meta": {"hexsha": "8a1a14f619211f27a2ece0ae7226a98f5435e598", "size": 14381, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "SingleGPU/Programs/NLS/GPUacc/cubicNLS.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": "SingleGPU/Programs/NLS/GPUacc/cubicNLS.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": "SingleGPU/Programs/NLS/GPUacc/cubicNLS.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": 27.0319548872, "max_line_length": 78, "alphanum_fraction": 0.6484945414, "num_tokens": 5583, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513759047847, "lm_q2_score": 0.7745833841649232, "lm_q1q2_score": 0.6942214238107969}} {"text": "! **\n! * Provides the cumulative distribution function (CDF) of the normal distribution\n! **\nmodule normal_cdf\n use kinds, only: dp\n implicit none\n private\n public :: cdf_normal\n\n contains\n\n ! **\n ! * Returns the value of the normal cumulative distribution function for a given x.\n ! *\n ! * Input:\n ! * - x: the x, at which the CDF is evaluated\n ! *\n ! * Return value: the value of the CDF of the normal distribution at x\n ! **\n real(dp) function cdf_normal(x)\n real(dp), intent(in) :: x\n real(dp) ::q,pdf\n\n call nprob(x,cdf_normal, q, pdf)\n end function cdf_normal\n\n subroutine nprob(z,p,q,pdf)\n real(dp), intent(in) :: z\n real(dp), intent(out) :: p,q,pdf\n real(dp) :: a0,a1,a2,a3,a4,a5,a6,a7,b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11\n real(dp) :: y, zabs\n ! Reference: Adams,A.G. Areas under the normal curve,\n ! Algorithm 39, Computer J., Vol. 12, 197-8, 1969.\n !\n ! Latest Revision - 23 January 1981\n ! Obtained from: http://lib.stat.cmu.edu/apstat/\n ! April 10, 2013: modified by Carlo Zanella:\n ! - adapted to the variable naming of this program\n ! - explicit variable declarations\n ! - specified intents of dummy arguments\n !\n\n data a0,a1,a2,a3,a4,a5,a6,a7/0.5d0, 0.398942280444d0, &\n 0.399903438504d0, 5.75885480458d0, 29.8213557808d0, &\n 2.62433121679d0, 48.6959930692d0, 5.92885724438d0/, &\n b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11/0.398942280385d0, &\n 3.8052d-8, 1.00000615302d0, 3.98064794d-4, 1.98615381364d0, &\n 0.151679116635d0, 5.29330324926d0, 4.8385912808d0, &\n 15.1508972451d0, 0.742380924027d0, 30.789933034d0, &\n 3.99019417011d0/\n !\n zabs = abs(z)\n if(zabs.gt.12.7d0) go to 20\n y = a0*z*z\n pdf = exp(-y)*b0\n if(zabs.gt.1.28d0) go to 10\n !\n ! z between -1.28 and +1.28\n !\n q = a0-zabs*(a1-a2*y/(y+a3-a4/(y+a5+a6/(y+a7))))\n if(z.lt.0.d0) go to 30\n p = 1.d0-q\n return\n !\n ! zabs between 1.28 and 12.7\n !\n 10 q = pdf/(zabs-b1+b2/(zabs+b3+b4/(zabs-b5+b6/(zabs+b7-b8/(zabs+b9+b10/(zabs+b11))))))\n if(z.lt.0.d0) go to 30\n p = 1.d0-q\n return\n !\n ! z far out in tail\n !\n 20 q = 0.d0\n pdf = 0.d0\n if(z.lt.0.d0) go to 30\n p = 1.d0\n return\n !\n ! negative z, interchange p and q\n !\n 30 p = q\n q = 1.d0-p\n return\n end subroutine nprob\n\nend module normal_cdf\n", "meta": {"hexsha": "214ec1af1044c22d9d38fcec3ed177557ebd3b71", "size": 2969, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "normal_cdf.f90", "max_stars_repo_name": "carlozanella/ncegm", "max_stars_repo_head_hexsha": "29c6846946bcdc8d527a4ff7a0bfb3ddee0c8bf8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-03-14T23:31:35.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-14T23:31:35.000Z", "max_issues_repo_path": "normal_cdf.f90", "max_issues_repo_name": "carlozanella/ncegm", "max_issues_repo_head_hexsha": "29c6846946bcdc8d527a4ff7a0bfb3ddee0c8bf8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "normal_cdf.f90", "max_forks_repo_name": "carlozanella/ncegm", "max_forks_repo_head_hexsha": "29c6846946bcdc8d527a4ff7a0bfb3ddee0c8bf8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.7386363636, "max_line_length": 99, "alphanum_fraction": 0.4819804648, "num_tokens": 972, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513648201266, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.694221415224805}} {"text": " program DRSSVA\nc>> 1996-06-27 DRSSVA Krogh Special code for C conversion.\nc>> 1996-05-28 DRSSVA Krogh Removed implicit statement.\nc>> 1994-10-19 DRSSVA Krogh Changes to use M77CON\nc>> 1989-03-07 DRSSVA CLL\nc Demo driver for SSVA, Singular Value Analysis.\nc\nc Mar 1987, C. L. Lawson & S. Y. Chiu, JPL. This sample problem\nc taken from the book, Solving Least Squares Problems,\nc Prentice-Hall, 1974, by C. L. Lawson and R. J. Hanson.\nc ------------------------------------------------------------------\nc--S replaces \"?\": DR?SVA, ?SVA\nc ------------------------------------------------------------------\n integer I, J, KPVEC(4), M, MDATA, MMAX, N, NMAX, NMAX2\n parameter(MMAX = 15, NMAX = 5, NMAX2 = NMAX*2)\n real A(MMAX,NMAX), B(MMAX), SING(NMAX)\n real D(NMAX), WORK(NMAX2)\n character*6 NAMES(NMAX)\nc\n data ((A(I,J),J=1,5),I=1,15) /\n *-.13405547E0,-.20162827E0,-.16930778E0,-.18971990E0,-.17387234E0,\n *-.10379475E0,-.15766336E0,-.13346256E0,-.14848550E0,-.13597690E0,\n *-.08779597E0,-.12883867E0,-.10683007E0,-.12011796E0,-.10932972E0,\n * .02058554E0, .00335331E0,-.01641270E0, .00078606E0, .00271659E0,\n *-.03248093E0,-.01876799E0, .00410639E0,-.01405894E0,-.01384391E0,\n * .05967662E0, .06667714E0, .04352153E0, .05740438E0, .05024962E0,\n * .06712457E0, .07352437E0, .04489770E0, .06471862E0, .05876455E0,\n * .08687186E0, .09368296E0, .05672327E0, .08141043E0, .07302320E0,\n * .02149662E0, .06222662E0, .07213486E0, .06200069E0, .05570931E0,\n * .06687407E0, .10344506E0, .09153849E0, .09508223E0, .08393667E0,\n * .15879069E0, .18088339E0, .11540692E0, .16160727E0, .14796479E0,\n * .17642887E0, .20361830E0, .13057860E0, .18385729E0, .17005549E0,\n * .11414080E0, .17259611E0, .14816471E0, .16007466E0, .14374096E0,\n * .07846038E0, .14669563E0, .14365800E0, .14003842E0, .12571177E0,\n * .10803175E0, .16994623E0, .14971519E0, .15885312E0, .14301547E0 /\nc\n data (B(I),I=1,15) /\n *-.4361E0, -.3437E0, -.2657E0, -.0392E0, .0193E0, .0747E0,\n * .0935E0, .1079E0, .1930E0, .2058E0, .2606E0, .3142E0,\n * .3529E0, .3615E0, .3647E0 /\nc\n data NAMES /'Earth ', 'Water ', 'Air ', 'Fire ', 'Time '/\n data KPVEC / 1, 111111, -1, 76/\nc ------------------------------------------------------------------\nc\n M = MMAX\n N = NMAX\n MDATA = M\n print '('' DRSSVA.. Demonstrate Singular Value Analysis''/\n * '' Listing of input matrix, A, and vector, B, follows..'')'\nc++ Code for ~.C. is active\n print '(/(5F12.7,F13.4))',\n * ((A(I,J),J=1,N),B(I),I=1,M)\nc++ Code for .C. is inactive\nc%% for (i = 1; i <= m; i++){\nc%% printf( \"\\n\" );\nc%% for (j = 1; j <= n; j++)\nc%% printf( \"%12.7f\", a[j - 1][i - 1] );\nc%% printf( \"%13.4f\", B[i] );}\nc%% fprintf( stdout, \" \\n\\n\\n \\n\" );\nc++ End\n print '(1X///1X)'\nc\n call SSVA(A, MMAX, M, N, MDATA, B, SING, KPVEC, NAMES, 1, D, WORK)\nc\n stop\n end\n", "meta": {"hexsha": "82c4a41ea363f41fce9e38b9446e77137972a72c", "size": 3039, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drssva.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drssva.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drssva.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": 44.6911764706, "max_line_length": 72, "alphanum_fraction": 0.5534715367, "num_tokens": 1283, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.839733983715524, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.6942179918047876}} {"text": "MODULE class_Circle\n IMPLICIT NONE\n PRIVATE\n REAL :: pi = 3.1415926535897931d0 ! Class-wide private constant\n\n TYPE, PUBLIC :: Circle\n REAL :: radius\n CONTAINS\n PROCEDURE :: area => circle_area\n PROCEDURE :: PRINT => circle_print\n END TYPE Circle\nCONTAINS\n FUNCTION circle_area(this) RESULT(area)\n CLASS(Circle), INTENT(in) :: this\n REAL :: area\n area = pi * this%radius**2\n END FUNCTION circle_area\n\n SUBROUTINE circle_print(this)\n CLASS(Circle), INTENT(in) :: this\n REAL :: area\n area = this%area() ! Call the type-bound function\n PRINT *, 'Circle: r = ', this%radius, ' area = ', area\n END SUBROUTINE circle_print\nEND MODULE class_Circle\n\n\nPROGRAM circle_test\n USE class_Circle\n IMPLICIT NONE\n\n TYPE(Circle) :: c ! Declare a variable of type Circle.\n c = Circle(1.5) ! Use the implicit constructor, radius = 1.5.\n CALL c%PRINT ! Call the type-bound subroutine\nEND PROGRAM circle_test\n", "meta": {"hexsha": "e946f3a87e7b1da2bc2bdf9cf3815b42c6152b7a", "size": 956, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "doc/Programs/OOExamples/Fortran/circle.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/OOExamples/Fortran/circle.f90", "max_issues_repo_name": "dnhdang94/ComputationalPhysicsMSU", "max_issues_repo_head_hexsha": "16990c74cf06eb5b933982137f0536d669567259", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-12-04T12:55:10.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-04T12:55:10.000Z", "max_forks_repo_path": "doc/Programs/OOExamples/Fortran/circle.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.5555555556, "max_line_length": 69, "alphanum_fraction": 0.6757322176, "num_tokens": 265, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722392, "lm_q2_score": 0.8267118026095991, "lm_q1q2_score": 0.6942179821268276}} {"text": "module triangle_m\n implicit none\n private\n public :: triangle_t\n\n type :: triangle_t\n private\n real :: height_, width_\n contains\n procedure :: area\n end type\n\n interface triangle_t\n module procedure construct\n end interface\ncontains\n pure function construct(height, width) result(triangle)\n real, intent(in) :: height, width\n type(triangle_t) :: triangle\n\n triangle%height_ = height\n triangle%width_ = width\n end function\n\n pure function area(self)\n class(triangle_t), intent(in) :: self\n real :: area\n\n area = 0.5 * self%height_ * self%width_\n end function\nend module\n", "meta": {"hexsha": "e4477bfe9403823be0179d468677fa55be4dcc84", "size": 682, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/custom_types/triangle_m.f90", "max_stars_repo_name": "everythingfunctional/rojff", "max_stars_repo_head_hexsha": "366f70cf2d197516ebcbddcd94e953f5268532c9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "example/custom_types/triangle_m.f90", "max_issues_repo_name": "everythingfunctional/rojff", "max_issues_repo_head_hexsha": "366f70cf2d197516ebcbddcd94e953f5268532c9", "max_issues_repo_licenses": ["MIT"], "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/custom_types/triangle_m.f90", "max_forks_repo_name": "everythingfunctional/rojff", "max_forks_repo_head_hexsha": "366f70cf2d197516ebcbddcd94e953f5268532c9", "max_forks_repo_licenses": ["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.3125, "max_line_length": 59, "alphanum_fraction": 0.6217008798, "num_tokens": 160, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339756938819, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.6942179797953818}} {"text": "*\n* Call with many array references\n*\n SUBROUTINE RESID(U,V,R,N,A)\n INTEGER N\n REAL*8 U(N,N,N),V(N,N,N),R(N,N,N),A(0:3)\n INTEGER I3, I2, I1\nC\n DO 600 I3=2,N-1\n DO 600 I2=2,N-1\n DO 600 I1=2,N-1\n R(I1,I2,I3)=V(I1,I2,I3)\n > -A(0)*( U(I1, I2, I3 ) )\n > -A(1)*( U(I1-1,I2, I3 ) + U(I1+1,I2, I3 )\n > + U(I1, I2-1,I3 ) + U(I1, I2+1,I3 )\n > + U(I1, I2, I3-1) + U(I1, I2, I3+1) )\n > -A(2)*( U(I1-1,I2-1,I3 ) + U(I1+1,I2-1,I3 )\n > + U(I1-1,I2+1,I3 ) + U(I1+1,I2+1,I3 )\n > + U(I1, I2-1,I3-1) + U(I1, I2+1,I3-1)\n > + U(I1, I2-1,I3+1) + U(I1, I2+1,I3+1)\n > + U(I1-1,I2, I3-1) + U(I1-1,I2, I3+1)\n > + U(I1+1,I2, I3-1) + U(I1+1,I2, I3+1) )\n > -A(3)*( U(I1-1,I2-1,I3-1) + U(I1+1,I2-1,I3-1)\n > + U(I1-1,I2+1,I3-1) + U(I1+1,I2+1,I3-1)\n > + U(I1-1,I2-1,I3+1) + U(I1+1,I2-1,I3+1)\n > + U(I1-1,I2+1,I3+1) + U(I1+1,I2+1,I3+1) )\n\n 600 CONTINUE\nC\nC\n RETURN\n END\n", "meta": {"hexsha": "0b2f685d2f18630830866de0b6e1e030bc363dc8", "size": 1164, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "packages/PIPS/validation/ArrayBoundCheck/TD_Call01.f", "max_stars_repo_name": "DVSR1966/par4all", "max_stars_repo_head_hexsha": "86b33ca9da736e832b568c5637a2381f360f1996", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 51, "max_stars_repo_stars_event_min_datetime": "2015-01-31T01:51:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T02:01:50.000Z", "max_issues_repo_path": "packages/PIPS/validation/ArrayBoundCheck/TD_Call01.f", "max_issues_repo_name": "DVSR1966/par4all", "max_issues_repo_head_hexsha": "86b33ca9da736e832b568c5637a2381f360f1996", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2017-05-29T09:29:00.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-11T16:01:39.000Z", "max_forks_repo_path": "packages/PIPS/validation/ArrayBoundCheck/TD_Call01.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": 35.2727272727, "max_line_length": 65, "alphanum_fraction": 0.3487972509, "num_tokens": 600, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.6942179785416148}} {"text": "module UtilitiesM\n!!$ Intrinsic standart iso_fortran Real types REAL32, REAL64, REAL128\n use, intrinsic :: iso_fortran_env\n implicit none\n\n public :: isp, idp, iqp, ikind, rsp, rdp, rqp, rkind!, debugger\n \n integer, parameter :: isp = int16\n integer, parameter :: idp = int32\n integer, parameter :: iqp = int64\n integer, parameter :: rsp = REAL32\n integer, parameter :: rdp = REAL64\n integer, parameter :: rqp = REAL128\n integer, parameter :: ikind = idp\n integer, parameter :: rkind = rdp\n \n interface assignAnyTypeToR8\n procedure assignAnyTypeToR8Scalar\n procedure assignAnyTypeToR8Array\n end interface assignAnyTypeToR8\n \ncontains\n \n subroutine assignAnyTypeToR8Scalar(output,input)\n implicit none\n real(rkind), intent(out) :: output\n class(*), intent(in) :: input\n select type(input)\n type is(integer)\n output=input\n type is(real(rsp))\n output=input\n type is(real(rdp))\n output=input\n type is(real(rqp))\n output=input\n type is(character(*))\n write(*,*) 'Wrong type of argument input!'\n stop\n end select\n end subroutine assignAnyTypeToR8Scalar\n\n subroutine assignAnyTypeToR8Array(output,input)\n implicit none\n real(rkind), intent(out), dimension(:) :: output\n class(*), intent(in), dimension(:) :: input\n select type(input)\n type is(integer)\n output=input\n type is(real(rsp))\n output=input\n type is(real(rdp))\n output=input\n type is(real(rqp))\n output=input\n type is(character(*))\n write(*,*) 'Wrong type of argument input!'\n stop\n end select\n end subroutine assignAnyTypeToR8Array\n\n pure function matinv2(A) result(B)\n !! Performs a direct calculation of the inverse of a 2\u00d72 matrix.\n real(rkind), intent(in) :: A(2,2) !! Matrix\n real(rkind) :: B(2,2) !! Inverse matrix\n real(rkind) :: detinv\n\n ! Calculate the inverse determinant of the matrix\n detinv = 1/(A(1,1)*A(2,2) - A(1,2)*A(2,1))\n\n ! Calculate the inverse of the matrix\n B(1,1) = +detinv * A(2,2)\n B(2,1) = -detinv * A(2,1)\n B(1,2) = -detinv * A(1,2)\n B(2,2) = +detinv * A(1,1)\n end function\n\n pure function matinv3(A) result(B)\n !! Performs a direct calculation of the inverse of a 3\u00d73 matrix.\n real(rkind), intent(in) :: A(3,3) !! Matrix\n real(rkind) :: B(3,3) !! Inverse matrix\n real(rkind) :: 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\n\n pure function matinv4(A) result(B)\n !! Performs a direct calculation of the inverse of a 4\u00d74 matrix.\n real(rkind), intent(in) :: A(4,4) !! Matrix\n real(rkind) :: B(4,4) !! Inverse matrix\n real(rkind) :: detinv\n\n ! Calculate the inverse determinant of the matrix\n detinv = &\n 1/(A(1,1)*(A(2,2)*(A(3,3)*A(4,4)-A(3,4)*A(4,3))+A(2,3)*(A(3,4)*A(4,2)-A(3,2)*A(4,4))+A(2,4)*(A(3,2)*A(4,3)-A(3,3)*A(4,2)))&\n - A(1,2)*(A(2,1)*(A(3,3)*A(4,4)-A(3,4)*A(4,3))+A(2,3)*(A(3,4)*A(4,1)-A(3,1)*A(4,4))+A(2,4)*(A(3,1)*A(4,3)-A(3,3)*A(4,1)))&\n + A(1,3)*(A(2,1)*(A(3,2)*A(4,4)-A(3,4)*A(4,2))+A(2,2)*(A(3,4)*A(4,1)-A(3,1)*A(4,4))+A(2,4)*(A(3,1)*A(4,2)-A(3,2)*A(4,1)))&\n - A(1,4)*(A(2,1)*(A(3,2)*A(4,3)-A(3,3)*A(4,2))+A(2,2)*(A(3,3)*A(4,1)-A(3,1)*A(4,3))+A(2,3)*(A(3,1)*A(4,2)-A(3,2)*A(4,1))))\n\n ! Calculate the inverse of the matrix\n B(1,1) = detinv*(A(2,2)*(A(3,3)*A(4,4)-A(3,4)*A(4,3))+A(2,3)*(A(3,4)*A(4,2)-A(3,2)*A(4,4))+A(2,4)*(A(3,2)*A(4,3)-A(3,3)*A(4,2)))\n B(2,1) = detinv*(A(2,1)*(A(3,4)*A(4,3)-A(3,3)*A(4,4))+A(2,3)*(A(3,1)*A(4,4)-A(3,4)*A(4,1))+A(2,4)*(A(3,3)*A(4,1)-A(3,1)*A(4,3)))\n B(3,1) = detinv*(A(2,1)*(A(3,2)*A(4,4)-A(3,4)*A(4,2))+A(2,2)*(A(3,4)*A(4,1)-A(3,1)*A(4,4))+A(2,4)*(A(3,1)*A(4,2)-A(3,2)*A(4,1)))\n B(4,1) = detinv*(A(2,1)*(A(3,3)*A(4,2)-A(3,2)*A(4,3))+A(2,2)*(A(3,1)*A(4,3)-A(3,3)*A(4,1))+A(2,3)*(A(3,2)*A(4,1)-A(3,1)*A(4,2)))\n B(1,2) = detinv*(A(1,2)*(A(3,4)*A(4,3)-A(3,3)*A(4,4))+A(1,3)*(A(3,2)*A(4,4)-A(3,4)*A(4,2))+A(1,4)*(A(3,3)*A(4,2)-A(3,2)*A(4,3)))\n B(2,2) = detinv*(A(1,1)*(A(3,3)*A(4,4)-A(3,4)*A(4,3))+A(1,3)*(A(3,4)*A(4,1)-A(3,1)*A(4,4))+A(1,4)*(A(3,1)*A(4,3)-A(3,3)*A(4,1)))\n B(3,2) = detinv*(A(1,1)*(A(3,4)*A(4,2)-A(3,2)*A(4,4))+A(1,2)*(A(3,1)*A(4,4)-A(3,4)*A(4,1))+A(1,4)*(A(3,2)*A(4,1)-A(3,1)*A(4,2)))\n B(4,2) = detinv*(A(1,1)*(A(3,2)*A(4,3)-A(3,3)*A(4,2))+A(1,2)*(A(3,3)*A(4,1)-A(3,1)*A(4,3))+A(1,3)*(A(3,1)*A(4,2)-A(3,2)*A(4,1)))\n B(1,3) = detinv*(A(1,2)*(A(2,3)*A(4,4)-A(2,4)*A(4,3))+A(1,3)*(A(2,4)*A(4,2)-A(2,2)*A(4,4))+A(1,4)*(A(2,2)*A(4,3)-A(2,3)*A(4,2)))\n B(2,3) = detinv*(A(1,1)*(A(2,4)*A(4,3)-A(2,3)*A(4,4))+A(1,3)*(A(2,1)*A(4,4)-A(2,4)*A(4,1))+A(1,4)*(A(2,3)*A(4,1)-A(2,1)*A(4,3)))\n B(3,3) = detinv*(A(1,1)*(A(2,2)*A(4,4)-A(2,4)*A(4,2))+A(1,2)*(A(2,4)*A(4,1)-A(2,1)*A(4,4))+A(1,4)*(A(2,1)*A(4,2)-A(2,2)*A(4,1)))\n B(4,3) = detinv*(A(1,1)*(A(2,3)*A(4,2)-A(2,2)*A(4,3))+A(1,2)*(A(2,1)*A(4,3)-A(2,3)*A(4,1))+A(1,3)*(A(2,2)*A(4,1)-A(2,1)*A(4,2)))\n B(1,4) = detinv*(A(1,2)*(A(2,4)*A(3,3)-A(2,3)*A(3,4))+A(1,3)*(A(2,2)*A(3,4)-A(2,4)*A(3,2))+A(1,4)*(A(2,3)*A(3,2)-A(2,2)*A(3,3)))\n B(2,4) = detinv*(A(1,1)*(A(2,3)*A(3,4)-A(2,4)*A(3,3))+A(1,3)*(A(2,4)*A(3,1)-A(2,1)*A(3,4))+A(1,4)*(A(2,1)*A(3,3)-A(2,3)*A(3,1)))\n B(3,4) = detinv*(A(1,1)*(A(2,4)*A(3,2)-A(2,2)*A(3,4))+A(1,2)*(A(2,1)*A(3,4)-A(2,4)*A(3,1))+A(1,4)*(A(2,2)*A(3,1)-A(2,1)*A(3,2)))\n B(4,4) = detinv*(A(1,1)*(A(2,2)*A(3,3)-A(2,3)*A(3,2))+A(1,2)*(A(2,3)*A(3,1)-A(2,1)*A(3,3))+A(1,3)*(A(2,1)*A(3,2)-A(2,2)*A(3,1)))\n end function\n \nend module UtilitiesM\n", "meta": {"hexsha": "62a083aa65ad7b09d422c7aa13682e28fbb7dcd9", "size": 6277, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/lib/Utilities.f90", "max_stars_repo_name": "ponfo/Project790", "max_stars_repo_head_hexsha": "abcfcc4945024bd6bd5832bc3ef3d4e1b0df3b91", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-07-13T23:33:40.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-23T22:25:21.000Z", "max_issues_repo_path": "src/lib/Utilities.f90", "max_issues_repo_name": "ponfo/Project790", "max_issues_repo_head_hexsha": "abcfcc4945024bd6bd5832bc3ef3d4e1b0df3b91", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-03-29T03:14:16.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T03:14:16.000Z", "max_forks_repo_path": "src/lib/Utilities.f90", "max_forks_repo_name": "ponfo/Project790", "max_forks_repo_head_hexsha": "abcfcc4945024bd6bd5832bc3ef3d4e1b0df3b91", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-12-19T08:02:30.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T10:45:13.000Z", "avg_line_length": 46.8432835821, "max_line_length": 132, "alphanum_fraction": 0.5043810738, "num_tokens": 3330, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339756938818, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.6942179762101686}} {"text": "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! This module contains code for constructing Legendre quadratures and evaluating\n! Legendre polynomials. \n!\n! The following routines should be regarded as public:\n!\n! legequad - return the nodes and weights of the n-point Legendre quadrature\n! on the interval [-1,1]\n!\n! legeexps - return the nodes and weights of the n-point Legendre quadrature\n! on the interval [-1,1] as well as the matrix which maps the scaled\n! values of Legendre expansions to their coefficients\n!\n! leges - evaluate the Legendre polynomials of degrees 0 through n as well \n! as their derivatives at a specified point in the interval [-1,1]\n!\n! leges0 - evaluate the Legendre polynomials of degrees 0 through n and \n! at a specified point in the interval [-1,1]\n!\n! lege - evaluate a Legendre polynomial of degree n and its derivative at \n! a specified point on the interval [-1,1]\n!\n! lege0 - evaluate a Legendre polynomial of degree n at a specified\n! point on the interval [-1,1]\n!\n! legeeval - evaluate a Legendre expansion and its derivative at a \n! specified point\n!\n! legeeval0 - evaluate a Legendre expansion at a specified point\n!\n! legediff - return the spectral differentiation matrix which takes\n! the scaled values of an n-term Legendre expansion at the\n! Legendre nodes to the scaled values of its derivative at the\n! Legendre nodes\n!\n! legeint - return the spectral integration matrix which takes the\n! scaled values of an n-term Legendre expansion at the nodes of\n! the n-point Legnedre quadrature to the scaled values of its\n! antiderivative at those same nodes\n!\n! legeq - evaluate the Legendre function of the second kind at a\n! user-specified point in the complex plane\n!\n! legen - evaluate the normalized Legendre polynomials of degrees 0 through n\n! at a user-specified point in the interval [-1,1]\n!\n! lege_stieltjes - evaluate P_\\nu(\\cos(\\theta)) on the interval (1/nu, \\pi/2)\n! using Stieltjes' asymptoptic formula\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\nmodule legendre\n\nuse utils\n\ncontains\n\n\nsubroutine legequad(n,xs,whts)\nimplicit double precision (a-h,o-z)\n!\ndouble precision, allocatable, intent(out) :: xs(:),whts(:)\ninteger n\n!\n! Return the nodes and weights of the n-point Legendre quadrature on the interval\n! [-1,1]. This quadrature integrates polynomials of degree less than or equal\n! to 2n-1 exactly.\n!\n! An O(n^2) algorithm is used to construct the quadrature formula when n is small\n! and the GLR algorithm is used when n is larger.\n!\n! Input parameters:\n!\n! n - an integer specifying the number of points to\n!\n! Output parameters:\n!\n! xs - upon return, a vector of length n specifying the nodes of the n-point\n! Legendre quadrature\n! whts - upon return, a of length n specifying the nodes of n-point\n! Legendre quadrature\n!\n\n\ndouble precision pols(n+1)\nallocate(xs(n),whts(n))\n\n\n\nmaxiters = 10\npi = acos(-1.0d0)\n\n!\n! Obtain machine zero.\n!\n\ncall mach_zero(eps0)\n\nif ( n .gt. 150) then\ncall legequad2(n,xs,whts)\nreturn\nendif\n\n!\n! Use Newton's method and the recurrence relation to find half of the\n! roots --- the others are obtained via symmetry.\n!\n! Note that we also store the value of the derivative at each of the obtained\n! roots for use in computing the weights below.\n!\nifodd = 0\nnn = (n+1)/2\nif (nn /= n/2) then\nifodd=1\nnn=nn-1\nendif\n\n!\n! Use Tricomi's formula to estimate the roots of P_{n+1}\n!\n\ndo i =nn+1,n\n dk = i-nn-1\n dn = n\n theta = (4*(ceiling(dn/2)-dk)-1) / (4*dn+2) * pi\n x0 = 1.0d0 - (dn-1)/(8*dn**3)-1.0d0/(384.0d0*dn**4)* &\n (39.0d0-28.0d0/sin(theta)**2)\n xs(i)=x0*cos(theta)\nenddo\n\n!\n! Perform Newton iterations in order to refine the estimates.\n!\ndo iter = 1,maxiters\n\n!\n! Evaluate the Legendre polynomial of degree n at each point; save\n! the values of the derivative in the whts array.\n!\ndo i=nn+1,n\ncall lege(n,xs(i),pols(i),whts(i))\nend do\n\n!\n! Perform one Newton iteration\n!\npols(nn+1:n) = pols(nn+1:n)/whts(nn+1:n)\nxs(nn+1:n) = xs(nn+1:n) - pols(nn+1:n)\n\nif(norm2(pols(nn+1:n)) < eps0) then\nexit\nendif\n\nend do\n\nif (iter == maxiters) then\nprint *,\"legequad failed!\"\nstop\nend if\n\n!\n! Compute the weights using the derivatives we stored above.\n!\ndo j=nn+1,n\n x = xs(j)\n dd = 2.0d0/(1.0d0-x**2)\n whts(j) = dd/(whts(j)**2)\nend do\n\n!\n! Reflect the quadrature nodes.\n!\ndo j=1,nn\nxs(j) = -xs(n-j+1)\nwhts(j) = whts(n-j+1)\nend do\n\n!\n! Handle the root at 0 if n is odd.\n!\n\nif (ifodd .eq. 1) then\nx0 = 0\ncall lege(n,x0,pol,der)\nxs(nn+1) = x0\nwhts(nn+1) = 2.0d0/(der**2)\nendif\n\nend subroutine\n\n\nsubroutine legequad2(n,xs,whts)\nimplicit double precision (a-h,o-z)\ndimension xs(n),whts(n)\ndata pi /3.14159265358979323846264338327950288d0/\n!\n! Use Newton's method and local Taylor expansions (i.e., the Glaser-Liu Rokhlin method)\n! to compute the n roots of the Legendre polynomial of degree n. This routine \n! is O(n) in the number of nodes n.\n\nmaxiters = 12\ncall mach_zero(eps0)\neps0=eps0*10\nk = 30\n!\n! Find the roots in [0,1]\n!\n ifodd = 0\n nn = (n+1)/2\n if (nn .ne. n/2) then\n ifodd=1\n nn=nn-1\n endif\n!\n! Use a negative value of x0 to indicate that the procedure has\n! not been initialized.\n!\n!\n x0 = -1\n!\n do 2000 i=nn+1,n\n!\n! Use Chebyshev node as initial guess for roots ...\n!\n! x1 = cos(-pi+(2*i-1)*pi/(2*n))\n!\n! ... or use this somewhat better approximation.\n!\n dk = i-nn-1\n dn = n\n theta = (4*(ceiling(dn/2)-dk)-1) / (4*dn+2) * pi\n\n x1 = 1.0d0 - (dn-1)/(8*dn**3)-1.0d0/(384.0d0*dn**4)* &\n (39.0d0-28.0d0/sin(theta)**2)\n! \n x1=x1*cos(theta)\n!\n! Conduct Newton iterations.\n!\n do 2100 iter=1,maxiters\n!\n! Evaluate the nth polynomial at x1 using a Taylor expansion\n! and the recurrence relation. The first evaluation must be\n! handled specially.\n!\n if (x0 .lt. 0) then\n call lege(n,x1,pol,der)\n else\n dx = x1-x0 \n call legetayl(n,k,x0,dx,pol,der)\n endif\n!\n! Newton iteration.\n!\n x0 = x1\n dd = -pol/der\n x1 = x0+dd\n!\n if (abs(dd) .lt. eps0) then\n xs(i)=x1\n whts(i)=der\n goto 2000\n endif\n!\n 2100 continue\n!\n! This doesn't happen.\n!\n print *,\"legeroots bombed!\"\n stop\n 2000 continue\n!\n! Compute the weights using the derivatives we stored above.\n! \n do 3000 j=nn+1,n\n x = xs(j)\n dd = 2.0d0/(1-x**2)\n whts(j) = dd/whts(j)**2\n 3000 continue\n!\n! Reflect the quadrature on [-1,0] to [0,1].\n!\n do 4000 j=1,nn\n xs(j) = -xs(n-j+1)\n whts(j) = whts(n-j+1)\n 4000 continue\n!\n! Handle the root at 0 if n is odd.\n!\n if (ifodd .eq. 1) then\n x0 = 0\n call lege(n,x0,pol,der)\n!\n xs(nn+1) = x0\n whts(nn+1) = 2.0d0/der**2\n endif\n!\nend subroutine\n\n\n subroutine legetayl(n,k,x,dx,pol,der)\n implicit double precision (a-h,o-z)\n!\n! Evaluate the Legendre polynomial of order n using a Taylor\n! expansion and the recurrence relation for the power series\n! coefficients.\n!\n k0 = min(k,n)\n p1 = pol\n p2 = der*dx\n sum = p1+p2\n sumder = p2/dx\n do 1000 j=0,k0-2\n d = 2*x*(j+1.0d0)**2/dx*p2-(n*(n+1.0d0)-j*(j+1.0d0))*p1\n d = d/(j+1.0d0)/(j+2.0d0)*dx**2/(1.0d0-x**2)\n sum = sum+d\n sumder = sumder+d*(j+2)/dx\n p1 = p2\n p2 = d\n 1000 continue\n pol = sum\n der = sumder\n end subroutine\n\n\n\nsubroutine legeexps(n,xs,whts,u)\nimplicit double precision (a-h,o-z)\ninteger n\ndouble precision, allocatable, intent(out) :: xs(:),whts(:),u(:,:)\n!\n! Return the nodes x_1,...,x_n and weights w_1,...,w_n of the n-point\n! Legendre quadrature on the interval [-1,1]. Also, construct the\n! matrix u taking the scaled values of a n-term Legendre expansion\n! at the nodes of the n-point Legendre quadrature to its coefficients.\n! That is, if f is a polynomial of degree n-1 whose Legendre expansion is\n!\n! f(x) = \\sum_{j=0}^{n-1} a_j P_j(x)\n!\n! then u is the matrix taking the vector\n!\n! ( f(x_1) \\sqrt{w_1} )\n! ( f(x_1) \\sqrt{w_2} )\n! .\n! . (1)\n! .\n! ( f(x_n) \\sqrt{w_n} )\n!\n! of scaled function values to the vector\n!\n!\n! (a_0 )\n! (a_1 )\n! .\n! . (2)\n! .\n! (a_{n-1})\n!\n!\n!\n!\n! Input parameters:\n!\n! n - the length of the Legendre quadrature to construct\n!\n! Output parameters:\n!\n! xs - the nodes of the n-point Legendre quadrature on the interval [-1,1]\n! whts - this array\n! u - the (n,n) matrix which maps the scaled values (1) of a\n! polynomial of degree n-1 to the coefficients (2) in its Legendre expansion\n!\n! Since this matrix is orthogonal, its transpose takes the coefficients\n! of the Legendre expansion (2) to its scaled values at the nodes of\n! the n-point Legendre quadrature.\n!\n\n!\n! Call legequad to construct the n-point quadrature formula\n!\ncall legequad(n,xs,whts)\n\n!\n! Construct the matrix u.\n!\nallocate(u(n,n))\n\ndo i=1,n\ncall leges0(n-1,xs(i),u(:,i))\nu(:,i) = u(:,i)*sqrt(whts(i))\nend do\n\ndo j=1,n\ndd = (2*j-1)/2.0d0\nu(j,:) = u(j,:)*dd\nend do\n\nend subroutine\n\n\n\n\nsubroutine leges(n,x,pols,ders)\nimplicit double precision (a-h,o-z)\n\ndouble precision, intent(out) :: pols(n+1),ders(n+1)\ndouble precision x\ninteger n\n!\n! Evaluate the n+1 nLegendre polynomials of degree 0 through n at the\n! point x using the standard 3-term recurrence relation. Return the values\n! of their derivative at the point x as well.\n!\n! Input parameters:\n!\n! n - an integer specifying the order of polynomials which are to\n! be evaluated\n! x - the point at which the polynomials and their derivatives\n!\n! Output parameters:\n!\n! pols - the ith entry of this user-supplied array of length n+1\n! will contain the value of normalized Legendre polynomial of degree\n! i-1 at x\n! ders - the ith entry of this user-supplied array will contain the\n! value of the derivative of the normalized Legendre polynomial\n!\n!\n\npols(1) = 1\nders(1) = 0\n\nif (n >= 1) then\npols(2) = x\nders(2) = 1\nend if\n\n!\n! Calculate the values of the unnormalized polynomials\n!\ndo j=2,n\n pols(j+1)=((2.0d0*j-1.0d0)*x*pols(j)-(j-1.0d0)*pols(j-1))/j\nend do\n\n!\n! Compute the derivatives of the unnormalized polynoials\n!\nd=x**2.0d0-1.0d0\ndo j=3,n+1\n ders(j)=(j-1.0d0)*(x*pols(j)-pols(j-1))/d\nend do\n\n\n\nend subroutine\n\n\nsubroutine leges0(n,x,pols)\nimplicit double precision (a-h,o-z)\n\ndouble precision, intent(out) :: pols(n+1)\ndouble precision x\ninteger n\n!\n! Evaluate the n+1 Legendre polynomials of degree 0 through n at the\n! point x using the standard 3-term recurrence relation.\n!\n! Input parameters:\n!\n! n - an integer specifying the order of polynomials which are to\n! be evaluated\n! x - the point at which the polynomials and their derivatives\n!\n! Output parameters:\n!\n! pols - the ith entry of this user-supplied array of length n+1\n! will contain the value of P_{i-1}(t)\n!\n\npols(1) = 1\n\nif (n >= 1) then\npols(2) = x\nend if\n\n!\n! Calculate the values of the polynomials\n!\n\ndo j=2,n\npols(j+1)=((2.0d0*j-1.0d0)*x*pols(j)-(j-1.0d0)*pols(j-1))/j\nend do\n\n\nend subroutine\n\n\nsubroutine leges2(n,x,pols,ders,ders2)\nimplicit double precision (a-h,o-z)\n\ndouble precision, intent(out) :: pols(n+1),ders(n+1),ders2(n+1)\ndouble precision x\ninteger n\n!\n! Evaluate the n+1 Legendre polynomials of degree 0 through n at the\n! point x using the standard 3-term recurrence relation. Return the values\n! of their first and second derivatives at the point x as well.\n!\n! Input parameters:\n!\n! n - an integer specifying the order of polynomials which are to\n! be evaluated\n! x - the point at which the polynomials and their derivatives\n!\n! Output parameters:\n!\n! pols - the ith entry of this user-supplied array of length n+1\n! will contain the value of normalized Legendre polynomial of degree\n! i-1 at x\n! ders - the ith entry of this user-supplied array will contain the\n! value of the derivative of the normalized Legendre polynomial\n! of degree i-1 at x\n! ders2 - the ith entry of this user-supplied array will contain\n! the value of the second derivative of the normalized Legendre\n! polynomial of degree i-1 at x\n!\n!\n\n\npols(1) = 1\nders(1) = 0\nders2(1) = 0\n\nif (n >= 1) then\npols(2) = x\nders(2) = 1\nders2(2) = 0\nend if\n\n!\n! Calculate the values of the unnormalized polynomials\n!\ndo j=2,n\n pols(j+1)=((2.0d0*j-1.0d0)*x*pols(j)-(j-1.0d0)*pols(j-1))/j\nend do\n\n!\n! Compute the derivatives of the unnormalized polynoials\n!\nd=x**2.0d0-1.0d0\ndo j=3,n+1\n ders(j)=(j-1.0d0)*(x*pols(j)-pols(j-1))/d\nend do\n\n!\n! Compute the second derivatives of the unnormalized polynomials\n!\ndo j=3,n+1\n ders2(j) = (j-1)/d * (pols(j)+ ( (j-1)*x-2*x) /(j-1) * ders(j) - ders(j-1))\nend do\n\n\n\nend subroutine\n\n\nsubroutine lege(n,x,pol,der)\nimplicit double precision (a-h,o-z)\ninteger n\ndouble precision x,pol\n!\n! Evaluate the Legendre polynomial of degree n and its derivative at\n! the point x.\n!\n! Input parameters:\n!\n! n - the degree of the polynomial to evaluate\n! x - the point at which the polynomial is to be evaluated\n!\n! Output parameters:\n!\n! pol - the value of P_n(x)\n! der - the value of P_n'(x)\n!\n\n\nif (n == 0) then\npol = 1\nder = 0\nelse if (n == 1) then\npol = x\nder = 1.0d0\nelse\np1 = 1\np2 = x\n\ndo j=2,n\n p = ((2*j-1)*x*p2-(j-1)*p1)/j\n p1 = p2\n p2 = p\nend do\n!\npol = p\n!\n! Compute the derivative using another well-known formula.\n!\nder=n*(x*p2-p1)/(x**2-1.0d0)\nendif\n\nend subroutine\n\n\n\nsubroutine lege0(n,x,pol)\nimplicit double precision (a-h,o-z)\ninteger n\ndouble precision x,pol\n!\n! Evaluate the Legendre polynomial of degree n at the point x.\n!\n! Input parameters:\n!\n! n - the degree of the polynomial to evaluate\n! x - the point at which the polynomial is to be evaluated\n!\n! Output parameters:\n!\n! pol - the value of P_n(x)\n!\n\n\nif (n == 0) then\npol = 1.0d0\nelse if (n == 1) then\npol = x\nelse\np1 = 1\np2 = x\n\ndo j=2,n\n p = ((2*j-1)*x*p2-(j-1)*p1)/j\n p1 = p2\n p2 = p\nend do\n\npol = p\nendif\n\nend subroutine\n\n\nsubroutine legeeval(n,coefs,x,val,der)\nimplicit double precision (a-h,o-z)\n\ninteger n\ndimension coefs(n)\ndouble precision x,val,der\n\n!\n! Evaluate an n-term Legendre expansion and its derivative at the point x.\n! That is, given n and a_0, a_1, ..., a_{n-1} evalute the function defined by\n!\n! n\n! f(t) = \\sum a_j P_j(t),\n! j=0\n!\n! where P_j is the jth Legendre polynomial, and its derivative\n! at the point x.\n!\n! Input parameters:\n!\n! n - the number of terms in the Legendre expansion\n! coefs - an array of length n containing the coefficients of the expansion\n! x - the point at which to evaluate the expansion\n!\n! Output parameters:\n!\n! val - the value of the expansion at the point x\n! der - the derivative of the expansion at the point x\n!\n!\n\ndimension pols(n),ders(n)\n\nval = 0\nder = 0\n\ncall leges(n-1,x,pols,ders)\n\n\ndo i=1,n\nval = val + pols(i)*coefs(i)\nder = der + ders(i)*coefs(i)\nend do\n\n\nend subroutine\n\n\nsubroutine legeeval0(n,coefs,x,val)\nimplicit double precision (a-h,o-z)\n\ninteger n\ndimension coefs(n)\ndouble precision x,val\n\n!\n! Evaluate an n-term Legendre expansion at the point x. That is, given n \n! and a_0, a_1, ..., a_{n-1} evalute the function defined by\n!\n! n\n! f(t) = \\sum a_j P_j(t),\n! j=0\n!\n! where P_j is the jth Legendre polynomial at the point x.\n!\n! Input parameters:\n!\n! n - the number of terms in the Legendre expansion\n! coefs - an array of length n containing the coefficients of the expansion\n! x - the point at which to evaluate the expansion\n!\n! Output parameters:\n!\n! val - the value of the expansion at the point x\n!\n\ndimension pols(n),ders(n)\n\nval = 0\n\ncall leges(n-1,x,pols,ders)\n\ndo i=1,n\nval = val + pols(i)*coefs(i)\nend do\n\nend subroutine\n\n\nsubroutine legediff(n,xs,whts,u,a)\nimplicit double precision (a-h,o-z)\n\ndouble precision, intent(in) :: xs(n),whts(n),u(n,n)\ndouble precision, allocatable, intent(out) :: a(:,:)\n!\n! Construct the (n,n) spectral differential matrix. That is, the matrix\n! which takes scaled values of a function f at the Legendre nodes\n! to the scaled values of its derivative at the Legendre nodes.\n!\n! Input parameters:\n!\n! n - the number of Legendre nodes used to represent inputs and outputs\n! (xs,whts) - the nodes and weights of the n-point Legendre quadrature\n! u - the (n,n) matrix taking the scaled values of a Legendre expansion of\n! order n-1 to its coefficients\n! v - the (n,n) matrix inverse of u\n!\n! Output parameters:\n!\n! a - the (n,n) spectral differentiation matrix, which is allocated\n! by the routine\n!\n\n! double precision, allocatable :: xs0(:),whts0(:)\ndouble precision, allocatable :: b(:,:)\ndouble precision :: pols(n),ders(n)\n\n! call legequad(n-1,xs0,whts0)\n\nallocate(a(n,n),b(n,n))\n\n!\n! Evaluate the derivatives of the Legendre polynomials at the\n! Legendre nodes.\n!\n\ndo i=1,n\ncall leges(n-1,xs(i),pols,ders)\ndo j=1,n\nb(i,j) = ders(j) *sqrt(whts(i))\nend do\nend do\n\n!\n! Multiply that matrix by the matrix which takes scaled values to\n! coefficients in order to form the output matrix.\n!\n\na = matmul(b,u)\n\nend subroutine\n\n\n\nsubroutine legeint(n,xs,whts,u,a)\nimplicit double precision (a-h,o-z)\n\ndouble precision, intent(in) :: xs(n),whts(n),u(n,n)\ndouble precision, intent(out) :: a(n,n)\n!\n! Construct the (n,n) spectral integration matrix. That is, the matrix\n! which takes scaled values of a Legendre\n! to the scaled values of its antiderivative at Legendre nodes.\n!\n! Input parameters:\n!\n! n -the number of\n! (xs,whts) - the nodes and weights of the n-point Legendre quadrature\n! u - the (n,n) matrix taking the scaled values of a Legendre expansion of\n! order n-1 to its coefficients\n!\n! Output parameters:\n!\n! a - the (n,n) spectral integration matrix\n!\n\ndouble precision, allocatable :: b(:,:)\ndouble precision :: pols(n)\n\n\nallocate(b(n,n))\n\n!\n! Use the formula\n!\n!\n! t\n! \\int P_n(x) dx = ( t P_n(t) - P_{n-1}(t) ) / (n+1)\n! -1\n!\n!\n! to form the matrix of integrals of the Legendre polynomials at the\n! Legendre nodes.\n!\n\n\ndo i=1,n\ncall leges0(n-1,xs(i),pols)\n\nb(i,1) = (1+xs(i))*sqrt(whts(i))\n\ndo j=2,n\nb(i,j) = (xs(i) * pols(j) - pols(j-1))/(j)\nb(i,j) = b(i,j)*sqrt(whts(i))\nend do\nend do\n\n\n!\n! Form the spectral integration matrix.\n!\na = matmul(b,u)\n\nend subroutine\n\n\nsubroutine legen(n,x,pols)\nimplicit double precision (a-h,o-z)\n\ndouble precision, intent(out) :: pols(n+1)\ndouble precision x\ninteger n\n!\n! Evaluate the n+1 normalized Legendre polynomials of degree 0 through n at the\n! point x using the standard 3-term recurrence relation.\n!\n! Input parameters:\n!\n! n - an integer specifying the order of polynomials which are to\n! be evaluated\n! x - the point at which the polynomials and their derivatives\n!\n! Output parameters:\n!\n! pols - the ith entry of this user-supplied array of length n+1\n! will contain the value of P_{i-1}(t)\n!\n\npols(1) = 1\n\nif (n >= 1) then\npols(2) = x\nend if\n\n!\n! Calculate the values of the polynomials\n!\ndo j=2,n\n pols(j+1)=((2.0d0*j-1.0d0)*x*pols(j)-(j-1.0d0)*pols(j-1))/j\nend do\n\n!\n! Normalize the polynomials.\n!\n\ndo j=1,n+1\n dd = sqrt((2*(j-1)+1)/2.0d0)\n pols(j) = pols(j)*dd\nend do\n\nend subroutine\n\n\n\nsubroutine lege_stieltjes(dnu,t,val)\nimplicit double precision (a-h,o-z)\n\ndouble precision, intent(in) :: dnu,t\ndouble precision, intent(out) :: val\n\ndata pi /3.14159265358979323846264338327950288q0/\ndata sqrt2overpi / 0.797884560802865355879892119868763737q0/\ndata piover2 / 1.57079632679489661923132169163975144q0/\n\nval = 0\nnterms = 17\nx = dnu+0.75d0\n\ndd = 1-1874409467055q0/(7.0368744177664q13*x**14)+ &\n7426362705q0/(1.099511627776q12*x**12)- &\n20898423q0/(8.589934592q9*x**10)+180323/(1.34217728q8*x**8)- &\n671/(5.2428799999999995q5*x**6)+21/(8.192q3*x**4)- &\n1/(6.4q1*x**2)\n\nc0 = 1.0d0/sqrt(x) * dd\ndd = 1.0d0\ndd2 = 1/sin(t)\n\ndo m=0,nterms\na = (dnu+m+0.5d0)*t-(m+0.5d0)*piover2\nval = val + c0 * cos(a)*dd\ndd = dd*dd2\nc0 = c0 * (m+0.5d0)**2/(2*(m+1.0d0)*(dnu+m+1.5d0))\nend do\n\nval = val * sqrt2overpi*sqrt(dd2)\n\nend subroutine\n\n\nend module\n", "meta": {"hexsha": "12cd335381660a17dd8d861e8e1b4fa593729607", "size": 20778, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "v2/specFun/src/legendre.f90", "max_stars_repo_name": "ButterflyLab/ButterflyLab", "max_stars_repo_head_hexsha": "fb152ba8f2c5dbdc2b15b516023516a5b538ef78", "max_stars_repo_licenses": ["0BSD"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2018-01-04T20:47:01.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-18T14:16:56.000Z", "max_issues_repo_path": "v2/specFun/src/legendre.f90", "max_issues_repo_name": "ButterflyLab/ButterflyLab", "max_issues_repo_head_hexsha": "fb152ba8f2c5dbdc2b15b516023516a5b538ef78", "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": "v2/specFun/src/legendre.f90", "max_forks_repo_name": "ButterflyLab/ButterflyLab", "max_forks_repo_head_hexsha": "fb152ba8f2c5dbdc2b15b516023516a5b538ef78", "max_forks_repo_licenses": ["0BSD"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-04-13T11:14:44.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-16T16:19:45.000Z", "avg_line_length": 22.0105932203, "max_line_length": 91, "alphanum_fraction": 0.6322071422, "num_tokens": 6812, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391664210672, "lm_q2_score": 0.7520125848754471, "lm_q1q2_score": 0.6941370694815847}} {"text": "\tSUBROUTINE VMATRIX(DATA,WT,NPT)\nC\nC\tCALCULATES VARIANCE MATRIX AND EIGENVALUES\nC\nC\tCOMMON /PARTBLK/ XDATA(2050,4),XFDATA(2050,4),XGSE(2050,4),\nC 1\t\tXRE,YRE,ZRE,SUNCLOCK,SPINRATE,SPSS\n\tCOMMON /VARMATX/ EVAL(3),EVECT(3,3)\n\tREAL DATA(2050,4),DATAS(2050,3),VMAT(3,3),WT(2050)\n\tREAL SN(3),CL(3),V3(3),AV(3),STD(3)\n\tINTEGER*4 SUNCLOCK\n\tDATA NSYS /-1/\nC\nC\tTHIS PROGRAM EXCLUDES GLITCH DATA BY USING WT\nC\nC\tsubtract averages\nC\nC\tWRITE(79,*) ' '\t\nC\tWRITE(79,*) 'VARIANCE MATRIX,NPT=',NPT\t\nC\n\tDO M = 1,3\n\t AV(M) = 0.\n\t COUNT = 0.\n\t DO N = 1,NPT\n\t\tAV(M) = AV(M) + WT(N)*DATA(N,M)\n\t\tCOUNT = COUNT+WT(N)\n\t ENDDO\nC\tPRINT*,'M,AV,COUNT',M,AV(M),COUNT\n\t AV(M) = AV(M)/COUNT\n\tENDDO\n\tDO M = 1,3\t\n\t DO N = 1,NPT\n\t\tDATAS(N,M) = WT(N)*(DATA(N,M) - AV(M))\n\t ENDDO\n\tENDDO\nC\nC\tPRINT*,' WITH AVERAGES REMOVED'\nC\nC\tFORM VARIANCE MATRIX\nC\t\n\tDO K = 1,3\n\t DO M = 1,3\n\t\tVMAT(K,M) = 0.\n\t ENDDO\n\tENDDO\nC\t\n\tDO N = 1,NPT\n\t DO K = 1,3\n\t DO M = K,3\n\t\tVMAT(K,M) = VMAT(K,M) + DATAS(N,K)*DATAS(N,M)\n\t ENDDO\n\t ENDDO\n\tENDDO\t\nc\tprint*,'diag elems',vmat(1,1),vmat(2,2),vmat(3,3),\nc 1\t' trace',vmat(1,1)+vmat(2,2)+vmat(3,3)\nC\nC\tCALCULATE EIGENVALUES AND MATRIX OF EIGENVECTORS\nC\n\tCALL JACOBI(VMAT,3,3,EVAL,EVECT,NROT)\nC\tPRINT*,'EIGENVALUES',EVAL\nC\tPRINT*,'EIGENVECTOR'\nC\tPRINT*,(EVECT(1,I),I=1,3)\nC\tPRINT*,(EVECT(2,I),I=1,3)\nC\tPRINT*,(EVECT(3,I),I=1,3)\nC\nC\tSORT IN DESCENDING ORDER OF EIGENVALUES\nC\n\tCALL EIGSRT(EVAL,EVECT,3,3)\nC\nC\nC \tENFORCE A RIGHT HANDED SYSTEM BY REVERSING THE SMALLEST\nC\tEIGENVECTOR IF NECESSARY\nC\n\tADOTBXC = EVECT(1,1)*EVECT(2,2)*EVECT(3,3)\n 1\t - EVECT(1,1)*EVECT(3,2)*EVECT(2,3)\n 1\t + EVECT(2,1)*EVECT(1,3)*EVECT(3,2)\n 1\t - EVECT(2,1)*EVECT(1,2)*EVECT(3,3)\n 1\t + EVECT(3,1)*EVECT(1,2)*EVECT(2,3)\n 1\t - EVECT(3,1)*EVECT(2,2)*EVECT(1,3)\nC\tPRINT*,'DETERMINANT OF EIGENVECTORS',ADOTBXC\n\tIF(ADOTBXC.LT.0.) THEN ! REVERSE SMALLEST EVECT FOR RH SYSTEM\n\t EVECT(1,3) = -EVECT(1,3)\n\t EVECT(2,3) = -EVECT(2,3)\n\t EVECT(3,3) = -EVECT(3,3)\nC\t PRINT*,'CHANGE TO RIGHT HANDED SYSTEM'\n\tENDIF\nC\nC\tPRINT*,'IN SYSTEM',NSYS,' EIGENVALUES:'\nC\tPRINT*,EVAL,'eig sum',eval(1)+eval(2)+eval(3)\nC\tPRINT*,'EIGENVECTORS'\nC\tPRINT*,(EVECT(1,I),I=1,3)\nC\tPRINT*,(EVECT(2,I),I=1,3)\nC\tPRINT*,(EVECT(3,I),I=1,3)\nC\tWRITE(79,*) 'IN SYSTEM',NSYS,' EIGENVALUES:'\nC\tWRITE(79,*) EVAL\nC\tWRITE(79,*) 'EIGENVECTORS IN COLUMNS BELOW EIGENVALUES'\nC\tWRITE(79,*)(EVECT(1,I),I=1,3)\nC\tWRITE(79,*)(EVECT(2,I),I=1,3)\nC\tWRITE(79,*)(EVECT(3,I),I=1,3)\n\tNSYS = 2\n\tRETURN\n\tEND\t\n", "meta": {"hexsha": "a857b5131fdb73bf6e5e55a61dc7f3afc2f053c8", "size": 2459, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/vmatrix_24.for", "max_stars_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_stars_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/vmatrix_24.for", "max_issues_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_issues_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/vmatrix_24.for", "max_forks_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_forks_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.1078431373, "max_line_length": 69, "alphanum_fraction": 0.6287108581, "num_tokens": 1275, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.923039160069787, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6941370595752521}} {"text": "!*********************************************************************\n! This file is part of Polylogarithm.\n!\n! Polylogarithm is licenced under the MIT License.\n!*********************************************************************\n\n!*********************************************************************\n!> @brief Clausen function \\f$\\operatorname{Cl}_3(\\theta) = \\operatorname{Re}(\\operatorname{Li}_3(e^{i\\theta}))\\f$\n!> @param x real angle\n!> @return \\f$\\operatorname{Cl}_3(\\theta)\\f$\n!> @author Alexander Voigt\n!> Implemented as rational function approximation.\n!*********************************************************************\n\ndouble precision function dcl3(x)\n implicit none\n double precision :: x, y, z, z2, z4, p, q, p0, p1, h\n double precision, parameter :: PI = 3.14159265358979324D0\n double precision, parameter :: PI2 = 2*PI, PIH = PI/2, PI28 = PI*PI/8\n double precision, parameter :: zeta3 = 1.2020569031595943D0\n double precision, parameter :: cp(4) = (/ &\n -7.5000000000000001D-1, &\n 1.5707637881835541D-2, &\n -3.5426736843494423D-5, &\n -2.4408931585123682D-7 /)\n double precision, parameter :: cq(4) = (/ &\n 1.0000000000000000D+0, &\n -2.5573146805410089D-2, &\n 1.5019774853075050D-4, &\n -1.0648552418111624D-7 /)\n double precision, parameter :: cr(6) = (/ &\n -4.9017024647634973D-1, &\n 4.1559155224660940D-1, &\n -7.9425531417806701D-2, &\n 5.9420152260602943D-3, &\n -1.8302227163540190D-4, &\n 1.8027408929418533D-6 /)\n double precision, parameter :: cs(6) = (/ &\n 1.0000000000000000D+0, &\n -1.9495887541644712D-1, &\n 1.2059410236484074D-2, &\n -2.5235889467301620D-4, &\n 1.0199322763377861D-6, &\n 1.9612106499469264D-9 /)\n\n if (x .lt. 0) then\n x = -x\n endif\n\n if (x .ge. PI2) then\n x = mod(x, PI2)\n endif\n\n if (x .gt. PI) then\n p0 = 6.28125D0\n p1 = 0.0019353071795864769253D0\n x = (p0 - x) + p1\n endif\n\n if (x .eq. 0) then\n dcl3 = zeta3\n return\n endif\n\n if (x .lt. PIH) then\n y = x*x\n z = y*y\n p = cp(1) + y * cp(2) + z * (cp(3) + y * cp(4))\n q = cq(1) + y * cq(2) + z * (cq(3) + y * cq(4))\n h = zeta3 + y*(p/q + log(x)/2)\n else\n y = PI - x\n z = y*y - PI28\n z2 = z*z\n z4 = z2*z2\n p = cr(1) + z * cr(2) + z2 * (cr(3) + z * cr(4)) + &\n z4 * (cr(5) + z * cr(6))\n q = cs(1) + z * cs(2) + z2 * (cs(3) + z * cs(4)) + &\n z4 * (cs(5) + z * cs(6))\n h = p/q\n endif\n\n dcl3 = h\n\nend function dcl3\n", "meta": {"hexsha": "708e88de417432dd3965ac59f923a3e0adc10e2d", "size": 2798, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/Cl3.f90", "max_stars_repo_name": "Expander/dilogarithm", "max_stars_repo_head_hexsha": "ad86038206895ab5bff79a26294f4bb5c5634eb5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-05-04T14:47:41.000Z", "max_stars_repo_stars_event_max_datetime": "2017-08-02T13:13:45.000Z", "max_issues_repo_path": "src/fortran/Cl3.f90", "max_issues_repo_name": "Expander/dilogarithm", "max_issues_repo_head_hexsha": "ad86038206895ab5bff79a26294f4bb5c5634eb5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/fortran/Cl3.f90", "max_forks_repo_name": "Expander/dilogarithm", "max_forks_repo_head_hexsha": "ad86038206895ab5bff79a26294f4bb5c5634eb5", "max_forks_repo_licenses": ["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.5348837209, "max_line_length": 114, "alphanum_fraction": 0.4474624732, "num_tokens": 986, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391621868804, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6941370509071526}} {"text": "subroutine UCalcEdgeCenterCoordinate(UG)\n use StructVar_Mod\n use LoopVar_Mod\n implicit none\n type(UnstructuredGrid), intent(inout) :: UG\n\n iELM => iElement\n call GravityCenterOfTriangle\n call MidPointOfLine\n\nreturn\ncontains\n!_________________________________________________\n subroutine GravityCenterOfTriangle\n implicit none\n do iElement=1,UG%Tri%Total\n iVertex1 = UG%Tri%Point(iELM,1) !\u4e09\u89d2\u5f62\u306e\u9802\u70b9\u306e\u70b9\u756a\u53f7\n iVertex2 = UG%Tri%Point(iELM,2)\n iVertex3 = UG%Tri%Point(iELM,3)\n !\u91cd\u5fc3\n UG%CD%Cell(iELM,:) = (UG%CD%Point(iVertex1,:) + UG%CD%Point(iVertex2,:) &\n & + UG%CD%Point(iVertex3,:))/3.0d0\n end do\n return\n end subroutine GravityCenterOfTriangle\n\n!_________________________________________________\n\n subroutine MidPointOfLine\n implicit none\n do iElement=1, UG%Line%Total\n iEndPoint1 = UG%Line%Point(iELM,1)\n iEndPoint2 = UG%Line%Point(iELM,2)\n UG%CD%Edge(iELM,:) = 0.5d0*(UG%CD%Point(iEndPoint1,:)+UG%CD%Point(iEndPoint2,:))\n end do\n return\n end subroutine MidPointOfLine\n\nend subroutine UCalcEdgeCenterCoordinate\n", "meta": {"hexsha": "0a5bd7723b5ccb6e777efc73f1313e0bbdc9d58b", "size": 1206, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "grid_generator/ManipulateVtk/Preprocessing4UnstructuredGrid/source/UCalcEdgeCenterCoordinate.f90", "max_stars_repo_name": "Mayu14/2D_comp_viscos", "max_stars_repo_head_hexsha": "a62633d8684b218b52e39d47a13717a1edfa4a46", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-05-08T18:00:28.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-08T18:00:28.000Z", "max_issues_repo_path": "grid_generator/ManipulateVtk/Preprocessing4UnstructuredGrid/source/UCalcEdgeCenterCoordinate.f90", "max_issues_repo_name": "Mayu14/2D_comp_viscos", "max_issues_repo_head_hexsha": "a62633d8684b218b52e39d47a13717a1edfa4a46", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "grid_generator/ManipulateVtk/Preprocessing4UnstructuredGrid/source/UCalcEdgeCenterCoordinate.f90", "max_forks_repo_name": "Mayu14/2D_comp_viscos", "max_forks_repo_head_hexsha": "a62633d8684b218b52e39d47a13717a1edfa4a46", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-02-20T09:26:27.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-20T09:26:27.000Z", "avg_line_length": 30.15, "max_line_length": 92, "alphanum_fraction": 0.6484245439, "num_tokens": 357, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473813156294, "lm_q2_score": 0.7956581000631541, "lm_q1q2_score": 0.6940902600126615}} {"text": " SUBROUTINE ZCLINT(NX,X,Y,NXOUT,XOUT,YOUT)\n*\n* Module number:\n*\n* Module name: ZCLINT\n*\n* Keyphrase:\n* ----------\n*\tLinear interpolation\n*\n* Description:\n* ------------\n*\tThis routine preforms linear interpolation within\n*\tinput vectors X and Y at positions in vector XTAB.\n*\n* FORTRAN name: zclint\n*\n* Keywords of accessed files and tables:\n* --------------------------------------\n*\tnone\n*\n* Subroutines Called:\n* -------------------\n*\tnone\n*\n* History:\n* --------\n* Version Date Author Description\n*\t1\tMay 89\tD. Lindler\tDesigned and coded\n*-------------------------------------------------------------------------------\n*\n* INPUTS:\n*\n*\tNX - number of points in input X and Y table\n*\tX - x-positions in input table\n*\tY - y-positions in input table\n*\tNXOUT - number of points to interpolate\n*\tXOUT - points to interpolate\n*\n* OUTPUTS:\n*\tYOUT - interpolated values\n*\n*------------------------------------------------------------------------------\n REAL X(1),XOUT(1)\n REAL Y(1),YOUT(1)\nC\nC Local variables\nC\n INTEGER NX,NXOUT\n INTEGER IPOS\nC ---> CURRENT POSITION IN X ARRAY\n INTEGER I,II\nC ---> INDEX IN XOUT AND YOUT\n REAL FRAC\nC ---> FRACTIONAL DISTANCE BETWEEN X(IPOS) AND\nC X(IPOS+1) OR XOUT(I)\nC-------------------------------------------------------------------------------\nC\nC INITIALIZATION\nC\n IPOS=1\nC ---> START AT BEGGINING OF X,Y\nC LOOP ON VALUES IN XOUT\nC\n DO 100 I=1,NXOUT\nC\nC FIND IPOS SUCH THAT X(IPOS) <= XOUT(I) < X(IPOS+1)\nC\nC DETERMINE IF WE SHOULD DECREASE IPOS\nC\n DO 10 II=1,NX\n IF((IPOS.EQ.1).OR.(XOUT(I).GT.X(IPOS)))GO TO 20\n IPOS=IPOS-1\n10 CONTINUE\nC\nC DETERMINE IF WE SHOULD INCREASE IPOS\nC\n20 DO 30 II=1,NX\n IF((IPOS.EQ.(NX-1)).OR.(XOUT(I).LE.X(IPOS+1))) GO TO 40\n IPOS=IPOS+1\n30 CONTINUE\nC\nC DETERMINE FRACTIONAL DISTANCE BETWEEN X(IPOS) AND X(IPOS+1)\nC\n40 IF (X(IPOS) .EQ. X(IPOS+1)) THEN\n FRAC=0.0\n ELSE\n FRAC= (XOUT(I)-X(IPOS)) / (X(IPOS+1)-X(IPOS))\n ENDIF\nC\nC COMPUTE INTERPOLATED VALUE\nC\n YOUT(I) = Y(IPOS) + FRAC * (Y(IPOS+1)-Y(IPOS))\n100 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "f146eaf97054f53a388cf6b7f60f8ae615e2a92e", "size": 2453, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "stsdas/pkg/hst_calib/hrs/calhrs/zclint.f", "max_stars_repo_name": "iraf-community/stsdas", "max_stars_repo_head_hexsha": "043c173fd5497c18c2b1bfe8bcff65180bca3996", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-12-20T10:06:48.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-20T10:06:48.000Z", "max_issues_repo_path": "stsdas/pkg/hst_calib/hrs/calhrs/zclint.f", "max_issues_repo_name": "spacetelescope/stsdas_stripped", "max_issues_repo_head_hexsha": "043c173fd5497c18c2b1bfe8bcff65180bca3996", "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": "stsdas/pkg/hst_calib/hrs/calhrs/zclint.f", "max_forks_repo_name": "spacetelescope/stsdas_stripped", "max_forks_repo_head_hexsha": "043c173fd5497c18c2b1bfe8bcff65180bca3996", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-10-12T20:01:16.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-19T08:04:30.000Z", "avg_line_length": 25.2886597938, "max_line_length": 80, "alphanum_fraction": 0.4671830412, "num_tokens": 689, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782094, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.6940902505046299}} {"text": "program test\n\nuse mo_kind, only: i4, sp, dp\nuse mo_ansi_colors, only: color, c_red, c_green\nuse mo_laplace_inversion, only: NLInvSteh\nuse mo_utils, only: eq\n\nimplicit none\n\ninteger(i4) :: n,m\nreal(dp), dimension(10) :: test_s, comp_func1, comp_func2\nreal(dp), dimension(10) :: testpara, compvalue\nreal(dp), dimension(10) :: meansq_err\n\nreal(sp), dimension(10) :: test_s_sp, comp_func1_sp, comp_func2_sp\nreal(sp), dimension(10) :: testpara_sp, compvalue_sp\nreal(sp), dimension(6) :: meansq_err_sp\n\nLOGICAL :: isgood\n\nreal(sp) :: stmp\nreal(dp) :: dtmp\n\n!--------------------------------------------------------------------------------------------------\n! with testpara[_sp] you can choose one of the served functions:\n! function 1 [ 1/(s+1) ] : (2,0,0,0,0,...)\n! function 2 [ 1/(s^2) ] : (0,2,0,0,0,...)\n! function 3 [24/(s^5) ] : (0,0,2,0,0,...)\n! function 4 [ 1/(s^2 + 1)] : (0,0,0,2,0,...)\n!--------------------------------------------------------------------------------------------------\n\n!--------------------------------------------------------------------------------------------------\n!Interface for the test-functions\n!--------------------------------------------------------------------------------------------------\n\nINTERFACE\n function testfuncvec(s, para)\n use mo_kind, only: dp\n implicit none\n real(dp), dimension(:), intent(in) :: s\n real(dp), dimension(:), intent(in) :: para\n real(dp), dimension(size(s)) :: testfuncvec\n end function testfuncvec\nEND INTERFACE\n\nINTERFACE\n function testfuncsgl(s, para)\n use mo_kind, only: dp\n implicit none\n real(dp), intent(in) :: s\n real(dp), dimension(:), intent(in) :: para\n real(dp) :: testfuncsgl\n end function testfuncsgl\nEND INTERFACE\n\nINTERFACE\n function testfuncvecsp(s, para)\n use mo_kind, only: sp\n implicit none\n real(sp), dimension(:), intent(in) :: s\n real(sp), dimension(:), intent(in) :: para\n real(sp), dimension(size(s)) :: testfuncvecsp\n end function testfuncvecsp\nEND INTERFACE\n\nINTERFACE\n function testfuncsglsp(s, para)\n use mo_kind, only: sp\n implicit none\n real(sp), intent(in) :: s\n real(sp), dimension(:), intent(in) :: para\n real(sp) :: testfuncsglsp\n end function testfuncsglsp\nEND INTERFACE\n\n\ndo n=1_i4, size(test_s)\n test_s(n) = real(n,dp)!*0.1_dp\nend do\ndo n=1_i4, size(test_s_sp)\n test_s_sp(n)= real(n,sp)!*0.1_sp\nend do\n\nisgood = .true.\n\n!--------------------------------------------------------------------------------------------------\n! 1. function\n!--------------------------------------------------------------------------------------------------\n\n!-------\n! dp\n!-------\n\ncompvalue = (/&\n 0.36786938930120000_dp,&\n 0.13539293114857939_dp,&\n 4.9877996513226830E-002_dp,&\n 1.8286058932031109E-002_dp,&\n 6.5874045566482612E-003_dp,&\n 2.2951255530484788E-003_dp,&\n 7.6967353312535096E-004_dp,&\n 2.6597684820688181E-004_dp,&\n 1.2496193720515686E-004_dp,&\n 1.0067495791304415E-004_dp/)\n\n! write(*,*) compvalue(10)\n\ntestpara=(/2.0_dp,0.0_dp,0.0_dp,0.0_dp,0.0_dp,0.0_dp,0.0_dp,0.0_dp,0.0_dp,0.0_dp/)\n\ncomp_func1=exp(-test_s(:))\ncomp_func2=NLInvSteh(testfuncvec, testpara, test_s, 12)\n\nwrite (*,*) \" \"\nwrite (*,*) \" \"\nwrite (*,*) \"dp: Function 1/(s+1) with inverse function e^(-t) [Stehfest-limit=12]\"\nwrite (*,*) '-------------------------------------------------------------------------------------------'\nwrite (*,*) \"time t analytical inverse Stehfest-inverted relativ error\"\nwrite (*,*) '-------------------------------------------------------------------------------------------'\ndo n=1_i4,size(test_s)\n write (*,*) test_s(n), comp_func1(n), comp_func2(n), abs((comp_func2(n)-comp_func1(n))/comp_func1(n))\n dtmp = NLInvSteh(testfuncsgl, testpara, test_s(n), 12)\n isgood = isgood .and. eq(comp_func2(n), dtmp)\n isgood = isgood .and. (int((comp_func2(n)-compvalue(n))*1000000.0_dp, i4) .eq. 0_i4)\nend do\n\nmeansq_err=0.0_dp\ndo m=1_i4, size(meansq_err)\n ! write (*,*) \" \"\n ! write (*,*) \"stehfest-limit: \", 2*m\n comp_func2=NLInvSteh(testfuncvec, testpara, test_s,2*m)\n ! write (*,*) \" \"\n ! write (*,*) \"Function 1/(s+1) with inverse function e^(-t)\"\n ! write (*,*) '-------------------------------------------------------------------------------------------'\n ! write (*,*) \"time t analytical inverse Stehfest-inverted relativ error\"\n ! write (*,*) '-------------------------------------------------------------------------------------------'\n do n=1_i4,size(test_s)\n ! write (*,*) test_s(n), comp_func1(n), comp_func2(n), abs((comp_func2(n)-comp_func1(n))/comp_func1(n))\n meansq_err(m)=meansq_err(m)+(comp_func2(n)-comp_func1(n))**2\n end do\nend do\n\nwrite (*,*) \" \"\nwrite (*,*) \"MSE between the stehfest-inverted- and analytical-function in dependency of the stehfestlimit\"\nwrite (*,*) '---------------------------------------------------------------------------------------------'\ndo m=1_i4, size(meansq_err)\n write (*,*) \"stehfest-limit with MSE: \", 2*m,\":\", meansq_err(m)\nend do\nwrite (*,*) \"least absolut MSE with Stehfest-limit: \", minloc(meansq_err)*2\n\n!-------\n! sp\n!-------\n\ncompvalue_sp = (/&\n 0.262637794_sp,&\n 0.138087913_sp,&\n 1.62456371E-02_sp,&\n 6.90439567E-02_sp,&\n 6.49825484E-03_sp,&\n -3.61014158E-03_sp,&\n -2.93968674E-02_sp,&\n 2.30146535E-02_sp,&\n 4.81352210E-03_sp,&\n 4.22386564E-02_sp/)\n\n\ntestpara_sp=(/2.0_sp,0.0_sp,0.0_sp,0.0_sp,0.0_sp,0.0_sp,0.0_sp,0.0_sp,0.0_sp,0.0_sp/)\n\ncomp_func1_sp=exp(-test_s_sp(:))\ncomp_func2_sp=NLInvSteh(testfuncvecsp, testpara_sp, test_s_sp, 12_i4)\n\nwrite (*,*) \" \"\nwrite (*,*) \"sp: Function 1/(s+1) with inverse function e^(-t) [Stehfest-limit=12]\"\nwrite (*,*) '---------------------------------------------------------------------'\nwrite (*,*) \"time t analytical inverse Stehfest-inverted relativ error\"\nwrite (*,*) '--------------------------------------------------------------------'\ndo n=1_i4,size(test_s_sp)\n write (*,*) test_s_sp(n), comp_func1_sp(n), comp_func2_sp(n), abs((comp_func2_sp(n)-comp_func1_sp(n))/comp_func1_sp(n))\n stmp = NLInvSteh(testfuncsglsp, testpara_sp, test_s_sp(n), 12)\n isgood = isgood .and. eq(comp_func2_sp(n), stmp)\n isgood = isgood .and. (int((comp_func2_sp(n)-compvalue_sp(n))*1000.0_sp, i4) .eq. 0_i4)\nend do\n\n\nmeansq_err_sp=0.0_sp\ndo m=1_i4, size(meansq_err_sp)\n ! write (*,*) \" \"\n ! write (*,*) \"stehfest-limit: \", 2*m\n comp_func2_sp=NLInvSteh(testfuncvecsp, testpara_sp, test_s_sp,2*m)\n ! write (*,*) \" \"\n ! write (*,*) \"Function 1/(s+1) with inverse function e^(-t)\"\n ! write (*,*) '-------------------------------------------------------------------'\n ! write (*,*) \"time t analytical inverse Stehfest-inverted relativ error\"\n ! write (*,*) '-------------------------------------------------------------------'\n do n=1_i4,size(test_s_sp)\n ! write (*,*) test_s_sp(n), comp_func1_sp(n), comp_func2_sp(n), abs((comp_func2_sp(n)-comp_func1_sp(n))/comp_func1_sp(n))\n meansq_err_sp(m)=meansq_err_sp(m)+(comp_func2_sp(n)-comp_func1_sp(n))**2\n end do\nend do\n\nwrite (*,*) \" \"\nwrite (*,*) \"MSE between the stehfest-inverted- and analytical-function in dependency of the stehfestlimit\"\nwrite (*,*) '---------------------------------------------------------------------------------------------'\ndo m=1_i4, size(meansq_err_sp)\n write (*,*) \"stehfest-limit with MSE: \", 2*m,\":\", meansq_err_sp(m)\nend do\nwrite (*,*) \"least absolut MSE with Stehfest-limit: \", minloc(meansq_err_sp)*2\n\n\n!--------------------------------------------------------------------------------------------------\n! 2. function\n!--------------------------------------------------------------------------------------------------\n\n!-------\n! dp\n!-------\n\ncompvalue = (/&\n 1.0000009622103812_dp,&\n 2.0000019244207623_dp,&\n 3.0000028866118105_dp,&\n 4.0000038488415246_dp,&\n 5.0000048109464998_dp,&\n 6.0000057732236209_dp,&\n 7.0000067358527165_dp,&\n 8.0000076976830492_dp,&\n 9.0000086601285041_dp,&\n 10.000009621893000_dp/)\n\ntestpara=(/0.0_dp,2.0_dp,0.0_dp,0.0_dp,0.0_dp,0.0_dp,0.0_dp,0.0_dp,0.0_dp,0.0_dp/)\n\ncomp_func1=test_s\ncomp_func2=NLInvSteh(testfuncvec, testpara, test_s, 12)\n\nwrite (*,*) \" \"\nwrite (*,*) \" \"\nwrite(*,*) \"dp: function 1/(s^2) with inverse function t [Stehfest-limit=12]\"\nwrite (*,*) '-------------------------------------------------------------------------------------------'\nwrite (*,*) \"time t analytical inverse Stehfest-inverted relativ error\"\nwrite (*,*) '-------------------------------------------------------------------------------------------'\ndo n=1_i4,size(test_s)\n write (*,*) test_s(n), comp_func1(n), comp_func2(n), abs((comp_func2(n)-comp_func1(n))/comp_func1(n))\n dtmp = NLInvSteh(testfuncsgl, testpara, test_s(n), 12)\n isgood = isgood .and. eq(comp_func2(n), dtmp)\n isgood = isgood .and. (int((comp_func2(n)-compvalue(n))*1000000.0_dp, i4) .eq. 0_i4)\nend do\n\n!-------\n! sp\n!-------\n\ncompvalue_sp = (/&\n 1.00012207_sp,&\n 2.00024414_sp,&\n 3.00002766_sp,&\n 4.00048828_sp,&\n 5.02748299_sp,&\n 6.00005531_sp,&\n 6.81852579_sp,&\n 8.00097656_sp,&\n 9.01331997_sp,&\n 10.0549660_sp/)\n\ntestpara_sp=(/0.0_sp,2.0_sp,0.0_sp,0.0_sp,0.0_sp,0.0_sp,0.0_sp,0.0_sp,0.0_sp,0.0_sp/)\n\ncomp_func1_sp=test_s_sp\ncomp_func2_sp=NLInvSteh(testfuncvecsp, testpara_sp, test_s_sp, 12)\n\nwrite (*,*) \" \"\nwrite(*,*) \"sp: function 1/(s^2) with inverse function t [Stehfest-limit=12]\"\nwrite (*,*) '--------------------------------------------------------------------'\nwrite (*,*) \"time t analytical inverse Stehfest-inverted relativ error\"\nwrite (*,*) '--------------------------------------------------------------------'\ndo n=1_i4,size(test_s_sp)\n write (*,*) test_s_sp(n), comp_func1_sp(n), comp_func2_sp(n), abs((comp_func2_sp(n)-comp_func1_sp(n))/comp_func1_sp(n))\n stmp = NLInvSteh(testfuncsglsp, testpara_sp, test_s_sp(n), 12)\n isgood = isgood .and. eq(comp_func2_sp(n), stmp)\n isgood = isgood .and. (int((comp_func2_sp(n)-compvalue_sp(n))*1000.0_sp, i4) .eq. 0_i4)\nend do\n\n!!--------------------------------------------------------------------------------------------------\n!! 3. function makes --> problems with different compiliers\n!!--------------------------------------------------------------------------------------------------\n\n!!-------\n!! dp\n!!-------\n\n!compvalue = (/&\n! 1.0072917132281780_dp,&\n! 16.116667411650848_dp,&\n! 81.590628772012082_dp,&\n! 257.86667858641357_dp,&\n! 629.55732075484286_dp,&\n! 1305.4500603521933_dp,&\n! 2418.5074034629538_dp,&\n! 4125.8668573826171_dp,&\n! 6608.8409304767702_dp,&\n! 10072.917132077486_dp/)\n\n!testpara=(/0.0_dp,0.0_dp,2.0_dp,0.0_dp,0.0_dp,0.0_dp,0.0_dp,0.0_dp,0.0_dp,0.0_dp/)\n\n!comp_func1=test_s(:)**4_i4\n!comp_func2=NLInvSteh(testfuncvec, testpara, test_s, 12)\n\n!write (*,*) \" \"\n!write (*,*) \" \"\n!write (*,*) \"dp: function 24/(s^5) with inverse function t^4 [Stehfest-limit=12]\"\n!write (*,*) '----------------------------------------------------------------------------------------------------------------------'\n!write (*,*) \"time t analytical inverse Stehfest-inverted relativ error\"\n!write (*,*) '-------------------------------------------------------------------------------------------------------'\n!do n=1_i4,size(test_s)\n! write (*,*) test_s(n), comp_func1(n), comp_func2(n), abs((comp_func2(n)-comp_func1(n))/comp_func1(n))\n\n! isgood = isgood .and. eq(comp_func2(n),NLInvSteh(testfuncsgl, testpara, test_s(n), 12))\n! isgood = isgood .and. (int((comp_func2(n)-compvalue(n))*1000000.0_dp, i4) .eq. 0_i4)\n!end do\n\n!!-------\n!! sp\n!!-------\n\n!compvalue_sp = (/&\n! 1.01060343_sp,&\n! 16.1696548_sp,&\n! 81.7020187_sp,&\n! 258.714478_sp,&\n! 625.435364_sp,&\n! 1307.23230_sp,&\n! 2387.24829_sp,&\n! 4139.43164_sp,&\n! 6627.02637_sp,&\n! 10006.9658_sp/)\n\n!testpara_sp=(/0.0_sp,0.0_sp,2.0_sp,0.0_sp,0.0_sp,0.0_sp,0.0_sp,0.0_sp,0.0_sp,0.0_sp/)\n\n!comp_func1_sp=test_s_sp(:)**4_i4\n!comp_func2_sp=NLInvSteh(testfuncvecsp, testpara_sp, test_s_sp, 12)\n\n!write (*,*) \" \"\n!write (*,*) \"sp: function 24/(s^5) with inverse function t^4 [Stehfest-limit=12]\"\n!write (*,*) '----------------------------------------------------------------------------------------------------------------------'\n!write (*,*) \"time t analytical inverse Stehfest-inverted relativ error\"\n!write (*,*) '-------------------------------------------------------------------------------------------------------'\n!do n=1_i4,size(test_s_sp)\n! write (*,*) test_s_sp(n), comp_func1_sp(n), comp_func2_sp(n), abs((comp_func2_sp(n)-comp_func1_sp(n))/comp_func1_sp(n))\n\n! isgood = isgood .and. eq(comp_func2_sp(n),NLInvSteh(testfuncsglsp, testpara_sp, test_s_sp(n), 12))\n! isgood = isgood .and. (int((comp_func2_sp(n)-compvalue_sp(n))*1000.0_sp, i4) .eq. 0_i4)\n!end do\n\n!--------------------------------------------------------------------------------------------------\n! 4. function\n!--------------------------------------------------------------------------------------------------\n\n!-------\n! dp\n!-------\n\ncompvalue = (/&\n 0.83959871008261233_dp,&\n 0.94458688164622640_dp,&\n 3.2028647167191657E-002_dp,&\n -0.82004733974486821_dp,&\n -0.55999021955903139_dp,&\n -2.2709467812679900E-002_dp,&\n 0.22006692791712928_dp,&\n 0.21684512943141837_dp,&\n 0.13265657517960888_dp,&\n 5.5232344654943893E-002_dp/)\n\ntestpara=(/0.0_dp,0.0_dp,0.0_dp,2.0_dp,0.0_dp,0.0_dp,0.0_dp,0.0_dp,0.0_dp,0.0_dp/)\n\ncomp_func1=sin(test_s(:))\ncomp_func2=NLInvSteh(testfuncvec, testpara, test_s, 12)\n\nwrite (*,*) \" \"\nwrite (*,*) \" \"\nwrite (*,*) \"dp: function 1/(s^2 + 1) with inverse function sin(t) [Stehfest-limit=12]\"\nwrite (*,*) '-------------------------------------------------------------------------------------------'\nwrite (*,*) \"time t analytical inverse Stehfest-inverted relativ error\"\nwrite (*,*) '-------------------------------------------------------------------------------------------'\ndo n=1_i4,size(test_s)\n write (*,*) test_s(n), comp_func1(n), comp_func2(n), abs((comp_func2(n)-comp_func1(n))/comp_func1(n))\n dtmp = NLInvSteh(testfuncsgl, testpara, test_s(n), 12)\n isgood = isgood .and. eq(comp_func2(n), dtmp)\n isgood = isgood .and. (int((comp_func2(n)-compvalue(n))*1000000.0_dp, i4) .eq. 0_i4)\nend do\n\nmeansq_err=0.0_dp\ndo m=1_i4, size(meansq_err)\n ! write (*,*) \" \"\n ! write (*,*) \"stehfest-limit: \", 2*m\n comp_func2=NLInvSteh(testfuncvec, testpara, test_s, 2*m)\n ! write (*,*) \" \"\n ! write (*,*) \"function 1/(s^2 + 1) with inverse function sin(t)\"\n ! write (*,*) '-------------------------------------------------------------------------------------------'\n ! write (*,*) \"time t analytical inverse Stehfest-inverted relativ error\"\n ! write (*,*) '-------------------------------------------------------------------------------------------'\n do n=1_i4,size(test_s)\n ! write (*,*) test_s(n), comp_func1(n), comp_func2(n), abs((comp_func2(n)-comp_func1(n))/comp_func1(n))\n meansq_err(m)=meansq_err(m)+(comp_func2(n)-comp_func1(n))**2\n end do\nend do\n\nwrite (*,*) \" \"\nwrite (*,*) \"MSE between the stehfest-inverted- and analytical-function in dependency of the stehfestlimit\"\nwrite (*,*) '---------------------------------------------------------------------------------------------'\ndo m=1_i4,size(meansq_err)\n write (*,*) \"stehfest-limit with MSE: \", 2*m,\":\", meansq_err(m)\nend do\nwrite (*,*) \"least absolut MSE with Stehfest-limit: \", minloc(meansq_err)*2\nwrite (*,*) ' '\n\n!-------\n! sp\n!-------\n\ncompvalue_sp = (/&\n 0.840711713_sp,&\n 0.959169507_sp,&\n 6.67876154E-02_sp,&\n -0.852895975_sp,&\n -0.582676828_sp,&\n 6.31774813E-02_sp,&\n 0.236722142_sp,&\n 0.222023711_sp,&\n 0.134778619_sp,&\n 6.28164634E-02_sp/)\n\ntestpara_sp=(/0.0_sp,0.0_sp,0.0_sp,2.0_sp,0.0_sp,0.0_sp,0.0_sp,0.0_sp,0.0_sp,0.0_sp/)\n\ncomp_func1_sp=sin(test_s_sp(:))\ncomp_func2_sp=NLInvSteh(testfuncvecsp, testpara_sp, test_s_sp, 12)\n\nwrite (*,*) \" \"\nwrite (*,*) \" \"\nwrite (*,*) \"sp: function 1/(s^2 + 1) with inverse function sin(t) [Stehfest-limit=12]\"\nwrite (*,*) '-------------------------------------------------------------------------'\nwrite (*,*) \"time t analytical inverse Stehfest-inverted relativ error\"\nwrite (*,*) '-------------------------------------------------------------------------'\ndo n=1_i4,size(test_s_sp)\n write (*,*) test_s_sp(n), comp_func1_sp(n), comp_func2_sp(n), abs((comp_func2_sp(n)-comp_func1_sp(n))/comp_func1_sp(n))\n stmp = NLInvSteh(testfuncsglsp, testpara_sp, test_s_sp(n), 12)\n isgood = isgood .and. eq(comp_func2_sp(n), stmp)\n#ifdef __INTEL__\n !MC Intel work around hopefully temporary\n isgood = isgood .and. (int((comp_func2_sp(n)-compvalue_sp(n))*10.0_sp, i4) .eq. 0_i4)\n#else\n isgood = isgood .and. (int((comp_func2_sp(n)-compvalue_sp(n))*1000.0_sp, i4) .eq. 0_i4)\n#endif\nend do\n\n\nmeansq_err_sp=0.0_sp\ndo m=1_i4, size(meansq_err_sp)\n ! write (*,*) \" \"\n ! write (*,*) \"stehfest-limit: \", 2*m\n comp_func2_sp=NLInvSteh(testfuncvecsp, testpara_sp, test_s_sp, 2*m)\n ! write (*,*) \" \"\n ! write (*,*) \"function 1/(s^2 + 1) with inverse function sin(t)\"\n ! write (*,*) '-------------------------------------------------------------------------------------------'\n ! write (*,*) \"time t analytical inverse Stehfest-inverted relativ error\"\n ! write (*,*) '-------------------------------------------------------------------------------------------'\n do n=1_i4,size(test_s_sp)\n ! write (*,*) test_s_sp(n), comp_func1_sp(n), comp_func2_sp(n), abs((comp_func2_sp(n)-comp_func1_sp(n))/comp_func1_sp(n))\n meansq_err_sp(m)=meansq_err_sp(m)+(comp_func2_sp(n)-comp_func1_sp(n))**2\n end do\nend do\n\nwrite (*,*) \" \"\nwrite (*,*) \"MSE between the stehfest-inverted- and analytical-function in dependency of the stehfestlimit\"\nwrite (*,*) '---------------------------------------------------------------------------------------------'\ndo m=1_i4, size(meansq_err_sp)\n write (*,*) \"stehfest-limit with MSE: \", 2*m,\":\", meansq_err_sp(m)\nend do\nwrite (*,*) \"least absolut MSE with Stehfest-limit: \", minloc(meansq_err_sp)*2\nwrite (*,*) ' '\n\n!--------------------------------------------------------------------------------------------------\n\nwrite (*,*) '-------------------------------------------------------------------------'\nwrite (*,*) '-------------------------------------------------------------------------'\nwrite (*,*) ' '\nif (isgood) then\n write(*,*) 'mo_laplace_inversion ', color('o.k.', c_green)\nelse\n write(*,*) 'mo_laplace_inversion ', color('failed', c_red)\nendif\n\nend program test\n\n\nfunction testfuncvec(s, para)\n use mo_kind, only: i4, dp\n implicit none\n real(dp), dimension(:), intent(in) :: s\n real(dp), dimension(:), intent(in) :: para\n real(dp), dimension(size(s)) :: testfuncvec\n\n testfuncvec = 0.0_dp\n\n if (para(1)>1) testfuncvec=1.0_dp/(s(:) + 1.0_dp)\n if (para(2)>1) testfuncvec=1.0_dp/(s(:)**2_i4)\n if (para(3)>1) testfuncvec=24.0_dp/(s(:)**5_i4)\n if (para(4)>1) testfuncvec=1.0_dp/(s(:)**2_i4 +1.0_dp)\n\nend function testfuncvec\n\nfunction testfuncsgl(s, para)\n use mo_kind, only: i4, dp\n implicit none\n real(dp), intent(in) :: s\n real(dp), dimension(:), intent(in) :: para\n real(dp) :: testfuncsgl\n\n testfuncsgl = 0.0_dp\n\n if (para(1)>1) testfuncsgl=1.0_dp/(s + 1.0_dp)\n if (para(2)>1) testfuncsgl=1.0_dp/(s**2_i4)\n if (para(3)>1) testfuncsgl=24.0_dp/(s**5_i4)\n if (para(4)>1) testfuncsgl=1.0_dp/(s**2_i4 +1.0_dp)\n\nend function testfuncsgl\n\nfunction testfuncvecsp(s, para)\n use mo_kind, only: i4, sp\n implicit none\n real(sp), dimension(:), intent(in) :: s\n real(sp), dimension(:), intent(in) :: para\n real(sp), dimension(size(s)) :: testfuncvecsp\n\n testfuncvecsp = 0.0_sp\n\n if (para(1)>1) testfuncvecsp=1.0_sp/(s(:) + 1.0_sp)\n if (para(2)>1) testfuncvecsp=1.0_sp/(s(:)**2_i4)\n if (para(3)>1) testfuncvecsp=24.0_sp/(s(:)**5_i4)\n if (para(4)>1) testfuncvecsp=1.0_sp/(s(:)**2_i4 +1.0_sp)\n\nend function testfuncvecsp\n\nfunction testfuncsglsp(s, para)\n use mo_kind, only: i4, sp\n implicit none\n real(sp), intent(in) :: s\n real(sp), dimension(:), intent(in) :: para\n real(sp) :: testfuncsglsp\n\n testfuncsglsp = 0.0_sp\n\n if (para(1)>1) testfuncsglsp=1.0_sp/(s + 1.0_sp)\n if (para(2)>1) testfuncsglsp=1.0_sp/(s**2_i4)\n if (para(3)>1) testfuncsglsp=24.0_sp/(s**5_i4)\n if (para(4)>1) testfuncsglsp=1.0_sp/(s**2_i4 +1.0_sp)\n\nend function testfuncsglsp\n", "meta": {"hexsha": "3452f568bea10d26e1d93b018f2cb247d4889dfc", "size": 21144, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/test_mo_laplace_inversion/main.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_laplace_inversion/main.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_laplace_inversion/main.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": 37.960502693, "max_line_length": 133, "alphanum_fraction": 0.506573969, "num_tokens": 6570, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382236515259, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.6940829290319543}} {"text": "module mod\n\ncontains\n real function add(x, y)\n real :: x\n real :: y\n real :: z\n z = 0.1\n add = x + y + z\n end function add\nend module mod\n\n\nprogram t\n\n use mod\n real :: r\n r = add(10.55, 5.1010)\n print *, r\n\nend program t\n", "meta": {"hexsha": "5a3001b2fc6e7ab75defa14653dc01016dd80b78", "size": 252, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/output_tests/func_out3.f90", "max_stars_repo_name": "clementval/fc", "max_stars_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/output_tests/func_out3.f90", "max_issues_repo_name": "clementval/fc", "max_issues_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/output_tests/func_out3.f90", "max_forks_repo_name": "clementval/fc", "max_forks_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "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": 11.4545454545, "max_line_length": 26, "alphanum_fraction": 0.5277777778, "num_tokens": 91, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8615382094310357, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.6940829135549165}} {"text": "program blockmatrix\n implicit none\n integer, dimension(:,:), codimension[:,:], allocatable :: a, b, c\n integer, dimension(:,:), allocatable :: bigmat\n integer :: numimgs\n integer :: nrows, ncols\n integer :: blockrows=5, blockcols=5\n integer :: myrow, mycol\n integer :: startrow, startcol\n integer :: i,j,k\n\n ! calculate block decomposition\n numimgs = num_images()\n call nearsquare(numimgs, nrows, ncols)\n if (nrows /= ncols) then\n print *,'Sorry, only works for square numbers of images right now.'\n stop\n endif\n allocate(a(blockrows,blockcols)[nrows,*])\n allocate(b(blockcols,blockrows)[nrows,*])\n allocate(c(blockrows,blockrows)[nrows,*])\n\n ! where is this image in the decomposition?\n mycol = ceiling(this_image()*1./nrows)\n myrow = modulo(this_image(),nrows)\n if (myrow == 0) myrow=nrows\n\n ! initialize data\n startrow = (myrow-1)*blockrows+1\n startcol = (mycol-1)*blockcols+1\n do i=1,blockrows\n a(i,:) = startrow+i-1\n enddo\n do j=1,blockcols\n b(:,j) = startcol+j-1\n enddo\n\n ! do the multiplication\n sync all\n c = 0.\n do k=1,ncols\n c = c + matmul(a(:,:)[myrow,k],b(:,:)[k,mycol])\n enddo\n sync all\n\n if (this_image() == 1) then\n allocate(bigmat(nrows*blockrows,ncols*blockcols))\n bigmat = reshape( [((i,i=1,nrows*blockrows),j=1,ncols*blockcols)], &\n [nrows*blockrows, ncols*blockcols])\n print *, 'Expected answer: '\n bigmat = matmul(bigmat,transpose(bigmat))\n do i=1,blockrows*nrows\n print '(50(I5,1X))',(bigmat(i,j),j=1,blockcols*ncols)\n enddo\n deallocate(bigmat)\n endif\n\n do k=1,num_images()\n if (this_image() == k) then\n print *, 'Image ', k, ' = ', myrow, ', ', mycol \n do i=1,blockrows\n print '(50(I5,1X))',(c(i,j),j=1,blockcols)\n enddo\n endif\n sync all\n enddo\n deallocate(a)\n deallocate(b)\n deallocate(c)\n\ncontains \n subroutine nearsquare(n, a, b)\n implicit none\n integer, intent(in) :: n\n integer, intent(out) :: a, b\n\n do a=ceiling(sqrt(n*1.0)),1,-1\n b = n/a\n if (a*b == n) exit\n enddo\n end subroutine nearsquare\n\nend program blockmatrix\n", "meta": {"hexsha": "f68585a209e39fa7dc74b9b51853e5deea787f31", "size": 2325, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": ".testfiles/blockmatrix-coarray.f90", "max_stars_repo_name": "eugeneswalker/taucmdr", "max_stars_repo_head_hexsha": "33190f5268678979700793229602a5ec7638783e", "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": ".testfiles/blockmatrix-coarray.f90", "max_issues_repo_name": "eugeneswalker/taucmdr", "max_issues_repo_head_hexsha": "33190f5268678979700793229602a5ec7638783e", "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": ".testfiles/blockmatrix-coarray.f90", "max_forks_repo_name": "eugeneswalker/taucmdr", "max_forks_repo_head_hexsha": "33190f5268678979700793229602a5ec7638783e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.6785714286, "max_line_length": 76, "alphanum_fraction": 0.5694623656, "num_tokens": 698, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381952105441, "lm_q2_score": 0.8056321959813274, "lm_q1q2_score": 0.6940829081292602}} {"text": "! Mikayla Webber\r\n! 4670 Numerical Analysis\r\n! Homework G Due 12.1.17\r\n\r\n! use at least three numerical methods to solve:\r\n! dy/dt = te^(3t) - 2y\r\n! y(0) = 0\r\n! for 0 <= t <= 2\r\n! for each method obtain at least 100 data points on your approximation and produce a graph for each method.\r\n\r\nprogram aopc\r\n implicit none\r\n\r\n integer :: i, neq, nsteps\r\n double precision :: a, b, dt\r\n double precision, allocatable, dimension(:, :) :: archive\r\n double precision, allocatable, dimension(:) :: f, t, u, f1, fi, fim1, fim2, fim3, fim4, yin, yout\r\n\r\n neq = 1\r\n a = 0.0d0\r\n b = 2.0d0\r\n nsteps = 100\r\n\r\n allocate(yin(neq), yout(neq), u(neq), t(0:nsteps), f(neq), archive(neq,0:nsteps))\r\n allocate(fi(neq), fim1(neq), fim2(neq), fim3(neq), fim4(neq))\r\n\r\n dt = ((b - a) / dble(nsteps))\r\n\r\n do i = 0, nsteps\r\n t(i) = (a + dble(i) * dt)\r\n end do\r\n\r\n archive (:,0) = (/ 1.0d0, 0.0d0, 0.0d0, 1.0d0 /) ! initial state vector\r\n call abinitializer(neq, nsteps, t, archive)\r\n\r\n do i = 4, (nsteps - 1)\r\n call computef(neq, t(i), archive(:,i), fi)\r\n call computef(neq, t(i-1), archive(:,i-1), fim1)\r\n call computef(neq, t(i-2), archive(:,i-2), fim2)\r\n call computef(neq, t(i-3), archive(:,i-3), fim3)\r\n call computef(neq, t(i-4), archive(:,i-4), fim4)\r\n u = archive(:,i) + dt / 720.0d0 * (1901.0d0 * fi - 2774.0d0 * fim1 + 2616.0d0 * fim2 - 1274.0d0 * fim3 + 251.0d0 * fim4)\r\n end do\r\n\r\n print*, 'Creating \"out5.2.3\"'\r\n open(unit=8, file='out5.2.3', status='replace')\r\n\r\n do i = 0, nsteps\r\n write(8,*) t(i), archive(1,i)\r\n end do\r\n\r\n close(8)\r\n deallocate(yin, yout, u, f, t, f1, fi, fim1, fim2, fim3, fim4, archive)\r\n\r\n stop\r\nend program aopc\r\n\r\n!----------------------------------------------------------------------\r\n\r\nsubroutine computef(neq, t, y, f)\r\n implicit none\r\n integer :: neq\r\n double precision :: f(neq)\r\n double precision, intent(in) :: t, y(neq)\r\n ! This subroutine computes the RHS of the differential equation:\r\n ! dy\r\n ! -- = f(t, y)\r\n ! dt\r\n ! where y is the array of unknowns, indexed from one to neq and f is the array of right sides.\r\n\r\n !y(0) = 0\r\n f(1) = (t * dexp(3.0d0 * t) - 2.0d0 * y(1))\r\n\r\n return\r\nend\r\n\r\n!-----------------------------------------------------------------------\r\n\r\nsubroutine abinitializer(neq, nsteps, t, archive)\r\n implicit none\r\n integer :: i, nsteps\r\n integer, intent(in) :: neq\r\n double precision, intent(in) :: t(0:nsteps)\r\n double precision :: tin, tout, yin(neq), yout(neq), archive(neq,0:nsteps)\r\n\r\n do i = 0, neq\r\n tin = t(i)\r\n yin = archive(:,i)\r\n tout = t(i+1)\r\n call extrapolate(neq, tin, tout, yin, yout)\r\n archive(:,i+1) = yout\r\n end do\r\n\r\n return\r\nend\r\n\r\n!-----------------------------------------------------------------------\r\n\r\nsubroutine extrapolate(neq, tin, tout, yin, yout)\r\n implicit none\r\n\r\n integer, intent(in) :: neq\r\n integer :: i, k, nrich, nsteps\r\n double precision :: yout(neq), bot\r\n double precision, intent(in) :: tin, tout, yin(neq)\r\n double precision, allocatable, dimension(:, :, :) :: table\r\n\r\n nrich = 10\r\n nsteps = 1\r\n allocate(table(0:nrich, 0:nrich, neq))\r\n\r\n do i = 0, nrich\r\n call euler(neq, tin, tout, nsteps, yin, yout)\r\n table(i,0,:) = yout\r\n nsteps = (nsteps * 2)\r\n end do\r\n\r\n do k = 1, nrich\r\n bot = (2.0d0**k - 1.0d0)\r\n do i = k, nrich\r\n table(i,k,:) = (table(i,k-1,:) + (table(i,k-1,:) - table(i-1,k-1,:)) / bot)\r\n end do\r\n end do\r\n\r\n yout = table(nrich, nrich, :)\r\n return\r\nend\r\n\r\n!-----------------------------------------------------------------------\r\n\r\nsubroutine euler(neq, tin, tout, nsteps, yin, yout)\r\n implicit none\r\n\r\n integer :: i\r\n integer, intent(in) :: neq, nsteps\r\n double precision :: yout(neq), f(neq), dt\r\n double precision, intent(in) :: tin, tout, yin(neq)\r\n\r\n yout = yin\r\n dt = ((tout - tin)/dble(nsteps))\r\n\r\n do i = 0, (nsteps - 1)\r\n call computef(neq, (tin + dble(i) * dt), yout, f)\r\n yout = (yout + dt * f)\r\n end do\r\n\r\n return\r\nend\r\n", "meta": {"hexsha": "c734c844cf5d6ea695eb5f20a2d69631fd296a1f", "size": 3976, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "4670 Numerical Analysis/HomeworkG/Question2Method3.f90", "max_stars_repo_name": "mwebber3/UnderGraduateCourses", "max_stars_repo_head_hexsha": "0040791609ad4dd4336077f072106f8f31fdf8df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "4670 Numerical Analysis/HomeworkG/Question2Method3.f90", "max_issues_repo_name": "mwebber3/UnderGraduateCourses", "max_issues_repo_head_hexsha": "0040791609ad4dd4336077f072106f8f31fdf8df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "4670 Numerical Analysis/HomeworkG/Question2Method3.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": 26.6845637584, "max_line_length": 125, "alphanum_fraction": 0.53722334, "num_tokens": 1391, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381952105442, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.6940829000881543}} {"text": "real function add(x, y)\n real :: x\n real :: y\n real :: z\n z = 0.1\n add = x + y + z\nend function add\n\nprogram t\n\n real :: r\n r = add(10.55, 5.1010)\n print *, r\n\nend program t\n", "meta": {"hexsha": "8c85e7ddd2194e3325bbf40d96f5c57db6eb4702", "size": 183, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/output_tests/func_out2.f90", "max_stars_repo_name": "clementval/fc", "max_stars_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/output_tests/func_out2.f90", "max_issues_repo_name": "clementval/fc", "max_issues_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/output_tests/func_out2.f90", "max_forks_repo_name": "clementval/fc", "max_forks_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "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": 11.4375, "max_line_length": 24, "alphanum_fraction": 0.5355191257, "num_tokens": 76, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.841825655188238, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.6940532013497135}} {"text": "module vector_utils_m\nuse constants_m\nimplicit none\n\ncontains\n\n\nfunction p_norm(v1,p) result(s)\n real(rp),dimension(:),intent(in)::v1\n integer,intent(in)::p\n real(rp)::s\n s=sum(abs(v1)**p)**(one/p)\nend function\n\n\n\nfunction vec_mag(v1) result(s)\n real(rp),dimension(:),intent(in)::v1\n real(rp)::s\n s=sqrt(dot_product(v1,v1))\nend function\n\n\n\n\nfunction unit_vec(v1) result(v)\n real(rp),dimension(:),intent(in)::v1\n real(rp),dimension(size(v1))::v\n v=v1/(vec_mag(v1)+small)\nend function\n\n\n\n\nfunction cross_prod(v1,v2) result(v)\n real(rp),dimension(3),intent(in)::v1,v2\n real(rp),dimension(3)::v\n integer,dimension(3),parameter::i1=(/2,3,1/)\n integer,dimension(3),parameter::i2=(/3,1,2/)\n v=v1(i1)*v2(i2)-v2(i1)*v1(i2)\nend function\n\n\n\nfunction vvec_mag(v1) result(v)\n real(rp),dimension(:,:),intent(in)::v1\n real(rp),dimension(size(v1,2))::v\n integer::i\n do i=1,size(v)\n v(i)=vec_mag(v1(:,i))\n end do\nend function\n\n\n\nfunction rev_order(v1) result(v)\n integer,dimension(:),intent(in)::v1\n integer,dimension(size(v1))::v\n integer::i,j\n j=0\n do i=size(v1),1,-1\n j=j+1\n v(i)=v1(j)\n end do\nend function\n\n\n\n\nfunction first_loc(v1,s1) result(s)\n integer,dimension(:),intent(in)::v1\n integer,intent(in)::s1\n integer::s,i\n s=0\n do i=1,size(v1)\n select case(v1(i)-s1)\n case(0)\n s=i\n return\n end select\n end do\nend function\n\n\n\n! C\nsubroutine setcp (n_lst, lst, iset)\n integer,intent(in)::n_lst\n integer,dimension(0:n_lst-1)::lst\n integer,intent(in)::iset\n\n integer::i, j, jj, k, l\n\n i = 0;\n do\n\n do j = i + 1, n_lst - 1\n jj = j;\n if (lst(j) /= lst(i)) then\n exit;\n end if\n if (j == n_lst - 1) jj = jj + 1;\n end do\n\n j = jj;\n\n do k = i + 1, j - 1\n lst(k) = iset;\n end do\n\n i = j;\n if (i >= n_lst - 1) exit;\n end do\nend subroutine\n\n\n\n! C\nsubroutine hpsortf (n, ra)\n integer,intent(in)::n\n! integer,dimension(n)::ra\n real(rp),dimension(n)::ra\n\n integer::l,ir,i,j\n! integer::rra\n real(rp)::rra\n\n l=n/2+1\n ir=n\n\n10 continue\n if(l > 1)then\n l=l-1\n rra=ra(l)\n else\n rra=ra(ir)\n ra(ir)=ra(1)\n ir=ir-1\n if(ir.eq.1)then\n ra(1)=rra\n return\n end if\n end if\n i=l\n j=l+l\n\n20 if(j.le.ir)then\n if(j < ir)then\n if(ra(j) < ra(j+1)) j=j+1\n end if\n if(rra < ra(j))then\n ra(i)=ra(j)\n i=j; j=j+j\n else\n j=ir+1\n end if\n goto 20\n end if\n\n ra(i)=rra\n goto 10\nend subroutine\n\n\n\n! C\nsubroutine hpsorti (n, ra)\n integer,intent(in)::n\n integer,dimension(n)::ra\n! real(rp),dimension(n)::ra\n\n integer::l,ir,i,j\n integer::rra\n! real(rp)::rra\n\n l=n/2+1\n ir=n\n\n10 continue\n if(l > 1)then\n l=l-1\n rra=ra(l)\n else\n rra=ra(ir)\n ra(ir)=ra(1)\n ir=ir-1\n if(ir.eq.1)then\n ra(1)=rra\n return\n end if\n end if\n i=l\n j=l+l\n\n20 if(j.le.ir)then\n if(j < ir)then\n if(ra(j) < ra(j+1)) j=j+1\n end if\n if(rra < ra(j))then\n ra(i)=ra(j)\n i=j; j=j+j\n else\n j=ir+1\n end if\n goto 20\n end if\n\n ra(i)=rra\n goto 10\nend subroutine\n\n\n\n! C\nsubroutine uniq (m0, lst0, m1, lst1)\n integer, intent(in) :: m0\n integer, dimension(:), intent(in) :: lst0\n integer, intent(out) :: m1\n integer, dimension(:), allocatable :: lst1\n\n integer :: i, int_max\n\n allocate (lst1(m0))\n lst1 = lst0\n\n int_max = huge (i)\n call hpsorti (m0, lst1)\n call setcp (m0, lst1, int_max)\n call hpsorti (m0, lst1)\n\n m1 = 0\n do i = 1, m0\n if (lst1(i) < int_max) m1 = m1 + 1\n end do\nend subroutine\n\n\n\n\nsubroutine iuniq (m0, lst0)\n integer, intent(inout) :: m0\n integer, dimension(:), intent(inout) :: lst0\n\n integer :: i, int_max, m1\n\n int_max = huge (i)\n\n call hpsorti (m0, lst0)\n call setcp (m0, lst0, int_max)\n call hpsorti (m0, lst0)\n\n m1 = 0\n do i = 1, m0\n if (lst0(i) < int_max) m1 = m1 + 1\n end do\n m0 = m1\nend subroutine\nend module\n", "meta": {"hexsha": "743791ce3ff3049c2f06f800c89ca622c084ca51", "size": 3852, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/vector_utils_m.f90", "max_stars_repo_name": "DominicJones/pcns", "max_stars_repo_head_hexsha": "8097d78d190066cab82c64b96076c37a539efb92", "max_stars_repo_licenses": ["MIT"], "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/vector_utils_m.f90", "max_issues_repo_name": "DominicJones/pcns", "max_issues_repo_head_hexsha": "8097d78d190066cab82c64b96076c37a539efb92", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/vector_utils_m.f90", "max_forks_repo_name": "DominicJones/pcns", "max_forks_repo_head_hexsha": "8097d78d190066cab82c64b96076c37a539efb92", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 14.8725868726, "max_line_length": 46, "alphanum_fraction": 0.5758047767, "num_tokens": 1523, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619350028204, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.6940532004321591}} {"text": "!\n! CalculiX - A 3-dimensional finite element program\n! Copyright (C) 1998 Guido Dhondt\n!\n! This program is free software; you can redistribute it and/or\n! modify it under the terms of the GNU General Public License as\n! published by the Free Software Foundation(version 2);\n! \n!\n! This program is distributed in the hope that it will be useful,\n! but WITHOUT ANY WARRANTY; without even the implied warranty of \n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \n! GNU General Public License for more details.\n!\n! You should have received a copy of the GNU General Public License\n! along with this program; if not, write to the Free Software\n! Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n!\n subroutine straighteq2d(col,straight)\n!\n! calculate the equation of the edges of a triangle with \n! (col(1,1),col(2,1)),(col(1,2),col(2,2)),(col(1,3),col(2,3))\n! as vertices. The equation of the edge \n! opposite notet(1) is of the form\n! straight(1)*x+straight(2)*y+straight(3)=0, such that the\n! vector (straight(1),straight(2)) points outwards; for the edge\n! opposite of nodet(2) the equation is \n! straight(4)*x+straight(5)*y+straight(6)=0 and for the edge\n! oppositie of nodet(3) it is\n! straight(7)*x+straight(8)*y+straight(9)=0. Here too, the normals\n! (straight(4),straight(5)) and (straight(7),straight(8)) point\n! outwards of the triangle.\n!\n implicit none\n!\n real*8 col(2,3),straight(9),x1,y1,dd\n!\n! edge opposite of 1\n!\n x1=col(1,3)-col(1,2)\n y1=col(2,3)-col(2,2)\n dd=dsqrt(x1*x1+y1*y1)\n!\n straight(1)=y1/dd\n straight(2)=-x1/dd\n!\n straight(3)=-(straight(1)*col(1,3)+\n & straight(2)*col(2,3))\n!\n if(straight(1)*col(1,1)+straight(2)*col(2,1)+\n & straight(3).gt.0.d0) then\n straight(1)=-straight(1)\n straight(2)=-straight(2)\n straight(3)=-straight(3)\n endif\n!\n! edge opposite of 2\n!\n x1=col(1,1)-col(1,3)\n y1=col(2,1)-col(2,3)\n dd=dsqrt(x1*x1+y1*y1)\n!\n straight(4)=y1/dd\n straight(5)=-x1/dd\n!\n straight(6)=-(straight(4)*col(1,1)+\n & straight(5)*col(2,1))\n!\n if(straight(4)*col(1,2)+straight(5)*col(2,2)+\n & straight(6).gt.0.d0) then\n straight(4)=-straight(4)\n straight(5)=-straight(5)\n straight(6)=-straight(6)\n endif\n!\n! edge opposite of 3\n!\n x1=col(1,2)-col(1,1)\n y1=col(2,2)-col(2,1)\n dd=dsqrt(x1*x1+y1*y1)\n!\n straight(7)=y1/dd\n straight(8)=-x1/dd\n!\n straight(9)=-(straight(7)*col(1,2)+\n & straight(8)*col(2,2))\n!\n if(straight(7)*col(1,3)+straight(8)*col(2,3)+\n & straight(9).gt.0.d0) then\n straight(7)=-straight(7)\n straight(8)=-straight(8)\n straight(9)=-straight(9)\n endif\n!\n return\n end\n\n", "meta": {"hexsha": "2d76bcf1e62641ba901293551633894ebcb1bed6", "size": 2925, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ccx_prool/CalculiX/ccx_2.9/src/straighteq2d.f", "max_stars_repo_name": "alleindrach/calculix-desktop", "max_stars_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ccx_prool/CalculiX/ccx_2.9/src/straighteq2d.f", "max_issues_repo_name": "alleindrach/calculix-desktop", "max_issues_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2017-09-21T17:03:55.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-25T16:08:31.000Z", "max_forks_repo_path": "ccx_prool/CalculiX/ccx_2.9/src/straighteq2d.f", "max_forks_repo_name": "alleindrach/calculix-desktop", "max_forks_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-08-29T18:41:28.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-29T18:41:28.000Z", "avg_line_length": 29.8469387755, "max_line_length": 71, "alphanum_fraction": 0.588034188, "num_tokens": 990, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361652391385, "lm_q2_score": 0.7606506418255927, "lm_q1q2_score": 0.6940451547140333}} {"text": "module mod_condition\n use mod_kinds, only: rk,ik\n use mod_constants, only: ONE\n\n use mod_inv, only: inv\n\n implicit none\n\n ! External procedures defined in LAPACK\n external DGETRI\n external DGETRF\n external DGECON\n external DLANGE\n real(rk) :: DLANGE\n\ncontains\n\n! subroutine condition_number(dim1,dim2,mat,rcond)\n! integer(kind=ik), intent(in) :: dim1,dim2\n! real(kind=rk), intent(in), dimension(dim1,dim2) :: mat\n! real(kind=rk), intent(inout) :: rcond\n!\n!\n! real(kind=rk) :: mat_norm,invmat_norm\n! integer(kind=ik) :: i, info, j, n, idim1,idim2\n! real(kind=rk), dimension(dim1,dim2) :: invmat\n! real(kind=rk), dimension(dim2) :: vector_sum_mat, vector_sum_invmat\n!\n! invmat = inv(mat)\n!\n! ! compute the 1-norm of each matrix\n! do idim2 = 1,dim2\n! vector_sum_mat(idim2) = sum(abs(mat(:,idim2)))\n! vector_sum_invmat(idim2) = sum(abs(invmat(:,idim2)))\n! end do\n!\n! mat_norm = maxval(vector_sum_mat)\n! invmat_norm = maxval(vector_sum_invmat)\n!\n! ! compute the matrix condition number\n! rcond = mat_norm*invmat_norm\n!\n! end subroutine condition_number\n!\n\n\n\n\n\n !>\n !!\n !! @author Nathan A. Wukie\n !! @date 3/17/2016\n !!\n !! TODO: Try to find URL for citation.\n !!\n !---------------------------------------------------------------------------\n function cond(A) result(rcond_out)\n real(rk), dimension(:,:), intent(in) :: A\n real(rk), dimension(size(A,1),size(A,2)) :: Ainv\n\n! real(rk), dimension(size(A,1)) :: work ! work array for LAPACK\n real(rk), dimension(size(A,1)) :: nwork\n real(rk), dimension(size(A,1)*4) :: conwork\n integer, dimension(size(A,1)) :: iconwork\n integer, dimension(size(A,1)) :: ipiv ! pivot indices\n integer :: n, info\n\n real(rk) :: anorm, rcond\n real(rk) :: rcond_out\n\n\n\n ! Store A in Ainv to prevent it from being overwritten by LAPACK\n Ainv = A\n n = size(A,1)\n\n\n !\n ! Compute matrix 1-norm\n !\n anorm = DLANGE( 'I', n, n, A, n, nwork)\n \n\n ! DGETRF computes an LU factorization of a general M-by-N matrix A\n ! using partial pivoting with row interchanges.\n call DGETRF(n, n, Ainv, n, ipiv, info)\n\n if (info /= 0) then\n stop 'Matrix is numerically singular!'\n end if\n\n\n\n !\n ! DGECON Estimate condition number\n !\n call DGECON('I',n,Ainv,n,anorm,RCOND,conwork,iconwork, info)\n !print*, 'Jacobi condition number: ', ONE/RCOND\n\n !\n ! RCOND is reciprical of condition number, so invert for output\n !\n rcond_out = ONE/rcond\n\n\n end function cond\n !******************************************************************************\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nend module mod_condition\n", "meta": {"hexsha": "349f466ec4c516a4f53cab204e3117710dab90cd", "size": 3089, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tools/mod_condition.f90", "max_stars_repo_name": "wanglican/ChiDG", "max_stars_repo_head_hexsha": "d3177b87cc2f611e66e26bb51616f9385168f338", "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/tools/mod_condition.f90", "max_issues_repo_name": "haohb/ChiDG", "max_issues_repo_head_hexsha": "d3177b87cc2f611e66e26bb51616f9385168f338", "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/tools/mod_condition.f90", "max_forks_repo_name": "haohb/ChiDG", "max_forks_repo_head_hexsha": "d3177b87cc2f611e66e26bb51616f9385168f338", "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": 24.1328125, "max_line_length": 93, "alphanum_fraction": 0.5121398511, "num_tokens": 831, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361509525462, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.694045153748407}} {"text": "program main\n use, intrinsic :: iso_fortran_env\n use :: mod_is_positive\n use :: mod_mean\n implicit none\n\n block\n print *, all([is_positive(-1_int8), &\n is_positive(-1_int16), &\n is_positive(-1_int32), &\n is_positive(-1_int64), &\n is_positive(-1.0_real32), &\n is_positive(-1.0_real64)])\n\n print *, all([is_positive(1_int8), &\n is_positive(1_int16), &\n is_positive(1_int32), &\n is_positive(1_int64), &\n is_positive(1.0_real32), &\n is_positive(1.0_real64)])\n end block\n\n block\n real(real64) :: x5(1, 1, 1, 1, 1)\n real(real64) :: x10(1, 1, 1, 1, 1, &\n 1, 1, 1, 1, 1)\n real(real64) :: x15(1, 1, 1, 1, 1, &\n 1, 1, 1, 1, 1, &\n 1, 1, 1, 1, 1)\n x5 = 5d0\n x10 = 10d0\n x15 = 15d0\n print *, mean(x5), mean(x10), mean(x15)\n end block\nend program main\n", "meta": {"hexsha": "e3ba5bc34e94ceef19d9708064c112ccda2e0193", "size": 1116, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/example.f90", "max_stars_repo_name": "degawa/ex_fypp", "max_stars_repo_head_hexsha": "9c2732375712af7de323ad2a0212098e56bb54bd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-11-26T14:11:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-28T23:50:35.000Z", "max_issues_repo_path": "example/example.f90", "max_issues_repo_name": "degawa/ex_fypp", "max_issues_repo_head_hexsha": "9c2732375712af7de323ad2a0212098e56bb54bd", "max_issues_repo_licenses": ["MIT"], "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/example.f90", "max_forks_repo_name": "degawa/ex_fypp", "max_forks_repo_head_hexsha": "9c2732375712af7de323ad2a0212098e56bb54bd", "max_forks_repo_licenses": ["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": 49, "alphanum_fraction": 0.4202508961, "num_tokens": 333, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970904940927, "lm_q2_score": 0.7879311981328135, "lm_q1q2_score": 0.6940075068249066}} {"text": " double precision function arcosh(x)\nc!but\nc calcule l'arcosinus hyperbolique d'un double precision\nc!liste d'appel\nc double precision function arcosh(x)\nc double precision x\nc!\nc Copyright INRIA\n double precision x\n if (x.lt.1.0d+0) go to 10\n arcosh = log(x+sqrt(x*x-1.0d+0))\n return\n10 arcosh = 0.0d+0\n return\n end\n double precision function arsinh(x)\nc!but\nc calcule l'arcsinus hyperbolique d'un double precision\nc!liste d'appel\nc double precision function arsinh(x)\nc double precision x\nc!\n double precision x\nc\n arsinh = log(x+sqrt(x*x+1.0d+0))\n return\n end\n", "meta": {"hexsha": "a5fb6e6c72e47dc75f298f6afae1999b3dff0032", "size": 646, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/calelm/arcosh.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/arcosh.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/arcosh.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": 23.0714285714, "max_line_length": 56, "alphanum_fraction": 0.6563467492, "num_tokens": 207, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778824, "lm_q2_score": 0.7879312031126512, "lm_q1q2_score": 0.6940075013492205}} {"text": "!--------------------------------------------------------------------------------------\n!\n!Copyright (C) 2014 TopCoder Inc., All Rights Reserved.\n!\n!--------------------------------------------------------------------------------------\n\n!--------------------------------------------------------------------------------------\n! This module contains code to perform a double integration using Gauss-Legendre formula\n! Contest Implementation of Higher Order Panel Methods version 1.0\n!\n! @author yedtoss\n! @version 1.0\n!--------------------------------------------------------------------------------------\n\n! VERSIONS: gaussm3\n! This is based on gaussm2 - but with major changes that WEIGHTS & ABSCISSAS are no longer common variables\n! They are obtained from gauleg as local variables. User must specify what order of integration (# Gaussian Pts)\n! Consequently, all Gaussian Quadrature routines are modified with CALL gauleg.\n\n\n!\n! 9/9/98 - All ALLOCATED variables (pointers & allocatables) have been deallocated except for\n! WEIGhts and ABSCissas\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! NOTES\n! 1. This MODULE can be compiled on its own like header file.\n! Then a *.lib file is created. To use functions in module, \n! must have \"USE module_name\" statement.\n! 2. FATAL -- Specification of assumed size may be done for last dimension only.\n! a(*,*) wrong a(9,*) correct\n! 3. But -- Specification of assumed shape can be done in ANY dimension \n! a(:,:) O.K.\n! 4. \"Module\" is different from \"include\". Non-module files which have functions\n! can be included when compiling main file by using \"INCLUDE\" inside the main \n! file.\n! 5. Dummy arguments cannot be ALLOCATABLE. !!BUT!! Dummy arguments can have \n! assumed shapes such as a(:,:)\n! 6. INTENT must be used with dummy argument only.\n! 7. Array must not have both ALLOCATABLE and POINTER attributes, but\n! pointers can be ALLOCATED.\n! 8. POINTER array (eg. ans) must be declared with a deferred shape specification\n! (see \"Dynamic Arrays\" in the Lahey Fortran 90 Language Reference).\n! ans(3,4) wrong ans(:,:) correct\n! 9. When dummy arguments are pointers, their actual argument must be pointers\n! too; and vice versa.\n! 10. Intrinsic function MAXLOC(find location of maximum element e.g. in a list)\n! returns an ARRAY.\n! 11. Intrinsic function MATMUL for Matrix Multiplication can handle REAL of \n! selected_kind (eg. double precision)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n! 1. Topics: Gaussian elimination solution of linear equations & Gaussian Qudrature!\n! 2. The variables in this module are GLOBALLY COMMON to all PROGRAM UNITS that \"use\"s\n! this module and all INTERNAL subprograms within this module. The common variables are the\n! Gauss-Legendre abscissas and weights for the Gaussian Qudrature.\n! 3. The user must first call \"gauleg\" from the main program to set up all the abscissas\n! and weights.\n\nmodule gaussm3\n\n USE COMMON_TYPE\n\n ! Common Global variables within module !\n !implicit none\n INTEGER, parameter :: dbp = 1\n! PRIVATE\n REAL :: newv\n REAL :: EPS, M_PI\n PARAMETER (EPS=3.0d-15) !EPS is the relative precision\n PARAMETER (M_PI=3.141592654d0) ! Pi value\n\n! PUBLIC :: newv, EPS, M_PI, n, xabsc, weig, dbp, qgss2d\n!REAL :: newv, EPS, M_PI, n, xabsc, weig, dbp, qgss2d\n\n INTERFACE \n\n END INTERFACE\n\n CONTAINS\n!* This module has the following INTERNAL FUNCTIONS:\n!* gauleg, qgauss, qgss3d, qgss2d, gsselm, identity_matrix\n!* This module has the following INTERNAL SUBROUTINES:\n!* linear_solver\n!* They can call on each other without first specifying their type\n!* NO INTERFACE nor EXTERNAL is required since they are INTERNAL functions\n\n!********************************************************************************\n!* Calculation of GAUSS-LEGENDRE abscissas and weights for Gaussian Quadrature\n!* integration of polynomial functions.\n!* For normalized lower and upper limits of integration -1.0 & 1.0, and\n!* given n, this routine calculates, arrays xabsc(1:n) and weig(1:n) of length n,\n!* containing the abscissas and weights of the Gauss-Legendre n-point quadrature\n!* formula. For detailed explanations finding weights & abscissas, see\n!* \"Numerical Recipes in Fortran */\n!********************************************************************************\n SUBROUTINE gauleg(ngp, xabsc, weig)\n\n !implicit none\n INTEGER i, j, m\n REAL p1, p2, p3, pp, z, z1\n INTEGER, INTENT(IN) :: ngp ! # of Gauss Points\n REAL , INTENT(OUT) :: xabsc(ngp), weig(ngp)\n\n\n m = (ngp + 1) / 2\n!* Roots are symmetric in the interval - so only need to find half of them */\n\n do i = 1, m ! Loop over the desired roots */\n\n z = cos( M_PI * (i-0.25d0) / (ngp+0.5d0) )\n!* Starting with the above approximation to the ith root,\n!* we enter the main loop of refinement by NEWTON'S method */\n100 p1 = 1.0d0\n p2 = 0.0d0\n!* Loop up the recurrence relation to get the Legendre\n!* polynomial evaluated at z */\n\n do j = 1, ngp\n p3 = p2\n p2 = p1\n p1 = ((2.0d0*j-1.0d0) * z * p2 - (j-1.0d0)*p3) / j\n enddo\n\n!* p1 is now the desired Legendre polynomial. We next compute pp,\n!* its derivative, by a standard relation involving also p2, the\n!* polynomial of one lower order. */\n pp = ngp*(z*p1-p2)/(z*z-1.0d0)\n z1 = z\n z = z1 - p1/pp ! Newton's Method */\n\n if (abs(z-z1) .gt. EPS) GOTO 100\n\n xabsc(i) = - z ! Roots will be bewteen -1.0 & 1.0 */\n xabsc(ngp+1-i) = + z ! and symmetric about the origin */\n weig(i) = 2.0d0/((1.0d0-z*z)*pp*pp) ! Compute the weight and its */\n weig(ngp+1-i) = weig(i) ! symmetric counterpart */\n\n end do ! i loop\n\n End subroutine gauleg\n\n\n\n!**********************************************************************************\n!* Generic 2D Gaussian Quadraure Routines *\n!**********************************************************************************\n!* Use this function to calculate 2D integral by Gaussian Quadrature\n!* Must supply boundary conditions x1,x2, y1(x), y2(x)\n!* and the function to be integrated over f(x,y)\n RECURSIVE function qgss2d(origfn, xx1, xx2, yf1, yf2, ngp) RESULT(inth)\n !implicit none ! returns integral in inth\n REAL inth, xx1, xx2\n REAL xm, xl, xtmp\n INTEGER j\n INTEGER, INTENT(IN) :: ngp ! # of Gauss Points\n REAL :: xabsc(ngp), weig(ngp)\n\n\n\n interface\n real function origfn(xp,yp) ! Original Function's Interface\n !implicit none\n REAL xp, yp\n end function origfn\n real function yf1(x)\n !implicit none\n REAL x\n end function yf1\n real function yf2(x)\n !implicit none\n REAL x\n end function yf2\n end interface\n\n call gauleg(ngp, xabsc, weig)\n\n inth = 0.0d0\n xm = 0.5 * (xx2 + xx1)\n xl = 0.5 * (xx2 - xx1)\n\n do j = 1, ngp\n xtmp = xm + xl*xabsc(j) ! Gauss-Legendre Abcissas\n inth = inth + weig(j) * qgssgy()\n END do\n\n inth = inth * xl; !Scale the answer to the range of integration */\n\n CONTAINS\n RECURSIVE function qgssgy() RESULT(intg)\n !implicit none ! returns integral in intg\n REAL intg\n REAL ym, yl, ytmp ! all undeclared variables are\n INTEGER j ! COOMON with HOST\n\n intg = 0.0d0\n ym = 0.5 * (yf2(xtmp) + yf1(xtmp))\n yl = 0.5 * (yf2(xtmp) - yf1(xtmp))\n\n do j = 1, ngp\n ytmp = ym + yl*xabsc(j) ! Gauss-Legendre Abcissas\n intg = intg + weig(j) * origfn(xtmp,ytmp)\n END do\n\n intg = intg * yl; !Scale the answer to the range of integration */\n END function qgssgy\n\n END FUNCTION qgss2d\n\n\n\n\n!**********************************************************************************\n!* Generic 2D Gaussian Quadraure Routines *\n!**********************************************************************************\n!* Use this function to calculate 2D integral by Gaussian Quadrature\n!* Must supply boundary conditions x1,x2, y1(x), y2(x)\n!* and the function to be integrated over f(x,y)\n RECURSIVE function qgss2d_simple(origfn, xx1, xx2, yf1, yf2, ngp, param) RESULT(inth)\n !implicit none ! returns integral in inth\n REAL xx1, xx2, yf1, yf2\n COMPLEX inth\n REAL xm, xl, xtmp\n INTEGER j\n INTEGER, INTENT(IN) :: ngp ! # of Gauss Points\n REAL :: xabsc(ngp), weig(ngp)\n TYPE(ParamsCommonInf) :: param\n\n\n\n interface\n complex function origfn(xp,yp, param) ! Original Function's Interface\n USE COMMON_TYPE\n !implicit none\n REAL , INTENT(IN) :: xp, yp\n TYPE(ParamsCommonInf) :: param\n end function origfn\n\n end interface\n\n call gauleg(ngp, xabsc, weig)\n\n inth = 0.0d0\n xm = 0.5 * (xx2 + xx1)\n xl = 0.5 * (xx2 - xx1)\n\n do j = 1, ngp\n xtmp = xm + xl*xabsc(j) ! Gauss-Legendre Abcissas\n inth = inth + weig(j) * qgssgy()\n END do\n\n inth = inth * xl; !Scale the answer to the range of integration */\n\n CONTAINS\n RECURSIVE function qgssgy() RESULT(intg)\n !implicit none ! returns integral in intg\n COMPLEX intg\n REAL ym, yl, ytmp ! all undeclared variables are\n INTEGER j ! COOMON with HOST\n\n intg = cmplx(0.0, 0.0)\n ym = 0.5 * (yf2 + yf1)\n yl = 0.5 * (yf2 - yf1)\n\n do j = 1, ngp\n ytmp = ym + yl*xabsc(j) ! Gauss-Legendre Abcissas\n intg = intg + weig(j) * origfn(xtmp,ytmp, param)\n END do\n intg = intg * yl; !Scale the answer to the range of integration */\n END function qgssgy\n\n END FUNCTION qgss2d_simple\n \n \n end module gaussm3\n", "meta": {"hexsha": "de50afb4d21939f1429e862087e8d90d3b646725", "size": 10571, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/NemohImproved/Nemoh/Solver/Core/Gaussm3.f90", "max_stars_repo_name": "NREL/OpenWARP", "max_stars_repo_head_hexsha": "ca49c4cbde17e0cead69bd9e55a81d5c0fafe4df", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2015-06-22T07:35:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-23T05:10:09.000Z", "max_issues_repo_path": "source/NemohImproved/Nemoh/Solver/Core/Gaussm3.f90", "max_issues_repo_name": "rhydar/Test", "max_issues_repo_head_hexsha": "32dd54af2c3657d0c49177395d5b1c1f7bd8e127", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2015-07-30T20:01:35.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-28T17:29:18.000Z", "max_forks_repo_path": "source/NemohImproved/Nemoh/Solver/Core/Gaussm3.f90", "max_forks_repo_name": "rhydar/Test", "max_forks_repo_head_hexsha": "32dd54af2c3657d0c49177395d5b1c1f7bd8e127", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2016-04-01T07:45:27.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-06T08:33:33.000Z", "avg_line_length": 38.3007246377, "max_line_length": 116, "alphanum_fraction": 0.5343865292, "num_tokens": 2842, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970748488297, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.6940074923044026}} {"text": "\n! $UWHPSC/codes/lapack/random/randomsys2.f90\n\nprogram randomsys2\n implicit none\n real(kind=8), dimension(:),allocatable :: x,b\n real(kind=8), dimension(:,:),allocatable :: a\n real(kind=8) :: err\n integer :: i, info, lda, ldb, nrhs, n\n integer, dimension(:), allocatable :: ipiv\n\n ! initialize random number generator seed\n ! if you remove this, the same numbers will be generated each\n ! time you run this code.\n call init_random_seed() \n\n print *, \"Input n ... \"\n read *, n\n\n allocate(a(n,n))\n allocate(b(n))\n allocate(x(n))\n allocate(ipiv(n))\n\n call random_number(a)\n call random_number(x)\n b = matmul(a,x) ! compute RHS\n \n nrhs = 1 ! number of right hand sides in b\n lda = n ! leading dimension of a\n ldb = n ! leading dimension of b\n\n call dgesv(n, nrhs, a, lda, ipiv, b, ldb, info)\n\n ! Note: the solution is returned in b\n ! and a has been changed.\n\n ! compare computed solution to original x:\n print *, \" x computed rel. error\"\n do i=1,n\n err = abs(x(i)-b(i))/abs(x(i))\n print '(3d16.6)', x(i),b(i),err\n enddo\n\n deallocate(a,b,ipiv)\n\nend program randomsys2\n", "meta": {"hexsha": "7959a66f59bfcf93545ea592b9d73b3c7435380d", "size": 1201, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/codes/lapack/random/randomsys2.f90", "max_stars_repo_name": "philipwangdk/HPC", "max_stars_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "uwhpsc/codes/lapack/random/randomsys2.f90", "max_issues_repo_name": "philipwangdk/HPC", "max_issues_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "uwhpsc/codes/lapack/random/randomsys2.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": 25.0208333333, "max_line_length": 65, "alphanum_fraction": 0.5945045795, "num_tokens": 349, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.899121388082479, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6939809924407159}} {"text": "subroutine outnormal_2d(x_solid,edge_el,normal,nsd_solid,nen_solid,len)\n! calculate the outward normal for the edge on the solid interface\ninteger nsd_solid ! dimension of solid\ninteger nen_solid ! number of nodes in solid element\nreal(8) x_solid(nen_solid,nsd_solid) ! coordinates of solid node in the element\ninteger edge_el(nen_solid) ! flag matrix that deside if the node is on the interface\nreal(8) normal(nsd_solid) ! output for outward normal\nreal(8) len ! length of the edge on the boundary\nreal(8) a(nsd_solid)\nreal(8) b(nsd_solid)\nreal(8) c(nsd_solid)\nreal(8) d(nsd_solid) ! check notes for definition \nreal(8) tmp(2,nsd_solid)\ninteger i\ninteger j\nreal(8) f(2,2)\nreal(8) invf(2,2)\nreal(8) p(2)\nreal(8) det\nreal(8) l\nj=1\ndo i=1,nen_solid\n\tif (edge_el(i) .eq. 1) then ! nodes on the edge\n\t\ttmp(j,1:nsd_solid)=x_solid(i,1:nsd_solid)\n\t\tj=j+1\n\tend if\n\n\tif (edge_el(i) .eq. 0) then ! nodes not on the edge\n\t\tc(1:nsd_solid)=x_solid(i,1:nsd_solid)\n\tend if\nend do\na(1:nsd_solid)=tmp(1,1:nsd_solid)\nb(1:nsd_solid)=tmp(2,1:nsd_solid)\n\n\nf(1,1)=b(2)-a(2)\nf(1,2)=-(b(1)-a(1))\nf(2,1)=b(1)-a(1)\nf(2,2)=b(2)-a(2)\n\np(1)=a(1)*(b(2)-a(2))-a(2)*(b(1)-a(1))\np(2)=c(1)*(b(1)-a(1))+c(2)*(b(2)-a(2))\n\ndet=f(1,1)*f(2,2)-f(1,2)*f(2,1)\n\ninvf(1,1)=f(2,2)/det\ninvf(2,2)=f(1,1)/det\ninvf(1,2)=-f(1,2)/det\ninvf(2,1)=-f(2,1)/det\n\nd(:)=0.0d0\n\ndo i=1,nsd_solid\n\tdo j=1,nsd_solid\n\t\td(i)=d(i)+invf(i,j)*p(j)\n\tend do\nend do\n\nnormal(1:nsd_solid)=d(1:nsd_solid)-c(1:nsd_solid)\nl=normal(1)**2+normal(2)**2\nl=sqrt(l)\nnormal(1:nsd_solid)=normal(1:nsd_solid)/l\n\nlen=(a(1)-b(1))**2+(a(2)-b(2))**2\nlen=sqrt(len)\n\n!write(*,*) 'normal inward', normal(:)\nreturn\nend subroutine outnormal_2d\n", "meta": {"hexsha": "d12980008cb999bd19753ba53e3aa4eeeb31ca81", "size": 1650, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "outnormal_2d.f90", "max_stars_repo_name": "biofluids/IFEM-archive", "max_stars_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-15T11:40:16.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-15T11:40:16.000Z", "max_issues_repo_path": "outnormal_2d.f90", "max_issues_repo_name": "biofluids/IFEM-archive", "max_issues_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "outnormal_2d.f90", "max_forks_repo_name": "biofluids/IFEM-archive", "max_forks_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-02-11T16:50:21.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-08T07:24:59.000Z", "avg_line_length": 23.5714285714, "max_line_length": 84, "alphanum_fraction": 0.6733333333, "num_tokens": 764, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.899121388082479, "lm_q2_score": 0.7718434873426302, "lm_q1q2_score": 0.693980987721927}} {"text": "MODULE Exponential_Integral\r\n\r\n! ALGORITHM 683, COLLECTED ALGORITHMS FROM ACM.\r\n! THIS WORK PUBLISHED IN TRANSACTIONS ON MATHEMATICAL SOFTWARE,\r\n! VOL. 16, NO. 2, PP. 178-182.\r\n\r\nIMPLICIT NONE\r\nINTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(12, 60)\r\n\r\n! COMMON /qad/ fnm, gln, x, y, iflag\r\nREAL (dp), SAVE :: fnm, gln, x, y\r\nINTEGER, SAVE :: iflag\r\nPRIVATE\r\nPUBLIC :: cexint, cexqad\r\n\r\nCONTAINS\r\n\r\n\r\nSUBROUTINE cexqad(z, n, kode, tol, cw, kerr)\r\n\r\n! CEXQAD COMPUTES EXPONENTIAL INTEGRALS E(N,Z) OF A COMPLEX (dp) ARGUMENT\r\n! Z BY QUADRATURE ON (T**(N-1)*EXP(-T)/(Z+T))/(N-1)! FROM T=0 TO\r\n! T=INFINITY. KODE=1 RETURNS CW=E(N,Z) WHILE KODE=2 RETURNS\r\n! CW=E(N,Z)*CEXP(Z). TOL IS THE REQUESTED RELATIVE ERROR AND KERR.NE.0 IS\r\n! AN ERROR FLAG INDICATING A PREMATURE TRUNCATION OF AN INTEGRAL IN CEXQAD.\r\n! THE QUADRATURE IS DONE AS TWO REAL INTEGRALS SINCE Z IS COMPLEX (dp).\r\n\r\nCOMPLEX (dp), INTENT(IN) :: z\r\nINTEGER, INTENT(IN) :: n\r\nINTEGER, INTENT(IN) :: kode\r\nREAL (dp), INTENT(IN) :: tol\r\nCOMPLEX (dp), INTENT(OUT) :: cw\r\nINTEGER, INTENT(OUT) :: kerr\r\n\r\n! COMMON /qad/ fnm, gln, x, y, iflag\r\n! EXTERNAL fqcex\r\nREAL (dp) :: a, ans, b, fn, gm, s1, s2, xtol\r\nINTEGER :: i, ierr\r\n\r\nfn = n\r\nfnm = fn - 1.0\r\ngm = 1.0_dp\r\nIF (n /= 1) THEN\r\n DO i = 2, n\r\n gm = gm * (i-1)\r\n END DO\r\nEND IF\r\ngln = LOG(gm)\r\nkerr = 0\r\nx = REAL(z)\r\ny = AIMAG(z)\r\n!-----------------------------------------------------------------------\r\n! REAL PART OF E(N,Z)\r\n!-----------------------------------------------------------------------\r\niflag = 1\r\ns1 = 0.0_dp\r\nb = 0.0_dp\r\nDO i = 1, 100\r\n a = b\r\n b = b + 5.0_dp\r\n xtol = tol\r\n CALL gaus8(fqcex, a, b, xtol, ans, ierr)\r\n s1 = s1 + ans\r\n IF (ABS(ans) < ABS(s1)*tol) GO TO 30\r\nEND DO\r\nkerr = 1\r\n!-----------------------------------------------------------------------\r\n! IMAGINARY PART OF E(N,Z)\r\n!-----------------------------------------------------------------------\r\n30 iflag = 2\r\ns2 = 0.0_dp\r\nIF (y /= 0.0_dp) THEN\r\n b = 0.0_dp\r\n DO i = 1, 100\r\n a = b\r\n b = b + 5.0_dp\r\n xtol = tol\r\n CALL gaus8(fqcex, a, b, xtol, ans, ierr)\r\n s2 = s2 + ans\r\n IF (ABS(ans) < ABS(s2)*tol) GO TO 50\r\n END DO\r\n kerr = 2\r\nEND IF\r\n\r\n50 cw = CMPLX(s1, -s2, KIND=dp)\r\nIF (kode == 1) cw = cw * EXP(-z)\r\nRETURN\r\nEND SUBROUTINE cexqad\r\n\r\n\r\n\r\nFUNCTION fqcex(t) RESULT(fn_val)\r\n\r\nREAL (dp), INTENT(IN) :: t\r\nREAL (dp) :: fn_val\r\n\r\n! COMMON /qad/ fnm, gln, x, y, iflag\r\n\r\nREAL (dp) :: a, b\r\n\r\na = -t + fnm * LOG(t) - gln\r\na = EXP(a)\r\nIF (iflag /= 2) THEN\r\n b = (x+t) / ((x+t)**2 + y**2)\r\nELSE\r\n b = y / ((x+t)**2 + y**2)\r\nEND IF\r\nfn_val = a * b\r\nRETURN\r\nEND FUNCTION fqcex\r\n\r\n\r\n\r\nFUNCTION g8(fun, x, h) RESULT(fn_val)\r\n! Replaces the statement function g8 which was part of GAUS8\r\n\r\nREAL (dp), INTENT(IN) :: x, h\r\nREAL (dp) :: fn_val\r\n\r\nINTERFACE\r\n FUNCTION fun(x) RESULT(fn_val)\r\n IMPLICIT NONE\r\n INTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(12, 60)\r\n REAL (dp), INTENT(IN) :: x\r\n REAL (dp) :: fn_val\r\n END FUNCTION fun\r\nEND INTERFACE\r\n\r\nREAL (dp), PARAMETER :: x1 = 1.83434642495649805D-01, x2 = 5.25532409916328986D-01, &\r\n x3 = 7.96666477413626740D-01, x4 = 9.60289856497536232D-01\r\nREAL (dp), PARAMETER :: w1 = 3.62683783378361983D-01, w2 = 3.13706645877887287D-01, &\r\n w3 = 2.22381034453374471D-01, w4 = 1.01228536290376259D-01\r\n\r\nfn_val = h * ((w1*(fun(x-x1*h) + fun(x+x1*h)) + w2*(fun(x-x2*h) + &\r\n fun(x+x2*h))) + (w3*(fun(x-x3*h) + fun(x+x3*h)) + w4*(fun(x-x4*h) + &\r\n fun(x+x4*h))))\r\n\r\nRETURN\r\nEND FUNCTION g8\r\n\r\n\r\n\r\nSUBROUTINE gaus8(fun, a, b, ERR, ans, ierr)\r\n\r\n! WRITTEN BY R.E. JONES\r\n\r\n! ABSTRACT\r\n! GAUS8 INTEGRATES REAL FUNCTIONS OF ONE VARIABLE OVER FINITE INTERVALS\r\n! USING AN ADAPTIVE 8-POINT LEGENDRE-GAUSS ALGORITHM.\r\n! GAUS8 IS INTENDED PRIMARILY FOR HIGH ACCURACY INTEGRATION OR\r\n! INTEGRATION OF SMOOTH FUNCTIONS.\r\n\r\n! GAUS8 CALLS I1MACH, R1MACH, XERROR\r\n\r\n! DESCRIPTION OF ARGUMENTS\r\n\r\n! INPUT--\r\n! FUN - NAME OF EXTERNAL FUNCTION TO BE INTEGRATED. THIS NAME MUST BE\r\n! IN AN EXTERNAL STATEMENT IN THE CALLING PROGRAM.\r\n! FUN MUST BE A FUNCTION OF ONE REAL ARGUMENT. THE VALUE OF THE\r\n! ARGUMENT TO FUN IS THE VARIABLE OF INTEGRATION WHICH RANGES\r\n! FROM A TO B.\r\n! A - LOWER LIMIT OF INTEGRAL\r\n! B - UPPER LIMIT OF INTEGRAL (MAY BE LESS THAN A)\r\n! ERR - IS A REQUESTED PSEUDORELATIVE ERROR TOLERANCE. NORMALLY PICK A\r\n! VALUE OF ABS(ERR) SO THAT STOL < ABS(ERR) <= 1.0E-3 WHERE STOL\r\n! IS THE DOUBLE PRECISION UNIT ROUNDOFF = EPSILON(0.0_dp).\r\n! ANS WILL NORMALLY HAVE NO MORE ERROR THAN ABS(ERR) TIMES THE\r\n! INTEGRAL OF THE ABSOLUTE VALUE OF FUN(X).\r\n! USUALLY, SMALLER VALUES FOR ERR YIELD MORE ACCURACY AND\r\n! REQUIRE MORE FUNCTION EVALUATIONS.\r\n\r\n! A NEGATIVE VALUE FOR ERR CAUSES AN ESTIMATE OF THE\r\n! ABSOLUTE ERROR IN ANS TO BE RETURNED IN ERR. NOTE THAT\r\n! ERR MUST BE A VARIABLE (NOT A CONSTANT) IN THIS CASE.\r\n! NOTE ALSO THAT THE USER MUST RESET THE VALUE OF ERR\r\n! BEFORE MAKING ANY MORE CALLS THAT USE THE VARIABLE ERR.\r\n\r\n! OUTPUT--\r\n! ERR - WILL BE AN ESTIMATE OF THE ABSOLUTE ERROR IN ANS IF THE\r\n! INPUT VALUE OF ERR WAS NEGATIVE. (ERR IS UNCHANGED IF\r\n! THE INPUT VALUE OF ERR WAS NONNEGATIVE.) THE ESTIMATED\r\n! ERROR IS SOLELY FOR INFORMATION TO THE USER AND SHOULD\r\n! NOT BE USED AS A CORRECTION TO THE COMPUTED INTEGRAL.\r\n! ANS - COMPUTED VALUE OF INTEGRAL\r\n! IERR- A STATUS CODE\r\n! --NORMAL CODES\r\n! 1 ANS MOST LIKELY MEETS REQUESTED ERROR TOLERANCE, OR A=B.\r\n! -1 A AND B ARE TOO NEARLY EQUAL TO ALLOW NORMAL INTEGRATION.\r\n! ANS IS SET TO ZERO.\r\n! --ABNORMAL CODE\r\n! 2 ANS PROBABLY DOES NOT MEET REQUESTED ERROR TOLERANCE.\r\n!***END PROLOGUE\r\n\r\nREAL (dp), INTENT(IN) :: a\r\nREAL (dp), INTENT(IN) :: b\r\nREAL (dp), INTENT(IN OUT) :: ERR\r\nREAL (dp), INTENT(OUT) :: ans\r\nINTEGER, INTENT(OUT) :: ierr\r\n\r\n! EXTERNAL fun\r\nINTERFACE\r\n FUNCTION fun(x) RESULT(fn_val)\r\n IMPLICIT NONE\r\n INTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(12, 60)\r\n REAL (dp), INTENT(IN) :: x\r\n REAL (dp) :: fn_val\r\n END FUNCTION fun\r\nEND INTERFACE\r\n\r\nINTEGER :: k, l, lmn, lmx, lr(30), mxl, nbits, nib, nlmx\r\nREAL (dp) :: aa(30), ae, anib, area, c, ce, ee, ef, eps, est, gl, glr, &\r\n gr(30), hh(30), tol, vl(30), vr\r\nINTEGER, PARAMETER :: nlmn = 1, kmx = 5000, kml = 6\r\nINTEGER, SAVE :: icall = 0\r\nREAL (dp), PARAMETER :: sq2 = 1.41421356_dp\r\n\r\n! INITIALIZE\r\n\r\nIF (icall /= 0) THEN\r\n WRITE(*, *) 'GAUS8- GAUS8 CALLED RECURSIVELY; NOT ALLOWED HERE'\r\n RETURN\r\nEND IF\r\n\r\nicall = 1\r\nk = DIGITS(0.0_dp)\r\nanib = LOG10(DBLE(RADIX(0.0_dp))) * k / 0.30102000_dp\r\nnbits = INT(anib)\r\nnlmx = (nbits*5) / 8\r\nans = 0.0_dp\r\nierr = 1\r\nce = 0.0_dp\r\nIF (a /= b) THEN\r\n lmx = nlmx\r\n lmn = nlmn\r\n IF (b /= 0.0_dp) THEN\r\n IF (SIGN(1.0_dp,b)*a > 0.0_dp) THEN\r\n c = ABS(1.0_dp-a/b)\r\n IF (c <= 0.1_dp) THEN\r\n IF (c <= 0.0_dp) GO TO 100\r\n anib = 0.5_dp - LOG(c) / 0.69314718_dp\r\n nib = anib\r\n lmx = MIN(nlmx, nbits-nib-7)\r\n IF (lmx < 1) GO TO 90\r\n lmn = MIN(lmn,lmx)\r\n END IF\r\n END IF\r\n END IF\r\n tol = MAX(ABS(ERR), 2.0_dp**(5-nbits)) / 2.0_dp\r\n IF (ERR == 0.0_dp) tol = SQRT(EPSILON(0.0_dp))\r\n eps = tol\r\n hh(1) = (b-a) / 4.0_dp\r\n aa(1) = a\r\n lr(1) = 1\r\n l = 1\r\n est = g8(fun, aa(l)+2.0_dp*hh(l), 2.0_dp*hh(l))\r\n k = 8\r\n area = ABS(est)\r\n ef = 0.5_dp\r\n mxl = 0\r\n \r\n! COMPUTE REFINED ESTIMATES, ESTIMATE THE ERROR, ETC.\r\n \r\n 10 gl = g8(fun, aa(l)+hh(l), hh(l))\r\n gr(l) = g8(fun, aa(l)+3.0_dp*hh(l), hh(l))\r\n k = k + 16\r\n area = area + (ABS(gl) + ABS(gr(l)) - ABS(est))\r\n! IF (L < LMN) GO TO 11\r\n glr = gl + gr(l)\r\n ee = ABS(est-glr) * ef\r\n ae = MAX(eps*area, tol*ABS(glr))\r\n IF (ee-ae > 0.0) THEN\r\n GO TO 40\r\n ELSE\r\n GO TO 30\r\n END IF\r\n 20 mxl = 1\r\n 30 ce = ce + (est-glr)\r\n IF (lr(l) > 0) THEN\r\n GO TO 70\r\n ELSE\r\n GO TO 50\r\n END IF\r\n \r\n! CONSIDER THE LEFT HALF OF THIS LEVEL\r\n \r\n 40 IF (k > kmx) lmx = kml\r\n IF (l >= lmx) GO TO 20\r\n l = l + 1\r\n eps = eps * 0.5_dp\r\n ef = ef / sq2\r\n hh(l) = hh(l-1) * 0.5_dp\r\n lr(l) = -1\r\n aa(l) = aa(l-1)\r\n est = gl\r\n GO TO 10\r\n \r\n! PROCEED TO RIGHT HALF AT THIS LEVEL\r\n \r\n 50 vl(l) = glr\r\n 60 est = gr(l-1)\r\n lr(l) = 1\r\n aa(l) = aa(l) + 4.0_dp * hh(l)\r\n GO TO 10\r\n \r\n! RETURN ONE LEVEL\r\n \r\n 70 vr = glr\r\n 80 IF (l > 1) THEN\r\n l = l - 1\r\n eps = eps * 2.0_dp\r\n ef = ef * sq2\r\n IF (lr(l) <= 0) THEN\r\n vl(l) = vl(l+1) + vr\r\n GO TO 60\r\n END IF\r\n vr = vl(l+1) + vr\r\n GO TO 80\r\n END IF\r\n \r\n! EXIT\r\n \r\n ans = vr\r\n IF (mxl == 0 .OR. ABS(ce) <= 2.0_dp*tol*area) GO TO 100\r\n ierr = 2\r\n WRITE(*, *) 'GAUS8- ANS IS PROBABLY INSUFFICIENTLY ACCURATE.'\r\n GO TO 100\r\n\r\n 90 ierr = -1\r\n WRITE(*, *) 'GAUS8- THE FOLLOWING TEMPORARY DIAGNOSTIC WILL APPEAR ONLY ONCE.'\r\n WRITE(*, *) 'A AND B ARE TOO NEARLY EQUAL TO ALLOW NORMAL INTEGRATION.'\r\n WRITE(*, *) 'ANS IS SET TO ZERO, AND IERR=-1.'\r\nEND IF\r\n100 icall = 0\r\nIF (ERR < 0.0_dp) ERR = ce\r\nRETURN\r\nEND SUBROUTINE gaus8\r\n\r\n\r\n\r\nSUBROUTINE cexint(z, n, kode, tol, m, cy, ierr)\r\n!***BEGIN PROLOGUE CEXINT\r\n!***DATE WRITTEN 870515 (YYMMDD)\r\n!***REVISION DATE 870515 (YYMMDD)\r\n!***CATEGORY NO. B5E\r\n!***KEYWORDS EXPONENTIAL INTEGRALS, SINE INTEGRAL, COSINE INTEGRAL\r\n!***AUTHOR AMOS, DONALD E., SANDIA NATIONAL LABORATORIES\r\n!***PURPOSE TO COMPUTE EXPONENTIAL INTEGRALS OF A COMPLEX (dp) ARGUMENT\r\n!***DESCRIPTION\r\n\r\n! ON KODE=1, CEXINT COMPUTES AN M MEMBER SEQUENCE OF COMPLEX (dp)\r\n! EXPONENTIAL INTEGRALS CY(J)=E(N+J-1,Z), J=1,...,M, FOR\r\n! POSITIVE ORDERS N,...,N+M-1 AND COMPLEX (dp) Z IN THE CUT PLANE\r\n! -PI < ARG(Z) <= PI (N=1 AND Z=CMPLX(0.0,0.0) CANNOT HOLD AT\r\n! THE SAME TIME). ON KODE=2, CEXINT COMPUTES SCALED FUNCTIONS\r\n\r\n! CY(J)=E(N+J-1,Z)*CEXP(Z), J=1,...,M,\r\n\r\n! WHICH REMOVES THE EXPONENTIAL BEHAVIOR IN BOTH THE LEFT AND\r\n! RIGHT HALF PLANES. DEFINITIONS AND NOTATION ARE FOUND IN THE\r\n! NBS HANDBOOK OF MATHEMATICAL FUNCTIONS (REF. 1).\r\n\r\n! INPUT\r\n! Z - Z=CMPLX(X,Y), -PI < ARG(Z) <= PI\r\n! N - INTEGER ORDER OF INITIAL E FUNCTION, N=1,2,...\r\n! (N=1 AND Z=CMPLX(0.0,0.0) IS AN ERROR)\r\n! KODE - A PARAMETER TO INDICATE THE SCALING OPTION\r\n! KODE= 1 RETURNS\r\n! CY(J)=E(N+J-1,Z), J=1,...,M\r\n! = 2 RETURNS\r\n! CY(J)=E(N+J-1,Z)*CEXP(Z), J=1,...,M\r\n! TOL - PRECISION (ACCURACY) DESIRED FOR THE SEQUENCE,\r\n! URND <= TOL <= 1.0E-3, WHERE URND IS LIMITED BY\r\n! URND = MAX(UNIT ROUNDOFF,1.0E-18) AND UNIT\r\n! ROUNDOFF = EPSILON(0.0_dp)\r\n! M - NUMBER OF E FUNCTIONS IN THE SEQUENCE, M >= 1\r\n\r\n! OUTPUT\r\n! CY - A COMPLEX (dp) VECTOR WHOSE FIRST M COMPONENTS CONTAIN\r\n! VALUES FOR THE SEQUENCE\r\n! CY(J)=E(N+J-1,Z) OR\r\n! CY(J)=E(N+J-1,Z)*CEXP(Z), J=1,...,M\r\n! DEPENDING ON KODE.\r\n! IERR - ERROR FLAG\r\n! IERR=0, NORMAL RETURN - COMPUTATION COMPLETED\r\n! IERR=1, INPUT ERROR - NO COMPUTATION\r\n! IERR=2, UNDERFLOW - FIRST M COMPONENTS OF CY\r\n! SET TO ZERO, CY(J)=CMPLX(0.0,0.0), J=1,M,\r\n! REAL(Z) > 0.0 TOO LARGE ON KODE=1\r\n! IERR=3, OVERFLOW - NO COMPUTATION,\r\n! REAL(Z) < 0.0 TOO SMALL ON KODE=1\r\n! IERR=4, CABS(Z) OR N+M-1 LARGE - COMPUTATION DONE\r\n! BUT LOSSES OF SIGNIFICANCE BY ARGUMENT REDUCTION\r\n! PRODUCE LESS THAN HALF OF MACHINE ACCURACY\r\n! IERR=5, CABS(Z) OR N+M-1 TOO LARGE - NO COMPUTATION BECAUSE\r\n! OF COMPLETE LOSSES OF SIGNIFICANCE BY ARGUMENT REDUCTION\r\n! IERR=6, ERROR - NO COMPUTATION,\r\n! ALGORITHM TERMINATION CONDITION NOT MET.\r\n! SEE LONG DESCRIPTION ABOUT PARAMETER ICMAX.\r\n! IERR=7, ERROR - NO COMPUTATION,\r\n! DISCRIMINATION ERROR. THIS CONDITION SHOULD NEVER OCCUR.\r\n\r\n!***LONG DESCRIPTION\r\n\r\n! CEXINT USES A COMBINATION OF POWER SERIES AND BACKWARD RECURRENCE\r\n! DESCRIBED IN REF. 2 FOR THE COMPLEX (dp) Z PLANE EXCEPT FOR A STRIP\r\n! 2*YB WIDE ABOUT THE NEGATIVE REAL AXIS, WHERE ANALYTIC CONTINUATION IS\r\n! CARRIED OUT BY LIMITED USE OF TAYLOR SERIES.\r\n! THE SWITCH FROM BACKWARD RECURRENCE TO TAYLOR SERIES IS NECESSARY BECAUSE\r\n! BACKWARD RECURRENCE IS SLOWLY CONVERGENT NEAR THE NEGATIVE REAL AXIS.\r\n! THE BOUNDARIES Y=-YB AND Y=YB WERE DETERMINED SO THAT BACKWARD RECURRENCE\r\n! WOULD CONVERGE EASILY WITH N AS LARGE AS 100 AND TOL AS SMALL AS 1.0D-18.\r\n! SUBROUTINE CEXENZ DOES THE BACKWARD RECURRENCE AND SUBROUTINE CACEXI DOES\r\n! THE ANALYTIC CONTINUATION. TO START THE CONTINUATION, CACEXI CALLS CEXENZ\r\n! WITH ZB=CMPLX(X,YB).\r\n! IF CEXENZ RETURNS IERR=6, THEN YB IS INCREASED BY 0.5 UNTIL CEXENZ RETURNS\r\n! IERR=0 OR 10 TRIES, WHICHEVER COMES FIRST.\r\n! WHEN IERR=0, THEN THE ANALYTIC CONTINUATION PROCEEDS VERTICALLY DOWN FROM\r\n! ZB=CMPLX(X,YB) TO Z=CMPLX(X,Y), 0 <= Y < YB.\r\n! CONJUGATION IS USED FOR Y < 0. YB INCREASES AS TOL DECREASES TO KEEP\r\n! CONVERGENCE RATES UP AND RECURRENCE DOWN.\r\n\r\n! PARAMETER ICDIM=250 ALLOCATES STORAGE FOR THE COEFFICIENTS OF THE BACKWARD\r\n! RECURRENCE ALGORITHM. IF THE ALGORITHM TERMINATION CONDITION IS NOT MET\r\n! IN ICDIM STEPS, THEN RECURRENCE PROCEEDS WITH NO ADDITIONAL STORAGE UNTIL\r\n! THE TERMINATION CONDITION IS MET OR THE LIMIT ICMAX=2000 IS EXCEEDED.\r\n! THE PURPOSE OF STORAGE IS TO MAKE THE ALGORITHM MORE EFFICIENT.\r\n! THE TERMINATION CONDITION IS MET IN LESS THAN 250 STEPS OVER MOST OF\r\n! THE COMPLEX (dp) PLANE EXCLUDING THE STRIP ABS(Y) < YB, X < 0.\r\n! EXCEPTIONS TO THIS RULE ARE GENERATED NEAR STRIP BOUNDARIES WHEN N+M-1\r\n! AND ABS(Z) ARE LARGE AND NEARLY EQUAL. IN THESE CASES, THE CONVERGENCE\r\n! IS VERY SLOW AND ADDITIONAL RECURRENCE (UP TO ICMAX) MUST BE USED.\r\n! ON THE OTHERHAND, THESE REGIONS OF SLOW CONVERGENCE ARE KEPT SMALL BY\r\n! ADJUSTING YB AS A FUNCTION OF TOL. THESE REGIONS COULD BE ELIMINATED\r\n! ENTIRELY BY MAKING YB SUFFICIENTLY LARGE, BUT THE EXPENSE AND INSTABILITY\r\n! OF CONTINUATION BY TAYLOR SERIES NOT ONLY GOES UP, BUT THE COMPUTATIONAL\r\n! EXPENSE BECOMES EXCESSIVELY LARGE IN OTHER PARTS OF THE LEFT HALF PLANE\r\n! (Y < YB) WHERE THE BACKWARD RECURRENCE ALGORITHM WOULD CONVERGE RAPIDLY.\r\n\r\n! DERIVATIVES FOR SUCCESSIVE POWER SERIES ARE NOT COMPUTED BY EVALUATING\r\n! DERIVATIVES OF A PREVIOUS POWER SERIES. BECAUSE OF THE RELATION\r\n\r\n! (1) DE(N,Z)/DZ = - E(N-1,Z),\r\n\r\n! SUCCESSIVE DERIVATIVES AT Z ARE GIVEN BY LOWER ORDER FUNCTIONS AND CAN BE\r\n! COMPUTED IN A STABLE FASHION BY BACKWARD RECURRENCE USING (2) PROVIDED\r\n! THAT THE BEGINNING ORDER NUB IS SMALLER THAN THE ARGUMENT.\r\n! TO ACHIEVE THIS FOR ALL INTERMEDIATE VALUES ZZ BETWEEN ZB AND Z, WE TAKE\r\n! NUB=MINO(N+M-1,INT(CABS(Z)+0.5)).\r\n! TO START, E(NUB,ZB) IS EVALUATED BY THE BACKWARD RECURRENCE ALGORITHM OF\r\n! REF. 3. TO CONTINUE THE FUNCTION FROM ZB TO Z VIA INTERMEDIATE VALUES ZZ,\r\n! DERIVATIVES OF E(NUB,ZB) ARE COMPUTED BY BACKWARD RECURRENCE ON (2).\r\n! THIS ALLOWS A STEP (NO LARGER THAN 0.5) TO ZZ FOR E(NUB,ZZ) USING THE\r\n! TAYLOR SERIES ABOUT ZB. NOW, WE APPLY (2) AGAIN STARTING AT E(NUB,ZZ) FOR\r\n! THE DERIVATIVES AT ZZ AND TAKE ANOTHER STEP, ETC. NOTICE THAT THE\r\n! STABILITY CONDITION FOR BACKWARD RECURRENCE, NUB <= ABS(Z) <= ABS(ZZ)\r\n! <= ABS(ZB), IS SATISFIED FOR ALL INTERMEDIATE VALUES ZZ. THE FINAL\r\n! SEQUENCE FOR ORDERS N,...,N+M-1 IS GENERATED FROM (2) BY BACKWARD\r\n! RECURRENCE, FORWARD RECURRENCE OR BOTH ONCE E(NUB,Z) HAS BEEN COMPUTED.\r\n\r\n! RECURRENCE WITH THE RELATION\r\n\r\n! (2) N*E(N+1,Z) + Z*E(N,Z) = CEXP(-Z)\r\n\r\n! IN A DIRECTION AWAY FROM THE INTEGER CLOSEST TO ABS(Z) IS STABLE.\r\n! FOR NEGATIVE ORDERS, THE RECURRENCE\r\n\r\n! E( 0,Z) = CEXP(-Z)/Z\r\n! E(-N,Z) = ( CEXP(-Z)+N*E(-N+1,Z) )/Z ,N=1,2,...\r\n\r\n! IS NUMERICALLY STABLE FOR ALL Z.\r\n\r\n! THE (CAPITAL) SINE AND COSINE INTEGRALS CAN BE COMPUTED FROM\r\n\r\n! SI(Z) = (E(1,I*Z)-E(1,-I*Z))/(2*I) + PI/2\r\n! CI(Z) = -(E(1,I*Z)+E(1,-I*Z))/2\r\n\r\n! IN -PI/2 < ARG(Z) <= PI/2, (I**2=-1), WHILE THE PRINCIPAL\r\n! VALUED EXPONENTIAL INTEGRAL EI(X) CAN BE COMPUTED FROM\r\n\r\n! EI( X) = -(E(1,-X+I*0)+E(1,-X-I*0))/2 = -REAL(E(1,-X))\r\n! EI(-X) = -REAL(E(1,X))\r\n\r\n! FOR X > 0.0 TO AN ACCURACY TOL. IF Z = X > 0 THEN THE REAL SINE AND\r\n! COSINE INTEGRALS ARE GIVEN BY\r\n\r\n! SI(X) = AIMAG(E(1,I*X)) + PI/2\r\n! CI(X) = -REAL(E(1,I*X)) .\r\n\r\n! THE ANALYTIC CONTINUATION TO OTHER SHEETS CAN BE DONE BY THE RELATIONS\r\n\r\n! E(N,Z*CEXP(2*PI*M*I)) = E(N,Z) - 2*PI*M*I*(-Z)**(N-1)/(N-1)!\r\n\r\n! WHERE M=+1 OR M=-1 AND I**2=-1.\r\n\r\n!***REFERENCES HANDBOOK OF MATHEMATICAL FUNCTIONS BY M. ABRAMOWITZ AND\r\n! I. A. STEGUN, NBS AMS SERIES 55, U.S. DEPT. OF COMMERCE, 1955.\r\n\r\n! COMPUTATION OF EXPONENTIAL INTEGRALS OF COMPLEX (dp) ARGUMENT\r\n! BY D. E. AMOS, ACM TRANS. MATH. SOFTWARE\r\n\r\n! COMPUTATION OF EXPONENTIAL INTEGRALS BY D. E. AMOS, ACM TRANS.\r\n! MATH. SOFTWARE, VOL 6, NO. 3 SEPTEMBER 1980, PP. 365-377;\r\n! ALGORITHM 556, EXPONENTIAL INTEGRALS, PP. 420-428.\r\n\r\n! REMARK ON ALGORITHM 556\r\n! BY D. E. AMOS, ACM TRANS. MATH. SOFTWARE, VOL 9, NO. 4\r\n! DECEMBER 1983, P. 525.\r\n\r\n! UNIFORM ASYMPTOTIC EXPANSIONS FOR EXPONENTIAL INTEGRALS E(N,X)\r\n! AND BICKLEY FUNCTIONS KI(N,X) BY D. E. AMOS, ACM TRANS. MATH.\r\n! SOFTWARE, VOL 9, NO. 4, DECEMBER. 1983, PP. 467-479;\r\n! ALGORITHM 609, A PORTABLE FORTRAN SUBROUTINE FOR BICKLEY\r\n! FUNCTIONS KI(N,X), PP. 480-493.\r\n\r\n!***ROUTINES CALLED CACEXI,CEXENZ,I1MACH,R1MACH\r\n!***END PROLOGUE CEXINT\r\n\r\nCOMPLEX (dp), INTENT(IN) :: z\r\nINTEGER, INTENT(IN) :: n\r\nINTEGER, INTENT(IN) :: kode\r\nREAL (dp), INTENT(IN) :: tol\r\nINTEGER, INTENT(IN) :: m\r\nCOMPLEX (dp), INTENT(OUT) :: cy(m)\r\nINTEGER, INTENT(OUT) :: ierr\r\n\r\nINTEGER :: i, k, k1, k2\r\nREAL (dp) :: aa, alim, az, bb, ca(250), d, elim, fn, rbry, r1m5, urnd, x, &\r\n y, yb, htol\r\nCOMPLEX (dp) :: cb(250)\r\n!-----------------------------------------------------------------------\r\n! DIMENSION CA(ICDIM),CB(ICDIM)\r\n!-----------------------------------------------------------------------\r\nINTEGER, PARAMETER :: icdim = 250\r\n\r\n!***FIRST EXECUTABLE STATEMENT CEXINT\r\nierr = 0\r\nx = REAL(z, KIND=dp)\r\ny = AIMAG(z)\r\nIF (x == 0.0_dp .AND. y == 0.0_dp .AND. n == 1) ierr = 1\r\nIF (n < 1) ierr = 1\r\nIF (kode < 1 .OR. kode > 2) ierr = 1\r\nIF (m < 1) ierr = 1\r\nurnd = MAX(EPSILON(0.0_dp), 1.0E-18)\r\nIF (tol < urnd .OR. tol > 1.0E-3) ierr = 1\r\nIF (ierr /= 0) RETURN\r\nIF (x /= 0.0_dp .OR. y /= 0.0_dp .OR. n <= 1) THEN\r\n!-----------------------------------------------------------------------\r\n! SET PARAMETERS RELATED TO MACHINE CONSTANTS.\r\n! URND IS THE APPROXIMATE UNIT ROUNDOFF LIMITED TO 1.0E-18.\r\n! ELIM IS THE APPROXIMATE EXPONENTIAL OVER- AND UNDERFLOW LIMIT.\r\n! EXP(-ELIM) < EXP(-ALIM)=EXP(-ELIM)/URND AND\r\n! EXP(ELIM) > EXP(ALIM)=EXP(ELIM)*URND ARE INTERVALS NEAR\r\n! UNDERFLOW AND OVERFLOW LIMITS WHERE SCALED ARITHMETIC IS DONE.\r\n!-----------------------------------------------------------------------\r\n k1 = MINEXPONENT(0.0_dp)\r\n k2 = MAXEXPONENT(0.0_dp)\r\n r1m5 = LOG10(DBLE(RADIX(0.0_dp)))\r\n k = MIN(ABS(k1),ABS(k2))\r\n elim = 2.303_dp * (k*r1m5 - 3.0_dp)\r\n k1 = DIGITS(0.0_dp) - 1\r\n aa = r1m5 * k1\r\n aa = aa * 2.303\r\n alim = elim + MAX(-aa, -41.45_dp)\r\n rbry = 2.0\r\n IF (urnd > 1.0E-8) rbry = 1.0_dp\r\n!-----------------------------------------------------------------------\r\n! TEST VARIABLES FOR RANGE. ABS(Z) CANNOT BE LARGER THAN THE ARGUMENT\r\n! OF THE INT( ) FUNCTION.\r\n!-----------------------------------------------------------------------\r\n az = ABS(z)\r\n fn = n+m-1\r\n aa = 0.5_dp / urnd\r\n bb = HUGE(0.0_dp) * 0.5_dp\r\n aa = MIN(aa,bb)\r\n IF (az > aa) GO TO 20\r\n IF (fn > aa) GO TO 20\r\n aa = SQRT(aa)\r\n IF (az > aa) ierr = 4\r\n IF (fn > aa) ierr = 4\r\n IF (x >= 0.0_dp) THEN\r\n!-----------------------------------------------------------------------\r\n! BACKWARD RECURRENCE FOR THE RIGHT HALF PLANE, X >= 0.0E0\r\n!-----------------------------------------------------------------------\r\n CALL cexenz(z, n, kode, m, cy, ierr, rbry, tol, elim, alim, icdim, ca, cb)\r\n RETURN\r\n END IF\r\n IF (az <= rbry) THEN\r\n!-----------------------------------------------------------------------\r\n! POWER SERIES FOR ABS(Z) <= RBRY AND X < 0.0E0\r\n!-----------------------------------------------------------------------\r\n CALL cexenz(z, n, kode, m, cy, ierr, rbry, tol, elim, alim, icdim, ca, cb)\r\n RETURN\r\n END IF\r\n d = -0.4342945_dp * LOG(tol)\r\n yb = 10.5_dp - 0.538460_dp * (18.0_dp-d)\r\n IF (ABS(y) >= yb) THEN\r\n!-----------------------------------------------------------------------\r\n! BACKWARD RECURRENCE EXTERIOR TO THE STRIP ABS(Y) < YB, X < 0.0\r\n!-----------------------------------------------------------------------\r\n htol = 0.125_dp * tol\r\n CALL cexenz(z, n, kode, m, cy, ierr, rbry, htol, elim, alim, icdim, ca, cb )\r\n RETURN\r\n END IF\r\n!-----------------------------------------------------------------------\r\n! TAYLOR SERIES IN CACEXI FOR ANALYTIC CONTINUATION\r\n!-----------------------------------------------------------------------\r\n CALL cacexi(z, n, kode, m, cy, ierr, yb, rbry, tol, elim, alim, icdim, ca, cb )\r\n RETURN\r\nEND IF\r\nDO i = 1, m\r\n cy(i) = 1.0_dp / (n+i-2)\r\nEND DO\r\nRETURN\r\n\r\n20 ierr = 5\r\nRETURN\r\nEND SUBROUTINE cexint\r\n\r\n\r\n\r\nSUBROUTINE cexenz(z, n, kode, m, cy, ierr, rbry, tol, elim, alim, icdim, ca, cb)\r\n!***BEGIN PROLOGUE CEXENZ\r\n!***REFER TO CEXINT\r\n\r\n! CEXENZ COMPUTES THE EXPONENTIAL INTEGRAL BY MEANS OF POWER SERIES AND A\r\n! BACKWARD RECURRENCE ALGORITHM FOR THE CONFLUENT HYPERGEOMETRIC\r\n! REPRESENTATION.\r\n\r\n!***ROUTINES CALLED PSIXN\r\n!***END PROLOGUE CEXENZ\r\n\r\nCOMPLEX (dp), INTENT(IN) :: z\r\nINTEGER, INTENT(IN) :: n\r\nINTEGER, INTENT(IN) :: kode\r\nINTEGER, INTENT(IN) :: m\r\nCOMPLEX (dp), INTENT(OUT) :: cy(m)\r\nINTEGER, INTENT(OUT) :: ierr\r\nREAL (dp), INTENT(IN) :: rbry\r\nREAL (dp), INTENT(IN) :: tol\r\nREAL (dp), INTENT(IN) :: elim\r\nREAL (dp), INTENT(IN) :: alim\r\nINTEGER, INTENT(IN) :: icdim\r\nREAL (dp), INTENT(OUT) :: ca(icdim)\r\nCOMPLEX (dp), INTENT(OUT) :: cb(icdim)\r\n\r\nINTEGER :: i, ic, icase, ict, ik, ind, iz, jset, k, kflag, kn, ks, ml, &\r\n mu, nd, nm\r\nREAL (dp) :: aa, aam, aams, aem, ah, ak, ap1, at, az, bk, bt, dk, ERR, &\r\n fc, fnm, rtola, tola, x, xtol, y, ck\r\nCOMPLEX (dp) :: cp1, cp2, cpt, cat, cbt, cy1, cy2, cyy(2), cnorm, cs, cak, &\r\n emz, caa, tz, fz, ct, scle, rscle\r\n\r\nREAL (dp), PARAMETER :: euler = -5.77215664901532861D-01\r\nCOMPLEX (dp), PARAMETER :: czero = (0.0_dp, 0.0_dp), cone = (1.0_dp, 0.0_dp)\r\nINTEGER, PARAMETER :: icmax = 2000\r\n\r\nierr = 0\r\nscle = cone\r\nrscle = cone\r\nx = REAL(z, KIND=dp)\r\ny = AIMAG(z)\r\naz = ABS(z)\r\nIF (az <= rbry) THEN\r\n!-----------------------------------------------------------------------\r\n! SERIES FOR E(N,Z) FOR ABS(Z) <= RBRY\r\n!-----------------------------------------------------------------------\r\n iz = az + 0.5_dp\r\n!-----------------------------------------------------------------------\r\n! ICASE=1 MEANS INTEGER CLOSEST TO ABS(Z) IS 2 AND N=1\r\n! ICASE=2 MEANS INTEGER CLOSEST TO ABS(Z) IS 0,1, OR 2 AND N >= 2\r\n!-----------------------------------------------------------------------\r\n icase = 2\r\n IF (iz > n) icase = 1\r\n nm = n - icase + 1\r\n nd = nm + 1\r\n ind = 3 - icase\r\n mu = m - ind\r\n ml = 1\r\n ks = nd\r\n fnm = nm\r\n cs = czero\r\n xtol = 0.3333_dp * tol\r\n aam = 1.0_dp\r\n IF (nd /= 1) THEN\r\n aam = 1.0_dp / fnm\r\n cs = aam\r\n END IF\r\n caa = cone\r\n aa = 1.0_dp\r\n ak = 1.0_dp\r\n!-----------------------------------------------------------------------\r\n! LIMIT INDEX I TO IK TO PREVENT UNDERFLOW ON SMALL VALUES OF Z\r\n!-----------------------------------------------------------------------\r\n ik = 35\r\n IF (az < xtol*aam) ik = 1\r\n DO i = 1, ik\r\n at = 1.0_dp / ak\r\n caa = -caa * z * at\r\n aa = aa * az * at\r\n IF (i /= nm) THEN\r\n cs = cs - caa / (ak-fnm)\r\n ELSE\r\n cs = cs + caa * (-LOG(z) + psixn(nd))\r\n END IF\r\n IF (aa <= xtol*ABS(cs)) EXIT\r\n ak = ak + 1.0_dp\r\n END DO\r\n\r\n IF (nd == 1) cs = cs + (-LOG(z) + euler)\r\n IF (kode == 2) cs = cs * EXP(z)\r\n cy(1) = cs\r\n ct = cs\r\n emz = cone\r\n IF (m /= 1) THEN\r\n cy(ind) = cs\r\n ak = ks\r\n IF (kode == 1) emz = EXP(-z)\r\n SELECT CASE ( icase )\r\n CASE ( 1)\r\n GO TO 140\r\n CASE ( 2)\r\n GO TO 160\r\n END SELECT\r\n END IF\r\n IF (icase == 2) RETURN\r\n IF (kode == 1) emz = EXP(-z)\r\n cy(1) = (emz-cs) / z\r\n RETURN\r\nEND IF\r\n!-----------------------------------------------------------------------\r\n! BACKWARD RECURSIVE MILLER ALGORITHM FOR\r\n! E(N,Z)=EXP(-Z)*(Z**(N-1))*U(N,N,Z)\r\n! WITH RECURSION AWAY FROM N=INTEGER CLOSEST TO ABS(Z)\r\n! U(A,B,Z) IS THE SECOND CONFLUENT HYPERGEOMETRIC FUNCTION\r\n!-----------------------------------------------------------------------\r\nemz = cone\r\nIF (kode /= 2) THEN\r\n!-----------------------------------------------------------------------\r\n! SCALE NEAR EXPONENT EXTREMES ON KODE=1\r\n!-----------------------------------------------------------------------\r\n IF (x >= 0.0_dp) THEN\r\n at = x + (n+m-1)\r\n ct = CMPLX(at, y, KIND=dp)\r\n aa = ABS(ct)\r\n at = x + LOG(aa)\r\n IF (at > elim) GO TO 30\r\n kflag = 1\r\n ELSE\r\n at = x\r\n IF (at < (-elim)) GO TO 180\r\n kflag = 2\r\n END IF\r\n IF (ABS(at) >= alim) THEN\r\n tola = EXP(alim-elim)\r\n rtola = 1.0_dp / tola\r\n IF (kflag /= 2) THEN\r\n scle = rtola\r\n rscle = tola\r\n ELSE\r\n scle = tola\r\n rscle = rtola\r\n END IF\r\n emz = scle\r\n END IF\r\n emz = emz * EXP(-z)\r\nEND IF\r\niz = az + 0.5_dp\r\nkn = n + m - 1\r\nIF (kn <= iz) GO TO 50\r\nIF (n < iz .AND. iz < kn) GO TO 80\r\nIF (n >= iz) GO TO 70\r\nierr = 7\r\nRETURN\r\n\r\n30 ierr = 2\r\ncy(1:m) = czero\r\nRETURN\r\n\r\n50 icase = 1\r\nks = kn\r\nml = m - 1\r\nmu = -1\r\nind = m\r\nIF (kn > 1) GO TO 90\r\n\r\n60 ks = 2\r\nicase = 3\r\nGO TO 90\r\n\r\n70 icase = 2\r\nind = 1\r\nks = n\r\nmu = m - 1\r\nIF (n > 1) GO TO 90\r\nIF (kn == 1) GO TO 60\r\niz = 2\r\n\r\n80 icase = 1\r\nks = iz\r\nml = iz - n\r\nind = ml + 1\r\nmu = kn - iz\r\n\r\n90 ik = ks / 2\r\nah = ik\r\njset = 1 + ks - 2 * ik\r\n!-----------------------------------------------------------------------\r\n! START COMPUTATION FOR\r\n! CYY(1) = C*U( A , A ,Z) JSET=1\r\n! CYY(1) = C*U(A+1,A+1,Z) JSET=2\r\n! FOR AN EVEN INTEGER A.\r\n!-----------------------------------------------------------------------\r\nic = 0\r\naa = ah + ah\r\ncaa = aa\r\naam = aa - 1.0_dp\r\naams = aam * aam\r\ntz = z + z\r\nfz = tz + tz\r\nak = ah\r\nxtol = tol\r\nct = aams + fz * ah\r\ncak = z + caa\r\naem = (ak+1.0_dp) / xtol\r\naem = aem / ABS(cak)\r\nbk = aa\r\nck = ah * ah\r\n!-----------------------------------------------------------------------\r\n! FORWARD RECURSION FOR P(IC),P(IC+1) AND INDEX IC FOR BACKWARD\r\n! RECURSION\r\n!-----------------------------------------------------------------------\r\ncp1 = czero\r\ncp2 = cone\r\n\r\n100 ic = ic + 1\r\nIF (ic <= icdim) THEN\r\n ak = ak + 1.0_dp\r\n ck = ck + 1.0_dp\r\n at = bk / (bk+ak+ck)\r\n bk = bk + ak + ak\r\n cat = at\r\n ca(ic) = at\r\n bt = 1.0_dp / (ak + 1.0_dp)\r\n cbt = (ak + ak + z) * bt\r\n cb(ic) = cbt\r\n cpt = cp2\r\n cp2 = cbt * cp2 - cat * cp1\r\n cp1 = cpt\r\n ct = ct + fz\r\n aem = aem * at\r\n bt = ABS(ct)\r\n ERR = aem / SQRT(bt)\r\n ap1 = ABS(cp1)\r\n IF (ERR*(ak+1.0_dp)/ap1 > ap1) GO TO 100\r\nELSE\r\n!-----------------------------------------------------------------------\r\n! CONTINUE FORWARD RECURRENCE UNINDEXED WHEN IC EXCEEDS ICDIM\r\n!-----------------------------------------------------------------------\r\n ic = ic - 1\r\n\r\n 110 ic = ic + 1\r\n IF (ic > icmax) GO TO 190\r\n ak = ak + 1.0_dp\r\n ck = ck + 1.0_dp\r\n at = bk / (bk+ak+ck)\r\n bk = bk + ak + ak\r\n cat = at\r\n bt = 1.0_dp / (ak+1.0_dp)\r\n cbt = (ak+ak + z) * bt\r\n cpt = cp2\r\n cp2 = cbt * cp2 - cat * cp1\r\n cp1 = cpt\r\n ct = ct + fz\r\n aem = aem * at\r\n bt = ABS(ct)\r\n ERR = aem / SQRT(bt)\r\n ap1 = ABS(cp1)\r\n IF (ERR*(ak+1.0_dp)/ap1 > ap1) GO TO 110\r\nEND IF\r\nfc = ic\r\nat = ((fc+1.0_dp)/(ak+1.0_dp)) * ((ak+ah)/(ak+1.0_dp))\r\ncat = at * SQRT(ct/(ct+fz))\r\ncy2 = cat * (cp1/cp2)\r\ncy1 = cone\r\n!-----------------------------------------------------------------------\r\n! BACKWARD RECURRENCE FOR\r\n! CY1= C*U( A ,A,Z)\r\n! CY2= C*(A/(1+A/2))*U(A+1,A,Z)\r\n!-----------------------------------------------------------------------\r\nIF (ic > icdim) THEN\r\n!-----------------------------------------------------------------------\r\n! BACKWARD RECUR UNINDEXED WHEN IC EXCEEDS ICDIM\r\n!-----------------------------------------------------------------------\r\n bt = aa + x\r\n\r\n 120 ak = ah + fc\r\n bk = ak + 1.0_dp\r\n ck = aam + fc\r\n dk = bt + fc + fc\r\n at = (ak/fc) * (bk/ck)\r\n cbt = CMPLX(dk/bk, y/bk, KIND=dp)\r\n cpt = cy1\r\n cy1 = (cbt*cy1 - cy2) * at\r\n cy2 = cpt\r\n fc = fc - 1.0_dp\r\n ic = ic - 1\r\n IF (ic > icdim) GO TO 120\r\nEND IF\r\nict = ic\r\nDO k = 1, ict\r\n at = 1.0_dp / ca(ic)\r\n cpt = cy1\r\n cy1 = (cb(ic)*cy1 - cy2) * at\r\n cy2 = cpt\r\n ic = ic - 1\r\nEND DO\r\n!-----------------------------------------------------------------------\r\n! THE CONTIGUOUS RELATION\r\n! Z*U(B,C+1,Z)=(C-B)*U(B,C,Z)+U(B-1,C,Z)\r\n! WITH B=A+1 , C=A IS USED FOR\r\n! CYY(2) = C * U(A+1,A+1,Z)\r\n! Z IS INCORPORATED INTO THE NORMALIZING RELATION FOR CNORM.\r\n!-----------------------------------------------------------------------\r\ncpt = cy2 / cy1\r\ncnorm = cone - cpt * (ah + 1.0_dp) / aa\r\ncyy(1) = cone / (cnorm*caa+z)\r\ncyy(2) = cnorm * cyy(1)\r\nIF (icase /= 3) THEN\r\n ct = emz * cyy(jset)\r\n cy(ind) = ct * rscle\r\n cs = ct\r\n IF (m == 1) RETURN\r\n ak = ks\r\n SELECT CASE ( icase )\r\n CASE ( 1)\r\n GO TO 140\r\n CASE ( 2)\r\n GO TO 160\r\n END SELECT\r\nEND IF\r\n!-----------------------------------------------------------------------\r\n! RECURSION SECTION N*E(N+1,Z) + Z*E(N,Z)=EMZ\r\n!-----------------------------------------------------------------------\r\nct = emz * (cone - cyy(1)) / z\r\ncy(1) = ct * rscle\r\nRETURN\r\n\r\n140 caa = ak\r\ntz = cone / z\r\nk = ind - 1\r\nDO i = 1, ml\r\n caa = caa - cone\r\n ct = (emz-caa*ct) * tz\r\n cy(k) = ct * rscle\r\n k = k - 1\r\nEND DO\r\nIF (mu <= 0) RETURN\r\nak = ks\r\n\r\n160 k = ind\r\nDO i = 1, mu\r\n cs = (emz - z*cs) / ak\r\n cy(k+1) = cs * rscle\r\n ak = ak + 1.0_dp\r\n k = k + 1\r\nEND DO\r\nRETURN\r\n\r\n180 ierr = 3\r\nRETURN\r\n\r\n190 ierr = 6\r\nRETURN\r\nEND SUBROUTINE cexenz\r\n\r\n\r\n\r\nSUBROUTINE cacexi(z, nu, kode, n, y, ierr, yb, rbry, tol, elim, alim, icdim, &\r\n ca, cb)\r\n!***BEGIN PROLOGUE CACEXI\r\n!***REFER TO CEXINT\r\n\r\n! CACEXI COMPUTES THE ANALYTIC CONTINUATION OF THE EXPONENTIAL INTEGRAL\r\n! FOR X < 0 AND -YB < Y < YB BY TAYLOR SERIES IN INCREMENTS OF HALF A UNIT.\r\n! THE CONTINUATION PROCEEDS VERTICALLY DOWN FROM ZB=CMPLX(X,YB) TO\r\n! Z=CMPLX(X,Y) FOR 0.0 <= Y < YB. CONJUGATION IS USED FOR Y < 0.0E0.\r\n\r\n!***ROUTINES CALLED CEXENZ\r\n!***END PROLOGUE CACEXI\r\n\r\nCOMPLEX (dp), INTENT(IN) :: z\r\nINTEGER, INTENT(IN) :: nu\r\nINTEGER, INTENT(IN) :: kode\r\nINTEGER, INTENT(IN) :: n\r\nCOMPLEX (dp), INTENT(OUT) :: y(n)\r\nINTEGER, INTENT(OUT) :: ierr\r\nREAL (dp), INTENT(IN OUT) :: yb\r\nREAL (dp), INTENT(IN OUT) :: rbry\r\nREAL (dp), INTENT(IN) :: tol\r\nREAL (dp), INTENT(IN) :: elim\r\nREAL (dp), INTENT(IN) :: alim\r\nINTEGER, INTENT(IN) :: icdim\r\nREAL (dp), INTENT(IN OUT) :: ca(icdim)\r\nCOMPLEX (dp), INTENT(IN OUT) :: cb(icdim)\r\n\r\nINTEGER :: i, iaz, il, is, iy, k, kb, kl, kmax, ks, kyb, nb, nflg, nub\r\nREAL (dp) :: az, del, fk, rtola, tola, yt, &\r\n zi, zid, zr, xtol, rzi, atrm, fj, rw, rq(64), asum, htol\r\nCOMPLEX (dp) :: yy(1), cex, sum, trm, zz, zp(64), zt, scle, &\r\n rscle, trms, zw, cezt\r\nCOMPLEX (dp), PARAMETER :: cone = (1.0_dp, 0.0_dp)\r\n\r\nscle = cone\r\nrscle = cone\r\nzr = REAL(z, KIND=dp)\r\nzi = AIMAG(z)\r\nzid = zi\r\nkyb = 0\r\nIF (zi < 0.0_dp) zid = -zid\r\naz = ABS(z)\r\niaz = az + 0.5_dp\r\n!-----------------------------------------------------------------------\r\n! SET ORDER NUB=MIN(N+M-1,INT(ABS(Z)+0.5)), GENERATE REMAINDER\r\n! OF THE SEQUENCE AFTER THE COMPUTATION OF E(NUB,Z)\r\n!-----------------------------------------------------------------------\r\nIF (nu < iaz) THEN\r\n IF (nu+n-1 <= iaz) GO TO 10\r\n nub = iaz\r\n nb = 0\r\n nflg = 3\r\n kb = nub - nu + 1\r\n ks = kb + 1\r\n kl = n\r\n is = 1\r\n il = kb - 1\r\n GO TO 30\r\nEND IF\r\nnub = MAX(iaz, 1)\r\nnb = nu - nub\r\nnflg = 1\r\nkb = 1\r\nks = 2\r\nkl = n\r\nGO TO 30\r\n\r\n10 nub = nu + n - 1\r\nnb = 0\r\nnflg = 2\r\nis = 2\r\nil = n\r\nkb = n\r\nGO TO 30\r\n!-----------------------------------------------------------------------\r\n! SET PARAMETERS FOR ANALYTIC CONTINUATION FROM Y=YB INTO THE REGION\r\n! 0 <= ZID < YB.\r\n!-----------------------------------------------------------------------\r\n20 yb = yb + 0.5_dp\r\nkyb = kyb + 1\r\nIF (kyb > 10) RETURN\r\nierr = 0\r\n\r\n30 del = yb - zid\r\n!-----------------------------------------------------------------------\r\n! MAKE DEL LARGE ENOUGH TO AVOID UNDERFLOW IN GENERATION OF POWERS\r\n!-----------------------------------------------------------------------\r\nIF (ABS(del) <= 1.0E-4) THEN\r\n yb = yb + 1.0E-4\r\n del = yb - zid\r\nEND IF\r\nhtol = 0.125_dp * tol\r\nzz = CMPLX(zr, yb, KIND=dp)\r\nCALL cexenz(zz, nub, 2, 1, yy, ierr, rbry, htol, elim, alim, icdim, ca, cb)\r\nIF (ierr == 6) GO TO 20\r\n!-----------------------------------------------------------------------\r\n! ANALYTIC CONTINUATION VIA TAYLOR SERIES FOR ORDER NUB\r\n!-----------------------------------------------------------------------\r\niy = del + del\r\nyt = del / (iy+1)\r\nsum = yy(1)\r\nhtol = 0.25_dp * tol\r\ntrm = sum\r\ncezt = CMPLX(COS(yt), -SIN(yt), KIND=dp)\r\nzw = cone\r\nzp(1) = cone\r\nfk = 1.0_dp\r\nfj = nub - 1\r\nzt = cone / zz\r\n!-----------------------------------------------------------------------\r\n! TERMS OF THE SERIES TRM=E(NUB-K,ZZ)*(YT**K)/K!, K=0,1,... ARE\r\n! GENERATED BY BACKWARD RECURRENCE. E IS SCALED BY CEXP(ZZ).\r\n!-----------------------------------------------------------------------\r\nDO k = 2, 64\r\n rw = yt / fk\r\n zw = zw * CMPLX(0.0_dp, rw, KIND=dp)\r\n rw = fj * rw\r\n trm = (zw - CMPLX(0.0_dp, rw, KIND=dp)*trm) * zt\r\n sum = sum + trm\r\n zp(k) = zw\r\n rq(k) = rw\r\n asum = ABS(sum)\r\n atrm = ABS(trm)\r\n IF (atrm < htol*asum) GO TO 50\r\n fk = fk + 1.0_dp\r\n fj = fj - 1.0_dp\r\nEND DO\r\nk = 64\r\n\r\n50 kmax = k\r\nsum = sum * cezt\r\nIF (iy /= 0) THEN\r\n DO i = 1, iy\r\n rzi = (iy-i+1) * yt + zid\r\n zz = CMPLX(zr, rzi, KIND=dp)\r\n zt = cone / zz\r\n trm = sum\r\n DO k = 2, kmax\r\n trm = (zp(k) - CMPLX(0.0_dp, rq(k), KIND=dp)*trm) * zt\r\n sum = sum + trm\r\n END DO\r\n atrm = ABS(trm)\r\n asum = ABS(sum)\r\n xtol = htol * asum\r\n IF (atrm >= xtol) THEN\r\n IF (kmax < 64) THEN\r\n kmax = kmax + 1\r\n DO k = kmax, 64\r\n rw = yt / fk\r\n zw = zw * CMPLX(0.0_dp, rw, KIND=dp)\r\n rw = fj * rw\r\n trm = (zw - CMPLX(0.0_dp, rw, KIND=dp)*trm) * zt\r\n sum = sum + trm\r\n zp(k) = zw\r\n rq(k) = rw\r\n atrm = ABS(trm)\r\n IF (atrm < xtol) GO TO 80\r\n fk = fk + 1.0_dp\r\n fj = fj - 1.0_dp\r\n END DO\r\n k = 64\r\n\r\n 80 kmax = k\r\n END IF\r\n END IF\r\n sum = sum * cezt\r\n END DO\r\nEND IF\r\n!-----------------------------------------------------------------------\r\n! FORM SEQUENCE UP OR DOWN FROM ORDER NUB\r\n!-----------------------------------------------------------------------\r\nIF (zi < 0.0_dp) sum = CONJG(sum)\r\ncex = cone\r\n!-----------------------------------------------------------------------\r\n! SCALE NEAR OVERFLOW LIMIT ON KODE=1\r\n!-----------------------------------------------------------------------\r\nIF (kode /= 2) THEN\r\n IF (ABS(zr) >= alim) THEN\r\n IF (ABS(zr) > elim) GO TO 130\r\n tola = EXP(alim-elim)\r\n rtola = 1.0_dp / tola\r\n scle = tola\r\n rscle = rtola\r\n END IF\r\n cex = scle * EXP(-z)\r\nEND IF\r\ntrm = sum * cex\r\ny(kb) = trm * rscle\r\ntrms = trm\r\nIF (n == 1 .AND. nflg /= 1) RETURN\r\nIF (nflg /= 2) THEN\r\n fk = nub\r\n IF (nflg == 1 .AND. nb /= 0) THEN\r\n DO k = 1, nb\r\n trm = (cex - z*trm) / fk\r\n fk = fk + 1.0_dp\r\n END DO\r\n END IF\r\n y(kb) = trm * rscle\r\n trms = trm\r\n IF (n == 1) RETURN\r\n DO k = ks, kl\r\n trm = (cex - z*trm) / fk\r\n y(k) = trm * rscle\r\n fk = fk + 1.0_dp\r\n END DO\r\n IF (nflg == 1) RETURN\r\nEND IF\r\nk = kb - 1\r\nfk = nub - 1\r\nzt = cone / z\r\nDO i = is, il\r\n trms = (cex - fk*trms) * zt\r\n y(k) = trms * rscle\r\n k = k - 1\r\n fk = fk - 1.0_dp\r\nEND DO\r\nRETURN\r\n\r\n130 ierr = 3\r\nRETURN\r\nEND SUBROUTINE cacexi\r\n\r\n\r\n\r\nFUNCTION psixn(n) RESULT(fn_val)\r\n!***BEGIN PROLOGUE PSIXN\r\n!***REFER TO EXINT,BSKIN\r\n\r\n! THIS SUBROUTINE RETURNS VALUES OF PSI(X)=DERIVATIVE OF LOG GAMMA(X),\r\n! X > 0.0 AT INTEGER ARGUMENTS. A TABLE LOOK-UP IS PERFORMED FOR N <= 100,\r\n! AND THE ASYMPTOTIC EXPANSION IS EVALUATED FOR N > 100.\r\n\r\n!***END PROLOGUE PSIXN\r\n\r\nINTEGER, INTENT(IN) :: n\r\nREAL (dp) :: fn_val\r\n\r\nINTEGER :: k\r\nREAL (dp) :: ax, fn, rfn2, trm, s, wdtol\r\n!-----------------------------------------------------------------------\r\n! PSIXN(N), N = 1,100\r\n!-----------------------------------------------------------------------\r\nREAL (dp), PARAMETER :: c(100) = (/ -5.77215664901532861D-01, &\r\n 4.22784335098467139D-01, 9.22784335098467139D-01, 1.25611766843180047_dp, &\r\n 1.50611766843180047_dp, 1.70611766843180047_dp, 1.87278433509846714_dp, &\r\n 2.01564147795561000_dp, 2.14064147795561000_dp, 2.25175258906672111_dp, &\r\n 2.35175258906672111_dp, 2.44266167997581202_dp, 2.52599501330914535_dp, &\r\n 2.60291809023222227_dp, 2.67434666166079370_dp, 2.74101332832746037_dp, &\r\n 2.80351332832746037_dp, 2.86233685773922507_dp, 2.91789241329478063_dp, &\r\n 2.97052399224214905_dp, 3.02052399224214905_dp, 3.06814303986119667_dp, &\r\n 3.11359758531574212_dp, 3.15707584618530734_dp, 3.19874251285197401_dp, &\r\n 3.23874251285197401_dp, 3.27720405131351247_dp, 3.31424108835054951_dp, &\r\n 3.34995537406483522_dp, 3.38443813268552488_dp, 3.41777146601885821_dp, &\r\n 3.45002953053498724_dp, 3.48127953053498724_dp, 3.51158256083801755_dp, &\r\n 3.54099432554389990_dp, 3.56956575411532847_dp, 3.59734353189310625_dp, &\r\n 3.62437055892013327_dp, 3.65068634839381748_dp, 3.67632737403484313_dp, &\r\n 3.70132737403484313_dp, 3.72571761793728215_dp, 3.74952714174680596_dp, &\r\n 3.77278295570029433_dp, 3.79551022842756706_dp, 3.81773245064978928_dp, &\r\n 3.83947158108457189_dp, 3.86074817682925274_dp, 3.88158151016258607_dp, &\r\n 3.90198967342789220_dp, 3.92198967342789220_dp, 3.94159751656514710_dp, &\r\n 3.96082828579591633_dp, 3.97969621032421822_dp, 3.99821472884273674_dp, &\r\n 4.01639654702455492_dp, 4.03425368988169777_dp, 4.05179754953082058_dp, &\r\n 4.06903892884116541_dp, 4.08598808138353829_dp, 4.10265474805020496_dp, &\r\n 4.11904819067315578_dp, 4.13517722293122029_dp, 4.15105023880423617_dp, &\r\n 4.16667523880423617_dp, 4.18205985418885155_dp, 4.19721136934036670_dp, &\r\n 4.21213674247469506_dp, 4.22684262482763624_dp, 4.24133537845082464_dp, &\r\n 4.25562109273653893_dp, 4.26970559977879245_dp, 4.28359448866768134_dp, &\r\n 4.29729311880466764_dp, 4.31080663231818115_dp, 4.32413996565151449_dp, &\r\n 4.33729786038835659_dp, 4.35028487337536958_dp, 4.36310538619588240_dp, &\r\n 4.37576361404398366_dp, 4.38826361404398366_dp, 4.40060929305632934_dp, &\r\n 4.41280441500754886_dp, 4.42485260777863319_dp, 4.43675736968339510_dp, &\r\n 4.44852207556574804_dp, 4.46014998254249223_dp, 4.47164423541605544_dp, &\r\n 4.48300787177969181_dp, 4.49424382683587158_dp, 4.50535493794698269_dp, &\r\n 4.51634394893599368_dp, 4.52721351415338499_dp, 4.53796620232542800_dp, &\r\n 4.54860450019776842_dp, 4.55913081598724211_dp, 4.56954748265390877_dp, &\r\n 4.57985676100442424_dp, 4.59006084263707730_dp, 4.60016185273808740_dp /)\r\n!-----------------------------------------------------------------------\r\n! COEFFICIENTS OF ASYMPTOTIC EXPANSION\r\n!-----------------------------------------------------------------------\r\nREAL (dp), PARAMETER :: b(6) = &\r\n (/ 8.33333333333333333D-02, -8.33333333333333333D-03, 3.96825396825396825D-03, &\r\n -4.16666666666666666D-03, 7.57575757575757576D-03, -2.10927960927960928D-02 /)\r\n\r\nIF (n <= 100) THEN\r\n fn_val = c(n)\r\n RETURN\r\nEND IF\r\nwdtol = MAX(EPSILON(0.0_dp), 1.0D-18)\r\nfn = n\r\nax = 1.0_dp\r\ns = -0.5_dp / fn\r\nIF (ABS(s) > wdtol) THEN\r\n rfn2 = 1.0_dp / (fn*fn)\r\n DO k = 1, 6\r\n ax = ax * rfn2\r\n trm = -b(k) * ax\r\n IF (ABS(trm) < wdtol) EXIT\r\n s = s + trm\r\n END DO\r\nEND IF\r\n\r\nfn_val = s + LOG(fn)\r\nRETURN\r\nEND FUNCTION psixn\r\n\r\nEND MODULE Exponential_Integral\r\n\r\n\r\n\r\n\r\nPROGRAM cqccex\r\n\r\n! Code converted using TO_F90 by Alan Miller\r\n! Date: 2002-03-26 Time: 19:32:11\r\n\r\n! CQCCEX IS A QUICK CHECK PROGRAM TO COMPARE EXPONENTIAL INTEGRALS\r\n! E(N,Z) FROM SUBROUTINE CEXINT,\r\n\r\n! CALL CEXINT(Z,N,KODE,TOL,M,CY,IERR)\r\n\r\n! AGAINST EXPONENTIAL INTEGRALS FROM QUADRATURE SUBROUTINE CEXQAD,\r\n\r\n! CALL CEXQAD(Z,N,KODE,TOL,CQ,KERR).\r\n\r\n! Z VALUES ARE TAKEN FROM THE REGION -6.5.LE.X.LE.5.5,-6.LE.Y.LE.6.\r\n! ORDERS N RUN FROM 3 TO 11 AND THE NUMBER OF MEMBERS M IN THE\r\n! SEQUENCE E(N+K-1,Z), K=1,M RUNS FROM 1 TO 3. BOTH SCALING OPTIONS\r\n\r\n! CY(K) = E(N+K-1,Z) K=1,M KODE=1\r\n! E(N+K-1,Z)*CEXP(Z) K=1,M KODE=2\r\n\r\n! ARE CHECKED AND THE REQUESTED ACCURACY TOL IS THE LARGER OF\r\n! UNIT ROUNDOFF AND 1.0E-7. RELATIVE ERRORS ERR1 AND ERR2 FOR THE\r\n! FIRST AND LAST MEMBERS OF THE SEQUENCE ARE COMPUTED AND COMPARED\r\n! AGAINST 100.0*TOL. IF A CHECK DOES NOT OCCUR, Z,ERR1,ERR2,N,M,KODE\r\n! AND ERROR FLAGS IERR FROM CEXINT, KERR1 FROM CEXQAD, AND KERR2\r\n! FROM CEXQAD ARE PRINTED. VALUES CY(1),CQ1 AND CY(N+M-1),CQ2 WHICH\r\n! WERE COMPARED IN ERR1 AND ERR2 ARE PRINTED NEXT. KERR1.NE.0 OR\r\n! KERR2.NE.0 INDICATE A PREMATURE TRUNCATION OF THE INTEGRAL EVAL-\r\n! UATION IN CEXQAD. THE SUFFIXES 1 AND 2 CORRESPOND TO EVALUATIONS\r\n! AT ORDERS N AND N+M-1 RESPECTIVELY.\r\n\r\n! CQCCEX CALLS CEXINT,CEXQAD AND LOWER LEVEL ROUTINES CEXENZ,CACEXI,\r\n! PSIXN,CEXQAD,GAUS8,FQCEX,I1MACH,R1MACH,XERROR,FDUMP\r\n\r\nUSE Exponential_Integral\r\nIMPLICIT NONE\r\nINTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(12, 60)\r\n\r\nCOMPLEX (dp) :: z, cy(10), cq1, cq2\r\nINTEGER :: ierr, iprnt, ix, iy, kerr1, kerr2, kode, m, n, nb\r\nREAL (dp) :: err1, err2, tol, x, xtol, y\r\n\r\niprnt = 0\r\ntol = MAX(1.0D-15, EPSILON(0.0_dp))\r\nxtol = tol * 100.0_dp\r\nWRITE(*, 5000)\r\nWRITE(*, 5100)\r\nDO kode = 1, 2\r\n DO m = 1, 3\r\n DO n = 3, 11, 2\r\n DO iy = 1, 13, 3\r\n y = iy - 7\r\n WRITE(*, 5200) kode, m, n, y\r\n DO ix = 2, 14, 4\r\n x = -7.5_dp + (ix-1)\r\n IF (y /= 0.0_dp .OR. x > 0.0_dp) THEN\r\n z = CMPLX(x, y, KIND=dp)\r\n CALL cexint(z, n, kode, tol, m, cy, ierr)\r\n nb = n\r\n CALL cexqad(z, nb, kode, tol, cq1, kerr1)\r\n err1 = ABS(cy(1)-cq1) / ABS(cq1)\r\n nb = n + m - 1\r\n CALL cexqad(z, nb, kode, tol, cq2, kerr2)\r\n err2 = ABS(cy(m)-cq2) / ABS(cq2)\r\n IF (err1 >= xtol .OR. err2 >= xtol) THEN\r\n IF (iprnt /= 1) THEN\r\n iprnt = 1\r\n OPEN (7, FILE='CEXDAT7', STATUS='UNKNOWN')\r\n WRITE (7,5300)\r\n END IF\r\n WRITE (7,5400) z, err1, err2, n, m, kode, ierr, kerr1, kerr2\r\n WRITE (7,5400) cy(1), cq1\r\n WRITE (7,5400) cy(m), cq2\r\n END IF\r\n END IF\r\n END DO\r\n END DO\r\n END DO\r\n END DO\r\nEND DO\r\nIF (iprnt == 0) THEN\r\n WRITE(*, 5500)\r\nELSE\r\n WRITE(*, 5600)\r\nEND IF\r\nSTOP\r\n\r\n5000 FORMAT (' CEXINT VS QUADRATURE FOR PARAMETERS:'/)\r\n5100 FORMAT (' KODE M N Y -6.5.LE.X.LE.5.5')\r\n5200 FORMAT (i5, i5, i5, g13.5)\r\n5300 FORMAT (' Z,ERR1,ERR2,N,M,KODE,IERR,KERR1,KERR2')\r\n5400 FORMAT (4g11.3, 6I5)\r\n5500 FORMAT (/' QUICK CHECKS FOR CEXINT ARE OK.')\r\n5600 FORMAT (/' SEE DATA FILE CEXDAT7 FOR ERRORS')\r\nEND PROGRAM cqccex\r\n", "meta": {"hexsha": "c69468c2e95a31ab7a66a79bc0524c583e50801a", "size": 44983, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/toms683.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/toms683.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/toms683.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": 32.4318673396, "max_line_length": 87, "alphanum_fraction": 0.517306538, "num_tokens": 16344, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.899121366457407, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6939809804683336}} {"text": "subroutine calculate_face_velocity_interp(u, v, uf, vf, p, p_uf, p_vf, s_uf, s_vf, ap, dx, dy, nx, ny, xi, xf)\nuse kind_parameters\nimplicit none\n\ninteger, intent(in):: nx, ny, xi, xf\nreal(kind=dp), intent(in), dimension(nx,xi-1:xf+1):: u, v, ap, p\nreal(kind=dp), intent(in):: dx(nx), dy(ny)\nreal(kind=dp), intent(in), dimension(nx-1,xi-1:xf+1):: p_uf, s_uf\nreal(kind=dp), intent(in), dimension(nx,xi-1:xf+1):: p_vf, s_vf\nreal(kind=dp), intent(inout), dimension(nx-1,xi-1:xf+1):: uf\nreal(kind=dp), intent(inout), dimension(nx,xi-1:xf+1):: vf\n\n!! Other local variables\nreal(kind=dp), dimension(nx-1, xi-1:xf+1):: auf_bar\nreal(kind=dp), dimension(nx, xi-1:xf+1):: avf_bar\nreal(kind=dp):: fe_area, fn_area\ninteger:: iu, ju, iv, jv\n\ndo ju=xi,xf\n do iu=2,nx-2\n\n fe_area = dx(iu+1)/(dx(iu+1)+dx(iu))\n auf_bar(iu,ju) = 1.0d0/(fe_area/ap(iu,ju) + (1.0d0-fe_area)/ap(iu+1,ju))\n\n end do\n\nend do\n\ndo ju = xi,xf\n\n do iu = 2,nx-2\n\n uf(iu,ju) = 0.50d0*(u(iu,ju) + u(iu+1,ju)) + 1.0d0/auf_bar(iu,ju)*((p(iu,ju) - p(iu+1,ju))*dy(ju) + s_uf(iu,ju)) - 0.50d0*(1.0d0/ap(iu,ju)*(p_uf(iu-1,ju)-p_uf(iu,ju))*dy(ju) + 1.0d0/ap(iu+1,ju)*(p_uf(iu,ju)-p_uf(iu+1,ju))*dy(ju))\n! uf(iu,ju) = 0.50d0*(u(iu,ju) + u(iu+1,ju)) + 1.0d0/auf_bar(iu,ju)*((p(iu,ju) - p(iu+1,ju))*dy(ju)) - 0.50d0*(1.0d0/ap(iu,ju)*(p_uf(iu-1,ju)-p_uf(iu,ju))*dy(ju) + 1.0d0/ap(iu+1,ju)*(p_uf(iu,ju)-p_uf(iu+1,ju))*dy(ju))\n!\n end do\n\nend do\n\ndo jv = xi,xf\n\n do iv = 2,nx-1\n\n fn_area = dy(jv+1)/(dy(jv+1)+dy(jv))\n avf_bar(iv,jv) = 1.0d0/(fn_area/ap(iv,jv) + (1.0d0-fn_area)/ap(iv,jv+1))\n\n end do\n\nend do\n\ndo jv = xi,xf\n\n do iv = 2,nx-1\n\n vf(iv,jv) = 0.50d0*(v(iv,jv) + v(iv,jv+1)) + 1.0d0/avf_bar(iv,jv)*((p(iv,jv) - p(iv,jv+1))*dx(iv) + s_vf(iv,jv)) - 0.50d0*(1.0d0/ap(iv,jv)*(p_vf(iv,jv-1)-p_vf(iv,jv))*dx(iv) + 1.0d0/ap(iv,jv+1)*(p_vf(iv,jv)-p_vf(iv,jv+1))*dx(iv))\n! vf(iv,jv) = 0.50d0*(v(iv,jv) + v(iv,jv+1)) + 1.0d0/avf_bar(iv,jv)*((p(iv,jv) - p(iv,jv+1))*dx(iv)) - 0.50d0*(1.0d0/ap(iv,jv)*(p_vf(iv,jv-1)-p_vf(iv,jv))*dx(iv) + 1.0d0/ap(iv,jv+1)*(p_vf(iv,jv)-p_vf(iv,jv+1))*dx(iv))\n\n end do\n\nend do\n\nif (xf .eq. ny-1) then\n\n do iv = 2,nx-1\n\n vf(iv,ny-1) = v(iv,ny)\n\n end do\n\nend if\n\ncall exchange_data(uf, nx-1, xi, xf)\ncall exchange_data(vf, nx, xi, xf)\n\nend subroutine\n", "meta": {"hexsha": "248b808a5e6986ac72029ff7424ddd35d54893ff", "size": 2334, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "calculate_face_velocity_interp.f90", "max_stars_repo_name": "pratanuroy/Multigrid_Cavity", "max_stars_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-09-11T12:01:52.000Z", "max_stars_repo_stars_event_max_datetime": "2017-09-11T12:01:52.000Z", "max_issues_repo_path": "calculate_face_velocity_interp.f90", "max_issues_repo_name": "pratanuroy/Multigrid_Cavity", "max_issues_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "calculate_face_velocity_interp.f90", "max_forks_repo_name": "pratanuroy/Multigrid_Cavity", "max_forks_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.7105263158, "max_line_length": 237, "alphanum_fraction": 0.5706940874, "num_tokens": 1142, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037363973294, "lm_q2_score": 0.7490872187162396, "lm_q1q2_score": 0.6938822895843363}} {"text": "\n! Code by: Jostein Brandshoi\n\n! ---------------------------------------------------------------------------------------------------------------\n! Compile/run on Windows:\n! > gfortran -o storm_surge.exe storm_surge.f90\n! > storm_surge.exe \n!\n! Compile/run on Linux:\n! > gfortran -o storm_surge storm_surge.f90\n! > ./storm_surge \n!\n! Command line args:\n! output_filename : Give a filename (*.dat) to store numerical solutions\n!\n! Purpose of program:\n! Solve exercise k) (linear rotating (with wind stress and friction) shallow water\n! equations applied to a storm surge problem) on Problem Set 10 in GEF4510\n!\n! Equations:\n! dU/dt - fV = -gH_0 * dh/dx + (tau_sx - tau_bx) / rho_0\n! dV/dt + fU = (tau_sy - tau_by) / rho_0\n! dh/dt \\ dU/dx = 0\n!\n! Scheme (FBTCS):\n! U(j, n+1) = U(j, n) + dt * f * V(j, n) - ((g * H_0 * dt) / dx) *&\n! (h(j + 1, n) - h(j, n)) + (dt / rho_0) * (tau_sx - tau_bx_coeff * U(j, n))\n!\n! V(j, n+1) = V(j, n) - dt * f * U(j, n+1) + (dt / rho_0) * &\n! (tau_sy - tau_by_coeff * V(j, n))\n!\n! h(j, n+1) = h(j, n) - (dt / dx) * (U(j, n+1) - U(j - 1, n+1))\n! ---------------------------------------------------------------------------------------------------------------\n\nPROGRAM advection_solver\n IMPLICIT NONE\n ! ------------------------------- VARIABLE DECLARATIONS -------------------------------\n double precision, parameter :: g = 10.0 ! Accelereation of gravity [m/s^2]\n double precision, parameter :: rho_0 = 1E+3 ! Uniform constant density [kg/m^3]\n double precision, parameter :: f = 1E-4 ! Coriolis parameter [s^(-1)]\n double precision, parameter :: R = 2.4E-3 ! Factor used in bottom stress [m/s]\n double precision, parameter :: H_0 = 300.0 ! Equillibrium height [m]\n double precision, parameter :: c_0 = dsqrt(g * H_0) ! Phase speed [m/s]\n double precision, parameter :: L_R = c_0 / f ! Rossby's deformation radius [m]\n double precision, parameter :: L = L_R * 10.0 ! Max distance from coast [m]\n double precision, parameter :: tau_sx = 0.0 ! Surface wind stress (x-dir) [Pa]\n double precision, parameter :: tau_sy = 0.1 ! Surface wind stress (y-dir) [Pa]\n double precision, parameter :: tau_bx_coeff = (rho_0 * R) / H_0 ! Bottom stress coeff (x-dir) [kg/m^3s]\n double precision, parameter :: tau_by_coeff = (rho_0 * R) / H_0 ! Bottom stress coeff (y-dir) [kg/m^3s]\n\n double precision, parameter :: C = 0.80 ! Courant number [c_0 * delta_t / delta_x] [m/s]\n double precision, parameter :: dx = L_R / 10.0 ! Distance between spatial gridpoints [m]\n double precision, parameter :: dt = C * dx / c_0 ! Time between temporal gridpoints [s]\n\n integer :: j, n ! Counter variables (j: space, n: time)\n integer :: n_temp, n_curr = 1, n_next = 2 ! Indices to represent curr and next time\n integer, parameter :: j_max = idnint(L / dx) + 1 ! Total number of space points in domain\n integer, parameter :: n_max = 1000 ! Some arbitrary upper bound for simulation time\n\n double precision, dimension(j_max, 2) :: U = 0.0 ! To store U at times n and n + 1 (also sets IC)\n double precision, dimension(j_max, 2) :: V = 0.0 ! To store V at times n and n + 1 (also sets IC)\n double precision, dimension(j_max, 2) :: h = H_0 ! To store h at times n and n + 1 (also sets IC)\n\n character(len = 32) :: output_filename ! Variable to hold output filename for results\n integer, parameter :: unit_number = 10 ! Unit number for identifying output file\n ! -------------------------------------------------------------------------------------\n\n ! ---------- GETTING ARGS FROM CMD-LINE AND OPEN .DAT FILE FOR RESULT OUTPUT ----------\n CALL GET_COMMAND_ARGUMENT(1, output_filename) ! Get cmd-line arg for output file\n open(unit = unit_number, file = output_filename, form = \"formatted\") ! Open file that will store results\n ! -------------------------------------------------------------------------------------\n\n ! ---------------------------- USING FBTCS SCHEME AND BC'S ----------------------------\n do n = 0, n_max - 1 ! Loop, in time to compute all three variables U, V, h\n U(j_max, n_next) = 0.0 ! BC: No flow through coast\n h(1, n_next) = H_0 ! BC: Ekman solution at position far away from coast\n\n do j = 1, j_max - 1 ! Loop in space to compute U_j^(n+1)\n U(j, n_next) = U(j, n_curr) + dt * f * V(j, n_curr) - ((g * H_0 * dt) / dx) *&\n (h(j + 1, n_curr) - h(j, n_curr)) + (dt / rho_0) * (tau_sx - tau_bx_coeff * U(j, n_curr))\n end do\n\n do j = 1, j_max ! Loop in space to compute V_j^(n+1)\n V(j, n_next) = V(j, n_curr) - dt * f * U(j, n_next) + (dt / rho_0) * &\n (tau_sy - tau_by_coeff * V(j, n_curr))\n end do\n\n do j = 2, j_max ! Loop in space to compute h_j^(n+1)\n h(j, n_next) = h(j, n_curr) - (dt / dx) * (U(j, n_next) - U(j - 1, n_next))\n end do\n\n ! Write line-wise to file. Write only solution for half the domain (closest to coast) to file.\n write(unit = 10, fmt = \"(157f20.14)\") float(n), U(50:, n_curr), V(50:, n_curr), h(50:, n_curr)\n\n n_temp = n_next ! Set help index to next time step column column\n n_next = n_curr ! Set next time step index to current ime step column\n n_curr = n_temp ! Set current time step index to next time step column\n end do\n ! -------------------------------------------------------------------------------------\n\n close(unit = unit_number) ! Close file after writing\n\nEND PROGRAM advection_solver\n", "meta": {"hexsha": "88bc5bb5150d5de9eef1fafbef342ee76e62c868", "size": 5853, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "project3/storm_surge.f90", "max_stars_repo_name": "jostbr/GEF4510-Projects", "max_stars_repo_head_hexsha": "1dc6d42b60672481ac6c0ea61268127a8c683e7b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-10-05T12:44:32.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-05T12:44:32.000Z", "max_issues_repo_path": "project3/storm_surge.f90", "max_issues_repo_name": "jostbr/GEF4510-Projects", "max_issues_repo_head_hexsha": "1dc6d42b60672481ac6c0ea61268127a8c683e7b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "project3/storm_surge.f90", "max_forks_repo_name": "jostbr/GEF4510-Projects", "max_forks_repo_head_hexsha": "1dc6d42b60672481ac6c0ea61268127a8c683e7b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 56.2788461538, "max_line_length": 113, "alphanum_fraction": 0.5240047839, "num_tokens": 1650, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037302939515, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6938822798236723}} {"text": "C*****************************************************************\n FUNCTION F0(ARG)\nC *\nC CALCULATES THE ERROR FUNCTION ACCORDING TO A RATIONAL *\nC APPROXIMATION FROM M. ABRAMOWITZ AND I.A. STEGUN, *\nC ABSOLUTE ERROR IS LESS THAN 1.5*10**(-7) *\nC CAN BE REPLACED BY A BUILT-IN FUNCTION ON SOME MACHINES *\nC *\nC*****************************************************************\n IMPLICIT DOUBLE PRECISION(A-H,O-Z)\n DIMENSION A(5)\n DATA P/0.3275911D0/\n DATA A/0.254829592D0,-0.284496736D0,1.421413741D0,\n $ -1.453152027D0,1.061405429D0/\n real*8 SARG\n real*8 ERF\n\n if (ARG.lt.1.0D-6) then\n F0=1.0D0-ARG/3.0D0\n return\n endif\n\n SARG = sqrt(ARG)\n T=1.0D0/(1.0D0+P*SARG)\n TN=T\n POLY=A(1)*TN\n DO 10 I=2,5\n TN=TN*T\n POLY=POLY+A(I)*TN\n 10 CONTINUE\n ERF=1.0D0-POLY*DEXP(-ARG)\n\n F0 = 0.886226925452758014 / SARG * ERF\n RETURN\n END\nC***************************************************************\n", "meta": {"hexsha": "420d76ae5f34e666c9eb5969c71c3d28982ee675", "size": 1181, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/f0.f", "max_stars_repo_name": "dzik143/hartree-fock-f77", "max_stars_repo_head_hexsha": "83162d012a32d2f954931c4a4613577199af8039", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-10-26T19:21:41.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-26T19:21:41.000Z", "max_issues_repo_path": "src/f0.f", "max_issues_repo_name": "dzik143/hartree-fock-f77", "max_issues_repo_head_hexsha": "83162d012a32d2f954931c4a4613577199af8039", "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/f0.f", "max_forks_repo_name": "dzik143/hartree-fock-f77", "max_forks_repo_head_hexsha": "83162d012a32d2f954931c4a4613577199af8039", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.9189189189, "max_line_length": 66, "alphanum_fraction": 0.4055884843, "num_tokens": 348, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037221561135, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6938822737277218}} {"text": "!-----------------------------------------------------------------------\n! Fortran GPU Tutorial: Reduction\n! written by Viktor K. Decyk, UCLA\n module redux\n implicit none\n!\n contains\n!\n subroutine sum0(a,sa)\n! simple 1d sum reduction of length nx\n! sa = sum(a)\n implicit none\n real :: sa\n real, dimension(:) :: a\n! local data\n integer :: j\n!\n sa = 0.0\n do j = 1, size(a,1)\n sa = sa + a(j)\n enddo\n!\n end subroutine\n!\n subroutine sum1(a,sa,mx)\n! 1d sum reductions, each of length mx\n! sa = sum(a)\n implicit none\n integer :: mx\n real :: sa\n real, dimension(:) :: a\n! local data\n integer :: j, js, jb, nx, nbx\n real :: t\n! nx = size of a array\n nx = size(a,1)\n! nbx = number of blocks\n nbx = (nx - 1)/mx + 1\n!\n sa = 0.0\n do jb = 1, nbx\n t = 0.0\n do js = 1, min(mx,nx-mx*(jb-1))\n j = js + mx*(jb - 1)\n t = t + a(j)\n enddo\n sa = sa + t\n\n enddo\n!\n end subroutine\n!\n subroutine sum2(a,d,mx)\n! segmented 1d sum reductions, each of length mx\n! forall (j = 1:nbx); d(j) = sum(a(1+mx*(j-1):min(nx,mx*j))); end forall\n implicit none\n integer :: mx\n real, dimension(:) :: a, d\n! local data\n integer :: j, js, jb, nx, nbx\n real :: t\n! nx = size of a array\n nx = size(a,1)\n! nbx = number of blocks\n nbx = (nx - 1)/mx + 1\n!\n do jb = 1, nbx\n t = 0.0\n do js = 1, min(mx,nx-mx*(jb-1))\n j = js + mx*(jb - 1)\n t = t + a(j)\n enddo\n d(jb) = t\n enddo\n!\n end subroutine\n!\n end module\n\n", "meta": {"hexsha": "948d10d2c787c6f3023e3a92eaa2dd05d56db935", "size": 1624, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gpu/GPUTutorial/redux.f90", "max_stars_repo_name": "gcasabona/cuda", "max_stars_repo_head_hexsha": "064cfa02398e2402c113d45153d7ba36ae930f7e", "max_stars_repo_licenses": ["W3C"], "max_stars_count": 51, "max_stars_repo_stars_event_min_datetime": "2017-03-22T04:06:03.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T22:48:51.000Z", "max_issues_repo_path": "gpu/GPUTutorial/redux.f90", "max_issues_repo_name": "gcasabona/cuda", "max_issues_repo_head_hexsha": "064cfa02398e2402c113d45153d7ba36ae930f7e", "max_issues_repo_licenses": ["W3C"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gpu/GPUTutorial/redux.f90", "max_forks_repo_name": "gcasabona/cuda", "max_forks_repo_head_hexsha": "064cfa02398e2402c113d45153d7ba36ae930f7e", "max_forks_repo_licenses": ["W3C"], "max_forks_count": 25, "max_forks_repo_forks_event_min_datetime": "2017-02-22T05:21:32.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-02T14:53:19.000Z", "avg_line_length": 20.3, "max_line_length": 72, "alphanum_fraction": 0.4649014778, "num_tokens": 547, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.822189134878876, "lm_q2_score": 0.8438950947024555, "lm_q1q2_score": 0.693841377841939}} {"text": "MODULE NRTYPE\n\tIMPLICIT NONE\n \t!-----------------------------------------------------------\n\tINTEGER, PARAMETER :: I4B = SELECTED_INT_KIND(9)\n\tINTEGER, PARAMETER :: I2B = SELECTED_INT_KIND(4)\n\tINTEGER, PARAMETER :: I1B = SELECTED_INT_KIND(2)\n\tINTEGER, PARAMETER :: SP = KIND(1.0)\n\tINTEGER, PARAMETER :: DP = KIND(1.0D0)\n\tINTEGER, PARAMETER :: SPC = KIND((1.0,1.0))\n\tINTEGER, PARAMETER :: DPC = KIND((1.0D0,1.0D0))\n\tINTEGER, PARAMETER :: LGT = KIND(.TRUE.)\n\tREAL(SP), PARAMETER :: PI=3.141592653589793238462643383279502884197_SP\n\tREAL(SP), PARAMETER :: PIO2=1.57079632679489661923132169163975144209858_SP\n\tREAL(SP), PARAMETER :: TWOPI=6.283185307179586476925286766559005768394_SP\n\tREAL(SP), PARAMETER :: SQRT2=1.41421356237309504880168872420969807856967_SP\n\tREAL(SP), PARAMETER :: EULER=0.5772156649015328606065120900824024310422_SP\n\tREAL(DP), PARAMETER :: PI_D=3.141592653589793238462643383279502884197_DP\n\tREAL(DP), PARAMETER :: PIO2_D=1.57079632679489661923132169163975144209858_DP\n\tREAL(DP), PARAMETER :: TWOPI_D=6.283185307179586476925286766559005768394_DP\n\tTYPE SPRS2_SP\n\t\tINTEGER(I4B) :: N,NELT\n\t\tREAL(SP), DIMENSION(:), POINTER :: VAL\n\t\tINTEGER(I4B), DIMENSION(:), POINTER :: IROW\n\t\tINTEGER(I4B), DIMENSION(:), POINTER :: JCOL\n\tEND TYPE SPRS2_SP\n\tTYPE SPRS2_DP\n\t\tINTEGER(I4B) :: N,NELT\n\t\tREAL(DP), DIMENSION(:), POINTER :: VAL\n\t\tINTEGER(I4B), DIMENSION(:), POINTER :: IROW\n\t\tINTEGER(I4B), DIMENSION(:), POINTER :: JCOL\n\tEND TYPE SPRS2_DP\n\t !-----------------------------------------------------------\nEND MODULE NRTYPE\n\n", "meta": {"hexsha": "e88525c61488b5c244bed5a3fac47958e8abda79", "size": 1527, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "Parabolic_Equation/2DPE/PERF/nrtype.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/nrtype.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/nrtype.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": 43.6285714286, "max_line_length": 77, "alphanum_fraction": 0.6863130321, "num_tokens": 533, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950907764118, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.6938413764523825}} {"text": " PROGRAM Testo\n USE Integer_Complex_Arithmetic\n IMPLICIT NONE\n TYPE(INTCOMPLEX) :: var1, var2, ans\n\n var1 = 3\n PRINT*, \"var1 = 3\"\n CALL Put_INTCOMPLEX(var1)\n\n var1 = 5.99\n PRINT*, \"var1 = 5.99\"\n CALL Put_INTCOMPLEX(var1)\n\n var1 = 6.01\n PRINT*, \"var1 = 6.01\"\n CALL Put_INTCOMPLEX(var1)\n\n var1 = Setup_INTCOMPLEX(1,2)\n var2 = Setup_INTCOMPLEX(3,4)\n\n PRINT*, \"(1,2)+(3,4)\"\n ans = var1 + var2\n CALL Put_INTCOMPLEX(ans)\n\n PRINT*, \"(1,2)-(3,4)\"\n ans = var1 - var2\n CALL Put_INTCOMPLEX(ans)\n\n PRINT*, \"(1,2)/(3,4)\"\n ans = var1 / var2\n CALL Put_INTCOMPLEX(ans)\n\n PRINT*, \"(3,4)/(3,4)\"\n ans = var2 / var2\n CALL Put_INTCOMPLEX(ans)\n\n PRINT*, \"(3,4)/(1,2)\"\n ans = var2 / var1\n CALL Put_INTCOMPLEX(ans)\n\n PRINT*, \"(1,2)*(3,4)\"\n ans = var1 * var2\n CALL Put_INTCOMPLEX(ans)\n\n PRINT*, \"(1,2)**3\"\n ans = var1 ** 3\n CALL Put_INTCOMPLEX(ans)\n\n PRINT*, \"+(1,2)\"\n ans = +var1\n CALL Put_INTCOMPLEX(ans)\n\n PRINT*, \"-(1,2)\"\n ans = -var1\n CALL Put_INTCOMPLEX(ans)\n\n PRINT*, \"Type in the two INTCOMPLEX components\"\n CALL Get_INTCOMPLEX(var1)\n PRINT*, \"This is what was typed in\"\n CALL Put_INTCOMPLEX(var1)\n\n PRINT*, \"Your number/(3,4)\"\n ans = var1 / var2\n CALL Put_INTCOMPLEX(ans)\n\n! Intrinsics\n\n PRINT*, \"REAL(3,4)\"\n PRINT*, REAL(var2)\n PRINT*, \"INT(3,4)\"\n PRINT*, INT(var2)\n PRINT*, \"AIMAG(3,4)\"\n PRINT*, AIMAG(var2)\n PRINT*, \"CONJG(3,4)\"\n CALL Put_INTCOMPLEX(CONJG(var2))\n PRINT*, \"ABS(3,4)\"\n PRINT*, ABS(var2)\n\n! REAL | INTEGER .OP. INTCOMPLEX\n\n PRINT*, \"2+(3,4)\"\n ans = 2 + var2\n CALL Put_INTCOMPLEX(ans)\n\n PRINT*, \"2-(3,4)\"\n ans = 2 - var2\n CALL Put_INTCOMPLEX(ans)\n\n PRINT*, \"2*(3,4)\"\n ans = 2 * var2\n CALL Put_INTCOMPLEX(ans)\n\n PRINT*, \"2/(3,4)\"\n ans = 2 /var2\n CALL Put_INTCOMPLEX(ans)\n\n var1 = Setup_INTCOMPLEX(1,2)\n PRINT*, \"4/(1,2)\"\n ans = 4/var1\n CALL Put_INTCOMPLEX(ans)\n\n PRINT*, \"2.5+(3,4)\"\n ans = 2.5 + var2\n CALL Put_INTCOMPLEX(ans)\n\n PRINT*, \"2.5-(3,4)\"\n ans = 2.5 - var2\n CALL Put_INTCOMPLEX(ans)\n\n PRINT*, \"2.5*(3,4)\"\n ans = 2 * var2\n CALL Put_INTCOMPLEX(ans)\n\n PRINT*, \"2.5/(3,4)\"\n ans = 2.5 /var2\n CALL Put_INTCOMPLEX(ans)\n\n PRINT*, \"4.7/(1,2)\"\n ans = 4.7/var1\n CALL Put_INTCOMPLEX(ans)\n\n\n PRINT*, \"-2.5+(3,4)\"\n ans = -2.5 + var2\n CALL Put_INTCOMPLEX(ans)\n\n PRINT*, \"-2.5-(3,4)\"\n ans = -2.5 - var2\n CALL Put_INTCOMPLEX(ans)\n\n PRINT*, \"-2.5*(3,4)\"\n ans = -2.5 * var2\n CALL Put_INTCOMPLEX(ans)\n\n PRINT*, \"-2.5/(3,4)\"\n ans = -2.5 /var2\n CALL Put_INTCOMPLEX(ans)\n\n PRINT*, \"-4.7/(1,2)\"\n ans = -4.7/var1\n CALL Put_INTCOMPLEX(ans)\n\n! INTCOMPLEX .OP. INTEGER | REAL\n\n PRINT*, \"(3,4)+2\"\n ans = var2 + 2\n CALL Put_INTCOMPLEX(ans)\n\n PRINT*, \"3,4)-2\"\n ans = var2-2\n CALL Put_INTCOMPLEX(ans)\n\n PRINT*, \"(3,4) * 2\"\n ans = var2 * 2\n CALL Put_INTCOMPLEX(ans)\n\n PRINT*, \"(3,4)/2\"\n ans = var2/2\n CALL Put_INTCOMPLEX(ans)\n\n PRINT*, \"(1,2)/4\"\n ans = var1/4\n CALL Put_INTCOMPLEX(ans)\n\n PRINT*, \"(3,4)+2.5\"\n ans = var2+2.5\n CALL Put_INTCOMPLEX(ans)\n\n PRINT*, \"(3,4)-2.5\"\n ans = var2-2.5\n CALL Put_INTCOMPLEX(ans)\n\n PRINT*, \"(3,4)*2.5\"\n ans = var2*2.5\n CALL Put_INTCOMPLEX(ans)\n\n PRINT*, \"(3,4)/2.5\"\n ans = var2/2.5\n CALL Put_INTCOMPLEX(ans)\n\n PRINT*, \"(1,2)/4.7\"\n ans = var1/4.7\n CALL Put_INTCOMPLEX(ans)\n\n PRINT*, \"-(3,4)-2.5\"\n ans = -var2-2.5\n CALL Put_INTCOMPLEX(ans)\n\n PRINT*, \"(3,4)*(-2.5)\"\n ans = var2*(-2.5)\n CALL Put_INTCOMPLEX(ans)\n\n PRINT*, \"0.99 * (3,4)\"\n ans = 0.99 *var2\n CALL Put_INTCOMPLEX(ans)\n\n PRINT*, \"1.0 * (3,4)\"\n ans = 1.0 *var2\n CALL Put_INTCOMPLEX(ans)\n\n! Extended precision\n\n var1 = Setup_INTCOMPLEX(3_short_int,1_long_int)\n PRINT*, \"var1 = Setup_INTCOMPLEX(3_short_int,1_long_int)\"\n CALL Put_INTCOMPLEX(var1)\n\n var1 = Setup_INTCOMPLEX(3_short_int,1_short_int)\n PRINT*, \"var1 = Setup_INTCOMPLEX(3_short_int,1_short_int)\"\n CALL Put_INTCOMPLEX(var1)\n\n var1 = Setup_INTCOMPLEX(3_long_int,1_short_int)\n PRINT*, \"var1 = Setup_INTCOMPLEX(3_long_int,1_short_int)\"\n CALL Put_INTCOMPLEX(var1)\n\n PRINT*, \"var1 = Setup_INTCOMPLEX(3_long_int,1_long_int)\"\n var1 = Setup_INTCOMPLEX(3_long_int,1_long_int)\n CALL Put_INTCOMPLEX(var1)\n\n PRINT*, \"200_short_int * Setup_INTCOMPLEX(3_long_int,1_long_int)\"\n ans = 200_short_int * var1\n CALL Put_INTCOMPLEX(ans)\n \n PRINT*, \"Setup_INTCOMPLEX(3_long_int,1_long_int) - 20_short_int\"\n ans = var1 - 20_short_int\n CALL Put_INTCOMPLEX(ans)\n \n PRINT*, \"Setup_INTCOMPLEX(3_long_int,1_long_int) ** 200_short_int\"\n ans = var1 ** 6_short_int\n CALL Put_INTCOMPLEX(ans)\n \n PRINT*, \"var ** 6_long_int\"\n ans = var1 ** 6_long_int\n CALL Put_INTCOMPLEX(ans)\n \n PRINT*, \"var1 = Setup_INTCOMPLEX(30000_long_int,10000_long_int)\"\n var1 = Setup_INTCOMPLEX(30000_long_int,10000_long_int)\n CALL Put_INTCOMPLEX(var1)\n\n PRINT*, \"400_long_int / Setup_INTCOMPLEX(30000_long_int,10000_long_int)\"\n ans = 400_long_int / var1\n CALL Put_INTCOMPLEX(ans)\n \n PRINT*, \"Setup_INTCOMPLEX(30000_long_int,10000_long_int) / 4000000\"\n ans = var1 / 4000000_long_int \n CALL Put_INTCOMPLEX(ans)\n \n END PROGRAM Testo\n\n", "meta": {"hexsha": "a7b740050a24bac1ee3769982ad10754e56047e5", "size": 5574, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "HPFCourse/progs/IntegerComplex6Program.f90", "max_stars_repo_name": "efurlanm/f90", "max_stars_repo_head_hexsha": "f9eab0725bcc244d8c11179058602443c2352a8a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-02-17T00:25:51.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-17T00:25:51.000Z", "max_issues_repo_path": "HPFCourse/progs/IntegerComplex6Program.f90", "max_issues_repo_name": "efurlanm/f90", "max_issues_repo_head_hexsha": "f9eab0725bcc244d8c11179058602443c2352a8a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HPFCourse/progs/IntegerComplex6Program.f90", "max_forks_repo_name": "efurlanm/f90", "max_forks_repo_head_hexsha": "f9eab0725bcc244d8c11179058602443c2352a8a", "max_forks_repo_licenses": ["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.3855421687, "max_line_length": 77, "alphanum_fraction": 0.5742734123, "num_tokens": 2045, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219504, "lm_q2_score": 0.8438950966654772, "lm_q1q2_score": 0.6938413757791261}} {"text": "PROGRAM pg124\r\n!-------------------------------------------------------------------------\r\n! program 12.4 three dimensional transient analysis of heat conduction\r\n! equation using 8-node hexahedral elements; DEC, parallel pcg version\r\n! implicit; integration in time using 'theta' method\r\n!-------------------------------------------------------------------------\r\n!USE mpi_wrapper !remove comment for serial compilation\r\n USE precision; USE global_variables; USE mp_interface; USE input\r\n USE output; USE loading; USE timing; USE maths; USE gather_scatter\r\n USE geometry; USE new_library; USE common_mod; USE geometry_mod\r\n IMPLICIT NONE\r\n!neq,ntot are now global variables - not declared\r\n INTEGER, PARAMETER::ndim=3,nodof=1,nprops=5\r\n INTEGER::nod,nn,nr,nip,i,j,k,l,m,iters,limit,iel,nstep,npri,nres,it,prog, &\r\n nlen,node_end,node_start,nodes_pp,loaded_freedoms,fixed_freedoms,is, &\r\n fixed_freedoms_pp,fixed_freedoms_start,loaded_freedoms_pp,np_types, &\r\n loaded_freedoms_start,nels,ndof,npes_pp,meshgen,partitioner,tz\r\n REAL(iwp)::kx,ky,kz,det,theta,dtim,real_time,tol,alpha,beta,up,big,q, &\r\n rho,cp,val0\r\n REAL(iwp),PARAMETER::zero=0.0_iwp,penalty=1.e20_iwp,t0=0.0_iwp\r\n CHARACTER(LEN=15)::element; CHARACTER(LEN=50)::argv,fname\r\n CHARACTER(LEN=6)::ch; LOGICAL::converged=.false.\r\n REAL(iwp),ALLOCATABLE::loads_pp(:),u_pp(:),p_pp(:),points(:,:),kay(:),&\r\n fun(:),jac(:,:),der(:,:),deriv(:,:),weights(:),d_pp(:),col(:,:), &\r\n kc(:,:),pm(:,:),funny(:,:),storka_pp(:,:,:),row(:,:),prop(:,:), &\r\n storkb_pp(:,:,:),x_pp(:),xnew_pp(:),pmul_pp(:,:),utemp_pp(:,:), &\r\n diag_precon_pp(:),diag_precon_tmp(:,:),g_coord_pp(:,:,:),timest(:), &\r\n ttr_pp(:),eld_pp(:,:),val(:,:),val_f(:),store_pp(:),r_pp(:), &\r\n kcx(:,:),kcy(:,:),kcz(:,:),eld(:)\r\n INTEGER,ALLOCATABLE::rest(:,:),g_num_pp(:,:),g_g_pp(:,:),no(:), &\r\n no_pp(:),no_f_pp(:),no_pp_temp(:),sense(:),node(:),etype_pp(:)\r\n\r\n INTEGER :: n_smplx\r\n INTEGER, ALLOCATABLE :: smplx(:,:)\r\n REAL(iwp):: ka\r\n!--------------------------input and initialisation-----------------------\r\n ALLOCATE(timest(20)); timest=zero; timest(1)=elap_time()\r\n CALL find_pe_procs(numpe,npes); CALL getname(argv,nlen)\r\n CALL read_p124(argv,numpe,dtim,element,fixed_freedoms,limit, &\r\n loaded_freedoms,meshgen,nels,nip,nn,nod,npri,nr,nres,nstep, &\r\n partitioner,theta,tol,np_types,val0)\r\n CALL calc_nels_pp(argv,nels,npes,numpe,partitioner,nels_pp)\r\n ndof=nod*nodof; ntot=ndof\r\n ALLOCATE(g_num_pp(nod,nels_pp),g_coord_pp(nod,ndim,nels_pp), &\r\n etype_pp(nels_pp),prop(nprops,np_types))\r\n g_num_pp=0; g_coord_pp=zero; etype_pp=0; prop=zero\r\n IF (nr>0) THEN; ALLOCATE(rest(nr,nodof+1)); rest=0; END IF\r\n CALL read_elements(argv,iel_start,nn,npes,numpe,etype_pp,g_num_pp)\r\n IF(meshgen==2) CALL abaqus2sg(element,g_num_pp)\r\n CALL read_g_coord_pp(argv,g_num_pp,nn,npes,numpe,g_coord_pp)\r\n IF (nr>0) CALL read_rest(argv,numpe,rest)\r\n CALL read_material(argv,prop,numpe,npes)\r\n ALLOCATE (points(nip,ndim),weights(nip),kay(ndim),fun(nod), &\r\n jac(ndim,ndim),der(ndim,nod),deriv(ndim,nod),pm(ntot,ntot), &\r\n kc(ntot,ntot),funny(1,nod),g_g_pp(ntot,nels_pp), &\r\n storka_pp(ntot,ntot,nels_pp),eld(ntot),col(ntot,1),row(1,ntot), &\r\n utemp_pp(ntot,nels_pp),storkb_pp(ntot,ntot,nels_pp), &\r\n pmul_pp(ntot,nels_pp),kcx(ntot,ntot),kcy(ntot,ntot),kcz(ntot,ntot))\r\n!---------- find the steering array and equations per process -----------\r\n timest(2)=elap_time(); g_g_pp=0; neq=0\r\n IF(nr>0) THEN; CALL rearrange_2(rest)\r\n elements_1: DO iel = 1, nels_pp\r\n CALL find_g4(g_num_pp(:,iel),g_g_pp(:,iel),rest)\r\n END DO elements_1\r\n ELSE\r\n g_g_pp=g_num_pp !When nr = 0, g_num_pp and g_g_pp are identical\r\n END IF\r\n neq=MAXVAL(g_g_pp); neq=max_p(neq); CALL calc_neq_pp\r\n CALL calc_npes_pp(npes,npes_pp); CALL make_ggl(npes_pp,npes,g_g_pp)\r\n DO i=1,neq_pp;IF(nres==ieq_start+i-1)THEN;it=numpe;is=i;END IF;END DO\r\n IF(numpe==it)THEN\r\n OPEN(11,FILE=argv(1:nlen)//'.res',STATUS='REPLACE',ACTION='WRITE')\r\n WRITE(11,'(A,I5,A)')\"This job ran on \", npes,\" processes\"\r\n WRITE(11,'(A,3(I7,A))')\"There are \",nn,\" nodes\",nr, &\r\n \" restrained and \",neq,\" equations\"\r\n WRITE(11,'(A,F10.4)')\"Time after setup is \",elap_time()-timest(1)\r\n END IF\r\n ALLOCATE(loads_pp(neq_pp),diag_precon_pp(neq_pp),u_pp(neq_pp), &\r\n d_pp(neq_pp),p_pp(neq_pp),x_pp(neq_pp),xnew_pp(neq_pp),r_pp(neq_pp))\r\n loads_pp=zero; diag_precon_pp=zero; u_pp=zero; r_pp=zero; d_pp=zero\r\n p_pp=zero; x_pp=zero; xnew_pp=zero\r\n!-------------- element stiffness using DEC and storage ----------------\r\n storka_pp=zero; storkb_pp=zero; dim_cmplx = 3; dim_embbd = 3; k=dim_cmplx+1\r\n ALLOCATE(num_pelm_pp(1)); num_pelm_pp(1)=nod; extra_pelm=0; glb_offset=0\r\n glb_num_elm = (/ nod, 19, 18, 6 /); num_elm=glb_num_elm\r\n ALLOCATE(lcl_complex(k));\r\n ALLOCATE(lcl_complex(1)%centers(nod,dim_embbd),&\r\n lcl_complex(k)%orientation(6),lcl_complex(k)%node_indx(6,k))\r\n lcl_complex(k)%orientation=0; indx_offset = 0\r\n elements_3: DO iel=1,nels_pp\r\n kc=zero; pm=zero;\r\n kay(1)=prop(1,etype_pp(iel)); kay(2)=prop(2,etype_pp(iel));\r\n kay(3)=prop(3,etype_pp(iel)); rho=prop(4,etype_pp(iel))\r\n cp=prop(5,etype_pp(iel))\r\n\r\n !- split elements into simplices\r\n CALL elm2smplx(num_elm(dim_cmplx+1),lcl_complex(dim_cmplx+1)%node_indx,&\r\n g_coord_pp(:,:,iel),element,nod)\r\n\r\n !- Recursively compute element (co-)boundaries\r\n DO k=dim_cmplx+1,2,-1; CALL calc_bndry_cobndry(k); END DO\r\n\r\n !- setup connectivity\r\n DO k=1,dim_cmplx+1\r\n lcl_complex(k)%lcl_node_indx = lcl_complex(k)%node_indx\r\n END DO\r\n\r\n !- calc circumcenter\r\n lcl_complex(1)%centers = g_coord_pp(:,:,iel)\r\n DO k=2,dim_cmplx+1; CALL calc_circumcenters(k); END DO\r\n\r\n !- calc primal edge and dual area and primal direction\r\n CALL calc_prml_unsgnd_vlm(2); CALL calc_dual_vlm(1); CALL calc_prml_dir()\r\n\r\n kcx=zero\r\n DO i=1,nod\r\n DO j=1,lcl_complex(1)%num_cobndry(i)\r\n k = lcl_complex(1)%cobndry(i)%indx(j)\r\n IF (ABS(lcl_complex(2)%dual_volume(k) / &\r\n max(lcl_complex(2)%prml_volume(k),small)) 0) THEN\r\n ALLOCATE(node(fixed_freedoms),no_pp_temp(fixed_freedoms), &\r\n no(fixed_freedoms),sense(fixed_freedoms),val_f(fixed_freedoms))\r\n node=0; no=0; no_pp_temp=0; sense=0; val_f = zero\r\n CALL read_fixed(argv,numpe,node,sense,val_f)\r\n CALL find_no2(g_g_pp,g_num_pp,node,sense,no)\r\n CALL reindex(ieq_start,no,no_pp_temp,fixed_freedoms_pp, &\r\n fixed_freedoms_start,neq_pp)\r\n ALLOCATE(no_f_pp(fixed_freedoms_pp),store_pp(fixed_freedoms_pp))\r\n no_f_pp=0; store_pp=zero; no_f_pp=no_pp_temp(1:fixed_freedoms_pp)\r\n DEALLOCATE(node,no,sense,no_pp_temp)\r\n END IF\r\n IF(fixed_freedoms==0) fixed_freedoms_pp=0\r\n!-------------------------- invert preconditioner ------------------------\r\n IF(fixed_freedoms_pp > 0) THEN\r\n DO i=1,fixed_freedoms_pp; l=no_f_pp(i)-ieq_start+1\r\n diag_precon_pp(l)=diag_precon_pp(l)+penalty\r\n store_pp(i)=diag_precon_pp(l)\r\n END DO\r\n END IF; diag_precon_pp=1._iwp/diag_precon_pp\r\n!--------------- read in loaded nodes and get starting r_pp --------------\r\n IF(loaded_freedoms>0) THEN\r\n ALLOCATE(node(loaded_freedoms),val(nodof,loaded_freedoms), &\r\n no_pp_temp(loaded_freedoms)); val=zero; node=0; no_pp_temp=0\r\n CALL read_loads(argv,numpe,node,val)\r\n CALL reindex(ieq_start,node,no_pp_temp,loaded_freedoms_pp, &\r\n loaded_freedoms_start,neq_pp); ALLOCATE(no_pp(loaded_freedoms_pp))\r\n no_pp=0; no_pp=no_pp_temp(1:loaded_freedoms_pp)\r\n DEALLOCATE(no_pp_temp,node)\r\n END IF\r\n IF(loaded_freedoms==0) loaded_freedoms_pp=0\r\n!------------------------- start time stepping loop ----------------------\r\n CALL calc_nodes_pp(nn,npes,numpe,node_end,node_start,nodes_pp)\r\n ALLOCATE(ttr_pp(nodes_pp),eld_pp(ntot,nels_pp))\r\n ttr_pp=zero; eld_pp=zero\r\n IF(numpe==it) &\r\n WRITE(11,'(A)') \" Time Temperature Iterations \"\r\n IF(numpe==1) THEN\r\n OPEN(13, file=argv(1:nlen)//'.npp', status='replace', action='write')\r\n WRITE(13,*) nn; WRITE(13,*) nstep/npri; WRITE(13,*) npes\r\n END IF\r\n timesteps: DO j=1,nstep\r\n real_time=j*dtim; timest(3)=elap_time(); loads_pp=zero\r\n!---- apply loads (sources and/or sinks) supplied as a boundary value ----\r\n IF(loaded_freedoms_pp>0) THEN\r\n DO i=1,loaded_freedoms_pp; k=no_pp(i)-ieq_start+1\r\n loads_pp(k)=val(loaded_freedoms_start+i-1,1)*dtim\r\n END DO; q=q+SUM_P(loads_pp)\r\n END IF\r\n!- compute RHS of time stepping equation, using storkb_pp, add to loads --\r\n u_pp=zero; pmul_pp=zero; utemp_pp=zero\r\n IF(j/=1) THEN\r\n CALL gather(xnew_pp,pmul_pp)\r\n elements_2a: DO iel=1,nels_pp\r\n utemp_pp(:,iel)=MATMUL(storkb_pp(:,:,iel),pmul_pp(:,iel))\r\n END DO elements_2a; CALL scatter(u_pp,utemp_pp)\r\n IF(fixed_freedoms_pp>0) THEN\r\n DO i=1,fixed_freedoms_pp; l=no_f_pp(i)-ieq_start+1\r\n k=fixed_freedoms_start+i-1; u_pp(l)=store_pp(i)*val_f(k)\r\n END DO\r\n END IF; loads_pp=loads_pp+u_pp\r\n ELSE\r\n!------------------------ set initial temperature ------------------------\r\n x_pp=val0; IF(numpe==it) WRITE(11,'(2e12.4)') 0.0_iwp, x_pp(is)\r\n IF(fixed_freedoms_pp>0) THEN\r\n DO i=1,fixed_freedoms_pp; l=no_f_pp(i)-ieq_start+1\r\n k=fixed_freedoms_start+i-1; x_pp(l)=val_f(k)\r\n END DO\r\n END IF\r\n CALL gather(x_pp,pmul_pp)\r\n elements_2c: DO iel=1,nels_pp\r\n utemp_pp(:,iel)=MATMUL(storka_pp(:,:,iel),pmul_pp(:,iel))\r\n END DO elements_2c; CALL scatter(u_pp,utemp_pp)\r\n loads_pp=loads_pp+u_pp; tz=0\r\n!----------------------- output \"results\" at t=0 -------------------------\r\n IF(numpe==1)THEN; WRITE(ch,'(I6.6)') tz\r\n OPEN(12,file=argv(1:nlen)//\".ensi.NDTTR-\"//ch,status='replace', &\r\n action='write')\r\n WRITE(12,'(A)') &\r\n \"Alya Ensight Gold --- Scalar per-node variable file\"\r\n WRITE(12,'(A/A/A)') \"part\", \" 1\",\"coordinates\"\r\n END IF\r\n eld_pp=zero; ttr_pp=zero; CALL gather(x_pp(1:),eld_pp)\r\n CALL scatter_nodes(npes,nn,nels_pp,g_num_pp,nod,nodof,nodes_pp, &\r\n node_start,node_end,eld_pp,ttr_pp,1)\r\n CALL dismsh_ensi_p(12,1,nodes_pp,npes,numpe,1,ttr_pp)\r\n! CALL dismsh_pb(12,1,nodes_pp,npes,numpe,1,ttr_pp)\r\n END IF\r\n!----- when x=0. p and r are just loads but in general p=r=loads-A*x -----\r\n r_pp=zero; pmul_pp=zero; utemp_pp=zero; x_pp=zero\r\n CALL gather(x_pp,pmul_pp)\r\n elements_2b: DO iel=1,nels_pp\r\n utemp_pp(:,iel)=MATMUL(storka_pp(:,:,iel),pmul_pp(:,iel))\r\n END DO elements_2b; CALL scatter(r_pp,utemp_pp)\r\n IF(fixed_freedoms_pp>0) THEN\r\n DO i=1,fixed_freedoms_pp; l=no_f_pp(i)-ieq_start+1\r\n k=fixed_freedoms_start+i-1; r_pp(l)=store_pp(i)*val_f(k)\r\n END DO\r\n END IF\r\n r_pp=loads_pp-r_pp; d_pp=diag_precon_pp*r_pp; p_pp=d_pp; iters=0\r\n!---------------- solve simultaneous equations by pcg --------------------\r\n iterations: DO\r\n iters=iters+1; u_pp=zero; pmul_pp=zero; utemp_pp=zero\r\n CALL gather(p_pp,pmul_pp)\r\n elements_6: DO iel=1,nels_pp\r\n utemp_pp(:,iel)=MATMUL(storka_pp(:,:,iel),pmul_pp(:,iel))\r\n END DO elements_6; CALL scatter(u_pp,utemp_pp)\r\n IF(fixed_freedoms_pp>0) THEN; DO i=1,fixed_freedoms_pp\r\n l=no_f_pp(i)-ieq_start+1; u_pp(l)=p_pp(l)*store_pp(i)\r\n END DO; END IF\r\n up=DOT_PRODUCT_P(r_pp,d_pp); alpha=up/DOT_PRODUCT_P(p_pp,u_pp)\r\n xnew_pp=x_pp+p_pp*alpha; r_pp=r_pp-u_pp*alpha\r\n d_pp=diag_precon_pp*r_pp; beta=DOT_PRODUCT_P(r_pp,d_pp)/up\r\n p_pp=d_pp+p_pp*beta; CALL checon_par(xnew_pp,tol,converged,x_pp)\r\n IF(converged.OR.iters==limit)EXIT\r\n END DO iterations; timest(4)=timest(4)+(elap_time()-timest(3))\r\n IF(j/npri*npri==j)THEN; timest(5)=elap_time()\r\n IF(numpe==1)THEN; WRITE(ch,'(I6.6)') j\r\n OPEN(12,file=argv(1:nlen)//\".ensi.NDTTR-\"//ch,status='replace', &\r\n action='write')\r\n WRITE(12,'(A)') &\r\n \"Alya Ensight Gold --- Scalar per-node variable file\"\r\n WRITE(12,'(A/A/A)') \"part\", \" 1\",\"coordinates\"\r\n END IF; eld_pp=zero; ttr_pp=zero; CALL gather(xnew_pp(1:),eld_pp)\r\n CALL scatter_nodes(npes,nn,nels_pp,g_num_pp,nod,nodof,nodes_pp, &\r\n node_start,node_end,eld_pp,ttr_pp,1)\r\n CALL dismsh_ensi_p(12,1,nodes_pp,npes,numpe,1,ttr_pp)\r\n! CALL dismsh_pb(12,1,nodes_pp,npes,numpe,1,ttr_pp)\r\n IF(numpe==1) CLOSE(12)\r\n IF(numpe==it) WRITE(11,'(2E12.4,I10)') real_time,xnew_pp(is),iters\r\n timest(6)=timest(6)+(elap_time()-timest(5))\r\n END IF\r\n END DO timesteps\r\n IF(numpe==it) THEN\r\n WRITE(11,'(A,F10.4)') \"The solution phase took \",timest(4)\r\n WRITE(11,'(A,F10.4)') \"Writing the output took \",timest(6)\r\n WRITE(11,'(A,F10.4)') \"This analysis took \",elap_time()-timest(1)\r\n CLOSE(11)\r\n END IF; CALL SHUTDOWN()\r\nEND PROGRAM pg124\r\n", "meta": {"hexsha": "ccbc3ad492770da2c3dfe8b5567daab9099042ad", "size": 14756, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/pg124/pg124.f90", "max_stars_repo_name": "ParaFEM/ParaGEMS", "max_stars_repo_head_hexsha": "fc494ba26b0b7d740bb386e2b52436a9d1f53927", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pg124/pg124.f90", "max_issues_repo_name": "ParaFEM/ParaGEMS", "max_issues_repo_head_hexsha": "fc494ba26b0b7d740bb386e2b52436a9d1f53927", "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/pg124/pg124.f90", "max_forks_repo_name": "ParaFEM/ParaGEMS", "max_forks_repo_head_hexsha": "fc494ba26b0b7d740bb386e2b52436a9d1f53927", "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": 50.361774744, "max_line_length": 87, "alphanum_fraction": 0.6319463269, "num_tokens": 4935, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178895092415, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6937150108050858}} {"text": "C$Procedure RAXISA ( Rotation axis of a matrix )\n \n SUBROUTINE RAXISA ( MATRIX, AXIS, ANGLE )\n \nC$ Abstract\nC\nC Compute the axis of the rotation given by an input matrix\nC and the angle of the rotation about that axis.\nC\nC$ Disclaimer\nC\nC THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE\nC CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.\nC GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE\nC ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE\nC PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED \"AS-IS\"\nC TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY\nC WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A\nC PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC\nC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE\nC SOFTWARE AND RELATED MATERIALS, HOWEVER USED.\nC\nC IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA\nC BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT\nC LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,\nC INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,\nC REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE\nC REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.\nC\nC RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF\nC THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY\nC CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE\nC ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.\nC\nC$ Required_Reading\nC\nC ROTATION\nC\nC$ Keywords\nC\nC ANGLE, MATRIX, ROTATION\nC\nC$ Declarations\n \n DOUBLE PRECISION MATRIX ( 3, 3 )\n DOUBLE PRECISION AXIS ( 3 )\n DOUBLE PRECISION ANGLE\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC MATRIX I 3x3 rotation matrix in double precision.\nC AXIS O Axis of the rotation.\nC ANGLE O Angle through which the rotation is performed.\nC\nC$ Detailed_Input\nC\nC MATRIX is a 3x3 rotation matrix in double precision.\nC\nC$ Detailed_Output\nC\nC AXIS is a unit vector pointing along the axis of the\nC rotation. In other words, AXIS is a unit eigenvector\nC of the input matrix, corresponding to the eigenvalue\nC 1. If the input matrix is the identity matrix, AXIS\nC will be the vector (0, 0, 1). If the input rotation is\nC a rotation by PI radians, both AXIS and -AXIS may be\nC regarded as the axis of the rotation.\nC\nC ANGLE is the angle between V and MATRIX*V for any non-zero\nC vector V orthogonal to AXIS. Angle is given in\nC radians. The angle returned will be in the range from\nC 0 to PI.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC 1) If the input matrix is not a rotation matrix (where a fairly\nC loose tolerance is used to check this) a routine in the\nC call tree of this routine will signal an error indicating\nC the problem.\nC\nC 2) If the input matrix is the identity matrix, this routine\nC returns an angle of 0.0, and an axis of ( 0.0, 0.0, 1.0 ).\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC Every rotation matrix has an axis A such any vector, V, parallel\nC to that axis satisfies the equation\nC\nC V = MATRIX * V\nC\nC This routine returns a unit vector AXIS parallel to the axis of\nC the input rotation matrix. Moreover for any vector W orthogonal\nC to the axis of the rotation\nC\nC AXIS and W x MATRIX*W\nC\nC (where \"x\" denotes the cross product operation)\nC\nC will be positive scalar multiples of one another (at least to\nC within the ability to make such computations with double\nC precision arithmetic, and under the assumption that the MATRIX\nC does not represent a rotation by zero or Pi radians).\nC\nC The angle returned will be the angle between W and MATRIX*W for\nC any vector orthogonal to AXIS.\nC\nC If the input matrix is a rotation by 0 or PI radians some choice\nC must be made for the AXIS returned. In the case of a rotation by\nC 0 radians, AXIS is along the positive z-axis. In the case of a\nC rotation by 180 degrees, two choices are\nC\nC$ Examples\nC\nC This routine can be used to numerically approximate the\nC instantaneous angular velocity vector of a rotating object.\nC\nC Suppose that R(t) is the rotation matrix whose columns represent\nC the inertial pointing vectors of the bodyfixed axes of an object\nC at time t.\nC\nC Then the angular velocity vector points along the vector given\nC by:\nC T\nC limit AXIS( R(t+h)R )\nC h-->0\nC\nC And the magnitude of the angular velocity at time t is given by:\nC\nC T\nC d ANGLE ( R(t+h)R(t) )\nC ---------------------- at h = 0\nC dh\nC\nC Thus to approximate the angular velocity vector the following\nC code fragment will do\nC\nC Load t into the double precision variable T\nC Load h into the double precision variable H\nC Load R(t+h) into the 3 by 3 double precision array RTH\nC Load R(t) into the 3 by 3 double precision array RT\nC .\nC .\nC .\nC compute the infinitesimal rotation R(t+h)R(t)**T\nC\nC CALL MXMT ( RTH, RT, INFROT )\nC\nC compute the AXIS and ANGLE of the infinitesimal rotation\nC\nC CALL RAXISA ( INFROT, AXIS, ANGLE )\nC\nC scale axis to get the angular velocity vector\nC\nC CALL VSCL ( ANGLE/H, AXIS, ANGVEL )\nC\nC\nC$ Restrictions\nC\nC 1) If the input matrix is not a rotation matrix but is close\nC enough to pass the tests this routine performs on it, no error\nC will be signaled, but the results may have poor accuracy.\nC\nC 2) The input matrix is taken to be an object that acts on\nC (rotates) vectors---it is not regarded as a coordinate\nC transformation. To find the axis and angle of a coordinate\nC transformation, input the transpose of that matrix to this\nC routine.\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC W.L. Taber (JPL)\nC F.S. Turner (JPL)\nC N.J. Bachman (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 2.1.2, 02-JAN-2008 (EDW)\nC\nC Minor edit to the ANGLE declaration strictly\nC identifying the constant as a double.\nC\nC From: \nC\nC ANGLE = 2.0 * DATAN2( VNORM(Q(1)), Q(0) )\nC\nC To:\nC\nC ANGLE = 2.D0 * DATAN2( VNORM(Q(1)), Q(0) )\nC\nC- SPICELIB Version 2.1.1, 05-JAN-2005 (NJB)\nC\nC Minor edits and formatting changes were made.\nC\nC- SPICELIB Version 2.1.0, 30-MAY-2002 (FST)\nC\nC This routine now participates in error handling properly.\nC\nC- SPICELIB Version 2.0.0, 19-SEP-1999 (WLT)\nC\nC The routine was re-written so as to avoid the numerical\nC instabilities present in the previous implementation for\nC rotations very near zero or 180 degrees.\nC\nC- SPICELIB Version 1.1.0, 29-FEB-1996 (KRG)\nC\nC The declaration for the SPICELIB function PI is now\nC preceded by an EXTERNAL statement declaring PI to be an\nC external function. This removes a conflict with any\nC compilers that have a PI intrinsic function.\nC\nC- SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)\nC\nC Comment section for permuted index source lines was added\nC following the header.\nC\nC- SPICELIB Version 1.0.0, 31-JAN-1990 (WLT)\nC\nC-&\n \nC$ Index_Entries\nC\nC axis and angle of a rotation matrix\nC\nC-&\n \n \nC$ Revisions\nC\nC- SPICELIB Version 2.1.0, 30-MAY-2002 (FST)\nC\nC Calls to CHKIN and CHKOUT in the standard SPICE error\nC handling style were added. Versions prior to 2.0.0\nC were error free, however the call to M2Q introduced in\nC version 2.0.0 signals an error if the input matrix is\nC not sufficiently close to a rotation.\nC\nC Additionally, FAILED is now checked after the call to\nC M2Q. This prevents garbage from being placed into the\nC output arguments.\nC\nC- SPICELIB Version 2.0.0, 21-SEP-1999 (WLT)\nC\nC The routine was re-written so as to avoid the numerical\nC instabilities present in the previous implementation for\nC rotations very near zero or 180 degrees.\nC\nC- SPICELIB Version 1.1.0, 29-FEB-1996 (KRG)\nC\nC The declaration for the SPICELIB function PI is now\nC preceded by an EXTERNAL statement declaring PI to be an\nC external function. This removes a conflict with any\nC compilers that have a PI intrinsic function.\nC\nC- SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)\nC\nC Comment section for permuted index source lines was added\nC following the header.\nC\nC- SPICELIB Version 1.0.0, 31-JAN-1990 (WLT)\nC\nC- Beta Version 1.1.0, 3-JAN-1989 (WLT)\nC\nC Even though the routine stipulates that the input matrix\nC should be a rotation matrix, it might not be. As a result\nC we could have negative numbers showing up where we need\nC to take square roots. This fix simply bounds these values\nC so that Fortran intrinsics always get reasonable input values.\nC\nC Add and example to the header.\nC-&\n \nC\nC SPICELIB functions\nC\n DOUBLE PRECISION VNORM\n LOGICAL FAILED\n LOGICAL RETURN\n LOGICAL VZERO\n \n EXTERNAL PI\n DOUBLE PRECISION PI\n \nC\nC Local Variables\nC\n DOUBLE PRECISION Q ( 0: 3 )\n \nC\nC Standard SPICE error handling.\nC\n IF ( RETURN() ) THEN\n RETURN\n ELSE\n CALL CHKIN ( 'RAXISA' )\n END IF\n \nC\nC Construct the quaternion corresponding to the input rotation\nC matrix\nC\n CALL M2Q ( MATRIX, Q )\n \nC\nC Check FAILED and return if an error has occurred.\nC\n IF ( FAILED() ) THEN\n CALL CHKOUT ( 'RAXISA' )\n RETURN\n END IF\n \nC\nC The quaternion we've just constructed is of the form:\nC\nC cos(ANGLE/2) + sin(ANGLE/2) * AXIS\nC\nC We take a few precautions to handle the case of an identity\nC rotation.\nC\n IF ( VZERO(Q(1)) ) THEN\n \n ANGLE = 0\n AXIS(1) = 0.0D0\n AXIS(2) = 0.0D0\n AXIS(3) = 1.0D0\n \n ELSE IF ( Q(0) .EQ. 0.0D0 ) THEN\n \n ANGLE = PI()\n AXIS(1) = Q(1)\n AXIS(2) = Q(2)\n AXIS(3) = Q(3)\n \n ELSE\n \n CALL VHAT ( Q(1), AXIS )\n ANGLE = 2.D0 * DATAN2 ( VNORM(Q(1)), Q(0) )\n \n END IF\n \n CALL CHKOUT ( 'RAXISA' )\n RETURN\n \n END\n", "meta": {"hexsha": "384a8f10feee243ede2d2f32bc9f5857235d9bf5", "size": 10864, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/raxisa.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/raxisa.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/raxisa.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": 30.3463687151, "max_line_length": 71, "alphanum_fraction": 0.6413843888, "num_tokens": 3082, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178994073576, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6937150085825128}} {"text": " ATAN2(y,x) ! Arctangent(y/x), ''-pi < result <= +pi''\n SINH(x) ! Hyperbolic sine\n COSH(x) ! Hyperbolic cosine\n TANH(x) ! Hyperbolic tangent\n", "meta": {"hexsha": "e7253702ce917ff9fd04f4bf13ffa9e67d1cf124", "size": 150, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Trigonometric-functions/Fortran/trigonometric-functions-2.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Trigonometric-functions/Fortran/trigonometric-functions-2.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Trigonometric-functions/Fortran/trigonometric-functions-2.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 30.0, "max_line_length": 54, "alphanum_fraction": 0.6066666667, "num_tokens": 56, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178895092415, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6937150059152739}} {"text": "FUNCTION q_lngm(x) RESULT(b)\r\n\r\n! Extended arithmetic calculation of the logarithm of the gamma\r\n! function (N.B. gamma(x) = (x-1)! in factorial notation):\r\n! b = ln (gamma (x))\r\n! where all quantities are in quadruple-precision.\r\n! The result (b) may occupy the same location as the input value (x).\r\n! x must not equal a negative integer; in this case a warning is given\r\n! and no result is calculated.\r\n\r\n! Algorithm: The true Stirling's approximation (not the version derived by\r\n! de Moivre which is usually quoted in textbooks) is used for x >= 16.\r\n! For smaller arguments, a Lanczos-type approximation is used.\r\n\r\n! Programmer: Alan Miller\r\n!\r\n! Latest Fortran 77 revision - 11 May 1988\r\n! Fortran 90 version - 21 August 1997\r\n\r\nUSE quadruple_precision\r\nIMPLICIT NONE\r\nTYPE (quad), INTENT(IN) :: x\r\nTYPE (quad) :: b\r\n\r\n! Local variables\r\n\r\nLOGICAL :: large\r\nINTEGER :: i, j\r\nTYPE (quad) :: z, total, temp, zz, term\r\nREAL (dp) :: zero = 0._dp, half = 0.5_dp, one = 1.0_dp\r\nINTEGER, PARAMETER :: g = 14\r\n\r\n! Table of values of\r\n! a(2j) = B(2j).[2**(2j-1) - 1]/[2j.(2j-1).2**(2j-1)]\r\n! where the B(2j)'s are the Bernouilli numbers.\r\n! Stirling's approximation for log(gamma(x)) is then\r\n! log(gamma(x)) = 0.5*log(2.pi) + z.log(z) - z - sum[a(2j)/z**(2j-1)]\r\n! where z = x - 0.5.\r\n\r\nTYPE (quad), PARAMETER :: st_coeff(16) = (/ &\r\n quad( 0.4166666666666667D-01, -.4625929269271486D-17), &\r\n quad( -.2430555555555556D-02, 0.4722302795714642D-18), &\r\n quad( 0.7688492063492064D-03, -.8742455613057720D-19), &\r\n quad( -.5905877976190476D-03, -.3820521941139396D-19), &\r\n quad( 0.8401067971380472D-03, -.2482348408384320D-19), &\r\n quad( -.1916590625086719D-02, 0.2283600073631585D-18), &\r\n quad( 0.6409473908253206D-02, -.7561615151693776D-18), &\r\n quad( -.2954975178039152D-01, 0.2751974392739155D-17), &\r\n quad( 0.1796430017910384D+00, 0.5451863036096252D-16), &\r\n quad( -.1392429561052216D+01, 0.1922261747261675D-16), &\r\n quad( 0.1340285765318479D+02, -.1330122271048497D-14), &\r\n quad( -.1568482659282295D+03, 0.5486595470093716D-13), &\r\n quad( 0.2193103267973761D+04, -.1576457483073076D-12), &\r\n quad( -.3610877098469368D+05, -.1128718158624283D-11), &\r\n quad( 0.6914722675633456D+06, -.9528010535925612D-11), &\r\n quad( -.1523822153940742D+08, 0.4711160925202246D-08) /)\r\n\r\n! Lanczos-type coeffs. for g = 14\r\n\r\nTYPE (quad), PARAMETER :: a(16) = (/ &\r\n quad( 0.1000000000000000D+01, 0.4846757479531194D-21), &\r\n quad( 0.1069184011592089D+07, -.5763228334420908D-09), &\r\n quad( -.4731034435392098D+07, 0.1831263028328363D-09), &\r\n quad( 0.8831027007071320D+07, -.3562876555263793D-09), &\r\n quad( -.9057605936125744D+07, -.8123034251454294D-09), &\r\n quad( 0.5575099541767454D+07, 0.4521232468551490D-09), &\r\n quad( -.2113664276594438D+07, 0.2261448706472902D-09), &\r\n quad( 0.4882973818694724D+06, -.2584262485630417D-10), &\r\n quad( -.6580271859490060D+05, 0.6829382319982582D-11), &\r\n quad( 0.4754359892166024D+04, -.6321699947095538D-12), &\r\n quad( -.1588514130362740D+03, 0.1630647068074753D-13), &\r\n quad( 0.1878850329497677D+01, -.5694435459399838D-16), &\r\n quad( -.4589872822043718D-02, 0.3894567587921014D-18), &\r\n quad( 0.5931363621107230D-06, -.1388883823219028D-21), &\r\n quad( 0.1024789274886151D-11, 0.2637600537816092D-27), &\r\n quad( -.3355721053959592D-12, 0.4593372363497046D-29) /)\r\n\r\n! Check negative arguments.\r\n\r\nIF (x%hi <= zero) THEN\r\n WRITE(*, *)' *** Negative argument in q_lngm ***'\r\n RETURN\r\nEND IF\r\n\r\nIF (x%hi == one .OR. x%hi == 2.d0) THEN\r\n IF (x%lo == zero) THEN\r\n b%hi = zero\r\n b%lo = zero\r\n RETURN\r\n END IF\r\nEND IF\r\n\r\nIF (x%hi >= 16._dp) GO TO 20\r\n\r\n! Fit a Lanczos-type approximation if x%hi < 16.\r\n! i.e. ln(gamma(x)) = lnsqrt(2.pi) + (x-.5)ln(x+g-.5) - (x+g-.5) + ln(A(x))\r\n! where A(x) = a0 + a1/x + a2/(x+1) + ... + ak/(x+g).\r\n! g = 14 here to achieve about 29 significant digits accuracy, except in the\r\n! vicinity of 1 and 2, where ln(gamma) = 0, where the absolute accuracy is\r\n! about 30 decimal digits.\r\n\r\nz = a(1)\r\nDO i = 2, g + 2\r\n z = z + a(i) / (x + DBLE(i-2))\r\nEND DO\r\ntemp = x - half\r\nzz = temp + DBLE(g)\r\nb = lnsqrt2pi + temp*log(zz) - zz + log(z)\r\n\r\nRETURN\r\n\r\n! Stirling's approximation.\r\n\r\n20 total = lnsqrt2pi\r\nz = x - half\r\ntotal = total + z * log(z) - z\r\nzz = z * z\r\nterm = z\r\nlarge = .true.\r\nDO j = 1, 16\r\n IF (large) THEN\r\n temp = st_coeff(j) / term\r\n total = total - temp\r\n term = term * zz\r\n IF (ABS(temp%hi) < ABS(total%lo)) large = .false.\r\n ELSE\r\n temp%lo = st_coeff(j)%hi / term%hi\r\n total%lo = total%lo - temp%lo\r\n IF (ABS(temp%lo) < 1.d-30) CYCLE\r\n term%hi = term%hi * zz%hi\r\n END IF\r\nEND DO\r\n\r\n! The smallest bit of sum%hi & the largest bit of sum%lo may be out\r\n! of alignment, so add zero to re-align.\r\n\r\nb = total + zero\r\n\r\nRETURN\r\nEND FUNCTION q_lngm\r\n\r\n\r\n\r\nPROGRAM test_q_lngm\r\n! Test the quadruple-precision lngamma function using\r\n! lngamma(m+x) - lngamma(n+x) = log[ (m+x-1).(m+x-2) .. (n+x) ]\r\n\r\nUSE quadruple_precision\r\nIMPLICIT NONE\r\n\r\nINTEGER :: m, n, i\r\nTYPE (quad) :: x, lngmm, lngmn, diff, log_prod, error, temp\r\nTYPE (quad), PARAMETER :: qone = quad( 1.0_dp, 0.0_dp)\r\n\r\nINTERFACE\r\n FUNCTION q_lngm(x) RESULT(b)\r\n USE quadruple_precision\r\n IMPLICIT NONE\r\n TYPE (quad), INTENT(IN) :: x\r\n TYPE (quad) :: b\r\n END FUNCTION q_lngm\r\nEND INTERFACE\r\n\r\nDO\r\n WRITE(*, '(a)', ADVANCE='NO') ' Enter 2 different positive integers: '\r\n READ(*, *) m, n\r\n IF (m == n) THEN\r\n WRITE(*, *) 'The integers must be different - try again!'\r\n CYCLE\r\n END IF\r\n IF (n > m) THEN\r\n i = m\r\n m = n\r\n n = i\r\n END IF\r\n CALL RANDOM_NUMBER(x%hi)\r\n x%lo = 0._dp\r\n lngmm = q_lngm(x+DBLE(m))\r\n WRITE(*, '(\" lngamma(\", f20.15, \") = \", f22.16)') x%hi+DBLE(m), lngmm%hi\r\n lngmn = q_lngm(x+DBLE(n))\r\n WRITE(*, '(\" lngamma(\", f20.15, \") = \", f22.16)') x%hi+DBLE(n), lngmn%hi\r\n diff = lngmm - lngmn\r\n temp = x + DBLE(m-1)\r\n log_prod = log(temp)\r\n DO i = 1, m-n-1\r\n temp = temp - qone\r\n log_prod = log_prod + log(temp)\r\n END DO\r\n error = diff - log_prod\r\n WRITE(*, '(\" Diff =\", f20.15, \" log_prod =\", f20.15, \" Error =\", g11.3)') &\r\n diff%hi, log_prod%hi, error%hi\r\nEND DO\r\n\r\nSTOP\r\nEND PROGRAM test_q_lngm\r\n", "meta": {"hexsha": "c95749dc0b119f2bc1d8de9cd7b4f667716212ec", "size": 6392, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/q_lngam.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/q_lngam.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/q_lngam.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": 32.612244898, "max_line_length": 81, "alphanum_fraction": 0.6115456821, "num_tokens": 2475, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308147331957, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6936959250724751}} {"text": "subroutine invert(a,nmax,ndm)\n\n!-----------------------------------------------------------------------\n!\n! This routine performs the inversion of a ndm*ndm square matrix \n! or just part of it (nmax*nmax)\n!\n!-----------------------------------------------------------------------\n use typre\n implicit none\n integer(ip), intent(in) :: ndm,nmax\n real(rp), intent(inout) :: a(ndm,ndm)\n real(rp) :: d\n integer(ip) :: n,j,i\n\n do n = 1,nmax\n d = a(n,n)\n do j = 1,nmax\n a(n,j) = -a(n,j)/d\n end do\n do i = 1,nmax\n if(n/=i) then\n do j = 1,nmax\n if(n/=j) a(i,j) = a(i,j) +a(i,n)*a(n,j)\n end do\n end if\n a(i,n) = a(i,n)/d\n end do\n a(n,n) = 1.0_rp/d\n end do\n \nend subroutine invert\n", "meta": {"hexsha": "b37dcd5bfaf991da92d7715095eeaf978b425bb6", "size": 808, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Sources/mathru/invert.f90", "max_stars_repo_name": "ciaid-colombia/InsFEM", "max_stars_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-24T08:19:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-24T08:19:54.000Z", "max_issues_repo_path": "Sources/mathru/invert.f90", "max_issues_repo_name": "ciaid-colombia/InsFEM", "max_issues_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Sources/mathru/invert.f90", "max_forks_repo_name": "ciaid-colombia/InsFEM", "max_forks_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.4848484848, "max_line_length": 72, "alphanum_fraction": 0.3861386139, "num_tokens": 242, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.933430812881347, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6936959236962403}} {"text": "module m_poisson_solver\n use mpifft\n use m_constants, only: PI\n use m_get_default, only: get_default\n implicit none\n\n !> 3d poisson equation solver.\n !>\n !> Poisson equation:\n !> \u2202^2p/\u2202^2 + \u2202^2p/\u2202y^2 + \u2202^2p/\u2202z^2 = f(x, y, z)\n type :: t_PoissonSolver3d\n double precision, private :: dx\n double precision, private :: dy\n double precision, private :: dz\n class(t_MPI_FFTExecutor3d), allocatable, private :: fft3d\n double precision, allocatable, private :: modified_wave_number(:, :, :)\n double precision, private :: boundary_condition_terms(2, 3)\n contains\n procedure :: solve => poissonSolver3d_solve\n end type\n\n private\n public t_PoissonSolver3d\n public new_PoissonSolver3d\n\ncontains\n\n function new_PoissonSolver3d(local_block, global_block, fft3d, dx, dy, dz, boundary_values) result(obj)\n type(t_Block), intent(in) :: local_block\n type(t_Block), intent(in) :: global_block\n class(t_MPI_FFTExecutor3d), intent(in) :: fft3d\n double precision, intent(in) :: dx\n double precision, intent(in), optional :: dy\n double precision, intent(in), optional :: dz\n double precision, intent(in), optional :: boundary_values(2, 3)\n type(t_PoissonSolver3d) :: obj\n\n integer :: start(3), end(3)\n integer :: kx, ky, kz\n\n obj%fft3d = fft3d\n obj%dx = dx\n obj%dy = get_default(dy, dx)\n obj%dz = get_default(dz, dx)\n\n if (present(boundary_values)) then\n obj%boundary_condition_terms(:, 1) = &\n calc_boundary_term(boundary_values(:, 1), obj%fft3d%boundary_types(1), obj%dx)\n obj%boundary_condition_terms(:, 2) = &\n calc_boundary_term(boundary_values(:, 2), obj%fft3d%boundary_types(2), obj%dy)\n obj%boundary_condition_terms(:, 3) = &\n calc_boundary_term(boundary_values(:, 3), obj%fft3d%boundary_types(3), obj%dz)\n else\n obj%boundary_condition_terms(:, :) = 0.0d0\n end if\n\n allocate (obj%modified_wave_number(local_block%sizes(1), &\n local_block%sizes(2), &\n local_block%sizes(3)))\n\n start(:) = local_block%start(:) - global_block%start(:)\n end(:) = local_block%end(:) - global_block%start(:)\n do concurrent(kz=start(3):end(3), ky=start(2):end(2), kx=start(1):end(1))\n block\n double precision :: wx, wy, wz\n\n integer :: ix, iy, iz\n double precision :: wn\n\n wx = calc_wave_number(kx, fft3d%nx, fft3d%boundary_types(1))\n wy = calc_wave_number(ky, fft3d%ny, fft3d%boundary_types(2))\n wz = calc_wave_number(kz, fft3d%nz, fft3d%boundary_types(3))\n\n ix = kx + global_block%start(1) - local_block%start(1) + 1\n iy = ky + global_block%start(2) - local_block%start(2) + 1\n iz = kz + global_block%start(3) - local_block%start(3) + 1\n wn = wx/(obj%dx*obj%dx) + wy/(obj%dy*obj%dy) + wz/(obj%dz*obj%dz)\n\n obj%modified_wave_number(ix, iy, iz) = wn\n end block\n end do\n end function\n\n pure function calc_boundary_term(boundary_values, boundary_type, gridwidth) result(terms)\n double precision, intent(in) :: boundary_values(2)\n integer, intent(in) :: boundary_type\n double precision, intent(in) :: gridwidth\n double precision :: terms(2)\n\n select case (boundary_type)\n case (BoundaryType_Periodic)\n terms(:) = boundary_values(:)\n\n case (BoundaryType_Dirichlet)\n terms(:) = [-boundary_values(1)/(gridwidth*gridwidth), &\n -boundary_values(2)/(gridwidth*gridwidth)]\n\n case (BoundaryType_Neumann)\n terms(:) = [2.0d0*boundary_values(1)/gridwidth, &\n -2.0d0*boundary_values(2)/gridwidth]\n\n case (BoundaryType_Dirichlet_Neumann)\n terms(:) = [-boundary_values(1)/(gridwidth*gridwidth), &\n -2.0d0*boundary_values(2)/gridwidth]\n\n case (BoundaryType_Neumann_Dirichlet)\n terms(:) = [-boundary_values(1)/(gridwidth*gridwidth), &\n -2.0d0*boundary_values(2)/gridwidth]\n end select\n end function\n\n pure function calc_wave_number(k, n, boundary_type) result(wn)\n integer, intent(in) :: k\n integer, intent(in) :: n\n integer, intent(in) :: boundary_type\n double precision :: wn\n\n select case (boundary_type)\n case (BoundaryType_Periodic)\n if (k <= int(n/2)) then\n wn = 2.0d0*sin(PI*k/dble(n))\n else\n wn = 2.0d0*sin(PI*(k - int(n/2))/dble(n))\n end if\n\n case (BoundaryType_Dirichlet)\n wn = 2.0d0*(cos(PI*(k + 1)/dble(n + 1)) - 1.0d0)\n\n case (BoundaryType_Neumann)\n wn = 2.0d0*(cos(PI*k/dble(n)) - 1.0d0)\n\n case (BoundaryType_Dirichlet_Neumann)\n wn = 2.0d0*(cos(PI*(k + 0.5d0)/dble(n + 1)) - 1.0d0)\n\n case (BoundaryType_Neumann_Dirichlet)\n wn = 2.0d0*(cos(PI*(k + 0.5d0)/dble(n + 1)) - 1.0d0)\n\n end select\n end function\n\n subroutine poissonSolver3d_solve(self, f, p)\n class(t_PoissonSolver3d), intent(inout) :: self\n double precision, intent(in) :: f(:, :, :)\n double precision, intent(out) :: p(:, :, :)\n\n double precision, allocatable :: ftmp(:, :, :)\n double precision, allocatable :: fk(:, :, :)\n double precision, allocatable :: pk(:, :, :)\n\n allocate (ftmp, source=f)\n allocate (fk, mold=f)\n allocate (pk, mold=p)\n\n ftmp(1, :, :) = ftmp(1, :, :) + self%boundary_condition_terms(1, 1)\n ftmp(:, 1, :) = ftmp(:, 1, :) + self%boundary_condition_terms(1, 2)\n ftmp(:, :, 1) = ftmp(:, :, 1) + self%boundary_condition_terms(1, 3)\n\n ftmp(self%fft3d%nx, :, :) = ftmp(self%fft3d%nx, :, :) + self%boundary_condition_terms(2, 1)\n ftmp(:, self%fft3d%ny, :) = ftmp(:, self%fft3d%ny, :) + self%boundary_condition_terms(2, 2)\n ftmp(:, :, self%fft3d%nz) = ftmp(:, :, self%fft3d%nz) + self%boundary_condition_terms(2, 3)\n\n call self%fft3d%forward(f(:, :, :), fk(:, :, :))\n\n pk(:, :, :) = f(:, :, :)/self%modified_wave_number(:, :, :)\n\n call self%fft3d%backward(pk(:, :, :), p(:, :, :))\n end subroutine\n\nend module\n", "meta": {"hexsha": "c9ea0c5f91357451313479b05dfa81a069d6b3d8", "size": 6507, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/poisson/poisson_solver.f90", "max_stars_repo_name": "Nkzono99/mpifft-solver", "max_stars_repo_head_hexsha": "e1ccf0595718145caf8e57bf1d0f6bf5a17dfd9b", "max_stars_repo_licenses": ["MIT"], "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/poisson/poisson_solver.f90", "max_issues_repo_name": "Nkzono99/mpifft-solver", "max_issues_repo_head_hexsha": "e1ccf0595718145caf8e57bf1d0f6bf5a17dfd9b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-01-20T21:56:49.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-08T00:52:53.000Z", "max_forks_repo_path": "src/poisson/poisson_solver.f90", "max_forks_repo_name": "Nkzono99/mpifft-solver", "max_forks_repo_head_hexsha": "e1ccf0595718145caf8e57bf1d0f6bf5a17dfd9b", "max_forks_repo_licenses": ["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.2764705882, "max_line_length": 107, "alphanum_fraction": 0.5666205625, "num_tokens": 1880, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308128813471, "lm_q2_score": 0.74316801430083, "lm_q1q2_score": 0.6936959236962403}} {"text": " real*8 function aunif (x1) result (unif)\r\n\r\n!! ~ ~ ~ PURPOSE ~ ~ ~\r\n!! This function generates random numbers ranging from 0.0 to 1.0.\r\n!! In the process of calculating the random number, the seed (x1) is \r\n!! set to a new value.\r\n!! This function implements the prime-modulus generator\r\n!! xi = 16807 xi Mod(2**(31) - 1)\r\n!! using code which ensures that no intermediate result uses more than\r\n!! 31 bits\r\n!! the theory behind the code is summarized in\r\n!! Bratley, P., B.L. Fox and L.E. Schrage. 1983. A Guide to Simulation.\r\n!! Springer-Verlag, New York. (pages 199-202)\r\n\r\n!! ~ ~ ~ INCOMING VARIABLES ~ ~ ~\r\n!! name |units |definition\r\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ \r\n!! x1 |none |random number generator seed (integer)\r\n!! |where 0 < x1 < 2147483647\r\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ \r\n\r\n!! ~ ~ ~ OUTGOING VARIABLES ~ ~ ~\r\n!! name |units |definition\r\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ \r\n!! unif |none |random number between 0.0 and 1.0\r\n!! x1 |none |random number generator seed (integer)\r\n!! |set to new value where 0 < x1 < 2147483647\r\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ \r\n\r\n!! ~ ~ ~ LOCAL DEFINITIONS ~ ~ ~\r\n!! name |units |definition\r\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ \r\n!! x2 |none |variable to hold calculation results \r\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ \r\n\r\n!! ~ ~ ~ ~ ~ ~ END SPECIFICATIONS ~ ~ ~ ~ ~ ~\r\n\r\n integer, intent (in out) :: x1\r\n integer :: x2\r\n\r\n x2 = 0\r\n unif = 0.\r\n\r\n x2 = x1 / 127773\r\n x1 = 16807 * (x1-x2*127773) - x2 * 2836\r\n if (x1 < 0) x1 = x1 + 2147483647\r\n unif = x1 * 4.656612875d-10\r\n\r\n return\r\n end", "meta": {"hexsha": "7f1849af22c70ea3b6a2d0bc7de5d6c2877ae427", "size": 2081, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "swat_cli/rev670_source/aunif.f", "max_stars_repo_name": "GISWAT/erosion-sediment", "max_stars_repo_head_hexsha": "6ab469eba99cba8e5c365cd4d18cba2e8781ccf6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-06-05T06:33:14.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-05T06:33:14.000Z", "max_issues_repo_path": "swat_cli/rev670_source/aunif.f", "max_issues_repo_name": "GISWAT/erosion-sediment", "max_issues_repo_head_hexsha": "6ab469eba99cba8e5c365cd4d18cba2e8781ccf6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "swat_cli/rev670_source/aunif.f", "max_forks_repo_name": "GISWAT/erosion-sediment", "max_forks_repo_head_hexsha": "6ab469eba99cba8e5c365cd4d18cba2e8781ccf6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.62, "max_line_length": 77, "alphanum_fraction": 0.3993272465, "num_tokens": 702, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308184368929, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6936959225152641}} {"text": "FUNCTION GET_TUNIV(z)\n\n !compute age of Universe in Gyr at redshift z\n !assumes flat universe w/ only matter and lambda\n !assumes om0,ol0,H0 set in sps_vars.f90\n \n USE sps_vars\n IMPLICIT NONE\n INTEGER :: i\n INTEGER, PARAMETER :: ii=10000\n REAL(SP), INTENT(in) :: z\n REAL(SP) :: get_tuniv, thub\n REAL(SP), DIMENSION(ii) :: lnstig, hub\n\n !---------------------------------------------------------------!\n !---------------------------------------------------------------!\n\n get_tuniv = 0.0\n\n !Hubble time in Gyr\n thub = 0.978E3 / H0\n\n DO i=1,ii\n lnstig(i) = REAL(i)/ii*(LOG(1E4)-LOG(1+z))+LOG(1+z)\n ENDDO\n \n hub = SQRT( om0*EXP(lnstig)**3 + ol0 )\n\n DO i=1,ii-1\n get_tuniv = get_tuniv + 0.5*(1/hub(i)+1/hub(i+1))\n ENDDO\n get_tuniv = get_tuniv * thub * (lnstig(2)-lnstig(1))\n\n\nEND FUNCTION GET_TUNIV\n", "meta": {"hexsha": "357a0c5c1af0c0a049769d7050e2a2aa84faccd7", "size": 826, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/get_tuniv.f90", "max_stars_repo_name": "christopherlovell/fsps", "max_stars_repo_head_hexsha": "1c09a47d7b0fb15a7f245ee3e9b2a7c54122ffdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 55, "max_stars_repo_stars_event_min_datetime": "2015-04-17T18:36:36.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-15T01:47:28.000Z", "max_issues_repo_path": "src/get_tuniv.f90", "max_issues_repo_name": "christopherlovell/fsps", "max_issues_repo_head_hexsha": "1c09a47d7b0fb15a7f245ee3e9b2a7c54122ffdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 27, "max_issues_repo_issues_event_min_datetime": "2015-11-04T03:19:44.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-15T22:03:19.000Z", "max_forks_repo_path": "src/get_tuniv.f90", "max_forks_repo_name": "christopherlovell/fsps", "max_forks_repo_head_hexsha": "1c09a47d7b0fb15a7f245ee3e9b2a7c54122ffdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 43, "max_forks_repo_forks_event_min_datetime": "2015-04-29T09:24:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T19:31:46.000Z", "avg_line_length": 22.9444444444, "max_line_length": 67, "alphanum_fraction": 0.5314769976, "num_tokens": 298, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308184368928, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.693695922515264}} {"text": "! ------------------------------------------------------ !\n! filtro compatto 3x5 !\n! F. Califano, Marzo 2001 !\n! ------------------------------------------------------ !\n! A (f_i-1 + f_i+1) + f_i = a_filt f_i + !\n! b_filt (f_i-2 + f_i+2) + c_filt (f_i-1 + f_i+1) !\n! ------------------------------------------------------ !\n\n!**************************************************\n! MPI PARALLEL VERSION: VALENTINI-FAGANELLO 2009\n!**************************************************\n\n subroutine filtro_open_x(QW)\n\nuse box_mod\nuse parameter_mod\nuse filtro_open_mod\n\nIMPLICIT NONE\n\n integer :: i\n REAL(dp), dimension (nx) :: QW, TW\n\n! Soluzione del sistema lineare tridiagonale fattorizzato LU\n! Differenze finite compatte 3x5\n\n TW = QW\n\n! Filtro IV ordine, Lele 1992, pag. 40, C.2.4\n\n !! do i = 3, nx2\n !! QW(i) = a_filt * TW(i) + b_filt * (TW(i+1) + TW(i-1)) &\n !! + c_filt * (TW(i+2) + TW(i-2))\n !! enddo\n\n! Filtro VI ordine, Lele 1992, pag. 40, C.2.5\n\n do i = 4, nx3\n QW(i) = a_filt * TW(i) + b_filt * (TW(i+1) + TW(i-1)) &\n + c_filt * (TW(i+2) + TW(i-2)) + d_filt * (TW(i+3) + TW(i-3))\n enddo\n\n! Boundary conditions\n\n !! QW(1) = TW(1)\n !! QW(2) = TW(2)\n !! QW(nx) = TW(nx)\n !! QW(nx1) = TW(nx1)\n\n! Boundary conditions VI ordine\n\n !! QW(3) = TW(3)\n !! QW(nx2) = TW(nx2)\n\n! Boundary conditions VI ordine, Lele pag. 41, C.2.11.a,b,c\n\n QW(1) = a11_filt * TW(1) + a12_filt * TW(2) + a13_filt * TW(3) &\n + a14_filt * TW(4) + a15_filt * TW(5)\n QW(2) = a21_filt * TW(1) + a22_filt * TW(2) + a23_filt * TW(3) &\n + a24_filt * TW(4) + a25_filt * TW(5)\n QW(3) = a31_filt * TW(1) + a32_filt * TW(2) + a33_filt * TW(3) &\n + a34_filt * TW(4) + a35_filt * TW(5)\n\n QW(nx ) = a11_filt * TW(nx ) + a12_filt * TW(nx1) + a13_filt * TW(nx2) &\n + a14_filt * TW(nx3) + a15_filt * TW(nx4)\n QW(nx1) = a21_filt * TW(nx ) + a22_filt * TW(nx1) + a23_filt * TW(nx2) &\n + a24_filt * TW(nx3) + a25_filt * TW(nx4)\n QW(nx2) = a31_filt * TW(nx ) + a32_filt * TW(nx1) + a33_filt * TW(nx2) &\n + a34_filt * TW(nx3) + a35_filt * TW(nx4)\n\n\n! Boundary conditions IV ordine, Lele 1992, pag. 40, C.2.11a,b,c\n\n! QW(1) = a11_filt * TW(1) + a12_filt * TW(2) + a13_filt * TW(3) &\n! + a14_filt * TW(4) + a15_filt * TW(5)\n!\n! QW(2) = a21_filt * TW(1) + a22_filt * TW(2) + a23_filt * TW(3) &\n! + a24_filt * TW(4) + a25_filt * TW(5)\n!\n! QW(nx1) = a21_filt * TW(nx) + a22_filt * TW(nx1) &\n! + a23_filt * TW(nx2) + a24_filt * TW(nx-3) + a25_filt * TW(nx-4)\n!\n! QW(nx) = a11_filt * TW(nx) + a12_filt * TW(nx1) &\n! + a13_filt * TW(nx2) + a14_filt * TW(nx-3) + a15_filt * TW(nx-4)\n\n\n CALL DGTTRS(TARNS,nx,LRHS,filt_m,filt_d,filt_p,filt_2,ipv_f,QW,ldb,INFO)\n\n if (info > 0 .or. info < 0) then\n write(*,*) 'Problemi soluzione, info:', info\n stop\n endif\n\n end subroutine\n", "meta": {"hexsha": "819c1fa8ed40199b2e740790acc9164983affdf0", "size": 3101, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "filtro_open_x.f90", "max_stars_repo_name": "sscerr/eTF", "max_stars_repo_head_hexsha": "31dea18c7b24b3ebbb6bdfea98467ffbf79f0852", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-02T04:11:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-02T04:11:49.000Z", "max_issues_repo_path": "filtro_open_x.f90", "max_issues_repo_name": "sscerr/eTF", "max_issues_repo_head_hexsha": "31dea18c7b24b3ebbb6bdfea98467ffbf79f0852", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "filtro_open_x.f90", "max_forks_repo_name": "sscerr/eTF", "max_forks_repo_head_hexsha": "31dea18c7b24b3ebbb6bdfea98467ffbf79f0852", "max_forks_repo_licenses": ["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.6421052632, "max_line_length": 77, "alphanum_fraction": 0.4627539503, "num_tokens": 1147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.933430805473952, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6936959128816211}} {"text": "module maptran\n\n use assert, only: wp,isclose\n implicit none\n private\n\n type,public :: Ellipsoid\n real(wp) :: SemimajorAxis, Flattening, SemiminorAxis \n end type\n\n real(wp), parameter :: pi = 4._wp * atan(1.0_wp)\n \n type(Ellipsoid), parameter, public :: wgs84Ellipsoid = &\n Ellipsoid(SemimajorAxis=6378137._wp, &\n SemiminorAxis=6378137._wp * (1._wp - 1._wp / 298.2572235630_wp), &\n Flattening = 1. / 298.2572235630_wp)\n\n public :: ecef2geodetic, geodetic2ecef, aer2enu, enu2aer, aer2ecef, ecef2aer, &\n enu2ecef, ecef2enu, aer2geodetic, geodetic2enu,&\n geodetic2aer,enu2geodetic,degrees,radians, anglesep\n\ncontains\n\n\nelemental subroutine ecef2geodetic(x, y, z, lat, lon, alt, spheroid, deg)\n\n! convert ECEF (meters) to geodetic coordintes\n\n! Algorithm is based on\n! http://www.astro.uni.torun.pl/~kb/Papers/geod/Geod-BG.htm\n! This algorithm provides a converging solution to the latitude equation\n! in terms of the parametric or reduced latitude form (v)\n! This algorithm provides a uniform solution over all latitudes as it does\n! not involve division by cos(phi) or sin(phi)\n\n real(wp), intent(in) :: x,y,z\n type(Ellipsoid), intent(in), optional :: spheroid\n logical, optional,value :: deg\n real(wp), intent(out) :: lat, lon, alt\n\n real(wp) :: ea, eb, rad, rho, c, vnew, v\n integer :: i\n type(Ellipsoid) :: ell\n\n ell = merge(spheroid, wgs84Ellipsoid, present(spheroid))\n\n if (.not.present(deg)) deg = .true.\n\n ea = ell%SemimajorAxis\n eb = ell%SemiminorAxis\n rad = hypot(x, y)\n! Constant required for Latitude equation\n rho = atan2(eb * z, ea * rad)\n! Constant required for latitude equation\n c = (ea**2 - eb**2) / hypot(ea * rad, eb * z)\n! Starter for the Newtons Iteration Method\n vnew = atan2(ea * z, eb * rad)\n! Initializing the parametric latitude\n v = 0._wp\n do i = 1,5\n v = vnew\n ! Newtons Method for computing iterations\n vnew = v - ((2 * sin(v - rho) - c * sin(2 * v)) / &\n (2 * (cos(v - rho) - c * cos(2 * v))))\n\n if (isclose(v,vnew)) exit\n enddo\n\n! Computing latitude from the root of the latitude equation\n lat = atan2(ea * tan(vnew), eb)\n! by inspection\n lon = atan2(y, x)\n\n alt = ((rad - ea * cos(vnew)) * cos(lat)) + &\n ((z - eb * sin(vnew)) * sin(lat))\n\n if (deg) then\n lat = degrees(lat)\n lon = degrees(lon)\n endif\n\nend subroutine ecef2geodetic\n\n\nelemental subroutine geodetic2ecef(lat,lon,alt, x,y,z, spheroid, deg)\n! geodetic2ecef convert from geodetic to ECEF coordiantes\n!\n! Inputs\n! ------\n! lat,lon, alt: ellipsoid geodetic coordinates of point(s) (degrees, degrees, meters)\n! spheroid: Ellipsoid parameter struct\n! deg: .true. degrees\n!\n! outputs\n! -------\n! x,y,z: ECEF coordinates of test point(s) (meters)\n!\n real(wp), value :: lat,lon\n real(wp), intent(in) :: alt\n real(wp), intent(out) :: x,y,z\n type(Ellipsoid), intent(in), optional :: spheroid\n logical, optional, value :: deg\n\n real(wp) :: N\n type(Ellipsoid) :: ell \n \n ell = merge(spheroid, wgs84Ellipsoid, present(spheroid)) \n\n if (.not.present(deg)) deg=.true.\n\n if (deg) then\n lat = radians(lat)\n lon = radians(lon)\n endif\n\n! Radius of curvature of the prime vertical section\n N = radius_normal(lat, ell)\n! Compute cartesian (geocentric) coordinates given (curvilinear) geodetic coordinates.\n\n x = (N + alt) * cos(lat) * cos(lon)\n y = (N + alt) * cos(lat) * sin(lon)\n z = (N * (ell%SemiminorAxis / ell%SemimajorAxis)**2 + alt) * sin(lat)\n\nend subroutine geodetic2ecef\n\n\nelemental subroutine aer2geodetic(az, el, slantRange, lat0, lon0, alt0, lat1, lon1, alt1, spheroid, deg)\n! aer2geodetic convert azimuth, elevation, range of target from observer to geodetic coordiantes\n!\n! Inputs\n! ------\n! az, el, slantrange: look angles and distance to point under test (degrees, degrees, meters)\n! az: azimuth clockwise from local north\n! el: elevation angle above local horizon\n! lat0, lon0, alt0: ellipsoid geodetic coordinates of observer/reference (degrees, degrees, meters)\n! spheroid: Ellipsoid parameter struct\n! deg: .true.: degrees\n!\n! Outputs\n! -------\n! lat1,lon1,alt1: geodetic coordinates of test points (degrees,degrees,meters)\n \n real(wp), intent(in) :: az, el, slantRange, lat0, lon0, alt0 \n type(Ellipsoid), intent(in), optional :: spheroid\n logical, intent(in), optional :: deg\n real(wp), intent(out) :: lat1,lon1,alt1\n \n real(wp) :: x,y,z\n\n call aer2ecef(az, el, slantRange, lat0, lon0, alt0, x, y, z, spheroid, deg)\n \n call ecef2geodetic(x, y, z, lat1, lon1, alt1, spheroid, deg)\nend subroutine aer2geodetic\n\n\nelemental subroutine geodetic2aer(lat, lon, alt, lat0, lon0, alt0, az, el, slantRange, spheroid, deg)\n! geodetic2aer from an observer's perspective, convert target coordinates to azimuth, elevation, slant range.\n!\n! Inputs\n! ------\n! lat,lon, alt: ellipsoid geodetic coordinates of point under test (degrees, degrees, meters)\n! lat0, lon0, alt0: ellipsoid geodetic coordinates of observer/reference (degrees, degrees, meters)\n! spheroid: Ellipsoid parameter struct\n! angleUnit: string for angular units. Default 'd': degrees, otherwise Radians\n!\n! Outputs\n! -------\n! az, el, slantrange: look angles and distance to point under test (degrees, degrees, meters)\n! az: azimuth clockwise from local north\n! el: elevation angle above local horizon\n\n real(wp), intent(in) :: lat,lon,alt, lat0, lon0, alt0 \n type(Ellipsoid), intent(in), optional :: spheroid\n logical, intent(in), optional :: deg\n real(wp), intent(out) :: az, el, slantRange\n\n real(wp) :: east,north,up\n\n\n call geodetic2enu(lat, lon, alt, lat0, lon0, alt0, east,north,up, spheroid, deg)\n call enu2aer(east, north, up, az, el, slantRange, deg)\n \nend subroutine geodetic2aer\n\n\n\nelemental subroutine geodetic2enu(lat, lon, alt, lat0, lon0, alt0, east, north, up, spheroid, deg)\n! geodetic2enu convert from geodetic to ENU coordinates\n!\n! Inputs\n! ------\n! lat,lon, alt: ellipsoid geodetic coordinates of point under test (degrees, degrees, meters)\n! lat0, lon0, alt0: ellipsoid geodetic coordinates of observer/reference (degrees, degrees, meters)\n! spheroid: Ellipsoid parameter struct\n! angleUnit: string for angular units. Default 'd': degrees\n!\n! outputs\n! -------\n! e,n,u: East, North, Up coordinates of test points (meters)\n\n real(wp), intent(in) :: lat, lon, alt, lat0, lon0, alt0 \n type(Ellipsoid), intent(in), optional :: spheroid\n logical, intent(in), optional :: deg\n real(wp), intent(out) :: east, north, up\n \n real(wp) x1,y1,z1,x2,y2,z2, dx,dy,dz\n\n\n call geodetic2ecef(lat,lon,alt,x1,y1,z1,spheroid,deg)\n call geodetic2ecef(lat0,lon0,alt0,x2,y2,z2,spheroid,deg)\n \n dx = x1-x2;\n dy = y1-y2;\n dz = z1-z2;\n \n call ecef2enuv(dx, dy, dz, lat0, lon0, east, north, up, deg)\n \n\nend subroutine geodetic2enu\n\n\nelemental subroutine enu2geodetic(east, north, up, lat0, lon0, alt0, lat, lon, alt, spheroid, deg)\n! enu2geodetic convert from ENU to geodetic coordinates\n!\n! Inputs\n! ------\n! East, North, Up: coordinates of point(s) (meters)\n! lat0, lon0, alt0: ellipsoid geodetic coordinates of observer/reference (degrees, degrees, meters)\n! spheroid: Ellipsoid parameter struct\n! deg: .true. degrees\n!\n! outputs\n! -------\n! lat,lon,alt: geodetic coordinates of test points (degrees,degrees,meters)\n\n real(wp), intent(in) :: east, north, up, lat0, lon0, alt0 \n type(Ellipsoid), intent(in), optional :: spheroid\n logical, intent(in), optional :: deg\n real(wp), intent(out) :: lat, lon, alt\n \n real(wp) :: x,y,z\n\n call enu2ecef(east, north, up, lat0, lon0, alt0, x, y, z, spheroid, deg)\n call ecef2geodetic(x, y, z, lat, lon, alt, spheroid,deg)\n\nend subroutine enu2geodetic\n\n\n\nelemental subroutine aer2ecef(az, el, slantRange, lat0, lon0, alt0, x,y,z, spheroid, deg)\n! aer2ecef convert azimuth, elevation, range to target from observer to ECEF coordinates\n!\n! Inputs\n! ------\n! az, el, slantrange: look angles and distance to point under test (degrees, degrees, meters)\n! az: azimuth clockwise from local north\n! el: elevation angle above local horizon\n! lat0, lon0, alt0: ellipsoid geodetic coordinates of observer/reference (degrees, degrees, meters)\n! spheroid: Ellipsoid parameter struct\n! deg: .true. degrees\n!\n! outputs\n! -------\n! x,y,z: Earth Centered Earth Fixed (ECEF) coordinates of test point (meters)\n\n real(wp), intent(in) :: az,el, slantRange, lat0, lon0, alt0\n type(Ellipsoid), intent(in), optional :: spheroid\n logical, intent(in), optional :: deg\n real(wp), intent(out) :: x,y,z\n\n real(wp) :: x0,y0,z0, e,n,u,dx,dy,dz\n\n\n! Origin of the local system in geocentric coordinates.\n call geodetic2ecef(lat0, lon0, alt0,x0, y0, z0, spheroid,deg)\n! Convert Local Spherical AER to ENU\n call aer2enu(az, el, slantRange, e, n, u,deg)\n! Rotating ENU to ECEF\n call enu2uvw(e, n, u, lat0, lon0, dx, dy, dz,deg)\n! Origin + offset from origin equals position in ECEF\n x = x0 + dx\n y = y0 + dy\n z = z0 + dz\n\nend subroutine aer2ecef\n\n\nelemental subroutine ecef2aer(x, y, z, lat0, lon0, alt0, az, el, slantRange, spheroid, deg)\n! ecef2aer convert ECEF of target to azimuth, elevation, slant range from observer\n!\n! Inputs\n! ------\n! x,y,z: Earth Centered Earth Fixed (ECEF) coordinates of test point (meters)\n! lat0, lon0, alt0: ellipsoid geodetic coordinates of observer/reference (degrees, degrees, meters)\n! spheroid: Ellipsoid parameter struct\n! deg: .true.: degrees\n!\n! Outputs\n! -------\n! az, el, slantrange: look angles and distance to point under test (degrees, degrees, meters)\n! az: azimuth clockwise from local north\n! el: elevation angle above local horizon\n\n real(wp), intent(in) :: x,y,z, lat0, lon0, alt0\n type(Ellipsoid), intent(in), optional :: spheroid\n logical, intent(in), optional :: deg\n real(wp), intent(out) :: az,el, slantRange\n \n real(wp) :: east, north, up\n\n call ecef2enu(x, y, z, lat0, lon0, alt0, east, north, up, spheroid, deg)\n call enu2aer(east, north, up, az, el, slantRange, deg)\n \nend subroutine ecef2aer\n\n\nelemental subroutine aer2enu(az, el, slantRange, east, north, up, deg)\n! aer2enu convert azimuth, elevation, range to ENU coordinates\n!\n! Inputs\n! ------\n! az, el, slantrange: look angles and distance to point under test (degrees, degrees, meters)\n! az: azimuth clockwise from local north\n! el: elevation angle above local horizon\n! angleUnit: string for angular units. Default 'd': degrees\n!\n! Outputs\n! -------\n! e,n,u: East, North, Up coordinates of test points (meters)\n\n real(wp), value :: az,el\n real(wp), intent(in) :: slantRange\n logical, optional, value :: deg\n real(wp),intent(out) :: east, north,up\n\n real(wp) :: r\n\n if(.not.present(deg)) deg=.true.\n\n if (deg) then\n az = radians(az)\n el = radians(el)\n endif\n\n! Calculation of AER2ENU\n up = slantRange * sin(el)\n r = slantRange * cos(el)\n east = r * sin(az)\n north = r * cos(az)\n\nend subroutine aer2enu\n\n\nelemental subroutine enu2aer(east, north, up, az, elev, slantRange, deg)\n! enu2aer convert ENU to azimuth, elevation, slant range\n!\n! Inputs\n! ------\n! e,n,u: East, North, Up coordinates of test points (meters)\n! deg: .true. degrees\n!\n! outputs\n! -------\n! az, el, slantrange: look angles and distance to point under test (degrees, degrees, meters)\n! az: azimuth clockwise from local north\n! el: elevation angle above local horizon\n\n real(wp),intent(in) :: east,north,up\n logical, optional, value :: deg\n real(wp), intent(out) :: az, elev, slantRange\n \n real(wp) :: r\n \n if (.not.present(deg)) deg = .true.\n\n r = hypot(east, north)\n slantRange = hypot(r, up)\n ! radians\n elev = atan2(up, r)\n az = modulo(atan2(east, north), 2._wp * atan2(0._wp, -1._wp))\n\n if (deg) then\n elev = degrees(elev)\n az = degrees(az)\n endif\n \nend subroutine enu2aer\n\n\nelemental subroutine enu2ecef(e, n, u, lat0, lon0, alt0, x, y, z, spheroid, deg)\n! enu2ecef convert from ENU to ECEF coordiantes\n!\n! Inputs\n! ------\n! e,n,u: East, North, Up coordinates of test points (meters)\n! lat0, lon0, alt0: ellipsoid geodetic coordinates of observer/reference (degrees, degrees, meters)\n! spheroid: Ellipsoid parameter struct\n! angleUnit: string for angular units. Default 'd': degrees\n!\n! outputs\n! -------\n! x,y,z: Earth Centered Earth Fixed (ECEF) coordinates of test point (meters)\n real(wp), intent(in) :: e,n,u,lat0,lon0,alt0\n type(Ellipsoid), intent(in), optional :: spheroid\n logical, intent(in), optional :: deg\n real(wp), intent(out) :: x,y,z \n \n real(wp) :: x0,y0,z0,dx,dy,dz \n \n\n call geodetic2ecef(lat0, lon0, alt0, x0, y0, z0, spheroid, deg)\n call enu2uvw(e, n, u, lat0, lon0, dx, dy, dz, deg)\n \n x = x0 + dx\n y = y0 + dy\n z = z0 + dz\nend subroutine enu2ecef\n\n\n\nelemental subroutine ecef2enu(x, y, z, lat0, lon0, alt0, east, north, up, spheroid, deg)\n! ecef2enu convert ECEF to ENU\n!\n! Inputs\n! ------\n! x,y,z: Earth Centered Earth Fixed (ECEF) coordinates of test point (meters)\n! lat0, lon0, alt0: ellipsoid geodetic coordinates of observer/reference (degrees, degrees, meters)\n! spheroid: Ellipsoid parameter struct\n! angleUnit: string for angular units. Default 'd': degrees\n!\n! outputs\n! -------\n! e,n,u: East, North, Up coordinates of test points (meters)\n \n real(wp), intent(in) :: x,y,z,lat0,lon0,alt0\n type(Ellipsoid), intent(in), optional :: spheroid\n logical, intent(in), optional :: deg\n real(wp), intent(out) :: east,north,up\n \n real(wp) :: x0,y0,z0\n\n call geodetic2ecef(lat0, lon0, alt0, x0,y0,z0, spheroid,deg)\n call ecef2enuv(x - x0, y - y0, z - z0, lat0, lon0, east, north, up, deg)\nend subroutine ecef2enu\n\n\nelemental subroutine ecef2enuv(u, v, w, lat0, lon0, east, north, up, deg)\n! ecef2enuv convert *vector projection* UVW to ENU\n!\n! Inputs\n! ------\n! u,v,w: meters\n! lat0,lon0: geodetic latitude and longitude (degrees)\n! deg: .true. degrees\n!\n! Outputs\n! -------\n! e,n,Up: East, North, Up vector\n\n real(wp), intent(in) :: u,v,w\n real(wp), value :: lat0,lon0\n logical, optional, value :: deg\n real(wp), intent(out) :: east, north, up\n \n real(wp) :: t\n \n if (.not.present(deg)) deg = .true.\n \n if (deg) then\n lat0 = radians(lat0)\n lon0 = radians(lon0)\n endif\n \n t = cos(lon0) * u + sin(lon0) * v\n east = -sin(lon0) * u + cos(lon0) * v\n up = cos(lat0) * t + sin(lat0) * w\n north = -sin(lat0) * t + cos(lat0) * w\nend subroutine ecef2enuv\n\n\nelemental subroutine enu2uvw(e,n,up,lat0,lon0,u,v,w,deg)\n! enu2uvw convert from ENU to UVW coordinates\n!\n! Inputs\n! ------\n! e,n,up: East, North, Up coordinates of point(s) (meters)\n! lat0,lon0: geodetic coordinates of observer/reference point (degrees)\n! deg: ,true. degrcees\n!\n! outputs\n! -------\n! u,v,w: coordinates of test point(s) (meters)\n real(wp), intent(in) :: e,n,up\n real(wp), value :: lat0,lon0\n real(wp), intent(out) :: u,v,w\n logical, optional, value :: deg\n\n real(wp) :: t\n\n if(.not.present(deg)) deg=.true.\n\n if (deg) then\n lat0 = radians(lat0)\n lon0 = radians(lon0)\n endif\n\n\n t = cos(lat0) * up - sin(lat0) * n\n w = sin(lat0) * up + cos(lat0) * n\n\n u = cos(lon0) * t - sin(lon0) * e\n v = sin(lon0) * t + cos(lon0) * e\n\nend subroutine enu2uvw\n\n\nelemental real(wp) function radius_normal(lat,E)\n real(wp), intent(in) :: lat\n type(Ellipsoid), intent(in) :: E\n\n radius_normal = E%SemimajorAxis**2 / sqrt( E%SemimajorAxis**2 * cos(lat)**2 + E%SemiminorAxis**2 * sin(lat)**2 )\n\nend function radius_normal\n\nelemental real(wp) function anglesep(lon0,lat0,lon1,lat1)\n! angular separation between two points on sphere\n! all input/output in DEGREES\n\n real(wp), intent(in) :: lat0,lon0,lat1,lon1\n real(wp) :: la0,lo0,la1,lo1\n \n la0 = radians(lat0)\n lo0 = radians(lon0)\n la1 = radians(lat1)\n lo1 = radians(lon1)\n\n anglesep = degrees(2 * asin(sqrt(haversine(la1 - la0) + &\n cos(la0) * cos(la1) * haversine(lo1 - lo0))))\n\n\nend function anglesep\n\n\nelemental real(wp) function haversine(theta)\n! theta: angle in RADIANS\n\n real(wp), intent(in) :: theta\n\n haversine = (1 - cos(theta)) / 2.\n\nend function haversine\n\n\nelemental real(wp) function degrees(rad)\n real(wp), intent(in) :: rad\n\n degrees = 180._wp / pi * rad\nend function degrees\n\n\nelemental real(wp) function radians(deg)\n real(wp), intent(in) :: deg\n\n radians = pi / 180._wp * deg\nend function radians\n\nend module\n", "meta": {"hexsha": "4d1d028c8fe79a8fb6c96340c18c76773186f16d", "size": 16229, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/maptran.f90", "max_stars_repo_name": "SamuelMarks/pymap3d", "max_stars_repo_head_hexsha": "312eafdb4c22979ce443856ea5845aaef32bd41e", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-06-27T13:50:36.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-27T13:50:36.000Z", "max_issues_repo_path": "fortran/maptran.f90", "max_issues_repo_name": "SamuelMarks/pymap3d", "max_issues_repo_head_hexsha": "312eafdb4c22979ce443856ea5845aaef32bd41e", "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": "fortran/maptran.f90", "max_forks_repo_name": "SamuelMarks/pymap3d", "max_forks_repo_head_hexsha": "312eafdb4c22979ce443856ea5845aaef32bd41e", "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": 28.5721830986, "max_line_length": 116, "alphanum_fraction": 0.6706513032, "num_tokens": 5308, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.933430805473952, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6936959128816211}} {"text": " SUBROUTINE ZPOSV_F95( A, B, UPLO, INFO )\n!\n! -- LAPACK95 interface driver routine (version 3.0) --\n! UNI-C, Denmark; Univ. of Tennessee, USA; NAG Ltd., UK\n! September, 2000\n!\n! .. USE STATEMENTS ..\n USE LA_PRECISION, ONLY: WP => DP\n USE LA_AUXMOD, ONLY: ERINFO, LSAME\n USE F77_LAPACK, ONLY: POSV_F77 => LA_POSV\n! .. IMPLICIT STATEMENT ..\n IMPLICIT NONE\n! .. SCALAR ARGUMENTS ..\n CHARACTER(LEN=1), INTENT(IN), OPTIONAL :: UPLO\n INTEGER, INTENT(OUT), OPTIONAL :: INFO\n! .. ARRAY ARGUMENTS ..\n COMPLEX(WP), INTENT(INOUT) :: A(:,:), B(:,:)\n!----------------------------------------------------------------------\n! \n! Purpose\n! =======\n! \n! LA_POSV computes the solution to a linear system of equations \n! A*X=B, where A is real symmetric or complex Hermitian and, in either\n! case, positive definite, and where X and B are rectangular matrices \n! or vectors. The Cholesky decomposition is used to factor A as\n! A = U^H*U if UPLO = 'U', or A = L*L^H if UPLO = 'L'\n! where U is an upper triangular matrix and L is a lower triangular \n! matrix (L = U^H ). The factored form of A is then used to solve the\n! above system.\n! \n! =========\n! \n! SUBROUTINE LA_POSV( A, B, UPLO=uplo, INFO=info )\n! (), INTENT(INOUT) :: A(:,:), \n! CHARACTER(LEN=1), INTENT(IN), OPTIONAL :: UPLO\n! INTEGER, INTENT(OUT), OPTIONAL :: INFO\n! where\n! ::= REAL | COMPLEX\n! ::= KIND(1.0) | KIND(1.0D0)\n! ::= B(:,:) | B(:)\n! \n! Arguments\n! =========\n! \n! A (input/output) REAL or COMPLEX square array, shape (:,:).\n! On entry, the matrix A.\n! If UPLO = 'U', the upper triangular part of A contains the upper \n! triangular part of the matrix A, and the strictly lower triangular\n! part of A is not referenced. If UPLO = 'L', the lower triangular \n! part of A contains the lower triangular part of the matrix A, and\n! the strictly upper triangular part of A is not referenced.\n! On exit, the factor U or L from the Cholesky factorization \n! A = U^H*U = L*L^H.\n! B (input/output) REAL or COMPLEX array, shape (:,:) with \n! size(B,1) = size(A,1) or shape (:) with size(B) = size(A,1).\n! On entry, the matrix B.\n! On exit, the solution matrix X.\n! UPLO Optional (input) CHARACTER(LEN=1)\n! = 'U': Upper triangle of A is stored;\n! = 'L': Lower triangle of A is stored.\n! Default value: 'U'.\n! INFO Optional (output) INTEGER\n! = 0: sauccessful exit.\n! < 0: if INFO = -i, the i-th argument had an illegal value.\n! > 0: if INFO = i, the leading minor of order i of A is not\n! positive definite, so the factorization could not be \n! \t completed and the solution could not be computed.\n! If INFO is not present and an error occurs, then the program is\n! terminated with an error message.\n!----------------------------------------------------------------------\n! .. PARAMETERS ..\n CHARACTER(LEN=7), PARAMETER :: SRNAME = 'LA_POSV'\n! .. LOCAL SCALARS ..\n CHARACTER(LEN=1) :: LUPLO\n INTEGER :: LINFO, N, NRHS\n! .. INTRINSIC FUNCTIONS ..\n INTRINSIC SIZE, PRESENT\n! .. EXECUTABLE STATEMENTS ..\n LINFO = 0; N = SIZE(A,1); NRHS = SIZE(B,2)\n IF( PRESENT(UPLO) )THEN; LUPLO = UPLO; ELSE; LUPLO = 'U'; END IF\n! .. TEST THE ARGUMENTS\n IF( SIZE( A, 2 ) /= N .OR. N < 0 ) THEN; LINFO = -1\n ELSE IF( SIZE( B, 1 ) /= N .OR. NRHS < 0 ) THEN; LINFO = -2\n ELSE IF( .NOT.LSAME(LUPLO,'U') .AND. .NOT.LSAME(LUPLO,'L') )THEN; LINFO = -3\n ELSE IF ( N > 0 ) THEN\n CALL POSV_F77( LUPLO, N, NRHS, A, N, B, N, LINFO )\n END IF\n CALL ERINFO( LINFO, SRNAME, INFO )\n END SUBROUTINE ZPOSV_F95\n", "meta": {"hexsha": "d489dde2984d536a53ca03af42ed8932ec12afaf", "size": 3761, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/la_zposv.f90", "max_stars_repo_name": "MattBurn/LAPACK95", "max_stars_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-12-29T15:07:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T10:09:22.000Z", "max_issues_repo_path": "src/la_zposv.f90", "max_issues_repo_name": "MattBurn/LAPACK95", "max_issues_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-02-21T10:46:38.000Z", "max_issues_repo_issues_event_max_datetime": "2017-10-20T17:03:14.000Z", "max_forks_repo_path": "src/la_zposv.f90", "max_forks_repo_name": "MattBurn/LAPACK95", "max_forks_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-12-29T15:34:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-15T07:12:40.000Z", "avg_line_length": 41.3296703297, "max_line_length": 80, "alphanum_fraction": 0.5713905876, "num_tokens": 1159, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767970940975, "lm_q2_score": 0.7905303260722198, "lm_q1q2_score": 0.6936720185276041}} {"text": "program test_varn\n use stdlib_experimental_error, only: check\n use stdlib_experimental_kinds, only: sp, dp, int32, int64\n use stdlib_experimental_stats, only: var\n use,intrinsic :: ieee_arithmetic, only : ieee_is_nan\n implicit none\n\n\n real(sp), parameter :: sptol = 1000 * epsilon(1._sp)\n real(dp), parameter :: dptol = 1000 * epsilon(1._dp)\n\n integer(int32) :: i321(5) = [1, 2, 3, 4, 5]\n\n integer(int32), allocatable :: i32(:,:), i323(:, :, :)\n\n real(sp) :: s1(5) = [1.0_sp, 2.0_sp, 3.0_sp, 4.0_sp, 5.0_sp]\n real(dp) :: d1(5) = [1.0_dp, 2.0_dp, 3.0_dp, 4.0_dp, 5.0_dp]\n\n real(sp), allocatable :: s(:, :), s3(:, :, :)\n real(dp), allocatable :: d3(:, :, :)\n real(dp) :: d(4, 3) = reshape([1._dp, 3._dp, 5._dp, 7._dp,&\n 2._dp, 4._dp, 6._dp, 8._dp,&\n 9._dp, 10._dp, 11._dp, 12._dp], [4, 3])\n\n\n complex(dp) :: cd1(5) = [ cmplx(0.57706_dp, 0.00000_dp),&\n cmplx(0.00000_dp, 1.44065_dp),&\n cmplx(1.26401_dp, 0.00000_dp),&\n cmplx(0.00000_dp, 0.88833_dp),&\n cmplx(1.14352_dp, 0.00000_dp)]\n complex(dp) :: cd(5,3)\n\n\n !sp\n !1dim\n print*,' test_sp_1dim'\n call check( abs(var(s1, corrected=.false.) - 2.5*(4./5.)) < sptol)\n call check( abs(var(s1, dim=1, corrected=.false.) - 2.5*(4./5.)) < sptol)\n\n print*,' test_sp_1dim_mask'\n call check( ieee_is_nan(var(s1, .false., corrected=.false.)))\n call check( ieee_is_nan(var(s1, 1, .false., corrected=.false.)))\n\n print*,' test_sp_1dim_mask_array'\n call check( abs(var(s1, s1 < 5, corrected=.false.) - 5./4.) < sptol)\n call check( ieee_is_nan((var(s1, s1 < 0., corrected=.false.))))\n call check( abs(var(s1, s1 == 1., corrected=.false.)) < sptol)\n call check( abs(var(s1, 1, s1 < 5, corrected=.false.) - 5./4.) < sptol)\n\n !2dim\n print*,' test_sp_2dim'\n s = d\n call check( abs(var(s, corrected=.false.) - 13.*11./12.) < sptol)\n call check( all( abs( var(s, 1, corrected=.false.) - [20., 20., 5.]/4.) < sptol))\n call check( all( abs( var(s, 2, corrected=.false.) -&\n [19.0, 43. / 3., 31. / 3. , 7.0]*2./3.) < sptol))\n\n print*,' test_sp_2dim_mask'\n call check( ieee_is_nan(var(s, .false., corrected=.false.)))\n call check( any(ieee_is_nan(var(s, 1, .false., corrected=.false.))))\n call check( any(ieee_is_nan(var(s, 2, .false., corrected=.false.))))\n\n print*,' test_sp_2dim_mask_array'\n call check( abs(var(s, s < 11, corrected=.false.) - 2.75*3.) < sptol)\n call check( all( abs( var(s, 1, s < 11, corrected=.false.) -&\n [5., 5., 0.25]) < sptol))\n call check( all( abs( var(s, 2, s < 11, corrected=.false.) -&\n [19.0*2./3., 43./9.*2., 0.25 , 0.25]) < sptol))\n\n\n !3dim\n allocate(s3(size(s,1),size(s,2),3))\n s3(:,:,1)=s;\n s3(:,:,2)=s*2;\n s3(:,:,3)=s*4;\n\n print*,' test_sp_3dim'\n call check( abs(var(s3, corrected=.false.) - 153.4*35./36.) < sptol)\n call check( all( abs( var(s3, 1, corrected=.false.) -&\n reshape([20. / 3., 20. / 3., 5. / 3.,&\n 4* 20. / 3., 4* 20. / 3., 4* 5. / 3.,&\n 16* 20. / 3., 16* 20. / 3., 16* 5. / 3.],&\n [size(s3,2), size(s3,3)])*3./4.)&\n < sptol))\n call check( all( abs( var(s3, 2, corrected=.false.) -&\n reshape([19.0, 43. / 3., 31. / 3. , 7.0,&\n 4* 19.0, 4* 43. / 3., 4* 31. / 3. , 4* 7.0,&\n 16* 19.0, 16* 43. / 3., 16* 31. / 3. , 16* 7.0],&\n [size(s3,1), size(s3,3)] )*2./3.)&\n < sptol))\n call check( all(abs( var(s3, 3, corrected=.false.) -&\n reshape([ 7./3., 21., 175./3.,&\n 343./3., 28./3., 112./3.,&\n 84., 448./3., 189.,&\n 700./3., 847./3., 336.], [size(s3,1), size(s3,2)] )*2./3.)&\n < sptol))\n\n print*,' test_sp_3dim_mask'\n call check( ieee_is_nan(var(s3, .false., corrected=.false.)))\n call check( any(ieee_is_nan(var(s3, 1, .false., corrected=.false.))))\n call check( any(ieee_is_nan(var(s3, 2, .false., corrected=.false.))))\n call check( any(ieee_is_nan(var(s3, 3, .false., corrected=.false.))))\n\n print*,' test_sp_3dim_mask_array'\n call check( abs(var(s3, s3 < 11, corrected=.false.) - 7.73702383_sp) < sptol)\n call check( all( abs( var(s3, 1, s3 < 45, corrected=.false.) -&\n reshape([5., 5., 1.25, 20., 20., 5., 80., 80., 32./3.],&\n [size(s3, 2), size(s3, 3)])) < sptol ))\n call check( all( abs( var(s3, 2, s3 < 45, corrected=.false.) -&\n reshape([ 38./3., 86./9., 6.88888931, 14./3., 152./3.,&\n 38.2222214, 27.5555573, 18.6666660, 202.666672,&\n 152.888885, 110.222229, 4.&\n ],&\n [size(s3, 1), size(s3, 3)])) < sptol ))\n call check( all( abs( var(s3, 3, s3 < 45, corrected=.false.) -&\n reshape([1.555555, 14., 38.888888, 76.222222, 6.2222222,&\n 24.888888, 56., 99.5555, 126., 155.555555, 188.22222, 36.&\n ], [size(s3,1), size(s3,2)] ))&\n < sptol ))\n\n !dp\n !1dim\n print*,' test_dp_1dim'\n call check( abs(var(d1, corrected=.false.) - 2.5_dp*(4._dp/5.)) < dptol)\n call check( abs(var(d1, dim=1, corrected=.false.) - 2.5_dp*(4._dp/5.)) < dptol)\n\n print*,' test_dp_1dim_mask'\n call check( ieee_is_nan(var(d1, .false., corrected=.false.)))\n call check( ieee_is_nan(var(d1, 1, .false., corrected=.false.)))\n\n print*,' test_dp_1dim_mask_array'\n call check( abs(var(d1, d1 < 5, corrected=.false.) - 5._dp/4.) < dptol)\n call check( ieee_is_nan((var(d1, d1 < 0, corrected=.false.))))\n call check( abs(var(d1, d1 == 1, corrected=.false.)) < dptol)\n call check( abs(var(d1, 1, d1 < 5, corrected=.false.) - 5._dp/4.) < dptol)\n\n !2dim\n print*,' test_dp_2dim'\n call check( abs(var(d, corrected=.false.) - 13._dp*11./12.) < dptol)\n call check( all( abs( var(d, 1, corrected=.false.) - [20., 20., 5.]/4._dp) < dptol))\n call check( all( abs( var(d, 2, corrected=.false.) -&\n [38._dp, 86._dp / 3._dp, 62._dp / 3._dp , 14._dp]/3._dp) < dptol))\n\n print*,' test_dp_2dim_mask'\n call check( ieee_is_nan(var(d, .false., corrected=.false.)))\n call check( any(ieee_is_nan(var(d, 1, .false., corrected=.false.))))\n call check( any(ieee_is_nan(var(d, 2, .false., corrected=.false.))))\n\n print*,' test_dp_2dim_mask_array'\n call check( abs(var(d, d < 11, corrected=.false.) - 2.75_dp*3._dp) < dptol)\n call check( all( abs( var(d, 1, d < 11, corrected=.false.) -&\n [5._dp, 5._dp, 0.25_dp]) < dptol))\n call check( all( abs( var(d, 2, d < 11, corrected=.false.) -&\n [38._dp/3., 86._dp/9., 0.25_dp , 0.25_dp]) < dptol))\n\n\n !3dim\n allocate(d3(size(d,1),size(d,2),3))\n d3(:,:,1)=d;\n d3(:,:,2)=d*2;\n d3(:,:,3)=d*4;\n\n print*,' test_dp_3dim'\n call check( abs(var(d3, corrected=.false.) - 153.4_dp*35._dp/36._dp) < dptol)\n call check( all( abs( var(d3, 1, corrected=.false.) -&\n reshape([20._dp , 20._dp , 5._dp ,&\n 4* 20._dp , 4* 20._dp , 4* 5._dp ,&\n 16* 20._dp , 16* 20._dp , 16* 5._dp ],&\n [size(d3,2), size(d3,3)])/4._dp)&\n < dptol))\n call check( all( abs( var(d3, 2, corrected=.false.) -&\n reshape([38._dp, 86. / 3._dp, 62. / 3._dp , 14._dp,&\n 8* 19._dp, 8* 43. / 3._dp, 8* 31. / 3._dp, 8* 7._dp,&\n 32* 19._dp, 32* 43. / 3._dp, 32* 31. / 3._dp, 32* 7._dp],&\n [size(d3,1), size(d3,3)] )/3._dp)&\n < dptol))\n print*,' test_dp_3dim'\n call check( all(abs( var(d3, 3, corrected=.false.) -&\n reshape([ 7._dp/3., 21._dp, 175._dp/3.,&\n 343._dp/3., 28._dp/3., 112._dp/3.,&\n 84._dp, 448._dp/3., 189._dp,&\n 700._dp/3., 847._dp/3., 336._dp],&\n [size(d3,1), size(d3,2)] )*2._dp/3._dp)&\n < dptol))\n\n print*,' test_dp_3dim_mask'\n call check( ieee_is_nan(var(d3, .false., corrected=.false.)))\n call check( any(ieee_is_nan(var(d3, 1, .false., corrected=.false.))))\n call check( any(ieee_is_nan(var(d3, 2, .false., corrected=.false.))))\n call check( any(ieee_is_nan(var(d3, 3, .false., corrected=.false.))))\n\n print*,' test_dp_3dim_mask_array'\n call check( abs(var(d3, d3 < 11, corrected=.false.) -&\n 7.7370242214532876_dp) < dptol)\n call check( all( abs( var(d3, 1, d3 < 45, corrected=.false.) -&\n reshape([5._dp, 5._dp, 1.25_dp, 20._dp, 20._dp, 5._dp,&\n 80._dp, 80._dp, 32._dp/3.],&\n [size(d3, 2), size(d3, 3)])) < dptol ))\n call check( all( abs( var(d3, 2, d3 < 45, corrected=.false.) -&\n reshape([ 38._dp/3., 86._dp/9., 62._dp/9., 14._dp/3., 152._dp/3.,&\n 344._dp/9., 248._dp/9., 168._dp/9., 1824._dp/9.,&\n 1376._dp/9., 992._dp/9., 4._dp&\n ],&\n [size(d3, 1), size(d3, 3)])) < dptol ))\n print*,' test_dp_3dim_mask_array'\n call check( all( abs( var(d3, 3, d3 < 45, corrected=.false.) -&\n reshape([14._dp/9., 14._dp, 350._dp/9., 686._dp/9., 56._dp/9.,&\n 224._dp/9., 56._dp, 896._dp/9., 126._dp, 1400._dp/9.,&\n 1694._dp/9., 36._dp&\n ], [size(d3,1), size(d3,2)] ))&\n < dptol ))\n\n !int32\n !1dim\n print*,' test_int32_1dim'\n call check( abs(var(i321, corrected=.false.) - 2.5_dp*(4._dp/5.)) < dptol)\n call check( abs(var(i321, dim=1, corrected=.false.) - 2.5_dp*(4._dp/5.)) < dptol)\n\n print*,' test_int32_1dim_mask'\n call check( ieee_is_nan(var(i321, .false., corrected=.false.)))\n call check( ieee_is_nan(var(i321, 1, .false., corrected=.false.)))\n\n print*,' test_int32_1dim_mask_array'\n call check( abs(var(i321, i321 < 5, corrected=.false.) - 5._dp/4.) < dptol)\n call check( ieee_is_nan((var(i321, i321 < 0, corrected=.false.))))\n call check( abs(var(i321, i321 == 1, corrected=.false.)) < dptol)\n call check( abs(var(i321, 1, i321 < 5, corrected=.false.) - 5._dp/4.) < dptol)\n\n !2dim\n i32 = d\n print*,' test_int32_2dim'\n call check( abs(var(i32, corrected=.false.) - 13._dp*11./12.) < dptol)\n call check( all( abs( var(i32, 1, corrected=.false.) -&\n [20., 20., 5.]/4._dp) < dptol))\n call check( all( abs( var(i32, 2, corrected=.false.) -&\n [38._dp, 86._dp / 3._dp, 62._dp / 3._dp , 14._dp]/3._dp) < dptol))\n\n print*,' test_int32_2dim_mask'\n call check( ieee_is_nan(var(i32, .false., corrected=.false.)))\n call check( any(ieee_is_nan(var(i32, 1, .false., corrected=.false.))))\n call check( any(ieee_is_nan(var(i32, 2, .false., corrected=.false.))))\n\n print*,' test_int32_2dim_mask_array'\n call check( abs(var(i32, i32 < 11, corrected=.false.) - 2.75_dp*3._dp) < dptol)\n call check( all( abs( var(i32, 1, i32 < 11, corrected=.false.) -&\n [5._dp, 5._dp, 0.25_dp]) < dptol))\n call check( all( abs( var(i32, 2, i32 < 11, corrected=.false.) -&\n [38._dp/3., 86._dp/9., 0.25_dp , 0.25_dp]) < dptol))\n\n\n !3dim\n allocate(i323(size(i32,1),size(i32,2),3))\n i323(:,:,1)=i32;\n i323(:,:,2)=i32*2;\n i323(:,:,3)=i32*4;\n\n print*,' test_int32_3dim'\n call check( abs(var(i323, corrected=.false.) - 153.4_dp*35._dp/36._dp) < dptol)\n call check( all( abs( var(i323, 1, corrected=.false.) -&\n reshape([20._dp , 20._dp , 5._dp ,&\n 4* 20._dp , 4* 20._dp , 4* 5._dp ,&\n 16* 20._dp , 16* 20._dp , 16* 5._dp ],&\n [size(i323,2), size(i323,3)])/4._dp)&\n < dptol))\n call check( all( abs( var(i323, 2, corrected=.false.) -&\n reshape([38._dp, 86. / 3._dp, 62. / 3._dp , 14._dp,&\n 8* 19._dp, 8* 43. / 3._dp, 8* 31. / 3._dp, 8* 7._dp,&\n 32* 19._dp, 32* 43. / 3._dp, 32* 31. / 3._dp, 32* 7._dp],&\n [size(i323,1), size(i323,3)] )/3._dp)&\n < dptol))\n print*,' test_int32_3dim'\n call check( all(abs( var(i323, 3, corrected=.false.) -&\n reshape([ 7._dp/3., 21._dp, 175._dp/3.,&\n 343._dp/3., 28._dp/3., 112._dp/3.,&\n 84._dp, 448._dp/3., 189._dp,&\n 700._dp/3., 847._dp/3., 336._dp],&\n [size(i323,1), size(i323,2)] )*2._dp/3._dp)&\n < dptol))\n\n print*,' test_int32_3dim_mask'\n call check( ieee_is_nan(var(i323, .false., corrected=.false.)))\n call check( any(ieee_is_nan(var(i323, 1, .false., corrected=.false.))))\n call check( any(ieee_is_nan(var(i323, 2, .false., corrected=.false.))))\n call check( any(ieee_is_nan(var(i323, 3, .false., corrected=.false.))))\n\n print*,' test_int32_3dim_mask_array'\n call check( abs(var(i323, i323 < 11, corrected=.false.) -&\n 7.7370242214532876_dp) < dptol)\n call check( all( abs( var(i323, 1, i323 < 45, corrected=.false.) -&\n reshape([5._dp, 5._dp, 1.25_dp, 20._dp, 20._dp, 5._dp,&\n 80._dp, 80._dp, 32._dp/3.],&\n [size(i323, 2), size(i323, 3)])) < dptol ))\n call check( all( abs( var(i323, 2, i323 < 45, corrected=.false.) -&\n reshape([ 38._dp/3., 86._dp/9., 62._dp/9., 14._dp/3., 152._dp/3.,&\n 344._dp/9., 248._dp/9., 168._dp/9., 1824._dp/9.,&\n 1376._dp/9., 992._dp/9., 4._dp&\n ],&\n [size(i323, 1), size(i323, 3)])) < dptol ))\n print*,' test_int32_3dim_mask_array'\n call check( all( abs( var(i323, 3, i323 < 45, corrected=.false.) -&\n reshape([14._dp/9., 14._dp, 350._dp/9., 686._dp/9., 56._dp/9.,&\n 224._dp/9., 56._dp, 896._dp/9., 126._dp, 1400._dp/9.,&\n 1694._dp/9., 36._dp&\n ], [size(i323,1), size(i323,2)] ))&\n < dptol ))\n\n !cdp\n !1dim\n print*,' test_cdp_1dim'\n call check( abs(var(cd1, corrected=.false.) -&\n (var(real(cd1), corrected=.false.) +&\n var(aimag(cd1), corrected=.false.))) < dptol)\n call check( abs(var(cd1, dim=1, corrected=.false.) -&\n (var(real(cd1), dim=1, corrected=.false.) +&\n var(aimag(cd1), dim=1, corrected=.false.))) < dptol)\n\n print*,' test_cdp_1dim_mask'\n call check( ieee_is_nan(var(cd1, .false., corrected=.false.)))\n call check( ieee_is_nan(var(cd1, 1, .false., corrected=.false.)))\n\n print*,' test_cdp_1dim_mask_array'\n call check( abs(var(cd1, aimag(cd1) == 0, corrected=.false.) -&\n var(real(cd1), aimag(cd1) == 0, corrected=.false.)) < dptol)\n call check( abs(var(cd1, 1, aimag(cd1) == 0, corrected=.false.) -&\n var(real(cd1), 1, aimag(cd1) == 0, corrected=.false.)) < dptol)\n call check( ieee_is_nan((var(cd1, (real(cd1) == 0 .and. aimag(cd1) == 0),&\n corrected=.false.))))\n call check( abs(var(cd1, (real(cd1) > 1.2 .and. aimag(cd1) == 0),&\n corrected=.false.)) < dptol)\n\n !2dim\n cd(:,1) = cd1\n cd(:,2) = cd1*3_sp\n cd(:,3) = cd1*1.5_sp\n\n print*,' test_cdp_2dim'\n call check( abs(var(cd, corrected=.false.) -&\n (var(real(cd), corrected=.false.) +&\n var(aimag(cd), corrected=.false.))) < dptol)\n call check( all( abs(var(cd, 1, corrected=.false.) -&\n (var(real(cd), 1, corrected=.false.) +&\n var(aimag(cd), 1, corrected=.false.))) < dptol))\n call check( all( abs(var(cd, 2, corrected=.false.) -&\n (var(real(cd), 2, corrected=.false.) +&\n var(aimag(cd), 2, corrected=.false.))) < dptol))\n\n print*,' test_cdp_2dim_mask'\n call check( ieee_is_nan(var(cd, .false., corrected=.false.)))\n call check( any(ieee_is_nan(var(cd, 1, .false., corrected=.false.))))\n call check( any(ieee_is_nan(var(cd, 2, .false., corrected=.false.))))\n\n print*,' test_cdp_2dim_mask_array'\n call check( abs(var(cd, aimag(cd) == 0, corrected=.false.) -&\n var(real(cd), aimag(cd) == 0, corrected=.false.)) < dptol)\n call check( all( abs( var(cd, 1, aimag(cd) == 0, corrected=.false.) -&\n var(real(cd), 1, aimag(cd) == 0, corrected=.false.)) < dptol))\n call check( any( ieee_is_nan( var(cd, 2, aimag(cd) == 0, corrected=.false.))))\n\nend program\n", "meta": {"hexsha": "af731e704a1715e22d2987a43f0be2db1e309a5d", "size": 17222, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/stats/test_varn.f90", "max_stars_repo_name": "ashwinvis/stdlib", "max_stars_repo_head_hexsha": "9e377fe8a5e75ae0d35f698719af3229b1d3cf1f", "max_stars_repo_licenses": ["MIT"], "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/tests/stats/test_varn.f90", "max_issues_repo_name": "ashwinvis/stdlib", "max_issues_repo_head_hexsha": "9e377fe8a5e75ae0d35f698719af3229b1d3cf1f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/tests/stats/test_varn.f90", "max_forks_repo_name": "ashwinvis/stdlib", "max_forks_repo_head_hexsha": "9e377fe8a5e75ae0d35f698719af3229b1d3cf1f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-04-21T23:21:05.000Z", "max_forks_repo_forks_event_max_datetime": "2020-04-21T23:21:05.000Z", "avg_line_length": 47.8388888889, "max_line_length": 89, "alphanum_fraction": 0.4957031704, "num_tokens": 6248, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476800298183, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.6936720145649691}} {"text": "module finite_differences\n\n implicit none\n\n public :: first_order_upwind\n public :: third_order_upwind\n public :: fifth_order_upwind\n public :: third_order_upwind_zed\n public :: first_order_upwind_zed\n public :: second_order_centered\n public :: fourth_order_centered\n public :: second_order_centered_zed\n public :: four_point_triangle\n public :: fd3pt, fd5pt\n public :: d2_3pt\n public :: fd_variable_upwinding_vpa\n public :: fd_variable_upwinding_zed\n public :: fd_cell_centres_zed, cell_centres_zed\n\n interface fd3pt\n module procedure fd3pt_real\n module procedure fd3pt_real_array\n module procedure fd3pt_complex_array\n end interface\n\n interface fd5pt\n module procedure fd5pt_real\n module procedure fd5pt_array\n end interface\n\n interface first_order_upwind\n module procedure first_order_upwind_real\n module procedure first_order_upwind_complex\n end interface\n\n interface third_order_upwind\n module procedure third_order_upwind_complex\n module procedure third_order_upwind_real\n end interface\n\n interface fifth_order_upwind\n module procedure fifth_order_upwind_complex\n module procedure fifth_order_upwind_real\n end interface\n\n interface tridag\n module procedure tridag_real\n module procedure tridag_complex\n end interface\n\n interface second_order_centered\n module procedure second_order_centered_real\n module procedure second_order_centered_complex\n end interface\n\n interface four_point_triangle\n module procedure four_point_triangle_real\n module procedure four_point_triangle_complex\n end interface\n\n interface fourth_order_centered\n module procedure fourth_order_centered_real\n module procedure fourth_order_centered_complex\n end interface\n\n interface second_order_centered_zed\n module procedure second_order_centered_zed_real\n module procedure second_order_centered_zed_complex\n end interface\n\n interface d2_3pt\n module procedure d2_3pt_real\n module procedure d2_3pt_complex\n end interface\n\ncontains\n\n subroutine first_order_upwind_real (llim, f, del, sgn, df)\n \n implicit none\n \n integer, intent (in) :: llim\n real, dimension (llim:), intent (in) :: f\n real, intent (in) :: del\n integer, intent (in) :: sgn\n real, dimension (llim:), intent (out) :: df\n \n integer :: i, n, istart, iend\n\n n = size(f)\n\n if (sgn == -1) then\n istart = llim\n iend = llim+n-1\n else\n istart = llim+n-1\n iend = llim\n end if\n\n ! zero BC, 1st order accurate upwind\n df(istart) = -f(istart)*sgn/del\n do i = istart-sgn, iend, -sgn\n df(i) = sgn*(f(i+sgn)-f(i))/del\n end do\n\n end subroutine first_order_upwind_real\n \n subroutine first_order_upwind_complex (llim, f, del, sgn, df)\n \n implicit none\n \n integer, intent (in) :: llim\n complex, dimension (llim:), intent (in) :: f\n real, intent (in) :: del\n integer, intent (in) :: sgn\n complex, dimension (llim:), intent (out) :: df\n \n integer :: i, n, istart, iend\n\n n = size(f)\n\n if (sgn == -1) then\n istart = llim\n iend = llim+n-1\n else\n istart = llim+n-1\n iend = llim\n end if\n\n ! zero BC, 1st order accurate upwind\n df(istart) = -f(istart)*sgn/del\n do i = istart-sgn, iend, -sgn\n df(i) = sgn*(f(i+sgn)-f(i))/del\n end do\n\n end subroutine first_order_upwind_complex\n \n subroutine third_order_upwind_complex (llim, f, del, sgn, df)\n \n implicit none\n \n integer, intent (in) :: llim\n complex, dimension (llim:), intent (in) :: f\n real, intent (in) :: del\n integer, intent (in) :: sgn\n complex, dimension (llim:), intent (out) :: df\n \n integer :: i, n, istart, iend\n\n n = size(f)\n if (sgn == -1) then\n istart = llim\n iend = llim+n-1\n else\n istart = llim+n-1\n iend = llim\n end if\n\n i = istart-sgn\n ! zero BC, 1st order accurate upwind\n df(istart) = -f(istart)*sgn/del\n\n ! zero BC, 3rd order accurate upwind\n df(i) = -sgn*(2.*f(i-sgn)+3.*f(i)-6.*f(i+sgn))/(6.*del)\n\n ! 1st order accurate upwind\n df(iend) = sgn*(f(iend+sgn)-f(iend))/del\n\n ! 3rd order accurate upwind\n do i = istart-2*sgn, iend+sgn, -sgn\n df(i) = -sgn*(2.*f(i-sgn)+3*f(i)-6.*f(i+sgn)+f(i+2*sgn))/(6.*del)\n end do\n\n end subroutine third_order_upwind_complex\n\n subroutine third_order_upwind_real (llim, f, del, sgn, df)\n \n implicit none\n \n integer, intent (in) :: llim\n real, dimension (llim:), intent (in) :: f\n real, intent (in) :: del\n integer, intent (in) :: sgn\n real, dimension (llim:), intent (out) :: df\n \n integer :: i, n, istart, iend\n\n n = size(f)\n if (sgn == -1) then\n istart = llim\n iend = llim+n-1\n else\n istart = llim+n-1\n iend = llim\n end if\n\n i = istart-sgn\n ! zero BC, 1st order accurate upwind\n df(istart) = -f(istart)*sgn/del\n ! zero BC, 3rd order accurate upwind\n df(i) = -sgn*(2.*f(i-sgn)+3.*f(i)-6.*f(i+sgn))/(6.*del)\n\n ! 1st order accurate upwind\n df(iend) = sgn*(f(iend+sgn)-f(iend))/del\n\n ! 3rd order accurate upwind\n do i = istart-2*sgn, iend+sgn, -sgn\n df(i) = -sgn*(2.*f(i-sgn)+3*f(i)-6.*f(i+sgn)+f(i+2*sgn))/(6.*del)\n end do\n\n end subroutine third_order_upwind_real\n\n subroutine fifth_order_upwind_complex (llim, f, del, sgn, df)\n \n implicit none\n \n integer, intent (in) :: llim\n complex, dimension (llim:), intent (in) :: f\n real, intent (in) :: del\n integer, intent (in) :: sgn\n complex, dimension (llim:), intent (out) :: df\n \n integer :: i, n, istart, iend\n\n n = size(f)\n if (sgn == -1) then\n istart = llim\n iend = llim+n-1\n else\n istart = llim+n-1\n iend = llim\n end if\n\n ! zero BC, 1st order accurate upwind\n df(istart) = -f(istart)*sgn/del\n ! zero BC, 3rd order accurate upwind\n i = istart-sgn\n df(i) = -sgn*(2.*f(i-sgn)+3.*f(i)-6.*f(i+sgn))/(6.*del)\n ! zero BC, 5th order accurate upwind\n i = istart-2*sgn\n df(i) = -sgn*(-3.*f(i-2*sgn)+30.*f(i-sgn)+20.*f(i)-60.*f(i+sgn)+15.*f(i+2*sgn))/(60.*del)\n\n ! 1st order accurate upwind\n df(iend) = sgn*(f(iend+sgn)-f(iend))/del\n ! 3rd order accurate upwind\n df(iend+sgn) = -sgn*(2.*f(iend)+3*f(iend+sgn)-6.*f(iend+2*sgn)+f(iend+3*sgn))/(6.*del)\n\n ! 5th order accurate upwind\n do i = istart-3*sgn, iend+2*sgn, -sgn\n df(i) = -sgn*(-3.*f(i-2*sgn)+30.*f(i-sgn)+20.*f(i)-60.*f(i+sgn)+15.*f(i+2*sgn)-2.*f(i+3*sgn)) &\n /(60.*del)\n end do\n\n end subroutine fifth_order_upwind_complex\n\n subroutine fifth_order_upwind_real (llim, f, del, sgn, df)\n \n implicit none\n \n integer, intent (in) :: llim\n real, dimension (llim:), intent (in) :: f\n real, intent (in) :: del\n integer, intent (in) :: sgn\n real, dimension (llim:), intent (out) :: df\n \n integer :: i, n, istart, iend\n\n n = size(f)\n if (sgn == -1) then\n istart = llim\n iend = llim+n-1\n else\n istart = llim+n-1\n iend = llim\n end if\n\n ! zero BC, 1st order accurate upwind\n df(istart) = -f(istart)*sgn/del\n ! zero BC, 3rd order accurate upwind\n i = istart-sgn\n df(i) = -sgn*(2.*f(i-sgn)+3.*f(i)-6.*f(i+sgn))/(6.*del)\n ! zero BC, 5th order accurate upwind\n i = istart-2*sgn\n df(i) = -sgn*(-3.*f(i-2*sgn)+30.*f(i-sgn)+20.*f(i)-60.*f(i+sgn)+15.*f(i+2*sgn))/(60.*del)\n\n ! 1st order accurate upwind\n df(iend) = -sgn*(f(iend)-f(iend+sgn))/del\n ! 3rd order accurate upwind\n df(iend+sgn) = -sgn*(2.*f(iend)+3*f(iend+sgn)-6.*f(iend+2*sgn)+f(iend+3*sgn))/(6.*del)\n\n ! 5th order accurate upwind\n do i = istart-3*sgn, iend+2*sgn, -sgn\n df(i) = -sgn*(-3.*f(i-2*sgn)+30.*f(i-sgn)+20.*f(i)-60.*f(i+sgn)+15.*f(i+2*sgn)-2.*f(i+3*sgn)) &\n /(60.*del)\n end do\n\n end subroutine fifth_order_upwind_real\n\n subroutine third_order_upwind_zed (llim, iseg, nseg, f, del, sgn, fl, fr, periodic, df)\n\n implicit none\n \n integer, intent (in) :: llim, iseg, nseg\n complex, dimension (llim:), intent (in) :: f\n real, intent (in) :: del\n integer, intent (in) :: sgn\n logical, intent (in) :: periodic\n complex, dimension (:), intent (in) :: fl, fr\n complex, dimension (llim:), intent (out) :: df\n\n integer :: i, istart, iend, ulim\n\n ulim = size(f)+llim-1 \n ! if sgn > 0, then stream speed is negative\n ! so sweep from more positive to more negative zed\n if (sgn > 0) then\n if (iseg == nseg .and..not.periodic) then\n i = ulim\n df(i) = -f(i)/del\n i = ulim-1\n df(i) = -(2.*f(i-1)+3.*f(i)-6.*f(i+1))/(6.*del)\n else\n i = ulim\n df(i) = -(2.*f(i-1)+3.*f(i)-6.*fr(1)+fr(2))/(6.*del)\n i = ulim-1\n df(i) = -(2.*f(i-1)+3.*f(i)-6.*f(i+1)+fr(1))/(6.*del)\n end if\n if (iseg == 1.and..not.periodic) then\n i = llim\n df(i) = (f(i+1)-f(i))/del\n else\n i = llim\n df(i) = -(2.*fl(2)+3*f(i)-6.*f(i+1)+f(i+2))/(6.*del)\n end if\n istart = ulim\n iend = llim\n else\n if (iseg == 1.and..not.periodic) then\n i = llim\n df(i) = f(i)/del\n i = llim+1\n df(i) = (2.*f(i+1)+3.*f(i)-6.*f(i-1))/(6.*del)\n else\n i = llim\n df(i) = (2.*f(i+1)+3*f(i)-6.*fl(2)+fl(1))/(6.*del)\n i = llim+1\n df(i) = (2.*f(i+1)+3*f(i)-6.*f(i-1)+fl(2))/(6.*del)\n end if\n if (iseg == nseg.and..not.periodic) then\n i = ulim\n df(i) = (f(i)-f(i-1))/del\n else\n i = ulim\n df(i) = (2.*fr(1)+3*f(i)-6.*f(i-1)+f(i-2))/(6.*del)\n end if\n istart = llim\n iend = ulim\n end if\n\n ! 3rd order accurate upwind\n do i = istart-2*sgn, iend+sgn, -sgn\n df(i) = -sgn*(2.*f(i-sgn)+3*f(i)-6.*f(i+sgn)+f(i+2*sgn))/(6.*del)\n end do\n\n end subroutine third_order_upwind_zed\n\n subroutine first_order_upwind_zed (llim, iseg, nseg, f, del, sgn, fl, fr, periodic, df)\n\n implicit none\n \n integer, intent (in) :: llim, iseg, nseg\n complex, dimension (llim:), intent (in) :: f\n real, intent (in) :: del\n integer, intent (in) :: sgn\n logical, intent (in) :: periodic\n complex, dimension (:), intent (in) :: fl, fr\n complex, dimension (llim:), intent (out) :: df\n\n integer :: i, istart, iend, ulim\n\n ulim = size(f)+llim-1 \n ! if sgn > 0, then stream speed is negative\n ! so sweep from more positive to more negative zed\n if (sgn > 0) then\n if (iseg == nseg.and..not.periodic) then\n i = ulim\n df(i) = -f(i)/del\n i = ulim-1\n df(i) = (f(i+1)-f(i))/del\n else\n i = ulim\n df(i) = (fr(1)-f(i))/del\n i = ulim-1\n df(i) = (f(i+1)-f(i))/del\n end if\n i = llim\n df(i) = (f(i+1)-f(i))/del\n istart = ulim\n iend = llim\n else\n if (iseg == 1.and..not.periodic) then\n i = llim\n df(i) = f(i)/del\n i = llim+1\n df(i) = (f(i)-f(i-1))/del\n else\n i = llim\n df(i) = (f(i)-fl(2))/del\n i = llim+1\n df(i) = (f(i)-f(i-1))/del\n end if\n i = ulim\n df(i) = (f(i)-f(i-1))/del\n istart = llim\n iend = ulim\n end if\n\n ! 3rd order accurate upwind\n do i = istart-2*sgn, iend+sgn, -sgn\n df(i) = sgn*(f(i+sgn)-f(i))/del\n end do\n\n end subroutine first_order_upwind_zed\n\n subroutine second_order_centered_real (llim, f, del, df)\n \n implicit none\n \n integer, intent (in) :: llim\n real, dimension (llim:), intent (in) :: f\n real, intent (in) :: del\n real, dimension (llim:), intent (out) :: df\n \n integer :: i, n, istart, iend\n\n n = size(f)\n istart = llim\n iend = llim+n-1\n\n ! zero BC\n df(istart) = f(istart+1) / (2.*del)\n df(iend) =-f(iend-1) / (2.*del) \n\n\n ! 2nd order accurate centered\n do i = istart+1, iend-1\n df(i) = (f(i+1) - f(i-1)) / (2.*del)\n end do\n\n end subroutine second_order_centered_real\n\n subroutine second_order_centered_complex (llim, f, del, df)\n \n implicit none\n \n integer, intent (in) :: llim\n complex, dimension (llim:), intent (in) :: f\n real, intent (in) :: del\n complex, dimension (llim:), intent (out) :: df\n \n integer :: i, n, istart, iend\n\n n = size(f)\n istart = llim\n iend = llim+n-1\n\n ! zero BC\n df(istart) = f(istart+1) / (2.*del)\n df(iend) =-f(iend-1) / (2.*del) \n\n\n ! 2nd order accurate centered\n do i = istart+1, iend-1\n df(i) = (f(i+1) - f(i-1)) / (2.*del)\n end do\n\n end subroutine second_order_centered_complex\n\n subroutine four_point_triangle_real (llim, f, del, df)\n \n implicit none\n \n integer, intent (in) :: llim\n real, dimension (llim:), intent (in) :: f\n real, intent (in) :: del\n real, dimension (llim:), intent (out) :: df\n \n integer :: i, n, istart, iend\n\n n = size(f)\n istart = llim\n iend = llim+n-1\n\n ! zero BC\n i=istart\n df(i) = f(i+1) / (2.0*del)\n i=istart+1\n df(i) = (f(i+1)-f(i-1)) / (2.0*del)\n i=istart+2\n df(i) = (-2.*f(i+3)+9.*f(i+1)-9.*f(i-1)) / (18.0*del)\n\n i=iend\n df(i) = -f(i-1) / (2.0*del)\n i=iend-1\n df(i) = (f(i+1)-f(i-1)) / (2.0*del)\n i=iend-2\n df(i) = (9.*f(i+1)-9.*f(i-1)+2.*f(i-3)) / (18.0*del)\n\n\n ! 2nd order accurate centered\n do i = istart+3, iend-3\n df(i) = (-2.*f(i+3)+9.*f(i+1)-9.*f(i-1)+2.*f(i-3)) / (18.0*del)\n end do\n\n end subroutine four_point_triangle_real\n\n subroutine four_point_triangle_complex (llim, f, del, df)\n \n implicit none\n \n integer, intent (in) :: llim\n complex, dimension (llim:), intent (in) :: f\n real, intent (in) :: del\n complex, dimension (llim:), intent (out) :: df\n \n integer :: i, n, istart, iend\n\n n = size(f)\n istart = llim\n iend = llim+n-1\n\n ! zero BC\n i=istart\n df(i) = f(i+1) / (2.0*del)\n i=istart+1\n df(i) = (f(i+1)-f(i-1)) / (2.0*del)\n i=istart+2\n df(i) = (-2.*f(i+3)+9.*f(i+1)-9.*f(i-1)) / (18.0*del)\n\n i=iend\n df(i) = -f(i-1) / (2.0*del)\n i=iend-1\n df(i) = (f(i+1)-f(i-1)) / (2.0*del)\n i=iend-2\n df(i) = (9.*f(i+1)-9.*f(i-1)+2.*f(i-3)) / (18.0*del)\n\n\n ! 2nd order accurate centered\n do i = istart+3, iend-3\n df(i) = (-2.*f(i+3)+9.*f(i+1)-9.*f(i-1)+2.*f(i-3)) / (18.0*del)\n end do\n\n end subroutine four_point_triangle_complex\n\n subroutine fourth_order_centered_real (llim, f, del, df)\n \n implicit none\n \n integer, intent (in) :: llim\n real, dimension (llim:), intent (in) :: f\n real, intent (in) :: del\n real, dimension (llim:), intent (out) :: df\n \n integer :: i, n, istart, iend\n\n n = size(f)\n istart = llim\n iend = llim+n-1\n\n ! zero BC\n ! 2nd order accurate centered\n df(istart) = f(istart + 1) / (2.*del)\n df(iend) =-f(iend - 1) / (2.*del) \n\n ! 4th order accurate centered\n df(istart+1) = (f(istart+3) - 8.*f(istart+2) + 8.*f(istart)) / (12.*del)\n df(iend-1) = (-8*f(iend) + 8.*f(iend-2) - f(iend-3)) / (12.*del) \n\n\n ! 4th order accurate centered\n do i = istart+2, iend-2\n df(i) = (f(i+2)-8.*f(i+1) + 8.*f(i-1)-f(i-2)) / (12.*del)\n end do\n\n end subroutine fourth_order_centered_real\n\n subroutine fourth_order_centered_complex (llim, f, del, df)\n \n implicit none\n \n integer, intent (in) :: llim\n complex, dimension (llim:), intent (in) :: f\n real, intent (in) :: del\n complex, dimension (llim:), intent (out) :: df\n \n integer :: i, n, istart, iend\n\n n = size(f)\n istart = llim\n iend = llim+n-1\n\n ! zero BC\n ! 2nd order accurate centered\n df(istart) = f(istart + 1) / (2.*del)\n df(iend) =-f(iend - 1) / (2.*del) \n\n ! 4th order accurate centered\n df(istart+1) = (f(istart+3) - 8.*f(istart+2) + 8.*f(istart))/ (12.*del)\n df(iend-1) = (-8*f(iend) + 8.*f(iend-2) - f(iend-3)) / (12.*del) \n\n\n ! 4th order accurate centered\n do i = istart+2, iend-2\n df(i) = (f(i+2)-8.*f(i+1) + 8.*f(i-1)-f(i-2)) / (12.*del)\n end do\n\n end subroutine fourth_order_centered_complex\n\n subroutine second_order_centered_zed_real (llim, iseg, nseg, f, del, sgn, fl, fr, periodic, df)\n\n implicit none\n \n integer, intent (in) :: llim, iseg, nseg\n real, dimension (llim:), intent (in) :: f\n integer, intent (in) :: sgn\n real, intent (in) :: del\n real, dimension (:), intent (in) :: fl, fr\n logical, intent (in) :: periodic\n real, dimension (llim:), intent (out) :: df\n\n integer :: i, ulim\n\n ulim = size(f)+llim-1 \n\n i = llim\n if (iseg == 1 .and. sgn>0 .and..not.periodic) then\n ! sgn > 0 corresponds to negative advection speed\n ! upwind at boundary requires taking information from right\n df(i) = (f(i+1)-f(i))/del\n else\n df(i) = 0.5*(f(i+1)-fl(2))/del\n end if\n\n i = ulim\n if (iseg == nseg .and. sgn<0 .and..not.periodic) then\n ! sgn < 0 corresponds to positive advection speed\n ! upwind at boundary requires taking information from left\n df(i) = (f(i)-f(i-1))/del\n else\n df(i) = 0.5*(fr(1)-f(i-1))/del\n end if\n \n do i = llim+1, ulim-1\n df(i) = 0.5*(f(i+1)-f(i-1))/del\n end do\n\n end subroutine second_order_centered_zed_real\n\n subroutine second_order_centered_zed_complex (llim, iseg, nseg, f, del, sgn, fl, fr, periodic, df)\n\n implicit none\n \n integer, intent (in) :: llim, iseg, nseg\n complex, dimension (llim:), intent (in) :: f\n integer, intent (in) :: sgn\n real, intent (in) :: del\n complex, dimension (:), intent (in) :: fl, fr\n logical, intent (in) :: periodic\n complex, dimension (llim:), intent (out) :: df\n\n integer :: i, ulim\n\n ulim = size(f)+llim-1 \n\n i = llim\n if (iseg == 1 .and. sgn>0 .and..not.periodic) then\n ! sgn > 0 corresponds to negative advection speed\n ! upwind at boundary requires taking information from right\n df(i) = (f(i+1)-f(i))/del\n else\n df(i) = 0.5*(f(i+1)-fl(2))/del\n end if\n\n i = ulim\n if (iseg == nseg .and. sgn<0 .and..not.periodic) then\n ! sgn < 0 corresponds to positive advection speed\n ! upwind at boundary requires taking information from left\n df(i) = (f(i)-f(i-1))/del\n else\n df(i) = 0.5*(fr(1)-f(i-1))/del\n end if\n \n do i = llim+1, ulim-1\n df(i) = 0.5*(f(i+1)-f(i-1))/del\n end do\n\n end subroutine second_order_centered_zed_complex\n\n subroutine second_order_centered_vpa (llim, f, del, df)\n\n implicit none\n \n integer, intent (in) :: llim\n complex, dimension (llim:), intent (in) :: f\n real, intent (in) :: del\n complex, dimension (llim:), intent (out) :: df\n\n integer :: i, ulim\n\n ulim = size(f)+llim-1 \n\n i = llim\n df(i) = 0.5*f(i+1)/del\n\n i = ulim\n df(i) = -0.5*f(i-1)/del\n\n do i = llim+1, ulim-1\n df(i) = 0.5*(f(i+1)-f(i-1))/del\n end do\n\n end subroutine second_order_centered_vpa\n\n subroutine fd_cell_centres_zed (llim, f, del, sgn, fl, fr, df)\n\n implicit none\n\n integer, intent (in) :: llim\n complex, dimension (llim:), intent (in) :: f\n real, intent (in) :: del\n integer, intent (in) :: sgn\n complex, intent (in) :: fl, fr\n complex, dimension (llim:), intent (out) :: df\n\n integer :: i, ulim\n\n ulim = size(f)+llim-1\n \n if (sgn > 0) then\n ! if sgn > 0, then stream speed is negative\n ! so sweep from more positive to more negative zed\n i = ulim\n df(i) = (fr-f(i))/del\n do i = ulim-1, llim, -1\n df(i) = (f(i+1)-f(i))/del\n end do\n else\n ! if sgn < 0, then stream speed is positive\n ! so sweep from more negative to more positive zed\n i = llim\n df(i) = (f(i)-fl)/del\n do i = llim+1, ulim\n df(i) = (f(i)-f(i-1))/del\n end do\n end if\n\n end subroutine fd_cell_centres_zed\n\n ! cell_centres_zed takes f at z grid locations\n ! and returns f at cell centres\n ! (with possible offset due to upwinding)\n subroutine cell_centres_zed (llim, f, upwnd, sgn, fl, fr, fc)\n\n implicit none\n\n integer, intent (in) :: llim\n complex, dimension (llim:), intent (in) :: f\n real, intent (in) :: upwnd\n integer, intent (in) :: sgn\n complex, intent (in) :: fl, fr\n complex, dimension (llim:), intent (out) :: fc\n\n integer :: i, ulim\n\n ulim = size(f)+llim-1\n\n if (sgn > 0) then\n ! if sgn > 0, then stream speed is negative\n ! so sweep from more positive to more negative zed\n i = ulim\n fc(i) = 0.5*((1.-upwnd)*fr + (1.+upwnd)*f(i))\n do i = ulim-1, llim, -1\n fc(i) = 0.5*((1.-upwnd)*f(i+1) + (1.+upwnd)*f(i))\n end do\n else\n ! if sgn < 0, then stream speed is positive\n ! so sweep from more negative to more positive zed\n i = llim\n fc(i) = 0.5*((1.+upwnd)*f(i)+(1.-upwnd)*fl)\n do i = llim+1, ulim\n fc(i) = 0.5*((1.+upwnd)*f(i)+(1.-upwnd)*f(i-1))\n end do\n end if\n\n end subroutine cell_centres_zed\n\n subroutine fd_variable_upwinding_zed (llim, iseg, nseg, f, del, sgn, upwnd, fl, fr, periodic, df)\n\n implicit none\n\n integer, intent (in) :: llim, iseg, nseg\n complex, dimension (llim:), intent (in) :: f\n real, intent (in) :: del, upwnd\n integer, intent (in) :: sgn\n complex, dimension (:), intent (in) :: fl, fr\n logical, intent (in) :: periodic\n complex, dimension (llim:), intent (out) :: df\n\n integer :: i, istart, iend, ulim\n\n ! if upwnd is zero or if vpa=0, then use centered differences\n if (abs(upwnd) < epsilon(0.) .or. sgn == 0) then\n call second_order_centered_zed (llim, iseg, nseg, f, del, sgn, fl, fr, periodic, df)\n else\n ulim = size(f)+llim-1\n \n ! if sgn > 0, then stream speed is negative\n ! so sweep from more positive to more negative zed\n if (sgn > 0) then\n if (iseg == nseg.and..not.periodic) then\n i = ulim\n df(i) = (0.5*(upwnd-1.)*f(i-1)-upwnd*f(i))/del\n else\n i = ulim\n df(i) = (0.5*(upwnd-1.)*f(i-1)-upwnd*f(i)+0.5*(1.+upwnd)*fr(1))/del\n end if\n if (iseg == 1.and..not.periodic) then\n i = llim\n ! at left boundary, must upwind fully as no info for f(i-1)\n df(i) = (f(i+1)-f(i))/del\n else\n i = llim\n df(i) = (0.5*(1.+upwnd)*f(i+1)-upwnd*f(i)+0.5*(upwnd-1.)*fl(2))/del\n end if\n istart = ulim\n iend = llim\n else\n if (iseg == 1.and..not.periodic) then\n i = llim\n df(i) = (0.5*(1.-upwnd)*f(i+1)+upwnd*f(i))/del\n else\n i = llim\n df(i) = (0.5*(1.-upwnd)*f(i+1)+upwnd*f(i)-0.5*(1.+upwnd)*fl(2))/del\n end if\n if (iseg == nseg.and..not.periodic) then\n i = ulim\n ! if at rightmost zed, have no info for f(i+1) so must fully upwind\n df(i) = (f(i)-f(i-1))/del\n else\n i = ulim\n df(i) = (0.5*(1.-upwnd)*fr(1)+upwnd*f(i)-0.5*(1.+upwnd)*f(i-1))/del\n end if\n istart = llim\n iend = ulim\n end if\n\n ! mixed 2nd order centered and 1st order upwind scheme\n do i = istart-sgn, iend+sgn, -sgn\n df(i) = sgn*(0.5*(1.+upwnd)*f(i+sgn) - upwnd*f(i) + 0.5*(upwnd-1.)*f(i-sgn))/del\n end do\n\n end if\n\n end subroutine fd_variable_upwinding_zed\n\n subroutine fd_variable_upwinding_vpa (llim, f, del, sgn, upwnd, df)\n\n implicit none\n\n integer, intent (in) :: llim\n complex, dimension (llim:), intent (in) :: f\n real, intent (in) :: del, upwnd\n integer, intent (in) :: sgn\n complex, dimension (llim:), intent (out) :: df\n\n integer :: i, istart, iend, ulim\n\n ! if upwnd is zero or if z=0, then use centered differences\n if (abs(upwnd) < epsilon(0.) .or. sgn == 0) then\n call second_order_centered_vpa (llim, f, del, df)\n else\n ulim = size(f)+llim-1\n\n ! if sgn > 0, then stream speed is negative\n ! so sweep from more positive to more negative zed\n if (sgn > 0) then\n istart = ulim\n iend = llim\n else\n istart = llim\n iend = ulim\n end if\n\n ! zero_bc assumes that g -> zero beyond grid\n ! boundaries in vpa\n df(istart) = sgn*(0.5*(upwnd-1.0)*f(istart-sgn)-upwnd*f(istart))/del\n\n ! as do not have info beyond grid boundary at end of sweep\n ! use pure upwinding\n df(iend) = sgn*(f(iend+sgn)-f(iend))/del\n\n ! mixed centered and 1st order upwind scheme\n do i = istart-sgn, iend+sgn, -sgn\n df(i) = sgn*(0.5*(1.+upwnd)*f(i+sgn) - upwnd*f(i) + 0.5*(upwnd-1.)*f(i-sgn))/del\n end do\n\n end if\n\n end subroutine fd_variable_upwinding_vpa\n\n ! only good for equally-spaced grid-pts\n subroutine fd3pt_real (prof, profgrad, dr)\n \n implicit none\n \n real, dimension (:), intent (in) :: prof\n real, dimension (:), intent (out) :: profgrad\n real, intent (in) :: dr\n \n integer :: ix, npts\n real, dimension (:), allocatable :: aa, bb, cc\n \n npts = size(prof)\n allocate (aa(npts), bb(npts), cc(npts))\n \n aa = 1.0 ; bb = 4.0 ; cc = 1.0\n aa(1) = 0.0 ; bb(1) = 0.5 ; cc(1) = 0.5\n aa(npts) = 0.5 ; bb(npts) = 0.5 ; cc(npts) = 0.0\n \n do ix = 2, npts-1\n profgrad(ix) = 3.0 * (prof(ix+1) - prof(ix-1)) / dr\n end do\n profgrad(1) = (prof(2)-prof(1))/dr\n profgrad(npts) = (prof(npts)-prof(npts-1))/dr\n \n call tridag (aa, bb, cc, profgrad)\n \n deallocate (aa, bb, cc)\n \n end subroutine fd3pt_real\n \n subroutine fd3pt_real_array (prof, profgrad, dr)\n \n implicit none\n \n real, dimension (:), intent (in) :: prof, dr\n real, dimension (:), intent (out) :: profgrad\n \n integer :: ix, npts\n real :: a, b, c\n \n npts = size(prof)\n \n do ix = 2, npts-1\n profgrad(ix) = ((prof(ix)-prof(ix-1))*dr(ix)/dr(ix-1) &\n + (prof(ix+1)-prof(ix))*dr(ix-1)/dr(ix)) / (dr(ix-1)+dr(ix))\n end do\n ix = 1\n a = -(2.*dr(1) + dr(2))/(dr(1)*(dr(1)+dr(2)))\n b = (dr(1)+dr(2))/(dr(1)*dr(2))\n c = -dr(1)/(dr(2)*(dr(1)+dr(2)))\n profgrad(1) = a*prof(1)+b*prof(2)+c*prof(3)\n ix = npts\n a = dr(npts-1)/(dr(npts-2)*(dr(npts-2)+dr(npts-1)))\n b = -(dr(npts-1)+dr(npts-2))/(dr(npts-2)*dr(npts-1))\n c = (2.*dr(npts-1)+dr(npts-2))/(dr(npts-1)*(dr(npts-1)+dr(npts-2)))\n profgrad(npts) = a*prof(npts-2) + b*prof(npts-1) + c*prof(npts)\n \n end subroutine fd3pt_real_array\n\n subroutine fd3pt_complex_array (prof, profgrad, dr)\n \n implicit none\n \n complex, dimension (:), intent (in) :: prof\n real, dimension (:), intent (in) :: dr\n complex, dimension (:), intent (out) :: profgrad\n \n integer :: ix, npts\n real :: a, b, c\n \n npts = size(prof)\n \n do ix = 2, npts-1\n profgrad(ix) = ((prof(ix)-prof(ix-1))*dr(ix)/dr(ix-1) &\n + (prof(ix+1)-prof(ix))*dr(ix-1)/dr(ix)) / (dr(ix-1)+dr(ix))\n end do\n ix = 1\n a = -(2.*dr(1) + dr(2))/(dr(1)*(dr(1)+dr(2)))\n b = (dr(1)+dr(2))/(dr(1)*dr(2))\n c = -dr(1)/(dr(2)*(dr(1)+dr(2)))\n profgrad(1) = a*prof(1)+b*prof(2)+c*prof(3)\n ix = npts\n a = dr(npts-1)/(dr(npts-2)*(dr(npts-2)+dr(npts-1)))\n b = -(dr(npts-1)+dr(npts-2))/(dr(npts-2)*dr(npts-1))\n c = (2.*dr(npts-1)+dr(npts-2))/(dr(npts-1)*(dr(npts-1)+dr(npts-2)))\n profgrad(npts) = a*prof(npts-2) + b*prof(npts-1) + c*prof(npts)\n \n end subroutine fd3pt_complex_array\n\n ! boundary points are 2nd-order accurate (2-pt compact difference)\n ! next to boundary points are 4th-order accurate (2-pt centered compact difference)\n ! interior points are 6th-order accurate (4-pt centered compact difference)\n subroutine fd5pt_real (prof, profgrad, dr)\n\n implicit none\n\n real, dimension (:), intent (in) :: prof\n real, dimension (:), intent (out) :: profgrad\n real, intent (in) :: dr\n\n integer :: ix, npts\n real, dimension (:), allocatable :: aa, bb, cc\n\n npts = size(prof)\n allocate (aa(npts), bb(npts), cc(npts))\n\n aa = 1.0 ; bb = 3.0 ; cc = 1.0\n aa(1) = 0.0 ; bb(1) = 0.5 ; cc(1) = 0.5\n aa(2) = 1.0 ; bb(2) = 4.0 ; cc(2) = 1.0\n aa(npts-1) = 1.0 ; bb(npts-1) = 4.0 ; cc(npts-1) = 1.0\n aa(npts) = 0.5 ; bb(npts) = 0.5 ; cc(npts) = 0.0\n\n do ix = 3, npts-2\n profgrad(ix) = (7.*(prof(ix+1) - prof(ix-1)) + 0.25*(prof(ix+2)-prof(ix-2))) / (3.*dr)\n end do\n profgrad(1) = (prof(2)-prof(1))/dr\n profgrad(2) = 3.0*(prof(3) - prof(1))/dr\n profgrad(npts-1) = 3.0*(prof(npts) - prof(npts-2))/dr\n profgrad(npts) = (prof(npts)-prof(npts-1))/dr\n\n call tridag (aa, bb, cc, profgrad)\n\n deallocate (aa, bb, cc)\n\n end subroutine fd5pt_real\n\n ! boundary points are 2nd-order accurate (2-pt compact difference)\n ! next to boundary points are 4th-order accurate (2-pt centered compact difference)\n ! interior points are 6th-order accurate (4-pt centered compact difference)\n subroutine fd5pt_array (prof, profgrad, dr)\n\n implicit none\n\n real, dimension (:), intent (in) :: prof, dr\n real, dimension (:), intent (out) :: profgrad\n\n integer :: ix, npts\n real, dimension (:), allocatable :: aa, bb, cc\n\n npts = size(prof)\n allocate (aa(npts), bb(npts), cc(npts))\n\n aa = 1.0 ; bb = 3.0 ; cc = 1.0\n aa(1) = 0.0 ; bb(1) = 0.5 ; cc(1) = 0.5\n aa(2) = 1.0 ; bb(2) = 4.0 ; cc(2) = 1.0\n aa(npts-1) = 1.0 ; bb(npts-1) = 4.0 ; cc(npts-1) = 1.0\n aa(npts) = 0.5 ; bb(npts) = 0.5 ; cc(npts) = 0.0\n\n do ix = 3, npts-2\n profgrad(ix) = (7.*(prof(ix+1) - prof(ix-1)) + 0.25*(prof(ix+2)-prof(ix-2))) / (3.*dr(ix))\n end do\n profgrad(1) = (prof(2)-prof(1))/dr(1)\n profgrad(2) = 3.0*(prof(3) - prof(1))/dr(2)\n profgrad(npts-1) = 3.0*(prof(npts) - prof(npts-2))/dr(npts-1)\n profgrad(npts) = (prof(npts)-prof(npts-1))/dr(npts)\n\n call tridag (aa, bb, cc, profgrad)\n\n deallocate (aa, bb, cc)\n\n end subroutine fd5pt_array\n\n\n ! second derivative using centered differences\n ! second order accurate\n subroutine d2_3pt_real (f, d2f, dr)\n\n implicit none\n\n real, dimension (:), intent (in) :: f\n real, dimension (:), intent (in) :: dr\n real, dimension (:), intent (out) :: d2f\n\n real :: a, b, c, d\n integer :: i, n\n\n n = size(f)\n\n do i = 2, n-1\n a = 2./(dr(i-1)*(dr(i)+dr(i-1)))\n b = -2./(dr(i-1)*dr(i))\n c = 2./(dr(i)*(dr(i)+dr(i-1)))\n d2f(i) = a*f(i-1)+b*f(i)+c*f(i+1)\n end do\n i = 1\n a = (6.*dr(1)+4.*dr(2)+2.*dr(3)) &\n / (dr(1)*(dr(1)+dr(2))*(dr(1)+dr(2)+dr(3)))\n b = -(4.*(dr(1)+dr(2))+2.*dr(3)) &\n / (dr(1)*dr(2)*(dr(2)+dr(3)))\n c = (4.*dr(1)+2.*(dr(2)+dr(3))) &\n / ((dr(2)+dr(1))*dr(2)*dr(3))\n d = -(4.*dr(1)+2.*dr(2)) &\n / ((dr(3)+dr(2)+dr(1))*(dr(3)+dr(2))*dr(3))\n d2f(i) = a*f(1)+b*f(2)+c*f(3)+d*f(4)\n i = n\n a = -(4.*dr(n-1)+2.*dr(n-2)) &\n / (dr(n-3)*(dr(n-3)+dr(n-2))*(dr(n-3)+dr(n-2)+dr(n-1)))\n b = (4.*dr(n-1)+2.*(dr(n-2)+dr(n-3))) &\n / (dr(n-3)*dr(n-2)*(dr(n-2)+dr(n-1)))\n c = -(4.*(dr(n-1)+dr(n-2))+2.*dr(n-3)) &\n / (dr(n-1)*dr(n-2)*(dr(n-2)+dr(n-3)))\n d = (6.*dr(n-1)+4.*dr(n-2)+2.*dr(n-3)) &\n / (dr(n-1)*(dr(n-1)+dr(n-2))*(dr(n-1)+dr(n-2)+dr(n-3)))\n d2f(i) = a*f(n-3)+b*f(n-2)+c*f(n-1)+d*f(n)\n\n! ! FLAG -- this is a hack\n! ! do not anticipate needing 2nd derivatives\n! ! at first and last grid points\n! d2f(1) = d2f(2)\n! d2f(n) = d2f(n-1)\n\n end subroutine d2_3pt_real\n\n subroutine d2_3pt_complex (f, d2f, dr)\n\n implicit none\n\n complex, dimension (:), intent (in) :: f\n real, dimension (:), intent (in) :: dr\n complex, dimension (:), intent (out) :: d2f\n\n real :: a, b, c, d\n integer :: i, n\n\n n = size(f)\n\n do i = 2, n-1\n a = 2./(dr(i-1)*(dr(i)+dr(i-1)))\n b = -2./(dr(i-1)*dr(i))\n c = 2./(dr(i)*(dr(i)+dr(i-1)))\n d2f(i) = a*f(i-1)+b*f(i)+c*f(i+1)\n end do\n i = 1\n a = (6.*dr(1)+4.*dr(2)+2.*dr(3)) &\n / (dr(1)*(dr(1)+dr(2))*(dr(1)+dr(2)+dr(3)))\n b = -(4.*(dr(1)+dr(2))+2.*dr(3)) &\n / (dr(1)*dr(2)*(dr(2)+dr(3)))\n c = (4.*dr(1)+2.*(dr(2)+dr(3))) &\n / ((dr(2)+dr(1))*dr(2)*dr(3))\n d = -(4.*dr(1)+2.*dr(2)) &\n / ((dr(3)+dr(2)+dr(1))*(dr(3)+dr(2))*dr(3))\n d2f(i) = a*f(1)+b*f(2)+c*f(3)+d*f(4)\n i = n\n a = -(4.*dr(n-1)+2.*dr(n-2)) &\n / (dr(n-3)*(dr(n-3)+dr(n-2))*(dr(n-3)+dr(n-2)+dr(n-1)))\n b = (4.*dr(n-1)+2.*(dr(n-2)+dr(n-3))) &\n / (dr(n-3)*dr(n-2)*(dr(n-2)+dr(n-1)))\n c = -(4.*(dr(n-1)+dr(n-2))+2.*dr(n-3)) &\n / (dr(n-1)*dr(n-2)*(dr(n-2)+dr(n-3)))\n d = (6.*dr(n-1)+4.*dr(n-2)+2.*dr(n-3)) &\n / (dr(n-1)*(dr(n-1)+dr(n-2))*(dr(n-1)+dr(n-2)+dr(n-3)))\n d2f(i) = a*f(n-3)+b*f(n-2)+c*f(n-1)+d*f(n)\n\n end subroutine d2_3pt_complex\n\n subroutine tridag_real (aa, bb, cc, sol)\n \n implicit none\n \n real, dimension (:), intent (in) :: aa, bb, cc\n real, dimension (:), intent (in out) :: sol\n \n integer :: ix, npts\n real :: bet\n \n real, dimension (:), allocatable :: gam\n \n npts = size(aa)\n allocate (gam(npts))\n \n bet = bb(1)\n sol(1) = sol(1)/bet\n \n do ix = 2, npts\n gam(ix) = cc(ix-1)/bet\n bet = bb(ix) - aa(ix)*gam(ix)\n if (bet == 0.0) write (*,*) 'tridiagonal solve failed'\n sol(ix) = (sol(ix)-aa(ix)*sol(ix-1))/bet\n end do\n\n do ix = npts-1, 1, -1\n sol(ix) = sol(ix) - gam(ix+1)*sol(ix+1)\n end do\n\n deallocate (gam)\n\n end subroutine tridag_real\n\n subroutine tridag_complex (llim, aa, bb, cc, sol)\n \n implicit none\n \n integer, intent (in) :: llim\n real, dimension (llim:), intent (in) :: aa, bb, cc\n complex, dimension (llim:), intent (in out) :: sol\n \n integer :: ix, npts\n real :: bet\n \n real, dimension (:), allocatable :: gam\n \n npts = size(bb)\n allocate (gam(llim:llim+npts-1))\n \n bet = bb(llim)\n sol(llim) = sol(llim)/bet\n \n do ix = llim+1, llim+npts-1\n gam(ix) = cc(ix-1)/bet\n bet = bb(ix) - aa(ix)*gam(ix)\n if (bet == 0.0) write (*,*) 'tridiagonal solve failed'\n sol(ix) = (sol(ix)-aa(ix)*sol(ix-1))/bet\n end do\n\n do ix = llim+npts-2, llim, -1\n sol(ix) = sol(ix) - gam(ix+1)*sol(ix+1)\n end do\n\n deallocate (gam)\n\n end subroutine tridag_complex\n \nend module finite_differences\n", "meta": {"hexsha": "6bf347fa941916f919d11ab5479e553a36076422", "size": 34314, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/finite_differences.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/finite_differences.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/finite_differences.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": 27.7846153846, "max_line_length": 102, "alphanum_fraction": 0.5404499621, "num_tokens": 12900, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767970940975, "lm_q2_score": 0.7905303137346446, "lm_q1q2_score": 0.6936720077016679}} {"text": "! { dg-do run }\n! PR fortran/24518 \n! MOD/MODULO of large arguments.\n! The naive algorithm goes pear-shaped for large arguments, instead\n! use fmod.\n! Here we test only with constant arguments (evaluated with\n! mpfr_fmod), as we don't want to cause failures on targets with a\n! crappy libm.\nprogram mod_large_1\n implicit none\n real :: r1\n r1 = mod (1e22, 1.7)\n if (abs(r1 - 0.995928764) > 1e-5) STOP 1\n r1 = modulo (1e22, -1.7)\n if (abs(r1 + 0.704071283) > 1e-5) STOP 2\nend program mod_large_1\n", "meta": {"hexsha": "98304c895ea306b378bd8306a7f7bfede977679e", "size": 500, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/mod_large_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/mod_large_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/mod_large_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": 29.4117647059, "max_line_length": 67, "alphanum_fraction": 0.696, "num_tokens": 180, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.693672004433262}} {"text": "double precision function allencahn_fort_eval_bc(iface,t,x,y)\n implicit none\n\n integer iface\n double precision x,y,t\n\n integer bctype(0:3)\n common /comm_bc/ bctype\n\n integer normals(0:3,2)\n double precision q,grad(2), qn, a,b\n\n data normals /-1,1,0,0,0,0,-1,1/\n\n call allencahn_qexact_gradient(x,y,q,grad)\n\n !! q_n = grad q \\cdot n\n qn = normals(iface,1)*grad(1) + normals(iface,2)*grad(2)\n\n !! bc_type is set in options .ini file as [multigrid] boundary_conditions\n if (bctype(iface) .eq. 1) then\n a = 1\n b = 0\n elseif (bctype(iface) .eq. 2) then\n a = 0\n b = 1\n endif\n\n allencahn_fort_eval_bc = a*q + b*qn\n !!allencahn_fort_eval_bc = 0\n\n return\n \nend function allencahn_fort_eval_bc\n\n\ndouble precision function allencahn_dirichlet(iface,t,x,y)\n implicit none\n\n integer iface\n double precision t,x,y\n\n allencahn_dirichlet = -1\n\nend function allencahn_dirichlet", "meta": {"hexsha": "834e48ef3a053ae08961fc0b457a0d488ee76bbe", "size": 957, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "applications/elliptic/allencahn/fortran/allencahn_eval_bc.f90", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2017-09-26T13:39:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:56:23.000Z", "max_issues_repo_path": "applications/elliptic/allencahn/fortran/allencahn_eval_bc.f90", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 75, "max_issues_repo_issues_event_min_datetime": "2017-08-02T19:56:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T12:36:32.000Z", "max_forks_repo_path": "applications/elliptic/allencahn/fortran/allencahn_eval_bc.f90", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-02-21T00:10:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T19:08:36.000Z", "avg_line_length": 21.2666666667, "max_line_length": 77, "alphanum_fraction": 0.6509926855, "num_tokens": 315, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767778695836, "lm_q2_score": 0.7905303211371898, "lm_q1q2_score": 0.6936719989996685}} {"text": "C Copyright 2021 Dennis Blondell Decker\nC Date: 29 May 2021\nC Purpose: Consecutive prime sum\nC Tectonics: gfortran --ffixed-form -o euler050 euler050.f90 primesieve.f90\n\n PROGRAM EULER050\n PARAMETER (MX=1000)\nC The gfortran compiler makes the program segmentation fault \nC PARAMETER (MX=1000000)\n LOGICAL SIEVE(MX)\n INTEGER PRIMES(MX), IARR(MX+1), ICUMARR(MX)\n EQUIVALENCE (IARR(2),ICURARR)\n EXTERNAL ERASTOTHENE\n\n DATA ICUMARR/MX*0/\n CALL ERASTOTHENE(SIEVE,MX)\n\n J=0\n DO 10 I=1,MX\n IF (SIEVE(I)) THEN\n J=J+1\n PRIMES(J)=I\n ENDIF\n 10 CONTINUE\n MXPRIMES=J\n\nC We treat this problem like a maximum sum subarray problem.\nC Use Bentley's quadratic variation of Kandane's Algorithm.\nC Instead of the maximum sum, we find the maximum length.\n IARR(1)=0\n DO 20 I=1,MXPRIMES\n 20 ICUMARR(I)=ICUMARR(I-1)+PRIMES(I)\n\nC DO 25 I=1,10\nC 25 PRINT *,I,PRIMES(I),ICUMARR(I),ICUMARR(I-1)\n\n MXSOFAR=0\n K=0\n L=0\n DO 40 I=1,MXPRIMES\n DO 30 J=I,MXPRIMES\n ISUM=ICUMARR(J)-ICUMARR(I-1)\nC ISUM IS SUM OF PRIMES(I:J)\nC IF (I.EQ.1.AND.J.EQ.6)\nC 1 PRINT*,ISUM,ICUMARR(J),ICUMARR(I-1),ICUMARR(0),I,J,K,L\n IF (ISUM.LT.MX) THEN\n IF (SIEVE(ISUM)) THEN\n IF ((L-K).LT.(J-I)) THEN\n K=I\n L=J\n MXSOFAR=ISUM\n ENDIF\n ENDIF\n ENDIF\n 30 CONTINUE\n 40 CONTINUE\n\n PRINT 50,MXSOFAR,L-K+1,(PRIMES(I),I=K,L)\n 50 FORMAT ('Sum:',I0,' with ',I0,' primes:',1000(I7))\n END\n", "meta": {"hexsha": "1c3b1c11ac24407f3ec2d265ccca119d9f883b8a", "size": 1804, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "euler/euler050.f90", "max_stars_repo_name": "dennisdjensen/Sketchbook", "max_stars_repo_head_hexsha": "efb4c7df592ba4fe84e9cdcb0883c93823d04bf5", "max_stars_repo_licenses": ["0BSD"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-04-26T19:30:58.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-12T16:34:23.000Z", "max_issues_repo_path": "euler/euler050.f90", "max_issues_repo_name": "dennisdjensen/sketchbook", "max_issues_repo_head_hexsha": "efb4c7df592ba4fe84e9cdcb0883c93823d04bf5", "max_issues_repo_licenses": ["0BSD"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "euler/euler050.f90", "max_forks_repo_name": "dennisdjensen/sketchbook", "max_forks_repo_head_hexsha": "efb4c7df592ba4fe84e9cdcb0883c93823d04bf5", "max_forks_repo_licenses": ["0BSD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.5737704918, "max_line_length": 75, "alphanum_fraction": 0.5182926829, "num_tokens": 599, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767746654974, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.693671994301554}} {"text": " subroutine DSDIF ( K, N, T, BCOEF, NDERIV, BDIF )\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc>> 1994-10-20 DSDIF Krogh Changes to use M77CON\nc>> 1992-11-02 DSDIF C. L. Lawson, JPL\nc>> 1988-03-16 C. L. Lawson, JPL\nc\nc Constructs a divided difference table in BDIF(,), preparatory to\nc derivative calculation.\nc The subroutine, BSPLPP, given on pp. 140-141 of\nc A PRACTICAL GUIDE TO SPLINES by Carl De Boor, Springer-Verlag,\nc 1978, has been recoded as separate subroutines: DSTOT (or DSTOP)\nc calling DSDIF and DSVALA. This subroutine has the functionality\nc of lines 57-71 of BSPLPP in the book.\nc ------------------------------------------------------------------\nc--D replaces \"?\": ?SDIF\nc ------------------------------------------------------------------\n integer I, ID, K, KMID, N, NDERIV\n double precision BCOEF(N), BDIF(N,NDERIV+1)\n double precision DIFF, FKMID, T(N+K), ZERO\n parameter(ZERO = 0.0D0)\nc ------------------------------------------------------------------\n do 10 I=1,N\n BDIF(I,1) = BCOEF(I)\n 10 continue\n KMID = K\n do 20 ID=2,NDERIV+1\n KMID = KMID - 1\n FKMID = dble(KMID)\n do 20 I=ID,N\n DIFF = T(I + KMID) - T(I)\n if (DIFF .ne. ZERO) then\n BDIF(I,ID) = FKMID*(BDIF(I,ID-1) - BDIF(I-1,ID-1))/DIFF\n else\n BDIF(I,ID) = ZERO\n endif\n 20 continue\n return\n end\n", "meta": {"hexsha": "69d0aa7443f7f29a21a2a7c6dc75850705618d85", "size": 1587, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/dsdif.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/dsdif.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/dsdif.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 38.7073170732, "max_line_length": 72, "alphanum_fraction": 0.5236294896, "num_tokens": 479, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206791658465, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.6936493745255183}} {"text": "submodule(forlab_stats) forlab_stats_randn\n\n implicit none\n\ncontains\n\n module function randn_0_sp(mean, std) result(random)\n real(sp), intent(in) :: mean, std\n real(sp) :: random\n\n real(sp) :: u, v, s\n\n do\n call random_number(u)\n call random_number(v)\n u = 2._sp*u - 1._sp\n v = 2._sp*v - 1._sp\n s = u*u + v*v\n if ((s > 0._sp) .and. (s < 1._sp)) exit\n end do\n\n random = mean + u*sqrt(-2.0_sp*log(s)/s)*std\n\n end function randn_0_sp\n\n module function randn_1_sp(mean, std, ndim) result(random)\n real(sp), intent(in) :: mean, std\n integer, intent(in) :: ndim\n real(sp) :: random(ndim)\n\n integer :: i\n\n do i = 1, ndim\n random(i) = randn_0_sp(mean, std)\n end do\n\n end function randn_1_sp\n module function randn_0_dp(mean, std) result(random)\n real(dp), intent(in) :: mean, std\n real(dp) :: random\n\n real(dp) :: u, v, s\n\n do\n call random_number(u)\n call random_number(v)\n u = 2._dp*u - 1._dp\n v = 2._dp*v - 1._dp\n s = u*u + v*v\n if ((s > 0._dp) .and. (s < 1._dp)) exit\n end do\n\n random = mean + u*sqrt(-2.0_dp*log(s)/s)*std\n\n end function randn_0_dp\n\n module function randn_1_dp(mean, std, ndim) result(random)\n real(dp), intent(in) :: mean, std\n integer, intent(in) :: ndim\n real(dp) :: random(ndim)\n\n integer :: i\n\n do i = 1, ndim\n random(i) = randn_0_dp(mean, std)\n end do\n\n end function randn_1_dp\n\nend submodule forlab_stats_randn\n", "meta": {"hexsha": "ee8155377c0c283ebd8c8634e75920a88c0285a1", "size": 1679, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/forlab_stats_randn.f90", "max_stars_repo_name": "zoziha/forlab_z", "max_stars_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2021-08-31T15:23:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T02:44:46.000Z", "max_issues_repo_path": "src/forlab_stats_randn.f90", "max_issues_repo_name": "zoziha/forlab_z", "max_issues_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-08-22T11:47:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-31T00:57:16.000Z", "max_forks_repo_path": "src/forlab_stats_randn.f90", "max_forks_repo_name": "zoziha/forlab_z", "max_forks_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-07-16T03:16:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-31T13:09:42.000Z", "avg_line_length": 23.6478873239, "max_line_length": 62, "alphanum_fraction": 0.5175699821, "num_tokens": 514, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.855851154320682, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.6936493154148344}} {"text": "!----------------------------------------------------------------------\n!----------------------------------------------------------------------\n! fhn : The FitzHugh - Nagumo Equation\n!----------------------------------------------------------------------\n!----------------------------------------------------------------------\n\n SUBROUTINE FUNC(NDIM,U,ICP,PAR,IJAC,F,DFDU,DFDP)\n! ---------- ----\n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: NDIM, ICP(*), IJAC\n DOUBLE PRECISION, INTENT(IN) :: U(NDIM), PAR(*)\n DOUBLE PRECISION, INTENT(OUT) :: F(NDIM)\n DOUBLE PRECISION, INTENT(INOUT) :: DFDU(NDIM,NDIM), DFDP(NDIM,*)\n\n DOUBLE PRECISION a,b,c,x,y\n\n a=PAR(1)\n b=PAR(2)\n c=PAR(3)\n\n x=U(1)\n y=U(2)\n\n F(1)= c * ( x - x**3/3 + y )\n F(2)=-( x - a + b*y ) / c\n\n END SUBROUTINE FUNC\n!----------------------------------------------------------------------\n!----------------------------------------------------------------------\n\n SUBROUTINE STPNT(NDIM,U,PAR,T)\n! ---------- -----\n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: NDIM\n DOUBLE PRECISION, INTENT(INOUT) :: U(NDIM),PAR(*)\n DOUBLE PRECISION, INTENT(IN) :: T\n!\n! Initialize the equation parameters\n PAR(1)=0.\n PAR(2)=0.8\n PAR(3)=3.0\n\n! Initialize the solution (assuming PAR(1)=0 )\n U(1)=0.\n U(2)=0.\n\n END SUBROUTINE STPNT\n!----------------------------------------------------------------------\n!----------------------------------------------------------------------\n SUBROUTINE BCND \n END SUBROUTINE BCND\n\n SUBROUTINE ICND \n END SUBROUTINE ICND\n\n SUBROUTINE FOPT \n END SUBROUTINE FOPT\n\n SUBROUTINE PVLS\n END SUBROUTINE PVLS\n!----------------------------------------------------------------------\n!----------------------------------------------------------------------\n", "meta": {"hexsha": "09c5649c137f470d03b2c54434f5d45f422e3688", "size": 1904, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "07p/demos/fhn/fhn.f90", "max_stars_repo_name": "st970703/AUTO07P-Update-to-Python-3.0", "max_stars_repo_head_hexsha": "fb2d2aebf2127fa914064d01ed62c0acb5f6421c", "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": "07p/demos/fhn/fhn.f90", "max_issues_repo_name": "st970703/AUTO07P-Update-to-Python-3.0", "max_issues_repo_head_hexsha": "fb2d2aebf2127fa914064d01ed62c0acb5f6421c", "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": "07p/demos/fhn/fhn.f90", "max_forks_repo_name": "st970703/AUTO07P-Update-to-Python-3.0", "max_forks_repo_head_hexsha": "fb2d2aebf2127fa914064d01ed62c0acb5f6421c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.2923076923, "max_line_length": 71, "alphanum_fraction": 0.3287815126, "num_tokens": 432, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511396138365, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.6936492937006257}} {"text": "! .................................................\r\n! ____ _ _ ____ _____ _ \r\n! | _ \\| | |_| | _ \\| ___| |_| \r\n! | |_) | |___ _ | |_) | |___ _ \r\n! | _ /| _ | | | | _ /|___ | | | \r\n! | | | | | | | | | | ___| | | | \r\n! |_| |_| |_| |_| |_| |_____| |_| \r\n! .................................................\r\n! PhiPsi: a general-purpose computational \r\n! mechanics program written in Fortran.\r\n! Website: http://phipsi.top \r\n! Author: Shi Fang from Huaiyin Institute of \r\n! Technology, HuaiAn, JiangSu, China \r\n! Contact me: shifang@hyit.edu.cn \r\n! ------------------------------------------------ \r\n! Please cite the following papers: \r\n! (1)Shi F, Wang X L, Liu C, Liu H, Wu H A. An \r\n! XFEM-based method with reduction technique \r\n! for modeling hydraulic fracture propagation \r\n! in formations containing frictional natural \r\n! fractures. Engineering Fracture Mechanics, \r\n! 2017, 173: 64-90. \r\n! (2)Shi F, Wang X L, Liu C, Liu H, Wu H A. A \r\n! coupled extended finite element approach \r\n! for modeling hydraulic fracturing in \r\n! consideration of proppant. Journal of \r\n! Natural Gas Science and Engineering, 2016, \r\n! 33: 885-897. \r\n! (3)Shi F, Wang X L, Liu C, Liu H, Wu H A. An \r\n! XFEM-based numerical model to calculate \r\n! conductivity of propped fracture considering \r\n! proppant transport, embedment and crushing. \r\n! Journal of Petroleum Science and Engineering, \r\n! 2018, 167: 615-626.. \r\n \r\n SUBROUTINE Matrix_Inverse(a,c,n) \r\nC get inverse matrix\r\n \r\n !============================================================\r\n ! Inverse matrix\r\n ! Method: Based on Doolittle LU factorization for Ax=b\r\n ! Alex G. December 2009\r\n !-----------------------------------------------------------\r\n ! input ...\r\n ! a(n,n) - array of coefficients for matrix A\r\n ! n - dimension\r\n ! output ...\r\n ! c(n,n) - inverse matrix of A\r\n ! comments ...\r\n ! the original matrix a(n,n) will be destroyed \r\n ! during the calculation\r\n !===========================================================\r\n implicit none \r\n integer,intent(in)::n\r\n double precision,intent(in):: a(n,n)\r\n double precision,intent(out):: c(n,n)\r\n double precision L(n,n), U(n,n), b(n), d(n), x(n)\r\n double precision coeff,tem_a(n,n)\r\n integer i, j, k\r\n \r\n tem_a = a\r\n ! step 0: initialization for matrices L and U and b\r\n ! Fortran 90/95 aloows such operations on matrices\r\n L=0.0D0\r\n U=0.0D0\r\n b=0.0D0\r\n\r\n ! step 1: forward elimination\r\n do k=1, n-1\r\n do i=k+1,n\r\n coeff=tem_a(i,k)/tem_a(k,k)\r\n L(i,k) = coeff\r\n do j=k+1,n\r\n tem_a(i,j) = tem_a(i,j)-coeff*tem_a(k,j) \r\n end do\r\n end do\r\n end do\r\n\r\n ! Step 2: prepare L and U matrices \r\n ! L matrix is a matrix of the elimination coefficient\r\n ! + the diagonal elements are 1.0\r\n do i=1,n\r\n\t\t L(i,i) = 1.0D0\r\n end do\r\n ! U matrix is the upper triangular part of A\r\n do j=1,n\r\n do i=1,j\r\n U(i,j) = tem_a(i,j)\r\n end do\r\n end do\r\n\r\n ! Step 3: compute columns of the inverse matrix C\r\n do k=1,n\r\n b(k)=1.0D0\r\n d(1) = b(1)\r\n\t\t! Step 3a: Solve Ld=b using the forward substitution\r\n do i=2,n\r\n d(i)=b(i)\r\n do j=1,i-1\r\n d(i) = d(i) - L(i,j)*d(j)\r\n end do\r\n end do\r\n\t\t! Step 3b: Solve Ux=d using the back substitution\r\n\t\t x(n)=d(n)/U(n,n)\r\n do i = n-1,1,-1\r\n x(i) = d(i)\r\n do j=n,i+1,-1\r\n\t\t\t x(i)=x(i)-U(i,j)*x(j)\r\n end do\r\n x(i) = x(i)/u(i,i)\r\n end do\r\n\t\t! Step 3c: fill the solutions x(n) into column k of C\r\n do i=1,n\r\n c(i,k) = x(i)\r\n end do\r\n\t\t b(k)=0.0D0\r\n end do\r\n\t\t \r\n return\r\n END SUBROUTINE Matrix_Inverse\r\n \r\n\r\n\r\n", "meta": {"hexsha": "a0ac0243fe8f982c367faf6ae0207569ed9ce8dc", "size": 4523, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Matrix_Inverse.f", "max_stars_repo_name": "PhiPsi-Software/PhiPsi_XFEM_Fortran_Codes_Early_Version", "max_stars_repo_head_hexsha": "1eae63a8f0dc968b9d5220397879645a83e5d083", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-04-15T11:56:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-14T11:49:59.000Z", "max_issues_repo_path": "Matrix_Inverse.f", "max_issues_repo_name": "PhiPsi-Software/PhiPsi_XFEM_Fortran_Codes_Early_Version", "max_issues_repo_head_hexsha": "1eae63a8f0dc968b9d5220397879645a83e5d083", "max_issues_repo_licenses": ["MIT"], "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_Inverse.f", "max_forks_repo_name": "PhiPsi-Software/PhiPsi_XFEM_Fortran_Codes_Early_Version", "max_forks_repo_head_hexsha": "1eae63a8f0dc968b9d5220397879645a83e5d083", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2019-01-20T00:55:09.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T00:30:28.000Z", "avg_line_length": 36.4758064516, "max_line_length": 69, "alphanum_fraction": 0.4183064338, "num_tokens": 1176, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.940789749258714, "lm_q2_score": 0.7371581510799253, "lm_q1q2_score": 0.6935108321185002}} {"text": "SUBROUTINE tide_perm (dC20_perm)\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! SUBROUTINE: tide_perm.f90\r\n! ----------------------------------------------------------------------\r\n! Purpose:\r\n! Permanent Tide term\r\n! ----------------------------------------------------------------------\r\n! Input arguments\r\n!\r\n! Output arguments:\r\n! - dC20_perm :\t\tPermanent tide (time-independent) as C20 coefficient correction\r\n! ----------------------------------------------------------------------\r\n! Dr. Thomas Papanikolaou, Geoscience Australia November 2015\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n USE mdl_precision\r\n IMPLICIT NONE\r\n\r\n! ----------------------------------------------------------------------\r\n! Dummy arguments declaration\r\n! ----------------------------------------------------------------------\r\n! IN\r\n\r\n! OUT\r\n REAL (KIND = prec_q), INTENT(OUT) :: dC20_perm\r\n! ----------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n! Local variables declaration\r\n! ---------------------------------------------------------------------- \r\n REAL (KIND = prec_q) :: k20\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! Love numbers (Knm) : Table 6.3, IERS Conventions (2010)\r\n! ----------------------------------------------------------------------\r\n! Elastic Earth\r\n k20 = 0.29525D0\r\n! Anelastic Earth\r\n k20 = 0.30190D0\r\n! ----------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n! Permanent tide (time-independent): C20 coefficient correction\r\n dC20_perm = 4.4228D-8 * (-0.31460D0) * k20\r\n! ----------------------------------------------------------------------\r\n\r\n\r\nEND\r\n", "meta": {"hexsha": "6a38a5041d552552497fcac793b726f955582c62", "size": 1979, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/tide_perm.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/tide_perm.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/tide_perm.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.6481481481, "max_line_length": 81, "alphanum_fraction": 0.2622536635, "num_tokens": 299, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404116305639, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6934917380628297}} {"text": " END FUNCTION func\n\n SUBROUTINE trapzd(func,a,b,s,n)\n IMPLICIT NONE\n INTEGER :: n\n REAL*8,INTENT(IN):: a,b\n EXTERNAL func\n INTEGER:: it,j\n REAL*8 :: del,sum,tnm,x,s,func\n* parameter (n=10000)\n it=2**(n-2)\n it = 50000\n tnm=float(it)\n del=(b-a)/tnm\n x=a+0.5*del\n sum=0.5*func(a)\n* write(*,*)' trap ',it,tnm,del,x\n do 11 j=1,it-1\n sum=sum+func(x)\n x=x+del\n* write(*,*)j,x,sum\n 11 continue\n sum=sum+0.5*func(b)\n s=sum*del\n return\n\n END subroutine\n\n\n\n\n program main\n IMPLICIT NONE\n REAL*8 ::a,b,a0,e0,c0,m1,m2,p,r,q,l3,l1,sf,s,func\n INTEGER :: n\n EXTERNAL func\n WRITE (*,*) \"a0= ,e0=, m1= ,m2= \"\n READ(*,*) a0,e0,m1,m2\n* a0 = 5.\n* e0 = 0.5\n* m1 = 10.\n* m2 = 10.\n* a0=a0*7.0e+08\n p=-12./19.\n r=121./304.\n q=-870./2299.\n n=10\n c0=a0*(e0**p)*((1+r*(e0**2))**q)\n l3=1.9e+16\n l1=((m1*m2)/m1+m2)\n a=0.\n b=e0\n write(*,*) a,b,c0,l1,l3\n call trapzd(func,a,b,s,n)\n write(*,*) \"trapezoidal : \" , s\n sf=(12./19.)*(c0**4./l1)*s*l3\n write(*,*) \"The time is(inMyrs) =\", sf/3.16e+13\n stop\n end\n\n", "meta": {"hexsha": "7fc29b46f47e0db165bdacef9708ac2f9f6ff612", "size": 1235, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "hubbletime.f", "max_stars_repo_name": "debatric/Test", "max_stars_repo_head_hexsha": "fe390d6224fa93121ab856fb5acfd075953c28ce", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "hubbletime.f", "max_issues_repo_name": "debatric/Test", "max_issues_repo_head_hexsha": "fe390d6224fa93121ab856fb5acfd075953c28ce", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hubbletime.f", "max_forks_repo_name": "debatric/Test", "max_forks_repo_head_hexsha": "fe390d6224fa93121ab856fb5acfd075953c28ce", "max_forks_repo_licenses": ["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.2459016393, "max_line_length": 55, "alphanum_fraction": 0.4518218623, "num_tokens": 512, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404077216355, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6934917351462259}} {"text": "!-------------------------------------------------------------------------------\n! Copyright (c) 2019 FrontISTR Commons\n! This software is released under the MIT License, see LICENSE.txt\n!-------------------------------------------------------------------------------\n!> \\brief This module contains functions for interpolation in 8 node\n!! hexahedral element (Langrange interpolation)\nmodule shape_hex8n\n integer, parameter, private :: kreal = kind(0.0d0)\n\ncontains\n subroutine ShapeFunc_hex8n(localcoord,func)\n real(kind=kreal) :: localcoord(3)\n real(kind=kreal) :: func(8)\n func(1) = 0.125d0*(1.d0-localcoord(1))*(1.d0-localcoord(2))*(1.d0-localcoord(3))\n func(2) = 0.125d0*(1.d0+localcoord(1))*(1.d0-localcoord(2))*(1.d0-localcoord(3))\n func(3) = 0.125d0*(1.d0+localcoord(1))*(1.d0+localcoord(2))*(1.d0-localcoord(3))\n func(4) = 0.125d0*(1.d0-localcoord(1))*(1.d0+localcoord(2))*(1.d0-localcoord(3))\n func(5) = 0.125d0*(1.d0-localcoord(1))*(1.d0-localcoord(2))*(1.d0+localcoord(3))\n func(6) = 0.125d0*(1.d0+localcoord(1))*(1.d0-localcoord(2))*(1.d0+localcoord(3))\n func(7) = 0.125d0*(1.d0+localcoord(1))*(1.d0+localcoord(2))*(1.d0+localcoord(3))\n func(8) = 0.125d0*(1.d0-localcoord(1))*(1.d0+localcoord(2))*(1.d0+localcoord(3))\n end subroutine\n\n subroutine ShapeDeriv_hex8n(localcoord, func)\n real(kind=kreal) :: localcoord(3)\n real(kind=kreal) :: func(8,3)\n func(1,1) = -0.125d0*(1.d0-localcoord(2))*(1.d0-localcoord(3))\n func(2,1) = 0.125d0*(1.d0-localcoord(2))*(1.d0-localcoord(3))\n func(3,1) = 0.125d0*(1.d0+localcoord(2))*(1.d0-localcoord(3))\n func(4,1) = -0.125d0*(1.d0+localcoord(2))*(1.d0-localcoord(3))\n func(5,1) = -0.125d0*(1.d0-localcoord(2))*(1.d0+localcoord(3))\n func(6,1) = 0.125d0*(1.d0-localcoord(2))*(1.d0+localcoord(3))\n func(7,1) = 0.125d0*(1.d0+localcoord(2))*(1.d0+localcoord(3))\n func(8,1) = -0.125d0*(1.d0+localcoord(2))*(1.d0+localcoord(3))\n\n func(1,2) = -0.125d0*(1.d0-localcoord(1))*(1.d0-localcoord(3))\n func(2,2) = -0.125d0*(1.d0+localcoord(1))*(1.d0-localcoord(3))\n func(3,2) = 0.125d0*(1.d0+localcoord(1))*(1.d0-localcoord(3))\n func(4,2) = 0.125d0*(1.d0-localcoord(1))*(1.d0-localcoord(3))\n func(5,2) = -0.125d0*(1.d0-localcoord(1))*(1.d0+localcoord(3))\n func(6,2) = -0.125d0*(1.d0+localcoord(1))*(1.d0+localcoord(3))\n func(7,2) = 0.125d0*(1.d0+localcoord(1))*(1.d0+localcoord(3))\n func(8,2) = 0.125d0*(1.d0-localcoord(1))*(1.d0+localcoord(3))\n\n func(1,3) = -0.125d0*(1.d0-localcoord(1))*(1.d0-localcoord(2))\n func(2,3) = -0.125d0*(1.d0+localcoord(1))*(1.d0-localcoord(2))\n func(3,3) = -0.125d0*(1.d0+localcoord(1))*(1.d0+localcoord(2))\n func(4,3) = -0.125d0*(1.d0-localcoord(1))*(1.d0+localcoord(2))\n func(5,3) = 0.125d0*(1.d0-localcoord(1))*(1.d0-localcoord(2))\n func(6,3) = 0.125d0*(1.d0+localcoord(1))*(1.d0-localcoord(2))\n func(7,3) = 0.125d0*(1.d0+localcoord(1))*(1.d0+localcoord(2))\n func(8,3) = 0.125d0*(1.d0-localcoord(1))*(1.d0+localcoord(2))\n end subroutine\n\nend module\n", "meta": {"hexsha": "2ddaf9b9ece4497b902e99d2c97f27235e7cc892", "size": 3048, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fistr1/src/lib/element/hex8n.f90", "max_stars_repo_name": "masae-hayashi/FrontISTR", "max_stars_repo_head_hexsha": "a488de9eb45b3238ba0cd11454c71a03450666a6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 64, "max_stars_repo_stars_event_min_datetime": "2016-09-08T05:26:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T03:36:57.000Z", "max_issues_repo_path": "fistr1/src/lib/element/hex8n.f90", "max_issues_repo_name": "masae-hayashi/FrontISTR", "max_issues_repo_head_hexsha": "a488de9eb45b3238ba0cd11454c71a03450666a6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2016-04-12T09:46:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-17T09:51:51.000Z", "max_forks_repo_path": "fistr1/src/lib/element/hex8n.f90", "max_forks_repo_name": "masae-hayashi/FrontISTR", "max_forks_repo_head_hexsha": "a488de9eb45b3238ba0cd11454c71a03450666a6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 38, "max_forks_repo_forks_event_min_datetime": "2016-10-05T01:47:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-16T07:05:26.000Z", "avg_line_length": 54.4285714286, "max_line_length": 84, "alphanum_fraction": 0.5974409449, "num_tokens": 1259, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403979493139, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6934917278547156}} {"text": "!Incomplete program....\r\n\r\nProgram MAIN\r\n implicit none;\r\n real ll, ul, sum1, sum2, sum;\r\n! F(x) = 1/(1 + x**2);\r\n F(X)=0.398862*((PI+(X/SQRT(200.0)))*EXP(-0.5*X*X))\r\n\r\n integer n, i;\r\n real h;\r\n real integral;\r\n \r\n ll = 0\r\n ul = 1\r\n n = 6\r\n h = (ul-ll) / n\r\n\r\n sum = F(ll) + F(ul);\r\n sum1 = 0;\r\n sum2 = 0;\r\n\r\n do i = 2 , n, 2\r\n sum1 = sum1 + F(ll + (i-1)*h)\r\n end do\r\n\r\n do i = 3 , n, 2\r\n sum2 = sum2 + F(ll + (i-1)*h)\r\n end do\r\n \r\n\r\n integral = h/3(sum + 2*sum2 + 4*sum1)\r\n\r\n print * , integral\r\n\r\nend program MAIN", "meta": {"hexsha": "23c911489c791015812d73437a12dc13f4abac66", "size": 590, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "III-sem/NumericalMethod/simpson.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/simpson.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/simpson.f95", "max_forks_repo_name": "ASHD27/JMI-MCA", "max_forks_repo_head_hexsha": "61995cd2c8306b089a9b40d49d9716043d1145db", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2019-11-11T06:49:10.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-07T12:41:20.000Z", "avg_line_length": 16.8571428571, "max_line_length": 55, "alphanum_fraction": 0.4254237288, "num_tokens": 236, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.929440403812707, "lm_q2_score": 0.7461389873857265, "lm_q1q2_score": 0.6934917217361939}} {"text": "module mod_initgrid\n use mod_param, only:pi\n use mod_types\n implicit none\n private\n public initgrid,distribute_grid,save_grid\n contains\n subroutine initgrid(n,lo,hi,gt,gr,l,drc_g,drf_g,rc_g,rf_g)\n !\n ! initializes a non-uniform grid\n !\n implicit none\n integer, parameter :: CLUSTER_TWO_END = 0, &\n CLUSTER_ONE_END = 1, &\n CLUSTER_MIDDLE = 2, &\n CLUSTER_ONE_END_R = 3\n integer , intent(in ) :: n,lo,hi,gt\n real(rp) , intent(in ) :: gr,l\n real(rp) , intent(out), dimension(1-1:) :: drc_g,drf_g,rc_g,rf_g\n real(rp) :: r0\n integer :: q\n procedure (), pointer :: gridpoint => null()\n select case(gt)\n case(CLUSTER_TWO_END)\n gridpoint => gridpoint_cluster_two_end\n case(CLUSTER_ONE_END)\n gridpoint => gridpoint_cluster_one_end\n case(CLUSTER_ONE_END_R)\n gridpoint => gridpoint_cluster_one_end_r\n case(CLUSTER_MIDDLE)\n gridpoint => gridpoint_cluster_middle\n case default\n gridpoint => gridpoint_cluster_two_end\n end select\n !\n ! step 1) determine coordinates of cell faces rf\n !\n do q=1,n\n r0 = (q-0._rp)/(1._rp*n)\n call gridpoint(gr,r0,rf_g(q))\n rf_g(q) = rf_g(q)*l\n enddo\n rf_g(0) = 0._rp\n !\n ! step 2) determine grid spacing between faces drf\n !\n do q=1,n\n drf_g(q) = rf_g(q)-rf_g(q-1)\n enddo\n drf_g(0 ) = drf_g(1)\n drf_g(n+1) = drf_g(n)\n !\n ! step 3) determine grid spacing between centers drc\n !\n do q=0,n\n drc_g(q) = .5_rp*(drf_g(q)+drf_g(q+1))\n enddo\n drc_g(n+1) = drc_g(n)\n !\n ! step 4) compute coordinates of cell centers rc and faces rf\n !\n rc_g(0) = -drc_g(0)/2._rp\n rf_g(0) = 0._rp\n do q=1,n+1\n rc_g(q) = rc_g(q-1) + drc_g(q-1)\n rf_g(q) = rf_g(q-1) + drf_g(q)\n enddo\n end subroutine initgrid\n !\n subroutine distribute_grid(lo,hi,grid_g,grid)\n implicit none\n integer :: lo,hi\n real(rp), intent(in ), dimension(1-1 :) :: grid_g\n real(rp), intent(out), dimension(lo-1:) :: grid\n grid(lo-1:hi+1) = grid_g(lo-1:hi+1)\n end subroutine distribute_grid\n !\n subroutine save_grid(fname,ng,rf_g,rc_g,drf_g,drc_g)\n implicit none\n character(len=*), intent(in) :: fname\n integer , intent(in) :: ng\n real(rp) , intent(in), dimension(1-1:) :: rf_g,rc_g,drf_g,drc_g\n integer :: iunit,q,rlen\n !\n inquire(iolength=rlen) 1._rp\n open(newunit=iunit,file=trim(fname)//'.bin',status='replace',access='direct',recl=ng*4*rlen)\n write(iunit,rec=1) rf_g(1:ng),rc_g(1:ng),drf_g(1:ng),drc_g(1:ng)\n close(iunit)\n open(newunit=iunit,status='replace',file=trim(fname)//'.out')\n do q=0,ng+1\n write(iunit,'(5E15.7)') 0._rp,rf_g(q),rc_g(q),drf_g(q),drc_g(q)\n enddo\n close(iunit)\n end subroutine save_grid\n !\n ! grid stretching functions \n ! see e.g., Fluid Flow Phenomena -- A Numerical Toolkit, by P. Orlandi\n ! Pirozzoli et al. JFM 788, 614\u2013639 (commented)\n !\n subroutine gridpoint_cluster_two_end(alpha,r0,r)\n !\n ! clustered at the two sides\n !\n implicit none\n real(rp), intent(in ) :: alpha,r0\n real(rp), intent(out) :: r\n if(alpha /= 0._rp) then\n r = 0.5_rp*(1._rp+tanh((r0-0.5_rp)*alpha)/tanh(alpha/2._rp))\n !r = 0.5_rp*(1._rp+erf( (r0-0.5_rp)*alpha)/erf( alpha/2._rp))\n else\n r = r0\n endif\n end subroutine gridpoint_cluster_two_end\n subroutine gridpoint_cluster_one_end(alpha,r0,r)\n !\n ! clustered at the lower side\n !\n implicit none\n real(rp), intent(in ) :: alpha,r0\n real(rp), intent(out) :: r\n if(alpha /= 0._rp) then\n r = 1.0_rp*(1._rp+tanh((r0-1.0_rp)*alpha)/tanh(alpha/1._rp))\n !r = 1.0_rp*(1._rp+erf( (r0-1.0_rp)*alpha)/erf( alpha/1._rp))\n else\n r = r0\n endif\n end subroutine gridpoint_cluster_one_end\n subroutine gridpoint_cluster_one_end_r(alpha,r0,r)\n !\n ! clustered at the lower side\n !\n implicit none\n real(rp), intent(in ) :: alpha,r0\n real(rp), intent(out) :: r\n if(alpha /= 0._rp) then\n r = 1._rp-1.0_rp*(1._rp+tanh((1._rp-r0-1.0_rp)*alpha)/tanh(alpha/1._rp))\n !r = 1._rp-1.0_rp*(1._rp+erf( (1._rp-r0-1.0_rp)*alpha)/erf( alpha/1._rp))\n else\n r = r0\n endif\n end subroutine gridpoint_cluster_one_end_r\n subroutine gridpoint_cluster_middle(alpha,r0,r)\n !\n ! clustered in the middle\n !\n implicit none\n real(rp), intent(in ) :: alpha,r0\n real(rp), intent(out) :: r\n if(alpha /= 0._rp) then\n if( r0 <= 0.5_rp) then \n r = 0.5_rp*(1._rp-1._rp+tanh(2._rp*alpha*(r0-0._rp))/tanh(alpha))\n !r = 0.5_rp*(1._rp-1._rp+erf( 2._rp*alpha*(r0-0._rp))/erf( alpha))\n elseif(r0 > 0.5_rp) then\n r = 0.5_rp*(1._rp+1._rp+tanh(2._rp*alpha*(r0-1._rp))/tanh(alpha))\n !r = 0.5_rp*(1._rp+1._rp+erf( 2._rp*alpha*(r0-1._rp))/erf( alpha))\n endif\n else\n r = r0\n endif\n end subroutine gridpoint_cluster_middle\nend module mod_initgrid\n", "meta": {"hexsha": "fd0b7a66e5953583e9133cdf169c0160e0c4adbb", "size": 5047, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/initgrid.f90", "max_stars_repo_name": "nazmas/SNaC", "max_stars_repo_head_hexsha": "e928adc142df5bbe1a7941907c35add6ea6f1ff0", "max_stars_repo_licenses": ["MIT"], "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/initgrid.f90", "max_issues_repo_name": "nazmas/SNaC", "max_issues_repo_head_hexsha": "e928adc142df5bbe1a7941907c35add6ea6f1ff0", "max_issues_repo_licenses": ["MIT"], "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/initgrid.f90", "max_forks_repo_name": "nazmas/SNaC", "max_forks_repo_head_hexsha": "e928adc142df5bbe1a7941907c35add6ea6f1ff0", "max_forks_repo_licenses": ["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.1543209877, "max_line_length": 96, "alphanum_fraction": 0.5950069348, "num_tokens": 1776, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916205190225, "lm_q2_score": 0.8031738034238807, "lm_q1q2_score": 0.6934535316965712}} {"text": "program quadratic\n implicit none \n real a,b,c,D,x1,x2\n a=3\n b=5\n c=1\n D=b*b-4*a*c\n x1=(-b+sqrt(D))/(2*a)\n x2=(-b-sqrt(D))/(2*a)\n print *,'X1 X2 = ',x1,x2\nend", "meta": {"hexsha": "d29031249cd9cf77f16d0f4e3faa8f3bf273579d", "size": 184, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "90and95/solveNonLinear/quadratic/simple.f90", "max_stars_repo_name": "terasakisatoshi/Fortran", "max_stars_repo_head_hexsha": "f2d7c94ad7a7efcd6545800b54674452d45a98f3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "90and95/solveNonLinear/quadratic/simple.f90", "max_issues_repo_name": "terasakisatoshi/Fortran", "max_issues_repo_head_hexsha": "f2d7c94ad7a7efcd6545800b54674452d45a98f3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "90and95/solveNonLinear/quadratic/simple.f90", "max_forks_repo_name": "terasakisatoshi/Fortran", "max_forks_repo_head_hexsha": "f2d7c94ad7a7efcd6545800b54674452d45a98f3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.7272727273, "max_line_length": 28, "alphanum_fraction": 0.4782608696, "num_tokens": 82, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741268224333, "lm_q2_score": 0.7279754607093178, "lm_q1q2_score": 0.693450588833337}} {"text": " subroutine ero_cfactor\n \n!! ~ ~ ~ PURPOSE ~ ~ ~\n!! this subroutine predicts daily soil loss caused by water erosion\n!! using the modified universal soil loss equation\n\n!! ~ ~ ~ INCOMING VARIABLES ~ ~ ~\n!! name |units |definition\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\n!! cvm(:) |none |natural log of USLE_C (the minimum value\n!! |of the USLE C factor for the land cover)\n!! hru_km(:) |km**2 |area of HRU in square kilometers\n!! peakr |m^3/s |peak runoff rate\n!! surfq(:) |mm H2O |surface runoff for the day in HRU\n!! usle_ei |100(ft-tn in)/(acre-hr)|USLE rainfall erosion index\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\n\n!! ~ ~ ~ OUTGOING VARIABLES ~ ~ ~\n!! name |units |definition\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\n!! cklsp(:) |\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\n!! ~ ~ ~ SUBROUTINES/FUNCTIONS CALLED ~ ~ ~\n!! Intrinsic: Exp\n\n!! ~ ~ ~ ~ ~ ~ END SPECIFICATIONS ~ ~ ~ ~ ~ ~\n\n use basin_module\n use hru_module, only : usle_cfac, cvm_com, ihru \n use plant_module\n use organic_mineral_mass_module\n \n implicit none\n\n integer :: j !none |HRU number\n real :: c ! |\n real :: rsd_frcov ! |fraction of cover by residue\n real :: grcov_fr ! |fraction of cover by biomass as function of lai \n real :: bio_frcov ! |fraction of cover by biomass - adjusted for canopy height\n real :: cover !kg/ha |soil cover\n integer :: max ! | ??? should this be real??\n \n j = ihru\n\n !! HRU sediment calculations\n if (bsn_cc%cfac == 0) then\n cover = pl_mass(j)%ab_gr_com%m + rsd1(j)%tot_com%m\n if (pcom(j)%npl > 0) then\n c = Exp((-.2231 - cvm_com(j)) * Exp(-.00115 * cover) + cvm_com(j))\n else\n if (cover > 1.e-4) then\n c = Exp(-.2231 * Exp(-.00115 * cover)) \n else\n c = .8\n end if\n\t end if\n else\n rsd_frcov = Exp(-bsn_prm%rsd_covco * cover)\n grcov_fr = pcom(j)%lai_sum / (pcom(j)%lai_sum + Exp(1.748 - 1.748 * pcom(j)%lai_sum))\n bio_frcov = 1. - grcov_fr * Exp(-.01 * pcom(j)%cht_mx)\n c = Max(1.e-10, rsd_frcov * bio_frcov)\n end if\n\n usle_cfac(ihru) = c\n \n return\n end subroutine ero_cfactor", "meta": {"hexsha": "d899832a149d838c18a669830f82b0ccc3b1c7d8", "size": 2639, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/data/program_analysis/multifile_multimod/mfmm_02/ero_cfactor.f90", "max_stars_repo_name": "mikiec84/delphi", "max_stars_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2018-03-03T11:57:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-16T21:19:54.000Z", "max_issues_repo_path": "tests/data/program_analysis/multifile_multimod/mfmm_02/ero_cfactor.f90", "max_issues_repo_name": "mikiec84/delphi", "max_issues_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 385, "max_issues_repo_issues_event_min_datetime": "2018-02-21T16:52:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-17T07:44:56.000Z", "max_forks_repo_path": "tests/data/program_analysis/multifile_multimod/mfmm_02/ero_cfactor.f90", "max_forks_repo_name": "mikiec84/delphi", "max_forks_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2018-03-20T01:08:11.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-29T01:04:49.000Z", "avg_line_length": 39.3880597015, "max_line_length": 98, "alphanum_fraction": 0.4501705191, "num_tokens": 846, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741308615411, "lm_q2_score": 0.7279754548076478, "lm_q1q2_score": 0.6934505861519302}} {"text": " SUBROUTINE dftcor(w,delta,a,b,endpts,corre,corim,corfac)\r\n REAL a,b,corfac,corim,corre,delta,w,endpts(8)\r\n REAL a0i,a0r,a1i,a1r,a2i,a2r,a3i,a3r,arg,c,cl,cr,s,sl,sr,t,t2,t4,\r\n *t6\r\n DOUBLE PRECISION cth,ctth,spth2,sth,sth4i,stth,th,th2,th4,tmth2,\r\n *tth4i\r\n th=w*delta\r\n if (a.ge.b.or.th.lt.0.d0.or.th.gt.3.1416d0)pause\r\n *'bad arguments to dftcor'\r\n if(abs(th).lt.5.d-2)then\r\n t=th\r\n t2=t*t\r\n t4=t2*t2\r\n t6=t4*t2\r\n corfac=1.-(11./720.)*t4+(23./15120.)*t6\r\n a0r=(-2./3.)+t2/45.+(103./15120.)*t4-(169./226800.)*t6\r\n a1r=(7./24.)-(7./180.)*t2+(5./3456.)*t4-(7./259200.)*t6\r\n a2r=(-1./6.)+t2/45.-(5./6048.)*t4+t6/64800.\r\n a3r=(1./24.)-t2/180.+(5./24192.)*t4-t6/259200.\r\n a0i=t*(2./45.+(2./105.)*t2-(8./2835.)*t4+(86./467775.)*t6)\r\n a1i=t*(7./72.-t2/168.+(11./72576.)*t4-(13./5987520.)*t6)\r\n a2i=t*(-7./90.+t2/210.-(11./90720.)*t4+(13./7484400.)*t6)\r\n a3i=t*(7./360.-t2/840.+(11./362880.)*t4-(13./29937600.)*t6)\r\n else\r\n cth=cos(th)\r\n sth=sin(th)\r\n ctth=cth**2-sth**2\r\n stth=2.d0*sth*cth\r\n th2=th*th\r\n th4=th2*th2\r\n tmth2=3.d0-th2\r\n spth2=6.d0+th2\r\n sth4i=1./(6.d0*th4)\r\n tth4i=2.d0*sth4i\r\n corfac=tth4i*spth2*(3.d0-4.d0*cth+ctth)\r\n a0r=sth4i*(-42.d0+5.d0*th2+spth2*(8.d0*cth-ctth))\r\n a0i=sth4i*(th*(-12.d0+6.d0*th2)+spth2*stth)\r\n a1r=sth4i*(14.d0*tmth2-7.d0*spth2*cth)\r\n a1i=sth4i*(30.d0*th-5.d0*spth2*sth)\r\n a2r=tth4i*(-4.d0*tmth2+2.d0*spth2*cth)\r\n a2i=tth4i*(-12.d0*th+2.d0*spth2*sth)\r\n a3r=sth4i*(2.d0*tmth2-spth2*cth)\r\n a3i=sth4i*(6.d0*th-spth2*sth)\r\n endif\r\n cl=a0r*endpts(1)+a1r*endpts(2)+a2r*endpts(3)+a3r*endpts(4)\r\n sl=a0i*endpts(1)+a1i*endpts(2)+a2i*endpts(3)+a3i*endpts(4)\r\n cr=a0r*endpts(8)+a1r*endpts(7)+a2r*endpts(6)+a3r*endpts(5)\r\n sr=-a0i*endpts(8)-a1i*endpts(7)-a2i*endpts(6)-a3i*endpts(5)\r\n arg=w*(b-a)\r\n c=cos(arg)\r\n s=sin(arg)\r\n corre=cl+c*cr-s*sr\r\n corim=sl+s*cr+c*sr\r\n return\r\n END\r\n", "meta": {"hexsha": "382dae1d03812d73baa3c7eadeb5916611ecaa55", "size": 2138, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/dftcor.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/dftcor.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/dftcor.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": 38.1785714286, "max_line_length": 72, "alphanum_fraction": 0.5233863424, "num_tokens": 1056, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741308615412, "lm_q2_score": 0.7279754430043072, "lm_q1q2_score": 0.6934505749083734}} {"text": "\tsubroutine mkbutter3(delt,df,numah,nfilt,fmin,fmax,zfilt)\nc band-pass filter fmin to fmax\nc generates 3-pole butterworth filter, BUT: zero phase\nc filters both ways: Multiplies filter by its complex congjgate\nC output is:\nC\tzfilt complex freq-domain transfer function\nC\tdf\tfrequency spacing\nC\tnfilt\t=2^l, number of points in zfilt\nc GAA \n\tcomplex zfilt(*)\n\n\tcomplex z0, zone\n\tdata si/0.8660254/,co/0.5/\nc find pwr of two .ge.numah\n\tl = 1\n1\tcontinue\n\t l = l * 2\n\t if (l.ge.numah) go to 2\n\t go to 1\n2\tcontinue\nc make sure at least more than 2x points than data\n\tnfilt = l * 2\n\tdf = 1./(float(nfilt-1)*delt)\n\n\tdfn = df/fmax\n\tdfn2 =df/fmin\n\tnfd2 = nfilt/2\n\tfn = dfn\n\tfn2 = dfn2\n\tzone = cmplx(1.,0.)\n\tdo 10 i=2,nfd2\nc low-pass stages\n\t z0 = cmplx(1.,fn)\n\t z0 = z0*cmplx(co,fn + si)*cmplx(co,fn - si)\n\t zfilt(i) = zone/(z0*conjg(z0))\nc modify for high-pass, also 2x 3pole\n\t z0 = cmplx(1.,fn2)\n\t z0 = z0*cmplx(co,fn2 + si)*cmplx(co,fn2 - si)\n\t zfilt(i) = zfilt(i)*cmplx(fn2**6,0.)/(z0*conjg(z0))\n\t zfilt(nfilt-i+2) = zfilt(i)\n\t fn = dfn + fn\n\t fn2 = dfn2 + fn2\n10\tcontinue\n\tzfilt(1) = cmplx(0.,0.)\n\tzfilt(nfd2 + 1) = cmplx(0.,0.)\n\treturn\n\tend\n", "meta": {"hexsha": "65cc51f3c8f23e14a16c05888b535c62371a5833", "size": 1179, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "bin/db/dbdepest/mkbutter3.f", "max_stars_repo_name": "jreyes1108/antelope_contrib", "max_stars_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_stars_repo_licenses": ["BSD-2-Clause", "MIT"], "max_stars_count": 30, "max_stars_repo_stars_event_min_datetime": "2015-02-20T21:44:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-27T02:53:14.000Z", "max_issues_repo_path": "bin/db/dbdepest/mkbutter3.f", "max_issues_repo_name": "jreyes1108/antelope_contrib", "max_issues_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_issues_repo_licenses": ["BSD-2-Clause", "MIT"], "max_issues_count": 14, "max_issues_repo_issues_event_min_datetime": "2015-07-07T19:17:24.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-19T19:18:53.000Z", "max_forks_repo_path": "bin/db/dbdepest/mkbutter3.f", "max_forks_repo_name": "jreyes1108/antelope_contrib", "max_forks_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_forks_repo_licenses": ["BSD-2-Clause", "MIT"], "max_forks_count": 46, "max_forks_repo_forks_event_min_datetime": "2015-02-06T16:22:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T11:46:37.000Z", "avg_line_length": 24.5625, "max_line_length": 64, "alphanum_fraction": 0.6403731976, "num_tokens": 479, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009596336303, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6933068024886219}} {"text": "C$Procedure M2EUL ( Matrix to Euler angles )\n \n SUBROUTINE M2EUL ( R, AXIS3, AXIS2, AXIS1,\n . ANGLE3, ANGLE2, ANGLE1 )\n \nC$ Abstract\nC\nC Factor a rotation matrix as a product of three rotations about\nC specified coordinate axes.\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 ROTATION\nC\nC$ Keywords\nC\nC ANGLE\nC MATRIX\nC ROTATION\nC TRANSFORMATION\nC\nC$ Declarations\n \n DOUBLE PRECISION R ( 3, 3 )\n \n INTEGER AXIS3\n INTEGER AXIS2\n INTEGER AXIS1\n \n DOUBLE PRECISION ANGLE3\n DOUBLE PRECISION ANGLE2\n DOUBLE PRECISION ANGLE1\n \nC$ Brief_I/O\nC\nC Variable I/O Description\nC -------- --- --------------------------------------------------\nC R I A rotation matrix to be factored.\nC AXIS3,\nC AXIS2,\nC AXIS1 I Numbers of third, second, and first rotation axes.\nC ANGLE3,\nC ANGLE2,\nC ANGLE1 O Third, second, and first Euler angles, in radians.\nC\nC$ Detailed_Input\nC\nC R is a 3x3 rotation matrix that is to be factored as\nC a product of three rotations about a specified\nC coordinate axes. The angles of these rotations are\nC called `Euler angles'.\nC\nC AXIS3,\nC AXIS2,\nC AXIS1 are the indices of the rotation axes of the\nC `factor' rotations, whose product is R. R is\nC factored as\nC\nC R = [ ANGLE3 ] [ ANGLE2 ] [ ANGLE1 ] .\nC AXIS3 AXIS2 AXIS1\nC\nC The axis numbers must belong to the set {1, 2, 3}.\nC The second axis number MUST differ from the first\nC and third axis numbers.\nC\nC See the $ Particulars section below for details\nC concerning this notation.\nC\nC$ Detailed_Output\nC\nC ANGLE3,\nC ANGLE2,\nC ANGLE1 are the Euler angles corresponding to the matrix\nC R and the axes specified by AXIS3, AXIS2, and\nC AXIS1. These angles satisfy the equality\nC\nC R = [ ANGLE3 ] [ ANGLE2 ] [ ANGLE1 ]\nC AXIS3 AXIS2 AXIS1\nC\nC\nC See the $ Particulars section below for details\nC concerning this notation.\nC\nC The range of ANGLE3 and ANGLE1 is (-pi, pi].\nC\nC The range of ANGLE2 depends on the exact set of\nC axes used for the factorization. For\nC factorizations in which the first and third axes\nC are the same,\nC\nC R = [r] [s] [t] ,\nC a b a\nC\nC the range of ANGLE2 is [0, pi].\nC\nC\nC For factorizations in which the first and third\nC axes are different,\nC\nC R = [r] [s] [t] ,\nC a b c\nC\nC the range of ANGLE2 is [-pi/2, pi/2].\nC\nC For rotations such that ANGLE3 and ANGLE1 are not\nC uniquely determined, ANGLE3 will always be set to\nC zero; ANGLE1 is then uniquely determined.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC 1) If any of AXIS3, AXIS2, or AXIS1 do not have values in\nC\nC { 1, 2, 3 },\nC\nC then the error SPICE(BADAXISNUMBERS) is signaled.\nC\nC 2) An arbitrary rotation matrix cannot be expressed using\nC a sequence of Euler angles unless the second rotation axis\nC differs from the other two. If AXIS2 is equal to AXIS3 or\nC AXIS1, then then error SPICE(BADAXISNUMBERS) is signaled.\nC\nC 3) If the input matrix R is not a rotation matrix, the error\nC SPICE(NOTAROTATION) is signaled.\nC\nC 4) If ANGLE3 and ANGLE1 are not uniquely determined, ANGLE3\nC is set to zero, and ANGLE1 is determined.\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC A word about notation: the symbol\nC\nC [ x ]\nC i\nC\nC indicates a coordinate system rotation of x radians about the\nC ith coordinate axis. To be specific, the symbol\nC\nC [ x ]\nC 1\nC\nC indicates a coordinate system rotation of x radians about the\nC first, or x-, axis; the corresponding matrix is\nC\nC +- -+\nC | 1 0 0 |\nC | |\nC | 0 cos(x) sin(x) |.\nC | |\nC | 0 -sin(x) cos(x) |\nC +- -+\nC\nC Remember, this is a COORDINATE SYSTEM rotation by x radians; this\nC matrix, when applied to a vector, rotates the vector by -x\nC radians, not x radians. Applying the matrix to a vector yields\nC the vector's representation relative to the rotated coordinate\nC system.\nC\nC The analogous rotation about the second, or y-, axis is\nC represented by\nC\nC [ x ]\nC 2\nC\nC which symbolizes the matrix\nC\nC +- -+\nC | cos(x) 0 -sin(x) |\nC | |\nC | 0 1 0 |,\nC | |\nC | sin(x) 0 cos(x) |\nC +- -+\nC\nC and the analogous rotation about the third, or z-, axis is\nC represented by\nC\nC [ x ]\nC 3\nC\nC which symbolizes the matrix\nC\nC +- -+\nC | cos(x) sin(x) 0 |\nC | |\nC | -sin(x) cos(x) 0 |.\nC | |\nC | 0 0 1 |\nC +- -+\nC\nC\nC The input matrix is assumed to be the product of three\nC rotation matrices, each one of the form\nC\nC +- -+\nC | 1 0 0 |\nC | |\nC | 0 cos(r) sin(r) | (rotation of r radians about the\nC | | x-axis),\nC | 0 -sin(r) cos(r) |\nC +- -+\nC\nC\nC +- -+\nC | cos(s) 0 -sin(s) |\nC | |\nC | 0 1 0 | (rotation of s radians about the\nC | | y-axis),\nC | sin(s) 0 cos(s) |\nC +- -+\nC\nC or\nC\nC +- -+\nC | cos(t) sin(t) 0 |\nC | |\nC | -sin(t) cos(t) 0 | (rotation of t radians about the\nC | | z-axis),\nC | 0 0 1 |\nC +- -+\nC\nC where the second rotation axis is not equal to the first or\nC third. Any rotation matrix can be factored as a sequence of\nC three such rotations, provided that this last criterion is met.\nC\nC This routine is related to the SPICELIB routine EUL2M, which\nC produces a rotation matrix, given a sequence of Euler angles.\nC This routine is a `right inverse' of EUL2M: the sequence of\nC calls\nC\nC CALL M2EUL ( R, AXIS3, AXIS2, AXIS1,\nC . ANGLE3, ANGLE2, ANGLE1 )\nC\nC CALL EUL2M ( ANGLE3, ANGLE2, ANGLE1,\nC . AXIS3, AXIS2, AXIS1, R )\nC\nC preserves R, except for round-off error.\nC\nC\nC On the other hand, the sequence of calls\nC\nC CALL EUL2M ( ANGLE3, ANGLE2, ANGLE1,\nC . AXIS3, AXIS2, AXIS1, R )\nC\nC CALL M2EUL ( R, AXIS3, AXIS2, AXIS1,\nC . ANGLE3, ANGLE2, ANGLE1 )\nC\nC\nC preserve ANGLE3, ANGLE2, and ANGLE1 only if these angles start\nC out in the ranges that M2EUL's outputs are restricted to.\nC\nC$ Examples\nC\nC 1) Conversion of instrument pointing from a matrix representation\nC to Euler angles:\nC\nC Suppose we want to find camera pointing in alpha, delta, and\nC kappa, given the inertial-to-camera coordinate transformation\nC\nC\nC +- -+\nC | 0.49127379678135830 0.50872620321864170 0.70699908539882417 |\nC | |\nC | -0.50872620321864193 -0.49127379678135802 0.70699908539882428 |\nC | |\nC | 0.70699908539882406 -0.70699908539882439 0.01745240643728360 |\nC +- -+\nC\nC\nC We want to find angles alpha, delta, kappa such that\nC\nC TICAM = [ kappa ] [ pi/2 - delta ] [ pi/2 + alpha ] .\nC 3 1 3\nC\nC We can use the following small program to do this computation:\nC\nC\nC PROGRAM EX1\nC IMPLICIT NONE\nC\nC DOUBLE PRECISION DPR\nC DOUBLE PRECISION HALFPI\nC DOUBLE PRECISION TWOPI\nC\nC DOUBLE PRECISION ALPHA\nC DOUBLE PRECISION ANG1\nC DOUBLE PRECISION ANG2\nC DOUBLE PRECISION DELTA\nC DOUBLE PRECISION KAPPA\nC DOUBLE PRECISION TICAM ( 3, 3 )\nC\nC\nC DATA TICAM / 0.49127379678135830D0,\nC . -0.50872620321864193D0,\nC . 0.70699908539882406D0,\nC . 0.50872620321864170D0,\nC . -0.49127379678135802D0,\nC . -0.70699908539882439D0,\nC . 0.70699908539882417D0,\nC . 0.70699908539882428D0,\nC . 0.01745240643728360D0 /\nC\nC\nC CALL M2EUL ( TICAM, 3, 1, 3, KAPPA, ANG2, ANG1 )\nC\nC DELTA = HALFPI() - ANG2\nC ALPHA = ANG1 - HALFPI()\nC\nC IF ( KAPPA .LT. 0.D0 ) THEN\nC KAPPA = KAPPA + TWOPI()\nC END IF\nC\nC IF ( ALPHA .LT. 0.D0 ) THEN\nC ALPHA = ALPHA + TWOPI()\nC END IF\nC\nC WRITE (*,'(1X,A,F24.14)') 'Alpha (deg): ', DPR() * ALPHA\nC WRITE (*,'(1X,A,F24.14)') 'Delta (deg): ', DPR() * DELTA\nC WRITE (*,'(1X,A,F24.14)') 'Kappa (deg): ', DPR() * KAPPA\nC\nC END\nC\nC\nC The program's output should be something like\nC\nC Alpha (deg): 315.00000000000000\nC Delta (deg): 1.00000000000000\nC Kappa (deg): 45.00000000000000\nC\nC possibly formatted a little differently, or degraded slightly\nC by round-off.\nC\nC\nC 2) Conversion of instrument pointing angles from a non-J2000,\nC not necessarily inertial frame to J2000-relative RA, Dec,\nC and Twist.\nC\nC Suppose that we have pointing for some instrument expressed as\nC\nC [ gamma ] [ beta ] [ alpha ]\nC 3 2 3\nC\nC with respect to some coordinate system S. For example, S\nC could be a spacecraft-fixed system.\nC\nC We will suppose that the transformation from J2000\nC coordinates to system S coordinates is given by the rotation\nC matrix J2S.\nC\nC The rows of J2S are the unit basis vectors of system S, given\nC in J2000 coordinates.\nC\nC We want to express the pointing with respect to the J2000\nC system as the sequence of rotations\nC\nC [ kappa ] [ pi/2 - delta ] [ pi/2 + alpha ] .\nC 3 1 3\nC\nC First, we use subroutine EUL2M to form the transformation\nC from system S to instrument coordinates S2INST.\nC\nC CALL EUL2M ( GAMMA, BETA, ALPHA, 3, 2, 3, S2INST )\nC\nC Next, we form the transformation from J2000 to instrument\nC coordinates J2INST.\nC\nC CALL MXM ( S2INST, J2S, J2INST )\nC\nC Finally, we express J2INST using the desired Euler angles, as\nC in the first example:\nC\nC CALL M2EUL ( J2INST, 3, 1, 3, TWIST, ANG2, ANG3 )\nC\nC RA = ANG3 - HALFPI()\nC DEC = HALFPI() - ANG2\nC\nC If we wish to make sure that RA, DEC, and TWIST are in\nC the ranges [0, 2pi), [-pi/2, pi/2], and [0, 2pi)\nC respectively, we may add the code\nC\nC IF ( RA .LT. 0.D0 ) THEN\nC RA = RA + TWOPI()\nC END IF\nC\nC IF ( TWIST .LT. 0.D0 ) THEN\nC TWIST = TWIST + TWOPI()\nC END IF\nC\nC Note that DEC is already in the correct range, since ANG2\nC is in the range [0, pi] when the first and third input axes\nC are equal.\nC\nC Now RA, DEC, and TWIST express the instrument pointing\nC as RA, Dec, and Twist, relative to the J2000 system.\nC\nC A warning note: more than one definition of RA, Dec, and\nC Twist is extant. Before using this example in an application,\nC check that the definition given here is consistent with that\nC used in your application.\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC N.J. Bachman (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 1.2.1, 21-DEC-2006 (NJB)\nC\nC Error corrected in header example: input matrix\nC previously did not match shown outputs. Offending\nC example now includes complete program.\nC\nC- SPICELIB Version 1.2.0, 15-OCT-2005 (NJB)\nC\nC Updated to remove non-standard use of duplicate arguments\nC in MXM and MTXM calls. A short error message cited in\nC the Exceptions section of the header failed to match\nC the actual short message used; this has been corrected.\nC\nC- SPICELIB Version 1.1.2, 13-OCT-2004 (NJB)\nC\nC Fixed header typo.\nC\nC- SPICELIB Version 1.1.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.1.0, 02-NOV-1990 (NJB)\nC\nC Header upgraded to describe notation in more detail. Argument\nC names were changed to describe the use of the arguments more\nC accurately. No change in functionality was made; the operation\nC of the routine is identical to that of the previous version.\nC\nC- SPICELIB Version 1.0.0, 03-SEP-1990 (NJB)\nC\nC-&\n \nC$ Index_Entries\nC\nC matrix to euler angles\nC\nC-&\n \n \n \nC$ Revisions\nC\nC- SPICELIB Version 1.2.0, 26-AUG-2005 (NJB)\nC\nC Updated to remove non-standard use of duplicate arguments\nC in MXM and MTXM calls. A short error message cited in\nC the Exceptions section of the header failed to match\nC the actual short message used; this has been corrected.\nC\nC- SPICELIB Version 1.1.0, 02-NOV-1990 (NJB)\nC\nC Argument names were changed to describe the use of the\nC arguments more accurately. The axis and angle numbers\nC now decrease, rather than increase, from left to right.\nC The current names reflect the order of operator application\nC when the Euler angle rotations are applied to a vector: the\nC rightmost matrix\nC\nC [ ANGLE1 ]\nC AXIS1\nC\nC is applied to the vector first, followed by\nC\nC [ ANGLE2 ]\nC AXIS2\nC\nC and then\nC\nC [ ANGLE3 ]\nC AXIS3\nC\nC Previously, the names reflected the order in which the Euler\nC angle matrices appear on the page, from left to right. This\nC naming convention was found to be a bit obtuse by a various\nC users.\nC\nC No change in functionality was made; the operation of the\nC routine is identical to that of the previous version.\nC\nC Also, the header was upgraded to describe the notation in more\nC detail. The symbol\nC\nC [ x ]\nC i\nC\nC is explained at mind-numbing length. An example was added\nC that shows a specific set of inputs and the resulting output\nC matrix.\nC\nC The angle sequence notation was changed to be consistent with\nC Rotations required reading.\nC\nC 1-2-3 and a-b-c\nC\nC have been changed to\nC\nC 3-2-1 and c-b-a.\nC\nC Also, one `)' was changed to a `}'.\nC\nC The phrase `first and third' was changed to `first or third'\nC in the $ Particulars section, where the criterion for the\nC existence of an Euler angle factorization is stated.\nC\nC-&\n \n \n \nC\nC SPICELIB functions\nC\n LOGICAL ISROT\n LOGICAL RETURN\n \nC\nC Local parameters\nC\n \nC\nC NTOL and DETOL are used to determine whether R is a rotation\nC matrix.\nC\nC NTOL is the tolerance for the norms of the columns of R.\nC\nC DTOL is the tolerance for the determinant of a matrix whose\nC columns are the unitized columns of R.\nC\nC\n DOUBLE PRECISION NTOL\n PARAMETER ( NTOL = 0.1D0 )\n \n DOUBLE PRECISION DTOL\n PARAMETER ( DTOL = 0.1D0 )\n \n \nC\nC Local variables\nC\n DOUBLE PRECISION CHANGE ( 3, 3 )\n DOUBLE PRECISION SIGN\n DOUBLE PRECISION TMPMAT ( 3, 3 )\n DOUBLE PRECISION TMPROT ( 3, 3 )\n \n INTEGER C\n INTEGER I\n INTEGER NEXT ( 3 )\n \n LOGICAL DEGEN\n \nC\nC Saved variables\nC\n SAVE NEXT\n \nC\nC Initial values\nC\n DATA NEXT / 2, 3, 1 /\n \n \nC\nC Standard SPICE error handling.\nC\n IF ( RETURN () ) THEN\n RETURN\n ELSE\n CALL CHKIN ( 'M2EUL' )\n END IF\n \nC\nC The first order of business is to screen out the goofy cases.\nC\nC Make sure the axis numbers are all right: They must belong to\nC the set {1, 2, 3}...\nC\n IF ( ( ( AXIS3 .LT. 1 ) .OR. ( AXIS3 .GT. 3 ) )\n . .OR. ( ( AXIS2 .LT. 1 ) .OR. ( AXIS2 .GT. 3 ) )\n . .OR. ( ( AXIS1 .LT. 1 ) .OR. ( AXIS1 .GT. 3 ) ) ) THEN\n \n CALL SETMSG ( 'Axis numbers are #, #, #. ' )\n CALL ERRINT ( '#', AXIS3 )\n CALL ERRINT ( '#', AXIS2 )\n CALL ERRINT ( '#', AXIS1 )\n CALL SIGERR ( 'SPICE(BADAXISNUMBERS)' )\n CALL CHKOUT ( 'M2EUL' )\n RETURN\n \nC\nC ...and the second axis number must differ from its neighbors.\nC\n ELSE IF ( ( AXIS3 .EQ. AXIS2 ) .OR. ( AXIS1 .EQ. AXIS2 ) ) THEN\n \n CALL SETMSG ( 'Middle axis matches neighbor: # # #.' )\n CALL ERRINT ( '#', AXIS3 )\n CALL ERRINT ( '#', AXIS2 )\n CALL ERRINT ( '#', AXIS1 )\n CALL SIGERR ( 'SPICE(BADAXISNUMBERS)' )\n CALL CHKOUT ( 'M2EUL' )\n RETURN\n \nC\nC R must be a rotation matrix, or we may as well forget it.\nC\n ELSE IF ( .NOT. ISROT ( R, NTOL, DTOL ) ) THEN\n \n CALL SETMSG ( 'Input matrix is not a rotation.' )\n CALL SIGERR ( 'SPICE(NOTAROTATION)' )\n CALL CHKOUT ( 'M2EUL' )\n RETURN\n \n END IF\n \n \nC\nC AXIS3, AXIS2, AXIS1 and R have passed their tests at this\nC point. We take the liberty of working with TMPROT, a version\nC of R that has unitized columns.\nC\n DO I = 1, 3\n CALL VHAT ( R(1,I), TMPROT(1,I) )\n END DO\n \nC\nC We now proceed to recover the promised Euler angles from\nC TMPROT.\nC\nC The ideas behind our method are explained in excruciating\nC detail in the ROTATION required reading, so we'll be terse.\nC Nonetheless, a word of explanation is in order.\nC\nC The sequence of rotation axes used for the factorization\nC belongs to one of two categories: a-b-a or c-b-a. We\nC wish to handle each of these cases in one shot, rather than\nC using different formulas for each sequence to recover the\nC Euler angles.\nC\nC What we're going to do is use the Euler angle formula for the\nC 3-1-3 factorization for all of the a-b-a sequences, and the\nC formula for the 3-2-1 factorization for all of the c-b-a\nC sequences.\nC\nC How can we get away with this? The Euler angle formulas for\nC each factorization are different!\nC\nC Our trick is to apply a change-of-basis transformation to the\nC input matrix R. For the a-b-a factorizations, we choose a new\nC basis such that a rotation of ANGLE3 radians about the basis\nC vector indexed by AXIS3 becomes a rotation of ANGLE3 radians\nC about the third coordinate axis, and such that a rotation of\nC ANGLE2 radians about the basis vector indexed by AXIS2 becomes\nC a rotation of ANGLE2 radians about the first coordinate axis.\nC So R can be factored as a 3-1-3 rotation relative to the new\nC basis, and the Euler angles we obtain are the exact ones we\nC require.\nC\nC The c-b-a factorizations can be handled in an analogous\nC fashion. We transform R to a basis where the original axis\nC sequence becomes a 3-2-1 sequence. In some cases, the angles\nC we obtain will be the negatives of the angles we require. This\nC will happen if and only if the ordered basis (here the e's are\nC the standard basis vectors)\nC\nC { e e e }\nC AXIS3 AXIS2 AXIS1\nC\nC is not right-handed. An easy test for this condition is that\nC AXIS2 is not the successor of AXIS3, where the ordering is\nC cyclic.\nC\n \n \n IF ( AXIS3 .EQ. AXIS1 ) THEN\n \nC\nC The axis order is a-b-a. We're going to find a matrix CHANGE\nC such that\nC\nC T\nC CHANGE R CHANGE\nC\nC gives us R in the a useful basis, that is, a basis in which\nC our original a-b-a rotation is a 3-1-3 rotation, but where the\nC rotation angles are unchanged. To achieve this pleasant\nC simplification, we set column 3 of CHANGE to to e(AXIS3),\nC column 1 of CHANGE to e(AXIS2), and column 2 of CHANGE to\nC\nC (+/-) e(C),\nC\nC (C is the remaining index) depending on whether\nC AXIS3-AXIS2-C is a right-handed sequence of axes: if it\nC is, the sign is positive. (Here e(1), e(2), e(3) are the\nC standard basis vectors.)\nC\nC Determine the sign of our third basis vector, so that we can\nC ensure that our new basis is right-handed. The variable NEXT\nC is just a little mapping that takes 1 to 2, 2 to 3, and 3 to\nC 1.\nC\n IF ( AXIS2 .EQ. NEXT(AXIS3) ) THEN\n SIGN = 1.D0\n ELSE\n SIGN = -1.D0\n END IF\n \nC\nC Since the axis indices sum to 6,\nC\n C = 6 - AXIS3 - AXIS2\n \nC\nC Set up the entries of CHANGE:\nC\n CALL CLEARD ( 9, CHANGE )\n \n CHANGE ( AXIS3, 3 ) = 1.D0\n CHANGE ( AXIS2, 1 ) = 1.D0\n CHANGE ( C, 2 ) = SIGN * 1.D0\n \nC\nC Transform TMPROT.\nC\n CALL MXM ( TMPROT, CHANGE, TMPMAT )\n CALL MTXM ( CHANGE, TMPMAT, TMPROT )\n \nC\nC Now we're ready to find the Euler angles, using a\nC 3-1-3 factorization. In general, the matrix product\nC\nC [ a1 ] [ a2 ] [ a3 ]\nC 3 1 3\nC\nC has the form\nC\nC +- -+\nC | cos(a1)cos(a3) cos(a1)sin(a3) sin(a1)sin(a2) |\nC | -sin(a1)cos(a2)sin(a3) +sin(a1)cos(a2)cos(a3) |\nC | |\nC | -sin(a1)cos(a3) -sin(a1)sin(a3) cos(a1)sin(a2) |\nC | -cos(a1)cos(a2)sin(a3) +cos(a1)cos(a2)cos(a3) |\nC | |\nC | sin(a2)sin(a3) -sin(a2)cos(a3) cos(a2) |\nC +- -+\nC\nC\nC but if a2 is 0 or pi, the product matrix reduces to\nC\nC\nC +- -+\nC | cos(a1)cos(a3) cos(a1)sin(a3) 0 |\nC | -sin(a1)cos(a2)sin(a3) +sin(a1)cos(a2)cos(a3) |\nC | |\nC | -sin(a1)cos(a3) -sin(a1)sin(a3) 0 |\nC | -cos(a1)cos(a2)sin(a3) +cos(a1)cos(a2)cos(a3) |\nC | |\nC | 0 0 cos(a2) |\nC +- -+\nC\nC\nC In this case, a1 and a3 are not uniquely determined. If we\nC arbitrarily set a1 to zero, we arrive at the matrix\nC\nC +- -+\nC | cos(a3) sin(a3) 0 |\nC | -cos(a2)sin(a3) cos(a2)cos(a3) 0 |\nC | 0 0 cos(a2) |\nC +- -+\nC\nC We take care of this case first. We test three conditions\nC that are mathematically equivalent, but may not be satisfied\nC simultaneously because of round-off:\nC\nC\n DEGEN = ( ( TMPROT(1,3) .EQ. 0.D0 )\n . .AND. ( TMPROT(2,3) .EQ. 0.D0 ) )\n . .OR. ( ( TMPROT(3,1) .EQ. 0.D0 )\n . .AND. ( TMPROT(3,2) .EQ. 0.D0 ) )\n . .OR. ( ABS( TMPROT(3,3) ) .EQ. 1.D0 )\n \n \nC\nC In the following block of code, we make use of the fact that\nC\nC SIN ( ANGLE2 ) > 0\nC -\nC in choosing the signs of the ATAN2 arguments correctly. Note\nC that ATAN2(x,y) = -ATAN2(-x,-y).\nC\nC\n IF ( DEGEN ) THEN\n \n ANGLE3 = 0.D0\n ANGLE2 = ACOS ( TMPROT(3,3) )\n ANGLE1 = ATAN2 ( TMPROT(1,2), TMPROT(1,1) )\n \n ELSE\nC\nC The normal case.\nC\n ANGLE3 = ATAN2 ( TMPROT(1,3), TMPROT(2,3) )\n ANGLE2 = ACOS ( TMPROT(3,3) )\n ANGLE1 = ATAN2 ( TMPROT(3,1), -TMPROT(3,2) )\n \n END IF\n \n \n \n ELSE\n \nC\nC The axis order is c-b-a. We're going to find a matrix CHANGE\nC such that\nC\nC T\nC CHANGE R CHANGE\nC\nC gives us R in the a useful basis, that is, a basis in which\nC our original c-b-a rotation is a 3-2-1 rotation, but where the\nC rotation angles are unchanged, or at worst negated. To\nC achieve this pleasant simplification, we set column 1 of\nC CHANGE to to e(AXIS3), column 2 of CHANGE to e(AXIS2), and\nC column 3 of CHANGE to\nC\nC (+/-) e(AXIS1),\nC\nC depending on whether AXIS3-AXIS2-AXIS1 is a right-handed\nC sequence of axes: if it is, the sign is positive. (Here\nC e(1), e(2), e(3) are the standard basis vectors.)\nC\nC We must be cautious here, because if AXIS3-AXIS2-AXIS1 is a\nC right-handed sequence of axes, all of the rotation angles will\nC be the same in our new basis, but if it's a left-handed\nC sequence, the third angle will be negated. Let's get this\nC straightened out right now. The variable NEXT is just a\nC little mapping that takes 1 to 2, 2 to 3, and 3 to 1.\nC\n IF ( AXIS2 .EQ. NEXT(AXIS3) ) THEN\n SIGN = 1.D0\n ELSE\n SIGN = -1.D0\n END IF\n \nC\nC Set up the entries of CHANGE:\nC\n CALL CLEARD ( 9, CHANGE )\n \n CHANGE ( AXIS3, 1 ) = 1.D0\n CHANGE ( AXIS2, 2 ) = 1.D0\n CHANGE ( AXIS1, 3 ) = SIGN * 1.D0\n \nC\nC Transform TMPROT.\nC\n CALL MXM ( TMPROT, CHANGE, TMPMAT )\n CALL MTXM ( CHANGE, TMPMAT, TMPROT )\n \nC\nC Now we're ready to find the Euler angles, using a\nC 3-2-1 factorization. In general, the matrix product\nC\nC [ a1 ] [ a2 ] [ a3 ]\nC 1 2 3\nC\nC has the form\nC\nC\nC +- -+\nC | cos(a2)cos(a3) cos(a2)sin(a3) -sin(a2) |\nC | |\nC | -cos(a1)sin(a3) cos(a1)cos(a3) sin(a1)cos(a2) |\nC | +sin(a1)sin(a2)cos(a3) +sin(a1)sin(a2)sin(a3) |\nC | |\nC | sin(a1)sin(a3) -sin(a1)cos(a3) cos(a1)cos(a2) |\nC | +cos(a1)sin(a2)cos(a3) +cos(a1)sin(a2)sin(a3) |\nC +- -+\nC\nC\nC but if a2 is -pi/2 or pi/2, the product matrix reduces to\nC\nC\nC +- -+\nC | 0 0 -sin(a2) |\nC | |\nC | -cos(a1)sin(a3) cos(a1)cos(a3) 0 |\nC | +sin(a1)sin(a2)cos(a3) +sin(a1)sin(a2)sin(a3) |\nC | |\nC | sin(a1)sin(a3) -sin(a1)cos(a3) 0 |\nC | +cos(a1)sin(a2)cos(a3) +cos(a1)sin(a2)sin(a3) |\nC +- -+\nC\nC\nC In this case, a1 and a3 are not uniquely determined. If we\nC arbitrarily set a1 to zero, we arrive at the matrix\nC\nC +- -+\nC | 0 0 -sin(a2) |\nC | -sin(a3) cos(a3) 0 |,\nC | sin(a2)cos(a3) sin(a2)sin(a3) 0 |\nC +- -+\nC\nC\nC We take care of this case first. We test three conditions\nC that are mathematically equivalent, but may not be satisfied\nC simultaneously because of round-off:\nC\nC\n DEGEN = ( ( TMPROT(1,1) .EQ. 0.D0 )\n . .AND. ( TMPROT(1,2) .EQ. 0.D0 ) )\n . .OR. ( ( TMPROT(2,3) .EQ. 0.D0 )\n . .AND. ( TMPROT(3,3) .EQ. 0.D0 ) )\n . .OR. ( ABS( TMPROT(1,3) ) .EQ. 1.D0 )\n \n \nC\nC In the following block of code, we make use of the fact that\nC\nC COS ( ANGLE2 ) > 0\nC -\nC in choosing the signs of the ATAN2 arguments correctly. Note\nC that ATAN2(x,y) = -ATAN2(-x,-y).\nC\nC\n IF ( DEGEN ) THEN\n \n ANGLE3 = 0.D0\n ANGLE2 = ASIN ( -TMPROT(1,3) )\n ANGLE1 = SIGN * ATAN2 ( -TMPROT(2,1), TMPROT(2,2) )\n \n ELSE\nC\nC The normal case.\nC\n ANGLE3 = ATAN2 ( TMPROT(2,3), TMPROT(3,3) )\n ANGLE2 = ASIN ( -TMPROT(1,3) )\n ANGLE1 = SIGN * ATAN2 ( TMPROT(1,2), TMPROT(1,1) )\n \n END IF\n \n \n END IF\n \n CALL CHKOUT ( 'M2EUL' )\n RETURN\n END\n", "meta": {"hexsha": "b74441da40e1aa55cf043ca7df3aa833122cc078", "size": 33082, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/m2eul.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/m2eul.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/m2eul.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": 33.3487903226, "max_line_length": 72, "alphanum_fraction": 0.5044737319, "num_tokens": 9402, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009480320036, "lm_q2_score": 0.7577943822145997, "lm_q1q2_score": 0.6933067987014637}} {"text": "module airfoil_bl_growth\n !! Calculates the boundary-layer growth over an elliptical airfoil assuming a non-viscous fluid. For these geometries, a potential-flow closed-form solution can be obtained. We assume that the boundary layer growth begins at a stagnation point. \n\n use precision\n use constants, only : PI\n \n implicit none\n\n real :: tau = 0.0\n !! Thickness ratio\n integer :: nx = 0\n !! Number of elements along the airfoil\n logical :: useMichelsCriterion, useFixedCriterion\n !! Criterion for handling boundary layer transition\n real :: xTrans = 0.0\n !! Location of transition criterion (used if tc == 'F')\n real :: Re = 0.0\n !! Reynolds number\n \n real :: xx(100)\n !! Domain coordinates of the boundary layer along the airfoil\n real :: yy(50)\n !! Range coordinates of the boundary layer along the airfoil\n real :: vgrad(100), theta(100) \n \ncontains\n\n subroutine calc_bl_growth(thicknessRatio, numElements, transitionCriterion, reynoldsNumber, transitionLocation)\n !! Calculates boundary layer growth on an airfoil (modeled as an ellipse), beginning at a stagnation point. Uses Thwaite's method for the laminar flow region, Michel's method to correct transition, and Head's method for the turbulent flow region.\n \n real, intent(in) :: thicknessRatio\n !! Airfoil thickness ratio\n integer, intent(in) :: numElements\n !! Number of desired elements along the airfoil\n character, intent(in) :: transitionCriterion\n !! Boundary layer transition criterion, allowable: 'M' (Michels Criterion) or 'F' (Fixed Location)\n real, intent(in) :: reynoldsNumber\n !! Reynolds number (reference length), /(Re_L/)\n real, optional, intent(in) :: transitionLocation\n !! Boundary layer transition location along the airfoil (only used if transitionCriterion == 'F')\n\n character(len=256) :: err_s\n \n tau = thicknessRatio\n nx = numElements\n if (transitionCriterion == 'F') then\n useFixedCriterion = .true.\n else if (transitionCriterion == 'M') then\n useMichelsCriterion = .true.\n else\n err_s = \"Argument Error - Transition criterion must be either 'F' (fixed location) or 'M' (Michels Criterion).\"\n call add_error_message(err_s)\n call print_error_list_to_shell()\n call terminate_with_failure()\n end if\n\n re = reynoldsNumber\n xTrans = transitionLocation\n \n call bl_growth()\n \n end subroutine calc_bl_growth\n\n subroutine bl_growth()\n\n real :: dth2ve6, dx, dy\n real :: H, L, fact, cf, lambda\n real :: x1, x2, x3, v1, v2, v3\n real :: Rex, Ret, RetMax\n\n integer :: i\n \n ! Calculate the domain coordinates along the airfoil, xx\n xx(1) = 0.0\n do i = 2, nx\n dx = x(i) - x(i-1)\n dy = y(i) - y(i-1)\n xx(i) = xx(i-1) + sqrt(dx**2 + dy**2)\n end do\n\n ! Calculate the velocity gradient at each node\n v1 = ve(3); x1 = xx(3)\n v2 = ve(1); x2 = xx(1)\n ! ve(nx+1) = ve(nx-2)\n xx(nx+1) = xx(nx-2)\n\n do i = 1, nx\n v3 = v1; x3 = x1\n v1 = v2; v1 = x2\n\n v2 = ve(nx-2)\n if (i < nx) v2 = ve(i+1)\n\n x2 = xx(i+1)\n fact = (x3 - x1) / (x2 - x1)\n\n vgrad(i) = ( (v2 - v1)*fact - (v3-v1)/fact ) / (x3 - x2)\n end do\n\n ! Laminar Flow Region\n theta(1) = sqrt(0.75 / Re / vgrad(1))\n\n i = 1\n lambda = theta(1)**2 * vgrad(1) * Re\n \n do while (lambda >= -0.0842)\n \n lambda = theta(i)**2 * vgrad(i) * Re\n call thwats(lambda, H, L)\n\n cf = 2 * L / Re / theta(i)\n if (i > 1) cf = cf / ve(i)\n\n print *, x(i), y(i), ve(i), vgrad(i), theta(i), h, cf\n\n i = i + 1\n\n if (i > nx) stop\n\n dth2ve6 = 0.225 * (ve(i)**5 + ve(i-1)**5) * (xx(i) - xx(i-1)) / Re\n theta(i) = sqrt( ((theta(i-1)**2)*(ve(i-1)**6) + dth2ve6) / ve(i)**6 )\n\n if (i == 2) theta(2) = theta(1)\n\n ! Test for transition\n if (useFixedCriterion) then\n Rex = Re*xx(i)*ve(i)\n Ret = Re*theta(i)*ve(i)\n RetMax = 1.174 * (1 + 22400/Rex) * Rex**0.46\n end if\n\n end do\n \n end subroutine bl_growth\n\n elemental real function x(i)\n !! X-coordinates of the ellipse,\n !! $$ x_i = -\\cos\\left(\\frac{(i-1)\\pi}{nx-1}\\tau\\right) $$\n\n integer, intent(in) :: i\n\n x = -cos(PI * (i-1) / real(nx - 1)) * tau\n end function x\n\n elemental real function y(i)\n !! Y-coordinates of the ellipse,\n !! $$ y_i = \\sin\\left(\\frac{(i-1)\\pi}{nx-1}\\tau\\right) $$\n \n integer, intent(in) :: i\n\n y = sin(pi*(i-1) / real(nx-1)) * tau\n end function y\n \n elemental real function ve(i)\n !! VE of the ellipse,\n !! $$ v_e = \\left(1 + \\tau\\right) \\cdot \\sqrt{\\frac{1 - x_i^2}{1-\\left(1-\\tau^2\\right)x_i^2}} $$\n integer, intent(in) :: i\n \n ve = (1 + tau) * sqrt((1 - x(i)**2) / (1 - (1-tau**2)*x(i)**2))\n end function ve\n \n \nend module airfoil_bl_growth\n", "meta": {"hexsha": "f817cefcc8dff4070c3f460eb50728d0a79ff78d", "size": 4831, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "doc/src/airfoilBlGrowth.f90", "max_stars_repo_name": "vincentjs/moran", "max_stars_repo_head_hexsha": "7f7db7a467e0891aba06fdf81fb225843e5c1ac4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-01-08T16:37:05.000Z", "max_stars_repo_stars_event_max_datetime": "2016-01-08T16:37:05.000Z", "max_issues_repo_path": "doc/src/airfoilBlGrowth.f90", "max_issues_repo_name": "vincentjs/moran", "max_issues_repo_head_hexsha": "7f7db7a467e0891aba06fdf81fb225843e5c1ac4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/src/airfoilBlGrowth.f90", "max_forks_repo_name": "vincentjs/moran", "max_forks_repo_head_hexsha": "7f7db7a467e0891aba06fdf81fb225843e5c1ac4", "max_forks_repo_licenses": ["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.4573170732, "max_line_length": 250, "alphanum_fraction": 0.5938729042, "num_tokens": 1517, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218262741297, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6932968053817409}} {"text": " SUBROUTINE CNMN02 (NCALC,SLOPE,DFTDF1,DF,S,N1)\r\n IMPLICIT DOUBLE PRECISION(A-H,O-Z)\r\n COMMON /CNMN1/ DELFUN,DABFUN,FDCH,FDCHM,CT,CTMIN,CTL,CTLMIN,ALPHAX\r\n 1,ABOBJ1,THETA,OBJ,NDV,NCON,NSIDE,IPRINT,NFDG,NSCAL,LINOBJ,ITMAX,IT\r\n 2RM,ICNDIR,IGOTO,NAC,INFO,INFOG,ITER,NFEASCT \r\n DIMENSION DF(N1), S(N1) \r\nC ROUTINE TO DETERMINE CONJUGATE DIRECTION VECTOR OR DIRECTION\r\nC OF STEEPEST DESCENT FOR UNCONSTRAINED FUNCTION MINIMIZATION.\r\nC BY G. N. VANDERPLAATS APRIL, 1972.\r\nC NASA-AMES RESEARCH CENTER, MOFFETT FIELD, CALIF.\r\nC NCALC = CALCULATION CONTROL.\r\nC NCALC = 0, S = STEEPEST DESCENT.\r\nC NCALC = 1, S = CONJUGATE DIRECTION. \r\nC CONJUGATE DIRECTION IS FOUND BY FLETCHER-REEVES ALGORITHM.\r\nC ------------------------------------------------------------------\r\nC CALCULATE NORM OF GRADIENT VECTOR \r\nC ------------------------------------------------------------------\r\n DFTDF=0.\r\n DO 10 I=1,NDV \r\n DFI=DF(I) \r\n10 DFTDF=DFTDF+DFI*DFI \r\nC ------------------------------------------------------------------\r\nC ********** FIND DIRECTION S **********\r\nC ------------------------------------------------------------------\r\n IF (NCALC.NE.1) GO TO 30\r\n IF (DFTDF1.LT.1.0E-20) GO TO 30 \r\nC ------------------------------------------------------------------\r\nC FIND FLETCHER-REEVES CONJUGATE DIRECTION\r\nC ------------------------------------------------------------------\r\n BETA=DFTDF/DFTDF1 \r\n SLOPE=0.\r\n DO 20 I=1,NDV \r\n DFI=DF(I) \r\n SI=BETA*S(I)-DFI\r\n SLOPE=SLOPE+SI*DFI\r\n20 S(I)=SI \r\n GO TO 50\r\n30 CONTINUE\r\n NCALC=0 \r\nC ------------------------------------------------------------------\r\nC CALCULATE DIRECTION OF STEEPEST DESCENT\r\nC ------------------------------------------------------------------\r\n DO 40 I=1,NDV \r\n40 S(I)=-DF(I) \r\n SLOPE=-DFTDF\r\n50 CONTINUE\r\nC ------------------------------------------------------------------\r\nC NORMALIZE S TO MAX ABS VALUE OF UNITY\r\nC ------------------------------------------------------------------\r\n S1=0. \r\n DO 60 I=1,NDV \r\n S2=ABS(S(I))\r\n IF (S2.GT.S1) S1=S2 \r\n60 CONTINUE\r\n IF (S1.LT.1.0E-20) S1=1.0E-20 \r\n S1=1./S1\r\n DFTDF1=DFTDF*S1 \r\n DO 70 I=1,NDV \r\n70 S(I)=S1*S(I)\r\n SLOPE=S1*SLOPE\r\n RETURN\r\n END ", "meta": {"hexsha": "8dd1fab41d72720d03f61457d7ef6bb14c8934f2", "size": 2530, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "pyoptsparse/pyCONMIN/source/cnmn02.f", "max_stars_repo_name": "robfalck/pyoptsparse", "max_stars_repo_head_hexsha": "c99f4bfe8961492d0a1879f9ecff7a2fbb3c8c1d", "max_stars_repo_licenses": ["CNRI-Python"], "max_stars_count": 26, "max_stars_repo_stars_event_min_datetime": "2020-08-25T16:16:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-10T08:23:57.000Z", "max_issues_repo_path": "pyoptsparse/pyCONMIN/source/cnmn02.f", "max_issues_repo_name": "robfalck/pyoptsparse", "max_issues_repo_head_hexsha": "c99f4bfe8961492d0a1879f9ecff7a2fbb3c8c1d", "max_issues_repo_licenses": ["CNRI-Python"], "max_issues_count": 90, "max_issues_repo_issues_event_min_datetime": "2020-08-24T23:02:47.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T13:48:15.000Z", "max_forks_repo_path": "pyoptsparse/pyCONMIN/source/cnmn02.f", "max_forks_repo_name": "robfalck/pyoptsparse", "max_forks_repo_head_hexsha": "c99f4bfe8961492d0a1879f9ecff7a2fbb3c8c1d", "max_forks_repo_licenses": ["CNRI-Python"], "max_forks_count": 25, "max_forks_repo_forks_event_min_datetime": "2020-08-24T19:28:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-27T21:17:37.000Z", "avg_line_length": 40.8064516129, "max_line_length": 73, "alphanum_fraction": 0.395256917, "num_tokens": 728, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218284193597, "lm_q2_score": 0.752012562644147, "lm_q1q2_score": 0.6932967967472202}} {"text": "!>\n!!##NAME\n!! calculator - [M_calculator] parse calculator expression and return numeric or string value\n!! (LICENSE:PD)\n!!##SYNOPSIS\n!!\n!! subroutine calculator(inline,outlin,mssg,slast,ierr)\n!!\n!! character(len=*),intent=(in) :: inline\n!! character(len=iclen_calc),intent=(out) :: outlin\n!! character(len=iclen_calc),intent=(out) :: mssg\n!! doubleprecision, intent=(out) :: slast\n!! integer, intent=(out) :: ierr\n!!\n!!##DESCRIPTION\n!! CALCULATOR(3f) evaluates FORTRAN-like expressions. It can be used to add\n!! calculator-like abilities to your program.\n!!\n!!##OPTIONS\n!! inline INLINE is a string expression up to (iclen_calc=512) characters long.\n!! The syntax of an expression is described in\n!! the main document of the Calculator Library.\n!! outlin Returned numeric value as a string when IERR=0.\n!! mssg MSSG is a string that can serve several purposes\n!! o Returned string value when IERR=2\n!! o Error message string when IERR=-1\n!! o Message from 'funcs' or 'dump' command when IERR=1\n!! slast SLAST has different meanings depending on whether a string or number\n!! is being returned\n!! o REAL value set to last successfully calculated value when IERR=0\n!! o Number of characters in returned string variable when IERR=2\n!! ierr status flag.\n!! -1 An error occurred\n!! 0 A numeric value was returned\n!! 1 A message was returned\n!! 2 A string value was returned\n!!##EXAMPLES\n!!\n!! Example calculator program\n!!\n!! program demo_calculator\n!! !compute(1f): line mode calculator program (that calls calculator(3f))\n!! use M_calculator, only: calculator,iclen_calc\n!! ! iclen_calc : max length of expression or variable value as a string\n!! implicit none\n!! integer,parameter :: dp=kind(0.0d0)\n!! character(len=iclen_calc) :: line\n!! character(len=iclen_calc) :: outlin\n!! character(len=iclen_calc) :: event\n!! real(kind=dp) :: rvalue\n!! integer :: ierr\n!! ierr=0\n!! call calculator('ownmode(1)',outlin,event,rvalue,ierr)\n!! ! activate user-defined function interface\n!! INFINITE: do\n!! read(*,'(a)',end=999)line\n!! if(line.eq.'.')stop\n!! call calculator(line,outlin,event,rvalue,ierr)\n!! select case (ierr)\n!! ! several different meanings to the error flag returned by calculator\n!! case(0)\n!! ! a numeric value was returned without error\n!! write(*,'(a,a,a)')trim(outlin),' = ',trim(line)\n!! case(2)\n!! ! a string value was returned without error\n!! write(*,'(a)')trim(event(:int(rvalue)))\n!! case(1)\n!! ! a request for a message has been returned (from DUMP or FUNC)\n!! write(*,'(a,a)')'message===>',trim(event(:len_trim(event)))\n!! case(-1)\n!! ! an error has occurred\n!! write(*,'(a,a)')'error===>',trim(event(:len_trim(event)))\n!! case default\n!! ! this should not occur\n!! WRITE(6,'(A,i10)')'*CALCULATOR* UNEXPECTED IERR VALUE ',IERR\n!! end select\n!! enddo INFINITE\n!! 999 continue\n!! end program demo_calculator\n!!\n!!##SEE ALSO\n!! see INUM0(),RNUM0(),SNUM0(),EXPRESSION().\n!!##AUTHOR\n!! John S. Urban\n!!##LICENSE\n!! Public Domain\n!===================================================================================================================================\n!>\n!! AUTHOR John S. Urban\n!!##VERSION 1.0 19971123,20161218\n!===================================================================================================================================\n!-----------------------------------------------------------------------------------------------------------------------------------\n!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!\n!-----------------------------------------------------------------------------------------------------------------------------------\nmodule M_calculator\nuse, intrinsic :: iso_fortran_env, only : stderr=>ERROR_UNIT,stdout=>OUTPUT_UNIT ! access computing environment\n\n!!implicit doubleprecision (a-h,o-z)\nimplicit none\nprivate\n\ninteger,parameter :: k_dbl=kind(0.0d0)\ninteger,parameter :: dp=kind(0.0d0)\n\ninteger,parameter,public :: iclen_calc=512 ! max length of expression or variable value as a string\ninteger,parameter,public :: ixy_calc=55555 ! number of variables in X() and Y() array\nreal(kind=dp),save,public :: x(ixy_calc)=0.0_dp ! x array for procedure funcs_\nreal(kind=dp),save,public :: y(ixy_calc)=0.0_dp ! y array for procedure funcs_\n\ninteger,parameter,public :: icname_calc=20 ! max length of a variable name\n\ncharacter(len=:),allocatable,save :: keys_q(:) ! contains the names of string variables\ncharacter(len=:),allocatable,save,public :: values(:) ! string variable values\ninteger,save,public,allocatable :: values_len(:) ! lengths of the string variable values\n\ncharacter(len=:),allocatable,save :: keyr_q(:) ! contains the names of numeric variables\nreal(kind=dp),save,allocatable :: values_d(:) ! numeric variable values\n\npublic :: calculator\nprivate :: stuff\nprivate :: stuffa\n! CONVENIENCE ROUTINES\npublic :: inum0 ! resolve a calculator string into a whole integer number\npublic :: rnum0 ! resolve a calculator string into a real number (return 0 on errors)\npublic :: dnum0 ! resolve a calculator string into a doubleprecision number (return 0 on error s)\npublic :: snum0 ! resolve a calculator expression into a string(return blank on errors)\npublic :: expression ! call calculator() calculator and display messages\n\npublic :: set_mysub\npublic :: set_myfunc\n\ninteger,parameter :: ixyc_calc=50 ! number of variables in $X() and $(Y) array\ninteger,parameter :: icbuf_calc=23*(iclen_calc/2+1) ! buffer for string as it is expanded\n\n\n! no check on whether line expansion ever causes line length to\n! exceed allowable number of characters.\n! number of characters to prevent over-expansion would currently be\n! 23 digits per number max*(input number of characters/2+1).\n\ncharacter(len=iclen_calc) :: mssge ! for error message/messages /returning string value\n\ncharacter(len=iclen_calc),save :: xc(ixyc_calc)=' ' ! $x array for procedure funcs_\ncharacter(len=iclen_calc),save :: yc(ixyc_calc)=' ' ! $y array for procedure funcs_\ncharacter(len=iclen_calc),save :: nc(ixyc_calc)=' ' ! $n array for procedure funcs_\n\n\ncharacter(len=iclen_calc),save :: last='0.0' ! string containing last answer (i.e. current value)\nlogical,save :: ownon=.false. ! flag for whether to look for substitute_subroutine(3f)\n\ninteger,save :: ktoken ! count of number of token strings assembled\n!\nprivate :: a_to_d_ ! returns a real value rval from a numeric character string chars.\nprivate :: squeeze_\nprivate :: stufftok_\nprivate :: funcs_\nprivate :: pows_\nprivate :: given_name_get_stringvalue_\nprivate :: parens_\nprivate :: args_\nprivate :: factors_\nprivate :: expressions_\nprivate :: help_funcs_\n\nprivate :: juown1_placeholder\nprivate :: c_placeholder\n\nabstract interface\n subroutine juown1_interface(func,iflen,args,iargstp,n,fval,ctmp,ier)\n import k_dbl\n character(len=*),intent(in) :: func\n integer,intent(in) :: iflen\n real(kind=k_dbl),intent(in) :: args(100)\n integer,intent(in) :: iargstp(100)\n integer,intent(in) :: n\n real(kind=k_dbl) :: fval\n character(len=*) :: ctmp\n integer :: ier\n end subroutine juown1_interface\nend interface\n\nabstract interface\n real function c_interface(args,n)\n import k_dbl\n integer,intent(in) :: n\n real(kind=k_dbl),intent(in) :: args(n)\n end function c_interface\nend interface\npublic c_interface\npublic juown1_interface\n\nprocedure(juown1_interface),pointer :: mysub => juown1_placeholder\nprocedure(c_interface),pointer :: myfunc => c_placeholder\n\npublic locate ! [M_list] find PLACE in sorted character array where value can be found or should be placed\n private locate_c\n private locate_d\n private locate_i\npublic insert ! [M_list] insert entry into a sorted allocatable array at specified position\n private insert_c\n private insert_d\n private insert_i\npublic replace ! [M_list] replace entry by index from a sorted allocatable array if it is present\n private replace_c\n private replace_d\n private replace_i\npublic remove ! [M_list] delete entry by index from a sorted allocatable array if it is present\n private remove_c\n private remove_d\n private remove_i\n\n!character(len=*),parameter::ident_1=\"&\n!&@(#)M_list::locate(3f): Generic subroutine locates where element is or should be in sorted allocatable array\"\ninterface locate\n module procedure locate_c, locate_d\nend interface\n\n!character(len=*),parameter::ident_2=\"&\n!&@(#)M_list::insert(3f): Generic subroutine inserts element into allocatable array at specified position\"\ninterface insert\n module procedure insert_c, insert_d, insert_i\nend interface\n\n!character(len=*),parameter::ident_3=\"&\n!&@(#)M_list::replace(3f): Generic subroutine replaces element from allocatable array at specified position\"\ninterface replace\n module procedure replace_c, replace_d, replace_i \nend interface\n\n!character(len=*),parameter::ident_4=\"&\n!&@(#)M_list::remove(3f): Generic subroutine deletes element from allocatable array at specified position\"\ninterface remove\n module procedure remove_c, remove_d, remove_i \nend interface\n\n!-----------------------------------------------------------------------------------------------------------------------------------\npublic dictionary\n\ntype dictionary\n character(len=:),allocatable :: key(:)\n character(len=:),allocatable :: value(:)\n integer,allocatable :: count(:)\n contains\n procedure,private :: get => dict_get\n procedure,private :: set => dict_add ! insert entry by name into a sorted allocatable character array if it is not present\n procedure,private :: del => dict_delete ! delete entry by name from a sorted allocatable character array if it is present\nend type dictionary\ncontains\n!-----------------------------------------------------------------------------------------------------------------------------------\n!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!\n!-----------------------------------------------------------------------------------------------------------------------------------\nsubroutine set_myfunc(proc)\nprocedure(c_interface) :: proc\n myfunc => proc\nend subroutine set_myfunc\n!-----------------------------------------------------------------------------------------------------------------------------------\n!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!\n!-----------------------------------------------------------------------------------------------------------------------------------\nsubroutine set_mysub(proc)\nprocedure(juown1_interface) :: proc\n mysub => proc\nend subroutine set_mysub\n!-----------------------------------------------------------------------------------------------------------------------------------\n!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!\n!-----------------------------------------------------------------------------------------------------------------------------------\nrecursive subroutine calculator(inline,outlin,mssg,slast,ierr)\n!\n! The goal is to create a procedure easily utilized from other\n! programs that takes a standard Fortran value statement and reduces\n! it down to a value, efficiently and using standard Fortran\n! standards where ever feasible.\n!\n! Version 2.0: 03/13/87\n! Version 3.0: 07/11/2013\n! Version 5.0: 07/16/2013\n!\n! o adjacent powers are done left to right, not right to left\n! o code does not prevent - and + beside an other operator.\n! o no check on whether user input more characters than allowed.\n! no check on whether line expansion ever causes line length to\n! exceed allowable number of characters.\n! number of characters to prevent over-expansion would currently be\n! 23 digits per number max*(input number of characters/2+1).\n! o allowing for ixy_calc arguments in max and min seems too high. if reducing\n! array size helps significantly in costs, do so.\n! o parentheses are required on a function call.\n! o square brackets [] are equivalent to parenthesis ().\n!===========================================================================--------------------------------------------------------\n! 2. need a generic help function to list commands and functions\n! 3. allow multiple expressions per line with a semi-colon between them\n! (like the parse functions).\n! 4. make a function to fill x and y arrays, or to read values into them\n! from a file; and make some statistical functions that work on the\n! arrays.\n! 6. allow user-written functions to be called from funcs_ routine.\n! 7. allow for user-defined arrays and array operations.\n!===========================================================================--------------------------------------------------------\n! 12/07/87 --- put in an implicit real (a-h,o-z) statement in each\n! procedure so that it could quickly be changed to\n! implicit real*8 (a-h,o-z) for a vax. be careful of\n! type mismatch between external functions and the\n! real variables.\n! use following xedit commands where periods denote\n! spaces\n! c/implicit real../implicit real*8./ *\n! 12/11/87 --- changed ifix calls to int calls as ifix on vax does\n! not allow real*8 in ifix calls\n! 12/11/87 --- moving all prints out of column 1 so it is not picked\n! out by vax as carriage control.\n! 12/28/87 --- put bn format specifier into a_to_d_ routine because\n! vax assumes zero fill\n! 06/23/88 --- making a first cut at allowing string variables.\n! 1. string variable names must start with a dollar-sign\n! 2. strings can only be up to (iclen_calc) characters long\n! 3. they will be returned in the message string to\n! the calling program\n! 4. input strings must be delimited with double quotes.\n! to place a double quote into the string, put two\n! double quotes adjacent to each other.\n! 5. a flag value for ier to distinguish between string\n! and numeric output?\n!#----------------------------------------------------------------------------------------------------------------------------------\n!subroutine calculator(inline,outlin,mssg,slast,ierr)\n\n!character(len=*),parameter::ident_1=\"@(#)M_calculator::calculator(3f): The procedure CALCULATOR(3f) acts like a calculator\"\n\n!-----------------------------------------------------------------------------------------------------------------------------------\ncharacter(len=*),intent(in) :: inline\ncharacter(len=iclen_calc),intent(out) :: outlin\ncharacter(len=iclen_calc),intent(out) :: mssg\nreal(kind=dp),intent(out) :: slast\ninteger,intent(out) :: ierr\n!-----------------------------------------------------------------------------------------------------------------------------------\ncharacter(len=icbuf_calc) :: line\ncharacter(len=iclen_calc) :: varnam\ncharacter(len=iclen_calc) :: junout\nreal(kind=dp),save :: rlast=0.0_dp\ninteger :: i10\ninteger :: i20\ninteger :: idum\ninteger :: imax\ninteger :: indx\ninteger :: iplace\ninteger :: istart\ninteger :: nchar2\ninteger :: nchard\n!-----------------------------------------------------------------------------------------------------------------------------------\n line=inline ! set working string to initial input line\n imax=len(inline) ! determine the length of the input line\n mssg=' ' ! set returned message/error/string value string to a blank\n outlin=' '\n BIG: do ! for $A=numeric and A=string\n ierr=1 ! set status flag to message mode\n mssge=' ' ! set message/error/string value in GLOBAL to a blank\n varnam=' '\n call squeeze_(line,imax,nchard,varnam,nchar2,ierr) ! preprocess the string: remove blanks and process special characters\n ! also remove all quoted strings and replace them with a token\n!-----------------------------------------------------------------------------------------------------------------------------------\n if(ierr.eq.-1)then ! if an error occurred during preprocessing of the string, set returned message and quit\n slast=rlast ! set returned real value to last good calculated value\n mssg=mssge ! place internal message from GLOBAL into message returned to user\n return\n elseif(nchard.eq.0)then ! if a blank input string was entered report it as an error and quit\n ierr=-1\n mssg='*calculator* input line was empty'\n elseif(line(1:nchard).eq.'dump')then ! process dump command\n write(*,*)line(1:nchard)\n write(*,*)'current value= ',last\n write(*,*)' variable name variable value '\n if(allocated(keyr_q))then\n do i10=1,size(keyr_q)\n if(keyr_q(i10).ne.' ')then\n write(junout,'('' '',2a,g23.16e3)')keyr_q(i10),' ',values_d(i10)\n write(*,*)trim(junout)\n endif\n enddo\n endif\n if(allocated(keys_q))then\n do i20=1,size(keys_q)\n if(keys_q(i20).ne.' ')then\n write(junout,'('' '',3a)')keys_q(i20),' ',values(i20)(:values_len(i20))\n write(*,*)trim(junout)\n endif\n enddo\n endif\n mssg='variable listing complete'\n elseif(line(1:nchard).eq.'funcs') then ! process funcs command\n call help_funcs_()\n mssg='function listing complete'\n!-----------------------------------------------------------------------------------------------------------------------------------\n else ! this is an input line to process\n call parens_(line,nchard,ierr) ! process the command\n if(ierr.eq.0)then ! if no errors occurred set output string, store the value as last, store any variable\n ! numeric value with no errors, assume nchard is 23 or less\n outlin=line(1:nchard) ! set string output value\n last=line(1:nchard) ! store last value (for use with question-mark token)\n call a_to_d_(last(1:nchard),rlast,idum) ! set real number output value\n if(nchar2.ne.0.and.varnam(1:1).ne.'$')then ! if the statement defines a variable make sure variable name is stored\n call locate(keyr_q,varnam(:nchar2),indx,ierr) ! determine placement of the variable and whether it is new\n if(ierr.eq.-1)then\n slast=rlast ! set returned real value to last good calculated value\n mssg=mssge ! place internal message from GLOBAL into message returned to user\n return\n endif\n if(indx.le.0)then ! if the variable needs added, add it\n istart=iabs(indx)\n call insert(keyr_q,varnam(:nchar2),istart)\n call insert(values_d,0.0d0,istart)\n endif\n call a_to_d_(last(1:nchard),values_d(iabs(indx)),ierr) ! store a defined variable's value\n elseif(nchar2.ne.0)then ! numeric value to string\n line(:)=' '\n line=varnam(:nchar2)//'=\"'//last(1:nchard)//'\"'\n imax=len_trim(line) ! determine the length of the input line\n cycle BIG\n endif\n elseif(ierr.eq.2)then ! returned output is not numeric, but alphanumeric (it is a string)\n!!!!!!! could return string values directly instead of thru message field\n!!!!!!! make sure normal output values are not left indeterminate\n mssg=mssge ! set returned string value to returned string value\n if(nchar2.ne.0.and.varnam(1:1).eq.'$')then ! if the statement defines a variable make sure variable name is stored\n call locate(keys_q,varnam(:nchar2),indx,ierr) ! determine placement of the variable and whether it is new\n if(ierr.eq.-1)then\n slast=rlast ! set returned real value to last good calculated value\n mssg=mssge ! place internal message from GLOBAL into message returned to user\n return\n endif\n iplace=iabs(indx)\n if(indx.le.0)then ! if the variable needs added, add it\n call insert(keys_q,varnam(:nchar2),iplace) ! adding the new variable name to the variable name array\n call insert(values,' ' ,iplace)\n call insert(values_len,0 ,iplace)\n endif\n call replace(values,mssg,iplace)\n call replace(values_len,len_trim(mssg),iplace)\n rlast=dble(values_len(iplace)) ! returned value is length of string when string is returned\n elseif(nchar2.ne.0)then ! string but being stored to numeric variable\n line=varnam(:nchar2)//'='//mssg\n imax=len_trim(line) ! determine the length of the input line\n cycle BIG\n else ! a string function with an assignment to it (for example \"Hello\"\n rlast=len_trim(mssg) ! probably should pass message length up from someplace\n endif\n endif\n mssg=mssge\n endif\n exit BIG\n enddo BIG\n slast=rlast ! set returned value to last successfully calculated real value\nend subroutine calculator\n!TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n!-----------------------------------------------------------------------------------------------------------------------------------\n!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!\n!-----------------------------------------------------------------------------------------------------------------------------------\n!>\n!!##NAME\n!! (LICENSE:PD)\n!!##SYNOPSIS\n!!\n!!##DESCRIPTION\n!!##OPTIONS\n!!##RETURNS\n!!##EXAMPLE\n!!\n!!##AUTHOR\n!! John S. Urban\n!!##LICENSE\n!! Public Domain\n!===================================================================================================================================\nsubroutine help_funcs_()\n\n!character(len=*),parameter::ident_2=\"@(#)M_calculator::help_funcs_(3fp): prints help for calculator functions\"\n\ncharacter(len=80),allocatable :: help_text(:)\ninteger :: i\nhelp_text=[ &\n&'--------------------------------------------------------------------------------',&\n&'standard functions available: ',&\n&'--------------------------------------------------------------------------------',&\n!&' c( : user-defined function ',&\n!&' ownmode( : call user-defined procedures ',&\n&'--------------------------------------------------------------------------------',&\n&' len_trim($value) : number of characters trimming trailing spaces ',&\n&' index($value,$match) : return position $match occurs in $value or zero ',&\n&' sign(val1,val2) : magnitude of val1 with the sign of val2 ',&\n&' real(value) : conversion to real type ',&\n&' str($str|expr,....) :append as strings and then convert to number ',&\n&' $str($str|expr,....) :append as strings ',&\n&' round(value,digits) : ',&\n&' ichar($value) : return ASCII Decimal Equivalent of character ',&\n&' $char(value) : return character given ASCII Decimal Equivalent ',&\n&' $f(format,value) : using FORMAT to create it convert number to string ',&\n&' $if(expr,$val1,$val2): if expr==0 return $val1, else return $val2 ',&\n&' if(expr,val1,val2) : if expr==0 return val1, else return val2 ',&\n&' hypot(x,y) : Euclidean distance function ',&\n&'--------------------------------------------------------------------------------',&\n&'WHOLE NUMBERS: ',&\n&' aint(value) : truncation toward zero to a whole number ',&\n&' anint(value): nearest whole number ',&\n&' int(value) : conversion to integer type ',&\n&' nint(value) : nearest integer ',&\n&' floor(A) : greatest integer less than or equal to A ',&\n&' ceiling(A) : least integer greater than or equal to A ',&\n&'--------------------------------------------------------------------------------',&\n&'MISCELLANEOUS: ',&\n&' max(v1,v2,v3,...v50) : maximum value of list ',&\n&' min(v1,v2,v3,...v50) : minimum value of list ',&\n&' dim(x,y) : maximum of X-Y and zero ',&\n&' frac(A) : fractional part of A (A - INT(A)) ',&\n&' mod(A,P) : remainder function ',&\n&' abs(value) : absolute value ',&\n&' exp(value) : exponent of value ',&\n&'NUMERIC FUNCTIONS: ',&\n&' bessel_j0 : Bessel function of the first kind of order 0 ',&\n&' bessel_j1 : Bessel function of the first kind of order 1 ',&\n&' bessel_jn : Bessel function of the first kind ',&\n&' bessel_y0 : Bessel function of the second kind of order 0 ',&\n&' bessel_y1 : Bessel function of the second kind of order 1 ',&\n&' bessel_yn : Bessel function of the second kind ',&\n&' sqrt(value) : return square root of value ',&\n&' log(v1) : logarithm of value to base e ',&\n&' log10(v1) : logarithm of value to base 10 ',&\n&'--------------------------------------------------------------------------------',&\n&'RANDOM NUMBERS: ',&\n&' srand(seed_value) : set seed value for rand() ',&\n&' rand() : random number ',&\n&'--------------------------------------------------------------------------------',&\n&'SYSTEM: ',&\n&' $getenv(name),$ge(name) : get environment variable value ',&\n&' sh(command) : system command ',&\n&'--------------------------------------------------------------------------------',&\n&'ARRAY STORAGE: ',&\n&' $nstore(start_index,$value1,$value2,$value3,....) | $n(index) ',&\n&' $xstore(start_index,$value1,$value2,$value3,....) | $x(index) ',&\n&' $ystore(start_index,$value1,$value2,$value3,....) | $y(index) ',&\n&' xstore(start_index,value1,value2,value3,....) | x(index) ',&\n&' ystore(start_index,value1,value2,value3,....) | y(index) ',&\n&'--------------------------------------------------------------------------------',&\n&'STRING MODIFICATION: ',&\n&' $l($input_string) : convert string to lowercase ',&\n&' $u($input_string) : convert string to uppercase ',&\n&' $substr($input_string,start_column,end_column) ',&\n&' $str($a|e,$a|e,$a|e,....):append string and value expressions into string ',&\n&'--------------------------------------------------------------------------------',&\n&'CALENDAR: ',&\n&' ye(),year() : current year ',&\n&' mo(),month() : current month ',&\n&' da(),day() : current day ',&\n&' ho(),hour() : current hour ',&\n&' mi(),minute() : current minute ',&\n&' se(),second() : current second ',&\n&' $mo([n]) : name of month ',&\n&' dw() : day of week ',&\n&' ju() : day of year ',&\n&'--------------------------------------------------------------------------------',&\n&'TRIGONOMETRIC: ',&\n&' cos(radians) : cosine | acos(x/r) | cosh() | acosh() | cosd(degrees) ',&\n&' sin(radians) : sine | asin(y/r) | sinh() | asinh() | sind(degrees) ',&\n&' tan(radians) : tangent | atan(y/x) | tanh() | atanh() | tand(degrees) ',&\n&' | atan2(x,y) | ',&\n&'--------------------------------------------------------------------------------',&\n&'UNIT CONVERSION: ',&\n&' c2f(c) : centigrade to Fahrenheit |f2c(f) : Fahrenheit to centigrade ',&\n&' d2r(d) : degrees to radians |r2d(r) : radians to degrees ',&\n&'--------------------------------------------------------------------------------',&\n&'LOGICAL: ',&\n&' ge(a,b) : greater than or equal to ',&\n&' le(a,b) : A less than or equal to B ',&\n&' gt(a,b) : A greater than B ',&\n&' lt(a,b) : A less than B ',&\n&' eq(a,b) : A equal to B ',&\n&' ne(a,b) : A not equal to B ',&\n&' lge($a,$b): lexically greater than or equal to ',&\n&' lle($a,$b): lexically A less than or equal to B ',&\n&' lgt($a,$b): lexically A greater than B ',&\n&' llt($a,$b): lexically A less than B ',&\n&' leq($a,$b): lexically A equal to B ',&\n&' lne($a,$b): lexically A not equal to B ',&\n&' in(lower_bound,test_value,upper_bound) : test if value in given range ',&\n&'--------------------------------------------------------------------------------',&\n&' ']\n do i=1,size(help_text)\n write(*,*)trim(help_text(i))\n enddo\nend subroutine help_funcs_\n!TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n!-----------------------------------------------------------------------------------------------------------------------------------\n! fraction : Fractional part of the model representation\n! exponent :\n! gamma : Logarithm of the Gamma function\n! log_gamma Logarithm of the Gamma function\n! erf Error function erfc (3fortran) -\n! Complementary error function erfc_scaled\n! erfc Complementary error function\n! erfc_scaled Error function\n! modulo Modulo function\n! btest MANIPULATION] Bit test function\n! tiny Smallest positive number of a real kind\n! epsilon Epsilon function\n! huge Largest number of a kind\n! same pads strings to same length and then calls MERGE(3f)\n! flush flush I/O buffers of specified files\n! unusedf\n! delimx\n! c\n! ownmode\n! mod\n! scale\n! len\n! ifdef\n! open close rewind write\n!-----------------------------------------------------------------------------------------------------------------------------------\n!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!\n!-----------------------------------------------------------------------------------------------------------------------------------\n!>\n!!##NAME\n!! parens_(3fp) - [M_calculator] crack out the parenthesis and solve\n!! (LICENSE:PD)\n!!##SYNOPSIS\n!!\n!! recursive subroutine parens_(string,nchar,ier)\n!! character(len=*) :: string\n!! integer,intent(inout) :: nchar\n!! integer,intent(out) :: ier\n!!##DESCRIPTION\n!! crack out the parenthesis and solve\n!!##OPTIONS\n!! string input string to expand and return\n!! nchar length of string on input and output\n!! ier status code\n!!\n!! 0=good numeric return\n!! 2=good alphameric return\n!! -1=error occurred, message is in mssge\n!!##RETURNS\n!!##EXAMPLE\n!!\n!!##AUTHOR\n!! John S. Urban\n!!##LICENSE\n!! Public Domain\n!===================================================================================================================================\nrecursive subroutine parens_(string,nchar,ier)\n\n!character(len=*),parameter::ident_3=\"@(#)M_calculator::parens_(3fp): crack out the parenthesis and solve\"\n\ncharacter(len=*) :: string\ninteger,intent(inout) :: nchar\ninteger,intent(out) :: ier\n\ncharacter(len=icbuf_calc) :: wstrng\ncharacter(len=:),allocatable :: dummy\ninteger :: imax\ninteger :: ileft\ninteger :: iright\ninteger :: i\ninteger :: iz\ninteger :: iwnchr\nreal(kind=dp) :: rdum\n!#----------------------------------------------------------------------------------------------------------------------------------\n imax=nchar\n ier=0\n INFINITE: do\n!#----------------------------------------------------------------------------------------------------------------------------------\n ileft=0 ! where rightmost left paren was found\n do i=imax,1,-1 ! find rightmost left paren\n if(string(i:i).eq.'(')then\n ileft=i\n exit\n endif\n enddo\n!#----------------------------------------------------------------------------------------------------------------------------------\n if(ileft.eq.0)then ! no left parenthesis was found; finish up\n if(index(string(:nchar),')').ne.0) then ! if here there are no left paren. check for an (unmatched) right paren\n ier=-1\n mssge='*parens_* extraneous right parenthesis found'\n else\n ! no parenthesis left, reduce possible expression to a single value primitive and quit\n ! a potential problem is that a blank string or () would end up here too.\n call expressions_(string,nchar,rdum,ier)\n endif\n return\n endif\n!#----------------------------------------------------------------------------------------------------------------------------------\n iright=index(string(ileft:nchar),')') ! left parenthesis was found; find matching right paren\n if(iright.eq.0) then\n ier=-1\n mssge='*parens_* right parenthesis missing'\n return\n endif\n!#----------------------------------------------------------------------------------------------------------------------------------\n iright=iright+ileft-1 !there was a matched set of paren remaining in the string\n iz=1 ! check now to see if this is a function call. search for an operator\n! if ileft is 1, then last set of parenthesis,(and for an expression)\n if(ileft.ne.1)then\n do i=ileft-1,1,-1\n iz=i\n if(index('#=*/(,',string(i:i)).ne.0)then\n iz=iz+1\n goto 11\n endif\n enddo\n! if here, a function call begins the string, as iz=1 but ileft doesn't\n endif\n!=======================================================================------------------------------------------------------------\n! iz=position beginning current primitive's string\n! ileft=position of opening parenthesis for this primitive\n! iright=position of end and right parenthesis for this string\n11 continue\n if(iz.eq.ileft)then ! if ileft eq iz then a parenthesized expression, not a function call\n wstrng=string(ileft+1:iright-1)\n iwnchr=iright-1-(ileft+1)+1\n call expressions_(wstrng,iwnchr,rdum,ier)\n else\n wstrng=string(iz:iright)\n iwnchr=iright-iz+1\n call funcs_(wstrng,iwnchr,ier)\n endif\n if(ier.eq.-1)return ! if an error occurred in expressions_ or funcs_, then return\n ! restring the evaluated primitive back into the main string\n ! remember that if an expression, iz=ileft\n ! last set of -matched- parentheses, and entire string was evaluated\n if(iz.eq.1.and.iright.eq.nchar)then\n dummy=wstrng(:iwnchr)\n nchar=iwnchr\n! last set of -matched- parentheses, but other characters still to right\n elseif(iz.eq.1)then\n dummy=wstrng(:iwnchr)//string(iright+1:nchar)\n nchar=iwnchr+nchar-iright\n elseif(iright.eq.nchar)then\n! last expression evaluated was at end of string\n dummy=string(:iz-1)//wstrng(:iwnchr)\n nchar=iz-1+iwnchr\n else\n! last expression evaluated was in middle of string\n dummy=string(:iz-1)//wstrng(:iwnchr)//string(iright+1:nchar)\n nchar=iz-1+iwnchr+nchar-iright\n endif\n! set last place to look for a left parenthesis to one to the left\n! of the beginning of the primitive just reduced, or to a 1 so that\n! the loop looking for the left parenthesis doesn't look for a\n! parenthesis at position 0:0\n imax=max(iz-1,1)\n string=dummy\n enddo INFINITE\nend subroutine parens_\n!TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n!-----------------------------------------------------------------------------------------------------------------------------------\n!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!\n!-----------------------------------------------------------------------------------------------------------------------------------\n!>\n!!##NAME\n!! funcs_(3fp) - [M_calculator]given string of form name(p1,p2,...) (p(i) are non-parenthesized expressions)\n!! call procedure \"name\" with those values as parameters.\n!! (LICENSE:PD)\n!!##SYNOPSIS\n!!\n!! recursive subroutine funcs_(wstrng,nchars,ier)\n!!\n!! character(len=*) :: wstrng\n!!##DESCRIPTION\n!!##OPTIONS\n!!##RETURNS\n!!##EXAMPLE\n!!\n!!##AUTHOR\n!! John S. Urban\n!!##LICENSE\n!! Public Domain\n!===================================================================================================================================\nrecursive subroutine funcs_(wstrng,nchars,ier)\n\n!character(len=*),parameter::ident_4=\"&\n!&@(#)M_calculator::funcs_(3fp):given string of form name(p1,p2,...) (p(i) are non-parenthesized expressions) call procedure name\"\n\ncharacter(len=*) :: wstrng\ninteger :: nchars\ninteger :: ier\n\ninteger,parameter :: iargs=100\ncharacter(len=10),save :: days(7)\ncharacter(len=10),save :: months(12)\ncharacter(len=9) :: day\ncharacter(len=iclen_calc) :: ctmp\ncharacter(len=iclen_calc) :: ctmp2\ncharacter(len=iclen_calc) :: junout\ncharacter(len=iclen_calc) :: cnum\ncharacter(len=icname_calc) :: wstrng2\n\nreal(kind=dp) :: args(iargs)\n\nreal :: acurcy\nreal(kind=dp) :: arg1\nreal(kind=dp) :: arg2\nreal(kind=dp) :: bottom\nreal(kind=dp) :: false\nreal(kind=dp) :: fval\nreal(kind=dp) :: top\nreal(kind=dp) :: true\nreal(kind=dp) :: val\n\nreal,external :: c\n\ninteger,save :: ikeepran=22\ninteger :: i\ninteger :: i1\ninteger :: i1010\ninteger :: i1033\ninteger :: i1060\ninteger :: i1066\ninteger :: i2\ninteger :: i2020\ninteger :: i3030\ninteger :: i410\ninteger :: i440\ninteger :: i520\ninteger :: i852\ninteger :: iargs_type(iargs)\ninteger :: ibegin(ixyc_calc),iterm(ixyc_calc)\ninteger :: icalen\ninteger :: icount\ninteger :: idarray(8)\ninteger :: idig\ninteger :: idum\ninteger :: iend\ninteger :: iend1\ninteger :: iend2\ninteger :: ifail\ninteger :: iflen\ninteger :: ii\ninteger :: iie\ninteger :: iii\ninteger :: iiie\ninteger :: ileft\ninteger :: ilen\ninteger :: in\ninteger :: ind\ninteger :: indexout\ninteger :: ios\ninteger :: iright\ninteger :: istart\ninteger :: istat\ninteger :: istore\ninteger :: istoreat\ninteger :: isub\ninteger :: itime(8)\ninteger :: itype\ninteger :: iunit\ninteger :: ival\ninteger :: ivalue\ninteger :: jend\ninteger :: jj\ninteger :: n\ninteger :: idat(8)\ninteger :: ierr\ninteger :: iweekday\ninteger :: ii2\ninteger :: ilen2\ninteger :: istatus\n\nintrinsic :: abs,aint,anint,exp,nint,int,log,log10\nintrinsic :: acos,asin,atan,cos,cosh,sin,sinh,tan,tanh\nintrinsic :: sqrt,atan2,dim,mod,sign,max,min\n!-----------------------------------------------------------------------------------------------------------------------------------\n data months/'January','February','March','April','May','June','July','August','September','October','November','December'/\n data days/'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'/\n!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc------------------------------------------------------------\n TRUE=0.0d0\n FALSE=1.0d0\n ier=0\n iright=nchars-1\n ileft=index(wstrng(1:nchars),'(')+1\n iend=ileft-2\n iflen=iright-ileft+1\n! n=number of parameters found\n if(iright-ileft.lt.0)then ! if call such as fx() expression string is null\n n=0\n else ! take string of expressions separated by commas and place values into an array and return how many values were found\n call args_(wstrng(ileft:iright),iflen,args,iargs_type,n,ier,100)\n if(ier.eq.-1)then\n goto 999\n else\n ier=0 ! ier could be 2 from args_()\n endif\n endif\n wstrng2=' '\n wstrng2(:iend)=lower(wstrng(:iend))\n fval=0.0d0\n if(ier.eq.-1)then\n goto 999\n endif\n!=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=------------------------------------------------------------\nselect case (wstrng2(:iend))\ncase(\"abs\",\"aint\",\"anint\",\"ceil\",\"ceiling\",\"floor\",\"frac\",\"int\",\"nint\",&\n &\"d2r\",\"r2d\",&\n &\"c2f\",\"f2c\",&\n &\"gamma\",\"log_gamma\",&\n &\"log\",\"log10\",\"exp\",&\n &\"bessel_j0\",\"bessel_j1\",\"bessel_y0\",\"bessel_y1\",&\n &\"erf\",\"erfc\",\"erfc_scaled\",&\n &\"sin\",\"cos\",\"tan\",&\n &\"sind\",\"cosd\",\"tand\",&\n &\"sinh\",\"cosh\",\"tanh\",&\n &\"asin\",\"acos\",\"atan\",&\n &\"asinh\",\"acosh\",\"atanh\",&\n! &\"cpu_time\",&\n &\"exponent\",\"fraction\",&\n &\"real\",\"sqrt\")\n if(n.ne.1)then ! check number of parameters\n mssge='*funcs_* incorrect number of parameters in '//wstrng2(:iend)\n ier=-1\n elseif(iargs_type(1).ne.0)then ! check type of parameters\n mssge='*funcs_* parameter not numeric in '//wstrng2(:iend)\n ier=-1\n else ! single numeric argument\n select case (wstrng2(:iend))\n!=======================================================================------------------------------------------------------------\n case(\"acos\");\n\n if(args(1).gt.1.or.args(1).lt.-1)then\n mssge='*acos* parameter not in range -1 >= value <=1'\n ier=-1\n else\n fval= acos(args(1))\n endif\n case(\"atan\"); fval= atan(args(1))\n case(\"asin\"); fval= asin(args(1))\n\n !case(\"cpu_time\"); fval= cpu_time(args(1))\n case(\"fraction\"); fval= fraction(args(1))\n case(\"exponent\"); fval= exponent(args(1))\n case(\"gamma\"); fval= gamma(args(1))\n case(\"log_gamma\"); fval= log_gamma(args(1))\n\n case(\"cos\"); fval= cos(args(1))\n case(\"sin\"); fval= sin(args(1))\n case(\"tan\"); fval= tan(args(1))\n\n case(\"acosh\"); fval= acosh(args(1))\n case(\"asinh\"); fval= asinh(args(1))\n case(\"atanh\"); fval= atanh(args(1))\n\n case(\"cosd\"); fval= cos(args(1)*acos(-1.0d0)/180.d0)\n case(\"sind\"); fval= sin(args(1)*acos(-1.0d0)/180.d0)\n case(\"tand\"); fval= tan(args(1)*acos(-1.0d0)/180.d0)\n\n case(\"cosh\"); fval= cosh(args(1))\n case(\"sinh\"); fval= sinh(args(1))\n case(\"tanh\"); fval= tanh(args(1))\n\n case(\"erf\"); fval= erf(args(1))\n case(\"erfc\"); fval= erfc(args(1))\n case(\"erfc_scaled\"); fval= erfc_scaled(args(1))\n\n case(\"d2r\"); fval= args(1)*acos(-1.0d0)/180.d0\n case(\"r2d\"); fval= args(1)*180.d0/acos(-1.0d0)\n\n case(\"c2f\"); fval= (args(1)+40.0d0)*9.0d0/5.0d0 - 40.0d0\n case(\"f2c\"); fval= (args(1)+40.0d0)*5.0d0/9.0d0 - 40.0d0\n\n case(\"bessel_j0\"); fval= bessel_j0(args(1))\n case(\"bessel_j1\"); fval= bessel_j1(args(1))\n case(\"bessel_y0\"); fval= bessel_y0(args(1))\n case(\"bessel_y1\"); fval= bessel_y1(args(1))\n\n case(\"abs\"); fval= abs(args(1))\n case(\"aint\"); fval= aint(args(1))\n case(\"anint\"); fval= anint(args(1))\n case(\"ceil\",\"ceiling\"); fval=ceiling(real(args(1)))\n case(\"exp\"); fval= exp(args(1))\n case(\"floor\"); fval= floor(real(args(1)))\n case(\"frac\"); fval= args(1)-int(args(1))\n case(\"int\"); fval= int(args(1))\n case(\"nint\"); fval= nint(args(1))\n case(\"real\"); fval= real(args(1))\n case(\"sqrt\"); fval= sqrt(args(1))\n!=======================================================================------------------------------------------------------------\n case(\"log\")\n if(args(1).le.0.0d0)then ! check for appropriate value range for function\n write(*,*)'*log* ERROR: cannot take log of ',real(args(1))\n else ! call function with one positive numeric parameter\n fval= log(args(1))\n endif\n!=======================================================================------------------------------------------------------------\n case(\"log10\")\n if(args(1).le.0.0d0)then ! check for appropriate value range for function\n write(*,*)'*log10* ERROR: cannot take log of ',real(args(1))\n else ! call function with one positive numeric parameter\n fval= log10(args(1))\n endif\n!=======================================================================------------------------------------------------------------\n end select\n endif\n!=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=------------------------------------------------------------\ncase(\"atan2\",\"dim\",\"mod\",\"bessel_jn\",\"bessel_yn\",\"sign\",\"hypot\",\"modulo\",\"scale\")\n if(n.ne.2)then ! check number of parameters\n mssge='*funcs_* incorrect number of parameters in '//wstrng2(:iend)\n ier=-1\n elseif(.not.all(iargs_type(1:2).eq.0))then ! check type of parameters\n mssge='*funcs_* parameters not all numeric in '//wstrng2(:iend)\n ier=-1\n else ! single numeric argument\n select case (wstrng2(:iend))\n case(\"atan2\"); fval= atan2 ( args(1), args(2) )\n case(\"dim\"); fval= dim ( args(1), args(2) )\n case(\"mod\"); fval= mod ( args(1), args(2) )\n case(\"modulo\"); fval= modulo ( args(1), args(2) )\n case(\"scale\"); fval= scale ( args(1), int(args(2)) )\n case(\"bessel_jn\"); fval= bessel_jn ( int(args(1)), args(2) )\n case(\"bessel_yn\"); fval= bessel_yn ( int(args(1)), args(2) )\n case(\"btest\"); fval= merge(TRUE, FALSE, btest( int(args(1)), int(args(2)) ) )\n case(\"sign\"); fval= sign ( args(1), args(2) )\n case(\"hypot\"); fval= hypot ( args(1), args(2) )\n end select\n endif\n!=======================================================================------------------------------------------------------------\ncase(\"tiny\")\n fval=tiny(0.d0)\ncase(\"epsilon\")\n fval=epsilon(0.d0)\ncase(\"huge\")\n fval=huge(0.d0)\n!=======================================================================------------------------------------------------------------\ncase(\"x\");\n ivalue=int(args(1)+0.5d0)\n if(ivalue.lt.1.or.ivalue.gt.ixy_calc)then ! if value not at least 1, or if not less than ixy_calc, report it\n mssge='*funcs_* illegal subscript value for x array'\n ier=-1\n else\n fval= x(ivalue)\n endif\n!=======================================================================------------------------------------------------------------\ncase(\"y\")\n ivalue=int(args(1)+0.5d0)\n! if value not at least 1, make it 1. if not less than ixy_calc, make it ixy_calc\n if(ivalue.lt.1.or.ivalue.gt.ixy_calc)then\n mssge='*funcs_* illegal subscript value for y array'\n ier=-1\n else\n fval= y(ivalue)\n endif\n!=======================================================================------------------------------------------------------------\ncase(\"max\")\n if(n.lt.1)then\n ier=-1\n mssge='*max* incorrect number of parameters for '//wstrng(:iend)\n elseif(.not.all(iargs_type(1:n).eq.0))then ! check type of parameters\n ier=-1\n mssge='*max* illegal parameter type (must be numeric)'\n else\n fval=args(1)\n do i=2,n\n fval=max(fval,args(i))\n enddo\n endif\n!=======================================================================------------------------------------------------------------\ncase(\"min\")\n if(n.lt.1)then\n ier=-1\n mssge='incorrect number of parameters for '//wstrng(:iend)\n elseif(.not.all(iargs_type(1:n).eq.0))then ! check type of parameters\n ier=-1\n mssge='*min* illegal parameter type (must be numeric)'\n else\n fval=args(1)\n do i=2,n\n fval=min(fval,args(i))\n enddo\n endif\n!=======================================================================------------------------------------------------------------\ncase(\"xstore\",\"ystore\") ! xstore function===>(where_to_start,value1,value2,value3...)\n if(n.lt.2)then ! need at least subscript to start storing at and a value\n ier=-1\n mssge='incorrect number of parameters for '//wstrng(:iend)\n fval=0.0d0\n else ! at least two values so something can be stored\n istoreat=int(args(1)+0.50d0) ! array subscript to start storing values at\n if(istoreat.lt.1.or.istoreat+n-2.gt.ixy_calc)then ! ignore -entire- function call if a bad subscript reference was made\n mssge='*funcs_* illegal subscript value for array in '//wstrng(:iend)\n ier=-1\n fval=0.0d0\n else ! legitimate subscripts to store at\n STEPTHRU: do i1033=2,n ! for each argument after the first one store the argument\n select case(wstrng2(:iend)) ! select X array or Y array\n case(\"xstore\");x(istoreat)=args(i1033)\n case(\"ystore\");y(istoreat)=args(i1033)\n end select\n istoreat=istoreat+1 ! increment location to store next value at\n enddo STEPTHRU\n fval=args(n) ! last value stored will become current value\n endif\n endif\n!=======================================================================------------------------------------------------------------\ncase(\"lle\",\"llt\",\"leq\",\"lge\",\"lgt\",\"lne\")\n if(iargs_type(1).eq.2.and.iargs_type(2).eq.2)then\n do i2020=1,n\n if(args(i2020).le.0.or.args(i2020).gt.size(values))then\n ier=-1\n mssge='unacceptable locations for strings encountered'\n goto 999\n endif\n enddo\n fval=FALSE ! assume false unless proven true\n i1=int(args(1))\n i2=int(args(2))\n ier=0\n select case (wstrng2(:iend))\n case(\"lle\")\n if(values(i1).le.values(i2))fval=TRUE\n case(\"llt\")\n if(values(i1).lt.values(i2))fval=TRUE\n case(\"leq\") ! if any string matches the first\n do i410=2,n\n if(iargs_type(i410).ne.2)then ! all parameters should be a string\n ier=-1\n mssge='non-string value encountered'\n elseif(values(i1).eq.values(int(args(i410)+0.5d0)))then\n fval=TRUE\n endif\n enddo\n case(\"lge\")\n if(values(i1).ge.values(i2))fval=TRUE\n case(\"lgt\")\n if(values(i1).gt.values(i2))fval=TRUE\n case(\"lne\")\n do i440=2,n\n fval=TRUE\n if(iargs_type(i440).ne.2)then ! all parameters should be a string\n ier=-1\n mssge='non-string value encountered'\n elseif(values(i1).eq.values(int(args(i440)+0.5d0)))then\n fval=FALSE\n endif\n enddo\n case default\n ier=-1\n mssge='internal error in funcs_ in lexical functions'\n end select\n else\n ier=-1\n mssge='lexical functions must have character parameters'\n endif\n!=======================================================================------------------------------------------------------------\ncase(\"le\",\"lt\",\"eq\",\"ge\",\"gt\",\"ne\")\n fval=FALSE\n do i520=1,n\n if(iargs_type(i520).ne.0)then ! this parameter was not a number\n ier=-1\n mssge='*logical* parameter was not a number'\n goto 999\n endif\n enddo\n if(n.eq.2.or.n.eq.3)then\n if(n.eq.3)then\n idig=int(args(3))\n if(idig.le.0.or.idig.gt.13)then\n mssge='*logical* precision must be between 1 and 13'\n ier=-1\n goto 999\n endif\n write(junout,'(a,3(g23.16e3,1x),i5)')'args=',args(1),args(2),args(3),idig\n write(*,*)junout\n arg1=round(args(1),idig)\n arg2=round(args(2),idig)\n write(junout,'(a,3(g23.16e3,1x),i5,1x,2(g23.16e3,1x))')'b. args=',args(1),args(2),args(3),idig,arg1,arg2\n write(*,*)junout\n else\n arg1=args(1)\n arg2=args(2)\n endif\n call stuff('LOGICAL1',arg1)\n call stuff('LOGICAL2',arg2)\n call stuff('STATUS',arg2-arg1)\n select case(wstrng2(:iend))\n case(\"le\"); if(arg1.le.arg2)fval=TRUE\n case(\"lt\"); if(arg1.lt.arg2)fval=TRUE\n case(\"eq\"); if(arg1.eq.arg2)fval=TRUE\n case(\"ge\"); if(arg1.ge.arg2)fval=TRUE\n case(\"gt\"); if(arg1.gt.arg2)fval=TRUE\n case(\"ne\"); if(arg1.ne.arg2)fval=TRUE\n case default\n ier=-1\n mssge='*logical* internal error in funcs_'\n end select\n else\n ier=-1\n mssge='*logical* must have 2 or 3 parameters'\n endif\n!=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=------------------------------------------------------------\ncase(\"ichar\")\n if(n.ne.1)then\n mssge='*ichar* takes one parameter'\n ier=-1\n elseif(iargs_type(1).ne.2)then\n mssge='*ichar* parameter must be a string'\n ier=-1\n else\n fval=ichar(values(int(args(1)))(1:1))\n endif\n!=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=------------------------------------------------------------\ncase(\"sh\")\n ii=int(args(1)+0.5d0)\n ilen=values_len(ii)\n if(ilen.ge.1)then\n call execute_command_line(values(ii)(:ilen),exitstat=idum)\n fval=idum\n else\n fval=0.0d0\n endif\n ctmp=' '\n iend=len_trim(ctmp)\n!=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=------------------------------------------------------------\ncase(\"$ge\",\"$getenv\") ! $getenv or $ge get system environment variable\n ii=int(args(1)+0.5d0)\n ilen=values_len(ii)\n if(ilen.ge.1)then\n call get_environment_variable(values(ii)(:ilen),ctmp)\n fval=len_trim(ctmp)\n if(fval.eq.0)then ! if value comes back blank and a non-blank default string is present, use it\n if(n.ge.2)then\n ii2=int(args(2)+0.5d0)\n ctmp=values(ii2)\n fval=values_len(ii2)\n endif\n endif\n fval=max(1.0d0,fval)\n else\n ctmp=' '\n fval=1.0d0\n endif\n ier=2\n iend=len_trim(ctmp)\n!=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=------------------------------------------------------------\ncase(\"if\")\n if(args(1).eq. TRUE)then\n fval=args(2)\n else\n fval=args(3)\n endif\n!=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=------------------------------------------------------------\ncase(\"$if\") ! $if function\n ier=2 ! returning string\n! check that 2nd and 3rd are acceptable string variables, should do generically at name lookup time\n if(args(1).eq. TRUE)then\n ii=int(args(2))\n else\n ii=int(args(3))\n endif\n ctmp=values(ii)\n iend=values_len(ii)\n!=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=------------------------------------------------------------\ncase(\"in\") ! in(lower_value,value,upper_value)\n fval=FALSE\n !=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n select case(n)\n !=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n case(2) ! if two parameters test }first - second}store $n(where_to_start,value1,value2,value3...)\n! ignore -entire- function call if a bad subscript reference was made\n if(ivalue.lt.1.or.ivalue+n-2.gt.ixyc_calc)then\n mssge='illegal subscript value for array in '//wstrng2(:iend)\n ier=-1\n else\n do i1066=ivalue,ivalue+n-2,1\n isub=i1066-ivalue+2\n select case(wstrng2(:iend))\n case(\"$nstore\"); nc(i1066)=values(int(args(isub)))\n case(\"$xstore\"); xc(i1066)=values(int(args(isub)))\n case(\"$ystore\"); yc(i1066)=values(int(args(isub)))\n end select\n enddo\n ctmp=values(ivalue+n-2)\n iend=len_trim(ctmp) ! very inefficient\n endif\n endif\n!=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=------------------------------------------------------------\ncase(\"str\",\"$str\",\"$\") ! \"$str\" appends numbers and strings into a new string\n ! \"str\" converts string to number IF string is simple numeric value\n jend=0\n ctmp=' '\n do i1010=1,n\n istart=jend+1 ! where to start appended argument in output string\n if(iargs_type(i1010).eq.2)then ! this parameter was a string\n in=int(args(i1010)) ! the value of a string argument is the subscript for where the string is\n jend=istart+values_len(in)-1 ! where appended argument ends in output string\n ctmp(istart:jend)=values(in)(:values_len(in))\n elseif(iargs_type(i1010).eq.0)then ! this parameter was a number\n if(args(i1010).ne.0)then\n call value_to_string(args(i1010),cnum,ilen,ier,fmt='(g23.16e3)',trimz=.true.) ! minimum of 23 characters required\n if(ier.ne.-1)then\n ilen=max(ilen,1)\n jend=istart+ilen-1\n if(cnum(ilen:ilen).eq.'.')jend=jend-1 ! this number ends in a decimal\n jend=max(jend,istart)\n if(jend.gt.len(ctmp))then\n write(*,*)'*funcs_* $str output string truncated'\n jend=len(ctmp)\n endif\n ctmp(istart:jend)=cnum(:ilen)\n endif\n else ! numeric argument was zero\n ctmp(istart:istart)='0'\n jend=jend+1\n endif\n else\n mssge='*funcs_* parameter to function $str not interpretable'\n ier=-1\n endif\n enddo\n if(ier.ge.0)then\n select case(wstrng2(:iend))\n case(\"$str\",\"$\")\n ier=2\n case(\"str\")\n ier=0\n call a_to_d_(ctmp,fval,ier) ! str function\n case default\n mssge='*funcs_* internal error: should not get here'\n ier=-1\n end select\n endif\n iend=jend\n!=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=------------------------------------------------------------\ncase(\"$x\",\"$y\",\"$n\")\n ier=2 ! returning string\n ivalue=int(args(1)+0.5d0)\n if(ivalue.lt.1.or.ivalue.gt.ixyc_calc)then ! if value not at least 1, or if not less than ixyc_calc, report it\n mssge='illegal subscript value for $x array'\n ier=-1\n else\n select case(wstrng2(:iend))\n case(\"$x\");ctmp= xc(ivalue)\n case(\"$y\"); ctmp= yc(ivalue)\n case(\"$n\"); ctmp= nc(ivalue)\n end select\n iend=len_trim(ctmp) ! very inefficient\n endif\n!=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=------------------------------------------------------------\ncase(\"unusedf\")\n fval=0.0d0\n!=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=------------------------------------------------------------\ncase(\"$l\") ! $l lower(string)\n ier=2 ! returning string\n if(n.ne.1)then\n ctmp=' '\n ier=-1\n mssge='*$l* must have one parameter'\n else\n ctmp=lower(values(int(args(1)+0.5d0)))\n iend=len_trim(ctmp) ! very inefficient\n endif\n!=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=------------------------------------------------------------\ncase(\"$u\")! $u upper(string)\n ier=2 ! returning string\n if(n.ne.1)then\n ctmp=' '\n ier=-1\n mssge='*$u* must have one parameter'\n else\n ctmp=upper(values(int(args(1)+0.5d0)))\n iend=len_trim(ctmp) ! very inefficient\n endif\n!=======================================================================------------------------------------------------------------\ncase(\"c\"); fval= myfunc(args,n) ! c(curve_number) or c(curve_number,index)\n!=======================================================================------------------------------------------------------------\ncase(\"ownmode\") ! specify whether to look for substitute_subroutine(3f) routine\n if(n.eq.1.and.iargs_type(1).eq.0)then\n if(args(1).gt.0)then\n ownon=.true.\n else\n ownon=.false.\n endif\n fval= args(1)\n else\n mssge='*ownmode* illegal arguments'\n ier=-1\n endif\n!=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=------------------------------------------------------------\ncase(\"delimx\") ! 'delimx(istore,line,delimiters) parse a string into $x array and return number of tokens\n if(n.ne.3)then ! wrong number of parameters\n ier=-1\n mssge='incorrect number of parameters for '//wstrng(:iend)\n else\n if(iargs_type(2).ne.2)then\n mssge='*delimx* second parameter not a string'\n ier=-1\n else\n ctmp=values(int(args(2)+0.5d0)) ! string to parse\n if(iargs_type(3).ne.2)then\n mssge='*delimx* delimiter parameter not a string'\n ier=-1\n else\n ctmp2=values(int(args(3)+0.5d0)) ! delimiters\n if(iargs_type(1).ne.0)then\n mssge='*delimx* first parameter not an index number'\n ier=-1\n else\n istore=int(args(1)+0.5d0) ! where to start storing into $n array at\n call delim(ctmp,['#NULL#'],ixyc_calc,icount,ibegin,iterm,ilen,ctmp2)\n if(istore.lt.1.or.istore+n-2.gt.ixyc_calc)then ! ignore entire function call if bad subscript reference was made\n mssge='illegal subscript value for array in delim'\n ier=-1\n else\n do i1060=1,icount\n xc(istore)=ctmp(ibegin(i1060):iterm(i1060))\n istore=istore+1\n enddo\n fval=icount ! return number of tokens found\n ier=0\n endif\n endif\n endif\n endif\n endif\n!=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=------------------------------------------------------------\ncase(\"round\")\n if(n.ne.2)then ! check number of parameters\n mssge='*funcs_* incorrect number of parameters in '//wstrng2(:iend)\n ier=-1\n elseif(.not.all(iargs_type(1:2).eq.0))then ! check type of parameters\n mssge='*funcs_* parameters not all numeric in '//wstrng2(:iend)\n ier=-1\n else ! single numeric argument\n fval=round(args(1),int(args(2)))\n endif\n!=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=------------------------------------------------------------\ncase(\"ifdef\")\n fval=-1\n if(n.ne.1)then ! check number of parameters\n mssge='*ifdef* incorrect number of parameters in '//wstrng(:iend)\n ier=-1\n elseif(iargs_type(1).ne.2)then ! the parameter should be a name of a variable\n mssge='*ifdef* name not a string:'//wstrng(:iend)\n ier=-1\n else\n ii=int(args(1)) ! get index into values() array\n iend1=values_len(ii) ! maximum end is at end of string\n if(values(ii)(1:1).eq.'$')then\n call locate(keys_q,values(ii)(:iend1),indexout,ierr) ! determine if the string variable name exists\n else\n call locate(keyr_q,values(ii)(:iend1),indexout,ierr) ! determine if the numeric variable name exists\n endif\n if(ierr.ne.0)then ! unexpected error\n ier=-1\n elseif(indexout.gt.0)then ! found variable name\n fval=0\n else ! did not find variable name\n fval=-1\n endif\n endif\n!=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=------------------------------------------------------------\ncase(\"ye\",\"mo\",\"da\",\"ho\",\"mi\",\"se\",\"timezone\",\"year\",\"month\",\"day\",\"hour\",\"minute\",\"second\",\"tz\")\n icalen=1 ! default value that is safe even if an error occurs\n !------------------------------------------\n call date_and_time(values=idarray)\n !------------------------------------------\n if(n.eq.0)then\n select case(wstrng2(:iend)) ! select desired subscript of value to return\n case(\"ye\",\"year\"); icalen=1 ! year\n case(\"mo\",\"month\"); icalen=2 ! month\n case(\"da\",\"day\"); icalen=3 ! day\n case(\"tz\",\"timezone\"); icalen=4 ! days since Sunday [ 0-6]\n case(\"ho\",\"hour\"); icalen=5 ! hour\n case(\"mi\",\"minute\"); icalen=6 ! minute\n case(\"se\",\"second\"); icalen=7 ! second\n case default ! report internal error if name was not matched\n ier=-1\n mssge='*calendar* internal error, unknown keyword'//wstrng2(:iend)\n end select\n if(ier.eq.0)then ! if error flag not set set return value\n fval=idarray(icalen)\n else ! error has occurred, set default return value\n fval=0.0d0\n endif\n else\n ier=-1\n mssge='*calendar* parameters not allowed'\n endif\n!=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=------------------------------------------------------------\ncase(\"$mo\") ! $mo(1-12) is \"January, February, ... \")\n ctmp=''\n ier=2 ! string will be returned\n if(n.lt.1)then ! $mo() use today\n call date_and_time(values=idarray)\n ival=idarray(2)\n elseif(n.eq.1)then ! $mo(N) just index into month names\n ival=mod(int(args(1))-1,12)+1\n if(ival.le.0)ival=ival+12\n elseif(args(2).eq.1)then ! $mo(YYYYMMDD,1) returns MM\n ival=int(args(1))\n ival=ival-((ival/10000)*10000) ! reduce to a four-digit value\n ival=ival/100 ! keep two high digits out of the four\n ival=mod(ival-1,12)+1 ! ensure in range 1 to 12\n if(ival.le.0)ival=ival+12\n else\n ival=1\n ctmp='UNKNOWN'\n iend=7\n mssge='*$mo* parameter(s) not valid'\n ier=-1\n endif\n if(ctmp.eq.'')then\n ctmp=months(ival)\n endif\n iend=len_trim(ctmp(1:20))\n!=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=------------------------------------------------------------\ncase default\n if(ownon)then\n! ==>wstrng(1:iend)=procedure name.\n! ==>iend=length of procedure name.\n! ==>args=array of ixy_calc elements containing procedure arguments.\n! ==>iargs_type=type of argument\n! ==>n=integer number of parameters\n! ==>x=array of ixy_calc x values\n! ==>y=array of ixy_calc y values\n! ==>ctmp is returned string if string function is called ( in which case fval is returned number of characters in ctmp)\n ier=0\n call mysub(wstrng(:iend),iend,args,iargs_type,n,fval,ctmp,ier)\n! <==fval=returned value to replace function call with\n! <=>ier=returned error flag. Set to -1 if an error occurs. Otherwise, user should leave it alone\n if(ier.eq.-1)then\n elseif(ier.eq.2)then\n iend=int(fval) ! string functions should return string length in fval\n if(fval.le.0)then\n mssge='*funcs_* bad length for returned string'\n ier=-1\n endif\n else\n ier=0\n endif\n else\n mssge='*funcs_* function not found: '//wstrng(:iend)\n ier=-1 ! ya done blown it if you get here\n endif\n!-----------------------------------------------------------------------------------------------------------------------------------\nend select\n!-----------------------------------------------------------------------------------------------------------------------------------\n999 continue ! return based on value of ier\n select case(ier)\n case(2) ! return string value\n call stufftok_(fval,wstrng,nchars,ctmp(:iend),iend,ier) ! add a new token variable and assign string to it\n case(0) ! return numeric value\n call value_to_string(fval,wstrng,nchars,idum,fmt='(g23.16e3)',trimz=.true.) ! minimum of 23 characters required\n case(-1) ! return error\n case default\n write(*,*)'*funcs_* unknown closing value ',ier\n ier=-1\n end select\nend subroutine funcs_\n!TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n!-----------------------------------------------------------------------------------------------------------------------------------\n!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!\n!-----------------------------------------------------------------------------------------------------------------------------------\n!>\n!!##NAME\n!! stufftok_(3fp)- [M_calculator] add a new token variable and assign string to it\n!! (LICENSE:PD)\n!!##SYNOPSIS\n!!\n!!##DESCRIPTION\n!!##OPTIONS\n!!##RETURNS\n!!##EXAMPLE\n!!\n!!##AUTHOR\n!! John S. Urban\n!!##LICENSE\n!! Public Domain\n!===================================================================================================================================\nsubroutine stufftok_(fval,wstrng,nchars,string,iend,ier)\n\n!character(len=*),parameter::ident_5=\"@(#)M_calculator::stufftok_(3fp): add a new token variable and assign string to it\"\n\nreal(kind=dp) :: fval\ncharacter(len=*) :: wstrng\ninteger :: nchars\ncharacter(len=*) :: string\ninteger :: iend\ninteger :: ier\n\ncharacter(len=5) :: toknam\n!-----------------------------------------------------------------------------------------------------------------------------------\n ktoken=ktoken+1 ! increment the counter of strings found to get a place to store into\n nchars=5\n write(toknam,'(''$_'',i3.3)')ktoken ! build a unique name for the token string found for this output string\n wstrng=toknam\n call stuffa(toknam,string(:iend)) ! cannot do this earlier or indexs from call that defined args could be wrong\n fval=0.0d0\n ier=2\n mssge=string(:iend)\nend subroutine stufftok_\n!TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n!-----------------------------------------------------------------------------------------------------------------------------------\n!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!\n!-----------------------------------------------------------------------------------------------------------------------------------\n!>\n!!##NAME\n!! args_(3fp)- [M_calculator] given 'par1,par2,...' store non-parenthesized expression par(n) into a real or string array\n!! (LICENSE:PD)\n!!##SYNOPSIS\n!!\n!!##DESCRIPTION\n!!##OPTIONS\n!!##RETURNS\n!!##EXAMPLE\n!!\n!!##AUTHOR\n!! John S. Urban\n!!##LICENSE\n!! Public Domain\n!===================================================================================================================================\nsubroutine args_(line,ilen,array,itype,iarray,ier,mx)\n\n!character(len=*),parameter::ident_6=\"&\n!&@(#)M_calculator::args_(3fp):given 'par1,par2,...' store non-parenthesized expression par(n) into a real or string array\"\n\n!@ (#) record type of par(n) into itype()\"\n!@ (#) Commas are only legal delimiters. extra or redundant delimiters are ignored.\n\n!-----------------------------------------------------------------------------------------------------------------------------------\ncharacter(len=*),intent(in) :: line ! input string\ninteger,intent(in) :: ilen ! length of input string\ninteger,intent(in) :: mx ! up to mx par(i) will be extracted. if more found an error is generated.\nreal(kind=dp),intent(out) :: array(mx)\ninteger,intent(out) :: itype(mx) ! itype=0 for number, itype=2 for string\ninteger,intent(out) :: iarray ! number of parameters found\ninteger :: ier ! ier=-1 if error occurs, ier undefined (not changed) if no error.\n!-----------------------------------------------------------------------------------------------------------------------------------\ninteger :: icalc\ninteger :: icol\ninteger :: iend\ninteger :: ilook\ninteger :: istart\ncharacter(len=1),parameter :: delimc=','\ncharacter(len=icbuf_calc) :: wstrng\n!-----------------------------------------------------------------------------------------------------------------------------------\n iarray=0\n if(ilen.eq.0)then ! check if input line (line) was totally blank\n return\n endif\n! there is at least one non-delimiter character in the command.\n! ilen is the column position of the last non-blank character\n! find next non-delimiter\n icol=1\n do ilook=1,mx,1\n do\n if(line(icol:icol).ne.delimc)then\n iarray=iarray+1\n istart=icol\n iend=index(line(istart:ilen),delimc)\n if(iend.eq.0)then ! no delimiter left\n icalc=ilen-istart+1\n wstrng=line(istart:ilen)\n ier=0\n call expressions_(wstrng,icalc,array(iarray),ier)\n itype(iarray)=ier\n return\n else\n iend=iend+istart-2\n icalc=iend-istart+1\n wstrng=line(istart:iend)\n ier=0\n call expressions_(wstrng,icalc,array(iarray),ier)\n itype(iarray)=ier\n if(ier.eq.-1)return\n endif\n icol=iend+2\n exit\n else\n icol=icol+1\n if(icol.gt.ilen)return ! last character in line was a delimiter, so no text left\n endif\n enddo\n if(icol.gt.ilen)return ! last character in line was a delimiter, so no text left\n enddo\n write(mssge,'(a,i4,a)')'more than ',mx,' arguments not allowed'\n ier=-1\nend subroutine args_\n!TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n!-----------------------------------------------------------------------------------------------------------------------------------\n!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!\n!-----------------------------------------------------------------------------------------------------------------------------------\n!>\n!!##NAME\n!! expressions_(3fp) - [M_calculator] resolve a series of terms into a single value and restring\n!! (LICENSE:PD)\n!!##SYNOPSIS\n!!\n!!##DESCRIPTION\n!!##OPTIONS\n!!##RETURNS\n!!##EXAMPLE\n!!\n!!##AUTHOR\n!! John S. Urban\n!!##LICENSE\n!! Public Domain\n!===================================================================================================================================\nsubroutine expressions_(string,nchar,value,ier)\n\n!character(len=*),parameter::ident_7=\"&\n!&@(#)M_calculator::expressions_(3fp): resolve a series of terms into a single value and restring\"\n\ncharacter(len=*),intent(inout) :: string\ninteger,intent(inout) :: nchar\nreal(kind=dp),intent(out) :: value\ninteger,intent(out) :: ier\ncharacter(len=icbuf_calc) :: dummy ! no single term may be over (icbuf_calc) characters\ninteger :: ier2\ninteger :: iend\ninteger :: iendm\ninteger :: iendp\ninteger :: ista\ninteger :: istat\ninteger :: nchar2\nreal(kind=dp) :: temp\n!-----------------------------------------------------------------------------------------------------------------------------------\n !!!!! what happens if the returned string is longer than the input string?\n value=0.0d0 ! initialize sum value to be returned to 0\n if(nchar.eq.0) return ! if this is a null string return\n ! first cut at handling string variables. assuming, with little checking, that the only string expression\n ! that can get here is a single variable name (or variable token) and that string variable names start with a $\n ! and that the error flag should be set to the value 2 to indicate that a string, not a number, is being returned\n ! for the 2 to get back, it must not be changed by this routine or anything it calls\n if(string(1:1).eq.'$')then\n call given_name_get_stringvalue_(string,ier)\n if(ier.eq.-1)return\n ier=2 ! flag that a character string is being returned\n!x return\n endif\n!x!!!!!\n ista=1 ! initialize the position of the unary sum operator for the current term\n if(index('#=',string(1:1)).ne.0)then ! check if input string starts with a unary (+-) operator\n istat=2 ! a starting unary sum operator is present, so the first term starts in column 2\n else ! input string does not start with a unary sum (-+) operator\n istat=1 ! no initial sum operator is present, so the first term starts in column 1\n endif\n do\n iendp=index(string(istat:nchar),'#') ! find left-most addition operator\n iendm=index(string(istat:nchar),'=') ! find left-most subtraction operator\n iend=min(iendp,iendm) ! find left-most sum (+-) operator assuming at least one of each exists\n if(iend.eq.0)iend=max(iendm,iendp) ! if one of the sum operators is not remaining, find left-most of remaining type\n if(iend.eq.0)then ! if no more sum operators remain this is the last remaining term\n iend=nchar ! find end character of remaining term\n else ! more than one term remains\n iend=iend+istat-2 ! find end character position of this (left-most) term\n endif\n dummy=string(istat:iend) ! set string dummy to current(left-most) term\n nchar2=iend-istat+1 ! calculate number of characters in current term\n! given that the current term ( dummy) is an optionally signed string containing only the operators **, * an / and no\n! parenthesis, reduce the string to a single value and add it to the sum of terms (value). do not change the input string.\n call pows_(dummy,nchar2,ier) ! evaluate and remove ** operators and return the altered string (dummy)\n if(ier.eq.-1) return ! if an error occurred, return\n call factors_(dummy,nchar2,temp,ier) ! evaluate and remove * and / operators, return the evaluated -value- temp\n if(ier.eq.-1)return ! if an error occurred, return\n if(string(ista:ista).eq.'=')then ! if term operator was a subtraction, subtract temp from value\n value=value-temp\n else ! operator was an addition (+) , add temp to value\n! if first term was not signed, then first character will not be a subtraction, so addition is implied\n value=value+temp\n endif\n ista=iend+1 ! calculate where next sum operator (assuming there is one) will be positioned in (string)\n istat=ista+1 ! calculate where beginning character of next term will be (if another term remains)\n if(iend.ne.nchar)then\n if(istat.gt.nchar)then ! a trailing sum operation on end of string\n ier=-1\n mssge='trailing sum operator'\n return\n endif\n ! if last term was not the end of (string) terms remain. keep summing terms\n else\n exit\n endif\n enddo\n call value_to_string(value,string,nchar,ier2,fmt='(g23.16e3)',trimz=.true.) ! convert sum of terms to string and return\n if(ier2.lt.0)ier=ier2\nend subroutine expressions_\n!TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n!-----------------------------------------------------------------------------------------------------------------------------------\n!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!\n!-----------------------------------------------------------------------------------------------------------------------------------\n!>\n!!##NAME\n!! (LICENSE:PD)\n!!##SYNOPSIS\n!!\n!! subroutine pows_(wstrng,nchar,ier)\n!!\n!! character(len=*),intent(inout) :: wstrng\n!! integer,intent(inout) :: nchar\n!! integer :: ier\n!!##DESCRIPTION\n!! given an unparenthesized string of form:\n!!\n!! stringo opo fval1 ** fval2 opo2 stringo2\n!!\n!! where opo is a preceding optional operator from set /,* and\n!! stringo is the string that would precede opo when it exists,\n!! and opo2 is an optional trailing operator from set /,*,**\n!! and stringo2 the string that would follow op2 when it exists,\n!! evaluate the expression fval1**fval2 and restring it; repeating\n!! from left to right until no power operators remain in the string\n!! or an error occurs\n!!\n!!##OPTIONS\n!! wstrng input string returned with power operators evaluated\n!! nchar input length of wstrng, returned corrected for new wstrng returned.\n!! ier error status\n!!\n!!\n!!##RETURNS\n!!##EXAMPLE\n!!\n!!##AUTHOR\n!! John S. Urban\n!!##LICENSE\n!! Public Domain\n!===================================================================================================================================\nsubroutine pows_(wstrng,nchar,ier)\n\n!character(len=*),parameter::ident_8=\"@(#)M_calculator::pows_(3fp): expand power functions in a string, working from left to right\"\n\ncharacter(len=*),intent(inout) :: wstrng ! input string returned with power operators evaluated\ninteger,intent(inout) :: nchar ! input length of wstrng, returned corrected for new wstrng returned.\ninteger :: ier ! error status\ncharacter(len=iclen_calc) :: tempch\ncharacter(len=icbuf_calc) :: dummy\ncharacter(len=1) :: z\nreal(kind=dp) :: fval1\nreal(kind=dp) :: fval2\ninteger :: i\ninteger :: id2\ninteger :: idum\ninteger :: im2\ninteger :: ip ! position of beginning of first ** operator\ninteger :: ip2\ninteger :: iright ! end of fval2 string\ninteger :: iz ! beginning of fval1 string\ninteger :: nchart\n!-----------------------------------------------------------------------------------------------------------------------------------\n INFINITE: do\n! find first occurrence of operator, starting at left and moving right\n ip=index(wstrng(:nchar),'**')\n if(ip.eq.0) then\n exit INFINITE\n elseif(ip.eq.1) then\n ier=-1\n mssge='power function \"**\" missing exponentiate'\n exit INFINITE\n elseif((ip+2).gt.nchar) then\n ier=-1\n mssge='power function \"**\" missing power'\n exit INFINITE\n endif\n!\n! find beginning of fval1 for this operator. go back to\n! beginning of string or to any previous * or / operator\n FINDVAL: do i=ip-1,1,-1\n iz=i\n z=wstrng(i:i)\n if(index('*/',z).ne.0)then ! note that use of index function was faster than .eq. on cyber\n iz=iz+1\n goto 11\n endif\n enddo FINDVAL\n iz=1\n11 continue\n if(ip-iz.eq.0)then\n ier=-1\n mssge='operator / is beside operator **'\n exit INFINITE\n endif\n!\n! now isolate beginning and end of fval2 string for current operator\n! note that looking for * also looks for ** operator, so checking\n! for * or / or ** to right\n!\n im2=index(wstrng((ip+2):nchar),'*')\n id2=index(wstrng((ip+2):nchar),'/')\n ip2=min0(im2,id2)\n if(ip2.eq.0)ip2=max0(im2,id2)\n if(ip2.eq.0)then\n iright=nchar\n elseif(ip2.eq.1)then\n ier=-1\n mssge='two operators from set [*/**] are side by side'\n exit INFINITE\n else\n iright=ip2+ip\n endif\n call a_to_d_(wstrng(iz:ip-1),fval1,ier)\n if(ier.eq.-1)then\n exit INFINITE\n endif\n call a_to_d_(wstrng(ip+2:iright),fval2,ier)\n if(ier.eq.-1)then\n exit INFINITE\n endif\n if(fval1.lt.0.0d0)then\n! this form better/safe? if(abs( fval2-int(fval2)/fval2).le..0001)\n if(fval2-int(fval2).eq.0.0d0)then\n fval1=fval1**int(fval2)\n else\n mssge='negative to the real power not allowed'\n ier=-1\n exit INFINITE\n endif\n else\n fval1=fval1**fval2\n endif\n call value_to_string(fval1,tempch,nchart,idum,fmt='(g23.16e3)',trimz=.true.) ! minimum of 23 characters required\n! place new value back into string and correct nchar.\n! note that not checking for nchar greater than (icbuf_calc)\n! in dummy or greater than len(wstrng).\n if(iz.eq.1.and.iright.eq.nchar)then ! there was only one operator and routine is done\n dummy=tempch(1:nchart)\n nchar=nchart\n else if(iz.eq.1)then ! iz was 1, but iright was nchar so\n dummy=tempch(1:nchart)//wstrng(iright+1:nchar)\n nchar=nchart+nchar-(iright+1)+1\n else if(iright.eq.nchar)then ! iz was not 1, but iright was nchar so\n dummy=wstrng(1:iz-1)//tempch(1:nchart)\n nchar=(iz-1)+nchart\n else ! iz was not 1, and iright was not nchar so\n dummy=wstrng(1:iz-1)//tempch(1:nchart)//wstrng(iright+1:nchar)\n nchar=(iz-1)+nchart+(nchar-(iright+1)+1)\n endif\n wstrng=dummy\n enddo INFINITE\nend subroutine pows_\n!TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n!-----------------------------------------------------------------------------------------------------------------------------------\n!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!\n!-----------------------------------------------------------------------------------------------------------------------------------\n!>\n!!##NAME\n!! (LICENSE:PD)\n!!##SYNOPSIS\n!!\n!!##DESCRIPTION\n!!##OPTIONS\n!!##RETURNS\n!!##EXAMPLE\n!!\n!!##AUTHOR\n!! John S. Urban\n!!##LICENSE\n!! Public Domain\n!===================================================================================================================================\nsubroutine factors_(wstrng,nchr,fval1,ier)\n\n!character(len=*),parameter::ident_9=\"&\n!&@(#)M_calculator::factors_(3fp):reduce unparenthesized string with only * and / operators to val\"\n\n!\n! The input string is unaltered. for any single pass thru the routine, the string structure is assumed to be:\n! fval1 op fval2 op fval op fval op fval op fval\n! where no blanks are in the string (only significant if string structure is bad) and the only operators are * or /.\n! working from left to right:\n! 1. locate and place into a real variable the fval1 string\n! 2. if one exists, locate and place into a real variable the fval2 string\n! 3. perform the indicated operation between fval1 and fval2\n! and store into fval1.\n! 3. repeat steps 2 thru 4 until no operators are left or\n! an error occurs.\n!\n! nchr = the position of the last non-blank character in the input string wstrng\n! ip = the position of the current operator to be used.\n! to the left of this is the fval1 string.\n! iright = the position of the last character in the fval2 string.\n! wstrng = the input string to be interpreted.\n! ier = is a flag indicating whether an error has occurred\n!-----------------------------------------------------------------------------------------------------------------------------------\ncharacter(len=*) :: wstrng\nreal(kind=dp) :: fval1\nreal(kind=dp) :: fval2\ninteger :: id\ninteger :: id2\ninteger :: ier\ninteger :: im\ninteger :: im2\ninteger :: ip\ninteger :: ip2\ninteger :: iright\ninteger :: nchr\n!-----------------------------------------------------------------------------------------------------------------------------------\n if((nchr).eq.0)then\n ier=-1\n mssge='trying to add/subtract a null string'\n return\n endif\n! find position of first operator\n im=index(wstrng(:nchr),'*')\n id=index(wstrng(:nchr),'/')\n! ip should be the position of the left-most operator\n ip=min0(im,id)\n! if one or both of the operators were not present, then\n! either im or id (or both) are zero, so look for max\n! instead of min for ip\n if(ip.eq.0) ip=max0(im,id)\n if( ip.eq.0 )then\n! no operator character (/ or *) left\n call a_to_d_(wstrng(1:nchr),fval1,ier)\n return\n elseif (ip.eq.1)then\n! if no string to left of operator, have a bad input string\n ier=-1\n mssge='first factor or quotient for \"*\" or \"/\" missing or null'\n return\n endif\n! convert located string for fval1 into real variable fval1\n call a_to_d_(wstrng(1:ip-1),fval1,ier)\n if(ier.eq.-1)return\n do\n if(ip.eq.nchr)then\n! if no string to left of operator, have a bad input string\n ier=-1\n mssge='second factor or quotient for \"*\" or \"/\" missing or null'\n return\n endif\n! locate string to put into fval2 for current operator by starting just to right of operator and ending at end of current\n! string or at next operator note that because of previous checks we know there is something to right of the operator.\n im2=index(wstrng((ip+1):nchr),'*')\n id2=index(wstrng((ip+1):nchr),'/')\n ip2=min0(im2,id2)\n if(ip2.eq.0)ip2=max0(im2,id2)\n if(ip2.eq.0)then\n iright=nchr\n elseif(ip2.eq.1)then\n ier=-1\n mssge='two operators from set [*/] are side by side'\n return\n else\n iright=ip2+ip-1\n endif\n! place located string for fval2 into real variable fval2\n call a_to_d_(wstrng(ip+1:iright),fval2,ier)\n if(ier.eq.-1)return\n! do specified operation between fval1 and fval2\n if(wstrng(ip:ip).eq.'*') then\n fval1=fval1*fval2\n else if(fval2.eq.0) then\n ier=-1\n mssge='division by zero'\n return\n else\n fval1=fval1/fval2\n endif\n if(iright.eq.nchr)return\n ip=iright+1\n enddo\nend subroutine factors_\n!TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n!-----------------------------------------------------------------------------------------------------------------------------------\n!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!\n!-----------------------------------------------------------------------------------------------------------------------------------\n!>\n!!##NAME\n!! a_to_d_(3f) - [M_calculator] returns a double precision value from a numeric character string specifically for M_calculator(3fm)\n!! (LICENSE:PD)\n!!##SYNOPSIS\n!!\n!! subroutine a_to_d_(chars,rval,ierr)\n!!\n!! character(len=*),intent(in) :: chars\n!! doubleprecision,intent(out) :: rval\n!! integer,intent(out) :: ierr\n!!\n!!##DESCRIPTION\n!! Convert a string representing a numeric scalar value to a numeric value, specifically\n!! for the M_calculator(3fp) module.Works with any g-format input, including integer, real, and exponential forms.\n!!\n!! 1. if chars=? set rval to value stored as current value, return.\n!! 2. if the string starts with a $ assume it is the name of a\n!! string variable or token and return its location as a doubleprecision number.\n!! 3. try to read string into a doubleprecision value. if successful, return.\n!! 4. if not interpretable as a doubleprecision value, see if it is a\n!! defined variable name and use that name's value if it is.\n!! 5. if no value can be associated to the string and/or if\n!! an unexpected error has occurred, set error flag and\n!! error message and set rval to zero and return.\n!! 6. note that blanks are treated as null, not zero.\n!!\n!!##OPTIONS\n!! chars is the input string\n!! rval is the doubleprecision output value\n!! ierr 0 if no error occurs\n!!\n!!##EXAMPLE\n!!\n!!\n!!##VERSION\n!! o 07/15/1986 J. S. Urban\n!! o 12/28/1987 modified to specify bn in formats for reads. vax\n!! defaults to zero-fill on internal files.\n!! o 12/22/2016 Changed to generate man(1) pages via ufpp(1).\n!!##AUTHOR\n!! John S. Urban\n!!##LICENSE\n!! Public Domain\n!===================================================================================================================================\nsubroutine a_to_d_(chars,rval8,ierr)\n\n!character(len=*),parameter::ident_10=\"&\n!&@(#)M_calculator::a_to_d_(3f):returns a real value rval8 from a numeric character string chars.\"\n\n! CAREFUL: LAST is in GLOBAL, but can be read from when passed to this routine as CHARS. DO NOT CHANGE CHARS.\ncharacter(len=*),intent(in) :: chars\ncharacter(len=:),allocatable :: chars_local\nreal(kind=dp),intent(out) :: rval8\ninteger,intent(out) :: ierr\n!-----------------------------------------------------------------------------------------------------------------------------------\ncharacter(len=13) :: frmt\ninteger :: ier\ninteger :: indx\ninteger :: ioerr\n!-----------------------------------------------------------------------------------------------------------------------------------\n ioerr=0\n chars_local=trim(adjustl(chars))//' ' ! minimum of one character required\n if(chars_local.eq.'?')then ! if string is a (unsigned) question mark, use value returned from last completed calculation\n !x!read(last,'(bn,g512.40)',iostat=ioerr,err=9991)rval8 ! assuming cannot get a read error out of reading last\n write(frmt,101)len(last) ! build a format statement to try and read the string as a number with\n chars_local=trim(last)//repeat(' ',512) ! kludge: problems if string is not long enough for format\n read(chars_local,fmt=frmt,iostat=ioerr,err=9991)rval8 ! try and read the string as a number\n elseif('$'.eq.chars_local(1:1))then ! string is a string variable name\n call locate(keys_q,chars_local,indx,ier) ! try to find the index in the character array for the string variable\n if(indx.le.0)then ! if indx is not .gt. 0 string was not a variable name\n ierr=-1\n mssge='undeclared string variable '//chars_local\n else\n rval8=real(indx) ! set value to position of string in the string array\n !!!! flag via a value for ierr that a string, not a number, has been found\n endif\n return\n ! no error on read on Sun on character string as a number, so make sure first character not numeric and try as variable name\n elseif(index('0123456789.-+',chars_local(1:1)).eq.0)then ! does not start with a numeric character. try as a variable name\n call locate(keyr_q,chars_local,indx,ier)\n if(indx.le.0)then ! if indx is not .gt. 0 string was not a variable name\n ierr=-1\n mssge='*a_2_d_* undeclared variable ['//chars_local//']'\n else\n rval8=values_d(indx)\n endif\n return\n else ! string is a number or a numeric variable name that starts with a numeric character\n write(frmt,101)len(chars_local) ! build a format statement to try and read the string as a number with\n101 format( '(bn,g',i5,'.0)' )\nchars_local=chars_local//repeat(' ',512) ! kludge: problems if string is not long enough for format\n read(chars_local,fmt=frmt,iostat=ioerr,err=999)rval8 ! try and read the string as a number\n chars_local=trim(chars_local)\n endif\n return ! string has successfully been converted to a number\n9991 continue ! string could not be read as number,so try as variable name that starts with number\n999 continue ! string could not be read as number,so try as variable name that starts with number\n rval8=0.0d0\n indx=0\n ! either here because of a read error (too big, too small, bad characters in string) or this is a variable name\n ! or otherwise unreadable.\n !!!!! look carefully at what happens with a possible null string\n call locate(keyr_q,chars_local,indx,ier)\n if(indx.le.0)then ! if indx is not .gt. 0 string was not a variable name\n mssge='bad variable name or unusable value = '//chars_local\n ierr=-1\n else\n rval8=values_d(indx)\n endif\nend subroutine a_to_d_\n!TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n!-----------------------------------------------------------------------------------------------------------------------------------\n!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!\n!-----------------------------------------------------------------------------------------------------------------------------------\n!>\n!!##NAME\n!! squeeze_ - [M_calculator] change +-[] to #=(),replace strings with placeholders,delete comments\n!! (LICENSE:PD)\n!!\n!!##DESCRIPTION\n!! remove all blanks from input string and return position of last non-blank character in nchars using imax as the highest\n!! column number to search in. return a zero in nchars if the string is blank.\n!!\n!! replace all + and - characters with the # and = characters which will be used to designate + and - operators, as opposed to\n!! value signs.\n!!\n!! replace [] with ()\n!!\n!! remove all strings from input string and replace them with string tokens and store the values for the string tokens.\n!! assumes character strings are (iclen_calc) characters max.\n!! if string is delimited with double quotes, the double quote character may be represented inside the string by\n!! putting two double quotes beside each other (\"he said \"\"greetings\"\", i think\" ==> he said \"greetings\", i think)\n!!\n!! !!!! if an equal sign is followed by a colon the remainder of the input line is placed into a string as-is\n!! !!!! without the need for delimiting it. ($string1=: he said \"greetings\", i think ==> he said \"greetings\", i think)\n!!\n!! anything past an # is considered a comment and ignored\n!!\n!! assumes length of input string is less than (icbuf_calc) characters\n!!\n!! if encounters more than one equal sign, uses right-most as the\n!! end of variable name and replaces others with & and makes a\n!! variable name out of it (ie a=b=10 ===> a&b=10)\n!!\n!! !!!!the length of string could actually be increased by converting quoted strings to tokens\n!!\n!! !!!!maybe change this to allow it or flag multiple equal signs?\n!!\n!! !!!!no check if varnam is a number or composed of characters\n!! !!!!like ()+-*/. . maybe only allow a-z with optional numeric\n!! !!!!suffix and underline character?\n!!\n!! !!!!variable names ending in letter e can be confused with\n!! !!!!e-format numbers (is 2e+20 the variable 2e plus 20 or\n!! !!!!the single number 200000000000000000000?). to reduce\n!! !!!!amount of resources used to check for this, and since\n!! !!!!words ending in e are so common, will assume + and -\n!! !!!!following an e are part of an e-format number if the\n!! !!!!character before the e is a period or digit (.0123456789).\n!! !!!!and won't allow variable names of digit-e format).\n!!\n!! !!!!make sure variable called e and numbers like e+3 or .e+3 are handled satisfactorily\n!!\n!!##AUTHOR\n!! John S. Urban\n!!##LICENSE\n!! Public Domain\n!===================================================================================================================================\nsubroutine squeeze_(string,imax,nchars,varnam,nchar2,ier)\n\n!character(len=*),parameter::ident_11=\"&\n!&@(#)M_calculator::squeeze_(3fp):change +-[] to #=(),replace strings with placeholders,delete comments\"\n\ninteger, parameter :: ilen=(icbuf_calc)+2\ncharacter(len=*) :: string\ninteger :: imax\ninteger,intent(out) :: nchars\ncharacter(len=icname_calc),intent(out) :: varnam\ninteger,intent(out) :: nchar2\ninteger,intent(out) :: ier\ncharacter(len=ilen) :: dummy\ncharacter(len=1) :: back1\ncharacter(len=1) :: back2\ninteger :: iplace\ncharacter(len=1) :: currnt\ncharacter(len=iclen_calc) :: ctoken\n!!character(len=10),parameter :: list =' +-=\"#[]{}' ! list of special characters\n!!character(len=10),parameter :: list2 =' #=& ()()' ! list of what to convert special characters too when appropriate\ncharacter(len=5) :: toknam\ninteger :: i10\ninteger :: i20\ninteger :: idum\ninteger :: ilook\ninteger :: indx\ninteger :: instring\ninteger :: ipoint\ninteger :: ivar\ninteger :: kstrln\n!-----------------------------------------------------------------------------------------------------------------------------------\n! keep track of previous 2 non-blank characters in dummy for when trying to distinguish between e-format numbers\n! and variables ending in e.\n back1=' '\n back2=' '\n varnam=' ' ! initialize output variable name to a blank string\n ivar=0\n nchar2=0\n nchars=0 ! the position of the last non-blank character in the output string (string)\n dummy(1:2)=' '\n!-----------------------------------------------------------------------------------------------------------------------------------\n! instead of just copy string to buffer, cut out rows of sign operators\n! dummy(3:)=string\n dummy=' '\n idum=3\n instring=0\n do i10=1,len_trim(string)\n ! if adjacent sign characters skip new character and maybe change sign of previous character\n if(string(i10:i10).eq.'\"'.and.instring.eq.0 )then ! starting a string\n instring=1\n elseif(string(i10:i10).eq.'\"'.and.instring.eq.1)then ! ending a string\n instring=0\n endif\n if(instring.ne.1)then\n if(string(i10:i10).eq.'+')then ! if found a + look to see if previous a + or -\n if(dummy(idum-1:idum-1).eq.'+')then ! last character stored was also a sign (it was +)\n cycle ! skip because ++ in a row\n elseif(dummy(idum-1:idum-1).eq.'-')then ! skip -+ and just leave -\n cycle\n endif\n elseif(string(i10:i10).eq.'-')then ! last character stored was also a sign (it was -)\n if(dummy(idum-1:idum-1).eq.'+')then ! +- in a row\n dummy(idum-1:idum-1)='-' ! change sign of previous plus\n cycle ! skip because +- in a row\n elseif(dummy(idum-1:idum-1).eq.'-')then ! skip but change sign of previous\n dummy(idum-1:idum-1)='+' ! change -- to +\n cycle\n endif\n endif\n endif\n ! character not skipped\n dummy(idum:idum)=string(i10:i10) ! simple copy of character\n idum=idum+1\n enddo\n!-----------------------------------------------------------------------------------------------------------------------------------\n string=' '\n ipoint=2 ! ipoint is the current character pointer for (dummy)\n ktoken=0 ! initialize the number of strings found in this string\n BIG: do ilook=1,imax\n ipoint=ipoint+1 ! move current character pointer forward\n currnt=dummy(ipoint:ipoint) ! store current character into currnt\n select case(currnt) ! check to see if current character has special meaning and requires processing ' +-=\"#[]{}'\n!-----------------------------------------------------------------------------------------------------------------------------------\n case(\" \") ! current is a blank not in a string. ignore it\n cycle BIG\n!-----------------------------------------------------------------------------------------------------------------------------------\n case(\"+\") ! current is a plus\n if(back1.eq.'e'.or.back1.eq.'E')then ! if previous letter was an e it could be e-format sign or operator.\n! note not using dummy directly, as it may contain blanks letter before +- was an e. must decide if the +- is part of\n! an e-format number or intended to be the last character of a variable name.\n!!!!! what is effect on a---b or other +- combinations?\n ! if letter before e is not numeric this is a variable name and - is an operator\n if(index('0123456789.',back2).eq.0)then\n currnt=\"#\" ! no digit before the e, so the e is the end of a variable name\n else ! digit before e, so assume this is number and do not change +- to #= operators\n endif\n else\n currnt=\"#\" ! previous letter was not e, so +- is an operator so change +- to #= operators\n endif\n!-----------------------------------------------------------------------------------------------------------------------------------\n case(\"-\") ! current is a minus\n if(back1.eq.'e'.or.back1.eq.'E')then ! if previous letter was an e it could be e-format sign or operator.\n! note not using dummy directly, as it may contain blanks letter before +- was an e. must decide if the +- is part of\n! an e-format number or intended to be the last character of a variable name.\n!!!!! what is effect on a---b or other +- combinations?\n ! if letter before e is not numeric this is a variable name and - is an operator\n if(index('0123456789.',back2).eq.0)then\n currnt=\"=\" ! no digit before the e, so the e is the end of a variable name\n else ! digit before e, so assume this is number and do not change +- to #= operators\n endif\n else\n currnt=\"=\" ! previous letter was not e, so +- is an operator so change +- to #= operators\n endif\n!-----------------------------------------------------------------------------------------------------------------------------------\n case(\"=\") ! current is a plus or minus\n currnt=\"&\"\n ivar=nchars+1 ! ivar is the position of an equal sign, if any\n!=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n case (\"{\", \"[\")\n currnt='(' ! currnt is [ or { . Replace with (\n case (\"}\", \"]\")\n currnt=')' ! currnt is ] or }, . Replace with )\n!=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n case(\"#\") ! any remainder is a comment\n exit\n!=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n case('\"') ! if character starts a quoted string, extract it and replace it with a token\n! figure out length of string, find matching left double quote, reduce internal \"\" to \"\n kstrln=0 ! initialize extracted string length\n ctoken=' ' ! initialize extracted string\n do i20 = ipoint+1,imax+2 ! try to find a matching double quote to the right of the first\n ipoint=ipoint+1\n if(dummy(ipoint:ipoint).eq.'\"')then !!!!! caution : could look at dummy(imax+1:imax+1)\n if(dummy(ipoint+1:ipoint+1).ne.'\"')then ! this is the end of the string\n goto 30\n else ! this is being used to try and represent an internal double-quote\n kstrln=kstrln+1 ! determine length of string to remove\n ctoken(kstrln:kstrln)=dummy(ipoint:ipoint) ! store the character into the current string storage\n ipoint=ipoint+1\n endif\n else ! this is an internal character of the current string\n kstrln=kstrln+1 ! determining length of string to remove\n ctoken(kstrln:kstrln)=dummy(ipoint:ipoint) ! store the character into the current string storage\n endif\n enddo\n ier=-1 ! if you get here an unmatched string delimiter (\") has been detected\n mssge='unmatched quotes in a string'\n return\n30 continue\n!!!!! check that current token string is not over (iclen_calc) characters long . what about the string \"\" or \"\"\"\" or \"\"\" ?\n ktoken=ktoken+1 ! increment the counter of strings found\n write(toknam,'(''$_'',i3.3)')ktoken ! build a unique name for the token string found for this input string\n nchars=nchars+1 ! increment counter of characters stored\n string(nchars:nchars+4)=toknam ! replace original delimited string with its token\n nchars=nchars+4\n! store the token name and value in the string variable arrays\n call locate(keys_q,toknam,indx,ier) ! determine storage placement of the variable and whether it is new\n if(ier.eq.-1)return\n iplace=iabs(indx)\n if(indx.le.0)then ! check if the token name needs added or is already defined\n call insert(keys_q,toknam, iplace) ! adding the new variable name to the variable name array\n call insert(values,' ' , iplace)\n call insert(values_len,0 , iplace)\n endif\n call replace(values,ctoken(:kstrln),iplace) ! store a defined variable's value\n call replace(values_len,kstrln,iplace) ! store length of string\n!!!!! note that reserving variable names starting with $_ for storing character token strings\n cycle BIG\n!=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n case default ! current is not one of the special characters in list\n end select\n!=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n ! for all but blank characters and strings\n back2=back1\n back1=currnt\n nchars=nchars+1\n string(nchars:nchars)=currnt\n!=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n enddo BIG\n!=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n! end of string or hit beginning of comment\n\n if(ivar.ne.0)then ! check to see if a variable name was defined:\n nchar2=ivar-1 ! variable was declared nchar2 is the position of the last character in the variable name\n if(nchar2.gt.20)then\n ier=-1\n mssge='new variable names must be 20 characters long or less'\n else if(nchar2.eq.0)then\n ier=-1\n mssge='input starts with =; cannot define a null variable name'\n else ! split up variable name and expression\n ! legal length variable name\n if(index('eE',string(nchar2:nchar2)).ne.0.and.nchar2.ne.1)then ! could be an unacceptable variable name\n if(index('0123456789',string(nchar2-1:nchar2-1)).ne.0)then\n! an unacceptable variable name if going to avoid conflict with\n! e-format numbers in a relatively straight-forward manner\n mssge='variable names ending in digit-e not allowed'\n ier=-1\n endif\n endif\n dummy=string\n varnam=dummy(1:ivar-1)\n if(nchars.ge.ivar+1)then\n string=dummy(ivar+1:nchars)\n else\n string=' '\n endif\n nchars=nchars-ivar\n endif\n endif\nend subroutine squeeze_\n!TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n!-----------------------------------------------------------------------------------------------------------------------------------\n!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!\n!-----------------------------------------------------------------------------------------------------------------------------------\n!>\n!!##NAME\n!! [M_calculator] given_name_get_stringvalue_(3fp) - return associated value for variable name\"\n!! (LICENSE:PD)\n!!##SYNOPSIS\n!!\n!! subroutine given_name_get_stringvalue_(chars,ierr)\n!!\n!! character(len=*),intent(in) :: chars\n!! integer,intent(out) :: ierr\n!!##DESCRIPTION\n!! return the actual string when given a string variable name or token\n!! the returned string is passed thru the message/string/error GLOBAL variable\n!!##OPTIONS\n!! CHARS\n!! IER ierr is set and returned as\n!!\n!! -1 an error occurs\n!! 2 a string is returned\n!!##RETURNS\n!! MSSGE when successful the variable value is returned through the global variable MSSGE\n!!\n!!##EXAMPLE\n!!\n!!##AUTHOR\n!! John S. Urban\n!!##LICENSE\n!! Public Domain\n!===================================================================================================================================\nsubroutine given_name_get_stringvalue_(chars,ierr)\n\n!character(len=*),parameter::ident_12=\"@(#)M_calculator::given_name_get_stringvalue_(3fp):return associated value for variable name\"\n\n!-----------------------------------------------------------------------------------------------------------------------------------\ncharacter(len=*),intent(in) :: chars\ninteger,intent(out) :: ierr\n!-----------------------------------------------------------------------------------------------------------------------------------\n integer :: index\n!-----------------------------------------------------------------------------------------------------------------------------------\n ierr=0\n index=0\n call locate(keys_q,chars,index,ierr)\n if(ierr.eq.-1) then\n elseif(index.le.0)then\n ierr=-1\n!!!! what if len(chars) is 0? look carefully at what happens with a possible null string\n mssge=' variable '//trim(chars)//' is undefined'\n else\n ierr=2\n mssge=values(index)\n endif\nend subroutine given_name_get_stringvalue_\n!TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n!-----------------------------------------------------------------------------------------------------------------------------------\n!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!\n!-----------------------------------------------------------------------------------------------------------------------------------\n!>\n!!##NAME\n!! stuff(3f) - [M_calculator] directly store value into calculator dictionary for efficiency\n!! (LICENSE:PD)\n!!\n!!##SYNOPSIS\n!!\n!! subroutine stuff(varnam,val)\n!!\n!! class(*),intent(in) :: varnam\n!! character(len=*),intent(in) :: val\n!!\n!!##DEFINITION\n!! breaking the rule of only accessing the calculator thru calculator(3f):\n!!\n!! a direct deposit of a value into the calculator assumed to\n!! be used only by friendly calls, for efficiency and to avoid\n!! problems with recursion if a routine called by the calculator\n!! in substitute_subroutine(3f) wants to store something back into the calculator\n!! variable table\n!!\n!! Normally values are stored or defined in the calculator module\n!! M_calculator(3fm) using the calculator(3f) routine or the convenience\n!! routines in the module M_calculator(3fm). For efficiency when\n!! large numbers of values require being stored the stuff(3f) procedure\n!! can be used to store numeric values by name in the calculator\n!! dictionary.\n!!\n!! breaking the rule of only accessing the calculator thru calculator(3f):\n!!\n!! stuff(3f) is assumed to only be used when needed for efficiency and to\n!! avoid problems with recursion if a routine called by the calculator\n!! in substitute_subroutine(3f) wants to store something back into the\n!! calculator variable table.\n!!\n!!##OPTIONS\n!! varnam name of calculator variable to define or replace val\n!! numeric value to associate with the name VARNAME. May be\n!! integer, real, or doubleprecision.\n!!\n!!##EXAMPLE\n!!\n!! Sample program:\n!!\n!! program demo_stuff\n!! use M_calculator, only : stuff, dnum0\n!! implicit none\n!! doubleprecision :: value\n!! call stuff('A',10.0)\n!! call stuff('PI',3.141592653589793238462643383279502884197169399375105820974944592307d0)\n!! value=dnum0('A*PI')\n!! write(*,*)value\n!! end program demo_stuff\n!!\n!! Expected result:\n!!\n!! 31.415926535897931\n!!\n!!##AUTHOR\n!! John S. Urban\n!!##LICENSE\n!! Public Domain\n!===================================================================================================================================\nsubroutine stuff(varnam,value)\n\n!character(len=*),parameter::ident_14=\"&\n!&@(#)M_calculator::stuff(3fp): pass key value and integer|real|doubleprecision value to dictionary(3f) as doubleprecision\"\n\ncharacter(len=*),intent(in) :: varnam ! variable name to add or replace value of\nclass(*),intent(in) :: value\n\nreal(kind=dp) :: val8 ! input value to store\ncharacter(len=:),allocatable :: varnam_local ! some trouble with variable length character strings on some machines\ninteger :: ierr\ninteger :: index\ninteger :: istart\n!-----------------------------------------------------------------------------------------------------------------------------------\n varnam_local=adjustl(trim(varnam))//' ' ! remove leading spaces but make sure at least one character long\n if(varnam_local(1:1).eq.'$')then ! add new variable to numeric value dictionary at specified location\n mssge='*stuff* numeric variable names must not start with a $'\n ierr=-1\n return\n endif\n!-----------------------------------------------------------------------------------------------------------------------------------\n ierr=0\n call locate(keyr_q,varnam_local,index,ierr)\n istart=iabs(index)\n if(index.le.0)then ! add entry to dictionary\n call insert(keyr_q,varnam_local,istart)\n call insert(values_d,0.0d0,istart)\n endif\n\n select type(value)\n type is (integer); val8=dble(value)\n type is (real); val8=dble(value)\n type is (doubleprecision); val8=value\n end select\n call replace(values_d,val8,istart)\n!-----------------------------------------------------------------------------------------------------------------------------------\nend subroutine stuff\n!TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n!-----------------------------------------------------------------------------------------------------------------------------------\n!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!\n!-----------------------------------------------------------------------------------------------------------------------------------\n!>\n!!##NAME\n!! stuffa(3f) - [M_calculator] stuffa(3f): directly store a string into calculator variable name table\n!! (LICENSE:PD)\n!!##SYNOPSIS\n!!\n!! subroutine stuffa(varnam,string)\n!!\n!! character(len=*),intent(in) :: varnam\n!! character(len=*),intent(in) :: string\n!!\n!!##DEFINITION\n!! Breaking the rule of only accessing the calculator thru calculator(3f):\n!!\n!! a direct deposit of a value into the calculator assumed to be used\n!! only by friendly calls, for efficiency and to avoid problems with\n!! recursion if a routine called by the calculator in JUOWN1(3f) wants\n!! to store something back into the calculator\n!! variable table.\n!!\n!!##OPTIONS\n!! varnam variable name to create or replace in calculator module\n!! string string to associate with the calculator variable name varnam\n!!##EXAMPLE\n!!\n!! Sample program:\n!!\n!! program demo_stuffa\n!! use M_calculator, only : stuffa\n!! use M_calculator, only : snum0\n!! implicit none\n!! call stuffa('$A','')\n!! call stuffa('$mystring','this is the value of the string')\n!! write(*,*)snum0('$mystring')\n!! call stuffa('$mystring','this is the new value of the string')\n!! write(*,*)snum0('$mystring')\n!! end program demo_stuffa\n!!##AUTHOR\n!! John S. Urban\n!!##LICENSE\n!! Public Domain\n!===================================================================================================================================\nsubroutine stuffa(varnam,string)\n\n!character(len=*),parameter::ident_15=\"@(#)M_calculator::stuffa(3f): directly store a string into calculator variable name table\"\n\ncharacter(len=*),intent(in) :: varnam ! assuming friendly, not checking for null or too long varnam0\ncharacter(len=:),allocatable :: varnam_local\ncharacter(len=*),intent(in) :: string\ninteger :: indx\ninteger :: ierr\n!-----------------------------------------------------------------------------------------------------------------------------------\n varnam_local=adjustl(trim(varnam))\n ierr=0\n!-----------------------------------------------------------------------------------------------------------------------------------\n call locate(keys_q,varnam_local,indx,ierr)\n if(indx.le.0)then ! variable name not in dictionary\n indx=iabs(indx)\n call insert(keys_q,varnam_local,indx) ! adding the new variable name to the variable name array\n call insert(values,' ' ,indx)\n call insert(values_len,0 ,indx)\n endif\n ! found variable name in dictionary\n call replace(values,string,indx)\n call replace(values_len,len_trim(string),indx)\n!-----------------------------------------------------------------------------------------------------------------------------------\nend subroutine stuffa\n!TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n!-----------------------------------------------------------------------------------------------------------------------------------\n!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!\n!-----------------------------------------------------------------------------------------------------------------------------------\n!>\n!!##NAME\n!! inum0(3f) - [M_calculator] return integer value from calculator expression\n!! (LICENSE:PD)\n!!##SYNOPSIS\n!!\n!! integer function inum0(inline,ierr)\n!!\n!! character(len=*),intent(in) :: inline\n!! integer,optional,intent(out) :: ierr\n!!\n!!##SYNOPSIS\n!!\n!! INUM0() evaluates a CHARACTER argument as a FORTRAN-like\n!! calculator expression and returns an integer.\n!!\n!! o INUM0() uses the calculator routine CALCULATOR(3f)\n!! o Remember that the calculator treats all values as DOUBLEPRECISION.\n!!\n!! Values returned are assumed to be very close to being whole integer\n!! values. A small value (0.01) is added to the result before it is\n!! returned to reduce roundoff error problems. This could introduce\n!! errors if INUM0 is misused and is not being used to calculate\n!! essentially integer results.\n!!##DESCRIPTION\n!!\n!! inline INLINE is a CHARACTER variable up to 255 characters long that is\n!! similar to a FORTRAN 77 numeric expression. Keep it less than 80\n!! characters when possible.\n!! ierr zero (0) if no error occurs\n!!\n!!##DEPENDENCIES\n!! All programs that call the calculator routine can supply their\n!! own substitute_subroutine(3f) and substitute_C(3f) procedures. See\n!! the ../html/Example.html\">example program for samples.\n!!##EXAMPLES\n!!\n!! Sample program:\n!!\n!! program demo_inum0\n!! use M_calculator, only : inum0\n!! i=inum0('20/3.4')\n!! j=inum0('CI = 13 * 3.1')\n!! k=inum0('CI')\n!! write(*,*)'Answers are ',I,J,K\n!! end program demo_inum0\n!!\n!!##SEE ALSO\n!! The syntax of an expression is as described in\n!! the main document of the Calculator Library.\n!! See\n!! CALCULATOR(),\n!! RNUM0(),\n!! DNUM0(),\n!! SNUM0(),\n!! EXPRESSION()\n!!##AUTHOR\n!! John S. Urban\n!!##LICENSE\n!! Public Domain\n!===================================================================================================================================\n!>\n!! AUTHOR: John S. Urban\n!!##VERSION: 19971123\n!===================================================================================================================================\n!-----------------------------------------------------------------------------------------------------------------------------------\ninteger function inum0(inline,ierr)\n\n!character(len=*),parameter::ident_16=\"@(#)M_calculator::inum0(3f):resolve a calculator string into a whole integer number\"\n\n! The special string '*' returns -99999, otherwise return 0 on errors\ncharacter(len=*),intent(in) :: inline\ninteger,optional,intent(out) :: ierr\n!-----------------------------------------------------------------------------------------------------------------------------------\ninteger,parameter :: IBIG=2147483647 ! overflow value (2**31-1)\ninteger :: iend\nreal,parameter :: SMALL=0.0001 ! and epsilon value\ndoubleprecision :: dnum1\ncharacter(len=iclen_calc) :: cdum20\ninteger :: ierr_local\ninteger :: ilen\n!-----------------------------------------------------------------------------------------------------------------------------------\nierr_local=0\nif(inline.eq.' ')then ! return 0 for a blank string\n dnum1=0.0d0\nelseif(inline.eq.'*')then ! return -99999 on special string \"*\"\n dnum1=-99999d0\nelse ! parse string using calculator function\n iend=len(inline)\n call expression(inline(:iend),dnum1,cdum20,ierr_local,ilen)\n if(ierr_local.ne.0)then\n dnum1=0.0d0\n endif\nendif\nif(present(ierr))then\n ierr=ierr_local\nendif\n!-----------------------------------------------------------------------------------------------------------------------------------\n! on most machines int() would catch the overflow, but this is safer\nif(dnum1.gt.IBIG)then\n write(*,*)'*inum0* integer overflow 2**31-1 <',dnum1\n inum0=IBIG\nelseif(dnum1.gt.0)then\n inum0=int(dnum1+SMALL)\nelse\n inum0=int(dnum1-SMALL)\nendif\n!-----------------------------------------------------------------------------------------------------------------------------------\nend function inum0\n!===================================================================================================================================\n!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()=\n!===================================================================================================================================\n!>\n!!##NAME\n!! rnum0(3f) - [M_calculator] returns real number from string expression using CALCULATOR(3f)\n!! (LICENSE:PD)\n!!##SYNOPSIS\n!!\n!! real function rnum0(inline)\n!!\n!! character(len=*), intent=(in) :: inline\n!! integer,intent(out),optional :: ierr\n!!\n!!##DESCRIPTION\n!! RNUM0() is used to return a REAL value from a CHARACTER string representing\n!! a numeric expression. It uses the M_calculator(3fp) module.\n!!\n!! inline INLINE is a CHARACTER variable up to (iclen_calc=512) characters long\n!! that is similar to a FORTRAN 77 numeric expression.\n!! ierr error code. If zero, no error occurred\n!!\n!!##DEPENDENCIES\n!! o User-supplied routines:\n!! All programs that call the calculator routine can supply their\n!! own substitute_subroutine(3f) and substitute_C(3f) procedures. See\n!! the example program for samples.\n!!##EXAMPLES\n!!\n!! Sample program\n!!\n!! program demo_rnum0\n!! use M_calculator, only : rnum0\n!! x=rnum0('20/3.4')\n!! y=rnum0('CI = 10 * sin(3.1416/4)')\n!! z=rnum0('CI')\n!! write(*,*)x,y,z\n!! end program demo_rnum0\n!!\n!!##SEE ALSO\n!!\n!! o The syntax of an expression is as described in the main documentation\n!! of the Calculator Library.\n!! o See EXPRESSION(3f), CALCULATOR(3f), INUM0(3f), DNUM0(3f), SNUM0(3f).\n!!\n!!##AUTHOR\n!! John S. Urban\n!!##LICENSE\n!! Public Domain\n!===================================================================================================================================\n!>\n!! AUTHOR John S. Urban\n!!##VERSION 1.0,19971123\n!===================================================================================================================================\nreal function rnum0(inline,ierr)\n\n!character(len=*),parameter::ident_17=\"@(#)M_calculator::rnum0(3f):resolve a calculator string into a real number\"\n\n!-----------------------------------------------------------------------------------------------------------------------------------\ncharacter(len=*),intent(in) :: inline\ninteger,optional,intent(out) :: ierr\n!-----------------------------------------------------------------------------------------------------------------------------------\ncharacter(len=iclen_calc) :: cdum20\ndoubleprecision :: d_answer\ninteger :: ierr_local\ninteger :: ilen\ninteger :: iend\n!-----------------------------------------------------------------------------------------------------------------------------------\n ierr_local=0\n if(inline.eq.' ')then\n d_answer=0.0d0\n elseif(inline.eq.'*')then ! the special string '*' returns -99999.0\n d_answer=-99999.0d0\n else\n iend=len(inline)\n call expression(inline(:iend),d_answer,cdum20,ierr_local,ilen)\n if(ierr_local.ne.0)then\n d_answer=0.0d0\n endif\n endif\n if(present(ierr))then\n ierr=ierr_local\n endif\n rnum0=real(d_answer)\n!-----------------------------------------------------------------------------------------------------------------------------------\nend function rnum0\n!===================================================================================================================================\n!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()=\n!===================================================================================================================================\n!>\n!!##NAME\n!! dnum0(3f) - [M_calculator] return double precision value from string expression using calculator(3f)\n!! (LICENSE:PD)\n!!##SYNOPSIS\n!!\n!! doubleprecision function dnum0(inline,ierr)\n!!\n!! character(len=*),intent(in) :: inline\n!! integer,optional,intent(out) :: ierr\n!!\n!!##DESCRIPTION\n!! DNUM0() is used to return a DOUBLEPRECISION value from a CHARACTER string\n!! representing a numeric expression.\n!! o If an error occurs in evaluating the expression INUM() returns zero(0).\n!! o DNUM0() ultimately uses the calculator routine CALCULATOR(3f)\n!!\n!! inline INLINE is a CHARACTER variable up to (iclen_calc=255) characters long\n!! that is similar to a FORTRAN 77 numeric expression.\n!! ierr error code. If zero, no error occurred\n!!\n!!##EXAMPLES\n!!\n!! Sample Program\n!!\n!! program demo_dnum0\n!! use M_calculator, only : dnum0\n!! doubleprecision x,y,z\n!! X=DNUM0('20/3.4')\n!! Y=DNUM0('CI = 10 * sin(3.1416/4)')\n!! Z=DNUM0('CI')\n!! write(*,*)x,y,z\n!! end program demo_dnum0\n!!\n!!##SEE ALSO\n!!\n!! o The syntax of an expression is as described in the main documentation of the Calculator Library.\n!! o See EXPRESSION(), CALCULATOR(), RNUM0(), SNUM0().\n!!\n!!##AUTHOR\n!! John S. Urban\n!!##LICENSE\n!! Public Domain\n!===================================================================================================================================\n!>\n!! AUTHOR + John S. Urban\n!!##VERSION 1.0, 19971123\n!===================================================================================================================================\ndoubleprecision function dnum0(inline,ierr)\n\n!character(len=*),parameter::ident_18=\"@(#)M_calculator::dnum0(3f):resolve a calculator string into a doubleprecision number\"\n\ncharacter(len=*),intent(in) :: inline\ninteger,optional,intent(out) :: ierr\ncharacter(len=iclen_calc) :: cdum20\ndoubleprecision :: dnum1\ninteger :: iend\ninteger :: ierr_local\ninteger :: ilen\n ierr_local=0\n if(inline.eq.' ')then\n dnum1=0.0d0\n elseif(inline.eq.'*')then ! the special string '*' returns -99999.0\n dnum1=-99999.0d0\n else\n iend=len(inline)\n call expression(inline(:iend),dnum1,cdum20,ierr_local,ilen)\n if(ierr_local.ne.0)then\n dnum1=0.0d0\n endif\n endif\n dnum0=dnum1\n if(present(ierr))then\n ierr=ierr_local\n endif\nend function dnum0\n!===================================================================================================================================\n!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()=\n!===================================================================================================================================\n!>\n!!##NAME\n!! snum0(3f) - [M_calculator] resolve a calculator expression into a string(return blank on errors)\n!! (LICENSE:PD)\n!!\n!!##SYNOPSIS\n!!\n!! function snum0(inline0,ierr)\n!!\n!! character(len=:),allocatable :: snum0(inline0)\n!! character(len=*),intent(in) :: inline0 ! input string\n!! integer,optional,intent(out) :: ierr\n!!\n!!##DESCRIPTION\n!! SNUM0() is used to return a string value up to (iclen_calc=512) characters\n!! long from a string expression.\n!! SNUM0() uses the calculator routine CALCULATOR(3f)\n!!\n!! inline0 INLINE0 is a CHARACTER variable up to (iclen_calc=512) characters long that\n!! is similar to a FORTRAN 77 expression.\n!! ierr error code. If zero, no error occurred\n!!\n!!##EXAMPLES\n!!\n!! Sample program:\n!!\n!! program demo_snum0\n!! use m_calculator, only: rnum0, snum0\n!! character(len=80) :: ic,jc,kc\n!!\n!! rdum=rnum0('A=83/2') ! set a variable in the calculator\n!! kc=snum0('$MYTITLE=\"This is my title variable\"')\n!!\n!! ic=snum0('$STR(\"VALUE IS [\",A,\"]\")')\n!! jc=snum0('$MYTITLE')\n!!\n!! write(*,*)'IC=',trim(ic)\n!! write(*,*)'JC=',trim(jc)\n!! write(*,*)'KC=',trim(kc)\n!!\n!! end program demo_snum0\n!!\n!! The output should look like\n!!\n!! IC=VALUE IS [41.5]\n!! JC=This is my title variable\n!! KC=This is my title variable\n!!\n!!##DEPENDENCIES\n!! o User-supplied routines:\n!! All programs that call the calculator routine can supply their\n!! own substitute_subroutine(3f) and substitute_C(3f) procedures. See\n!! the example program for samples.\n!!\n!!##SEE ALSO\n!! o The syntax of an expression is described in the main document of the\n!! Calculator Library.\n!! o See CALCULATOR(), RNUM0(), SNUM0(), EXPRESSION().\n!!\n!!##AUTHOR\n!! John S. Urban\n!!##LICENSE\n!! Public Domain\n!===================================================================================================================================\n!>\n!! AUTHOR John S. Urban\n!!##VERSION 1.0, 19971123\n!===================================================================================================================================\n!===================================================================================================================================\nfunction snum0(inline0,ierr)\n\n!character(len=*),parameter::ident_19=\"@(#)M_calculator::snum0(3f):resolve a calculator expression into a string\"\n\n! a few odd things are done because some compilers did not work as expected\ncharacter(len=:),allocatable :: snum0\ncharacter(len=*),intent(in) :: inline0 ! input string\ninteger,optional,intent(out) :: ierr\ncharacter(len=iclen_calc) :: lcopy ! working string\ncharacter(len=iclen_calc) :: inline ! working copy of input string\ninteger :: ierr_local\ninteger :: iend ! size of input string\ninteger :: ilen\ndoubleprecision :: dnum1\n\n inline=inline0 ! some compilers need a copy of known length to work as expected\n ierr_local=0\n if(inline.eq.' ')then ! what to do for a blank string\n snum0=' ' ! return a blank string\n else ! non-blank input expression\n iend=len(inline) ! size of working string\n lcopy=' ' ! initialize trimmed string\n lcopy=adjustl(inline(:iend)) ! trim leading spaces\n if(lcopy(1:1).eq.'$'.or.lcopy(1:1).eq.'\"')then ! this is a string that needs evaluated\n dnum1=0.0d0\n call expression(inline(:iend),dnum1,lcopy,ierr_local,ilen)\n if(ierr_local.ne.2)then ! check if expression was evaluated to a string successfully\n snum0=' ' ! input string was not resolved to a string\n endif\n snum0=lcopy(:max(1,ilen)) ! return whatever expression() returned\n else ! input was just a string, not an expression so just copy it\n snum0=inline(:iend) ! copy input string to output\n endif\n endif\n if(present(ierr))then\n ierr=ierr_local\n endif\nend function snum0\n!===================================================================================================================================\n!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()=\n!===================================================================================================================================\n!>\n!!##NAME\n!! expression(3f) - [M_calculator] return value from a string expression processing messages to simplify call to CALCULATOR(3f)\n!! (LICENSE:PD)\n!!##SYNOPSIS\n!!\n!! subroutine expression(inlin0,outval,outlin0,ierr,ilen)\n!!\n!! character(len=*), intent=(in) :: inlin0\n!! doubleprecision, intent=(out) :: outval\n!! character(len=*), intent=(out) :: outlin0\n!! integer, intent=(out) :: ierr\n!! integer, intent=(out) :: ilen\n!!\n!!##DESCRIPTION\n!! expression() takes a string containing a FORTRAN-like expression and evaluates\n!! it and returns a numeric or string value as appropriate.\n!! The main purpose of expression() is to assume the burden of displaying the\n!! calculator messages for codes that make multiple calls to CALCULATOR(3f).\n!! CALCULATOR(3f) does not display error messages directly.\n!!\n!! o EXPRESSION(3f) calls the calculator routine CALCULATOR(3f) to evaluate the\n!! expressions.\n!! o Messages beginning with a # are considered comments and are not passed\n!! on to the calculator.\n!!\n!! inlin0 INLIN0 is a string containing a numeric expression. The expression can\n!! be up to (iclen_calc=512) characters long. The syntax of an expression\n!! is as described in the main document of the Calc library. For example:\n!!\n!! 'A=sin(3.1416/5)'\n!! '# this is a comment'\n!! '$STR(\"The value is \",40/3)'\n!!\n!! outval OUTVAL is a numeric value calculated from the expression in INLIN0\n!! (when IERR returns 0).\n!! When a string value is returned (IERR=2) then OUTVAL is the length of\n!! the output string.\n!! outlin0 OUTLIN0 contains a string representation of the number returned in\n!! OUTVAL up to 23 characters long when INLIN0 is a numeric expression. It\n!! contains a string up to (iclen_calc=512) characters long when INLIN0 is\n!! a string expression.\n!! ierr IERR returns\n!!\n!! o -1 if an error occurred\n!! o 0 if a numeric value is returned (value is in OUTVAL, string\n!! representation of the value is in OUTLIN2).\n!! o 1 if no value was returned but a message was displayed (If a 'dump'\n!! or 'funcs' command was passed to the calculator).\n!! o 2 if the expression evaluated to a string value instead of a\n!! numeric value (value is in OUTLIN0).\n!! ilen ILEN returns the length of the input string minus trailing blanks.\n!!\n!!##DEPENDENCIES\n!! o User-supplied routines:\n!! All programs that call the calculator routine can supply their\n!! own substitute_subroutine(3f) and substitute_C(3f) procedures. See\n!! the example program for samples.\n!!##EXAMPLES\n!!\n!! Sample program:\n!!\n!! program demo_expression\n!! use M_calculator, only : iclen_calc\n!! use M_calculator, only : expression\n!! character(len=iclen_calc) :: outlin0\n!! doubleprecision :: outval\n!! call expression('A=3.4**5 ',outval,outlin0,ierr,ilen)\n!! write(*,*)'value of expression is ',outval\n!! write(*,*)'string representation of value is ',trim(outlin0)\n!! write(*,*)'error flag value is ',ierr\n!! write(*,*)'length of expression is ',ilen\n!! end program demo_expression\n!!\n!! Results:\n!!\n!! value of expression is 454.35424000000000\n!! string representation of value is 454.35424\n!! error flag value is 0\n!! length of expression is 8\n!!\n!!##SEE ALSO\n!! See also: STRGAR(),RNUM0(),CALCULATOR(),INUM0(),SNUM0()\n!!##AUTHOR\n!! John S. Urban\n!!##LICENSE\n!! Public Domain\n!===================================================================================================================================\n!>\n!! AUTHOR John S. Urban\n!!##VERSION V1.0, 19971123\n!===================================================================================================================================\nrecursive subroutine expression(inlin0,outval,outlin0,ierr,ilen)\n\n!character(len=*),parameter::ident_20=\"@(#)M_calculator::expression(3f):call CALCULATOR(3f) calculator and display messages\"\n\n! evaluate a FORTRAN-like string expression and return a numeric\n! value and its character equivalent or a string value as appropriate\ncharacter(len=*),intent(in) :: inlin0\ndoubleprecision :: outval\ncharacter(len=*) :: outlin0\ninteger,intent(out) :: ierr\ninteger,intent(out) :: ilen\n\ncharacter(len=iclen_calc) :: line\ncharacter(len=iclen_calc) :: outlin\ndoubleprecision,save :: rvalue=0.0d0\nintrinsic :: len\ninteger :: imaxi\ncharacter(len=iclen_calc) :: event\n!#----------------------------------------------------------------------------------------------------------------------------------\n ! copy INLIN0 to working copy LINE and find position of last non-blank character\n ! in the string\n line=''\n line=inlin0\n ! if the line is blank set imaxi to 1, else set it to the least of the length of the input string or (iclen_calc)\n ! NOTE: not checking if input expression is longer than (iclen_calc) characters!!\n imaxi=max(min(len(line),len(inlin0)),1)\n ilen=len_trim(line(1:imaxi))\n!-----------------------------------------------------------------------------------------------------------------------------------\n if(ilen.eq.0)then ! command was totally blank\n ierr=-1\n write(*,*)'*expression* warning===> blank expression'\n!-----------------------------------------------------------------------------------------------------------------------------------\n elseif(line(:1).eq.'#')then ! line was a comment\n!-----------------------------------------------------------------------------------------------------------------------------------\n else\n ierr=0\n call calculator(line(:ilen),outlin,event,rvalue,ierr) ! evaluate the expression\n!-----------------------------------------------------------------------------------------------------------------------------------\n select case(ierr)\n case(-1) ! trapped error, display error message\n write(*,*)'*expression* error===>',trim(event)\n !call pdec(line(:ilen)) ! echo input string as is and in ASCII decimal\n case(1) ! general message, display message\n write(*,*)'*expression* message===>',trim(event)\n case(0) ! numeric output\n outlin0=outlin\n case(2) ! string output\n outlin0=event ! assumes outlin is long enough to return the string into\n ilen=int(rvalue) ! in special mode where a string is returned, rvalue is the length of the string\n case default\n write(*,*)'*expression* warning===> unexpected ierr value=',ierr\n end select\n!-----------------------------------------------------------------------------------------------------------------------------------\n endif\n!-----------------------------------------------------------------------------------------------------------------------------------\n outval=rvalue ! return normal sized real value\nend subroutine expression\n!===================================================================================================================================\n!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()=\n!===================================================================================================================================\nsubroutine juown1_placeholder(func,iflen,args,iargstp,n,fval,ctmp,ier)\n ! extend functions available to the calculator routine\n!\n! if the function ownmode(1) is called this subroutine\n! will be accessed to do user-written functions.\n!\n! func(iend-1)=procedure name. func should not be changed.\n! iflen=length of procedure name.\n! args=array of 100 elements containing procedure arguments.\n! iargstp=type of argument(1=value,2=position of string value)\n! n=integer number of parameters\n! x=array of 55555 x values\n! y=array of 55555 y values\n! fval=value to replace function call\n! ctmp=string to return when returning a string value\n! ier=returned error flag value.\n! set to -1 if an error occurs.\n! set to 0 if a number is returned\n! set to 2 if a string is returned\n!\n!!use M_calculator, only : x, y, values, values_len\ninteger, parameter :: k_dbl = SELECTED_REAL_KIND(15,300) ! real*8\ncharacter(len=*),intent(in) :: func\ninteger,intent(in) :: iflen\nreal(kind=k_dbl),intent(in) :: args(100)\ninteger,intent(in) :: iargstp(100)\ninteger,intent(in) :: n\nreal(kind=k_dbl) :: fval\ncharacter(len=*) :: ctmp\ninteger :: ier\n\ninteger :: i10\ninteger :: iwhich\ninteger :: ilen\n!-----------------------------------------------------------------------\n fval=0.0d0\n!-----------------------------------------------------------------------\n write(*,*)'*juown1_placeholder* unknown function ', func(1:iflen)\n write(*,*)'function name length is..',iflen\n write(*,*)'number of arguments .....',n\n do i10=1,n\n if(iargstp(i10).eq.0)then\n write(*,*)i10,' VALUE=',args(i10)\n elseif(iargstp(i10).eq.2)then\n iwhich=int(args(i10)+0.5d0)\n ilen=values_len(iwhich)\n write(*,*)i10,' STRING='//values(iwhich)(:ilen)\n else\n write(*,*)'unknown parameter type is ',iargstp(i10)\n endif\n enddo\nend subroutine juown1_placeholder\n!----------------------------------------------------------------------------------------------------------------------------------!\n!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!\n!----------------------------------------------------------------------------------------------------------------------------------!\nreal function c_placeholder(args,n)\n! a built-in calculator function called c must be satisfied.\n! write whatever you want here as a function\ninteger,intent(in) :: n\nreal(kind=k_dbl),intent(in) :: args(n)\n c_placeholder=0.0_k_dbl\nend function c_placeholder\n!===================================================================================================================================\n!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()=\n!===================================================================================================================================\n! copies\n! use M_strings, only : upper, lower, value_to_string, delim\n! use M_list, only : locate, insert, replace\n! use M_math, only : round\n!===================================================================================================================================\nelemental pure function upper(str,begin,end) result (string)\n\n!character(len=*),parameter::ident_21=\"@(#)M_strings::upper(3f): Changes a string to uppercase\"\n\ncharacter(*), intent(In) :: str ! inpout string to convert to all uppercase\ninteger, intent(in), optional :: begin,end\ncharacter(len(str)) :: string ! output string that contains no miniscule letters\ninteger :: i ! loop counter\ninteger :: ibegin,iend\n string = str ! initialize output string to input string\n\n ibegin = 1\n if (present(begin))then\n ibegin = max(ibegin,begin)\n endif\n\n iend = len_trim(str)\n if (present(end))then\n iend= min(iend,end)\n endif\n\n do i = ibegin, iend ! step thru each letter in the string in specified range\n select case (str(i:i))\n case ('a':'z') ! located miniscule letter\n string(i:i) = char(iachar(str(i:i))-32) ! change miniscule letter to uppercase\n end select\n end do\n\nend function upper\n!===================================================================================================================================\nelemental pure function lower(str,begin,end) result (string)\n\n!character(len=*),parameter::ident_22=\"@(#)M_strings::lower(3f): Changes a string to lowercase over specified range\"\n\ncharacter(*), intent(In) :: str\ncharacter(len(str)) :: string\ninteger,intent(in),optional :: begin, end\ninteger :: i\ninteger :: ibegin, iend\n string = str\n\n ibegin = 1\n if (present(begin))then\n ibegin = max(ibegin,begin)\n endif\n\n iend = len_trim(str)\n if (present(end))then\n iend= min(iend,end)\n endif\n\n do i = ibegin, iend ! step thru each letter in the string in specified range\n select case (str(i:i))\n case ('A':'Z')\n string(i:i) = char(iachar(str(i:i))+32) ! change letter to miniscule\n case default\n end select\n end do\n\nend function lower\n!===================================================================================================================================\nsubroutine delim(line,array,n,icount,ibegin,iterm,ilen,dlim)\n\n!character(len=*),parameter::ident_9=\"@(#)M_strings::delim(3f): parse a string and store tokens into an array\"\n\n!\n! given a line of structure \" par1 par2 par3 ... parn \"\n! store each par(n) into a separate variable in array.\n!\n! IF ARRAY(1) == '#N#' do not store into string array (KLUDGE))\n!\n! also count number of elements of array initialized, and\n! return beginning and ending positions for each element.\n! also return position of last non-blank character (even if more\n! than n elements were found).\n!\n! no quoting of delimiter is allowed\n! no checking for more than n parameters, if any more they are ignored\n!\ncharacter(len=*),intent(in) :: line\ninteger,intent(in) :: n\ncharacter(len=*) :: array(n)\ninteger,intent(out) :: icount\ninteger,intent(out) :: ibegin(n)\ninteger,intent(out) :: iterm(n)\ninteger,intent(out) :: ilen\ncharacter(len=*),intent(in) :: dlim\n!-----------------------------------------------------------------------------------------------------------------------------------\ncharacter(len=len(line)):: line_local\nlogical :: lstore\ninteger :: i10\ninteger :: iarray\ninteger :: icol\ninteger :: idlim\ninteger :: iend\ninteger :: ifound\ninteger :: istart\n!-----------------------------------------------------------------------------------------------------------------------------------\n icount=0\n ilen=len_trim(line)\n line_local=line\n\n idlim=len(dlim)\n if(idlim > 5)then\n idlim=len_trim(dlim) ! dlim a lot of blanks on some machines if dlim is a big string\n if(idlim == 0)then\n idlim=1 ! blank string\n endif\n endif\n\n if(ilen == 0)then ! command was totally blank\n return\n endif\n!\n! there is at least one non-blank character in the command\n! ilen is the column position of the last non-blank character\n! find next non-delimiter\n icol=1\n\n if(array(1) == '#N#')then ! special flag to not store into character array\n lstore=.false.\n else\n lstore=.true.\n endif\n\n do iarray=1,n,1 ! store into each array element until done or too many words\n NOINCREMENT: do\n if(index(dlim(1:idlim),line_local(icol:icol)) == 0)then ! if current character is not a delimiter\n istart=icol ! start new token on the non-delimiter character\n ibegin(iarray)=icol\n iend=ilen-istart+1+1 ! assume no delimiters so put past end of line\n do i10=1,idlim\n ifound=index(line_local(istart:ilen),dlim(i10:i10))\n if(ifound > 0)then\n iend=min(iend,ifound)\n endif\n enddo\n if(iend <= 0)then ! no remaining delimiters\n iterm(iarray)=ilen\n if(lstore)then\n array(iarray)=line_local(istart:ilen)\n endif\n icount=iarray\n return\n else\n iend=iend+istart-2\n iterm(iarray)=iend\n if(lstore)then\n array(iarray)=line_local(istart:iend)\n endif\n endif\n icol=iend+2\n exit NOINCREMENT\n endif\n icol=icol+1\n enddo NOINCREMENT\n! last character in line was a delimiter, so no text left\n! (should not happen where blank=delimiter)\n if(icol > ilen)then\n icount=iarray\n if( (iterm(icount)-ibegin(icount)) < 0)then ! last token was all delimiters\n icount=icount-1\n endif\n return\n endif\n enddo\n icount=n ! more than n elements\nend subroutine delim\n!===================================================================================================================================\nsubroutine value_to_string(gval,chars,length,err,fmt,trimz)\n\n!character(len=*),parameter::ident_40=\"@(#)M_strings::value_to_string(3fp): subroutine returns a string from a value\"\n\nclass(*),intent(in) :: gval\ncharacter(len=*),intent(out) :: chars\ninteger,intent(out),optional :: length\ninteger,optional :: err\ninteger :: err_local\ncharacter(len=*),optional,intent(in) :: fmt ! format to write value with\nlogical,intent(in),optional :: trimz\ncharacter(len=:),allocatable :: fmt_local\ncharacter(len=1024) :: msg\n\n! Notice that the value GVAL can be any of several types ( INTEGER,REAL,DOUBLEPRECISION,LOGICAL)\n\n if (present(fmt)) then\n select type(gval)\n type is (integer)\n fmt_local='(i0)'\n if(fmt.ne.'') fmt_local=fmt\n write(chars,fmt_local,iostat=err_local,iomsg=msg)gval\n type is (real)\n fmt_local='(bz,g23.10e3)'\n fmt_local='(bz,g0.8)'\n if(fmt.ne.'') fmt_local=fmt\n write(chars,fmt_local,iostat=err_local,iomsg=msg)gval\n type is (doubleprecision)\n fmt_local='(bz,g0)'\n if(fmt.ne.'') fmt_local=fmt\n write(chars,fmt_local,iostat=err_local,iomsg=msg)gval\n type is (logical)\n fmt_local='(l1)'\n if(fmt.ne.'') fmt_local=fmt\n write(chars,fmt_local,iostat=err_local,iomsg=msg)gval\n class default\n write(*,*)'*value_to_string* UNKNOWN TYPE'\n chars=' '\n end select\n if(fmt.eq.'') then\n chars=adjustl(chars)\n call trimzeros(chars)\n endif\n else ! no explicit format option present\n err_local=-1\n select type(gval)\n type is (integer)\n write(chars,*,iostat=err_local,iomsg=msg)gval\n type is (real)\n write(chars,*,iostat=err_local,iomsg=msg)gval\n type is (doubleprecision)\n write(chars,*,iostat=err_local,iomsg=msg)gval\n type is (logical)\n write(chars,*,iostat=err_local,iomsg=msg)gval\n class default\n chars=''\n end select\n chars=adjustl(chars)\n if(index(chars,'.').ne.0) call trimzeros(chars)\n endif\n if(present(trimz))then\n if(trimz)then\n chars=adjustl(chars)\n call trimzeros(chars)\n endif\n endif\n\n if(present(length)) then\n length=len_trim(chars)\n endif\n\n if(present(err)) then\n err=err_local\n elseif(err_local.ne.0)then\n !! cannot currently do I/O from a function being called from I/O\n !!write(ERROR_UNIT,'(a)')'*value_to_string* WARNING:['//trim(msg)//']'\n chars=chars//' *value_to_string* WARNING:['//trim(msg)//']'\n endif\n\nend subroutine value_to_string\n!===================================================================================================================================\n!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()=\n!===================================================================================================================================\nsubroutine locate_c(list,value,place,ier,errmsg)\n\n!character(len=*),parameter::ident_5=\"&\n!&@(#)M_list::locate_c(3f): find PLACE in sorted character array where VALUE can be found or should be placed\"\n\ncharacter(len=*),intent(in) :: value\ninteger,intent(out) :: place\ncharacter(len=:),allocatable :: list(:)\ninteger,intent(out),optional :: ier\ncharacter(len=*),intent(out),optional :: errmsg\ninteger :: i\ncharacter(len=:),allocatable :: message\ninteger :: arraysize\ninteger :: maxtry\ninteger :: imin, imax\ninteger :: error\n if(.not.allocated(list))then\n list=[character(len=max(len_trim(value),2)) :: ]\n endif\n arraysize=size(list)\n\n error=0\n if(arraysize.eq.0)then\n maxtry=0\n place=-1\n else\n maxtry=int(log(float(arraysize))/log(2.0)+1.0)\n place=(arraysize+1)/2\n endif\n imin=1\n imax=arraysize\n message=''\n\n LOOP: block\n do i=1,maxtry\n\n if(value.eq.list(PLACE))then\n exit LOOP\n else if(value.gt.list(place))then\n imax=place-1\n else\n imin=place+1\n endif\n\n if(imin.gt.imax)then\n place=-imin\n if(iabs(place).gt.arraysize)then ! ran off end of list. Where new value should go or an unsorted input array'\n exit LOOP\n endif\n exit LOOP\n endif\n\n place=(imax+imin)/2\n\n if(place.gt.arraysize.or.place.le.0)then\n message='*locate* error: search is out of bounds of list. Probably an unsorted input array'\n error=-1\n exit LOOP\n endif\n\n enddo\n message='*locate* exceeded allowed tries. Probably an unsorted input array'\n endblock LOOP\n if(present(ier))then\n ier=error\n else if(error.ne.0)then\n write(stderr,*)message//' VALUE=',trim(value)//' PLACE=',place\n stop 1\n endif\n if(present(errmsg))then\n errmsg=message\n endif\nend subroutine locate_c\n!===================================================================================================================================\nsubroutine locate_d(list,value,place,ier,errmsg)\n\n!character(len=*),parameter::ident_6=\"&\n!&@(#)M_list::locate_d(3f): find PLACE in sorted doubleprecision array where VALUE can be found or should be placed\"\n\n! Assuming an array sorted in descending order\n!\n! 1. If it is not found report where it should be placed as a NEGATIVE index number.\n\ndoubleprecision,allocatable :: list(:)\ndoubleprecision,intent(in) :: value\ninteger,intent(out) :: place\ninteger,intent(out),optional :: ier\ncharacter(len=*),intent(out),optional :: errmsg\n\ninteger :: i\ncharacter(len=:),allocatable :: message\ninteger :: arraysize\ninteger :: maxtry\ninteger :: imin, imax\ninteger :: error\n\n if(.not.allocated(list))then\n list=[doubleprecision :: ]\n endif\n arraysize=size(list)\n\n error=0\n if(arraysize.eq.0)then\n maxtry=0\n place=-1\n else\n maxtry=int(log(float(arraysize))/log(2.0)+1.0)\n place=(arraysize+1)/2\n endif\n imin=1\n imax=arraysize\n message=''\n\n LOOP: block\n do i=1,maxtry\n\n if(value.eq.list(PLACE))then\n exit LOOP\n else if(value.gt.list(place))then\n imax=place-1\n else\n imin=place+1\n endif\n\n if(imin.gt.imax)then\n place=-imin\n if(iabs(place).gt.arraysize)then ! ran off end of list. Where new value should go or an unsorted input array'\n exit LOOP\n endif\n exit LOOP\n endif\n\n place=(imax+imin)/2\n\n if(place.gt.arraysize.or.place.le.0)then\n message='*locate* error: search is out of bounds of list. Probably an unsorted input array'\n error=-1\n exit LOOP\n endif\n\n enddo\n message='*locate* exceeded allowed tries. Probably an unsorted input array'\n endblock LOOP\n if(present(ier))then\n ier=error\n else if(error.ne.0)then\n write(stderr,*)message//' VALUE=',value,' PLACE=',place\n stop 1\n endif\n if(present(errmsg))then\n errmsg=message\n endif\nend subroutine locate_d\n!===================================================================================================================================\nsubroutine locate_i(list,value,place,ier,errmsg)\n\n!character(len=*),parameter::ident_8=\"&\n!&@(#)M_list::locate_i(3f): find PLACE in sorted integer array where VALUE can be found or should be placed\"\n\n! Assuming an array sorted in descending order\n!\n! 1. If it is not found report where it should be placed as a NEGATIVE index number.\n\ninteger,allocatable :: list(:)\ninteger,intent(in) :: value\ninteger,intent(out) :: place\ninteger,intent(out),optional :: ier\ncharacter(len=*),intent(out),optional :: errmsg\n\ninteger :: i\ncharacter(len=:),allocatable :: message\ninteger :: arraysize\ninteger :: maxtry\ninteger :: imin, imax\ninteger :: error\n\n if(.not.allocated(list))then\n list=[integer :: ]\n endif\n arraysize=size(list)\n\n error=0\n if(arraysize.eq.0)then\n maxtry=0\n place=-1\n else\n maxtry=int(log(float(arraysize))/log(2.0)+1.0)\n place=(arraysize+1)/2\n endif\n imin=1\n imax=arraysize\n message=''\n\n LOOP: block\n do i=1,maxtry\n\n if(value.eq.list(PLACE))then\n exit LOOP\n else if(value.gt.list(place))then\n imax=place-1\n else\n imin=place+1\n endif\n\n if(imin.gt.imax)then\n place=-imin\n if(iabs(place).gt.arraysize)then ! ran off end of list. Where new value should go or an unsorted input array'\n exit LOOP\n endif\n exit LOOP\n endif\n\n place=(imax+imin)/2\n\n if(place.gt.arraysize.or.place.le.0)then\n message='*locate* error: search is out of bounds of list. Probably an unsorted input array'\n error=-1\n exit LOOP\n endif\n\n enddo\n message='*locate* exceeded allowed tries. Probably an unsorted input array'\n endblock LOOP\n if(present(ier))then\n ier=error\n else if(error.ne.0)then\n write(stderr,*)message//' VALUE=',value,' PLACE=',place\n stop 1\n endif\n if(present(errmsg))then\n errmsg=message\n endif\nend subroutine locate_i\n!===================================================================================================================================\nsubroutine remove_i(list,place)\n\n!character(len=*),parameter::ident_13=\"@(#)M_list::remove_i(3fp): remove value from allocatable array at specified position\"\ninteger,allocatable :: list(:)\ninteger,intent(in) :: place\ninteger :: end\n\n if(.not.allocated(list))then\n list=[integer :: ]\n endif\n end=size(list)\n if(place.le.0.or.place.gt.end)then ! index out of bounds of array\n elseif(place.eq.end)then ! remove from array\n list=[ list(:place-1)]\n else\n list=[ list(:place-1), list(place+1:) ]\n endif\n\nend subroutine remove_i\n!===================================================================================================================================\nsubroutine remove_c(list,place)\n\n!character(len=*),parameter::ident_9=\"@(#)M_list::remove_c(3fp): remove string from allocatable string array at specified position\"\n\ncharacter(len=:),allocatable :: list(:)\ninteger,intent(in) :: place\ninteger :: ii, end\n if(.not.allocated(list))then\n list=[character(len=2) :: ]\n endif\n ii=len(list)\n end=size(list)\n if(place.le.0.or.place.gt.end)then ! index out of bounds of array\n elseif(place.eq.end)then ! remove from array\n list=[character(len=ii) :: list(:place-1) ]\n else\n list=[character(len=ii) :: list(:place-1), list(place+1:) ]\n endif\nend subroutine remove_c\nsubroutine remove_d(list,place)\n\n!character(len=*),parameter::ident_10=\"&\n!&@(#)M_list::remove_d(3fp): remove doubleprecision value from allocatable array at specified position\"\n\ndoubleprecision,allocatable :: list(:)\ninteger,intent(in) :: place\ninteger :: end\n if(.not.allocated(list))then\n list=[doubleprecision :: ]\n endif\n end=size(list)\n if(place.le.0.or.place.gt.end)then ! index out of bounds of array\n elseif(place.eq.end)then ! remove from array\n list=[ list(:place-1)]\n else\n list=[ list(:place-1), list(place+1:) ]\n endif\n\nend subroutine remove_d\n!===================================================================================================================================\nsubroutine replace_c(list,value,place)\n\n!character(len=*),parameter::ident_14=\"@(#)M_list::replace_c(3fp): replace string in allocatable string array at specified position\"\n\ncharacter(len=*),intent(in) :: value\ncharacter(len=:),allocatable :: list(:)\ncharacter(len=:),allocatable :: kludge(:)\ninteger,intent(in) :: place\ninteger :: ii\ninteger :: tlen\ninteger :: end\n if(.not.allocated(list))then\n list=[character(len=max(len_trim(value),2)) :: ]\n endif\n tlen=len_trim(value)\n end=size(list)\n if(place.lt.0.or.place.gt.end)then\n write(stderr,*)'*replace_c* error: index out of range. end=',end,' index=',place\n elseif(len_trim(value).le.len(list))then\n list(place)=value\n else ! increase length of variable\n ii=max(tlen,len(list))\n kludge=[character(len=ii) :: list ]\n list=kludge\n list(place)=value\n endif\nend subroutine replace_c\n!===================================================================================================================================\nsubroutine replace_d(list,value,place)\n\n!character(len=*),parameter::ident_15=\"&\n!&@(#)M_list::replace_d(3fp): place doubleprecision value into allocatable array at specified position\"\n\ndoubleprecision,intent(in) :: value\ndoubleprecision,allocatable :: list(:)\ninteger,intent(in) :: place\ninteger :: end\n if(.not.allocated(list))then\n list=[doubleprecision :: ]\n endif\n end=size(list)\n if(end.eq.0)then ! empty array\n list=[value]\n elseif(place.gt.0.and.place.le.end)then\n list(place)=value\n else ! put in middle of array\n write(stderr,*)'*replace_d* error: index out of range. end=',end,' index=',place\n endif\nend subroutine replace_d\n!===================================================================================================================================\nsubroutine replace_i(list,value,place)\n\n!character(len=*),parameter::ident_18=\"@(#)M_list::replace_i(3fp): place value into allocatable array at specified position\"\n\ninteger,intent(in) :: value\ninteger,allocatable :: list(:)\ninteger,intent(in) :: place\ninteger :: end\n if(.not.allocated(list))then\n list=[integer :: ]\n endif\n end=size(list)\n if(end.eq.0)then ! empty array\n list=[value]\n elseif(place.gt.0.and.place.le.end)then\n list(place)=value\n else ! put in middle of array\n write(stderr,*)'*replace_i* error: index out of range. end=',end,' index=',place\n endif\nend subroutine replace_i\n!===================================================================================================================================\nsubroutine insert_c(list,value,place)\n\n!character(len=*),parameter::ident_19=\"@(#)M_list::insert_c(3fp): place string into allocatable string array at specified position\"\n\ncharacter(len=*),intent(in) :: value\ncharacter(len=:),allocatable :: list(:)\ncharacter(len=:),allocatable :: kludge(:)\ninteger,intent(in) :: place\ninteger :: ii\ninteger :: end\n\n if(.not.allocated(list))then\n list=[character(len=max(len_trim(value),2)) :: ]\n endif\n\n ii=max(len_trim(value),len(list),2)\n end=size(list)\n\n if(end.eq.0)then ! empty array\n list=[character(len=ii) :: value ]\n elseif(place.eq.1)then ! put in front of array\n kludge=[character(len=ii) :: value, list]\n list=kludge\n elseif(place.gt.end)then ! put at end of array\n kludge=[character(len=ii) :: list, value ]\n list=kludge\n elseif(place.ge.2.and.place.le.end)then ! put in middle of array\n kludge=[character(len=ii) :: list(:place-1), value,list(place:) ]\n list=kludge\n else ! index out of range\n write(stderr,*)'*insert_c* error: index out of range. end=',end,' index=',place,' value=',value\n endif\n\nend subroutine insert_c\n!===================================================================================================================================\nsubroutine insert_d(list,value,place)\n\n!character(len=*),parameter::ident_21=\"&\n!&@(#)M_list::insert_d(3fp): place doubleprecision value into allocatable array at specified position\"\n\ndoubleprecision,intent(in) :: value\ndoubleprecision,allocatable :: list(:)\ninteger,intent(in) :: place\ninteger :: end\n if(.not.allocated(list))then\n list=[doubleprecision :: ]\n endif\n end=size(list)\n if(end.eq.0)then ! empty array\n list=[value]\n elseif(place.eq.1)then ! put in front of array\n list=[value, list]\n elseif(place.gt.end)then ! put at end of array\n list=[list, value ]\n elseif(place.ge.2.and.place.le.end)then ! put in middle of array\n list=[list(:place-1), value,list(place:) ]\n else ! index out of range\n write(stderr,*)'*insert_d* error: index out of range. end=',end,' index=',place,' value=',value\n endif\nend subroutine insert_d\n!===================================================================================================================================\nsubroutine insert_i(list,value,place)\n\n!character(len=*),parameter::ident_23=\"@(#)M_list::insert_i(3fp): place value into allocatable array at specified position\"\n\ninteger,allocatable :: list(:)\ninteger,intent(in) :: value\ninteger,intent(in) :: place\ninteger :: end\n if(.not.allocated(list))then\n list=[integer :: ]\n endif\n end=size(list)\n if(end.eq.0)then ! empty array\n list=[value]\n elseif(place.eq.1)then ! put in front of array\n list=[value, list]\n elseif(place.gt.end)then ! put at end of array\n list=[list, value ]\n elseif(place.ge.2.and.place.le.end)then ! put in middle of array\n list=[list(:place-1), value,list(place:) ]\n else ! index out of range\n write(stderr,*)'*insert_i* error: index out of range. end=',end,' index=',place,' value=',value\n endif\n\nend subroutine insert_i\n!===================================================================================================================================\nsubroutine dict_delete(self,key)\n\n!character(len=*),parameter::ident_24=\"@(#)M_list::dict_delete(3f): remove string from sorted allocatable string array if present\"\n\nclass(dictionary),intent(inout) :: self\ncharacter(len=*),intent(in) :: key\ninteger :: place\n\n call locate(self%key,key,place)\n if(place.ge.1)then\n call remove(self%key,place)\n call remove(self%value,place)\n call remove(self%count,place)\n endif\n\nend subroutine dict_delete\n!===================================================================================================================================\nfunction dict_get(self,key) result(value)\n\n!character(len=*),parameter::ident_25=\"@(#)M_list::dict_get(3f): get value of key-value pair in dictionary, given key\"\n\n!!class(dictionary),intent(inout) :: self\nclass(dictionary) :: self\ncharacter(len=*),intent(in) :: key\ncharacter(len=:),allocatable :: value\ninteger :: place\n call locate(self%key,key,place)\n if(place.lt.1)then\n value=''\n else\n value=self%value(place)(:self%count(place))\n endif\nend function dict_get\n!===================================================================================================================================\nsubroutine dict_add(self,key,value)\n\n!character(len=*),parameter::ident_26=\"@(#)M_list::dict_add(3f): place key-value pair into dictionary, adding the key if required\"\n\nclass(dictionary),intent(inout) :: self\ncharacter(len=*),intent(in) :: key\ncharacter(len=*),intent(in) :: value\ninteger :: place\ninteger :: place2\n call locate(self%key,key,place)\n if(place.lt.1)then\n place2=iabs(place)\n call insert( self%key, key, place2 )\n call insert( self%value, value, place2 )\n call insert( self%count, len_trim(value), place2 )\n elseif(place.gt.0)then ! replace instead of insert\n call insert( self%value, value, place )\n call insert( self%count, len_trim(value), place )\n endif\nend subroutine dict_add\n!===================================================================================================================================\n!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()=\n!===================================================================================================================================\nfunction round(val,idigits0)\nimplicit none\ncharacter(len=*),parameter :: ident=\"@(#) M_math::round(3f): round val to specified number of significant digits\"\ninteger,parameter :: dp=kind(0.0d0)\nreal(kind=dp),intent(in) :: val\ninteger,intent(in) :: idigits0\n integer :: idigits,ipow\n real(kind=dp) :: aval,rnormal\n real(kind=dp) :: round\n! this does not work very well because of round-off errors.\n! Make a better one, probably have to use machine-dependent bit shifting\n ! make sure a reasonable number of digits has been requested\n idigits=max(1,idigits0)\n aval=abs(val)\n! select a power that will normalize the number\n! (put it in the range 1 > abs(val) <= 0)\n if(aval.ge.1)then\n ipow=int(log10(aval)+1)\n else\n ipow=int(log10(aval))\n endif\n rnormal=val/(10.0d0**ipow)\n if(rnormal.eq.1)then\n ipow=ipow+1\n endif\n !normalize, multiply by 10*idigits to an integer, and so on\n round=real(anint(val*10.d0**(idigits-ipow)))*10.d0**(ipow-idigits)\nend function round\n!===================================================================================================================================\nsubroutine trimzeros(string)\n\n!character(len=*),parameter::ident_50=\"@(#)M_strings::trimzeros(3fp): Delete trailing zeros from numeric decimal string\"\n\n! if zero needs added at end assumes input string has room\ncharacter(len=*) :: string\ncharacter(len=len(string)+2) :: str\ncharacter(len=len(string)) :: exp ! the exponent string if present\ninteger :: ipos ! where exponent letter appears if present\ninteger :: i, ii\n str=string ! working copy of string\n ipos=scan(str,'eEdD') ! find end of real number if string uses exponent notation\n if(ipos>0) then ! letter was found\n exp=str(ipos:) ! keep exponent string so it can be added back as a suffix\n str=str(1:ipos-1) ! just the real part, exponent removed will not have trailing zeros removed\n endif\n if(index(str,'.').eq.0)then ! if no decimal character in original string add one to end of string\n ii=len_trim(str)\n str(ii+1:ii+1)='.' ! add decimal to end of string\n endif\n do i=len_trim(str),1,-1 ! scanning from end find a non-zero character\n select case(str(i:i))\n case('0') ! found a trailing zero so keep trimming\n cycle\n case('.') ! found a decimal character at end of remaining string\n if(i.le.1)then\n str='0'\n else\n str=str(1:i-1)\n endif\n exit\n case default\n str=str(1:i) ! found a non-zero character so trim string and exit\n exit\n end select\n end do\n if(ipos>0)then ! if originally had an exponent place it back on\n string=trim(str)//trim(exp)\n else\n string=str\n endif\nend subroutine trimzeros\n!===================================================================================================================================\nsubroutine init_random_seed(mine)\n\n!character(len=*),parameter::ident_7=\"&\n!&@(#)M_random::init_random_seed(3f): initialize random_number(3f) to return a single value with single integer seed like srand(3c)\"\n\n! to make this start with a single number like srand(3c) take the seed and\n! use the value to fill the seed array, adding 37 to each subsequent value\n! till the array is filled.\ninteger,intent(in) :: mine\n integer :: i, n\n integer, dimension(:), allocatable :: seed\n call random_seed(size = n)\n allocate(seed(n))\n seed = mine + 37 * (/ (i - 1, i = 1, n) /)\n !write(*,*)seed\n !write(*,*)(/ (i - 1, i = 1, n) /)\n call random_seed(put = seed)\n deallocate(seed)\nend subroutine init_random_seed\n!===================================================================================================================================\n!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()=\n!===================================================================================================================================\nend module M_calculator\n!===================================================================================================================================\n!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()=\n!===================================================================================================================================\n", "meta": {"hexsha": "4194f6d1d0ab8b70f99b95e244a4df5213a329b9", "size": 205620, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/M_calculator.f90", "max_stars_repo_name": "urbanjost/M_calculator", "max_stars_repo_head_hexsha": "1d1fccc7e3a5e5fbd03f8ce8b18f0a10d579ac94", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-26T18:46:14.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-20T02:58:10.000Z", "max_issues_repo_path": "src/M_calculator.f90", "max_issues_repo_name": "urbanjost/M_calculator", "max_issues_repo_head_hexsha": "1d1fccc7e3a5e5fbd03f8ce8b18f0a10d579ac94", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-09-18T00:04:19.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-18T03:50:52.000Z", "max_forks_repo_path": "src/M_calculator.f90", "max_forks_repo_name": "urbanjost/M_calculator", "max_forks_repo_head_hexsha": "1d1fccc7e3a5e5fbd03f8ce8b18f0a10d579ac94", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-10-08T00:32:16.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-08T00:32:16.000Z", "avg_line_length": 47.8186046512, "max_line_length": 135, "alphanum_fraction": 0.4644198035, "num_tokens": 46219, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.847967769904032, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.6932768053083811}} {"text": " SUBROUTINE SHTCC (MODE,LPIVOT,L1,M,U, UPARAM,C,LDC,NVC)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc>> 1996-03-30 SHTCC Krogh Added external statement.\nC>> 1994-11-11 SHTCC Krogh Declared all vars.\nC>> 1994-10-20 SHTCC Krogh Changes to use M77CON\nC>> 1987-08-19 SHTCC Lawson Initial code.\nc--S replaces \"?\": ?HTCC, ?NRM2\nc\nC Construction and/or application of a single Householder\nC transformation.. Q = I + U*(U**T)/b\nc where I is the MxM identity matrix, b is a scalar, and U is an\nc M-dimensional Householder vector.\nc All vectors are M-vectors but only the components in positions\nc LPIVOT, and L1 through M, will be referenced.\nc This version, identified by CC at the end of its name, is\nc specialized for the Column-Column case, i.e. U() is a vector or\nc a column of a matrix and C() is regarded a containing a set\nc of column vectors to which transformations will be applied.\nc ------------------------------------------------------------------\nC Subroutine arguments\nc\nC MODE [in] = 1 OR 2 When MODE = 1 this subr determines the\nc parameters for a Householder transformation and applies\nc the transformation to NVC vectors. When MODE = 2 this\nc subr applies a previously determined Householder\nc transformation.\nC LPIVOT [in] The index of the pivot element.\nC L1,M [in] If L1 .le. M elements LPIVOT and L1 through M will\nc be referenced. If L1 .gt. M the subroutine returns\nc immediately. This may be regarded\nc as performing an identity transformation.\nC U() [inout] Contains an M-dimensional vector with storage\nc spacing of 1 between elements.\nc When MODE = 1 this is the vector from which Householder\nc parameters are to be determined.\nc When MODE = 2 this is the result from previous computation\nc with MODE = 1.\nc UPARAM [inout] Holds a value that supplements the\nc contents of U() to complete the definition of a\nc Householder transformation. Computed when MODE = 1 and\nc reused when MODE = 2.\nc UPARAM is the pivot component of the Householder U-vector.\nC C() [inout] On entry contains a set of NVC M-vectors to which a\nc Householder transformation is to be applied.\nc On exit contains the set of transformed vectors.\nC These vectors are the columns of an M x NVC matrix in C(,).\nC LDC [in] Leading dimension of C(,). Require LDC .ge. M.\nC NVC [in] Number of vectors in C(,) to be transformed.\nc If NVC .le. 0 no reference will be made to the array C(,).\nc ------------------------------------------------------------------\nc Subprograms referenced: SNRM2\nc ------------------------------------------------------------------\nc This code was originally developed by Charles L. Lawson and\nc Richard J. Hanson at Jet Propulsion Laboratory in 1973. The\nc original code was described and listed in the book,\nc\nc Solving Least Squares Problems\nc C. L. Lawson and R. J. Hanson\nc Prentice-Hall, 1974\nc\nc Feb, 1985, C. L. Lawson & S. Y. Chan, JPL. Adapted code from the\nc Lawson & Hanson book to Fortran 77 for use in the JPL MATH77\nc library.\nc Prefixing subprogram names with S or D for s.p. or d.p. versions.\nc Using generic names for intrinsic functions.\nc Adding calls to BLAS and MATH77 error processing subrs in some\nc program units.\nc July, 1987. CLL. Changed user interface so method of specifying\nc column/row storage options is more language-independent.\nC ------------------------------------------------------------------\n external SNRM2\n real U(*), UPARAM, C(*), SNRM2\n real B, FAC, HOLD, VNORM, ONE, ZERO, SUM, BINV\n integer MODE, LPIVOT, L1, M, LDC, NVC\n integer JCBASE, JCPIV, IUL0, J, I\n parameter (ONE = 1.0E0, ZERO = 0.0E0)\nC ------------------------------------------------------------------\n if (0.ge.LPIVOT .or. LPIVOT.ge.L1 .or. L1.gt.M) return\n if( MODE .eq. 1) then\nC ****** CONSTRUCT THE TRANSFORMATION. ******\n IUL0 = L1 - 1\n if(IUL0 .eq. LPIVOT) then\n VNORM = SNRM2(M-L1+2, U(IUL0), 1)\n else\n HOLD = U(IUL0)\n U(IUL0) = U(LPIVOT)\n VNORM = SNRM2(M-L1+2, U(IUL0), 1)\n U(IUL0) = HOLD\n endif\nc\n if (U(LPIVOT) .gt. ZERO) VNORM = -VNORM\n UPARAM = U(LPIVOT)-VNORM\n U(LPIVOT) = VNORM\n endif\nC ****** Apply the transformation I + U*(U**T)/B to C. ****\nC\n if (NVC .le. 0) return\n B = UPARAM * U(LPIVOT)\nC Here B .le. 0. If B = 0., return.\n if (B .eq. ZERO) return\n BINV = ONE / B\n JCBASE = 0\nc\n do 120 J = 1,NVC\n JCPIV = JCBASE + LPIVOT\n SUM = C(JCPIV) * UPARAM\n do 90 I = L1, M\n SUM = SUM + C(JCBASE+I)*U(I)\n 90 continue\n if (SUM .NE. ZERO) then\n FAC = SUM * BINV\n C(JCPIV) = C(JCPIV) + FAC*UPARAM\n do 110 I = L1, M\n C(JCBASE+I) = C(JCBASE+I) + FAC*U(I)\n 110 continue\n endif\n JCBASE = JCBASE + LDC\n 120 continue\n return\n end\n", "meta": {"hexsha": "cf0f7f32933cce34d3b1b1435d5d3b7ed5bd50c1", "size": 5548, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/shtcc.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/shtcc.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/shtcc.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 45.1056910569, "max_line_length": 72, "alphanum_fraction": 0.5611031002, "num_tokens": 1590, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772384450967, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.6932358531937216}} {"text": "program log_det_test\n use m_util\n implicit none\n \n real(dp), dimension(3,3) :: A\n real(dp) :: expected\n\n A = reshape((/ 1.0_dp, 5.0_dp, 20.0_dp, -2.0_dp, -0.5_dp, 8.0_dp, 7.0_dp, 1.0_dp, 0.0_dp /), (/ 3, 3 /))\n\n expected = 5.71042701737487_dp\n if (abs(logdet(A)-expected) > 1.0d-10) stop 1\n \nend program log_det_test\n", "meta": {"hexsha": "1655ff78e56eebd9b82ab52448c936ad7f16153f", "size": 326, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/logdet_test.f90", "max_stars_repo_name": "JaakkoAhola/GPEmulator", "max_stars_repo_head_hexsha": "d4439dfadc51e322000602aa9bd4a02ab271f2e4", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2019-02-13T06:47:31.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-07T22:15:47.000Z", "max_issues_repo_path": "test/logdet_test.f90", "max_issues_repo_name": "JaakkoAhola/GPEmulator", "max_issues_repo_head_hexsha": "d4439dfadc51e322000602aa9bd4a02ab271f2e4", "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": "test/logdet_test.f90", "max_forks_repo_name": "JaakkoAhola/GPEmulator", "max_forks_repo_head_hexsha": "d4439dfadc51e322000602aa9bd4a02ab271f2e4", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-01-23T18:28:11.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-07T22:32:40.000Z", "avg_line_length": 23.2857142857, "max_line_length": 106, "alphanum_fraction": 0.6319018405, "num_tokens": 145, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8740772351648677, "lm_q2_score": 0.793105941403651, "lm_q1q2_score": 0.6932358484549328}} {"text": "Module hard_sphere_structure_module\n Implicit None\n Real * 8, Dimension(:), Allocatable :: Int_absci_1, Int_weight_1\n Integer, Parameter :: Int_points=100\n Real * 8, Dimension(:) , Allocatable :: musj\n Contains\n\n !Function for the calculation of the structure factor for a Hard Sphere System\n Real * 8 Function Sk_HS_py(vw_option,phi_val,k_val)\n Implicit None\n Logical, Intent(in) :: vw_option !Logical variable for Verlet-Weiss correction if True\n Real * 8, Intent(in) :: phi_val !Volume fraction value\n Real * 8, Intent (in) :: k_val !Value of the wave vector\n Real * 8 :: k_vw,k_func,ckdum,phi_vw,dum1,dum2,dum3,dum4,dumsin,dumcos\n Real * 8 :: k_vw2,k_vw3,k_vw4,k_vw6\n If (vw_option .EQV. .TRUE.) Then\n !Verlet-Weiss correction for the volume fraction\n phi_vw=phi_val*(1.d0 - (phi_val / 16.d0))\n !Verlet-Weiss correction for the wave-vector\n k_vw= k_val * ( ( phi_vw / phi_val ) ** ( 1.d0 / 3.d0 ) )\n Else\n phi_vw=phi_val\n k_vw= k_val\n End If\n dum1= - ( ( 1.d0 + 2.d0 * phi_vw ) ** 2 )\n dum2= 6.d0 * phi_vw * ( ( 1.d0 + ( phi_vw / 2.d0 ) ) ** 2 )\n dum3= - 0.5d0 * phi_vw * ( ( 1.d0 + ( 2.d0 * phi_vw ) ) ** 2 )\n dum4= ( 1.d0 - phi_vw )\n dum4= dum4 ** 4\n dum1= dum1 / dum4\n dum2= dum2 / dum4\n dum3= dum3 / dum4\n k_vw2=k_vw * k_vw\n If (k_vw > 0.075d0 ) Then\n dumsin= sin( k_vw )\n dumcos= cos( k_vw )\n k_vw3=k_vw2 * k_vw\n k_vw4=k_vw3 * k_vw\n k_vw6=k_vw4 * k_vw2\n ckdum= ( dum1 * ( dumsin - k_vw * dumcos ) / ( k_vw3 ) ) + &\n & ( dum2 * ( ( ( 2.d0 * k_vw ) * dumsin ) + ( ( - ( k_vw2 ) + 2.d0 ) * dumcos ) - 2.d0 ) / &\n & ( k_vw4 ) ) + ( dum3 * ( ( ( 4.d0 * ( k_vw3 ) - 24.d0 * k_vw ) * dumsin )&\n & + ( ( - ( k_vw4 ) + 12.d0 * ( k_vw2 ) - 24.d0 ) * dumcos ) + 24.d0 ) / ( k_vw6 ))\n Else\n ckdum = dum1 * ( (1.d0 / 3.d0) - ( k_vw2 / 30.d0 ) ) + dum2 * ( 0.25d0 - ( k_vw2 / 36.d0 ) ) &\n & + dum3 * ( ( 1.d0 / 6.d0 ) - ( k_vw2 / 48.d0 ) )\n End If\n ckdum = 24.d0 * phi_vw * ckdum\n Sk_HS_py = 1.d0 / ( 1.d0 - ckdum )\n return\n !*********!\n End Function\n\n !Subroutine for the calculation of the Structure factor of a Hard Sphere System\n !for an array of wave vectors \"k_val\" of dimension \"k_points\" that goes into\n !a predefined array \"sk_val\"\n !vw_option Logical value, True for Verlet-Weiss Correction, False Otherwise\n Subroutine Calc_Sk_HS_py_mono(vw_option,phi_val,k_points,k_val,sk_val)\n Implicit None\n Logical, Intent(in) :: vw_option !Logical variable for activating Verlet-Weiss correction if True\n Real * 8, Intent(in) :: phi_val !Volume fraction of the system\n Real * 8, Dimension(:), Intent(in) :: k_val !Wave vector array\n Real * 8, Dimension(:), Intent(out) :: sk_val !Structure factor array\n Integer, Intent(in) :: k_points\n Integer :: i1\n Do i1=1, k_points\n sk_val(i1)=Sk_HS_py(vw_option,phi_val,k_val(i1))\n End Do\n End Subroutine\n\n !Function for the calculation of the structure factor of Hard Disk System using Rosenfeld Approximation\n Real * 8 Function Sk_HD_ros(phi_val,k_val)\n Implicit None\n Real * 8, Intent(in) :: phi_val\n Real * 8, Intent(in) :: k_val\n Integer :: i1\n Real * 8 :: A,B,G,J0,J1,J12,Z1,Z2,X, phi_val2, phi_val3, phi_val4,dum1\n Real * 8 :: k_val2\n phi_val2=phi_val * phi_val\n phi_val3=phi_val2 * phi_val\n phi_val4=phi_val3 * phi_val\n Z1= ( 1.d0 + 0.128d0 * ( phi_val2 ) + 0.027d0 * ( phi_val3 ) + 0.06d0 * &\n & ( phi_val4 ) ) / ( 1.d0 - phi_val ) ** 2\n Z2= ( ( 2.d0 * 0.128d0 * phi_val ) + ( 3.d0 * 0.027d0 * ( phi_val2 ) ) + &\n & ( 4.d0 * 0.06d0 * ( phi_val3 ) ) ) * ( ( 1.d0 - phi_val ) ** 2 )\n Z2= ( Z2 / ( 1.d0 - phi_val ) ** 4 ) + ( 2.d0 * ( Z1 / ( 1.d0 - phi_val ) ) )\n !Z1=1.0d0/(1.d0-eta(1))**2.d0\n !Z2=2.0d0/(1.d0-eta(1))**3.d0\n X= Z1 + phi_val * Z2\n G= Sqrt( Z2 / 2.d0 )\n A= ( 1.d0 + ( ( 2.d0 * phi_val - 1.d0 ) * X ) + ( 2.d0 * phi_val * G ) ) / phi_val\n B= ( ( ( 1.d0 - phi_val ) * X ) - 1.d0 - ( 3.d0 * phi_val * G ) ) / phi_val\n If ( k_val > 0.075d0 ) Then\n \tJ0= BESSEL_JN ( 0 , k_val/ 2.d0 )\n \tJ1= BESSEL_JN ( 1 , k_val/ 2.d0 )\n \tJ12= BESSEL_JN ( 1 , k_val )\n dum1= A * ( ( 2.d0 * J1 / k_val ) ** 2 ) + ( B * 2.d0 * J0 * J1 /k_val ) + G * 2.d0 * J12 /k_val\n Else\n k_val2= k_val * k_val\n dum1= A * ( ( 0.25d0 - k_val2 / 64.d0 ) ) + ( B * ( 0.5d0 - 3.d0 * k_val2 / 64.d0 ) ) &\n & + G * ( 1.d0 - k_val2 / 8.d0 )\n End If\n dum1= dum1 * 4.d0 * phi_val\n Sk_HD_ros= 1.d0 / ( 1.d0 + dum1 )\n return\n End Function\n\n !Subroutine for the calculation of the Structure factor of a Hard Disk System\n !for an array of wave vectors \"k_val\" of dimension \"k_points\" that goes into\n !a predefined array \"sk_val\" using the approximation derived by Rosenfeld\n Subroutine Calc_Sk_hd_ros_mono(phi_val,k_points,k_val,sk_val)\n Implicit None\n Real * 8, Intent(in) :: phi_val !Volume fraction of the system\n Real * 8, Dimension(:), Intent(in) :: k_val !Wave vector array\n Real * 8, Dimension(:), Intent(out) :: sk_val !Structure factor array\n Integer, Intent(in) :: k_points\n Integer :: i1\n Do i1=1, k_points\n sk_val(i1)=Sk_HD_ros(phi_val,k_val(i1))\n End Do\n End Subroutine\n\n !!Function that calculates the structure factor of a HARD Sphere + Atractive Yukawa\n !System with particle size equal to the unit using Sharma Sharma approximation\n Real * 8 Function Sk_HSAY(vw_option,phi_val,Temp_val,z_yuk,k_val)\n Implicit None\n Logical, Intent(in) :: vw_option !Logical variable for Verlet-Weiss correction if True\n Real * 8, Intent (in) :: phi_val !Volume fraction value\n Real * 8, Intent (in) :: k_val !Value of the wave vector\n Real * 8, Intent (in) :: Temp_val !Value of the Temperature\n Real * 8, Intent (in) :: z_yuk !Value of the screening constant\n Real * 8 :: dum1,ck_dum\n ck_dum= ( 1.d0 / Sk_HS_py(vw_option,phi_val,k_val) )\n If ( k_val > 0.075d0 ) Then\n dum1= 24.d0 * phi_val * ( ( k_val * cos(k_val) ) + ( z_yuk * sin(k_val) ) ) &\n & / ( Temp_val * k_val * ( ( k_val ** 2 ) + ( z_yuk ** 2) ) )\n Else\n dum1= 24.d0 * phi_val * ( ( 1.d0 - 0.5d0 * k_val ** 2 ) + ( z_yuk * ( 1.d0 - &\n & k_val ** 2 / 6.d0 ) ) ) / ( Temp_val * ( ( k_val ** 2 ) + ( z_yuk ** 2) ) )\n End If\n ck_dum= ck_dum-dum1\n sk_HSAY= 1.d0 / ck_dum\n return\n End Function\n\n !Subroutine for the calculation of the Structure factor of a Hard Sphere + Atractive\n !Yukawa System for an array of wave vectors \"k_val\" of dimension \"k_points\" that goes into\n !a predefined array \"sk_val\", with \"vw_option\" Logical value which for True selects Verlet-Weiss Correction\n Subroutine Calc_Sk_HSAY_sh_sh(vw_option,phi_val,Temp_val,z_yuk,k_points,k_val,sk_val)\n Implicit None\n Logical, Intent(in) :: vw_option !Logical variable for activating Verlet-Weiss correction if True\n Real * 8, Intent(in) :: phi_val !Volume fraction of the system\n Real * 8, Intent(in) :: Temp_val !Value of the temperature\n Real * 8, Intent(in) :: z_yuk !Value of the Yukawa screening reach\n Real * 8, Dimension(:), Intent(in) :: k_val !Wave vector array\n Real * 8, Dimension(:), Intent(out) :: sk_val !Structure factor array\n Integer, Intent(in) :: k_points\n Integer :: i1\n Do i1=1, k_points\n sk_val(i1)=Sk_HSAY(vw_option,phi_val,Temp_val,z_yuk,k_val(i1))\n End Do\n End Subroutine\n\n !Function that calculates the structure factor of a HARD Disk + Atractive Yukawa\n !System with particle size equal to the unit using Sharma Sharma approximation\n Real * 8 Function Sk_HDAY(phi_val,Temp_val,z_yuk,k_val)\n Implicit None\n Real * 8, Intent (in) :: phi_val !Volume fraction value\n Real * 8, Intent (in) :: k_val !Value of the wave vector\n Real * 8, Intent (in) :: Temp_val !Value of the Temperature\n Real * 8, Intent (in) :: z_yuk !Value of the screening constant\n Real * 8 :: dum1,ck_dum,y, J0\n Real * 8, Parameter :: dy=1.d-5\n ck_dum= ( 1.d0 / Sk_HD_ros(phi_val,k_val) )\n !FOURIER TRANSFORM OF beta u(r)\n y= 1.d0 !initial value of integration -> Particle size =1.d0\n dum1= 0.d0\n Do While ( exp(- z_yuk * y ) > dy )\n \tJ0= BESSEl_JN(0, k_val * y)\n \tdum1= dum1 + J0 * exp(- y * z_yuk )\n \ty= y + dy\n End Do\n dum1 = 8.d0 * phi_val * dum1 * ( dy ) * exp( z_yuk ) / Temp_val !!!!!!!!!!!!!!!!!!!!!!!!!!!rho beta u\n ck_dum=ck_dum-dum1\n sk_HDAY= 1.d0 / ck_dum\n return\n End Function\n\n !Function that calculates the structure factor of a HARD Disk + Atractive Yukawa\n !System with particle size equal to the unit using Sharma Sharma approximation\n Real * 8 Function Sk_HDAY2(phi_val,Temp_val,z_yuk,k_val)\n Implicit None\n Real * 8, Intent (in) :: phi_val !Volume fraction value\n Real * 8, Intent (in) :: k_val !Value of the wave vector\n Real * 8, Intent (in) :: Temp_val !Value of the Temperature\n Real * 8, Intent (in) :: z_yuk !Value of the screening constant\n Real * 8 :: dum1,ck_dum,y, J0, weight\n Integer :: EOFint,i1\n ck_dum= ( 1.d0 / Sk_HD_ros(phi_val,k_val) )\n !FOURIER TRANSFORM OF beta u(r)\n dum1= 0.d0\n EOFint=0\n i1=0\n Do i1=1,Int_points\n y= Int_absci_1(i1)\n weight=Int_weight_1(i1)\n J0= BESSEl_JN(0, k_val * y)\n \tdum1= dum1 + weight *J0 * exp(- y * z_yuk )\n End Do\n dum1 = 8.d0 * phi_val * ( 1.d0 / ( SQRT( z_yuk ** 2 + k_val ** 2) ) - dum1 ) * exp( z_yuk ) / Temp_val !!!!!!!!!!!!!!!!!!!!!!!!!!!rho beta u\n ck_dum=ck_dum-dum1\n sk_HDAY2= 1.d0 / ck_dum\n return\n End Function\n\n !Obtention of the abscissas and weights for the integral used in Sk_HDAY2\n Subroutine Sk_HDAY2_integral_constants(Allocation)\n Implicit None\n Integer :: EOFint,i1\n Logical, Intent(in) :: Allocation\n If (Allocation .eqv. .True.) Then\n Allocate(Int_absci_1(Int_points))\n Allocate(Int_weight_1(Int_points))\n Open(unit=33, File=\"./source_code/operations/Integral_method1_abscisas_weights.dat\", Status=\"Old\" )\n Do i1=1,Int_points\n Read (33, *, IOSTAT=EOFint) Int_absci_1(i1), Int_weight_1(i1)\n End Do\n Close(33)\n Else\n Deallocate(Int_absci_1)\n Deallocate(Int_weight_1)\n End If\n End Subroutine\n\n !Subroutine for the calculation of the Structure factor of a Hard Disk + Atractive\n !Yukawa System for an array of wave vectors \"k_val\" of dimension \"k_points\" that goes into\n !a predefined array \"sk_val\", with \"vw_option\" Logical value which for True selects Verlet-Weiss Correction\n Subroutine Calc_Sk_HDAY_sh_sh(phi_val,Temp_val,z_yuk,k_points,k_val,sk_val)\n Implicit None\n Real * 8, Intent(in) :: phi_val !Volume fraction of the system\n Real * 8, Intent(in) :: Temp_val !Value of the temperature\n Real * 8, Intent(in) :: z_yuk !Value of the Yukawa screening reach\n Real * 8, Dimension(:), Intent(in) :: k_val !Wave vector array\n Real * 8, Dimension(:), Intent(out) :: sk_val !Structure factor array\n Integer, Intent(in) :: k_points\n Integer :: i1\n Do i1=1, k_points\n !sk_val(i1)=Sk_HDAY(phi_val,Temp_val,z_yuk,k_val(i1))\n sk_val(i1)=Sk_HDAY2(phi_val,Temp_val,z_yuk,k_val(i1))\n End Do\n End Subroutine\n\n Real * 8 Function spinodal_T_HDAY(phi_val,z_yuk)\n Implicit None\n Real * 8, Intent(in) :: phi_val, z_yuk\n spinodal_T_HDAY= 8.d0 * phi_val * Sk_HD_ros(phi_val,0.d0) / z_yuk\n End\n\n Real * 8 Function spinodal_T_HSAY(phi_val,z_yuk,vw_option)\n Implicit None\n Real * 8, Intent(in) :: phi_val, z_yuk\n Logical, intent(in) :: vw_option\n Real * 8 :: phi_dum\n if (vw_option .eqv. .true. ) then\n phi_dum = phi_val*(1.d0 - (phi_val / 16.d0))\n else\n phi_dum = phi_val\n end if\n spinodal_T_HSAY = 24.d0 * phi_dum * (z_yuk + 1.d0) * Sk_HS_py(vw_option,phi_val,0.d0) / (z_yuk ** 2)\n end\n\n Real * 8 Function blip_TLJ(Temp_val,dimension,nu_val)\n Use integration_module\n Implicit None\n Real * 8, Intent(in) :: Temp_val,dimension,nu_val\n Real * 8 :: dx, x\n Real * 8, Dimension(:), Allocatable :: Integrand\n Integer :: nx, i1\n dx=1.d-6\n nx= Int(1.d0/dx)\n Allocate(Integrand(nx))\n Do i1=1, nx\n x=i1*dx\n Integrand(i1) = ( (x) ** (dimension-1.d0) ) * exp(- ( (x ** - (2 * nu_val ) ) &\n &- 2.d0 * (x ** (-nu_val)) + 1.d0) / Temp_val )\n End Do\n blip_TLJ=1.d0 - dimension * DIntegral_simpson_3_8(Integrand,nx,dx)\n blip_TLJ=blip_TLJ**( 1.d0 / dimension )\n Deallocate(Integrand)\n End\n\n Subroutine Calc_gr_HDAY(grs,rs,kmax_val, phi_val, Temp_val, z_yuk, np, k)\n Implicit None\n Real * 8, Dimension(:), Intent(out) :: grs\n Real * 8, Dimension(:), Intent(out) :: rs\n Real * 8, Intent(in) :: kmax_val\n REal * 8, Intent(in) :: phi_val, Temp_val, z_yuk\n Real * 8, Dimension(:), Intent(out) :: k\n Integer, Intent(in) :: np\n Real * 8 :: K_max, R_max, ri,kj, J0,J1\n Integer :: i1, i2\n Do i1=1, np\n k(i1)= musj(i1) * kmax_val /musj(np)\n rs(i1) = musj(i1) / kmax_val\n End Do\n\n Do i1=1,np\n grs(i1)=0.d0\n Do i2=1,np-1\n J0=BESSEl_JN(0,(k(i2)*rs(i1)))\n J1=BESSEl_JN(1,(k(i2)*rs(np)))\n J1= J1 * J1\n grs(i1)= grs(i1) + (Sk_HDAY2(phi_val,Temp_val,z_yuk,k(i1)) * J0 / J1 )\n End Do\n grs(i1) = grs(i1) / (4.d0 * Atan(1.d0) * rs(np) * rs(np) )\n End Do\n End Subroutine\n\n Subroutine Calc_Sk_HDAY_low_rho(np,musj,rs,ks, R_max, phi_val, Temp_val, Z_yuk, grV, SkV)\n Implicit None\n Real * 8, Dimension(:), Intent(out) :: grV, SkV\n Real * 8, Dimension(:) :: rs, ks\n Real * 8, Dimension(:), Intent(in) :: musj\n Real * 8, Intent(in) :: phi_val, Temp_val, Z_yuk\n Integer, Intent(in) :: np\n Real * 8 :: R_max, J0 , J1, kn, delta_rho\n Integer :: i1, i2\n\n !Calculation of the wave vectors, radial distances and radial distribution\n Do i1=1, np\n ks(i1) = musj(i1) / R_max\n rs(i1) = musj(i1) * R_max / musj(np)\n grV(i1) = low_rho_gr_HDAY(rs(i1), Temp_val, Z_yuk)\n End Do\n kn = ks(np)\n !Calculation of the structure factor for each wave vector\n !S(k) = 1 + (\u03c14\u03c0/k) \u222b g(r) Sin(kr) dr\n Do i1=1,np\n SkV(i1) = 0.d0\n !J0=rs(1)*grV(1)*BESSEl_JN(0,(ks(i1) * rs(1)))\n Do i2=2,np!-1\n delta_rho= rs(i2) - rs(i2-1)\n J0=BESSEl_JN(0,(ks(i1) * rs(i2)))\n J1=BESSEl_JN(1,(kn * rs(i2)))\n J1= J1 * J1\n SkV(i1) = SkV(i1) + ( (grV(i2)-1.d0) * J0 / J1 )\n !J1=rs(i2)*(grV(i2)-1.d0)*BESSEl_JN(0,(ks(i1) * rs(i2)))\n !SkV(i1) = SkV(i1) + 0.5d0 * delta_rho * (J0+J1)\n !J0=J1\n End Do\n SkV(i1) = 1.d0 + (16.d0 * phi_val * SkV(i1) / (kn * kn ))\n !SkV(i1) = 1.d0 + (8.d0 * phi_val * SkV(i1))\n End Do\n\n End Subroutine\n\n Real * 8 Function low_rho_gr_HDAY(X_val,Temp_val,Z_val)\n Implicit None\n Real * 8 :: X_val, Temp_val, Z_val\n If (X_val < 1.d0 ) Then\n low_rho_gr_HDAY =0.d0\n Else\n low_rho_gr_HDAY = exp( exp(- Z_val * (X_val-1) ) / (Temp_val * X_val) )\n End If\n End\n\n Subroutine Calc_hk_ck(Sk_val,knp_val,rho_val,hk_v,ck_v)\n Implicit None\n Real * 8, Dimension(:), Intent(in) :: Sk_val\n Real * 8, Dimension(:), Intent(out) :: hk_v, ck_v\n Integer, Intent(in) :: knp_val\n Real * 8 :: rho_val\n hk_v = (Sk_val - 1.d0 ) / rho_val\n ck_v = (1.d0 - (1.d0 / Sk_val) )/rho_val\n End Subroutine\n\n Subroutine Calc_FT_2D_radial(rnp,Fr,Fk,rv,kv)\n Implicit None\n Real * 8, Dimension(:) :: Fr, Fk, rv, kv\n Integer :: rnp\n Integer :: i1,i2\n Real * 8 :: kn,kn2, int_const, J0, J1\n kn=kv(rnp)\n kn2=kn*kn\n int_const = 4.d0* 4.d0 * Atan(1.d0) / kn2\n Do i1=1,rnp\n Fk(i1) = 0.d0\n Do i2=1,rnp-1\n J0=BESSEl_JN(0,(kv(i1) * rv(i2)))\n J1=BESSEl_JN(1,(kn * rv(i2)))\n J1= J1 * J1\n Fk(i1) = Fk(i1) + ( (Fr(i2)) * J0 / J1 )\n End Do\n Fk(i1) = int_const * Fk(i1)\n End Do\n\n End Subroutine\n\n Subroutine Calc_IFT_2D_radial(rnp,Fr,Fk,rv,kv)\n Implicit None\n Real * 8, Dimension(:) :: Fr, Fk, rv, kv\n Integer :: rnp\n Integer :: i1,i2\n Real * 8 :: rn,rn2, int_const, J0, J1\n rn=rv(rnp)\n rn2=rn*rn\n int_const = 1.d0 / (rn2 * 4.d0 * Atan(1.d0))\n Do i1=1,rnp\n Fr(i1) = 0.d0\n Do i2=1,rnp-1\n J0=BESSEl_JN(0,(kv(i2) * rv(i1)))\n J1=BESSEl_JN(1,(rn * kv(i2)))\n J1= J1 * J1\n Fr(i1) = Fr(i1) + ( (Fk(i2)) * J0 / J1 )\n End Do\n Fr(i1) = int_const * Fr(i1)\n End Do\n\n End Subroutine\n\n Subroutine Calc_sk_HDAY_Sharma_Sharma_V2(knp_val,rv,kv, phi_val, Temp_val, Z_yuk, grV, SkV)\n Implicit None\n Real * 8, Dimension(:) :: grV, SkV\n Real * 8, Dimension(:) :: rv, kv\n Real * 8, Intent(in) :: phi_val, Temp_val, Z_yuk\n Integer, Intent(in) :: knp_val\n Real * 8, Dimension(:), Allocatable :: ck_v, hk_v, cr_v, hr_v, Sk_aux, Yk_v,Yr_v\n Real * 8 :: rho_val,dum1\n Integer :: i1, i2\n Allocate(ck_v(knp_val))\n Allocate(hk_v(knp_val))\n Allocate(cr_v(knp_val))\n Allocate(hr_v(knp_val))\n Allocate(Sk_aux(knp_val))\n rho_val= phi_val / Atan(1.d0)\n Call Calc_Sk_hd_ros_mono(phi_val, knp_val,kv,SkV)\n Call Calc_hk_ck(Skv,knp_val,rho_val,hk_v,ck_v)\n cr_v=0.d0\n Do i1=1, knp_val\n if( rv(i1) >= 1.d0 ) cr_v(i1) = exp(exp(-Z_yuk * (rv(i1) - 1.d0) ) / (Temp_val*rv(i1))) - 1.d0\n End Do\n Call Calc_FT_2D_radial(knp_val,cr_v,Sk_aux,rv,kv)\n ck_v = ck_v + Sk_aux\n SkV= 1.d0 / (1.d0 - rho_val * ck_v)\n !Open(unit=10, file=\"ck_PY.dat\", Status=\"Replace\")\n !Do i1=1, knp_val\n ! Write(10,*), kv(i1), ck_v(i1), Sk_aux(i1)\n !End Do\n !Close(10)\n Deallocate(ck_v)\n Deallocate(hk_v)\n Deallocate(cr_v)\n Deallocate(hr_v)\n Deallocate(Sk_aux)\n End Subroutine\n\nEnd Module\n", "meta": {"hexsha": "8c5f5ad54c58f4b8fc38857b5618fa43f1682103", "size": 17536, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "source_code/structures/Hard_Sphere/hard_sphere_structure_old.f03", "max_stars_repo_name": "LANIMFE/HS_HSSW_quench_NESCGLE", "max_stars_repo_head_hexsha": "d6d18fc3158fc45b51db5e7a77e2ed4639eaf0de", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-14T17:17:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-14T17:17:00.000Z", "max_issues_repo_path": "source_code/structures/Hard_Sphere/hard_sphere_structure_old.f03", "max_issues_repo_name": "LANIMFE/HS_HSSW_quench_NESCGLE", "max_issues_repo_head_hexsha": "d6d18fc3158fc45b51db5e7a77e2ed4639eaf0de", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source_code/structures/Hard_Sphere/hard_sphere_structure_old.f03", "max_forks_repo_name": "LANIMFE/HS_HSSW_quench_NESCGLE", "max_forks_repo_head_hexsha": "d6d18fc3158fc45b51db5e7a77e2ed4639eaf0de", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.288209607, "max_line_length": 145, "alphanum_fraction": 0.6078353102, "num_tokens": 6644, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505453836383, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.6932279573134011}} {"text": "\r\n subroutine fcn(me,x,y,f)\r\n !! subroutine computing the value of \\(dy/dx=f(x,y)\\)\r\n\r\n use iso_fortran_env, only: wp => real64\r\n\r\n use easydop853_module\r\n \r\n implicit none\r\n\r\n class(dop853_class),intent(inout) :: me\r\n !! dop853_class object\r\n real(wp),intent(in) :: x\r\n !! independent variable \\(x\\)\r\n real(wp),dimension(:),intent(in) :: y\r\n !! state vector \\(y(x)\\)\r\n real(wp),dimension(:),intent(out) :: f\r\n !! derivative vector \\(f(x,y)=dy/dx\\)\r\n\r\n f(1:3)=y(4:6)\r\n f(4:6)=-y(1:3)/sum(y(1:3)**2.0_wp)**1.5_wp\r\n\r\n end subroutine fcn\r\n", "meta": {"hexsha": "124a506dfcf21df53a12b0aef1a38fb90a048330", "size": 605, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fcn.f90", "max_stars_repo_name": "GasinAn/easydop853", "max_stars_repo_head_hexsha": "b65193dbe43c1000958b77c1050296ef916d17f1", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-29T23:19:51.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-29T23:19:51.000Z", "max_issues_repo_path": "fcn.f90", "max_issues_repo_name": "GasinAn/easydop853", "max_issues_repo_head_hexsha": "b65193dbe43c1000958b77c1050296ef916d17f1", "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": "fcn.f90", "max_forks_repo_name": "GasinAn/easydop853", "max_forks_repo_head_hexsha": "b65193dbe43c1000958b77c1050296ef916d17f1", "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.2083333333, "max_line_length": 58, "alphanum_fraction": 0.5421487603, "num_tokens": 194, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6932279551506491}} {"text": "module example_eigen\n\nuse phaml\nimplicit none\n\nprivate\npublic setup_example_eigen\n\nreal(my_real), save :: prob_param=25.0_my_real\n\ncontains\n\nsubroutine setup_example_eigen()\nuse pde_pointers\ncall set_pde_pointers(pdecoefs, bconds, iconds, trues, truexs, trueys)\nend subroutine\n\nsubroutine pdecoefs(x,y,cxx,cxy,cyy,cx,cy,c,rs)\nreal(my_real), intent(in) :: x,y\nreal(my_real), intent(out) :: cxx(:,:),cxy(:,:),cyy(:,:),cx(:,:),cy(:,:), &\n c(:,:),rs(:)\ncxx(1,1) = 1.0_my_real\ncyy(1,1) = 1.0_my_real\nc(1,1) = 0.5_my_real*prob_param*(x*x+3.0_my_real*y*y)\nrs(1) = 1.0_my_real\n\ncxy=0; cx=0; cy=0\nend subroutine pdecoefs\n\nsubroutine bconds(x,y,bmark,itype,c,rs)\nreal(my_real), intent(in) :: x,y\ninteger, intent(in) :: bmark\ninteger, intent(out) :: itype(:)\nreal(my_real), intent(out) :: c(:,:),rs(:)\nitype = DIRICHLET\nc = 0.0_my_real\nrs(1) = 0.0_my_real\nend subroutine bconds\n\nfunction iconds(x,y,comp,eigen)\nreal(my_real), intent(in) :: x,y\ninteger, intent(in) :: comp,eigen\nreal(my_real) :: iconds\niconds = 0.0_my_real\nend function iconds\n\nfunction trues(x,y,comp,eigen) ! real (my_real)\nreal(my_real), intent(in) :: x,y\ninteger, intent(in) :: comp,eigen\nreal (my_real) :: trues\nreal (my_real) :: xmax,ymax,tmax,d,sq3\nsq3 = sqrt(3.0_my_real)\nd = sqrt(prob_param/8)\n\nselect case (eigen)\n\ncase(1)\n\n trues = exp(-d*(x*x+sq3*y*y))\n\n! Eigenvectors are unique up to a multiplicative constant, and are scaled to\n! have M-norm 1.0; this is approximately the scaling factor for this solution\n\n! trues = 1.217006012276_my_real * trues\n\n! TEMP disabling the 2nd and 3rd true solutions because 1) the scale factor\n! seems to be slightly off, 2) can't determine the sign of the scale factor\n\ncase(2)\n\n trues = huge(0.0_my_real)\n! xmax = sqrt(1/(2*d))\n! tmax = xmax*exp(-d*xmax**2)\n! trues = x*exp(-d*(x*x+sq3*y*y))\n! trues = 1.04009347278_my_real * trues / tmax\n\ncase(3)\n\n trues = huge(0.0_my_real)\n! ymax = sqrt(1/(2*sq3*d))\n! tmax = ymax*exp(-d*sq3*ymax**2)\n! trues = y*exp(-d*(x*x+sq3*y*y))\n! trues = 1.038366656409_my_real * trues / tmax\n\ncase default\n\n trues = huge(0.0_my_real)\n\nend select\n\nend function trues\n\nfunction truexs(x,y,comp,eigen) ! real (my_real)\nreal(my_real), intent(in) :: x,y\ninteger, intent(in) :: comp,eigen\nreal (my_real) :: truexs\n\nreal (my_real) :: xmax,ymax,tmax,d,sq3\nsq3 = sqrt(3.0_my_real)\nd = sqrt(prob_param/8)\n\nselect case (eigen)\n\ncase(1)\n\n truexs = exp(-d*(x*x+sq3*y*y))\n truexs = -2*d*x*truexs\n! truexs = 1.217006012276_my_real * truexs\n\n! TEMP disabling the 2nd and 3rd true solutions because 1) the scale factor\n! seems to be slightly off, 2) can't determine the sign of the scale factor\n\ncase(2)\n\n truexs = huge(0.0_my_real)\n! xmax = sqrt(1/(2*d))\n! tmax = xmax*exp(-d*xmax**2)\n! truexs = exp(-d*(x*x+sq3*y*y))\n! truexs = (1-2*d*x*x)*truexs\n! truexs = 1.04009347278_my_real * truexs / tmax\n\ncase(3)\n\n truexs = huge(0.0_my_real)\n! ymax = sqrt(1/(2*sq3*d))\n! tmax = ymax*exp(-d*sq3*ymax**2)\n! truexs = exp(-d*(x*x+sq3*y*y))\n! truexs = -2*d*x*y*truexs\n! truexs = 1.038366656409_my_real * truexs / tmax\n\ncase default\n\n truexs = huge(0.0_my_real)\n\nend select\n\nend function truexs\n\nfunction trueys(x,y,comp,eigen) ! real (my_real)\nreal(my_real), intent(in) :: x,y\ninteger, intent(in) :: comp,eigen\nreal (my_real) :: trueys\n\nreal (my_real) :: xmax,ymax,tmax,d,sq3\n\nsq3 = sqrt(3.0_my_real)\nd = sqrt(prob_param/8)\n\nselect case (eigen)\n\ncase(1)\n\n trueys = exp(-d*(x*x+sq3*y*y))\n trueys = -2*sq3*d*y*trueys\n! trueys = 1.217006012276_my_real * trueys\n\n! TEMP disabling the 2nd and 3rd true solutions because 1) the scale factor\n! seems to be slightly off, 2) can't determine the sign of the scale factor\n\ncase(2)\n\n trueys = huge(0.0_my_real)\n! xmax = sqrt(1/(2*d))\n! tmax = xmax*exp(-d*xmax**2)\n! trueys = exp(-d*(x*x+sq3*y*y))\n! trueys = -2*sq3*d*y*x*trueys\n! trueys = 1.04009347278_my_real * trueys / tmax\n\ncase(3)\n\n trueys = huge(0.0_my_real)\n! ymax = sqrt(1/(2*sq3*d))\n! tmax = ymax*exp(-d*sq3*ymax**2)\n! trueys = exp(-d*(x*x+sq3*y*y))\n! trueys = (1-2*d*sq3*y**2)*trueys\n! trueys = 1.038366656409_my_real * trueys / tmax\n\ncase default\n\n trueys = huge(0.0_my_real)\n\nend select\n\nend function trueys\n\nend module\n", "meta": {"hexsha": "589e45d00feceb0b6bf91db8dc06ff795198f866", "size": 4256, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "phaml/example_eigen.f90", "max_stars_repo_name": "qsnake/phaml", "max_stars_repo_head_hexsha": "8925b4c32657bbd9f81cd5f8f9d6739151c66fec", "max_stars_repo_licenses": ["mpich2"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-09-07T15:46:34.000Z", "max_stars_repo_stars_event_max_datetime": "2018-09-07T15:46:34.000Z", "max_issues_repo_path": "phaml/example_eigen.f90", "max_issues_repo_name": "qsnake/phaml", "max_issues_repo_head_hexsha": "8925b4c32657bbd9f81cd5f8f9d6739151c66fec", "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": "phaml/example_eigen.f90", "max_forks_repo_name": "qsnake/phaml", "max_forks_repo_head_hexsha": "8925b4c32657bbd9f81cd5f8f9d6739151c66fec", "max_forks_repo_licenses": ["mpich2"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.7593582888, "max_line_length": 80, "alphanum_fraction": 0.6609492481, "num_tokens": 1629, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422645, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6932279533735992}} {"text": " double precision function DPQUAD(KORDER, NPC, XI, PC, X1, X2)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc>> 1994-10-20 DPQUAD Krogh Changes to use M77CON\nc>> 1992-11-12 DPQUAD C. L. Lawson, JPL Saving IL1 and IL2.\nc>> 1992-10-27 C. L. Lawson, JPL\nc>> 1988-03-16 C. L. Lawson, JPL\nC\nC This subroutine computes the integral over [X1,X2] of a\nc piecewise polynomial using the piecewise Power\nc representation given by [XI, PC, NPC, KORDER].\nc The degrees of the polynomial pieces are KORDER-1.\nc Require 2 .le. KORDER .le. 20.\nc Permits X1 .le. X2 or X1 gt. X2.\nC The \"proper interpolation interval\" is from XI(1) to XI(NPC+1).\nc For most reliable results, X1 and X2 should lie in this\nc interval, however this subr will give a result even if this\nc is not the case by use of extrapolation.\nc ------------------------------------------------------------------\nC DESCRIPTION OF ARGUMENTS\nC INPUT:\nc KORDER [in] Order of the polynomial pieces. This is one\nc greater than the degree of the pieces. KORDER is also the\nc leading dimension of the array PC(,).\nc Require 2 .le. KORDER .le. 20.\nc NPC - NUMBER OF POLYNOMIAL PIECES\nC XI() - Breakpoint array of length NPC+1\nC PC(i,j) - Coeffs for the Power representation of a piecewise\nc polynomial. i=1,KORDER , j=1,NPC\nc The coeffs PC(*,j) are used at XI(j) and on the\nc interval between XI(j) and XI(j+1).\nc PC(i,j) is the coefficient to be multiplied times\nc (X - X(j))**(i-1).\nC X1,X2 - END POINTS OF QUADRATURE INTERVAL, NORMALLY IN\nC XI(1) .LE. X .LE. XI(NPC+1) but extrapolation is\nc permitted.\nC\nc OUTPUT:\nc DPQUAD - Integral of the piecewise polynomial from X1 to X2.\nc ------------------------------------------------------------------\nc Adapted from subroutine PPQUAD due to D. E. Amos,\nc Sandia, June, 1979. Documented in SAND79-1825. PPQUAD uses the\nc Taylor basis, whereas this subprogram uses the Power basis.\nc Uses the [XI, PC, NPC, KORDER] representation of a piecewise\nc polynomial as presented by Carl De Boor in\nc A PRACTICAL GUIDE TO SPLINES, Springer-Verlag, 1978.\nc (Called [XI, C, LXI, K] in the book.)\nc ------------------------------------------------------------------\nc--D replaces \"?\": ?PQUAD, ?SFIND\nc ------------------------------------------------------------------\n integer II, IL1, IL2, IM, KORDER, LEFT, MODE, NPC\n double precision A, AA, B, BB, DENOM, DX, ONE\n double precision Q, S, SS(2), PC(KORDER,NPC)\n double precision X, X1, X2, XI(NPC+1)\n double precision ZERO\n parameter(ONE = 1.0D0, ZERO = 0.0D0)\n save IL1, IL2\n data IL1, IL2 / 1,1 /\nc ------------------------------------------------------------------\nC\n AA= min(X1,X2)\n BB= max(X1,X2)\n Q = ZERO\n if(AA .eq. BB) go to 90\n call DSFIND ( XI, 1, NPC+1, AA, IL1, MODE )\n call DSFIND ( XI, 1, NPC+1, BB, IL2, MODE )\n do 50 LEFT=IL1,IL2\n if(LEFT .eq. IL1) then\n A=AA\n else\n A= XI(LEFT)\n endif\n if(LEFT .eq. IL2) then\n B = BB\n else\n B = XI(LEFT+1)\n endif\n X = A\n do 40 II=1,2\n SS(II) = ZERO\n DX=X-XI(LEFT)\n if(DX .ne. ZERO) then\n DENOM = dble(KORDER)\n S=PC(KORDER,LEFT)/DENOM\n do 30 IM = KORDER-1, 1, -1\n DENOM = DENOM - ONE\n S = S * DX + PC(IM,LEFT) / DENOM\n 30 continue\n SS(II)=S*DX\n endif\n X = B\n 40 continue\n Q=Q+(SS(2)-SS(1))\n 50 continue\n if(X1 .gt. X2) Q=-Q\n 90 continue\n DPQUAD = Q\n return\n end\n", "meta": {"hexsha": "647766bf1fe5b0740c05b7e58a430cf1722bade1", "size": 3957, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/dpquad.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/dpquad.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/dpquad.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.1782178218, "max_line_length": 72, "alphanum_fraction": 0.5294414961, "num_tokens": 1205, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422645, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.6932279533735991}} {"text": "\tFUNCTION PS_BVSQ ( datain, nparm, clev, ivcord )\nC************************************************************************\nC* PS_BVSQ\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes the square of the Brunt-Vaisala Frequency.\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PS_BVSQ ( DATAIN, NPARM, CLEV, IVCORD )\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tDATAIN(NPARM,*)\tREAL\t\tStation data\t\t\t*\nC*\tNPARM\t\tINTEGER\t\tNumber of data set parameters\t*\nC*\tCLEV\t\tREAL\t\tVertical level\t\t\t*\nC*\tIVCORD\t\tINTEGER \tVertical coordinate number\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPS_BVSQ\t\tREAL\t\tBrunt-Vaisala Frequency **2\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* J. Nielsen/SUNYA\t 8/90\t\t\t\t\t\t*\nC* T. Lee/GSC\t\t 8/97\tChanged default depth to RMISSD\t\t*\nC************************************************************************\n\tINCLUDE\t\t'GEMPRM.PRM'\nC*\n\tREAL\t\tdatain (*)\nC*\n\tREAL\t\tstndl (10), stndb (10), stndt (10)\nC*\n\tINCLUDE\t\t'ERMISS.FNC'\nC-----------------------------------------------------------------------------\n\tPS_BVSQ = RMISSD\nC\nC*\tGet data at this layer, unless requested otherwise.\nC\n\tdfdpth = RMISSD\n\tidfcrd = 3\n\tCALL PC_DPTH ( datain, nparm, clev, ivcord, dfdpth, idfcrd, 1,\n +\t\t \tdepth, idcord, stndl, stndb, stndt, ier )\nC\nC*\tCheck for missing data.\nC\n\tIF ( ier .ne. 0 ) RETURN\n\tIF ( ERMISS ( stndt (1) ) .or. ERMISS ( stndb (1) ) .or.\n +\t ERMISS ( stndt (2) ) .or. ERMISS ( stndb (2) ) .or.\n +\t ERMISS ( stndt (6) ) .or. ERMISS ( stndb (6) ) ) RETURN\n\tdepth = stndt (6) - stndb (6)\n\tIF ( depth .eq. 0.0 ) RETURN\nC*\n\tthtop = PR_THTA ( stndt (2), stndt (1) )\n\tthbot = PR_THTA ( stndb (2), stndb (1) )\n theav = ( thtop + thbot ) / 2.\nC\nC*\tCompute N**2.\nC\n bvfsqd = ( GRAVTY / theav ) * ( thtop - thbot ) / depth\n\tIF ( bvfsqd .lt. 0.0 ) RETURN\n\tPS_BVSQ = bvfsqd\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "7c3f453cd9b21d429336fd23701980835cad28dd", "size": 1810, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/ps/psbvsq.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/ps/psbvsq.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/ps/psbvsq.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.1666666667, "max_line_length": 78, "alphanum_fraction": 0.5099447514, "num_tokens": 684, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505376715775, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6932279514036981}} {"text": "! *******************************************************************\r\n! * *\r\n! * Function dlspx2 *\r\n! * *\r\n! *******************************************************************\r\n! Double Precision Version 1.71\r\n! Written by Gordon A. Fenton, Sept. 1989\r\n! Latest Update: May 9, 2001\r\n!\r\n! PURPOSE returns the covariance between two points in a 2-D random field\r\n! with Gaussian type covariance function (separable and mean-square\r\n! differentiable).\r\n!\r\n! This function returns the covariance between two points, separated\r\n! by lag vector {X,Y}, in a 2-D random field having separable (and mean-\r\n! square differentiable) covariance function\r\n!\r\n! B(x,y) = var * exp{ -pi*(|x|/thx)^2 } * exp{ -pi*(|y|/thy)^2 }\r\n!\r\n! If var < 0, then this function returns the variance of a local average\r\n! of the process, |var|*V(X,Y), averaged over the domain X x Y.\r\n! Thus the variance function is also separable and can be written\r\n! as the product of two one-d variance functions corresponding to the\r\n! exponential correlation function\r\n!\r\n! V(X,Y) = V(X)*V(Y)\r\n!\r\n! where individual functions are based on the 1-D analytical model\r\n!\r\n! V(X) = (1/a*a) * [pi*(|X|/thx)*erf(a) + exp(-a*a) - 1]\r\n!\r\n! where a = (|X|*sqrt(pi))/thx and erf(.) is the error function,\r\n! dthx is the directional scale of fluctuation, and var is the\r\n! point variance. The variance of a local average is given by\r\n! var*V(X,Y).\r\n!\r\n! See page 186 of \"Random Fields\" by E. Vanmarcke and G.A. Fenton's\r\n! thesis for more details.\r\n!\r\n! The parameters var, dthx, and dthy are brought into this\r\n! routine through the common block /dparam/.\r\n!\r\n! The arguments to this routine, X and Y, are the components of the lag\r\n! vector between the two points (or the dimensions of the averaging\r\n! region, if var < 0).\r\n!\r\n! The data value `eund' is designed to avoid underflow errors arising from\r\n! exp(-a) for a > eund. We quite happily accept a zero in this case. This\r\n! tends to be compiler dependent.\r\n!\r\n! REVISION HISTORY:\r\n! 1.3\teliminated unused local variables `two' and `four' (Dec 5/96)\r\n! 1.4\tadded lvarfn flag to end of /dparam/ common block. Set it to\r\n!\ttrue if the variance function is to be returned. Otherwise this\r\n!\tfunction returns the covariance. (May 31/00)\r\n! 1.5\teliminated lvarfn -- now return covariances only if var < 0 (Mar 27/01)\r\n! 1.6\tproperly handled sign on var for covariances (Apr 5/01)\r\n! 1.7\treversed default - now return covariances if var > 0. (Apr 11/01)\r\n! 1.71\trevised above documentation to reflect revision 1.7 (May 9/01)\r\n!---------------------------------------------------------------------------\r\n real*8 function dlspx2( X, Y )\r\n implicit real*8 (a-h,o-z)\r\n common/dparam/ var, pb, dthx, dthy, dthz\r\n data zero/0.d0/, one/1.d0/\r\n data rtpi/1.77245385090551588d0/, eund/300.d0/\r\n data pi/3.1415926535897932384d0/\r\n exp(s) = dexp(s)\r\n abs(s) = dabs(s)\r\n r_erf(s) = derf(s)\r\n\r\n if( var .lt. zero ) then\t\t\t! return variance function\r\n rx = abs(X)/dthx\r\n ry = abs(Y)/dthy\r\n a = rtpi*rx\r\n aa = a*a\r\n b = rtpi*ry\r\n bb = b*b\r\n!\t\t\t\t\t\tin the x direction\r\n if( X .eq. zero ) then\r\n dsepa = one\r\n elseif( aa .lt. eund ) then\r\n dsepa = (pi*rx*r_erf(a) + exp(-aa) - one)/aa\r\n else\r\n dsepa = (pi*rx - one)/aa\r\n endif\r\n!\t\t\t\t\t\tand in the y direction\r\n if( Y .eq. zero ) then\r\n dsepb = one\r\n elseif( bb .lt. eund ) then\r\n dsepb = (pi*ry*r_erf(b) + exp(-bb) - one)/bb\r\n else\r\n dsepb = (pi*ry - one)/bb\r\n endif\r\n dlspx2 = -var*dsepa*dsepb\r\n\r\n else\t\t\t\t\t! var < 0, return covariance\r\n!\t\t\t\t\t\t\tin the x direction\r\n if( dthx .eq. zero ) then\r\n if( X .eq. zero ) then\r\n dsepa = one\r\n else\r\n dsepa = zero\r\n endif\r\n else\r\n rx = X/dthx\r\n px = pi*rx*rx\r\n if( px .lt. eund ) then\r\n dsepa = exp(-px)\r\n else\r\n dsepa = zero\r\n endif\r\n endif\r\n!\t\t\t\t\t\t\tin the y direction\r\n if( dthy .eq. zero ) then\r\n if( Y .eq. zero ) then\r\n dsepb = one\r\n else\r\n dsepb = zero\r\n endif\r\n else\r\n ry = Y/dthy\r\n py = pi*ry*ry\r\n if( py .lt. eund ) then\r\n dsepb = exp(-py)\r\n else\r\n dsepb = zero\r\n endif\r\n endif\r\n dlspx2 = var*dsepa*dsepb\r\n endif\r\n\r\n return\r\n end\r\n", "meta": {"hexsha": "5c04581378f0c95146422c91bb30c01b6bc5c044", "size": 4877, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/libs/gaf95/dlspx2.f95", "max_stars_repo_name": "leemargetts/PoreFEM", "max_stars_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/libs/gaf95/dlspx2.f95", "max_issues_repo_name": "leemargetts/PoreFEM", "max_issues_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/libs/gaf95/dlspx2.f95", "max_forks_repo_name": "leemargetts/PoreFEM", "max_forks_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.3955223881, "max_line_length": 79, "alphanum_fraction": 0.5060488005, "num_tokens": 1386, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318196, "lm_q2_score": 0.7799929104825006, "lm_q1q2_score": 0.6932255649477375}} {"text": " REAL FUNCTION SBESY0 (X)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc>> 1996-03-30 SBESY0 Krogh Added external statement.\nC>> 1995-11-13 SBESY0 Krogh Changes to simplify conversion to C.\nC>> 1994-11-11 SBESY0 Krogh Declared all vars.\nC>> 1994-10-20 SBESY0 Krogh Changes to use M77CON\nC>> 1990-11-29 SBESY0 CLL\nC>> 1985-08-02 SBESY0 Lawson Initial code.\nC JULY 1977 EDITION. W. FULLERTON, C3, LOS ALAMOS SCIENTIFIC LAB.\nC C.L.LAWSON & S.CHAN, JPL, 1984 FEB ADAPTED TO JPL MATH77 LIBRARY.\nc ------------------------------------------------------------------\nc--S replaces \"?\": ?BESY0, ?BESJ0, ?BMP0, ?INITS, ?CSEVL, ?ERM1\nc ------------------------------------------------------------------\n EXTERNAL R1MACH, SBESJ0, SCSEVL\n INTEGER NTY0\n REAL X, BY0CS(19), AMPL, THETA, TWODPI, XSML,\n 1 Y, R1MACH, SCSEVL, SBESJ0\nC\nC SERIES FOR BY0 ON THE INTERVAL 0. TO 1.60000E+01\nC WITH WEIGHTED ERROR 8.14E-32\nC LOG WEIGHTED ERROR 31.09\nC SIGNIFICANT FIGURES REQUIRED 30.31\nC DECIMAL PLACES REQUIRED 31.73\nC\n SAVE NTY0, XSML\nC\n DATA BY0CS / -.1127783939286557321793980546028E-1,\n * -.1283452375604203460480884531838E+0,\n * -.1043788479979424936581762276618E+0,\n * +.2366274918396969540924159264613E-1,\n * -.2090391647700486239196223950342E-2,\n * +.1039754539390572520999246576381E-3,\n * -.3369747162423972096718775345037E-5,\n * +.7729384267670667158521367216371E-7,\n * -.1324976772664259591443476068964E-8,\n * +.1764823261540452792100389363158E-10,\n * -.1881055071580196200602823012069E-12,\n * +.1641865485366149502792237185749E-14,\n * -.1195659438604606085745991006720E-16,\n * +.7377296297440185842494112426666E-19,\n * -.3906843476710437330740906666666E-21,\n * +.1795503664436157949829120000000E-23,\n * -.7229627125448010478933333333333E-26,\n * +.2571727931635168597333333333333E-28,\n * -.8141268814163694933333333333333E-31 /\nC\n DATA TWODPI / 0.636619772367581343075535053490057E0 /\n DATA NTY0, XSML / 0, 0.E0 /\nC ------------------------------------------------------------------\n IF (NTY0 .eq. 0) then\n call SINITS (BY0CS, 19, 0.1E0*R1MACH(3), NTY0)\n XSML = SQRT (4.0E0*R1MACH(3))\n endif\nC\n IF (X .LE. 0.E0) THEN\n SBESY0 = 0.E0\n CALL SERM1 ('SBESY0',1,0,'X IS ZERO OR NEGATIVE','X',X,'.')\n ELSE IF (X .LE. 4.E0) THEN\n IF (X .LE. XSML) THEN\n Y = 0.E0\n ELSE\n Y = X * X\n END IF\n SBESY0 = TWODPI*LOG(0.5E0*X)*SBESJ0(X) + .375E0 +\n * SCSEVL (.125E0*Y-1.E0, BY0CS, NTY0)\n ELSE\n CALL SBMP0 (X, AMPL, THETA)\n SBESY0 = AMPL * SIN(THETA)\n END IF\nC\n RETURN\nC\n END\n", "meta": {"hexsha": "21e7487de90d0864794899e0d94d8f32aff304a3", "size": 3036, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/sbesy0.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/sbesy0.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/sbesy0.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.9473684211, "max_line_length": 72, "alphanum_fraction": 0.5694993412, "num_tokens": 1117, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588052782736, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6932255536100879}} {"text": " Program dsbgv_example\n\n! DSBGV Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_interfaces, Only: dsbgv\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nin = 5, nout = 6\n Character (1), Parameter :: uplo = 'U'\n! .. Local Scalars ..\n Integer :: i, info, j, ka, kb, ldab, ldbb, n\n! .. Local Arrays ..\n Real (Kind=dp), Allocatable :: ab(:, :), bb(:, :), w(:), work(:)\n Real (Kind=dp) :: dummy(1, 1)\n! .. Intrinsic Procedures ..\n Intrinsic :: max, min\n! .. Executable Statements ..\n Write (nout, *) 'DSBGV Example Program Results'\n Write (nout, *)\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n, ka, kb\n ldab = ka + 1\n ldbb = kb + 1\n Allocate (ab(ldab,n), bb(ldbb,n), w(n), work(3*n))\n\n! Read the upper or lower triangular parts of the matrices A and\n! B from data file\n\n If (uplo=='U') Then\n Read (nin, *)((ab(ka+1+i-j,j),j=i,min(n,i+ka)), i=1, n)\n Read (nin, *)((bb(kb+1+i-j,j),j=i,min(n,i+kb)), i=1, n)\n Else If (uplo=='L') Then\n Read (nin, *)((ab(1+i-j,j),j=max(1,i-ka),i), i=1, n)\n Read (nin, *)((bb(1+i-j,j),j=max(1,i-kb),i), i=1, n)\n End If\n\n! Solve the generalized symmetric band eigenvalue problem\n! A*x = lambda*B*x\n\n Call dsbgv('No vectors', uplo, n, ka, kb, ab, ldab, bb, ldbb, w, dummy, &\n 1, work, info)\n\n If (info==0) Then\n\n! Print solution\n\n Write (nout, *) 'Eigenvalues'\n Write (nout, 100) w(1:n)\n Else If (info>n .And. info<=2*n) Then\n i = info - n\n Write (nout, 110) 'The leading minor of order ', i, &\n ' of B is not positive definite'\n Else\n Write (nout, 120) 'Failure in DSBGV. INFO =', info\n End If\n\n100 Format (3X, (6F11.4))\n110 Format (1X, A, I4, A)\n120 Format (1X, A, I4)\n End Program\n", "meta": {"hexsha": "8adbbae4b5035ed436a50df0c8a3176b1c4516e8", "size": 2149, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/dsbgv_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/dsbgv_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/dsbgv_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 31.1449275362, "max_line_length": 90, "alphanum_fraction": 0.5430432759, "num_tokens": 706, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853655, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6932255535589491}} {"text": "!This module contains two types that are required for the simulation:\n!Vectors for calculating and storing objects' positions, velocities and accelerations\n!Objects (planets, stars, moons etc.), that are made up of mass and forementioned vectors. Objects are essentially used for\n!storing values.\n\nmodule types_mod\n use param_mod\n !Creation of types\n type:: vector\n real(rk)::x,y,z\n end type vector\n type:: object\n character(len=50)::description\n real(rk)::mass\n type(vector)::pos\n type(vector)::vel\n type(vector)::acc\n end type object\n\n !Operators and routine assignment for vector calculations\n interface operator(+)\n module procedure vadd\n end interface operator(+)\n interface operator(-)\n module procedure vsub\n end interface operator(-)\n interface operator(*)\n module procedure vmul\n end interface operator(*)\n interface operator(/)\n module procedure vdiv\n end interface operator(/)\ncontains\n !Simple vector subroutines and also a subroutine for calculating the length of a vector\n \n !Addition\n type(vector) function vadd(v,u)\n implicit none\n type(vector),intent(in)::v,u\n vadd%x=v%x+u%x\n vadd%y=v%y+u%y\n vadd%z=v%z+u%z\n end function vadd\n\n !Subtraction\n type(vector) function vsub(v,u)\n implicit none\n type(vector),intent(in)::v,u\n vsub%x=v%x-u%x\n vsub%y=v%y-u%y\n vsub%z=v%z-u%z\n end function vsub\n\n !Multiplication\n type(vector) function vmul(v,k)\n implicit none\n real(rk),intent(in)::k\n type(vector),intent(in)::v\n vmul%x=k*v%x\n vmul%y=k*v%y\n vmul%z=k*v%z\n end function\n\n !Division\n type(vector) function vdiv(v,k)\n implicit none\n real(rk),intent(in)::k\n type(vector),intent(in)::v\n vdiv%x=v%x/k\n vdiv%y=v%y/k\n vdiv%z=v%z/k\n end function\n\n !Vector length\n real(rk) function vectorlen(v)\n implicit none\n type(vector),intent(in)::v\n vectorlen=sqrt((v%x)**2+(v%y)**2+(v%z)**2)\n end function vectorlen\nend module types_mod\n\n", "meta": {"hexsha": "9848f4260e8639c8f36ffa6667eee2d002370187", "size": 2499, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/types_mod.f90", "max_stars_repo_name": "toicca/planetary-simulator-sc2", "max_stars_repo_head_hexsha": "f673eb0fbb49b72fdaf861782fa476b13d798aa0", "max_stars_repo_licenses": ["MIT"], "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/types_mod.f90", "max_issues_repo_name": "toicca/planetary-simulator-sc2", "max_issues_repo_head_hexsha": "f673eb0fbb49b72fdaf861782fa476b13d798aa0", "max_issues_repo_licenses": ["MIT"], "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/types_mod.f90", "max_forks_repo_name": "toicca/planetary-simulator-sc2", "max_forks_repo_head_hexsha": "f673eb0fbb49b72fdaf861782fa476b13d798aa0", "max_forks_repo_licenses": ["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.4756097561, "max_line_length": 123, "alphanum_fraction": 0.5362144858, "num_tokens": 578, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587934924569, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6932255489625223}} {"text": "! Calculate the exponential integral using the algorithm of\n! [1] Tseng, Lee, Journal of Hydrology, 205 (1998) 38-51\nmodule m_exponential_integral\n\n implicit none\n\n real, parameter :: series_laguerre = 4.0\n\ncontains\n\n ! Calculate the exponential integral E_1(x):\n !\n ! inf\n ! / -t\n ! | e\n ! E (x) = | dt -----\n ! 1 | t\n ! /\n ! x\n !\n ! Input: arg - position at which exponential integral is evaluated (arg > 0)\n ! Output: res - E_1(arg)\n pure subroutine calculateExponentialIntegral(arg, res)\n\n implicit none\n\n real, intent(in) :: arg\n real, intent(inout) :: res\n\n ! For arguments smaller than 4 the series expansion is used\n if (arg < series_laguerre) then\n res = seriesExpansion(arg)\n\n ! otherwise a Gauss-Laguerre expansion is better\n else\n res = exp(-arg)*gauss_laguerre(arg)\n endif\n\n end subroutine calculateExponentialIntegral\n\n ! Series expansion of the exponential integral\n !\n ! n_cut\n ! ----- n n\n ! \\ (-1) x\n ! E (x) = -gamma - ln(x) - ) --------\n ! 1 / n * n!\n ! -----\n ! n = 1\n !\n ! where gamma is the Euler constant.\n ! n_cut is set to 25\n ! Input: arg - argument for which the exponential integral is approximated\n ! Return: approximation by series expansion for E_1(arg)\n pure real function seriesExpansion(arg)\n\n implicit none\n\n real, intent(in) :: arg\n\n real :: res, fact ! result of the summation, 1 / n\n integer :: i ! counter variable\n\n real, parameter :: EULER_GAMMA = 0.57721566490153286060651209008241 ! Euler constant\n integer, parameter :: ITERATION = 25 ! Cutoff for series expansion\n\n ! initialize summation result\n res = 0.0\n\n ! perform the summation\n do i = ITERATION, 2, -1\n ! calculate 1/n\n fact = 1.0/i\n ! add next term of summation\n res = arg*fact*(fact - res)\n end do\n\n ! calculate the final result\n seriesExpansion = -EULER_GAMMA - log(arg) + arg*(1.0 - res)\n\n end function seriesExpansion\n\n ! The Gauss Laguerre expansion of the exponential integral can be written as\n !\n ! N\n ! E (arg) ----- a\n ! 1 \\ n\n ! ------- = ) --------\n ! -arg / x + arg\n ! e ----- n\n ! n=1\n !\n ! where the a_n and x_n are determined by least quadrature and are given in [1]\n ! Input: arg - point at which Gaussian Laguerre quadrature is calculated\n ! Return: E_1(arg) in this approximation\n pure real function gauss_laguerre(arg)\n\n implicit none\n\n real, intent(in) :: arg\n\n ! the quadrature constants a_n and x_n from [1]\n real, parameter :: a(1:15) = (/ &\n 0.2182348859400869e+00, 0.3422101779228833e+00, 0.2630275779416801e+00, &\n 0.1264258181059305e+00, 0.4020686492100091e-01, 0.8563877803611838e-02, &\n 0.1212436147214252e-02, 0.1116743923442519e-03, 0.6459926762022901e-05, &\n 0.2226316907096273e-06, 0.4227430384979365e-08, 0.3921897267041089e-10, &\n 0.1456515264073126e-12, 0.1483027051113301e-15, 0.1600594906211133e-19/)\n real, parameter :: x(1:15) = (/ &\n 0.9330781201728180e-01, 0.4926917403018839e+00, 0.1215595412070949e+01, &\n 0.2269949526203743e+01, 0.3667622721751437e+01, 0.5425336627413553e+01, &\n 0.7565916226613068e+01, 0.1012022856801911e+02, 0.1313028248217572e+02, &\n 0.1665440770832996e+02, 0.2077647889944877e+02, 0.2562389422672878e+02, &\n 0.3140751916975394e+02, 0.3853068330648601e+02, 0.4802608557268579e+02/)\n\n ! Calculate the summation\n gauss_laguerre = sum(a/(x + arg))\n\n end function gauss_laguerre\n\nend module m_exponential_integral\n", "meta": {"hexsha": "fbc62909cbe57731c4723021d01fc6c46083bbe7", "size": 4119, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "hybrid/exponential_integral.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": "hybrid/exponential_integral.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": "hybrid/exponential_integral.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.762295082, "max_line_length": 98, "alphanum_fraction": 0.560815732, "num_tokens": 1256, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.888758793492457, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6932255489625223}} {"text": "\tFUNCTION PR_DDEP ( tmpx, dwpx )\nC************************************************************************\nC* PR_DDEP\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes DPDX, the dewpoint depression, from TMPX and \t*\nC* DWPX, both of which must be in the same units (Celsius, Kelvin, or\t*\nC* Fahrenheit). The output will be calculated in these units. The \t*\nC* following equation is used:\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* DPDX = TMPX - DWPX\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PR_DDEP ( TMPX, DWPX ) \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*\tTMPX\t\tREAL \tAir temperature \t\t*\nC*\tDWPX\t\tREAL\t\tDewpoint temperature\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPR_DDEP\t\tREAL\t\tDewpoint depression\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* M. Goodman/RDS\t1/84\tOriginal source\t\t\t\t*\nC* I. Graffman/RDS\t12/87\tGEMPAK4\t\t\t\t\t*\nC* G. Huffman/GSC\t7/88\tDocumentation, variable names\t\t*\nC************************************************************************\n INCLUDE 'GEMPRM.PRM'\n INCLUDE 'ERMISS.FNC'\nC------------------------------------------------------------------------\n\tIF ( ERMISS (tmpx) .or. ERMISS (dwpx) .or. \n +\t ( dwpx .gt. tmpx ) ) THEN\n\t PR_DDEP = RMISSD\n\t ELSE\n\t PR_DDEP = tmpx - dwpx\n\tEND IF\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "7bb780e551f086af1219f0d561ee8b427e7158ad", "size": 1251, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/pr/prddep.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/prddep.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/prddep.f", "max_forks_repo_name": "oxelson/gempak", "max_forks_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 27, "max_forks_repo_forks_event_min_datetime": "2016-06-06T21:55:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T18:23:28.000Z", "avg_line_length": 32.9210526316, "max_line_length": 73, "alphanum_fraction": 0.4692246203, "num_tokens": 393, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587817066392, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6932255397696682}} {"text": "!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 1998 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Spherepack *\n! * *\n! * A Package of Fortran Subroutines and Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams and Paul Swarztrauber *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\nsubmodule(vector_synthesis_routines) vector_synthesis_gaussian_saved\n\ncontains\n\n ! Purpose:\n !\n ! subroutine vhsgs(nlat, nlon, ityp, nt, v, w, idvw, jdvw, br, bi, cr, ci, &\n ! mdab, ndab, wvhsgs, ierror)\n !\n ! subroutine vhsgs performs the vector spherical harmonic synthesis\n ! of the arrays br, bi, cr, and ci and stores the result in the\n ! arrays v and w. the synthesis is performed on an equally spaced\n ! longitude grid and a gaussian colatitude grid (measured from\n ! the north pole). v(i, j) and w(i, j) are the colatitudinal and\n ! east longitudinal components respectively, located at the i(th)\n ! colatitude gaussian point (see nlat below) and longitude\n ! phi(j) = (j-1)*2*pi/nlon. the spectral respresentation of (v, w)\n ! is given below at output parameters v, w.\n !\n ! input parameters\n !\n ! nlat the number of points in the gaussian colatitude grid on the\n ! full sphere. these lie in the interval (0, pi) and are computed\n ! in radians in theta(1) <...< theta(nlat) by subroutine\n ! compute_gaussian_latitudes_and_weights.\n ! if nlat is odd the equator will be included as the grid point\n ! theta((nlat + 1)/2). if nlat is even the equator will be\n ! excluded as a grid point and will lie half way between\n ! theta(nlat/2) and theta(nlat/2+1). nlat must be at least 3.\n ! note: on the half sphere, the number of grid points in the\n ! colatitudinal direction is nlat/2 if nlat is even or\n ! (nlat + 1)/2 if nlat is odd.\n !\n ! nlon the number of distinct londitude points. nlon determines\n ! the grid increment in longitude as 2*pi/nlon. for example\n ! nlon = 72 for a five degree grid. nlon must be greater\n ! than zero. the axisymmetric case corresponds to nlon=1.\n ! the efficiency of the computation is improved when nlon\n ! is a product of small prime numbers.\n !\n ! ityp = 0 no symmetries exist about the equator. the synthesis\n ! is performed on the entire sphere. i.e. on the\n ! arrays v(i, j), w(i, j) for i=1, ..., nlat and\n ! j=1, ..., nlon.\n !\n ! = 1 no symmetries exist about the equator. the synthesis\n ! is performed on the entire sphere. i.e. on the\n ! arrays v(i, j), w(i, j) for i=1, ..., nlat and\n ! j=1, ..., nlon. the curl of (v, w) is zero. that is, \n ! (d/dtheta (sin(theta) w) - dv/dphi)/sin(theta) = 0.\n ! the coefficients cr and ci are zero.\n !\n ! = 2 no symmetries exist about the equator. the synthesis\n ! is performed on the entire sphere. i.e. on the\n ! arrays v(i, j), w(i, j) for i=1, ..., nlat and\n ! j=1, ..., nlon. the divergence of (v, w) is zero. i.e., \n ! (d/dtheta (sin(theta) v) + dw/dphi)/sin(theta) = 0.\n ! the coefficients br and bi are zero.\n !\n ! = 3 v is symmetric and w is antisymmetric about the\n ! equator. the synthesis is performed on the northern\n ! hemisphere only. i.e., if nlat is odd the synthesis\n ! is performed on the arrays v(i, j), w(i, j) for\n ! i=1, ..., (nlat + 1)/2 and j=1, ..., nlon. if nlat is\n ! even the synthesis is performed on the the arrays\n ! v(i, j), w(i, j) for i=1, ..., nlat/2 and j=1, ..., nlon.\n !\n ! = 4 v is symmetric and w is antisymmetric about the\n ! equator. the synthesis is performed on the northern\n ! hemisphere only. i.e., if nlat is odd the synthesis\n ! is performed on the arrays v(i, j), w(i, j) for\n ! i=1, ..., (nlat + 1)/2 and j=1, ..., nlon. if nlat is\n ! even the synthesis is performed on the the arrays\n ! v(i, j), w(i, j) for i=1, ..., nlat/2 and j=1, ..., nlon.\n ! the curl of (v, w) is zero. that is, \n ! (d/dtheta (sin(theta) w) - dv/dphi)/sin(theta) = 0.\n ! the coefficients cr and ci are zero.\n !\n ! = 5 v is symmetric and w is antisymmetric about the\n ! equator. the synthesis is performed on the northern\n ! hemisphere only. i.e., if nlat is odd the synthesis\n ! is performed on the arrays v(i, j), w(i, j) for\n ! i=1, ..., (nlat + 1)/2 and j=1, ..., nlon. if nlat is\n ! even the synthesis is performed on the the arrays\n ! v(i, j), w(i, j) for i=1, ..., nlat/2 and j=1, ..., nlon.\n ! the divergence of (v, w) is zero. i.e., \n ! (d/dtheta (sin(theta) v) + dw/dphi)/sin(theta) = 0.\n ! the coefficients br and bi are zero.\n !\n ! = 6 v is antisymmetric and w is symmetric about the\n ! equator. the synthesis is performed on the northern\n ! hemisphere only. i.e., if nlat is odd the synthesis\n ! is performed on the arrays v(i, j), w(i, j) for\n ! i=1, ..., (nlat + 1)/2 and j=1, ..., nlon. if nlat is\n ! even the synthesis is performed on the the arrays\n ! v(i, j), w(i, j) for i=1, ..., nlat/2 and j=1, ..., nlon.\n !\n ! = 7 v is antisymmetric and w is symmetric about the\n ! equator. the synthesis is performed on the northern\n ! hemisphere only. i.e., if nlat is odd the synthesis\n ! is performed on the arrays v(i, j), w(i, j) for\n ! i=1, ..., (nlat + 1)/2 and j=1, ..., nlon. if nlat is\n ! even the synthesis is performed on the the arrays\n ! v(i, j), w(i, j) for i=1, ..., nlat/2 and j=1, ..., nlon.\n ! the curl of (v, w) is zero. that is, \n ! (d/dtheta (sin(theta) w) - dv/dphi)/sin(theta) = 0.\n ! the coefficients cr and ci are zero.\n !\n ! = 8 v is antisymmetric and w is symmetric about the\n ! equator. the synthesis is performed on the northern\n ! hemisphere only. i.e., if nlat is odd the synthesis\n ! is performed on the arrays v(i, j), w(i, j) for\n ! i=1, ..., (nlat + 1)/2 and j=1, ..., nlon. if nlat is\n ! even the synthesis is performed on the the arrays\n ! v(i, j), w(i, j) for i=1, ..., nlat/2 and j=1, ..., nlon.\n ! the divergence of (v, w) is zero. i.e., \n ! (d/dtheta (sin(theta) v) + dw/dphi)/sin(theta) = 0.\n ! the coefficients br and bi are zero.\n !\n !\n ! nt the number of syntheses. in the program that calls vhsgs, \n ! the arrays v, w, br, bi, cr, and ci can be three dimensional\n ! in which case multiple syntheses will be performed.\n ! the third index is the synthesis index which assumes the\n ! values k=1, ..., nt. for a single synthesis set nt=1. the\n ! discription of the remaining parameters is simplified\n ! by assuming that nt=1 or that all the arrays are two\n ! dimensional.\n !\n ! idvw the first dimension of the arrays v, w as it appears in\n ! the program that calls vhags. if ityp <= 2 then idvw\n ! must be at least nlat. if ityp > 2 and nlat is\n ! even then idvw must be at least nlat/2. if ityp > 2\n ! and nlat is odd then idvw must be at least (nlat + 1)/2.\n !\n ! jdvw the second dimension of the arrays v, w as it appears in\n ! the program that calls vhsgs. jdvw must be at least nlon.\n !\n ! br, bi two or three dimensional arrays (see input parameter nt)\n ! cr, ci that contain the vector spherical harmonic coefficients\n ! in the spectral representation of v(i, j) and w(i, j) given\n ! below at the discription of output parameters v and w.\n !\n ! mdab the first dimension of the arrays br, bi, cr, and ci as it\n ! appears in the program that calls vhsgs. mdab must be at\n ! least min(nlat, nlon/2) if nlon is even or at least\n ! min(nlat, (nlon + 1)/2) if nlon is odd.\n !\n ! ndab the second dimension of the arrays br, bi, cr, and ci as it\n ! appears in the program that calls vhsgs. ndab must be at\n ! least nlat.\n !\n ! wvhsgs an array which must be initialized by subroutine vhsgsi.\n ! once initialized, wvhsgs can be used repeatedly by vhsgs\n ! as long as nlon and nlat remain unchanged. wvhsgs must\n ! not be altered between calls of vhsgs.\n !\n ! lvhsgs the dimension of the array wvhsgs as it appears in the\n ! program that calls vhsgs. define\n !\n ! l1 = min(nlat, nlon/2) if nlon is even or\n ! l1 = min(nlat, (nlon + 1)/2) if nlon is odd\n !\n ! and\n !\n ! l2 = nlat/2 if nlat is even or\n ! l2 = (nlat + 1)/2 if nlat is odd\n !\n ! then lvhsgs must be at least\n !\n ! l1*l2*(2*nlat-l1+1)+nlon+15+2*nlat\n !\n ! output parameters\n !\n ! v, w two or three dimensional arrays (see input parameter nt)\n ! in which the synthesis is stored. v is the colatitudinal\n ! component and w is the east longitudinal component.\n ! v(i, j), w(i, j) contain the components at the guassian colatitude\n ! point theta(i) and longitude phi(j) = (j-1)*2*pi/nlon.\n ! the index ranges are defined above at the input parameter\n ! ityp. v and w are computed from the formulas given below.\n !\n !\n ! define\n !\n ! 1. theta is colatitude and phi is east longitude\n !\n ! 2. the normalized associated legendre funnctions\n !\n ! pbar(m, n, theta) = sqrt((2*n+1)*factorial(n-m)\n ! /(2*factorial(n+m)))*sin(theta)**m/(2**n*\n ! factorial(n)) times the (n+m)th derivative\n ! of (x**2-1)**n with respect to x=cos(theta)\n !\n ! 3. vbar(m, n, theta) = the derivative of pbar(m, n, theta) with\n ! respect to theta divided by the square\n ! root of n(n+1).\n !\n ! vbar(m, n, theta) is more easily computed in the form\n !\n ! vbar(m, n, theta) = (sqrt((n+m)*(n-m+1))*pbar(m-1, n, theta)\n ! -sqrt((n-m)*(n+m+1))*pbar(m+1, n, theta))/(2*sqrt(n*(n+1)))\n !\n ! 4. wbar(m, n, theta) = m/(sin(theta))*pbar(m, n, theta) divided\n ! by the square root of n(n+1).\n !\n ! wbar(m, n, theta) is more easily computed in the form\n !\n ! wbar(m, n, theta) = sqrt((2n+1)/(2n-1))*(sqrt((n+m)*(n+m-1))\n ! *pbar(m-1, n-1, theta)+sqrt((n-m)*(n-m-1))*pbar(m+1, n-1, theta))\n ! /(2*sqrt(n*(n+1)))\n !\n !\n ! the colatitudnal dependence of the normalized surface vector\n ! spherical harmonics are defined by\n !\n ! 5. bbar(m, n, theta) = (vbar(m, n, theta), i*wbar(m, n, theta))\n !\n ! 6. cbar(m, n, theta) = (i*wbar(m, n, theta), -vbar(m, n, theta))\n !\n !\n ! the coordinate to index mappings\n !\n ! 7. theta(i) = i(th) gaussian grid point and phi(j) = (j-1)*2*pi/nlon\n !\n !\n ! the maximum (plus one) longitudinal wave number\n !\n ! 8. mmax = min(nlat, nlon/2) if nlon is even or\n ! mmax = min(nlat, (nlon + 1)/2) if nlon is odd.\n !\n ! if we further define the output vector as\n !\n ! 9. h(i, j) = (v(i, j), w(i, j))\n !\n ! and the complex coefficients\n !\n ! 10. b(m, n) = cmplx(br(m+1, n+1), bi(m+1, n+1))\n !\n ! 11. c(m, n) = cmplx(cr(m+1, n+1), ci(m+1, n+1))\n !\n !\n ! then for i=1, ..., nlat and j=1, ..., nlon\n !\n ! the expansion for real h(i, j) takes the form\n !\n ! h(i, j) = the sum from n=1 to n=nlat-1 of the real part of\n !\n ! .5*(b(0, n)*bbar(0, n, theta(i))+c(0, n)*cbar(0, n, theta(i)))\n !\n ! plus the sum from m=1 to m=mmax-1 of the sum from n=m to\n ! n=nlat-1 of the real part of\n !\n ! b(m, n)*bbar(m, n, theta(i))*exp(i*m*phi(j))\n ! +c(m, n)*cbar(m, n, theta(i))*exp(i*m*phi(j))\n !\n ! *************************************************************\n !\n ! in terms of real variables this expansion takes the form\n !\n ! for i=1, ..., nlat and j=1, ..., nlon\n !\n ! v(i, j) = the sum from n=1 to n=nlat-1 of\n !\n ! .5*br(1, n+1)*vbar(0, n, theta(i))\n !\n ! plus the sum from m=1 to m=mmax-1 of the sum from n=m to\n ! n=nlat-1 of the real part of\n !\n ! (br(m+1, n+1)*vbar(m, n, theta(i))-ci(m+1, n+1)*wbar(m, n, theta(i)))\n ! *cos(m*phi(j))\n ! -(bi(m+1, n+1)*vbar(m, n, theta(i))+cr(m+1, n+1)*wbar(m, n, theta(i)))\n ! *sin(m*phi(j))\n !\n ! and for i=1, ..., nlat and j=1, ..., nlon\n !\n ! w(i, j) = the sum from n=1 to n=nlat-1 of\n !\n ! -.5*cr(1, n+1)*vbar(0, n, theta(i))\n !\n ! plus the sum from m=1 to m=mmax-1 of the sum from n=m to\n ! n=nlat-1 of the real part of\n !\n ! -(cr(m+1, n+1)*vbar(m, n, theta(i))+bi(m+1, n+1)*wbar(m, n, theta(i)))\n ! *cos(m*phi(j))\n ! +(ci(m+1, n+1)*vbar(m, n, theta(i))-br(m+1, n+1)*wbar(m, n, theta(i)))\n ! *sin(m*phi(j))\n !\n !\n ! br(m+1, nlat), bi(m+1, nlat), cr(m+1, nlat), and ci(m+1, nlat) are\n ! assumed zero for m even.\n !\n !\n ! ierror = 0 no errors\n ! = 1 error in the specification of nlat\n ! = 2 error in the specification of nlon\n ! = 3 error in the specification of ityp\n ! = 4 error in the specification of nt\n ! = 5 error in the specification of idvw\n ! = 6 error in the specification of jdvw\n ! = 7 error in the specification of mdab\n ! = 8 error in the specification of ndab\n ! = 9 error in the specification of lvhsgs\n !\n module subroutine vhsgs(nlat, nlon, ityp, nt, v, w, idvw, jdvw, br, bi, cr, ci, &\n mdab, ndab, wvhsgs, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n integer(ip), intent(in) :: ityp\n integer(ip), intent(in) :: nt\n real(wp), intent(out) :: v(idvw, jdvw, nt)\n real(wp), intent(out) :: w(idvw, jdvw, nt)\n integer(ip), intent(in) :: idvw\n integer(ip), intent(in) :: jdvw\n real(wp), intent(in) :: br(mdab, ndab, nt)\n real(wp), intent(in) :: bi(mdab, ndab, nt)\n real(wp), intent(in) :: cr(mdab, ndab, nt)\n real(wp), intent(in) :: ci(mdab, ndab, nt)\n integer(ip), intent(in) :: mdab\n integer(ip), intent(in) :: ndab\n real(wp), intent(in) :: wvhsgs(:)\n integer(ip), intent(out) :: ierror\n\n ! Local variables\n integer(ip) :: idv, idz, imid, ist, lnl, lzimn, mmax\n integer(ip) :: lwork, workspace_indices(7)\n\n associate (lvhsgs => size(wvhsgs))\n\n imid = (nlat + 1)/2\n mmax = min(nlat, (nlon + 1)/2)\n idz = (mmax*(2*nlat-mmax+1))/2\n lzimn = idz*imid\n\n ! Check calling arguments\n if (nlat < 3) then\n ierror = 1\n else if (nlon < 1) then\n ierror = 2\n else if (ityp < 0 .or. ityp > 8) then\n ierror = 3\n else if (nt < 0) then\n ierror = 4\n else if ( &\n (ityp <= 2 .and. idvw < nlat) &\n .or. &\n (ityp > 2 .and. idvw < imid)) then\n ierror = 5\n else if (jdvw < nlon) then\n ierror = 6\n else if (mdab < mmax) then\n ierror = 7\n else if (ndab < nlat) then\n ierror = 8\n else if (lvhsgs < 2*lzimn+nlon+15) then\n ierror = 9\n else\n ierror = 0\n end if\n\n ! Check error flag\n if (ierror /= 0) return\n\n ! Set required workspace size\n select case (ityp)\n case(0:2)\n ist = imid\n idv = nlat\n case default\n ist = 0\n idv = imid\n end select\n\n lnl = nt*idv*nlon\n lwork = (2 * lnl) + (idv * nlon)\n\n block\n real(wp) :: work(lwork)\n\n ! Compute workspace indices\n workspace_indices = get_vhsgs_workspace_indices(nlat, imid, ist, lnl)\n\n associate (&\n jw1 => workspace_indices(1), &\n jw2 => workspace_indices(2), &\n jw3 => workspace_indices(3), &\n iw1 => workspace_indices(4), &\n iw2 => workspace_indices(5), &\n iw3 => workspace_indices(6), &\n iw4 => workspace_indices(7) &\n )\n call vhsgs_lower_utility_routine(nlat, nlon, ityp, nt, imid, idvw, &\n jdvw, v, w, mdab, ndab, br, bi, cr, ci, idv, work, work(iw1:), &\n work(iw2:), work(iw3:), work(iw4:), idz, wvhsgs(jw1:), &\n wvhsgs(jw2:), wvhsgs(jw3:))\n end associate\n end block\n end associate\n\n end subroutine vhsgs\n\n ! Purpose:\n !\n ! Computes the gaussian points theta, gauss\n ! weights wts, and the components vb and wb of the vector\n ! harmonics.\n !\n ! set imid = (nlat + 1)/2 and lmn=(nlat*(nlat + 1))/2 then\n ! wvhsgs must have 2*(imid*lmn+nlat)+nlon+15 locations\n !\n ! real array dwork must have\n ! 3*nlat*(nlat + 1)+5*nlat+1 = nlat*(3*nlat+8)+1\n ! locations which is determined by the size of dthet, \n ! dwts, dwork, and dpbar in vhsgs_lower_utility_routine\n !\n ! subroutine vhsgsi(nlat, nlon, wvhsgs, ierror)\n !\n ! subroutine vhsgsi initializes the array wvhsgs which can then be\n ! used repeatedly by subroutine vhsgs until nlat or nlon is changed.\n !\n ! input parameters\n !\n ! nlat the number of points in the gaussian colatitude grid on the\n ! full sphere. these lie in the interval (0, pi) and are computed\n ! in radians in theta(1) <...< theta(nlat) by subroutine compute_gaussian_latitudes_and_weights.\n ! if nlat is odd the equator will be included as the grid point\n ! theta((nlat + 1)/2). if nlat is even the equator will be\n ! excluded as a grid point and will lie half way between\n ! theta(nlat/2) and theta(nlat/2+1). nlat must be at least 3.\n ! note: on the half sphere, the number of grid points in the\n ! colatitudinal direction is nlat/2 if nlat is even or\n ! (nlat + 1)/2 if nlat is odd.\n !\n ! nlon the number of distinct londitude points. nlon determines\n ! the grid increment in longitude as 2*pi/nlon. for example\n ! nlon = 72 for a five degree grid. nlon must be greater\n ! than zero. the axisymmetric case corresponds to nlon=1.\n ! the efficiency of the computation is improved when nlon\n ! is a product of small prime numbers.\n !\n ! lvhsgs the dimension of the array wvhsgs as it appears in the\n ! program that calls vhsgs. define\n !\n ! l1 = min(nlat, nlon/2) if nlon is even or\n ! l1 = min(nlat, (nlon + 1)/2) if nlon is odd\n !\n ! and\n !\n ! l2 = nlat/2 if nlat is even or\n ! l2 = (nlat + 1)/2 if nlat is odd\n !\n ! then lvhsgs must be at least\n !\n ! l1*l2*(2*nlat-l1+1)+nlon+15+2*nlat\n !\n ! output parameters\n !\n ! wvhsgs an array which is initialized for use by subroutine vhsgs.\n ! once initialized, wvhsgs can be used repeatedly by vhsgs\n ! as long as nlat and nlon remain unchanged. wvhsgs must not\n ! be altered between calls of vhsgs.\n !\n !\n ! ierror = 0 no errors\n ! = 1 error in the specification of nlat\n ! = 2 error in the specification of nlon\n ! = 3 error in the specification of lvhsgs\n !\n module subroutine vhsgsi(nlat, nlon, wvhsgs, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n real(wp), intent(out) :: wvhsgs(:)\n integer(ip), intent(out) :: ierror\n\n ! Local variables\n integer(ip) :: imid, lmn, ldwork\n type(SpherepackUtility) :: util\n\n associate (lvhsgs => size(wvhsgs))\n\n imid = (nlat + 1)/2\n lmn = (nlat*(nlat + 1))/2\n\n ! Check calling arguments\n if (nlat < 3) then\n ierror = 1\n else if (nlon < 1) then\n ierror = 2\n else if (lvhsgs < 2*(imid*lmn) + nlon + 15) then\n ierror = 3\n else\n ierror = 0\n end if\n\n ! Check error flag\n if (ierror /= 0) return\n\n ! Set required workspace size\n ldwork = (nlat*3*(nlat+3)+2)/2\n\n block\n integer(ip) :: jw1, jw2, jw3\n integer(ip) :: iw1, iw2, iw3, iw4\n real(wp) :: dwork(ldwork)\n\n ! Set saved workspace pointer indices\n jw1 = 1\n jw2 = jw1+imid*lmn\n jw3 = jw2+imid*lmn\n\n ! Set unsaved workspace pointer indices\n iw1 = 1\n iw2 = iw1+nlat\n iw3 = iw2+nlat\n iw4 = iw3+3*imid*nlat\n\n call vhgsi_lower_utility_routine(nlat, imid, wvhsgs(jw1:), &\n wvhsgs(jw2:), dwork(iw1:), dwork(iw2:), dwork(iw3:), dwork(iw4:))\n\n call util%hfft%initialize(nlon, wvhsgs(jw3:))\n end block\n end associate\n\n end subroutine vhsgsi\n\n pure function get_vhsgs_workspace_indices(nlat, imid, ist, lnl) &\n result (return_value)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: imid\n integer(ip), intent(in) :: ist\n integer(ip), intent(in) :: lnl\n integer(ip) :: return_value(7)\n\n ! Local variables\n integer(ip) :: lmn\n\n associate (i => return_value)\n\n ! set wvhsgs pointers\n lmn = nlat*(nlat + 1)/2\n i(1) = 1\n i(2) = i(1)+imid*lmn\n i(3) = i(2)+imid*lmn\n\n ! set work pointers\n i(4) = ist+1\n i(5) = lnl+1\n i(6) = i(5)+ist\n i(7) = i(5)+lnl\n end associate\n\n end function get_vhsgs_workspace_indices\n\n subroutine vhsgs_lower_utility_routine(nlat, nlon, ityp, nt, imid, idvw, jdvw, v, w, mdab, &\n ndab, br, bi, cr, ci, idv, ve, vo, we, wo, work, idz, vb, wb, wrfft)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n integer(ip), intent(in) :: ityp\n integer(ip), intent(in) :: nt\n integer(ip), intent(in) :: imid\n integer(ip), intent(in) :: idvw\n integer(ip), intent(in) :: jdvw\n real(wp), intent(out) :: v(idvw, jdvw, nt)\n real(wp), intent(out) :: w(idvw, jdvw, nt)\n integer(ip), intent(in) :: mdab\n integer(ip), intent(in) :: ndab\n real(wp), intent(in) :: br(mdab, ndab, nt)\n real(wp), intent(in) :: bi(mdab, ndab, nt)\n real(wp), intent(in) :: cr(mdab, ndab, nt)\n real(wp), intent(in) :: ci(mdab, ndab, nt)\n integer(ip), intent(in) :: idv\n real(wp), intent(out) :: ve(idv, nlon, nt)\n real(wp), intent(out) :: vo(idv, nlon, nt)\n real(wp), intent(out) :: we(idv, nlon, nt)\n real(wp), intent(out) :: wo(idv, nlon, nt)\n real(wp), intent(out) :: work(*)\n integer(ip), intent(in) :: idz\n real(wp), intent(in) :: vb(imid, *)\n real(wp), intent(in) :: wb(imid, *)\n real(wp), intent(in) :: wrfft(*)\n\n ! Local variables\n integer(ip) :: i, imm1, k, m, mb, mmax\n integer(ip) :: mn, mp1, mp2, odd_stride, even_stride, np1\n type(VectorSynthesisUtility) :: util\n\n call util%synthesis_setup(even_stride, imid, imm1, mmax, nlat, &\n odd_stride, ve, vo, we, wo)\n\n vector_symmetry_cases: select case (ityp)\n case (0)\n ! case ityp=0 no symmetries\n !\n ! case m = 0\n !\n do k=1, nt\n do np1=2, even_stride, 2\n do i=1, imid\n ve(i, 1, k)=ve(i, 1, k)+br(1, np1, k)*vb(i, np1)\n we(i, 1, k)=we(i, 1, k)-cr(1, np1, k)*vb(i, np1)\n end do\n end do\n end do\n\n do k=1, nt\n do np1=3, odd_stride, 2\n do i=1, imm1\n vo(i, 1, k)=vo(i, 1, k)+br(1, np1, k)*vb(i, np1)\n wo(i, 1, k)=wo(i, 1, k)-cr(1, np1, k)*vb(i, np1)\n end do\n end do\n end do\n\n ! case m = 1 through nlat-1\n if (2 <= mmax) then\n do mp1=2, mmax\n m = mp1-1\n mb = m * (nlat-1) - (m * (m - 1))/2\n mp2 = mp1+1\n if (mp1 <= odd_stride) then\n do k=1, nt\n do np1=mp1, odd_stride, 2\n mn = mb+np1\n do i=1, imm1\n vo(i, 2*mp1-2, k) = vo(i, 2*mp1-2, k)+br(mp1, np1, k)*vb(i, mn)\n ve(i, 2*mp1-2, k) = ve(i, 2*mp1-2, k)-ci(mp1, np1, k)*wb(i, mn)\n vo(i, 2*mp1-1, k) = vo(i, 2*mp1-1, k)+bi(mp1, np1, k)*vb(i, mn)\n ve(i, 2*mp1-1, k) = ve(i, 2*mp1-1, k)+cr(mp1, np1, k)*wb(i, mn)\n wo(i, 2*mp1-2, k) = wo(i, 2*mp1-2, k)-cr(mp1, np1, k)*vb(i, mn)\n we(i, 2*mp1-2, k) = we(i, 2*mp1-2, k)-bi(mp1, np1, k)*wb(i, mn)\n wo(i, 2*mp1-1, k) = wo(i, 2*mp1-1, k)-ci(mp1, np1, k)*vb(i, mn)\n we(i, 2*mp1-1, k) = we(i, 2*mp1-1, k)+br(mp1, np1, k)*wb(i, mn)\n end do\n\n if (mod(nlat, 2) /= 0) then\n ve(imid, 2*mp1-2, k) = ve(imid, 2*mp1-2, k) &\n -ci(mp1, np1, k)*wb(imid, mn)\n ve(imid, 2*mp1-1, k) = ve(imid, 2*mp1-1, k) &\n +cr(mp1, np1, k)*wb(imid, mn)\n we(imid, 2*mp1-2, k) = we(imid, 2*mp1-2, k) &\n -bi(mp1, np1, k)*wb(imid, mn)\n we(imid, 2*mp1-1, k) = we(imid, 2*mp1-1, k) &\n +br(mp1, np1, k)*wb(imid, mn)\n end if\n end do\n end do\n end if\n\n if (mp2 <= even_stride) then\n do k=1, nt\n do np1=mp2, even_stride, 2\n mn = mb+np1\n do i=1, imm1\n ve(i, 2*mp1-2, k) = ve(i, 2*mp1-2, k)+br(mp1, np1, k)*vb(i, mn)\n vo(i, 2*mp1-2, k) = vo(i, 2*mp1-2, k)-ci(mp1, np1, k)*wb(i, mn)\n ve(i, 2*mp1-1, k) = ve(i, 2*mp1-1, k)+bi(mp1, np1, k)*vb(i, mn)\n vo(i, 2*mp1-1, k) = vo(i, 2*mp1-1, k)+cr(mp1, np1, k)*wb(i, mn)\n we(i, 2*mp1-2, k) = we(i, 2*mp1-2, k)-cr(mp1, np1, k)*vb(i, mn)\n wo(i, 2*mp1-2, k) = wo(i, 2*mp1-2, k)-bi(mp1, np1, k)*wb(i, mn)\n we(i, 2*mp1-1, k) = we(i, 2*mp1-1, k)-ci(mp1, np1, k)*vb(i, mn)\n wo(i, 2*mp1-1, k) = wo(i, 2*mp1-1, k)+br(mp1, np1, k)*wb(i, mn)\n end do\n if (mod(nlat, 2) /= 0) then\n ve(imid, 2*mp1-2, k) = ve(imid, 2*mp1-2, k) &\n +br(mp1, np1, k)*vb(imid, mn)\n ve(imid, 2*mp1-1, k) = ve(imid, 2*mp1-1, k) &\n +bi(mp1, np1, k)*vb(imid, mn)\n we(imid, 2*mp1-2, k) = we(imid, 2*mp1-2, k) &\n -cr(mp1, np1, k)*vb(imid, mn)\n we(imid, 2*mp1-1, k) = we(imid, 2*mp1-1, k) &\n -ci(mp1, np1, k)*vb(imid, mn)\n end if\n end do\n end do\n end if\n end do\n end if\n case (1)\n !\n ! case ityp=1 no symmetries, cr and ci equal zero\n !\n ! case m = 0\n !\n do k=1, nt\n do np1=2, even_stride, 2\n do i=1, imid\n ve(i, 1, k)=ve(i, 1, k)+br(1, np1, k)*vb(i, np1)\n end do\n end do\n end do\n\n do k=1, nt\n do np1=3, odd_stride, 2\n do i=1, imm1\n vo(i, 1, k)=vo(i, 1, k)+br(1, np1, k)*vb(i, np1)\n end do\n end do\n end do\n !\n ! case m = 1 through nlat-1\n !\n if (mmax < 2) exit vector_symmetry_cases\n do mp1=2, mmax\n m = mp1-1\n ! mb = m*(nlat-1)-(m*(m-1))/2\n mb = m*nlat-(m*(m+1))/2\n mp2 = mp1+1\n if (mp1 <= odd_stride) then\n do k=1, nt\n do np1=mp1, odd_stride, 2\n mn = mb+np1\n do i=1, imm1\n vo(i, 2*mp1-2, k) = vo(i, 2*mp1-2, k)+br(mp1, np1, k)*vb(i, mn)\n vo(i, 2*mp1-1, k) = vo(i, 2*mp1-1, k)+bi(mp1, np1, k)*vb(i, mn)\n we(i, 2*mp1-2, k) = we(i, 2*mp1-2, k)-bi(mp1, np1, k)*wb(i, mn)\n we(i, 2*mp1-1, k) = we(i, 2*mp1-1, k)+br(mp1, np1, k)*wb(i, mn)\n end do\n if (mod(nlat, 2) /= 0) then\n we(imid, 2*mp1-2, k) = we(imid, 2*mp1-2, k) &\n -bi(mp1, np1, k)*wb(imid, mn)\n we(imid, 2*mp1-1, k) = we(imid, 2*mp1-1, k) &\n +br(mp1, np1, k)*wb(imid, mn)\n end if\n end do\n end do\n end if\n\n if (mp2 <= even_stride) then\n do k=1, nt\n do np1=mp2, even_stride, 2\n mn = mb+np1\n do i=1, imm1\n ve(i, 2*mp1-2, k) = ve(i, 2*mp1-2, k)+br(mp1, np1, k)*vb(i, mn)\n ve(i, 2*mp1-1, k) = ve(i, 2*mp1-1, k)+bi(mp1, np1, k)*vb(i, mn)\n wo(i, 2*mp1-2, k) = wo(i, 2*mp1-2, k)-bi(mp1, np1, k)*wb(i, mn)\n wo(i, 2*mp1-1, k) = wo(i, 2*mp1-1, k)+br(mp1, np1, k)*wb(i, mn)\n end do\n if (mod(nlat, 2) /= 0) then\n ve(imid, 2*mp1-2, k) = ve(imid, 2*mp1-2, k) &\n +br(mp1, np1, k)*vb(imid, mn)\n ve(imid, 2*mp1-1, k) = ve(imid, 2*mp1-1, k) &\n +bi(mp1, np1, k)*vb(imid, mn)\n end if\n end do\n end do\n end if\n end do\n case (2)\n !\n ! case ityp=2 no symmetries, br and bi are equal to zero\n !\n ! case m = 0\n !\n do k=1, nt\n do np1=2, even_stride, 2\n do i=1, imid\n we(i, 1, k)=we(i, 1, k)-cr(1, np1, k)*vb(i, np1)\n end do\n end do\n end do\n\n do k=1, nt\n do np1=3, odd_stride, 2\n do i=1, imm1\n wo(i, 1, k)=wo(i, 1, k)-cr(1, np1, k)*vb(i, np1)\n end do\n end do\n end do\n !\n ! case m = 1 through nlat-1\n !\n if (mmax < 2) exit vector_symmetry_cases\n\n do mp1=2, mmax\n m = mp1-1\n mb = m*nlat-(m*(m+1))/2\n mp2 = mp1+1\n\n if (mp1 <= odd_stride) then\n do k=1, nt\n do np1=mp1, odd_stride, 2\n mn = mb+np1\n do i=1, imm1\n ve(i, 2*mp1-2, k) = ve(i, 2*mp1-2, k)-ci(mp1, np1, k)*wb(i, mn)\n ve(i, 2*mp1-1, k) = ve(i, 2*mp1-1, k)+cr(mp1, np1, k)*wb(i, mn)\n wo(i, 2*mp1-2, k) = wo(i, 2*mp1-2, k)-cr(mp1, np1, k)*vb(i, mn)\n wo(i, 2*mp1-1, k) = wo(i, 2*mp1-1, k)-ci(mp1, np1, k)*vb(i, mn)\n end do\n if (mod(nlat, 2) /= 0) then\n ve(imid, 2*mp1-2, k) = ve(imid, 2*mp1-2, k) &\n -ci(mp1, np1, k)*wb(imid, mn)\n ve(imid, 2*mp1-1, k) = ve(imid, 2*mp1-1, k) &\n +cr(mp1, np1, k)*wb(imid, mn)\n end if\n end do\n end do\n end if\n\n if (mp2 <= even_stride) then\n do k=1, nt\n do np1=mp2, even_stride, 2\n mn = mb+np1\n do i=1, imm1\n vo(i, 2*mp1-2, k) = vo(i, 2*mp1-2, k)-ci(mp1, np1, k)*wb(i, mn)\n vo(i, 2*mp1-1, k) = vo(i, 2*mp1-1, k)+cr(mp1, np1, k)*wb(i, mn)\n we(i, 2*mp1-2, k) = we(i, 2*mp1-2, k)-cr(mp1, np1, k)*vb(i, mn)\n we(i, 2*mp1-1, k) = we(i, 2*mp1-1, k)-ci(mp1, np1, k)*vb(i, mn)\n end do\n if (mod(nlat, 2) /= 0) then\n we(imid, 2*mp1-2, k) = we(imid, 2*mp1-2, k) &\n -cr(mp1, np1, k)*vb(imid, mn)\n we(imid, 2*mp1-1, k) = we(imid, 2*mp1-1, k) &\n -ci(mp1, np1, k)*vb(imid, mn)\n end if\n end do\n end do\n end if\n end do\n case (3)\n !\n ! case ityp=3 v even, w odd\n !\n ! case m = 0\n !\n do k=1, nt\n do np1=2, even_stride, 2\n do i=1, imid\n ve(i, 1, k)=ve(i, 1, k)+br(1, np1, k)*vb(i, np1)\n end do\n end do\n end do\n\n do k=1, nt\n do np1=3, odd_stride, 2\n do i=1, imm1\n wo(i, 1, k)=wo(i, 1, k)-cr(1, np1, k)*vb(i, np1)\n end do\n end do\n end do\n !\n ! case m = 1 through nlat-1\n !\n if (mmax < 2) exit vector_symmetry_cases\n\n do mp1=2, mmax\n m = mp1-1\n mb = m*nlat-(m*(m+1))/2\n mp2 = mp1+1\n if (mp1 <= odd_stride) then\n do k=1, nt\n do np1=mp1, odd_stride, 2\n mn = mb+np1\n do i=1, imm1\n ve(i, 2*mp1-2, k) = ve(i, 2*mp1-2, k)-ci(mp1, np1, k)*wb(i, mn)\n ve(i, 2*mp1-1, k) = ve(i, 2*mp1-1, k)+cr(mp1, np1, k)*wb(i, mn)\n wo(i, 2*mp1-2, k) = wo(i, 2*mp1-2, k)-cr(mp1, np1, k)*vb(i, mn)\n wo(i, 2*mp1-1, k) = wo(i, 2*mp1-1, k)-ci(mp1, np1, k)*vb(i, mn)\n end do\n if (mod(nlat, 2) /= 0) then\n ve(imid, 2*mp1-2, k) = ve(imid, 2*mp1-2, k) &\n -ci(mp1, np1, k)*wb(imid, mn)\n ve(imid, 2*mp1-1, k) = ve(imid, 2*mp1-1, k) &\n +cr(mp1, np1, k)*wb(imid, mn)\n end if\n end do\n end do\n end if\n\n if (mp2 <= even_stride) then\n do k=1, nt\n do np1=mp2, even_stride, 2\n mn = mb+np1\n do i=1, imm1\n ve(i, 2*mp1-2, k) = ve(i, 2*mp1-2, k)+br(mp1, np1, k)*vb(i, mn)\n ve(i, 2*mp1-1, k) = ve(i, 2*mp1-1, k)+bi(mp1, np1, k)*vb(i, mn)\n wo(i, 2*mp1-2, k) = wo(i, 2*mp1-2, k)-bi(mp1, np1, k)*wb(i, mn)\n wo(i, 2*mp1-1, k) = wo(i, 2*mp1-1, k)+br(mp1, np1, k)*wb(i, mn)\n end do\n if (mod(nlat, 2) /= 0) then\n ve(imid, 2*mp1-2, k) = ve(imid, 2*mp1-2, k) &\n +br(mp1, np1, k)*vb(imid, mn)\n ve(imid, 2*mp1-1, k) = ve(imid, 2*mp1-1, k) &\n +bi(mp1, np1, k)*vb(imid, mn)\n end if\n end do\n end do\n end if\n end do\n case (4)\n !\n ! case ityp=4 v even, w odd, and both cr and ci equal zero\n !\n ! case m = 0\n !\n do k=1, nt\n do np1=2, even_stride, 2\n do i=1, imid\n ve(i, 1, k)=ve(i, 1, k)+br(1, np1, k)*vb(i, np1)\n end do\n end do\n end do\n !\n ! case m = 1 through nlat-1\n !\n if (mmax < 2) exit vector_symmetry_cases\n\n do mp1=2, mmax\n m = mp1-1\n mb = m*nlat-(m*(m+1))/2\n mp2 = mp1+1\n\n if (mp2 <= even_stride) then\n do k=1, nt\n do np1=mp2, even_stride, 2\n mn = mb+np1\n do i=1, imm1\n ve(i, 2*mp1-2, k) = ve(i, 2*mp1-2, k)+br(mp1, np1, k)*vb(i, mn)\n ve(i, 2*mp1-1, k) = ve(i, 2*mp1-1, k)+bi(mp1, np1, k)*vb(i, mn)\n wo(i, 2*mp1-2, k) = wo(i, 2*mp1-2, k)-bi(mp1, np1, k)*wb(i, mn)\n wo(i, 2*mp1-1, k) = wo(i, 2*mp1-1, k)+br(mp1, np1, k)*wb(i, mn)\n end do\n if (mod(nlat, 2) /= 0) then\n ve(imid, 2*mp1-2, k) = ve(imid, 2*mp1-2, k) &\n +br(mp1, np1, k)*vb(imid, mn)\n ve(imid, 2*mp1-1, k) = ve(imid, 2*mp1-1, k) &\n +bi(mp1, np1, k)*vb(imid, mn)\n end if\n end do\n end do\n end if\n end do\n case (5)\n !\n ! case ityp=5 v even, w odd, br and bi equal zero\n !\n ! case m = 0\n !\n do k=1, nt\n do np1=3, odd_stride, 2\n do i=1, imm1\n wo(i, 1, k)=wo(i, 1, k)-cr(1, np1, k)*vb(i, np1)\n end do\n end do\n end do\n !\n ! case m = 1 through nlat-1\n !\n if (mmax < 2) exit vector_symmetry_cases\n\n do mp1=2, mmax\n m = mp1-1\n mb = m*nlat-(m*(m+1))/2\n mp2 = mp1+1\n\n if (mp1 <= odd_stride) then\n do k=1, nt\n do np1=mp1, odd_stride, 2\n mn = mb+np1\n do i=1, imm1\n ve(i, 2*mp1-2, k) = ve(i, 2*mp1-2, k)-ci(mp1, np1, k)*wb(i, mn)\n ve(i, 2*mp1-1, k) = ve(i, 2*mp1-1, k)+cr(mp1, np1, k)*wb(i, mn)\n wo(i, 2*mp1-2, k) = wo(i, 2*mp1-2, k)-cr(mp1, np1, k)*vb(i, mn)\n wo(i, 2*mp1-1, k) = wo(i, 2*mp1-1, k)-ci(mp1, np1, k)*vb(i, mn)\n end do\n if (mod(nlat, 2) /= 0) then\n ve(imid, 2*mp1-2, k) = ve(imid, 2*mp1-2, k) &\n -ci(mp1, np1, k)*wb(imid, mn)\n ve(imid, 2*mp1-1, k) = ve(imid, 2*mp1-1, k) &\n +cr(mp1, np1, k)*wb(imid, mn)\n end if\n end do\n end do\n end if\n end do\n case (6)\n !\n ! case ityp=6 v odd , w even\n !\n ! case m = 0\n !\n do k=1, nt\n do np1=2, even_stride, 2\n do i=1, imid\n we(i, 1, k)=we(i, 1, k)-cr(1, np1, k)*vb(i, np1)\n end do\n end do\n end do\n\n do k=1, nt\n do np1=3, odd_stride, 2\n do i=1, imm1\n vo(i, 1, k)=vo(i, 1, k)+br(1, np1, k)*vb(i, np1)\n end do\n end do\n end do\n !\n ! case m = 1 through nlat-1\n !\n if (mmax < 2) exit vector_symmetry_cases\n\n do mp1=2, mmax\n m = mp1-1\n mb = m*nlat-(m*(m+1))/2\n mp2 = mp1+1\n if (mp1 <= odd_stride) then\n do k=1, nt\n do np1=mp1, odd_stride, 2\n mn = mb+np1\n do i=1, imm1\n vo(i, 2*mp1-2, k) = vo(i, 2*mp1-2, k)+br(mp1, np1, k)*vb(i, mn)\n vo(i, 2*mp1-1, k) = vo(i, 2*mp1-1, k)+bi(mp1, np1, k)*vb(i, mn)\n we(i, 2*mp1-2, k) = we(i, 2*mp1-2, k)-bi(mp1, np1, k)*wb(i, mn)\n we(i, 2*mp1-1, k) = we(i, 2*mp1-1, k)+br(mp1, np1, k)*wb(i, mn)\n end do\n if (mod(nlat, 2) /= 0) then\n we(imid, 2*mp1-2, k) = we(imid, 2*mp1-2, k) &\n -bi(mp1, np1, k)*wb(imid, mn)\n we(imid, 2*mp1-1, k) = we(imid, 2*mp1-1, k) &\n +br(mp1, np1, k)*wb(imid, mn)\n end if\n end do\n end do\n end if\n\n if (mp2 <= even_stride) then\n do k=1, nt\n do np1=mp2, even_stride, 2\n mn = mb+np1\n do i=1, imm1\n vo(i, 2*mp1-2, k) = vo(i, 2*mp1-2, k)-ci(mp1, np1, k)*wb(i, mn)\n vo(i, 2*mp1-1, k) = vo(i, 2*mp1-1, k)+cr(mp1, np1, k)*wb(i, mn)\n we(i, 2*mp1-2, k) = we(i, 2*mp1-2, k)-cr(mp1, np1, k)*vb(i, mn)\n we(i, 2*mp1-1, k) = we(i, 2*mp1-1, k)-ci(mp1, np1, k)*vb(i, mn)\n end do\n if (mod(nlat, 2) /= 0) then\n we(imid, 2*mp1-2, k) = we(imid, 2*mp1-2, k) &\n -cr(mp1, np1, k)*vb(imid, mn)\n we(imid, 2*mp1-1, k) = we(imid, 2*mp1-1, k) &\n -ci(mp1, np1, k)*vb(imid, mn)\n end if\n end do\n end do\n end if\n end do\n case (7)\n !\n ! case ityp=7 v odd, w even cr and ci equal zero\n !\n ! case m = 0\n !\n do k=1, nt\n do np1=3, odd_stride, 2\n do i=1, imm1\n vo(i, 1, k)=vo(i, 1, k)+br(1, np1, k)*vb(i, np1)\n end do\n end do\n end do\n !\n ! case m = 1 through nlat-1\n !\n if (mmax < 2) exit vector_symmetry_cases\n\n do mp1=2, mmax\n m = mp1-1\n mb = m*nlat-(m*(m+1))/2\n mp2 = mp1+1\n if (mp1 <= odd_stride) then\n do k=1, nt\n do np1=mp1, odd_stride, 2\n mn = mb+np1\n do i=1, imm1\n vo(i, 2*mp1-2, k) = vo(i, 2*mp1-2, k)+br(mp1, np1, k)*vb(i, mn)\n vo(i, 2*mp1-1, k) = vo(i, 2*mp1-1, k)+bi(mp1, np1, k)*vb(i, mn)\n we(i, 2*mp1-2, k) = we(i, 2*mp1-2, k)-bi(mp1, np1, k)*wb(i, mn)\n we(i, 2*mp1-1, k) = we(i, 2*mp1-1, k)+br(mp1, np1, k)*wb(i, mn)\n end do\n if (mod(nlat, 2) /= 0) then\n we(imid, 2*mp1-2, k) = we(imid, 2*mp1-2, k) &\n -bi(mp1, np1, k)*wb(imid, mn)\n we(imid, 2*mp1-1, k) = we(imid, 2*mp1-1, k) &\n +br(mp1, np1, k)*wb(imid, mn)\n end if\n end do\n end do\n end if\n end do\n case (8)\n !\n ! case ityp=8 v odd, w even br and bi equal zero\n !\n ! case m = 0\n !\n do k=1, nt\n do np1=2, even_stride, 2\n do i=1, imid\n we(i, 1, k)=we(i, 1, k)-cr(1, np1, k)*vb(i, np1)\n end do\n end do\n end do\n !\n ! case m = 1 through nlat-1\n !\n if (mmax < 2) exit vector_symmetry_cases\n\n do mp1=2, mmax\n m = mp1-1\n mb = m*nlat-(m*(m+1))/2\n mp2 = mp1+1\n if (mp2 <= even_stride) then\n do k=1, nt\n do np1=mp2, even_stride, 2\n mn = mb+np1\n do i=1, imm1\n vo(i, 2*mp1-2, k) = vo(i, 2*mp1-2, k)-ci(mp1, np1, k)*wb(i, mn)\n vo(i, 2*mp1-1, k) = vo(i, 2*mp1-1, k)+cr(mp1, np1, k)*wb(i, mn)\n we(i, 2*mp1-2, k) = we(i, 2*mp1-2, k)-cr(mp1, np1, k)*vb(i, mn)\n we(i, 2*mp1-1, k) = we(i, 2*mp1-1, k)-ci(mp1, np1, k)*vb(i, mn)\n end do\n if (mod(nlat, 2) /= 0) then\n we(imid, 2*mp1-2, k) = we(imid, 2*mp1-2, k) &\n -cr(mp1, np1, k)*vb(imid, mn)\n we(imid, 2*mp1-1, k) = we(imid, 2*mp1-1, k) &\n -ci(mp1, np1, k)*vb(imid, mn)\n end if\n end do\n end do\n end if\n end do\n end select vector_symmetry_cases\n\n call util%assemble_transform(idvw, jdvw, idv, imid, &\n imm1, ityp, nlat, nlon, nt, v, ve, vo, w, we, wo, wrfft)\n\n end subroutine vhsgs_lower_utility_routine\n\n subroutine vhgsi_lower_utility_routine(nlat, imid, vb, wb, dthet, dwts, dpbar, work)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: imid\n real(wp), intent(out) :: vb(imid, *)\n real(wp), intent(out) :: wb(imid, *)\n real(wp), intent(out) :: dthet(nlat)\n real(wp), intent(out) :: dwts(nlat)\n real(wp), intent(out) :: dpbar(imid, nlat, 3)\n real(wp), intent(out) :: work(..)\n\n ! Local variables\n integer(ip) :: i, id, ierror, ix, iy\n integer(ip) :: m, mn, n, nm, np, nz\n real(wp) :: abel, bbel, cbel, dcf\n type(SpherepackUtility) :: util\n\n ! Compute gauss points and weights\n call compute_gaussian_latitudes_and_weights(nlat, dthet, dwts, ierror)\n !\n ! Compute associated legendre functions\n !\n ! Compute m=n=0 legendre polynomials for all theta(i)\n !\n dpbar(:, 1, 1) = cos(PI/4)\n vb(:, 1) = ZERO\n wb(:, 1) = ZERO\n !\n ! main loop for remaining vb, and wb\n !\n do n=1, nlat-1\n nm = mod(n - 2, 3) + 1\n nz = mod(n - 1, 3) + 1\n np = mod(n, 3) + 1\n !\n ! Compute dpbar for m=0\n !\n call util%compute_fourier_coefficients(0, n, work)\n mn = get_index(0, n, nlat)\n do i=1, imid\n call util%compute_legendre_polys_from_fourier_coeff(0, n, dthet(i), work, dpbar(i, 1, np))\n end do\n !\n ! Compute dpbar for m=1\n !\n call util%compute_fourier_coefficients(1, n, work)\n mn = get_index(1, n, nlat)\n do i=1, imid\n call util%compute_legendre_polys_from_fourier_coeff(1, n, dthet(i), work, dpbar(i, 2, np))\n end do\n !\n ! Compute and store dpbar for m=2, n\n !\n if (2 <= n) then\n do m=2, n\n abel = sqrt(real((2*n+1)*(m+n-2)*(m+n-3), kind=wp)/ &\n real((2*n-3)*(m+n-1)*(m+n), kind=wp))\n bbel = sqrt(real((2*n+1)*(n-m-1)*(n-m), kind=wp)/ &\n real((2*n-3)*(m+n-1)*(m+n), kind=wp))\n cbel = sqrt(real((n-m+1)*(n-m+2), kind=wp)/ &\n real((m+n-1)*(m+n), kind=wp))\n id = get_index(m, n, nlat)\n if (m < n-1) then\n dpbar(:, m+1, np) = abel*dpbar(:, m-1, nm)+bbel*dpbar(:, m+1, nm)-cbel*dpbar(:, m-1, np)\n else\n dpbar(:, m+1, np) = abel*dpbar(:, m-1, nm)-cbel*dpbar(:, m-1, np)\n end if\n end do\n end if\n !\n ! Compute the derivative of the functions\n !\n ix = get_index(0, n, nlat)\n iy = get_index(n, n, nlat)\n do i=1, imid\n vb(i, ix) = -dpbar(i, 2, np)\n vb(i, iy) = dpbar(i, n, np)/sqrt(real(2*(n+1), kind=wp))\n end do\n !\n if (n /= 1) then\n dcf = sqrt(real(4*n*(n+1), kind=wp))\n do m=1, n-1\n ix = get_index(m, n, nlat)\n abel = sqrt(real((n+m)*(n-m+1), kind=wp))/dcf\n bbel = sqrt(real((n-m)*(n+m+1), kind=wp))/dcf\n do i=1, imid\n vb(i, ix) = abel*dpbar(i, m, np)-bbel*dpbar(i, m+2, np)\n end do\n end do\n end if\n !\n ! compute the vector harmonic w(theta) = m*pbar/cos(theta)\n !\n ! set wb=0 for m=0\n !\n ix = get_index(0, n, nlat)\n wb(1:imid, ix) = ZERO\n !\n ! compute wb for m=1, n\n !\n dcf = sqrt(real(2*n+1, kind=wp)/real(4*n*(n+1)*(n+n-1), kind=wp))\n\n do m=1, n\n ix = get_index(m, n, nlat)\n abel = dcf*sqrt(real((n+m)*(n+m-1), kind=wp))\n bbel = dcf*sqrt(real((n-m)*(n-m-1), kind=wp))\n if (m < n-1) then\n wb(:, ix) = abel*dpbar(:, m, nz) + bbel*dpbar(:, m+2, nz)\n else\n wb(:, ix) = abel*dpbar(:, m, nz)\n end if\n end do\n end do\n\n end subroutine vhgsi_lower_utility_routine\n\n pure function get_index(m, n, nlat) &\n result (return_value)\n\n ! Dummy arguments\n integer(ip), intent(in) :: m\n integer(ip), intent(in) :: n\n integer(ip), intent(in) :: nlat\n integer(ip) :: return_value\n\n return_value = m*nlat-(m*(m+1))/2+n+1\n\n end function get_index\n\nend submodule vector_synthesis_gaussian_saved\n", "meta": {"hexsha": "ff24395f0614d0dfb20731bf98618a7ae99e42d4", "size": 59164, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/vector_synthesis_gaussian_grid_saved.f90", "max_stars_repo_name": "jlokimlin/spherepack4.1", "max_stars_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-06-28T14:01:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T21:59:28.000Z", "max_issues_repo_path": "src/vector_synthesis_gaussian_grid_saved.f90", "max_issues_repo_name": "jlokimlin/spherepack4.1", "max_issues_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2016-05-07T23:00:35.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-22T23:52:30.000Z", "max_forks_repo_path": "src/vector_synthesis_gaussian_grid_saved.f90", "max_forks_repo_name": "jlokimlin/spherepack4.1", "max_forks_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-06-28T14:03:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T12:53:54.000Z", "avg_line_length": 45.3016845329, "max_line_length": 112, "alphanum_fraction": 0.3741464404, "num_tokens": 17118, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110540642805, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6932046039174342}} {"text": "function r8_gamma ( x )\n\n!*****************************************************************************80\n!\n!! R8_GAMMA evaluates Gamma(X) for a real argument.\n!\n! Discussion:\n!\n! This function was originally named DGAMMA.\n!\n! However, a number of Fortran compilers now include a library\n! function of this name. To avoid conflicts, this function was\n! renamed R8_GAMMA.\n!\n! This routine calculates the GAMMA function for a real argument X.\n! Computation is based on an algorithm outlined in reference 1.\n! The program uses rational functions that approximate the GAMMA\n! function to at least 20 significant decimal digits. Coefficients\n! for the approximation over the interval (1,2) are unpublished.\n! Those for the approximation for 12 <= X are from reference 2.\n!\n! Modified:\n!\n! 18 January 2008\n!\n! Author:\n!\n! Original FORTRAN77 version by William Cody, Laura Stoltz.\n! FORTRAN90 version by John Burkardt\n!\n! Reference:\n!\n! William Cody,\n! An Overview of Software Development for Special Functions,\n! in Numerical Analysis Dundee, 1975,\n! edited by GA Watson,\n! Lecture Notes in Mathematics 506,\n! Springer, 1976.\n!\n! John Hart, Ward Cheney, Charles Lawson, Hans Maehly,\n! Charles Mesztenyi, John Rice, Henry Thatcher,\n! Christoph Witzgall,\n! Computer Approximations,\n! Wiley, 1968,\n! LC: QA297.C64.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the function.\n!\n! Output, real ( kind = 8 ) R8_GAMMA, the value of the function.\n!\n implicit none\n!\n! Coefficients for minimax approximation over (12, INF).\n!\n real ( kind = 8 ), dimension ( 7 ) :: c = (/ &\n -1.910444077728D-03, &\n 8.4171387781295D-04, &\n -5.952379913043012D-04, &\n 7.93650793500350248D-04, &\n -2.777777777777681622553D-03, &\n 8.333333333333333331554247D-02, &\n 5.7083835261D-03 /)\n real ( kind = 8 ) eps\n real ( kind = 8 ) fact\n real ( kind = 8 ) half\n integer ( kind = 4 ) i\n integer ( kind = 4 ) n\n real ( kind = 8 ) one\n real ( kind = 8 ) p(8)\n logical parity\n real ( kind = 8 ) pi\n real ( kind = 8 ) q(8)\n real ( kind = 8 ) r8_gamma\n real ( kind = 8 ) res\n real ( kind = 8 ) sqrtpi\n real ( kind = 8 ) sum\n real ( kind = 8 ) twelve\n real ( kind = 8 ) two\n real ( kind = 8 ) x\n real ( kind = 8 ) xbig\n real ( kind = 8 ) xden\n real ( kind = 8 ) xinf\n real ( kind = 8 ) xminin\n real ( kind = 8 ) xnum\n real ( kind = 8 ) y\n real ( kind = 8 ) y1\n real ( kind = 8 ) ysq\n real ( kind = 8 ) z\n real ( kind = 8 ) zero\n!\n! Mathematical constants\n!\n data one /1.0D+00 /\n data half /0.5D+00/\n data twelve /12.0D+00/\n data two /2.0D+00 /\n data zero /0.0D+00/\n data sqrtpi /0.9189385332046727417803297D+00/\n data pi /3.1415926535897932384626434D+00/\n!\n! Machine dependent parameters\n!\n data xbig / 171.624D+00 /\n data xminin / 2.23D-308 /\n data eps / 2.22D-16 /\n data xinf /1.79D+308/\n!\n! Numerator and denominator coefficients for rational minimax\n! approximation over (1,2).\n!\n data p / -1.71618513886549492533811D+0, 2.47656508055759199108314D+01, &\n -3.79804256470945635097577D+02, 6.29331155312818442661052D+02, &\n 8.66966202790413211295064D+02, -3.14512729688483675254357D+04, &\n -3.61444134186911729807069D+04, 6.64561438202405440627855D+04 /\n\n data q / -3.08402300119738975254353D+01, 3.15350626979604161529144D+02, &\n -1.01515636749021914166146D+03, -3.10777167157231109440444D+03, &\n 2.25381184209801510330112D+04, 4.75584627752788110767815D+03, &\n -1.34659959864969306392456D+05, -1.15132259675553483497211D+05 /\n\n parity = .false.\n fact = one\n n = 0\n y = x\n!\n! Argument is negative.\n!\n if ( y <= zero ) then\n\n y = - x\n y1 = aint ( y )\n res = y - y1\n\n if ( res /= zero ) then\n\n if ( y1 /= aint ( y1 * half ) * two ) then\n parity = .true.\n end if\n\n fact = - pi / sin ( pi * res )\n y = y + one\n\n else\n\n res = xinf\n r8_gamma = res\n return\n\n end if\n\n end if\n!\n! Argument is positive.\n!\n if ( y < eps ) then\n!\n! Argument < EPS.\n!\n if ( xminin <= y ) then\n res = one / y\n else\n res = xinf\n r8_gamma = res\n return\n end if\n\n else if ( y < twelve ) then\n\n y1 = y\n!\n! 0.0 < argument < 1.0.\n!\n if ( y < one ) then\n\n z = y\n y = y + one\n!\n! 1.0 < argument < 12.0.\n! Reduce argument if necessary.\n!\n else\n\n n = int ( y ) - 1\n y = y - real ( n, kind = 8 )\n z = y - one\n\n end if\n!\n! Evaluate approximation for 1.0 < argument < 2.0.\n!\n xnum = zero\n xden = one\n do i = 1, 8\n xnum = ( xnum + p(i) ) * z\n xden = xden * z + q(i)\n end do\n\n res = xnum / xden + one\n!\n! Adjust result for case 0.0 < argument < 1.0.\n!\n if ( y1 < y ) then\n\n res = res / y1\n!\n! Adjust result for case 2.0 < argument < 12.0.\n!\n else if ( y < y1 ) then\n\n do i = 1, n\n res = res * y\n y = y + one\n end do\n\n end if\n\n else\n!\n! Evaluate for 12.0 <= argument.\n!\n if ( y <= xbig ) then\n\n ysq = y * y\n sum = c(7)\n do i = 1, 6\n sum = sum / ysq + c(i)\n end do\n sum = sum / y - y + sqrtpi\n sum = sum + ( y - half ) * log ( y )\n res = exp ( sum )\n\n else\n\n res = huge ( res )\n r8_gamma = res\n return\n\n end if\n\n end if\n!\n! Final adjustments and return.\n!\n if ( parity ) then\n res = - res\n end if\n\n if ( fact /= one ) then\n res = fact / res\n end if\n\n r8_gamma = res\n\n return\n\nend function r8_gamma\n\n", "meta": {"hexsha": "55de2ae8ccd81bc0c8f53c92590d8f2233885363", "size": 5611, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Algorithm/DiffusionMonteCarlo/r8_gamma.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/r8_gamma.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/r8_gamma.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": 21.5807692308, "max_line_length": 80, "alphanum_fraction": 0.5690607735, "num_tokens": 1994, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110396870288, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6932045927419984}} {"text": "PROGRAM LAPLACE\n INTEGER, PARAMETER :: XSIZE=41,YSIZE=41\n REAL(8), DIMENSION(1:XSIZE,1:YSIZE) :: PHIOLD,PHINEW,ORIPHI,ERROR\n REAL :: MAXDELTA\n REAL(8) :: ERRORSUM,PHISTAR,NSQ=XSIZE*YSIZE\n REAL :: OMEGA\n\n REAL(8), PARAMETER :: CONVERGENCE = EPSILON(ERRORSUM)\n INTEGER :: ITERATIONS = 0\n\n INTEGER :: I,J\n\n DO I=1,XSIZE\n DO J=1,YSIZE\n PHINEW(I,J) = (I*I-J*J)/(NSQ)\n END DO\n END DO\n \n PHINEW(2:XSIZE-1,2:YSIZE-1)=0\n\n ORIPHI(1:XSIZE,1:YSIZE) = PHINEW(1:XSIZE,1:YSIZE)\n\n open(10,file='sor_41.csv')\n\n OMEGA = 0.0\n\n HUNT_OMEGA:DO\n OMEGA = OMEGA+0.1\n ITERATIONS = 0\n PHINEW(1:XSIZE,1:YSIZE) = ORIPHI(1:XSIZE,1:YSIZE)\n GAUSS_ITERATION: DO\n ITERATIONS = ITERATIONS+1\n PHIOLD=PHINEW\n\n DO I=2,XSIZE-1\n DO J=2,YSIZE-1\n PHINEW(I,J)=(0.25*(&\n &PHINEW(I-1,J)+&\n &PHINEW(I+1,J)+&\n &PHINEW(I,J-1)+&\n &PHINEW(I,J+1))-PHINEW(I,J))*OMEGA+&\n &PHINEW(I,J)\n END DO\n END DO\n ERROR = PHIOLD-PHINEW\n ERRORSUM = SQRT(SUM(ERROR*ERROR)/NSQ)\n if (ITERATIONS>=100) EXIT GAUSS_ITERATION\n END DO GAUSS_ITERATION\n\n write(10,*) OMEGA, ERRORSUM \n if (OMEGA >= 1.0) EXIT HUNT_OMEGA\n END DO HUNT_OMEGA\n \n close(10)\nEND PROGRAM LAPLACE\n", "meta": {"hexsha": "767017c70ffeddb8b3566c3a4b9d7427423028e7", "size": 1469, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "a3/sor/laplace.f95", "max_stars_repo_name": "cheekujodhpur/ae320", "max_stars_repo_head_hexsha": "7eb6a6d1fbf3fc2dcde546b96505e365a0b134a3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-04-11T21:21:24.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-15T06:20:02.000Z", "max_issues_repo_path": "a3/sor/laplace.f95", "max_issues_repo_name": "cheekujodhpur/ae320", "max_issues_repo_head_hexsha": "7eb6a6d1fbf3fc2dcde546b96505e365a0b134a3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "a3/sor/laplace.f95", "max_forks_repo_name": "cheekujodhpur/ae320", "max_forks_repo_head_hexsha": "7eb6a6d1fbf3fc2dcde546b96505e365a0b134a3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.2321428571, "max_line_length": 69, "alphanum_fraction": 0.5037440436, "num_tokens": 519, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181875, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.693150529226935}} {"text": "!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 2005 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Fishpack *\n! * *\n! * A Package of Fortran *\n! * *\n! * Subroutines and Example Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams, Paul Swarztrauber and Roland Sweet *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\n! SUBROUTINE hwscyl(a, b, m, mbdcnd, bda, bdb, c, d, n, nbdcnd, bdc, bdd,\n! elmbda, f, idimf, pertrb, ierror)\n!\n!\n! DIMENSION OF bda(n), bdb(n), bdc(m), bdd(m), f(idimf, n+1)\n! ARGUMENTS\n!\n! PURPOSE Solves a finite difference approximation\n! to the helmholtz equation in cylindrical\n! coordinates. this modified helmholtz equation\n!\n! (1/r)(d/dr)(r(du/dr)) + (d/dz)(du/dz)\n!\n! + (lambda/r**2)u = f(r, z)\n!\n! results from the fourier transform of the\n! three-dimensional poisson equation.\n!\n! USAGE call hwscyl(a, b, m, mbdcnd, bda, bdb, c, d, n,\n! nbdcnd, bdc, bdd, elmbda, f, idimf,\n! pertrb, ierror, w)\n!\n! ARGUMENTS\n! ON INPUT a, b\n! the range of r, i.e., a <= r <= b.\n! a must be less than b and a must be\n! non-negative.\n!\n! m\n! the number of panels into which the\n! interval (a, b) is subdivided. hence,\n! there will be m+1 grid points in the\n! r-direction given by r(i) = a+(i-1)dr,\n! for i = 1, 2, ..., m+1, where dr = (b-a)/m\n! is the panel width. m must be greater\n! than 3.\n!\n! mbdcnd\n! indicates the type of boundary conditions\n! at r = a and r = b.\n!\n! = 1 if the solution is specified at\n! r = a and r = b.\n! = 2 if the solution is specified at\n! r = a and the derivative of the\n! solution with respect to r is\n! specified at r = b.\n! = 3 if the derivative of the solution\n! with respect to r is specified at\n! r = a (see note below) and r = b.\n! = 4 if the derivative of the solution\n! with respect to r is specified at\n! r = a (see note below) and the\n! solution is specified at r = b.\n! = 5 if the solution is unspecified at\n! r = a = 0 and the solution is\n! specified at r = b.\n! = 6 if the solution is unspecified at\n! r = a = 0 and the derivative of the\n! solution with respect to r is specified\n! at r = b.\n!\n! if a = 0, do not use mbdcnd = 3 or 4,\n! but instead use mbdcnd = 1, 2, 5, or 6 .\n!\n! bda\n! a one-dimensional array of length n+1 that\n! specifies the values of the derivative of\n! the solution with respect to r at r = a.\n!\n! when mbdcnd = 3 or 4,\n! bda(j) = (d/dr)u(a, z(j)), j = 1, 2, ..., n+1.\n!\n! when mbdcnd has any other value, bda is\n! a dummy variable.\n!\n! bdb\n! a one-dimensional array of length n+1 that\n! specifies the values of the derivative\n! of the solution with respect to r at r = b.\n!\n! when mbdcnd = 2, 3, or 6,\n! bdb(j) = (d/dr)u(b, z(j)), j = 1, 2, ..., n+1.\n!\n! when mbdcnd has any other value, bdb is\n! a dummy variable.\n!\n! c, d\n! the range of z, i.e., c <= z <= d.\n! c must be less than d.\n!\n! n\n! the number of panels into which the\n! interval (c, d) is subdivided. hence,\n! there will be n+1 grid points in the\n! z-direction given by z(j) = c+(j-1)dz,\n! for j = 1, 2, ..., n+1,\n! where dz = (d-c)/n is the panel width.\n! n must be greater than 3.\n!\n! nbdcnd\n! indicates the type of boundary conditions\n! at z = c and z = d.\n!\n! = 0 if the solution is periodic in z,\n! i.e., u(i, 1) = u(i, n+1).\n! = 1 if the solution is specified at\n! z = c and z = d.\n! = 2 if the solution is specified at\n! z = c and the derivative of\n! the solution with respect to z is\n! specified at z = d.\n! = 3 if the derivative of the solution\n! with respect to z is\n! specified at z = c and z = d.\n! = 4 if the derivative of the solution\n! with respect to z is specified at\n! z = c and the solution is specified\n! at z = d.\n!\n! bdc\n! a one-dimensional array of length m+1 that\n! specifies the values of the derivative\n! of the solution with respect to z at z = c.\n!\n! when nbdcnd = 3 or 4,\n! bdc(i) = (d/dz)u(r(i), c), i = 1, 2, ..., m+1.\n!\n! when nbdcnd has any other value, bdc is\n! a dummy variable.\n!\n! bdd\n! a one-dimensional array of length m+1 that\n! specifies the values of the derivative of\n! the solution with respect to z at z = d.\n!\n! when nbdcnd = 2 or 3,\n! bdd(i) = (d/dz)u(r(i), d), i = 1, 2, ..., m+1\n!\n! when nbdcnd has any other value, bdd is\n! a dummy variable.\n!\n! elmbda\n! the constant lambda in the helmholtz\n! equation. if lambda > 0, a solution\n! may not exist. however, hwscyl will\n! attempt to find a solution. lambda must\n! be zero when mbdcnd = 5 or 6 .\n!\n! f\n! a two-dimensional array, of dimension at\n! least (m+1)*(n+1), specifying values\n! of the right side of the helmholtz\n! equation and boundary data (if any).\n!\n! on the interior, f is defined as follows:\n! for i = 2, 3, ..., m and j = 2, 3, ..., n\n! f(i, j) = f(r(i), z(j)).\n!\n! on the boundaries f is defined as follows:\n! for j = 1, 2, ..., n+1 and i = 1, 2, ..., m+1\n!\n! mbdcnd f(1, j) f(m+1, j)\n! ------ --------- ---------\n!\n! 1 u(a, z(j)) u(b, z(j))\n! 2 u(a, z(j)) f(b, z(j))\n! 3 f(a, z(j)) f(b, z(j))\n! 4 f(a, z(j)) u(b, z(j))\n! 5 f(0, z(j)) u(b, z(j))\n! 6 f(0, z(j)) f(b, z(j))\n!\n! nbdcnd f(i, 1) f(i, n+1)\n! ------ --------- ---------\n!\n! 0 f(r(i), c) f(r(i), c)\n! 1 u(r(i), c) u(r(i), d)\n! 2 u(r(i), c) f(r(i), d)\n! 3 f(r(i), c) f(r(i), d)\n! 4 f(r(i), c) u(r(i), d)\n!\n! note:\n! if the table calls for both the solution\n! u and the right side f at a corner then\n! the solution must be specified.\n!\n! idimf\n! the row (or first) dimension of the array\n! f as it appears in the program calling\n! hwscyl. this parameter is used to specify\n! the variable dimension of f. idimf must\n! be at least m+1 .\n!\n!\n! ON OUTPUT f\n! contains the solution u(i, j) of the finite\n! difference approximation for the grid point\n! (r(i), z(j)), i =1, 2, ..., m+1, j =1, 2, ..., n+1.\n!\n! pertrb\n! if one specifies a combination of periodic,\n! derivative, and unspecified boundary\n! conditions for a poisson equation\n! (lambda = 0), a solution may not exist.\n! pertrb is a constant, calculated and\n! subtracted from f, which ensures that a\n! solution exists. hwscyl then computes\n! this solution, which is a least squares\n! solution to the original approximation.\n! this solution plus any constant is also\n! a solution. hence, the solution is not\n! unique. the value of pertrb should be\n! small compared to the right side f.\n! otherwise, a solution is obtained to an\n! essentially different problem. this\n! comparison should always be made to insure\n! that a meaningful solution has been obtained.\n!\n! ierror\n! an error flag which indicates invalid input\n! parameters. except for numbers 0 and 11,\n! a solution is not attempted.\n!\n! = 0 no error.\n! = 1 a < 0 .\n! = 2 a >= b.\n! = 3 mbdcnd < 1 or mbdcnd > 6 .\n! = 4 c >= d.\n! = 5 n <= 3\n! = 6 nbdcnd < 0 or nbdcnd > 4 .\n! = 7 a = 0, mbdcnd = 3 or 4 .\n! = 8 a > 0, mbdcnd >= 5 .\n! = 9 a = 0, lambda /= 0, mbdcnd >= 5 .\n! = 10 idimf < m+1 .\n! = 11 lambda > 0 .\n! = 12 m <= 3\n! = 20 if the dynamic allocation of real and\n! complex workspace required for solution\n! fails (for example if n, m are too large\n! for your computer)\n!\n! since this is the only means of indicating\n! a possibly incorrect call to hwscyl, the\n! user should test ierror after the call.\n!\n!\n! HISTORY Written by Roland Sweet at NCAR in the late\n! 1970's. Released on NCAR's public software\n! libraries in January 1980.\n! Revised in June 2004 by John Adams using\n! Fortran 90 dynamically allocated workspace.\n!\n!\n!\n! ALGORITHM The routine defines the finite difference\n! equations, incorporates boundary data, and\n! adjusts the right side of singular systems\n! and then calls genbun to solve the system.\n!\n! TIMING For large m and n, the operation count\n! is roughly proportional to\n!\n! m*n*(log2(n)\n!\n! but also depends on input parameters nbdcnd\n! and mbdcnd.\n!\n! ACCURACY The solution process employed results in a loss\n! of no more than three significant digits for n\n! and m as large as 64. more details about\n! accuracy can be found in the documentation for\n! subroutine genbun which is the routine that\n! solves the finite difference equations.\n!\n! REFERENCES Swarztrauber, P. and R. Sweet, \"Efficient\n! FORTRAN subprograms for the solution of\n! elliptic equations\"\n! NCAR TN/IA-109, July, 1975, 138 pp.\n!\nsubmodule(centered_helmholtz_solvers) centered_cylindrical_solver\n\ncontains\n\n module subroutine hwscyl(a, b, m, mbdcnd, bda, bdb, c, d, n, nbdcnd, bdc, &\n bdd, elmbda, f, idimf, pertrb, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: m\n integer(ip), intent(in) :: mbdcnd\n integer(ip), intent(in) :: n\n integer(ip), intent(in) :: nbdcnd\n integer(ip), intent(in) :: idimf\n integer(ip), intent(out) :: ierror\n real(wp), intent(in) :: a\n real(wp), intent(in) :: b\n real(wp), intent(in) :: c\n real(wp), intent(in) :: d\n real(wp), intent(in) :: elmbda\n real(wp), intent(out) :: pertrb\n real(wp), intent(in) :: bda(:)\n real(wp), intent(in) :: bdb(:)\n real(wp), intent(in) :: bdc(:)\n real(wp), intent(in) :: bdd(:)\n real(wp), intent(inout) :: f(:,:)\n\n ! Local variables\n type(FishpackWorkspace) :: workspace\n\n ! Check input arguments\n call hwscyl_check_input_arguments(a, b, m, mbdcnd, c, d, n, &\n nbdcnd, elmbda, idimf, ierror)\n\n ! Check error flag\n if (ierror /= 0) return\n\n ! Allocate memory\n call workspace%initialize_staggered_workspace(n, m)\n\n ! Solve system\n associate( rew => workspace%real_workspace )\n call hwscyl_lower_routine(a, b, m, mbdcnd, bda, bdb, c, d, n, &\n nbdcnd, bdc, bdd, elmbda, f, idimf, pertrb, ierror, rew)\n end associate\n\n ! Release memory\n call workspace%destroy()\n\n end subroutine hwscyl\n\n subroutine hwscyl_check_input_arguments(a, b, m, mbdcnd, c, d, n, &\n nbdcnd, elmbda, idimf, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: m\n integer(ip), intent(in) :: mbdcnd\n integer(ip), intent(in) :: n\n integer(ip), intent(in) :: nbdcnd\n integer(ip), intent(in) :: idimf\n integer(ip), intent(out) :: ierror\n real(wp), intent(in) :: a\n real(wp), intent(in) :: b\n real(wp), intent(in) :: c\n real(wp), intent(in) :: d\n real(wp), intent(in) :: elmbda\n\n if (a < ZERO) then\n ierror = 1\n else if (a >= b) then\n ierror = 2\n else if (mbdcnd <= 0 .or. mbdcnd >= 7) then\n ierror = 3\n else if (c >= d) then\n ierror = 4\n else if (n <= 3) then\n ierror = 5\n else if (nbdcnd <= (-1) .or. nbdcnd >= 5) then\n ierror = 6\n else if (a == ZERO .and. (mbdcnd == 3 .or. mbdcnd == 4)) then\n ierror = 7\n else if (a > ZERO .and. mbdcnd >= 5) then\n ierror = 8\n else if (a == ZERO .and. elmbda /= ZERO .and. mbdcnd >= 5) then\n ierror = 9\n else if (idimf < m + 1) then\n ierror = 10\n else if (m <= 3) then\n ierror = 12\n else\n ierror = 0\n end if\n\n end subroutine hwscyl_check_input_arguments\n\n subroutine hwscyl_lower_routine(a, b, m, mbdcnd, bda, bdb, c, d, n, nbdcnd, bdc, &\n bdd, elmbda, f, idimf, pertrb, ierror, w)\n\n ! Dummy arguments\n\n integer(ip), intent(in) :: m\n integer(ip), intent(in) :: mbdcnd\n integer(ip), intent(in) :: n\n integer(ip), intent(in) :: nbdcnd\n integer(ip), intent(in) :: idimf\n integer(ip), intent(out) :: ierror\n real(wp), intent(in) :: a\n real(wp), intent(in) :: b\n real(wp), intent(in) :: c\n real(wp), intent(in) :: d\n real(wp), intent(in) :: elmbda\n real(wp), intent(out) :: pertrb\n real(wp), intent(in) :: bda(:)\n real(wp), intent(in) :: bdb(:)\n real(wp), intent(in) :: bdc(:)\n real(wp), intent(in) :: bdd(:)\n real(wp), intent(inout) :: f(:,:)\n real(wp), intent(inout) :: w(:)\n\n ! Local variables\n integer(ip) :: mp1, np1, np, mstart, mstop, munk, nstart, nstop, nunk\n integer(ip) :: id2, id3, id4, id5, id6, istart\n integer(ip) :: ij, i, j, k, l, nsp1, nstm1\n integer(ip) :: local_error_flag, i1\n real(wp) :: dr, half_dr, dr2, dth, dth2\n real(wp) :: a1, r, a2, s, s1, s2\n type(CenteredCyclicReductionUtility) :: util\n\n mp1 = m + 1\n dr = (b - a)/m\n half_dr = dr/2\n dr2 = dr**2\n np1 = n + 1\n dth = (d - c)/n\n dth2 = dth**2\n np = nbdcnd + 1\n\n ! Define range of indices i and j for unknowns u(i, j).\n mstart = 2\n mstop = m\n select case (mbdcnd)\n case (2)\n mstop = mp1\n case (3, 6)\n mstart = 1\n mstop = mp1\n case (4:5)\n mstart = 1\n end select\n\n munk = mstop - mstart + 1\n nstart = 1\n nstop = n\n select case (np)\n case (2)\n nstart = 2\n case (3)\n nstart = 2\n nstop = np1\n case (4)\n nstop = np1\n end select\n\n nunk = nstop - nstart + 1\n\n ! Define a, b, c coefficients in w-array.\n id2 = munk\n id3 = id2 + munk\n id4 = id3 + munk\n id5 = id4 + munk\n id6 = id5 + munk\n istart = 1\n a1 = TWO/dr2\n ij = 0\n\n if (mbdcnd==3 .or. mbdcnd==4) ij = 1\n\n if (mbdcnd > 4) then\n w(1) = 0.\n w(id2+1) = -TWO*a1\n w(id3+1) = TWO*a1\n istart = 2\n ij = 1\n end if\n\n do i = istart, munk\n r = a + real(i - ij, kind=wp)*dr\n j = id5 + i\n w(j) = r\n j = id6 + i\n w(j) = ONE/r**2\n w(i) = (r - half_dr)/(r*dr2)\n j = id3 + i\n w(j) = (r + half_dr)/(r*dr2)\n k = id6 + i\n j = id2 + i\n w(j) = (-a1) + elmbda*w(k)\n end do\n\n select case (mbdcnd)\n case (2)\n w(id2) = a1\n case (3, 6)\n w(id2) = a1\n w(id3+1) = a1*real(istart, kind=wp)\n case (4)\n w(id3+1) = a1*real(istart, kind=wp)\n end select\n\n select case (mbdcnd)\n case (1:2)\n a1 = w(1)\n f(2, nstart:nstop) = f(2, nstart:nstop) - a1*f(1, nstart:nstop)\n case (3:4)\n a1 = TWO*dr*w(1)\n f(1, nstart:nstop) = f(1, nstart:nstop) + a1*bda(nstart:nstop)\n end select\n\n select case (mbdcnd)\n case (1, 4:5)\n a1 = w(id4)\n f(m, nstart:nstop) = f(m, nstart:nstop) - a1*f(mp1, nstart:nstop)\n case (2:3, 6)\n a1 = TWO*dr*w(id4)\n f(mp1, nstart:nstop) = f(mp1, nstart:nstop) - a1*bdb(nstart:nstop)\n end select\n\n ! Enter boundary data for z-boundaries.\n a1 = ONE/dth2\n l = id5 - mstart + 1\n\n if (np /= 1) then\n select case (np)\n case (2:3)\n f(mstart:mstop, 2) = f(mstart:mstop, 2) - a1*f(mstart:mstop, 1)\n case (4:5)\n a1 = 2./dth\n f(mstart:mstop, 1) = f(mstart:mstop, 1) + a1*bdc(mstart:mstop)\n end select\n\n a1 = ONE/dth2\n select case (np)\n case (2, 5)\n f(mstart:mstop, n) = f(mstart:mstop, n) - a1*f(mstart:mstop, np1)\n case (3:4)\n a1 = 2./dth\n f(mstart:mstop, np1) = f(mstart:mstop, np1) - a1*bdd(mstart:mstop)\n end select\n end if\n\n if_block: block\n pertrb = ZERO\n if (elmbda >= ZERO) then\n if (elmbda /= ZERO) then\n ierror = 11\n return\n else\n w(id5+1) = HALF*(w(id5+2)-half_dr)\n\n select case (mbdcnd)\n case (1:2, 4:5)\n exit if_block\n case (6)\n w(id5+1) = HALF*w(id5+1)\n end select\n\n select case (np)\n case (1)\n a2 = ONE\n case (2:3, 5)\n exit if_block\n case (4)\n a2 = TWO\n end select\n\n k = id5 + munk\n w(k) = HALF*(w(k-1)+half_dr)\n s = ZERO\n\n do i = mstart, mstop\n s1 = ZERO\n nsp1 = nstart + 1\n nstm1 = nstop - 1\n s1 = sum(f(i, nsp1:nstm1))\n k = i + l\n s = s + (a2*s1 + f(i, nstart)+f(i, nstop))*w(k)\n end do\n\n s2 = real(m, kind=wp)*a + (0.75_wp + real((m - 1)*(m + 1), kind=wp))*half_dr\n\n if (mbdcnd == 3) s2 = s2 + 0.25_wp*half_dr\n\n s1 = (TWO + a2*real(nunk-2, kind=wp))*s2\n\n pertrb = s/s1\n f(mstart:mstop, nstart:nstop) = &\n f(mstart:mstop, nstart:nstop) - pertrb\n end if\n end if\n end block if_block\n\n w(:mstop-mstart+1) = w(:mstop-mstart+1)*dth2\n w(id2+1:mstop-mstart+1+id2) = w(id2+1:mstop-mstart+1+id2)*dth2\n w(id3+1:mstop-mstart+1+id3) = w(id3+1:mstop-mstart+1+id3)*dth2\n f(mstart:mstop, nstart:nstop) = f(mstart:mstop, nstart:nstop)*dth2\n w(1) = ZERO\n w(id4) = ZERO\n\n ! Solve the system of equations.\n local_error_flag = 0\n i1 = 1\n call util%genbun_lower_routine(nbdcnd, nunk, i1, munk, w(1:), w(id2+1:), w(id3+1:), &\n idimf, f(mstart:, nstart:), local_error_flag, w(id4+1:))\n\n if (local_error_flag /= 0) then\n error stop 'fishpack library: genbun_lower_routine call failed in hwscyl_lower_routine'\n end if\n\n if (nbdcnd == 0) f(mstart:mstop, np1) = f(mstart:mstop, 1)\n\n end subroutine hwscyl_lower_routine\n\nend submodule centered_cylindrical_solver\n", "meta": {"hexsha": "232ac73d3106207b7b4428bbab6a3636aa410833", "size": 26147, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/centered_cylindrical_solver.f90", "max_stars_repo_name": "jlokimlin/fishpack", "max_stars_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2018-03-12T11:31:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-27T07:58:23.000Z", "max_issues_repo_path": "src/centered_cylindrical_solver.f90", "max_issues_repo_name": "jlokimlin/fishpack", "max_issues_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2016-05-07T22:42:47.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-15T17:44:58.000Z", "max_forks_repo_path": "src/centered_cylindrical_solver.f90", "max_forks_repo_name": "jlokimlin/modern_fishpack", "max_forks_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-01-26T20:49:05.000Z", "max_forks_repo_forks_event_max_datetime": "2017-01-27T16:44:58.000Z", "avg_line_length": 41.1763779528, "max_line_length": 99, "alphanum_fraction": 0.3757218801, "num_tokens": 6511, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314647623016, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6931505221392329}} {"text": "program call_by_in_reference\n implicit none\n\n print *, factorial(5)\n\ncontains\n\n function factorial(arg) result(fac)\n implicit none\n integer, intent(in) :: arg\n integer :: fac, n\n\n n = arg\n fac = 1\n do while (n > 1)\n fac = fac*n\n n = n - 1\n end do\n end function factorial\n\nend program call_by_in_reference\n", "meta": {"hexsha": "42cc6e98f4dad620e5a42bd0d9fff9108eab2b55", "size": 388, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source_code/call_by_semantics/call_by_in_reference.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/call_by_semantics/call_by_in_reference.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/call_by_semantics/call_by_in_reference.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": 17.6363636364, "max_line_length": 39, "alphanum_fraction": 0.5515463918, "num_tokens": 98, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181876, "lm_q2_score": 0.7826624738835051, "lm_q1q2_score": 0.6931505202476373}} {"text": "!********************************************************************************\n! MPROUTINES: Multi-Precision Routines\n! Authors: Thomas R. Cameron and Aidan O'Neill\n! Institution: Davidson College, Mathematics and Computer Science Department\n! Last Modified: 29 March 2020\n!********************************************************************************\nmodule mproutines\n use eft\n use mpmodule\n implicit none\n \ncontains\n !********************************************************\n ! Compute Condition *\n !********************************************************\n ! Given the polynomial, use multi-precision Horner method\n ! to compute the condition number of poly at x. The\n ! result is returned in comp which has type real(kind=dp). \n !********************************************************\n function compCond(poly,x,deg) result(comp)\n implicit none\n ! argument variables\n integer :: deg\n real(kind=dp) :: poly(:), x\n ! local variables\n integer :: k\n real(kind=dp) :: comp\n type(mp_real) :: mp_comp, mp_poly(deg+1), mp_apoly(deg+1), alpha, beta, rho\n \n ! convert to mp_type\n do k=1,deg+1\n mp_poly(k) = mpreald(poly(k))\n mp_apoly(k) = abs(mp_poly(k))\n end do\n ! compute rho\n mp_comp = mpreald(abs(x))\n rho = mp_apoly(deg+1)\n do k=deg,1,-1\n rho = mp_comp*rho + mp_apoly(k)\n end do\n ! compute alpha and beta\n mp_comp = mpreald(x)\n alpha = mp_poly(deg+1)\n beta = mpreald(0.0_dp)\n do k=deg,1,-1\n beta = mp_comp*beta + alpha\n alpha = mp_comp*alpha + mp_poly(k)\n end do\n ! compute cond\n if(beta==mpreald(0.0_dp)) then\n mp_comp = mpreald(big)\n else\n mp_comp = rho/abs(mp_comp*beta)\n end if\n ! convert to dp-precision\n comp = mp_comp\n return\n end function compCond\n !********************************************************\n ! Compute Condition Cplx *\n !********************************************************\n ! Complex version of Compute Condition.\n !********************************************************\n function compCondCplx(poly,x,deg) result(comp)\n implicit none\n ! argument variables\n integer :: deg\n complex(kind=dp) :: poly(:), x\n ! local variables\n integer :: k\n real(kind=dp) :: comp\n type(mp_real) :: mp_comp, mp_apoly(deg+1), rho\n type(mp_complex) :: cmp_comp, mp_poly(deg+1), alpha, beta\n \n ! convert to mp_type\n do k=1,deg+1\n mp_poly(k) = mpcmplxdc(poly(k))\n mp_apoly(k) = abs(mp_poly(k))\n end do\n ! compute rho\n mp_comp = mpreald(abs(x))\n rho = mp_apoly(deg+1)\n do k=deg,1,-1\n rho = mp_comp*rho + mp_apoly(k)\n end do\n ! compute alpha and beta\n cmp_comp = mpcmplxdc(x)\n alpha = mp_poly(deg+1)\n beta = mpcmplxdc(cmplx(0.0_dp,0.0_dp,kind=dp))\n do k=deg,1,-1\n beta = cmp_comp*beta + alpha\n alpha = cmp_comp*alpha + mp_poly(k)\n end do\n ! compute cond\n if(beta==mpcmplxdc(cmplx(0.0_dp,0.0_dp,kind=dp))) then\n mp_comp = mpreald(big)\n else\n mp_comp = rho/abs(cmp_comp*beta)\n end if\n ! convert to dp-precision\n comp = mp_comp\n return\n end function compCondCplx\n !********************************************************\n ! limAccPoly *\n !********************************************************\n ! Creates test polynomial (x-1)^deg-10^(-8) for the \n ! limiting accuracy testing. The result is stored in poly. \n !********************************************************\n subroutine limAccPoly(poly,deg)\n implicit none\n ! argument variables\n integer, intent(in) :: deg\n real(kind=dp), intent(inout) :: poly(:)\n ! local variables\n type(mp_real) :: r(deg), c(deg), alpha\n integer :: i, j\n \n ! store mp-type arrays\n do i=1,deg\n r(i) = mpreald(1.0_dp)\n c(i) = mpreald(0.0_dp)\n end do\n ! create poly\n do i=1,deg\n alpha = -r(i)\n do j=i,1,-1\n if(j==1) then\n c(j) = c(j) + alpha\n else\n c(j) = c(j) + alpha*c(j-1)\n end if\n end do\n end do\n ! shift c(deg) by 10E-8\n c(deg) = c(deg) - mpreald(1.0E-8_dp)\n ! convert to dp-precision\n do i=1,deg\n poly(i) = c(deg+1-i)\n end do\n poly(deg+1) = 1.0_dp\n end subroutine limAccPoly\n !********************************************************\n ! limAccPolyCplx *\n !********************************************************\n ! Complex version of limAccPoly.\n !********************************************************\n subroutine limAccPolyCplx(poly,deg)\n implicit none\n ! argument variables\n integer, intent(in) :: deg\n complex(kind=dp), intent(inout) :: poly(:)\n ! local variables\n type(mp_complex) :: r(deg), c(deg), alpha\n integer :: i, j\n \n ! store mp-type arrays\n do i=1,deg\n r(i) = mpcmplxdc(cmplx(1.0_dp,1.0_dp,kind=dp))\n c(i) = mpcmplxdc(cmplx(0.0_dp,0.0_dp,kind=dp))\n end do\n ! create poly\n do i=1,deg\n alpha = -r(i)\n do j=i,1,-1\n if(j==1) then\n c(j) = c(j) + alpha\n else\n c(j) = c(j) + alpha*c(j-1)\n end if\n end do\n end do\n ! shift c(deg) by 10E-8\n c(deg) = c(deg) - mpcmplxdc(cmplx(1.0E-8_dp,0.0_dp,kind=dp))\n ! convert to dp-precision\n do i=1,deg\n poly(i) = c(deg+1-i)\n end do\n poly(deg+1) = cmplx(1.0_dp,0.0_dp,kind=dp)\n end subroutine limAccPolyCplx\n !********************************************************\n ! limAccRoot *\n !********************************************************\n ! Given coeeficients of (x-1)^deg-10^(-8) stored in \n ! dp-precision, use multi-precision Newton's method to \n ! compute exact root. The result is returned in comp which\n ! has type real(kind=dp).\n !********************************************************\n function limAccRoot(poly,deg) result(comp)\n implicit none\n ! argument variables\n integer :: deg\n real(kind=dp) :: poly(:)\n ! local variables\n integer :: j, k\n real(kind=dp) :: comp\n type(mp_real) :: mp_comp, mp_poly(deg+1), alpha, beta\n \n ! convert to mp-type\n do k=1,deg+1\n mp_poly(k) = mpreald(poly(k))\n end do\n ! root approximation\n mp_comp = mpreald(1.0_dp + 10.0_dp**(-8.0_dp/real(deg,kind=dp)))\n ! Newton's method\n do k=1,5\n ! MPHorner applied to mp_mpoly\n alpha = mp_poly(deg+1)\n beta = mpreald(0.0_dp)\n do j=deg,1,-1\n beta = mp_comp*beta + alpha\n alpha = mp_comp*alpha + mp_poly(j)\n end do\n ! update root approximation\n mp_comp = mp_comp - (alpha/beta)\n end do\n ! convert to dp-precision\n comp = mp_comp\n return\n end function limAccRoot\n !********************************************************\n ! limAccRootCplx *\n !********************************************************\n ! Complex version of limAccRoot.\n !********************************************************\n function limAccRootCplx(poly,deg) result(comp)\n implicit none\n ! argument variables\n integer :: deg\n complex(kind=dp) :: poly(:)\n ! local variables\n integer :: j, k\n complex(kind=dp) :: comp\n type(mp_complex) :: mp_comp, mp_poly(deg+1), alpha, beta\n \n ! convert to mp-type\n do k=1,deg+1\n mp_poly(k) = mpcmplxdc(poly(k))\n end do\n ! root approximation\n mp_comp = mpcmplxdc(cmplx(1.0_dp + 10.0_dp**(-8.0_dp/real(deg,kind=dp)),1.0_dp,kind=dp))\n ! Newton's method\n do k=1,5\n ! MPHorner applied to mp_mpoly\n alpha = mp_poly(deg+1)\n beta = mpcmplxdc(cmplx(0.0_dp,0.0_dp,kind=dp))\n do j=deg,1,-1\n beta = mp_comp*beta + alpha\n alpha = mp_comp*alpha + mp_poly(j)\n end do\n ! update root approximation\n mp_comp = mp_comp - (alpha/beta)\n end do\n ! convert to dp-precision\n comp = mp_comp\n return\n end function limAccRootCplx\n !********************************************************\n ! Multi-precision Horner *\n !********************************************************\n ! Evaluate polynomial at floating-point number in multi-\n ! precision using MPFun and Horner's method. The result\n ! is returned in comp which has type real(kind=dp). \n !********************************************************\n function MPHorner(poly,x,deg) result(comp)\n implicit none\n ! argument variables\n integer :: deg\n real(kind=dp) :: poly(:), x\n ! local variables\n integer :: k\n real(kind=dp) :: comp\n type(mp_real) :: mp_comp, mp_poly(deg+1), mp_x\n \n ! convert to mp-type\n do k=1,deg+1\n mp_poly(k) = mpreald(poly(k))\n end do\n mp_x = mpreald(x)\n ! Horner's method\n mp_comp = mp_poly(deg+1)\n do k=deg,1,-1\n mp_comp = mp_x*mp_comp + mp_poly(k)\n end do\n ! convert to dp-precision\n comp = mp_comp\n return\n end function MPHorner\n !********************************************************\n ! Multi-precision Horner Cplx *\n !********************************************************\n ! Complex version of MPHorner.\n !********************************************************\n function MPHornerCplx(poly,x,deg) result(comp)\n implicit none\n ! argument variables\n integer :: deg\n complex(kind=dp) :: poly(:), x\n ! local variables\n integer :: k\n complex(kind=dp) :: comp\n type(mp_complex) :: mp_comp, mp_poly(deg+1), mp_x\n \n ! convert to mp-type\n do k=1,deg+1\n mp_poly(k) = mpcmplxdc(poly(k))\n end do\n mp_x = mpcmplxdc(x)\n ! Horner's method\n mp_comp = mp_poly(deg+1)\n do k=deg,1,-1\n mp_comp = mp_x*mp_comp + mp_poly(k)\n end do\n ! convert to dp-precision\n comp = mp_comp\n return\n end function MPHornerCplx \n !********************************************************\n ! Roots to Coeffs *\n !********************************************************\n ! Uses mpfun to compute the coefficients of a polynomial\n ! whose roots are given in roots. The result is stored\n ! in coeffs.\n !********************************************************\n subroutine rootCoeff(deg,roots,coeffs)\n implicit none\n ! argument variables\n integer, intent(in) :: deg\n real(kind=dp), intent(in) :: roots(:)\n real(kind=dp), intent(out) :: coeffs(:)\n ! local variables\n type(mp_real) :: r(deg), c(deg+1), alpha\n integer :: i, j\n \n ! convert to mp-type\n do i=1,deg\n r(i) = mpreald(roots(i))\n c(i) = mpreald(0.0_dp)\n end do\n\t\t! expand polynomial\n do i=1,deg\n alpha = -r(i)\n do j=i,1,-1\n if(j==1) then\n c(j) = c(j) + alpha\n else\n c(j) = c(j) + alpha*c(j-1)\n end if\n end do\n end do\n ! convert to dp-precision\n do i=1,deg\n coeffs(i) = c(deg+1-i)\n end do\n ! multiply by leading coefficient\n do i=1,deg\n coeffs(i) = coeffs(deg+1)*coeffs(i)\n end do\n end subroutine rootCoeff\n !********************************************************\n ! Roots to Coeffs Cplx *\n !********************************************************\n ! Complex version of rootCoeff.\n !********************************************************\n subroutine rootCoeffCplx(deg,roots,coeffs)\n implicit none\n ! argument variables\n integer, intent(in) :: deg\n complex(kind=dp), intent(in) :: roots(:)\n complex(kind=dp), intent(out) :: coeffs(:)\n ! local variables\n type(mp_complex) :: r(deg), c(deg+1), alpha\n integer :: i, j\n \n ! convert to mp-type\n do i=1,deg\n r(i) = mpcmplxdc(roots(i))\n c(i) = mpcmplxdc(cmplx(0.0_dp,0.0_dp,kind=dp))\n end do\n\t\t! expand polynomial\n do i=1,deg\n alpha = -r(i)\n do j=i,1,-1\n if(j==1) then\n c(j) = c(j) + alpha\n else\n c(j) = c(j) + alpha*c(j-1)\n end if\n end do\n end do\n ! convert to dp-precision\n do i=1,deg\n coeffs(i) = c(deg+1-i)\n end do\n ! multiply by leading coefficient\n do i=1,deg\n coeffs(i) = coeffs(deg+1)*coeffs(i)\n end do\n end subroutine rootCoeffCplx\nend module mproutines", "meta": {"hexsha": "f020e43da4ae0acbcd9779ba6fbe56cb8fde35e7", "size": 14707, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/mproutines.f90", "max_stars_repo_name": "trcameron/FPML-Comp", "max_stars_repo_head_hexsha": "f71c968b5a9fc490fcce7490b8543e6c54dc7c42", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/mproutines.f90", "max_issues_repo_name": "trcameron/FPML-Comp", "max_issues_repo_head_hexsha": "f71c968b5a9fc490fcce7490b8543e6c54dc7c42", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/mproutines.f90", "max_forks_repo_name": "trcameron/FPML-Comp", "max_forks_repo_head_hexsha": "f71c968b5a9fc490fcce7490b8543e6c54dc7c42", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.7675, "max_line_length": 101, "alphanum_fraction": 0.4040252941, "num_tokens": 3427, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314647623015, "lm_q2_score": 0.7826624789529376, "lm_q1q2_score": 0.6931505176495841}} {"text": "Function fnndpi(s)\n Parameter (srt0=2.012)\n If (s<=srt0**2) Then\n fnndpi = 0.\n Else\n fnndpi = 26.*exp(-(s-4.65)**2/0.1) + 4.*exp(-(s-4.65)**2/2.) + 0.28*exp(-(s-6.)**2/10.)\n End If\n Return\nEnd Function fnndpi\n", "meta": {"hexsha": "5bed741b16419c15dc00c9a7ed03d3090076f764", "size": 220, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fnndpi.f90", "max_stars_repo_name": "xiaohaijin/AMPT", "max_stars_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-12-24T19:37:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-14T12:58:59.000Z", "max_issues_repo_path": "src/fnndpi.f90", "max_issues_repo_name": "xiaohaijin/AMPT", "max_issues_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_issues_repo_licenses": ["MIT"], "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/fnndpi.f90", "max_forks_repo_name": "xiaohaijin/AMPT", "max_forks_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_forks_repo_licenses": ["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.0, "max_line_length": 91, "alphanum_fraction": 0.5545454545, "num_tokens": 109, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9441768651485394, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.693138668060613}} {"text": "c=======================================================================\nc\nc subroutine pricing/PRvanilla \nc\nc This function computes analytic valuation and greeks for European \nc style puts and calls (Vanilla) allows different daycount and interest \nc rate conventions.\nc\nc List of Results (Greeks)\nc ------------------------\nc 0 :value\nc 1 :spot delta\nc 2 :gamma\nc 3 :annual theta\nc 4 :vega\nc 5 :rho domestic\nc 6 :rho foreign\nc 7 :dstrike !derivative wrt strike\nc 8 :d2strike !second derivative wrt strike\nc 9 :dduration !derivative wrt to T(time to expiration) = - annual theta\nc 10:leverage !spot * spotdelta / value\nc 11:vomma !second derivative wrt vol\nc 12:retrieved_vola !volatility implied by the option value, enter value for vol\nc 13:forwarddelta !derivative wrt forward\nc 14:probdelta !common probability factor in spot delta and forward delta, N(d1)\nc 15:daily theta\nc 16:forward\nc 17:swaprate\nc 18:d1\nc 19:d2\nc 20:disc !domestic discount factor\nc 21:strike_of_delta \nc\nc-----------------------------------------------------------------------\n SUBROUTINE PRvanilla(spot, strike, vol, rd, rf, tau, phi, \n & convention, quotation, greek, van, info) \nc-----------------------------------------------------------------------\nc\nc INPUT\nc spot : spot price (>0) double \nc strike : stike price (>0) double\nc vol : annual volatility (>=0) double\nc rd : domestic risk free rate (>=0) double \nc discounting is done as (1+r)^{-T}\\n\nc rf : foreign risk free rate or dividend rate (>=0) double \nc discounting is done as (1+rf)^{-T}\\n \nc tau : time to maturity (in year) double\nc phi : (1) Call, (-1) Put integer\nc convention : compounded convention integer\nc (0) linear for less than one year,\nc (1) annually compounded, \nc (2) continuously compounded\nc quotation : system of quotation integer\nc (0) domestic, \nc (1) %domestic, \nc (2) foreign, \nc (3) %foreign\nc greek : type of result integer\nc (0) :value\nc (1) :spot delta, first derivative of the option value with respect to the underlying price\nc (2) :gamma, second derivative of the option value with respect to the underlying price\nc (3) :annual theta, derivative of the option value with respect to the amount of time to expiry\nc (4) :vega, derivative of the option value with respect to the volatility of the underlying\nc (5) :rho domestic, derivative of the option value with respect to the risk free rate\nc (6) :rho foreign\nc (7) :dstrike, derivative wrt strike\nc (8) :d2strike, second derivative wrt strike\nc (9) :dduration, derivative wrt to T(time to expiration) = - annual theta\nc (10):leverage, spot * spotdelta / value\nc (11):vomma/volga, second derivative wrt vol (second derivative of the option value with respect to the volatility of the underlying)\nc (12):retrieved_vola, volatility implied by the option value, enter value for vol\nc (13):forwarddelta, derivative wrt forward\nc (14):probdelta, common probability factor in spot delta and forward delta, N(d1)\nc (15):daily theta\nc (16):forward\nc (17):swaprate\nc (18):d1\nc (19):d2\nc (20):disc, domestic discount factor\nc (21):strike_of_delta \nc\nc OUTPUT\nc van : result of analytics double \nc info : diagnostic argument integer\nc\nc----------------------------------------------------------------------\nc\n IMPLICIT NONE\nc\nc i/o arguments\n INTEGER phi, convention, quotation, greek, info\n DOUBLE PRECISION spot, strike, vol, rd, rf, tau, van\nc\nc external functions\n DOUBLE PRECISION PRVAN\n EXTERNAL PRVAN\nc\nc----------------------------------------------------------------------\nc\nc initialization \n info = 0\n van = 0\nc\nc PRVAN (Analytics Vanilla), cf. pricing/PRutils.F \n van = PRVAN(spot, strike, vol, rd ,rf ,tau ,phi ,convention,\n & quotation, greek) \nc\n RETURN\n END \n \n \n", "meta": {"hexsha": "e39d91093c518778625205f71cd8f7cb2bfe51e0", "size": 4710, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/pricing/PRvanilla.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/pricing/PRvanilla.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/pricing/PRvanilla.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": 42.0535714286, "max_line_length": 138, "alphanum_fraction": 0.5218683652, "num_tokens": 1148, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768541530197, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6931386599885873}} {"text": " subroutine clawpack46_rpt2(ixy,maxm,meqn,mwaves,mbc,mx,ql,qr,\n & aux1,aux2,aux3,imp,asdq,bmasdq,bpasdq)\n implicit double precision (a-h,o-z)\nc\nc # Riemann solver in the transverse direction for the acoustics equations\nc # with varying material properties rho and kappa\nc\nc # auxN(i,1) holds rho\nc # auxN(i,2) holds c\nc # N = 1 for row below\nc # 2 for this row\nc # 3 for row above\nc\nc # Split asdq into down-going flux bmasdq and up-going flux bpasdq.\nc\nc # imp=1 means asdq=amdq, imp=2 means asdq=apdq\nc\n dimension ql(1-mbc:maxm+mbc, meqn)\n dimension qr(1-mbc:maxm+mbc, meqn)\n dimension asdq(1-mbc:maxm+mbc, meqn)\n dimension bmasdq(1-mbc:maxm+mbc, meqn)\n dimension bpasdq(1-mbc:maxm+mbc, meqn)\n dimension aux1(1-mbc:maxm+mbc, *)\n dimension aux2(1-mbc:maxm+mbc, *)\n dimension aux3(1-mbc:maxm+mbc, *)\nc\nc\nc\n if (ixy.eq.1) then\n mu = 2\n mv = 3\n else\n mu = 3\n mv = 2\n endif\nc\nc\n do 20 i = 2-mbc, mx+mbc\nc\nc # imp is used to flag whether wave is going to left or right,\nc # since material properties are different on the two sides\nc\n if (imp.eq.1) then\nc # asdq = amdq, moving to left\n i1 = i-1\n else\nc # asdq = apdq, moving to right\n i1 = i\n endif\nc\nc # The flux difference asdq is split into downward moving part\nc # traveling at speed -c relative to the medium below and\nc # an upward moving part traveling\nc # at speed +c relative to the medium above.\nc\nc # Note that the sum of these parts does not give all of asdq\nc # since there is also reflection at the interfaces which decreases\nc # the flux.\nc\nc # sound speed in each row of cells:\n cm = aux1(i1,2)\n c = aux2(i1,2)\n cp = aux3(i1,2)\nc\nc # impedances:\n zm = aux1(i1,1)*aux1(i1,2)\n zz = aux2(i1,1)*aux2(i1,2)\n zp = aux3(i1,1)*aux3(i1,2)\n\nc # transmitted part of down-going wave:\n a1 = (-asdq(i,1) + asdq(i,mv)*zz) /\n & (zm + zz)\n\nc # transmitted part of up-going wave:\n a2 = (asdq(i,1) + asdq(i,mv)*zz) /\n & (zz + zp)\nc\nc # The down-going flux difference bmasdq is the product -c * wave\nc\n bmasdq(i,1) = cm * a1*zm\n bmasdq(i,mu) = 0.d0\n bmasdq(i,mv) = -cm * a1\nc\nc # The up-going flux difference bpasdq is the product c * wave\nc\n bpasdq(i,1) = cp * a2*zp\n bpasdq(i,mu) = 0.d0\n bpasdq(i,mv) = cp * a2\nc\n 20 continue\nc\n return\n end\n", "meta": {"hexsha": "9bc466e17e752af24e18a7ffd0fbec5d659209a9", "size": 2703, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "applications/clawpack/acoustics/2d/rp/rpt2acv.f", "max_stars_repo_name": "scivision/forestclaw", "max_stars_repo_head_hexsha": "4dae847a8abd1055e70acda9c2973cd3dd77d3f1", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-09T23:06:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-09T23:06:42.000Z", "max_issues_repo_path": "applications/clawpack/acoustics/2d/rp/rpt2acv.f", "max_issues_repo_name": "scottaiton/forestclaw", "max_issues_repo_head_hexsha": "2abaab636e6e93f5507a6f231490144a3f805b59", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "applications/clawpack/acoustics/2d/rp/rpt2acv.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": 28.7553191489, "max_line_length": 78, "alphanum_fraction": 0.5519792823, "num_tokens": 924, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.911179705187943, "lm_q2_score": 0.760650658103136, "lm_q1q2_score": 0.6930894424014303}} {"text": "!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 1998 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Spherepack *\n! * *\n! * A Package of Fortran77 Subroutines and Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams and Paul Swarztrauber *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\n! a program testing subroutines shpgi and shpg\n!\n! shpg is the n**2 projection with complement, odd/even\n! factorization and zero truncation on a Gaussian distributed\n! grid. The projection is defined in the JCP paper \"Generalized\n! discrete spherical harmonic transforms\" by \n! Paul N. Swarztrauber and William F. Spotz\n! J. Comp. Phys., 159(2000) pp. 213-230.\n!\n! April 2002\n!\nprogram tshpg\n\n use, intrinsic :: ISO_Fortran_env, only: &\n stdout => OUTPUT_UNIT\n\n use spherepack\n\n ! Explicit typing only\n implicit none\n\n real(wp) :: discretization_error\n real(wp) :: g\n real(wp) :: ga\n real(wp) :: gb\n real(wp) :: gh\n integer(ip) :: i\n integer(ip) :: idimg\n integer(ip) :: idp\n integer(ip) :: ierror\n integer(ip) :: iprint\n integer(ip) :: isym\n integer(ip) :: iwshp\n integer(ip) :: j\n integer(ip) :: jdimg\n integer(ip) :: kdp\n integer(ip) :: liwshp\n integer(ip) :: lwork\n integer(ip) :: lwrk\n integer(ip) :: lwrk1\n integer(ip) :: lwsha\n integer(ip) :: lwshp\n integer(ip) :: lwshs\n integer(ip) :: mode\n integer(ip) :: mp1\n integer(ip) :: mtr\n integer(ip) :: mtrunc\n integer(ip) :: nlat\n integer(ip) :: nlon\n integer(ip) :: np1\n integer(ip) :: nt\n real(wp) :: sx\n real(wp) :: sy\n \n real(wp) :: toe\n real(wp) :: tusl\n real(wp) :: wrk1\n real(wp) :: wrk2\n real(wp) :: wshagc\n real(wp) :: wshp\n real(wp) :: wshsgc\n parameter (idp=8)\n parameter (kdp=idp+idp-2)\n parameter (lwshp=2*(idp+1)**2+kdp+20, &\n liwshp=4*(idp+1), lwrk=1.25*(idp+1)**2+7*idp+8)\n parameter (lwrk1=idp*kdp)\n parameter(lwork = 4*idp*(idp-1), &\n lwsha=idp*(4*idp+1)+idp+idp+15)\n real(wp), parameter :: ZERO = 0.0_wp\n real(wp) :: work(lwrk)\n dimension sx(idp, kdp), sy(idp, kdp), &\n wshp(lwshp), iwshp(liwshp), wrk1(lwrk1)\n dimension g(idp, kdp, 2), ga(idp, idp, 2), gb(idp, idp, 2), &\n gh(idp, kdp, 2), &\n wrk2(lwork), wshagc(lwsha), wshsgc(lwsha)\n \n iprint = 0\n nt = 1\n isym = 0\n mode = 0\n\n do nlat=6, 8\n do mtr=1, 2\n nlon = 2*(nlat-1)\n mtrunc = nlat-mtr\n mtrunc = min(mtrunc, nlat-1, nlon/2)\n idimg = idp\n jdimg = kdp\n call shagci(nlat, nlon, wshagc, ierror)\n call check_error(ierror)\n\n lwshs = lwsha\n call shsgci(nlat, nlon, wshsgc, ierror)\n call check_error(ierror)\n\n ! Initiate faster filter\n call shpgi(nlat, nlon, isym, mtrunc, wshp, lwshp, iwshp, liwshp, &\n work, lwrk, ierror)\n call check_error(ierror)\n\n if (iprint /= 0) write (stdout, '(3(a, i5))') &\n ' mode =' , nlon, ' nlat =', nlat, ' nlon =', nlon\n\n ! Initialize with pseudo random field\n do i=1, nlat\n do j=1, nlon\n sx(i, j) = cos(real(i*j, kind=wp))\n g(i, j, 1) = sx(i, j)\n end do\n end do\n\n call shagc(nlat, nlon, mode, nt, g, idimg, jdimg, ga, gb, idimg, idimg, &\n wshagc, ierror)\n call check_error(ierror)\n\n if(mtrunc < nlat-1) then\n do np1=mtrunc+2, nlat\n do mp1=1, np1\n ga(mp1, np1, 1) = ZERO\n gb(mp1, np1, 1) = ZERO\n end do\n end do\n end if\n\n call shsgc(nlat, nlon, mode, nt, gh, idimg, jdimg, ga, gb, idimg, idimg, wshsgc, ierror)\n call check_error(ierror)\n\n call shpg(nlat, nlon, isym, mtrunc, sx, sy, idp, &\n wshp, lwshp, iwshp, liwshp, wrk1, lwrk1, ierror)\n call check_error(ierror)\n\n if (iprint > 0) write (stdout, '(/a/)') ' approx and exact solution'\n\n do j=1, nlon\n if(iprint > 0) write (stdout, 437) j, (sy(i, j), gh(i, j, 1), i=1, nlat)\n437 format(' j=', i5, 1p4e15.6/(8x, 1p4e15.6))\n end do\n\n discretization_error = maxval(abs(sy(:nlat, :nlon)-gh(:nlat, :nlon, 1)))\n\n write (stdout, '(/2(a, i5)/)') &\n 'case nlat =', nlat, ' and mtrunc =', mtrunc\n\n write (stdout, '(3(a, 1pe15.6/))') &\n ' error =', discretization_error, &\n ' tusl =', tusl, &\n ' toe =', toe\n end do\n end do\nend program tshpg\n\n", "meta": {"hexsha": "215d13d5d542a4cf350f2509cfda29f2632c155a", "size": 6582, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/tshpg.f90", "max_stars_repo_name": "jlokimlin/spherepack4.1", "max_stars_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-06-28T14:01:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T21:59:28.000Z", "max_issues_repo_path": "test/tshpg.f90", "max_issues_repo_name": "jlokimlin/spherepack4.1", "max_issues_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2016-05-07T23:00:35.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-22T23:52:30.000Z", "max_forks_repo_path": "test/tshpg.f90", "max_forks_repo_name": "jlokimlin/spherepack4.1", "max_forks_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-06-28T14:03:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T12:53:54.000Z", "avg_line_length": 35.9672131148, "max_line_length": 100, "alphanum_fraction": 0.3884837435, "num_tokens": 1839, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797003640646, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6930894288442995}} {"text": "***************************************************************************\n\n! CHIME model\n! Simulates Susceptible, Infected, Recovered Population by taking into\n! account SIR model parameters as long as hospitalization parameters and\n! policy initiatives\n\n****************************************************************************\n! Policy Module\n\n! State Variables:\n! beta Rate of transmission via contact\n! num_days Number of days over which a certain policy is active\n**************************************************************************** \n module PolicyMod\n implicit none\n type Policy \n real beta \n integer num_days \n \n end type Policy\n end module PolicyMod\n\n*****************************************************************************\n! Subroutine to calculate beta of SIR model from intrinsic growth rate,\n! gamma (1/infectious days), relative contact rate (social distancing\n! parameter)\n!\n! Input Variables:\n! intrinsic_growth_rate Rate at which rate of infection is growing \n! gamma Rate of recovery from infection\n! susceptible Size of Susceptible Population\n! relative_contact_rate Contact rate between members of susceptible and infected groups\n! \n! Local Variables:\n! inv_contact_rate Complement of relative_contact_rate\n! updated_growth_rate modified growth rate\n!\n! Output Variable:\n! beta Rate of transmission via contact\n*****************************************************************************\n subroutine get_beta(intrinsic_growth_rate, gamma, \n & susceptible, relative_contact_rate, \n & beta) \n real intrinsic_growth_rate, susceptible\n & relative_contact_rate, gamma\n real inv_contact_rate, updated_growth_rate\n real beta\n\n inv_contact_rate = 1.0 - relative_contact_rate\n updated_growth_rate = intrinsic_growth_rate + gamma\n beta = updated_growth_rate / susceptible * inv_contact_rate\n\n end subroutine get_beta\n\n*****************************************************************************\n! Subroutine to calculate intrinsic growth rate necessary for\n! calculating beta from doubling time (doubling_time) as the input\n! parameter\n!\n! Input Variable:\n! doubling_time Time taken for the number of infected people to double \n! \n! Output Variable:\n! growth_rate Intrinsic growth rate \n****************************************************************************\n\n subroutine get_growth_rate(doubling_time, \n & growth_rate) \n\n real doubling_time\n real growth_rate\n\n if (doubling_time .eq. 0.0) then\n growth_rate = 0.0\n else\n growth_rate = 2.0 ** (1.0 / doubling_time) - 1.0\n endif\n\n end subroutine get_growth_rate\n\n\n*****************************************************************************\n! Subroutine to calculate susceptible (s), infected (i), and recovered (r)\n! group of people in one day. The populations are normaized based\n! on a scaling factor (scale) from beta, gamma parameters \n!\n! Input Variables:\n! beta Rate of transmission via contact\n! gamma Rate of recovery from infection\n! n Total number of members (s+i+r)\n! s Amount of susceptble members at previous timestep\n! i Amount of infected members at previous timestep\n! r Amount of recovered members at current timestep\n!\n! State Variables:\n! s_n Amount of susceptible members at current timestep\n! i_n Amount of infected members at current timestep\n! r_n Amount of recovered members at current timestep\n! scale scaling factor\n*****************************************************************************\n\n subroutine sir(beta, gamma, n, \n & s, i, r) \n\n real beta, gamma, n\n real s, i, r\n real s_n, i_n, r_n, scale\n\n ! Calculate current day's susceptible (s_n), infected (i_n),\n ! recovered (r_n) populations from previous day's populations\n ! using SIR model\n s_n = (-beta * s * i) + s\n i_n = (beta * s * i - gamma * i) + i\n r_n = gamma * i + r\n\n ! Calculate scaling factor\n scale = n / (s_n + i_n + r_n)\n\n ! Scale s, i, r populations\n s = s_n * scale\n i = i_n * scale\n r = r_n * scale\n\n end subroutine sir\n\n*****************************************************************************\n! Subroutine to simulate susceptible (s), infected (i), and recovered (r)\n! group of people over the total number of days spanning over all policies\n! \n! Input Variables:\n! s_n Amount of susceptible members at current timestep\n! i_n Amount of infected members at current timestep\n! r_n Amount of recovered members at current timestep\n! gamma Rate of recovery from infection\n! i_day Index of day beyond which SIR model is simulated \n! N_p Number of policies\n! N_t Total number of days over which policies are active\n! policy list of policies containing both beta and number of days over\n! which a particular policy is active\n!\n! Local Variables:\n! n Total population\n! beta Rate of transmission via contact\n! N_d Number of days in each policy\n! d Day Index\n! idx Counter over arrays\n! p_idx Counter over policies\n! d_idx Counter over N_d\n! \n! Output Variables:\n! T Array for storing indices of total number of days\n! S Array for storing amount of susceptible members on a particular day\n! over all sets of policies\n! I Array for storing amount of infected members on a particular day\n! over all sets of policies\n! R Array for storing amount of recovered members on a particular day\n! over all sets of policies\n! E Arrau for storing amount of members to have ever been infected on a\n! particular day over all policies\n*****************************************************************************\n subroutine sim_sir(s_n, i_n, r_n, gamma, i_day, N_p, \n & N_t, policies, \n & T, S, E, I, R) \n use PolicyMod\n\n real s_n, i_n, r_n, gamma\n integer i_day, N_p, N_t\n type (Policy) policies(N_p)\n real n, beta\n integer d, idx, p_idx, d_idx, N_d\n integer T(N_t+1)\n real S(N_t+1), E(N_t+1), I(N_t+1), R(N_t+1)\n\n n = s_n + i_n + r_n\n d = i_day\n\n idx = 1\n do p_idx = 1, N_p\n beta = policies(p_idx) % beta\n N_d = policies(p_idx) % num_days\n do d_idx = 1, N_d\n T(idx) = d\n S(idx) = s_n\n I(idx) = i_n\n R(idx) = r_n\n E(idx) = i_n + r_n\n idx = idx + 1\n call sir(beta, gamma, n, s_n, i_n, r_n)\n d = d + 1\n enddo\n enddo\n\n T(idx) = d\n S(idx) = s_n\n I(idx) = i_n\n R(idx) = r_n\n E(idx) = i_n + r_n\n\n end subroutine sim_sir\n\n\n program main\n use PolicyMod\n implicit none\n real s_n, i_n, r_n, beta, doubling_time, growth_rate\n integer p_idx\n integer, parameter :: i_day = 0, n_days = 20\n integer, parameter :: N_p = 2, infectious_days = 14\n real, parameter :: relative_contact_rate = 0.05\n real, parameter :: gamma = 1.0 / infectious_days\n type (Policy), dimension(1:N_p) :: policies\n integer N_t\n integer, dimension(:), allocatable :: T\n real, dimension(:), allocatable :: S, E, I, R\n\n s_n = 1000\n i_n = 0\n r_n = 0\n\n N_t = 0\n do p_idx = 1, N_p\n doubling_time = p_idx * 5.0\n call get_growth_rate(doubling_time, growth_rate)\n call get_beta(growth_rate, gamma, s_n,\n & relative_contact_rate, beta)\n policies(p_idx) % beta = beta\n policies(p_idx) % num_days = n_days * p_idx\n N_t = N_t + policies(p_idx) % num_days\n end do\n\n allocate(T(N_t+1)); allocate(S(N_t+1)); allocate(E(N_t+1));\n allocate(I(N_t+1)); allocate(R(N_t+1));\n\n call sim_sir(s_n, i_n, r_n, gamma, i_day, N_p, N_t, policies,\n & T, S, E, I, R)\n end program main\n", "meta": {"hexsha": "8143b2ed45de6e5e6ef074ad0dda2086e7c90ca2", "size": 9148, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "tests/data/model_analysis/CHIME.for", "max_stars_repo_name": "rsulli55/automates", "max_stars_repo_head_hexsha": "1647a8eef85c4f03086a10fa72db3b547f1a0455", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2018-12-19T16:32:38.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-05T07:58:15.000Z", "max_issues_repo_path": "tests/data/model_analysis/CHIME.for", "max_issues_repo_name": "rsulli55/automates", "max_issues_repo_head_hexsha": "1647a8eef85c4f03086a10fa72db3b547f1a0455", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 183, "max_issues_repo_issues_event_min_datetime": "2018-12-20T17:03:01.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-23T22:21:42.000Z", "max_forks_repo_path": "tests/data/model_analysis/CHIME.for", "max_forks_repo_name": "rsulli55/automates", "max_forks_repo_head_hexsha": "1647a8eef85c4f03086a10fa72db3b547f1a0455", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-01-04T22:37:49.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T17:34:16.000Z", "avg_line_length": 38.4369747899, "max_line_length": 97, "alphanum_fraction": 0.4996720595, "num_tokens": 1994, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894604912848, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6930890530785749}} {"text": "c Version 1.3.2\nc----------------------------------------------------------------------\nc =========================\nc subroutine GCONVL\nc =========================\nc\nc Convolute given real-valued spectrum with a Gaussian lineshape \nc having a specified derivative peak-to-peak linewidth.\nc\nc NOTE: this differs from EPRLL version, which transforms a\nc complex-valued spectrum. \nc\nc----------------------------------------------------------------------\n subroutine gconvl( spectr,wline,dfld,nfld,nft, tmpdat)\n!f2py intent(in) spectr\n!f2py intent(in) wline\n!f2py intent(in) dfld\n!f2py intent(in) nfld\n!f2py intent(in) nft\n!f2py intent(out) tmpdat\n\n implicit none\nc\n integer nfld,nft\nc\n integer i,k,no2\n double precision df,f,g,gnorm\nc\nc include 'nlsdim.inc'\nc include 'ftwork.inc'\nc include 'pidef.inc'\nc\n double precision EIGHT,EPS,ONE,TWO,THIRD,ZERO\n double precision PI,RADIAN\n integer MXPT\n parameter ( EIGHT=8.0D0,ONE=1.0D0,TWO=2.0D0,ZERO=0.0D0,\n # EPS=1.0D-6,THIRD=0.33333333333333D0 )\n parameter (PI=3.1415926535897932384D0,RADIAN=PI/180.0D0)\n parameter (MXPT=4096)\n double precision tmpdat(MXPT)\n double precision spectr(MXPT),wline,dfld\nc\nc######################################################################\nc\n if (wline.lt.EPS) return\nc\nc -----------------------------------------------\nc Store calculation in tmpdat, zero-pad, and FFT\nc -----------------------------------------------\n do i=1,nfld\n tmpdat(i)=spectr(i)\n end do\nc\n do i=nfld+1,nft\n tmpdat(i)=ZERO\n end do\nc\n no2=nft/2\n call realft( tmpdat,no2,+1 )\nc\nc ------------------------------------------------------------\nc Convolute with Gaussian function by multiplying in\nc with a Gaussian in Fourier space.\nc\nc NOTE: REALFT returns only the positive frequencies\nc since FT of a real function is symmetric. Also, the\nc first and last elements of the FT array are real-valued\nc and returned as the real and imaginary parts of tmpdat(1)\nc ------------------------------------------------------------\n df=TWO*PI/(nft*dfld)\n gnorm=ONE/dfloat(no2)\n tmpdat(1)=tmpdat(1)*gnorm\n tmpdat(2)=tmpdat(2)*gnorm*dexp(-(no2*df*wline)**2/EIGHT)\n f=df\n do i=3,nft,2\n g=gnorm*dexp( -(f*wline)**2/EIGHT )\n tmpdat(i)=tmpdat(i)*g\n tmpdat(i+1)=tmpdat(i+1)*g\n f=f+df\n end do\nc\nc ------------------------------------------------------------\nc Back-transfor to obtain convoluted spectrum and restore in\nc spectr array\nc ------------------------------------------------------------\n call realft( tmpdat,no2,-1 )\nc no need, as tmpdat is my output now \nc do i=1,nfld\nc spectr(i)=tmpdat(i)\nc end do\nc\n return\n end\n\n\n subroutine realft(data,n,isign)\n implicit none\n integer i,i1,i2,i3,i4,isign,n,n2p3\n double precision c1,c2,h1r,h1i,h2r,h2i,wrs,wis,wr,wi,wpr,wpi,\n # wtemp,theta\n double precision data(2*n)\nc\n theta=6.28318530717959d0/2.0d0/dble(n)\n c1=0.5d0\n if (isign.eq.1) then\n c2=-0.5d0\n call four1(data,n,+1)\n else\n c2=0.5d0\n theta=-theta\n endif\n wpr=-2.0d0*dsin(0.5d0*theta)**2\n wpi=dsin(theta)\n wr=1.d0+wpr\n wi=wpi\n n2p3=2*n+3\n do 11 i=2,n/2+1\n i1=2*i-1\n i2=i1+1\n i3=n2p3-i2\n i4=i3+1\n wrs=sngl(wr)\n wis=sngl(wi)\n h1r=c1*(data(i1)+data(i3))\n h1i=c1*(data(i2)-data(i4))\n h2r=-c2*(data(i2)+data(i4))\n h2i=c2*(data(i1)-data(i3))\n data(i1)=h1r+wrs*h2r-wis*h2i\n data(i2)=h1i+wrs*h2i+wis*h2r\n data(i3)=h1r-wrs*h2r+wis*h2i\n data(i4)=-h1i+wrs*h2i+wis*h2r\n wtemp=wr\n wr=wr*wpr-wi*wpi+wr\n wi=wi*wpr+wtemp*wpi+wi\n11 continue\n if (isign.eq.1) then\n h1r=data(1)\n data(1)=h1r+data(2)\n data(2)=h1r-data(2)\n else\n h1r=data(1)\n data(1)=c1*(h1r+data(2))\n data(2)=c1*(h1r-data(2))\n call four1(data,n,-1)\n endif\n return\n end\n\n subroutine four1(data,nn,isign)\n implicit none\n integer i,istep,j,m,mmax,n,nn,isign\n double precision wr,wi,wpr,wpi,wtemp,tempi,tempr,theta\n double precision data(2*nn)\nc\n n=2*nn\n j=1\n do 11 i=1,n,2\n if(j.gt.i)then\n tempr=data(j)\n tempi=data(j+1)\n data(j)=data(i)\n data(j+1)=data(i+1)\n data(i)=tempr\n data(i+1)=tempi\n endif\n m=n/2\n1 if ((m.ge.2).and.(j.gt.m)) then\n j=j-m\n m=m/2\n go to 1\n endif\n j=j+m\n11 continue\n mmax=2\n2 if (n.gt.mmax) then\n istep=2*mmax\n theta=6.28318530717959d0/(isign*mmax)\n wpr=-2.d0*dsin(0.5d0*theta)**2\n wpi=dsin(theta)\n wr=1.d0\n wi=0.d0\n do 13 m=1,mmax,2\n do 12 i=m,n,istep\n j=i+mmax\n tempr=sngl(wr)*data(j)-sngl(wi)*data(j+1)\n tempi=sngl(wr)*data(j+1)+sngl(wi)*data(j)\n data(j)=data(i)-tempr\n data(j+1)=data(i+1)-tempi\n data(i)=data(i)+tempr\n data(i+1)=data(i+1)+tempi\n12 continue\n wtemp=wr\n wr=wr*wpr-wi*wpi+wr\n wi=wi*wpr+wtemp*wpi+wi\n13 continue\n mmax=istep\n go to 2\n endif\n return\n end\n\n\n", "meta": {"hexsha": "d3992b195efca31a0417c5f57d586ec743cae2d5", "size": 5557, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "lsld2/fit/gconvl.f", "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/fit/gconvl.f", "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/fit/gconvl.f", "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.3743842365, "max_line_length": 71, "alphanum_fraction": 0.4900125967, "num_tokens": 1828, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894520743981, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.6930890512151239}} {"text": "module local_routines \n !!\n !! Simulate wave motion in a paraboloid bowl, which has an analytical solution \n !!\n use global_mod, only: dp, ip\n use domain_mod, only: domain_type, STG, UH, VH, ELV\n use read_raster_mod, only: multi_raster_type\n use logging_mod, only: log_output_unit\n implicit none\n\n contains \n\n subroutine set_initial_conditions_paraboloid_bowl(domain) \n class(domain_type), target, intent(inout):: domain\n integer(ip):: i, j\n real(dp) :: x, y, L, D, r0, r, A\n\n r0 = 2000.0_dp\n L = 2500.0_dp\n D = 1000.0_dp\n A = (L**4 - r0**4)/(r0**4 + L**4)\n\n ! Set stage and elevation \n ! This saves memory compared to doing it all at once.\n do j = 1, domain%nx(2)\n y = domain%y(j)\n do i = 1, domain%nx(1)\n x = domain%x(i)\n\n r = sqrt(x*x + y*y)\n ! Bed elevation\n domain%U(i,j,ELV) = D*(r*r/(L*L) - 1.0_dp)\n ! Stage\n domain%U(i,j,STG) = D*( & \n (sqrt(1.0_dp-A*A))/(1.0_dp - A) & \n -1.0_dp - r*r/(L*L)*((1.0_dp - A*A)/((1.0_dp - A)**2) - 1.0_dp) &\n )\n end do\n end do\n\n ! Ensure stage >= elevation\n domain%U(:,:,STG) = max(domain%U(:,:,STG), domain%U(:,:,ELV) + 1.0e-07_dp)\n\n write(log_output_unit,*) 'Stage range is: ', minval(domain%U(:,:,STG)), maxval(domain%U(:,:,STG))\n write(log_output_unit,*) 'Elev range is: ', minval(domain%U(:,:,ELV)), maxval(domain%U(:,:,ELV))\n\n if(domain%timestepping_method == 'cliffs') then\n domain%cliffs_minimum_allowed_depth = 5_dp\n end if\n\n end subroutine\n\nend module \n\n!@!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\nprogram run_paraboloid_basin\n !!\n !! Simulate wave motion in a paraboloid bowl, which has an analytical solution \n !!\n\n use global_mod, only: ip, dp, default_nonlinear_timestepping_method\n use domain_mod, only: domain_type\n use multidomain_mod, only: multidomain_type\n use timer_mod, only: timer_type\n use logging_mod, only: log_output_unit, send_log_output_to_file\n use stop_mod, only: generic_stop\n#ifdef COARRAY_PROVIDE_CO_ROUTINES\n use coarray_intrinsic_alternatives, only: co_min\n#endif\n use coarray_intrinsic_alternatives, only: swals_mpi_init, swals_mpi_finalize\n use local_routines\n\n implicit none\n\n ! Type holding all domains \n type(multidomain_type) :: md\n\n ! Local timing object\n type(timer_type) :: program_timer\n\n ! Change this to decrease the cell size by mesh_refine (i.e. for convergence testing)\n integer(ip), parameter :: mesh_refine = 4_ip\n\n ! The global (i.e. outer-domain) time-step in the multidomain \n real(dp) :: global_dt ! = (0.23_dp/mesh_refine) * 1.0_dp\n\n ! Approx timestep between outputs\n real(dp) :: approximate_writeout_frequency = 1.0_dp\n real(dp) :: final_time = 300.0_dp * 1.0_dp\n\n ! Length/width\n real(dp), parameter, dimension(2):: global_lw = 8000.0_dp * [1.0_dp, 1.0_dp]\n ! Lower-left corner coordinate\n real(dp), parameter, dimension(2):: global_ll = -global_lw/2.0_dp\n ! grid size (number of x/y cells)\n integer(ip), parameter, dimension(2):: global_nx = [100, 100]*mesh_refine + 1\n\n ! Useful misc variables\n integer(ip):: nd, j\n\n call swals_mpi_init\n call program_timer%timer_start('setup')\n\n#ifdef SPHERICAL\n write(log_output_unit,*) 'Code assumes cartesian oordinates, but SPHERICAL is defined'\n call generic_stop\n#endif\n \n ! nd domains in this model\n nd = 1\n allocate(md%domains(nd))\n\n !\n ! Setup basic metadata\n !\n\n ! Linear domain\n md%domains(1)%lw = global_lw\n md%domains(1)%lower_left =global_ll\n md%domains(1)%nx = global_nx\n md%domains(1)%dx = md%domains(1)%lw/md%domains(1)%nx\n md%domains(1)%dx_refinement_factor = 1.0_dp\n md%domains(1)%timestepping_refinement_factor = 1_ip\n md%domains(1)%timestepping_method = default_nonlinear_timestepping_method \n\n !@ Splitting the domain the same way, irrespective of np, improves reproducibility\n ! md%load_balance_file = 'load_balance_partition.txt'\n call get_command_argument(1, md%load_balance_file)\n\n ! Allocate domains and prepare comms\n call md%setup(extra_halo_buffer=0_ip)\n\n ! Set initial conditions\n do j = 1, size(md%domains)\n call set_initial_conditions_paraboloid_bowl(md%domains(j))\n end do\n call md%make_initial_conditions_consistent()\n \n ! NOTE: For stability in 'null' regions, we set them to 'high land' that\n ! should be inactive. \n call md%set_null_regions_to_dry()\n \n write(log_output_unit,*) 'End setup'\n\n ! Print the gravity-wave CFL limit, to guide timestepping\n do j = 1, size(md%domains)\n write(log_output_unit,*) 'domain: ', j, 'ts: ', &\n md%domains(j)%stationary_timestep_max()\n end do\n global_dt = md%stationary_timestep_max()\n\n call program_timer%timer_end('setup')\n call program_timer%timer_start('evolve')\n\n#ifdef COARRAY\n ! Get the minimum global_dt\n call co_min(global_dt)\n#endif\n flush(log_output_unit)\n\n ! The water will rise (and fall) in the deepest area so we need a timestep \n ! somewhat smaller than the initial stationary timestep. From experience \n ! this timestep is stable\n global_dt = 0.71_dp * global_dt * md%domains(1)%cfl ! * 1.0_dp/3.0_dp\n\n !\n ! Evolve the code\n !\n\n do while (.true.)\n \n ! IO \n call program_timer%timer_start('IO')\n call md%write_outputs_and_print_statistics(&\n approximate_writeout_frequency = approximate_writeout_frequency)\n call program_timer%timer_end('IO')\n\n call md%evolve_one_step(global_dt)\n\n if (md%domains(1)%time > final_time) exit\n end do\n\n call program_timer%timer_end('evolve')\n call md%finalise_and_print_timers\n\n write(log_output_unit,*) ''\n write(log_output_unit, *) 'Program timer'\n write(log_output_unit, *) ''\n call program_timer%print(log_output_unit)\n call swals_mpi_finalize\nend program\n", "meta": {"hexsha": "a8ee04d1dfb0a2a207eec51777abdddbffd52431", "size": 6163, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "propagation/SWALS/examples/paraboloid_bowl/paraboloid_bowl.f90", "max_stars_repo_name": "KayaGeoAus/ptha", "max_stars_repo_head_hexsha": "183c956506f35930437fa37d24d5b49abbb94284", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2017-03-28T02:33:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-10T01:11:24.000Z", "max_issues_repo_path": "propagation/SWALS/examples/paraboloid_bowl/paraboloid_bowl.f90", "max_issues_repo_name": "KayaGeoAus/ptha", "max_issues_repo_head_hexsha": "183c956506f35930437fa37d24d5b49abbb94284", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2021-11-15T22:44:38.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-02T06:04:18.000Z", "max_forks_repo_path": "propagation/SWALS/examples/paraboloid_bowl/paraboloid_bowl.f90", "max_forks_repo_name": "KayaGeoAus/ptha", "max_forks_repo_head_hexsha": "183c956506f35930437fa37d24d5b49abbb94284", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-11-08T21:22:37.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-07T11:36:39.000Z", "avg_line_length": 31.932642487, "max_line_length": 105, "alphanum_fraction": 0.6354048353, "num_tokens": 1731, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894548800269, "lm_q2_score": 0.7745833841649232, "lm_q1q2_score": 0.6930890440760581}} {"text": " Program zstedc_example\n\n! ZSTEDC Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use blas_interfaces, Only: dznrm2\n Use lapack_example_aux, Only: nagf_file_print_matrix_complex_gen_comp\n Use lapack_interfaces, Only: zhbtrd, zstedc\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nin = 5, nout = 6\n Character (1), Parameter :: uplo = 'U'\n! .. Local Scalars ..\n Complex (Kind=dp) :: scal\n Integer :: i, ifail, info, j, k, kd, ldab, ldz, lgn, liwork, lrwork, &\n lwork, n\n! .. Local Arrays ..\n Complex (Kind=dp), Allocatable :: ab(:, :), work(:), z(:, :)\n Complex (Kind=dp) :: cdum(1)\n Real (Kind=dp), Allocatable :: d(:), e(:), rwork(:)\n Real (Kind=dp) :: rdum(1)\n Integer :: idum(1)\n Integer, Allocatable :: iwork(:)\n Character (1) :: clabs(1), rlabs(1)\n! .. Intrinsic Procedures ..\n Intrinsic :: abs, ceiling, conjg, log, max, maxloc, min, nint, real\n! .. Executable Statements ..\n Write (nout, *) 'ZSTEDC Example Program Results'\n Write (nout, *)\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n, kd\n ldab = kd + 1\n ldz = n\n lgn = ceiling(log(real(n,kind=dp))/log(2.0_dp))\n Allocate (ab(ldab,n), z(ldz,n), d(n), e(n-1))\n\n! Use routine workspace query to get optimal workspace.\n lwork = -1\n lrwork = -1\n liwork = -1\n Call zstedc('V', n, d, e, z, ldz, cdum, lwork, rdum, lrwork, idum, &\n liwork, info)\n\n! Make sure that there is enough workspace.\n lwork = max(n*n, nint(real(cdum(1))))\n lrwork = max(1+3*n+2*n*lgn+4*n*n, nint(rdum(1)))\n liwork = max(6+6*n+5*n*lgn, idum(1))\n Allocate (work(lwork), rwork(lrwork), iwork(liwork))\n\n! Read the upper or lower triangular part of the band matrix A\n! from data file\n\n If (uplo=='U') Then\n Do i = 1, n\n Read (nin, *)(ab(kd+1+i-j,j), j=i, min(n,i+kd))\n End Do\n Else If (uplo=='L') Then\n Do i = 1, n\n Read (nin, *)(ab(1+i-j,j), j=max(1,i-kd), i)\n End Do\n End If\n\n! Reduce A to tridiagonal form T = (Z**T)*A*Z, and form Z\n\n Call zhbtrd('V', uplo, n, kd, ab, ldab, d, e, z, ldz, work, info)\n\n! Calculate all the eigenvalues and eigenvectors of A,\n! from T and Z\n\n Call zstedc('V', n, d, e, z, ldz, work, lwork, rwork, lrwork, iwork, &\n liwork, info)\n\n If (info==0) Then\n\n! Print eigenvalues and eigenvectors\n\n Write (nout, *) 'Eigenvalues'\n Write (nout, 100) d(1:n)\n\n Write (nout, *)\n Flush (nout)\n\n! Normalize the eigenvectors, largest element real\n Do i = 1, n\n rwork(1:n) = abs(z(1:n,i))\n k = maxloc(rwork(1:n), 1)\n scal = conjg(z(k,i))/abs(z(k,i))/dznrm2(n, z(1,i), 1)\n z(1:n, i) = z(1:n, i)*scal\n End Do\n\n! ifail: behaviour on error exit\n! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft\n ifail = 0\n Call nagf_file_print_matrix_complex_gen_comp('General', ' ', n, n, z, &\n ldz, 'Bracketed', 'F7.4', 'Eigenvectors', 'Integer', rlabs, &\n 'Integer', clabs, 80, 0, ifail)\n\n Else\n Write (nout, 110) 'Failure in ZSTEDC. INFO = ', info\n End If\n\n100 Format (4X, F8.4, 3(10X,F8.4))\n110 Format (1X, A, I10)\n End Program\n", "meta": {"hexsha": "4241407e9789011b01d7e472bbfe3a801cc184e4", "size": 3614, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/zstedc_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/zstedc_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/zstedc_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 32.2678571429, "max_line_length": 90, "alphanum_fraction": 0.552573326, "num_tokens": 1208, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789452074398, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.6930890372467349}} {"text": "SUBROUTINE beta_pred (mjd, r_sat, v_sat, fti, ft0, beta)\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! SUBROUTINE: beta_pred.f90\r\n! ----------------------------------------------------------------------\r\n! Purpose:\r\n! Computation of the beta angle (Sun elevation angle w.r.t. orbtial plane) at a previous of future epoch\r\n! based on the Keplerian elements for the satellite orbit propagation and the DE Ephemeris for the Sun position\r\n! ----------------------------------------------------------------------\r\n! Input arguments:\r\n! - mjd:\t\tModified Julian Day number in GPS Time (including the fraction of the day)\r\n! - r_sat: \t\tSatellite position vector (m) in ITRF\r\n! - v_sat: \t\tSatellite velocity vector (m/sec) in ITRF\r\n! - fti:\t\tOrbit angle (degrees) at the input epoch ti \r\n! - ft0:\t\tOrbit angle (degrees) at the required epoch t0 (forward or backward)\r\n!\r\n! Output arguments:\r\n! - beta:\t\tSun elevation angle with respect to the orbital plane at the epoch t0 (degrees) \r\n! ----------------------------------------------------------------------\r\n! Note 1:\r\n! - kepler:\t\tKepler elements array (6)\r\n! a: \tsemi-major axis (m)\r\n! e: \teccentricity\r\n! i: \tinclination (degrees)\r\n! Omega: \tright ascension of the ascending node (degrees)\r\n! omega: \targument of perigee (degrees)\r\n! E: \teccentric anomaly (degrees)\r\n! ----------------------------------------------------------------------\r\n! Dr. Thomas Papanikolaou, Geoscience Australia 8 June 2017\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n USE mdl_precision\r\n USE mdl_num\r\n USE mdl_planets\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) :: mjd, r_sat(3), v_sat(3)\r\n REAL (KIND = prec_q), INTENT(IN) :: fti, ft0\r\n! OUT\r\n REAL (KIND = prec_d), INTENT(OUT) :: beta\r\n! ----------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n! Local variables declaration\r\n! ----------------------------------------------------------------------\r\n REAL (KIND = prec_q) :: ti, t0, frate\r\n REAL (KIND = prec_q) :: mjd_t0 , mjd_TT, mjd_GPS, mjd_TAI, mjd_UTC\r\n INTEGER (KIND = prec_int8) :: Norb, i, sz1, sz2\r\n REAL (KIND = prec_q) :: GM, kepler_i(9), kepler_0(6), a_semiaxis, ec, n_motion, Ei_rad, Mi_rad, Mo_rad, Mo_deg, Eo_deg\r\n REAL (KIND = prec_q) :: dt\r\n REAL (KIND = prec_q), DIMENSION(3) :: rsat_t0, vsat_t0\r\n! ----------------------------------------------------------------------\r\n! Planetary/Lunar Epehemeris data processing (lib3_planets): Variables declaration\r\n DOUBLE PRECISION JD_TT, R_eph(6)\r\n INTEGER NTARG, NCTR\r\n! CHARACTER (LEN=100) :: fname_header, fname_data, fname_out\r\n REAL (KIND = prec_d) :: rsun_t0(3)\r\n! ----------------------------------------------------------------------\r\n INTEGER (KIND = prec_int8) :: NPint\r\n\r\n\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! Current epoch in seconds since start of the day (0h)\r\nti = (mjd - INT(mjd)) * 86400.D0 \r\n! ----------------------------------------------------------------------\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! Computation of the forward/backward epoch t0\r\n! ----------------------------------------------------------------------\r\n! Orbital angle rate (in degrees/sec)\r\nfrate = sqrt( (v_sat(1)**2+v_sat(2)**2+v_sat(3)**2) / (r_sat(1)**2+r_sat(2)**2+r_sat(3)**2) ) * (180.0D0 / PI_global)\r\n\r\nt0 = ti + (ft0 - fti)/ frate\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! Computation of the satellite position and velocity vectors at epoch t0\r\n! through Keplerian orbit consideration\r\n! ----------------------------------------------------------------------\r\n! Gravitational constant\r\nGM = 0.39860044150D+15\r\n\r\n! Kepler elements at ti\r\nCALL kepler_z2k (r_sat, v_sat, GM, kepler_i)\r\n\r\na_semiaxis = kepler_i(1)\r\nec = kepler_i(2)\r\n\r\n! Eccentric anomaly at ti (radians)\r\nEi_rad = kepler_i(7) * (PI_global / 180.D0)\r\n\r\n! Mean anomaly at ti (radians)\r\nMi_rad = Ei_rad - ec * sin(Ei_rad)\r\n\r\n! mean motion (rad/sec)\r\nn_motion = sqrt(GM / a_semiaxis**3)\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! Time difference since current epoch\r\ndt = t0 - ti\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! Mean anomaly (radians) at epoch t0 \r\nMo_rad = Mi_rad + n_motion * dt\r\n\r\n! Mean anomaly (in degrees) at epoch t0\r\nMo_deg = Mo_rad * (180.D0/PI_global)\r\n\r\n! Angle reduction within the range {0 - 360} degrees\r\nIf (abs(Mo_deg) >= 360.D0) then\r\n\tMo_deg = Mo_deg - INT(Mo_deg / 360.D0) * 360.D0\r\nEnd If\r\n\r\nif (Mo_deg < 0.0D0) then\r\n Mo_deg = Mo_deg + 360.D0\r\nend if\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n! Kepler Equation \r\n! Eccentric anomaly (degrees) at epoch t0 obtained by solving Kepler's Equation\r\nCALL kepler_eq ( Mo_deg , ec , Eo_deg)\r\n\r\n! Kepler elements at epoch t0\r\n!kepler_0 = (/ a, e, i, Omega_asc, omega_per, Eo_deg /)\r\nkepler_0 = (/ kepler_i(1), kepler_i(2), kepler_i(3), kepler_i(4), kepler_i(5), Eo_deg /)\r\n\r\n! State vector (Cartesian coordinates) at epoch t0\r\nCALL kepler_k2z (kepler_0, GM, rsat_t0, vsat_t0) \r\n! ----------------------------------------------------------------------\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! Sun position vector at reference epoch t0\r\n! ----------------------------------------------------------------------\r\n! Center celestial body : Earth\r\n NCTR = 3 \r\n! Target celestial body : Sun\r\n NTARG = 11 \r\n\t \r\n! Time System transformation: GPS to TT\r\nmjd_t0 = mjd + dt/86400.0D0\t\t\r\nCALL time_GPS (mjd_t0 , mjd_TT, mjd_GPS, mjd_TAI, mjd_UTC)\r\n\r\n! JD at the epoch t0 (in TT)\r\n JD_TT = mjd_TT + 2400000.5D0\r\n\r\n! Sun state vector in ICRF (in KM)\r\n CALL PLEPH ( JD_TT, NTARG, NCTR, R_eph )\r\n\r\n\t ! Km to meters\r\n\t rsun_t0(1) = R_eph(1) * 1000D0\r\n\t rsun_t0(2) = R_eph(2) * 1000D0\r\n\t rsun_t0(3) = R_eph(3) * 1000D0\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! Sun elevation angle at epoch t0\r\n! ----------------------------------------------------------------------\r\n! Beta angle (in degrees)\r\n CALL beta_angle (rsat_t0, vsat_t0, rsun_t0, beta)\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n\r\nif (1<0) then\r\nPRINT *, \"fti,ft0,frate\", fti, ft0, frate\r\nPRINT *, \"ti, t0, dt\", ti, t0, dt\r\nPRINT *, \"kepler_i\", kepler_i\r\nPRINT *, \"kepler_0\", kepler_0\r\n!PRINT *, \"Mi_deg\", Mi_rad*(180.D0/PI_global)\r\n!PRINT *, \"Mo_deg\", Mo_deg\r\nPRINT *, \"frate \", frate\r\nPRINT *, \"n_motion \", n_motion * (180.0D0 / PI_global)\r\n\r\nPRINT *, \"beta\", beta\r\nPRINT *, \"rsat_t0\", rsat_t0\r\nPRINT *, \"vsat_t0\", vsat_t0\r\nend if\r\n\r\n\r\n\r\nEND\r\n", "meta": {"hexsha": "b223c45868c415e33169733325c58b24c5354cb9", "size": 7317, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/beta_pred.f90", "max_stars_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_stars_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 73, "max_stars_repo_stars_event_min_datetime": "2021-07-08T23:35:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T15:17:58.000Z", "max_issues_repo_path": "src/fortran/beta_pred.f90", "max_issues_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_issues_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-09-27T14:27:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T23:50:02.000Z", "max_forks_repo_path": "src/fortran/beta_pred.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.7688442211, "max_line_length": 125, "alphanum_fraction": 0.4451277846, "num_tokens": 1836, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299632771661, "lm_q2_score": 0.7490872131147276, "lm_q1q2_score": 0.6930779346815341}} {"text": " SUBROUTINE SPEAR(DATA1,DATA2,N,WKSP1,WKSP2,D,ZD,PROBD,RS,PROBRS)\n DIMENSION DATA1(N),DATA2(N),WKSP1(N),WKSP2(N)\n DO 11 J=1,N\n WKSP1(J)=DATA1(J)\n WKSP2(J)=DATA2(J)\n11 CONTINUE\n CALL SORT2(N,WKSP1,WKSP2)\n CALL CRANK(N,WKSP1,SF)\n CALL SORT2(N,WKSP2,WKSP1)\n CALL CRANK(N,WKSP2,SG)\n D=0.\n DO 12 J=1,N\n D=D+(WKSP1(J)-WKSP2(J))**2\n12 CONTINUE\n EN=N\n EN3N=EN**3-EN\n AVED=EN3N/6.-(SF+SG)/12.\n FAC=(1.-SF/EN3N)*(1.-SG/EN3N)\n VARD=((EN-1.)*EN**2*(EN+1.)**2/36.)*FAC\n ZD=(D-AVED)/SQRT(VARD)\n PROBD=ERFCC(ABS(ZD)/1.4142136)\n RS=(1.-(6./EN3N)*(D+0.5*(SF+SG)))/FAC\n T=RS*SQRT((EN-2.)/((1.+RS)*(1.-RS)))\n DF=EN-2.\n PROBRS=BETAI(0.5*DF,0.5,DF/(DF+T**2))\n RETURN\n END\n", "meta": {"hexsha": "8f35d8798f22c08193f2bce5e96469eee035fce2", "size": 788, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "Math3/NumRec/source/spear.for", "max_stars_repo_name": "domijin/MM3", "max_stars_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Math3/NumRec/source/spear.for", "max_issues_repo_name": "domijin/MM3", "max_issues_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Math3/NumRec/source/spear.for", "max_forks_repo_name": "domijin/MM3", "max_forks_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.1428571429, "max_line_length": 70, "alphanum_fraction": 0.5152284264, "num_tokens": 371, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299488452012, "lm_q2_score": 0.7490872187162397, "lm_q1q2_score": 0.6930779290534205}} {"text": "!---------------------------------------------------!\n! Copyright (c) 2017 Shunsuke A. Sato !\n! Released under the MIT license !\n! https://opensource.org/licenses/mit-license.php !\n!---------------------------------------------------!\n!-------10--------20--------30--------40--------50--------60--------70--------80--------90\nsubroutine set_deps\n use global_variables\n implicit none\n integer :: ikr,ikz\n\n select case(nband_type)\n case(N_PARABOLIC_BAND)\n!$omp parallel do private(ikz, ikr)\n do ikz = -NKz,NKz\n do ikr = 1,NKr\n deps(ikr,ikz) = eps_g + 0.5d0/mass_r*(kr(ikr)**2+kz(ikz)**2)\n end do\n end do\n case(N_NONPARABOLIC_BAND)\n!$omp parallel do private(ikz, ikr)\n do ikz = -NKz,NKz\n do ikr = 1,NKr\n deps(ikr,ikz) = eps_g*sqrt(1d0 + (kr(ikr)**2+kz(ikz)**2)/(mass_r*eps_g)) \n end do\n end do\n case default\n write(*,\"(A,2x,A)\")\"Invalid nband_type\",nband_type\n stop\n end select\n\n\n return\nend subroutine set_deps\n", "meta": {"hexsha": "2b14d89725388b19fe5a6be946f0ede53b25a951", "size": 1005, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/preparation/set_deps.f90", "max_stars_repo_name": "shunsuke-sato/two_band_model", "max_stars_repo_head_hexsha": "27653b364b8f08f12eaa273a094c15f7154bdfc9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-07-12T15:46:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T11:32:46.000Z", "max_issues_repo_path": "src/preparation/set_deps.f90", "max_issues_repo_name": "shunsuke-sato/two_band_model", "max_issues_repo_head_hexsha": "27653b364b8f08f12eaa273a094c15f7154bdfc9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-09T02:08:03.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-09T02:20:22.000Z", "max_forks_repo_path": "src/preparation/set_deps.f90", "max_forks_repo_name": "shunsuke-sato/two_band_model", "max_forks_repo_head_hexsha": "27653b364b8f08f12eaa273a094c15f7154bdfc9", "max_forks_repo_licenses": ["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.7142857143, "max_line_length": 90, "alphanum_fraction": 0.5134328358, "num_tokens": 317, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850128595115, "lm_q2_score": 0.7401743505760728, "lm_q1q2_score": 0.693014151347399}} {"text": " REAL FUNCTION EPSLON (X)\nC\nC ESTIMATE MACHINE ARITHMETIC ROUNDOFF IN QUANTITIES OF SIZE X\nC\nC THIS PROGRAM SHOULD FUNCTION PROPERLY ON ALL SYSTEMS\nC SATISFYING THE FOLLOWING TWO ASSUMPTIONS,\nC 1. THE BASE USED IN REPRESENTING FLOATING POINT\nC NUMBERS IS NOT A POWER OF THREE.\nC 2. THE QUANTITY A IN STATEMENT 10 IS REPRESENTED TO\nC THE ACCURACY USED IN FLOATING POINT VARIABLES\nC THAT ARE STORED IN MEMORY.\nC THE STATEMENT NUMBER 10 AND THE GO TO 10 ARE INTENDED TO\nC FORCE OPTIMIZING COMPILERS TO GENERATE CODE SATISFYING\nC ASSUMPTION 2.\nC UNDER THESE ASSUMPTIONS, IT SHOULD BE TRUE THAT,\nC A IS NOT EXACTLY EQUAL TO FOUR-THIRDS,\nC B HAS A ZERO FOR ITS LAST BIT OR DIGIT,\nC C IS NOT EXACTLY EQUAL TO ONE,\nC EPS MEASURES THE SEPARATION OF 1.0 FROM\nC THE NEXT LARGER FLOATING POINT NUMBER.\nC\nC CALLED BY: INPUT\nC CALLS:\nC\nC REVISIONS:\nC 7-10-92 CHANGE TO CCM CODING CONVENTIONS (R. JAKOB)\nC\nC------------ Arguments ------------------------------------------------\nC\nC Input\nC\nC APPROXIMATED VALUE\n REAL X \nC \nC------ Local Variables ------------------------------------------------\nC\n REAL A,B,C,EPS\nC\nC----- Executable Statements -------------------------------------------\nC\n A = 4.0E0/3.0E0 \n 10 B = A - 1.0E0 \n C = B + B + B \n EPS = ABS(C-1.0E0) \n IF (EPS .EQ. 0.0E0) GO TO 10 \n EPSLON = EPS*ABS(X) \n RETURN \n END \n", "meta": {"hexsha": "b33def7f2f198525514ed9e1c8f5a854fc8c1c69", "size": 1679, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/epslon.f", "max_stars_repo_name": "jhaoli/shallow_spectral", "max_stars_repo_head_hexsha": "a2580f9baad596a56efaaae20b80e1bd543c2502", "max_stars_repo_licenses": ["NetCDF"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-06-19T02:24:41.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-19T02:24:41.000Z", "max_issues_repo_path": "src/epslon.f", "max_issues_repo_name": "jhaoli/shallow_spectral", "max_issues_repo_head_hexsha": "a2580f9baad596a56efaaae20b80e1bd543c2502", "max_issues_repo_licenses": ["NetCDF"], "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/epslon.f", "max_forks_repo_name": "jhaoli/shallow_spectral", "max_forks_repo_head_hexsha": "a2580f9baad596a56efaaae20b80e1bd543c2502", "max_forks_repo_licenses": ["NetCDF"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.2653061224, "max_line_length": 72, "alphanum_fraction": 0.5122096486, "num_tokens": 454, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278571786139, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.6929781771245308}} {"text": " module macmath\nc Math constants\n\nc Napier's constant(Exp[1])\nc \\lim_{n\\rightarrow\\infty}(1 + \\frac{1}{n})^n\n real*8, parameter :: m_e = 2.7182818284590452354d0\n\nc Euler-Mascheroni constant(Euler's gamma)\nc \\lim_{n\\rightarrow\\infty}(\\sum_{k=1}^{n}\\frac{1}{k} - \\ln{n})\n real*8, parameter :: m_euler = 0.57721566490153286061d0\n\nc Log[2, Exp[1]]\n real*8, parameter :: m_log2e = 1.4426950408889634074d0\n\nc Log[10, Exp[1]]\n real*8, parameter :: m_log10e = 0.43429448190325182765d0\n\nc Log[Exp[1], 2]\n real*8, parameter :: m_ln2 = 0.69314718055994530942d0\n\nc Log[Exp[1], 10]\n real*8, parameter :: m_ln10 = 2.30258509299404568402d0\n\nc Pi\n real*8, parameter :: m_pi = 3.14159265358979323846d0\n\nc 2 * Pi\n real*8, parameter :: m_2pi = 6.28318530717958647693d0\n\nc 4 * Pi\n real*8, parameter :: m_4pi = 12.5663706143591729539d0\n\nc Pi / 2\n real*8, parameter :: m_pi_2 = 1.57079632679489661923d0\n\nc Pi / 4\n real*8, parameter :: m_pi_4 = 0.78539816339744830962d0\n\nc 1 / Pi\n real*8, parameter :: m_1_pi = 0.31830988618379067154d0\n\nc 2 / Pi\n real*8, parameter :: m_2_pi = 0.63661977236758134308d0\n\nc 4 / Pi\n real*8, parameter :: m_4_pi = 1.27323954473516268615d0\n\nc Sqrt[Pi]\n real*8, parameter :: m_sqrtpi = 1.77245385090551602730d0\n\nc 2 / Sqrt[Pi]\n real*8, parameter :: m_2_sqrtpi = 1.12837916709551257390d0\n\nc Sqrt[2]\n real*8, parameter :: m_sqrt2 = 1.41421356237309504880d0\n\nc Sqrt[1/2]\n real*8, parameter :: m_1_sqrt2 = 0.70710678118654752440d0\n\nc Sqrt[3]\n real*8, parameter :: m_sqrt3 = 1.73205080756887729353d0\n\nc Sqrt[1/3]\n real*8, parameter :: m_1_sqrt3 = 0.57735026918962576451d0\n\nc Standard alias for SAD sources\n real*8, parameter :: napier = m_e, euler = m_euler\n real*8, parameter :: pi = m_pi\n real*8, parameter :: pi2 = m_2pi, pi4 = m_4pi\n real*8, parameter :: hpi = m_pi_2, qpi = m_pi_4\n\n integer*4 ,parameter :: nsprime=1000;\n integer*4 ,parameter :: smallprime(nsprime)=[\n $2,3,5,7,11,13,17,19,23,29,31,37, 41, 43, 47, 53, 59, 61, \n $67,71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, \n $139,149,151,157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, \n $223, 227, 229,233,239,241,251,257, 263, 269, 271, 277, 281, 283, \n $293,307,311,313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, \n $383, 389, 397,401,409,419, 421, 431, 433, 439, 443, 449, 457, 461, \n $463, 467, 479, 487, 491,499,503,509, 521, 523, 541, 547, 557, 563, \n $569, 571, 577, 587, 593, 599, 601,607,613,617, 619, 631, 641, 643, \n $647, 653, 659, 661, 673, 677, 683, 691, 701,709,719,727, 733, 739, \n $743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821,823,827,829, \n $839,853,857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929,937, \n $941, 947,953,967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, \n $1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, \n $1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, \n $1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, \n $1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, \n $1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, 1433, \n $1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, \n $1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, \n $1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, \n $1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, \n $1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823, 1831, \n $1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, \n $1931, 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997, 1999, 2003, \n $2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, \n $2089, 2099, 2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, \n $2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251, 2267, 2269, \n $2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, \n $2351, 2357, 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411, 2417, \n $2423, 2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521, 2531, \n $2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617, 2621, \n $2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687, 2689, 2693, \n $2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, 2767, \n $2777, 2789, 2791, 2797, 2801, 2803, 2819, 2833, 2837, 2843, 2851, \n $2857, 2861, 2879, 2887, 2897, 2903, 2909, 2917, 2927, 2939, 2953, \n $2957, 2963, 2969, 2971, 2999, 3001, 3011, 3019, 3023, 3037, 3041, \n $3049, 3061, 3067, 3079, 3083, 3089, 3109, 3119, 3121, 3137, 3163, \n $3167, 3169, 3181, 3187, 3191, 3203, 3209, 3217, 3221, 3229, 3251, \n $3253, 3257, 3259, 3271, 3299, 3301, 3307, 3313, 3319, 3323, 3329, \n $3331, 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391, 3407, 3413, \n $3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, 3517, \n $3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, 3581, 3583, \n $3593, 3607, 3613, 3617, 3623, 3631, 3637, 3643, 3659, 3671, 3673, \n $3677, 3691, 3697, 3701, 3709, 3719, 3727, 3733, 3739, 3761, 3767, \n $3769, 3779, 3793, 3797, 3803, 3821, 3823, 3833, 3847, 3851, 3853, \n $3863, 3877, 3881, 3889, 3907, 3911, 3917, 3919, 3923, 3929, 3931, \n $3943, 3947, 3967, 3989, 4001, 4003, 4007, 4013, 4019, 4021, 4027, \n $4049, 4051, 4057, 4073, 4079, 4091, 4093, 4099, 4111, 4127, 4129, \n $4133, 4139, 4153, 4157, 4159, 4177, 4201, 4211, 4217, 4219, 4229, \n $4231, 4241, 4243, 4253, 4259, 4261, 4271, 4273, 4283, 4289, 4297, \n $4327, 4337, 4339, 4349, 4357, 4363, 4373, 4391, 4397, 4409, 4421, \n $4423, 4441, 4447, 4451, 4457, 4463, 4481, 4483, 4493, 4507, 4513, \n $4517, 4519, 4523, 4547, 4549, 4561, 4567, 4583, 4591, 4597, 4603, \n $4621, 4637, 4639, 4643, 4649, 4651, 4657, 4663, 4673, 4679, 4691, \n $4703, 4721, 4723, 4729, 4733, 4751, 4759, 4783, 4787, 4789, 4793, \n $4799, 4801, 4813, 4817, 4831, 4861, 4871, 4877, 4889, 4903, 4909, \n $4919, 4931, 4933, 4937, 4943, 4951, 4957, 4967, 4969, 4973, 4987, \n $4993, 4999, 5003, 5009, 5011, 5021, 5023, 5039, 5051, 5059, 5077, \n $5081, 5087, 5099, 5101, 5107, 5113, 5119, 5147, 5153, 5167, 5171, \n $5179, 5189, 5197, 5209, 5227, 5231, 5233, 5237, 5261, 5273, 5279, \n $5281, 5297, 5303, 5309, 5323, 5333, 5347, 5351, 5381, 5387, 5393, \n $5399, 5407, 5413, 5417, 5419, 5431, 5437, 5441, 5443, 5449, 5471, \n $5477, 5479, 5483, 5501, 5503, 5507, 5519, 5521, 5527, 5531, 5557, \n $5563, 5569, 5573, 5581, 5591, 5623, 5639, 5641, 5647, 5651, 5653, \n $5657, 5659, 5669, 5683, 5689, 5693, 5701, 5711, 5717, 5737, 5741, \n $5743, 5749, 5779, 5783, 5791, 5801, 5807, 5813, 5821, 5827, 5839, \n $5843, 5849, 5851, 5857, 5861, 5867, 5869, 5879, 5881, 5897, 5903, \n $5923, 5927, 5939, 5953, 5981, 5987, 6007, 6011, 6029, 6037, 6043, \n $6047, 6053, 6067, 6073, 6079, 6089, 6091, 6101, 6113, 6121, 6131, \n $6133, 6143, 6151, 6163, 6173, 6197, 6199, 6203, 6211, 6217, 6221, \n $6229, 6247, 6257, 6263, 6269, 6271, 6277, 6287, 6299, 6301, 6311, \n $6317, 6323, 6329, 6337, 6343, 6353, 6359, 6361, 6367, 6373, 6379, \n $6389, 6397, 6421, 6427, 6449, 6451, 6469, 6473, 6481, 6491, 6521, \n $6529, 6547, 6551, 6553, 6563, 6569, 6571, 6577, 6581, 6599, 6607, \n $6619, 6637, 6653, 6659, 6661, 6673, 6679, 6689, 6691, 6701, 6703, \n $6709, 6719, 6733, 6737, 6761, 6763, 6779, 6781, 6791, 6793, 6803, \n $6823, 6827, 6829, 6833, 6841, 6857, 6863, 6869, 6871, 6883, 6899, \n $6907, 6911, 6917, 6947, 6949, 6959, 6961, 6967, 6971, 6977, 6983, \n $6991, 6997, 7001, 7013, 7019, 7027, 7039, 7043, 7057, 7069, 7079, \n $7103, 7109, 7121, 7127, 7129, 7151, 7159, 7177, 7187, 7193, 7207, \n $7211, 7213, 7219, 7229, 7237, 7243, 7247, 7253, 7283, 7297, 7307, \n $7309, 7321, 7331, 7333, 7349, 7351, 7369, 7393, 7411, 7417, 7433, \n $7451, 7457, 7459, 7477, 7481, 7487, 7489, 7499, 7507, 7517, 7523, \n $7529, 7537, 7541, 7547, 7549, 7559, 7561, 7573, 7577, 7583, 7589, \n $7591, 7603, 7607, 7621, 7639, 7643, 7649, 7669, 7673, 7681, 7687, \n $7691, 7699, 7703, 7717, 7723, 7727, 7741, 7753, 7757, 7759, 7789, \n $7793, 7817, 7823, 7829, 7841, 7853, 7867, 7873, 7877, 7879, 7883, \n $7901, 7907, 7919]\n\n end module\n\n module macphys\n use macmath\nc DO not forget to update sim/MACPHYS.h!!!\nc\nc Update History:\nc 2016/01/12:\tfrom PDG 2014 https://www.google.co.jp/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&ved=0ahUKEwjHw4unsKLKAhUEoJQKHaiPCLgQFggjMAE&url=http%3A%2F%2Fpdg.lbl.gov%2F2014%2Freviews%2Frpp2014-rev-phys-constants.pdf&usg=AFQjCNGXw6APvgkpoTdIRLeC-XV651ZbJg&sig2=-wjwSn5pfl6Juvok0hFqow\nc 2008/03/27:\tfrom CODATA 2006\nc \t\t\thttp://physics.nist.gov/cuu/Constants/Table/allascii.txt\nc\nc 2003/07/15:\tfrom Particle Data Book\nc\n\nc Including math constant for permeability of vacuum\n\nc Speed of light in vacuum:\t\tc\nc Definition:\t299 792 458. m/sec\n real*8, parameter :: cveloc = 299792458d0\n\nc Planck's constant:\t\th\nc CODATA 2006:\t6.626 068 96(33) x 10^-34 Js\nc PDG 2014::\t6.626 069 57(29) x 10^-34 Js\nc CODATA 2018 6.626 070 15 x 10^-34 Js exact\n real*8, parameter :: plank = 6.62607015d-34\n\nc Dirac's constant:\t\t\thbar = h / (2 Pi)\nc PDB 2003:\t\t1.054 571 596(82) x 10^-34 Js\nc CODATA 2006:\t1.054 571 628(53) x 10^-34 Js\nc PDG 2014: \t1.054 571 726(47) x 10^-34 Js\nc CODATA 2018: h (exact) / 2pi\n real*8, parameter :: plankr = plank/m_2pi\n\nc Elementary charge:\t\te\nc PDB 2003:\t\t1.602 176 462(63) x 10^-19 C\nc CODATA 2006:\t1.602 176 487(40) x 10^-19 C\nc PDG 2014: \t1.602 176 565(35) x 10^-19 C\nc CODATA 2018: 1.602 176 634 x 10^-19 C exact\n real*8, parameter :: elemch = 1.602176634d-19\n\nc Electron charge in elementary charge unit\n real*8, parameter :: echarg = 1.0d0\n\nc Fine-structure constant\t\t\\alpha = \\mu_0 e^2 c / (2 h)\nc PDB 2003:\t\t1 / 137.035 999 76(50)\nc CODATA 2006:\t1 / 137.035 999 679(94)\nc PDG 2014: \t1 / 137.035 999 074(44)\nc CODATA 2018: \t1 / 137.035 999 084(21)\n real*8, parameter :: finest = 1.d0 / 137.035999084d0\n\nc Permeability of vacuum:\t\t\\mu_0\nc Definition:\t4 Pi x 10^-7 N A^-2\nc CODATA 2018: 1.000 000 000 55 * above\nc CODATA 2018: 4 pi alpha hbar/(e^2 c)\nc real*8, parameter :: mu0 = 1.00000000055d0 * pi * 4.d-7\n real*8, parameter :: mu0=m_4pi*finest*plankr/elemch**2/cveloc\n\nc Permittivity of vacuum:\t\t\\epsilon_0 = 1 / (\\mu_0 c^2)\nc Delivered from defintion\n real*8, parameter :: ep0 = 1.d0 / (mu0 * cveloc**2)\n\nc Electron mass energy equivalent in eV:\tm_e c^2 / e\nc PDB 2003:\t\t.510 998 902(21) MeV\nc CODATA 2006:\t.510 998 910(13) MeV\nc PDG 2014: \t.510 998 928(11) MeV\nc CODATA 2018: \t.510 998 950 00(15) MeV\n real*8, parameter :: elmass = 0.51099895000d6\n\nc Proton mass energy equivalent in eV:\tm_p c^2 / e\nc PDB 2003:\t\t938. 271 998(38) MeV\nc CODATA 2006:\t938. 272 013(23) MeV\nc PDG 2014: \t938. 272 046(21) MeV\nc CODATA 2018: \t938. 272 088 16(29) MeV\n real*8, parameter :: prmass = 938.27208816d6\n\nc Classical electron radius:\tr_e = e^2 / (4Pi \\epsilon_0 m_e c^2)\nc \t\t\t\t\t = (\\alpha hbar c) / (m_e c^2)\nc \t\t\t\t\t = (e^2 c^2 \\mu_0 / 4Pi) / (m_e c^2)\nc \t\t\t\t\t = e c^2 * 10^-7 * (e / (m_e c^2))\nc PDB 2003:\t\t2.817 940 285(??) x 10^-15 m\nc CODATA 2006:\t2.817 940 2894(58) x 10^-15 m\nc PDG 2014: \t2.817 940 3267(27) x 10^-15 m\nc parameter (elradi = finest * plankr * cveloc / (elemch * elmass))\n real*8, parameter :: elradi =\n $ finest * plankr * cveloc / (elemch * elmass)\n\nc Classical proton radius:\t\tr_p = e^2 / (4Pi \\epsilon_0 m_p c^2)\nc \t\t\t\t\t = (\\alpha hbar c) / (m_p c^2)\nc \t\t\t\t\t = (e^2 c^2 \\mu_0 / 4Pi) / (m_p c^2)\nc \t\t\t\t\t = e c^2 * 10^-7 * (e / (m_p c^2))\nc parameter (prradi = finest * plankr * cveloc / (elemch * prmass))\n real*8, parameter :: prradi =\n $ finest * plankr * cveloc / (elemch * prmass)\n\nc Boltzmann Constant:\nc PDG2014: 1.380 6488(13) x 10^-23 J/K\nc COD2018:\t\t1.380 649 \u00d7 10\u221223 J/K exact\n real*8, parameter :: kboltzman = 1.380649d-23\n\nc Spin precession coefficient (ge-2)/2\nc NIST 2014 0.00115965218091\nc CODATA 2018: (2.002 319 304 362 56(35))/2-1 = 0.001159652181280002\nc\n real*8 , parameter :: gspin = 0.001159652181280002\n\n end module\n\n module maccode\nc Do not forget to update sim/MACCODE.h when you change this module!!!!\n implicit none\n integer*4 , parameter ::\n $ icNULL = 0, icDRFT = 1,\n $ icBEND = 2, icQUAD = 4, icSEXT = 6,\n $ icOCTU = 8, icDECA = 10, icDODECA = 12,\n $ icUND = 18, icWIG = 19, icSOL = 20,\n $ icST = 21, icMULT = 22, icTEST = 30,\n $ icCAVI = 31, icTCAV = 32, icMAP = 33,\n $ icINS = 34, icCOORD = 35, icBEAM = 36,\n $ icPROT = 37, icSPCH = 38,\n $ icMARK = 41, icMONI = 42, icAPRT = 43,\n $ icMXEL = 99, icLINE = 100, icCELL = 100,\n\n $ icRSVD = 258,\n $ icDEF = icRSVD + 2, icACT = icDEF + 2,\n $ icPROC = icACT + 2, icVAR = icPROC + 2,\n $ icKWRD = icVAR + 2, icUNIT = icKWRD + 2,\n $ icRAND = icUNIT + 2, icENV = icRAND + 2,\n $ icFLAG = icENV + 2, icGLI = icFLAG + 4,\n $ icGLL = icGLI + 4, icGLR = icGLI + 8,\n $ icGraf = icGLL + 2, icPART = icGraf + 2\n end module\n\n module maccbk\n implicit none\n public\n integer*4 FLAGON,FLAGOF\n parameter (FLAGON=-1,FLAGOF=0)\n integer*4 HTMAX,MAXPNAME,LILISTDUMMY\n parameter(MAXPNAME=32,LILISTDUMMY=3)\n character*(MAXPNAME) NULSTR\n parameter(HTMAX=2**18,NULSTR=' ')\n\n integer*4 pagesz,inipage\n parameter(pagesz=4096/8,inipage=4)\n integer*4 MAXSTR,MAXMEM0,MAXMEM\n parameter (MAXSTR=256)\n parameter (MAXMEM=2*inipage*pagesz)\n parameter (MAXMEM0=6*1024*pagesz)\nc$$$ character*(MAXPNAME) pname(HTMAX)\nc$$$ integer*4 lpname(HTMAX)\nc$$$ integer*4 idtype(HTMAX)\nc$$$ integer*8 idval(HTMAX)\n character*(MAXPNAME), dimension(:), \n $ allocatable, target:: pname\n integer*4 , dimension(:), \n $ allocatable, target :: lpname\n integer*4 , dimension(:), \n $ allocatable, target :: idtype\n integer*8 , dimension(:), \n $ allocatable, target :: idval\nc$$$ character*(MAXPNAME), pointer, dimension(:) :: ppname\nc$$$ integer*4 , pointer, dimension(:) :: plpname(:)\nc$$$ integer*4 , pointer, dimension(:) :: pidtype(:)\nc$$$ integer*8 , pointer, dimension(:) :: pidval(:)\n integer*8 ilistroot\n integer*4, parameter :: klistlen=16\n integer*8, pointer, dimension(:) :: klist\n real*8, pointer, dimension(:) :: rlist\n integer*4, pointer, dimension(:,:) :: ilist\n integer*1, pointer, dimension(:,:) :: jlist\n integer*8, parameter :: i00=int8(0)\n\n interface sethtb\n module procedure sethtb4,sethtb8\n end interface\n\n contains\n integer*4 function sethtb8(token,type,ival)\n use iso_c_binding\n use maccode\n implicit none\n character*(*) , intent(in) :: token\n integer*8, target, intent(in):: ival\n integer*4 , intent(in) :: type\n integer*4 idx,hsrch\n sethtb8=0\n \n idx= hsrch(token(:len_trim(token)))\n if(idx .le. 0 .or. idx .gt. HTMAX) then\n call errmsg('sethtb8'\n & ,'illegal index value for sethashtble: '//\n $ token(:len_trim(token))\n & , 0,16)\n else\n idtype(idx)=type\n idval(idx)=merge(transfer(c_loc(ival),i00)/8,\n $ ival,type .eq. icRSVD)\n sethtb8=idx\n endif\n return\n end function\n\n integer*4 function sethtb4(token,type,ival)\n implicit none\n character*(*) , intent(in) ::token\n integer*4 , intent(in) :: type,ival\n sethtb4=sethtb8(token,type,int8(ival))\n return\n end function\n\n subroutine forcesf\n implicit none\n call abort\n end subroutine\n\n end module\n\nc Don't confuse, Emacs. This is -*- fortran -*- mode!\n module tfcbk\n implicit none\n integer*4, parameter:: maxgeneration=2**30-1,maxlevele=2**14,\n $ nsymhash=2047,nslots=32,maxlbuf=2**22\n real*8 dinfinity,dnotanumber\n integer*8\n $ itfcontroot,itfcontext,itfcontextpath,itflocal,\n $ kxeof,kxfailed,iaxhold,iaximmediate,\n $ iaxline,kxliteral,kxnull,kxnulll,kxnulls,\n $ iaxout,iaxpriority,iaxschar,\n $ iaxslotnull,iaxslotpart,iaxslotseqnull,\n $ kxvect,kxvect1,iavpw,\n $ kerror,ierrorf,ierrorgen,ierrorprint,ierrorth,\n $ ierrorexp,ifunbase,initmessage,levelcompile,\n $ kinfinity,kminfinity,knotanumber\n integer*4 \n $ levele,levelp,lgeneration,ltrace,\n $ modethrow,iordless\n end module\n\n module tfmem\n use maccbk, only:i00\n implicit none\n integer*8, parameter :: mpsize=2**22,kcpklist0=0,maxstack=2**25,\n $ minstack=2**18\n integer*8 , parameter :: mhash=32767\n integer*4, parameter :: nindex=64,\n $ minseg0=9,minseg1=16,minseg2=16\n integer*4, parameter :: ncbk = 2**16\n integer*8, parameter :: kcpoffset = 0\n type cbkalloc\n integer*8, allocatable :: ca(:)\n end type\n\n type (cbkalloc), target, allocatable :: sadalloc(:)\n integer*8 ,allocatable :: kcbk(:,:)\n integer*8 :: icp=0,nmem=0,nnet=0,ich=0,maxic=3,\n $ minic,icsep,nitaloc\n integer*8 kfirstalloc\n integer*4 :: icbk=1,jcbk=1\n\n type sad_descriptor\n sequence\n real*8 x(1:0)\n integer*8 k\n end type\n\n interface sad_loc\n module procedure ksad_loc,dsad_loc,isad_loc,rsad_loc\n end interface\n\n contains\n integer*8 function dsad_loc(k)\n use iso_c_binding\n implicit none\n type (sad_descriptor), target, intent(in) :: k\n dsad_loc=(transfer(c_loc(k),i00)-kcpklist0)/8\n return\n end function\n\n integer*8 function ksad_loc(k)\n use iso_c_binding\n implicit none\n integer*8, target, intent(in) :: k\n ksad_loc=(transfer(c_loc(k),i00)-kcpklist0)/8\n return\n end function\n\n integer*8 function isad_loc(i)\n use iso_c_binding\n implicit none\n integer*4, target, intent(in):: i\n isad_loc=(transfer(c_loc(i),i00)-kcpklist0)/8\n return\n end function\n\n integer*8 function rsad_loc(x)\n use iso_c_binding\n implicit none\n real*8, target, intent(in):: x\n rsad_loc=(transfer(c_loc(x),i00)-kcpklist0)/8\n return\n end function\n\n subroutine tfcbkinit\n use iso_c_binding\n use maccbk\n implicit none\n type (c_ptr) cp\n integer*4, save::lps=0\n integer*4 getpagesize\nc kcpklist0=transfer(c_loc(kdummy),i00)\nc write(*,*)'tfcbkinit ',kcpklist0,2**31\nc kcpklist0=transfer(c_loc(kdummy),i00)-kcpoffset-8\n if(lps .eq. 0)then\n lps=getpagesize()\n endif\n allocate(pname(0:HTMAX))\n allocate(lpname(0:HTMAX))\n allocate(idtype(0:HTMAX))\n allocate(idval(0:HTMAX))\nc$$$ ppname=>pname\nc$$$ plpname=>lpname\nc$$$ pidtype=>idtype\nc$$$ pidval=>idval\n call c_f_pointer(transfer(kcpklist0+8,cp),klist,[klistlen])\n call lminit(klist(0),lps,pname(0),lpname(0),idtype(0),idval(0))\n call c_f_pointer(c_loc(klist(1)),rlist,[klistlen])\n call c_f_pointer(c_loc(klist(1)),ilist,[2,klistlen])\n call c_f_pointer(c_loc(klist(1)),jlist,[8,klistlen])\n return\n end subroutine\n\n subroutine talocinit\n use maccbk\n use iso_c_binding, only:c_loc\n implicit none\n integer*8 ka,ic\n allocate(sadalloc(ncbk))\n allocate(sadalloc(1)%ca(nindex*2+mhash+16))\n ka=transfer(c_loc(sadalloc(1)%ca(1)),i00)\nc kcpklist0=0\n call tfcbkinit\n icp=ksad_loc(sadalloc(1)%ca(1))\n allocate (kcbk(3,ncbk))\n kcbk(1,1)=icp\n kcbk(2,1)=icp+nindex*2+mhash+15\n kcbk(3,1)=kcbk(2,1)\n do ic=icp,icp+nindex*2,2\n klist(ic)=ic\n klist(ic+1)=ic\n enddo\n ich=icp+nindex*2+4\n do ic=ich,ich+mhash\n klist(ic)=ic\n enddo\n icsep=ich+mhash+1\n klist(icsep)=icsep\n nmem=0\n nnet=0\n kfirstalloc=ktaloc(3)\n return\n end subroutine\n\n integer*8 function ktaloc(n)\n use maccbk\n implicit none\n integer*4 , intent(in):: n\n integer*4 m,n1,m1\n integer*8 ic1,i,ic,ic2,ip1,j,i1\n n1=max(n,3)\n m=n1+1\n if(n1 .lt. nindex)then\n ic=icp+n1*2\n i=klist(ic)\n if(i .ne. ic)then\n m=ilist(1,i-1)\n klist(ic)=klist(i)\n klist(klist(i)+1)=ic\n j=ich+iand(i+m+2,mhash)\n do while(klist(j) .ne. i+2)\n j=klist(j)\n enddo\n klist(j)=klist(i+2)\n nnet=nnet+m\n ktaloc=i\n return\n endif\n ic1=ic+min(m,minseg1)*2\n if(ic1 .le. maxic)then\n ic2=min(maxic-2,ic1+10)\n do ic=ic1,ic2,2\n i=klist(ic)\n if(ic .ne. i)then\n m1=ilist(1,i-1)\n klist(ic)=klist(i)\n klist(klist(i)+1)=ic\n j=ich+iand(i+m1+2,mhash)\n do while(klist(j) .ne. i+2)\n j=klist(j)\n enddo\n klist(j)=klist(i+2)\n call tsetindexhash(i+m,m1-m)\n ilist(1,i-1)=m\n nnet=nnet+m\n ktaloc=i\n return\n endif\n enddo\n do ic=maxic,ic2+2,-2\n i=klist(ic)\n if(ic .ne. i)then\n m1=ilist(1,i-1)\n klist(ic)=klist(i)\n klist(klist(i)+1)=ic\n j=ich+iand(i+m1+2,mhash)\n do while(klist(j) .ne. i+2)\n j=klist(j)\n enddo\n klist(j)=klist(i+2)\n call tsetindexhash(i+m,m1-m)\n ilist(1,i-1)=m\n nnet=nnet+m\n maxic=merge(ic-2,ic,klist(ic) .eq. ic)\n ktaloc=i\n return\n endif\n enddo\n maxic=ic1-2\n endif\n endif\n ic=icp+nindex*2\n 1000 i1=ic\n i=klist(i1)\n do while(i .ne. ic)\n m1=ilist(1,i-1)\n if(m1 .eq. m)then\n klist(i1)=klist(i)\n klist(klist(i)+1)=i1\n j=ich+iand(i+m+2,mhash)\n do while(klist(j) .ne. i+2)\n j=klist(j)\n enddo\n klist(j)=klist(i+2)\n nnet=nnet+m\n ktaloc=i\n return\n elseif(m1-minseg2 .ge. m)then\n klist(i1)=klist(i)\n klist(klist(i)+1)=i1\n j=ich+iand(i+m1+2,mhash)\n do while(klist(j) .ne. i+2)\n j=klist(j)\n enddo\n klist(j)=klist(i+2)\n call tsetindexhash(i+m,m1-m)\n ilist(1,i-1)=m\n nnet=nnet+m\n ktaloc=i\n return\n endif\n i1=i\n i=klist(i)\n enddo\n call talocp(m,ip1)\n if(ip1 .gt. 0)then\n go to 1000\n endif\n ktaloc=-1\n return\n end function\n\n subroutine tsetindexhash(ip,m)\n use maccbk\n implicit none\n integer*4 , intent(in) :: m\n integer*8 , intent(in) ::ip\n integer*8 ic,ic1,ia\n if(m .gt. nindex)then\n ic=icp+nindex*2\n else\n ic=icp+(m-1)*2\n maxic=max(ic,maxic)\n endif\n klist(ip )=klist(ic)\n klist(ip+1)=ic\n klist(klist(ic)+1)=ip\n klist(ic)=ip\n ia=ip+2\n ic1=ich+iand(ia+m,mhash)\n klist(ia )=klist(ic1)\n klist(ic1 )=ia\n ilist(1,ip-1)=m\nc call tfsetlastp(ip+m-1)\n return\n end subroutine\n\n subroutine tfree(ka)\n use maccbk\nc use ffs0, only:ifinext\n implicit none\n integer*8, intent(in):: ka\n integer*8 ix,ik,ik0,ip,ix1\n integer*4 m,mx\n m=ilist(1,ka-1)\nc if(associated(ifinext) .and. ka .eq. ifinext)then\nc write(*,*)'tfree ',ka,m\nc endif\n if(m .lt. 4)then\n if(m .ne. 0)then\n write(*,*)'tfree-too small segment: ',ka,m\n call abort\n endif\n return\n endif\n nnet=nnet-m\n ix=ka+2\n ik=iand(ix,mhash)+ich\n ik0=ik\n ip=klist(ik)\n do while(ip .ne. ik0)\n if(ip .lt. ix)then\n mx=ilist(1,ip-3)\n if(ip+mx .eq. ix)then\n klist(ik )=klist(ip)\n klist(klist(ip-2)+1)=klist(ip-1)\n klist(klist(ip-1) )=klist(ip-2)\n m=m+mx\n ix=ip\n exit\n endif\n endif\n ik=ip\n ip=klist(ik)\n enddo\n ix1=ix+m\nc if(tfchecklastp(ix1))then\n ik=iand(ix1+ilist(1,ix1-3),mhash)+ich\n ik0=ik\n ip=klist(ik)\n do while(ip .ne. ik0)\n if(ip .eq. ix1)then\n klist(ik )=klist(ip)\n klist(klist(ip-2)+1)=klist(ip-1)\n klist(klist(ip-1) )=klist(ip-2)\n m=m+ilist(1,ix1-3)\n exit\n endif\n ik=ip\n ip=klist(ik)\n enddo\nc endif\n call tsetindexhash(ix-2,m)\n return\n end subroutine\n \n integer*8 function ktzaloc(ktype,nw)\n use maccbk\n implicit none\n integer*4, intent(in):: nw\n integer*8, intent(in):: ktype\n integer*8 k1\n k1=ktaloc(nw+2)\n ilist(2,k1-1)=0\n klist(k1)=ktype\n ilist(1,k1+1)=0\n ktzaloc=k1+2\n return\n end function\n\n end module\n\n module tfcode\n use tfmem, only:sad_descriptor\n implicit none\n real*8, parameter :: xinfinity=1.7976931348623157D308\n integer*4, parameter :: ntfoper=0,ntfreal=1,ntflist=3,ntflistr=4,\n $ ntfstkseq=5,\n $ ntfstk=6,ntfstring=101,ntfsymbol=201,ntfpat=203,ntfarg=205,\n $ ntffun=ntfoper,ntfdef=ntfsymbol\n integer*4, parameter :: nfunif=39,nfunlength=20,nfunreppart=22,\n $ nfundo=29,nfunwhich=126,nfunswitch=91,\n $ nfunmodule=34,nfunblock=35,nfunswicases=37,\n $ nfunselect=41,nfunappend=44,\n $ nfunprepend=45,nfunposition=59,nfunthread=83,nfunscan=96,\n $ nfununeval=132,nfuncases=133,nfundelcases=134,\n $ nfunwith=141,nfunselcases=142,nfunextract=154,\n $ nfuninsert=177,nfundelete=178\n integer*4, parameter ::\n $ mtfnull=0,\n $ mtfneg=1,mtfinv=2,mtfplus=3,mtfminus=4,mtfmult=5,mtfdiv=6,\n $ mtfrevpower=7,mtfpower=8,\n $ mtfgreater=9,mtfgeq=10,mtfleq=11,mtfless=12,\n $ mtfequal=13,mtfunequal=14,mtfand=15,mtfor=16,\n $ mtfnot=17,mtfsame=18,mtfunsame=19,mtfconcat=20,mtfleftbra=21,\n $ mtfrightbra=22,mtfleftbrace=23,mtfrightbrace=24,\n $ mtfsetdelayed=25,mtfset=26,mtfcomplex=27,mtfleftparen=28,\n $ mtfrightparen=29,mtfcomma=30,mtfcomp=31,mtffun=32,\n $ mtfcolon=33,mtfrule=34,mtfruledelayed=35,mtfreplace=36,\n $ mtfreplacerepeated=37,mtfupset=38,mtfupsetdelayed=39,\n $ mtfunset=40,mtfpattest=41,mtfflag=42,mtfslot=43,\n $ mtfslotseq=44,mtfdot=45,mtfalt=46,mtfmap=47,mtfmapall=48,\n $ mtfapply=49,mtfrepeated=50,mtfrepeatednull=51,\n $ mtfinequality=52,mtfaddto=53,mtfsubtractfrom=54,\n $ mtftimesby=55,mtfdivideby=56,\n $ mtfincrement=57,mtfdecrement=58,\n $ mtfpart=59,mtfatt=60,mtfmessagename=61,mtftagset=62,\n $ mtfleftcomment=63,mtfrightcomment=64,mtfhold=65,\n $ mtfend=66,\n $ mtflist=mtfleftbrace,mtftimes=mtfmult\n integer*4 mtfnopc\n parameter (mtfnopc=mtfend)\n integer*4 lsimplepat,lsimplepatlist,lconstlist,lnoconstlist,\n $ larglist,lnopatlist,lmemberlist,lnodefsymbol,lnoseqlist,\n $ lnonreallist\n parameter (lsimplepat=1,lsimplepatlist=2,larglist=4,\n $ lconstlist=8,lnoconstlist=16,lnopatlist=32,lmemberlist=64,\n $ lnodefsymbol=128,lnoseqlist=256,lnonreallist=512)\n integer*4 kconstlist,knoconstlist,kfixedarg,knofixedarg,\n $ kallnofixedarg,knopatarg,kpatarg,kconstarg,knoconstarg,\n $ kseqarg,knoseqarg,ksymbollist,knosymbollist,ktoberebuilt\n parameter (knopatarg=lnonreallist*2,\n $ kpatarg=lnonreallist*4,\n $ kconstlist=lnonreallist*8,\n $ knoconstlist=lnonreallist*16,\n $ kfixedarg=lnonreallist*32,\n $ knofixedarg=lnonreallist*64,\n $ kallnofixedarg=lnonreallist*128,\n $ kconstarg=lnonreallist*256,\n $ knoconstarg=lnonreallist*512,\n $ kseqarg=lnonreallist*1024,\n $ knoseqarg=lnonreallist*2048,\n $ ksymbollist=lnonreallist*4096,\n $ knosymbollist=lnonreallist*8192,\n $ ktoberebuilt=lnonreallist*16384)\n integer*4 iattrholdfirst,iattrholdrest,iattrholdall,\n $ iattrconstant,iattrimmediate,iattrorderless,\n $ iattrdynamic,iattrprotected,iattrnumeric\n parameter (iattrholdfirst=1,iattrholdrest=2,\n $ iattrholdall=iattrholdfirst+iattrholdrest,\n $ iattrimmediate=4,iattrnumeric=8,\n $ iattrorderless=16,iattrdynamic=32,\n $ iattrprotected=64,iattrconstant=128)\n real*8 rtfnull\n parameter (rtfnull=0.d0)\n integer*4, parameter :: irtcret=-4,irtcthrow=-5,\n $ irtcgoto=-6,irtcabort=-7\n integer*8 , parameter ::\n $ ktfnull =int8(z'fff0000000000000'),\n $ ktfother =int8(z'fff2000000000000'),\n $ ktfnr =int8(z'7ff2000000000000'),\n $ ktfoper =int8(z'fff6000000000000'),\n $ ktfref =int8(z'fffa000000000000'),\n $ ktfobj =int8(z'7ff2000000000000'),\n $ ktflist =int8(z'7ff2000000000000'),\n $ ktfpat =int8(z'7ff6000000000000'),\n $ ktfstring=int8(z'7ffa000000000000'),\n $ ktfsymbol=int8(z'7ffe000000000000'),\n $ ktomask =int8(z'fff2000000000000'),\n $ ktrmask =int8(z'7ff2000000000000'),\n $ ktfmask =int8(z'fffe000000000000'),\n $ ktamask =int8(z'0001ffffffffffff'),\n $ ktftrue =int8(z'3ff0000000000000'),\n $ ktffalse =int8(z'0000000000000000'),\n $ ktfnan =int8(z'fff8000000000000'),\n $ ktfenan =int8(z'7ff0000000000000'),\n $ ktfenanb =int8(z'000fffffffffffff')\n type (sad_descriptor) ,parameter ::\n $ dxzero=sad_descriptor(1,int8(0)),\n $ dxnullo=sad_descriptor(1,ktfoper+mtfnull)\n integer*4 , parameter :: mbody = 2**8\n integer*4 , parameter :: mbody1 = 2**8\n real*8 ,parameter :: rtfnan=transfer(ktfnan,1.d0)\n\n type sad_object\n sequence\n integer*4 len,attr\n type (sad_descriptor) alloc\n integer*4 ref,nl\n integer*8 body(1:0)\n real*8 rbody(1:0)\n type (sad_descriptor) dbody(0:mbody1)\n end type\n\n type sad_list\n sequence\n integer*2 lenp,lena\n integer*4 attr\n integer*8 alloc\n integer*4 ref,nl\n type (sad_descriptor) head\n real*8 rbody(1:0)\n complex*16 cbody(1:0)\n type (sad_descriptor) dbody(1:0)\n integer*8 body(1:mbody1)\n end type\n\n type sad_dlist\n sequence\n type (sad_list) list(1:0)\n integer*2 lenp,lena\n integer*4 attr\n type (sad_descriptor) alloc\n integer*4 ref,nl\n type (sad_descriptor) head\n real*8 rbody(1:0)\n complex*16 cbody(1:0)\n integer*8 body(1:0)\n type (sad_descriptor) dbody(1:mbody1)\n end type\n\n type sad_rlist\n sequence\n type (sad_dlist) dlist(1:0)\n integer*2 lenp,lena\n integer*4 attr\n type (sad_descriptor) alloc\n integer*4 ref,nl\n type (sad_descriptor) head\n complex*16 cbody(1:0)\n integer*8 body(1:0)\n type (sad_descriptor) dbody(1:0)\n real*8 rbody(1:mbody1)\n end type\n\n type sad_complex\n sequence\n integer*2 lenp,lena\n integer*4 attr\n integer*8 alloc\n integer*4 ref,nl\n type (sad_descriptor) head\n integer*8 body(1:0)\n type (sad_descriptor) dbody(1:0)\n complex*16 cx(1:0)\n real*8 re,im\n end type\n\n type sad_symbol\n sequence\n integer*4 attr,override\n type (sad_descriptor) alloc\n integer*4 ref,gen\n integer*8 loc,dummy(11:10)\n end type\n\n type sad_symdef\n sequence\n integer*4 len,attr\n integer*8 next,prev,upval,downval\n type (sad_descriptor) value\n type (sad_symbol) sym\n end type\n\n type sad_funtbl\n sequence\n type (sad_symdef) def\n integer*4 narg,id,mapeval(2,1)\n end type\n\n type sad_pat\n sequence\n integer*4 len,mat\n integer*8 alloc\n integer*4 ref,gen\n type (sad_descriptor) expr,head\n type (sad_pat), pointer :: equiv\n type (sad_descriptor) value\n type (sad_symbol) sym\n type (sad_descriptor) default\n end type\n\n type sad_string\n sequence\n integer*4 len,override\n type (sad_descriptor) alloc\n integer*4 ref,gen\n integer*4 nch,nc\n integer*1 istr(1:0)\n integer*8 kstr(1:0)\nc size limitation due to gfortran 7 on macOS ???\n character*(mbody1) str\n end type\n\n type sad_namtbl\n sequence\n integer*4 len,dummy\n integer*8 next,symdef,cont\n type (sad_string) str\n end type\n\n type sad_deftbl\n sequence\n integer*4 len,pat\n integer*8 next,prev\n integer*4 npat,attr\n type (sad_descriptor) arg,argc,body,bodyc\n real*8 compile\n type (sad_descriptor) pattbl(1:2**10)\n end type\n\n type sad_defhash\n sequence\n integer*4 len,attr\n integer*8 next,prev\n integer*4 gen,nhash\n integer*8 hash(0:-1)\n type (sad_descriptor) dhash(0:2**10-1)\n end type\n\n end module\n\n module tfstk\n use tfcbk\n use tfcode\n use maccbk\n use tfmem, only:sad_loc,ksad_loc,ktaloc,tfree\n implicit none\n public\n integer*8 ispbase\n integer*4 mstk,isp,ivstkoffset,ipurefp,napuref,isporg\n integer*4, pointer, dimension(:,:) :: ivstk,itastk,ivstk2,itastk2\n real*8, pointer, dimension(:) :: vstk,rtastk,vstk2,rtastk2\n integer*8, pointer, dimension(:) :: ktastk,ktastk2\n type (sad_descriptor), pointer, dimension(:) :: dtastk,dtastk2,\n $ dlist\n type (sad_descriptor) kxmatrix,dxliteral,dxeof,dxfailed,\n $ dxvect,dxvect1,dxnull,dxnulll,dxnulls\n\nc integer*4 ivstk (2,RBASE:RBASE+MAXMEM0-1)\nc real*8 vstk ( RBASE:RBASE+MAXMEM0-1)\nc integer*4 itastk(2,RBASE:RBASE+MAXMEM0-1)\nc integer*2 jtastk(4,RBASE:RBASE+MAXMEM0-1)\nc integer*8 ktastk( RBASE:RBASE+MAXMEM0-1)\nc real*8 rtastk( RBASE:RBASE+MAXMEM0-1)\nc equivalence ( ivstk(1,RBASE),ilist(1,RBASE))\nc equivalence ( vstk( RBASE),ilist(1,RBASE))\nc equivalence (itastk(1,RBASE),ilist(1,RBASE))\nc equivalence (jtastk(1,RBASE),ilist(1,RBASE))\nc equivalence (rtastk( RBASE),ilist(1,RBASE))\nc equivalence (ktastk( RBASE),ilist(1,RBASE))\n logical*4 :: tfstkinit = .false.\n\n type (sad_symdef), pointer :: redmath\n\n interface loc_sad\n module procedure loc_sym,loc_string,\n $ loc_pat,loc_obj,loc_complex,loc_symdef,\n $ loc_dlist,loc_rlist\n end interface\n\n interface descr_sad\n module procedure descr_sym,descr_string,\n $ descr_pat,descr_obj,descr_complex,descr_symdef,\n $ descr_dlist,descr_rlist\n end interface\n\n interface ktfaddr\n module procedure ktfaddrk,ktfaddrd\n end interface\n\n interface kxaaloc\n module procedure kxaaloc_dlist,kxaaloc_rlist\n end interface\n\n interface ktaaloc\n module procedure ktaaloc_dlist,ktaaloc_rlist\n end interface\n\n interface ktfreallistqo\n module procedure ktfreallistqo_rlist,\n $ ktfreallistqo_dlist\n end interface\n\n interface ktfreallistq\n module procedure ktfreallistqo_rlist,\n $ ktfreallistqo_dlist,ktfreallistqk,ktfreallistqd,\n $ ktfreallistqk_rlist,ktfreallistqd_rlist\n end interface\n\n interface ktfnonreallistqo\n module procedure ktfnonreallistqo_rlist,\n $ ktfnonreallistqo_dlist\n end interface\n\n interface kxadaloc\n module procedure kxadaloc_dlist\n end interface\n\n interface ktadaloc\n module procedure ktadaloc_dlist\n end interface\n\n interface ktflistq\n module procedure ktflistq_dlist,ktflistqd_rlist,\n $ ktflistqd_dlist,ktflistq_rlist\n end interface\n\n interface ktfnonlistq\n module procedure ktfnonlistq_dlist,ktfnonlistq_rlist,\n $ ktfnonlistqd_dlist,ktfnonlistqd_rlist\n end interface\n\n interface tflistq\n module procedure tflistq_dlist,\n $ tflistqd_dlist,tflistq_rlist\n end interface\n\n interface tfnonlistq\n module procedure tfnonlistq_dlist,\n $ tfnonlistqd_dlist,tfnonlistq_rlist,tfnonlistqd_rlist\n end interface\n\n interface ktfrealq\n module procedure ktfrealq_k,ktfrealq_d,ktfrealq_ki,ktfrealq_di,\n $ ktfrealq_dk\n end interface\n\n interface ktfnonrealq\n module procedure ktfnonrealq_k,ktfnonrealq_d,\n $ ktfnonrealq_ki,ktfnonrealq_di\n end interface\n\n interface tfruleq\n module procedure tfruleqk_dlist,tfruleqd_dlist\n end interface\n\n interface tfnumlistqn\n module procedure tfnumlistqnk,tfnumlistqnd\n end interface\n\n interface tfcomplexq\n module procedure tfcomplexqc,tfcomplexqx,\n $ tfcomplexqdx,tfcomplexqdc\n end interface\n\n interface tfreallistq\n module procedure tfreallistqk,tfreallistqd\n end interface\n\n interface tfnonreallistq\n module procedure tfnonreallistqk,tfnonreallistqd\n end interface\n\n interface tfgetllstkall\n module procedure tfgetllstkall_dlist,\n $ tfgetllstkall_rlist\n end interface\n\n interface tfgetdefargp\n module procedure tfgetdefargp_dlist\n end interface\n\n interface ktfstringq\n module procedure ktfstringqk,ktfstringqd\n end interface\n\n interface kxmakelist\n module procedure kxmakelist_dlist,kxmakelist_rlist\n end interface\n\n interface sad_descr\n module procedure list_descr,rlist_descr,dlist_descr,\n $ symbol_descr,dfromr,dfromk,string_descr,pat_descr\n end interface\n\n interface ktfpatq\n module procedure ktfpatqk,ktfpatqd\n end interface\n\n interface ktfsymbolq\n module procedure ktfsymbolqk,ktfsymbolqd\n end interface\n\n interface ktfsequenceq\n module procedure ktfsequenceq_dlist,ktfsequenceq_rlist,\n $ ktfsequenceqd_dlist,ktfsequenceqd_rlist\n end interface\n\n interface tfcomplexnumlistqk\n module procedure \n $ tfcomplexnumlistqk_dlist\n end interface\n\n interface ktfmakelist\n moduleprocedure ktfmakelist_dlist,ktfmakelist_rlist\n end interface\n\n interface ktfobjq\n module procedure ktfobjqk,ktfobjqd\n end interface\n\n interface ktaobj\n module procedure ktaobjk,ktaobjd\n end interface\n\n interface tfmakerulestk\n module procedure tfmakerulestk_dd,tfmakerulestk_dr\n end interface\n\n interface ktfnonoperq\n module procedure ktfnonoperqk,ktfnonoperqd\n end interface\n\n interface ktfoperq\n module procedure ktfoperqk,ktfoperqd\n end interface\n\n interface ktfrefq\n module procedure ktfrefqk,ktfrefqd\n end interface\n\n interface tfnumberq\n module procedure tfnumberqk,tfnumberqd\n end interface\n\n interface ktfnonsymbolq\n module procedure ktfnonsymbolqk,ktfnonsymbolqd\n end interface\n\n interface tfsameq\n module procedure tfsameqk,tfsameqd\n end interface\n\n interface tfsamesymbolq\n module procedure tfsamesymbolqk,tfsamesymbolqd,tfsamesymbolqo\n end interface\n\n interface tfsamestringq\n module procedure tfsamestringqk,tfsamestringqd,tfsamestringqo\n end interface\n\n interface tfconstq\n module procedure tfconstqk,tfconstqd\n end interface\n\n interface tfconstpatternq\n module procedure tfconstpatternqk,tfconstpatternqd\n end interface\n\n interface tfsameheadq\n module procedure tfsameheadqk,tfsameheadqd\n end interface\n\n interface tfexprq\n module procedure tfexprqk,tfexprqd\n end interface\n\n interface tfinequalityq\n module procedure tfinequalityqk,tfinequalityqd\n end interface\n\n contains\n subroutine tfinitstk\n use iso_c_binding\n use tfmem, only:maxstack,minstack\n implicit none\n integer*4 idummy\n if(tfstkinit)then\n return\n endif\nc mstk=max(2**18,int(rgetgl1('STACKSIZ')))\n mstk=int(maxstack*2)\n ispbase=0\n do while (ispbase .le. 0)\n mstk=mstk/2\n if(mstk .lt. minstack)then\n write(*,*)'Stack allocation failed: ',mstk,ispbase\n call abort\n endif\n ispbase=ktaloc(mstk*2)-1\n enddo\n call rsetGL('STACKSIZ',dble(mstk/2),idummy)\n isp=0\n isporg=isp+1\n ivstkoffset=mstk\n ipurefp=0\n napuref=0\n call c_f_pointer(c_loc(klist(ispbase+1)),vstk,[klistlen])\n call c_f_pointer(c_loc(klist(ispbase+1)),rtastk,[klistlen])\n call c_f_pointer(c_loc(klist(ispbase+1)),ktastk,[klistlen])\n call c_f_pointer(c_loc(klist(ispbase+1)),dtastk,[klistlen])\n call c_f_pointer(c_loc(klist(ispbase+1)),itastk,[2,klistlen])\n call c_f_pointer(c_loc(klist(ispbase+1)),ivstk,[2,klistlen])\n call c_f_pointer(c_loc(klist(ivstkoffset+ispbase+1)),\n $ vstk2,[klistlen])\n call c_f_pointer(c_loc(klist(ivstkoffset+ispbase+1)),\n $ rtastk2,[klistlen])\n call c_f_pointer(c_loc(klist(ivstkoffset+ispbase+1)),\n $ ktastk2,[klistlen])\n call c_f_pointer(c_loc(klist(ivstkoffset+ispbase+1)),\n $ dtastk2,[klistlen])\n call c_f_pointer(c_loc(klist(ivstkoffset+ispbase+1)),\n $ itastk2,[2,klistlen])\n call c_f_pointer(c_loc(klist(ivstkoffset+ispbase+1)),\n $ ivstk2,[2,klistlen])\n call c_f_pointer(c_loc(klist(1)),dlist,[klistlen])\n tfstkinit=.true.\n return\n end subroutine\n\n integer*8 function ktfsadalloc(n)\n use tfmem\n use iso_c_binding\n implicit none\n integer*8 , intent(in) :: n\n integer*4 istat,i\n ktfsadalloc=0\n do i=icbk+1,ncbk\n allocate(sadalloc(i)%ca(n),stat=istat)\n if(istat .ne. 0)then\nc write(*,*)'ktfsadalloc allocation error in ALLOCATE: ',\nc $ n,i,istat\n ktfsadalloc=-1\n return\n endif\n icbk=icbk+1\n ktfsadalloc=sad_loc(sadalloc(i)%ca(1))\n if(ktfsadalloc .ge. 0)then\n call tfentercbk(ktfsadalloc,n)\n return\n else\n write(*,*)'Negative allocation - retry: ',i,ktfsadalloc\n endif\n enddo\n if(icbk .ge. ncbk)then\n write(*,*)'ktfsadalloc too many allocations: ',icbk\n call abort\n endif\n end function\n\n subroutine tfentercbk(ka,n)\n use tfmem\n implicit none\n integer*8 , intent(in) :: ka,n\n integer*4 j,j0,k\n j0=jcbk+1\n do j=1,jcbk\n if(kcbk(2,j) .eq. ka-1)then\n kcbk(2,j)=ka+n-1\n kcbk(3,j)=kcbk(2,j)\n do k=1,jcbk\n if(kcbk(1,k) .eq. kcbk(2,j)+1)then\n if(k .lt. j)then\n kcbk(1,k)=kcbk(1,j)\n kcbk(:,j)=0\n if(j .eq. jcbk)then\n jcbk=jcbk-1\n endif\n else\n kcbk(2:3,j)=kcbk(2,k)\nc kcbk(3,j)=kcbk(2,k)\n kcbk(:,k)=0\n endif\n return\n endif\n enddo\n elseif(kcbk(1,j) .eq. ka+n)then\n kcbk(1,j)=ka\n do k=1,jcbk\n if(kcbk(2,k) .eq. kcbk(1,j)+1)then\n if(k .lt. j)then\n kcbk(2:3,k)=kcbk(2:3,j)\n kcbk(:,j)=0\n if(j .eq. jcbk)then\n jcbk=jcbk-1\n endif\n else\n kcbk(1,j)=kcbk(1,k)\n kcbk(:,k)=0\n endif\n return\n endif\n enddo\n elseif(kcbk(2,j) .eq. 0)then\n j0=min(j0,j)\n endif\n enddo\n kcbk(1,j0)=ka\n kcbk(2,j0)=ka+n-1\n kcbk(3,j0)=kcbk(2,j0)\n jcbk=max(jcbk,j0)\n return\n end subroutine\n\n integer*4 pure function itfcbk(k)\n use tfmem\n implicit none\n integer*8 , intent(in) ::k\n integer*4 i\n do i=1,jcbk\n if(k .le. kcbk(2,i) .and. k .ge. kcbk(1,i))then\n itfcbk=i\n return\n endif\n enddo\n itfcbk=0\n return\n end\n\n subroutine tfsetlastp(k)\n use tfmem\n implicit none\n integer*8 , intent(in) ::k\n integer*4 i\n i=itfcbk(k)\n if(i .ne. 0)then\n kcbk(3,i)=max(kcbk(3,i),k)\n endif\n return\n end\n\n logical*4 function tfchecklastp(k)\n use tfmem\n implicit none\n integer*8, intent(in):: k\n integer*4 i\n i=itfcbk(k)\n tfchecklastp=merge(k .le. kcbk(3,i),.false.,i .ne. 0)\n if(.not. tfchecklastp)then\n if(i .ne. 0)then\n write(*,*)'tfcklastp ',k,i,kcbk(3,i),kcbk(2,i)\n else\n write(*,*)'tfcklastp ',k,0\n endif\n endif\n return\n end\n\n integer*4 function iget_fun_id(ka)\n use iso_c_binding\n implicit none\n type (sad_funtbl), pointer :: fun\n integer*8 , intent(in):: ka\n call c_f_pointer(c_loc(klist(klist(ifunbase+ka)-9)),fun)\n iget_fun_id=fun%id\n return\n end function\n\n subroutine dlist_list(dlist,list)\n use iso_c_binding\n implicit none\n type (sad_dlist), target, intent(in) :: dlist\n type (sad_list), pointer, intent(out) :: list\n call c_f_pointer(c_loc(dlist),list)\n return\n end subroutine\n\n subroutine dlist_rlist(dlist,rlist)\n use iso_c_binding\n implicit none\n type (sad_dlist), target, intent(in) :: dlist\n type (sad_rlist), pointer, intent(out) :: rlist\n call c_f_pointer(c_loc(dlist),rlist)\n return\n end subroutine\n\n subroutine list_dlist(list,dlist)\n use iso_c_binding\n implicit none\n type (sad_list), target, intent(in) :: list\n type (sad_dlist), pointer, intent(out) :: dlist\n call c_f_pointer(c_loc(list),dlist)\n return\n end subroutine\n\n subroutine loc_list(locp,list)\n use iso_c_binding\n implicit none\n type (sad_list), pointer, intent(out) :: list\n integer*8 , intent(in) :: locp\n call c_f_pointer(c_loc(klist(locp-3)),list)\n return\n end subroutine\n\n subroutine loc_dlist(locp,dlist)\n use iso_c_binding\n implicit none\n type (sad_dlist), pointer, intent(out) :: dlist\n integer*8 , intent(in) :: locp\n call c_f_pointer(c_loc(klist(locp-3)),dlist)\n return\n end subroutine\n\n subroutine loc_rlist(locp,rlist)\n use iso_c_binding\n implicit none\n type (sad_rlist), pointer, intent(out) :: rlist\n integer*8 , intent(in) :: locp\n call c_f_pointer(c_loc(klist(locp-3)),rlist)\n return\n end subroutine\n\n subroutine descr_list(dscr,list)\n implicit none\n type (sad_descriptor) , intent(in)::dscr\n type (sad_list), pointer, intent(out) :: list\n call loc_list(ktfaddrd(dscr),list)\n return\n end subroutine\n\n subroutine descr_rlist(dscr,list)\n implicit none\n type (sad_descriptor) , intent(in)::dscr\n type (sad_rlist), pointer, intent(out) :: list\n call loc_rlist(ktfaddrd(dscr),list)\n return\n end subroutine\n\n subroutine descr_dlist(dscr,dlist)\n implicit none\n type (sad_descriptor) , intent(in)::dscr\n type (sad_dlist), pointer, intent(out) :: dlist\n call loc_dlist(ktfaddrd(dscr),dlist)\n return\n end subroutine\n\n subroutine loc_complex(locp,cx)\n use iso_c_binding\n implicit none\n type (sad_complex), pointer, intent(out) :: cx\n integer*8 , intent(in)::locp\n call c_f_pointer(c_loc(klist(locp-3)),cx)\n return\n end subroutine\n\n subroutine descr_complex(dscr,complex)\n implicit none\n type (sad_descriptor) , intent(in)::dscr\n type (sad_complex), pointer, intent(out) :: complex\n call loc_complex(ktfaddrd(dscr),complex)\n return\n end subroutine\n\n subroutine loc_obj(locp,obj)\n use iso_c_binding\n implicit none\n type (sad_object), pointer, intent(out) :: obj\n integer*8 , intent(in)::locp\n call c_f_pointer(c_loc(klist(locp-3)),obj)\n return\n end subroutine\n\n subroutine descr_obj(dscr,obj)\n implicit none\n type (sad_descriptor) , intent(in)::dscr\n type (sad_object), pointer, intent(out) :: obj\n call loc_obj(ktfaddrd(dscr),obj)\n return\n end subroutine\n\n subroutine loc_namtbl(locp,loc)\n use iso_c_binding\n implicit none\n type (sad_namtbl), pointer, intent(out) :: loc\n integer*8 , intent(in)::locp\n call c_f_pointer(c_loc(klist(locp-1)),loc)\n return\n end subroutine\n\n subroutine descr_namtbl(dscr,namtbl)\n implicit none\n type (sad_descriptor) , intent(in):: dscr\n type (sad_namtbl), pointer, intent(out) :: namtbl\n call loc_namtbl(ktfaddrd(dscr),namtbl)\n return\n end subroutine\n\n subroutine sym_namtbl(sym,loc)\n implicit none\n type (sad_symbol) , intent(in)::sym\n type (sad_namtbl), pointer, intent(out) :: loc\n call loc_namtbl(sym%loc,loc)\n return\n end subroutine\n\n subroutine sym_symstr(sym,str)\n implicit none\n type (sad_symbol) , intent(in)::sym\n type (sad_string), pointer, intent(out) :: str\n call loc_symstr(sym%loc,str)\n return\n end subroutine\n\n subroutine loc_symstr(loc,str)\n implicit none\n integer*8 , intent(in)::loc\n type (sad_string), pointer, intent(out) :: str\n type (sad_namtbl), pointer :: nam\n if(loc .eq. 0)then\n call loc_sad(ktfaddr(kxnulls),str)\n else\n call loc_namtbl(loc,nam)\n str=>nam%str\n endif\n return\n end subroutine\n\n subroutine loc_pat(locp,pat)\n use iso_c_binding\n implicit none\n type (sad_pat), pointer, intent(out) :: pat\n integer*8 , intent(in)::locp\n call c_f_pointer(c_loc(klist(locp-3)),pat)\n return\n end subroutine\n\n subroutine descr_pat(dscr,pat)\n implicit none\n type (sad_descriptor) , intent(in)::dscr\n type (sad_pat), pointer, intent(out) :: pat\n call loc_pat(ktfaddrd(dscr),pat)\n return\n end subroutine\n\n subroutine loc_string(locp,str)\n use iso_c_binding\n implicit none\n type (sad_string), pointer, intent(out) :: str\n integer*8 , intent(in)::locp\n call c_f_pointer(c_loc(klist(locp-3)),str)\n return\n end subroutine\n\n subroutine descr_string(dscr,string)\n implicit none\n type (sad_descriptor) , intent(in)::dscr\n type (sad_string), pointer, intent(out) :: string\n call loc_string(ktfaddrd(dscr),string)\n return\n end subroutine\n\n subroutine loc_sym(locp,sym)\n use iso_c_binding\n implicit none\n type (sad_symbol), pointer, intent(out) :: sym\n integer*8 , intent(in)::locp\n call c_f_pointer(c_loc(klist(locp-3)),sym)\n return\n end subroutine\n\n subroutine descr_sym(dscr,symbol)\n implicit none\n type (sad_descriptor) , intent(in)::dscr\n type (sad_symbol), pointer, intent(out) :: symbol\n call loc_sym(ktfaddrd(dscr),symbol)\n return\n end subroutine\n\n subroutine loc1_symdef(locp1,symd)\n use iso_c_binding\n implicit none\n type (sad_symdef), pointer, intent(out) :: symd\n integer*8 , intent(in)::locp1\n call c_f_pointer(c_loc(klist(locp1-1)),symd)\n return\n end subroutine\n\n subroutine loc_symdef(locp,symd)\n use iso_c_binding\n implicit none\n type (sad_symdef), pointer, intent(out) :: symd\n integer*8 , intent(in)::locp\n call c_f_pointer(c_loc(klist(locp-9)),symd)\n return\n end subroutine\n\n subroutine descr_symdef(dscr,symdef)\n implicit none\n type (sad_descriptor) , intent(in)::dscr\n type (sad_symdef), pointer, intent(out) :: symdef\n call loc_symdef(ktfaddrd(dscr),symdef)\n return\n end subroutine\n\n subroutine sym_symdef(sym,symd)\n use iso_c_binding\n implicit none\n type (sad_symbol), target, intent(in) :: sym\n type (sad_symdef), pointer, intent(out) :: symd\n call c_f_pointer(c_loc(sym%dummy(1)),symd)\n return\n end subroutine\n\n subroutine loc_deftbl(locp,loc)\n use iso_c_binding\n implicit none\n type (sad_deftbl), pointer, intent(out) :: loc\n integer*8 , intent(in)::locp\n call c_f_pointer(c_loc(klist(locp-1)),loc)\n return\n end subroutine\n\n subroutine loc_defhash(locp,loc)\n use iso_c_binding\n implicit none\n type (sad_defhash), pointer, intent(out) :: loc\n integer*8 , intent(in)::locp\n call c_f_pointer(c_loc(klist(locp-1)),loc)\n return\n end subroutine\n\n subroutine dlist_dlist(kl,kl1)\n implicit none\n type (sad_dlist) , target, intent(in) :: kl\n type (sad_dlist), pointer, intent(out) :: kl1\n kl1=>kl\n return\n end subroutine dlist_dlist\n\n type (sad_descriptor) function dlist_descr(kl)\n implicit none\n type (sad_dlist) , intent(in)::kl\n dlist_descr%k=ktflist+sad_loc(kl%head)\n return\n end\n\n type (sad_descriptor) function list_descr(kl)\n implicit none\n type (sad_list) , intent(in)::kl\n list_descr%k=ktflist+sad_loc(kl%head)\n return\n end\n\n type (sad_descriptor) function rlist_descr(kl)\n implicit none\n type (sad_rlist) , intent(in)::kl\n rlist_descr%k=ktflist+sad_loc(kl%head)\n return\n end\n\n type (sad_descriptor) function symbol_descr(s)\n implicit none\n type (sad_symbol) , intent(in)::s\n symbol_descr%k=ktfsymbol+sad_loc(s%loc)\n return\n end\n\n type (sad_descriptor) function string_descr(s)\n implicit none\n type (sad_string) , intent(in)::s\n string_descr%k=ktfstring+sad_loc(s%nch)\n return\n end\n\n type (sad_descriptor) function pat_descr(p)\n implicit none\n type (sad_pat) , intent(in)::p\n pat_descr%k=ktfpat+sad_loc(p%len)+3\n return\n end\n\n integer*8 pure elemental function ktfaddrk(k)\n implicit none\n integer*8 , intent(in)::k\n ktfaddrk=iand(ktamask,k)\n return\n end function ktfaddrk\n\n integer*8 pure elemental function ktfaddrd(k)\n implicit none\n type (sad_descriptor) , intent(in)::k\n ktfaddrd=iand(ktamask,k%k)\n return\n end function ktfaddrd\n\n integer*8 pure elemental function ktftype(k)\n implicit none\n integer*8 , intent(in)::k\n ktftype=iand(ktfmask,k)\n return\n end function ktftype\n\n logical*4 function ktfobjqk(k,obj)\n implicit none\n type (sad_object), pointer, optional, intent(out) :: obj\n integer*8 , intent(in)::k\n if(iand(ktomask,k) .eq. ktfobj)then\n ktfobjqk=.true.\n if(present(obj))then\n call loc_obj(iand(ktamask,k),obj)\n endif\n else\n ktfobjqk=.false.\n endif\n return\n end function ktfobjqk\n\n logical*4 function ktfobjqd(k,obj)\n implicit none\n type (sad_descriptor) , intent(in)::k\n type (sad_object), pointer, optional, intent(out) :: obj\n if(iand(ktomask,k%k) .eq. ktfobj)then\n ktfobjqd=.true.\n if(present(obj))then\n call loc_obj(iand(ktamask,k%k),obj)\n endif\n else\n ktfobjqd=.false.\n endif\n return\n end function ktfobjqd\n\n integer*8 pure elemental function ktaobjk(k) result(ka)\n use tfmem,only:kfirstalloc\n implicit none\n integer*8 , intent(in)::k\n ka=merge(iand(ktamask,k),kfirstalloc+1,\n $ iand(ktomask,k) .eq. ktfobj)\n return\n end function ktaobjk\n\n integer*8 pure elemental function ktaobjd(k) result(ka)\n use tfmem,only:kfirstalloc\n implicit none\n type (sad_descriptor) , intent(in)::k\n ka=merge(iand(ktamask,k%k),kfirstalloc+1,\n $ iand(ktomask,k%k) .eq. ktfobj)\n return\n end function ktaobjd\n\n logical*4 pure elemental function ktfnonobjq(ka)\n implicit none\n integer*8 , intent(in)::ka\n ktfnonobjq=iand(ktomask,ka) .ne. ktfobj\n return\n end function ktfnonobjq\n\n logical*4 function ktfnanq(x)\n implicit none\n real*8 , intent(in)::x\n ktfnanq=transfer(x,i00) .eq. ktfnan\n return\n end\n\n logical*4 pure elemental function ktfenanq(x)\n use iso_c_binding\n implicit none\n real*8 , intent(in)::x\n integer*8 k\nc k=kfromr(x)\n k=transfer(x,i00)\n ktfenanq=k .eq. knotanumber .or.\n $ iand(k,ktfenan) .eq. ktfenan .and.\n $ iand(k,ktfenanb) .ne. 0 .and. k .ne. kinfinity .and.\n $ k .ne. kminfinity\n return\n end function \n\n logical*4 pure elemental function ktfenanzeroq(x)\n implicit none\n real*8 , intent(in)::x\n ktfenanzeroq=x .eq. 0.d0 .and. ktfenanq(x)\n return\n end function \n\n logical*4 function ktfrealq_k(k,v)\n implicit none\n integer*8 , intent(in)::k\n real*8, optional, intent(out) :: v\n ktfrealq_k=iand(ktrmask,k) .ne. ktfnr\n if(ktfrealq_k .and. present(v))then\n v=transfer(k,0.d0)\n endif\n return\n end function ktfrealq_k\n\n logical*4 function ktfrealq_d(k,v)\n implicit none\n type (sad_descriptor) , intent(in)::k\n real*8, optional, intent(out) :: v\n ktfrealq_d=iand(ktrmask,k%k) .ne. ktfnr\n if(ktfrealq_d .and. present(v))then\n v=k%x(1)\n endif\n return\n end function ktfrealq_d\n\n logical*4 function ktfrealq_ki(k,iv)\n implicit none\n integer*8 , intent(in)::k\n integer*4 , intent(out) :: iv\n ktfrealq_ki=iand(ktrmask,k) .ne. ktfnr\n if(ktfrealq_ki)then\n iv=int(transfer(k,0.d0))\n endif\n return\n end function ktfrealq_ki\n\n logical*4 function ktfrealq_di(k,iv)\n implicit none\n type (sad_descriptor) , intent(in)::k\n integer*4 , intent(out) :: iv\n ktfrealq_di=iand(ktrmask,k%k) .ne. ktfnr\n if(ktfrealq_di)then\n iv=int(k%x(1))\n endif\n return\n end function ktfrealq_di\n\n logical*4 function ktfrealq_dk(k,iv)\n implicit none\n type (sad_descriptor) , intent(in)::k\n integer*8 , intent(out) :: iv\n ktfrealq_dk=iand(ktrmask,k%k) .ne. ktfnr\n if(ktfrealq_dk)then\n iv=int8(k%x(1))\n endif\n return\n end function ktfrealq_dk\n\n logical*4 function ktfnonrealq_k(k,v)\n implicit none\n integer*8 , intent(in)::k\n real*8, optional, intent(out) :: v\n ktfnonrealq_k=iand(ktrmask,k) .eq. ktfnr\n if(.not. ktfnonrealq_k .and. present(v))then\n v=transfer(k,0.d0)\n endif\n return\n end function ktfnonrealq_k\n\n logical*4 function ktfnonrealq_d(k,v)\n implicit none\n type (sad_descriptor) , intent(in)::k\n real*8, optional, intent(out) :: v\n ktfnonrealq_d=iand(ktrmask,k%k) .eq. ktfnr\n if(.not. ktfnonrealq_d .and. present(v))then\n v=k%x(1)\n endif\n return\n end function ktfnonrealq_d\n\n logical*4 function ktfnonrealq_ki(k,iv)\n implicit none\n integer*8 , intent(in)::k\n integer*4 , intent(out) :: iv\n ktfnonrealq_ki=iand(ktrmask,k) .eq. ktfnr\n if(.not. ktfnonrealq_ki)then\n iv=int(transfer(k,0.d0))\n endif\n return\n end function ktfnonrealq_ki\n\n logical*4 function ktfnonrealq_di(k,iv)\n implicit none\n type (sad_descriptor) , intent(in)::k\n integer*4 , intent(out) :: iv\n ktfnonrealq_di=iand(ktrmask,k%k) .eq. ktfnr\n if(.not. ktfnonrealq_di)then\n iv=int(k%x(1))\n endif\n return\n end function ktfnonrealq_di\n\n logical*4 function ktfoperqk(k,ka)\n implicit none\n integer*8 , intent(in)::k\n integer*8 , optional, intent(out) :: ka\n ktfoperqk=iand(ktfmask,k) .eq. ktfoper\n if(ktfoperqk .and. present(ka))then\n ka=ktfaddr(k)\n endif\n return\n end function ktfoperqk\n\n logical*4 function ktfnonoperqk(k,ka)\n implicit none\n integer*8 , intent(in)::k\n integer*8 , optional, intent(out) :: ka\n ktfnonoperqk=iand(ktfmask,k) .ne. ktfoper\n if(.not. ktfnonoperqk .and. present(ka))then\n ka=ktfaddr(k)\n endif\n return\n end function ktfnonoperqk\n\n logical*4 function ktfoperqd(k,ka) result(v)\n implicit none\n type (sad_descriptor) , intent(in)::k\n integer*8, optional, intent(out) :: ka\n v=iand(ktfmask,k%k) .eq. ktfoper\n if(v .and. present(ka))then\n ka=ktfaddr(k)\n endif\n return\n end function ktfoperqd\n\n logical*4 function ktfnonoperqd(k,ka)\n implicit none\n type (sad_descriptor) , intent(in)::k\n integer*8, optional, intent(out) :: ka\n ktfnonoperqd=iand(ktfmask,k%k) .ne. ktfoper\n if(.not. ktfnonoperqd .and. present(ka))then\n ka=ktfaddr(k)\n endif\n return\n end function ktfnonoperqd\n\n logical*4 function ktfstringqk(k,str)\n implicit none\n type (sad_string), pointer, optional, intent(out) :: str\n integer*8 , intent(in)::k\n ktfstringqk=iand(ktfmask,k) .eq. ktfstring\n if(present(str) .and. ktfstringqk)then\n call loc_string(ktfaddr(k),str)\n endif\n return\n end function ktfstringqk\n\n logical*4 function ktfstringqd(k,str)\n implicit none\n type (sad_descriptor) , intent(in)::k\n type (sad_string), pointer, optional, intent(out) :: str\n ktfstringqd=iand(ktfmask,k%k) .eq. ktfstring\n if(present(str) .and. ktfstringqd)then\n call loc_string(ktfaddr(k%k),str)\n endif\n return\n end function ktfstringqd\n\n logical*4 function ktfnonstringq(k,str)\n implicit none\n type (sad_string), pointer, optional, intent(out) :: str\n integer*8 , intent(in)::k\n ktfnonstringq=iand(ktfmask,k) .ne. ktfstring\n if(present(str) .and. .not. ktfnonstringq)then\n call loc_string(ktfaddr(k),str)\n endif\n return\n end function ktfnonstringq\n\n logical*4 function ktflistq_rlist(k,kl)\n implicit none\n type (sad_rlist), pointer, intent(out) :: kl\n integer*8 , intent(in)::k\n if(iand(ktfmask,k) .eq. ktflist)then\n ktflistq_rlist=.true.\n call loc_sad(iand(ktamask,k),kl)\n else\n ktflistq_rlist=.false.\n endif \n return\n end function ktflistq_rlist\n\n logical*4 function ktflistq_dlist(k,kl)\n implicit none\n type (sad_dlist), pointer, optional, intent(out) :: kl\n integer*8 , intent(in)::k\n if(iand(ktfmask,k) .eq. ktflist)then\n ktflistq_dlist=.true.\n if(present(kl))then\n call loc_dlist(iand(ktamask,k),kl)\n endif\n else\n ktflistq_dlist=.false.\n endif \n return\n end function ktflistq_dlist\n\n logical*4 function ktflistqd_rlist(k,kl)\n implicit none\n type (sad_rlist), pointer, intent(out) :: kl\n type (sad_descriptor), intent(in):: k\n if(iand(ktfmask,k%k) .eq. ktflist)then\n ktflistqd_rlist=.true.\n call loc_sad(iand(ktamask,k%k),kl)\n else\n ktflistqd_rlist=.false.\n endif \n return\n end function ktflistqd_rlist\n\n logical*4 function ktflistqd_dlist(k,kl)\n implicit none\n type (sad_dlist), pointer, optional, intent(out) :: kl\n type (sad_descriptor), intent(in):: k\n if(iand(ktfmask,k%k) .eq. ktflist)then\n ktflistqd_dlist=.true.\n if(present(kl))then\n call loc_dlist(iand(ktamask,k%k),kl)\n endif\n else\n ktflistqd_dlist=.false.\n endif \n return\n end function ktflistqd_dlist\n\n logical*4 function ktfnonlistq_rlist(k,kl)\n implicit none\n type (sad_rlist), pointer, intent(out) :: kl\n integer*8 k\n if(iand(ktfmask,k) .eq. ktflist)then\n ktfnonlistq_rlist=.false.\n call loc_sad(iand(ktamask,k),kl)\n else\n ktfnonlistq_rlist=.true.\n endif \n return\n end function ktfnonlistq_rlist\n\n logical*4 function ktfnonlistq_dlist(k,kl)\n implicit none\n type (sad_dlist), pointer, optional, intent(out) :: kl\n integer*8 , intent(in)::k\n if(iand(ktfmask,k) .eq. ktflist)then\n ktfnonlistq_dlist=.false.\n if(present(kl))then\n call loc_dlist(iand(ktamask,k),kl)\n endif\n else\n ktfnonlistq_dlist=.true.\n endif \n return\n end function ktfnonlistq_dlist\n\n logical*4 function ktfnonlistqd_rlist(k,kl)\n implicit none\n type (sad_rlist), pointer, intent(out) :: kl\n type (sad_descriptor), intent(in):: k\n if(iand(ktfmask,k%k) .eq. ktflist)then\n ktfnonlistqd_rlist=.false.\n call loc_sad(iand(ktamask,k%k),kl)\n else\n ktfnonlistqd_rlist=.true.\n endif \n return\n end function ktfnonlistqd_rlist\n\n logical*4 function ktfnonlistqd_dlist(k,kl)\n implicit none\n type (sad_dlist), pointer, optional, intent(out) :: kl\n type (sad_descriptor), intent(in):: k\n if(iand(ktfmask,k%k) .eq. ktflist)then\n ktfnonlistqd_dlist=.false.\n if(present(kl))then\n call loc_dlist(iand(ktamask,k%k),kl)\n endif\n else\n ktfnonlistqd_dlist=.true.\n endif \n return\n end function ktfnonlistqd_dlist\n\n logical*4 function tflistq_rlist(k,kl)\n implicit none\n type (sad_rlist), pointer, optional, intent(out) :: kl\n integer*8 , intent(in)::k\n if(iand(ktfmask,k) .eq. ktflist .and.\n $ klist(ktfaddr(k)) .eq. ktfoper+mtflist)then\n tflistq_rlist=.true.\n if(present(kl))then\n call loc_sad(iand(ktamask,k),kl)\n endif\n else\n tflistq_rlist=.false.\n endif \n return\n end function tflistq_rlist\n\n logical*4 function tflistq_dlist(k,kl)\n implicit none\n type (sad_dlist), pointer, intent(out) :: kl\n integer*8 , intent(in)::k\n if(iand(ktfmask,k) .eq. ktflist .and.\n $ klist(ktfaddr(k)) .eq. ktfoper+mtflist)then\n tflistq_dlist=.true.\n call loc_dlist(iand(ktamask,k),kl)\n else\n tflistq_dlist=.false.\n endif \n return\n end function tflistq_dlist\n\n logical*4 function tflistqd_rlist(k,kl)\n implicit none\n type (sad_rlist), pointer, intent(out) :: kl\n type (sad_descriptor), intent(in):: k\n if(iand(ktfmask,k%k) .eq. ktflist .and.\n $ klist(ktfaddr(k%k)) .eq. ktfoper+mtflist)then\n tflistqd_rlist=.true.\n call loc_sad(iand(ktamask,k%k),kl)\n else\n tflistqd_rlist=.false.\n endif \n return\n end function tflistqd_rlist\n\n logical*4 function tflistqd_dlist(k,kl)\n implicit none\n type (sad_dlist), pointer, optional, intent(out) :: kl\n type (sad_descriptor), intent(in):: k\n if(iand(ktfmask,k%k) .eq. ktflist .and.\n $ klist(ktfaddr(k%k)) .eq. ktfoper+mtflist)then\n tflistqd_dlist=.true.\n if(present(kl))then\n call loc_dlist(iand(ktamask,k%k),kl)\n endif\n else\n tflistqd_dlist=.false.\n endif \n return\n end function tflistqd_dlist\n\n logical*4 function tfnonlistq_rlist(k,kl)\n implicit none\n type (sad_rlist), pointer, optional, intent(out) :: kl\n integer*8 , intent(in)::k\n if(iand(ktfmask,k) .eq. ktflist .and.\n $ klist(ktfaddr(k)) .eq. ktfoper+mtflist)then\n tfnonlistq_rlist=.false.\n if(present(kl))then\n call loc_sad(iand(ktamask,k),kl)\n endif\n else\n tfnonlistq_rlist=.true.\n endif \n return\n end function tfnonlistq_rlist\n\n logical*4 function tfnonlistq_dlist(k,kl)\n implicit none\n type (sad_dlist), pointer, intent(out) :: kl\n integer*8 , intent(in)::k\n if(iand(ktfmask,k) .eq. ktflist .and.\n $ klist(ktfaddr(k)) .eq. ktfoper+mtflist)then\n tfnonlistq_dlist=.false.\n call loc_dlist(iand(ktamask,k),kl)\n else\n tfnonlistq_dlist=.true.\n endif \n return\n end function tfnonlistq_dlist\n\n logical*4 function tfnonlistqd_rlist(k,kl)\n implicit none\n type (sad_rlist), pointer, optional, intent(out) :: kl\n type (sad_descriptor), intent(in):: k\n if(iand(ktfmask,k%k) .eq. ktflist .and.\n $ klist(ktfaddr(k%k)) .eq. ktfoper+mtflist)then\n tfnonlistqd_rlist=.false.\n if(present(kl))then\n call loc_sad(iand(ktamask,k%k),kl)\n endif\n else\n tfnonlistqd_rlist=.true.\n endif \n return\n end function tfnonlistqd_rlist\n\n logical*4 function tfnonlistqd_dlist(k,kl)\n implicit none\n type (sad_dlist), pointer, intent(out) :: kl\n type (sad_descriptor), intent(in):: k\n if(iand(ktfmask,k%k) .eq. ktflist .and.\n $ klist(ktfaddr(k%k)) .eq. ktfoper+mtflist)then\n tfnonlistqd_dlist=.false.\n call loc_dlist(iand(ktamask,k%k),kl)\n else\n tfnonlistqd_dlist=.true.\n endif \n return\n end function tfnonlistqd_dlist\n\n logical*4 function tfreallistqd(k,kl)\n implicit none\n type (sad_descriptor), intent(in):: k\n type (sad_rlist), pointer, optional, intent(out) :: kl\n type (sad_dlist), pointer :: kl1\n if(ktflistq(k,kl1))then\n tfreallistqd=kl1%head%k .eq. ktfoper+mtflist\n $ .and. ktfreallistq(kl1)\n if(tfreallistqd .and. present(kl))then\n call descr_sad(k,kl)\n endif\n else\n tfreallistqd=.false.\n endif\n return\n end function\n\n logical*4 function tfreallistqk(k,kl)\n use iso_c_binding\n implicit none\n type (sad_rlist), pointer, optional, intent(out) :: kl\n type (sad_rlist), pointer :: kl1\n integer*8 k\n if(ktflistq(k,kl1))then\n tfreallistqk=kl1%head%k .eq. ktfoper+mtflist\n $ .and. ktfreallistq(kl1)\n if(tfreallistqk .and. present(kl))then\n kl=>kl1\n endif\n else\n tfreallistqk=.false.\n endif\n return\n end function\n\n logical*4 function tfnonreallistqd(k,kl)\n implicit none\n type (sad_descriptor) , intent(in)::k\n type (sad_rlist), pointer, optional, intent(out) :: kl\n tfnonreallistqd=.not. tfreallistqd(k,kl)\n return\n end function\n\n logical*4 function tfnonreallistqk(k,kl)\n use iso_c_binding\n implicit none\n type (sad_rlist), pointer, optional, intent(out) :: kl\n integer*8 , intent(in)::k\n tfnonreallistqk=.not. tfreallistqk(k,kl)\n return\n end function\n\n logical*4 function ktflistqx(k,cx)\n implicit none\n type (sad_complex), pointer, optional, intent(out) :: cx\n integer*8 , intent(in)::k\n if(iand(ktfmask,k) .eq. ktflist)then\n ktflistqx=.true.\n if(present(cx))then\n call loc_complex(iand(ktamask,k),cx)\n endif\n else\n ktflistqx=.false.\n endif \n return\n end function ktflistqx\n\n logical*4 function tfnonlistqk_rlist(k,kl)\n implicit none\n type (sad_rlist), pointer, intent(out) :: kl\n integer*8 , intent(in)::k\n integer*8 ka\n if(iand(ktfmask,k) .eq. ktflist)then\n ka=ktfaddr(k)\n if(klist(ka) .eq. ktfoper+mtflist)then\n tfnonlistqk_rlist=.false.\n call loc_rlist(ka,kl)\n return\n endif\n endif\n tfnonlistqk_rlist=.true.\n return\n end function tfnonlistqk_rlist\n\n logical*4 function tfnonlistqk_dlist(k,kl)\n implicit none\n type (sad_dlist), pointer, intent(out) :: kl\n integer*8 , intent(in)::k\n integer*8 ka\n if(iand(ktfmask,k) .eq. ktflist)then\n ka=ktfaddr(k)\n if(klist(ka) .eq. ktfoper+mtflist)then\n tfnonlistqk_dlist=.false.\n call loc_dlist(ka,kl)\n return\n endif\n endif\n tfnonlistqk_dlist=.true.\n return\n end function tfnonlistqk_dlist\n\n recursive logical*4 function tfruleqk_dlist(k,klx) result(lx)\n implicit none\n type (sad_dlist), pointer :: kl\n type (sad_dlist), pointer, optional, intent(out) :: klx\n integer*8 , intent(in)::k\n integer*4 i\n lx=.false.\n if(ktflistq(k,kl))then\n select case (kl%head%k)\n case (ktfoper+mtflist)\n if(.not. ktfnonreallistqo(kl))return\n do i=1,kl%nl\n if(.not. tfruleqk_dlist(kl%dbody(i)%k))then\n return\n endif\n enddo\n case (ktfoper+mtfrule,ktfoper+mtfruledelayed)\n if(kl%nl .ne. 2)return\n case default\n return\n end select\n else\n return\n endif\n lx=.true.\n if(present(klx))then\n klx=>kl\n endif\n return\n end function tfruleqk_dlist\n\n logical*4 function tfruleqd_dlist(k,klx)\n implicit none\n type (sad_descriptor) , intent(in)::k\n type (sad_dlist), pointer, optional, intent(out) :: klx\n tfruleqd_dlist=tfruleqk_dlist(k%k,klx)\n return\n end function tfruleqd_dlist\n\n logical*4 function tfnumberqk(k,c)\n implicit none\n integer*8 , intent(in)::k\n type (sad_complex), pointer :: cx\n complex*16, optional, intent(out) :: c\n real*8 v\n if(ktfrealq(k,v))then\n tfnumberqk=.true.\n if(present(c))then\n c=v\n endif\n else\n tfnumberqk=tfcomplexqx(k,cx)\n if(tfnumberqk .and. present(c))then\n c=cx%cx(1)\n endif\n endif\n return\n end function\n\n logical*4 function tfnumberqd(k,c)\n implicit none\n type (sad_descriptor) , intent(in)::k\n type (sad_complex), pointer :: cx\n complex*16, optional, intent(out) :: c\n real*8 v\n if(ktfrealq(k,v))then\n tfnumberqd=.true.\n if(present(c))then\n c=v\n endif\n else\n tfnumberqd=tfcomplexqx(k%k,cx)\n if(tfnumberqd .and. present(c))then\n c=cx%cx(1)\n endif\n endif\n return\n end function\n\n logical*4 function tfnumlistqnd(k,n,kl1)\n implicit none\n type (sad_descriptor) , intent(in)::k\n type (sad_rlist), pointer, optional, intent(out) :: kl1\n type (sad_dlist), pointer :: kl\n integer*4 , intent(in)::n \n if(ktflistq(k,kl))then\n tfnumlistqnd=kl%head%k .eq. ktfoper+mtflist\n $ .and. ktfreallistq(kl) .and. kl%nl .eq. n\n if(present(kl1))then\n call descr_rlist(k,kl1)\n endif\n else\n tfnumlistqnd=.false.\n endif\n return\n end function\n\n logical*4 function tfnumlistqnk(k,n,kl1)\n implicit none\n integer*8 , intent(in)::k\n type (sad_rlist), pointer, optional, intent(out) :: kl1\n type (sad_dlist), pointer :: kl\n integer*4 , intent(in)::n \n if(ktflistq(k,kl))then\n tfnumlistqnk=kl%head%k .eq. ktfoper+mtflist\n $ .and. ktfreallistq(kl) .and. kl%nl .eq. n\n if(present(kl1))then\n call loc_rlist(ktfaddr(k),kl1)\n endif\n else\n tfnumlistqnk=.false.\n endif\n return\n end function\n \n logical*4 function tfcomplexnumlistqk_dlist(k,klx)\n implicit none\n type (sad_dlist), pointer, optional, intent(out) :: klx\n type (sad_dlist), pointer :: kl\n integer*8 , intent(in)::k\n integer*4 i\n tfcomplexnumlistqk_dlist=.false.\n if(tflistq(k,kl))then\n if(ktfnonreallistqo(kl))then\n do i=1,kl%nl\n if(.not. tfnumberqd(kl%dbody(i)))then\n return\n endif\n enddo\n endif\n tfcomplexnumlistqk_dlist=.true.\n if(present(klx))then\n klx=>kl\n endif\n endif\n return\n end function\n \n logical*4 function ktfsymbolqk(k,sym)\n implicit none\n type (sad_symbol), pointer, optional, intent(out) :: sym\n integer*8 , intent(in)::k\n ktfsymbolqk=iand(ktfmask,k) .eq. ktfsymbol\n if(present(sym) .and. ktfsymbolqk)then\n call loc_sym(ktfaddr(k),sym)\n endif\n return\n end function ktfsymbolqk\n\n logical*4 function ktfnonsymbolqk(k,sym)\n implicit none\n type (sad_symbol), pointer, optional, intent(out) :: sym\n integer*8 , intent(in)::k\n ktfnonsymbolqk=iand(ktfmask,k) .ne. ktfsymbol\n if(present(sym) .and. .not. ktfnonsymbolqk)then\n call loc_sym(ktfaddr(k),sym)\n endif\n return\n end function ktfnonsymbolqk\n\n logical*4 function ktfsymbolqd(k,sym)\n implicit none\n type (sad_descriptor) , intent(in)::k\n type (sad_symbol), pointer, optional, intent(out) :: sym\n ktfsymbolqd=iand(ktfmask,k%k) .eq. ktfsymbol\n if(present(sym) .and. ktfsymbolqd)then\n call loc_sym(ktfaddr(k%k),sym)\n endif\n return\n end function ktfsymbolqd\n\n logical*4 function ktfnonsymbolqd(k,sym)\n implicit none\n type (sad_descriptor) , intent(in)::k\n type (sad_symbol), pointer, optional, intent(out) :: sym\n ktfnonsymbolqd=iand(ktfmask,k%k) .ne. ktfsymbol\n if(present(sym) .and. .not. ktfnonsymbolqd)then\n call loc_sym(ktfaddr(k%k),sym)\n endif\n return\n end function ktfnonsymbolqd\n\n logical*4 function ktfsymbolqdef(k,symd)\n implicit none\n type (sad_symdef), pointer, optional, intent(out) :: symd\n integer*8 , intent(in)::k\n ktfsymbolqdef=iand(ktfmask,k) .eq. ktfsymbol\n if(present(symd) .and. ktfsymbolqdef)then\n call loc_symdef(ktfaddr(k),symd)\n endif\n return\n end function ktfsymbolqdef\n\n logical*4 function ktfpatqk(k,pat)\n implicit none\n type (sad_pat), pointer, optional, intent(out) :: pat\n integer*8 , intent(in)::k\n if(iand(ktfmask,k) .eq. ktfpat)then\n ktfpatqk=.true.\n if(present(pat))then\n call loc_pat(iand(ktamask,k),pat)\n endif\n else\n ktfpatqk=.false.\n endif\n return\n end function ktfpatqk\n\n logical*4 function ktfpatqd(k,pat)\n implicit none\n type (sad_descriptor) , intent(in)::k\n type (sad_pat), pointer, optional, intent(out) :: pat\n ktfpatqd=ktfpatqk(k%k,pat)\n return\n end function ktfpatqd\n\n logical*4 function ktfnonpatq(k,pat)\n implicit none\n type (sad_pat), pointer, optional, intent(out) :: pat\n integer*8 , intent(in)::k\n ktfnonpatq=iand(ktfmask,k) .ne. ktfpat\n if(present(pat) .and. .not. ktfnonpatq)then\n call loc_pat(ktfaddr(k),pat)\n endif\n return\n end function ktfnonpatq\n\n logical*4 function ktfrefqk(k,ka)\n implicit none\n integer*8 , intent(in)::k\n integer*8 , optional, intent(out) :: ka\n ktfrefqk=iand(ktfmask,k) .eq. ktfref\n if(ktfrefqk .and. present(ka))then\n ka=ktfaddr(k)\n endif\n return\n end function ktfrefqk\n\n logical*4 function ktfrefqd(k,ka)\n implicit none\n type (sad_descriptor) , intent(in)::k\n integer*8 , optional, intent(out) :: ka\n ktfrefqd=iand(ktfmask,k%k) .eq. ktfref\n if(ktfrefqd .and. present(ka))then\n ka=ktfaddr(k%k)\n endif\n return\n end function ktfrefqd\n\n logical*4 pure elemental function ktfnonrefq(k)\n implicit none\n integer*8 , intent(in)::k\n ktfnonrefq=iand(ktfmask,k) .ne. ktfref\n return\n end function ktfnonrefq\n\n logical*4 pure elemental function ktfreallistqk(ka)\n implicit none\n integer*8 , intent(in)::ka\n ktfreallistqk=iand(ilist(2,ka-3),lnonreallist) .eq. 0\n return\n end function ktfreallistqk\n\n logical*4 function ktfreallistqk_rlist(ka,kl)\n implicit none\n type (sad_rlist), pointer, intent(out) :: kl\n integer*8 , intent(in)::ka\n ktfreallistqk_rlist=iand(ilist(2,ka-3),lnonreallist) .eq. 0\n if(ktfreallistqk_rlist)then\n call loc_sad(ka,kl)\n endif\n return\n end function ktfreallistqk_rlist\n\n logical*4 pure elemental function ktfreallistqd(ka)\n implicit none\n type (sad_descriptor) , intent(in)::ka\n ktfreallistqd=iand(ilist(2,ktfaddrd(ka)-3),lnonreallist) .eq. 0\n return\n end function ktfreallistqd\n\n logical*4 function ktfreallistqd_rlist(ka,kl)\n implicit none\n type (sad_rlist), pointer, intent(out) :: kl\n type (sad_descriptor) , intent(in)::ka\n ktfreallistqd_rlist=\n $ iand(ilist(2,ktfaddrd(ka)-3),lnonreallist) .eq. 0\n if(ktfreallistqd_rlist)then\n call loc_sad(ktfaddrd(ka),kl)\n endif\n return\n end function ktfreallistqd_rlist\n\n logical*4 pure elemental function ktfnonreallistq(ka)\n implicit none\n integer*8 , intent(in)::ka\n ktfnonreallistq=iand(ilist(2,ka-3),lnonreallist) .ne. 0\n return\n end function ktfnonreallistq\n\n logical*4 pure elemental function ktfreallistqo_rlist(list)\n implicit none\n type (sad_rlist) , intent(in)::list\n ktfreallistqo_rlist=iand(list%attr,lnonreallist) .eq. 0\n return\n end function ktfreallistqo_rlist\n\n logical*4 pure elemental function ktfreallistqo_dlist(list)\n implicit none\n type (sad_dlist) , intent(in)::list\n ktfreallistqo_dlist=iand(list%attr,lnonreallist) .eq. 0\n return\n end function ktfreallistqo_dlist\n\n logical*4 pure elemental function ktfnonreallistqo_rlist(list)\n implicit none\n type (sad_rlist) , intent(in)::list\n ktfnonreallistqo_rlist=iand(list%attr,lnonreallist) .ne. 0\n return\n end function ktfnonreallistqo_rlist\n\n logical*4 pure elemental function ktfnonreallistqo_dlist(list)\n implicit none\n type (sad_dlist) , intent(in)::list\n ktfnonreallistqo_dlist=iand(list%attr,lnonreallist) .ne. 0\n return\n end function ktfnonreallistqo_dlist\n\n logical*4 pure elemental function ktftrueq(ka)\n implicit none\n integer*8 , intent(in)::ka\n ktftrueq=ka .ne. 0 .and. iand(ktrmask,ka) .ne. ktfnr\n return\n end function ktftrueq\n\n logical*4 function ktfsequenceq_rlist(k,kl) result(v)\n implicit none\n type (sad_rlist), pointer, intent(out) :: kl\n integer*8 , intent(in)::k\n v=iand(ktfmask,k) .eq. ktflist .and.\n $ klist(iand(ktamask,k)) .eq. ktfoper+mtfnull\n if(v)then\n call loc_sad(iand(ktamask,k),kl)\n endif\n return\n end function ktfsequenceq_rlist\n\n logical*4 function ktfsequenceq_dlist(k,kl) result(v)\n implicit none\n type (sad_dlist), pointer, optional, intent(out) :: kl\n integer*8 , intent(in)::k\n v=iand(ktfmask,k) .eq. ktflist .and.\n $ klist(iand(ktamask,k)) .eq. ktfoper+mtfnull\n if(v .and. present(kl))then\n call loc_dlist(iand(ktamask,k),kl)\n endif\n return\n end function ktfsequenceq_dlist\n\n logical*4 function ktfsequenceqd_rlist(k,kl) result(v)\n implicit none\n type (sad_rlist), pointer, intent(out) :: kl\n type (sad_descriptor) , intent(in)::k\n v=iand(ktfmask,k%k) .eq. ktflist .and.\n $ klist(iand(ktamask,k%k)) .eq. ktfoper+mtfnull\n if(v)then\n call loc_sad(iand(ktamask,k%k),kl)\n endif\n return\n end function ktfsequenceqd_rlist\n\n logical*4 function ktfsequenceqd_dlist(k,kl) result(v)\n implicit none\n type (sad_dlist), pointer, optional, intent(out) :: kl\n type (sad_descriptor) , intent(in)::k\n v=iand(ktfmask,k%k) .eq. ktflist .and.\n $ klist(iand(ktamask,k%k)) .eq. ktfoper+mtfnull\n if(v .and. present(kl))then\n call loc_dlist(iand(ktamask,k%k),kl)\n endif\n return\n end function ktfsequenceqd_dlist\n\n logical*4 pure elemental function ktfprotectedq(ka)\n implicit none\n integer*8 , intent(in)::ka\n ktfprotectedq=iand(ilist(1,ka-3),iattrprotected) .ne. 0\n return\n end function ktfprotectedq\n\n logical*4 pure elemental function ktfprotectedqo(sym)\n implicit none\n type (sad_symbol) , intent(in)::sym\n ktfprotectedqo=iand(sym%attr,iattrprotected) .ne. 0\n return\n end function ktfprotectedqo\n\n logical*4 pure elemental function ktfconstantq(ka)\n implicit none\n integer*8 , intent(in)::ka\n ktfconstantq=iand(ilist(1,ka-3),iattrconstant) .ne. 0\n return\n end function ktfconstantq\n\n logical*4 pure elemental function ktfconstantsymq(sym)\n implicit none\n type (sad_symbol) , intent(in)::sym\n ktfconstantsymq=iand(sym%attr,iattrconstant) .ne. 0\n return\n end function ktfconstantsymq\n\n logical*4 pure elemental function ktfimmediateq(ka)\n implicit none\n integer*8 , intent(in)::ka\n ktfimmediateq=iand(ilist(1,ka-3),iattrimmediate) .ne. 0\n return\n end function ktfimmediateq\n\n logical*4 pure elemental function ktfnumericq(ka)\n implicit none\n integer*8 , intent(in)::ka\n ktfnumericq=iand(ilist(1,ka-3),iattrnumeric) .ne. 0\n return\n end function ktfnumericq\n\n logical*4 pure elemental function ktfovrwrtq(kl)\n implicit none\n type (sad_dlist) , intent(in)::kl\n ktfovrwrtq=kl%ref .le. 0 .or.\n $ kl%ref .eq. 1 .and. ktfaddr(kl%alloc) .eq. 0\n return\n end function ktfovrwrtq\n\n logical*4 function tfcomplexqdx(k,cx)\n implicit none\n type (sad_complex), pointer :: c\n type (sad_complex), pointer, optional, intent(out) :: cx\n type (sad_descriptor) , intent(in)::k\n tfcomplexqdx=ktflistqx(k%k,c) .and.\n $ c%head%k .eq. ktfoper+mtfcomplex\n $ .and. c%nl .eq. 2 .and.\n $ iand(lnonreallist,c%attr) .eq. 0\n if(tfcomplexqdx .and. present(cx))then\n cx=>c\n endif\n return\n end function\n\n logical*4 function tfcomplexqdc(k,cv)\n implicit none\n type (sad_complex), pointer :: c\n complex*16 cv\n type (sad_descriptor) , intent(in)::k\n tfcomplexqdc=ktflistqx(k%k,c) .and.\n $ c%head%k .eq. ktfoper+mtfcomplex\n $ .and. c%nl .eq. 2 .and.\n $ iand(lnonreallist,c%attr) .eq. 0\n if(tfcomplexqdc)then\n cv=c%cx(1)\n endif\n return\n end function\n\n logical*4 function tfcomplexqx(k,cx)\n implicit none\n type (sad_complex), pointer :: c\n type (sad_complex), pointer, optional, intent(out) :: cx\n integer*8 , intent(in)::k\n tfcomplexqx=ktflistqx(k,c) .and.\n $ c%head%k .eq. ktfoper+mtfcomplex\n $ .and. c%nl .eq. 2 .and.\n $ iand(lnonreallist,c%attr) .eq. 0\n if(tfcomplexqx .and. present(cx))then\n cx=>c\n endif\n return\n end function\n\n logical*4 function tfcomplexqc(k,cv)\n implicit none\n type (sad_complex), pointer :: c\n complex*16 cv\n integer*8 , intent(in)::k\n tfcomplexqc=ktflistqx(k,c) .and.\n $ c%head%k .eq. ktfoper+mtfcomplex\n $ .and. c%nl .eq. 2 .and.\n $ iand(lnonreallist,c%attr) .eq. 0\n if(tfcomplexqc)then\n cv=c%cx(1)\n endif\n return\n end function\n\n recursive logical*4 function tfsameqk(ka,kp) result(lx)\n use tfcode\n use iso_c_binding\n implicit none\n type (sad_dlist), pointer :: kla,klp\n type (sad_symbol), pointer :: syma,symp\n type (sad_string), pointer :: stra,strp\n type (sad_pat), pointer :: pata,patp\n integer*8 , intent(in)::ka,kp\n integer*8 nc\n if(ka .eq. kp)then\n lx=.true.\n return\n endif\n lx=.false.\n if(ktfrealq(ka) .or. ktfoperq(ka) .or.\n $ ktftype(ka) .ne. ktftype(kp))then\n return\n endif\n if(ktfsymbolq(ka,syma))then\n call loc_sad(ktfaddr(kp),symp)\n lx=tfsamesymbolqo(syma,symp)\n elseif(ktfstringq(ka,stra))then\n call loc_sad(ktfaddr(kp),strp)\n nc=stra%nch\n if(nc .eq. strp%nch)then\n lx=stra%str(1:nc) .eq. strp%str(1:nc)\n endif\n elseif(ktflistq(ka,kla))then\n call loc_sad(ktfaddr(kp),klp)\n if(kla%nl .eq. klp%nl)then\n lx=tfsamelistqo(kla,klp)\n endif\n elseif(ktfpatq(ka,pata))then\n call loc_sad(ktfaddr(kp),patp)\n if(.not. tfsameqk(pata%expr%k,patp%expr%k))then\n return\n endif\n if(.not. tfsameqk(pata%head%k,patp%head%k))then\n return\n endif\n if(.not. tfsameqk(pata%default%k,patp%default%k))then\n return\n endif\n lx=tfsamesymbolqk(ktfaddr(pata%sym%alloc),\n $ ktfaddr(patp%sym%alloc))\n endif\n return\n end function\n\n logical*4 function tfsameqd(ka,kp)\n implicit none\n type (sad_descriptor) , intent(in)::ka,kp\n tfsameqd=tfsameqk(ka%k,kp%k)\n return\n end function\n\n logical*4 function tfsamelistqo(lista,listp)\n implicit none\n type (sad_dlist) , intent(inout)::lista,listp\n type (sad_descriptor) kai,kpi\n integer*8 kaai,kapi\n integer*4 i,m\n tfsamelistqo=.false.\n m=lista%nl\n if(m .ne. listp%nl)then\n return\n endif\n do i=0,m\n kai=lista%dbody(i)\n kpi=listp%dbody(i)\n if(kai%k .ne. kpi%k)then\n if(ktfobjq(kai))then\n if(tfsameq(kai,kpi))then\n kaai=ktfaddr(kai%k)\n kapi=ktfaddr(kpi%k)\n if(ilist(1,kapi-1) .ge. ilist(1,kaai-1))then\n call tflocal1(kai%k)\n lista%dbody(i)=dtfcopy1(kpi)\n else\n call tflocal1(kpi%k)\n listp%dbody(i)=dtfcopy1(kai)\n endif\n cycle\n endif\n endif\n return\n endif\n enddo\n tfsamelistqo=.true.\n return\n end\n\n logical*4 pure elemental function tfsamesymbolqo(sa,sp)\n use tfcode\n implicit none\n type(sad_symbol) , intent(in)::sa,sp\n tfsamesymbolqo=sa%loc .eq. sp%loc .and.\n $ max(0,sa%gen) .eq. max(0,sp%gen)\n return\n end function\n\n logical*4 function tfsamesymbolqk(ka1,kp1)\n implicit none\n type (sad_symbol) ,pointer :: syma,symp\n integer*8 , intent(in)::ka1,kp1\n integer*8 ka,kp\n ka=ktfaddr(ka1)\n kp=ktfaddr(kp1)\n if(ka .eq. kp)then\n tfsamesymbolqk=.true.\n elseif(ka .eq. 0 .or. kp .eq. 0)then\n tfsamesymbolqk=.false.\n else\n call loc_sad(ka,syma)\n call loc_sad(kp,symp)\n tfsamesymbolqk=tfsamesymbolqo(syma,symp)\n endif\n return\n end function\n\n logical*4 function tfsamesymbolqd(k1,k2)\n implicit none\n type (sad_descriptor) k1,k2\n tfsamesymbolqd=tfsamesymbolqk(k1%k,k2%k)\n return\n end function\n\n logical*4 function tfsamestringqk(ka1,kp1)\n implicit none\n type (sad_string), pointer :: stra,strp\n integer*8 ka1,kp1\n if(ktfaddr(ka1) .eq. ktfaddr(kp1))then\n tfsamestringqk=.true.\n else\n call loc_sad(ktfaddr(ka1),stra)\n call loc_sad(ktfaddr(kp1),strp)\n tfsamestringqk=tfsamestringqo(stra,strp)\n endif\n return\n end function\n\n logical*4 function tfsamestringqd(k1,k2)\n implicit none\n type (sad_descriptor) k1,k2\n tfsamestringqd=tfsamestringqk(k1%k,k2%k)\n return\n end function\n\n logical*4 function tfsamestringqo(sa,sp)\n use tfcode\n implicit none\n type(sad_string) , intent(in)::sa,sp\n tfsamestringqo=sa%nch .eq. sp%nch .and.\n $ sa%str(:sa%nch) .eq. sp%str(:sp%nch)\n return\n end function\n\n logical*4 function tfexprqd(k)\n implicit none\n type (sad_descriptor) , intent(in)::k\n type (sad_dlist), pointer :: kl\n tfexprqd=ktflistq(k,kl) .and. kl%head%k .ne. ktfoper+mtflist\n return\n end function\n\n logical*4 function tfexprqk(k)\n implicit none\n integer*8 , intent(in)::k\n type (sad_dlist), pointer :: kl\n tfexprqk=ktflistq(k,kl) .and. kl%head%k .ne. ktfoper+mtflist\n return\n end function\n\n logical*4 function tfsameheadqk(k1,k2)\n implicit none\n integer*8 , intent(in)::k1,k2\n tfsameheadqk=tfsameq(klist(ktfaddr(k1)),klist(ktfaddr(k2)))\n return\n end function\n\n logical*4 function tfsameheadqd(k1,k2)\n implicit none\n type (sad_descriptor) , intent(in)::k1,k2\n tfsameheadqd=tfsameq(klist(ktfaddr(k1)),klist(ktfaddr(k2)))\n return\n end function\n\n logical function tfinequalityqk(k)\n implicit none\n integer*8 , intent(in)::k\n type (sad_dlist), pointer :: kl\n tfinequalityqk=ktflistq(k,kl) .and.\n $ kl%head%k .eq. ktfoper+mtfinequality\n return\n end function\n\n logical function tfinequalityqd(k)\n implicit none\n type (sad_descriptor) , intent(in)::k\n type (sad_dlist), pointer :: kl\n tfinequalityqd=ktflistq(k,kl) .and.\n $ kl%head%k .eq. ktfoper+mtfinequality\n return\n end function\n\n recursive logical*4 function tfconstqk(k) result(lx)\n implicit none\n integer*8 , intent(in)::k\n type (sad_dlist), pointer :: kl\n type (sad_symdef), pointer ::symd\n type (sad_pat), pointer :: pat\n logical*4 tfconstlistqo\n lx=.true.\n if(ktfsymbolqdef(k,symd))then\n lx=ktfconstantsymq(symd%sym) .and.\n $ symd%value%k .eq. ktfsymbol+ktfaddr(k)\n $ .and. symd%upval .eq. 0\n elseif(ktflistq(k,kl))then\n lx=tfconstlistqo(kl)\n elseif(ktfpatq(k,pat))then\n lx=tfconstqk(pat%expr%k)\n endif\n return\n end function\n\n logical*4 function tfconstqd(k)\n implicit none\n type (sad_descriptor) , intent(in)::k\n tfconstqd=tfconstqk(k%k)\n return\n end function\n\n logical*4 function tfconstpatternqk(k)\n implicit none\n integer*8 , intent(in)::k\n type (sad_dlist), pointer :: kl\n logical*4 tfconstpatternheadqk,tfconstpatternlistbodyqo\n tfconstpatternqk=.true.\n if(ktfpatq(k))then\n tfconstpatternqk=.false.\n elseif(ktflistq(k,kl))then\n tfconstpatternqk=tfconstpatternheadqk(kl%head) .and.\n $ tfconstpatternlistbodyqo(kl)\n endif\n return\n end function\n\n logical*4 function tfconstpatternqd(k)\n implicit none\n type (sad_descriptor) , intent(in)::k\n type (sad_dlist), pointer :: kl\n logical*4 tfconstpatternheadqk,tfconstpatternlistbodyqo\n tfconstpatternqd=.true.\n if(ktfpatq(k))then\n tfconstpatternqd=.false.\n elseif(ktflistq(k,kl))then\n tfconstpatternqd=tfconstpatternheadqk(kl%head) .and.\n $ tfconstpatternlistbodyqo(kl)\n endif\n return\n end function\n\n logical*4 function tfheldqd(k)\n implicit none\n type (sad_descriptor) , intent(in)::k\n type (sad_dlist), pointer :: kl\n tfheldqd=ktflistq(k,kl) .and.\n $ kl%head%k .eq. ktfoper+mtfhold\n return\n end function\n\n logical*4 function tfmatrixqd(k,kl,klind,klbody)\n implicit none\n type (sad_descriptor) , intent(in)::k\n type (sad_dlist), pointer, optional,\n $ intent(out) :: kl,klbody\n type (sad_rlist), pointer, optional,\n $ intent(out) :: klind\n type (sad_rlist), pointer :: kli1\n type (sad_dlist), pointer :: kl1,klb1\n if(ktflistq(k,kl1))then\n if(tfsameq(kl1%head,kxmatrix) .and. kl1%nl .eq. 2)then\n if(tfreallistq(kl1%dbody(1),kli1) .and.\n $ ktflistq(kl1%dbody(2),klb1))then\n tfmatrixqd=.true.\n if(present(kl))then\n kl=>kl1\n if(present(klind))then\n klind=>kli1\n if(present(klbody))then\n klbody=>klb1\n endif\n endif\n endif\n return\n endif\n endif\n endif\n tfmatrixqd=.false.\n return\n end function\n\n complex*16 pure function cfromr(r)\n implicit none\n real*8 , intent(in)::r(2)\n cfromr=dcmplx(r(1),r(2))\n return\n end function cfromr\n\n subroutine incr1i(ia)\n implicit none\n integer*4 ,intent(inout):: ia(:)\n ia=ia+1\n return\n end\n\n integer*8 function ktfcopy1(k)\n implicit none\n integer*8 , intent(in)::k\n integer*8 ka\n ka=iand(ktamask,k)\n ilist(1,ka-1)=ilist(1,ka-1)+1\n ktfcopy1=k\n return\n end function ktfcopy1\n\n integer*8 function ktfcopyd(k,d)\n implicit none\n integer*8 , intent(in)::k\n integer*8 ka\n logical*4 , intent(inout)::d\n if(iand(ktomask,k) .eq. ktfobj)then\n d=.true.\n ka=iand(ktamask,k)\n ilist(1,ka-1)=ilist(1,ka-1)+1\n else\n d=d .or. ktfnonrealq(k)\n endif\n ktfcopyd=k\n return\n end function ktfcopyd\n\n integer*8 function ktfcopy(k)\n implicit none\n integer*8 , intent(in)::k\n integer*8 ka\n if(iand(ktomask,k) .eq. ktfobj)then\n ka=iand(ktamask,k)\n ilist(1,ka-1)=ilist(1,ka-1)+1\n endif\n ktfcopy=k\n return\n end function\n\n subroutine ktfcopym(k)\n implicit none\n integer*8 ,intent(in):: k(:)\n ilist(1,ktaobj(k)-1)=ilist(1,ktaobj(k)-1)+1\n return\n end\n\n subroutine dtfcopym(d)\n implicit none\n type(sad_descriptor) ,intent(in):: d(:)\n ilist(1,ktaobj(d)-1)=ilist(1,ktaobj(d)-1)+1\n return\n end\n\n type (sad_descriptor) function dtfcopy(d)\n implicit none\n type (sad_descriptor) , intent(in)::d\n integer*8 ka\n if(iand(ktomask,d%k) .eq. ktfobj)then\n ka=iand(ktamask,d%k)\n ilist(1,ka-1)=ilist(1,ka-1)+1\n endif\n dtfcopy=d\n return\n end function\n\n type (sad_descriptor) function dtfcopy1(d)\n implicit none\n type (sad_descriptor) , intent(in)::d\n dtfcopy1%k=ktfcopy1(d%k)\n return\n end function\n\n subroutine tflocald(k)\n implicit none\n type (sad_descriptor) , intent(in)::k\n type (sad_object), pointer :: obj\n integer*8 itfroot\n if(ktfobjqd(k,obj))then\n obj%ref=obj%ref-1\n if(obj%ref .le. 0)then\n obj%ref=0\n if(ktfaddr(obj%alloc) .eq. 0)then\n itfroot=itflocal+levele\n obj%alloc%k=obj%alloc%k+ktfaddr(klist(itfroot))\n klist(itfroot)=ktfaddr(k%k)-2\n endif\n endif\n endif\n return\n end subroutine \n\n subroutine tflocal1d(k)\n implicit none\n type (sad_descriptor) , intent(in)::k\n type (sad_object), pointer :: obj\n integer*8 ka,itfroot\n ka=ktfaddr(k)\n call loc_obj(ka,obj)\n obj%ref=obj%ref-1\n if(obj%ref .le. 0)then\n obj%ref=0\n if(ktfaddr(obj%alloc) .eq. 0)then\n itfroot=itflocal+levele\n obj%alloc%k=obj%alloc%k+ktfaddr(klist(itfroot))\n klist(itfroot)=ka-2\n endif\n endif\n return\n end subroutine\n\n subroutine tfconnect(k,irtc)\n implicit none\n type (sad_descriptor) , intent(in)::k\n integer*4 irtc\n call tfconnectk(k%k,irtc)\n return\n end subroutine\n\n subroutine tfconnectk(k,irtc)\n implicit none\n type (sad_object), pointer :: obj\n integer*4 l,itfdownlevel\n integer*4 , intent(out)::irtc\n integer*8 , intent(in)::k\n integer*8 ka,j\n if(levele .gt. 0)then\n if(irtc .ne. 0)then\n l=itfdownlevel()\n elseif(ktfobjq(k))then\n ka=ktfaddr(k)\n call loc_obj(ktfaddr(ka),obj)\n obj%ref=obj%ref+1\n l=itfdownlevel()\n call tflocal1(ka)\n if(ktfaddr(obj%alloc) .eq. 0)then\n j=itflocal+levele\n obj%alloc%k=ktftype(obj%alloc%k)+klist(j)\n klist(j)=sad_loc(obj%alloc)\n endif\nc call tfdebugprint(ktftype(klist(ka-2))+ka,'tfconnectk',1)\nc write(*,*)'with ',ilist(1,ka-1),ktfaddr(klist(ka-2))\n else\n l=itfdownlevel()\n endif\n endif\n return\n end subroutine\n\n subroutine tfconnectk1(k,irtc)\n implicit none\n type (sad_object), pointer :: obj\n integer*4 l,itfdownlevel\n integer*4 , intent(out)::irtc\n integer*8 , intent(in)::k\n integer*8 ka\n if(levele .gt. 0)then\n if(irtc .ne. 0)then\n l=itfdownlevel()\n elseif(ktfobjq(k))then\n ka=ktfaddr(k)\n call loc_obj(ktfaddr(ka),obj)\n obj%ref=obj%ref+1\n l=itfdownlevel()\n call tflocal1(ka)\n else\n l=itfdownlevel()\n endif\n endif\n return\n end subroutine\n\n type (sad_descriptor) function kxaaloc_dlist(mode,nd,kl)\n implicit none\n type (sad_dlist), pointer, optional, intent(out) :: kl\n integer*4 , intent(in)::mode,nd\n kxaaloc_dlist%k=ktflist+ktaaloc_dlist(mode,nd,kl)\n return\n end function\n\n type (sad_descriptor) function kxaaloc_rlist(mode,nd,kl)\n implicit none\n type (sad_rlist), pointer, intent(out) :: kl\n integer*4 , intent(in)::mode,nd\n kxaaloc_rlist%k=ktflist+ktaaloc_rlist(mode,nd,kl)\n return\n end function\n\n type (sad_descriptor) function kxadaloc_dlist(mode,nd,kl)\n implicit none\n type (sad_dlist), pointer, optional, intent(out) :: kl\n integer*4 , intent(in)::mode,nd\n kxadaloc_dlist%k=ktflist+ktadaloc(mode,nd,kl)\n return\n end function\n\n type (sad_descriptor) function kxadalocnull(mode,nd,kl)\n implicit none\n type (sad_dlist), pointer, optional, intent(out) :: kl\n integer*4 , intent(in)::mode,nd\n kxadalocnull%k=ktflist+ktadalocnull(mode,nd,kl)\n return\n end function\n\n type (sad_descriptor) function kxavaloc(mode,nd,kl)\n implicit none\n type (sad_rlist), pointer, optional, intent(out) :: kl\n integer*4 , intent(in)::mode,nd\n kxavaloc%k=ktflist+ktavaloc(mode,nd,kl)\n return\n end function\n\n type (sad_descriptor) function kxmakelist_dlist(isp1,kl)\n implicit none\n type (sad_dlist), pointer, optional, intent(out) :: kl\n integer*4 , intent(in)::isp1\n kxmakelist_dlist%k=ktflist+ktfmakelist(isp1,kl)\n return\n end function\n\n type (sad_descriptor) function kxmakelist_rlist(isp1,kl)\n implicit none\n type (sad_rlist), pointer, intent(out) :: kl\n integer*4 , intent(in)::isp1\n kxmakelist_rlist%k=ktflist+ktfmakelist(isp1,kl)\n return\n end function\n\n type (sad_descriptor) function kxmakelist0(isp1,kl)\n implicit none\n type (sad_dlist), pointer, optional, intent(out) :: kl\n integer*4 , intent(in)::isp1\n kxmakelist0%k=ktflist+ktfmakelist0(isp1,kl)\n return\n end function\n\n type (sad_descriptor) function kxcompose(isp1,kl)\n implicit none\n type (sad_dlist), pointer, optional, intent(out) :: kl\n integer*4 , intent(in)::isp1\n kxcompose%k=ktflist+ktfcompose(isp1,kl)\n return\n end function\n\n type (sad_descriptor) function kxcomposer(isp1)\n implicit none\n integer*4 , intent(in)::isp1\n kxcomposer%k=ktflist+\n $ ktfcrelistr(ktastk(isp1+1:isp),dtastk(isp1))\n return\n end function\n\n type (sad_descriptor) function kxcomposev(isp0,kl)\n implicit none\n type (sad_dlist), pointer, optional, intent(out) :: kl\n integer*4 , intent(in)::isp0\n kxcomposev%k=ktflist+ktfcomposev(isp0,kl)\n return\n end function\n\n type (sad_descriptor) function kxcalocv(mode,x,y)\n implicit none\n integer*4 , intent(in)::mode\n real*8 , intent(in)::x,y\n kxcalocv%k=ktflist+ktcalocv(mode,x,y)\n return\n end function\n\n type (sad_descriptor) function kxsalocb(mode,string,leng,str)\n implicit none\n type (sad_string), pointer, optional, intent(out) :: str\n integer*4 , intent(in)::mode,leng\n character , intent(in)::string(leng)\n kxsalocb%k=ktfstring+ktsalocb(mode,string,leng)\n if(present(str))then\n call descr_sad(kxsalocb,str)\n endif\n return\n end function\n\n type (sad_descriptor) function kxsalocbb(mode,leng,str)\n implicit none\n type (sad_string), pointer, optional, intent(out) :: str\n integer*4 , intent(in)::mode,leng\n kxsalocbb%k=ktfstring+ktsalocbb(mode,leng)\n if(present(str))then\n call descr_sad(kxsalocbb,str)\n endif\n return\n end function\n\n type (sad_descriptor) function kxsymbolz(name,l,symd)\n implicit none\n type (sad_symdef), pointer, optional, intent(out) :: symd\n integer*4 , intent(in)::l\n character , intent(in)::name(l)\n kxsymbolz%k=ktfsymbol+ktfsymbolz(name,l,symd)\n return\n end function\n\n type (sad_descriptor) function kxsymbolv(name,l,symd0)\n implicit none\n type (sad_symdef), pointer, optional, intent(out) :: symd0\n type (sad_symdef), pointer :: symd\n integer*8 k\n integer*4 , intent(in)::l\n character , intent(in)::name(l)\n k=ktfsymbolz(name,l,symd)\n kxsymbolv=symd%value\n if(present(symd0))then\n symd0=>symd\n endif\n return\n end function\n\n type (sad_descriptor) function kxsymbolf(name,l,const,symd0)\n implicit none\n type (sad_symdef), pointer, optional, intent(out) :: symd0\n type (sad_symdef), pointer :: symd\n integer*4 , intent(in)::l\n character , intent(in)::name(l)\n logical*4 , intent(in)::const\n kxsymbolf=kxsymbolz(name,l,symd)\n if(present(symd0))then\n symd0=>symd\n endif \n if(const .and. symd%sym%gen .le. 0)then\n symd%sym%attr=ior(symd%sym%attr,iattrconstant+iattrprotected)\n endif\n return\n end function\n\n subroutine tfsetsymbolr(name,l,val)\n implicit none\n integer*4 , intent(in)::l\n character , intent(in)::name(l)\n real*8 , intent(in)::val\n type (sad_symdef), pointer :: symd\n type (sad_descriptor) kx\n kx=kxsymbolz(name,l,symd)\n symd%value=dfromr(val)\n return\n end subroutine\n\n type (sad_descriptor) pure elemental function k_descr(k)\n implicit none\n integer*8 , intent(in)::k\n k_descr%k=k\n return\n end function\n\n type (sad_descriptor) function kxscopy(ka,leng,str)\n implicit none\n type (sad_string), pointer, optional, intent(out) :: str\n integer*8 , intent(in)::ka\n integer*8 ktfaloc,l\n integer*4 , intent(in)::leng\n integer*4 nw,n\n if(leng .eq. 0)then\n kxscopy=dxnulls\n go to 10\n endif\n nw=leng/8+2\n l=ktfaloc(-1,ktfstring,nw)\n ilist(2,l-3)=-1\n ilist(1,l)=leng\n klist(l+nw-1)=0\n n=(min(leng,ilist(1,ka))+7)/8\n klist(l+1:l+n)=klist(ka+1:ka+n)\n kxscopy%k=ktfstring+l\n 10 if(present(str))then\n call descr_sad(kxscopy,str)\n endif\n return\n end function\n\n type (sad_descriptor) function kxnaloc1(lg,locp)\n implicit none\n integer*8 , intent(in)::locp\n integer*4 , intent(in)::lg\n kxnaloc1=kxnaloc(lg,locp,0)\n return\n end function\n\n type (sad_descriptor) function kxnaloc(lg,locp,n)\n implicit none\n integer*8 kp,kp1, kp0,ktalocr\n integer*8 , intent(in)::locp\n integer*4 , intent(in)::lg\n integer*4 ipg,n\n type (sad_symdef), pointer :: def,def0\n type (sad_namtbl), pointer :: loc\n call loc_namtbl(locp,loc)\n kp0=sad_loc(loc%symdef)\n kp=loc%symdef\n if(kp .le. 0)then\n kp=ktalocr(9+n)\n call loc1_symdef(kp,def)\n def%next=0\n def%prev=kp0\n def%upval=0\n def%downval=0\n def%value%k=ktfsymbol+kp+8\n def%sym%attr=0\n def%sym%override=-2\n def%sym%alloc%k=ktfsymbol\n def%sym%ref=2\n def%sym%gen=lg\n def%sym%loc=locp\n loc%symdef=kp\n loc%str%ref=loc%str%ref+1\n else\n call loc1_symdef(kp,def0)\n ipg=def0%sym%gen\n do while(lg .lt. ipg)\n kp0=kp\n kp=def0%next\n if(kp .eq. 0)then\n exit\n endif\n call loc1_symdef(kp,def0)\n ipg=def0%sym%gen\n enddo\n kp1=ktaloc(9+n)\n call loc1_symdef(kp1,def)\n def%next=kp\n def%prev=kp0\n if(kp .ne. 0)then\n def0%prev=kp1\n if(lg .eq. ipg)then\n def0%sym%override=0\n endif\n endif\n klist(kp0)=kp1\n def%upval=0\n def%downval=0\n def%value%k=ktfsymbol+kp1+8\n def%sym%attr=0\n def%sym%override=-2\n def%sym%alloc%k=ktfsymbol\n def%sym%ref=2\n def%sym%gen=lg\n def%sym%loc=locp\n endif\n kxnaloc=sad_descr(def%sym)\n return\n end function\n\n real*8 function rfromd(d)\n implicit none\n type (sad_descriptor) , intent(in)::d\n rfromd=d%x(1)\n return\n end function\n\n integer*4 function ifromd(d)\n implicit none\n type (sad_descriptor) , intent(in)::d\n ifromd=int(d%x(1))\n return\n end function\n\n type (sad_descriptor) function dfromr(x)\n implicit none\n real*8 , intent(in)::x\n dfromr%x(1)=x\n return\n end function\n\n type (sad_descriptor) pure elemental function dfromk(k)\n implicit none\n integer*8 , intent(in)::k\n dfromk%k=k\n return\n end function\n\n integer*8 function ktfmakelist0(isp1,kl)\n implicit none\n type (sad_dlist), pointer, optional, intent(out) :: kl\n integer*4 , intent(in)::isp1\n integer*4 narg\n narg=isp-isp1\n if(narg .le. 0)then\n ktfmakelist0=ktfaddr(kxnulll)\n go to 10\n elseif(narg .eq. 1)then\n if(ktastk(isp) .eq. ktfoper+mtfnull)then\n ktfmakelist0=ktfaddr(kxnulll)\n go to 10\n endif\n endif\n ktfmakelist0=ktfaddr(\n $ kxcrelistm(narg,ktastk(isp1+1:isp1+narg),\n $ k_descr(ktfoper+mtflist)))\n 10 if(present(kl))then\n call loc_sad(ktfmakelist0,kl)\n endif\n return\n end function\n\n type (sad_descriptor) function kxcrelistm(m,ks,kh)\n implicit none\n type (sad_descriptor) , intent(in)::kh\n type (sad_dlist), pointer ::kl\n integer*4 , intent(in)::m\n integer*8 , intent(in)::ks(m)\n kxcrelistm=kxaaloc(-1,m,kl)\n call tfcrelista(ks,kh,kl)\n return\n end function\n\n subroutine tfcrelista(ks,kh,list)\n implicit none\n type (sad_descriptor) ,intent(in):: kh\n type (sad_dlist) ,intent(inout):: list\n integer*4 i\n integer*8 ,intent(in):: ks(:)\n logical*4 d\n list%head=dtfcopy(kh)\n d=.false.\n do i=1,size(ks)\n list%dbody(i)%k=ktfcopyd(ks(i),d)\n enddo\n if(d)then\n list%attr=ior(list%attr,lnonreallist)\n endif\n return\n end subroutine\n \n integer*8 function ktfcrelistr(ks,kh)\n implicit none\n type (sad_descriptor) ,intent(in):: kh\n type (sad_dlist), pointer ::kl\n integer*8 ,intent(in):: ks(:)\n ktfcrelistr=ktaalocr(-1,size(ks),kl)\n call tfcrelista(ks,kh,kl)\n return\n end\n\n integer*8 function ktsalocb(mode,string,leng)\n integer*8 ktfaloc,l\n integer*4 , intent(in)::leng,mode\n integer*4 nw,ik\n character , intent(in)::string(leng)\n if(leng .eq. 1)then\n ik=ichar(string(1))\n ktsalocb=iaxschar+ik*5+3\n if(mode .eq. 0)then\n ilist(1,ktsalocb-1)=ilist(1,ktsalocb-1)+1\n endif\n elseif(leng .eq. 0)then\n ktsalocb=ktfaddr(kxnulls)\n if(mode .eq. 0)then\n ilist(1,ktsalocb-1)=ilist(1,ktsalocb-1)+1\n endif\n else\n nw=leng/8+2\n l=ktfaloc(mode,ktfstring,nw)\n call tfpadstr(string,l+1,leng)\n ilist(1,l)=leng\n ilist(2,l)=0\n ilist(2,l-3)=-1\n ktsalocb=l\n endif\n return\n end function\n \n integer*8 function ktsalocbb(mode,leng)\n implicit none\n integer*8 ktfaloc,l\n integer*4 leng,nw,mode\n if(leng .eq. 0)then\n ktsalocbb=kxnulls\n if(mode .eq. 0)then\n ilist(1,ktfaddr(kxnulls)-1)=\n $ ilist(1,ktfaddr(kxnulls)-1)+1\n endif\n return\n endif\n nw=leng/8+2\n l=ktfaloc(mode,ktfstring,nw)\n ilist(2,l-3)=-1\n ilist(1,l)=leng\n klist(l+nw-1)=0\n ktsalocbb=l\n return\n end function\n\n integer*8 function ktcalocv(mode,x,y)\n implicit none\n type (sad_rlist), pointer :: kl\n integer*4 mode\n real*8 x,y\n ktcalocv=ktavaloc(mode,2,kl)\n kl%attr=lconstlist\n kl%head%k=ktfoper+mtfcomplex\n kl%rbody(1)=x\n kl%rbody(2)=y\n return\n end function\n\n integer*8 function ktadalocnull(mode,nd,kl)\n implicit none\n integer*4 , intent(in)::mode,nd\n type (sad_dlist), pointer :: kl1\n type (sad_dlist), pointer, optional, intent(out) :: kl\n ktadalocnull=ktadaloc(mode,nd,kl1)\n kl1%body(1:nd)=ktfoper+mtfnull\n if(present(kl))then\n kl=>kl1\n endif\n return\n end function\n\n integer*8 function ktaaloc_dlist(mode,nd,kl)\n implicit none\n type (sad_dlist), pointer, optional, intent(out) :: kl\n integer*8 ka,ktfaloc\n integer*4 , intent(in)::nd,mode\n ka=ktfaloc(mode,ktflist,nd+1)\n ilist(1,ka-3)=0\n ilist(2,ka-1)=nd\n klist(ka)=ktfoper+mtflist\n ktaaloc_dlist=ka\n if(present(kl))then\n call loc_dlist(ka,kl)\n endif\n return\n end function\n\n integer*8 function ktaaloc_rlist(mode,nd,kl)\n implicit none\n type (sad_rlist), pointer, intent(out) :: kl\n integer*8 ka,ktfaloc\n integer*4 , intent(in)::nd,mode\n ka=ktfaloc(mode,ktflist,nd+1)\n ilist(1,ka-3)=0\n ilist(2,ka-1)=nd\n klist(ka)=ktfoper+mtflist\n ktaaloc_rlist=ka\n call loc_rlist(ka,kl)\n return\n end function\n\n integer*8 function ktavaloc(mode,nd,kl)\n implicit none\n type (sad_rlist), pointer, optional, intent(out) :: kl\n integer*4 , intent(in)::mode,nd\n integer*8 k1,itfroot\n k1=ktaloc(nd+3)\n ilist(1,k1-1)=0\n ilist(2,k1-1)=kconstarg\n if(mode .eq. 0)then\n klist(k1)=ktflist\n else\n itfroot=itflocal+levele\n klist(k1)=ktflist+klist(itfroot)\n klist(itfroot)=k1\n endif\n ilist(1,k1+1)=mode+1\n ilist(2,k1+1)=nd\n klist(k1+2)=ktfoper+mtflist\n ktavaloc=k1+2\n if(present(kl))then\n call loc_rlist(k1+2,kl)\n endif\n return\n end function\n\n integer*8 function ktadaloc_dlist(mode,nd,kl)\n implicit none\n type (sad_dlist), pointer, optional, intent(out) :: kl\n integer*4 mode,nd\n integer*8 k1,itfroot\n k1=ktaloc(nd+3)\n klist(k1-1)=0\n ilist(2,k1-1)=lnonreallist\n if(mode .eq. 0)then\n klist(k1)=ktflist\n else\n itfroot=itflocal+levele\n klist(k1)=ktflist+klist(itfroot)\n klist(itfroot)=k1\n endif\n ilist(1,k1+1)=mode+1\n ilist(2,k1+1)=nd\n klist(k1+2)=ktfoper+mtflist\n ktadaloc_dlist=k1+2\n if(present(kl))then\n call loc_dlist(k1+2,kl)\n endif\n return\n end function\n\n integer*8 function ktaalocr(mode,nd,kl)\n implicit none\n type (sad_dlist), pointer, optional, intent(out) :: kl\n integer*8 ka,ktfalocr\n integer*4 , intent(in)::nd,mode\n ka=ktfalocr(mode,ktflist,nd+1)\n ilist(1,ka-3)=0\n ilist(2,ka-1)=nd\n klist(ka)=ktfoper+mtflist\n ktaalocr=ka\n if(present(kl))then\n call loc_sad(ka,kl)\n endif\n return\n end function\n\n integer*8 function ktraaloc(mode,nd,kl)\n implicit none\n type (sad_rlist), pointer, optional, intent(out) :: kl\n type (sad_rlist), pointer :: kl1\n integer*4 , intent(in)::mode,nd\n integer*8 ka\n ka=ktavaloc(mode,nd,kl1)\n kl1%rbody(1:nd)=0.d0\n if(present(kl))then\n kl=>kl1\n endif\n ktraaloc=ka\n return\n end function\n\n type (sad_descriptor) function kxraaloc(mode,nd,kl)\n implicit none\n type (sad_rlist), pointer, optional, intent(out) :: kl\n type (sad_rlist), pointer :: kl1\n integer*4 , intent(in)::mode,nd\n integer*8 ka\n ka=ktavaloc(mode,nd,kl1)\n kl1%rbody(1:nd)=0.d0\n if(present(kl))then\n kl=>kl1\n endif\n kxraaloc%k=ktflist+ka\n return\n end function\n\n integer*8 function ktaalocsp(nd,lp,la,kl1)\n implicit none\n type (sad_dlist), pointer, optional, intent(out) :: kl1\n type (sad_dlist), pointer :: kl\n integer*8 ka\n integer*4 , intent(in)::nd\n integer*2 , intent(in)::lp,la\n ka=ktaloc(nd+lp+la+3)+lp+2\n call loc_sad(ka,kl)\n kl%lenp=lp\n kl%lena=la\n kl%attr=0\n kl%alloc%k=ktflist\n kl%ref=1\n kl%nl=nd\n call tflocal1(ka)\n ktaalocsp=ka\n if(present(kl1))then\n kl1=>kl\n endif\n return\n end function\n\n integer*8 function ktfcomposev(isp0,kl)\n implicit none\n type (sad_dlist), pointer, optional, intent(out) :: kl\n integer*8 kax,kh\n integer*4 , intent(in)::isp0\n if(isp .gt. isp0)then\n ktfcomposev=ktfcompose(isp0)\n else\n kh=ktastk(isp0)\n if(kh .eq. ktfoper+mtflist)then\n ktfcomposev=ktfaddr(kxnulll)\n elseif(kh .eq. ktfoper+mtfnull)then\n ktfcomposev=ktfaddr(kxnull)\n elseif(kh.eq. ktfoper+mtfslot)then\n ktfcomposev=ktfaddr(klist(iaxslotnull))\n elseif(ktastk(isp0) .eq. ktfoper+mtfslotseq)then\n ktfcomposev=ktfaddr(klist(iaxslotnull+1))\n else\n kax=ktaaloc(-1,0,kl)\n klist(kax)=ktfcopy(kh)\n ktfcomposev=kax\n return\n endif\n endif\n if(present(kl))then\n call loc_sad(ktfcomposev,kl)\n endif\n return\n end function\n\n integer*8 function ktfcompose(isp1,kl)\n implicit none\n type (sad_dlist), pointer, optional, intent(out) :: kl\n integer*4 , intent(in)::isp1\n ktfcompose=ktfaddr(\n $ kxcrelistm(isp-isp1,ktastk(isp1+1:isp),dtastk(isp1)))\n if(present(kl))then\n call loc_sad(ktfcompose,kl)\n endif\n return\n end function\n\n integer*8 function ktfmakelist_dlist(isp1,kl)\n implicit none\n type (sad_dlist), pointer, optional, intent(out) :: kl\n integer*4 , intent(in)::isp1\n integer*4 narg\n narg=isp-isp1\n if(narg .eq. 1)then\n if(ktastk(isp) .eq. ktfoper+mtfnull)then\n ktfmakelist_dlist=ktaaloc(-1,0,kl)\n return\n endif\n endif\n ktfmakelist_dlist=\n $ ktfaddr(kxcrelistm(narg,ktastk(isp1+1:isp1+narg),\n $ k_descr(ktfoper+mtfleftbrace)))\n if(present(kl))then\n call loc_dlist(ktfmakelist_dlist,kl)\n endif\n return\n end function\n\n integer*8 function ktfmakelist_rlist(isp1,kl)\n implicit none\n type (sad_rlist), pointer, intent(out) :: kl\n integer*4 , intent(in)::isp1\n integer*4 narg\n narg=isp-isp1\n if(narg .eq. 1)then\n if(ktastk(isp) .eq. ktfoper+mtfnull)then\n ktfmakelist_rlist=ktavaloc(-1,0,kl)\n return\n endif\n endif\n ktfmakelist_rlist=\n $ ktfaddr(kxcrelistm(narg,ktastk(isp1+1:isp1+narg),\n $ k_descr(ktfoper+mtfleftbrace)))\n call loc_rlist(ktfmakelist_rlist,kl)\n return\n end function\n\n integer*8 function ktfsymbolz(name,l,symd)\n implicit none\n type (sad_symdef), pointer, optional, intent(out) :: symd\n integer*4 , intent(in)::l\n integer*8 ktfsymbolc\n character , intent(in)::name(l)\n ktfsymbolz=ktfsymbolc(name,l,i00)\n if(present(symd))then\n call loc_symdef(ktfsymbolz,symd)\n endif\n return\n end function\n\n function tfsydef(sym)\n implicit none\n type (sad_symbol), pointer :: tfsydef\n type (sad_descriptor) kx\n type (sad_symbol) , intent(in)::sym\nc type (sad_symbol), pointer, intent(out) :: symx\n call tfsydefg(sym%loc,kx,sym%gen)\n call loc_sad(ktfaddrd(kx),tfsydef)\n return\n end function\n\n type (sad_descriptor) function dxsycopy(sym)\n implicit none\n type (sad_symbol) , intent(in)::sym\n integer*8 kax,ktfaloc\n kax=ktfaloc(-1,ktfsymbol,1)\n ilist(2,kax-1)=maxgeneration\n klist(kax)=sym%loc\n dxsycopy%k=ktfsymbol+kax\n return\n end function\n\n type (sad_descriptor) function kxpfaloc(k)\n implicit none\n type (sad_descriptor) , intent(in)::k\n type (sad_dlist), pointer :: klx\n type (sad_rlist), pointer :: klr\n real*8 x\n if(ktfrealq(k,x))then\n kxpfaloc=kxavaloc(-1,1,klr)\n klr%rbody(1)=x\n klr%head%k=ktfoper+mtffun\n else\n kxpfaloc=kxadaloc(-1,1,klx)\n klx%dbody(1)=dtfcopy(k)\n klx%head%k=ktfoper+mtffun\n endif\n return\n end function\n\n type (sad_descriptor) function kxpaloc(string)\n implicit none\n character*(*) , intent(in)::string\n type (sad_descriptor) kh\n integer*8 ipk\n integer*4 lenw,l,ip,k\n l=lenw(string)\n ip=index(string(1:l),'_')\n if(ip .gt. 0)then\n k=merge(3,merge(2,1,string(ip:min(l,ip+1)) .eq. '__'),\n $ string(ip:min(l,ip+2)) .eq. '___')\n else\n k=0\n ip=l+1\n endif\n ipk=ip+k\n kh%k=merge(ktfref,\n $ ktfsymbol+ktfsymbolz(string(ipk:l),int(l-ipk+1)),\n $ ipk .gt. l)\n kxpaloc=kxpalocb(string(1:ip-1),ip-1,transfer(ktfref+k,kh),kh)\n return\n end function\n\n type (sad_descriptor) function kxpalocb(symb,ls,kp,kh)\n implicit none\n type (sad_descriptor) , intent(in)::kp,kh\n integer*4 , intent(in)::ls\n character , intent(in)::symb(ls)\n kxpalocb=kxpcopyss(kp,kh,\n $ merge(kxsymbolz(symb,ls),dfromk(i00),ls .gt. 0),\n $ transfer(ktfref,kp))\n return\n end function\n\n type (sad_descriptor) function kxpcopyss(kp,kh,ks,kd)\n use tfcode\n use iso_c_binding\n implicit none\n type (sad_descriptor) , intent(in)::kp,kh,kd,ks\n type (sad_pat), pointer :: pat\n type (sad_symbol), pointer :: sym\n integer*8 kax,ktfaloc\n kax=ktfaloc(-1,ktfpat,9)\n call loc_pat(kax,pat) \n pat%expr=dtfcopy(kp)\n pat%head=dtfcopy(kh)\n nullify(pat%equiv)\n pat%default=dtfcopy(kd)\n pat%value%k=ktfref\n pat%sym%attr=pat%len-7\n pat%sym%override=1\n pat%sym%ref=1\n if(ktfsymbolq(ks,sym))then\n pat%sym%alloc=dtfcopy1(ks)\n pat%sym%gen=sym%gen\n pat%sym%loc=sym%loc\n else\n pat%sym%alloc%k=ktfsymbol\n pat%sym%gen=0\n pat%sym%loc=0\n endif\n kxpcopyss%k=ktfpat+kax\n return\n end function\n\n type (sad_descriptor) function kxsubstring(kh,isp1,isp2)\n implicit none\n type (sad_descriptor) , intent(in)::kh\n type (sad_descriptor) kx\n type (sad_string), pointer :: str\n integer*4 n,ic1,ic2\n integer*4 , intent(in)::isp1,isp2\n call descr_sad(kh,str)\n n=str%nch\n ic1=int(rtastk(isp1))\n if(ic1 .lt. 0)then\n ic1=n+1+ic1\n endif\n ic2=int(rtastk(isp2))\n if(ic2 .lt. 0)then\n ic2=n+1+ic2\n endif\n if(ic2 .lt. ic1 .or. ic2 .le. 0 .or. ic1 .gt. n)then\n kx%k=kxnulls\n else\n ic1=max(1,ic1)\n ic2=min(n,ic2)\n kx=kxsalocb(-1,str%str(ic1:ic2),ic2-ic1+1)\n endif\n kxsubstring=kx\n return\n end function\n\n function tfclonelist(list) result(listc)\n implicit none\n type (sad_dlist), pointer:: listc\n type (sad_dlist), target, intent(in) :: list\n integer*4 i\n if(ktfovrwrtq(list))then\n listc=>list\n else\n call loc_dlist(ktaaloc(-1,list%nl),listc)\n listc%attr=list%attr\n if(ktfreallistq(list))then\n listc%head=dtfcopy(list%head)\n listc%dbody(1:list%nl)=list%dbody(1:list%nl)\n else\n do i=0,list%nl\n listc%dbody(i)=dtfcopy(list%dbody(i))\n enddo\n endif\n endif\n listc%attr=ior(listc%attr,ktoberebuilt)\n return\n end function\n\n function tfduplist(list) result(listc)\n implicit none\n type (sad_dlist), pointer :: listc\n type (sad_dlist), target, intent(in) :: list\n integer*4 i\n call loc_dlist(ktaaloc(-1,list%nl),listc)\n listc%attr=list%attr\n if(ktfreallistq(list))then\n listc%head=dtfcopy(list%head)\n listc%dbody(1:list%nl)=list%dbody(1:list%nl)\n else\n do i=0,list%nl\n listc%dbody(i)=dtfcopy(list%dbody(i))\n enddo\n endif\n return\n end function\n\n recursive subroutine tfgetllstkall_dlist(list)\n implicit none\n type (sad_dlist) , intent(inout)::list\n type (sad_dlist),pointer :: listi\n integer*4 i,m\n logical*4 noseq\n m=list%nl\n if(iand(list%attr,lnoseqlist) .ne. 0)then\n ktastk(isp+1:isp+m)=list%body(1:m)\nc call tmov(klist(ka+1),ktastk(isp+1),m)\n isp=isp+m\n return\n endif\n noseq=.true.\n if(ktfreallistq(list))then\n dtastk(isp+1:isp+m)=list%dbody(1:m)\n isp=isp+m\n else\n do i=1,m\n isp=isp+1\n dtastk(isp)=list%dbody(i)\n if(ktfsequenceq(ktastk(isp)))then\n noseq=.false.\n isp=isp-1\n call loc_dlist(ktfaddr(list%dbody(i)),listi)\n call tfgetllstkall_dlist(listi)\n endif\n enddo\n endif\n if(noseq)then\n list%attr=ior(list%attr,lnoseqlist)\n endif\n return\n end subroutine\n\n recursive subroutine tfgetllstkall_rlist(list)\n implicit none\n type (sad_rlist) , intent(inout)::list\n type (sad_rlist),pointer :: listi\n integer*4 i,m\n logical*4 noseq\n m=list%nl\n if(iand(list%attr,lnoseqlist) .ne. 0)then\n ktastk(isp+1:isp+m)=list%body(1:m)\nc call tmov(klist(ka+1),ktastk(isp+1),m)\n isp=isp+m\n return\n endif\n noseq=.true.\n if(ktfreallistq(list))then\n dtastk(isp+1:isp+m)=list%dbody(1:m)\n isp=isp+m\n else\n do i=1,m\n isp=isp+1\n dtastk(isp)=list%dbody(i)\n if(ktfsequenceq(dtastk(isp)))then\n noseq=.false.\n isp=isp-1\n call loc_rlist(ktfaddr(list%dbody(i)),listi)\n call tfgetllstkall_rlist(listi)\n endif\n enddo\n endif\n if(noseq)then\n list%attr=ior(list%attr,lnoseqlist)\n endif\n return\n end subroutine\n\n logical*4 pure elemental function tfonstackq(ka)\n implicit none\n integer*8 , intent(in)::ka\n tfonstackq=ka .ge. isporg+ispbase\n $ .and. ka .le. isporg+ivstkoffset*2+ispbase\n return\n end function\n\n subroutine tfgetdefargp_dlist(kl,kas,kp,ev,irtc)\n implicit none\n type (sad_dlist) , intent(inout)::kl\n type (sad_descriptor) kv\n integer*8 , intent(in)::kas\n integer*8 kp\n integer*4 isp0\n integer*4 , intent(out)::irtc\n logical*4 , intent(out)::ev\n isp=isp+1\n isp0=isp\n dtastk(isp)=kl%head\n call tfgetllstkall(kl)\n call tfdeval(isp0,kas,kv,1,.true.,ev,irtc)\n kp=ktfaddrd(kv)\n isp=isp0-1\n return\n end subroutine\n\n subroutine tfmakerulestk_dd(ks,kx)\n implicit none\n type (sad_descriptor) , intent(in)::kx,ks\n type (sad_dlist), pointer :: kl1\n isp=isp+1\n ktastk(isp)=ktflist+ktadaloc(-1,2,kl1)\n kl1%head%k=ktfoper+mtfrule\n kl1%dbody(1)=dtfcopy1(ks)\n kl1%dbody(2)=dtfcopy(kx)\n return\n end\n\n subroutine tfmakerulestk_dr(ks,x)\n implicit none\n type (sad_descriptor) , intent(in)::ks\n type (sad_dlist), pointer :: kl1\n real*8 , intent(in)::x\n isp=isp+1\n ktastk(isp)=ktflist+ktadaloc(-1,2,kl1)\n kl1%head%k=ktfoper+mtfrule\n kl1%dbody(1)=dtfcopy1(ks)\n kl1%rbody(2)=x\n return\n end\n\n recursive subroutine tfrebuildl(kl,klx,rep)\n implicit none\n type (sad_dlist), target, intent(inout) :: kl\n type (sad_dlist), pointer :: kli,klxi\n type (sad_dlist), pointer, intent(out) :: klx\n integer*8 kax\n integer*4 i,isp0\n logical*4, intent(out):: rep\n logical*4 rep1\n rep=.false.\n if(iand(kl%attr,ktoberebuilt) .eq. 0)then\n klx=>kl\n return\n endif\n kl%attr=kl%attr-ktoberebuilt\n if(ktfreallistq(kl))then\n klx=>kl\n return\n endif\n isp=isp+1\n isp0=isp\n dtastk(isp)=kl%head\n do i=1,kl%nl\n if(ktfsequenceq(kl%body(i),kli))then\n call tfgetllstkall(kli)\n rep=.true.\n elseif(ktflistq(kl%body(i),kli))then\n call tfrebuildl(kli,klxi,rep1)\n isp=isp+1\n if(rep1)then\n dtastk(isp)=sad_descr(klxi)\n rep=.true.\n else\n ktastk(isp)=kl%body(i)\n endif\n else\n isp=isp+1\n ktastk(isp)=kl%body(i)\n endif\n enddo\n if(rep)then\n kax=ktfcompose(isp0,klx)\n else\n klx=>kl\n endif\n isp=isp0-1\n return\n end subroutine \n\n subroutine tfmatrixmaybeq(k,cmplm,realm,vec,n,m,kl)\n implicit none\n type (sad_descriptor), intent(in):: k\n type (sad_dlist), pointer, intent(out) :: kl\n type (sad_dlist), pointer :: kli\n integer*4 i\n integer*4 , intent(out)::n,m\n logical*4 , intent(out)::cmplm,realm,vec\n n=0\n m=0\n realm=.false.\n cmplm=.false.\n vec=.false.\n if(ktflistq(k,kl))then\n if(kl%head%k .eq. ktfoper+mtflist)then\n n=kl%nl\n if(ktfnonreallistqo(kl))then\n do i=1,n\n if(ktfnonlistq(kl%dbody(i)))then\n return\n endif\n call descr_sad(kl%dbody(i),kli)\n if(kli%head%k .ne. ktfoper+mtflist)then\n return\n endif\n if(i .eq. 1)then\n m=kli%nl\n elseif(m .ne. kli%nl)then\n m=0\n return\n endif\n if(ktfnonreallistqo(kli))then\n cmplm=.true.\n return\n endif\n enddo\n realm=.true.\n else\n vec=.true.\n endif\n endif\n endif\n return\n end subroutine\n\n type (sad_descriptor) function kxm2l(a,n,m,nd,trans)\n implicit none\n type (sad_descriptor) kx,ki\n type (sad_dlist), pointer :: klx\n type (sad_rlist), pointer :: klr,klri\n integer*4 , intent(in)::n,m,nd\n integer*4 i\n logical*4 , intent(in)::trans\n real*8 , intent(in)::a(nd,m)\n if(n .eq. 0)then\n kx=kxavaloc(-1,m,klr)\n klr%rbody(1:m)=a(1:m,1)\n klr%attr=ior(klr%attr,lconstlist)\n else\n if(trans)then\n kx=kxadaloc(-1,m,klx)\n do i=1,m\n ki=kxavaloc(0,n,klri)\n klri%rbody(1:n)=a(1:n,i)\n klri%attr=ior(lconstlist,klri%attr)\n klx%dbody(i)=ki\n enddo\n else\n kx=kxadaloc(-1,n,klx)\n do i=1,n\n ki=kxavaloc(0,m,klri)\n klri%rbody(1:m)=a(i,:)\n klri%attr=ior(lconstlist,klri%attr)\n klx%dbody(i)=ki\n enddo\n endif\n klx%attr=ior(klx%attr,lconstlist)\n endif\n kxm2l=kx\n return\n end function\n\n type (sad_descriptor) function kxcopylist(k)\n implicit none\n type (sad_descriptor) , intent(in)::k\n type (sad_dlist), pointer :: kl,klx\n integer*4 m,i\n call descr_sad(k,kl)\n m=kl%nl\n kxcopylist=kxaaloc(-1,m,klx)\n if(ktfreallistq(kl))then\n klx%head=dtfcopy(kl%head)\n klx%body(1:m)=kl%body(1:m)\n else\n do i=0,m\n klx%dbody(i)=dtfcopy(kl%dbody(i))\n enddo\n endif\n klx%attr=kl%attr\n return\n end function\n\n type (sad_descriptor) function kxargsym(n0)\n implicit none\n integer*4, parameter :: nsym=1024 \n type (sad_descriptor), save :: ksym(nsym)\n integer*4 , intent(in)::n0\n integer*4 n,l,n1,ls,ifrac\n character*32 name,buf\n data ksym%k /nsym*0/\n data name /'`Class`s '/\n if(ksym(n0)%k .ne. 0)then\n kxargsym=ksym(n0)\n return\n endif\n n=n0\n l=32\n do while(n .ne. 0)\n n1=n/62\n ifrac=n-n1*62\n buf(l:l)=merge(char(ichar('0')+ifrac),\n $ merge(char(ichar('a')+ifrac-10),\n $ char(ichar('A')+ifrac-36),ifrac .lt. 36),\n $ ifrac .lt. 10)\n l=l-1\n n=n1\n enddo\n name(9:9+31-l)=buf(l+1:32)\n ls=9+32-l\n name(ls:ls)='$'\n kxargsym=kxsymbolz(name,ls)\n ksym(n0)=kxargsym\n return\n end function\n\n pure subroutine resetnan(a,xl)\n implicit none\n real*8, intent(in), optional:: xl\n real*8, intent(inout) ::a(:)\n real*8 x\n x=merge(xl,0.d0,present(xl))\n a=merge(x,a,ktfenanq(a))\n return\n end subroutine\n\n pure subroutine limitnan(a,x)\n implicit none\n real*8, intent(in) :: x\n real*8 , intent(inout)::a(:)\n a=sign(merge(x,merge(x,a,abs(a)>x),ktfenanq(a)),a)\n return\n end subroutine\n\n subroutine setompnumthreads(isp1,kx,irtc)\n implicit none\n integer*4 ,intent(in):: isp1\n integer*4 ,intent(out):: irtc\n integer*4 itfmessage,iv\n type (sad_descriptor),intent(out):: kx\n if(isp .ne. isp1+1)then\n irtc=itfmessage(9,'General::narg','\"1\"')\n return\n elseif(ktfnonrealq(dtastk(isp),iv))then\n irtc=itfmessage(9,'General::wrongtype','\"Real\"')\n return\n elseif(iv .le. 0)then\n irtc=itfmessage(9,'General::wrongval','\">= 1\"')\n return\n endif\nc call omp_set_num_threads(iv)\n kx=dfromr(dble(iv))\n irtc=0\n return\n end\n\n end module\n", "meta": {"hexsha": "7894d87a95ab7d1efdfbdbebb365f0cb1126c6a8", "size": 141146, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/tfstk.f", "max_stars_repo_name": "noboruatkek/SAD", "max_stars_repo_head_hexsha": "3881a190af8903537774c57b56963ffc94cfc039", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/tfstk.f", "max_issues_repo_name": "noboruatkek/SAD", "max_issues_repo_head_hexsha": "3881a190af8903537774c57b56963ffc94cfc039", "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/tfstk.f", "max_forks_repo_name": "noboruatkek/SAD", "max_forks_repo_head_hexsha": "3881a190af8903537774c57b56963ffc94cfc039", "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.2754265455, "max_line_length": 288, "alphanum_fraction": 0.5648052371, "num_tokens": 46203, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813538993888, "lm_q2_score": 0.7248702702332475, "lm_q1q2_score": 0.6929624623389957}} {"text": " FUNCTION CSNDEQC(SNDDIA,SSG,WS,TAUR,TAUB,D50,SIGPHI, \n & SNDDMX,IOPT,ISNDAL) \n INTEGER::IOPT,ISNDAL\n REAL::CSNDEQC,REY,SNDDIA,SSG,DFAC,D50,RLAM,SIGPHI,USTAR,TAUB\n REAL::VAL,WS,TMP,TAUR,TAURS,REY3,RATIO,SNDDMX\nC CHANGE RECORD \nC \nC \nC ** CALCULATES NEAR BED REFERENCE CONCENTRATION FOR NONCOHESIVE \nC ** SEDIMENT \nC ** IOPT=1 BASED ON \nC ** \nC ** GARCIA, M., AND G. PARKER, 1991: ENTRAINMENT OF BED SEDIMENT \nC ** INTO SUSPENSION, J. HYDRAULIC ENGINEERING, 117, 414-435. \nC \n IF(IOPT.EQ.1)THEN \n REY=1.E6*SNDDIA*SQRT( 9.8*(SSG-1.)*SNDDIA ) \n REY=REY**0.6 \n DFAC=1. \n IF(ISNDAL.GE.1) DFAC=(SNDDIA/D50)**0.2 \n RLAM=1.-0.29*SIGPHI \n USTAR=SQRT(TAUB) \n VAL=DFAC*RLAM*REY*USTAR/WS \n VAL=1.3E-7*(VAL**5) \n TMP=VAL/(1+3.33*VAL) \n CSNDEQC=1.E6*SSG*TMP \n IF(USTAR.LT.WS) CSNDEQC=0. \n ENDIF \nC \nC ** IOPT=2 BASED ON \nC ** \nC ** SMITH, J. D., AND S. R. MCLEAN, 1977: SPATIALLY AVERAGED FLOW \nC ** OVER A WAVY SURFACE, J. GEOPHYSICAL RESEARCH, 82, 1735-1746. \nC \n IF(IOPT.EQ.2)THEN \n VAL=2.4E-3*( (TAUB/TAUR)-1. ) \n VAL=MAX(VAL,0.) \n TMP=0.65*VAL/(1.+VAL) \n CSNDEQC=1.E6*SSG*TMP \n USTAR=SQRT(TAUB) \n IF(USTAR.LT.WS) CSNDEQC=0. \n ENDIF \nC \nC ** IOPT=3 BASED ON \nC ** \nC ** VAN RIJN, L. C., 1984: SEDIMENT TRANSPORT, PART II: SUSPENDED \nC ** LOAD TRANSPORT, J. HYDRAULIC ENGINEERING, 110, 1623-1641. \nC \n IF(IOPT.EQ.3)THEN \n REY=1.E4*SNDDIA*( (9.8*(SSG-1.))**0.333 ) \n IF(REY.LE.10.) TAURS=(4.*WS/REY)**2 \n IF(REY.GT.10.) TAURS=0.016*WS*WS \n REY3=REY**0.3 \n VAL=(TAUB/TAURS)-1. \nC \nC VAL=(TAUB/TAUR)-1. \nC \n VAL=MAX(VAL,0.) \n VAL=VAL**1.5 \n RATIO=SNDDIA/(3.*SNDDMX) \n TMP=0.015*RATIO*VAL/REY3 \n CSNDEQC=1.E6*SSG*TMP \n USTAR=SQRT(TAUB) \n IF(USTAR.LT.WS) CSNDEQC=0. \n ENDIF \n 600 FORMAT(10E12.4) \n RETURN \n END \n\n", "meta": {"hexsha": "f852618b0576cab4cebbe0d1c587c337115a8551", "size": 2054, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "EFDC_src/CSNDEQC.f", "max_stars_repo_name": "T-Carlotto/SW2D-EFDC", "max_stars_repo_head_hexsha": "7b01a41a308cb79db569a0e6291fe40797f3ef28", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 32, "max_stars_repo_stars_event_min_datetime": "2018-03-31T22:19:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-14T01:35:23.000Z", "max_issues_repo_path": "EFDC_src/CSNDEQC.f", "max_issues_repo_name": "T-Carlotto/SW2D-EFDC", "max_issues_repo_head_hexsha": "7b01a41a308cb79db569a0e6291fe40797f3ef28", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-04-02T06:13:13.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-10T07:15:07.000Z", "max_forks_repo_path": "EFDC_src/CSNDEQC.f", "max_forks_repo_name": "T-Carlotto/SW2D-EFDC", "max_forks_repo_head_hexsha": "7b01a41a308cb79db569a0e6291fe40797f3ef28", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2018-06-27T02:55:23.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-09T07:51:23.000Z", "avg_line_length": 29.3428571429, "max_line_length": 69, "alphanum_fraction": 0.5374878286, "num_tokens": 916, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632316144274, "lm_q2_score": 0.727975460709318, "lm_q1q2_score": 0.692933074566773}} {"text": "program svd\n use util_mod, only : print_matrix\n use, intrinsic :: iso_fortran_env, only : error_unit\n implicit none\n integer, parameter :: nr_rows = 3, nr_cols = 4\n real, dimension(nr_rows, nr_cols) :: M, M_orig, Sigma, tmp\n real, dimension(nr_rows, nr_rows) :: U\n real, dimension(nr_cols, nr_cols) :: VT\n real, dimension(min(nr_rows, nr_cols)) :: S\n real, dimension(:), allocatable :: work\n integer :: istat, work_size, info\n\n call random_number(M)\n M_orig = M\n\n ! compute full SVD of M\n allocate(work(1))\n info = 0\n call sgesvd('A', 'A', nr_rows, nr_cols, M, nr_rows, S, &\n U, nr_rows, VT, nr_cols, work, -1, info)\n work_size = int(work(1)) + 1\n write (unit=error_unit, fmt='(A, I0, A)') &\n 'work size is ', work_size, ' double'\n deallocate(work)\n allocate(work(work_size), stat=istat)\n if (istat /= 0) then\n write (unit=error_unit, fmt='(A)') 'can not allocate work array'\n stop\n end if\n call sgesvd('A', 'A', nr_rows, nr_cols, M, nr_rows, S, &\n U, nr_rows, VT, nr_cols, work, work_size, info)\n\n call compute_sigma(S, Sigma)\n\n ! print results if verbose\n print '(A)', 'U'\n call print_matrix(U)\n print '(A)', 'Sigma'\n call print_matrix(Sigma)\n print '(A)', 'V^t'\n call print_matrix(VT)\n\n call sgemm('N', 'N', nr_rows, nr_cols, nr_rows, 1.0, U, nr_rows, &\n Sigma, nr_rows, 0.0, tmp, nr_rows)\n call sgemm('N', 'N', nr_rows, nr_cols, nr_cols, 1.0, tmp, nr_rows, &\n VT, nr_cols, 0.0, M, nr_rows)\n\n print '(A)', 'M'\n call print_matrix(M)\n print '(A)', 'orig. M'\n call print_matrix(M_orig)\n\n ! compute and print relative error\n print '(A, E10.3)', 'relative error = ', compute_error(M_orig, M)\n\ncontains\n\n subroutine compute_sigma(S, Sigma)\n implicit none\n real, dimension(:), intent(in) :: S\n real, dimension(:, :), intent(out) :: Sigma\n integer :: i\n Sigma = 0.0\n do i = 1, min(size(Sigma, 1), size(Sigma, 2))\n Sigma(i, i) = S(i)\n end do\n end subroutine compute_sigma\n\n function compute_error(orig_A, A) result(rel_err)\n implicit none\n real, dimension(:, :), intent(in) :: orig_A, A\n real :: rel_err\n integer :: i, j\n real :: norm\n rel_err = 0.0\n do j = 1, size(A, 2)\n do i = 1, size(A, 1)\n norm = abs(orig_A(i, j))\n rel_err = rel_err + abs(A(i, j) - orig_A(i, j))/norm\n end do\n end do\n rel_err = rel_err/(size(A, 1)*size(A, 2))\n end function compute_error\n\nend program svd\n", "meta": {"hexsha": "446514da2faa09618cf67b5f21e3b36419b467bc", "size": 2655, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source_code/blas_lapack/svd.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/blas_lapack/svd.f90", "max_issues_repo_name": "gjbex/CMake-intro", "max_issues_repo_head_hexsha": "b4855c172f1d4a965f2b148b96ed160f4ea1e5bd", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-09-30T04:25:50.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-06T08:21:30.000Z", "max_forks_repo_path": "source_code/blas_lapack/svd.f90", "max_forks_repo_name": "gjbex/CMake-intro", "max_forks_repo_head_hexsha": "b4855c172f1d4a965f2b148b96ed160f4ea1e5bd", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2021-09-27T07:30:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-07T16:23:19.000Z", "avg_line_length": 30.8720930233, "max_line_length": 72, "alphanum_fraction": 0.5634651601, "num_tokens": 816, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711756575749, "lm_q2_score": 0.8152324848629214, "lm_q1q2_score": 0.6929241135931834}} {"text": "program main\n implicit none\n integer,parameter :: kd = kind(1.0)\n real(kd),parameter :: pi = 4.0_kd*atan(1.0_kd)\n real(kd),allocatable :: R(:) ! \u81ea\u76f8\u5173\u51fd\u6570\u503c\n real(kd),allocatable :: S(:) ! \u6ce2\u80fd\u8c31\u503c\n real(kd),allocatable :: omg(:) ! \u9891\u7387\n real(kd),allocatable :: zeta(:) ! \u6ce2\u9762\u5347\u9ad8\n integer :: n ! \u5bf9\u65f6\u95f4 N \u7b49\u5206\n integer :: m ! \u6ede\u540e\u6ce2\u6d6a\u6570\u91cf\n real(kd) :: T ! \u603b\u65f6\u95f4 s\n real(kd) :: tp(2) ! \u65f6\u95f4\u8282\u70b9\n real(kd) :: dt ! \u65f6\u95f4\u95f4\u9694\n\n real(kd) :: tmp\n logical :: exists\n integer :: i,k,ierr \n character(128) :: filename\n \n\n filename = \"random_wave.csv\" \n open(10,file=trim(adjustl(filename)))\n n = 0\n do\n read(10,*,iostat = ierr )\n if(ierr .ne. 0 ) exit\n n = n + 1\n end do\n close(10) \n m = n/37 ! \u9009\u62e9\u5408\u9002\u7684\u503c\n allocate( R(0:m),S(0:m),omg(0:m),zeta(n) )\n R = 0.0_kd; S = 0.0_kd; omg = 0.0_kd; zeta = 0.0_kd\n\n\n ! \u8bfb\u53d6\u6ce2\u9762\u5347\u9ad8\n open(10,file=trim(adjustl(filename)))\n read(10,*) tp(1),zeta(1)\n do i = 2, n-1\n read(10,*) tmp,zeta(i)\n end do\n read(10,*) tp(2),zeta(n)\n close(10)\n T = tp(2) - tp(1)\n dt = T/n \n \n ! \u83b7\u53d6\u5404 k \u503c\u5904\u7684\u81ea\u76f8\u5173\u51fd\u6570\n do k = 0, m\n do i = 1, n-k\n R(k) = R(k) + zeta(i)*zeta(i+k)\n end do\n R(k) = R(k) / real(n-k,kd)\n end do\n \n ! \u5229\u7528\u68af\u5f62\u79ef\u5206\u83b7\u5f97\u8c31\u503c\n do i = 0, m\n omg(i) = real(i,kd)*pi/m/dt\n do k = 1, m-1\n S(i) = S(i) + 2.0_kd*R(k)*cos( (real(i,kd)*k)/m*pi )\n end do\n S(i) = S(i) + R(0) + R(m)*cos( real(i,kd)*pi )\n end do\n S = S * dt / pi\n\n ! Hamming\u5e73\u6ed1\n S(0) = 0.54_kd*S(0)+0.46_kd*S(1)\n do i = 1, m-1\n S(i) = 0.54_kd*S(i) + 0.23_kd*(S(i-1)+S(i+1))\n end do\n S(m) = 0.54_kd*S(m)+0.46_kd*S(m-1)\n ! \u8f93\u51fa\u8c31\u503c\n filename = \"BNP01.csv\" \n open(10,file=trim(adjustl(filename)))\n do i = 0, m\n write(10,\"(f12.7,',',f12.7)\") omg(i),S(i)\n end do\n close(10)\n deallocate( R,S,omg,zeta )\nend program\n\n\n", "meta": {"hexsha": "9f63dbf99e4aa14af20ed31f6a981a4c376e821c", "size": 2070, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "analysis.f90", "max_stars_repo_name": "Fitanium/Analysis-of-Irregular-Wave-Energy-Spectrum-based-on-Autocorrelation-Function-Method", "max_stars_repo_head_hexsha": "4109304031df4cea98ca22a07437dd44a01e0847", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-17T08:37:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-17T08:37:18.000Z", "max_issues_repo_path": "analysis.f90", "max_issues_repo_name": "Fitanium/Analysis-of-Irregular-Wave-Energy-Spectrum-based-on-Autocorrelation-Function-Method", "max_issues_repo_head_hexsha": "4109304031df4cea98ca22a07437dd44a01e0847", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "analysis.f90", "max_forks_repo_name": "Fitanium/Analysis-of-Irregular-Wave-Energy-Spectrum-based-on-Autocorrelation-Function-Method", "max_forks_repo_head_hexsha": "4109304031df4cea98ca22a07437dd44a01e0847", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-01-20T09:52:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-20T09:52:17.000Z", "avg_line_length": 25.5555555556, "max_line_length": 60, "alphanum_fraction": 0.4400966184, "num_tokens": 883, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813454, "lm_q2_score": 0.7718435083355187, "lm_q1q2_score": 0.6928802879014831}} {"text": "c program DRDBINOM\nc>> 1998-05-12 DRDBINOM Krogh Ensure Pascal print output.\nc>> 1995-12-15 DRDBINUM Krogh Initial Code.\nc--D replaces \"?\": DR?BINOM, ?BINOM\nc\nc Test DBINOM for computing binomial coefficients.\nc Checks a large value computed with factorials, one a little larger\nc that is computed using log gamma, and then finds first that differs\nc from that obtained using the Pascal triangle.\nc\n integer K, N, NMAX\n parameter (NMAX = 120)\n external DBINOM\n double precision BC1, BC2, P(0:NMAX), TP, DBINOM\nc ( 150 ) ( 151 )\nc BC1 = ( ) BC2 = ( )\nc ( 30 ) ( 29 )\n parameter (BC1 = 32198785340494567031466236484400.D0)\n parameter (BC2 = 9880808670399701168713050486000.D0)\nc\n 10 format (/' N K',12X,'DBINOM',20X, A, 8X, ' Col. 2 - Col. 1')\n 20 format (I4, I4,1P,E26.17,E26.17,1P,E16.7)\nc\n print 10, ' True '\n TP = DBINOM(150, 30)\n print 20, 150, 30, TP, BC1, BC1 - TP\n TP = DBINOM(151, 29)\n print 20, 151, 29, TP, BC2, BC2 - TP\nc\n print 10, 'Pascal'\n P(0) = 1.D0\n do 80 N = 0, NMAX\n do 40 K = 0, N\n TP = DBINOM(N, K)\n if (TP .ne. P(K)) go to 100\n 40 continue\nc Update the Pascal Triangle.\n P(N+1) = 1.D0\n do 60 K = N, 1, -1\n P(K) = P(K) + P(K-1)\n 60 continue\n 80 continue\n 100 print 20, N, K, TP, P(K), P(K) - TP\n stop\n end\n", "meta": {"hexsha": "8b3ba3ed1e1b8cfe0fedbe9d4f5cd3686e9924dd", "size": 1471, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drdbinom.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drdbinom.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drdbinom.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": 31.9782608696, "max_line_length": 70, "alphanum_fraction": 0.5499660095, "num_tokens": 550, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953003183444, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6928802758801051}} {"text": "! Pseudorandom number generator\n! (and a bad one at that)\n module lcgenerator\n integer*8, save :: random_last = 0\n contains\n\n subroutine seed(s)\n integer :: s\n random_last = s\n end subroutine\n\n real function lcgrandom()\n integer*8, parameter :: MULTIPLIER = 1366\n integer*8, parameter :: ADDEND = 150889\n integer*8, parameter :: PMOD = 714025\n \n integer*8 :: random_next = 0\n random_next = mod((MULTIPLIER * random_last + ADDEND), PMOD)\n random_last = random_next\n lcgrandom = (1.0*random_next)/PMOD\n return\n end function\n end module lcgenerator\n", "meta": {"hexsha": "87e7209f2552f08b6979db28012dcbb04e17ba8d", "size": 725, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "darts/collective/fortran/lcgenerator.f", "max_stars_repo_name": "PawseySC/Intermediate-Supercomputing", "max_stars_repo_head_hexsha": "2adfdbe994d1a07491ffee783bfd2a2c03f03e7e", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-04-06T02:57:44.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-27T22:01:11.000Z", "max_issues_repo_path": "darts/collective/fortran/lcgenerator.f", "max_issues_repo_name": "PawseySupercomputing/Intermediate-Supercomputing", "max_issues_repo_head_hexsha": "28252556226354ef9a01178d6ebb54757b0bea2f", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-10-09T07:20:40.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-22T04:23:27.000Z", "max_forks_repo_path": "darts/collective/fortran/lcgenerator.f", "max_forks_repo_name": "PawseySupercomputing/Intermediate-Supercomputing", "max_forks_repo_head_hexsha": "28252556226354ef9a01178d6ebb54757b0bea2f", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-03-01T05:56:44.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-02T15:54:39.000Z", "avg_line_length": 30.2083333333, "max_line_length": 72, "alphanum_fraction": 0.5489655172, "num_tokens": 173, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8976952975813453, "lm_q2_score": 0.7718434873426302, "lm_q1q2_score": 0.6928802690562657}} {"text": "! These are chosen to match the wrf module_model_constants.F where\n! applicable\nMODULE wrf_constants\n INTEGER, PARAMETER :: ERRLEN=512\n INTEGER, PARAMETER :: ALGERR=64\n\n REAL(KIND=8), PARAMETER :: WRF_EARTH_RADIUS = 6370000.D0\n REAL(KIND=8), PARAMETER :: T_BASE = 300.0D0\n REAL(KIND=8), PARAMETER :: PI = 3.1415926535897932384626433D0\n REAL(KIND=8), PARAMETER :: RAD_PER_DEG = PI/180.D0\n REAL(KIND=8), PARAMETER :: DEG_PER_RAD = 180.D0/PI\n REAL(KIND=8), PARAMETER :: DEFAULT_FILL = 9.9692099683868690D36\n INTEGER(KIND=1), PARAMETER :: DEFAULT_FILL_INT8 = -127\n INTEGER(KIND=2), PARAMETER :: DEFAULT_FILL_INT16 = -32767\n INTEGER(KIND=4), PARAMETER :: DEFAULT_FILL_INT32 = -2147483647\n INTEGER(KIND=8), PARAMETER :: DEFAULT_FILL_INT64 = INT(-9223372036854775806D0, KIND=8)\n REAL(KIND=4), PARAMETER :: DEFAULT_FILL_FLOAT = 9.9692099683868690E36\n REAL(KIND=8), PARAMETER :: DEFAULT_FILL_DOUBLE = 9.9692099683868690D36\n CHARACTER(LEN=1), PARAMETER :: DEFAULT_FILL_CHAR = ACHAR(0)\n\n\n REAL(KIND=8), PARAMETER :: P1000MB = 100000.D0\n ! j/k/kg\n REAL(KIND=8), PARAMETER :: RD = 287.D0\n REAL(KIND=8), PARAMETER :: RV = 461.6D0\n !REAL(KIND=8), PARAMETER :: RV = 461.5D0\n ! j/k/kg note: not using bolton's value of 1005.7\n REAL(KIND=8), PARAMETER :: CP = 1004.5D0\n !REAL(KIND=8), PARAMETER :: CP = 1004D0\n\n REAL(KIND=8), PARAMETER :: G = 9.81D0\n REAL(KIND=8), PARAMETER :: USSALR = 0.0065D0 ! deg C per m\n\n REAL(KIND=8), PARAMETER :: CELKEL = 273.15D0\n REAL(KIND=8), PARAMETER :: CELKEL_TRIPLE = 273.16D0\n !REAL(KIND=8), PARAMETER :: GRAV = 9.81D0\n ! hpa\n REAL(KIND=8), PARAMETER :: EZERO = 6.112D0\n REAL(KIND=8), PARAMETER :: ESLCON1 = 17.67D0\n REAL(KIND=8), PARAMETER :: ESLCON2 = 29.65D0\n REAL(KIND=8), PARAMETER :: EPS = 0.622D0\n REAL(KIND=8), PARAMETER :: GAMMA = RD/CP\n ! cp_moist=cp*(1.+cpmd*qvp)\n REAL(KIND=8), PARAMETER :: CPMD = .887D0\n ! rgas_moist=rgas*(1.+rgasmd*qvp)\n REAL(KIND=8), PARAMETER :: RGASMD = .608D0\n ! gamma_moist=gamma*(1.+gammamd*qvp)\n REAL(KIND=8), PARAMETER :: GAMMAMD = RGASMD - CPMD\n REAL(KIND=8), PARAMETER :: TLCLC1 = 2840.D0\n REAL(KIND=8), PARAMETER :: TLCLC2 = 3.5D0\n REAL(KIND=8), PARAMETER :: TLCLC3 = 4.805D0\n REAL(KIND=8), PARAMETER :: TLCLC4 = 55.D0\n ! k\n REAL(KIND=8), PARAMETER :: THTECON1 = 3376.D0\n REAL(KIND=8), PARAMETER :: THTECON2 = 2.54D0\n REAL(KIND=8), PARAMETER :: THTECON3 = .81D0\n\n REAL(KIND=8), PARAMETER :: ABSCOEFI = .272D0 ! cloud ice absorption coefficient in m^2/g\n REAL(KIND=8), PARAMETER :: ABSCOEF = .145D0 ! cloud water absorption coefficient in m^2/g\n\n REAL(KIND=8), PARAMETER :: GAMMA_SEVEN = 720.D0\n REAL(KIND=8), PARAMETER :: RHOWAT = 1000.D0\n REAL(KIND=8), PARAMETER :: RHO_R = RHOWAT\n REAL(KIND=8), PARAMETER :: RHO_S = 100.D0\n REAL(KIND=8), PARAMETER :: RHO_G = 400.D0\n REAL(KIND=8), PARAMETER :: ALPHA = 0.224D0\n\n REAL(KIND=8), PARAMETER :: SCLHT = RD*256.D0/G\n REAL(KIND=8), PARAMETER :: EXPON = RD*USSALR/G\n REAL(KIND=8), PARAMETER :: EXPONI = 1./EXPON\n\n\nEND MODULE wrf_constants\n\n", "meta": {"hexsha": "08645026d41530ee70224c49695682234c73016e", "size": 3131, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/wrf_constants.f90", "max_stars_repo_name": "skysightsoaringweather/wrf-python", "max_stars_repo_head_hexsha": "1f12654263c9d7bdd0b309a98eb5c1dbc2564901", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 315, "max_stars_repo_stars_event_min_datetime": "2016-12-29T17:42:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T03:57:41.000Z", "max_issues_repo_path": "fortran/wrf_constants.f90", "max_issues_repo_name": "skysightsoaringweather/wrf-python", "max_issues_repo_head_hexsha": "1f12654263c9d7bdd0b309a98eb5c1dbc2564901", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 147, "max_issues_repo_issues_event_min_datetime": "2017-01-19T17:45:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T15:00:29.000Z", "max_forks_repo_path": "fortran/wrf_constants.f90", "max_forks_repo_name": "skysightsoaringweather/wrf-python", "max_forks_repo_head_hexsha": "1f12654263c9d7bdd0b309a98eb5c1dbc2564901", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 112, "max_forks_repo_forks_event_min_datetime": "2016-12-29T12:56:52.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-16T08:05:49.000Z", "avg_line_length": 41.7466666667, "max_line_length": 95, "alphanum_fraction": 0.6512296391, "num_tokens": 1211, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133464597459, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6928648009338592}} {"text": "fibonacci = lambda(n) \n if n <= 2 \n then n \n else fibonacci(n-1) + fibonacci(n-2);\n\nprint(fibonacci(27));", "meta": {"hexsha": "2e8bb36f4536ef08d45b2093da8f12217af55181", "size": 150, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "examples/fibonacci.f", "max_stars_repo_name": "git-bauerseb/M-Lang", "max_stars_repo_head_hexsha": "6b0dcb4b15a7fbc79f7eb92d309ed33b20a91093", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-11-14T20:38:24.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-30T13:46:55.000Z", "max_issues_repo_path": "examples/fibonacci.f", "max_issues_repo_name": "git-bauerseb/M-Lang", "max_issues_repo_head_hexsha": "6b0dcb4b15a7fbc79f7eb92d309ed33b20a91093", "max_issues_repo_licenses": ["MIT"], "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/fibonacci.f", "max_forks_repo_name": "git-bauerseb/M-Lang", "max_forks_repo_head_hexsha": "6b0dcb4b15a7fbc79f7eb92d309ed33b20a91093", "max_forks_repo_licenses": ["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.0, "max_line_length": 53, "alphanum_fraction": 0.4466666667, "num_tokens": 38, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133464597458, "lm_q2_score": 0.7371581568543044, "lm_q1q2_score": 0.6928647900790275}} {"text": "! **************************************************************************\n! ... test_ltm.f90\n! ... Quim Ballabrera, January 2018\n! ...\n! ... System Dynamics\n! ... Adjoint methods applied to the Lorenz model\n! ...\n! ... Test the Tangent Linear Model (the derivative of the Linear Model)\n! ... by calculating the numerical local derivative of the Nonlinear model\n! ...\n! ... L dx = [M(xr+alpha*dx) -M(xr)]/alpha\n! ... So,\n! ... [ (M(xr+alpha*dx)-M(xr) ] / [ alpha*L dx ] -> 1\n! ...\n! **************************************************************************\n\nprogram test_ltm\n\nuse sysdyn\n\nimplicit none\n\ninteger, parameter :: NVE = lorenz_n\n\nlogical Zexist\n\ninteger iu,i,iter,rr,record\nreal(dp) alpha,tr\nreal(dp), dimension(NVE) :: xr,yr,dx,dy\nreal(dp), dimension(NVE) :: xp,yp,dyp\n\ncharacter(len=180) nfile,tfile,dfile\n\nNAMELIST /namltm/ tfile, &\n record, &\n dfile\n\ncall header()\n\n! ... Default initialization\n! ...\ntfile = '../../work/lorenz_simulation.dat'\nrecord = 101\ndx = [0.1D0,0.2D0,0.5D0]\n\n\ncall getarg(1,nfile)\ninquire(file=nfile,exist=Zexist)\n\nif ((len_trim(nfile).gt.0).and. &\n (.not.Zexist)) call stop_error(1,'Namelist file not found')\n\n\nif (Zexist) then\n write(*,*) 'Reading ', trim(nfile)\n iu = unitfree()\n open(iu,file=nfile,status='old')\n rewind(iu)\n read(iu,namltm)\n close(iu)\n\n ! ... Read the perturbation:\n ! ...\n open(iu,file=tfile,status='old')\n read(iu,*) tr, dx\n close(iu)\n \nendif\n\n\niu = unitfree()\nopen(iu,file=tfile,status='old')\ndo rr=1,record\n read(iu,*,end=2000,err=2000) tr, xr\nenddo\n\n! ... Save the reference for the LTM code\n! ... LORENZ_REF(1:LORENZ_N) is a vector in the LORENZ module\n! ...\nlorenz_ref(:) = xr(:)\n\n\nwrite(*,*) \nwrite(*,*) 'Reference state : '\nwrite(*,'(100(F12.7))') SNGL(xr)\n\nwrite(*,*) \nwrite(*,*) 'Perturbation vector : '\nwrite(*,'(100(F12.8))') SNGL(dx)\n\n\ncall lorenz_rhs(NVE,tr,xr,yr) ! Reference Run\n\nwrite(*,*)\nwrite(*,*) 'Positive perturbations:'\nwrite(*,*) '------------------------------------------------------'\n\nalpha = one\ndo iter=1,5\n xp(:) = xr(:) + alpha*dx(:)\n call lorenz_rhs(NVE,tr,xp,yp)\n dyp(:) = yp(:) - yr(:)\n\n call lorenz_ltm(NVE,tr,dx,dy)\n dy = alpha*dy\n\n write(*,*)\n write(*,'(T2,\"alpha, a = \",F9.6)') alpha\n write(*,'(T2,\"M(x+a*dx)-M(x) = \",8F10.6)') dyp(:)\n write(*,'(T2,\"a*LTM(dx) = \",8F10.6)') dy(:)\n write(*,'(T2,\"(M(x+a*dx)-M(x))/(a*LTM(dx)) = \",8F10.6)') (dyp(i)/dy(i),i=1,NVE)\n\n alpha = 0.1D0*alpha\nenddo\n\n\nwrite(*,*)\nwrite(*,*) 'Negative perturbations:'\nwrite(*,*) '------------------------------------------------------'\n\nalpha = one\ndo iter=1,5\n xp(:) = xr(:) - alpha*dx(:)\n call lorenz_rhs(NVE,tr,xp,yp)\n dyp(:) = yp(:) - yr(:)\n\n call lorenz_ltm(NVE,tr,dx,dy)\n dy = alpha*dy\n\n write(*,*)\n write(*,'(T2,\"alpha, a = \",F9.6)') alpha\n write(*,'(T2,\"M(x-a*dx)-M(x) = \",8F10.6)') dyp(:)\n write(*,'(T2,\"a*LTM(dx) = \",8F10.6)') dy(:)\n write(*,'(T2,\"(M(x-a*dx)-M(x))/(a*LTM(dx)) = \",8F10.6)') (dyp(i)/dy(i),i=1,NVE)\n\n alpha = 0.1D0*alpha\nenddo\n\n\n\n\n! ... Success run\n! ...\ncall stop_error(0,'TEST_LTM Ok')\n\n! ... Faulted run\n! ...\n2000 call stop_error(1,'TEST _LTM: Error reading input file')\n\nend program test_ltm\n\n", "meta": {"hexsha": "ac665391b58908867b6ef021263336aaa34ffe90", "size": 3359, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/4dvar/test_ltm.f90", "max_stars_repo_name": "quimbp/system_dynamics", "max_stars_repo_head_hexsha": "366339d9f6fea2e4242f8a73b700f8ea0af07797", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-11-22T13:23:22.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-22T13:23:22.000Z", "max_issues_repo_path": "src/4dvar/test_ltm.f90", "max_issues_repo_name": "quimbp/system_dynamics", "max_issues_repo_head_hexsha": "366339d9f6fea2e4242f8a73b700f8ea0af07797", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/4dvar/test_ltm.f90", "max_forks_repo_name": "quimbp/system_dynamics", "max_forks_repo_head_hexsha": "366339d9f6fea2e4242f8a73b700f8ea0af07797", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.0986842105, "max_line_length": 81, "alphanum_fraction": 0.5087823757, "num_tokens": 1139, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240860523328, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.6927780057228846}} {"text": "!!\r\n!! Luke McCulloch\r\n!! Module to compute Points on a plate\r\n!! geo.f90\r\n!! Inputs Number of points in X, NI\r\n!! Number of points in Y, NJ\r\n!! Physical (RECTangular) Plate Dimentions, lx, ly\r\n!! Output The Array, \"Points\"\r\n!!\r\n\r\nMODULE geo\r\n\r\n use precise, only : defaultp\r\n\r\n IMPLICIT NONE\r\n INTEGER, PARAMETER, PRIVATE :: WP=defaultp\r\n\r\nCONTAINS\r\n\r\n Subroutine D1(NI, dx, X)\r\n INTEGER :: NI, i\r\n REAL(wp) :: dx\r\n REAL(wp), DIMENSION(NI) :: X\r\n X(1)=0.0\r\n Do i = 2,NI\r\n x(i)=x(i-1)+dx\r\n End Do\r\n End Subroutine D1\r\n\r\n\r\n Subroutine V1(NV, dx, V) \r\n INTEGER :: NV, i\r\n REAL(wp) :: dx\r\n REAL(wp), DIMENSION(NV) :: V\r\n V(1)=-.025\r\n Do i = 2,NV\r\n V(i)=V(i-1)+dx\r\n End Do\r\n End Subroutine V1\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n Subroutine plate( NI, NJ, lx, ly, dx, dy, X, Y, Points )!!! Set lx and ly to 1 for initial tests\r\n ! Subroutine to Compute Points on a Plate\r\n \r\n INTEGER :: NI, NJ, i, j, ipt\r\n REAL(wp) :: lx, ly, dx, dy, Xo, Yo!, X, Y ! Number of X points, Number of Y Points, Length of plate in x, Length of plate in Y, step x, step y\r\n \r\n REAL(wp), DIMENSION(2,NJ*NI) :: Points ! Matrix of Points on the Plate\r\n REAL(wp), DIMENSION(NI,NJ) :: X \r\n REAL(wp), DIMENSION(NI,NJ) :: Y \r\n\r\n dx = lx/(NI-1)\r\n dy = ly/(NJ-1)\r\n\r\n Xo=0.\r\n Yo=0.\r\n\r\n !How do you want it? Scalars or Vectors...\r\n ipt=1 ! point counter\r\n Do j = 1,NJ\r\n Do i = 1,NI\r\n X(i,j) = Xo+REAL(dx*i)-dx\r\n Y(i,j) = Yo+REAL(dy*j)-dy\r\n Points(:,ipt)=(/ X(i,j), Y(i,j) /) ! Vector Version - Not used\r\n ipt=ipt+1\r\n End Do\r\n !ipt=ipt+1\r\n End Do\r\n\r\n\r\n\r\n END SUBROUTINE plate\r\nEND MODULE geo\r\n \r\n", "meta": {"hexsha": "16ec92971795401fc0018cb9b9098fec09b3be17", "size": 1719, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Euler/newton/src/geo.f90", "max_stars_repo_name": "LukeMcCulloch/ModelEquations", "max_stars_repo_head_hexsha": "57d892c1653a7c35d2a608b9daca9e776f63e9c5", "max_stars_repo_licenses": ["MIT"], "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/newton/src/geo.f90", "max_issues_repo_name": "LukeMcCulloch/ModelEquations", "max_issues_repo_head_hexsha": "57d892c1653a7c35d2a608b9daca9e776f63e9c5", "max_issues_repo_licenses": ["MIT"], "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/newton/src/geo.f90", "max_forks_repo_name": "LukeMcCulloch/ModelEquations", "max_forks_repo_head_hexsha": "57d892c1653a7c35d2a608b9daca9e776f63e9c5", "max_forks_repo_licenses": ["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.4875, "max_line_length": 148, "alphanum_fraction": 0.5258871437, "num_tokens": 578, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240686758841, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.6927779897522055}} {"text": "! ============================== PROGRAM MAKE_TTTABLE ================================== !\n\n! This program is a self-contained Fortran90 script to generate a travel time table T(X,Z)\n! for P or S arrivals from a source located at a depth Z to point at the surface (Z = 0)\n! at horizontal offset X. The calculated travel times are obtained via numerical \n! ray tracing through input velocity model. \n\n! No object file dependencies. To compile, simply type: gfortran -O make_TTtable.f90 -o make_TTtable\n\nprogram make_TTtable\n\t\n\timplicit none\n\t\n\t! ---------------- parameter and variable declarations ---------------\n\tinteger, parameter :: npts0=1000,nz0=100,nx0=500,nray0=40002,ncount0=80002\n\treal, parameter :: erad=6371., pi=3.1415927\n\t!-------\n\tinteger :: i,j,k,kk,iz,i2,ideprad\n real :: zz,z1,z2,fact,zmin,zmax,alpha0,beta0,sfact,dz\n\tinteger :: npts,ndep,nump,np,ncount,ndel,nz_s,nz,nk\n\tinteger :: ideptype,idep,itype,icount,idel,iw,imth,irtr\n\treal :: ecircum,kmdeg,degrad,angle\n\treal :: p,pmin,pmax,pstep,plongcut,frac,xcore,tcore,h\n\treal :: dep,dep1,dep2,dep3,del,del1,del2,del3,deldel\n\treal :: scr1,scr2,scr3,scr4,xold,x,x1,x2,dx,t,t1,t2,dt\n\treal :: tbest,pbest,ubest\n\treal :: xsave(ncount0),tsave(ncount0),psave(ncount0),usave(ncount0)\n\treal :: deptab(nz0),ptab(nray0),delttab(nray0)\n\treal :: z_inp(npts0),alpha_inp(npts0),beta_inp(npts0) \n\treal :: z_s(npts0),r_s(npts0),alpha_s(npts0),beta_s(npts0)\n\treal :: z(npts0),alpha(npts0),beta(npts0)\n\treal :: slow(npts0,2),deltab(nray0),tttab(nray0)\n\treal :: angang(nx0,nz0),tt(nx0,nz0),rayray(nx0,nz0),etaeta(nx0,nz0)\n\treal :: depxcor(nray0,nz0),deptcor(nray0,nz0)\n\treal :: depucor(nray0,nz0)\n character*100 ttfile, vmodel\n\n ! define fixed variables\n\tecircum=2.*pi*erad\n\tkmdeg=ecircum/360.\n\tdegrad=180./pi\n\tzmax = 9999 ! maximum depth\n\tnump = 9998 ! number of rays\n\tideptype = 1 ! Source depths: (1) Range, (2) Exact\n\n\n!--------------------- INPUT AND SETUP -------------------------------------!\n\t\n\t\n\t! -------- Parse Input for TT table ------------- !\n\tprint *, 'Enter name of output travel-time table '\n\tread *, ttfile\n\tprint *,ttfile\n\tprint *, 'Enter phase for travel time-table: P=1, S=2'\n\tread *, iw\n\tprint *, iw\n\tprint *, 'Enter table output units: 1 = (x in km, t in sec), 2 = (x in deg, t in min.)'\n\tread *, itype\n\tprint *, itype\n\tprint *, 'Enter travel-time table depths (km): min, max, space'\n\tread *, dep1,dep2,dep3\n\tprint *, dep1,dep2,dep3\n\t\n\tprint *, 'Enter travel-time table distances (del): min, max, space'\n\tread *, del1,del2,del3\n\tprint *, del1,del2,del3\n\t\n\t! ------ Parse Inputs for Velocity Model ------------!\n\tprint *, 'Enter assumed Vp/Vs if Vs not specified in input file: '\n\tread *, sfact\n\tprint *, sfact\n\tprint *, 'Enter min ray param (p-P, p-S) at long range (.133 = no Pn, .238 = no Sn):'\n\tread *, plongcut\n\tprint *, plongcut\n\tprint *, 'Enter name of velocity model (for reference only)'\n\tread *, vmodel\n\tprint *, vmodel\n\tprint *, 'Enter velo. model input format for first column (1=depth, 2=radius)'\n\tread *, ideprad\n\tprint *, ideprad\n\tprint *, 'Enter number of lines in velocity model'\n\tread *, npts\n\tprint *, npts\n\tprint *, 'Enter velocity model, with one line (Z, Vp, Vs) for each model depth point'\n\tprint *, 'Note that the program uses linear interpolations between model lines,'\n\tprint *, 'so models with constant velocity layers should include a depth point at' \n\tprint *, 'both the layer top and bottom.'\n\tdo i = 1, npts\n\t read *, z_inp(i), alpha_inp(i), beta_inp(i)\n\t if (beta_inp(i) == 0) beta_inp(i) = alpha_inp(i)/sfact\n\t write(*,'(f10.3,2f8.4)'), z_inp(i), alpha_inp(i), beta_inp(i)\n\tenddo\n\t\n\n\n!------- Interpolate Velocity Model and Perform Flat-Earth Transformation ------------------!\n\n\t!----- interpolate input model, while preserving layer interfaces: \n\t! z_inp,alpha_inp,beta_inp --> z_s,alpha_s,beta_s \n\tprint *, 'Interpolating velocity model to source depths...'\n\tkk=0\n\tdz = dep3 ! set spacing equal to the travel time table depth spacing\n\tnz = floor(z_inp(npts)/dz)+1 ! number of interpolation pts\n\tdo iz=1,nz\n\t zz = (iz-1)*dz ! interpolation point\n \n\t do i=1,npts-1 ! loop over velocity model layers\n \n\t\tz1=z_inp(i) ! top layer\n\t\tz2=z_inp(i+1) ! bottom layer\n\t\n\t\tif (z1<=zz.and.z2>zz) then ! match with interpolation pt \n\t\n\t\t ! get interpolation factor\n\t\t if (z2==z1) then ! check for layer interface (prevent divide by zero)\n\t\t\t\tfact = 0. \n\t\t else ! not an interface: interpolate\n\t\t\t\tfact=(zz-z1)/(z2-z1)\n\t\t endif\n\t\t \n\t\t ! compute v at interpolation point\n\t\t alpha0=alpha_inp(i)+fact*(alpha_inp(i+1)-alpha_inp(i))\n\t\t beta0=beta_inp(i)+fact*(beta_inp(i+1)-beta_inp(i))\n\t \n\t\t\t! append to interpolated velocity model (skip duplicate lines)\n\t\t if ((kk==0).or.(z_s(kk)/=zz).or.(alpha_s(kk)/=alpha0).or.(beta_s(kk)/=beta0)) then\n\t\t\t\tkk=kk+1\n\t\t\t\tz_s(kk)=zz\n\t\t\t\talpha_s(kk)=alpha0\n\t\t\t\tbeta_s(kk)=beta0\n\t\t endif\n\t\t \n\t\t\t!check for layer points we might miss\n\t\t\t do k = i+1, npts\n\t\t\t\tif (z_inp(k)-zz > dz) exit\n\t\t\t\tkk=kk+1\n\t\t\t\tz_s(kk)=z_inp(k)\n\t\t\t\talpha_s(kk)=alpha_inp(k)\n\t\t\t\tbeta_s(kk)=beta_inp(k) \n\t\t\tenddo\n\t \n\t\t exit ! exit inner loop over velo model points\n\t\tend if \n\t enddo ! end loop on velocity model layers\n \n\tenddo ! end loop on interpolation pts\n\n\t! print out interpolated model\n\tnz_s = kk\n\tdo i = 1,nz_s\n\twrite(*,'(f10.3,2f8.4)'), z_s(i), alpha_s(i), beta_s(i)\n\tenddo\n\n\n\t! ----- transform to flat earth -------!\n\tdo i=1,nz_s\n\t if (ideprad.eq.2) z_s(i)=erad-z_s(i) ! note erad is earth radius\n\t if (z_s(i).eq.erad) then !value at center of earth is removed to avoid singularity in transformation\n\t\tnz_s = i-1\n\t\texit\n\t endif\n\t call FLATTEN(z_s(i),alpha_s(i),z(i),alpha(i)) ! flat-earth transform for Vp\n\t call FLATTEN(z_s(i),beta_s(i),z(i),beta(i)) ! flat-earth transform for Vs\n\tenddo \n\n\t!-------- set up dummy interface at bottom\n\ti = nz_s+1\n\tz_s(i)=z_s(i-1) \n\talpha_s(i)=alpha_s(i-1)\n\tbeta_s(i)=beta_s(i-1)\n\tcall FLATTEN(z_s(i),alpha_s(i),z(i),alpha(i))\n\tcall FLATTEN(z_s(i),beta_s(i),z(i),beta(i))\n\tnpts=i\n\tprint *,'Depth points in model= ',npts\n\n\t! ----- compute slowness\n\tdo i=1,npts\n\t slow(i,1)=1./alpha(i)\n\t if (beta(i).ne.0.) then\n\t\tslow(i,2)=1./beta(i)\n\t else\n\t\tslow(i,2)=1./alpha(i) !fluid legs are always P!\n\t end if \n\tenddo\n\n\t! --------- print out velocity table\n\tprint *,'************************* Table of Model Interfaces *****', &\n\t'*****************'\n\tprint *,' Depth Top Velocities Bot Velocities -----Flat Earth ', &\n\t' Slownesses-----'\n\tprint *,' vp1 vs1 vp2 vs2 p1 p2 ', &\n\t ' s1 s2'\n\tdo i=2,npts\n\t if (i.eq.2.or.z(i).eq.z(i-1)) then\n\t\tscr1=1./alpha(i-1)\n\t\tscr2=1./alpha(i)\n\t\tscr3=999.\n\t\tif (beta(i-1).ne.0.) scr3=1./beta(i-1)\n\t\tscr4=999.\n\t\tif (beta(i).ne.0.) scr4=1./beta(i)\n\t\tprint 42,z_s(i),i-1,alpha_s(i-1),beta_s(i-1), &\n\t\t i,alpha_s(i),beta_s(i), scr1,scr2,scr3,scr4\n\t42 format (f6.1,2(i5,f6.2,f5.2),2x,2f8.5,2x,2f8.5)\n\t end if\n\tenddo\n\n\t! setup range of source depths\n\t dep2=dep2+dep3/20.\n\t idep=0\n\t ndep = floor((dep2-dep1)/dep3)+1\n\t do idep = 1,ndep\n\t\tdep = dep1 + (idep-1)*dep3\n\t\tdeptab(idep)=dep\n\t enddo \n\n!----------------------------------------------------------------------------------------- \n \n\n! --------------------------------- ray tracing ------------------------------------------\n! shoot rays with different ray parameters (nump total) from the surface,\n! and keep track of the offset distance (x) and travel time (t) to different depths\n\n ! get number of rays to compute \n pmin=0.\n pmax=slow(1,iw)\n print *,'pmin, pmax = ', pmin, pmax\n print *,'Number of rays to compute:'\n print *, nump \n pstep=(pmax-pmin)/float(nump)\n\n np=0\n200 do np = 1, nump ! ------- loop over ray parameters (p) ---------------\n \n ! current ray parameter\n p = pmin + (np-1)*pstep\n ptab(np)=p\n\n x=0. ! rays start at x,t = 0,0\n t=0.\n xcore=0.\n tcore=0.\n \n imth=3 !preferred v(z) interpolation method, optimal for flat-earth transform\n \n ! initialize arrays: depxcor, deptcor, depucor (size nump by ndep), which track\n ! the offset (x) and travel time (t) for different rays to different depths \n do idep=1,ndep\n if (deptab(idep).eq.0.) then\n depxcor(np,idep)=0.\n deptcor(np,idep)=0.\n depucor(np,idep)=slow(1,iw)\n else\n depxcor(np,idep)=-999.\n deptcor(np,idep)=-999.\n depucor(np,idep)=-999.\n end if\n enddo\n\n do i=1,npts-1 ! ------ loop over layers (i) ----------------------------\n \n !check to see if z exceeds zmax\n if (z_s(i).ge.zmax) then \n deltab(np)=-999.\n tttab(np)=-999.\n go to 200\n end if\n\n ! layer thickness\n h=z(i+1)-z(i)\t\t\t\t\t\t\t \n if (h.eq.0.) cycle !skip if interface\n \n ! LAYERTRACE calculates the travel time and range offset for ray tracing through a single layer.\n\t\t\t! Input: p = horizontal slowness\n\t\t\t! h = layer thickness\n\t\t\t! utop = slowness at top of layer\n\t\t\t! ubot = slowness at bottom of layer\n\t\t\t! imth = interpolation method\n\t\t\t! imth = 1, v(z) = 1/sqrt(a - 2*b*z) fastest to compute\n\t\t\t! = 2, v(z) = a - b*z linear gradient\n\t\t\t! = 3, v(z) = a*exp(-b*z) referred when Earth Flattening is applied\n\t\t\t! Returns: dx = range offset\n\t\t\t! dt = travel time\n\t\t\t! irtr = return code (-1: zero thickness layer, 0: ray turned above layer, \n\t\t\t! = 1: ray passed through layer, 2: ray turned within layer, 1 segment counted)\n call LAYERTRACE(p,h,slow(i,iw),slow(i+1,iw),imth,dx,dt,irtr) ! compute dx, dt for layer\n \n ! update x,t after tracing through layer\n x=x+dx\n t=t+dt\n \n ! exit when ray has turned\n if (irtr.eq.0.or.irtr.eq.2) exit \n \n \t! save current x,t,u for ray sampling source depths (stored in deptab)\n do idep=1,ndep\n if (abs(z_s(i+1)-deptab(idep)).lt.0.1) then\n depxcor(np,idep)=x\n deptcor(np,idep)=t\n depucor(np,idep)=slow(i+1,iw) \n end if\n enddo\n\n! \n enddo !------------ end loop on layers----------------------------------\n \n ! compute final (surface-to-surface) two-way offset and travel times for ray\n x=2.*x\n t=2.*t\n deltab(np)=x !stored in km\n tttab(np)=t !stored in seconds\n\n enddo !---------------- end loop on ray parameter p --------------------\n print *,'Completed ray tracing loop'\n\n!----------------------------------------------\n \n! special section to get (0,0) point\n np=np+1\n ptab(np)=slow(1,iw)\n deltab(np)=0.\n tttab(np)=0.\n do idep=1,ndep\n if (deptab(idep).eq.0.) then\n depxcor(np,idep)=0.\n deptcor(np,idep)=0.\n depucor(np,idep)=slow(1,iw)\n else\n depxcor(np,idep)=-999.\n deptcor(np,idep)=-999.\n depucor(np,idep)=-999.\n end if \n enddo\n\n!-------------------------------------------------------------------------\n\n\n!----- Now compute T(X,Z) for first arriving rays\n \n do idep=1,ndep ! loop over source depth's (Z)\n \n \n icount=0 ! save array index\n xold=-999. ! current x\n \n ! if source is at 0 depth, go skip the upgoing ray loop\n if (deptab(idep).eq.0.) then\n i2=np\n go to 223\n end if\n \n ! loop for upgoing rays from the source\n do i=1,np \n x2=depxcor(i,idep) ! offset at this source depth\n if (x2.eq.-999.) exit \n if (x2.le.xold) exit !stop when ray heads inward\n t2=deptcor(i,idep)\n icount=icount+1 ! increment save index\n xsave(icount)=x2 ! save offset from this depth to surface\n tsave(icount)=t2 ! save travel time\n psave(icount)=-ptab(i) ! save p as negative for upgoing from source\n usave(icount)=depucor(i,idep) ! save slowness\n xold=x2\n enddo\n i2=i-1\n \n ! loop for downgoing rays from the source\n223 continue \n do i=i2,1,-1 \n if (depxcor(i,idep).eq.-999.) cycle ! skip\n if (deltab(i).eq.-999.) cycle ! skip\n x2=deltab(i)-depxcor(i,idep) ! source-surface offset is total offset minus offset from downgoing leg \n t2=tttab(i)-deptcor(i,idep) ! same for source surface travel time\n icount=icount+1 ! increment save index\n xsave(icount)=x2 ! save offset from this depth to surface\n tsave(icount)=t2 ! save p as negative for upgoing from source\n psave(icount)=ptab(i) ! save p as negative for upgoing from source\n usave(icount)=depucor(i,idep) ! save slowness\n xold=x2\n enddo \n ncount=icount\n \n \n ! interpolate offsets to the desired spacing and find the first-arriving ray\n ndel = floor((del2-del1)/del3) + 1 ! number of interpolation pts\n \n do idel = 1, ndel !---------- loop over offsets\n \n deldel = del1 + (idel-1)*del3 ! current offset in km\n \n ! convert from km to degree, if desired\n del=deldel\n if (itype.eq.2) del=deldel*kmdeg\n delttab(idel)=deldel\n \n ! search for first arriving ray at this offset\n tt(idel,idep)=99999.\n do i=2,ncount\n x1=xsave(i-1)\n x2=xsave(i)\n if (x1.gt.del.or.x2.lt.del) cycle\n if (psave(i).gt.0..and.psave(i).lt.plongcut) cycle\n frac=(del-x1)/(x2-x1)\n tbest=tsave(i-1)+frac*(tsave(i)-tsave(i-1))\n if (psave(i-1).le.0..and.psave(i).le.0. .or. &\n psave(i-1).ge.0..and.psave(i).ge.0.) then\n pbest=psave(i-1)+frac*(psave(i)-psave(i-1))\n ubest=usave(i-1)+frac*(usave(i)-usave(i-1)) \n else\n if (frac.lt.0.5) then\n pbest=psave(i-1)\n ubest=usave(i-1)\n else\n pbest=psave(i)\n ubest=usave(i)\n end if\n end if\n \n if (tbest.lt.tt(idel,idep)) then\n tt(idel,idep)=tbest\n scr1=pbest/ubest\n if (scr1.gt.1.) then\n scr1=1.\n end if\n angle=asin(scr1)*degrad\n if (angle.lt.0.) then\n angle=-angle\n else\n angle=180.-angle\n end if\n angang(idel,idep)=angle\n rayray(idel,idep)=pbest\n etaeta(idel,idep)=ubest*sqrt(1.-scr1**2) \n if (angang(idel,idep).lt.90.) then\n etaeta(idel,idep)=-etaeta(idel,idep)\n endif\n end if\n enddo\n \n ! no ray arrivals\n if (tt(idel,idep).eq.99999.) tt(idel,idep)=0. \n if (itype.eq.2) tt(idel,idep)=tt(idel,idep)/60. \n\n enddo !end loop on offsets\n \n enddo !end loop on depth\n\n ! fix edge cases\n if (delttab(1).eq.0.) then\n if (deptab(1).eq.0.) tt(1,1)=0. !set tt to zero at (0,0)\n do idep=1,ndep\n angang(1,idep)=0. !straight up at zero range\n etaeta(1,idep)=-abs(etaeta(1,idep))\n enddo\n\n end if\n\n!-------------- Make output files -----------------\n\n! get file name from input\n print *,'Output file name for travel-time table:'\n print *, ttfile\n open (11,file=ttfile) \n \n! write headers for all files\n \n! first line: model name, iw (1/2 for P/S), pmin, pmax, np \n write (11,407) vmodel(1:20),iw,pmin,pmax,np \n407 format ('From deptable, file= ',a20,' iw =',i2,' pmin=',f8.5, &\n ' pmax=',f8.5,' np=',i6)\n \n! second line: table size ndel,ndep:\n! ndel rows (different X/DEL offsets)\n! ndep columns (different source depths)\n write (11,408) ndel,ndep\n408 format (2i5)\n \n! third line: row of source depths\n write (11,409) (deptab(j),j=1,ndep)\n409 format (8x,100f8.1)\n \n! fill in table:\n! first column is X/DEL of each row\n! then TT_ij = TT(x_i, z_j), where: TT_ij is the travel time of first arriving ray \n! from a source at horizontal distance x_i and depth z_j\n do i=1,ndel\n if (itype.eq.1) then\n write (11,410) delttab(i),(tt(i,j),j=1,ndep)\n else\n write (11,413) delttab(i),(tt(i,j),j=1,ndep)\n end if\n\n410 format (101f8.4)\n413 format (f8.3,100f8.4)\n\n enddo\n close (11)\n\n999 return\n\n\t\nend program make_TTtable \n\n!================================ END PROGRAM ============================================\n\n\n!================================ SUBROUTINES ============================================\n\n!-----------------------------------------------------------------------\n! INTERP finds the y3 value between y1 and y2, using the\n! position of x3 relative to x1 and x2.\n subroutine INTERP(x1,x2,x3,y1,y2,y3)\n fract=(x3-x1)/(x2-x1)\n y3=y1+fract*(y2-y1)\n return\n end\n\n!-----------------------------------------------------------------------\n! FLATTEN calculates flat earth tranformation.\n subroutine FLATTEN(z_s,vel_s,z_f,vel_f)\n erad=6371.\n r=erad-z_s\n z_f=-erad*alog(r/erad)\n vel_f=vel_s*(erad/r)\n return\n end\n\n!-----------------------------------------------------------------------\n! UNFLATTEN is inverse of FLATTEN.\n subroutine UNFLATTEN(z_f,vel_f,z_s,vel_s)\n erad=6371.\n r=erad*exp(-z_f/erad)\n z_s=erad-r\n vel_s=vel_f*(r/erad)\n return\n end\n\n!\n!-----------------------------------------------------------------------\n! LAYERTRACE calculates the travel time and range offset\n! for ray tracing through a single layer.\n!\n! Input: p = horizontal slowness\n! h = layer thickness\n! utop = slowness at top of layer\n! ubot = slowness at bottom of layer\n! imth = interpolation method\n! imth = 1, v(z) = 1/sqrt(a - 2*b*z) fastest to compute\n! = 2, v(z) = a - b*z linear gradient\n! = 3, v(z) = a*exp(-b*z) preferred when Earth Flattening is applied\n!\n! Returns: dx = range offset\n! dt = travel time\n! irtr = return code\n! = -1, zero thickness layer\n! = 0, ray turned above layer\n! = 1, ray passed through layer\n! = 2, ray turned within layer, 1 segment counted\n!\n! Note: This version does calculation in double precision,\n! but all i/o is still single precision\n!\n subroutine LAYERTRACE(p1,h1,utop1,ubot1,imth,dx1,dt1,irtr)\n implicit real*8 (a-h,o-z)\n real*4 p1,h1,utop1,ubot1,dx1,dt1\n \n ! double precision\n p=dble(p1)\n h=dble(h1)\n utop=dble(utop1)\n ubot=dble(ubot1)\n\n !check for zero thickness layer\n if (h.eq.0.) then \n dx1=0.\n dt1=0.\n irtr=-1\n return \n end if\n\n ! slowness of top layer\n u=utop\n \n !check for complex vertical slowness: ray turned above layer\n y=u-p\n if (y.le.0.) then \n dx1=0.\n dt1=0.\n irtr=0\n return\n end if\n\n\n\t ! qs = vertical slowness: sqrt(u^2-p^2)\n q=y*(u+p)\n qs=dsqrt(q)\n\n ! special function needed for integral at top of layer\n if (imth.eq.2) then\n y=u+qs\n if (p.ne.0.) y=y/p\n qr=dlog(y)\n else if (imth.eq.3) then ! flat-earth\n qr=atan2(qs,p)\n end if \n\n\n ! b factor (ray tracing integral constant)\n if (imth.eq.1) then\n b=-(utop**2-ubot**2)/(2.*h)\n else if (imth.eq.2) then\n vtop=1./utop\n vbot=1./ubot\n b=-(vtop-vbot)/h\n else \n b=-dlog(ubot/utop)/h ! flat earth\n end if \n!\n\t !constant velocity layer\n if (b.eq.0.) then \n b=1./h\n etau=qs\n ex=p/qs\n irtr=1\n go to 160\n end if\n\n\t! ray tracing integral at upper limit, 1/b factor omitted until end\n if (imth.eq.1) then\n etau=-q*qs/3.\n ex=-qs*p\n else if (imth.eq.2) then\n ex=qs/u !*** - in some versions (wrongly)\n etau=qr-ex\n if (p.ne.0.) ex=ex/p\n else\n etau=qs-p*qr ! flat-earth\n ex=qr\n end if\n\n\t ! check lower limit to see if we have turning point\n u=ubot\n if (u.le.p) then !if turning point,\n irtr=2 ! then no contribution\n go to 160 !from bottom point\n end if\n \n ! no turning point: ray passes through \n irtr=1\n q=(u-p)*(u+p)\n qs=dsqrt(q)\n!\n if (imth.eq.1) then\n etau=etau+q*qs/3.\n ex=ex+qs*p\n else if (imth.eq.2) then\n y=u+qs\n z=qs/u\n etau=etau+z\n if (p.ne.0.) then\n y=y/p\n z=z/p\n end if\n qr=dlog(y)\n etau=etau-qr\n ex=ex-z\n else\n qr=atan2(qs,p)\n etau=etau-qs+p*qr\n ex=ex-qr\n end if \n\n\n ! ray tracing equations to get dt, dx\n160 dx=ex/b ! horizontal offset in km\n dtau=etau/b ! delay time\n dt=dtau+p*dx ! convert delay time to travel time\n\n ! back to single precision at the end\n dx1=sngl(dx)\n dt1=sngl(dt)\n return\n end\n\n!-----------------------------------------------------------------------\n", "meta": {"hexsha": "929a0b3720667475a8da375260575b7b37414325", "size": 22939, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "TT/make_TTtable.f90", "max_stars_repo_name": "shicks-seismo/PhaseLink_work", "max_stars_repo_head_hexsha": "d1716bdc4f02582dbae45e404cfbdfbca09f3871", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "TT/make_TTtable.f90", "max_issues_repo_name": "shicks-seismo/PhaseLink_work", "max_issues_repo_head_hexsha": "d1716bdc4f02582dbae45e404cfbdfbca09f3871", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "TT/make_TTtable.f90", "max_forks_repo_name": "shicks-seismo/PhaseLink_work", "max_forks_repo_head_hexsha": "d1716bdc4f02582dbae45e404cfbdfbca09f3871", "max_forks_repo_licenses": ["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.4875912409, "max_line_length": 116, "alphanum_fraction": 0.5008936745, "num_tokens": 6742, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088025362858, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6927220142862003}} {"text": "!Calculate the Writhe of a curve using the method of Klenin (2000)\n\nsubroutine WRITHE(R, N, Wr)\n use params, only: dp, pi\n use vector_utils, only: cross\n use precision, only: eps\n\n implicit none\n\n integer, intent(in) :: N ! Number of beads\n real(dp), intent(in) :: R(3, N) ! PositionS\n !Geometric variables\n real(dp) r1(3) ! Position bead 1\n real(dp) r2(3) ! Position bead 2\n real(dp) r12(3) ! Relative position vector\n real(dp) s1 ! Length of segment 1\n real(dp) s2 ! Length of segment 2\n real(dp) beta ! Angle between tangents\n real(dp) e1(3) ! Tangent of first segment\n real(dp) e2(3) ! Tangent of second segment\n real(dp) cosB\n real(dp) sin2B\n real(dp) unit_cross(3)\n real(dp) OMEGA(N, N) ! Matrix of solid angles\n real(dp) a0\n real(dp) a1\n real(dp) a2\n real(dp) a3\n real(dp) b\n !Variables for writhe integral\n real(dp) t1\n real(dp) t2\n real(dp) F1\n real(dp) F2\n real(dp) F3\n real(dp) F4\n\n !Counter variables\n integer I, IP1\n integer J, JP1\n\n real(dp) dWr\n real(dp), intent(out) :: Wr ! Writhe\n\n OMEGA = 0\n Wr = 0.\n\n do I = 2, N\n if (I == N) then\n IP1 = 1\n else\n IP1 = I + 1\n ENDif\n do J = 1, I - 1\n\n if (J == N) then\n JP1 = 1\n else\n JP1 = J + 1\n ENDif\n\n r1 = R(:, I)\n r2 = R(:, J)\n r12 = r2 - r1\n\n s2 = SQRT(SUM((R(:, JP1) - R(:, J))**2))\n s1 = SQRT(SUM((R(:, IP1) - R(:, I))**2))\n e2 = (R(:, JP1) - R(:, J))/s2\n e1 = (R(:, IP1) - R(:, I))/s1\n cosB = doT_PRODUCT(e1, e2)\n B = ACOS(cosB)\n\n ! sin2B = 1.-(cosB**2.)\n sin2B = sin(B)**2.\n unit_cross = cross(e1, e2)\n\n if (abs(sin2B) .lt. (eps)) then\n sin2b = 0.\n endif\n\n a1 = doT_PRODUCT(r12, e2*cosB - e1)/(sin2B)\n a2 = doT_PRODUCT(r12, e2 - e1*cosB)/sin2B\n a0 = doT_PRODUCT(r12, unit_cross)/sin2B\n\n t1 = a1 + s1\n t2 = a2 + s2\n F1 = -ATAN((t1*t2 + (a0**2.)*cosB)/(a0*SQRT((t1**2.+t2**2.-2.*t1*t2*cosB + (a0**2.)*sin2B))))/(4.*PI)\n t1 = a1 + s1\n t2 = a2\n F2 = -ATAN((t1*t2 + (a0**2.)*cosB)/(a0*SQRT((t1**2.+t2**2.-2.*t1*t2*cosB + (a0**2.)*sin2B))))/(4.*PI)\n t1 = a1\n t2 = a2 + s2\n F3 = -ATAN((t1*t2 + (a0**2.)*cosB)/(a0*SQRT((t1**2.+t2**2.-2.*t1*t2*cosB + (a0**2.)*sin2B))))/(4.*PI)\n t1 = a1\n t2 = a2\n F4 = -ATAN((t1*t2 + (a0**2.)*cosB)/(a0*SQRT((t1**2.+t2**2.-2.*t1*t2*cosB + (a0**2.)*sin2B))))/(4.*PI)\n dWr = F1 - F2 - F3 + F4\n\n if (dWr /= dWr) then\n dWr = 0.\n endif\n if (JP1 == I .OR. IP1 == J) then\n dWr = 0.\n endif\n\n if (abs(a0) < 10.**(-10.)) then\n dWr = 0.\n endif\n\n Wr = Wr + dWr\n\n ENDdo\n ENDdo\n\n Wr = 2.*Wr\n\n RETURN\nEND subroutine WRITHE\n\n", "meta": {"hexsha": "f7141682606630d2d1f9ab144f3aeba458f236ee", "size": 3084, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "src/util/writhe.f03", "max_stars_repo_name": "SpakowitzLab/BasicWLC", "max_stars_repo_head_hexsha": "13edbbc8e8cd36a3586571ff4d80880fc89d30e6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-16T01:39:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-16T01:39:18.000Z", "max_issues_repo_path": "src/util/writhe.f03", "max_issues_repo_name": "riscalab/wlcsim", "max_issues_repo_head_hexsha": "e34877ef6c5dc83c6444380dbe624b371d70faf2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 17, "max_issues_repo_issues_event_min_datetime": "2016-07-08T21:17:40.000Z", "max_issues_repo_issues_event_max_datetime": "2017-01-24T09:05:25.000Z", "max_forks_repo_path": "src/util/writhe.f03", "max_forks_repo_name": "riscalab/wlcsim", "max_forks_repo_head_hexsha": "e34877ef6c5dc83c6444380dbe624b371d70faf2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2017-02-19T06:28:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-05T22:28:08.000Z", "avg_line_length": 25.7, "max_line_length": 110, "alphanum_fraction": 0.445849546, "num_tokens": 1188, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087965937711, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6927220098522583}} {"text": " subroutine point_to_plane_lg (xq,yq,zq,xplane,yplane,zplane,\n * xproj,yproj,zproj,dist,ierror)\nc#######################################################################\nc\nc purpose -\nc\nC This routine computes the projection of the query point\nc to a plane and determines if the projection is inside\nc the triangle of nodes defining the plane\nc\nc input:\nc\nc xq,yq,zq coordinates of query point\nc xplane,yplane,zplane coordinates of nodes defining the plane\nc\nc output:\nc\nc xproj,yproj,zproj coordinates of projected point\nc dist distance from query point to projected point\nc ierror = 0 normal completion\nc = 1 plane ill defined (probably nodes are collinear)\nc = 2 projected node outside triangle\nC\nC $Log: point_to_plane_lg.f,v $\nC Revision 2.00 2007/11/09 20:03:58 spchu\nC Import to CVS\nC\nCPVCS \r\nCPVCS Rev 1.1 01 Feb 2002 10:40:02 dcg\r\nCPVCS add subroutine project_point_to_line\r\nCPVCS \r\nCPVCS Rev 1.0 28 Jan 2002 13:14:54 dcg\r\nCPVCS Initial revision.\r\nc#######################################################################\nc\n implicit none\n real*8 xq,yq,zq,xplane(*),yplane(*),zplane(*),\n * xproj,yproj,zproj,a,b,c,d,au,bu,cu,sf,ss,\n * sarea,dist,sarea0\n integer ierror\n include 'consts.h'\n include 'statementfunctions.h'\nC\nC SET UP THE EQUATION OF THE PLANE FROM THE 3 POINTS.\nC\n ierror=0\n a=dcrosx(xplane(1),yplane(1),zplane(1),\n * xplane(2),yplane(2),zplane(2),\n * xplane(3),yplane(3),zplane(3))\n b=dcrosy(xplane(1),yplane(1),zplane(1),\n * xplane(2),yplane(2),zplane(2),\n * xplane(3),yplane(3),zplane(3))\n c=dcrosz(xplane(1),yplane(1),zplane(1),\n * xplane(2),yplane(2),zplane(2),\n * xplane(3),yplane(3),zplane(3))\n d=a*xplane(1)+b*yplane(1)+c*zplane(1)\n ss=sqrt(a*a + b*b + c*c)\n if (ss.le.zero) then\n ierror=1\n xproj=0.\n yproj=0.\n zproj=0.\n else\nc get unit normal to plane\nC and the distance to the plane (sf)\n au=a/ss\n bu=b/ss\n cu=c/ss\n sf=(a*xq + b*yq + c*zq - d)/ss\nc get projection of query point onto plane\n xproj=xq-au*sf\n yproj=yq-bu*sf\n zproj=zq-cu*sf\n dist=dlen(xq,yq,zq,xproj,yproj,zproj)\n sarea0=dszarea(xplane(1),yplane(1),zplane(1),\n * xplane(2),yplane(2),zplane(2),\n * xplane(3),yplane(3),zplane(3))\n sarea0=dsign(one,sarea0)\nc test inside\n sarea=dszarea(xplane(2),yplane(2),zplane(2),\n * xplane(3),yplane(3),zplane(3),\n * xproj,yproj,zproj)\n if(sarea0.ne.dsign(one,sarea)) then\n ierror=2\n go to 9999\n endif\n sarea=dszarea(xplane(1),yplane(1),zplane(1),\n * xplane(2),yplane(2),zplane(2),\n * xproj,yproj,zproj)\n if(sarea0.ne.dsign(one,sarea)) then\n ierror=2\n go to 9999\n endif\n sarea=dszarea(xplane(1),yplane(1),zplane(1),\n * xproj,yproj,zproj,\n * xplane(3),yplane(3),zplane(3))\n if(sarea0.ne.dsign(one,sarea)) then\n ierror=2\n go to 9999\n endif\n endif\n 9999 continue\n return\n end\nC\nC\nC\n subroutine project_point_to_line(x1,y1,z1,x2,y2,z2,\n * x3,y3,z3,xproj,yproj,zproj)\n implicit none\n include 'consts.h'\nc\nc project x3,y3,z3 onto line defined by\nc x1,y1,z1,x2,y2,z2\nc return coordinates in xproj,yproj,zproj\nc\n real*8 x1,y1,z1,x2,y2,z2,x3,y3,z3,xproj,yproj,zproj,frac\nc\n frac=((x2-x1)*(x3-x1)+\n & (y2-y1)*(y3-y1)+\n & (z2-z1)*(z3-z1))/\n & ((x2-x1)*(x2-x1)+\n & (y2-y1)*(y2-y1)+\n & (z2-z1)*(z2-z1))\n xproj=frac*x2+(one-frac)*x1\n yproj=frac*y2+(one-frac)*y1\n zproj=frac*z2+(one-frac)*z1\n return\n end\n", "meta": {"hexsha": "8b8a4414d42239990b0528ea59be924836fa8f20", "size": 3834, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/point_to_plane_lg.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/point_to_plane_lg.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/point_to_plane_lg.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.4923076923, "max_line_length": 72, "alphanum_fraction": 0.5641627543, "num_tokens": 1366, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087946129328, "lm_q2_score": 0.7461389930307512, "lm_q1q2_score": 0.6927220031333872}} {"text": " subroutine kkmclf(npts, e, finp, fout)\nc forward (f'->f'') kk transform, using mclaurin series algorithm\nc arguments: \nc npts size of arrays to consider \nc e energy array *must be on an even grid* [npts] (in)\nc finp f' array [npts] (in)\nc fout f'' array [npts] (out)\nc notes fopi = 4/pi\n implicit none\n double precision e(*), finp(*), fout(*)\n double precision factor, ei2, de2, fopi, zero, tiny\n parameter(fopi = 1.273239544735163d0, zero = 0.d0, tiny=1.d-20)\n integer npts, i, j, k, ioff, nptsk\n \n if (npts.ge.2) then \n factor = fopi * (e(npts) - e(1)) / (npts - 1)\n nptsk = npts / 2\n do 100 i=1, npts\n fout(i) = zero\n ei2 = e(i) * e(i)\n ioff = mod(i,2) - 1\n do 50 k = 1, nptsk\n j = k + k + ioff\n de2 = e(j)*e(j) - ei2\n if (abs(de2).le.tiny) de2 = tiny\n fout(i) = fout(i) + finp(j) / de2\n 50 continue \n fout(i) = factor * fout(i) * e(i)\n 100 continue \n end if\n return\nc end subroutine kkmclf\n end\n", "meta": {"hexsha": "bd393ffec9b3032f7820997d305ece7fe308baa8", "size": 1233, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/diffkk/kkmclf.f", "max_stars_repo_name": "keechul/ifeffit", "max_stars_repo_head_hexsha": "306444e500cb3ecb1795fcbde9219369b003f1fa", "max_stars_repo_licenses": ["Naumen", "Condor-1.1", "MS-PL"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2017-09-16T12:41:43.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-08T05:17:16.000Z", "max_issues_repo_path": "src/diffkk/kkmclf.f", "max_issues_repo_name": "bruceravel/ifeffit", "max_issues_repo_head_hexsha": "97f6458584e237a6a9e3681bb9b604c9d1ec9743", "max_issues_repo_licenses": ["Naumen", "Condor-1.1", "MS-PL"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-07-20T01:15:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-20T02:09:08.000Z", "max_forks_repo_path": "src/diffkk/kkmclf.f", "max_forks_repo_name": "bruceravel/ifeffit", "max_forks_repo_head_hexsha": "97f6458584e237a6a9e3681bb9b604c9d1ec9743", "max_forks_repo_licenses": ["Naumen", "Condor-1.1", "MS-PL"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-03-22T19:27:11.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-23T07:47:31.000Z", "avg_line_length": 36.2647058824, "max_line_length": 70, "alphanum_fraction": 0.4590429846, "num_tokens": 412, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088005554476, "lm_q2_score": 0.7461389873857264, "lm_q1q2_score": 0.6927220023264384}} {"text": "! Algorithm AS66 Applied Statistics (1973) vol.22, no.3\r\n\r\n! Evaluates the tail area of the standardised normal curve\r\n! from x to infinity if upper is .true. or\r\n! from minus infinity to x if upper is .false.\r\n\r\n! ELF90-compatible version by Alan Miller\r\n! Latest revision - 29 November 2001\r\n\r\nFUNCTION alnorm( x, upper ) RESULT( fn_val )\r\n IMPLICIT NONE\r\n INTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(15, 100)\r\n REAL(DP), INTENT(IN) :: x\r\n LOGICAL, INTENT(IN) :: upper\r\n REAL(DP) :: fn_val\r\n\r\n ! Local variables\r\n REAL(DP), PARAMETER :: zero=0.0_DP, one=1.0_DP, half=0.5_DP, con=1.28_DP\r\n REAL(DP) :: z, y\r\n LOGICAL :: up\r\n\r\n ! Machine dependent constants\r\n REAL(DP), PARAMETER :: ltone = 7.0_DP, utzero = 18.66_DP\r\n REAL(DP), PARAMETER :: p = 0.398942280444_DP, q = 0.39990348504_DP, &\r\n r = 0.398942280385_DP, a1 = 5.75885480458_DP, &\r\n a2 = 2.62433121679_DP, a3 = 5.92885724438_DP, &\r\n b1 = -29.8213557807_DP, b2 = 48.6959930692_DP, &\r\n c1 = -3.8052E-8_DP, c2 = 3.98064794E-4_DP, &\r\n c3 = -0.151679116635_DP, c4 = 4.8385912808_DP, &\r\n c5 = 0.742380924027_DP, c6 = 3.99019417011_DP, &\r\n d1 = 1.00000615302_DP, d2 = 1.98615381364_DP, &\r\n d3 = 5.29330324926_DP, d4 = -15.1508972451_DP, &\r\n d5 = 30.789933034_DP\r\n\r\n up = upper\r\n z = x\r\n IF( z < zero ) THEN\r\n up = .NOT. up\r\n z = -z\r\n END IF\r\n IF( z <= ltone .OR. (up .AND. z <= utzero) ) THEN\r\n y = half*z*z\r\n IF( z > con ) THEN\r\n fn_val = r*EXP( -y )/(z+c1+d1/(z+c2+d2/(z+c3+d3/(z+c4+d4/(z+c5+d5/(z+c6))))))\r\n ELSE\r\n fn_val = half - z*(p-q*y/(y+a1+b1/(y+a2+b2/(y+a3))))\r\n END IF\r\n ELSE\r\n fn_val = zero\r\n END IF\r\n\r\n IF( .NOT. up ) fn_val = one - fn_val\r\n RETURN\r\nEND FUNCTION alnorm\r\n", "meta": {"hexsha": "0adf5177258181ef9a4ba541a95e61bbcefa0428", "size": 2054, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/as66.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/as66.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/as66.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": 37.3454545455, "max_line_length": 87, "alphanum_fraction": 0.505842259, "num_tokens": 724, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122313857379, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.6927181669027969}} {"text": " Program dhseqr_example\n\n! DHSEQR Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use blas_interfaces, Only: dgemm\n Use lapack_example_aux, Only: nagf_file_print_matrix_real_gen\n Use lapack_interfaces, Only: dhseqr, dlange\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nin = 5, nout = 6\n! .. Local Scalars ..\n Real (Kind=dp) :: alpha, beta, norm\n Integer :: i, ifail, info, ldc, ldd, ldh, ldz, lwork, n\n! .. Local Arrays ..\n Real (Kind=dp), Allocatable :: c(:, :), d(:, :), h(:, :), wi(:), &\n work(:), wr(:), z(:, :)\n! .. Intrinsic Procedures ..\n Intrinsic :: epsilon\n! .. Executable Statements ..\n Write (nout, *) 'DHSEQR Example Program Results'\n Flush (nout)\n\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n\n ldc = n\n ldd = n\n ldh = n\n ldz = n\n lwork = n\n Allocate (c(ldc,n), d(ldd,n), h(ldh,n), wi(n), work(lwork), wr(n), &\n z(ldz,n))\n\n! Read H from data file\n Read (nin, *)(h(i,1:n), i=1, n)\n\n! Copy H into D\n d(1:n, 1:n) = h(1:n, 1:n)\n\n! Print Matrix H\n! ifail: behaviour on error exit\n! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft\n ifail = 0\n Call nagf_file_print_matrix_real_gen('General', ' ', n, n, h, ldh, &\n 'Matrix H', ifail)\n\n! Calculate the eigenvalues and Schur factorization of H\n\n Call dhseqr('Schur form', 'Initialize Z', n, 1, n, h, ldh, wr, wi, z, &\n ldz, work, lwork, info)\n\n Write (nout, *)\n If (info>0) Then\n Write (nout, *) 'Failure to converge.'\n Else\n\n! Compute H - Z*T*Z^T from the factorization of A and store in matrix D\n alpha = 1.0_dp\n beta = 0.0_dp\n Call dgemm('N', 'N', n, n, n, alpha, z, ldz, h, ldh, beta, c, ldc)\n alpha = -1.0_dp\n beta = 1.0_dp\n Call dgemm('N', 'T', n, n, n, alpha, c, ldc, z, ldz, beta, d, ldd)\n\n! Find norm of matrix D and print warning if it is too large\n norm = dlange('O', ldd, n, d, ldd, work)\n If (norm>epsilon(1.0E0_dp)**0.8_dp) Then\n Write (nout, *) 'Norm of H-(Z*T*Z^T) is much greater than 0.'\n Write (nout, *) 'Schur factorization has failed.'\n Else\n! Print eigenvalues\n Write (nout, *) 'Eigenvalues'\n Write (nout, 100)(' (', wr(i), ',', wi(i), ')', i=1, n)\n End If\n End If\n\n100 Format (1X, A, F8.4, A, F8.4, A)\n End Program\n", "meta": {"hexsha": "7317c65e86b91dd7454c0bbcd462cff82a27deb0", "size": 2747, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/dhseqr_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/dhseqr_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/dhseqr_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 31.9418604651, "max_line_length": 90, "alphanum_fraction": 0.5438660357, "num_tokens": 901, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312226373181, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.6927181630757909}} {"text": "module vector_synthesis_routines\n\n use spherepack_precision, only: &\n wp, & ! working precision\n ip, & ! integer precision\n PI, &\n odd\n\n use type_SpherepackUtility, only: &\n SpherepackUtility, &\n get_lvhsec, get_lvhsgc, get_lvhses, get_lvhsgs\n\n use gaussian_latitudes_and_weights_routines, only: &\n compute_gaussian_latitudes_and_weights\n\n ! Explicit typing only\n implicit none\n\n ! Everything is private unless stated otherwise\n private\n public :: vhsgc, vhsgci, initialize_vhsec\n public :: vhses, vhsesi, initialize_vhses\n public :: vhsec, vhseci, initialize_vhsgc\n public :: vhsgs, vhsgsi, initialize_vhsgs\n public :: VectorBackwardTransform\n public :: VectorSynthesisUtility\n \n ! Parameters confined to the module\n real(wp), parameter :: ZERO = 0.0_wp\n real(wp), parameter :: HALF = 0.5_wp\n real(wp), parameter :: ONE = 1.0_wp\n real(wp), parameter :: TWO = 2.0_wp\n real(wp), parameter :: FOUR = 4.0_wp\n\n type, public :: VectorBackwardTransform\n contains\n ! Type-bound procedures\n procedure, nopass :: vhsec\n procedure, nopass :: vhseci\n procedure, nopass :: vhsgc\n procedure, nopass :: vhsgci\n procedure, nopass :: vhses\n procedure, nopass :: vhsesi\n procedure, nopass :: vhsgs\n procedure, nopass :: vhsgsi\n procedure, nopass :: initialize_vhsec\n procedure, nopass :: initialize_vhses\n procedure, nopass :: initialize_vhsgc\n procedure, nopass :: initialize_vhsgs\n end type VectorBackwardTransform\n\n type, public, extends(SpherepackUtility) :: VectorSynthesisUtility\n contains\n procedure :: assemble_transform\n procedure, nopass :: synthesis_setup\n end type VectorSynthesisUtility\n\n ! Declare interfaces for submodule implementation\n interface\n module subroutine vhsec(nlat, nlon, ityp, nt, v, w, idvw, jdvw, br, bi, cr, ci, &\n mdab, ndab, wvhsec, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n integer(ip), intent(in) :: ityp\n integer(ip), intent(in) :: nt\n real(wp), intent(out) :: v(idvw, jdvw, nt)\n real(wp), intent(out) :: w(idvw, jdvw, nt)\n integer(ip), intent(in) :: idvw\n integer(ip), intent(in) :: jdvw\n real(wp), intent(in) :: br(mdab, ndab, nt)\n real(wp), intent(in) :: bi(mdab, ndab, nt)\n real(wp), intent(in) :: cr(mdab, ndab, nt)\n real(wp), intent(in) :: ci(mdab, ndab, nt)\n integer(ip), intent(in) :: mdab\n integer(ip), intent(in) :: ndab\n real(wp), intent(in) :: wvhsec(:)\n integer(ip), intent(out) :: ierror\n end subroutine vhsec\n\n module subroutine vhses(nlat, nlon, ityp, nt, v, w, idvw, jdvw, br, bi, cr, ci, &\n mdab, ndab, wvhses, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n integer(ip), intent(in) :: ityp\n integer(ip), intent(in) :: nt\n real(wp), intent(out) :: v(idvw, jdvw, nt)\n real(wp), intent(out) :: w(idvw, jdvw, nt)\n integer(ip), intent(in) :: idvw\n integer(ip), intent(in) :: jdvw\n real(wp), intent(in) :: br(mdab, ndab, nt)\n real(wp), intent(in) :: bi(mdab, ndab, nt)\n real(wp), intent(in) :: cr(mdab, ndab, nt)\n real(wp), intent(in) :: ci(mdab, ndab, nt)\n integer(ip), intent(in) :: mdab\n integer(ip), intent(in) :: ndab\n real(wp), intent(in) :: wvhses(:)\n integer(ip), intent(out) :: ierror\n end subroutine vhses\n\n module subroutine vhsgc(nlat, nlon, ityp, nt, v, w, idvw, jdvw, br, bi, cr, ci, &\n mdab, ndab, wvhsgc, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n integer(ip), intent(in) :: ityp\n integer(ip), intent(in) :: nt\n real(wp), intent(out) :: v(idvw, jdvw, nt)\n real(wp), intent(out) :: w(idvw, jdvw, nt)\n integer(ip), intent(in) :: idvw\n integer(ip), intent(in) :: jdvw\n real(wp), intent(in) :: br(mdab, ndab, nt)\n real(wp), intent(in) :: bi(mdab, ndab, nt)\n real(wp), intent(in) :: cr(mdab, ndab, nt)\n real(wp), intent(in) :: ci(mdab, ndab, nt)\n integer(ip), intent(in) :: mdab\n integer(ip), intent(in) :: ndab\n real(wp), intent(in) :: wvhsgc(:)\n integer(ip), intent(out) :: ierror\n end subroutine vhsgc\n\n module subroutine vhsgs(nlat, nlon, ityp, nt, v, w, idvw, jdvw, br, bi, cr, ci, &\n mdab, ndab, wvhsgs, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n integer(ip), intent(in) :: ityp\n integer(ip), intent(in) :: nt\n real(wp), intent(out) :: v(idvw, jdvw, nt)\n real(wp), intent(out) :: w(idvw, jdvw, nt)\n integer(ip), intent(in) :: idvw\n integer(ip), intent(in) :: jdvw\n real(wp), intent(in) :: br(mdab, ndab, nt)\n real(wp), intent(in) :: bi(mdab, ndab, nt)\n real(wp), intent(in) :: cr(mdab, ndab, nt)\n real(wp), intent(in) :: ci(mdab, ndab, nt)\n integer(ip), intent(in) :: mdab\n integer(ip), intent(in) :: ndab\n real(wp), intent(in) :: wvhsgs(:)\n integer(ip), intent(out) :: ierror\n end subroutine vhsgs\n\n module subroutine vhseci(nlat, nlon, wvhsec, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n real(wp), intent(out) :: wvhsec(:)\n integer(ip), intent(out) :: ierror\n end subroutine vhseci\n\n module subroutine vhsesi(nlat, nlon, wvhses, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n real(wp), intent(out) :: wvhses(:)\n integer(ip), intent(out) :: ierror\n end subroutine vhsesi\n\n module subroutine vhsgci(nlat, nlon, wvhsgc, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n real(wp), intent(out) :: wvhsgc(:)\n integer(ip), intent(out) :: ierror\n end subroutine vhsgci\n\n module subroutine vhsgsi(nlat, nlon, wvhsgs, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n real(wp), intent(out) :: wvhsgs(:)\n integer(ip), intent(out) :: ierror\n end subroutine vhsgsi\n end interface\n\ncontains\n\n pure subroutine synthesis_setup(even_stride, imid, imm1, mmax, nlat, &\n odd_stride, ve, vo, we, wo)\n\n ! Dummy arguments\n integer(ip), intent(out) :: even_stride\n integer(ip), intent(in) :: imid\n integer(ip), intent(out) :: imm1\n integer(ip), intent(out) :: mmax\n integer(ip), intent(in) :: nlat\n integer(ip), intent(out) :: odd_stride\n real(wp), intent(out) :: ve(:,:,:)\n real(wp), intent(out) :: vo(:,:,:)\n real(wp), intent(out) :: we(:,:,:)\n real(wp), intent(out) :: wo(:,:,:)\n\n ! Local variables\n integer(ip) :: nlon\n\n nlon = size(ve, dim=2)\n\n mmax = min(nlat, (nlon + 1)/2)\n\n select case (mod(nlat, 2))\n case (0)\n imm1 = imid\n odd_stride = nlat\n even_stride = nlat-1\n case default\n imm1 = imid-1\n odd_stride = nlat-1\n even_stride = nlat\n end select\n\n ! Set even spherical components equal to 0.0\n ve = ZERO\n we = ZERO\n vo = ZERO\n wo = ZERO\n\n end subroutine synthesis_setup\n\n subroutine assemble_transform(self, idvw, jdvw, idv, imid, &\n imm1, ityp, nlat, nlon, nt, v, ve, vo, w, we, wo, wrfft)\n\n class(VectorSynthesisUtility), intent(inout) :: self\n integer(ip), intent(in) :: idvw\n integer(ip), intent(in) :: jdvw\n integer(ip), intent(in) :: idv\n integer(ip), intent(in) :: imid\n integer(ip), intent(in) :: imm1\n integer(ip), intent(in) :: ityp\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n integer(ip), intent(in) :: nt\n real(wp), intent(out) :: v(idvw, jdvw, nt)\n real(wp), intent(inout) :: ve(idv, nlon, nt)\n real(wp), intent(in) :: vo(idv, nlon, nt)\n real(wp), intent(out) :: w(idvw, jdvw, nt)\n real(wp), intent(inout) :: we(idv, nlon, nt)\n real(wp), intent(in) :: wo(idv, nlon, nt)\n real(wp), intent(in) :: wrfft(..)\n\n ! Local variables\n integer(ip) :: k, i\n\n do k=1, nt\n call self%hfft%backward(idv, nlon, ve(:, :, k), idv, wrfft)\n call self%hfft%backward(idv, nlon, we(:, :, k), idv, wrfft)\n end do\n\n select case (ityp)\n case(0:2)\n do k=1, nt\n do i=1, imm1\n v(i, :, k) = HALF * (ve(i, :, k) + vo(i, :, k))\n w(i, :, k) = HALF * (we(i, :, k) + wo(i, :, k))\n v((nlat + 1)-i, :, k) = HALF * (ve(i, :, k) - vo(i, :, k))\n w((nlat + 1)-i, :, k) = HALF * (we(i, :, k) - wo(i, :, k))\n end do\n end do\n case default\n do k=1, nt\n v(1:imm1, :, k) = HALF * ve(1:imm1, :, k)\n w(1:imm1, :, k) = HALF * we(1:imm1, :, k)\n end do\n end select\n\n if (mod(nlat, 2) /= 0) then\n do k=1, nt\n v(imid, :, k) = HALF * ve(imid, :, k)\n w(imid, :, k) = HALF * we(imid, :, k)\n end do\n end if\n\n end subroutine assemble_transform\n\n subroutine initialize_vhsec(nlat, nlon, wavetable, error_flag)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n real(wp), allocatable, intent(out) :: wavetable(:)\n integer(ip), intent(out) :: error_flag\n\n ! Local variables\n type(SpherepackUtility) :: util\n\n ! Initialize wavetable\n call util%initialize_wavetable(nlat, nlon, wavetable, &\n get_lvhsec, vhseci, error_flag)\n\n end subroutine initialize_vhsec\n\n subroutine initialize_vhses(nlat, nlon, wavetable, error_flag)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n real(wp), allocatable, intent(out) :: wavetable(:)\n integer(ip), intent(out) :: error_flag\n\n ! Local variables\n type(SpherepackUtility) :: util\n\n ! Initialize wavetable\n call util%initialize_wavetable(nlat, nlon, wavetable, &\n get_lvhses, vhsesi, error_flag)\n\n end subroutine initialize_vhses\n\n subroutine initialize_vhsgc(nlat, nlon, wavetable, error_flag)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n real(wp), allocatable, intent(out) :: wavetable(:)\n integer(ip), intent(out) :: error_flag\n\n ! Local variables\n type(SpherepackUtility) :: util\n\n ! Initialize wavetable\n call util%initialize_wavetable(nlat, nlon, wavetable, &\n get_lvhsgc, vhsgci, error_flag)\n\n end subroutine initialize_vhsgc\n\n subroutine initialize_vhsgs(nlat, nlon, wavetable, error_flag)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n real(wp), allocatable, intent(out) :: wavetable(:)\n integer(ip), intent(out) :: error_flag\n\n ! Local variables\n type(SpherepackUtility) :: util\n\n ! Initialize wavetable\n call util%initialize_wavetable(nlat, nlon, wavetable, &\n get_lvhsgs, vhsgsi, error_flag)\n\n end subroutine initialize_vhsgs\n\nend module vector_synthesis_routines\n", "meta": {"hexsha": "cc4cd4668b0becb9028e2e71ff5db85a23900f31", "size": 12713, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/vector_synthesis_routines.f90", "max_stars_repo_name": "jlokimlin/spherepack4.1", "max_stars_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-06-28T14:01:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T21:59:28.000Z", "max_issues_repo_path": "src/vector_synthesis_routines.f90", "max_issues_repo_name": "jlokimlin/spherepack4.1", "max_issues_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2016-05-07T23:00:35.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-22T23:52:30.000Z", "max_forks_repo_path": "src/vector_synthesis_routines.f90", "max_forks_repo_name": "jlokimlin/spherepack4.1", "max_forks_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-06-28T14:03:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T12:53:54.000Z", "avg_line_length": 36.1164772727, "max_line_length": 89, "alphanum_fraction": 0.5197828994, "num_tokens": 3540, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312226373181, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6927181581930056}} {"text": " Subroutine gespd(a,rhs,sol,n,m)\n!\n! Solves Ax = d with A a nxn SPD and d a nxm.\n!\n implicit none\n real*8, dimension(n,n), intent(inout):: a\n real*8, dimension(n,m), intent(inout):: rhs\n real*8, dimension(n,n+m):: aa\n real*8, dimension(n,m) :: y\n real*8, dimension(n,m),intent(out)::sol\n integer ::k,i,j,l\n integer,intent(in)::n,m\n aa(1:n,1:n)= a\n aa(1:n,(n+1):n+m) = rhs\n!\n! Factor A via column version and\n! write over the matrix.\n!\n do k=1,n-1\n aa(k+1:n,k) = aa(k+1:n,k)/aa(k,k)\n do j=k+1,n\n do i=k+1,n\n aa(i,j) = aa(i,j) - aa(i,k)*aa(k,j)\n enddo\n enddo\n enddo\n!\n! Solve Ly = d via column version and\n! multiple right sides.\n!\n do j=1,n-1\n do l =1,m\n y(j,l)=aa(j,n+l)\n enddo\n do i = j+1,n\n do l=1,m\n aa(i,n+l) = aa(i,n+l) - aa(i,j)*y(j,l)\n enddo\n enddo\n enddo\n!\n! Solve Ux = y via column version and\n! multiple right sides.\n!\n do j=n,2,-1\n do l = 1,m\n sol(j,l) = aa(j,n+l)/aa(j,j)\n enddo\n do i = 1,j-1\n do l=1,m\n aa(i,n+l)=aa(i,n+l)-aa(i,j)*sol(j,l)\n enddo\n enddo\n enddo\n do l=1,m\n sol(1,l) = aa(1,n+l)/a(1,1)\n enddo\n end ", "meta": {"hexsha": "47a52a2e9ce76474489eda306eee9ef6ee1f9b65", "size": 1321, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/gespd.f", "max_stars_repo_name": "imohame/LabCode", "max_stars_repo_head_hexsha": "b7fca6e58f6c26917ff4a8862ab473da282d027d", "max_stars_repo_licenses": ["MIT"], "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/gespd.f", "max_issues_repo_name": "imohame/LabCode", "max_issues_repo_head_hexsha": "b7fca6e58f6c26917ff4a8862ab473da282d027d", "max_issues_repo_licenses": ["MIT"], "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/gespd.f", "max_forks_repo_name": "imohame/LabCode", "max_forks_repo_head_hexsha": "b7fca6e58f6c26917ff4a8862ab473da282d027d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-04-19T08:21:42.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-18T02:43:24.000Z", "avg_line_length": 22.775862069, "max_line_length": 50, "alphanum_fraction": 0.4542013626, "num_tokens": 479, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122188543453, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.692718157335282}} {"text": "*DECK LSSODS\n SUBROUTINE LSSODS (A, X, B, M, N, NRDA, IFLAG, IRANK, ISCALE, Q,\n + DIAG, KPIVOT, ITER, RESNRM, XNORM, Z, R, DIV, TD, SCALES)\nC***BEGIN PROLOGUE LSSODS\nC***SUBSIDIARY\nC***PURPOSE Subsidiary to BVSUP\nC***LIBRARY SLATEC\nC***TYPE SINGLE PRECISION (LSSODS-S)\nC***AUTHOR (UNKNOWN)\nC***DESCRIPTION\nC\nC LSSODS solves the same problem as SODS (in fact, it is called by\nC SODS) but is somewhat more flexible in its use. In particular,\nC LSSODS allows for iterative refinement of the solution, makes the\nC transformation and triangular reduction information more\nC accessible, and enables the user to avoid destruction of the\nC original matrix A.\nC\nC Modeled after the ALGOL codes in the articles in the REFERENCES\nC section.\nC\nC **********************************************************************\nC INPUT\nC **********************************************************************\nC\nC A -- Contains the matrix of M equations in N unknowns and must\nC be dimensioned NRDA by N. A remains unchanged\nC X -- Solution array of length at least N\nC B -- Given constant vector of length M, B remains unchanged\nC M -- Number of equations, M greater or equal to 1\nC N -- Number of unknowns, N not larger than M\nC NRDA -- Row dimension of A, NRDA greater or equal to M\nC IFLAG -- Status indicator\nC = 0 for the first call (and for each new problem defined by\nC a new matrix A) when the matrix data is treated as exact\nC =-K for the first call (and for each new problem defined by\nC a new matrix A) when the matrix data is assumed to be\nC accurate to about K digits\nC = 1 for subsequent calls whenever the matrix A has already\nC been decomposed (problems with new vectors B but\nC same matrix a can be handled efficiently)\nC ISCALE -- Scaling indicator\nC =-1 if the matrix A is to be pre-scaled by\nC columns when appropriate\nC If the scaling indicator is not equal to -1\nC no scaling will be attempted\nC For most problems scaling will probably not be necessary\nC ITER -- Maximum number of iterative improvement steps to be\nC performed, 0 .LE. ITER .LE. 10 (SODS uses ITER=0)\nC Q -- Matrix used for the transformation, must be dimensioned\nC NRDA by N (SODS puts A in the Q location which conserves\nC storage but destroys A)\nC When iterative improvement of the solution is requested,\nC ITER .GT. 0, this additional storage for Q must be\nC made available\nC DIAG,KPIVOT,Z,R, -- Arrays of length N (except for R which is M)\nC DIV,TD,SCALES used for internal storage\nC\nC **********************************************************************\nC OUTPUT\nC **********************************************************************\nC\nC IFLAG -- Status indicator\nC =1 if solution was obtained\nC =2 if improper input is detected\nC =3 if rank of matrix is less than N\nC if the minimal length least squares solution is\nC desired, simply reset IFLAG=1 and call the code again\nC\nC The next three IFLAG values can occur only when\nC the iterative improvement mode is being used.\nC =4 if the problem is ill-conditioned and maximal\nC machine accuracy is not achievable\nC =5 if the problem is very ill-conditioned and the solution\nC IS likely to have no correct digits\nC =6 if the allowable number of iterative improvement steps\nC has been completed without getting convergence\nC X -- Least squares solution of A X = B\nC IRANK -- Contains the numerically determined matrix rank\nC the user must not alter this value on succeeding calls\nC with input values of IFLAG=1\nC Q -- Contains the strictly upper triangular part of the reduced\nC matrix and the transformation information in the lower\nC triangular part\nC DIAG -- Contains the diagonal elements of the triangular reduced\nC matrix\nC KPIVOT -- Contains the pivotal information. The column interchanges\nC performed on the original matrix are recorded here\nC ITER -- The actual number of iterative corrections used\nC RESNRM -- The Euclidean norm of the residual vector B - A X\nC XNORM -- The Euclidean norm of the solution vector\nC DIV,TD -- Contains transformation information for rank\nC deficient problems\nC SCALES -- Contains the column scaling parameters\nC\nC **********************************************************************\nC\nC***SEE ALSO BVSUP\nC***REFERENCES G. Golub, Numerical methods for solving linear least\nC squares problems, Numerische Mathematik 7, (1965),\nC pp. 206-216.\nC P. Businger and G. Golub, Linear least squares\nC solutions by Householder transformations, Numerische\nC Mathematik 7, (1965), pp. 269-276.\nC***ROUTINES CALLED J4SAVE, OHTROR, ORTHOL, R1MACH, SDOT, SDSDOT,\nC XERMAX, XERMSG, XGETF, XSETF\nC***REVISION HISTORY (YYMMDD)\nC 750601 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890831 Modified array declarations. (WRB)\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\nC 900402 Added TYPE section. (WRB)\nC 910408 Updated the REFERENCES section. (WRB)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE LSSODS\n DIMENSION A(NRDA,*),X(*),B(*),Q(NRDA,*),DIAG(*),\n 1 Z(*),KPIVOT(*),R(*),DIV(*),TD(*),SCALES(*)\nC\nC **********************************************************************\nC\nC MACHINE PRECISION (COMPUTER UNIT ROUNDOFF VALUE) IS DEFINED\nC THE FUNCTION R1MACH.\nC\nC***FIRST EXECUTABLE STATEMENT LSSODS\n URO = R1MACH(3)\nC\nC **********************************************************************\nC\n IF (N .LT. 1 .OR. M .LT. N .OR. NRDA .LT. M) GO TO 1\n IF (ITER .LT. 0) GO TO 1\n IF (IFLAG .LE. 0) GO TO 5\n IF (IFLAG .EQ. 1) GO TO 15\nC\nC INVALID INPUT FOR LSSODS\n 1 IFLAG=2\n CALL XERMSG ('SLATEC', 'LSSODS', 'INVALID INPUT PARAMETERS.', 2,\n + 1)\n RETURN\nC\n 5 CALL XGETF (NFATAL)\n MAXMES = J4SAVE (4,0,.FALSE.)\n IF (IFLAG .EQ. 0) GO TO 7\n NFAT = -1\n IF(NFATAL .EQ. 0) NFAT=0\n CALL XSETF (NFAT)\n CALL XERMAX (1)\nC\nC COPY MATRIX A INTO MATRIX Q\nC\n 7 DO 10 J=1,N\n DO 10 K=1,M\n 10 Q(K,J)=A(K,J)\nC\nC USE ORTHOGONAL TRANSFORMATIONS TO REDUCE Q TO\nC UPPER TRIANGULAR FORM\nC\n CALL ORTHOL(Q,M,N,NRDA,IFLAG,IRANK,ISCALE,DIAG,KPIVOT,SCALES,Z,TD)\nC\n CALL XSETF (NFATAL)\n CALL XERMAX (MAXMES)\n IF (IRANK .EQ. N) GO TO 12\nC\nC FOR RANK DEFICIENT PROBLEMS USE ADDITIONAL ORTHOGONAL\nC TRANSFORMATIONS TO FURTHER REDUCE Q\nC\n IF (IRANK .NE. 0) CALL OHTROR(Q,N,NRDA,DIAG,IRANK,DIV,TD)\n RETURN\nC\nC STORE DIVISORS FOR THE TRIANGULAR SOLUTION\nC\n 12 DO 13 K=1,N\n 13 DIV(K)=DIAG(K)\nC\n 15 IRM=IRANK-1\n IRP=IRANK+1\n ITERP=MIN(ITER+1,11)\n ACC=10.*URO\nC\nC ZERO OUT SOLUTION ARRAY\nC\n DO 20 K=1,N\n 20 X(K)=0.\nC\n IF (IRANK .GT. 0) GO TO 25\nC\nC SPECIAL CASE FOR THE NULL MATRIX\n ITER=0\n XNORM=0.\n RESNRM=SQRT(SDOT(M,B(1),1,B(1),1))\n RETURN\nC\nC COPY CONSTANT VECTOR INTO R\nC\n 25 DO 30 K=1,M\n 30 R(K)=B(K)\nC\nC **********************************************************************\nC SOLUTION SECTION\nC ITERATIVE REFINEMENT OF THE RESIDUAL VECTOR\nC **********************************************************************\nC\n DO 100 IT=1,ITERP\n ITER=IT-1\nC\nC APPLY ORTHOGONAL TRANSFORMATION TO R\nC\n DO 35 J=1,IRANK\n MJ=M-J+1\n GAMMA=SDOT(MJ,Q(J,J),1,R(J),1)/(DIAG(J)*Q(J,J))\n DO 35 K=J,M\n 35 R(K)=R(K)+GAMMA*Q(K,J)\nC\nC BACKWARD SUBSTITUTION FOR TRIANGULAR SYSTEM SOLUTION\nC\n Z(IRANK)=R(IRANK)/DIV(IRANK)\n IF (IRM .EQ. 0) GO TO 45\n DO 40 L=1,IRM\n K=IRANK-L\n KP=K+1\n 40 Z(K)=(R(K)-SDOT(L,Q(K,KP),NRDA,Z(KP),1))/DIV(K)\nC\n 45 IF (IRANK .EQ. N) GO TO 60\nC\nC FOR RANK DEFICIENT PROBLEMS OBTAIN THE\nC MINIMAL LENGTH SOLUTION\nC\n NMIR=N-IRANK\n DO 50 K=IRP,N\n 50 Z(K)=0.\n DO 55 K=1,IRANK\n GAM=((TD(K)*Z(K))+SDOT(NMIR,Q(K,IRP),NRDA,Z(IRP),1))/\n 1 (TD(K)*DIV(K))\n Z(K)=Z(K)+GAM*TD(K)\n DO 55 J=IRP,N\n 55 Z(J)=Z(J)+GAM*Q(K,J)\nC\nC REORDER SOLUTION COMPONENTS ACCORDING TO PIVOTAL POINTS\nC AND RESCALE ANSWERS AS DICTATED\nC\n 60 DO 65 K=1,N\n Z(K)=Z(K)*SCALES(K)\n L=KPIVOT(K)\n 65 X(L)=X(L)+Z(K)\nC\nC COMPUTE CORRECTION VECTOR NORM (SOLUTION NORM)\nC\n ZNORM=SQRT(SDOT(N,Z(1),1,Z(1),1))\n IF (IT .EQ. 1) XNORM=ZNORM\n IF (ITERP .GT. 1) GO TO 80\nC\nC NO ITERATIVE CORRECTIONS TO BE PERFORMED, SO COMPUTE\nC THE APPROXIMATE RESIDUAL NORM DEFINED BY THE EQUATIONS\nC WHICH ARE NOT SATISFIED BY THE SOLUTION\nC THEN WE ARE DONE\nC\n MMIR=M-IRANK\n IF (MMIR .EQ. 0) GO TO 70\n RESNRM=SQRT(SDOT(MMIR,R(IRP),1,R(IRP),1))\n RETURN\n 70 RESNRM=0.\n RETURN\nC\nC COMPUTE RESIDUAL VECTOR FOR THE ITERATIVE IMPROVEMENT PROCESS\nC\n 80 DO 85 K=1,M\n 85 R(K)=-SDSDOT(N,-B(K),A(K,1),NRDA,X(1),1)\n RESNRM=SQRT(SDOT(M,R(1),1,R(1),1))\n IF (IT .EQ. 1) GO TO 100\nC\nC TEST FOR CONVERGENCE\nC\n IF (ZNORM .LE. ACC*XNORM) RETURN\nC\nC COMPARE SUCCESSIVE REFINEMENT VECTOR NORMS\nC FOR LOOP TERMINATION CRITERIA\nC\n IF (ZNORM .LE. 0.25*ZNRM0) GO TO 100\n IF (IT .EQ. 2) GO TO 90\nC\n IFLAG=4\n CALL XERMSG ('SLATEC', 'LSSODS',\n + 'PROBLEM MAY BE ILL-CONDITIONED. MAXIMAL MACHINE ACCURACY ' //\n + 'IS NOT ACHIEVABLE.', 3, 1)\n RETURN\nC\n 90 IFLAG=5\n CALL XERMSG ('SLATEC', 'LSSODS',\n + 'PROBLEM IS VERY ILL-CONDITIONED. ITERATIVE ' //\n + 'IMPROVEMENT IS INEFFECTIVE.', 8, 1)\n RETURN\nC\n 100 ZNRM0=ZNORM\nC **********************************************************************\nC\nC **********************************************************************\n IFLAG=6\n CALL XERMSG ('SLATEC', 'LSSODS',\n + 'CONVERGENCE HAS NOT BEEN OBTAINED WITH ALLOWABLE ' //\n + 'NUMBER OF ITERATIVE IMPROVEMENT STEPS.', 8, 1)\nC\n RETURN\n END\n", "meta": {"hexsha": "f5990236550a859f9e86994aae50616cad49f08a", "size": 10715, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/lssods.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/lssods.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/lssods.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.2467105263, "max_line_length": 72, "alphanum_fraction": 0.5685487634, "num_tokens": 3257, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122213606241, "lm_q2_score": 0.763483758172699, "lm_q1q2_score": 0.692718144600429}} {"text": "c***********************************************************************\nc> \\file conte.f\nc> \\brief Solves the Orr-Sommerfeld equation for incompressible channel\nc> \\author S. Scott Collis\nc***********************************************************************\nC> \\brief Orr-Sommerfeld solver for channel flow\nC> \\details Main program to solve the Orr-Sommerfeld equation for \nC> incompressible Channel flow\nC> Uses the method of Godunov-Conte orthonormalization with\nC> explicit Runge-Kutta time integration.\nC> Reference: S.D. Conte, SIAM Review, v8, n3, July 1966\nC> \"The Numerical Solution of Linear Boundary Value\nC> Problems\"\nc***********************************************************************\n program conte_chan\nc***********************************************************************\nc \nc Purpose: Solve the Orr-Sommerfeld equation using Runge-\nc Kutta explicit integration with pseudo-orthogonalization\nc\nc This version assumes a parabolic channel profile\nc\nc Citation: Follows the method of S.D. Conte in \nc SIAM Review, v8, n3, July 1966\nc \"The Numerical Solution of Linear Boundary Value\nc Problems\"\nc\nc Output: Complex valued eigenfunction is phi \nc\nc fort.10 Mean velocity profile\nc fort.11 phi(y)\nc fort.12 phi'(y)\nc fort.13 phi''(y)\nc fort.14 phi'''(y)\nc\nc Author: Scott Collis\nc\nc Date: 6-30-1992\nc\nc Revised: 12-29-2019\nc\nc***********************************************************************\nc Common variables\nc***********************************************************************\n parameter (imax=10000)\n integer n\n complex alpha, c\n real U(0:imax), d2U(0:imax), Re, ymin, ymax, h\n\n common /setup/ n, alpha, u, d2u, Re, ymin, ymax, h, c\nc***********************************************************************\n parameter (neq=4)\n complex bc1(neq), bc2(neq)\n character input*1\n \n complex INPROD\n external OSHOMO, OSPART, INPROD\nc\nc Defaults\nc \n n = 2000\n Re = 10000.0\n alphar = 1.0\n alphai = 0.0\n cr = 0.23753\n ci = 0.00374\n ymin = -1.0\n ymax = 1.0\nc\nc Input parameters\nc\n write (*,10)\n 10 format (/,10x,'Solve Orr-Sommerfeld for Channel using shooting',/)\n write (*,15)\n 15 format(/,1x,'Read from keyboard, file, default (k,d) ==> ',$)\n read (*,'(a)') input\n if (input .eq. 'k' .or. input .eq. 'K') then\n write (*,20)\n 20 format (/,1x,'Enter number of steps ==> ',$)\n read (*,*) n\n write (*,30)\n 30 format (/,1x,'Enter Reynolds number ==> ',$)\n read (*,*) Re\n write (*,40) \n 40 format (/,1x,'Enter alpha_r ==> ',$)\n read (*,*) alphar\n write (*,45) \n 45 format (/,1x,'Enter alpha_i ==> ',$)\n read (*,*) alphai\n write (*,50)\n 50 format (/,1x,'Enter guess for (c_r, c_i) ==> ',$)\n read (*,*) cr, ci\n end if\nc\nc Echo input\nc\n write (*,100) n\n 100 format (/,1x,'n = ',i5)\n write (*,110) Re\n 110 format (1x,'Re = ',e20.10)\n write (*,120) alphar, alphai\n 120 format (1x,'alpha = (',e20.10,', ',e20.10,')')\n write (*,130) cr, ci\n 130 format (1x,'c = (',e20.10,', ',e20.10,')',/)\nc\nc Set constants\nc\n alpha = cmplx(alphar,alphai)\n c = cmplx(cr,ci)\n h = (ymax-ymin)/float(n)\nc\nc Check the problem size\nc\n if (n .gt. imax) then\n write (*,300)\n 300 format (/,/,1x,'N > Idim...Stopping',/,/)\n goto 210\n endif\nc\nc This really just makes a parabolic profile\nc\n call SET_MEAN_FLOW \nc\nc set the boundary conditions\nc\n do i = 1, neq\n bc1(i) = 0.0\n bc2(i) = 0.0\n end do\n \n call CONTE(n, neq, 2, bc1, bc2, ymin, ymax, c, .true.,\n & OSHOMO, OSPART, INPROD)\n\n 210 continue \n stop\n end\n\nC***********************************************************************\nC> \\brief Defines the inner product for use in orthonormalization\nC> \\details Returns the value of \\f$ v_1 \\cdot v_2 \\f$\nC> \\param n length of vectors\nC> \\param v1 first vector\nC> \\param v2 second vector\nC> \\return possibly complex valued inner product\nC***********************************************************************\n function INPROD(n, v1, v2)\nC***********************************************************************\nC\nC Perform and inner product on two comples vectors, v1 and v2\nC\nc***********************************************************************\n complex v1(n), v2(n)\n complex INPROD\n integer n, i\n#if USE_ANALYTIC_INPROD\nc\nc Lets define a different complex inner product so that the\nc iteration is analytic\nc\n INPROD = 0.0\n do i = 1, n\n INPROD = INPROD + v1(i)*v2(i)\n end do\n#else\n INPROD = 0.0\n do i = 1, n\n INPROD = INPROD + v1(i)*conjg(v2(i))\n end do\n#endif \n return\n end\n\nC***********************************************************************\nC> \\brief Evaluate the homogeneous Orr-Sommerfeld equation\nC> \\param[in] neq number of equations\nC> \\param[in] yo Current state vector\nC> \\param[in] t Current independent variable\nC> \\param[out] yf Function evaluation\nC***********************************************************************\n subroutine OSHOMO(neq,yo,t,yf)\nC***********************************************************************\nC\nC Function evaluation for the Orr-Sommerfeld equation\nC\nc***********************************************************************\nc Common variables\nc***********************************************************************\n parameter (imax=10000)\n integer n\n complex alpha, c\n real U(0:imax), d2U(0:imax), Re, ymin, ymax, h\n\n common /setup/ n, alpha, u, d2u, Re, ymin, ymax, h, c\nc***********************************************************************\n complex yo(4), yf(4)\n real t\n integer neq\n real UU, dUU, d2UU\nc\nc Get the velocity field\nc\n call CHANNEL(t,UU,dUU,d2UU)\n\n do j = 1 , 3\n yf(j) = yo(j+1)\n end do\n yf(4) = 2.*alpha**2*yo(3)-alpha**4*yo(1) + \n & (0,1.)*alpha*Re*((UU-c)*(yo(3)-alpha**2*yo(1))-\n & d2UU*yo(1)) \n\n return\n end\n\nC***********************************************************************\nC> \\brief Evaluate the homogeneous Orr-Sommerfeld equation\nC> \\param[in] neq number of equations\nC> \\param[in] yo Current state vector\nC> \\param[in] t Current independent variable\nC> \\param[out] yf Function evaluation\nC***********************************************************************\n subroutine OSPART(neq,yo,t,yf)\nC***********************************************************************\nC\nC Function evaluation for the Orr-Sommerfeld equation\nC\nc***********************************************************************\nc Common variables\nc***********************************************************************\n parameter (imax=10000)\n integer n\n complex alpha, c\n real U(0:imax), d2U(0:imax), Re, ymin, ymax, h\n\n common /setup/ n, alpha, u, d2u, Re, ymin, ymax, h, c\nc***********************************************************************\n complex yo(4), yf(4)\n real t\n integer neq\n real UU, dUU, d2UU\nc\nc Get the velocity field\nc\n call CHANNEL(t,UU,dUU,d2UU)\n\n do j = 1 , 3\n yf(j) = yo(j+1)\n end do\n yf(4) = 2.*alpha**2*yo(3)-alpha**4*yo(1) + \n & (0,1.)*alpha*Re*((UU-c)*(yo(3)-alpha**2*yo(1))-\n & d2UU*yo(1)) \n\n return\n end\n\nC***********************************************************************\nC> \\brief Set the mean flow \nC***********************************************************************\n subroutine SET_MEAN_FLOW \nC***********************************************************************\nC\nC Setup/solve for the velocity profile. In this case, the profile\nC for an incompressible channel flow is analytic\nC\nc***********************************************************************\nc Common variables\nc***********************************************************************\n parameter (imax=10000)\n integer n\n complex alpha, c\n real U(0:imax), d2U(0:imax), Re, ymin, ymax, h\n\n common /setup/ n, alpha, u, d2u, Re, ymin, ymax, h, c\nc***********************************************************************\n integer i, j, k, p\n real xi(3,imax), f(3), eta(3), y, pi, us, dus, d2us\n real k1(3), k2(3), k3(3), k4(3), err, x2old, f1old\n\n pi = acos(-1.0)\nc\nc Now assemble the velocity field\nc\n do i = 0, n\n y = ymin + i*h\n call CHANNEL(y,u(i),dudy,d2u(i))\n end do\nc\nc Write profile on 2x resolve mesh\nc\nc open (10, FILE='chan.dat', ACTION='WRITE', FORM='FORMATTED')\n do i = 0, 2*n\n y = ymin + i*h/2.0\n call CHANNEL(y,us,dus,d2us)\n write (10,10) y, us, d2us\n 10 format (1x,5(ES16.8E3,1x))\n end do\nc close(10)\n\n write (*,20)\n 20 format (1x,'Channel velocity profile completed...',/)\n\n return\n end\n\nC***********************************************************************\nC> \\brief The analytic profile for incompressible channel flow\nC> \\param[in] y location to evaluate profile \\f$[-1,1]\\f$\nC> \\param[out] u velocity at \\f$y\\f$ \nC> \\param[out] dudy derivative of velocity at \\f$y\\f$ \nC> \\param[out] d2udy2 second derivative of velocity at \\f$y\\f$\nC***********************************************************************\n subroutine CHANNEL(y,u,dudy,d2udy2)\nC***********************************************************************\nC\nC Incompressible channel flow profile\nC\nC***********************************************************************\n real y, u, dudy, d2udy2\nC***********************************************************************\n u = 1.0 - y**2\n dudy = -2.0*y\n d2udy2 = -2.0\n return\n end\n", "meta": {"hexsha": "bf4fe8ce1ff16753df273b63af4b8d8c54053ea7", "size": 10305, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "conte.f", "max_stars_repo_name": "sscollis/os-stab", "max_stars_repo_head_hexsha": "01d3254e5a391a66c3a4c3971d1b1cd3d53e8330", "max_stars_repo_licenses": ["BSD-3-Clause-No-Nuclear-License-2014", "BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-04-12T00:03:09.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-04T18:46:30.000Z", "max_issues_repo_path": "conte.f", "max_issues_repo_name": "sscollis/os-stab", "max_issues_repo_head_hexsha": "01d3254e5a391a66c3a4c3971d1b1cd3d53e8330", "max_issues_repo_licenses": ["BSD-3-Clause-No-Nuclear-License-2014", "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": "conte.f", "max_forks_repo_name": "sscollis/os-stab", "max_forks_repo_head_hexsha": "01d3254e5a391a66c3a4c3971d1b1cd3d53e8330", "max_forks_repo_licenses": ["BSD-3-Clause-No-Nuclear-License-2014", "BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-03-05T06:10:21.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-17T18:58:41.000Z", "avg_line_length": 31.8055555556, "max_line_length": 72, "alphanum_fraction": 0.4262008734, "num_tokens": 2766, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146780175245, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.6927071736490819}} {"text": "program F_cum\n!===============================================================================\n! Outputs values of the cumulative F distribution F(x;m,n)\n use statistical\n implicit none\n integer,parameter :: rs = 8\n real(rs) :: x\n integer :: m,n\n character(len=80) :: arg\n \n if (command_argument_count() /= 3) then\n write(*,'(a)') 'Usage: F_cum [x] [n] [m]'\n stop\n endif\n \n call get_command_argument(1,arg) ; read(arg,*) x\n call get_command_argument(2,arg) ; read(arg,*) n\n call get_command_argument(3,arg) ; read(arg,*) m\n \n write(*,*) f_dist_cum(n,m,x)\n \nend program F_cum", "meta": {"hexsha": "0b8cc3b291c9c90e75fc4ba8c919bfb1d8a4ef1e", "size": 621, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test_statistical/F_cum.f90", "max_stars_repo_name": "JackWalpole/seismo-fortran-fork", "max_stars_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2015-06-23T05:28:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T03:46:07.000Z", "max_issues_repo_path": "test_statistical/F_cum.f90", "max_issues_repo_name": "JackWalpole/seismo-fortran-fork", "max_issues_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2017-05-17T11:02:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-28T09:36:24.000Z", "max_forks_repo_path": "test_statistical/F_cum.f90", "max_forks_repo_name": "JackWalpole/seismo-fortran-fork", "max_forks_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-04-15T02:55:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-20T12:20:51.000Z", "avg_line_length": 28.2272727273, "max_line_length": 80, "alphanum_fraction": 0.5362318841, "num_tokens": 171, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467738423873, "lm_q2_score": 0.7879311981328135, "lm_q1q2_score": 0.6927071708482299}} {"text": "\ufeffx: i32 = 5 * 3 + 4;\ny: i32 = 4 + 5 * 3;\nz: i32 = 5 * (3 + 4);\n", "meta": {"hexsha": "a4a74fa1f3ba2f4be212d5cd4ce012f5df548f63", "size": 63, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/operators/precedence.f", "max_stars_repo_name": "Flamaros/f-lang", "max_stars_repo_head_hexsha": "bcfe9e814e0c654ce68939ecf78b9fc0a937a3fc", "max_stars_repo_licenses": ["MIT"], "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/operators/precedence.f", "max_issues_repo_name": "Flamaros/f-lang", "max_issues_repo_head_hexsha": "bcfe9e814e0c654ce68939ecf78b9fc0a937a3fc", "max_issues_repo_licenses": ["MIT"], "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/operators/precedence.f", "max_forks_repo_name": "Flamaros/f-lang", "max_forks_repo_head_hexsha": "bcfe9e814e0c654ce68939ecf78b9fc0a937a3fc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.75, "max_line_length": 21, "alphanum_fraction": 0.3333333333, "num_tokens": 43, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972818382005, "lm_q2_score": 0.7956581097540518, "lm_q1q2_score": 0.6926977876243982}} {"text": " program test1\n implicit none\n integer::i\n integer::nnu !Simpson\u79ef\u5206\u5c0f\u533a\u95f4\u7684\u6570\u76ee\n real*8::xival !Simpson\u79ef\u5206\u7684\u79ef\u5206\u533a\u95f4\u957f\u5ea6\n real*8,allocatable,dimension(:)::rr !Simpson\u79ef\u5206\u7684\u683c\u70b9\n real*8,allocatable,dimension(:)::rw !Simpson\u79ef\u5206\u7684\u6743\u91cd\u7cfb\u6570\n real*8::f\n \n nnu=1000 !\u7ed9\u51faSimpson\u79ef\u5206\u7684\u5c0f\u533a\u95f4\u7684\u6570\u76ee\n xival=40.0 !\u7ed9\u51faSimpson\u79ef\u5206\u7684\u79ef\u5206\u533a\u95f4\u957f\u5ea6\n allocate(rr(0:nnu),rw(0:nnu))\n call simpson(nnu,xival,rr,rw) !\u521d\u59cb\u5316\u9ad8\u65af\u79ef\u5206\uff0c\u8f93\u51fa\u79ef\u5206\u683c\u70b9\u4e0e\u6743\u91cd\u7cfb\u6570\n f=0.d0\n do i=0,nnu\n f=f+rr(i)**2*rw(i)\n end do\n write(*,*)f\n end program test1\n\n\n ! subroutine to generate the grid points and width for Simpson integration\n subroutine simpson(nnu,xival,rr,rw)\n implicit none \n integer :: nxmx,nnu\n real*8 :: xival\n real*8,dimension(1:nnu) :: rr,rw\n real*8,dimension(1:nnu+1) :: sxx,wxx\n real*8 :: dx, d43,d23\n integer :: nxmx1, nxmx2,i \n \n nxmx=nnu+1\n dx=xival/float(nxmx-1)\n \n d43=4.d0/3.d0\n d23=2.d0/3.d0\n \n wxx(1)=dx/3.d0\n wxx(nxmx)=dx/3.d0\n sxx(1)=0.d0\n sxx(nxmx)=float(nxmx-1)*dx\n\n \n nxmx1=nxmx-1\n nxmx2=nxmx-2\n \n do 50 i=2,nxmx1,2\n sxx(i)=float(i-1)*dx\n 50 wxx(i)=d43*dx\n \n do 55 i=3,nxmx2,2\n sxx(i)=float(i-1)*dx\n 55 wxx(i)=d23*dx\n \n \n do i=1,nnu\n rr(i)=sxx(i+1)\n rw(i)=wxx(i+1)\n end do \n end subroutine \n\n\n\n", "meta": {"hexsha": "81dc936131068a099ff0ec2659380d06f22b2b04", "size": 1422, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "simpson_exp.f90", "max_stars_repo_name": "yazhouLY/samples", "max_stars_repo_head_hexsha": "15ee20e233aa74f46ab022dfc69f3d11fb67b608", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "simpson_exp.f90", "max_issues_repo_name": "yazhouLY/samples", "max_issues_repo_head_hexsha": "15ee20e233aa74f46ab022dfc69f3d11fb67b608", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "simpson_exp.f90", "max_forks_repo_name": "yazhouLY/samples", "max_forks_repo_head_hexsha": "15ee20e233aa74f46ab022dfc69f3d11fb67b608", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.21875, "max_line_length": 75, "alphanum_fraction": 0.5309423347, "num_tokens": 590, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232809, "lm_q2_score": 0.7956581024858785, "lm_q1q2_score": 0.692697775953966}} {"text": "!****************************************************************************!\n! Quick sort routine from: !\n! Brainerd, W.S., Goldberg, C.H. & Adams, J.C. (1990) \"Programmer's Guide to !\n! Fortran 90\", McGraw-Hill ISBN 0-07-000248-7, pages 149-150. !\n! Modified by Alan Miller to include an associated integer array which gives !\n! the positions of the elements in the original order. !\n! Modified for integer array by Sarit Dutta !\n!****************************************************************************!\n\nMODULE m_qsort\n!! Implements quicksort for a sequence of integers and reals, in combination with\n!! insertion sort for very short sequences.\n!\"\"\n\nUSE M_PRECISION\n\nIMPLICIT NONE\n\nCONTAINS\n\n!******************************************************************************\n\nRECURSIVE SUBROUTINE iqsort(list, order)\n !! Sorts a sequence of integers\n !\"\"\n\nIMPLICIT NONE\n\nINTEGER, DIMENSION (:), INTENT(IN OUT) :: list\n !! Sequence of integers to be sorted\nINTEGER, DIMENSION (:), INTENT(OUT), OPTIONAL :: order\n !! Indices of the sorted sequence\n\n! Local variable\nINTEGER :: i\n\nIF (PRESENT(order)) THEN\n DO i = 1, SIZE(list)\n order(i) = i\n END DO\nEND IF\n\nCALL quick_sort_1(1, SIZE(list))\n\nCONTAINS\n\n RECURSIVE SUBROUTINE quick_sort_1(left_end, right_end)\n \n INTEGER, INTENT(IN) :: left_end, right_end\n \n ! Local variables\n INTEGER :: i, j, itemp\n INTEGER :: reference, temp\n INTEGER, PARAMETER :: max_simple_sort_size = 8\n \n IF (right_end < left_end + max_simple_sort_size) THEN\n ! Use interchange sort for small lists\n CALL interchange_sort(left_end, right_end)\n \n ELSE\n ! Use partition (\"quick\") sort\n reference = list((left_end + right_end)/2)\n i = left_end - 1; j = right_end + 1\n \n DO\n ! Scan list from left end until element >= reference is found\n DO\n i = i + 1\n IF (list(i) >= reference) EXIT\n END DO\n ! Scan list from right end until element <= reference is found\n DO\n j = j - 1\n IF (list(j) <= reference) EXIT\n END DO\n \n IF (i < j) THEN\n ! Swap two out-of-order elements\n temp = list(i); list(i) = list(j); list(j) = temp\n IF (PRESENT(order)) THEN\n itemp = order(i); order(i) = order(j); order(j) = itemp\n END IF\n ELSE IF (i == j) THEN\n i = i + 1\n EXIT\n ELSE\n EXIT\n END IF\n END DO\n \n IF (left_end < j) CALL quick_sort_1(left_end, j)\n IF (i < right_end) CALL quick_sort_1(i, right_end)\n END IF\n \n END SUBROUTINE quick_sort_1\n\n\n SUBROUTINE interchange_sort(left_end, right_end)\n \n INTEGER, INTENT(IN) :: left_end, right_end\n \n ! Local variables\n INTEGER :: i, j, itemp\n INTEGER :: temp\n \n DO i = left_end, right_end - 1\n DO j = i+1, right_end\n IF (list(i) > list(j)) THEN\n temp = list(i); list(i) = list(j); list(j) = temp\n IF (PRESENT(order)) THEN\n itemp = order(i); order(i) = order(j); order(j) = itemp\n END IF\n END IF\n END DO\n END DO\n \n END SUBROUTINE interchange_sort\n\nEND SUBROUTINE iqsort\n\n!******************************************************************************\n\nRECURSIVE SUBROUTINE dqsort(list, order)\n !! Sorts a sequence of reals\n !\"\"\n\nIMPLICIT NONE\n\nREAL(RP), DIMENSION (:), INTENT(IN OUT) :: list\n !! Sequence of reals to be sorted\nINTEGER, DIMENSION (:), INTENT(OUT), OPTIONAL :: order\n !! Indices of the sorted sequence\n\n! Local variable\nINTEGER :: i\n\nIF (PRESENT(order)) THEN\n DO i = 1, SIZE(list)\n order(i) = i\n END DO\nEND IF\n\nCALL quick_sort_1(1, SIZE(list))\n\nCONTAINS\n\n RECURSIVE SUBROUTINE quick_sort_1(left_end, right_end)\n \n INTEGER, INTENT(IN) :: left_end, right_end\n \n ! Local variables\n INTEGER :: i, j, itemp\n REAL(RP) :: reference, temp\n INTEGER, PARAMETER :: max_simple_sort_size = 8\n \n IF (right_end < left_end + max_simple_sort_size) THEN\n ! Use interchange sort for small lists\n CALL interchange_sort(left_end, right_end)\n \n ELSE\n ! Use partition (\"quick\") sort\n reference = list((left_end + right_end)/2)\n i = left_end - 1; j = right_end + 1\n \n DO\n ! Scan list from left end until element >= reference is found\n DO\n i = i + 1\n IF (list(i) >= reference) EXIT\n END DO\n ! Scan list from right end until element <= reference is found\n DO\n j = j - 1\n IF (list(j) <= reference) EXIT\n END DO\n \n IF (i < j) THEN\n ! Swap two out-of-order elements\n temp = list(i); list(i) = list(j); list(j) = temp\n IF (PRESENT(order)) THEN\n itemp = order(i); order(i) = order(j); order(j) = itemp\n END IF\n ELSE IF (i == j) THEN\n i = i + 1\n EXIT\n ELSE\n EXIT\n END IF\n END DO\n \n IF (left_end < j) CALL quick_sort_1(left_end, j)\n IF (i < right_end) CALL quick_sort_1(i, right_end)\n END IF\n \n END SUBROUTINE quick_sort_1\n\n\n SUBROUTINE interchange_sort(left_end, right_end)\n \n INTEGER, INTENT(IN) :: left_end, right_end\n \n ! Local variables\n INTEGER :: i, j, itemp\n REAL(RP) :: temp\n \n DO i = left_end, right_end - 1\n DO j = i+1, right_end\n IF (list(i) > list(j)) THEN\n temp = list(i); list(i) = list(j); list(j) = temp\n IF (PRESENT(order)) THEN\n itemp = order(i); order(i) = order(j); order(j) = itemp\n END IF\n END IF\n END DO\n END DO\n \n END SUBROUTINE interchange_sort\n\nEND SUBROUTINE dqsort\n\n!******************************************************************************\n\nEND MODULE m_qsort\n", "meta": {"hexsha": "8fb0872dc9eccb63d623a92191bd2aa7f06be7c2", "size": 6403, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/m_qsort.f90", "max_stars_repo_name": "saridut/mcpak", "max_stars_repo_head_hexsha": "e182eb11198f7c03f737df696017b7eb7dc99230", "max_stars_repo_licenses": ["MIT"], "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/m_qsort.f90", "max_issues_repo_name": "saridut/mcpak", "max_issues_repo_head_hexsha": "e182eb11198f7c03f737df696017b7eb7dc99230", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/m_qsort.f90", "max_forks_repo_name": "saridut/mcpak", "max_forks_repo_head_hexsha": "e182eb11198f7c03f737df696017b7eb7dc99230", "max_forks_repo_licenses": ["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.5848214286, "max_line_length": 82, "alphanum_fraction": 0.4935186631, "num_tokens": 1558, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.6926119474433546}} {"text": "program divprec\nuse, intrinsic:: iso_fortran_env, stderr=>error_unit\nimplicit none (type, external)\n\n! shows pitfall of not being mindful with input Kind\n\n! NOTE that 9/5.0_dp /= 9/5.0, even when the assigned variable is real(dp) !!\n\n! NOTE: using gfortran option \"-fdefault-real-8\" fixes these problems!\n! NOTE: using ifort option \"-r8\" fixes these problems!\n\nreal(real32) :: huge32 = 9/5.0_real32\nreal(real64) :: huge64 = 9/5.0_real64\nreal(real128) :: huge128 = 9/5.0_real128\ninteger(int64) :: hugeint64 = 9/5_int64\n\nreal(real64) :: imdouble = 9/5.\n\ninteger(int64) :: J, K\n\nprint *, compiler_version()\n\nif (storage_size(imdouble) /= 64) then\n write(stderr,*) 'expected real64 but you have real bits: ', storage_size(imdouble)\n error stop\nendif\nprint *,'64-bit variable with 32-bit constants',imdouble\n\nif (storage_size(huge64) /= 64) then\n write(stderr,*) 'expected real64 but you have real bits: ', storage_size(huge64)\n error stop\nendif\nprint *,'64-bit',huge64\nprint *,'64-bit variable, 32-bit constants equal to all 64-bit constants?',imdouble==huge64\n\n\nif (storage_size(huge32) /= 32) then\n write(stderr,*) 'expected real32 but you have real bits: ', storage_size(huge32)\n error stop\nendif\nprint *,'32-bit',huge32\n\nif (storage_size(huge128) /= 128) then\n write(stderr,*) 'expected real128 but you have real bits: ', storage_size(huge128)\n error stop\nendif\nprint *,'128-bit',huge128\n\nif (storage_size(hugeint64) /= 64) then\n write(stderr,*) 'expected int64 but you have integer bits: ', storage_size(hugeint64)\n error stop\nendif\nprint *,'64-bit Integer ',hugeint64\n\n\n\n! 64-bit variable with 32-bit constants 1.7999999523162842\n! 64-bit variable, 32-bit constants equal to all 64-bit constants? F\n! 32-bit 1.79999995\n! 64-bit 1.8000000000000000\n! 128-bit 1.80000000000000000000000000000000004\n! 64-bit Integer 1\n! kinds sp dp qp i64\n! 4 8 16 8\n! Bit Patterns:\n! 11011011111111111100110011001100110011000000000000000000000000000000\n! 11011011111111111100110011001100110011001100110011001100110011001101\n\nJ = transfer(imdouble, J)\nK = transfer(huge64, K)\nprint *,'Bit Patterns:'\n\nprint '(A,B64)','64-bit variable with 32-bit constants ', J\nprint '(A,B64)','64-bit variable with 64-bit constants ', K\n\nend program\n", "meta": {"hexsha": "b26b2b12a8057803c346c952d435a77b69bc90b1", "size": 2295, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "real/div_precision.f90", "max_stars_repo_name": "supershushu/fortran2018-examples", "max_stars_repo_head_hexsha": "f0dc03b80326bc7c06fa31945b6e7406a60c1fa8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 305, "max_stars_repo_stars_event_min_datetime": "2017-12-07T12:47:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T12:03:16.000Z", "max_issues_repo_path": "real/div_precision.f90", "max_issues_repo_name": "supershushu/fortran2018-examples", "max_issues_repo_head_hexsha": "f0dc03b80326bc7c06fa31945b6e7406a60c1fa8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2018-11-24T15:45:53.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-06T08:10:43.000Z", "max_forks_repo_path": "real/div_precision.f90", "max_forks_repo_name": "supershushu/fortran2018-examples", "max_forks_repo_head_hexsha": "f0dc03b80326bc7c06fa31945b6e7406a60c1fa8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 60, "max_forks_repo_forks_event_min_datetime": "2017-11-28T07:56:03.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-20T01:37:53.000Z", "avg_line_length": 29.8051948052, "max_line_length": 91, "alphanum_fraction": 0.7163398693, "num_tokens": 724, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430394931456, "lm_q2_score": 0.8333245953120233, "lm_q1q2_score": 0.6926119370320306}} {"text": "module mod_tests_jacobi_iteration_4_point_stencil\n use,intrinsic :: iso_fortran_env\n use mod_wall_clock_time, only : wall_clock_time\n implicit none\n private \n public tests_jacobi\n contains\n !---\n subroutine tests_jacobi(nsize,nloop,nimp,wct,a,b)\n integer(int32),intent(in) :: nsize,nloop,nimp\n real(real64),dimension(nimp),intent(out) :: wct\n real(real64),dimension(nsize,nsize),intent(inout) :: a,b\n integer(int32) :: i,j,k,l\n real(real64) :: t1,t2,error\n\n ! implementation 1 \"sequential do\"\n i = 1\n call wall_clock_time(t1)\n do l=1,nloop\n do k=2,nsize-1\n do j=2,nsize-1\n b(j,k) = 0.25d0*(a(j,k-1)+a(j-1,k)+a(j+1,k)+a(j,k+1))\n end do\n end do\n !error = sum(abs(a-b))\n do k=2,nsize-1\n do j=2,nsize-1\n a(j,k) = b(j,k)\n end do\n end do\n end do\n call wall_clock_time(t2)\n wct(i) = t2-t1\n\n ! implementation 2 \"OpenMP do\"\n i = 2\n call wall_clock_time(t1)\n do l=1,nloop\n !$omp parallel do collapse(2) private(j,k) shared(nsize,a,b)\n do k=2,nsize-1\n do j=2,nsize-1\n b(j,k) = 0.25d0*(a(j,k-1)+a(j-1,k)+a(j+1,k)+a(j,k+1))\n end do\n end do\n !$omp end parallel do\n !error = sum(abs(a-b))\n !$omp parallel do collapse(2) private(j,k) shared(nsize,a,b)\n do k=2,nsize-1\n do j=2,nsize-1\n a(j,k) = b(j,k)\n end do\n end do\n !$omp end parallel do\n end do\n call wall_clock_time(t2)\n wct(i) = t2-t1\n\n ! implementation 3 \"do concurrent (single loop)\"\n i = 3\n call wall_clock_time(t1)\n do l=1,nloop\n do concurrent(k=2:nsize-1,j=2:nsize-1)\n b(j,k) = 0.25d0*(a(j,k-1)+a(j-1,k)+a(j+1,k)+a(j,k+1))\n end do\n !error = sum(abs(a-b))\n do concurrent(k=2:nsize-1,j=2:nsize-1)\n !do concurrent(j=2:nsize-1,k=2:nsize-1)\n a(j,k) = b(j,k)\n end do\n end do\n call wall_clock_time(t2)\n wct(i) = t2-t1\n\n ! implementation 4 \"do concurrent (double loop)\"\n i = 4\n call wall_clock_time(t1)\n do l=1,nloop\n do concurrent(k=2:nsize-1)\n do concurrent(j=2:nsize-1)\n b(j,k) = 0.25d0*(a(j,k-1)+a(j-1,k)+a(j+1,k)+a(j,k+1))\n end do\n end do\n !error = sum(abs(a-b))\n do concurrent(k=2:nsize-1)\n do concurrent(j=2:nsize-1)\n a(j,k) = b(j,k)\n end do\n end do\n end do\n call wall_clock_time(t2)\n wct(i) = t2-t1\n\n end subroutine tests_jacobi\n !---\nend module mod_tests_jacobi_iteration_4_point_stencil", "meta": {"hexsha": "09f5fe086c0f2a6c5f9d01ad84d672dc689f4220", "size": 2683, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/two_dimensional/jacobi.f90", "max_stars_repo_name": "toya42/fortran_parallel_03", "max_stars_repo_head_hexsha": "8bb2ac1274da671638eb9c6b52e01b70704b1862", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2022-01-14T13:27:01.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-14T13:51:43.000Z", "max_issues_repo_path": "src/two_dimensional/jacobi.f90", "max_issues_repo_name": "toya42/fortran_parallel_03", "max_issues_repo_head_hexsha": "8bb2ac1274da671638eb9c6b52e01b70704b1862", "max_issues_repo_licenses": ["MIT"], "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/two_dimensional/jacobi.f90", "max_forks_repo_name": "toya42/fortran_parallel_03", "max_forks_repo_head_hexsha": "8bb2ac1274da671638eb9c6b52e01b70704b1862", "max_forks_repo_licenses": ["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.2421052632, "max_line_length": 68, "alphanum_fraction": 0.5285128587, "num_tokens": 906, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.831143031127974, "lm_q2_score": 0.8333246035907932, "lm_q1q2_score": 0.6926119369419692}} {"text": "program test\n\n !----------------------------------------------------------------------------\n ! MODULS AND VARIABLS\n !----------------------------------------------------------------------------\n\n USE mo_kind, ONLY: sp, dp, i4\n use mo_ansi_colors, only: color, c_red, c_green\n USE mo_pumpingtests, ONLY: thiem, theis, ext_thiem2d, ext_thiem3d, ext_theis2d, ext_theis3d\n use mo_utils, ONLY: eq\n\n Implicit none\n\n REAL(sp) :: Reftest, hreftest, Qwtest, Ktest, Ltest, Stest, TGtest, &\n vartest, corrtest, anisotest!, proptest\n REAL(dp) :: Reftestd, hreftestd, Qwtestd, Ktestd, Ltestd, Stestd, &\n TGtestd, vartestd, corrtestd, anisotestd\n !, proptestd\n LOGICAL :: isgood\n\n real(dp), dimension(3,3) :: fpoints_dp, fpoints2_dp, fpoints3_dp\n real(sp), dimension(3,3) :: fpoints_sp, fpoints2_sp, fpoints3_sp\n\n real(dp), dimension(9,2) :: grid_dp\n real(sp), dimension(9,2) :: grid_sp\n\n integer(i4) :: m,n\n\n real(sp) :: stmp\n real(dp) :: dtmp\n\n !----------------------------------------------------------------------------\n ! test-parameters\n !----------------------------------------------------------------------------\n\n Reftest = 1.0_sp\n hreftest = 0.0_sp\n Qwtest = -0.001_sp\n Ktest = 0.0001_sp\n Ltest = 1.0_sp\n Stest = 0.001_sp\n TGtest = Ltest*Ktest\n vartest = 1.0_sp\n !proptest = 0.8_sp\n corrtest = 10.0_sp\n anisotest = 1.0_sp\n\n Reftestd = 1.0_dp\n hreftestd = 0.0_dp\n Qwtestd = -0.001_dp\n Ktestd = 0.0001_dp\n Ltestd = 1.0_dp\n Stestd = 0.001_dp\n TGtestd = Ltestd*Ktestd\n vartestd = 1.0_dp\n !proptestd = 0.8_dp\n corrtestd = 10.0_dp\n anisotestd = 1.0_dp\n\n grid_sp = reshape((/ 1._sp, 2._sp, 3._sp,&\n 1._sp, 2._sp, 3._sp,&\n 1._sp, 2._sp, 3._sp,&\n 50.0_sp, 50.0_sp, 50.0_sp,&\n 100.0_sp, 100.0_sp, 100.0_sp,&\n 1000.0_sp, 1000.0_sp, 1000.0_sp /), (/9,2/))\n\n grid_dp = reshape((/ 1._dp, 2._dp, 3._dp,&\n 1._dp, 2._dp, 3._dp,&\n 1._dp, 2._dp, 3._dp,&\n 50.0_dp, 50.0_dp, 50.0_dp,&\n 100.0_dp, 100.0_dp, 100.0_dp,&\n 1000.0_dp, 1000.0_dp, 1000.0_dp /), (/9,2/))\n\n isgood = .TRUE.\n\n !----------------------------------------------------------------------------\n ! tests\n !----------------------------------------------------------------------------\n\n write (*,*) ''\n write (*,*) 'Test mo_pumpingtests.f90'\n write (*,*) ''\n\n write (*,*) \"THIEM's SOLUTION\"\n write (*,*) '-------------------------------------------------------------------------'\n\n ! Thiemsp(0.2) = -2.56150007\n ! Thiemsp(0.3) = -1.91618240\n ! Thiemdp(0.2) = -2.5614999936338809\n ! Thiemdp(0.3) = -1.9161822315668402\n\n stmp = thiem(0.2_sp, (/Ktest /), (/Reftest , hreftest , Qwtest , Ltest /))\n isgood = isgood .and. (nint(stmp*1000) .EQ. -2562)\n stmp = thiem(0.3_sp, (/Ktest /), (/Reftest , hreftest , Qwtest , Ltest /))\n isgood = isgood .and. (nint(stmp*1000) .EQ. -1916)\n dtmp = thiem(0.2_dp, (/Ktestd/), (/Reftestd, hreftestd, Qwtestd, Ltestd/))\n isgood = isgood .and. (nint(dtmp*1000000) .EQ. -2561500)\n dtmp = thiem(0.3_dp, (/Ktestd/), (/Reftestd, hreftestd, Qwtestd, Ltestd/))\n isgood = isgood .and. (nint(dtmp*1000000) .EQ. -1916182)\n !sp\n write (*,*) 'Thiemsp(0.2) =', thiem(0.2_sp, (/Ktest /), (/Reftest , hreftest , Qwtest , Ltest /))\n write (*,*) 'Thiemsp(0.3) =', thiem(0.3_sp, (/Ktest /), (/Reftest , hreftest , Qwtest , Ltest /))\n !dp\n write (*,*) 'Thiemdp(0.2) =', thiem(0.2_dp, (/Ktestd/), (/Reftestd, hreftestd, Qwtestd, Ltestd/))\n write (*,*) 'Thiemdp(0.3) =', thiem(0.3_dp, (/Ktestd/), (/Reftestd, hreftestd, Qwtestd, Ltestd/))\n\n write (*,*) ' '\n\n write (*,*) \"EXTENDED THIEM's SOLUTION IN 3D\"\n write (*,*) '-------------------------------------------------------------------------'\n\n ! ext_Thiem3d_sp(0.2) = -4.19452763\n ! ext_Thiem3d_sp(0.3) = -3.13209820\n ! ext_Thiem3d_sp(0.2) = -1.55417931 optional\n ! ext_Thiem3d_sp(0.3) = -1.16274548 optional\n ! ext_Thiem3d_dp(0.2) = -4.1945268260359985\n ! ext_Thiem3d_dp(0.3) = -3.1320977426835279\n ! ext_Thiem3d_dp(0.2) = -1.5541790860603071 optional\n ! ext_Thiem3d_dp(0.3) = -1.1627453616249193 optional\n\n stmp = ext_thiem3d(0.2_sp, (/Ktest , vartest , corrtest , anisotest/), &\n (/Reftest , hreftest , Qwtest , Ltest /))\n isgood = isgood .and. (nint(stmp*1000) .EQ. -4195)\n stmp = ext_thiem3d(0.3_sp, (/Ktest , vartest , corrtest , anisotest/), &\n (/Reftest , hreftest , Qwtest , Ltest /))\n isgood = isgood .and. (nint(stmp*1000) .EQ. -3132)\n stmp = ext_thiem3d(0.2_sp, (/Ktest , vartest , corrtest , anisotest/), &\n (/Reftest , hreftest , Qwtest , Ltest /), .false., 1.0_sp)\n isgood = isgood .and. (nint(stmp*1000) .EQ. -1554)\n stmp = ext_thiem3d(0.3_sp, (/Ktest , vartest , corrtest , anisotest/), &\n (/Reftest , hreftest , Qwtest , Ltest /), .false., 1.0_sp)\n isgood = isgood .and. (nint(stmp*1000) .EQ. -1163)\n dtmp = ext_thiem3d(0.2_dp, (/Ktestd, vartestd, corrtestd, anisotestd/), &\n (/Reftestd, hreftestd, Qwtestd, Ltestd/))\n isgood = isgood .and. (nint(dtmp*1000000).EQ. -4194527)\n dtmp = ext_thiem3d(0.3_dp, (/Ktestd, vartestd, corrtestd, anisotestd/), &\n (/Reftestd, hreftestd, Qwtestd, Ltestd/))\n isgood = isgood .and. (nint(dtmp*1000000).EQ. -3132098)\n dtmp = ext_thiem3d(0.2_dp, (/Ktestd, vartestd, corrtestd, anisotestd/), &\n (/Reftestd, hreftestd, Qwtestd, Ltestd/), .false., 1.0_dp)\n isgood = isgood .and. (nint(dtmp*1000000) .EQ. -1554179)\n dtmp = ext_thiem3d(0.3_dp, (/Ktestd, vartestd, corrtestd, anisotestd/), &\n (/Reftestd, hreftestd, Qwtestd, Ltestd/), .false., 1.0_dp)\n isgood = isgood .and. (nint(dtmp*1000000) .EQ. -1162745)\n !sp\n write (*,*) 'ext_Thiem3d_sp(0.2)_std=', ext_thiem3d(0.2_sp, (/Ktest , vartest , corrtest , anisotest /), &\n (/Reftest , hreftest , Qwtest , Ltest /))\n write (*,*) 'ext_Thiem3d_sp(0.3)_std=', ext_thiem3d(0.3_sp, (/Ktest , vartest , corrtest , anisotest /), &\n (/Reftest , hreftest , Qwtest , Ltest /))\n !with optional inputs\n write (*,*) 'ext_Thiem3d_sp(0.2)_opt=', ext_thiem3d(0.2_sp, (/Ktest , vartest , corrtest , anisotest /), &\n (/Reftest , hreftest , Qwtest , Ltest /), &\n .false., 1.0_sp)\n write (*,*) 'ext_Thiem3d_sp(0.3)_opt=', ext_thiem3d(0.3_sp, (/Ktest , vartest , corrtest , anisotest /), &\n (/Reftest , hreftest , Qwtest , Ltest /), &\n .false., 1.0_sp)\n !dp\n write (*,*) 'ext_Thiem3d_dp(0.2)_std=', ext_thiem3d(0.2_dp, (/Ktestd, vartestd, corrtestd, anisotestd/), &\n (/Reftestd, hreftestd, Qwtestd, Ltestd/))\n write (*,*) 'ext_Thiem3d_dp(0.3)_std=', ext_thiem3d(0.3_dp, (/Ktestd, vartestd, corrtestd, anisotestd/), &\n (/Reftestd, hreftestd, Qwtestd, Ltestd/))\n !with optional inputs\n write (*,*) 'ext_Thiem3d_dp(0.2)_opt=', ext_thiem3d(0.2_dp, (/Ktestd, vartestd, corrtestd, anisotestd/), &\n (/Reftestd, hreftestd, Qwtestd, Ltestd/), &\n .false., 1.0_dp)\n write (*,*) 'ext_Thiem3d_dp(0.3)_opt=', ext_thiem3d(0.3_dp, (/Ktestd, vartestd, corrtestd, anisotestd/), &\n (/Reftestd, hreftestd, Qwtestd, Ltestd/), &\n .false., 1.0_dp)\n\n write (*,*) ' '\n\n write (*,*) \"EXTENDED THIEM's SOLUTION IN 2D\"\n write (*,*) '-------------------------------------------------------------------------'\n\n ! ext_Thiem2d_sp(0.2) = -2.57654548\n ! ext_Thiem2d_sp(0.3) = -1.93043315\n ! ext_Thiem2d_sp(0.2) = -2.56530547 optional\n ! ext_Thiem2d_sp(0.3) = -1.91978836 optional\n ! ext_Thiem2d_dp(0.2) = -2.5765449512179259\n ! ext_Thiem2d_dp(0.3) = -1.9304329811242074\n ! ext_Thiem2d_dp(0.2) = -2.5653048154494607 optional\n ! ext_Thiem2d_dp(0.3) = -1.9197882246039830 optional\n\n stmp = ext_thiem2d(0.2_sp, (/TGtest , vartest , corrtest /), (/Reftest , hreftest , Qwtest /))\n isgood = isgood .and. (nint(stmp*1000) .EQ. -2577)\n stmp = ext_thiem2d(0.3_sp, (/TGtest , vartest , corrtest /), (/Reftest , hreftest , Qwtest /))\n isgood = isgood .and. (nint(stmp*1000) .EQ. -1930)\n stmp = ext_thiem2d(0.2_sp, (/TGtest , vartest , corrtest /), (/Reftest , hreftest , Qwtest /),1.0_sp)\n isgood = isgood .and. (nint(stmp*1000) .EQ. -2565)\n stmp = ext_thiem2d(0.3_sp, (/TGtest , vartest , corrtest /), (/Reftest , hreftest , Qwtest /),1.0_sp)\n isgood = isgood .and. (nint(stmp*1000) .EQ. -1920)\n dtmp = ext_thiem2d(0.2_dp, (/TGtestd, vartestd, corrtestd/), (/Reftestd, hreftestd, Qwtestd/))\n isgood = isgood .and. (nint(dtmp*1000000) .EQ. -2576545)\n dtmp = ext_thiem2d(0.3_dp, (/TGtestd, vartestd, corrtestd/), (/Reftestd, hreftestd, Qwtestd/))\n isgood = isgood .and. (nint(dtmp*1000000) .EQ. -1930433)\n dtmp = ext_thiem2d(0.2_dp, (/TGtestd,vartestd,corrtestd/), (/Reftestd,hreftestd,Qwtestd/),1.0_dp)\n isgood = isgood .and. (nint(dtmp*1000000) .EQ. -2565305)\n dtmp = ext_thiem2d(0.3_dp, (/TGtestd,vartestd,corrtestd/), (/Reftestd,hreftestd,Qwtestd/),1.0_dp)\n isgood = isgood .and. (nint(dtmp*1000000) .EQ. -1919788)\n !sp\n write (*,*) 'ext_Thiem2d_sp(0.2)_std=', ext_thiem2d(0.2_sp, (/TGtest , vartest , corrtest /), &\n (/Reftest , hreftest , Qwtest /))\n write (*,*) 'ext_Thiem2d_sp(0.3)_std=', ext_thiem2d(0.3_sp, (/TGtest , vartest , corrtest /), &\n (/Reftest , hreftest , Qwtest /))\n !with optional inputs\n write (*,*) 'ext_Thiem2d_sp(0.2)_opt=', ext_thiem2d(0.2_sp,(/TGtest ,vartest ,corrtest /), &\n (/Reftest ,hreftest ,Qwtest /),1.0_sp)\n write (*,*) 'ext_Thiem2d_sp(0.3)_opt=', ext_thiem2d(0.3_sp,(/TGtest ,vartest ,corrtest /), &\n (/Reftest ,hreftest ,Qwtest /),1.0_sp)\n !dp\n write (*,*) 'ext_Thiem2d_dp(0.2)_std=', ext_thiem2d(0.2_dp, (/TGtestd, vartestd, corrtestd/), &\n (/Reftestd, hreftestd, Qwtestd/))\n write (*,*) 'ext_Thiem2d_dp(0.3)_std=', ext_thiem2d(0.3_dp, (/TGtestd, vartestd, corrtestd/), &\n (/Reftestd, hreftestd, Qwtestd/))\n !with optional inputs\n write (*,*) 'ext_Thiem2d_dp(0.2)_opt=', ext_thiem2d(0.2_dp,(/TGtestd,vartestd,corrtestd/), &\n (/Reftestd,hreftestd,Qwtestd/),1.0_dp)\n write (*,*) 'ext_Thiem2d_dp(0.3)_opt=', ext_thiem2d(0.3_dp,(/TGtestd,vartestd,corrtestd/), &\n (/Reftestd,hreftestd,Qwtestd/),1.0_dp)\n\n write (*,*) ' '\n\n write (*,*) \"THEIS' SOLUTION\"\n write (*,*) '-------------------------------------------------------------------------'\n\n ! Theissp(r=.2,t=.0) = 0.00000000\n ! Theissp(r=.2,t=.1) = -0.174579859\n ! Theissp(r=.3,t=.2) = -0.142127588\n ! Theissp(r=.3,t=.3) = -0.270834625\n ! Theisdp(r=.2,t=.0) = 0.0000000000000000\n ! Theisdp(r=.2,t=.1) = -0.17458018796997515\n ! Theisdp(r=.3,t=.2) = -0.14212753460648780\n ! Theisdp(r=.3,t=.3) = -0.27083461355368116\n\n stmp = theis(0.2_sp, 0.0_sp, (/Stest , Ktest /), (/Qwtest , Ltest /) )\n isgood = isgood .and. (nint(stmp*1000) .EQ. 0)\n stmp = theis(0.2_sp, 0.1_sp, (/Stest , Ktest /), (/Qwtest , Ltest /) )\n isgood = isgood .and. (nint(stmp*1000) .EQ. -175)\n stmp = theis(0.3_sp, 0.2_sp, (/Stest , Ktest /), (/Qwtest , Ltest /) )\n isgood = isgood .and. (nint(stmp*1000) .EQ. -142)\n stmp = theis(0.3_sp, 0.3_sp, (/Stest , Ktest /), (/Qwtest , Ltest /) )\n isgood = isgood .and. (nint(stmp*1000) .EQ. -271)\n dtmp = theis(0.2_dp, 0.0_dp, (/Stestd, Ktestd/), (/Qwtestd, Ltestd/) )\n isgood = isgood .and. (nint(dtmp*1000000) .EQ. 0)\n dtmp = theis(0.2_dp, 0.1_dp, (/Stestd, Ktestd/), (/Qwtestd, Ltestd/) )\n isgood = isgood .and. (nint(dtmp*1000000) .EQ. -174580)\n dtmp = theis(0.3_dp, 0.2_dp, (/Stestd, Ktestd/), (/Qwtestd, Ltestd/) )\n isgood = isgood .and. (nint(dtmp*1000000) .EQ. -142128)\n dtmp = theis(0.3_dp, 0.3_dp, (/Stestd, Ktestd/), (/Qwtestd, Ltestd/) )\n isgood = isgood .and. (nint(dtmp*1000000) .EQ. -270835)\n !sp\n write (*,*) 'Theissp(r=.2,t=.0) =', theis(0.2_sp, 0.0_sp, (/Stest , Ktest /), (/Qwtest , Ltest /) )\n write (*,*) 'Theissp(r=.2,t=.1) =', theis(0.2_sp, 0.1_sp, (/Stest , Ktest /), (/Qwtest , Ltest /) )\n write (*,*) 'Theissp(r=.3,t=.2) =', theis(0.3_sp, 0.2_sp, (/Stest , Ktest /), (/Qwtest , Ltest /) )\n write (*,*) 'Theissp(r=.3,t=.3) =', theis(0.3_sp, 0.3_sp, (/Stest , Ktest /), (/Qwtest , Ltest /) )\n !dp\n write (*,*) 'Theisdp(r=.2,t=.0) =', theis(0.2_dp, 0.0_dp, (/Stestd, Ktestd/), (/Qwtestd, Ltestd/) )\n write (*,*) 'Theisdp(r=.2,t=.1) =', theis(0.2_dp, 0.1_dp, (/Stestd, Ktestd/), (/Qwtestd, Ltestd/) )\n write (*,*) 'Theisdp(r=.3,t=.2) =', theis(0.3_dp, 0.2_dp, (/Stestd, Ktestd/), (/Qwtestd, Ltestd/) )\n write (*,*) 'Theisdp(r=.3,t=.3) =', theis(0.3_dp, 0.3_dp, (/Stestd, Ktestd/), (/Qwtestd, Ltestd/) )\n\n write (*,*) ' '\n\n write (*,*) \"EXTENDED THEIS' SOLUTION IN 2D\"\n write (*,*) '-------------------------------------------------------------------------'\n\n ! ext_theis2d_dp_vec(r= 1 ,t= 50 ) = -2.6724678924208556\n ! ext_theis2d_dp_vec(r= 1 ,t= 100 ) = -3.4409275281733089\n ! ext_theis2d_dp_vec(r= 1 ,t= 1000 ) = -5.7384083577267218\n ! ext_theis2d_dp_vec(r= 2 ,t= 50 ) = -1.2250879935634749\n ! ext_theis2d_dp_vec(r= 2 ,t= 100 ) = -1.8423690881291142\n ! ext_theis2d_dp_vec(r= 2 ,t= 1000 ) = -4.0012094551152613\n ! ext_theis2d_dp_vec(r= 3 ,t= 50 ) = -0.60506500331545221\n ! ext_theis2d_dp_vec(r= 3 ,t= 100 ) = -1.0950539046041157\n ! ext_theis2d_dp_vec(r= 3 ,t= 1000 ) = -3.0545777884298797\n\n fpoints_dp = ext_theis2d(&\n rad = (/1._dp,2._dp,3._dp/),&\n time = (/50.0_dp,100.0_dp,1000.0_dp/),&\n params = (/TGtestd, vartestd, corrtestd, Stestd/),&\n inits = (/Qwtestd/))\n\n do m=1_i4,3_i4\n do n=1_i4,3_i4\n fpoints2_dp(m,n) = ext_theis2d(&\n rad = real(m,dp),&\n time = real(425_i4*n**2_i4-1225_i4*n+850_i4,dp),& !polynomial with p(1)=50 p(2)=100 p(3)=1000\n params = (/TGtestd, vartestd, corrtestd, Stestd/),&\n inits = (/Qwtestd/))\n end do\n end do\n\n fpoints3_dp = reshape(&\n ext_theis2d(&\n grid = grid_dp,&\n params = (/TGtestd, vartestd, corrtestd, Stestd/),&\n inits = (/Qwtestd/)),(/3,3/))\n\n\n do m=1_i4,3_i4\n do n=1_i4,3_i4\n isgood = isgood .and. eq(fpoints_dp(m,n),fpoints2_dp(m,n))\n isgood = isgood .and. eq(fpoints_dp(m,n),fpoints3_dp(m,n))\n end do\n end do\n\n dtmp = fpoints_dp(1,1)\n isgood = isgood .and. (nint(dtmp*1000000) .eq. -2672468)\n dtmp = fpoints_dp(1,2)\n isgood = isgood .and. (nint(dtmp*1000000) .eq. -3440928)\n dtmp = fpoints_dp(1,3)\n isgood = isgood .and. (nint(dtmp*1000000) .eq. -5738408)\n dtmp = fpoints_dp(2,1)\n isgood = isgood .and. (nint(dtmp*1000000) .eq. -1225088)\n dtmp = fpoints_dp(2,2)\n isgood = isgood .and. (nint(dtmp*1000000) .eq. -1842369)\n dtmp = fpoints_dp(2,3)\n isgood = isgood .and. (nint(dtmp*1000000) .eq. -4001209)\n dtmp = fpoints_dp(3,1)\n isgood = isgood .and. (nint(dtmp*1000000) .eq. -605065)\n dtmp = fpoints_dp(3,2)\n isgood = isgood .and. (nint(dtmp*1000000) .eq. -1095054)\n dtmp = fpoints_dp(3,3)\n isgood = isgood .and. (nint(dtmp*1000000) .eq. -3054578)\n\n do m=1_i4,3_i4\n do n=1_i4,3_i4\n write(*,*) \"ext_theis2d_dp_vec(r=\",m,\",t=\",425_i4*n**2_i4-1225_i4*n+850_i4,\") = \", fpoints_dp(m,n)\n write(*,*) \"ext_theis2d_dp_sgl(r=\",m,\",t=\",425_i4*n**2_i4-1225_i4*n+850_i4,\") = \", fpoints2_dp(m,n)\n write(*,*) \"ext_theis2d_dp_gri(r=\",m,\",t=\",425_i4*n**2_i4-1225_i4*n+850_i4,\") = \", fpoints3_dp(m,n)\n end do\n end do\n\n !### sp #########################################################################\n ! ext_theis2d_sp_vec(r= 1 ,t= 50 ) = -2.67246795\n ! ext_theis2d_sp_vec(r= 1 ,t= 100 ) = -3.44092774\n ! ext_theis2d_sp_vec(r= 1 ,t= 1000 ) = -5.73840857\n ! ext_theis2d_sp_vec(r= 2 ,t= 50 ) = -1.22508800\n ! ext_theis2d_sp_vec(r= 2 ,t= 100 ) = -1.84236920\n ! ext_theis2d_sp_vec(r= 2 ,t= 1000 ) = -4.00120974\n ! ext_theis2d_sp_vec(r= 3 ,t= 50 ) = -0.605064988\n ! ext_theis2d_sp_vec(r= 3 ,t= 100 ) = -1.09505391\n ! ext_theis2d_sp_vec(r= 3 ,t= 1000 ) = -3.05457783\n\n fpoints_sp = ext_theis2d(&\n rad = (/1._sp,2._sp,3._sp/),&\n time = (/50.0_sp,100.0_sp,1000.0_sp/),&\n params = (/TGtest, vartest, corrtest, Stest/),&\n inits = (/Qwtest/))\n\n do m=1_i4,3_i4\n do n=1_i4,3_i4\n fpoints2_sp(m,n) = ext_theis2d(&\n rad = real(m,sp),&\n time = real(425_i4*n**2_i4-1225_i4*n+850_i4,sp),& !polynomial with p(1)=50 p(2)=100 p(3)=1000\n params = (/TGtest, vartest, corrtest, Stest/),&\n inits = (/Qwtest/))\n end do\n end do\n\n fpoints3_sp = reshape(&\n ext_theis2d(&\n grid = grid_sp,&\n params = (/TGtest, vartest, corrtest, Stest/),&\n inits = (/Qwtest/)),(/3,3/))\n\n do m=1_i4,3_i4\n do n=1_i4,3_i4\n isgood = isgood .and. eq(fpoints_sp(m,n),fpoints2_sp(m,n))\n isgood = isgood .and. eq(fpoints_sp(m,n),fpoints3_sp(m,n))\n end do\n end do\n\n stmp = fpoints_sp(1,1)\n isgood = isgood .and. (nint(stmp*1000) .eq. -2672)\n stmp = fpoints_sp(1,2)\n isgood = isgood .and. (nint(stmp*1000) .eq. -3441)\n stmp = fpoints_sp(1,3)\n isgood = isgood .and. (nint(stmp*1000) .eq. -5738)\n stmp = fpoints_sp(2,1)\n isgood = isgood .and. (nint(stmp*1000) .eq. -1225)\n stmp = fpoints_sp(2,2)\n isgood = isgood .and. (nint(stmp*1000) .eq. -1842)\n stmp = fpoints_sp(2,3)\n isgood = isgood .and. (nint(stmp*1000) .eq. -4001)\n stmp = fpoints_sp(3,1)\n isgood = isgood .and. (nint(stmp*1000) .eq. - 605)\n stmp = fpoints_sp(3,2)\n isgood = isgood .and. (nint(stmp*1000) .eq. -1095)\n stmp = fpoints_sp(3,3)\n isgood = isgood .and. (nint(stmp*1000) .eq. -3055)\n\n do m=1_i4,3_i4\n do n=1_i4,3_i4\n write(*,*) \"ext_theis2d_sp_vec(r=\",m,\",t=\",425_i4*n**2_i4-1225_i4*n+850_i4,\") = \", fpoints_sp(m,n)\n write(*,*) \"ext_theis2d_sp_sgl(r=\",m,\",t=\",425_i4*n**2_i4-1225_i4*n+850_i4,\") = \", fpoints2_sp(m,n)\n write(*,*) \"ext_theis2d_sp_gri(r=\",m,\",t=\",425_i4*n**2_i4-1225_i4*n+850_i4,\") = \", fpoints3_sp(m,n)\n end do\n end do\n\n\n write (*,*) ' '\n\n write (*,*) \"EXTENDED THEIS' SOLUTION IN 3D\"\n write (*,*) '-------------------------------------------------------------------------'\n\n ! ext_theis3d_dp_vec(r= 1 ,t= 50 ) = -2.6719739969853862\n ! ext_theis3d_dp_vec(r= 1 ,t= 100 ) = -3.4114799964304905\n ! ext_theis3d_dp_vec(r= 1 ,t= 1000 ) = -5.4641666480313242\n ! ext_theis3d_dp_vec(r= 2 ,t= 50 ) = -1.2452670522580507\n ! ext_theis3d_dp_vec(r= 2 ,t= 100 ) = -1.8293707976344475\n ! ext_theis3d_dp_vec(r= 2 ,t= 1000 ) = -3.7458081837503667\n ! ext_theis3d_dp_vec(r= 3 ,t= 50 ) = -0.64353916624054508\n ! ext_theis3d_dp_vec(r= 3 ,t= 100 ) = -1.1069066253083155\n ! ext_theis3d_dp_vec(r= 3 ,t= 1000 ) = -2.8268598328483159\n\n fpoints_dp = ext_theis3d(&\n rad = (/1._dp,2._dp,3._dp/),&\n time = (/50.0_dp,100.0_dp,1000.0_dp/),&\n params = (/Ktestd, vartestd, corrtestd, Stestd, anisotestd/),&\n inits = (/Qwtestd, Ltestd/))\n\n do m=1_i4,3_i4\n do n=1_i4,3_i4\n fpoints2_dp(m,n) = ext_theis3d(&\n rad = real(m,dp),&\n time = real(425_i4*n**2_i4-1225_i4*n+850_i4,dp),& !polynomial with p(1)=50 p(2)=100 p(3)=1000\n params = (/Ktestd, vartestd, corrtestd, Stestd, anisotestd/),&\n inits = (/Qwtestd, Ltestd/))\n end do\n end do\n\n fpoints3_dp = reshape(&\n ext_theis3d(&\n grid = grid_dp,&\n params = (/Ktestd, vartestd, corrtestd, Stestd, anisotestd/),&\n inits = (/Qwtestd, Ltestd/)),(/3,3/))\n\n do m=1_i4,3_i4\n do n=1_i4,3_i4\n isgood = isgood .and. eq(fpoints_dp(m,n), fpoints2_dp(m,n))\n isgood = isgood .and. eq(fpoints_dp(m,n), fpoints3_dp(m,n))\n end do\n end do\n\n dtmp = fpoints_dp(1,1)\n isgood = isgood .and. (nint(dtmp*1000000) .eq. -2671974)\n dtmp = fpoints_dp(1,2)\n isgood = isgood .and. (nint(dtmp*1000000) .eq. -3411480)\n dtmp = fpoints_dp(1,3)\n isgood = isgood .and. (nint(dtmp*1000000) .eq. -5464167)\n dtmp = fpoints_dp(2,1)\n isgood = isgood .and. (nint(dtmp*1000000) .eq. -1245267)\n dtmp = fpoints_dp(2,2)\n isgood = isgood .and. (nint(dtmp*1000000) .eq. -1829371)\n dtmp = fpoints_dp(2,3)\n isgood = isgood .and. (nint(dtmp*1000000) .eq. -3745808)\n dtmp = fpoints_dp(3,1)\n isgood = isgood .and. (nint(dtmp*1000000) .eq. -643539)\n dtmp = fpoints_dp(3,2)\n isgood = isgood .and. (nint(dtmp*1000000) .eq. -1106907)\n dtmp = fpoints_dp(3,3)\n isgood = isgood .and. (nint(dtmp*1000000) .eq. -2826860)\n\n do m=1_i4,3_i4\n do n=1_i4,3_i4\n write(*,*) \"ext_theis3d_dp_vec(r=\",m,\",t=\",425_i4*n**2_i4-1225_i4*n+850_i4,\") = \", fpoints_dp(m,n)\n write(*,*) \"ext_theis3d_dp_sgl(r=\",m,\",t=\",425_i4*n**2_i4-1225_i4*n+850_i4,\") = \", fpoints2_dp(m,n)\n write(*,*) \"ext_theis3d_dp_gri(r=\",m,\",t=\",425_i4*n**2_i4-1225_i4*n+850_i4,\") = \", fpoints3_dp(m,n)\n end do\n end do\n\n ! ext_theis3d_sp_vec(r= 1 ,t= 50 ) = -2.67197418\n ! ext_theis3d_sp_vec(r= 1 ,t= 100 ) = -3.41148019\n ! ext_theis3d_sp_vec(r= 1 ,t= 1000 ) = -5.46416712\n ! ext_theis3d_sp_vec(r= 2 ,t= 50 ) = -1.24526703\n ! ext_theis3d_sp_vec(r= 2 ,t= 100 ) = -1.82937086\n ! ext_theis3d_sp_vec(r= 2 ,t= 1000 ) = -3.74580836\n ! ext_theis3d_sp_vec(r= 3 ,t= 50 ) = -0.643539190\n ! ext_theis3d_sp_vec(r= 3 ,t= 100 ) = -1.10690665\n ! ext_theis3d_sp_vec(r= 3 ,t= 1000 ) = -2.82685995\n\n fpoints_sp = ext_theis3d(&\n rad = (/1._sp,2._sp,3._sp/),&\n time = (/50.0_sp,100.0_sp,1000.0_sp/),&\n params = (/Ktest, vartest, corrtest, Stest, anisotest/),&\n inits = (/Qwtest, Ltest/))\n\n do m=1_i4,3_i4\n do n=1_i4,3_i4\n fpoints2_sp(m,n) = ext_theis3d(&\n rad = real(m,sp),&\n time = real(425_i4*n**2_i4-1225_i4*n+850_i4,sp),& !polynomial with p(1)=50 p(2)=100 p(3)=1000\n params = (/Ktest, vartest, corrtest, Stest, anisotest/),&\n inits = (/Qwtest, Ltest/))\n end do\n end do\n\n fpoints3_sp = reshape(&\n ext_theis3d(&\n grid = grid_sp,&\n params = (/Ktest, vartest, corrtest, Stest, anisotest/),&\n inits = (/Qwtest, Ltest/)),(/3,3/))\n\n do m=1_i4,3_i4\n do n=1_i4,3_i4\n isgood = isgood .and. eq(fpoints_sp(m,n), fpoints2_sp(m,n))\n isgood = isgood .and. eq(fpoints_sp(m,n), fpoints3_sp(m,n))\n end do\n end do\n\n stmp = fpoints_sp(1,1)\n isgood = isgood .and. (nint(stmp*1000) .eq. -2672)\n stmp = fpoints_sp(1,2)\n isgood = isgood .and. (nint(stmp*1000) .eq. -3411)\n stmp = fpoints_sp(1,3)\n isgood = isgood .and. (nint(stmp*1000) .eq. -5464)\n stmp = fpoints_sp(2,1)\n isgood = isgood .and. (nint(stmp*1000) .eq. -1245)\n stmp = fpoints_sp(2,2)\n isgood = isgood .and. (nint(stmp*1000) .eq. -1829)\n stmp = fpoints_sp(2,3)\n isgood = isgood .and. (nint(stmp*1000) .eq. -3746)\n stmp = fpoints_sp(3,1)\n isgood = isgood .and. (nint(stmp*1000) .eq. -644)\n stmp = fpoints_sp(3,2)\n isgood = isgood .and. (nint(stmp*1000) .eq. -1107)\n stmp = fpoints_sp(3,3)\n isgood = isgood .and. (nint(stmp*1000) .eq. -2827)\n\n do m=1_i4,3_i4\n do n=1_i4,3_i4\n write(*,*) \"ext_theis3d_sp_vec(r=\",m,\",t=\",425_i4*n**2_i4-1225_i4*n+850_i4,\") = \", fpoints_sp(m,n)\n write(*,*) \"ext_theis3d_sp_sgl(r=\",m,\",t=\",425_i4*n**2_i4-1225_i4*n+850_i4,\") = \", fpoints2_sp(m,n)\n write(*,*) \"ext_theis3d_sp_gri(r=\",m,\",t=\",425_i4*n**2_i4-1225_i4*n+850_i4,\") = \", fpoints3_sp(m,n)\n end do\n end do\n\n\n write (*,*) ' '\n\n write (*,*) '-------------------------------------------------------------------------'\n write (*,*) '-------------------------------------------------------------------------'\n if (isgood) then\n write(*,*) 'mo_pumpingtests ', color('o.k.', c_green)\n else\n write(*,*) 'mo_pumpingtests ', color('failed', c_red)\n endif\n\nend program test\n", "meta": {"hexsha": "850eaaca7fb19a01fc174945fbc575a6dfa5043c", "size": 25105, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/test_mo_pumpingtests/main.f90", "max_stars_repo_name": "mcuntz/jams_fortran", "max_stars_repo_head_hexsha": "a1dcab78eda21f930aa6c8c3633598a522f01659", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2020-02-28T00:14:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-20T23:32:41.000Z", "max_issues_repo_path": "test/test_mo_pumpingtests/main.f90", "max_issues_repo_name": "mcuntz/jams_fortran", "max_issues_repo_head_hexsha": "a1dcab78eda21f930aa6c8c3633598a522f01659", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-05-09T15:33:11.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-28T16:16:09.000Z", "max_forks_repo_path": "test/test_mo_pumpingtests/main.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": 45.5626134301, "max_line_length": 112, "alphanum_fraction": 0.5355905198, "num_tokens": 10657, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245828938678, "lm_q2_score": 0.8311430415844384, "lm_q1q2_score": 0.6926119284534927}} {"text": " module MOD_DTDR\r\n contains\r\nC********** MODULNAME: DTDR ******* 01/06/87 20.29.23.****** 82 KARTEN\r\nc*** this version was for the IMSL routine IPERK\r\nc SUBROUTINE DTDR(N,R,T,TPRIME)\r\nc*** present version for the numerical recipes routines\r\n SUBROUTINE DTDR(R,T,TPRIME)\r\nC*******************************************************************************\r\nC*** THIS SUBROUTINE HELPS TO CALCULATE THE TEMPERATURE STRUCTURE OF A\r\nC*** SPHERICAL, GREY ATMOSPHERE.\r\nC*** IT IS A FORMAL PARAMETER OF THE IMSL-ROUTINE \"IVPRK\"(DVERK) AND CALLED \r\nC*** ONLY FROM THERE.\r\nC*** THE DIFFERENTIAL EQUATION IS WRITTEN: Y' = F(X,Y)\r\nC*** HERE: DT/DR = FUNCTION OF (R,T)\r\nC*** THE EDDINGTON FACTOR F IS ASSUMED TO BE 1/3 INSIDE THE RADIUS R1, I.E.\r\nC*** WHERE TAU=1.\r\nC*** OUTSIDE THE RADIUS R13, I.E. WHERE TAU=1/3, WE ASSUME GEOMETRICAL DILUTION\r\nC*** DILUTION OF THE RADIATION FIELD AS FOR A UNIFORM RADIATING SPHERE\r\nC*** OF RADIUS R23\r\nC*** F IS INTERPOLATED IN THE INTERJACENT REGION\r\nC*******************************************************************************\r\n\r\n IMPLICIT REAL*8(A-H,O-Z)\r\n \r\n PARAMETER ( ONE = 1.D+0, TWO = 2.D+0, THREE = 3.D+0 )\r\n \r\n COMMON /COMTEFF/ TEFF,TMIN,TMODIFY,SPHERIC\r\nC*** OPAROSS FROM SUBROUTINE GREY\r\n COMMON /COMDTDR/ OPAMEAN,R23COM,R1COM,R13COM\r\n \r\n IF (R .LE. R1 COM) THEN\r\nC*** OPTICALLY THICK REGION\r\n FEDDI=.33333333333333\r\n BFAC=0.\r\n ELSE IF (R .LT. R13COM) THEN\r\nC*** INTERPOLATED REGION AROUND R23, I.E. BETWEEN TAU=1/3 AND TAU=1\r\nC*** F1 = FEDDI AT R1\r\n F1=0.333333333333\r\nC*** F2 = FEDDI AT R13\r\n R2=R13COM*R13COM\r\n SMUE=SQRT(ONE-R23COM*R23COM/R2)\r\n F2=((SMUE+ONE)*SMUE+ONE)/THREE\r\nC*** F3 = FPRIME AT R1\r\n F3=0.\r\nC*** F4 = FPRIME AT R13\r\n F4=(TWO+ONE/SMUE)*R23COM*R23COM/R2/R13COM/THREE\r\nC*** POLYNOMIAL COEFFICIENTS, SEE SUBROUTINE CUBIC\r\n D1=ONE/(R13COM-R1COM)\r\n D2=D1*D1\r\n D3=D1*D2\r\n D23=D2/THREE\r\n H11=D3\r\n H12=-D3\r\n H13=D23\r\n H14=TWO*D23\r\n H21=-D1\r\n H22=TWO*D1\r\n H23=-0.333333333333333D0\r\n H24=-0.666666666666666D0\r\n H31=-D3\r\n H32=D3\r\n H33=-TWO*D23\r\n H34=-D23\r\n H41=TWO*D1\r\n H42=-D1\r\n H43=0.666666666666666D0\r\n H44=0.333333333333333D0\r\nC*** CALCULATE POLYNOMIAL COEFFICIENTS: P(VECTOR) = H(MATRIX) * F(VECTOR)\r\n P1=H11*F1+H12*F2+H13*F3+H14*F4\r\n P2=H21*F1+H22*F2+H23*F3+H24*F4\r\n P3=H31*F1+H32*F2+H33*F3+H34*F4\r\n P4=H41*F1+H42*F2+H43*F3+H44*F4\r\nC*** EVALUATION OF THE POLYNOMIAL\r\n FEDDI=P1*(R-R1COM)**3 + P2*(R-R1COM)\r\n + +P3*(R13COM-R)**3+P4*(R13COM-R)\r\nC*** ... AND ITS DERIVATIVE\r\n FPRIME=THREE*P1*(R-R1COM)**2 + P2\r\n - -THREE*P3*(R13COM-R)**2-P4\r\n BFAC=(THREE*FEDDI-ONE)/R+FPRIME\r\n ELSE\r\n R2=R*R\r\n SMUE=SQRT(ONE-R23COM*R23COM/R2)\r\n FEDDI=((SMUE+ONE)*SMUE+ONE)/THREE\r\n FPRIME=(TWO+ONE/SMUE)*R23COM*R23COM/R2/R/THREE\r\n BFAC=(THREE*FEDDI-ONE)/R+FPRIME\r\n ENDIF\r\n TT=TEFF/T\r\n TT3=TT*TT*TT\r\n TPRIME=-BFAC*T/4./FEDDI-OPAMEAN/R/R*TEFF/16./FEDDI*TT3\r\n RETURN\r\n END subroutine\r\n end module\r\n", "meta": {"hexsha": "adf55f3bae1b8044d7125c2cbc8074a12af3ffa3", "size": 3216, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/dtdr.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/dtdr.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/dtdr.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": 34.5806451613, "max_line_length": 81, "alphanum_fraction": 0.5581467662, "num_tokens": 1267, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810525948928, "lm_q2_score": 0.7310585844894971, "lm_q1q2_score": 0.6925910512821921}} {"text": " subroutine cauchy_ppart2(x,nx,xres,fx,pint)\n\t\n! -----------------------------------------------\n! Returns principal part of int(x,fx/(x-xres))\n! -----------------------------------------------\n\n implicit none\n integer, parameter :: idebug = 0\n\n integer nx\n real xres \n real x(nx), fx(nx)\n real pint\n! ---------------\n! local variables\n! ---------------\n logical, parameter :: use_linear = .true.\n\n integer :: i\n real, dimension(nx-1) :: va0,va1,va2\n real :: a0,a1,a2, x1,x2,x3, f1,f2,f3\n real :: tmp1,tmp2, d1,d2,d3, d31,d21\n real :: value0,value1,value2, xleft,xright\n real :: v0,v1,v2\n intrinsic :: log\n\n\n! ------------------------------------------------------------\n! compute piecewise quadratic over \n! [x(i-1), x(i), x(i+1)] as a0 + a1*(x-xres)+ a2*(x-xres)^2\n!\n! assume xres is not exactly one of x(1:n)\n! ------------------------------------------------------------\n do i=2,nx-1\n x1 = x(i-1)\n x2 = x(i)\n x3 = x(i+1)\n f1 = fx(i-1)\n f2 = fx(i)\n f3 = fx(i+1)\n! --------------------------------------\n! find a0,a1,a2 such that\n!\n! a0 + a1*(x1-xres) + a2*(x1-xres)^2 = f1\n! a0 + a1*(x2-xres) + a2*(x2-xres)^2 = f2\n! a0 + a1*(x3-xres) + a2*(x3-xres)^2 = f3\n! --------------------------------------\n d1 = x1-xres\n d2 = x2-xres\n d3 = x3-xres\n d31 = (d3-d1)*(d3+d1)\n d21 = (d2-d1)*(d2+d1)\n! ----------------------------------\n! a1 * ( d3-d1 ) + a2*( d31 ) = f3-f1\n! a1 * ( d2-d1 ) + a2*( d21 ) = f2-f1\n! -----------------------------------\n tmp1 = ((f3-f1)*(d2-d1) - (f2-f1)*(d3-d1))\n tmp2 = ( d31*(d2-d1) - d21*(d3-d1) )\n\n a2 = tmp1/tmp2\n a1 = ((f3-f1) - a2*d31 )/(d3-d1)\n a0 = f1 - a2*d1*d1 - a1*d1\n\n va0(i) = a0\n va1(i) = a1\n va2(i) = a2\n enddo\n\n! --------------------------------------------\n! special handling for first interval\n! --------------------------------------------\n if (use_linear) then\n! ------------------------------\n! backward compatible with df_dv\n!\n! a0 + a1*(x1-xres) = f1\n! a0 + a1*(x2-xres) = f2\n! ------------------------------\n x1 = x(1)\n x2 = x(2)\n f1 = fx(1)\n f2 = fx(2)\n\n a1 = (f2-f1)/(x2-x1)\n a0 = f1 - a1*(x1-xres)\n a2 = 0.0\n\n va0(1) = a0\n va1(1) = a1\n va2(1) = a2\n else\n! ------------------------------------\n! use quadratic even in first interval\n! ------------------------------------\n va0(1) = va0(2)\n va1(1) = va1(2)\n va2(1) = va2(2)\n\n endif\n\n if (idebug.ge.1) then\n do i=1,nx-1\n write(*,*) 'i,a0,a1,a2 ',i,va0(i),va1(i),va2(i)\n enddo\n endif\n\n\n! ----------------------------------------------\n! sum contribtions from a0\n!\n! int( 1/(x-xres), x=xleft..xright ) = log( (xright-xres)/(xleft-xres) )\n!\n! sum contributions from a1\n!\n! int( a1, x=xleft..xright) = (xright-xleft)*a1\n!\n! sum contributions from a2\n!\n! int( a2*(x-xres), x=xleft..xright) = \n! = (a2/2) * ( (xright-xres)**2 - (xleft-xres)**2)\n! = (a2/2) * ( (xright+xleft - 2*xres) * (xright-xleft) )\n! ----------------------------------------------\n value0 = 0.0d0\n value1 = 0.0d0\n value2 = 0.0d0\n\n do i=1,nx-1\n a0 = va0(i)\n a1 = va1(i)\n a2 = va2(i)\n\n xleft = x(i)\n xright = x(i+1)\n\n v0 = a0*log( abs( (xright-xres)/(xleft-xres) ) )\n v1 = a1*(xright-xleft)\n v2 = a2*(xright+xleft-2.0d0*xres)*(xright-xleft)\n\n value0 = value0 + v0\n value1 = value1 + v1\n value2 = value2 + v2\n\n if (idebug.ge.1) then\n write(*,*) 'i,v0,v1,v2 ',i,v0,v1,v2\n endif\n\n enddo \n value2 = value2*0.5d0\n\n\n pint = value0 + value1 + value2\n \n return\n end subroutine cauchy_ppart2\n\t\n\t\n!\n!*************************************************************************\n!\n\n\n subroutine cauchy_ppart6(x,nx,xres,nfx,fx,pint,is_uniform)\n! -----------------------------------------------\n! Returns principal part of int(x,fx/(x-xres))\n! -----------------------------------------------\n implicit none\n integer, parameter :: idebug = 0\n\n integer nx,nfx\n real*8 xres \n real*8 x(nx), fx(nx,nfx)\n real*8 pint(nfx)\n logical :: is_uniform\n! ---------------\n! local variables\n! ---------------\n\n integer :: i,j,ih,nlog\n real*8, dimension(nx) :: vx, vlogt\n real*8 :: a0,a1,a2, x1,x2,x3, f1,f2,f3\n real*8 :: tmp1,tmp2, d1,d2,d3, d31,d21\n real*8 :: d3md1, d2md1\n real*8, dimension(nfx) :: value0,value1,value2 \n real*8 :: xleft,xright\n real*8 :: v0,v1,v2\n real*8 :: xc,a,b\n\n intrinsic :: log,abs,mod\n\n logical, parameter ::use_approx = .false.\n\n\n logical, parameter :: use_pade = .true.\n \n real*8 :: h,t,dx,t2, logt\n real*8, parameter :: zero=0.0d0\n real*8, parameter :: one=1.0d0\n real*8, parameter :: two=2.0d0\n real*8, parameter :: three=3.0d0\n real*8, parameter :: four=4.0d0\n real*8, parameter :: five=5.0d0\n real*8, parameter :: six=6.0d0\n real*8, parameter :: seven=7.0d0\n real*8, parameter :: eight=8.0d0\n logical :: isok\n\n\n! ------------------------------------------------------------\n! compute piecewise quadratic over \n! [x(i-1), x(i), x(i+1)] as a0 + a1*(x-xres)+ a2*(x-xres)^2\n!\n! assume xres is not exactly one of x(1:n)\n! ------------------------------------------------------------\n\n value0 = zero\n value1 = zero\n value2 = zero\n pint = zero\n\n! ------------------\n! precompute the logs\n! ------------------\n nlog = (nx-1)/2\n do ih=1,nlog\n i = 2*ih\n x1 = x(i-1)\n x2 = x(i)\n x3 = x(i+1)\n vx(ih) = abs( (x3-xres)/(x1-xres) )\n enddo\n call vlog( vlogt, vx, nlog )\n \n\n if (is_uniform) then\n\n dx = (x(nx)-x(1))/dble(nx-1)\n h = dx\n\n\n \n do j=1,nfx\n do ih=1,nlog\n i = 2*ih\n\n x1 = x(i-1)\n x2 = x(i)\n x3 = x(i+1)\n\n d2 = x2-xres\n d1 = d2 - h\n d3 = d2 + h\n\n\n\n f1 = fx(i-1,j)\n f2 = fx(i,j)\n f3 = fx(i+1,j)\n\n \n! --------------------------------------\n! find a0,a1,a2 such that\n!\n! a0 + a1*(x1-xres) + a2*(x1-xres)^2 = f1\n! a0 + a1*(x2-xres) + a2*(x2-xres)^2 = f2\n! a0 + a1*(x3-xres) + a2*(x3-xres)^2 = f3\n!\n! a0 + a1*(x2-xres) + a2*(x2-xres)^2 = f2\n! a0 + a1*((x2-xres)-h) + a2*((x2-xres)-h)^2 = f1\n! a0 + a1*((x2-xres)+h) + a2*((x2-xres)+h)^2 = f3\n!\n! f2 + a1*h + a2*(h*h + 2*h*(x2-xres)) = f3\n! f2 - a1*h + a2*(h*h - 2*h*(x2-xres)) = f1\n! --------------------------------------\n\n\n\n! ---------------------\n! d31 = (d3-d1)*(d3+d1)\n! d21 = (d2-d1)*(d2+d1)\n!\n! a1 * ( d3-d1 ) + a2*( d31 ) = f3-f1\n! a1 * ( d2-d1 ) + a2*( d21 ) = f2-f1\n! -----------------------------------\n\n a2 = (f3-two*f2+f1)/(two*h*h)\n a1 = (f3-f1)/(two*h) - two*a2*d2\n a0 = f2 - (a1*d2 + a2*d2*d2)\n\n\n logt = vlogt(ih)\n value0(j) = value0(j) + a0*logt\n value1(j) = value1(j) + a1 \n value2(j) = value2(j) + a2*d2\n\n enddo\n enddo\n\n value1 = value1 * (two*h)\n value2 = value2 * (four*h)\n\n\n else\n\n\n \n do j=1,nfx\n do ih=1,nlog\n i = 2*ih\n x1 = x(i-1)\n x2 = x(i)\n x3 = x(i+1)\n\n\n \n! --------------------------------------\n! find a0,a1,a2 such that\n!\n! a0 + a1*(x1-xres) + a2*(x1-xres)^2 = f1\n! a0 + a1*(x2-xres) + a2*(x2-xres)^2 = f2\n! a0 + a1*(x3-xres) + a2*(x3-xres)^2 = f3\n! --------------------------------------\n d1 = x1-xres\n d2 = x2-xres\n d3 = x3-xres\n d31 = (d3-d1)*(d3+d1)\n d21 = (d2-d1)*(d2+d1)\n! ----------------------------------\n! a1 * ( d3-d1 ) + a2*( d31 ) = f3-f1\n! a1 * ( d2-d1 ) + a2*( d21 ) = f2-f1\n! -----------------------------------\n logt = log( abs( (x3-xres)/(x1-xres) ))\n\n f1 = fx(i-1,j)\n f2 = fx(i,j)\n f3 = fx(i+1,j)\n\n tmp1 = ((f3-f1)*(d2-d1) - (f2-f1)*(d3-d1))\n tmp2 = ( d31*(d2-d1) - d21*(d3-d1) )\n\n a2 = tmp1/tmp2\n a1 = ((f3-f1) - a2*d31 )/(d3-d1)\n a0 = f1 - a2*d1*d1 - a1*d1\n!\n! f(x) = a0 + a1*(x-xres) + a2*(x-xres)^2 \n!\n! int( f(x)/(x-xres), x=x1..x3 ) = \n! a0 * int( 1/(x-xres), x=x1..x3 ) + \n! a1 * int( 1, x=x1..x3)\n! a2 * int( (x-xres), x=x1..x3 )\n!\n\n logt = vlogt(ih)\n value0(j) = value0(j) + a0 * logt\n value1(j) = value1(j) + a1 * (x3-x1)\n value2(j) = value2(j) + a2 * (x3-x1)*((x3-xres)+(x1-xres))\n\n enddo\n\n enddo\n endif\n\n\n! ----------------------------------\n! do we have an odd number of intervals?\n! if so, need to account for last interval\n! ----------------------------------\n if (mod(nx,2).eq.0) then\n\n x1 = x(nx-2)\n x2 = x(nx-1)\n x3 = x(nx)\n\n d1 = x1-xres\n d2 = x2-xres\n d3 = x3-xres\n d31 = (d3-d1)*(d3+d1)\n d21 = (d2-d1)*(d2+d1)\n\n logt = log( abs( (x3-xres)/(x2-xres) ))\n\n do j=1,nfx\n\n f1 = fx(nx-2,j)\n f2 = fx(nx-1,j)\n f3 = fx(nx,j)\n\n \n! --------------------------------------\n! find a0,a1,a2 such that\n!\n! a0 + a1*(x1-xres) + a2*(x1-xres)^2 = f1\n! a0 + a1*(x2-xres) + a2*(x2-xres)^2 = f2\n! a0 + a1*(x3-xres) + a2*(x3-xres)^2 = f3\n! --------------------------------------\n! ----------------------------------\n! a1 * ( d3-d1 ) + a2*( d31 ) = f3-f1\n! a1 * ( d2-d1 ) + a2*( d21 ) = f2-f1\n! -----------------------------------\n tmp1 = ((f3-f1)*(d2-d1) - (f2-f1)*(d3-d1))\n tmp2 = ( d31*(d2-d1) - d21*(d3-d1) )\n\n a2 = tmp1/tmp2\n a1 = ((f3-f1) - a2*d31 )/(d3-d1)\n a0 = f1 - a2*d1*d1 - a1*d1\n!\n! f(x) = a0 + a1*(x-xres) + a2*(x-xres)^2 \n!\n! int( f(x)/(x-xres), x=x2..x3 ) = \n! a0 * int( 1/(x-xres), x=x2..x3 ) + \n! a1 * int( 1, x=x1..x3)\n! a2 * int( (x-xres), x=x2..x3 )\n!\n value1(j) = value1(j) + a1 * (x3-x2)\n value2(j) = value2(j) + a2 * (x3-x2)*(x3+x2-two*xres)\n value0(j) = value0(j) + a0 * logt\n enddo\n\n endif\n \n value2 = value2 / two\n pint = value0 + value1 + value2\n\n\n return\n\n end subroutine cauchy_ppart6\n\n\n\n", "meta": {"hexsha": "7bfa0231772feed45ef64d645985ce09e389293c", "size": 11722, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/cauchy_ppart.f90", "max_stars_repo_name": "ORNL-Fusion/aorsa", "max_stars_repo_head_hexsha": "82bab1e3b88e10e6bd5ca9b16589b11a97dd8f39", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2019-03-12T13:33:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-11T08:28:46.000Z", "max_issues_repo_path": "src/cauchy_ppart.f", "max_issues_repo_name": "ORNL-Fusion/aorsa3d", "max_issues_repo_head_hexsha": "c72ac3c209ed256c21e66a6075bf882f96f626c4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 29, "max_issues_repo_issues_event_min_datetime": "2020-01-24T15:58:55.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-28T15:16:05.000Z", "max_forks_repo_path": "src/cauchy_ppart.f", "max_forks_repo_name": "ORNL-Fusion/aorsa3d", "max_forks_repo_head_hexsha": "c72ac3c209ed256c21e66a6075bf882f96f626c4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-09-10T16:48:52.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-10T16:48:52.000Z", "avg_line_length": 27.2604651163, "max_line_length": 77, "alphanum_fraction": 0.3394471933, "num_tokens": 3934, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297941266014, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.6925796723224359}} {"text": "! An example of the diffusion equation.\nmodule diffusion\n\n implicit none\n\n ! Define the attributes of the model.\n type :: diffusion_model\n real :: dt\n real :: t\n real :: t_end\n\n integer :: n_x\n integer :: n_y\n\n real :: dx\n real :: dy\n\n real, pointer :: density(:,:)\n real, pointer :: density_tmp(:,:)\n end type diffusion_model\n\ncontains\n\n ! Initializes the model with values read from a file.\n subroutine initialize_from_file(model, config_file)\n character (len=*), intent (in) :: config_file\n type (diffusion_model), intent (out) :: model\n\n open(15, file=config_file)\n read(15, *) model%dt, model%t_end, model%n_x, model%n_y\n close(15)\n call initialize(model)\n end subroutine initialize_from_file\n\n ! Initializes the model with default hardcoded values.\n subroutine initialize_from_defaults(model)\n type (diffusion_model), intent (out) :: model\n\n model%dt = 1.\n model%t_end = 20.\n model%n_x = 10\n model%n_y = 20\n call initialize(model)\n end subroutine initialize_from_defaults\n\n ! Allocates memory and sets values for either initialization technique.\n subroutine initialize(model)\n type (diffusion_model), intent (inout) :: model\n\n model%t = 0.\n model%dx = 1.\n model%dy = 1.\n\n allocate(model%density(model%n_y, model%n_x))\n allocate(model%density_tmp(model%n_y, model%n_x))\n\n model%density = 0.\n model%density_tmp = 0.\n\n call set_boundary_conditions(model%density)\n call set_boundary_conditions(model%density_tmp)\n end subroutine initialize\n\n ! Sets boundary conditions on values array.\n subroutine set_boundary_conditions(z)\n implicit none\n real, dimension (:,:), intent (out) :: z\n integer :: i, top_x\n\n top_x = size(z, 2)-1\n\n do i = 0, top_x\n z(1,i+1) = 0.25*top_x**2 - (i - 0.5*top_x)**2\n end do\n end subroutine set_boundary_conditions\n\n ! Frees memory when program completes.\n subroutine cleanup(model)\n type (diffusion_model), intent (inout) :: model\n\n deallocate (model%density)\n deallocate (model%density_tmp)\n end subroutine cleanup\n\n ! Steps the diffusion model forward in time.\n subroutine advance_in_time(model)\n type (diffusion_model), intent (inout) :: model\n\n call solve_2d(model)\n model%density = model%density_tmp\n model%t = model%t + model%dt\n end subroutine advance_in_time\n\n ! The solver for the two-dimensional diffusion equation.\n subroutine solve_2d(model)\n type (diffusion_model), intent (inout) :: model\n\n real, parameter :: rho = 0.\n real :: dx2\n real :: dy2\n real :: dx2_dy2_rho\n real :: coef\n integer :: i, j\n\n dx2 = model%dx**2\n dy2 = model%dy**2\n dx2_dy2_rho = dx2 * dy2 * rho\n coef = model%dt / (2. * (dx2 + dy2))\n\n do i = 2, model%n_y-1\n do j = 2, model%n_x-1\n model%density_tmp(i,j) = coef * ( &\n dx2*(model%density(i-1,j) + model%density(i+1,j)) + &\n dy2*(model%density(i,j-1) + model%density(i,j+1)) - &\n dx2_dy2_rho )\n end do\n end do\n end subroutine solve_2d\n\n ! A helper routine for displaying model parameters.\n subroutine print_info(file_unit, model)\n type (diffusion_model), intent (in) :: model\n integer :: file_unit\n\n write(file_unit,\"(a10, i8)\") \"n_x:\", model%n_x\n write(file_unit,\"(a10, i8)\") \"n_y:\", model%n_y\n write(file_unit,\"(a10, f8.2)\") \"dx:\", model%dx\n write(file_unit,\"(a10, f8.2)\") \"dy:\", model%dy\n write(file_unit,\"(a10, f8.2)\") \"dt:\", model%dt\n write(file_unit,\"(a10, f8.2)\") \"t:\", model%t\n write(file_unit,\"(a10, f8.2)\") \"t_end:\", model%t_end\n end subroutine print_info\n\n ! A helper routine that prints the current state of the model.\n subroutine print_values(file_unit, model)\n type (diffusion_model), intent (in) :: model\n integer :: file_unit, i, j\n character(len=30) :: rowfmt\n\n write(rowfmt,'(a,i4,a)') '(', model%n_x, '(1x,f6.1))'\n do i = 1, model%n_y\n write(file_unit,fmt=rowfmt) model%density(i,:)\n end do\n end subroutine print_values\n\nend module diffusion\n", "meta": {"hexsha": "58898732d6c62c052414df52f4d589661bc07990", "size": 4053, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "diffusion/diffusion.f90", "max_stars_repo_name": "mdpiper/diffusion-f90", "max_stars_repo_head_hexsha": "b5153d82fedd7b0bfc5cf13d78a1e81a96e0b9ad", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "diffusion/diffusion.f90", "max_issues_repo_name": "mdpiper/diffusion-f90", "max_issues_repo_head_hexsha": "b5153d82fedd7b0bfc5cf13d78a1e81a96e0b9ad", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "diffusion/diffusion.f90", "max_forks_repo_name": "mdpiper/diffusion-f90", "max_forks_repo_head_hexsha": "b5153d82fedd7b0bfc5cf13d78a1e81a96e0b9ad", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-06-17T20:33:36.000Z", "max_forks_repo_forks_event_max_datetime": "2019-06-17T20:33:36.000Z", "avg_line_length": 27.5714285714, "max_line_length": 73, "alphanum_fraction": 0.6496422403, "num_tokens": 1176, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637648915616, "lm_q2_score": 0.8056321819811829, "lm_q1q2_score": 0.6925727946797474}} {"text": "module quadglobal\nuse mpmodule\nimplicit none\ninteger ndebug, ndigits, nerror, nquadl\nend module\n\nprogram tquadts\n\n! David H. Bailey 2002-11-05\n! This is the ARPREC Fortran-90 version.\n\n! This software is provided for research purposes only. \n! Commercial usage requires license agreement.\n\n! This work was supported by the Director, Office of Science, Division\n! of Mathematical, Information, and Computational Sciences of the\n! U.S. Department of Energy under contract number DE-AC03-76SF00098.\n\n! This program demonstrates the quadrature routine 'quadts', which employs\n! the tanh-sinh function. The function quadts is suitable to integrate\n! a function that is continuous, infinitely differentiable and integrable on a\n! finite open interval. It can also be used for certain integrals on\n! infinite intervals, by making a suitable change of variable -- see below.\n! While this routine is not quite as efficient as quadgs for functions that \n! are regular on a closed interval, it can be used for functions with an\n! integrable singularity at one or both of the endpoints.\n\n! The function(s) to be integrated is(are) defined in external function\n! subprogram(s) -- see the sample function subprograms below. The name(s) of\n! the function subprogram(s) must be included in appropriate type and external\n! statements in the main program.\n\n! Note that an integral of a function on an infinite interval can be\n! converted to an integral on a finite interval by means of a suitable\n! change of variable. Example (here the notation \"inf\" means infinity):\n\n! Int_0^inf f(t) dt = Int_0^1 f(t) dt + Int_1^inf f(t) dt\n! = Int_0^1 f(t) dt + Int_0^1 f(1/t)/t^2 dt\n\n! Inputs set in parameter statement below:\n! kdebug Debug level setting. Default = 2.\n! ndp Digits of precision. May not exceed mpipl in file mpmod90.f.\n! In some cases, ndp must be significantly greater than the desired\n! tolerance in the result-- see the examples below.\n! neps Log10 of the desired tolerance in the result (negative integer).\n! nq1 Max number of phases in quadrature routine; adding 1 increases\n! (possibly doubles) the number of accurate digits in the result,\n! but also roughly quadruples the run time. nq1 > 2.\n! XSL nq1 = m\n! nq2 Space parameter for wk and xk arrays in the calling program. By\n! default it is set to 8 * 2^nq1. Increase nq2 if directed by a \n! message produced in initqts. Note that the dimension of the\n! wk and xk arrays starts with -1, so the length of these arrays is\n! (nq2+2) * (mpwds+5) eight-byte words.\n\nuse mpmodule\nuse quadglobal\nimplicit none\ninteger i, kdebug, ndp, neps, nq1, nq2, n1\nparameter (kdebug = 2, ndp = 400, neps = -400, nq1 = 9, nq2 = 8 * 2 ** nq1)\ndouble precision dplog10q, d1, d2, second, tm0, tm1\ntype (mp_real) err, quadts, fun01, fun02, fun03, fun04, fun05, fun06, fun07, &\n fun08, fun09, fun10, fun11, fun12, fun13, fun14, fun15a, fun15b, &\n t1, t2, t3, t4, wk(-1:nq2), xk(-1:nq2), x1, x2\nexternal quadts, fun01, fun02, fun03, fun04, fun05, fun06, fun07, fun08, &\n fun09, fun10, fun11, fun12, fun13, fun14, fun15a, fun15b, second\n\ncall mpinit\nif (ndp > mpipl .or. nq1 < 2) stop\ncall mpsetprec (ndp)\nmpeps = mpreal (10.d0) ** neps\nmpoud = ndp\n\nndebug = kdebug\nndigits = ndp\nnerror = 0\nnquadl = nq1\nwrite (6, 1) ndigits, neps, nquadl\n1 format ('Quadts test'/'Digits =',i6,' Epsilon =',i6,' Quadlevel =',i6)\n\n! Initialize quadrature tables wk and xk (weights and abscissas).\n\ntm0 = second ()\ncall initqts (nq1, nq2, wk, xk)\ntm1 = second ()\nif (nerror > 0) stop\nwrite (6, 2) tm1 - tm0\n2 format ('Quadrature initialization completed: cpu time =',f12.6)\n\n! XSL\nwrite(*, *) 'nq1 = ', nq1, ' nq2 = ', nq2\n!\n\n! Begin quadrature tests.\n\nwrite (6, 11)\n11 format (/'Continuous functions on finite itervals:'//&\n 'Problem 1: Int_0^1 t*log(1+t) dt = 1/4')\nx1 = 0.d0\nx2 = 1.d0\ntm0 = second ()\nt1 = quadts (fun01, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\n3 format ('Quadrature completed: CPU time =',f12.6/'Result =')\ncall mpwrite (6, t1)\nt2 = 0.25d0\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n4 format ('Actual error =',f10.6,'x10^',i5)\n\nstop \n\nwrite (6, 12)\n12 format (/'Problem 2: Int_0^1 t^2*arctan(t) dt = (pi - 2 + 2*log(2))/12')\nx1 = 0.d0\nx2 = 1.d0\ntm0 = second ()\nt1 = quadts (fun02, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, t1)\nt2 = (mppic - 2.d0 + 2.d0 * mpl02) / 12.d0\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 13)\n13 format (/'Problem 3: Int_0^(pi/2) e^t*cos(t) dt = 1/2*(e^(pi/2) - 1)')\nx1 = 0.d0\nx2 = 0.5d0 * mppic\ntm0 = second ()\nt1 = quadts (fun03, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, t1)\nt2 = 0.5d0 * (exp (0.5d0 * mppic) - 1.d0)\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 14)\n14 format (/ &\n 'Problem 4: Int_0^1 arctan(sqrt(2+t^2))/((1+t^2)sqrt(2+t^2)) dt = 5*Pi^2/96')\nx1 = 0.d0\nx2 = 1.d0\ntm0 = second ()\nt1 = quadts (fun04, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, t1)\nt2 = 5.d0 * mppic**2 / 96.d0\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 15)\n15 format (/&\n 'Continuous functions on finite itervals, but non-diff at an endpoint'// &\n 'Problem 5: Int_0^1 sqrt(t)*log(t) dt = -4/9')\nx1 = 0.d0\nx2 = 1.d0\ntm0 = second ()\nt1 = quadts (fun05, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, t1)\nt2 = mpreal (-4.d0) / 9.d0\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 16)\n16 format (/'Problem 6: Int_0^1 sqrt(1-t^2) dt = pi/4')\nx1 = 0.d0\nx2 = 1.d0\ntm0 = second ()\nt1 = quadts (fun06, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, t1)\nt2 = 0.25d0 * mppic\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 17)\n17 format (/&\n 'Functions on finite intervals with integrable singularity at an endpoint.'//&\n 'Problem 7: Int_0^1 t/sqrt(1-t^2) dt = 1')\nx1 = 0.d0\nx2 = 1.d0\ntm0 = second ()\nt1 = quadts (fun07, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, t1)\nt2 = 1.d0\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 18)\n18 format (/'Problem 8: Int_0^1 log(t)^2 dt = 2')\nx1 = 0.d0\nx2 = 1.d0\ntm0 = second ()\nt1 = quadts (fun08, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, t1)\nt2 = 2.d0\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 19)\n19 format (/'Problem 9: Int_0^(pi/2) log(cos(t)) dt = -pi*log(2)/2')\nx1 = 0.d0\nx2 = 0.5d0 * mppic\ntm0 = second ()\nt1 = quadts (fun09, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, t1)\nt2 = -0.5d0 * mppic * mpl02\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 20)\n20 format (/'Problem 10: Int_0^(pi/2) sqrt(tan(t)) dt = pi*sqrt(2)/2')\nx1 = 0.d0\nx2 = 0.5d0 * mppic\ntm0 = second ()\nt1 = quadts (fun10, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, t1)\nt2 = 0.5d0 * mppic * sqrt (mpreal (2.d0))\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 21)\n21 format (/&\n 'Functions on an infinite interval (requiring a two-step solution'//&\n 'Problem 11: Int_0^inf 1/(1+t^2) dt = pi/2')\nx1 = 0.d0\nx2 = 1.d0\ntm0 = second ()\nt1 = quadts (fun11, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, t1)\nt2 = 0.5d0 * mppic\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 22)\n22 format (/'Problem 12: Int_0^inf e^(-t)/sqrt(t) dt = sqrt(pi)')\nx1 = 0.d0\nx2 = 1.d0\ntm0 = second ()\nt1 = quadts (fun12, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, t1)\nt2 = sqrt (mppic)\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 23)\n23 format (/'Problem 13: Int_0^inf e^(-t^2/2) dt = sqrt(pi/2)')\nx1 = 0.d0\nx2 = 1.d0\ntm0 = second ()\nt1 = quadts (fun13, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, t1)\nt2 = sqrt (0.5d0 * mppic)\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 24)\n24 format (/&\n 'Oscillatory functions on an infinite interval.'//&\n 'Problem 14: Int_0^inf e^(-t)*cos(t) dt = 1/2')\nx1 = 0.d0\nx2 = 1.d0\ntm0 = second ()\nt1 = quadts (fun14, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, t1)\nt2 = 0.5d0\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 25)\n25 format (/'Problem 15: Int_0^inf sin(t)/t = pi/2')\nx1 = 0.d0\nx2 = mppic\ntm0 = second ()\nt1 = quadts (fun15a, x1, x2, nq1, nq2, wk, xk)\nx2 = 1.d0 / mppic\nt2 = quadts (fun15b, x1, x2, nq1, nq2, wk, xk)\nt3 = t1 + 40320.d0 * t2 - 1.d0 / mppic + 2.d0 / mppic ** 3 &\n - 24.d0 / mppic ** 5 + 720.d0 / mppic ** 7\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\nt4 = 0.5d0 * mppic\ncall decmdq (t4 - t3, d1, n1)\nwrite (6, 4) d1, n1\nwrite (6, 26)\n26 format ('Prob 15 error may be 40,000 X higher than estimated error.')\n\nstop\nend\n\nfunction fun01 (t)\n\n! fun01(t) = t * log(1+t)\n\nuse mpmodule\nimplicit none\ntype (mp_real) fun01, t\n\nfun01 = t * log (1.d0 + t)\nreturn\nend\n\nfunction fun02 (t)\n\n! fun02(t) = t^2 * arctan(t)\n\nuse mpmodule\nimplicit none\ntype (mp_real) fun02, t\n\nfun02 = t ** 2 * atan (t)\nreturn\nend\n\nfunction fun03 (t)\n\n! fun03(t) = e^t * cos(t)\n\nuse mpmodule\nimplicit none\ntype (mp_real) fun03, t\n\nfun03 = exp(t) * cos(t)\nreturn\nend\n\nfunction fun04 (t)\n\n! fun04(t) = arctan(sqrt(2+t^2))/((1+t^2)sqrt(2+t^2))\n\nuse mpmodule\nimplicit none\ntype (mp_real) fun04, t, t1\n\nt1 = sqrt (2.d0 + t**2)\nfun04 = atan(t1)/((1.d0 + t**2)*t1)\nreturn\nend\n\nfunction fun05 (t)\n\n! fun05(t) = sqrt(t)*log(t)\n\nuse mpmodule\nimplicit none\ntype (mp_real) fun05, t\n\nfun05 = sqrt (t) * log (t)\nreturn\nend\n\nfunction fun06 (t)\n\n! fun06(t) = sqrt(1-t^2)\n\nuse mpmodule\nimplicit none\ntype (mp_real) fun06, t\n\nfun06 = sqrt (1.d0 - t**2)\nreturn\nend\n\nfunction fun07 (t)\n\n! fun07(t) = t / sqrt(1-t^2)\n\nuse mpmodule\nimplicit none\ntype (mp_real) fun07, t\n\nfun07 = t / sqrt (1.d0 - t**2)\nreturn\nend\n\nfunction fun08 (t)\n\n! fun08(t) = log(t)^2\n\nuse mpmodule\nimplicit none\ntype (mp_real) fun08, t\n\nfun08 = log (t) ** 2\nreturn\nend\n\nfunction fun09 (t)\n\n! fun09(t) = log (cos (t))\n\nuse mpmodule\nimplicit none\ntype (mp_real) fun09, t\n\nfun09 = log (cos (t))\nreturn\nend\n\nfunction fun10 (t)\n\n! fun10(t) = sqrt(tan(t))\n\nuse mpmodule\nimplicit none\ntype (mp_real) fun10, t\n\nfun10 = sqrt (tan (t))\nreturn\nend\n\nfunction fun11 (t)\n\n! fun11(t) = 1/(u^2(1+(1/u-1)^2)) = 1/(1 - 2*u + u^2)\n\nuse mpmodule\nimplicit none\ntype (mp_real) fun11, t\n\nfun11 = 1.d0 / (1.d0 - 2.d0 * t + 2.d0 * t ** 2)\nreturn\nend\n\nfunction fun12 (t)\n\n! fun12(t) = e^(-(1/t-1)) / sqrt(t^3 - t^4)\n\nuse mpmodule\nimplicit none\ntype (mp_real) fun12, t, t1\n\nt1 = 1.d0 / t - 1.d0\nfun12 = exp (-t1) / sqrt (t ** 3 - t ** 4)\nreturn\nend\n\nfunction fun13 (t)\n\n! fun13(t) = e^(-(1/t-1)^2/2) / t^2\n\nuse mpmodule\nimplicit none\ntype (mp_real) fun13, t, t1\n\nt1 = 1.d0 / t - 1.d0\nfun13 = exp (-0.5d0 * t1 ** 2) / t ** 2\nreturn\nend\n\nfunction fun14 (t)\n\n! fun14(t) = e^(-(1/t-1)) * cos (1/t-1) / t^2\n\nuse mpmodule\nimplicit none\ntype (mp_real) fun14, t, t1\n\nt1 = 1.d0 / t - 1.d0\nfun14 = exp (-t1) * cos (t1) / t ** 2\nreturn\nend\n\nfunction fun15a (t)\n\n! fun15a(t) = sin(t)/t\n\nuse mpmodule\nuse quadglobal\nimplicit none\ntype (mp_real) fun15a, t\n\nfun15a = sin (t) / t\nreturn\nend\n\nfunction fun15b (t)\n\n! fun15b(t) = t^7 * sin(1/t)\n\nuse mpmodule\nuse quadglobal\nimplicit none\ntype (mp_real) fun15b, t\n\nfun15b = t**7 * sin (1.d0 / t)\nreturn\nend\n\nsubroutine initqts (nq1, nq2, wk, xk)\n\n! This subroutine initializes the quadrature arays xk and wk using the\n! function x(t) = tanh (pi/2*sinh(t)). The argument nq2 is the space\n! allocated for wk and xk in the calling program. By default it is set to \n! 8 * 2^nq1. Increase nq2 if directed by a message produced below.\n! Upon completion, wk(-1) = nq1, and xk(-1) = n, the maximum space parameter\n! for these arrays. In other words, the arrays occupy (wk(i), i = -1 to n)\n! and (xk(i), i = -1 to n), where n = xk(-1).\n! David H Bailey 2002-11-05\n\nuse mpmodule\nuse quadglobal\nimplicit none\ninteger i, ierror, iprint, j, k, k1, nq1, nq2\n! XSL\ninteger ntids, tid, OMP_GET_THREAD_NUM, OMP_GET_NUM_THREADS\nreal*8 h\nparameter (iprint = 1000)\ntype (mp_real) p2, t1, t2, t3, t4, t5, wk(-1:nq2), xk(-1:nq2)\n\nif (ndebug >= 1) then\n write (6, 1)\n1 format ('initqts: Tanh-sinh quadrature initialization')\nendif\n\np2 = 0.5d0 * mppic\nh = 0.5d0 ** nq1\nwk(-1) = dble (nq1)\n\n!$omp parallel do private(k,t1,t2,t3,t4,t5,ntids,tid) shared(nq2,p2,h)\ndo k = 0, nq2\n if (ndebug >= 2 .and. mod (k, iprint) == 0) then\n ntids = omp_get_num_threads()\n tid = omp_get_thread_num()\n print*, 'nthreads = ', ntids, ' thread = ', tid\n write (6, *) k, nq2\n endif\n t1 = dble (k) * h\n\n! xk(k) = tanh (p2 * sinh (t1))\n! wk(k) = p2 * cosh (t1) / cosh (p2 * sinh (t1)) ** 2\n\n! The next five lines are equivalent to the above two, but faster.\n\n call mpcsshf (t1, t2, t3)\n t3 = p2 * t3\n call mpcsshf (t3, t4, t5)\n xk(k) = t5 / t4\n wk(k) = p2 * t2 / t4 ** 2\n\n! call mpgetpar ('mpier', ierror)\n! if (ierror > 0) goto 120\n! if (xk(k) .eq. 1.d0) goto 100\nenddo\n!$omp end parallel do\n\nprint*, 'k = ', k\ngoto 100\n\nwrite (6, 2) nq2\n2 format ('initqts: Table space parameter is too small; value =',i8)\nnerror = 91\ngoto 130\n\n100 continue\n\n! XSL, out-of parallel-do loop, k is not defined\nk = nq2\n!\nxk(-1) = dble (k)\nif (ndebug >= 2) then\n write (6, 3) k\n3 format ('initqts: Table spaced used =',i8)\nendif\ngoto 130\n\n120 continue\n\nnerror = ierror + 100\nwrite (6, 4) nerror\n4 format ('initqts: Error in quadrature initialization; code =',i5)\n\n130 continue\n\nreturn\nend\n\nfunction quadts (fun, x1, x2, nq1, nq2, wk, xk)\n\n! This routine computes the integral of the function in fun on the interval\n! [x1, x2], with up to nq1 iterations, with a target tolerance of mpeps.\n! wk and xk are precomputed tables of weights and abscissas. The function\n! fun is not evaluated at x = x1 or x2.\n! David H. Bailey 2002-11-05\n\nuse mpmodule\nuse quadglobal\nimplicit none\ninteger i, ierror, ip(0:100), j, k, k1, k2, n, nds, nq1, nq2, nqq1\nreal*8 d1, d2, d3, d4, dplog10q, h\ntype (mp_real) ax, bx, c10, quadts, eps, eps1, eps2, err, fmx, fun, &\n sum, s1, s2, s3, t1, t2, t3, t4, term, wk(-1:nq2), xk(-1:nq2), &\n x1, x2, xx1, xx2\nexternal fun, dplog10q\n\nnds = mpoud\nmpoud = 56\nax = 0.5d0 * (x2 - x1)\nbx = 0.5d0 * (x2 + x1)\nsum = 0.d0\ns1 = 0.d0\ns2 = 0.d0\nh = 1.d0\nc10 = 10.d0\neps = mpeps\neps1 = 2.d0 ** 48 * mpeps\n\nif (wk(-1) < dble (nq1)) then\n write (6, 1) nq1\n1 format ('quadts: quadrature arrays have not been initialized; nq1 =',i6)\n nerror = 70\n goto 140\nendif\nnqq1 = dble (wk(-1)) ! XSL note: nqq1 = nq1 = m\nn = dble (xk(-1))\n\ndo k = 0, nqq1\n ip(k) = 2 ** k\nenddo\n\ndo k = 1, nq1\n h = 0.5d0 * h\n s3 = s2\n s2 = s1\n fmx = 0.d0\n k1 = ip(nqq1-k)\n k2 = ip(nqq1-k+1)\n\n! Evaluate function at level k in x, avoiding unnecessary computation.\n\n do i = 0, n, k1\n if (mod (i, k2) /= 0 .or. k == 1) then\n xx1 = - ax * xk(i) + bx\n xx2 = ax * xk(i) + bx\n if (xx1 > x1 .and. xx2 < x2) then\n t1 = fun (xx1)\n call mpgetpar ('mpier', ierror)\n if (ierror > 0 .or. nerror > 0) goto 130\n if (i > 0) then\n t2 = fun (xx2)\n call mpgetpar ('mpier', ierror)\n if (ierror > 0 .or. nerror > 0) goto 130\n else\n t2 = 0.d0\n endif\n sum = sum + wk(i) * (t1 + t2)\n fmx = max (fmx, abs (t1), abs (t2))\n else\n goto 100\n endif\n endif\n enddo\n\n100 continue\n\n! Compute s1 = current integral approximation and err = error estimate.\n\n s1 = ax * h * sum\n eps2 = fmx * eps1\n d1 = dplog10q (abs (s1 - s2))\n d2 = dplog10q (abs (s1 - s3))\n d3 = dplog10q (eps2) - 12.d0\n\n if (k <= 2) then\n err = 1.d0\n elseif (d1 .eq. -9999.d0) then\n err = 0.d0\n else\n d4 = min (0.d0, max (d1 ** 2 / d2, 2.d0 * d1, d3))\n err = c10 ** nint (d4)\n endif\n\n! Output current integral approximation and error estimate, to 56 dp.\n\n if (ndebug >= 2) then\n write (6, 2) k, nq1, nint (dplog10q (abs (err)))\n2 format ('quadts: Iteration',i3,' of',i3,'; est error = 10^',i5, &\n '; approx value =')\n call mpwrite (6, s1)\n endif\n if (k >= 3 .and. err < eps1) goto 140\n if (k >= 3 .and. err < eps2) goto 120\nenddo\n\nwrite (6, 3) nint (dplog10q (abs (err))), nquadl\n3 format ('quadts: Estimated error = 10^',i5/&\n 'Increase Quadlevel for greater accuracy. Current Quadlevel =',i4)\ngoto 140\n\n120 continue\n\nwrite (6, 4) nint (dplog10q (abs (err))), ndigits\n4 format ('quadts: Estimated error = 10^',i5/&\n 'Increase working prec (Digits) for greater accuracy. Current Digits =',i4)\ngoto 140\n\n130 continue\n\nif (ierror > 0) nerror = ierror + 100\nwrite (6, 5) nerror\n5 format ('quadts: Error in quadrature calculation; code =',i5)\ns1 = 0.d0\n\n140 continue\n\nquadts = s1\nmpoud = nds\nreturn\nend\n\nfunction dplog10q (a)\n\n! For input MP value a, this routine returns a DP approximation to log10 (a).\n\nuse mpmodule\nimplicit none\ninteger ia\ndouble precision da, dplog10q, t1\ntype (mp_real) a\n\ncall mpmdc (a%mpr, da, ia)\nif (da .eq. 0.d0) then\n dplog10q = -9999.d0\nelse\n dplog10q = log10 (abs (da)) + ia * log10 (2.d0)\nendif\n\n100 continue\nreturn\nend\n\nsubroutine decmdq (a, b, ib)\n\n! For input MP value a, this routine returns DP b and integer ib such that \n! a = b * 10^ib, with 1 <= abs (b) < 10 for nonzero a.\n\nuse mpmodule\nimplicit none\ninteger ia, ib\ndouble precision da, b, t1, xlt\nparameter (xlt = 0.3010299956639812d0)\ntype (mp_real) a\n\ncall mpmdc (a%mpr, da, ia)\nif (da .ne. 0.d0) then\n t1 = xlt * ia + log10 (abs (da))\n ib = t1\n if (t1 .lt. 0.d0) ib = ib - 1\n b = sign (10.d0 ** (t1 - ib), da)\nelse\n b = 0.d0\n ib = 0\nendif\n\nreturn\nend\n", "meta": {"hexsha": "4dbe558c2694ab4a048dd57d3e291da21d77dabf", "size": 17821, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/mpfun/tquadts_omp.f", "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/mpfun/tquadts_omp.f", "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/mpfun/tquadts_omp.f", "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": 22.9061696658, "max_line_length": 80, "alphanum_fraction": 0.62207508, "num_tokens": 7489, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007394, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.6925727928983955}} {"text": "module norm\ncontains\n\n function Jnorm(j)\n implicit none\n integer, INTENT(IN) :: j\n real(kind=8) :: Jnorm\n\n Jnorm = 2d0 * j + 1d0\n\n end function Jnorm\n\n\n function j2norm(two_j)\n implicit none\n integer, intent(in) :: two_j\n integer :: j2norm\n \n j2norm = two_j + 1\n \n end function j2norm\n \n\n function Qnorm(j)\n implicit none\n integer, INTENT(IN) :: j\n real(kind=8) :: Qnorm\n\n if (j<0) STOP \"qnorm error: negative j\"\n\n Qnorm = sqrt(2d0 * j + 1d0)\n\n end function Qnorm\n\n\n function q2norm(two_j)\n implicit none\n integer, intent(in) :: two_j\n real(kind=8) :: q2norm\n if (two_j<0) STOP \"qnorm error: negative j\"\n\n q2norm = sqrt(two_j + 1d0)\n \n end function q2norm \n\nend module norm\n", "meta": {"hexsha": "9b3919aa6a54fb76399a8dd3ffce2e8e27ef3bd0", "size": 841, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/norm.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/norm.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/norm.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": 17.8936170213, "max_line_length": 51, "alphanum_fraction": 0.5410225922, "num_tokens": 254, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637361282707, "lm_q2_score": 0.8056321796478255, "lm_q1q2_score": 0.6925727695012119}} {"text": "\nPROGRAM MAIN\n\n IMPLICIT NONE\n\n ! Loop counter and maximum value\n INTEGER :: i, max_val\n ! Variables for previous sequence vals, and current one\n INTEGER :: fib_first, fib_second, fib_current\n\n ! Do the first 20 terms\n max_val = 20\n\n ! Optional last but to add- sanity check on max_val\n IF(max_val < 3 .OR. max_val > 46) THEN\n PRINT*, \"Sequence is too short or long. max_val should be between 3 and 46\"\n END IF\n\n ! f(1) = 1 and f(2) = 1\n fib_first = 1\n fib_second = 1\n\n ! Print the initial 2 values so we see the whole sequence up to max_val\n PRINT*, fib_first\n PRINT*, fib_second\n\n ! Loop from the third value to max_value, calculating and printing the term\n DO i = 3, max_val\n\n ! This is the current term\n fib_current = fib_first + fib_second\n\n ! these are the previous terms, fib_first = f(n-2) and fib_second=f(n-1)\n fib_first = fib_second\n fib_second = fib_current\n\n ! Print the calculated value\n PRINT*, fib_current\n\n END DO\n\nEND PROGRAM\n", "meta": {"hexsha": "014e800e02871fce58a903d6b2ec07f500241b89", "size": 987, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ModelSolutions/Fibonacci.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/Fibonacci.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/Fibonacci.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": 22.9534883721, "max_line_length": 79, "alphanum_fraction": 0.6909827761, "num_tokens": 289, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.835483553488848, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.6925647464972514}} {"text": " program pendulum\n real omega(300),teta(300),t(300)\n open(7,file=\"pend_out\")\n print*, \"Enter teta0\"\n read(5,*) teta0\n print*, \"Enter q\"\n read(5,*) q\n 111 format(2(2x,e11.5))\n pi=3.1415927\n teta=teta0*pi/180.0\n g=9.8\n s1=1.0\n freq=sqrt(g/s1)\n period=2.0*pi/freq\n tt=4.0*period\n dt=tt/300.0\n t(1)=0.0\n omega(1)=0.0\n teta(1)=teta0\n g1=g/s1\n do i=1,299\n t(i+1)=t(i)+dt\n omega(i+1)=omega(i)-(g1*teta(i)+q*omega(i))*dt\n teta(i+1)=teta(i)+omega(i+1)*dt\n write(7,111) t(i+1),teta(i+1)\n enddo\n end\n\n", "meta": {"hexsha": "6f4984d10790e6bc5a11857cfc86e51377ab8822", "size": 629, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "proj3/pend.f", "max_stars_repo_name": "GeorgeDavila/Computational_Physics_Fortran", "max_stars_repo_head_hexsha": "e23ce3d419a560ba4d82693d7b1e9c05e790e05b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-08-08T16:49:19.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-11T02:25:48.000Z", "max_issues_repo_path": "proj3/pend.f", "max_issues_repo_name": "GeorgeDavila/Computational_Physics_Fortran", "max_issues_repo_head_hexsha": "e23ce3d419a560ba4d82693d7b1e9c05e790e05b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "proj3/pend.f", "max_forks_repo_name": "GeorgeDavila/Computational_Physics_Fortran", "max_forks_repo_head_hexsha": "e23ce3d419a560ba4d82693d7b1e9c05e790e05b", "max_forks_repo_licenses": ["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.6896551724, "max_line_length": 54, "alphanum_fraction": 0.4833068362, "num_tokens": 268, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475730993027, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6925298795536027}} {"text": "PROGRAM FDM_HeatEq2D\r\n USE FDM_Grid2D\r\n USE SimulationTime\r\n\tIMPLICIT NONE \r\n REAL(dp), DIMENSION(:,:), ALLOCATABLE :: T, TNew\r\n REAL(dp) :: time\r\n INTEGER :: i, j\r\n INTEGER :: timeStep = 0\r\n \r\n CALL SetFDMGrid\r\n CALL CalculateDt\r\n\r\n IF (.NOT. ALLOCATED(T)) THEN\r\n ALLOCATE(T(1:nx,1:ny))\r\n ENDIF\r\n\r\n IF (.NOT. ALLOCATED(Tnew)) THEN\r\n ALLOCATE(Tnew(1:nx,1:ny))\r\n Tnew = 0.0d0\r\n ENDIF\r\n\r\n ! B.C\r\n\tT(1,1:ny) = 0.0d0\r\n T(nx,1:ny) = 0.0d0\r\n T(1:nx,1) = 0.0d0\r\n T(1:nx,ny) = 0.0d0\r\n\r\n ! Initial solution\r\n T(2:nx-1,2:ny-1) = 0.0d0\r\n T(nx/2,ny/2) = 100.0d0\r\n T(nx/2+1,ny/2) = 100.0d0\r\n T(nx/2,ny/2+1) = 100.0d0\r\n T(nx/2+1,ny/2+1) = 100.0d0\r\n\r\n CALL SetEndTime\r\n\r\n time = 0.0d0\r\n\t\r\n \tDO WHILE (time <= endTime)\r\n \ttime = time + dt\r\n timeStep = timeStep + 1\r\n DO j = 2, ny - 1\r\n DO i = 2, nx - 1\r\n\t\t\tTNew(i,j) = TNew(i,j) + dt * kappa * (T(i-1,j) - 2.0d0*T(i,j) + T(i+1,j)) / delta_x**2 \r\n TNew(i,j) = TNew(i,j) + dt * kappa * (T(i,j-1) - 2.0d0*T(i,j) + T(i,j+1)) / delta_y**2 \r\n ENDDO\r\n ENDDO\r\n\r\n T = TNew\r\n\r\n IF (MOD(timeStep,10) == 0) CALL WriteSolutionToVTK(timeStep)\r\n ENDDO\r\n\r\n CONTAINS\r\n\r\n \tSUBROUTINE WriteSolutionToMatlab(timeStep)\r\n \tIMPLICIT NONE\r\n INTEGER, INTENT(IN) :: timeStep\r\n INTEGER :: j\r\n CHARACTER(20) :: chrTimeStep\r\n\r\n WRITE(chrTimeStep,'(I7.7)') timeStep\r\n OPEN(UNIT = 20, FILE = trim(chrTimeStep)//'.dat', STATUS = 'REPLACE')\r\n DO j = 1, ny\r\n WRITE(20,'(1000f13.5)') T(:,j)\r\n ENDDO\r\n CLOSE(UNIT = 20)\r\n END SUBROUTINE WriteSolutionToMatlab\r\n\r\n SUBROUTINE WriteSolutionToVTK(timeStep)\r\n \tIMPLICIT NONE\r\n INTEGER, INTENT(IN) :: timeStep\r\n INTEGER :: i, j\r\n CHARACTER(20) :: chrTimeStep\r\n\r\n WRITE(chrTimeStep,'(I7.7)') timeStep\r\n OPEN(UNIT = 20, FILE = trim(chrTimeStep)//'.vtk', STATUS = 'REPLACE')\r\n WRITE(20,'(1A26)') '# vtk DataFile Version 2.0'\r\n WRITE(20,'(A)') 'Diffusion 2D'\r\n WRITE(20,'(A)') 'ASCII'\r\n WRITE(20,'(A)') 'DATASET STRUCTURED_GRID'\r\n WRITE(20,100) nx, ny, 1\r\n WRITE(20,200) nx * ny \r\n DO j = 1, ny\r\n DO i = 1, nx\r\n WRITE(20,*) x(i), y(j), 0.0d0\r\n ENDDO\r\n ENDDO\r\n WRITE(20,*) 'POINT_DATA', nx * ny\r\n WRITE(20,'(A)') 'SCALARS T float'\r\n WRITE(20,'(A)') 'LOOKUP_TABLE default'\r\n DO j = 1, ny\r\n DO i = 1, nx\r\n WRITE(20,*) T(i,j)\r\n ENDDO\r\n ENDDO\r\n CLOSE(UNIT = 20)\r\n\r\n100 FORMAT('DIMENSIONS ',3I9)\r\n200 FORMAT('POINTS ',I9,' float') \r\n END SUBROUTINE WriteSolutionToVTK\r\n\r\nEND PROGRAM FDM_HeatEq2D\r\n", "meta": {"hexsha": "01cabdcd943a13ce5f2a688568f76d597477a54a", "size": 2963, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "main.f95", "max_stars_repo_name": "truongd8593/FDM_HeatEq2D", "max_stars_repo_head_hexsha": "bfeac1955a2b05c5ffcea7814d1aa47dac78c96d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "main.f95", "max_issues_repo_name": "truongd8593/FDM_HeatEq2D", "max_issues_repo_head_hexsha": "bfeac1955a2b05c5ffcea7814d1aa47dac78c96d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "main.f95", "max_forks_repo_name": "truongd8593/FDM_HeatEq2D", "max_forks_repo_head_hexsha": "bfeac1955a2b05c5ffcea7814d1aa47dac78c96d", "max_forks_repo_licenses": ["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.4903846154, "max_line_length": 100, "alphanum_fraction": 0.4731690854, "num_tokens": 1040, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528019683105, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.6925245929223875}} {"text": "MODULE populate\nIMPLICIT NONE\nREAL, DIMENSION(-50:50,0:100) :: values\nINTEGER :: i, j\nCONTAINS\n SUBROUTINE populate_array()\n INTEGER, DIMENSION(8) :: time\n CALL DATE_AND_TIME(VALUES=time)\n CALL SRAND(time(8))\n DO i = -50, 50\n DO j = 0, 100\n IF (RAND() .gt. 0.95) THEN\n values(i, j) = 0.\n ELSE\n values(i, j) = RAND() * 20. - 10.\n END IF\n END DO\n END DO\n END SUBROUTINE populate_array\nEND MODULE populate\n\nPROGRAM counting\nUSE populate\nIMPLICIT NONE\nINTEGER :: pos_count = 0, neg_count = 0, zero_count = 0\n\nCALL populate_array()\n\nDO i = -50, 50\n DO j = 0, 100\n IF (values(i, j) .gt. 0.0) THEN\n pos_count = pos_count + 1\n ELSE IF (values(i, j) .lt. 0.0) THEN\n neg_count = neg_count + 1\n ELSE\n zero_count = zero_count + 1\n END IF\n END DO\nEND DO\n\nWRITE(*, *) \"Counting positive, negative, and zero values in array...\"\nWRITE(*, *) \"Results using DO and IF statements:\"\nWRITE(*, '(3(A,I5,2X))') \"POS: \", pos_count, \"NEG: \", neg_count, \"ZERO: \", zero_count\nWRITE(*, *) \"Results using COUNT statements:\"\nWRITE(*, '(3(A,I5,2X))') \"POS: \", COUNT(values > 0.), \"NEG: \", COUNT(values < 0.), \"ZERO: \", COUNT(values == 0.)\nEND PROGRAM counting\n", "meta": {"hexsha": "541ab0d926899d2677724d374124d83f5b1621dd", "size": 1224, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap8/counting.f90", "max_stars_repo_name": "evanmacbride/fortran-practice", "max_stars_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/chap8/counting.f90", "max_issues_repo_name": "evanmacbride/fortran-practice", "max_issues_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/chap8/counting.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.0425531915, "max_line_length": 112, "alphanum_fraction": 0.6029411765, "num_tokens": 410, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527944504227, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.6925245868113422}} {"text": "C$Procedure POLYDS ( Compute a Polynomial and its Derivatives )\n \n SUBROUTINE POLYDS ( COEFFS, DEG, NDERIV, T, P )\n \nC$ Abstract\nC\nC Compute the value of a polynomial and it's first\nC n derivatives at the value T.\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\nC INTERPOLATION, MATH, POLYNOMIAL\nC\nC$ Declarations\n \n DOUBLE PRECISION COEFFS ( 0:* )\n INTEGER DEG\n INTEGER NDERIV\n DOUBLE PRECISION T\n DOUBLE PRECISION P ( 0:* )\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC COEFFS I Coefficients of the polynomial to be evaluated.\nC DEG I Degree of the polynomial to be evaluated.\nC NDERIV I Number of derivatives to compute.\nC T I Point to evaluate the polynomial and derivatives\nC P O Value of polynomial and derivatives.\nC\nC$ Detailed_Input\nC\nC COEFFS containst the coefficients of the polynomial that is\nC to be evaluated. The first element of this array\nC should be the constant term, the second element the\nC linear coefficient, the third term the quadratic\nC coefficient, and so on. The number of coefficients\nC supplied should be one more than DEG.\nC\nC DEG is the degree of the polynomial to be evaluated. DEG\nC should be one less than the number of coefficients\nC supplied.\nC\nC NDERIV is the number of derivatives to compute. If NDERIV\nC is zero, only the polynomial will be evaluated. If\nC NDERIV = 1, then the polynomial and its first\nC derivative will be evaluated, and so on. If the value\nC of NDERIV is negative, the routine returns\nC immediately.\nC\nC T is the point at which the polynomial and its\nC derivatives should be evaluated.\nC\nC$ Detailed_Output\nC\nC P is an array containing the value of the polynomial and\nC its derivatives evaluated at T. The first element of\nC the array contains the value of P at T. The second\nC element of the array contains the value of the first\nC derivative of P at T and so on. The NDERIV + 1'st\nC element of the array contains the NDERIV'th derivative\nC of P evaluated at T.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Particulars\nC\nC This routine uses the user supplied coefficients (COEFFS)\nC to evaluate a polynomial (having these coefficients) and its\nC derivatives at the point T. The zero'th derivative of the\nC polynomial is regarded as the polynomial itself.\nC\nC$ Examples\nC\nC Suppose T = 1.0D0\nC\nC\nC Degree COEFFS Deriviative Number P\nC ------ ------ ------------------ ----------\nC 0 1 0 5\nC 1 3 1 10\nC 2 0.5 2 29\nC 3 1 3 102\nC 4 0.5\nC 5 -1\nC 6 1\nC\nC$ Restrictions\nC\nC Depending on the coefficients the user should be careful when\nC taking high order derivatives. As the example shows, these\nC can get big in a hurry. In general the coefficients of the\nC derivatives of a polynomial grow at a rate greater\nC than N! (N factorial).\nC\nC$ Exceptions\nC\nC Error free\nC\nC 1) If NDERIV is less than zero, the routine simply returns\nC\nC 2) If the degree of the polynomial is less than 0, the routine\nC simply returns.\nC\nC$ Files\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC W.L. Taber (JPL)\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Version\nC\nC- SPICELIB Version 1.1.0, 11-JUL-1995 (KRG)\nC\nC Replaced the function calls to DFLOAT with standard conforming \nC calls to DBLE.\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 compute a polynomial and its derivatives\nC\nC-&\n \n \n \nC$ Revisions\nC\nC- SPICELIB Version 1.1.0, 11-JUL-1995 (KRG)\nC\nC Replaced the function calls to DFLOAT with standard conforming \nC calls to DBLE.\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- Beta Version 1.0.1, 30-DEC-1988 (WLT)\nC\nC The error free specification was added as well as notes\nC on exceptional degree or derivative requests.\nC\nC-&\n \n \nC\nC Local variables\nC\n INTEGER I\n INTEGER K\n DOUBLE PRECISION SCALE\n \n \n IF ( NDERIV .LT. 0 ) THEN\n RETURN\n END IF\n \nC\nC The following loops may not look like much, but they compute\nC P(T), P'(T), P''(T), ... etc.\nC\nC To see why, recall that if A_0 through A_N are the coefficients\nC of a polynomial, then P(t) can be computed from the sequence\nC of polynomials given by:\nC\nC P_0(t) = 0\nC P_1(t) = t*P_0(t) + A_N\nC P_2(t) = t*P_1(t) + A_[N-1]\nC .\nC .\nC .\nC P_n(t) = t*P_[n-1](t) + A_0\nC\nC The final polynomial in this list is in fact P(t). From this\nC it follows that P'(t) is given by P_n'(t). But\nC\nC P_n'(t) = t*P_[n-1]'(t) + P_[n-1](t)\nC\nC and\nC\nC P_[n-1]'(t) = t*P_[n-2]'(t) + P_[n-2](t)\nC .\nC .\nC .\nC P_2'(t) = t*P_1'(t) + P_1(t)\nC P_1'(t) = t*P_0'(t) + P_0(t)\nC P_0'(t) = 0\nC\nC Rearranging the sequence we have a recursive method\nC for computing P'(t). At the i'th stage we require only the i-1st\nC polynomials P_[i-1] and P_[i-1]' .\nC\nC P_0'(t) = 0\nC P_1'(t) = t*P_0'(t) + P_0(t)\nC P_2'(t) = t*P_1'(t) + P_1(t)\nC .\nC .\nC .\nC P_[n-1]'(t) = t*P_[n-2]'(t) + P_[n-2](t)\nC P_n'(t) = t*P_[n-1]'(t) + P_[n-1](t)\nC\nC\nC Similarly,\nC\nC P_0''(t) = 0\nC P_1''(t) = t*P_0''(t) + 2*P_0'(t)\nC P_2''(t) = t*P_1''(t) + 2*P_1'(t)\nC .\nC .\nC .\nC P_[n-1]''(t) = t*P_[n-2]''(t) + 2*P_[n-2]'(t)\nC\nC\nC\nC P_0'''(t) = 0\nC P_1'''(t) = t*P_0'''(t) + 3*P_0''(t)\nC P_2'''(t) = t*P_1'''(t) + 3*P_1''(t)\nC .\nC .\nC .\nC P_[n-1]'''(t) = t*P_[n-2]'''(t) + 3*P_[n-2]''(t)\nC\nC Thus if P(I) contains the k'th iterations of the i'th derivative\nC computation of P and P(I-1) contains the k'th iteration of the\nC i-1st derivative of P then, t*P(I) + I*P(I-1) is the value of the\nC k+1st iteration of the computation of the i'th derivative of\nC P. This can then be stored in P(I).\nC\nC If in a loop we compute in-place k'th iteration of the\nC I'th derivative before we perform the in-place k'th iteration\nC of the I-1st and I-2cnd derivative, then the k-1'th values\nC of the I-1st and I-2cnd will not be altered and will be available\nC for the computation of the k'th interation of the I-1st\nC derivative. This observation gives us an economical way to\nC compute all of the derivatives (including the zero'th derivative)\nC in place. We simply compute the iterates of the high order\nC derivatives first.\n \nC\nC Initialize the polynomial value (and all of its derivatives) to be\nC zero.\nC\n DO I = 0, NDERIV\n P(I) = 0.0D0\n END DO\n \n \nC\nC Set up the loop \"counters\" (they count backwards) for the first\nC pass through the loop.\nC\n K = DEG\n I = NDERIV\n SCALE = DBLE ( NDERIV )\n \n DO WHILE ( K .GE. 0 )\n \n DO WHILE ( I .GT. 0 )\n P(I) = T*P(I) + SCALE*P(I-1)\n SCALE = SCALE - 1\n I = I - 1\n END DO\n \n P(0) = T*P(0) + COEFFS(K)\n K = K - 1\n I = NDERIV\n SCALE = DBLE( NDERIV )\n END DO\n \n RETURN\n END\n \n", "meta": {"hexsha": "49679ba92d0c8610a537713e7e710d99c39a5593", "size": 9870, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/polyds.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/polyds.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/polyds.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": 30.5572755418, "max_line_length": 72, "alphanum_fraction": 0.569402229, "num_tokens": 3067, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026663679977, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6924855303348374}} {"text": " Program zhegv_example\n\n! ZHEGV Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_example_aux, Only: nagf_file_print_matrix_complex_gen\n Use lapack_interfaces, Only: ddisna, zhegv, zlanhe, ztrcon\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nb = 64, nin = 5, nout = 6\n! .. Local Scalars ..\n Complex (Kind=dp) :: scal\n Real (Kind=dp) :: anorm, bnorm, eps, rcond, rcondb, t1, t2, t3\n Integer :: i, ifail, info, k, lda, ldb, lwork, n\n! .. Local Arrays ..\n Complex (Kind=dp), Allocatable :: a(:, :), b(:, :), work(:)\n Complex (Kind=dp) :: dummy(1)\n Real (Kind=dp), Allocatable :: eerbnd(:), rcondz(:), rwork(:), w(:), &\n zerbnd(:)\n! .. Intrinsic Procedures ..\n Intrinsic :: abs, conjg, epsilon, max, maxloc, nint, real\n! .. Executable Statements ..\n Write (nout, *) 'ZHEGV Example Program Results'\n Write (nout, *)\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n\n lda = n\n ldb = n\n Allocate (a(lda,n), b(ldb,n), eerbnd(n), rcondz(n), rwork(3*n-2), w(n), &\n zerbnd(n))\n\n! Use routine workspace query to get optimal workspace.\n lwork = -1\n Call zhegv(1, 'Vectors', 'Upper', n, a, lda, b, ldb, w, dummy, lwork, &\n rwork, info)\n\n! Make sure that there is enough workspace for block size nb.\n lwork = max((nb+1)*n, nint(real(dummy(1))))\n Allocate (work(lwork))\n\n! Read the upper triangular parts of the matrices A and B\n\n Read (nin, *)(a(i,i:n), i=1, n)\n Read (nin, *)(b(i,i:n), i=1, n)\n\n! Compute the one-norms of the symmetric matrices A and B\n\n anorm = zlanhe('One norm', 'Upper', n, a, lda, rwork)\n bnorm = zlanhe('One norm', 'Upper', n, b, ldb, rwork)\n\n! Solve the generalized Hermitian eigenvalue problem\n! A*x = lambda*B*x (itype = 1)\n\n Call zhegv(1, 'Vectors', 'Upper', n, a, lda, b, ldb, w, work, lwork, &\n rwork, info)\n\n If (info==0) Then\n\n! Print solution\n\n Write (nout, *) 'Eigenvalues'\n Write (nout, 100) w(1:n)\n Flush (nout)\n\n! Normalize the eigenvectors, largest element real\n! (normalization w.r.t B unaffected: Z^HBZ = I).\n Do i = 1, n\n rwork(1:n) = abs(a(1:n,i))\n k = maxloc(rwork(1:n), 1)\n scal = conjg(a(k,i))/abs(a(k,i))\n a(1:n, i) = a(1:n, i)*scal\n End Do\n\n! ifail: behaviour on error exit\n! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft\n ifail = 0\n Call nagf_file_print_matrix_complex_gen('General', ' ', n, n, a, lda, &\n 'Eigenvectors', ifail)\n\n! Call ZTRCON to estimate the reciprocal condition\n! number of the Cholesky factor of B. Note that:\n! cond(B) = 1/rcond**2\n Call ztrcon('One norm', 'Upper', 'Non-unit', n, b, ldb, rcond, work, &\n rwork, info)\n\n! Print the reciprocal condition number of B\n\n rcondb = rcond**2\n Write (nout, *)\n Write (nout, *) 'Estimate of reciprocal condition number for B'\n Write (nout, 110) rcondb\n Flush (nout)\n\n! Get the machine precision, eps, and if rcondb is not less\n! than eps**2, compute error estimates for the eigenvalues and\n! eigenvectors\n\n eps = epsilon(1.0E0_dp)\n If (rcond>=eps) Then\n\n! Call DDISNA to estimate reciprocal condition\n! numbers for the eigenvectors of (A - lambda*B)\n\n Call ddisna('Eigenvectors', n, n, w, rcondz, info)\n\n! Compute the error estimates for the eigenvalues and\n! eigenvectors\n\n t1 = eps/rcondb\n t2 = anorm/bnorm\n t3 = t2/rcond\n Do i = 1, n\n eerbnd(i) = t1*(t2+abs(w(i)))\n zerbnd(i) = t1*(t3+abs(w(i)))/rcondz(i)\n End Do\n\n! Print the approximate error bounds for the eigenvalues\n! and vectors\n\n Write (nout, *)\n Write (nout, *) 'Error estimates for the eigenvalues'\n Write (nout, 110) eerbnd(1:n)\n Write (nout, *)\n Write (nout, *) 'Error estimates for the eigenvectors'\n Write (nout, 110) zerbnd(1:n)\n Else\n Write (nout, *)\n Write (nout, *) 'B is very ill-conditioned, error ', &\n 'estimates have not been computed'\n End If\n Else If (info>n) Then\n i = info - n\n Write (nout, 120) 'The leading minor of order ', i, &\n ' of B is not positive definite'\n Else\n Write (nout, 130) 'Failure in ZHEGV. INFO =', info\n End If\n\n100 Format (3X, (6F11.4))\n110 Format (4X, 1P, 6E11.1)\n120 Format (1X, A, I4, A)\n130 Format (1X, A, I4)\n End Program\n", "meta": {"hexsha": "f69f69b3a3bae9c185ceb946c74f3012f90fbd21", "size": 4955, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/zhegv_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/zhegv_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/zhegv_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 32.8145695364, "max_line_length": 90, "alphanum_fraction": 0.5600403633, "num_tokens": 1541, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026528034426, "lm_q2_score": 0.7549149978955811, "lm_q1q2_score": 0.6924855302107219}} {"text": "PROGRAM CNPE2_HF\r\n USE PE2D_TYPE\n USE PE2D_VAR\n USE PE2D_AUX\n USE PE2D_GROUND\r\n IMPLICIT NONE\r\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\r\n WRITE(*,*) \"\"\r\n WRITE(*,*) \"================================================\"\r\n WRITE(*,*) \"========== Parabolic Equation Package ==========\"\r\n WRITE(*,*) \"================================================\"\r\n WRITE(*,*) \"\"\r\n WRITE(*,*) \"University of Bristol\"\r\n WRITE(*,*) \"Mech. Eng. Department\"\r\n WRITE(*,*) \"Aerodynamics and Aeroacoustics Research Group\"\r\n WRITE(*,*) \"\"\r\n WRITE(*,*) \"Codor Khodr, July 2016\"\r\n WRITE(*,*) \"\"\r\n WRITE(*,*) \"================================================\"\r\n WRITE(*,*) \"\"\r\n WRITE(*,*) \"CNPE2_HF\"\r\n WRITE(*,*) \"Dimension : 2D\"\r\n WRITE(*,*) \"Atmosphere : Homogeneous\"\r\n WRITE(*,*) \"Boundary : Flat\"\r\n WRITE(*,*) \"Impedance : Rigid\"\r\n WRITE(*,*) \"\"\r\n WRITE(*,*) \"================================================\"\r\n WRITE(*,*) \"\"\r\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\r\n !Read data\r\n OPEN(UNIT=10,FILE=\"CNPE2_IN.dat\",STATUS=\"OLD\")\r\n READ(10,*) L !Domain range\r\n READ(10,*) F !Frequency\r\n READ(10,*) ZS !Source height\r\n READ(10,*) ZR !Target height\r\n READ(10,*) ZX !Impedance real part\r\n READ(10,*) ZY !Impedance imaginary part\r\n READ(10,*) ANGLE !Terrain maximum angle\r\n READ(10,*) DC !Atmosphere profile coefficient\r\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\n C0 = 343.0_DP\r\n LMBDA0 = C0/F\r\n K0 = 2*PI*F/C0\r\n DZ = LMBDA0/10\r\n DR = LMBDA0/10\n H = 100*LMBDA0\r\n HA = 30*LMBDA0\r\n N = FLOOR(H/DZ)\r\n M = FLOOR(L/DR)\n WRITE(*,*) \"================================================\"\n WRITE(*,*) \"\"\n WRITE(*,*) \"Size of the system : \", N\n WRITE(*,*) \"Number of steps : \", M\n WRITE(*,*) \"\"\n WRITE(*,*) \"================================================\"\r\n NS = MAX(1,FLOOR(ZS/DZ))\r\n NA = FLOOR(HA/DZ)\n A = IM/(2.0_DP*K0*DZ**2)\n KU = 1\n KL = 1\n NDIAG = KU+KL+1\r\n WIDE_I = 1\r\n Z = CMPLX(ZX,ZY,KIND=DPC)\r\n R = (Z-1.0_DP)/(Z+1.0_DP)\r\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\r\n !Absorbing coefficient\r\n AS = 4.897_DP*(10**(-9))*(F**3) - &\r\n 7.119_DP*(10**(-6))*(F**2) + &\r\n 3.109_DP*(10**(-3))*F + &\r\n 0.113\r\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\r\n !Atmosphere density and wave velocity\r\n ALLOCATE(C(N),K(N),DK2(N),ALT(N))\r\n Z0 = 0.5_DP\r\n DO NZ = 1,N\r\n ALT(NZ) = NZ*DZ\r\n C(NZ) = C0+DC*ALT(NZ)!LOG(1+ALT(NZ)/Z0)\r\n K(NZ) = 2.0_DP*PI*F/C(NZ)\r\n IF (NZ.GT.(N-NA)) THEN\r\n K(NZ) = K(NZ)+AS*IM*(NZ-N+NA)**2/NA**2\r\n END IF\r\n DK2(NZ) = K(NZ)**2-K0**2\r\n END DO\r\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\r\n !Starting field\r\n ALLOCATE(PHI(N,M+1),PC(N,M),QC(N,M),P(N,M),Q(N,M))\r\n A0 = 1.3717_DP\r\n A2 = -0.3701_DP\r\n B = 3.0_DP\r\n DO NZ = 1,N\r\n PHI(NZ,1) = SQRT(IM*K0)* &\r\n ((A0+A2*K0**2*(NZ*DZ-ZS)**2)*EXP(-K0**2*(NZ*DZ-ZS)**2/B) + &\r\n R*(A0+A2*K0**2*(NZ*DZ+ZS)**2)*EXP(-K0**2*(NZ*DZ+ZS)**2/B))\r\n END DO\r\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\r\n !Initialization (Dense Matrices)\n ALLOCATE(T(N,N),D(N,N),E(N,N),I(N,N))\n TAU1 = 4.0_DP/(3.0_DP-2.0_DP*IM*K0*DZ)\n TAU2 = -1.0_DP/(3.0_DP-2.0_DP*IM*K0*DZ)\n SIGMA1 = 4.0_DP*Z/(3.0_DP*Z-2.0_DP*IM*K0*DZ)\n SIGMA2 = -1.0_DP*Z/(3.0_DP*Z-2.0_DP*IM*K0*DZ)\n T(:,:) = 0.0_DP\n DO NZ = 2,N-1\n T(NZ,NZ-1) = 1.0_DP\n T(NZ,NZ) = -2.0_DP\n T(NZ,NZ+1) = 1.0_DP\n END DO\n T(1,1) = -2.0_DP+SIGMA1\n T(1,2) = 1.0_DP+SIGMA2\n T(N,N-1) = 1.0_DP+TAU2\n T(N,N) = -2.0_DP+TAU1\n E = DDIAG(CMPLX(ALT,0.0_DP,KIND=DPC),N)\n D = (IM/(2.0_DP*K0))*DDIAG(DK2,N)\n I = EYE(N)\n !-----------------------------------------------------------\n !-----------------------------------------------------------\n !System - M1 and M2\n ALLOCATE(M1(N,N),M2(N,N),MB2(NDIAG,N),MB1(NDIAG,N))\n C1 = CMPLX(1.0_DP,0.0_DP,KIND=DPC)\n C2 = CMPLX(0.0_DP,0.0_DP,KIND=DPC)\n SELECT CASE (WIDE_I)\n CASE(0)\n BETA1 = DR/2.0_DP\n BETA2 = -DR/2.0_DP\n CASE(1)\n BETA1 = 1.0_DP/(2.0_DP*IM*K0)+DR/2.0_DP\n BETA2 = 1.0_DP/(2.0_DP*IM*K0)-DR/2.0_DP\n CASE DEFAULT\n STOP \"[MAIN] : Enter valid wide-angle case\"\n END SELECT\n WRITE(*,*) \"Wide-angle order : \", WIDE\n M1 = I+A*BETA1*T+BETA1*D\n M2 = I+A*BETA2*T+BETA2*D\n MB1 = D2B(M1,N,KL,KU)\n MB2 = D2B(M2,N,KL,KU)\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\r\n !Forward-marching procedure\n ALLOCATE(MB2T(KL+NDIAG,N),IPIV(N),TEMP(N,1))\n MB2T(KL+1:KL+NDIAG,:) = MB2\n CALL CPU_TIME(TI)\n !-----------------------------------------------------------\n DO MX = 2,M+1\n WRITE(*,*) \"Step :\", MX-1, \"out of\", M\n !-------------------------------\n !Right hand side multiplication\n !-------------------------------\n CALL ZGBMV('N',N,N,KL,KU,C1,MB1,KL+KU+1,PHI(1:N,MX-1),1,C2,TEMP(:,1),1)\n WRITE(*,*) \".... Right-hand side multiplied\"\n !-------------------------------\n !System solving\n !-------------------------------\n CALL ZGBSV(N,KL,KU,1,MB2T,2*KL+KU+1,IPIV,TEMP,N,INFO) !Band matrix form\n IF (INFO.NE.0) THEN\n STOP \"ERROR : Matrix is singular\"\n END IF\n WRITE(*,*) \".... System solved\"\n !-------------------------------\n !Real pressure\n !-------------------------------\n PHI(1:N,MX) = TEMP(:,1)\r\n PC(1:N,MX-1) = EXP(IM*K0*(MX-1)*DR)*PHI(1:N,MX)*(1/SQRT((MX-1)*DR))\r\n P(1:N,MX-1) = REALPART(PC(1:N,MX-1))\r\n WRITE(*,*)\r\n END DO\n !-----------------------------------------------------------\r\n CALL CPU_TIME(TF)\r\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\r\n ALLOCATE(LP(N,M),LQ(N,M),LPG(M),LQG(M))\r\n P0 = ABS(PC(NS,1)) !Reference pressure (real)\r\n Q0 = ABS(QC(NS,1)) !Reference corrected pressure (real)\r\n DO MX = 1,M\r\n DO NZ = 1,N\r\n LP(NZ,MX) = 10.0_DP*LOG10(ABS(PC(NZ,MX))**2/(P0**2))\r\n LQ(NZ,MX) = 10.0_DP*LOG10(ABS(QC(NZ,MX))**2/(Q0**2))\r\n IF (LP(NZ,MX).LE.-120) THEN\r\n LP(NZ,MX) = -120\r\n LQ(NZ,MX) = -120\r\n END IF\r\n END DO\r\n END DO\r\n LP0 = LP(NS,1)\r\n LQ0 = LQ(NS,1)\r\n LPG = LP(1,1:M)\r\n LQG = LQ(1,1:M)\r\n LPR = LP(NR,M)\r\n LQR = LQ(NR,M)\r\n PR = SQRT(2.0_DP)*P0*10**(LPR/20)\r\n QR = SQRT(2.0_DP)*Q0*10**(LPR/20)\r\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\r\n !Output\r\n OPEN(UNIT=10,FILE=\"CNPE2_TL.dat\")\r\n OPEN(UNIT=20,FILE=\"CNPE2_FIELD.dat\")\r\n !OPEN(UNIT=30,FILE=\"CNPE2_PC.dat\")\r\n !OPEN(UNIT=50,FILE=\"CNPE2_Topo.dat\")\r\n DO MX = 1,M\r\n WRITE(10,100) MX*DR, 0.0, LPG(MX)\r\n DO NZ = 1,N\r\n WRITE(20,100) MX*DR, NZ*DZ, LP(NZ,MX)\r\n END DO\r\n WRITE(20,*)\r\n END DO\r\n 100 FORMAT(3(3X,F12.6))\r\n !101 FORMAT(4(3X,F12.6),3X,F12.6,SP,F12.6,SS,\"i\")\r\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\r\n DEALLOCATE(PHI,PC,QC,P,Q,LP,LQ)\n CALL SYSTEM('gnuplot -p plot_xterm.plt')\n CALL SYSTEM('gnuplot -p plot_xterm_contour.plt')\n WRITE(*,*) \"================================================\"\n WRITE(*,*) \"Input file : \", TOPO\n WRITE(*,*) \"================================================\"\n WRITE(*,*) \"Output file : CNPE2_TL.dat\"\n WRITE(*,*) \" CNPE2_FIELD.dat\"\n WRITE(*,*) \"================================================\"\n WRITE(*,*)\n WRITE(*,*) \"System size (N x M) :\", N, M\n WRITE(*,*) \"Step size :\", DR\n WRITE(*,*) \"Main CPU time (s) :\", TF-TI\n WRITE(*,*) \"Real pressure at the source - P0 (Pa) :\", P0\n WRITE(*,*) \"Real pressure at the target - PR (Pa) :\", PR\n WRITE(*,*) \"SPL/TL at the source - LP0 (dB) :\", LP0\n WRITE(*,*) \"SPL/TL at the target - LPR (dB) :\", LPR\n WRITE(*,*)\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\r\nEND PROGRAM CNPE2_HF\r\n", "meta": {"hexsha": "b5cafef15f0a5bdf149a6ff55325b3461c04e166", "size": 8337, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "Parabolic_Equation/2DPE/SRC/CNPE/CNPE2_HF.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/SRC/CNPE/CNPE2_HF.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/SRC/CNPE/CNPE2_HF.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": 35.1772151899, "max_line_length": 115, "alphanum_fraction": 0.3847906921, "num_tokens": 2724, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026573249611, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6924855285660988}} {"text": "FUNCTION dcosint(xvalue) RESULT(fn_val)\r\n\r\n! This program calculates the value of the cosine-integral\r\n! defined as\r\n\r\n! DCOSINT(x) = Gamma + Ln(x) + Integral (0 to x) [cos(t)-1]/t dt\r\n\r\n! where Gamma is Euler's constant.\r\n\r\n! The code uses rational approximations with a maximum accuracy of 20sf.\r\n\r\n\r\n! INPUT PARAMETER:\r\n\r\n! XVALUE - DOUBLE PRECISION - The argument to the function\r\n\r\n\r\n! MACHINE-DEPENDENT PARAMETERS:\r\n\r\n! XLOW - DOUBLE PRECISION - The absolute value below which\r\n! DCOSINT( x ) = gamma + LN(x) ,\r\n! to machine precision.\r\n! The recommended value is SQRT(2*EPSNEG)\r\n\r\n! XHIGH1 - DOUBLE PRECISION - The value above which\r\n! DCOSINT(x) = sin(x)/x - cos(x)/x^2\r\n! to machine precision.\r\n! The recommended value is SQRT(6/EPSNEG)\r\n\r\n! XHIGH2 - DOUBLE PRECISION - The value above which the trig. functions\r\n! cannot be accurately determined.\r\n! The value of the function is\r\n! DCOSINT(x) = 0.0\r\n! The recommended value is pi/EPS.\r\n\r\n! Values of EPS and EPSNEG for certain machine/compiler\r\n! combinations can be found in the paper\r\n\r\n! W.J. CODY Algorithm 665: MACHAR: A subroutine to dynamically\r\n! determine machine parameters, ACM Trans. Math. Soft. 14 (1988) 303-311.\r\n\r\n! The current code gives numerical values for XLOW,XHIGH1,XHIGH2\r\n! suitable for machines whose arithmetic conforms to the IEEE\r\n! standard. The codes will probably work on other machines\r\n! but might overflow or underflow for certain arguments.\r\n\r\n! AUTHOR: Allan MacLeod\r\n! Dept. of Mathematics and Statistics\r\n! University of Paisley\r\n! Scotland\r\n! (e-mail: macl_ms0@paisley.ac.uk)\r\n\r\nIMPLICIT NONE\r\nINTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(14, 60)\r\nREAL (dp), INTENT(IN) :: xvalue\r\nREAL (dp) :: fn_val\r\n\r\n! Local variables\r\nINTEGER :: i\r\nREAL (dp) :: cx, dif, fival, gival, logval, root, sum, sumden, sumnum, &\r\n sx, x, xsq\r\n\r\n! DATA VALUES\r\n\r\nREAL (dp), PARAMETER :: zero = 0.0_dp, one = 1.0_dp, three = 3.0_dp, &\r\n six = 6.0_dp, twelve = 12.0_dp\r\nREAL (dp), PARAMETER :: gamma = 0.57721566490153286060_dp\r\nREAL (dp), PARAMETER :: logl1 = 0.046875_dp, logl2 = 0.25_dp\r\n\r\n! MACHINE-DEPENDENT PARAMETERS (SUITABLE FOR IEEE MACHINES)\r\n\r\nREAL (dp), PARAMETER :: xlow = 1.48996E-8_dp, xhigh1 = 2.324953E8_dp, &\r\n xhigh2 = 1.4148475E16_dp\r\n\r\n! VALUES FOR COS-INTEGRAL FOR 0 < X <= 3\r\n\r\nREAL (dp), PARAMETER :: ac1n(0:5) = (/ -0.24607411378767540707_dp, &\r\n 0.72113492241301534559E-2_dp, -0.11867127836204767056E-3_dp, &\r\n 0.90542655466969866243E-6_dp, -0.34322242412444409037E-8_dp, &\r\n 0.51950683460656886834E-11_dp /)\r\nREAL (dp), PARAMETER :: ac1d(0:5) = (/ 1.0_dp, 0.12670095552700637845E-1_dp, &\r\n 0.78168450570724148921E-4_dp, 0.29959200177005821677E-6_dp, &\r\n 0.73191677761328838216E-9_dp, 0.94351174530907529061E-12_dp /)\r\n\r\n! VALUES FOR COS-INTEGRAL FOR 3 < X <= 6\r\n\r\nREAL (dp), PARAMETER :: ac2n(0:7) = (/ -0.15684781827145408780_dp, &\r\n 0.66253165609605468916E-2_dp, -0.12822297297864512864E-3_dp, &\r\n 0.12360964097729408891E-5_dp, -0.66450975112876224532E-8_dp, &\r\n 0.20326936466803159446E-10_dp, -0.33590883135343844613E-13_dp, &\r\n 0.23686934961435015119E-16_dp /)\r\nREAL (dp), PARAMETER :: ac2d(0:6) = (/ 1.0_dp, 0.96166044388828741188E-2_dp, &\r\n 0.45257514591257035006E-4_dp, 0.13544922659627723233E-6_dp, &\r\n 0.27715365686570002081E-9_dp, 0.37718676301688932926E-12_dp, &\r\n 0.27706844497155995398E-15_dp /)\r\n\r\n! VALUES FOR FI(X) FOR 6 <= X <= 12\r\n\r\nREAL (dp), PARAMETER :: afn1(0:7) = (/ 0.99999999962173909991E0_dp, &\r\n 0.36451060338631902917E3_dp, 0.44218548041288440874E5_dp, &\r\n 0.22467569405961151887E7_dp, 0.49315316723035561922E8_dp, &\r\n 0.43186795279670283193E9_dp, 0.11847992519956804350E10_dp, &\r\n 0.45573267593795103181E9_dp /)\r\nREAL (dp), PARAMETER :: afd1(0:7) = (/ 1.0_dp, 0.36651060273229347594E3_dp, &\r\n 0.44927569814970692777E5_dp, 0.23285354882204041700E7_dp, &\r\n 0.53117852017228262911E8_dp, 0.50335310667241870372E9_dp, &\r\n 0.16575285015623175410E10_dp, 0.11746532837038341076E10_dp /)\r\n\r\n! VALUES OF GI(X) FOR 6 <= X <=12\r\n\r\nREAL (dp), PARAMETER :: agn1(0:8) = (/ 0.99999999920484901956E0_dp, &\r\n 0.51385504875307321394E3_dp, 0.92293483452013810811E5_dp, &\r\n 0.74071341863359841727E7_dp, 0.28142356162841356551E9_dp, &\r\n 0.49280890357734623984E10_dp, 0.35524762685554302472E11_dp, &\r\n 0.79194271662085049376E11_dp, 0.17942522624413898907E11_dp /)\r\nREAL (dp), PARAMETER :: agd1(0:8) = (/ 1.0_dp, 0.51985504708814870209E3_dp, &\r\n 0.95292615508125947321E5_dp, 0.79215459679762667578E7_dp, &\r\n 0.31977567790733781460E9_dp, 0.62273134702439012114E10_dp, &\r\n 0.54570971054996441467E11_dp, 0.18241750166645704670E12_dp, &\r\n 0.15407148148861454434E12_dp /)\r\n\r\n! VALUES FOR FI(X) FOR X > 12\r\n\r\nREAL (dp), PARAMETER :: afn2(0:7) = (/ 0.19999999999999978257E1_dp, &\r\n 0.22206119380434958727E4_dp, 0.84749007623988236808E6_dp, &\r\n 0.13959267954823943232E9_dp, 0.10197205463267975592E11_dp, &\r\n 0.30229865264524075951E12_dp, 0.27504053804288471142E13_dp, &\r\n 0.21818989704686874983E13_dp /)\r\nREAL (dp), PARAMETER :: afd2(0:7) = (/ 1.0_dp, 0.11223059690217167788E4_dp, &\r\n 0.43685270974851313242E6_dp, 0.74654702140658116258E8_dp, &\r\n 0.58580034751805687471E10_dp, 0.20157980379272098841E12_dp, &\r\n 0.26229141857684496445E13_dp, 0.87852907334918467516E13_dp /)\r\n\r\n! VALUES FOR GI(X) FOR X > 12\r\n\r\nREAL (dp), PARAMETER :: agn2(0:8) = (/ 0.59999999999999993089E1_dp, &\r\n 0.96527746044997139158E4_dp, 0.56077626996568834185E7_dp, &\r\n 0.15022667718927317198E10_dp, 0.19644271064733088465E12_dp, &\r\n 0.12191368281163225043E14_dp, 0.31924389898645609533E15_dp, &\r\n 0.25876053010027485934E16_dp, 0.12754978896268878403E16_dp /)\r\nREAL (dp), PARAMETER :: agd2(0:8) = (/ 1.0_dp, 0.16287957674166143196E4_dp, &\r\n 0.96636303195787870963E6_dp, 0.26839734750950667021E9_dp, &\r\n 0.37388510548029219241E11_dp, 0.26028585666152144496E13_dp, &\r\n 0.85134283716950697226E14_dp, 0.11304079361627952930E16_dp, &\r\n 0.42519841479489798424E16_dp /)\r\n\r\n! VALUES FOR AN APPROXIMATION TO LN(X/ROOT)\r\n\r\nREAL (dp), PARAMETER :: p(0:2) = (/ 0.83930008362695945726E1_dp, &\r\n -0.65306663899493304675E1_dp, 0.569155722227490223_dp /)\r\nREAL (dp), PARAMETER :: q(0:1) = (/ 0.41965004181347972847E1_dp, &\r\n -0.46641666676862479585E1_dp /)\r\n\r\n! VALUES OF THE FIRST TWO ROOTS OF THE COSINE-INTEGRAL\r\n\r\nREAL (dp), PARAMETER :: rt1n = 631.0_dp, rt1d = 1024.0_dp, &\r\n rt1r = 0.29454812071623379711E-3_dp\r\nREAL (dp), PARAMETER :: rt2n = 3465.0_dp, rt2d = 1024.0_dp, &\r\n rt2r = 0.39136005118642639785E-3_dp\r\n\r\n! START COMPUTATION\r\n\r\nx = xvalue\r\nIF ( x <= zero ) THEN\r\n fn_val = zero\r\n RETURN\r\nEND IF\r\nIF ( x <= six ) THEN\r\n \r\n! CODE FOR 3 < X < = 6\r\n \r\n IF ( x > three ) THEN\r\n sumnum = zero\r\n sumden = zero\r\n xsq = x * x\r\n DO i = 7 , 0 , -1\r\n sumnum = sumnum * xsq + ac2n( i )\r\n END DO\r\n DO i = 6 , 0 , -1\r\n sumden = sumden * xsq + ac2d( i )\r\n END DO\r\n root = rt2n / rt2d\r\n dif = ( x - root ) - rt2r\r\n sum = root + rt2r\r\n IF ( ABS(dif) < logl2 ) THEN\r\n cx = dif / ( sum + x )\r\n xsq = cx * cx\r\n sx = p(0) + xsq * ( p(1) + xsq * p(2) )\r\n sx = sx / ( q(0) + xsq * ( q(1) + xsq ) )\r\n logval = cx * sx\r\n ELSE\r\n logval = LOG( x / sum )\r\n END IF\r\n fn_val = logval + dif * ( x + sum ) * sumnum / sumden\r\n ELSE\r\n \r\n! CODE FOR 0 < X < = 3\r\n \r\n IF ( x > xlow ) THEN\r\n sumnum = zero\r\n sumden = zero\r\n xsq = x * x\r\n DO i = 5 , 0 , -1\r\n sumnum = sumnum * xsq + ac1n( i )\r\n sumden = sumden * xsq + ac1d( i )\r\n END DO\r\n root = rt1n / rt1d\r\n dif = ( x - root ) - rt1r\r\n sum = root + rt1r\r\n IF ( ABS(dif) < logl1 ) THEN\r\n cx = dif / ( sum + x )\r\n xsq = cx * cx\r\n sx = p(0) + xsq * ( p(1) + xsq * p(2) )\r\n sx = sx / ( q(0) + xsq * ( q(1) + xsq ) )\r\n logval = cx * sx\r\n ELSE\r\n logval = LOG( x / sum )\r\n END IF\r\n fn_val = logval + dif * ( x + sum ) * sumnum / sumden\r\n ELSE\r\n fn_val = gamma + LOG( x )\r\n END IF\r\n END IF\r\nEND IF\r\n\r\n! CODE FOR 6 < X < = 12\r\n\r\nIF ( x > six .AND. x <= twelve ) THEN\r\n sumnum = zero\r\n sumden = zero\r\n xsq = one / ( x * x )\r\n DO i = 7 , 0 , -1\r\n sumnum = sumnum * xsq + afn1( i )\r\n sumden = sumden * xsq + afd1( i )\r\n END DO\r\n fival = sumnum / ( x * sumden )\r\n sumnum = zero\r\n sumden = zero\r\n DO i = 8 , 0 , -1\r\n sumnum = sumnum * xsq + agn1( i )\r\n sumden = sumden * xsq + agd1( i )\r\n END DO\r\n gival = xsq * sumnum / sumden\r\n fn_val = fival * SIN( x ) - gival * COS( x )\r\nEND IF\r\n\r\n! CODE FOR X > 12\r\n\r\nIF ( x > twelve ) THEN\r\n IF ( x > xhigh2 ) THEN\r\n fn_val = zero\r\n ELSE\r\n cx = COS( x )\r\n sx = SIN( x )\r\n xsq = one / ( x * x )\r\n IF ( x > xhigh1 ) THEN\r\n fn_val = sx / x - cx * xsq\r\n ELSE\r\n sumnum = zero\r\n sumden = zero\r\n DO i = 7 , 0 , -1\r\n sumnum = sumnum * xsq + afn2( i )\r\n sumden = sumden * xsq + afd2( i )\r\n END DO\r\n fival = ( one - xsq * sumnum / sumden ) / x\r\n sumnum = zero\r\n sumden = zero\r\n DO i = 8 , 0 , -1\r\n sumnum = sumnum * xsq + agn2( i )\r\n sumden = sumden * xsq + agd2( i )\r\n END DO\r\n gival = ( one - xsq * sumnum / sumden ) * xsq\r\n fn_val = sx * fival - cx * gival\r\n END IF\r\n END IF\r\nEND IF\r\n\r\nRETURN\r\nEND FUNCTION dcosint\r\n", "meta": {"hexsha": "9462ee59e9476e7689f860f9c03280d49f06379d", "size": 10396, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/dcosint.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/dcosint.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/dcosint.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": 37.1285714286, "max_line_length": 81, "alphanum_fraction": 0.5694497884, "num_tokens": 3806, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026505426831, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.692485513330085}} {"text": "program while_01\nimplicit none\ninteger :: i, j\ni = 1\nj = 0\ndo while (i < 11)\n j = j + i\n i = i + 1\nend do\nif (j /= 55) error stop\nif (i /= 11) error stop\n\ni = 1\nj = 0\ndo while (i <= 10)\n j = j + i\n i = i + 1\nend do\nif (j /= 55) error stop\nif (i /= 11) error stop\n\ni = 1\nj = 0\ndo while (i < 1)\n j = j + i\n i = i + 1\nend do\nif (j /= 0) error stop\nif (i /= 1) error stop\nend\n", "meta": {"hexsha": "004695c25f343b87591bf16307bd1fcd8af58fea", "size": 390, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "integration_tests/while_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": "integration_tests/while_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": 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/while_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": 12.5806451613, "max_line_length": 23, "alphanum_fraction": 0.5, "num_tokens": 184, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706734, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.6924703043122117}} {"text": "! { dg-do run }\n! PR51634 - Handle allocatable components correctly in expressions \n! involving typebound operators. From comment 2 of PR but using\n! classes throughout.\n!\n! Reported by Tobias Burnus \n! \nmodule soop_stars_class\n implicit none\n type soop_stars\n real, dimension(:), allocatable :: position,velocity\n contains\n procedure :: total\n procedure :: mult\n procedure :: assign\n generic :: operator(+) => total\n generic :: operator(*) => mult\n generic :: assignment(=) => assign\n end type\ncontains\n function mult(lhs,rhs)\n class(soop_stars) ,intent(in) :: lhs\n real ,intent(in) :: rhs\n class(soop_stars), allocatable :: mult\n type(soop_stars) :: tmp\n tmp = soop_stars (lhs%position*rhs, lhs%velocity*rhs)\n allocate (mult, source = tmp)\n end function\n\n function total(lhs,rhs)\n class(soop_stars) ,intent(in) :: lhs,rhs\n class(soop_stars), allocatable :: total\n type(soop_stars) :: tmp\n tmp = soop_stars (lhs%position + rhs%position, &\n lhs%velocity + rhs%velocity)\n allocate (total, source = tmp)\n end function\n\n subroutine assign(lhs,rhs)\n class(soop_stars), intent(in) :: rhs\n class(soop_stars), intent(out) :: lhs\n lhs%position = rhs%position\n lhs%velocity = rhs%velocity\n end subroutine\nend module\n\nprogram main\n use soop_stars_class ,only : soop_stars\n implicit none\n class(soop_stars), allocatable :: fireworks\n real :: dt\n allocate (fireworks, source = soop_stars ([1,2,3], [4,5,6]))\n dt = 5\n fireworks = fireworks + fireworks*dt\n if (any (fireworks%position .ne. [6, 12, 18])) STOP 1\n if (any (fireworks%velocity .ne. [24, 30, 36])) STOP 2\nend program\n", "meta": {"hexsha": "96c4f32da3947e170ad703e1fe1e26b9fe201d13", "size": 1692, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/typebound_operator_13.f03", "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/typebound_operator_13.f03", "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/typebound_operator_13.f03", "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": 29.1724137931, "max_line_length": 67, "alphanum_fraction": 0.6713947991, "num_tokens": 497, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199552262967, "lm_q2_score": 0.8267117962054048, "lm_q1q2_score": 0.6924702977226225}} {"text": "\nprogram test2\n\n use mpi\n\n use quadrature, only: trapezoid\n use functions, only: f, fevals_proc, k\n\n implicit none\n real(kind=8) :: a,b,int_true, int_approx, int_sub, dx_sub\n real(kind=8) :: ab_sub(2) ! to hold a and b for each subinterval\n\n integer :: i,j,jj,n_proc,proc_num, num_procs,ierr,n,fevals_total,nsub\n integer, dimension(MPI_STATUS_SIZE) :: status\n logical :: debug\n\n debug = .false.\n\n call MPI_INIT(ierr)\n call MPI_COMM_SIZE(MPI_COMM_WORLD, num_procs, ierr)\n call MPI_COMM_RANK(MPI_COMM_WORLD, proc_num, ierr)\n\n ! All processes set these values so we don't have to broadcast:\n k = 1.d3 ! functions module variable \n a = 0.d0\n b = 2.d0\n int_true = (b-a) + (b**4 - a**4) / 4.d0 - (1.d0/k) * (cos(k*b) - cos(k*a))\n n = 1000 ! points per subinterval\n nsub = num_procs - 1 ! number of subintervals\n\n ! Each process keeps track of number of fevals:\n fevals_proc = 0\n\n if (proc_num==0) then\n print '(\"Using \",i3,\" processes\")', num_procs\n print '(\"true integral: \", es22.14)', int_true\n print *, \" \" ! blank line\n\n int_approx = 0.d0 ! initialize variable for accumulating integral\n\n endif\n\n call MPI_BARRIER(MPI_COMM_WORLD,ierr) ! wait for process 0 to print\n\n ! -----------------------------------------\n ! code for Master (Processor 0):\n ! -----------------------------------------\n\n if (proc_num == 0) then\n\n dx_sub = (b-a) / nsub\n\n do j=1,nsub\n ab_sub(1) = a + (j-1)*dx_sub\n ab_sub(2) = a + j*dx_sub\n call MPI_SEND(ab_sub, 2, MPI_DOUBLE_PRECISION, j, j, &\n MPI_COMM_WORLD, ierr)\n enddo\n\n do j=1,nsub\n call MPI_RECV(int_sub, 1, MPI_DOUBLE_PRECISION, &\n MPI_ANY_SOURCE, MPI_ANY_TAG, &\n MPI_COMM_WORLD, status, ierr)\n jj = status(MPI_TAG)\n if (debug) then\n print *,\"+++ int_sub, int_approx: \",int_sub, int_approx\n endif\n int_approx = int_approx + int_sub\n\n enddo\n endif\n\n ! -----------------------------------------\n ! code for Workers (Processors 1, 2, ...):\n ! -----------------------------------------\n if (proc_num /= 0) then\n\n call MPI_RECV(ab_sub, 2, MPI_DOUBLE_PRECISION, &\n 0, MPI_ANY_TAG, &\n MPI_COMM_WORLD, status, ierr)\n\n j = status(MPI_TAG) ! this is the subinterval number\n\n if (debug) then\n print '(\"+++ Process \",i4,\" received message with tag \",i6)', &\n proc_num, j ! for debugging\n endif\n\n int_sub = trapezoid(f,ab_sub(1),ab_sub(2),n)\n\n call MPI_SEND(int_sub, 1, MPI_DOUBLE_PRECISION, &\n 0, j, MPI_COMM_WORLD, ierr)\n\n endif\n\n\n call MPI_BARRIER(MPI_COMM_WORLD,ierr) ! wait for all process to print\n\n ! print the number of function evaluations by each thread:\n print '(\"fevals by Process \",i2,\": \",i13)', proc_num, fevals_proc\n\n call MPI_BARRIER(MPI_COMM_WORLD,ierr) ! wait for all process to print\n\n call MPI_REDUCE(fevals_proc, fevals_total, 1, MPI_INTEGER, MPI_SUM, 0, &\n MPI_COMM_WORLD, ierr)\n\n if (proc_num==0) then\n print '(\"Trapezoid approximation with \",i8,\" total points: \",es22.14)',&\n nsub*n, int_approx\n print '(\"Total number of fevals: \",i10)', fevals_total\n endif\n\n call MPI_FINALIZE(ierr)\n\nend program test2\n", "meta": {"hexsha": "4d488929adea4c381983ec654e83d3b96a76880d", "size": 3498, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/2013/solutions/homework6/test2.f90", "max_stars_repo_name": "philipwangdk/HPC", "max_stars_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "uwhpsc/2013/solutions/homework6/test2.f90", "max_issues_repo_name": "philipwangdk/HPC", "max_issues_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "uwhpsc/2013/solutions/homework6/test2.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": 30.1551724138, "max_line_length": 80, "alphanum_fraction": 0.5546026301, "num_tokens": 958, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117769928211, "lm_q2_score": 0.8376199552262967, "lm_q1q2_score": 0.692470281629779}} {"text": "! ==================================================================================\n! Purpose: This subroutine computes roots of the water-wave dispersion equation \n! in finite water depth, by using a higher-order iterative method\n!\n! License:\n! \n! This routine is part of FinGreen3D.\n!\n! FinGreen3D is a free software package: you can redistribute it and/or modify it\n! under the terms of the GNU Lesser General Public License as published by the\n! Free Software Foundation, either version 3 of the License, or (at your option) \n! any later version.\n!\n! You should have received a copy of the GNU General Public License (either V3 \n! or later), along with FinGreen3D. If not, see .\n!\n! Author:\n! \n! Yingyi Liu on Mar.23, 2017\n! \n! Reference:\n! \n! Yingyi Liu, Shigeo Yoshida, Liang Sun, Junliang Gao\n! FinGreen3D: An efficient open-source package for computing free-surface \n! Green's function in finite water depth using new region-decomposition \n! strategy with applications to wave-structure interactions\n! Computer Physics Communications, 2016\n! \n! J.N. Newman\n! Numerical solutions of the water-wave dispersion relation\n! Applied Ocean Research 12 (1990) 14-18\n!\n! Parameters:\n! Input: NRT --- Integer, the number of roots required\n! W --- Real, wave angular frequency\n! H --- Real, water depth (h>0)\n! Output: WVN --- Real, an array storing roots of the dispersion equation\n! ==================================================================================\n \n SUBROUTINE DISPERSION(WVN,NRT,W,H)\n!\n! Evaluation of the roots of the following equations \n! by higher-order iterative method\n! first root stored in WVN is from Eq. (i)\n! the rest roots are from Eq. (ii)\n! i) w*w/g = k tanh ( kh )\n! ii) -w*w/g = Um tan ( Umh )\n!\n\n IMPLICIT NONE\n INTEGER,INTENT(IN):: NRT\n REAL*8,INTENT(IN):: W,H\n REAL*8,INTENT(OUT):: WVN(1:NRT)\n INTEGER I, M\n REAL*8 T,X,U,Y,DNM,G,PI\n REAL*8 FUN,DFUN,D2FUN,TRIAL,EXX\n\n DATA G,PI/9.807d0,3.141592653589793d0/\n\n!------------------------------------------------------------------\n! I. calculation of wave number (root of Eq. (i))\n!------------------------------------------------------------------\n!\n! initialize iteration by an accurate Chebyshev approximation\n! if y=x, use the approximation directly insteady of iteration\n! to avoid the singularity in the denomenator of the transcendental\n! function; otherwise, do the iterative procedure. \n!\n X=W*W*H/G\n IF (X.GT.0.D0.AND.X.LE.2.D0) THEN\n Y=DSQRT(X)*(0.9994D0+0.1701D0*X+0.0305*X*X)\n ELSE\n T=X*DEXP(-2.D0*X)\n Y=X+2.D0*T-6.D0*T*T\n ENDIF\n\n IF (DABS(Y-X).LT.1.E-10) THEN\n WVN(1)=X/H\n ELSE\n M=0\n EXX=1.D0\n DO WHILE (EXX.GT.1.0D-10)\n TRIAL=Y\n DNM=TRIAL*TRIAL-X*X\n FUN=DLOG((TRIAL+X)/(TRIAL-X))/2.D0-TRIAL\n DFUN=-X/DNM-1.D0\n D2FUN=2.D0*X*TRIAL/(DNM*DNM)\n Y=TRIAL-FUN/DFUN*(1.D0+(FUN/DFUN)*(D2FUN/DFUN)/2.D0)\n EXX=DABS(Y-TRIAL)\n M=M+1\n ENDDO\n WVN(1)=Y/H\n ENDIF\n\n!------------------------------------------------------------------\n! II. calcultion of roots of Eq. (ii), which characterizes\n! the evanescene modes in eigenfucntion\n!------------------------------------------------------------------\n!\n! initialize iteration by a suitable starting approximation\n!\n U=3.D0*X/(7.D0+3.D0*X)\n T=0.0159D0+0.1032D0*U+4.3152D0*U*U-2.8768D0*U*U*U\n!\n! perform iterative procedure to find exact solution of Um (m=1,..NRT-1)\n! of the transcendental equation Eq. (ii)\n!\n DO I=2,NRT\n M=0\n EXX=1.D0\n DO WHILE (EXX.GT.1.0D-10)\n TRIAL=T\n Y=(I-1)*PI-TRIAL\n DNM=Y*Y+X*X\n FUN=ATAN2(X,Y)-TRIAL\n DFUN=X/DNM-1.D0\n D2FUN=2.D0*X*TRIAL/(DNM*DNM)\n T=TRIAL-FUN/DFUN*(1.D0+(FUN/DFUN)*(D2FUN/DFUN)/2.D0)\n EXX=DABS(T-TRIAL)\n M=M+1\n ENDDO\n Y=(I-1)*PI-T\n WVN(I)=Y/H\n T=T-PI*X/(X*X+PI*I*(PI*(I-1)-T))\n ENDDO\n\n END SUBROUTINE DISPERSION", "meta": {"hexsha": "0266ebe0b12f32bf9945df34f2c5d3f46890b049", "size": 4176, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "pyhams/src/WavDynSubs.f90", "max_stars_repo_name": "shousner/pyHAMS", "max_stars_repo_head_hexsha": "2ad2598bac92e17e78c8b120d6d09710a9dd5046", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 53, "max_stars_repo_stars_event_min_datetime": "2020-11-03T02:03:01.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-10T10:26:04.000Z", "max_issues_repo_path": "pyhams/src/WavDynSubs.f90", "max_issues_repo_name": "shousner/pyHAMS", "max_issues_repo_head_hexsha": "2ad2598bac92e17e78c8b120d6d09710a9dd5046", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 90, "max_issues_repo_issues_event_min_datetime": "2020-08-24T23:02:47.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T13:48:15.000Z", "max_forks_repo_path": "pyhams/src/WavDynSubs.f90", "max_forks_repo_name": "shousner/pyHAMS", "max_forks_repo_head_hexsha": "2ad2598bac92e17e78c8b120d6d09710a9dd5046", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 30, "max_forks_repo_forks_event_min_datetime": "2020-11-03T02:03:07.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-28T13:03:18.000Z", "avg_line_length": 32.8818897638, "max_line_length": 84, "alphanum_fraction": 0.5502873563, "num_tokens": 1289, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.920789673717312, "lm_q2_score": 0.7520125848754472, "lm_q1q2_score": 0.6924454226587754}} {"text": "! Program to test SELECTED_INT_KIND intrinsic function.\nProgram test_si_kind\n integer*1 i1\n integer*2 i2\n integer*4 i4\n integer*8 i8\n integer res\n real t\n\n t = huge (i1)\n t = log10 (t)\n res = selected_int_kind (int (t))\n if (res .ne. 1) call abort\n\n t = huge (i2)\n t = log10 (t)\n res = selected_int_kind (int (t))\n if (res .ne. 2) call abort\n\n t = huge (i4)\n t = log10 (t)\n res = selected_int_kind (int (t))\n if (res .ne. 4) call abort\n\n t = huge (i8)\n t = log10 (t)\n res = selected_int_kind (int (t))\n if (res .ne. 8) call abort\n\n i4 = huge (i4)\n res = selected_int_kind (i4)\n if (res .ne. (-1)) call abort\n\nend program\n\n", "meta": {"hexsha": "b231dc66ebe5887a841519cac37d23aae333f27e", "size": 647, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_si_kind.f90", "max_stars_repo_name": "best08618/asylo", "max_stars_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-05-02T17:34:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-17T10:15:18.000Z", "max_issues_repo_path": "llvm-gcc-4.2-2.9/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_si_kind.f90", "max_issues_repo_name": "vidkidz/crossbridge", "max_issues_repo_head_hexsha": "ba0bf94aee0ce6cf7eb5be882382e52bc57ba396", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "llvm-gcc-4.2-2.9/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_si_kind.f90", "max_forks_repo_name": "vidkidz/crossbridge", "max_forks_repo_head_hexsha": "ba0bf94aee0ce6cf7eb5be882382e52bc57ba396", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-27T00:22:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-01T09:41:02.000Z", "avg_line_length": 17.9722222222, "max_line_length": 55, "alphanum_fraction": 0.6151468315, "num_tokens": 247, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896802383028, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6924454173274668}} {"text": "\n\n!! ketot is matrix elements of -1/2 d^2/dx^2 in sinc function basis\n\nsubroutine sineDVR(ketot,fdtot, points,gridpoints,spacing)\n implicit none\n integer,intent(in) :: gridpoints\n real*8,intent(in) :: spacing\n real*8,intent(out) :: ketot(1-gridpoints:gridpoints-1),points(gridpoints),&\n fdtot(1-gridpoints:gridpoints-1)\n integer :: i\n real*8 :: mypi\n\n myPi = 4d0*atan(1d0)\n\n do i=1,gridpoints\n points(i) = i*spacing\n enddo\n\n points(:)=points(:)-(points(1)+points(gridpoints))/2d0\n\n do i=1-gridpoints,gridpoints-1\n if (i==0) then\n ketot(i) = myPi**2/3.d0\n fdtot(i) = 0d0\n else\n ketot(i) = 2.d0/real(i,8)**2 * (-1)**(i)\n fdtot(i) = 1d0/real(i,8) * (-1)**(i)\n endif\n enddo\n\n ketot=ketot/2.d0/spacing**2 \n fdtot=fdtot/spacing\n\nend subroutine sineDVR\n\n\n\n \n\n\n\n\n\n", "meta": {"hexsha": "7bfcd936bac1145438f20d2cda8490c6f14904ad", "size": 824, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "MCTDH.SRC/SINCDVR/SineDVR.f90", "max_stars_repo_name": "danhax/V1-temp", "max_stars_repo_head_hexsha": "efbcba25dbd8550e62f1a83ce8c2328a30659466", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2016-02-08T05:46:15.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-23T12:27:36.000Z", "max_issues_repo_path": "MCTDH.SRC/SINCDVR/SineDVR.f90", "max_issues_repo_name": "danhax/V1-temp", "max_issues_repo_head_hexsha": "efbcba25dbd8550e62f1a83ce8c2328a30659466", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 18, "max_issues_repo_issues_event_min_datetime": "2015-12-21T19:20:36.000Z", "max_issues_repo_issues_event_max_datetime": "2020-11-20T06:22:29.000Z", "max_forks_repo_path": "MCTDH.SRC/SINCDVR/SineDVR.f90", "max_forks_repo_name": "danhax/V1-temp", "max_forks_repo_head_hexsha": "efbcba25dbd8550e62f1a83ce8c2328a30659466", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-03-04T17:35:46.000Z", "max_forks_repo_forks_event_max_datetime": "2018-03-02T03:11:23.000Z", "avg_line_length": 18.3111111111, "max_line_length": 77, "alphanum_fraction": 0.6140776699, "num_tokens": 319, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436482, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6924454056713892}} {"text": "program Map\n implicit none\n\n real :: t\n integer :: i\n\n do i = 0, 10\n t = Maprange((/0.0, 10.0/), (/-1.0, 0.0/), real(i))\n write(*,*) i, \" maps to \", t\n end do\n\ncontains\n\nfunction Maprange(a, b, s)\n real :: Maprange\n real, intent(in) :: a(2), b(2), s\n\n Maprange = (s-a(1)) * (b(2)-b(1)) / (a(2)-a(1)) + b(1)\n\nend function Maprange\nend program Map\n", "meta": {"hexsha": "02231f7a8b9c23c95cb5536f12524b800eb68368", "size": 360, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Map-range/Fortran/map-range.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/Map-range/Fortran/map-range.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/Map-range/Fortran/map-range.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.3636363636, "max_line_length": 56, "alphanum_fraction": 0.5305555556, "num_tokens": 154, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148513, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6923789351689823}} {"text": "! **\n! * Provides a demo model to be solved by the non-concave EGM algorithm. The input model is taken as is from Fella (2011).\n! **\nmodule demo_fella11\n use kinds, only: dp\n use ncegm, only: ncegm_model,ncegm_setup,ncegm_solve\n use grids, only: build_grid\n use tauchen, only: tauchen_discretize\n implicit none\n private\n save\n public :: start_demo_fella2011\n\n ! *******************************************************************************************************\n ! ** Model parameters (Fella, 2011)\n ! *******************************************************************************************************\n\n integer, parameter :: len_a_grid = 400 ! asset grid size\n real (dp), parameter :: theta= .77d0 ! non-durables weight\n real (dp), parameter :: tau = 0.d0 ! .2435d0! intratemporal elast.\n real (dp), parameter :: kappa = .075d0 ! flow of house servic.\n real (dp), parameter :: bita= 0.93d0 ! discount factor\n\n real (dp), parameter :: rho_yp = .977d0\n real (dp), parameter :: mu0_yp = 0.d0\n real (dp), parameter :: sigma_yp = .024d0\n\n real (dp), parameter :: rho_yt= .0d0\n real (dp), parameter :: mu0_yt = .0d0\n real (dp), parameter :: sigma_yt = .063d0\n real (dp), parameter :: downp= .2d0 ! downpayment ratio\n real (dp), parameter :: gamma_= .06d0 ! percentage transaction cost\n\n\n ! *******************************************************************************************************\n ! ** Numerical parameters\n ! *******************************************************************************************************\n real (dp), parameter :: min_a= 0.d0 ! lower bound on assets\n real (dp), parameter :: max_a= 25.d0 ! upper bound on assets\n real (dp), parameter :: min_h= 1.d-2 ! lower bound on housing size\n real (dp), parameter :: max_h = 10.0 ! upper bound on housing\n integer, parameter :: len_yp_grid = 7 ! persistent shock grid size\n real(dp), parameter :: cover_yp = 3.d0 ! cover 3 sd each side\n integer, parameter :: len_yt_grid = 7 ! persistent shock grid size\n real(dp), parameter :: cover_yt = 3.d0 ! cover 3 sd each side\n integer, parameter :: len_h_grid = 7 ! number of housing choices\n integer, parameter :: len_y_grid = len_yp_grid*len_yt_grid ! Income grid\n\n\n ! *******************************************************************************************************\n ! ** Grids\n ! *******************************************************************************************************\n real(dp), dimension(len_a_grid) :: a_grid\n real(dp), dimension(len_h_grid) :: sd_grid\n real(dp), dimension(len_y_grid) :: z_grid\n real(dp), dimension(len_y_grid,len_y_grid) :: z_transition\n\n contains\n\n ! **\n ! * Sets up and solves the model from Fella (2011)\n ! **\n subroutine start_demo_fella2011()\n type(ncegm_model) :: m\n logical :: status\n real(dp), dimension(len_a_grid, len_h_grid, len_y_grid), target :: vfguess\n\n ! Setup the grids\n a_grid = build_grid(len_a_grid, min_a, max_a,2)\n sd_grid = build_grid(len_h_grid, min_h, max_h,0)\n call fella_create_zgrid_and_transition(z_grid, z_transition)\n\n ! Compute an initial guess for the value function\n vfguess = vfinitialguess()\n\n ! Allocate the grids and arrays of the model\n allocate(m%a_grid(len_a_grid),m%d_grid(len_h_grid),m%s_grid(len_h_grid),m%z_grid(len_y_grid))\n allocate(m%V_initial(len_a_grid,len_h_grid,len_y_grid))\n allocate(m%z_transition(len_y_grid,len_y_grid))\n\n ! Specify return function and derivatives\n m%F=>u\n m%dF=>du\n m%d2F=>d2u\n ! Specify budget constraint Lambda and, optionally, its derivative\n m%Lambda => Lambda\n m%dLambda => dLambda\n ! Specify transition function for state variable s\n m%Psi=>Psi\n ! Specify Markov matrix for the transition of the stochastic variable z\n m%z_transition=z_transition\n ! Specify the grids for A, D, S and Z (note that the grids for D and S are the same)\n m%a_grid=a_grid\n m%d_grid=sd_grid\n m%s_grid=sd_grid\n m%z_grid=z_grid\n ! Specify an initial guess for the value function\n m%V_initial=vfguess\n ! Finally, specify discount factor beta\n m%beta=bita\n m%state_independent_foc_and_f=.TRUE.\n\n call ncegm_setup(m,status)\n if (status) call ncegm_solve()\n\n end subroutine start_demo_fella2011\n\n\n ! *******************************************************************************************************\n ! ** Model functions\n ! *******************************************************************************************************\n\n function u(c,d,s,z)\n real(dp), dimension(:), intent(in) :: c\n real(dp), intent(in) :: d,s,z\n real(dp), dimension(size(c)) :: u\n if (tau.NE.0.d0) then\n u = LOG(theta*c**tau+(1.d0-theta)*(kappa*d)**tau)/tau\n else\n u = theta*LOG(c)+(1.d0-theta)*LOG(kappa*d)\n end if\n end function u\n\n function du(c,d,s,z)\n real(dp), dimension(:), intent(in) :: c\n real(dp), intent(in) :: d,s,z\n real(dp), dimension(size(c)) :: du\n\n du = theta*c**(tau-1.d0)/(theta*c**tau+(1.d0-theta)*(kappa*d)**tau)\n end function du\n\n function d2u(c,d,s,z)\n real(dp), dimension(:), intent(in) :: c\n real(dp), intent(in) :: d,s,z\n real(dp), dimension(size(c)) :: d2u\n\n d2u = (-tau*((theta*c**(tau-1))/(theta*c**tau+(1-theta)*(kappa*d)**tau))**2 + (tau-1)*theta*c**(tau-2)/(theta*c**tau+(1-theta)*(kappa*d)**tau))\n end function d2u\n\n function Lambda(a,d,s,z)\n real(dp), dimension(:), intent(in) :: a\n real(dp), intent(in) :: d,s,z\n real(dp), dimension(size(a)) :: Lambda\n real(dp) :: trans_cost\n if (s.NE.d) then\n trans_cost = gamma_*d\n else\n trans_cost = 0.d0\n end if\n Lambda = (1.d0+6.d-2)*( a-(1.d0-downp)*s) + s- downp*d + z - trans_cost\n end function Lambda\n\n function dLambda(a,d,s,z)\n real(dp), dimension(:), intent(in) :: a\n real(dp), intent(in) :: d,s,z\n real(dp), dimension(size(a)) :: dLambda\n real(dp) :: trans_cost\n dLambda = 1.d0+6.d-2\n end function dLambda\n\n function Psi(s_index,d_index,z_index)\n integer, intent(in) :: s_index, d_index, z_index\n integer :: Psi\n Psi = d_index ! new state is equal to current period's discrete choice d\n end function\n\n\n ! *******************************************************************************************************\n ! ** Helper functions to set up the model\n ! *******************************************************************************************************\n\n ! **\n ! * Creates the grid for the stochastic variable z consisting of the sum of two AR(1) variables discretized using Tauchen (1986)'s method.\n ! *\n ! * Output:\n ! * - zgrid: the grid for Z\n ! * - transition_matrix: the Markov matrix for Z\n ! **\n subroutine fella_create_zgrid_and_transition(zgrid, transition_matrix)\n real(dp), dimension(len_y_grid), intent(out) :: zgrid\n real(dp), dimension(len_y_grid,len_y_grid), intent(out) :: transition_matrix\n\n\n real(dp), dimension(:), allocatable :: yp_grid, yt_grid\n real(dp), dimension(:,:), allocatable :: pi_yt, picum_yt, pi_yp, picum_yp\n\n integer :: i1, j1, i2, j2, index\n\n allocate(yp_grid(len_yp_grid),pi_yp(len_yp_grid,len_yp_grid),picum_yp(len_yp_grid,len_yp_grid))\n allocate(yt_grid(len_yt_grid),pi_yt(len_yt_grid,len_yt_grid),picum_yt(len_yt_grid,len_yt_grid))\n\n call tauchen_discretize(yp_grid,pi_yp,picum_yp,rho_yp,mu0_yp,sigma_yp,len_yp_grid,cover_yp)\n call tauchen_discretize(yt_grid,pi_yt,picum_yt,rho_yt,mu0_yt,sigma_yt,len_yt_grid,cover_yt)\n\n do i1 = 1,len_yp_grid\n do j1 = 1,len_yt_grid\n index = len_yt_grid*(i1-1) + j1\n zgrid(index) = yp_grid(i1) + yt_grid(j1)\n end do\n end do\n zgrid = exp(zgrid)\n\n ! Transition matrix for z\n do i1 = 1, size(pi_yp,1)\n do i2 = 1, size(pi_yt,1)\n do j1 = 1, size(pi_yp,2)\n do j2 = 1, size(pi_yt,2)\n transition_matrix((i1-1)*size(pi_yt,1)+i2,(j1-1)*size(pi_yt,2)+j2) = pi_yp(i1,j1)*pi_yt(i2,j2)\n end do\n end do\n end do\n end do\n\n end subroutine\n\n ! **\n ! * Computes an initial guess for the value function by assuming the household consumes 2% of its assets plus its earned income.\n ! *\n ! * Return value: initial guess for the value function\n ! **\n function vfinitialguess() result(guess)\n real(dp), dimension(len_a_grid, len_h_grid, len_y_grid) :: guess\n integer :: i1, i2\n real(dp), dimension(len_a_grid) :: c_guess\n\n do i1 = 1,len_y_grid\n c_guess(:) = 2.d-2*a_grid(:) + z_grid(i1)\n do i2 = 1,len_h_grid\n guess(:,i2,i1) = u(c_guess, sd_grid(i2), sd_grid(i2), z_grid(i1))\n end do\n end do\n end function\n\nend module demo_fella11\n", "meta": {"hexsha": "bce6430984120b20b2193fcc6623ab083cdef92c", "size": 10951, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "demo_fella11.f90", "max_stars_repo_name": "carlozanella/ncegm", "max_stars_repo_head_hexsha": "29c6846946bcdc8d527a4ff7a0bfb3ddee0c8bf8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-03-14T23:31:35.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-14T23:31:35.000Z", "max_issues_repo_path": "demo_fella11.f90", "max_issues_repo_name": "carlozanella/ncegm", "max_issues_repo_head_hexsha": "29c6846946bcdc8d527a4ff7a0bfb3ddee0c8bf8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "demo_fella11.f90", "max_forks_repo_name": "carlozanella/ncegm", "max_forks_repo_head_hexsha": "29c6846946bcdc8d527a4ff7a0bfb3ddee0c8bf8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.6, "max_line_length": 155, "alphanum_fraction": 0.4558487809, "num_tokens": 2532, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765257642906, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6923789333877406}} {"text": "program next_up\n use, intrinsic :: ieee_arithmetic\n use, intrinsic :: iso_fortran_env, only : DP => REAL64\n implicit none\n real :: x, next_x\n integer :: e\n\n do e = -37, 37\n x = 10.0**e\n next_x = ieee_next_after(x, x + 1.0)\n print '(4E15.7)', x, next_x, next_x - x, (next_x - x)/x\n end do\nend program next_up\n", "meta": {"hexsha": "9220400cf2bbf15a0ce452c522d13c73331db709", "size": 350, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source_code/ieee754/next_up.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/ieee754/next_up.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/ieee754/next_up.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": 25.0, "max_line_length": 63, "alphanum_fraction": 0.5771428571, "num_tokens": 120, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9136765234137297, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6923789266087067}} {"text": "! Objetivo: Resolver a Eq. -g_div_k*t+(v0_sin_theta+g_div_k)/k*&\n! (1.0-exp_menoskt) usando rtsafe para determinar o alcance.\n\nMODULE altura_projetil \n\tREAL :: exp_menoskt,v0_sin_theta,k,g_div_k\nCONTAINS\n\tSUBROUTINE funcd(t,altura_funct,deriv_funct)\n\t\tUSE nrtype\n\t\tIMPLICIT none\n\t\tREAL, INTENT(IN) :: t\n\t\tREAL, INTENT(OUT) :: altura_funct,deriv_funct\n\t\texp_menoskt= exp(-k*t)\n\t\taltura_funct=-g_div_k*t+(v0_sin_theta+g_div_k)/k*(1.0-exp_menoskt)\n\t\tderiv_funct=-g_div_k+(v0_sin_theta+g_div_k)*exp_menoskt\n\tEND SUBROUTINE funcd\n\tFUNCTION altura_funct(t)\n\t\tUSE nrtype\n\t\tREAL, INTENT(IN) :: t\n\t\texp_menoskt= exp(-k*t)\n\t\taltura_funct=-g_div_k*t+(v0_sin_theta+g_div_k)/k*(1.0-exp_menoskt)\n\tEND FUNCTION\nEND MODULE \nPROGRAM arremesso\n\tUSE altura_projetil\n\tUSE nrtype\n\tUSE nr, ONLY: rtsafe\n\tIMPLICIT none\n\tINTEGER,PARAMETER :: theta_x_R=8,k_x_R=9,pontos=300,pt_menos_1=pontos-1\n\tREAL, PARAMETER :: g=9.81,v0=600.0\n\tINTEGER :: theta_1,theta_2,theta_3,k1,k2\n\tREAL :: theta, t,t_1,t_2, R,v0_sob_k\n\tINTEGER,PARAMETER :: val_interv_k=10,interv_theta=7,interv_theta_mais1=&\n\t\t\t\tinterv_theta+1\n\tREAL, PARAMETER :: v0_quad_g=(v0**2)/g,theta0=0.0,theta_final=PIO2,&\n\t\t\t\tk_inicial=0.0, k_final=0.1\n\tREAL, PARAMETER :: variacao_theta=theta_final-theta0,variacao_k=&\n\t\t\tk_final-k_inicial,variacao_theta_1=variacao_theta/REAL(pt_menos_1)\n\tREAL, PARAMETER :: variacao_k1=variacao_k/REAL(val_interv_k),precisao=1.0e-5\n\tREAL, PARAMETER :: variacao_k2=variacao_k/REAL(pt_menos_1),variacao_theta_2=&\n\t\t\t\t\t\tvariacao_theta/REAL(interv_theta_mais1)\n\tLOGICAL :: succes\n\t\n\tOPEN(unit=theta_x_R,file=\"Theta_vs_R.dat\")\n\tOPEN(unit=k_x_R,file=\"k_vs_R.dat\")\n! R vs theta, com k no intervalo [0, 0,1] (11 valores equidistantes)\n! Inicialmente para k igual a zero\n\ttheta=theta0\n\tDO theta_1=1,pontos\n\t\tv0_sin_theta=v0*sin(theta)\n\t\tR=v0_quad_g*sin(2.0*theta)\n\t\tWRITE(unit=theta_x_R,fmt=*) theta/PIO2,R\n\t\ttheta=theta+variacao_theta_1\n\tEND DO\n\tWRITE(unit=theta_x_R,fmt=*)\n! Agora para k diferente de zero\n\tk=k_inicial\n\tDO k1=1,val_interv_k\n\t\tk=k+variacao_k1\n\t\tg_div_k=g/k\n\t\tv0_sob_k=v0/k \n\t\ttheta=theta0\n\t\tR=0.0\n\t\tWRITE(unit=theta_x_R,fmt=*) theta/PIO2,R\n\t\ttheta=theta+variacao_theta_1\n\t\tv0_sin_theta = v0*sin(theta)\n\t\tt_1=v0_sin_theta/g\n\t\tt_2=2.0*t_1\n\t\tDO theta_2=1,pontos\n\t\t\tCALL zbrac(altura_funct,t_1,t_2,succes)\n\t\t\tT=rtsafe(funcd,t_1,t_2,precisao)\n\t\t\tR=v0_sob_k*cos(theta)*(1.0-exp(-k*T))\n\t\t\tWRITE(unit=theta_x_R,fmt=*) theta/PIO2,R,T,t_1,t_2\n\t\t\ttheta=theta+variacao_theta_1\n\t\t\tv0_sin_theta = v0*sin(theta)\n\t\t\tt_1=T-0.1\n\t\t\tt_2=T+0.1\n\t\tEND DO\n\t\tWRITE(unit=theta_x_R,fmt=*)\n\tEND DO\n! R vs k[0, 0,1], com theta no intervalo (0, pi/2) (7 valores equidistantes)\n\ttheta=theta0\n\tDO theta_3=1,interv_theta\n! Inicialmente para k igual a zero\n\t\ttheta=theta+variacao_theta_2\n\t\tv0_sin_theta=v0*sin(theta)\n\t\tk=k_inicial\n\t\tR=v0_quad_g*sin(2.0*theta)\n\t\tWRITE(unit=k_x_R,fmt=*) k,R\n! Agora para k diferente de zero\n\t\tt_1=v0_sin_theta/g\n\t\tt_2=2.0*t_1\n\t\tDO k2=1,pt_menos_1\n\t\t\tk=k+variacao_k2\n\t\t\tg_div_k=g/k\n\t\t\tv0_sob_k=v0/k\n\t\t\tCALL zbrac(altura_funct,t_1,t_2,succes)\n\t\t\tT=rtsafe(funcd,t_1,t_2,precisao)\n\t\t\tR=v0*cos(theta)/k*(1.0-exp(-k*T))\n\t\t\tWRITE(unit=k_x_R,fmt=*) k,R\n\t\t\tv0_sin_theta=v0*sin(theta)\n\t\t\tt_1=T-0.1\n\t\t\tt_2=T+0.1\n\t\tEND DO\n\t\tWRITE(unit=k_x_R,fmt=*)\n\tEND DO\n\tCLOSE(unit=theta_x_R)\n\tCLOSE(unit=k_x_R)\nEND PROGRAM arremesso", "meta": {"hexsha": "b1bebf285641200ec93d16638b5de3ec31587ff9", "size": 3280, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "exercicio_2.f90", "max_stars_repo_name": "GuilhermeMonteiroPeixoto/Computational-Physics-using-Fortran", "max_stars_repo_head_hexsha": "3d2b3dd87d99b451aed5fe1e9e99813390396485", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "exercicio_2.f90", "max_issues_repo_name": "GuilhermeMonteiroPeixoto/Computational-Physics-using-Fortran", "max_issues_repo_head_hexsha": "3d2b3dd87d99b451aed5fe1e9e99813390396485", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "exercicio_2.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": 30.3703703704, "max_line_length": 78, "alphanum_fraction": 0.7332317073, "num_tokens": 1361, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765163620469, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6923789212649812}} {"text": "!\n! See deeming.py for info. This file contains 2 Fortran implimentations\n! of the deeming periodogram algorithm\nsubroutine periodogram(time, value, freqs, nt, nf , numprocs, amps)\n\n! periodogram calculates the Deeming periodogram of the datapoints contained\n! in the arrays time, value at the frequencies contained in freqs\n! This subroutine is meant for f2py wrapping as well as a testbed of openMP\n! within a python environment\n\n use omp_lib\n implicit none\n\n\n ! sizes of time and frequency arrays\n integer :: nt, nf, id\n ! arrays\n double precision time(nt), value(nt)\n double precision freqs(nf), amps(nf)\n integer :: numprocs, f\n double precision :: pi, realpart, imagpart\n\n pi = 3.1415926535897931D0\n realpart = 0.0D0\n imagpart = 0.0D0\n\n! Add compiler directives so f2py knows what to do\n\n!f2py intent(in) time\n!f2py intent(in) value\n\n!f2py intent(in) nt\n!f2py depend(nt) time\n!f2py depend(nt) value\n\n!f2py intent(in) freqs\n!f2py intent(in) nf\n!f2py depend(nf) freqs\n\n!f2py intent(in) numprocs\n!f2py intent(out) amps\n\n call OMP_SET_NUM_THREADS(numprocs)\n\n !$OMP PARALLEL DO &\n !$OMP DEFAULT(SHARED) PRIVATE(f,realpart, imagpart)\n do f = 1, nf\n ! calculate real and imaginary parts\n realpart = sum((value*dcos(2.0D0*pi*freqs(f)*time)))\n imagpart = sum((value*dsin(2.0D0*pi*freqs(f)*time)))\n\n ! calculate the amplitude\n amps(f) = 2.0D0*dsqrt(realpart**2 + imagpart**2)/nt\n end do\n !$OMP END PARALLEL DO\n\n\n\nend subroutine\n\n\nsubroutine periodogram2(time, value, freqs, nt, nf , numprocs, amps)\n\n! periodogram calculates the Deeming periodogram of the datapoints contained\n! in the arrays time, value at the frequencies contained in freqs\n! This subroutine is meant for f2py wrapping as well as a testbed of openMP\n! within a python environment\n\n use omp_lib\n implicit none\n\n\n ! sizes of time and frequency arrays\n integer :: nt, nf, id\n ! arrays\n double precision time(nt), value(nt)\n double precision freqs(nf), amps(nf)\n integer :: numprocs, f, d\n double precision :: pi, realpart, imagpart\n\n pi = 3.1415926535897931D0\n realpart = 0.0D0\n imagpart = 0.0D0\n\n! Add compiler directives so f2py knows what to do\n\n!f2py threadsafe\n!f2py intent(in) time\n!f2py intent(in) value\n\n!f2py intent(in) nt\n!f2py depend(nt) time\n!f2py depend(nt) value\n\n!f2py intent(in) freqs\n!f2py intent(in) nf\n!f2py depend(nf) freqs\n\n!f2py intent(in) numprocs\n!f2py intent(out) amps\n\n call OMP_SET_NUM_THREADS(numprocs)\n\n !$OMP PARALLEL DO &\n !$OMP DEFAULT(SHARED) PRIVATE(f,realpart, imagpart)\n do f = 1, nf\n ! calculate real and imaginary parts\n do d = 1, nt\n realpart = realpart + value(d)*dcos(2.0D0*pi*freqs(f)*time(d))\n imagpart = imagpart + value(d)*dsin(2.0D0*pi*freqs(f)*time(d))\n end do\n\n ! calculate the amplitude\n amps(f) = 2.0D0*dsqrt(realpart*realpart + imagpart*imagpart)/nt\n\n realpart = 0.0D0\n imagpart = 0.0D0\n end do\n !$OMP END PARALLEL DO\n\nend subroutine\n", "meta": {"hexsha": "a2583e0f392520b1c0d4b8c176b7aa9d39d82ee1", "size": 3063, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "seismo/src/periodogram.f90", "max_stars_repo_name": "drdangersimon/seismo", "max_stars_repo_head_hexsha": "b02e7838191a04615210ca3cc104866fc2e04aad", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-07-23T08:01:18.000Z", "max_stars_repo_stars_event_max_datetime": "2015-07-23T08:01:18.000Z", "max_issues_repo_path": "seismo/src/periodogram.f90", "max_issues_repo_name": "ezietsman/seismo", "max_issues_repo_head_hexsha": "43729526391126c025bf13d727edb693cd46daa9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "seismo/src/periodogram.f90", "max_forks_repo_name": "ezietsman/seismo", "max_forks_repo_head_hexsha": "43729526391126c025bf13d727edb693cd46daa9", "max_forks_repo_licenses": ["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.106557377, "max_line_length": 76, "alphanum_fraction": 0.6813581456, "num_tokens": 960, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757870046160258, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.692336184167902}} {"text": "!------------------------------------------------------------------------\n! RK4 SOLVER for a system of ODEs |\n! Course: AE305 |\n!------------------------------------------------------------------------\nmodule data\n\tinteger, parameter :: neq=2\n\treal*8, parameter :: rho_p=1140., a=5.55e-5 ! ..., ..., ...\nend module\n\t\nprogram sysRK4\n\tuse data\n\treal*8 :: y(neq)\n\tcharacter*40 :: fname\n\n!..read the input data\n\twrite(*,'(/(a))',advance='no')' Enter the step size and the end point :>'\n\tread(*,*) dt,tmax\n!..open the output file \n\twrite(*,'(a)',advance='no')' Enter the output file name [solution.dat]:>'\n\tread(*,'(a)') fname\n\tif( fname .eq. ' ') fname = 'solution.dat'\n\topen(1,file=fname,form='formatted')\n\n!..set the initial conditions\n\ttime = 0.\n!~ \ty(1) = ...\n!~ \ty(2) = ...\n\twrite(1,'(6E14.5)') time,(y(i),i=1,neq)\n\n!..solution loop\n\tDO WHILE (time .lt. tmax) \n\t\tcall SRK4(time,dt,y)\n\t\ttime = time + dt \n\t\twrite(1,'(6E14.5)') time,(y(i),i=1,neq)\n\tENDDO\n\n\tclose(1)\n\tstop\nend\n\t\n!------------------------------------------------------------------------\nsubroutine SRK4(time,dt,y)\n use data\n\treal*8 :: y(neq),ytmp(neq),k1(neq),k2(neq),k3(neq),k4(neq)\n\tdt2 = 0.5*dt\n\t\t\n\tcall odes(time,y,k1)\n\tdo i = 1,neq\n ytmp(i) = y(i) + k1(i)*dt2\n\tenddo\n!~ \tcall ODES( ... )\n!~ \t...\n!~ \t...\n\n!..obtain the solution at t+dt and update y for the next step\n\tdo i = 1,neq\n\t\tphi = (k1(i) + 2*(k2(i)+k3(i)) + k4(i))/6.\n\t\ty(i) = y(i) + phi*dt\n\tenddo\n\n\treturn\n\tend\n\n!------------------------------------------------------------------------\nsubroutine ODEs(time,y,f)\n use data\n\treal*8 :: y(neq),f(neq)\n\n!..define the ODE's & return the slopes in the \"f\" array\n\n!~ \tf(1) = ...\n!~ \tf(2) = ...\n\n\treturn\nend\n", "meta": {"hexsha": "8f22a98cf83869713cdc79d88ad0c624237f8f26", "size": 1796, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Homework2/hw2-option2.f90", "max_stars_repo_name": "Atknssl/AE305-Homeworks", "max_stars_repo_head_hexsha": "5a2d5abb7b8837f72b94faecc2fe3180fd65f96a", "max_stars_repo_licenses": ["AFL-3.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-03-06T18:42:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-04T13:27:27.000Z", "max_issues_repo_path": "Homework2/hw2-option2.f90", "max_issues_repo_name": "Atknssl/AE305-Homeworks", "max_issues_repo_head_hexsha": "5a2d5abb7b8837f72b94faecc2fe3180fd65f96a", "max_issues_repo_licenses": ["AFL-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Homework2/hw2-option2.f90", "max_forks_repo_name": "Atknssl/AE305-Homeworks", "max_forks_repo_head_hexsha": "5a2d5abb7b8837f72b94faecc2fe3180fd65f96a", "max_forks_repo_licenses": ["AFL-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.6315789474, "max_line_length": 74, "alphanum_fraction": 0.4448775056, "num_tokens": 578, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339837155239, "lm_q2_score": 0.8244619350028204, "lm_q1q2_score": 0.6923287051017277}} {"text": " program P0214\nc>> 1997-10-02 Krogh Generate plots for ch02-02.tex\n integer MAXPT\n real RMAXPT, XA, XB, XSIZE, YSIZE\n real YMIN\n real PI2\n parameter (MAXPT=101, RMAXPT=101.E0)\n parameter (XA = 0.0E0, XB = 12.0E0)\n parameter (XSIZE=3.2E0, YSIZE=2.5E0)\n parameter (YMIN=-2.0E0)\n parameter (PI2=1.57079632679489E0)\n real DX, OPT(23), X(MAXPT), Y(MAXPT, 3)\n external SCI, SCIN, SSI\n real SCI, SCIN, SSI\n integer I\n character COPT*63\n real PLOUNI, PLOTXT, PLONY, PLOBOR, PLOYMX, PLOANL\n parameter (PLOUNI=1.E0, PLOTXT=14.E0, PLONY=2.E0, PLOBOR=4.E0,\n 1 PLOYMX=9.E0, PLOANL=16.E0)\n data OPT / 0.E0, PLONY, RMAXPT, 3.E0, PLOANL, PI2, 1924.E0,\n 1 PLOTXT, 1.3E0, 1.9E0, 360.E0, PLOTXT, 4.3E0, -.6E0, 0.E0,\n 1 PLOTXT, 7.E0, 2.8E0, 0.E0, PLOYMX, YMIN, 4.E0,\n 2 0.E0 /\nc 1111111111222222222233333333334444444444555555555556666\nc 1234567890123456789012345678901234567890123456789012345678901234\n data COPT /\n 1'F{pl02-14.tex}[cr]{$\\frac{\\pi}{2}$}{Si$(x)$}{Ci$(x)$}{Cin$(x)$}'\n 2/\nc\n DX = (XB - XA) / (MAXPT-1)\n do 100 I = 1, MAXPT\n X(I) = real(I-1) * DX\n if (X(I) .eq. 0.E0) X(I) = 1.E-3\n Y(I,1) = SSI(X(I))\n Y(I,2) = SCI(X(I))\n Y(I,3) = SCIN(X(I))\n 100 continue\n call SPLOT(XSIZE, YSIZE, X, MAXPT, Y, OPT, COPT)\n stop\n end\n", "meta": {"hexsha": "30247f42b2b7d731e95cc7650521bcebba72abf4", "size": 1423, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/extras/pl02-14.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/extras/pl02-14.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/extras/pl02-14.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": 34.7073170732, "max_line_length": 71, "alphanum_fraction": 0.5635980323, "num_tokens": 638, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.824461928533133, "lm_q1q2_score": 0.692328686441834}} {"text": " SUBROUTINE CELLVECT\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!! Generates the vectors used to convert fractionals to\n!! Cartesians and cartesians to fractionals\n!! Using the cell parameters a,b \n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n USE header_file\n IMPLICIT NONE\n \n REAL(kind = double) :: DET\n REAL(kind = double), DIMENSION(3,3) :: DUMMY1,DUMMY2 \n INTEGER :: I,J\n\n!!! EA is on x-axis so is (a,0,0)\n\n EFC(1,1) = ALEN\n EFC(1,2) = BLEN*COS(GAMMA) + DELTA \n EFC(1,3) = CLEN*COS(GAMMA) \n\n!!! EB lies in xy plane at an angle gamma to x\n\n EFC(2,1) = 0.0D0\n EFC(2,2) = BLEN*SIN(GAMMA) \n EFC(2,3) = CLEN*(COS(ALPHA) -(COS(GAMMA)*COS(BETA)))/SIN(GAMMA) \n\n!!! EC points into space and has components in all directions\n\n EFC(3,1) = 0.0D0\n EFC(3,2) = 0.0D0 \n EFC(3,3) = CLEN - CLEN*COS(BETA)*COS(BETA) + & \n & CLEN*((COS(ALPHA) - COS(ALPHA)*COS(BETA)) / SIN(GAMMA)) &\n & *((COS(ALPHA)-COS(ALPHA)*COS(BETA))/SIN(GAMMA)) \n\n!!! copy EFC array elements to dummy1 matrix\n\n DO I = 1,3\n DO J = 1,3\n DUMMY1(I,J) = EFC(I,J)\n END DO\n END DO\n\n CALL INVERT(DUMMY1,DUMMY2)\n\n!!! copy dummy2 array elements to ECF matrix\n\n DO I = 1,3\n DO J = 1,3\n ECF(I,J) = DUMMY2(I,J)\n END DO\n END DO\n\n\n END SUBROUTINE\n\n", "meta": {"hexsha": "f06ad36bb81ebb7d7769a0e16f9ed12f2bcbb462", "size": 1449, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "synthetic_NEMD/src/src_3dsllod/cellvect.f90", "max_stars_repo_name": "niallj/ImperialNESS-Sep14", "max_stars_repo_head_hexsha": "0cd309273cdb89f8055c2aa51422584e2284ca94", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "synthetic_NEMD/src/src_3dsllod/cellvect.f90", "max_issues_repo_name": "niallj/ImperialNESS-Sep14", "max_issues_repo_head_hexsha": "0cd309273cdb89f8055c2aa51422584e2284ca94", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "synthetic_NEMD/src/src_3dsllod/cellvect.f90", "max_forks_repo_name": "niallj/ImperialNESS-Sep14", "max_forks_repo_head_hexsha": "0cd309273cdb89f8055c2aa51422584e2284ca94", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.875, "max_line_length": 76, "alphanum_fraction": 0.4858523119, "num_tokens": 494, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418116217418, "lm_q2_score": 0.7490872243177518, "lm_q1q2_score": 0.6922628245437092}} {"text": "PROGRAM EXAMPLE\n IMPLICIT NONE\n INTEGER :: exponent, factor\n\n WRITE(*,*) \"Enter exponent of Mersenne number\"\n READ(*,*) exponent\n factor = Mfactor(exponent)\n IF (factor == 0) THEN\n WRITE(*,*) \"No Factor found\"\n ELSE\n WRITE(*,\"(A,I0,A,I0)\") \"M\", exponent, \" has a factor: \", factor\n END IF\n\nCONTAINS\n\nFUNCTION isPrime(number)\n! code omitted - see [[Primality by Trial Division]]\nEND FUNCTION\n\nFUNCTION Mfactor(p)\n INTEGER :: Mfactor\n INTEGER, INTENT(IN) :: p\n INTEGER :: i, k, maxk, msb, n, q\n\n DO i = 30, 0 , -1\n IF(BTEST(p, i)) THEN\n msb = i\n EXIT\n END IF\n END DO\n\n maxk = 16384 / p ! limit for k to prevent overflow of 32 bit signed integer\n DO k = 1, maxk\n q = 2*p*k + 1\n IF (.NOT. isPrime(q)) CYCLE\n IF (MOD(q, 8) /= 1 .AND. MOD(q, 8) /= 7) CYCLE\n n = 1\n DO i = msb, 0, -1\n IF (BTEST(p, i)) THEN\n n = MOD(n*n*2, q)\n ELSE\n n = MOD(n*n, q)\n ENDIF\n END DO\n IF (n == 1) THEN\n Mfactor = q\n RETURN\n END IF\n END DO\n Mfactor = 0\nEND FUNCTION\nEND PROGRAM EXAMPLE\n", "meta": {"hexsha": "334db9efdceb12048ddf0b96a96aff13b5104c77", "size": 1069, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Factors-of-a-Mersenne-number/Fortran/factors-of-a-mersenne-number.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/Factors-of-a-Mersenne-number/Fortran/factors-of-a-mersenne-number.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/Factors-of-a-Mersenne-number/Fortran/factors-of-a-mersenne-number.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 20.1698113208, "max_line_length": 82, "alphanum_fraction": 0.5603367633, "num_tokens": 388, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418241572634, "lm_q2_score": 0.7490872131147276, "lm_q1q2_score": 0.6922628235807251}} {"text": "c\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc . .\nc . copyright (c) 1998 by UCAR .\nc . .\nc . University Corporation for Atmospheric Research .\nc . .\nc . all rights reserved .\nc . .\nc . .\nc . SPHEREPACK3.0 .\nc . .\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc\nc\nc\nc ... file shagc.f\nc\nc this file contains code and documentation for subroutines\nc shagc and shagci\nc\nc ... files which must be loaded with shagc.f\nc\nc sphcom.f, hrfft.f, gaqd.f\nc\nc\nc subroutine shagc(nlat,nlon,isym,nt,g,idg,jdg,a,b,mdab,ndab,\nc + wshagc,lshagc,work,lwork,ierror)\nc\nc subroutine shagc performs the spherical harmonic analysis\nc on the array g and stores the result in the arrays a and b.\nc the analysis is performed on a gaussian grid in colatitude\nc and an equally spaced grid in longitude. the associated\nc legendre functions are recomputed rather than stored as they\nc are in subroutine shags. the analysis is described below\nc at output parameters a,b.\nc\nc input parameters\nc\nc nlat the number of points in the gaussian colatitude grid on the\nc full sphere. these lie in the interval (0,pi) and are compu\nc in radians in theta(1),...,theta(nlat) by subroutine gaqd.\nc if nlat is odd the equator will be included as the grid poi\nc theta((nlat+1)/2). if nlat is even the equator will be\nc excluded as a grid point and will lie half way between\nc theta(nlat/2) and theta(nlat/2+1). nlat must be at least 3.\nc note: on the half sphere, the number of grid points in the\nc colatitudinal direction is nlat/2 if nlat is even or\nc (nlat+1)/2 if nlat is odd.\nc\nc nlon the number of distinct londitude points. nlon determines\nc the grid increment in longitude as 2*pi/nlon. for example\nc nlon = 72 for a five degree grid. nlon must be greater\nc than or equal to 4. the efficiency of the computation is\nc improved when nlon is a product of small prime numbers.\nc\nc isym = 0 no symmetries exist about the equator. the analysis\nc is performed on the entire sphere. i.e. on the\nc array g(i,j) for i=1,...,nlat and j=1,...,nlon.\nc (see description of g below)\nc\nc = 1 g is antisymmetric about the equator. the analysis\nc is performed on the northern hemisphere only. i.e.\nc if nlat is odd the analysis is performed on the\nc array g(i,j) for i=1,...,(nlat+1)/2 and j=1,...,nlon.\nc if nlat is even the analysis is performed on the\nc array g(i,j) for i=1,...,nlat/2 and j=1,...,nlon.\nc\nc\nc = 2 g is symmetric about the equator. the analysis is\nc performed on the northern hemisphere only. i.e.\nc if nlat is odd the analysis is performed on the\nc array g(i,j) for i=1,...,(nlat+1)/2 and j=1,...,nlon.\nc if nlat is even the analysis is performed on the\nc array g(i,j) for i=1,...,nlat/2 and j=1,...,nlon.\nc\nc nt the number of analyses. in the program that calls shagc,\nc the arrays g,a and b can be three dimensional in which\nc case multiple analyses will be performed. the third\nc index is the analysis index which assumes the values\nc k=1,...,nt. for a single analysis set nt=1. the\nc discription of the remaining parameters is simplified\nc by assuming that nt=1 or that the arrays g,a and b\nc have only two dimensions.\nc\nc g a two or three dimensional array (see input parameter\nc nt) that contains the discrete function to be analyzed.\nc g(i,j) contains the value of the function at the gaussian\nc point theta(i) and longitude point phi(j) = (j-1)*2*pi/nlon\nc the index ranges are defined above at the input parameter\nc isym.\nc\nc idg the first dimension of the array g as it appears in the\nc program that calls shagc. if isym equals zero then idg\nc must be at least nlat. if isym is nonzero then idg must\nc be at least nlat/2 if nlat is even or at least (nlat+1)/2\nc if nlat is odd.\nc\nc jdg the second dimension of the array g as it appears in the\nc program that calls shagc. jdg must be at least nlon.\nc\nc mdab the first dimension of the arrays a and b as it appears\nc in the program that calls shagc. mdab must be at least\nc min0((nlon+2)/2,nlat) if nlon is even or at least\nc min0((nlon+1)/2,nlat) if nlon is odd\nc\nc ndab the second dimension of the arrays a and b as it appears\nc in the program that calls shaec. ndab must be at least nlat\nc\nc wshagc an array which must be initialized by subroutine shagci.\nc once initialized, wshagc can be used repeatedly by shagc.\nc as long as nlat and nlon remain unchanged. wshagc must\nc not be altered between calls of shagc.\nc\nc lshagc the dimension of the array wshagc as it appears in the\nc program that calls shagc. define\nc\nc l1 = min0(nlat,(nlon+2)/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc and\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc then lshagc must be at least\nc\nc nlat*(2*l2+3*l1-2)+3*l1*(1-l1)/2+nlon+15\nc\nc\nc work a work array that does not have to be saved.\nc\nc lwork the dimension of the array work as it appears in the\nc program that calls shagc. define\nc\nc l1 = min0(nlat,(nlon+2)/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc and\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc if isym is zero then lwork must be at least\nc\nc nlat*(nlon*nt+max0(3*l2,nlon))\nc\nc if isym is not zero then lwork must be at least\nc\nc l2*(nlon*nt+max0(3*nlat,nlon))\nc\nc **************************************************************\nc\nc output parameters\nc\nc a,b both a,b are two or three dimensional arrays (see input\nc parameter nt) that contain the spherical harmonic\nc coefficients in the representation of g(i,j) given in the\nc discription of subroutine shagc. for isym=0, a(m,n) and\nc b(m,n) are given by the equations listed below. symmetric\nc versions are used when isym is greater than zero.\nc\nc definitions\nc\nc 1. the normalized associated legendre functions\nc\nc pbar(m,n,theta) = sqrt((2*n+1)*factorial(n-m)/(2*factorial(n+m)))\nc *sin(theta)**m/(2**n*factorial(n)) times the\nc (n+m)th derivative of (x**2-1)**n with respect\nc to x=cos(theta).\nc\nc 2. the fourier transform of g(i,j).\nc\nc c(m,i) = 2/nlon times the sum from j=1 to j=nlon of\nc g(i,j)*cos((m-1)*(j-1)*2*pi/nlon)\nc (the first and last terms in this sum\nc are divided by 2)\nc\nc s(m,i) = 2/nlon times the sum from j=2 to j=nlon of\nc g(i,j)*sin((m-1)*(j-1)*2*pi/nlon)\nc\nc\nc 3. the gaussian points and weights on the sphere\nc (computed by subroutine gaqd).\nc\nc theta(1),...,theta(nlat) (gaussian pts in radians)\nc wts(1),...,wts(nlat) (corresponding gaussian weights)\nc\nc 4. the maximum (plus one) longitudinal wave number\nc\nc mmax = min0(nlat,(nlon+2)/2) if nlon is even or\nc mmax = min0(nlat,(nlon+1)/2) if nlon is odd.\nc\nc\nc then for m=0,...,mmax-1 and n=m,...,nlat-1 the arrays a,b\nc are given by\nc\nc a(m+1,n+1) = the sum from i=1 to i=nlat of\nc c(m+1,i)*wts(i)*pbar(m,n,theta(i))\nc\nc b(m+1,n+1) = the sum from i=1 to nlat of\nc s(m+1,i)*wts(i)*pbar(m,n,theta(i))\nc\nc ierror = 0 no errors\nc = 1 error in the specification of nlat\nc = 2 error in the specification of nlon\nc = 3 error in the specification of isym\nc = 4 error in the specification of nt\nc = 5 error in the specification of idg\nc = 6 error in the specification of jdg\nc = 7 error in the specification of mdab\nc = 8 error in the specification of ndab\nc = 9 error in the specification of lshagc\nc = 10 error in the specification of lwork\nc\nc\nc ****************************************************************\nc\nc subroutine shagci(nlat,nlon,wshagc,lshagc,dwork,ldwork,ierror)\nc\nc subroutine shagci initializes the array wshagc which can then\nc be used repeatedly by subroutines shagc. it precomputes\nc and stores in wshagc quantities such as gaussian weights,\nc legendre polynomial coefficients, and fft trigonometric tables.\nc\nc input parameters\nc\nc nlat the number of points in the gaussian colatitude grid on the\nc full sphere. these lie in the interval (0,pi) and are compu\nc in radians in theta(1),...,theta(nlat) by subroutine gaqd.\nc if nlat is odd the equator will be included as the grid poi\nc theta((nlat+1)/2). if nlat is even the equator will be\nc excluded as a grid point and will lie half way between\nc theta(nlat/2) and theta(nlat/2+1). nlat must be at least 3.\nc note: on the half sphere, the number of grid points in the\nc colatitudinal direction is nlat/2 if nlat is even or\nc (nlat+1)/2 if nlat is odd.\nc\nc nlon the number of distinct londitude points. nlon determines\nc the grid increment in longitude as 2*pi/nlon. for example\nc nlon = 72 for a five degree grid. nlon must be greater\nc than or equal to 4. the efficiency of the computation is\nc improved when nlon is a product of small prime numbers.\nc\nc wshagc an array which must be initialized by subroutine shagci.\nc once initialized, wshagc can be used repeatedly by shagc\nc as long as nlat and nlon remain unchanged. wshagc must\nc not be altered between calls of shagc.\nc\nc lshagc the dimension of the array wshagc as it appears in the\nc program that calls shagc. define\nc\nc l1 = min0(nlat,(nlon+2)/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc and\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc then lshagc must be at least\nc\nc nlat*(2*l2+3*l1-2)+3*l1*(1-l1)/2+nlon+15\nc\nc dwork a double precision work array that does not have to be saved.\nc\nc ldwork the dimension of the array dwork as it appears in the\nc program that calls shagci. ldwork must be at least\nc\nc nlat*(nlat+4)\nc\nc output parameter\nc\nc wshagc an array which must be initialized before calling shagc or\nc once initialized, wshagc can be used repeatedly by shagc or\nc as long as nlat and nlon remain unchanged. wshagc must not\nc altered between calls of shagc.\nc\nc ierror = 0 no errors\nc = 1 error in the specification of nlat\nc = 2 error in the specification of nlon\nc = 3 error in the specification of lshagc\nc = 4 error in the specification of ldwork\nc = 5 failure in gaqd to compute gaussian points\nc (due to failure in eigenvalue routine)\nc\nc\nc ****************************************************************\n subroutine shagc(nlat,nlon,isym,nt,g,idg,jdg,a,b,mdab,ndab,\n 1 wshagc,lshagc,work,lwork,ierror)\nc subroutine shagc performs the spherical harmonic analysis on\nc a gaussian grid on the array(s) in g and returns the coefficients\nc in array(s) a,b. the necessary legendre polynomials are computed\nc as needed in this version.\nc\n dimension g(idg,jdg,1),a(mdab,ndab,1),b(mdab,ndab,1),\n 1 wshagc(lshagc),work(lwork)\nc check input parameters\n ierror = 1\n if (nlat.lt.3) return\n ierror = 2\n if (nlon.lt.4) return\n ierror = 3\n if (isym.lt.0 .or.isym.gt.2) return\n ierror = 4\n if (nt.lt.1) return\nc set upper limit on m for spherical harmonic basis\n l = min0((nlon+2)/2,nlat)\nc set gaussian point nearest equator pointer\n late = (nlat+mod(nlat,2))/2\nc set number of grid points for analysis/synthesis\n lat = nlat\n if (isym.ne.0) lat = late\n ierror = 5\n if (idg.lt.lat) return\n ierror = 6\n if (jdg.lt.nlon) return\n ierror = 7\n if(mdab .lt. l) return\n ierror = 8\n if(ndab .lt. nlat) return\n l1 = l\n l2 = late\n ierror = 9\nc check permanent work space length\n if (lshagc .lt. nlat*(2*l2+3*l1-2)+3*l1*(1-l1)/2+nlon+15)return\n ierror = 10\nc check temporary work space length\n if (isym.eq.0) then\n if(lwork.lt.nlat*(nlon*nt+max0(3*l2,nlon))) return\n else\nc isym.ne.0\n if(lwork.lt.l2*(nlon*nt+max0(3*nlat,nlon))) return\n end if\n ierror = 0\nc starting address for gaussian wts in shigc and fft values\n iwts = 1\n ifft = nlat+2*nlat*late+3*(l*(l-1)/2+(nlat-l)*(l-1))+1\nc set pointers for internal storage of g and legendre polys\n ipmn = lat*nlon*nt+1\n call shagc1(nlat,nlon,l,lat,isym,g,idg,jdg,nt,a,b,mdab,ndab,\n 1wshagc,wshagc(iwts),wshagc(ifft),late,work(ipmn),work)\n return\n end\n subroutine shagc1(nlat,nlon,l,lat,mode,gs,idg,jdg,nt,a,b,mdab,\n 1 ndab,w,wts,wfft,late,pmn,g)\n dimension gs(idg,jdg,nt),a(mdab,ndab,nt),\n 1 b(mdab,ndab,nt),g(lat,nlon,nt)\n dimension w(1),wts(nlat),wfft(1),pmn(nlat,late,3)\nc set gs array internally in shagc1\n do 100 k=1,nt\n do 100 j=1,nlon\n do 100 i=1,lat\n g(i,j,k) = gs(i,j,k)\n 100 continue\nc do fourier transform\n do 101 k=1,nt\n call hrfftf(lat,nlon,g(1,1,k),lat,wfft,pmn)\n 101 continue\nc scale result\n sfn = 2.0/float(nlon)\n do 102 k=1,nt\n do 102 j=1,nlon\n do 102 i=1,lat\n g(i,j,k) = sfn*g(i,j,k)\n 102 continue\nc compute using gaussian quadrature\nc a(n,m) = s (ga(theta,m)*pnm(theta)*sin(theta)*dtheta)\nc b(n,m) = s (gb(theta,m)*pnm(theta)*sin(theta)*dtheta)\nc here ga,gb are the cos(phi),sin(phi) coefficients of\nc the fourier expansion of g(theta,phi) in phi. as a result\nc of the above fourier transform they are stored in array\nc g as follows:\nc for each theta(i) and k= l-1\nc ga(0),ga(1),gb(1),ga(2),gb(2),...,ga(k-1),gb(k-1),ga(k)\nc correspond to (in the case nlon=l+l-2)\nc g(i,1),g(i,2),g(i,3),g(i,4),g(i,5),...,g(i,2l-4),g(i,2l-3),g(i,2l-\nc initialize coefficients to zero\n do 103 k=1,nt\n do 103 np1=1,nlat\n do 103 mp1=1,l\n a(mp1,np1,k) = 0.0\n b(mp1,np1,k) = 0.0\n 103 continue\nc set m+1 limit on b(m+1) calculation\n lm1 = l\n if (nlon .eq. l+l-2) lm1 = l-1\n if (mode.eq.0) then\nc for full sphere (mode=0) and even/odd reduction:\nc overwrite g(i) with (g(i)+g(nlat-i+1))*wts(i)\nc overwrite g(nlat-i+1) with (g(i)-g(nlat-i+1))*wts(i)\n nl2 = nlat/2\n do 104 k=1,nt\n do 104 j=1,nlon\n do 105 i=1,nl2\n is = nlat-i+1\n t1 = g(i,j,k)\n t2 = g(is,j,k)\n g(i,j,k) = wts(i)*(t1+t2)\n g(is,j,k) = wts(i)*(t1-t2)\n 105 continue\nc adjust equator if necessary(nlat odd)\n if (mod(nlat,2).ne.0) g(late,j,k) = wts(late)*g(late,j,k)\n 104 continue\nc set m = 0 coefficients first\n m = 0\n call legin(mode,l,nlat,m,w,pmn,km)\n do 106 k=1,nt\n do 106 i=1,late\n is = nlat-i+1\n do 107 np1=1,nlat,2\nc n even\n a(1,np1,k) = a(1,np1,k)+g(i,1,k)*pmn(np1,i,km)\n 107 continue\n do 108 np1=2,nlat,2\nc n odd\n a(1,np1,k) = a(1,np1,k)+g(is,1,k)*pmn(np1,i,km)\n 108 continue\n 106 continue\nc compute coefficients for which b(m,n) is available\n do 109 mp1=2,lm1\n m = mp1-1\n mp2 = m+2\nc compute pmn for all i and n=m,...,l-1\n call legin(mode,l,nlat,m,w,pmn,km)\n do 110 k=1,nt\n do 111 i=1,late\n is = nlat-i+1\nc n-m even\n do 112 np1=mp1,nlat,2\n a(mp1,np1,k) = a(mp1,np1,k)+g(i,2*m,k)*pmn(np1,i,km)\n b(mp1,np1,k) = b(mp1,np1,k)+g(i,2*m+1,k)*pmn(np1,i,km)\n 112 continue\nc n-m odd\n do 113 np1=mp2,nlat,2\n a(mp1,np1,k) = a(mp1,np1,k)+g(is,2*m,k)*pmn(np1,i,km)\n b(mp1,np1,k) = b(mp1,np1,k)+g(is,2*m+1,k)*pmn(np1,i,km)\n 113 continue\n 111 continue\n 110 continue\n 109 continue\n if (nlon .eq. l+l-2) then\nc compute a(l,np1) coefficients only\n m = l-1\n call legin(mode,l,nlat,m,w,pmn,km)\n do 114 k=1,nt\n do 114 i=1,late\n is = nlat-i+1\nc n-m even\n do 124 np1=l,nlat,2\n a(l,np1,k) = a(l,np1,k)+0.5*g(i,nlon,k)*pmn(np1,i,km)\n 124 continue\n lp1 = l+1\nc n-m odd\n do 125 np1=lp1,nlat,2\n a(l,np1,k) = a(l,np1,k)+0.5*g(is,nlon,k)*pmn(np1,i,km)\n 125 continue\n 114 continue\n end if\n else\nc half sphere\nc overwrite g(i) with wts(i)*(g(i)+g(i)) for i=1,...,nlate/2\n nl2 = nlat/2\n do 116 k=1,nt\n do 116 j=1,nlon\n do 115 i=1,nl2\n g(i,j,k) = wts(i)*(g(i,j,k)+g(i,j,k))\n 115 continue\nc adjust equator separately if a grid point\n if (nl2.lt.late) g(late,j,k) = wts(late)*g(late,j,k)\n 116 continue\nc set m = 0 coefficients first\n m = 0\n call legin(mode,l,nlat,m,w,pmn,km)\n ms = 1\n if (mode.eq.1) ms = 2\n do 117 k=1,nt\n do 117 i=1,late\n do 117 np1=ms,nlat,2\n a(1,np1,k) = a(1,np1,k)+g(i,1,k)*pmn(np1,i,km)\n 117 continue\nc compute coefficients for which b(m,n) is available\n do 118 mp1=2,lm1\n m = mp1-1\n ms = mp1\n if (mode.eq.1) ms = mp1+1\nc compute pmn for all i and n=m,...,nlat-1\n call legin(mode,l,nlat,m,w,pmn,km)\n do 119 k=1,nt\n do 119 i=1,late\n do 119 np1=ms,nlat,2\n a(mp1,np1,k) = a(mp1,np1,k)+g(i,2*m,k)*pmn(np1,i,km)\n b(mp1,np1,k) = b(mp1,np1,k)+g(i,2*m+1,k)*pmn(np1,i,km)\n 119 continue\n 118 continue\n if (nlon.eq.l+l-2) then\nc compute coefficient a(l,np1) only\n m = l-1\n call legin(mode,l,nlat,m,w,pmn,km)\n ns = l\n if (mode.eq.1) ns = l+1\n do 120 k=1,nt\n do 120 i=1,late\n do 120 np1=ns,nlat,2\n a(l,np1,k) = a(l,np1,k)+0.5*g(i,nlon,k)*pmn(np1,i,km)\n 120 continue\n end if\n end if\n return\n end\n subroutine shagci(nlat,nlon,wshagc,lshagc,dwork,ldwork,ierror)\nc this subroutine must be called before calling shagc with\nc fixed nlat,nlon. it precomputes quantites such as the gaussian\nc points and weights, m=0,m=1 legendre polynomials, recursion\nc recursion coefficients.\n dimension wshagc(lshagc)\n double precision dwork(ldwork)\n ierror = 1\n if (nlat.lt.3) return\n ierror = 2\n if (nlon.lt.4) return\nc set triangular truncation limit for spherical harmonic basis\n l = min0((nlon+2)/2,nlat)\nc set equator or nearest point (if excluded) pointer\n late = (nlat+mod(nlat,2))/2\n l1 = l\n l2 = late\n ierror = 3\nc check permanent work space length\n if (lshagc .lt. nlat*(2*l2+3*l1-2)+3*l1*(1-l1)/2+nlon+15)return\n ierror = 4\n if (ldwork.lt.nlat*(nlat+4))return\n ierror = 0\nc set pointers\n i1 = 1\n i2 = i1+nlat\n i3 = i2+nlat*late\n i4 = i3+nlat*late\n i5 = i4+l*(l-1)/2 +(nlat-l)*(l-1)\n i6 = i5+l*(l-1)/2 +(nlat-l)*(l-1)\n i7 = i6+l*(l-1)/2 +(nlat-l)*(l-1)\nc set indices in temp work for double precision gaussian wts and pts\n idth = 1\n idwts = idth+nlat\n iw = idwts+nlat\n call shagci1(nlat,nlon,l,late,wshagc(i1),wshagc(i2),wshagc(i3),\n 1wshagc(i4),wshagc(i5),wshagc(i6),wshagc(i7),dwork(idth),\n 2dwork(idwts),dwork(iw),ierror)\n if (ierror.ne.0) ierror = 5\n return\n end\n subroutine shagci1(nlat,nlon,l,late,wts,p0n,p1n,abel,bbel,cbel,\n 1 wfft,dtheta,dwts,work,ier)\n dimension wts(nlat),p0n(nlat,late),p1n(nlat,late),abel(1),bbel(1),\n 1 cbel(1),wfft(1)\n double precision pb,dtheta(nlat),dwts(nlat),work(*)\nc compute the nlat gaussian points and weights, the\nc m=0,1 legendre polys for gaussian points and all n,\nc and the legendre recursion coefficients\nc define index function used in storing\nc arrays for recursion coefficients (functions of (m,n))\nc the index function indx(m,n) is defined so that\nc the pairs (m,n) map to [1,2,...,indx(l-1,l-1)] with no\nc \"holes\" as m varies from 2 to n and n varies from 2 to l-1.\nc (m=0,1 are set from p0n,p1n for all n)\nc define for 2.le.n.le.l-1\n indx(m,n) = (n-1)*(n-2)/2+m-1\nc define index function for l.le.n.le.nlat\n imndx(m,n) = l*(l-1)/2+(n-l-1)*(l-1)+m-1\nc preset quantites for fourier transform\n call hrffti(nlon,wfft)\nc compute double precision gaussian points and weights\nc lw = 4*nlat*(nlat+1)+2\n lw = nlat*(nlat+2)\n call gaqd(nlat,dtheta,dwts,work,lw,ier)\n if (ier.ne.0) return\nc store gaussian weights single precision to save computation\nc in inner loops in analysis\n do 100 i=1,nlat\n wts(i) = dwts(i)\n 100 continue\nc initialize p0n,p1n using double precision dnlfk,dnlft\n do 101 np1=1,nlat\n do 101 i=1,late\n p0n(np1,i) = 0.0\n p1n(np1,i) = 0.0\n 101 continue\nc compute m=n=0 legendre polynomials for all theta(i)\n np1 = 1\n n = 0\n m = 0\n call dnlfk(m,n,work)\n do 103 i=1,late\n call dnlft(m,n,dtheta(i),work,pb)\n p0n(1,i) = pb\n 103 continue\nc compute p0n,p1n for all theta(i) when n.gt.0\n do 104 np1=2,nlat\n n = np1-1\n m = 0\n call dnlfk(m,n,work)\n do 105 i=1,late\n call dnlft(m,n,dtheta(i),work,pb)\n p0n(np1,i) = pb\n 105 continue\nc compute m=1 legendre polynomials for all n and theta(i)\n m = 1\n call dnlfk(m,n,work)\n do 106 i=1,late\n call dnlft(m,n,dtheta(i),work,pb)\n p1n(np1,i) = pb\n 106 continue\n 104 continue\nc compute and store swarztrauber recursion coefficients\nc for 2.le.m.le.n and 2.le.n.le.nlat in abel,bbel,cbel\n do 107 n=2,nlat\n mlim = min0(n,l)\n do 107 m=2,mlim\n imn = indx(m,n)\n if (n.ge.l) imn = imndx(m,n)\n abel(imn)=sqrt(float((2*n+1)*(m+n-2)*(m+n-3))/\n 1 float(((2*n-3)*(m+n-1)*(m+n))))\n bbel(imn)=sqrt(float((2*n+1)*(n-m-1)*(n-m))/\n 1 float(((2*n-3)*(m+n-1)*(m+n))))\n cbel(imn)=sqrt(float((n-m+1)*(n-m+2))/\n 1 float(((n+m-1)*(n+m))))\n 107 continue\n return\n end\n", "meta": {"hexsha": "3828179288c3364ca03108533da8e9c3af3eb21e", "size": 23651, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "contrib/spherepack/Src/shagc.f", "max_stars_repo_name": "xylar/cdat", "max_stars_repo_head_hexsha": "8a5080cb18febfde365efc96147e25f51494a2bf", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 62, "max_stars_repo_stars_event_min_datetime": "2018-03-30T15:46:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-08T23:30:24.000Z", "max_issues_repo_path": "contrib/spherepack/Src/shagc.f", "max_issues_repo_name": "xylar/cdat", "max_issues_repo_head_hexsha": "8a5080cb18febfde365efc96147e25f51494a2bf", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 114, "max_issues_repo_issues_event_min_datetime": "2018-03-21T01:12:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-05T12:29:54.000Z", "max_forks_repo_path": "contrib/spherepack/Src/shagc.f", "max_forks_repo_name": "CDAT/uvcdat", "max_forks_repo_head_hexsha": "5133560c0c049b5c93ee321ba0af494253b44f91", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2018-06-06T02:42:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-26T03:27:00.000Z", "avg_line_length": 37.5412698413, "max_line_length": 75, "alphanum_fraction": 0.5696165067, "num_tokens": 7888, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418241572634, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.692262823580725}} {"text": "module module_velnw\n\ncontains\n\n subroutine velnw(km,jm,im,dxs,ro,p,u,dt,f,dys,v,g,dzs,w,h)\n use params_common_sn!, only : ip, jp, kp !, only : ip, jp, kp\n integer, intent(In) :: km\n integer, intent(In) :: jm\n integer, intent(In) :: im\n real, dimension(0:ip), intent(In) :: dxs\n real, intent(In) :: ro\n real, dimension(0:ip+2,0:jp+2,0:kp+1), intent(In) :: p\n real, dimension(0:ip+1,-1:jp+1,0:kp+1), intent(InOut) :: u\n real, intent(In) :: dt\n real, dimension(0:ip,0:jp,0:kp), intent(In) :: f\n real, dimension(0:jp), intent(In) :: dys\n real, dimension(0:ip+1,-1:jp+1,0:kp+1), intent(InOut) :: v\n real, dimension(0:ip,0:jp,0:kp), intent(In) :: g\n real, dimension(-1:kp+2), intent(In) :: dzs\n real, dimension(0:ip+1,-1:jp+1,-1:kp+1), intent(InOut) :: w\n real, dimension(0:ip,0:jp,0:kp), intent(In) :: h\n integer :: k\n integer :: j\n integer :: i\n real :: pz\n! \n! \n! --u velocity\n do k=1,km\n do j=1,jm\n do i=1,im\n pz = (-p(i,j,k)+p(i+1,j,k))/ro/dxs(i)\n u(i,j,k)=u(i,j,k)+dt*(f(i,j,k)-pz)\n u(i,j,k)=u(i,j,k)\n end do\n end do\n end do\n! --v velocity\n do k=1,km\n do j=1,jm\n do i=1,im\n pz = (-p(i,j,k)+p(i,j+1,k))/ro/dys(j)\n! if (k.eq.km/2 .and. j.eq.jm/2 .and. i.eq.im/2) then\n! print *,'timestep', p(i,j,k),p(i,j+1,k),v(i,j,k),v(i,j,k)\n! & +dt*(g(i,j,k)-pz)\n! end if\n v(i,j,k)=v(i,j,k)+dt*(g(i,j,k)-pz)\n v(i,j,k)=v(i,j,k)\n end do\n end do\n end do\n! --w velocity\n do k=1,km-1\n do j=1,jm\n do i=1,im\n pz = (-p(i,j,k)+p(i,j,k+1))/ro/dzs(k)\n w(i,j,k)=w(i,j,k)+dt*(h(i,j,k)-pz)\n w(i,j,k)=w(i,j,k)\n end do\n end do\n end do\n! \n return\n end subroutine velnw\n\nend module module_velnw\n\n", "meta": {"hexsha": "1ce86b4c40301f0b3884eb851e6195dc5034c618", "size": 1867, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "evaluation/coverage/velnw.f95", "max_stars_repo_name": "wimvanderbauwhede/AutoParallel-Fortran", "max_stars_repo_head_hexsha": "87a322d1936e6cc92d83235b9523ef86b6d4b26b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-07-29T12:04:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-29T12:04:10.000Z", "max_issues_repo_path": "evaluation/coverage/velnw.f95", "max_issues_repo_name": "wimvanderbauwhede/AutoParallel-Fortran", "max_issues_repo_head_hexsha": "87a322d1936e6cc92d83235b9523ef86b6d4b26b", "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": "evaluation/coverage/velnw.f95", "max_forks_repo_name": "wimvanderbauwhede/AutoParallel-Fortran", "max_forks_repo_head_hexsha": "87a322d1936e6cc92d83235b9523ef86b6d4b26b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-08-13T09:39:36.000Z", "max_forks_repo_forks_event_max_datetime": "2018-08-13T09:39:36.000Z", "avg_line_length": 27.4558823529, "max_line_length": 71, "alphanum_fraction": 0.4836636315, "num_tokens": 744, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418158002492, "lm_q2_score": 0.7490872131147276, "lm_q1q2_score": 0.6922628173205926}} {"text": "module types\nimplicit none\nprivate\npublic dp\n\ninteger, parameter :: dp=kind(0d0)\n\nend module\n\nmodule find_fit_module\n\n! This module contains a general function find_fit() for a nonlinear least\n! squares fitting. The function can fit any nonlinear expression to any data.\n\nuse minpack_module, only: lmdif1\nuse types, only: dp\nimplicit none\nprivate\npublic find_fit\n\ncontains\n\nsubroutine find_fit(data_x, data_y, expr, pars)\n! Fits the (data_x, data_y) arrays with the function expr(x, pars).\n! The user can provide any nonlinear function 'expr' depending on any number of\n! parameters 'pars' and it must return the evaluated expression on the\n! array 'x'. The arrays 'data_x' and 'data_y' must have the same\n! length.\nreal(dp), intent(in) :: data_x(:), data_y(:)\ninterface\n function expr(x, pars) result(y)\n use types, only: dp\n implicit none\n real(dp), intent(in) :: x(:), pars(:)\n real(dp) :: y(size(x))\n end function\nend interface\nreal(dp), intent(inout) :: pars(:)\n\nreal(dp) :: tol, fvec(size(data_x))\ninteger :: iwa(size(pars)), info, m, n\nreal(dp), allocatable :: wa(:)\n\ntol = sqrt(epsilon(1._dp))\nm = size(fvec)\nn = size(pars)\nallocate(wa(m*n + 5*n + m))\ncall lmdif1(fcn, m, n, pars, fvec, tol, info, iwa, wa, size(wa))\nif (info /= 1) stop \"failed to converge\"\n\ncontains\n\nsubroutine fcn(m, n, x, fvec, iflag)\ninteger, intent(in) :: m, n\ninteger, intent(inout) :: iflag\nreal(dp), intent(in) :: x(n)\nreal(dp), intent(out) :: fvec(m)\n! Suppress compiler warning:\nfvec(1) = iflag\nfvec = data_y - expr(data_x, x)\nend subroutine\n\nend subroutine\n\nend module\n\n\nprogram example_primes\n\n! Find a nonlinear fit of the form a*x*log(b + c*x) to a list of primes.\n\nuse find_fit_module, only: find_fit\nuse types, only: dp\nimplicit none\n\nreal(dp) :: pars(3)\nreal(dp), parameter :: y(*) = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, &\n 37, 41, 43, 47, 53, 59, 61, 67, 71]\ninteger :: i\npars = [1._dp, 1._dp, 1._dp]\ncall find_fit([(real(i, dp), i=1,size(y))], y, expression, pars)\nprint *, pars\n\ncontains\n\nfunction expression(x, pars) result(y)\nreal(dp), intent(in) :: x(:), pars(:)\nreal(dp) :: y(size(x))\nreal(dp) :: a, b, c\na = pars(1)\nb = pars(2)\nc = pars(3)\ny = a*x*log(b + c*x)\nend function\n\nend program\n", "meta": {"hexsha": "c014bd3f078ec4ec43feef314c1f9304600f998a", "size": 2213, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/example_primes.f90", "max_stars_repo_name": "ivan-pi/minpack-1", "max_stars_repo_head_hexsha": "d5dbbaf2fe6a1e3704ca865a8583d51f13c94a20", "max_stars_repo_licenses": ["MIT"], "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/example_primes.f90", "max_issues_repo_name": "ivan-pi/minpack-1", "max_issues_repo_head_hexsha": "d5dbbaf2fe6a1e3704ca865a8583d51f13c94a20", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "examples/example_primes.f90", "max_forks_repo_name": "ivan-pi/minpack-1", "max_forks_repo_head_hexsha": "d5dbbaf2fe6a1e3704ca865a8583d51f13c94a20", "max_forks_repo_licenses": ["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.8144329897, "max_line_length": 79, "alphanum_fraction": 0.6714866697, "num_tokens": 714, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625050654264, "lm_q2_score": 0.7431680199891789, "lm_q1q2_score": 0.6922331455836335}} {"text": " SUBROUTINE tutest(data1,n1,data2,n2,t,prob)\r\n INTEGER n1,n2\r\n REAL prob,t,data1(n1),data2(n2)\r\nCU USES avevar,betai\r\n REAL ave1,ave2,df,var1,var2,betai\r\n call avevar(data1,n1,ave1,var1)\r\n call avevar(data2,n2,ave2,var2)\r\n t=(ave1-ave2)/sqrt(var1/n1+var2/n2)\r\n df=(var1/n1+var2/n2)**2/((var1/n1)**2/(n1-1)+(var2/n2)**2/(n2-1))\r\n prob=betai(0.5*df,0.5,df/(df+t**2))\r\n return\r\n END\r\n", "meta": {"hexsha": "222bc7431403ede1466ce04a9e07ff1be01b9d8a", "size": 439, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/tutest.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/tutest.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/tutest.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": 33.7692307692, "max_line_length": 72, "alphanum_fraction": 0.576309795, "num_tokens": 183, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625031628428, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6922331335727268}} {"text": "module plane42rect \n\n !! This module contains subroutines specific to the plane42 element \n !! \n !! The plane42 element has 4 nodes. Each node has 2 degrees-of-freedom,\n !! namely, displacement along the \\(x\\)- and \\(y\\)-coordinate directions.\n !!\n !! The nodes are numbered counter-clockwise as indicated below. The\n !! figure also shows how the element edges are labelled. For example,\n !! edge 1 is the edge between element node 1 and 2.\n !!\n !! N4 E3 N3\n !! o------o \n !! | |\n !! E4 | | E2\n !! | |\n !! o------o\n !! N1 E1 N2\n !! \n !!\n !! `N1` = element node 1, `N2` = element node 2, etc \n !! `E1` = element face 1, `E2` = element face 2, etc \n \n use types\n implicit none\n save\n \n private\n public :: plane42rect_ke, plane42rect_re, plane42rect_ss\n\ncontains\n\n subroutine plane42rect_ke(xe, young, nu, thk, ke)\n\n !! This subroutine constructs the stiffness matrix for\n !! a rectangular 4-noded quad element.\n\n real(wp), intent(in) :: young\n !! Young's Modulus for this element\n real(wp), intent(in) :: nu\n !! Poisson's Ratio for this element\n real(wp), intent(in) :: thk\n !! Thickness of this element\n \n real(wp), dimension(:), intent(in) :: xe\n !! Nodal coordinates of this element in undeformed configuration\n !!\n !! * `xe(1:2)` = \\((x,y)\\)-coordinates of element node 1\n !! * `xe(3:4)` = \\((x,y)\\)-coordinates of element node 1\n !! * `xe(5:6)` = \\((x,y)\\)-coordinates of element node 2\n !! * `xe(7:8)` = \\((x,y)\\)-coordinates of element node 2\n !!\n !! See also [[plane42rect]]\n real(wp), dimension(:,:), intent(out) :: ke\n !! Stiffness matrix\n\n real(wp) :: cmat(3,3), fact, aa, bb\n real(wp) :: t1, t2, t3, t4, t5, t6, t9, t11, t13, t15, &\n t16, t17, t18, t19, t22, t25, t29, t33, &\n t34, t38, t42, t43, t47, t51, t55, t56, &\n t57, t58, t59, t62, t66, t70, t74, t78, &\n t82, t86, t90, t94, t98, t102, t106, t110\n real(wp) :: d11, d12, d13, d22, d23, d33\n\n aa = (xe(3)-xe(1))/2\n bb = (xe(8)-xe(2))/2\n\n ! build constitutive matrix (plane stress)\n cmat = 0\n fact = young/(1-nu**2)\n cmat(1,1) = fact\n cmat(1,2) = fact*nu\n cmat(2,1) = fact*nu\n cmat(2,2) = fact\n cmat(3,3) = fact*(1-nu)/2\n\n d11 = cmat(1,1)\n d12 = cmat(1,2)\n d13 = cmat(1,3)\n d22 = cmat(2,2)\n d23 = cmat(2,3)\n d33 = cmat(3,3)\n\n t1 = bb**2\n t2 = t1*d11\n t3 = 2*t2\n t4 = aa**2\n t5 = t4*d33\n t6 = 2*t5\n t9 = 3*d13*aa*bb\n t11 = 1/aa\n t13 = 1/bb\n t15 = (t3+t6+t9)*t11*t13/6\n t16 = d13*t1\n t17 = 4*t16\n t18 = t4*d23\n t19 = 4*t18\n t22 = 3*d12*aa*bb\n t25 = 3*aa*d33*bb\n t29 = (t17+t19+t22+t25)*t11*t13/12\n t33 = (-t3+t5)*t11*t13/6\n t34 = 2*t18\n t38 = (-t17+t34+t22-t25)*t11*t13/12\n t42 = (t2+t5+t9)*t11*t13/6\n t43 = 2*t16\n t47 = (t43+t34+t22+t25)*t11*t13/12\n t51 = (-t2+t6)*t11*t13/6\n t55 = (-t43+t19+t22-t25)*t11*t13/12\n t56 = d33*t1\n t57 = 2*t56\n t58 = t4*d22\n t59 = 2*t58\n t62 = 3*aa*d23*bb\n t66 = (t57+t59+t62)*t11*t13/6\n t70 = (-t17+t34-t22+t25)*t11*t13/12\n t74 = (-t57+t58)*t11*t13/6\n t78 = (t56+t58+t62)*t11*t13/6\n t82 = (-t43+t19-t22+t25)*t11*t13/12\n t86 = (-t56+t59)*t11*t13/6\n t90 = (t3+t6-t9)*t11*t13/6\n t94 = (t17+t19-t22-t25)*t11*t13/12\n t98 = (t2+t5-t9)*t11*t13/6\n t102 = (t43+t34-t22-t25)*t11*t13/12\n t106 = (t57+t59-t62)*t11*t13/6\n t110 = (t56+t58-t62)*t11*t13/6\n ke(1,1) = t15\n ke(1,2) = t29\n ke(1,3) = t33\n ke(1,4) = t38\n ke(1,5) = -t42\n ke(1,6) = -t47\n ke(1,7) = -t51\n ke(1,8) = -t55\n ke(2,1) = t29\n ke(2,2) = t66\n ke(2,3) = t70\n ke(2,4) = t74\n ke(2,5) = -t47\n ke(2,6) = -t78\n ke(2,7) = -t82\n ke(2,8) = -t86\n ke(3,1) = t33\n ke(3,2) = t70\n ke(3,3) = t90\n ke(3,4) = t94\n ke(3,5) = -t51\n ke(3,6) = -t82\n ke(3,7) = -t98\n ke(3,8) = -t102\n ke(4,1) = t38\n ke(4,2) = t74\n ke(4,3) = t94\n ke(4,4) = t106\n ke(4,5) = -t55\n ke(4,6) = -t86\n ke(4,7) = -t102\n ke(4,8) = -t110\n ke(5,1) = -t42\n ke(5,2) = -t47\n ke(5,3) = -t51\n ke(5,4) = -t55\n ke(5,5) = t15\n ke(5,6) = t29\n ke(5,7) = t33\n ke(5,8) = t38\n ke(6,1) = -t47\n ke(6,2) = -t78\n ke(6,3) = -t82\n ke(6,4) = -t86\n ke(6,5) = t29\n ke(6,6) = t66\n ke(6,7) = t70\n ke(6,8) = t74\n ke(7,1) = -t51\n ke(7,2) = -t82\n ke(7,3) = -t98\n ke(7,4) = -t102\n ke(7,5) = t33\n ke(7,6) = t70\n ke(7,7) = t90\n ke(7,8) = t94\n ke(8,1) = -t55\n ke(8,2) = -t86\n ke(8,3) = -t102\n ke(8,4) = -t110\n ke(8,5) = t38\n ke(8,6) = t74\n ke(8,7) = t94\n ke(8,8) = t106\n\n ke = ke*thk\n end subroutine plane42rect_ke\n!\n!--------------------------------------------------------------------------------------------------\n!\n subroutine plane42rect_re(xe, eface, fe, thk, re)\n\n !! This subroutine computes the element load vector due\n !! to surface traction (traction is always perpendicular\n !! to element face).\n\n ! inputs:\n ! xe\t\tnodal coordniates\n ! eface\t\tface number\n ! fe\t\tpressure value\n ! thk\t\tthickness\n ! re\t\telement load vector (output)\n \n\n integer, intent(in) :: eface\n !! Element face where traction (pressure) is applied\n\n real(wp), intent(in) :: fe\n !! Value of surface traction (pressure)\n real(wp), intent(in) :: thk\n !! Thickness of this element\n real(wp), dimension(:), intent(in) :: xe\n !! Nodal coordinates of this element in undeformed configuration (see also [[plane42rect_ke]])\n real(wp), intent(out) :: re(8)\n !! Element force vector\n !!\n !! * `re(1:2)` = \\((f_x^1, f_y^1)\\) force at element node 1 in \\(x\\)- and y-direction\n !! * `re(3:4)` = \\((f_x^2, f_y^2)\\) force at element node 1 in \\(x\\)- and y-direction\n !! * etc...\n real(wp) :: aa, bb, nface(2,8), f(2)\n\n aa = (xe(3)-xe(1))/2\n bb = (xe(8)-xe(2))/2\n\n nface = 0\n f = 0\n if (eface == 1) then\n nface(1,1) = aa\n nface(1,3) = aa\n nface(2,2) = aa\n nface(2,4) = aa\n f(2) = fe\n elseif (eface == 2) then\n nface(1,3) = bb\n nface(1,5) = bb\n nface(2,4) = bb\n nface(2,6) = bb\n f(1) = -fe\n elseif (eface == 3) then\n nface(1,5) = aa\n nface(1,7) = aa\n nface(2,6) = aa\n nface(2,8) = aa\n f(2) = -fe\n elseif (eface == 4) then\n nface(1,1) = bb\n nface(1,7) = bb\n nface(2,2) = bb\n nface(2,8) = bb\n f(1) = fe\n endif\n \n re = matmul(transpose(nface), f) * thk\n \n end subroutine plane42rect_re\n!\n!--------------------------------------------------------------------------------------------------\n!\n subroutine plane42rect_ss(xe, de, young, nu, estress, estrain, element_evaluation_x, element_evaluation_y)\n\n !! This subrotuine computes the element stress and strain (The location inside the element\n !! where stress and and strain is evaluated, is defined inside the subroutine).\n\n real(wp), intent(in) :: young\n !! Young's Modulus for this element\n real(wp), intent(in) :: nu \n !! Poisson's Ratio for this element\n real(wp), intent(in) :: element_evaluation_x, element_evaluation_y\n !! Point of evaluation for continuum elements\n real(wp), dimension(:), intent(in) :: xe\n !! Nodal coordinates of this element in undeformed configuration (see also [[plane42rect_ke]])\n real(wp), dimension(:), intent(in) :: de\n !! Displacement field\n !!\n !! * `de(1:2)` = displacement of element node 1 along \\(x\\)- and \\(y\\)-axis, respectively\n !! * `de(3:4)` = displacement of element node 2 along \\(x\\)- and \\(y\\)-axis, respectively\n !! * etc...\n real(wp), dimension(:), intent(out) :: estress\n !! Stress at a point inside the element\n !!\n !! * `estress(1)` = \\(\\sigma_{11}\\)\n !! * `estress(2)` = \\(\\sigma_{22}\\)\n !! * `estress(3)` = \\(\\sigma_{12}\\)\n real(wp), dimension(:), intent(out) :: estrain\n !! Strain at a point inside the element\n !!\n !! * `estrain(1)` = \\(\\epsilon_{11}\\)\n !! * `estrain(2)` = \\(\\epsilon_{22}\\)\n !! * `estrain(3)` = \\(\\epsilon_{12}\\)\n real(wp) :: bmat(3, 8), cmat(3, 3)\n real(wp) :: factc, factb, aa, bb\n\t\t\n\t\t! Element dimensions\n aa = (xe(3)-xe(1))/2\n bb = (xe(8)-xe(2))/2\n\n ! Build strain-displacement matrix\n bmat = 0\n factb = 1/(4*aa*bb)\n\n bmat(1,1) = factb*(-bb+element_evaluation_y)\n bmat(3,1) = factb*(-aa+element_evaluation_x)\n bmat(2,2) = bmat(3,1)\n bmat(3,2) = bmat(1,1)\n\n bmat(1,3) = factb*( bb-element_evaluation_y)\n bmat(3,3) = factb*(-aa-element_evaluation_x)\n bmat(2,4) = bmat(3,3)\n bmat(3,4) = bmat(1,3)\n\n bmat(1,5) = factb*(bb+element_evaluation_y)\n bmat(3,5) = factb*(aa+element_evaluation_x)\n bmat(2,6) = bmat(3,5)\n bmat(3,6) = bmat(1,5)\n\n bmat(1,7) = factb*(-bb-element_evaluation_y)\n bmat(3,7) = factb*( aa-element_evaluation_x)\n bmat(2,8) = bmat(3,7)\n bmat(3,8) = bmat(1,7)\n\n ! Compute element strain\n estrain = matmul(bmat, de)\n\n ! Build constitutive matrix (plane stress)\n cmat = 0\n factc = young/(1-nu**2)\n cmat(1,1) = factc\n cmat(1,2) = factc*nu\n cmat(2,1) = factc*nu\n cmat(2,2) = factc\n cmat(3,3) = factc*(1-nu)/2\n\n ! Compute element stress\n estress = matmul(cmat, estrain)\n\n ! Compute principal stress and direction\n ! print *, \"stress:\",estress\n end subroutine plane42rect_ss\n\nend module plane42rect\n", "meta": {"hexsha": "a87df1cce5fd8bff10df241cd849e299979a024b", "size": 10869, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/elements/plane42rect.f90", "max_stars_repo_name": "Sebastian-dm/finite-element", "max_stars_repo_head_hexsha": "aba1e152b85e579d04e35bdcf50205ee2639dcf2", "max_stars_repo_licenses": ["MIT"], "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/elements/plane42rect.f90", "max_issues_repo_name": "Sebastian-dm/finite-element", "max_issues_repo_head_hexsha": "aba1e152b85e579d04e35bdcf50205ee2639dcf2", "max_issues_repo_licenses": ["MIT"], "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/elements/plane42rect.f90", "max_forks_repo_name": "Sebastian-dm/finite-element", "max_forks_repo_head_hexsha": "aba1e152b85e579d04e35bdcf50205ee2639dcf2", "max_forks_repo_licenses": ["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.4132947977, "max_line_length": 110, "alphanum_fraction": 0.4586438495, "num_tokens": 3829, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248225478306, "lm_q2_score": 0.7371581684030624, "lm_q1q2_score": 0.6922098182743694}} {"text": " SUBROUTINE princi(ndime,i,ll)\r\n !\r\n ! Compute principal values and directions of a 3-D 2nd order tensor\r\n ! used to compute principal values and directions of INERTIA tensor\r\n ! NOT adequate for Cauchy-Green tensor\r\n ! not very efficient but called once in a run\r\n !\r\n IMPLICIT NONE\r\n INTEGER (kind=4),INTENT (IN) :: ndime !problem dimension, MUST be 3\r\n REAL (kind=8), INTENT(IN OUT) :: i(ndime,ndime), & ! inertia tensor in global system (IN)\r\n ll(ndime,ndime) ! local system at the node (IN)\r\n\r\n REAL (kind=8),PARAMETER :: pi = 3.14159265358979\r\n INTEGER (kind=4) :: k,lg(1)\r\n REAL (kind=8) :: i1,i2,i3,i13,phi,lp(3),la,a(2,2),det,l(3,3),pr(3)\r\n\r\n ! compute mean value and deviator tensor\r\n i1 = (i(1,1) + i(2,2) + i(3,3)) ! I1\r\n i13 = i1/3d0 ! I1/3\r\n i(1,1) = i(1,1) -i13 ! deviator tensor\r\n i(2,2) = i(2,2) -i13\r\n i(3,3) = i(3,3) -i13\r\n ! compute principal values\r\n i2 =SQRT(4d0*( - i(1,1)*i(2,2) - i(1,1)*i(3,3) - i(2,2)*i(3,3) & ! (4/3 I2)^(1/2)\r\n + i(1,2)**2 + i(1,3)**2 + i(2,3)**2 )/3d0)\r\n i3 = i(1,1)*i(2,2)*i(3,3) + 2*i(1,2)*i(2,3)*i(3,1) & !third inv (det)\r\n -i(1,1)*i(2,3)**2 - i(2,2)*i(1,3)**2 - i(3,3)*i(1,2)**2\r\n IF(i2/i1 < 1.e-6)THEN !all eigenvalues are almost equal\r\n i(1,1) = i(1,1) + i13\r\n i(2,2) = i(2,2) + i13\r\n i(3,3) = i(3,3) + i13\r\n ll(:,1) = (/ 1d0, 0d0, 0d0 /)\r\n ll(:,2) = (/ 0d0, 1d0, 0d0 /)\r\n ll(:,3) = (/ 0d0, 0d0, 1d0 /)\r\n RETURN\r\n END IF\r\n phi = ASIN(-4d0*i3/(i2**3))/3d0 !angle\r\n lp(1) = i2*SIN(phi+2d0/3d0*pi) !largest root\r\n lp(2) = i2*SIN(phi) !interm. root\r\n lp(3) = i2*SIN(phi+4d0/3d0*pi) !smallest root\r\n ! compute firt and third principal directions\r\n DO k=1,3,2 !principal directions 1 & 3\r\n ! first option, use the first two equations\r\n a(1,1) = i(1,1) - lp(k)\r\n a(1,2) = i(1,2)\r\n a(2,1) = i(2,1)\r\n a(2,2) = i(2,2) - lp(k)\r\n det = a(1,1)*a(2,2) - a(1,2)*a(2,1)\r\n IF( ABS(det) > 1d-8)THEN\r\n i1 = (-i(1,3)*a(2,2)+i(2,3)*a(1,2) )/det\r\n i2 = ( i(1,3)*a(2,1)-i(2,3)*a(1,1) )/det\r\n i3 = 1d0\r\n la = SQRT(i1**2+i2**2+i3**2)\r\n l(1,k) = i1/la\r\n l(2,k) = i2/la\r\n l(3,k) = i3/la\r\n ELSE\r\n ! second option, use the last two equations\r\n a(1,1) = i(2,2) - lp(k)\r\n a(1,2) = i(2,3)\r\n a(2,1) = i(3,2)\r\n a(2,2) = i(3,3) - lp(k)\r\n det = a(1,1)*a(2,2) - a(1,2)*a(2,1)\r\n IF( ABS(det) > 1d-8)THEN\r\n i1 = 1d0\r\n i2 = (-i(2,1)*a(2,2)+i(3,1)*a(1,2) )/det\r\n i3 = ( i(2,1)*a(2,1)-i(3,1)*a(1,1) )/det\r\n la = SQRT(i1**2+i2**2+i3**2)\r\n l(1,k) = i1/la\r\n l(2,k) = i2/la\r\n l(3,k) = i3/la\r\n ELSE\r\n ! Third option, use the first and third equations\r\n a(1,1) = i(1,1) - lp(k)\r\n a(1,2) = i(1,3)\r\n a(2,1) = i(3,1)\r\n a(2,2) = i(3,3) - lp(k)\r\n det = a(1,1)*a(2,2) - a(1,2)*a(2,1)\r\n IF( ABS(det) > 1d-8)THEN\r\n i1 = (-i(1,2)*a(2,2)+i(3,2)*a(1,2) )/det\r\n i2 = 1d0\r\n i3 = ( i(1,2)*a(2,1)-i(3,2)*a(1,1) )/det\r\n la = SQRT(i1**2+i2**2+i3**2)\r\n l(1,k) = i1/la\r\n l(2,k) = i2/la\r\n l(3,k) = i3/la\r\n ELSE\r\n RETURN\r\n END IF\r\n END IF\r\n END IF\r\n END DO\r\n ! compute second direction using the vectorial product (det = 1)\r\n CALL vecpro(l(1,3),l(1,1),l(1,2))\r\n !Reorder directions to minimize rotations with respecto to input matrix LL\r\n ! select 1st direction\r\n pr(1) = DOT_PRODUCT(l(:,1),ll(:,1)) !cos 1-1\r\n pr(2) = DOT_PRODUCT(l(:,2),ll(:,1)) !cos 2-1\r\n pr(3) = DOT_PRODUCT(l(:,3),ll(:,1)) !cos 3-1\r\n lg = MAXLOC( ABS(pr) ) !direction with larger component along original X1 direction\r\n IF( lg(1) == 2 )THEN !if it is the second\r\n lp = (/ lp(2), lp(3), lp(1) /) !shift\r\n IF( pr(lg(1)) > 0d0 )THEN\r\n l = RESHAPE((/ l(:,2),l(:,3),l(:,1) /),(/3,3/))\r\n ELSE\r\n l =-RESHAPE((/ l(:,2),l(:,3),l(:,1) /),(/3,3/))\r\n END IF\r\n ELSE IF ( lg(1) == 3 )THEN !if it is the third\r\n lp = (/ lp(3), lp(1), lp(2) /)\r\n IF( pr(lg(1)) > 0d0 )THEN\r\n l = RESHAPE((/ l(:,3),l(:,1),l(:,2) /),(/3,3/))\r\n ELSE\r\n l =-RESHAPE((/ l(:,3),l(:,1),l(:,2) /),(/3,3/))\r\n END IF\r\n END IF\r\n ! select 2nd direction\r\n pr(2) = DOT_PRODUCT(l(:,2),ll(:,2)) !cos 2-2\r\n pr(3) = DOT_PRODUCT(l(:,3),ll(:,2)) !cos 3-2\r\n IF( ABS(pr(3)) > ABS(pr(2)) )THEN !compare 2nd component of the 2-3 directions\r\n lp(2:3) = (/ lp(3), lp(2) /) !swap if necessary\r\n IF( pr(3) > 0d0 )THEN\r\n l(:,2:3) = RESHAPE((/ l(:,3),-l(:,2) /),(/3,2/))\r\n ELSE\r\n l(:,2:3) = RESHAPE((/-l(:,3), l(:,2) /),(/3,2/))\r\n END IF\r\n END IF\r\n ! pass principal values\r\n i(1,1) = lp(1) + i13\r\n i(2,2) = lp(2) + i13\r\n i(3,3) = lp(3) + i13\r\n ll = l\r\n RETURN\r\n END SUBROUTINE princi\r\n", "meta": {"hexsha": "47ac92fe6cb5f01db0f6bbd32f92e872a9d33644", "size": 4897, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/auxil/princi.f90", "max_stars_repo_name": "jerebenitez/IFE-simpact-openfoam", "max_stars_repo_head_hexsha": "2dbcbf3195b22fca1c80ad0da6b3822b6cad5cdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/auxil/princi.f90", "max_issues_repo_name": "jerebenitez/IFE-simpact-openfoam", "max_issues_repo_head_hexsha": "2dbcbf3195b22fca1c80ad0da6b3822b6cad5cdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/auxil/princi.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": 36.5447761194, "max_line_length": 95, "alphanum_fraction": 0.4610986318, "num_tokens": 2250, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971871, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6921886092647906}} {"text": "function boxmuller(n, m)\n real(4) :: n, m\n real(4) :: boxmuller\n real(4) :: pi = 3.14159265359\n\n boxmuller = sqrt(-2.0*log(n)) * cos(2.0*pi*m)\nend function boxmuller\n\nfunction normrand(mu, sigma)\n real(rk) :: mu, sigma\n real(rk) :: normrand\n\n normrand = boxmuller(rand(), rand()) * sigma + mu\nend function normrand\n\n! Monte Carlo fit\nsubroutine fitlinemc(xdata, ydata, n, sigma, a, b, sa, sb, ag, bg)\n real(rk), allocatable :: xdata(:)\n real(rk), allocatable :: ydata(:)\n real(rk), allocatable :: sigma(:)\n\n integer :: n, i, ii, sn\n real(rk) :: a, b, sa, sb\n real(rk) :: am, bm, pm\n real(rk) :: sq, sql, ra, rb, ag, bg\n\n a = ag\n b = bg\n sa = 0.0\n sb = 0.0\n sql = 100000000.0\n\n sn = 1\n am = 0.0\n bm = 0.0\n\n do ii = 1, 50000000\n sq = 0.0\n\n !ra = a + (rand() - 0.5) * a * 0.0001\n !rb = b + (rand() - 0.5) * b * 0.0001\n ra = normrand(a, sqrt(sa))\n rb = normrand(b, sqrt(sb))\n\n i = 1\n do while (i <= n)\n sq = sq + (normrand(ydata(i), sigma(i)) - (ra + rb * xdata(i)))**2 / (sigma(i)**2)\n i = i + 1\n end do\n\n if (sq < sql) then\n a = ra\n b = rb\n\n sn = sn + 1\n\n pm = am\n am = am + (a - am) / sn\n sa = sa + ((a - pm) * (a - am) - sa) / sn\n\n pm = bm\n bm = bm + (b - bm) / sn\n sb = sb + ((b - pm) * (b - bm) - sb) / sn\n\n sql = sq\n end if\n end do\n\n sa = sqrt(sa)\n sb = sqrt(sb)\nend subroutine fitlinemc\n", "meta": {"hexsha": "3abf260fed370e5318f6c7bf9c445a045b087846", "size": 1441, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fitmc.f90", "max_stars_repo_name": "Roninkoi/Scicodes", "max_stars_repo_head_hexsha": "97eb4dc017ad4cd494b545aecaa9fdd7c501a9b7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fitmc.f90", "max_issues_repo_name": "Roninkoi/Scicodes", "max_issues_repo_head_hexsha": "97eb4dc017ad4cd494b545aecaa9fdd7c501a9b7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fitmc.f90", "max_forks_repo_name": "Roninkoi/Scicodes", "max_forks_repo_head_hexsha": "97eb4dc017ad4cd494b545aecaa9fdd7c501a9b7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.0138888889, "max_line_length": 90, "alphanum_fraction": 0.4829979181, "num_tokens": 592, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942067038785, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.692188608433557}} {"text": " PROGRAM xpowell\r\nC driver for routine powell\r\n INTEGER NDIM\r\n REAL FTOL\r\n PARAMETER(NDIM=3,FTOL=1.0E-6)\r\n INTEGER i,iter,np\r\n REAL fret,p(NDIM),xi(NDIM,NDIM)\r\n np=NDIM\r\n DATA xi/1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0/\r\n DATA p/1.5,1.5,2.5/\r\n call powell(p,xi,NDIM,np,FTOL,iter,fret)\r\n write(*,'(/1x,a,i3)') 'Iterations:',iter\r\n write(*,'(/1x,a/1x,3f12.6)') 'Minimum found at: ',(p(i),i=1,NDIM)\r\n write(*,'(/1x,a,f12.6)') 'Minimum function value =',fret\r\n write(*,'(/1x,a)') 'True minimum of function is at:'\r\n write(*,'(1x,3f12.6/)') 1.0,2.0,3.0\r\n END\r\n REAL FUNCTION func(x)\r\n REAL bessj0,x(3)\r\n func=0.5-bessj0((x(1)-1.0)**2+(x(2)-2.0)**2+(x(3)-3.0)**2)\r\n END\r\n", "meta": {"hexsha": "368872cd20c0d0e130717f03497b3bff631982a4", "size": 765, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xpowell.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xpowell.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xpowell.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": 34.7727272727, "max_line_length": 72, "alphanum_fraction": 0.5189542484, "num_tokens": 333, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942171172602, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6921886067710884}} {"text": "module Mod_sldsup_calculateAU\n use typre\n implicit none \n \n contains\n\n subroutine getAU_S(nd,tn,mu,J,b,gdev,AU)\n integer(ip), intent(in) :: nd,tn\n real(rp), intent(in) :: mu,J,gdev(tn),b(nd,nd)\n real(rp), intent(inout) :: AU(tn)\n real(rp) :: i(tn),b_ii\n real(rp) :: C(tn),bvoigt(tn)\n\n call get2ndIITensor_voigt(nd,tn,i)\n call trace(nd,b,b_ii)\n call getVoigtStress(tn,nd,b,bvoigt)\n\n !Stress tensor term: (b - (b_ll/nd)*i)_ij\n C = (bvoigt - (b_ii/nd)*i)\n\n !A(U): (J/2mu)*S_ij -0.5(b-(b_ll/nd)*i)_ij\n AU = 0.5_rp*((J/mu)*gdev-C)\n\n end subroutine\n\n subroutine getAU_S_OSGS(nd,tn,mu,b,gdev,AU)\n integer(ip), intent(in) :: nd,tn\n real(rp), intent(in) :: mu,gdev(tn),b(nd,nd)\n real(rp), intent(inout) :: AU(tn)\n real(rp) :: i(tn),b_ii\n real(rp) :: C(tn),bvoigt(tn)\n\n call get2ndIITensor_voigt(nd,tn,i)\n call trace(nd,b,b_ii)\n call getVoigtStress(tn,nd,b,bvoigt)\n\n !Stress tensor term: (b - (b_ll/nd)*i)_ij\n C = (bvoigt - (b_ii/nd)*i)\n\n !A(U): (J/2mu)*S_ij -0.5(b-(b_ll/nd)*i)_ij\n AU = -0.5_rp*C\n\n end subroutine\n\n end module\n", "meta": {"hexsha": "6696ad58551da16b3da4b1d1f6c9974f2d61040d", "size": 1242, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Sources/modules/solids/models/sldsup/Elmopes/neohookean/Mod_sldsup_calculateAU_NH.f90", "max_stars_repo_name": "ciaid-colombia/InsFEM", "max_stars_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-24T08:19:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-24T08:19:54.000Z", "max_issues_repo_path": "Sources/modules/solids/models/sldsup/Elmopes/neohookean/Mod_sldsup_calculateAU_NH.f90", "max_issues_repo_name": "ciaid-colombia/InsFEM", "max_issues_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Sources/modules/solids/models/sldsup/Elmopes/neohookean/Mod_sldsup_calculateAU_NH.f90", "max_forks_repo_name": "ciaid-colombia/InsFEM", "max_forks_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.0, "max_line_length": 67, "alphanum_fraction": 0.5273752013, "num_tokens": 470, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971871, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.6921885996226141}} {"text": "module open_linalg_m\n\n use, intrinsic :: iso_fortran_env, only: sp => real32, dp => real64, stderr => error_unit\n implicit none\n private\n\n public :: det, inv, matmul, operator(.i.), operator(.x.), solve\n\n interface operator(.x.)\n module procedure matmul_sp, matmul_dp, cmatmul_sp, cmatmul_dp, &\n rcmatmul_sp, rcmatmul_dp, crmatmul_sp, crmatmul_dp\n end interface\n\n interface matmul\n module procedure matmul_sp, matmul_dp, cmatmul_sp, cmatmul_dp, &\n rcmatmul_sp, rcmatmul_dp, crmatmul_sp, crmatmul_dp\n end interface matmul\n\n interface det\n module procedure det_sp, det_dp\n end interface det\n\n interface operator(.i.)\n module procedure inv_sp, inv_dp, cinv_sp, cinv_dp\n end interface\n\n interface inv\n module procedure inv_sp, inv_dp, cinv_sp, cinv_dp\n end interface inv\n\n interface solve\n module procedure solve_sp, solve_dp, csolve_sp, csolve_dp\n end interface solve\n\ncontains\n\n function inv_sp(a) result(b)\n !! calculate inverse of a single precision matrix\n real(sp), intent(in) :: a(:, :)\n real(sp) b(size(a, 2), size(a, 1))\n integer ipiv(size(a, 1)), info\n real(sp) work(size(a, 2))\n\n b = a\n ! http://www.netlib.org/lapack/explore-html/d8/ddc/group__real_g_ecomputational_ga8d99c11b94db3d5eac75cac46a0f2e17.html\n call sgetrf(size(a, 1), size(a, 2), b, size(a, 1), ipiv, info)\n if (info < 0) then\n write (stderr, *) 'sgetrf: illegal value in argument ', info\n error stop\n else if (info > 0) then\n write (stderr, *) 'sgetrf: singular matrix, U(i,i) is exactly zero, info = ', info\n error stop\n end if\n\n ! http://www.netlib.org/lapack/explore-html/d8/ddc/group__real_g_ecomputational_ga1af62182327d0be67b1717db399d7d83.html\n call sgetri(size(a, 2), b, size(a, 1), ipiv, work, size(a, 2), info)\n if (info < 0) then\n write (stderr, *) 'sgetri: illegal value in argument ', info\n error stop\n else if (info > 0) then\n write (stderr, *) 'sgetri: singular matrix, U(i,i) is exactly zero, info = ', info\n error stop\n end if\n\n end function inv_sp\n\n function inv_dp(a) result(b)\n !! calculate inverse of a double precision matrix\n real(dp), intent(in) :: a(:, :)\n real(dp) b(size(a, 2), size(a, 1))\n integer ipiv(size(a, 1)), info\n real(dp) work(size(a, 2))\n\n b = a\n ! http://www.netlib.org/lapack/explore-html/d8/ddc/group__real_g_ecomputational_ga8d99c11b94db3d5eac75cac46a0f2e17.html\n call dgetrf(size(a, 1), size(a, 2), b, size(a, 1), ipiv, info)\n if (info < 0) then\n write (stderr, *) 'dgetrf: illegal value in argument ', info\n error stop\n else if (info > 0) then\n write (stderr, *) 'dgetrf: singular matrix, U(i,i) is exactly zero, info = ', info\n error stop\n end if\n\n ! http://www.netlib.org/lapack/explore-html/d8/ddc/group__real_g_ecomputational_ga1af62182327d0be67b1717db399d7d83.html\n call dgetri(size(a, 2), b, size(a, 1), ipiv, work, size(a, 2), info)\n if (info < 0) then\n write (stderr, *) 'dgetri: illegal value in argument ', info\n error stop\n else if (info > 0) then\n write (stderr, *) 'dgetri: singular matrix, U(i,i) is exactly zero, info = ', info\n error stop\n end if\n\n end function inv_dp\n\n function cinv_sp(a) result(b)\n !! calculate inverse of a single precision matrix\n complex(sp), intent(in) :: a(:, :)\n complex(sp) b(size(a, 2), size(a, 1))\n integer ipiv(size(a, 1)), info\n complex(sp) work(size(a, 2))\n\n b = a\n ! http://www.netlib.org/lapack/explore-html/d8/ddc/group__real_g_ecomputational_ga8d99c11b94db3d5eac75cac46a0f2e17.html\n call cgetrf(size(a, 1), size(a, 2), b, size(a, 1), ipiv, info)\n if (info < 0) then\n write (stderr, *) 'cgetrf: illegal value in argument ', info\n error stop\n else if (info > 0) then\n write (stderr, *) 'cgetrf: singular matrix, U(i,i) is exactly zero, info = ', info\n error stop\n end if\n\n ! http://www.netlib.org/lapack/explore-html/d8/ddc/group__real_g_ecomputational_ga1af62182327d0be67b1717db399d7d83.html\n call cgetri(size(a, 2), b, size(a, 1), ipiv, work, size(a, 2), info)\n if (info < 0) then\n write (stderr, *) 'cgetri: illegal value in argument ', info\n error stop\n else if (info > 0) then\n write (stderr, *) 'cgetri: singular matrix, U(i,i) is exactly zero, info = ', info\n error stop\n end if\n\n end function cinv_sp\n\n function cinv_dp(a) result(b)\n !! calculate inverse of a double precision matrix\n complex(dp), intent(in) :: a(:, :)\n complex(dp) b(size(a, 2), size(a, 1))\n integer ipiv(size(a, 1)), info\n complex(dp) work(size(a, 2))\n\n b = a\n ! http://www.netlib.org/lapack/explore-html/d8/ddc/group__real_g_ecomputational_ga8d99c11b94db3d5eac75cac46a0f2e17.html\n call zgetrf(size(a, 1), size(a, 2), b, size(a, 1), ipiv, info)\n if (info < 0) then\n write (stderr, *) 'zgetrf: illegal value in argument ', info\n error stop\n else if (info > 0) then\n write (stderr, *) 'zgetrf: singular matrix, U(i,i) is exactly zero, info = ', info\n error stop\n end if\n\n ! http://www.netlib.org/lapack/explore-html/d8/ddc/group__real_g_ecomputational_ga1af62182327d0be67b1717db399d7d83.html\n call zgetri(size(a, 2), b, size(a, 1), ipiv, work, size(a, 2), info)\n if (info < 0) then\n write (stderr, *) 'zgetri: illegal value in argument ', info\n error stop\n else if (info > 0) then\n write (stderr, *) 'zgetri: singular matrix, U(i,i) is exactly zero, info = ', info\n error stop\n end if\n\n end function cinv_dp\n\n function solve_sp(a, b) result(x)\n !! solve linear system of single precision\n real(sp), intent(in) :: a(:, :), b(:, :)\n real(sp) x(size(b, 1), size(b, 2))\n\n real(sp) a_(size(a, 1), size(a, 2))\n integer ipiv(size(a, 1))\n integer info\n\n a_ = a; x = b\n ! http://www.netlib.org/lapack/explore-html/d0/db8/group__real_g_esolve_ga3b05fb3999b3d7351cb3101a1fd28e78.html\n call sgesv(size(a, 1), size(b, 2), a_, size(a, 1), ipiv, x, size(b, 1), info)\n\n if (info < 0) then\n write (stderr, *) 'sgesv: illegal value in argument ', info\n error stop\n else if (info > 0) then\n write (stderr, *) 'sgesv: singular matrix, U(i,i) is exactly zero, info = ', info\n error stop\n end if\n\n end function solve_sp\n\n function solve_dp(a, b) result(x)\n !! solve linear system of double precision\n real(dp), intent(in) :: a(:, :), b(:, :)\n real(dp) x(size(b, 1), size(b, 2))\n\n real(dp) a_(size(a, 1), size(a, 2))\n integer ipiv(size(a, 1))\n integer info\n\n a_ = a; x = b\n ! http://www.netlib.org/lapack/explore-html/d7/d3b/group__double_g_esolve_ga5ee879032a8365897c3ba91e3dc8d512.html\n call dgesv(size(a, 1), size(b, 2), a_, size(a, 1), ipiv, x, size(b, 1), info)\n\n if (info < 0) then\n write (stderr, *) 'dgesv: illegal value in argument ', info\n error stop\n else if (info > 0) then\n write (stderr, *) 'dgesv: singular matrix, U(i,i) is exactly zero, info = ', info\n error stop\n end if\n\n end function solve_dp\n \n function csolve_sp(a, b) result(x)\n !! solve linear system of single precision\n complex(sp), intent(in) :: a(:, :), b(:, :)\n complex(sp) x(size(b, 1), size(b, 2))\n\n complex(sp) a_(size(a, 1), size(a, 2))\n integer ipiv(size(a, 1))\n integer info\n\n a_ = a; x = b\n ! http://www.netlib.org/lapack/explore-html/d0/db8/group__real_g_esolve_ga3b05fb3999b3d7351cb3101a1fd28e78.html\n call cgesv(size(a, 1), size(b, 2), a_, size(a, 1), ipiv, x, size(b, 1), info)\n\n if (info < 0) then\n write (stderr, *) 'cgesv: illegal value in argument ', info\n error stop\n else if (info > 0) then\n write (stderr, *) 'cgesv: singular matrix, U(i,i) is exactly zero, info = ', info\n error stop\n end if\n\n end function csolve_sp\n \n function csolve_dp(a, b) result(x)\n !! solve linear system of double precision\n complex(dp), intent(in) :: a(:, :), b(:, :)\n complex(dp) x(size(b, 1), size(b, 2))\n\n complex(dp) a_(size(a, 1), size(a, 2))\n integer ipiv(size(a, 1))\n integer info\n\n a_ = a; x = b\n ! http://www.netlib.org/lapack/explore-html/d7/d3b/group__double_g_esolve_ga5ee879032a8365897c3ba91e3dc8d512.html\n call zgesv(size(a, 1), size(b, 2), a_, size(a, 1), ipiv, x, size(b, 1), info)\n\n if (info < 0) then\n write (stderr, *) 'zgesv: illegal value in argument ', info\n error stop\n else if (info > 0) then\n write (stderr, *) 'zgesv: singular matrix, U(i,i) is exactly zero, info = ', info\n error stop\n end if\n\n end function csolve_dp\n\n function det_sp(a) result(d)\n !! calculate determinant of a single precision matrix\n real(sp), intent(in) :: a(:, :)\n real(sp) d\n real(sp) a_(size(a, 1), size(a, 2))\n integer ipiv(size(a, 1)), info, i\n\n a_ = a\n ! http://www.netlib.org/lapack/explore-html/d8/ddc/group__real_g_ecomputational_ga8d99c11b94db3d5eac75cac46a0f2e17.html\n call sgetrf(size(a, 1), size(a, 2), a_, size(a, 1), ipiv, info)\n if (info < 0) then\n write (stderr, *) 'sgetrf: illegal value in argument ', info\n error stop\n else if (info > 0) then\n write (stderr, *) 'sgetrf: singular matrix, U(i,i) is exactly zero, info = ', info\n error stop\n end if\n\n d = 1.0_sp\n do i = 1, size(a, 2)\n if (ipiv(i) /= i) then\n d = -d*a_(i, i)\n else\n d = d*a_(i, i)\n end if\n end do\n\n end function det_sp\n\n function det_dp(a) result(d)\n !! calculate determinant of a double precision matrix\n real(dp), intent(in) :: a(:, :)\n real(dp) d\n real(dp) a_(size(a, 1), size(a, 2))\n integer ipiv(size(a, 1)), info, i\n\n a_ = a\n ! http://www.netlib.org/lapack/explore-html/d8/ddc/group__real_g_ecomputational_ga8d99c11b94db3d5eac75cac46a0f2e17.html\n call dgetrf(size(a, 1), size(a, 2), a_, size(a, 1), ipiv, info)\n if (info < 0) then\n write (stderr, *) 'dgetrf: illegal value in argument ', info\n error stop\n else if (info > 0) then\n write (stderr, *) 'dgetrf: singular matrix, U(i,i) is exactly zero, info = ', info\n error stop\n end if\n\n d = 1.0_dp\n do i = 1, size(a, 2)\n if (ipiv(i) /= i) then\n d = -d*a_(i, i)\n else\n d = d*a_(i, i)\n end if\n end do\n\n end function det_dp\n\n function matmul_sp(a, b) result(c)\n !! matrix multiplication of single precision matrices\n real(sp), intent(in) :: a(:, :), b(:, :)\n integer m, n, k\n real(sp) c(size(a, 1), size(b, 2))\n\n m = size(a, 1)\n n = size(b, 2)\n k = size(a, 2)\n ! http://www.netlib.org/lapack/explore-html/d1/d54/group__double__blas__level3_gaeda3cbd99c8fb834a60a6412878226e1.html\n call sgemm( &\n 'N', 'N', &\n m, n, k, &\n 1.0_sp, a, m, b, k, &\n 0.0_sp, c, m)\n\n end function matmul_sp\n\n function matmul_dp(a, b) result(c)\n !! matrix multiplication of double precision matrices\n real(dp), intent(in) :: a(:, :), b(:, :)\n real(dp) c(size(a, 1), size(b, 2))\n integer m, n, k\n\n m = size(a, 1)\n n = size(b, 2)\n k = size(a, 2)\n ! http://www.netlib.org/lapack/explore-html/d1/d54/group__double__blas__level3_gaeda3cbd99c8fb834a60a6412878226e1.html\n call dgemm( &\n 'N', 'N', &\n m, n, k, &\n 1.0_dp, a, m, b, k, &\n 0.0_dp, c, m)\n\n end function matmul_dp\n\n function cmatmul_sp(a, b) result(c)\n !! matrix multiplication of single precision complex matrices\n complex(sp), intent(in) :: a(:, :), b(:, :)\n complex(sp) c(size(a, 1), size(b, 2))\n integer m, n, k\n\n m = size(a, 1)\n n = size(b, 2)\n k = size(a, 2)\n ! http://www.netlib.org/lapack/explore-html/d1/d54/group__double__blas__level3_gaeda3cbd99c8fb834a60a6412878226e1.html\n call cgemm( &\n 'N', 'N', &\n m, n, k, &\n (1.0_sp, 0.0_sp), a, m, b, k, &\n (0.0_sp, 0.0_sp), c, m)\n\n end function cmatmul_sp\n\n function cmatmul_dp(a, b) result(c)\n !! matrix multiplication of double precision complex matrices\n complex(dp), intent(in) :: a(:, :), b(:, :)\n complex(dp) c(size(a, 1), size(b, 2))\n integer m, n, k\n\n m = size(a, 1)\n n = size(b, 2)\n k = size(a, 2)\n ! http://www.netlib.org/lapack/explore-html/d1/d54/group__double__blas__level3_gaeda3cbd99c8fb834a60a6412878226e1.html\n call zgemm( &\n 'N', 'N', &\n m, n, k, &\n (1.0_dp, 0.0_dp), a, m, b, k, &\n (0.0_dp, 0.0_dp), c, m)\n\n end function cmatmul_dp\n\n function rcmatmul_sp(a, b) result(c)\n !! matrix multiplication of single precision complex matrices\n real(sp), intent(in) :: a(:, :)\n complex(sp), intent(in) :: b(:, :)\n complex(sp) c(size(a, 1), size(b, 2))\n integer m, n, k\n\n m = size(a, 1)\n n = size(b, 2)\n k = size(a, 2)\n ! http://www.netlib.org/lapack/explore-html/d1/d54/group__double__blas__level3_gaeda3cbd99c8fb834a60a6412878226e1.html\n call cgemm( &\n 'N', 'N', &\n m, n, k, &\n (1.0_sp, 0.0_sp), cmplx(a, kind=sp), m, b, k, &\n (0.0_sp, 0.0_sp), c, m)\n\n end function rcmatmul_sp\n\n function rcmatmul_dp(a, b) result(c)\n !! matrix multiplication of double precision complex matrices\n real(dp), intent(in) :: a(:, :)\n complex(dp), intent(in) :: b(:, :)\n complex(dp) c(size(a, 1), size(b, 2))\n integer m, n, k\n\n m = size(a, 1)\n n = size(b, 2)\n k = size(a, 2)\n ! http://www.netlib.org/lapack/explore-html/d1/d54/group__double__blas__level3_gaeda3cbd99c8fb834a60a6412878226e1.html\n call zgemm( &\n 'N', 'N', &\n m, n, k, &\n (1.0_dp, 0.0_dp), cmplx(a, kind=dp), m, b, k, &\n (0.0_dp, 0.0_dp), c, m)\n\n end function rcmatmul_dp\n\n function crmatmul_sp(a, b) result(c)\n !! matrix multiplication of single precision complex matrices\n complex(sp), intent(in) :: a(:, :)\n real(sp), intent(in) :: b(:, :)\n complex(sp) c(size(a, 1), size(b, 2))\n integer m, n, k\n\n m = size(a, 1)\n n = size(b, 2)\n k = size(a, 2)\n ! http://www.netlib.org/lapack/explore-html/d1/d54/group__double__blas__level3_gaeda3cbd99c8fb834a60a6412878226e1.html\n call cgemm( &\n 'N', 'N', &\n m, n, k, &\n (1.0_sp, 0.0_sp), a, m, cmplx(b, kind=sp), k, &\n (0.0_sp, 0.0_sp), c, m)\n\n end function crmatmul_sp\n\n function crmatmul_dp(a, b) result(c)\n !! matrix multiplication of double precision complex matrices\n complex(dp), intent(in) :: a(:, :)\n real(dp), intent(in) :: b(:, :)\n complex(dp) c(size(a, 1), size(b, 2))\n integer m, n, k\n\n m = size(a, 1)\n n = size(b, 2)\n k = size(a, 2)\n ! http://www.netlib.org/lapack/explore-html/d1/d54/group__double__blas__level3_gaeda3cbd99c8fb834a60a6412878226e1.html\n call zgemm( &\n 'N', 'N', &\n m, n, k, &\n (1.0_dp, 0.0_dp), a, m, cmplx(b, kind=dp), k, &\n (0.0_dp, 0.0_dp), c, m)\n\n end function crmatmul_dp\n\nend module open_linalg_m\n", "meta": {"hexsha": "43576a0d0b83472b819f068eea42ae5469571b9f", "size": 16293, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/open_linalg.f90", "max_stars_repo_name": "zoziha/open_linalg", "max_stars_repo_head_hexsha": "219c7b4e014719a6d80581c132803712dcddc43c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2022-03-09T10:40:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-13T08:59:14.000Z", "max_issues_repo_path": "src/open_linalg.f90", "max_issues_repo_name": "zoziha/open_linalg", "max_issues_repo_head_hexsha": "219c7b4e014719a6d80581c132803712dcddc43c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-03-09T16:57:28.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-10T00:29:32.000Z", "max_forks_repo_path": "src/open_linalg.f90", "max_forks_repo_name": "zoziha/open_linalg", "max_forks_repo_head_hexsha": "219c7b4e014719a6d80581c132803712dcddc43c", "max_forks_repo_licenses": ["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.7302631579, "max_line_length": 127, "alphanum_fraction": 0.5565580311, "num_tokens": 5221, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.760650658103136, "lm_q1q2_score": 0.6921213666721601}} {"text": "c\nc\tMATH -- C callable math functions. This is the only portable way\nc\tto access the Fortran intrinsic functions from C. As a local\nc\toptimization it is possible to add defines to map these external\nc\tnames onto the local Fortran library functions, but since C is not\nc\tgenerally used intensively for computations and all floating point\nc\tis done in double precision anyway, it is probably not worth it.\nc\n\n\tinteger function xnint (x)\n\tdouble precision x\n\t\txnint = nint (x)\n\tend\n\n\tdouble precision function xexp (x)\n\tdouble precision x\n\t\txexp = exp(x)\n\tend\n\n\tdouble precision function xlog (x)\n\tdouble precision x\n\t\txlog = log(x)\n\tend\n\n\tdouble precision function xlog10 (x)\n\tdouble precision x\n\t\txlog10 = log10(x)\n\tend\n\n\tdouble precision function xpow (x, y)\n\tdouble precision x\n\tdouble precision y\n\t\txpow = x ** y\n\tend\n\n\tdouble precision function xsqrt (x)\n\tdouble precision x\n\t\txsqrt = sqrt(x)\n\tend\n\n\tdouble precision function xsin (x)\n\tdouble precision x\n\t\txsin = sin(x)\n\tend\n\n\tdouble precision function xcos (x)\n\tdouble precision x\n\t\txcos = cos(x)\n\tend\n\n\tdouble precision function xtan (x)\n\tdouble precision x\n\t\txtan = tan(x)\n\tend\n\n\tdouble precision function xasin (x)\n\tdouble precision x\n\t\txasin = asin(x)\n\tend\n\n\tdouble precision function xacos (x)\n\tdouble precision x\n\t\txacos = acos(x)\n\tend\n\n\tdouble precision function xatan (x)\n\tdouble precision x\n\t\txatan = atan(x)\n\tend\n\n\tdouble precision function xatan2 (x, y)\n\tdouble precision x\n\tdouble precision y\n\t\txatan2 = atan2(x,y)\n\tend\n", "meta": {"hexsha": "89279451e101b355c474edac83ad55f4b763e20e", "size": 1489, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iraf.v2161/sys/libc/mathf.f", "max_stars_repo_name": "ysBach/irafdocgen", "max_stars_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:19:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T16:48:42.000Z", "max_issues_repo_path": "sys/libc/mathf.f", "max_issues_repo_name": "kirxkirx/iraf", "max_issues_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-30T13:48:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-02T19:40:25.000Z", "max_forks_repo_path": "sys/libc/mathf.f", "max_forks_repo_name": "kirxkirx/iraf", "max_forks_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.5921052632, "max_line_length": 68, "alphanum_fraction": 0.7327065144, "num_tokens": 396, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.909907001151883, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6921213493647972}} {"text": "! { dg-do run }\n!\n! Testing IEEE modules on large real kinds\n\nprogram test\n\n use ieee_arithmetic\n implicit none\n\n ! k1 and k2 will be large real kinds, if supported, and single/double\n ! otherwise\n integer, parameter :: k1 = &\n max(ieee_selected_real_kind(precision(0.d0) + 1), kind(0.))\n integer, parameter :: k2 = &\n max(ieee_selected_real_kind(precision(0._k1) + 1), kind(0.d0))\n\n real(kind=k1) :: x1, y1\n real(kind=k2) :: x2, y2\n logical :: l\n\n ! Checking ieee_is_finite\n\n if (.not. ieee_is_finite(huge(0._k1))) STOP 1\n if (ieee_is_finite(ieee_value(0._k1, ieee_negative_inf))) STOP 2\n x1 = -42\n if (.not. ieee_is_finite(x1)) STOP 3\n if (ieee_is_finite(sqrt(x1))) STOP 4\n\n if (.not. ieee_is_finite(huge(0._k2))) STOP 5\n if (ieee_is_finite(ieee_value(0._k2, ieee_negative_inf))) STOP 6\n x2 = -42\n if (.not. ieee_is_finite(x2)) STOP 7\n if (ieee_is_finite(sqrt(x2))) STOP 8\n\n ! Other ieee_is intrinsics\n\n if (ieee_is_nan(huge(0._k1))) STOP 9\n if (.not. ieee_is_negative(-huge(0._k1))) STOP 10\n if (.not. ieee_is_normal(-huge(0._k1))) STOP 11\n\n if (ieee_is_nan(huge(0._k2))) STOP 12\n if (.not. ieee_is_negative(-huge(0._k2))) STOP 13\n if (.not. ieee_is_normal(-huge(0._k2))) STOP 14\n\n ! ieee_support intrinsics\n\n if (.not. ieee_support_datatype(x1)) STOP 15\n if (.not. ieee_support_denormal(x1)) STOP 16\n if (.not. ieee_support_divide(x1)) STOP 17\n if (.not. ieee_support_inf(x1)) STOP 18\n if (.not. ieee_support_io(x1)) STOP 19\n if (.not. ieee_support_nan(x1)) STOP 20\n if (.not. ieee_support_rounding(ieee_nearest, x1)) STOP 21\n if (.not. ieee_support_sqrt(x1)) STOP 22\n if (.not. ieee_support_standard(x1)) STOP 23\n\n l = ieee_support_underflow_control(x1)\n\n if (.not. ieee_support_datatype(x2)) STOP 24\n if (.not. ieee_support_denormal(x2)) STOP 25\n if (.not. ieee_support_divide(x2)) STOP 26\n if (.not. ieee_support_inf(x2)) STOP 27\n if (.not. ieee_support_io(x2)) STOP 28\n if (.not. ieee_support_nan(x2)) STOP 29\n if (.not. ieee_support_rounding(ieee_nearest, x2)) STOP 30\n if (.not. ieee_support_sqrt(x2)) STOP 31\n if (.not. ieee_support_standard(x2)) STOP 32\n\n l = ieee_support_underflow_control(x2)\n\n ! ieee_value and ieee_class\n\n if (.not. ieee_is_nan(ieee_value(x1, ieee_quiet_nan))) STOP 33\n if (ieee_class(ieee_value(x1, ieee_positive_denormal)) &\n /= ieee_positive_denormal) STOP 34\n\n if (.not. ieee_is_nan(ieee_value(x2, ieee_quiet_nan))) STOP 35\n if (ieee_class(ieee_value(x2, ieee_positive_denormal)) &\n /= ieee_positive_denormal) STOP 36\n\n ! ieee_unordered\n\n if (.not. ieee_unordered(ieee_value(x1, ieee_quiet_nan), 0._k1)) STOP 37\n if (ieee_unordered(ieee_value(x1, ieee_negative_inf), 0._k1)) STOP 38\n\n if (.not. ieee_unordered(ieee_value(x2, ieee_quiet_nan), 0._k2)) STOP 39\n if (ieee_unordered(ieee_value(x2, ieee_negative_inf), 0._k2)) STOP 40\n\n ! ieee_copy_sign\n\n if (.not. ieee_class(ieee_copy_sign(ieee_value(x1, ieee_positive_inf), -1.)) &\n == ieee_negative_inf) STOP 41\n if (.not. ieee_class(ieee_copy_sign(0._k1, -42._k2)) &\n == ieee_negative_zero) STOP 42\n\n if (.not. ieee_class(ieee_copy_sign(ieee_value(x2, ieee_positive_inf), -1.)) &\n == ieee_negative_inf) STOP 43\n if (.not. ieee_class(ieee_copy_sign(0._k2, -42._k1)) &\n == ieee_negative_zero) STOP 44\n\n ! ieee_logb\n\n if (ieee_logb (42._k1) /= exponent(42._k1) - 1) STOP 45\n\n if (ieee_logb (42._k2) /= exponent(42._k2) - 1) STOP 46\n\n ! ieee_next_after\n\n if (ieee_next_after(42._k1, ieee_value(x1, ieee_positive_inf)) &\n /= 42._k1 + spacing(42._k1)) STOP 47\n\n if (ieee_next_after(42._k2, ieee_value(x2, ieee_positive_inf)) &\n /= 42._k2 + spacing(42._k2)) STOP 48\n\n ! ieee_rem\n\n if (ieee_class(ieee_rem(-42._k1, 2._k1)) /= ieee_negative_zero) &\n STOP 49\n\n if (ieee_class(ieee_rem(-42._k2, 2._k2)) /= ieee_negative_zero) &\n STOP 50\n\n ! ieee_rint\n\n if (ieee_rint(-1.1_k1) /= -1._k1) STOP 51\n if (ieee_rint(huge(x1)) /= huge(x1)) STOP 52\n\n if (ieee_rint(-1.1_k2) /= -1._k2) STOP 53\n if (ieee_rint(huge(x2)) /= huge(x2)) STOP 54\n\n ! ieee_scalb\n\n x1 = sqrt(42._k1)\n if (ieee_scalb(x1, 2) /= 4._k1 * x1) STOP 55\n if (ieee_scalb(x1, -2) /= x1 / 4._k1) STOP 56\n\n x2 = sqrt(42._k2)\n if (ieee_scalb(x2, 2) /= 4._k2 * x2) STOP 57\n if (ieee_scalb(x2, -2) /= x2 / 4._k2) STOP 58\n\nend program test\n", "meta": {"hexsha": "65b42e9041fd9010abc469e3cf6276a1eff19a9d", "size": 4321, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/ieee/large_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/ieee/large_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/ieee/large_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": 30.4295774648, "max_line_length": 80, "alphanum_fraction": 0.6794723444, "num_tokens": 1585, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127417985636, "lm_q2_score": 0.8104789178257654, "lm_q1q2_score": 0.6920782748905321}} {"text": "! { dg-do run }\nprogram aint_anint_1\n \n implicit none\n\n real(4) :: r = 42.7, r1, r2\n real(8) :: s = 42.7D0, s1, s2\n\n r1 = aint(r)\n r2 = aint(r,kind=8)\n if (abs(r1 - r2) > 0.1) STOP 1\n\n r1 = anint(r)\n r2 = anint(r,kind=8)\n if (abs(r1 - r2) > 0.1) STOP 2\n\n s1 = aint(s)\n s2 = aint(s, kind=4)\n if (abs(s1 - s2) > 0.1) STOP 3\n\n s1 = anint(s)\n s2 = anint(s, kind=4)\n if (abs(s1 - s2) > 0.1) STOP 4\n\n\nend program aint_anint_1\n\n", "meta": {"hexsha": "812e9e467ceceeb6e3571e89b00c9e649997a93c", "size": 439, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/aint_anint_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/aint_anint_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/aint_anint_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": 15.6785714286, "max_line_length": 32, "alphanum_fraction": 0.5284738041, "num_tokens": 227, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357701094304, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.6920564937722006}} {"text": " program demo_sqrt\n use, intrinsic :: iso_fortran_env, only : real_kinds, &\n & real32, real64, real128\n implicit none\n real(kind=real64) :: x, x2\n complex :: z, z2\n\n x = 2.0_real64\n z = (1.0, 2.0)\n write(*,*)x,z\n\n x2 = sqrt(x)\n z2 = sqrt(z)\n write(*,*)x2,z2\n\n x2 = x**0.5\n z2 = z**0.5\n write(*,*)x2,z2\n\n end program demo_sqrt\n", "meta": {"hexsha": "b4c1cbeb139f2c3d2490dcc6b37a2e8b7a35259e", "size": 402, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/sqrt.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/sqrt.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/sqrt.f90", "max_forks_repo_name": "urbanjost/fortran-intrinsic-descriptions", "max_forks_repo_head_hexsha": "59b3618e6c247802cb26f32a1a77e8b718bcc165", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-06T15:56:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-06T15:56:31.000Z", "avg_line_length": 19.1428571429, "max_line_length": 59, "alphanum_fraction": 0.4925373134, "num_tokens": 150, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.867035752930664, "lm_q2_score": 0.7981867705385763, "lm_q1q2_score": 0.6920564675732097}} {"text": "\n! KGEN-generated Fortran source file\n!\n! Filename : mo_math_constants.f90\n! Generated at: 2015-02-19 15:30:32\n! KGEN version: 0.4.4\n\n\n\n MODULE mo_math_constants\n USE mo_kind, ONLY: wp\n IMPLICIT NONE\n PUBLIC\n ! Mathematical constants defined:\n !\n !--------------------------------------------------------------\n ! Fortran name | C name | meaning |\n !--------------------------------------------------------------\n ! euler | M_E | e |\n ! log2e | M_LOG2E | log2(e) |\n ! log10e | M_LOG10E | log10(e) |\n ! ln2 | M_LN2 | ln(2) |\n ! ln10 | M_LN10 | ln(10) |\n ! pi | M_PI | pi |\n ! pi_2 | M_PI_2 | pi/2 |\n ! pi_4 | M_PI_4 | pi/4 |\n ! rpi | M_1_PI | 1/pi |\n ! rpi_2 | M_2_PI | 2/pi |\n ! rsqrtpi_2 | M_2_SQRTPI | 2/(sqrt(pi)) |\n ! sqrt2 | M_SQRT2 | sqrt(2) |\n ! sqrt1_2 | M_SQRT1_2 | 1/sqrt(2) |\n ! sqrt3 | | sqrt(3) |\n ! sqrt1_3 | | 1/sqrt(3) |\n ! half angle of pentagon |\n ! pi_5 | | pi/5 |\n ! latitude of the lowest major triangle corner |\n ! and latitude of the major hexagonal faces centers |\n ! phi0 | | pi/2 -2acos(1/(2*sin(pi/5))) |\n ! conversion factor from radians to degree |\n ! rad2deg | | 180/pi |\n ! conversion factor from degree to radians |\n ! deg2rad | | pi/180 |\n ! one_third | | 1/3 |\n !-------------------------------------------------------------|\n REAL(KIND=wp), parameter :: pi = 3.14159265358979323846264338327950288419717_wp\n\n ! read subroutines\n END MODULE mo_math_constants\n", "meta": {"hexsha": "792ef885ed665a0b2f0acdea82dda40d7e554679", "size": 2528, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/ncar_kernels/PSRAD_lrtm_codereview/src/mo_math_constants.f90", "max_stars_repo_name": "kammerdienerb/flang", "max_stars_repo_head_hexsha": "8cc4a02b94713750f09fe6b756d33daced0b4a74", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 716, "max_stars_repo_stars_event_min_datetime": "2017-05-17T17:58:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T11:20:58.000Z", "max_issues_repo_path": "test/ncar_kernels/PSRAD_lrtm_codereview/src/mo_math_constants.f90", "max_issues_repo_name": "kammerdienerb/flang", "max_issues_repo_head_hexsha": "8cc4a02b94713750f09fe6b756d33daced0b4a74", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 794, "max_issues_repo_issues_event_min_datetime": "2017-05-18T19:27:40.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T23:22:11.000Z", "max_forks_repo_path": "test/ncar_kernels/PSRAD_lrtm_codereview/src/mo_math_constants.f90", "max_forks_repo_name": "kammerdienerb/flang", "max_forks_repo_head_hexsha": "8cc4a02b94713750f09fe6b756d33daced0b4a74", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 157, "max_forks_repo_forks_event_min_datetime": "2017-05-17T18:50:33.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T07:06:45.000Z", "avg_line_length": 51.5918367347, "max_line_length": 95, "alphanum_fraction": 0.3014240506, "num_tokens": 583, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942377652497, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6920255828265952}} {"text": "FUNCTION betacf(a,b,x)\r\nINTEGER MAXIT\r\nREAL*8 betacf,a,b,x,EPS,FPMIN\r\nPARAMETER (MAXIT=100,EPS=3.e-7,FPMIN=1.e-30)\r\nINTEGER m,m2\r\nREAL*8 aa,c,d,del,h,qab,qam,qap\r\nqab=a+b\r\nqap=a+1.\r\nqam=a-1.\r\nc=1.\r\nd=1.-qab*x/qap\r\nif(abs(d).lt.FPMIN)d=FPMIN\r\nd=1./d\r\nh=d\r\ndo m=1,MAXIT\r\n m2=2*m\r\n aa=m*(b-m)*x/((qam+m2)*(a+m2))\r\n d=1.+aa*d\r\n if(abs(d).lt.FPMIN)d=FPMIN\r\n c=1.+aa/c\r\n if(abs(c).lt.FPMIN)c=FPMIN\r\n d=1./d\r\n h=h*d*c\r\n aa=-(a+m)*(qab+m)*x/((a+m2)*(qap+m2))\r\n d=1.+aa*d\r\n if(abs(d).lt.FPMIN)d=FPMIN\r\n c=1.+aa/c\r\n if(abs(c).lt.FPMIN)c=FPMIN\r\n d=1./d\r\n del=d*c\r\n h=h*del\r\n if(abs(del-1.).lt.EPS)goto 1\r\nenddo\r\npause 'a or b too big, or MAXIT too small in betacf'\r\n1 betacf=h\r\nreturn\r\nEND\r\n", "meta": {"hexsha": "a399cde1058704a8e1efe60a39396434e006ce1f", "size": 701, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "spear/betacf.f90", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "spear/betacf.f90", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "spear/betacf.f90", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.4473684211, "max_line_length": 53, "alphanum_fraction": 0.5763195435, "num_tokens": 343, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220291, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.6920255783692824}} {"text": "subroutine ComputeDG82(DG82, lmax, m, theta0, exitstatus)\n!-------------------------------------------------------------------------------\n!\n! This routine will compute the kernel of Grunbaum et al. 1982\n! that commutes with the space concentration kernel. This\n! kernel is tridiagonal and has simple expressions for\n! its elements. Note that this kernel is multiplied by -1 in\n! comparison to Grunbaum et al. in order that the eigenvectors\n! will be listed in the same order as the eigenvectors of the\n! equivalent space concentration matrix Dllm. While the eigenfunctions\n! of this kernel correspond to the eigenvalues of Dllm, the eigenvalues\n! do NOT!\n!\n! Calling Parameters\n! IN\n! lmax Maximum spherical harmonic degree.\n! theta0 Angular radius of spherical cap IN RADIANS.\n! m Angular order to concentration problem.\n!\n! OUT\n! D0G82 Symmetric tridiagonal kernel with a maximum size of\n! lmax+1 by lmax+1.\n!\n! OPTIONAL (OUT)\n! exitstatus If present, instead of executing a STOP when an error\n! is encountered, the variable exitstatus will be\n! returned describing the error.\n! 0 = No errors;\n! 1 = Improper dimensions of input array;\n! 2 = Improper bounds for input variable;\n! 3 = Error allocating memory;\n! 4 = File IO error.\n!\n! Copyright (c) 2005-2019, SHTOOLS\n! All rights reserved.\n!\n!------------------------------------------------------------------------------\n use ftypes\n\n implicit none\n\n real(dp), intent(out) :: DG82(:,:)\n real(dp), intent(in) :: theta0\n integer(int32), intent(in) :: lmax, m\n integer(int32), intent(out), optional :: exitstatus\n real(dp) :: x\n integer(int32) :: i, n\n\n if (present(exitstatus)) exitstatus = 0\n\n n = lmax + 1 - abs(m)\n\n if (n < 1) then\n print*, \"Error --- ComputeDG82\"\n print*, \"abs(M) must be less than or equal to LMAX.\"\n print*, \"Input values of l and m are \", lmax, m\n if (present(exitstatus)) then\n exitstatus = 2\n return\n else\n stop\n end if\n\n else if (size(DG82(1,:)) < n .or. size(DG82(:,1)) < n) then\n print*, \"Error --- ComputeDG82\"\n print*, \"DG82 must be dimensioned as (LMAX-abs(M)+1,\" // &\n \"LMAX-abs(M)+1) where LMAX and M are \", lmax, m\n print*, \"Input array is dimensioned as \", size(DG82(1,:)), &\n size(DG82(:,1))\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n end if\n\n DG82 = 0.0d0\n\n x = cos(theta0)\n\n DG82(1,1) = x * dble(1+m) * dble(m)\n\n do i = 2, n, 1\n DG82(i,i) = x * dble(i+m) * dble(i+m-1)\n\n DG82(i,i-1) = - sqrt(dble(i-1+m)**2 - dble(m)**2) * &\n ( dble(i-1+m)**2 - dble(lmax+1)**2 ) / &\n sqrt(4.0_dp * dble(i-1+m)**2 - 1.0_dp)\n\n DG82(i-1,i) = DG82(i,i-1)\n\n end do\n\nend subroutine ComputeDG82\n", "meta": {"hexsha": "b5f5d464765c3286c5c3bcf708f5290c6e4e9871", "size": 3191, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/ComputeDG82.f95", "max_stars_repo_name": "mjc87/SHTOOLS", "max_stars_repo_head_hexsha": "8d83c42d1313d5624c4db8c2e57300c5d819834e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 251, "max_stars_repo_stars_event_min_datetime": "2015-01-27T12:58:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T17:19:36.000Z", "max_issues_repo_path": "src/ComputeDG82.f95", "max_issues_repo_name": "mjc87/SHTOOLS", "max_issues_repo_head_hexsha": "8d83c42d1313d5624c4db8c2e57300c5d819834e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 193, "max_issues_repo_issues_event_min_datetime": "2015-03-11T06:21:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T14:05:45.000Z", "max_forks_repo_path": "src/ComputeDG82.f95", "max_forks_repo_name": "mreineck/SHTOOLS", "max_forks_repo_head_hexsha": "fec33f203ee0b47008fd69d4080304d6ebd272e7", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 100, "max_forks_repo_forks_event_min_datetime": "2015-04-03T07:11:05.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-23T23:46:33.000Z", "avg_line_length": 32.8969072165, "max_line_length": 80, "alphanum_fraction": 0.5186461924, "num_tokens": 862, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872046056466901, "lm_q2_score": 0.7799928900257126, "lm_q1q2_score": 0.6920132844024844}} {"text": "! This is a collection of 3 routines to calculate the new mean\r\n! and sum of squares of deviations about the mean (and hence the new\r\n! sample variance or standard deviation) after:\r\n\r\n! 1. A new observation becomes available (routine update).\r\n! 2. An observation is dropped (routine downdate).\r\n! 3. An observation is replaced with a new one (routine replace).\r\n\r\n! Latest revision - 24 November 2001\r\n! Alan Miller (amiller @ bigpond.net.au)\r\n\r\n\r\nSUBROUTINE update(n, mean, sumsq, x)\r\n! x contains the value of the new case.\r\n\r\nIMPLICIT NONE\r\n\r\nINTEGER, INTENT(IN OUT) :: n\r\nREAL, INTENT(IN OUT) :: mean, sumsq\r\nREAL, INTENT(IN) :: x\r\n\r\n! Local variable\r\nREAL :: dev\r\n\r\nn = n + 1\r\ndev = x - mean\r\nmean = mean + dev/n\r\nsumsq = sumsq + dev*(x - mean)\r\n\r\nRETURN\r\nEND SUBROUTINE update\r\n\r\n\r\n\r\nSUBROUTINE downdate(n, mean, sumsq, x)\r\n! x contained the value to be removed.\r\n\r\nIMPLICIT NONE\r\n\r\nINTEGER, INTENT(IN OUT) :: n\r\nREAL, INTENT(IN OUT) :: mean, sumsq\r\nREAL, INTENT(IN) :: x\r\n\r\n! Local variable\r\nREAL :: dev\r\n\r\nn = n - 1\r\ndev = x - mean\r\nmean = mean - dev/n\r\nsumsq = sumsq - dev*(x - mean)\r\n\r\nRETURN\r\nEND SUBROUTINE downdate\r\n\r\n\r\n\r\nSUBROUTINE replace(n, mean, sumsq, x, y)\r\n! x is the value to be removed and replaced with the value y.\r\n\r\nIMPLICIT NONE\r\n\r\nINTEGER, INTENT(IN) :: n\r\nREAL, INTENT(IN OUT) :: mean, sumsq\r\nREAL, INTENT(IN) :: x, y\r\n\r\n! Local variables\r\nREAL :: diff, devx\r\n\r\ndiff = y - x\r\ndevx = x - mean\r\nmean = mean + diff/n\r\nsumsq = sumsq + diff*(devx + y - mean)\r\n\r\nRETURN\r\nEND SUBROUTINE replace\r\n", "meta": {"hexsha": "da5aa2796f754f7bac355ff5a52fb046aed9596c", "size": 1557, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/update.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/update.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/update.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": 20.4868421053, "max_line_length": 69, "alphanum_fraction": 0.6403339756, "num_tokens": 457, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523148, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6920132749823381}} {"text": "module callback_01\n\ncontains\n\nreal function cb(f, a, b)\nreal, intent(in) :: a, b\ninterface\n real function f(x)\n implicit none\n real, intent(in) :: x\n end function\nend interface\ncb = (b-a) + f(a) + f(b)\nend function\n\n\nsubroutine foo(c, d)\nreal :: c, d\nprint *, cb(f, c, d)\n\ncontains\n\nreal function f(x)\nreal, intent(in) :: x\nf = 2*x\nend function f\n\nend subroutine foo\n\nend module\n\nprogram main\n use callback_01\n call foo(1.5, 2.0)\nend program\n", "meta": {"hexsha": "722fd377a47973bd3b218add8e3dac52a84f502c", "size": 456, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "integration_tests/callback_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": "integration_tests/callback_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": 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/callback_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": 12.6666666667, "max_line_length": 25, "alphanum_fraction": 0.6535087719, "num_tokens": 150, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045817875224, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6920132703298424}} {"text": " SUBROUTINE STM(E, Y, Z, K, T, D, P, N)\n! ________________________________________________________\n! | |\n! | FIND THE K-TH SMALLEST EIGENVALUE OF A TRIDIAGONAL |\n! | MATRIX WHOSE CROSS-DIAGONAL PRODUCTS ARE NONNEGATIVE |\n! |USING BOTH THE BISECTION METHOD AND A NEWTON-LIKE METHOD|\n! | |\n! | INPUT: |\n! | |\n! | Y,Z --ENDS OF AN INTERVAL THAT CONTAINS THE |\n! | DESIRED EIGENVALUE |\n! | |\n! | K --INDEX OF DESIRED EIGENVALUE |\n! | |\n! | T --TOLERANCE (ITERATIONS CONTINUE UNTIL |\n! | THE ERROR IN THE EIGENVALUE .LE. T) |\n! | |\n! | D --DIAGONAL OF THE COEFFICIENT MATRIX A |\n! | |\n! | P --CROSS-DIAGONAL PRODUCTS A SUB I+1,I |\n! | TIMES A SUB I,I+1 |\n! | |\n! | N --MATRIX DIMENSION |\n! | |\n! | OUTPUT: |\n! | |\n! | E --EIGENVALUE |\n! | |\n! | BUILTIN FUNCTIONS: ABS,MAX,SIGN,SQRT |\n! | PACKAGE SUBROUTINES: CP,EQL,INP |\n! |________________________________________________________|\n!\n USE stel_kinds\n IMPLICIT NONE\n!-----------------------------------------------\n! D u m m y A r g u m e n t s\n!-----------------------------------------------\n INTEGER :: K, N\n REAL(rprec):: E, Y, Z, T\n REAL(rprec), DIMENSION(N) :: D, P\n!-----------------------------------------------\n! L o c a l P a r a m e t e r s\n!-----------------------------------------------\n REAL(rprec), PARAMETER :: one = 1, zero = 0\n!-----------------------------------------------\n! L o c a l V a r i a b l e s\n!-----------------------------------------------\n INTEGER :: I, J, M\n REAL(rprec) :: A,B,FL,FR,L,Q,R,S,U,V,\n 1 W,D2,D3,D4,P2,P3,P4,D34,D42,D23\n REAL(rprec), DIMENSION(4) :: F, H, X\n REAL(rprec), DIMENSION(4) :: G\n REAL(rprec) :: C, GL, GR\n!-----------------------------------------------\n L = Y\n R = Z\n IF ( L .LT. R ) GOTO 10\n L = Z\n R = Y\n10 IF ( N .EQ. 1 ) GOTO 210\n S = T + T\n U = ONE\n20 U = U/2\n A = ONE + U\n IF (A .GT. ONE) GOTO 20\n U = 5*U\n V = U/2\n CALL CP(L,FL,GL,I,D,P,N)\n CALL CP(R,FR,GR,J,D,P,N)\n IF ( I .GE. K ) GOTO 190\n IF ( J .LT. K ) GOTO 200\nC --------------------------------\nC |*** ISOLATE THE EIGENVALUE ***|\nC --------------------------------\n30 E = R - L\n IF ( E .LE. S ) GOTO 180\n IF ( E .LE. U*(ABS(L)+ABS(R)) ) GOTO 180\n IF ( J .EQ. I+1 ) GOTO 70\n40 A = .5*(L+R)\n CALL CP(A,B,C,M,D,P,N)\n IF ( K .LE. M ) GOTO 50\n L = A\n I = M\n FL = B\n GL = C\n GOTO 30\n50 R = A\n J = M\n FR = B\n GR = C\n GOTO 30\n60 E = R - L\n IF ( E .LE. S ) GOTO 180\n IF ( E .LE. U*(ABS(L)+ABS(R)) ) GOTO 180\n70 X(1) = L\n F(1) = FL\n G(1) = GL\n X(2) = R\n F(2) = FR\n G(2) = GR\n CALL EQL(X,F,G,H,2)\n IF ( H(1) .EQ. H(2) ) GOTO 160\nC ---------------------\nC |*** SECANT STEP ***|\nC ---------------------\n A = X(1) - H(1)*(X(1)-X(2))/(H(1)-H(2))\n Q = A\n W = MAX(T,V*(ABS(L)+ABS(R)))\n IF ( ABS(A-L) .LT. W ) A = L + W\n IF ( ABS(A-R) .LT. W ) A = R - W\n CALL CP(A,B,C,J,D,P,N)\n IF ( I .GE. J ) GOTO 80\n R = A\n FR = B\n GR = C\n GOTO 90\n80 L = A\n FL = B\n GL = C\n90 X(3) = A\n F(3) = B\n G(3) = C\n W = R - L\n IF ( W .LE. S ) GOTO 220\n IF ( W .LE. U*(ABS(L)+ABS(R)) ) GOTO 220\n CALL EQL(X,F,G,H,3)\nC --------------------------------------\nC |*** QUADRATIC INTERPOLATION STEP ***|\nC --------------------------------------\n CALL INP(A,X(1),X(2),X(3),H(1),H(2),H(3),L,R)\n B = L\n IF ( ABS(A-L) .GT. ABS(A-R) ) B = R\nC ------------------------------------\nC |*** APPLY PSEUDO-NEWTON METHOD ***|\nC ------------------------------------\n100 Q = A\n W = MAX(T,V*(ABS(L)+ABS(R)))\n IF ( ABS(A-L) .LT. W ) GOTO 110\n IF ( ABS(A-R) .GT. W ) GOTO 130\n110 IF ( A+A .GT. L+R ) GOTO 120\n A = L + W\n GOTO 130\n120 A = R - W\n130 IF ( A .LE. L ) GOTO 160\n IF ( A .GE. R ) GOTO 160\n E = .5*E\n IF ( E .LT. ABS(B-A) ) GOTO 160\n CALL CP(A,B,C,J,D,P,N)\n IF ( I .GE. J ) GOTO 140\n R = A\n FR = B\n GR = C\n GOTO 150\n140 L = A\n FL = B\n GL = C\n150 W = R - L\n IF ( W .LE. S ) GOTO 220\n IF ( W .LE. U*(ABS(L)+ABS(R)) ) GOTO 220\n X(4) = A\n F(4) = B\n G(4) = C\n CALL EQL(X,F,G,H,4)\n IF ( X(1) .LT. L ) GOTO 160\n IF ( X(1) .GT. R ) GOTO 160\n B = X(1)\n D4 = X(4) - B\n D3 = X(3) - B\n D2 = X(2) - B\n D34 = X(3) - X(4)\n D42 = X(4) - X(2)\n D23 = X(2) - X(3)\n P2 = D2*(ONE+((D2/D3)*D42+(D2/D4)*D23)/D34)\n P3 = D3*(ONE+((D3/D2)*D34+(D3/D4)*D23)/D42)\n P4 = D4*(ONE+((D4/D2)*D34+(D4/D3)*D42)/D23)\n IF (P2 .NE. ZERO) P2 = (H(2)-H(1))/P2\n IF (P3 .NE. ZERO) P3 = (H(3)-H(1))/P3\n IF (P4 .NE. ZERO) P4 = (H(4)-H(1))/P4\n P2 = P2 + P3 + P4\n IF (P2 .EQ. ZERO) GOTO 160\n A = B - H(1)/P2\n GOTO 100\nC --------------------------\nC |*** BISECTION METHOD ***|\nC --------------------------\n160 A = (L+R)/2\n CALL CP(A,B,C,J,D,P,N)\n IF ( I .GE. J ) GOTO 170\n R = A\n FR = B\n GR = C\n GOTO 60\n170 L = A\n FL = B\n GL = C\n GOTO 60\n180 E = (L+R)/2\n RETURN\n190 E = L\n RETURN\n200 E = R\n RETURN\n210 E = D(1)\n IF ( L .GT. E ) E = L\n IF ( R .LT. E ) E = R\n RETURN\n220 E = Q\n RETURN\n END SUBROUTINE STM\n", "meta": {"hexsha": "172f19ae15a15533c16681c10cb5f52ba5294cc1", "size": 6561, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "COBRAVMEC/Sources/STM.f", "max_stars_repo_name": "joseluisvelasco/STELLOPT", "max_stars_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2020-05-08T01:47:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T10:35:28.000Z", "max_issues_repo_path": "COBRAVMEC/Sources/STM.f", "max_issues_repo_name": "joseluisvelasco/STELLOPT", "max_issues_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 77, "max_issues_repo_issues_event_min_datetime": "2020-05-08T07:18:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:20:33.000Z", "max_forks_repo_path": "COBRAVMEC/Sources/STM.f", "max_forks_repo_name": "joseluisvelasco/STELLOPT", "max_forks_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-02-10T13:47:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T12:53:43.000Z", "avg_line_length": 31.2428571429, "max_line_length": 64, "alphanum_fraction": 0.3199207438, "num_tokens": 2184, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045847699186, "lm_q2_score": 0.7799928900257126, "lm_q1q2_score": 0.6920132681187511}} {"text": "#include \"eiscor.h\"\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! d_symtrid_specint\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! This routine computes upper and lower bounds on the spectrum of a \n! real symmetric tridiagonal matrix T.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! INPUT VARIABLES:\n!\n! NEWT LOGICAL\n! .TRUE.: uses Newton's method to refine boundaries\n! .FALSE.: only uses Gerschgorin bounds\n!\n! N INTEGER\n! dimension of matrix\n!\n! D REAL(8) array of dimension (N) \n! diagonal entries of T\n!\n! E REAL(8) array of dimension (N-1)\n! subdiagonal entries of T\n!\n! OUTPUT VARIABLES:\n!\n! A,B REAL(8)\n! upper and lower bounds on the spectrum of T\n!\n! INFO INTEGER\n! INFO = 0 implies successful computation\n! INFO = -1 implies A or B is NAN\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine d_symtrid_specint(NEWT,N,D,E,A,B,INFO)\n\n implicit none\n \n ! input variables\n logical, intent(in) :: NEWT\n integer, intent(in) :: N\n real(8), intent(in) :: D(N), E(N-1)\n real(8), intent(inout) :: A, B\n integer, intent(inout) :: INFO\n\n ! compute variables\n integer :: ii\n real(8) :: ta, tb\n real(8) :: tol = EISCOR_DBL_EPS\n \n ! initialize INFO\n INFO = 0\n\n ! initialize A and B\n A = D(1) - abs(E(1))\n B = D(1) + abs(E(1))\n\n ! loop through diagonals\n do ii=1,N-2\n\n ! compute ta and tb\n ta = D(ii) - abs(E(ii)) - abs(E(ii+1))\n tb = D(ii) + abs(E(ii)) + abs(E(ii+1))\n\n ! check A\n if (ta < A) then\n A = ta\n end if\n\n ! check B\n if (tb > B) then\n B = tb\n end if\n\n end do\n\n ! check final entry\n ta = D(N) - abs(E(N-1))\n tb = D(N) + abs(E(N-1))\n \n ! check A\n if (ta < A) then\n A = ta\n end if\n\n ! check B\n if (tb > B) then\n B = tb\n end if\n\n ! return if A and B are 0\n if ((A.EQ.0d0).AND.(B.EQ.0d0)) then\n return\n end if\n\n ! Newton updates\n if (NEWT) then\n\n ! maximum of 10 corrections\n do ii=1,10\n\n ! correction for A\n call d_symtrid_newtonstep(N,D,E,A,ta,INFO)\n \n ! check if INFO = -1\n if (INFO.EQ.-1) then\n ta = tol\n INFO = 0\n end if\n \n ! correction for B\n call d_symtrid_newtonstep(N,D,E,B,tb,INFO)\n \n ! check if INFO = -1\n if (INFO.EQ.-1) then\n tb = -tol\n INFO = 0\n end if\n \n ! update if not converged\n if ((abs(ta) > tol*abs(A)).AND.(abs(tb) > tol*abs(B))) then\n\n A = A - ta\n B = B - tb\n \n ! exit otherwise\n else\n \n exit\n\n end if\n\n end do\n\n end if\n\n ! check if A and B are NAN\n if ((A.NE.A).OR.(B.NE.B)) then \n INFO = -1\n end if\n\nend subroutine d_symtrid_specint\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! d_symtrid_newtonstep\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! This routine computes a Newton correction for a real number x of a\n! real symmetric tridiagonal matrix T using Sturm sequences.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! INPUT VARIABLES:\n!\n! N INTEGER\n! dimension of matrix\n!\n! D REAL(8) array of dimension (N) \n! diagonal entries of T\n!\n! E REAL(8) array of dimension (N)\n! subdiagonal entries of T\n!\n! X REAL(8)\n! input guess \n!\n! OUTPUT VARIABLES:\n!\n! F REAL(8)\n! computed Newton correction at X\n!\n! INFO INTEGER\n! INFO = 0 implies successful computation\n! INFO = -1 implies zero derivative at X\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine d_symtrid_newtonstep(N,D,E,X,F,INFO)\n\n implicit none\n \n ! input variables\n integer, intent(in) :: N\n real(8), intent(in) :: D(N), E(N-1)\n real(8), intent(in) :: X\n real(8), intent(inout) :: F\n integer, intent(inout) :: INFO\n\n ! compute variables\n integer :: ii\n real(8) :: p0, p1, p2\n real(8) :: d0, d1, d2\n \n ! initialize INFO\n INFO = 0\n\n ! initialize p0, p1 and p2\n p0 = 1d0 \n p1 = D(1) - X\n p2 = (D(2)-X)*p1 - E(1)*E(1)*p0\n\n ! initialize d0, d1 and d2\n d0 = 0d0 \n d1 = -1d0\n d2 = -p1 + (D(2)-X)*d1 - E(1)*E(1)*d0\n\n ! loop through diagonals\n do ii=3,N\n\n ! update d0, d1 and d2\n d0 = -p2 + (D(ii)-X)*d2 - E(ii-1)*E(ii-1)*d1\n d1 = d2\n d2 = d0\n\n ! update p0, p1 and p2\n p0 = (D(ii)-X)*p2 - E(ii-1)*E(ii-1)*p1\n p1 = p2\n p2 = p0\n\n end do\n\n ! compute F\n ! if derivative is zero set Newton step\n ! to zero and throw error\n if (d2.EQ.0d0) then\n F = 0\n INFO = -1\n else\n F = p2/d2\n end if\n\nend subroutine d_symtrid_newtonstep\n", "meta": {"hexsha": "d8cec7919e968a79250370e164f48a49486f67a8", "size": 5008, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/AMVW/src/double/d_symtrid_specint.f90", "max_stars_repo_name": "trcameron/FPML", "max_stars_repo_head_hexsha": "f6aacfcd702f7ce74a45ffaf281e9586dceb1b7e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tests/AMVW/src/double/d_symtrid_specint.f90", "max_issues_repo_name": "trcameron/FPML", "max_issues_repo_head_hexsha": "f6aacfcd702f7ce74a45ffaf281e9586dceb1b7e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/AMVW/src/double/d_symtrid_specint.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": 21.0420168067, "max_line_length": 70, "alphanum_fraction": 0.4580670927, "num_tokens": 1569, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382236515258, "lm_q2_score": 0.8031738034238806, "lm_q1q2_score": 0.6919649318852498}} {"text": " PROGRAM xpade\r\nC driver for routine pade\r\n INTEGER NMAX\r\n PARAMETER(NMAX=100)\r\n INTEGER j,k,n\r\n REAL resid\r\n DOUBLE PRECISION b,d,fac,fn,ratval,x,c(NMAX),cc(NMAX)\r\n1 write(*,*) 'Enter n for PADE routine:'\r\n read(*,*,END=999) n\r\n fac=1\r\n do 11 j=1,2*n+1\r\n c(j)=fac/dble(j)\r\n cc(j)=c(j)\r\n fac=-fac\r\n11 continue\r\n call pade(c,n,resid)\r\n write(*,'(1x,a,1pd16.8)') 'Norm of residual vector=',resid\r\n write(*,*) 'point, func. value, pade series, power series'\r\n do 13 j=1,21\r\n x=(j-1)*0.25\r\n b=0.\r\n do 12 k=2*n+1,1,-1\r\n b=b*x+cc(k)\r\n12 continue\r\n d=ratval(x,c,n,n)\r\n write(*,'(1p4d16.8)') x,fn(x),d,b\r\n13 continue\r\n goto 1\r\n999 END\r\n DOUBLE PRECISION FUNCTION fn(x)\r\n DOUBLE PRECISION x\r\n if (x.eq.0.) then\r\n fn=1.\r\n else\r\n fn=log(1.+x)/x\r\n endif\r\n return\r\n END\r\n", "meta": {"hexsha": "72b85128a77306701f1e45c2272a896619de212b", "size": 963, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xpade.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xpade.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xpade.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.6923076923, "max_line_length": 65, "alphanum_fraction": 0.4849428868, "num_tokens": 329, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.86153820232079, "lm_q2_score": 0.8031737940012417, "lm_q1q2_score": 0.6919649066349983}} {"text": "cc Copyright (C) 2009: Zydrunas Gimbutas and Hong Xiao\ncc Contact: Zydrunas Gimbutas \ncc Hong Xiao \ncc \ncc This software is being released under a modified FreeBSD license\ncc (see COPYING in home directory). \nccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\nc\nc \nc Quadratures for smooth functions on a cube\nc\nc All quadratures are accurate to 15 digits\nc All weights are positive and inside the cube\nc\nc Input:\nc\nc n - the degree of the quadrature (must not exceed 15)\nc\nc Output:\nc\nc fort.11 - quadrature nodes and weights\nc fort.12 - quadrature nodes in gnuplot compatible format\nc fort.14 - cube as contructed in gnuplot compatible format\nc \nc in gnuplot:\nc\nc splot 'fort.14' w l, 'fort.12'\nc\nc\nc\n implicit real *8 (a-h,o-z)\n real *8 rnodes(3,1000),weights(1000)\n real *8 rints(1000),z(3),pols(1000)\n real *8 work(100000)\nc\nc\n call prini(6,13)\nc\nc SET ALL PARAMETERS\nc\n PRINT *, 'ENTER mmax (1..15)'\n READ *, mmax\nc\n call prinf('mmax=*',mmax,1)\nc\nc\n\nc\nc ... retrieve the quadrature rule \nc\n call cubearbq(mmax,rnodes,weights,numnodes)\nc\n call prinf('nummodes=*',numnodes,1)\n call prin2('rnodes=*',rnodes,3*numnodes) \n call prin2('weights=*',weights,numnodes) \nc\n d=0\n do i=1,numnodes\n d=d+weights(i)\n enddo\nc\n call prin2('sum of weights=*',d,1)\nc \nc ... plot the cube\nc\n write(14,*) -1,-1,-1\n write(14,*) +1,-1,-1\n write(14,*) +1,+1,-1\n write(14,*) -1,+1,-1\n write(14,*) -1,-1,-1\n write(14,*)\nc\n write(14,*) -1,-1,+1\n write(14,*) +1,-1,+1\n write(14,*) +1,+1,+1\n write(14,*) -1,+1,+1\n write(14,*) -1,-1,+1\n write(14,*)\nc\n write(14,*) -1,-1,-1\n write(14,*) -1,-1,+1\n write(14,*)\n write(14,*) +1,-1,-1\n write(14,*) +1,-1,+1\n write(14,*)\n write(14,*) +1,+1,-1\n write(14,*) +1,+1,+1\n write(14,*)\n write(14,*) -1,+1,-1\n write(14,*) -1,+1,+1\n write(14,*)\nc\nc\nc ... dump the nodes into a file\nc \n write(11,*) numnodes\n do i=1,numnodes\n write(11,1020) rnodes(1,i),rnodes(2,i),rnodes(3,i),weights(i)\n write(12,*) rnodes(1,i),rnodes(2,i),rnodes(3,i)\n enddo\n 1010 format(i2)\n 1020 format(4(e21.15,2x))\nc\n\nc\nc construct the matrix of values of the orthogonal polynomials\nc at the user-provided nodes \nc\n npols=(mmax+1)*(mmax+2)*(mmax+3)/6\nc\nc\n do 1200 j=1,npols\n rints(j)=0\n 1200 continue\nc\nc\n do 2400 i=1,numnodes\nc\n z(1)=rnodes(1,i)\n z(2)=rnodes(2,i)\n z(3)=rnodes(3,i)\nc \n call lege3eva(mmax,z,pols,work)\nc\n do 2200 j=1,npols\nc\n rints(j)=rints(j)+weights(i)*pols(j)\n\n 2200 continue\n\n 2400 continue\nc\nc\n call prin2('rints=*',rints,npols)\nc\n vol=8.0d0\nc\n d=0\n d=(rints(1)-sqrt(vol))**2\n do i=2,npols\n d=d+rints(i)**2\n enddo\nc\n d=sqrt(d)/npols\nc\n call prin2('error=*',d,1)\nc\n stop\n end\nc\nc\nc\n", "meta": {"hexsha": "9e7a30050f7d310e84411762d40e18ff6ce2eb7b", "size": 3285, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "cubearbq_dr.f", "max_stars_repo_name": "zgimbutas/triasymq", "max_stars_repo_head_hexsha": "940a83c2f3cbbc0295fb87f0a4d411b9435c6678", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-12-16T15:55:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T00:06:27.000Z", "max_issues_repo_path": "cubearbq_dr.f", "max_issues_repo_name": "zgimbutas/triasymq", "max_issues_repo_head_hexsha": "940a83c2f3cbbc0295fb87f0a4d411b9435c6678", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cubearbq_dr.f", "max_forks_repo_name": "zgimbutas/triasymq", "max_forks_repo_head_hexsha": "940a83c2f3cbbc0295fb87f0a4d411b9435c6678", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.4705882353, "max_line_length": 75, "alphanum_fraction": 0.5363774734, "num_tokens": 1174, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543488, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.6919426321447911}} {"text": "c program DRDHERQL\nc>> 1996-05-28 DRDHERQL Krogh Added external statement.\nc>> 1994-10-19 DRDHERQL Krogh Changes to use M77CON\nc>> 1994-09-23 DRDHERQL CLL\nc>> 1992-04-23 CLL\nc>> 1992-03-04 DRDHERQL Krogh Initial version.\nc Demonstrate Hermitian eigenvalue/eigenvector subroutine DHERQL.\nc ------------------------------------------------------------------\nc--D replaces \"?\": DR?HERQL, ?HERQL, ?VECP, ?MATP, ?DOT\nc ------------------------------------------------------------------\n integer I, IERR, J, LDA, LDA3, N\n parameter (LDA = 4)\n parameter (LDA3 = 3*LDA)\n double precision AR(LDA, LDA), AI(LDA, LDA)\n double precision ARSAV(LDA, LDA), AISAV(LDA, LDA), ANORM\n external DDOT\n double precision DDOT, DR(LDA,LDA), DI(LDA,LDA), EVAL(LDA)\n double precision VR(LDA, LDA), VI(LDA, LDA), WORK(LDA3)\n data AR(1,1) / 25.0d0 /\n data (AR(2,I), I=1,2) / -3.0d0, 25.0d0 /\n data (AR(3,I), I=1,3) / -08.0d0, 0.0d0, 25.0d0 /\n data (AR(4,I), I=1,4) / 0.0d0, -08.0d0, 3.0d0, 25.0d0 /\n data AI(1,1) / 0.0d0 /\n data (AI(2,I), I=1,2) / 4.0d0, 0.0d0 /\n data (AI(3,I), I=1,3) / -06.0d0, 0.0d0, 0.0d0 /\n data (AI(4,I), I=1,4) / 0.0d0, 06.0d0, 4.0d0, 0.0d0 /\n data ANORM / 46.0d0 /\n data N /LDA/\nc ------------------------------------------------------------------\n print*,'DRDHERQL.. Demo driver for DHERQL.'\nc\nc First copy AR() and AI() to ARSAV() and AISAV() for later\nc residual check.\nc\n do 20 I = 1,N\n do 10 J = 1,I\n ARSAV(I,J) = AR(I,J)\n ARSAV(J,I) = ARSAV(I,J)\n AISAV(I,J) = AI(I,J)\n AISAV(J,I) = -AISAV(I,J)\n 10 continue\n 20 continue\n\n call DHERQL(AR, AI, LDA, N, EVAL, VR, VI, WORK, IERR)\n if (IERR .eq. 0) then\n call DVECP(EVAL, N, '0 Eigenvalues')\n call DMATP(VR,LDA,N,N,\n * '0 Real parts of eigenvectors as column vectors')\n call DMATP(VI,LDA,N,N,\n * '0 Imaginary parts of eigenvectors as column vectors')\nc\nc As a check compute D = (ASAV*EVEC - EVEC*EVAL) / ANORM.\nc Expect D to be close to the machine precision.\nc\n do 40 J = 1, LDA\n do 30 I = 1, LDA\n DR(I, J) = (DDOT(LDA,ARSAV(I,1),LDA,VR(1,J),1) -\n * DDOT(LDA,AISAV(I,1),LDA,VI(1,J),1) -\n * VR(I,J)*EVAL(J))/ANORM\n DI(I, J) = (DDOT(LDA,ARSAV(I,1),LDA,VI(1,J),1) +\n * DDOT(LDA,AISAV(I,1),LDA,VR(1,J),1) -\n * VI(I,J)*EVAL(J))/ANORM\n 30 continue\n 40 continue\n call DMATP(DR, LDA, N, N,\n * '0Real part of residual matrix D = (A*EVEC - EVEC*EVAL) / ANORM')\n call DMATP(DI, LDA, N, N,\n * '0Imag part of residual matrix D = (A*EVEC - EVEC*EVAL) / ANORM')\n else\n print '(/a,i5)',' Convergence failure in DHERQL, IERR =',IERR\n end if\n stop\n end\n", "meta": {"hexsha": "d7eb396cfb70796436ed51108ca84875e45e31af", "size": 2978, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drdherql.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drdherql.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drdherql.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": 40.2432432432, "max_line_length": 72, "alphanum_fraction": 0.4865681666, "num_tokens": 1142, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094145755218, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.6919426294482942}} {"text": "\n!*********************\nprogram stommel\n use numz\n use input\n use constants\n use face\n implicit none\n real(b8)diff\n real(b8)dx2,dy2,bottom\n real(b8), allocatable:: psi(:,:) ! our calculation grid\n real(b8), allocatable:: new_psi(:,:) ! temp storage for the grid\n real(b8) t1,t2,walltime\n integer i,j,i1,i2,j1,j2\n integer iout\n! get the input. see above for typical values\n read(*,*)nx,ny\n read(*,*)lx,ly\n read(*,*)alpha,beta,gamma\n read(*,*)steps\n! allocate the grid to size nx * ny plus the boundary cells\n allocate(psi(0:nx+1,0:ny+1))\n allocate(new_psi(0:nx+1,0:ny+1))\n allocate(for(0:nx+1,0:ny+1))\n! calculate the constants for the calculations\n dx=lx/(nx+1)\n dy=ly/(ny+1)\n dx2=dx*dx\n dy2=dy*dy\n bottom=2.0_b8*(dx2+dy2)\n a1=(dy2/bottom)+(beta*dx2*dy2)/(2.0_b8*gamma*dx*bottom)\n a2=(dy2/bottom)-(beta*dx2*dy2)/(2.0_b8*gamma*dx*bottom)\n a3=dx2/bottom\n a4=dx2/bottom\n a5=dx2*dy2/(gamma*bottom)\n a6=pi/(ly)\n! set initial guess for the value of the grid\n psi=1.0_b8\n! set the indices for the interior of the grid\n i1=1\n i2=nx\n j1=1\n j2=ny\n! set boundary conditions\n call bc(psi,i1,i2,j1,j2)\n! set the force array\n call do_force(i1,i2,j1,j2)\n new_psi=psi\n! do the jacobian iterations\n iout=steps/100\n if(iout == 0)iout=1\n t1=walltime()\n do i=1,steps\n call do_jacobi(psi,new_psi,diff,i1,i2,j1,j2)\n\tif(mod(i,iout) .eq. 0)write(*,'(i6,1x,g20.10)')i,diff\n enddo\n t2=walltime()\n write(*,'(\"run time =\",f10.2)')t2-t1\n! write out the final grid\n call write_grid(psi,i1,i2,j1,j2)\nend program stommel\n\n\n\n \n\n", "meta": {"hexsha": "0b703c5e52dbc4346d46438d62191323db676007", "size": 1648, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "make/simple/stf_00.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": "make/simple/stf_00.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": "make/simple/stf_00.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": 24.5970149254, "max_line_length": 68, "alphanum_fraction": 0.6171116505, "num_tokens": 635, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094174159127, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.6919426269999855}} {"text": "program Newton\n\treal*8 x(2),t,g(2),A(2,2),Gni(2,2),b(2),f,p(2),ans,aro(2)\n\tdata x /0,0/\n\tdata A /2,-1,-1,2/\n\tdata Gni /0.6666667,0.3333334,0.3333334,0.666666667/\n\tdata b /-10,-4/\n\topen(13,file=\"Newton\")\n\twrite(13,\"(5A13)\")\"f\",\"x1\",\"x2\",\"g1\",\"g2\"\n\tdo\n\tg=matmul(A,x)+b\n\tf=60-10*x(1)-4*x(2)+x(1)*x(1)+x(2)*x(2)-x(1)*x(2)\n\twrite(13,\"(5f13.6)\")f,x,g\n\tcall onedimenmul(g,g,2,ans)\n\tif(ans<0.01) exit\n\tp=matmul(-Gni,g)\n\tx=x+p\n\tend do\n\tclose(13)\nend program Newton\n\n\tsubroutine onedimenmul(m1,m2,n,ans)\n\tinteger n\n\treal*8 m1(n),m2(n),ans\n\tans=0\n\tdo i=1,n\n\t\tans=m1(i)*m2(i)+ans\n\tend do\n\tend subroutine onedimenmul\n", "meta": {"hexsha": "87030db08c6ff772d4d2ab025d5b1e4ed32e16c3", "size": 604, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Newton.f90", "max_stars_repo_name": "DearDon/Optimization", "max_stars_repo_head_hexsha": "f22a95bc1317aff69664516c495d94831dabce51", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Newton.f90", "max_issues_repo_name": "DearDon/Optimization", "max_issues_repo_head_hexsha": "f22a95bc1317aff69664516c495d94831dabce51", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Newton.f90", "max_forks_repo_name": "DearDon/Optimization", "max_forks_repo_head_hexsha": "f22a95bc1317aff69664516c495d94831dabce51", "max_forks_repo_licenses": ["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.8275862069, "max_line_length": 58, "alphanum_fraction": 0.6109271523, "num_tokens": 300, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094145755218, "lm_q2_score": 0.7745833737577158, "lm_q1q2_score": 0.6919426201514377}} {"text": "\n!------------------------------------------------------------------\n! Program to test if my concept for checking that two structures \n! are equal works properly.\n!\n! Works by generating two equal geometric shapes as points \n! (sets of coordinates on a grid), but located at different \n! positions on the grid. If it works correctly, after\n! aligning with the main rotation axis with the z-axis, \n! and moving the center of mass to (0,0,0) \n! for both structures, both sets of points should\n! have the same set of coordinates, and a comparison routine\n! should find that for every point in structure 1, there is\n! a point with equal coordinates in structure 2.\n!------------------------------------------------------------------\n\nprogram abcd\nuse global_module\nuse auxilary_subroutines\nimplicit none\n\nreal(kind=8), allocatable, dimension(:,:) :: matrixa, matrixb\nreal(kind=8), allocatable, dimension(:) :: mass\ninteger :: i, j, n, test_variable\n\nn = 20\nallocate( matrixa(n,3), matrixb(n,3), mass(n) )\n\n! The points are hydrogen atoms (needed for some of the\n! subrutines that are called). The same mass array is used for matrixa\n! and matrixb\ndo i = 1, n\n mass(i) = 1.0\nend do\n\n! Define the coordinates of points on the grid. You can see the shape\n! when the files are printed. It's kinda like an L:\ndo i = 1, 10\n matrixa(i,1) = i\n matrixa(i,2) = 0\n matrixa(i,3) = 0\nend do\n\ndo i = 1, 5\n matrixa(10+i,1) = i\n matrixa(10+i,2) = 1\n matrixa(10+i,3) = 0\nend do\n\ndo i = 1, 5\n matrixa(15+i,1) = 1\n matrixa(15+i,2) = i\n matrixa(15+i,3) = 0\nend do\n\n! Print the .xyz file of these \"hydrogen\" points on the grid:\nopen(unit=1, file='file1-1.xyz', action='write', status='replace')\nwrite(1,'(A2)') '20'\nwrite(1,'(A4)') 'abcd'\ndo i = 1, 20\n write(1,'(A19,3F11.7)') ' H ', (matrixa(i,j), j = 1, 3)\nend do\nclose(1)\n\n! Move them so that the main rotation axis is aligned with the\n! z-axis axis and the center of mass is at (0,0,0):\ncall center_and_main_inertia_vector (mass,n,matrixa)\n\n! And print the new coordinates:\nopen(unit=2, file='file1-2.xyz', action='write', status='replace')\nwrite(2,'(A2)') '20'\nwrite(2,'(A4)') 'abcd'\ndo i = 1, 20\n write(2,'(A19,3F11.7)') ' H ', (matrixa(i,j), j = 1, 3)\nend do\n\nclose(2)\n\n! Now, make another set of hydrogen atoms of the same shape, but\n! rotated about itself:\ndo i = 1, 10\n matrixb(i,1) = i\n matrixb(i,2) = 0\n matrixb(i,3) = 0\nend do\n\ndo i = 1, 5\n matrixb(10+i,1) = i\n matrixb(10+i,2) = -1\n matrixb(10+i,3) = 0\nend do\n\ndo i = 1, 5\n matrixb(15+i,1) = 1\n matrixb(15+i,2) = -i\n matrixb(15+i,3) = 0\nend do\n\n! And write them to a file:\nopen(unit=3, file='file2-1.xyz', action='write', status='replace')\nwrite(3,'(A2)') '20'\nwrite(3,'(A4)') 'abcd'\ndo i = 1, 20\n write(3,'(A19,3F11.7)') ' H ', (matrixb(i,j), j = 1, 3)\nend do\nclose(3)\n\n! And move them so that the center of mass is at (0,0,0)\n! and the main rotation axis is aligned with the z-axis:\ncall center_and_main_inertia_vector (mass,n,matrixb)\n\n! And write the new, translated coordinates to a file:\nopen(unit=4, file='file2-2.xyz', action='write', status='replace')\nwrite(4,'(A2)') '20'\nwrite(4,'(A4)') 'abcd'\ndo i = 1, 20\n write(4,'(A19,3F11.7)') ' H ', (matrixb(i,j), j = 1, 3)\nend do\n\nclose(4)\n\n! and now, compare matrixa(file1-2.xyz) and matrixb(file2-2.xyz):\ncall compare(matrixa,matrixb,n,test_variable)\n\nend program abcd\n", "meta": {"hexsha": "734ff8d4fc667a0420a13a9a1c91a8a0a6617c5b", "size": 3422, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "test_compare_procedure/test1/main.f95", "max_stars_repo_name": "ElenaKusevska/coordinates_on_a_grid", "max_stars_repo_head_hexsha": "6605c76d9c6561fee6eaaa844fb954f7784f623c", "max_stars_repo_licenses": ["MIT"], "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_compare_procedure/test1/main.f95", "max_issues_repo_name": "ElenaKusevska/coordinates_on_a_grid", "max_issues_repo_head_hexsha": "6605c76d9c6561fee6eaaa844fb954f7784f623c", "max_issues_repo_licenses": ["MIT"], "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_compare_procedure/test1/main.f95", "max_forks_repo_name": "ElenaKusevska/coordinates_on_a_grid", "max_forks_repo_head_hexsha": "6605c76d9c6561fee6eaaa844fb954f7784f623c", "max_forks_repo_licenses": ["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.1587301587, "max_line_length": 74, "alphanum_fraction": 0.6227352425, "num_tokens": 1181, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093946927838, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6919426186958836}} {"text": " subroutine ZQUO(CNUM,CDENOM,CQUOT)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nC>> 1995-10-30 ZQUO Krogh Fixed so M77CON can get S.P. for C conv.\nC>> 1987-12-07 ZQUO Lawson Initial code.\nc--Z replaces \"?\": ?QUO\nC\nC Computes the quotient of two double precision complex numbers.\nC Computes Z = U / V where the data is given as\nC CNUM(1) = Real part of U\nC CNUM(2) = Imaginary part of U\nC CDENOM(1) = Real part of V\nC CDENOM(2) = Imaginary part of V\nC Result returned as\nC CQUOT(1) = Real part of Z\nC CQUOT(2) = Imaginary part of Z\nC\nc If CDENOM = (0,0) this subr will divide by zero. We assume this\nc will activate a system error stop.\nC C.L.Lawson & S.Chan, JPL, June 3,1986. 2/17/87.\nC ------------------------------------------------------------------\nC\n double precision CNUM(2),CDENOM(2),CQUOT(2)\n double precision A1,B1,C1,D1,DENOM, ONE\n parameter(ONE = 1.0D0)\nC\n if(abs(CDENOM(1)) .gt. abs(CDENOM(2))) then\n A1 = CNUM(1)/CDENOM(1)\n B1 = CNUM(2)/CDENOM(1)\n D1 = CDENOM(2)/CDENOM(1)\n DENOM = ONE + D1*D1\n CQUOT(1) = (A1 + B1*D1) / DENOM\n CQUOT(2) = (B1 - A1*D1) / DENOM\n else\n A1 = CNUM(1)/CDENOM(2)\n B1 = CNUM(2)/CDENOM(2)\n C1 = CDENOM(1)/CDENOM(2)\n DENOM = ONE + C1*C1\n CQUOT(1) = (A1*C1 + B1) / DENOM\n CQUOT(2) = (B1*C1 - A1) / DENOM\n end if\n return\n end\n", "meta": {"hexsha": "1fb4b8aa0868d6d1f13de8cca08c5fa19d2aec64", "size": 1589, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/zquo.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/zquo.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/zquo.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 35.3111111111, "max_line_length": 72, "alphanum_fraction": 0.5550660793, "num_tokens": 585, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.7745833841649232, "lm_q1q2_score": 0.6919426184476954}} {"text": "*DECK CASIN\n COMPLEX FUNCTION CASIN (ZINP)\nC***BEGIN PROLOGUE CASIN\nC***PURPOSE Compute the complex arc sine.\nC***LIBRARY SLATEC (FNLIB)\nC***CATEGORY C4A\nC***TYPE COMPLEX (CASIN-C)\nC***KEYWORDS ARC SINE, ELEMENTARY FUNCTIONS, FNLIB, TRIGONOMETRIC\nC***AUTHOR Fullerton, W., (LANL)\nC***DESCRIPTION\nC\nC CASIN(ZINP) calculates the complex trigonometric arc sine of ZINP.\nC The result is in units of radians, and the real part is in the first\nC or fourth quadrant.\nC\nC***REFERENCES (NONE)\nC***ROUTINES CALLED R1MACH\nC***REVISION HISTORY (YYMMDD)\nC 770701 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890531 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC***END PROLOGUE CASIN\n COMPLEX ZINP, Z, Z2, SQZP1, CI\n LOGICAL FIRST\n SAVE PI2, PI, CI, NTERMS, RMIN, FIRST\n DATA PI2 /1.5707963267 9489661923E0/\n DATA PI /3.1415926535 8979324E0/\n DATA CI /(0.,1.)/\n DATA FIRST /.TRUE./\nC***FIRST EXECUTABLE STATEMENT CASIN\n IF (FIRST) THEN\nC NTERMS = LOG(EPS)/LOG(RMAX) WHERE RMAX = 0.1\n NTERMS = -0.4343*LOG(R1MACH(3))\n RMIN = SQRT (6.0*R1MACH(3))\n ENDIF\n FIRST = .FALSE.\nC\n Z = ZINP\n R = ABS (Z)\n IF (R.GT.0.1) GO TO 30\nC\n CASIN = Z\n IF (R.LT.RMIN) RETURN\nC\n CASIN = (0.0, 0.0)\n Z2 = Z*Z\n DO 20 I=1,NTERMS\n TWOI = 2*(NTERMS-I) + 1\n CASIN = 1.0/TWOI + TWOI*CASIN*Z2/(TWOI+1.0)\n 20 CONTINUE\n CASIN = Z*CASIN\n RETURN\nC\n 30 IF (REAL(ZINP).LT.0.0) Z = -ZINP\nC\n SQZP1 = SQRT (Z+1.0)\n IF (AIMAG(SQZP1).LT.0.) SQZP1 = -SQZP1\n CASIN = PI2 - CI * LOG (Z + SQZP1*SQRT(Z-1.0))\nC\n IF (REAL(CASIN).GT.PI2) CASIN = PI - CASIN\n IF (REAL(CASIN).LE.(-PI2)) CASIN = -PI - CASIN\n IF (REAL(ZINP).LT.0.) CASIN = -CASIN\nC\n RETURN\n END\n", "meta": {"hexsha": "53cdce804f40af8db17a0820686cad61811329d9", "size": 1879, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/casin.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/casin.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/casin.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.0447761194, "max_line_length": 70, "alphanum_fraction": 0.6072378925, "num_tokens": 761, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093946927837, "lm_q2_score": 0.7745833737577158, "lm_q1q2_score": 0.6919426047505993}} {"text": "module spharmt\n\n!\n! fortran95 spherical harmonic module.\n! For gaussian grids and triangular truncation only.\n!\n! version 1.1 9/30/2003 (second version - now all fortran using fft99)\n! Jeff Whitaker \n\n! Modified by Sam Goldberg to add subroutines that perform SH transforms using\n! 2-dimensional matrices of coefficients (U(l,m)) instead of 1-dimensional vectors\n! - spat2spec, spec2spat\n\n!-----------------------------------------------------------------------------\n! to use this module, put \"use spharmt\" at top of main program\n! (just after program statement).\n! to initialize arrays needed to compute spherical harmonic transforms\n! at T(ntrunc) resolution on a nlon x nlat gaussian grid, \n! do something like this:\n! \n! type (sphere) :: sphere_dat\n! parameter (nlon=192,nlat=nlon/2)\n! parameter (ntrunc=62)\n! rsphere = 6.3712e6\n! call spharmt_init(sphere_dat,nlon,nlat,ntrunc,re)\n \n! derived data type \"sphere\" contains stuff needed for legendre\n! transforms and fft. By creating multiple instances of sphere\n! data types, spherical harmonic transforms on multiple grids can\n! be done easily in the same code.\n!\n! Components of sphere derived data type are:\n!\n! NLON (integer) - number of longitudes\n! NLAT (integer) - number of latitudes\n! NTRUNC (integer) - triangular truncation limit\n! RE (real) - radius of sphere (m).\n! PNM (real pointer array dimension ((ntrunc+1)*(ntrunc+2)/2, nlat) - \n! Associated legendre polynomials.\n! HNM (real pointer array, same size as pnm) = -(1 - x*x) * d(pnm)/dx \n! at x = sin(latitude).\n! GAULATS (real pointer array dimension nlat) - sin(gaussian latitudes).\n! WEIGHTS (real pointer array dimension nlat) - gaussian weights.\n! GWRC (real pointer array dimension nlat) - gaussian weights divided by \n! rsphere*(1-x**2).\n! INDXM (integer pointer array dimension (ntrunc+1)*(ntrunc+2)/2) - value of\n! zonal wavenumber m corresponding to spectral array index \n! nm=1,(ntrunc+1)*(ntrunc+2)/2)\n! INDXN (integer pointer array same size as indxm) - value of\n! spherical harmonic degree n corresponding to spectral array index \n! nm=1,(ntrunc+1)*(ntrunc+2)/2)\n! LAP (real pointer array dimension (ntrunc+1)*(ntrunc+2)/2) - \n! lapacian operator in spectral space = \n! -n*(n+1)/rsphere**2, where n is degree of spherical harmonic.\n! ILAP (real pointer array same size as lap) - inverse laplacian operator in \n! spectral space.\n! TRIGS, IFAX: arrays needed by Temperton FFT.\n! ISINITIALIZED (logical) - true if derived data type has been\n! initialized by call to spharm_init, false if not initialized.\n! \n\n! public routines:\n!\n! SPHARMT_INIT(sphere_dat,nlon,nlat,ntrunc,re): initialize a sphere object\n! (sphere_dat - derived data type \"sphere\"). inputs are nlon (number of unique\n! longitudes), nlat (number of gaussian latitudes), and re \n! (radius of sphere in m). Must be called before anything else.\n!\n! SPHARMT_DESTROY(sphere_dat): cleans up pointer arrays allocated by \n! spharmt_init.\n!\n! SPHARM(sphere_dat, ugrid, anm, idir): spherical harmonic transform \n! (forward, i.e. grid to spectral, for idir=1 and backward for idir=-1). \n! Arguments are sphere derived data type (sphere_dat), gridded data (ugrid),\n! complex spectral coefficients (anm), and flag specifying direction of \n! transform (idir). See \"Import Details\" below for information \n! about indexing of grid and spectral arrays.\n\n! GAULW(gaulats,weights): compute sin(gaussian latitudes) and gaussian\n! weights. Number of latitudes determined by size of input arrays.\n\n! LEGEND(x,pnm,hnm): compute associated legendre functions (pnm) and\n! their derivates hnm = (X**2-1)*D(PNM)/DX at x = sin(latitude). The\n! input arrays pnm and hnm should have dimension (ntrunc+1)*(ntrunc+2)/2, \n! where ntrunc is triangular truncation limit (see Import Details below\n! for a description of the spectral indexing).\n\n! GETUV(sphere_dat,vrtnm,divnm,ug,vg): get U,V (u*cos(lat),v*cos(lat) on grid) \n! from spectral coefficients of vorticity and divergence. \n! Input: sphere_dat, spectral coeffs. of vort and div (vrtnm,divnm).\n! Output: gridded U,V (ug,vg).\n!\n! GETVRTDIV(sphere_dat,vrtnm,divnm,ug,vg): get spectral coefficients of \n! vorticity and divergence (vrtnm,divnm) from gridded U,V (ug,vg).\n!\n! COSGRAD(sphere_dat,chinm,uchig,vchig): compute cos(lat)*vector gradient.\n! Inputs: sphere_dat, spectral coefficient array (chinm).\n! Outputs: longitudinal and latitudinal components of gradient on the gaussian\n! grid (uchig,vchig).\n\n! SPECSMOOTH(sphere_dat,datagrid,smooth): isotropic spectral smoothing.\n! Inputs: sphere_dat, smooth(ntrunc+1) (smoothing factor as a function\n! of spherical harmonic degree), datagrid (gridded data to be smoothed).\n! Outputs: datagrid (smoothed gridded data).\n!\n! SUMNM(sphere_dat,am,bm,anm,isign1,isign2): \n! given the arrays of fourier coeffs, am and bm,\n! compute the complex spherical harmonic coeffs (anm) of: \n! isign1*( (1./rsphere*(1.-x**2))*d(ag)/d(lon) + (isign2/rsphere)*d(bg)/dx )\n! where ag and bg are the grid pt counterparts of am,bm,\n! isign1,isign2 are +1 or -1, rsphere is radius of sphere, x=sin(lat))\n! am,bm can be computed from gridded data (ag,bg) using RFFT.\n!\n! RFFT(sphere_dat, data, coeff, idir): computes fourier harmonics in zonal\n! direction of a gridded array. idir=+1 for forward (grid\n! to fourier) and -1 for backward (fourier to grid) transform.\n! data (nlon,nlat) contains gridded data, coeff (ntrunc+1,nlat) contains\n! complex zonal fourier harmonics.\n! \n! Important Details:\n!\n! The gridded data is assumed to be oriented such that i=1 is the Greenwich\n! meridian and j=1 is the northernmost point. Grid indices increase eastward \n! and southward. The grid increment in longitude is 2*pi/nlon radians.\n! For example nlon = 72 for a five degree grid. nlon must be greater than or\n! equal to 4. The efficiency of the computation is improved when nlon is a\n! product of small prime numbers.\n\n! The spectral data is assumed to be in a complex array of dimension\n! (NTRUNC+1)*(NTRUNC+2)/2. NTRUNC is the triangular truncation limit (NTRUNC=42\n! for T42). NTRUNC must be <= nlon/2. Coefficients are ordered so that first\n! (nm=1) is m=0,n=0, second is m=0,n=1, nm=mtrunc is m=0,n=mtrunc, nm=mtrunc+1 \n! is m=1,n=1, etc. In Fortran90 syntax, values of m (degree) and n (order)\n! corresponding as a function of the index nm are:\n\n! indxm = (/((m,n=m,mtrunc),m=0,mtrunc)/)\n! indxn = (/((n,n=m,mtrunc),m=0,mtrunc)/)\n\n! Conversely, the index nm as a function of m and n is:\n\n! nm = sum((/(i,i=mtrunc+1,mtrunc-m+2,-1)/))+n-m+1\n\n! The associated legendre polynomials are normalized so that the integral \n! (pbar(n,m,theta)**2)*sin(theta) on the interval theta=0 to theta=pi is 1, \n! where: pbar(m,n,theta) = sqrt((2*n+1)*factorial(n-m)/(2*factorial(n+m)))\n! *sin(theta)**m/(2**n*factorial(n)) times the (n+m)th derivative of \n! (x**2-1)**n with respect to x=cos(theta).\n\n! note: theta = 0.5*pi - phi, where phi is latitude and theta is colatitude,\n! Therefore, cos(theta) = sin(phi) and sin(theta) = cos(phi).\n\n! Note that pbar(0,0,theta)=sqrt(2)/2, \n! and pbar(1,0,theta)=0.5*sqrt(6.)*sin(lat).\n!----------------------------------------------------------------------------\n\n! explicit typing\n\n implicit none\n\n! everything private to module, unless otherwise specified.\n\n private\n public :: sphere,spharmt_init,spharmt_destroy,spharm,rfft,cosgrad,&\n specsmooth,getuv,getvrtdiv,sumnm,gaulw,legend,spat2spec,spec2spat\n \n type sphere\n\n! rsphere is radius of sphere in m.\n real :: rsphere = 0.\n\n! nlons is number of longitudes (not including cyclic point).\n integer :: nlons = 0\n\n! nlats is number of gaussian latitudes.\n integer :: nlats = 0\n\n! for fft.\n real, dimension(:), pointer :: trigs\n integer, dimension(:), pointer :: ifax\n\n! ntrunc is triangular truncation limit (e.g. 42 for T42 truncation)\n integer :: ntrunc = 0\n\n! gaulats is sin(gaussian lats), weights are gaussian weights,\n! gwrc is gaussian weights divided by re*cos(lat)**2, lap is \n! the laplacian operatore -n*(n+1)/re**2 (where n is the degree \n! of the spherical harmonic),\n! ilap is the inverse laplacian (1/lap, set to zero for n=0).\n real, dimension(:), pointer :: gaulats, weights, gwrc, lap, ilap\n\n! pnm is associated legendre polynomials, hnm is -(1-x**2)d(pnm)/dx,\n! where x = gaulats.\n real, dimension(:,:), pointer :: pnm, hnm\n\n! indxm is zonal wavenumber index, indxn is spherical harmonic degree index.\n integer, dimension(:), pointer :: indxm, indxn\n logical :: isinitialized=.FALSE.\n\n end type sphere\n\n contains\n\n subroutine spharmt_init(sphere_dat,nlon,nlat,ntrunc,re)\n\n! initialize a sphere object.\n\n integer, intent(in) :: nlon,nlat,ntrunc\n real, intent(in) :: re\n type (sphere), intent(inout) :: sphere_dat\n real, dimension(:), allocatable :: pnm_tmp,hnm_tmp\n double precision, dimension(:), allocatable :: gaulats_tmp,weights_tmp\n integer :: nmdim,m,n,j\n\n sphere_dat%nlons = nlon\n sphere_dat%nlats = nlat\n sphere_dat%ntrunc = ntrunc\n sphere_dat%rsphere = re\n\n nmdim = (ntrunc+1)*(ntrunc+2)/2\n\n allocate(gaulats_tmp(nlat))\n allocate(weights_tmp(nlat))\n\n call gaulw(gaulats_tmp,weights_tmp)\n\n allocate(sphere_dat%gwrc(nlat))\n sphere_dat%gwrc = weights_tmp/(dble(re)*(1.d0-gaulats_tmp**2))\n allocate(sphere_dat%gaulats(nlat))\n allocate(sphere_dat%weights(nlat))\n sphere_dat%gaulats = gaulats_tmp\n sphere_dat%weights = weights_tmp\n deallocate(weights_tmp)\n\n allocate(sphere_dat%indxm(nmdim))\n allocate(sphere_dat%indxn(nmdim))\n allocate(sphere_dat%lap(nmdim))\n allocate(sphere_dat%ilap(nmdim))\n\n sphere_dat%indxm = (/((m,n=m,ntrunc),m=0,ntrunc)/)\n sphere_dat%indxn = (/((n,n=m,ntrunc),m=0,ntrunc)/)\n sphere_dat%lap(:)=-real(sphere_dat%indxn(:))*real(sphere_dat%indxn(:)+1)/re**2\n sphere_dat%ilap(1) = 0.\n sphere_dat%ilap(2:nmdim) = 1./sphere_dat%lap(2:nmdim)\n\n allocate(sphere_dat%pnm(nmdim,nlat))\n allocate(sphere_dat%hnm(nmdim,nlat))\n allocate(pnm_tmp(nmdim))\n allocate(hnm_tmp(nmdim))\n do j=1,nlat\n call legend(gaulats_tmp(j),pnm_tmp,hnm_tmp)\n sphere_dat%pnm(:,j) = pnm_tmp(:)\n sphere_dat%hnm(:,j) = hnm_tmp(:)\n enddo\n deallocate(gaulats_tmp)\n deallocate(pnm_tmp)\n deallocate(hnm_tmp)\n\n allocate(sphere_dat%trigs((3*nlon/2)+1))\n allocate(sphere_dat%ifax(13))\n call set99(sphere_dat%trigs,sphere_dat%ifax,nlon)\n\n sphere_dat%isinitialized = .TRUE.\n end subroutine spharmt_init\n\n subroutine spharmt_destroy(sphere_dat)\n\n! deallocate pointers in sphere object.\n\n type (sphere), intent(inout) :: sphere_dat\n\n if (.not. sphere_dat%isinitialized) return\n\n deallocate(sphere_dat%gaulats)\n deallocate(sphere_dat%weights)\n deallocate(sphere_dat%gwrc)\n deallocate(sphere_dat%pnm)\n deallocate(sphere_dat%hnm)\n deallocate(sphere_dat%indxm)\n deallocate(sphere_dat%indxn)\n deallocate(sphere_dat%lap)\n deallocate(sphere_dat%ilap)\n deallocate(sphere_dat%trigs)\n deallocate(sphere_dat%ifax)\n\n end subroutine spharmt_destroy\n\n subroutine gaulw(sinlats, wts)\n\n! compute sin of gaussian latitudes and gaussian weights.\n! uses the iterative method presented in Numerical Recipes.\n\n double precision, intent (inout), dimension(:) :: sinlats, wts\n\n integer :: itermax\n integer :: i, iter, j, nlat, nprec\n double precision :: pi, pp, p1, p2, p3, z, z1, converg, ten\n\n\n ten = 10.d0\n converg = ten * EPSILON(ten)\n\n nprec = precision(converg)\n \n converg = .1**nprec\n\n itermax = 10\n\n pi = 4.0*ATAN(1.0)\n\n nlat = size(sinlats)\n if (size(sinlats) .ne. size(wts)) then\n print *, 'sinlats and wts must be same size in gaulw!'\n stop\n end if\n\n do i=1,nlat\n z = cos(pi*(i - 0.25)/(nlat + 0.5))\n do iter=1,itermax\n p1 = 1.0\n p2 = 0.0\n do j=1,nlat\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 = nlat*(z*p1 - p2)/(z*z - 1.0E+00)\n z1 = z\n z = z1 - p1/pp\n if(ABS(z - z1) .LT. converg) go to 10\n end do\n print *, 'abscissas failed to converge in itermax iterations'\n print *, 'stopping in gaulw!'\n stop\n\n10 continue\n\n sinlats (i) = z\n wts (i) = 2.0/((1.0 - z*z)*pp*pp)\n\n end do\n\n return\n end subroutine gaulw\n\n SUBROUTINE LEGEND(X,PMN,HMN)\n!\n! THIS SUBROUTINE COMPUTES ASSOCIATED LEGENDRE \n! FUNCTIONS, PMN, AND THE DERIVATIVE QUANTITY \n! HMN = -(1 - X*X) * D(PMN)/DX AT X = COS( COLATITUDE ) \n! GIVEN SOME COLATITUDE IN THE DOMAIN.\n!\n! ACCURACY: \n!\n! THE RECURSION RELATION EMPLOYED IS LESS ACCURATE\n! NEAR THE POLES FOR M + N .GE. ROUGHLY 75 BECAUSE THE RECURSION\n! INVOLVES THE DIFFERENCE OF NEARLY EQUAL NUMBERS, SO\n! THE ASSOCIATED LEGENDRE FUNCTIONS ARE COMPUTED USING DOUBLE\n! PRECISION ACCUMULATORS. \n! SEE BELOUSOV, TABLES OF NORMALIZED ASSOCIATED LEGENDRE \n! POLYNOMIALS, C. 1962, FOR INFORMATION ON THE ACCURATE \n! COMPUTATION OF ASSOCIATED LEGENDRE FUNCTIONS.\n \n real, dimension(:), intent(inout) :: PMN, HMN\n double precision, intent(in) :: x\n integer :: m,n,nm,i,nmax,np1,nmstrt,j,nmdim,ntrunc\n double precision :: A, B, PROD, SINSQ, &\n eps,epsnmp1,EPSPMN, PMNJ, PMNJM1, PMNJM2\n \n \n!**** SET PARAMETERS FOR ENTRY INTO THE RECURSIVE FORMULAE. \n \n \n SINSQ = 1.D0 - X * X\n \n A = 1.D0\n B = 0.D0\n PROD = 1.D0\n \n nmdim = size(pmn)\n ntrunc = nint((-1.+sqrt(1+8*float(nmdim)))/2.)-1\n if (size(pmn) .ne. size(hmn)) then\n print *, 'pnm and hnm must be same size in subroutine legend!'\n stop\n end if\n \n!**** LOOP FOR THE 'M' INDEX. \n \n NMSTRT = 0\n DO I = 1, NTRUNC+1\n \n M = (I - 1)\n NMAX = NTRUNC+1-M\n \n! WHEN M=0 (I=1), STANDARD LEGENDRE POLYNOMIALS ARE\n! GENERATED. \n \n IF (M .NE. 0) THEN\n A = A + 2.D0\n B = B + 2.D0\n PROD = PROD * SINSQ * A / B \n END IF\n \n!**** GENERATE PMN AND HMN FOR J = 1 AND 2.\n \n PMNJM2 = SQRT(0.5D0 * PROD)\n NM = NMSTRT + 1\n PMN(NM) = PMNJM2\n \n PMNJM1 = SQRT( DBLE(2 * M + 3) ) * X * PMNJM2\n IF (NM .NE. NMDIM) PMN(NM+1) = PMNJM1\n \n NP1 = M + 1 \n EPSNMP1 = SQRT( DBLE(NP1*NP1 - M*M) / DBLE(4*NP1*NP1 - 1) )\n EPSPMN = X * PMNJM1 - EPSNMP1 * PMNJM2 \n \n HMN(NM) = DBLE(M) * EPSNMP1 * PMNJM1 \n IF (NM .NE. NMDIM) &\n HMN(NM+1) = DBLE(M+1) * EPSPMN - &\n DBLE(M+2) * EPSNMP1 * PMNJM2\n \n!**** LOOP FOR THE 'N' INDEX.\n! NOW APPLY THE RECURSION FORMULAE FOR J .GE. 3.\n \n DO J = 3, NMAX \n N = M + J - 1\n NM = NMSTRT + J\n EPS = SQRT( DBLE(N*N - M*M) / DBLE(4*N*N - 1) )\n PMNJ = EPSPMN / EPS \n PMN(NM) = PMNJ\n \n! COMPUTE EPS * PMN FOR J+1.\n \n EPSPMN = X * PMNJ - EPS * PMNJM1 \n \n! COMPUTE THE DERIVATIVE.\n \n HMN(NM) = DBLE(N) * EPSPMN - &\n DBLE(N+1) * EPS * PMNJM1 \n \n PMNJM2 = PMNJM1 \n PMNJM1 = PMNJ\n ENDDO \n NMSTRT = NMSTRT + NMAX\n ENDDO\n\n END SUBROUTINE LEGEND\n\n subroutine rfft(sphere_dat, data, coeff, idir)\n\n! real multiple fft (uses temperton fft991)\n\n type (sphere), intent(in) :: sphere_dat\n \n real, dimension(sphere_dat%nlons,sphere_dat%nlats), intent(inout) :: data\n real, dimension(sphere_dat%nlats*(sphere_dat%nlons+2)) :: wrk1\n real, dimension(sphere_dat%nlats*(sphere_dat%nlons+1)) :: wrk2\n complex, dimension(sphere_dat%ntrunc+1,sphere_dat%nlats), intent(inout) :: coeff\n integer :: nlons,nlats,ntrunc,mwaves,i,j,m,n\n integer, intent(in) :: idir\n\n if (.not. sphere_dat%isinitialized) then\n print *, 'uninitialized sphere object in rfft!'\n stop\n end if\n\n\n nlons = sphere_dat%nlons\n nlats = sphere_dat%nlats\n ntrunc = sphere_dat%ntrunc\n if (ntrunc .gt. nlons/2) then\n print *, 'ntrunc must be less than or equal to nlons in rfft'\n stop\n end if\n\n mwaves = ntrunc+1\n\n!==> forward transform.\n\n if (idir .eq. +1) then\n \n!==> copy the data into the work array.\n! transforms are computed pairwise using a complex fft.\n \n n = 0\n wrk1 = 0.\n do j=1,nlats\n do i=1,nlons+2 \n n = n + 1\n wrk1(n) = 0.0\n if (i .le. nlons) then\n wrk1(n) = data(i,j)\n end if\n enddo\n enddo\n \n call fft991(wrk1,wrk2,sphere_dat%trigs,sphere_dat%ifax,1,nlons+2,nlons,nlats,-1)\n \n n = -1\n do j=1,nlats\n do m=1,(nlons/2)+1\n n = n + 2\n if (m .le. mwaves) then\n coeff(m,j) = cmplx(wrk1(n),wrk1(n+1)) \n end if\n enddo\n enddo\n\n!==> inverse transform.\n\n else if (idir .eq. -1) then\n\n wrk1 = 0.\n n = -1\n do j=1,nlats\n do m=1,(nlons/2)+1\n n = n + 2\n if (m .le. mwaves) then\n wrk1(n) = real(coeff(m,j))\n wrk1(n+1) = aimag(coeff(m,j))\n end if\n enddo\n enddo\n \n call fft991(wrk1,wrk2,sphere_dat%trigs,sphere_dat%ifax,1,nlons+2,nlons,nlats,1)\n \n n = 0\n do j=1,nlats\n do i=1,nlons+2 \n n = n + 1\n if (i .le. nlons) then\n data(i,j) = wrk1(n)\n end if\n enddo\n enddo\n\n else\n write(6,*) ' idir must be +1 or -1 in RFFT!'\n write(6,*) ' execution terminated.'\n stop\n end if\n\n end subroutine rfft\n\n subroutine spharm(sphere_dat, ugrid, anm, idir)\n\n! spherical harmonic transform\n\n type (sphere), intent(in) :: sphere_dat\n \n real, dimension(sphere_dat%nlons,sphere_dat%nlats), intent(inout) :: ugrid\n complex, dimension((sphere_dat%ntrunc+1)*(sphere_dat%ntrunc+2)/2), intent(inout) :: anm\n complex, dimension(sphere_dat%ntrunc+1,sphere_dat%nlats) :: am\n integer :: nlats,ntrunc,mwaves,nmstrt,nm,m,n,j\n integer, intent(in) :: idir\n\n if (.not. sphere_dat%isinitialized) then\n print *, 'uninitialized sphere object in spharm!'\n stop\n end if\n\n nlats = sphere_dat%nlats\n ntrunc = sphere_dat%ntrunc\n mwaves = ntrunc+1\n\n IF (IDIR .eq. +1) then\n \n!==> GRID SPACE TO SPECTRAL SPACE TRANSFORMATION \n! FIRST, INITIALIZE ARRAY. \n \n anm = 0.\n \n!==> perform ffts on each latitude.\n\n call rfft(sphere_dat, ugrid, am, 1)\n \n!==> SUM OVER ALL GAUSSIAN LATITUDES FOR EACH MODE AND EACH WAVE TO\n! OBTAIN THE TRANSFORMED VARIABLE IN SPECTRAL SPACE.\n \n do j=1,nlats\n NMSTRT = 0\n DO m = 1, mwaves\n DO n = 1, mwaves-m+1\n NM = NMSTRT + n\n anm(NM)=anm(NM)+sphere_dat%pnm(nm,j)*sphere_dat%weights(j)*am(m,j)\n enddo\n nmstrt = nmstrt + mwaves-m+1\n enddo\n enddo\n\n!==> SPECTRAL SPACE TO GRID SPACE TRANSFORMATION.\n \n else if (idir .eq. -1) then\n \n DO J = 1, NLATS \n \n!==> INVERSE LEGENDRE TRANSFORM TO GET VALUES OF THE ZONAL FOURIER\n! TRANSFORM AT LATITUDE j.\n \n!==> SUM THE VARIOUS MERIDIONAL MODES TO BUILD THE FOURIER SERIES\n! COEFFICIENT FOR ZONAL WAVENUMBER M=I-1 AT the GIVEN LATITUDE. \n \n NMSTRT = 0\n do m = 1, MWAVES\n am(m,j) = cmplx(0., 0.)\n DO n = 1, mwaves-m+1\n NM = NMSTRT + n\n am(m,j) = am(m,j) + anm(NM) * sphere_dat%pnm(NM,j) \n enddo\n NMSTRT = NMSTRT + mwaves-m+1\n enddo\n \n ENDDO\n\n!==> FOURIER TRANSFORM TO COMPUTE THE VALUES OF THE VARIABLE IN GRID \n! SPACE at THE J-TH LATITUDE. \n\n call rfft(sphere_dat, ugrid, am, -1)\n \n else\n print *, 'error in spharm: idir must be -1 or +1!'\n print *, 'execution terminated in subroutine spharm'\n end if\n\n end subroutine spharm\n\n subroutine getuv(sphere_dat,vrtnm,divnm,ug,vg)\n\n! compute U,V (winds times cos(lat)) from vrtnm,divnm\n! (spectral coeffs of vorticity and divergence).\n\n type (sphere), intent(in) :: sphere_dat\n real, dimension(sphere_dat%nlons,sphere_dat%nlats), intent(out) :: ug,vg\n complex, dimension((sphere_dat%ntrunc+1)*(sphere_dat%ntrunc+2)/2), intent(in) :: vrtnm,divnm\n complex, dimension(sphere_dat%ntrunc+1,sphere_dat%nlats) :: um,vm\n integer :: nlats,ntrunc,mwaves,m,j,n,nm,nmstrt\n real :: rm\n\n if (.not. sphere_dat%isinitialized) then\n print *, 'uninitialized sphere object in getuv!'\n stop\n end if\n\n\n nlats = sphere_dat%nlats\n ntrunc = sphere_dat%ntrunc\n mwaves = ntrunc+1\n\n do j=1,nlats\n nmstrt = 0\n do m=1,mwaves\n rm = m-1\n um(m,j) = cmplx(0.,0.)\n vm(m,j) = cmplx(0.,0.)\n do n=1,mwaves-m+1\n nm = nmstrt + n\n um(m,j) = um(m,j) + (sphere_dat%ilap(nm)/sphere_dat%rsphere)*( &\n cmplx(0.,rm)*divnm(nm)*sphere_dat%pnm(nm,j) + &\n vrtnm(nm)*sphere_dat%hnm(nm,j) )\n vm(m,j) = vm(m,j) + (sphere_dat%ilap(nm)/sphere_dat%rsphere)*( &\n cmplx(0.,rm)*vrtnm(nm)*sphere_dat%pnm(nm,j) - &\n divnm(nm)*sphere_dat%hnm(nm,j) )\n enddo\n nmstrt = nmstrt + mwaves-m+1\n enddo\n enddo\n\n call rfft(sphere_dat, ug, um, -1)\n call rfft(sphere_dat, vg, vm, -1)\n \n end subroutine getuv\n\n subroutine getvrtdiv(sphere_dat,vrtnm,divnm,ug,vg)\n\n! compute vrtnm,divnm (spectral coeffs of vorticity and\n! divergence) from U,V (winds time cos(lat)).\n\n type (sphere), intent(in) :: sphere_dat\n \n real, dimension(sphere_dat%nlons,sphere_dat%nlats), intent(inout) :: ug,vg\n complex, dimension((sphere_dat%ntrunc+1)*(sphere_dat%ntrunc+2)/2), intent(in) :: vrtnm,divnm\n complex, dimension(sphere_dat%ntrunc+1,sphere_dat%nlats) :: um,vm\n\n if (.not. sphere_dat%isinitialized) then\n print *, 'uninitialized sphere object in getvrtdiv!'\n stop\n end if\n\n call rfft(sphere_dat, ug, um, 1)\n call rfft(sphere_dat, vg, vm, 1)\n\n call sumnm(sphere_dat,um,vm,divnm,1,1)\n call sumnm(sphere_dat,vm,um,vrtnm,1,-1)\n \n end subroutine getvrtdiv\n\n subroutine sumnm(sphere_dat,am,bm,anm,isign1,isign2)\n!\n! given the arrays of fourier coeffs, am and bm,\n! compute the complex spherical harmonic coeffs of: \n!\n! isign1*( (1./re*(1.-x**2))*d(ag)/d(lon) + (isign2/re)*d(bg)/dx )\n!\n! where x = sin(lat), isign1 and isign2 are either +1 or -1,\n! ag and bg are the physical space values of am,bm and re\n! is the radius of the sphere.\n!\n! the result is returned in anm.\n!\n! for example on how to use this routine, see subroutine getvrtdiv.\n!\n!\n type (sphere), intent(in) :: sphere_dat\n \n integer, intent(in) :: isign1,isign2\n complex, dimension((sphere_dat%ntrunc+1)*(sphere_dat%ntrunc+2)/2) :: anm\n complex, dimension(sphere_dat%ntrunc+1,sphere_dat%nlats), intent(in) :: am,bm\n integer :: nlats,ntrunc,mwaves,j,m,n,nm,nmstrt\n real :: sign1,sign2,rm\n\n if (.not. sphere_dat%isinitialized) then\n print *, 'uninitialized sphere object in sumnm!'\n stop\n end if\n\n\n sign1 = float(isign1)\n sign2 = float(isign2)\n if (isign2 .ne. 1 .and. isign2 .ne. -1) then\n print *, ' isign2 must be +1 or -1 in sumnm!'\n print *, ' execution terminated in sumnm'\n end if\n if (isign1 .ne. 1 .and. isign1 .ne. -1) then\n print *, ' isign1 must be +1 or -1 in sumnm!'\n print *, ' execution terminated in sumnm'\n stop\n end if\n nlats = sphere_dat%nlats\n ntrunc = sphere_dat%ntrunc\n mwaves = ntrunc+1\n \n anm = 0.\n DO J=1,NLATS\n NMSTRT = 0 \n DO m = 1, MWAVES \n RM = M-1 \n DO n = 1, mwaves-m+1\n NM = NMSTRT + n\n aNM(NM) = aNM(NM) + sign1*sphere_dat%GWrC(j)*(CMPLX(0.,RM) &\n * sphere_dat%PNM(NM,J) * am(m,j) &\n + sign2 * sphere_dat%HNM(NM,J) * bm(m,j))\n enddo\n nmstrt = nmstrt + mwaves - m +1\n enddo\n enddo\n\n end subroutine sumnm\n\n subroutine cosgrad(sphere_dat,divnm,ug,vg)\n\n! compute coslat * gradient of spectral coefficients (divnm)\n! vector gradient returned on grid as (ug,vg)\n\n type (sphere), intent(in) :: sphere_dat\n \n real, dimension(sphere_dat%nlons,sphere_dat%nlats), intent(out) :: ug,vg\n complex, dimension((sphere_dat%ntrunc+1)*(sphere_dat%ntrunc+2)/2), intent(in) :: divnm\n complex, dimension(sphere_dat%ntrunc+1,sphere_dat%nlats) :: um,vm\n integer :: nlats,ntrunc,mwaves,j,m,n,nm,nmstrt\n real :: rm\n\n if (.not. sphere_dat%isinitialized) then\n print *, 'uninitialized sphere object in cosgrad!'\n stop\n end if\n\n\n nlats = sphere_dat%nlats\n ntrunc = sphere_dat%ntrunc\n mwaves = ntrunc+1\n \n do j=1,nlats\n nmstrt = 0\n do m=1,mwaves\n rm = (m-1)\n um(m,j) = cmplx(0.,0.)\n vm(m,j) = cmplx(0.,0.)\n do n=1,mwaves-m+1\n nm = nmstrt + n\n um(m,j) = um(m,j) + (1./sphere_dat%rsphere)* &\n cmplx(0.,rm)*divnm(nm)*sphere_dat%pnm(nm,j) \n vm(m,j) = vm(m,j) - (1./sphere_dat%rsphere)* &\n divnm(nm)*sphere_dat%hnm(nm,j) \n enddo\n nmstrt = nmstrt + mwaves - m +1\n enddo\n enddo\n\n call rfft(sphere_dat, ug, um, -1)\n call rfft(sphere_dat, vg, vm, -1)\n\n end subroutine cosgrad\n\n subroutine specsmooth(sphere_dat,datagrid,smooth)\n \n! isotropic spectral smoothing of datagrid.\n! input: smooth(sphere_dat%ntrunc+1) - smoothing factor as a\n! function of degree (sphere_dat%indxn).\n\n type (sphere), intent(in) :: sphere_dat\n real, dimension(sphere_dat%nlons,sphere_dat%nlats), intent(inout) :: datagrid\n real, dimension(sphere_dat%ntrunc+1), intent(in) :: smooth\n complex, dimension((sphere_dat%ntrunc+1)*(sphere_dat%ntrunc+2)/2) :: dataspec\n integer :: n,nm,nmdim\n\n if (.not. sphere_dat%isinitialized) then\n print *, 'uninitialized sphere object in specsmooth!'\n stop\n end if\n\n\n nmdim = (sphere_dat%ntrunc+1)*(sphere_dat%ntrunc+2)/2\n\n call spharm(sphere_dat, datagrid, dataspec, 1)\n\n do nm=1,nmdim\n n = sphere_dat%indxn(nm)\n dataspec(nm) = dataspec(nm)*smooth(n+1)\n enddo\n\n call spharm(sphere_dat, datagrid, dataspec, -1)\n\n end subroutine specsmooth\n\n subroutine fft99 (a,work,trigs,ifax,inc,jump,n,lot,isign) \n\n! purpose performs multiple fast fourier transforms. this package\n! will perform a number of simultaneous real/half-complex\n! periodic fourier transforms or corresponding inverse\n! transforms, i.e. given a set of real data vectors, the\n! package returns a set of 'half-complex' fourier\n! coefficient vectors, or vice versa. the length of the\n! transforms must be an even number greater than 4 that has\n! no other factors except possibly powers of 2, 3, and 5.\n! this is an all-fortran version of a optimized routine\n! fft99 written for xmp/ymps by dr. clive temperton of\n! ecmwf.\n!\n! the package fft99f contains several user-level routines:\n!\n! subroutine set99\n! an initialization routine that must be called once\n! before a sequence of calls to the fft routines\n! (provided that n is not changed).\n!\n! subroutines fft99 and fft991\n! two fft routines that return slightly different\n! arrangements of the data in gridpoint space.\n!\n! usage let n be of the form 2**p * 3**q * 5**r, where p .ge. 1,\n! q .ge. 0, and r .ge. 0. then a typical sequence of\n! calls to transform a given set of real vectors of length\n! n to a set of 'half-complex' fourier coefficient vectors\n! of length n is\n!\n! dimension ifax(13),trigs(3*n/2+1),a(m*(n+2)),\n! + work(m*(n+1))\n!\n! call set99 (trigs, ifax, n)\n! call fft99 (a,work,trigs,ifax,inc,jump,n,m,isign)\n!\n! see the individual write-ups for set99, fft99, and\n! fft991 below, for a detailed description of the\n! arguments.\n!\n! history the package was written by clive temperton at ecmwf in\n! november, 1978. it was modified, documented, and tested\n! for ncar by russ rew in september, 1980.\n!\n!-----------------------------------------------------------------------\n!\n! subroutine set99 (trigs, ifax, n)\n!\n! purpose a set-up routine for fft99 and fft991. it need only be\n! called once before a sequence of calls to the fft\n! routines (provided that n is not changed).\n!\n! argument ifax(13),trigs(3*n/2+1)\n! dimensions\n!\n! arguments\n!\n! on input trigs\n! a floating point array of dimension 3*n/2 if n/2 is\n! even, or 3*n/2+1 if n/2 is odd.\n!\n! ifax\n! an integer array. the number of elements actually used\n! will depend on the factorization of n. dimensioning\n! ifax for 13 suffices for all n less than a million.\n!\n! n\n! an even number greater than 4 that has no prime factor\n! greater than 5. n is the length of the transforms (see\n! the documentation for fft99 and fft991 for the\n! definitions of the transforms).\n!\n! on output ifax\n! contains the factorization of n/2. ifax(1) is the\n! number of factors, and the factors themselves are stored\n! in ifax(2),ifax(3),... if set99 is called with n odd,\n! or if n has any prime factors greater than 5, ifax(1)\n! is set to -99.\n!\n! trigs\n! an array of trigonometric function values subsequently\n! used by the fft routines.\n!\n!-----------------------------------------------------------------------\n!\n! subroutine fft991 (a,work,trigs,ifax,inc,jump,n,m,isign)\n! and\n! subroutine fft99 (a,work,trigs,ifax,inc,jump,n,m,isign)\n!\n! purpose perform a number of simultaneous real/half-complex\n! periodic fourier transforms or corresponding inverse\n! transforms, using ordinary spatial order of gridpoint\n! values (fft991) or explicit cyclic continuity in the\n! gridpoint values (fft99). given a set\n! of real data vectors, the package returns a set of\n! 'half-complex' fourier coefficient vectors, or vice\n! versa. the length of the transforms must be an even\n! number that has no other factors except possibly powers\n! of 2, 3, and 5. this is an all-fortran version of \n! optimized routine fft991 written for xmp/ymps by\n! dr. clive temperton of ecmwf.\n!\n! argument a(m*(n+2)), work(m*(n+1)), trigs(3*n/2+1), ifax(13)\n! dimensions\n!\n! arguments\n!\n! on input a\n! an array of length m*(n+2) containing the input data\n! or coefficient vectors. this array is overwritten by\n! the results.\n!\n! work\n! a work array of dimension m*(n+1)\n!\n! trigs\n! an array set up by set99, which must be called first.\n!\n! ifax\n! an array set up by set99, which must be called first.\n!\n! inc\n! the increment (in words) between successive elements of\n! each data or coefficient vector (e.g. inc=1 for\n! consecutively stored data).\n!\n! jump\n! the increment (in words) between the first elements of\n! successive data or coefficient vectors. on crays, \n! try to arrange data so that jump is not a multiple of 8\n! (to avoid memory bank conflicts). for clarification of\n! inc and jump, see the examples below.\n!\n! n\n! the length of each transform (see definition of\n! transforms, below).\n!\n! m\n! the number of transforms to be done simultaneously.\n!\n! isign\n! = +1 for a transform from fourier coefficients to\n! gridpoint values.\n! = -1 for a transform from gridpoint values to fourier\n! coefficients.\n!\n! on output a\n! if isign = +1, and m coefficient vectors are supplied\n! each containing the sequence:\n!\n! a(0),b(0),a(1),b(1),...,a(n/2),b(n/2) (n+2 values)\n!\n! then the result consists of m data vectors each\n! containing the corresponding n+2 gridpoint values:\n!\n! for fft991, x(0), x(1), x(2),...,x(n-1),0,0.\n! for fft99, x(n-1),x(0),x(1),x(2),...,x(n-1),x(0).\n! (explicit cyclic continuity)\n!\n! when isign = +1, the transform is defined by:\n! x(j)=sum(k=0,...,n-1)(c(k)*exp(2*i*j*k*pi/n))\n! where c(k)=a(k)+i*b(k) and c(n-k)=a(k)-i*b(k)\n! and i=sqrt (-1)\n!\n! if isign = -1, and m data vectors are supplied each\n! containing a sequence of gridpoint values x(j) as\n! defined above, then the result consists of m vectors\n! each containing the corresponding fourier cofficients\n! a(k), b(k), 0 .le. k .le n/2.\n!\n! when isign = -1, the inverse transform is defined by:\n! c(k)=(1/n)*sum(j=0,...,n-1)(x(j)*exp(-2*i*j*k*pi/n))\n! where c(k)=a(k)+i*b(k) and i=sqrt(-1)\n!\n! a call with isign=+1 followed by a call with isign=-1\n! (or vice versa) returns the original data.\n!\n! note: the fact that the gridpoint values x(j) are real\n! implies that b(0)=b(n/2)=0. for a call with isign=+1,\n! it is not actually necessary to supply these zeros.\n!\n! examples given 19 data vectors each of length 64 (+2 for explicit\n! cyclic continuity), compute the corresponding vectors of\n! fourier coefficients. the data may, for example, be\n! arranged like this:\n!\n! first data a(1)= . . . a(66)= a(70)\n! vector x(63) x(0) x(1) x(2) ... x(63) x(0) (4 empty locations)\n!\n! second data a(71)= . . . a(140)\n! vector x(63) x(0) x(1) x(2) ... x(63) x(0) (4 empty locations)\n!\n! and so on. here inc=1, jump=70, n=64, m=19, isign=-1,\n! and fft99 should be used (because of the explicit cyclic\n! continuity).\n!\n! alternatively the data may be arranged like this:\n!\n! first second last\n! data data data\n! vector vector vector\n!\n! a(1)= a(2)= a(19)=\n!\n! x(63) x(63) . . . x(63)\n! a(20)= x(0) x(0) . . . x(0)\n! a(39)= x(1) x(1) . . . x(1)\n! . . .\n! . . .\n! . . .\n!\n! in which case we have inc=19, jump=1, and the remaining\n! parameters are the same as before. in either case, each\n! coefficient vector overwrites the corresponding input\n! data vector.\n!\n!-----------------------------------------------------------------------\n integer, intent(in) :: inc,jump,n,lot,isign\n integer, intent(in) :: ifax(:)\n real, intent(in) :: trigs(:)\n real, intent(inout) :: a(*),work(*)\n\n! dimension a(n),work(n),trigs(n),ifax(1)\n!\n! subroutine \"fft99\" - multiple fast real periodic transform\n! corresponding to old scalar routine fft9\n! procedure used to convert to half-length complex transform\n! is given by cooley, lewis and welch (j. sound vib., vol. 12\n! (1970), 315-337)\n!\n! a is the array containing input and output data\n! work is an area of size (n+1)*lot\n! trigs is a previously prepared list of trig function values\n! ifax is a previously prepared list of factors of n/2\n! inc is the increment within each data 'vector'\n! (e.g. inc=1 for consecutively stored data)\n! jump is the increment between the start of each data vector\n! n is the length of the data vectors\n! lot is the number of data vectors\n! isign = +1 for transform from spectral to gridpoint\n! = -1 for transform from gridpoint to spectral\n!\n! ordering of coefficients:\n! a(0),b(0),a(1),b(1),a(2),b(2),...,a(n/2),b(n/2)\n! where b(0)=b(n/2)=0; (n+2) locations required\n!\n! ordering of data:\n! x(n-1),x(0),x(1),x(2),...,x(n),x(0)\n! i.e. explicit cyclic continuity; (n+2) locations required\n!\n! vectorization is achieved on cray by doing the transforms in\n! parallel\n!\n! *** n.b. n is assumed to be an even number\n!\n! definition of transforms:\n! -------------------------\n!\n! isign=+1: x(j)=sum(k=0,...,n-1)(c(k)*exp(2*i*j*k*pi/n))\n! where c(k)=a(k)+i*b(k) and c(n-k)=a(k)-i*b(k)\n!\n! isign=-1: a(k)=(1/n)*sum(j=0,...,n-1)(x(j)*cos(2*j*k*pi/n))\n! b(k)=-(1/n)*sum(j=0,...,n-1)(x(j)*sin(2*j*k*pi/n))\n!\n\n integer :: nfax, nx, nh, ink, igo, ibase, jbase\n integer :: i, j, k, L, m, ia, la, ib\n\n nfax=ifax(1)\n nx=n+1\n nh=n/2\n ink=inc+inc\n if (isign.eq.+1) go to 30\n\n! if necessary, transfer data to work area\n igo=50\n if (mod(nfax,2).eq.1) goto 40\n ibase=inc+1\n jbase=1\n do L=1,lot\n i=ibase\n j=jbase\n do m=1,n\n work(j)=a(i)\n i=i+inc\n j=j+1\n enddo\n ibase=ibase+jump\n jbase=jbase+nx\n enddo\n\n igo=60\n go to 40\n\n! preprocessing (isign=+1)\n! ------------------------\n\n 30 continue\n call fft99a(a,work,trigs,inc,jump,n,lot)\n igo=60\n\n! complex transform\n! -----------------\n\n 40 continue\n ia=inc+1\n la=1\n do 80 k=1,nfax\n if (igo.eq.60) go to 60\n 50 continue\n call vpassm (a(ia),a(ia+inc),work(1),work(2),trigs, &\n ink,2,jump,nx,lot,nh,ifax(k+1),la)\n igo=60\n go to 70\n 60 continue\n call vpassm (work(1),work(2),a(ia),a(ia+inc),trigs, &\n 2,ink,nx,jump,lot,nh,ifax(k+1),la)\n igo=50\n 70 continue\n la=la*ifax(k+1)\n 80 continue\n\n if (isign.eq.-1) go to 130\n\n! if necessary, transfer data from work area\n\n if (mod(nfax,2).ne.1) then\n ibase=1\n jbase=ia\n do L=1,lot\n i=ibase\n j=jbase\n do m=1,n\n a(j)=work(i)\n i=i+1\n j=j+inc\n enddo\n ibase=ibase+nx\n jbase=jbase+jump\n enddo\n endif\n\n! fill in cyclic boundary points\n ia=1\n ib=n*inc+1\n do L=1,lot\n a(ia)=a(ib)\n a(ib+inc)=a(ia+inc)\n ia=ia+jump\n ib=ib+jump\n enddo\n go to 140\n\n! postprocessing (isign=-1):\n! --------------------------\n\n 130 continue\n call fft99b(work,a,trigs,inc,jump,n,lot)\n\n 140 continue\n\n end subroutine fft99\n\n!##########################################################################\n\n subroutine fft99a (a,work,trigs,inc,jump,n,lot)\n integer, intent(in) :: inc,jump,n,lot\n real, intent(in) :: trigs(:)\n real, intent(inout) :: a(*),work(*)\n\n! dimension a(n),work(n),trigs(n)\n!\n! subroutine fft99a - preprocessing step for fft99, isign=+1\n! (spectral to gridpoint transform)\n\n integer :: nh, nx, ink, k, L\n integer :: ia, ib, ja, jb, iabase, ibbase, jabase, jbbase\n real :: c, s\n\n nh=n/2\n nx=n+1\n ink=inc+inc\n\n! a(0) and a(n/2)\n ia=1\n ib=n*inc+1\n ja=1\n jb=2\n do L=1,lot\n work(ja)=a(ia)+a(ib)\n work(jb)=a(ia)-a(ib)\n ia=ia+jump\n ib=ib+jump\n ja=ja+nx\n jb=jb+nx\n enddo\n \n! remaining wavenumbers\n iabase=2*inc+1\n ibbase=(n-2)*inc+1\n jabase=3\n jbbase=n-1\n\n do k=3,nh,2\n ia=iabase\n ib=ibbase\n ja=jabase\n jb=jbbase\n c=trigs(n+k)\n s=trigs(n+k+1)\n do L=1,lot\n work(ja)=(a(ia)+a(ib))- &\n (s*(a(ia)-a(ib))+c*(a(ia+inc)+a(ib+inc)))\n work(jb)=(a(ia)+a(ib))+ &\n (s*(a(ia)-a(ib))+c*(a(ia+inc)+a(ib+inc)))\n work(ja+1)=(c*(a(ia)-a(ib))-s*(a(ia+inc)+a(ib+inc)))+ &\n (a(ia+inc)-a(ib+inc))\n work(jb+1)=(c*(a(ia)-a(ib))-s*(a(ia+inc)+a(ib+inc)))- &\n (a(ia+inc)-a(ib+inc))\n ia=ia+jump\n ib=ib+jump\n ja=ja+nx\n jb=jb+nx\n enddo\n iabase=iabase+ink\n ibbase=ibbase-ink\n jabase=jabase+2\n jbbase=jbbase-2\n enddo\n\n! wavenumber n/4 (if it exists)\n if (iabase.eq.ibbase) then\n ia=iabase\n ja=jabase\n do L=1,lot\n work(ja)=2.0*a(ia)\n work(ja+1)=-2.0*a(ia+inc)\n ia=ia+jump\n ja=ja+nx\n enddo\n endif\n\n end subroutine fft99a\n\n!##########################################################################\n\n subroutine fft99b (work,a,trigs,inc,jump,n,lot)\n integer, intent(in) :: inc,jump,n,lot\n real, intent(in) :: trigs(:)\n real, intent(inout) :: a(*),work(*)\n\n! dimension work(n),a(n),trigs(n)\n!\n! subroutine fft99b - postprocessing step for fft99, isign=-1\n! (gridpoint to spectral transform)\n\n integer :: nh, nx, ink, k, L\n integer :: ia, ib, ja, jb, iabase, ibbase, jabase, jbbase\n real :: scale, c, s\n\n nh=n/2\n nx=n+1\n ink=inc+inc\n\n! a(0) and a(n/2)\n scale=1.0/real(n)\n ia=1\n ib=2\n ja=1\n jb=n*inc+1\n do L=1,lot\n a(ja)=scale*(work(ia)+work(ib))\n a(jb)=scale*(work(ia)-work(ib))\n a(ja+inc)=0.0\n a(jb+inc)=0.0\n ia=ia+nx\n ib=ib+nx\n ja=ja+jump\n jb=jb+jump\n enddo\n\n! remaining wavenumbers\n scale=0.5*scale\n iabase=3\n ibbase=n-1\n jabase=2*inc+1\n jbbase=(n-2)*inc+1\n\n do k=3,nh,2\n ia=iabase\n ib=ibbase\n ja=jabase\n jb=jbbase\n c=trigs(n+k)\n s=trigs(n+k+1)\n do L=1,lot\n a(ja)=scale*((work(ia)+work(ib)) &\n +(c*(work(ia+1)+work(ib+1))+s*(work(ia)-work(ib))))\n a(jb)=scale*((work(ia)+work(ib)) &\n -(c*(work(ia+1)+work(ib+1))+s*(work(ia)-work(ib))))\n a(ja+inc)=scale*((c*(work(ia)-work(ib))-s*(work(ia+1)+work(ib+1))) &\n +(work(ib+1)-work(ia+1)))\n a(jb+inc)=scale*((c*(work(ia)-work(ib))-s*(work(ia+1)+work(ib+1))) &\n -(work(ib+1)-work(ia+1)))\n ia=ia+nx\n ib=ib+nx\n ja=ja+jump\n jb=jb+jump\n enddo\n iabase=iabase+2\n ibbase=ibbase-2\n jabase=jabase+ink\n jbbase=jbbase-ink\n enddo\n\n! wavenumber n/4 (if it exists)\n if (iabase.eq.ibbase) then\n ia=iabase\n ja=jabase\n scale=2.0*scale\n do L=1,lot\n a(ja)=scale*work(ia)\n a(ja+inc)=-scale*work(ia+1)\n ia=ia+nx\n ja=ja+jump\n enddo\n endif\n\n end subroutine fft99b\n\n!##########################################################################\n\n subroutine fft991(a,work,trigs,ifax,inc,jump,n,lot,isign)\n integer, intent(in) :: inc,jump,n,lot,isign\n integer, intent(in) :: ifax(:)\n real, intent(in) :: trigs(:)\n real, intent(inout) :: a(*),work(*)\n\n! dimension a(n),work(n),trigs(n),ifax(1)\n!\n! subroutine \"fft991\" - multiple real/half-complex periodic\n! fast fourier transform\n!\n! same as fft99 except that ordering of data corresponds to\n! that in mrfft2\n!\n! procedure used to convert to half-length complex transform\n! is given by cooley, lewis and welch (j. sound vib., vol. 12\n! (1970), 315-337)\n!\n! a is the array containing input and output data\n! work is an area of size (n+1)*lot\n! trigs is a previously prepared list of trig function values\n! ifax is a previously prepared list of factors of n/2\n! inc is the increment within each data 'vector'\n! (e.g. inc=1 for consecutively stored data)\n! jump is the increment between the start of each data vector\n! n is the length of the data vectors\n! lot is the number of data vectors\n! isign = +1 for transform from spectral to gridpoint\n! = -1 for transform from gridpoint to spectral\n!\n! ordering of coefficients:\n! a(0),b(0),a(1),b(1),a(2),b(2),...,a(n/2),b(n/2)\n! where b(0)=b(n/2)=0; (n+2) locations required\n!\n! ordering of data:\n! x(0),x(1),x(2),...,x(n-1)\n!\n! vectorization is achieved on cray by doing the transforms in\n! parallel\n!\n! *** n.b. n is assumed to be an even number\n!\n! definition of transforms:\n! -------------------------\n!\n! isign=+1: x(j)=sum(k=0,...,n-1)(c(k)*exp(2*i*j*k*pi/n))\n! where c(k)=a(k)+i*b(k) and c(n-k)=a(k)-i*b(k)\n!\n! isign=-1: a(k)=(1/n)*sum(j=0,...,n-1)(x(j)*cos(2*j*k*pi/n))\n! b(k)=-(1/n)*sum(j=0,...,n-1)(x(j)*sin(2*j*k*pi/n))\n!\n\n integer :: nfax, nx, nh, ink, igo, ibase, jbase\n integer :: i, j, k, L, m, ia, la, ib\n\n\n nfax=ifax(1)\n nx=n+1\n nh=n/2\n ink=inc+inc\n if (isign.eq.+1) go to 30\n\n! if necessary, transfer data to work area\n igo=50\n if (mod(nfax,2).eq.1) goto 40\n ibase=1\n jbase=1\n do L=1,lot\n i=ibase\n j=jbase\n do m=1,n\n work(j)=a(i)\n i=i+inc\n j=j+1\n enddo\n ibase=ibase+jump\n jbase=jbase+nx\n enddo\n!\n igo=60\n go to 40\n!\n! preprocessing (isign=+1)\n! ------------------------\n!\n 30 continue\n call fft99a(a,work,trigs,inc,jump,n,lot)\n igo=60\n!\n! complex transform\n! -----------------\n!\n 40 continue\n ia=1\n la=1\n do k=1,nfax\n if (igo.eq.60) go to 60\n 50 continue\n call vpassm (a(ia),a(ia+inc),work(1),work(2),trigs, &\n ink,2,jump,nx,lot,nh,ifax(k+1),la)\n igo=60\n go to 70\n 60 continue\n call vpassm (work(1),work(2),a(ia),a(ia+inc),trigs, &\n 2,ink,nx,jump,lot,nh,ifax(k+1),la)\n igo=50\n 70 continue\n la=la*ifax(k+1)\n enddo\n\n if (isign.eq.-1) go to 130\n\n! if necessary, transfer data from work area\n if (mod(nfax,2).ne.1) then\n ibase=1\n jbase=1\n do L=1,lot\n i=ibase\n j=jbase\n do m=1,n\n a(j)=work(i)\n i=i+1\n j=j+inc\n enddo\n ibase=ibase+nx\n jbase=jbase+jump\n enddo\n endif\n\n! fill in zeros at end\n ib=n*inc+1\n do L=1,lot\n a(ib)=0.0\n a(ib+inc)=0.0\n ib=ib+jump\n enddo\n go to 140\n\n! postprocessing (isign=-1):\n! --------------------------\n\n 130 continue\n call fft99b (work,a,trigs,inc,jump,n,lot)\n\n 140 continue\n\n end subroutine fft991\n\n!##########################################################################\n\n subroutine set99 (trigs, ifax, n)\n integer, intent(in) :: n\n integer, intent(out) :: ifax(:)\n real, intent(out) :: trigs(:)\n\n! dimension ifax(13),trigs(1)\n!\n! mode 3 is used for real/half-complex transforms. it is possible\n! to do complex/complex transforms with other values of mode, but\n! documentation of the details were not available when this routine\n! was written.\n!\n integer :: mode = 3\n integer :: i\n\n call fax (ifax, n, mode)\n i = ifax(1)\n if (ifax(i+1) .gt. 5 .or. n .le. 4) ifax(1) = -99\n if (ifax(1) .le. 0 ) then \n write(6,*) ' set99 -- invalid n'\n stop\n endif\n call fftrig (trigs, n, mode)\n\n end subroutine set99\n\n!##########################################################################\n\n subroutine fax (ifax,n,mode)\n integer, intent(out) :: ifax(:)\n integer, intent(in) :: n, mode\n\n integer :: nn, k, L, inc, nfax, ii, istop, i, item\n\n nn=n\n if (iabs(mode).eq.1) go to 10\n if (iabs(mode).eq.8) go to 10\n nn=n/2\n if ((nn+nn).eq.n) go to 10\n ifax(1)=-99\n return\n 10 k=1\n! test for factors of 4\n 20 if (mod(nn,4).ne.0) go to 30\n k=k+1\n ifax(k)=4\n nn=nn/4\n if (nn.eq.1) go to 80\n go to 20\n! test for extra factor of 2\n 30 if (mod(nn,2).ne.0) go to 40\n k=k+1\n ifax(k)=2\n nn=nn/2\n if (nn.eq.1) go to 80\n! test for factors of 3\n 40 if (mod(nn,3).ne.0) go to 50\n k=k+1\n ifax(k)=3\n nn=nn/3\n if (nn.eq.1) go to 80\n go to 40\n! now find remaining factors\n 50 L=5\n inc=2\n! inc alternately takes on values 2 and 4\n 60 if (mod(nn,L).ne.0) go to 70\n k=k+1\n ifax(k)=L\n nn=nn/L\n if (nn.eq.1) go to 80\n go to 60\n 70 L=L+inc\n inc=6-inc\n go to 60\n 80 ifax(1)=k-1\n! ifax(1) contains number of factors\n nfax=ifax(1)\n! sort factors into ascending order\n if (nfax.eq.1) go to 110\n do 100 ii=2,nfax\n istop=nfax+2-ii\n do 90 i=2,istop\n if (ifax(i+1).ge.ifax(i)) go to 90\n item=ifax(i)\n ifax(i)=ifax(i+1)\n ifax(i+1)=item\n 90 continue\n 100 continue\n 110 continue\n\n end subroutine fax\n\n!##########################################################################\n\n subroutine fftrig (trigs,n,mode)\n real, intent(out) :: trigs(:)\n integer, intent(in) :: n, mode\n\n real :: del, angle,pi\n integer :: imode, nn, nh, i, L, la\n\n pi = 4.*atan(1.0)\n imode=iabs(mode)\n nn=n\n if (imode.gt.1.and.imode.lt.6) nn=n/2\n del=(pi+pi)/real(nn)\n L=nn+nn\n do i=1,L,2\n angle=0.5*real(i-1)*del\n trigs(i)=cos(angle)\n trigs(i+1)=sin(angle)\n enddo\n if (imode.eq.1) return\n if (imode.eq.8) return\n\n del=0.5*del\n nh=(nn+1)/2\n L=nh+nh\n la=nn+nn\n do i=1,L,2\n angle=0.5*real(i-1)*del\n trigs(la+i)=cos(angle)\n trigs(la+i+1)=sin(angle)\n enddo\n if (imode.le.3) return\n\n del=0.5*del\n la=la+nn\n if (mode.ne.5) then\n do i=2,nn\n angle=real(i-1)*del\n trigs(la+i)=2.0*sin(angle)\n enddo\n return\n endif\n\n del=0.5*del\n do i=2,n\n angle=real(i-1)*del\n trigs(la+i)=sin(angle)\n enddo\n\n end subroutine fftrig\n\n!##########################################################################\n\n subroutine vpassm (a,b,c,d,trigs,inc1,inc2,inc3,inc4,lot,n,ifac,la)\n integer, intent(in) :: inc1, inc2, inc3, inc4, lot, n, ifac, la\n real, intent(in) :: a(n),b(n),trigs(n)\n real, intent(out) :: c(n),d(n)\n!\n! subroutine \"vpassm\" - multiple version of \"vpassa\"\n! performs one pass through data\n! as part of multiple complex fft routine\n! a is first real input vector\n! b is first imaginary input vector\n! c is first real output vector\n! d is first imaginary output vector\n! trigs is precalculated table of sines \" cosines\n! inc1 is addressing increment for a and b\n! inc2 is addressing increment for c and d\n! inc3 is addressing increment between a\"s & b\"s\n! inc4 is addressing increment between c\"s & d\"s\n! lot is the number of vectors\n! n is length of vectors\n! ifac is current factor of n\n! la is product of previous factors\n!\n\n real :: sin36=0.587785252292473\n real :: cos36=0.809016994374947\n real :: sin72=0.951056516295154\n real :: cos72=0.309016994374947\n real :: sin60=0.866025403784437\n\n integer :: i, j, k, L, m, iink, jink, jump, ibase, jbase, igo, ijk, la1\n integer :: ia, ja, ib, jb, kb, ic, jc, kc, id, jd, kd, ie, je, ke\n real :: c1, s1, c2, s2, c3, s3, c4, s4\n\n m=n/ifac\n iink=m*inc1\n jink=la*inc2\n jump=(ifac-1)*jink\n ibase=0\n jbase=0\n igo=ifac-1\n if (igo.gt.4) return\n!del go to (10,50,90,130),igo\n\n select case (igo)\n\n! coding for factor 2\n\n case (1)\n 10 ia=1\n ja=1\n ib=ia+iink\n jb=ja+jink\n do 20 L=1,la\n i=ibase\n j=jbase\n do 15 ijk=1,lot\n c(ja+j)=a(ia+i)+a(ib+i)\n d(ja+j)=b(ia+i)+b(ib+i)\n c(jb+j)=a(ia+i)-a(ib+i)\n d(jb+j)=b(ia+i)-b(ib+i)\n i=i+inc3\n j=j+inc4\n 15 continue\n ibase=ibase+inc1\n jbase=jbase+inc2\n 20 continue\n if (la.eq.m) return\n la1=la+1\n jbase=jbase+jump\n do 40 k=la1,m,la\n kb=k+k-2\n c1=trigs(kb+1)\n s1=trigs(kb+2)\n do 30 L=1,la\n i=ibase\n j=jbase\n do 25 ijk=1,lot\n c(ja+j)=a(ia+i)+a(ib+i)\n d(ja+j)=b(ia+i)+b(ib+i)\n c(jb+j)=c1*(a(ia+i)-a(ib+i))-s1*(b(ia+i)-b(ib+i))\n d(jb+j)=s1*(a(ia+i)-a(ib+i))+c1*(b(ia+i)-b(ib+i))\n i=i+inc3\n j=j+inc4\n 25 continue\n ibase=ibase+inc1\n jbase=jbase+inc2\n 30 continue\n jbase=jbase+jump\n 40 continue\n! return\n\n! coding for factor 3\n\n case (2)\n 50 ia=1\n ja=1\n ib=ia+iink\n jb=ja+jink\n ic=ib+iink\n jc=jb+jink\n do 60 L=1,la\n i=ibase\n j=jbase\n do 55 ijk=1,lot\n c(ja+j)=a(ia+i)+(a(ib+i)+a(ic+i))\n d(ja+j)=b(ia+i)+(b(ib+i)+b(ic+i))\n c(jb+j)=(a(ia+i)-0.5*(a(ib+i)+a(ic+i)))-(sin60*(b(ib+i)-b(ic+i)))\n c(jc+j)=(a(ia+i)-0.5*(a(ib+i)+a(ic+i)))+(sin60*(b(ib+i)-b(ic+i)))\n d(jb+j)=(b(ia+i)-0.5*(b(ib+i)+b(ic+i)))+(sin60*(a(ib+i)-a(ic+i)))\n d(jc+j)=(b(ia+i)-0.5*(b(ib+i)+b(ic+i)))-(sin60*(a(ib+i)-a(ic+i)))\n i=i+inc3\n j=j+inc4\n 55 continue\n ibase=ibase+inc1\n jbase=jbase+inc2\n 60 continue\n if (la.eq.m) return\n la1=la+1\n jbase=jbase+jump\n do 80 k=la1,m,la\n kb=k+k-2\n kc=kb+kb\n c1=trigs(kb+1)\n s1=trigs(kb+2)\n c2=trigs(kc+1)\n s2=trigs(kc+2)\n do 70 L=1,la\n i=ibase\n j=jbase\n do 65 ijk=1,lot\n c(ja+j)=a(ia+i)+(a(ib+i)+a(ic+i))\n d(ja+j)=b(ia+i)+(b(ib+i)+b(ic+i))\n c(jb+j)= &\n c1*((a(ia+i)-0.5*(a(ib+i)+a(ic+i)))-(sin60*(b(ib+i)-b(ic+i)))) &\n -s1*((b(ia+i)-0.5*(b(ib+i)+b(ic+i)))+(sin60*(a(ib+i)-a(ic+i))))\n d(jb+j)= &\n s1*((a(ia+i)-0.5*(a(ib+i)+a(ic+i)))-(sin60*(b(ib+i)-b(ic+i)))) &\n +c1*((b(ia+i)-0.5*(b(ib+i)+b(ic+i)))+(sin60*(a(ib+i)-a(ic+i))))\n c(jc+j)= &\n c2*((a(ia+i)-0.5*(a(ib+i)+a(ic+i)))+(sin60*(b(ib+i)-b(ic+i)))) &\n -s2*((b(ia+i)-0.5*(b(ib+i)+b(ic+i)))-(sin60*(a(ib+i)-a(ic+i))))\n d(jc+j)= &\n s2*((a(ia+i)-0.5*(a(ib+i)+a(ic+i)))+(sin60*(b(ib+i)-b(ic+i)))) &\n +c2*((b(ia+i)-0.5*(b(ib+i)+b(ic+i)))-(sin60*(a(ib+i)-a(ic+i))))\n i=i+inc3\n j=j+inc4\n 65 continue\n ibase=ibase+inc1\n jbase=jbase+inc2\n 70 continue\n jbase=jbase+jump\n 80 continue\n! return\n\n! coding for factor 4\n\n case (3)\n 90 ia=1\n ja=1\n ib=ia+iink\n jb=ja+jink\n ic=ib+iink\n jc=jb+jink\n id=ic+iink\n jd=jc+jink\n do 100 L=1,la\n i=ibase\n j=jbase\n do 95 ijk=1,lot\n c(ja+j)=(a(ia+i)+a(ic+i))+(a(ib+i)+a(id+i))\n c(jc+j)=(a(ia+i)+a(ic+i))-(a(ib+i)+a(id+i))\n d(ja+j)=(b(ia+i)+b(ic+i))+(b(ib+i)+b(id+i))\n d(jc+j)=(b(ia+i)+b(ic+i))-(b(ib+i)+b(id+i))\n c(jb+j)=(a(ia+i)-a(ic+i))-(b(ib+i)-b(id+i))\n c(jd+j)=(a(ia+i)-a(ic+i))+(b(ib+i)-b(id+i))\n d(jb+j)=(b(ia+i)-b(ic+i))+(a(ib+i)-a(id+i))\n d(jd+j)=(b(ia+i)-b(ic+i))-(a(ib+i)-a(id+i))\n i=i+inc3\n j=j+inc4\n 95 continue\n ibase=ibase+inc1\n jbase=jbase+inc2\n 100 continue\n if (la.eq.m) return\n la1=la+1\n jbase=jbase+jump\n do 120 k=la1,m,la\n kb=k+k-2\n kc=kb+kb\n kd=kc+kb\n c1=trigs(kb+1)\n s1=trigs(kb+2)\n c2=trigs(kc+1)\n s2=trigs(kc+2)\n c3=trigs(kd+1)\n s3=trigs(kd+2)\n do 110 L=1,la\n i=ibase\n j=jbase\n do 105 ijk=1,lot\n c(ja+j)=(a(ia+i)+a(ic+i))+(a(ib+i)+a(id+i))\n d(ja+j)=(b(ia+i)+b(ic+i))+(b(ib+i)+b(id+i))\n c(jc+j)= &\n c2*((a(ia+i)+a(ic+i))-(a(ib+i)+a(id+i))) &\n -s2*((b(ia+i)+b(ic+i))-(b(ib+i)+b(id+i)))\n d(jc+j)= &\n s2*((a(ia+i)+a(ic+i))-(a(ib+i)+a(id+i))) &\n +c2*((b(ia+i)+b(ic+i))-(b(ib+i)+b(id+i)))\n c(jb+j)= &\n c1*((a(ia+i)-a(ic+i))-(b(ib+i)-b(id+i))) &\n -s1*((b(ia+i)-b(ic+i))+(a(ib+i)-a(id+i)))\n d(jb+j)= &\n s1*((a(ia+i)-a(ic+i))-(b(ib+i)-b(id+i))) &\n +c1*((b(ia+i)-b(ic+i))+(a(ib+i)-a(id+i)))\n c(jd+j)= &\n c3*((a(ia+i)-a(ic+i))+(b(ib+i)-b(id+i))) &\n -s3*((b(ia+i)-b(ic+i))-(a(ib+i)-a(id+i)))\n d(jd+j)= &\n s3*((a(ia+i)-a(ic+i))+(b(ib+i)-b(id+i))) &\n +c3*((b(ia+i)-b(ic+i))-(a(ib+i)-a(id+i)))\n i=i+inc3\n j=j+inc4\n 105 continue\n ibase=ibase+inc1\n jbase=jbase+inc2\n 110 continue\n jbase=jbase+jump\n 120 continue\n! return\n\n! coding for factor 5\n\n case (4)\n 130 ia=1\n ja=1\n ib=ia+iink\n jb=ja+jink\n ic=ib+iink\n jc=jb+jink\n id=ic+iink\n jd=jc+jink\n ie=id+iink\n je=jd+jink\n do 140 L=1,la\n i=ibase\n j=jbase\n do 135 ijk=1,lot\n c(ja+j)=a(ia+i)+(a(ib+i)+a(ie+i))+(a(ic+i)+a(id+i))\n d(ja+j)=b(ia+i)+(b(ib+i)+b(ie+i))+(b(ic+i)+b(id+i))\n c(jb+j)=(a(ia+i)+cos72*(a(ib+i)+a(ie+i))-cos36*(a(ic+i)+a(id+i))) &\n -(sin72*(b(ib+i)-b(ie+i))+sin36*(b(ic+i)-b(id+i)))\n c(je+j)=(a(ia+i)+cos72*(a(ib+i)+a(ie+i))-cos36*(a(ic+i)+a(id+i))) &\n +(sin72*(b(ib+i)-b(ie+i))+sin36*(b(ic+i)-b(id+i)))\n d(jb+j)=(b(ia+i)+cos72*(b(ib+i)+b(ie+i))-cos36*(b(ic+i)+b(id+i))) &\n +(sin72*(a(ib+i)-a(ie+i))+sin36*(a(ic+i)-a(id+i)))\n d(je+j)=(b(ia+i)+cos72*(b(ib+i)+b(ie+i))-cos36*(b(ic+i)+b(id+i))) &\n -(sin72*(a(ib+i)-a(ie+i))+sin36*(a(ic+i)-a(id+i)))\n c(jc+j)=(a(ia+i)-cos36*(a(ib+i)+a(ie+i))+cos72*(a(ic+i)+a(id+i))) &\n -(sin36*(b(ib+i)-b(ie+i))-sin72*(b(ic+i)-b(id+i)))\n c(jd+j)=(a(ia+i)-cos36*(a(ib+i)+a(ie+i))+cos72*(a(ic+i)+a(id+i))) &\n +(sin36*(b(ib+i)-b(ie+i))-sin72*(b(ic+i)-b(id+i)))\n d(jc+j)=(b(ia+i)-cos36*(b(ib+i)+b(ie+i))+cos72*(b(ic+i)+b(id+i))) &\n +(sin36*(a(ib+i)-a(ie+i))-sin72*(a(ic+i)-a(id+i)))\n d(jd+j)=(b(ia+i)-cos36*(b(ib+i)+b(ie+i))+cos72*(b(ic+i)+b(id+i))) &\n -(sin36*(a(ib+i)-a(ie+i))-sin72*(a(ic+i)-a(id+i)))\n i=i+inc3\n j=j+inc4\n 135 continue\n ibase=ibase+inc1\n jbase=jbase+inc2\n 140 continue\n if (la.eq.m) return\n la1=la+1\n jbase=jbase+jump\n do 160 k=la1,m,la\n kb=k+k-2\n kc=kb+kb\n kd=kc+kb\n ke=kd+kb\n c1=trigs(kb+1)\n s1=trigs(kb+2)\n c2=trigs(kc+1)\n s2=trigs(kc+2)\n c3=trigs(kd+1)\n s3=trigs(kd+2)\n c4=trigs(ke+1)\n s4=trigs(ke+2)\n do 150 L=1,la\n i=ibase\n j=jbase\n do 145 ijk=1,lot\n c(ja+j)=a(ia+i)+(a(ib+i)+a(ie+i))+(a(ic+i)+a(id+i))\n d(ja+j)=b(ia+i)+(b(ib+i)+b(ie+i))+(b(ic+i)+b(id+i))\n c(jb+j)= &\n c1*((a(ia+i)+cos72*(a(ib+i)+a(ie+i))-cos36*(a(ic+i)+a(id+i))) &\n -(sin72*(b(ib+i)-b(ie+i))+sin36*(b(ic+i)-b(id+i)))) &\n -s1*((b(ia+i)+cos72*(b(ib+i)+b(ie+i))-cos36*(b(ic+i)+b(id+i))) &\n +(sin72*(a(ib+i)-a(ie+i))+sin36*(a(ic+i)-a(id+i))))\n d(jb+j)= &\n s1*((a(ia+i)+cos72*(a(ib+i)+a(ie+i))-cos36*(a(ic+i)+a(id+i))) &\n -(sin72*(b(ib+i)-b(ie+i))+sin36*(b(ic+i)-b(id+i)))) &\n +c1*((b(ia+i)+cos72*(b(ib+i)+b(ie+i))-cos36*(b(ic+i)+b(id+i))) &\n +(sin72*(a(ib+i)-a(ie+i))+sin36*(a(ic+i)-a(id+i))))\n c(je+j)= &\n c4*((a(ia+i)+cos72*(a(ib+i)+a(ie+i))-cos36*(a(ic+i)+a(id+i))) &\n +(sin72*(b(ib+i)-b(ie+i))+sin36*(b(ic+i)-b(id+i)))) &\n -s4*((b(ia+i)+cos72*(b(ib+i)+b(ie+i))-cos36*(b(ic+i)+b(id+i))) &\n -(sin72*(a(ib+i)-a(ie+i))+sin36*(a(ic+i)-a(id+i))))\n d(je+j)= &\n s4*((a(ia+i)+cos72*(a(ib+i)+a(ie+i))-cos36*(a(ic+i)+a(id+i))) &\n +(sin72*(b(ib+i)-b(ie+i))+sin36*(b(ic+i)-b(id+i)))) &\n +c4*((b(ia+i)+cos72*(b(ib+i)+b(ie+i))-cos36*(b(ic+i)+b(id+i))) &\n -(sin72*(a(ib+i)-a(ie+i))+sin36*(a(ic+i)-a(id+i))))\n c(jc+j)= &\n c2*((a(ia+i)-cos36*(a(ib+i)+a(ie+i))+cos72*(a(ic+i)+a(id+i))) &\n -(sin36*(b(ib+i)-b(ie+i))-sin72*(b(ic+i)-b(id+i)))) &\n -s2*((b(ia+i)-cos36*(b(ib+i)+b(ie+i))+cos72*(b(ic+i)+b(id+i))) &\n +(sin36*(a(ib+i)-a(ie+i))-sin72*(a(ic+i)-a(id+i))))\n d(jc+j)= &\n s2*((a(ia+i)-cos36*(a(ib+i)+a(ie+i))+cos72*(a(ic+i)+a(id+i))) &\n -(sin36*(b(ib+i)-b(ie+i))-sin72*(b(ic+i)-b(id+i)))) &\n +c2*((b(ia+i)-cos36*(b(ib+i)+b(ie+i))+cos72*(b(ic+i)+b(id+i))) &\n +(sin36*(a(ib+i)-a(ie+i))-sin72*(a(ic+i)-a(id+i))))\n c(jd+j)= &\n c3*((a(ia+i)-cos36*(a(ib+i)+a(ie+i))+cos72*(a(ic+i)+a(id+i))) &\n +(sin36*(b(ib+i)-b(ie+i))-sin72*(b(ic+i)-b(id+i)))) &\n -s3*((b(ia+i)-cos36*(b(ib+i)+b(ie+i))+cos72*(b(ic+i)+b(id+i))) &\n -(sin36*(a(ib+i)-a(ie+i))-sin72*(a(ic+i)-a(id+i))))\n d(jd+j)= &\n s3*((a(ia+i)-cos36*(a(ib+i)+a(ie+i))+cos72*(a(ic+i)+a(id+i))) &\n +(sin36*(b(ib+i)-b(ie+i))-sin72*(b(ic+i)-b(id+i)))) &\n +c3*((b(ia+i)-cos36*(b(ib+i)+b(ie+i))+cos72*(b(ic+i)+b(id+i))) &\n -(sin36*(a(ib+i)-a(ie+i))-sin72*(a(ic+i)-a(id+i))))\n i=i+inc3\n j=j+inc4\n 145 continue\n ibase=ibase+inc1\n jbase=jbase+inc2\n 150 continue\n jbase=jbase+jump\n 160 continue\n\n end select\n\n end subroutine vpassm\n \nSUBROUTINE spat2spec(Z,U,spheredat) !Added by Sam Goldberg to use 2-dimensional matrices of spherical harmonic coefficients (U(l,m))\nIMPLICIT none\nTYPE(sphere), INTENT(IN) :: spheredat\nREAL, DIMENSION(spheredat%nlats, spheredat%nlons), INTENT(IN) :: Z !spatial field\nCOMPLEX, DIMENSION(0:spheredat%ntrunc, 0:spheredat%ntrunc), INTENT(OUT) :: U !matrix of spherical harmonic coefficients\nCOMPLEX, DIMENSION((spheredat%ntrunc+1)*(spheredat%ntrunc+2)/2) :: Uvec !Vector of spherical harmonic coefficients\nREAL, DIMENSION(spheredat%nlats, spheredat%nlons) :: Zi\nINTEGER :: i,m,n\n\nZi(:,:) = Z(:,:)\n\nCALL spharm(spheredat,Zi,Uvec,1)\n\n!Convert vector of coefficients into matrix\nDO n = 0,spheredat%ntrunc\n DO m = 0,n\n U(n,m) = Uvec(sum((/(i,i=spheredat%ntrunc+1,spheredat%ntrunc-m+2,-1)/))+n-m+1)/1.41421356 !Corrects for SH normalization to match Jerry's\n ENDDO\nENDDO\n\nEND SUBROUTINE spat2spec\n\nSUBROUTINE spec2spat(Z,U,spheredat) !Added by Sam Goldberg to use 2-dimensional matrices of spherical harmonic coefficients (U(l,m))\nIMPLICIT none\nTYPE(sphere), INTENT(IN) :: spheredat\nREAL, DIMENSION(spheredat%nlats, spheredat%nlons), INTENT(OUT) :: Z !spatial field\nCOMPLEX, DIMENSION(0:spheredat%ntrunc, 0:spheredat%ntrunc), INTENT(IN) :: U !matrix of spherical harmonic coefficients\nCOMPLEX, DIMENSION((spheredat%ntrunc+1)*(spheredat%ntrunc+2)/2) :: Uvec !Vector of spherical harmonic coefficients\nINTEGER :: i\n\n\n!Convert matrix of coefficients into vector\nDO i = 1,((spheredat%ntrunc+1)*(spheredat%ntrunc+2)/2)\n Uvec(i) = U(spheredat%indxn(i),spheredat%indxm(i))*1.41421356 !Corrects for SH normalization to match Jerry's\nENDDO\n\nCALL spharm(spheredat,Z,Uvec,-1) \n\nEND SUBROUTINE spec2spat\n\nend module spharmt", "meta": {"hexsha": "95475e394a4a277455e5c24c26a2a5f1bf6fac71", "size": 63219, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "spharmt.f90", "max_stars_repo_name": "MALI-Dev/1DSeaLevelModel_FWTW", "max_stars_repo_head_hexsha": "3d74f592cb890f6347aca9c6defadaf567dfd62c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "spharmt.f90", "max_issues_repo_name": "MALI-Dev/1DSeaLevelModel_FWTW", "max_issues_repo_head_hexsha": "3d74f592cb890f6347aca9c6defadaf567dfd62c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-03-03T01:00:31.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-03T20:51:33.000Z", "max_forks_repo_path": "spharmt.f90", "max_forks_repo_name": "MALI-Dev/1DSeaLevelModel_FWTW", "max_forks_repo_head_hexsha": "3d74f592cb890f6347aca9c6defadaf567dfd62c", "max_forks_repo_licenses": ["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.8385365854, "max_line_length": 141, "alphanum_fraction": 0.5547066546, "num_tokens": 21246, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632896242074, "lm_q2_score": 0.7461389873857264, "lm_q1q2_score": 0.6919419058589023}} {"text": "************************************************************************\n* Transform Q0 pressure vector to L2_0\n*\n* This routine transforms the vector P into the space L2_0.\n* For this purpose, the vector AREA with the areas of all elements\n* is used. AREA(NEL+1) is assumed to be the sum of all AREA(IEL).\n*\n* In:\n* NEL - Number of elements in the geometry\n* P - array [1..NEL] of double\n* Pressure vector in the space P0, one pressure value\n* per element\n* AREA - array [1..NEL+1] of double\n* Area of all elements; AREA[NEL+1] is the sum of the\n* areas of all elements\n*\n* Out:\n* P - the modified vector\n************************************************************************\n\n SUBROUTINE TOL20A (P,AREA,NEL)\n\n IMPLICIT NONE\n \n INCLUDE 'cbasictria.inc'\n\nC parameters\n\n INTEGER INEUM, NEL\n DOUBLE PRECISION AREA(*)\n DOUBLE PRECISION P(*)\n \nC local variables\n\n DOUBLE PRECISION PINT,C\n INTEGER IEL\n\nC Build the integral\nC int_Omega p dx\nC This is approximated by\nC PINT = SUM_Elements P(Element)*Volume(Element)\n\n PINT=0D0\n DO IEL=1,NEL\n PINT=PINT+P(IEL)*AREA(IEL)\n END DO\n\nC Divide PINT by the volume of the domain; this gives the integral\nC mean value of the pressure:\n\n C = PINT/AREA(NEL+1)\n\nC Subtract the integral mean value C of the pressure from all\nC pressure components. Afterwards, P has integral mean value = 0.\n\n DO IEL=1,NEL\n P(IEL)=P(IEL)-C\n END DO\n\n END\n", "meta": {"hexsha": "bd7669aa0daf99c190d8965bd06618c079972a93", "size": 1580, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "area51/cc2d_movbc_structured_2/src/discr_nonlinear/normvectors.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/discr_nonlinear/normvectors.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/discr_nonlinear/normvectors.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": 25.9016393443, "max_line_length": 72, "alphanum_fraction": 0.5601265823, "num_tokens": 414, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563336, "lm_q2_score": 0.782662489091802, "lm_q1q2_score": 0.6919043894885821}} {"text": "\n! Program to solve the two-dimensional Ising model \n! with zero external field.\n! The coupling constant J = 1\n! Boltzmann's constant = 1, temperature has thus dimension energy\n! Metropolis sampling is used. Periodic boundary conditions.\n\nPROGRAM ising2dim\n USE constants\n USE f90library\n INTEGER :: idum, n_spins, mcs, de, t, cycles, tstep\n INTEGER, ALLOCATABLE, DIMENSION(:,:) :: spin_matrix\n REAL(dp) :: w(-8:8), average(5)\n REAL(DP) :: initial_temp, final_temp, E, M, temp_step, temperature\n\n CALL read_input(n_spins, mcs, initial_temp, final_temp, temp_step)\n ALLOCATE(spin_matrix(n_spins,n_spins))\n ! We assume that we start with the lowest temperature and that all\n ! spins are ordered. These spins are then updated with the latest value\n ! for every temperature in the loop over temperatures. The next temp step\n ! receives as input the previous spin matrix\n spin_matrix = 1\n ! Find temperature step\n tstep = INT((final_temp-initial_temp)/temp_step); temperature = initial_temp\n ! random starting point\n idum = -1 \n \n OPEN(UNIT=6,FILE='mc_calc.dat')\n DO t = 1, tstep\n ! initialise energy, magnetization and array for energy changes \n E = 0.0_dp; M = 0.0_dp; w = 0.0_dp\n DO de =-8, 8, 4 \n w(de) = EXP(-de/temperature)\n ENDDO\n ! initialise array for expectation values\n average = 0.0_dp\n CALL initialize(n_spins, temperature, spin_matrix, E, M)\n ! start Monte Carlo computation\n DO cycles = 1, mcs\n CALL Metropolis(n_spins, idum, spin_matrix, E, M, w)\n ! update expectation values\n average(1) = average(1) + E; average(2) = average(2) + E*E\n average(3) = average(3)+M; average(4) = average(4)+M*M \n average(5) = average(5)+ABS(M)\n ENDDO\n ! print results\n CALL output(n_spins, mcs, temperature, average)\n ! update temp\n temperature = temperature + temp_step\n ENDDO\n DEALLOCATE(spin_matrix)\n\nEND PROGRAM ising2dim\n!\n! read in input data\n!\nSUBROUTINE read_input(n_spins, mcs, initial_temp, final_temp, temp_step)\n USE constants\n IMPLICIT NONE\n INTEGER, INTENT(inout) :: n_spins, mcs\n REAL(dp), INTENT(inout) :: initial_temp, final_temp, temp_step\n\n WRITE(*,*) 'Number of Monte Carlo trials =' \n READ(*,*) mcs\n WRITE(*,*) 'Lattice size or number of spins (x and y equal) ='\n READ(*,*) n_spins\n WRITE(*,*) 'Initial temperature with dimension energy='\n READ(*,*) initial_temp\n WRITE(*,*) 'Final temperature with dimension energy='\n READ(*,*) final_temp\n WRITE(*,*) 'Temperature step with dimension energy='\n READ(*,*) temp_step\n\nEND SUBROUTINE read_input\n!\n! function to initialise energy, spin matrix and magnetization\n!\nSUBROUTINE initialize(n_spins, temperature, spin_matrix, E, M)\n USE constants\n IMPLICIT NONE\n INTEGER, INTENT(in) :: n_spins\n INTEGER, INTENT(inout) :: spin_matrix(n_spins, n_spins)\n REAL(dp), INTENT(in) :: temperature\n REAL(dp), INTENT(inout) :: E, M\n INTEGER :: x, y, right, left, up, down\n\n ! setup initial energy and magnetization\n DO y =1, n_spins\n DO x= 1, n_spins\n right = x+1 ; IF(x == n_spins ) right = 1 \n left = x-1 ; IF(x == 1 ) left = n_spins \n up = y+1 ; IF(y == n_spins ) up = 1 \n down = y-1 ; IF(y == 1 ) down = n_spins \n e= e-spin_matrix(x,y)*(spin_matrix(right,y)+&\n spin_matrix(left,y)+spin_matrix(x,up)+ &\n spin_matrix(x,down) )\n m = m + spin_matrix(x,y) \n ENDDO\n ENDDO\n e = e*0.5_dp\n\nEND SUBROUTINE initialize\n!\n! Here we perform the sampling\n!\nSUBROUTINE metropolis(n_spins, idum, spin_matrix, e, m, w)\n USE constants\n USE f90library\n IMPLICIT NONE\n INTEGER, INTENT(in) :: n_spins, idum\n INTEGER :: x, y, ix, iy, deltae, right, left, up, down\n INTEGER, INTENT(inout) :: spin_matrix(n_spins, n_spins)\n REAL(dp) :: e, m, w(-8:8)\n\n ! loop over all spins\n DO y =1, n_spins\n DO x= 1, n_spins\n ix = INT(ran1(idum)*n_spins)+1\n iy = INT(ran1(idum)*n_spins)+1\n right = ix+1 ; IF(ix == n_spins ) right = 1 \n left = ix-1 ; IF(ix == 1 ) left = n_spins \n up = iy+1 ; IF(iy == n_spins ) up = 1 \n down = iy-1 ; IF(iy == 1 ) down = n_spins \n deltae = 2*spin_matrix(ix,iy)*(spin_matrix(right,iy)+&\n spin_matrix(left,iy)+spin_matrix(ix,up)+ &\n spin_matrix(ix,down) )\n IF ( ran1(idum) <= w(deltae) ) THEN\n spin_matrix(ix,iy) = -spin_matrix(ix,iy) !flip one spin and accept new spin config\n m = m+2*spin_matrix(ix,iy)\n e = e+deltaE\n ENDIF\n ENDDO\n ENDDO\nEND SUBROUTINE metropolis\n!\n! Write out , , Heat capacity and susceptibility.\n!\nSUBROUTINE output(n_spins, mcs, temperature, average)\n USE constants\n IMPLICIT NONE\n INTEGER, INTENT(in) :: n_spins, mcs\n REAL(dp), INTENT(in) :: temperature, average(5)\n REAL(dp) :: norm, Eaverage, E2average, Maverage, M2average, Mabsaverage, &\n Evariance, Mvariance\n\n norm = 1.0_dp/mcs ! divided by total number of cycles \n Eaverage = average(1)*norm\n E2average = average(2)*norm\n Maverage = average(3)*norm\n M2average = average(4)*norm\n Mabsaverage = average(5)*norm\n ! all expectation values are per spin, divide by 1/n_spins/n_spins\n Evariance = (E2average- Eaverage*Eaverage)/n_spins/n_spins\n Mvariance = (M2average - Mabsaverage*Mabsaverage)/n_spins/n_spins\n WRITE(6,'(6F12.6)')temperature, Eaverage/n_spins/n_spins, Evariance/temperature/temperature, &\n Maverage/n_spins/n_spins, Mvariance/temperature, Mabsaverage/n_spins/n_spins\n\nEND SUBROUTINE output\n\n", "meta": {"hexsha": "6c2c6a1ad089c747945203795ec9e0b3f85ece92", "size": 5543, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "doc/Programs/LecturePrograms/programs/StatPhys/Fortran/ising_2dim.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/StatPhys/Fortran/ising_2dim.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/StatPhys/Fortran/ising_2dim.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.64375, "max_line_length": 96, "alphanum_fraction": 0.6568645138, "num_tokens": 1763, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392939666336, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.6919043853077301}} {"text": "program potencial\n use iso_fortran_env\n\n implicit none\n\n integer, parameter :: n = 100\n real*8, dimension(:), allocatable :: x, y, z, m, ep\n real*8, parameter :: G = 4.299e-6, eps=0.0\n real*8 :: dist\n integer :: i, j\n\n\n allocate(x(n), y(n), z(n), m(n), ep(n))\n\n !-------------leo las posiciones de las particulas---------------------\n open(20, file='../tests/test_data/mock_particles.dat', status='old')\n do i=1, n\n read(20,*) x(i), y(i), z(i), m(i)\n end do\n close(20)\n\n !======================================================================\n !Calcula la energia potencial espec\u00edfica de cada una de las particulas\n\n\n do i = 1, n\n ep(i) = 0.\n do j = 1, n\n if (i /= j) then\n\n dist = sqrt((x(i)-x(j))**2 + (y(i)-y(j))**2 + (z(i)-z(j))**2 + eps**2)\n ep(i) = ep(i) + m(j)/dist\n\n end if\n end do\n ep(i) = ep(i)*G\n end do\n !$OMP END DO\n !$OMP END PARALLEL\n\n !======================================================================\n\n !-------------escribo los potenciales de las particulas---------------------\n open(30, file='../tests/test_data/fpotential_test.dat', status='unknown')\n do i = 1,n\n write(30,*) ep(i)\n end do\n close(30)\n\n deallocate(x, y, z, m, ep)\n\n end program\n", "meta": {"hexsha": "8a8f4b03999d530c9a1a5da29687d8ba566c3ab0", "size": 1451, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "resource/potential_test.f90", "max_stars_repo_name": "vcristiani/galaxy-chop", "max_stars_repo_head_hexsha": "6a854ee8701001ab0f15d6b0112401c123d0c6b2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-09-25T19:31:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-09T19:47:46.000Z", "max_issues_repo_path": "resource/potential_test.f90", "max_issues_repo_name": "vcristiani/galaxy-chop", "max_issues_repo_head_hexsha": "6a854ee8701001ab0f15d6b0112401c123d0c6b2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 98, "max_issues_repo_issues_event_min_datetime": "2020-10-05T20:52:22.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-11T15:28:43.000Z", "max_forks_repo_path": "resource/potential_test.f90", "max_forks_repo_name": "vcristiani/galaxy-chop", "max_forks_repo_head_hexsha": "6a854ee8701001ab0f15d6b0112401c123d0c6b2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-17T23:07:33.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-17T23:07:33.000Z", "avg_line_length": 27.3773584906, "max_line_length": 98, "alphanum_fraction": 0.399724328, "num_tokens": 399, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.884039278690883, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.691904368870396}} {"text": "C=======================================================================\nC VPSAT, Real Function, N.B. Pickering, 4/1/90\nC Calculates saturated vapor pressure of air (Tetens, 1930).\n!-----------------------------------------------------------------------\n! Called by: CANPET, HMET, VPSLOP, PETPEN\n! Calls: None\n!-----------------------------------------------------------------------\nC Input : T (C)\nC Output: VPSAT (Pa)\nC=======================================================================\n\n REAL FUNCTION VPSAT(T)\n\n IMPLICIT NONE\n REAL T\n\n VPSAT = 610.78 * EXP(17.269*T/(T+237.30))\n\n RETURN\n END FUNCTION VPSAT\nC=======================================================================\n! VPSAT Variables\n!-----------------------------------------------------------------------\n! T Air temperature (oC)\n! VPSAT Saturated vapor pressure of air (Pa)\nC=======================================================================\n\n\n\nC=======================================================================\nC VPSLOP, Real Function, N.B. Pickering, 4/1/90\nC Calculates slope of saturated vapor pressure versus temperature curve\nC using Classius-Clapeyron equation (see Brutsaert, 1982 p. 41)\n!-----------------------------------------------------------------------\n! Called by: ETSOLV, PETPEN, TRATIO\n! Calls: VPSAT\n!-----------------------------------------------------------------------\nC Input : T (C)\nC Output: VPSLOP\nC=======================================================================\n\n REAL FUNCTION VPSLOP(T)\n\n IMPLICIT NONE\n\n REAL T,VPSAT\n\nC dEsat/dTempKel = MolWeightH2O * LatHeatH2O * Esat / (Rgas * TempKel^2)\n\n VPSLOP = 18.0 * (2501.0-2.373*T) * VPSAT(T) / (8.314*(T+273.0)**2)\n\n RETURN\n END FUNCTION VPSLOP\nC=======================================================================\n! VPSLOP variables\n!-----------------------------------------------------------------------\n! T Air temperature (oC)\n! VPSAT Saturated vapor pressure of air (Pa)\n! VPSLOP Slope of saturated vapor pressure versus temperature curve\nC=======================================================================\n\n\nC=======================================================================\nC PETDYN Subroutine, K. J. BOOTE, F. SAU, M. BOSTIC\nC Calculates PENMAN-MONTEITH potential evapotranspiration\nC using dynamic CANHT, LAI, along with wind effects on Ra, Rs\nC Steiner approach for Ra recommended, but FAO and Lhomme commented out\nC Sunlit LAI effect on Rs is recommended, but rl/(0.5*LAI) would work\nC Weighting used for Ra and Rs between soil and crop. Need to changee\nC two constants (HTS and zos) if you change from sunlit LAI to other.\nC-----------------------------------------------------------------------\nC REVISION HISTORY\nC 11/19/01 TO 1/15/02 Written By Boote, Sau, McNair\nC 01/15/03 Moved from V3.5 trial to V4.0 by K. J. Boote\n! 07/24/2006 CHP Use MSALB instead of SALB (includes mulch and soil \n! water effects on albedo)\n\n! Called from: PET\n! Calls: None\nC=======================================================================\n SUBROUTINE PETDYN(\n & CANHT, CLOUDS, MSALB, SRAD, TAVG, TDEW, !Input\n & TMAX, TMIN, WINDSP, XHLAI, !Input\n & EO) !Output\nC Calculates Penman-Monteith evapotranspiration\n!-----------------------------------------------------------------------\n IMPLICIT NONE\n SAVE\n!-----------------------------------------------------------------------\n! INPUT VARIABLES:\n REAL CLOUDS, MSALB, SRAD, TAVG, TDEW, TMAX, TMIN,\n & WINDSP, XHLAI, WINDSP_M\n!-----------------------------------------------------------------------\n! OUTPUT VARIABLES:\n REAL EO\n!-----------------------------------------------------------------------\n! LOCAL VARIABLES:\n REAL ALBEDO, EAIR, ESAT, G, LHVAP, PSYCON, RADB,\n & RNET, RNETMG, S, TK4,\n & VHCAIR, VPD, DAIR, RT\n REAL SHAIR, PATM, SBZCON\n REAL k,DFAO, CANHT, ZOMF, ZOHF, ra, rl, rs, RAERO !add for PenDyn\n REAL ZCROP,DCROP,ZOMC,ZOVC,WIND2C,RASOIL,HTS,DLH,ZOLH\n REAL MAXHT, rb, AC, AS_MOD, zos, RTOT !add for PenDyn\nC PARAMETER (SHAIR = 1005.0)\n PARAMETER (SHAIR = 0.001005) !changed for PenDyn to MJ/kg/K\n PARAMETER (PATM = 101300.0)\n! PARAMETER (SBZCON=4.093E-9) !(MJ/m2/d)\n PARAMETER (SBZCON=4.903E-9) !(MJ/K4/m2/d) fixed constant 5/6/02\n!-----------------------------------------------------------------------\n! FUNCTION SUBROUTINES:\n REAL VPSLOP, VPSAT !Found in file HMET.for\n\nC-----------------------------------------------------------------------\nC Compute air properties.\n LHVAP = (2501.0-2.373*TAVG) * 1000.0 ! J/kg\nC PSYCON = SHAIR * PATM / (0.622*LHVAP) ! Pa/K\n PSYCON = SHAIR * PATM / (0.622*LHVAP) * 1000000 ! Pa/K\n ESAT = (VPSAT(TMAX)+VPSAT(TMIN)) / 2.0 ! Pa\n EAIR = VPSAT(TDEW) ! Pa\n VPD = ESAT - EAIR ! Pa\n S = (VPSLOP(TMAX)+VPSLOP(TMIN)) / 2.0 ! Pa/K\n RT = 8.314 * (TAVG + 273.0) ! N.m/mol\n DAIR = 0.028966*(PATM-0.387*EAIR)/RT ! kg/m3\nC BAD DAIR = 0.1 * 18.0 / RT * ((PATM -EAIR)/0.622 + EAIR) ! kg/m3\n VHCAIR = DAIR * SHAIR !not used ! J/m3\n\nC Convert windspeed to 2 m reference height.\n! Do this conversion in WEATHR and send out 2m windspeed\n! CHP 11/26/01\n! WIND2 = WINDSP * (2.0/WINDHT)**0.2\n\nC Calculate aerodynamic resistance (ra).\nC ra (d/m) = {ln[zm-d/zom]*ln[zh-d/zoh]}/(k^2*uz)\nC zm = ht.wind measurement (m), zh = ht.humidity measurement (m),\nC zom,zoh=rooughness length of momentum, heat and vapor x-fer (m)\nC k=von Karman's constant 0.41, uz=WINDSP @ z m/d,\nC d = zero plane displacement height (m)\n\n WINDSP_M = WINDSP*(1000.)/86400. !Converts km/d to m/s\n k = 0.41 !von Karman's constant\n\n IF (CANHT .LE. 0.10) THEN\n ZCROP = 2.0 + 0.10\nC Next 3 are Steiner et al. coefficients, used for Steiner Ra\n DCROP = 0.75 * 0.10\n ZOMC = 0.25 * (0.10 - DCROP)\n ZOVC = 0.1 * ZOMC\n DFAO = 2. * 0.10 / 3.0\n ZOMF = 0.123*0.10\n ZOHF = 0.1*ZOMF\n\n ELSE\n ZCROP = 2.0 + CANHT\n DCROP = 0.75 * CANHT\n ZOMC = 0.25 * (CANHT - DCROP)\n ZOVC = 0.1 * ZOMC\n DFAO= 2.0 * CANHT / 3.0\n ZOMF = 0.123*CANHT\n ZOHF = 0.1*ZOMF\n ENDIF\n\nC LHOMME ET AL. AG & FOR. MET. 104:119. 2000.\nC Combined effects of LAI and crop height on Ra\nC cd = 0.2 (in eq below), where X=0.2*LAI\nC Zolh up to X<0.2 (or LAI=1), then X 0.2 to 1.5 (LAI=7.5)\nC Actually should have a cap at LAI 7.5 or less.\n\n DLH = 1.1*MAX(0.10,CANHT)*LOG(1.+(0.2*XHLAI)**0.25)\n\n IF (XHLAI .LT. 1.0) THEN\n ZOLH = 0.01+0.3*MAX(0.10,CANHT)*(0.2*XHLAI)**0.5\n ELSE\nC ELSEIF (XHLAI .LT. 7.5)\n ZOLH = 0.3*MAX(0.10,CANHT)*(1.0-DLH/MAX(0.10,CANHT))\n ENDIF\n\nC Concept of Ra, always for 2 m above crop height, from Steiner et al\nC Agron. J. 83:240. 1991. Also, needs wind speed adjusted, up to\nC 10 m, then back down to exactly 2 m above crop height.\nC Needs z defined at 2 m above crop, or z = 2.0 + CANHT\nC Grass assumed 0.10 m, its d is 0.075, its Zom is 0.00625\n\n WIND2C = WINDSP_M * LOG((10.-0.075)/0.00625) *\n & LOG((ZCROP-DCROP)/ZOMC) /\n & (LOG((10.-DCROP)/ZOMC)*LOG((2.-0.075)/0.00625))\n\nC Steiner Ra\n ra = ( (LOG((ZCROP-DCROP)/ZOMC)*LOG((ZCROP-DCROP)/ZOVC))\n & /((k**2)*WIND2C) ) /86400\n\nC Standard FAO Ra\nC ra = ( (LOG((ZCROP-DFAO)/ZOMF)*LOG((ZCROP-DFAO)/ZOHF))\nC & /((k**2)*WIND2C) ) /86400\n\nC Lhomme Ra\nC ra = ( (LOG((ZCROP-DLH)/ZOLH)*LOG((ZCROP-DLH)/(0.1*ZOLH)))\nC & /((k**2)*WIND2C) ) /86400\n\nC NOW, COMPUTING Ra for bare soil and Rs for bare soil\nC For bare soil Ra, with an effective height of 0.40 m\nC Uses standard FAO eq, windsp for 2 m height. Not for soil Rs\nC HTS = 0.13, for SUNLIT LAI FORM. HTS = 0.25 for 0.5*LAI FORM.\n\n HTS = 0.13\nC HTS = 0.25\n RASOIL = ( (LOG((2.0-2*HTS/3.)/(0.123*HTS))\n & *LOG((2.0-2*HTS/3.)/(0.1*0.123*HTS)))/((k**2)*WINDSP_M))/86400\n\nCWMB BOUNDARY LAYER RESISTANCE (rb) FOR BARE SOIL FROM (JAGTAP AND JONES, 1989)\nC zos = roughness ht. of soil (m), MAXHT = maximum plant height (m)\nC MAXHT is a dummy argument to get right Rs from soil. Not real\nC This is wet surface resistance, Rs-soil, to match up with Rs-crop\nC Do not want WIND2C, as this one acts most for bare soil, no crop\nC\nC For Sunlit LAI for Rc, use zos = 0.01\nC For 0.5*LAI for Rc, need zos = 0.03\n zos = 0.01\nC zos = 0.03\n MAXHT = 1.0\n rb=((log(2.0/zos)*log((0.83*MAXHT)/zos))/\n & ((k**2)*WINDSP_M))/86400\nC\n\nC Using K = 0.5 everywhere possible\n AC = 1-exp(-0.50*XHLAI)\n AS_MOD = 1 - AC\n\n RAERO = AC*RA + AS_MOD*RASOIL\nC Calculate surface resistance (rs).\nC rs = rl/LAIactive rs (s m^-1),\nC rl = bulk stomatal resistance of the well-illuminated leaf (s m^-1)\n\n rl = 100 !value assummed from FAO grass reference\n IF (XHLAI .GE. 0.1) THEN\nC rs = rl/(0.5*XHLAI)\n rs = rl/((1/0.5)*(1.0-EXP(-0.5*XHLAI))) !SUNLIT LAI form\n ELSE\n rs = rl/(0.5*0.1)\n ENDIF\n \n rs = rs/86400 !converts (s m^-1 to d/m)\n\n RTOT = AC*rs + AS_MOD*rb\n\nC Calculate net radiation (MJ/m2/d). By FAO method 1990. EAIR is divided\nC by 1000 to convert Pa to KPa.\n\n G = 0.0\n IF (XHLAI .LE. 0.0) THEN\n ALBEDO = MSALB\n ELSE\nC I THINK THIS K VALUE SHOULD BE 0.5, NEAR THEORETICAL OF 0.5 KJB\n ALBEDO = 0.23-(0.23-MSALB)*EXP(-0.75*XHLAI)\n ENDIF\n\n TK4 = ((TMAX+273.)**4+(TMIN+273.)**4) / 2.0\n RADB = SBZCON * TK4 * (0.34 - 0.14 * SQRT(EAIR/1000)) *\n & (1.35 * (1. - CLOUDS) - 0.35)\n RNET= (1.0-ALBEDO)*SRAD - RADB\n\nC Compute EO using Penman-Montieth\n\n RNETMG = (RNET-G)\nC !MJ/m2/d\n EO=((S*RNETMG + (DAIR*SHAIR*VPD)/RAERO)/(S+PSYCON*(1+RTOT/RAERO))) \nC !Converts MJ/m2/d to mm/d\n EO = EO/ (LHVAP / 1000000.)\n!### EO = MAX(EO,0.0) !gives error in DECRAT_C\n EO = MAX(EO,0.0001)\n\n!-----------------------------------------------------------------------\n RETURN\n END SUBROUTINE PETDYN\n\n! PETPEN VARIABLES: Nearly same as PETPEN above\n", "meta": {"hexsha": "f60fb2a68a6ec81765cd6a2b16e1e61aa92c1ef1", "size": 10812, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "tests/data/program_analysis/PETDYN.for", "max_stars_repo_name": "mwdchang/delphi", "max_stars_repo_head_hexsha": "c6177f2d614118883eaaa7f5300f3e46f10ddc7e", "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/program_analysis/PETDYN.for", "max_issues_repo_name": "mwdchang/delphi", "max_issues_repo_head_hexsha": "c6177f2d614118883eaaa7f5300f3e46f10ddc7e", "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/program_analysis/PETDYN.for", "max_forks_repo_name": "mwdchang/delphi", "max_forks_repo_head_hexsha": "c6177f2d614118883eaaa7f5300f3e46f10ddc7e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-07-18T19:13:13.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-18T19:13:13.000Z", "avg_line_length": 39.0324909747, "max_line_length": 82, "alphanum_fraction": 0.4725305216, "num_tokens": 3587, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109798251322, "lm_q2_score": 0.7279754607093178, "lm_q1q2_score": 0.6918758709013948}} {"text": "C/MEMBR ADD NAME=URAND,SSI=0\n double precision function urand(iy)\n integer iy\n save\nc!purpose\nc\nc urand is a uniform random number generator based on theory and\nc suggestions given in d.e. knuth (1969), vol 2. the integer iy\nc should be initialized to an arbitrary integer prior to the first call\nc to urand. the calling program should not alter the value of iy\nc between subsequent calls to urand. values of urand will be returned\nc in the interval (0,1).\nc\nc!calling sequence\nc double precision function urand(iy)\nc integer iy\nc!\ncc symbolics version\nc double precision function urand(iy)\nc integer iy\nc lispfunction random 'cl-user::random' (integer) integer\nc urand=dble(real(random(2**31)))/(dble(real(2**31))-1.0d+0)\nc return\nc end\ncc end\nc\n integer ia,ic,itwo,m2,m,mic\n double precision halfm,s\n data m2/0/,itwo/2/\n if (m2 .ne. 0) go to 20\nc\nc if first entry, compute machine integer word length\nc\n m = 1\n 10 m2 = m\n m = itwo*m2\n if (m .gt. m2) go to 10\n halfm = m2\nc\nc compute multiplier and increment for linear congruential method\nc\n ia = 8*nint(halfm*atan(1.0d+0)/8.0d+0) + 5\n ic = 2*nint(halfm*(0.50d+0-sqrt(3.0d+0)/6.0d+0)) + 1\n mic = (m2 - ic) + m2\nc\nc s is the scale factor for converting to floating point\nc\n s = 0.50d+0/halfm\nc\nc compute next random number\nc\n 20 iy = iy*ia\nc\nc the following statement is for computers which do not allow\nc integer overflow on addition\nc\n if (iy .gt. mic) iy = (iy - m2) - m2\nc\n iy = iy + ic\nc\nc the following statement is for computers where the\nc word length for addition is greater than for multiplication\nc\n if (iy/2 .gt. m2) iy = (iy - m2) - m2\nc\nc the following statement is for computers where integer\nc overflow affects the sign bit\nc\n if (iy .lt. 0) iy = (iy + m2) + m2\n urand = dble(iy)*s\n return\n end\n", "meta": {"hexsha": "62b83b458626cacf885c8bd7625b9d9af5e25fd2", "size": 1954, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/calelm/urand.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/urand.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/urand.f", "max_forks_repo_name": "alpgodev/numx", "max_forks_repo_head_hexsha": "d2d3a0713020e1b83b65d3a661c3801ea256aff9", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.7671232877, "max_line_length": 72, "alphanum_fraction": 0.6484135107, "num_tokens": 679, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473813156294, "lm_q2_score": 0.793105953629227, "lm_q1q2_score": 0.6918639017542911}} {"text": "*dk,primestep\n subroutine primestep(m,n)\nC #####################################################################\nC\nC PURPOSE -\nC\nC Given a positive integer M, repeated calls to PRIMESTEP\nC produce a complete permutation of the integers {1,...,M}.\nC Then, when that permutation is finished, a different\nC permutation is generated, and so on.\nC The permutations are derived by taking jumps by\nC a prime number that doesn't divide into M. The\nC purpose of this is to produce 'good' sequences of\nC nodes for Gauss-Seidel relaxation.\nC\nC INPUT ARGUMENTS -\nC\nC M - The length of the sequence to be permuted\nC\nC INPUT/OUTPUT ARGUMENTS -\nC\nC N - The next element in the permutation.\nC\nC CHANGE HISTORY -\nC\nC $Log: primestep.f,v $\nC Revision 2.00 2007/11/09 20:03:58 spchu\nC Import to CVS\nC\nCPVCS \nCPVCS Rev 1.2 Fri Dec 18 17:43:14 1998 kuprat\nCPVCS Corrected documentation.\nCPVCS \nCPVCS Rev 1.1 Fri Nov 13 15:43:00 1998 kuprat\nCPVCS We now start afresh if we notice the user has changed the \nCPVCS length of the array to be permuted.\nCPVCS \nCPVCS Rev 1.0 Wed Nov 04 02:43:34 1998 kuprat\nCPVCS Initial revision.\nC#######################################################################\n \n integer m,n\n \n integer mp\n parameter (mp=10)\n \n integer iprime(10),np\n \nc.... IPRIME contains the choices of primes for stepping through\nc.... the sequence.\n \n data iprime / 17,19,23,29,31,37,41,43,47,53 /\n \n data np / 0 /\n data mlast / 0 /\n save iprime,np,inext,mlast\n \nc.... Check if M is different from MLAST. If this is so, then this \nc.... is either the initial invocation, or the user has changed the\nc.... length of the array we are permuting. In either case, set\nc.... INEXT to 1, meaning we want the first element of a fresh\nc.... permutation. If M is the same as MLAST, increment INEXT to \nc.... get the next element of the permutation.\n\n if (m.ne.mlast) then\n inext=1\n mlast=m\n else\n inext=mod(inext,m)+1 \n endif\n\nc.... If INEXT is 1, we need to find a new prime that doesn't divide M\nc.... to generate a fresh permutation.\n\n if (inext.eq.1) then\n np=mod(np,mp)+1\n itried=0\n do while (mod(m,iprime(np)).eq.0)\n np=mod(np,mp)+1\n itried=itried+1\n if (itried.eq.mp) then\n print*,'PRIMESTEP: All primes divide ',m\n stop\n endif\n enddo\n endif\n\nc.... Generate the next element of the permutation.\n \n n=mod(inext*iprime(np),m)+1\n \n return\n end\n \n", "meta": {"hexsha": "3dad5cd510ff3e5cd1090f0828bed196481fd76b", "size": 2727, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/primestep.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/primestep.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/primestep.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": 28.7052631579, "max_line_length": 72, "alphanum_fraction": 0.5764576458, "num_tokens": 778, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.6918638879581546}} {"text": "C\nC file hstcyl.f\nC\n SUBROUTINE HSTCYL (A,B,M,MBDCND,BDA,BDB,C,D,N,NBDCND,BDC,BDD,\n 1 ELMBDA,F,IDIMF,PERTRB,IERROR,W)\nC\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC * *\nC * copyright (c) 1999 by UCAR *\nC * *\nC * UNIVERSITY CORPORATION for ATMOSPHERIC RESEARCH *\nC * *\nC * all rights reserved *\nC * *\nC * FISHPACK version 4.1 *\nC * *\nC * A PACKAGE OF FORTRAN SUBPROGRAMS FOR THE SOLUTION OF *\nC * *\nC * SEPARABLE ELLIPTIC PARTIAL DIFFERENTIAL EQUATIONS *\nC * *\nC * BY *\nC * *\nC * JOHN ADAMS, PAUL SWARZTRAUBER AND ROLAND SWEET *\nC * *\nC * OF *\nC * *\nC * THE NATIONAL CENTER FOR ATMOSPHERIC RESEARCH *\nC * *\nC * BOULDER, COLORADO (80307) U.S.A. *\nC * *\nC * WHICH IS SPONSORED BY *\nC * *\nC * THE NATIONAL SCIENCE FOUNDATION *\nC * *\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC\nC\nC\nC DIMENSION OF BDA(N),BDB(N),BDC(M),BDD(M),F(IDIMF,N),\nC ARGUMENTS W(SEE ARGUMENT LIST)\nC\nC LATEST REVISION NOVEMBER 1988\nC\nC PURPOSE SOLVES THE STANDARD FIVE-POINT FINITE\nC DIFFERENCE APPROXIMATION ON A STAGGERED\nC GRID TO THE MODIFIED HELMHOLTZ EQUATION\nC IN CYLINDRICAL COORDINATES. THIS EQUATION\nC\nC (1/R)(D/DR)(R(DU/DR)) + (D/DZ)(DU/DZ)\nC\nC + LAMBDA*(1/R**2)*U = F(R,Z)\nC\nC IS A TWO-DIMENSIONAL MODIFIED HELMHOLTZ\nC EQUATION RESULTING FROM THE FOURIER TRANSFORM\nC OF A THREE-DIMENSIONAL POISSON EQUATION.\nC\nC USAGE CALL HSTCYL (A,B,M,MBDCND,BDA,BDB,C,D,N,\nC NBDCND,BDC,BDD,ELMBDA,F,IDIMF,\nC PERTRB,IERROR,W)\nC\nC ARGUMENTS\nC ON INPUT A,B\nC\nC THE RANGE OF R, I.E. A .LE. R .LE. B.\nC A MUST BE LESS THAN B AND A MUST BE\nC BE NON-NEGATIVE.\nC\nC M\nC THE NUMBER OF GRID POINTS IN THE INTERVAL\nC (A,B). THE GRID POINTS IN THE R-DIRECTION\nC R-DIRECTION ARE GIVEN BY\nC R(I) = A + (I-0.5)DR FOR I=1,2,...,M\nC WHERE DR =(B-A)/M.\nC M MUST BE GREATER THAN 2.\nC\nC MBDCND\nC INDICATES THE TYPE OF BOUNDARY CONDITIONS\nC AT R = A AND R = B.\nC\nC = 1 IF THE SOLUTION IS SPECIFIED AT R = A\nC (SEE NOTE BELOW) AND R = B.\nC\nC = 2 IF THE SOLUTION IS SPECIFIED AT R = A\nC (SEE NOTE BELOW) AND THE DERIVATIVE\nC OF THE SOLUTION WITH RESPECT TO R IS\nC SPECIFIED AT R = B.\nC\nC = 3 IF THE DERIVATIVE OF THE SOLUTION\nC WITH RESPECT TO R IS SPECIFIED AT\nC R = A (SEE NOTE BELOW) AND R = B.\nC\nC = 4 IF THE DERIVATIVE OF THE SOLUTION\nC WITH RESPECT TO R IS SPECIFIED AT\nC R = A (SEE NOTE BELOW) AND THE\nC SOLUTION IS SPECIFIED AT R = B.\nC\nC = 5 IF THE SOLUTION IS UNSPECIFIED AT\nC R = A = 0 AND THE SOLUTION IS\nC SPECIFIED AT R = B.\nC\nC = 6 IF THE SOLUTION IS UNSPECIFIED AT\nC R = A = 0 AND THE DERIVATIVE OF THE\nC SOLUTION WITH RESPECT TO R IS SPECIFIED\nC AT R = B.\nC\nC NOTE:\nC IF A = 0, DO NOT USE MBDCND = 1,2,3, OR 4,\nC BUT INSTEAD USE MBDCND = 5 OR 6.\nC THE RESULTING APPROXIMATION GIVES THE ONLY\nC MEANINGFUL BOUNDARY CONDITION,\nC I.E. DU/DR = 0.\nC (SEE D. GREENSPAN, 'INTRODUCTORY NUMERICAL\nC ANALYSIS OF ELLIPTIC BOUNDARY VALUE\nC PROBLEMS,' HARPER AND ROW, 1965, CHAPTER 5.)\nC\nC BDA\nC A ONE-DIMENSIONAL ARRAY OF LENGTH N THAT\nC SPECIFIES THE BOUNDARY VALUES (IF ANY)\nC OF THE SOLUTION AT R = A.\nC\nC WHEN MBDCND = 1 OR 2,\nC BDA(J) = U(A,Z(J)) , J=1,2,...,N.\nC\nC WHEN MBDCND = 3 OR 4,\nC BDA(J) = (D/DR)U(A,Z(J)) , J=1,2,...,N.\nC\nC WHEN MBDCND = 5 OR 6, BDA IS A DUMMY\nC VARIABLE.\nC\nC BDB\nC A ONE-DIMENSIONAL ARRAY OF LENGTH N THAT\nC SPECIFIES THE BOUNDARY VALUES OF THE\nC SOLUTION AT R = B.\nC\nC WHEN MBDCND = 1,4,OR 5,\nC BDB(J) = U(B,Z(J)) , J=1,2,...,N.\nC\nC WHEN MBDCND = 2,3, OR 6,\nC BDB(J) = (D/DR)U(B,Z(J)) , J=1,2,...,N.\nC\nC C,D\nC THE RANGE OF Z, I.E. C .LE. Z .LE. D.\nC C MUST BE LESS THAN D.\nC\nC N\nC THE NUMBER OF UNKNOWNS IN THE INTERVAL\nC (C,D). THE UNKNOWNS IN THE Z-DIRECTION\nC ARE GIVEN BY Z(J) = C + (J-0.5)DZ,\nC J=1,2,...,N, WHERE DZ = (D-C)/N.\nC N MUST BE GREATER THAN 2.\nC\nC NBDCND\nC INDICATES THE TYPE OF BOUNDARY CONDITIONS\nC AT Z = C AND Z = D.\nC\nC = 0 IF THE SOLUTION IS PERIODIC IN Z, I.E.\nC U(I,J) = U(I,N+J).\nC\nC = 1 IF THE SOLUTION IS SPECIFIED AT Z = C\nC AND Z = D.\nC\nC = 2 IF THE SOLUTION IS SPECIFIED AT Z = C\nC AND THE DERIVATIVE OF THE SOLUTION WITH\nC RESPECT TO Z IS SPECIFIED AT Z = D.\nC\nC = 3 IF THE DERIVATIVE OF THE SOLUTION WITH\nC RESPECT TO Z IS SPECIFIED AT Z = C\nC AND Z = D.\nC\nC = 4 IF THE DERIVATIVE OF THE SOLUTION WITH\nC RESPECT TO Z IS SPECIFIED AT Z = C AND\nC THE SOLUTION IS SPECIFIED AT Z = D.\nC\nC BDC\nC A ONE DIMENSIONAL ARRAY OF LENGTH M THAT\nC SPECIFIES THE BOUNDARY VALUES OF THE\nC SOLUTION AT Z = C.\nC\nC WHEN NBDCND = 1 OR 2,\nC BDC(I) = U(R(I),C) , I=1,2,...,M.\nC\nC WHEN NBDCND = 3 OR 4,\nC BDC(I) = (D/DZ)U(R(I),C), I=1,2,...,M.\nC\nC WHEN NBDCND = 0, BDC IS A DUMMY VARIABLE.\nC\nC BDD\nC A ONE-DIMENSIONAL ARRAY OF LENGTH M THAT\nC SPECIFIES THE BOUNDARY VALUES OF THE\nC SOLUTION AT Z = D.\nC\nC WHEN NBDCND = 1 OR 4,\nC BDD(I) = U(R(I),D) , I=1,2,...,M.\nC\nC WHEN NBDCND = 2 OR 3,\nC BDD(I) = (D/DZ)U(R(I),D) , I=1,2,...,M.\nC\nC WHEN NBDCND = 0, BDD IS A DUMMY VARIABLE.\nC\nC ELMBDA\nC THE CONSTANT LAMBDA IN THE MODIFIED\nC HELMHOLTZ EQUATION. IF LAMBDA IS GREATER\nC THAN 0, A SOLUTION MAY NOT EXIST.\nC HOWEVER, HSTCYL WILL ATTEMPT TO FIND A\nC SOLUTION. LAMBDA MUST BE ZERO WHEN\nC MBDCND = 5 OR 6.\nC\nC F\nC A TWO-DIMENSIONAL ARRAY THAT SPECIFIES\nC THE VALUES OF THE RIGHT SIDE OF THE\nC MODIFIED HELMHOLTZ EQUATION.\nC FOR I=1,2,...,M AND J=1,2,...,N\nC F(I,J) = F(R(I),Z(J)) .\nC F MUST BE DIMENSIONED AT LEAST M X N.\nC\nC IDIMF\nC THE ROW (OR FIRST) DIMENSION OF THE ARRAY\nC F AS IT APPEARS IN THE PROGRAM CALLING\nC HSTCYL. THIS PARAMETER IS USED TO SPECIFY\nC THE VARIABLE DIMENSION OF F. IDIMF MUST\nC BE AT LEAST M.\nC\nC W\nC A ONE-DIMENSIONAL ARRAY THAT MUST BE\nC PROVIDED BY THE USER FOR WORK SPACE. W MAY\nC REQUIRE UP TO 13M + 4N + M*INT(LOG2(N))\nC LOCATIONS. THE ACTUAL NUMBER OF LOCATIONS\nC USED IS COMPUTED BY HSTCYL AND IS RETURNED\nC IN THE LOCATION W(1).\nC\nC ON OUTPUT\nC\nC F\nC CONTAINS THE SOLUTION U(I,J) OF THE FINITE\nC DIFFERENCE APPROXIMATION FOR THE GRID POINT\nC (R(I),Z(J)) FOR I=1,2,...,M, J=1,2,...,N.\nC\nC PERTRB\nC IF A COMBINATION OF PERIODIC, DERIVATIVE,\nC OR UNSPECIFIED BOUNDARY CONDITIONS IS\nC SPECIFIED FOR A POISSON EQUATION\nC (LAMBDA = 0), A SOLUTION MAY NOT EXIST.\nC PERTRB IS A CONSTANT, CALCULATED AND\nC SUBTRACTED FROM F, WHICH ENSURES THAT A\nC SOLUTION EXISTS. HSTCYL THEN COMPUTES\nC THIS SOLUTION, WHICH IS A LEAST SQUARES\nC SOLUTION TO THE ORIGINAL APPROXIMATION.\nC THIS SOLUTION PLUS ANY CONSTANT IS ALSO\nC A SOLUTION; HENCE, THE SOLUTION IS NOT\nC UNIQUE. THE VALUE OF PERTRB SHOULD BE\nC SMALL COMPARED TO THE RIGHT SIDE F.\nC OTHERWISE, A SOLUTION IS OBTAINED TO AN\nC ESSENTIALLY DIFFERENT PROBLEM.\nC THIS COMPARISON SHOULD ALWAYS BE MADE TO\nC INSURE THAT A MEANINGFUL SOLUTION HAS BEEN\nC OBTAINED.\nC\nC IERROR\nC AN ERROR FLAG THAT INDICATES INVALID INPUT\nC PARAMETERS. EXCEPT TO NUMBERS 0 AND 11,\nC A SOLUTION IS NOT ATTEMPTED.\nC\nC = 0 NO ERROR\nC\nC = 1 A .LT. 0\nC\nC = 2 A .GE. B\nC\nC = 3 MBDCND .LT. 1 OR MBDCND .GT. 6\nC\nC = 4 C .GE. D\nC\nC = 5 N .LE. 2\nC\nC = 6 NBDCND .LT. 0 OR NBDCND .GT. 4\nC\nC = 7 A = 0 AND MBDCND = 1,2,3, OR 4\nC\nC = 8 A .GT. 0 AND MBDCND .GE. 5\nC\nC = 9 M .LE. 2\nC\nC = 10 IDIMF .LT. M\nC\nC = 11 LAMBDA .GT. 0\nC\nC = 12 A=0, MBDCND .GE. 5, ELMBDA .NE. 0\nC\nC SINCE THIS IS THE ONLY MEANS OF INDICATING\nC A POSSIBLY INCORRECT CALL TO HSTCYL, THE\nC USER SHOULD TEST IERROR AFTER THE CALL.\nC\nC W\nC W(1) CONTAINS THE REQUIRED LENGTH OF W.\nC\nC I/O NONE\nC\nC PRECISION SINGLE\nC\nC REQUIRED LIBRARY COMF, GENBUN, GNBNAUX, AND POISTG\nC FILES FROM FISHPACK\nC\nC LANGUAGE FORTRAN\nC\nC HISTORY WRITTEN BY ROLAND SWEET AT NCAR IN 1977.\nC RELEASED ON NCAR'S PUBLIC SOFTWARE LIBRARIES\nC IN JANUARY 1980.\nC\nC PORTABILITY FORTRAN 77\nC\nC ALGORITHM THIS SUBROUTINE DEFINES THE FINITE-DIFFERENCE\nC EQUATIONS, INCORPORATES BOUNDARY DATA, ADJUSTS\nC THE RIGHT SIDE WHEN THE SYSTEM IS SINGULAR AND\nC CALLS EITHER POISTG OR GENBUN WHICH SOLVES THE\nC LINEAR SYSTEM OF EQUATIONS.\nC\nC TIMING FOR LARGE M AND N, THE OPERATION COUNT\nC IS ROUGHLY PROPORTIONAL TO M*N*LOG2(N).\nC\nC ACCURACY THE SOLUTION PROCESS RESULTS IN A LOSS\nC OF NO MORE THAN FOUR SIGNIFICANT DIGITS\nC FOR N AND M AS LARGE AS 64.\nC MORE DETAILED INFORMATION ABOUT ACCURACY\nC CAN BE FOUND IN THE DOCUMENTATION FOR\nC SUBROUTINE POISTG WHICH IS THE ROUTINE THAT\nC ACTUALLY SOLVES THE FINITE DIFFERENCE\nC EQUATIONS.\nC\nC REFERENCES U. SCHUMANN AND R. SWEET, \"A DIRECT METHOD FOR\nC THE SOLUTION OF POISSON'S EQUATION WITH NEUMANN\nC BOUNDARY CONDITIONS ON A STAGGERED GRID OF\nC ARBITRARY SIZE,\" J. COMP. PHYS. 20(1976),\nC PP. 171-182.\nC***********************************************************************\n DIMENSION F(IDIMF,1) ,BDA(*) ,BDB(*) ,BDC(*) ,\n 1 BDD(*) ,W(*)\nC\n IERROR = 0\n IF (A .LT. 0.) IERROR = 1\n IF (A .GE. B) IERROR = 2\n IF (MBDCND.LE.0 .OR. MBDCND.GE.7) IERROR = 3\n IF (C .GE. D) IERROR = 4\n IF (N .LE. 2) IERROR = 5\n IF (NBDCND.LT.0 .OR. NBDCND.GE.5) IERROR = 6\n IF (A.EQ.0. .AND. MBDCND.NE.5 .AND. MBDCND.NE.6) IERROR = 7\n IF (A.GT.0. .AND. MBDCND.GE.5) IERROR = 8\n IF (IDIMF .LT. M) IERROR = 10\n IF (M .LE. 2) IERROR = 9\n IF (A.EQ.0. .AND. MBDCND.GE.5 .AND. ELMBDA.NE.0.) IERROR = 12\n IF (IERROR .NE. 0) RETURN\n DELTAR = (B-A)/FLOAT(M)\n DLRSQ = DELTAR**2\n DELTHT = (D-C)/FLOAT(N)\n DLTHSQ = DELTHT**2\n NP = NBDCND+1\nC\nC DEFINE A,B,C COEFFICIENTS IN W-ARRAY.\nC\n IWB = M\n IWC = IWB+M\n IWR = IWC+M\n DO 101 I=1,M\n J = IWR+I\n W(J) = A+(FLOAT(I)-0.5)*DELTAR\n W(I) = (A+FLOAT(I-1)*DELTAR)/(DLRSQ*W(J))\n K = IWC+I\n W(K) = (A+FLOAT(I)*DELTAR)/(DLRSQ*W(J))\n K = IWB+I\n W(K) = ELMBDA/W(J)**2-2./DLRSQ\n 101 CONTINUE\nC\nC ENTER BOUNDARY DATA FOR R-BOUNDARIES.\nC\n GO TO (102,102,104,104,106,106),MBDCND\n 102 A1 = 2.*W(1)\n W(IWB+1) = W(IWB+1)-W(1)\n DO 103 J=1,N\n F(1,J) = F(1,J)-A1*BDA(J)\n 103 CONTINUE\n GO TO 106\n 104 A1 = DELTAR*W(1)\n W(IWB+1) = W(IWB+1)+W(1)\n DO 105 J=1,N\n F(1,J) = F(1,J)+A1*BDA(J)\n 105 CONTINUE\n 106 CONTINUE\n GO TO (107,109,109,107,107,109),MBDCND\n 107 W(IWC) = W(IWC)-W(IWR)\n A1 = 2.*W(IWR)\n DO 108 J=1,N\n F(M,J) = F(M,J)-A1*BDB(J)\n 108 CONTINUE\n GO TO 111\n 109 W(IWC) = W(IWC)+W(IWR)\n A1 = DELTAR*W(IWR)\n DO 110 J=1,N\n F(M,J) = F(M,J)-A1*BDB(J)\n 110 CONTINUE\nC\nC ENTER BOUNDARY DATA FOR THETA-BOUNDARIES.\nC\n 111 A1 = 2./DLTHSQ\n GO TO (121,112,112,114,114),NP\n 112 DO 113 I=1,M\n F(I,1) = F(I,1)-A1*BDC(I)\n 113 CONTINUE\n GO TO 116\n 114 A1 = 1./DELTHT\n DO 115 I=1,M\n F(I,1) = F(I,1)+A1*BDC(I)\n 115 CONTINUE\n 116 A1 = 2./DLTHSQ\n GO TO (121,117,119,119,117),NP\n 117 DO 118 I=1,M\n F(I,N) = F(I,N)-A1*BDD(I)\n 118 CONTINUE\n GO TO 121\n 119 A1 = 1./DELTHT\n DO 120 I=1,M\n F(I,N) = F(I,N)-A1*BDD(I)\n 120 CONTINUE\n 121 CONTINUE\nC\nC ADJUST RIGHT SIDE OF SINGULAR PROBLEMS TO INSURE EXISTENCE OF A\nC SOLUTION.\nC\n PERTRB = 0.\n IF (ELMBDA) 130,123,122\n 122 IERROR = 11\n GO TO 130\n 123 GO TO (130,130,124,130,130,124),MBDCND\n 124 GO TO (125,130,130,125,130),NP\n 125 CONTINUE\n DO 127 I=1,M\n A1 = 0.\n DO 126 J=1,N\n A1 = A1+F(I,J)\n 126 CONTINUE\n J = IWR+I\n PERTRB = PERTRB+A1*W(J)\n 127 CONTINUE\n PERTRB = PERTRB/(FLOAT(M*N)*0.5*(A+B))\n DO 129 I=1,M\n DO 128 J=1,N\n F(I,J) = F(I,J)-PERTRB\n 128 CONTINUE\n 129 CONTINUE\n 130 CONTINUE\nC\nC MULTIPLY I-TH EQUATION THROUGH BY DELTHT**2\nC\n DO 132 I=1,M\n W(I) = W(I)*DLTHSQ\n J = IWC+I\n W(J) = W(J)*DLTHSQ\n J = IWB+I\n W(J) = W(J)*DLTHSQ\n DO 131 J=1,N\n F(I,J) = F(I,J)*DLTHSQ\n 131 CONTINUE\n 132 CONTINUE\n LP = NBDCND\n W(1) = 0.\n W(IWR) = 0.\nC\nC CALL GENBUN TO SOLVE THE SYSTEM OF EQUATIONS.\nC\n IF (NBDCND .EQ. 0) GO TO 133\n CALL POISTG (LP,N,1,M,W,W(IWB+1),W(IWC+1),IDIMF,F,IERR1,W(IWR+1))\n GO TO 134\n 133 CALL GENBUN (LP,N,1,M,W,W(IWB+1),W(IWC+1),IDIMF,F,IERR1,W(IWR+1))\n 134 CONTINUE\n W(1) = W(IWR+1)+3.*FLOAT(M)\n RETURN\nC\nC REVISION HISTORY---\nC\nC SEPTEMBER 1973 VERSION 1\nC APRIL 1976 VERSION 2\nC JANUARY 1978 VERSION 3\nC DECEMBER 1979 VERSION 3.1\nC FEBRUARY 1985 DOCUMENTATION UPGRADE\nC NOVEMBER 1988 VERSION 3.2, FORTRAN 77 CHANGES\nC-----------------------------------------------------------------------\n END\n", "meta": {"hexsha": "68bde11f1f81a48dc2d0268387434880f86ba52e", "size": 19211, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/src/hstcyl.f", "max_stars_repo_name": "ipelupessy/omuse", "max_stars_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2020-03-25T10:02:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-18T00:28:35.000Z", "max_issues_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/src/hstcyl.f", "max_issues_repo_name": "ipelupessy/omuse", "max_issues_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 45, "max_issues_repo_issues_event_min_datetime": "2020-03-03T16:07:16.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-14T09:01:07.000Z", "max_forks_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/src/hstcyl.f", "max_forks_repo_name": "ipelupessy/omuse", "max_forks_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-03-03T13:28:50.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-26T09:20:02.000Z", "avg_line_length": 39.5288065844, "max_line_length": 72, "alphanum_fraction": 0.4027380147, "num_tokens": 5375, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9585377261041521, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6918180975326584}} {"text": "FUNCTION ran_gamma(s, first) RESULT(fn_val)\r\nUSE random\r\nIMPLICIT NONE\r\n\r\n! Uses the algorithm in\r\n! Marsaglia, G. and Tsang, W.W. (2000) `A simple method for generating\r\n! gamma variables', Trans. om Math. Software (TOMS).\r\n\r\n! Generates a random gamma deviate for shape parameter s >= 1.\r\n\r\nREAL, INTENT(IN) :: s\r\nLOGICAL, INTENT(IN) :: first\r\nREAL :: fn_val\r\n\r\n! Local variables\r\nREAL, SAVE :: c, d\r\nREAL :: u, v, x\r\n\r\nIF (s < 1.0) THEN\r\n WRITE(*, *) 'Shape parameter must be >= 1'\r\n STOP\r\nEND IF\r\n\r\nIF (first) THEN\r\n d = s - 1./3.\r\n c = 1.0/SQRT(9.0*d)\r\nEND IF\r\n\r\n! Start of main loop\r\nDO\r\n\r\n! Generate v = (1+cx)^3 where x is random normal; repeat if v <= 0.\r\n\r\n DO\r\n x = random_normal()\r\n v = (1.0 + c*x)**3\r\n IF (v > 0.0) EXIT\r\n END DO\r\n\r\n! Generate uniform variable U\r\n\r\n CALL RANDOM_NUMBER(u)\r\n IF (u < 1.0 - 0.0331*x**4) THEN\r\n fn_val = d*v\r\n EXIT\r\n ELSE IF (LOG(u) < 0.5*x**2 + d*(1.0 - v + LOG(v))) THEN\r\n fn_val = d*v\r\n EXIT\r\n END IF\r\nEND DO\r\n\r\nRETURN\r\nEND FUNCTION ran_gamma\r\n\r\n\r\n\r\nPROGRAM test_rgamma\r\nUSE random\r\nIMPLICIT NONE\r\n\r\nINTERFACE\r\n FUNCTION ran_gamma(s, first) RESULT(fn_val)\r\n USE random\r\n IMPLICIT NONE\r\n REAL, INTENT(IN) :: s\r\n LOGICAL, INTENT(IN) :: first\r\n REAL :: fn_val\r\n END FUNCTION ran_gamma\r\nEND INTERFACE\r\n\r\nREAL, PARAMETER :: shape(8) = (/ 1.0, 2.0, 3.0, 4.0, 5.0, 10.0, 20.0, 50.0 /)\r\nINTEGER :: i, j\r\nREAL :: aver, dev, sumsq, start, finish, x\r\n\r\nDO i = 1, 8\r\n WRITE(*, *)\r\n WRITE(*, '(a, f7.1)') ' Shape parameter = ', shape(i)\r\n\r\n! First time the new algorithm\r\n\r\n CALL CPU_TIME(start)\r\n x = ran_gamma(shape(i), .TRUE.)\r\n aver = x\r\n sumsq = 0.0\r\n DO j = 2, 1000000\r\n x = ran_gamma(shape(i), .FALSE.)\r\n dev = x - aver\r\n aver = aver + dev/j\r\n sumsq = sumsq + dev*(x-aver)\r\n END DO\r\n CALL CPU_TIME(finish)\r\n sumsq = SQRT(sumsq/999999.)\r\n WRITE(*, *) 'Using Marsaglia & Tsang algorithm'\r\n WRITE(*, '(a, f7.2, a, 2f7.3)') &\r\n ' Time = ', finish - start, 'sec. Mean & st.devn. = ', aver, sumsq\r\n\r\n! Repeat using algorithm in module random\r\n\r\n CALL CPU_TIME(start)\r\n x = random_gamma(shape(i), .TRUE.)\r\n aver = x\r\n sumsq = 0.0\r\n DO j = 2, 1000000\r\n x = random_gamma(shape(i), .FALSE.)\r\n dev = x - aver\r\n aver = aver + dev/j\r\n sumsq = sumsq + dev*(x-aver)\r\n END DO\r\n CALL CPU_TIME(finish)\r\n sumsq = SQRT(sumsq/999999.)\r\n WRITE(*, *) 'Using algorithm in module random'\r\n WRITE(*, '(a, f7.2, a, 2f7.3)') &\r\n ' Time = ', finish - start, 'sec. Mean & st.devn. = ', aver, sumsq\r\nEND DO\r\n\r\nSTOP\r\nEND PROGRAM test_rgamma\r\n", "meta": {"hexsha": "22f24b2edf0406cbc23506890102abc3b9b55cb9", "size": 2632, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/rgamma.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/rgamma.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/rgamma.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": 22.3050847458, "max_line_length": 79, "alphanum_fraction": 0.5604103343, "num_tokens": 917, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.896251378675949, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6917658037640638}} {"text": "!!!!!\n! This subroutine calculates the gamma coefficients for the Meador & \n! Weaver two-stream plane-parallel atmosphere radiative transfer code. \n! The calculations are taken directly from Pinty et al. (2006) Table \n! 4.\n!\n! Pinty, B., Lavergne, T., Dickinson, R.E., Widlowski, J.-L., Gobron, \n! N., Verstraete, M.M., 2006. Simplifying the interaction of land \n! surfaces with radiation for relating remote sensing products to \n! climate models. J. Geophys. Res. 111, D02116. \n! doi:10.1029/2005JD005952\n!!!!!\n\nsubroutine pinty(rl, tl, mu0, gammas)\n use mod_dataspec_wavelength\n implicit none\n\n real*8, intent(in) :: mu0\n real*8, intent(in), dimension(nw) :: rl, tl\n real*8, intent(out), dimension(nw, 4) :: gammas\n\n real*8, dimension(nw) :: w0, wd, w02, wd6\n\n w0 = rl + tl\n wd = rl - tl\n\n w02 = w0 / 2.0d0\n wd6 = wd / 6.0d0\n\n gammas(:,1) = 2.0d0 * (1 - w02 + wd6)\n gammas(:,2) = 2.0d0 * (w02 + wd6)\n gammas(:,3) = 2.0d0 * (w02 / 2.0d0 + mu0 * wd6) / w0\n gammas(:,4) = 1.0d0 - gammas(:,3)\n\nend subroutine pinty\n", "meta": {"hexsha": "ad334fd10d5b6d253ec6324015e5e63a7037c64a", "size": 1056, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "modules/rtm/src/RTM/twostream/gamma.functions.f90", "max_stars_repo_name": "Kah5/pecan", "max_stars_repo_head_hexsha": "72bec0eebbda513d492e6fa4b3f50757aa9448d0", "max_stars_repo_licenses": ["NCSA", "Unlicense"], "max_stars_count": 151, "max_stars_repo_stars_event_min_datetime": "2015-01-26T13:43:20.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T19:06:56.000Z", "max_issues_repo_path": "modules/rtm/src/RTM/twostream/gamma.functions.f90", "max_issues_repo_name": "Kah5/pecan", "max_issues_repo_head_hexsha": "72bec0eebbda513d492e6fa4b3f50757aa9448d0", "max_issues_repo_licenses": ["NCSA", "Unlicense"], "max_issues_count": 1771, "max_issues_repo_issues_event_min_datetime": "2015-01-02T03:33:13.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T13:16:40.000Z", "max_forks_repo_path": "modules/rtm/src/RTM/twostream/gamma.functions.f90", "max_forks_repo_name": "Kah5/pecan", "max_forks_repo_head_hexsha": "72bec0eebbda513d492e6fa4b3f50757aa9448d0", "max_forks_repo_licenses": ["NCSA", "Unlicense"], "max_forks_count": 171, "max_forks_repo_forks_event_min_datetime": "2015-01-08T18:44:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T07:18:53.000Z", "avg_line_length": 29.3333333333, "max_line_length": 72, "alphanum_fraction": 0.6287878788, "num_tokens": 392, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513703624558, "lm_q2_score": 0.7718435083355187, "lm_q1q2_score": 0.6917658020510743}} {"text": "! =============================================================================\r\n! Test FFT module\r\n!\r\n! This unit test checks the FFT module with reference solutions.\r\n! =============================================================================\r\nprogram test_fft_3d\r\n use unit_test\r\n use constants, only : pi, twopi, f12, zero, four, two\r\n use inversion_utils, only : init_fft, fftxyp2s, fftxys2p\r\n use parameters, only : update_parameters, dx, nx, ny, nz, lower, extent\r\n implicit none\r\n\r\n double precision :: error = zero\r\n double precision, allocatable :: fp1(:, :, :), &\r\n fp2(:, :, :), &\r\n fp(:, :, :), &\r\n fs(:, :, :)\r\n integer :: i, j, k\r\n double precision :: x, y, z\r\n\r\n\r\n nx = 32\r\n ny = 64\r\n nz = 128\r\n lower = (/-pi, f12 * pi, zero/)\r\n extent = (/twopi, two * twopi, four * twopi/)\r\n\r\n call update_parameters\r\n\r\n allocate(fp1(0:nz, 0:ny-1, 0:nx-1))\r\n allocate(fp2(0:nz, 0:ny-1, 0:nx-1))\r\n allocate(fs(0:nz, 0:nx-1, 0:ny-1))\r\n\r\n call init_fft\r\n\r\n ! setup test field\r\n do i = 0, nx-1\r\n x = lower(1) + dble(i) * dx(1)\r\n do j = 0, ny-1\r\n y = lower(2) + dble(j) * dx(2)\r\n do k = 0, nz\r\n z = lower(3) + dble(k) * dx(3)\r\n fp1(k, j, i) = dcos(four * x) + dsin(y) + dcos(z)\r\n fp2(k, j, i) = fp1(k, j, i)\r\n enddo\r\n enddo\r\n enddo\r\n\r\n fs = zero\r\n\r\n ! we need to copy since fftxyp2s overwrites *fp*.\r\n fp = fp1\r\n\r\n ! forward FFT\r\n call fftxyp2s(fp, fs)\r\n\r\n ! inverse FFT\r\n call fftxys2p(fs, fp2)\r\n\r\n ! final check\r\n error = maxval(dabs(fp1 - fp2))\r\n\r\n call print_result_dp('Test FFT 2D transform', error, atol=dble(1.0e-14))\r\n\r\nend program test_fft_3d\r\n", "meta": {"hexsha": "0548d946b066457565f87cd0700ac547a88a80e5", "size": 1934, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "unit-tests/3d/test_fft_3d.f90", "max_stars_repo_name": "matt-frey/epic", "max_stars_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2021-11-11T10:50:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T00:11:41.000Z", "max_issues_repo_path": "unit-tests/3d/test_fft_3d.f90", "max_issues_repo_name": "matt-frey/epic", "max_issues_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 47, "max_issues_repo_issues_event_min_datetime": "2021-11-12T17:09:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-24T16:50:58.000Z", "max_forks_repo_path": "unit-tests/3d/test_fft_3d.f90", "max_forks_repo_name": "matt-frey/epic", "max_forks_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.303030303, "max_line_length": 80, "alphanum_fraction": 0.4265770424, "num_tokens": 564, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513675912912, "lm_q2_score": 0.7718435083355187, "lm_q1q2_score": 0.6917657999121688}} {"text": " Program dtgsna_example\n\n! DTGSNA Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_example_aux, Only: nagf_blas_dpyth\n Use lapack_interfaces, Only: dlange, dtgevc, dtgsna\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nin = 5, nout = 6\n! .. Local Scalars ..\n Real (Kind=dp) :: eps, snorm, stnrm, tnorm\n Integer :: i, info, lda, ldb, ldvl, ldvr, lwork, m, n\n! .. Local Arrays ..\n Real (Kind=dp), Allocatable :: a(:, :), b(:, :), dif(:), s(:), vl(:, :), &\n vr(:, :), work(:)\n Integer, Allocatable :: iwork(:)\n Logical :: select(1)\n! .. Intrinsic Procedures ..\n Intrinsic :: epsilon\n! .. Executable Statements ..\n Write (nout, *) 'DTGSNA Example Program Results'\n Write (nout, *)\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n\n lda = n\n ldb = n\n ldvl = n\n ldvr = n\n lwork = 2*n*(n+2) + 16\n Allocate (a(lda,n), b(ldb,n), dif(n), s(n), vl(ldvl,n), vr(ldvr,n), &\n work(lwork), iwork(n+6))\n\n! Read A and B from data file\n\n Read (nin, *)(a(i,1:n), i=1, n)\n Read (nin, *)(b(i,1:n), i=1, n)\n\n! Calculate the left and right generalized eigenvectors of the\n! pair (A,B). Note that DTGEVC requires WORK to be of dimension\n! at least 6*n.\n\n Call dtgevc('Both', 'All', select, n, a, lda, b, ldb, vl, ldvl, vr, &\n ldvr, n, m, work, info)\n\n If (info>0) Then\n Write (nout, 100) info, info + 1\n Else\n\n! Estimate condition numbers for all the generalized eigenvalues\n! and right eigenvectors of the pair (A,B)\n\n Call dtgsna('Both', 'All', select, n, a, lda, b, ldb, vl, ldvl, vr, &\n ldvr, s, dif, n, m, work, lwork, iwork, info)\n\n! Print condition numbers of eigenvalues and right eigenvectors\n\n Write (nout, *) 'S'\n Write (nout, 110) s(1:m)\n Write (nout, *)\n Write (nout, *) 'DIF'\n Write (nout, 110) dif(1:m)\n\n! Calculate approximate error estimates\n\n! Compute the 1-norms of A and B and then compute\n! SQRT(snorm**2 + tnorm**2)\n\n eps = epsilon(1.0E0_dp)\n snorm = dlange('1-norm', n, n, a, lda, work)\n tnorm = dlange('1-norm', n, n, b, ldb, work)\n stnrm = nagf_blas_dpyth(snorm, tnorm)\n Write (nout, *)\n Write (nout, *) 'Approximate error estimates for eigenvalues of (A,B)'\n Write (nout, 110)(eps*stnrm/s(i), i=1, m)\n Write (nout, *)\n Write (nout, *) 'Approximate error estimates for right ', &\n 'eigenvectors of (A,B)'\n Write (nout, 110)(eps*stnrm/dif(i), i=1, m)\n End If\n\n100 Format (' The 2-by-2 block (', I5, ':', I5, ') does not have a co', &\n 'mplex eigenvalue')\n110 Format ((3X,1P,7E11.1))\n End Program\n", "meta": {"hexsha": "3b4e8c2f4ef8e1f33718dc6790aa4e296a98ae94", "size": 3063, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/dtgsna_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/dtgsna_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/dtgsna_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 32.935483871, "max_line_length": 90, "alphanum_fraction": 0.5576232452, "num_tokens": 988, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513675912912, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6917657905047165}} {"text": "! Programming name : Possuile2DFlow.f90\n! Programming purpose : Compute possuile flow using LBM\n! Programming author: Yang Yang :-)\n\n!-----------------------------------------------------------------------------------------------------------\n! Simulation Parameter Bolock\nMODULE ParametersBlock\nimplicit none\n! Module name: ParametersBlock\n! Modul purpose: Specify and compute basic parameters\n\n! Parallel parameter\ninteger, parameter:: CPUS = 6\n \n! Discrete parameters\n! Mesh parameters: \ninteger, parameter:: Nx = 512, Ny = 512 ! Mesh size \ninteger, parameter:: t_max = 1000000 ! Max time step\n! Lattice model parameters:\ninteger, parameter:: D = 2 ! 2 Dimension model\ninteger, parameter:: Q = 9 ! D2Q9 velocity model\ninteger, parameter:: Qm = 5 ! D2Q5 velocity model\n\nreal*8, parameter:: c = 1.d0 ! lattice speed\nreal*8, parameter:: delta_x = 1.d0 ! mesh step length\nreal*8, parameter:: delta_y = delta_x ! mesh step length\nreal*8, parameter:: delta_t = delta_x / c ! time step length\n\nreal*8, parameter:: omega_alpha(1:Q) = (/ 4.d0/9.d0, 1.d0/9.d0, 1.d0/9.d0, 1.d0/9.d0, 1.d0/9.d0,&\n& 1.d0/36.d0, 1.d0/36.d0, 1.d0/36.d0, 1.d0/36.d0 /) ! Weight of distrbution function \ninteger, parameter:: e_alpha(1:2,1:Q) = (/0,0, 1,0, 0,1, -1,0, 0,-1, 1,1, -1,1, -1,-1, 1,-1 /) ! Discrete velocity model\n\nreal*8, parameter:: CQ = 1.d0/2.d0 ! CQ parameter in Mass LBE\nreal*8, parameter:: J0 = 0.9995d0 ! J0 parameter in Mass LBE\nreal*8, parameter:: J_alpha(1:Qm) = (/J0, (1.d0-J0)/4.d0, (1.d0-J0)/4.d0, (1.d0-J0)/4.d0, (1.d0-J0)/4.d0/) ! J_alpha in Mass LBE\n\n\n! Physics parameters\n! Flow parameters\nreal*8, parameter:: rho_0 = 1.d0 ! Reference Density\nreal*8, parameter:: Ma = 0.001d0 ! Mach number (Inlet Velocity)\nreal*8, parameter:: Re = 200 ! Renoyld number (Viscosity)\n! Mass Transfer parameters\nreal*8, parameter:: C0 = 1.d0 ! Inlet concentration\nreal*8, parameter:: Sc = 2000 ! Schmit number (Diffusion coefficient)\nreal*8, parameter:: Pe = Re*Sc ! Peclect number (Diffusion coefficient)\n\n! Computing parameters\n! Fluid Flow\nreal*8, parameter:: Ly = Ny*delta_y ! Characteristic length\nreal*8, parameter:: U0 = 1.d0/sqrt(3.d0)*c*Ma ! Characteristic Velocity\nreal*8, parameter:: nu = U0*Ly / Re ! Viscosity of fluid \nreal*8, parameter:: tau_f = (3.d0*nu) / (delta_t*c**2) + 1.d0/2.d0 ! dimensionless relaxion time of flow\n! Mass Transfer\nreal*8, parameter:: Dm = nu / Sc ! Diffusion coefficient\nreal*8, parameter:: tau_m = Dm / (delta_t*c**2*CQ*(1-J0)) + 1.d0/2.d0 ! dimensionless relaxion time of Mass transfer\n\n! Central parameters: Nx,Ny,t_max;D,Q,Qm;c,delta_x,delta_y,delta_t,omega_alpha,e_alpha,CQ,J0,J_alpha\n! U0,C0,nu,Dm,tau_f,tau_m\nEND MODULE ParametersBlock\n!------------------------------------------------\n\n\n!------------------------------------------------\n! main program\nPROGRAM main\nuse ParametersBlock\nimplicit none\ninteger, parameter:: Output_Interval = 10000, Report_Interval = 1000\nreal*8, parameter:: BreakCriticalCondition = 1.d-5\n\n\ninteger::t=0\nreal*8 f(Nx+1,Ny+1,Q), f_eq(Nx+1,Ny+1,Q), f_Temp(Nx+1,Ny+1,Q)\nreal*8 rho(Nx+1,Ny+1), u(Nx+1,Ny+1,D), u_temp(Nx+1,Ny+1,D)\nreal*8 epsilon\n\n!%% Output Simulation parameters\ncall OutputParameters()\nWrite(*,*) 'Programing Paused, Continue?...'\npause\n\n!%% Initial field\ncall InitialField(f,f_eq,rho,u)\n!%% Evolution field main loop\ndo t = 1,t_max\n call ComputeF(f,f_eq,f_Temp)\n call MacroVars(f,f_Temp,rho,u,u_temp)\n call ComputeF_eq(rho,u,f_eq)\n Call BCs(f,f_eq,rho,u)\n if(mod(t,Output_Interval).EQ.0) then\n Call Outputs(rho,u,t)\n end if\n if(mod(t,Report_Interval).EQ.0 ) then\n Call Erro(u,u_temp,epsilon)\n print 300, t,epsilon\n if(epsilon5000) then \n Print*, 'epsilon < BreakCriticalCondition','Step = ',t\n Exit\n end if\n end if\n\nend do\n\n300 format(1x,'Current Time Step = ',I10,', Current Residuls = ',ES25.15,/)\n!%% Report and output computing result \ncall SimulationReport(t,epsilon,u)\n\n!%% Output Velocity field and time step as meso file\ncall MesoField(u,t)\n\n\nEND PROGRAM main\n!--------------------------------------------------------------\n\n\n\n!--------------------------------------------------------------\n!subroutine OutputParameters\nSUBROUTINE OutputParameters() \nuse ParametersBlock\nimplicit none\ninteger i\ncharacter(len=20), parameter:: FileName1='SimulationParameters.txt'\n!FileName2='MesoParameters.dat'\n\n! Print \nWrite(*,100) Nx,Ny,t_max\n100 format(1x,'Nx = 'I10,', Ny = ',I10,', t_max = ',I10,/)\nWrite(*,101) D,Q,Qm\n101 format(1x,'D = ',I3,', Q = ',I3,', Qm = ',I3,/)\nWrite(*,102) c,delta_x,delta_y,delta_t\n102 format(1x,'c = ',ES15.5,', delta_x = ',ES15.5,', delta_y = ',ES15.5,', delta_t = ',ES15.5,/)\nWrite(*,103) omega_alpha\n103 format(1x,'Omega_alpha = ',9F10.5,/)\nWrite(*,*) 'e_alpha = '\ndo i = 1,D\n Write(*,104) e_alpha(i,:)\n 104 format(1x,9I3)\nend do\n\nWrite(*,105) CQ,J0\n105 format(1x,'CQ = ',F10.5,', J0 = 'F10.5,/)\nWrite(*,106) J_alpha\n106 format(1x,'J_alpha ='5F10.5)\n\nWrite(*,107) U0,Rho_0,C0\n107 format(1x,'U0 = ',F10.5,', Rho_0 = ',F10.5,', C0 = 'F10.5,/)\nWrite(*,108) nu,Dm\n108 format(1x,'nu = ',ES15.6,', Dm = ',ES15.6,/)\nWrite(*,109) tau_f,tau_m\n109 format(1x,'tau_f = ',ES15.6,', tau_m = ',ES15.6,/)\n\nWrite(*,110) Re,Sc,Pe\n110 format(1x,'Re = ',F12.4,', Sc = ',F12.4,', Pe = ',F12.4,/)\n\n! Output to ReportFile\nOpen(unit=20,file=Trim(FileName1))\nWrite(20,100) Nx,Ny,t_max\nWrite(20,101) D,Q,Qm\nWrite(20,102) c,delta_x,delta_y,delta_t\nWrite(20,103) omega_alpha\nWrite(20,*) 'e_alpha = '\ndo i = 1,D\n Write(20,104) e_alpha(i,:)\nend do\n\nWrite(20,105) CQ,J0\nWrite(20,106) J_alpha\n\nWrite(20,107) U0,Rho_0,C0\nWrite(20,108) nu,Dm\nWrite(20,109) tau_f,tau_m\nWrite(20,110) Re,Sc,Pe\nClose(20)\n\n! Output Meso parameter file\n!Open(unit=30,file=Trim(FileName2))\n!Write(30,*) Nx,Ny,t_max,D,Qm,c,delta_x,delta_y,delta_t,e_alpha,CQ,J_alpha,C0,tau_m\n!Close(30)\n\nEND SUBROUTINE OutputParameters\n!---------------------------------------------------------\n\n\n\n!---------------------------------------------------------\nSUBROUTINE InitialField(f,f_eq,rho,u)\nuse ParametersBlock\nuse omp_lib\nimplicit none\nreal*8, INTENT(INOUT):: f(Nx+1,Ny+1,Q), f_eq(Nx+1,Ny+1,Q)\nreal*8, INTENT(INOUT):: rho(Nx+1,Ny+1), u(Nx+1,Ny+1,D)\ninteger i,j,k\nreal*8 u_square,e_temp,x\n\n!$OMP PARALLEL DO PRIVATE(i,j) SHARED(u,rho) NUM_THREADS(CPUS)\n! Macro Varibles \ndo i=1,Nx+1\n do j = 1,Ny+1\n u(i,j,:) = 0\n rho(i,j) = Rho_0\n end do\nend do\n!$OMP END PARALLEL DO\n\nj = Ny+1\n!$OMP PARALLEL DO PRIVATE(i,x) FIRSTPRIVATE(j) SHARED(u) NUM_THREADS(CPUS)\ndo i = 1,Nx+1\n x = (i-1.d0)/Nx\n u(i,j,1) = U0*16.d0*(x**2)*(1.d0-x)**2\nend do\n!$OMP END PARALLEL DO\n\n!$OMP PARALLEL DO PRIVATE(i,j,u_square,e_temp) SHARED(f,f_eq,u,rho) NUM_THREADS(CPUS)\n! Micro Variles\ndo i=1,Nx+1\n do j = 1,Ny+1\n u_square = u(i,j,1)**2 + u(i,j,2)**2\n do k = 1,Q\n e_temp = u(i,j,1)*dble(e_alpha(1,k)) + u(i,j,2)*dble(e_alpha(2,k)) \n f_eq(i,j,k) = rho(i,j)*Omega_alpha(k)*( 1.d0 + e_temp*3.d0/c**2 + e_temp**2*9.d0/2.d0/c**4 - u_square*3.d0/2.d0/c**2 )\n f(i,j,k) = f_eq(i,j,k)\n end do\n end do\nend do\n!$OMP END PARALLEL DO\n\nEND SUBROUTINE InitialField\n!--------------------------------------------------------\n\n\n\n\n!--------------------------------------------------------\nSUBROUTINE ComputeF(f,f_eq,f_Temp)\nuse ParametersBlock\nuse omp_lib\nimplicit none\n\nreal*8, INTENT(INOUT):: f_Temp(Nx+1,Ny+1,Q)\nreal*8, INTENT(IN):: f(Nx+1,Ny+1,Q), f_eq(Nx+1,Ny+1,Q)\n\ninteger i,j,k\ninteger i_temp,j_temp\n\n!$OMP PARALLEL DO PRIVATE(i,j,k,i_temp,j_temp) SHARED(f,f_eq,F_Temp) NUM_THREADS(CPUS)\ndo i = 2,Nx\n do j = 2,Ny\n do k = 1,Q\n i_temp = i - e_alpha(1,k)\n j_temp = j - e_alpha(2,k)\n F_Temp(i,j,k) = f(i_temp,j_temp,k) + (f_eq(i_temp,j_temp,k) - f(i_temp,j_temp,k))/tau_f \n end do\n end do\nend do\n!$OMP END PARALLEL DO\n\n\nEND SUBROUTINE ComputeF\n!--------------------------------------------------------\n\n\n\n\n!--------------------------------------------------------\nSUBROUTINE MacroVars(f,f_Temp,rho,u,u_temp)\nuse ParametersBlock\nuse omp_lib\nimplicit none\n\nreal*8, INTENT(IN):: f_Temp(Nx+1,Ny+1,Q)\nREAL*8, INTENT(OUT):: f(Nx+1,Ny+1,Q), rho(Nx+1,Ny+1),u(Nx+1,Ny+1,D),u_temp(Nx+1,Ny+1,D)\ninteger i,j,k\n\n!$OMP PARALLEL DO PRIVATE(i,j,k) SHARED(u_temp,rho,u,f,f_Temp) NUM_THREADS(CPUS)\n! Initial and sum all direction\ndo i = 2,Nx\n do j = 2,Ny\n u_temp(i,j,:) = u(i,j,:)\n rho(i,j) = 0.d0\n u(i,j,:) = 0.d0\n do k = 1,Q\n f(i,j,k) = f_Temp(i,j,k)\n rho(i,j) = rho(i,j) + f(i,j,k)\n u(i,j,1) = u(i,j,1) + e_alpha(1,k)*f(i,j,k)\n u(i,j,2) = u(i,j,2) + e_alpha(2,k)*f(i,j,k)\n end do\n u(i,j,:) = u(i,j,:) / Rho(i,j)\n end do\nend do\n!$OMP END PARALLEL DO\n\nEND SUBROUTINE \n!--------------------------------------------------------\n\n\n\n\n!--------------------------------------------------------\nSUBROUTINE ComputeF_eq(rho,u,f_eq)\nuse ParametersBlock\nuse omp_lib\nimplicit none\n\nreal*8, INTENT(IN):: rho(Nx+1,Ny+1),u(Nx+1,Ny+1,D)\nreal*8, INTENT(OUT):: f_eq(Nx+1,Ny+1,Q)\ninteger i,j,k\nreal*8 u_square,e_temp\n\n!$OMP PARALLEL DO PRIVATE(i,j,k,u_square,e_temp) SHARED(u,rho,f_eq) NUM_THREADS(CPUS)\ndo i = 2,Nx\n do j = 2,Ny\n u_square = u(i,j,1)**2 + u(i,j,2)**2 \n do k = 1,Q\n e_temp = u(i,j,1)*dble(e_alpha(1,k)) + u(i,j,2)*dble(e_alpha(2,k)) \n f_eq(i,j,k) = rho(i,j)*Omega_alpha(k)*( 1.d0 + e_temp*3.d0/c**2 + e_temp**2*9.d0/2.d0/c**4 - u_square*3.d0/2.d0/c**2 )\n end do\n end do\nend do\n!$OMP END PARALLEL DO\n\nEND SUBROUTINE ComputeF_eq\n!--------------------------------------------------------\n\n\n!--------------------------------------------------------\nSUBROUTINE BCs(f,f_eq,rho,u)\nuse ParametersBlock\nuse omp_lib\nimplicit none\n\nreal*8, INTENT(INOUT):: f(Nx+1,Ny+1,Q),f_eq(Nx+1,Ny+1,Q),rho(Nx+1,Ny+1),u(Nx+1,Ny+1,D)\ninteger i,j,k\nreal*8 u_square,e_temp,x\n\n\n!%% Inlet non-equilibrium scheme\ni = 1\n!$OMP PARALLEL DO PRIVATE(j,k,u_square,e_temp) FIRSTPRIVATE(i) SHARED(rho,u,f_eq,f) NUM_THREADS(CPUS)\ndo j = 2,Ny\n rho(i,j) = rho(i+1,j)\n u(i,j,1) = 0\n u(i,j,2) = 0\n u_square = u(i,j,1)**2 + u(i,j,2)**2 \n do k = 1,Q\n e_temp = u(i,j,1)*dble(e_alpha(1,k)) + u(i,j,2)*dble(e_alpha(2,k))\n f_eq(i,j,k) = rho(i,j)*Omega_alpha(k)*( 1.d0 + e_temp*3.d0/c**2 + e_temp**2*9.d0/2.d0/c**4 - u_square*3.d0/2.d0/c**2 )\n f(i,j,k) = f_eq(i,j,k) + (f(i+1,j,k) - f_eq(i+1,j,k) )\n end do\nend do\n!$OMP END PARALLEL DO\n\n\n!%% Outlet fully developed \ni = Nx+1\n!$OMP PARALLEL DO PRIVATE(j,k,u_square,e_temp) FIRSTPRIVATE(i) SHARED(rho,u,f_eq,f) NUM_THREADS(CPUS)\ndo j = 2,Ny\n u(i,j,1) = 0\n u(i,j,2) = 0\n rho(i,j) = rho(i-1,j)\n do k = 1,Q\n e_temp = u(i,j,1)*dble(e_alpha(1,k)) + u(i,j,2)*dble(e_alpha(2,k))\n f_eq(i,j,k) = rho(i,j)*Omega_alpha(k)*( 1.d0 + e_temp*3.d0/c**2 + e_temp**2*9.d0/2.d0/c**4 - u_square*3.d0/2.d0/c**2 )\n f(i,j,k) = f_eq(i,j,k) + (f(i-1,j,k) - f_eq(i-1,j,k) )\n end do \nend do\n!$OMP END PARALLEL DO \n\n!%% Walls non-equilibrium scheme\n! %% Bottom \nj = 1\n!$OMP PARALLEL DO PRIVATE(i,k,u_square,e_temp) FIRSTPRIVATE(j) SHARED(rho,u,f,f_eq) NUM_THREADS(CPUS)\ndo i = 1,Nx + 1\n rho(i,j) = rho(i,j+1)\n u(i,j,1) = 0\n u(i,j,2) = 0\n u_square = u(i,j,1)**2 + u(i,j,2)**2 \n do k = 1,Q\n e_temp = u(i,j,1)*dble(e_alpha(1,k)) + u(i,j,2)*dble(e_alpha(2,k))\n f_eq(i,j,k) = rho(i,j)*Omega_alpha(k)*( 1.d0 + e_temp*3.d0/c**2 + e_temp**2*9.d0/2.d0/c**4 - u_square*3.d0/2.d0/c**2 )\n f(i,j,k) = f_eq(i,j,k) + (f(i,j+1,k) - f_eq(i,j+1,k) )\n end do\nend do\n!$OMP END PARALLEL DO\n\n\n!%% TOP\nj = Ny+1\n!$OMP PARALLEL DO PRIVATE(i,k,u_square,e_temp,x) FIRSTPRIVATE(j) SHARED(rho,u,f,f_eq) NUM_THREADS(CPUS)\ndo i = 1,Nx + 1\n x = (i-1.d0)/Nx\n rho(i,j) = rho(i,j-1)\n u(i,j,1) = U0*16.d0*(x**2)*(1.d0-x)**2\n u(i,j,2) = 0\n u_square = u(i,j,1)**2 + u(i,j,2)**2 \n do k = 1,Q\n e_temp = u(i,j,1)*dble(e_alpha(1,k)) + u(i,j,2)*dble(e_alpha(2,k))\n f_eq(i,j,k) = rho(i,j)*Omega_alpha(k)*( 1.d0 + e_temp*3.d0/c**2 + e_temp**2*9.d0/2.d0/c**4 - u_square*3.d0/2.d0/c**2 )\n f(i,j,k) = f_eq(i,j,k) + (f(i,j-1,k) - f_eq(i,j-1,k) )\n end do\nend do\n!$OMP END PARALLEL DO\n\nEND SUBROUTINE BCs\n!--------------------------------------------------------\n\n\n!--------------------------------------------------------\nSUBROUTINE Outputs(rho,u,t)\nuse ParametersBlock\nimplicit none\n\ninteger, INTENT(IN):: t\nreal*8, INTENT(IN):: rho(Nx+1,Ny+1),u(Nx+1,Ny+1,D)\n\nreal*8 rho_out(Nx+1,Ny+1),u_out(Nx+1,Ny+1,D)\ncharacter(len=100) Char_Temp,Nx_Temp,Ny_Temp\ninteger i,j\n\nWrite(Char_Temp,*) t\nWrite(Nx_Temp,*) Nx+1\nWrite(Ny_Temp,*) Ny+1\nopen(20,file='FlowDataAtStep'//Trim(Char_Temp)//'.dat')\n\nWrite(20,*) 'VARIABLES = X, Y, U, V, Rho'\nWrite(20,*) 'Zone T=\"\", I ='//Trim(Nx_Temp)//', J ='//Trim(Ny_Temp)//', F = Point'\n\n! Dimensionless\ndo i = 1,Nx+1\n do j = 1,Ny+1\n u_out(i,j,:) = u(i,j,:) / U0\n rho_out(i,j) = rho(i,j) / Rho_0\n end do\nend do\n\n! Output\ndo j = 1,Ny+1\n do i = 1,Nx+1\n Write(20,200) dble(i-1)/dble(Ly),dble(j-1)/dble(Ly),u_out(i,j,1),u_out(i,j,2),rho_out(i,j)\n end do\nend do\n200 format(1x,5ES24.15)\n\nclose(20)\n\nEND SUBROUTINE Outputs\n!--------------------------------------------------------\n\n\n\n!--------------------------------------------------------\nSUBROUTINE Erro(u,u_temp,epsilon)\nuse ParametersBlock\nuse omp_lib\nimplicit none\n\nreal*8, INTENT(IN):: u(Nx+1,Ny+1,D),u_temp(Nx+1,Ny+1,D)\nreal*8, INTENT(INOUT):: epsilon\ninteger i,j\nreal*8:: num = 0.d0, den = 0.d0\n\n!$OMP PARALLEL DO PRIVATE(i,j) SHARED(u,u_temp) REDUCTION(+:num,den) NUM_THREADS(CPUS)\ndo i = 2,Nx\n do j = 2,Ny\n num = num + (u(i,j,1)-u_temp(i,j,1))**2 + (u(i,j,2)-u_temp(i,j,2))**2\n den = den + u_temp(i,j,1)**2 + u_temp(i,j,2)**2\n end do\nend do\n!$OMP END PARALLEL DO\n\nepsilon = sqrt(num) / sqrt(den)\n\nEND SUBROUTINE Erro\n!--------------------------------------------------------\n\n\n\n!--------------------------------------------------------\nSUBROUTINE SimulationReport(t,epsilon,u)\nuse ParametersBlock \nimplicit none\n\nreal*8, INTENT(IN):: t,epsilon,u(Nx+1,Ny+1,D)\ninteger j,i1,i2,i3,i4,i5,i6,i7,i8,i9,i10\n\n! %% Compute Log File\nopen(20,file='Report.log')\nWrite(20,200) t,epsilon\n200 format(1x,'Final Time Step:',I10,', Final Residual:',ES25.15)\nclose(20)\n\n! %% Velocity Profile \ni1 = NINT(0.d0*Nx) +1\ni2 = NINT(1.d0/20.d0*Nx) +1\ni3 = NINT(1.d0/10.d0*Nx) +1\ni4 = NINT(3.d0/20.d0*Nx) +1\ni5 = NINT(1.d0/5.d0*Nx) +1\ni6 = NINT(3.d0/10.d0*Nx) +1\ni7 = NINT(2.d0/5.d0*Nx) +1\ni8 = NINT(3.d0/5.d0*Nx) +1\ni9 = NINT(4.d0/5.d0*Nx) +1\ni10 = Nx+1 \nopen(30,file = 'VelocityProfile.txt')\nWrite(30,*) 'Variables = Y,U(X1:X10)'\ndo j = 1,Ny+1\n Write(30,300) dble(j-1)/dble(Ly) ,u(i1,j,1)/U0,u(i2,j,1)/U0,u(i3,j,1)/U0,u(i4,j,1)/U0,u(i5,j,1)/U0& \n &,u(i6,j,1)/U0,u(i7,j,1)/U0,u(i8,j,1)/U0,u(i9,j,1)/U0, u(i10,j,1)/U0\nend do\n300 format(1x,11ES18.10)\nclose(30)\n\nEND SUBROUTINE SimulationReport\n!--------------------------------------------------------\n\n\n!--------------------------------------------------------\n!: This Subroutine is really important, play a role of bridge\nSUBROUTINE Mesofield(u,t)\nuse ParametersBlock\nimplicit none\n\nreal*8, INTENT(IN):: u(Nx+1,Ny+1,D)\ninteger, INTENT(IN):: t\nopen(100,file = 'MesoField.dat')\nWrite(100,*) u,t\n\nclose(100)\nEND SUBROUTINE Mesofield\n!--------------------------------------------------------\n", "meta": {"hexsha": "15f7a563053442a75ceb85500356279ab69e73a3", "size": 15419, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Homeworks/\u8ba1\u7b97\u6d41\u4f53\u529b\u5b66\u7b2c\u516d\u6b21\u4f5c\u4e1a/CavityLidDrivenFlow/CavityLBM.f90", "max_stars_repo_name": "shihe000/matlabcfd", "max_stars_repo_head_hexsha": "1134a2385efaa4c9824a309fbb79fd33afff17c1", "max_stars_repo_licenses": ["AFL-3.0"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2018-03-12T02:18:35.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-09T01:53:49.000Z", "max_issues_repo_path": "Homeworks/\u8ba1\u7b97\u6d41\u4f53\u529b\u5b66\u7b2c\u516d\u6b21\u4f5c\u4e1a/CavityLidDrivenFlow/CavityLBM.f90", "max_issues_repo_name": "shihe000/matlabcfd", "max_issues_repo_head_hexsha": "1134a2385efaa4c9824a309fbb79fd33afff17c1", "max_issues_repo_licenses": ["AFL-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Homeworks/\u8ba1\u7b97\u6d41\u4f53\u529b\u5b66\u7b2c\u516d\u6b21\u4f5c\u4e1a/CavityLidDrivenFlow/CavityLBM.f90", "max_forks_repo_name": "shihe000/matlabcfd", "max_forks_repo_head_hexsha": "1134a2385efaa4c9824a309fbb79fd33afff17c1", "max_forks_repo_licenses": ["AFL-3.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-06-02T11:35:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-05T21:28:17.000Z", "avg_line_length": 29.0376647834, "max_line_length": 128, "alphanum_fraction": 0.5688436345, "num_tokens": 5744, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898254600903, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.6917085314355036}} {"text": "module snding_mod\n implicit none\n private\n public :: splint, spline\n\n contains\n\n real pure function splint(XA,YA,Y2A,n,x)\n integer, intent(in) :: n, x\n real, intent(in) :: XA(50), YA(50), Y2A(n)\n \n real :: h, a, b\n integer :: klo, khi, k\n \n klo=1\n khi=n\n \n do \n if (khi-klo <= 1) exit\n if (khi-klo > 1) then\n k=(khi+klo)/2\n if (XA(k) > x) then\n khi=k\n else\n klo=k\n end if\n end if\n end do\n \n H=XA(KHI)-XA(KLO)\n A=(XA(KHI)-X)/H\n B=(X-XA(KLO))/H\n splint=A*YA(KLO)+B*YA(KHI)+((A**3-A)*Y2A(KLO)+(B**3-B)*Y2A(KHI))*(H**2)/6.\n \n end function\n\n\n pure function spline(X,Y,N,YP1,YPN)\n integer, parameter :: NMAX=100\n real :: U(NMAX)\n real :: UN,QN,P,SIG\n integer, intent(in) :: N\n integer :: i, k\n real, intent(in) :: X(N), Y(N), YP1, YPN\n real :: spline(N)\n \n IF (YP1>.99E30) THEN\n spline(1)=0.\n U(1)=0.\n ELSE\n spline(1)=-0.5\n U(1)=(3./(X(2)-X(1)))*((Y(2)-Y(1))/(X(2)-X(1))-YP1)\n end if\n do I=2,N-1\n SIG=(X(I)-X(I-1))/(X(I+1)-X(I-1))\n P=SIG*spline(I-1)+2.\n spline(I)=(SIG-1.)/P\n U(I)=(6.*((Y(I+1)-Y(I))/(X(I+1)-X(I))-(Y(I)-Y(I-1)) &\n /(X(I)-X(I-1)))/(X(I+1)-X(I-1))-SIG*U(I-1))/P\n end do\n IF (YPN>.99E30) THEN\n QN=0.\n UN=0.\n ELSE\n QN=0.5\n UN=(3./(X(N)-X(N-1)))*(YPN-(Y(N)-Y(N-1))/(X(N)-X(N-1)))\n end if\n spline(N)=(UN-QN*U(N-1))/(QN*spline(N-1)+1.)\n do K=N-1,1,-1\n spline(K)=spline(K)*spline(K+1)+U(K)\n end do\n return\n end function\n\nend module snding_mod\n", "meta": {"hexsha": "122c64b585cc11b317e43213ea7aa907c503632c", "size": 1733, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/snding_mod.f90", "max_stars_repo_name": "aap1/simsphere", "max_stars_repo_head_hexsha": "b35ab1c67902f935264900c950cd42b6e96c4574", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2019-11-04T05:08:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:19:21.000Z", "max_issues_repo_path": "src/snding_mod.f90", "max_issues_repo_name": "aap1/simsphere", "max_issues_repo_head_hexsha": "b35ab1c67902f935264900c950cd42b6e96c4574", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 17, "max_issues_repo_issues_event_min_datetime": "2018-10-04T15:35:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-06T15:15:02.000Z", "max_forks_repo_path": "src/snding_mod.f90", "max_forks_repo_name": "aap1/simsphere", "max_forks_repo_head_hexsha": "b35ab1c67902f935264900c950cd42b6e96c4574", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-10-06T18:43:14.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-01T01:33:53.000Z", "avg_line_length": 22.8026315789, "max_line_length": 80, "alphanum_fraction": 0.4264281593, "num_tokens": 679, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898229217591, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.6917085294975289}} {"text": "!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 1998 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Spherepack *\n! * *\n! * A Package of Fortran Subroutines and Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams and Paul Swarztrauber *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\n!\n!\n!\n! 11/96\n!\n! a program for testing all vector analysis and synthesis subroutines\n!\n! (1) first a scalar stream function and a scalar velocity potential function\n! are set in st, sv by restricting polys in x, y, z to the sphere surface\n!\n! (2) the vector vield (v, w) is set by analytically differenting the scalar fields in (1)\n! using the standard formula relating a vector field and the stream and velocity\n! potential scalar fields in colatitude X longitude spherical coordinates\n!\n! v = -1/sin(theta)*d(st)/dphi + d(sv)/dtheta\n!\n! w = 1/sin(theta)*d(sv)/dphi + d(st)/dtheta\n!\n! (3) a vector analysis is performed on (v, w)\n!\n! (4) a vector synthesis is performed using coeffs from (3)\n!\n! (5) the synthesized vector field from (4) is compared with the vector field from (2)\n!\n! note: vhaec, vhaes, vhagc, vhags, vhsec, vhses, vhsgc, vhsgs are all tested!\n!\nprogram tvha\n\n use, intrinsic :: ISO_Fortran_env, only: &\n stdout => OUTPUT_UNIT\n\n use spherepack, only: &\n ip, & ! Integer precision\n wp, & ! Working precision\n Sphere, &\n Regularsphere, &\n GaussianSphere\n\n ! Explicit typing only\n implicit none\n\n ! Dictionary\n class(Sphere), allocatable :: solver\n\n ! Test gaussian grid\n allocate (GaussianSphere :: solver)\n call test_vector_analysis_and_synthesis_routines(solver)\n deallocate (solver)\n\n ! Test regular grid\n allocate (RegularSphere :: solver)\n call test_vector_analysis_and_synthesis_routines(solver)\n deallocate (solver)\n\ncontains\n\n subroutine test_vector_analysis_and_synthesis_routines(sphere_type)\n\n ! Dummy arguments\n class(Sphere), intent(inout) :: sphere_type\n\n ! Local variables\n integer(ip), parameter :: NLONS = 19\n integer(ip), parameter :: NLATS = 25\n integer(ip), parameter :: NSYNTHS = 2\n integer(ip) :: i, j, k ! Counters\n real(wp) :: polar_component(NLATS, NLONS, NSYNTHS)\n real(wp) :: azimuthal_component(NLATS, NLONS, NSYNTHS)\n real(wp) :: synthesized_polar(NLATS, NLONS, NSYNTHS)\n real(wp) :: synthesized_azimuthal(NLATS, NLONS, NSYNTHS)\n character(len=:), allocatable :: previous_polar_error, previous_azimuthal_error\n\n ! Set up workspace arrays\n select type(sphere_type)\n type is (GaussianSphere)\n\n ! Initialize gaussian sphere object\n sphere_type = GaussianSphere(NLATS, NLONS)\n\n ! Allocate known error from previous platform\n allocate (previous_polar_error, source=' polar error = 5.107026e-15')\n allocate (previous_azimuthal_error, source=' azimuthal error = 9.325873e-15')\n\n type is (RegularSphere)\n\n ! Initialize regular sphere\n sphere_type = RegularSphere(NLATS, NLONS)\n\n ! Allocate known error from previous platform\n allocate (previous_polar_error, source=' polar error = 5.329071e-15')\n allocate (previous_azimuthal_error, source=' azimuthal error = 7.771561e-15')\n end select\n\n !\n ! Set scalar stream and velocity potential fields as polys in x, y, z\n ! and then set v, w from st, sv scalar fields\n !\n associate (&\n ve => polar_component, &\n we => azimuthal_component, &\n radial => sphere_type%unit_vectors%radial, &\n theta => sphere_type%unit_vectors%polar, &\n phi => sphere_type%unit_vectors%azimuthal &\n )\n do k=1, NSYNTHS\n do j=1, NLONS\n do i=1, NLATS\n associate (&\n x => radial(i, j)%x, & !sint*cosp\n y => radial(i, j)%y, & !sint*sinp\n z => radial(i, j)%z, & !cost\n dxdt => theta(i, j)%x, &! cost*cosp\n dxdp => -radial(i, j)%y, & !-sint*sinp\n dydt => theta(i, j)%y, &! cost*sinp\n dydp => radial(i, j)%x, & ! sint*cosp\n dzdt => theta(i, j)%z, & ! -sint\n dzdp => phi(i, j)%z, & ! 0.0\n cosp => phi(i, j)%y, &\n sinp => -phi(i, j)%x &\n )\n select case (k)\n case (1)\n associate (&\n dstdt => x*dydt+y*dxdt, &\n dsvdt => y*dzdt+z*dydt &\n )\n ve(i, j, k) = -(cosp*dydp+sinp*dxdp) + dsvdt\n we(i, j, k) = sinp*dzdp + dxdt + dstdt\n end associate\n case (2)\n associate (&\n dstdt => x*dzdt+z*dxdt, &\n dsvdt => x*dydt+y*dxdt &\n )\n !\n ! v = -1/sin(theta)*d(st)/dphi + d(sv)/dtheta\n !\n ! w = 1/sin(theta)*d(sv)/dphi + d(st)/dtheta\n !\n ve(i, j, k) = z*sinp + dsvdt\n we(i, j, k) = cosp*dydp+ sinp*dxdp + dstdt\n end associate\n end select\n end associate\n end do\n end do\n end do\n end associate\n\n\n !\n ! Perform analysis then synthesis\n !\n do k = 1, NSYNTHS\n associate (&\n ve => polar_component(:, :, k), &\n we => azimuthal_component(:, :, k), &\n v => synthesized_polar(:, :, k), &\n w => synthesized_azimuthal(:, :, k) &\n )\n\n ! Analyse function into (real) coefficients\n call sphere_type%vector_analysis_from_spherical_components(ve, we)\n\n ! Synthesize function from (real) coefficients\n call sphere_type%perform_vector_synthesis(v, w)\n end associate\n end do\n\n\n !\n ! Compute discretization error\n !\n associate (&\n ve => polar_component, &\n we => azimuthal_component, &\n v => synthesized_polar, &\n w => synthesized_azimuthal &\n )\n associate (&\n err2v => maxval(abs(v - ve)), &\n err2w => maxval(abs(w - we)) &\n )\n !\n ! Print earlier output from platform with 64-bit floating point\n ! arithmetic followed by the output from this computer\n !\n write (stdout, '(a)') ''\n write (stdout, '(a)') ' test vector analysis and synthesis *** TEST RUN *** '\n write (stdout, '(a)') ''\n write (stdout, '(a)') ' grid type = '//sphere_type%grid%grid_type\n write (stdout, '(a)') ' Testing vector analysis and synthesis'\n write (stdout, '(2(a, i3))') ' nlat = ', NLATS, ' nlon = ', NLONS\n write (stdout, '(a)') ' Previous 64 bit floating point arithmetic result '\n write (stdout, '(a)') previous_polar_error\n write (stdout, '(a)') previous_azimuthal_error\n write (stdout, '(a)') ' The output from your computer is: '\n write (stdout, '(a, 1pe15.6)') ' polar error = ', err2v\n write (stdout, '(a, 1pe15.6)') ' azimuthal error = ', err2w\n write (stdout, '(a)') ''\n end associate\n end associate\n !\n ! Release memory\n !\n call sphere_type%destroy()\n deallocate (previous_polar_error)\n deallocate (previous_azimuthal_error)\n\n end subroutine test_vector_analysis_and_synthesis_routines\n\nend program tvha\n", "meta": {"hexsha": "089b5ba2693d94ff1bb70b856f23d5fe36337c46", "size": 10561, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/test_vector_analysis_and_synthesis_routines.f90", "max_stars_repo_name": "jlokimlin/spherepack4.1", "max_stars_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-06-28T14:01:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T21:59:28.000Z", "max_issues_repo_path": "test/test_vector_analysis_and_synthesis_routines.f90", "max_issues_repo_name": "jlokimlin/spherepack4.1", "max_issues_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2016-05-07T23:00:35.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-22T23:52:30.000Z", "max_forks_repo_path": "test/test_vector_analysis_and_synthesis_routines.f90", "max_forks_repo_name": "jlokimlin/spherepack4.1", "max_forks_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-06-28T14:03:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T12:53:54.000Z", "avg_line_length": 43.2827868852, "max_line_length": 97, "alphanum_fraction": 0.407631853, "num_tokens": 2225, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898279984214, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6917085236221407}} {"text": "C FILE: vvh_routines.f\n\n SUBROUTINE Tensor_Inner_Product_3X3(a,b,T)\n \n implicit none\n real(8), dimension(3,3), intent(in) :: a, b\n real(8), intent(out) :: T!, TX\n\n !TX = sum(sum(a*b,2))\n \n T = a(1,1)*b(1,1) + a(1,2)*b(1,2) + a(1,3)*b(1,3) \n T = T + a(2,1)*b(2,1) + a(2,2)*b(2,2) + a(2,3)*b(2,3)\n T = T + a(3,1)*b(3,1) + a(3,2)*b(3,2) + a(3,3)*b(3,3) \n\n END SUBROUTINE\n\n SUBROUTINE HENCKY_1D(mu, etr, Ei, dWtr, d2Wtr, energye)\n\n implicit none\n real(8), intent(in) :: mu, etr(3,1), Ei(3,3,3)\n real(8) :: G, eps(3), vdWtr(3)\n real(8), intent(out) :: dWtr(3,3), d2Wtr(3,3), energye\n\n eps(:) = 0.d0\n\n G = mu\n\n eps=[etr(1,1), etr(2,1), etr(3,1)]\n\n vdWtr(:) = 2*G*eps(:)\n\n dWtr(1, 1:3) = [vdWtr(1), 0.0d0, 0.0d0]\n dWtr(2, 1:3) = [ 0.0d0, vdWtr(2), 0.0d0]\n dWtr(3, 1:3) = [ 0.0d0, 0.0d0, vdWtr(3)]\n\n d2Wtr(1, 1:3) = [2*G, 0.0d0, 0.0d0]\n d2Wtr(2, 1:3) = [ 0.0d0, 2*G, 0.0d0]\n d2Wtr(3, 1:3) = [ 0.0d0, 0.0d0, 2*G]\n\n energye = G*(eps(1)**2 + eps(2)**2 + eps(3)**2)\n\n END SUBROUTINE\n\n SUBROUTINE Hencky_3D(mu, etr, Ei, dWtr, d2Wtr, energye)\n \n implicit none\n real(8), intent(in) :: mu, etr(3,3), Ei(3,3,3)\n real(8) :: G, eps(3), vdWtr(3)\n real(8), intent(out) :: dWtr(3,3), d2Wtr(3,3), energye\n\n eps(:) = 0.d0\n\n G = mu\n\n call Tensor_Inner_Product_3X3(etr, Ei(:,:,1), eps(1))\n call Tensor_Inner_Product_3X3(etr, Ei(:,:,2), eps(2))\n call Tensor_Inner_Product_3X3(etr, Ei(:,:,3), eps(3))\n\n vdWtr(:) = 2*G*eps(:)\n\n dWtr(1, 1:3) = [vdWtr(1), 0.0d0, 0.0d0]\n dWtr(2, 1:3) = [ 0.0d0, vdWtr(2), 0.0d0]\n dWtr(3, 1:3) = [ 0.0d0, 0.0d0, vdWtr(3)]\n\n d2Wtr(1, 1:3) = [2*G, 0.0d0, 0.0d0]\n d2Wtr(2, 1:3) = [ 0.0d0, 2*G, 0.0d0]\n d2Wtr(3, 1:3) = [ 0.0d0, 0.0d0, 2*G]\n\n energye = G*(eps(1)**2 + eps(2)**2 + eps(3)**2)\n\n END SUBROUTINE\n\nC END FILE", "meta": {"hexsha": "56af5a6d89f330bbcf12d78d049c021885fcbd8e", "size": 2298, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "yamate/materials/vvh_routines.f", "max_stars_repo_name": "WRupp/yamate", "max_stars_repo_head_hexsha": "e63d334a418259919a6fbd6baf0163e967c52618", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "yamate/materials/vvh_routines.f", "max_issues_repo_name": "WRupp/yamate", "max_issues_repo_head_hexsha": "e63d334a418259919a6fbd6baf0163e967c52618", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "yamate/materials/vvh_routines.f", "max_forks_repo_name": "WRupp/yamate", "max_forks_repo_head_hexsha": "e63d334a418259919a6fbd6baf0163e967c52618", "max_forks_repo_licenses": ["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.4794520548, "max_line_length": 81, "alphanum_fraction": 0.406875544, "num_tokens": 1069, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898153067649, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6917085188079358}} {"text": " program main\nc\nc ... array declarations.\nc\n implicit double precision (a-h, o-z)\n dimension coef(120,5), rhs(100), u(100), wksp(600), ubar(1),\n a rparm(30)\n integer jcoef(120,5), iwksp(300), iparm(30), p(100), ip(100)\n external cg, rs6\nc\n ndim = 120\n mdim = 5\n nw = 600\n inw = 300\nc\nc ... generate coef, jcoef, and rhs.\nc\n nx = 10\n ny = 10\n n = nx*ny\n h = 1.0d0/dble(nx + 1)\n maxnz = 5\n do i = 1,n \n coef(i,1) = 6.0d0\n coef(i,2) = -1.0d0\n coef(i,3) = -2.0d0\n coef(i,4) = -1.0d0\n coef(i,5) = -2.0d0\n jcoef(i,1) = i\n jcoef(i,2) = i + 1\n jcoef(i,3) = i + nx\n jcoef(i,4) = i - 1\n jcoef(i,5) = i - nx\n rhs(i) = 0.0d0\n enddo\n k = 0\n do j = 1,ny\n y = dble(j)*h\n do i = 1,nx\n x = dble(i)*h\n k = k + 1\n if (j .eq. 1) then\n rhs(k) = rhs(k) + 2.0d0\n coef(k,5) = 0.0d0\n jcoef(k,5) = 0 \n endif\n if (j .eq. ny) then\n rhs(k) = rhs(k) + 2.0d0*(1.0d0 + x)\n coef(k,3) = 0.0d0\n jcoef(k,3) = 0 \n endif\n if (i .eq. 1) then\n rhs(k) = rhs(k) + 1.0d0\n coef(k,4) = 0.0d0\n jcoef(k,4) = 0 \n endif\n if (i .eq. nx) then\n rhs(k) = rhs(k) + 1.0d0 + y\n coef(k,2) = 0.0d0\n jcoef(k,2) = 0 \n endif\n enddo\n enddo\n call dfault (iparm,rparm)\nc\nc ... now, reset some default values.\nc\n iparm(3) = 3\n iparm(12) = 1 \n iparm(14) = 1 \n iparm(23) = 0 \nc\nc ... generate an initial guess for u and call nspcg.\nc\n call vfill (n,u,0.0d0)\nc\n call redblk (ndim,n,maxnz,coef,jcoef,p,ip,1,iwksp,ier)\n call nspcg (rs6,cg,ndim,mdim,n,maxnz,coef,jcoef,p,ip, \n a u,ubar,rhs,wksp,iwksp,nw,inw,iparm,rparm,ier)\n stop\n end \n", "meta": {"hexsha": "09466d128fa4974084db5f2f160816ddd9beedd7", "size": 2024, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "svSolver-master/Code/ThirdParty/nspcg/simvascular_nspcg/tstnsp3.f", "max_stars_repo_name": "mccsssk2/SimVascularPM3_March2020", "max_stars_repo_head_hexsha": "3cce6cc7be66545bea5dc3915a2db50a3892bf04", "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": "svSolver-master/Code/ThirdParty/nspcg/simvascular_nspcg/tstnsp3.f", "max_issues_repo_name": "mccsssk2/SimVascularPM3_March2020", "max_issues_repo_head_hexsha": "3cce6cc7be66545bea5dc3915a2db50a3892bf04", "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": "svSolver-master/Code/ThirdParty/nspcg/simvascular_nspcg/tstnsp3.f", "max_forks_repo_name": "mccsssk2/SimVascularPM3_March2020", "max_forks_repo_head_hexsha": "3cce6cc7be66545bea5dc3915a2db50a3892bf04", "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.6829268293, "max_line_length": 66, "alphanum_fraction": 0.4160079051, "num_tokens": 806, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898203834278, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6917085178082168}} {"text": "program ch0708\n ! Table of Liquid Conversion Measurements\n implicit none\n\n integer :: litre\n real :: gallon, usgallon\n\n do litre = 1, 10\n gallon = litre/4.545\n usgallon = litre/3.7854118\n print *, litre, ' ', gallon, ' ', usgallon\n end do\nend program\n", "meta": {"hexsha": "f0aa8820f0bcf8f4db98d24ce7537a25dc633536", "size": 290, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ch07/ch0708.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": "ch07/ch0708.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": "ch07/ch0708.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.7142857143, "max_line_length": 50, "alphanum_fraction": 0.6034482759, "num_tokens": 85, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9059898203834278, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6917085129325481}} {"text": "\n SUBROUTINE INIFFT\n\nC Initialize FFTs\n\n include \"atparam.h\"\n\n COMMON /FFTCOM/ WSAVE(2*IX+15)\n\n CALL RFFTI (IX,WSAVE)\nC CALL DFFTI (IX,WSAVE)\n\n RETURN\n END\n\n*********************************************************************\n\n SUBROUTINE GRIDX(VARM,VORG,KCOS)\n\nC From Fourier coefficients to grid-point data\n\n include \"atparam.h\"\n\n include \"com_spectral.h\"\n\n COMMON /FFTCOM/ WSAVE(2*IX+15)\n\n REAL VORG(IX,IL), VARM(MX2,IL)\n REAL FVAR(IX)\n\nC Copy Fourier coefficients into working array\n\n DO J=1,IL\n\n FVAR(1)=VARM(1,J)\n\n DO M=3,MX2\n FVAR(M-1)=VARM(M,J)\n ENDDO\n DO M=MX2,IX\n FVAR(M)=0.0\n ENDDO\n\n\nC Inverse FFT\n\n CALL RFFTB (IX,FVAR,WSAVE)\nC CALL DFFTB (IX,FVAR,WSAVE)\n\nC Copy output into grid-point field, scaling by cos(lat) if needed\n\n IF (KCOS.EQ.1) THEN\n\n DO I=1,IX\n VORG(I,J)=FVAR(I)\n ENDDO\n\n ELSE\n\n DO I=1,IX\n VORG(I,J)=FVAR(I)*COSGR(J)\n ENDDO\n\n ENDIF\n\n ENDDO\n\n RETURN\n END\n\n******************************************************************\n\n SUBROUTINE SPECX(VORG,VARM)\n\nC From grid-point data to Fourier coefficients\n\n include \"atparam.h\"\n\n COMMON /FFTCOM/ WSAVE(2*IX+15)\n\n REAL VORG(IX,IL), VARM(MX2,IL)\n REAL FVAR(IX)\n\nC Copy grid-point data into working array\n\n DO J=1,IL\n\n DO I=1,IX\n FVAR(I)=VORG(I,J)\n ENDDO\n\nC Direct FFT\n\n CALL RFFTF (IX,FVAR,WSAVE)\nC CALL DFFTF (IX,FVAR,WSAVE)\n\nC Copy output into spectral field, dividing by no. of long.\n\n SCALE=1./FLOAT(IX)\n\nC Mean value (a(0))\n\n VARM(1,J)=FVAR(1)*SCALE\n VARM(2,J)=0.0\n\n DO M=3,MX2\n VARM(M,J)=FVAR(M-1)*SCALE\n ENDDO\n\n ENDDO\n\n RETURN\n END\n\n include \"spe_subfft_fftpack2.f\"\n", "meta": {"hexsha": "bf454f0435a093a2e4f7ba550c436a5b4e55b7dc", "size": 1923, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "models/speedy/t21/spe_subfft_fftpack.f", "max_stars_repo_name": "enino84/AMLCS", "max_stars_repo_head_hexsha": "7a37cca01c9305afb99b652baeb9e0952ebe889b", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "models/speedy/t21/spe_subfft_fftpack.f", "max_issues_repo_name": "enino84/AMLCS", "max_issues_repo_head_hexsha": "7a37cca01c9305afb99b652baeb9e0952ebe889b", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "models/speedy/t21/spe_subfft_fftpack.f", "max_forks_repo_name": "enino84/AMLCS", "max_forks_repo_head_hexsha": "7a37cca01c9305afb99b652baeb9e0952ebe889b", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.5775862069, "max_line_length": 70, "alphanum_fraction": 0.5007800312, "num_tokens": 609, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898127684335, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6917085071186236}} {"text": "!\nMODULE shape_2_mod\n !\n ! Shape function library - 2d.\n !\n USE IntrinsicTypesModule, RK=>REAL_KIND\n !\n IMPLICIT NONE\n !\nCONTAINS\n ! \n !\n !***********************************************************************\n !\n SUBROUTINE sf2d(itype, npts, pts, vals, MV1, istat)\n !\n ! Evaluate shape functions at a list of points.\n !\n !----------------------------------------------------------------------\n !\n IMPLICIT NONE\n !\n ! Arguments:\n !\n INTEGER :: itype, npts, MV1, istat\n REAL(RK) :: pts(2,*), vals(MV1, *)\n !\n !----------------------------------------------------------------------\n !\n istat = 0\n !\n IF (itype .eq. 3) THEN\n !\n call sf2d03(npts, pts, vals, MV1)\n !\n ELSEIF (itype .eq. 4) THEN\n !\n call sf2d04(npts, pts, vals, MV1)\n !\n ELSEIF (itype .eq. 6) THEN\n !\n call sf2d06(npts, pts, vals, MV1)\n !\n ELSEIF (itype .eq. 8) THEN\n !\n call sf2d08(npts, pts, vals, MV1)\n !\n ELSEIF (itype .eq. 9) THEN\n !\n call sf2d09(npts, pts, vals, MV1)\n !\n ELSE\n !\n ! Unrecognized element type.\n !\n istat = 1\n !\n ENDIF\n !\n RETURN\n END SUBROUTINE sf2d\n !\n !***********************************************************************\n !\n SUBROUTINE sf2dg(itype, npts, pts, grads, MG1, istat)\n !\n ! Evaluate shape function gradients at a list of points.\n !\n !----------------------------------------------------------------------\n !\n IMPLICIT NONE\n !\n ! Arguments:\n !\n INTEGER :: itype, npts, MG1, istat\n REAL(RK) :: pts(2,*), grads(2,MG1, *)\n !\n !----------------------------------------------------------------------\n !\n istat = 0\n !\n IF (itype .eq. 3) THEN\n !\n call sf2dg03(npts, pts, grads, MG1)\n !\n ELSEIF (itype .eq. 4) THEN\n !\n call sf2dg04(npts, pts, grads, MG1)\n !\n ELSEIF (itype .eq. 6) THEN\n !\n call sf2dg06(npts, pts, grads, MG1)\n !\n ELSEIF (itype .eq. 8) THEN\n !\n call sf2dg08(npts, pts, grads, MG1)\n !\n ELSEIF (itype .eq. 9) THEN\n !\n call sf2dg09(npts, pts, grads, MG1)\n !\n ELSE\n !\n ! Unrecognized element type.\n !\n istat = 1\n !\n ENDIF\n !\n RETURN\n END SUBROUTINE sf2dg\n !\n !***********************************************************************\n !\n ! ***** t3 ******\n !\n SUBROUTINE sf2d03(npts, pnts, value, MV1)\n !\n ! three node triangular element (values)\n ! \n IMPLICIT NONE\n !\n INTEGER :: npts, MV1\n REAL(RK) :: value(MV1,*), pnts(2, *)\n !\n INTEGER :: i\n REAL(RK) ::xi, eta, zeta\n !\n do i=1, npts\n xi = pnts(1,i)\n eta = pnts(2,i)\n zeta = 1.d0 - xi - eta\n !\n ! nodal locations:\n !\n ! 2\n ! 31\n !\n value(1,i) = xi\n value(2,i) = eta\n value(3,i) = zeta\n enddo\n !\n RETURN\n END SUBROUTINE sf2d03\n !\n !***********************************************************************\n !\n SUBROUTINE sf2dg03(npts, pnts, grad, MG1)\n !\n ! three node tirangle element (gradients)\n ! \n IMPLICIT NONE\n !\n INTEGER :: npts, MG1\n REAL(RK) :: grad(2,MG1,*), pnts(2,*)\n !\n INTEGER :: i\n REAL(RK) :: xi, eta, zeta\n !\n do i=1, npts\n xi = pnts(1,i)\n eta = pnts(2,i)\n zeta = 1.0d0 - xi - eta\n !\n grad(1,1,i) = 1.0d0\n grad(1,2,i) = 0.0d0\n grad(1,3,i) = -1.0d0\n !\n grad(2,1,i) = 0.d0\n grad(2,2,i) = 1.d0\n grad(2,3,i) = -1.d0\n enddo\n !\n RETURN\n END SUBROUTINE sf2dg03\n !\n !***********************************************************************\n !\n ! ***** q4 ******\n !\n SUBROUTINE sf2d04(npts, pnts, value, MV1)\n !\n ! four node quadrilateral element (values)\n ! \n IMPLICIT NONE\n !\n INTEGER :: npts, MV1\n REAL(RK) :: value(MV1,*), pnts(2, *)\n !\n INTEGER :: i\n REAL(RK) :: xi, eta\n !\n do i=1, npts\n xi = pnts(1,i)\n eta = pnts(2,i)\n !\n value(1,i) = (1.0d0-xi)*(1.0d0-eta)\n value(2,i) = xi*(1.0d0-eta)\n value(3,i) = xi*eta\n value(4,i) = (1.0d0-xi)*eta\n enddo\n !\n RETURN\n END SUBROUTINE sf2d04\n !\n !***********************************************************************\n !\n SUBROUTINE sf2dg04(npts, pnts, grad, MG1)\n !\n ! four node quadrilateral element (gradients)\n ! \n IMPLICIT NONE\n !\n INTEGER :: npts, MG1\n REAL(RK) :: grad(2,MG1,*), pnts(2,*)\n !\n INTEGER :: i\n REAL(RK) :: xi, eta\n !\n do i=1, npts\n xi = pnts(1,i)\n eta = pnts(2,i)\n !\n grad(1,1,i) = eta-1.0d0\n grad(1,2,i) = 1.0d0-eta\n grad(1,3,i) = eta\n grad(1,4,i) = -eta\n !\n grad(2,1,i) =xi-1.0d0\n grad(2,2,i) =-xi\n grad(2,3,i) =xi\n grad(2,4,i) =1.0d0-xi\n enddo\n !\n RETURN\n END SUBROUTINE sf2dg04\n !\n !***********************************************************************\n !\n ! ****** t6 ******\n !\n SUBROUTINE sf2d06(npts, pnts, value, MV1)\n !\n ! six node triangular element (values)\n ! \n IMPLICIT NONE\n !\n INTEGER :: npts, MV1\n REAL(RK) :: value(MV1,*), pnts(2, *)\n !\n INTEGER :: i\n REAL(RK) :: xi, eta, zeta\n !\n do i=1, npts\n xi = pnts(1,i)\n eta = pnts(2,i)\n zeta = 1.0d0 - xi - eta\n ! nodal locations:\n !\n ! 3\n ! 42\n ! 561\n !\n !\n value(1,i) = (2.0d0*xi-1.0d0)*xi\n value(2,i) = 4.0d0*eta*xi\n value(3,i) = (2.0d0*eta-1.0d0)*eta\n value(4,i) = 4.0d0*eta*zeta\n value(5,i) = (2.0d0*zeta-1.0d0)*zeta\n value(6,i) = 4.0d0*xi*zeta\n enddo\n !\n RETURN\n END SUBROUTINE sf2d06\n !\n !***********************************************************************\n !\n SUBROUTINE sf2dg06(npts, pnts, grad, MG1)\n !\n ! six node triangular element (gradients)\n ! \n IMPLICIT NONE\n !\n INTEGER :: npts, MG1\n REAL(RK) :: grad(2,MG1,*), pnts(2,*)\n !\n INTEGER :: i\n REAL(RK) :: xi, eta, zeta\n !\n do i=1, npts\n xi = pnts(1,i)\n eta = pnts(2,i)\n zeta = 1.0d0 - xi - eta\n !\n grad(1,1,i) = 4.0d0*xi-1.0d0\n grad(1,2,i) = 4.0d0*eta\n grad(1,3,i) = 0.0d0\n grad(1,4,i) = -4.0d0*eta\n grad(1,5,i) = -4.0d0*zeta+1.0d0\n grad(1,6,i) = 4.0d0*zeta-4.0d0*xi\n !\n grad(2,1,i) = 0.0d0\n grad(2,2,i) = 4.0d0*xi\n grad(2,3,i) = 4.0d0*eta-1.0d0\n grad(2,4,i) = 4.0d0*zeta-4.0d0*eta\n grad(2,5,i) = -4.0d0*zeta+1.0d0\n grad(2,6,i) = -4.0d0*xi\n enddo\n !\n RETURN\n END SUBROUTINE sf2dg06\n !\n !***********************************************************************\n !\n ! ***** q8 *****\n !\n SUBROUTINE sf2d08(npts, pnts, value, MV1)\n !\n ! eight-node quadilateral ( serendipity ) element (values)\n !\n IMPLICIT NONE\n !\n INTEGER :: npts, MV1\n REAL(RK) :: value(MV1,*), pnts(2, *)\n !\n INTEGER :: i\n REAL(RK) :: xi, eta\n !\n do i=1, npts\n xi = pnts(1,i)\n eta = pnts(2,i)\n !\n value(1,i) = (1.0-xi)*(1.0-eta)*(-2.0*xi-2.0*eta+1.0)\n value(2,i) = 4.0*xi*(1.0-xi)*(1.0-eta)\n value(3,i) = xi*(1.0-eta)*(2.0*xi-2.0*eta-1.0)\n value(4,i) = 4.0*xi*eta*(1.0-eta)\n value(5,i) = xi*eta*(2.0*xi+2.0*eta-3.0)\n value(6,i) = 4.0*xi*eta*(1.0-xi)\n value(7,i) = eta*(1.0-xi)*(-2.0*xi+2.0*eta-1.0)\n value(8,i) = 4.0*eta*(1.0-xi)*(1.0-eta)\n enddo\n !\n RETURN\n END SUBROUTINE sf2d08\n !\n !***********************************************************************\n !\n SUBROUTINE sf2dg08(npts, pnts, grad, MG1)\n !\n ! eight-node quadilateral ( serendipity ) element (gradients)\n !\n IMPLICIT NONE\n !\n INTEGER :: npts, MG1\n REAL(RK) :: grad(2,MG1,*), pnts(2,*)\n !\n INTEGER :: i\n REAL(RK) :: xi, eta\n !\n do i=1, npts\n xi = pnts(1,i)\n eta = pnts(2,i)\n !\n grad(1,1,i) = -1.0*(1.0-eta)*(3.0-4.0*xi-2.0*eta)\n grad(1,2,i) = 4.0*(1.0-eta)*(1.0-2.0*xi)\n grad(1,3,i) = (1.0-eta)*(4.0*xi-2.0*eta-1.0)\n grad(1,4,i) = 4.0*eta*(1.0-eta)\n grad(1,5,i) = eta*(4.0*xi+2.0*eta-3.0)\n grad(1,6,i) = 4.0*eta*(1.0-2.0*xi)\n grad(1,7,i) = -eta*(-4.0*xi+2.0*eta+1.0)\n grad(1,8,i) = -4.0*eta*(1.0-eta)\n !\n grad(2,1,i) = -1.0*(1.0-xi)*(3.0-4.0*eta-2.0*xi)\n grad(2,2,i) = -4.0*xi*(1.0-xi)\n grad(2,3,i) = -xi*(2.0*xi-4.0*eta+1.0)\n grad(2,4,i) = 4.0*xi*(1.0-2.0*eta)\n grad(2,5,i) = xi*(2.0*xi+4.0*eta-3.0)\n grad(2,6,i) = 4.0*xi*(1.0-xi)\n grad(2,7,i) = (1.0-xi)*(-2.0*xi+4.0*eta-1.0)\n grad(2,8,i) = 4.0*(1.0-xi)*(1.0-2.0*eta)\n enddo\n !\n RETURN\n END SUBROUTINE sf2dg08\n !\n !***********************************************************************\n !\n ! ***** q9 *****\n !\n SUBROUTINE sf2d09(npts, pnts, value, MV1)\n !\n ! nine-node quadilateral element ( lagrangian ) (values)\n ! \n IMPLICIT NONE\n !\n INTEGER :: npts, MV1\n REAL(RK) :: value(MV1,*), pnts(2, *)\n !\n INTEGER :: i\n REAL(RK) :: xi, eta\n !\n do i=1, npts\n xi = pnts(1,i)\n eta = pnts(2,i)\n !\n value(1,i) = (2.0*xi-1.0)*(2.0*eta-1.0)*(xi-1.0)*(eta-1.0)\n value(2,i) = 4.0*xi*(1.0-xi)*(eta-1.0)*(2.0*eta-1.0)\n value(3,i) = xi*(2.0*xi-1.0)*(2.0*eta-1.0)*(eta-1.0)\n value(4,i) = 4.0*xi*eta*(2.0*xi-1.0)*(1.0-eta)\n value(5,i) = xi*eta*(2.0*xi-1.0)*(2.0*eta-1.0)\n value(6,i) = 4.0*xi*eta*(1.0-xi)*(2.0*eta-1.0)\n value(7,i) = (xi-1.0)*(2.0*xi-1.0)*(2.0*eta-1.0)*eta\n value(8,i) = 4.0*(2.0*xi-1.0)*(xi-1.0)*(1.0-eta)*eta\n value(9,i) = 16.0*xi*eta*(1.0-xi)*(1.0-eta)\n enddo\n !\n RETURN\n END SUBROUTINE sf2d09\n !\n !***********************************************************************\n !\n SUBROUTINE sf2dg09(npts, pnts, grad, MG1)\n !\n ! nine-node quadilateral element ( lagrangian ) (gradients)\n ! \n IMPLICIT NONE\n !\n INTEGER :: npts, MG1\n REAL(RK) :: grad(2,MG1,*), pnts(2,*)\n !\n INTEGER :: i\n REAL(RK) :: xi, eta\n !\n do i=1, npts\n xi = pnts(1,i)\n eta = pnts(2,i)\n !\n grad(1,1,i) = (4.0*xi-3.0)*(2.0*eta-1.0)*(eta-1.0)\n grad(1,2,i) = 4.0*(1.0-2.0*xi)*(eta-1.0)*(2.0*eta-1.0)\n grad(1,3,i) = (4.0*xi-1.0)*(2.0*eta-1.0)*(eta-1.0)\n grad(1,4,i) = 4.0*eta*(4.0*xi-1.0)*(1.0-eta)\n grad(1,5,i) = eta*(4.0*xi-1.0)*(2.0*eta-1.0)\n grad(1,6,i) = 4.0*eta*(1.0-2.0*xi)*(2.0*eta-1.0)\n grad(1,7,i) = (4.0*xi-3.0)*(2.0*eta-1.0)*eta\n grad(1,8,i) = 4.0*eta*(4.0*xi-3.0)*(1.0-eta)\n grad(1,9,i) = 16.0*(1.0-2.0*xi)*(1.0-eta)*eta\n !\n grad(2,1,i) = (2.0*xi-1.0)*(4.0*eta-3.0)*(xi-1.0)\n grad(2,2,i) = 4.0*xi*(1.0-xi)*(4.0*eta-3.0)\n grad(2,3,i) = xi*(2.0*xi-1.0)*(4.0*eta-3.0)\n grad(2,4,i) = 4.0*xi*(2.0*xi-1.0)*(1.0-2.0*eta)\n grad(2,5,i) = xi*(2.0*xi-1.0)*(4.0*eta-1.0)\n grad(2,6,i) = 4.0*xi*(1.0-xi)*(4.0*eta-1.0)\n grad(2,7,i) = (xi-1.0)*(2.0*xi-1.0)*(4.0*eta-1.0)\n grad(2,8,i) = 4.0*(2.0*xi-1.0)*(xi-1.0)*(1.0-2.0*eta)\n grad(2,9,i) = 16.0*xi*(1.0-xi)*(1.0-2.0*eta)\n enddo\n !\n RETURN\n END SUBROUTINE sf2dg09\n !\n !\nEND MODULE shape_2_mod\n", "meta": {"hexsha": "eabecf5e8e112fac08b4a1859d5aa50d0ec56b67", "size": 11467, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "PythonFortranCode/shape_2d.f90", "max_stars_repo_name": "rcarson3/pyFEpX", "max_stars_repo_head_hexsha": "f95851e41025fb57893041d0395d53a5745b7e6c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-03-27T21:24:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T13:35:59.000Z", "max_issues_repo_path": "PythonFortranCode/shape_2d.f90", "max_issues_repo_name": "rcarson3/pyFEpX", "max_issues_repo_head_hexsha": "f95851e41025fb57893041d0395d53a5745b7e6c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-09-10T22:54:10.000Z", "max_issues_repo_issues_event_max_datetime": "2018-09-10T22:54:10.000Z", "max_forks_repo_path": "PythonFortranCode/shape_2d.f90", "max_forks_repo_name": "rcarson3/pyFEpX", "max_forks_repo_head_hexsha": "f95851e41025fb57893041d0395d53a5745b7e6c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-05-13T07:44:35.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-11T13:36:00.000Z", "avg_line_length": 24.6602150538, "max_line_length": 75, "alphanum_fraction": 0.4079532572, "num_tokens": 4690, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424373085145, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.6916209431924136}} {"text": "!***********************************************************************\n! Routes water between segments in the system using Muskingum routing\n!\n! The Muskingum equation is described in 'Hydrology for Engineers', 3rd ed.\n! by Linsley, R.K, Kohler, M.A., and Paulhus, J.L.H., 1982 p. 275 and in\n! 'Water in Environmental Planning' by Dunne, T., and Leopold, L.B. 1978\n! p. 357.\n!\n! Note that the Muskingum equation assumes a linear relation of storage\n! to the inflow/outflow relation and therefore the relation is the same\n! throughout the range of the hydrograph. The route_time parameter in\n! the fixroute module is replaced by two new parameters, K_coef and\n! x_coef, which are described below:\n!\n! The Muskingum method is based on the equation: S = K[xI + (1 - x)O]\n! where S is storage, K is the storage coefficient, x is a coefficient\n! between 0 and .5, I is inflow, and O is outflow.\n!\n! Solving for the outflow at day 2,O2; and knowing the inflow at day 1,\n! I1; the inflow at day 2,I2; and the outflow at day 1, O1; the storage\n! equation can be written as follows:\n!\n! O2 = czero*I2 + cone*I1 + ctwo*O1\n!\n! where czero = -((Kx - 12) / (K - Kx + 12))\n! cone = (Kx + 12) / (K - Kx + 12)\n! ctwo = (K - Kx - 12) / (K - Kx + 12)\n!\n! assuming a time step of one day and K is in units of hours\n!\n! This module is based on the \"musroute.f\" module. It differs in three\n! basic ways:\n!\n! 1. This module uses an internal routing time step of one hour.\n! The old muskingum module ran on the same daily time step as\n! the rest of PRMS. The problem with this is that there is no\n! ability to distinguish where the flood wave (front of the flow\n! change) within the segment. For example, if there is a series\n! of 4 1-day long segments, a flood wave will make it to the bottom\n! of these in 1 day. If the same system is modeled as 1 4-day long\n! segment, it will take 4 days.\n!\n! 2. The X parameter has been removed as a specified input and is now computed. To\n! my knowledge, no modeler had ever set this to anything other than the default\n! value (0.2) anyway. Always using the default value can lead to problems\n! with the C coffecients which can result in mass balance problems or negative\n! flow values.\n!\n! To solve this problem, I assume that the C coefficients must\n! always be between 0 and 1. By setting the C coefficients equal to 0 and 1,\n! various limits on the time step (ts), X, and K can be determined. There are\n! two of these limits which are of interest:\n!\n! When C0 = 0:\n! ts\n! K = -----\n! 2X\n!\n! When C2 = 0:\n! ts\n! K = -----\n! 2(1-X)\n!\n! Determining a value of K half way between these two limits (by averaging)\n! and solving for X using the quadratic formula results in:\n!\n! 1-sqrt(1-(ts/K))\n! X = ------------------\n! 2\n!\n! So when ts is fixed at one hour and K is fixed as the average (or expected)\n! travel time corresponding to the segment (for each segment in the stream\n! network), a value of X can be computed (for each segment in the stream\n! network) which will result in both conservation of mass and non-negative\n! flows. Another benefit is that only one input parameter (K) needs to be\n! input to the module.\n!\n! 3. If the travel time of a segment is less than or equal to the routing\n! time step (one hour), then the outflow of the segment is set to the\n! value of the inflow.\n!\n!***********************************************************************\n MODULE PRMS_MUSKINGUM\n IMPLICIT NONE\n! Local Variables\n DOUBLE PRECISION, PARAMETER :: ONE_24TH = 1.0D0 / 24.0D0\n INTEGER, SAVE, ALLOCATABLE :: Ts_i(:)\n REAL, SAVE, ALLOCATABLE :: Ts(:), C0(:), C1(:), C2(:)\n DOUBLE PRECISION, SAVE, ALLOCATABLE :: Currinsum(:), Pastin(:), Pastout(:)\n DOUBLE PRECISION, SAVE, ALLOCATABLE :: Outflow_ts(:), Inflow_ts(:)\n CHARACTER(LEN=9), SAVE :: MODNAME\n! Declared Variables\n DOUBLE PRECISION, SAVE :: Basin_segment_storage\n DOUBLE PRECISION, SAVE, ALLOCATABLE :: Segment_delta_flow(:)\n! Declared Parameters\n REAL, SAVE, ALLOCATABLE :: K_coef(:), X_coef(:), Segment_flow_init(:)\n END MODULE PRMS_MUSKINGUM\n\n!***********************************************************************\n! Main muskingum routine\n!***********************************************************************\n INTEGER FUNCTION muskingum()\n USE PRMS_MODULE, ONLY: Process, Save_vars_to_file, Init_vars_from_file\n IMPLICIT NONE\n! Functions\n INTEGER, EXTERNAL :: muskingum_decl, muskingum_init, muskingum_run\n EXTERNAL :: muskingum_restart\n!***********************************************************************\n muskingum = 0\n\n IF ( Process(:3)=='run' ) THEN\n muskingum = muskingum_run()\n ELSEIF ( Process(:4)=='decl' ) THEN\n muskingum = muskingum_decl()\n ELSEIF ( Process(:4)=='init' ) THEN\n IF ( Init_vars_from_file==1 ) CALL muskingum_restart(1)\n muskingum = muskingum_init()\n ELSEIF ( Process(:5)=='clean' ) THEN\n IF ( Save_vars_to_file==1 ) CALL muskingum_restart(0)\n ENDIF\n\n END FUNCTION muskingum\n\n!***********************************************************************\n! muskingum_decl - Declare parameters and variables and allocate arrays\n! Declared Parameters\n! tosegment, hru_segment, obsin_segment, K_coef, x_coef\n!***********************************************************************\n INTEGER FUNCTION muskingum_decl()\n USE PRMS_MUSKINGUM\n USE PRMS_MODULE, ONLY: Nsegment, Init_vars_from_file\n IMPLICIT NONE\n! Functions\n INTEGER, EXTERNAL :: declparam, declvar\n EXTERNAL read_error, print_module\n! Local Variables\n CHARACTER(LEN=80), SAVE :: Version_muskingum\n!***********************************************************************\n muskingum_decl = 0\n\n Version_muskingum = 'muskingum.f90 2016-07-25 12:06:00Z'\n CALL print_module(Version_muskingum, 'Streamflow Routing ', 90)\n MODNAME = 'muskingum'\n\n ALLOCATE ( C1(Nsegment), C2(Nsegment), C0(Nsegment), Ts(Nsegment) )\n ALLOCATE ( Currinsum(Nsegment), Ts_i(Nsegment) )\n ALLOCATE ( Pastin(Nsegment), Pastout(Nsegment) )\n ALLOCATE ( Outflow_ts(Nsegment), Inflow_ts(Nsegment) )\n\n IF ( declvar(MODNAME, 'basin_segment_storage', 'one', 1, 'double', &\n & 'Basin area-weighted average storage in the stream network', &\n & 'inches', Basin_segment_storage)/=0 ) CALL read_error(3, 'basin_segment_storage')\n\n ALLOCATE ( Segment_delta_flow(Nsegment) )\n IF ( declvar(MODNAME, 'segment_delta_flow', 'nsegment', Nsegment, 'double', &\n & 'Cummulative flow in minus flow out for each stream segment', &\n & 'cfs', Segment_delta_flow)/=0 ) CALL read_error(3, 'segment_delta_flow')\n\n ALLOCATE ( K_coef(Nsegment) )\n IF ( declparam(MODNAME, 'K_coef', 'nsegment', 'real', &\n & '1.0', '0.01', '24.0', &\n & 'Muskingum storage coefficient', &\n & 'Travel time of flood wave from one segment to the next downstream segment,'// &\n & ' called the Muskingum storage coefficient; enter 1.0 for reservoirs,'// &\n & ' diversions, and segment(s) flowing out of the basin', &\n & 'hours')/=0 ) CALL read_error(1, 'K_coef')\n\n ALLOCATE ( X_coef(Nsegment) )\n IF ( declparam(MODNAME, 'x_coef', 'nsegment', 'real', &\n & '0.2', '0.0', '0.5', &\n & 'Routing weighting factor', &\n & 'The amount of attenuation of the flow wave, called the'// &\n & ' Muskingum routing weighting factor; enter 0.0 for'// &\n & ' reservoirs, diversions, and segment(s) flowing out of the basin', &\n & 'decimal fraction')/=0 ) CALL read_error(1, 'x_coef')\n\n IF ( Init_vars_from_file==0 ) THEN\n ALLOCATE ( Segment_flow_init(Nsegment) )\n IF ( declparam(MODNAME, 'segment_flow_init', 'nsegment', 'real', &\n & '0.0', '0.0', '1.0E7', &\n & 'Initial flow in each stream segment', &\n & 'Initial flow in each stream segment', &\n & 'cfs')/=0 ) CALL read_error(1, 'segment_flow_init')\n ENDIF\n\n END FUNCTION muskingum_decl\n\n!***********************************************************************\n! muskingum_init - Get and check parameter values and initialize variables\n!***********************************************************************\n INTEGER FUNCTION muskingum_init()\n USE PRMS_MUSKINGUM\n USE PRMS_MODULE, ONLY: Nsegment, Inputerror_flag, Parameter_check_flag, &\n & Init_vars_from_file\n USE PRMS_BASIN, ONLY: NEARZERO, Basin_area_inv\n USE PRMS_FLOWVARS, ONLY: Seg_inflow, Seg_outflow\n USE PRMS_SET_TIME, ONLY: Cfs_conv\n IMPLICIT NONE\n EXTERNAL :: read_error\n INTEGER, EXTERNAL :: getparam\n! Local Variables\n INTEGER :: i, ierr\n REAL :: k, x, d, x_max\n!***********************************************************************\n muskingum_init = 0\n\n IF ( getparam(MODNAME, 'K_coef', Nsegment, 'real', K_coef)/=0 ) CALL read_error(2, 'K_coef')\n IF ( getparam(MODNAME, 'x_coef', Nsegment, 'real', X_coef)/=0 ) CALL read_error(2, 'x_coef')\n IF ( Init_vars_from_file==0 ) THEN\n IF ( getparam(MODNAME, 'segment_flow_init', Nsegment, 'real', Segment_flow_init)/=0 ) &\n & CALL read_error(2,'segment_flow_init')\n Seg_inflow = 0.0D0\n DO i = 1, Nsegment\n Seg_outflow(i) = Segment_flow_init(i)\n ENDDO\n DEALLOCATE ( Segment_flow_init )\n Segment_delta_flow = 0.0D0\n Outflow_ts = 0.0D0\n ENDIF\n!\n! Compute the three constants in the Muskingum routing equation based\n! on the values of K_coef and a routing period of 1 hour. See the notes\n! at the top of this file.\n\n!\n C0 = 0.0\n C1 = 0.0\n C2 = 0.0\n!make sure K>0\n Ts = 1.0\n ierr = 0\n Basin_segment_storage = 0.0D0\n DO i = 1, Nsegment\n Basin_segment_storage = Basin_segment_storage + Seg_outflow(i)\n k = K_coef(i)\n x = X_coef(i)\n\n! check the values of k and x to make sure that Muskingum routing is stable\n\n IF ( k<1.0 ) THEN\n! IF ( Parameter_check_flag>0 ) THEN\n! PRINT '(/,A,I6,A,F6.2,/,9X,A,/)', 'WARNING, segment ', i, ' has K_coef < 1.0,', k, &\n! & 'this may produce unstable results'\n! ierr = 1\n! ENDIF\n Ts(i) = 0.0\n Ts_i(i) = -1\n\n ELSEIF ( k<2.0 ) THEN\n Ts(i) = 1.0\n Ts_i(i) = 1\n\n ELSEIF ( k<3.0 ) THEN\n Ts(i) = 2.0\n Ts_i(i) = 2\n\n ELSEIF ( k<4.0 ) THEN\n Ts(i) = 3.0\n Ts_i(i) = 3\n\n ELSEIF ( k<6.0 ) THEN\n Ts(i) = 4.0\n Ts_i(i) = 4\n\n ELSEIF ( k<8.0 ) THEN\n Ts(i) = 6.0\n Ts_i(i) = 6\n\n ELSEIF ( k<12.0 ) THEN\n Ts(i) = 8.0\n Ts_i(i) = 8\n\n ELSEIF ( k<24.0 ) THEN\n Ts(i) = 12.0\n Ts_i(i) = 12\n\n ELSE\n Ts(i) = 24.0\n Ts_i(i) = 24\n\n ENDIF\n\n! x must be <= t/(2K) the C coefficents will be negative. Check for this for all segments\n! with Ts >= minimum Ts (1 hour).\n IF ( Ts(i)>0.1 ) THEN\n x_max = Ts(i) / (2.0 * k)\n IF ( x>x_max ) THEN\n PRINT *, 'ERROR, x_coef value is too large for stable routing for segment:', i, ' x_coef:', x\n PRINT *, ' a maximum value of:', x_max, ' is suggested'\n Inputerror_flag = 1\n CYCLE\n ENDIF\n ENDIF\n\n d = k - (k * x) + (0.5 * Ts(i))\n IF ( d==0.0 ) THEN\n PRINT *, 'ERROR, segment ', i, ' computed value d = 0.0, change values of K_coef and x_coef'\n Inputerror_flag = 1\n ENDIF\n C0(i) = (-(k * x) + (0.5 * Ts(i))) / d\n C1(i) = ((k * x) + (0.5 * Ts(i))) / d \n C2(i) = (k - (k * x) - (0.5 * Ts(i))) / d\n\n ! the following code was in the original musroute, but, not in Linsley and others\n ! rsr, 3/1/2016 - having < 0 coefficient can cause negative flows as found by Jacob in GCPO headwater\n! if c2 is <= 0.0 then short travel time though reach (less daily\n! flows), thus outflow is mainly = inflow w/ small influence of previous\n! inflow. Therefore, keep c0 as is, and lower c1 by c2, set c2=0\n\n! if c0 is <= 0.0 then long travel time through reach (greater than daily\n! flows), thus mainly dependent on yesterdays flows. Therefore, keep\n! c2 as is, reduce c1 by c0 and set c0=0\n! SHORT travel time\n IF ( C2(i)<0.0 ) THEN\n IF ( Parameter_check_flag>0 ) THEN\n PRINT '(/,A)', 'WARNING, c2 < 0, set to 0, c1 set to c1 + c2'\n PRINT *, ' old c2:', C2(i), '; old c1:', C1(i), '; new c1:', C1(i) + C2(i)\n PRINT *, ' K_coef:', K_coef(i), '; x_coef:', x_coef(i)\n ENDIF\n C1(i) = C1(i) + C2(i)\n C2(i) = 0.0\n ENDIF\n\n! LONG travel time\n IF ( C0(i)<0.0 ) THEN\n IF ( Parameter_check_flag>0 ) THEN\n PRINT '(/,A)', 'WARNING, c0 < 0, set to 0, c0 set to c1 + c0'\n PRINT *, ' old c0:', C0(i), 'old c1:', C1(i), 'new c1:', C1(i) + C0(i)\n PRINT *, ' K_coef:', K_coef(i), '; x_coef:', x_coef(i)\n ENDIF\n C1(i) = C1(i) + C0(i)\n C0(i) = 0.0\n ENDIF\n\n ENDDO\n IF ( ierr==1 ) PRINT '(/,A,/)', '***Recommend that the Muskingum parameters be adjusted in the Parameter File'\n DEALLOCATE ( K_coef, X_coef)\n\n Basin_segment_storage = Basin_segment_storage*Basin_area_inv/Cfs_conv\n\n END FUNCTION muskingum_init\n\n!***********************************************************************\n! muskingum_run - Compute routing summary values\n!***********************************************************************\n INTEGER FUNCTION muskingum_run()\n USE PRMS_MUSKINGUM\n USE PRMS_MODULE, ONLY: Nsegment\n USE PRMS_BASIN, ONLY: CFS2CMS_CONV, Basin_area_inv, Obsin_segment, Segment_order, Tosegment\n USE PRMS_FLOWVARS, ONLY: Basin_ssflow, Basin_cms, Basin_gwflow_cfs, Basin_ssflow_cfs, &\n & Basin_stflow_out, Basin_cfs, Basin_stflow_in, Basin_sroff_cfs, Seg_inflow, Seg_outflow, Seg_upstream_inflow, &\n & Seg_lateral_inflow, Flow_out\n USE PRMS_OBS, ONLY: Streamflow_cfs\n USE PRMS_SET_TIME, ONLY: Cfs_conv\n USE PRMS_SRUNOFF, ONLY: Basin_sroff\n USE PRMS_GWFLOW, ONLY: Basin_gwflow\n IMPLICIT NONE\n! Functions\n INTRINSIC MOD\n! Local Variables\n INTEGER :: i, j, iorder, toseg, imod, tspd\n DOUBLE PRECISION :: area_fac, currin\n!***********************************************************************\n muskingum_run = 0\n\n! SET yesterdays inflows and outflows into temp (past arrays)\n! values may be 0.0 as intial, > 0.0 for runtime and dynamic\n! initial condtions. Then set outlfow and inflow for this time\n! step to 0.0\n!\n! upstream_inflow and outflow will vary by hour\n! lateral_inflow and everything else will vary by day\n!\n! Compute surface runoff, ssflow, and gwflow going to each segment\n! This is todays \"seg_inflow\" before additional water is routed to\n! a new (if any is routed)\n!\n! For each HRU if the lateral flow for this HRU goes to the\n! segment being evaluated (segment i) then sum flows\n!\n! Do these calculations once for the current day, before the hourly\n! routing starts.\n!\n! Out2 = In2*C0 + In1*C1 + Out1*C2\n! Seg_outflow = Seg_inflow*Czero + Pastinflow*Cone + Pastoutflow*Ctwo\n! C0, C1, and C2: initialized in the \"init\" part of this module\n!\n Pastin = Seg_inflow\n Pastout = Seg_outflow\n Seg_inflow = 0.0D0\n Seg_outflow = 0.0D0\n Inflow_ts = 0.0D0\n Currinsum = 0.0D0\n\n! 24 hourly timesteps per day\n DO j = 1, 24\n\n Seg_upstream_inflow = 0.0D0\n DO i = 1, Nsegment\n iorder = Segment_order(i)\n\n! current inflow to the segment is the time weighted average of the outflow\n! of the upstream segments plus the lateral HRU inflow plus any gains.\n currin = Seg_lateral_inflow(iorder)\n IF ( Obsin_segment(iorder)>0 ) Seg_upstream_inflow(iorder) = Streamflow_cfs(Obsin_segment(iorder))\n currin = currin + Seg_upstream_inflow(iorder)\n Seg_inflow(iorder) = Seg_inflow(iorder) + currin\n Inflow_ts(iorder) = Inflow_ts(iorder) + currin\n Currinsum(iorder) = Currinsum(iorder) + Seg_upstream_inflow(iorder)\n\n ! Check to see if this segment is to be routed on this time step\n tspd = Ts_i(iorder)\n imod = MOD( j, tspd )\n IF ( imod==0 ) THEN\n Inflow_ts(iorder) = (Inflow_ts(iorder) / Ts(iorder))\n! Compute routed streamflow\n IF ( Ts_i(iorder)>0 ) THEN\n! Muskingum routing equation\n Outflow_ts(iorder) = Inflow_ts(iorder)*C0(iorder) + Pastin(iorder)*C1(iorder) + Outflow_ts(iorder)*C2(iorder)\n ELSE\n! If travel time (K_coef paremter) is less than or equal to\n! time step (one hour), then the outflow is equal to the inflow\n! Outflow_ts is the value from last hour\n Outflow_ts(iorder) = Inflow_ts(iorder)\n ENDIF\n\n ! pastin is equal to the Inflow_ts on the previous routed timestep\n Pastin(iorder) = Inflow_ts(iorder)\n\n! because the upstream inflow from streams is used, reset it to zero so new average\n! can be computed next routing timestep.\n Inflow_ts(iorder) = 0.0D0\n ENDIF\n\n ! Seg_outflow (the mean daily flow rate for each segment) will be the average of the hourly values.\n Seg_outflow(iorder) = Seg_outflow(iorder) + Outflow_ts(iorder)\n ! pastout is equal to the Inflow_ts on the previous routed timestep\n Pastout(iorder) = Outflow_ts(iorder)\n\n! Add current timestep's flow rate to sum the upstream flow rates.\n! This can be thought of as a volume because it is a volumetric rate\n! (cubic feet per second) over a time step of an hour. Down below when\n! this value is used, it will be divided by the number of hours in the\n! segment's simulation time step, giving the mean flow rate over that\n! period of time.\n toseg = Tosegment(iorder)\n IF ( toseg>0 ) Seg_upstream_inflow(toseg) = Seg_upstream_inflow(toseg) + Outflow_ts(iorder)\n\n ENDDO ! segment\n\n ENDDO ! timestep\n\n Basin_segment_storage = 0.0D0\n Flow_out = 0.0D0\n DO i = 1, Nsegment\n Seg_outflow(i) = Seg_outflow(i) * ONE_24TH\n Seg_inflow(i) = Seg_inflow(i) * ONE_24TH\n Seg_upstream_inflow(i) = Currinsum(i) * ONE_24TH\n! Flow_out is the total flow out of the basin, which allows for multiple outlets\n! includes closed basins (tosegment=0)\n IF ( Tosegment(i)==0 ) Flow_out = Flow_out + Seg_outflow(i)\n Segment_delta_flow(i) = Segment_delta_flow(i) + Seg_inflow(i) - Seg_outflow(i)\n Basin_segment_storage = Basin_segment_storage + Segment_delta_flow(i)\n ENDDO\n\n area_fac = Cfs_conv/Basin_area_inv\n Basin_stflow_in = Basin_sroff + Basin_gwflow + Basin_ssflow ! not equal to stflow_out if replacement flows\n Basin_cfs = Flow_out\n Basin_stflow_out = Basin_cfs / area_fac\n Basin_cms = Basin_cfs*CFS2CMS_CONV\n Basin_sroff_cfs = Basin_sroff*area_fac\n Basin_ssflow_cfs = Basin_ssflow*area_fac\n Basin_gwflow_cfs = Basin_gwflow*area_fac\n Basin_segment_storage = Basin_segment_storage/area_fac\n\n END FUNCTION muskingum_run\n\n!***********************************************************************\n! muskingum_restart - write or read restart file\n!***********************************************************************\n SUBROUTINE muskingum_restart(In_out)\n USE PRMS_MODULE, ONLY: Restart_outunit, Restart_inunit\n USE PRMS_MUSKINGUM\n IMPLICIT NONE\n ! Argument\n INTEGER, INTENT(IN) :: In_out\n ! Function\n EXTERNAL check_restart\n ! Local Variable\n CHARACTER(LEN=9) :: module_name\n!***********************************************************************\n IF ( In_out==0 ) THEN\n WRITE ( Restart_outunit ) MODNAME\n WRITE ( Restart_outunit ) Basin_segment_storage\n WRITE ( Restart_outunit ) Segment_delta_flow\n WRITE ( Restart_outunit ) Outflow_ts\n WRITE ( Restart_outunit ) Pastin\n WRITE ( Restart_outunit ) Pastout\n ELSE\n READ ( Restart_inunit ) module_name\n CALL check_restart(MODNAME, module_name)\n READ ( Restart_inunit ) Basin_segment_storage\n READ ( Restart_inunit ) Segment_delta_flow\n READ ( Restart_inunit ) Outflow_ts\n READ ( Restart_inunit ) Pastin\n READ ( Restart_inunit ) Pastout\n ENDIF\n END SUBROUTINE muskingum_restart\n", "meta": {"hexsha": "34b7cd697467c46453f6482f472fc5870b50dea6", "size": 20966, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "prms/muskingum.f90", "max_stars_repo_name": "iyanuobidele/prms-on-pegasus", "max_stars_repo_head_hexsha": "a649b09d6fc5f905e95c638f3485e33c57152ea0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "prms/muskingum.f90", "max_issues_repo_name": "iyanuobidele/prms-on-pegasus", "max_issues_repo_head_hexsha": "a649b09d6fc5f905e95c638f3485e33c57152ea0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "prms/muskingum.f90", "max_forks_repo_name": "iyanuobidele/prms-on-pegasus", "max_forks_repo_head_hexsha": "a649b09d6fc5f905e95c638f3485e33c57152ea0", "max_forks_repo_licenses": ["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.1905697446, "max_line_length": 123, "alphanum_fraction": 0.5877134408, "num_tokens": 5915, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951661947456, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.6916153513859958}} {"text": " subroutine intrinsic01\n\n intrinsic abs,exp,sqrt\n \n read *, x\n\n print *, abs(sqrt(x))\n\n end\n", "meta": {"hexsha": "f9f2ac617935854bf41eadcfa09c718cf4d21c22", "size": 118, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "packages/PIPS/validation/Syntax/intrinsic01.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/Syntax/intrinsic01.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/Syntax/intrinsic01.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": 11.8, "max_line_length": 29, "alphanum_fraction": 0.5169491525, "num_tokens": 29, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.855851154320682, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.6915852574878295}} {"text": "MODULE DUALSIMP_MOD\n! Fortran 90 module for solving the asymetric dual of a problem\n!\n! max C^T X\n! s.t. A X \\leq B\n!\n! where A is dense and the dual solution is unique.\n!\n! As far as the author knows, this code has tested robust in all situations\n! where Y is unique. However, this code exists primarily for learning\n! purposes, and has not been thoroughly tested for robustness. Neither does\n! it represent the most efficient method for solving LPs of the above form\n! in many situations.\n!\n! Two subroutines are provided:\n!\n! DUALSIMPLEX for solving an LP when the initial basis is known (Phase II of\n! the simplex algorithm),\n!\n! and\n!\n! FEASIBLEBASIS for finding an initial dual feasible basis when none is\n! known (Phase I of the simplex algorithm) by solving the auxiliary\n! problem using DUALSIMPLEX.\n!\n! Author: Tyler Chang\n! Last Update: July, 2019\n\n! Includes the R8 data type for approximately 64-bit precision.\nINTEGER, PARAMETER:: R8=SELECTED_REAL_KIND(13)\n\nCONTAINS\n\nSUBROUTINE DUALSIMPLEX (N, M, AT, B, C, IBASIS, X, Y, IERR, &\n & EPS, IBUDGET, OBASIS)\n! Solves a primal problem of the form\n!\n! maximize C^T X\n! such that A X \\leq B\n!\n! where A \\in R^{M \\times N}, C,X \\in R^N, and B \\in R^M.\n!\n! Assuming M > N, this is done most efficiently by applying the simplex\n! method on the asymmetric dual problem\n!\n! minimize B^T Y\n! such that A^T Y = C\n! and Y \\geq 0\n!\n! where Y \\in R^M.\n!\n! To solve the dual problem, the revised simplex algorithm is applied. In\n! each iteration of the dual simplex algorithm, a complete LU factorization\n! is performed via DGETRF. Dantzig's rule is used to pivot, until either a\n! solution is found, or a pivot does not improve the objective. When a pivot\n! fails to improve the objective, Bland's rule is used until improvement\n! resumes, at which point Dantzig's pivoting strategy is resumed.\n!\n! This strategy is most effective when A is dense and when M > N. For\n! efficient memory access patterns, the constraints are specified by\n! inputting A^T instead of A. For efficient linear algebra, LAPACK is\n! used for computing LU factorizations and performing triangular solve\n! operations, and BLAS is used for computing dot products and matrix-vector\n! multiplication.\n!\n! While a complete LU factorization in each iteration produces maximum\n! numerical stability, a Woodbury update could alternatively be performed\n! if iteration speed is of greater concern. When M >> N, the cost of the\n! LU factorization is negligible compared to other computational costs,\n! and the difference in speed would be negligible.\n!\n! On input:\n!\n! N is the integer number of variables in the primal problem.\n!\n! M is the integer number of constraints in the primal problem.\n!\n! AT(N,M) is the transpose of the real valued constraint matrix A.\n!\n! B(M) is the real valued vector of upper bounds for the constraints.\n!\n! C(N) is the real valued cost vector for the objective function.\n!\n! IBASIS(N) is an integer valued vector containing the indices\n! (from AT) of an intitial basis that is dual feasible.\n!\n! On output:\n!\n! X(N) is a real valued vector, which contains the primal solution.\n!\n! Y(M) is a real valued vector, which contains the dual solution.\n!\n! IERR is an integer valued error flag. The error codes are listed below:\n!\n! Tens-digit is 0:\n!\n! These codes indicate expected termination conditions.\n!\n! 0 : C^T X has been successfully maximized.\n! 1 : The dual problem is unbounded, therefore the primal must be infeasible.\n!\n! Tens-digit is 1:\n!\n! These codes indicate that the problem dimensions do not agree.\n!\n! 10 : Illegal problem dimensions: N < 1.\n! 11 : Illegal problem dimensions: M < N. If you wish to solve a problem with\n! more variables than constraints, consider using a primal method.\n! 12 : N does not match the first dimension of the constraint matrix AT.\n! 13 : M does not match the second dimension of the constraint matrix AT.\n! 14 : M does not match the length of the upper bounds B.\n! 15 : N does not match the length of the cost vector C.\n! 16 : N does not match the length of the initial basis IBASIS.\n! 17 : N does not match the length of the primal solution vector X.\n! 18 : M does not match the length of the dual solution vector Y.\n!\n! Tens-digit is 2:\n!\n! These codes indicate that the optional arguments contain illegal values\n! or dimensions.\n!\n! 20 : The optional argument EPS must be strictly positive.\n! 21 : The optional argument IBUDGET must be nonnegative.\n! 22 : The optional argument OBASIS must be length N.\n!\n! Tens-digit is 3:\n!\n! These codes indicate that the initial basis (IBASIS) was not feasible.\n!\n! 30 : The provided initial basis IBASIS for AT contains indices that are\n! out of the bounds of AT (either greater than M or less than 1).\n! 31 : The provided initial basis IBASIS for AT contains duplicate indices,\n! making it rank-deficient.\n! 32 : The provided initial basis IBASIS for AT, while not redundant,\n! produced a singularity\n! 33 : The provided initial basis IBASIS for AT is not feasible.\n!\n! Tens-digit is 4:\n!\n! These codes indicate\n!\n! 40 : The pivot budget (IBUDGET) was exceeded before a solution could be\n! found. Consider increasing IBUDGET, or increasing the working\n! precision EPS.\n! 41 : A pivot has produced a singular basis. Consider increasing the\n! working precision (EPS).\n! \n! Tens-digit is 5:\n!\n! These codes indicate a LAPACK error. If one of these errors occurs,\n! it most likely indicates a system or compiler failure of some kind.\n!\n! 50 : The subroutine DGETRF reported an illegal value (rare).\n! 51 : The subroutine DGETRS reported an illegal value (rare).\n!\n! Optional arguments:\n!\n! EPS contains the working precision for the problem. EPS must be a\n! strictly positive real number, and by default EPS is the square-root of\n! the unit roundoff.\n!\n! IBUDGET contains the integer budget for the maximum number of pivots\n! allowed. By default, IBUDGET=50,000.\n!\n! When present, OBASIS(:) returns the integer indices of the final basis\n! as listed in AT.\n\nIMPLICIT NONE\n! Parameter list.\nINTEGER, INTENT(IN) :: N\nINTEGER, INTENT(IN) :: M\nREAL(KIND=R8), INTENT(IN) :: AT(:,:)\nREAL(KIND=R8), INTENT(IN) :: B(:)\nREAL(KIND=R8), INTENT(IN) :: C(:)\nINTEGER, OPTIONAL, INTENT(INOUT) :: IBASIS(:)\nREAL(KIND=R8), INTENT(OUT) :: X(:)\nREAL(KIND=R8), INTENT(OUT) :: Y(:)\nINTEGER, INTENT(OUT) :: IERR\nREAL(KIND=R8), OPTIONAL, INTENT(IN) :: EPS\nINTEGER, OPTIONAL, INTENT(IN) :: IBUDGET\nINTEGER, OPTIONAL, INTENT(OUT) :: OBASIS(:)\n! Local variables.\nINTEGER :: I, J, IBUDGETL\nREAL(KIND=R8) :: EPSL, NEWSOL, OLDSOL\nINTEGER :: IPIV(N), JPIV(M)\nREAL(KIND=R8) :: APIV(N,M), BPIV(M), S(M-N), LU(N,N)\n! External procedures.\nREAL(KIND=R8), EXTERNAL :: DDOT ! Inner product (BLAS).\nEXTERNAL :: DGEMV ! General matrix vector multiply (BLAS)\nEXTERNAL :: DGETRF ! Perform a LU factorization with partial pivoting (LAPACK).\nEXTERNAL :: DGETRS ! Use the output of DGETRF to solve a linear system (LAPACK).\n\n! Check inputs for errors.\nIF (N < 1) THEN\n IERR = 10; RETURN\nELSE IF (M < N) THEN\n IERR = 11; RETURN\nELSE IF (SIZE(AT,1) .NE. N) THEN\n IERR = 12; RETURN\nELSE IF (SIZE(AT,2) .NE. M) THEN\n IERR = 13; RETURN\nELSE IF (SIZE(B,1) .NE. M) THEN\n IERR = 14; RETURN\nELSE IF (SIZE(C,1) .NE. N) THEN\n IERR = 15; RETURN\nELSE IF (SIZE(IBASIS,1) .NE. N) THEN\n IERR = 16; RETURN\nELSE IF (SIZE(X,1) .NE. N) THEN\n IERR = 17; RETURN\nELSE IF (SIZE(Y,1) .NE. M) THEN\n IERR = 18; RETURN\nEND IF\n! Check for optionals.\nIF (PRESENT(EPS)) THEN\n IF(EPS .LE. 0.0_R8) THEN ! Must be strictly positive.\n IERR = 20; RETURN; END IF\n EPSL = EPS\nELSE ! Set the default value.\n EPSL = EPSILON(0.0_R8)\nEND IF\nIF (PRESENT(IBUDGET)) THEN\n IF(IBUDGET < 0) THEN ! Must be nonnegative.\n IERR = 21; RETURN; END IF\n IBUDGETL = IBUDGET\nELSE ! Set the default value.\n IBUDGETL = 50000\nEND IF\nIF (PRESENT(OBASIS)) THEN\n IF(SIZE(OBASIS, 1) .NE. N) THEN ! Must match the size of IBASIS.\n IERR = 22; RETURN; END IF\n OBASIS = 0 ! Initialize to zeros.\nEND IF\n\n! Check for issues with the initial basis, IBASIS.\nIF (ANY(IBASIS < 1) .OR. ANY(IBASIS > M)) THEN ! Check for illegal values.\n IERR = 30; RETURN; END IF\nDO I = 1, N ! Check for illegal bases.\n IF (ANY(IBASIS(I+1:N) .EQ. IBASIS(I))) THEN\n IERR = 31; RETURN; END IF\nEND DO\n\n! Initialize JPIV.\nFORALL ( I = 1 : M ) JPIV(I) = I\n! Initilaize APIV and BPIV.\nAPIV(:,:) = AT(:,:)\nBPIV(:) = B(:)\n! Pivot the indices of APIV and BPIV to match IBASIS.\nDO I = 1, N\n ! Locate the current index of the basis element (after swapping).\n DO J = 1, M\n IF (JPIV(J) .EQ. IBASIS(I)) EXIT\n END DO\n ! Pivot APIV and BPIV to match the initial basis specified in IBASIS.\n CALL DSWAP(N, APIV(:,I), 1, APIV(:,J), 1)\n OLDSOL = BPIV(I)\n BPIV(I) = BPIV(J)\n BPIV(J) = OLDSOL\n ! Track the changes in JPIV.\n IPIV(1) = JPIV(I)\n JPIV(I) = JPIV(J)\n JPIV(J) = IPIV(1)\nEND DO\n\n! Get a solution using the LU factorization.\nLU(:,:) = APIV(:,1:N)\nCALL DGETRF(N, N, LU, N, IPIV, IERR)\nIF (IERR > 0) THEN ! LU is exactly singular.\n IERR = 32; RETURN\nELSE IF (IERR < 0) THEN\n IERR = 50; RETURN; END IF\n! Use the LU factorization to get the first N elements of the dual solution.\nY(1:N) = C(:)\nCALL DGETRS('N', N, 1, LU, N, IPIV, Y, M, IERR)\nIF (IERR .NE. 0) THEN\n IERR = 51; RETURN; END IF\nIF (ANY(Y(1:N) .LT. -EPSL)) THEN\n IERR = 33; RETURN; END IF\nY(N+1:M) = 0.0_R8 ! The last N elements are zeros.\n! Given S(1:N)=0, use the LU factorization to get the primal solution.\nX(:) = BPIV(1:N)\nCALL DGETRS('T', N, 1, LU, N, IPIV, X, N, IERR)\nIF (IERR .NE. 0) THEN\n IERR = 51; RETURN; END IF\n! Get the rest of the slack variables by solving B - A*X for the kernel.\nS(:) = BPIV(N+1:M)\nCALL DGEMV('T', N, M-N, -1.0_R8, APIV(:,N+1:M), N, X, 1, 1.0_R8, S, 1)\n! Check if the KKT conditions have been satisfied.\nIF (ALL(S .GE. -EPSL) ) THEN\n IERR = 0\n ! Undo the pivots in Y, so that Y can be output.\n CALL DLAPMT( .FALSE., 1, M, Y, 1, JPIV )\n ! Store the final basis in OBASIS.\n IF(PRESENT(OBASIS)) OBASIS(:) = JPIV(1:N)\n RETURN\nEND IF\n\n! If not, compute the current solution and begin the iteration.\nNEWSOL = DDOT(N, BPIV, 1, Y, 1)\nOLDSOL = NEWSOL + 1.0_R8\n! Loop until a solution is found.\nDO I = 1, IBUDGETL\n ! Choose the pivot rule based on the improvement.\n IF (OLDSOL - NEWSOL > EPSL) THEN\n CALL PIVOT_DANTZIG() ! Use Dantzig's rule when improvement is made.\n IF (IERR .NE. 0) RETURN\n ELSE\n CALL PIVOT_BLAND() ! Use Bland's rule when stalled.\n IF (IERR .NE. 0) RETURN\n END IF\n ! Get a new solution using the LU factorization.\n LU(:,:) = APIV(:,1:N)\n CALL DGETRF(N, N, LU, N, IPIV, IERR)\n IF (IERR > 0) THEN ! LU is exactly singular.\n IERR = 41; RETURN\n ELSE IF (IERR < 0) THEN\n IERR = 50; RETURN; END IF\n ! Use the LU factorization to get the first N elements of the dual solution.\n Y(1:N) = C(:)\n CALL DGETRS('N', N, 1, LU, N, IPIV, Y, M, IERR)\n IF (IERR .NE. 0) THEN\n IERR = 51; RETURN; END IF\n ! Given S(1:N)=0, use the LU factorization to get the primal solution.\n X(:) = BPIV(1:N)\n CALL DGETRS('T', N, 1, LU, N, IPIV, X, N, IERR)\n IF (IERR .NE. 0) THEN\n IERR = 51; RETURN; END IF\n ! Get the rest of the slack variables by solving B - A*X for the kernel.\n S(:) = BPIV(N+1:M)\n CALL DGEMV('T', N, M-N, -1.0_R8, APIV(:,N+1:M), N, X, 1, 1.0_R8, S, 1)\n ! Check if the KKT conditions are satisfied.\n IF (ALL(S .GE. -EPSL) ) THEN\n ! Undo the pivots in Y, so that Y can be output.\n CALL DLAPMT( .FALSE., 1, M, Y, 1, JPIV )\n ! Store the final basis in OBASIS.\n IF(PRESENT(OBASIS)) OBASIS(:) = JPIV(1:N)\n RETURN\n END IF\n ! Save the current solution and update the new solution.\n OLDSOL = NEWSOL\n NEWSOL = DDOT(N, BPIV, 1, Y, 1)\nEND DO\n! Budget expired.\nIERR = 40\nRETURN\n\nCONTAINS\n\nSUBROUTINE PIVOT_DANTZIG()\n! Pivot using Dantzig's minimum ratio method for fast convergence.\n!\n! On input, assume that APIV(:,:) contains the basis and kernel of AT,\n! in that order. Also, assume that LU contains the LU factorization\n! of the basis and IPIV contains the corresponding pivot indices.\n! Also assume that Y contains a dual feasible solution and S contains\n! the non-basic slack variables.\n!\n! Given the above, compute the entering and exiting indices (IENTER and IEXIT)\n! and update APIV(:,:) and BPIV(:) accordingly, tracking the pivots in JPIV.\nINTEGER :: IENTER, IEXIT\nREAL(KIND=R8) :: W(N), CURRMIN\n! Compute the entering index.\nIENTER = MINLOC(S, 1) + N\n! Build a weight vector for the entering vertex using the LU factorization.\nW(:) = APIV(:,IENTER)\nCALL DGETRS('N', N, 1, LU, N, IPIV, W, N, IERR)\nIF (IERR .NE. 0) THEN\n IERR = 51; RETURN; END IF\n! Compute the weight ratios and choose the exiting index.\nCURRMIN = HUGE(0.0_R8)\nIEXIT = 0\nDO J = 1, N\n IF (W(J) .LT. EPSL) CYCLE\n W(J) = Y(J) / W(J)\n IF (W(J) < CURRMIN) THEN\n CURRMIN = W(J)\n IEXIT = J\n END IF\nEND DO\n! Check that an exiting index was found.\nIF (IEXIT .EQ. 0) THEN\n IERR = 1\n RETURN\nEND IF\n! Perform the pivot operation on both AT and B.\nCALL DSWAP(N, APIV(:,IEXIT), 1, APIV(:,IENTER), 1) ! Pivot AT using DSWAP.\nW(1) = BPIV(IEXIT) ! Pivot B using W(1) as a temp variable.\nBPIV(IEXIT) = BPIV(IENTER)\nBPIV(IENTER) = W(1)\n! Record the pivot in JPIV(:).\nJ = JPIV(IENTER)\nJPIV(IENTER) = JPIV(IEXIT)\nJPIV(IEXIT) = J\nRETURN\nEND SUBROUTINE PIVOT_DANTZIG\n\nSUBROUTINE PIVOT_BLAND()\n! Pivot using Bland's anticycling rule to guarantee convergence on degenerate\n! point sets.\n!\n! On input, assume that APIV(:,:) contains the basis and kernel of AT,\n! in that order. Also, assume that LU contains the LU factorization\n! of the basis and IPIV contains the corresponding pivot indices.\n! Also assume that Y contains a dual feasible solution and S contains\n! the non-basic slack variables.\n!\n! Given the above, compute the entering and exiting indices (IENTER and IEXIT)\n! and update APIV(:,:) and BPIV(:) accordingly, tracking the pivots in JPIV.\nINTEGER :: IENTER, IEXIT\nREAL(KIND=R8) :: W(N), CURRMIN\n! Compute the entering index. It is the first negative entry in the kernel.\nDO J = 1, M-N\n IF(S(J) < -EPSL) THEN\n IENTER = J+N; EXIT; END IF\nEND DO\n! Build a weight vector for the entering vertex using the LU factorization.\nW(:) = APIV(:,IENTER)\nCALL DGETRS('N', N, 1, LU, N, IPIV, W, N, IERR)\nIF (IERR .NE. 0) THEN\n IERR = 51; RETURN; END IF\n! Compute the weight ratios and choose the exiting index.\nCURRMIN = HUGE(0.0_R8)\nIEXIT = 0\nDO J = 1, N\n IF (W(J) .LT. EPSL) CYCLE\n W(J) = Y(J) / W(J)\n IF (W(J) - CURRMIN < -EPSL) THEN\n CURRMIN = W(J)\n IEXIT = J\n END IF\nEND DO\n! Check that an exiting index was found.\nIF (IEXIT .EQ. 0) THEN\n IERR = 1\n RETURN\nEND IF\n! Perform the pivot operation on both AT and B.\nCALL DSWAP(N, APIV(:,IEXIT), 1, APIV(:,IENTER), 1) ! Pivot AT using DSWAP.\nW(1) = BPIV(IEXIT) ! Pivot B using W(1) as a temp variable.\nBPIV(IEXIT) = BPIV(IENTER)\nBPIV(IENTER) = W(1)\n! Record the pivot in JPIV(:).\nJ = JPIV(IENTER)\nJPIV(IENTER) = JPIV(IEXIT)\nJPIV(IEXIT) = J\nRETURN\nEND SUBROUTINE PIVOT_BLAND\n\nEND SUBROUTINE DUALSIMPLEX\n\nSUBROUTINE FEASIBLEBASIS (N, M, AT, C, BASIS, IERR, EPS, IBUDGET)\n! Implement the simplex method to find a dual feasible basis for a primal\n! problem of the form\n!\n! maximize C^T X\n! such that A X \\leq B\n!\n! where A \\in R^{M \\times N}, X \\in R^N, and B \\in R^M.\n!\n! The asymmetric dual problem is then of the form\n!\n! minimize B^T Y\n! such that A^T Y = C\n! and Y \\geq 0\n!\n! where Y \\in R^M.\n!\n! A basis V \\in R^{N \\times N} for A^T is dual feasible if V Y = C is\n! solvable with Y \\geq 0.\n!\n! Find the indices of A corresponding to V by solving the auxiliary problem\n!\n! minimize SUM(Z)\n! such that A_AUX [Z^T Y^T]^T = C\n! and Z \\geq 0, Y \\geq 0.\n!\n! where Z \\in R^N and A_AUX = [ SIGN_N | A^T ] \\in R^{N \\times N+M}.\n! Here, SIGN_N denotes the N-by-N identity matrix, except that when\n! C(I) < 0 then SIGN_N(I,I) = -1.\n!\n! Trivially, columns 1, ..., N of A_AUX provide an initial basis for this\n! problem, with solution Z = ABS(B) and Y = 0. When SUM(Z) has been minimized,\n! if SUM(Z) > 0, the problem is infeasible. Otherwise, if SUM(Z) = 0, then\n! a feasible basis is given by the columns of A^T that are in the basis of\n! A_AUX.\n!\n! Uses DUALSIMPLEX to solve the auxiliary problem.\n!\n! On input:\n!\n! N is the integer number of variables in the primal problem.\n!\n! M is the integer number of constraints in the primal problem.\n!\n! AT(N,M) is the transpose of the real valued constraint matrix A.\n!\n! C(N) is the real valued cost vector for the objective function.\n!\n! On output:\n!\n! BASIS(N) is an integer valued vector, which contains the indices of a\n! dual feasible basis for AT.\n!\n! IERR is an integer valued error flag. The error codes are listed below:\n!\n! Tens-digit is 0:\n!\n! These codes indicate expected termination conditions.\n!\n! 0 : C^T X has been successfully maximized.\n! 1 : The dual problem is unbounded, therefore the primal must be infeasible.\n! 2 : The dual problem is infeasible, the primal may be unbounded or\n! infeasible.\n!\n! Tens-digit is 1:\n!\n! These codes indicate that the problem dimensions do not agree.\n!\n! 10 : Illegal problem dimensions: N < 1.\n! 11 : Illegal problem dimensions: M < N. If you wish to solve a problem with\n! more variables than constraints, consider using a primal method.\n! 12 : N does not match the first dimension of the constraint matrix AT.\n! 13 : M does not match the second dimension of the constraint matrix AT.\n! 15 : N does not match the length of the cost vector C.\n! 16 : N does not match the length of the output BASIS.\n!\n! Tens-digit is 2:\n!\n! These codes indicate that the optional arguments contain illegal values\n! or dimensions.\n!\n! 20 : The optional argument EPS must be strictly positive.\n! 21 : The optional argument IBUDGET must be nonnegative.\n!\n! Tens-digit is 4:\n!\n! These codes indicate\n!\n! 40 : The pivot budget (IBUDGET) was exceeded before a solution could be\n! found. Consider increasing IBUDGET, or increasing the working\n! precision EPS.\n! 41 : A pivot has produced a singular basis. Consider increasing the\n! working precision (EPS).\n! \n! Tens-digit is 5:\n!\n! These codes indicate a LAPACK error. If one of these errors occurs,\n! it most likely indicates a system or compiler failure of some kind.\n!\n! 50 : The subroutine DGETRF reported an illegal value (rare).\n! 51 : The subroutine DGETRS reported an illegal value (rare).\n!\n! Optional arguments:\n!\n! EPS contains the working precision for the problem. EPS must be a\n! strictly positive real number, and by default EPS is the square-root of\n! the unit roundoff.\n!\n! IBUDGET contains the integer budget for the maximum number of pivots\n! allowed. By default, IBUDGET=50,000.\n\nIMPLICIT NONE\n! Parameter list.\nINTEGER, INTENT(IN) :: N\nINTEGER, INTENT(IN) :: M\nREAL(KIND=R8), INTENT(IN) :: AT(:,:)\nREAL(KIND=R8), INTENT(IN) :: C(:)\nINTEGER, INTENT(OUT) :: BASIS(:)\nINTEGER, INTENT(OUT) :: IERR\nREAL(KIND=R8), OPTIONAL, INTENT(IN) :: EPS\nINTEGER, OPTIONAL, INTENT(IN) :: IBUDGET\n! Local variables.\nINTEGER :: I, IDX, IBUDGETL, IBASIS(N)\nREAL(KIND=R8) :: EPSL\nREAL(KIND=R8) :: A_AUX(N,N+M)\nREAL(KIND=R8) :: B_AUX(N+M)\nREAL(KIND=R8) :: Y_AUX(M+N)\nREAL(KIND=R8) :: X(N)\n! External (BLAS) function DDOT for inner products.\nREAL(KIND=R8), EXTERNAL :: DDOT\n\n! Check inputs for errors.\nIF (N < 1) THEN\n IERR = 10; RETURN\nELSE IF (M < N) THEN\n IERR = 11; RETURN\nELSE IF (SIZE(AT,1) .NE. N) THEN\n IERR = 12; RETURN\nELSE IF (SIZE(AT,2) .NE. M) THEN\n IERR = 13; RETURN\nELSE IF (SIZE(C,1) .NE. N) THEN\n IERR = 15; RETURN\nELSE IF (SIZE(BASIS,1) .NE. N) THEN\n IERR = 16; RETURN\nEND IF\n! Check for optionals.\nIF (PRESENT(EPS)) THEN\n IF(EPS .LE. 0.0_R8) THEN ! Must be strictly positive.\n IERR = 20; RETURN; END IF\n EPSL = EPS\nELSE ! Set the default value.\n EPSL = EPSILON(0.0_R8)\nEND IF\nIF (PRESENT(IBUDGET)) THEN\n IF(IBUDGET < 0) THEN ! Must be nonnegative.\n IERR = 21; RETURN; END IF\n IBUDGETL = IBUDGET\nELSE ! Set the default value.\n IBUDGETL = 50000\nEND IF\n\n! Copy AT into A_AUX to solve Phase 1 problem and zero B_AUX.\nA_AUX(:,N+1:N+M) = AT(:,:)\nB_AUX(1:N) = 1.0_R8\nB_AUX(N+1:N+M) = 0.0_R8\n! Create artificial variables to solve the problem.\nA_AUX(:,1:N) = 0.0_R8\nFORALL ( I = 1 : N ) A_AUX(I,I) = SIGN(1.0_R8, C(I))\n! Set IBASIS.\nFORALL (I = 1 : N) IBASIS(I) = I\n! Get solution.\nCALL DUALSIMPLEX(N, N+M, A_AUX, B_AUX, C, IBASIS, X, Y_AUX, IERR, &\n & EPS=EPSL, IBUDGET=IBUDGETL, OBASIS=BASIS)\nIF (IERR .NE. 0) RETURN\n! Check for infeasible dual solution.\nIF (DDOT(N, Y_AUX, 1, B_AUX, 1) > EPSL) THEN; IERR = 2; RETURN; END IF\nBASIS(:) = BASIS(:) - N\n! Check that all basis elements are legal (in case of degeneracies).\nDO I = 1, N\n IF (BASIS(I) < 1) THEN\n IDX = 1 ! Find an available legal basis element.\n DO WHILE (ANY(BASIS(:) .EQ. IDX)); IDX = IDX + 1; END DO\n BASIS(I) = IDX\n END IF\nEND DO\nRETURN\n\nEND SUBROUTINE FEASIBLEBASIS\n\nEND MODULE DUALSIMP_MOD\n", "meta": {"hexsha": "6bdd7fd42f39eef3460ab1750e86d8d140e3c35a", "size": 21020, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "dualsimplex.f90", "max_stars_repo_name": "thchang/DualSimplex", "max_stars_repo_head_hexsha": "1d1be4c1afec13224fc64b3125194cd7d6ce4e4b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-08-01T08:56:56.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-01T08:56:56.000Z", "max_issues_repo_path": "dualsimplex.f90", "max_issues_repo_name": "thchang/DualSimplex", "max_issues_repo_head_hexsha": "1d1be4c1afec13224fc64b3125194cd7d6ce4e4b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "dualsimplex.f90", "max_forks_repo_name": "thchang/DualSimplex", "max_forks_repo_head_hexsha": "1d1be4c1afec13224fc64b3125194cd7d6ce4e4b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-20T18:16:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T18:16:36.000Z", "avg_line_length": 32.84375, "max_line_length": 80, "alphanum_fraction": 0.6817316841, "num_tokens": 6809, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096112990283, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6915848751831141}} {"text": "c program DRDHTCC\nc>> 1994-10-19 DRDHTCC Krogh Changes to use M77CON\nc>> 1987-12-09 DRDHTCC Lawson Initial Code.\nc Demo driver for DHTCC, Householder transformations.\nc--D replaces \"?\": DR?HTCC, ?HTCC, ?MATP\n integer IDIM, JDIM, J, M, N\n parameter(IDIM = 3, JDIM = 5, M = 3, N = 2)\n double precision D(IDIM,JDIM), UPARAM, ZERO\n parameter(ZERO = 0.0D0)\n data (D(1,J),J=1,5) / 0.870D0, 0.796D0, 1.0D0, 0.0D0, 0.0D0 /\n data (D(2,J),J=1,5) / 0.571D0, -0.804D0, 0.0D0, 1.0D0, 0.0D0 /\n data (D(3,J),J=1,5) / -0.960D0, 0.346D0, 0.0D0, 0.0D0, 1.0D0 /\nc ------------------------------------------------------------------\n print*,'DRDHTCC.. Demonstrate computation of a QR decomposition.'\n print*,'Given matrix A, compute orthogonal Q and triangular R'\n print*,'such that A = Q * R.'\n call DMATP(D,IDIM,M,N,'0 A =')\n do 20002 J=1,N\n call DHTCC(1,J,J+1,M,D(1,J),UPARAM,D(1,J+1),IDIM,M+N-J)\n20002 continue\n call DMATP(D(1,N+1),IDIM,M,M,'0 Q [Transposed] =')\n D(2,1) = ZERO\n D(3,1) = ZERO\n D(3,2) = ZERO\n call DMATP(D,IDIM,M,N,'0 R =')\n stop\n end\n", "meta": {"hexsha": "99d407172b1c62da9d56c25e33c064257d452933", "size": 1167, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drdhtcc.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drdhtcc.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drdhtcc.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 41.6785714286, "max_line_length": 72, "alphanum_fraction": 0.5312767781, "num_tokens": 491, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425245706047, "lm_q2_score": 0.7520125848754471, "lm_q1q2_score": 0.6915827520637223}} {"text": "program Apollonius\n implicit none\n\n integer, parameter :: dp = selected_real_kind(15)\n\n type circle\n real(dp) :: x\n real(dp) :: y\n real(dp) :: radius\n end type\n\n type(circle) :: c1 , c2, c3, r\n\n c1 = circle(0.0, 0.0, 1.0)\n c2 = circle(4.0, 0.0, 1.0)\n c3 = circle(2.0, 4.0, 2.0)\n\n write(*, \"(a,3f12.8))\") \"External tangent:\", SolveApollonius(c1, c2, c3, 1, 1, 1)\n write(*, \"(a,3f12.8))\") \"Internal tangent:\", SolveApollonius(c1, c2, c3, -1, -1, -1)\n\ncontains\n\nfunction SolveApollonius(c1, c2, c3, s1, s2, s3) result(res)\n type(circle) :: res\n type(circle), intent(in) :: c1, c2, c3\n integer, intent(in) :: s1, s2, s3\n\n real(dp) :: x1, x2, x3, y1, y2, y3, r1, r2, r3\n real(dp) :: v11, v12, v13, v14\n real(dp) :: v21, v22, v23, v24\n real(dp) :: w12, w13, w14\n real(dp) :: w22, w23, w24\n real(dp) :: p, q, m, n, a, b, c, det\n\n x1 = c1%x; x2 = c2%x; x3 = c3%x\n y1 = c1%y; y2 = c2%y; y3 = c3%y\n r1 = c1%radius; r2 = c2%radius; r3 = c3%radius\n\n v11 = 2*x2 - 2*x1\n v12 = 2*y2 - 2*y1\n v13 = x1*x1 - x2*x2 + y1*y1 - y2*y2 - r1*r1 + r2*r2\n v14 = 2*s2*r2 - 2*s1*r1\n\n v21 = 2*x3 - 2*x2\n v22 = 2*y3 - 2*y2\n v23 = x2*x2 - x3*x3 + y2*y2 - y3*y3 - r2*r2 + r3*r3\n v24 = 2*s3*r3 - 2*s2*r2\n\n w12 = v12/v11\n w13 = v13/v11\n w14 = v14/v11\n\n w22 = v22/v21-w12\n w23 = v23/v21-w13\n w24 = v24/v21-w14\n\n p = -w23/w22\n q = w24/w22\n m = -w12*P - w13\n n = w14 - w12*q\n\n a = n*n + q*q - 1\n b = 2*m*n - 2*n*x1 + 2*p*q - 2*q*y1 + 2*s1*r1\n c = x1*x1 + m*m - 2*m*x1 + p*p + y1*y1 - 2*p*y1 - r1*r1\n\n det = b*b - 4*a*c\n res%radius = (-b-sqrt(det)) / (2*a)\n res%x = m + n*res%radius\n res%y = p + q*res%radius\n\nend function\nend program\n", "meta": {"hexsha": "4b0c72aec3928f5d5f91bf3bbae19e5339ca5894", "size": 1652, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Problem-of-Apollonius/Fortran/problem-of-apollonius.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/Problem-of-Apollonius/Fortran/problem-of-apollonius.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/Problem-of-Apollonius/Fortran/problem-of-apollonius.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.6301369863, "max_line_length": 86, "alphanum_fraction": 0.534503632, "num_tokens": 863, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425355825847, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6915827450112331}} {"text": "submodule(nf_random) nf_random_submodule\n implicit none\n\n real, parameter :: pi = 4 * atan(1.d0)\n\ncontains\n\n module function randn_1d(i) result(x)\n integer, intent(in) :: i\n real :: x(i)\n real :: u(i), v(i)\n call random_number(u)\n call random_number(v)\n x = sqrt(-2 * log(u)) * cos(2 * pi * v)\n end function randn_1d\n\n module function randn_2d(i, j) result(x)\n integer, intent(in) :: i, j\n real :: x(i,j)\n real :: u(i,j), v(i,j)\n call random_number(u)\n call random_number(v)\n x = sqrt(-2 * log(u)) * cos(2 * pi * v)\n end function randn_2d\n\n module function randn_4d(i, j, k, l) result(x)\n integer, intent(in) :: i, j, k, l\n real :: x(i,j,k,l)\n real :: u(i,j,k,l), v(i,j,k,l)\n call random_number(u)\n call random_number(v)\n x = sqrt(-2 * log(u)) * cos(2 * pi * v)\n end function randn_4d\n\nend submodule nf_random_submodule\n", "meta": {"hexsha": "973c84e847282046ad4cb1cb825ab255726dc0cf", "size": 882, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/nf_random_submodule.f90", "max_stars_repo_name": "rouson/neural-fortran", "max_stars_repo_head_hexsha": "c05368a5f36ea15bf2428c33c02b97c6f7d30c35", "max_stars_repo_licenses": ["MIT"], "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/nf_random_submodule.f90", "max_issues_repo_name": "rouson/neural-fortran", "max_issues_repo_head_hexsha": "c05368a5f36ea15bf2428c33c02b97c6f7d30c35", "max_issues_repo_licenses": ["MIT"], "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/nf_random_submodule.f90", "max_forks_repo_name": "rouson/neural-fortran", "max_forks_repo_head_hexsha": "c05368a5f36ea15bf2428c33c02b97c6f7d30c35", "max_forks_repo_licenses": ["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.5, "max_line_length": 48, "alphanum_fraction": 0.5975056689, "num_tokens": 299, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.919642533380189, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6915827433550038}} {"text": "REAL*8 function kern_num(x_a, y_a, x_b, y_b, lx, ly)\nimplicit none\nREAL*8, intent(in) :: x_a\nREAL*8, intent(in) :: y_a\nREAL*8, intent(in) :: x_b\nREAL*8, intent(in) :: y_b\nREAL*8, intent(in) :: lx\nREAL*8, intent(in) :: ly\nkern_num = cos(x_a - x_b)*cos(y_a - y_b)\nend function\nREAL*8 function dkdx_num(x_a, y_a, x_b, y_b, lx, ly)\nimplicit none\nREAL*8, intent(in) :: x_a\nREAL*8, intent(in) :: y_a\nREAL*8, intent(in) :: x_b\nREAL*8, intent(in) :: y_b\nREAL*8, intent(in) :: lx\nREAL*8, intent(in) :: ly\ndkdx_num = -sin(x_a - x_b)*cos(y_a - y_b)\nend function\nREAL*8 function dkdy_num(x_a, y_a, x_b, y_b, lx, ly)\nimplicit none\nREAL*8, intent(in) :: x_a\nREAL*8, intent(in) :: y_a\nREAL*8, intent(in) :: x_b\nREAL*8, intent(in) :: y_b\nREAL*8, intent(in) :: lx\nREAL*8, intent(in) :: ly\ndkdy_num = -sin(y_a - y_b)*cos(x_a - x_b)\nend function\nREAL*8 function dkdx0_num(x_a, y_a, x_b, y_b, lx, ly)\nimplicit none\nREAL*8, intent(in) :: x_a\nREAL*8, intent(in) :: y_a\nREAL*8, intent(in) :: x_b\nREAL*8, intent(in) :: y_b\nREAL*8, intent(in) :: lx\nREAL*8, intent(in) :: ly\ndkdx0_num = sin(x_a - x_b)*cos(y_a - y_b)\nend function\nREAL*8 function dkdy0_num(x_a, y_a, x_b, y_b, lx, ly)\nimplicit none\nREAL*8, intent(in) :: x_a\nREAL*8, intent(in) :: y_a\nREAL*8, intent(in) :: x_b\nREAL*8, intent(in) :: y_b\nREAL*8, intent(in) :: lx\nREAL*8, intent(in) :: ly\ndkdy0_num = sin(y_a - y_b)*cos(x_a - x_b)\nend function\nREAL*8 function d2kdxdx0_num(x_a, y_a, x_b, y_b, lx, ly)\nimplicit none\nREAL*8, intent(in) :: x_a\nREAL*8, intent(in) :: y_a\nREAL*8, intent(in) :: x_b\nREAL*8, intent(in) :: y_b\nREAL*8, intent(in) :: lx\nREAL*8, intent(in) :: ly\nd2kdxdx0_num = cos(x_a - x_b)*cos(y_a - y_b)\nend function\nREAL*8 function d2kdydy0_num(x_a, y_a, x_b, y_b, lx, ly)\nimplicit none\nREAL*8, intent(in) :: x_a\nREAL*8, intent(in) :: y_a\nREAL*8, intent(in) :: x_b\nREAL*8, intent(in) :: y_b\nREAL*8, intent(in) :: lx\nREAL*8, intent(in) :: ly\nd2kdydy0_num = cos(x_a - x_b)*cos(y_a - y_b)\nend function\nREAL*8 function d2kdxdy0_num(x_a, y_a, x_b, y_b, lx, ly)\nimplicit none\nREAL*8, intent(in) :: x_a\nREAL*8, intent(in) :: y_a\nREAL*8, intent(in) :: x_b\nREAL*8, intent(in) :: y_b\nREAL*8, intent(in) :: lx\nREAL*8, intent(in) :: ly\nd2kdxdy0_num = -sin(x_a - x_b)*sin(y_a - y_b)\nend function\nREAL*8 function d3kdxdx0dy0_num(x_a, y_a, x_b, y_b, lx, ly)\nimplicit none\nREAL*8, intent(in) :: x_a\nREAL*8, intent(in) :: y_a\nREAL*8, intent(in) :: x_b\nREAL*8, intent(in) :: y_b\nREAL*8, intent(in) :: lx\nREAL*8, intent(in) :: ly\nd3kdxdx0dy0_num = sin(y_a - y_b)*cos(x_a - x_b)\nend function\nREAL*8 function d3kdydy0dy0_num(x_a, y_a, x_b, y_b, lx, ly)\nimplicit none\nREAL*8, intent(in) :: x_a\nREAL*8, intent(in) :: y_a\nREAL*8, intent(in) :: x_b\nREAL*8, intent(in) :: y_b\nREAL*8, intent(in) :: lx\nREAL*8, intent(in) :: ly\nd3kdydy0dy0_num = sin(y_a - y_b)*cos(x_a - x_b)\nend function\nREAL*8 function d3kdxdy0dy0_num(x_a, y_a, x_b, y_b, lx, ly)\nimplicit none\nREAL*8, intent(in) :: x_a\nREAL*8, intent(in) :: y_a\nREAL*8, intent(in) :: x_b\nREAL*8, intent(in) :: y_b\nREAL*8, intent(in) :: lx\nREAL*8, intent(in) :: ly\nd3kdxdy0dy0_num = sin(x_a - x_b)*cos(y_a - y_b)\nend function\nINTEGER*4 function dkdlx_num(x_a, y_a, x_b, y_b, lx, ly)\nimplicit none\nREAL*8, intent(in) :: x_a\nREAL*8, intent(in) :: y_a\nREAL*8, intent(in) :: x_b\nREAL*8, intent(in) :: y_b\nREAL*8, intent(in) :: lx\nREAL*8, intent(in) :: ly\ndkdlx_num = 0\nend function\nINTEGER*4 function dkdly_num(x_a, y_a, x_b, y_b, lx, ly)\nimplicit none\nREAL*8, intent(in) :: x_a\nREAL*8, intent(in) :: y_a\nREAL*8, intent(in) :: x_b\nREAL*8, intent(in) :: y_b\nREAL*8, intent(in) :: lx\nREAL*8, intent(in) :: ly\ndkdly_num = 0\nend function\nINTEGER*4 function d3kdxdx0dlx_num(x_a, y_a, x_b, y_b, lx, ly)\nimplicit none\nREAL*8, intent(in) :: x_a\nREAL*8, intent(in) :: y_a\nREAL*8, intent(in) :: x_b\nREAL*8, intent(in) :: y_b\nREAL*8, intent(in) :: lx\nREAL*8, intent(in) :: ly\nd3kdxdx0dlx_num = 0\nend function\nINTEGER*4 function d3kdydy0dlx_num(x_a, y_a, x_b, y_b, lx, ly)\nimplicit none\nREAL*8, intent(in) :: x_a\nREAL*8, intent(in) :: y_a\nREAL*8, intent(in) :: x_b\nREAL*8, intent(in) :: y_b\nREAL*8, intent(in) :: lx\nREAL*8, intent(in) :: ly\nd3kdydy0dlx_num = 0\nend function\nINTEGER*4 function d3kdxdy0dlx_num(x_a, y_a, x_b, y_b, lx, ly)\nimplicit none\nREAL*8, intent(in) :: x_a\nREAL*8, intent(in) :: y_a\nREAL*8, intent(in) :: x_b\nREAL*8, intent(in) :: y_b\nREAL*8, intent(in) :: lx\nREAL*8, intent(in) :: ly\nd3kdxdy0dlx_num = 0\nend function\nINTEGER*4 function d3kdxdx0dly_num(x_a, y_a, x_b, y_b, lx, ly)\nimplicit none\nREAL*8, intent(in) :: x_a\nREAL*8, intent(in) :: y_a\nREAL*8, intent(in) :: x_b\nREAL*8, intent(in) :: y_b\nREAL*8, intent(in) :: lx\nREAL*8, intent(in) :: ly\nd3kdxdx0dly_num = 0\nend function\nINTEGER*4 function d3kdydy0dly_num(x_a, y_a, x_b, y_b, lx, ly)\nimplicit none\nREAL*8, intent(in) :: x_a\nREAL*8, intent(in) :: y_a\nREAL*8, intent(in) :: x_b\nREAL*8, intent(in) :: y_b\nREAL*8, intent(in) :: lx\nREAL*8, intent(in) :: ly\nd3kdydy0dly_num = 0\nend function\nINTEGER*4 function d3kdxdy0dly_num(x_a, y_a, x_b, y_b, lx, ly)\nimplicit none\nREAL*8, intent(in) :: x_a\nREAL*8, intent(in) :: y_a\nREAL*8, intent(in) :: x_b\nREAL*8, intent(in) :: y_b\nREAL*8, intent(in) :: lx\nREAL*8, intent(in) :: ly\nd3kdxdy0dly_num = 0\nend function\n", "meta": {"hexsha": "ec32476e05755328f08d6081e2fab54885718023", "size": 5186, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "draft/pendulum/cosine_prod/kernels.f90", "max_stars_repo_name": "krystophny/profit", "max_stars_repo_head_hexsha": "c6316c9df7cfaa7b30332fdbbf85ad27175eaf92", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2019-12-03T14:11:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-15T13:44:06.000Z", "max_issues_repo_path": "draft/pendulum/cosine_prod/kernels.f90", "max_issues_repo_name": "krystophny/profit", "max_issues_repo_head_hexsha": "c6316c9df7cfaa7b30332fdbbf85ad27175eaf92", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 118, "max_issues_repo_issues_event_min_datetime": "2019-11-16T19:51:26.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-26T13:52:00.000Z", "max_forks_repo_path": "draft/pendulum/cosine_prod/kernels.f90", "max_forks_repo_name": "krystophny/profit", "max_forks_repo_head_hexsha": "c6316c9df7cfaa7b30332fdbbf85ad27175eaf92", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2020-06-08T07:22:56.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-21T14:12:21.000Z", "avg_line_length": 27.1518324607, "max_line_length": 62, "alphanum_fraction": 0.6683378326, "num_tokens": 2163, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425311777929, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6915827416987743}} {"text": "C-----------------------------------------------------------------------\n SUBROUTINE MOVECT(FLAT,FLON,TLAT,TLON,CROT,SROT)\nC$$$ SUBPROGRAM DOCUMENTATION BLOCK\nC\nC SUBPROGRAM: MOVECT MOVE A VECTOR ALONG A GREAT CIRCLE\nC PRGMMR: IREDELL ORG: W/NMC23 DATE: 96-04-10\nC\nC ABSTRACT: THIS SUBPROGRAM PROVIDES THE ROTATION PARAMETERS\nC TO MOVE A VECTOR ALONG A GREAT CIRCLE FROM ONE\nC POSITION TO ANOTHER WHILE CONSERVING ITS ORIENTATION\nC WITH RESPECT TO THE GREAT CIRCLE. THESE ROTATION\nC PARAMETERS ARE USEFUL FOR VECTOR INTERPOLATION.\nC \nC PROGRAM HISTORY LOG:\nC 96-04-10 IREDELL\nC 1999-04-08 IREDELL GENERALIZE PRECISION\nC\nC USAGE: CALL MOVECT(FLAT,FLON,TLAT,TLON,CROT,SROT)\nC\nC INPUT ARGUMENT LIST:\nC FLAT - REAL LATITUDE IN DEGREES FROM WHICH TO MOVE THE VECTOR\nC FLON - REAL LONGITUDE IN DEGREES FROM WHICH TO MOVE THE VECTOR\nC TLAT - REAL LATITUDE IN DEGREES TO WHICH TO MOVE THE VECTOR\nC TLON - REAL LONGITUDE IN DEGREES TO WHICH TO MOVE THE VECTOR\nC\nC OUTPUT ARGUMENT LIST:\nC CROT - REAL CLOCKWISE VECTOR ROTATION COSINE\nC SROT - REAL CLOCKWISE VECTOR ROTATION SINE\nC (UTO=CROT*UFROM-SROT*VFROM;\nC VTO=SROT*UFROM+CROT*VFROM)\nC\nC REMARKS: THIS SUBPROGRAM IS CORRECT TO SEVEN DIGITS ON THE CRAYS.\nC USE DOUBLE PRECISION IF BETTER PRECISION IS REQUIRED.\nC\nC ATTRIBUTES:\nC LANGUAGE: FORTRAN 90\nC\nC$$$\n INTEGER,PARAMETER:: KD=SELECTED_REAL_KIND(15,45)\n REAL(KIND=KD):: PI,DPR,CRDLIM\n REAL(KIND=KD):: CTLAT,STLAT,CFLAT,SFLAT,CDLON,SDLON,CRD\n REAL(KIND=KD):: SRD2RN,STR,CTR,SFR,CFR\n PARAMETER(PI=3.14159265358979,DPR=180./PI)\n PARAMETER(CRDLIM=0.9999999)\nC - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\nC COMPUTE COSINE OF THE RADIAL DISTANCE BETWEEN THE POINTS.\n CTLAT=COS(TLAT/DPR)\n STLAT=SIN(TLAT/DPR)\n CFLAT=COS(FLAT/DPR)\n SFLAT=SIN(FLAT/DPR)\n CDLON=COS((FLON-TLON)/DPR)\n SDLON=SIN((FLON-TLON)/DPR)\n CRD=STLAT*SFLAT+CTLAT*CFLAT*CDLON\nC - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\nC COMPUTE ROTATIONS AT BOTH POINTS WITH RESPECT TO THE GREAT CIRCLE\nC AND COMBINE THEM TO GIVE THE TOTAL VECTOR ROTATION PARAMETERS.\n IF(ABS(CRD).LE.CRDLIM) THEN\n SRD2RN=-1/(1-CRD**2)\n STR=CFLAT*SDLON\n CTR=CFLAT*STLAT*CDLON-SFLAT*CTLAT\n SFR=CTLAT*SDLON\n CFR=CTLAT*SFLAT*CDLON-STLAT*CFLAT\n CROT=SRD2RN*(CTR*CFR-STR*SFR)\n SROT=SRD2RN*(CTR*SFR+STR*CFR)\nC USE A DIFFERENT APPROXIMATION FOR NEARLY COINCIDENT POINTS.\nC MOVING VECTORS TO ANTIPODAL POINTS IS AMBIGUOUS ANYWAY.\n ELSE\n CROT=CDLON\n SROT=SDLON*STLAT\n ENDIF\nC - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n END\n", "meta": {"hexsha": "cf701ceaedfe05026e5aa19709ddcdb565c72e9f", "size": 2848, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "buildscripts/libs/NCEPlibs/src/ip/v2.0.0/src/movect.f", "max_stars_repo_name": "GMAO-SI-Team/jedi-stack", "max_stars_repo_head_hexsha": "c34e968b3f803a255a7d2d1f33c1bf8c4d1559a0", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2019-05-21T18:44:01.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-14T21:21:11.000Z", "max_issues_repo_path": "buildscripts/libs/NCEPlibs/src/ip/v2.0.0/src/movect.f", "max_issues_repo_name": "GMAO-SI-Team/jedi-stack", "max_issues_repo_head_hexsha": "c34e968b3f803a255a7d2d1f33c1bf8c4d1559a0", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 152, "max_issues_repo_issues_event_min_datetime": "2019-04-04T14:22:18.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-24T14:41:00.000Z", "max_forks_repo_path": "buildscripts/libs/NCEPlibs/src/ip/v2.0.0/src/movect.f", "max_forks_repo_name": "GMAO-SI-Team/jedi-stack", "max_forks_repo_head_hexsha": "c34e968b3f803a255a7d2d1f33c1bf8c4d1559a0", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2019-04-26T21:07:48.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-09T20:41:34.000Z", "avg_line_length": 39.0136986301, "max_line_length": 72, "alphanum_fraction": 0.6095505618, "num_tokens": 1001, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240194661944, "lm_q2_score": 0.7371581741774411, "lm_q1q2_score": 0.6915457893417021}} {"text": " double precision function pythag(a, b)\n*\n* PURPOSE\n* computes sqrt(a^2 + b^2) with accuracy and\n* without spurious underflow / overflow problems\n*\n* MOTIVATION\n* This work was motivated by the fact that the original Scilab\n* PYTHAG, which implements Moler and Morrison's algorithm is slow.\n* Some tests showed that the Kahan's algorithm, is superior in\n* precision and moreover faster than the original PYTHAG. The speed\n* gain partly comes from not calling DLAMCH.\n*\n* REFERENCE\n* This is a Fortran-77 translation of an algorithm by William Kahan,\n* which appears in his article \"Branch cuts for complex elementary\n* functions, or much ado about nothing's sign bit\",\n* Editors: Iserles, A. and Powell, M. J. D. \n* in \"States of the Art in Numerical Analysis\"\n* Oxford, Clarendon Press, 1987\n* ISBN 0-19-853614-3\n*\n* AUTHOR\n* Bruno Pincon , \n* Thanks to Lydia van Dijk \n*\n implicit none\n\n* PARAMETERS\n double precision a, b\n\n* EXTERNAL FUNCTIONS\n integer isanan\n external isanan\n double precision dlamch\n external dlamch\n\n* CONSTANTS\n double precision r2, r2p1, t2p1\n* These constants depend upon the floating point arithmetic of the\n* machine. Here, we give them assuming radix 2 and a 53 bits wide\n* mantissa, correspond to IEEE 754 double precision format. YOU\n* MUST RE-COMPUTE THESE CONSTANTS FOR A MACHINE THAT HAS DIFFERENT\n* CHARACTERISTIC!\n*\n* (1) r2 must approximate sqrt(2) to machine precision. The near\n* floating point from sqrt(2) is exactly:\n*\n* r2 = (1.0110101000001001111001100110011111110011101111001101)_2\n* = (1.4142135623730951454746218587388284504413604736328125)_10\n* sqrt(2) = (1.41421356237309504880168872420969807856967187537694807317...)_10\n*\n* (2) r2p1 must approximate 1+sqrt(2) to machine precision.\n* The near floating point is exactly:\n*\n* r2p1 = (10.011010100000100111100110011001111111001110111100110)_2\n* = (2.41421356237309492343001693370752036571502685546875)_10\n* sqrt(2)+1 = (2.41421356237309504880168872420969807856967187537694...)_10\n*\n* (3) t2p1 must approximate 1+sqrt(2)-r2p1 to machine precision, \n* this is\n* 1.25371671790502177712854645019908198073176679... 10^(-16)\n* and the near float is exactly: \n* (5085679199899093/40564819207303340847894502572032)_10\n* t2p1 = (1.253716717905021735741793363204945859....)_10\n*\n parameter ( r2 = 1.41421356237309504d0, \n $ r2p1 = 2.41421356237309504d0,\n $ t2p1 = 1.25371671790502177d-16)\n* LOCAL VARIABLES\n double precision x, y\n double precision s, t, temp\n\r\n* STATIC VARIABLES\r\n double precision rmax\r\n save rmax\r\n\r\n logical first\r\n save first\r\n data first /.true./\r\n\r\n\n* TEXT\n* Initialize rmax with computed largest non-overflowing number\n if (first) then\n rmax = dlamch('o')\n first = .false.\n endif\n\n* Test for arguments being NaN\n if (isanan(a) .eq. 1) then\n pythag = a\n return\n endif\n if (isanan(b) .eq. 1) then\n pythag = b\n return\n endif\n\n x = abs(a)\n y = abs(b)\n\n* Order x and y such that 0 <= y <= x\n if (x .lt. y) then\n temp = x\n x = y\n y = temp\n endif\n\n* Test for overflowing x\n if (x .gt. rmax) then\n pythag = x\n return\n endif\n\n* Handle generic case \n t = x - y\n if (t .ne. x) then\n if (t .gt. y) then\n* 2 < x/y < 2/epsm\n s = x / y\n s = s + sqrt(1d0 + s*s)\n else\n* 1 <= x/y <= 2\n s = t / y\n t = (2d0 + s) * s\n s = ( ( t2p1 + t/(r2 + sqrt(2d0 + t)) ) + s ) + r2p1\n endif\n pythag = x + y/s\n else\n pythag = x\n endif\n end\n\n\n\n", "meta": {"hexsha": "0b99708925ec0b5da0408aa6f2159892faa6ee01", "size": 4231, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/calelm/pythag.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/pythag.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/pythag.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": 30.8832116788, "max_line_length": 86, "alphanum_fraction": 0.5774048688, "num_tokens": 1266, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.7690802317779601, "lm_q1q2_score": 0.6914964813851406}} {"text": "C**********************************************************************\n subroutine CURVEG(NC, NV, K1, A, B, NN, TSTEP, NT, T,V,X,Y,NSTEP)\nC***********************************************************************\nC THE PROGRAM GENERATES NEW POINTS ON A CURVE BY LINEAR INTERPOLATION\nC USING AN ARITHMETIC OR A HALFLOGARITHMIC SCALE\nC\nC NV(I) = NUMBER OF VALUES ON CURVE I\nC NC = NUMBER OF CURVES\nC K1 = SWITCH K1 = 1 ARITHMETIC SCALE\nC K1 = 2 HALFLOGARITHMIC SCALE\nC A,B = PARAMETERS FOR CALCULATING NEW VALUES\nC Y = A*X + B\nC X,Y = KNOWN POINTS ON CURVE\nC T = VALUES ON ABSISSA WHERE NEW POINTS ARE GENERATED\nC V = NEW ORDINATE VALUES\nC\nC ARITHMETIC SCALE K1 = 1\nC NN = NUMBER OF INTERVALS\nC TSTEP = LARGEST VALUE IN EACH INTERVAL\nC NT = NUMBER OF STEPS IN EACH INTERVAL\nC\nC HALFLOGARITHMIC SCALE\nC NN = NUMBER OF VALUES IN EACH LOG10\nC\nC CODED BY PER B SCHNABEL SEPT 1970\nC\nC***********************************************************************\nC\n dimension X(27,20),Y(27,20),A(27,20),B(27,20),NV(27),TSTEP(27)\n dimension NT(27), T(200), V(27,200)\nC\n XMIN = 100000000.\n XMAX = 0.\n do L= 1,NC\n M = NV(L)\n if (XMAX .lt. X(L,M)) XMAX = X(L,M)\n if (XMIN .gt. X(L,1)) XMIN = X(L,1)\n M = M - 1\n do I = 1,M\n X1 = X(L,I)\n X2 = X(L,I+1)\n if (K1 .eq. 2) X1 = ALOG10(X1)\n if (K1 .eq. 2) X2 = ALOG10(X2)\n X(L,I) = X(L,I+1)\n A(L,I) = (Y(L,I+1) - Y(L,I))/(X2 - X1)\n B(L,I) = -A(L,I)*X1 + Y(L,I)\n end do\n end do\nC\n call STEPG(K1, NN, TSTEP, NT, XMIN, XMAX, T, NSTEP)\nC\n do L = 1,NC\n M = NV(L) - 1\n do I = 1,NSTEP\n do J = 1,M\n if (T(I) .lt. X(L,J)) go to 31\n end do\n J = M\n 31 TT = T(I)\n if (K1 .eq. 2) TT = ALOG10(TT)\n V(L,I) = A(L,J)*TT + B(L,J)\n end do\n end do\n return\n end", "meta": {"hexsha": "982289bc20170d42ea2f465a95ccb90b34705c46", "size": 2180, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "_origin/subroutines/CURVEG.f", "max_stars_repo_name": "shyang107/goshake", "max_stars_repo_head_hexsha": "3b886f286ae82efac94ae2a58560af3145553efd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-01-16T14:00:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T06:38:14.000Z", "max_issues_repo_path": "_origin/subroutines/CURVEG.f", "max_issues_repo_name": "shyang107/goshake", "max_issues_repo_head_hexsha": "3b886f286ae82efac94ae2a58560af3145553efd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "_origin/subroutines/CURVEG.f", "max_forks_repo_name": "shyang107/goshake", "max_forks_repo_head_hexsha": "3b886f286ae82efac94ae2a58560af3145553efd", "max_forks_repo_licenses": ["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.5384615385, "max_line_length": 72, "alphanum_fraction": 0.4151376147, "num_tokens": 727, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213664574069, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.6914964784292604}} {"text": "subroutine heat_init(blockno, mbc,mx,my,meqn, & \n xlower,ylower,dx,dy,q)\n IMPLICIT NONE\n\n INTEGER mbc,mx,my, meqn, blockno\n DOUBLE PRECISION xlower,ylower,dx,dy\n DOUBLE PRECISION q(1-mbc:mx+mbc,1-mbc:my+mbc,meqn)\n\n INTEGER i,j, m\n DOUBLE PRECISION xc,yc, heat_qexact, qe\n\n do i = 1-mbc,mx+mbc\n do j = 1-mbc,my+mbc\n xc = xlower + (i-0.5)*dx\n yc = ylower + (j-0.5)*dy\n qe = heat_qexact(xc,yc)\n q(i,j,1) = qe\n end do\n end do\n\nend subroutine heat_init\n\n\n", "meta": {"hexsha": "d5b0bbce2e0c3115c8121fe7e2c34cf51a28eb6d", "size": 558, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "applications/elliptic/heat/fortran/heat_init.f90", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2017-09-26T13:39:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:56:23.000Z", "max_issues_repo_path": "applications/elliptic/heat/fortran/heat_init.f90", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 75, "max_issues_repo_issues_event_min_datetime": "2017-08-02T19:56:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T12:36:32.000Z", "max_forks_repo_path": "applications/elliptic/heat/fortran/heat_init.f90", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-02-21T00:10:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T19:08:36.000Z", "avg_line_length": 23.25, "max_line_length": 54, "alphanum_fraction": 0.5501792115, "num_tokens": 208, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636754, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.6914964730694328}} {"text": "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n!\r\n! This file contains code for constructing Gauss-Jacobi quadrature rules. The n-point\r\n! Gauss-Jacobi rule associated with the parameters (da,db) is the quadrature rule\r\n!\r\n! 1 n\r\n! \\int (1-x)^da (1+x)^db p(x) ~ \\sum p(x_j) w_j (1)\r\n! -1 j=1\r\n! \r\n! which is exact when p is a polynomial of degree 2n-1. The n-point modified\r\n! Gauss-Jacoi quadrature rule is \r\n!\r\n! \\pi \r\n! \\int cos(t/2)^(2db+1) sin(t/2)^(2da+1) p(cos(t)) dt ~ \r\n! 0 (2)\r\n!\r\n! n\r\n! \\sum sin(t/2)^(2db+1) cos(t/2)^(2da+1) p(cos(t_j)) w_j .\r\n! j=1\r\n!\r\n! It is exact when p is a polynomial of degree less than or equal to 2n-1. Note that\r\n! the importance of the modified rule is that it integrates products of the functions\r\n! obtained by introducing the change of variables x = cos(t) into Jacobi's differential\r\n! equation.\r\n!\r\n! The following subroutines should be regarded as publicly callable:\r\n!\r\n! jacobi_quad - construct the quadrature rule (1)\r\n!\r\n! jacobi_quad_mod - construct the quadrature rule (2)\r\n!\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\n\r\nsubroutine jacobi_quad(n,da,db,xs,whts)\r\nuse chebyshev\r\nimplicit double precision (a-h,o-z)\r\ninteger, intent(in) :: n\r\ndouble precision, intent(in) :: da,db\r\ndouble precision, intent(out) :: xs(n),whts(n)\r\n\r\n!\r\n! Return the n-point Gauss-Jacobi rule (1).\r\n!\r\n! Input parameters:\r\n! n - the length of the desired quadrature rule\r\n! (da,db) - the parameters for Jacobi's differential equation\r\n!\r\n! Output parameters:\r\n! xs - this user-supplied vector of length n will contain the nodes of the \r\n! Gauss-Jacobi quadrature rule\r\n! whts - this user-supplied vector of length n will contain the quadrature\r\n! weights\r\n!\r\n\r\ndouble precision, allocatable :: ab(:,:),avals(:,:),psivals(:,:)\r\ndouble precision, allocatable :: abinv(:,:),alphainv(:,:),alphainvp(:,:)\r\n\r\n\r\ndouble precision, allocatable :: avals2(:,:),psivals2(:,:)\r\ndouble precision, allocatable :: abinv2(:,:),alphainv2(:,:),alphainvp2(:,:)\r\n\r\ntype(chebexps_data) :: chebdata\r\ndata pi / 3.14159265358979323846264338327950288d0 /\r\n\r\ndnu = n\r\np = dnu+(da+db+1)/2\r\nk = 20\r\ncall chebexps(k,chebdata)\r\n\r\n!\r\n! Construct the phase function\r\n!\r\n\r\nnints = 50\r\nallocate(ab(2,nints))\r\ncall jacobi_phase_disc(nints,ab)\r\n\r\nallocate(avals(k,nints),psivals(k,nints))\r\nallocate(avals2(k,nints),psivals2(k,nints))\r\n\r\ncall jacobi_phase(chebdata,dnu,da,db,nints,ab,avals,psivals)\r\npsivals = psivals*dnu\r\navals = 1/avals**2\r\n\r\n\r\ncall jacobi_phase(chebdata,dnu,db,da,nints,ab,avals2,psivals2)\r\npsivals2 = psivals2*dnu\r\navals2 = 1/avals2**2\r\n\r\n\r\n!\r\n! add dnu*t\r\n!\r\n\r\ndo int=1,nints\r\na = ab(1,int)\r\nb = ab(2,int)\r\npsivals(:,int) = psivals(:,int) + dnu * (chebdata%xs * (b-a)/2 + (b+a)/2)\r\npsivals2(:,int) = psivals2(:,int) + dnu * (chebdata%xs * (b-a)/2 + (b+a)/2)\r\nend do\r\n\r\n\r\n! determine the number of roots in (0,pi/2)\r\n\r\nnroots = (psivals(k,nints/2)-psivals(1,1)) / pi\r\n\r\n!\r\n! Invert the phase function\r\n!\r\n\r\nallocate(abinv(2,nints),alphainv(k,nints),alphainvp(k,nints))\r\n\r\ncall jacobi_phase_inverse(nints,ab,chebdata%k,chebdata%xs,chebdata%aintl,chebdata%u, &\r\n psivals,avals,abinv,alphainv,alphainvp)\r\n\r\n\r\nallocate(abinv2(2,nints),alphainv2(k,nints),alphainvp2(k,nints))\r\n\r\ncall jacobi_phase_inverse(nints,ab,chebdata%k,chebdata%xs,chebdata%aintl,chebdata%u, &\r\n psivals2,avals2,abinv2,alphainv2,alphainvp2)\r\n\r\n\r\n!\r\n! Calculate the roots of P_n^(da,db)(cos(t)) in (0,pi)\r\n!\r\n\r\n\r\ndconst = pi *2.0d0**(da+db+1.0d0)\r\n\r\nxs = 0\r\nwhts = 0\r\n\r\nxx = pi/2 \r\nint0 = 1\r\ndo i=1,nroots\r\ndo int=int0,nints-1\r\nif (xx .lt. abinv(2,int)) exit\r\nend do\r\na = abinv(1,int)\r\nb = abinv(2,int)\r\nint0 = int\r\ncall chebeval(a,b,k,chebdata%xs,alphainv(:,int),xx,t)\r\nxs(n-i+1) = t\r\nxx = xx + pi\r\nend do\r\n\r\n\r\nxx = pi/2 \r\nint0 = 1\r\ndo i=1,n-nroots\r\ndo int=int0,nints-1\r\nif (xx .lt. abinv2(2,int)) exit\r\nend do\r\na = abinv2(1,int)\r\nb = abinv2(2,int)\r\nint0 = int\r\ncall chebeval(a,b,k,chebdata%xs,alphainv2(:,int),xx,t)\r\nxs(i) = t\r\nxx = xx + pi\r\nend do\r\n\r\n!\r\n! Evaluate the corresponding weights\r\n!\r\n\r\n\r\nint0 = 1 \r\ndo i=1,nroots\r\nidx = n-i+1\r\nt = xs(idx)\r\n\r\ndo int=int0,nints-1\r\nif (t .lt. ab(2,int)) exit\r\nend do\r\na = ab(1,int)\r\nb = ab(2,int)\r\nint0 = int\r\ncall chebeval(a,b,k,chebdata%xs,avals(:,int),t,apval)\r\nr = cos(t/2)**(2*db+1) * sin(t/2)**(2*da+1)\r\nwhts(idx) = dconst * r/apval\r\n \r\nend do\r\n\r\n\r\n\r\nint0 = 1 \r\ndo i=1,n-nroots\r\nidx = i\r\nt = xs(idx)\r\n\r\ndo int=int0,nints-1\r\nif (t .lt. ab(2,int)) exit\r\nend do\r\na = ab(1,int)\r\nb = ab(2,int)\r\nint0 = int\r\ncall chebeval(a,b,k,chebdata%xs,avals2(:,int),t,apval)\r\nr = cos(t/2)**(2*da+1) * sin(t/2)**(2*db+1)\r\nwhts(idx) = dconst * r/apval\r\nxs(idx) = pi-t \r\nend do\r\n\r\nxs = cos(xs)\r\n\r\n\r\nend subroutine\r\n\r\n\r\n\r\nsubroutine jacobi_quad_mod(n,da,db,xs,whts)\r\nuse chebyshev\r\nimplicit double precision (a-h,o-z)\r\ninteger, intent(in) :: n\r\ndouble precision, intent(in) :: da,db\r\ndouble precision, intent(out) :: xs(n),whts(n)\r\n\r\n!\r\n! Return the n-point modified Gauss-Jacobi rule (2).\r\n!\r\n! Input parameters:\r\n! n - the length of the desired quadrature rule\r\n! (da,db) - the parameters for Jacobi's differential equation\r\n!\r\n! Output parameters:\r\n! xs - this user-supplied vector of length n will contain the nodes of the \r\n! Gauss-Jacobi quadrature rule\r\n! whts - this user-supplied vector of length n will contain the quadrature\r\n! weights\r\n!\r\n\r\ndouble precision, allocatable :: ab(:,:),avals(:,:),psivals(:,:)\r\ndouble precision, allocatable :: abinv(:,:),alphainv(:,:),alphainvp(:,:)\r\n\r\n\r\ndouble precision, allocatable :: avals2(:,:),psivals2(:,:)\r\ndouble precision, allocatable :: abinv2(:,:),alphainv2(:,:),alphainvp2(:,:)\r\n\r\ntype(chebexps_data) :: chebdata\r\ndata pi / 3.14159265358979323846264338327950288d0 /\r\n\r\ndnu = n\r\np = dnu+(da+db+1)/2\r\nk = 20\r\ncall chebexps(k,chebdata)\r\n\r\n!\r\n! Construct the phase function\r\n!\r\n\r\nnints = 50\r\nallocate(ab(2,nints))\r\ncall jacobi_phase_disc(nints,ab)\r\n\r\nallocate(avals(k,nints),psivals(k,nints))\r\nallocate(avals2(k,nints),psivals2(k,nints))\r\n\r\ncall jacobi_phase(chebdata,dnu,da,db,nints,ab,avals,psivals)\r\npsivals = psivals*dnu\r\navals = 1/avals**2\r\n\r\n\r\ncall jacobi_phase(chebdata,dnu,db,da,nints,ab,avals2,psivals2)\r\npsivals2 = psivals2*dnu\r\navals2 = 1/avals2**2\r\n\r\n\r\n!\r\n! add dnu*t\r\n!\r\n\r\ndo int=1,nints\r\na = ab(1,int)\r\nb = ab(2,int)\r\npsivals(:,int) = psivals(:,int) + dnu * (chebdata%xs * (b-a)/2 + (b+a)/2)\r\npsivals2(:,int) = psivals2(:,int) + dnu * (chebdata%xs * (b-a)/2 + (b+a)/2)\r\nend do\r\n\r\n\r\n! determine the number of roots in (0,pi/2)\r\n\r\nnroots = (psivals(k,nints/2)-psivals(1,1)) / pi\r\n\r\n!\r\n! Invert the phase function\r\n!\r\n\r\nallocate(abinv(2,nints),alphainv(k,nints),alphainvp(k,nints))\r\n\r\ncall jacobi_phase_inverse(nints,ab,chebdata%k,chebdata%xs,chebdata%aintl,chebdata%u, &\r\n psivals,avals,abinv,alphainv,alphainvp)\r\n\r\n\r\nallocate(abinv2(2,nints),alphainv2(k,nints),alphainvp2(k,nints))\r\n\r\ncall jacobi_phase_inverse(nints,ab,chebdata%k,chebdata%xs,chebdata%aintl,chebdata%u, &\r\n psivals2,avals2,abinv2,alphainv2,alphainvp2)\r\n\r\n\r\n!\r\n! Calculate the roots of P_n^(da,db)(cos(t)) in (0,pi)\r\n!\r\n\r\n\r\n\r\nxs = 0\r\nwhts = 0\r\n\r\nxx = pi/2 \r\nint0 = 1\r\ndo i=1,nroots\r\ndo int=int0,nints-1\r\nif (xx .lt. abinv(2,int)) exit\r\nend do\r\na = abinv(1,int)\r\nb = abinv(2,int)\r\nint0 = int\r\ncall chebeval(a,b,k,chebdata%xs,alphainv(:,int),xx,t)\r\nxs(i) = t\r\nxx = xx + pi\r\nend do\r\n\r\nxx = pi/2 \r\nint0 = 1\r\ndo i=1,n-nroots\r\nidx = n-i+1\r\ndo int=int0,nints-1\r\nif (xx .lt. abinv2(2,int)) exit\r\nend do\r\na = abinv2(1,int)\r\nb = abinv2(2,int)\r\nint0 = int\r\ncall chebeval(a,b,k,chebdata%xs,alphainv2(:,int),xx,t)\r\nxs(idx) = t\r\nxx = xx + pi\r\nend do\r\n\r\n\r\n\r\n!\r\n! Evaluate the corresponding weights\r\n!\r\n\r\n\r\nint0 = 1 \r\ndo i=1,nroots\r\nt = xs(i)\r\ndo int=int0,nints-1\r\nif (t .lt. ab(2,int)) exit\r\nend do\r\na = ab(1,int)\r\nb = ab(2,int)\r\nint0 = int\r\ncall chebeval(a,b,k,chebdata%xs,avals(:,int),t,apval)\r\n!r = cos(t/2)**(2*db+1) * sin(t/2)**(2*da+1)\r\nwhts(i) = pi/apval\r\nend do\r\n\r\n\r\n\r\nint0 = 1 \r\ndo i=1,n-nroots\r\nidx = n-i+1\r\nt = xs(idx)\r\n\r\ndo int=int0,nints-1\r\nif (t .lt. ab(2,int)) exit\r\nend do\r\na = ab(1,int)\r\nb = ab(2,int)\r\nint0 = int\r\ncall chebeval(a,b,k,chebdata%xs,avals2(:,int),t,apval)\r\nwhts(idx) = pi /apval\r\nxs(idx) = pi-t \r\nend do\r\n\r\n! do i=1,n\r\n! print *,xs(i),whts(i)\r\n! end do\r\n!xs = cos(xs)\r\n\r\n\r\nend subroutine\r\n\r\n\r\n\r\nsubroutine jacobi_quad_mod2(n,da,db,xs,whts)\r\nuse chebyshev\r\nimplicit double precision (a-h,o-z)\r\ninteger, intent(in) :: n\r\ndouble precision, intent(in) :: da,db\r\ndouble precision, intent(out) :: xs(n),whts(n)\r\n\r\n!\r\n! Return the modin-point Gauss-Jacobi rule (2).\r\n!\r\n! Input parameters:\r\n! n - the length of the desired quadrature rule\r\n! (da,db) - the parameters for Jacobi's differential equation\r\n!\r\n! Output parameters:\r\n! xs - this user-supplied vector of length n will contain the nodes of the \r\n! Gauss-Jacobi quadrature rule\r\n! whts - this user-supplied vector of length n will contain the quadrature\r\n! weights\r\n!\r\n\r\ndouble precision, allocatable :: ab(:,:),avals(:,:),psivals(:,:)\r\ndouble precision, allocatable :: abinv(:,:),alphainv(:,:),alphainvp(:,:)\r\ntype(chebexps_data) :: chebdata\r\ndata pi / 3.14159265358979323846264338327950288d0 /\r\n\r\ndnu = n\r\np = dnu+(da+db+1)/2\r\nk = 20\r\ncall chebexps(k,chebdata)\r\n\r\n!\r\n! Construct the phase function\r\n!\r\n\r\nnints = 50\r\nallocate(ab(2,nints))\r\ncall jacobi_phase_disc(nints,ab)\r\n\r\nallocate(avals(k,nints),psivals(k,nints))\r\ncall jacobi_phase(chebdata,dnu,da,db,nints,ab,avals,psivals)\r\n#ifdef OVERDNU\r\npsivals = psivals*dnu\r\n#endif\r\navals = 1/avals**2\r\n\r\n!\r\n! add p*t and multiply by p\r\n!\r\n\r\ndo int=1,nints\r\na = ab(1,int)\r\nb = ab(2,int)\r\npsivals(:,int) = psivals(:,int) + dnu * (chebdata%xs * (b-a)/2 + (b+a)/2)\r\nend do\r\n\r\n\r\n\r\n!\r\n! Invert the phase function\r\n!\r\n\r\nallocate(abinv(2,nints),alphainv(k,nints),alphainvp(k,nints))\r\n\r\ncall jacobi_phase_inverse(nints,ab,chebdata%k,chebdata%xs,chebdata%aintl,chebdata%u, &\r\n psivals,avals,abinv,alphainv,alphainvp)\r\n\r\n!\r\n! Calculate the roots of P_n^(da,db)(cos(t)) in (0,pi)\r\n!\r\n\r\nxx = pi/2\r\nint0 = 1\r\ndo i=1,n\r\ndo int=int0,nints-1\r\nif (xx .lt. abinv(2,int)) exit\r\nend do\r\na = abinv(1,int)\r\nb = abinv(2,int)\r\nint0 = int\r\ncall chebeval(a,b,k,chebdata%xs,alphainv(:,int),xx,xs(i))\r\nxx = xx + pi\r\nend do\r\n\r\n\r\n!\r\n! Evaluate the corresponding weights\r\n!\r\n\r\ndconst = pi\r\n\r\nint0 = 1 \r\ndo i=1,n\r\nidx = i\r\nt = xs(idx)\r\n\r\ndo int=int0,nints-1\r\nif (t .lt. ab(2,int)) exit\r\nend do\r\na = ab(1,int)\r\nb = ab(2,int)\r\nint0 = int\r\ncall chebeval(a,b,k,chebdata%xs,avals(:,int),t,apval)\r\nwhts(idx) = dconst/apval\r\n\r\nend do\r\n\r\nend subroutine\r\n\r\n\r\n\r\n\r\nsubroutine jacobi_phase_inverse(nints,ab,k,xscheb,chebintl,ucheb,alpha,alphap,&\r\n abinv,alphainv,alphainvp)\r\nuse chebyshev\r\nimplicit double precision (a-h,o-z)\r\n\r\ninteger, intent(in) :: nints,k\r\ndouble precision, intent(in) :: xscheb(k),ab(2,nints),chebintl(k,k)\r\ndouble precision, intent(in) :: alpha(k,nints),alphap(k,nints),ucheb(k,k)\r\ndouble precision, intent(out) :: alphainv(k,nints),alphainvp(k,nints),abinv(2,nints)\r\n\r\n!\r\n! Compute the inverse of the phase function alpha via Newton's method.\r\n! \r\n! Input parameters:\r\n! (nints,ab) - the discretization scheme for representing the phase\r\n! function alpha\r\n! k - the number of terms in the piecewise Chebyshev expansions used to\r\n! represent the solution\r\n! xscheb - the nodes of the k-point Chebyshev grid on the interval [-1,1]\r\n! chebintl - the left Chebyshev spectral integration matrix as returned by \r\n! chebexps\r\n! chebintr - the right Chebyshev spectral integration matrix as returned by \r\n! chebexps\r\n! ucheb - the values-to-coefficients matrix returned by chebexps\r\n!\r\n! Output parameters:\r\n!\r\n! (nints,abinv) - the discretization scheme used to represent the inverse of\r\n! alpha\r\n! alphainv - a (k,nints) array specifying the values of the inverse of\r\n! alpha at the nodes of the k-point Chebyshev grids on the intervals\r\n! in the discretization scheme \r\n!\r\n! alphainvp - a (k,nints) array specifying the values of the derivative of\r\n! the inverse of alpha at the nodes of the k-point Chebyshev grids on the \r\n! intervals in the discretization scheme \r\n!\r\n!\r\n\r\neps0 = epsilon(0.0d0)\r\nmaxiters = 12\r\neps0 = sqrt(eps0)\r\nnextra = 3\r\n\r\n!\r\n! Form the initial list of intervals for the inverse function.\r\n!\r\n\r\ndo int=1,nints\r\na = ab(1,int)\r\nb = ab(2,int)\r\n\r\ncall chebpw_eval(nints,ab,k,xscheb,alpha,a,a0)\r\ncall chebpw_eval(nints,ab,k,xscheb,alpha,b,b0)\r\n\r\nabinv(1,int) = a0\r\nabinv(2,int) = b0\r\n\r\nend do\r\n\r\n!\r\n! Use Newton's method to evaluate the inverse at each of the Chebyhev nodes \r\n! on the grid defined by abinv; start at the right-hand side since alpha\r\n! is monotonically increasing.\r\n!\r\n\r\ndo int = nints,1,-1\r\n\r\na0 = abinv(1,int)\r\nb0 = abinv(2,int)\r\na = ab(1,int)\r\nb = ab(2,int)\r\n\r\n\r\ndo i = k,1,-1\r\n\r\nx = (b0-a0)/2*xscheb(i) + (b0+a0)/2\r\nt = (b-a)/2*xscheb(i) + (b+a)/2\r\n\r\ndo iter=1,maxiters+1\r\n\r\nif (iter .eq. maxiters+1) then\r\ncall prina(\"in kummer_phase_invert: maximum number of Newton iterations exceeded\")\r\nstop\r\nendif\r\n\r\ncall chebpw_eval(nints,ab,k,xscheb,alpha,t,val)\r\ncall chebpw_eval(nints,ab,k,xscheb,alphap,t,der)\r\n\r\ndelta = (val-x)/der\r\n\r\nif (abs(delta) .lt. eps0*(1+abs(t))) exit\r\nt = t - delta\r\n\r\nend do\r\n\r\n\r\ndo iextra=1,nextra\r\n\r\ncall chebpw_eval(nints,ab,k,xscheb,alpha,t,val)\r\ncall chebpw_eval(nints,ab,k,xscheb,alphap,t,der)\r\n\r\ndelta = (val-x)/der\r\nt = t - delta\r\n\r\nend do\r\n\r\nalphainv(i,int) = t\r\nalphainvp(i,int) = 1.0d0/der\r\n\r\nend do\r\nend do\r\n\r\nend subroutine\r\n", "meta": {"hexsha": "3fc85e0fe73afdff26d67d693833f11e329ccb8d", "size": 14171, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "v2/specFun/fastJacobiTransform/src/jacobi_quad.f90", "max_stars_repo_name": "ButterflyLab/ButterflyLab", "max_stars_repo_head_hexsha": "fb152ba8f2c5dbdc2b15b516023516a5b538ef78", "max_stars_repo_licenses": ["0BSD"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2018-01-04T20:47:01.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-18T14:16:56.000Z", "max_issues_repo_path": "v2/specFun/fastJacobiTransform/src/jacobi_quad.f90", "max_issues_repo_name": "ButterflyLab/ButterflyLab", "max_issues_repo_head_hexsha": "fb152ba8f2c5dbdc2b15b516023516a5b538ef78", "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": "v2/specFun/fastJacobiTransform/src/jacobi_quad.f90", "max_forks_repo_name": "ButterflyLab/ButterflyLab", "max_forks_repo_head_hexsha": "fb152ba8f2c5dbdc2b15b516023516a5b538ef78", "max_forks_repo_licenses": ["0BSD"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-04-13T11:14:44.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-16T16:19:45.000Z", "avg_line_length": 23.1174551387, "max_line_length": 98, "alphanum_fraction": 0.6125890904, "num_tokens": 4889, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.930458253565792, "lm_q2_score": 0.7431680199891789, "lm_q1q2_score": 0.691486817985079}} {"text": "!---------------------------------------------------------------!\n!\n! Written by Quinn MacPherson 8/4/17\n!---------------------------------------------------------------!\nsubroutine y2_calc(u, Y2real)\n use params, only: dp, pi\n implicit none\n\n!real(dp), parameter :: pi=3.14159265359_dp\n\n real(dp), intent(in) :: u(3)\n real(dp), intent(out), dimension(-2:2) :: Y2real\n real(dp), parameter, dimension(-2:2) :: coefficient = (/0.5_dp*sqrt(15.0_dp/pi), &\n 0.5_dp*sqrt(15.0_dp/pi), &\n 0.25_dp*sqrt(5.0_dp/pi), &\n 0.5_dp*sqrt(15.0_dp/pi), &\n 0.25_dp*sqrt(15.0_dp/pi)/)\n Y2real(-2) = coefficient(-2)*u(1)*u(2)\n Y2real(-1) = coefficient(-1)*u(2)*u(3)\n Y2real(0) = coefficient(0)*(2*u(3)**2 - u(1)**2 - u(2)**2)\n Y2real(1) = coefficient(1)*u(3)*u(1)\n Y2real(2) = coefficient(2)*(u(1)**2 - u(2)**2)\n RETURN\nEND\n\n!---------------------------------------------------------------!\n", "meta": {"hexsha": "e2cc7625cad003bef77e2018e4fe882effd2412d", "size": 1127, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "src/mc/y2_calc.f03", "max_stars_repo_name": "SpakowitzLab/BasicWLC", "max_stars_repo_head_hexsha": "13edbbc8e8cd36a3586571ff4d80880fc89d30e6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-16T01:39:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-16T01:39:18.000Z", "max_issues_repo_path": "src/mc/y2_calc.f03", "max_issues_repo_name": "riscalab/wlcsim", "max_issues_repo_head_hexsha": "e34877ef6c5dc83c6444380dbe624b371d70faf2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 17, "max_issues_repo_issues_event_min_datetime": "2016-07-08T21:17:40.000Z", "max_issues_repo_issues_event_max_datetime": "2017-01-24T09:05:25.000Z", "max_forks_repo_path": "src/mc/y2_calc.f03", "max_forks_repo_name": "riscalab/wlcsim", "max_forks_repo_head_hexsha": "e34877ef6c5dc83c6444380dbe624b371d70faf2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2016-06-21T22:03:53.000Z", "max_forks_repo_forks_event_max_datetime": "2016-11-10T00:55:01.000Z", "avg_line_length": 41.7407407407, "max_line_length": 85, "alphanum_fraction": 0.3691215617, "num_tokens": 313, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582632076909, "lm_q2_score": 0.743167997235783, "lm_q1q2_score": 0.6914868039795447}} {"text": "! created by EverLookNeverSee@GitHub on 05/26/20\n! This program computes slope of the chord in given function.\n\n! y = sqrt(x) , if 0 =< x =< 1\n! y = f(x) -->\n! y = e ** (1 - x) , if x > 1\n\nfunction f(x)\n if (x >= 0. .and. x<= 1.) then\n f = sqrt(x)\n elseif (x > 1.) then\n f = exp(1. - x)\n else\n print *, \"Function not defined.\"\n end if\n return\nend function f\n\nprogram main\n slope = (f(0.5) - f(2.)) / 0.5 - 2.0\n print *, slope\nend program main", "meta": {"hexsha": "35d6a750e1f16e347a48d56ef6a88e0f904c06dd", "size": 519, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/other/slope_of_chord.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/slope_of_chord.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/slope_of_chord.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": 23.5909090909, "max_line_length": 61, "alphanum_fraction": 0.493256262, "num_tokens": 183, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582477806521, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6914867978074345}} {"text": "! =============================================================================\n! This module contains all ellipse operations.\n! =============================================================================\nmodule parcel_ellipse\n use constants, only : pi &\n , fpi &\n , zero &\n , two &\n , f12 &\n , f14\n implicit none\n\n contains\n\n ! Obtain the largest eigenvalue (i.e. the semi-major axis squared [a**2])\n ! @param[in] B11 is the B matrix (1, 1) element\n ! @param[in] B12 is the B matrix (1, 2) element\n ! @param[in] B22 is the B matrix (2, 2) element\n ! @returns the largest eigenvalue\n function get_eigenvalue(B11, B12, B22) result(a2)\n double precision, intent(in) :: B11\n double precision, intent(in) :: B12\n double precision, intent(in) :: B22\n double precision :: a2\n\n a2 = f12 * (B11 + B22) + dsqrt(f14 * (B11 - B22) ** 2 + B12 ** 2)\n end function get_eigenvalue\n\n ! Obtain the eigenvector of the largest eigenvalue\n ! @param[in] a2 is the largest eigenvalue\n ! @param[in] B11 is the B matrix (1, 1) element\n ! @param[in] B12 is the B matrix (1, 2) element\n ! @param[in] B22 is the B matrix (2, 2) element\n ! @returns the eigenvector\n function get_eigenvector(a2, B11, B12, B22) result(evec)\n double precision, intent(in) :: a2\n double precision, intent(in) :: B11\n double precision, intent(in) :: B12\n double precision, intent(in) :: B22\n double precision :: evec(2)\n\n evec(1) = a2 - B22\n evec(2) = B12\n\n if (dabs(evec(1)) + dabs(evec(2)) == zero) then\n if (B11 > B22) then\n evec(1) = evec(1) + epsilon(evec(1))\n else\n evec(2) = evec(2) + epsilon(evec(2))\n endif\n endif\n\n evec = evec / norm2(evec)\n\n end function get_eigenvector\n\n ! used in unit tests only\n function get_angle(B11, B12, volume) result(angle)\n double precision, intent(in) :: B11\n double precision, intent(in) :: B12\n double precision, intent(in) :: volume\n double precision :: B22\n double precision :: a2\n double precision :: evec(2)\n double precision :: angle\n\n B22 = get_B22(B11, B12, volume)\n\n a2 = get_eigenvalue(B11, B12, B22)\n\n evec = get_eigenvector(a2, B11, B12, B22)\n\n angle = datan2(evec(2), evec(1))\n\n end function get_angle\n\n ! Obtain the B22 matrix element\n ! @param[in] B11 is the B matrix (1, 1) element\n ! @param[in] B12 is the B matrix (1, 2) element\n ! @param[in] volume of the parcel\n ! @returns B22\n elemental function get_B22(B11, B12, volume) result(B22)\n double precision, intent(in) :: B11\n double precision, intent(in) :: B12\n double precision, intent(in) :: volume\n double precision :: B22\n double precision :: ab\n\n ab = get_ab(volume)\n\n B22 = (ab ** 2 + B12 ** 2) / B11\n\n end function get_B22\n\n ! Obtain the product of the semi-minor and semi-major axis.\n ! @param[in] volume of the parcel\n ! @returns ab = volume / pi\n elemental function get_ab(volume) result(ab)\n double precision, intent(in) :: volume\n double precision :: ab\n\n ab = volume * fpi\n end function\n\n ! Obtain the aspect ratio a/b of the parcel(s).\n ! @param[in] a2 is the largest eigenvalue\n ! @param[in] volume of the parcel(s)\n ! @returns lam = a/b\n elemental function get_aspect_ratio(a2, volume) result(lam)\n double precision, intent(in) :: a2\n double precision, intent(in) :: volume\n double precision :: lam\n\n lam = (a2 / volume) * pi\n end function\n\n ! Obtain the ellipse support points for par2grid and grid2par\n ! @param[in] position vector of the parcel\n ! @param[in] volume of the parcel\n ! @param[in] B matrix elements of the parcel\n ! @returns the parcel support points\n function get_ellipse_points(position, volume, B) result(points)\n double precision, intent(in) :: position(2)\n double precision, intent(in) :: volume\n double precision, intent(in) :: B(2) ! B11, B12\n double precision :: B22\n double precision :: c\n double precision :: a2\n double precision :: evec(2)\n double precision :: h(2)\n double precision :: points(2, 2)\n\n B22 = get_B22(B(1), B(2), volume)\n\n a2 = get_eigenvalue(B(1), B(2), B22)\n\n c = dsqrt(dabs(two * a2 - B(1) - B22))\n\n evec = get_eigenvector(a2, B(1), B(2), B22)\n\n h = f12 * c * evec\n\n points(:, 1) = position - h\n points(:, 2) = position + h\n\n end function get_ellipse_points\nend module parcel_ellipse\n", "meta": {"hexsha": "015de2d7ff65b8d9797aa0f42f440af4071c452a", "size": 5450, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/2d/parcels/parcel_ellipse.f90", "max_stars_repo_name": "matt-frey/epic", "max_stars_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2021-11-11T10:50:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T00:11:41.000Z", "max_issues_repo_path": "src/2d/parcels/parcel_ellipse.f90", "max_issues_repo_name": "matt-frey/epic", "max_issues_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 47, "max_issues_repo_issues_event_min_datetime": "2021-11-12T17:09:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-24T16:50:58.000Z", "max_forks_repo_path": "src/2d/parcels/parcel_ellipse.f90", "max_forks_repo_name": "matt-frey/epic", "max_forks_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.8243243243, "max_line_length": 81, "alphanum_fraction": 0.4946788991, "num_tokens": 1363, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582477806522, "lm_q2_score": 0.743167997235783, "lm_q1q2_score": 0.6914867925146633}} {"text": "c\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc . .\nc . copyright (c) 1998 by UCAR .\nc . .\nc . University Corporation for Atmospheric Research .\nc . .\nc . all rights reserved .\nc . .\nc . .\nc . SPHEREPACK .\nc . .\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc\nc\nc\nc ... file islapgc.f\nc\nc this file includes documentation and code for\nc subroutine islapgc i\nc\nc ... files which must be loaded with islapgc.f\nc\nc sphcom.f, hrfft.f, shagc.f, shsgc.f\nc\nc subroutine islapgc(nlat,nlon,isym,nt,xlmbda,sf,ids,jds,a,b,\nc +mdab,ndab,wshsgc,lshsgc,work,lwork,pertrb,ierror)\nc\nc islapgc inverts the laplace or helmholz operator on a Gaussian\nc grid using o(n**2) storage. given the\nc spherical harmonic coefficients a(m,n) and b(m,n) of the right\nc hand side slap(i,j), islapgc computes a solution sf(i,j) to\nc the following helmhotz equation :\nc\nc 2 2\nc [d(sf(i,j))/dlambda /sint + d(sint*d(sf(i,j))/dtheta)/dtheta]/sint\nc\nc - xlmbda * sf(i,j) = slap(i,j)\nc\nC*PL*ERROR* Comment line too long\nc where sf(i,j) is computed at the Gaussian colatitude point theta(i)\nc (see nlat as an input argument) and longitude\nc\nc lambda(j) = (j-1)*2*pi/nlon\nc\nc for i=1,...,nlat and j=1,...,nlon.\nc\nc\nc input parameters\nc\nc nlat the number of points in the gaussian colatitude grid on the\nC*PL*ERROR* Comment line too long\nc full sphere. these lie in the interval (0,pi) and are computed\nC*PL*ERROR* Comment line too long\nc in radians in theta(1) <...< theta(nlat) by subroutine gaqd.\nC*PL*ERROR* Comment line too long\nc if nlat is odd the equator will be included as the grid point\nc theta((nlat+1)/2). if nlat is even the equator will be\nc excluded as a grid point and will lie half way between\nc theta(nlat/2) and theta(nlat/2+1). nlat must be at least 3.\nc note: on the half sphere, the number of grid points in the\nc colatitudinal direction is nlat/2 if nlat is even or\nc (nlat+1)/2 if nlat is odd.\nc\nc nlon the number of distinct longitude points. nlon determines\nc the grid increment in longitude as 2*pi/nlon. for example\nc nlon = 72 for a five degree grid. nlon must be greater\nc than zero. the axisymmetric case corresponds to nlon=1.\nc the efficiency of the computation is improved when nlon\nc is a product of small prime numbers.\nc\nC*PL*ERROR* Comment line too long\nc isym this parameter should have the same value input to subroutine\nC*PL*ERROR* Comment line too long\nc shagc to compute the coefficients a and b for the scalar field\nc slap. isym is set as follows:\nc\nc = 0 no symmetries exist in slap about the equator. scalar\nc synthesis is used to compute sf on the entire sphere.\nc i.e., in the array sf(i,j) for i=1,...,nlat and\nc j=1,...,nlon.\nc\nc = 1 sf and slap are antisymmetric about the equator. the\nc synthesis used to compute sf is performed on the\nc northern hemisphere only. if nlat is odd, sf(i,j) is\nc computed for i=1,...,(nlat+1)/2 and j=1,...,nlon. if\nc nlat is even, sf(i,j) is computed for i=1,...,nlat/2\nc and j=1,...,nlon.\nc\nc\nc = 2 sf and slap are symmetric about the equator. the\nc synthesis used to compute sf is performed on the\nc northern hemisphere only. if nlat is odd, sf(i,j) is\nc computed for i=1,...,(nlat+1)/2 and j=1,...,nlon. if\nc nlat is even, sf(i,j) is computed for i=1,...,nlat/2\nc and j=1,...,nlon.\nc\nc\nc nt the number of solutions. in the program that calls islapgc\nc the arrays sf,a, and b can be three dimensional in which\nc case multiple solutions are computed. the third index\nc is the solution index with values k=1,...,nt.\nc for a single solution set nt=1. the description of the\nc remaining parameters is simplified by assuming that nt=1\nc and sf,a,b are two dimensional.\nc\nc xlmbda a one dimensional array with nt elements. if xlmbda is\nc is identically zero islapgc solves poisson's equation.\nc if xlmbda > 0.0 islapgc solves the helmholtz equation.\nc if xlmbda < 0.0 the nonfatal error flag ierror=-1 is\nc returned. negative xlambda could result in a division\nc by zero.\nc\nc ids the first dimension of the array sf as it appears in the\nC*PL*ERROR* Comment line too long\nc program that calls islapgc. if isym = 0 then ids must be at\nc least nlat. if isym > 0 and nlat is even then ids must be\nc at least nlat/2. if isym > 0 and nlat is odd then ids must\nc be at least (nlat+1)/2.\nc\nc jds the second dimension of the array sf as it appears in the\nc program that calls islapgc. jds must be at least nlon.\nc\nc\nc a,b two or three dimensional arrays (see input parameter nt)\nc that contain scalar spherical harmonic coefficients\nc of the scalar field slap. a,b must be computed by shagc\nc prior to calling islapgc.\nc\nc\nc mdab the first dimension of the arrays a and b as it appears\nc in the program that calls islapgc. mdab must be at\nc least min0(nlat,(nlon+2)/2) if nlon is even or at least\nc min0(nlat,(nlon+1)/2) if nlon is odd.\nc\nc ndab the second dimension of the arrays a and b as it appears\nc in the program that calls islapgc. ndbc must be at least\nc least nlat.\nc\nc mdab,ndab should have the same values input to shagc to\nc compute the coefficients a and b.\nc\nc wshsgc an array which must be initialized by subroutine shsgci\nc once initialized, wshsgc can be used repeatedly by islapgc\nc as long as nlon and nlat remain unchanged. wshsgc must\nc not be altered between calls of islapgc.\nc\nc\nc lshsgc the dimension of the array wshsgc as it appears in the\nc program that calls islapgc. let\nc\nc l1 = min0(nlat,(nlon+2)/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc and\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc then lshsgc must be at least\nc\nc nlat*(2*l2+3*l1-2)+3*l1*(1-l1)/2+nlon+15\nc\nc work a work array that does not have to be saved.\nc\nc lwork the dimension of the array work as it appears in the\nc program that calls islapgc. define\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc l1 = min0(nlat,(nlon+2)/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc if isym = 0 let\nc\nc lwkmin = nlat*(2*nt*nlon+max0(6*l2,nlon)+2*nt*l1+1).\nc\nc if isym > 0 let\nc\nC*PL*ERROR* Comment line too long\nc lwkmin = l2*(2*nt*nlon+max0(6*nlat,nlon))+nlat*(2*nt*l1+1)\nc\nc\nc then lwork must be greater than or equal to lwkmin (see ierror=10)\nc\nc **************************************************************\nc\nc output parameters\nc\nc\nC*PL*ERROR* Comment line too long\nc sf a two or three dimensional arrays (see input parameter nt) that\nc inverts the scalar laplacian in slap. sf(i,j) is given at\nc the colatitude\nc\nc theta(i) = (i-1)*pi/(nlat-1)\nc\nc and longitude\nc\nc lambda(j) = (j-1)*2*pi/nlon\nc\nc for i=1,...,nlat and j=1,...,nlon.\nc\nc pertrb a one dimensional array with nt elements (see input\nc parameter nt). in the discription that follows we assume\nc that nt=1. if xlmbda > 0.0 then pertrb=0.0 is always\nc returned because the helmholtz operator is invertible.\nc if xlmbda = 0.0 then a solution exists only if a(1,1)\nc is zero. islapgc sets a(1,1) to zero. the resulting\nc solution sf(i,j) solves poisson's equation with\nc pertrb = a(1,1)/(2.*sqrt(2.)) subtracted from the\nc right side slap(i,j).\nc\nC*PL*ERROR* Comment line too long\nc ierror a parameter which flags errors in input parameters as follows:\nc\nc = 0 no errors detected\nc\nc = 1 error in the specification of nlat\nc\nc = 2 error in the specification of nlon\nc\nc = 3 error in the specification of ityp\nc\nc = 4 error in the specification of nt\nc\nc = 5 error in the specification of ids\nc\nc = 6 error in the specification of jds\nc\nc = 7 error in the specification of mdbc\nc\nc = 8 error in the specification of ndbc\nc\nc = 9 error in the specification of lshsgc\nc\nc = 10 error in the specification of lwork\nc\nc\nc **********************************************************************\nc\nc end of documentation for islapgc\nc\nc **********************************************************************\nc\n SUBROUTINE DISLAPGC(NLAT,NLON,ISYM,NT,XLMBDA,SF,IDS,JDS,A,B,MDAB,\n + NDAB,WSHSGC,LSHSGC,WORK,LWORK,PERTRB,IERROR)\n DOUBLE PRECISION XLMBDA\n DOUBLE PRECISION SF\n DOUBLE PRECISION A\n DOUBLE PRECISION B\n DOUBLE PRECISION WSHSGC\n DOUBLE PRECISION WORK\n DOUBLE PRECISION PERTRB\n DIMENSION SF(IDS,JDS,NT),A(MDAB,NDAB,NT),B(MDAB,NDAB,NT)\n DIMENSION WSHSGC(LSHSGC),WORK(LWORK),XLMBDA(NT),PERTRB(NT)\nc\nc check input parameters\nc\n IERROR = 1\n IF (NLAT.LT.3) RETURN\n IERROR = 2\n IF (NLON.LT.4) RETURN\n IERROR = 3\n IF (ISYM.LT.0 .OR. ISYM.GT.2) RETURN\n IERROR = 4\n IF (NT.LT.0) RETURN\n IERROR = 5\n IMID = (NLAT+1)/2\n IF ((ISYM.EQ.0.AND.IDS.LT.NLAT) .OR.\n + (ISYM.GT.0.AND.IDS.LT.IMID)) RETURN\n IERROR = 6\n IF (JDS.LT.NLON) RETURN\n IERROR = 7\n MMAX = MIN0(NLAT,NLON/2+1)\n IF (MDAB.LT.MMAX) RETURN\n IERROR = 8\n IF (NDAB.LT.NLAT) RETURN\n IERROR = 9\nc\nc set and verify saved work space length\nc\nc\n L1 = MIN0(NLAT, (NLON+2)/2)\n L2 = (NLAT+1)/2\n LWMIN = NLAT* (2*L2+3*L1-2) + 3*L1* (1-L1)/2 + NLON + 15\n IF (LSHSGC.LT.LWMIN) RETURN\n IERROR = 10\nc\nc set and verify unsaved work space length\nc\n LS = NLAT\n IF (ISYM.GT.0) LS = IMID\n NLN = NT*LS*NLON\n MN = MMAX*NLAT*NT\nc lwmin = nln+ls*nlon+2*mn+nlat\nc if (lwork .lt. lwmin) return\n IF (ISYM.EQ.0) THEN\n LWMIN = NLAT* (2*NT*NLON+MAX0(6*L2,NLON)+2*L1*NT+1)\n ELSE\n LWMIN = L2* (2*NT*NLON+MAX0(6*NLAT,NLON)) + NLAT* (2*L1*NT+1)\n END IF\n IF (LWORK.LT.LWMIN) RETURN\n IERROR = 0\nc\nc check sign of xlmbda\nc\n DO K = 1,NT\n IF (XLMBDA(K).LT.0.0D0) THEN\n IERROR = -1\n END IF\n END DO\nc\nc set work space pointers\nc\n IA = 1\n IB = IA + MN\n IFN = IB + MN\n IWK = IFN + NLAT\n LWK = LWORK - 2*MN - NLAT\n CALL DISLPGC1(NLAT,NLON,ISYM,NT,XLMBDA,SF,IDS,JDS,A,B,MDAB,NDAB,\n + WORK(IA),WORK(IB),MMAX,WORK(IFN),WSHSGC,LSHSGC,\n + WORK(IWK),LWK,PERTRB,IERROR)\n RETURN\n END\n\n SUBROUTINE DISLPGC1(NLAT,NLON,ISYM,NT,XLMBDA,SF,IDS,JDS,A,B,MDAB,\n + NDAB,AS,BS,MMAX,FNN,WSAV,LSAV,WK,LWK,PERTRB,\n + IERROR)\n DOUBLE PRECISION XLMBDA\n DOUBLE PRECISION SF\n DOUBLE PRECISION A\n DOUBLE PRECISION B\n DOUBLE PRECISION AS\n DOUBLE PRECISION BS\n DOUBLE PRECISION FNN\n DOUBLE PRECISION WSAV\n DOUBLE PRECISION WK\n DOUBLE PRECISION PERTRB\n DOUBLE PRECISION FN\n DIMENSION SF(IDS,JDS,NT),A(MDAB,NDAB,NT),B(MDAB,NDAB,NT)\n DIMENSION AS(MMAX,NLAT,NT),BS(MMAX,NLAT,NT),FNN(NLAT)\n DIMENSION WSAV(LSAV),WK(LWK),XLMBDA(NT),PERTRB(NT)\nc\nc set multipliers and preset synthesis coefficients to zero\nc\n DO N = 1,NLAT\n FN = DBLE(N-1)\n FNN(N) = FN* (FN+1.0D0)\n DO M = 1,MMAX\n DO K = 1,NT\n AS(M,N,K) = 0.0D0\n BS(M,N,K) = 0.0D0\n END DO\n END DO\n END DO\n\n DO K = 1,NT\nc\nc compute synthesis coefficients for xlmbda zero or nonzero\nc\n IF (XLMBDA(K).EQ.0.0D0) THEN\n DO N = 2,NLAT\n AS(1,N,K) = -A(1,N,K)/FNN(N)\n BS(1,N,K) = -B(1,N,K)/FNN(N)\n END DO\n DO M = 2,MMAX\n DO N = M,NLAT\n AS(M,N,K) = -A(M,N,K)/FNN(N)\n BS(M,N,K) = -B(M,N,K)/FNN(N)\n END DO\n END DO\n ELSE\nc\nc xlmbda nonzero so operator invertible unless\nc -n*(n-1) = xlmbda(k) < 0.0 for some n\nc\n PERTRB(K) = 0.0D0\n DO N = 1,NLAT\n AS(1,N,K) = -A(1,N,K)/ (FNN(N)+XLMBDA(K))\n BS(1,N,K) = -B(1,N,K)/ (FNN(N)+XLMBDA(K))\n END DO\n DO M = 2,MMAX\n DO N = M,NLAT\n AS(M,N,K) = -A(M,N,K)/ (FNN(N)+XLMBDA(K))\n BS(M,N,K) = -B(M,N,K)/ (FNN(N)+XLMBDA(K))\n END DO\n END DO\n END IF\n END DO\nc\nc synthesize as,bs into sf\nc\n CALL DSHSGC(NLAT,NLON,ISYM,NT,SF,IDS,JDS,AS,BS,MMAX,NLAT,WSAV,\n + LSAV,WK,LWK,IERROR)\n RETURN\n END\n", "meta": {"hexsha": "364ff376cb1d746395666cb08cb75f5e350fa141", "size": 14242, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "external/sphere3.1_dp/islapgc.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "external/sphere3.1_dp/islapgc.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "external/sphere3.1_dp/islapgc.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 35.783919598, "max_line_length": 76, "alphanum_fraction": 0.539882039, "num_tokens": 4465, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361652391386, "lm_q2_score": 0.7577943658046608, "lm_q1q2_score": 0.6914389851746297}} {"text": "program ex4p2_dist1\r\n use mt_mod\r\n implicit none\r\n integer, parameter:: ik=selected_int_kind(11), rk=selected_real_kind(11,100), counts=100, distrs=10000\r\n integer :: err, i, j, k\r\n integer(kind=ik), dimension(39) :: x, y\r\n real(kind=rk), dimension(1000) :: h=0\r\n integer(kind=ik), dimension(distrs, counts) :: D_k=0\r\n real(kind=rk) :: mean_t, mean_w=0, dx_bar=1, u, x_low, x_up, x_bar\r\n\r\n call init_genrand64(int(1234765, ik))\r\n\r\n !Read data\r\n open(1, action=\"read\", file=\"distr1.dat\", status=\"old\")\r\n do i=1, 39\r\n read(1, *) x(i), y(i)\r\n end do\r\n close(1)\r\n\r\n !True mean (weighted)\r\n do j=1, size(y)\r\n mean_t=mean_t+y(j)*x(j)\r\n end do\r\n mean_t=mean_t/real(sum(y), rk)\r\n\r\n !Generate synthetic data to D_k and store their means to h\r\n do i=1, distrs\r\n D_k(i,:) = 0\r\n do j=1, counts\r\n u=real(sum(y), rk)*genrand64_real3()\r\n k=1\r\n do\r\n if(F_k(int(k-1, ik))=0.155) then\r\n x_low=k\r\n exit\r\n end if\r\n end do\r\n\r\n do k=1, size(h)\r\n if(H_k(k)<0.845.and.H_k(k)>=0.835) then\r\n x_up=k\r\n exit\r\n end if\r\n end do\r\n\r\n !Results\r\n print*, \"Lower and upper uncertainty respectively:\"\r\n print*, mean_t-x_low, x_up-mean_t\r\n print*, \"Error assuming Gaussian shape:\"\r\n do i=1, size(x)\r\n x(i)=x(i)*x(i)\r\n end do\r\n x_bar=sum(x)/real(size(x), rk)\r\n print*,1/sqrt(real(size(x),rk))*sqrt(x_bar-mean_t**2)\r\n\r\n !Save data, this part was changed as needed\r\n open(1, action=\"write\", file=\"data_distr1.txt\", status=\"replace\", position=\"append\")\r\n do i=1, size(h)\r\n write(1, *) H_k(i), i\r\n end do\r\n close(1)\r\n\r\n\r\ncontains\r\n\r\n!Cumulative function F\r\nreal(kind=rk) function F_k(k)\r\n implicit none\r\n integer(kind=ik), intent(in) :: k\r\n F_k=sum(y(:k))\r\nend function\r\n\r\n!Cumulative function H\r\nreal(kind=rk) function H_k(k)\r\n implicit none\r\n integer, intent(in) :: k\r\n H_k=sum(h(:k))/real(sum(h), rk)\r\nend function\r\n \r\nend program ex4p2_dist1", "meta": {"hexsha": "d88c616cab1f67b9f004e5f5e7b445e1e4219a9a", "size": 2517, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Nico_Toikka_ex4/p2/ex4p2_dist1.f95", "max_stars_repo_name": "toicca/basics-of-mc", "max_stars_repo_head_hexsha": "71f2fc2ac4252c359a6c6bbf46d9bac743aaec25", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Nico_Toikka_ex4/p2/ex4p2_dist1.f95", "max_issues_repo_name": "toicca/basics-of-mc", "max_issues_repo_head_hexsha": "71f2fc2ac4252c359a6c6bbf46d9bac743aaec25", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Nico_Toikka_ex4/p2/ex4p2_dist1.f95", "max_forks_repo_name": "toicca/basics-of-mc", "max_forks_repo_head_hexsha": "71f2fc2ac4252c359a6c6bbf46d9bac743aaec25", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.6836734694, "max_line_length": 107, "alphanum_fraction": 0.533174414, "num_tokens": 803, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361604769413, "lm_q2_score": 0.7577943658046608, "lm_q1q2_score": 0.6914389815658634}} {"text": "SUBROUTINE eta_nonlinear_standing(H,Lx,x,omega,time,eta,etax,etaxx,etat)\n!\nUSE Precision\nUSE Constants\nIMPLICIT NONE\nREAL(KIND=long), INTENT(IN) :: H,Lx,x,omega,time\nREAL(KIND=long), INTENT(OUT) :: eta,etax\nREAL(KIND=long), INTENT(OUT) :: etaxx,etat\n! REAL(KIND=long), OPTIONAL :: y,etay,etayy !Boundary fitted ?\n! Local variables\nREAL(KIND=long) :: kx, half_H, sinkx\n!\nREAL(KIND=long) :: HH,k,w,ky,y,Ly\n!\ny = zero ; Ly = zero ; ky = zero\nkx = two*pi/Lx\nk = SQRT(kx**2+ky**2)\nw = omega\nHH = H\n!\neta = half*HH*COS(w*time)*COS(kx*X)*COS(ky*Y)\netax = -kx*half*HH*COS(w*time)*SIN(kx*X)*COS(ky*Y)\netaxx = -kx**2*half*HH*COS(w*time)*COS(kx*X)*COS(ky*Y)\netat = -half*w*HH*SIN(w*time)*COS(kx*X)*COS(ky*Y)\n\n\nEND SUBROUTINE eta_nonlinear_standing\n", "meta": {"hexsha": "9ab1ad22ef466d03ff1d7e04e5c0ac15aaaac894", "size": 746, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/functions/eta_nonlinear_standing.f90", "max_stars_repo_name": "apengsigkarup/OceanWave3D", "max_stars_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 46, "max_stars_repo_stars_event_min_datetime": "2016-01-08T12:36:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T06:56:45.000Z", "max_issues_repo_path": "src/functions/eta_nonlinear_standing.f90", "max_issues_repo_name": "apengsigkarup/OceanWave3D", "max_issues_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-10-10T19:45:08.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-07T07:37:11.000Z", "max_forks_repo_path": "src/functions/eta_nonlinear_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": 26.6428571429, "max_line_length": 72, "alphanum_fraction": 0.6689008043, "num_tokens": 316, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147438, "lm_q2_score": 0.7577943658046609, "lm_q1q2_score": 0.6914389779570971}} {"text": "\t!--------------------------------------------------------------------\n\t!\n\t!\n\t! PURPOSE\n\t!\n\t! This program solves nonlinear Klein-Gordon equation in 3 dimensions\n\t! u_{tt}-(u_{xx}+u_{yy}+u_{zz})+u=Es*|u|^2u\n\t! using a second order implicit-explicit time stepping scheme.\n\t!\n\t! The boundary conditions are u(x=-Lx*pi,y,z)=u(x=Lx*\\pi,y,z), \n\t!\tu(x,y=-Ly*pi,z)=u(x,y=Ly*pi,z),u(x,y,z=-Ly*pi)=u(x,y,z=Ly*pi),\n\t! The initial condition is u=0.5*exp(-x^2-y^2-z^2)*sin(10*x+12*y)\n\t!\n\t! .. Parameters ..\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! Nz\t\t\t\t= number of modes in z - power of 2 for FFT\n\t! Nt\t\t\t\t= number of timesteps to take\n\t! Tmax\t\t\t\t= maximum simulation time\n\t! plotgap\t\t\t= number of timesteps between plots\n\t! FFTW_IN_PLACE \t= value for FFTW input \n\t! FFTW_MEASURE \t= value for FFTW input\n\t! FFTW_EXHAUSTIVE \t= value for FFTW input\n\t! FFTW_PATIENT \t= value for FFTW input \n\t! FFTW_ESTIMATE \t= value for FFTW input\n\t! FFTW_FORWARD = value for FFTW input\n\t! FFTW_BACKWARD\t= value for FFTW input\t\n\t! pi = 3.14159265358979323846264338327950288419716939937510d0\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! Lz\t\t\t\t= width of box in z direction\n\t! ES\t\t\t\t= +1 for focusing and -1 for defocusing\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! k\t\t\t\t= loop counter in z direction\n\t! n\t\t\t\t= loop counter for timesteps direction\t\n\t! allocatestatus\t= error indicator during allocation\n\t! start\t\t\t= variable to record start time of program\n\t! finish\t\t\t= variable to record end time of program\n\t! count_rate\t\t= variable for clock count rate\n\t! planfz\t\t\t= Forward 1d fft plan \n\t! planbz\t\t\t= Backward 1d fft plan\n\t! planfxy\t\t\t= Forward 2d fft plan \n\t! planbxy\t\t\t= Backward 2d fft plan\n\t! planfxyz\t\t\t= Forward 3d fft plan \n\t! planbxyz\t\t\t= Backward 3d fft plan\n\t! dt\t\t\t\t= timestep\n\t! modescalereal\t= Number to scale after backward FFT \n\t! ierr\t\t\t\t= error code\n\t! plotnum\t\t\t= number of plot\n\t! numthreads\t\t= total number of OpenMP threads\n\t! mythreadid\t\t= thread number\n\t! .. Arrays ..\n\t! unew \t\t\t= approximate solution\n\t! vnew \t\t\t= Fourier transform of approximate solution\n\t! u \t\t\t\t= approximate solution\n\t! v \t\t\t\t= Fourier transform of approximate solution\n\t! uold \t\t\t= approximate solution\n\t! vold \t\t\t= Fourier transform of approximate solution\n\t! nonlin \t\t\t= nonlinear term, u^3\n\t! nonlinhat \t\t= Fourier transform of nonlinear term, u^3\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! kz\t\t\t\t= fourier frequencies in z direction\n\t! x\t\t\t\t= x locations\n\t! y\t\t\t\t= y locations\n\t! z\t\t\t\t= z locations\n\t! time\t\t\t\t= times at which save data\n\t! en\t\t\t\t= total energy\t\n\t! enstr\t\t\t= strain energy\n\t! enpot\t\t\t= potential energy\n\t! enkin\t\t\t= kinetic energy\n\t! name_config\t\t= array to store filename for data to be saved \n\t! lowxv\t\t\t= array with entries of array to be used by each thread\n\t! upxv\t\t\t\t= array with entries of array to be used by each thread\n\t! lowzv\t\t\t= array with entries of array to be used by each thread\n\t! upzv\t\t\t\t= array with entries of array to be used by each thread\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!\tgetgrid.f90\t-- Get initial grid of points\n\t! \tinitialdata.f90 -- Get initial data\n\t!\tenercalc.f90 -- Subroutine to calculate the energy\n\t!\tsavedata.f90 -- Save initial data\n\t!\tstoreold.f90 -- Store old data\n\t! External libraries required\n\t! \tFFTW3\t -- Fast Fourier Transform in the West Library\n\t!\t\t\t(http://www.fftw.org/)\n\t! \tOpenMP library\n\t\t\n\tPROGRAM Kg\n\tUSE omp_lib\t\t \t \n\tIMPLICIT NONE\t\t\t\t\t \n\t! Declare variables\n\tINTEGER(kind=4), PARAMETER\t:: Nx=64\n\tINTEGER(kind=4), PARAMETER \t:: Ny=64\n\tINTEGER(kind=4), PARAMETER \t:: Nz=64\n\tINTEGER(kind=4), PARAMETER\t:: Nt=20 \n\tINTEGER(kind=4), PARAMETER\t:: plotgap=10\t\n\tREAL(kind=8), PARAMETER\t\t:: &\n\t\tpi=3.14159265358979323846264338327950288419716939937510d0\n\tREAL(kind=8), PARAMETER\t\t:: Lx=64.0d0\n\tREAL(kind=8), PARAMETER\t\t:: Ly=64.0d0 \n\tREAL(kind=8), PARAMETER\t\t:: Lz=64.0d0 \n\tREAL(kind=8), PARAMETER\t\t:: Es=1.0d0\t\n\tREAL(kind=8)\t\t\t\t:: dt=0.050d0/REAL(Nt,kind(0d0))\t\n\tCOMPLEX(kind=8), DIMENSION(:), ALLOCATABLE\t:: kx,ky,kz \n\tREAL(kind=8), \t DIMENSION(:), ALLOCATABLE\t:: x,y,z\t\n\tCOMPLEX(kind=8), DIMENSION(:,:,:), ALLOCATABLE:: u,nonlin,vtemp1\n\tCOMPLEX(kind=8), DIMENSION(:,:,:), ALLOCATABLE:: v,nonlinhat,vtemp2\n\tCOMPLEX(kind=8), DIMENSION(:,:,:), ALLOCATABLE:: uold\n\tCOMPLEX(kind=8), DIMENSION(:,:,:), ALLOCATABLE:: vold\n\tCOMPLEX(kind=8), DIMENSION(:,:,:), ALLOCATABLE:: unew\n\tCOMPLEX(kind=8), DIMENSION(:,:,:), ALLOCATABLE:: vnew\n\tREAL(kind=8), DIMENSION(:,:,:), ALLOCATABLE :: savearray\n\tREAL(kind=8), DIMENSION(:), ALLOCATABLE\t:: time,enkin,enstr,enpot,en\n\tINTEGER(kind=4), DIMENSION(:), ALLOCATABLE :: lowxv, upxv, lowzv, upzv\n\tREAL(kind=8) :: modescalereal\n\tINTEGER(kind=4)\t:: ierr,i,j,k,n,allocatestatus,numthreads,mythreadid\n\tINTEGER(kind=4)\t:: start, finish, count_rate, plotnum\n\tINTEGER(kind=4), PARAMETER\t:: FFTW_IN_PLACE = 8, FFTW_MEASURE = 0, &\n\t\tFFTW_EXHAUSTIVE = 8, FFTW_PATIENT = 32, FFTW_ESTIMATE = 64\n\tINTEGER(kind=4),PARAMETER\t:: FFTW_FORWARD = -1, FFTW_BACKWARD=1\t\n\tINTEGER(kind=8)\t:: planfxy,planbxy,planfz,planbz\n\tCHARACTER*100\t:: name_config\n\t! Start short parallel region to count threads \n\t!$OMP PARALLEL\n numthreads=omp_get_num_threads()\n !$OMP END PARALLEL\n PRINT *,'There are ',numthreads,' threads.'\n\tALLOCATE(kx(1:Nx),ky(1:Ny),kz(1:Nz),x(1:Nx),y(1:Ny),z(1:Nz),u(1:Nx,1:Ny,1:Nz),&\n\t\t\tv(1:Nz,1:Ny,1:Nx),nonlin(1:Nx,1:Ny,1:Nz),nonlinhat(1:Nz,1:Ny,1:Nx),&\n\t\t\tuold(1:Nx,1:Ny,1:Nz),vold(1:Nz,1:Ny,1:Nx),vtemp1(1:Nx,1:Ny,1:Nz),&\n\t\t\tvtemp2(1:Nz,1:Ny,1:Nx),unew(1:Nx,1:Ny,1:Nz),vnew(1:Nz,1:Ny,1:Nx),&\n\t\t\tsavearray(1:Nx,1:Ny,1:Nz),time(1:1+Nt/plotgap),enkin(1:1+Nt/plotgap),&\n\t\t\tenstr(1:1+Nt/plotgap),enpot(1:1+Nt/plotgap),en(1:1+Nt/plotgap),&\n\t\t\tlowxv(1:numthreads),upxv(1:numthreads),lowzv(1:numthreads),upzv(1:numthreads),&\n\t\t\tstat=allocatestatus)\t\n\tIF (allocatestatus .ne. 0) stop \n\tPRINT *,'allocated arrays'\n\t\n\t! set up ffts\n\tCALL dfftw_plan_dft_2d_(planfxy,Nx,Ny,u(1:Nx,1:Ny,1),vtemp1(1:Nx,1:Ny,1),&\n\t\t\t\t\t\t\tFFTW_FORWARD,FFTW_ESTIMATE)\n \tCALL dfftw_plan_dft_2d_(planbxy,Nx,Ny,vtemp1(1:Nx,1:Ny,1),u(1:Nx,1:Ny,1),&\n \t\t\t\t\t\t\tFFTW_BACKWARD,FFTW_ESTIMATE)\n\tCALL dfftw_plan_dft_(planfxy,Nx,Ny,v(1:Nz,1:Ny,1),vold(1:Nx,1:Ny,1),&\n\t\t\t\t\t\t\tFFTW_FORWARD,FFTW_ESTIMATE)\n \tCALL dfftw_plan_dft_(planbz,Nz,vold(1:Nz,1,1),v(1:Nz,1,1),&\n \t\t\t\t\t\t\tFFTW_BACKWARD,FFTW_ESTIMATE)\n\tPRINT *,'Setup FFTs'\n\tDO i=1,numthreads\n\t\tlowxv(i)=1+(i-1)*Nx/numthreads\n\tEND DO\n\tDO i=1,numthreads\n\t\tupxv(i)=i*Nx/numthreads\n\tEND DO\n\tDO k=1,numthreads\n\t\tlowzv(k)=1+(k-1)*Nz/numthreads\n\tEND DO\n\tDO k=1,numthreads\n\t\tupxv(k)=k*Nz/numthreads\n\tEND DO\n\tupxv(numthreads)=Nx\n\tupzv(numthreads)=Nz\n\t\n\t! setup fourier frequencies\n\tCALL getgrid(Nx,Ny,Nz,Lx,Ly,Lz,pi,name_config,x,y,z,kx,ky,kz)\n\tPRINT *,'Setup grid and fourier frequencies'\n\t!$OMP PARALLEL PRIVATE(i,j,k)\n\t! setup array ranges\n\tmythreadid=omp_get_thread_num()\n\tCALL initialdata(Nx,Ny,Nz,mythreadid,numthreads,lowxv,lowzv,upxv,upzv,&\n\t\t\t\tx,y,z,u,uold)\n\t!$OMP MASTER\t\t\t\n\tplotnum=1\t\n\tname_config = 'data/u' \n\t!$OMP END MASTER\n\tDO k=lowzv(mythreadid),upzv(mythreadid)\n\t\tDO j=1,Ny\n\t\t\tDO i=1,Nx\n\t\t\t\tsavearray(i,j,k)=REAL(unew(i,j,k),kind(0d0))\n\t\t\tEND DO\n\t\tEND DO\n\tEND DO\t\n\t!$OMP MASTER\n\tCALL savedata(Nx,Ny,Nz,plotnum,name_config,savearray)\n\t!$OMP END MASTER\n\t! forward transform\n\tCALL forwardfft(Nx,Ny,Nz,planfz,planfxy,mythreadid,numthreads,&\n\t\t\t\t\tlowxv,lowzv,upxv,upzv,u,v,vtemp1,vtemp2)\t\t\t\t\t\n\tCALL forwardfft(Nx,Ny,Nz,planfz,planfxy,mythreadid,numthreads,&\n\t\t\t\t\tlowxv,lowzv,upxv,upzv,uold,vold,vtemp1,vtemp2)\n\t!$OMP MASTER\n\tmodescalereal=1.0d0/REAL(Nx,KIND(0d0))\n\tmodescalereal=modescalereal/REAL(Ny,KIND(0d0))\n\tmodescalereal=modescalereal/REAL(Nz,KIND(0d0))\n\t!$OMP END MASTER\n\n\tCALL enercalc(Nx,Ny,Nz,planbxy,planbz,planfxy,planfz,dt,Es,&\n\t\t\tmodescalereal,enkin(plotnum),enstr(plotnum),enpot(plotnum),&\n\t\t\ten(plotnum),mythreadid,numthreads,lowxv,lowzv,upxv,upzv,&\n\t\t\tkx,ky,kz,nonlin,nonlinhat,vtemp1,vtemp2,v,vold,u,uold)\n\t!$OMP MASTER\n\tPRINT *,'Got initial data, starting timestepping'\n\ttime(plotnum)=0.0d0\n \tCALL system_clock(start,count_rate)\t\n\t!$OMP END MASTER\n\tDO n=1,Nt\t\t\t\t\t\n\t\tDO k=lowzv(mythreadid),upzv(mythreadid)\n\t\t\tDO j=1,Ny\n\t\t\t\tDO i=1,Nx\n\t\t\t\t\tnonlin(i,j,k)=(abs(u(i,j,k))*2)*u(i,j,k)\n\t\t\t\tEND DO\n\t\t\tEND DO\n\t\tEND DO\n\t\tCALL forwardfft(Nx,Ny,Nz,planfz,planfxy,mythreadid,numthreads,&\n\t\t\t\t\t lowxv,lowzv,upxv,upzv,nonlin,nonlinhat,vtemp1,vtemp2)\n\n\t\tDO i=lowxv(mythreadid),upxv(mythreadid)\n\t\t\tDO j=1,Ny\n\t\t\t\tDO k=1,Nz\n\t\t\t\t\tvnew(k,j,i)=&\n\t\t\t\t\t( 0.25d0*(kx(i)*kx(i) + ky(j)*ky(j)+ kz(k)*kz(k)-1.0d0)&\n\t\t\t\t\t*(2.0d0*v(k,j,i)+vold(k,j,i))&\n\t\t\t\t\t+(2.0d0*v(k,j,i)-vold(k,j,i))/(dt*dt)&\n\t\t\t\t\t+Es*nonlinhat(k,j,i) )&\n\t\t\t\t\t/(1/(dt*dt)-0.25*(kx(i)*kx(i)+ ky(j)*ky(j)+ kz(k)*kz(k)-1.0d0))\n\t\t\t\tEND DO\t\n\t\t\tEND DO\n\t\tEND DO\n\t\tCALL backwardfft(Nx,Ny,Nz,planbz,planbxy,mythreadid,numthreads,&\n\t\t\t\t\tlowxv,lowzv,upxv,upzv,vnew,unew,vtemp1,vtemp2)\n\t\t\t\t\t\t\t\t\t\t\n\t\t! normalize result\n\t\tDO k=lowzv(mythreadid),upzv(mythreadid)\n\t\t\tDO j=1,Ny\n\t\t\t\tDO i=1,Nx\n\t\t\t\t\tunew(i,j,k)=unew(i,j,k)*modescalereal\n\t\t\t\tEND DO\n\t\t\tEND DO\n\t\tEND DO\n\t\tIF (mod(n,plotgap)==0) then\n\t\t\t!$OMP MASTER\n\t\t\tplotnum=plotnum+1\n\t\t\ttime(plotnum)=n*dt\n\t\t\tPRINT *,'time',n*dt\n\t\t\t!$OMP END MASTER\n\t\t\tCALL enercalc(Nx,Ny,Nz,planbxy,planbz,planfxy,planfz,dt,Es,&\n\t\t\t\tmodescalereal,enkin(plotnum),enstr(plotnum),enpot(plotnum),&\n\t\t\t\ten(plotnum),mythreadid,numthreads,lowxv,lowzv,upxv,upzv,kx,ky,kz,&\n\t\t\t\tnonlin,nonlinhat,vtemp1,vtemp2,v,vold,u,uold)\n\t\t\tDO k=lowzv(mythreadid),upzv(mythreadid)\n\t\t\t\tDO j=1,Ny\n\t\t\t\t\tDO i=1,Nx\n\t\t\t\t\t\tsavearray(i,j,k)=REAL(unew(i,j,k),kind(0d0))\n\t\t\t\t\tEND DO\n\t\t\t\tEND DO\n\t\t\tEND DO\t\n\t\t\t!$OMP BARRIER\n\t\t\t!$OMP MASTER\n\t\t\tCALL savedata(Nx,Ny,Nz,plotnum,name_config,savearray)\n\t\t\t!$OMP END MASTER\n\t\tEND IF\n\t\t\t! .. Update old values ..\n\t\t!$OMP BARRIER\t\n\t\tCALL storeold(Nx,Ny,Nz,mythreadid,numthreads,&\n\t\t\t\t\tlowxv,lowzv,upxv,upzv,unew,u,uold,vnew,v,vold)\n\t\t!$OMP BARRIER\t\t\t\n\tEND DO\t\n\t!$OMP END PARALLEL\n\tPRINT *,'Finished time stepping'\n\tCALL system_clock(finish,count_rate)\n\tPRINT*,'Program took ',&\n\t\tREAL(finish-start,kind(0d0))/REAL(count_rate,kind(0d0)),&\n\t\t'for Time stepping'\n\tCALL saveresults(Nt,plotgap,time,en,enstr,enkin,enpot)\t\n\t\t\t\n\t! Save times at which output was made in text format\n\tPRINT *,'Saved data'\n\n\tCALL dfftw_destroy_plan_(planbxy)\n\tCALL dfftw_destroy_plan_(planfxy)\n\tCALL dfftw_destroy_plan_(planbz)\n\tCALL dfftw_destroy_plan_(planfz)\n\tCALL dfftw_cleanup()\n\tDEALLOCATE(kx,ky,kz,x,y,z,u,&\n\t\t\tv,nonlin,nonlinhat,&\n\t\t\tuold,vold,vtemp1,&\n\t\t\tvtemp2,unew,vnew,&\n\t\t\tsavearray,time,enkin,&\n\t\t\tenstr,enpot,en,&\n\t\t\tlowxv,upxv,lowzv,upzv,&\n\t\t\tstat=allocatestatus)\t\n\tIF (allocatestatus .ne. 0) STOP \n\tPRINT *,'Deallocated arrays'\n\tPRINT *,'Program execution complete'\n\tEND PROGRAM Kg\n", "meta": {"hexsha": "e7812ee0c946f8f21a21ca79d2ac4864323abcc2", "size": 11140, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "KleinGordon/Programs/KleinGordon3dThreadFFTv2/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/KleinGordon3dThreadFFTv2/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/KleinGordon3dThreadFFTv2/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": 35.7051282051, "max_line_length": 82, "alphanum_fraction": 0.6654398564, "num_tokens": 4407, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361509525463, "lm_q2_score": 0.7577943658046609, "lm_q1q2_score": 0.6914389743483306}} {"text": "!---------------------------------------------------------------------!\n! OWNER: Ithaca Combustion Enterprise, LLC !\n! COPYRIGHT: \u00a9 2012, Ithaca Combustion Enterprise, LLC !\n! LICENSE: BSD 3-Clause License (The complete text of the license can !\n! be found in the `LICENSE-ICE.txt' file included in the ISAT-CK7 !\n! source directory.) !\n!---------------------------------------------------------------------!\n\nsubroutine ell_pt_modify( n, c, gg, p )\n\n! Modify the ellipsoid E so that its boundary intersects the given\n! point p. The ellipsoid E is given by: { x | norm(G^T * (x-c) ) <=1 ), \n! where G is an n x n lower triangular matrix. The array gg contains \n! the matrix G in packed format.\n! Method: \n! 1/ transform to y-space in which E is the unit ball: (p-c) transforms to yp.\n! 2/ generate the modified ellipsoid in y-space in terms of a rank-one \n! modification of the identity: one principal axis is yp.\n! 3/ transform back to x-space and form the modified G.\n\n! S.B. Pope 12/24/05\n\nimplicit none\n\ninteger, parameter :: k_dp = kind(1.d0)\ninteger, intent(in) :: n\nreal(k_dp), intent(in) :: c(n), p(n)\nreal(k_dp), intent(inout) :: gg((n*(n+1))/2)\n\ninteger :: i, j, k\nreal(k_dp) :: yp(n), ypnorm, v(n), q(n,n), g(n,n), gamma\n\n! Transform to y-space: y = G^T * [x-c]\nyp = p-c \ncall dtpmv( 'L', 'T', 'N', n, gg, yp, 1 ) ! yp = G^T * [p-c]\n\n! Transform to z-space: z = Q^T * y, where yp = Q * R\nypnorm = sqrt( sum(yp*yp) )\n\nif( ypnorm == 0.d0 ) then ! degenerate case p = c\n gg = 0.d0 ! set G = I * 1.d30\n k = 0 \n do j = 1, n\n do i = j,n\n k = k + 1\n\t if( i == j ) gg(k) = 1.d30\n end do\n end do\n return\nendif\n\n! The modified ellipsoid is { y | y^T B^2 y <=1 }\n! B = I + gamma * yp * yp^2\n\ngamma = (1.d0/ypnorm - 1.d0) / ypnorm**2\n\n! Transform back to x\ng = 0.d0\nk = 0 ! unpack g\ndo j = 1, n\n do i = j,n\n k = k + 1\n\t g(i,j) = gg(k)\n end do\nend do\n\n! q = G*B = G + (gamma*G*yp)*yp^T\n\nv = gamma * matmul( g, yp )\n\ndo i = 1, n\ndo j = 1, n\n q(i,j) = g(i,j) + v(i)*yp(j)\nend do\nend do\n\n\ncall ell_bbt2chol( n, q, gg )\n\nreturn\nend subroutine ell_pt_modify\n", "meta": {"hexsha": "69b75deb5fec92db7bbeda34225e2c449588e3e2", "size": 2243, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/isat/ell_lib/ell_pt_modify.f90", "max_stars_repo_name": "xuhan425/isat_ffd", "max_stars_repo_head_hexsha": "3a5449f7e49b686c33fe0e97ca90ea8d92fc2f00", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-04-10T20:16:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-15T11:09:44.000Z", "max_issues_repo_path": "src/isat/ell_lib/ell_pt_modify.f90", "max_issues_repo_name": "xuhan425/isat_ffd", "max_issues_repo_head_hexsha": "3a5449f7e49b686c33fe0e97ca90ea8d92fc2f00", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-06-07T14:10:25.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-07T14:10:25.000Z", "max_forks_repo_path": "src/isat/ell_lib/ell_pt_modify.f90", "max_forks_repo_name": "xuhan425/isat_ffd", "max_forks_repo_head_hexsha": "3a5449f7e49b686c33fe0e97ca90ea8d92fc2f00", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-06-07T03:44:12.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-05T05:54:10.000Z", "avg_line_length": 27.3536585366, "max_line_length": 79, "alphanum_fraction": 0.5207311636, "num_tokens": 768, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.923039160069787, "lm_q2_score": 0.7490872243177518, "lm_q1q2_score": 0.6914368423532657}} {"text": "\tprogram jacobitst\nc\nc\twhat's a row and what's a column?\nc\tthis shows that, in evect(i,j) i is component, j is vector #\nc\n\treal aa(3,3),evect(3,3),eval(3)\n\tdata aa /9*0./\nc\n\taa(1,1) = 1.\n\taa(2,2) = 2.\n\taa(3,3) = 1.\n\taa(1,2) = .5\n\taa(2,1) = aa(1,2) \n\tcall jacobi(aa,3,3,eval,evect,nrot)\n\tprint*,eval\n\tdo j = 1,3\n\t print*,evect(1,j),evect(2,j),evect(3,j)\n\tenddo\n\tcall eigsrt(eval,evect,3,3)\n\tprint*,eval\n\tdo j = 1,3\n\t print*,evect(1,j),evect(2,j),evect(3,j)\n\tenddo\n\tstop\n\tend\t\n", "meta": {"hexsha": "e22f3e89a0cb30391240efa651acbfe314c6caa5", "size": 477, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/jacobitst_6.for", "max_stars_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_stars_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/jacobitst_6.for", "max_issues_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_issues_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/jacobitst_6.for", "max_forks_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_forks_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.3461538462, "max_line_length": 62, "alphanum_fraction": 0.605870021, "num_tokens": 232, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.923039160069787, "lm_q2_score": 0.749087201911703, "lm_q1q2_score": 0.6914368216716053}} {"text": "program euler_094\n use EulerCommon\n integer(int64) :: L = 10**9\n integer(int64) :: a, c, s, p, m\n integer(int64) :: new(4)\n\n a = 1\n c = 1\n s = 0\n p = 0\n m = 1\n ! use generating function n(i) = 4*n(i-1) - n(i-2); cf. wiki on Heronian Triangles\n do while (p < L)\n ! if the next line doesn't work, get a better compiler\n new = [c, 4*c - a + 2*m, -m, s + p]\n a = new(1); c = new(2); m = new(3); s = new(4)\n p = 3*c - m\n end do\n \n print *,s\n \nend program euler_094ents here\n", "meta": {"hexsha": "c32d845e50f447df2a14a2154b784c043d39256a", "size": 519, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "euler_094.f90", "max_stars_repo_name": "kylekanos/ProjectEuler", "max_stars_repo_head_hexsha": "bfdbda0a9a83af45b92c47439f657d11df785527", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-05-13T03:36:23.000Z", "max_stars_repo_stars_event_max_datetime": "2016-05-13T03:36:23.000Z", "max_issues_repo_path": "euler_094.f90", "max_issues_repo_name": "kylekanos/ProjectEuler", "max_issues_repo_head_hexsha": "bfdbda0a9a83af45b92c47439f657d11df785527", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "euler_094.f90", "max_forks_repo_name": "kylekanos/ProjectEuler", "max_forks_repo_head_hexsha": "bfdbda0a9a83af45b92c47439f657d11df785527", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.5652173913, "max_line_length": 85, "alphanum_fraction": 0.5163776493, "num_tokens": 207, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012671214071, "lm_q2_score": 0.7310585727705126, "lm_q1q2_score": 0.6914361244663182}} {"text": "!PR fortran/32238\n! { dg-do compile }\n! { dg-final { cleanup-modules \"bug_test\" } }\n\nmodule bug_test\n\ncontains\n subroutine bug(c)\n\n implicit none\n\n integer, parameter :: fp = selected_real_kind(13)\n complex(kind=fp) :: c(:,:)\n where( abs( aimag( c ) ) < 1.e-10_fp ) &\n & c = cmplx( real( c , fp ) , 0._fp , fp )\n where( abs( real( c , fp ) ) < 1.e-10_fp ) &\n & c = cmplx( 0._fp , aimag( c ) , fp )\n\n return\n end subroutine bug\n\nend module bug_test\n", "meta": {"hexsha": "2c88b356561414e59a6ed4886761958026ef9662", "size": 529, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/pr32238.f90", "max_stars_repo_name": "maurizioabba/rose", "max_stars_repo_head_hexsha": "7597292cf14da292bdb9a4ef573001b6c5b9b6c0", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/pr32238.f90", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/pr32238.f90", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 23.0, "max_line_length": 70, "alphanum_fraction": 0.5160680529, "num_tokens": 166, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818409, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.691391338679145}} {"text": "program problem92\n implicit none\n integer, parameter :: mlimit=10000000,tlimit=1000000\n integer*1, dimension(mlimit) :: memo\n integer :: i,answer\n\n do i=1,mlimit\n memo(i)=0\n end do\n memo(1)=1\n memo(89)=89\n\n do i=1,mlimit\n call trajectory(i)\n end do\n\n answer=0\n do i=1,mlimit-1\n if(memo(i)==89) answer=answer+1\n end do\n\n print *, answer\n\ncontains\n\n subroutine trajectory(n)\n implicit none\n integer, intent(in) :: n\n integer, dimension(tlimit) :: history\n integer :: i,current\n\n current=n\n i=0\n do while(memo(current)/=1 .and. memo(current)/=89) ! follow trajectory\n i=i+1\n history(i)=current\n current=step(current)\n end do\n do i=i,1,-1 ! record results in memo\n memo(history(i))=memo(current)\n end do\n\n end subroutine trajectory\n\n pure function step(n)\n implicit none\n integer, intent(in) :: n\n integer :: step,remaining\n\n step=0\n remaining=n\n do while (remaining>0)\n step=step+mod(remaining,10)**2\n remaining=remaining/10\n end do\n \n end function step\n\nend program problem92\n", "meta": {"hexsha": "d8de612d00862fef0ca4fe69152c5a20787f39dd", "size": 1163, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "problem92.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": "problem92.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": "problem92.f08", "max_forks_repo_name": "jamesmcclain/Dioskouroi", "max_forks_repo_head_hexsha": "e433cbf7a1306d2755723f1028a4a3034da9d64a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.3833333333, "max_line_length": 74, "alphanum_fraction": 0.5941530525, "num_tokens": 338, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476793890012, "lm_q2_score": 0.7879311931529758, "lm_q1q2_score": 0.691391337173805}} {"text": "\nc read data from a text file and fit a gaussian to it\n\n program fitgausfile\n\n parameter (NMAX=10000)\n\n real xd(NMAX),yd(NMAX),yerr(NMAX),yfit(NMAX)\n real pars(4),errpars(4),dydp(4)\n integer ifit(4)\n character fname*80\n\nc file is assumed sorted with x increasing\n\n call pgbeg(0,\"?\",1,1)\n call pgscf(2)\n call pgsch(1.5)\n \n 100 continue\n write(*,'(\"File with x,y,yerr [quit]: \",$)')\n read(*,'(a)') fname\n if (fname(1:3) .eq. ' ') go to 666\n open(2,file=fname,status='old',err=100)\n\n np = 1\n 200 continue\n read(2,*,err=220,end=220) xd(np),yd(np),yerr(np)\n np = np + 1\n go to 200\n 220 continue\n np = np-1\n close(2)\n write(*,'(\"Read \",i5,\" points\")') np\n\nc plot data\nc wxmin = 1.e10\nc wxmax = -1.e10\n wxmin = xd(1)\n wxmax = xd(np)\n wymin = 1.e10\n wymax = -1.e10\n do i=1,np\n wymin = min(wymin,yd(i))\n wymax = max(wymax,yd(i))\n end do\n wxmarg = (wxmax-wxmin) / 100.\n wymarg = (wymax-wymin) / 40.\n call pgenv(wxmin-wxmarg,wxmax+wxmarg,wymin-wymarg,\n $ wymax+wymarg,0,1)\n call pgpt(np,xd,yd,17)\n call pgerrb(6,np,xd,yd,yerr,0.0)\n\n write(*,'(\"x range to fit: \",$)')\n read(*,*) xmin,xmax\n call locate(xd,np,xmin,ixmin)\n ixmin = max(ixmin,1)\n call locate(xd,np,xmax,ixmax)\n ixmax = min(ixmax,np)\n nfit = ixmax-ixmin+1\n\n iguess=1\n do i=1,4\n ifit(i) = 1\n end do\n call fitgaus(xd(ixmin),yd(ixmin),yerr(ixmin),nfit,\n $ pars,errpars,ifit,iguess,chisq)\n do i=1,4\n write (*,*) pars(i),\" +- \", errpars(i)\n end do\n write(*,*) \"chisq = \",chisq\n\nc compute and plot fit\n do i=ixmin,ixmax\n call gausfunc(xd(i),pars,yfit(i),dydp,4)\n end do\n call pgqci(indexc)\n call pgsci(2)\n call pgline(nfit,xd(ixmin),yfit(ixmin))\n call pgsci(indexc)\n\nc write out data, fit, subtracted\n\n open(3,file='fitgausfile.out',status='unknown')\n do i=1,np\nc call gausfunc(xd(i),pars,gfitval,dydp,4)\nc write(3,*) i,xd(i),yd(i),yerr(i),gfitval,yd(i)-gfitval\n call gausfunc(xd(i),pars,yfit(i),dydp,4)\n write(3,*) i,xd(i),yd(i),yerr(i),yfit(i),yd(i)-yfit(i)\n end do\n close(3)\n\n go to 100\n\n 666 continue\n\n end\n\n \n", "meta": {"hexsha": "c9e919e95a92f94cebbd54a8d4b771ae70fabbf3", "size": 2357, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "fitgausfile.f", "max_stars_repo_name": "bjweiner/statprogs", "max_stars_repo_head_hexsha": "6e70b17f93d1beb4e9dffd3939c443bf9398bf10", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fitgausfile.f", "max_issues_repo_name": "bjweiner/statprogs", "max_issues_repo_head_hexsha": "6e70b17f93d1beb4e9dffd3939c443bf9398bf10", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fitgausfile.f", "max_forks_repo_name": "bjweiner/statprogs", "max_forks_repo_head_hexsha": "6e70b17f93d1beb4e9dffd3939c443bf9398bf10", "max_forks_repo_licenses": ["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.8080808081, "max_line_length": 64, "alphanum_fraction": 0.5366991939, "num_tokens": 871, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476793890012, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.6913913349889589}} {"text": "\nC The program below uses ZVODE to solve the following system of 2 ODEs:\nC dz/dt = i*z; dw/dt = -i*w*w*z,z(0) = 1; w(0) = 1/2.1, t = 0 to 2*pi.\nC Solution: w = 1/(z + 1.1), z = exp(it). As z traces the unit circle,\nC w traces a circle of radius 10/2.1 with center at 11/2.1.\n\n\n SUBROUTINE FEX (NEQ, T, Y, YDOT, RPAR, IPAR)\n INTEGER NEQ, IPAR(*)\n DOUBLE COMPLEX Y(NEQ), YDOT(NEQ), RPAR(*), CMP\n DOUBLE PRECISION T\n character(len=100) msg\n\nc the imaginary unit i\n CMP = DCMPLX(0.0D0,1.0D0)\n\n YDOT(1) = CMP*Y(1)\n YDOT(2) = -CMP*Y(2)*Y(2)*Y(1)\n\n RETURN\n END\n\n SUBROUTINE JEX (NEQ, T, Y, ML, MU, PD, NRPD, RPAR, IPAR)\n INTEGER NEQ, ML, MU, NRPD, IPAR(*)\n DOUBLE COMPLEX Y(NEQ), PD(NRPD,NEQ), RPAR(*), CMP\n DOUBLE PRECISION T\nc the imaginary unit i\n CMP = DCMPLX(0.0D0,1.0D0)\n\n PD(2,3) = -2.0D0*CMP*Y(1)*Y(2)\n PD(2,1) = -CMP*Y(2)*Y(2)\n PD(1,1) = CMP\n RETURN\n END\n", "meta": {"hexsha": "98beed50ea0229fe4a90734c548da8e2c80c75c6", "size": 959, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "deSolve/doc/dynload/zvodedll.f", "max_stars_repo_name": "solgenomics/R_libs", "max_stars_repo_head_hexsha": "a936847f6063cdf3d207e8364f05f2e13be2d878", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "deSolve/doc/dynload/zvodedll.f", "max_issues_repo_name": "solgenomics/R_libs", "max_issues_repo_head_hexsha": "a936847f6063cdf3d207e8364f05f2e13be2d878", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-08-17T15:14:11.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-23T21:55:49.000Z", "max_forks_repo_path": "deSolve/doc/dynload/zvodedll.f", "max_forks_repo_name": "solgenomics/R_libs", "max_forks_repo_head_hexsha": "a936847f6063cdf3d207e8364f05f2e13be2d878", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-04T05:34:16.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-04T05:34:16.000Z", "avg_line_length": 27.4, "max_line_length": 71, "alphanum_fraction": 0.5557872784, "num_tokens": 415, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767810736692, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.6913913248905627}} {"text": "program linear_transform\n implicit none\n real, dimension(5) :: values\n real, dimension(2) :: a = [ 1.1, 2.2 ], &\n x = [ 0.5, 2.0 ], &\n b = [ -1.2, 2.5 ]\n integer :: i\n\n call random_number(values)\n print *, values\n print *, lin_transform(values, 2.0, 1.0)\n print *, lin_transform(x, a, b)\n\ncontains\n\n elemental real function lin_transform(x, a, b)\n implicit none\n real, intent(in) :: x, a, b\n\n lin_transform = a*x + b\n end function lin_transform\n\nend program linear_transform\n", "meta": {"hexsha": "14a461a2218121b03692c32ee32f02b5f09c6c03", "size": 576, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source_code/arrays/linear_transform.f90", "max_stars_repo_name": "caguerra/Fortran-MOOC", "max_stars_repo_head_hexsha": "fb8a9c24e62ce5f388deb06b21e3009aea6b78d4", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2021-05-20T12:03:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-16T19:46:26.000Z", "max_issues_repo_path": "source_code/arrays/linear_transform.f90", "max_issues_repo_name": "caguerra/Fortran-MOOC", "max_issues_repo_head_hexsha": "fb8a9c24e62ce5f388deb06b21e3009aea6b78d4", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-09-30T04:25:50.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-06T08:21:30.000Z", "max_forks_repo_path": "source_code/arrays/linear_transform.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": 24.0, "max_line_length": 50, "alphanum_fraction": 0.5434027778, "num_tokens": 164, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767810736693, "lm_q2_score": 0.7879311856832191, "lm_q1q2_score": 0.6913913205208707}} {"text": "!>\n! Runs a linear advection diffusion equation with increasing resolution and checks that the observed\n! convergence orders match the order of the involved discretizations.\n!\nPROGRAM advection_diffusion_test\n\nUSE Timestepper, only : Euler, RK3Ssp, InitializeTimestepper, FinalizeTimestepper\nIMPLICIT NONE\n\nINCLUDE 'mpif.h'\n\n#include \n\n#if(linear==0)\n WRITE(*,*) 'WARNING: advection_diffusion_test requires linear advection to have analytical solution available... recompile with flag linear=1 to run this test. Now exiting.'\n STOP\n#else\n\nDOUBLE PRECISION, PARAMETER :: pi = 3.1415926535897932_8 ! underscore indicates rounding to real(8) precision\nINTEGER, PARAMETER, DIMENSION(5) :: N_v = (/ 20, 30, 40, 50, 60 /)\n\nDOUBLE PRECISION, PARAMETER :: Tend = 0.05\n\nDOUBLE PRECISION, ALLOCATABLE, DIMENSION(:,:,:,:) :: Q, Qref\nDOUBLE PRECISION, ALLOCATABLE, DIMENSION(:) :: error\n\nDOUBLE PRECISION :: dx, dy, dz, x, y, z, dt, nu, convrate\nINTEGER :: method, i, j, k, Nx, Ny, Nz, nn, order_adv, order_diff, Nsteps, Nthreads, mpi_thread_provided, ierr\n\nCALL MPI_INIT_THREAD(MPI_THREAD_FUNNELED, mpi_thread_provided, ierr)\n\n\nDO method=1,3,2\n \n IF (method==1) THEN\n order_adv = 1\n order_diff = 2\n ELSE IF (method==3) THEN\n order_adv = 5\n order_diff = 4\n END IF\n \n ALLOCATE(error(SIZE(N_v)))\n\n DO nn=1,SIZE(N_v)\n\n Nx = N_v(nn)-3\n Ny = N_v(nn)+1\n Nz = N_v(nn)+3\n \n dx = 1.0/DBLE(Nx)\n dy = 1.0/DBLE(Ny)\n dz = 1.0/DBLE(Nz)\n \n !nu = 0.0025\n nu = 0.0\n !dt = 0.5*(dz*dz)/nu\n dt = 0.25*dz\n Nsteps = CEILING(Tend/dt)\n dt = Tend/DBLE(Nsteps)\n\n Nthreads=1\n\n ALLOCATE(Q( -2:Nx+3, -2:Ny+3, -2:Nz+3, 0:Nthreads-1))\n ALLOCATE(Qref(-2:Nx+3, -2:Ny+3, -2:Nz+3, 0:Nthreads-1))\n\n CALL InitializeTimestepper(nu, Nx, Ny, Nz, Nthreads)\n \n ! Compute initial and analytic solution \n DO k=-2,Nz+3\n DO j=-2,Ny+3\n DO i=-2,Nx+3\n\n x = 0.5*dx + DBLE(i - 1)*dx\n y = 0.5*dy + DBLE(j - 1)*dy\n z = 0.5*dz + DBLE(k - 1)*dz\n \n Q(i,j,k,:) = SIN(2.0*pi*x)*SIN(2.0*pi*y)*SIN(2.0*pi*z) \n Qref(i,j,k,:) = EXP(-12*nu*pi*pi*Tend)*SIN(2.0*pi*(x-Tend))*SIN(2.0*pi*(y-Tend))*SIN(2.0*pi*(z-Tend))\n \n END DO\n END DO\n END DO\n\n \n IF (method==1) THEN\n CALL Euler( Q(:,:,:,0), DBLE(0.0), Tend, Nsteps, dx, dy, dz, order_adv, order_diff)\n ELSE IF (method==3) THEN\n CALL Rk3Ssp(Q(:,:,:,0), DBLE(0.0), Tend, Nsteps, dx, dy, dz, order_adv, order_diff)\n END IF\n\n error(nn) = MAXVAL(ABS(Q(1:Nx,1:Ny,1:Nz,0) - Qref(1:Nx,1:Ny,1:Nz,0)))/MAXVAL(ABS(Qref(1:Nx,1:Ny,1:Nz,0)))\n\n CALL FinalizeTimestepper \n \n DEALLOCATE(Q)\n DEALLOCATE(Qref)\n\n END DO ! N_v\n \n DO nn=1,SIZE(N_v)-1\n convrate = LOG10( error(nn+1)/error(nn) )/LOG10( DBLE(N_v(nn))/DBLE(N_v(nn+1)) )\n IF (convrate < 0.95*DBLE(method)) THEN\n WRITE(*,'(A, I2, A)') 'ERROR: Method ', method, ' failed to reproduce expected order of convergence. Now exiting.'\n STOP\n END IF\n END DO\n \n DEALLOCATE(error)\n\nEND DO ! method\n\nCALL MPI_FINALIZE(ierr)\n\nPRINT*, '\\x1B[32m[0] -- Successful: Both Euler and Rk3Ssp produced the expected order of convergence for the linear advection-diffusion problem. \\x1B[0m'\n\n#endif\n\nEND PROGRAM advection_diffusion_test", "meta": {"hexsha": "90b37461906b190e478950519805578630e21fe4", "size": 3784, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/src/advection_diffusion_conv_test.f90", "max_stars_repo_name": "Parallel-in-Time/PararealF90", "max_stars_repo_head_hexsha": "a8318a79b92465a8a3cf775cc7fd096ff0494529", "max_stars_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2017-03-17T15:04:00.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-10T08:05:52.000Z", "max_issues_repo_path": "test/src/advection_diffusion_conv_test.f90", "max_issues_repo_name": "Parallel-in-Time/PararealF90", "max_issues_repo_head_hexsha": "a8318a79b92465a8a3cf775cc7fd096ff0494529", "max_issues_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2015-09-23T09:08:12.000Z", "max_issues_repo_issues_event_max_datetime": "2015-09-23T09:32:24.000Z", "max_forks_repo_path": "test/src/advection_diffusion_conv_test.f90", "max_forks_repo_name": "Parallel-in-Time/PararealF90", "max_forks_repo_head_hexsha": "a8318a79b92465a8a3cf775cc7fd096ff0494529", "max_forks_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-10-24T20:15:26.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-10T08:05:36.000Z", "avg_line_length": 31.7983193277, "max_line_length": 177, "alphanum_fraction": 0.5430761099, "num_tokens": 1203, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916134888614, "lm_q2_score": 0.8006920092299292, "lm_q1q2_score": 0.691310765756667}} {"text": "module test_various_functions_mod\n use various_functions_mod\n use funit\n implicit none\n \ncontains\n\n @test\n subroutine test_dmatinv3()\n \n double precision,dimension(3,3) :: A, B, C, D\n double precision,dimension(3,3) :: D_known\n integer :: ierr\n \n A = reshape((/1.d0, 0.d0, 0.d0, 0.d0, 1.d0, 0.d0, 0.d0, 0.d0, 1.d0/), (/3, 3/))\n call dmatinv3(A, B, ierr)\n \n @assertEqual(A, B, tolerance=1e-13, message=\"test various_functions_mod with identity matrix\")\n \n C = reshape((/0.d0, 1.d0, 1.d0, 1.d0, 0.d0, 1.d0, 1.d0, 1.d0, 0.d0/), (/3, 3/))\n call dmatinv3(C, D, ierr)\n \n D_known = 1.d0/2.d0*reshape((/-1.d0, 1.d0, 1.d0, 1.d0, -1.d0, 1.d0, 1.d0, 1.d0, -1.d0/), (/3, 3/))\n @assertEqual(D, D_known, tolerance=1e-13, message=\"test various_functions_mod with a symmetric matrix\")\n\n end subroutine test_dmatinv3\n \n @test\n subroutine test_dmatinv3_fail()\n \n double precision,dimension(3,3) :: A, B, C, D\n integer :: ierr\n \n A = reshape((/1.d0, 0.d0, 0.d0, 0.d0, 1.d0, 0.d0, 0.d0, 0.d0, 0.d0/), (/3, 3/))\n call dmatinv3(A, B, ierr)\n \n @assertEqual(ierr, 1, message = \"test various_functions_mod, matrix not invertible\")\n\n\n end subroutine test_dmatinv3_fail\n \nend module test_various_functions_mod\n", "meta": {"hexsha": "33b37afa4cfadb623b86f001b97fe6af1285680f", "size": 1322, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "SRC/TESTS/test_various_functions_mod.f90", "max_stars_repo_name": "Forsti5/GORILLA", "max_stars_repo_head_hexsha": "a28576e625a55b2c3adacf0dbb6806294f888e6f", "max_stars_repo_licenses": ["MIT"], "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/TESTS/test_various_functions_mod.f90", "max_issues_repo_name": "Forsti5/GORILLA", "max_issues_repo_head_hexsha": "a28576e625a55b2c3adacf0dbb6806294f888e6f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SRC/TESTS/test_various_functions_mod.f90", "max_forks_repo_name": "Forsti5/GORILLA", "max_forks_repo_head_hexsha": "a28576e625a55b2c3adacf0dbb6806294f888e6f", "max_forks_repo_licenses": ["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.7441860465, "max_line_length": 109, "alphanum_fraction": 0.5983358548, "num_tokens": 496, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633915959134569, "lm_q2_score": 0.8006920116079209, "lm_q1q2_score": 0.691310753737319}} {"text": "subroutine heat_fort_rhs(blockno, mbc,mx,my,meqn,mfields, & \n xlower,ylower,dx,dy,lambda, method,q,rhs)\n IMPLICIT NONE\n\n INTEGER mbc,mx,my, mfields, meqn, method\n DOUBLE PRECISION xlower,ylower,dx,dy, lambda\n DOUBLE PRECISION rhs(1-mbc:mx+mbc,1-mbc:my+mbc,mfields) \n DOUBLE PRECISION q(1-mbc:mx+mbc,1-mbc:my+mbc,meqn)\n\n INTEGER i,j, blockno\n\n do i = 1-mbc,mx+mbc\n do j = 1-mbc,my+mbc\n!! xc = xlower + (i-0.5)*dx\n!! yc = ylower + (j-0.5)*dy\n rhs(i,j,1) = lambda*q(i,j,1)\n end do\n end do\n\nend subroutine heat_fort_rhs\n\n\nsubroutine heat_update_q(mbc,mx,my,meqn,mfields,rhs,q)\n IMPLICIT NONE\n\n INTEGER mbc,mx,my, mfields, meqn\n DOUBLE PRECISION rhs(1-mbc:mx+mbc,1-mbc:my+mbc,mfields) \n DOUBLE PRECISION q(1-mbc:mx+mbc,1-mbc:my+mbc,meqn)\n\n INTEGER i,j\n\n do i = 1,mx\n do j = 1,my\n q(i,j,1) = rhs(i,j,1)\n end do\n end do\n!!100 format(2F16.8)\n\nend subroutine heat_update_q\n\n", "meta": {"hexsha": "317b1dd100046eb08374d2f1ed6d179eebb2cea6", "size": 1012, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "applications/elliptic/heat/fortran/heat_fort_rhs.f90", "max_stars_repo_name": "ForestClaw/ForestClaw", "max_stars_repo_head_hexsha": "c81095f3e525f99cfb771c9049e9d272eb12d4cb", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "applications/elliptic/heat/fortran/heat_fort_rhs.f90", "max_issues_repo_name": "ForestClaw/ForestClaw", "max_issues_repo_head_hexsha": "c81095f3e525f99cfb771c9049e9d272eb12d4cb", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-08-02T09:52:43.000Z", "max_issues_repo_issues_event_max_datetime": "2017-08-02T14:16:23.000Z", "max_forks_repo_path": "applications/elliptic/heat/fortran/heat_fort_rhs.f90", "max_forks_repo_name": "ForestClaw/ForestClaw", "max_forks_repo_head_hexsha": "c81095f3e525f99cfb771c9049e9d272eb12d4cb", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.6829268293, "max_line_length": 66, "alphanum_fraction": 0.5958498024, "num_tokens": 386, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.847967769904032, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.6912908797557218}} {"text": "! Longest Collatz sequence\n!\n! The following iterative sequence is defined for the set of positive integers:\n!\n! n > n/2 (n is even)\n! n > 3n + 1 (n is odd)\n!\n! Using the rule above and starting with 13, we generate the following sequence:\n!\n! 13 > 40 > 20 > 10 > 5 > 16 > 8 > 4 > 2 > 1\n!\n! It can be seen that this sequence (starting at 13 and finishing at 1) contains\n! 10 terms. Although it has not been proved yet (Collatz Problem), it is\n! thought that all starting numbers finish at 1.\n!\n! Which starting number, under one million, produces the longest chain?\n!\n! NOTE: Once the chain starts the terms are allowed to go above one million.\nmodule Problem14\n\n implicit none\n private\n\n public :: solve\ncontains\n subroutine solve\n write (*, '(A)') 'Problem 14. Longest Collatz sequence.'\n\n write (*, '(A, I)') 'Chain 1: ', chain1()\n end subroutine\n\n function chain1\n integer :: chain1\n integer :: index\n integer :: value\n integer :: max\n\n ! initial values\n chain1 = 0\n index = 0\n value = 0\n max = 0\n\n do index = 1, 1000000\n value = get_length(index)\n\n if (value .gt. max) then\n max = value\n chain1 = index\n end if\n end do\n end function\n\n function get_length(number)\n integer, intent(in) :: number\n\n integer :: get_length\n integer*8 :: value\n\n ! initial value\n get_length = 1\n value = number\n\n do while (value .gt. 1)\n if (mod(value, 2) .eq. 0) then\n value = value / 2\n else\n value = (value * 3) + 1\n end if\n\n get_length = get_length + 1\n end do\n end function\nend module\n", "meta": {"hexsha": "172c3bb0f1888271fb1368b4d30e811430064a04", "size": 1808, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Problem14.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": "Problem14.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": "Problem14.f", "max_forks_repo_name": "andreypudov/projecteuler", "max_forks_repo_head_hexsha": "898b1db49c6fdde8fa42c7a2bc471a0ed3bc73e9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.1066666667, "max_line_length": 80, "alphanum_fraction": 0.5536504425, "num_tokens": 490, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677660619634, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.6912908785268395}} {"text": " !#################################################################################!\n !/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\!\n!######################################################################################!\n!##! !##!\n!##! !##!\nMODULE Additional_Functions_Module !##!\n!##! !##!\n!##!________________________________________________________________________________!##!\n!##! !##!\n!##! Contains functions and subroutine to calculate special functions such as !##!\n!##! the Lagrange and Legendre Polynomials and Spherical Harmonics, initialize !##!\n!##! quadratures, perform other useful operations !##!\n!##! !##!\n!##!================================================================================!##!\n!##! !##!\n!##! Contains: !##!\n!##! !##!\n!##! +101+ Lagrange_Poly !##!\n!##! +102+ Lagrange_First_Deriv !##!\n!##! +103+ Lagrange_Second_Deriv !##!\n!##! +104+ Legendre_Poly !##!\n!##! +105+ Spherical_Harmonic !##!\n!##! !##!\n!##! +201+ Norm_Factor !##!\n!##! +202+ Factorial !##!\n!##! +203+ Factorial_Division !##!\n!##! +204+ Power !##!\n!##! !##!\n!##! +301+ Map_To_X_Space !##!\n!##! +302+ Map_From_X_Space !##!\n!##! !##!\n!##! +401+ MVMULT_CCS !##!\n!##! +402+ MVMULT_FULL !##!\n!##! +403+ SVVAD !##!\n!##! !##!\n!##! +501+ Initialize_LGL_Quadrature !##!\n!##! +502+ Initialize_LGL_Quadrature_Locations !##!\n!##! +503+ Initialize_LG_Quadrature !##!\n!##! +504+ Initialize_LG_Quadrature_Locations !##!\n!##! !##!\n!##! +601+ SphericalHarmonic_OrthogonalityTest !##!\n!##! !##!\n!##! !##!\n!######################################################################################!\n !\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/!\n !#################################################################################!\n\n!*D*================================!\n! !\n! Dependencies !\n! !\n!===================================!\nUSE constants, &\n ONLY: idp, pi, eps\n\n\n\nIMPLICIT NONE\n\n\n\n\n\nCONTAINS\n !+101+################################################################!\n! !\n! Lagrange_Poly - Calculates the value of the Lagrange Polynomial !\n! !\n! !\n !#####################################################################!\nPURE FUNCTION Lagrange_Poly(x, Ord, xlocs)\n\n\nINTEGER, INTENT(IN) :: Ord\nREAL(KIND = idp), INTENT(IN) :: x\nREAL(KIND = idp), INTENT(IN), DIMENSION(0:Ord) :: xlocs\n\n\nINTEGER :: i,j\nREAL(KIND = idp), DIMENSION(0:Ord) :: tmp\nREAL(KIND = idp), DIMENSION(0:Ord) :: Lagrange_Poly\n\n\n\ntmp(:) = 1.0_idp\n\nDO j = 0,Ord\n DO i = 0,Ord\n IF (i .NE. j) THEN\n tmp(i) = tmp(i) * (x - xlocs(j))/(xlocs(i) - xlocs(j))\n END IF\n END DO\nEND DO\n\n\n\nLagrange_Poly = tmp\n\n\nEND FUNCTION Lagrange_Poly\n\n\n\n\n\n !+102+################################################################!\n! !\n! Lagrange_Poly_Deriv - Calculates the value of the first derivative !\n! of Lagrange Polynomials. !\n! !\n! !\n !#####################################################################!\nFUNCTION Lagrange_Poly_Deriv(x, Ord, xlocs)\n\nINTEGER, INTENT(in) :: Ord\nREAL(KIND = idp), INTENT(in) :: x\nREAL(KIND = idp), INTENT(inout), DIMENSION(0:Ord) :: xlocs\n\n\n\nINTEGER :: i,j,k\nREAL(KIND = idp), DIMENSION(0:Ord) :: tmp,tmp2\nREAL(KIND = idp), DIMENSION(0:Ord) :: Lagrange_Poly_Deriv\n\n\ntmp(:) = 1.0_idp\ntmp2(:) = 0.0_idp\n\nDO j = 0,Ord\n DO i = 0,Ord\n IF (i .NE. j) THEN\n\n tmp(i) = 1/(xlocs(i) - xlocs(j))\n\n DO k = 0,Ord\n\n IF (k .NE. i .AND. k .NE. j) THEN\n tmp(i) = tmp(i) * (x - xlocs(k))/(xlocs(i) - xlocs(k))\n END IF\n\n END DO\n tmp2(i) = tmp2(i) + tmp(i)\n END IF\n END DO\nEND DO\n\n\n\nLagrange_Poly_Deriv = tmp2\n\n\nEND FUNCTION Lagrange_Poly_Deriv\n\n\n\n\n\n !+103+################################################################!\n! !\n! Lagrange_Second_Deriv - Calculates the value of the first derivative !\n! of Lagrange Polynomials. !\n! !\n! !\n !#####################################################################!\nFUNCTION Lagrange_Second_Deriv(x, Ord, xlocs)\n\nINTEGER, INTENT(in) :: Ord\nREAL(KIND = idp), INTENT(in) :: x\nREAL(KIND = idp), INTENT(inout), DIMENSION(0:Ord) :: xlocs\n\n\n\nINTEGER :: i, j, k, l\nREAL(KIND = idp), DIMENSION(0:Ord) :: tmp,tmp2\nREAL(KIND = idp), DIMENSION(0:Ord) :: Lagrange_Second_Deriv\n\n\n\n\n\nIF (Ord == 1) THEN\n\n LAGRANGE_SECOND_DERIV = 0.0_idp\n\n\nELSE\n\n\n\n tmp(:) = 1.0_idp\n tmp2(:) = 0.0_idp\n\n DO i = 0,Ord\n\n DO k = 0,Ord\n\n IF (k .NE. i) THEN\n\n\n DO l = 0,Ord\n\n IF (l .NE. i .AND. l .NE. k) THEN\n\n tmp(i) = (1/(xlocs(i) - xlocs(k)))*(1/(xlocs(i) - xlocs(l)))\n\n !print*,\"tmp A \",i, k, l, tmp(i)\n\n DO j = 0,Ord\n\n IF (j .NE. i .AND. j .NE. k .AND. j .NE. l) THEN\n\n tmp(i) = tmp(i) * (x - xlocs(j))/(xlocs(i) - xlocs(j))\n !print*,\"tmp B \",i, k, l, j, tmp(i)\n\n END IF\n\n END DO ! j Loop\n\n tmp2(i) = tmp2(i) + tmp(i)\n\n !print*,\"tmp A\",j, i, tmp2(i)\n\n END IF\n\n END DO ! l Loop\n\n END IF\n\n END DO ! k Loop\n\n END DO ! i Loop\n\n\n\n Lagrange_Second_Deriv = tmp2\n\n\nEND IF\n\nEND FUNCTION Lagrange_Second_Deriv\n\n\n\n\n\n !+104+################################################################!\n! !\n! Legendre_Poly - Calculates the value of the Legendre Polynomial !\n! P^m_l(cos(theta)) !\n! !\n !#####################################################################!\nFUNCTION Legendre_Poly(l,m,num_points,theta)\n\n\n! Returns array that conatins the values P^m_n(cos(theta)) for n = 0:l\n! If m > n then returns 0 as the poly doesn't exist there.\n\nINTEGER, INTENT(IN) :: l,m, num_points\nREAL(KIND = idp), INTENT(IN), DIMENSION(1:num_points) :: theta\nREAL(KIND = idp), DIMENSION(1:num_points) :: Legendre_Poly, Legendre_Polyc\n\nINTEGER :: i,j,n\nREAL(KIND = idp) :: factor, normfactor\nREAL(KIND = idp), DIMENSION(1:num_points) :: costheta, sqrfactor\nREAL(KIND = idp), DIMENSION(0:l,1:num_points) :: Plm\n\n\nn = abs(m)\ncostheta = cos(theta)\nsqrfactor = sqrt(1.0_idp - costheta*costheta)\n\n\n\nPlm(:,:) = 0.0_idp\n\n\n\n\nIF (n <= l) THEN\n\n Plm(n,:) = 1.0_idp\n factor = 1.0_idp\n\n DO i = 1,n\n Plm(n,:) = -Plm(n,:)*factor*sqrfactor(:)\n factor = factor + 2.0_idp\n END DO\nEND IF\n\n\n\nIF (n + 1 <= l) THEN\n Plm(n+1,:) = costheta(:)*(2.0_idp*n + 1.0_idp) * Plm(n,:)\nEND IF\n\n\n\nDO i = n+2,l\n\n Plm(i,:) = ( ( 2*i - 1)*costheta(:)*Plm(i-1,:) + (-i - n +1)*Plm(i-2,:) )/(i - n)\n\nEND DO\n\n\n\n\n\n\n\n\nIf (m < 0) THEN\n normfactor = ((-1)**n)*(1.0_idp*Factorial(l-n))/(1.0_idp*Factorial(l+n))\n\n Legendre_Poly(:) = normfactor*Plm(l,:)\nELSE\n Legendre_Poly(:) = Plm(l,:)\nEND IF\n\n\n\n\nEND FUNCTION Legendre_Poly\n\n\n\n\n\n\n\n\n\n\n !+105+################################################################!\n! !\n! Spherical_Harmonic - Calculates the value of the spherical harmonic,!\n! Y^M_L(Theta, Phi). Uses Legendre_Poly !\n! !\n! Output - 2L Value array - (Real, Imaginary) !\n! !\n !#####################################################################!\nFUNCTION Spherical_Harmonic(l,m,theta,phi)\n\n\n\n\nINTEGER, INTENT(IN) :: l,m\nREAL(KIND = idp), INTENT(IN) :: theta, phi\n\n\nINTEGER :: abs_m\nREAL(KIND = idp), DIMENSION(0:0) :: Plm\nCOMPLEX(KIND = idp) :: Spherical_Harmonic\n\n\nPlm = Legendre_Poly(l,m,1,[theta])\n\n\nSpherical_Harmonic = Norm_Factor(l,m)*Plm(0)*EXP(COMPLEX(0,m*phi))\n\n\nEND FUNCTION Spherical_Harmonic\n\n\n\n\n\n\n\n\n !+201+####################################################!\n! !\n! Norm_Factor - Calculate normalization factor for !\n! spherical harmonics !\n! !\n !#########################################################!\nFUNCTION Norm_Factor(l,m)\n\nINTEGER, INTENT(IN) :: l,m\nREAL(KIND = idp) :: Norm_Factor\n\n\n!Norm_Factor = 1.0_idp\nNorm_Factor = sqrt( ( ( 2.0_idp * l + 1.0_idp) * Factorial(l - m))/( 4.0_idp * pi * Factorial(l + m)))\n!Norm_Factor = sqrt( (( 2.0_idp * l + 1.0_idp)/( 4.0_idp * pi)) * Factorial_Division(l - m, l + m) )\n\n\n\n\n\nEND FUNCTION Norm_Factor\n\n\n\n\n\n\n !+202+################################################################!\n! !\n! Factorial - Calulcates N!, for use in Legendre_Poly !\n! !\n !#####################################################################!\nPURE REAL(KIND = idp) FUNCTION Factorial(n)\n\nINTEGER, INTENT(IN) :: n\n\n\nINTEGER :: i\nREAL(KIND = idp) :: fact\n\n\nfact = 1\nDO i = 2,n\n fact = fact*i\nEND DO\n\n\n\n\nFactorial = fact\n\n\nEND FUNCTION Factorial\n\n\n\n\n\n\n\n !+203+################################################################!\n! !\n! Factorial_Division - Calulcates M!/N!, for use in Legendre_Poly !\n! !\n !#####################################################################!\nREAL(KIND = idp) FUNCTION Factorial_Division(M,N)\n\nINTEGER, INTENT(IN) :: N,M\n\n\nINTEGER :: i\nREAL(KIND = idp) :: fact\n\n\n\nIF (M .GE. N) THEN\n\n fact = N\n DO i = N+1,M\n fact = fact*i\n END DO\n\n IF (fact .EQ. 0) THEN\n fact = 1\n END IF\n\nEND IF\n\n\nIF (M < N) THEN\n\n fact = M\n\n IF (fact .EQ. 0) THEN\n fact = 1\n END IF\n\n DO i = M+1, N\n fact = fact*i\n END DO\n\n\n\n\n fact = 1/fact\n\nEND IF\n\nFactorial_Division = fact\n\n\nEND FUNCTION Factorial_Division\n\n\n\n\n\n\n\n\n\n\n !+204+################################################################!\n! !\n! POWER - Simple x**y function for testing code, TEST_LGL !\n! !\n !#####################################################################!\nPURE ELEMENTAL FUNCTION POWER(x,y)\n\nINTEGER, INTENT(IN) :: y\nREAL(KIND = idp), INTENT(IN) :: x\n\nINTEGER :: i\nREAL(KIND = idp) :: tmp\nREAL(KIND = idp) :: POWER\n\ntmp = 1.0_idp\n\n\nIF (y < 0) THEN\n\n DO i = 1,abs(y)\n\n tmp = tmp/x\n\n END DO\n\nELSE\n\n DO i = 1,y\n tmp = tmp*x\n END DO\n\nEND IF\n\nPOWER = tmp\n\nEND FUNCTION POWER\n\n\n\n\n\n\n\n\n\n\n\n!+301+##################################################!\n! !\n! Map_To_X_Space - maps r value between ra, and rb to x !\n! space such that x in [-1,1]. !\n! !\n!#######################################################!\nPURE ELEMENTAL FUNCTION Map_To_X_Space(ra, rb, r)\n\nREAL(KIND = idp) :: Map_To_X_Space\nREAL(KIND = idp), intent(in) :: ra, rb\nREAL(KIND = idp), intent(in) :: r\n\nMap_To_X_Space = (2.0_idp*(r - ra))/(rb - ra) - 1.0_idp\n\n\nEND FUNCTION Map_To_X_Space\n\n\n\n\n\n\n\n!+302+##################################################!\n! !\n! Map_From_X_Space - maps x value between -1, and 1 to r !\n! space such that r in [ra,rb]. !\n! !\n!#######################################################!\nPURE ELEMENTAL FUNCTION Map_From_X_Space(a, b, x)\n\nREAL(KIND = idp) :: Map_From_X_Space\nREAL(KIND = idp), intent(in) :: a, b\nREAL(KIND = idp), intent(in) :: x\n\nMap_From_X_Space = ((b - a)* (x+1.0_idp))/2.0_idp + a\n\n\nEND FUNCTION Map_From_X_Space\n\n\n\n\n\n\n\n\n\n!+401+############################################################!\n!\n! MVMULT_CCS: Multiply a vector by a matrix in CCS format\n!\n!#################################################################!\nFUNCTION MVMULT_CCS(N, NNZ, ELEM_VAL, COL_PTR, ROW_IND, VECT)\n\n\nINTEGER, INTENT(IN) :: N, NNZ\nINTEGER, DIMENSION(0:N), INTENT(IN) :: COL_PTR\nINTEGER, DIMENSION(0:NNZ - 1),INTENT(IN) :: ROW_IND\n\nREAL(KIND = idp), DIMENSION(0:NNZ - 1), INTENT(IN) :: ELEM_VAL\nREAL(KIND = idp), DIMENSION(0:N-1), INTENT(IN) :: VECT\n\n\nREAL(KIND = idp), DIMENSION(0:N-1) :: MVMULT_CCS\n\nINTEGER :: i, j\n\nMVMULT_CCS = 0.0_idp\n\nDO i = 0,N-1\n\n\n DO j = COL_PTR(i),COL_PTR(i+1)-1\n\n MVMULT_CCS(ROW_IND(j)) = MVMULT_CCS(ROW_IND(j)) + ELEM_VAL(j)*VECT(i)\n\n END DO\n\n\nEND DO\n\n\n\nEND FUNCTION MVMULT_CCS\n\n\n\n\n!+402+############################################################!\n!\n! MVMULT_FULL: Multiply a vector by a matrix in CCS format\n!\n!#################################################################!\nPURE FUNCTION MVMULT_FULL(A, V, N, M)\n\n\nINTEGER, INTENT(IN) :: N, M\nREAL(KIND = idp), INTENT(IN), DIMENSION(1:M) :: V\nREAL(KIND = idp), INTENT(IN), DIMENSION(1:N,1:M) :: A\n\n\nREAL(KIND = idp), DIMENSION(1:N) :: MVMULT_FULL\n\n\nREAL(KIND = idp), DIMENSION(1:N) :: Sol\n\nINTEGER :: i,j\n\n\n\nDo i = 1,N\n\n Sol(i) = 0.D0\n\n Do j = 1,M\n\n Sol(i) = Sol(i) + A(i,j)*V(j)\n\n END DO\n\nEND DO\n\nMVMULT_FULL = Sol\n\nEND FUNCTION MVMULT_FULL\n\n\n\n\n\n\n\n\n\n\n!+403+############################################!\n!\n! SVVAD - Scaled Vector-Vector Addition\n! A = alpha*A + B\n!\n!################################################!\nFUNCTION SVVADD(N, alpha, A, B )\n\nINTEGER, INTENT(IN) :: N\nREAL(KIND = idp), INTENT(IN) :: alpha\n\nREAL(KIND = idp), DIMENSION(0:N-1), INTENT(IN) :: B\nREAL(KIND = idp), DIMENSION(0:N-1), INTENT(IN) :: A\n\nREAL(KIND = idp), DIMENSION(0:N-1) :: SVVADD\n\nINTEGER :: i\n\nDO i = 0,N-1\n\n SVVADD(i) = alpha*A(i) + B(i)\n\nEND DO\n\n\nEND FUNCTION SVVADD\n\n\n\n\n\n\n\n\n\n\n\n\n\n !+501+####################################################################!\n! !\n! Initialize_LGL_Quadrature - Calculate the Legendre-Gauss-Lobatto !\n! Quadrature node locations and weights. !\n! !\n !#########################################################################!\nSUBROUTINE Initialize_LGL_Quadrature(Ord, xloc, weights)\n\n\nINTEGER, INTENT(IN) :: Ord\nREAL(KIND = idp), INTENT(INOUT), DIMENSION(0:Ord) :: xloc, weights\n\n\nINTEGER :: i, j, Op1\nREAL(KIND = idp), DIMENSION(0:Ord) :: xtmp, xlast\nREAL(KIND = idp), DIMENSION(0:Ord,0:Ord) :: VanderM\n\n\n\nOp1 = Ord +1\n\n!! Set Initial Guess at x locations !!\nDO i = 0,Ord\n xtmp(i) = cos(i*pi/Ord)\nEND DO\n\n\n!! Initialize VanderM and xlast !!\nVanderM(:,:) = 0.0_idp\nxlast(:) = 42\n\n!! Loop until converged on machine precision !!\nDO WHILE (MAXVAL(ABS(xtmp(:) - xlast(:))) > eps)\n\n !! Set xlast to newest versions of xtmp !!\n xlast(:) = xtmp(:)\n\n\n VanderM(:,0) = 1\n VanderM(:,1) = xtmp(:)\n\n !! Calculate Elements of Vandermonde Matrix for Legendre Polynomials !!\n DO i = 1,Ord-1\n VanderM(:,i+1) = ((2*(i+1)-1)*xtmp(:)*VanderM(:,i) - (i)*VanderM(:,i-1))/(i+1)\n END DO\n\n !! Update xtmp using derivative of Legendre Polynomials !!\n xtmp(:) = xlast(:) - ( xtmp(:)*VanderM(:,Ord) - VanderM(:,Ord-1) )/(Op1 * VanderM(:,Ord))\n\n\nEND DO\n\n\nDO i = 0,Ord\n xloc(i) = xtmp(Ord-i)\n weights(i) = 2/(Ord*Op1 * VanderM(Ord-i,Ord)*VanderM(Ord-i,Ord))\nEND DO\n\n\n\n\n\nEND SUBROUTINE Initialize_LGL_Quadrature\n\n\n\n\n\n !+502+########################################################################!\n! !\n! Initialize_LGL_Quadrature_Locations - Calculates the Legendre-Gauss-Lobatto !\n! Quadrature node locations. Does not calculate the weights !\n! needed for integration, use \"Initialize_LGL_Quadrature\", +501+, !\n! for locations and weights. !\n! !\n !#############################################################################!\nPURE FUNCTION Initialize_LGL_Quadrature_Locations(Ord)\n\n\nINTEGER, INTENT(IN) :: Ord\nREAL(KIND = idp), DIMENSION(0:Ord) :: Initialize_LGL_Quadrature_Locations\n\n\nINTEGER :: i, j, Op1\nREAL(KIND = idp), DIMENSION(0:Ord) :: xtmp, xlast\nREAL(KIND = idp), DIMENSION(0:Ord,0:Ord) :: VanderM\n\n\n\nOp1 = Ord +1\n\n!! Set Initial Guess at x locations !!\nDO i = 0,Ord\n xtmp(i) = cos(i*pi/Ord)\nEND DO\n\n\n!! Initialize VanderM and xlast !!\nVanderM(:,:) = 0.0_idp\nxlast(:) = 42\n\n!! Loop until converged on machine precision !!\nDO WHILE (MAXVAL(ABS(xtmp(:) - xlast(:))) > eps)\n\n !! Set xlast to newest versions of xtmp !!\n xlast(:) = xtmp(:)\n\n\n VanderM(:,0) = 1\n VanderM(:,1) = xtmp(:)\n\n !! Calculate Elements of Vandermonde Matrix for Legendre Polynomials !!\n DO i = 1,Ord-1\n VanderM(:,i+1) = ((2*(i+1)-1)*xtmp(:)*VanderM(:,i) - (i)*VanderM(:,i-1))/(i+1)\n END DO\n\n !! Update xtmp using derivative of Legendre Polynomials !!\n xtmp(:) = xlast(:) - ( xtmp(:)*VanderM(:,Ord) - VanderM(:,Ord-1) )/(Op1 * VanderM(:,Ord))\n\n\nEND DO\n\n\nDO i = 0,Ord\n Initialize_LGL_Quadrature_Locations(i) = xtmp(Ord-i)\nEND DO\n\n\n\n\n\nEND FUNCTION Initialize_LGL_Quadrature_Locations\n\n\n\n\n!+503+##################################################################!\n! !\n! Initialize_LG_Quadrature - Calculate the Legendre-Gauss Quadrature !\n! node locations and weights. !\n! !\n!#######################################################################!\nSUBROUTINE Initialize_LG_Quadrature(Ord, xloc, weights)\n\nINTEGER, INTENT(IN) :: Ord\nREAL(KIND = idp), INTENT(INOUT), DIMENSION(1:Ord) :: xloc, weights\n\nINTEGER :: i, j, m\nREAL(KIND = idp) :: p1, p2, p3, pp, z, z1\n\n\nm = (Ord + 1)/2\n\nDO i = 1,m\n\n z = cos(pi * (i-0.25_idp)/(Ord + 0.5_idp))\n z1 = 42.0_idp\n\n DO WHILE ( ABS(z - z1) .GT. eps)\n p1 = 1.0_idp\n p2 = 0.0_idp\n\n DO j = 1, Ord\n\n p3 = p2\n p2 = p1\n p1 = ((2.0_idp*j - 1.0_idp)*z*p2 - (j - 1.0_idp)*p3)/j\n\n END DO\n\n\n pp = Ord*(z*p1 - p2)/(z*z-1.0_idp)\n z1 = z\n z = z1 - p1/pp\n\n\n END DO\n\n xloc(i) = -z\n xloc(Ord-i+1) = +z\n\n weights(i) = 2.0_idp/((1.0_idp - z*z)*pp*pp)\n weights(Ord-i+1) = weights(i)\n\nEND DO\n\n!PRINT*,\"!!!!!!!!!!!!!!!\"\n!PRINT*,xloc\n!PRINT*,\" \"\n!PRINT*,weights\n!PRINT*,\"!!!!!!!!!!!!!!!\"\n\n\nEND SUBROUTINE Initialize_LG_Quadrature\n\n\n\n\n\n !+504+########################################################################!\n! !\n! Initialize_LG_Quadrature_Locations - Calculates the Legendre-Gauss !\n! Quadrature node locations. Does not calculate the weights !\n! needed for integration, use \"Initialize_LG_Quadrature\", +503+, !\n! for locations and weights. !\n! !\n !#############################################################################!\nPURE FUNCTION Initialize_LG_Quadrature_Locations(Ord)\n\nINTEGER, INTENT(IN) :: Ord\n\n\nREAL(KIND = idp), DIMENSION(1:Ord) :: Initialize_LG_Quadrature_Locations\n\nINTEGER :: i, j, m\nREAL(KIND = idp) :: p1, p2, p3, pp, z, z1\n\n\nm = (Ord + 1)/2\n\nDO i = 1,m\n\n z = cos(pi * (i-0.25_idp)/(Ord + 0.5_idp))\n z1 = 42.0_idp\n\n DO WHILE ( ABS(z - z1) .GT. eps)\n p1 = 1.0_idp\n p2 = 0.0_idp\n\n DO j = 1, Ord\n\n p3 = p2\n p2 = p1\n p1 = ((2.0_idp*j - 1.0_idp)*z*p2 - (j - 1.0_idp)*p3)/j\n\n END DO\n\n\n pp = Ord*(z*p1 - p2)/(z*z-1.0_idp)\n z1 = z\n z = z1 - p1/pp\n\n\n END DO\n\n Initialize_LG_Quadrature_Locations(i) = -z\n Initialize_LG_Quadrature_Locations(Ord-i+1) = +z\n\n\nEND DO\n\n!PRINT*,\"!!!!!!!!!!!!!!!\"\n!PRINT*,xloc\n!PRINT*,\" \"\n!PRINT*,weights\n!PRINT*,\"!!!!!!!!!!!!!!!\"\n\n\nEND FUNCTION Initialize_LG_Quadrature_Locations\n\n\n\n\n\n\n\n\n\n!+601+####################################################################!\n! !\n! SphericalHarmonic_OrthogonalityTest - Shows Orthogonality of Spherical !\n! Harmonic Functions !\n! !\n !#########################################################################!\nSUBROUTINE SphericalHarmonic_OrthogonalityTest(L_LIMIT, L_SPECIFIC, M_SPECIFIC)\n\n\n!REAL(KIND = idp) :: BC_Integralb\n!COMPLEX(KIND = idp) :: SphereHarmonic_OrthogTest\n\n\n\nINTEGER, INTENT(IN) :: L_LIMIT, L_SPECIFIC, M_SPECIFIC\n\n\nINTEGER :: l, m\nINTEGER :: te, td, pe, pd\n\n\nINTEGER :: T_Degree, P_Degree\n\nINTEGER :: T_SUB_ELEMENTS, P_SUB_ELEMENTS\n\n\nREAL(KIND = idp), ALLOCATABLE, DIMENSION(:) :: P_xlocs, P_locs, P_weights, &\n T_xlocs, T_locs, T_weights, &\n Sub_tlocs, Sub_plocs\n\nREAL(KIND = idp) :: deltasubt, deltasubp, deltat, deltap\n\n\nCOMPLEX(KIND = idp) :: TMP_VALUE\n\n\nT_SUB_ELEMENTS = 32\nP_SUB_ELEMENTS = 32\n\nT_Degree = 5\nP_Degree = 5\n\n\n\n\nALLOCATE(P_xlocs(0:P_Degree), P_locs(0:P_Degree), P_weights(0:P_Degree))\nALLOCATE(T_xlocs(0:T_Degree), T_locs(0:T_Degree), T_weights(0:T_Degree))\nALLOCATE(Sub_tlocs(0:T_SUB_ELEMENTS),Sub_plocs(0:P_SUB_ELEMENTS))\n\nCALL Initialize_LGL_Quadrature(P_Degree, P_xlocs, P_weights)\nCALL Initialize_LGL_Quadrature(T_Degree, T_xlocs, T_weights)\n\ndeltasubt = (pi)/REAL(T_SUB_ELEMENTS)\ndeltasubp = (2*pi)/REAL(P_SUB_ELEMENTS)\n\nDO te = 0, T_SUB_ELEMENTS\n Sub_tlocs(te) = 0.0_idp + te*deltasubt\nEND DO\n\nDO pe = 0,P_SUB_ELEMENTS\n Sub_plocs(pe) = 0.0_idp + pe*deltasubp\nEND DO\n\n\n\n\nPRINT*,\"L_SPECIFIC, l, M_SPECIFIC, m, Integral Value\"\nDO l = 0,L_LIMIT\n DO m = -l,l\n\n TMP_VALUE = 0.0_idp\n\n DO te = 0, T_SUB_ELEMENTS - 1\n\n T_locs = Map_From_X_Space(Sub_tlocs(te), Sub_tlocs(te+1), T_xlocs)\n deltat = Sub_tlocs(te+1)-Sub_tlocs(te)\n\n DO pe = 0, P_SUB_ELEMENTS - 1\n\n P_locs = Map_From_X_Space(Sub_plocs(pe), Sub_plocs(pe+1), P_xlocs)\n deltap = Sub_plocs(pe+1) - Sub_plocs(pe)\n\n DO td = 0, T_Degree\n\n DO pd = 0, P_Degree\n\n TMP_VALUE = TMP_VALUE + T_weights(td)*P_weights(pd) &\n * Spherical_Harmonic(L_SPECIFIC, M_SPECIFIC, T_locs(td), P_locs(pd)) & ! Ylm\n * POWER(-1.0_idp, M)*Spherical_Harmonic(L, -M, T_locs(td), P_locs(pd)) & ! Ylm* = (-1)^m Yl-m\n * sin(T_locs(td)) &\n * deltat/2.0_idp*deltap/2.0_idp\n\n\n END DO\n END DO\n END DO\n END DO\n\n PRINT*, L_SPECIFIC, l, M_SPECIFIC, m, TMP_VALUE\n\n\n END DO\nEND DO\n\n\n\n\n\n\nEND SUBROUTINE SphericalHarmonic_OrthogonalityTest\n\n\n\n\n\n\n\n\n\nEND MODULE Additional_Functions_Module", "meta": {"hexsha": "1aff0be745f4f7f766281883926ffd4d6b8dffcb", "size": 29073, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Code/Newton/z.Additional_Functions_Module.f90", "max_stars_repo_name": "jrober50/Poseidon_Newton", "max_stars_repo_head_hexsha": "9b3dc4d986055185da817e40c7a612e9f899b82a", "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": "Code/Newton/z.Additional_Functions_Module.f90", "max_issues_repo_name": "jrober50/Poseidon_Newton", "max_issues_repo_head_hexsha": "9b3dc4d986055185da817e40c7a612e9f899b82a", "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": "Code/Newton/z.Additional_Functions_Module.f90", "max_forks_repo_name": "jrober50/Poseidon_Newton", "max_forks_repo_head_hexsha": "9b3dc4d986055185da817e40c7a612e9f899b82a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.4059945504, "max_line_length": 142, "alphanum_fraction": 0.3590616723, "num_tokens": 6789, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936878, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.6912908621915281}} {"text": "MODULE matrix_maintenance\nIMPLICIT NONE\nINTEGER, PARAMETER :: COL_WIDTH = 8\n\nCONTAINS\n SUBROUTINE LOAD_MATRIX(filename, arr, r, c, fmt)\n IMPLICIT NONE\n CHARACTER(*), INTENT(IN) :: filename\n REAL, DIMENSION(:,:), ALLOCATABLE, INTENT(OUT) :: arr\n INTEGER, INTENT(OUT) :: r, c\n CHARACTER(*) :: fmt\n INTEGER :: i, j, status\n CHARACTER(LEN=800) :: line\n CHARACTER(LEN=3) :: col_str\n\n OPEN (1, FILE=filename, STATUS='OLD', ACTION='READ')\n DO\n READ(1, '(A)', IOSTAT=status) line\n IF (status .lt. 0) THEN\n EXIT\n ELSE\n r = r + 1\n END IF\n END DO\n c = LEN_TRIM(line) / COL_WIDTH\n\n ! Convert the integer c to a string\n WRITE(col_str, '(I3)') c\n col_str = TRIM(col_str)\n fmt = '(' // col_str // 'F8.1)'\n\n ALLOCATE(arr(1:r, 1:c))\n REWIND(1)\n READ(1, fmt) ((arr(i, j), j=1, c), i=1, r)\n END SUBROUTINE LOAD_MATRIX\nEND MODULE matrix_maintenance\n\nPROGRAM matrix_mult\nUSE matrix_maintenance\nIMPLICIT NONE\n\nREAL, ALLOCATABLE, DIMENSION(:,:) :: matrixA, matrixB, matrixC\nREAL :: temp\nINTEGER :: i, j, k, l, colsA, rowsA, colsB, rowsB\nCHARACTER(LEN=9) :: col_fmtA, col_fmtB\n\nrowsA = 0\ncolsA = 0\nCALL LOAD_MATRIX(\"matrixA.dat\", matrixA, rowsA, colsA, col_fmtA)\nWRITE(*, *) \"MATRIX A:\"\nWRITE(*, col_fmtA) ((matrixA(i, j), j=1, colsA), i=1, rowsA)\n\nrowsB = 0\ncolsB = 0\nCALL LOAD_MATRIX(\"matrixB.dat\", matrixB, rowsB, colsB, col_fmtB)\nWRITE(*, *) \"MATRIX B:\"\nWRITE(*, col_fmtB) ((matrixB(i, j), j=1, colsB), i=1, rowsB)\n\nIF (colsA .eq. rowsB) THEN\n ! Call matrix multiplication function.\n ALLOCATE(matrixC(1:rowsA, 1:colsB))\n DO i = 1, rowsA\n DO j = 1, colsB\n temp = 0\n DO k = 1, colsA\n temp = temp + matrixA(i, k) * matrixB(k, j)\n END DO\n matrixC(i, j) = temp\n END DO\n END DO\nEND IF\n\nWRITE(*, *) \"MATRIX C:\"\nWRITE(*, '(3F14.3)') ((matrixC(i, j), j = 1, colsB), i = 1, rowsA)\nmatrixC = 0.\nWRITE(*, *) \"MATRIX C:\"\nWRITE(*, '(3F14.3)') ((matrixC(i, j), j = 1, colsB), i = 1, rowsA)\nmatrixC = MATMUL(matrixA, matrixB)\nWRITE(*, *) \"MATRIX C:\"\nWRITE(*, '(3F14.3)') ((matrixC(i, j), j = 1, colsB), i = 1, rowsA)\n\nCLOSE(1)\nEND PROGRAM matrix_mult\n", "meta": {"hexsha": "ab4304f59d3d70467021b58fe0a9128cd6174062", "size": 2095, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap8/matrix_mult.f90", "max_stars_repo_name": "evanmacbride/fortran-practice", "max_stars_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/chap8/matrix_mult.f90", "max_issues_repo_name": "evanmacbride/fortran-practice", "max_issues_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/chap8/matrix_mult.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": 24.9404761905, "max_line_length": 66, "alphanum_fraction": 0.6186157518, "num_tokens": 793, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267762381843, "lm_q2_score": 0.7956581097540519, "lm_q1q2_score": 0.6912890704853804}} {"text": "PROGRAM F047\n\n ! Copyright 2021 Melwyn Francis Carlo\n ! FILE REFERENCE: http://www.naturalnumbers.org/primes.html\n\n IMPLICIT NONE\n\n INTEGER, PARAMETER :: MAX_N = 5E5\n\n INTEGER :: PRIME_NUM\n CHARACTER (LEN=50), PARAMETER :: FILENAME = \"problems/003/PrimeNumbers_Upto_1000000\"\n\n INTEGER :: I = 1\n INTEGER :: MAIN_COUNT = 0\n\n INTEGER, DIMENSION(INT(MAX_N/10)) :: PRIMES_LIST = 0\n\n INTEGER :: J, TEMP_I, I_BY_5, SUB_COUNT\n\n OPEN (2, FILE = FILENAME, STATUS = 'OLD')\n\n DO\n READ(2, *, END=10) PRIME_NUM\n IF (PRIME_NUM > MAX_N) EXIT\n PRIMES_LIST(I) = PRIME_NUM\n I = I + 1\n END DO\n\n 10 CLOSE(2)\n\n DO I = 1000, MAX_N\n\n J = 1\n TEMP_I = I\n I_BY_5 = INT(I / 5)\n SUB_COUNT = 0\n\n DO WHILE (PRIMES_LIST(J) < I_BY_5)\n\n IF (MOD(TEMP_I, PRIMES_LIST(J)) /= 0) THEN\n J = J + 1\n CYCLE\n END IF\n\n DO WHILE (MOD(TEMP_I, PRIMES_LIST(J)) == 0)\n TEMP_I = TEMP_I / PRIMES_LIST(J)\n END DO\n\n SUB_COUNT = SUB_COUNT + 1\n\n IF (SUB_COUNT == 4) EXIT\n\n J = J + 1\n\n END DO\n\n IF (SUB_COUNT /= 4) THEN\n MAIN_COUNT = 0\n CYCLE\n END IF\n\n MAIN_COUNT = MAIN_COUNT + 1\n\n IF (MAIN_COUNT == 4) EXIT\n\n END DO\n\n PRINT ('(I0)'), I - 3\n\nEND PROGRAM F047\n", "meta": {"hexsha": "26956714d170a355e837759ab7bf07ac1a1fae67", "size": 1417, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "problems/047/047.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/047/047.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/047/047.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": 19.9577464789, "max_line_length": 88, "alphanum_fraction": 0.5067043049, "num_tokens": 448, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.868826769445233, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.6912890524509463}} {"text": "FUNCTION SETSTVEL(D,SSG)\n\n ! ** NONCOHEASIVE SEDIMENT SETTLING AND SHIELDS CRITERIA\n ! ** USING VAN RIJN'S EQUATIONS\n\n ! CHANGE RECORD\n\n IMPLICIT NONE\n\n REAL :: SETSTVEL,D,SSG,VISC,GP,GPD,SQGPD,RD,WSET,TMP\n\n VISC=1.D-6\n GP=(SSG-1.)*9.82\n GPD=GP*D\n SQGPD=SQRT(GPD)\n RD=SQGPD*D/VISC\n\n ! ** SETTLING VELOCITY\n\n IF( D < 1.0E-4 )THEN\n WSET=SQGPD*RD/18.\n ENDIF\n IF( D >= 1.0E-4 .AND. D < 1.E-3 )THEN\n TMP=SQRT(1.+0.01*RD*RD)-1.\n WSET=10.0*SQGPD*TMP/RD\n ENDIF\n IF( D >= 1.E-3 )THEN\n WSET=1.1*SQGPD\n ENDIF\n SETSTVEL=WSET\n\nEND FUNCTION\n\n", "meta": {"hexsha": "483b06d6d7c8b25b66978c1bec469caf220dbf39", "size": 561, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "EFDC/setstvel.f90", "max_stars_repo_name": "dsi-llc/EFDCPlus", "max_stars_repo_head_hexsha": "27ece1cd0bb9e02a46d1ad20f343bc5d109acfb3", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 35, "max_stars_repo_stars_event_min_datetime": "2019-09-11T23:39:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T08:14:29.000Z", "max_issues_repo_path": "EFDC/setstvel.f90", "max_issues_repo_name": "dsi-llc/EFDCPlus8.5", "max_issues_repo_head_hexsha": "27ece1cd0bb9e02a46d1ad20f343bc5d109acfb3", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-08-06T01:59:24.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-25T01:46:32.000Z", "max_forks_repo_path": "EFDC/setstvel.f90", "max_forks_repo_name": "dsi-llc/EFDCPlus", "max_forks_repo_head_hexsha": "27ece1cd0bb9e02a46d1ad20f343bc5d109acfb3", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 22, "max_forks_repo_forks_event_min_datetime": "2020-03-06T06:34:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-02T04:15:55.000Z", "avg_line_length": 16.5, "max_line_length": 59, "alphanum_fraction": 0.6185383244, "num_tokens": 274, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541626630937, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6912867138754744}} {"text": "MODULE NORM_MOD\n\n! The Norm Module contains the function Norm, which returns a random number \n! (deviate) drawn from a normal distribution with zero mean and unit \n! variance (i.e., standard deviation = 1).\n!\n! Created by: Elizabeth North\n! Modified by: Zachary Schlag\n! Created on: 22 Aug 2008\n! Last Modified on: Feb 2011\n\nIMPLICIT NONE\nPUBLIC\n\nCONTAINS\n\n! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n! ~~ ~~\n! ~~ FUNCTION norm ~~\n! ~~ ~~\n! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n DOUBLE PRECISION FUNCTION norm()\n ! This function returns a normally distributed deviate with \n ! zero mean and unit variance (i.e., standard deviation = 1). \n ! By E. North, 8/22/08\n USE PARAM_MOD, ONLY: PI\n USE RANDOM_MOD, ONLY: genrand_real3\n IMPLICIT NONE\n\n DOUBLE PRECISION :: dev1,dev2\n\n dev1 = genrand_real3()\n dev2 = genrand_real3()\n norm = sqrt(DBLE(-2.)*log(dev1)) * cos(DBLE(2.)*PI*dev2)\n\n END FUNCTION norm\n\nEND MODULE NORM_MOD", "meta": {"hexsha": "ab933d00f95487d1c8ff97cfd0b21cfa8cc8b643", "size": 1376, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Model6/norm_module.f90", "max_stars_repo_name": "CaptainYin/ParLTRANS", "max_stars_repo_head_hexsha": "760734f058589ab464897dcf01f3f5528803d43b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Model6/norm_module.f90", "max_issues_repo_name": "CaptainYin/ParLTRANS", "max_issues_repo_head_hexsha": "760734f058589ab464897dcf01f3f5528803d43b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Model6/norm_module.f90", "max_forks_repo_name": "CaptainYin/ParLTRANS", "max_forks_repo_head_hexsha": "760734f058589ab464897dcf01f3f5528803d43b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.5609756098, "max_line_length": 77, "alphanum_fraction": 0.4331395349, "num_tokens": 294, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037282594921, "lm_q2_score": 0.7461390043208003, "lm_q1q2_score": 0.6911513415021826}} {"text": "program main\n implicit none\n\n integer, parameter :: d = 1 ! Number of inputs\n integer, parameter :: k = 1 ! Number of outputs\n integer, parameter :: h = 8 ! Number of hidden nodes\n integer, parameter :: n = 64 ! Training data counts\n integer, parameter :: epochs = 1000 ! Iteration of training\n real(8), parameter :: learn_rate = 0.03\n\n type type_weights\n real(8) :: w1(h, d), w2(k, h), b1(h), b2(k)\n end type type_weights\n\n call training()\n\n contains\n\n subroutine training()\n ! Main subroutine\n integer :: itr, i\n real(8) :: train_x(d, n), train_y(k, n)\n real(8) :: loss, y(k), diff(k)\n type(type_weights) :: weights\n call get_initial_weights(weights)\n call get_training_data(train_x, train_y)\n do itr = 1, epochs\n loss = 0.0\n do i = 1, n ! Todo: shuffled order\n y = forward(train_x(:, i), weights)\n diff = y - train_y(:, i)\n loss = loss + sum(diff ** 2)\n call backward(train_x(:, i), weights, diff)\n end do\n print *, loss ! Decays to zero\n end do\n end subroutine training\n\n pure function activation(a)\n ! Hyperbolic tangent activation function\n real(8), intent(in) :: a(h)\n real(8) :: activation(h)\n activation = tanh(a)\n end function activation\n\n pure function activation_prime(a)\n ! Derivative of the activation function\n real(8), intent(in) :: a(h)\n real(8) :: activation_prime(h)\n activation_prime = cosh(a) ** (-2)\n end function activation_prime\n\n pure function forward(x, w)\n ! Forward evaluation of neural network\n real(8), intent(in) :: x(d)\n type(type_weights), intent(in) :: w\n real(8) :: forward(k)\n forward = matmul(w%w2, activation(matmul(w%w1, x) + w%b1)) + w%b2\n end function forward\n\n subroutine backward(x, w, diff)\n ! Calculate derivative of loss function in weight space and gradient descent\n real(8), intent(in) :: x(d), diff(k)\n type(type_weights), intent(inout) :: w\n real(8) :: v1(h), v2(h)\n v1 = matmul(diff, w%w2) * activation_prime(matmul(w%w1, x) + w%b1)\n v2 = activation(matmul(w%w1, x) + w%b1)\n w%w1 = w%w1 - learn_rate * matmul(reshape(v1, (/h, 1/)), reshape(x, (/1, d/)))\n w%b1 = w%b1 - learn_rate * v1\n w%w2 = w%w2 - learn_rate * matmul(reshape(diff, (/k, 1/)), reshape(v2, (/1, h/)))\n w%b2 = w%b2 - learn_rate * diff\n end subroutine backward\n\n subroutine get_training_data(train_x, train_y)\n ! Training data is y = 2 x^2 - 1\n real(8), intent(out) :: train_x(d, n), train_y(k, n)\n integer :: i\n if ((d /= 1) .or. (k /= 1)) then\n print *, \"Shape mismatch. Stop.\"\n stop 3\n end if\n do i = 1, n\n train_x(1, i) = -1.0 + (2.0 * i / n)\n train_y(1, i) = 2 * train_x(1, i) ** 2 - 1\n end do\n end subroutine get_training_data\n\n subroutine get_initial_weights(res)\n ! Randomly initialize weights\n type(type_weights), intent(out) :: res\n integer :: seed(100)\n seed(:) = 0\n call random_seed(put=seed)\n call random_number(res%w1)\n call random_number(res%w2)\n call random_number(res%b1)\n call random_number(res%b2)\n res%w1 = res%w1 - 0.5\n res%w2 = res%w2 - 0.5\n res%b1 = res%b1 - 0.5\n res%b2 = res%b2 - 0.5\n end subroutine get_initial_weights\nend program main\n\n", "meta": {"hexsha": "55e8178df62686afdf215049155db3e4a4c587b9", "size": 3238, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "main.f90", "max_stars_repo_name": "ysdtkm/neural_network_fortran", "max_stars_repo_head_hexsha": "0483a64d4828c326e90a00f59a22f5b1c22a3f5f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "main.f90", "max_issues_repo_name": "ysdtkm/neural_network_fortran", "max_issues_repo_head_hexsha": "0483a64d4828c326e90a00f59a22f5b1c22a3f5f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "main.f90", "max_forks_repo_name": "ysdtkm/neural_network_fortran", "max_forks_repo_head_hexsha": "0483a64d4828c326e90a00f59a22f5b1c22a3f5f", "max_forks_repo_licenses": ["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.8380952381, "max_line_length": 85, "alphanum_fraction": 0.6127239036, "num_tokens": 1053, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037302939515, "lm_q2_score": 0.7461389930307512, "lm_q1q2_score": 0.6911513325621574}} {"text": "!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 1998 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Spherepack *\n! * *\n! * A Package of Fortran Subroutines and Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams and Paul Swarztrauber *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\nsubmodule(scalar_laplacian_routines) scalar_laplacian_gaussian_grid\n\ncontains\n ! subroutine slapgc(nlat, nlon, isym, nt, slap, ids, jds, a, b, &\n ! mdab, ndab, wshsgc, ierror)\n !\n !\n ! given the scalar spherical harmonic coefficients a and b, precomputed\n ! by subroutine shagc for a scalar field sf, subroutine slapgc computes\n ! the laplacian of sf in the scalar array slap. slap(i, j) is the\n ! laplacian of sf at the gaussian colatitude theta(i) (see nlat as\n ! an input parameter) and east longitude lambda(j) = (j-1)*2*pi/nlon\n ! on the sphere. i.e.\n !\n ! slap(i, j) =\n !\n ! 2 2\n ! [1/sint*d (sf(i, j)/dlambda + d(sint*d(sf(i, j))/dtheta)/dtheta]/sint\n !\n !\n ! where sint = sin(theta(i)). the scalar laplacian in slap has the\n ! same symmetry or absence of symmetry about the equator as the scalar\n ! field sf. the input parameters isym, nt, mdab, ndab must have the\n ! same values used by shagc to compute a and b for sf. the associated\n ! legendre functions are stored rather than recomputed as they are\n ! in subroutine slapgc.\n !\n ! input parameters\n !\n ! nlat the number of points in the gaussian colatitude grid on the\n ! full sphere. these lie in the interval (0, pi) and are computed\n ! in radians in theta(1) <...< theta(nlat) by subroutine compute_gaussian_latitudes_and_weights.\n ! if nlat is odd the equator will be included as the grid point\n ! theta((nlat + 1)/2). if nlat is even the equator will be\n ! excluded as a grid point and will lie half way between\n ! theta(nlat/2) and theta(nlat/2+1). nlat must be at least 3.\n ! note: on the half sphere, the number of grid points in the\n ! colatitudinal direction is nlat/2 if nlat is even or\n ! (nlat + 1)/2 if nlat is odd.\n !\n ! nlon the number of distinct longitude points. nlon determines\n ! the grid increment in longitude as 2*pi/nlon. for example\n ! nlon = 72 for a five degree grid. nlon must be greater\n ! than zero. the axisymmetric case corresponds to nlon=1.\n ! the efficiency of the computation is improved when nlon\n ! is a product of small prime numbers.\n !\n ! isym this parameter should have the same value input to subroutine\n ! shagc to compute the coefficients a and b for the scalar field\n ! sf. isym is set as follows:\n !\n ! = 0 no symmetries exist in sf about the equator. scalar\n ! synthesis is used to compute slap on the entire sphere.\n ! i.e., in the array slap(i, j) for i=1, ..., nlat and\n ! j=1, ..., nlon.\n !\n ! = 1 sf and slap are antisymmetric about the equator. the\n ! synthesis used to compute slap is performed on the\n ! northern hemisphere only. if nlat is odd, slap(i, j) is\n ! computed for i=1, ..., (nlat + 1)/2 and j=1, ..., nlon. if\n ! nlat is even, slap(i, j) is computed for i=1, ..., nlat/2\n ! and j=1, ..., nlon.\n !\n !\n ! = 2 sf and slap are symmetric about the equator. the\n ! synthesis used to compute slap is performed on the\n ! northern hemisphere only. if nlat is odd, slap(i, j) is\n ! computed for i=1, ..., (nlat + 1)/2 and j=1, ..., nlon. if\n ! nlat is even, slap(i, j) is computed for i=1, ..., nlat/2\n ! and j=1, ..., nlon.\n !\n !\n ! nt the number of analyses. in the program that calls slapgc\n ! the arrays slap, a, and b can be three dimensional in which\n ! case multiple synthesis will be performed. the third index\n ! is the synthesis index which assumes the values k=1, ..., nt.\n ! for a single analysis set nt=1. the description of the\n ! remaining parameters is simplified by assuming that nt=1\n ! or that all the arrays are two dimensional.\n !\n ! ids the first dimension of the array slap as it appears in the\n ! program that calls slapgc. if isym = 0 then ids must be at\n ! least nlat. if isym > 0 and nlat is even then ids must be\n ! at least nlat/2. if isym > 0 and nlat is odd then ids must\n ! be at least (nlat + 1)/2.\n !\n ! jds the second dimension of the array slap as it appears in the\n ! program that calls slapgc. jds must be at least nlon.\n !\n !\n ! a, b two or three dimensional arrays (see input parameter nt)\n ! that contain scalar spherical harmonic coefficients\n ! of the scalar field sf as computed by subroutine shagc.\n ! *** a, b must be computed by shagc prior to calling slapgc.\n !\n !\n ! mdab the first dimension of the arrays a and b as it appears\n ! in the program that calls slapgc. mdab must be at\n ! least min(nlat, (nlon+2)/2) if nlon is even or at least\n ! min(nlat, (nlon + 1)/2) if nlon is odd.\n !\n ! ndab the second dimension of the arrays a and b as it appears\n ! in the program that calls slapgc. ndbc must be at least\n ! least nlat.\n !\n ! mdab, ndab should have the same values input to shagc to\n ! compute the coefficients a and b.\n !\n !\n ! wshsgc an array which must be initialized by subroutine shsgci.\n ! once initialized, wshsgc\n ! can be used repeatedly by slapgc as long as nlat and nlon\n ! remain unchanged. wshsgc must not be altered between calls\n ! of slapgc.\n !\n ! lshsgc the dimension of the array wshsgc as it appears in the\n ! program that calls slapgc. let\n !\n ! l1 = min(nlat, (nlon+2)/2) if nlon is even or\n ! l1 = min(nlat, (nlon + 1)/2) if nlon is odd\n !\n ! and\n !\n ! l2 = nlat/2 if nlat is even or\n ! l2 = (nlat + 1)/2 if nlat is odd\n !\n ! then lshsgc must be at least\n !\n ! nlat*(2*l2+3*l1-2)+3*l1*(1-l1)/2+nlon+15\n !\n ! output parameters\n !\n !\n ! slap a two or three dimensional arrays (see input parameter nt) that\n ! contain the scalar laplacian of the scalar field sf. slap(i, j)\n ! is the scalar laplacian at the gaussian colatitude theta(i)\n ! and longitude lambda(j) = (j-1)*2*pi/nlon for i=1, ..., nlat\n ! and j=1, ..., nlon.\n !\n !\n ! ierror a parameter which flags errors in input parameters as follows:\n !\n ! = 0 no errors detected\n !\n ! = 1 error in the specification of nlat\n ! = 2 error in the specification of nlon\n ! = 3 error in the specification of isym\n ! = 4 error in the specification of nt\n ! = 5 error in the specification of ids\n ! = 6 error in the specification of jds\n ! = 7 error in the specification of mdab\n ! = 8 error in the specification of ndab\n ! = 9 error in the specification of lshsgc\n !\n module subroutine slapgc(nlat, nlon, isym, nt, slap, ids, jds, a, b, &\n mdab, ndab, wshsgc, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n integer(ip), intent(in) :: isym\n integer(ip), intent(in) :: nt\n real(wp), intent(out) :: slap(ids, jds, nt)\n integer(ip), intent(in) :: ids\n integer(ip), intent(in) :: jds\n real(wp), intent(in) :: a(mdab, ndab, nt)\n real(wp), intent(in) :: b(mdab, ndab, nt)\n integer(ip), intent(in) :: mdab\n integer(ip), intent(in) :: ndab\n real(wp), intent(in) :: wshsgc(:)\n integer(ip), intent(out) :: ierror\n\n ! Local variables\n integer(ip) :: required_wavetable_size\n type(ScalarSynthesisUtility) :: util\n\n ! Check input arguments\n required_wavetable_size = util%get_lshsgc(nlat, nlon)\n\n call util%check_scalar_transform_inputs(isym, ids, jds, &\n mdab, ndab, nlat, nlon, nt, required_wavetable_size, &\n wshsgc, ierror)\n\n ! Check error flag\n if (ierror /= 0) return\n\n call scalar_laplacian_lower_utility_routine(nlat, nlon, isym, nt, slap, &\n a, b, wshsgc, shsgc, ierror)\n\n end subroutine slapgc\n\nend submodule scalar_laplacian_gaussian_grid\n", "meta": {"hexsha": "6180ad257005c3bf10bf45e115c0acd3916a9130", "size": 11099, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/scalar_laplacian_gaussian_grid.f90", "max_stars_repo_name": "jlokimlin/spherepack4.1", "max_stars_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-06-28T14:01:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T21:59:28.000Z", "max_issues_repo_path": "src/scalar_laplacian_gaussian_grid.f90", "max_issues_repo_name": "jlokimlin/spherepack4.1", "max_issues_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2016-05-07T23:00:35.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-22T23:52:30.000Z", "max_forks_repo_path": "src/scalar_laplacian_gaussian_grid.f90", "max_forks_repo_name": "jlokimlin/spherepack4.1", "max_forks_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-06-28T14:03:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T12:53:54.000Z", "avg_line_length": 49.5491071429, "max_line_length": 111, "alphanum_fraction": 0.4739165691, "num_tokens": 2781, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179043564153, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.6911408069129995}} {"text": "c=======================================================================\nc\nc subroutine PESBM\nc\nc Simulation of a Standard Brownian Motion \nc\nc dSt = mu*dt + sigma*dWt\nc\nc Method: Euler discretization of SDE\nc\nc S(1) = S\nc S(1+t) = S(t) + mu*dt + sigma*sqrt(dt)*N(0,1)\nc\nc with dt = T/(N-1) \nc\nc-----------------------------------------------------------------------\nc\nc INPUT :\nc T : time (days, months, years) integer\nc N : number of sub-division(s) integer \nc S : initial value double\nc mu : process drifts double\nc sigma : process volatility double\nc\nc OUTPUT :\nc y : generated process (N) double\nc info : diagnostic information integer\nc\nc-----------------------------------------------------------------------\nc\n SUBROUTINE pesbm ( T, N, S, mu, sigma, y, info )\nc\n IMPLICIT NONE\nc\nc arguments i/o\n INTEGER T, N, info\n DOUBLE PRECISION S, mu, sigma, y(*)\nc\nc local variables\n INTEGER i, M\n DOUBLE PRECISION dt\nc\nc external functions\n DOUBLE PRECISION rn \n EXTERNAL rn\nc\nc-----------------------------------------------------------------------\nc\nc initialization\n info = 0\nc\nc discetization step \n M = N - 1\n dt = (dfloat(T)/M)\nc\nc standard Brownian motion\n y(1) = S\n DO i = 1,M\n y(i + 1) = y(i) + mu*dt + sigma* SQRT(dt) * rn() \n ENDDO\nc\n RETURN\n END\n", "meta": {"hexsha": "be4098d5b86a3ea2a859779f62dba55073c54ffb", "size": 1722, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/rnd/process/pesbm.f", "max_stars_repo_name": "alpgodev/numx", "max_stars_repo_head_hexsha": "d2d3a0713020e1b83b65d3a661c3801ea256aff9", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-07-25T20:28:58.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-10T18:52:08.000Z", "max_issues_repo_path": "src/math/rnd/process/pesbm.f", "max_issues_repo_name": "alpgodev/numx", "max_issues_repo_head_hexsha": "d2d3a0713020e1b83b65d3a661c3801ea256aff9", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/math/rnd/process/pesbm.f", "max_forks_repo_name": "alpgodev/numx", "max_forks_repo_head_hexsha": "d2d3a0713020e1b83b65d3a661c3801ea256aff9", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.90625, "max_line_length": 73, "alphanum_fraction": 0.3803716609, "num_tokens": 416, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837705, "lm_q2_score": 0.7606506635289835, "lm_q1q2_score": 0.6911408024317612}} {"text": "!##############################################################################\n! MODULE globals\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!##############################################################################\nmodule globals\n\n implicit none\n\n ! model parameters\n real*8, parameter :: gamma = 0.50d0\n real*8, parameter :: beta = 0.96d0\n real*8, parameter :: alpha = 0.36d0\n real*8, parameter :: delta = 0.08d0\n real*8, parameter :: rho = 0.6d0\n real*8, parameter :: sigma_eps = 0.04d0*(1d0-rho**2)\n\n ! numerical parameters\n real*8, parameter :: a_l = 0d0\n real*8, parameter :: a_u = 100d0\n real*8, parameter :: a_grow = 0.01d0\n real*8, parameter :: sig_in = 1d-10\n real*8, parameter :: sig_out = 1d-6\n integer, parameter :: itermax = 50000\n\n ! macroeconomic variables\n real*8 :: r, w, KK, AA, LL, YY, CC, II\n\n ! the shock process\n integer, parameter :: NS = 7\n real*8 :: pi(NS, NS), eta(NS), weights(NS)\n\n ! policy and value function\n integer, parameter :: NA = 1000\n real*8 :: a(0:NA), c(0:NA, NS), V(0:NA, NS)\n\n ! variables to numerically determine policy function\n real*8 :: c_new(0:NA, NS), RHS(0:NA, NS)\n logical :: check\n\n ! variables to communicate with function\n real*8 :: a_com\n integer :: is_com\n\n ! simulated path of consumption and savings\n integer, parameter :: TT = 100000\n real*8 :: c_t(-5000:TT), a_t(-5000:TT), eta_t(-5000:TT)\n integer :: is_t(-5000:TT)\n\ncontains\n\n\n ! calculate the difference on the asset market given an interest rate\n function asset_market(r_input)\n\n implicit none\n real*8, intent(in) :: r_input\n real*8 :: asset_market\n\n ! set the interest rate\n r = r_input\n\n ! calculate the corresponding capital stock\n KK = (alpha/(r+delta))**(1d0/(1d0-alpha))*LL\n\n ! get wages and output\n w = (1d0-alpha)*(KK/LL)**alpha\n YY = KK**alpha*LL**(1d0-alpha)\n\n ! solve the household value function iteration problem\n call solve_household()\n\n ! simulate an asset and consumption path\n call simulate_path()\n\n ! get aggregate assets\n AA = sum(a_t(0:TT))/dble(TT+1)\n\n ! get the difference between asset demand and supply\n asset_market = (AA - KK)/AA\n\n write(*,'(2f10.4,f12.8)')KK/YY*100d0, r*100d0, AA-KK\n\n end function\n\n\n ! determines the solution to the household optimization problem\n subroutine solve_household()\n\n use toolbox\n\n implicit none\n integer :: ia, is, iter\n real*8 :: con_lev, x_in\n\n ! set tolerance level for interior optimization\n call settol_root(sig_in)\n\n ! do a policy function iteration with rootfinding\n do iter = 1, itermax\n\n ! interpolate coefficients\n call interpolate()\n\n ! solve the household problem for all gridpoints\n do ia = 0, NA\n do is = 1, NS\n\n ! initialize starting value and communication variables\n x_in = c(ia, is)\n a_com = a(ia)\n is_com = is\n\n ! find the optimal consumption level\n call fzero(x_in, foc, check)\n if(check)write(*,*)'ERROR IN ROOTFINDING PROCESS'\n\n ! check for borrowing constraint\n if(x_in > (1d0+r)*a_com+w*eta(is_com) - a_l) &\n x_in = (1d0+r)*a_com+w*eta(is_com) - a_l\n\n ! get optimal consumption and value function\n c_new(ia, is) = x_in\n\n enddo\n enddo\n\n ! get convergence level\n con_lev = maxval(abs(c_new(:, :) - c(:, :))/max(abs(c(:, :)), 1d-10))\n\n ! check for convergence\n if(con_lev < sig_in)then\n return\n endif\n\n c = c_new\n enddo\n\n write(*,*)'Policy Function Iteration did not converge'\n\n end subroutine\n\n\n ! the first order condition\n function foc(x_in)\n\n use toolbox\n\n implicit none\n real*8, intent(in) :: x_in\n real*8 :: foc, aplus, varphi\n integer :: ial, iar\n\n ! future assets\n aplus = (1d0+r)*a_com + w*eta(is_com) - x_in\n\n ! calculate future expected marginal utility\n call linint_Grow(aplus, a_l, a_u, a_grow, NA, ial, iar, varphi)\n foc = varphi*RHS(ial,is_com) + (1d0-varphi)*RHS(iar,is_com)\n\n ! get first order condition\n foc = x_in - foc\n\n end function\n\n\n ! Set up data for interpolation\n subroutine interpolate()\n\n implicit none\n integer :: is, ia, is_p\n\n do is = 1, NS\n do ia = 0, NA\n\n ! calculate the RHS of the first order condition\n RHS(ia, is) = 0d0\n do is_p = 1, NS\n RHS(ia, is) = RHS(ia, is) + pi(is, is_p)*c_new(ia, is_p)**(-1d0/gamma)\n enddo\n RHS(ia, is) = (beta*(1d0+r)*RHS(ia, is))**(-gamma)\n enddo\n\n enddo\n\n end subroutine\n\n\n ! simulates household path through time\n subroutine simulate_path()\n\n use toolbox\n\n implicit none\n integer :: it, ial, iar\n real*8 :: varphi\n\n ! initialize variables\n eta_t(-5000) = eta(is_t(-5000))\n a_t(-5000) = 1d0\n call linint_Grow(a_t(-5000), a_l, a_u, a_grow, NA, ial, iar, varphi)\n c_t(-5000) = varphi*c(ial, is_t(-5000)) + (1d0-varphi)*c(iar, is_t(-5000))\n\n ! calculate the time path of all economic variables\n do it = -4999, TT\n eta_t(it) = eta(is_t(it))\n a_t(it) = min(w*eta_t(it-1) + (1d0+r)*a_t(it-1) - c_t(it-1), a_u)\n call linint_Grow(a_t(it), a_l, a_u, a_grow, NA, ial, iar, varphi)\n c_t(it) = varphi*c(ial, is_t(it)) + (1d0-varphi)*c(iar, is_t(it))\n enddo\n\n end subroutine\n\nend module\n", "meta": {"hexsha": "b7d3a625c834bf5b530626a6bbad39ab73739774", "size": 6155, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "complete/prog09/prog09_08/prog09_08m.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/prog09/prog09_08/prog09_08m.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/prog09/prog09_08/prog09_08m.f90", "max_forks_repo_name": "aswinvk28/modflow_fortran", "max_forks_repo_head_hexsha": "0c8dd5da8fe08f0abcc6b677503e96cdcdb7ee1e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-04-07T12:27:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-07T12:27:47.000Z", "avg_line_length": 27.7252252252, "max_line_length": 90, "alphanum_fraction": 0.5380991064, "num_tokens": 1729, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178870347122, "lm_q2_score": 0.7606506526772883, "lm_q1q2_score": 0.6911407888072124}} {"text": "module parameters\r\n integer, parameter :: latt_leng = 30\r\n integer, parameter :: EXCH_CONST = 1 ! exchange constant\r\n integer, parameter :: n_T_step = 500\r\n double precision, parameter :: T_start = 0.5d0\r\n double precision, parameter :: T_end = 3.5d0\r\n integer, dimension(-1 : latt_leng, -1 : latt_leng) :: spin_of ! (-1 ... latt_leng) X (-1 ... latt_leng)\r\nend module\r\n\r\nprogram Tc_calculate\r\n use parameters\r\n implicit none\r\n integer i\r\n double precision, dimension(0 : n_T_step):: M\r\n double precision, dimension(0 : n_T_step):: Cv\r\n double precision, dimension(0 : n_T_step):: E\r\n double precision :: T, Tc_E, Tc_M, Tc_Cv\r\n \r\n open (unit=15, file='output_ising_model_avg_E_change_plot_5.txt', status='old', &\r\n access='sequential', form='formatted', action='read' )\r\n open (unit=20, file='output_ising_model_avg_M_change_plot_5.txt', status='old', &\r\n access='sequential', form='formatted', action='read' )\r\n open (unit=25, file='output_ising_model_avg_Cv_change_plot_5.txt', status='old', &\r\n access='sequential', form='formatted', action='read' )\r\n \r\n do i = 0, n_T_step\r\n read (15, *) T, E(i)\r\n read (20, *) T, M(i)\r\n read (25, *) T, Cv(i)\r\n end do\r\n \r\n call compute_Tc_with_E_or_M(E, Tc_E)\r\n call compute_Tc_with_E_or_M(M, Tc_M)\r\n call compute_Tc_with_Cv(Cv, Tc_Cv)\r\n print *, \"Tc_E = \", Tc_E\r\n print *, \"Tc_M = \", Tc_M \r\n print *, \"Tc_Cv = \", Tc_Cv \r\n close(15)\r\n close(20)\r\n close(25)\r\nend program\r\n\r\n\r\nsubroutine compute_Tc_with_E_or_M(phys_obsv, Tc) ! Compute Tc by calculating T where dp_q / dT is max.\r\n use parameters\r\n integer :: T_step\r\n double precision :: max_slope, slope, del_T, T\r\n double precision, intent(out) :: Tc\r\n double precision, dimension(0 : n_T_step), intent(in) :: phys_obsv\r\n\r\n max_slope = 0d0\r\n slope = 0d0\r\n del_T = (T_end - T_start) / n_T_step\r\n do T_step = 0, n_T_step - 1\r\n T = T_start + del_T * T_step\r\n slope = (phys_obsv(T_step + 1) - phys_obsv(T_step)) / del_T\r\n if (slope > max_slope) then \r\n max_slope = slope\r\n Tc = T + 0.5*del_T\r\n end if\r\n end do\r\nend subroutine\r\nsubroutine compute_Tc_with_Cv(Cv, Tc)\r\n use parameters\r\n integer :: T_step\r\n double precision :: max_value, del_T, T\r\n double precision, intent(out) :: Tc\r\n double precision, dimension(0 : n_T_step), intent(in) :: Cv\r\n\r\n max_value = 0d0\r\n del_T = (T_end - T_start) / n_T_step\r\n do T_step = 0, n_T_step\r\n T = T_start + del_T * T_step\r\n if (Cv(T_step) > max_value) then \r\n max_value = Cv(T_step)\r\n Tc = T\r\n end if\r\n end do\r\nend subroutine\r\n", "meta": {"hexsha": "4c47ba80e134bc098ae62c4b5fb286c608b95139", "size": 2756, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src-fortran/Tc_calculation_from_txt.f95", "max_stars_repo_name": "swlee23/ising-model", "max_stars_repo_head_hexsha": "4fc88612a5330d8e52ce3809673b3689c65aeac7", "max_stars_repo_licenses": ["MIT"], "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-fortran/Tc_calculation_from_txt.f95", "max_issues_repo_name": "swlee23/ising-model", "max_issues_repo_head_hexsha": "4fc88612a5330d8e52ce3809673b3689c65aeac7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src-fortran/Tc_calculation_from_txt.f95", "max_forks_repo_name": "swlee23/ising-model", "max_forks_repo_head_hexsha": "4fc88612a5330d8e52ce3809673b3689c65aeac7", "max_forks_repo_licenses": ["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.45, "max_line_length": 108, "alphanum_fraction": 0.6026850508, "num_tokens": 845, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178969328287, "lm_q2_score": 0.7606506418255928, "lm_q1q2_score": 0.6911407864761765}} {"text": " program demo_decodebase\n use M_strings, only : codebase, decodebase\n implicit none\n integer :: ba,bd\n character(len=40) :: x,y\n integer :: r\n\n print *,' BASE CONVERSION'\n write(*,'(\"Start Base (2 to 36): \")',advance='no'); read *, bd\n write(*,'(\"Arrival Base (2 to 36): \")',advance='no'); read *, ba\n INFINITE: do\n print *,''\n write(*,'(\"Enter number in start base: \")',advance='no'); read *, x\n if(x.eq.'0') exit INFINITE\n if(decodebase(x,bd,r)) then\n if(codebase(r,ba,y)) then\n write(*,'(\"In base \",I2,\": \",A20)') ba, y\n else\n print *,'Error in coding number.'\n endif\n else\n print *,'Error in decoding number.'\n endif\n enddo INFINITE\n\n end program demo_decodebase\n", "meta": {"hexsha": "6be5fdb351662203f9a70ccb6d9e720d78b8399e", "size": 964, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/demo_decodebase.f90", "max_stars_repo_name": "urbanjost/M_strings", "max_stars_repo_head_hexsha": "360b3ec5fb78fdff63ad14a7933f44403cc5d930", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2019-12-16T20:00:23.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-10T01:44:42.000Z", "max_issues_repo_path": "example/demo_decodebase.f90", "max_issues_repo_name": "urbanjost/M_strings", "max_issues_repo_head_hexsha": "360b3ec5fb78fdff63ad14a7933f44403cc5d930", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-01-11T16:35:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-18T19:54:11.000Z", "max_forks_repo_path": "example/demo_decodebase.f90", "max_forks_repo_name": "urbanjost/M_strings", "max_forks_repo_head_hexsha": "360b3ec5fb78fdff63ad14a7933f44403cc5d930", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-26T13:59:46.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-24T03:28:12.000Z", "avg_line_length": 35.7037037037, "max_line_length": 80, "alphanum_fraction": 0.4450207469, "num_tokens": 234, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8577681122619883, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.6910456039214244}} {"text": "MODULE FUN_xyCOLINEAR\n!!#### PURPOSE\n!! Test for colinearity between:\n!! @ three points in R^2 \n!! @ a line and a point in R^2 \n\n!!#### DETAILS\n!! Collinear is the most common spelling but I don\"t know where the\n!! extra \"l\" comes from so I\"m not using it.\n\n\n!!#### METHOD\n!! For three points to be colinear, the following ratios must be equal:\n!! x2-x1:y2-y1 = x3-x1:y3-y1\n!! where the three points being tested are (x1,y1), (x2,y2), and (x3,y3).\n\n\n!!#### SOURCE\n!! Eric W. Weisstein. \"Collinear.\" From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/Collinear.html\n\n\n!We will check to see that the following fraction is equal.\n!\n!! x2-x1 x3-x1\n!! ----- = -----\n!! y2-y1 y3-y1\n\n\n!!#### DEPENDENCIES\nUSE KND_IntrinsicTypes,ONLY: KIND_Rsp,KIND_Rdp !!((01-A-KND_IntrinsicTypes.f90))\nUSE FUN_Default !!((04-A-FUN_Default.f90))\n\n\n!!#### DEFAULT IMPLICIT\nIMPLICIT NONE\n\n!!#### DEFAULT ACCESS\nPRIVATE\n\n!!#### PROCEDURE OVERLOADING\nINTERFACE xyCOLINEAR_P3\n MODULE PROCEDURE xyCOLINEAR_P3_Rsp\n MODULE PROCEDURE xyCOLINEAR_P3_Rdp\nEND INTERFACE\n\nINTERFACE xyCOLINEAR_LnP\n MODULE PROCEDURE xyCOLINEAR_LnP_Rsp\n MODULE PROCEDURE xyCOLINEAR_LnP_Rdp\nEND INTERFACE\n\n!!#### PUBLIC ACCESS LIST\nPUBLIC :: xyCOLINEAR_P3\nPUBLIC :: xyCOLINEAR_LnP\n\nCONTAINS\n\n\nFUNCTION xyCOLINEAR_P3_Rsp( P3 , tol , err ) RESULT(COLINEAR)\n!!#### LOCAL KINDS\nUSE KND_IntrinsicTypes ,ONLY: KIND_R=>KIND_Rsp !!((01-A-KND_IntrinsicTypes.f90))\nUSE PAR_Constants_Rsp ,ONLY: c_1 !!((02-A-PAR_Constants_Rsp.f90))\nUSE VAR_ComputationalGeometry,ONLY: DEFAULT_tol=>DEFAULT_tol_Rsp !!((03-A-VAR_ComputationalGeometry.f90))\nINCLUDE \"05-B-FUN_xyCOLINEAR_P3.f90.hdr\"\n!!--begin--\nINCLUDE \"05-B-FUN_xyCOLINEAR_P3.f90.alg\"\n!!--end--\nEND FUNCTION\n\nFUNCTION xyCOLINEAR_P3_Rdp( P3 , tol , err ) RESULT(COLINEAR)\n!!#### LOCAL KINDS\nUSE KND_IntrinsicTypes ,ONLY: KIND_R=>KIND_Rdp !!((01-A-KND_IntrinsicTypes.f90))\nUSE PAR_Constants_Rdp ,ONLY: c_1 !!((02-A-PAR_Constants_Rdp.f90))\nUSE VAR_ComputationalGeometry,ONLY: DEFAULT_tol=>DEFAULT_tol_Rdp !!((03-A-VAR_ComputationalGeometry.f90))\nINCLUDE \"05-B-FUN_xyCOLINEAR_P3.f90.hdr\"\n!!--begin--\nINCLUDE \"05-B-FUN_xyCOLINEAR_P3.f90.alg\"\n!!--end--\nEND FUNCTION\n\n\nFUNCTION xyCOLINEAR_LnP_Rsp( Ln , P , tol , err ) RESULT(COLINEAR)\n!!#### LOCAL KINDS\nUSE KND_IntrinsicTypes ,ONLY: KIND_R=>KIND_Rsp !!((01-A-KND_IntrinsicTypes.f90))\nUSE PAR_Constants_Rsp ,ONLY: c_1 !!((02-A-PAR_Constants_Rsp.f90))\nUSE VAR_ComputationalGeometry,ONLY: DEFAULT_tol=>DEFAULT_tol_Rsp !!((03-A-VAR_ComputationalGeometry.f90))\nINCLUDE \"05-B-FUN_xyCOLINEAR_LnP.f90.hdr\"\n!!--begin--\nINCLUDE \"05-B-FUN_xyCOLINEAR_LnP.f90.bdy\"\n!!--end--\nEND FUNCTION\n\nFUNCTION xyCOLINEAR_LnP_Rdp( Ln , P , tol , err ) RESULT(COLINEAR)\n!!#### LOCAL KINDS\nUSE KND_IntrinsicTypes ,ONLY: KIND_R=>KIND_Rdp !!((01-A-KND_IntrinsicTypes.f90))\nUSE PAR_Constants_Rdp ,ONLY: c_1 !!((02-A-PAR_Constants_Rdp.f90))\nUSE VAR_ComputationalGeometry,ONLY: DEFAULT_tol=>DEFAULT_tol_Rdp !!((03-A-VAR_ComputationalGeometry.f90))\nINCLUDE \"05-B-FUN_xyCOLINEAR_LnP.f90.hdr\"\n!!--begin--\nINCLUDE \"05-B-FUN_xyCOLINEAR_LnP.f90.bdy\"\n!!--end--\nEND FUNCTION\n\n\nFUNCTION TEST_xyCOLINEAR_LnP() RESULT(Pass)\nLOGICAL :: Pass\nPass = .TRUE.\n\nEND FUNCTION\n\nEND MODULE\n", "meta": {"hexsha": "3c37388c518a329be0a8fc3b7d85c6bdf5d82edf", "size": 3463, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/05-B-FUN_xyCOLINEAR.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/05-B-FUN_xyCOLINEAR.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/05-B-FUN_xyCOLINEAR.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": 31.1981981982, "max_line_length": 118, "alphanum_fraction": 0.6814900375, "num_tokens": 1070, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.8056321866478978, "lm_q1q2_score": 0.6910455940600009}} {"text": "Program Task1\nIMPLICIT NONE\n! p 'Results.dat' u 1:2 w l, '' u 1:3 w l\n\nREAL, Dimension(:), Allocatable:: Time, Mass, MassExact, MassError\nREAL:: h, MassDash, LargestError\nINTEGER:: I, npts\n\nnpts=300\n\nAllocate(Time(0:npts), Mass(0:npts), MassExact(0:npts), MassError(0:npts))\n\nMass(0)=0.1; Time(0)=0.0; h=0.1 !Setting intial boundary conditions\n\nOPEN(10, FILE='Results.dat')\n\nDO i=1,npts\n\n Time(i)=Time(i-1)+h\n MassDash=-0.3*Mass(i-1)\n Mass(i)=Mass(i-1)+h*MassDash\n \n MassExact(i)=0.1*exp(-0.3*Time(i))\n\n MassError(i) = ABS(MassExact(i)-Mass(i))\n\n WRITE(10,'(f9.5, f9.5, f9.5, f9.5)') Time(i), Mass(i), MassExact(i), MassError(i)\n \nEND DO\n\nLargestError = MAXVAL(MassError)\n\nWRITE(6,*) 'Largest absolute difference between exact and apporximated mass is:',LargestError \n\nCLOSE(10)\n\nDEALLOCATE(Time, Mass, MassExact)\n\nEND PROGRAM \n\n\n\n\n\n\n", "meta": {"hexsha": "896b049d3e897b8720999e08ca233189ab54dcae", "size": 842, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Radioactive Decay/Task 1.f90", "max_stars_repo_name": "DGrifferty/Fortran", "max_stars_repo_head_hexsha": "600b46fb553fe955c7dd574ee4f51ac1f24de62e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Radioactive Decay/Task 1.f90", "max_issues_repo_name": "DGrifferty/Fortran", "max_issues_repo_head_hexsha": "600b46fb553fe955c7dd574ee4f51ac1f24de62e", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Radioactive Decay/Task 1.f90", "max_forks_repo_name": "DGrifferty/Fortran", "max_forks_repo_head_hexsha": "600b46fb553fe955c7dd574ee4f51ac1f24de62e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.3043478261, "max_line_length": 94, "alphanum_fraction": 0.674584323, "num_tokens": 310, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182187, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.6910455902030158}} {"text": "double precision function true_solution(x, y, t)\n\n! True solution for the porous medium equation,\n! q_t = (q**2)_xx.\n\n double precision :: x, y, t\n double precision :: mass, tau, t0\n parameter(mass = 1.d0)\n parameter(t0 = .3d0)\n\n tau = t + t0\n true_solution = (mass - 1.d0/16.d0 * (x**2 + y**2) / sqrt(tau)) / sqrt(tau)\n if (true_solution < 0.d0) true_solution = 0.d0\nend function true_solution\n", "meta": {"hexsha": "328ce81a31681d53be8782f6ca07b7eb3c1c12dc", "size": 420, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "applications/2d/Order2Nonlinear/true_solution.f90", "max_stars_repo_name": "claridge/implicit_solvers", "max_stars_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-04-29T00:16:18.000Z", "max_stars_repo_stars_event_max_datetime": "2017-04-29T00:16:18.000Z", "max_issues_repo_path": "applications/2d/Order2Nonlinear/true_solution.f90", "max_issues_repo_name": "claridge/implicit_solvers", "max_issues_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "applications/2d/Order2Nonlinear/true_solution.f90", "max_forks_repo_name": "claridge/implicit_solvers", "max_forks_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.0, "max_line_length": 79, "alphanum_fraction": 0.6261904762, "num_tokens": 140, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9532750440288019, "lm_q2_score": 0.7248702761768248, "lm_q1q2_score": 0.6910007444376324}} {"text": "!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 2005 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Fishpack *\n! * *\n! * A Package of Fortran *\n! * *\n! * Subroutines and Example Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams, Paul Swarztrauber and Roland Sweet *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\n! Purpose:\n!\n! To illustrate the use of subroutine blktri to\n! solve the equation\n!\n! 0.5/s*(d/ds)(0.5/s*du/ds)+0.5/t*(d/dt)(0.5/t*du/dt)\n! (1)\n! = 15/4*s*t*(s**4+t**4)\n!\n! on the rectangle 0 < s < 1 and 0 < t < 1\n! with the boundary conditions\n!\n! u(0, t) = 0\n! 0 <= t <= 1\n! u(1, t) = t**5\n!\n! and\n!\n! u(s, 0) = 0\n! 0 <= s <= 1\n! u(s, 1) = s**5\n!\n! the exact solution of this problem is u(s, t) = (s*t)**5\n!\n! define the integers m = 50 and n = 63. then define the\n! grid increments deltas = 1/(m+1) and deltat = 1/(n+1).\n!\n! the grid is then given by s(i) = i*deltas for i = 1, ..., m\n! and t(j) = j*deltat for j = 1, ..., n.\n!\n! the approximate solution is given as the solution to\n! the following finite difference approximation of equation (1).\n!\n! .5/(s(i)*deltas)*((u(i+1, j)-u(i, j))/(2*s(i+.5)*deltas)\n! -(u(i, j)-u(i-1, j))/(2*s(i-.5)*deltas))\n! +.5/(t(i)*deltat)*((u(i, j+1)-u(i, j))/(2*t(i+.5)*deltat) (2)\n! -(u(i, j)-u(i, j-1))/(2*t(i-.5)*deltat))\n! = 15/4*s(i)*t(j)*(s(i)**4+t(j)**4)\n!\n! where s(i+.5) = .5*(s(i+1)+s(i))\n! s(i-.5) = .5*(s(i)+s(i-1))\n! t(i+.5) = .5*(t(i+1)+t(i))\n! t(i-.5) = .5*(t(i)+t(i-1))\n!\n! the approach is to write equation (2) in the form\n!\n! am(i)*u(i-1, j)+bm(i, j)*u(i, j)+cm(i)*u(i+1, j)\n! +an(j)*u(i, j-1)+bn(j)*u(i, j)+cn(j)*u(i, j+1) (3)\n! = y(i, j)\n!\n! and then call subroutine blktri to determine u(i, j)\n!\nprogram test_blktri\n\n use, intrinsic :: ISO_Fortran_env, only: &\n stdout => OUTPUT_UNIT\n\n use fishpack\n\n ! Explicit typing only\n implicit none\n\n ! Dictionary\n type(FishpackWorkspace) :: workspace\n integer(ip), parameter :: M = 50, N = 63\n integer(ip), parameter :: IDIMY = 75, NT = 105\n integer(ip) :: iflg, np, mp, i, j, ierror\n real(wp) :: y(IDIMY, NT)\n real(wp), dimension(IDIMY) :: am, bm, cm, s\n real(wp), dimension(NT) :: an, bn, cn, t\n real(wp) :: ds, dt\n real(wp), parameter :: ONE = 1.0_wp, TWO = 2.0_wp\n\n ! Set boundary conditions\n np = 1\n mp = 1\n\n ! Set mesh sizes\n ds = ONE/(M + 1)\n dt = ONE/(N + 1)\n\n ! Generate and store grid points for the purpose of computing the\n ! coefficients and the array y.\n do i = 1, M\n s(i) = real(i, kind=wp) * ds\n end do\n\n do j = 1, N\n t(j) = real(j, kind=wp) * dt\n end do\n\n ! Compute the coefficients am, bm, cm corresponding to the s direction\n block\n real(wp) :: half_ds, two_ds\n real(wp) :: temp1, temp2, temp3\n\n half_ds = ds/2\n two_ds = TWO * ds\n\n do i = 1, M\n temp1 = ONE/(s(i) * two_ds)\n temp2 = ONE/((s(i) - half_ds) * two_ds)\n temp3 = ONE/((s(i) + half_ds) * two_ds)\n am(i) = temp1 * temp2\n cm(i) = temp1 * temp3\n bm(i) = -(am(i) + cm(i))\n end do\n end block\n\n ! Compute the coefficients an, bn, cn corresponding to the t direction\n block\n real(wp) :: half_dt, two_dt\n real(wp) :: temp1, temp2, temp3\n\n half_dt = dt/2\n two_dt = TWO * dt\n\n do j = 1, N\n temp1 = ONE / (t(j) * two_dt)\n temp2 = ONE / ((t(j)-half_dt) * two_dt)\n temp3 = ONE / ((t(j)+half_dt) * two_dt)\n an(j) = temp1 * temp2\n cn(j) = temp1 * temp3\n bn(j) = -(an(j) + cn(j))\n end do\n end block\n\n ! Compute right hand side of equation\n do j = 1, n\n y(:M, j) = 3.75_wp * s(:M) * t(j) * (s(:M)**4 + t(j)**4)\n end do\n\n ! The nonzero boundary conditions enter the linear system via\n ! the right side y(i, j). if the equations (3) given above\n ! are evaluated at i=m and j=1, ..., n then the term cm(m)*u(m+1, j)\n ! is known from the boundary condition to be cm(m)*t(j)**5.\n ! therefore this term can be included in the right side y(m, j).\n ! the same analysis applies at j=n and i=1, .., m. note that the\n ! corner at j=n, i=m includes contributions from both boundaries.\n y(M,:N) = y(M,:N) - cm(M) * (t(:N)**5)\n y(:M,N) = y(:M,N) - cn(N) * (s(:M)**5)\n\n ! Initialize workspace and lower solver routines\n iflg = 0\n call blktri(iflg, np, N, an, bn, cn, mp, M, am, bm, cm, IDIMY, y, ierror, workspace)\n\n iflg = iflg + 1\n do while (iflg <= 1)\n\n ! Solve real block tridiagonal linear system\n call blktri(iflg, np, N, an, bn, cn, mp, M, am, bm, cm, IDIMY, &\n y, ierror, workspace)\n\n iflg = iflg + 1 ! Increment flag\n end do\n\n ! Compute discretization error. The exact solution is\n !\n ! u(s,t) = (st)**5\n block\n real(wp), parameter :: KNOWN_ERROR = 0.164778571363905e-4_wp\n real(wp) :: discretization_error\n real(wp) :: exact_solution(M, N)\n\n do j = 1, N\n do i = 1, M\n exact_solution(i,j) = (s(i)*t(j))**5\n end do\n end do\n\n ! Set discretization error\n discretization_error = maxval(abs(exact_solution-y(:M,:N)))\n\n call check_output('blktri', ierror, KNOWN_ERROR, discretization_error)\n end block\n\n ! Release memory\n call workspace%destroy()\n\nend program test_blktri\n", "meta": {"hexsha": "cdb252828cf735aafbc8a32a1db13b95f2d8aaf1", "size": 7462, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/tblktri.f90", "max_stars_repo_name": "jlokimlin/fishpack", "max_stars_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2018-03-12T11:31:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-27T07:58:23.000Z", "max_issues_repo_path": "examples/tblktri.f90", "max_issues_repo_name": "jlokimlin/fishpack", "max_issues_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2016-05-07T22:42:47.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-15T17:44:58.000Z", "max_forks_repo_path": "examples/tblktri.f90", "max_forks_repo_name": "jlokimlin/modern_fishpack", "max_forks_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-01-26T20:49:05.000Z", "max_forks_repo_forks_event_max_datetime": "2017-01-27T16:44:58.000Z", "avg_line_length": 34.8691588785, "max_line_length": 88, "alphanum_fraction": 0.4036451354, "num_tokens": 2104, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648677, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.6909845595703886}} {"text": " program phitest \nc-------------------------------------------------------------------\nc Test program for exponential propagator using Arnoldi approach\nc This main program is a very simple test using diagonal matrices\nc (Krylov subspace methods are blind to the structure of the matrix\nc except for symmetry). This provides a good way of testing the\nc accuracy of the method as well as the error estimates. This test\nc program tests the phi-function variant instead of the exponential.\nc\nc The subroutine phipro which is tested here computes an approximation \nc to the vector\nc\nc \tw(tn) = w(t0) + tn * phi( - A * tn ) * (r - A w(t0))\nc\nc where phi(z) = (1-exp(z)) / z\nc \nc i.e. it solves dw/dt = -A w + r in [t0,t0+ tn] (returns only w(t0+tn))\nc \nc In this program t0=0, tn is input by the user and A is a simple \nc diagonal matrix. \nc\nc-------------------------------------------------------------------\n implicit real*8 (a-h,o-z)\n parameter (nmax = 400, ih0=60, ndmx=20,nzmax = 7*nmax)\n real*8 a(nzmax), u(ih0*nmax), w(nmax),w1(nmax),x(nmax),y(nmax),\n * r(nmax) \n integer ioff(10) \n data iout/6/,a0/0.0/,b0/1.0/,epsmac/1.d-10/,eps/1.d-10/\nc \nc dimendion of matrix\nc \n n = 100\nc---------------------------define matrix -----------------------------\nc A is a single diagonal matrix (ndiag = 1 and ioff(1) = 0 ) \nc-----------------------------------------------------------------------\n ndiag = 1\n ioff(1) = 0\nc\nc entriesin the diagonal are uniformly distributed. \nc \n h = 1.0d0 / real(n+1) \n do 1 j=1, n\n a(j) = real(j+1)*h \n 1 continue\nc--------\n write (6,'(10hEnter tn: ,$)')\n read (5,*) tn \nc \n write (6,'(36hEpsilon (desired relative accuracy): ,$)')\n read (5,*) eps \nc-------\n write (6,'(36h m (= dimension of Krylov subspace): ,$)')\n read (5,*) m \nc \nc define initial conditions to be (1,1,1,1..1)^T\nc \n do 2 j=1,n\n w(j) = 1.0 - 1.0/real(j+10) \n r(j) = 1.0\n w1(j) = w(j) \n 2 continue\nc \nc \nc HERE IT IS DONE IN 10 SUBSTEPS \nc nsteps = 10 \nc tnh = tn/real(nsteps) \nc MARCHING LOOP \nc do jj =1, nsteps \nc call phiprod (n, m, eps, tnh, u, w, r, x, y, a, ioff, ndiag) \n call phiprod (n, m, eps, tn, u, w, r, x, y, a, ioff, ndiag)\nc enddo\n print *, ' final answer '\n print *, (w(k),k=1,20) \nc \nc exact solution \nc \n do 4 k=1,n\n w1(k)=w1(k)+((1.0 - dexp(-a(k)*tn) )/a(k))*(r(k) \n + - a(k)*w1(k) ) \n 4 continue\nc \nc exact solution \nc \n print *, ' exact answer '\n print *, (w1(k),k=1,20) \nc \nc computing actual 2-norm of error \nc \n t = 0.0d0\n do 47 k=1,n\n t = t+ (w1(k)-w(k))**2 \n 47 continue\n t = dsqrt(t / ddot(n, w,1,w,1) )\nc \n write (6,*) ' final error', t\nc----------------------------------------------------------------------- \n stop\n end\nc-----------------------------------------------------------------------\n\tsubroutine oped(n,x,y,diag,ioff,ndiag)\nc======================================================\nc this kernel performs a matrix by vector multiplication\nc for a diagonally structured matrix stored in diagonal format\nc======================================================\n\timplicit real*8 (a-h,o-z)\n\treal*8 x(n), y(n), diag(n,ndiag)\n\tcommon nope, nmvec\n\tinteger j, n, ioff(ndiag)\nCDIR$ IVDEP\n\tdo 1 j=1, n\n\t\ty(j) = 0.00\n 1\tcontinue\t\nc\n\tdo 10 j=1,ndiag\n\tio = ioff(j)\n\ti1=max0(1,1-io)\n\ti2=min0(n,n-io)\nCDIR$ IVDEP\n\tdo 9 k=i1,i2\n\ty(k) = y(k)+diag(k,j)*x(k+io)\n 9\tcontinue\n 10\tcontinue\n\tnmvec = nmvec + 1 \n\tnope = nope + 2*ndiag*n\n\treturn\n\tend\nc\n", "meta": {"hexsha": "17f75a44aab06e8304ef34c280de96b475347c46", "size": 3727, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/latools/SPARSKIT2/UNSUPP/MATEXP/rphi.f", "max_stars_repo_name": "xywei/Mirana", "max_stars_repo_head_hexsha": "81d0ed67fad20cd3be8880ed672c12feff3c22c9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-03-11T15:22:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-22T16:26:18.000Z", "max_issues_repo_path": "src/latools/SPARSKIT2/UNSUPP/MATEXP/rphi.f", "max_issues_repo_name": "xywei/Mirana", "max_issues_repo_head_hexsha": "81d0ed67fad20cd3be8880ed672c12feff3c22c9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2021-06-30T20:39:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-15T12:42:50.000Z", "max_forks_repo_path": "src/latools/SPARSKIT2/UNSUPP/MATEXP/rphi.f", "max_forks_repo_name": "xywei/Mirana", "max_forks_repo_head_hexsha": "81d0ed67fad20cd3be8880ed672c12feff3c22c9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-03-13T17:09:10.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-22T00:30:19.000Z", "avg_line_length": 29.1171875, "max_line_length": 75, "alphanum_fraction": 0.4832304803, "num_tokens": 1221, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044095, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.6909845543841474}} {"text": " real*8 function fndmnx(vector,ndim,minmax)\nc\nc find smallest(minmax=1) or largest(minmax=2)\nc *absolute* value of elements in vector\n* or\nc find smallest(minmax=-1) or largest(minmax=-2)\nc value of elements in vector\nc\nc adapted from Jeppe Olsen's version\nc\n implicit none\n integer, intent(in) ::\n & ndim, minmax\n real(8), intent(in) ::\n & vector(ndim)\n integer ::\n & i\nc\n if(minmax.eq.1) then\n fndmnx=abs(vector(1))\n do i=2,ndim\n fndmnx=min(fndmnx,abs(vector(i)))\n end do\n end if\nc\n if(minmax.eq.2) then\n fndmnx=abs(vector(1))\n do i=2,ndim\n fndmnx=max(fndmnx,abs(vector(i)))\n end do\n end if\nc\n if(minmax.eq.-1) then\n fndmnx=vector(1)\n do i=2,ndim\n fndmnx=min(fndmnx,vector(i))\n end do\n end if\nc\n if(minmax.eq.-2) then\n fndmnx=vector(1)\n do i=2,ndim\n fndmnx=max(fndmnx,vector(i))\n end do\n end if\n \n return\n end\n", "meta": {"hexsha": "090f285d7853aca9d3172e4b864c71d34ab8e5ef", "size": 1060, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "baserout/fndmnx.f", "max_stars_repo_name": "ak-ustutt/GeCCo-public", "max_stars_repo_head_hexsha": "8d43a6c9323aeba7eb54625b95553bfd4b2418c6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "baserout/fndmnx.f", "max_issues_repo_name": "ak-ustutt/GeCCo-public", "max_issues_repo_head_hexsha": "8d43a6c9323aeba7eb54625b95553bfd4b2418c6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baserout/fndmnx.f", "max_forks_repo_name": "ak-ustutt/GeCCo-public", "max_forks_repo_head_hexsha": "8d43a6c9323aeba7eb54625b95553bfd4b2418c6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.6326530612, "max_line_length": 52, "alphanum_fraction": 0.5311320755, "num_tokens": 352, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648677, "lm_q2_score": 0.7905303162021597, "lm_q1q2_score": 0.6909845530999924}} {"text": "MODULE Residuo\n\n CONTAINS\n \n SUBROUTINE calcula_residuo_UV( A, u, b, r, t)\n \n USE ClassMatrizA\n \n IMPLICIT NONE\n \n TYPE ( MatrizA ), INTENT(IN) :: A\n DOUBLE PRECISION, DIMENSION(:, :), INTENT(INOUT) :: r\n DOUBLE PRECISION, DIMENSION(:, :), INTENT(IN) :: u, b\n INTEGER, INTENT(IN) :: t\n \n INTEGER :: p, stencil, ite, se ! se = elemento do stencil\n DOUBLE PRECISION :: ax, ux, sm, correcao ! Soma dos componentes do stencil\n \n \n DO p = 1, A % Nx * A % Ny\n \n ! Obtendo o stencil do volume\n stencil = A % v(p)\n \n ! Para cada coeficiente do stencil da matriz\n ! Lembrando que o primeiro e sempre ap e Gauss-Seidel\n ! e definido como \n ! u(p) = (aw * u(p-1) + ae * u(p+1) + as * u(p-Nx) ... + b(p)) / ap\n ! O codigo abaixo soma aw * u(p-1) + ae * u(p+1) + as * u(p-Nx) ...\n sm = 0.0d0\n DO se = 2, SIZE(A % s(stencil) % p) !(comeca em 2 porque nao considera o ap)\n \n ! ax = aw, ae, as, an, aww, ann, etc...\n ! ux = u(p-1), u(p+1), u(p-Nx), u(p+Nx), u(p-2), u(p+2*Nx), etc...\n ! Logo\n ! ax * ux = aw * u(p-1), ae * u(p+1), as * u(p-Nx), etc...\n \n ax = A % s(stencil) % c(se)\n ux = u(p + A % s(stencil) % p(se), t+1)\n \n sm = sm + ax * ux\n \n END DO \n \n ! Obtendo o ap\n ax = A % s(stencil) % c(1)\n sm = sm + u(p, t)\n \n ! Somando b(p) e subtraindo ap * up para compor o residuo\n r(p, t+1) = sm + b(p, t) - ax * u(p, t+1)\n \n END DO\n \n \n END SUBROUTINE calcula_residuo_UV\n\n \n \n SUBROUTINE calcula_residuo_P(A, u, b, r, t)\n \n USE ClassMatrizA\n \n IMPLICIT NONE\n \n TYPE ( MatrizA ), INTENT(IN) :: A\n DOUBLE PRECISION, DIMENSION(:, :), INTENT(INOUT) :: r\n DOUBLE PRECISION, DIMENSION(:, :), INTENT(IN) :: u, b\n INTEGER, INTENT(IN) :: t\n \n INTEGER :: p, stencil, ite, se ! se = elemento do stencil\n DOUBLE PRECISION :: ax, ux, sm, correcao ! Soma dos componentes do stencil\n \n \n DO p = 1, A % Nx * A % Ny\n \n ! Obtendo o stencil do volume\n stencil = A % v(p)\n \n ! Para cada coeficiente do stencil da matriz\n ! Lembrando que o primeiro e sempre ap e Gauss-Seidel\n ! e definido como \n ! u(p) = (aw * u(p-1) + ae * u(p+1) + as * u(p-Nx) ... + b(p)) / ap\n ! O codigo abaixo soma aw * u(p-1) + ae * u(p+1) + as * u(p-Nx) ...\n sm = 0.0d0\n DO se = 2, SIZE(A % s(stencil) % p) !(comeca em 2 porque nao considera o ap)\n \n ! ax = aw, ae, as, an, aww, ann, etc...\n ! ux = u(p-1), u(p+1), u(p-Nx), u(p+Nx), u(p-2), u(p+2*Nx), etc...\n ! Logo\n ! ax * ux = aw * u(p-1), ae * u(p+1), as * u(p-Nx), etc...\n \n ax = A % s(stencil) % c(se)\n ux = u(p + A % s(stencil) % p(se), t+1)\n \n sm = sm + ax * ux\n \n END DO \n \n ! Obtendo o ap\n ax = A % s(stencil) % c(1)\n \n ! Somando b(p) e subtraindo ap * up para compor o residuo\n r(p, t+1) = sm + b(p, t) - ax * u(p, t+1)\n \n END DO\n \n END SUBROUTINE calcula_residuo_P\n\nEND MODULE Residuo\n", "meta": {"hexsha": "4427581ff7ba033e41a5c504f459c6dc6fd92c16", "size": 3769, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "residuo.f90", "max_stars_repo_name": "RevertonLuis/NavierStokesSpaceTimeParallelProjectionMethod", "max_stars_repo_head_hexsha": "23fbf3b01a34c244d8928fae4ad9d12bffef8d07", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-02T16:28:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-02T16:28:12.000Z", "max_issues_repo_path": "residuo.f90", "max_issues_repo_name": "RevertonLuis/NavierStokesSpaceTimeParallelProjectionMethod", "max_issues_repo_head_hexsha": "23fbf3b01a34c244d8928fae4ad9d12bffef8d07", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "residuo.f90", "max_forks_repo_name": "RevertonLuis/NavierStokesSpaceTimeParallelProjectionMethod", "max_forks_repo_head_hexsha": "23fbf3b01a34c244d8928fae4ad9d12bffef8d07", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.2636363636, "max_line_length": 87, "alphanum_fraction": 0.4032899973, "num_tokens": 1138, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711908591638, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.690913806006115}} {"text": "program problem26\n implicit none\n integer :: i,temp,answer=-1,best=-1\n\n do i=2,1000\n temp=period(i)\n if (temp>best) then\n best=temp\n answer=i\n end if\n end do\n\n print *, answer\n\ncontains\n pure function period(n)\n implicit none\n integer, intent(in) :: n\n integer, parameter :: size=1000000\n integer, dimension(size) :: quotients,remainders\n integer :: period,i,j\n\n quotients(1)=0\n remainders(1)=1\n\n ! Generate sequence of (quotient,remainder) pairs. A cycle occurs\n ! when and only when a (quotient,remainder) pair is repeated.\n do i=2,size\n quotients(i)=(remainders(i-1)*10)/n\n remainders(i)=mod(remainders(i-1)*10,n)\n ! Look for a repeated pair\n do j=1,i-1\n if (quotients(i)==quotients(j) .and. remainders(i)==remainders(j)) then\n period=i-j\n go to 1\n end if\n end do\n end do\n1 continue\n\n end function period\n\nend program problem26\n", "meta": {"hexsha": "21a89e9413d9c5cc17e30eb0fc16e0e6a9d0b5bd", "size": 1000, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "problem26.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": "problem26.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": "problem26.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": 22.7272727273, "max_line_length": 81, "alphanum_fraction": 0.591, "num_tokens": 289, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84997116805678, "lm_q2_score": 0.8128673246376009, "lm_q1q2_score": 0.6909137893974114}} {"text": "*DECK CTRCO\n SUBROUTINE CTRCO (T, LDT, N, RCOND, Z, JOB)\nC***BEGIN PROLOGUE CTRCO\nC***PURPOSE Estimate the condition number of a triangular matrix.\nC***LIBRARY SLATEC (LINPACK)\nC***CATEGORY D2C3\nC***TYPE COMPLEX (STRCO-S, DTRCO-D, CTRCO-C)\nC***KEYWORDS CONDITION NUMBER, LINEAR ALGEBRA, LINPACK,\nC TRIANGULAR MATRIX\nC***AUTHOR Moler, C. B., (U. of New Mexico)\nC***DESCRIPTION\nC\nC CTRCO estimates the condition of a complex triangular matrix.\nC\nC On Entry\nC\nC T COMPLEX(LDT,N)\nC T contains the triangular matrix. The zero\nC elements of the matrix are not referenced, and\nC the corresponding elements of the array can be\nC used to store other information.\nC\nC LDT INTEGER\nC LDT is the leading dimension of the array T.\nC\nC N INTEGER\nC N is the order of the system.\nC\nC JOB INTEGER\nC = 0 T is lower triangular.\nC = nonzero T is upper triangular.\nC\nC On Return\nC\nC RCOND REAL\nC an estimate of the reciprocal condition of T .\nC For the system T*X = B , relative perturbations\nC in T and B of size EPSILON may cause\nC relative perturbations in X of size EPSILON/RCOND .\nC If RCOND is so small that the logical expression\nC 1.0 + RCOND .EQ. 1.0\nC is true, then T may be singular to working\nC precision. In particular, RCOND is zero if\nC exact singularity is detected or the estimate\nC underflows.\nC\nC Z COMPLEX(N)\nC a work vector whose contents are usually unimportant.\nC If T is close to a singular matrix, then Z is\nC an approximate null vector in the sense that\nC NORM(A*Z) = RCOND*NORM(A)*NORM(Z) .\nC\nC***REFERENCES J. J. Dongarra, J. R. Bunch, C. B. Moler, and G. W.\nC Stewart, LINPACK Users' Guide, SIAM, 1979.\nC***ROUTINES CALLED CAXPY, CSSCAL, SCASUM\nC***REVISION HISTORY (YYMMDD)\nC 780814 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890831 Modified array declarations. (WRB)\nC 890831 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900326 Removed duplicate information from DESCRIPTION section.\nC (WRB)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE CTRCO\n INTEGER LDT,N,JOB\n COMPLEX T(LDT,*),Z(*)\n REAL RCOND\nC\n COMPLEX W,WK,WKM,EK\n REAL TNORM,YNORM,S,SM,SCASUM\n INTEGER I1,J,J1,J2,K,KK,L\n LOGICAL LOWER\n COMPLEX ZDUM,ZDUM1,ZDUM2,CSIGN1\n REAL CABS1\n CABS1(ZDUM) = ABS(REAL(ZDUM)) + ABS(AIMAG(ZDUM))\n CSIGN1(ZDUM1,ZDUM2) = CABS1(ZDUM1)*(ZDUM2/CABS1(ZDUM2))\nC\nC***FIRST EXECUTABLE STATEMENT CTRCO\n LOWER = JOB .EQ. 0\nC\nC COMPUTE 1-NORM OF T\nC\n TNORM = 0.0E0\n DO 10 J = 1, N\n L = J\n IF (LOWER) L = N + 1 - J\n I1 = 1\n IF (LOWER) I1 = J\n TNORM = MAX(TNORM,SCASUM(L,T(I1,J),1))\n 10 CONTINUE\nC\nC RCOND = 1/(NORM(T)*(ESTIMATE OF NORM(INVERSE(T)))) .\nC ESTIMATE = NORM(Z)/NORM(Y) WHERE T*Z = Y AND CTRANS(T)*Y = E .\nC CTRANS(T) IS THE CONJUGATE TRANSPOSE OF T .\nC THE COMPONENTS OF E ARE CHOSEN TO CAUSE MAXIMUM LOCAL\nC GROWTH IN THE ELEMENTS OF Y .\nC THE VECTORS ARE FREQUENTLY RESCALED TO AVOID OVERFLOW.\nC\nC SOLVE CTRANS(T)*Y = E\nC\n EK = (1.0E0,0.0E0)\n DO 20 J = 1, N\n Z(J) = (0.0E0,0.0E0)\n 20 CONTINUE\n DO 100 KK = 1, N\n K = KK\n IF (LOWER) K = N + 1 - KK\n IF (CABS1(Z(K)) .NE. 0.0E0) EK = CSIGN1(EK,-Z(K))\n IF (CABS1(EK-Z(K)) .LE. CABS1(T(K,K))) GO TO 30\n S = CABS1(T(K,K))/CABS1(EK-Z(K))\n CALL CSSCAL(N,S,Z,1)\n EK = CMPLX(S,0.0E0)*EK\n 30 CONTINUE\n WK = EK - Z(K)\n WKM = -EK - Z(K)\n S = CABS1(WK)\n SM = CABS1(WKM)\n IF (CABS1(T(K,K)) .EQ. 0.0E0) GO TO 40\n WK = WK/CONJG(T(K,K))\n WKM = WKM/CONJG(T(K,K))\n GO TO 50\n 40 CONTINUE\n WK = (1.0E0,0.0E0)\n WKM = (1.0E0,0.0E0)\n 50 CONTINUE\n IF (KK .EQ. N) GO TO 90\n J1 = K + 1\n IF (LOWER) J1 = 1\n J2 = N\n IF (LOWER) J2 = K - 1\n DO 60 J = J1, J2\n SM = SM + CABS1(Z(J)+WKM*CONJG(T(K,J)))\n Z(J) = Z(J) + WK*CONJG(T(K,J))\n S = S + CABS1(Z(J))\n 60 CONTINUE\n IF (S .GE. SM) GO TO 80\n W = WKM - WK\n WK = WKM\n DO 70 J = J1, J2\n Z(J) = Z(J) + W*CONJG(T(K,J))\n 70 CONTINUE\n 80 CONTINUE\n 90 CONTINUE\n Z(K) = WK\n 100 CONTINUE\n S = 1.0E0/SCASUM(N,Z,1)\n CALL CSSCAL(N,S,Z,1)\nC\n YNORM = 1.0E0\nC\nC SOLVE T*Z = Y\nC\n DO 130 KK = 1, N\n K = N + 1 - KK\n IF (LOWER) K = KK\n IF (CABS1(Z(K)) .LE. CABS1(T(K,K))) GO TO 110\n S = CABS1(T(K,K))/CABS1(Z(K))\n CALL CSSCAL(N,S,Z,1)\n YNORM = S*YNORM\n 110 CONTINUE\n IF (CABS1(T(K,K)) .NE. 0.0E0) Z(K) = Z(K)/T(K,K)\n IF (CABS1(T(K,K)) .EQ. 0.0E0) Z(K) = (1.0E0,0.0E0)\n I1 = 1\n IF (LOWER) I1 = K + 1\n IF (KK .GE. N) GO TO 120\n W = -Z(K)\n CALL CAXPY(N-KK,W,T(I1,K),1,Z(I1),1)\n 120 CONTINUE\n 130 CONTINUE\nC MAKE ZNORM = 1.0\n S = 1.0E0/SCASUM(N,Z,1)\n CALL CSSCAL(N,S,Z,1)\n YNORM = S*YNORM\nC\n IF (TNORM .NE. 0.0E0) RCOND = YNORM/TNORM\n IF (TNORM .EQ. 0.0E0) RCOND = 0.0E0\n RETURN\n END\n", "meta": {"hexsha": "82474fd4aa9b10430138d099b1b83626fcd44863", "size": 5824, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/ctrco.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/ctrco.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/ctrco.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.3555555556, "max_line_length": 71, "alphanum_fraction": 0.5178571429, "num_tokens": 2102, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711604559848, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.690913775512537}} {"text": "Real Function fd1(dmass, aj, al, width, widb0, srt)\n Save\n amn = 0.938\n amp = 0.138\n amd = amn\n ak02 = 0.25*(dmass**2-amd**2-amp**2)**2 - (amp*amd)**2\n If (ak02>0.) Then\n q0 = sqrt(ak02/dmass)\n Else\n q0 = 0.0\n fd1 = 0\n Return\n End If\n ak2 = 0.25*(srt**2-amd**2-amp**2)**2 - (amp*amd)**2\n If (ak2>0.) Then\n q = sqrt(ak2/dmass)\n Else\n q = 0.00\n fd1 = 0\n Return\n End If\n b = widb0*1.2*dmass/srt*(q/q0)**(2.*al+1)/(1.+0.2*(q/q0)**(2*al))\n fd1 = (2.*aj+1)*width**2*b/((srt-dmass)**2+0.25*width**2)/(2.*q**2)\n Return\nEnd Function fd1\n", "meta": {"hexsha": "79b03c7421f9c0e0f68dce48fa13eae2000025cd", "size": 567, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fd1.f90", "max_stars_repo_name": "xiaohaijin/AMPT", "max_stars_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-12-24T19:37:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-14T12:58:59.000Z", "max_issues_repo_path": "src/fd1.f90", "max_issues_repo_name": "xiaohaijin/AMPT", "max_issues_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_issues_repo_licenses": ["MIT"], "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/fd1.f90", "max_forks_repo_name": "xiaohaijin/AMPT", "max_forks_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_forks_repo_licenses": ["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.8076923077, "max_line_length": 69, "alphanum_fraction": 0.5255731922, "num_tokens": 287, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308147331957, "lm_q2_score": 0.7401743735019595, "lm_q1q2_score": 0.6909015685025667}} {"text": "C\nC $Id: mdpgci.f,v 1.8 2008-09-18 00:42:17 kennison Exp $\nC\nC Copyright (C) 2000\nC University Corporation for Atmospheric Research\nC All Rights Reserved\nC\nC The use of this Software is governed by a License Agreement.\nC\n SUBROUTINE MDPGCI (ALAT,ALON,BLAT,BLON,NOPI,RLTI,RLNI)\nC\n INTEGER NOPI\n DOUBLE PRECISION ALAT,ALON,BLAT,BLON,RLTI(*),RLNI(*)\nC\nC Declare common block containing math constants.\nC\n COMMON /MAPCM0/ COS1,DTOR,DTRH,OOPI,PI,PIOF,PIOT,RTDD,RTOD,\n + SROT,SIN1,TOPI,TSRT\n DOUBLE PRECISION COS1,DTOR,DTRH,OOPI,PI,PIOF,PIOT,RTDD,RTOD,\n + SROT,SIN1,TOPI,TSRT\n SAVE /MAPCM0/\nC\nC This routine, given the latitudes and longitudes of two points A and\nC B on the surface of the globe, interpolates NOPI points along the\nC great circle route joining A to B and returns the latitudes and\nC longitudes of the interpolated points in the arrays RLTI and RLNI.\nC\nC Rotations about a given axis are used extensively below. Assume a\nC right-handed system with U, V, and W axes. Rotating by an angle \"a\"\nC about the U axis maps the point (u,v,w) into the point (u',v',w'),\nC where\nC\nC u' = u\nC v' = v cos(a) - w sin(a)\nC w' = w cos(a) + v sin(a)\nC\nC A positive value of \"a\" represents rotation in the direction from the\nC V axis to the W axis.\nC\nC Similarly, rotating by an angle \"a\" about the V axis maps the point\nC (u,v,w) into the point (u',v',w'), where\nC\nC u' = u cos(a) + w sin(a)\nC v' = v\nC w' = w cos(a) - u sin(a)\nC\nC A positive value of \"a\" represents rotation in the direction from the\nC W axis to the U axis.\nC\nC Rotating by an angle \"a\" about the W axis maps the point (u,v,w) into\nC the point (u',v',w'), where\nC\nC u' = u cos(a) - v sin(a)\nC v' = v cos(a) + u sin(a)\nC w' = w\nC\nC A positive value of \"a\" represents rotation in the direction from the\nC U axis to the V axis.\nC\nC Declare local variables.\nC\n INTEGER IOPI\nC\n DOUBLE PRECISION ALPH,BETA,CALN,CALP,CALT,CBLN,CBLT,GAMA,SALN,\n + SALP,SALT,SBLN,SBLT,UCPA,UCPB,UCPD,UCPF,UCPG,\n + UCPH,UCPO,UCPP,UCPQ,VCPA,VCPB,VCPD,VCPF,VCPG,\n + VCPH,VCPO,VCPP,VCPQ,WCPA,WCPB,WCPD,WCPF,WCPG,\n + WCPH,WCPO,WCPP,WCPQ\nC\nC Check for an uncleared prior error.\nC\n IF (ICFELL('MDPGCI - UNCLEARED PRIOR ERROR',1).NE.0) RETURN\nC\nC Compute the U, V, and W coordinates (on a unit sphere) of the points\nC A and B.\nC\n CALT=COS(ALAT*DTOR)\n SALT=SIN(ALAT*DTOR)\n CALN=COS(ALON*DTOR)\n SALN=SIN(ALON*DTOR)\nC\n CBLT=COS(BLAT*DTOR)\n SBLT=SIN(BLAT*DTOR)\n CBLN=COS(BLON*DTOR)\n SBLN=SIN(BLON*DTOR)\nC\n UCPA=CALT*CALN\n VCPA=CALT*SALN\n WCPA=SALT\nC\n UCPB=CBLT*CBLN\n VCPB=CBLT*SBLN\n WCPB=SBLT\nC\nC Rotating the points about the W axis by the angle -ALON carries point\nC A into point C, in the UW plane. It carries point B into point D.\nC\nC CDLN=COS((BLON-ALON)*DTOR)\nC SDLN=SIN((BLON-ALON)*DTOR)\nC\nC UCPC=CALT\nC VCPC=0.D0\nC WCPC=SALT\nC\n UCPD=UCPB*CALN+VCPB*SALN\n VCPD=VCPB*CALN-UCPB*SALN\n WCPD=WCPB\nC\nC UCPD=CBLT*CDLN\nC VCPD=CBLT*SDLN\nC WCPD=SBLT\nC\nC Rotating the points about the V axis by the angle ALAT carries point\nC C into point E, on the U axis. It carries point D into point F.\nC\nC UCPE=1.D0\nC VCPE=0.D0\nC WCPE=0.D0\nC\n UCPF=UCPD*CALT+WCPD*SALT\n VCPF=VCPD\n WCPF=WCPD*CALT-UCPD*SALT\nC\nC UCPF=CALT*CBLT*CDLN-SALT*SBLT\nC VCPF=CBLT*SDLN\nC WCPF=CALT*SBLT+SALT*CBLT*CDLN\nC\nC Rotating the points about the U axis by the angle -ATAN(WCPF/VCPF)\nC leaves the position of point E unchanged, but carries point F into\nC point G, in the UV plane.\nC\n IF (WCPF.NE.0.D0.OR.VCPF.NE.0.D0) THEN\n ALPH=ATAN2(WCPF,VCPF)\n ELSE\n ALPH=0.D0\n END IF\nC\n CALP=COS(ALPH)\n SALP=SIN(ALPH)\nC\n UCPG=UCPF\n VCPG=VCPF*CALP+WCPF*SALP\n WCPG=WCPF*CALP-VCPF*SALP\nC\nC UCPG=CALT*CBLT*CDLN-SALT*SBLT\nC VCPG=CBLT*SDLN*CALP-CALT*SBLT*SALP-SALT*CBLT*CDLN*SALP\nC WCPG=CALT*SBLT*CALP+SALT*CBLT*CDLN*CALP+CBLT*SDLN*SALP\nC\nC The angle from E to G (which is the same as the angle from A to B)\nC may now be computed easily.\nC\n IF (VCPG.NE.0.D0.OR.UCPG.NE.0.D0) THEN\n BETA=ATAN2(VCPG,UCPG)\n ELSE\n BETA=0.D0\n END IF\nC\nC Interpolate points between the points E and G and map them back to\nC the great circle route between A and B.\nC\n DO 101 IOPI=1,NOPI\n GAMA=(DBLE(IOPI)/DBLE(NOPI+1))*BETA\n UCPH=COS(GAMA)\n VCPH=SIN(GAMA)\n WCPH=0.D0\n UCPO=UCPH\n VCPO=VCPH*CALP-WCPH*SALP\n WCPO=WCPH*CALP+VCPH*SALP\n UCPP=UCPO*CALT-WCPO*SALT\n VCPP=VCPO\n WCPP=WCPO*CALT+UCPO*SALT\n UCPQ=UCPP*CALN-VCPP*SALN\n VCPQ=VCPP*CALN+UCPP*SALN\n WCPQ=WCPP\n RLTI(IOPI)=RTOD*ATAN2(WCPQ,SQRT(UCPQ*UCPQ+VCPQ*VCPQ))\n IF (VCPQ.NE.0.D0.OR.UCPQ.NE.0.D0) THEN\n RLNI(IOPI)=RTOD*ATAN2(VCPQ,UCPQ)\n ELSE\n RLNI(IOPI)=0.D0\n END IF\n 101 CONTINUE\nC\nC Done.\nC\n RETURN\nC\n END\n", "meta": {"hexsha": "c12c9c6046f0be048e0bf6d38c0def963b6078bd", "size": 5355, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ncarg2d/src/libncarg/ezmap/mdpgci.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "ncarg2d/src/libncarg/ezmap/mdpgci.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "ncarg2d/src/libncarg/ezmap/mdpgci.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 28.4840425532, "max_line_length": 71, "alphanum_fraction": 0.6089635854, "num_tokens": 2012, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308036221031, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.6909015549284886}} {"text": "! Theta-e\n!NCLFORTSTART\nSUBROUTINE DEQTHECALC(qvp, tmk, prs, eth, miy, mjx, mkzh)\n USE wrf_constants, ONLY : EPS, GAMMA, GAMMAMD, TLCLC1, TLCLC2, TLCLC3, TLCLC4, &\n THTECON1, THTECON2, THTECON3\n\n IMPLICIT NONE\n\n !f2py threadsafe\n !f2py intent(in,out) :: eth\n\n ! Input variables\n ! Sizes\n INTEGER,INTENT(IN) :: miy, mjx, mkzh\n ! Qvapor [g/kg]\n REAL(KIND=8), DIMENSION(miy,mjx,mkzh), INTENT(IN) :: qvp\n ! Temperature [K]\n REAL(KIND=8), DIMENSION(miy,mjx,mkzh), INTENT(IN) :: tmk\n ! full pressure (=P+PB) [hPa]\n REAL(KIND=8), DIMENSION(miy,mjx,mkzh), INTENT(IN) :: prs\n ! Output variable\n ! equivalent potential temperature [K]\n REAL(KIND=8), DIMENSION(miy,mjx,mkzh), INTENT(OUT) :: eth\n\n!NCLEND\n\n ! local variables\n REAL(KIND=8) :: q\n REAL(KIND=8) :: t\n REAL(KIND=8) :: p\n REAL(KIND=8) :: e\n REAL(KIND=8) :: tlcl\n INTEGER :: i, j, k\n\n !$OMP PARALLEL DO COLLAPSE(3) PRIVATE(i, j, k, q, t, p, e, tlcl) &\n !$OMP SCHEDULE(runtime)\n DO k = 1,mkzh\n DO j = 1,mjx\n DO i = 1,miy\n q = MAX(qvp(i,j,k), 1.D-15)\n t = tmk(i,j,k)\n p = prs(i,j,k)/100.\n e = q*p/(EPS + q)\n tlcl = TLCLC1/(LOG(t**TLCLC2/e) - TLCLC3) + TLCLC4\n eth(i,j,k) = tmk(i,j,k)*(1000.D0/p)**(GAMMA*(1.D0 + GAMMAMD*q))* &\n EXP((THTECON1/tlcl - THTECON2)*q*(1.D0 + THTECON3*q))\n END DO\n END DO\n END DO\n !$OMP END PARALLEL DO\n\n RETURN\n\nEND SUBROUTINE DEQTHECALC\n", "meta": {"hexsha": "65c069d40ff78bf4c2c752dc88b8ab42308919b4", "size": 1572, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ni/src/lib/nfpfort/eqthecalc.f90", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 315, "max_stars_repo_stars_event_min_datetime": "2016-12-29T17:42:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T03:57:41.000Z", "max_issues_repo_path": "ni/src/lib/nfpfort/eqthecalc.f90", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "ni/src/lib/nfpfort/eqthecalc.f90", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 112, "max_forks_repo_forks_event_min_datetime": "2016-12-29T12:56:52.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-16T08:05:49.000Z", "avg_line_length": 28.5818181818, "max_line_length": 84, "alphanum_fraction": 0.5324427481, "num_tokens": 598, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107966642556, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6908725942765974}} {"text": " FUNCTION BESSK1(X)\n REAL*8 Y,P1,P2,P3,P4,P5,P6,P7,\n * Q1,Q2,Q3,Q4,Q5,Q6,Q7\n DATA P1,P2,P3,P4,P5,P6,P7/1.0D0,0.15443144D0,-0.67278579D0,\n * -0.18156897D0,-0.1919402D-1,-0.110404D-2,-0.4686D-4/\n DATA Q1,Q2,Q3,Q4,Q5,Q6,Q7/1.25331414D0,0.23498619D0,-0.3655620D-1,\n * 0.1504268D-1,-0.780353D-2,0.325614D-2,-0.68245D-3/\n IF (X.LE.2.0) THEN\n Y=X*X/4.0\n BESSK1=(LOG(X/2.0)*BESSI1(X))+(1.0/X)*(P1+Y*(P2+\n * Y*(P3+Y*(P4+Y*(P5+Y*(P6+Y*P7))))))\n ELSE\n Y=2.0/X\n BESSK1=(EXP(-X)/SQRT(X))*(Q1+Y*(Q2+Y*(Q3+\n * Y*(Q4+Y*(Q5+Y*(Q6+Y*Q7))))))\n ENDIF\n RETURN\n END\r", "meta": {"hexsha": "83a996cecda5e9e14852e7c4778ff115b9b0ad5f", "size": 656, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "Math3/NumRec/source/bessk1.for", "max_stars_repo_name": "domijin/MM3", "max_stars_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Math3/NumRec/source/bessk1.for", "max_issues_repo_name": "domijin/MM3", "max_issues_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Math3/NumRec/source/bessk1.for", "max_forks_repo_name": "domijin/MM3", "max_forks_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.4444444444, "max_line_length": 72, "alphanum_fraction": 0.5045731707, "num_tokens": 356, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107914029486, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.690872590398182}} {"text": "c from SHOOTGRO\nc *********************************************************************\nc * *\nc * F U N C T I O N D A Y L T H *\nc * dmh 1/22/93 *\nc *********************************************************************\nc This function uses latitude and day of year to calculate \nc day length (in hours) using code extracted from the WGEN model\nc (Richardson, C.W. andD.A. Wright. 1984. WGEN: A model for generating\nc daily weather variables. USDA-ARS, ARS-8. 83 pp.). Day length on\nc consecutive days is used to calculate the change in day length, which\nc subroutine PHYLLO uses to calculate the phyllochron for each seedling \nc cohort. \n\nc INPUTS: lat(R)\nc dummy argument--stday(R)\n\nc OUTPUTS: function value--DAYLTH(C)\n\nc include 'shtgro.inc'\n\n subroutine daylenth(daylth, daynum, latitude)\n \n implicit none\n\n integer daynum, stday\n real ch, daylth, halfdy, latitude, latrad, sd\n \n stday = daynum\n\nc Change latitude in degrees (LAT) to radians (LATRAD).\n\n latrad = latitude * 6.2832 / 360.\n\nc Calculate SD, the angle (in radians) of declination of the sun \nc the angular distance of the sun north(+) or south(-) of the equator\nc on the day of year. STDAY is the julian date (day of year).\n\n sd = 0.4102 * SIN(0.0172 * (REAL(stday) - 80.25))\n\nc Calculate cos h (=CH) of the half-day length in radians.\n\n ch = -TAN(latrad) * TAN(sd)\n if(ch.gt.1.0) ch = 1.0\n if(ch.lt.-1.0) ch = -1.0\n\nc Calculate half-day length in radians.\n\n halfdy = ACOS(ch)\n\nc Calculate day length in hours.\n\n daylth = halfdy * 7.6394\n\n return\n end", "meta": {"hexsha": "60fb8d753a471675a17066f4b60e00be0faea407", "size": 1796, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "PhenologyMMS/daylenth.for", "max_stars_repo_name": "USDA-ARS-WMSRU/phenologymms-science", "max_stars_repo_head_hexsha": "e753a303f47ac6602d492d02399343dfe670b696", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "PhenologyMMS/daylenth.for", "max_issues_repo_name": "USDA-ARS-WMSRU/phenologymms-science", "max_issues_repo_head_hexsha": "e753a303f47ac6602d492d02399343dfe670b696", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "PhenologyMMS/daylenth.for", "max_forks_repo_name": "USDA-ARS-WMSRU/phenologymms-science", "max_forks_repo_head_hexsha": "e753a303f47ac6602d492d02399343dfe670b696", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.0714285714, "max_line_length": 73, "alphanum_fraction": 0.539532294, "num_tokens": 492, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107896491796, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6908725891053769}} {"text": " FUNCTION bessi1(x)\r\n REAL bessi1,x\r\n REAL ax\r\n DOUBLE PRECISION p1,p2,p3,p4,p5,p6,p7,q1,q2,q3,q4,q5,q6,q7,q8,q9,y\r\n SAVE p1,p2,p3,p4,p5,p6,p7,q1,q2,q3,q4,q5,q6,q7,q8,q9\r\n DATA p1,p2,p3,p4,p5,p6,p7/0.5d0,0.87890594d0,0.51498869d0,\r\n *0.15084934d0,0.2658733d-1,0.301532d-2,0.32411d-3/\r\n DATA q1,q2,q3,q4,q5,q6,q7,q8,q9/0.39894228d0,-0.3988024d-1,\r\n *-0.362018d-2,0.163801d-2,-0.1031555d-1,0.2282967d-1,-0.2895312d-1,\r\n *0.1787654d-1,-0.420059d-2/\r\n if (abs(x).lt.3.75) then\r\n y=(x/3.75)**2\r\n bessi1=x*(p1+y*(p2+y*(p3+y*(p4+y*(p5+y*(p6+y*p7))))))\r\n else\r\n ax=abs(x)\r\n y=3.75/ax\r\n bessi1=(exp(ax)/sqrt(ax))*(q1+y*(q2+y*(q3+y*(q4+y*(q5+y*(q6+y*\r\n *(q7+y*(q8+y*q9))))))))\r\n if(x.lt.0.)bessi1=-bessi1\r\n endif\r\n return\r\n END\r\n", "meta": {"hexsha": "190f38c2961da64bb8ea61aa2410ff3284156a8d", "size": 837, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/bessi1.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/bessi1.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/bessi1.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.3913043478, "max_line_length": 73, "alphanum_fraction": 0.5340501792, "num_tokens": 423, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107949104866, "lm_q2_score": 0.7371581568543043, "lm_q1q2_score": 0.6908725821601718}} {"text": "module chinese_remainder_theorem\n use, intrinsic :: iso_fortran_env\n use internal\n implicit none\n integer, private, parameter :: intkind = int64\ncontains\n function crt(remainders, moduli) result(res)\n integer(intkind), intent(in) :: remainders(:), moduli(:)\n integer(intkind) :: res(2), r0, m0, r1, m1, g, im, tmp(2), u, x\n integer(int32) :: i\n res = 0\n r0 = 0\n m0 = 1\n do i = 1, size(remainders)\n r1 = modulo(remainders(i), moduli(i))\n m1 = moduli(i)\n if (m0 < m1) then\n call swap(r0, r1)\n call swap(m0, m1)\n end if\n if (mod(m0, m1) == 0) then\n if (mod(r0, m1) /= r1) return\n cycle\n end if\n tmp = inv_gcd(m0, m1)\n g = tmp(1)\n im = tmp(2)\n u = m1 / g\n if (mod(r1 - r0, g) /= 0) return\n x = mod(mod((r1 - r0) / g, u) * im, u)\n r0 = r0 + x * m0\n m0 = m0 * u\n if (r0 < 0) r0 = r0 + m0\n end do\n res = (/r0, m0/)\n end\nend module chinese_remainder_theorem", "meta": {"hexsha": "f894b429d97038484c30bba20101150e343c2f62", "size": 985, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "atcoder/chinese_remainder_theorem.f08", "max_stars_repo_name": "ue1221/ac-library-fortran", "max_stars_repo_head_hexsha": "669e32256a1de30edc32cfc6420b6cab78a62fb4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "atcoder/chinese_remainder_theorem.f08", "max_issues_repo_name": "ue1221/ac-library-fortran", "max_issues_repo_head_hexsha": "669e32256a1de30edc32cfc6420b6cab78a62fb4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "atcoder/chinese_remainder_theorem.f08", "max_forks_repo_name": "ue1221/ac-library-fortran", "max_forks_repo_head_hexsha": "669e32256a1de30edc32cfc6420b6cab78a62fb4", "max_forks_repo_licenses": ["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.6216216216, "max_line_length": 67, "alphanum_fraction": 0.530964467, "num_tokens": 376, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947086083138, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6908464884880695}} {"text": "module setup_mod\n\n use config_mod\n\ncontains\n\nsubroutine setup_init(mesh)\n\n use mesh_mod, only: mesh_t\n use mesh_mod, only: mesh_iterate_cells\n\n type(mesh_t), intent(inout) :: mesh\n\n call mesh_iterate_cells(mesh,setup_init_cb)\n\nend subroutine\n\nsubroutine setup_init_cb(cell)\n\n use equations_mod\n use mesh_mod, only: cell_t\n use mesh_mod, only: cell_get_coords\n\n type(cell_t), intent(inout) :: cell\n\n real(dp) :: dens(N_NODES,N_NODES)\n real(dp) :: velx(N_NODES,N_NODES)\n real(dp) :: vely(N_NODES,N_NODES)\n real(dp) :: pres(N_NODES,N_NODES)\n\n real(dp) :: momx(N_NODES,N_NODES)\n real(dp) :: momy(N_NODES,N_NODES)\n real(dp) :: ener(N_NODES,N_NODES)\n\n real(dp) :: coords(N_NODES,N_NODES,N_DIMS)\n\n coords = cell_get_coords(cell)\n\n dens = dens0\n velx = velx0\n vely = vely0\n pres = pres0\n\n momx = dens * velx\n momy = dens * vely\n ener = pres/(kappa-1) + 0.5*dens*(velx**2 + vely**2)\n\n ener = ener + blast_ener/(2*pi*blast_sigm**2) * exp(-0.5*(coords(:,:,1)**2 + coords(:,:,2)**2)/blast_sigm**2)\n\n cell%state(:,:,DENS_VAR) = dens\n cell%state(:,:,MOMX_VAR) = momx\n cell%state(:,:,MOMY_VAR) = momy\n cell%state(:,:,ENER_VAR) = ener\n\nend subroutine\n\nend module\n", "meta": {"hexsha": "08da94320b3acbf1125f867b4cba5954b5b3f514", "size": 1237, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/setups/sedov-blast/setup_mod.f90", "max_stars_repo_name": "jmark/nemo2d", "max_stars_repo_head_hexsha": "a508f192d0f6da49e485ee9c8d1c049dbb81d033", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source/setups/sedov-blast/setup_mod.f90", "max_issues_repo_name": "jmark/nemo2d", "max_issues_repo_head_hexsha": "a508f192d0f6da49e485ee9c8d1c049dbb81d033", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/setups/sedov-blast/setup_mod.f90", "max_forks_repo_name": "jmark/nemo2d", "max_forks_repo_head_hexsha": "a508f192d0f6da49e485ee9c8d1c049dbb81d033", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.3275862069, "max_line_length": 113, "alphanum_fraction": 0.6426839127, "num_tokens": 388, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853654, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.69083208679499}} {"text": "module KEPLER\n! Description:\n! Root-finding procedures for the Kepler equation.\n! \n! Author:\n! Davide Amato\n! Space Dynamics Group - Technical University of Madrid\n! davideamato@email.arizona.edu\n!\n! ==============================================================================\n\nuse KINDS, only: dk\nimplicit none\n\n\ncontains\n\nfunction KESOLVE(ecc,M,tol)\n! Solves the Kepler equation to the desired tolerance using the regula falsi\n! method.\n\n! VARIABLES\nimplicit none\n! Arguments\nreal(dk),intent(in) :: ecc,M,tol\n!logical,intent(out),optional :: flag\n! Function def\nreal(dk) :: KESOLVE\n\n! Locals\nreal(dk) :: zero\nreal(dk) :: sinM\nreal(dk) :: K0,K1,M1\ninteger :: it\nreal(dk) :: Enext,Knext,Ecurr,Kcurr,Eprev,Kprev\n\n! ==============================================================================\n\n!if (present(flag)) flag = .false.\n\nzero = epsilon(0._dk)\nsinM = sin(M)\nif (abs(sinM) <= zero .or. ecc <= zero) then\n KESOLVE = M\n return\nend if\n\n! Plant seeds for the regula falsi\nK0 = KEPEQ(ecc,M,M)\nM1 = M + sinM/abs(sinM)*ecc\nK1 = KEPEQ(ecc,M1,M)\n\nKprev = K0; Eprev = M\nKcurr = K1; Ecurr = M1\n\nit = 0\ndo\n \n Enext = (Ecurr*Kprev - Eprev*Kcurr)/(Kprev - Kcurr)\n Knext = KEPEQ(ecc,Enext,M)\n \n ! Update Kprev, Eprev if the sign changed\n if (Knext*Kprev > 0._dk) then\n Eprev = Ecurr\n Kprev = Kcurr\n end if\n \n Ecurr = Enext; Kcurr = Knext\n \n it = it + 1\n \n if (abs(Kcurr) <= tol) then\n KESOLVE = Ecurr\n return\n end if\n \n if (it > 100) then\n KESOLVE = Ecurr\n write(*,*) 'KESOLVE did not converge.'\n write(*,*) 'Kcurr = ',Kcurr\n! if (present(flag)) flag = .true.\n return\n end if\n\nend do\n\nend function KESOLVE\n\nfunction KEPEQ(ecc,E,M)\n\n! VARIABLES\nimplicit none\nreal(dk),intent(in) :: ecc,E,M\nreal(dk) :: KEPEQ\n\nKEPEQ = E - ecc*sin(E) - M\n\nend function KEPEQ\n\n\nend module KEPLER\n", "meta": {"hexsha": "af902010708bfba8f7c3bb87377e6157bbbdc051", "size": 1934, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "thalassa-master/thalassa_dir/kepler.f90", "max_stars_repo_name": "isaiasAaraya/TLEanalysis", "max_stars_repo_head_hexsha": "104b6f4fd6da4f78c88c1cf3acc255c3794f5180", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "thalassa-master/thalassa_dir/kepler.f90", "max_issues_repo_name": "isaiasAaraya/TLEanalysis", "max_issues_repo_head_hexsha": "104b6f4fd6da4f78c88c1cf3acc255c3794f5180", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "thalassa-master/thalassa_dir/kepler.f90", "max_forks_repo_name": "isaiasAaraya/TLEanalysis", "max_forks_repo_head_hexsha": "104b6f4fd6da4f78c88c1cf3acc255c3794f5180", "max_forks_repo_licenses": ["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.9607843137, "max_line_length": 80, "alphanum_fraction": 0.5599793175, "num_tokens": 618, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587817066391, "lm_q2_score": 0.7772998663336157, "lm_q1q2_score": 0.6908320822233978}} {"text": " Program dgesdd_example\n\n! DGESDD Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_example_aux, Only: nagf_file_print_matrix_real_gen\n Use lapack_interfaces, Only: ddisna, dgesdd\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nb = 64, nin = 5, nout = 6\n! .. Local Scalars ..\n Real (Kind=dp) :: eps, serrbd\n Integer :: i, ifail, info, lda, ldu, lwork, m, n\n! .. Local Arrays ..\n Real (Kind=dp), Allocatable :: a(:, :), rcondu(:), rcondv(:), s(:), &\n u(:, :), uerrbd(:), verrbd(:), work(:)\n Real (Kind=dp) :: dummy(1, 1)\n Integer, Allocatable :: iwork(:)\n! .. Intrinsic Procedures ..\n Intrinsic :: epsilon, max, min, nint\n! .. Executable Statements ..\n Write (nout, *) 'DGESDD Example Program Results'\n Write (nout, *)\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) m, n\n lda = m\n ldu = m\n Allocate (a(lda,n), rcondu(m), rcondv(m), s(m), u(ldu,m), uerrbd(m), &\n verrbd(m), iwork(8*min(m,n)))\n\n! Use routine workspace query to get optimal workspace.\n lwork = -1\n Call dgesdd('Overwrite A by tranpose(V)', m, n, a, lda, s, u, ldu, &\n dummy, 1, dummy, lwork, iwork, info)\n\n! Make sure that there is enough workspace for block size nb.\n lwork = max((5*m+9)*m+n+nb*(m+n), nint(dummy(1,1)))\n Allocate (work(lwork))\n\n! Read the m by n matrix A from data file\n\n Read (nin, *)(a(i,1:n), i=1, m)\n\n! Compute the singular values and left and right singular vectors\n! of A (A = U*S*(V**T), m.le.n)\n\n Call dgesdd('Overwrite A by tranpose(V)', m, n, a, lda, s, u, ldu, &\n dummy, 1, work, lwork, iwork, info)\n\n If (info==0) Then\n\n! Print solution\n\n Write (nout, *) 'Singular values'\n Write (nout, 100) s(1:m)\n Flush (nout)\n\n! Normalize so that u(1,j)>=0\n Do i = 1, m\n If (u(1,i)<0.0_dp) Then\n u(1:m, i) = -u(1:m, i)\n a(i, 1:n) = -a(i, 1:n)\n End If\n End Do\n! ifail: behaviour on error exit\n! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft\n ifail = 0\n Call nagf_file_print_matrix_real_gen('General', ' ', m, m, u, ldu, &\n 'Left singular vectors', ifail)\n\n Write (nout, *)\n Flush (nout)\n\n Call nagf_file_print_matrix_real_gen('General', ' ', m, n, a, lda, &\n 'Right singular vectors by row '//'(first m rows of V**T)', ifail)\n\n! Get the machine precision, EPS and compute the approximate\n! error bound for the computed singular values. Note that for\n! the 2-norm, S(1) = norm(A)\n\n eps = epsilon(1.0E0_dp)\n serrbd = eps*s(1)\n\n! Call DDISNA to estimate reciprocal condition\n! numbers for the singular vectors\n\n Call ddisna('Left', m, n, s, rcondu, info)\n Call ddisna('Right', m, n, s, rcondv, info)\n\n! Compute the error estimates for the singular vectors\n\n Do i = 1, m\n uerrbd(i) = serrbd/rcondu(i)\n verrbd(i) = serrbd/rcondv(i)\n End Do\n\n! Print the approximate error bounds for the singular values\n! and vectors\n\n Write (nout, *)\n Write (nout, *) 'Error estimate for the singular values'\n Write (nout, 110) serrbd\n Write (nout, *)\n Write (nout, *) 'Error estimates for the left singular vectors'\n Write (nout, 110) uerrbd(1:m)\n Write (nout, *)\n Write (nout, *) 'Error estimates for the right singular vectors'\n Write (nout, 110) verrbd(1:m)\n Else\n Write (nout, 120) 'Failure in DGESDD. INFO =', info\n End If\n\n100 Format (3X, (8F8.4))\n110 Format (4X, 1P, 6E11.1)\n120 Format (1X, A, I4)\n End Program\n", "meta": {"hexsha": "430c0b8938fd3e945ee96ecb96e0422fdefb6674", "size": 4025, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/dgesdd_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/dgesdd_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/dgesdd_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 32.4596774194, "max_line_length": 90, "alphanum_fraction": 0.5639751553, "num_tokens": 1252, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587846530937, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6908320753435973}} {"text": " SUBROUTINE MB02GD( TYPET, TRIU, K, N, NL, P, S, T, LDT, RB, LDRB,\n $ DWORK, LDWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute the Cholesky factor of a banded symmetric positive\nC definite (s.p.d.) block Toeplitz matrix, defined by either its\nC first block row, or its first block column, depending on the\nC routine parameter TYPET.\nC\nC By subsequent calls of this routine the Cholesky factor can be\nC computed block column by block column.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC TYPET CHARACTER*1\nC Specifies the type of T, as follows:\nC = 'R': T contains the first block row of an s.p.d. block\nC Toeplitz matrix; the Cholesky factor is upper\nC triangular;\nC = 'C': T contains the first block column of an s.p.d.\nC block Toeplitz matrix; the Cholesky factor is\nC lower triangular. This choice results in a column\nC oriented algorithm which is usually faster.\nC Note: in the sequel, the notation x / y means that\nC x corresponds to TYPET = 'R' and y corresponds to\nC TYPET = 'C'.\nC\nC TRIU CHARACTER*1\nC Specifies the structure of the last block in T, as\nC follows:\nC = 'N': the last block has no special structure;\nC = 'T': the last block is lower / upper triangular.\nC\nC Input/Output Parameters\nC\nC K (input) INTEGER\nC The number of rows / columns in T, which should be equal\nC to the blocksize. K >= 0.\nC\nC N (input) INTEGER\nC The number of blocks in T. N >= 1.\nC If TRIU = 'N', N >= 1;\nC if TRIU = 'T', N >= 2.\nC\nC NL (input) INTEGER\nC The lower block bandwidth, i.e., NL + 1 is the number of\nC nonzero blocks in the first block column of the block\nC Toeplitz matrix.\nC If TRIU = 'N', 0 <= NL < N;\nC if TRIU = 'T', 1 <= NL < N.\nC\nC P (input) INTEGER\nC The number of previously computed block rows / columns of\nC the Cholesky factor. 0 <= P <= N.\nC\nC S (input) INTEGER\nC The number of block rows / columns of the Cholesky factor\nC to compute. 0 <= S <= N - P.\nC\nC T (input/output) DOUBLE PRECISION array, dimension\nC (LDT,(NL+1)*K) / (LDT,K)\nC On entry, if P = 0, the leading K-by-(NL+1)*K /\nC (NL+1)*K-by-K part of this array must contain the first\nC block row / column of an s.p.d. block Toeplitz matrix.\nC On entry, if P > 0, the leading K-by-(NL+1)*K /\nC (NL+1)*K-by-K part of this array must contain the P-th\nC block row / column of the Cholesky factor.\nC On exit, if INFO = 0, then the leading K-by-(NL+1)*K /\nC (NL+1)*K-by-K part of this array contains the (P+S)-th\nC block row / column of the Cholesky factor.\nC\nC LDT INTEGER\nC The leading dimension of the array T.\nC LDT >= MAX(1,K) / MAX(1,(NL+1)*K).\nC\nC RB (input/output) DOUBLE PRECISION array, dimension\nC (LDRB,MIN(P+NL+S,N)*K) / (LDRB,MIN(P+S,N)*K)\nC On entry, if TYPET = 'R' and TRIU = 'N' and P > 0,\nC the leading (NL+1)*K-by-MIN(NL,N-P)*K part of this array\nC must contain the (P*K+1)-st to ((P+NL)*K)-th columns\nC of the upper Cholesky factor in banded format from a\nC previous call of this routine.\nC On entry, if TYPET = 'R' and TRIU = 'T' and P > 0,\nC the leading (NL*K+1)-by-MIN(NL,N-P)*K part of this array\nC must contain the (P*K+1)-st to (MIN(P+NL,N)*K)-th columns\nC of the upper Cholesky factor in banded format from a\nC previous call of this routine.\nC On exit, if TYPET = 'R' and TRIU = 'N', the leading\nC (NL+1)*K-by-MIN(NL+S,N-P)*K part of this array contains\nC the (P*K+1)-st to (MIN(P+NL+S,N)*K)-th columns of the\nC upper Cholesky factor in banded format.\nC On exit, if TYPET = 'R' and TRIU = 'T', the leading\nC (NL*K+1)-by-MIN(NL+S,N-P)*K part of this array contains\nC the (P*K+1)-st to (MIN(P+NL+S,N)*K)-th columns of the\nC upper Cholesky factor in banded format.\nC On exit, if TYPET = 'C' and TRIU = 'N', the leading\nC (NL+1)*K-by-MIN(S,N-P)*K part of this array contains\nC the (P*K+1)-st to (MIN(P+S,N)*K)-th columns of the lower\nC Cholesky factor in banded format.\nC On exit, if TYPET = 'C' and TRIU = 'T', the leading\nC (NL*K+1)-by-MIN(S,N-P)*K part of this array contains\nC the (P*K+1)-st to (MIN(P+S,N)*K)-th columns of the lower\nC Cholesky factor in banded format.\nC For further details regarding the band storage scheme see\nC the documentation of the LAPACK routine DPBTF2.\nC\nC LDRB INTEGER\nC The leading dimension of the array RB.\nC If TRIU = 'N', LDRB >= MAX( (NL+1)*K,1 );\nC if TRIU = 'T', LDRB >= NL*K+1.\nC\nC Workspace\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0, DWORK(1) returns the optimal\nC value of LDWORK.\nC On exit, if INFO = -13, DWORK(1) returns the minimum\nC value of LDWORK.\nC The first 1 + ( NL + 1 )*K*K elements of DWORK should be\nC preserved during successive calls of the routine.\nC\nC LDWORK INTEGER\nC The length of the array DWORK.\nC LDWORK >= 1 + ( NL + 1 )*K*K + NL*K.\nC For optimum performance LDWORK should be larger.\nC\nC If LDWORK = -1, then a workspace query is assumed;\nC the routine only calculates the optimal size of the\nC DWORK array, returns this value as the first entry of\nC the DWORK array, and no error message related to LDWORK\nC is issued by XERBLA.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value;\nC = 1: the reduction algorithm failed. The Toeplitz matrix\nC associated with T is not (numerically) positive\nC definite.\nC\nC METHOD\nC\nC Householder transformations and modified hyperbolic rotations\nC are used in the Schur algorithm [1], [2].\nC\nC REFERENCES\nC\nC [1] Kailath, T. and Sayed, A.\nC Fast Reliable Algorithms for Matrices with Structure.\nC SIAM Publications, Philadelphia, 1999.\nC\nC [2] Kressner, D. and Van Dooren, P.\nC Factorizations and linear system solvers for matrices with\nC Toeplitz structure.\nC SLICOT Working Note 2000-2, 2000.\nC\nC NUMERICAL ASPECTS\nC\nC The implemented method is numerically stable.\nC 3\nC The algorithm requires O( K *N*NL ) floating point operations.\nC\nC CONTRIBUTOR\nC\nC D. Kressner, Technical Univ. Berlin, Germany, May 2001.\nC\nC REVISIONS\nC\nC V. Sima, Research Institute for Informatics, Bucharest, June 2001,\nC Mar. 2004, Apr. 2011.\nC\nC KEYWORDS\nC\nC Elementary matrix operations, Householder transformation, matrix\nC operations, Toeplitz matrix.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, ONE\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )\nC .. Scalar Arguments ..\n CHARACTER TRIU, TYPET\n INTEGER INFO, K, LDRB, LDT, LDWORK, N, NL, P, S\nC .. Array Arguments ..\n DOUBLE PRECISION DWORK(LDWORK), RB(LDRB,*), T(LDT,*)\nC .. Local Scalars ..\n CHARACTER STRUCT\n LOGICAL ISROW, LQUERY, LTRI\n INTEGER HEAD, I, IERR, J, JJ, KK, LEN, LEN2, LENR, NB,\n $ NBMIN, PDW, POSR, PRE, RNK, SIZR, STPS, WRKMIN,\n $ WRKOPT\nC .. Local Arrays ..\n INTEGER IPVT(1)\n DOUBLE PRECISION DUM(1)\nC .. External Functions ..\n LOGICAL LSAME\n INTEGER ILAENV\n EXTERNAL ILAENV, LSAME\nC .. External Subroutines ..\n EXTERNAL DCOPY, DGELQF, DGEQRF, DLACPY, DLASET, DPOTRF,\n $ DTRSM, MB02CU, MB02CV, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC DBLE, INT, MAX, MIN, MOD\nC\nC .. Executable Statements ..\nC\nC Decode the scalar input parameters.\nC\n INFO = 0\n LTRI = LSAME( TRIU, 'T' )\n LENR = ( NL + 1 )*K\n IF ( LTRI ) THEN\n SIZR = NL*K + 1\n ELSE\n SIZR = LENR\n END IF\n ISROW = LSAME( TYPET, 'R' )\n WRKMIN = 1 + ( LENR + NL )*K\nC\nC Check the scalar input parameters.\nC\n IF ( .NOT.( ISROW .OR. LSAME( TYPET, 'C' ) ) ) THEN\n INFO = -1\n ELSE IF ( .NOT.( LTRI .OR. LSAME( TRIU, 'N' ) ) ) THEN\n INFO = -2\n ELSE IF ( K.LT.0 ) THEN\n INFO = -3\n ELSE IF ( ( LTRI .AND. N.LT.2 ) .OR.\n $ ( .NOT.LTRI .AND. N.LT.1 ) ) THEN\n INFO = -4\n ELSE IF ( NL.GE.N .OR. ( LTRI .AND. NL.LT.1 ) .OR.\n $ ( .NOT.LTRI .AND. NL.LT.0 ) ) THEN\n INFO = -5\n ELSE IF ( P.LT.0 .OR. P.GT.N ) THEN\n INFO = -6\n ELSE IF ( S.LT.0 .OR. S.GT.N-P ) THEN\n INFO = -7\n ELSE IF ( ( ISROW .AND. LDT.LT.MAX( 1, K ) ) .OR.\n $ ( .NOT.ISROW .AND. LDT.LT.MAX( 1, LENR ) ) )\n $ THEN\n INFO = -9\n ELSE IF ( ( LTRI .AND. LDRB.LT.SIZR ) .OR.\n $ ( .NOT.LTRI .AND. LDRB.LT.MAX( 1, LENR ) ) )\n $ THEN\n INFO = -11\n ELSE\n LQUERY = LDWORK.EQ.-1\n PDW = LENR*K + 1\n KK = PDW + 4*K\n IF ( ISROW ) THEN\n CALL DGEQRF( K, LENR, T, LDT, DWORK, DWORK, -1, INFO )\n ELSE\n CALL DGELQF( LENR, K, T, LDT, DWORK, DWORK, -1, INFO )\n END IF\n WRKOPT = KK + INT( DWORK(1) )\n IF ( LDWORK.LT.WRKMIN .AND. .NOT.LQUERY ) THEN\n DWORK(1) = DBLE( WRKMIN )\n INFO = -13\n END IF\n END IF\nC\nC Return if there were illegal values.\nC\n IF ( INFO.NE.0 ) THEN\n CALL XERBLA( 'MB02GD', -INFO )\n RETURN\n ELSE IF( LQUERY ) THEN\n DWORK(1) = WRKOPT\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF ( S*K.EQ.0 ) THEN\n DWORK(1) = ONE\n RETURN\n END IF\nC\nC Compute the generator if P = 0.\nC\n IF ( P.EQ.0 ) THEN\n IF ( ISROW ) THEN\n CALL DPOTRF( 'Upper', K, T, LDT, IERR )\n IF ( IERR.NE.0 ) THEN\nC\nC Error return: The matrix is not positive definite.\nC\n INFO = 1\n RETURN\n END IF\n IF ( NL.GT.0 )\n $ CALL DTRSM( 'Left', 'Upper', 'Transpose', 'NonUnit', K,\n $ NL*K, ONE, T, LDT, T(1,K+1), LDT )\nC\nC Copy the first block row to RB.\nC\n IF ( LTRI ) THEN\nC\n DO 10 I = 1, LENR - K\n CALL DCOPY( MIN( I, K ), T(1,I), 1,\n $ RB( MAX( SIZR-I+1, 1 ),I ), 1 )\n 10 CONTINUE\nC\n DO 20 I = K, 1, -1\n CALL DCOPY( I, T(K-I+1,LENR-I+1), 1,\n $ RB( 1,LENR-I+1 ), 1 )\n 20 CONTINUE\nC\n ELSE\nC\n DO 30 I = 1, LENR\n CALL DCOPY( MIN( I, K ), T(1,I), 1,\n $ RB( MAX( SIZR-I+1, 1 ),I ), 1 )\n 30 CONTINUE\nC\n END IF\nC\nC Quick return if N = 1.\nC\n IF ( N.EQ.1 ) THEN\n DWORK(1) = ONE\n RETURN\n END IF\nC\n CALL DLACPY( 'All', K, NL*K, T(1,K+1), LDT, DWORK(2), K )\n CALL DLASET( 'All', K, K, ZERO, ZERO, DWORK(NL*K*K+2), K )\n POSR = K + 1\n ELSE\n CALL DPOTRF( 'Lower', K, T, LDT, IERR )\n IF ( IERR.NE.0 ) THEN\nC\nC Error return: The matrix is not positive definite.\nC\n INFO = 1\n RETURN\n END IF\n IF ( NL.GT.0 )\n $ CALL DTRSM( 'Right', 'Lower', 'Transpose', 'NonUnit',\n $ NL*K, K, ONE, T, LDT, T(K+1,1), LDT )\nC\nC Copy the first block column to RB.\nC\n POSR = 1\n IF ( LTRI ) THEN\nC\n DO 40 I = 1, K\n CALL DCOPY( SIZR, T(I,I), 1, RB(1,POSR), 1 )\n POSR = POSR + 1\n 40 CONTINUE\nC\n ELSE\nC\n DO 50 I = 1, K\n CALL DCOPY( LENR-I+1, T(I,I), 1, RB(1,POSR), 1 )\n IF ( LENR.LT.N*K .AND. I.GT.1 ) THEN\n CALL DLASET( 'All', I-1, 1, ZERO, ZERO,\n $ RB(LENR-I+2,POSR), LDRB )\n END IF\n POSR = POSR + 1\n 50 CONTINUE\nC\n END IF\nC\nC Quick return if N = 1.\nC\n IF ( N.EQ.1 ) THEN\n DWORK(1) = ONE\n RETURN\n END IF\nC\n CALL DLACPY( 'All', NL*K, K, T(K+1,1), LDT, DWORK(2), LENR )\n CALL DLASET( 'All', K, K, ZERO, ZERO, DWORK(NL*K+2), LENR )\n END IF\n PRE = 1\n STPS = S - 1\n ELSE\n PRE = P\n STPS = S\n POSR = 1\n END IF\nC\n HEAD = MOD( ( PRE - 1 )*K, LENR )\nC\nC Determine block size for the involved block Householder\nC transformations.\nC\n NB = MIN( INT( ( LDWORK - KK )/LENR ), K )\n IF ( ISROW ) THEN\n NBMIN = MAX( 2, ILAENV( 2, 'DGEQRF', ' ', K, LENR, -1, -1 ) )\n ELSE\n NBMIN = MAX( 2, ILAENV( 2, 'DGELQF', ' ', LENR, K, -1, -1 ) )\n END IF\n IF ( NB.LT.NBMIN ) NB = 0\nC\nC Generator reduction process.\nC\n IF ( ISROW ) THEN\nC\n DO 90 I = PRE, PRE + STPS - 1\n CALL MB02CU( 'Row', K, K, K, NB, T, LDT, DUM, 1,\n $ DWORK(HEAD*K+2), K, RNK, IPVT, DWORK(PDW+1),\n $ ZERO, DWORK(PDW+4*K+1), LDWORK-PDW-4*K, IERR )\nC\n IF ( IERR.NE.0 ) THEN\nC\nC Error return: The positive definiteness is (numerically)\nC not satisfied.\nC\n INFO = 1\n RETURN\n END IF\nC\n LEN = MAX( MIN( ( N - I )*K - K, LENR - HEAD - K ), 0 )\n LEN2 = MAX( MIN( ( N - I )*K - LEN - K, HEAD ), 0 )\n IF ( LEN.EQ.( LENR-K ) ) THEN\n STRUCT = TRIU\n ELSE\n STRUCT = 'N'\n END IF\n CALL MB02CV( 'Row', STRUCT, K, LEN, K, K, NB, -1, DUM, 1,\n $ DUM, 1, DWORK(HEAD*K+2), K, T(1,K+1), LDT,\n $ DUM, 1, DWORK((HEAD+K)*K+2), K, DWORK(PDW+1),\n $ DWORK(PDW+4*K+1), LDWORK-PDW-4*K, IERR )\nC\n IF ( ( N - I )*K.GE.LENR ) THEN\n STRUCT = TRIU\n ELSE\n STRUCT = 'N'\n END IF\n CALL MB02CV( 'Row', STRUCT, K, LEN2, K, K, NB, -1, DUM, 1,\n $ DUM, 1, DWORK(HEAD*K+2), K, T(1,K+LEN+1), LDT,\n $ DUM, 1, DWORK(2), K, DWORK(PDW+1),\n $ DWORK(PDW+4*K+1), LDWORK-PDW-4*K, IERR )\nC\n CALL DLASET( 'All', K, K, ZERO, ZERO, DWORK(HEAD*K+2), K )\nC\nC Copy current block row to RB.\nC\n IF ( LTRI ) THEN\nC\n DO 60 J = 1, MIN( LEN + LEN2 + K, LENR - K )\n CALL DCOPY( MIN( J, K ), T(1,J), 1,\n $ RB(MAX( SIZR-J+1, 1 ),POSR+J-1 ), 1 )\n 60 CONTINUE\nC\n IF ( LEN+LEN2+K.GE.LENR ) THEN\nC\n DO 70 JJ = K, 1, -1\n CALL DCOPY( JJ, T(K-JJ+1,LENR-JJ+1), 1,\n $ RB(1,POSR+LENR-JJ), 1 )\n 70 CONTINUE\nC\n END IF\n POSR = POSR + K\nC\n ELSE\nC\n DO 80 J = 1, LEN + LEN2 + K\n CALL DCOPY( MIN( J, K ), T(1,J), 1,\n $ RB(MAX( SIZR-J+1, 1 ),POSR+J-1), 1 )\n IF ( J.GT.LENR-K ) THEN\n CALL DLASET( 'All', SIZR-J, 1, ZERO, ZERO,\n $ RB(1,POSR+J-1), 1 )\n END IF\n 80 CONTINUE\nC\n POSR = POSR + K\n END IF\n HEAD = MOD( HEAD + K, LENR )\n 90 CONTINUE\nC\n ELSE\nC\n DO 120 I = PRE, PRE + STPS - 1\nC\n CALL MB02CU( 'Column', K, K, K, NB, T, LDT, DUM, 1,\n $ DWORK(HEAD+2), LENR, RNK, IPVT, DWORK(PDW+1),\n $ ZERO, DWORK(PDW+4*K+1), LDWORK-PDW-4*K, IERR )\nC\n IF ( IERR.NE.0 ) THEN\nC\nC Error return: The positive definiteness is (numerically)\nC not satisfied.\nC\n INFO = 1\n RETURN\n END IF\nC\n LEN = MAX( MIN( ( N - I )*K - K, LENR - HEAD - K ), 0 )\n LEN2 = MAX( MIN( ( N - I )*K - LEN - K, HEAD ), 0 )\n IF ( LEN.EQ.( LENR-K ) ) THEN\n STRUCT = TRIU\n ELSE\n STRUCT = 'N'\n END IF\n CALL MB02CV( 'Column', STRUCT, K, LEN, K, K, NB, -1, DUM,\n $ 1, DUM, 1, DWORK(HEAD+2), LENR, T(K+1,1), LDT,\n $ DUM, 1, DWORK(HEAD+K+2), LENR, DWORK(PDW+1),\n $ DWORK(PDW+4*K+1), LDWORK-PDW-4*K, IERR )\nC\n IF ( ( N - I )*K.GE.LENR ) THEN\n STRUCT = TRIU\n ELSE\n STRUCT = 'N'\n END IF\n CALL MB02CV( 'Column', STRUCT, K, LEN2, K, K, NB, -1, DUM,\n $ 1, DUM, 1, DWORK(HEAD+2), LENR, T(K+LEN+1,1),\n $ LDT, DUM, 1, DWORK(2), LENR, DWORK(PDW+1),\n $ DWORK(PDW+4*K+1), LDWORK-PDW-4*K, IERR )\nC\n CALL DLASET( 'All', K, K, ZERO, ZERO, DWORK(HEAD+2), LENR )\nC\nC Copy current block column to RB.\nC\n IF ( LTRI ) THEN\nC\n DO 100 J = 1, K\n CALL DCOPY( MIN( SIZR, (N-I)*K-J+1 ), T(J,J), 1,\n $ RB(1,POSR), 1 )\n POSR = POSR + 1\n 100 CONTINUE\nC\n ELSE\nC\n DO 110 J = 1, K\n CALL DCOPY( MIN( SIZR-J+1, (N-I)*K-J+1 ), T(J,J), 1,\n $ RB(1,POSR), 1 )\n IF ( LENR.LT.(N-I)*K ) THEN\n CALL DLASET( 'All', J-1, 1, ZERO, ZERO,\n $ RB(MIN( SIZR-J+1, (N-I)*K-J+1 ) + 1,\n $ POSR), LDRB )\n END IF\n POSR = POSR + 1\n 110 CONTINUE\nC\n END IF\n HEAD = MOD( HEAD + K, LENR )\n 120 CONTINUE\nC\n END IF\n DWORK(1) = DBLE( WRKOPT )\n RETURN\nC\nC *** Last line of MB02GD ***\n END\n", "meta": {"hexsha": "86746fbe6e739cf474c7570383732a26feb34a71", "size": 19287, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB02GD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB02GD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB02GD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 34.6888489209, "max_line_length": 72, "alphanum_fraction": 0.4625913828, "num_tokens": 6209, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172659321807, "lm_q2_score": 0.727975460709318, "lm_q1q2_score": 0.6907884838420056}} {"text": "subroutine MakeGravGradGridDH(cilm, lmax, gm, r0, a, f, vxx, vyy, vzz, vxy, &\n vxz, vyz, n, sampling, lmax_calc, extend, &\n exitstatus)\n!------------------------------------------------------------------------------\n!\n! Given the 4pi normalized gravitational spherical harmonic coefficients\n! CILM, this subroutine will compute 2D Driscol and Healy sampled grids of\n! the six components of the gravity \"gradient\" tensor in a local\n! north-oriented reference frame:\n!\n! (Vxx, Vxy, Vxz)\n! (Vyx, Vyy, Vyz)\n! (Vzx, Vzy, Vzz)\n! \n! where X points NORTH, Y points WEST, and Z points UPWARD. The gravitational\n! potential is defined as\n!\n! V = GM/r Sum_{l=0}^LMAX (R0/r)^l Sum_{m=-l}^l C_{lm} Y_{lm},\n!\n! Laplace's equation implies that Vxx + Vyy + Vzz = 0, and the gravity tensor\n! is symmetric. The components are calculated according to eq. 1 in\n! Petrovskaya and Vershkov (2006, J. Geod, 80, 117-127), which is based on\n! eq. 3.28 in Reed (1973, Ohio State Univ., Dept. Geod. Sci., Rep. 201,\n! Columbus, OH). Note that Reed's equations are in terms of latitude, and\n! that the Y axis points East:\n!\n! Vzz = Vrr\n! Vxx = 1/r Vr + 1/r^2 Vtt\n! Vyy = 1/r Vr + 1/r^2 /tan(t) Vt + 1/r^2 /sin(t)^2 Vpp\n! Vxy = 1/r^2 /sin(t) Vtp - cos(t)/sin(t)^2 /r^2 Vp\n! Vxz = 1/r^2 Vt - 1/r Vrt\n! Vyz = 1/r^2 /sin(t) Vp - 1/r /sin(t) Vrp\n!\n! where r, t, p stand for radius, theta, and phi, and subscripts on V denote\n! partial derivatives.\n!\n! The output grid are in units of 1/s and are cacluated on a flattened\n! ellipsoid with semi-major axis A and flattening F. To obtain units of\n! Eotvos (10^-9 s^-1), multiply by 10^9.\n!\n! When SAMPLING = 1, the output grids contain N samples in latitude from\n! 90 to -90 + interval and N samples in longitude from 0 to 360-2*interval,\n! where N=2*(LMAX+1) and interval=180/N. When SAMPLING = 2, the grids are\n! equally spaced in degrees latitude and longitude with dimension (N x 2N).\n! If the optional parameter EXTEND is set to 1, the output grids will contain\n! an extra column corresponding to 360 E and an extra row corresponding to\n! 90 S, which increases each of the dimensions of the grid by one.\n!\n! Calling Parameters\n!\n! IN\n! cilm The 4-pi normalized gravitational potential spherical\n! harmonic coefficients.\n! lmax The maximum spherical harmonic degree of the function,\n! used to determine the number of samples N.\n! GM Product of the gravitatonal constant and the planet's\n! mass.\n! r0 Reference radius of potential coefficients.\n! a The semimajor axis of the flattened ellipsoid.\n! f Flattening of the planet.\n!\n! IN, OPTIONAL\n! sampling (1) Grid is N latitudes by N longitudes (default).\n! (2) Grid is N by 2N. The higher frequencies resulting\n! from this oversampling in longitude are discarded, and\n! hence not aliased into lower frequencies.\n! lmax_calc The maximum spherical harmonic degree to evaluate\n! the coefficients up to.\n! extend If 1, return a grid that contains an additional column\n! and row corresponding to 360 E longitude and 90 S\n! latitude, respectively.\n!\n! OUT\n! Vxx x-x component of the gravity gradient tensor.\n! Vyy y-y component of the gravity gradient tensor.\n! Vzz z-z component of the gravity gradient tensor.\n! Vxy x-y component of the gravity gradient tensor.\n! Vxz x-z component of the gravity gradient tensor.\n! Vyz y-z component of the gravity gradient tensor.\n! N Number of samples in latitude. Number of samples in\n! longitude is N when sampling is 1 (default), and is\n! 2N when sampling is 2.\n!\n! OPTIONAL (OUT)\n! exitstatus If present, instead of executing a STOP when an error\n! is encountered, the variable exitstatus will be\n! returned describing the error.\n! 0 = No errors;\n! 1 = Improper dimensions of input array;\n! 2 = Improper bounds for input variable;\n! 3 = Error allocating memory;\n! 4 = File IO error.\n!\n! Notes:\n! 1. If lmax is greater than the the maximum spherical harmonic\n! degree of the input coefficients, then the coefficients will be\n! zero padded.\n! 2. Latitude is geocentric latitude.\n!\n! Copyright (c) 2005-2019, SHTOOLS\n! All rights reserved.\n!\n!------------------------------------------------------------------------------\n use FFTW3\n use ftypes\n use, intrinsic :: iso_c_binding\n\n implicit none\n\n real(dp), intent(in) :: cilm(:,:,:), gm, r0, a, f\n real(dp), intent(out) :: vxx(:,:), vyy(:,:), vzz(:,:), vxy(:,:), vxz(:,:),&\n vyz(:,:)\n integer, intent(in) :: lmax\n integer, intent(out) :: n\n integer, intent(in), optional :: sampling, lmax_calc, extend\n integer, intent(out), optional :: exitstatus\n integer :: l, m, i, l1, m1, lmax_comp, i_eq, i_s, astat(4), nlong, &\n nlat_out, nlong_out, extend_grid\n real(dp) :: grid(4*lmax+4), pi, theta, scalef, rescalem, u, p, dpl, dpl2, &\n dpl2s, pmm, sint, pm1, pm2, z, tempr, r_ex, lat, &\n prefactor(lmax), coefr0, coefrs0, coeft0, coefts0, coefp0, &\n coefps0, coefrr0, coefrrs0, coefrt0, coefrts0, coefrp0, &\n coefrps0, coeftp0, coeftps0, coefpp0, coefpps0, coeftt0, &\n coeftts0\n complex(dp) :: coef(2*lmax+3), coefr(2*lmax+3), coefrs(2*lmax+3), &\n coeft(2*lmax+3), coefts(2*lmax+3), coefp(2*lmax+3), &\n coefps(2*lmax+3), tempc, coefrr(2*lmax+3), &\n coefrrs(2*lmax+3), coefrt(2*lmax+3), coefrts(2*lmax+3), &\n coefrp(2*lmax+3), coefrps(2*lmax+3), coeftp(2*lmax+3), &\n coeftps(2*lmax+3), coefpp(2*lmax+3), coefpps(2*lmax+3), &\n coeftt(2*lmax+3), coeftts(2*lmax+3)\n type(C_PTR) :: plan\n real(dp), save, allocatable :: ff1(:,:), ff2(:,:), sqr(:)\n integer(int1), save, allocatable :: fsymsign(:,:)\n integer, save :: lmax_old = 0\n\n!$OMP threadprivate(ff1, ff2, sqr, fsymsign, lmax_old)\n\n if (present(exitstatus)) exitstatus = 0\n\n n = 2 * lmax + 2\n\n if (present(sampling)) then\n if (sampling == 1) then\n nlong = n\n else if (sampling == 2) then\n nlong = 2 * n\n else\n print*, \"Error --- MakeGravGradGridDH\"\n print*, \"Optional parameter SAMPLING must be 1 (N by N) \" // &\n \"or 2 (N by 2N).\"\n print*, \"Input value is \", sampling\n if (present(exitstatus)) then\n exitstatus = 2\n return\n else\n stop\n end if\n end if\n else\n nlong = n\n end if\n\n if (present(extend)) then\n if (extend == 0) then\n extend_grid = 0\n nlat_out = n\n nlong_out = nlong\n else if (extend == 1) then\n extend_grid = 1\n nlat_out = n + 1\n nlong_out = nlong + 1\n else\n print*, \"Error --- MakeGravGradGridDH\"\n print*, \"Optional parameter EXTEND must be 0 or 1.\"\n print*, \"Input value is \", extend\n if (present(exitstatus)) then\n exitstatus = 2\n return\n else\n stop\n end if\n end if\n else\n extend_grid = 0\n nlat_out = n\n nlong_out = nlong\n end if\n\n if (size(cilm(:,1,1)) < 2) then\n print*, \"Error --- MakeGravGradGridDH\"\n print*, \"CILM must be dimensioned as (2, *, *).\"\n print*, \"Input dimension is \", size(cilm(:,1,1)), size(cilm(1,:,1)), &\n size(cilm(1,1,:))\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n end if\n\n if (size(vxx(:,1)) < nlat_out .or. size(vxx(1,:)) < nlong_out .or. &\n size(vyy(:,1)) < nlat_out .or. size(vyy(1,:)) < nlong_out .or. &\n size(vzz(:,1)) < nlat_out .or. size(vzz(1,:)) < nlong_out .or. &\n size(vxy(:,1)) < nlat_out .or. size(vxy(1,:)) < nlong_out .or. &\n size(vxz(:,1)) < nlat_out .or. size(vxz(1,:)) < nlong_out .or. &\n size(vyz(:,1)) < nlat_out .or. size(vyz(1,:)) < nlong_out) then\n print*, \"Error --- MakeGravGradGridDH\"\n print*, \"VXX, VYY, VZZ, VXY, VXZ, and VYZ must be dimensioned \" // &\n \"as: \", nlat_out, nlong_out\n print*, \"Input dimensions are \", size(vxx(:,1)), size(vxx(1,:)), &\n size(vyy(:,1)), size(vyy(1,:)), size(vzz(:,1)), size(vzz(1,:)), &\n size(vxy(:,1)), size(vxy(1,:)), size(vxz(:,1)), size(vxz(1,:)), &\n size(vyz(:,1)), size(vyz(1,:))\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n end if\n\n if (cilm(1,1,1) /= 1.0_dp .and. f /= 0.0_dp) then\n print*, \"Warning --- MakeGravGradGridDH\"\n print*, \"The degree-0 term of the spherical harmonic coefficients is \"\n print*, \"not equal to 1. The variation in gravity resulting from \"\n print*, \"variations in radius of the flattened ellipsoid will not be \"\n print*, \"taken into account.\"\n print*, \"C00 = \", cilm(1,1,1)\n print*, \"F = \", f\n end if\n\n pi = acos(-1.0_dp)\n\n scalef = 1.0e-280_dp\n\n if (present(lmax_calc)) then\n if (lmax_calc > lmax) then\n print*, \"Error --- MakeGravGradGridDH\"\n print*, \"LMAX_CALC must be less than or equal to LMAX.\"\n print*, \"LMAX = \", lmax\n print*, \"LMAX_CALC = \", lmax_calc\n if (present(exitstatus)) then\n exitstatus = 2\n return\n else\n stop\n end if\n\n else\n lmax_comp = min(lmax, size(cilm(1,1,:))-1, size(cilm(1,:,1))-1, &\n lmax_calc)\n\n end if\n\n else\n lmax_comp = min(lmax, size(cilm(1,1,:))-1, size(cilm(1,:,1))-1)\n\n end if\n\n !--------------------------------------------------------------------------\n !\n ! Calculate recursion constants used in computing Legendre functions.\n !\n !--------------------------------------------------------------------------\n if (lmax_comp /= lmax_old) then\n\n if (allocated (sqr)) deallocate (sqr)\n if (allocated (ff1)) deallocate (ff1)\n if (allocated (ff2)) deallocate (ff2)\n if (allocated (fsymsign)) deallocate (fsymsign)\n\n allocate (sqr(2 * lmax_comp + 1), stat=astat(1))\n allocate (ff1(lmax_comp+1,lmax_comp+1), stat=astat(2))\n allocate (ff2(lmax_comp+1,lmax_comp+1), stat=astat(3))\n allocate (fsymsign(lmax_comp+1,lmax_comp+1), stat=astat(4))\n\n if (sum(astat(1:4)) /= 0) then\n print*, \"Error --- MakeGravGradGridDH\"\n print*, \"Problem allocating arrays SQR, FF1, FF2, or FSYMSIGN\", &\n astat(1), astat(2), astat(3), astat(4)\n if (present(exitstatus)) then\n exitstatus = 3\n return\n else\n stop\n end if\n\n end if\n\n !----------------------------------------------------------------------\n !\n ! Calculate signs used for symmetry of Legendre functions about\n ! equator. For the first derivative in theta, these signs are\n ! reversed.\n !\n !----------------------------------------------------------------------\n do l = 0, lmax_comp, 1\n do m = 0, l, 1\n if (mod(l-m,2) == 0) then\n fsymsign(l+1,m+1) = 1\n\n else\n fsymsign(l+1,m+1) = -1\n\n end if\n\n end do\n\n end do\n\n !----------------------------------------------------------------------\n !\n ! Precompute square roots of integers that are used several times.\n !\n !----------------------------------------------------------------------\n do l=1, 2*lmax_comp+1\n sqr(l) = sqrt(dble(l))\n end do\n\n !----------------------------------------------------------------------\n !\n ! Precompute multiplicative factors used in recursion relationships\n ! P(l,m) = x*f1(l,m)*P(l-1,m) - P(l-2,m)*f2(l,m)\n ! k = l*(l+1)/2 + m + 1\n ! Note that prefactors are not used for the case when m=l as a\n ! different recursion is used. Furthermore, for m=l-1, Plmbar(l-2,m)\n ! is assumed to be zero.\n !\n !----------------------------------------------------------------------\n if (lmax_comp /= 0) then\n ff1(2,1) = sqr(3)\n ff2(2,1) = 0.0_dp\n\n end if\n\n do l = 2, lmax_comp, 1\n ff1(l+1,1) = sqr(2*l-1) * sqr(2*l+1) / dble(l)\n ff2(l+1,1) = dble(l-1) * sqr(2*l+1) / sqr(2*l-3) / dble(l)\n\n do m = 1, l-2, 1\n ff1(l+1,m+1) = sqr(2*l+1) * sqr(2*l-1) / sqr(l+m) / sqr(l-m)\n ff2(l+1,m+1) = sqr(2*l+1) * sqr(l-m-1) * sqr(l+m-1) &\n / sqr(2*l-3) / sqr(l+m) / sqr(l-m)\n end do\n\n ff1(l+1,l) = sqr(2*l+1) * sqr(2*l-1) / sqr(l+m) / sqr(l-m)\n ff2(l+1,l) = 0.0_dp\n\n end do\n\n lmax_old = lmax_comp\n\n end if\n\n !--------------------------------------------------------------------------\n !\n ! Create generic plan for grid.\n !\n !--------------------------------------------------------------------------\n plan = fftw_plan_dft_c2r_1d(nlong, coef(1:nlong/2+1), grid(1:nlong), &\n FFTW_MEASURE)\n\n !--------------------------------------------------------------------------\n !\n ! Determine Clms one l at a time by intergrating over latitude.\n !\n !--------------------------------------------------------------------------\n i_eq = n / 2 + 1 ! Index correspondong to zero latitude\n\n ! First do equator\n\n r_ex = a\n theta = pi / 2.0_dp\n z = 0.0_dp\n u = 1.0_dp\n lat = 0.0_dp\n\n coefr(1:lmax+2) = cmplx(0.0_dp, 0.0_dp, dp)\n coefr0 = 0.0_dp\n\n coefrr(1:lmax+2) = cmplx(0.0_dp, 0.0_dp, dp)\n coefrr0 = 0.0_dp\n\n coeft(1:lmax+2) = cmplx(0.0_dp, 0.0_dp, dp)\n coeft0 = 0.0_dp\n\n coeftp(1:lmax+2) = cmplx(0.0_dp, 0.0_dp, dp)\n coeftp0 = 0.0_dp\n\n coefp(1:lmax+2) = cmplx(0.0_dp, 0.0_dp, dp)\n coefp0 = 0.0_dp\n\n coefrt(1:lmax+2) = cmplx(0.0_dp, 0.0_dp, dp)\n coefrt0 = 0.0_dp\n\n coefrp(1:lmax+2) = cmplx(0.0_dp, 0.0_dp, dp)\n coefrp0 = 0.0_dp\n\n coefpp(1:lmax+2) = cmplx(0.0_dp, 0.0_dp, dp)\n coefpp0 = 0.0_dp\n\n coeftt(1:lmax+2) = cmplx(0.0_dp, 0.0_dp, dp)\n coeftt0 = 0.0_dp\n\n pm2 = 1.0_dp\n\n tempr = -cilm(1,1,1) * pm2 ! l = 0\n coefr0 = coefr0 + tempr\n\n tempr = 2 * cilm(1,1,1) * pm2 ! l = 0\n coefrr0 = coefrr0 + tempr\n\n ! derivative in theta and phi of l=0 term is 0. No need to calculate this\n\n if (lmax_comp /= 0) then ! l = 1\n prefactor(1) = r0 / r_ex\n\n do l = 2, lmax_comp, 1\n prefactor(l) = prefactor(l-1) * r0 / r_ex\n end do\n\n pm1 = 0.0_dp\n\n dpl = ff1(2,1)\n tempr = cilm(1,2,1) * dpl * prefactor(1)\n coeft0 = coeft0 + tempr\n\n tempr = cilm(1,2,1) * dpl * (-2) * prefactor(1) ! -2 = (l+1) prefactor\n coefrt0 = coefrt0 + tempr\n\n end if\n\n do l = 2, lmax_comp, 1\n l1 = l + 1\n p = - ff2(l1,1) * pm2\n tempr = cilm(1,l1,1) * p * (-l1) * prefactor(l)\n coefr0 = coefr0 + tempr\n\n tempr = cilm(1,l1,1) * p * (l1) * (l1+1) * prefactor(l)\n coefrr0 = coefrr0 + tempr\n\n dpl = l * ( sqr(2*l+1) / sqr(2*l-1) * pm1 )\n tempr = cilm(1,l1,1) * dpl * prefactor(l)\n coeft0 = coeft0 + tempr\n\n tempr = cilm(1,l1,1) * dpl * (-l1) * prefactor(l)\n coefrt0 = coefrt0 + tempr\n\n dpl2 = -l*l1 * p\n tempr = cilm(1,l1,1) * dpl2 * prefactor(l)\n coeftt0 = coeftt0 + tempr\n\n pm2 = pm1\n pm1 = p\n\n end do\n\n pmm = sqr(2) * scalef\n\n rescalem = 1.0_dp / scalef\n\n do m = 1, lmax_comp-1, 1\n\n m1 = m + 1\n\n pmm = pmm * sqr(2*m+1) / sqr(2*m)\n pm2 = pmm\n\n tempc = cmplx(cilm(1,m1,m1), - cilm(2,m1,m1), dp) * pm2 * (-m-1) &\n * prefactor(m) ! (m,m)\n coefr(m1) = coefr(m1) + tempc\n\n tempc = cmplx(cilm(1,m1,m1), - cilm(2,m1,m1), dp) * pm2 * (m+1) &\n * (m+2) * prefactor(m) ! (m,m)\n coefrr(m1) = coefrr(m1) + tempc\n\n tempc = cmplx(cilm(2,m1,m1), cilm(1,m1,m1), dp) * pm2 &\n * prefactor(m) * m ! (m,m)\n coefp(m1) = coefp(m1) + tempc\n\n tempc = - cmplx(cilm(1,m1,m1), - cilm(2,m1,m1), dp) * pm2 &\n * prefactor(m) * m**2 ! (m,m)\n coefpp(m1) = coefpp(m1) + tempc\n\n tempc = cmplx(cilm(2,m1,m1), cilm(1,m1,m1), dp) * pm2 *(-m-1) &\n * prefactor(m) * m ! (m,m)\n coefrp(m1) = coefrp(m1) + tempc\n\n dpl2 = -(m*m1 -(m**2)) * pm2\n tempc = cmplx(cilm(1,m1,m1), - cilm(2,m1,m1), dp) * dpl2 &\n * prefactor(m) ! (m,m)\n coeftt(m1) = coeftt(m1) + tempc\n\n pm1 = 0.0_dp\n\n dpl = sqr(2*m+3) * pmm\n tempc = cmplx(cilm(1,m1+1,m1), - cilm(2,m1+1,m1), dp) * dpl &\n * prefactor(m+1) ! (m+1,m)\n coeft(m1) = coeft(m1) + tempc\n\n tempc = cmplx(cilm(1,m1+1,m1), - cilm(2,m1+1,m1), dp) * dpl * (-m-2) &\n * prefactor(m+1) ! (m+1,m)\n coefrt(m1) = coefrt(m1) + tempc\n\n tempc = cmplx(cilm(2,m1+1,m1), cilm(1,m1+1,m1), dp) * dpl &\n * prefactor(m+1) * m ! (m+1,m)\n coeftp(m1) = coeftp(m1) + tempc\n\n do l = m + 2, lmax_comp, 1\n l1 = l + 1\n p = - ff2(l1,m1) * pm2\n tempc = cmplx(cilm(1,l1,m1), - cilm(2,l1,m1), dp) * p * (-l1) &\n * prefactor(l)\n coefr(m1) = coefr(m1) + tempc\n\n tempc = cmplx(cilm(1,l1,m1), - cilm(2,l1,m1), dp) * p * (l1) &\n * (l1+1) * prefactor(l)\n coefrr(m1) = coefrr(m1) + tempc\n\n tempc = cmplx(cilm(2,l1,m1), cilm(1,l1,m1), dp) * p &\n * prefactor(l) * m\n coefp(m1) = coefp(m1) + tempc\n\n tempc = - cmplx(cilm(1,l1,m1), - cilm(2,l1,m1), dp) * p &\n * prefactor(l) * m**2\n coefpp(m1) = coefpp(m1) + tempc\n\n tempc = cmplx(cilm(2,l1,m1), cilm(1,l1,m1), dp) * p * (-l1) &\n * prefactor(l) * m\n coefrp(m1) = coefrp(m1) + tempc\n\n dpl = sqr(2*l+1) * sqr(l-m) * sqr(l+m) / sqr(2*l-1) * pm1\n tempc = cmplx(cilm(1,l1,m1), - cilm(2,l1,m1), dp) * dpl &\n * prefactor(l)\n coeft(m1) = coeft(m1) + tempc\n\n tempc = cmplx(cilm(1,l1,m1), - cilm(2,l1,m1), dp) * dpl * (-l1) &\n * prefactor(l)\n coefrt(m1) = coefrt(m1) + tempc\n\n tempc = cmplx(cilm(2,l1,m1), cilm(1,l1,m1), dp) * dpl * &\n prefactor(l) * m\n coeftp(m1) = coeftp(m1) + tempc\n\n dpl2 = - (l * l1 -(m**2) / u**2) * p\n tempc = cmplx(cilm(1,l1,m1), - cilm(2,l1,m1), dp) * dpl2 &\n * prefactor(l)\n coeftt(m1) = coeftt(m1) + tempc\n\n pm2 = pm1\n pm1 = p\n\n end do\n\n coefr(m1) = coefr(m1) * rescalem\n coefrr(m1) = coefrr(m1) * rescalem\n coeft(m1) = coeft(m1) * rescalem\n coeftt(m1) = coeftt(m1) * rescalem\n coefrt(m1) = coefrt(m1) * rescalem\n coefp(m1) = coefp(m1) * rescalem\n coefpp(m1) = coefpp(m1) * rescalem\n coeftp(m1) = coeftp(m1) * rescalem\n coefrp(m1) = coefrp(m1) * rescalem\n\n end do\n\n if (lmax_comp /= 0) then\n\n pmm = pmm * sqr(2*lmax_comp+1) / sqr(2*lmax_comp) * rescalem\n tempc = cmplx(cilm(1,lmax_comp+1,lmax_comp+1), &\n - cilm(2,lmax_comp+1,lmax_comp+1), dp) * pmm &\n * (-lmax_comp-1) * prefactor(lmax_comp)\n coefr(lmax_comp+1) = coefr(lmax_comp+1) + tempc\n\n tempc = cmplx(cilm(1,lmax_comp+1,lmax_comp+1), &\n - cilm(2,lmax_comp+1,lmax_comp+1), dp) * pmm &\n * (lmax_comp+1) * (lmax_comp+2) * prefactor(lmax_comp)\n coefrr(lmax_comp+1) = coefrr(lmax_comp+1) + tempc\n\n tempc = cmplx(cilm(2,lmax_comp+1,lmax_comp+1), &\n cilm(1,lmax_comp+1,lmax_comp+1), dp) * pmm &\n * prefactor(lmax_comp) * lmax_comp\n coefp(lmax_comp+1) = coefp(lmax_comp+1) + tempc\n\n tempc = - cmplx(cilm(1,lmax_comp+1,lmax_comp+1), &\n - cilm(2,lmax_comp+1,lmax_comp+1), dp) * pmm &\n * prefactor(lmax_comp) * lmax_comp**2\n coefpp(lmax_comp+1) = coefpp(lmax_comp+1) + tempc\n\n tempc = cmplx(cilm(2,lmax_comp+1,lmax_comp+1), &\n cilm(1,lmax_comp+1,lmax_comp+1), dp) * pmm &\n * (-lmax_comp-1) * prefactor(lmax_comp) * lmax_comp\n coefrp(lmax_comp+1) = coefrp(lmax_comp+1) + tempc\n\n dpl2 = -(lmax_comp*(lmax_comp+1)-(lmax_comp**2)) * pmm \n tempc = cmplx(cilm(1,lmax_comp+1,lmax_comp+1), &\n - cilm(2,lmax_comp+1,lmax_comp+1), dp) * dpl2 &\n * prefactor(lmax_comp)\n coeftt(lmax_comp+1) = coeftt(lmax_comp+1) + tempc\n\n end if\n\n coefr0 = coefr0 * gm / r_ex**2\n coefr(2:lmax+1) = coefr(2:lmax+1) * gm / r_ex**2\n\n coefrt0 = - coefrt0 * gm / r_ex**2\n coefrt(2:lmax+1) = - coefrt(2:lmax+1) * gm / r_ex**2\n\n coefrr0 = coefrr0 * gm / r_ex**3\n coefrr(2:lmax+1) = coefrr(2:lmax+1) * gm / r_ex**3\n\n coeft0 = - coeft0 * gm / r_ex\n coeft(2:lmax+1) = - coeft(2:lmax+1) * gm / r_ex\n\n coeftt0 = coeftt0 * gm / r_ex\n coeftt(2:lmax+1) = coeftt(2:lmax+1) * gm / r_ex\n\n coeftp0 = - coeftp0 * gm / r_ex\n coeftp(2:lmax+1) = - coeftp(2:lmax+1) * gm / r_ex\n\n coefp0 = coefp0 * gm / r_ex\n coefp(2:lmax+1) = coefp(2:lmax+1) * gm / r_ex\n\n coefpp0 = coefpp0 * gm / r_ex\n coefpp(2:lmax+1) = coefpp(2:lmax+1) * gm / r_ex\n\n coefrp0 = coefrp0 * gm / r_ex**2\n coefrp(2:lmax+1) = coefrp(2:lmax+1) * gm / r_ex**2\n\n ! Vzz = Vrr\n coef(1) = cmplx(coefrr0, 0.0_dp, dp)\n coef(2:lmax+1) = coefrr(2:lmax+1) / 2.0_dp\n\n if (present(sampling)) then\n if (sampling == 2) then\n coef(lmax+2:2*lmax+3) = cmplx(0.0_dp, 0.0_dp, dp)\n end if\n end if\n\n call fftw_execute_dft_c2r(plan, coef, grid)\n vzz(i_eq,1:nlong) = grid(1:nlong)\n\n ! Vxx = 1/r Vr + 1/r^2 Vtt\n coef(1) = cmplx(coefr0/r_ex + coeftt0/r_ex**2, 0.0_dp, dp)\n coef(2:lmax+1) = (coefr(2:lmax+1)/r_ex + coeftt(2:lmax+1)/r_ex**2 ) / 2.0_dp\n\n if (present(sampling)) then\n if (sampling == 2) then\n coef(lmax+2:2*lmax+3) = cmplx(0.0_dp, 0.0_dp, dp)\n end if\n end if\n\n call fftw_execute_dft_c2r(plan, coef, grid)\n vxx(i_eq,1:nlong) = grid(1:nlong)\n\n ! Vyy = 1/r Vr + 1/r^2 /tan(t) Vt + 1/r^2 /sin(t)^2 Vpp\n coef(1) = cmplx(coefr0/r_ex + coefpp0/(r_ex**2), 0.0_dp, dp)\n coef(2:lmax+1) = (coefr(2:lmax+1)/r_ex &\n + coefpp(2:lmax+1)/(r_ex**2) ) / 2.0_dp\n\n if (present(sampling)) then\n if (sampling == 2) then\n coef(lmax+2:2*lmax+3) = cmplx(0.0_dp, 0.0_dp, dp)\n end if\n end if\n\n call fftw_execute_dft_c2r(plan, coef, grid)\n vyy(i_eq,1:nlong) = grid(1:nlong)\n\n ! Vxy = 1/r^2 /sin(t) Vtp - cos(t)/sin(t)^2 /r^2 Vp\n coef(1) = cmplx(coeftp0/r_ex**2, 0.0_dp, dp)\n coef(2:lmax+1) = (coeftp(2:lmax+1)/r_ex**2 ) / 2.0_dp\n\n if (present(sampling)) then\n if (sampling == 2) then\n coef(lmax+2:2*lmax+3) = cmplx(0.0_dp, 0.0_dp, dp)\n end if\n end if\n\n call fftw_execute_dft_c2r(plan, coef, grid)\n vxy(i_eq,1:nlong) = grid(1:nlong)\n\n ! Vxz = 1/r^2 Vt - 1/r Vrt\n coef(1) = cmplx(coeft0/r_ex**2 - coefrt0/r_ex, 0.0_dp, dp)\n coef(2:lmax+1) = (coeft(2:lmax+1) / r_ex**2 &\n - coefrt(2:lmax+1)/r_ex ) / 2.0_dp\n\n if (present(sampling)) then\n if (sampling == 2) then\n coef(lmax+2:2*lmax+3) = cmplx(0.0_dp, 0.0_dp, dp)\n end if\n end if\n\n call fftw_execute_dft_c2r(plan, coef, grid)\n vxz(i_eq,1:nlong) = grid(1:nlong)\n\n ! Vyz = 1/r^2 /sin(t) Vp - 1/r /sin(t) Vrp\n coef(1) = cmplx(coefp0/r_ex**2 - coefrp0/r_ex, 0.0_dp, dp)\n coef(2:lmax+1) = (coefp(2:lmax+1) / r_ex**2 &\n - coefrp(2:lmax+1)/r_ex ) / 2.0_dp\n\n if (present(sampling)) then\n if (sampling == 2) then\n coef(lmax+2:2*lmax+3) = cmplx(0.0_dp, 0.0_dp, dp)\n end if\n end if\n\n call fftw_execute_dft_c2r(plan, coef, grid)\n vyz(i_eq,1:nlong) = grid(1:nlong)\n\n do i = 1, i_eq - 1, 1\n\n i_s = 2 * i_eq - i\n\n theta = pi * dble(i-1) / dble(n)\n z = cos(theta)\n u = sqrt( (1.0_dp-z) * (1.0_dp+z) )\n sint = sin(theta)\n lat = pi / 2.0_dp - theta\n\n if (i == 1) then ! Reference ellipsoid radius\n r_ex = a * (1.0_dp - f)\n\n else\n r_ex = (1.0_dp + tan(lat)**2) / &\n (1.0_dp + tan(lat)**2 / (1.0_dp - f)**2 )\n r_ex = a * sqrt(r_ex)\n\n end if\n\n coefr(1:lmax+2) = cmplx(0.0_dp, 0.0_dp, dp)\n coefr0 = 0.0_dp\n coefrs(1:lmax+2) = cmplx(0.0_dp, 0.0_dp, dp)\n coefrs0 = 0.0_dp\n\n coefrr(1:lmax+2) = cmplx(0.0_dp, 0.0_dp, dp)\n coefrr0 = 0.0_dp\n coefrrs(1:lmax+2) = cmplx(0.0_dp, 0.0_dp, dp)\n coefrrs0 = 0.0_dp\n\n coeft(1:lmax+2) = cmplx(0.0_dp, 0.0_dp, dp)\n coeft0 = 0.0_dp\n coefts(1:lmax+2) = cmplx(0.0_dp, 0.0_dp, dp)\n coefts0 = 0.0_dp\n\n coeftp(1:lmax+2) = cmplx(0.0_dp, 0.0_dp, dp)\n coeftp0 = 0.0_dp\n coeftps(1:lmax+2) = cmplx(0.0_dp, 0.0_dp, dp)\n coeftps0 = 0.0_dp\n\n coefp(1:lmax+2) = cmplx(0.0_dp, 0.0_dp, dp)\n coefp0 = 0.0_dp\n coefps(1:lmax+2) = cmplx(0.0_dp, 0.0_dp, dp)\n coefps0 = 0.0_dp\n\n coefrt(1:lmax+2) = cmplx(0.0_dp, 0.0_dp, dp)\n coefrt0 = 0.0_dp\n coefrts(1:lmax+2) = cmplx(0.0_dp, 0.0_dp, dp)\n coefrts0 = 0.0_dp\n\n coefrp(1:lmax+2) = cmplx(0.0_dp, 0.0_dp, dp)\n coefrp0 = 0.0_dp\n coefrps(1:lmax+2) = cmplx(0.0_dp, 0.0_dp, dp)\n coefrps0 = 0.0_dp\n\n coefpp(1:lmax+2) = cmplx(0.0_dp, 0.0_dp, dp)\n coefpp0 = 0.0_dp\n coefpps(1:lmax+2) = cmplx(0.0_dp, 0.0_dp, dp)\n coefpps0 = 0.0_dp\n\n coeftt(1:lmax+2) = cmplx(0.0_dp, 0.0_dp, dp)\n coeftt0 = 0.0_dp\n coeftts(1:lmax+2) = cmplx(0.0_dp, 0.0_dp, dp)\n coeftts0 = 0.0_dp\n\n pm2 = 1.0_dp\n\n tempr = -cilm(1,1,1) * pm2 ! l = 0\n coefr0 = coefr0 + tempr\n coefrs0 = coefrs0 + tempr ! fsymsign is always 1 for l=m=0\n\n tempr = 2 * cilm(1,1,1) * pm2 ! l = 0\n coefrr0 = coefrr0 + tempr\n coefrrs0 = coefrrs0 + tempr\n\n ! derivative in theta and phi of l=0 term is 0, so no need to\n ! calculate this\n\n if (lmax_comp /= 0) then ! l = 1\n prefactor(1) = r0 / r_ex\n\n do l = 2, lmax_comp, 1\n prefactor(l) = prefactor(l-1) * r0 / r_ex\n end do\n\n pm1 = ff1(2,1) * z\n\n ! -2 = (l+1) prefactor\n tempr = cilm(1,2,1) * pm1 * (-2) * prefactor(1)\n coefr0 = coefr0 + tempr\n coefrs0 = coefrs0 - tempr ! fsymsign = -1\n\n ! 6 = (l+1)*(l+2) prefactor\n tempr = cilm(1,2,1) * pm1 * (6) * prefactor(1)\n coefrr0 = coefrr0 + tempr\n coefrrs0 = coefrrs0 - tempr ! fsymsign = -1\n\n ! dpl is the first derivative with respect to Z\n dpl = ff1(2,1)\n tempr = cilm(1,2,1) * dpl * prefactor(1)\n coeft0 = coeft0 + tempr\n coefts0 = coefts0 + tempr ! reverse fsymsign\n\n ! -2 = (l+1) prefactor\n tempr = cilm(1,2,1) * dpl * (-2) * prefactor(1)\n coefrt0 = coefrt0 + tempr\n coefrts0 = coefrts0 + tempr ! reverse fsymsign\n\n ! dpl2 is the second derivative with respect to THETA. Must\n ! multiply dpl by -sin(theta) in the recurrence relation\n ! note that the first term is symmetric about the equator according\n ! the fsymsign, whereas the second term differs\n ! by -1.\n dpl2 = -2 * pm1 + z * dpl\n dpl2s = 2 * pm1 + z * dpl\n tempr = cilm(1,2,1) * prefactor(1)\n coeftt0 = coeftt0 + tempr * dpl2\n coeftts0 = coeftts0 + tempr * dpl2s\n\n end if\n\n do l = 2, lmax_comp, 1\n l1 = l + 1\n p = ff1(l1,1) * z * pm1 - ff2(l1,1) * pm2\n tempr = cilm(1,l1,1) * p * (-l1) * prefactor(l)\n coefr0 = coefr0 + tempr\n coefrs0 = coefrs0 + tempr * fsymsign(l1,1)\n\n tempr = cilm(1,l1,1) * p * (l1) * (l1+1) * prefactor(l)\n coefrr0 = coefrr0 + tempr\n coefrrs0 = coefrrs0 + tempr * fsymsign(l1,1)\n\n dpl = l * ( sqr(2*l+1) / sqr(2*l-1) * pm1 - z * p ) / u**2\n tempr = cilm(1,l1,1) * dpl * prefactor(l)\n coeft0 = coeft0 + tempr\n coefts0 = coefts0 - tempr * fsymsign(l1,1) ! reverse fsymsign\n\n tempr = cilm(1,l1,1) * dpl * (-l1) * prefactor(l)\n coefrt0 = coefrt0 + tempr\n coefrts0 = coefrts0 - tempr * fsymsign(l1,1)\n\n dpl2 = -l * l1 * p + z * dpl\n dpl2s = -l * l1 * p * fsymsign(l1,1) - z * dpl * fsymsign(l1,1)\n tempr = cilm(1,l1,1) * prefactor(l)\n coeftt0 = coeftt0 + tempr * dpl2\n coeftts0 = coeftts0 + tempr * dpl2s\n\n pm2 = pm1\n pm1 = p\n\n end do\n\n pmm = sqr(2) * scalef\n\n rescalem = 1.0_dp / scalef\n\n do m = 1, lmax_comp-1, 1\n\n m1 = m + 1\n rescalem = rescalem * u\n\n pmm = pmm * sqr(2*m+1) / sqr(2*m)\n pm2 = pmm\n\n tempc = cmplx(cilm(1,m1,m1), - cilm(2,m1,m1), dp) * pm2 * (-m-1) &\n * prefactor(m) ! (m,m)\n coefr(m1) = coefr(m1) + tempc\n coefrs(m1) = coefrs(m1) + tempc ! fsymsign = 1\n\n tempc = cmplx(cilm(1,m1,m1), - cilm(2,m1,m1), dp) * pm2 * (m+1) &\n * (m+2) * prefactor(m) ! (m,m)\n coefrr(m1) = coefrr(m1) + tempc\n coefrrs(m1) = coefrrs(m1) + tempc ! fsymsign = 1\n\n tempc = cmplx(cilm(2,m1,m1), cilm(1,m1,m1), dp) * pm2 &\n * prefactor(m) * m ! (m,m)\n coefp(m1) = coefp(m1) + tempc\n coefps(m1) = coefps(m1) + tempc ! fsymsign = 1\n\n tempc = - cmplx(cilm(1,m1,m1), - cilm(2,m1,m1), dp) * pm2 &\n * prefactor(m) * m**2 ! (m,m)\n coefpp(m1) = coefpp(m1) + tempc\n coefpps(m1) = coefpps(m1) + tempc ! fsymsign = 1\n\n tempc = cmplx(cilm(2,m1,m1), cilm(1,m1,m1), dp) * pm2 *(-m-1) &\n * prefactor(m) * m ! (m,m)\n coefrp(m1) = coefrp(m1) + tempc\n coefrps(m1) = coefrps(m1) + tempc ! fsymsign = 1\n\n dpl = -m * z * pm2 / u**2\n tempc = cmplx(cilm(1,m1,m1), - cilm(2,m1,m1), dp) * dpl &\n * prefactor(m) ! (m,m)\n coeft(m1) = coeft(m1) + tempc\n coefts(m1) = coefts(m1) - tempc ! reverse fsymsign\n\n tempc = cmplx(cilm(1,m1,m1), - cilm(2,m1,m1), dp) * dpl * (-m-1) &\n * prefactor(m) ! (m,m)\n coefrt(m1) = coefrt(m1) + tempc\n coefrts(m1) = coefrts(m1) - tempc ! reverse fsymsign\n\n tempc = cmplx(cilm(2,m1,m1), cilm(1,m1,m1), dp) * dpl &\n * prefactor(m) * m ! (m,m)\n coeftp(m1) = coeftp(m1) + tempc\n coeftps(m1) = coeftps(m1) - tempc ! reverse fsymsign\n\n dpl2 = -(m*m1 - (m**2)/u**2) * pm2 + z * dpl\n dpl2s = -(m*m1 - (m**2)/u**2) * pm2 - z * dpl\n tempc = cmplx(cilm(1,m1,m1), - cilm(2,m1,m1), dp) &\n * prefactor(m) ! (m,m)\n coeftt(m1) = coeftt(m1) + tempc * dpl2\n coeftts(m1) = coeftts(m1) + tempc * dpl2s\n\n pm1 = z * ff1(m1+1,m1) * pm2\n tempc = cmplx(cilm(1,m1+1,m1), - cilm(2,m1+1,m1), dp) * pm1 &\n * (-m-2) * prefactor(m+1) ! (m+1,m)\n coefr(m1) = coefr(m1) + tempc \n coefrs(m1) = coefrs(m1) - tempc ! fsymsign = -1\n\n tempc = cmplx(cilm(1,m1+1,m1), - cilm(2,m1+1,m1), dp) * pm1 &\n * (m+2) * (m+3) * prefactor(m+1) ! (m+1,m)\n coefrr(m1) = coefrr(m1) + tempc\n coefrrs(m1) = coefrrs(m1) - tempc ! fsymsign = -1\n\n tempc = cmplx(cilm(2,m1+1,m1), cilm(1,m1+1,m1), dp) * pm1 &\n * prefactor(m+1) * m ! (m+1,m)\n coefp(m1) = coefp(m1) + tempc\n coefps(m1) = coefps(m1) - tempc ! fsymsign = -1\n\n tempc = - cmplx(cilm(1,m1+1,m1), - cilm(2,m1+1,m1), dp) * pm1 &\n * prefactor(m+1) * m**2 ! (m+1,m)\n coefpp(m1) = coefpp(m1) + tempc\n coefpps(m1) = coefpps(m1) - tempc ! fsymsign = -1\n\n tempc = cmplx(cilm(2,m1+1,m1), cilm(1,m1+1,m1), dp) * pm1 &\n * (-m-2) * prefactor(m+1) * m ! (m+1,m)\n coefrp(m1) = coefrp(m1) + tempc\n coefrps(m1) = coefrps(m1) - tempc ! fsymsign = -1\n\n dpl = (sqr(2*m+3) * pmm - z * (m+1) * pm1) / u**2\n tempc = cmplx(cilm(1,m1+1,m1), - cilm(2,m1+1,m1), dp) * dpl &\n * prefactor(m+1) ! (m+1,m)\n coeft(m1) = coeft(m1) + tempc\n coefts(m1) = coefts(m1) + tempc ! reverse fsymsign\n\n tempc = cmplx(cilm(1,m1+1,m1), - cilm(2,m1+1,m1), dp) * dpl &\n * (-m-2) * prefactor(m+1) ! (m+1,m)\n coefrt(m1) = coefrt(m1) + tempc\n coefrts(m1) = coefrts(m1) + tempc ! reverse fsymsign\n\n tempc = cmplx(cilm(2,m1+1,m1), cilm(1,m1+1,m1), dp) * dpl &\n * prefactor(m+1) * m ! (m+1,m)\n coeftp(m1) = coeftp(m1) + tempc\n coeftps(m1) = coeftps(m1) + tempc ! reverse fsymsign\n\n dpl2 = -(m1*(m1+1) - (m**2)/u**2) * pm1 + z * dpl\n dpl2s = (m1*(m1+1) - (m**2)/u**2) * pm1 + z * dpl\n tempc = cmplx(cilm(1,m1+1,m1), - cilm(2,m1+1,m1), dp) &\n * prefactor(m+1) ! (m+1,m)\n coeftt(m1) = coeftt(m1) + tempc * dpl2\n coeftts(m1) = coeftts(m1) + tempc * dpl2s\n\n do l=m+2, lmax_comp, 1\n l1 = l + 1\n p = z * ff1(l1,m1) * pm1 - ff2(l1,m1) * pm2\n tempc = cmplx(cilm(1,l1,m1), - cilm(2,l1,m1), dp) * p * (-l1) &\n * prefactor(l)\n coefr(m1) = coefr(m1) + tempc\n coefrs(m1) = coefrs(m1) + tempc * fsymsign(l1,m1)\n\n tempc = cmplx(cilm(1,l1,m1), - cilm(2,l1,m1), dp) * p * (l1) &\n * (l1+1) * prefactor(l)\n coefrr(m1) = coefrr(m1) + tempc\n coefrrs(m1) = coefrrs(m1) + tempc * fsymsign(l1,m1)\n\n tempc = cmplx(cilm(2,l1,m1), cilm(1,l1,m1), dp) * p &\n * prefactor(l) * m\n coefp(m1) = coefp(m1) + tempc\n coefps(m1) = coefps(m1) + tempc * fsymsign(l1,m1)\n\n tempc = - cmplx(cilm(1,l1,m1), - cilm(2,l1,m1), dp) * p &\n * prefactor(l) * m**2\n coefpp(m1) = coefpp(m1) + tempc\n coefpps(m1) = coefpps(m1) + tempc * fsymsign(l1,m1)\n\n tempc = cmplx(cilm(2,l1,m1), cilm(1,l1,m1), dp) * p * (-l1) &\n * prefactor(l) * m\n coefrp(m1) = coefrp(m1) + tempc\n coefrps(m1) = coefrps(m1) + tempc * fsymsign(l1,m1)\n\n dpl = ( sqr(2*l+1) * sqr(l-m) * sqr(l+m) / sqr(2*l-1) &\n * pm1 - z * l * p) / u**2\n tempc = cmplx(cilm(1,l1,m1), - cilm(2,l1,m1), dp) * dpl &\n * prefactor(l)\n coeft(m1) = coeft(m1) + tempc\n ! reverse fsymsign\n coefts(m1) = coefts(m1) - tempc * fsymsign(l1,m1)\n\n tempc = cmplx(cilm(1,l1,m1), - cilm(2,l1,m1), dp) * dpl &\n * (-l1) * prefactor(l)\n coefrt(m1) = coefrt(m1) + tempc\n ! reverse fsymsign\n coefrts(m1) = coefrts(m1) - tempc * fsymsign(l1,m1)\n\n tempc = cmplx(cilm(2,l1,m1), cilm(1,l1,m1), dp) * dpl &\n * prefactor(l) * m\n coeftp(m1) = coeftp(m1) + tempc\n ! reverse fsymsign\n coeftps(m1) = coeftps(m1) - tempc * fsymsign(l1,m1)\n\n dpl2 = -(l * l1 -(m**2)/u**2) * p + z * dpl\n dpl2s = -(l * l1 -(m**2)/u**2) * p * fsymsign(l1,m1) &\n - z * dpl * fsymsign(l1,m1) \n tempc = cmplx(cilm(1,l1,m1), - cilm(2,l1,m1), dp) &\n * prefactor(l)\n coeftt(m1) = coeftt(m1) + tempc * dpl2\n coeftts(m1) = coeftts(m1) + tempc * dpl2s\n\n pm2 = pm1\n pm1 = p\n\n end do\n\n coefr(m1) = coefr(m1) * rescalem\n coefrs(m1) = coefrs(m1) * rescalem\n\n coefrr(m1) = coefrr(m1) * rescalem\n coefrrs(m1) = coefrrs(m1) * rescalem\n\n coeft(m1) = coeft(m1) * rescalem\n coefts(m1) = coefts(m1) * rescalem\n\n coeftt(m1) = coeftt(m1) * rescalem\n coeftts(m1) = coeftts(m1) * rescalem\n\n coefrt(m1) = coefrt(m1) * rescalem\n coefrts(m1) = coefrts(m1) * rescalem\n\n coefp(m1) = coefp(m1) * rescalem\n coefps(m1) = coefps(m1) * rescalem\n\n coefpp(m1) = coefpp(m1) * rescalem\n coefpps(m1) = coefpps(m1) * rescalem\n\n coeftp(m1) = coeftp(m1) * rescalem\n coeftps(m1) = coeftps(m1) * rescalem\n\n coefrp(m1) = coefrp(m1) * rescalem\n coefrps(m1) = coefrps(m1) * rescalem\n\n end do\n\n if (lmax_comp /= 0) then\n\n rescalem = rescalem * u\n\n pmm = pmm * sqr(2*lmax_comp+1) / sqr(2*lmax_comp) * rescalem\n tempc = cmplx(cilm(1,lmax_comp+1,lmax_comp+1), &\n - cilm(2,lmax_comp+1,lmax_comp+1), dp) * pmm &\n * (-lmax_comp-1) * prefactor(lmax_comp)\n coefr(lmax_comp+1) = coefr(lmax_comp+1) + tempc\n coefrs(lmax_comp+1) = coefrs(lmax_comp+1) + tempc ! fsymsign = 1\n\n tempc = cmplx(cilm(1,lmax_comp+1,lmax_comp+1), &\n - cilm(2,lmax_comp+1,lmax_comp+1), dp) * pmm &\n * (lmax_comp+1) * (lmax_comp+2) &\n * prefactor(lmax_comp)\n coefrr(lmax_comp+1) = coefrr(lmax_comp+1) + tempc\n coefrrs(lmax_comp+1) = coefrrs(lmax_comp+1) + tempc ! fsymsign = 1\n\n tempc = cmplx(cilm(2,lmax_comp+1,lmax_comp+1), &\n cilm(1,lmax_comp+1,lmax_comp+1), dp) * pmm &\n * prefactor(lmax_comp) * lmax_comp\n coefp(lmax_comp+1) = coefp(lmax_comp+1) + tempc\n coefps(lmax_comp+1) = coefps(lmax_comp+1) + tempc ! fsymsign = 1\n\n tempc = - cmplx(cilm(1,lmax_comp+1,lmax_comp+1), &\n - cilm(2,lmax_comp+1,lmax_comp+1), dp) * pmm &\n * prefactor(lmax_comp) * lmax_comp**2\n coefpp(lmax_comp+1) = coefpp(lmax_comp+1) + tempc\n coefpps(lmax_comp+1) = coefpps(lmax_comp+1) + tempc ! fsymsign = 1\n\n tempc = cmplx(cilm(2,lmax_comp+1,lmax_comp+1), &\n cilm(1,lmax_comp+1,lmax_comp+1), dp) * pmm &\n * (-lmax_comp-1) * prefactor(lmax_comp) * lmax_comp\n coefrp(lmax_comp+1) = coefrp(lmax_comp+1) + tempc\n coefrps(lmax_comp+1) = coefrps(lmax_comp+1) + tempc ! fsymsign = 1\n\n dpl = -lmax_comp * z * pmm / u**2\n tempc = cmplx(cilm(1,lmax_comp+1,lmax_comp+1), &\n - cilm(2,lmax_comp+1,lmax_comp+1), dp) * dpl &\n * prefactor(lmax_comp)\n coeft(lmax_comp+1) = coeft(lmax_comp+1) + tempc\n ! reverse fsymsign\n coefts(lmax_comp+1) = coefts(lmax_comp+1) - tempc\n\n tempc = cmplx(cilm(1,lmax_comp+1,lmax_comp+1), &\n - cilm(2,lmax_comp+1,lmax_comp+1), dp) * dpl &\n * (-lmax_comp-1) * prefactor(lmax_comp)\n coefrt(lmax_comp+1) = coefrt(lmax_comp+1) + tempc\n ! reverse fsymsign\n coefrts(lmax_comp+1) = coefrts(lmax_comp+1) - tempc\n\n tempc = cmplx(cilm(2,lmax_comp+1,lmax_comp+1), &\n cilm(1,lmax_comp+1,lmax_comp+1), dp) * dpl &\n * prefactor(lmax_comp) * lmax_comp\n coeftp(lmax_comp+1) = coeftp(lmax_comp+1) + tempc\n coeftps(lmax_comp+1) = coeftps(lmax_comp+1) - tempc\n\n dpl2 = -(lmax_comp*(lmax_comp+1)-(lmax_comp**2)/u**2) * pmm &\n + z * dpl\n dpl2s = -(lmax_comp*(lmax_comp+1)-(lmax_comp**2)/u**2) * pmm &\n - z * dpl\n tempc = cmplx(cilm(1,lmax_comp+1,lmax_comp+1), &\n - cilm(2,lmax_comp+1,lmax_comp+1), dp) &\n * prefactor(lmax_comp)\n coeftt(lmax_comp+1) = coeftt(lmax_comp+1) + tempc * dpl2\n coeftts(lmax_comp+1) = coeftts(lmax_comp+1) + tempc * dpl2s\n\n end if\n\n ! Note that the first angular derivatives are with repsect to z,\n ! but that the second is with respect to theta.\n\n coefr0 = coefr0 * gm / r_ex**2\n coefr(2:lmax+1) = coefr(2:lmax+1) * gm / r_ex**2\n\n coefrs0 = coefrs0 * gm / r_ex**2\n coefrs(2:lmax+1) = coefrs(2:lmax+1) * gm / r_ex**2\n\n coefrt0 = -sint * coefrt0 * gm / r_ex**2\n coefrt(2:lmax+1) = -sint * coefrt(2:lmax+1) * gm / r_ex**2\n\n coefrts0 = -sint * coefrts0 * gm / r_ex**2\n coefrts(2:lmax+1) = -sint * coefrts(2:lmax+1) * gm / r_ex**2\n\n coefrr0 = coefrr0 * gm / r_ex**3\n coefrr(2:lmax+1) = coefrr(2:lmax+1) * gm / r_ex**3\n\n coefrrs0 = coefrrs0 * gm / r_ex**3\n coefrrs(2:lmax+1) = coefrrs(2:lmax+1) * gm / r_ex**3\n\n coeft0 = -sint * coeft0 * gm / r_ex\n coeft(2:lmax+1) = -sint * coeft(2:lmax+1) * gm / r_ex\n\n coefts0 = -sint * coefts0 * gm / r_ex\n coefts(2:lmax+1) = -sint * coefts(2:lmax+1) * gm / r_ex\n\n coeftt0 = coeftt0 * gm / r_ex\n coeftt(2:lmax+1) = coeftt(2:lmax+1) * gm / r_ex\n\n coeftts0 = coeftts0 * gm / r_ex\n coeftts(2:lmax+1) = coeftts(2:lmax+1) * gm / r_ex\n\n coeftp0 = -sint * coeftp0 * gm / r_ex\n coeftp(2:lmax+1) = -sint * coeftp(2:lmax+1) * gm / r_ex\n\n coeftps0 = -sint * coeftps0 * gm / r_ex\n coeftps(2:lmax+1) = -sint * coeftps(2:lmax+1) * gm / r_ex\n\n coefp0 = coefp0 * gm / r_ex\n coefp(2:lmax+1) = coefp(2:lmax+1) * gm / r_ex\n\n coefps0 = coefps0 * gm / r_ex\n coefps(2:lmax+1) = coefps(2:lmax+1) * gm / r_ex\n\n coefpp0 = coefpp0 * gm / r_ex\n coefpp(2:lmax+1) = coefpp(2:lmax+1) * gm / r_ex\n\n coefpps0 = coefpps0 * gm / r_ex\n coefpps(2:lmax+1) = coefpps(2:lmax+1) * gm / r_ex\n\n coefrp0 = coefrp0 * gm / r_ex**2\n coefrp(2:lmax+1) = coefrp(2:lmax+1) * gm / r_ex**2\n\n coefrps0 = coefrps0 * gm / r_ex**2\n coefrps(2:lmax+1) = coefrps(2:lmax+1) * gm / r_ex**2\n\n ! Vzz = Vrr\n coef(1) = cmplx(coefrr0, 0.0_dp, dp)\n coef(2:lmax+1) = coefrr(2:lmax+1) / 2.0_dp\n\n if (present(sampling)) then\n if (sampling == 2) then\n coef(lmax+2:2*lmax+3) = cmplx(0.0_dp, 0.0_dp, dp)\n end if\n\n end if\n\n call fftw_execute_dft_c2r(plan, coef, grid)\n vzz(i,1:nlong) = grid(1:nlong)\n\n if (i == 1) then\n ! These derivatives are undefined at the pole\n vxx(1,1:nlong) = 0.0_dp\n vyy(1,1:nlong) = 0.0_dp\n vxy(1,1:nlong) = 0.0_dp\n vxz(1,1:nlong) = 0.0_dp\n vyz(1,1:nlong) = 0.0_dp\n\n else\n ! Vxx = 1/r Vr + 1/r^2 Vtt\n coef(1) = cmplx(coefr0/r_ex + coeftt0/r_ex**2, 0.0_dp, dp)\n coef(2:lmax+1) = (coefr(2:lmax+1)/r_ex &\n + coeftt(2:lmax+1)/r_ex**2 ) / 2.0_dp\n\n if (present(sampling)) then\n if (sampling == 2) then\n coef(lmax+2:2*lmax+3) = cmplx(0.0_dp, 0.0_dp, dp)\n end if\n end if\n\n call fftw_execute_dft_c2r(plan, coef, grid)\n vxx(i,1:nlong) = grid(1:nlong)\n\n ! Vyy = 1/r Vr + 1/r^2 /tan(t) Vt + 1/r^2 /sin(t)^2 Vpp\n coef(1) = cmplx(coefr0/r_ex + coeft0/(r_ex**2)/tan(theta) &\n + coefpp0/(r_ex**2)/u**2, 0.0_dp, dp)\n coef(2:lmax+1) = (coefr(2:lmax+1)/r_ex &\n + coeft(2:lmax+1)/(r_ex**2)/tan(theta) + &\n coefpp(2:lmax+1)/(r_ex**2)/u**2 ) / 2.0_dp\n\n if (present(sampling)) then\n if (sampling == 2) then\n coef(lmax+2:2*lmax+3) = cmplx(0.0_dp, 0.0_dp, dp)\n end if\n end if\n\n call fftw_execute_dft_c2r(plan, coef, grid)\n vyy(i,1:nlong) = grid(1:nlong)\n\n ! Vxy = 1/r^2 /sin(t) Vtp - cos(t)/sin(t)^2 /r^2 Vp\n coef(1) = cmplx(coeftp0/sint/r_ex**2 &\n - coefp0/(r_ex**2)*z/u**2, 0.0_dp, dp)\n coef(2:lmax+1) = (coeftp(2:lmax+1)/sint/r_ex**2 &\n - coefp(2:lmax+1)/(r_ex**2)*z/u**2 ) / 2.0_dp\n\n if (present(sampling)) then\n if (sampling == 2) then\n coef(lmax+2:2*lmax+3) = cmplx(0.0_dp, 0.0_dp, dp)\n end if\n end if\n\n call fftw_execute_dft_c2r(plan, coef, grid)\n vxy(i,1:nlong) = grid(1:nlong)\n\n ! Vxz = 1/r^2 Vt - 1/r Vrt\n coef(1) = cmplx(coeft0/r_ex**2 - coefrt0/r_ex, 0.0_dp, dp)\n coef(2:lmax+1) = (coeft(2:lmax+1)/r_ex**2 &\n - coefrt(2:lmax+1)/r_ex ) / 2.0_dp\n\n if (present(sampling)) then\n if (sampling == 2) then\n coef(lmax+2:2*lmax+3) = cmplx(0.0_dp, 0.0_dp, dp)\n end if\n end if\n\n call fftw_execute_dft_c2r(plan, coef, grid)\n vxz(i,1:nlong) = grid(1:nlong)\n\n ! Vyz = 1/r^2 /sin(t) Vp - 1/r /sin(t) Vrp\n coef(1) = cmplx(coefp0/sint/r_ex**2 - coefrp0/sint/r_ex, 0.0_dp, dp)\n coef(2:lmax+1) = (coefp(2:lmax+1)/sint/r_ex**2 &\n - coefrp(2:lmax+1)/sint/r_ex ) / 2.0_dp\n\n if (present(sampling)) then\n if (sampling == 2) then\n coef(lmax+2:2*lmax+3) = cmplx(0.0_dp, 0.0_dp, dp)\n end if\n end if\n\n call fftw_execute_dft_c2r(plan, coef, grid)\n vyz(i,1:nlong) = grid(1:nlong)\n\n end if\n\n ! don't compute value for south pole when extend = 0.\n if (.not. (i == 1 .and. extend_grid == 0) ) then\n ! Vzz = Vrr\n coef(1) = cmplx(coefrrs0, 0.0_dp, dp)\n coef(2:lmax+1) = coefrrs(2:lmax+1) / 2.0_dp\n\n if (present(sampling)) then\n if (sampling == 2) then\n coef(lmax+2:2*lmax+3) = cmplx(0.0_dp, 0.0_dp, dp)\n end if\n end if\n\n call fftw_execute_dft_c2r(plan, coef, grid)\n vzz(i_s,1:nlong) = grid(1:nlong)\n\n if (i == 1) then\n ! These derivatives are undefined at the pole\n vxx(1,1:nlong) = 0.0_dp\n vyy(1,1:nlong) = 0.0_dp\n vxy(1,1:nlong) = 0.0_dp\n vxz(1,1:nlong) = 0.0_dp\n vyz(1,1:nlong) = 0.0_dp\n\n else\n ! Vxx = 1/r Vr + 1/r^2 Vtt\n coef(1) = cmplx(coefrs0/r_ex + coeftts0/r_ex**2, 0.0_dp, dp)\n coef(2:lmax+1) = (coefrs(2:lmax+1)/r_ex &\n + coeftts(2:lmax+1)/r_ex**2 ) / 2.0_dp\n\n if (present(sampling)) then\n if (sampling == 2) then\n coef(lmax+2:2*lmax+3) = cmplx(0.0_dp, 0.0_dp, dp)\n end if\n end if\n\n call fftw_execute_dft_c2r(plan, coef, grid)\n vxx(i_s,1:nlong) = grid(1:nlong)\n\n ! Vyy = 1/r Vr + 1/r^2 /tan(t) Vt + 1/r^2 /sin(t)^2 Vpp\n coef(1) = cmplx(coefrs0/r_ex + coefts0/(r_ex**2)/tan(theta) &\n + coefpps0/(r_ex**2)/u**2, 0.0_dp, dp)\n coef(2:lmax+1) = (coefrs(2:lmax+1)/r_ex &\n + coefts(2:lmax+1)/(r_ex**2)/tan(theta) + &\n coefpps(2:lmax+1)/(r_ex**2)/u**2 ) / 2.0_dp\n\n if (present(sampling)) then\n if (sampling == 2) then\n coef(lmax+2:2*lmax+3) = cmplx(0.0_dp, 0.0_dp, dp)\n end if\n end if\n\n call fftw_execute_dft_c2r(plan, coef, grid)\n vyy(i_s,1:nlong) = grid(1:nlong)\n\n ! Vxy = 1/r^2 /sin(t) Vtp - cos(t)/sin(t)^2 /r^2 Vp\n coef(1) = cmplx(coeftps0/sint/r_ex**2 &\n - coefps0/(r_ex**2)*z/u**2, 0.0_dp, dp)\n coef(2:lmax+1) = (coeftps(2:lmax+1)/sint/r_ex**2 &\n - coefps(2:lmax+1)/(r_ex**2)*z/u**2 ) &\n / 2.0_dp\n\n if (present(sampling)) then\n if (sampling == 2) then\n coef(lmax+2:2*lmax+3) = cmplx(0.0_dp, 0.0_dp, dp)\n end if\n end if\n\n call fftw_execute_dft_c2r(plan, coef, grid)\n vxy(i_s,1:nlong) = grid(1:nlong)\n\n ! Vxz = 1/r^2 Vt - 1/r Vrt\n coef(1) = cmplx(coefts0/r_ex**2 - coefrts0/r_ex, 0.0_dp, dp)\n coef(2:lmax+1) = (coefts(2:lmax+1)/r_ex**2 &\n - coefrts(2:lmax+1)/r_ex ) / 2.0_dp\n\n if (present(sampling)) then\n if (sampling == 2) then\n coef(lmax+2:2*lmax+3) = cmplx(0.0_dp, 0.0_dp, dp)\n end if\n end if\n\n call fftw_execute_dft_c2r(plan, coef, grid)\n vxz(i_s,1:nlong) = grid(1:nlong)\n\n ! Vyz = 1/r^2 /sin(t) Vp - 1/r /sin(t) Vrp\n coef(1) = cmplx(coefps0/sint/r_ex**2 - coefrps0/sint/r_ex, &\n 0.0_dp, dp)\n coef(2:lmax+1) = (coefps(2:lmax+1)/sint/r_ex**2 &\n - coefrps(2:lmax+1)/sint/r_ex ) / 2.0_dp\n\n if (present(sampling)) then\n if (sampling == 2) then\n coef(lmax+2:2*lmax+3) = cmplx(0.0_dp, 0.0_dp, dp)\n end if\n end if\n\n call fftw_execute_dft_c2r(plan, coef, grid)\n vyz(i_s,1:nlong) = grid(1:nlong)\n\n end if\n\n end if\n\n end do\n\n if (extend_grid == 1) then\n vxx(1:nlat_out, nlong_out) = vxx(1:nlat_out, 1)\n vyy(1:nlat_out, nlong_out) = vyy(1:nlat_out, 1)\n vzz(1:nlat_out, nlong_out) = vzz(1:nlat_out, 1)\n vxy(1:nlat_out, nlong_out) = vxy(1:nlat_out, 1)\n vxz(1:nlat_out, nlong_out) = vxz(1:nlat_out, 1)\n vyz(1:nlat_out, nlong_out) = vyz(1:nlat_out, 1)\n end if\n\n call fftw_destroy_plan(plan)\n\nend subroutine MakeGravGradGridDH\n", "meta": {"hexsha": "3b73ac251f22d46a5bffd2f8267ffb842d9311b6", "size": 52508, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/MakeGravGradGridDH.f95", "max_stars_repo_name": "megies/SHTOOLS", "max_stars_repo_head_hexsha": "740455a28eafb6bb23a449cdec43724e86d99c4f", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/MakeGravGradGridDH.f95", "max_issues_repo_name": "megies/SHTOOLS", "max_issues_repo_head_hexsha": "740455a28eafb6bb23a449cdec43724e86d99c4f", "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/MakeGravGradGridDH.f95", "max_forks_repo_name": "megies/SHTOOLS", "max_forks_repo_head_hexsha": "740455a28eafb6bb23a449cdec43724e86d99c4f", "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": 37.3191186923, "max_line_length": 80, "alphanum_fraction": 0.4729184124, "num_tokens": 18638, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172644875642, "lm_q2_score": 0.7279754430043072, "lm_q1q2_score": 0.6907884659897698}} {"text": " !\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 1998 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Spherepack *\n! * *\n! * A Package of Fortran Subroutines and Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams and Paul Swarztrauber *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\n!\n!\n!\n! 1/976\n!\n! a program for testing all vector laplacian and its inverse\n!\n! (1) first set the vector function (rotation about equator) using\n! v = cos(phi) and w = -cos(theta)*sin(phi)\n!\n! (2) set vector laplacian ananlytically\n! vlap = -2.*cos(phi)=-2.*v, wlap = -2.*w\n! (i.e., L(v, w) = -2.*(v, w) so (v, w) is an eigenfunction for the\n! vector Laplacian with eigenvalue -2.\n!\n! (3) compute the coefficients br, bi, cr, ci of (v, w) using vector analysis\n!\n! (3) compute the vector laplacian of (v, w) using vlapec, vlapes, vlapgc, vlapgs\n!\n! (4) compare (3) with (2)\n!\n! (5) invert (4) and compare with (v, w)\n!\nprogram tvlap\n\n use, intrinsic :: ISO_Fortran_env, only: &\n stdout => OUTPUT_UNIT\n\n use spherepack, only: &\n ip, & ! Integer precision\n wp, & ! Working precision\n Sphere, &\n Regularsphere, &\n GaussianSphere\n\n ! Explicit typing only\n implicit none\n\n ! Dictionary\n class(Sphere), allocatable :: solver\n\n ! Test gaussian grid\n allocate (GaussianSphere :: solver)\n call test_vector_laplacian_routines(solver)\n deallocate (solver)\n\n ! Test regular grid\n allocate (RegularSphere :: solver)\n call test_vector_laplacian_routines(solver)\n deallocate (solver)\n\ncontains\n\n subroutine test_vector_laplacian_routines( sphere_type)\n\n ! Dummy arguments\n class(Sphere), intent(inout) :: sphere_type\n\n ! Local variables\n integer(ip), parameter :: NLONS = 16\n integer(ip), parameter :: NLATS = 29\n integer(ip) :: i, j, k ! Counters\n real(wp) :: original_polar_component(NLATS, NLONS)\n real(wp) :: original_azimuthal_component(NLATS, NLONS)\n real(wp) :: exact_polar_laplacian(NLATS, NLONS)\n real(wp) :: exact_azimuthal_laplacian(NLATS, NLONS)\n real(wp) :: polar_component(NLATS, NLONS)\n real(wp) :: azimuthal_component(NLATS, NLONS)\n real(wp) :: approximate_polar_laplacian(NLATS, NLONS)\n real(wp) :: approximate_azimuthal_laplacian(NLATS, NLONS)\n character(len=:), allocatable :: previous_polar_laplacian_error\n character(len=:), allocatable :: previous_polar_inversion_error\n character(len=:), allocatable :: previous_azimuthal_laplacian_error\n character(len=:), allocatable :: previous_azimuthal_inversion_error\n\n ! Set up workspace arrays\n select type(sphere_type)\n type is (GaussianSphere)\n\n ! Initialize gaussian sphere object\n sphere_type = GaussianSphere(NLATS, NLONS)\n\n ! Allocate known error from previous platform\n allocate (previous_polar_laplacian_error, source=' polar laplacian error = 1.761258e-12')\n allocate (previous_azimuthal_laplacian_error, source=' azimuthal laplacian error = 8.710810e-13')\n allocate (previous_polar_inversion_error, source=' polar inversion error = 5.551115e-16')\n allocate (previous_azimuthal_inversion_error, source=' azimuthal inversion error = 7.216450e-16')\n\n type is (RegularSphere)\n\n ! Initialize regular sphere\n sphere_type = RegularSphere(NLATS, NLONS)\n\n ! Allocate known error from previous platform\n allocate (previous_polar_laplacian_error, source=' polar laplacian error = 3.113065e-13')\n allocate (previous_azimuthal_laplacian_error, source=' azimuthal laplacian error = 4.702905e-13')\n allocate (previous_polar_inversion_error, source=' polar inversion error = 5.551115e-16')\n allocate (previous_azimuthal_inversion_error, source=' azimuthal inversion error = 5.551115e-16')\n end select\n\n !\n ! test all vector laplacian and inverse vector laplacian subroutines\n !\n associate (&\n r => sphere_type%unit_vectors%radial, &\n phi => sphere_type%unit_vectors%azimuthal, &\n ve => original_polar_component, &\n we => original_azimuthal_component, &\n velap => exact_polar_laplacian, &\n welap => exact_azimuthal_laplacian &\n )\n do j=1, NLONS\n do i=1, NLATS\n associate (&\n cost => r(i, j)%z, &\n cosp => phi(i, j)%y, &\n sinp => -phi(i, j)%x &\n )\n !\n ! set vector field v, w\n !\n ve(i, j) = cosp\n we(i, j) = -cost*sinp\n !\n ! set vector laplacian vlap, wlap\n !\n velap(i, j) = -2.0_wp * ve(i, j)\n welap(i, j) = -2.0_wp * we(i, j)\n end associate\n end do\n end do\n end associate\n\n\n associate (&\n ve => original_polar_component, &\n we => original_azimuthal_component, &\n vlap => approximate_polar_laplacian, &\n wlap => approximate_azimuthal_laplacian &\n )\n !\n ! Compute vector laplacian\n !\n call sphere_type%get_laplacian(ve, we, vlap, wlap)\n\n end associate\n\n !\n ! Compute laplacian error\n !\n associate (&\n velap => exact_polar_laplacian, &\n welap => exact_azimuthal_laplacian, &\n vlap => approximate_polar_laplacian, &\n wlap => approximate_azimuthal_laplacian &\n )\n associate (&\n err2v => maxval(abs(vlap - velap)), &\n err2w => maxval(abs(wlap - welap)) &\n )\n\n !\n ! Print earlier output from platform with 64-bit floating point\n ! arithmetic followed by the output from this computer\n !\n write (stdout, '(/a/)') ' tvlap *** TEST RUN *** '\n write (stdout, '(a)') ' grid type = '//sphere_type%grid%grid_type\n write (stdout, '(a)') ' Testing vector laplacian'\n write (stdout, '(2(a, i3))') ' nlat = ', NLATS, ' nlon = ', NLONS\n write (stdout, '(a)') ' Previous 64 bit floating point arithmetic result '\n write (stdout, '(a)') previous_polar_laplacian_error\n write (stdout, '(a)') previous_azimuthal_laplacian_error\n write (stdout, '(a)') ' The output from your computer is: '\n write (stdout, '(a, 1pe15.6)') ' polar laplacian error = ', err2v\n write (stdout, '(a, 1pe15.6/)') ' azimuthal laplacian error = ', err2w\n end associate\n end associate\n !\n ! Now recompute (v, w) inverting (velap, welap)\n !\n associate (&\n v => polar_component, &\n w => azimuthal_component, &\n velap => exact_polar_laplacian, &\n welap => exact_azimuthal_laplacian &\n )\n call sphere_type%invert_laplacian( velap, welap, v, w)\n end associate\n\n !\n ! compare this v, w with original\n !\n associate (&\n ve => original_polar_component, &\n we => original_azimuthal_component, &\n v => polar_component, &\n w => azimuthal_component &\n )\n associate (&\n err2v => maxval(abs(v - ve)), &\n err2w => maxval(abs(w - we)) &\n )\n !\n ! Print earlier output from platform with 64-bit floating point\n ! arithmetic followed by the output from this computer\n !\n write (stdout, '(/a/)') ' tvlap *** TEST RUN *** '\n write (stdout, '(a)') ' grid type = '//sphere_type%grid%grid_type\n write (stdout, '(a)') ' Testing vector laplacian inversion'\n write (stdout, '(2(a, i3))') ' nlat = ', NLATS, ' nlon = ', NLONS\n write (stdout, '(a)') ' Previous 64 bit floating point arithmetic result '\n write (stdout, '(a)') previous_polar_inversion_error\n write (stdout, '(a)') previous_azimuthal_inversion_error\n write (stdout, '(a)') ' The output from your computer is: '\n write (stdout, '(a, 1pe15.6)') ' polar inversion error = ', err2v\n write (stdout, '(a, 1pe15.6/)') ' azimuthal inversion error = ', err2w\n end associate\n end associate\n !\n ! Release memory\n deallocate (previous_polar_laplacian_error)\n deallocate (previous_polar_inversion_error)\n deallocate (previous_azimuthal_laplacian_error)\n deallocate (previous_azimuthal_inversion_error)\n call sphere_type%destroy()\n\n end subroutine test_vector_laplacian_routines\n\nend program tvlap\n\n", "meta": {"hexsha": "05696d144bdeb76749bbcc8f1ddd43c823289743", "size": 11337, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/test_vector_laplacian_routines.f90", "max_stars_repo_name": "jlokimlin/spherepack4.1", "max_stars_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-06-28T14:01:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T21:59:28.000Z", "max_issues_repo_path": "test/test_vector_laplacian_routines.f90", "max_issues_repo_name": "jlokimlin/spherepack4.1", "max_issues_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2016-05-07T23:00:35.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-22T23:52:30.000Z", "max_forks_repo_path": "test/test_vector_laplacian_routines.f90", "max_forks_repo_name": "jlokimlin/spherepack4.1", "max_forks_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-06-28T14:03:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T12:53:54.000Z", "avg_line_length": 43.2709923664, "max_line_length": 113, "alphanum_fraction": 0.4636147129, "num_tokens": 2559, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181875, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6907862572904733}} {"text": "program test_fm\nuse types, only: dp\nuse constants, only: pi\nuse special_functions, only: Fm\nuse utils, only: assert\nimplicit none\n\nreal(dp), allocatable :: F(:), G(:)\nreal(dp) :: x\nreal(dp), parameter :: eps = 1e-15_dp\nreal(dp), parameter :: eps_rel = 1e-12_dp\nreal(dp), parameter :: xlist(23) = [0._dp, 1e-9_dp, 1e-6_dp, 0.1_dp, 0.5_dp, &\n 2._dp, 10._dp, 15._dp, 19._dp, 20._dp, 21._dp, 25._dp, 30._dp, 50._dp, &\n 100._dp, 150._dp, 200._dp, 500._dp, 2000._dp, 20000._dp, 2e5_dp, 2e6_dp, &\n 2e8_dp]\ninteger :: m, maxm, i\nreal(dp) :: F0\n! We use downward recursion with initial value 0, so maxm must be very high to\n! get accurate results:\nmaxm = 1000\nallocate(F(0:maxm), G(0:maxm))\n\ndo i = 1, size(xlist)\n x = xlist(i)\n if (x < 510) then\n call downwards(maxm, x, F)\n else\n call asympt(maxm, x, F)\n end if\n if (x < epsilon(1._dp)) then\n F0 = 1\n else\n F0 = 0.5_dp * sqrt(pi/x) * erf(sqrt(x))\n end if\n call assert(abs(F(0) - F0) < eps)\n call assert(abs(F(0) - F0) / F(0) < 1e-14_dp)\n do m = 0, 500\n call Fm(m, x, G(:m))\n call assert(all(abs(G(:m) - F(:m)) < eps))\n call assert(all(rel_error(F(:m), G(:m)) < eps_rel))\n end do\nend do\n\ncontains\n\nsubroutine downwards(maxm, t, F)\ninteger, intent(in) :: maxm\nreal(dp), intent(in) :: t\nreal(dp), intent(out) :: F(0:)\ninteger :: m\nF(maxm) = 0\ndo m = maxm-1, 0, -1\n F(m) = (2*t*F(m + 1) + exp(-t)) / (2*m + 1)\nend do\nend subroutine\n\nsubroutine asympt(maxm, t, F)\ninteger, intent(in) :: maxm\nreal(dp), intent(in) :: t\nreal(dp), intent(out) :: F(0:)\ninteger :: m\ndo m = 0, maxm\n ! This can overflow (NaN):\n !F(m) = gamma(m+0.5_dp) / (2*t**(m+0.5_dp))\n ! so this is equivalent, but works for large \"t\" and \"m\":\n F(m) = exp(log_gamma(m+0.5_dp) - (m+0.5_dp)*log(t)) / 2\nend do\nend subroutine\n\nreal(dp) elemental function rel_error(a, b) result(r)\nreal(dp), intent(in) :: a, b\nreal(dp) :: m, d\nd = abs(a-b)\nm = max(abs(a), abs(b))\nif (d < tiny(1._dp)) then\n r = 0\nelse\n r = d / m\nend if\nend function\n\nend program\n", "meta": {"hexsha": "87efc29857e1642faca5c8303291b10bb95973b5", "size": 2058, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/test_fm.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/tests/test_fm.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/tests/test_fm.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": 24.7951807229, "max_line_length": 78, "alphanum_fraction": 0.584548105, "num_tokens": 818, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809304, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6907862525814557}} {"text": " subroutine OPERATORLAP4(\n & lofphi\n & ,ilofphilo0,ilofphilo1,ilofphilo2\n & ,ilofphihi0,ilofphihi1,ilofphihi2\n & ,nlofphicomp\n & ,phi\n & ,iphilo0,iphilo1,iphilo2\n & ,iphihi0,iphihi1,iphihi2\n & ,nphicomp\n & ,iregionlo0,iregionlo1,iregionlo2\n & ,iregionhi0,iregionhi1,iregionhi2\n & ,dx\n & ,alpha\n & ,beta\n & )\n implicit none\n integer*8 ch_flops\n COMMON/ch_timer/ ch_flops\n integer nlofphicomp\n integer ilofphilo0,ilofphilo1,ilofphilo2\n integer ilofphihi0,ilofphihi1,ilofphihi2\n REAL*8 lofphi(\n & ilofphilo0:ilofphihi0,\n & ilofphilo1:ilofphihi1,\n & ilofphilo2:ilofphihi2,\n & 0:nlofphicomp-1)\n integer nphicomp\n integer iphilo0,iphilo1,iphilo2\n integer iphihi0,iphihi1,iphihi2\n REAL*8 phi(\n & iphilo0:iphihi0,\n & iphilo1:iphihi1,\n & iphilo2:iphihi2,\n & 0:nphicomp-1)\n integer iregionlo0,iregionlo1,iregionlo2\n integer iregionhi0,iregionhi1,iregionhi2\n REAL*8 dx\n REAL*8 alpha\n REAL*8 beta\n REAL*8 dxinv, lap\n integer n,ncomp\n integer i,j,k\n ncomp = nphicomp\n if(ncomp .ne. nlofphicomp) then\n call MAYDAYERROR()\n endif\n dxinv = (1.0d0)/(dx*dx)\n do n = 0, ncomp-1\n do k = iregionlo2,iregionhi2\n do j = iregionlo1,iregionhi1\n do i = iregionlo0,iregionhi0\n lap = ( \n & (16.0d0)*phi(i-1,j ,k ,n) - phi(i-2,j ,k ,n)\n & + (16.0d0)*phi(i+1,j ,k ,n) - phi(i+2,j ,k ,n)\n & + (16.0d0)*phi(i ,j-1,k ,n) - phi(i ,j-2,k ,n)\n & + (16.0d0)*phi(i ,j+1,k ,n) - phi(i ,j+2,k ,n)\n & + (16.0d0)*phi(i ,j ,k-1,n) - phi(i ,j ,k-2,n)\n & + (16.0d0)*phi(i ,j ,k+1,n) - phi(i ,j ,k+2,n)\n & -((30.0d0)*3)*phi(i,j,k,n) )\n & * (1.000d0 / 12.000d0) * dxinv\n lofphi(i,j,k,n) = alpha*phi(i,j,k,n)+beta*lap\n enddo\n enddo\n enddo\n enddo\n return\n end\n subroutine OPERATORLAPRES4(\n & r\n & ,irlo0,irlo1,irlo2\n & ,irhi0,irhi1,irhi2\n & ,nrcomp\n & ,phi\n & ,iphilo0,iphilo1,iphilo2\n & ,iphihi0,iphihi1,iphihi2\n & ,nphicomp\n & ,rhs\n & ,irhslo0,irhslo1,irhslo2\n & ,irhshi0,irhshi1,irhshi2\n & ,nrhscomp\n & ,iregionlo0,iregionlo1,iregionlo2\n & ,iregionhi0,iregionhi1,iregionhi2\n & ,dx\n & ,alpha\n & ,beta\n & )\n implicit none\n integer*8 ch_flops\n COMMON/ch_timer/ ch_flops\n integer nrcomp\n integer irlo0,irlo1,irlo2\n integer irhi0,irhi1,irhi2\n REAL*8 r(\n & irlo0:irhi0,\n & irlo1:irhi1,\n & irlo2:irhi2,\n & 0:nrcomp-1)\n integer nphicomp\n integer iphilo0,iphilo1,iphilo2\n integer iphihi0,iphihi1,iphihi2\n REAL*8 phi(\n & iphilo0:iphihi0,\n & iphilo1:iphihi1,\n & iphilo2:iphihi2,\n & 0:nphicomp-1)\n integer nrhscomp\n integer irhslo0,irhslo1,irhslo2\n integer irhshi0,irhshi1,irhshi2\n REAL*8 rhs(\n & irhslo0:irhshi0,\n & irhslo1:irhshi1,\n & irhslo2:irhshi2,\n & 0:nrhscomp-1)\n integer iregionlo0,iregionlo1,iregionlo2\n integer iregionhi0,iregionhi1,iregionhi2\n REAL*8 dx\n REAL*8 alpha\n REAL*8 beta\n REAL*8 dxinv, lap, lhs\n integer n,ncomp\n integer i,j,k\n ncomp = nphicomp\n dxinv = (1.0d0)/(dx*dx)\n do n = 0, ncomp-1\n do k = iregionlo2,iregionhi2\n do j = iregionlo1,iregionhi1\n do i = iregionlo0,iregionhi0\n lap = ( \n & (16.0d0)*phi(i-1,j ,k ,n) - phi(i-2,j ,k ,n)\n & + (16.0d0)*phi(i+1,j ,k ,n) - phi(i+2,j ,k ,n)\n & + (16.0d0)*phi(i ,j-1,k ,n) - phi(i ,j-2,k ,n)\n & + (16.0d0)*phi(i ,j+1,k ,n) - phi(i ,j+2,k ,n)\n & + (16.0d0)*phi(i ,j ,k-1,n) - phi(i ,j ,k-2,n)\n & + (16.0d0)*phi(i ,j ,k+1,n) - phi(i ,j ,k+2,n)\n & -((30.0d0)*3)*phi(i,j,k,n) )\n & * (1.000d0 / 12.000d0) * dxinv\n lhs = alpha*phi(i,j,k,n) + beta*lap\n r(i,j,k,n) = rhs(i,j,k,n) - lhs\n enddo\n enddo\n enddo\n enddo\n return\n end\n subroutine RESTRICTRES4(\n & res\n & ,ireslo0,ireslo1,ireslo2\n & ,ireshi0,ireshi1,ireshi2\n & ,nrescomp\n & ,phi\n & ,iphilo0,iphilo1,iphilo2\n & ,iphihi0,iphihi1,iphihi2\n & ,nphicomp\n & ,rhs\n & ,irhslo0,irhslo1,irhslo2\n & ,irhshi0,irhshi1,irhshi2\n & ,nrhscomp\n & ,alpha\n & ,beta\n & ,iregionlo0,iregionlo1,iregionlo2\n & ,iregionhi0,iregionhi1,iregionhi2\n & ,dx\n & )\n implicit none\n integer*8 ch_flops\n COMMON/ch_timer/ ch_flops\n integer nrescomp\n integer ireslo0,ireslo1,ireslo2\n integer ireshi0,ireshi1,ireshi2\n REAL*8 res(\n & ireslo0:ireshi0,\n & ireslo1:ireshi1,\n & ireslo2:ireshi2,\n & 0:nrescomp-1)\n integer nphicomp\n integer iphilo0,iphilo1,iphilo2\n integer iphihi0,iphihi1,iphihi2\n REAL*8 phi(\n & iphilo0:iphihi0,\n & iphilo1:iphihi1,\n & iphilo2:iphihi2,\n & 0:nphicomp-1)\n integer nrhscomp\n integer irhslo0,irhslo1,irhslo2\n integer irhshi0,irhshi1,irhshi2\n REAL*8 rhs(\n & irhslo0:irhshi0,\n & irhslo1:irhshi1,\n & irhslo2:irhshi2,\n & 0:nrhscomp-1)\n REAL*8 alpha\n REAL*8 beta\n integer iregionlo0,iregionlo1,iregionlo2\n integer iregionhi0,iregionhi1,iregionhi2\n REAL*8 dx\n REAL*8 denom,dxinv,lofphi,lap\n integer n,ncomp\n integer i,j,k\n integer ii,jj,kk\n ncomp = nphicomp\n dxinv = (1.0d0) / (dx*dx)\n denom = 2 *2 *2\n do n = 0, ncomp-1\n do k = iregionlo2,iregionhi2\n do j = iregionlo1,iregionhi1\n do i = iregionlo0,iregionhi0\n ii = i/2 \n jj = j/2 \n kk = k/2 \n lap = ( \n & (16.0d0)*phi(i-1,j ,k ,n) - phi(i-2,j ,k ,n)\n & + (16.0d0)*phi(i+1,j ,k ,n) - phi(i+2,j ,k ,n)\n & + (16.0d0)*phi(i ,j-1,k ,n) - phi(i ,j-2,k ,n)\n & + (16.0d0)*phi(i ,j+1,k ,n) - phi(i ,j+2,k ,n)\n & + (16.0d0)*phi(i ,j ,k-1,n) - phi(i ,j ,k-2,n)\n & + (16.0d0)*phi(i ,j ,k+1,n) - phi(i ,j ,k+2,n)\n & -((30.0d0)*3)*phi(i,j,k,n) )\n & * (1.000d0 / 12.000d0) * dxinv\n lofphi = alpha*phi(i,j,k,n) + beta*lap\n res(ii,jj,kk,n) = res(ii,jj,kk,n)\n & + (rhs(i,j,k,n) - lofphi) / denom\n enddo\n enddo\n enddo\n enddo\n return\n end\n subroutine GSRBLAPLACIAN4(\n & phi\n & ,iphilo0,iphilo1,iphilo2\n & ,iphihi0,iphihi1,iphihi2\n & ,nphicomp\n & ,rhs\n & ,irhslo0,irhslo1,irhslo2\n & ,irhshi0,irhshi1,irhshi2\n & ,nrhscomp\n & ,iregionlo0,iregionlo1,iregionlo2\n & ,iregionhi0,iregionhi1,iregionhi2\n & ,dx\n & ,tmp\n & ,itmplo0,itmplo1,itmplo2\n & ,itmphi0,itmphi1,itmphi2\n & ,ntmpcomp\n & ,redBlack\n & )\n implicit none\n integer*8 ch_flops\n COMMON/ch_timer/ ch_flops\n integer nphicomp\n integer iphilo0,iphilo1,iphilo2\n integer iphihi0,iphihi1,iphihi2\n REAL*8 phi(\n & iphilo0:iphihi0,\n & iphilo1:iphihi1,\n & iphilo2:iphihi2,\n & 0:nphicomp-1)\n integer nrhscomp\n integer irhslo0,irhslo1,irhslo2\n integer irhshi0,irhshi1,irhshi2\n REAL*8 rhs(\n & irhslo0:irhshi0,\n & irhslo1:irhshi1,\n & irhslo2:irhshi2,\n & 0:nrhscomp-1)\n integer iregionlo0,iregionlo1,iregionlo2\n integer iregionhi0,iregionhi1,iregionhi2\n REAL*8 dx\n integer ntmpcomp\n integer itmplo0,itmplo1,itmplo2\n integer itmphi0,itmphi1,itmphi2\n REAL*8 tmp(\n & itmplo0:itmphi0,\n & itmplo1:itmphi1,\n & itmplo2:itmphi2,\n & 0:ntmpcomp-1)\n integer redBlack\n REAL*8 dx2t, thD\n integer i,j,k\n integer n,ncomp,indtot,imin,imax,red,black\n red = 0\n black = 1\n dx2t = (12.0d0)*dx*dx\n thD = (1.000d0 / 30.000d0)/3\n ncomp = nphicomp\n if(ncomp .ne. nrhscomp) then\n call MAYDAYERROR()\n endif\n do n = 0, ncomp - 1\n if (redBlack .eq. red) then\n do k=iregionlo2, iregionhi2\n do j=iregionlo1, iregionhi1\n imin = iregionlo0\n indtot = imin + j + k\n imin = imin + abs(mod(indtot+red, 2))\n imax = iregionhi0\n do i = imin, imax, 2\n tmp(i,j,k,n) = thD*( \n & (16.0d0)*phi(i+1,j,k,n) - phi(i+2,j,k,n)\n & + (16.0d0)*phi(i-1,j,k,n) - phi(i-2,j,k,n)\n & + (16.0d0)*phi(i,j+1,k,n) - phi(i,j+2,k,n)\n & + (16.0d0)*phi(i,j-1,k,n) - phi(i,j-2,k,n)\n & + (16.0d0)*phi(i,j,k+1,n) - phi(i,j,k+2,n)\n & + (16.0d0)*phi(i,j,k-1,n) - phi(i,j,k-2,n) \n & - dx2t*rhs(i,j,k,n) )\n enddo\n enddo\n enddo\n else if (redBlack .eq. black) then\n do k=iregionlo2, iregionhi2\n do j=iregionlo1, iregionhi1\n imin = iregionlo0\n indtot = imin + j + k\n imin = imin + abs(mod(indtot+black, 2))\n imax = iregionhi0\n do i = imin, imax, 2\n phi(i,j,k,n) = thD*( \n & (16.0d0)*tmp(i+1,j,k,n) - tmp(i+2,j,k,n)\n & + (16.0d0)*tmp(i-1,j,k,n) - tmp(i-2,j,k,n)\n & + (16.0d0)*tmp(i,j+1,k,n) - tmp(i,j+2,k,n)\n & + (16.0d0)*tmp(i,j-1,k,n) - tmp(i,j-2,k,n)\n & + (16.0d0)*tmp(i,j,k+1,n) - tmp(i,j,k+2,n)\n & + (16.0d0)*tmp(i,j,k-1,n) - tmp(i,j,k-2,n) \n & - dx2t*rhs(i,j,k,n) )\n enddo\n enddo\n enddo\n do k=iregionlo2, iregionhi2\n do j=iregionlo1, iregionhi1\n imin = iregionlo0\n indtot = imin + j + k\n imin = imin + abs(mod(indtot+red, 2))\n imax = iregionhi0\n do i = imin, imax, 2\n phi(i,j,k,n) = tmp(i,j,k,n)\n enddo\n enddo\n enddo\n else\n call MAYDAYERROR()\n end if\n enddo\n return\n end\n subroutine SORLAPLACIAN4(\n & phi\n & ,iphilo0,iphilo1,iphilo2\n & ,iphihi0,iphihi1,iphihi2\n & ,nphicomp\n & ,rhs\n & ,irhslo0,irhslo1,irhslo2\n & ,irhshi0,irhshi1,irhshi2\n & ,nrhscomp\n & ,iregionlo0,iregionlo1,iregionlo2\n & ,iregionhi0,iregionhi1,iregionhi2\n & ,dx\n & )\n implicit none\n integer*8 ch_flops\n COMMON/ch_timer/ ch_flops\n integer nphicomp\n integer iphilo0,iphilo1,iphilo2\n integer iphihi0,iphihi1,iphihi2\n REAL*8 phi(\n & iphilo0:iphihi0,\n & iphilo1:iphihi1,\n & iphilo2:iphihi2,\n & 0:nphicomp-1)\n integer nrhscomp\n integer irhslo0,irhslo1,irhslo2\n integer irhshi0,irhshi1,irhshi2\n REAL*8 rhs(\n & irhslo0:irhshi0,\n & irhslo1:irhshi1,\n & irhslo2:irhshi2,\n & 0:nrhscomp-1)\n integer iregionlo0,iregionlo1,iregionlo2\n integer iregionhi0,iregionhi1,iregionhi2\n REAL*8 dx\n REAL*8 dx2t, thD, tmp, omega\n integer i,j,k\n integer n,ncomp\n dx2t = (12.0d0)*dx*dx\n thD = (1.000d0 / 30.000d0)/3\n omega = 0.47\n ncomp = nphicomp\n if(ncomp .ne. nrhscomp) then\n call MAYDAYERROR()\n endif\n do n = 0, ncomp - 1\n do k = iregionlo2,iregionhi2\n do j = iregionlo1,iregionhi1\n do i = iregionlo0,iregionhi0\n tmp = thD*( \n & (16.0d0)*phi(i+1,j,k,n) - phi(i+2,j,k,n)\n & + (16.0d0)*phi(i-1,j,k,n) - phi(i-2,j,k,n)\n & + (16.0d0)*phi(i,j+1,k,n) - phi(i,j+2,k,n)\n & + (16.0d0)*phi(i,j-1,k,n) - phi(i,j-2,k,n)\n & + (16.0d0)*phi(i,j,k+1,n) - phi(i,j,k+2,n)\n & + (16.0d0)*phi(i,j,k-1,n) - phi(i,j,k-2,n) \n & - dx2t*rhs(i,j,k,n) )\n phi(i,j,k,n) = omega*tmp\n & + ((1.0d0)-omega)*phi(i,j,k,n)\n enddo\n enddo\n enddo\n enddo\n return\n end\n subroutine GSRBHELMHOLTZ4(\n & phi\n & ,iphilo0,iphilo1,iphilo2\n & ,iphihi0,iphihi1,iphihi2\n & ,nphicomp\n & ,rhs\n & ,irhslo0,irhslo1,irhslo2\n & ,irhshi0,irhshi1,irhshi2\n & ,nrhscomp\n & ,iregionlo0,iregionlo1,iregionlo2\n & ,iregionhi0,iregionhi1,iregionhi2\n & ,dx\n & ,tmp\n & ,itmplo0,itmplo1,itmplo2\n & ,itmphi0,itmphi1,itmphi2\n & ,ntmpcomp\n & ,alpha\n & ,beta\n & ,redBlack\n & )\n implicit none\n integer*8 ch_flops\n COMMON/ch_timer/ ch_flops\n integer nphicomp\n integer iphilo0,iphilo1,iphilo2\n integer iphihi0,iphihi1,iphihi2\n REAL*8 phi(\n & iphilo0:iphihi0,\n & iphilo1:iphihi1,\n & iphilo2:iphihi2,\n & 0:nphicomp-1)\n integer nrhscomp\n integer irhslo0,irhslo1,irhslo2\n integer irhshi0,irhshi1,irhshi2\n REAL*8 rhs(\n & irhslo0:irhshi0,\n & irhslo1:irhshi1,\n & irhslo2:irhshi2,\n & 0:nrhscomp-1)\n integer iregionlo0,iregionlo1,iregionlo2\n integer iregionhi0,iregionhi1,iregionhi2\n REAL*8 dx\n integer ntmpcomp\n integer itmplo0,itmplo1,itmplo2\n integer itmphi0,itmphi1,itmphi2\n REAL*8 tmp(\n & itmplo0:itmphi0,\n & itmplo1:itmphi1,\n & itmplo2:itmphi2,\n & 0:ntmpcomp-1)\n REAL*8 alpha\n REAL*8 beta\n integer redBlack\n REAL*8 dx2t, lambda, lap, dxinv, helm\n integer i,j,k\n integer n,ncomp,indtot,imin,imax,red,black\n red = 0\n black = 1\n dx2t = (12.0d0)*dx*dx\n dxinv = (1.0d0)/(dx*dx)\n lambda = (1.0d0)/(alpha - beta*(30.0d0)*3*(1.000d0 / 12.000d0)*dxi\n &nv)\n lambda = lambda*(0.60)\n ncomp = nphicomp\n if(ncomp .ne. nrhscomp) then\n call MAYDAYERROR()\n endif\n do n = 0, ncomp - 1\n if (redBlack .eq. red) then\n do k=iregionlo2, iregionhi2\n do j=iregionlo1, iregionhi1\n imin = iregionlo0\n indtot = imin + j + k\n imin = imin + abs(mod(indtot+red, 2))\n imax = iregionhi0\n do i = imin, imax, 2\n lap = ( \n & (16.0d0)*phi(i-1,j ,k ,n) - phi(i-2,j ,k ,n)\n & + (16.0d0)*phi(i+1,j ,k ,n) - phi(i+2,j ,k ,n)\n & + (16.0d0)*phi(i ,j-1,k ,n) - phi(i ,j-2,k ,n)\n & + (16.0d0)*phi(i ,j+1,k ,n) - phi(i ,j+2,k ,n)\n & + (16.0d0)*phi(i ,j ,k-1,n) - phi(i ,j ,k-2,n)\n & + (16.0d0)*phi(i ,j ,k+1,n) - phi(i ,j ,k+2,n)\n & -((30.0d0)*3)*phi(i,j,k,n) )\n & * (1.000d0 / 12.000d0) * dxinv\n helm = alpha*phi(i,j,k,n) + beta*lap\n tmp(i,j,k,n) = phi(i,j,k,n) +\n & lambda*( rhs(i,j,k,n) - helm )\n enddo\n enddo\n enddo\n else if (redBlack .eq. black) then\n do k=iregionlo2, iregionhi2\n do j=iregionlo1, iregionhi1\n imin = iregionlo0\n indtot = imin + j + k\n imin = imin + abs(mod(indtot+black, 2))\n imax = iregionhi0\n do i = imin, imax, 2\n lap = ( \n & (16.0d0)*tmp(i+1,j,k,n) - tmp(i+2,j,k,n)\n & + (16.0d0)*tmp(i-1,j,k,n) - tmp(i-2,j,k,n)\n & + (16.0d0)*tmp(i,j+1,k,n) - tmp(i,j+2,k,n)\n & + (16.0d0)*tmp(i,j-1,k,n) - tmp(i,j-2,k,n)\n & + (16.0d0)*tmp(i,j,k+1,n) - tmp(i,j,k+2,n)\n & + (16.0d0)*tmp(i,j,k-1,n) - tmp(i,j,k-2,n) \n & -((30.0d0)*3)*tmp(i,j,k,n) )\n & * (1.000d0 / 12.000d0) * dxinv\n helm = alpha*tmp(i,j,k,n) + beta*lap\n phi(i,j,k,n) = tmp(i,j,k,n) +\n & lambda*( rhs(i,j,k,n) - helm )\n enddo\n enddo\n enddo\n do k=iregionlo2, iregionhi2\n do j=iregionlo1, iregionhi1\n imin = iregionlo0\n indtot = imin + j + k\n imin = imin + abs(mod(indtot+red, 2))\n imax = iregionhi0\n do i = imin, imax, 2\n phi(i,j,k,n) = tmp(i,j,k,n)\n enddo\n enddo\n enddo\n else\n call MAYDAYERROR()\n end if\n enddo\n return\n end\n subroutine NEWGETFLUX4(\n & flux\n & ,ifluxlo0,ifluxlo1,ifluxlo2\n & ,ifluxhi0,ifluxhi1,ifluxhi2\n & ,nfluxcomp\n & ,phi\n & ,iphilo0,iphilo1,iphilo2\n & ,iphihi0,iphihi1,iphihi2\n & ,nphicomp\n & ,iboxlo0,iboxlo1,iboxlo2\n & ,iboxhi0,iboxhi1,iboxhi2\n & ,beta_dx\n & ,a_idir\n & )\n implicit none\n integer*8 ch_flops\n COMMON/ch_timer/ ch_flops\n integer CHF_ID(0:5,0:5)\n data CHF_ID/ 1,0,0,0,0,0 ,0,1,0,0,0,0 ,0,0,1,0,0,0 ,0,0,0,1,0,0 ,0\n &,0,0,0,1,0 ,0,0,0,0,0,1 /\n integer nfluxcomp\n integer ifluxlo0,ifluxlo1,ifluxlo2\n integer ifluxhi0,ifluxhi1,ifluxhi2\n REAL*8 flux(\n & ifluxlo0:ifluxhi0,\n & ifluxlo1:ifluxhi1,\n & ifluxlo2:ifluxhi2,\n & 0:nfluxcomp-1)\n integer nphicomp\n integer iphilo0,iphilo1,iphilo2\n integer iphihi0,iphihi1,iphihi2\n REAL*8 phi(\n & iphilo0:iphihi0,\n & iphilo1:iphihi1,\n & iphilo2:iphihi2,\n & 0:nphicomp-1)\n integer iboxlo0,iboxlo1,iboxlo2\n integer iboxhi0,iboxhi1,iboxhi2\n REAL*8 beta_dx\n integer a_idir\n INTEGER ncomp,n\n integer ii, jj, kk\n integer i , j , k \n ncomp = nphicomp\n ii = CHF_ID(a_idir, 0)\n jj = CHF_ID(a_idir, 1)\n kk = CHF_ID(a_idir, 2)\n do n = 0, ncomp-1\n do k = iboxlo2,iboxhi2\n do j = iboxlo1,iboxhi1\n do i = iboxlo0,iboxhi0\n flux(i,j,k,n) = beta_dx * (1.000d0 / 12.000d0) *\n & ( (15.0d0)*phi(i,j,k,n)\n & + phi(i-2*ii,j-2*jj,k-2*kk,n)\n & - phi(i+ii,j+jj,k+kk,n)\n & - (15.0d0)*phi(i-ii,j-jj,k-kk,n) )\n enddo\n enddo\n enddo\n enddo\n return\n end\n subroutine PROLONGLINEAR(\n & phi\n & ,iphilo0,iphilo1,iphilo2\n & ,iphihi0,iphihi1,iphihi2\n & ,nphicomp\n & ,coarse\n & ,icoarselo0,icoarselo1,icoarselo2\n & ,icoarsehi0,icoarsehi1,icoarsehi2\n & ,ncoarsecomp\n & ,ifineBoxlo0,ifineBoxlo1,ifineBoxlo2\n & ,ifineBoxhi0,ifineBoxhi1,ifineBoxhi2\n & ,icrseBoxlo0,icrseBoxlo1,icrseBoxlo2\n & ,icrseBoxhi0,icrseBoxhi1,icrseBoxhi2\n & ,r\n & )\n implicit none\n integer*8 ch_flops\n COMMON/ch_timer/ ch_flops\n integer nphicomp\n integer iphilo0,iphilo1,iphilo2\n integer iphihi0,iphihi1,iphihi2\n REAL*8 phi(\n & iphilo0:iphihi0,\n & iphilo1:iphihi1,\n & iphilo2:iphihi2,\n & 0:nphicomp-1)\n integer ncoarsecomp\n integer icoarselo0,icoarselo1,icoarselo2\n integer icoarsehi0,icoarsehi1,icoarsehi2\n REAL*8 coarse(\n & icoarselo0:icoarsehi0,\n & icoarselo1:icoarsehi1,\n & icoarselo2:icoarsehi2,\n & 0:ncoarsecomp-1)\n integer ifineBoxlo0,ifineBoxlo1,ifineBoxlo2\n integer ifineBoxhi0,ifineBoxhi1,ifineBoxhi2\n integer icrseBoxlo0,icrseBoxlo1,icrseBoxlo2\n integer icrseBoxhi0,icrseBoxhi1,icrseBoxhi2\n integer r\n INTEGER ncomp, n\n integer i ,j ,k \n integer ic,jc,kc\n ncomp = nphicomp\n do n = 0, ncomp-1\n do k = ifineBoxlo2,ifineBoxhi2\n do j = ifineBoxlo1,ifineBoxhi1\n do i = ifineBoxlo0,ifineBoxhi0\n ic = i/r\n jc = j/r\n kc = k/r\n phi(i,j,k,n) = phi(i,j,k,n) +\n & coarse(ic,jc,kc,n)\n if (ic.ne.icrseBoxhi0 .and.\n & (ic*r.lt.i .or. ic.eq.icrseBoxlo0)) then\n phi(i,j,k,n) = phi(i,j,k,n) +\n & (coarse(ic+1,jc,kc,n)\n & - coarse(ic,jc,kc,n))/r*(i+(0.500d0)-ic*r-(0.500d0)*\n &r)\n else\n phi(i,j,k,n) = phi(i,j,k,n) +\n & (- coarse(ic-1,jc,kc,n)\n & + coarse(ic,jc,kc,n))/r*(i+(0.500d0)-ic*r-(0.500d0)*\n &r)\n endif\n if (jc.ne.icrseBoxhi1 .and.\n & (jc*r.lt.j .or. jc.eq.icrseBoxlo1)) then\n phi(i,j,k,n) = phi(i,j,k,n) +\n & (coarse(ic,jc+1,kc,n)\n & - coarse(ic,jc,kc,n))/r*(j+(0.500d0)-jc*r-(0.500d0)*\n &r)\n else\n phi(i,j,k,n) = phi(i,j,k,n) +\n & (- coarse(ic,jc-1,kc,n)\n & + coarse(ic,jc,kc,n))/r*(j+(0.500d0)-jc*r-(0.500d0)*\n &r)\n endif\n if (kc.ne.icrseBoxhi2 .and.\n & (kc*r.lt.k .or. kc.eq.icrseBoxlo2)) then\n phi(i,j,k,n) = phi(i,j,k,n) +\n & (coarse(ic,jc,kc+1,n)\n & - coarse(ic,jc,kc,n))/r*(k+(0.500d0)-kc*r-(0.500d0)*\n &r)\n else\n phi(i,j,k,n) = phi(i,j,k,n) +\n & (- coarse(ic,jc,kc-1,n)\n & + coarse(ic,jc,kc,n))/r*(k+(0.500d0)-kc*r-(0.500d0)*\n &r)\n endif\n enddo\n enddo\n enddo\n enddo\n return\n end\n", "meta": {"hexsha": "43da8c5f95bf3cbd4cad3415e9a7db4d99e9a8b4", "size": 22745, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "lib/src/AMRElliptic/f/3d.Darwin.64.clang++.gfortran.DEBUG.OPTHIGH/NewPoissonOp4F.f", "max_stars_repo_name": "88Sasha88/Chombo_3.2", "max_stars_repo_head_hexsha": "b2a17351a1ec71995408d4f1a6079d1247a8a9e6", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lib/src/AMRElliptic/f/3d.Darwin.64.clang++.gfortran.DEBUG.OPTHIGH/NewPoissonOp4F.f", "max_issues_repo_name": "88Sasha88/Chombo_3.2", "max_issues_repo_head_hexsha": "b2a17351a1ec71995408d4f1a6079d1247a8a9e6", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lib/src/AMRElliptic/f/3d.Darwin.64.clang++.gfortran.DEBUG.OPTHIGH/NewPoissonOp4F.f", "max_forks_repo_name": "88Sasha88/Chombo_3.2", "max_forks_repo_head_hexsha": "b2a17351a1ec71995408d4f1a6079d1247a8a9e6", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.6795977011, "max_line_length": 72, "alphanum_fraction": 0.4681468455, "num_tokens": 8946, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314617436727, "lm_q2_score": 0.7799928900257126, "lm_q1q2_score": 0.6907862433431435}} {"text": "*> \\brief \\b DDRGSX\n*\n* =========== DOCUMENTATION ===========\n*\n* Online html documentation available at\n* http://www.netlib.org/lapack/explore-html/\n*\n* Definition:\n* ===========\n*\n* SUBROUTINE DDRGSX( NSIZE, NCMAX, THRESH, NIN, NOUT, A, LDA, B, AI,\n* BI, Z, Q, ALPHAR, ALPHAI, BETA, C, LDC, S,\n* WORK, LWORK, IWORK, LIWORK, BWORK, INFO )\n*\n* .. Scalar Arguments ..\n* INTEGER INFO, LDA, LDC, LIWORK, LWORK, NCMAX, NIN,\n* $ NOUT, NSIZE\n* DOUBLE PRECISION THRESH\n* ..\n* .. Array Arguments ..\n* LOGICAL BWORK( * )\n* INTEGER IWORK( * )\n* DOUBLE PRECISION A( LDA, * ), AI( LDA, * ), ALPHAI( * ),\n* $ ALPHAR( * ), B( LDA, * ), BETA( * ),\n* $ BI( LDA, * ), C( LDC, * ), Q( LDA, * ), S( * ),\n* $ WORK( * ), Z( LDA, * )\n* ..\n*\n*\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*>\n*> DDRGSX checks the nonsymmetric generalized eigenvalue (Schur form)\n*> problem expert driver DGGESX.\n*>\n*> DGGESX factors A and B as Q S Z' and Q T Z', where ' means\n*> transpose, T is upper triangular, S is in generalized Schur form\n*> (block upper triangular, with 1x1 and 2x2 blocks on the diagonal,\n*> the 2x2 blocks corresponding to complex conjugate pairs of\n*> generalized eigenvalues), and Q and Z are orthogonal. It also\n*> computes the generalized eigenvalues (alpha(1),beta(1)), ...,\n*> (alpha(n),beta(n)). Thus, w(j) = alpha(j)/beta(j) is a root of the\n*> characteristic equation\n*>\n*> det( A - w(j) B ) = 0\n*>\n*> Optionally it also reorders the eigenvalues so that a selected\n*> cluster of eigenvalues appears in the leading diagonal block of the\n*> Schur forms; computes a reciprocal condition number for the average\n*> of the selected eigenvalues; and computes a reciprocal condition\n*> number for the right and left deflating subspaces corresponding to\n*> the selected eigenvalues.\n*>\n*> When DDRGSX is called with NSIZE > 0, five (5) types of built-in\n*> matrix pairs are used to test the routine DGGESX.\n*>\n*> When DDRGSX is called with NSIZE = 0, it reads in test matrix data\n*> to test DGGESX.\n*>\n*> For each matrix pair, the following tests will be performed and\n*> compared with the threshold THRESH except for the tests (7) and (9):\n*>\n*> (1) | A - Q S Z' | / ( |A| n ulp )\n*>\n*> (2) | B - Q T Z' | / ( |B| n ulp )\n*>\n*> (3) | I - QQ' | / ( n ulp )\n*>\n*> (4) | I - ZZ' | / ( n ulp )\n*>\n*> (5) if A is in Schur form (i.e. quasi-triangular form)\n*>\n*> (6) maximum over j of D(j) where:\n*>\n*> if alpha(j) is real:\n*> |alpha(j) - S(j,j)| |beta(j) - T(j,j)|\n*> D(j) = ------------------------ + -----------------------\n*> max(|alpha(j)|,|S(j,j)|) max(|beta(j)|,|T(j,j)|)\n*>\n*> if alpha(j) is complex:\n*> | det( s S - w T ) |\n*> D(j) = ---------------------------------------------------\n*> ulp max( s norm(S), |w| norm(T) )*norm( s S - w T )\n*>\n*> and S and T are here the 2 x 2 diagonal blocks of S and T\n*> corresponding to the j-th and j+1-th eigenvalues.\n*>\n*> (7) if sorting worked and SDIM is the number of eigenvalues\n*> which were selected.\n*>\n*> (8) the estimated value DIF does not differ from the true values of\n*> Difu and Difl more than a factor 10*THRESH. If the estimate DIF\n*> equals zero the corresponding true values of Difu and Difl\n*> should be less than EPS*norm(A, B). If the true value of Difu\n*> and Difl equal zero, the estimate DIF should be less than\n*> EPS*norm(A, B).\n*>\n*> (9) If INFO = N+3 is returned by DGGESX, the reordering \"failed\"\n*> and we check that DIF = PL = PR = 0 and that the true value of\n*> Difu and Difl is < EPS*norm(A, B). We count the events when\n*> INFO=N+3.\n*>\n*> For read-in test matrices, the above tests are run except that the\n*> exact value for DIF (and PL) is input data. Additionally, there is\n*> one more test run for read-in test matrices:\n*>\n*> (10) the estimated value PL does not differ from the true value of\n*> PLTRU more than a factor THRESH. If the estimate PL equals\n*> zero the corresponding true value of PLTRU should be less than\n*> EPS*norm(A, B). If the true value of PLTRU equal zero, the\n*> estimate PL should be less than EPS*norm(A, B).\n*>\n*> Note that for the built-in tests, a total of 10*NSIZE*(NSIZE-1)\n*> matrix pairs are generated and tested. NSIZE should be kept small.\n*>\n*> SVD (routine DGESVD) is used for computing the true value of DIF_u\n*> and DIF_l when testing the built-in test problems.\n*>\n*> Built-in Test Matrices\n*> ======================\n*>\n*> All built-in test matrices are the 2 by 2 block of triangular\n*> matrices\n*>\n*> A = [ A11 A12 ] and B = [ B11 B12 ]\n*> [ A22 ] [ B22 ]\n*>\n*> where for different type of A11 and A22 are given as the following.\n*> A12 and B12 are chosen so that the generalized Sylvester equation\n*>\n*> A11*R - L*A22 = -A12\n*> B11*R - L*B22 = -B12\n*>\n*> have prescribed solution R and L.\n*>\n*> Type 1: A11 = J_m(1,-1) and A_22 = J_k(1-a,1).\n*> B11 = I_m, B22 = I_k\n*> where J_k(a,b) is the k-by-k Jordan block with ``a'' on\n*> diagonal and ``b'' on superdiagonal.\n*>\n*> Type 2: A11 = (a_ij) = ( 2(.5-sin(i)) ) and\n*> B11 = (b_ij) = ( 2(.5-sin(ij)) ) for i=1,...,m, j=i,...,m\n*> A22 = (a_ij) = ( 2(.5-sin(i+j)) ) and\n*> B22 = (b_ij) = ( 2(.5-sin(ij)) ) for i=m+1,...,k, j=i,...,k\n*>\n*> Type 3: A11, A22 and B11, B22 are chosen as for Type 2, but each\n*> second diagonal block in A_11 and each third diagonal block\n*> in A_22 are made as 2 by 2 blocks.\n*>\n*> Type 4: A11 = ( 20(.5 - sin(ij)) ) and B22 = ( 2(.5 - sin(i+j)) )\n*> for i=1,...,m, j=1,...,m and\n*> A22 = ( 20(.5 - sin(i+j)) ) and B22 = ( 2(.5 - sin(ij)) )\n*> for i=m+1,...,k, j=m+1,...,k\n*>\n*> Type 5: (A,B) and have potentially close or common eigenvalues and\n*> very large departure from block diagonality A_11 is chosen\n*> as the m x m leading submatrix of A_1:\n*> | 1 b |\n*> | -b 1 |\n*> | 1+d b |\n*> | -b 1+d |\n*> A_1 = | d 1 |\n*> | -1 d |\n*> | -d 1 |\n*> | -1 -d |\n*> | 1 |\n*> and A_22 is chosen as the k x k leading submatrix of A_2:\n*> | -1 b |\n*> | -b -1 |\n*> | 1-d b |\n*> | -b 1-d |\n*> A_2 = | d 1+b |\n*> | -1-b d |\n*> | -d 1+b |\n*> | -1+b -d |\n*> | 1-d |\n*> and matrix B are chosen as identity matrices (see DLATM5).\n*>\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in] NSIZE\n*> \\verbatim\n*> NSIZE is INTEGER\n*> The maximum size of the matrices to use. NSIZE >= 0.\n*> If NSIZE = 0, no built-in tests matrices are used, but\n*> read-in test matrices are used to test DGGESX.\n*> \\endverbatim\n*>\n*> \\param[in] NCMAX\n*> \\verbatim\n*> NCMAX is INTEGER\n*> Maximum allowable NMAX for generating Kroneker matrix\n*> in call to DLAKF2\n*> \\endverbatim\n*>\n*> \\param[in] THRESH\n*> \\verbatim\n*> THRESH is DOUBLE PRECISION\n*> A test will count as \"failed\" if the \"error\", computed as\n*> described above, exceeds THRESH. Note that the error\n*> is scaled to be O(1), so THRESH should be a reasonably\n*> small multiple of 1, e.g., 10 or 100. In particular,\n*> it should not depend on the precision (single vs. double)\n*> or the size of the matrix. THRESH >= 0.\n*> \\endverbatim\n*>\n*> \\param[in] NIN\n*> \\verbatim\n*> NIN is INTEGER\n*> The FORTRAN unit number for reading in the data file of\n*> problems to solve.\n*> \\endverbatim\n*>\n*> \\param[in] NOUT\n*> \\verbatim\n*> NOUT is INTEGER\n*> The FORTRAN unit number for printing out error messages\n*> (e.g., if a routine returns IINFO not equal to 0.)\n*> \\endverbatim\n*>\n*> \\param[out] A\n*> \\verbatim\n*> A is DOUBLE PRECISION array, dimension (LDA, NSIZE)\n*> Used to store the matrix whose eigenvalues are to be\n*> computed. On exit, A contains the last matrix actually used.\n*> \\endverbatim\n*>\n*> \\param[in] LDA\n*> \\verbatim\n*> LDA is INTEGER\n*> The leading dimension of A, B, AI, BI, Z and Q,\n*> LDA >= max( 1, NSIZE ). For the read-in test,\n*> LDA >= max( 1, N ), N is the size of the test matrices.\n*> \\endverbatim\n*>\n*> \\param[out] B\n*> \\verbatim\n*> B is DOUBLE PRECISION array, dimension (LDA, NSIZE)\n*> Used to store the matrix whose eigenvalues are to be\n*> computed. On exit, B contains the last matrix actually used.\n*> \\endverbatim\n*>\n*> \\param[out] AI\n*> \\verbatim\n*> AI is DOUBLE PRECISION array, dimension (LDA, NSIZE)\n*> Copy of A, modified by DGGESX.\n*> \\endverbatim\n*>\n*> \\param[out] BI\n*> \\verbatim\n*> BI is DOUBLE PRECISION array, dimension (LDA, NSIZE)\n*> Copy of B, modified by DGGESX.\n*> \\endverbatim\n*>\n*> \\param[out] Z\n*> \\verbatim\n*> Z is DOUBLE PRECISION array, dimension (LDA, NSIZE)\n*> Z holds the left Schur vectors computed by DGGESX.\n*> \\endverbatim\n*>\n*> \\param[out] Q\n*> \\verbatim\n*> Q is DOUBLE PRECISION array, dimension (LDA, NSIZE)\n*> Q holds the right Schur vectors computed by DGGESX.\n*> \\endverbatim\n*>\n*> \\param[out] ALPHAR\n*> \\verbatim\n*> ALPHAR is DOUBLE PRECISION array, dimension (NSIZE)\n*> \\endverbatim\n*>\n*> \\param[out] ALPHAI\n*> \\verbatim\n*> ALPHAI is DOUBLE PRECISION array, dimension (NSIZE)\n*> \\endverbatim\n*>\n*> \\param[out] BETA\n*> \\verbatim\n*> BETA is DOUBLE PRECISION array, dimension (NSIZE)\n*>\n*> On exit, (ALPHAR + ALPHAI*i)/BETA are the eigenvalues.\n*> \\endverbatim\n*>\n*> \\param[out] C\n*> \\verbatim\n*> C is DOUBLE PRECISION array, dimension (LDC, LDC)\n*> Store the matrix generated by subroutine DLAKF2, this is the\n*> matrix formed by Kronecker products used for estimating\n*> DIF.\n*> \\endverbatim\n*>\n*> \\param[in] LDC\n*> \\verbatim\n*> LDC is INTEGER\n*> The leading dimension of C. LDC >= max(1, LDA*LDA/2 ).\n*> \\endverbatim\n*>\n*> \\param[out] S\n*> \\verbatim\n*> S is DOUBLE PRECISION array, dimension (LDC)\n*> Singular values of C\n*> \\endverbatim\n*>\n*> \\param[out] WORK\n*> \\verbatim\n*> WORK is DOUBLE PRECISION array, dimension (LWORK)\n*> \\endverbatim\n*>\n*> \\param[in] LWORK\n*> \\verbatim\n*> LWORK is INTEGER\n*> The dimension of the array WORK.\n*> LWORK >= MAX( 5*NSIZE*NSIZE/2 - 2, 10*(NSIZE+1) )\n*> \\endverbatim\n*>\n*> \\param[out] IWORK\n*> \\verbatim\n*> IWORK is INTEGER array, dimension (LIWORK)\n*> \\endverbatim\n*>\n*> \\param[in] LIWORK\n*> \\verbatim\n*> LIWORK is INTEGER\n*> The dimension of the array IWORK. LIWORK >= NSIZE + 6.\n*> \\endverbatim\n*>\n*> \\param[out] BWORK\n*> \\verbatim\n*> BWORK is LOGICAL array, dimension (LDA)\n*> \\endverbatim\n*>\n*> \\param[out] INFO\n*> \\verbatim\n*> INFO is INTEGER\n*> = 0: successful exit\n*> < 0: if INFO = -i, the i-th argument had an illegal value.\n*> > 0: A routine returned an error code.\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee\n*> \\author Univ. of California Berkeley\n*> \\author Univ. of Colorado Denver\n*> \\author NAG Ltd.\n*\n*> \\date June 2016\n*\n*> \\ingroup double_eig\n*\n* =====================================================================\n SUBROUTINE DDRGSX( NSIZE, NCMAX, THRESH, NIN, NOUT, A, LDA, B, AI,\n $ BI, Z, Q, ALPHAR, ALPHAI, BETA, C, LDC, S,\n $ WORK, LWORK, IWORK, LIWORK, BWORK, INFO )\n*\n* -- LAPACK test routine (version 3.7.0) --\n* -- LAPACK is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n* June 2016\n*\n* .. Scalar Arguments ..\n INTEGER INFO, LDA, LDC, LIWORK, LWORK, NCMAX, NIN,\n $ NOUT, NSIZE\n DOUBLE PRECISION THRESH\n* ..\n* .. Array Arguments ..\n LOGICAL BWORK( * )\n INTEGER IWORK( * )\n DOUBLE PRECISION A( LDA, * ), AI( LDA, * ), ALPHAI( * ),\n $ ALPHAR( * ), B( LDA, * ), BETA( * ),\n $ BI( LDA, * ), C( LDC, * ), Q( LDA, * ), S( * ),\n $ WORK( * ), Z( LDA, * )\n* ..\n*\n* =====================================================================\n*\n* .. Parameters ..\n DOUBLE PRECISION ZERO, ONE, TEN\n PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0, TEN = 1.0D+1 )\n* ..\n* .. Local Scalars ..\n LOGICAL ILABAD\n CHARACTER SENSE\n INTEGER BDSPAC, I, I1, IFUNC, IINFO, J, LINFO, MAXWRK,\n $ MINWRK, MM, MN2, NERRS, NPTKNT, NTEST, NTESTT,\n $ PRTYPE, QBA, QBB\n DOUBLE PRECISION ABNRM, BIGNUM, DIFTRU, PLTRU, SMLNUM, TEMP1,\n $ TEMP2, THRSH2, ULP, ULPINV, WEIGHT\n* ..\n* .. Local Arrays ..\n DOUBLE PRECISION DIFEST( 2 ), PL( 2 ), RESULT( 10 )\n* ..\n* .. External Functions ..\n LOGICAL DLCTSX\n INTEGER ILAENV\n DOUBLE PRECISION DLAMCH, DLANGE\n EXTERNAL DLCTSX, ILAENV, DLAMCH, DLANGE\n* ..\n* .. External Subroutines ..\n EXTERNAL ALASVM, DGESVD, DGET51, DGET53, DGGESX, DLABAD,\n $ DLACPY, DLAKF2, DLASET, DLATM5, XERBLA\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC ABS, MAX, SQRT\n* ..\n* .. Scalars in Common ..\n LOGICAL FS\n INTEGER K, M, MPLUSN, N\n* ..\n* .. Common blocks ..\n COMMON / MN / M, N, MPLUSN, K, FS\n* ..\n* .. Executable Statements ..\n*\n* Check for errors\n*\n IF( NSIZE.LT.0 ) THEN\n INFO = -1\n ELSE IF( THRESH.LT.ZERO ) THEN\n INFO = -2\n ELSE IF( NIN.LE.0 ) THEN\n INFO = -3\n ELSE IF( NOUT.LE.0 ) THEN\n INFO = -4\n ELSE IF( LDA.LT.1 .OR. LDA.LT.NSIZE ) THEN\n INFO = -6\n ELSE IF( LDC.LT.1 .OR. LDC.LT.NSIZE*NSIZE / 2 ) THEN\n INFO = -17\n ELSE IF( LIWORK.LT.NSIZE+6 ) THEN\n INFO = -21\n END IF\n*\n* Compute workspace\n* (Note: Comments in the code beginning \"Workspace:\" describe the\n* minimal amount of workspace needed at that point in the code,\n* as well as the preferred amount for good performance.\n* NB refers to the optimal block size for the immediately\n* following subroutine, as returned by ILAENV.)\n*\n MINWRK = 1\n IF( INFO.EQ.0 .AND. LWORK.GE.1 ) THEN\n MINWRK = MAX( 10*( NSIZE+1 ), 5*NSIZE*NSIZE / 2 )\n*\n* workspace for sggesx\n*\n MAXWRK = 9*( NSIZE+1 ) + NSIZE*\n $ ILAENV( 1, 'DGEQRF', ' ', NSIZE, 1, NSIZE, 0 )\n MAXWRK = MAX( MAXWRK, 9*( NSIZE+1 )+NSIZE*\n $ ILAENV( 1, 'DORGQR', ' ', NSIZE, 1, NSIZE, -1 ) )\n*\n* workspace for dgesvd\n*\n BDSPAC = 5*NSIZE*NSIZE / 2\n MAXWRK = MAX( MAXWRK, 3*NSIZE*NSIZE / 2+NSIZE*NSIZE*\n $ ILAENV( 1, 'DGEBRD', ' ', NSIZE*NSIZE / 2,\n $ NSIZE*NSIZE / 2, -1, -1 ) )\n MAXWRK = MAX( MAXWRK, BDSPAC )\n*\n MAXWRK = MAX( MAXWRK, MINWRK )\n*\n WORK( 1 ) = MAXWRK\n END IF\n*\n IF( LWORK.LT.MINWRK )\n $ INFO = -19\n*\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'DDRGSX', -INFO )\n RETURN\n END IF\n*\n* Important constants\n*\n ULP = DLAMCH( 'P' )\n ULPINV = ONE / ULP\n SMLNUM = DLAMCH( 'S' ) / ULP\n BIGNUM = ONE / SMLNUM\n CALL DLABAD( SMLNUM, BIGNUM )\n THRSH2 = TEN*THRESH\n NTESTT = 0\n NERRS = 0\n*\n* Go to the tests for read-in matrix pairs\n*\n IFUNC = 0\n IF( NSIZE.EQ.0 )\n $ GO TO 70\n*\n* Test the built-in matrix pairs.\n* Loop over different functions (IFUNC) of DGGESX, types (PRTYPE)\n* of test matrices, different size (M+N)\n*\n PRTYPE = 0\n QBA = 3\n QBB = 4\n WEIGHT = SQRT( ULP )\n*\n DO 60 IFUNC = 0, 3\n DO 50 PRTYPE = 1, 5\n DO 40 M = 1, NSIZE - 1\n DO 30 N = 1, NSIZE - M\n*\n WEIGHT = ONE / WEIGHT\n MPLUSN = M + N\n*\n* Generate test matrices\n*\n FS = .TRUE.\n K = 0\n*\n CALL DLASET( 'Full', MPLUSN, MPLUSN, ZERO, ZERO, AI,\n $ LDA )\n CALL DLASET( 'Full', MPLUSN, MPLUSN, ZERO, ZERO, BI,\n $ LDA )\n*\n CALL DLATM5( PRTYPE, M, N, AI, LDA, AI( M+1, M+1 ),\n $ LDA, AI( 1, M+1 ), LDA, BI, LDA,\n $ BI( M+1, M+1 ), LDA, BI( 1, M+1 ), LDA,\n $ Q, LDA, Z, LDA, WEIGHT, QBA, QBB )\n*\n* Compute the Schur factorization and swapping the\n* m-by-m (1,1)-blocks with n-by-n (2,2)-blocks.\n* Swapping is accomplished via the function DLCTSX\n* which is supplied below.\n*\n IF( IFUNC.EQ.0 ) THEN\n SENSE = 'N'\n ELSE IF( IFUNC.EQ.1 ) THEN\n SENSE = 'E'\n ELSE IF( IFUNC.EQ.2 ) THEN\n SENSE = 'V'\n ELSE IF( IFUNC.EQ.3 ) THEN\n SENSE = 'B'\n END IF\n*\n CALL DLACPY( 'Full', MPLUSN, MPLUSN, AI, LDA, A, LDA )\n CALL DLACPY( 'Full', MPLUSN, MPLUSN, BI, LDA, B, LDA )\n*\n CALL DGGESX( 'V', 'V', 'S', DLCTSX, SENSE, MPLUSN, AI,\n $ LDA, BI, LDA, MM, ALPHAR, ALPHAI, BETA,\n $ Q, LDA, Z, LDA, PL, DIFEST, WORK, LWORK,\n $ IWORK, LIWORK, BWORK, LINFO )\n*\n IF( LINFO.NE.0 .AND. LINFO.NE.MPLUSN+2 ) THEN\n RESULT( 1 ) = ULPINV\n WRITE( NOUT, FMT = 9999 )'DGGESX', LINFO, MPLUSN,\n $ PRTYPE\n INFO = LINFO\n GO TO 30\n END IF\n*\n* Compute the norm(A, B)\n*\n CALL DLACPY( 'Full', MPLUSN, MPLUSN, AI, LDA, WORK,\n $ MPLUSN )\n CALL DLACPY( 'Full', MPLUSN, MPLUSN, BI, LDA,\n $ WORK( MPLUSN*MPLUSN+1 ), MPLUSN )\n ABNRM = DLANGE( 'Fro', MPLUSN, 2*MPLUSN, WORK, MPLUSN,\n $ WORK )\n*\n* Do tests (1) to (4)\n*\n CALL DGET51( 1, MPLUSN, A, LDA, AI, LDA, Q, LDA, Z,\n $ LDA, WORK, RESULT( 1 ) )\n CALL DGET51( 1, MPLUSN, B, LDA, BI, LDA, Q, LDA, Z,\n $ LDA, WORK, RESULT( 2 ) )\n CALL DGET51( 3, MPLUSN, B, LDA, BI, LDA, Q, LDA, Q,\n $ LDA, WORK, RESULT( 3 ) )\n CALL DGET51( 3, MPLUSN, B, LDA, BI, LDA, Z, LDA, Z,\n $ LDA, WORK, RESULT( 4 ) )\n NTEST = 4\n*\n* Do tests (5) and (6): check Schur form of A and\n* compare eigenvalues with diagonals.\n*\n TEMP1 = ZERO\n RESULT( 5 ) = ZERO\n RESULT( 6 ) = ZERO\n*\n DO 10 J = 1, MPLUSN\n ILABAD = .FALSE.\n IF( ALPHAI( J ).EQ.ZERO ) THEN\n TEMP2 = ( ABS( ALPHAR( J )-AI( J, J ) ) /\n $ MAX( SMLNUM, ABS( ALPHAR( J ) ),\n $ ABS( AI( J, J ) ) )+\n $ ABS( BETA( J )-BI( J, J ) ) /\n $ MAX( SMLNUM, ABS( BETA( J ) ),\n $ ABS( BI( J, J ) ) ) ) / ULP\n IF( J.LT.MPLUSN ) THEN\n IF( AI( J+1, J ).NE.ZERO ) THEN\n ILABAD = .TRUE.\n RESULT( 5 ) = ULPINV\n END IF\n END IF\n IF( J.GT.1 ) THEN\n IF( AI( J, J-1 ).NE.ZERO ) THEN\n ILABAD = .TRUE.\n RESULT( 5 ) = ULPINV\n END IF\n END IF\n ELSE\n IF( ALPHAI( J ).GT.ZERO ) THEN\n I1 = J\n ELSE\n I1 = J - 1\n END IF\n IF( I1.LE.0 .OR. I1.GE.MPLUSN ) THEN\n ILABAD = .TRUE.\n ELSE IF( I1.LT.MPLUSN-1 ) THEN\n IF( AI( I1+2, I1+1 ).NE.ZERO ) THEN\n ILABAD = .TRUE.\n RESULT( 5 ) = ULPINV\n END IF\n ELSE IF( I1.GT.1 ) THEN\n IF( AI( I1, I1-1 ).NE.ZERO ) THEN\n ILABAD = .TRUE.\n RESULT( 5 ) = ULPINV\n END IF\n END IF\n IF( .NOT.ILABAD ) THEN\n CALL DGET53( AI( I1, I1 ), LDA, BI( I1, I1 ),\n $ LDA, BETA( J ), ALPHAR( J ),\n $ ALPHAI( J ), TEMP2, IINFO )\n IF( IINFO.GE.3 ) THEN\n WRITE( NOUT, FMT = 9997 )IINFO, J,\n $ MPLUSN, PRTYPE\n INFO = ABS( IINFO )\n END IF\n ELSE\n TEMP2 = ULPINV\n END IF\n END IF\n TEMP1 = MAX( TEMP1, TEMP2 )\n IF( ILABAD ) THEN\n WRITE( NOUT, FMT = 9996 )J, MPLUSN, PRTYPE\n END IF\n 10 CONTINUE\n RESULT( 6 ) = TEMP1\n NTEST = NTEST + 2\n*\n* Test (7) (if sorting worked)\n*\n RESULT( 7 ) = ZERO\n IF( LINFO.EQ.MPLUSN+3 ) THEN\n RESULT( 7 ) = ULPINV\n ELSE IF( MM.NE.N ) THEN\n RESULT( 7 ) = ULPINV\n END IF\n NTEST = NTEST + 1\n*\n* Test (8): compare the estimated value DIF and its\n* value. first, compute the exact DIF.\n*\n RESULT( 8 ) = ZERO\n MN2 = MM*( MPLUSN-MM )*2\n IF( IFUNC.GE.2 .AND. MN2.LE.NCMAX*NCMAX ) THEN\n*\n* Note: for either following two causes, there are\n* almost same number of test cases fail the test.\n*\n CALL DLAKF2( MM, MPLUSN-MM, AI, LDA,\n $ AI( MM+1, MM+1 ), BI,\n $ BI( MM+1, MM+1 ), C, LDC )\n*\n CALL DGESVD( 'N', 'N', MN2, MN2, C, LDC, S, WORK,\n $ 1, WORK( 2 ), 1, WORK( 3 ), LWORK-2,\n $ INFO )\n DIFTRU = S( MN2 )\n*\n IF( DIFEST( 2 ).EQ.ZERO ) THEN\n IF( DIFTRU.GT.ABNRM*ULP )\n $ RESULT( 8 ) = ULPINV\n ELSE IF( DIFTRU.EQ.ZERO ) THEN\n IF( DIFEST( 2 ).GT.ABNRM*ULP )\n $ RESULT( 8 ) = ULPINV\n ELSE IF( ( DIFTRU.GT.THRSH2*DIFEST( 2 ) ) .OR.\n $ ( DIFTRU*THRSH2.LT.DIFEST( 2 ) ) ) THEN\n RESULT( 8 ) = MAX( DIFTRU / DIFEST( 2 ),\n $ DIFEST( 2 ) / DIFTRU )\n END IF\n NTEST = NTEST + 1\n END IF\n*\n* Test (9)\n*\n RESULT( 9 ) = ZERO\n IF( LINFO.EQ.( MPLUSN+2 ) ) THEN\n IF( DIFTRU.GT.ABNRM*ULP )\n $ RESULT( 9 ) = ULPINV\n IF( ( IFUNC.GT.1 ) .AND. ( DIFEST( 2 ).NE.ZERO ) )\n $ RESULT( 9 ) = ULPINV\n IF( ( IFUNC.EQ.1 ) .AND. ( PL( 1 ).NE.ZERO ) )\n $ RESULT( 9 ) = ULPINV\n NTEST = NTEST + 1\n END IF\n*\n NTESTT = NTESTT + NTEST\n*\n* Print out tests which fail.\n*\n DO 20 J = 1, 9\n IF( RESULT( J ).GE.THRESH ) THEN\n*\n* If this is the first test to fail,\n* print a header to the data file.\n*\n IF( NERRS.EQ.0 ) THEN\n WRITE( NOUT, FMT = 9995 )'DGX'\n*\n* Matrix types\n*\n WRITE( NOUT, FMT = 9993 )\n*\n* Tests performed\n*\n WRITE( NOUT, FMT = 9992 )'orthogonal', '''',\n $ 'transpose', ( '''', I = 1, 4 )\n*\n END IF\n NERRS = NERRS + 1\n IF( RESULT( J ).LT.10000.0D0 ) THEN\n WRITE( NOUT, FMT = 9991 )MPLUSN, PRTYPE,\n $ WEIGHT, M, J, RESULT( J )\n ELSE\n WRITE( NOUT, FMT = 9990 )MPLUSN, PRTYPE,\n $ WEIGHT, M, J, RESULT( J )\n END IF\n END IF\n 20 CONTINUE\n*\n 30 CONTINUE\n 40 CONTINUE\n 50 CONTINUE\n 60 CONTINUE\n*\n GO TO 150\n*\n 70 CONTINUE\n*\n* Read in data from file to check accuracy of condition estimation\n* Read input data until N=0\n*\n NPTKNT = 0\n*\n 80 CONTINUE\n READ( NIN, FMT = *, END = 140 )MPLUSN\n IF( MPLUSN.EQ.0 )\n $ GO TO 140\n READ( NIN, FMT = *, END = 140 )N\n DO 90 I = 1, MPLUSN\n READ( NIN, FMT = * )( AI( I, J ), J = 1, MPLUSN )\n 90 CONTINUE\n DO 100 I = 1, MPLUSN\n READ( NIN, FMT = * )( BI( I, J ), J = 1, MPLUSN )\n 100 CONTINUE\n READ( NIN, FMT = * )PLTRU, DIFTRU\n*\n NPTKNT = NPTKNT + 1\n FS = .TRUE.\n K = 0\n M = MPLUSN - N\n*\n CALL DLACPY( 'Full', MPLUSN, MPLUSN, AI, LDA, A, LDA )\n CALL DLACPY( 'Full', MPLUSN, MPLUSN, BI, LDA, B, LDA )\n*\n* Compute the Schur factorization while swapping the\n* m-by-m (1,1)-blocks with n-by-n (2,2)-blocks.\n*\n CALL DGGESX( 'V', 'V', 'S', DLCTSX, 'B', MPLUSN, AI, LDA, BI, LDA,\n $ MM, ALPHAR, ALPHAI, BETA, Q, LDA, Z, LDA, PL, DIFEST,\n $ WORK, LWORK, IWORK, LIWORK, BWORK, LINFO )\n*\n IF( LINFO.NE.0 .AND. LINFO.NE.MPLUSN+2 ) THEN\n RESULT( 1 ) = ULPINV\n WRITE( NOUT, FMT = 9998 )'DGGESX', LINFO, MPLUSN, NPTKNT\n GO TO 130\n END IF\n*\n* Compute the norm(A, B)\n* (should this be norm of (A,B) or (AI,BI)?)\n*\n CALL DLACPY( 'Full', MPLUSN, MPLUSN, AI, LDA, WORK, MPLUSN )\n CALL DLACPY( 'Full', MPLUSN, MPLUSN, BI, LDA,\n $ WORK( MPLUSN*MPLUSN+1 ), MPLUSN )\n ABNRM = DLANGE( 'Fro', MPLUSN, 2*MPLUSN, WORK, MPLUSN, WORK )\n*\n* Do tests (1) to (4)\n*\n CALL DGET51( 1, MPLUSN, A, LDA, AI, LDA, Q, LDA, Z, LDA, WORK,\n $ RESULT( 1 ) )\n CALL DGET51( 1, MPLUSN, B, LDA, BI, LDA, Q, LDA, Z, LDA, WORK,\n $ RESULT( 2 ) )\n CALL DGET51( 3, MPLUSN, B, LDA, BI, LDA, Q, LDA, Q, LDA, WORK,\n $ RESULT( 3 ) )\n CALL DGET51( 3, MPLUSN, B, LDA, BI, LDA, Z, LDA, Z, LDA, WORK,\n $ RESULT( 4 ) )\n*\n* Do tests (5) and (6): check Schur form of A and compare\n* eigenvalues with diagonals.\n*\n NTEST = 6\n TEMP1 = ZERO\n RESULT( 5 ) = ZERO\n RESULT( 6 ) = ZERO\n*\n DO 110 J = 1, MPLUSN\n ILABAD = .FALSE.\n IF( ALPHAI( J ).EQ.ZERO ) THEN\n TEMP2 = ( ABS( ALPHAR( J )-AI( J, J ) ) /\n $ MAX( SMLNUM, ABS( ALPHAR( J ) ), ABS( AI( J,\n $ J ) ) )+ABS( BETA( J )-BI( J, J ) ) /\n $ MAX( SMLNUM, ABS( BETA( J ) ), ABS( BI( J, J ) ) ) )\n $ / ULP\n IF( J.LT.MPLUSN ) THEN\n IF( AI( J+1, J ).NE.ZERO ) THEN\n ILABAD = .TRUE.\n RESULT( 5 ) = ULPINV\n END IF\n END IF\n IF( J.GT.1 ) THEN\n IF( AI( J, J-1 ).NE.ZERO ) THEN\n ILABAD = .TRUE.\n RESULT( 5 ) = ULPINV\n END IF\n END IF\n ELSE\n IF( ALPHAI( J ).GT.ZERO ) THEN\n I1 = J\n ELSE\n I1 = J - 1\n END IF\n IF( I1.LE.0 .OR. I1.GE.MPLUSN ) THEN\n ILABAD = .TRUE.\n ELSE IF( I1.LT.MPLUSN-1 ) THEN\n IF( AI( I1+2, I1+1 ).NE.ZERO ) THEN\n ILABAD = .TRUE.\n RESULT( 5 ) = ULPINV\n END IF\n ELSE IF( I1.GT.1 ) THEN\n IF( AI( I1, I1-1 ).NE.ZERO ) THEN\n ILABAD = .TRUE.\n RESULT( 5 ) = ULPINV\n END IF\n END IF\n IF( .NOT.ILABAD ) THEN\n CALL DGET53( AI( I1, I1 ), LDA, BI( I1, I1 ), LDA,\n $ BETA( J ), ALPHAR( J ), ALPHAI( J ), TEMP2,\n $ IINFO )\n IF( IINFO.GE.3 ) THEN\n WRITE( NOUT, FMT = 9997 )IINFO, J, MPLUSN, NPTKNT\n INFO = ABS( IINFO )\n END IF\n ELSE\n TEMP2 = ULPINV\n END IF\n END IF\n TEMP1 = MAX( TEMP1, TEMP2 )\n IF( ILABAD ) THEN\n WRITE( NOUT, FMT = 9996 )J, MPLUSN, NPTKNT\n END IF\n 110 CONTINUE\n RESULT( 6 ) = TEMP1\n*\n* Test (7) (if sorting worked) <--------- need to be checked.\n*\n NTEST = 7\n RESULT( 7 ) = ZERO\n IF( LINFO.EQ.MPLUSN+3 )\n $ RESULT( 7 ) = ULPINV\n*\n* Test (8): compare the estimated value of DIF and its true value.\n*\n NTEST = 8\n RESULT( 8 ) = ZERO\n IF( DIFEST( 2 ).EQ.ZERO ) THEN\n IF( DIFTRU.GT.ABNRM*ULP )\n $ RESULT( 8 ) = ULPINV\n ELSE IF( DIFTRU.EQ.ZERO ) THEN\n IF( DIFEST( 2 ).GT.ABNRM*ULP )\n $ RESULT( 8 ) = ULPINV\n ELSE IF( ( DIFTRU.GT.THRSH2*DIFEST( 2 ) ) .OR.\n $ ( DIFTRU*THRSH2.LT.DIFEST( 2 ) ) ) THEN\n RESULT( 8 ) = MAX( DIFTRU / DIFEST( 2 ), DIFEST( 2 ) / DIFTRU )\n END IF\n*\n* Test (9)\n*\n NTEST = 9\n RESULT( 9 ) = ZERO\n IF( LINFO.EQ.( MPLUSN+2 ) ) THEN\n IF( DIFTRU.GT.ABNRM*ULP )\n $ RESULT( 9 ) = ULPINV\n IF( ( IFUNC.GT.1 ) .AND. ( DIFEST( 2 ).NE.ZERO ) )\n $ RESULT( 9 ) = ULPINV\n IF( ( IFUNC.EQ.1 ) .AND. ( PL( 1 ).NE.ZERO ) )\n $ RESULT( 9 ) = ULPINV\n END IF\n*\n* Test (10): compare the estimated value of PL and it true value.\n*\n NTEST = 10\n RESULT( 10 ) = ZERO\n IF( PL( 1 ).EQ.ZERO ) THEN\n IF( PLTRU.GT.ABNRM*ULP )\n $ RESULT( 10 ) = ULPINV\n ELSE IF( PLTRU.EQ.ZERO ) THEN\n IF( PL( 1 ).GT.ABNRM*ULP )\n $ RESULT( 10 ) = ULPINV\n ELSE IF( ( PLTRU.GT.THRESH*PL( 1 ) ) .OR.\n $ ( PLTRU*THRESH.LT.PL( 1 ) ) ) THEN\n RESULT( 10 ) = ULPINV\n END IF\n*\n NTESTT = NTESTT + NTEST\n*\n* Print out tests which fail.\n*\n DO 120 J = 1, NTEST\n IF( RESULT( J ).GE.THRESH ) THEN\n*\n* If this is the first test to fail,\n* print a header to the data file.\n*\n IF( NERRS.EQ.0 ) THEN\n WRITE( NOUT, FMT = 9995 )'DGX'\n*\n* Matrix types\n*\n WRITE( NOUT, FMT = 9994 )\n*\n* Tests performed\n*\n WRITE( NOUT, FMT = 9992 )'orthogonal', '''',\n $ 'transpose', ( '''', I = 1, 4 )\n*\n END IF\n NERRS = NERRS + 1\n IF( RESULT( J ).LT.10000.0D0 ) THEN\n WRITE( NOUT, FMT = 9989 )NPTKNT, MPLUSN, J, RESULT( J )\n ELSE\n WRITE( NOUT, FMT = 9988 )NPTKNT, MPLUSN, J, RESULT( J )\n END IF\n END IF\n*\n 120 CONTINUE\n*\n 130 CONTINUE\n GO TO 80\n 140 CONTINUE\n*\n 150 CONTINUE\n*\n* Summary\n*\n CALL ALASVM( 'DGX', NOUT, NERRS, NTESTT, 0 )\n*\n WORK( 1 ) = MAXWRK\n*\n RETURN\n*\n 9999 FORMAT( ' DDRGSX: ', A, ' returned INFO=', I6, '.', / 9X, 'N=',\n $ I6, ', JTYPE=', I6, ')' )\n*\n 9998 FORMAT( ' DDRGSX: ', A, ' returned INFO=', I6, '.', / 9X, 'N=',\n $ I6, ', Input Example #', I2, ')' )\n*\n 9997 FORMAT( ' DDRGSX: DGET53 returned INFO=', I1, ' for eigenvalue ',\n $ I6, '.', / 9X, 'N=', I6, ', JTYPE=', I6, ')' )\n*\n 9996 FORMAT( ' DDRGSX: S not in Schur form at eigenvalue ', I6, '.',\n $ / 9X, 'N=', I6, ', JTYPE=', I6, ')' )\n*\n 9995 FORMAT( / 1X, A3, ' -- Real Expert Generalized Schur form',\n $ ' problem driver' )\n*\n 9994 FORMAT( 'Input Example' )\n*\n 9993 FORMAT( ' Matrix types: ', /\n $ ' 1: A is a block diagonal matrix of Jordan blocks ',\n $ 'and B is the identity ', / ' matrix, ',\n $ / ' 2: A and B are upper triangular matrices, ',\n $ / ' 3: A and B are as type 2, but each second diagonal ',\n $ 'block in A_11 and ', /\n $ ' each third diaongal block in A_22 are 2x2 blocks,',\n $ / ' 4: A and B are block diagonal matrices, ',\n $ / ' 5: (A,B) has potentially close or common ',\n $ 'eigenvalues.', / )\n*\n 9992 FORMAT( / ' Tests performed: (S is Schur, T is triangular, ',\n $ 'Q and Z are ', A, ',', / 19X,\n $ ' a is alpha, b is beta, and ', A, ' means ', A, '.)',\n $ / ' 1 = | A - Q S Z', A,\n $ ' | / ( |A| n ulp ) 2 = | B - Q T Z', A,\n $ ' | / ( |B| n ulp )', / ' 3 = | I - QQ', A,\n $ ' | / ( n ulp ) 4 = | I - ZZ', A,\n $ ' | / ( n ulp )', / ' 5 = 1/ULP if A is not in ',\n $ 'Schur form S', / ' 6 = difference between (alpha,beta)',\n $ ' and diagonals of (S,T)', /\n $ ' 7 = 1/ULP if SDIM is not the correct number of ',\n $ 'selected eigenvalues', /\n $ ' 8 = 1/ULP if DIFEST/DIFTRU > 10*THRESH or ',\n $ 'DIFTRU/DIFEST > 10*THRESH',\n $ / ' 9 = 1/ULP if DIFEST <> 0 or DIFTRU > ULP*norm(A,B) ',\n $ 'when reordering fails', /\n $ ' 10 = 1/ULP if PLEST/PLTRU > THRESH or ',\n $ 'PLTRU/PLEST > THRESH', /\n $ ' ( Test 10 is only for input examples )', / )\n 9991 FORMAT( ' Matrix order=', I2, ', type=', I2, ', a=', D10.3,\n $ ', order(A_11)=', I2, ', result ', I2, ' is ', 0P, F8.2 )\n 9990 FORMAT( ' Matrix order=', I2, ', type=', I2, ', a=', D10.3,\n $ ', order(A_11)=', I2, ', result ', I2, ' is ', 0P, D10.3 )\n 9989 FORMAT( ' Input example #', I2, ', matrix order=', I4, ',',\n $ ' result ', I2, ' is', 0P, F8.2 )\n 9988 FORMAT( ' Input example #', I2, ', matrix order=', I4, ',',\n $ ' result ', I2, ' is', 1P, D10.3 )\n*\n* End of DDRGSX\n*\n END\n", "meta": {"hexsha": "7fe9dfc14f371492b99da1ee85c5d4f47f9f6c26", "size": 36238, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "lapack-netlib/TESTING/EIG/ddrgsx.f", "max_stars_repo_name": "dnoan/OpenBLAS", "max_stars_repo_head_hexsha": "b54b50fe3a5ec921d18ddf5fbdb80092d1b23893", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 4392, "max_stars_repo_stars_event_min_datetime": "2015-01-02T18:15:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T12:14:38.000Z", "max_issues_repo_path": "lapack-netlib/TESTING/EIG/ddrgsx.f", "max_issues_repo_name": "dnoan/OpenBLAS", "max_issues_repo_head_hexsha": "b54b50fe3a5ec921d18ddf5fbdb80092d1b23893", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2067, "max_issues_repo_issues_event_min_datetime": "2015-01-01T03:50:01.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T18:59:43.000Z", "max_forks_repo_path": "lapack-netlib/TESTING/EIG/ddrgsx.f", "max_forks_repo_name": "dnoan/OpenBLAS", "max_forks_repo_head_hexsha": "b54b50fe3a5ec921d18ddf5fbdb80092d1b23893", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1564, "max_forks_repo_forks_event_min_datetime": "2015-01-01T01:32:27.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T07:12:54.000Z", "avg_line_length": 35.3196881092, "max_line_length": 76, "alphanum_fraction": 0.4433743584, "num_tokens": 11293, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8918110396870287, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.6907820085157862}} {"text": "!***********************************************************************\nsubroutine sort(ra,n)\n!=======================================================================\n implicit none\n integer i,j,l,n,ir\n double precision ra(n),rra\n!-----------------------------------------------------------------------\n l=n/2+1\n ir=n\n10 continue\n if(l.gt.1)then\n l=l-1\n rra=ra(l)\n else\n rra=ra(ir)\n ra(ir)=ra(1)\n ir=ir-1\n if(ir.eq.1)then\n ra(1)=rra\n return\n endif\n endif\n i=l\n j=l+l\n20 if(j.le.ir)then\n if(j.lt.ir)then\n if(ra(j).lt.ra(j+1))j=j+1\n endif\n if(rra.lt.ra(j))then\n ra(i)=ra(j)\n i=j\n j=j+j\n else\n j=ir+1\n endif\n go to 20\n endif\n ra(i)=rra\n goto 10\n ! ---------------------------------------------------------------------\nend subroutine sort\n!***********************************************************************\n\n!***********************************************************************\ndouble precision function Planck(x)\n!=======================================================================\n! This function evaluates the Planck function multiplied by wavelength\n! and normalized by sigma*T^4/Pi. [Z.I., Mar. 1996]\n! =======================================================================\n implicit none\n double precision x\n ! ---------------------------------------------------------------------\n if (x.gt.100.0d0) then\n Planck = 0.0d0\n else\n if (x.lt.0.00001d0) then\n Planck = 0.155d0*x**3.0d0\n else\n Planck = 0.155d0*x**4.0d0/(dexp(x) - 1.0d0)\n end if\n end if\n ! ---------------------------------------------------------------------\n return\nend function Planck\n!***********************************************************************\n\n!***********************************************************************\nsubroutine Simpson(n,n1,n2,x,y,integral)\n!=======================================================================\n! This subroutine calculates integral I(y(x)*dx). Both y and x are\n! 1D arrays, y(i), x(i) with i=1,N (declared with NN). Lower and upper\n! integration limits are x(N1) and x(N2), respectively. The method used\n! is Simpson (trapezoid) approximation. The resulting integral is sum of\n! y(i)*wgth, i=N1,N2. [Z.I., Mar. 1996]\n! =======================================================================\n implicit none\n !---parameter\n integer n, n1, n2\n double precision integral\n double precision,allocatable :: x(:), y(:)\n !---locale\n integer i\n double precision wgth, dyn2\n ! ---------------------------------------------------------------------\n dyn2 = 0.0d0\n ! set integral to 0 and accumulate result in the loop\n integral = 0.0d0\n ! calculate weight, wgth, and integrate in the same loop\n if ((n2-n1).gt.100) then\n !$OMP PARALLEL DO reduction(+:integral) private(i,wgth)\n do i = n1, n2\n ! weigths\n if (i.ne.n1.and.i.ne.n2) then\n wgth = 0.5d0*(x(i+1)-x(i-1))\n else\n if (i.eq.n1) wgth = 0.5d0*(x(n1+1)-x(n1))\n if (i.eq.n2) wgth = 0.5d0*(x(n2)-x(n2-1))\n end if\n ! add contribution to the integral\n integral = integral + y(i)*wgth\n end do\n !$OMP END PARALLEL DO\n else if (n2.gt.n1) then\n do i = n1, n2\n ! weigths\n if (i.ne.n1.and.i.ne.n2) then\n wgth = 0.5d0*(x(i+1)-x(i-1))\n else\n if (i.eq.n1) wgth = 0.5d0*(x(n1+1)-x(n1))\n if (i.eq.n2) wgth = 0.5d0*(x(n2)-x(n2-1))\n end if\n ! add contribution to the integral\n integral = integral + y(i)*wgth\n end do\n else\n integral = 0.0d0\n end if\n ! --------------------------------------------------------------------\n return\nend subroutine Simpson\n!***********************************************************************\n\n!***********************************************************************\nsubroutine PowerInter(nn,n,x,y,xloc,iNloc,Yloc)\n!=======================================================================\n! This subroutine performs power law interpolation for y(x) such that\n! Yloc = y(xloc). It is assumed that x is monotonously increasing.\n! [based on sub LinInter by ZI'96, modified for power law interp. by MN'03]\n!=======================================================================\n\n implicit none\n integer nn, n, i, istop, iNloc\n double precision x(nn), y(nn), xloc, Yloc, pow\n! -----------------------------------------------------------------------\n\n if (n.gt.1) then\n if ((x(1)-xloc)*(x(n)-xloc).le.0.0d0) then\n istop = 0\n i = 1\n do while (istop.ne.1)\n i = i + 1\n if (i.gt.n) stop 'powinter ???'\n if (x(i).ge.xloc) then\n istop = 1\n iNloc = i\n if ((y(i)*y(i-1)).gt.0.0d0) then\n pow = dlog(y(i)/y(i-1))/dlog(x(i)/x(i-1))\n Yloc = y(i-1)*((xloc/x(i-1))**pow)\n else\n Yloc = 0.0d0\n end if\n end if\n end do\n else\n if (xloc.le.x(1)) Yloc = y(1)\n if (xloc.ge.x(n)) Yloc = y(n)\n end if\n else\n Yloc = y(1)\n end if\n!-----------------------------------------------------------------------\n return\nend subroutine PowerInter\n!***********************************************************************\n\n!***********************************************************************\nsubroutine PowerInt(n,n1,n2,x,y,integral)\n!=======================================================================\n! This subroutine calculates integral I(y(x)*dx). Both y and x are\n! 1D arrays, y(i), x(i) with i=1,N (declared with NN). Lower and upper\n! integration limits are x(N1) and x(N2), respectively. The method used\n! is a power-law approximation for y(x) between any two points .\n! (This subroutine is used for integration over size distribution) [ZI,'96]\n!=======================================================================\n\n implicit none\n integer i, n, n1, n2\n double precision x(n), y(n), integral, pow, c, delint\n ! --------------------------------------------------------------------\n ! set integral to 0 and accumulate result in the loop\n integral = 0.0d0\n ! calculate weight, wgth, and integrate in the same loop\n if (n2.gt.n1) then\n do i = n1, n2-1\n pow = dlog(Y(i+1)/Y(i)) / dlog(x(i+1)/x(i))\n c = Y(i) / x(i)**pow\n delint=(x(i+1)**(pow+1.0d+0)-x(i)**(pow+1.0d+0))*c/(pow+1.0d+0)\n ! add contribution to the integral\n integral = integral + delint\n end do\n else\n integral = 0.0d0\n ! this was in case of single size grains\n ! integral = Y(1)\n end if\n !---------------------------------------------------------------------\n\n return\nend subroutine PowerInt\n!***********************************************************************\n\n!***********************************************************************\nsubroutine scaleto1(Nmax,n,y)\n!=======================================================================\n! This subroutine scales vector Y such that Y(1) = 1.0\n! [Z.I., Jan. 1997]\n!=======================================================================\n implicit none\n integer Nmax, N, i\n double precision Y(Nmax), Scale\n !---------------------------------------------------------------------\n Scale = Y(1)\n do i = 1, N\n Y(i) = Y(i) / Scale\n end do\n !---------------------------------------------------------------------\n return\nend subroutine scaleto1\n!***********************************************************************\n\n!***********************************************************************\nsubroutine ROMBY(fnc,a,b,ss)\n!=======================================================================\n! This subroutine performs Romberg integration of function func on\n! interval [a,b]. The result is returned in ss. Desired accuracy is set\n! to 0.002. [Z.I., Feb. 1996]\n! =======================================================================\n IMPLICIT NONE\n INTEGER JMAX,JMAXP,K,KM, J\n PARAMETER (JMAX=30, JMAXP=JMAX+1, K=3, KM=K-1)\n DOUBLE PRECISION a,b,fnc,ss,EPS_loc, aux, dss,h(JMAXP),s(JMAXP)\n EXTERNAL fnc\n ! ---------------------------------------------------------------------\n EPS_loc = 0.002d0\n h(1)=1.0d0\n do j=1,JMAX\n call trapzd(fnc,a,b,s(j),j)\n if (j.ge.K) then\n aux = 0.0d0\n call polint(h(j-KM),s(j-KM),K,aux,ss,dss)\n IF (dabs(dss).le.EPS_loc*dabs(ss)) RETURN\n endif\n s(j+1)=s(j)\n h(j+1)=0.25d0*h(j)\n end do\n ! --------------------------------------------------------------------\n RETURN\nEND subroutine ROMBY\n!***********************************************************************\n!!$\n!!$\n!!$!***********************************************************************\n!!$SUBROUTINE ScaletoArea(Nmax,N,X,Y,Area)\n!!$! =======================================================================\n!!$! This subroutine scales a function Y(x) by the area A=Int{2*Pi Y(x)xdx}.\n!!$! X and Y are 1D arrays. (Used for PSF normalization.) [MN, Sep'04]\n!!$! =======================================================================\n!!$ IMPLICIT none\n!!$ INTEGER Nmax, N, i\n!!$ DOUBLE PRECISION Y(Nmax),X(Nmax),Fn(Nmax),Area,Pi\n!!$ !-----------------------------------------------------------------------\n!!$ Pi = 2.0D+00*ASIN(1.0)\n!!$ DO i = 1, N\n!!$ Fn(i) = Y(i)*X(i)\n!!$ END DO\n!!$ ! Integrate:\n!!$ Area = 0.0D+00\n!!$ DO i = 1, N-1\n!!$ Area = Area + 0.5D+00*(Fn(i+1)+Fn(i))*(X(i+1)-X(i))\n!!$ END DO\n!!$ Area = 2.0D+00*Pi*Area\n!!$ ! Normalize:\n!!$ DO i = 1, N\n!!$ Y(i) = Y(i) / Area\n!!$ END DO\n!!$ ! -----------------------------------------------------------------------\n!!$ RETURN\n!!$END SUBROUTINE ScaletoArea\n!!$! ***********************************************************************\n!!$\n!!$!***********************************************************************\n!!$subroutine shiftIns(x,Nmax,n,xins,i)\n!!$!=======================================================================\n!!$! Rearranges a vector X by inserting a new element Xins. [MN, Aug'96]\n!!$! =======================================================================\n!!$ use interfaces\n!!$ implicit none\n!!$ !---parameter\n!!$ integer :: Nmax,n,i\n!!$ double precision :: xins\n!!$ double precision,allocatable :: x(:)\n!!$ !---local\n!!$ integer j\n!!$ ! ---------------------------------------------------------------------\n!!$ do j = n+1, i+2, -1\n!!$ x(j) = x(j-1)\n!!$ end do\n!!$ x(i+1) = xins\n!!$ ! -----------------------------------------------------------------------\n!!$ return\n!!$end subroutine shiftIns\n!***********************************************************************\n!!$\n!!$\n!***********************************************************************\nSUBROUTINE Spline(x,y,n,yp1,ypn,y2)\n!=======================================================================\n INTEGER n,NMAX\n DOUBLE PRECISION yp1,ypn,x(n),y(n),y2(n)\n PARAMETER (NMAX=500)\n INTEGER i,k\n DOUBLE PRECISION p,qn,sig,un,u(NMAX)\n ! --------------------------------------------------------------------\n if (yp1.gt..99e30) then\n y2(1)=0.\n u(1)=0.\n else\n y2(1)=-0.5\n u(1)=(3./(x(2)-x(1)))*((y(2)-y(1))/(x(2)-x(1))-yp1)\n endif\n do i=2,n-1\n sig=(x(i)-x(i-1))/(x(i+1)-x(i-1))\n p=sig*y2(i-1)+2.\n y2(i)=(sig-1.)/p\n u(i)=(6.*((y(i+1)-y(i))/(x(i+1)-x(i)) &\n -(y(i)-y(i-1))/(x(i)-x(i-1)))/(x(i+1)-x(i-1))-sig*u(i-1))/p\n end do\n if (ypn.gt..99e30) then\n qn=0.\n un=0.\n else\n qn=0.5\n un=(3./(x(n)-x(n-1)))*(ypn-(y(n)-y(n-1))/(x(n)-x(n-1)))\n endif\n y2(n)=(un-qn*u(n-1))/(qn*y2(n-1)+1.)\n do k=n-1,1,-1\n y2(k)=y2(k)*y2(k+1)+u(k)\n end do\n ! --------------------------------------------------------------------\n return\nend subroutine Spline\n!***********************************************************************\n\n!***********************************************************************\nSUBROUTINE SPLINE2(x,fun,N,coef)\n! =======================================================================\n! This subroutine finds coefficients coef(i,j) such that\n! fun(x)=coef(i,1) + coef(i,2)*x + coef(i,3)*x^2 + coef(i,4)*x^3\n! for x(i).LE.x.LE.x(i+1) is a cubic spline approximation of fun(x),\n! with i=1..N. [Z.I., Feb. 1995]\n! =======================================================================\n use common\n IMPLICIT none\n INTEGER N, i\n DOUBLE PRECISION x(npY), coef(npY,4), secnder(npY), y2at1, y2atN, &\n Dd, xL, xR, dR, dL, fun(npY), fL, fR\n ! -----------------------------------------------------------------------\n ! find second derivative, secnder\n y2at1 = (fun(2)-fun(1))/(x(2)-x(1))\n y2atN = (fun(N)-fun(N-1))/(x(N)-x(N-1))\n CALL SPLINE(x,fun,N,y2at1,y2atN,secnder)\n ! generate coef(i,j), j=1,2,3,4\n DO i = 1, N-1\n Dd = x(i+1) - x(i)\n xL = x(i)\n xR = x(i+1)\n dL = secnder(i)\n dR = secnder(i+1)\n fL = fun(i)\n fR = fun(i+1)\n coef(i,1) = (xR*fL-xL*fR)/Dd + dL*xR*Dd/6.*((xR/Dd)**2.-1.)\n coef(i,1) = coef(i,1) - dR*xL*Dd/6. *((xL/Dd)**2.-1.)\n coef(i,2) = (fR-fL)/Dd + dL*Dd/6.*(1.-3.*(xR/Dd)**2.)\n coef(i,2) = coef(i,2) - dR*Dd/6.*(1.-3.*(xL/Dd)**2.)\n coef(i,3) = (dL*xR-dR*xL)/Dd/2.\n coef(i,4) = (dR-dL)/6./Dd\n END DO\n ! ---------------------------------------------------------------------\n RETURN\nEND SUBROUTINE SPLINE2\n!***********************************************************************\n\n!***********************************************************************\nSUBROUTINE trapzd(func,a,b,s,n)\n! =======================================================================\n IMPLICIT NONE\n INTEGER n\n DOUBLE PRECISION a,b,s,func\n EXTERNAL func\n INTEGER it,j\n DOUBLE PRECISION del,sum,tnm,x\n ! ----------------------------------------------------------------------\n IF (n.eq.1) THEN\n s=0.5d0*(b-a)*(func(a)+func(b))\n ELSE\n it=2**(n-2)\n tnm=it\n del=(b-a)/tnm\n x=a+0.5d0*del\n sum=0.\n DO j = 1, it\n sum=sum+func(x)\n x=x+del\n END DO\n s=0.5d0*(s+(b-a)*sum/tnm)\n END IF\n ! -------------------------------------------------------------------------\n RETURN\nEND SUBROUTINE trapzd\n!***********************************************************************\n\n!***********************************************************************\nsubroutine polint(xa,ya,n,x,y,dy)\n ! For polinomial interpolation, used in Subroutine Romby.\n ! ====================================================================\n implicit none\n integer n,Nmax\n double precision dy,x,y,xa(n),ya(n)\n parameter (Nmax=1000)\n integer i,m,ns\n double precision den,dif,dift,ho,hp,w,c(Nmax),d(Nmax)\n !---------------------------------------------------------------------\n c = 0.0d0\n d = 0.0d0\n ns=1\n dif=dabs(x-xa(1))\n do i=1,n\n dift=dabs(x-xa(i))\n if (dift.lt.dif) then\n ns=i\n dif=dift\n endif\n c(i)=ya(i)\n d(i)=ya(i)\n end do\n y=ya(ns)\n ns=ns-1\n do m=1,n-1\n do i=1,n-m\n ho=xa(i)-x\n hp=xa(i+m)-x\n w=c(i+1)-d(i)\n den=ho-hp\n if(den.eq.0.0d0) then\n write(6,'(a)') 'failure in polint'\n stop\n endif\n den=w/den\n d(i)=hp*den\n c(i)=ho*den\n end do\n if (2*ns.lt.n-m)then\n dy=c(ns+1)\n else\n dy=d(ns)\n ns=ns-1\n endif\n y=y+dy\n end do\n!-----------------------------------------------------------------------\n return\nend subroutine polint\n!***********************************************************************\n!!$\n!!$\n!!$\n!***********************************************************************\nsubroutine doProduct(nn,yt,pt,p0,j,prd)\n!=======================================================================\n! This is an auxiliary subroutine which evaluates a messy expression\n! needed to calculate normalization constants for a broken power law\n! density. [Z.I., Aug. 1996]\n!=======================================================================\n implicit none\n integer nn, i, j\n double precision yt(nn), pt(nn), prd, p0\n !---------------------------------------------------------------------\n prd = yt(1)**(pt(1) - p0)\n if (j.gt.1) then\n do i = 2, j\n prd = prd * yt(i)**(pt(i) - pt(i-1))\n end do\n end if\n !---------------------------------------------------------------------\n return\nend subroutine doProduct\n!***********************************************************************\n!!$\n!!$\n!***********************************************************************\nsubroutine gauleg(x1,x2,xg,wg,n)\n!=====================================================================\n implicit none\n\n integer i,m,n,j\n double precision x1,x2,xm,xl,eps,delj,p,eta\n double precision xg(n),wg(n),sum,ff,p1,p2,p3,z1,z,pp\n parameter (eps=1.0d-14)\n ! -------------------------------------------------------------------\n xg = 0.0d0\n wg = 0.0d0\n m = int((n+1)/2)\n xm = 0.5d0*(x2+x1)\n xl = 0.5d0*(x2-x1)\n do i = 1, m\n z = cos(3.1415926535898d0*(dble(i) - 0.25d0)/(dble(n) + 0.5d0))\n1 continue\n p1 = 1.0d0\n p2 = 0.0d0\n do j = 1, n\n p3 = p2\n p2 = p1\n p1 = ((2.0d0*dble(j)-1.0d0)*z*p2-(j-1.0d0)*p3)/dble(j)\n end do\n pp = dble(n)*(z*p1 - p2)/(z*z - 1.0d0)\n z1 = z\n z = z1-p1/pp\n if (abs(z-z1).gt.eps) go to 1\n xg(i) = xm-xl*z\n xg(n+1-i) = xm+xl*z\n wg(i) = 2.d0*xl/((1.d0-z*z)*pp*pp)\n wg(n+1-i) = wg(i)\n end do\n !-------------------------------------------------------------------\n return\nend subroutine gauleg\n!***********************************************************************\n\n!**********************************************************************\nSUBROUTINE ANALINT(nY,Nanal,xaux,yaux,m,aux)\n\n!======================================================================\n! This subroutine calculates integral I(x**m*y(x)*dx). Both y and x are\n! 1D arrays, y(i), x(i) with i=1,Nanal. The method used is approximation\n! of y(x) by y = P(x) + d/sqrt(1-x*x), where P(x) is the polynomial of\n! order Nanal-1, and analytic evaluation of the integral. It is assumed\n! that xaux(1)=0. Coefficients are determined from the set of Nanal\n! linear equations and subsequent call to the linear system solver\n! LINSYS. [Z.I., Nov. 1995]\n! ANALINT is called from Nordlund to evaluate analytically the contribution\n! of Nanal grid points. [MN]\n! =======================================================================\n use common\n IMPLICIT none\n INTERFACE\n SUBROUTINE LINSYS(Nreal,A,B,X)\n integer Nreal\n DOUBLE PRECISION,allocatable :: A(:,:), B(:), X(:)\n END SUBROUTINE LINSYS\n END INTERFACE\n !---parameter\n integer nY, Nanal\n double precision :: xaux(Nanal),yaux(Nanal)\n double precision :: m,aux\n !---local\n INTEGER i, j\n DOUBLE PRECISION b\n double precision,allocatable :: A(:,:),xaux_tmp(:),yaux_tmp(:),coeff(:)\n ! ---------------------------------------------------------------------\n allocate(A(Nanal,Nanal))\n A = 0\n allocate(xaux_tmp(Nanal))\n xaux_tmp = 0\n allocate(yaux_tmp(Nanal))\n yaux_tmp = 0\n allocate(coeff(Nanal))\n coeff = 0\n do i=1,Nanal\n xaux_tmp(i) = xaux(i)\n yaux_tmp(i) = yaux(i)\n end do\n error = 0\n ! generate matrix A and vector B\n DO i = 1, Nanal\n DO j = 1, Nanal-1\n IF (xaux_tmp(i).EQ.0.0.AND.j.EQ.1) THEN\n A(i,j) = 1.0\n ELSE\n A(i,j) = xaux_tmp(i)**(1.0*j-1.0)\n END IF\n END DO\n A(i,Nanal) = 1.0/sqrt(1.0-xaux_tmp(i)*xaux_tmp(i))\n END DO\n ! solve for the coefficients\n CALL LINSYS(Nanal,A,yaux_tmp,coeff)\n IF(error.NE.0) THEN\n CALL MSG(19)\n print*,\"MSG(19)\"\n RETURN\n END IF\n ! upper limit for integration:\n b = xaux_tmp(Nanal)\n ! evaluate m-dependent contribution of the last term\n IF (m.GT.0.1) THEN\n IF (m.GT.1.1) THEN\n ! this is for m=2\n aux = 0.5*(DASIN(b)-b*sqrt(1.-b*b))\n ELSE\n ! this is for m=1\n aux = 1.0 - sqrt(1.-b*b)\n ENDIF\n ELSE\n ! this is for m=0\n aux = DASIN(b)\n ENDIF\n aux = aux * coeff(Nanal)\n ! add contribution from the polynom\n DO i = 1, Nanal-1\n aux = aux + coeff(i) * (b**(m+1.0*i)) / (m+1.0*i)\n END DO\n! -----------------------------------------------------------------------\n do i=1,Nanal\n xaux(i) = xaux_tmp(i)\n yaux(i) = yaux_tmp(i)\n end do\n999 deallocate(A)\n deallocate(xaux_tmp)\n deallocate(yaux_tmp)\n deallocate(coeff)\n RETURN\nEND SUBROUTINE ANALINT\n!***********************************************************************\n\n! ***********************************************************************\nSUBROUTINE ChkConv(nY,accuracy_loc,Aold,Anew,Aconv_loc)\n! =======================================================================\n! This subroutine checks convergence of an array A(nY) between values\n! given in Aold and Anew. If the relative difference for EVERY element\n! is smaller than accuracy, Aconv is assigned 1, otherwise 0.\n! [Z.I., Jul. 1996]\n! =======================================================================\n use common\n IMPLICIT none\n ! --- parameter\n INTEGER Aconv_loc,nY\n DOUBLE PRECISION accuracy_loc \n DOUBLE PRECISION,allocatable :: Aold(:), Anew(:) \n ! --- local\n INTEGER iY\n DOUBLE PRECISION delta\n! -----------------------------------------------------------------------\n Aconv_loc = 1\n ! loop over radial positions\n DO iY = 1, nY\n ! find relative difference\n delta = dabs(Anew(iY)-Aold(iY))\n IF (delta.GT.dabs(Anew(iY))*accuracy_loc) Aconv_loc = 0\n END DO\n ! -----------------------------------------------------------------------\n RETURN\nEND SUBROUTINE ChkConv\n! ***********************************************************************\n\n!***********************************************************************\nSUBROUTINE LINSYS(Nreal,A,B,X)\n!=======================================================================\n! This subroutine solves the set of linear equations [A]*[X] = [B] for\n! X [A(k,1)*X(1)+A(k,2)*X(2)+...+A(k,Nreal)*X(Nreal) = B(k), k=1,Nreal).\n! The real size of matrix A is Nreal x Nreal and its physical dimension\n! is npY x npY, where npY comes from INCLUDE 'userpar.inc'. Both vectors\n! B and X have real lengths Nreal. The set is solved by calls to LUDCMP\n! and LUBKSB and the solution is improved subsequently by a call to\n! MPROVE. These three subroutines are taken from Numerical Recipes.\n! [Z.I., Nov. 1995]\n! =======================================================================\n use common\n IMPLICIT none\n !--- parameter\n integer nY,Nreal\n DOUBLE PRECISION,allocatable :: A(:,:), B(:), X(:)\n !--- local\n INTEGER i, j\n integer ,allocatable :: indx(:)\n DOUBLE PRECISION d\n double precision,allocatable :: A1c(:,:), B1(:), A2c(:,:), B2(:)\n INTERFACE\n SUBROUTINE LUDCMP(A,N,NP,INDX,D)\n integer N,NP\n double precision :: D\n integer, allocatable :: indx(:)\n double precision,allocatable :: A(:,:),B(:)\n END SUBROUTINE LUDCMP\n SUBROUTINE LUBKSB(A,N,NP,INDX,B)\n integer N,NP\n integer, allocatable :: indx(:)\n double precision,allocatable :: A(:,:),B(:)\n END SUBROUTINE LUBKSB\n SUBROUTINE MPROVE(A,ALUD,N,NP,INDX,B,X)\n integer :: n,np\n integer,allocatable :: INDX(:)\n double precision,allocatable :: A(:,:),ALUD(:,:),B(:),X(:)\n END SUBROUTINE MPROVE\n END INTERFACE\n ! ---------------------------------------------------------------------\n allocate(indx(Nreal))\n indx = 0\n allocate(A1c(Nreal,Nreal))\n A1c = 0\n allocate(B1(Nreal))\n B1 = 0\n allocate(A2c(Nreal,Nreal))\n A2c = 0\n allocate(B2(Nreal))\n B2 = 0\n error = 0\n ! generate DOUBLE PRECISION copies of A and B (two copies because they\n ! are changed in LUDCMP and LUBKSB, but still needed for MPROVE)\n DO i = 1, Nreal\n B1(i) = B(i)\n B2(i) = B(i)\n DO j = 1, Nreal\n A1c(i,j) = A(i,j)\n A2c(i,j) = A(i,j)\n END DO\n END DO\n ! solve the system\n CALL LUDCMP(A1c,Nreal,nY,indx,d)\n IF (error.NE.0) RETURN\n CALL LUBKSB(A1c,Nreal,nY,indx,B1)\n ! improve the solution (saved in B)\n CALL MPROVE(A2c,A1c,Nreal,nY,indx,B2,B1)\n ! copy the improved solution to output vector X\n DO i = 1, Nreal\n X(i) = B1(i)\n END DO\n ! --------------------------------------------------------------------\n deallocate(indx)\n deallocate(A1c)\n deallocate(B1)\n deallocate(A2c)\n deallocate(B2)\n RETURN\nEND SUBROUTINE LINSYS\n!***********************************************************************\n\n! ***********************************************************************\nSUBROUTINE LUBKSB(A,N,NP,INDX,B)\n IMPLICIT none\n !---parameter\n integer N,NP\n integer, allocatable :: indx(:)\n double precision,allocatable :: A(:,:),B(:)\n !---local\n integer :: i,j,ii,ll\n double precision :: sum\n!!$ DIMENSION INDX(NP)\n!!$ DOUBLE PRECISION A(NP,NP),B(NP)\n ! -------------------------------------------------------------------\n II=0\n !impossible to parallelize since B(J) needs to is changed and used!\n DO I=1,N\n LL=INDX(I)\n SUM=B(LL)\n B(LL)=B(I)\n IF (II.NE.0)THEN\n DO J=II,I-1\n SUM=SUM-A(I,J)*B(J)\n END DO\n ELSE IF (SUM.NE.0.) THEN\n II=I\n ENDIF\n B(I)=SUM\n END DO\n !impossible to parallelize since B(J) needs to is changed and used!\n DO I=N,1,-1\n SUM=B(I)\n IF(I.LT.N)THEN\n DO J=I+1,N\n SUM=SUM-A(I,J)*B(J)\n END DO\n ENDIF\n B(I)=SUM/A(I,I)\n END DO\n ! -------------------------------------------------------------------\n RETURN\nEND SUBROUTINE LUBKSB\n! ***********************************************************************\n\n! ***********************************************************************\nSUBROUTINE LUDCMP(A,N,NP,INDX,D)\n IMPLICIT none\n !---parameter\n integer N,NP\n double precision :: D\n integer, allocatable :: indx(:)\n double precision,allocatable :: A(:,:),B(:)\n !---local\n integer :: i,k,j,imax,error\n DOUBLE PRECISION TINY\n PARAMETER (TINY=1.D-20)\n DOUBLE PRECISION,allocatable :: VV(:)\n double precision :: SUM,aamax,DUM\n ! ------------------------------------------------------------------\n allocate(VV(N))\n VV = 0\n error = 0\n D = 1.\n DO I = 1, N\n AAMAX=0.\n DO J = 1, N\n IF (DABS(A(I,J)).GT.AAMAX) AAMAX=DABS(A(I,J))\n END DO\n ! IF (AAMAX.EQ.0.) PAUSE 'Singular matrix.'\n IF (AAMAX.EQ.0.) THEN\n error = 5\n RETURN\n ENDIF\n VV(I)=1./AAMAX\n END DO\n!! !$OMP PARALLEL DO private(J,I,SUM,DUM,IMAX,AAMAX,D)\n DO J = 1 , N\n IF (J.GT.1) THEN\n DO I = 1, J-1\n SUM=A(I,J)\n IF (I.GT.1)THEN\n DO K = 1, I-1\n SUM=SUM-A(I,K)*A(K,J)\n END DO\n A(I,J)=SUM\n ENDIF\n END DO\n ENDIF\n AAMAX=0.\n DO I = J, N\n SUM=A(I,J)\n IF (J.GT.1)THEN\n DO K = 1, J-1\n SUM=SUM-A(I,K)*A(K,J)\n END DO\n A(I,J)=SUM\n ENDIF\n DUM=VV(I)*DABS(SUM)\n IF (DUM.GE.AAMAX) THEN\n IMAX=I\n AAMAX=DUM\n ENDIF\n END DO\n IF (J.NE.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 D=-D\n VV(IMAX)=VV(J)\n ENDIF\n INDX(J)=IMAX\n IF(J.NE.N)THEN\n IF(A(J,J).EQ.0.)A(J,J)=TINY\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\n!! !$OMP END PARALLEL DO\n IF(A(N,N).EQ.0.)A(N,N)=TINY\n !------------------------------------------------------------------\n deallocate(VV)\n RETURN\nEND SUBROUTINE LUDCMP\n! ***********************************************************************\n\n!***********************************************************************\nSUBROUTINE MPROVE(A,ALUD,N,NP,INDX,B,X)\n IMPLICIT none\n INTERFACE\n SUBROUTINE LUBKSB(A,N,NP,INDX,B)\n integer N,NP\n integer, allocatable :: indx(:)\n double precision,allocatable :: A(:,:),B(:)\n END SUBROUTINE LUBKSB\n END INTERFACE\n !---parameter\n integer :: n,np\n integer,allocatable :: INDX(:)\n double precision,allocatable :: A(:,:),ALUD(:,:),B(:),X(:)\n !---local\n integer i,j\n DOUBLE PRECISION SDP\n double precision,allocatable :: R(:)\n ! ---------------------------------------------------------------------\n allocate(R(N))\n R = 0\n DO i = 1, N\n SDP = -B(i)\n DO j = 1, N\n SDP = SDP + A(i,j)*X(j)\n END DO\n R(i) = SDP\n END DO\n CALL LUBKSB(ALUD,N,NP,INDX,R)\n DO i = 1, N\n X(i) = X(i) - R(i)\n END DO\n ! -----------------------------------------------------------------------\n deallocate(R)\n RETURN\nEND SUBROUTINE MPROVE\n!***********************************************************************\n\n! ***********************************************************************\nSUBROUTINE Maple3(w,z,p,MpInt)\n! =====================================================================\n! This function calculates indefinite integral:\n! MpInt(iC) = INT(w^(2-iC) / sqrt(w^2-p^2) * dw), for iC=1,2,3,4.\n! [Z.I., Apr. 1996]\n! =====================================================================\n IMPLICIT none\n DOUBLE PRECISION w, z, p, MpInt(4)\n ! ---------------------------------------------------------------------\n ! integrals\n MpInt(1) = z\n MpInt(2) = dlog(w+z)\n IF (p.GT.0.0) THEN\n MpInt(3) = dacos(p/w)/p\n MpInt(4) = z/w/p/p\n ELSE\n MpInt(3) = -1.0 / w\n MpInt(4) = -0.5 / w / w\n END IF\n ! ---------------------------------------------------------------------\n RETURN\nEND SUBROUTINE Maple3\n!***********************************************************************\n\n!**********************************************************************\nsubroutine add(np1,nr1,np2,nr2,q1,q2,q3,qout) !only needed in matrix method\n!======================================================================\n! This subroutine evaluates the following expression:\n! [qOut] = [q1] + [q2] + [q3]. qout, q1, q2 and q2 are matrices of\n! physical size (np2,np1) and real size (nr2,nr1). [Z.I., Nov. 1995]\n! ======================================================================\n implicit none\n !---parameter\n integer np1, nr1, np2, nr2\n double precision, allocatable :: q1(:,:), q2(:,:), q3(:,:),qout(:,:)\n !---local\n integer i2, i1\n !--------------------------------------------------------------------\n ! loop over index 2\n do i2 = 1, nr2\n ! loop over index 1\n do i1 = 1, nr1\n qout(i2,i1) = q1(i2,i1) + q2(i2,i1) + q3(i2,i1)\n end do\n end do\n !--------------------------------------------------------------------\n return\nend subroutine add\n!**********************************************************************\n!!$\n!***********************************************************************\nSUBROUTINE ChkRange(dr,x)\n!=======================================================================\n! This subroutine checks if x is within the allowed range defined by\n! dr<<1:\n! dr**2 < x < 1/dr**2\n! If it is not then x = 0.0 [Z.I., Jan. 1997]\n!=======================================================================\n IMPLICIT none\n DOUBLE PRECISION x, dr\n!-----------------------------------------------------------------------\n IF ((x-dr*dr)*(x-1.0d0/dr/dr).LT.0.0d0) THEN\n continue\n ELSE\n ! continue\n x = 0.0d0\n END IF\n!-----------------------------------------------------------------------\n RETURN\nEND SUBROUTINE ChkRange\n!***********************************************************************\n!!$\n!!$!***********************************************************************\n!!$DOUBLE PRECISION FUNCTION Bessel(x)\n!!$!=======================================================================\n!!$! This function evaluates the Bessel function of the zeroth kind.\n!!$! Formulae are from Abramowitz & Stegun. [Z.I., Jan. 1997]\n!!$! =======================================================================\n!!$ use common\n!!$ IMPLICIT none\n!!$ INTEGER i\n!!$ DOUBLE PRECISION x, c(6)\n!!$ ! ---------------------------------------------------------------------\n!!$ c(1) = -2.2499997D+00\n!!$ c(2) = 1.2656208D+00\n!!$ c(3) = -0.3163866D+00\n!!$ c(4) = 0.0444479D+00\n!!$ c(5) = -0.0039444D+00\n!!$ c(6) = 0.00021D+00\n!!$ Bessel=0.0D+00\n!!$ IF (x.LE.3.0D+00)THEN\n!!$ DO i=1,6\n!!$ Bessel = Bessel + c(i)*(x/3.0D+00)**(2.0D+00*i)\n!!$ END DO\n!!$ Bessel = 1.0D+00 + Bessel\n!!$ ELSE\n!!$ Bessel = dsqrt(2.0D+00/Pi/x) * dcos(x-Pi/4.0D+00)\n!!$ ENDIF\n!!$ ! --------------------------------------------------------------------\n!!$ RETURN\n!!$END FUNCTION Bessel\n!!$!***********************************************************************\n\n!***********************************************************************\nsubroutine LinInter(nn,n,x,y,xloc,iNloc,Yloc)\n!=======================================================================\n! This subroutine performs linear interpolation for y(x) such that\n! Yloc = y(xloc). It is assumed that x is monotonously increasing.\n! [Z.I., Mar. 1996]\n!=======================================================================\n implicit none\n integer nn, n, i, istop, iNloc\n double precision x(nn), y(nn), xloc, Yloc\n !---------------------------------------------------------------------\n if (n.gt.1) then\n if ((x(1)-xloc)*(x(n)-xloc).le.0.0d0) then\n istop = 0\n i = 1\n do while (istop.ne.1)\n i = i + 1\n if (i.gt.n) stop 'lininter ???'\n if (x(i).ge.xloc) then\n istop = 1\n iNloc = i\n Yloc = y(i-1) + (y(i)-y(i-1))/(x(i)-x(i-1))*(xloc-x(i-1))\n end if\n end do\n else\n if (xloc.le.x(1)) Yloc = y(1)\n if (xloc.ge.x(n)) Yloc = y(n)\n end if\n else\n Yloc = y(1)\n end if\n !---------------------------------------------------------------------\n return\nend subroutine LinInter\n!***********************************************************************\n", "meta": {"hexsha": "4f135b275b8721c894d04f32184f8fb5e8f97f6c", "size": 34164, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/math.f90", "max_stars_repo_name": "ivezic/dusty", "max_stars_repo_head_hexsha": "89992eb4fd25290aa0bbc60730f977baac197f11", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2016-06-07T08:13:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-27T16:18:48.000Z", "max_issues_repo_path": "source/math.f90", "max_issues_repo_name": "ivezic/dusty", "max_issues_repo_head_hexsha": "89992eb4fd25290aa0bbc60730f977baac197f11", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2018-01-08T05:18:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-27T18:37:11.000Z", "max_forks_repo_path": "source/math.f90", "max_forks_repo_name": "ivezic/dusty", "max_forks_repo_head_hexsha": "89992eb4fd25290aa0bbc60730f977baac197f11", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-01-03T20:39:07.000Z", "max_forks_repo_forks_event_max_datetime": "2018-01-03T20:39:07.000Z", "avg_line_length": 32.818443804, "max_line_length": 78, "alphanum_fraction": 0.3853178785, "num_tokens": 9511, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246077301781, "lm_q2_score": 0.8289388083214155, "lm_q1q2_score": 0.6907751072767649}} {"text": "! { dg-do run }\n! { dg-options \"-O\" }\n! PR 80304 - this used to give a wrong result.\n! Original test case by Chinoune\nmodule test_mod\n implicit none\n\ncontains\n\n pure real function add(i,j,k)\n integer ,intent(in) :: i,j,k\n add = real(i+j+k)+1.\n end function add\n\n pure real function add2(i,j,k)\n integer ,intent(in) :: i,j,k\n add2 = real(i+j+k)\n end function add2\n\n subroutine check_err(a, s)\n real, dimension(:,:), intent(in) :: a\n real, intent(in) :: s\n if (abs(sum(a) - s) > 1e-5) STOP 1\n end subroutine check_err\n\nend module test_mod\n\nprogram test \n use test_mod\n implicit none\n\n integer :: i ,j\n real :: a(0:1,0:1) ,b(0:1,0:1)\n\n ! first do-concurrent loop \n a = 0.\n b = 0.\n DO CONCURRENT( i=0:1 ,j=0:1)\n a(i,j) = add(i,j,abs(i-j))\n b(i,j) = add2(i,j,abs(i-j))\n END DO\n call check_err (a, 10.)\n call check_err (b, 6.)\n\n ! normal do loop \n a = 0.\n b = 0.\n DO i=0,1 \n DO j=0,1\n a(i,j) = add(i,j,abs(i-j))\n b(i,j) = add2(i,j,abs(i-j))\n END DO\n END DO\n call check_err (a, 10.)\n call check_err (b, 6.)\n\n ! second do-concuurent loop \n a = 0.\n b = 0.\n DO CONCURRENT( i=0:1 ,j=0:1)\n a(i,j) = add(i,j,abs(i-j))\n b(i,j) = add2(i,j,abs(i-j))\n END DO\n call check_err (a, 10.)\n call check_err (b, 6.)\n\nend program test\n", "meta": {"hexsha": "8f8338aa44330ecd168443129e8396b12ebf5e55", "size": 1303, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/do_concurrent_4.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/do_concurrent_4.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/do_concurrent_4.f90", "max_forks_repo_name": "brugger1/testsuite", "max_forks_repo_head_hexsha": "9b504db668cdeaf7c561f15b76c95d05bfdd1517", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2020-08-31T21:59:10.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-23T22:06:46.000Z", "avg_line_length": 19.1617647059, "max_line_length": 46, "alphanum_fraction": 0.5625479662, "num_tokens": 498, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245953120233, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.6907750969828745}} {"text": "program test_random\n use,intrinsic :: iso_fortran_env\n use random_mod\n implicit none\n\n print'(a)', '### random_mod test'\n print'(a)', '# random01_test'\n if (.not. random01_limits()) error stop\n print'(a)', '# randrange_limits'\n if (.not. randrange_limits()) error stop\ncontains\n function random01_limits() result(ret)\n integer(int32):: n,i\n real(real64),allocatable:: a(:)\n real(real64):: amin, amax\n logical:: ret\n\n n=10000\n allocate(a(n), source=[(random01(),i=1,n)])\n amin=a(1)\n amax=a(1)\n do i=1,n\n if (a(i)amax) then\n amax = a(i)\n end if\n end do\n ret = 0d0<=amin .and. amax<=1d0\n end function\n\n\n function randrange_limits() result(ret)\n integer(int32):: n,i\n integer(int32):: imin,imax ! \u4e71\u6570\u306e\u7406\u8ad6\u4e0b\u9650/\u4e0a\u9650\n integer(int32):: amax,amin ! \u4e71\u6570\u306e\u5b9f\u969b\u4e0b\u9650/\u4e0a\u9650\n integer(int32), allocatable:: a(:)\n logical:: ret\n\n n=10000\n imin=0\n imax=100\n allocate(a(n), source=[(randrange(imin,imax),i=1,n)])\n amax = a(1)\n amin = a(1)\n do i=1,n\n amax = max(amax, a(i))\n amin = min(amin, a(i))\n end do\n\n ret = imin<=amin .and. amax<=imax\n end function\nend program test_random", "meta": {"hexsha": "925419d726d4d4961c476e9957b5a49389fcbd79", "size": 1380, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/test_random/test_random.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": "test/test_random/test_random.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": "test/test_random/test_random.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.0377358491, "max_line_length": 61, "alphanum_fraction": 0.5217391304, "num_tokens": 427, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289387998695209, "lm_q2_score": 0.8333245953120233, "lm_q1q2_score": 0.6907750899397028}} {"text": " Program zggevx_example\n\n! ZGGEVX Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_example_aux, Only: nagf_sort_realvec_rank_rearrange, &\n nagf_blas_dpyth, nagf_sort_cmplxvec_rank_rearrange, &\n nagf_sort_realvec_rank\n Use lapack_interfaces, Only: zggevx\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nb = 64, nin = 5, nout = 6\n Logical, Parameter :: verbose = .False.\n! .. Local Scalars ..\n Complex (Kind=dp) :: eig, scal\n Real (Kind=dp) :: abnorm, abnrm, bbnrm, eps, small, tol\n Integer :: i, ifail, ihi, ilo, info, j, k, lda, ldb, ldvr, lwork, n\n! .. Local Arrays ..\n Complex (Kind=dp), Allocatable :: a(:, :), alpha(:), b(:, :), beta(:), &\n temp(:), vr(:, :), work(:)\n Complex (Kind=dp) :: dummy(1, 1)\n Real (Kind=dp), Allocatable :: lscale(:), rconde(:), rcondv(:), &\n rscale(:), rwork(:)\n Integer, Allocatable :: irank(:), iwork(:)\n Logical, Allocatable :: bwork(:)\n! .. Intrinsic Procedures ..\n Intrinsic :: abs, epsilon, max, maxloc, nint, real, tiny\n! .. Executable Statements ..\n Write (nout, *) 'ZGGEVX Example Program Results'\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n\n lda = n\n ldb = n\n ldvr = n\n Allocate (a(lda,n), alpha(n), b(ldb,n), beta(n), vr(ldvr,n), lscale(n), &\n rconde(n), rcondv(n), rscale(n), rwork(6*n), iwork(n+2), bwork(n), &\n temp(n))\n\n! Use routine workspace query to get optimal workspace.\n lwork = -1\n Call zggevx('Balance', 'No vectors (left)', 'Vectors (right)', &\n 'Both reciprocal condition numbers', n, a, lda, b, ldb, alpha, beta, &\n dummy, 1, vr, ldvr, ilo, ihi, lscale, rscale, abnrm, bbnrm, rconde, &\n rcondv, dummy, lwork, rwork, iwork, bwork, info)\n\n! Make sure that there is enough workspace for block size nb.\n lwork = max((nb+2*n)*n, nint(real(dummy(1,1))))\n Allocate (work(lwork))\n\n! Read in the matrices A and B\n\n Read (nin, *)(a(i,1:n), i=1, n)\n Read (nin, *)(b(i,1:n), i=1, n)\n\n! Solve the generalized eigenvalue problem\n\n Call zggevx('Balance', 'No vectors (left)', 'Vectors (right)', &\n 'Both reciprocal condition numbers', n, a, lda, b, ldb, alpha, beta, &\n dummy, 1, vr, ldvr, ilo, ihi, lscale, rscale, abnrm, bbnrm, rconde, &\n rcondv, work, lwork, rwork, iwork, bwork, info)\n\n If (info>0) Then\n Write (nout, *)\n Write (nout, 100) 'Failure in ZGGEVX. INFO =', info\n Else\n\n! Compute the machine precision, the safe range parameter\n! SMALL and sqrt(ABNRM**2+BBNRM**2)\n\n eps = epsilon(1.0E0_dp)\n small = tiny(1.0E0_dp)\n abnorm = nagf_blas_dpyth(abnrm, bbnrm)\n tol = eps*abnorm\n\n! Reorder eigenvalues by descending absolute value\n rwork(1:n) = abs(alpha(1:n)/beta(1:n))\n Allocate (irank(n))\n ifail = 0\n Call nagf_sort_realvec_rank(rwork, 1, n, 'Descending', irank, ifail)\n Call nagf_sort_cmplxvec_rank_rearrange(alpha, 1, n, irank, ifail)\n Call nagf_sort_cmplxvec_rank_rearrange(beta, 1, n, irank, ifail)\n Call nagf_sort_realvec_rank_rearrange(rconde, 1, n, irank, ifail)\n! Reorder eigenvectors accordingly\n Do j = 1, n\n temp(1:n) = vr(j, 1:n)\n Call nagf_sort_cmplxvec_rank_rearrange(temp, 1, n, irank, ifail)\n vr(j, 1:n) = temp(1:n)\n End Do\n Call nagf_sort_realvec_rank_rearrange(rcondv, 1, n, irank, ifail)\n\n! Print out eigenvalues and vectors and associated condition\n! number and bounds\n\n Write (nout, *)\n Write (nout, *) 'Eigenvalues'\n Write (nout, *)\n If (verbose) Then\n Write (nout, *) ' Eigenvalue rcond error'\n Else\n Write (nout, *) ' Eigenvalue'\n End If\n\n Do j = 1, n\n\n! Print out information on the j-th eigenvalue\n\n If ((abs(alpha(j)))*small>=abs(beta(j))) Then\n If (rconde(j)>0.0_dp) Then\n If (tol/rconde(j)<500.0_dp*eps) Then\n Write (nout, 140) j, rconde(j), '-'\n Else\n Write (nout, 150) j, rconde(j), tol/rconde(j)\n End If\n Else\n Write (nout, 140) j, rconde(j), 'Inf'\n End If\n Else\n eig = alpha(j)/beta(j)\n If (verbose) Then\n If (rconde(j)>0.0_dp) Then\n If (tol/rconde(j)<500.0_dp*eps) Then\n Write (nout, 110) j, eig, rconde(j), '-'\n Else\n Write (nout, 120) j, eig, rconde(j), tol/rconde(j)\n End If\n Else\n Write (nout, 110) j, eig, rconde(j), 'Inf'\n End If\n Else\n Write (nout, 110) j, eig\n End If\n End If\n\n End Do\n\n Write (nout, *)\n Write (nout, *) 'Eigenvectors'\n Write (nout, *)\n If (verbose) Then\n Write (nout, *) ' Eigenvector rcond error'\n Else\n Write (nout, *) ' Eigenvector'\n End If\n\n Do j = 1, n\n\n! Print information on j-th eigenvector\n Write (nout, *)\n\n! Re-normalize eigenvector, largest absolute element real (=1)\n rwork(1:n) = abs(vr(1:n,j))\n k = maxloc(rwork(1:n), 1)\n scal = (1.0_dp, 0.0_dp)/vr(k, j)\n vr(1:n, j) = vr(1:n, j)*scal\n\n If (verbose) Then\n If (rcondv(j)>0.0_dp) Then\n If (tol/rcondv(j)<500.0_dp*eps) Then\n Write (nout, 110) j, vr(1, j), rcondv(j), '-'\n Else\n Write (nout, 120) j, vr(1, j), rcondv(j), tol/rcondv(j)\n End If\n Else\n Write (nout, 110) j, vr(1, j), rcondv(j), 'Inf'\n End If\n Else\n Write (nout, 110) j, vr(1, j)\n End If\n Write (nout, 130) vr(2:n, j)\n\n End Do\n\n If (verbose) Then\n Write (nout, *)\n Write (nout, *) &\n 'Errors below 500*machine precision are not displayed'\n End If\n End If\n\n100 Format (1X, A, I4)\n110 Format (1X, I2, 1X, '(', 1P, E11.4, ',', E11.4, ')', 1X, 0P, F7.4, 4X, &\n A)\n120 Format (1X, I2, 1X, '(', 1P, E11.4, ',', E11.4, ')', 1X, 0P, F7.4, 1X, &\n 1P, E8.1)\n130 Format (1X, 3X, '(', 1P, E11.4, ',', E11.4, ')')\n140 Format (1X, I2, 1X, ' Infinite or undetermined', 1X, 0P, F7.4, 4X, A)\n150 Format (1X, I2, 1X, ' Infinite or undetermined', 1X, 0P, F7.4, 1X, 1P, &\n E8.1)\n\n End Program\n", "meta": {"hexsha": "c13d3ad36b9841c9a6329326d2eed413e1f173be", "size": 6909, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/zggevx_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/zggevx_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/zggevx_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 34.8939393939, "max_line_length": 90, "alphanum_fraction": 0.5246779563, "num_tokens": 2241, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802507195636, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6907086972911629}} {"text": "!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n! Projet MICO 1995 - Partie theorique (ver. FORTRAN/Python)\n!\n! Calcule u(v) et P(u) par Newton Raphson\n!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n! | P\n! | \n! | a \n! |--> \n! ^ o------o---u\n! | \\ /|\n! | \\ / v\n! | \\/\n! | /\\ \n! | / \\ \n! | / \\ \n! h | / \\ \n! | / \\ \n! | / \\ \n! | / \\ \n! | / \\ \n! | / \\ \n! v o |--------o\n! b\n\n\nmodule pars\n\n integer, parameter :: DP = KIND(1.0D0) !< double precision\n\n real(DP) :: h = 40. ! height\n real(DP) :: a = 24. ! x pos of upper join\n real(DP) :: b = 40. ! x pos of lower join\n real(DP) :: Vh = 160. ! volume of horizontal rod\n real(DP) :: Vv = 200. ! volume of vertical rods\n real(DP) :: E = 70000. ! Young's modulus\n\n integer, parameter :: ivmax = 91\n integer, parameter :: ivmaxl = 16\n\nend module pars\n\nsubroutine theoric(x, y, P, vl, ul, Pl)\n use pars\n implicit none\n\n real(DP), intent(inout) :: P(ivmax), x(ivmax), y(ivmax) !< nonlinear response\n real(DP), intent(inout) :: Pl(ivmaxl), vl(ivmaxl), ul(ivmaxl) !< linear response\n\n ! ----Declarations--------\n integer :: j\n logical :: converged\n real(DP) :: Lh, Lv\n real(DP) :: TOL\n real(DP) :: u, v, lastu, F, DF, Du\n\n ! ----Donnees-------------\n\n print *, 'computing solution from theory...'\n\n Lh = 2*a ! length of the horizontal rod\n Lv = sqrt(h**2 + (b + a)**2) ! length of the vertical rods\n TOL = 1e-5 ! N-R tolerance\n\n ! Nonlinear response\n u = 0.\n lastu = 0.\n\n do j = 0, ivmax-1\n ! set v\n v = real(j, KIND(v))\n\n ! solve u = u(v) with a N-R procedure\n lastu = 2*TOL\n converged = .false.\n do while (.not. converged)\n F = force(u, v)\n if (abs(u - lastu) > TOL) then\n DF = dforce(u, v)\n Du = -F/DF\n lastu = u\n u = u + Du\n else\n converged = .true.\n endif\n enddo\n\n ! compute P from u, v and fill arrays\n x(j+1) = v\n y(j+1) = u\n P(j+1) = (E*Vv/Lv**4)*(v*v + u*u - 2*h*v + 2*u*(a + b))*(v - h)\n enddo\n\n ! Linear response\n do j = 0, ivmaxl-1\n v = real(j, KIND(v))\n vl(j + 1) = v\n ul(j + 1) = 2*h*v*(a + b)*Vv/Lv**4/(Vh/a**2 + 2*Vv*(a + b)**2/Lv**4)\n Pl(j + 1) = -2*h*Vv*E/Lv**4*(ul(v + 1)*(a + b) - h*v)\n enddo\n\ncontains\n function force(u, v)\n implicit none\n real(DP), intent(in) :: u, v\n real(DP) :: force\n force = (Vv/Lv**4)*(v**2 + u**2 - 2*h*v + 2*u*(a + b))*(u + a + b) &\n + (8*Vh/Lh**4)*(u**2 + 2*a*u)*(u + a)\n end function\n\n function dforce(u, v)\n implicit none\n real(DP), intent(in) :: u, v\n real(DP) :: dforce\n dforce = (Vv/Lv**4)*((u + a + b)*(2*u + 2*(a + b)) &\n + (v**2 + u**2 - 2*h*v + 2*u*(a + b))) &\n + (8*Vh/Lh**4)*((2*u + 2*a)*(u + a) + (u**2 + 2*u*a))\n end function\n\nend subroutine theoric\n", "meta": {"hexsha": "a534d3ec98dbf12043f7fe64fa0e9552a209add7", "size": 3530, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "student/mico/theoric.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/mico/theoric.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/mico/theoric.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": 28.9344262295, "max_line_length": 85, "alphanum_fraction": 0.3634560907, "num_tokens": 1142, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802417938535, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6907086956836691}} {"text": "c this version from 18 March 1998 uses revised coefficients \nc that are consistent with Cordes \\& Rickett (1998, ApJ, submitted)\nc modifications:\nc\t28 March 2001: added FUNCTION TRANSITION_FREQUENCY \n \n REAL FUNCTION TAUISS(d, sm, nu)\nc\nc calculates the pulse broadening time in ms\nc from distance, scattering measure, and radio frequency\nc\nc input: d = pulsar distance (kpc) \nc sm = scattering measure (kpc m^{-20/3})\nc nu = radio frequency (GHz)\nc output: tauss = pulse broadening time (ms) \nc\n implicit none\n real d, sm, nu\n tauiss = 1000. * (sm / 292.)**1.2 * d * nu**(-4.4)\n end\nc\nc\n REAL FUNCTION SCINTBW(d, sm, nu)\nc\nc calculates the scintillation bandwidth in kHz \nc from distance, scattering measure, and radio frequency\nc\nc input: d = pulsar distance (kpc) \nc sm = scattering measure (kpc m^{-20/3})\nc nu = radio frequency (GHz)\nc output: scintbw = scintillation bandwidth (kHz)\nc\n implicit none\n real d, sm, nu\n real c1\n parameter(c1=1.16)\t\t! for uniform, Kolmogorov medium\n real tauiss\n tauiss = 1000. * (sm / 292.)**1.2 * d * nu**(-4.4)\t! ms\n scintbw = c1 / (2. * 3.14159 * tauiss)\t\t\t! kHz\n end\n \n REAL FUNCTION SCINTIME(sm, nu, vperp)\nc\nc calculates the scintillation speed for given distance, galactic\nc longitude and latitude, frequency, and transverse velocity \nc\nc input: sm = scattering measure\t(kpc m^{-20/3})\nc nu = radio frequency \t(GHz)\nc vperp = psr transverse speed \t(km/s) \nc\nc output: scintime = scintillation time (sec)\nc \nc usage: should be called with sm = smtau for appropriate\nc line of sight weighting\nc reference: eqn (46) of Cordes & Lazio 1991, ApJ, 376, 123.\nc\n implicit none\n real sm, nu, vperp\nc nb: formerly, the coeff. in the following line was 2.3 from \nc Cordes & Lazio (1991)\n scintime = 3.3 * nu**1.2 * sm**(-0.6) * (100./vperp)\n end\n \n \n REAL FUNCTION SPECBROAD(sm, nu, vperp)\nc\nc calculates the bandwdith of spectral broadening\nc for given scattering measure, , frequency, and transverse velocity \n \nc input: sm = scattering measure\t(kpc m^{-20/3})\nc nu = radio frequency \t(GHz)\nc vperp = psr transverse speed \t(km/s) \n \nc output: specbroad = spectral broadening bandwidth (Hz)\nc \nc usage: should be called with sm = smtau for appropriate\nc line of sight weighting\nc reference: eqn (47) of Cordes & Lazio 1991, ApJ, 376, 123.\nc\n implicit none\n real sm, nu, vperp\nc nb: the coeff. in the following line is 0.14 Hz from Cordes & Lazio (1991)\nc it is changed to 0.097 to conform with FUNCTION SCINTIME and\nc a new calculation consistent with Cordes & Rickett (1998)\n\n specbroad = 0.097 * nu**(-1.2) * sm**0.6 * (vperp/100.)\t! Hz\n end\n \n \n REAL FUNCTION THETA_XGAL(sm, nu)\nc\nc calculates angular broadening for an extragalactic\nc source of plane waves\nc\nc sm = scattering measure\nc nu = radio frequency\nc theta_xgal = angular broadening FWHM (mas)\nc\n implicit none\n real sm, nu\n theta_xgal = 128. * sm**0.6 * nu**(-2.2)\n end\nc\n REAL FUNCTION THETA_GAL(sm, nu)\nc\nc calculates angular broadening for a galactic\nc source of spherical waves\nc\nc sm = scattering measure\nc nu = radio frequency\nc theta_gal = angular broadening FWHM (mas)\nc\n implicit none\n real sm, nu\n theta_gal = 71. * sm**0.6 * nu**(-2.2)\n end\nc\n FUNCTION EM (sm)\nc\nc units of sm are kpc m^{-20/3}\nc units of em are pc cm^{-6} \nc\nc calculates the emission measure from the scattering measure\nc using an assumed outer scale and spectral index of the\nc wavenumber spectrum.\nc\nc for a wavenumber spectrum P_n(q) = q^{-alpha} from q_0 to q_1\nc the mean square electron density is\nc\nc =~ 4pi*[C_n^2 / (alpha - 3) ] * q_0^{3 - alpha)\nc\nc ( an approximate form that assumes (q_0 / q_1)^{3-alpha} >> 1.\nc\nc Jim Cordes 18 Dec 1989\nc\n data router /1./\t! outer scale = 1 pc\n data pc/3.086e+18/\n data alpha/3.6666667/\n data pi/3.14159/\nc\n em = sm *\n 1 ( (4. * pi * 1000.) / (alpha - 3.) ) * \n 2 (router*pc / (2. * 3.14159) )**(alpha-3.) *\n 3 (0.01) ** (20./3.)\nc\n return\n end \n\n REAL FUNCTION THETA_ISO(smiso, nu)\n real smiso, nu\n\nc smiso in (kpc m^{-20/3}) x kpc^{5/3}\nc nu in GHz\nc returns the isoplanatic angle in microarcsec\nc 12 October 1998 \nc JMC\n\n\nc \\theta_{iso} = \\delta r_s / d\nc = \\left [\nc\t (\\lambda r_e)^2 f_{\\alpha} SM_{iso}\nc\t\t \\right ]^{1/\\alpha}\nc where \\alpha = 5/3 for Kolmogorov case.\nc NB SM_{iso} = \\int_0^d ds s^{\\alpha} \\cnsq\nc so SM_{iso} does not have the units of scattering\nc measure, but rather units of SM x Length^{\\alpha}\nc\nc f_{\\alpha} = 8\\pi^2 \\Gamma(1-\\alpha/2) / [\\alpha 2^{\\alpha} \\Gamma(1+\\alpha/2)]\nc for \\alpha = 5/3, f_{\\alpha}= 88.3\nc\nc real r_e\nc parameter(r_e = 2.82e-13)\t\t\t!cm\nc real kpc\nc parameter(kpc = 3.086e21)\t\t\t!cm\nc real falpha\nc parameter(falpha=88.3)\n\n theta_log_radian = \n . 13.287 \t\t\t\t! 0.6*log10(30cm*r_e)\n . + 1.2 * alog10(nu) \n . - 1.1676\t\t\t\t! 0.6*log10(f_alpha) \n . - 0.6 * alog10(smiso)\n . - 34.383\t\t\t\t! 1.6 * alog10(kpc)\n . + 8.\t\t\t\t\t! -(20/3)*log(100)\n theta_log_microarcsec = \n . theta_log_radian + 11.314425\t! 11.314425=alog10(microarsec/rad)\n theta_iso = 10.**theta_log_microarcsec\n return\n end\n\n\n\n REAL FUNCTION THETA_ISO_TEST(smiso, nu)\n real smiso, nu\n\nc smiso in (kpc m^{-20/3}) x kpc^{5/3}\nc nu in GHz\nc returns the isoplanatic angle in microarcsec\nc 12 October 1998 \nc JMC\n\n\nc \\theta_{iso} = \\delta r_s / d\nc = \\left [\nc\t (\\lambda r_e)^2 f_{\\alpha} SM_{iso}\nc\t\t \\right ]^{1/\\alpha}\nc where \\alpha = 5/3 for Kolmogorov case.\nc NB SM_{iso} = \\int_0^d ds s^{\\alpha} \\cnsq\nc so SM_{iso} does not have the units of scattering\nc measure, but rather units of SM x Length^{\\alpha}\nc\nc f_{\\alpha} = 8\\pi^2 \\Gamma(1-\\alpha/2) / [\\alpha 2^{\\alpha} \\Gamma(1+\\alpha/2)]\nc for \\alpha = 5/3, f_{\\alpha}= 88.3\nc\nc real r_e\nc parameter(r_e = 2.82e-13)\t\t\t!cm\nc real kpc\nc parameter(kpc = 3.086e21)\t\t\t!cm\nc real falpha\nc parameter(falpha=88.3)\n\n theta_log_radian = \n . 13.287 \t\t\t\t! 0.6*log10(30cm*r_e)\n . + 1.2 * alog10(nu) \n . - 1.1676\t\t\t\t! 0.6*log10(f_alpha) \n . - 0.6 * alog10(smiso)\n . - 34.383\t\t\t\t! 1.6 * alog10(kpc)\n . + 8.\t\t\t\t\t! -(20/3)*log(100)\n theta_log_microarcsec = \n . theta_log_radian + 11.314425\t! 11.314425=alog10(microarsec/rad)\n theta_iso_test = 10.**theta_log_microarcsec\nc write(6,*) 'smiso, nu = ', smiso, nu\nc write(6,*) 'theta_log_radian = ', theta_log_radian\nc write(6,*) 'theta_log_microarcsec = ', theta_log_microarcsec\nc write(6,*) 'theta_iso = ', theta_iso_test\n return\n end\n\n REAL FUNCTION TRANSITION_FREQUENCY(sm, smtau, smtheta, dintegrate)\n implicit none\n real sm, smtau, smtheta, dintegrate\nc returns the transition frequency between weak and strong scattering\nc 28 March 2001 \nc JMC\n\nc input:\nc (all sm values in (kpc m^{-20/3})) \nc\t sm = int[\\cnsq]\nc smtau = int[(s/D)(1-s/D) \\cnsq]\nc smtheta = int[ (1-s/D) \\cnsq]\nc dintegrate = distance used to integrate \\cnsq (kpc) \nc output:\nc transition_frequency = GHz given by\nc \t\\nu_t = 318 GHz \\xi^{10/17} SM^{6/17} D_{eff}^{5/17}\nc where \nc D_{eff} = effective path length through medium\nc D_{eff} = \\int_0^dintegrate ds s \\cnsq / \\int_0^dintegrate ds \\cnsq\nc\nc Note we can calculate D_{eff} using\nc D_{eff} = dintegrate * (sm - smtau/6 - smtau/3) / sm\nc\n real deff\n real xi\n parameter(xi= 0.3989) ! (2.*pi)^{-1/2} = fresnel scale definition factor\n real coefficient\n parameter(coefficient=318.)\t ! GHz; see NE2001 paper\n deff = (dintegrate*(sm - smtau/6. - smtheta/3.)) / sm \n transition_frequency = \n . coefficient * xi**(10./17.) * sm**(6./17.) * deff**(5./17.) \n return\n end\n\n", "meta": {"hexsha": "ced9de801dbe865704d961a25afcdba1cbe65c47", "size": 8144, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "pyne2001/NE2001/src/scattering98.f", "max_stars_repo_name": "v-morello/pyne2001", "max_stars_repo_head_hexsha": "d080568df76f7dd427d29532b828ab367a03b831", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "pyne2001/NE2001/src/scattering98.f", "max_issues_repo_name": "v-morello/pyne2001", "max_issues_repo_head_hexsha": "d080568df76f7dd427d29532b828ab367a03b831", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-06-04T15:48:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-05T21:03:43.000Z", "max_forks_repo_path": "pyne2001/NE2001/src/scattering98.f", "max_forks_repo_name": "v-morello/pyne2001", "max_forks_repo_head_hexsha": "d080568df76f7dd427d29532b828ab367a03b831", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-04-13T11:25:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-13T11:25:08.000Z", "avg_line_length": 29.9411764706, "max_line_length": 81, "alphanum_fraction": 0.6097740668, "num_tokens": 2871, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480252950991, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6907086938644718}} {"text": "\nsubroutine densty(nz, mubar_z, T, den, P, press)\n use photochem_data, only: grav_z, p0, &\n dz\n implicit none\n \n integer, intent(in) :: nz\n real(8), intent(in) :: mubar_z(nz), T(nz)\n real(8), intent(out) :: den(nz), P(nz), press(nz)\n \n ! local varaibles\n real*8 rgas, bk\n real*8 roverm\n real*8 t0, p1, ha, tav\n integer i\n! THIS SUBROUTINE CALCULATES ATMOSPHERIC NUMBER DENSITIES, ASSUM-\n! ING HYDROSTATIC EQUILIBRIUM\n ! g0 = g\n rgas = 8.3143E7\n bk = 1.38054E-16\n\n \n roverm = rgas/mubar_z(1)\n\n t0 = T(1) + (T(1)-T(2))/2.\n ha = roverm*0.5*(t0+T(1))/grav_z(1)\n p1 = p0*1E6*EXP(-0.5*DZ(1)/ha)\n DEN(1) = p1/(bk*T(1))\n!\n! ***** FIND DENSITY FROM HYDROSTATIC EQUILIBRIUM *****\n DO i = 2 , nz\n roverm = rgas/mubar_z(i)\n ! r = r0 + Z(i)\n ! gz = g0*(r0/r)*(r0/r)\n tav = 0.5*(T(i)+T(i-1))\n ha = roverm*tav/grav_z(i)\n DEN(i) = DEN(i-1)*EXP(-DZ(i)/ha)*T(i-1)/T(i)\n ENDDO\n! ***** FIND PRESSURE FROM THIS DENSITY *********\n DO i = 1 , nz\n PRESS(i) = DEN(i)*bk*T(i) ! dynes\n ENDDO\n ! pressure in bars\n do i = 1,nz\n P(i) = DEN(i)*1.38E-16*T(i) * 1.0e-6 !bars\n enddo\n\nend subroutine\n\nsubroutine mean_molecular_weight(nq, usol_layer, mass, background_mu, mubar, err)\n implicit none\n \n integer, intent(in) :: nq\n real(8), intent(in) :: usol_layer(nq)\n real(8), intent(in) :: mass(nq)\n real(8), intent(in) :: background_mu\n \n real(8), intent(out) :: mubar\n character(len=1000), intent(out) :: err\n integer :: j\n real(8) :: f_background\n err = \"\"\n\n mubar = 0.d0\n do j = 1, nq\n mubar = mubar + usol_layer(j) * mass(j)\n enddo\n f_background = 1 - sum(usol_layer)\n \n if (f_background < 0.d0) then\n err = \"Mixing ratios sum to > 1.0. Atmosphere is probably in a run-away state.\"\n return\n endif\n \n mubar = mubar + f_background * background_mu\n \nend subroutine\n\n\n\n\n", "meta": {"hexsha": "7fa672f913ce85819eaa33eeaf7a9b9afca6b647", "size": 1852, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/Densty.f90", "max_stars_repo_name": "Nicholaswogan/PhotochemPy", "max_stars_repo_head_hexsha": "68c45a1d11660ae3d4f2c6ea43ee5dc403d4cb94", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2021-01-06T23:07:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-27T17:06:03.000Z", "max_issues_repo_path": "src/Densty.f90", "max_issues_repo_name": "StAtmos/PhotochemPy", "max_issues_repo_head_hexsha": "68c45a1d11660ae3d4f2c6ea43ee5dc403d4cb94", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-07-15T09:55:36.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-23T17:32:45.000Z", "max_forks_repo_path": "src/Densty.f90", "max_forks_repo_name": "StAtmos/PhotochemPy", "max_forks_repo_head_hexsha": "68c45a1d11660ae3d4f2c6ea43ee5dc403d4cb94", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2021-01-09T00:22:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-04T16:01:25.000Z", "avg_line_length": 22.5853658537, "max_line_length": 83, "alphanum_fraction": 0.5858531317, "num_tokens": 738, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802462567087, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6907086888302872}} {"text": "!>@brief Calculate $E(k)$ by Karman formula\n!>@detail \u0414\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0438\u0437\u043e\u0442\u0440\u043e\u043f\u043d\u043e\u0439 \u0442\u0443\u0440\u0431\u0443\u043b\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043c\u0435\u0442\u043e\u0434, \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u0432 \u0440\u0430\u0431\u043e\u0442\u0435 Rogallo [1]. \n!!\n!! \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u041a\u0430\u0440\u043c\u0430\u043d\u0430 \u0441\u043f\u0435\u043a\u0442\u0440\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u0438 \u044d\u043d\u0435\u0440\u0433\u0438\u0438:\n!! $${ E(k) = \\frac{\\sigma^2 L }{2 \\pi} \\frac{(\\alpha k L)^4}{(1+(\\alpha k L)^2)^{17/6}} }$$,\n!! \u0433\u0434\u0435 _k_ - \u0432\u043e\u043b\u043d\u043e\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u043e\u0442\u0430, $\\sigma = \\sqrt{u'^2+v'^2+w'^2}$ - \u0441\u0440\u0435\u0434\u043d\u0435\u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u043e\u0435 \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u0435; \n!! $\\alpha$ - \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 ??? ($\\alpha\\approx 1.339$). _L_ - \u043c\u0430\u0441\u0448\u0442\u0430\u0431 \u0442\u0443\u0440\u0431\u0443\u043b\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438.\n!!\nfunction set_eturb(dk, dl_in, dsigma_in) result(de)\n USE prec_mod\n USE constants, ONLY: f_zero, f_pi\n implicit none\n real(prec), intent(IN) :: dk !< wave number\n real(prec), intent(IN), optional :: dl_in !< Integral Length Scale (set by default 0.1 m)\n real(prec), intent(IN), optional :: dsigma_in !< RMS of velocities (set by default 10 m/s)\n real(prec) :: de !< return value\n\n real(prec), save :: dl_def = 1.0d-1\n real(prec), save :: dsig_def = 1.0d+1\n real(prec) :: dl\n real(prec) :: dsig\n real(prec) :: dalpha\n real(prec) :: dtmp\n\n! check if presented\n dl = dl_def ! [m]\n if(present(dl_in)) dl = dl_in\n\n dsig = dsig_def ! [m/s]\n if(present(dsigma_in)) dsig = dsigma_in\n\n ! write(*,*) \"set_eturb: dl and dsig\", dl,dsig\n\n dalpha = 1.339d0\n dtmp = (dalpha * dl * dk ) ** 2\n\n de = dl * 5.5d+1 / f_pi / 2.7d+1\n de = de * (dtmp * dsig)**2\n de = de / (1.d0 + dtmp)**(1.7d+1/6.0d0)\n\n return\nend function set_eturb\n", "meta": {"hexsha": "b2b12da07f4536929b973a5a08abf93df880f736", "size": 1422, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/set_eturb.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_eturb.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_eturb.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": 33.0697674419, "max_line_length": 103, "alphanum_fraction": 0.6308016878, "num_tokens": 586, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802395624259, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6907086837961025}} {"text": "!------------------------------------------------------------------------------\n! MODULE: grid_utils\n!\n!> @author\n!> Pavel Junker\n!\n! DESCRIPTION: \n!> basically just Fortran analogs of Octave/Matlab 'linspace' and 'meshgrid'\n!\n! REVISION HISTORY:\n! 13.03.2021 - Initial Version\n!------------------------------------------------------------------------------\nmodule grid_utils\n\timplicit none\n\tprivate\n\tinteger, parameter :: DP = kind(0.D0)\n\tpublic :: grid_init_1d, grid_init_2d\ncontains\n \n\tpure subroutine grid_init_1d(grid, low, high, n)\n\t\tinteger, intent(in) :: n\n\t\treal(kind=DP), intent(out) :: grid(1,n)\n\t\treal(kind=DP), intent(in) :: low, high\n\t\treal(kind=DP) :: a, b\n\t\tinteger :: i\n\n\t\t! obtain axis by linear transformation of sequence 1, 2, ..., n\n\t\ta = (high - low)/(n - 1)\n\t\tb = (low*n - high)/(n - 1)\n\t\tgrid(1,:) = a * [(i, i=1,n)] + b\n\n\tend subroutine grid_init_1d\n\n\tpure subroutine grid_init_2d(grid, x_low, x_high, y_low, y_high, nx, ny)\n\t\tinteger, intent(in) :: nx, ny\n\t\treal(kind=DP), intent(out) :: grid(2,nx*ny)\n\t\treal(kind=DP), intent(in) :: x_low, x_high, y_low, y_high\n\t\treal(kind=DP) :: a, b\n\t\tinteger :: i, j, k\n\n\t\tk = 1\n\t\tdo i=1,nx\n\t\t\tdo j=1,ny\n\t\t\t\tgrid(:,k) = [i,j]\n\t\t\t\tk = k + 1\n\t\t\tend do\n\t\tend do\n\t\t! transform x axis\n\t\ta = (x_high - x_low)/(nx - 1)\n\t\tb = (x_low*nx - x_high)/(nx - 1)\n\t\tgrid(1,:) = a * grid(1,:) + b\n\t\t! transform y axis\n\t\ta = (y_high - y_low)/(ny - 1)\n\t\tb = (y_low*ny - y_high)/(ny - 1)\n\t\tgrid(2,:) = a * grid(2,:) + b\n\n\tend subroutine grid_init_2d\n\nend module grid_utils\n", "meta": {"hexsha": "6d9f03d865e3abbfa6e16456e012cae68e8a7eec", "size": 1518, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "kde/src/grid_utils.f90", "max_stars_repo_name": "PYunker/HeClustersDMC2", "max_stars_repo_head_hexsha": "b36353d40804344b7cedc346d9ff88c81dea6d01", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "kde/src/grid_utils.f90", "max_issues_repo_name": "PYunker/HeClustersDMC2", "max_issues_repo_head_hexsha": "b36353d40804344b7cedc346d9ff88c81dea6d01", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "kde/src/grid_utils.f90", "max_forks_repo_name": "PYunker/HeClustersDMC2", "max_forks_repo_head_hexsha": "b36353d40804344b7cedc346d9ff88c81dea6d01", "max_forks_repo_licenses": ["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.3, "max_line_length": 79, "alphanum_fraction": 0.5428194993, "num_tokens": 522, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118111485244, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.6907041047570543}} {"text": " PROGRAM SIMPLIF\n INTEGER I\n REAL*4 R\n REAL*8 D\n COMPLEX*8 C\n COMPLEX*16 DC\n\n I = INT(-590E-2) !-5\n I = INT(-590D-2) !-5\n I = INT((-590E-2, 3.4E2)) !-5\n I = INT(INT(I)) !I\n I = INT(INT(INT(R))) !INT(R)\n\nC R -> I\n I = 5.9 !5\n I = 5.9E2 !590\n I = 590E-2 !5\n I = -5.9 !-5\n I = -5.9E2 !-590\n I = -590E-2 !-5\n\nC I -> R\n R = R + 5 + 5.9 + I\n\nC D -> R\n R = +590.9D-2 !590.9E-2 \n R = -590.9D-2 !-590.9E-2\n\nC R -> D\n D = +5.9E2 !5.9D2\n D = -5.9E2 !-5.9D2\n\nC D -> I\n I = 5.9D2 !590\n I = 590D-2 !5\n I = -5.9D2 !-590\n I = -590D-2 !-5\n\n I = -R\n R = -I\n I = -D\n D = -I\n\nC R -> C\n C = -5.9E2 !-(5.9E2, 0.0)\n C = 590E-2 !(590E-2, 0.0)\n\nc D -> C\n C = -5.9D2 !-(5.9E2, 0.0)\n C = 590D-2 !(590E-2, 0.0)\n\nC I -> C\n C = -5 !-(5.0, 0.0)\n C = 5 !(5.0, 0.0)\n\nC C -> R\n R = (5.9D2, 3.9D2) !5.9E2\n R = (5.9E2, 3.9) !5.9E2\n R = (-590.9E-1, 3.4) !-590.9E-1\n R = -(590.9E-1, 3.4) !-590.9E-1\n\nC C -> D\n D = (5.9E2, 3.4E2) !5.9D2\n D = (590E-2, 3.4E2) !590D-2\n D = (-590E-2, 3.4E2) !-590D-2\n\nC C -> I\n I = (5.9E2, 3.4E2) !590\n I = (590E-2, 3.4E2) !5\n I = (-590E-2, 3.4E2) !-5\n\n R = SIN(R)\n D = SIN(D)\n C = SIN(C)\n\nC DC -> C\n C = (-5.9E2, 3.9D2) !(-5.9E2, 3.9E2)\n C = CMPLX((-5.9E2, 3.9D2)) !(-5.9E2, 3.9E2)\n DC = (-5.9E2, 3.9D2) !(-5.9E2, 3.9E2)\n\nC C -> DC\n DC = (-5.9E2, -3.9D2) !(-5.9D2, -3.9D2)\n DC = (5.9E2, -3.9E2) !(5.9D2, -3.9D2)\n DC = DCMPLX((5.9E2, -3.9E2)) !(5.9D2, -3.9D2)\n\nC DC -> D\n D = (-5.9D2, -3.9D2) !-5.9D2\n\nC DC -> R\n R = (-5.9D2, -3.9D2) !-5.9E2\n\nC DC -> I\n I = (-5.9D2, -3.9D2) !-590\n \nC I -> DC\n DC = 5 !(5.0, 0.0)\n DC = -5.9E2 !-(5.9D2, 0.0)\n DC = -5.9D2 !-(5.9D2, 0.0)\n\nC others...\n \n I = REAL(DBLE((10.0D0,-10.0D0)))\n\n END\n\n\n\n\n\n\n", "meta": {"hexsha": "63a8bb3ea4ca3c617cea99f37b490b3b702c5367", "size": 2504, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "packages/PIPS/validation/Flint/simplification.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/Flint/simplification.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/Flint/simplification.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": 22.5585585586, "max_line_length": 56, "alphanum_fraction": 0.285942492, "num_tokens": 1188, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835371034368, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.6907040920917612}} {"text": "module p2grid\nimplicit none\n\ncontains\n\nfunction index2lagpos(id,ng)\nimplicit none\ninteger(8)::id\ninteger(4)::ng\nreal(4)::index2lagpos(3)\n! index range from 0 - ng^3-1\n! output range is (0,ng]\ninteger(8)::id2\ninteger(4)::i,j,k\nid2=id\nk=id2/ng**2\nid2=id2-k*ng**2\nj=id2/ng\ni=id2-j*ng\nindex2lagpos=[k,j,i]\nendfunction index2lagpos\n\n! ===== density =====\nsubroutine massassign(np,pos,ng,den8,cmd)\nuse omp_lib\nimplicit none\ninteger(4)::np\nreal(4)::pos(3,np)\ninteger(4)::ng\nreal(8)::den8(ng,ng,ng)\ninteger(4)::cmd\ninteger(4)::ibin,jbin,kbin,ibinm1,jbinm1,kbinm1,ibinp1,jbinp1,kbinp1\nreal(4)::hx,hy,hz,hx0,hy0,hz0,hxm1,hym1,hzm1,hxp1,hyp1,hzp1\ninteger(4)::pid\nreal(8)::tmp1,tmp2\ninteger(4)::i,j,k\n!$omp parallel do default(shared)\ndo k=1,ng\n den8(:,:,k)=0.d0\nenddo\n!$omp end parallel do\nwrite(*,*) 'begin mass assignment by method',cmd\nif (cmd.eq.1) then\n ! NGP\n !$omp parallel do default(private) shared(np,pos,den8) schedule(static)\n do pid=1,np\n ibin=ceiling(pos(1,pid))\n jbin=ceiling(pos(2,pid))\n kbin=ceiling(pos(3,pid))\n !$omp atomic\n den8(ibin,jbin,kbin)=den8(ibin,jbin,kbin)+1.d0\n enddo\n !$omp end parallel do\nelseif (cmd.eq.2) then\n ! CIC\n !$omp parallel do default(private) shared(np,ng,pos,den8) schedule(static)\n do pid=1,np\n ibin=ceiling(pos(1,pid))\n jbin=ceiling(pos(2,pid))\n kbin=ceiling(pos(3,pid))\n hx=pos(1,pid)-ibin+0.5\n hy=pos(2,pid)-jbin+0.5\n hz=pos(3,pid)-kbin+0.5\n hx0=1.-abs(hx)\n if (hx.gt.0.) then\n hxp1=hx\n hxm1=0.\n else\n hxp1=0.\n hxm1=-hx\n endif\n hy0=1.-abs(hy)\n if (hy.gt.0.) then\n hyp1=hy\n hym1=0.\n else\n hyp1=0.\n hym1=-hy\n endif\n hz0=1.-abs(hz)\n if (hz.gt.0.) then\n hzp1=hz\n hzm1=0.\n else\n hzp1=0.\n hzm1=-hz\n endif\n ibinm1=mod(ibin-2+ng,ng)+1\n jbinm1=mod(jbin-2+ng,ng)+1\n kbinm1=mod(kbin-2+ng,ng)+1\n ibinp1=mod(ibin+ng,ng)+1\n jbinp1=mod(jbin+ng,ng)+1\n kbinp1=mod(kbin+ng,ng)+1\n !$omp atomic\n den8(ibinm1,jbinm1,kbinm1)=den8(ibinm1,jbinm1,kbinm1)+hxm1*hym1*hzm1\n !$omp atomic\n den8(ibin ,jbinm1,kbinm1)=den8(ibin ,jbinm1,kbinm1)+hx0 *hym1*hzm1\n !$omp atomic\n den8(ibinp1,jbinm1,kbinm1)=den8(ibinp1,jbinm1,kbinm1)+hxp1*hym1*hzm1\n !$omp atomic\n den8(ibinm1,jbin ,kbinm1)=den8(ibinm1,jbin ,kbinm1)+hxm1*hy0 *hzm1\n !$omp atomic\n den8(ibin ,jbin ,kbinm1)=den8(ibin ,jbin ,kbinm1)+hx0 *hy0 *hzm1\n !$omp atomic\n den8(ibinp1,jbin ,kbinm1)=den8(ibinp1,jbin ,kbinm1)+hxp1*hy0 *hzm1\n !$omp atomic\n den8(ibinm1,jbinp1,kbinm1)=den8(ibinm1,jbinp1,kbinm1)+hxm1*hyp1*hzm1\n !$omp atomic\n den8(ibin ,jbinp1,kbinm1)=den8(ibin ,jbinp1,kbinm1)+hx0 *hyp1*hzm1\n !$omp atomic\n den8(ibinp1,jbinp1,kbinm1)=den8(ibinp1,jbinp1,kbinm1)+hxp1*hyp1*hzm1\n !$omp atomic\n den8(ibinm1,jbinm1,kbin )=den8(ibinm1,jbinm1,kbin )+hxm1*hym1*hz0\n !$omp atomic\n den8(ibin ,jbinm1,kbin )=den8(ibin ,jbinm1,kbin )+hx0 *hym1*hz0\n !$omp atomic\n den8(ibinp1,jbinm1,kbin )=den8(ibinp1,jbinm1,kbin )+hxp1*hym1*hz0\n !$omp atomic\n den8(ibinm1,jbin ,kbin )=den8(ibinm1,jbin ,kbin )+hxm1*hy0 *hz0\n !$omp atomic\n den8(ibin ,jbin ,kbin )=den8(ibin ,jbin ,kbin )+hx0 *hy0 *hz0\n !$omp atomic\n den8(ibinp1,jbin ,kbin )=den8(ibinp1,jbin ,kbin )+hxp1*hy0 *hz0\n !$omp atomic\n den8(ibinm1,jbinp1,kbin )=den8(ibinm1,jbinp1,kbin )+hxm1*hyp1*hz0\n !$omp atomic\n den8(ibin ,jbinp1,kbin )=den8(ibin ,jbinp1,kbin )+hx0 *hyp1*hz0\n !$omp atomic\n den8(ibinp1,jbinp1,kbin )=den8(ibinp1,jbinp1,kbin )+hxp1*hyp1*hz0\n !$omp atomic\n den8(ibinm1,jbinm1,kbinp1)=den8(ibinm1,jbinm1,kbinp1)+hxm1*hym1*hzp1\n !$omp atomic\n den8(ibin ,jbinm1,kbinp1)=den8(ibin ,jbinm1,kbinp1)+hx0 *hym1*hzp1\n !$omp atomic\n den8(ibinp1,jbinm1,kbinp1)=den8(ibinp1,jbinm1,kbinp1)+hxp1*hym1*hzp1\n !$omp atomic\n den8(ibinm1,jbin ,kbinp1)=den8(ibinm1,jbin ,kbinp1)+hxm1*hy0 *hzp1\n !$omp atomic\n den8(ibin ,jbin ,kbinp1)=den8(ibin ,jbin ,kbinp1)+hx0 *hy0 *hzp1\n !$omp atomic\n den8(ibinp1,jbin ,kbinp1)=den8(ibinp1,jbin ,kbinp1)+hxp1*hy0 *hzp1\n !$omp atomic\n den8(ibinm1,jbinp1,kbinp1)=den8(ibinm1,jbinp1,kbinp1)+hxm1*hyp1*hzp1\n !$omp atomic\n den8(ibin ,jbinp1,kbinp1)=den8(ibin ,jbinp1,kbinp1)+hx0 *hyp1*hzp1\n !$omp atomic\n den8(ibinp1,jbinp1,kbinp1)=den8(ibinp1,jbinp1,kbinp1)+hxp1*hyp1*hzp1\n enddo\n !$omp end parallel do\nelseif (cmd.eq.3) then\n ! TSC\n !$omp parallel do default(private) shared(np,ng,pos,den8) schedule(static)\n do pid=1,np\n ibin=ceiling(pos(1,pid))\n jbin=ceiling(pos(2,pid))\n kbin=ceiling(pos(3,pid))\n hx=pos(1,pid)-ibin+0.5\n hy=pos(2,pid)-jbin+0.5\n hz=pos(3,pid)-kbin+0.5\n hx0=0.75-hx**2\n hxp1=0.5*(0.5+hx)**2\n hxm1=0.5*(0.5-hx)**2\n hy0=0.75-hy**2\n hyp1=0.5*(0.5+hy)**2\n hym1=0.5*(0.5-hy)**2\n hz0=0.75-hz**2\n hzp1=0.5*(0.5+hz)**2\n hzm1=0.5*(0.5-hz)**2\n ibinm1=mod(ibin-2+ng,ng)+1\n jbinm1=mod(jbin-2+ng,ng)+1\n kbinm1=mod(kbin-2+ng,ng)+1\n ibinp1=mod(ibin+ng,ng)+1\n jbinp1=mod(jbin+ng,ng)+1\n kbinp1=mod(kbin+ng,ng)+1\n !$omp atomic\n den8(ibinm1,jbinm1,kbinm1)=den8(ibinm1,jbinm1,kbinm1)+hxm1*hym1*hzm1\n !$omp atomic\n den8(ibin ,jbinm1,kbinm1)=den8(ibin ,jbinm1,kbinm1)+hx0 *hym1*hzm1\n !$omp atomic\n den8(ibinp1,jbinm1,kbinm1)=den8(ibinp1,jbinm1,kbinm1)+hxp1*hym1*hzm1\n !$omp atomic\n den8(ibinm1,jbin ,kbinm1)=den8(ibinm1,jbin ,kbinm1)+hxm1*hy0 *hzm1\n !$omp atomic\n den8(ibin ,jbin ,kbinm1)=den8(ibin ,jbin ,kbinm1)+hx0 *hy0 *hzm1\n !$omp atomic\n den8(ibinp1,jbin ,kbinm1)=den8(ibinp1,jbin ,kbinm1)+hxp1*hy0 *hzm1\n !$omp atomic\n den8(ibinm1,jbinp1,kbinm1)=den8(ibinm1,jbinp1,kbinm1)+hxm1*hyp1*hzm1\n !$omp atomic\n den8(ibin ,jbinp1,kbinm1)=den8(ibin ,jbinp1,kbinm1)+hx0 *hyp1*hzm1\n !$omp atomic\n den8(ibinp1,jbinp1,kbinm1)=den8(ibinp1,jbinp1,kbinm1)+hxp1*hyp1*hzm1\n !$omp atomic\n den8(ibinm1,jbinm1,kbin )=den8(ibinm1,jbinm1,kbin )+hxm1*hym1*hz0\n !$omp atomic\n den8(ibin ,jbinm1,kbin )=den8(ibin ,jbinm1,kbin )+hx0 *hym1*hz0\n !$omp atomic\n den8(ibinp1,jbinm1,kbin )=den8(ibinp1,jbinm1,kbin )+hxp1*hym1*hz0\n !$omp atomic\n den8(ibinm1,jbin ,kbin )=den8(ibinm1,jbin ,kbin )+hxm1*hy0 *hz0\n !$omp atomic\n den8(ibin ,jbin ,kbin )=den8(ibin ,jbin ,kbin )+hx0 *hy0 *hz0\n !$omp atomic\n den8(ibinp1,jbin ,kbin )=den8(ibinp1,jbin ,kbin )+hxp1*hy0 *hz0\n !$omp atomic\n den8(ibinm1,jbinp1,kbin )=den8(ibinm1,jbinp1,kbin )+hxm1*hyp1*hz0\n !$omp atomic\n den8(ibin ,jbinp1,kbin )=den8(ibin ,jbinp1,kbin )+hx0 *hyp1*hz0\n !$omp atomic\n den8(ibinp1,jbinp1,kbin )=den8(ibinp1,jbinp1,kbin )+hxp1*hyp1*hz0\n !$omp atomic\n den8(ibinm1,jbinm1,kbinp1)=den8(ibinm1,jbinm1,kbinp1)+hxm1*hym1*hzp1\n !$omp atomic\n den8(ibin ,jbinm1,kbinp1)=den8(ibin ,jbinm1,kbinp1)+hx0 *hym1*hzp1\n !$omp atomic\n den8(ibinp1,jbinm1,kbinp1)=den8(ibinp1,jbinm1,kbinp1)+hxp1*hym1*hzp1\n !$omp atomic\n den8(ibinm1,jbin ,kbinp1)=den8(ibinm1,jbin ,kbinp1)+hxm1*hy0 *hzp1\n !$omp atomic\n den8(ibin ,jbin ,kbinp1)=den8(ibin ,jbin ,kbinp1)+hx0 *hy0 *hzp1\n !$omp atomic\n den8(ibinp1,jbin ,kbinp1)=den8(ibinp1,jbin ,kbinp1)+hxp1*hy0 *hzp1\n !$omp atomic\n den8(ibinm1,jbinp1,kbinp1)=den8(ibinm1,jbinp1,kbinp1)+hxm1*hyp1*hzp1\n !$omp atomic\n den8(ibin ,jbinp1,kbinp1)=den8(ibin ,jbinp1,kbinp1)+hx0 *hyp1*hzp1\n !$omp atomic\n den8(ibinp1,jbinp1,kbinp1)=den8(ibinp1,jbinp1,kbinp1)+hxp1*hyp1*hzp1\n enddo\n !$omp end parallel do\nelse\n write(*,*) 'ERROR: mass assignment not specified'\nendif\nwrite(*,*) 'statistics:'\ntmp1=0.d0\ntmp2=0.d0\n!$omp parallel do default(shared) reduction(+:tmp1,tmp2) \ndo k=1,ng\n den8(:,:,k)=den8(:,:,k)/np*real(ng)**3-1.d0\n tmp1=tmp1+sum(den8(:,:,k))/real(ng)**3\n tmp2=tmp2+sum(den8(:,:,k)**2)/real(ng)**3\nenddo\n!$omp end parallel do\ntmp2=sqrt(tmp2)\nwrite(*,*) 'mean:',real(tmp1)\nwrite(*,*) 'sigma:',real(tmp2)\nendsubroutine massassign\n\n! ===== density =====\nsubroutine massassigndown(np,pos,ng,den8,cmd,nc,coarse)\nuse omp_lib\nimplicit none\ninteger(8)::np\nreal(4)::pos(3,np)\ninteger(4)::ng\nreal(8)::den8(ng,ng,ng)\ninteger(4)::cmd\ninteger(4)::nc,coarse\ninteger(4)::ibin,jbin,kbin,ibinm1,jbinm1,kbinm1,ibinp1,jbinp1,kbinp1\nreal(4)::hx,hy,hz,hx0,hy0,hz0,hxm1,hym1,hzm1,hxp1,hyp1,hzp1\ninteger(8)::pid\ninteger(8)::i8,j8,k8\nreal(8)::tmp1,tmp2\ninteger(4)::i,j,k\n!$omp parallel do default(shared)\ndo k=1,ng\n den8(:,:,k)=0.d0\nenddo\n!$omp end parallel do\nwrite(*,*) 'begin mass assignment by method',cmd\nif (cmd.eq.1) then\n ! NGP\n !$omp parallel do default(private) shared(np,pos,den8,nc,coarse) schedule(static)\n do pid=1,np\n k8=(pid-1)/nc/nc\n i8=(pid-1)-k8*nc*nc\n j8=i8/nc\n i8=i8-j8*nc\n if (any( mod([i8,j8,k8],coarse).ne.0 )) cycle\n ibin=ceiling(pos(1,pid))\n jbin=ceiling(pos(2,pid))\n kbin=ceiling(pos(3,pid))\n !$omp atomic\n den8(ibin,jbin,kbin)=den8(ibin,jbin,kbin)+1.d0\n enddo\n !$omp end parallel do\nelseif (cmd.eq.2) then\n ! CIC\n !$omp parallel do default(private) shared(np,ng,pos,den8,nc,coarse) schedule(static)\n do pid=1,np\n k8=(pid-1)/nc/nc\n i8=(pid-1)-k8*nc*nc\n j8=i8/nc\n i8=i8-j8*nc\n if (any( mod([i8,j8,k8],coarse).ne.0 )) cycle\n ibin=ceiling(pos(1,pid))\n jbin=ceiling(pos(2,pid))\n kbin=ceiling(pos(3,pid))\n hx=pos(1,pid)-ibin+0.5\n hy=pos(2,pid)-jbin+0.5\n hz=pos(3,pid)-kbin+0.5\n hx0=1.-abs(hx)\n if (hx.gt.0.) then\n hxp1=hx\n hxm1=0.\n else\n hxp1=0.\n hxm1=-hx\n endif\n hy0=1.-abs(hy)\n if (hy.gt.0.) then\n hyp1=hy\n hym1=0.\n else\n hyp1=0.\n hym1=-hy\n endif\n hz0=1.-abs(hz)\n if (hz.gt.0.) then\n hzp1=hz\n hzm1=0.\n else\n hzp1=0.\n hzm1=-hz\n endif\n ibinm1=mod(ibin-2+ng,ng)+1\n jbinm1=mod(jbin-2+ng,ng)+1\n kbinm1=mod(kbin-2+ng,ng)+1\n ibinp1=mod(ibin+ng,ng)+1\n jbinp1=mod(jbin+ng,ng)+1\n kbinp1=mod(kbin+ng,ng)+1\n !$omp atomic\n den8(ibinm1,jbinm1,kbinm1)=den8(ibinm1,jbinm1,kbinm1)+hxm1*hym1*hzm1\n !$omp atomic\n den8(ibin ,jbinm1,kbinm1)=den8(ibin ,jbinm1,kbinm1)+hx0 *hym1*hzm1\n !$omp atomic\n den8(ibinp1,jbinm1,kbinm1)=den8(ibinp1,jbinm1,kbinm1)+hxp1*hym1*hzm1\n !$omp atomic\n den8(ibinm1,jbin ,kbinm1)=den8(ibinm1,jbin ,kbinm1)+hxm1*hy0 *hzm1\n !$omp atomic\n den8(ibin ,jbin ,kbinm1)=den8(ibin ,jbin ,kbinm1)+hx0 *hy0 *hzm1\n !$omp atomic\n den8(ibinp1,jbin ,kbinm1)=den8(ibinp1,jbin ,kbinm1)+hxp1*hy0 *hzm1\n !$omp atomic\n den8(ibinm1,jbinp1,kbinm1)=den8(ibinm1,jbinp1,kbinm1)+hxm1*hyp1*hzm1\n !$omp atomic\n den8(ibin ,jbinp1,kbinm1)=den8(ibin ,jbinp1,kbinm1)+hx0 *hyp1*hzm1\n !$omp atomic\n den8(ibinp1,jbinp1,kbinm1)=den8(ibinp1,jbinp1,kbinm1)+hxp1*hyp1*hzm1\n !$omp atomic\n den8(ibinm1,jbinm1,kbin )=den8(ibinm1,jbinm1,kbin )+hxm1*hym1*hz0\n !$omp atomic\n den8(ibin ,jbinm1,kbin )=den8(ibin ,jbinm1,kbin )+hx0 *hym1*hz0\n !$omp atomic\n den8(ibinp1,jbinm1,kbin )=den8(ibinp1,jbinm1,kbin )+hxp1*hym1*hz0\n !$omp atomic\n den8(ibinm1,jbin ,kbin )=den8(ibinm1,jbin ,kbin )+hxm1*hy0 *hz0\n !$omp atomic\n den8(ibin ,jbin ,kbin )=den8(ibin ,jbin ,kbin )+hx0 *hy0 *hz0\n !$omp atomic\n den8(ibinp1,jbin ,kbin )=den8(ibinp1,jbin ,kbin )+hxp1*hy0 *hz0\n !$omp atomic\n den8(ibinm1,jbinp1,kbin )=den8(ibinm1,jbinp1,kbin )+hxm1*hyp1*hz0\n !$omp atomic\n den8(ibin ,jbinp1,kbin )=den8(ibin ,jbinp1,kbin )+hx0 *hyp1*hz0\n !$omp atomic\n den8(ibinp1,jbinp1,kbin )=den8(ibinp1,jbinp1,kbin )+hxp1*hyp1*hz0\n !$omp atomic\n den8(ibinm1,jbinm1,kbinp1)=den8(ibinm1,jbinm1,kbinp1)+hxm1*hym1*hzp1\n !$omp atomic\n den8(ibin ,jbinm1,kbinp1)=den8(ibin ,jbinm1,kbinp1)+hx0 *hym1*hzp1\n !$omp atomic\n den8(ibinp1,jbinm1,kbinp1)=den8(ibinp1,jbinm1,kbinp1)+hxp1*hym1*hzp1\n !$omp atomic\n den8(ibinm1,jbin ,kbinp1)=den8(ibinm1,jbin ,kbinp1)+hxm1*hy0 *hzp1\n !$omp atomic\n den8(ibin ,jbin ,kbinp1)=den8(ibin ,jbin ,kbinp1)+hx0 *hy0 *hzp1\n !$omp atomic\n den8(ibinp1,jbin ,kbinp1)=den8(ibinp1,jbin ,kbinp1)+hxp1*hy0 *hzp1\n !$omp atomic\n den8(ibinm1,jbinp1,kbinp1)=den8(ibinm1,jbinp1,kbinp1)+hxm1*hyp1*hzp1\n !$omp atomic\n den8(ibin ,jbinp1,kbinp1)=den8(ibin ,jbinp1,kbinp1)+hx0 *hyp1*hzp1\n !$omp atomic\n den8(ibinp1,jbinp1,kbinp1)=den8(ibinp1,jbinp1,kbinp1)+hxp1*hyp1*hzp1\n enddo\n !$omp end parallel do\nelseif (cmd.eq.3) then\n ! TSC\n !$omp parallel do default(private) shared(np,ng,pos,den8,nc,coarse) schedule(static)\n do pid=1,np\n k8=(pid-1)/nc/nc\n i8=(pid-1)-k8*nc*nc\n j8=i8/nc\n i8=i8-j8*nc\n if (any( mod([i8,j8,k8],coarse).ne.0 )) cycle\n ibin=ceiling(pos(1,pid))\n jbin=ceiling(pos(2,pid))\n kbin=ceiling(pos(3,pid))\n hx=pos(1,pid)-ibin+0.5\n hy=pos(2,pid)-jbin+0.5\n hz=pos(3,pid)-kbin+0.5\n hx0=0.75-hx**2\n hxp1=0.5*(0.5+hx)**2\n hxm1=0.5*(0.5-hx)**2\n hy0=0.75-hy**2\n hyp1=0.5*(0.5+hy)**2\n hym1=0.5*(0.5-hy)**2\n hz0=0.75-hz**2\n hzp1=0.5*(0.5+hz)**2\n hzm1=0.5*(0.5-hz)**2\n ibinm1=mod(ibin-2+ng,ng)+1\n jbinm1=mod(jbin-2+ng,ng)+1\n kbinm1=mod(kbin-2+ng,ng)+1\n ibinp1=mod(ibin+ng,ng)+1\n jbinp1=mod(jbin+ng,ng)+1\n kbinp1=mod(kbin+ng,ng)+1\n !$omp atomic\n den8(ibinm1,jbinm1,kbinm1)=den8(ibinm1,jbinm1,kbinm1)+hxm1*hym1*hzm1\n !$omp atomic\n den8(ibin ,jbinm1,kbinm1)=den8(ibin ,jbinm1,kbinm1)+hx0 *hym1*hzm1\n !$omp atomic\n den8(ibinp1,jbinm1,kbinm1)=den8(ibinp1,jbinm1,kbinm1)+hxp1*hym1*hzm1\n !$omp atomic\n den8(ibinm1,jbin ,kbinm1)=den8(ibinm1,jbin ,kbinm1)+hxm1*hy0 *hzm1\n !$omp atomic\n den8(ibin ,jbin ,kbinm1)=den8(ibin ,jbin ,kbinm1)+hx0 *hy0 *hzm1\n !$omp atomic\n den8(ibinp1,jbin ,kbinm1)=den8(ibinp1,jbin ,kbinm1)+hxp1*hy0 *hzm1\n !$omp atomic\n den8(ibinm1,jbinp1,kbinm1)=den8(ibinm1,jbinp1,kbinm1)+hxm1*hyp1*hzm1\n !$omp atomic\n den8(ibin ,jbinp1,kbinm1)=den8(ibin ,jbinp1,kbinm1)+hx0 *hyp1*hzm1\n !$omp atomic\n den8(ibinp1,jbinp1,kbinm1)=den8(ibinp1,jbinp1,kbinm1)+hxp1*hyp1*hzm1\n !$omp atomic\n den8(ibinm1,jbinm1,kbin )=den8(ibinm1,jbinm1,kbin )+hxm1*hym1*hz0\n !$omp atomic\n den8(ibin ,jbinm1,kbin )=den8(ibin ,jbinm1,kbin )+hx0 *hym1*hz0\n !$omp atomic\n den8(ibinp1,jbinm1,kbin )=den8(ibinp1,jbinm1,kbin )+hxp1*hym1*hz0\n !$omp atomic\n den8(ibinm1,jbin ,kbin )=den8(ibinm1,jbin ,kbin )+hxm1*hy0 *hz0\n !$omp atomic\n den8(ibin ,jbin ,kbin )=den8(ibin ,jbin ,kbin )+hx0 *hy0 *hz0\n !$omp atomic\n den8(ibinp1,jbin ,kbin )=den8(ibinp1,jbin ,kbin )+hxp1*hy0 *hz0\n !$omp atomic\n den8(ibinm1,jbinp1,kbin )=den8(ibinm1,jbinp1,kbin )+hxm1*hyp1*hz0\n !$omp atomic\n den8(ibin ,jbinp1,kbin )=den8(ibin ,jbinp1,kbin )+hx0 *hyp1*hz0\n !$omp atomic\n den8(ibinp1,jbinp1,kbin )=den8(ibinp1,jbinp1,kbin )+hxp1*hyp1*hz0\n !$omp atomic\n den8(ibinm1,jbinm1,kbinp1)=den8(ibinm1,jbinm1,kbinp1)+hxm1*hym1*hzp1\n !$omp atomic\n den8(ibin ,jbinm1,kbinp1)=den8(ibin ,jbinm1,kbinp1)+hx0 *hym1*hzp1\n !$omp atomic\n den8(ibinp1,jbinm1,kbinp1)=den8(ibinp1,jbinm1,kbinp1)+hxp1*hym1*hzp1\n !$omp atomic\n den8(ibinm1,jbin ,kbinp1)=den8(ibinm1,jbin ,kbinp1)+hxm1*hy0 *hzp1\n !$omp atomic\n den8(ibin ,jbin ,kbinp1)=den8(ibin ,jbin ,kbinp1)+hx0 *hy0 *hzp1\n !$omp atomic\n den8(ibinp1,jbin ,kbinp1)=den8(ibinp1,jbin ,kbinp1)+hxp1*hy0 *hzp1\n !$omp atomic\n den8(ibinm1,jbinp1,kbinp1)=den8(ibinm1,jbinp1,kbinp1)+hxm1*hyp1*hzp1\n !$omp atomic\n den8(ibin ,jbinp1,kbinp1)=den8(ibin ,jbinp1,kbinp1)+hx0 *hyp1*hzp1\n !$omp atomic\n den8(ibinp1,jbinp1,kbinp1)=den8(ibinp1,jbinp1,kbinp1)+hxp1*hyp1*hzp1\n enddo\n !$omp end parallel do\nelse\n write(*,*) 'ERROR: mass assignment not specified'\nendif\nwrite(*,*) 'statistics:'\ntmp1=0.d0\ntmp2=0.d0\n!$omp parallel do default(shared) reduction(+:tmp1,tmp2) \ndo k=1,ng\n den8(:,:,k)=den8(:,:,k)/np*coarse**3*real(ng)**3-1.d0\n tmp1=tmp1+sum(den8(:,:,k))/real(ng)**3\n tmp2=tmp2+sum(den8(:,:,k)**2)/real(ng)**3\nenddo\n!$omp end parallel do\ntmp2=sqrt(tmp2)\nwrite(*,*) 'mean:',real(tmp1)\nwrite(*,*) 'sigma:',real(tmp2)\nendsubroutine massassigndown\n\n\nsubroutine massassign_double(np,pos,ng,den8,cmd)\nuse omp_lib\nimplicit none\ninteger(4)::np\nreal(8)::pos(3,np)\ninteger(4)::ng\nreal(8)::den8(ng,ng,ng)\ninteger(4)::cmd\ninteger(4)::ibin,jbin,kbin,ibinm1,jbinm1,kbinm1,ibinp1,jbinp1,kbinp1\nreal(8)::hx,hy,hz,hx0,hy0,hz0,hxm1,hym1,hzm1,hxp1,hyp1,hzp1\ninteger(4)::pid\nreal(8)::tmp1,tmp2\ninteger(4)::i,j,k\n!$omp parallel do default(shared)\ndo k=1,ng\n den8(:,:,k)=0.d0\nenddo\n!$omp end parallel do\nwrite(*,*) 'begin mass assignment by method',cmd\nif (cmd.eq.1) then\n ! NGP\n !$omp parallel do default(private) shared(np,pos,den8) schedule(static)\n do pid=1,np\n ibin=ceiling(pos(1,pid))\n jbin=ceiling(pos(2,pid))\n kbin=ceiling(pos(3,pid))\n !$omp atomic\n den8(ibin,jbin,kbin)=den8(ibin,jbin,kbin)+1.d0\n enddo\n !$omp end parallel do\nelseif (cmd.eq.2) then\n ! CIC\n !$omp parallel do default(private) shared(np,ng,pos,den8) schedule(static)\n do pid=1,np\n ibin=ceiling(pos(1,pid))\n jbin=ceiling(pos(2,pid))\n kbin=ceiling(pos(3,pid))\n hx=pos(1,pid)-ibin+0.5\n hy=pos(2,pid)-jbin+0.5\n hz=pos(3,pid)-kbin+0.5\n hx0=1.-abs(hx)\n if (hx.gt.0.) then\n hxp1=hx\n hxm1=0.\n else\n hxp1=0.\n hxm1=-hx\n endif\n hy0=1.-abs(hy)\n if (hy.gt.0.) then\n hyp1=hy\n hym1=0.\n else\n hyp1=0.\n hym1=-hy\n endif\n hz0=1.-abs(hz)\n if (hz.gt.0.) then\n hzp1=hz\n hzm1=0.\n else\n hzp1=0.\n hzm1=-hz\n endif\n ibinm1=mod(ibin-2+ng,ng)+1\n jbinm1=mod(jbin-2+ng,ng)+1\n kbinm1=mod(kbin-2+ng,ng)+1\n ibinp1=mod(ibin+ng,ng)+1\n jbinp1=mod(jbin+ng,ng)+1\n kbinp1=mod(kbin+ng,ng)+1\n !$omp atomic\n den8(ibinm1,jbinm1,kbinm1)=den8(ibinm1,jbinm1,kbinm1)+hxm1*hym1*hzm1\n !$omp atomic\n den8(ibin ,jbinm1,kbinm1)=den8(ibin ,jbinm1,kbinm1)+hx0 *hym1*hzm1\n !$omp atomic\n den8(ibinp1,jbinm1,kbinm1)=den8(ibinp1,jbinm1,kbinm1)+hxp1*hym1*hzm1\n !$omp atomic\n den8(ibinm1,jbin ,kbinm1)=den8(ibinm1,jbin ,kbinm1)+hxm1*hy0 *hzm1\n !$omp atomic\n den8(ibin ,jbin ,kbinm1)=den8(ibin ,jbin ,kbinm1)+hx0 *hy0 *hzm1\n !$omp atomic\n den8(ibinp1,jbin ,kbinm1)=den8(ibinp1,jbin ,kbinm1)+hxp1*hy0 *hzm1\n !$omp atomic\n den8(ibinm1,jbinp1,kbinm1)=den8(ibinm1,jbinp1,kbinm1)+hxm1*hyp1*hzm1\n !$omp atomic\n den8(ibin ,jbinp1,kbinm1)=den8(ibin ,jbinp1,kbinm1)+hx0 *hyp1*hzm1\n !$omp atomic\n den8(ibinp1,jbinp1,kbinm1)=den8(ibinp1,jbinp1,kbinm1)+hxp1*hyp1*hzm1\n !$omp atomic\n den8(ibinm1,jbinm1,kbin )=den8(ibinm1,jbinm1,kbin )+hxm1*hym1*hz0\n !$omp atomic\n den8(ibin ,jbinm1,kbin )=den8(ibin ,jbinm1,kbin )+hx0 *hym1*hz0\n !$omp atomic\n den8(ibinp1,jbinm1,kbin )=den8(ibinp1,jbinm1,kbin )+hxp1*hym1*hz0\n !$omp atomic\n den8(ibinm1,jbin ,kbin )=den8(ibinm1,jbin ,kbin )+hxm1*hy0 *hz0\n !$omp atomic\n den8(ibin ,jbin ,kbin )=den8(ibin ,jbin ,kbin )+hx0 *hy0 *hz0\n !$omp atomic\n den8(ibinp1,jbin ,kbin )=den8(ibinp1,jbin ,kbin )+hxp1*hy0 *hz0\n !$omp atomic\n den8(ibinm1,jbinp1,kbin )=den8(ibinm1,jbinp1,kbin )+hxm1*hyp1*hz0\n !$omp atomic\n den8(ibin ,jbinp1,kbin )=den8(ibin ,jbinp1,kbin )+hx0 *hyp1*hz0\n !$omp atomic\n den8(ibinp1,jbinp1,kbin )=den8(ibinp1,jbinp1,kbin )+hxp1*hyp1*hz0\n !$omp atomic\n den8(ibinm1,jbinm1,kbinp1)=den8(ibinm1,jbinm1,kbinp1)+hxm1*hym1*hzp1\n !$omp atomic\n den8(ibin ,jbinm1,kbinp1)=den8(ibin ,jbinm1,kbinp1)+hx0 *hym1*hzp1\n !$omp atomic\n den8(ibinp1,jbinm1,kbinp1)=den8(ibinp1,jbinm1,kbinp1)+hxp1*hym1*hzp1\n !$omp atomic\n den8(ibinm1,jbin ,kbinp1)=den8(ibinm1,jbin ,kbinp1)+hxm1*hy0 *hzp1\n !$omp atomic\n den8(ibin ,jbin ,kbinp1)=den8(ibin ,jbin ,kbinp1)+hx0 *hy0 *hzp1\n !$omp atomic\n den8(ibinp1,jbin ,kbinp1)=den8(ibinp1,jbin ,kbinp1)+hxp1*hy0 *hzp1\n !$omp atomic\n den8(ibinm1,jbinp1,kbinp1)=den8(ibinm1,jbinp1,kbinp1)+hxm1*hyp1*hzp1\n !$omp atomic\n den8(ibin ,jbinp1,kbinp1)=den8(ibin ,jbinp1,kbinp1)+hx0 *hyp1*hzp1\n !$omp atomic\n den8(ibinp1,jbinp1,kbinp1)=den8(ibinp1,jbinp1,kbinp1)+hxp1*hyp1*hzp1\n enddo\n !$omp end parallel do\nelseif (cmd.eq.3) then\n ! TSC\n !$omp parallel do default(private) shared(np,ng,pos,den8) schedule(static)\n do pid=1,np\n ibin=ceiling(pos(1,pid))\n jbin=ceiling(pos(2,pid))\n kbin=ceiling(pos(3,pid))\n hx=pos(1,pid)-ibin+0.5\n hy=pos(2,pid)-jbin+0.5\n hz=pos(3,pid)-kbin+0.5\n hx0=0.75-hx**2\n hxp1=0.5*(0.5+hx)**2\n hxm1=0.5*(0.5-hx)**2\n hy0=0.75-hy**2\n hyp1=0.5*(0.5+hy)**2\n hym1=0.5*(0.5-hy)**2\n hz0=0.75-hz**2\n hzp1=0.5*(0.5+hz)**2\n hzm1=0.5*(0.5-hz)**2\n ibinm1=mod(ibin-2+ng,ng)+1\n jbinm1=mod(jbin-2+ng,ng)+1\n kbinm1=mod(kbin-2+ng,ng)+1\n ibinp1=mod(ibin+ng,ng)+1\n jbinp1=mod(jbin+ng,ng)+1\n kbinp1=mod(kbin+ng,ng)+1\n !$omp atomic\n den8(ibinm1,jbinm1,kbinm1)=den8(ibinm1,jbinm1,kbinm1)+hxm1*hym1*hzm1\n !$omp atomic\n den8(ibin ,jbinm1,kbinm1)=den8(ibin ,jbinm1,kbinm1)+hx0 *hym1*hzm1\n !$omp atomic\n den8(ibinp1,jbinm1,kbinm1)=den8(ibinp1,jbinm1,kbinm1)+hxp1*hym1*hzm1\n !$omp atomic\n den8(ibinm1,jbin ,kbinm1)=den8(ibinm1,jbin ,kbinm1)+hxm1*hy0 *hzm1\n !$omp atomic\n den8(ibin ,jbin ,kbinm1)=den8(ibin ,jbin ,kbinm1)+hx0 *hy0 *hzm1\n !$omp atomic\n den8(ibinp1,jbin ,kbinm1)=den8(ibinp1,jbin ,kbinm1)+hxp1*hy0 *hzm1\n !$omp atomic\n den8(ibinm1,jbinp1,kbinm1)=den8(ibinm1,jbinp1,kbinm1)+hxm1*hyp1*hzm1\n !$omp atomic\n den8(ibin ,jbinp1,kbinm1)=den8(ibin ,jbinp1,kbinm1)+hx0 *hyp1*hzm1\n !$omp atomic\n den8(ibinp1,jbinp1,kbinm1)=den8(ibinp1,jbinp1,kbinm1)+hxp1*hyp1*hzm1\n !$omp atomic\n den8(ibinm1,jbinm1,kbin )=den8(ibinm1,jbinm1,kbin )+hxm1*hym1*hz0\n !$omp atomic\n den8(ibin ,jbinm1,kbin )=den8(ibin ,jbinm1,kbin )+hx0 *hym1*hz0\n !$omp atomic\n den8(ibinp1,jbinm1,kbin )=den8(ibinp1,jbinm1,kbin )+hxp1*hym1*hz0\n !$omp atomic\n den8(ibinm1,jbin ,kbin )=den8(ibinm1,jbin ,kbin )+hxm1*hy0 *hz0\n !$omp atomic\n den8(ibin ,jbin ,kbin )=den8(ibin ,jbin ,kbin )+hx0 *hy0 *hz0\n !$omp atomic\n den8(ibinp1,jbin ,kbin )=den8(ibinp1,jbin ,kbin )+hxp1*hy0 *hz0\n !$omp atomic\n den8(ibinm1,jbinp1,kbin )=den8(ibinm1,jbinp1,kbin )+hxm1*hyp1*hz0\n !$omp atomic\n den8(ibin ,jbinp1,kbin )=den8(ibin ,jbinp1,kbin )+hx0 *hyp1*hz0\n !$omp atomic\n den8(ibinp1,jbinp1,kbin )=den8(ibinp1,jbinp1,kbin )+hxp1*hyp1*hz0\n !$omp atomic\n den8(ibinm1,jbinm1,kbinp1)=den8(ibinm1,jbinm1,kbinp1)+hxm1*hym1*hzp1\n !$omp atomic\n den8(ibin ,jbinm1,kbinp1)=den8(ibin ,jbinm1,kbinp1)+hx0 *hym1*hzp1\n !$omp atomic\n den8(ibinp1,jbinm1,kbinp1)=den8(ibinp1,jbinm1,kbinp1)+hxp1*hym1*hzp1\n !$omp atomic\n den8(ibinm1,jbin ,kbinp1)=den8(ibinm1,jbin ,kbinp1)+hxm1*hy0 *hzp1\n !$omp atomic\n den8(ibin ,jbin ,kbinp1)=den8(ibin ,jbin ,kbinp1)+hx0 *hy0 *hzp1\n !$omp atomic\n den8(ibinp1,jbin ,kbinp1)=den8(ibinp1,jbin ,kbinp1)+hxp1*hy0 *hzp1\n !$omp atomic\n den8(ibinm1,jbinp1,kbinp1)=den8(ibinm1,jbinp1,kbinp1)+hxm1*hyp1*hzp1\n !$omp atomic\n den8(ibin ,jbinp1,kbinp1)=den8(ibin ,jbinp1,kbinp1)+hx0 *hyp1*hzp1\n !$omp atomic\n den8(ibinp1,jbinp1,kbinp1)=den8(ibinp1,jbinp1,kbinp1)+hxp1*hyp1*hzp1\n enddo\n !$omp end parallel do\nelse\n write(*,*) 'ERROR: mass assignment not specified'\nendif\nwrite(*,*) 'statistics:'\ntmp1=0.d0\ntmp2=0.d0\n!$omp parallel do default(shared) reduction(+:tmp1,tmp2) \ndo k=1,ng\n den8(:,:,k)=den8(:,:,k)/np*real(ng)**3-1.d0\n tmp1=tmp1+sum(den8(:,:,k))/real(ng)**3\n tmp2=tmp2+sum(den8(:,:,k)**2)/real(ng)**3\nenddo\n!$omp end parallel do\ntmp2=sqrt(tmp2)\nwrite(*,*) 'mean:',real(tmp1)\nwrite(*,*) 'sigma:',real(tmp2)\nendsubroutine massassign_double\n\n\n\n\nendmodule p2grid\n", "meta": {"hexsha": "42564b2f467a0173c27e0a597ebc0b4f840d06ce", "size": 23758, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "p2grid.f90", "max_stars_repo_name": "ColdThunder/FFTcf", "max_stars_repo_head_hexsha": "3dbbfd3ed1d53e3e3cf4001a506531816bc8b261", "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": "p2grid.f90", "max_issues_repo_name": "ColdThunder/FFTcf", "max_issues_repo_head_hexsha": "3dbbfd3ed1d53e3e3cf4001a506531816bc8b261", "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": "p2grid.f90", "max_forks_repo_name": "ColdThunder/FFTcf", "max_forks_repo_head_hexsha": "3dbbfd3ed1d53e3e3cf4001a506531816bc8b261", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.9058171745, "max_line_length": 86, "alphanum_fraction": 0.6472346157, "num_tokens": 11549, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505453836383, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6906860079594046}} {"text": "!\n subroutine differentiate(x,y,z,n,f,fx,fy,fz)\n!\n! Computes derivatives of linear functions specified at tetrahedron vertices\n!\n! Input parameters:\n! Formal: x(4),y(4),z(4) - coordinates (x,y,z) of 4 vertices\n! n - number of functions to differentiate\n! f(4,n) - values of functions at the vertices\n! Output parameters:\n! Formal: fx(n),fy(n),fz(n) - deivatives of functions over x,y and z, resp.\n!\n! Called routines: dgesv - from the Lapack library\n!\n implicit none\n!\n integer :: n\n double precision, dimension(n) :: fx,fy,fz\n double precision, dimension(4) :: x,y,z\n double precision, dimension(4,n) :: f\n!\n integer :: ierr\n integer, dimension(3) :: ipiv\n double precision, dimension(3,3) :: a,b\n double precision, dimension(:,:), allocatable :: df\n!\n allocate(df(3,n))\n!\n df(1,:)=f(2,:)-f(1,:)\n df(2,:)=f(3,:)-f(1,:)\n df(3,:)=f(4,:)-f(1,:)\n!\n a(1,1)=x(2)-x(1)\n a(1,2)=x(3)-x(1)\n a(1,3)=x(4)-x(1)\n a(2,1)=y(2)-y(1)\n a(2,2)=y(3)-y(1)\n a(2,3)=y(4)-y(1)\n a(3,1)=z(2)-z(1)\n a(3,2)=z(3)-z(1)\n a(3,3)=z(4)-z(1)\n!\n b=0.d0\n b(1,1)=1.d0\n b(2,2)=1.d0\n b(3,3)=1.d0\n!\n call dgesv(3,3,a,3,ipiv,b,3,ierr)\n!\n df=matmul(transpose(b),df)\n!\n fx=df(1,:)\n fy=df(2,:)\n fz=df(3,:)\n!\n deallocate(df)\n!\n end subroutine differentiate\n", "meta": {"hexsha": "a2cb7c0025b0a6503486b0c641ec7f45e944f73d", "size": 1409, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "SRC/differentiate.f90", "max_stars_repo_name": "Forsti5/GORILLA", "max_stars_repo_head_hexsha": "a28576e625a55b2c3adacf0dbb6806294f888e6f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-08-22T02:43:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-22T02:43:24.000Z", "max_issues_repo_path": "SRC/differentiate.f90", "max_issues_repo_name": "Forsti5/GORILLA", "max_issues_repo_head_hexsha": "a28576e625a55b2c3adacf0dbb6806294f888e6f", "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/differentiate.f90", "max_forks_repo_name": "Forsti5/GORILLA", "max_forks_repo_head_hexsha": "a28576e625a55b2c3adacf0dbb6806294f888e6f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2021-03-04T08:07:13.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-03T11:21:31.000Z", "avg_line_length": 23.8813559322, "max_line_length": 85, "alphanum_fraction": 0.5251951739, "num_tokens": 541, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422645, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6906860040340492}} {"text": "program tarefa2\n \n !Recebe os valores dos vetores\n print *, 'Digite V1: (x1, y1, z1)'\n read(*,*) x1, y1, z1\n print *, 'Digite V2: (x2, y2, z2)'\n read(*,*) x2, y2, z2\n \n !Calcula o m\u00f3dulo do vetor e divide por 2, para obter a \u00e1rea do tri\u00e2ngulo\n area = (y1*z2 - y2*z1)**2 + (x2*z1 - x1*z2)**2 + (x1*y2 - x2*y1)**2\n area = sqrt(area)/2.d0\n !imprime a \u00e1rea\n print '(A, F8.5)', \"\u00c1rea tri\u00e2ngulo: \", area\n\nend program tarefa2\n", "meta": {"hexsha": "a4b606896c38af7c2b8652e0d095a5f39faefb19", "size": 455, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "projeto-1/tarefa-2/tarefa-2-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-2/tarefa-2-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-2/tarefa-2-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": 28.4375, "max_line_length": 77, "alphanum_fraction": 0.5604395604, "num_tokens": 193, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008906, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6906859952402324}} {"text": "subroutine clawpack46_setaux(mbc,mx,my,mz, & \n xlower,ylower,zlower, dx,dy,dz, maux,aux)\n implicit none\n\n integer :: mbc, mx, my, mz, maux\n double precision :: xlower, ylower, zlower, dx, dy, dz\n double precision :: aux(1-mbc:mx+mbc,1-mbc:my+mbc,1-mbc:mz+mbc,maux)\n\n integer :: i, j, k\n double precision :: xc(1-mbc:mx+mbc)\n double precision :: yc(1-mbc:my+mbc)\n double precision :: xll, yll, psi\n\n do i = 1-mbc,mx+mbc\n xc(i) = xlower + (i-0.5d0)*dx\n enddo\n\n do j = 1-mbc,my+mbc\n yc(j) = ylower + (j-0.5d0)*dy\n end do\n\n\n do k = 1-mbc,mz+mbc\n do j = 1-mbc,my+mbc\n do i = 1-mbc,mx+mbc\n xll = xc(i)\n yll = yc(j)\n !! # difference stream function psi to get normal velocities:\n aux(i,j,k,1) = (psi(xll, yll+dy) - psi(xll,yll)) / dy\n aux(i,j,k,2) = -(psi(xll+dx, yll) - psi(xll,yll)) / dx\n aux(i,j,k,3) = 0\n enddo\n enddo\n end do\n\n return\nend subroutine clawpack46_setaux\n", "meta": {"hexsha": "1f63def2f4f2fff826929c518ee497ba863067b8", "size": 1067, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "applications/clawpack/advection/3d/filament/user_4.6/setaux.f90", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "applications/clawpack/advection/3d/filament/user_4.6/setaux.f90", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-08-02T09:52:43.000Z", "max_issues_repo_issues_event_max_datetime": "2017-08-02T14:16:23.000Z", "max_forks_repo_path": "applications/clawpack/advection/3d/filament/user_4.6/setaux.f90", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "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": 28.0789473684, "max_line_length": 77, "alphanum_fraction": 0.5173383318, "num_tokens": 403, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.7634837635542925, "lm_q1q2_score": 0.6906859913148766}} {"text": "c DRSLESUM\nc>> 1995-05-28 DRSLESUM Krogh Changes to use M77CON\nc>> 1994-08-09 DRSLESUM WVS Set up for CHGTYP\nc>> 1994-07-14 DRSLESUM CLL\nc>> 1992-04-29 DRSLESUM CAO Replaced '1' in format.\nc>> 1991-11-19 DRSLESUM CLL\nc>> 1987-12-09 DRSLESUM Lawson Initial Code.\nc--S replaces \"?\": ?LESUM, DR?LESUM\nc\nc Demonstration driver for evaluation of a Legendre series.\nc ------------------------------------------------------------------\n integer j\n real x,a(0:5),y,w,z\n data a/0.07e0, 0.27e0, 0.20e0, 0.28e0, 0.08e0, 0.08e0/\nc ------------------------------------------------------------------\n print '(1x,3x,a1,14x,a1,17x,a1/)','x','y','z'\n do 20 j = -10,10,2\n x = real(j) /10.e0\n call slesum (x,5,a,y)\n w = 0.35e0 * (x**4) + 0.63e0 * (x**5)\n z = y - w\n print '(1x,f5.2,5x,g15.7,g15.2)',x,y,z\n 20 continue\n end\n", "meta": {"hexsha": "709b1624efd9d99a14b84c8cf2919aac0dcf7ce6", "size": 902, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drslesum.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drslesum.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drslesum.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 36.08, "max_line_length": 72, "alphanum_fraction": 0.4822616408, "num_tokens": 357, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008906, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6906859903717711}} {"text": "program singintquad\n implicit none\n integer, parameter :: dp=8\n real(dp) :: lowlim, uplim\n integer :: steps\n complex(dp) :: integral\n\n lowlim = 0.0_dp\n uplim = 1.0_dp\n steps=200 !keep steps so that interval width ~ 1.0e-2 to 1.0e-3\n\n\n CALL integ13(nume,deno,lowlim,uplim,steps,integral)\n\n write(*,'(A,2ES10.2e2,\"i\")') \"The integral value is\", integral\n\n contains\n\n subroutine integ13(num,den,q,p,N,integral)\n !!!--------------------------\n !This subroutine performs integration by equidistant intervals for 'nearly' singular functions using quadratic approximations.\n ! func -> function to integrate, q-> lower bound, p-> upper bound, N -> number of intervals (including q and p)\n ! OUTPUT => integral\n ! Use num, den to declare numerator, denominator respectively of the integral A(y)/B(y)\n !!!---------------------------\n real(dp), intent(in) :: q,p\n integer, intent(in) :: N\n real(dp) :: h,x\n COMPLEX(dp) :: num,den, tp(3), int, a,b,c,d,e,f\n COMPLEX(dp), intent(out) :: integral\n integer :: i,k,t\n h=(p-q)/N ! h is the interval width.\n x=(q+h/1000) ! x tracks the interval. h/1000 extra factor is added to skew the program a bit from the sing.\n integral=0.\n k =0;t=0 ! dummy indices to keep track of which approximation gets triggered\n write(*,'(A,F7.3, \" to\", F7.3)') \"Integral limits\", q,p\n write(*,'(A,ES8.2e2,/,A)') 'Interval width = ', h, repeat(\"-\",10)\n \n ! Main LOOP below\n do i=0,N-1\n !Variables named same as the writeup\n int=0.\n a =(2.) *(den(x+h)-2.*den(x+h/2) +den(x))\n b = -den(x+h) + 4* den(x+h/2) -3*den(x)\n c = den(x)\n d =(2.) *(num(x+h)-2.*num(x+h/2) + num(x))\n e = -num(x+h) - 3.*num(x) + 4.* num(x+h/2)\n f = num(x)\n\n if (abs(a) .le. 1.0e-6) then\n ! if the quad coeff. is too low then switch to linear\n b = den(x+h)-den(x)\n c = den(x)\n if (abs(b) .le. 1.0e-3) then\n \t! if linear approx also requires log expansion, upto 3rd order.\n int=h/(2*c) * (2*d/3 +e + 2*f-(2*b*e+b*f)/(3*c)+2*b**2 *f/(3*c**2))\n ! print*, 'linearapprox', int, x\n k= k+1\n else\n ! int = h/b *( d/2 +e+ d*c/b + (d*c**2 / b**2 -e*c/b + f) * log(1+b/c) ) ! old one has some typo\n int = h/(2*b**3) * (b*(-2*c*d+b*(d+2*e)) +2*( c**2 *d - b*c*e+b**2 *f)*log((1+b/c)) )\n t=t+1\n ! print*, 'linear', int, x\n endif\n else\n tp(1)= ( -b + sqrt(b**2 - 4*a*c) )/(2*a) !x1\n tp(2)= ( -b - sqrt(b**2 - 4*a*c) )/(2*a) !x2\n if ((real(tp(1)) < q .and. real(tp(1)) > p) .or. (real(tp(2)) < q .and. real(tp(2)) > p)) then\n print*, \"Quadratic approx not possible decrease interval to force linear\"\n EXIT\n endif\n ! int = h/a * ( d + log(1-1/tp(2)) *(d*(-b)/a +e+(d*tp(1)**2+e*tp(1)+f)/(tp(2)-tp(1))) &\n ! - log(1-1/tp(1)) * (d*tp(1)**2+e*tp(1)+f)/(tp(2)-tp(1)) )\n ! print*, 'quad', int, x\n tp(1) = sqrt(4*a*c - b**2)\n int = h*((4*a**2*atan((b+2*a)/tp(1))-4*a**2*atan(b/tp(1)))*f+(-b*tp(1)* &\n log(abs(c+b+a))+b*tp(1)*log(abs(c))+(2*b**2-4*a*c)*atan((b+2*a)/tp(1))+(4*a*c-2*b**2)*&\n atan(b/tp(1))+2*a*tp(1))*d+e*a*tp(1)*log(abs(c+b+a))-e*a*tp(1)*&\n log(abs(c))-2*e*a*b*atan((b+2*a)/tp(1))+2*e*a*b*atan(b/tp(1)))/(2*a**2*tp(1))\n endif\n\n integral = int+integral\n x=x+h\n end do\n write(*,'(A,I5,\"/\",I5)') \"# log expansions in linear:\", k,N\n write(*,'(A,I5,\"/\",I5)') \"# total linear approximations:\", k+t,N\n write(*,'(A,I5,\"/\",I5,/,A)') \"# total quadratic approximations:\", N-k-t,N, repeat(\"-\",10)\n\n end subroutine\n\nfunction nume(x)\n ! this is A(y) in integral(A(y)/B(y))\n implicit none\n COMPLEX(dp) :: nume,y\n real(dp) :: x\n y= complex(x,0.)\n ! nume= complex(abs(x),0.)\n ! nume = y-sqrt(y**2-1)\n !nume = sqrt(1-y**2)\n nume=1\n\n return\nend function nume\n\nfunction deno(x)\n ! this is B(y) in integral(A(y)/B(y))\n implicit none\n COMPLEX(dp) :: deno,y\n real(dp) :: x\n y = complex(x,0)\n ! deno = complex(0.9-x,1.0e-10)\n ! deno = sqrt(y**2 -1) + complex(0.,1.0e-10)\n !deno = 1-y + complex(0.,1.0e-10)\n deno = y**2\n\nend function deno\n\n\nend program singintquad\n", "meta": {"hexsha": "f6d4ca7e4ad5bca010369c198ce637f92b239220", "size": 4892, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Singint_Quadratic.f90", "max_stars_repo_name": "gauravag99/singularintegral", "max_stars_repo_head_hexsha": "e416d123c7a30097691a70c0acc4a44667d5479b", "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": "Singint_Quadratic.f90", "max_issues_repo_name": "gauravag99/singularintegral", "max_issues_repo_head_hexsha": "e416d123c7a30097691a70c0acc4a44667d5479b", "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": "Singint_Quadratic.f90", "max_forks_repo_name": "gauravag99/singularintegral", "max_forks_repo_head_hexsha": "e416d123c7a30097691a70c0acc4a44667d5479b", "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": 40.7666666667, "max_line_length": 134, "alphanum_fraction": 0.4480784955, "num_tokens": 1596, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009596336302, "lm_q2_score": 0.7549149978955811, "lm_q1q2_score": 0.6906724560164871}} {"text": ": fib 00; dup 2 0) THEN\n ! For a stencil of one point, the derivative is zero\n\tStencil = zero\n\tStencil(alpha+1) = zero\n\tDiffStencils(1,:) = Stencil\nELSE\n!\tALLOCATE( idx(rank) )\n\tDO i=-alpha,alpha,1\n\t\tidx(i+alpha+1) = i\n\tEND DO\n\tDO i = 1 , alpha\n\t\tDiff = alpha-i+1\n\t\t! Expansion point where the approximation is to be defined\n\t\tx0 = x(i,1) ! FIXME: y-index fixed\n\n\t\t! Determine local finite difference stencil coefficients\n\t\tCALL weights(x0,x(i+idx+Diff,1),rank-1,rank-1,order,c) ! FIXME: y-index fixed\n\t\tStencil = c(1:rank,order+1)\n\t\tDiffStencils(i,:) = Stencil\n\tEND DO\n\tDO i = alpha+1 , Nx-alpha\n\t\t! Expansion point where the approximation is to be defined\n\t\tx0 = x(i,1) ! FIXME: y-index fixed\n\n\t\t! Determine local finite difference stencil coefficients\n\t\t! FIXME: put his outside loop if we do not need flexible grids (e.g. in the case of transformation to an equi-distant grid)\n\t\tCALL weights(x0,x(i+idx,1),rank-1,rank-1,order,c) ! FIXME: y-index fixed\n\t\tStencil = c(1:rank,order+1)\n\t\tDiffStencils(i,:) = Stencil\n\tEND DO\n\tDO i = Nx-alpha+1 , Nx\n\t\tDiff = (Nx-alpha)-i\n\t\t! Expansion point where the approximation is to be defined\n\t\tx0 = x(i,1) ! FIXME: y-index fixed\n\n\t\t! Determine local finite difference stencil coefficients\n\t\tCALL weights(x0,x(i+idx+Diff,1),rank-1,rank-1,order,c) ! FIXME: y-index fixed\n\t\tStencil = c(1:rank,order+1)\n\t\tDiffStencils(i,:) = Stencil\n\tEND DO\nENDIF\nDEALLOCATE(Stencil,tmpStencil,c)\n\nEND SUBROUTINE BuildStencilsGridX\n", "meta": {"hexsha": "c15bc796576f2365cd39bca38b8c266c864f55d1", "size": 2261, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/initialization/BuildStencilsGridX.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/initialization/BuildStencilsGridX.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/initialization/BuildStencilsGridX.f90", "max_forks_repo_name": "apengsigkarup/OceanWave3D", "max_forks_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2015-10-01T12:17:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-02T16:23:37.000Z", "avg_line_length": 33.7462686567, "max_line_length": 125, "alphanum_fraction": 0.6771340115, "num_tokens": 765, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278540866547, "lm_q2_score": 0.7826624789529376, "lm_q1q2_score": 0.6906431717765823}} {"text": "*DECK FC\n SUBROUTINE FC (NDATA, XDATA, YDATA, SDDATA, NORD, NBKPT, BKPT,\n + NCONST, XCONST, YCONST, NDERIV, MODE, COEFF, W, IW)\nC***BEGIN PROLOGUE FC\nC***PURPOSE Fit a piecewise polynomial curve to discrete data.\nC The piecewise polynomials are represented as B-splines.\nC The fitting is done in a weighted least squares sense.\nC Equality and inequality constraints can be imposed on the\nC fitted curve.\nC***LIBRARY SLATEC\nC***CATEGORY K1A1A1, K1A2A, L8A3\nC***TYPE SINGLE PRECISION (FC-S, DFC-D)\nC***KEYWORDS B-SPLINE, CONSTRAINED LEAST SQUARES, CURVE FITTING,\nC WEIGHTED LEAST SQUARES\nC***AUTHOR Hanson, R. J., (SNLA)\nC***DESCRIPTION\nC\nC This subprogram fits a piecewise polynomial curve\nC to discrete data. The piecewise polynomials are\nC represented as B-splines.\nC The fitting is done in a weighted least squares sense.\nC Equality and inequality constraints can be imposed on the\nC fitted curve.\nC\nC For a description of the B-splines and usage instructions to\nC evaluate them, see\nC\nC C. W. de Boor, Package for Calculating with B-Splines.\nC SIAM J. Numer. Anal., p. 441, (June, 1977).\nC\nC For further documentation and discussion of constrained\nC curve fitting using B-splines, see\nC\nC R. J. Hanson, Constrained Least Squares Curve Fitting\nC to Discrete Data Using B-Splines, a User's\nC Guide. Sandia Labs. Tech. Rept. SAND-78-1291,\nC December, (1978).\nC\nC Input..\nC NDATA,XDATA(*),\nC YDATA(*),\nC SDDATA(*)\nC The NDATA discrete (X,Y) pairs and the Y value\nC standard deviation or uncertainty, SD, are in\nC the respective arrays XDATA(*), YDATA(*), and\nC SDDATA(*). No sorting of XDATA(*) is\nC required. Any non-negative value of NDATA is\nC allowed. A negative value of NDATA is an\nC error. A zero value for any entry of\nC SDDATA(*) will weight that data point as 1.\nC Otherwise the weight of that data point is\nC the reciprocal of this entry.\nC\nC NORD,NBKPT,\nC BKPT(*)\nC The NBKPT knots of the B-spline of order NORD\nC are in the array BKPT(*). Normally the\nC problem data interval will be included between\nC the limits BKPT(NORD) and BKPT(NBKPT-NORD+1).\nC The additional end knots BKPT(I),I=1,...,\nC NORD-1 and I=NBKPT-NORD+2,...,NBKPT, are\nC required to compute the functions used to fit\nC the data. No sorting of BKPT(*) is required.\nC Internal to FC( ) the extreme end knots may\nC be reduced and increased respectively to\nC accommodate any data values that are exterior\nC to the given knot values. The contents of\nC BKPT(*) is not changed.\nC\nC NORD must be in the range 1 .LE. NORD .LE. 20.\nC The value of NBKPT must satisfy the condition\nC NBKPT .GE. 2*NORD.\nC Other values are considered errors.\nC\nC (The order of the spline is one more than the\nC degree of the piecewise polynomial defined on\nC each interval. This is consistent with the\nC B-spline package convention. For example,\nC NORD=4 when we are using piecewise cubics.)\nC\nC NCONST,XCONST(*),\nC YCONST(*),NDERIV(*)\nC The number of conditions that constrain the\nC B-spline is NCONST. A constraint is specified\nC by an (X,Y) pair in the arrays XCONST(*) and\nC YCONST(*), and by the type of constraint and\nC derivative value encoded in the array\nC NDERIV(*). No sorting of XCONST(*) is\nC required. The value of NDERIV(*) is\nC determined as follows. Suppose the I-th\nC constraint applies to the J-th derivative\nC of the B-spline. (Any non-negative value of\nC J < NORD is permitted. In particular the\nC value J=0 refers to the B-spline itself.)\nC For this I-th constraint, set\nC XCONST(I)=X,\nC YCONST(I)=Y, and\nC NDERIV(I)=ITYPE+4*J, where\nC\nC ITYPE = 0, if (J-th deriv. at X) .LE. Y.\nC = 1, if (J-th deriv. at X) .GE. Y.\nC = 2, if (J-th deriv. at X) .EQ. Y.\nC = 3, if (J-th deriv. at X) .EQ.\nC (J-th deriv. at Y).\nC (A value of NDERIV(I)=-1 will cause this\nC constraint to be ignored. This subprogram\nC feature is often useful when temporarily\nC suppressing a constraint while still\nC retaining the source code of the calling\nC program.)\nC\nC MODE\nC An input flag that directs the least squares\nC solution method used by FC( ).\nC\nC The variance function, referred to below,\nC defines the square of the probable error of\nC the fitted curve at any point, XVAL.\nC This feature of FC( ) allows one to use the\nC square root of this variance function to\nC determine a probable error band around the\nC fitted curve.\nC\nC =1 a new problem. No variance function.\nC\nC =2 a new problem. Want variance function.\nC\nC =3 an old problem. No variance function.\nC\nC =4 an old problem. Want variance function.\nC\nC Any value of MODE other than 1-4 is an error.\nC\nC The user with a new problem can skip directly\nC to the description of the input parameters\nC IW(1), IW(2).\nC\nC If the user correctly specifies the new or old\nC problem status, the subprogram FC( ) will\nC perform more efficiently.\nC By an old problem it is meant that subprogram\nC FC( ) was last called with this same set of\nC knots, data points and weights.\nC\nC Another often useful deployment of this old\nC problem designation can occur when one has\nC previously obtained a Q-R orthogonal\nC decomposition of the matrix resulting from\nC B-spline fitting of data (without constraints)\nC at the breakpoints BKPT(I), I=1,...,NBKPT.\nC For example, this matrix could be the result\nC of sequential accumulation of the least\nC squares equations for a very large data set.\nC The user writes this code in a manner\nC convenient for the application. For the\nC discussion here let\nC\nC N=NBKPT-NORD, and K=N+3\nC\nC Let us assume that an equivalent least squares\nC system\nC\nC RC=D\nC\nC has been obtained. Here R is an N+1 by N\nC matrix and D is a vector with N+1 components.\nC The last row of R is zero. The matrix R is\nC upper triangular and banded. At most NORD of\nC the diagonals are nonzero.\nC The contents of R and D can be copied to the\nC working array W(*) as follows.\nC\nC The I-th diagonal of R, which has N-I+1\nC elements, is copied to W(*) starting at\nC\nC W((I-1)*K+1),\nC\nC for I=1,...,NORD.\nC The vector D is copied to W(*) starting at\nC\nC W(NORD*K+1)\nC\nC The input value used for NDATA is arbitrary\nC when an old problem is designated. Because\nC of the feature of FC( ) that checks the\nC working storage array lengths, a value not\nC exceeding NBKPT should be used. For example,\nC use NDATA=0.\nC\nC (The constraints or variance function request\nC can change in each call to FC( ).) A new\nC problem is anything other than an old problem.\nC\nC IW(1),IW(2)\nC The amounts of working storage actually\nC allocated for the working arrays W(*) and\nC IW(*). These quantities are compared with the\nC actual amounts of storage needed in FC( ).\nC Insufficient storage allocated for either\nC W(*) or IW(*) is an error. This feature was\nC included in FC( ) because misreading the\nC storage formulas for W(*) and IW(*) might very\nC well lead to subtle and hard-to-find\nC programming bugs.\nC\nC The length of W(*) must be at least\nC\nC NB=(NBKPT-NORD+3)*(NORD+1)+\nC 2*MAX(NDATA,NBKPT)+NBKPT+NORD**2\nC\nC Whenever possible the code uses banded matrix\nC processors BNDACC( ) and BNDSOL( ). These\nC are utilized if there are no constraints,\nC no variance function is required, and there\nC is sufficient data to uniquely determine the\nC B-spline coefficients. If the band processors\nC cannot be used to determine the solution,\nC then the constrained least squares code LSEI\nC is used. In this case the subprogram requires\nC an additional block of storage in W(*). For\nC the discussion here define the integers NEQCON\nC and NINCON respectively as the number of\nC equality (ITYPE=2,3) and inequality\nC (ITYPE=0,1) constraints imposed on the fitted\nC curve. Define\nC\nC L=NBKPT-NORD+1\nC\nC and note that\nC\nC NCONST=NEQCON+NINCON.\nC\nC When the subprogram FC( ) uses LSEI( ) the\nC length of the working array W(*) must be at\nC least\nC\nC LW=NB+(L+NCONST)*L+\nC 2*(NEQCON+L)+(NINCON+L)+(NINCON+2)*(L+6)\nC\nC The length of the array IW(*) must be at least\nC\nC IW1=NINCON+2*L\nC\nC in any case.\nC\nC Output..\nC MODE\nC An output flag that indicates the status\nC of the constrained curve fit.\nC\nC =-1 a usage error of FC( ) occurred. The\nC offending condition is noted with the\nC SLATEC library error processor, XERMSG.\nC In case the working arrays W(*) or IW(*)\nC are not long enough, the minimal\nC acceptable length is printed.\nC\nC = 0 successful constrained curve fit.\nC\nC = 1 the requested equality constraints\nC are contradictory.\nC\nC = 2 the requested inequality constraints\nC are contradictory.\nC\nC = 3 both equality and inequality constraints\nC are contradictory.\nC\nC COEFF(*)\nC If the output value of MODE=0 or 1, this array\nC contains the unknowns obtained from the least\nC squares fitting process. These N=NBKPT-NORD\nC parameters are the B-spline coefficients.\nC For MODE=1, the equality constraints are\nC contradictory. To make the fitting process\nC more robust, the equality constraints are\nC satisfied in a least squares sense. In this\nC case the array COEFF(*) contains B-spline\nC coefficients for this extended concept of a\nC solution. If MODE=-1,2 or 3 on output, the\nC array COEFF(*) is undefined.\nC\nC Working Arrays..\nC W(*),IW(*)\nC These arrays are respectively typed REAL and\nC INTEGER.\nC Their required lengths are specified as input\nC parameters in IW(1), IW(2) noted above. The\nC contents of W(*) must not be modified by the\nC user if the variance function is desired.\nC\nC Evaluating the\nC Variance Function..\nC To evaluate the variance function (assuming\nC that the uncertainties of the Y values were\nC provided to FC( ) and an input value of\nC MODE=2 or 4 was used), use the function\nC subprogram CV( )\nC\nC VAR=CV(XVAL,NDATA,NCONST,NORD,NBKPT,\nC BKPT,W)\nC\nC Here XVAL is the point where the variance is\nC desired. The other arguments have the same\nC meaning as in the usage of FC( ).\nC\nC For those users employing the old problem\nC designation, let MDATA be the number of data\nC points in the problem. (This may be different\nC from NDATA if the old problem designation\nC feature was used.) The value, VAR, should be\nC multiplied by the quantity\nC\nC REAL(MAX(NDATA-N,1))/MAX(MDATA-N,1)\nC\nC The output of this subprogram is not defined\nC if an input value of MODE=1 or 3 was used in\nC FC( ) or if an output value of MODE=-1, 2, or\nC 3 was obtained. The variance function, except\nC for the scaling factor noted above, is given\nC by\nC\nC VAR=(transpose of B(XVAL))*C*B(XVAL)\nC\nC The vector B(XVAL) is the B-spline basis\nC function values at X=XVAL.\nC The covariance matrix, C, of the solution\nC coefficients accounts only for the least\nC squares equations and the explicitly stated\nC equality constraints. This fact must be\nC considered when interpreting the variance\nC function from a data fitting problem that has\nC inequality constraints on the fitted curve.\nC\nC Evaluating the\nC Fitted Curve..\nC To evaluate derivative number IDER at XVAL,\nC use the function subprogram BVALU( ).\nC\nC F = BVALU(BKPT,COEFF,NBKPT-NORD,NORD,IDER,\nC XVAL,INBV,WORKB)\nC\nC The output of this subprogram will not be\nC defined unless an output value of MODE=0 or 1\nC was obtained from FC( ), XVAL is in the data\nC interval, and IDER is nonnegative and .LT.\nC NORD.\nC\nC The first time BVALU( ) is called, INBV=1\nC must be specified. This value of INBV is the\nC overwritten by BVALU( ). The array WORKB(*)\nC must be of length at least 3*NORD, and must\nC not be the same as the W(*) array used in\nC the call to FC( ).\nC\nC BVALU( ) expects the breakpoint array BKPT(*)\nC to be sorted.\nC\nC***REFERENCES R. J. Hanson, Constrained least squares curve fitting\nC to discrete data using B-splines, a users guide,\nC Report SAND78-1291, Sandia Laboratories, December\nC 1978.\nC***ROUTINES CALLED FCMN\nC***REVISION HISTORY (YYMMDD)\nC 780801 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890531 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900510 Convert references to XERRWV to references to XERMSG. (RWC)\nC 900607 Editorial changes to Prologue to make Prologues for EFC,\nC DEFC, FC, and DFC look as much the same as possible. (RWC)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE FC\n REAL BKPT(*), COEFF(*), SDDATA(*), W(*), XCONST(*),\n * XDATA(*), YCONST(*), YDATA(*)\n INTEGER IW(*), MODE, NBKPT, NCONST, NDATA, NDERIV(*), NORD\nC\n EXTERNAL FCMN\nC\n INTEGER I1, I2, I3, I4, I5, I6, I7, MDG, MDW\nC\nC***FIRST EXECUTABLE STATEMENT FC\n MDG = NBKPT - NORD + 3\n MDW = NBKPT - NORD + 1 + NCONST\nC USAGE IN FCMN( ) OF W(*)..\nC I1,...,I2-1 G(*,*)\nC\nC I2,...,I3-1 XTEMP(*)\nC\nC I3,...,I4-1 PTEMP(*)\nC\nC I4,...,I5-1 BKPT(*) (LOCAL TO FCMN( ))\nC\nC I5,...,I6-1 BF(*,*)\nC\nC I6,...,I7-1 W(*,*)\nC\nC I7,... WORK(*) FOR LSEI( )\nC\n I1 = 1\n I2 = I1 + MDG*(NORD+1)\n I3 = I2 + MAX(NDATA,NBKPT)\n I4 = I3 + MAX(NDATA,NBKPT)\n I5 = I4 + NBKPT\n I6 = I5 + NORD*NORD\n I7 = I6 + MDW*(NBKPT-NORD+1)\n CALL FCMN(NDATA, XDATA, YDATA, SDDATA, NORD, NBKPT, BKPT, NCONST,\n 1 XCONST, YCONST, NDERIV, MODE, COEFF, W(I5), W(I2), W(I3),\n 2 W(I4), W(I1), MDG, W(I6), MDW, W(I7), IW)\n RETURN\n END\n", "meta": {"hexsha": "60945620a260935c0150e985f83a38f7703b4897", "size": 19550, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/fc.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/fc.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/fc.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.4514563107, "max_line_length": 72, "alphanum_fraction": 0.4874680307, "num_tokens": 4359, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894604912848, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6906374317111856}} {"text": "Module strain_mod\n ! Module for all strain-related calculations\n\nContains\n\n Subroutine Strains(F, m, DT, ndir, eps)\n ! The purpose of this subroutine is to calculate the strains (eps, plas12, inel12)\n ! for the given deformation gradient and temperature.\n !\n ! If a nonzero value for R_phi0 is provided, the strains are given in the fiber reference frame\n\n Use matProp_Mod\n Use forlog_Mod\n\n ! Arguments\n Type(matProps), intent(IN) :: m\n Double Precision, intent(IN) :: F(3,3) ! Deformation gradient\n Double Precision, intent(IN) :: DT ! Coefficients of thermal expansion and temperature change\n Integer, intent(IN) :: ndir\n Double Precision, intent(OUT) :: eps(ndir,ndir) ! GL stain tensor, without plasticity\n\n ! Locals\n Parameter (zero=0.d0)\n ! -------------------------------------------------------------------- !\n\n ! Initialize strain tensor\n eps = zero\n\n ! Calculate the Green-Lagrange strain\n eps = GLStrain(F,ndir)\n\n ! Account for thermal strains\n If (DT /= zero) Then\n eps(1,1) = eps(1,1) - m%cte(1)*DT\n eps(2,2) = eps(2,2) - m%cte(2)*DT\n eps(3,3) = eps(3,3) - m%cte(3)*DT\n End If\n\n Return\n End Subroutine Strains\n\n\n Pure Function GLStrain(F, ndir)\n ! Computes the Green-Lagrange strain from the deformation gradient\n\n ! Input\n Double Precision, intent(IN) :: F(3,3)\n Integer, intent(IN) :: ndir\n\n ! Output\n Double Precision :: GLStrain(ndir,ndir)\n\n ! Locals\n Double Precision :: eye(ndir,ndir) ! Identity\n Double Precision, parameter :: zero=0.d0, one=1.d0, half=0.5d0\n ! -------------------------------------------------------------------- !\n\n ! Initialize identity matrix\n eye = zero; Do I = 1,3; eye(I,I) = one; End Do\n\n GLStrain = (MATMUL(TRANSPOSE(F), F) - eye)*half\n\n Return\n End Function GLStrain\n\n\n\nEnd Module strain_mod\n", "meta": {"hexsha": "0f9cbc861503919268813971a3453dc3d6e574f4", "size": 1923, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "for/strain.for", "max_stars_repo_name": "LucaDiStasio/CompDam_DGD", "max_stars_repo_head_hexsha": "c01344972db6b9b97d5d19225bff8e63d8e54a20", "max_stars_repo_licenses": ["NASA-1.3"], "max_stars_count": 81, "max_stars_repo_stars_event_min_datetime": "2016-07-12T18:14:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T04:46:46.000Z", "max_issues_repo_path": "for/strain.for", "max_issues_repo_name": "LucaDiStasio/CompDam_DGD", "max_issues_repo_head_hexsha": "c01344972db6b9b97d5d19225bff8e63d8e54a20", "max_issues_repo_licenses": ["NASA-1.3"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2017-04-04T13:37:26.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-18T14:52:06.000Z", "max_forks_repo_path": "for/strain.for", "max_forks_repo_name": "LucaDiStasio/CompDam_DGD", "max_forks_repo_head_hexsha": "c01344972db6b9b97d5d19225bff8e63d8e54a20", "max_forks_repo_licenses": ["NASA-1.3"], "max_forks_count": 55, "max_forks_repo_forks_event_min_datetime": "2016-07-12T18:47:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T22:46:28.000Z", "avg_line_length": 27.8695652174, "max_line_length": 120, "alphanum_fraction": 0.5865834633, "num_tokens": 532, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894661025424, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6906374266500905}} {"text": "MODULE expint_module\n\n implicit none\n\n PRIVATE\n PUBLIC :: expint\n\nCONTAINS\n\n\n FUNCTION expint( n, x )\n implicit none\n real(8) :: expint\n integer,intent(IN) :: n\n real(8),intent(IN) :: x\n expint=expint_2( x )\n! expint=expint_1( n, x )\n END FUNCTION expint\n\n\n FUNCTION expint_2( x )\n\n implicit none\n real(8) :: expint_2\n real(8),intent(IN) :: x\n real(8),parameter :: euler=0.577215664901532860606512d0\n real(8) :: y,tny,eps,delta\n real(8) :: ai,bi,f0,f1,C0,C1,D0,D1,a0\n integer :: nmax,i,j\n\n nmax = 100000\n eps = epsilon(1.0d0)\n tny = tiny(1.0d0)\n\n if ( x <= 0.0d0 ) then\n\n stop \"bad argument (stop@expint)\"\n\n else if ( x >= 0.5d0 ) then\n\n f0 = tny\n C0 = f0\n D0 = 0.0d0\n a0 = 1.0d0\n\n do i=1,nmax\n bi = x + 2.0d0*i - 1.0d0\n ai = -(i-1)*(i-1) + a0\n D1 = bi + ai*D0\n if ( D1 == 0.0d0 ) D1=tny\n C1 = bi + ai/C0\n if ( C1 == 0.0d0 ) C1=tny\n D1 = 1.0d0/D1\n delta = C1*D1\n f1 = f0*delta\n if ( abs(delta-1.0d0) < eps ) exit\n f0 = f1\n C0 = C1\n D0 = D1\n a0 = 0.0d0\n end do\n\n if ( i > nmax ) stop \"continued fraction is not converged(stop@expint)\"\n\n expint_2 = f1*exp(-x)\n\n else if ( x < 0.5d0 ) then\n\n f0 = 0.0d0\n\n do i=1,nmax\n\n f1 = f0\n\n ai = 1.0d0\n do j=1,i\n ai = ai*( -x/dble(j) )\n end do\n\n f0 = f0 + ai/dble(i)\n\n if ( abs(f0-f1) < eps ) exit\n\n end do\n\n if ( i > nmax ) stop \"power series is not converged(stop@expint)\"\n\n expint_2 = - euler - log(x) - f0\n\n end if\n\n END FUNCTION expint_2\n\n\n function expint_1(n,x) result(expint)\n implicit none\n integer,intent(in) :: n\n real(8),intent(in) :: x\n real(8) :: expint\n integer,parameter :: maxit=200\n real(8),parameter :: esp=1.d-12, big=huge(x)*esp\n real(8),parameter :: euler=0.577215664901532860606512d0\n integer :: i,nm1,j\n real(8) :: a,b,c,d,del,fact,h,arsum\n \n if ( .not.(n>=0.and.x>=0.d0.and.(x>0.d0.or.n>1)) ) then\n write(*,*) 'Bad arguments in expint.f'\n stop\n end if\n \n if ( n==0 ) then\n expint=exp(-x)/x\n return\n end if\n nm1=n-1\n if ( x==0.d0 ) then\n expint=1.d0/nm1\n else if ( x>1.d0 ) then\n b=x+n\n c=big\n d=1.d0/b\n h=d\n do i=1,maxit\n a=-i*(nm1+i)\n b=b+2.d0\n d=1.d0/(a*d+b)\n c=b+a/c\n del=c*d\n h=h*del\n if ( abs(del-1.d0)<=esp ) exit\n end do\n if ( i>maxit ) then\n write(*,*) 'Continued fraction failed in expint.f'\n stop\n end if\n expint=h*exp(-x)\n else\n if ( nm1/=0 ) then\n expint=1.d0/nm1\n else\n expint=-log(x)-euler\n end if\n fact=1.d0\n do i=1,maxit\n fact=-fact*x/i\n if ( i/=nm1 ) then\n del=-fact/(i-nm1)\n else\n arsum = 0.d0\n do j=1,nm1\n arsum = arsum + 1.d0/j\n end do\n del = fact*(-LOG(x)-euler+arsum)\n end if\n expint=expint+del\n if ( abs(del)maxit ) then\n write(*,*) 'series failed in expint.f'\n stop\n end if\n end if\n\n end function expint_1\n\nEND MODULE expint_module\n", "meta": {"hexsha": "f8af0e58ce2f29406736c5bf6474baf815f8c517", "size": 3435, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/expint_module.f90", "max_stars_repo_name": "j-iwata/RSDFT", "max_stars_repo_head_hexsha": "2a961b2c8339a49de9bd09f55e7d6a45b6159d2e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2016-10-31T02:11:39.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-04T17:45:30.000Z", "max_issues_repo_path": "src/expint_module.f90", "max_issues_repo_name": "j-iwata/RSDFT", "max_issues_repo_head_hexsha": "2a961b2c8339a49de9bd09f55e7d6a45b6159d2e", "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/expint_module.f90", "max_forks_repo_name": "j-iwata/RSDFT", "max_forks_repo_head_hexsha": "2a961b2c8339a49de9bd09f55e7d6a45b6159d2e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-10-31T02:11:41.000Z", "max_forks_repo_forks_event_max_datetime": "2020-04-18T14:26:38.000Z", "avg_line_length": 20.5688622754, "max_line_length": 78, "alphanum_fraction": 0.4721979622, "num_tokens": 1269, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969136, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6906374244845842}} {"text": "MODULE mod_blas\n\n IMPLICIT NONE\n\n INTERFACE\n\n ! BLAS Level 1 function\n ! Double precision Euclidean norm\n DOUBLE PRECISION FUNCTION DNRM2( n, X, incx )\n INTEGER n, incx\n DOUBLE PRECISION X(*)\n END FUNCTION DNRM2\n\n ! BLAS Level 2 subroutine\n ! Double precision matrix-vector multiply C = alpha * A x + beta * y\n SUBROUTINE DGEMV( trans, m, n, &\n alpha, A, lda, &\n x, incx, &\n beta, y, incy )\n CHARACTER*1 trans\n INTEGER m, n, lda, incx, incy\n DOUBLE PRECISION alpha, beta\n DOUBLE PRECISION A(lda,*), X(*), Y(*)\n END SUBROUTINE DGEMV\n\n END INTERFACE\n\nEND MODULE mod_blas\n", "meta": {"hexsha": "39e88aeb3c22a63b551075d8472f1798d57ed3e0", "size": 714, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mpi-acc-magma-zgemv/mod_blas.f90", "max_stars_repo_name": "wyphan/testcodes", "max_stars_repo_head_hexsha": "cbf8ea436119882ad39dbe78271cb1aefe3c9543", "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": "mpi-acc-magma-zgemv/mod_blas.f90", "max_issues_repo_name": "wyphan/testcodes", "max_issues_repo_head_hexsha": "cbf8ea436119882ad39dbe78271cb1aefe3c9543", "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": "mpi-acc-magma-zgemv/mod_blas.f90", "max_forks_repo_name": "wyphan/testcodes", "max_forks_repo_head_hexsha": "cbf8ea436119882ad39dbe78271cb1aefe3c9543", "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": 24.6206896552, "max_line_length": 73, "alphanum_fraction": 0.5588235294, "num_tokens": 195, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789452074398, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6906374205186124}} {"text": "! $UWHPSC/codes/mpi/quadrature/functions_mod.f90\n\nmodule functions_mod\n\n ! Define the function we want to integrate.\n ! Also define the indefinite integral (anti-derivative) of g for\n ! use in computing the true solution to compute the error.\n\n ! The integer gevals can be initialized to 0 in the main program\n ! and then will count how many times the function g is called by each proc.\n ! Note that this is automatically local to each processor!\n\n ! k is the wave number used in g and gint.\n\n use mpi\n implicit none\n integer :: gevals\n real(kind=8) :: k\n save\n\ncontains\n\nreal(kind=8) function g(x)\n ! Test function to integrate\n implicit none\n real(kind=8), intent(in) :: x\n integer :: proc_num, ierr\n\n g = exp(0.1d0*x) + cos(k*x)\n gevals = gevals + 1\n\nend function g\n\nreal(kind=8) function gint(x)\n ! Anti-derivative of g\n implicit none\n real(kind=8), intent(in) :: x\n gint = 10.d0*exp(0.1d0*x) + sin(k*x) / k\nend function gint\n\nend module functions_mod\n", "meta": {"hexsha": "1b94bed4cce62f5d544510e1d4a8669c6f267da7", "size": 1022, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/codes/mpi/quadrature/functions_mod.f90", "max_stars_repo_name": "philipwangdk/HPC", "max_stars_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "uwhpsc/codes/mpi/quadrature/functions_mod.f90", "max_issues_repo_name": "philipwangdk/HPC", "max_issues_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "uwhpsc/codes/mpi/quadrature/functions_mod.f90", "max_forks_repo_name": "philipwangdk/HPC", "max_forks_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.3333333333, "max_line_length": 79, "alphanum_fraction": 0.6722113503, "num_tokens": 289, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240964782012, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.6906104398211279}} {"text": "module EquationClass\n use iso_fortran_env\n use MathClass\n implicit none\n\n type :: Equation_\n real(real64) :: a, b, c, d\n real(real64),allocatable :: x(:)\n logical :: LinearEquation, QuadraticEquation\n contains\n procedure, public :: setup => setupEquation\n procedure, public :: solve => solveEquation\n end type\n\ncontains\n\n! ####################################\nsubroutine setupEquation(obj,LinearEquation,QuadraticEquation,a,b,c,d)\n class(Equation_),intent(inout) :: obj\n logical,optional,intent(in) :: LinearEquation,QuadraticEquation\n real(real64),optional,intent(in) :: a,b,c,d\n obj%LinearEquation=.false.\n obj%QuadraticEquation =.false.\n \n if(present(LinearEquation) )then\n if(LinearEquation .eqv. .true.)then\n if(allocated(obj%x) )then\n deallocate(obj%x)\n endif\n allocate(obj%x(1))\n obj%LinearEquation=.true.\n !allocate(obj%x(2) )\n obj%a = input(default=0.0d0, option=a) \n obj%b = input(default=0.0d0, option=b)\n print *, \"Linear Equation\"\n print *, obj%a, \"x\", \"+\",obj%b,\"= 0\"\n ! obj%c = input(default=0.0d0, option=c)\n ! obj%d = input(default=0.0d0, option=d) \n return\n endif\n endif\n\n if(present(QuadraticEquation))then\n if(QuadraticEquation .eqv. .true.)then\n if(allocated(obj%x) )then\n deallocate(obj%x)\n endif\n allocate(obj%x(2))\n obj%QuadraticEquation=.true.\n obj%a = input(default=0.0d0, option=a) \n obj%b = input(default=0.0d0, option=b) \n obj%c = input(default=0.0d0, option=c)\n print *, \"Quadratic Equation\"\n print *, obj%a, \"x^2\", \"+\",obj%b,\"x +\",obj%c,\"= 0\"\n endif\n return\n endif\n\nend subroutine setupEquation\n! ####################################\n\n! ####################################\nsubroutine solveEquation(obj)\n class(Equation_),intent(inout) :: obj\n real(real64) :: Dval\n\n if(obj%LinearEquation .eqv. .true.)then\n if(obj%a ==0.0d0 .or. obj%a /= obj%a)then\n print *, \"solveEquation :: ERROR :: ax +b =0, a=0\"\n stop\n else\n obj%x(1) = - obj%b / obj%a\n print *, \"x = \", obj%x(1)\n endif\n return\n endif\n if(obj%QuadraticEquation .eqv. .true.)then\n Dval = obj%b * obj%b - 4.0d0*obj%a*obj%c\n if(Dval < 0.0d0)then\n print *, \"solveEquation :: ERROR :: D = b^2 - 4 a c < 0\"\n stop\n else\n if(Dval == 0.0d0)then\n obj%x = - obj%b/(2.0d0 * obj%a)\n print *, \"x = \", obj%x(1)\n else\n obj%x(1) = (- obj%b + sqrt(Dval))/(2.0d0 * obj%a)\n obj%x(2) = (- obj%b - sqrt(Dval))/(2.0d0 * obj%a)\n print *, \"x = \", obj%x(2)\n endif\n endif\n return\n endif\nend subroutine\n! ####################################\n\nend module EquationClass", "meta": {"hexsha": "6affcc23fc98e168169d2306416329826e797e5e", "size": 3084, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/EquationClass/EquationClass.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": "src/EquationClass/EquationClass.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": "src/EquationClass/EquationClass.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": 31.793814433, "max_line_length": 70, "alphanum_fraction": 0.4944876783, "num_tokens": 891, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240756264639, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.6906104231775467}} {"text": "!==============================================================================!\n subroutine Surf_Mod_Statistics(surf)\n!------------------------------------------------------------------------------!\n implicit none\n!---------------------------------[Arguments]----------------------------------!\n type(Surf_Type), target :: surf\n!-----------------------------------[Locals]-----------------------------------!\n type(Vert_Type), pointer :: vert(:)\n type(Elem_Type), pointer :: elem(:)\n type(Side_Type), pointer :: side(:)\n integer, pointer :: nv, ns, ne\n integer :: item, i, j, k, c, d, e, s, v, si, sj, sk\n integer :: nne_s, nne_e\n real, allocatable :: nne(:)\n real :: a(3), b(3), tri_v(3)\n real :: max_rat, min_rat, max_l, min_l\n character(len=160) :: line\n integer, parameter :: T=33 ! indent\n!==============================================================================!\n\n ! Take aliases\n nv => surf % n_verts\n ns => surf % n_sides\n ne => surf % n_elems\n vert => surf % vert\n side => surf % side\n elem => surf % elem\n\n !--------------------------!\n ! Compute side lengths !\n !--------------------------!\n do s = 1, ns\n c = side(s) % c\n d = side(s) % d\n side(s) % length = Math_Mod_Distance( &\n vert(c) % x_n, vert(c) % y_n, vert(c) % z_n, &\n vert(d) % x_n, vert(d) % y_n, vert(d) % z_n)\n end do\n\n !-----------------------------!\n ! Compute elements' areas !\n !-----------------------------!\n do e = 1, ne\n i = elem(e) % i\n j = elem(e) % j\n k = elem(e) % k\n a(1) = vert(j) % x_n - vert(i) % x_n\n a(2) = vert(j) % y_n - vert(i) % y_n\n a(3) = vert(j) % z_n - vert(i) % z_n\n b(1) = vert(k) % x_n - vert(i) % x_n\n b(2) = vert(k) % y_n - vert(i) % y_n\n b(3) = vert(k) % z_n - vert(i) % z_n\n tri_v = Math_Mod_Cross_Product(a, b)\n elem(e) % area = sqrt(dot_product(tri_v, tri_v)) * 0.5\n end do\n\n !------------------------------!\n ! Extreme side size ratios !\n !------------------------------!\n max_rat = -HUGE\n min_rat = +HUGE\n do e = 1, ne\n si = elem(e) % si\n sj = elem(e) % sj\n sk = elem(e) % sk\n max_l = max(side(si) % length, side(sj) % length, side(sk) % length)\n min_l = min(side(si) % length, side(sj) % length, side(sk) % length)\n max_rat = max(max_rat, max_l/min_l)\n min_rat = min(min_rat, max_l/min_l)\n end do\n\n !--------------------------------!\n ! Count number of neighbours !\n !--------------------------------!\n call Surf_Mod_Count_Vertex_Elements(surf)\n nne_s = minval(vert(1:nv) % nne)\n nne_e = maxval(vert(1:nv) % nne)\n allocate(nne(nne_s:nne_e)); nne = 0.0\n do v = 1, nv\n nne(vert(v) % nne) = nne(vert(v) % nne) + 1.0\n end do\n\n if(this_proc < 2) then\n\n line( 1:160) = ' '\n line( 1+T:63+T) = &\n '#=============================================================#'\n print *, trim(line)\n line( 1+T:63+T) = &\n '# Surface mesh statistics #'\n print *, trim(line)\n line( 1+T:63+T) = &\n '#-------------------------------------------------------------#'\n print *, trim(line)\n\n ! Number of elements (1), nodes (2) and sides (3)\n do item = 1, 3\n line( 1:160) = ' '\n line( 1+T: 1+T) = '#'\n line(63+T:63+T) = '#'\n line( 3+T: 3+T) = '-'\n if(item.eq.1) line( 5+T: 5+T+20) = 'Number of elements: '\n if(item.eq.1) write(line(32+T:37+T), '(i6)') surf % n_elems\n if(item.eq.2) line( 5+T: 5+T+20) = 'Number of vertices: '\n if(item.eq.2) write(line(32+T:37+T), '(i6)') surf % n_verts\n if(item.eq.3) line( 5+T: 5+T+20) = 'Number of sides: '\n if(item.eq.3) write(line(32+T:37+T), '(i6)') surf % n_sides\n print *, trim(line)\n end do\n\n line( 1+T:63+T) = &\n '#-------------------------------------------------------------#'\n print *, trim(line)\n\n ! Maximum (1) and minimum (2) element area\n ! Maximum (3) and minimum (4) side length\n ! Maximum (5) and minimum (6) side length ratio\n do item = 1, 6\n line( 1:160) = ' '\n line( 1+T: 1+T) = '#'\n line(63+T:63+T) = '#'\n line( 3+T: 3+T) = '-'\n if(item.eq.1) line( 5+T: 5+T+33) = 'Maximum element area: '\n if(item.eq.1) write(line(36+T:47+T), '(1pe12.5)') &\n maxval(elem(1:ne) % area)\n if(item.eq.2) line( 5+T: 5+T+33) = 'Minimum element area: '\n if(item.eq.2) write(line(36+T:47+T), '(1pe12.5)') &\n minval(elem(1:ne) % area)\n if(item.eq.3) line( 5+T: 5+T+33) = 'Maximum side length: '\n if(item.eq.3) write(line(36+T:47+T), '(1pe12.5)') &\n maxval(side(1:ns) % length)\n if(item.eq.4) line( 5+T: 5+T+33) = 'Minimum side length: '\n if(item.eq.4) write(line(36+T:47+T), '(1pe12.5)') &\n minval(side(1:ns) % length)\n if(item.eq.5) line( 5+T: 5+T+33) = 'Maximum side ratio in element: '\n if(item.eq.5) write(line(36+T:47+T), '(1pe12.5)') max_rat\n if(item.eq.6) line( 5+T: 5+T+33) = 'Minimum side ratio in element: '\n if(item.eq.6) write(line(36+T:47+T), '(1pe12.5)') min_rat\n print *, trim(line)\n end do\n\n line( 1+T:63+T) = &\n '#-------------------------------------------------------------#'\n print *, trim(line)\n\n ! Number of neighbours\n do item = nne_s, nne_e\n line( 1:160) = ' '\n line( 1+T: 1+T) = '#'\n line(63+T:63+T) = '#'\n line( 3+T: 3+T) = '-'\n line( 5+T: 5+T+43) = 'Percentage of vertices with XX neighbours: '\n write(line(33+T:34+T), '(i2)') item\n write(line(48+T:53+T), '(f6.2)') nne(item) / nv * 100.0\n line(55+T:55+T) = '%'\n print *, trim(line)\n end do\n\n line( 1+T:63+T) = &\n '#-------------------------------------------------------------#'\n print *, trim(line)\n print *, ''\n\n end if\n\n end subroutine\n", "meta": {"hexsha": "84b895f953e5b51c33a119647d13597ba27c4fb3", "size": 6053, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Sources/Process/Surf_Mod/Statistics.f90", "max_stars_repo_name": "Dundj/Convex_Geomotry", "max_stars_repo_head_hexsha": "38507824d97270b3e4ead194a16148ff6158b59f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 64, "max_stars_repo_stars_event_min_datetime": "2018-05-29T09:39:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T13:59:18.000Z", "max_issues_repo_path": "Sources/Process/Surf_Mod/Statistics.f90", "max_issues_repo_name": "EdinSmartLab/T-Flows", "max_issues_repo_head_hexsha": "5a7f70421f18069453977142e6515cdc959a9e50", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 124, "max_issues_repo_issues_event_min_datetime": "2018-05-28T12:58:20.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-03T11:12:31.000Z", "max_forks_repo_path": "Sources/Process/Surf_Mod/Statistics.f90", "max_forks_repo_name": "EdinSmartLab/T-Flows", "max_forks_repo_head_hexsha": "5a7f70421f18069453977142e6515cdc959a9e50", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 39, "max_forks_repo_forks_event_min_datetime": "2018-05-28T13:13:06.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-27T17:41:08.000Z", "avg_line_length": 36.245508982, "max_line_length": 80, "alphanum_fraction": 0.4113662647, "num_tokens": 2004, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.7981867777396211, "lm_q1q2_score": 0.6906104224948899}} {"text": "module universal_constants\n use kind_parameters, only : rkind\n implicit none\n\n private\n public :: pi\n public :: atmospheric_pressure\n\n real(rkind), parameter :: pi = 3.141592654_rkind\n real(rkind), parameter :: atmospheric_pressure = 101325._rkind ! Pascals\n\nend module\n", "meta": {"hexsha": "c10156f98c6b034450ac5931e73c484489839401", "size": 277, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/utilities/universal_constants.f90", "max_stars_repo_name": "sourceryinstitute/rocket-science", "max_stars_repo_head_hexsha": "92c79b1008db7a715770e098db0dbda6a6062d54", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-09-23T15:09:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-24T05:50:57.000Z", "max_issues_repo_path": "src/utilities/universal_constants.f90", "max_issues_repo_name": "sourceryinstitute/rocket-science", "max_issues_repo_head_hexsha": "92c79b1008db7a715770e098db0dbda6a6062d54", "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/utilities/universal_constants.f90", "max_forks_repo_name": "sourceryinstitute/rocket-science", "max_forks_repo_head_hexsha": "92c79b1008db7a715770e098db0dbda6a6062d54", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2021-03-04T14:17:20.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-21T17:35:44.000Z", "avg_line_length": 21.3076923077, "max_line_length": 74, "alphanum_fraction": 0.7472924188, "num_tokens": 74, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240756264638, "lm_q2_score": 0.7981867753392728, "lm_q1q2_score": 0.6906104148701903}} {"text": "!> @brief Finite Difference Approximations module\nmodule FDA\nimplicit none\n\ncontains\n\n !> @brief Finite Difference Coefficient calculation\n\n !> Compute coefficients for finite difference approximation for the\n !! derivative of order k at xbar based on grid values at points in xpt.\n !!\n !! @param[in] xbar location at which we want to approximate the derivative\n !! (may but need not be a grid point)\n !! @param[in] xpt grid point locations which the stencil is to extend over\n !! (distinct, otherwise arbitrary)\n !! @param[out] c weights at grid locations xpt(0:n) for derivatives\n !! of order 0:m, found in c(0:n,0:m)\n subroutine FDAFDC(xbar, xpt, c)\n real(kind(0.d0)), intent(in) :: xbar\n real(kind(0.d0)), intent(in), dimension(:) :: xpt\n real(kind(0.d0)), intent(out), dimension(:,:) :: c\n\n ! local variables\n real(kind(0.d0)) :: c1, c2, c3, c4, c5\n integer :: k, j, i, mn, devs\n\n devs = size(c, dim=2)\n c1 = 1.d0\n c4 = xpt(1)-xbar\n\n do k = 1, devs\n do j = 1 , size(c, dim=1)\n c(j,k) = 0.d0\n end do\n end do\n\n c(1,1) = 1.d0\n do i = 2, size(c, dim=1)\n mn = min(i,devs)\n c2 = 1.0d0\n c5 = c4\n c4 = xpt(i) - xbar\n\n do j = 1, i\n c3 = xpt(i)-xpt(j)\n c2 = c2 * c3\n\n if ( j .eq. i ) then\n do k = mn, 1, -1\n c(i,k) = c1 * (k * c(i-1,k-1) - c5 * c(i-1,k))/c2\n end do\n\n c(i,1) = -c1 * c5 * c(i-1,1)/c2\n endif\n\n do k = mn, 2, -1\n c(j,k) = (c4 * c(j,k) - k * c(j,k-1))/c3\n end do\n\n c(j,1) = c4 * c(j,1)/c3\n end do\n\n c1 = c2\n end do\n\n end subroutine FDAFDC\n\n\nend module FDA\n", "meta": {"hexsha": "8b49f598f591bdeced0881158740184f7c70b047", "size": 1838, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "srcf/core/FDA.f90", "max_stars_repo_name": "Phortran/cmeth", "max_stars_repo_head_hexsha": "604e73a926eeeb0020b194e33f71b5d483e2029c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "srcf/core/FDA.f90", "max_issues_repo_name": "Phortran/cmeth", "max_issues_repo_head_hexsha": "604e73a926eeeb0020b194e33f71b5d483e2029c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "srcf/core/FDA.f90", "max_forks_repo_name": "Phortran/cmeth", "max_forks_repo_head_hexsha": "604e73a926eeeb0020b194e33f71b5d483e2029c", "max_forks_repo_licenses": ["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.2571428571, "max_line_length": 81, "alphanum_fraction": 0.4874863983, "num_tokens": 620, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240686758841, "lm_q2_score": 0.7981867777396212, "lm_q1q2_score": 0.6906104113991687}} {"text": "\r\n! ------------------------ begin dcdt -------------------\r\n subroutine dcdt (y,dt,npts,indx1,indx2,ldc,ldt)\r\n!+\r\n! dcdt - fits dc or trend between indices indx1 and indx2.\r\n! then removes dc or detrends whole trace.\r\n! y is real, dt = delta t.\r\n! if remove dc, ldc = .true.\r\n! if detrend, ldt = .true.\r\n!-\r\n\r\n! Dates: 12/14/00 - Cleaned up formatting of original program\r\n! 04/28/15 - Replaced comment characters * or C with ! (The Fortran 95 standard)\r\n\r\n real y(*)\r\n logical ldc,ldt\r\n\r\n if (.not. ldc .and. .not. ldt) then\r\n return\r\n end if\r\n\r\n!\r\n!...fit dc and trend between indices indx1 and indx2.\r\n nsum = indx2-indx1+1\r\n sumx = 0.0\r\n sumx2 = 0.0\r\n sumy = 0.0\r\n sumxy = 0.0\r\n do i=indx1,indx2\r\n xsubi = (i-1)*dt\r\n sumxy = sumxy+xsubi*y(i)\r\n sumx = sumx+xsubi\r\n sumx2 = sumx2+xsubi*xsubi\r\n sumy = sumy+y(i)\r\n end do\r\n!\r\n!... remove dc.\r\n if (ldc) then\r\n avy = sumy/nsum\r\n do i=1,npts\r\n y(i) = y(i)-avy\r\n end do\r\n! Debug\r\n write(*,'(a)') ' indx1, indx2, avy'\r\n write(*, *) indx1, indx2, avy\r\n! Debug\r\n\r\n\r\n\r\n return\r\n endif\r\n!\r\n!... detrend. see draper and smith, p. 10.\r\n if (ldt) then\r\n bxy = (sumxy-sumx*sumy/nsum)/(sumx2-sumx*sumx/nsum)\r\n axy = (sumy-bxy*sumx)/nsum\r\n qxy = dt*bxy\r\n do i=1,npts\r\n y(i) = y(i)-(axy+(i-1)*qxy)\r\n end do\r\n return\r\n endif\r\n!\r\n return\r\n end\r\n! ------------------------ end dcdt -------------------\r\n\r\n", "meta": {"hexsha": "7a85ba43222d6621b928beac0f2236788c7fa184", "size": 1622, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "bbp/src/usgs/fas/dcdt.for", "max_stars_repo_name": "kevinmilner/bbp", "max_stars_repo_head_hexsha": "d9ba291b123be4e85f76317ef23600a339b2354d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2017-10-31T09:16:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T23:44:29.000Z", "max_issues_repo_path": "bbp/src/usgs/fas/dcdt.for", "max_issues_repo_name": "kevinmilner/bbp", "max_issues_repo_head_hexsha": "d9ba291b123be4e85f76317ef23600a339b2354d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 37, "max_issues_repo_issues_event_min_datetime": "2017-05-23T15:15:35.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-05T09:13:18.000Z", "max_forks_repo_path": "bbp/src/usgs/fas/dcdt.for", "max_forks_repo_name": "kevinmilner/bbp", "max_forks_repo_head_hexsha": "d9ba291b123be4e85f76317ef23600a339b2354d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2017-09-21T17:43:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-29T06:34:30.000Z", "avg_line_length": 23.8529411765, "max_line_length": 88, "alphanum_fraction": 0.4630086313, "num_tokens": 536, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218434359675, "lm_q2_score": 0.7490872075132153, "lm_q1q2_score": 0.6905998592448847}} {"text": "program main\n use sho \n implicit none\n integer :: status = 0\n call init\n print*, \"Tmax (in seconds) : \", sho_tmax\n print*, \"Tmax (in binary periods) : \", sho_tmax/sho_period\n do while (sho_t.le.sho_tmax)\n call sho_interrupt\n call sho_rk4\n !call sho_collision_test\n if (sho_test == 1) then ! Ends progam if test mass gets too close to accretor \n print*, \"Binary Periods completed before collision: \", sho_t/(2.0*sho_pi/omega)\n call exit(status)\n end if\n call sho_update\n end do\n call sho_exit\nend program main\n\n\n", "meta": {"hexsha": "ba39e4242b7fdc474354cd0338e7ddebac219a95", "size": 589, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "main.f90", "max_stars_repo_name": "icweaver/particle_trajectory", "max_stars_repo_head_hexsha": "ec2d9762d114ffe6ab628ffda17c7ed4b7d26a3c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "main.f90", "max_issues_repo_name": "icweaver/particle_trajectory", "max_issues_repo_head_hexsha": "ec2d9762d114ffe6ab628ffda17c7ed4b7d26a3c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "main.f90", "max_forks_repo_name": "icweaver/particle_trajectory", "max_forks_repo_head_hexsha": "ec2d9762d114ffe6ab628ffda17c7ed4b7d26a3c", "max_forks_repo_licenses": ["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.7727272727, "max_line_length": 85, "alphanum_fraction": 0.6315789474, "num_tokens": 171, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218391455084, "lm_q2_score": 0.7490872075132153, "lm_q1q2_score": 0.6905998560309566}} {"text": "!>----------------------------------------\n!! Simple program to test and time sorting routines\n!!\n!! Generates n random numbers, uses heap_sort to sort them,\n!! Then tests that the sort succeeded and prints timing info\n!!\n!! Next this is repeated for quick_sort. \n!!\n!! Initial data show that this implementation of quick_sort is ~2x faster than \n!! the (somewhat naive) implementation of heap_sort\n!!\n!!----------------------------------------\nprogram test_sort\n use sort_mod\n \n implicit none\n\n real, parameter :: valid_error = 1e-5\n integer*8, parameter :: n = 1000000\n \n real, allocatable, dimension(:) :: to_sort, sorted\n integer :: i, start_time, end_time, COUNT_RATE, COUNT_MAX\n \n allocate(to_sort(n))\n allocate(sorted(n))\n \n !-------------------------------\n ! SETUP sorting\n !-------------------------------\n call random_number(to_sort)\n sorted=0\n ! test heap_sort (system_clock is used to time how long it takes)\n \n call system_clock(start_time)\n !-------------------------------\n ! HEAP SORT\n !-------------------------------\n call heap_sort(to_sort, sorted)\n \n call system_clock(end_time, COUNT_RATE, COUNT_MAX)\n if (start_time>end_time) end_time=end_time+COUNT_MAX\n\n call show_results(sorted, \"HEAP_SORT\", (end_time-start_time) / real(COUNT_RATE))\n \n\n !-------------------------------\n ! SETUP sorting\n !-------------------------------\n ! now test quick_sort \n call random_number(to_sort)\n sorted = 0\n \n call system_clock(start_time)\n !-------------------------------\n ! QUICK SORT\n !-------------------------------\n call quick_sort(to_sort, sorted)\n \n call system_clock(end_time, COUNT_RATE, COUNT_MAX)\n if (start_time>end_time) end_time=end_time+COUNT_MAX\n\n call show_results(sorted, \"QUICK_SORT\", (end_time-start_time) / real(COUNT_RATE))\n \n !-------------------------------\n ! SETUP sorting\n !-------------------------------\n ! now test quick_sort \n call random_number(to_sort)\n \n call system_clock(start_time)\n !-------------------------------\n ! QUICK SORT in place\n !-------------------------------\n call sort(to_sort)\n \n call system_clock(end_time, COUNT_RATE, COUNT_MAX)\n if (start_time>end_time) end_time=end_time+COUNT_MAX\n\n call show_results(to_sort, \"QUICK_SORT (in place)\", (end_time-start_time) / real(COUNT_RATE))\n\ncontains\n !>--------------------------\n !! Print out results from a given sort test\n !!\n !!--------------------------\n subroutine show_results(data, name, time)\n implicit none\n real, dimension(:), intent(in) :: data\n character(len=*), intent(in) :: name\n real, intent(in) :: time\n \n integer :: i, n, err\n \n n = size(data)\n \n print*, \"---------------------------\"\n err = 0\n do i=1,n-1\n if (sorted(i+1)\n! and Francois-Xavier Coudert \n!\nprogram main\n call PR31994\n call PR31994_comment6\ncontains\n subroutine PR31994\r\n implicit none\r\n complex (kind=4), dimension(2,2) :: a, b, c\r\n a(1,1) = (1.,1.)\r\n a(2,1) = (2.,2.)\r\n a(1,2) = (3.,3.)\r\n a(2,2) = (4.,4.)\r\n b=conjg (transpose (a))\r\n c=transpose (a)\r\n c=conjg (c)\r\n if (any (b .ne. c)) STOP 1\n end subroutine PR31994\n subroutine PR31994_comment6\n implicit none\r\n real ,dimension(2,2)::a\n integer ,dimension(2,2) :: b, c\n a = reshape ((/1.,2.,3.,4./), (/2,2/))\n b=int (transpose(a))\n c = int (a)\n c = transpose (c)\n if (any (b .ne. c)) STOP 2\n end subroutine PR31994_comment6\r\nEND program main\r\n", "meta": {"hexsha": "246f8ceacaa33687769f437ab31452a24819d85b", "size": 980, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/array_reference_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/array_reference_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/array_reference_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": 27.2222222222, "max_line_length": 64, "alphanum_fraction": 0.6081632653, "num_tokens": 353, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104788903594355, "lm_q2_score": 0.8519528076067261, "lm_q1q2_score": 0.6904897661477051}} {"text": "subroutine qinit(meqn,mbc,mx,xlower,dx,q,maux,aux)\n\n ! Set initial conditions for the q array.\n ! This default version simply sets eta = max(h + b,0)\n\n ! For more specific initial conditions\n ! copy this to an application directory and\n ! loop over all grid cells to set values of q(1:meqn, 1:mx).\n\n use geoclaw_module, only: grav !uncomment if needed\n use grid_module, only: xgrid,zgrid,mx_grid\n\n implicit none\n\n integer, intent(in) :: meqn,mbc,mx,maux\n real(kind=8), intent(in) :: xlower,dx\n real(kind=8), intent(in) :: aux(maux,1-mbc:mx+mbc)\n real(kind=8), intent(inout) :: q(meqn,1-mbc:mx+mbc)\n\n !locals\n integer :: i\n real(kind=8) :: xcell,x0,width,eta\n\n x0 = -60.d3 ! initial location of step\n width = 30.e3\n\n do i=1,mx\n xcell = 0.5*(xgrid(i) + xgrid(i+1))\n !if (xcell > x0) then \n if ((xcell < x0-width) .or. (xcell > x0)) then \n eta = 0.d0\n else\n eta = 1.d0\n endif\n q(1,i) = max(0.0, eta - aux(1,i))\n q(2,i) = eta*sqrt(grav*q(1,i)) ! right-going\n\n enddo\n\n\nend subroutine qinit\n", "meta": {"hexsha": "d3c4599ad76582107a6801b38d88c61cfe4e546d", "size": 1104, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "qinit_box/qinit.f90", "max_stars_repo_name": "rjleveque/shoaling_paper_figures", "max_stars_repo_head_hexsha": "4cd22188dff7e9797e6f1c5f5845fc5b420585bb", "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": "qinit_box/qinit.f90", "max_issues_repo_name": "rjleveque/shoaling_paper_figures", "max_issues_repo_head_hexsha": "4cd22188dff7e9797e6f1c5f5845fc5b420585bb", "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": "qinit_box/qinit.f90", "max_forks_repo_name": "rjleveque/shoaling_paper_figures", "max_forks_repo_head_hexsha": "4cd22188dff7e9797e6f1c5f5845fc5b420585bb", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.2857142857, "max_line_length": 65, "alphanum_fraction": 0.5923913043, "num_tokens": 391, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797124237605, "lm_q2_score": 0.7577943822145998, "lm_q1q2_score": 0.6904868672626403}} {"text": " SUBROUTINE slDMAT (N, A, Y, D, JF, IW)\n*+\n* - - - - -\n* D M A T\n* - - - - -\n*\n* Matrix inversion & solution of simultaneous equations\n* (double precision)\n*\n* For the set of n simultaneous equations in n unknowns:\n* A.Y = X\n*\n* where:\n* A is a non-singular N x N matrix\n* Y is the vector of N unknowns\n* X is the known vector\n*\n* DMATRX computes:\n* the inverse of matrix A\n* the determinant of matrix A\n* the vector of N unknowns\n*\n* Arguments:\n*\n* symbol type dimension before after\n*\n* N i no. of unknowns unchanged\n* A d (N,N) matrix inverse\n* Y d (N) known vector solution vector\n* D d - determinant\n* * JF i - singularity flag\n* IW i (N) - workspace\n*\n* * JF is the singularity flag. If the matrix is non-singular, JF=0\n* is returned. If the matrix is singular, JF=-1 & D=0D0 are\n* returned. In the latter case, the contents of array A on return\n* are undefined.\n*\n* Algorithm:\n* Gaussian elimination with partial pivoting.\n*\n* Speed:\n* Very fast.\n*\n* Accuracy:\n* Fairly accurate - errors 1 to 4 times those of routines optimized\n* for accuracy.\n*\n* P.T.Wallace Starlink 4 December 2001\n*\n* Copyright (C) 2001 Rutherford Appleton Laboratory\n*\n* License:\n* This program is free software; you can redistribute it and/or modify\n* it under the terms of the GNU General Public License as published by\n* the Free Software Foundation; either version 2 of the License, or\n* (at your option) any later version.\n*\n* This program is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU General Public License for more details.\n*\n* You should have received a copy of the GNU General Public License\n* along with this program (see SLA_CONDITIONS); if not, write to the\n* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,\n* Boston, MA 02110-1301 USA\n*\n* Copyright (C) 1995 Association of Universities for Research in Astronomy Inc.\n*-\n\n IMPLICIT NONE\n\n INTEGER N\n DOUBLE PRECISION A(N,N),Y(N),D\n INTEGER JF\n INTEGER IW(N)\n\n DOUBLE PRECISION SFA\n PARAMETER (SFA=1D-20)\n\n INTEGER K,IMX,I,J,NP1MK,KI\n DOUBLE PRECISION AMX,T,AKK,YK,AIK\n\n\n JF=0\n D=1D0\n DO K=1,N\n AMX=DABS(A(K,K))\n IMX=K\n IF (K.NE.N) THEN\n DO I=K+1,N\n T=DABS(A(I,K))\n IF (T.GT.AMX) THEN\n AMX=T\n IMX=I\n END IF\n END DO\n END IF\n IF (AMX.LT.SFA) THEN\n JF=-1\n ELSE\n IF (IMX.NE.K) THEN\n DO J=1,N\n T=A(K,J)\n A(K,J)=A(IMX,J)\n A(IMX,J)=T\n END DO\n T=Y(K)\n Y(K)=Y(IMX)\n Y(IMX)=T\n D=-D\n END IF\n IW(K)=IMX\n AKK=A(K,K)\n D=D*AKK\n IF (DABS(D).LT.SFA) THEN\n JF=-1\n ELSE\n AKK=1D0/AKK\n A(K,K)=AKK\n DO J=1,N\n IF (J.NE.K) A(K,J)=A(K,J)*AKK\n END DO\n YK=Y(K)*AKK\n Y(K)=YK\n DO I=1,N\n AIK=A(I,K)\n IF (I.NE.K) THEN\n DO J=1,N\n IF (J.NE.K) A(I,J)=A(I,J)-AIK*A(K,J)\n END DO\n Y(I)=Y(I)-AIK*YK\n END IF\n END DO\n DO I=1,N\n IF (I.NE.K) A(I,K)=-A(I,K)*AKK\n END DO\n END IF\n END IF\n END DO\n IF (JF.NE.0) THEN\n D=0D0\n ELSE\n DO K=1,N\n NP1MK=N+1-K\n KI=IW(NP1MK)\n IF (NP1MK.NE.KI) THEN\n DO I=1,N\n T=A(I,NP1MK)\n A(I,NP1MK)=A(I,KI)\n A(I,KI)=T\n END DO\n END IF\n END DO\n END IF\n\n END\n", "meta": {"hexsha": "9209b0629c759a784a776131782815a60f296b8b", "size": 4384, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iraf.v2161/math/slalib/dmat.f", "max_stars_repo_name": "ysBach/irafdocgen", "max_stars_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:19:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T16:48:42.000Z", "max_issues_repo_path": "math/slalib/dmat.f", "max_issues_repo_name": "kirxkirx/iraf", "max_issues_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-30T13:48:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-02T19:40:25.000Z", "max_forks_repo_path": "math/slalib/dmat.f", "max_forks_repo_name": "kirxkirx/iraf", "max_forks_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.572327044, "max_line_length": 80, "alphanum_fraction": 0.463959854, "num_tokens": 1240, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797003640645, "lm_q2_score": 0.757794360334681, "lm_q1q2_score": 0.6904868381873325}} {"text": "!> \\file mo_standard_score.f90\n\n!> \\brief Routines for calculating the normalization (anomaly)/standard score/z score and the \n!> deseasonalized (standard score on monthly basis) values of a time series.\n\n!> \\details In environmental research often the centralization and standardization are estimated\n!> for characterizing the dynamics of a signal.\n\n!> \\author Matthias Zink\n!> \\date May 2015\n\nMODULE mo_standard_score\n\n ! This module contains routines for the masked calculation of\n ! the standard_score of a time series (centralized and standardized time series).\n\n ! Written May 2015, Matthias Zink\n\n ! License\n ! -------\n ! This file is part of the JAMS Fortran package, distributed under the MIT License.\n !\n ! Copyright (c) 2015 Matthias Zink\n !\n ! Permission is hereby granted, free of charge, to any person obtaining a copy\n ! of this software and associated documentation files (the \"Software\"), to deal\n ! in the Software without restriction, including without limitation the rights\n ! to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n ! copies of the Software, and to permit persons to whom the Software is\n ! furnished to do so, subject to the following conditions:\n !\n ! The above copyright notice and this permission notice shall be included in all\n ! copies or substantial portions of the Software.\n !\n ! THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n ! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n ! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n ! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n ! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n ! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n ! SOFTWARE.\n\n USE mo_kind, ONLY: i4, sp, dp\n\n IMPLICIT NONE\n\n PUBLIC :: standard_score ! standard score of a population\n PUBLIC :: classified_standard_score ! standard score for classes of a population (e.g. classes=months)\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! standard_score\n\n ! PURPOSE\n !> \\brief Calculates the standard score / normalization (anomaly) / z-score.\n !> \\details In statistics, the standard score is the (signed) number of standard deviations an observation\n !> or datum is above the mean. Thus, a positive standard score indicates a datum above the mean, \n !> while a negative standard score indicates a datum below the mean.\n !> It is a dimensionless quantity obtained by subtracting the population mean from \n !> an individual raw score and then dividing the difference by the population standard deviation.\n !> This conversion process is called standardizing or normalizing (however, \"normalizing\" can\n !> refer to many types of ratios).\\n\n !> Standard scores are also called z-values, z-scores, normal scores, and standardized variables; the use\n !> of \"Z\" is because the normal distribution is also known as the \"Z distribution\". They are most frequently\n !> used to compare a sample to a standard normal deviate, though they can be defined without assumptions of\n !> normality (Wikipedia, May 2015).\n !>\n !> \\f[ standard\\_score = \\frac{x - \\mu_x}{\\sigma_x} \\f]\n !> where \\f$ \\mu_x \\f$ is the mean of a population \\f$ x \\f$ and \\f$ \\sigma_x \\f$ its standard deviation.\n !>\n !> If an optional mask is given, the calculations are over those locations that correspond\n !> to true values in the mask.\n\n ! CALLING SEQUENCE\n ! out = standard_score(data, mask=mask)\n \n ! INDENT(IN)\n !> \\param[in] \"real(sp/dp), dimension(:) :: data\" data to calculate the standard score for\n\n ! INDENT(INOUT)\n ! None\n\n ! INDENT(OUT)\n ! None\n\n ! INDENT(IN), OPTIONAL\n !> \\param[in] \"logical, dimension(:),optinal :: mask\" indication which cells to use for calculation\n !> If present, only those locations in mask having true values in mask are evaluated.\n\n ! INDENT(INOUT), OPTIONAL\n ! None\n\n ! INDENT(OUT), OPTIONAL\n ! None\n \n ! RETURN\n !> \\return real(sp/dp) :: standard_score — standard score / normalization (anomaly) / z-score\n \n ! RESTRICTIONS\n ! Input values must be floating points.\n\n ! EXAMPLE\n ! data = (/ 1., 2, 3., -999., 5., 6. /)\n ! out = standard_score(data, mask=(data >= 0.))\n ! -> see also example in test directory\n \n ! LITERATURE\n !> \\note Richard J. Larsen and Morris L. Marx (2000) An Introduction to Mathematical Statistics and Its\n !> Applications, Third Edition, ISBN 0-13-922303-7. p. 282. \n\n ! HISTORY\n !> \\author Matthias Zink\n !> \\date May 2015\n\n INTERFACE standard_score\n MODULE PROCEDURE standard_score_sp, standard_score_dp\n END INTERFACE standard_score\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! classified_standard_score\n\n ! PURPOSE\n !> \\brief Calculates the classified standard score (e.g. classes are months).\n !> \\details In statistics, the standard score is the (signed) number of standard deviations an observation\n !> or datum is above the mean. Thus, a positive standard score indicates a datum above the mean, \n !> while a negative standard score indicates a datum below the mean.\n !> It is a dimensionless quantity obtained by subtracting the population mean from \n !> an individual raw score and then dividing the difference by the population standard deviation.\n !> This conversion process is called standardizing or normalizing (however, \"normalizing\" can\n !> refer to many types of ratios).\\n\n !> Standard scores are also called z-values, z-scores, normal scores, and standardized variables; the use\n !> of \"Z\" is because the normal distribution is also known as the \"Z distribution\". They are most frequently\n !> used to compare a sample to a standard normal deviate, though they can be defined without assumptions of\n !> normality (Wikipedia, May 2015).\\n\n !> In this particular case the standard score is calculated for means and standard deviations derived from\n !> classes of the time series. Such classes could be for example months. Thus, the output would be a\n !> deseasonalized time series. \n !>\n !> \\f[ classified\\_standard\\_score = \\frac{x_i - \\mu_{c_{x_i}}}{\\sigma_{c_{x_i}}} \\f]\n !> where \\f$ x_i \\f$ is an element of class \\f$ c_{x_i} \\f$. \\f$ x \\f$ is a population, \\f$ \\mu_{c_{x_i}} \\f$\n !> is the mean of all members of a class \\f$ c_{x_i} \\f$ and \\f$ \\sigma_{c_{x_i}} \\f$ its standard deviation.\n !>\n !> If an optinal mask is given, the calculations are over those locations that correspond to true values in the mask.\n\n ! CALLING SEQUENCE\n ! out = classified_standard_score(data, mask=mask)\n \n ! INDENT(IN)\n !> \\param[in] \"integer, dimension(:) :: classes\" classes to categorize data (e.g. months)\n !> \\param[in] \"real(sp/dp), dimension(:) :: data\" data to calculate the standard score for\n\n \n ! INDENT(INOUT)\n ! None\n\n ! INDENT(OUT)\n ! None\n\n ! INDENT(IN), OPTIONAL\n !> \\param[in] \"logical, dimension(:), optional :: mask\" indication which cells to use for calculation\n !> If present, only those locations in mask having true values in mask are evaluated.\n\n ! INDENT(INOUT), OPTIONAL\n ! None\n\n ! INDENT(OUT), OPTIONAL\n ! None\n \n ! RETURN\n !> \\return real(sp/dp) :: classified_standard_score — classified standard score (e.g. deseasonalized\n !> time series)\n \n ! RESTRICTIONS\n ! Input values must be floating points.\n\n ! EXAMPLE\n ! data = (/ 1., 2, 3., -999., 5., 6. /)\n ! classes = (/ 1, 1, 1, 2, 2 , 2 /)\n ! out = classified_standard_score(data, classes, mask=(data >= 0.))\n ! -> see also example in test directory\n \n ! LITERATURE\n ! None\n\n ! HISTORY\n !> \\author Matthias Zink\n !> \\date May 2015\n\n INTERFACE classified_standard_score\n MODULE PROCEDURE classified_standard_score_sp, classified_standard_score_dp\n END INTERFACE classified_standard_score\n \n ! ------------------------------------------------------------------\n\n PRIVATE\n\n ! ------------------------------------------------------------------\n\nCONTAINS\n\n ! ------------------------------------------------------------------\n\n FUNCTION standard_score_sp(data, mask)\n\n use mo_moment, only: average, stddev\n \n implicit none\n \n real(sp), dimension(:), intent(in) :: data ! data arrau input\n logical, dimension(:), optional, intent(in) :: mask ! optional input\n real(sp), dimension(size(data, dim=1)) :: standard_score_sp\n\n ! local\n logical, dimension(size(data, dim=1)) :: maske\n \n ! check if optional mask matches shape of data\n if (present(mask)) then\n if (size(mask) .ne. size(data)) stop '***Error: standard_score_sp: size(mask) .ne. size(data)'\n maske = mask\n else\n maske(:) = .true.\n endif\n\n ! check if enough values (>1) are available\n if (count(maske) .LE. 2) stop '***Error: standard_score_sp: less than 2 elements avaiable'\n \n standard_score_sp = ( data(:) - average(data, mask=maske) ) / stddev(data, mask=maske, ddof=1_i4)\n\n END FUNCTION standard_score_sp\n\n \n FUNCTION standard_score_dp(data, mask)\n\n use mo_moment, only: average, stddev\n \n implicit none\n \n real(dp), dimension(:), intent(in) :: data ! data arrau input\n logical, dimension(:), optional, intent(in) :: mask ! optional input\n real(dp), dimension(size(data, dim=1)) :: standard_score_dp\n\n ! local\n logical, dimension(size(data, dim=1)) :: maske\n \n ! check if optional mask matches shape of data\n if (present(mask)) then\n if (size(mask) .ne. size(data)) stop '***Error: standard_score_dp: size(mask) .ne. size(data)'\n maske = mask\n else\n maske(:) = .true.\n endif\n\n ! check if enough values (>1) are available\n if (count(maske) .LE. 2) stop '***Error: standard_score_dp: less than 2 elements avaiable'\n \n standard_score_dp = ( data(:) - average(data, mask=maske) ) / stddev(data, mask=maske, ddof=1_i4)\n\n END FUNCTION standard_score_dp\n\n ! ------------------------------------------------------------------\n\n FUNCTION classified_standard_score_sp(data, classes, mask)\n\n use mo_moment, only: average, stddev\n use mo_orderpack, only: unista\n \n implicit none\n \n real(sp), dimension(:), intent(in) :: data ! data array with input\n integer, dimension(:), intent(in) :: classes ! array indicateing classes\n logical, dimension(:), optional, intent(in) :: mask ! array masking elements of data\n real(sp), dimension(size(data, dim=1)) :: classified_standard_score_sp\n\n ! local\n integer(i4) :: iclass, ielem ! loop variable\n integer(i4) :: number_of_classes ! number of unique classes in vector\n ! classes\n integer(i4), dimension(size(data, dim=1)) :: unique_classes ! vector of uniqe classes\n real(sp) :: class_mean ! mean of class\n real(sp) :: class_stddev ! standard deviation of class\n logical, dimension(size(data, dim=1)) :: maske ! data mask\n logical, dimension(size(data, dim=1)) :: mask_class_maske ! combined mask for current class and\n ! maske\n\n ! check if optional mask matches shape of data\n if (present(mask)) then\n if (size(mask) .ne. size(data)) stop '***Error: classified_standard_score_sp: size(mask) .ne. size(data)'\n maske = mask\n else\n maske(:) = .true.\n endif\n\n ! check if enough values (>1) are available\n if (count(maske) .LE. 2) stop '***Error: classified_standard_score_sp: less than 2 elements available'\n\n ! initialization\n classified_standard_score_sp = 0.0_sp\n \n ! write classes to new array for getting unique array elements\n unique_classes = classes\n call unista(unique_classes, number_of_classes) ! (unique arry elements in the 1:number_of_classes \n ! ! indexes of array unique_classes)\n \n ! loop over classes\n do iclass = 1, number_of_classes\n ! calculate mean and standard deviation for class\n mask_class_maske = (maske .AND. (classes==unique_classes(iclass)))\n class_mean = average(data, mask=mask_class_maske)\n class_stddev = stddev(data, mask=mask_class_maske, ddof=1_i4)\n ! loop over array elements\n do ielem = 1, size(data, dim=1)\n if (.NOT. mask_class_maske(ielem)) cycle ! skip masked values and other classes\n classified_standard_score_sp(ielem) = ( data(ielem) - class_mean ) / class_stddev\n end do\n end do\n \n END FUNCTION classified_standard_score_sp\n\n \n FUNCTION classified_standard_score_dp(data, classes, mask)\n\n use mo_moment, only: average, stddev\n use mo_orderpack, only: unista\n \n implicit none\n \n real(dp), dimension(:), intent(in) :: data ! data array with input\n integer, dimension(:), intent(in) :: classes ! array indicateing classes\n logical, dimension(:), optional, intent(in) :: mask ! array masking elements of data\n real(dp), dimension(size(data, dim=1)) :: classified_standard_score_dp\n\n ! local\n integer(i4) :: iclass, ielem ! loop variable\n integer(i4) :: number_of_classes ! number of unique classes in vector classes\n integer(i4), dimension(size(data, dim=1)) :: unique_classes ! vector of uniqe classes\n real(dp) :: class_mean ! mean of class\n real(dp) :: class_stddev ! standard deviation of class\n logical, dimension(size(data, dim=1)) :: maske ! data mask\n logical, dimension(size(data, dim=1)) :: mask_class_maske ! combined mask for current class and maske\n\n ! check if optional mask matches shape of data\n if (present(mask)) then\n if (size(mask) .ne. size(data)) stop '***Error: classified_standard_score_dp: size(mask) .ne. size(data)'\n maske = mask\n else\n maske(:) = .true.\n endif\n\n ! check if enough values (>1) are available\n if (count(maske) .LE. 2) stop '***Error: classified_standard_score_dp: less than 2 elements avaiable'\n\n ! initialization\n classified_standard_score_dp = 0.0_dp\n \n ! write classes to new array for getting unique array elements\n unique_classes = classes\n call unista(unique_classes, number_of_classes) ! (unique arry elements in the 1:number_of_classes \n ! ! indexes of array unique_classes)\n \n ! loop over classes\n do iclass = 1, number_of_classes\n ! calculate mean and standard deviation for class\n mask_class_maske = (maske .AND. (classes==unique_classes(iclass)))\n class_mean = average(data, mask=mask_class_maske)\n class_stddev = stddev(data, mask=mask_class_maske, ddof=1_i4)\n ! loop over array elements\n do ielem = 1, size(data, dim=1)\n if (.NOT. mask_class_maske(ielem)) cycle ! skip masked values and other classes\n classified_standard_score_dp(ielem) = ( data(ielem) - class_mean ) / class_stddev\n end do\n end do\n \n END FUNCTION classified_standard_score_dp\n \nEND MODULE mo_standard_score\n", "meta": {"hexsha": "deb497660d1203d4777245ab72917edc68dc0353", "size": 16471, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mo_standard_score.f90", "max_stars_repo_name": "mcuntz/jams_fortran", "max_stars_repo_head_hexsha": "a1dcab78eda21f930aa6c8c3633598a522f01659", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2020-02-28T00:14:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-20T23:32:41.000Z", "max_issues_repo_path": "mo_standard_score.f90", "max_issues_repo_name": "mcuntz/jams_fortran", "max_issues_repo_head_hexsha": "a1dcab78eda21f930aa6c8c3633598a522f01659", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-05-09T15:33:11.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-28T16:16:09.000Z", "max_forks_repo_path": "mo_standard_score.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": 43.4591029024, "max_line_length": 129, "alphanum_fraction": 0.606581264, "num_tokens": 3974, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972818382005, "lm_q2_score": 0.7931059536292271, "lm_q1q2_score": 0.690475887439299}} {"text": "! Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.\n! See https://llvm.org/LICENSE.txt for license information.\n! SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception\n\n! Test assignment of array-valued intrinsics with F2003 allocatable\n! assignment semantics. Compile with -Mallocatable=03.\n! Like al21.f90 but source array is allocatable too.\nprogram al22\n implicit none\n logical :: fail = .false.\n integer :: i\n real, allocatable :: a1(:)\n real :: a2(4,4)\n a1 = [ (i, i=1, 16) ]\n a2 = reshape(a1, [4, 4])\n\n call test_minval()\n call test_product()\n call test_sum()\n call test_cshift()\n call test_eoshift()\n if (.not. fail) write(*,'(\"PASS\")')\n\ncontains\n\n subroutine test_minval()\n real, allocatable :: b1(:)\n b1 = minval(a2, 1)\n call check('minval', b1, [1.0, 5.0, 9.0, 13.0])\n end subroutine\n\n subroutine test_cshift()\n real, allocatable :: b1(:)\n b1 = cshift(a1, 4)\n call check('cshift', b1, [ &\n 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, &\n 13.0, 14.0, 15.0, 16.0, 1.0, 2.0, 3.0, 4.0 &\n ])\n end subroutine\n\n subroutine test_product()\n real, allocatable :: b1(:)\n b1 = product(a2, 1)\n call check('product', b1, [24.0, 1680.0, 11880.0, 43680.0])\n end subroutine\n\n subroutine test_sum()\n real, allocatable :: b1(:)\n b1 = sum(a2, 1)\n call check('sum', b1, [10.0, 26.0, 42.0, 58.0])\n end subroutine\n\n subroutine test_eoshift()\n real, allocatable :: b1(:)\n b1 = eoshift(a1, 4)\n call check('cshift', b1, [ &\n 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, &\n 13.0, 14.0, 15.0, 16.0, 0.0, 0.0, 0.0, 0.0 &\n ])\n end subroutine\n\n ! Check that actual is the same as expected; report failure if not.\n subroutine check(label, actual, expected)\n character(len=*) :: label\n real :: actual(:)\n real :: expected(:)\n if (size(actual) /= size(expected)) then\n else if (any(actual /= expected)) then\n else\n return\n end if\n write(*,'(\"FAIL: \",a)') label\n print *,\" expected:\", expected\n print *,\" actual: \", actual\n fail = .true.\n end subroutine\n\nend\n", "meta": {"hexsha": "3c541512c259a040be38186c61626e16ede1c833", "size": 2113, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/f90_correct/src/al22.f90", "max_stars_repo_name": "abrahamtovarmob/flang", "max_stars_repo_head_hexsha": "bcd84b29df046b6d6574f0bfa34ea5059092615a", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 716, "max_stars_repo_stars_event_min_datetime": "2017-05-17T17:58:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T11:20:58.000Z", "max_issues_repo_path": "test/f90_correct/src/al22.f90", "max_issues_repo_name": "abrahamtovarmob/flang", "max_issues_repo_head_hexsha": "bcd84b29df046b6d6574f0bfa34ea5059092615a", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 794, "max_issues_repo_issues_event_min_datetime": "2017-05-18T19:27:40.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T23:22:11.000Z", "max_forks_repo_path": "test/f90_correct/src/al22.f90", "max_forks_repo_name": "abrahamtovarmob/flang", "max_forks_repo_head_hexsha": "bcd84b29df046b6d6574f0bfa34ea5059092615a", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 157, "max_forks_repo_forks_event_min_datetime": "2017-05-17T18:50:33.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T07:06:45.000Z", "avg_line_length": 26.746835443, "max_line_length": 79, "alphanum_fraction": 0.6010411737, "num_tokens": 782, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972818382005, "lm_q2_score": 0.7931059511841119, "lm_q1q2_score": 0.6904758853105883}} {"text": "!*==crotg.f90 processed by SPAG 7.51RB at 20:37 on 3 Mar 2022\n!> \\brief \\b CROTG\n!\n! =========== DOCUMENTATION ===========\n!\n! Online html documentation available at\n! http://www.netlib.org/lapack/explore-html/\n!\n! Definition:\n! ===========\n!\n! SUBROUTINE CROTG(CA,CB,C,S)\n!\n! .. Scalar Arguments ..\n! COMPLEX CA,CB,S\n! REAL C\n! ..\n!\n!\n!> \\par Purpose:\n! =============\n!>\n!> \\verbatim\n!>\n!> CROTG determines a complex Givens rotation.\n!> \\endverbatim\n!\n! Arguments:\n! ==========\n!\n!> \\param[in,out] CA\n!> \\verbatim\n!> CA is COMPLEX\n!> \\endverbatim\n!>\n!> \\param[in] CB\n!> \\verbatim\n!> CB is COMPLEX\n!> \\endverbatim\n!>\n!> \\param[out] C\n!> \\verbatim\n!> C is REAL\n!> \\endverbatim\n!>\n!> \\param[out] S\n!> \\verbatim\n!> S is COMPLEX\n!> \\endverbatim\n!\n! Authors:\n! ========\n!\n!> \\author Univ. of Tennessee\n!> \\author Univ. of California Berkeley\n!> \\author Univ. of Colorado Denver\n!> \\author NAG Ltd.\n!\n!> \\date November 2017\n!\n!> \\ingroup complex_blas_level1\n!\n! =====================================================================\n SUBROUTINE CROTG(Ca,Cb,C,S)\n IMPLICIT NONE\n!*--CROTG66\n!\n! -- Reference BLAS level1 routine (version 3.8.0) --\n! -- Reference BLAS is a software package provided by Univ. of Tennessee, --\n! -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n! November 2017\n!\n! .. Scalar Arguments ..\n COMPLEX Ca , Cb , S\n REAL C\n! ..\n!\n! =====================================================================\n!\n! .. Local Scalars ..\n COMPLEX alpha\n REAL norm , scale\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC CABS , CONJG , SQRT\n! ..\n IF ( CABS(Ca)==0. ) THEN\n C = 0.\n S = (1.,0.)\n Ca = Cb\n ELSE\n scale = CABS(Ca) + CABS(Cb)\n norm = scale*SQRT((CABS(Ca/scale))**2+(CABS(Cb/scale))**2)\n alpha = Ca/CABS(Ca)\n C = CABS(Ca)/norm\n S = alpha*CONJG(Cb)/norm\n Ca = alpha*norm\n ENDIF\n END SUBROUTINE CROTG\n", "meta": {"hexsha": "25cab52d0242591cf192a27835fd04a521d8e682", "size": 2082, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/blas/crotg.f90", "max_stars_repo_name": "urbanjost/spag_lapack", "max_stars_repo_head_hexsha": "1b082638c0ff5feb1a295a3aa4624c538d14847c", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2022-03-04T13:15:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-04T17:40:26.000Z", "max_issues_repo_path": "src/blas/crotg.f90", "max_issues_repo_name": "urbanjost/spag_lapack", "max_issues_repo_head_hexsha": "1b082638c0ff5feb1a295a3aa4624c538d14847c", "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": "src/blas/crotg.f90", "max_forks_repo_name": "urbanjost/spag_lapack", "max_forks_repo_head_hexsha": "1b082638c0ff5feb1a295a3aa4624c538d14847c", "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": 20.82, "max_line_length": 80, "alphanum_fraction": 0.492795389, "num_tokens": 656, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972784807408, "lm_q2_score": 0.7931059536292271, "lm_q1q2_score": 0.6904758847764777}} {"text": "!*****************************************************************************************\n!>\n! Units test for 1d-6d tensor product b-spline interpolation.\n\n program bspline_test\n\n use bspline_module\n use bspline_kinds_module, only: wp, ip\n\n implicit none\n\n integer(ip),parameter :: nx = 50 !! number of points in x\n integer(ip),parameter :: ny = 50 !! number of points in y\n integer(ip),parameter :: nz = 50 !! number of points in z\n integer(ip),parameter :: nx_new = 256 !! nbr of interpolated x-points\n integer(ip),parameter :: ny_new = 256 !! nbr of interpolated y-points\n integer(ip),parameter :: nz_new = 256 !! nbr of interpolated z-points\n integer(ip),parameter :: kx = 4 !! order in x\n integer(ip),parameter :: ky = 4 !! order in y\n integer(ip),parameter :: kz = 4 !! order in z\n\n integer(ip),parameter :: iknot = 0 !! automatically select the knots\n\n real(wp), parameter :: x_min=0._wp, x_max=10._wp !! range og x-grid\n real(wp), parameter :: y_min=0._wp, y_max=10._wp !! range og y-grid\n real(wp), parameter :: z_min=0._wp, z_max=10._wp !! range og z-grid\n\n real(wp) :: x(nx),y(ny),z(nz),tx(nx+kx),ty(ny+ky),tz(nz+kz)\n real(wp) :: fcn_3d(nx,ny,nz)\n\n real(wp),dimension(ky,kz) :: w1_3d\n real(wp),dimension(kz) :: w2_3d\n real(wp),dimension(3*max(kx,ky,kz)) :: w3_3d\n\n real(wp) :: tol,dx,dy,dz,dx_new,dy_new,dz_new,int_3d,int_3d_new, &\n sum_x,sum_y,f_2d\n real(wp),dimension(6) :: val,tru,err,errmax\n logical :: fail\n integer(ip) :: i,j,k,l,m,n,idx,idy,idz,idq,idr,ids\n integer(ip),dimension(6) :: iflag\n integer(ip) :: inbvx,inbvy,inbvz,inbvq,inbvr,inbvs\n integer(ip) :: iloy,iloz,iloq,ilor,ilos\n integer :: count_rate, count_max,count,t_start,t_final\n real :: time_s\n\n real(wp), allocatable :: xout(:),yout(:),zout(:),fout(:,:,:)\n\n call system_clock(count_max=count_max, count_rate=count_rate)\n\n call system_clock(t_start)\n\n print*, \"\"\n print*, \"-----------3D-Bspline Interpolation--------------\"\n print*, \"\"\n\n fail = .false.\n tol = 100 * epsilon(1.0_wp)\n idx = 0\n idy = 0\n idz = 0\n allocate(xout(nx_new)); allocate(yout(ny_new));\n allocate(zout(nz_new)); allocate(fout(nx_new,ny_new,nz_new))\n\n dx = (x_max-x_min)/real(nx-1,wp); dy = (y_max-y_min)/real(ny-1,wp)\n dz = (z_max-z_min)/real(nz-1,wp)\n!x-grid\n do i=1,nx\n x(i) = x_min + real(i-1,wp)*dx\n end do\n!y-grid\n do j=1,ny\n y(j) = y_min + real(j-1,wp)*dy\n enddo\n!z-grid\n do k=1,nz\n z(k) = z_min + real(k-1,wp)*dz\n enddo\n!2d function to be interpolated\n do i=1,nx\n do j=1,ny\n do k=1,nz\n fcn_3d(i,j,k) = f3(x(i),y(j),z(k))\n enddo\n enddo\n end do\n\n!defining the interpolated 3D-grid\n dx_new = (x_max-x_min)/real(nx_new-1,wp); dy_new = (y_max-y_min)/real(ny_new-1,wp)\n dz_new = (z_max-z_min)/real(nz_new-1,wp)\n do i=1,nx_new\n xout(i) = x_min + real(i-1,wp)*dx_new\n enddo\n do j=1,ny_new\n yout(j) = y_min + real(j-1,wp)*dy_new\n enddo\n do k=1,nz_new\n zout(k) = z_min + real(k-1,wp)*dz_new\n enddo\n print*,\"--Grid parameter----\"\n print*, \"--nbr of point:nx, nx_new\",nx, nx_new\n print*, \"--nbr of point:ny, ny_new\",ny, ny_new\n print*, \"--nbr of point:nz, nz_new\",nz, nz_new\n print*, \"--spatial step:dx, dx_new\", dx, dx_new\n print*, \"--spatial step:dy, dy_new\", dy, dy_new\n print*, \"--spatial step:dz, dz_new\", dz, dz_new\n print*,\"--xmax,ymax,zmax\",x_max,y_max,z_max\n print*,\"\"\n \n !have to set these before the first evaluate call:\n inbvx = 1\n inbvy = 1\n inbvz = 1\n ! initialize\n\n call db3ink(x,nx,y,ny,z,nz,fcn_3d,kx,ky,kz,iknot,tx,ty,tz,fcn_3d,iflag(3))\n\n if (any(iflag/=0)) then\n do i=2,2\n if (iflag(i)/=0) then\n write(*,*) 'Error initializing ',i,'D spline: '//get_status_message(iflag(i))\n end if\n end do\n end if\n\n ! compute max error at interpolation points\n\n errmax = 0.0_wp\n do i=1,size(xout)\n do j=1,size(yout)\n do k=1,size(zout)\n call db3val(xout(i),yout(j),zout(k),idx,idy,idz,&\n tx,ty,tz,nx,ny,nz,kx,ky,kz,fcn_3d,val(3),iflag(3),&\n inbvx,inbvy,inbvz,iloy,iloz,&\n w1_3d,w2_3d,w3_3d)\n\n tru(3) = f3(x(i),y(j),z(k))\n err(3) = abs(tru(3)-val(3))\n errmax(3) = max(err(3),errmax(3))\n \n fout(i,j,k) = val(3)\n enddo \n enddo\n end do\n\n ! check max error against tolerance\n do i=3,3\n write(*,*) i,'D: max error:', errmax(i)\n! if (errmax(i) >= tol) then\n! write(*,*) ' ** test failed ** '\n! else\n! write(*,*) ' ** test passed ** '\n! end if\n write(*,*) ''\n end do\n\n!Evaluate the integral\n!without interpolation\n sum_y=0._wp\n do j=1,ny\n sum_x=0._wp\n do k=1,nz\n sum_x = sum_x + sum(fcn_3d(1:nx,j,k))\n enddo\n sum_y = sum_y + sum_x\n enddo\n int_3d = sum_y*dx*dy*dz\n\n!with interpolation\n sum_y=0._wp\n do j=1,ny_new\n sum_x = 0._wp\n do k=1,nz_new\n sum_x = sum_x + sum(fout(1:nx_new,j,k))\n enddo\n sum_y = sum_y + sum_x\n enddo\n int_3d_new = sum_y*dx_new*dy_new*dz_new\n\n print*,\"--3D-Integral without interpolation\", int_3d\n print*,\"--3D-Integral with interpolation\", int_3d_new\n\n call system_clock(t_final)\n\n time_s = real(t_final - t_start)/real(count_rate)\n print*,\"\"\n print*, '--Time it takes (s)', time_s\n\n!print out the output file\n! open(100,file='2Dxy-TestBspline-Without-Interpolation.dat')\n! open(101,file='2Dxy-TestBspline-With-Interpolation.dat')\n!prinout data\n!data without interpolation\n! do i=1,nx\n! do j=1,ny\n! f_2d = sum(fcn_3d(i,j,1:nz))*dz\n! write(100,*)x(i),y(j),f_2d\n! enddo\n! write(100,*)\n! enddo\n!data with interpolation\n! do i=1,size(xout)\n! do j=1,size(yout)\n! f_2d = sum(fout(i,j,1:nz_new))\n! write(101,*)xout(i),yout(j),f_2d\n! enddo\n! write(101,*)\n! enddo\n\n contains\n\n real(wp) function f1(x) !! 1d test function\n implicit none\n real(wp) :: x\n !f1 = 0.5_wp * (x*exp(-x) + sin(x) )\n f1 = sin(x)\n end function f1\n\n real(wp) function f2(x,y) !! 2d test function\n implicit none\n real(wp) x,y,piov2\n !piov2 = 2.0_wp * atan(1.0_wp)\n !f2 = 0.5_wp * (y*exp(-x) + sin(piov2*y) )\n f2 = 1._wp*sin(sqrt((x*x + y*y)*1._wp))\n end function f2\n\n real(wp) function f3 (x,y,z) !! 3d test function\n implicit none\n real(wp) x,y,z,piov2\n !piov2 = 2.0_wp*atan(1.0_wp)\n !f3 = 0.5_wp*( y*exp(-x) + z*sin(piov2*y) )\n f3 = 1._wp*sin(sqrt(x*x + y*y + z*z))\n end function f3\n\n real(wp) function f4 (x,y,z,q) !! 4d test function\n implicit none\n real(wp) x,y,z,q,piov2\n piov2 = 2.0_wp*atan(1.0_wp)\n f4 = 0.5_wp*( y*exp(-x) + z*sin(piov2*y) + q )\n end function f4\n\n real(wp) function f5 (x,y,z,q,r) !! 5d test function\n implicit none\n real(wp) x,y,z,q,r,piov2\n piov2 = 2.0_wp*atan(1.0_wp)\n f5 = 0.5_wp*( y*exp(-x) + z*sin(piov2*y) + q*r )\n end function f5\n\n real(wp) function f6 (x,y,z,q,r,s) !! 6d test function\n implicit none\n real(wp) x,y,z,q,r,s,piov2\n piov2 = 2.0_wp*atan(1.0_wp)\n f6 = 0.5_wp*( y*exp(-x) + z*sin(piov2*y) + q*r + 2.0_wp*s )\n end function f6\n\n end program bspline_test\n", "meta": {"hexsha": "5966d180b2b8f8a531499377a1d62925d997b094", "size": 7741, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Bspline-3D/bspline_test.f90", "max_stars_repo_name": "HichamAgueny/BsplineInterpolation", "max_stars_repo_head_hexsha": "1df4c882203788d5b06e6b10aec0f6b8b4435918", "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": "Bspline-3D/bspline_test.f90", "max_issues_repo_name": "HichamAgueny/BsplineInterpolation", "max_issues_repo_head_hexsha": "1df4c882203788d5b06e6b10aec0f6b8b4435918", "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": "Bspline-3D/bspline_test.f90", "max_forks_repo_name": "HichamAgueny/BsplineInterpolation", "max_forks_repo_head_hexsha": "1df4c882203788d5b06e6b10aec0f6b8b4435918", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.23828125, "max_line_length": 93, "alphanum_fraction": 0.5408861904, "num_tokens": 2718, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232809, "lm_q2_score": 0.7931059511841119, "lm_q1q2_score": 0.6904758799849456}} {"text": "c\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc . .\nc . copyright (c) 1998 by UCAR .\nc . .\nc . University Corporation for Atmospheric Research .\nc . .\nc . all rights reserved .\nc . .\nc . .\nc . SPHEREPACK .\nc . .\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc\nc\nc ... file tvshifte.f is a test program illustrating the\nc use of subroutine vshifte (see documentation for vshifte)\nc\nc ... required files off spherepack3.0\nc\nc hrfft.f, vshifte.f\nc\nc Let the analytic vector field (u,v) in geophysical coordinates be\nc given by\nc\nc u = -exp(x)*sin(p) + exp(-z)*cos(p) + exp(y)*sin(t)*sin(p)\nc\nc v = exp(y)*cos(p) + exp(z)*cos(t) - exp(x)*sin(t)*cos(p)\nc\nc where t is the latitude coordinate, p is the longitude coordinate,\nc and x=cos(t)*cos(p),y=cos(t)*sin(p),z=sin(t) are the cartesian coordinates\nc restricted to the sphere.\n\nc The \"offset\" vector field (uoff,voff) is set equal to (u,v).\nc This is transferred to the \"regular\" grid in (ureg,vreg). (ureg,vreg)\nc is then compared with (u,v) on the regular grid. Finally (ureg,vreg)\nc is transferred back to (uoff,voff) which is again compared with (u,v).\nc The least squares error after each transformation with vshifte\nc is computed and printed. Results from running the program on\nc a 2.5 degree equally spaced regular and offset grid is given.\nc Output from runs on separate platforms with 32 bit and 64 bit\nc floating point arithmetic is listed.\nc\nC *********************************************\nC OUTPUT\nC *********************************************\nc\nc vshifte arguments\nc ioff = 0 nlon = 144 nlat = 72\nc lsave = 608 lwork = 21024\nc ier = 0\nc least squares error\nC *** 32 BIT ARITHMETIC\nc err2u = 0.377E-06 err2v = 0.328E-06\nC *** 64 BIT ARITHMETIC\nc err2u = 0.777E-13 err2v = 0.659E-13\n\nc vshifte arguments\nc ioff = 1 nlon = 144 nlat = 72\nc lsave = 608 lwork = 21024\nc ier = 0\nc least squares error\nC *** 32 BIT ARITHMETIC\nc err2u = 0.557E-06 err2v = 0.434E-06\nC *** 64 BIT AIRTHMETIC\nc err2u = 0.148E-12 err2v = 0.118E-12\nc\nC *********************************************\nC END OF OUTPUT (CODE FOLLOWS)\nC *********************************************\nc\n program testvshifte\n implicit none\n integer nnlon,nnlat,nnlatp1,nnlat2,llsave,llwork\nc\nc set equally spaced grid sizes in nnlat,nnlon\nc\n parameter(nnlon=144,nnlat=72)\nc\nc set parameters which depend on nnlat,nnlon\nc\n parameter(nnlatp1=nnlat+1,nnlat2=nnlat+nnlat)\nc save work space\n parameter (llsave=2*(2*nnlat+nnlon)+32)\nc unsaved work space for nnlon even\n parameter (llwork = 2*nnlon*(nnlat+1))\nc unsaved work space for nnlon odd\nc parameter (llwork = nnlon*(5*nnlat+1))\n integer ioff,nlon,nlat,nlat2,j,i,lsave,lwork,ier\n real pi,dlat,dlon,dlat2,dlon2,lat,long,x,y,z,ex,ey,ez,emz\n real err2u,err2v,ue,ve,sint,sinp,cost,cosp\n real uoff(nnlon,nnlat),voff(nnlon,nnlat)\n real ureg(nnlon,nnlatp1),vreg(nnlon,nnlatp1)\n real wsave(llsave),work(llwork)\nc\nc set resolution, work space lengths, and grid increments\nc\n nlat = nnlat\n nlon = nnlon\n lsave = llsave\n nlat2 = nnlat2\n lwork = llwork\n pi = 4.0*atan(1.0)\n dlat = pi/nlat\n dlon = (pi+pi)/nlon\n dlat2 = 0.5*dlat\n dlon2 = 0.5*dlon\nc\nc set (uoff,voff) = (u,v) on offset grid\nc\n do j=1,nlon\n\tlong = dlon2+(j-1)*dlon\n\tsinp = sin(long)\n\tcosp = cos(long)\n\tdo i=1,nlat\n\t lat = -0.5*pi+dlat2+(i-1)*dlat\n\t sint = sin(lat)\n\t cost = cos(lat)\n\t x = cost*cosp\n\t y = cost*sinp\n\t z = sint\n\t ex = exp(x)\n\t ey = exp(y)\n\t ez = exp(z)\n\t emz = exp(-z)\n\t uoff(j,i) =-ex*sinp+emz*cost+ey*sint*sinp\n\t voff(j,i) = ey*cosp+ez*cost-ex*sint*cosp\n\tend do\n end do\nc\nc initialize wsav for offset to regular shift\nc\n ioff = 0\n call vshifti(ioff,nlon,nlat,lsave,wsave,ier)\nc\nc write input arguments to vshifte\nc\n write(*,100) ioff,nlon,nlat,lsave,lwork\n 100 format(' vshifte arguments',\n +/' ioff = ',i2, ' nlon = ',i3,' nlat = ',i3,\n +/' lsave = ',i5, ' lwork = ',i5)\nc\nc shift offset to regular grid\nc\n call vshifte(ioff,nlon,nlat,uoff,voff,ureg,vreg,\n + wsave,lsave,work,lwork,ier)\n write(*,200) ier\n 200 format(' ier = ',i2)\n if (ier.eq.0) then\nc\nc compute error in ureg,vreg\nc\n err2u = 0.0\n err2v = 0.0\n do j=1,nlon\n\tlong = (j-1)*dlon\n\tsinp = sin(long)\n\tcosp = cos(long)\n\tdo i=1,nlat+1\n\t lat = -0.5*pi+(i-1)*dlat\n\t sint = sin(lat)\n\t cost = cos(lat)\n\t x = cost*cosp\n\t y = cost*sinp\n\t z = sint\n\t ex = exp(x)\n\t ey = exp(y)\n\t ez = exp(z)\n\t emz = exp(-z)\n\t ue = -ex*sinp+emz*cost+ey*sint*sinp\n\t ve = ey*cosp+ez*cost-ex*sint*cosp\n\t err2u = err2u + (ureg(j,i)-ue)**2\n\t err2v = err2v + (vreg(j,i)-ve)**2\n\tend do\n end do\n err2u = sqrt(err2u/(nlon*(nlat+1)))\n err2v = sqrt(err2v/(nlon*(nlat+1)))\n write(*,300) err2u,err2v\n 300 format(' least squares error ',\n +/' err2u = ',e10.3, ' err2v = ',e10.3)\n end if\nc\nc initialize wsav for regular to offset shift\nc\n ioff = 1\n call vshifti(ioff,nlon,nlat,lsave,wsave,ier)\nc\nc transfer regular grid values in (ureg,vreg) to offset grid in (uoff,voff)\nc\n do j=1,nlon\n\tdo i=1,nlat\n\t uoff(j,i) = 0.0\n\t voff(j,i) = 0.0\n\tend do\n end do\n write(*,100) ioff,nlon,nlat,lsave,lwork\n call vshifte(ioff,nlon,nlat,uoff,voff,ureg,vreg,\n + wsave,lsave,work,lwork,ier)\n write(*,200) ier\n if (ier .eq. 0) then\nc\nc compute error in uoff,voff\nc\n err2u = 0.0\n err2v = 0.0\n do j=1,nlon\n\tlong = dlon2+(j-1)*dlon\n\tsinp = sin(long)\n\tcosp = cos(long)\n\tdo i=1,nlat\n\t lat = -0.5*pi+dlat2+(i-1)*dlat\n\t sint = sin(lat)\n\t cost = cos(lat)\n\t x = cost*cosp\n\t y = cost*sinp\n\t z = sint\n\t ex = exp(x)\n\t ey = exp(y)\n\t ez = exp(z)\n\t emz = exp(-z)\n\t ue = -ex*sinp+emz*cost+ey*sint*sinp\n\t ve = ey*cosp+ez*cost-ex*sint*cosp\n\t err2u = err2u + (uoff(j,i)-ue)**2\n\t err2v = err2v + (voff(j,i)-ve)**2\n\tend do\n end do\n err2u = sqrt(err2u/(nlon*(nlat+1)))\n err2v = sqrt(err2v/(nlon*(nlat+1)))\n write(*,300) err2u,err2v\n end if\n end\n", "meta": {"hexsha": "fbfa829cbb97e4ec320994d6979376864fb23037", "size": 6830, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/drivers/testvshifte.f", "max_stars_repo_name": "jprules321/colas", "max_stars_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/drivers/testvshifte.f", "max_issues_repo_name": "jprules321/colas", "max_issues_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/drivers/testvshifte.f", "max_forks_repo_name": "jprules321/colas", "max_forks_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.4396551724, "max_line_length": 80, "alphanum_fraction": 0.5284040996, "num_tokens": 2418, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232808, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.6904758757275243}} {"text": "module slf_deriv\n\n use iso_fortran_env, only: r64 => real64\n implicit none\n\ncontains\n\n subroutine deriv(x,yin,yout)\n real(r64), intent(in) :: x(:), yin(:)\n real(r64), intent(out) :: yout(:)\n real(r64) :: dx2\n integer :: i,n\n\n n = size(yout)\n\n if ( n .lt. 3 ) then\n write (0,*) 'n should be at least 3!'\n return\n end if\n\n do i=2,n-1\n yout(i) = (yin(i+1)-yin(i-1))/(x(i+1)-x(i-1))\n end do\n dx2 = 2 * ( yin(3) + yin(1) - 2 * yin(2) ) / ( (x(3)-x(2))**2 + (x(2)-x(1))**2 )\n yout(1) = yout(2) + (x(1)-x(2))*dx2\n dx2 = 2 * ( yin(n) + yin(n-2) - 2 * yin(n-1) ) / ( (x(n)-x(n-1))**2 + (x(n-1)-x(n-2))**2 )\n yout(n) = yout(n-1) + (x(n)-x(n-1))*dx2\n end subroutine\n\n subroutine deriv2(x,yin,yout)\n real(r64), intent(in) :: x(:), yin(:)\n real(r64), intent(out) :: yout(:)\n integer :: i,n\n n = size(yout)\n\n do i=2,n-1\n yout(i) = 2 * ( yin(i+1) + yin(i-1) - 2 * yin(i) ) / ( (x(i+1)-x(i))**2 + (x(i-1)-x(i))**2 )\n end do\n yout(1) = yout(2) + ( x(1) - x(2) )*( yout(3)-yout(2) )/( x(3)-x(2) )\n yout(n) = yout(n-1) + ( x(n) - x(n-1) )*( yout(n-1)-yout(n-2) )/( x(n-1)-x(n-2) )\n end subroutine\n\n\nend module\n", "meta": {"hexsha": "79e77553f6745511174ebabacbe43bf700e9594c", "size": 1300, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/math/deriv.f90", "max_stars_repo_name": "gronki/pydiskvert", "max_stars_repo_head_hexsha": "da9fc71acbdaf48b67a372c51481b30f30c88d29", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/math/deriv.f90", "max_issues_repo_name": "gronki/pydiskvert", "max_issues_repo_head_hexsha": "da9fc71acbdaf48b67a372c51481b30f30c88d29", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/math/deriv.f90", "max_forks_repo_name": "gronki/pydiskvert", "max_forks_repo_head_hexsha": "da9fc71acbdaf48b67a372c51481b30f30c88d29", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.8888888889, "max_line_length": 104, "alphanum_fraction": 0.4223076923, "num_tokens": 556, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934408, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.6904758735910806}} {"text": "program combinations\n\n implicit none\n integer, parameter :: m_max = 3\n integer, parameter :: n_max = 5\n integer, dimension (m_max) :: comb\n character (*), parameter :: fmt = '(i0' // repeat (', 1x, i0', m_max - 1) // ')'\n\n call gen (1)\n\ncontains\n\n recursive subroutine gen (m)\n\n implicit none\n integer, intent (in) :: m\n integer :: n\n\n if (m > m_max) then\n write (*, fmt) comb\n else\n do n = 1, n_max\n if ((m == 1) .or. (n > comb (m - 1))) then\n comb (m) = n\n call gen (m + 1)\n end if\n end do\n end if\n\n end subroutine gen\n\nend program combinations\n", "meta": {"hexsha": "b85f12fe96166a006afe52906c89ef1434659fbf", "size": 620, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Combinations/Fortran/combinations-2.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Combinations/Fortran/combinations-2.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Combinations/Fortran/combinations-2.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 18.7878787879, "max_line_length": 82, "alphanum_fraction": 0.5419354839, "num_tokens": 198, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972549785203, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.690475859750595}} {"text": "!!# FUNCTION MODULE: \nMODULE FUN_xyINTEGRALXX\n\n!!## PURPOSE\n!! Integrates the function $XX$ over a polygon in 2D.\n\n\n\n!*******************************************************************************\n!\n!! xyINTEGRALXX_Pg integrates the function X*X over a polygon in 2D.\n!\n! Discussion:\n!\n! The polygon is bounded by the points (X(1:N), Y(1:N)).\n!\n! INTEGRAL = (1/12) * sum ( 1 <= I <= N )\n! ( X(I)**3 + X(I)**2 * X(I-1) + X(I) * X(I-1)**2 + X(I-1)**3 )\n! * ( Y(I) - Y(I-1) )\n!\n! where X(0) and Y(0) should be replaced by X(N) and Y(N).\n!\n! Modified:\n!\n! 10 July 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! SF Bockman,\n! Generalizing the Formula for Areas of Polygons to Moments,\n! American Mathematical Society Monthly,\n! 1989, pages 131-132.\n!\n! Parameters:\n!\n! Input, integer N, the number of vertices of the polygon.\n! N should be at least 3 for a nonzero INTEGRALXX.\n!\n! Input, real ( kind = 8 ) Pg(2,N), the coordinates of the vertices\n! of the polygon. These vertices should be given in\n! counter clockwise order.\n!\n! Output, real ( kind = 8 ) INTEGRALXX, the value of the integral.\n!\n\n!!## EXTERNAL MODULES\nUSE FUN_Error !!((04-A-FUN_Error.f90))\nUSE FUN_xyAVERAGEX !!((05-A-FUN_xyAVERAGEX.f90))\nUSE FUN_xyINTEGRAL1 !!((06-A-FUN_xyINTEGRAL1.f90))\n\n!!## DEFAULT IMPLICIT\nIMPLICIT NONE\n\n!!## PROCEDURE OVERLOADING\nINTERFACE xyINTEGRALXX_Pg\n MODULE PROCEDURE xyINTEGRALXX_Pg_Rsp\n MODULE PROCEDURE xyINTEGRALXX_Pg_Rdp\nEND INTERFACE\n\n!!## PROCEDURE OVERLOADING\n!INTERFACE xyINTEGRALXX_Ls\n! MODULE PROCEDURE xyINTEGRALXX_Ls_Rsp\n! MODULE PROCEDURE xyINTEGRALXX_Ls_Rdp\n!END INTERFACE\n!\n!!!## PUBLIC ACCESS LIST\n!PUBLIC :: xyINTEGRALXX_Ls\n!PUBLIC :: xyINTEGRALXX_Ls_Rsp\n!PUBLIC :: xyINTEGRALXX_Ls_Rdp\n\n!!## PUBLIC ACCESS LIST\nPUBLIC :: xyINTEGRALXX_Pg\nPUBLIC :: xyINTEGRALXX_Pg_Rsp\nPUBLIC :: xyINTEGRALXX_Pg_Rdp\n\n\n!!## CONTAINED PROCEDURES\nCONTAINS\n\n\n!\n!!!### FUNCTION \n!FUNCTION xyINTEGRALXX_Ls_Rsp( Ls ) RESULT(INTEGRALX)\n!\n!!!#### LOCAL MAPPINGS\n!USE PAR_Constants_Rsp !!((02-A-PAR_Constants_Rsp.f90))\n!USE KND_IntrinsicTypes,ONLY: KIND_R => KIND_Rsp !!((01-A-KND_IntrinsicTypes.f90))\n!INCLUDE \"06-A-FUN_xyINTEGRALXX_Ls.f90.hdr\"\n!!!--begin--\n!INCLUDE \"06-A-FUN_xyINTEGRALXX_Ls.f90.bdy\"\n!!!--end--\n!END FUNCTION\n!\n!\n!\n!!!### FUNCTION \n!FUNCTION xyINTEGRALXX_Ls_Rdp( Ls ) RESULT(INTEGRALX)\n!\n!!!#### LOCAL MAPPINGS\n!USE PAR_Constants_Rdp !!((02-A-PAR_Constants_Rsp.f90))\n!USE KND_IntrinsicTypes,ONLY: KIND_R => KIND_Rdp !!((01-A-KND_IntrinsicTypes.f90))\n!INCLUDE \"06-A-FUN_xyINTEGRALXX_Ls.f90.hdr\"\n!!!--begin--\n!INCLUDE \"06-A-FUN_xyINTEGRALXX_Ls.f90.bdy\"\n!!!--end--\n!END FUNCTION\n\n\n\n\n!!### FUNCTION \nFUNCTION xyINTEGRALXX_Pg_Rsp( N , Pg ) RESULT(INTEGRALXX)\n\n!!#### LOCAL MAPPINGS\nUSE PAR_Constants_Rsp !!((02-A-PAR_Constants_Rsp.f90))\nUSE KND_IntrinsicTypes,ONLY: KIND_R => KIND_Rsp !!((01-A-KND_IntrinsicTypes.f90))\n\nINCLUDE \"07-A-FUN_xyINTEGRALXX_Pg.f90.hdr\"\n\n!!--begin--\nINCLUDE \"07-A-FUN_xyINTEGRALXX_Pg.f90.bdy\"\n!!--end--\n\nEND FUNCTION\n\n\n\n!!### FUNCTION \nFUNCTION xyINTEGRALXX_Pg_Rdp( N , Pg ) RESULT(INTEGRALXX)\n\n!!#### LOCAL MAPPINGS\nUSE PAR_Constants_Rdp !!((02-A-PAR_Constants_Rdp.f90))\nUSE KND_IntrinsicTypes,ONLY: KIND_R => KIND_Rdp !!((01-A-KND_IntrinsicTypes.f90))\n\nINCLUDE \"07-A-FUN_xyINTEGRALXX_Pg.f90.hdr\"\n!!--begin--\nINCLUDE \"07-A-FUN_xyINTEGRALXX_Pg.f90.bdy\"\n\n!!--end--\nEND FUNCTION\n\n\n\n\n\nEND MODULE\n", "meta": {"hexsha": "3f189f346d126f2252f6cd6aff710aea61308c53", "size": 3683, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/07-A-FUN_xyINTEGRALXX.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/07-A-FUN_xyINTEGRALXX.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/07-A-FUN_xyINTEGRALXX.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": 24.3907284768, "max_line_length": 82, "alphanum_fraction": 0.6502850937, "num_tokens": 1197, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972549785201, "lm_q2_score": 0.7931059462938814, "lm_q1q2_score": 0.6904758597505948}} {"text": "submodule(forlab) forlab_eye\n use forlab_kinds\n\ncontains\n !! Default Versions\n module procedure eye_1_default\n integer :: i\n eye_1_default = zeros(dim1, dim1)\n do i = 1, dim1\n eye_1_default (i, i) = 1.0d0\n end do\n return\n end procedure\n\n module procedure eye_2_default\n integer :: i\n eye_2_default = zeros(dim1, dim2)\n do i = 1, min(dim1, dim2)\n eye_2_default (i, i) = 1.0d0\n end do\n return\n end procedure\n\n !! Multi-precision versions\n module procedure eye_1_sp\n integer :: i\n eye_1_sp = zeros(dim1, dim1, flag)\n do i = 1, dim1\n eye_1_sp (i, i) = 1.0_sp\n end do\n return\n end procedure\n\n module procedure eye_2_sp\n integer :: i\n eye_2_sp = zeros(dim1, dim2, flag)\n do i = 1, min(dim1, dim2)\n eye_2_sp (i, i) = 1.0_sp\n end do\n return\n end procedure\n \n module procedure eye_1_dp\n integer :: i\n eye_1_dp = zeros(dim1, dim1, flag)\n do i = 1, dim1\n eye_1_dp (i, i) = 1.0_dp\n end do\n return\n end procedure\n\n module procedure eye_2_dp\n integer :: i\n eye_2_dp = zeros(dim1, dim2, flag)\n do i = 1, min(dim1, dim2)\n eye_2_dp (i, i) = 1.0_dp\n end do\n return\n end procedure\n \n module procedure eye_1_qp\n integer :: i\n eye_1_qp = zeros(dim1, dim1, flag)\n do i = 1, dim1\n eye_1_qp (i, i) = 1.0_qp\n end do\n return\n end procedure\n\n module procedure eye_2_qp\n integer :: i\n eye_2_qp = zeros(dim1, dim2, flag)\n do i = 1, min(dim1, dim2)\n eye_2_qp (i, i) = 1.0_qp\n end do\n return\n end procedure\n \nend submodule\n", "meta": {"hexsha": "fc2d329e8a0da3a4a6141ad8428707bd47b3e8f9", "size": 1826, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/forlab_eye.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_eye.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_eye.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": 22.825, "max_line_length": 42, "alphanum_fraction": 0.526286966, "num_tokens": 575, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637648915617, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.6904594076133471}} {"text": "program mydebug\r\nuse hybrid\r\n! call test1()\r\n! call qrtest()\r\n\r\n! call finitedifftest\r\n! call doglegtest\r\ncall FsolveHybridTest\r\nwrite(*,*) 'press any key to continue'\r\nread(*,*) \r\n\r\n\r\nend program mydebug\r\n\r\n\r\n\r\n\r\n\r\nsubroutine doglegtest\r\nuse myutility; use hybrid\r\n! subroutine to test dogleg\r\n\r\nimplicit none\r\nreal(kind=db), dimension(3,3) :: jacob, Q, R\r\nreal(kind=db), dimension(3) :: x0, p, Qtf\r\nexternal :: funs2\r\nreal(kind=db), dimension(3) :: fval\r\nreal(kind=db) :: delta\r\ninteger :: flag\r\n! real(kind=db), dimension(2,2) :: GetJacobian\r\n\r\nx0(1) = 0.5_db\r\nx0(2) = 1.0_db\r\nx0(3) = 1.5_db\r\ndelta = 0.10_db\r\n\r\ncall funs2(x0,fval)\r\nwrite(*,*) 'funs2([0.50, 1.00. 1.50 ]):'\r\nwrite(*,*) fval\r\n\r\nx0 = x0+1\r\ncall funs2(x0,fval)\r\ncall GetJacobian(jacob, funs2, x0, 0.0001_db,fval)\r\ncall QRfactorization(jacob,Q,R)\r\n\r\nQtf = matmul(transpose(Q), fval)\r\ncall dogleg(p,Q,R,delta,Qtf,flag)\r\n\r\nwrite(*,*) 'p:'\r\nwrite(*,*) p\r\nwrite(*,*) 'flag:'\r\nwrite(*,*) flag\r\n\r\nend subroutine doglegtest\r\n\r\n\r\n\r\nsubroutine finitedifftest()\r\nuse myutility; use hybrid, only : GetJacobian\r\n! test finite difference\r\nimplicit none\r\n\r\nreal(kind=db), dimension(2,2) :: jacob\r\nreal(kind=db), dimension(2) :: x0\r\nexternal :: funs1\r\nreal(kind=db), dimension(2) :: fval\r\n! real(kind=db), dimension(2,2) :: GetJacobian\r\n\r\nx0(1) = 2.0_db\r\nx0(2) = 3.0_db\r\n\r\ncall funs1(x0, fval)\r\ncall GetJacobian(jacob, funs1, x0, 0.001_db,fval)\r\n\r\ncall MatrixWrite(jacob)\r\n\r\nend subroutine finitedifftest\r\n\r\nsubroutine funs1(x, fval0)\r\nuse myutility; \r\nimplicit none\r\nreal(kind=db), intent(IN), dimension(:) :: x\r\nreal(kind=db), intent(OUT), dimension(:) :: fval0\r\n\r\nfval0(1) = x(2) - x(1)**2\r\nfval0(2) = 2 - x(1) - x(2)\r\n\r\nend subroutine funs1\r\n\r\n\r\n\r\nsubroutine funs3(x, fval0)\r\nuse myutility; \r\nimplicit none\r\nreal(kind=db), intent(IN), dimension(:) :: x\r\nreal(kind=db), intent(OUT), dimension(:) :: fval0\r\n\r\nfval0(1) = 10_db*(x(2) - x(1)**2)\r\nfval0(2) = 2 - x(1) - x(2)\r\n\r\nend subroutine funs3\r\n\r\n\r\nsubroutine funs2(x, fval0)\r\nuse myutility; \r\n! a little difficult function\r\n! solution x = [0.50, 1.00. 1.50 ] (+ 2pi*n)\r\n\r\nimplicit none\r\nreal(kind=db), intent(IN), dimension(:) :: x\r\nreal(kind=db), intent(OUT), dimension(:) :: fval0\r\n\r\nfval0(1) = 1.20_db * sin(x(1)) -1.40_db*cos(x(2))+ 0.70_db*sin(x(3)) & \r\n\t\t\t- 0.517133908732486_db\r\n\r\nfval0(2) = 0.80_db * cos(x(1)) -0.50_db*sin(x(2))+ 1.00_db*cos(x(3)) &\r\n\t\t\t- 0.352067758776053_db\r\n\r\nfval0(3) = 3.50_db * sin(x(1)) -4.25_db*cos(x(2))+ 2.80_db*cos(x(3)) &\r\n\t\t\t+ 0.4202312501553165_db\r\n\r\nend subroutine funs2\r\n\r\n\r\nsubroutine qrtest\r\nuse myutility; use hybrid, only : QRfactorization, QRupdate\r\n! test QR factorization and update\r\n\r\nimplicit none\r\nreal(kind=db), dimension(5,5) :: Q, A3\r\nreal(kind=db), dimension(5,5) :: A, R ,A2, A4, A5, A6, B1, B2\r\nreal(kind=db), dimension(5) :: u,v\r\nINTEGER :: isize\r\nINTEGER,ALLOCATABLE :: iseed(:)\r\n\r\n! set a seed. \r\nCALL RANDOM_SEED(SIZE=isize)\r\nALLOCATE( iseed(isize) )\r\nCALL RANDOM_SEED(GET=iseed)\r\niseed = 1\r\nCALL RANDOM_SEED(PUT = iseed) \r\n\r\nCALL RANDOM_NUMBER(A) ! generate random number\r\nA = A - 0.5\r\nwrite(*,*) 'A:'\r\ncall MatrixWrite( A )\r\n\r\nQ = 1\r\nR = 1\r\ncall QRfactorization(A,Q,R)\r\n\r\nA2 = matmul(Q , R)\r\nA3 = matmul(Q , transpose(Q))\r\n\r\nwrite(*,*) 'Q:'\r\ncall MatrixWrite( Q )\r\nwrite(*,*) 'R:'\r\ncall MatrixWrite( R )\r\nwrite(*,*) 'Q*R:'\r\ncall MatrixWrite( A2)\r\nwrite(*,*) \"Q*Q':\"\r\ncall MatrixWrite( A3)\r\nA3 = A2 - A\r\nwrite(*,*) \"Q*R - A:\"\r\ncall MatrixWrite( A3)\r\n\r\n! update test\r\ncall RANDOM_NUMBER(u)\r\ncall RANDOM_NUMBER(v)\r\nu = (u-0.5) * 1\r\nv = (v-0.5) * 1\r\n\r\nwrite(*,*) ' '\r\nwrite(*,*) 'update A '\r\ncall MatrixWrite( A+outer(u,v))\r\ncall QRupdate(Q,R,u,v)\r\n\r\n\r\nwrite(*,*) 'update Q:'\r\ncall MatrixWrite( Q )\r\nwrite(*,*) 'update R:'\r\ncall MatrixWrite( R )\r\nwrite(*,*) \"Q*Q':\"\r\ncall MatrixWrite( matmul(Q , transpose(Q)))\r\nwrite(*,*) \"Q*R - A:\"\r\ncall MatrixWrite( matmul(Q , R) - (A + outer(u,v)))\r\n\r\n\r\n! write(*,*) \"Q*Q':\"\r\n! call MatrixWrite( A3)\r\n! \r\n\r\nend subroutine qrtest\r\n\r\n\r\nsubroutine temp\r\n! temp place to put code\r\n\r\n\r\nend subroutine temp\r\n\r\n", "meta": {"hexsha": "848dd3dca69bed6487678e0726f0a631c194037a", "size": 4044, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "debug_hybrid.f90", "max_stars_repo_name": "yoki/Optimization", "max_stars_repo_head_hexsha": "49f3707ab5778b23c440ebc67dfa35354662565d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-10-26T16:18:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-08T09:14:51.000Z", "max_issues_repo_path": "debug_hybrid.f90", "max_issues_repo_name": "yoki/Optimization", "max_issues_repo_head_hexsha": "49f3707ab5778b23c440ebc67dfa35354662565d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "debug_hybrid.f90", "max_forks_repo_name": "yoki/Optimization", "max_forks_repo_head_hexsha": "49f3707ab5778b23c440ebc67dfa35354662565d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-04-05T18:05:05.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-08T15:15:45.000Z", "avg_line_length": 20.0198019802, "max_line_length": 73, "alphanum_fraction": 0.6174579624, "num_tokens": 1469, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007394, "lm_q2_score": 0.8031737963569014, "lm_q1q2_score": 0.6904594038629424}} {"text": "! RUN: %python %S/test_folding.py %s %flang_fc1\n! Test operation folding edge case (both expected value and messages)\n! These tests make assumptions regarding real(4) and integer(4) extrema.\n\n#define TEST_ISNAN(v) logical, parameter :: test_##v =.NOT.(v.EQ.v)\n\nmodule integer_tests\n integer(4), parameter :: i4_pmax = 2147483647_4\n ! Fortran grammar rule R605 prevents from writing -2147483648_4 in an\n ! expression because literal-constant are not signed so this would parse\n ! to -(2147483648_4) and 2147483648_4 is not accepted as a literal-constant.\n ! However, one can reach this value with operations.\n integer(4), parameter :: i4_nmax = -2147483647_4 - 1_4\n\n ! Integer division by zero are not tested here because they are handled as fatal\n ! errors in constants.\n\n !WARN: warning: INTEGER(4) negation overflowed\n logical, parameter :: test_overflow_unary_minus1 = (-i4_nmax).EQ.i4_nmax\n logical, parameter :: test_no_overflow_unary_minus1 = (-i4_pmax).EQ.(i4_nmax+1_4)\n logical, parameter :: test_no_overflow_unary_plus1 = (+i4_pmax).EQ.i4_pmax\n logical, parameter :: test_no_overflow_unary_plus2 = (+i4_nmax).EQ.i4_nmax\n\n !WARN: warning: INTEGER(4) addition overflowed\n logical, parameter :: test_overflow_add1 = (i4_pmax+1_4).EQ.i4_nmax\n !WARN: warning: INTEGER(4) addition overflowed\n logical, parameter :: test_overflow_add2 = (i4_nmax + (-1_4)).EQ.i4_pmax\n !WARN: warning: INTEGER(4) addition overflowed\n logical, parameter :: test_overflow_add3 = (i4_pmax + i4_pmax).EQ.(-2_4)\n !WARN: warning: INTEGER(4) addition overflowed\n logical, parameter :: test_overflow_add4 = (i4_nmax + i4_nmax).EQ.(0_4)\n logical, parameter :: test_no_overflow_add1 = (i4_pmax + 0_4).EQ.i4_pmax\n logical, parameter :: test_no_overflow_add2 = (i4_nmax + (-0_4)).EQ.i4_nmax\n logical, parameter :: test_no_overflow_add3 = (i4_pmax + i4_nmax).EQ.(-1_4)\n logical, parameter :: test_no_overflow_add4 = (i4_nmax + i4_pmax).EQ.(-1_4)\n\n !WARN: warning: INTEGER(4) subtraction overflowed\n logical, parameter :: test_overflow_sub1 = (i4_nmax - 1_4).EQ.i4_pmax\n !WARN: warning: INTEGER(4) subtraction overflowed\n logical, parameter :: test_overflow_sub2 = (i4_pmax - (-1_4)).EQ.i4_nmax\n !WARN: warning: INTEGER(4) subtraction overflowed\n logical, parameter :: test_overflow_sub3 = (i4_nmax - i4_pmax).EQ.(1_4)\n !WARN: warning: INTEGER(4) subtraction overflowed\n logical, parameter :: test_overflow_sub4 = (i4_pmax - i4_nmax).EQ.(-1_4)\n logical, parameter :: test_no_overflow_sub1 = (i4_nmax - 0_4).EQ.i4_nmax\n logical, parameter :: test_no_overflow_sub2 = (i4_pmax - (-0_4)).EQ.i4_pmax\n logical, parameter :: test_no_overflow_sub3 = (i4_nmax - i4_nmax).EQ.0_4\n logical, parameter :: test_no_overflow_sub4 = (i4_pmax - i4_pmax).EQ.0_4\n\n\n !WARN: warning: INTEGER(4) multiplication overflowed\n logical, parameter :: test_overflow_mult1 = (i4_pmax*2_4).EQ.(-2_4)\n !WARN: warning: INTEGER(4) multiplication overflowed\n logical, parameter :: test_overflow_mult2 = (i4_nmax*2_4).EQ.(0_4)\n !WARN: warning: INTEGER(4) multiplication overflowed\n logical, parameter :: test_overflow_mult3 = (i4_nmax*i4_nmax).EQ.(0_4)\n !WARN: warning: INTEGER(4) multiplication overflowed\n logical, parameter :: test_overflow_mult4 = (i4_pmax*i4_pmax).EQ.(1_4)\n\n !WARN: warning: INTEGER(4) division overflowed\n logical, parameter :: test_overflow_div1 = (i4_nmax/(-1_4)).EQ.(i4_nmax)\n logical, parameter :: test_no_overflow_div1 = (i4_nmax/(-2_4)).EQ.(1_4 + i4_pmax/2_4)\n logical, parameter :: test_no_overflow_div2 = (i4_nmax/i4_nmax).EQ.(1_4)\n\n !WARN: warning: INTEGER(4) power overflowed\n logical, parameter :: test_overflow_pow1 = (i4_pmax**2_4).EQ.(1_4)\n !WARN: warning: INTEGER(4) power overflowed\n logical, parameter :: test_overflow_pow3 = (i4_nmax**2_4).EQ.(0_4)\n logical, parameter :: test_no_overflow_pow1 = ((-1_4)**i4_nmax).EQ.(1_4)\n logical, parameter :: test_no_overflow_pow2 = ((-1_4)**i4_pmax).EQ.(-1_4)\n\nend module\n\nmodule real_tests\n ! Test real(4) operation folding on edge cases (inf and NaN)\n\n real(4), parameter :: r4_pmax = 3.4028235E38\n real(4), parameter :: r4_nmax = -3.4028235E38\n !WARN: warning: invalid argument on division\n real(4), parameter :: r4_nan = 0._4/0._4\n TEST_ISNAN(r4_nan)\n !WARN: warning: division by zero\n real(4), parameter :: r4_pinf = 1._4/0._4\n !WARN: warning: division by zero\n real(4), parameter :: r4_ninf = -1._4/0._4\n\n logical, parameter :: test_r4_nan_parentheses1 = .NOT.(((r4_nan)).EQ.r4_nan)\n logical, parameter :: test_r4_nan_parentheses2 = .NOT.(((r4_nan)).NE.r4_nan)\n logical, parameter :: test_r4_pinf_parentheses = ((r4_pinf)).EQ.r4_pinf\n logical, parameter :: test_r4_ninf_parentheses = ((r4_ninf)).EQ.r4_ninf\n\n ! No warnings expected\n logical, parameter :: test_r4_negation1 = (-r4_pmax).EQ.r4_nmax\n logical, parameter :: test_r4_negation2 = (-r4_nmax).EQ.r4_pmax\n logical, parameter :: test_r4_negation3 = (-r4_pinf).EQ.r4_ninf\n logical, parameter :: test_r4_negation4 = (-r4_ninf).EQ.r4_pinf\n logical, parameter :: test_r4_plus1 = (+r4_pmax).EQ.r4_pmax\n logical, parameter :: test_r4_plus2 = (+r4_nmax).EQ.r4_nmax\n logical, parameter :: test_r4_plus3 = (+r4_pinf).EQ.r4_pinf\n logical, parameter :: test_r4_plus4 = (+r4_ninf).EQ.r4_ninf\n ! NaN propagation , no warnings expected (quiet)\n real(4), parameter :: r4_nan_minus = (-r4_nan)\n TEST_ISNAN(r4_nan_minus)\n real(4), parameter :: r4_nan_plus = (+r4_nan)\n TEST_ISNAN(r4_nan_plus)\n\n !WARN: warning: overflow on addition\n logical, parameter :: test_inf_r4_add9 = (r4_pmax + r4_pmax).eq.(r4_pinf)\n !WARN: warning: overflow on addition\n logical, parameter :: test_inf_r4_add10 = (r4_nmax + r4_nmax).eq.(r4_ninf)\n !WARN: warning: overflow on subtraction\n logical, parameter :: test_inf_r4_sub9 = (r4_pmax - r4_nmax).eq.(r4_pinf)\n !WARN: warning: overflow on subtraction\n logical, parameter :: test_inf_r4_sub10 = (r4_nmax - r4_pmax).eq.(r4_ninf)\n\n ! No warnings expected below (inf propagation).\n logical, parameter :: test_inf_r4_add1 = (r4_pinf + r4_pinf).EQ.(r4_pinf)\n logical, parameter :: test_inf_r4_add2 = (r4_ninf + r4_ninf).EQ.(r4_ninf)\n logical, parameter :: test_inf_r4_add3 = (r4_pinf + r4_nmax).EQ.(r4_pinf)\n logical, parameter :: test_inf_r4_add4 = (r4_pinf + r4_pmax).EQ.(r4_pinf)\n logical, parameter :: test_inf_r4_add5 = (r4_ninf + r4_pmax).EQ.(r4_ninf)\n logical, parameter :: test_inf_r4_add6 = (r4_ninf + r4_nmax).EQ.(r4_ninf)\n logical, parameter :: test_inf_r4_add7 = (r4_ninf + 0._4).EQ.(r4_ninf)\n logical, parameter :: test_inf_r4_add8 = (r4_pinf + 0._4).EQ.(r4_pinf)\n\n !WARN: warning: invalid argument on subtraction\n real(4), parameter :: r4_nan_sub1 = r4_pinf - r4_pinf\n TEST_ISNAN(r4_nan_sub1)\n !WARN: warning: invalid argument on subtraction\n real(4), parameter :: r4_nan_sub2 = r4_ninf - r4_ninf\n TEST_ISNAN(r4_nan_sub2)\n !WARN: warning: invalid argument on addition\n real(4), parameter :: r4_nan_add1 = r4_ninf + r4_pinf\n TEST_ISNAN(r4_nan_add1)\n !WARN: warning: invalid argument on addition\n real(4), parameter :: r4_nan_add2 = r4_pinf + r4_ninf\n TEST_ISNAN(r4_nan_add2)\n\n ! No warnings expected here (quite NaN propagation)\n real(4), parameter :: r4_nan_sub3 = 0._4 - r4_nan\n TEST_ISNAN(r4_nan_sub3)\n real(4), parameter :: r4_nan_sub4 = r4_nan - r4_pmax\n TEST_ISNAN(r4_nan_sub4)\n real(4), parameter :: r4_nan_sub5 = r4_nan - r4_nmax\n TEST_ISNAN(r4_nan_sub5)\n real(4), parameter :: r4_nan_sub6 = r4_nan - r4_nan\n TEST_ISNAN(r4_nan_sub6)\n real(4), parameter :: r4_nan_add3 = 0._4 + r4_nan\n TEST_ISNAN(r4_nan_add3)\n real(4), parameter :: r4_nan_add4 = r4_nan + r4_pmax\n TEST_ISNAN(r4_nan_add4)\n real(4), parameter :: r4_nan_add5 = r4_nmax + r4_nan\n TEST_ISNAN(r4_nan_add5)\n real(4), parameter :: r4_nan_add6 = r4_nan + r4_nan\n TEST_ISNAN(r4_nan_add6)\n\n !WARN: warning: overflow on multiplication\n logical, parameter :: test_inf_r4_mult1 = (1.5_4*r4_pmax).eq.(r4_pinf)\n !WARN: warning: overflow on multiplication\n logical, parameter :: test_inf_r4_mult2 = (1.5_4*r4_nmax).eq.(r4_ninf)\n !WARN: warning: overflow on division\n logical, parameter :: test_inf_r4_div1 = (r4_nmax/(-0.5_4)).eq.(r4_pinf)\n !WARN: warning: overflow on division\n logical, parameter :: test_inf_r4_div2 = (r4_pmax/(-0.5_4)).eq.(r4_ninf)\n\n ! No warnings expected below (inf propagation).\n logical, parameter :: test_inf_r4_mult3 = (r4_pinf*r4_pinf).EQ.(r4_pinf)\n logical, parameter :: test_inf_r4_mult4 = (r4_ninf*r4_ninf).EQ.(r4_pinf)\n logical, parameter :: test_inf_r4_mult5 = (r4_pinf*0.1_4).EQ.(r4_pinf)\n logical, parameter :: test_inf_r4_mult6 = (r4_ninf*r4_nmax).EQ.(r4_pinf)\n logical, parameter :: test_inf_r4_div3 = (r4_pinf/0.).EQ.(r4_pinf)\n logical, parameter :: test_inf_r4_div4 = (r4_ninf/0.).EQ.(r4_ninf)\n logical, parameter :: test_inf_r4_div5 = (0./r4_pinf).EQ.(0.)\n logical, parameter :: test_inf_r4_div6 = (0./r4_ninf).EQ.(0.)\n logical, parameter :: test_inf_r4_div7 = (r4_pinf/r4_pmax).EQ.(r4_pinf)\n logical, parameter :: test_inf_r4_div8 = (r4_pinf/r4_nmax).EQ.(r4_ninf)\n logical, parameter :: test_inf_r4_div9 = (r4_nmax/r4_pinf).EQ.(0.)\n logical, parameter :: test_inf_r4_div10 = (r4_nmax/r4_ninf).EQ.(0.)\n\n !WARN: warning: invalid argument on division\n real(4), parameter :: r4_nan_div1 = 0._4/0._4\n TEST_ISNAN(r4_nan_div1)\n !WARN: warning: invalid argument on division\n real(4), parameter :: r4_nan_div2 = r4_ninf/r4_ninf\n TEST_ISNAN(r4_nan_div2)\n !WARN: warning: invalid argument on division\n real(4), parameter :: r4_nan_div3 = r4_ninf/r4_pinf\n TEST_ISNAN(r4_nan_div3)\n !WARN: warning: invalid argument on division\n real(4), parameter :: r4_nan_div4 = r4_pinf/r4_ninf\n TEST_ISNAN(r4_nan_div4)\n !WARN: warning: invalid argument on division\n real(4), parameter :: r4_nan_div5 = r4_pinf/r4_pinf\n TEST_ISNAN(r4_nan_div5)\n !WARN: warning: invalid argument on multiplication\n real(4), parameter :: r4_nan_mult1 = r4_pinf*0._4\n TEST_ISNAN(r4_nan_mult1)\n !WARN: warning: invalid argument on multiplication\n real(4), parameter :: r4_nan_mult2 = 0._4*r4_ninf\n TEST_ISNAN(r4_nan_mult2)\n\n ! No warnings expected here (quite NaN propagation)\n real(4), parameter :: r4_nan_div6 = 0._4/r4_nan\n TEST_ISNAN(r4_nan_div6)\n real(4), parameter :: r4_nan_div7 = r4_nan/r4_nan\n TEST_ISNAN(r4_nan_div7)\n real(4), parameter :: r4_nan_div8 = r4_nan/0._4\n TEST_ISNAN(r4_nan_div8)\n real(4), parameter :: r4_nan_div9 = r4_nan/1._4\n TEST_ISNAN(r4_nan_div9)\n real(4), parameter :: r4_nan_mult3 = r4_nan*1._4\n TEST_ISNAN(r4_nan_mult3)\n real(4), parameter :: r4_nan_mult4 = r4_nan*r4_nan\n TEST_ISNAN(r4_nan_mult4)\n real(4), parameter :: r4_nan_mult5 = 0._4*r4_nan\n TEST_ISNAN(r4_nan_mult5)\n\n ! TODO: ** operator folding\n ! logical, parameter :: test_inf_r4_exp1 = (r4_pmax**2._4).EQ.(r4_pinf)\n\n ! Relational operator edge cases (No warnings expected?)\n logical, parameter :: test_inf_r4_eq1 = r4_pinf.EQ.r4_pinf\n logical, parameter :: test_inf_r4_eq2 = r4_ninf.EQ.r4_ninf\n logical, parameter :: test_inf_r4_eq3 = .NOT.(r4_pinf.EQ.r4_ninf)\n logical, parameter :: test_inf_r4_eq4 = .NOT.(r4_pinf.EQ.r4_pmax)\n\n logical, parameter :: test_inf_r4_ne1 = .NOT.(r4_pinf.NE.r4_pinf)\n logical, parameter :: test_inf_r4_ne2 = .NOT.(r4_ninf.NE.r4_ninf)\n logical, parameter :: test_inf_r4_ne3 = r4_pinf.NE.r4_ninf\n logical, parameter :: test_inf_r4_ne4 = r4_pinf.NE.r4_pmax\n\n logical, parameter :: test_inf_r4_gt1 = .NOT.(r4_pinf.GT.r4_pinf)\n logical, parameter :: test_inf_r4_gt2 = .NOT.(r4_ninf.GT.r4_ninf)\n logical, parameter :: test_inf_r4_gt3 = r4_pinf.GT.r4_ninf\n logical, parameter :: test_inf_r4_gt4 = r4_pinf.GT.r4_pmax\n\n logical, parameter :: test_inf_r4_lt1 = .NOT.(r4_pinf.LT.r4_pinf)\n logical, parameter :: test_inf_r4_lt2 = .NOT.(r4_ninf.LT.r4_ninf)\n logical, parameter :: test_inf_r4_lt3 = r4_ninf.LT.r4_pinf\n logical, parameter :: test_inf_r4_lt4 = r4_pmax.LT.r4_pinf\n\n logical, parameter :: test_inf_r4_ge1 = r4_pinf.GE.r4_pinf\n logical, parameter :: test_inf_r4_ge2 = r4_ninf.GE.r4_ninf\n logical, parameter :: test_inf_r4_ge3 = .NOT.(r4_ninf.GE.r4_pinf)\n logical, parameter :: test_inf_r4_ge4 = .NOT.(r4_pmax.GE.r4_pinf)\n\n logical, parameter :: test_inf_r4_le1 = r4_pinf.LE.r4_pinf\n logical, parameter :: test_inf_r4_le2 = r4_ninf.LE.r4_ninf\n logical, parameter :: test_inf_r4_le3 = .NOT.(r4_pinf.LE.r4_ninf)\n logical, parameter :: test_inf_r4_le4 = .NOT.(r4_pinf.LE.r4_pmax)\n\n ! Invalid relational argument\n logical, parameter :: test_nan_r4_eq1 = .NOT.(r4_nan.EQ.r4_nan)\n logical, parameter :: test_nan_r4_ne1 = .NOT.(r4_nan.NE.r4_nan)\n\nend module\n\n! TODO: edge case conversions\n! TODO: complex tests (or is real tests enough?)\n\n! Logical operation (with logical arguments) cannot overflow or be invalid.\n! CHARACTER folding operations may cause host memory exhaustion if the\n! string are very large. This will cause a fatal error for the program\n! doing folding (e.g. f18), so there is nothing very interesting to test here.\n", "meta": {"hexsha": "ed2ab8e83bab609f464ac98e6729a2616f25d34e", "size": 12905, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "flang/test/Evaluate/folding03.f90", "max_stars_repo_name": "lxbndr/llvm-project", "max_stars_repo_head_hexsha": "2b715b15f5f4c6dd60f05d1b62f9c404e8b56e34", "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": "flang/test/Evaluate/folding03.f90", "max_issues_repo_name": "lxbndr/llvm-project", "max_issues_repo_head_hexsha": "2b715b15f5f4c6dd60f05d1b62f9c404e8b56e34", "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": "flang/test/Evaluate/folding03.f90", "max_forks_repo_name": "lxbndr/llvm-project", "max_forks_repo_head_hexsha": "2b715b15f5f4c6dd60f05d1b62f9c404e8b56e34", "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": 48.6981132075, "max_line_length": 87, "alphanum_fraction": 0.7352189074, "num_tokens": 4513, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099168, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.6904594001125374}} {"text": "! { dg-do run }\n\nprogram e_53_2\n !$omp declare target (fib)\n integer :: x, fib\n !$omp target map(from: x)\n x = fib (25)\n !$omp end target\n if (x /= fib (25)) call abort\nend program\n\ninteger recursive function fib (n) result (f)\n !$omp declare target\n integer :: n\n if (n <= 0) then\n f = 0\n else if (n == 1) then\n f = 1\n else\n f = fib (n - 1) + fib (n - 2)\n end if\nend function\n", "meta": {"hexsha": "0fb64af7e6d77258bf92d6489da4b7047866acc7", "size": 400, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gcc-gcc-7_3_0-release/libgomp/testsuite/libgomp.fortran/examples-4/declare_target-2.f90", "max_stars_repo_name": "best08618/asylo", "max_stars_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-05-02T17:34:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-17T10:15:18.000Z", "max_issues_repo_path": "gcc-gcc-7_3_0-release/libgomp/testsuite/libgomp.fortran/examples-4/declare_target-2.f90", "max_issues_repo_name": "best08618/asylo", "max_issues_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "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": "gcc-gcc-7_3_0-release/libgomp/testsuite/libgomp.fortran/examples-4/declare_target-2.f90", "max_forks_repo_name": "best08618/asylo", "max_forks_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-27T00:22:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-01T09:41:02.000Z", "avg_line_length": 17.3913043478, "max_line_length": 45, "alphanum_fraction": 0.565, "num_tokens": 148, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099168, "lm_q2_score": 0.8031737963569014, "lm_q1q2_score": 0.690459398087462}} {"text": "subroutine matgen(imat, a, lda, n, d, info)\n implicit none\n\n integer :: imat, n, lda, info\n real(kind(1.d0)) :: a(lda,n)\n real(kind(1.d0)) :: d(n)\n\n real(kind(1.d0)), allocatable :: work(:)\n character(len=3) :: path\n character :: type, dist, pack\n integer :: kl, ku, mode, i\n real(kind(1.d0)) :: anorm, cndnum, rcondc\n integer :: iseed(4)\n real(kind(1.d0)), parameter :: done=1.d0, dmone=-1.d0\n\n iseed = (/1988, 1989, 1990, 1991/)\n info = 0\n path(1:1) = 'Double precision'\n path(2:3) = 'SY'\n\n select case(imat)\n case(1)\n dist = 'U' ! uniform distribution\n type = 'P' ! symmetric, positive-definite\n mode = 0 ! use D\n cndnum = n ! the condition number\n anorm = n ! the matrix norm\n kl = n-1 ! upper bandwidth\n ku = n-1 ! lower bandwidth\n pack = 'N' ! no pack\n !write(*,'(\"=======================\")')\n !write(*,'(\"Dist : \",a1)')dist\n !write(*,'(\"Type : \",a1)')type\n !write(*,'(\"Mode : \",i1)')mode\n !write(*,'(\"Anorm : \",es10.3)')anorm\n !write(*,'(\"Cond : \",es10.3)')cndnum\n !write(*,'(\" \")')\n \n allocate(work(3*n), stat=info)\n if(info .ne. 0) return\n \n do i=1,n\n d(i) = n-i+1\n end do\n\n call dlatms( n, n, dist, iseed, type, &\n & d, mode, cndnum, anorm, kl, ku, &\n & pack, a, n, work, info )\n \n deallocate(work, stat=info)\n\n if(info .ne. 0) return\n\n case(2)\n dist = 'N' ! uniform distribution\n type = 'P' ! symmetric, positive-definite\n mode = 5 ! random numbers in the range\n ! ( 1/COND , 1 ) such that their logarithms\n ! are uniformly distributed.\n cndnum = 1e10 ! the condition number\n anorm = 1.d0 ! the matrix norm\n kl = n-1 ! upper bandwidth\n ku = n-1 ! lower bandwidth\n pack = 'N' ! no pack\n !write(*,'(\"=======================\")')\n !write(*,'(\"Dist : \",a1)')dist\n !write(*,'(\"Type : \",a1)')type\n !write(*,'(\"Mode : \",i1)')mode\n !write(*,'(\"Anorm : \",es10.3)')anorm\n !write(*,'(\"Cond : \",es10.3)')cndnum\n !write(*,'(\" \")')\n \n allocate(work(3*n), stat=info)\n if(info .ne. 0) return\n \n call dlatms( n, n, dist, iseed, type, &\n & d, mode, cndnum, anorm, kl, ku, &\n & pack, a, n, work, info )\n if(info .ne. 0) return\n\n call sort(d, n)\n \n deallocate(work, stat=info)\n\n case(3)\n dist = 'N' ! uniform distribution\n type = 'P' ! symmetric, positive-definite\n mode = 3 ! D(I)=COND**(-(I-1)/(N-1))\n cndnum = 1e5 ! the condition number\n anorm = 100.d0 ! the matrix norm\n kl = n-1 ! upper bandwidth\n ku = n-1 ! lower bandwidth\n pack = 'N' ! no pack\n !write(*,'(\"=======================\")')\n !write(*,'(\"Dist : \",a1)')dist\n !write(*,'(\"Type : \",a1)')type\n !write(*,'(\"Mode : \",i1)')mode\n !write(*,'(\"Anorm : \",es10.3)')anorm\n !write(*,'(\"Cond : \",es10.3)')cndnum\n !write(*,'(\" \")')\n \n allocate(work(3*n), stat=info)\n if(info .ne. 0) return\n \n call dlatms( n, n, dist, iseed, type, &\n & d, mode, cndnum, anorm, kl, ku, &\n & pack, a, n, work, info )\n if(info .ne. 0) return\n \n deallocate(work, stat=info)\n\n case(4)\n dist = 'N' ! uniform distribution\n type = 'P' ! symmetric, positive-definite\n mode = 4 ! D(i)=1 - (i-1)/(N-1)*(1 - 1/COND)\n cndnum = 1e2 ! the condition number\n anorm = 1000.d0 ! the matrix norm\n kl = n-1 ! upper bandwidth\n ku = n-1 ! lower bandwidth\n pack = 'N' ! no pack\n !write(*,'(\"=======================\")')\n !write(*,'(\"Dist : \",a1)')dist\n !write(*,'(\"Type : \",a1)')type\n !write(*,'(\"Mode : \",i1)')mode\n !write(*,'(\"Anorm : \",es10.3)')anorm\n !write(*,'(\"Cond : \",es10.3)')cndnum\n !write(*,'(\" \")')\n \n allocate(work(3*n), stat=info)\n if(info .ne. 0) return\n \n call dlatms( n, n, dist, iseed, type, &\n & d, mode, cndnum, anorm, kl, ku, &\n & pack, a, n, work, info )\n if(info .ne. 0) return\n \n deallocate(work, stat=info)\n case default\n write(*,'(\"Wrong matrix id\")')\n info = 1\n end select\n\n !write(*,'(\"Matrix generated\")')\n\n return\nend subroutine matgen\n \n\n! --------------------------------------------------------------------\n! SUBROUTINE Sort():\n! This subroutine receives an array x() and sorts it into descending\n! order.\n! --------------------------------------------------------------------\n\nSUBROUTINE Sort(x, Size)\n IMPLICIT NONE\n DOUBLE PRECISION, DIMENSION(Size), INTENT(INOUT) :: x\n INTEGER, INTENT(IN) :: Size\n INTEGER :: i\n INTEGER :: Location\n DOUBLE PRECISION :: Temp\n\n\n DO i = 1, Size-1 \n Location = FindMaximum(x, i, Size) \n Temp = x(i)\n x(i) = x(Location)\n x(Location) = Temp\n END DO\n\n CONTAINS\n\n INTEGER FUNCTION FindMaximum(x, Start, End)\n IMPLICIT NONE\n DOUBLE PRECISION, DIMENSION(:), INTENT(IN) :: x\n INTEGER, INTENT(IN) :: Start, End\n DOUBLE PRECISION :: Maximum\n INTEGER :: Location\n INTEGER :: i\n\n Maximum = x(Start)\n Location = Start\n DO i = Start+1, End\n IF (x(i) > Maximum) THEN\n Maximum = x(i)\n Location = i\n END IF\n END DO\n FindMaximum = Location ! return the position\n END FUNCTION FindMaximum\n\nEND SUBROUTINE Sort\n", "meta": {"hexsha": "ed3e177b42dc4e0dd1508587d6f6f4ce9d95f2d6", "size": 5637, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Projects/Eigenfaces/2 - Calcul des couples propres/Code Fortran+matlab/Fortran/matgen/matgen.f90", "max_stars_repo_name": "faicaltoubali/ENSEEIHT", "max_stars_repo_head_hexsha": "6db0aef64d68446b04f17d1eae574591026002b5", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-05-02T12:32:32.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-12T20:20:35.000Z", "max_issues_repo_path": "Projects/Eigenfaces/2 - Calcul des couples propres/Code Fortran+matlab/Fortran/matgen/matgen.f90", "max_issues_repo_name": "faicaltoubali/ENSEEIHT", "max_issues_repo_head_hexsha": "6db0aef64d68446b04f17d1eae574591026002b5", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-01-14T20:03:26.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-30T01:10:00.000Z", "max_forks_repo_path": "Projects/Eigenfaces/2 - Calcul des couples propres/Code Fortran+matlab/Fortran/matgen/matgen.f90", "max_forks_repo_name": "faicaltoubali/ENSEEIHT", "max_forks_repo_head_hexsha": "6db0aef64d68446b04f17d1eae574591026002b5", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2020-11-11T21:28:11.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-19T13:54:22.000Z", "avg_line_length": 29.207253886, "max_line_length": 71, "alphanum_fraction": 0.4729466028, "num_tokens": 1836, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190939, "lm_q2_score": 0.803173801068221, "lm_q1q2_score": 0.6904593963621322}} {"text": "program sqrt_01\nimplicit none\nreal :: x\nx = sqrt(4.0)\nif (abs(x - 2) > 1e-5) error stop\nx = sqrt(2.0)\nif (abs(x - 1.4142135623730951) > 1e-5) error stop\nend program\n", "meta": {"hexsha": "00a1d10c78c29275daf410b43cba852edcb864ff", "size": 165, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "integration_tests/sqrt_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": "integration_tests/sqrt_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": 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/sqrt_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": 18.3333333333, "max_line_length": 50, "alphanum_fraction": 0.6606060606, "num_tokens": 74, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8596637505099167, "lm_q2_score": 0.8031737916455819, "lm_q1q2_score": 0.6904593940373114}} {"text": "function OnMult(n_a, n_b)\n\tinteger, intent(in) :: n_a\n\tinteger, intent(in) :: n_b\n\n\tinteger :: i, j, k\n\treal :: temp\n\n\t!Create arrays\n\treal, dimension(n_a*n_a) :: a\n\treal, dimension(n_b*n_b) :: b\n\treal, dimension(n_a*n_b) :: c\n\t\n \t!Initialize array a\n\tdo i=1,n_a*n_a\n\t\ta(i) = 1\n\tend do\n\n\t!Initialize array b\n\tdo i=0,n_b*n_b - 1\n\t\tb(i+1) = i/n_b + 1\n\tend do\n\n\t!Matrix Multiplication\n\tdo i=0,n_a - 1\n\t\tdo j=0,n_b - 1\n\t\t\ttemp = 0\n\t\t\tdo k=0,n_a - 1\n\t\t\t\ttemp = temp + a(i*n_a+k+1) * b(k*n_b+k+1)\n\t\t\tend do\n\t\t\tc(i*n_a+j+1) = temp\n\t\tend do\n\tend do\n\n\t!Print Result Matrix\n\tprint *, \"Result matrix: \"\n\tdo i=1,min(n_a*n_b, 10)\n\t\tprint *, c(i)\n\tend do\n\n end function \n\nfunction OnMultLine(n_a, n_b)\n\tinteger, intent(in) :: n_a\n\tinteger, intent(in) :: n_b\n\n\tinteger :: i, j, k\n\n\t!Create arrays\n\treal, dimension(n_a*n_a) :: a\n\treal, dimension(n_b*n_b) :: b\n\treal, dimension(n_a*n_b) :: c\n\t\n \t!Initialize array a\n\tdo i=1,n_a*n_a\n\t\ta(i) = 1\n\tend do\n\n\t!Initialize array b\n\tdo i=0,n_b*n_b - 1\n\t\tb(i+1) = i/n_b+1\n\tend do\n\n\t!Initialize array b\n\tdo i=1,n_a*n_b\n\t\tc(i) = 0\n\tend do\n\t\t\t\t\t\n\t!Matrix Multiplication\n\tdo i=0,n_a - 1\n\t\tdo k=0,n_b - 1\n\t\t\tdo j=0,n_b - 1\n\t\t\t\tc(i*n_a+j+1) = c(i*n_a+j+1) + a(i*n_a+k+1) * b(k*n_b+j+1)\n\t\t\tend do\n\t\tend do\n\tend do\n\n\t!Print Result Matrix\n\tprint *, \"Result matrix: \"\n\tdo i=1,min(n_a*n_b, 10)\n\t\tprint *, c(i)\n\tend do\n\n end function \n\n\nprogram ex1\n\tprint *, OnMultLine(10, 10)\nend program ex1\n", "meta": {"hexsha": "304d9d04c0e6ae57821a301c3d2b1f20ce6752bf", "size": 1407, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Assignment 1/ex1.f90", "max_stars_repo_name": "msandim/feup-cpar", "max_stars_repo_head_hexsha": "ca0023b1a3d8fa194eaaa84471788d8543870ed8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-07-13T19:30:12.000Z", "max_stars_repo_stars_event_max_datetime": "2018-03-11T12:13:55.000Z", "max_issues_repo_path": "Assignment 1/ex1.f90", "max_issues_repo_name": "msandim/feup-cpar", "max_issues_repo_head_hexsha": "ca0023b1a3d8fa194eaaa84471788d8543870ed8", "max_issues_repo_licenses": ["MIT"], "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 1/ex1.f90", "max_forks_repo_name": "msandim/feup-cpar", "max_forks_repo_head_hexsha": "ca0023b1a3d8fa194eaaa84471788d8543870ed8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.808988764, "max_line_length": 61, "alphanum_fraction": 0.5970149254, "num_tokens": 577, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190939, "lm_q2_score": 0.803173791645582, "lm_q1q2_score": 0.6904593882618311}} {"text": "module mod_func\n\n use, intrinsic :: iso_fortran_env\n\n real(kind=real64), parameter :: f1_exact = 61.675091159487667993149630_real64\n real(kind=real64), parameter :: pi = 3.141592653589793238462643_real64\n\ncontains\n\n function f1(x)\n\n use, intrinsic :: iso_fortran_env\n\n implicit none\n\n real(kind=real64) :: f1\n real(kind=real64) :: x\n\n f1 = log(pi*x)*sin(pi*x)**2 + x\n\n return\n\n end function\n\n function f2(x)\n\n use, intrinsic :: iso_fortran_env\n\n implicit none\n\n real(kind=real64) :: f2\n real(kind=real64) :: x\n\n f2 = 50.0D+00/(pi*(2500.0D+00*x*x + 1.0D+00))\n\n return\n\n end function\n\nend module mod_func\n\nprogram main\n\n use, intrinsic :: iso_fortran_env\n use mod_func\n use mpi_f08\n\n implicit none\n\n integer(kind=int32) :: i, ierror\n integer(kind=int32) :: master\n integer(kind=int32) :: p\n integer(kind=int32) :: num_proc, rank\n integer(kind=int32) :: n, my_n\n integer(kind=int32) :: source, destin\n integer(kind=int32) :: tag\n\n real(kind=real64) :: a, b, my_a, my_b\n real(kind=real64) :: error\n real(kind=real64) :: total\n real(kind=real64) :: wtime\n real(kind=real64) :: x\n real(kind=real64) :: my_total\n real(kind=real64) :: exact\n type(MPI_Status) :: mpistatus\n\n a = 1.0_real64\n b = 10.0_real64\n n = huge(1_int32)\n\n exact = f1_exact\n\n master = 0\n\n call MPI_Init(ierror)\n\n call MPI_Comm_size(MPI_COMM_WORLD, num_proc, ierror)\n\n call MPI_Comm_rank(MPI_COMM_WORLD, rank, ierror)\n\n ! RANK 0 reads in the quadrature rule, and parcels out the\n ! evaluation points among the processes.\n if (rank == 0) then\n\n ! We want N to be the total number of evaluations.\n ! If necessary, we adjust N to be divisible by the number of processors.\n my_n = n/(num_proc - 1)\n n = (num_proc - 1)*my_n\n\n wtime = MPI_Wtime()\n\n write (*, '(a)') ' '\n write (*, '(a)') ' Quadrature of f(x) from A to B.'\n write (*, '(a)') ' f(x) = log(pi*x)*sin(pi*x)**2 + x'\n write (*, '(a)') ' '\n write (*, '(a,g14.6)') ' A = ', a\n write (*, '(a,g14.6)') ' B = ', b\n write (*, '(a,i12)') ' N = ', n\n write (*, '(a,g24.16)') ' Exact = ', exact\n write (*, '(a)') ' '\n end if\n\n ! Rank 0 has the computed value for my_n\n source = master\n\n ! Share with all the ranks the number of elements that each rank will compute\n call MPI_Bcast(my_n, 1, MPI_INTEGER, source, MPI_COMM_WORLD, ierror)\n\n ! Rank 0 assigns each process a subinterval of [A,B].\n if (rank == 0) then\n\n do p = 1, num_proc - 1\n\n my_a = (real(num_proc - p, kind=real64)*a &\n + real(p - 1, kind=real64)*b) &\n /real(num_proc - 1, kind=real64)\n\n destin = p\n tag = 1\n call MPI_Send(my_a, 1, MPI_DOUBLE_PRECISION, destin, tag, &\n MPI_COMM_WORLD, ierror)\n\n my_b = (real(num_proc - p - 1, kind=real64)*a &\n + real(p, kind=real64)*b) &\n /real(num_proc - 1, kind=real64)\n\n destin = p\n tag = 2\n call MPI_Send(my_b, 1, MPI_DOUBLE_PRECISION, destin, tag, &\n MPI_COMM_WORLD, ierror)\n\n end do\n\n total = 0.0D+00\n my_total = 0.0D+00\n\n! Processes receive MY_A, MY_B, and compute their part of the integral.\n else\n\n source = master\n tag = 1\n\n call MPI_Recv(my_a, 1, MPI_DOUBLE_PRECISION, source, tag, &\n MPI_COMM_WORLD, mpistatus, ierror)\n\n source = master\n tag = 2\n\n call MPI_Recv(my_b, 1, MPI_DOUBLE_PRECISION, source, tag, &\n MPI_COMM_WORLD, mpistatus, ierror)\n\n my_total = 0.0D+00\n do i = 1, my_n\n x = (real(my_n - i, kind=real64)*my_a &\n + real(i - 1, kind=real64)*my_b) &\n /real(my_n - 1, kind=real64)\n my_total = my_total + f1(x)\n end do\n\n my_total = (my_b - my_a)*my_total/real(my_n, kind=real64)\n\n write (*, '(a,i3,a,g14.6)') &\n ' RANK: ', rank, ' Partial Quadrature: ', my_total\n\n end if\n\n ! Each process sends its value of MY_TOTAL to the master process, to\n ! be summed in TOTAL.\n call MPI_Reduce(my_total, total, 1, MPI_DOUBLE_PRECISION, &\n MPI_SUM, master, MPI_COMM_WORLD, ierror)\n\n ! Report the results.\n if (rank == master) then\n\n error = abs(total - exact)\n wtime = MPI_Wtime() - wtime\n\n write (*, '(a)') ' '\n write (*, '(a,g24.16)') ' Estimate = ', total\n write (*, '(a,g14.6)') ' Error = ', error\n write (*, '(a,g14.6)') ' Time = ', wtime\n\n end if\n\n! Terminate MPI.\n call MPI_Finalize(ierror)\n\n! Terminate.\n if (rank == master) then\n write (*, '(a)') ' '\n write (*, '(a)') ' Normal end of execution.'\n end if\n\n stop\n\nend program\n", "meta": {"hexsha": "e7cac58d6bd80267f2948c80f577febd432f5fe3", "size": 4855, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "files/mpi/example_03.f90", "max_stars_repo_name": "WVUHPC/Modern-Fortran", "max_stars_repo_head_hexsha": "97c4db834d4e6ca43802318e4dc63ce4faa641aa", "max_stars_repo_licenses": ["CC-BY-4.0"], "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": "files/mpi/example_03.f90", "max_issues_repo_name": "WVUHPC/Modern-Fortran", "max_issues_repo_head_hexsha": "97c4db834d4e6ca43802318e4dc63ce4faa641aa", "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": "files/mpi/example_03.f90", "max_forks_repo_name": "WVUHPC/Modern-Fortran", "max_forks_repo_head_hexsha": "97c4db834d4e6ca43802318e4dc63ce4faa641aa", "max_forks_repo_licenses": ["CC-BY-4.0"], "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": 24.6446700508, "max_line_length": 80, "alphanum_fraction": 0.5583934089, "num_tokens": 1546, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339756938818, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.6904201473454933}} {"text": " real function sum(n, a)\n real s, a(100)\n s = 0.\n do i = 1, n\n s = s + 2. * a(i)\n enddo\n sum = s\n end\n", "meta": {"hexsha": "bb850da1b5ada0b641736f668d9c97c23187fcb5", "size": 146, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "packages/PIPS/validation/Demo/TutorialPPoPP2010.sub/intro_example03.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/Demo/TutorialPPoPP2010.sub/intro_example03.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/Demo/TutorialPPoPP2010.sub/intro_example03.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": 16.2222222222, "max_line_length": 29, "alphanum_fraction": 0.3424657534, "num_tokens": 56, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8221891305219504, "lm_q2_score": 0.8397339736884712, "lm_q1q2_score": 0.6904201456966665}} {"text": "@process free(f90) init(f90ptr) nosave\n!**********************************************************************\n! LICENSED MATERIALS - PROPERTY OF IBM *\n! \"RESTRICTED MATERIALS OF IBM\" *\n! *\n! 5765-C41 *\n! 5765-G18 *\n! (C) COPYRIGHT IBM CORP. 1997, 2003. ALL RIGHTS RESERVED. *\n! *\n! U.S. GOVERNMENT USERS RESTRICTED RIGHTS - USE, DUPLICATION *\n! OR DISCLOSURE RESTRICTED BY GSA ADP SCHEDULE CONTRACT WITH *\n! IBM CORP. *\n!**********************************************************************\n!\n! This sample program shows how to build and solve a sparse linear\n! system using the subroutines in the sparse section of Parallel\n! ESSL. The matrix and RHS are generated\n! in parallel, so that there is no serial bottleneck. \n!\n! The program solves a linear system based on the partial differential\n! equation \n!\n! \n! b1 dd(u) b2 dd(u) b3 dd(u) a1 d(u) a2 d(u) a3 d(u) \n! - ------ - ------ - ------ - ----- - ------ - ------ + a4 u \n! dxdx dydy dzdz dx dy dz \n!\n! = 0 \n! \n! with Dirichlet boundary conditions on the unit cube \n!\n! 0<=x,y,z<=1\n! \n! The equation is discretized with finite differences and uniform stepsize;\n! the resulting discrete equation is\n!\n! ( u(x,y,z)(2b1+2b2+2b3+a1+a2+a3)+u(x-1,y,z)(-b1-a1)+u(x,y-1,z)(-b2-a2)+\n! + u(x,y,z-1)(-b3-a3)-u(x+1,y,z)b1-u(x,y+1,z)b2-u(x,y,z+1)b3)*(1/h**2)\n!\n!\n! In this sample program the index space of the discretized\n! computational domain is first numbered sequentially in a standard way, \n! then the corresponding vector is distributed according to an HPF BLOCK\n! distribution directive.\n!\n! Boundary conditions are set in a very simple way, by adding \n! equations of the form\n!\n! u(x,y,z) = rhs(x,y,z)\n!\nProgram PDE90\n USE F90SPARSE\n Implicit none\n\n INTERFACE PART_BLOCK\n ! .....user defined subroutine.....\n SUBROUTINE PART_BLOCK(GLOBAL_INDX,N,NP,PV,NV)\n IMPLICIT NONE \n INTEGER, INTENT(IN) :: GLOBAL_INDX, N, NP\n INTEGER, INTENT(OUT) :: NV\n INTEGER, INTENT(OUT) :: PV(*) \n END SUBROUTINE PART_BLOCK\n END INTERFACE\n\n ! Input parameters\n Character*10 :: CMETHD, PREC\n Integer :: IDIM, IRET\n\n ! Miscellaneous \n Integer, Parameter :: IZERO=0, IONE=1\n Character, PARAMETER :: ORDER='R'\n INTEGER :: IARGC\n REAL(KIND(1.D0)), PARAMETER :: DZERO = 0.D0, ONE = 1.D0\n REAL(KIND(1.D0)) :: TIMEF, T1, T2, TPREC, TSOLVE, T3, T4 \n EXTERNAL TIMEF\n\n ! Sparse Matrix and preconditioner\n TYPE(D_SPMAT) :: A\n TYPE(D_PRECN) :: APRC\n ! Descriptor\n TYPE(DESC_TYPE) :: DESC_A\n ! Dense Matrices\n REAL(KIND(1.d0)), POINTER :: B(:), X(:)\n\n ! BLACS parameters\n INTEGER :: nprow, npcol, icontxt, iam, np, myprow, mypcol\n \n ! Solver parameters\n INTEGER :: ITER, ITMAX,IERR,ITRACE, METHD,IPREC, ISTOPC,&\n & IPARM(20) \n REAL(KIND(1.D0)) :: ERR, EPS, RPARM(20)\n \n ! Other variables\n INTEGER :: I,INFO\n INTEGER :: INTERNAL, M,II\n \n ! Initialize BLACS \n CALL BLACS_PINFO(IAM, NP)\n CALL BLACS_GET(IZERO, IZERO, ICONTXT)\n\n ! Rectangular Grid, P x 1\n\n CALL BLACS_GRIDINIT(ICONTXT, ORDER, NP, IONE)\n CALL BLACS_GRIDINFO(ICONTXT, NPROW, NPCOL, MYPROW, MYPCOL)\n\n !\n ! Get parameters\n !\n CALL GET_PARMS(ICONTXT,CMETHD,PREC,IDIM,ISTOPC,ITMAX,ITRACE)\n \n !\n ! Allocate and fill in the coefficient matrix, RHS and initial guess \n !\n\n CALL BLACS_BARRIER(ICONTXT,'All')\n T1 = TIMEF()\n CALL CREATE_MATRIX(PART_BLOCK,IDIM,A,B,X,DESC_A,ICONTXT) \n T2 = TIMEF() - T1\n \n CALL DGAMX2D(ICONTXT,'A',' ',IONE, IONE,T2,IONE,T1,T1,-1,-1,-1)\n IF (IAM.EQ.0) Write(6,*) 'Matrix creation Time : ',T2/1.D3\n\n !\n ! Prepare the preconditioner.\n ! \n SELECT CASE (PREC) \n CASE ('ILU')\n IPREC = 2\n CASE ('DIAGSC')\n IPREC = 1\n CASE ('NONE')\n IPREC = 0\n CASE DEFAULT\n WRITE(0,*) 'Unknown preconditioner'\n CALL BLACS_ABORT(ICONTXT,-1)\n END SELECT\n CALL BLACS_BARRIER(ICONTXT,'All')\n T1 = TIMEF()\n CALL PSPGPR(IPREC,A,APRC,DESC_A,INFO=IRET)\n TPREC = TIMEF()-T1\n \n CALL DGAMX2D(icontxt,'A',' ',IONE, IONE,TPREC,IONE,t1,t1,-1,-1,-1)\n \n IF (IAM.EQ.0) WRITE(6,*) 'Preconditioner Time : ',TPREC/1.D3\n\n IF (IRET.NE.0) THEN\n WRITE(0,*) 'Error on preconditioner',IRET\n CALL BLACS_ABORT(ICONTXT,-1)\n STOP\n END IF\n \n !\n ! Iterative method parameters \n !\n IF (CMETHD(1:6).EQ.'CGSTAB') Then\n METHD = 1 \n ELSE IF (CMETHD(1:3).EQ.'CGS') Then\n METHD = 2\n ELSE IF (CMETHD(1:5).EQ.'TFQMR') THEN\n METHD = 3\n ELSE\n WRITE(0,*) 'Unknown method '\n CALL BLACS_ABORT(ICONTXT,-1)\n METHD = 0\n END IF\n EPS = 1.D-9\n IPARM = 0\n RPARM = 0.D0\n IPARM(1) = METHD\n IPARM(2) = ISTOPC\n IPARM(3) = ITMAX\n IPARM(4) = ITRACE\n RPARM(1) = EPS\n CALL BLACS_BARRIER(ICONTXT,'All')\n T1 = TIMEF() \n CALL PSPGIS(A,B,X,APRC,DESC_A,&\n & IPARM=IPARM,RPARM=RPARM,INFO=IERR) \n CALL BLACS_BARRIER(ICONTXT,'All')\n T2 = TIMEF() - T1\n ITER = IPARM(5)\n ERR = RPARM(2)\n CALL DGAMX2D(ICONTXT,'A',' ',IONE, IONE,T2,IONE,T1,T1,-1,-1,-1)\n\n IF (IAM.EQ.0) THEN\n WRITE(6,*) 'Time to Solve Matrix : ',T2/1.D3 \n WRITE(6,*) 'Time per iteration : ',T2/(ITER*1.D3)\n WRITE(6,*) 'Number of iterations : ',ITER\n WRITE(6,*) 'Error on exit : ',ERR\n WRITE(6,*) 'INFO on exit : ',IERR\n END IF\n\n ! \n ! Cleanup storage and exit\n !\n CALL PGEFREE(B,DESC_A)\n CALL PGEFREE(X,DESC_A)\n\n CALL PSPFREE(APRC,DESC_A) \n CALL PSPFREE(A,DESC_A)\n \n CALL PADFREE(DESC_A)\n \n CALL BLACS_GRIDEXIT(ICONTXT)\n CALL BLACS_EXIT(0)\n \n STOP\n \nCONTAINS\n !\n ! Subroutine to allocate and fill in the coefficient matrix and\n ! the RHS. \n !\n SUBROUTINE CREATE_MATRIX(PARTS,IDIM,A,B,T,DESC_A,ICONTXT)\n!\n! Discretize the partial diferential equation\n! \n! b1 dd(u) b2 dd(u) b3 dd(u) a1 d(u) a2 d(u) a3 d(u) \n! - ------ - ------ - ------ - ----- - ------ - ------ + a4 u \n! dxdx dydy dzdz dx dy dz \n!\n! = 0 \n! \n! boundary condition: Dirichlet\n! 0< x,y,z<1\n! \n! u(x,y,z)(2b1+2b2+2b3+a1+a2+a3)+u(x-1,y,z)(-b1-a1)+u(x,y-1,z)(-b2-a2)+\n! + u(x,y,z-1)(-b3-a3)-u(x+1,y,z)b1-u(x,y+1,z)b2-u(x,y,z+1)b3\n USE F90SPARSE\n Implicit None\n INTEGER :: IDIM\n INTERFACE PARTS\n SUBROUTINE PARTS(GLOBAL_INDX,N,P,PV,NV)\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: GLOBAL_INDX, N, P\n INTEGER, INTENT(OUT) :: NV\n INTEGER, INTENT(OUT) :: PV(*)\n \n END SUBROUTINE PARTS\n END INTERFACE\n Real(Kind(1.D0)),Pointer :: B(:),T(:)\n Type (DESC_TYPE) :: DESC_A\n Integer :: ICONTXT\n Type(D_SPMAT) :: A\n Real(Kind(1.d0)) :: ZT(10),GLOB_X,GLOB_Y,GLOB_Z\n Integer :: M,N,NNZ,GLOB_ROW,J\n Type (D_SPMAT) :: ROW_MAT\n Integer :: X,Y,Z,COUNTER,IA,I,INDX_OWNER\n INTEGER :: NPROW,NPCOL,MYPROW,MYPCOL\n Integer :: ELEMENT\n INTEGER :: INFO, NV, INV\n INTEGER, ALLOCATABLE :: PRV(:)\n ! deltah dimension of each grid cell\n ! deltat discretization time\n Real(Kind(1.D0)) :: DELTAH\n Real(Kind(1.d0)),Parameter :: RHS=0.d0,ONE=1.d0,ZERO=0.d0\n Real(Kind(1.d0)) :: TIMEF, T1, T2, TINS\n external timef\n ! common area\n\n\n CALL BLACS_GRIDINFO(ICONTXT, NPROW, NPCOL, MYPROW, MYPCOL)\n\n DELTAH = 1.D0/(IDIM-1)\n\n ! Initialize array descriptor and sparse matrix storage. Provide an\n ! estimate of the number of non zeroes \n\n M = IDIM*IDIM*IDIM\n N = M\n NNZ = (N*7)/(NPROW*NPCOL)\n Call PADALL(N,PARTS,DESC_A,ICONTXT)\n Call PSPALL(A,DESC_A,NNZ=NNZ)\n ! Define RHS from boundary conditions; also build initial guess \n Call PGEALL(B,DESC_A)\n Call PGEALL(T,DESC_A)\n \n ! We build an auxiliary matrix consisting of one row at a\n ! time\n ROW_MAT%DESCRA(1:1) = 'G'\n ROW_MAT%FIDA = 'CSR'\n ALLOCATE(ROW_MAT%AS(20))\n ALLOCATE(ROW_MAT%IA1(20))\n ALLOCATE(ROW_MAT%IA2(20))\n ALLOCATE(PRV(NPROW))\n ROW_MAT%IA2(1)=1 \n\n TINS = 0.D0\n CALL BLACS_BARRIER(ICONTXT,'ALL')\n T1 = TIMEF()\n\n ! Loop over rows belonging to current process in a BLOCK\n ! distribution.\n\n DO GLOB_ROW = 1, N\n CALL PARTS(GLOB_ROW,N,NPROW,PRV,NV)\n DO INV = 1, NV\n INDX_OWNER = PRV(INV)\n IF (INDX_OWNER == MYPROW) THEN\n ! Local matrix pointer \n ELEMENT=1\n ! Compute gridpoint Coordinates\n IF (MOD(GLOB_ROW,(IDIM*IDIM)).EQ.0) THEN\n X = GLOB_ROW/(IDIM*IDIM)\n ELSE\n X = GLOB_ROW/(IDIM*IDIM)+1\n ENDIF\n IF (MOD((GLOB_ROW-(X-1)*IDIM*IDIM),IDIM).EQ.0) THEN\n Y = (GLOB_ROW-(X-1)*IDIM*IDIM)/IDIM\n ELSE\n Y = (GLOB_ROW-(X-1)*IDIM*IDIM)/IDIM+1\n ENDIF\n Z = GLOB_ROW-(X-1)*IDIM*IDIM-(Y-1)*IDIM\n\t ! GLOB_X, GLOB_Y, GLOB_X coordinates\n\t GLOB_X=X*DELTAH\n\t GLOB_Y=Y*DELTAH\n\t GLOB_Z=Z*DELTAH\n \n ! Check on boundary points \n IF (X.EQ.1) THEN\n ROW_MAT%AS(ELEMENT)=ONE\n ROW_MAT%IA1(ELEMENT)=(X-1)*IDIM*IDIM+(Y-1)*IDIM+(Z)\n ELEMENT=ELEMENT+1\n ELSE IF (Y.EQ.1) THEN\n ROW_MAT%AS(ELEMENT)=ONE\n ROW_MAT%IA1(ELEMENT)=(X-1)*IDIM*IDIM+(Y-1)*IDIM+(Z)\n ELEMENT=ELEMENT+1\n ELSE IF (Z.EQ.1) THEN\n ROW_MAT%AS(ELEMENT)=ONE\n ROW_MAT%IA1(ELEMENT)=(X-1)*IDIM*IDIM+(Y-1)*IDIM+(Z)\n ELEMENT=ELEMENT+1\n ELSE IF (X.EQ.IDIM) THEN\n ROW_MAT%AS(ELEMENT)=ONE\n ROW_MAT%IA1(ELEMENT)=(X-1)*IDIM*IDIM+(Y-1)*IDIM+(Z)\n ELEMENT=ELEMENT+1\n ELSE IF (Y.EQ.IDIM) THEN\n ROW_MAT%AS(ELEMENT)=ONE\n ROW_MAT%IA1(ELEMENT)=(X-1)*IDIM*IDIM+(Y-1)*IDIM+(Z)\n ELEMENT=ELEMENT+1\n ELSE IF (Z.EQ.IDIM) THEN\n ROW_MAT%AS(ELEMENT)=ONE\n ROW_MAT%IA1(ELEMENT)=(X-1)*IDIM*IDIM+(Y-1)*IDIM+(Z)\n ELEMENT=ELEMENT+1\n ELSE\n ! Internal point: build discretization\n ! \n ! Term depending on (x-1,y,z)\n !\n ROW_MAT%AS(ELEMENT)=-B1(GLOB_X,GLOB_Y,GLOB_Z)&\n & -A1(GLOB_X,GLOB_Y,GLOB_Z)\n ROW_MAT%AS(ELEMENT) = ROW_MAT%AS(ELEMENT)/(DELTAH*&\n & DELTAH)\n ROW_MAT%IA1(ELEMENT)=(X-2)*IDIM*IDIM+(Y-1)*IDIM+(Z)\n ELEMENT=ELEMENT+1\n ! Term depending on (x,y-1,z)\n ROW_MAT%AS(ELEMENT)=-B2(GLOB_X,GLOB_Y,GLOB_Z)&\n & -A2(GLOB_X,GLOB_Y,GLOB_Z)\n ROW_MAT%AS(ELEMENT) = ROW_MAT%AS(ELEMENT)/(DELTAH*&\n & DELTAH)\n ROW_MAT%IA1(ELEMENT)=(X-1)*IDIM*IDIM+(Y-2)*IDIM+(Z)\n ELEMENT=ELEMENT+1\n ! Term depending on (x,y,z-1)\n ROW_MAT%AS(ELEMENT)=-B3(GLOB_X,GLOB_Y,GLOB_Z)&\n & -A3(GLOB_X,GLOB_Y,GLOB_Z)\n ROW_MAT%AS(ELEMENT) = ROW_MAT%AS(ELEMENT)/(DELTAH*&\n & DELTAH)\n ROW_MAT%IA1(ELEMENT)=(X-1)*IDIM*IDIM+(Y-1)*IDIM+(Z-1)\n ELEMENT=ELEMENT+1\n ! Term depending on (x,y,z)\n ROW_MAT%AS(ELEMENT)=2*B1(GLOB_X,GLOB_Y,GLOB_Z)&\n & +2*B2(GLOB_X,GLOB_Y,GLOB_Z)&\n & +2*B3(GLOB_X,GLOB_Y,GLOB_Z)&\n & +A1(GLOB_X,GLOB_Y,GLOB_Z)&\n & +A2(GLOB_X,GLOB_Y,GLOB_Z)&\n & +A3(GLOB_X,GLOB_Y,GLOB_Z)\n ROW_MAT%AS(ELEMENT) = ROW_MAT%AS(ELEMENT)/(DELTAH*&\n & DELTAH)\n ROW_MAT%IA1(ELEMENT)=(X-1)*IDIM*IDIM+(Y-1)*IDIM+(Z)\n ELEMENT=ELEMENT+1 \n ! Term depending on (x,y,z+1)\n ROW_MAT%AS(ELEMENT)=-B1(GLOB_X,GLOB_Y,GLOB_Z)\n ROW_MAT%AS(ELEMENT) = ROW_MAT%AS(ELEMENT)/(DELTAH*&\n & DELTAH)\n ROW_MAT%IA1(ELEMENT)=(X-1)*IDIM*IDIM+(Y-1)*IDIM+(Z+1)\n ELEMENT=ELEMENT+1\n ! Term depending on (x,y+1,z)\n ROW_MAT%AS(ELEMENT)=-B2(GLOB_X,GLOB_Y,GLOB_Z)\n ROW_MAT%AS(ELEMENT) = ROW_MAT%AS(ELEMENT)/(DELTAH*&\n & DELTAH)\n ROW_MAT%IA1(ELEMENT)=(X-1)*IDIM*IDIM+(Y)*IDIM+(Z)\n ELEMENT=ELEMENT+1\n ! Term depending on (x+1,y,z)\n ROW_MAT%AS(ELEMENT)=-B3(GLOB_X,GLOB_Y,GLOB_Z)\n ROW_MAT%AS(ELEMENT) = ROW_MAT%AS(ELEMENT)/(DELTAH*&\n & DELTAH)\n ROW_MAT%IA1(ELEMENT)=(X)*IDIM*IDIM+(Y-1)*IDIM+(Z)\n ELEMENT=ELEMENT+1\n ENDIF\n ROW_MAT%M=1\n ROW_MAT%N=N\n ROW_MAT%IA2(2)=ELEMENT \n ! IA== GLOBAL ROW INDEX\n IA=(X-1)*IDIM*IDIM+(Y-1)*IDIM+(Z)\n T3 = TIMEF()\n CALL PSPINS(A,IA,1,ROW_MAT,DESC_A) \n TINS = TINS + (TIMEF()-T3)\n\t ! Build RHS \n IF (X==1) THEN \n GLOB_Y=(Y-IDIM/2)*DELTAH\n GLOB_Z=(Z-IDIM/2)*DELTAH \n ZT(1) = EXP(-GLOB_Y**2-GLOB_Z**2)\n ELSE IF ((Y==1).OR.(Y==IDIM).OR.(Z==1).OR.(Z==IDIM)) THEN \n GLOB_X=3*(X-1)*DELTAH\n GLOB_Y=(Y-IDIM/2)*DELTAH\n GLOB_Z=(Z-IDIM/2)*DELTAH \n ZT(1) = EXP(-GLOB_Y**2-GLOB_Z**2)*EXP(-GLOB_X)\n ELSE\n ZT(1) = 0.D0\n ENDIF\n CALL PGEINS(B,ZT(1:1),DESC_A,IA)\n ZT(1)=0.D0\n CALL PGEINS(T,ZT(1:1),DESC_A,IA) \t \n END IF\n END DO \n END DO\n \n CALL BLACS_BARRIER(ICONTXT,'ALL') \n T2 = TIMEF()\n \n IF (MYPROW.EQ.0) THEN\n WRITE(0,*) ' pspins time',TINS/1.D3\n WRITE(0,*) ' Insert time',(T2-T1)/1.D3\n ENDIF\n\n DEALLOCATE(ROW_MAT%AS,ROW_MAT%IA1,ROW_MAT%IA2)\n \n\n CALL BLACS_BARRIER(ICONTXT,'ALL') \n T1 = TIMEF()\n \n CALL PSPASB(A,DESC_A,INFO=INFO,DUPFLAG=0,MTYPE='GEN ') \n \n CALL BLACS_BARRIER(ICONTXT,'ALL')\n T2 = TIMEF()\n \n IF (MYPROW.EQ.0) THEN\n WRITE(0,*) ' Assembly time',(T2-T1)/1.D3\n ENDIF\n \n CALL PGEASB(B,DESC_A) \n CALL PGEASB(T,DESC_A)\n RETURN\n END SUBROUTINE CREATE_MATRIX\n !\n ! Functions parameterizing the differential equation \n ! \n FUNCTION A1(X,Y,Z)\n REAL(KIND(1.D0)) :: A1\n REAL(KIND(1.D0)) :: X,Y,Z\n A1=1.D0\n END FUNCTION A1\n FUNCTION A2(X,Y,Z)\n REAL(KIND(1.D0)) :: A2\n REAL(KIND(1.D0)) :: X,Y,Z\n A2=2.D1*Y\n END FUNCTION A2\n FUNCTION A3(X,Y,Z)\n REAL(KIND(1.D0)) :: A3\n REAL(KIND(1.D0)) :: X,Y,Z \n A3=1.D0\n END FUNCTION A3\n FUNCTION A4(X,Y,Z)\n REAL(KIND(1.D0)) :: A4\n REAL(KIND(1.D0)) :: X,Y,Z \n A4=1.D0\n END FUNCTION A4\n FUNCTION B1(X,Y,Z)\n REAL(KIND(1.D0)) :: B1 \n REAL(KIND(1.D0)) :: X,Y,Z\n B1=1.D0\n END FUNCTION B1\n FUNCTION B2(X,Y,Z)\n REAL(KIND(1.D0)) :: B2\n REAL(KIND(1.D0)) :: X,Y,Z\n B2=1.D0\n END FUNCTION B2\n FUNCTION B3(X,Y,Z)\n REAL(KIND(1.D0)) :: B3\n REAL(KIND(1.D0)) :: X,Y,Z\n B3=1.D0\n END FUNCTION B3 \n !\n ! Get iteration parameters from the command line\n !\n SUBROUTINE GET_PARMS(ICONTXT,CMETHD,PREC,IDIM,ISTOPC,ITMAX,ITRACE)\n IMPLICIT NONE \n integer :: icontxt\n Character*10 :: CMETHD, PREC\n Integer :: IDIM, IRET, ISTOPC,ITMAX,ITRACE\n Character*40 :: CHARBUF\n INTEGER :: IARGC, NPROW, NPCOL, MYPROW, MYPCOL\n EXTERNAL IARGC\n INTEGER :: INTBUF(10), IP\n \n CALL BLACS_GRIDINFO(ICONTXT, NPROW, NPCOL, MYPROW, MYPCOL)\n\n IF (MYPROW==0) THEN\n ! Read command line parameters \n IP=IARGC()\n IF (IARGC().GE.3) THEN\n CALL GETARG(1,CHARBUF)\n READ(CHARBUF,*) CMETHD\n CALL GETARG(2,CHARBUF)\n READ(CHARBUF,*) PREC\n \n ! Convert strings in array\n DO I = 1, LEN(CMETHD)\n INTBUF(I) = IACHAR(CMETHD(I:I))\n END DO\n ! Broadcast parameters to all processors\n CALL IGEBS2D(ICONTXT,'ALL',' ',10,1,INTBUF,10)\n \n DO I = 1, LEN(PREC)\n INTBUF(I) = IACHAR(PREC(I:I))\n END DO\n ! Broadcast parameters to all processors\n CALL IGEBS2D(ICONTXT,'ALL',' ',10,1,INTBUF,10)\n \n CALL GETARG(3,CHARBUF)\n READ(CHARBUF,*) IDIM\n IF (IARGC().GE.4) THEN\n CALL GETARG(4,CHARBUF)\n READ(CHARBUF,*) ISTOPC\n ELSE\n ISTOPC=1 \n ENDIF\n IF (IARGC().GE.5) THEN\n CALL GETARG(5,CHARBUF)\n READ(CHARBUF,*) ITMAX\n ELSE\n ITMAX=500\n ENDIF\n IF (IARGC().GE.6) THEN\n CALL GETARG(6,CHARBUF)\n READ(CHARBUF,*) ITRACE\n ELSE\n ITRACE=0\n ENDIF\n ! Broadcast parameters to all processors \n CALL IGEBS2D(ICONTXT,'ALL',' ',1,1,IDIM,1)\n CALL IGEBS2D(ICONTXT,'ALL',' ',1,1,ISTOPC,1)\n CALL IGEBS2D(ICONTXT,'ALL',' ',1,1,ITMAX,1)\n CALL IGEBS2D(ICONTXT,'ALL',' ',1,1,ITRACE,1)\n WRITE(6,*)'Solving matrix: ELL1' \n WRITE(6,*)'on grid',IDIM,'x',IDIM,'x',IDIM\n WRITE(6,*)' with BLOCK data distribution, NP=',Np,&\n & ' Preconditioner=',PREC,&\n & ' Iterative methd=',CMETHD \n ELSE\n ! Wrong number of parameter, print an error message and exit\n CALL PR_USAGE(0) \n CALL BLACS_ABORT(ICONTXT,-1)\n STOP 1\n ENDIF\n ELSE\n ! Receive Parameters\n CALL IGEBR2D(ICONTXT,'ALL',' ',10,1,INTBUF,10,0,0)\n DO I = 1, 10\n CMETHD(I:I) = ACHAR(INTBUF(I))\n END DO\n CALL IGEBR2D(ICONTXT,'ALL',' ',10,1,INTBUF,10,0,0)\n DO I = 1, 10\n PREC(I:I) = ACHAR(INTBUF(I))\n END DO\n CALL IGEBR2D(ICONTXT,'ALL',' ',1,1,IDIM,1,0,0)\n CALL IGEBR2D(ICONTXT,'ALL',' ',1,1,ISTOPC,1,0,0)\n CALL IGEBR2D(ICONTXT,'ALL',' ',1,1,ITMAX,1,0,0)\n CALL IGEBR2D(ICONTXT,'ALL',' ',1,1,ITRACE,1,0,0)\n END IF\n RETURN\n \n END SUBROUTINE GET_PARMS\n !\n ! Print an error message \n ! \n SUBROUTINE PR_USAGE(IOUT)\n IMPLICIT NONE \n INTEGER :: IOUT\n WRITE(IOUT,*)'Incorrect parameter(s) found'\n WRITE(IOUT,*)' Usage: pde90 methd prec dim &\n &[istop itmax itrace]' \n WRITE(IOUT,*)' Where:'\n WRITE(IOUT,*)' methd: CGSTAB TFQMR CGS' \n WRITE(IOUT,*)' prec : ILU DIAGSC NONE'\n WRITE(IOUT,*)' dim number of points along each axis'\n WRITE(IOUT,*)' the size of the resulting linear '\n WRITE(IOUT,*)' system is dim**3'\n WRITE(IOUT,*)' istop Stopping criterion 1, 2 or 3 [1] '\n WRITE(IOUT,*)' itmax Maximum number of iterations [500] '\n WRITE(IOUT,*)' itrace 0 (no tracing, default) or ' \n WRITE(IOUT,*)' >= 0 do tracing every ITRACE'\n WRITE(IOUT,*)' iterations ' \n END SUBROUTINE PR_USAGE\n\nEND PROGRAM PDE90\n\n", "meta": {"hexsha": "b9f3fe64bf242a6ec4d1e65ffcf95cdc05413431", "size": 19722, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "power_pessl/pde90.f", "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": "power_pessl/pde90.f", "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": "power_pessl/pde90.f", "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": 32.5445544554, "max_line_length": 75, "alphanum_fraction": 0.5177466788, "num_tokens": 6612, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467770088162, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.6904015034274417}} {"text": "C\r\n\r\nC\r\nC\r\n PURE SUBROUTINE PARTS(COMP, XMOD, ANGL, SMALLNUM, PI)\r\n \r\n IMPLICIT NONE\r\nC\r\nC Dummy arguments\r\nC\r\n REAL(8) :: ANGL\r\n real(8), intent(in) :: PI\r\n real(8), intent(in) :: SMALLNUM\r\n REAL(8) :: XMOD\r\n REAL(8) , DIMENSION(2) :: COMP\r\n \r\n INTENT (IN) COMP\r\n INTENT (OUT) ANGL , XMOD\r\nC Local variables\r\n REAL(8) :: DABS\r\n REAL(8) :: DATAN2\r\n REAL(8) :: DSQRT\r\n REAL(8) :: R1\r\n REAL(8) :: R2\r\n \r\nC\r\n R1 = COMP(1)\r\n IF(DABS(R1) <= SMALLNUM)R1 = 0.D0\r\n R2 = COMP(2)\r\n IF(DABS(R2) <= SMALLNUM)R2 = 0.D0\r\nC\r\n XMOD = DSQRT(R1*R1 + R2*R2)\r\nC\r\n IF( DABS(R1) > SMALLNUM .AND. DABS(R2) > SMALLNUM )THEN\r\n ANGL = DATAN2(R2,R1)\r\n ELSE IF( DABS(R1) > SMALLNUM .AND. DABS(R2) < SMALLNUM )THEN\r\n IF( R1 > 0 )THEN\r\n ANGL = 0.D0\r\n ELSE\r\n ANGL = PI\r\n END IF\r\n ELSE IF( DABS(R1) < SMALLNUM .AND. DABS(R2) > SMALLNUM )THEN\r\n IF( R2 > 0 )THEN\r\n ANGL = PI * 0.5\r\n ELSE\r\n ANGL = PI * 1.5\r\n END IF\r\n ELSE\r\n ANGL = 0.D0\r\n END IF\r\nC\r\n RETURN\r\nC\r\n END", "meta": {"hexsha": "e6b70d30645ca95bfb48b08dc30ffbb37c34e1a1", "size": 1186, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/test/resources/com/woodplc/cora/refactoring/manual_ref_sub_f77.for", "max_stars_repo_name": "mchochlov/CoRA", "max_stars_repo_head_hexsha": "43a1ce77cbb7c50e887cf18935627aa5e57d2616", "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/test/resources/com/woodplc/cora/refactoring/manual_ref_sub_f77.for", "max_issues_repo_name": "mchochlov/CoRA", "max_issues_repo_head_hexsha": "43a1ce77cbb7c50e887cf18935627aa5e57d2616", "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/test/resources/com/woodplc/cora/refactoring/manual_ref_sub_f77.for", "max_forks_repo_name": "mchochlov/CoRA", "max_forks_repo_head_hexsha": "43a1ce77cbb7c50e887cf18935627aa5e57d2616", "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": 21.962962963, "max_line_length": 67, "alphanum_fraction": 0.4510961214, "num_tokens": 435, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.925229961215457, "lm_q2_score": 0.7461390043208003, "lm_q1q2_score": 0.6903501620290737}} {"text": "module vallado\n!! based on http://www.smad.com/vallado/\nuse, intrinsic:: iso_fortran_env, only: @wp_real@\n\nimplicit none (type, external)\nprivate\npublic:: toGST, toJulian, toLST, radec2azel, azel2radec\n\nreal(wp), parameter :: pi = 4._wp * atan(1.0_wp)\n\ntype,public :: datetime\ninteger :: year, month, day, hour, minute\nreal(wp) :: second\nend type\n\n\ncontains\n\nelemental subroutine azel2radec(azz,ell,llat,llon,jd, ra,decl)\n! convert azimuth, elevation to right ascension, declination\n!\n! inputs\n! ------\n! az, el: azimuth, elevation (degrees)\n! lat, lon: geodetic latitude, longitude (degrees)\n! jd: julian date (decimal)\n!\n! outputs\n! -------\n! ra, decl: right ascension, declination (degrees)\n\nreal(wp), intent(in) :: azz,ell,llat,llon\nreal(wp), intent(in) :: jd ! Julian Date\nreal(wp), intent(out) :: ra, decl\n\nreal(wp) :: lst, lha, sinv, cosv, az, el, lat, lon\n\naz = radians(azz)\nel = radians(ell)\nlat = radians(llat)\nlon = radians(llon)\n\nDecl = ASIN(SIN(El)*SIN(lat) + &\n COS(el)*COS(lat)*COS(Az) )\n\nSinv = -(SIN(az)*COS(el)*COS(lat)) / &\n (COS(lat)*COS(Decl))\n\nCosv = (SIN(el) - SIN(lat)*SIN(decl)) / &\n (COS(lat)*COS(Decl))\n\nLHA = ATAN2(Sinv,Cosv)\nlst = toLST(Lon, JD)\n\nra = modulo(degrees(LST - LHA), 360._wp)\ndecl = degrees(decl)\n\nend subroutine azel2radec\n\n\nelemental SUBROUTINE radec2azel(rra,dDecl,llat,llon,jd, Az,El)\n! convert right ascension, declination to azimuth, elevation\n!\n! inputs\n! ------\n! ra, decl: right ascension, declination (degrees)\n! lat, lon: geodetic latitude, longitude (degrees)\n! jd: julian date (decimal)\n!\n! outputs\n! -------\n! az, el: azimuth, elevation (degrees)\n\nREAL(wp), intent(in) :: rra,dDecl, llat, llon\nreal(wp), intent(in) :: jd\nreal(wp), intent(out) :: Az,El\n\nREAL(wp) :: Sinv, Cosv, LHA, lat, lon, ra, decl\n\nlat = radians(llat)\nlon = radians(llon)\nra = radians(rra)\ndecl = radians(ddecl)\n\nLHA = toLST(Lon, JD) - ra\n\nEl = ASIN( SIN(Decl)*SIN(lat) + &\n COS(Decl)*COS(lat)*COS(LHA) )\n\nSinv = -SIN(LHA)*COS(Decl)*COS(lat) / &\n (COS(el)*COS(lat))\n\nCosv = ( SIN(Decl)-SIN(el)*SIN(lat) ) / &\n (COS(el)*COS(lat))\n\nAz = modulo(degrees(ATAN2(Sinv,Cosv)), 360._wp)\nel = degrees(el)\n\n\nEND subroutine radec2azel\n\n\nelemental real(wp) function toLST(Lon, JD) result(LST)\n!! Julian Date => local sidereal time\n!!\n!! ## inputs\n!!\n!! * lon: geodetic longitude (radians)\n!! * jd: Julian Date (decimal)\n\nREAL(wp), intent(in) :: Lon, JD\n\nLST = Lon + toGST(jd)\n\nLST = modulo(LST, 2*pi )\n\nEND function toLST\n\n\nelemental real(wp) function toJulian(t) result(jd)\n! Gregorian date, time => Julian Date\n!\n! inputs\n! ------\n! time: Gregorian user-defined type\n!\n! output\n! -----\n! JD: Julian Date\n\ntype(datetime), intent(in) :: t\nreal(wp) :: B, y, m\n\ny = t%year\nm = t%month\n\nIF ( M <= 2 ) THEN\n Y = y - 1\n M = m + 12\nENDIF\n\nB = 2 - INT(Y*0.01_wp) + INT(INT(Y*0.01_wp)*0.25_wp)\n\nJD= INT( 365.25_wp*(Y + 4716) ) + &\n INT( 30.6001_wp*(M+1) ) + &\n t%day + B - 1524.5_wp + &\n ( (t%second/60.0_wp + t%minute ) / 60.0_wp + t%hour ) / 24.0_wp\n\nEND function toJulian\n\n\nelemental real(wp) FUNCTION toGST(JD) result(GST)\n! Julian Date => to Greenwich Sidereal Time\n!\n! inputs\n! ------\n! JD: Julian Date (decimal)\n!\n! output\n! ------\n! GST: Greenwich Sidereal Time (decimal)\n\nreal(wp), intent(in) :: JD\nreal(wp) :: TUT1\n\n\nTUT1= ( JD - 2451545._wp ) / 36525._wp\ngst = -6.2e-6_wp*TUT1**3 + &\n 0.093104_wp*TUT1**2 + &\n (876600._wp*3600._wp + 8640184.812866_wp)*TUT1 + &\n 67310.54841_wp\n\ngst = modulo(radians(gst) / 240._wp, 2*pi) ! 360/86400 = 1/240, to deg, to rad\n\nend function toGST\n\n\nelemental real(wp) function degrees(rad)\nreal(wp), intent(in) :: rad\n\ndegrees = 180._wp / pi * rad\nend function degrees\n\n\nelemental real(wp) function radians(deg)\nreal(wp), intent(in) :: deg\n\nradians = pi / 180._wp * deg\nend function radians\n\n\nend module vallado\n", "meta": {"hexsha": "16e35f9366bc1670a0b61b18ee83991f3fce6c4b", "size": 3849, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/vallado.in.f90", "max_stars_repo_name": "geospace-code/maptran3d", "max_stars_repo_head_hexsha": "c41e12171ac5a87ba6ab497a3d8b1cf2cddd2a58", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-07-24T23:22:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-10T09:36:56.000Z", "max_issues_repo_path": "src/vallado.in.f90", "max_issues_repo_name": "geospace-code/maptran3d", "max_issues_repo_head_hexsha": "c41e12171ac5a87ba6ab497a3d8b1cf2cddd2a58", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/vallado.in.f90", "max_forks_repo_name": "geospace-code/maptran3d", "max_forks_repo_head_hexsha": "c41e12171ac5a87ba6ab497a3d8b1cf2cddd2a58", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-01-31T08:55:13.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-31T08:55:13.000Z", "avg_line_length": 19.9430051813, "max_line_length": 78, "alphanum_fraction": 0.6331514679, "num_tokens": 1354, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92522995296862, "lm_q2_score": 0.746138993030751, "lm_q1q2_score": 0.6903501454298953}} {"text": "!!---------------------------------------------------------------------------------------\n!!----- Multi-material and multi-phase (EOS module)\n!!----- by\n!!----- Aditya K Pandare\n!!---------------------------------------------------------------------------------------\n\nMODULE eos\n \nUSE glob_var\n\nimplicit none\n\nCONTAINS\n\n!----------------------------------------------------------------------------------------------\n!----- Density from pressure using isothermal 'ideal-gas' eos\n!----------------------------------------------------------------------------------------------\n\nfunction eos1_density(pres)\n\nreal*8, intent(in) :: pres\n\nreal*8 :: eos1_density\n\n eos1_density = pres / (rgas*tinf)\n\nend function\n\n!----------------------------------------------------------------------------------------------\n!----- Density from pressure using Tait eos\n!----------------------------------------------------------------------------------------------\n\nfunction eos2_density(pres)\n\nreal*8, intent(in) :: pres\n\nreal*8 :: eos2_density\n\n eos2_density = rho0 * (1.0 + n0/k0 * (pres - p0))**(1.0/n0)\n\nend function\n\n!----------------------------------------------------------------------------------------------\n!----- speed of sound using Tait eos\n!----------------------------------------------------------------------------------------------\n\nfunction eos2_ssound(rho)\n\nreal*8, intent(in) :: rho\n\nreal*8 :: eos2_ssound\n\n eos2_ssound = dsqrt(k0/(rho0**n0) * (rho**(n0-1.0)))\n\nend function\n\n!----------------------------------------------------------------------------------------------\n!----- Density from pressure and temperature using stiffened gas eos\n!----------------------------------------------------------------------------------------------\n\nfunction eos3_density(gam, cp, p_c, pres, temp)\n\nreal*8, intent(in) :: gam, cp, p_c, pres, temp\n\nreal*8 :: eos3_density\n\n eos3_density = gam * (pres + p_c) / ((gam - 1.0) * cp * temp)\n\nend function\n\n!----------------------------------------------------------------------------------------------\n!----- Total energy from pressure and density using stiffened gas eos\n!----------------------------------------------------------------------------------------------\n\nfunction eos3_rhoe(gam, p_c, pres, rho, u)\n\nreal*8, intent(in) :: gam, p_c, pres, rho, u\n\nreal*8 :: eos3_rhoe\n\n eos3_rhoe = (pres + p_c)/(gam - 1.0) + (0.5*rho*u*u) + p_c;\n\nend function\n\n!----------------------------------------------------------------------------------------------\n!----- Pressure from total energy and density using stiffened gas eos\n!----------------------------------------------------------------------------------------------\n\nfunction eos3_pr(gam, p_c, rho, rhoe, u)\n\nreal*8, intent(in) :: gam, p_c, rho, rhoe, u\n\nreal*8 :: eos3_pr\n\n eos3_pr = (gam - 1.0) * (rhoe - 0.5*rho*u*u - p_c) - p_c;\n\nend function\n\n!----------------------------------------------------------------------------------------------\n!----- Vol-frac times pressure from total energy and density using sgeos\n!----------------------------------------------------------------------------------------------\n\nfunction eos3_alphapr(gam, p_c, alpha, arho, arhoe, u)\n\nreal*8, intent(in) :: gam, p_c, alpha, arho, arhoe, u\n\nreal*8 :: eos3_alphapr\n\n eos3_alphapr = (gam - 1.0) * (arhoe - 0.5*arho*u*u - alpha*p_c) - alpha*p_c;\n\nend function\n\n!----------------------------------------------------------------------------------------------\n!----- Temperature from total energy and density using stiffened gas eos\n!----------------------------------------------------------------------------------------------\n\nfunction eos3_t(gam, cp, p_c, rho, rhoe, u)\n\nreal*8, intent(in) :: gam, cp, p_c, rho, rhoe, u\n\nreal*8 :: eos3_t\n\n eos3_t = (rhoe - (0.5*rho*u*u) - p_c) * (gam/(rho * cp));\n\nend function\n\n!----------------------------------------------------------------------------------------------\n!----- speed of sound from density and pressure using stiffened gas eos\n!----------------------------------------------------------------------------------------------\n\nfunction eos3_ss(gam, p_c, arho, al, apr)\n\nreal*8, intent(in) :: gam, p_c, arho, al, apr\n\nreal*8 :: pre, eos3_ss\n\n pre = max(apr+al*p_c, 1.0d-14);\n if (arho .lt. 1.0d-16) then\n if (al .le. 100.0*g_alphamin) then\n eos3_ss = 0.0\n else\n write(*,*) \"Error: zero/negative density encountered in speed of sound calculation: \", arho\n write(*,*) \" Volume-fraction: \", al\n call exit\n end if\n else\n eos3_ss = dsqrt(gam *pre/arho);\n end if\n\nend function\n\n!----------------------------------------------------------------------------------------------\n!----- Get primitive variables for a mesh element from conserved\n!----------------------------------------------------------------------------------------------\n\nsubroutine get_uprim_mm6eq(ucons, uprim)\n\nreal*8, intent(in) :: ucons(g_neqns)\n\ninteger :: i\nreal*8 :: almat(g_mmi%nummat), pmat(g_mmi%nummat), tmat(g_mmi%nummat), &\n rhomat(g_mmi%nummat), rhoemat(g_mmi%nummat), u, rho\nreal*8 :: uprim(g_neqns)\n\nassociate (nummat=>g_mmi%nummat)\n\n ! bulk state\n rho = sum( ucons(g_mmi%irmin:g_mmi%irmax) )\n u = ucons(g_mmi%imome) / rho\n uprim(g_mmi%imome) = u\n\n ! material states\n do i = 1,nummat\n ! conserved variables\n almat(i) = ucons(i)\n rhomat(i) = ucons(g_mmi%irmin+i-1) / almat(i)\n rhoemat(i) = ucons(g_mmi%iemin+i-1) / almat(i)\n ! primitive variables\n pmat(i) = eos3_pr(g_gam(i), g_pc(i), rhomat(i), rhoemat(i), u)\n tmat(i) = eos3_t(g_gam(i), g_cp(i), g_pc(i), rhomat(i), rhoemat(i), u)\n\n uprim(i) = almat(i)\n uprim(g_mmi%irmin+i-1) = pmat(i)\n uprim(g_mmi%iemin+i-1) = tmat(i)\n end do !i\n\nend associate\n\nend subroutine get_uprim_mm6eq\n\n!----------------------------------------------------------------------------------------------\n!----- Tiny phase treatment for mm6eq:\n!----- ignore it\n!----------------------------------------------------------------------------------------------\n\nsubroutine ignore_tinyphase_mm6eq(ucons, uprim)\n\ninteger :: ie, i, mmax\nreal*8 :: almat(g_mmi%nummat), pmax, tmax, &\n rhomat, rhoemat, &\n al_eps, rho, u, alsum, d_al, d_are, are_new, &\n apk, ak, kmat(g_mmi%nummat), &\n p_target, ratio, &\n ucons(g_tdof,g_neqns,0:imax+1), &\n uprim(g_tdof,g_nprim,0:imax+1)\n\nassociate (nummat=>g_mmi%nummat)\n\n al_eps = 1d-2\n\n do ie = 1,imax\n\n !--- find material in largest quantity\n almat = ucons(1,g_mmi%iamin:g_mmi%iamax,ie)\n mmax = maxloc(almat, 1)\n\n rhomat = ucons(1,g_mmi%irmin+mmax-1,ie)/almat(mmax)\n rhoemat = ucons(1,g_mmi%iemin+mmax-1,ie)/almat(mmax)\n rho = sum(ucons(1,g_mmi%irmin:g_mmi%irmax,ie))\n u = uprim(1,vel_idx(nummat, 0),ie)\n pmax = uprim(1,apr_idx(nummat, mmax),ie)/almat(mmax)\n tmax = eos3_t(g_gam(mmax), g_cp(mmax), g_pc(mmax), rhomat, rhoemat, u)\n\n !--- get equilibrium pressure\n !p_target = 0.0\n !ratio = 0.0\n !do i = 1,nummat\n ! rhomat = ucons(1,g_mmi%irmin+i-1,ie)\n ! apk = uprim(1,apr_idx(nummat, i),ie)\n ! ak = eos3_ss(g_gam(i), g_pc(i), rhomat, almat(i), apk)\n ! kmat(i) = rhomat * ak * ak / almat(i)\n\n ! p_target = p_target + (almat(i) * apk / kmat(i))\n ! ratio = ratio + (almat(i) * almat(i) / kmat(i))\n !end do !i\n !p_target = p_target / ratio\n !p_target = max(p_target, 1d-14)\n p_target = max(pmax, 1d-14)\n\n !--- correct minority materials and store volume/energy changes\n d_al = 0.0\n d_are = 0.0\n do i = 1,nummat\n apk = uprim(1,apr_idx(nummat, i),ie)/almat(i)\n ! positive volfrac\n if (almat(i) > 0.0) then\n ! pressure relaxation\n if ((almat(i) <= al_eps) &! .and. dabs(apk-pmax)/pmax > 1e-4) &\n .or. (apk+g_pc(i) < 0.0)) then\n rhomat = ucons(1,g_mmi%irmin+i-1,ie) / almat(i)\n are_new = almat(i) * eos3_rhoe(g_gam(i), g_pc(i), p_target, rhomat, u)\n d_are = d_are + ucons(1,g_mmi%iemin+i-1,ie) - are_new\n\n ucons(1,g_mmi%iemin+i-1,ie) = are_new\n uprim(1,apr_idx(nummat, i),ie) = almat(i) * p_target\n end if\n ! negative volfrac\n else if (almat(i) < 0.0) then\n rhomat = eos3_density(g_gam(i), g_cp(i), g_pc(i), p_target, tmax)\n d_al = d_al + (almat(i) - 1d-14)\n\n ucons(1,g_mmi%iamin+i-1,ie) = 1d-14\n ucons(1,g_mmi%irmin+i-1,ie) = 1d-14 * rhomat\n ucons(1,g_mmi%iemin+i-1,ie) = 1d-14 * eos3_rhoe(g_gam(i), g_pc(i), &\n p_target, rhomat, u)\n uprim(1,apr_idx(nummat, i),ie) = 1d-14 * p_target\n end if\n end do !i\n\n !--- update state of majority material\n ucons(1,g_mmi%iamin+mmax-1,ie) = ucons(1,g_mmi%iamin+mmax-1,ie) + d_al\n almat(mmax) = ucons(1,g_mmi%iamin+mmax-1,ie)\n ucons(1,g_mmi%iemin+mmax-1,ie) = ucons(1,g_mmi%iemin+mmax-1,ie) + d_are\n uprim(1,apr_idx(nummat, mmax),ie) = eos3_alphapr(g_gam(mmax), g_pc(mmax), &\n almat(mmax), ucons(1,g_mmi%irmin+mmax-1,ie), &\n ucons(1,g_mmi%iemin+mmax-1,ie), u)\n\n !--- enforce unit sum\n alsum = 0.0\n do i = 1,nummat\n alsum = alsum + ucons(1,g_mmi%iamin+i-1,ie)\n end do !i\n\n do i = 1,nummat\n ucons(1,g_mmi%iamin+i-1,ie) = ucons(1,g_mmi%iamin+i-1,ie) / alsum\n ucons(1,g_mmi%irmin+i-1,ie) = ucons(1,g_mmi%irmin+i-1,ie) / alsum\n ucons(1,g_mmi%iemin+i-1,ie) = ucons(1,g_mmi%iemin+i-1,ie) / alsum\n uprim(1,apr_idx(nummat, i),ie) = uprim(1,apr_idx(nummat, i),ie) / alsum\n end do !i\n\n end do !ie\n\nend associate\n\nend subroutine ignore_tinyphase_mm6eq\n\n!----------------------------------------------------------------------------------------------\n!----- Check if volume fraction satisfies [0,1] bounds\n!----------------------------------------------------------------------------------------------\n\nsubroutine check_volfrac(ie,uc)\n\ninteger, intent(in) :: ie\nreal*8, intent(in) :: uc(g_neqns)\n\ninteger :: imat, mmax\nreal*8 :: eps\n\nassociate (nummat=>g_mmi%nummat)\n\n eps = 0.0001*g_alphamin\n\n !do imat = 1,nummat\n\n ! if ( (uc(imat) .lt. eps) .or. (uc(imat) .gt. 1.0-eps) ) then\n ! write(*,*) \"------------------------------------------------------------------\"\n ! write(*,*) \"Bound-violating volume fraction: \", uc(imat)\n ! write(*,*) \" in cell \", ie\n ! write(*,*) \" material-id: \", imat\n ! write(*,*) \" density: \", uc(g_mmi%irmin+imat-1)\n ! write(*,*) \" total-energy: \", uc(g_mmi%iemin+imat-1)\n ! write(*,*) \"------------------------------------------------------------------\"\n ! write(*,*) \" \"\n ! end if\n\n !end do !imat\n\nend associate\n\nend subroutine check_volfrac\n\n!----------------------------------------------------------------------------------------------\n\nEND MODULE eos\n", "meta": {"hexsha": "a476eae1776a22e95133ada8ccee6a1931038bfe", "size": 10726, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "src/eos.f03", "max_stars_repo_name": "lanl/multimat_1drdg", "max_stars_repo_head_hexsha": "3a22ae85c2143d20b15d22e98a9bf92d5e2d9039", "max_stars_repo_licenses": ["BSD-3-Clause", "Unlicense"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-09-02T18:09:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-25T16:31:50.000Z", "max_issues_repo_path": "src/eos.f03", "max_issues_repo_name": "lanl/multimat_1drdg", "max_issues_repo_head_hexsha": "3a22ae85c2143d20b15d22e98a9bf92d5e2d9039", "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": "src/eos.f03", "max_forks_repo_name": "lanl/multimat_1drdg", "max_forks_repo_head_hexsha": "3a22ae85c2143d20b15d22e98a9bf92d5e2d9039", "max_forks_repo_licenses": ["BSD-3-Clause", "Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.0179104478, "max_line_length": 99, "alphanum_fraction": 0.4546895394, "num_tokens": 3175, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299509069105, "lm_q2_score": 0.7461389817407016, "lm_q1q2_score": 0.6903501334456815}} {"text": "! VERSION 1.0 2/5/99\n!*********************************************************************\n\n! MODIFIED BESSEL FUNCTIONS OF THE FIRST\n! KIND OF INTEGER ORDER AND REAL ARGUMENT\n! ---------------------------------------\n\n! This double precision function subroutine calculates the\n! value of the modified Bessel function of the first kind of\n! integer order and strictly real argument via a backward\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! Bug in small-argument Taylor series expansion fixed by DEB OCT-92\n\n\n! Includes:\n! rndoff.inc\n\n! Uses:\n! bessi0.f\n! bessi1.f\n\n!*********************************************************************\n\n function bessi(n,z)\n implicit none\n integer :: n\n double precision :: bessi,z\n\n include 'rndoff.inc'\n\n double precision :: bessi0,bessi1\n external bessi0,bessi1\n\n integer :: iacc\n double precision :: bigno,bigni\n parameter (iacc=40,bigno=1.0D10,bigni=1.0D-10)\n\n integer :: i,m,mmax\n double precision :: x,phase,twobyx,bi,bip,bim\n\n intrinsic abs\n\n!#####################################################################\n\n!---------------------------------------------------------------------\n! get proper phase factor if argument is negative with the\n! following rules\n! n\n! I (z) = I (z) and I (-z) = (-1) I (z)\n! n -n n n\n!---------------------------------------------------------------------\n\n m=abs(n)\n x=abs(z)\n\n if ((z < 0.0D0) .AND. (mod(m,2) == 1)) then\n phase=-1.0D0\n else\n phase=1.0D0\n end if\n\n!---------------------------------------------------------------------\n! return proper values if argument is zero\n!---------------------------------------------------------------------\n\n if (x < rndoff) then\n if (m == 0) then\n bessi=1.0D0\n else\n bessi=0.0D0\n end if\n return\n end if\n\n!---------------------------------------------------------------------\n! call bessi0 if n=0, bessi1 if n=1, or go through\n! downward recurrence if n>1.\n!---------------------------------------------------------------------\n\n if (m == 0) then\n bessi=phase*bessi0(x)\n else if (m == 1) then\n bessi=phase*bessi1(x)\n else\n bessi=0.0D0\n twobyx=2.0D0/x\n bip=0.0D0\n bi=1.0D0\n mmax=2*((m+int(sqrt(dble(iacc*m)))))\n do 10 i=mmax,1,-1\n bim=bip+dble(i)*twobyx*bi\n bip=bi\n bi=bim\n if (abs(bi) > bigno) then\n bessi=bessi*bigni\n bi=bi*bigni\n bip=bip*bigni\n end if\n if (i == m) bessi=bip\n 10 END DO\n bessi=phase*bessi*bessi0(x)/bi\n end if\n\n return\n end function bessi\n\n!*********************************************************************\n\n! MODIFIED BESSEL FUNCTION OF THE FIRST\n! KIND OF ORDER ZERO AND REAL ARGUMENT\n! -------------------------------------\n\n! This double precision function subroutine calculates the\n! modified Bessel function of the first kind of order zero\n! and real argument by either the Taylor series expansion\n! for small arguments or the first term of the asymptotic\n! series for sufficiently large arguments.\n\n! written by DJS 10-SEP-87\n\n! Includes:\n! rndoff.inc\n! pidef.inc\n\n! Uses:\n\n!*********************************************************************\n\n function bessi0(z)\n\n include 'rndoff.inc'\n! include 'pidef.inc'\n double precision :: pi,radian\n parameter (pi=3.1415926535897932384D0,radian=pi/180.0D0)\n\n\n double precision :: bessi0\n double precision :: z\n\n integer :: i,j\n double precision :: x,y,smax,temp1,temp2,temp3,sum\n\n integer :: nmax\n parameter (nmax=40)\n\n double precision :: tser\n dimension tser(nmax)\n\n double precision :: cutoff\n parameter (cutoff=20.0D0)\n\n!######################################################################\n\n y=abs(z)\n\n!------------------------------------------------------------\n! Set function value to unity if argument is too small\n!------------------------------------------------------------\n if (y < rndoff) then\n bessi0=1.0D0\n \n !-------------------------------------------------------------\n ! Taylor series expansion for small to moderate arguments\n !-------------------------------------------------------------\n else if (y <= cutoff) then\n x=y*y*0.25D0\n temp1=1.0D0\n smax=1.0D0\n i=1\n 10 temp1=(temp1/dble(i))*(x/dble(i))\n if (i > nmax) then\n write(*,1000)\n stop\n end if\n tser(i)=temp1\n i=i+1\n if (temp1 > smax) smax=temp1\n if (temp1/smax > rndoff) go to 10\n \n bessi0=0.0D0\n do 20 j=i-1,1,-1\n bessi0=bessi0+tser(j)\n 20 END DO\n bessi0=bessi0+1.0D0\n \n !----------------------------------------------\n ! Asymptotic expansion for large arguments\n !----------------------------------------------\n else\n x=0.125D0/y\n sum=0.0D0\n temp3=1.0D0\n smax=1.0D0\n i=1\n 30 temp1=dble(2*i-1)\n temp2=(x*temp1)*(temp1/dble(i))\n if (temp2 > 1.0D0) go to 40\n temp3=temp3*temp2\n if (temp3 > smax) smax=temp3\n if (temp3/smax < rndoff) go to 40\n sum=sum+temp3\n i=i+1\n go to 30\n 40 bessi0=dexp(y)*((sum+1.0D0)/dsqrt(y*(pi+pi)))\n end if\n\n return\n\n 1000 format('bessi0: Taylor series did not converge')\n end function bessi0\n\n!*********************************************************************\n\n! MODIFIED BESSEL FUNCTION OF THE FIRST\n! KIND OF ORDER ONE AND REAL ARGUMENT\n! -------------------------------------\n\n! This double precision function subroutine calculates the\n! modified Bessel function of the first kind of order one\n! and real argument by either the Taylor series expansion\n! for small arguments or the first term of the asymptotic\n! series for sufficiently large arguments.\n\n! written by DJS 10-SEP-87\n\n! Includes:\n! rndoff.inc\n! pidef.inc\n\n! Uses:\n\n!*********************************************************************\n\n function bessi1(z)\n\n include 'rndoff.inc'\n! include 'pidef.inc'\n double precision :: pi,radian\n parameter (pi=3.1415926535897932384D0,radian=pi/180.0D0)\n\n double precision :: bessi1\n double precision :: z\n\n integer :: i,j\n double precision :: x,y,smax,temp1,temp2,temp3,phase,sum\n\n integer :: nmax\n parameter (nmax=40)\n\n double precision :: series\n dimension series(nmax)\n\n double precision :: cutoff\n parameter (cutoff=20.0D0)\n\n!#####################################################################\n\n if (z > 0.0D0) then\n phase=1.0D0\n y=z\n else\n phase=-1.0D0\n y=-z\n end if\n\n!----------------------------------------------------------------------\n! set answer to zero if argument is too small, otherwise\n!----------------------------------------------------------------------\n if (y < rndoff) then\n bessi1=0.0D0\n \n !----------------------------------------------------------------------\n ! Use Taylor series expansion for small to moderate arguments or\n !----------------------------------------------------------------------\n else if (y <= cutoff) then\n x=y*y*0.25D0\n temp1=1.0D0\n smax=1.0D0\n i=1\n 10 temp1=(temp1/dble(i))*(x/dble(i+1))\n if (i > nmax) then\n write(*,1000)\n stop\n end if\n series(i)=temp1\n i=i+1\n if (temp1 > smax) smax=temp1\n if (temp1/smax > rndoff) go to 10\n bessi1=0.0D0\n do 20 j=i-1,1,-1\n bessi1=bessi1+series(j)\n 20 END DO\n bessi1=phase*y*0.5D0*(bessi1+1.0D0)\n \n !----------------------------------------------------------------------\n ! asymptotic expansion for large arguments\n !----------------------------------------------------------------------\n else\n x=0.125D0/y\n sum=3.0D0*x\n temp3=sum\n smax=1.0D0\n i=2\n 30 temp1=dble(2*i-1)\n temp1=temp1*temp1-4.0D0\n temp2=(x*temp1)/dble(i)\n if (temp2 > 1.0D0) go to 40\n temp3=temp3*temp2\n if (temp3 > smax) smax=temp3\n if (temp3/smax < rndoff) go to 40\n sum=sum+temp3\n i=i+1\n go to 30\n 40 bessi1=dexp(y)*(1.0D0-sum)/dsqrt(y*(pi+pi))\n end if\n\n return\n\n!----------------------------------------------------------------------\n 1000 format('bessi0: Taylor series did not converge')\n end function bessi1\n", "meta": {"hexsha": "7a55a1e8aa65d042efe52d4daa65a17e2caac5bf", "size": 9188, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lsld2/minimalistic/bessel.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/bessel.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/bessel.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": 28.1840490798, "max_line_length": 75, "alphanum_fraction": 0.422398781, "num_tokens": 2396, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299488452012, "lm_q2_score": 0.7461389817407016, "lm_q1q2_score": 0.6903501319073598}} {"text": " real*8 function theta(r20,thk,tmp) result (r_theta)\r\n \r\n!! ~ ~ ~ PURPOSE ~ ~ ~\r\n!! this function corrects rate constants for temperature\r\n!! Equation is III-52 from QUAL2E\r\n\r\n!! ~ ~ ~ INCOMING VARIABLES ~ ~ ~\r\n!! name |units |definition\r\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\r\n!! r20 |1/day |value of the reaction rate coefficient at\r\n!! |the standard temperature (20 degrees C)\r\n!! thk |none |temperature adjustment factor (empirical\r\n!! |constant for each reaction coefficient)\r\n!! tmp |deg C |temperature on current day\r\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\r\n\r\n!! ~ ~ ~ OUTGOING VARIABLES ~ ~ ~\r\n!! name |units |definition\r\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\r\n!! theta |1/day |value of the reaction rate coefficient at\r\n!! |the local temperature\r\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\r\n\r\n!! ~ ~ ~ ~ ~ ~ END SPECIFICATIONS ~ ~ ~ ~ ~ ~\r\n\r\n real*8, intent (in) :: r20, thk, tmp\r\n\r\n r_theta = 0.\r\n r_theta = r20 * thk ** (tmp - 20.)\r\n\r\n return\r\n end", "meta": {"hexsha": "a7b71f1875262e2b38c89279be43b85d4ba43209", "size": 1359, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "swat_cli/rev670_source/theta.f", "max_stars_repo_name": "GISWAT/erosion-sediment", "max_stars_repo_head_hexsha": "6ab469eba99cba8e5c365cd4d18cba2e8781ccf6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-06-05T06:33:14.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-05T06:33:14.000Z", "max_issues_repo_path": "swat_cli/rev670_source/theta.f", "max_issues_repo_name": "GISWAT/erosion-sediment", "max_issues_repo_head_hexsha": "6ab469eba99cba8e5c365cd4d18cba2e8781ccf6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "swat_cli/rev670_source/theta.f", "max_forks_repo_name": "GISWAT/erosion-sediment", "max_forks_repo_head_hexsha": "6ab469eba99cba8e5c365cd4d18cba2e8781ccf6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.46875, "max_line_length": 76, "alphanum_fraction": 0.374540103, "num_tokens": 407, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768635777511, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6902485958624868}} {"text": "C Return radius for a given lat,lon.\nC Longitudes may be either east or west.\nC\n subroutine ellipse_radius(lat,lon,ra,rb,rc,lora,gcr)\n implicit none\n real*8 lat,lon\t\t!Input lat,lon coordinates\n real*8 ra,rb,rc\t\t!Input target body radii\n real*8 lora\t\t!Longitude of semi-major axis\n real*8 gcr\t\t!geocentric radius\n real*8 rlat,rlon,clat,slat,clon,slon,dtor,PI\n\n PI = 3.141592653589793D0\n dtor = PI/180.d0\t\t!degrees to radians\n rlat = lat*dtor\t\t!convert to radians\n rlon = (lon-lora)*dtor\n clat = dcos(rlat)\n slat = dsin(rlat)\n clon = dcos(rlon)\n slon = dsin(rlon)\n gcr = 1.d0/dsqrt((clat*clon/ra)**2+(clat*slon/rb)**2+(slat/rc)**2)\n return\n end\n", "meta": {"hexsha": "9588cd59342e9441058e8f36cefb8d17e9f31158", "size": 733, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "vos/p2/sub/ellipse_proj/ellipse_radius.f", "max_stars_repo_name": "NASA-AMMOS/VICAR", "max_stars_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2020-10-21T05:56:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T10:02:01.000Z", "max_issues_repo_path": "vos/p2/sub/ellipse_proj/ellipse_radius.f", "max_issues_repo_name": "NASA-AMMOS/VICAR", "max_issues_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "vos/p2/sub/ellipse_proj/ellipse_radius.f", "max_forks_repo_name": "NASA-AMMOS/VICAR", "max_forks_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-03-09T01:51:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-23T00:23:24.000Z", "avg_line_length": 31.8695652174, "max_line_length": 72, "alphanum_fraction": 0.6248294679, "num_tokens": 273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545392102523, "lm_q2_score": 0.7279754489059775, "lm_q1q2_score": 0.6902332263138237}} {"text": "SUBROUTINE fmplat(d2x,d2y,d2xy,points,aa,bb,i)\n!\n! This subroutine forms the 2nd derivatives for rectangular\n! plate bending elements.\n!\n IMPLICIT NONE\n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\n REAL(iwp),INTENT(IN)::points(:,:),aa,bb\n REAL(iwp),INTENT(OUT)::d2x(:),d2y(:),d2xy(:)\n INTEGER,INTENT(IN)::i\n REAL(iwp)::x,e,xp1,xp12,xp13,ep1,ep12,ep13,p1,q1,p2,q2,p3,q3,p4,q4,dp1, &\n dq1,dp2,dq2,dp3,dq3,dp4,dq4,d2p1,d2p2,d2p3,d2p4,d2q1,d2q2,d2q3,d2q4, &\n pt25=0.25_iwp,pt375=0.375_iwp,pt5=0.5_iwp,pt75=0.75_iwp,one=1.0_iwp, &\n opt5=1.5_iwp,d3=3.0_iwp\n x=points(i,1)\n e=points(i,2)\n xp1=x+one\n xp12=xp1*xp1\n xp13=xp12*xp1\n ep1=e+one\n ep12=ep1*ep1\n ep13=ep12*ep1\n p1=one-pt75*xp12+pt25*xp13\n q1=one-pt75*ep12+pt25*ep13\n p2=pt5*aa*xp1*(one-xp1+pt25*xp12)\n q2=pt5*bb*ep1*(one-ep1+pt25*ep12)\n p3=pt25*xp12*(d3-xp1)\n q3=pt25*ep12*(d3-ep1)\n p4=pt25*aa*xp12*(pt5*xp1-one)\n q4=pt25*bb*ep12*(pt5*ep1-one)\n dp1=opt5*xp1*(pt5*xp1-one)\n dq1=opt5*ep1*(pt5*ep1-one)\n dp2=aa*(pt5-xp1+pt375*xp12)\n dq2=bb*(pt5-ep1+pt375*ep12)\n dp3=opt5*xp1*(one-pt5*xp1)\n dq3=opt5*ep1*(one-pt5*ep1)\n dp4=pt5*aa*xp1*(pt75*xp1-one)\n dq4=pt5*bb*ep1*(pt75*ep1-one)\n d2p1=opt5*x\n d2p2=pt25*aa*(d3*x-one)\n d2p3=-d2p1\n d2p4=pt25*aa*(d3*x+one)\n d2q1=opt5*e\n d2q2=pt25*bb*(d3*e-one)\n d2q3=-d2q1\n d2q4=pt25*bb*(d3*e+one)\n d2x(1)=d2p1*q1\n d2x(2)=d2p2*q1\n d2x(3)=d2p1*q2\n d2x(4)=d2p2*q2\n d2x(5)=d2p1*q3\n d2x(6)=d2p2*q3\n d2x(7)=d2p1*q4\n d2x(8)=d2p2*q4\n d2x(9)=d2p3*q3\n d2x(10)=d2p4*q3\n d2x(11)=d2p3*q4\n d2x(12)=d2p4*q4\n d2x(13)=d2p3*q1\n d2x(14)=d2p4*q1\n d2x(15)=d2p3*q2\n d2x(16)=d2p4*q2\n d2y(1)=p1*d2q1\n d2y(2)=p2*d2q1\n d2y(3)=p1*d2q2\n d2y(4)=p2*d2q2\n d2y(5)=p1*d2q3\n d2y(6)=p2*d2q3\n d2y(7)=p1*d2q4\n d2y(8)=p2*d2q4\n d2y(9)=p3*d2q3\n d2y(10)=p4*d2q3\n d2y(11)=p3*d2q4\n d2y(12)=p4*d2q4\n d2y(13)=p3*d2q1\n d2y(14)=p4*d2q1\n d2y(15)=p3*d2q2\n d2y(16)=p4*d2q2\n d2xy(1)=dp1*dq1\n d2xy(2)=dp2*dq1\n d2xy(3)=dp1*dq2\n d2xy(4)=dp2*dq2\n d2xy(5)=dp1*dq3\n d2xy(6)=dp2*dq3\n d2xy(7)=dp1*dq4\n d2xy(8)=dp2*dq4\n d2xy(9)=dp3*dq3\n d2xy(10)=dp4*dq3\n d2xy(11)=dp3*dq4\n d2xy(12)=dp4*dq4\n d2xy(13)=dp3*dq1\n d2xy(14)=dp4*dq1\n d2xy(15)=dp3*dq2\n d2xy(16)=dp4*dq2\nRETURN\nEND SUBROUTINE fmplat\n", "meta": {"hexsha": "c5fd360e2d2c11e9a60c6b53b4aedebdddeee5ff", "size": 2124, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "main/fmplat.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/fmplat.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/fmplat.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": 21.8969072165, "max_line_length": 75, "alphanum_fraction": 0.6746704331, "num_tokens": 1326, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850021922959, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6901901319128657}} {"text": "!*********************************************************************\n! This file is part of Polylogarithm.\n!\n! Polylogarithm is licenced under the MIT License.\n!*********************************************************************\n\n!*********************************************************************\n!> @brief Clausen function \\f$\\operatorname{Cl}_4(\\theta) = \\operatorname{Im}(\\operatorname{Li}_4(e^{i\\theta}))\\f$\n!> @param x real angle\n!> @return \\f$\\operatorname{Cl}_4(\\theta)\\f$\n!> @author Alexander Voigt\n!> Implemented as rational function approximation.\n!*********************************************************************\n\ndouble precision function dcl4(x)\n implicit none\n double precision :: x, y, z, z2, z4, p, q, p0, p1, h, sgn\n double precision, parameter :: PI = 3.14159265358979324D0\n double precision, parameter :: PI2 = 2*PI, PIH = PI/2, PI28 = PI*PI/8\n double precision, parameter :: zeta3 = 1.2020569031595943D0\n double precision, parameter :: cp(4) = (/ &\n -3.0555555555555556D-1, &\n 6.0521392328447206D-3, &\n -1.9587493942041528D-5, &\n -3.1137343767030358D-8 /)\n double precision, parameter :: cq(4) = (/ &\n 1.0000000000000000D+0, &\n -2.2079728398400851D-2, &\n 1.0887447112236682D-4, &\n -6.1847621370547954D-8 /)\n double precision, parameter :: cr(6) = (/ &\n 7.6223911686491336D-1, &\n -2.4339587368267260D-1, &\n 2.8715364937979943D-2, &\n -1.5368612510964667D-3, &\n 3.6261044225761673D-5, &\n -2.8557977333851308D-7 /)\n double precision, parameter :: cs(6) = (/ &\n 1.0000000000000000D+0, &\n -1.7465715261403233D-1, &\n 9.5439417991615653D-3, &\n -1.7325070821666274D-4, &\n 5.9283675098376635D-7, &\n 9.4127575773361230D-10 /)\n\n sgn = 1\n\n if (x .lt. 0) then\n x = -x\n sgn = -1\n endif\n\n if (x .ge. PI2) then\n x = mod(x, PI2)\n endif\n\n if (x .gt. PI) then\n p0 = 6.28125D0\n p1 = 0.0019353071795864769253D0\n x = (p0 - x) + p1\n sgn = -sgn\n endif\n\n if (x .eq. 0 .or. x .eq. PI) then\n dcl4 = 0\n return\n endif\n\n if (x .lt. PIH) then\n y = x*x\n z = y*y\n p = cp(1) + y * cp(2) + z * (cp(3) + y * cp(4))\n q = cq(1) + y * cq(2) + z * (cq(3) + y * cq(4))\n h = x*(zeta3 + y*(p/q + log(x)/6))\n else\n y = PI - x\n z = y*y - PI28\n z2 = z*z\n z4 = z2*z2\n p = cr(1) + z * cr(2) + z2 * (cr(3) + z * cr(4)) + &\n z4 * (cr(5) + z * cr(6))\n q = cs(1) + z * cs(2) + z2 * (cs(3) + z * cs(4)) + &\n z4 * (cs(5) + z * cs(6))\n h = y*p/q\n endif\n\n dcl4 = sgn*h\n\nend function dcl4\n", "meta": {"hexsha": "64c4b247a8597cdd2d5ba0a97ac5136a1a8d556d", "size": 2865, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/Cl4.f90", "max_stars_repo_name": "Expander/dilogarithm", "max_stars_repo_head_hexsha": "ad86038206895ab5bff79a26294f4bb5c5634eb5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-05-04T14:47:41.000Z", "max_stars_repo_stars_event_max_datetime": "2017-08-02T13:13:45.000Z", "max_issues_repo_path": "src/fortran/Cl4.f90", "max_issues_repo_name": "Expander/dilogarithm", "max_issues_repo_head_hexsha": "ad86038206895ab5bff79a26294f4bb5c5634eb5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/fortran/Cl4.f90", "max_forks_repo_name": "Expander/dilogarithm", "max_forks_repo_head_hexsha": "ad86038206895ab5bff79a26294f4bb5c5634eb5", "max_forks_repo_licenses": ["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.8333333333, "max_line_length": 114, "alphanum_fraction": 0.4460732984, "num_tokens": 1023, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533032291501, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.6901780341931393}} {"text": "subroutine interp2(x,y,v,n1,n2,a,b,NZ)\n implicit none\n integer*4::n1,n2;\n integer*4,dimension(1)::sx,sy;\n real*8(n2,n1)::v;\n real*8(n1):: x;\n real*8(n2):: y;\n real*8(1,1):: NZ1,v1,v2,v3,v4,v5;\n real*8(1):: x1,x2,x3,y1,y2,y3\n real*8::a,b,NZ\n sx=minloc(abs(x-a));sy=minloc(abs(y-b));\n y1=y(sy);x1=x(sx);\n y2=y(sy-1);x2=x(sx-1);y3=y(sy+1);x3=x(sx+1);\n v1=v(sy,sx);v2=v(sy,sx-1);v3=v(sy-1,sx);v4=v(sy+1,sx);\n v5=v(sy,sx+1);\n if((y1(1)>b).AND.(x1(1)>a))then\n NZ1=v1(1,1)-(v1(1,1)-v2(1,1))/(x1(1)-x2(1))*(x1(1)-a)&\n &-(v1(1,1)-v3(1,1))/(y1(1)-y2(1))*(y1(1)-b);\n else if((y1(1)<=b).AND.(x1(1)>a))then\n NZ1=v1(1,1)-(v1(1,1)-v2(1,1))/(x1(1)-x2(1))*(x1(1)-a)&\n &-(v4(1,1)-v1(1,1))/(y3(1)-y1(1))*(y1(1)-b);\n else if(y1(1)>b.AND.x1(1)<=a)then\n NZ1=v1(1,1)-(v5(1,1)-v1(1,1))/(x3(1)-x1(1))*(x1(1)-a)&\n &-(v1(1,1)-v3(1,1))/(y1(1)-y2(1))*(y1(1)-b);\n else\n NZ1=v1(1,1)-(v5(1,1)-v1(1,1))/(x3(1)-x1(1))*(x1(1)-a)&\n &-(v4(1,1)-v1(1,1))/(y3(1)-y1(1))*(y1(1)-b);\n end if\n NZ=NZ1(1,1);\n return;\nend subroutine\n\n\n", "meta": {"hexsha": "19e18ea7b83a40a885449f6d2b32e345a8618227", "size": 1079, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "11/mathlib/interp2.f90", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "11/mathlib/interp2.f90", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "11/mathlib/interp2.f90", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.7352941176, "max_line_length": 60, "alphanum_fraction": 0.4745134384, "num_tokens": 625, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533069832973, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6901780316275331}} {"text": "/* Examples for testing */\n\n lambda x:A. x;\n\nlambda x:Bool. x;\n(lambda x:Bool->Bool. if x false then true else false) \n (lambda x:Bool. if x then false else true); \n\nlambda x:Nat. succ x;\n(lambda x:Nat. succ (succ x)) (succ 0); \n\n\n(lambda x:X. lambda y:X->X. y x);\n(lambda x:X->X. x 0) (lambda y:Nat. y); \n\n", "meta": {"hexsha": "d849e7eb74d8a412c7a8dd3ae9def87fbb9b7513", "size": 308, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "examples/recon/test.f", "max_stars_repo_name": "1inguini/TaPL.lean", "max_stars_repo_head_hexsha": "412f824a25a7ea592ad3d411f81eb7e15f9fc5fb", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "examples/recon/test.f", "max_issues_repo_name": "1inguini/TaPL.lean", "max_issues_repo_head_hexsha": "412f824a25a7ea592ad3d411f81eb7e15f9fc5fb", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "examples/recon/test.f", "max_forks_repo_name": "1inguini/TaPL.lean", "max_forks_repo_head_hexsha": "412f824a25a7ea592ad3d411f81eb7e15f9fc5fb", "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.25, "max_line_length": 55, "alphanum_fraction": 0.6168831169, "num_tokens": 105, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9073122238669026, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6901476352664414}} {"text": "subroutine nbody_acceleration(position,velocity,acceleration)\n! Routine drives calculation of all different acceleration terms\n\nuse embryodata,only: nbodies\nimplicit none\n\n\nreal,dimension(3,nbodies), intent(in) :: position,velocity\nreal,dimension(3,nbodies), intent(out) :: acceleration\n\nacceleration(:,:) = 0.0\n\ncall nbody_grav_acceleration(position,acceleration)\ncall nbody_drag_terms(position,velocity,acceleration)\n\nend subroutine nbody_acceleration\n", "meta": {"hexsha": "bb0e7bc9b1be90e1ce2dacb571e8fd7097c1e48a", "size": 454, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/nbody/nbody_acceleration.f90", "max_stars_repo_name": "dh4gan/grapus", "max_stars_repo_head_hexsha": "456707db38dd8920d319807f7f4f7297d6278b4a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/nbody/nbody_acceleration.f90", "max_issues_repo_name": "dh4gan/grapus", "max_issues_repo_head_hexsha": "456707db38dd8920d319807f7f4f7297d6278b4a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/nbody/nbody_acceleration.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": 26.7058823529, "max_line_length": 64, "alphanum_fraction": 0.8237885463, "num_tokens": 108, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9073122213606241, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6901476284371011}} {"text": "subroutine interp1(x,v,n1,n2,C,NZ)\n implicit none;\n integer*4 i,n1,n2;\n double precision,dimension(n1):: x,v;\n double precision,dimension(n2):: C,NZ;\n double precision,dimension(1)::NZ1,P1,P2,P3,V1,V2,V3;\n do i=1,n2\n P1=x(minloc(abs(x-C(i)))-1);P2=x(minloc(abs(x-C(i))));\n P3=x(minloc(abs(x-C(i)))+1);\n V1=v(minloc(abs(x-C(i)))-1);V2=v(minloc(abs(x-C(i))));\n V3=v(minloc(abs(x-C(i)))+1);\nif (C(i)==x(i)) then \nNZ1(1)=v(i);\nelse\n if (C(i)>P2(1)) then\n NZ1(1)=V2(1)+(V3(1)-V2(1))/(P3(1)-P2(1))*(C(i)-P2(1));\n else \n NZ1(1)=V2(1)+(V2(1)-V1(1))/(P2(1)-P1(1))*(C(i)-P2(1));\n end if;\nend if;\n NZ(i)=NZ1(1);\n end do ;\n \n return;\nend subroutine\n", "meta": {"hexsha": "e7b9f9f8880c08b9e69397d85df98556915db637", "size": 650, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "11/mathlib/interp1.f90", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "11/mathlib/interp1.f90", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "11/mathlib/interp1.f90", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.0, "max_line_length": 56, "alphanum_fraction": 0.5723076923, "num_tokens": 290, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.900529786117893, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6900702553180342}} {"text": " program NS\n parameter (nvar=3,nxm=2000,nym=2000)\n real phi1(nvar,nxm,nym)\n real xcoef(nxm,nym)\n\n nx=101\n ny=101\n\n! This loop nest should be parallelized on j\n! xco, px and py should be privatized\n do j=2,ny-1\n do i=2,nx-1\n xco=xcoef(i,j)\n px=(phi1(3,i+1,j)-phi1(3,i-1,j))*h1p2\n py=(phi1(3,i,j+1)-phi1(3,i,j-1))*h2p2\n phi1(1,i,j)=phi1(1,i,j)-dt*px*xco\n phi1(2,i,j)=phi1(2,i,j)-dt*py*xco\n enddo\n enddo\n end\n", "meta": {"hexsha": "01c4cec9a4501a6574d398cd15dba3a6fb6093ca", "size": 538, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "packages/PIPS/validation/CoarseGrainParallelization/Fortran.sub/NS_3.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/CoarseGrainParallelization/Fortran.sub/NS_3.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/CoarseGrainParallelization/Fortran.sub/NS_3.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": 25.619047619, "max_line_length": 50, "alphanum_fraction": 0.4944237918, "num_tokens": 208, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297834483234, "lm_q2_score": 0.766293648423189, "lm_q1q2_score": 0.69007025327236}} {"text": "!Implemented by Anant Dixit (Oct, 2014)\nprogram mdr\nimplicit none\ninteger :: i, mdr, mp, n, j\ncharacter(len=*), parameter :: hfmt = '(A18)', nfmt = '(I6)'\ncharacter(len=*), parameter :: cfmt = '(A3)', rfmt = '(I3)', ffmt = '(I9)'\n\nwrite(*,hfmt) 'Number MDR MP '\nwrite(*,*) '------------------'\n\ni = 123321\ncall root_pers(i,mdr,mp)\nwrite(*,nfmt,advance='no') i\nwrite(*,cfmt,advance='no') ' '\nwrite(*,rfmt,advance='no') mdr\nwrite(*,cfmt,advance='no') ' '\nwrite(*,rfmt) mp\n\ni = 3939\ncall root_pers(i,mdr,mp)\nwrite(*,nfmt,advance='no') i\nwrite(*,cfmt,advance='no') ' '\nwrite(*,rfmt,advance='no') mdr\nwrite(*,cfmt,advance='no') ' '\nwrite(*,rfmt) mp\n\ni = 8822\ncall root_pers(i,mdr,mp)\nwrite(*,nfmt,advance='no') i\nwrite(*,cfmt,advance='no') ' '\nwrite(*,rfmt,advance='no') mdr\nwrite(*,cfmt,advance='no') ' '\nwrite(*,rfmt) mp\n\ni = 39398\ncall root_pers(i,mdr,mp)\nwrite(*,nfmt,advance='no') i\nwrite(*,cfmt,advance='no') ' '\nwrite(*,rfmt,advance='no') mdr\nwrite(*,cfmt,advance='no') ' '\nwrite(*,rfmt) mp\n\nwrite(*,*)\nwrite(*,*)\nwrite(*,*) 'First five numbers with MDR in first column: '\nwrite(*,*) '---------------------------------------------'\n\ndo i = 0,9\n n = 0\n j = 0\n write(*,rfmt,advance='no') i\n do\n call root_pers(j,mdr,mp)\n if(mdr.eq.i) then\n n = n+1\n if(n.eq.5) then\n write(*,ffmt) j\n exit\n else\n write(*,ffmt,advance='no') j\n end if\n end if\n j = j+1\n end do\nend do\n\nend program\n\nsubroutine root_pers(i,mdr,mp)\nimplicit none\ninteger :: N, s, a, i, mdr, mp\nn = i\na = 0\nif(n.lt.10) then\n mdr = n\n mp = 0\n return\nend if\ndo while(n.ge.10)\n a = a + 1\n s = 1\n do while(n.gt.0)\n s = s * mod(n,10)\n n = int(real(n)/10.0D0)\n end do\n n = s\nend do\nmdr = s\nmp = a\nend subroutine\n", "meta": {"hexsha": "61f6db314676f052dadfc4f5101cc798edd86156", "size": 1757, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Digital-root-Multiplicative-digital-root/Fortran/digital-root-multiplicative-digital-root.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Digital-root-Multiplicative-digital-root/Fortran/digital-root-multiplicative-digital-root.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Digital-root-Multiplicative-digital-root/Fortran/digital-root-multiplicative-digital-root.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 19.3076923077, "max_line_length": 74, "alphanum_fraction": 0.5577689243, "num_tokens": 707, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479466, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.6900598958189375}} {"text": "\tFUNCTION bessi_s(n,x)\n\tuse mo_kind\n use mo_nrutil, ONLY : assert\n\tuse mo_nr, ONLY : bessi0\n\tIMPLICIT NONE\n\tINTEGER(I4), INTENT(IN) :: n\n\tREAL(SP), INTENT(IN) :: x\n\tREAL(SP) :: bessi_s\n\tINTEGER(I4), PARAMETER :: IACC=40,IEXP=maxexponent(x)/2\n\tINTEGER(I4) :: j,m\n\tREAL(SP) :: bi,bim,bip,tox\n\tcall assert(n >= 2, 'bessi_s args')\n\tbessi_s=0.0\n\tif (x*x <= 8.0_sp*tiny(x)) RETURN\n\ttox=2.0_sp/abs(x)\n\tbip=0.0\n\tbi=1.0\n\tm=2*((n+int(sqrt(real(IACC*n,sp)))))\n\tdo j=m,1,-1\n\t\tbim=bip+j*tox*bi\n\t\tbip=bi\n\t\tbi=bim\n\t\tif (exponent(bi) > IEXP) then\n\t\t\tbessi_s=scale(bessi_s,-IEXP)\n\t\t\tbi=scale(bi,-IEXP)\n\t\t\tbip=scale(bip,-IEXP)\n\t\tend if\n\t\tif (j == n) bessi_s=bip\n\tend do\n\tbessi_s=bessi_s*bessi0(x)/bi\n\tif (x < 0.0 .and. mod(n,2) == 1) bessi_s=-bessi_s\n\tEND FUNCTION bessi_s\n\n\n\tFUNCTION bessi_v(n,x)\n\tuse mo_kind\n use mo_nrutil, ONLY : assert\n\tuse mo_nr, ONLY : bessi0\n\tIMPLICIT NONE\n\tINTEGER(I4), INTENT(IN) :: n\n\tREAL(SP), DIMENSION(:), INTENT(IN) :: x\n\tREAL(SP), DIMENSION(size(x)) :: bessi_v\n\tINTEGER(I4), PARAMETER :: IACC=40,IEXP=maxexponent(x)/2\n\tINTEGER(I4) :: j,m\n\tREAL(SP), DIMENSION(size(x)) :: bi,bim,bip,tox\n\tLOGICAL(LGT), DIMENSION(size(x)) :: mask\n\tcall assert(n >= 2, 'bessi_v args')\n\tbessi_v=0.0\n\tmask = (x <= 8.0_sp*tiny(x))\n\ttox=2.0_sp/merge(2.0_sp,abs(x),mask)\n\tbip=0.0\n\tbi=1.0_sp\n\tm=2*((n+int(sqrt(real(IACC*n,sp)))))\n\tdo j=m,1,-1\n\t\tbim=bip+j*tox*bi\n\t\tbip=bi\n\t\tbi=bim\n\t\twhere (exponent(bi) > IEXP)\n\t\t\tbessi_v=scale(bessi_v,-IEXP)\n\t\t\tbi=scale(bi,-IEXP)\n\t\t\tbip=scale(bip,-IEXP)\n\t\tend where\n\t\tif (j == n) bessi_v=bip\n\tend do\n\tbessi_v=bessi_v*bessi0(x)/bi\n\twhere (mask) bessi_v=0.0_sp\n\twhere (x < 0.0 .and. mod(n,2) == 1) bessi_v=-bessi_v\n\tEND FUNCTION bessi_v\n\n\n\tFUNCTION dbessi_s(n,x)\n\tuse mo_kind\n use mo_nrutil, ONLY : assert\n\tuse mo_nr, ONLY : bessi0\n\tIMPLICIT NONE\n\tINTEGER(I4), INTENT(IN) :: n\n\tREAL(DP), INTENT(IN) :: x\n\tREAL(DP) :: dbessi_s\n\tINTEGER(I4), PARAMETER :: IACC=40,IEXP=maxexponent(x)/2\n\tINTEGER(I4) :: j,m\n\tREAL(DP) :: bi,bim,bip,tox\n\tcall assert(n >= 2, 'dbessi_s args')\n\tdbessi_s=0.0\n\tif (x*x <= 8.0_dp*tiny(x)) RETURN\n\ttox=2.0_dp/abs(x)\n\tbip=0.0\n\tbi=1.0\n\tm=2*((n+int(sqrt(real(IACC*n,dp)))))\n\tdo j=m,1,-1\n\t\tbim=bip+j*tox*bi\n\t\tbip=bi\n\t\tbi=bim\n\t\tif (exponent(bi) > IEXP) then\n\t\t\tdbessi_s=scale(dbessi_s,-IEXP)\n\t\t\tbi=scale(bi,-IEXP)\n\t\t\tbip=scale(bip,-IEXP)\n\t\tend if\n\t\tif (j == n) dbessi_s=bip\n\tend do\n\tdbessi_s=dbessi_s*bessi0(x)/bi\n\tif (x < 0.0 .and. mod(n,2) == 1) dbessi_s=-dbessi_s\n\tEND FUNCTION dbessi_s\n\n\n\tFUNCTION dbessi_v(n,x)\n\tuse mo_kind\n use mo_nrutil, ONLY : assert\n\tuse mo_nr, ONLY : bessi0\n\tIMPLICIT NONE\n\tINTEGER(I4), INTENT(IN) :: n\n\tREAL(DP), DIMENSION(:), INTENT(IN) :: x\n\tREAL(DP), DIMENSION(size(x)) :: dbessi_v\n\tINTEGER(I4), PARAMETER :: IACC=40,IEXP=maxexponent(x)/2\n\tINTEGER(I4) :: j,m\n\tREAL(DP), DIMENSION(size(x)) :: bi,bim,bip,tox\n\tLOGICAL(LGT), DIMENSION(size(x)) :: mask\n\tcall assert(n >= 2, 'dbessi_v args')\n\tdbessi_v=0.0\n\tmask = (x <= 8.0_dp*tiny(x))\n\ttox=2.0_dp/merge(2.0_dp,abs(x),mask)\n\tbip=0.0\n\tbi=1.0_dp\n\tm=2*((n+int(sqrt(real(IACC*n,dp)))))\n\tdo j=m,1,-1\n\t\tbim=bip+j*tox*bi\n\t\tbip=bi\n\t\tbi=bim\n\t\twhere (exponent(bi) > IEXP)\n\t\t\tdbessi_v=scale(dbessi_v,-IEXP)\n\t\t\tbi=scale(bi,-IEXP)\n\t\t\tbip=scale(bip,-IEXP)\n\t\tend where\n\t\tif (j == n) dbessi_v=bip\n\tend do\n\tdbessi_v=dbessi_v*bessi0(x)/bi\n\twhere (mask) dbessi_v=0.0_dp\n\twhere (x < 0.0 .and. mod(n,2) == 1) dbessi_v=-dbessi_v\n\tEND FUNCTION dbessi_v\n\n", "meta": {"hexsha": "7505f340e0c42b38ed930862846fae118ebd1103", "size": 3380, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "nr_jams/bessi.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/bessi.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/bessi.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": 24.1428571429, "max_line_length": 56, "alphanum_fraction": 0.6363905325, "num_tokens": 1508, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479466, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.6900598870963832}} {"text": "! ConsoleFortran.f90 \r\n!\r\n! FUNCTIONS:\r\n! ConsoleFortran - Entry point of console application.\r\n!\r\n\r\n!****************************************************************************\r\n!\r\n! PROGRAM: ConsoleFortran\r\n!\r\n! PURPOSE: Testing rand with gfortran.\r\n!\r\n!****************************************************************************\r\n\r\n program ConsoleFortran\r\n implicit none\r\n\r\n integer(8) npts\r\n parameter (npts = 10d5)\r\n\r\n integer(8) i\r\n\r\n real(8) f,sum\r\n real(8) xmin,xmax,x\r\n\r\n xmin = 0.0d0\r\n xmax = 1.0d0\r\n\r\n do i=1,npts\r\n x = (xmax-xmin)*rand(0) + xmin\r\n sum = sum + 4.0d0/(1.0d0 + x**2)\r\n enddo\r\n f = sum/npts\r\n \r\n write(*,*)'PI calculated with ',npts,' points = ',f\r\n call ZBQLUAB(-10.0,10.0)\r\n\r\n stop\r\n end\r\n\r\n", "meta": {"hexsha": "87549a808a5332f4472c75364096e42f60bbc01b", "size": 826, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ConsoleFortran.f90", "max_stars_repo_name": "truongd8593/Example_Makefile", "max_stars_repo_head_hexsha": "3c6b7be8668d55aa823ab7cda1844f1e450ca1fd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-02-20T00:44:27.000Z", "max_stars_repo_stars_event_max_datetime": "2018-04-04T10:17:52.000Z", "max_issues_repo_path": "ConsoleFortran.f90", "max_issues_repo_name": "truongd8593/Example_Makefile", "max_issues_repo_head_hexsha": "3c6b7be8668d55aa823ab7cda1844f1e450ca1fd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ConsoleFortran.f90", "max_forks_repo_name": "truongd8593/Example_Makefile", "max_forks_repo_head_hexsha": "3c6b7be8668d55aa823ab7cda1844f1e450ca1fd", "max_forks_repo_licenses": ["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.1463414634, "max_line_length": 78, "alphanum_fraction": 0.4140435835, "num_tokens": 227, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479467, "lm_q2_score": 0.787931185683219, "lm_q1q2_score": 0.690059882735106}} {"text": "module runge_kutta_mod\n!\nprivate\n!\npublic :: runge_kutta_allroutines\n\n contains\n!\n subroutine runge_kutta_allroutines(rk_order,y,nvar,x1,x2,derivs)\n!\n IMPLICIT NONE\n!\n external :: derivs\n integer :: rk_order,nvar\n double precision :: x1,x2,h1\n double precision, dimension(nvar) :: y,dydx,yout\n!\n h1=x2-x1\n!\n select case(rk_order)\n case(4)\n call derivs(x1,y,dydx)\n call rk4(y,dydx,x1,h1,yout,derivs)\n y = yout\n!\n case DEFAULT\n print *, 'Chosen Runge Kutta is not available'\n stop\n!\n end select\n!\n end subroutine runge_kutta_allroutines\n!\n!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\n!\n SUBROUTINE rk4(y,dydx,x,h,yout,derivs)\n!\n IMPLICIT NONE\n!\n external :: derivs\n double precision, DIMENSION(:), INTENT(IN) :: y,dydx\n double precision, INTENT(IN) :: x,h\n double precision, DIMENSION(:), INTENT(OUT) :: yout\n!\n! INTERFACE\n! SUBROUTINE derivs(x,y,dydx)\n!!\n! IMPLICIT NONE\n!!\n! double precision, INTENT(IN) :: x\n! double precision, DIMENSION(:), INTENT(IN) :: y\n! double precision, DIMENSION(:), INTENT(OUT) :: dydx\n!!\n! END SUBROUTINE derivs\n! END INTERFACE\n!\n double precision :: h6,hh,xh\n double precision, DIMENSION(size(y)) :: dym,dyt,yt\n!\n hh=h*0.5d0\n h6=h/6.0d0\n xh=x+hh\n yt=y+hh*dydx\n call derivs(xh,yt,dyt)\n yt=y+hh*dyt\n call derivs(xh,yt,dym)\n yt=y+h*dym\n dym=dyt+dym\n call derivs(x+h,yt,dyt)\n yout=y+h6*(dydx+dyt+2.0d0*dym)\n!\n END SUBROUTINE rk4\n!\nend module\n", "meta": {"hexsha": "b1177f13699f1d2c967433a2f9acb4c23faddaa2", "size": 1815, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "SRC/runge_kutta_mod.f90", "max_stars_repo_name": "Forsti5/GORILLA", "max_stars_repo_head_hexsha": "a28576e625a55b2c3adacf0dbb6806294f888e6f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-08-22T02:43:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-22T02:43:24.000Z", "max_issues_repo_path": "SRC/runge_kutta_mod.f90", "max_issues_repo_name": "Forsti5/GORILLA", "max_issues_repo_head_hexsha": "a28576e625a55b2c3adacf0dbb6806294f888e6f", "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/runge_kutta_mod.f90", "max_forks_repo_name": "Forsti5/GORILLA", "max_forks_repo_head_hexsha": "a28576e625a55b2c3adacf0dbb6806294f888e6f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2021-03-04T08:07:13.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-03T11:21:31.000Z", "avg_line_length": 24.2, "max_line_length": 72, "alphanum_fraction": 0.5493112948, "num_tokens": 544, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.853912760387131, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.6900189108235837}} {"text": "program arrays_04_func\nimplicit none\nreal :: a(3), b\na(1) = 3\na(2) = 2\na(3) = 1\nb = sum(a)\nif (abs(b-6) > 1e-5) error stop\n\ncontains\n\n real function sum(a) result(r)\n real, intent(in) :: a(:)\n integer :: i\n print *, \"sum\"\n r = 0\n do i = 1, size(a)\n r = r + a(i)\n end do\n end function\n\n real function abs(a) result(r)\n real, intent(in) :: a\n print *, \"abs\"\n if (a > 0) then\n r = a\n else\n r = -a\n end if\n end function\n\nend\n", "meta": {"hexsha": "214dbfc277e7538e7c122868d846a8ad75720cdd", "size": 487, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "integration_tests/arrays_04_func.f90", "max_stars_repo_name": "Thirumalai-Shaktivel/lfortran", "max_stars_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 316, "max_stars_repo_stars_event_min_datetime": "2019-03-24T16:23:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:28:33.000Z", "max_issues_repo_path": "integration_tests/arrays_04_func.f90", "max_issues_repo_name": "Thirumalai-Shaktivel/lfortran", "max_issues_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-07-29T04:58:03.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-04T16:40:06.000Z", "max_forks_repo_path": "integration_tests/arrays_04_func.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": 14.7575757576, "max_line_length": 34, "alphanum_fraction": 0.498973306, "num_tokens": 185, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517043, "lm_q2_score": 0.8080672227971212, "lm_q1q2_score": 0.6900189067887279}} {"text": "\tREAL*8\tFUNCTION MODUL(V)\n\tIMPLICIT NONE\n\n\tREAL*8\tV(3)\n\t\n\tMODUL = SQRT(V(1)**2 + V(2)**2 + V(3)**2)\n\tEND\n\n\n\tREAL*8 FUNCTION DOTPRD(V1,V2)\n\tIMPLICIT NONE\n\n\tREAL*8 V1(3), V2(3)\n\tREAL*8 DP\n\tINTEGER*2 I\n\n\tDP = 0\n\tDO I=1,3\n\t\tDP = DP + V1(I) * V2(I)\n\tENDDO\n\tDOTPRD = DP\n\tEND\n\n\tSUBROUTINE CRSPRD(V1,V2,CP)\n\tIMPLICIT NONE\n\tREAL*8 V1(3),V2(3),CP(3)\n\n\tCP(1) = V1(2)*V2(3) - V1(3)*V2(2)\n\tCP(2) = V1(3)*V2(1) - V1(1)*V2(3)\n\tCP(3) = V1(1)*V2(2) - V1(2)*V2(1)\n\tRETURN\n\tEND\n\n\tSUBROUTINE NORM(V,NV)\n\tIMPLICIT NONE\n\tREAL*8 V(3),NV(3)\n\tREAL*8 M\n\tREAL*8 MODUL\n\tINTEGER I\n\n\tM = MODUL(V)\n\tIF (M .NE. 0) THEN\n\t DO I=1,3\n\t NV(I) = V(I) / M\n\t ENDDO\n ELSE\n\t DO I=1,3\n\t\tNV(I) = 0\n\t ENDDO\n\tEND IF\n\tRETURN\n\tEND\n\n\tREAL*8 FUNCTION ANGLE(V1,V2)\n\tIMPLICIT NONE\n\tREAL*8 V1(3)\n\tREAL*8 V2(3)\n\tREAL*8 MODUL,DOTPRD\n\tREAL*8 DP\n\tREAL*8 AB\n\n\tDP = DOTPRD(V1,V2)\n\tAB = MODUL(V1) * MODUL(V2)\n\n\tANGLE = ACOS(DP / AB)\n\tRETURN\n\tEND\n\n\tSUBROUTINE VECADD(A,B,R)\n\tIMPLICIT NONE\n\tREAL*8\tA(3),B(3),R(3)\n\tINTEGER\tI\n\n\tDO I=1,3\n\t R(I) = A(I) + B(I)\n\tENDDO\n\tRETURN\n\tEND\n\n\tSUBROUTINE VECSUB(A,B,R)\n\tIMPLICIT NONE\n\tREAL*8\tA(3),B(3),R(3)\n\tINTEGER\tI\n\n\tDO I=1,3\n\t R(I) = A(I) - B(I)\n\tENDDO\n\tRETURN\n\tEND\n\n\tSUBROUTINE VECCPY(O,D)\n\tIMPLICIT NONE\n\tREAL*8 O(3),D(3)\n\tINTEGER I\n\n\tDO I=1,3\n\t D(I) = O(I)\n\tENDDO\n\tRETURN\n\tEND\t\n\t\n\tSUBROUTINE VECMUL(O,S,D)\n\tIMPLICIT NONE\n\tREAL*8 O(3),S,D(3)\n\tINTEGER I\n\n\tDO I=1,3\n\t D(I) =S*O(I)\n\tENDDO\n\tRETURN\n\tEND\n\n\tSUBROUTINE VECINV(O,D)\n\tIMPLICIT NONE\n\tREAL*8 O(3),D(3)\n\tCALL VECMUL(O,-1.0D0,D)\n\tRETURN\n\tEND\n\n", "meta": {"hexsha": "ad6d864dcbc0e4be2d9fba50b4476b69c43c43a0", "size": 1512, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "fortran/vector.f", "max_stars_repo_name": "jguillaumes/orbit-examples", "max_stars_repo_head_hexsha": "753c541a769a7fa635231b5b6f8c960aef5b64fd", "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": "fortran/vector.f", "max_issues_repo_name": "jguillaumes/orbit-examples", "max_issues_repo_head_hexsha": "753c541a769a7fa635231b5b6f8c960aef5b64fd", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/vector.f", "max_forks_repo_name": "jguillaumes/orbit-examples", "max_forks_repo_head_hexsha": "753c541a769a7fa635231b5b6f8c960aef5b64fd", "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": 12.6, "max_line_length": 42, "alphanum_fraction": 0.5767195767, "num_tokens": 778, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127603871312, "lm_q2_score": 0.8080672112416736, "lm_q1q2_score": 0.6900189029297085}} {"text": "!---------------------------------------------------!\n! Copyright (c) 2017 Shunsuke A. Sato !\n! Released under the MIT license !\n! https://opensource.org/licenses/mit-license.php !\n!---------------------------------------------------!\nsubroutine wfn_rho\n use global_variables\n implicit none\n integer :: ix,iy\n real(dp) :: tmp\n\n rho(:)=0d0\n\n! do ix = 0,Nx\n! tmp = 0d0\n! do iy = 0,Nx\n! tmp = tmp + wfn(ix,iy)**2\n! end do\n! rho(ix) = tmp\n! end do\n\n do ix = 0,Nx\n rho(ix) = sum(wfn(:,ix)**2)\n end do\n rho = rho*2d0*dx\n\n return\nend subroutine wfn_rho\n!=======10========20========30========40========50========60========70========80========90=======100\nsubroutine zwfn_rho\n use global_variables\n implicit none\n integer :: ix,iy\n real(dp) :: tmp\n\n rho(:)=0d0\n\n! do ix = 0,Nx\n! tmp = 0d0\n! do iy = 0,Nx\n! tmp = tmp + wfn(ix,iy)**2\n! end do\n! rho(ix) = tmp\n! end do\n\n do ix = 0,Nx\n rho(ix) = sum(abs(zwfn(:,ix))**2)\n end do\n rho = rho*2d0*dx\n\n return\nend subroutine zwfn_rho\n", "meta": {"hexsha": "ffcff64bee5c32bca63c6154ccbb4de23ecf6e8c", "size": 1063, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/wfn_rho.f90", "max_stars_repo_name": "shunsuke-sato/qm1d", "max_stars_repo_head_hexsha": "b09bbe97dc2987188fe635b27dce89ce82e5d1ee", "max_stars_repo_licenses": ["MIT"], "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/wfn_rho.f90", "max_issues_repo_name": "shunsuke-sato/qm1d", "max_issues_repo_head_hexsha": "b09bbe97dc2987188fe635b27dce89ce82e5d1ee", "max_issues_repo_licenses": ["MIT"], "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/wfn_rho.f90", "max_forks_repo_name": "shunsuke-sato/qm1d", "max_forks_repo_head_hexsha": "b09bbe97dc2987188fe635b27dce89ce82e5d1ee", "max_forks_repo_licenses": ["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.0566037736, "max_line_length": 100, "alphanum_fraction": 0.4675446849, "num_tokens": 355, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517043, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.6900189028417903}} {"text": " FUNCTION hypgeo(a,b,c,z)\r\n COMPLEX hypgeo,a,b,c,z\r\n REAL EPS\r\n PARAMETER (EPS=1.e-6)\r\nCU USES bsstep,hypdrv,hypser,odeint\r\n INTEGER kmax,nbad,nok\r\n EXTERNAL bsstep,hypdrv\r\n COMPLEX z0,dz,aa,bb,cc,y(2)\r\n COMMON /hypg/ aa,bb,cc,z0,dz\r\n COMMON /path/ kmax\r\n kmax=0\r\n if (real(z)**2+aimag(z)**2.le.0.25) then\r\n call hypser(a,b,c,z,hypgeo,y(2))\r\n return\r\n else if (real(z).lt.0.) then\r\n z0=cmplx(-0.5,0.)\r\n else if (real(z).le.1.0) then\r\n z0=cmplx(0.5,0.)\r\n else\r\n z0=cmplx(0.,sign(0.5,aimag(z)))\r\n endif\r\n aa=a\r\n bb=b\r\n cc=c\r\n dz=z-z0\r\n call hypser(aa,bb,cc,z0,y(1),y(2))\r\n call odeint(y,4,0.,1.,EPS,.1,.0001,nok,nbad,hypdrv,bsstep)\r\n hypgeo=y(1)\r\n return\r\n END\r\n", "meta": {"hexsha": "96f5b9baf7ececa08f399542caf8814b773ecb96", "size": 818, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/hypgeo.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/hypgeo.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/hypgeo.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": 26.3870967742, "max_line_length": 65, "alphanum_fraction": 0.5073349633, "num_tokens": 314, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133565584851, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6900087431763484}} {"text": "C\nC file hwscsp.f\nC\n SUBROUTINE HWSCSP (INTL,TS,TF,M,MBDCND,BDTS,BDTF,RS,RF,N,NBDCND,\n 1 BDRS,BDRF,ELMBDA,F,IDIMF,PERTRB,IERROR,W)\nC\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC * *\nC * copyright (c) 1999 by UCAR *\nC * *\nC * UNIVERSITY CORPORATION for ATMOSPHERIC RESEARCH *\nC * *\nC * all rights reserved *\nC * *\nC * FISHPACK version 4.1 *\nC * *\nC * A PACKAGE OF FORTRAN SUBPROGRAMS FOR THE SOLUTION OF *\nC * *\nC * SEPARABLE ELLIPTIC PARTIAL DIFFERENTIAL EQUATIONS *\nC * *\nC * BY *\nC * *\nC * JOHN ADAMS, PAUL SWARZTRAUBER AND ROLAND SWEET *\nC * *\nC * OF *\nC * *\nC * THE NATIONAL CENTER FOR ATMOSPHERIC RESEARCH *\nC * *\nC * BOULDER, COLORADO (80307) U.S.A. *\nC * *\nC * WHICH IS SPONSORED BY *\nC * *\nC * THE NATIONAL SCIENCE FOUNDATION *\nC * *\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC\nC\nC\nC DIMENSION OF BDTS(N+1), BDTF(N+1), BDRS(M+1), BDRF(M+1),\nC ARGUMENTS F(IDIMF,N+1), W(SEE ARGUMENT LIST)\nC\nC LATEST REVISION NOVEMBER 1988\nC\nC PURPOSE SOLVES A FINITE DIFFERENCE APPROXIMATION\nC TO THE MODIFIED HELMHOLTZ EQUATION IN\nC SPHERICAL COORDINATES ASSUMING AXISYMMETRY\nC (NO DEPENDENCE ON LONGITUDE). THE EQUATION\nC IS\nC\nC (1/R**2)(D/DR)((R**2)(D/DR)U) +\nC\nC (1/(R**2)SIN(THETA))(D/DTHETA)\nC\nC (SIN(THETA)(D/DTHETA)U) +\nC\nC (LAMBDA/(RSIN(THETA))**2)U = F(THETA,R).\nC\nC THIS TWO DIMENSIONAL MODIFIED HELMHOLTZ\nC EQUATION RESULTS FROM THE FOURIER TRANSFORM\nC OF THE THREE DIMENSIONAL POISSON EQUATION.\nC\nC USAGE CALL HWSCSP (INTL,TS,TF,M,MBDCND,BDTS,BDTF,\nC RS,RF,N,NBDCND,BDRS,BDRF,ELMBDA,\nC F,IDIMF,PERTRB,IERROR,W)\nC\nC ARGUMENTS\nC ON INPUT INTL\nC = 0 ON INITIAL ENTRY TO HWSCSP OR IF ANY\nC OF THE ARGUMENTS RS, RF, N, NBDCND\nC ARE CHANGED FROM A PREVIOUS CALL.\nC = 1 IF RS, RF, N, NBDCND ARE ALL UNCHANGED\nC FROM PREVIOUS CALL TO HWSCSP.\nC\nC NOTE:\nC A CALL WITH INTL=0 TAKES APPROXIMATELY\nC 1.5 TIMES AS MUCH TIME AS A CALL WITH\nC INTL = 1 . ONCE A CALL WITH INTL = 0\nC HAS BEEN MADE THEN SUBSEQUENT SOLUTIONS\nC CORRESPONDING TO DIFFERENT F, BDTS, BDTF,\nC BDRS, BDRF CAN BE OBTAINED FASTER WITH\nC INTL = 1 SINCE INITIALIZATION IS NOT\nC REPEATED.\nC\nC TS,TF\nC THE RANGE OF THETA (COLATITUDE), I.E.,\nC TS .LE. THETA .LE. TF. TS MUST BE LESS\nC THAN TF. TS AND TF ARE IN RADIANS. A TS OF\nC ZERO CORRESPONDS TO THE NORTH POLE AND A\nC TF OF PI CORRESPONDS TO THE SOUTH POLE.\nC\nC **** IMPORTANT ****\nC\nC IF TF IS EQUAL TO PI THEN IT MUST BE\nC COMPUTED USING THE STATEMENT\nC TF = PIMACH(DUM). THIS INSURES THAT TF\nC IN THE USER'S PROGRAM IS EQUAL TO PI IN\nC THIS PROGRAM WHICH PERMITS SEVERAL TESTS\nC OF THE INPUT PARAMETERS THAT OTHERWISE\nC WOULD NOT BE POSSIBLE.\nC\nC M\nC THE NUMBER OF PANELS INTO WHICH THE\nC INTERVAL (TS,TF) IS SUBDIVIDED.\nC HENCE, THERE WILL BE M+1 GRID POINTS\nC IN THE THETA-DIRECTION GIVEN BY\nC THETA(K) = (I-1)DTHETA+TS FOR\nC I = 1,2,...,M+1, WHERE DTHETA = (TF-TS)/M\nC IS THE PANEL WIDTH.\nC\nC MBDCND\nC INDICATES THE TYPE OF BOUNDARY CONDITION\nC AT THETA = TS AND THETA = TF.\nC\nC = 1 IF THE SOLUTION IS SPECIFIED AT\nC THETA = TS AND THETA = TF.\nC = 2 IF THE SOLUTION IS SPECIFIED AT\nC THETA = TS AND THE DERIVATIVE OF THE\nC SOLUTION WITH RESPECT TO THETA IS\nC SPECIFIED AT THETA = TF\nC (SEE NOTE 2 BELOW).\nC = 3 IF THE DERIVATIVE OF THE SOLUTION\nC WITH RESPECT TO THETA IS SPECIFIED\nC AT THETA = TS AND THETA = TF\nC (SEE NOTES 1,2 BELOW).\nC = 4 IF THE DERIVATIVE OF THE SOLUTION\nC WITH RESPECT TO THETA IS SPECIFIED\nC AT THETA = TS (SEE NOTE 1 BELOW) AND\nC SOLUTION IS SPECIFIED AT THETA = TF.\nC = 5 IF THE SOLUTION IS UNSPECIFIED AT\nC THETA = TS = 0 AND THE SOLUTION IS\nC SPECIFIED AT THETA = TF.\nC = 6 IF THE SOLUTION IS UNSPECIFIED AT\nC THETA = TS = 0 AND THE DERIVATIVE\nC OF THE SOLUTION WITH RESPECT TO THETA\nC IS SPECIFIED AT THETA = TF\nC (SEE NOTE 2 BELOW).\nC = 7 IF THE SOLUTION IS SPECIFIED AT\nC THETA = TS AND THE SOLUTION IS\nC UNSPECIFIED AT THETA = TF = PI.\nC = 8 IF THE DERIVATIVE OF THE SOLUTION\nC WITH RESPECT TO THETA IS SPECIFIED\nC AT THETA = TS (SEE NOTE 1 BELOW)\nC AND THE SOLUTION IS UNSPECIFIED AT\nC THETA = TF = PI.\nC = 9 IF THE SOLUTION IS UNSPECIFIED AT\nC THETA = TS = 0 AND THETA = TF = PI.\nC\nC NOTE 1:\nC IF TS = 0, DO NOT USE MBDCND = 3,4, OR 8,\nC BUT INSTEAD USE MBDCND = 5,6, OR 9 .\nC\nC NOTE 2:\nC IF TF = PI, DO NOT USE MBDCND = 2,3, OR 6,\nC BUT INSTEAD USE MBDCND = 7,8, OR 9 .\nC\nC BDTS\nC A ONE-DIMENSIONAL ARRAY OF LENGTH N+1 THAT\nC SPECIFIES THE VALUES OF THE DERIVATIVE OF\nC THE SOLUTION WITH RESPECT TO THETA AT\nC THETA = TS. WHEN MBDCND = 3,4, OR 8,\nC\nC BDTS(J) = (D/DTHETA)U(TS,R(J)),\nC J = 1,2,...,N+1 .\nC\nC WHEN MBDCND HAS ANY OTHER VALUE, BDTS IS\nC A DUMMY VARIABLE.\nC\nC BDTF\nC A ONE-DIMENSIONAL ARRAY OF LENGTH N+1 THAT\nC SPECIFIES THE VALUES OF THE DERIVATIVE OF\nC THE SOLUTION WITH RESPECT TO THETA AT\nC THETA = TF. WHEN MBDCND = 2,3, OR 6,\nC\nC BDTF(J) = (D/DTHETA)U(TF,R(J)),\nC J = 1,2,...,N+1 .\nC\nC WHEN MBDCND HAS ANY OTHER VALUE, BDTF IS\nC A DUMMY VARIABLE.\nC\nC RS,RF\nC THE RANGE OF R, I.E., RS .LE. R .LT. RF.\nC RS MUST BE LESS THAN RF. RS MUST BE\nC NON-NEGATIVE.\nC\nC N\nC THE NUMBER OF PANELS INTO WHICH THE\nC INTERVAL (RS,RF) IS SUBDIVIDED.\nC HENCE, THERE WILL BE N+1 GRID POINTS IN THE\nC R-DIRECTION GIVEN BY R(J) = (J-1)DR+RS\nC FOR J = 1,2,...,N+1, WHERE DR = (RF-RS)/N\nC IS THE PANEL WIDTH.\nC N MUST BE GREATER THAN 2\nC\nC NBDCND\nC INDICATES THE TYPE OF BOUNDARY CONDITION\nC AT R = RS AND R = RF.\nC\nC = 1 IF THE SOLUTION IS SPECIFIED AT\nC R = RS AND R = RF.\nC = 2 IF THE SOLUTION IS SPECIFIED AT\nC R = RS AND THE DERIVATIVE\nC OF THE SOLUTION WITH RESPECT TO R\nC IS SPECIFIED AT R = RF.\nC = 3 IF THE DERIVATIVE OF THE SOLUTION\nC WITH RESPECT TO R IS SPECIFIED AT\nC R = RS AND R = RF.\nC = 4 IF THE DERIVATIVE OF THE SOLUTION\nC WITH RESPECT TO R IS SPECIFIED AT\nC RS AND THE SOLUTION IS SPECIFIED AT\nC R = RF.\nC = 5 IF THE SOLUTION IS UNSPECIFIED AT\nC R = RS = 0 (SEE NOTE BELOW) AND THE\nC SOLUTION IS SPECIFIED AT R = RF.\nC = 6 IF THE SOLUTION IS UNSPECIFIED AT\nC R = RS = 0 (SEE NOTE BELOW) AND THE\nC DERIVATIVE OF THE SOLUTION WITH\nC RESPECT TO R IS SPECIFIED AT R = RF.\nC\nC NOTE:\nC NBDCND = 5 OR 6 CANNOT BE USED WITH\nC MBDCND = 1,2,4,5, OR 7. THE FORMER\nC INDICATES THAT THE SOLUTION IS UNSPECIFIED\nC AT R = 0, THE LATTER INDICATES THAT THE\nC SOLUTION IS SPECIFIED).\nC USE INSTEAD NBDCND = 1 OR 2 .\nC\nC BDRS\nC A ONE-DIMENSIONAL ARRAY OF LENGTH M+1 THAT\nC SPECIFIES THE VALUES OF THE DERIVATIVE OF\nC THE SOLUTION WITH RESPECT TO R AT R = RS.\nC\nC WHEN NBDCND = 3 OR 4,\nC BDRS(I) = (D/DR)U(THETA(I),RS),\nC I = 1,2,...,M+1 .\nC\nC WHEN NBDCND HAS ANY OTHER VALUE, BDRS IS\nC A DUMMY VARIABLE.\nC\nC BDRF\nC A ONE-DIMENSIONAL ARRAY OF LENGTH M+1\nC THAT SPECIFIES THE VALUES OF THE\nC DERIVATIVE OF THE SOLUTION WITH RESPECT\nC TO R AT R = RF.\nC\nC WHEN NBDCND = 2,3, OR 6,\nC BDRF(I) = (D/DR)U(THETA(I),RF),\nC I = 1,2,...,M+1 .\nC\nC WHEN NBDCND HAS ANY OTHER VALUE, BDRF IS\nC A DUMMY VARIABLE.\nC\nC ELMBDA\nC THE CONSTANT LAMBDA IN THE HELMHOLTZ\nC EQUATION. IF LAMBDA .GT. 0, A SOLUTION\nC MAY NOT EXIST. HOWEVER, HWSCSP WILL\nC ATTEMPT TO FIND A SOLUTION. IF NBDCND = 5\nC OR 6 OR MBDCND = 5,6,7,8, OR 9, ELMBDA\nC MUST BE ZERO.\nC\nC F\nC A TWO-DIMENSIONAL ARRAY, OF DIMENSION AT\nC LEAST (M+1)*(N+1), SPECIFYING VALUES OF THE\nC RIGHT SIDE OF THE HELMHOLTZ EQUATION AND\nC BOUNDARY VALUES (IF ANY).\nC\nC ON THE INTERIOR, F IS DEFINED AS FOLLOWS:\nC FOR I = 2,3,...,M AND J = 2,3,...,N\nC F(I,J) = F(THETA(I),R(J)).\nC\nC ON THE BOUNDARIES, F IS DEFINED AS FOLLOWS:\nC FOR J=1,2,...,N+1, I=1,2,...,M+1,\nC\nC MBDCND F(1,J) F(M+1,J)\nC ------ ---------- ----------\nC\nC 1 U(TS,R(J)) U(TF,R(J))\nC 2 U(TS,R(J)) F(TF,R(J))\nC 3 F(TS,R(J)) F(TF,R(J))\nC 4 F(TS,R(J)) U(TF,R(J))\nC 5 F(0,R(J)) U(TF,R(J))\nC 6 F(0,R(J)) F(TF,R(J))\nC 7 U(TS,R(J)) F(PI,R(J))\nC 8 F(TS,R(J)) F(PI,R(J))\nC 9 F(0,R(J)) F(PI,R(J))\nC\nC NBDCND F(I,1) F(I,N+1)\nC ------ -------------- --------------\nC\nC 1 U(THETA(I),RS) U(THETA(I),RF)\nC 2 U(THETA(I),RS) F(THETA(I),RF)\nC 3 F(THETA(I),RS) F(THETA(I),RF)\nC 4 F(THETA(I),RS) U(THETA(I),RF)\nC 5 F(TS,0) U(THETA(I),RF)\nC 6 F(TS,0) F(THETA(I),RF)\nC\nC NOTE:\nC IF THE TABLE CALLS FOR BOTH THE SOLUTION\nC U AND THE RIGHT SIDE F AT A CORNER THEN\nC THE SOLUTION MUST BE SPECIFIED.\nC\nC IDIMF\nC THE ROW (OR FIRST) DIMENSION OF THE ARRAY\nC F AS IT APPEARS IN THE PROGRAM CALLING\nC HWSCSP. THIS PARAMETER IS USED TO SPECIFY\nC THE VARIABLE DIMENSION OF F. IDIMF MUST\nC BE AT LEAST M+1 .\nC\nC W\nC A ONE-DIMENSIONAL ARRAY THAT MUST BE\nC PROVIDED BY THE USER FOR WORK SPACE.\nC ITS LENGTH CAN BE COMPUTED FROM THE\nC FORMULA BELOW WHICH DEPENDS ON THE VALUE\nC OF NBDCND\nC\nC IF NBDCND=2,4 OR 6 DEFINE NUNK=N\nC IF NBDCND=1 OR 5 DEFINE NUNK=N-1\nC IF NBDCND=3 DEFINE NUNK=N+1\nC\nC NOW SET K=INT(LOG2(NUNK))+1 AND\nC L=2**(K+1) THEN W MUST BE DIMENSIONED\nC AT LEAST (K-2)*L+K+5*(M+N)+MAX(2*N,6*M)+23\nC\nC **IMPORTANT**\nC FOR PURPOSES OF CHECKING, THE REQUIRED\nC LENGTH OF W IS COMPUTED BY HWSCSP AND\nC STORED IN W(1) IN FLOATING POINT FORMAT.\nC\nC ON OUTPUT F\nC CONTAINS THE SOLUTION U(I,J) OF THE FINITE\nC DIFFERENCE APPROXIMATION FOR THE GRID POINT\nC (THETA(I),R(J)), I = 1,2,...,M+1,\nC J = 1,2,...,N+1 .\nC\nC PERTRB\nC IF A COMBINATION OF PERIODIC OR DERIVATIVE\nC BOUNDARY CONDITIONS IS SPECIFIED FOR A\nC POISSON EQUATION (LAMBDA = 0), A SOLUTION\nC MAY NOT EXIST. PERTRB IS A CONSTANT,\nC CALCULATED AND SUBTRACTED FROM F, WHICH\nC ENSURES THAT A SOLUTION EXISTS. HWSCSP\nC THEN COMPUTES THIS SOLUTION, WHICH IS A\nC LEAST SQUARES SOLUTION TO THE ORIGINAL\nC APPROXIMATION. THIS SOLUTION IS NOT UNIQUE\nC AND IS UNNORMALIZED. THE VALUE OF PERTRB\nC SHOULD BE SMALL COMPARED TO THE RIGHT SIDE\nC F. OTHERWISE , A SOLUTION IS OBTAINED TO\nC AN ESSENTIALLY DIFFERENT PROBLEM. THIS\nC COMPARISON SHOULD ALWAYS BE MADE TO INSURE\nC THAT A MEANINGFUL SOLUTION HAS BEEN OBTAINED.\nC\nC IERROR\nC AN ERROR FLAG THAT INDICATES INVALID INPUT\nC PARAMETERS. EXCEPT FOR NUMBERS 0 AND 10,\nC A SOLUTION IS NOT ATTEMPTED.\nC\nC = 1 TS.LT.0. OR TF.GT.PI\nC = 2 TS.GE.TF\nC = 3 M.LT.5\nC = 4 MBDCND.LT.1 OR MBDCND.GT.9\nC = 5 RS.LT.0\nC = 6 RS.GE.RF\nC = 7 N.LT.5\nC = 8 NBDCND.LT.1 OR NBDCND.GT.6\nC = 9 ELMBDA.GT.0\nC = 10 IDIMF.LT.M+1\nC = 11 ELMBDA.NE.0 AND MBDCND.GE.5\nC = 12 ELMBDA.NE.0 AND NBDCND EQUALS 5 OR 6\nC = 13 MBDCND EQUALS 5,6 OR 9 AND TS.NE.0\nC = 14 MBDCND.GE.7 AND TF.NE.PI\nC = 15 TS.EQ.0 AND MBDCND EQUALS 3,4 OR 8\nC = 16 TF.EQ.PI AND MBDCND EQUALS 2,3 OR 6\nC = 17 NBDCND.GE.5 AND RS.NE.0\nC = 18 NBDCND.GE.5 AND MBDCND EQUALS 1,2,4,5 OR\nC\nC SINCE THIS IS THE ONLY MEANS OF INDICATING\nC A POSSLIBY INCORRECT CALL TO HWSCSP, THE\nC USER SHOULD TEST IERROR AFTER A CALL.\nC\nC W\nC CONTAINS INTERMEDIATE VALUES THAT MUST NOT\nC BE DESTROYED IF HWSCSP WILL BE CALLED AGAIN\nC WITH INTL = 1. W(1) CONTAINS THE NUMBER\nC OF LOCATIONS WHICH W MUST HAVE\nC\nC SPECIAL CONDITIONS NONE\nC\nC I/O NONE\nC\nC PRECISION SINGLE\nC\nC REQUIRED LIBRARY BLKTRI, AND COMF FROM FISHPACK\nC FILES\nC\nC LANGUAGE FORTRAN\nC\nC HISTORY WRITTEN BY ROLAND SWEET AT NCAR IN THE LATE\nC 1970'S. RELEASED ON NCAR'S PUBLIC SOFTWARE\nC LIBRARIES IN JANUARY 1980.\nC\nC PORTABILITY FORTRAN 77.\nC\nC ALGORITHM THE ROUTINE DEFINES THE FINITE DIFFERENCE\nC EQUATIONS, INCORPORATES BOUNDARY DATA, AND\nC ADJUSTS THE RIGHT SIDE OF SINGULAR SYSTEMS\nC AND THEN CALLS BLKTRI TO SOLVE THE SYSTEM.\nC\nC REFERENCES SWARZTRAUBER,P. AND R. SWEET, \"EFFICIENT\nC FORTRAN SUBPROGRAMS FOR THE SOLUTION OF\nC ELLIPTIC EQUATIONS\"\nC NCAR TN/IA-109, JULY, 1975, 138 PP.\nC***********************************************************************\n DIMENSION F(IDIMF,1) ,BDTS(*) ,BDTF(*) ,BDRS(*) ,\n 1 BDRF(*) ,W(*)\nC\n PI = PIMACH(DUM)\n IERROR = 0\n IF (TS.LT.0. .OR. TF.GT.PI) IERROR = 1\n IF (TS .GE. TF) IERROR = 2\n IF (M .LT. 5) IERROR = 3\n IF (MBDCND.LT.1 .OR. MBDCND.GT.9) IERROR = 4\n IF (RS .LT. 0.) IERROR = 5\n IF (RS .GE. RF) IERROR = 6\n IF (N .LT. 5) IERROR = 7\n IF (NBDCND.LT.1 .OR. NBDCND.GT.6) IERROR = 8\n IF (ELMBDA .GT. 0.) IERROR = 9\n IF (IDIMF .LT. M+1) IERROR = 10\n IF (ELMBDA.NE.0. .AND. MBDCND.GE.5) IERROR = 11\n IF (ELMBDA.NE.0. .AND. (NBDCND.EQ.5 .OR. NBDCND.EQ.6)) IERROR = 12\n IF ((MBDCND.EQ.5 .OR. MBDCND.EQ.6 .OR. MBDCND.EQ.9) .AND.\n 1 TS.NE.0.) IERROR = 13\n IF (MBDCND.GE.7 .AND. TF.NE.PI) IERROR = 14\n IF (TS.EQ.0. .AND.\n 1 (MBDCND.EQ.4 .OR. MBDCND.EQ.8 .OR. MBDCND.EQ.3)) IERROR = 15\n IF (TF.EQ.PI .AND.\n 1 (MBDCND.EQ.2 .OR. MBDCND.EQ.3 .OR. MBDCND.EQ.6)) IERROR = 16\n IF (NBDCND.GE.5 .AND. RS.NE.0.) IERROR = 17\n IF (NBDCND.GE.5 .AND. (MBDCND.EQ.1 .OR. MBDCND.EQ.2 .OR.\n 1 MBDCND.EQ.5 .OR. MBDCND.EQ.7))\n 2 IERROR = 18\n IF (IERROR.NE.0 .AND. IERROR.NE.9) RETURN\n NCK = N\n GO TO (101,103,102,103,101,103),NBDCND\n 101 NCK = NCK-1\n GO TO 103\n 102 NCK = NCK+1\n 103 L = 2\n K = 1\n 104 L = L+L\n K = K+1\n IF (NCK-L) 105,105,104\n 105 L = L+L\n NP1 = N+1\n MP1 = M+1\n I1 = (K-2)*L+K+MAX0(2*N,6*M)+13\n I2 = I1+NP1\n I3 = I2+NP1\n I4 = I3+NP1\n I5 = I4+NP1\n I6 = I5+NP1\n I7 = I6+MP1\n I8 = I7+MP1\n I9 = I8+MP1\n I10 = I9+MP1\n W(1) = FLOAT(I10+M)\n CALL HWSCS1 (INTL,TS,TF,M,MBDCND,BDTS,BDTF,RS,RF,N,NBDCND,BDRS,\n 1 BDRF,ELMBDA,F,IDIMF,PERTRB,W(2),W(I1),W(I2),W(I3),\n 2 W(I4),W(I5),W(I6),W(I7),W(I8),W(I9),W(I10))\n RETURN\n END\n SUBROUTINE HWSCS1 (INTL,TS,TF,M,MBDCND,BDTS,BDTF,RS,RF,N,NBDCND,\n 1 BDRS,BDRF,ELMBDA,F,IDIMF,PERTRB,W,S,AN,BN,CN,\n 2 R,AM,BM,CM,SINT,BMH)\n DIMENSION F(IDIMF,*) ,BDRS(*) ,BDRF(*) ,BDTS(*) ,\n 1 BDTF(*) ,AM(*) ,BM(*) ,CM(*) ,\n 2 AN(*) ,BN(*) ,CN(*) ,S(*) ,\n 3 R(*) ,SINT(*) ,BMH(*) ,W(*)\n PI = PIMACH(DUM)\n EPS = EPMACH(DUM)\n MP1 = M+1\n DTH = (TF-TS)/FLOAT(M)\n TDT = DTH+DTH\n HDTH = DTH/2.\n SDTS = 1./(DTH*DTH)\n DO 102 I=1,MP1\n THETA = TS+FLOAT(I-1)*DTH\n SINT(I) = SIN(THETA)\n IF (SINT(I)) 101,102,101\n 101 T1 = SDTS/SINT(I)\n AM(I) = T1*SIN(THETA-HDTH)\n CM(I) = T1*SIN(THETA+HDTH)\n BM(I) = -(AM(I)+CM(I))\n 102 CONTINUE\n NP1 = N+1\n DR = (RF-RS)/FLOAT(N)\n HDR = DR/2.\n TDR = DR+DR\n DR2 = DR*DR\n CZR = 6.*DTH/(DR2*(COS(TS)-COS(TF)))\n DO 103 J=1,NP1\n R(J) = RS+FLOAT(J-1)*DR\n AN(J) = (R(J)-HDR)**2/DR2\n CN(J) = (R(J)+HDR)**2/DR2\n BN(J) = -(AN(J)+CN(J))\n 103 CONTINUE\n MP = 1\n NP = 1\nC\nC BOUNDARY CONDITION AT PHI=PS\nC\n GO TO (104,104,105,105,106,106,104,105,106),MBDCND\n 104 AT = AM(2)\n ITS = 2\n GO TO 107\n 105 AT = AM(1)\n ITS = 1\n CM(1) = CM(1)+AM(1)\n GO TO 107\n 106 ITS = 1\n BM(1) = -4.*SDTS\n CM(1) = -BM(1)\nC\nC BOUNDARY CONDITION AT PHI=PF\nC\n 107 GO TO (108,109,109,108,108,109,110,110,110),MBDCND\n 108 CT = CM(M)\n ITF = M\n GO TO 111\n 109 CT = CM(M+1)\n AM(M+1) = AM(M+1)+CM(M+1)\n ITF = M+1\n GO TO 111\n 110 ITF = M+1\n AM(M+1) = 4.*SDTS\n BM(M+1) = -AM(M+1)\n 111 WTS = SINT(ITS+1)*AM(ITS+1)/CM(ITS)\n WTF = SINT(ITF-1)*CM(ITF-1)/AM(ITF)\n ITSP = ITS+1\n ITFM = ITF-1\nC\nC BOUNDARY CONDITION AT R=RS\nC\n ICTR = 0\n GO TO (112,112,113,113,114,114),NBDCND\n 112 AR = AN(2)\n JRS = 2\n GO TO 118\n 113 AR = AN(1)\n JRS = 1\n CN(1) = CN(1)+AN(1)\n GO TO 118\n 114 JRS = 2\n ICTR = 1\n S(N) = AN(N)/BN(N)\n DO 115 J=3,N\n L = N-J+2\n S(L) = AN(L)/(BN(L)-CN(L)*S(L+1))\n 115 CONTINUE\n S(2) = -S(2)\n DO 116 J=3,N\n S(J) = -S(J)*S(J-1)\n 116 CONTINUE\n WTNM = WTS+WTF\n DO 117 I=ITSP,ITFM\n WTNM = WTNM+SINT(I)\n 117 CONTINUE\n YPS = CZR*WTNM*(S(2)-1.)\nC\nC BOUNDARY CONDITION AT R=RF\nC\n 118 GO TO (119,120,120,119,119,120),NBDCND\n 119 CR = CN(N)\n JRF = N\n GO TO 121\n 120 CR = CN(N+1)\n AN(N+1) = AN(N+1)+CN(N+1)\n JRF = N+1\n 121 WRS = AN(JRS+1)*R(JRS)**2/CN(JRS)\n WRF = CN(JRF-1)*R(JRF)**2/AN(JRF)\n WRZ = AN(JRS)/CZR\n JRSP = JRS+1\n JRFM = JRF-1\n MUNK = ITF-ITS+1\n NUNK = JRF-JRS+1\n DO 122 I=ITS,ITF\n BMH(I) = BM(I)\n 122 CONTINUE\n ISING = 0\n GO TO (132,132,123,132,132,123),NBDCND\n 123 GO TO (132,132,124,132,132,124,132,124,124),MBDCND\n 124 IF (ELMBDA) 132,125,125\n 125 ISING = 1\n SUM = WTS*WRS+WTS*WRF+WTF*WRS+WTF*WRF\n IF (ICTR) 126,127,126\n 126 SUM = SUM+WRZ\n 127 DO 129 J=JRSP,JRFM\n R2 = R(J)**2\n DO 128 I=ITSP,ITFM\n SUM = SUM+R2*SINT(I)\n 128 CONTINUE\n 129 CONTINUE\n DO 130 J=JRSP,JRFM\n SUM = SUM+(WTS+WTF)*R(J)**2\n 130 CONTINUE\n DO 131 I=ITSP,ITFM\n SUM = SUM+(WRS+WRF)*SINT(I)\n 131 CONTINUE\n HNE = SUM\n 132 GO TO (133,133,133,133,134,134,133,133,134),MBDCND\n 133 BM(ITS) = BMH(ITS)+ELMBDA/SINT(ITS)**2\n 134 GO TO (135,135,135,135,135,135,136,136,136),MBDCND\n 135 BM(ITF) = BMH(ITF)+ELMBDA/SINT(ITF)**2\n 136 DO 137 I=ITSP,ITFM\n BM(I) = BMH(I)+ELMBDA/SINT(I)**2\n 137 CONTINUE\n GO TO (138,138,140,140,142,142,138,140,142),MBDCND\n 138 DO 139 J=JRS,JRF\n F(2,J) = F(2,J)-AT*F(1,J)/R(J)**2\n 139 CONTINUE\n GO TO 142\n 140 DO 141 J=JRS,JRF\n F(1,J) = F(1,J)+TDT*BDTS(J)*AT/R(J)**2\n 141 CONTINUE\n 142 GO TO (143,145,145,143,143,145,147,147,147),MBDCND\n 143 DO 144 J=JRS,JRF\n F(M,J) = F(M,J)-CT*F(M+1,J)/R(J)**2\n 144 CONTINUE\n GO TO 147\n 145 DO 146 J=JRS,JRF\n F(M+1,J) = F(M+1,J)-TDT*BDTF(J)*CT/R(J)**2\n 146 CONTINUE\n 147 GO TO (151,151,153,153,148,148),NBDCND\n 148 IF (MBDCND-3) 155,149,155\n 149 YHLD = F(ITS,1)-CZR/TDT*(SIN(TF)*BDTF(2)-SIN(TS)*BDTS(2))\n DO 150 I=1,MP1\n F(I,1) = YHLD\n 150 CONTINUE\n GO TO 155\n 151 RS2 = (RS+DR)**2\n DO 152 I=ITS,ITF\n F(I,2) = F(I,2)-AR*F(I,1)/RS2\n 152 CONTINUE\n GO TO 155\n 153 DO 154 I=ITS,ITF\n F(I,1) = F(I,1)+TDR*BDRS(I)*AR/RS**2\n 154 CONTINUE\n 155 GO TO (156,158,158,156,156,158),NBDCND\n 156 RF2 = (RF-DR)**2\n DO 157 I=ITS,ITF\n F(I,N) = F(I,N)-CR*F(I,N+1)/RF2\n 157 CONTINUE\n GO TO 160\n 158 DO 159 I=ITS,ITF\n F(I,N+1) = F(I,N+1)-TDR*BDRF(I)*CR/RF**2\n 159 CONTINUE\n 160 CONTINUE\n PERTRB = 0.\n IF (ISING) 161,170,161\n 161 SUM = WTS*WRS*F(ITS,JRS)+WTS*WRF*F(ITS,JRF)+WTF*WRS*F(ITF,JRS)+\n 1 WTF*WRF*F(ITF,JRF)\n IF (ICTR) 162,163,162\n 162 SUM = SUM+WRZ*F(ITS,1)\n 163 DO 165 J=JRSP,JRFM\n R2 = R(J)**2\n DO 164 I=ITSP,ITFM\n SUM = SUM+R2*SINT(I)*F(I,J)\n 164 CONTINUE\n 165 CONTINUE\n DO 166 J=JRSP,JRFM\n SUM = SUM+R(J)**2*(WTS*F(ITS,J)+WTF*F(ITF,J))\n 166 CONTINUE\n DO 167 I=ITSP,ITFM\n SUM = SUM+SINT(I)*(WRS*F(I,JRS)+WRF*F(I,JRF))\n 167 CONTINUE\n PERTRB = SUM/HNE\n DO 169 J=1,NP1\n DO 168 I=1,MP1\n F(I,J) = F(I,J)-PERTRB\n 168 CONTINUE\n 169 CONTINUE\n 170 DO 172 J=JRS,JRF\n RSQ = R(J)**2\n DO 171 I=ITS,ITF\n F(I,J) = RSQ*F(I,J)\n 171 CONTINUE\n 172 CONTINUE\n IFLG = INTL\n 173 CALL BLKTRI (IFLG,NP,NUNK,AN(JRS),BN(JRS),CN(JRS),MP,MUNK,\n 1 AM(ITS),BM(ITS),CM(ITS),IDIMF,F(ITS,JRS),IERROR,W)\n IFLG = IFLG+1\n IF (IFLG-1) 174,173,174\n 174 IF (NBDCND) 177,175,177\n 175 DO 176 I=1,MP1\n F(I,JRF+1) = F(I,JRS)\n 176 CONTINUE\n 177 IF (MBDCND) 180,178,180\n 178 DO 179 J=1,NP1\n F(ITF+1,J) = F(ITS,J)\n 179 CONTINUE\n 180 XP = 0.\n IF (ICTR) 181,188,181\n 181 IF (ISING) 186,182,186\n 182 SUM = WTS*F(ITS,2)+WTF*F(ITF,2)\n DO 183 I=ITSP,ITFM\n SUM = SUM+SINT(I)*F(I,2)\n 183 CONTINUE\n YPH = CZR*SUM\n XP = (F(ITS,1)-YPH)/YPS\n DO 185 J=JRS,JRF\n XPS = XP*S(J)\n DO 184 I=ITS,ITF\n F(I,J) = F(I,J)+XPS\n 184 CONTINUE\n 185 CONTINUE\n 186 DO 187 I=1,MP1\n F(I,1) = XP\n 187 CONTINUE\n 188 RETURN\nC\nC REVISION HISTORY---\nC\nC SEPTEMBER 1973 VERSION 1\nC APRIL 1976 VERSION 2\nC JANUARY 1978 VERSION 3\nC DECEMBER 1979 VERSION 3.1\nC FEBRUARY 1985 DOCUMENTATION UPGRADE\nC NOVEMBER 1988 VERSION 3.2, FORTRAN 77 CHANGES\nC-----------------------------------------------------------------------\n END\n", "meta": {"hexsha": "ebb52b7c841720c8a3d904fcda2f9bfd7ca982c4", "size": 29556, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/src/hwscsp.f", "max_stars_repo_name": "ipelupessy/omuse", "max_stars_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2020-03-25T10:02:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-18T00:28:35.000Z", "max_issues_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/src/hwscsp.f", "max_issues_repo_name": "ipelupessy/omuse", "max_issues_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 45, "max_issues_repo_issues_event_min_datetime": "2020-03-03T16:07:16.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-14T09:01:07.000Z", "max_forks_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/src/hwscsp.f", "max_forks_repo_name": "ipelupessy/omuse", "max_forks_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-03-03T13:28:50.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-26T09:20:02.000Z", "avg_line_length": 40.5432098765, "max_line_length": 72, "alphanum_fraction": 0.4122005684, "num_tokens": 9045, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133481428691, "lm_q2_score": 0.734119526900183, "lm_q1q2_score": 0.69000874246581}} {"text": "C GARESOL.F - Gateway function for solving descriptor algebraic Riccati\nC equations using SLICOT routine SG02AD.\nC\nC RELEASE 2.0 of SLICOT Basic Systems and Control Toolbox.\nC Based on SLICOT RELEASE 5.7. Copyright (c) 2003-2020 NICONET e.V.\nC\nC Matlab call:\nC [X,F,ev,db,rcond1] = garesol(A,E,Q,R,B,L,flag)\nC [X,ev,db,rcond1] = garesol(A,E,Q,R,B,L,flag)\nC [X,ev,db,rcond1] = garesol(A,E,Q,G,flag)\nC [Z,scale,ev,db,rcond1] = garesol(A,E,Q,R,B,L,flag)\nC [Z,scale,ev,db,rcond1] = garesol(A,E,Q,G,flag)\nC\nC Purpose:\nC To solve the continuous-time algebraic Riccati equations\nC -1\nC 0 = Q + A'*X*E + E'*X*A - (L + E'*X*B)*R *(L + E'*X*B)' , (1a)\nC\nC or the discrete-time algebraic Riccati equations\nC -1\nC E'*X*E = A'*X*A - (L + A'*X*B)*(R + B'*X*B) (L + A'*X*B)' + Q;\nC (1b)\nC or, in alternate forms,\nC\nC -1\nC 0 = Q - L*R *L' + A1'*X*E + E'*X*A1 - E'*X*G*X*E, (2a)\nC\nC or\nC -1 -1\nC E'*X*E = Q - L*R *L' + A1'*X*(I + G*X) *A1, (2b)\nC\nC -1 -1\nC where G = B*R *B', A1 = A - B*R *L'. The optimal feedback gain\nC matrix is\nC\nC -1\nC F = R (L+E'XB)' , for (1a),\nC\nC and\nC -1\nC F = (R+B'XB) (L+A'XB)' , for (2a).\nC\nC The function can also be used to compute an orthogonal basis of the\nC subspace which generates the solution.\nC\nC The generalized Schur method is used on the extended pencils\nC\nC [ A 0 B ] [ E 0 0 ]\nC a [ Q A' L ] - b [ 0 -E' 0 ] , (3a)\nC [ L' B' R ] [ 0 0 0 ]\nC or\nC\nC [ A 0 B ] [ E 0 0 ]\nC a [ Q -E' L ] - b [ 0 -A' 0 ] , (3b)\nC [ L' 0 R ] [ 0 -B' 0 ]\nC\nC to solve the equations (1a) or (1b).\nC\nC Input parameters:\nC A - real N-by-N system state matrix.\nC E - real N-by-N descriptor system matrix.\nC Q - normally, real symmetric N-by-N state weighting matrix.\nC If flag(5) <> 0, array Q stores the P-by-N factor C of Q,\nC Q = C'*C.\nC R - normally, real symmetric M-by-M input weighting matrix.\nC If R is an input parameter and flag(6) <> 0, array R stores\nC the P-by-M factor D of R, R = D'*D.\nC B - real N-by-M input matrix.\nC L - real N-by-M coupling matrix.\nC G - real symmetric N-by-N matrix.\nC flag - (optional) vector of length 10 containing options:\nC flag(1) = 0 : solve the continuous-time equation (1a);\nC otherwise, solve the discrete-time\nC equation (1b).\nC flag(2) = 0 : compute the stabilizing solution;\nC otherwise, compute the anti-stabilizing\nC solution.\nC flag(3) = 0 : compute both the solution X and the\nC feedback gain matrix F;\nC > 0 : compute the solution only;\nC < 0 : compute the related subspace.\nC flag(4) : tolerance to check the singularity of\nC the matrix pencil. If tol <= 0, tol will\nC be replaced by EPS, the machine epsilon.\nC flag(5) = 0 : matrix Q is not factored; otherwise Q is\nC assumed factored as Q = C'*C, where C is\nC P-by-N.\nC flag(6) = 0 : matrix R is not factored; otherwise R is\nC assumed factored as R = D'*D, where D is\nC P-by-M.\nC flag(7) = 0 : the upper triangles of matrices Q and G,\nC or Q and R, are stored; otherwise, lower\nC triangles are stored.\nC flag(8) = 0 : matrix L is zero; otherwise, L is given.\nC flag(9) = 0 : use a scaling strategy (for given R, B);\nC otherwise, do not use a scaling strategy.\nC flag(10) = 0 : iterative refinement should not be used\nC for solving the system of algebraic\nC equations giving the solution matrix X;\nC otherwise, use iterative refinement.\nC Default: flag(1:4) = [0,0,1,0,0,0,0,1,0,0].\nC\nC Output parameters:\nC X - N-by-N real symmetric solution of Riccati equations (1)\nC or (2).\nC F - M-by-N real state feedback matrix, returned only when R\nC and B are input arguments, the number of output parameters\nC is at least 2, and X is computed.\nC Z - 2N-by-N real matrix with orthonormal columns, the basis of\nC the subspace related to the solution X.\nC scale - the scaling factor used internally, which should multiply\nC the submatrix Z(N+1:2N,:) to recover X from Z.\nC ev - complex vector of length N.\nC the \"a\" part of the associated eigenvalues in (3).\nC db - real vector of length N containing the \"b\" part of\nC the associated eigenvalues in (3), i.e., the associated\nC eigenvalues with respect to X are ev(k)/db(k), k=1,...,N.\nC rcond1 - estimate of the reciprocal of the 1-norm condition number\nC of the N-th order system of algebraic equations from which\nC the solution matrix X is obtained.\nC\nC Contributor:\nC V. Sima, Katholieke Univ. Leuven, Belgium, March 2003.\nC\nC Revisions:\nC V. Sima, Research Institute for Informatics, Bucharest, Jan. 2005,\nC Apr. 2009, Dec. 2012, Dec. 2014, Jan. 2015, Apr. 2017.\nC\nC **********************************************************************\nC\nC\n SUBROUTINE MEXFUNCTION( NLHS, PLHS, NRHS, PRHS )\nC\nC .. Parameters ..\n DOUBLE PRECISION ONE, ZERO\n PARAMETER ( ONE = 1.0D0, ZERO = 0.0D0 )\nC\nC .. Mex-file interface parameters ..\n INTEGER PLHS(*), PRHS(*)\n INTEGER*4 NLHS, NRHS\nC\nC .. Mex-file integer functions ..\n INTEGER mxCreateDoubleMatrix, mxGetPr\n INTEGER*4 mxGetM, mxGetN, mxIsNumeric, mxIsComplex\nC\nC .. Scalar parameters used by SLICOT subroutines ..\n CHARACTER ACC, DICO, FACT, FACTR, JOBB, JOBL, SCAL, SORT,\n $ UPLO\n INTEGER INFO, IWARN, LDA, LDB, LDE, LDF, LDL, LDQ, LDR,\n $ LDS, LDT, LDU, LDWORK, LDX, M, N, P\n DOUBLE PRECISION RCOND1, RNORM, TOL\nC\nC .. Allocatable arrays ..\nC !Fortran 90/95 (Fixed dimensions should be used with Fortran 77.)\n LOGICAL, ALLOCATABLE :: BWORK(:)\n INTEGER, ALLOCATABLE :: IPIV(:), IWORK(:)\n DOUBLE PRECISION, ALLOCATABLE :: A(:,:), B(:,:), BETA(:),\n $ DWORK(:), E(:,:), F(:,:), L(:,:),\n $ Q(:,:), R(:,:), S(:,:), T(:,:),\n $ U(:,:), WI(:), WR(:), X(:,:)\n COMPLEX*16, ALLOCATABLE :: EV(:)\nC\nC .. Local variables and constant dimension arrays ..\n LOGICAL WITHF, WITHL, WITHR\n CHARACTER*120 TEXT\n INTEGER FLAG(10), FLAGF, I, IP, ISIZE, LIWORK, LOUT(2),\n $ NCB, NN, NO, NP\n DOUBLE PRECISION FLAGR(10), SCALE\nC\nC .. External Functions ..\n LOGICAL LSAME, MA02HD\n EXTERNAL LSAME, MA02HD\nC\nC .. External subroutines ..\n EXTERNAL SB02ND, SG02AD, SG02ND\nC\nC ..Intrinsic functions..\n INTRINSIC DCMPLX, MAX, MIN\nC\nC Check for proper number of arguments.\nC\n IF ( NRHS.LT.4 ) THEN\n CALL mexErrMsgTxt\n $ ( 'GARESOL requires at least 4 input arguments' )\n ELSE IF ( NLHS.GT.5 ) THEN\n CALL mexErrMsgTxt\n $ ( 'GARESOL requires at most 5 output arguments' )\n END IF\nC\nC A(NxN), E(NxN), Q(NxN), (R(MxM), B(NxM), L(NxM),) (G(NxN))\nC\n N = mxGetM( PRHS(1) )\n P = mxGetM( PRHS(3) )\n NP = mxGetM( PRHS(4) )\n M = mxGetN( PRHS(4) )\nC\n IF ( mxGetN( PRHS(1) ).NE.N ) THEN\n CALL mexErrMsgTxt( 'A must be a square matrix' )\n END IF\n IF ( mxIsNumeric( PRHS(1) ).EQ.0 .OR.\n $ mxIsComplex( PRHS(1) ).EQ.1 ) THEN\n CALL mexErrMsgTxt( 'A must be a real matrix' )\n END IF\nC\n IF ( mxGetM( PRHS(2) ).NE.N .OR. mxGetN( PRHS(2) ).NE.N ) THEN\n CALL mexErrMsgTxt( 'E must have the same dimension as A' )\n END IF\n IF ( mxIsNumeric( PRHS(2) ).EQ.0 .OR.\n $ mxIsComplex( PRHS(2) ).EQ.1 ) THEN\n CALL mexErrMsgTxt( 'E must be a real matrix' )\n END IF\nC\n IF ( mxGetN( PRHS(3) ).NE.N ) THEN\n CALL mexErrMsgTxt\n $ ( 'Q must have the same column dimension as A' )\n END IF\n IF ( mxIsNumeric( PRHS(3) ).EQ.0 .OR.\n $ mxIsComplex( PRHS(3) ).EQ.1 ) THEN\n CALL mexErrMsgTxt( 'Q must be a real matrix' )\n END IF\nC\n IF ( NRHS.GE.6 ) THEN\n JOBB = 'B'\n WITHR = .TRUE.\n IF ( mxIsNumeric( PRHS(4) ).EQ.0 .OR.\n $ mxIsComplex( PRHS(4) ).EQ.1 ) THEN\n CALL mexErrMsgTxt( 'R must be a real matrix' )\n END IF\nC\n IF ( mxGetM( PRHS(5) ).NE.N ) THEN\n CALL mexErrMsgTxt\n $ ( 'B must have the same row dimension as A' )\n END IF\n IF ( mxGetN( PRHS(5) ).NE.M ) THEN\n CALL mexErrMsgTxt\n $ ( 'B must have the same column dimension as R' )\n END IF\n IF ( mxIsNumeric( PRHS(5) ).EQ.0 .OR.\n $ mxIsComplex( PRHS(5) ).EQ.1 ) THEN\n CALL mexErrMsgTxt( 'B must be a real matrix' )\n END IF\nC\n IF ( mxGetM( PRHS(6) ).NE.N ) THEN\n CALL mexErrMsgTxt\n $ ( 'L must have the same row dimension as A' )\n END IF\n IF ( mxGetN( PRHS(6) ).NE.M ) THEN\n CALL mexErrMsgTxt\n $ ( 'L must have the same column dimension as R' )\n END IF\n IF ( mxIsNumeric( PRHS(6) ).EQ.0 .OR.\n $ mxIsComplex( PRHS(6) ).EQ.1 ) THEN\n CALL mexErrMsgTxt( 'L must be a real matrix' )\n END IF\nC\n IP = 7\n ELSE\n JOBB = 'G'\n WITHR = .FALSE.\n IF ( NP.NE.N .OR. M.NE.N ) THEN\n CALL mexErrMsgTxt\n $ ( 'G must have the same dimension as A' )\n END IF\n IF ( mxIsNumeric( PRHS(4) ).EQ.0 .OR.\n $ mxIsComplex( PRHS(4) ).EQ.1 ) THEN\n CALL mexErrMsgTxt( 'G must be a real matrix' )\n END IF\n IP = 5\n END IF\nC\n DO 10 I = 1, 10\n FLAG(I) = 0\n 10 CONTINUE\nC\n FLAG(3) = 1\n FLAG(8) = 1\nC\n IF ( NRHS.GE.IP ) THEN\nC\nC flag\nC\n ISIZE = mxGetM( PRHS(IP) ) * mxGetN( PRHS(IP) )\n IF ( ISIZE.GT.10 )\n $ CALL mexErrMsgTxt\n $ ( 'FLAG must be a vector with at most 10 elements' )\n IF ( mxIsNumeric( PRHS(IP) ).EQ.0 .OR.\n $ mxIsComplex( PRHS(IP) ).EQ.1 ) THEN\n CALL mexErrMsgTxt( 'FLAG must be a real vector' )\n END IF\n CALL mxCopyPtrToReal8( mxGetPr( PRHS(IP) ), FLAGR, ISIZE )\nC\n DO 20 I = 1, ISIZE\n FLAG(I) = FLAGR(I)\n 20 CONTINUE\nC\n END IF\nC\n IF ( FLAG(1).EQ.0 ) THEN\n DICO = 'C'\n ELSE\n DICO = 'D'\n END IF\nC\n IF ( FLAG(2).EQ.0 ) THEN\n SORT = 'S'\n ELSE\n SORT = 'U'\n END IF\n FLAGF = FLAG(3)\n WITHF = FLAGF.EQ.0 .AND. WITHR .AND. NLHS.GE.2\n TOL = FLAGR(4)\nC\n IF ( FLAG(5).EQ.0 .AND. P.NE.N )\n $ CALL mexErrMsgTxt( 'Q must have the same size as A' )\n IF ( WITHR ) THEN\n IF ( FLAG(6).EQ.0 ) THEN\n FACTR = 'N'\n IF ( NP.NE.M )\n $ CALL mexErrMsgTxt( 'R must be a square matrix' )\n ELSE\n FACTR = 'D'\n IF ( FLAG(5).NE.0 .AND. NP.NE.P ) THEN\n CALL mexErrMsgTxt\n $ ( 'D must must have the same row dimension as C' )\n END IF\n END IF\n ELSE\n FLAG(6) = 0\n FLAG(8) = 0\n END IF\nC\n IF ( FLAG(5).EQ.0 ) THEN\n IF ( FLAG(6).EQ.0 ) THEN\n FACT = 'N'\n ELSE\n FACT = 'D'\n END IF\n ELSE\n IF ( FLAG(6).EQ.0 ) THEN\n FACT = 'C'\n ELSE\n FACT = 'B'\n END IF\n END IF\nC\n IF ( FLAG(7).EQ.0 ) THEN\n UPLO = 'U'\n ELSE\n UPLO = 'L'\n END IF\nC\n IF ( FLAG(8).EQ.0 ) THEN\n JOBL = 'Z'\n WITHL = .FALSE.\n ELSE\n JOBL = 'N'\n WITHL = .TRUE.\n END IF\nC\n IF ( FLAG(9).EQ.0 .AND. WITHR ) THEN\n SCAL = 'G'\n ELSE\n SCAL = 'N'\n END IF\nC\n IF ( FLAG(10).EQ.0 ) THEN\n ACC = 'N'\n ELSE\n ACC = 'R'\n END IF\nC\nC Determine the lenghts of working arrays.\nC Use a larger value for LDWORK for enabling calls of block algorithms\nC in DGEES or DGGES, and also in DGEQRF/DGEQLF (M*NB), DGETRI (N*NB),\nC DSYTRF (M*NB), DORMQL (2*N*NB).\nC\n NN = 2*N\n LDA = MAX( 1, N )\n LDE = LDA\n LDB = LDA\n LDU = MAX( 1, NN )\n LDL = 1\nC\n LDWORK = MAX( 7*(2*N + 1) + 16, 16*N )\n IF ( WITHR ) THEN\n NCB = M\n LDS = MAX( 1, NN + M )\n LIWORK = MAX( 1, M, NN )\n LDWORK = MAX( LDWORK, 2*N + M, 3*M )\n IF ( WITHL )\n $ LDL = LDA\n ELSE\n NCB = N\n LDS = LDU\n LIWORK = LDU\n END IF\n LDQ = MAX( 1, P )\n LDR = MAX( 1, NP )\n LDT = LDS\n LDX = LDA\nC\nC Allocate variable dimension local arrays.\nC !Fortran 90/95\nC\n ALLOCATE( A(LDA,N), E(LDE,N), B(LDB,NCB), Q(LDQ,N), U(LDU,NN),\n $ EV(N), WR(NN), WI(NN), IWORK(LIWORK), DWORK(LDWORK),\n $ BWORK(NN), T(LDT,NN), BETA(NN), S(LDS,LDS), X(LDX,N) )\n IF ( WITHR ) THEN\n ALLOCATE( R(LDR,M) )\n IF ( WITHL )\n $ ALLOCATE( L(LDL,M) )\n IF ( WITHF ) THEN\n LDF = LDR\n ALLOCATE( F(LDF,N), IPIV(M) )\n END IF\n END IF\nC\nC Copy inputs from MATLAB workspace to locally allocated arrays.\nC\n CALL mxCopyPtrToReal8( mxGetPr( PRHS(1) ), A, N*N )\n CALL mxCopyPtrToReal8( mxGetPr( PRHS(2) ), E, N*N )\n CALL mxCopyPtrToReal8( mxGetPr( PRHS(3) ), Q, P*N )\nC\n IF ( WITHR ) THEN\n CALL mxCopyPtrToReal8( mxGetPr( PRHS(4) ), R, NP*M )\n CALL mxCopyPtrToReal8( mxGetPr( PRHS(5) ), B, N*M )\n IF ( WITHL )\n $ CALL mxCopyPtrToReal8( mxGetPr( PRHS(6) ), L, N*M )\nC\n ELSE\n CALL mxCopyPtrToReal8( mxGetPr( PRHS(4) ), B, N*N )\n END IF\nC\nC Do the actual computations.\nC\n CALL SG02AD( DICO, JOBB, FACT, UPLO, JOBL, SCAL, SORT, ACC, N,\n $ M, P, A, LDA, E, LDE, B, LDB, Q, LDQ, R, LDR, L, LDL,\n $ RCOND1, X, LDX, WR, WI, BETA, S, LDS, T, LDT, U, LDU,\n $ TOL, IWORK, DWORK, LDWORK, BWORK, IWARN, INFO )\nC\n IF ( INFO.NE.0 ) THEN\n WRITE( TEXT, '('' INFO = '', I4, '' ON EXIT FROM SG02AD'')' )\n $ INFO\n GO TO 40\n END IF\nC\n SCALE = DWORK(4)\n IF ( WITHF ) THEN\n IF ( FLAG(1).EQ.0 ) THEN\n IF ( N.EQ.0 .OR. MA02HD( 'Full', N, N, ONE, E, LDE ) ) THEN\n CALL SB02ND( DICO, FACTR, UPLO, JOBL, N, M, P, A, LDA, B,\n $ LDB, R, LDR, IPIV, L, LDL, X, LDX, RNORM, F,\n $ LDF, LOUT, IWORK, DWORK, LDWORK, INFO )\n ELSE\n CALL SG02ND( DICO, 'GenE', 'Kalman', 'No XE', FACTR,\n $ UPLO, JOBL, 'NoTrans', N, M, P, A, LDA, E,\n $ LDE, B, LDB, R, LDR, IPIV, L, LDL, X, LDX,\n $ RNORM, F, LDF, A, 1, A, 1, LOUT, IWORK,\n $ DWORK, LDWORK, INFO )\n END IF\n ELSE\n CALL SB02ND( DICO, FACTR, UPLO, JOBL, N, M, P, A, LDA, B,\n $ LDB, R, LDR, IPIV, L, LDL, X, LDX, RNORM, F,\n $ LDF, LOUT, IWORK, DWORK, LDWORK, INFO )\n END IF\nC\n IF ( INFO.NE.0 ) THEN\n WRITE( TEXT, '('' INFO = '', I4, '' ON EXIT FROM SB02ND'')')\n $ INFO\n GO TO 40\n END IF\n END IF\nC\nC Copy output to MATLAB workspace.\nC\n IF ( INFO.EQ.0 ) THEN\n IF ( FLAGF.GE.0 ) THEN\n PLHS(1) = mxCreateDoubleMatrix( N, N, 0 )\n CALL mxCopyReal8ToPtr( X, mxGetPr( PLHS(1) ), N*N )\n NO = 2\n IF ( WITHF ) THEN\n PLHS(2) = mxCreateDoubleMatrix( M, N, 0 )\n CALL mxCopyReal8ToPtr( F, mxGetPr( PLHS(2) ), M*N )\n NO = NO + 1\n END IF\n ELSE\n PLHS(1) = mxCreateDoubleMatrix( NN, N, 0 )\n CALL mxCopyReal8ToPtr( U, mxGetPr( PLHS(1) ), NN*N )\n PLHS(2) = mxCreateDoubleMatrix( 1, 1, 0 )\n CALL mxCopyReal8ToPtr( SCALE, mxGetPr( PLHS(2) ), 1 )\n NO = 3\n END IF\nC\n IF ( NLHS.GE.NO ) THEN\nC\n DO 30 I = 1, N\n EV(I) = DCMPLX( WR(I), WI(I) )\n 30 CONTINUE\nC\n NP = MIN( 1, N )\n PLHS(NO) = mxCreateDoubleMatrix( N, NP, 1 )\n CALL mxCopyComplex16ToPtr( EV, mxGetPr( PLHS(NO) ),\n $ mxGetPi( PLHS(NO) ), N*NP )\n NO = NO + 1\n PLHS(NO) = mxCreateDoubleMatrix( N, NP, 0 )\n CALL mxCopyReal8ToPtr( BETA, mxGetPr( PLHS(NO) ), N*NP )\n END IF\nC\n NO = NO + 1\n IF ( NLHS.GE.NO ) THEN\n PLHS(NO) = mxCreateDoubleMatrix( 1, 1, 0 )\n CALL mxCopyReal8ToPtr( RCOND1, mxGetPr( PLHS(NO) ), 1 )\n END IF\n END IF\nC\nC Deallocate local arrays.\nC !Fortran 90/95\nC\n 40 CONTINUE\nC\n DEALLOCATE( A, E, B, Q, S, U, EV, WR, WI, IWORK, DWORK, BWORK,\n $ T, X, BETA )\n IF ( WITHR ) THEN\n DEALLOCATE( R )\n IF ( WITHL )\n $ DEALLOCATE( L )\n IF ( WITHF )\n $ DEALLOCATE( F, IPIV )\n END IF\nC\nC Error and warning handling.\nC\n IF ( INFO.NE.0 ) THEN\n CALL mexErrMsgTxt( TEXT )\n ELSE IF ( IWARN.NE.0 ) THEN\n WRITE( TEXT, '('' IWARN = '',I4,'' ON EXIT FROM SG02AD'')'\n $ ) IWARN\n CALL mexPrintf( TEXT )\n END IF\nC\n RETURN\nC\nC *** Last line of GARESOL ***\n END\n", "meta": {"hexsha": "b302e46cb84eaa5022e8db7ce171a2b138fb29b5", "size": 18644, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "mex_src/garesol.f", "max_stars_repo_name": "SLICOT/SLICOT-BasicControl", "max_stars_repo_head_hexsha": "f8a1715a56fe5503347da61e57c2d97e9dd08cee", "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": "mex_src/garesol.f", "max_issues_repo_name": "SLICOT/SLICOT-BasicControl", "max_issues_repo_head_hexsha": "f8a1715a56fe5503347da61e57c2d97e9dd08cee", "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": "mex_src/garesol.f", "max_forks_repo_name": "SLICOT/SLICOT-BasicControl", "max_forks_repo_head_hexsha": "f8a1715a56fe5503347da61e57c2d97e9dd08cee", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-27T09:49:32.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-27T09:49:32.000Z", "avg_line_length": 34.2091743119, "max_line_length": 72, "alphanum_fraction": 0.4778481013, "num_tokens": 6072, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133531922388, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6900087407051213}} {"text": "!-------------------------------------------------------------------------------!\r\n! !\r\n\r\nsubroutine fitgauss(s,yag,y,w,nlocal,yfit)\r\n\r\n! (1) Fit local asymmetric Gaussian functions !\r\n! !\r\n! / !\r\n! | c(1) + c(2)*exp(-((x(1)-t)/x(2)).^x(3)), t <= x(1) !\r\n! y(t) = | !\r\n! | c(1) + c(2)*exp(-((t-x(1))/x(4)).^x(5)), t > x(1) ! \r\n! \\ !\r\n! !\r\n! in an iterative proceedure to approach the upper/lower envelope of !\r\n! the data values. The linear, c(1) and c(2), and non-linear x(1),...,x(5) !\r\n! parameters are determined using Marquard's method. Note that we separate !\r\n! the two parameter sets in order to improve performance. The non-linear !\r\n! parameters are box constrained bl(i) <= x(i) <= bu(i) to ensure that we !\r\n! find a phenologically sound solution. ! \r\n! !\r\n! (2) Merge the local functions to a global function !\r\n! !\r\n! Authors: !\r\n! Per J\\\"onsson, Malm\\\"o University, Sweden !\r\n! e-mail per.jonsson@ts.mah.se !\r\n! !\r\n! Lars Eklundh, Lund University, Sweden !\r\n! e-mail lars.eklundh@nateko.lu.se !\r\n! !\r\n! Improved estimates of starting parameters !\r\n! !\r\n! Updated September 2006 !\r\n! !\r\n!-------------------------------------------------------------------------------!\r\n\r\nimplicit none\r\n\r\ninteger :: i,j,k,l,nyear,nptperyear,npt,nenvi,printflag,debugflag,win(3)\r\ninteger :: m0,m1,m2,n,n1,n2,nmid,nlocal,s(4*nyear+2),term,nseason,kmin,lmin\r\ninteger :: sumnonconstant\r\ndouble precision :: wfact,y(npt),w(npt),yfit(npt),wfit(npt),ylocal(nlocal,npt)\r\ndouble precision :: width,x(5),xn(5),ones(npt),t(npt),cut,ndiff,mid\r\ndouble precision :: exparg(npt),arg(npt),ytilde(npt),Btilde(npt,2),c(2),bl(5),bu(5)\r\ndouble precision :: yag(2*nptperyear,7,2),fact(7),chi2,chi2min,ymed\r\n\r\ncommon /parameters/ nyear,nptperyear,npt,nenvi,printflag,debugflag,wfact,win \r\n\r\nyfit = y\r\nwfit = w\r\nylocal = 0.d0\r\nones = 1.d0\r\n\r\n!---- Initiate matrix that will contain the local functions --------------------- \r\n\r\nylocal = 0.d0\r\n\r\n!---- Define widths for one and two seasons respectively ------------------------\r\n\r\nif (nlocal/nyear == 2) then\r\n width = nptperyear/4.d0\r\n nseason = 1\r\nelse \r\n width = nptperyear/8.d0\r\n nseason = 2;\r\nend if\r\n\r\nfact = (/ 0.2d0, 0.4d0, 0.7d0, 1.d0, 1.3d0, 1.7d0, 2.1d0 /)\r\n\r\n!---- Iterative fits to local asymmetric Gaussians in all intervalls ------------\r\n\r\ndo j = 1,nenvi\r\n do i = 1,nlocal \r\n \r\n!---- Fitting intervall given by [m0,m2] ---------------------------------------- \r\n \r\n m0 = s(i)\r\n m1 = s(i+1)\r\n m2 = s(i+2)\r\n\tn = m2 - m0 + 1\r\n\r\n!---- Check if the are enought non constant data values in the intervall ---------\r\n\r\n sumnonconstant = 0\r\n\tdo k = m0,m2-1\r\n\t if (abs(y(k) - y(k+1)) < 1.d-6) then\r\n\t sumnonconstant = sumnonconstant + 1\r\n\t end if\r\n\tend do\r\n\r\n\tif ((sumnonconstant < 3.d0*(m2-m0+1)/4.d0) .and. (count(w(m0:m2) == 0.d0) < 3.d0*(m2-m0+1)/4.d0)) then\r\n\r\n \r\n!---- Initial estimates of fitting parameters ----------------------------------- \r\n! Loop over width and position in time \r\n\r\n chi2min = 1.d60\r\n\r\n\t do k = 1,7\r\n\t do l = 1,5\r\n\t x(1) = floor(m1 - m0 + dble(l-3)*width/3.d0)\r\n\t\t if ( (1.d0 <= x(1)) .and. (x(1) <= dble(n-1)) ) then\r\n\t\t nmid = x(1)\r\n\t\t x(1) = x(1) + 0.5d0 \r\n\t\t exparg(1:n) = yag(nptperyear-nmid+1:nptperyear+n-nmid,k,nseason) \r\n ytilde(1:n) = wfit(m0:m2)*y(m0:m2)\r\n Btilde(1:n,1:2) = reshape(source = (/ wfit(m0:m2), wfit(m0:m2)*exparg(1:n) /), &\r\n\t shape = (/ n,2 /)) \r\n\t call gauss(2,matmul(transpose(Btilde(1:n,1:2)),Btilde(1:n,1:2)), &\r\n\t matmul(ytilde(1:n),Btilde(1:n,1:2)),c)\r\n\r\n!---- Evaluate the fitted function and compute chi-square ---------------------- \r\n \r\n ylocal(i,m0:m2) = c(1) + c(2)*exparg(1:n)\t\t \r\n\t\t chi2 = sum((wfit(m0:m2)*(ylocal(i,m0:m2)-y(m0:m2)))**2.d0)\r\n\t\t if (chi2 < chi2min) then\r\n\t\t chi2min = chi2\r\n\t\t\t kmin = k\r\n\t\t\t lmin = l\r\n\t end if \r\n\t\t\r\n\t\t end if\r\n\t end do\r\n\t end do \r\n\t\t \r\n!---- Best starting values ------------------------------------------------------\t\t \r\n\t\t \r\n x(1) = floor(m1 - m0 + (lmin-3.d0)*width/3.d0) + 0.5d0 \r\n x(2) = width*fact(kmin)/(log(2.d0)**0.25d0)\r\n x(4) = x(2)\r\n x(3) = 3.d0\r\n x(5) = 3.d0\r\n\t\t \r\n!---- Set constraints -----------------------------------------------------------\r\n\r\n bl = (/ 1.d0+0.01d0, 0.6d0*x(2), 2.d0, 0.6d0*x(4), 2.d0 /)\r\n bu = (/ n-0.01d0, 1.4d0*x(2), 8.d0, 1.4d0*x(4), 8.d0 /)\r\n \r\n!---- Separable box constrained non-linear least squares fit -------------------- \r\n\r\n! write(*,*) 'Gauss,x,chi2min',x,chi2min\r\n\t call marquardt(1,term,x,xn,bl,bu,5,y(m0:m2),wfit(m0:m2),n)\r\n!\t write(*,*) 'xn',xn\r\n!\t pause\r\n\t nmid = floor(xn(1))\r\n\r\n!---- Final linear fit to determine c(1) and c(2) -------------------------------\r\n\r\n t = dble((/(i,i=1,npt)/))\r\n! write(*,*) nmid+1, n\r\n! changed for compiling in gfortran\r\nif(nmid .LE. n) then\r\n arg(1:n) = (/ ((xn(1)-t(1:nmid))/xn(2))**xn(3), &\r\n\t ((t(nmid+1:n)-xn(1))/xn(4))**xn(5) /)\r\nelse\r\n arg(1:n) = ((xn(1)-t(1:nmid))/xn(2))**xn(3) \r\nend if\r\n exparg(1:n) = exp(-arg(1:n)) \r\n ytilde(1:n) = wfit(m0:m2)*y(m0:m2)\r\n Btilde(1:n,1:2) = reshape(source = (/ wfit(m0:m2), wfit(m0:m2)*exparg(1:n) /), &\r\n\t shape = (/ n,2 /)) \r\n\t call gauss(2,matmul(transpose(Btilde(1:n,1:2)),Btilde(1:n,1:2)), &\r\n\t matmul(ytilde(1:n),Btilde(1:n,1:2)),c)\r\n \r\n!---- Evaluate the fitted function ---------------------------------------------- \r\n \r\n ylocal(i,m0:m2) = c(1) + c(2)*exparg(1:n)\r\n\r\n \r\n else \r\n\t\r\n!---- If many constant values in interval replace with median value -------------\r\n\t \r\n\t call median(y(m0:m2),m2-m0+1,ymed)\r\n\t ylocal(i,m0:m2) = ymed\r\n \r\n\tend if\r\n \r\n end do ! end loop over local functions \r\n \r\n!---- Merge local functions to a global function -------------------------------- \r\n \r\n do i = 2,nlocal\r\n n1 = s(i)\r\n n2 = s(i+1)\r\n\tndiff = dble(n2 - n1)\r\n mid = (n1 + n2)/2.d0 \r\n do k = n1,n2 \r\n cut = (atan(10.d0*(k-mid)/ndiff) - atan(10.d0*(n1-mid)/ndiff))/ &\r\n (atan(10.d0*(n2-mid)/ndiff) - atan(10.d0*(n1-mid)/ndiff))\r\n yfit(k) = cut*ylocal(i,k) + (1.d0-cut)*ylocal(i-1,k)\r\n end do\r\n end do\r\n \r\n!---- Add points in the beginning and at the end -------------------------------\r\n \r\n yfit(s(1):s(2)) = ylocal(1,s(1):s(2))\r\n yfit(s(nlocal+1):s(nlocal+2)) = ylocal(nlocal,s(nlocal+1):s(nlocal+2)) \r\n\r\n!---- Modify weights --------------------\r\n\r\n if (j < nenvi) then\r\n call modweight(j,npt,wfit,y,yfit)\r\n end if\r\n\r\nend do ! end loop over envelope iterations\r\n\r\n!---- Output for debug purposes ------------------------------------------------\r\n\r\n! write(*,*) 2,sum(yfit)\r\n\r\nend subroutine fitgauss\r\n", "meta": {"hexsha": "84eb32f438371d183736fd8ed15afdc06fd1b794", "size": 8226, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/Smooth_Gapfill_LAI/fitgauss.f90", "max_stars_repo_name": "bucricket/projectMASpreprocess", "max_stars_repo_head_hexsha": "608495d7cd6890ecca6ad2a8be0d15b5ea80f7c1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-28T20:26:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T20:26:59.000Z", "max_issues_repo_path": "source/Smooth_Gapfill_LAI/fitgauss.f90", "max_issues_repo_name": "bucricket/projectMASpreprocess", "max_issues_repo_head_hexsha": "608495d7cd6890ecca6ad2a8be0d15b5ea80f7c1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/Smooth_Gapfill_LAI/fitgauss.f90", "max_forks_repo_name": "bucricket/projectMASpreprocess", "max_forks_repo_head_hexsha": "608495d7cd6890ecca6ad2a8be0d15b5ea80f7c1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-04-20T21:04:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-16T08:05:44.000Z", "avg_line_length": 38.8018867925, "max_line_length": 104, "alphanum_fraction": 0.4048140044, "num_tokens": 2449, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133515091156, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6900087394695078}} {"text": " program sndrv2\nc\nc Simple program to illustrate the idea of reverse communication\nc in shift-invert mode for a standard nonsymmetric eigenvalue problem.\nc\nc We implement example two of ex-nonsym.doc in DOCUMENTS directory\nc\nc\\Example-2\nc ... Suppose we want to solve A*x = lambda*x in shift-invert mode,\nc where A is derived from the centered difference discretization\nc of the 1-dimensional convection-diffusion operator\nc (d^2u / dx^2) + rho*(du/dx) \nc on the interval [0,1] with zero Dirichlet boundary condition.\nc\nc ... The shift sigma is a real number.\nc\nc ... OP = inv[A-sigma*I] and B = I.\nc\nc ... Use mode 3 of SNAUPD.\nc\nc\\BeginLib\nc\nc\\Routines called:\nc snaupd ARPACK reverse communication interface routine.\nc sneupd ARPACK routine that returns Ritz values and (optionally)\nc Ritz vectors.\nc sgttrf LAPACK tridiagonal factorization routine.\nc sgttrs LAPACK tridiagonal solve routine.\nc slapy2 LAPACK routine to compute sqrt(x**2+y**2) carefully.\nc saxpy Level 1 BLAS that computes y <- alpha*x+y.\nc scopy Level 1 BLAS that copies one vector to another.\nc sdot Level 1 BLAS that computes the dot product of two vectors.\nc snrm2 Level 1 BLAS that computes the norm of a vector.\nc av Matrix vector multiplication routine that computes A*x.\nc\nc\\Author\nc Richard Lehoucq\nc Danny Sorensen\nc Chao Yang\nc Dept. of Computational &\nc Applied Mathematics\nc Rice University\nc Houston, Texas\nc\nc\\SCCS Information: @(#)\nc FILE: ndrv2.F SID: 2.4 DATE OF SID: 4/22/96 RELEASE: 2\nc\nc\\Remarks\nc 1. None\nc\nc\\EndLib\nc--------------------------------------------------------------------------\nc\nc %-----------------------------%\nc | Define leading dimensions |\nc | for all arrays. |\nc | MAXN: Maximum dimension |\nc | of the A allowed. |\nc | MAXNEV: Maximum NEV allowed |\nc | MAXNCV: Maximum NCV allowed |\nc %-----------------------------%\nc\n integer maxn, maxnev, maxncv, ldv\n parameter (maxn=256, maxnev=10, maxncv=25, \n & ldv=maxn )\nc\nc %--------------%\nc | Local Arrays |\nc %--------------%\nc\n integer iparam(11), ipntr(14), ipiv(maxn)\n logical select(maxncv)\n Real\n & ax(maxn), d(maxncv,3), resid(maxn),\n & v(ldv, maxncv), workd(3*maxn),\n & workev(3*maxncv),\n & workl(3*maxncv*maxncv+6*maxncv),\n & dd(maxn), dl(maxn), du(maxn),\n & du2(maxn)\nc\nc %---------------%\nc | Local Scalars |\nc %---------------%\nc\n character bmat*1, which*2\n integer ido, n, nev, ncv, lworkl, info, j,\n & ierr, nconv, maxitr, ishfts, mode\n Real\n & tol, h, s,\n & sigmar, sigmai, s1, s2, s3\n logical first, rvec\nc\nc %------------%\nc | Parameters |\nc %------------%\nc\n Real\n & one, zero, two, rho\n common /convct/ rho\n parameter (one = 1.0E+0, zero = 0.0E+0, \n & two = 2.0E+0)\nc\nc %-----------------------------%\nc | BLAS & LAPACK routines used |\nc %-----------------------------%\nc\n Real\n & sdot, snrm2, slapy2\n external sgttrf, sgttrs, sdot, snrm2, slapy2\nc\nc %--------------------%\nc | Intrinsic function |\nc %--------------------%\nc\n intrinsic abs\nc\nc %-----------------------%\nc | Executable statements |\nc %-----------------------%\nc\nc %--------------------------------------------------%\nc | The number N is the dimension of the matrix. A |\nc | standard eigenvalue problem is solved (BMAT = |\nc | 'I'). NEV is the number of eigenvalues (closest |\nc | to the shift SIGMAR) to be approximated. Since |\nc | the shift-invert mode is used, WHICH is set to |\nc | 'LM'. The user can modify NEV, NCV, SIGMAR to |\nc | solve problems of different sizes, and to get |\nc | different parts of the spectrum. However, The |\nc | following conditions must be satisfied: |\nc | N <= MAXN, | \nc | NEV <= MAXNEV, |\nc | NEV + 2 <= NCV <= MAXNCV | \nc %--------------------------------------------------%\nc\n n = 100\n nev = 4 \n ncv = 20 \n if ( n .gt. maxn ) then\n print *, ' ERROR with _NDRV2: N is greater than MAXN '\n go to 9000\n else if ( nev .gt. maxnev ) then\n print *, ' ERROR with _NDRV2: NEV is greater than MAXNEV '\n go to 9000\n else if ( ncv .gt. maxncv ) then\n print *, ' ERROR with _NDRV2: NCV is greater than MAXNCV '\n go to 9000\n end if\n bmat = 'I'\n which = 'LM'\n sigmar = 1.0E+0 \n sigmai = 0.0E+0 \nc\nc %----------------------------------------------------%\nc | Construct C = A - SIGMA*I in real arithmetic, and |\nc | factor C in real arithmetic using LAPACK |\nc | subroutine sgttrf. The matrix A is chosen to be |\nc | the tridiagonal matrix derived from standard |\nc | central difference of the 1-d convection diffusion |\nc | operator u\" + rho*u' on the interval [0, 1] with | \nc | zero Dirichlet boundary condition. |\nc %----------------------------------------------------%\nc\n rho = 1.0E+1\n h = one / real(n+1)\n s = rho*h / two\nc\n s1 = -one-s \n s2 = two - sigmar\n s3 = -one+s \nc\n do 10 j = 1, n-1\n dl(j) = s1 \n dd(j) = s2\n du(j) = s3\n 10 continue \n dd(n) = s2 \nc \n call sgttrf(n, dl, dd, du, du2, ipiv, ierr)\n if ( ierr .ne. 0 ) then\n print*, ' ' \n print*, ' ERROR with _gttrf in _NDRV2.'\n print*, ' '\n go to 9000\n end if\nc \nc %-----------------------------------------------------%\nc | The work array WORKL is used in SNAUPD as |\nc | workspace. Its dimension LWORKL is set as |\nc | illustrated below. The parameter TOL determines |\nc | the stopping criterion. If TOL<=0, machine |\nc | precision is used. The variable IDO is used for |\nc | reverse communication, and is initially set to 0. |\nc | Setting INFO=0 indicates that a random vector is |\nc | generated in SNAUPD to start the Arnoldi iteration. |\nc %-----------------------------------------------------%\nc\n lworkl = 3*ncv**2+6*ncv \n tol = zero \n ido = 0\n info = 0\nc\nc %---------------------------------------------------%\nc | This program uses exact shifts with respect to |\nc | the current Hessenberg matrix (IPARAM(1) = 1). |\nc | IPARAM(3) specifies the maximum number of Arnoldi |\nc | iterations allowed. Mode 3 of SNAUPD is used |\nc | (IPARAM(7) = 3). All these options can be |\nc | changed by the user. For details see the |\nc | documentation in SNAUPD. |\nc %---------------------------------------------------%\nc\n ishfts = 1\n maxitr = 300\n mode = 3\n \n iparam(1) = ishfts \n iparam(3) = maxitr \n iparam(7) = mode \nc\nc %-------------------------------------------%\nc | M A I N L O O P (Reverse communication) | \nc %-------------------------------------------%\nc\n 20 continue\nc\nc %---------------------------------------------%\nc | Repeatedly call the routine SNAUPD and take | \nc | actions indicated by parameter IDO until |\nc | either convergence is indicated or maxitr |\nc | has been exceeded. |\nc %---------------------------------------------%\nc\n call snaupd ( ido, bmat, n, which, nev, tol, resid, \n & ncv, v, ldv, iparam, ipntr, workd, workl, lworkl, \n & info )\nc\n if ( ido .eq. -1 .or. ido .eq. 1) then\nc\nc %-------------------------------------------%\nc | Perform y <--- OP*x = inv[A-SIGMA*I]*x |\nc | The user should supply his/her own linear |\nc | system solver here that takes |\nc | workd(ipntr(1)) as the input, and returns |\nc | the result to workd(ipntr(2)). |\nc %-------------------------------------------%\nc\n call scopy( n, workd(ipntr(1)), 1, workd(ipntr(2)), 1)\nc\n call sgttrs('N', n, 1, dl, dd, du, du2, ipiv, \n & workd(ipntr(2)), n, ierr) \n if ( ierr .ne. 0 ) then\n print*, ' ' \n print*, ' ERROR with _gttrs in _NDRV2.'\n print*, ' '\n go to 9000\n end if\nc\nc %-----------------------------------------%\nc | L O O P B A C K to call SNAUPD again. |\nc %-----------------------------------------%\nc\n go to 20\nc\n end if\nc\nc %-----------------------------------------%\nc | Either we have convergence, or there is |\nc | an error. |\nc %-----------------------------------------%\nc\n if ( info .lt. 0 ) then\nc\nc %--------------------------%\nc | Error message, check the |\nc | documentation in SNAUPD. |\nc %--------------------------%\nc\n print *, ' '\n print *, ' Error with _naupd, info = ', info\n print *, ' Check the documentation in _naupd.'\n print *, ' ' \nc\n else \nc\nc %-------------------------------------------%\nc | No fatal errors occurred. |\nc | Post-Process using SNEUPD. |\nc | |\nc | Computed eigenvalues may be extracted. | \nc | |\nc | Eigenvectors may also be computed now if |\nc | desired. (indicated by rvec = .true.) | \nc %-------------------------------------------%\nc \n rvec = .true.\nc\n call sneupd ( rvec, 'A', select, d, d(1,2), v, ldv, \n & sigmar, sigmai, workev, bmat, n, which, nev, tol, \n & resid, ncv, v, ldv, iparam, ipntr, workd, \n & workl, lworkl, ierr ) \nc\nc %-----------------------------------------------%\nc | The real part of the eigenvalue is returned |\nc | in the first column of the two dimensional |\nc | array D, and the imaginary part is returned |\nc | in the second column of D. The corresponding |\nc | eigenvectors are returned in the first NEV |\nc | columns of the two dimensional array V if |\nc | requested. Otherwise, an orthogonal basis |\nc | for the invariant subspace corresponding to |\nc | the eigenvalues in D is returned in V. |\nc %-----------------------------------------------%\nc\n if ( ierr .ne. 0 ) then\nc\nc %------------------------------------%\nc | Error condition: |\nc | Check the documentation of SNEUPD. |\nc %------------------------------------%\nc\n print *, ' ' \n print *, ' Error with _neupd, info = ', ierr\n print *, ' Check the documentation of _neupd. '\n print *, ' ' \nc \n else\nc\n first = .true.\n nconv = iparam(5)\n do 30 j=1, nconv\nc\nc %---------------------------%\nc | Compute the residual norm |\nc | |\nc | || A*x - lambda*x || |\nc | |\nc | for the NCONV accurately |\nc | computed eigenvalues and |\nc | eigenvectors. (iparam(5) |\nc | indicates how many are |\nc | accurate to the requested |\nc | tolerance) |\nc %---------------------------%\nc\n if (d(j,2) .eq. zero) then\nc\nc %--------------------%\nc | Ritz value is real |\nc %--------------------%\nc\n call av(n, v(1,j), ax)\n call saxpy(n, -d(j,1), v(1,j), 1, ax, 1)\n d(j,3) = snrm2(n, ax, 1)\n d(j,3) = d(j,3) / abs(d(j,1))\nc\n else if (first) then\nc\nc %------------------------%\nc | Ritz value is complex |\nc | Residual of one Ritz |\nc | value of the conjugate |\nc | pair is computed. | \nc %------------------------%\nc \n call av(n, v(1,j), ax)\n call saxpy(n, -d(j,1), v(1,j), 1, ax, 1)\n call saxpy(n, d(j,2), v(1,j+1), 1, ax, 1)\n d(j,3) = snrm2(n, ax, 1)\n call av(n, v(1,j+1), ax)\n call saxpy(n, -d(j,2), v(1,j), 1, ax, 1)\n call saxpy(n, -d(j,1), v(1,j+1), 1, ax, 1)\n d(j,3) = slapy2( d(j,3), snrm2(n, ax, 1) )\n d(j+1,3) = d(j,3)\n first = .false.\n else\n first = .true.\n end if\nc\n 30 continue\nc\nc %-----------------------------%\nc | Display computed residuals. |\nc %-----------------------------%\nc\n call smout(6, nconv, 3, d, maxncv, -6,\n & 'Ritz values (Real,Imag) and relative residuals')\nc\n end if\nc\nc %-------------------------------------------%\nc | Print additional convergence information. |\nc %-------------------------------------------%\nc\n if ( info .eq. 1) then\n print *, ' '\n print *, ' Maximum number of iterations reached.'\n print *, ' '\n else if ( info .eq. 3) then\n print *, ' ' \n print *, ' No shifts could be applied during implicit\n & Arnoldi update, try increasing NCV.'\n print *, ' '\n end if \nc\n print *, ' '\n print *, ' _NDRV2 '\n print *, ' ====== '\n print *, ' '\n print *, ' Size of the matrix is ', n\n print *, ' The number of Ritz values requested is ', nev\n print *, ' The number of Arnoldi vectors generated',\n & ' (NCV) is ', ncv\n print *, ' What portion of the spectrum: ', which\n print *, ' The number of converged Ritz values is ', \n & nconv \n print *, ' The number of Implicit Arnoldi update',\n & ' iterations taken is ', iparam(3)\n print *, ' The number of OP*x is ', iparam(9)\n print *, ' The convergence criterion is ', tol\n print *, ' '\nc\n end if\nc\nc %---------------------------%\nc | Done with program sndrv2. |\nc %---------------------------%\nc\n 9000 continue\nc\n end\nc\nc-------------------------------------------------------------------\nc\nc matrix vector multiplication subroutine\nc\n subroutine av (n, v, w)\n integer n, j\n Real\n & v(n), w(n), rho, two, one, dd, dl, du, s, h\n common /convct/ rho\n parameter (one = 1.0E+0, two = 2.0E+0 )\nc\nc Compute the matrix vector multiplication y<---A*x\nc where A is a n by n nonsymmetric tridiagonal matrix derived from\nc the central difference discretization of the 1-dimensional\nc convection diffusion operator on the interval [0,1] with\nc zero Dirichlet boundary condition.\nc\nc\n h = one / real(n+1)\n s = rho *h / two\n dd = two\n dl = -one - s\n du = -one + s\nc\n w(1) = dd*v(1) + du*v(2)\n do 10 j = 2,n-1\n w(j) = dl*v(j-1) + dd*v(j) + du*v(j+1)\n 10 continue\n w(n) = dl*v(n-1) + dd*v(n)\n return\n end\n", "meta": {"hexsha": "bec17fbd2de30858d26253dffebd4ba09d1a5454", "size": 16178, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ccx_prool/ARPACK_i8/EXAMPLES/NONSYM/sndrv2.f", "max_stars_repo_name": "alleindrach/calculix-desktop", "max_stars_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ccx_prool/ARPACK_i8/EXAMPLES/NONSYM/sndrv2.f", "max_issues_repo_name": "alleindrach/calculix-desktop", "max_issues_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ccx_prool/ARPACK_i8/EXAMPLES/NONSYM/sndrv2.f", "max_forks_repo_name": "alleindrach/calculix-desktop", "max_forks_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.8663793103, "max_line_length": 75, "alphanum_fraction": 0.4190876499, "num_tokens": 4365, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357735451835, "lm_q2_score": 0.7956581049086031, "lm_q1q2_score": 0.6898640404669254}} {"text": "!*********************************************************************\n!\n! This benchmark test program is measuring a cpu performance\n! of floating point operation by a Poisson equation solver.\n!!\n! If you have any question, please ask me via email.\n! written by Ryutaro HIMENO, November 26, 2001.\n! Version 3.0\n! ----------------------------------------------\n! Ryutaro Himeno, Dr. of Eng.\n! Head of Computer Information Division,\n! RIKEN (The Institute of Pysical and Chemical Research)\n! Email : himeno@postman.riken.go.jp\n! ---------------------------------------------------------------\n! You can adjust the size of this benchmark code to fit your target\n! computer. In that case, please chose following sets of\n! (mimax,mjmax,mkmax):\n! small : 65,33,33\n! small : 129,65,65\n! midium: 257,129,129\n! large : 513,257,257\n! ext.large: 1025,513,513\n! This program is to measure a computer performance in MFLOPS\n! by using a kernel which appears in a linear solver of pressure\n! Poisson eq. which appears in an incompressible Navier-Stokes solver.\n! A point-Jacobi method is employed in this solver as this method can \n! be easyly vectrized and be parallelized.\n! ------------------\n! Finite-difference method, curvilinear coodinate system\n! Vectorizable and parallelizable on each grid point\n! No. of grid points : imax x jmax x kmax including boundaries\n! ------------------\n! A,B,C:coefficient matrix, wrk1: source term of Poisson equation\n! wrk2 : working area, OMEGA : relaxation parameter\n! BND:control variable for boundaries and objects ( = 0 or 1)\n! P: pressure\n! -------------------\n! -------------------\n! \"use portlib\" statement on the next line is for Visual fortran\n! to use UNIX libraries. Please remove it if your system is UNIX.\n! -------------------\n! use portlib\n!\nmodule pres\n real(4),dimension(:,:,:),allocatable :: p\nend module pres\n!\nmodule mtrx\n real(4),dimension(:,:,:,:),allocatable :: a,b,c\nend module mtrx\n!\nmodule bound\n real(4),dimension(:,:,:),allocatable :: bnd\nend module bound\n!\nmodule work\n real(4),dimension(:,:,:),allocatable :: wrk1,wrk2\nend module work\n!\nmodule others\n integer :: mimax,mjmax,mkmax\n integer :: imax,jmax,kmax\n real(4),parameter :: omega=0.8\nend module others\n!\n!\nprogram HimenoBMTxp_F90\n use others\n!\n implicit none\n!\n integer :: nn\n integer :: ic,icr,icm\n real(4) :: flop,xmflops2,score,gosa\n real(8) :: cpu0,cpu1,cpu,dt\n ! ttarget specifys the measuring period in sec\n real(4),parameter :: ttarget=60.0\n real(8),external :: second\n!\n call readparam\n!\n!! Initializing matrixes\n call initmem\n call initmt\n print *,' mimax=',mimax,' mjmax=',mjmax,' mkmax=',mkmax\n print *,' imax=',imax,' jmax=',jmax,' kmax=',kmax\n!\n call system_clock(ic,icr,icm)\n dt= 1.0/real(icr,8)\n print '(2x,a,e10.5)','Time measurement accuracy : ',dt\n!! Start measuring\n!\n nn=3\n print *,' Start rehearsal measurement process.'\n print *,' Measure the performance in 3 times.'\n!\n cpu0=second()\n!! Jacobi iteration\n call jacobi(nn,gosa)\n!\n cpu1=second()\n cpu = (cpu1 - cpu0)*dt\n flop=real(kmax-2,4)*real(jmax-2,4)*real(imax-2,4)*34.0\n if(cpu /= 0.0) xmflops2=flop/real(cpu,4)*1.0e-6*real(nn,4)\n print *,' MFLOPS:',xmflops2,' time(s):',cpu,gosa\n!\n!! end the test loop\n nn=int(ttarget/(cpu/3.0))\n print *,'Now, start the actual measurement process.'\n print *,'The loop will be excuted in',nn,' times.'\n print *,'This will take about one minute.'\n print *,'Wait for a while.'\n!\n!! Jacobi iteration\n cpu0= second()\n!! Jacobi iteration\n call jacobi(nn,gosa)\n!\n cpu1= second()\n cpu = (cpu1 - cpu0)*dt\n if(cpu /= 0.0) xmflops2=flop*1.0e-6/real(cpu,4)*real(nn,4)\n!\n!!! xmflops2=nflop/cpu*1.0e-6*float(nn)\n!\n print *,' Loop executed for ',nn,' times'\n print *,' Gosa :',gosa\n print *,' MFLOPS:',xmflops2, ' time(s):',cpu\n score=xmflops2/82.84\n print *,' Score based on Pentium III 600MHz :',score\n!\n! pause\n! stop\nend program HimenoBMTxp_F90\n!\n!\nsubroutine readparam\n!\n use others\n!\n implicit none\n!\n character(10) :: size\n!\n print *,'Select Grid-size:'\n! print *,'For example:'\n print *,'Grid-size= '\n print *,' XS (64x32x32)'\n print *,' S (128x64x64)'\n print *,' M (256x128x128)'\n print *,' L (512x256x256)'\n print *,' XL (1024x512x512)'\n! print *,' Grid-size = '\n! read(*,*) size\n size=\"M\"\n\n call grid_set(size)\n!\n imax=mimax-1\n jmax=mjmax-1\n kmax=mkmax-1\n!\n return\nend subroutine readparam\n!\n!\nsubroutine grid_set(size)\n!\n use others\n!\n implicit none\n!\n character(10),intent(in) :: size\n!\n select case(size)\n case(\"xs\")\n mimax=65\n mjmax=33\n mkmax=33\n case(\"XS\")\n mimax=65\n mjmax=33\n mkmax=33\n case(\"s\")\n mimax=129\n mjmax=65\n mkmax=65\n case(\"S\")\n mimax=129\n mjmax=65\n mkmax=65\n case(\"m\")\n mimax=257\n mjmax=129\n mkmax=129\n case(\"M\")\n mimax=257\n mjmax=129\n mkmax=129\n case(\"l\")\n mimax=513\n mjmax=257\n mkmax=257\n case(\"L\")\n mimax=513\n mjmax=257\n mkmax=257\n case(\"xl\")\n mimax=1025\n mjmax=513\n mkmax=513\n case(\"XL\")\n mimax=1025\n mjmax=513\n mkmax=513\n case default\n print *,'Invalid input character !!'\n stop\n end select\n!\n return\nend subroutine grid_set\n!\n!\n!**************************************************************\nsubroutine initmt\n!**************************************************************\n use pres\n use mtrx\n use bound\n use work\n use others\n!\n implicit none\n!\n integer :: i,j,k\n!\n! a=0.0\n! b=0.0\n! c=0.0\n! p=0.0\n! wrk1=0.0 \n! wrk2=0.0 \n! bnd=0.0 \n do k=1,mkmax\n do j=1,mjmax\n do i=1,mimax\n a(i,j,k,1)=0.0\n a(i,j,k,2)=0.0\n a(i,j,k,3)=0.0\n a(i,j,k,4)=0.0\n b(i,j,k,1)=0.0\n b(i,j,k,2)=0.0\n b(i,j,k,3)=0.0\n c(i,j,k,1)=0.0\n c(i,j,k,2)=0.0\n c(i,j,k,3)=0.0\n p(i,j,k)=0.0\n wrk1(i,j,k)=0.0 \n wrk2(i,j,k)=0.0 \n bnd(i,j,k)=0.0 \n enddo\n enddo\n enddo\n!\n! a(1:imax,1:jmax,1:kmax,1:3)=1.0\n! a(1:imax,1:jmax,1:kmax,4)=1.0/6.0\n! c(1:imax,1:jmax,1:kmax,:)=1.0\n! bnd(1:imax,1:jmax,1:kmax)=1.0 \n! do k=1,kmax\n! p(:,:,k)=real((k-1)*(k-1),4)/real((kmax-1)*(kmax-1),4)\n! enddo\n do k=1,kmax\n do j=1,jmax\n do i=1,imax\n a(i,j,k,1)=1.0\n a(i,j,k,2)=1.0\n a(i,j,k,3)=1.0\n a(i,j,k,4)=1.0/6.0\n b(i,j,k,1)=0.0\n b(i,j,k,2)=0.0\n b(i,j,k,3)=0.0\n c(i,j,k,1)=1.0\n c(i,j,k,2)=1.0\n c(i,j,k,3)=1.0\n p(i,j,k)=real((k-1)*(k-1),4)/real((kmax-1)*(kmax-1),4)\n wrk1(i,j,k)=0.0 \n wrk2(i,j,k)=0.0 \n bnd(i,j,k)=1.0\n enddo\n enddo\n enddo\n!\n return\nend subroutine initmt\n!\n!*************************************************************\nsubroutine initmem\n!*************************************************************\n use pres\n use mtrx\n use bound\n use work\n use others\n!\n implicit none\n!\n allocate(p(mimax,mjmax,mkmax))\n allocate(a(mimax,mjmax,mkmax,4),b(mimax,mjmax,mkmax,3), &\n c(mimax,mjmax,mkmax,3))\n allocate(bnd(mimax,mjmax,mkmax))\n allocate(wrk1(mimax,mjmax,mkmax),wrk2(mimax,mjmax,mkmax))\n!\n return\nend subroutine initmem\n!\n!*************************************************************\nsubroutine jacobi(nn,gosa)\n!*************************************************************\n use pres\n use mtrx\n use bound\n use work\n use others\n!\n implicit none\n!\n integer,intent(in) :: nn\n real(4),intent(inout) :: gosa\n integer :: i,j,k,loop\n real(4) :: s0,ss\n!\n!\n do loop=1,nn\n gosa= 0.0\n do k=2,kmax-1\n do j=2,jmax-1\n do i=2,imax-1\n s0=a(I,J,K,1)*p(I+1,J,K) &\n +a(I,J,K,2)*p(I,J+1,K) &\n +a(I,J,K,3)*p(I,J,K+1) &\n +b(I,J,K,1)*(p(I+1,J+1,K)-p(I+1,J-1,K) &\n -p(I-1,J+1,K)+p(I-1,J-1,K)) &\n +b(I,J,K,2)*(p(I,J+1,K+1)-p(I,J-1,K+1) &\n -p(I,J+1,K-1)+p(I,J-1,K-1)) &\n +b(I,J,K,3)*(p(I+1,J,K+1)-p(I-1,J,K+1) &\n -p(I+1,J,K-1)+p(I-1,J,K-1)) &\n +c(I,J,K,1)*p(I-1,J,K) &\n +c(I,J,K,2)*p(I,J-1,K) &\n +c(I,J,K,3)*p(I,J,K-1)+wrk1(I,J,K)\n ss=(s0*a(I,J,K,4)-p(I,J,K))*bnd(I,J,K)\n GOSA=GOSA+SS*SS\n wrk2(I,J,K)=p(I,J,K)+OMEGA *SS\n enddo\n enddo\n enddo\n! \n! p(2:imax-1,2:jmax-1,2:kmax-1)= &\n! wrk2(2:imax-1,2:jmax-1,2:kmax-1)\n do k=2,kmax-1\n do j=2,jmax-1\n do i=2,imax-1\n p(I,J,K)=wrk2(I,J,K)\n enddo\n enddo\n enddo\n!\n enddo\n!! End of iteration\n return\nend subroutine jacobi\n!\n!\n!\nfunction second() result(rtime)\n!\n implicit none\n!\n integer :: ic,ir,im\n real(8) :: rtime\n!\n call system_clock(ic,ir,im)\n!\n rtime= real(ic,8)\n!\nend function second\n", "meta": {"hexsha": "3b04e47fe79dfd12b507da5173d95d160f545815", "size": 9135, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "sample/himenoBMTxp.f90", "max_stars_repo_name": "kazukomatsu/autoOMP_f", "max_stars_repo_head_hexsha": "519641e349c12369041da0645bcd3f2444ff46aa", "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": "sample/himenoBMTxp.f90", "max_issues_repo_name": "kazukomatsu/autoOMP_f", "max_issues_repo_head_hexsha": "519641e349c12369041da0645bcd3f2444ff46aa", "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": "sample/himenoBMTxp.f90", "max_forks_repo_name": "kazukomatsu/autoOMP_f", "max_forks_repo_head_hexsha": "519641e349c12369041da0645bcd3f2444ff46aa", "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.6658031088, "max_line_length": 70, "alphanum_fraction": 0.5142857143, "num_tokens": 3161, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357529306639, "lm_q2_score": 0.795658104908603, "lm_q1q2_score": 0.6898640240648158}} {"text": "SUBROUTINE FIB(A,N)\n!\n! CALCULATE FIRST N FIBONACCI NUMBERS\n!\n INTEGER N\n REAL*8 A(N)\n DO I=1,N\n IF (I.EQ.1) THEN\n A(I) = 0.5D0\n ELSEIF (I.EQ.2) THEN\n A(I) = 1.0D0\n ELSE \n A(I) = A(I-1) + A(I-2)\n ENDIF\n ENDDO\nEND", "meta": {"hexsha": "2e5c89bebe7bb4120f927abc364cf0344ed6ea8b", "size": 266, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test_f2py/fib1.f90", "max_stars_repo_name": "temper8/MatBench", "max_stars_repo_head_hexsha": "1ea24d18af35b57ef2d61148709eb6d49835fe97", "max_stars_repo_licenses": ["MIT"], "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_f2py/fib1.f90", "max_issues_repo_name": "temper8/MatBench", "max_issues_repo_head_hexsha": "1ea24d18af35b57ef2d61148709eb6d49835fe97", "max_issues_repo_licenses": ["MIT"], "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_f2py/fib1.f90", "max_forks_repo_name": "temper8/MatBench", "max_forks_repo_head_hexsha": "1ea24d18af35b57ef2d61148709eb6d49835fe97", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.625, "max_line_length": 39, "alphanum_fraction": 0.477443609, "num_tokens": 118, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357529306639, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.6898640219642271}} {"text": " DOUBLE PRECISION FUNCTION DSDOT(N,SX,INCX,SY,INCY)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nC>> 1994-11-11 DSDOT Krogh Declared all vars.\nC>> 1985-08-02 DSDOT Lawson Initial code.\nC\nC RETURNS D.P. DOT PRODUCT ACCUMULATED IN D.P., FOR S.P. SX AND SY\nC DSDOT = SUM FOR I = 0 TO N-1 OF SX(LX+I*INCX) * SY(LY+I*INCY),\nC WHERE LX = 1 IF INCX .GE. 0, ELSE LX = (-INCX)*N, AND LY IS\nC DEFINED IN A SIMILAR WAY USING INCY.\nC\n INTEGER N, INCX, INCY, KX, KY, I, NS\n REAL SX(*),SY(*)\nC\n DSDOT = 0.D0\n IF(N .LE. 0)RETURN\n IF(INCX.EQ.INCY.AND.INCX.GT.0) GO TO 20\n KX = 1\n KY = 1\n IF(INCX.LT.0) KX = 1+(1-N)*INCX\n IF(INCY.LT.0) KY = 1+(1-N)*INCY\n DO 10 I = 1,N\n DSDOT = DSDOT + DBLE(SX(KX))*DBLE(SY(KY))\n KX = KX + INCX\n KY = KY + INCY\n 10 CONTINUE\n RETURN\n 20 CONTINUE\n NS = N*INCX\n DO 30 I=1,NS,INCX\n DSDOT = DSDOT + DBLE(SX(I))*DBLE(SY(I))\n 30 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "4cc4215751f1f203318a9763ddd98c6c5898aa0b", "size": 1118, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/dsdot.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/dsdot.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/dsdot.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": 31.0555555556, "max_line_length": 70, "alphanum_fraction": 0.5688729875, "num_tokens": 448, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.795658090372256, "lm_q1q2_score": 0.6898640169286532}} {"text": "C Copyright 2021 Dennis Blondell Decker\nC Date: 29 May 2021\nC Purpose: Maximum Sum Subarray - Kadane's Algorithm\nC Tectonics: gfortran -ffixed-form -c maxsumsubarray.f90\nC Can handle negative integer sums\nC The ISTART and ISTOP are inclusive as always in Fortran\n\n SUBROUTINE MAXSUMSUBARRAY(NUMBERS,ILEN,ISUM,ISTART,ISTOP)\n DIMENSION NUMBERS(ILEN)\n\n ISUM=-(2**32-1)\n ISTART=1\n ISTOP=1\n ICURSUM=-(2**32-1)\n DO 10 J=1,ILEN\n IF (ICURSUM.LT.0) THEN\n I=J\n ICURSUM=NUMBERS(J)\n ELSE\n ICURSUM=ICURSUM+NUMBERS(J)\n ENDIF\n IF (ICURSUM.GT.ISUM) THEN\n ISUM=ICURSUM\n ISTART=I\n ISTOP=J\n ENDIF\n 10 CONTINUE\n END\n", "meta": {"hexsha": "014ef3557740df6fb2a518bd46c21812c7257b20", "size": 798, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "euler/maxsumsubarray.f90", "max_stars_repo_name": "dennisdjensen/Sketchbook", "max_stars_repo_head_hexsha": "efb4c7df592ba4fe84e9cdcb0883c93823d04bf5", "max_stars_repo_licenses": ["0BSD"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-04-26T19:30:58.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-12T16:34:23.000Z", "max_issues_repo_path": "euler/maxsumsubarray.f90", "max_issues_repo_name": "dennisdjensen/sketchbook", "max_issues_repo_head_hexsha": "efb4c7df592ba4fe84e9cdcb0883c93823d04bf5", "max_issues_repo_licenses": ["0BSD"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "euler/maxsumsubarray.f90", "max_forks_repo_name": "dennisdjensen/sketchbook", "max_forks_repo_head_hexsha": "efb4c7df592ba4fe84e9cdcb0883c93823d04bf5", "max_forks_repo_licenses": ["0BSD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.5172413793, "max_line_length": 63, "alphanum_fraction": 0.5626566416, "num_tokens": 250, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412809, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.6898267553871547}} {"text": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\ncc cc\ncc mnspro : sproot test program cc\ncc application : to find the intersection of a planar cc\ncc cubic spline curve x = sx(u) y = sy(u) with cc\ncc a straight line alfa*x + beta*y = gamma cc\ncc cc\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\n real t(13),c(26),zero(20),sp(40),cc(13)\n integer i,idim,ier,is,i1,i2,j,k,k1,l1,l2,m,mest,n,nc,nk1\n real alfa,beta,gamma,per\nc we have a planar curve\n idim = 2\nc we have a cubic spline curve.\n k = 3\n k1 = k+1\nc set up the dimension information\n nc = 26\n mest = 20\nc n denotes the total number of knots.\n n = 13\nc set up the knots of the spline curve\n t(4) = 0.\n t(5) = 0.2e0\n t(6) = 0.3e0\n t(7) = 0.5e0\n t(8) = 0.6e0\n t(9) = 0.7e0\n t(10) = 0.1e+01\nc fetch the b-spline coefficients for sx(u)\n c(1) = 0.1e+01\n c(2) = 0.3e+01\n c(3) = 0.4e+01\n c(4) = 0.5e+01\n c(5) = 0.3e+01\n c(6) = -0.1e+01\nc fetch the b-spline coefficients for sy(u)\n c(14) = 0.1e+01\n c(15) = 0.2e+01\n c(16) = -0.3e+01\n c(17) = 0.2e+01\n c(18) = 0.1e+01\n c(19) = 0.4e+01\nc we have a closed curve.\nc incorporate the boundary conditions for periodic splines\n per = t(10)-t(4)\n do 10 i=1,3\nc the boundary knots\n t(i) = t(i+6)-per\n t(i+10) = t(i+4)+per\nc the boundary coefficients\n c(i+6) = c(i)\n c(i+19) = c(i+13)\n 10 continue\nc print the data of the spline curve.\n write(6,900) k\n write(6,905)\n write(6,910) (t(i),i=1,n)\n write(6,915)\n nk1 = n-k1\n write(6,920) (c(i),i=1,nk1)\n write(6,925)\n i1 = n+1\n i2 = n+nk1\n write(6,920) (c(i),i=i1,i2)\nc loop for the different lines.\n do 200 is=1,5\n go to (110,120,130,140,150),is\nc fetch the parameters of the straight line.\n 110 alfa = 0.\n beta = 0.1e+01\n gamma = 0.\n go to 160\n 120 alfa = 0.1e+01\n beta = 0.\n go to 160\n 130 beta = -0.1e+01\n go to 160\n 140 alfa = 0.4e0\n beta = 0.3e0\n gamma = 0.12e+01\n go to 160\n 150 beta = 0.4e0\n gamma = 0.\nc print the parameters of the straight line.\n 160 write(6,930) alfa,beta,gamma\nc calculate the coefficients of s(u) = sx(u)*alfa + sy(u)*beta - gamma\n do 170 i=1,nk1\n j = i+n\n cc(i) = alfa*c(i)+beta*c(j)-gamma\n 170 continue\nc find the zeros of s(u)\n call sproot(t,n,cc,zero,mest,m,ier)\n write(6,935) m\n if(m.eq.0) go to 200\nc find the intersection points\n call curev(idim,t,n,c,nc,k,zero,m,sp,nc,ier)\nc print the intersection points\n write(6,940)\n l2 = 0\n do 180 i=1,m\n l1 = l2+1\n l2 = l1+1\n write(6,945) i,zero(i),sp(l1),sp(l2)\n 180 continue\n 200 continue\n stop\nc format statements.\n 900 format(31h0degree of the spline curve k =,i2)\n 905 format(1x,21hposition of the knots)\n 910 format(5x,7f6.1)\n 915 format(1x,30hb-spline coefficients of sx(u))\n 920 format(5x,14f5.0)\n 925 format(1x,30hb-spline coefficients of sy(u))\n 930 format(18h0intersection with,f6.1,5h *x +,f5.1,5h *y =,f5.1)\n 935 format(1x,33hnumber of intersection points m =,i3)\n 940 format(6x,1hi,7x,4hu(i),5x,8hsx(u(i)),4x,8hsy(u(i)))\n 945 format(1x,i6,3f12.5)\n end\n", "meta": {"hexsha": "f5a9c9feeb748faaf2bb312f61a6a2048b2578a5", "size": 3641, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ApproxSpline/Resources/F77-Sources/ex/mnspro.f", "max_stars_repo_name": "modelica-3rdparty/ApproxSpline", "max_stars_repo_head_hexsha": "28420f5c1a88c9cd069defbd8c05e4a78a090675", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-07-13T17:24:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-18T16:16:02.000Z", "max_issues_repo_path": "ApproxSpline/Resources/F77-Sources/ex/mnspro.f", "max_issues_repo_name": "tbeu/ApproxSpline", "max_issues_repo_head_hexsha": "28420f5c1a88c9cd069defbd8c05e4a78a090675", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-03-28T09:08:23.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T07:35:48.000Z", "max_forks_repo_path": "ApproxSpline/Resources/F77-Sources/ex/mnspro.f", "max_forks_repo_name": "modelica-3rdparty/ApproxSpline", "max_forks_repo_head_hexsha": "28420f5c1a88c9cd069defbd8c05e4a78a090675", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-10-21T07:46:49.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T20:02:06.000Z", "avg_line_length": 30.3416666667, "max_line_length": 72, "alphanum_fraction": 0.5383136501, "num_tokens": 1400, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026573249612, "lm_q2_score": 0.7520125848754472, "lm_q1q2_score": 0.6898231424480606}} {"text": "c $Id: ffft.f,v 1.1 2002/12/03 22:09:46 ahotan Exp $\nc $Log: ffft.f,v $\nc Revision 1.1 2002/12/03 22:09:46 ahotan\nc Migrating from tas/archive\nc\nc Revision 1.1.1.1 1998/08/03 06:39:55 mbritton\nc start\nc\nc Revision 1.1 1994/11/25 03:13:05 jsandhu\nc Initial revision\nc\nc Revision 1.1 1994/11/25 03:13:05 jsandhu\nc Initial revision\nc\n\n* ffft.f,v 1.1 93/10/29 22:56:39 will \nC @(#)ffft.f\t1.1 9/7/90\n\tsubroutine ffft(d,npts,isign,ireal)\n\nC Fourier transform of length npts=2**k, performed in place.\nC Input data in array d, treated as complex if ireal=0, and as real if ireal=1.\nC In either case the transform values are returned in array d, treated as\nC complex. The DC term is d(1), and d(npts/2+1) is the term at the Nyquist\nC frequency. The basic algorithm is the same as Norm Brenner's FOUR1, and\nC uses radix-2 transforms.\n\nC J. H. Taylor, Princeton University.\n*\tMODIFICATIONS:\n*\t\tRemoved MAXSAM in size of d() \t- WD 14aug92\n\n\tcomplex d(*),t,w,wstep,tt,uu\n\tdata pi/3.14159265/\n\nC Shuffle the data to bit-reversed order.\n\n\timax=npts/(ireal+1)\n\tirev=1\n\tdo 5 i=1,imax\n\tif(i.ge.irev) go to 2\n\tt=d(i)\n\td(i)=d(irev)\n\td(irev)=t\n2\tmmax=imax/2\n3\tif(irev.le.mmax) go to 5\n\tirev=irev-mmax\n\tmmax=mmax/2\n\tif(mmax.ge.1) go to 3\n5\tirev=irev+mmax\n\nC The radix-2 transform begins here.\n\n\tapi=isign*pi/2.\n\tmmax=1\n6\tistep=2*mmax\n\twstep=cmplx(-2.*sin(api/mmax)**2,sin(2.*api/mmax))\n\tw=1.\n\tdo 9 m=1,mmax\n\nC This in the inner-most loop -- optimization here is important!\n\tdo 8 i=m,imax,istep\n\tt=w*d(i+mmax)\n\td(i+mmax)=d(i)-t\n8\td(i)=d(i)+t\n\n9\tw=w*(1.+wstep)\n\tmmax=istep\n\tif(mmax.lt.imax) go to 6\n\n\tif(ireal.eq.0) return\n\nC Now complete the last stage of a doubled-up real transform.\n\n\tjmax=imax/2 + 1\n\twstep=cmplx(-2.*sin(isign*pi/npts)**2,sin(isign*pi/imax))\n\tw=1.0\n\td(imax+1)=d(1)\n\n\tdo 10 j=1,jmax\n\tuu=cmplx(real(d(j))+real(d(2+imax-j)),aimag(d(j)) - \n + aimag(d(2+imax-j)))\n\ttt=w*cmplx(aimag(d(j))+aimag(d(2+imax-j)),-real(d(j)) +\n + real(d(2+imax-j)))\n\td(j)=uu+tt\n\td(2+imax-j)=conjg(uu-tt)\n10\tw=w*(1.+wstep)\n\n\treturn\n\tend\n", "meta": {"hexsha": "ce98945745784d9ec72ad1a43e5a2741f5f5231e", "size": 2041, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Util/fft/ffft.f", "max_stars_repo_name": "rwharton/psrchive_dsn", "max_stars_repo_head_hexsha": "9584862167154fa48db89b86151c4221ad4bb96b", "max_stars_repo_licenses": ["AFL-2.1"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Util/fft/ffft.f", "max_issues_repo_name": "rwharton/psrchive_dsn", "max_issues_repo_head_hexsha": "9584862167154fa48db89b86151c4221ad4bb96b", "max_issues_repo_licenses": ["AFL-2.1"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Util/fft/ffft.f", "max_forks_repo_name": "rwharton/psrchive_dsn", "max_forks_repo_head_hexsha": "9584862167154fa48db89b86151c4221ad4bb96b", "max_forks_repo_licenses": ["AFL-2.1"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-02-13T20:08:14.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-13T20:08:14.000Z", "avg_line_length": 22.9325842697, "max_line_length": 80, "alphanum_fraction": 0.6663400294, "num_tokens": 865, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026618464796, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.689823135651884}} {"text": "\n! --- potential and force fields\n\n subroutine derivs(x,Ntraj,v,dv,ddv)\n \n use cdat, only : ipot \n\n implicit real*8(a-h,o-z)\n integer*4,intent(IN) :: Ntraj\n real*8,intent(IN) :: x(Ntraj)\n real*8,intent(OUT) :: v(Ntraj),dv(Ntraj),ddv(Ntraj)\n\n! --- eckart barrier \n! v0 = 16d0\n! a = 0.8d0\n!\n! do i=1,ntraj\n! v(i) = v0/cosh(x(i)/a)**2\n! dv(i) = -2d0*v0*tanh(x(i)/a)/a/(cosh(x(i)/a))**2\n! ddv(i) = 4d0*v0*tanh(x(i)/a)**2/a**2/cosh(x(i)/a)**2-2d0*v0* &\n! (1d0-tanh(x(i)/a)**2)/a**2/cosh(x(i)/a)**2\n! enddo\n if (ipot == 1) then \n! ----- quatic oscilator\n ak = 1.d0\n ak2 = 0.01d0 \n\n do i=1,Ntraj\n dv(i) = ak*x(i) + 4d0*ak2*x(i)**3 \n v(i) = ak*x(i)**2/2d0 + ak2*x(i)**4\n ddv(i) = ak + 12d0*ak2*x(i)**2 \n! ddv(i) = 0d0 \n enddo \n\n elseif(ipot == 2) then \n\n!------morse potential with extra bound potential at the right side \n de = 0.176d0\n x0 = 1.4d0\n a = 1.02d0\n beta = 100d0 \n bound = 5d0 \n b = 0d0 \n\n do i=1,Ntraj\n d = (1d0-exp(-a*(x(i)-x0)))\n v(i) = de*d**2\n dv(i) = 2*de*d*a*exp(-a*(x(i)-x0))+b*exp(-beta*(x(i)-bound)**2)\n ddv(i)=2*de*(-d*exp(-a*((x(i)-x0)))*a**2+(exp(-a*(x(i)-x0)))**2*a**2) \n enddo\n \n endif \n!---------doulbe well---------------------------\n! eta = 1.3544d0\n! do i=1,Ntraj\n! v(i) = 1d0/16d0/eta*x(i)**4-0.5d0*x(i)**2\n! dv(i) = 1d0/4d0/eta*x(i)**3-x(i)\n! ddv(i) = 3d0/4d0/eta*x(i)**2-1d0\n! enddo\n\n return\n end subroutine derivs \n", "meta": {"hexsha": "f5a5bfea6bcde05d42b0c8c65cb9ca514b63ae49", "size": 1639, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "GWP/QTGB/resample/derivs.f90", "max_stars_repo_name": "binggu56/qmd", "max_stars_repo_head_hexsha": "e2628710de15f8a8b9a1280fcf92f9e87559414c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "GWP/QTGB/resample/derivs.f90", "max_issues_repo_name": "binggu56/qmd", "max_issues_repo_head_hexsha": "e2628710de15f8a8b9a1280fcf92f9e87559414c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "GWP/QTGB/resample/derivs.f90", "max_forks_repo_name": "binggu56/qmd", "max_forks_repo_head_hexsha": "e2628710de15f8a8b9a1280fcf92f9e87559414c", "max_forks_repo_licenses": ["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.0158730159, "max_line_length": 84, "alphanum_fraction": 0.4362416107, "num_tokens": 708, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436482, "lm_q2_score": 0.7490872075132153, "lm_q1q2_score": 0.6897517637636422}} {"text": "module maths\n use maths_utils, only: cds1, cds2\n implicit none\n private\n public :: mean, cen_diff_stag, cen_diff, uneven_deriv, calc_mfpsi\n\n real, parameter, public :: Half = 0.5, One = 1.\n real, parameter :: Quarter = 0.25\n\ncontains\n\n real function mean(data)\n real, dimension(:,:), intent(in) :: data\n\n mean = sum(data) / size(data)\n end function mean\n\n ! ===========================================================================\n\n function cen_diff_stag(data, rdx, dim)\n real, dimension(:,:), intent(in) :: data\n real, intent(in) :: rdx\n integer, intent(in) :: dim\n real, dimension(cds1(size(data,1),dim),cds2(size(data,2),dim)) :: cen_diff_stag\n\n integer :: nPoints\n \n nPoints = size(data,dim) - 1\n\n select case (dim)\n case (1)\n cen_diff_stag = rdx * (data(2:nPoints+1,:) - data(1:nPoints,:))\n case (2)\n cen_diff_stag = rdx * (data(:,2:nPoints+1) - data(:,1:nPoints))\n case default\n stop \"Error in dim value in cen_diff_stag!\"\n end select\n end function cen_diff_stag\n\n ! ===========================================================================\n\n function cen_diff(d, dxr, dim)\n real, dimension(:,:,:,:), intent(in) :: d\n real, intent(in) :: dxr\n integer, intent(in) :: dim\n real, dimension(size(d,1),size(d,2),size(d,3),size(d,4)) :: cen_diff\n\n integer :: n\n\n n = size(d,dim)\n\n select case (dim)\n case (1)\n cen_diff(2:n-1,:,:,:) = Half * dxr * (d(3:n,:,:,:) - d(1:n-2,:,:,:))\n cen_diff((/1,n/),:,:,:) = dxr * (d((/2,n/),:,:,:) - d((/1,n-1/),:,:,:))\n case (2)\n cen_diff(:,2:n-1,:,:) = Half * dxr * (d(:,3:n,:,:) - d(:,1:n-2,:,:))\n cen_diff(:,(/1,n/),:,:) = dxr * (d(:,(/2,n/),:,:) - d(:,(/1,n-1/),:,:))\n case (4)\n cen_diff(:,:,:,2:n-1) = Half * dxr * (d(:,:,:,3:n) - d(:,:,:,1:n-2))\n cen_diff(:,:,:,(/1,n/)) = dxr * (d(:,:,:,(/2,n/)) - d(:,:,:,(/1,n-1/)))\n case default\n stop \"Bad dim in cen_diff!\"\n end select\n end function cen_diff\n\n ! ===========================================================================\n\n function uneven_deriv(d, coordVal, dim)\n real, dimension(:,:,:,:), intent(in) :: d\n real, dimension(:), intent(in) :: coordVal\n integer, intent(in) :: dim\n real, dimension(size(d,1),size(d,2),size(d,3),size(d,4)) :: uneven_deriv\n\n real, dimension(2:size(coordVal)) :: deltaCoord\n real, dimension(3) :: c\n integer :: n, i\n \n n = size(d,dim)\n if (n /= size(coordVal)) stop \"Arrays don't conform in uneven_deriv!\"\n \n deltaCoord = coordVal(2:) - coordVal(:n-1)\n select case (dim)\n case (3)\n do i = 2, n - 1\n c = deriv_coeff(deltaCoord(i), deltaCoord(i+1))\n uneven_deriv(:,:,i,:) = c(1) * d(:,:,i-1,:) + c(2) * d(:,:,i,:) + &\n c(3)*d(:,:,i+1,:)\n end do\n uneven_deriv(:,:,(/1,n/),:) = (d(:,:,(/2,n/),:) - &\n d(:,:,(/1,n-1/),:)) / spread(spread(spread(coordVal((/2,n/)) - &\n coordVal((/1,n-1/)),1,size(d,1)),2,size(d,2)),4,size(d,4))\n case default\n stop \"This dim value not implemented in uneven_deriv!\"\n end select\n end function uneven_deriv\n\n ! ===========================================================================\n\n function calc_mfpsi(mfu, mfv)\n real, dimension(:,:), intent(in) :: mfu, mfv\n real, dimension(size(mfv,1)-1,size(mfu,2)-1) :: calc_mfpsi\n\n integer :: nx, ny!, i, j\n\n nx = size(mfv,1)\n ny = size(mfu,2)\n if (size(mfv,2) /= ny-1 .or. size(mfu,1) /= nx-1) stop \"Mismatch in mfpsi!\"\n \n calc_mfpsi = Quarter * (mfu(:,:ny-1)+mfu(:,2:) + mfv(:nx-1,:)+mfv(2:,:))\n!!$ do j = 1, ny-1\n!!$ do i = 1, nx-1\n!!$ calc_mfpsi(i,j) = Quarter * &\n!!$ (mfu(i,j) + mfu(i,j+1) + mfv(i,j) + mfv(i+1,j))\n!!$ end do\n!!$ end do\n end function calc_mfpsi\n\n ! ===========================================================================\n\n ! A function to calculate the coefficients for taking a first derivative\n ! with variable grid spacing\n pure function deriv_coeff(d1, d2)\n real, intent(in) :: d1, d2 ! Grid spacings adj. to derivative pt.\n real, dimension(3) :: deriv_coeff\n \n deriv_coeff(1) = -d2 / (d1 * (d1+d2))\n deriv_coeff(2) = (d2**2 - d1**2) / (d1 * d2 * (d1+d2))\n deriv_coeff(3) = d1 / (d2 * (d1+d2))\n end function deriv_coeff\n \nend module maths\n", "meta": {"hexsha": "b47ebce706e1e1f3ed7254cecfb89ed8236b46c0", "size": 4502, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "maths.f90", "max_stars_repo_name": "huangynj/pv", "max_stars_repo_head_hexsha": "bf65888a83b8af4f3bef54c7ea4929e8a99e3cf5", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2016-07-08T05:24:53.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-10T17:10:39.000Z", "max_issues_repo_path": "maths.f90", "max_issues_repo_name": "sgdecker/pv", "max_issues_repo_head_hexsha": "bf65888a83b8af4f3bef54c7ea4929e8a99e3cf5", "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": "maths.f90", "max_forks_repo_name": "sgdecker/pv", "max_forks_repo_head_hexsha": "bf65888a83b8af4f3bef54c7ea4929e8a99e3cf5", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-10-25T17:06:49.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-10T17:08:48.000Z", "avg_line_length": 33.8496240602, "max_line_length": 83, "alphanum_fraction": 0.4675699689, "num_tokens": 1413, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765328159726, "lm_q2_score": 0.7549149978955811, "lm_q1q2_score": 0.6897481178480118}} {"text": "program main\n use MathClass\n implicit none\n\n integer(int32) :: d, e, lambda,prime1,prime2,seed,id_rsa(2),id_rsa_pub(2)\n integer(int32) :: message, ciphertext,a,m\n\n prime1=61\n prime2=53\n seed=17\n call rsa_keygen(prime1,prime2,seed,id_rsa,id_rsa_pub)\n \n message=1234\n print *, \"message = \", message\n \n ciphertext = rsa_encrypt(id_rsa_pub,message)\n print *, \"ciphertext = \", ciphertext\n\n message = rsa_decrypt(id_rsa,ciphertext)\n print *, \"message = \", message\n print *, \">>>>>>>>>>>>>>>>>>>>>>>>>\"\n print *, \"Private key \",id_rsa\n print *, \"Public key \",id_rsa_pub\n print *, \"<<<<<<<<<<<<<<<<<<<<<<<<<\"\n \nend program main", "meta": {"hexsha": "d046e8a0827b6d7f6b49af7747827a68d85d475e", "size": 683, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/app/RSAencryption/RSAencryption.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/RSAencryption/RSAencryption.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/RSAencryption/RSAencryption.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": 26.2692307692, "max_line_length": 77, "alphanum_fraction": 0.5900439239, "num_tokens": 187, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148512, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6897481042230831}} {"text": " function sqrt_1(T)\n implicit none\n \n type(Tensor1), intent(in) :: T\n type(Tensor1) :: sqrt_1\n\n sqrt_1%a = dsqrt(T%a)\n \n end function sqrt_1\n\n function stretch_2(T)\n ! Source:\n !\n ! Franca, L.P. (1989): AN ALGORITHM TO COMPUTE\n ! THE SQUARE ROOT OF A POSITIVE DEFINITE MATRIX\n ! \n implicit none\n \n type(Tensor2), intent(in) :: T\n type(Tensor2) :: stretch_2\n \n real(kind=8) :: I_T,II_T,III_T,I_U,II_U,III_U,k,l,lam,phi\n\n ! Invariants of T\n I_T = tr(T)\n II_T = 0.5*(I_T**2-T**T)\n III_T = det(T)\n k = I_T**2-3.*II_T\n \n ! Isotropy check\n if (dabs(k).le.1.0d-8) then\n lam = (I_T/3.)**(1./2.)\n stretch_2 = lam * identity2(T)\n return\n end if\n \n ! Calculate largest eigenvalues\n l = I_T**3 - 9./2. * I_T*II_T + 27./2. * III_T\n phi = dacos(l/k**(3./2.))\n lam = dsqrt(1./3.*(I_T+2*k**(1./2.)*dcos(phi/3.)))\n \n ! Invariants of U\n III_U = (III_T)**(1./2.)\n I_U = lam + dsqrt(-lam**2+I_T+2.*III_U/lam)\n II_U = (I_U**2-I_T)/2.\n \n print *, 'test', l,k,1-l**2/k**3\n \n stretch_2 = 1./(I_U*II_U-III_U)\n * *(I_U*III_U*identity2(T) + (I_U**2-II_U)*T-T**2)\n \n end function stretch_2\n \n function stretch_2s(T)\n ! Source:\n !\n ! Franca, L.P. (1989): AN ALGORITHM TO COMPUTE\n ! THE SQUARE ROOT OF A POSITIVE DEFINITE MATRIX\n ! \n implicit none\n \n type(Tensor2s), intent(in) :: T\n type(Tensor2s) :: stretch_2s\n \n real(kind=8) :: I_T,II_T,III_T,I_U,II_U,III_U,k,l,lam,phi\n\n ! Invariants of T\n I_T = tr(T)\n II_T = 0.5*(I_T**2-tr(T*T))\n III_T = det(T)\n k = I_T**2-3.*II_T\n \n ! Isotropy check\n if (k.le.1.0d-8) then\n lam = (I_T/3.)**(1./2.)\n stretch_2s = lam * identity2(T)\n return\n end if\n \n ! Calculate largest eigenvalues\n l = I_T**3 - 9./2. * I_T*II_T + 27./2. * III_T\n phi = dacos(l/k**(3./2.))\n lam = dsqrt(1./3.*(I_T+2*k**(1./2.)*dcos(phi/3.)))\n \n ! Invariants of U\n III_U = (III_T)**(1./2.)\n I_U = lam + dsqrt(-lam**2+I_T+2.*III_U/lam)\n II_U = (I_U**2-I_T)/2.\n\n stretch_2s = 1./(I_U*II_U-III_U)\n * *(I_U*III_U*identity2(T) + (I_U**2-II_U)*T-T*T)\n \n end function stretch_2s", "meta": {"hexsha": "c36e331add2b493ccd68df33fc8202238985c39f", "size": 2578, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ttb/libsqrt.f", "max_stars_repo_name": "kengwit/ttb", "max_stars_repo_head_hexsha": "e3e41fdc0a3b47a45f762d8d89dafce3ace838f4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 41, "max_stars_repo_stars_event_min_datetime": "2018-02-27T06:31:19.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-30T07:58:45.000Z", "max_issues_repo_path": "ttb/libsqrt.f", "max_issues_repo_name": "kengwit/ttb", "max_issues_repo_head_hexsha": "e3e41fdc0a3b47a45f762d8d89dafce3ace838f4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 22, "max_issues_repo_issues_event_min_datetime": "2017-12-01T07:47:36.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-16T05:42:06.000Z", "max_forks_repo_path": "ttb/libsqrt.f", "max_forks_repo_name": "kengwit/ttb", "max_forks_repo_head_hexsha": "e3e41fdc0a3b47a45f762d8d89dafce3ace838f4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-07-12T01:45:20.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-25T08:03:13.000Z", "avg_line_length": 27.7204301075, "max_line_length": 65, "alphanum_fraction": 0.4561675718, "num_tokens": 878, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.913676518712608, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6897481021631796}} {"text": "FUNCTION erf(x) RESULT(fn_val)\r\n!-----------------------------------------------------------------------\r\n! EVALUATION OF THE REAL ERROR FUNCTION\r\n! Based upon a Fortran 66 routine in the Naval Surface Warfare Center's\r\n! Mathematics Library (1993 version).\r\n! Adapted by Alan.Miller @ vic.cmis.csiro.au\r\n!-----------------------------------------------------------------------\r\nIMPLICIT NONE\r\nINTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(14, 60) ! `Double precision'\r\n\r\nREAL (dp), INTENT(IN) :: x\r\nREAL (dp) :: fn_val\r\n\r\n! Local variables\r\n\r\nREAL (dp), PARAMETER :: c = .564189583547756_dp, one = 1.0_dp, half = 0.5_dp, &\r\n zero = 0.0_dp\r\nREAL (dp), PARAMETER :: &\r\n a(5) = (/ .771058495001320D-04, -.133733772997339D-02, &\r\n .323076579225834D-01, .479137145607681D-01, &\r\n .128379167095513D+00 /), &\r\n b(3) = (/ .301048631703895D-02, .538971687740286D-01, &\r\n .375795757275549D+00 /), &\r\n p(8) = (/ -1.36864857382717D-07, 5.64195517478974D-01, &\r\n 7.21175825088309D+00, 4.31622272220567D+01, &\r\n 1.52989285046940D+02, 3.39320816734344D+02, &\r\n 4.51918953711873D+02, 3.00459261020162D+02 /), &\r\n q(8) = (/ 1.00000000000000D+00, 1.27827273196294D+01, &\r\n 7.70001529352295D+01, 2.77585444743988D+02, &\r\n 6.38980264465631D+02, 9.31354094850610D+02, &\r\n 7.90950925327898D+02, 3.00459260956983D+02 /), &\r\n r(5) = (/ 2.10144126479064D+00, 2.62370141675169D+01, &\r\n 2.13688200555087D+01, 4.65807828718470D+00, &\r\n 2.82094791773523D-01 /), &\r\n s(4) = (/ 9.41537750555460D+01, 1.87114811799590D+02, &\r\n 9.90191814623914D+01, 1.80124575948747D+01 /)\r\nREAL (dp) :: ax, bot, t, top, x2\r\n!-------------------------\r\nax = ABS(x)\r\n\r\nIF (ax <= half) THEN\r\n t = x*x\r\n top = ((((a(1)*t + a(2))*t + a(3))*t + a(4))*t + a(5)) + one\r\n bot = ((b(1)*t + b(2))*t + b(3))*t + one\r\n fn_val = x*(top/bot)\r\n RETURN\r\nEND IF\r\n\r\nIF (ax <= 4.0_dp) THEN\r\n top = ((((((p(1)*ax + p(2))*ax + p(3))*ax + p(4))*ax + p(5))*ax &\r\n + p(6))*ax + p(7))*ax + p(8)\r\n bot = ((((((q(1)*ax + q(2))*ax + q(3))*ax + q(4))*ax + q(5))*ax &\r\n + q(6))*ax + q(7))*ax + q(8)\r\n fn_val = half + (half - EXP(-x*x)*top/bot)\r\n IF (x < zero) fn_val = -fn_val\r\n RETURN\r\nEND IF\r\n\r\nIF (ax < 5.8_dp) THEN\r\n x2 = x*x\r\n t = one / x2\r\n top = (((r(1)*t + r(2))*t + r(3))*t + r(4))*t + r(5)\r\n bot = (((s(1)*t + s(2))*t + s(3))*t + s(4))*t + one\r\n fn_val = (c - top/(x2*bot)) / ax\r\n fn_val = half + (half - EXP(-x2)*fn_val)\r\n IF (x < zero) fn_val = -fn_val\r\n RETURN\r\nEND IF\r\n\r\nfn_val = SIGN(one, x)\r\nRETURN\r\nEND FUNCTION erf\r\n", "meta": {"hexsha": "6a2d195e83ea766b83ff1d42206009a0905461e4", "size": 2870, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/erf.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/erf.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/erf.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": 39.3150684932, "max_line_length": 80, "alphanum_fraction": 0.4735191638, "num_tokens": 1096, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765187126079, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6897481021631795}} {"text": " SUBROUTINE shape4 (nnode, shape, deriv ,xita, eta, zeta )\r\n !********************************************************************\r\n !\r\n !*** calculates shape functions and their derivatives for 3d\r\n ! prismatic elements\r\n !\r\n !********************************************************************\r\n IMPLICIT NONE\r\n\r\n INTEGER(Kind=4) :: nnode\r\n REAL (kind=8) deriv(nnode,3),shape(nnode),xita,eta,zeta\r\n\r\n REAL (kind=8) l1,l2,zzet,bf\r\n\r\n l1 = (1d0-zeta)/2d0 !linear functions L1\r\n l2 = (1d0+zeta)/2d0 ! L2\r\n zzet = 1d0-xita-eta !third area coordinate\r\n\r\n IF( nnode == 6 )THEN\r\n !*** shape functions\r\n\r\n shape(1) = zzet * l1\r\n shape(2) = xita * l1\r\n shape(3) = eta * l1\r\n shape(4) = zzet * l2\r\n shape(5) = xita * l2\r\n shape(6) = eta * l2\r\n\r\n !*** and derivatives\r\n\r\n deriv(1,1) = -l1\r\n deriv(2,1) = l1\r\n deriv(3,1) = 0d0\r\n deriv(4,1) = -l2\r\n deriv(5,1) = l2\r\n deriv(6,1) = 0d0\r\n\r\n deriv(1,2) = -l1\r\n deriv(2,2) = 0d0\r\n deriv(3,2) = l1\r\n deriv(4,2) = -l2\r\n deriv(5,2) = 0d0\r\n deriv(6,2) = l2\r\n\r\n deriv(1,3) = -zzet/2d0\r\n deriv(2,3) = -xita/2d0\r\n deriv(3,3) = -eta /2d0\r\n deriv(4,3) = zzet/2d0\r\n deriv(5,3) = xita/2d0\r\n deriv(6,3) = eta /2d0\r\n\r\n ELSE IF( nnode == 15 )THEN\r\n bf = 1d0 - zeta**2 !bubble function\r\n shape(1) = zzet*(2d0*zzet-1d0)*l1 - zzet*bf/2d0\r\n shape(2) = xita*(2d0*xita-1d0)*l1 - xita*bf/2d0\r\n shape(3) = eta *(2d0*eta -1d0)*l1 - eta *bf/2d0\r\n shape(4) = zzet*(2d0*zzet-1d0)*l2 - zzet*bf/2d0\r\n shape(5) = xita*(2d0*xita-1d0)*l2 - xita*bf/2d0\r\n shape(6) = eta *(2d0*eta -1d0)*l2 - eta *bf/2d0\r\n shape(7) = 4d0*zzet*xita*l1\r\n shape(8) = 4d0*xita*eta *l1\r\n shape(9) = 4d0*eta *zzet*l1\r\n shape(10) = zzet*bf\r\n shape(11) = xita*bf\r\n shape(12) = eta *bf\r\n shape(13) = 4d0*zzet*xita*l2\r\n shape(14) = 4d0*xita*eta *l2\r\n shape(15) = 4d0*eta *zzet*l2\r\n\r\n deriv(1,1) = (-4d0*zzet+1d0)*l1 + bf/2d0\r\n deriv(2,1) = (4d0*xita-1d0)*l1 - bf/2d0\r\n deriv(3,1) = 0d0\r\n deriv(4,1) = (-4d0*zzet+1d0)*l2 + bf/2d0\r\n deriv(5,1) = (4d0*xita-1d0)*l2 - bf/2d0\r\n deriv(6,1) = 0d0\r\n deriv(7,1) = 4d0*(zzet-xita)*l1\r\n deriv(8,1) = 4d0*eta * l1\r\n deriv(9,1) = -4d0*eta * l1\r\n deriv(10,1) = -bf\r\n deriv(11,1) = bf\r\n deriv(12,1) = 0d0\r\n deriv(13,1) = 4d0*(zzet-xita)*l2\r\n deriv(14,1) = 4d0*eta * l2\r\n deriv(15,1) = -4d0*eta * l2\r\n\r\n deriv(1,2) = (-4d0*zzet+1d0)*l1 + bf/2d0\r\n deriv(2,2) = 0d0\r\n deriv(3,2) = (4d0*eta -1d0)*l1 - bf/2d0\r\n deriv(4,2) = (-4d0*zzet+1d0)*l2 + bf/2d0\r\n deriv(5,2) = 0d0\r\n deriv(6,2) = (4d0*eta -1d0)*l2 - bf/2d0\r\n deriv(7,2) = -4d0*xita* l1\r\n deriv(8,2) = 4d0*xita* l1\r\n deriv(9,2) = 4d0*(-eta+zzet)*l1\r\n deriv(10,2) = -bf\r\n deriv(11,2) = 0d0\r\n deriv(12,2) = bf\r\n deriv(13,2) = -4d0*xita* l2\r\n deriv(14,2) = 4d0*xita* l2\r\n deriv(15,2) = 4d0*(-eta+zzet)*l2\r\n\r\n deriv(1,3) = -zzet*(2d0*zzet-1d0)/2d0 + zzet*zeta\r\n deriv(2,3) = -xita*(2d0*xita-1d0)/2d0 + xita*zeta\r\n deriv(3,3) = -eta *(2d0*eta -1d0)/2d0 + eta *zeta\r\n deriv(4,3) = zzet*(2d0*zzet-1d0)/2d0 + zzet*zeta\r\n deriv(5,3) = xita*(2d0*xita-1d0)/2d0 + xita*zeta\r\n deriv(6,3) = eta *(2d0*eta -1d0)/2d0 + eta *zeta\r\n deriv(7,3) = -2d0*zzet*xita\r\n deriv(8,3) = -2d0*xita*eta\r\n deriv(9,3) = -2d0*eta *zzet\r\n deriv(10,3) = -zzet*2d0*zeta\r\n deriv(11,3) = -xita*2d0*zeta\r\n deriv(12,3) = -eta *2d0*zeta\r\n deriv(13,3) = 2d0*zzet*xita\r\n deriv(14,3) = 2d0*xita*eta\r\n deriv(15,3) = 2d0*eta *zzet\r\n END IF\r\n\r\n RETURN\r\n END SUBROUTINE shape4\r\n", "meta": {"hexsha": "013f6cc891c026e2bf48e9556318ab0c4f56aafc", "size": 3779, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/auxil/shape4.f90", "max_stars_repo_name": "jerebenitez/IFE-simpact-openfoam", "max_stars_repo_head_hexsha": "2dbcbf3195b22fca1c80ad0da6b3822b6cad5cdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/auxil/shape4.f90", "max_issues_repo_name": "jerebenitez/IFE-simpact-openfoam", "max_issues_repo_head_hexsha": "2dbcbf3195b22fca1c80ad0da6b3822b6cad5cdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/auxil/shape4.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": 31.2314049587, "max_line_length": 71, "alphanum_fraction": 0.4834612331, "num_tokens": 1818, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148513, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6897480991850923}} {"text": "module fwdmodel\nuse comm,only: J,wp,c_int,pi,c\nimplicit none\n\nprivate\npublic:: chirp, chirp_phase\ncontains\n\n\npure subroutine chirp(bm,tm,t,Ns,range_m,Atarg,Ntarg,nlfm,y)\n\ninteger(c_int), intent(in) :: Ns,Ntarg\nreal(wp), intent(in) :: bm,tm,t(Ns),range_m(Ntarg),Atarg(Ntarg),nlfm\ncomplex(wp),intent(out) :: y(Ns)\n\ncomplex(wp) :: LO(Ns)\nreal(wp) :: phase(Ns), toffs(Ntarg)\ninteger :: i\n\ntoffs = 2*range_m/c !two-way delay\n\ncall chirp_phase(bm,tm,t,Ns,nlfm,phase)\n! radar transmit\nLO = exp(J*phase)\n! generate target returns\ny = 0.\ndo concurrent (i=1:Ntarg)\n call chirp_phase(bm,tm,t+toffs(i),Ns,nlfm,phase)\n y = y + Atarg(i) * exp(J*phase) * conjg(LO)\nenddo\n\nend subroutine chirp\n\npure subroutine chirp_phase(bm,tm,t,Ns,nlfm,phase)\n\ninteger(c_int), intent(in) :: Ns\nreal(wp), intent(in) :: bm,tm,nlfm,t(Ns)\nreal(wp), intent(out):: phase(Ns)\n\nreal(wp) :: B1, B2\n\nB1 = bm / tm\nB2 = bm / tm**2\n\nphase = 2._wp*pi*(-0.5_wp*bm*t & !starting freq\n + 0.5_wp*B1*t**2 & !linear ramp (\"derivative of phase is frequency\")\n + 0.5_wp*nlfm*B2*t**3) !quadratic frequency\n\nend subroutine chirp_phase\n\nend module fwdmodel\n", "meta": {"hexsha": "a237ad5a0d5920c1de19bf22d5fd40a23522e2da", "size": 1136, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fwdmodel.f90", "max_stars_repo_name": "scienceopen/tin-can-radar", "max_stars_repo_head_hexsha": "1791c6247c0f0a1d82e6b7fcfd9c59a53c56b850", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2016-06-22T08:19:27.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-15T13:37:56.000Z", "max_issues_repo_path": "fwdmodel.f90", "max_issues_repo_name": "scivision/tincanradar", "max_issues_repo_head_hexsha": "1791c6247c0f0a1d82e6b7fcfd9c59a53c56b850", "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": "fwdmodel.f90", "max_forks_repo_name": "scivision/tincanradar", "max_forks_repo_head_hexsha": "1791c6247c0f0a1d82e6b7fcfd9c59a53c56b850", "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": 21.8461538462, "max_line_length": 82, "alphanum_fraction": 0.6698943662, "num_tokens": 420, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765234137296, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.689748095636145}} {"text": " Program zupmtr_example\n\n! ZUPMTR Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use blas_interfaces, Only: dznrm2\n Use lapack_example_aux, Only: nagf_file_print_matrix_complex_gen_comp\n Use lapack_interfaces, Only: dstebz, zhptrd, zstein, zupmtr\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Real (Kind=dp), Parameter :: zero = 0.0E0_dp\n Integer, Parameter :: nin = 5, nout = 6\n! .. Local Scalars ..\n Complex (Kind=dp) :: scal\n Real (Kind=dp) :: vl, vu\n Integer :: i, ifail, info, j, k, ldc, m, n, nsplit\n Character (1) :: uplo\n! .. Local Arrays ..\n Complex (Kind=dp), Allocatable :: ap(:), c(:, :), tau(:), work(:)\n Real (Kind=dp), Allocatable :: d(:), e(:), rwork(:), w(:)\n Integer, Allocatable :: iblock(:), ifailv(:), isplit(:), iwork(:)\n Character (1) :: clabs(1), rlabs(1)\n! .. Intrinsic Procedures ..\n Intrinsic :: abs, conjg, maxloc\n! .. Executable Statements ..\n Write (nout, *) 'ZUPMTR Example Program Results'\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n\n ldc = n\n Allocate (ap(n*(n+1)/2), c(ldc,n), tau(n), work(n), d(n), e(n), rwork(5* &\n n), w(n), iblock(n), ifailv(n), isplit(n), iwork(3*n))\n\n! Read A from data file\n\n Read (nin, *) uplo\n If (uplo=='U') Then\n Read (nin, *)((ap(i+j*(j-1)/2),j=i,n), i=1, n)\n Else If (uplo=='L') Then\n Read (nin, *)((ap(i+(2*n-j)*(j-1)/2),j=1,i), i=1, n)\n End If\n\n! Reduce A to tridiagonal form T = (Q**H)*A*Q\n Call zhptrd(uplo, n, ap, d, e, tau, info)\n\n! Calculate the two smallest eigenvalues of T (same as A)\n\n Call dstebz('I', 'B', n, vl, vu, 1, 2, zero, d, e, m, nsplit, w, iblock, &\n isplit, rwork, iwork, info)\n\n Write (nout, *)\n If (info>0) Then\n Write (nout, *) 'Failure to converge.'\n Else\n Write (nout, *) 'Eigenvalues'\n Write (nout, 100) w(1:m)\n\n! Calculate the eigenvectors of T, storing the result in C\n Call zstein(n, d, e, m, w, iblock, isplit, c, ldc, rwork, iwork, &\n ifailv, info)\n\n If (info>0) Then\n Write (nout, *) 'Failure to converge.'\n Else\n\n! Calculate the eigenvectors of A = Q * (eigenvectors of T)\n Call zupmtr('Left', uplo, 'No transpose', n, m, ap, tau, c, ldc, &\n work, info)\n\n! Print eigenvectors\n\n Write (nout, *)\n Flush (nout)\n\n! Normalize the eigenvectors, largest element real\n Do i = 1, m\n rwork(1:n) = abs(c(1:n,i))\n k = maxloc(rwork(1:n), 1)\n scal = conjg(c(k,i))/abs(c(k,i))/dznrm2(n, c(1,i), 1)\n c(1:n, i) = c(1:n, i)*scal\n End Do\n\n! ifail: behaviour on error exit\n! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft\n ifail = 0\n Call nagf_file_print_matrix_complex_gen_comp('General', ' ', n, m, &\n c, ldc, 'Bracketed', 'F7.4', 'Eigenvectors', 'Integer', rlabs, &\n 'Integer', clabs, 80, 0, ifail)\n\n End If\n End If\n\n100 Format (8X, 4(F7.4,11X,:))\n End Program\n", "meta": {"hexsha": "e40f858c02983c61f625d8418b4ced62e02e9db9", "size": 3398, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/zupmtr_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/zupmtr_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/zupmtr_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 33.6435643564, "max_line_length": 90, "alphanum_fraction": 0.5385520895, "num_tokens": 1116, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765140114859, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6897480885382504}} {"text": "module system_mod\n\nuse global_mod, only: V0,Rm,Amp,rcut\nuse bessel_mod, only: Bessk\n\nimplicit none\n\ncontains \n\n!-----------------------------------------------------------------------\n\n function LogPsi(opt,Rm,rij)\n\n logical,save :: FirstCall = .True.\n real (kind=8) :: Rm\n real (kind=8) :: rij,zij\n real (kind=8) :: K0,K1\n real (kind=8) :: dfdr,d2fdr2\n real (kind=8) :: LogPsi\n integer (kind=4) :: opt\n \n real (kind=8),save :: Lmax,C1,C2,C3\n \n if (FirstCall) then\n \n Lmax = 2.d0*rcut\n\n C3 = 0.5d0*sqrt(4.d0*Rm)*(Lmax-Rm)**2/(Lmax*(Lmax-2.d0*Rm))*&\n & Bessk(1,sqrt(4.d0/Rm))/Bessk(0,sqrt(4.d0/Rm))\n C2 = exp(4.d0*C3/Lmax)\n C1 = C2*exp(-C3*(1.d0/Rm+1.d0/(Lmax-Rm)))/Bessk(0,sqrt(4.d0/Rm))\n \n FirstCall = .False.\n \n end if\n\n zij = sqrt(4.d0/rij)\n \n K0 = Bessk(0,zij)\n K1 = Bessk(1,zij)\n\n if (opt==0) then\n\n if (rij<=Rm) then\n \n LogPsi = log(C1*K0)\n \n else\n \n LogPsi = log(C2)-C3*(1.d0/rij+1.d0/(Lmax-rij))\n \n end if\n\n else if (opt==1) then\n \n if (rij<=Rm) then\n \n dfdr = zij*K1/(2.d0*rij) \n LogPsi = dfdr/K0\n\n else\n\n LogPsi = C3*(1.d0/rij**2-1.d0/(Lmax-rij)**2)\n \n end if\n \n else if (opt==2) then\n\n if (rij<=Rm) then\n\n dfdr = zij*K1/(2.d0*rij)\n d2fdr2 = K0/rij**3-dfdr/rij\n LogPsi = (d2fdr2*K0-dfdr*dfdr)/(K0*K0)\n \n else\n\n LogPsi = -2.d0*C3*(1.d0/rij**3+1.d0/(Lmax-rij)**3)\n\n end if\n\n else \n\n print *, 'The parameter opt in the function LogPsi crash!!!'\n stop\n\n end if\n\n return\n end function LogPsi\n\n!-----------------------------------------------------------------------\n\n function Potential(rij)\n\n implicit none\n \n real (kind=8) :: Potential,rij\n \n Potential = V0/rij**3\n \n end function Potential\n\n!----------------------------------------------------------------------- \n\nend module system_mod\n", "meta": {"hexsha": "c1fce3ef0136adc15d041bd895ef95c1af104e96", "size": 2047, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Algorithm/DiffusionMonteCarlo/system_mod.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/system_mod.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/system_mod.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.3113207547, "max_line_length": 74, "alphanum_fraction": 0.4440644846, "num_tokens": 695, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475715065793, "lm_q2_score": 0.7310585903489891, "lm_q1q2_score": 0.6896423458347422}} {"text": "************************************************************************\r\n*\r\n* Subroutine LOAD95CI Called by: AMLLOAD2\r\n*\r\n* compute 95% confidence intervals\r\n*\r\n************************************************************************\r\n SUBROUTINE LOAD95CI(LOADAML,SEP,LOW95,UP95)\r\n*\r\n* subroutine args\r\n*\r\n DOUBLE PRECISION LOADAML,SEP,LOW95,UP95\r\n*\r\n* local vars\r\n*\r\n DOUBLE PRECISION A,B\r\n*\r\n* compute 95% confidence intervals\r\n*\r\n B = SQRT(LOG(1+(SEP/LOADAML)**2))\r\n A = LOG(LOADAML)-B**2/2.D0\r\n LOW95 = EXP(A-1.96*B)\r\n UP95 = EXP(A+1.96*B)\r\n \r\n RETURN\r\n END\r\n", "meta": {"hexsha": "9b0d61bc45e46d7b13f7d40bd2a88ad0729c8477", "size": 656, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "codeNexampls/[loadest]/loadsrc/loadest/source_USGS/load95ci.f", "max_stars_repo_name": "lthiamodelers/baseflow-coefficients", "max_stars_repo_head_hexsha": "183fef49548fa2e1bf0bb8cff57e96e75d629760", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "codeNexampls/[loadest]/loadsrc/loadest/source_USGS/load95ci.f", "max_issues_repo_name": "lthiamodelers/baseflow-coefficients", "max_issues_repo_head_hexsha": "183fef49548fa2e1bf0bb8cff57e96e75d629760", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "codeNexampls/[loadest]/loadsrc/loadest/source_USGS/load95ci.f", "max_forks_repo_name": "lthiamodelers/baseflow-coefficients", "max_forks_repo_head_hexsha": "183fef49548fa2e1bf0bb8cff57e96e75d629760", "max_forks_repo_licenses": ["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.2962962963, "max_line_length": 73, "alphanum_fraction": 0.4131097561, "num_tokens": 161, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475778774727, "lm_q2_score": 0.7310585727705126, "lm_q1q2_score": 0.6896423339096251}} {"text": "module stats_mod\n implicit none\n\n private\n\n type, public :: stats_t\n real :: sum, sum2\n integer :: n\n end type stats_t\n\n public :: init_stats, add_stats_value, mean_stats\n\ncontains\n\n subroutine init_stats(stats)\n implicit none\n type(stats_t), intent(out) :: stats\n\n stats = stats_t(0.0, 0.0, 0)\n end subroutine init_stats\n\n subroutine add_stats_value(stats, value)\n implicit none\n type(stats_t), intent(inout) :: stats\n real, value :: value\n\n stats%sum = stats%sum + value\n stats%sum2 = stats%sum2 + value**2\n stats%n = stats%n + 1\n end subroutine add_stats_value\n\n function mean_stats(stats) result(mean_value)\n type(stats_t), intent(in) :: stats\n real :: mean_value\n\n call validate(stats)\n associate (sum => stats%sum, n => stats%n)\n mean_value = sum/n\n end associate\n end function mean_stats\n\n subroutine validate(stats, need_stddev)\n use, intrinsic :: iso_fortran_env, only : error_unit\n implicit none\n type(stats_t), intent(in) :: stats\n logical, optional, value :: need_stddev\n\n if (stats%n < 1) then\n write (unit=error_unit, fmt='(A)') 'error: not enough data'\n stop 1\n else if (present(need_stddev)) then\n if (need_stddev .and. stats%n < 2) then\n write (unit=error_unit, fmt='(A)') 'error: not enough data'\n stop 1\n end if\n end if\n end subroutine validate\n\nend module stats_mod\n", "meta": {"hexsha": "b4f16ff0604cb4865147a1f993456abcb0f116e6", "size": 1571, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "scenarios/Week_03/Modules/modules_mod_04.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": "scenarios/Week_03/Modules/modules_mod_04.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": "scenarios/Week_03/Modules/modules_mod_04.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": 26.1833333333, "max_line_length": 75, "alphanum_fraction": 0.5907065563, "num_tokens": 397, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324983301568, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.6896397713600091}} {"text": "program nans\n! Compiler options like -Ofast and -ffast-math break this program.\n! NaN are not IEEE compliant if using such options.\n!\n! Gfortran >= 6 needed for ieee_arithmetic: ieee_is_nan\n\n!> Examples\n\n!> Gfortran 10.2.0 Windows\n! IEEE value isnan hex\n! real 32 NaN T FFC00000\n! real 64 NaN T FFF8000000000000\n! real128 NaN T FFFF8000000000000000000000000000\n! complex 64 NaN T FFC00000\n! complex128 NaN T FFF8000000000000\n! complex256 NaN T FFFF8000000000000000000000000000\n\n!> Ifort 2021.1 Winodws and Ifx 2021.1 Windows\n! IEEE value isnan hex\n! real 32 NaN T 7FC00000\n! real 64 NaN T 7FF8000000000000\n! real128 NaN T 7FFF8000000000000000000000000000\n! complex 64 NaN T 7FC00000\n! complex128 NaN T 7FF8000000000000\n! complex256 NaN T 7FFF8000000000000000000000000000\n\nuse, intrinsic :: iso_fortran_env, only: real32, real64, real128\nuse, intrinsic :: iso_fortran_env, only: int32, int64\nuse, intrinsic :: ieee_arithmetic, only: ieee_value, ieee_quiet_nan, ieee_is_nan\nimplicit none (type, external)\n\nreal(real32) :: nan_real32\nreal(real64) :: nan_real64\nreal(real128) :: nan_real128\ncomplex(real32) :: nan_complex64\ncomplex(real64) :: nan_complex128\ncomplex(real128) :: nan_complex256\n\ninteger(int32) :: ISP\ninteger(int64) :: IDP\ncharacter(*), parameter :: fmt='(A8,I3,2X,F5.1,6X,L1,2X,Z32)'\n\n\n! this is the cross platform way to get NaN on modern compilers including gfortran and ifort.\nnan_real32 = ieee_value(0.,ieee_quiet_nan)\nnan_real64 = ieee_value(0.,ieee_quiet_nan)\nnan_real128 = ieee_value(0.,ieee_quiet_nan)\nnan_complex64 = ieee_value(0., ieee_quiet_nan)\nnan_complex128 = ieee_value(0.,ieee_quiet_nan)\nnan_complex256 = ieee_value(0.,ieee_quiet_nan)\n\n! --------- print results\n\nISP = transfer(nan_real32, ISP)\nIDP = transfer(nan_real64, IDP)\n\nprint '(A10,A8,A8,A28)','IEEE', 'value', 'isnan', 'hex'\nprint fmt,'real',storage_size(nan_real32), nan_real32, ieee_is_nan(nan_real32), ISP\nprint fmt,'real',storage_size(nan_real64), nan_real64, ieee_is_nan(nan_real64), IDP\nprint fmt,'real',storage_size(nan_real128),nan_real128, ieee_is_nan(nan_real128), nan_real128\n\nprint fmt,'complex',storage_size(nan_complex64),real(nan_complex64),ieee_is_nan(real(nan_complex64)),nan_complex64\nprint fmt,'complex',storage_size(nan_complex128),real(nan_complex128),ieee_is_nan(real(nan_complex128)),nan_complex128\nprint fmt,'complex',storage_size(nan_complex256),real(nan_complex256),ieee_is_nan(real(nan_complex256)),nan_complex256\n\n\nend program\n", "meta": {"hexsha": "e9d6f34c250254702dc6cbdf2b88eb8ac8d3e809", "size": 2808, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "real/nans.f90", "max_stars_repo_name": "supershushu/fortran2018-examples", "max_stars_repo_head_hexsha": "f0dc03b80326bc7c06fa31945b6e7406a60c1fa8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 305, "max_stars_repo_stars_event_min_datetime": "2017-12-07T12:47:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T12:03:16.000Z", "max_issues_repo_path": "real/nans.f90", "max_issues_repo_name": "supershushu/fortran2018-examples", "max_issues_repo_head_hexsha": "f0dc03b80326bc7c06fa31945b6e7406a60c1fa8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2018-11-24T15:45:53.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-06T08:10:43.000Z", "max_forks_repo_path": "real/nans.f90", "max_forks_repo_name": "supershushu/fortran2018-examples", "max_forks_repo_head_hexsha": "f0dc03b80326bc7c06fa31945b6e7406a60c1fa8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 60, "max_forks_repo_forks_event_min_datetime": "2017-11-28T07:56:03.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-20T01:37:53.000Z", "avg_line_length": 41.2941176471, "max_line_length": 118, "alphanum_fraction": 0.6837606838, "num_tokens": 834, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84594244507642, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.6896397710444203}} {"text": "program verify_bounds\n implicit none\n integer, parameter :: NR_CASES = 10000\n integer :: i, start_val, end_val, step\n\n do i = 1, NR_CASES\n call generate_bounds(start_val, end_val, step)\n call test_do_loop(start_val, end_val, step)\n end do\n\ncontains\n\n subroutine test_do_loop(start_val, end_val, step)\n implicit none\n integer, value :: start_val, end_val, step\n integer :: i, expected_i, last_val, expected_last_val, &\n nr_iters, expected_nr_iters\n\n nr_iters = 0\n last_val = start_val\n do i = start_val, end_val, step\n nr_iters = nr_iters + 1\n last_val = i\n end do\n expected_nr_iters = (end_val - start_val + step)/step\n if (nr_iters /= expected_nr_iters) then\n print '(5(A, I0))', 'start = ', start_val, &\n ', end = ', end_val, &\n ' step = ', step, &\n ', expected nr. iters = ', expected_nr_iters, &\n ', nr. iters = ', nr_iters\n end if\n if (nr_iters /= 0) then\n expected_last_val = start_val + (nr_iters - 1)*step\n if (last_val /= expected_last_val) then\n print '(5(A, I0))', 'start = ', start_val, &\n ', end = ', end_val, &\n ' step = ', step, &\n ', expected last = ', expected_last_val, &\n ', last = ', last_val\n end if\n end if\n expected_i = start_val + expected_nr_iters*step\n if (i /= expected_i) then\n print '(5(A, I0))', 'start = ', start_val, &\n ', end = ', end_val, &\n ' step = ', step, &\n ', expected i = ', expected_i, &\n ', i = ', i\n end if\n end subroutine test_do_loop\n\n subroutine generate_bounds(start_val, end_val, step)\n implicit none\n integer, intent(out) :: start_val, end_val, step\n\n step = 0\n do while (step == 0)\n step = random_int(-100, 100)\n end do\n if (step >= 0) then\n do while (.true.)\n start_val = random_int(-100, 100)\n end_val = random_int(-100, 100)\n if (start_val <= end_val) exit\n end do\n else\n do while (.true.)\n start_val = random_int(-100, 100)\n end_val = random_int(-100, 100)\n if (start_val >= end_val) exit\n end do\n end if\n end subroutine generate_bounds\n\n function random_int(from_val, to_val) result(r_int)\n implicit none\n integer ,value :: from_val, to_val\n integer :: r_int\n real :: r\n \n call random_number(r)\n r_int = int(from_val + r*(to_val - from_val))\n end function random_int\n\n\nend program verify_bounds\n", "meta": {"hexsha": "5e37431a71780c201256f88b0224be8dd55f8983", "size": 3052, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source_code/iterations/verify_do_loop.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/iterations/verify_do_loop.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/iterations/verify_do_loop.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": 34.6818181818, "max_line_length": 79, "alphanum_fraction": 0.4783748362, "num_tokens": 704, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424373085145, "lm_q2_score": 0.8152324983301567, "lm_q1q2_score": 0.6896397666105222}} {"text": "!> @ingroup insertion_sort_asc\n!> \n!> @brief \n!> Run an insertion sort on a vector of integer values. \n!>\n!> @details \n!> Run an ascending on a vector of integer values to sort them in the specified order.The vector of intergers map is permuted in the same way that the vector vec is permuted to be sorted. It is important that map be at least as long as vec.\n!>\n!> @param vec\n!> The vector integer values to be sorted.\n!>\n!> @param map\n!> Vector of intergers which is permuted in the same way that vec is permuted. If map is a vector of values 1 to N, where N is the length of vec, than, map is the map from vec's original value to vec's final value after the sort.\n!> \n!> @warning\n!> The length of map is not checked within this subroutine. If the length of vec is larger than the length of map, than this subroutine may attempt to access elements outside of map.\n!> \n!> @author Arin R. Bratt\n!> @date 11/07/2014\npure subroutine insertion_sort_asc_map_int(vec,map)\n ! Arguments\n integer, intent(inout) :: vec(:)\n integer, intent(inout) :: map(:)\n \n ! Variables\n integer :: integer_value\n integer :: swap_value\n integer :: i\n integer :: j\n \n \n ! Sort to the first element\n if (vec(size(vec,1)) > vec(1)) then\n integer_value = vec(1)\n else\n integer_value = vec(size(vec,1))\n vec(size(vec,1)) = vec(1)\n end if\n \n do i = size(vec,1) - 1,2,-1\n if (integer_value > vec(i)) then\n ! Swap integer values integer_value and vec(i).\n swap_value = integer_value\n integer_value = vec(i)\n vec(i) = swap_value\n end if\n end do\n\n ! Run regualr insertion sort\n do j = 3,size(vec,1)\n swap_value = vec(j)\n i = j - 1\n if (vec(i) > swap_value) then\n vec(j) = vec(i)\n i = i - 1\n do\n if (.not. vec(i) > swap_value) exit\n vec(i + 1) = vec(i)\n i = i - 1\n end do\n vec(i + 1) = swap_value\n end if\n end do\nend subroutine insertion_sort_asc_map_int\n\n\n", "meta": {"hexsha": "c98939316b7831f851f0c6ff575b0406c1075de8", "size": 1972, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/insertion_sort_asc_map_int.f90", "max_stars_repo_name": "arinrb/bsort", "max_stars_repo_head_hexsha": "17cc0e2cbe52af808bae860d53dd4e4d691f4674", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-11-08T18:36:23.000Z", "max_stars_repo_stars_event_max_datetime": "2015-11-08T18:36:23.000Z", "max_issues_repo_path": "src/insertion_sort_asc_map_int.f90", "max_issues_repo_name": "arinrb/bsort", "max_issues_repo_head_hexsha": "17cc0e2cbe52af808bae860d53dd4e4d691f4674", "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/insertion_sort_asc_map_int.f90", "max_forks_repo_name": "arinrb/bsort", "max_forks_repo_head_hexsha": "17cc0e2cbe52af808bae860d53dd4e4d691f4674", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.4328358209, "max_line_length": 240, "alphanum_fraction": 0.6389452333, "num_tokens": 574, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324893519999, "lm_q2_score": 0.8459424334245618, "lm_q1q2_score": 0.6896397558491939}} {"text": "! ##################################################################################################################################\n! Begin MIT license text. \n! _______________________________________________________________________________________________________\n \n! Copyright 2019 Dr William R Case, Jr (dbcase29@gmail.com) \n \n! Permission is hereby granted, free of charge, to any person obtaining a copy of this software and \n! associated documentation files (the \"Software\"), to deal in the Software without restriction, including\n! without limitation the rights 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 furnished to do so, subject to \n! the following conditions: \n \n! The above copyright notice and this permission notice shall be included in all copies or substantial \n! portions of the Software and documentation. \n \n! THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS \n! OR 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 \n! THE SOFTWARE. \n! _______________________________________________________________________________________________________\n \n! End MIT license text. \n \n SUBROUTINE PLANE_COORD_TRANS_21 ( THETA, T21, CALLING_SUBR )\n \n! Creates a coordinate transformation matrix for a plane rotation of a vector in coordinate system 1, through an angle THETA, to\n! a vector in coordinate system 2\n\n! | U2 | | cos(THETA) sin(THETA) 0 | | U1 |\n! | V2 | = | -sin(THETA) cos(THETA) 0 | | V1 |\n! | W2 | | 0 0 1 | | W1 |\n \n USE PENTIUM_II_KIND, ONLY : BYTE, LONG, DOUBLE\n USE IOUNT1, ONLY : F04, WRT_LOG\n USE SCONTR, ONLY : BLNK_SUB_NAM\n USE TIMDAT, ONLY : TSEC\n USE CONSTANTS_1, ONLY : ONE, ZERO\n USE SUBR_BEGEND_LEVELS, ONLY : PLANE_COORD_TRANS_21_BEGEND\n \n USE PLANE_COORD_TRANS_21_USE_IFs\n\n IMPLICIT NONE\n \n CHARACTER(LEN=LEN(BLNK_SUB_NAM)):: SUBR_NAME = 'PLANE_COORD_TRANS_21'\n CHARACTER(LEN=*), INTENT(IN) :: CALLING_SUBR ! Subr that called this one\n\n INTEGER(LONG), PARAMETER :: SUBR_BEGEND = PLANE_COORD_TRANS_21_BEGEND\n\n REAL(DOUBLE), INTENT(IN) :: THETA ! Angle from x axis of system 1 to x axis of system 2\n REAL(DOUBLE), INTENT(OUT) :: T21(3,3) ! Transformation matrix which will transform a vector, U1, in coord sys\n! 1 to a vector, U2, in coord sys 2 (i.e. U2 = T21*U1)\n\n INTRINSIC :: DSIN, DCOS\n\n! **********************************************************************************************************************************\n IF (WRT_LOG >= SUBR_BEGEND) THEN\n CALL OURTIM\n WRITE(F04,9001) SUBR_NAME,TSEC\n 9001 FORMAT(1X,A,' BEGN ',F10.3)\n ENDIF\n \n! **********************************************************************************************************************************\n! Row 1\n\n T21(1,1) = DCOS( THETA )\n T21(1,2) = DSIN( THETA )\n T21(1,3) = ZERO\n\n! Row 2\n\n T21(2,1) = -T21(1,2)\n T21(2,2) = T21(1,1)\n T21(2,3) = ZERO\n\n! Row 3\n\n T21(3,1) = ZERO\n T21(3,2) = ZERO\n T21(3,3) = ONE\n\n\n! **********************************************************************************************************************************\n IF (WRT_LOG >= SUBR_BEGEND) THEN\n CALL OURTIM\n WRITE(F04,9002) SUBR_NAME,TSEC\n 9002 FORMAT(1X,A,' END ',F10.3)\n ENDIF\n\n RETURN\n\n! **********************************************************************************************************************************\n\n! **********************************************************************************************************************************\n\n END SUBROUTINE PLANE_COORD_TRANS_21\n", "meta": {"hexsha": "b99f6696cb28184381b0720a1fcf889a4a65ce47", "size": 5520, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Source/UTIL/PLANE_COORD_TRANS_21.f90", "max_stars_repo_name": "JohnDN90/MYSTRAN", "max_stars_repo_head_hexsha": "1dd7dc19e54c1bb2b5235244af65115950e21488", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 43, "max_stars_repo_stars_event_min_datetime": "2020-04-04T15:33:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-23T08:46:05.000Z", "max_issues_repo_path": "Source/UTIL/PLANE_COORD_TRANS_21.f90", "max_issues_repo_name": "JohnDN90/MYSTRAN", "max_issues_repo_head_hexsha": "1dd7dc19e54c1bb2b5235244af65115950e21488", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 15, "max_issues_repo_issues_event_min_datetime": "2020-07-06T21:15:15.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-06T19:54:09.000Z", "max_forks_repo_path": "Source/UTIL/PLANE_COORD_TRANS_21.f90", "max_forks_repo_name": "JohnDN90/MYSTRAN", "max_forks_repo_head_hexsha": "1dd7dc19e54c1bb2b5235244af65115950e21488", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2020-05-28T17:16:44.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-06T18:08:31.000Z", "avg_line_length": 55.7575757576, "max_line_length": 132, "alphanum_fraction": 0.4076086957, "num_tokens": 1026, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872046056466901, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6896240122256971}} {"text": " SUBROUTINE DRANGV(A, NDIM, N, U, X, HAVEC, IERR)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc>> 1996-03-30 DRANGV Krogh Added external statement.\nC>> 1994-11-11 DRANGV Krogh Declared all vars.\nC>> 1994-10-20 DRANGV Krogh Changes to use M77CON\nC>> 1987-04-22 DRANGV Lawson Initial code.\nc--D replaces \"?\": ?RANGV, ?RANG\nc\nc DRANGV generates an N-component random vector, X, from a multi-\nc variate normal distribution having a specified mean vector, U,\nc and covariance matrix, A.\nc ------------------------------------------------------------------\nc Subroutine arguments\nc\nc A(,) [inout] Array with first dimension NDIM, and second\nc dimension at least N. When HAVEC is false, A(,) contains\nc the given N x N symmetric covariance matrix. This\nc subroutine will replace A by its lower-triangular Cholesky\nc factor, C, and set HAVEC = .true.\nc When HAVEC is true A(,) is assumed to contain the Cholesky\nc factor, C.\nc Note: Only the lower triangle of the array A(,) is used by\nc this subroutine.\nc\nc NDIM [in] First dimension of the array A(,).\nc Require NDIM .ge. N.\nc\nc N [in] Order of the covariance matrix A and dimension of the\nc vectors U and X.\nc\nc U() [in] Contains the N-dimensional mean vector.\nc\nc X() [out] On return will contain the N-dimensional generated\nc random vector.\nc\nc HAVEC [inout] See description above for A(,).\nc\nc IERR [out] IERR is only referenced when this subr is entered\nc with HAVEC = false.\nc In that case IERR will be set to zero if the\nc Cholesky factorization is successful. If the factorization\nc is unsuccessful IERR will be set to the index of the row at\nc which failure is detected. In this latter case the results\nc returned in A(,) and X() will not be valid.\nc -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\nc Subprogram referenced: DRANG\nc -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\nc Programmed for JPL by Carl Pitts, Heliodyne Corp., April, 1969.\nc Adapted to Fortran 77 for the JPL MATH 77 library by C. L. Lawson\nc and S. Y. Chiu, JPL, April 1987.\nc ------------------------------------------------------------------\n external DRANG\n integer IERR, NDIM, N, J, K, L\n double precision A(NDIM,N), U(N), X(N), SUM, ZERO\n double precision DRANG\n logical HAVEC\n parameter(ZERO = 0.0D0)\nc ------------------------------------------------------------------\n if(.not. HAVEC) then\nc -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\nc BEGIN PROCEDURE TO CALCULATE C-MATRIX, NOTE THE C-MATRIX\nc overwrites the lower triangle of the A matrix.\nc\n DO 40 J=1,N\n DO 30 K=1,J\n SUM = ZERO\n DO 20 L=1,K-1\n SUM=SUM+A(J,L)*A(K,L)\n 20 CONTINUE\n if(J .ne. K) then\n A(J,K)=(A(J,K)-SUM)/A(K,K)\n else\n SUM=A(K,K)-SUM\n if(SUM .le. ZERO) then\n IERR = K\nc Error return.\n RETURN\n endif\n A(K,K)=SQRT(SUM)\n endif\n 30 continue\n 40 continue\n HAVEC=.TRUE.\n IERR = 0\n endif\nc END PROCEDURE TO CALCULATE C-MATRIX\nc ------------------------------------------------------------------\nc BEGIN PROCEDURE TO CALCULATE RANDOM VECTOR\nc\nc LOOP TO FILL Y-VECTOR WITH NORMALLY DISTRIBUTED RANDOM NUMBERS\nc WITH ZERO MEAN AND UNIT VARIANCE NOTE THE Y-VECTOR IS STORED\nc TEMPORARILY IN THE X-VECTOR\nc\n DO 70 J=1,N\n X(J)= DRANG()\n 70 CONTINUE\nc\nc LOOP TO CALCULATE X-VECTOR\nc\n DO 90 J=N,1,-1\n SUM=U(J)\n DO 80 K=1,J\n SUM=SUM+A(J,K)*X(K)\n 80 CONTINUE\n X(J)=SUM\n 90 CONTINUE\n return\n end\n", "meta": {"hexsha": "2eb9f423811a44f157df02aed905aa1a8f5a217e", "size": 4215, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/drangv.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/drangv.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/drangv.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": 37.972972973, "max_line_length": 72, "alphanum_fraction": 0.5143534994, "num_tokens": 1202, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045847699186, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6896239959981856}} {"text": "! Taken from getstarlist.f90 in ramses/utils/f90\nsubroutine friedmann(O_mat_0,O_vac_0,O_k_0,alpha,axp_min, &\n & axp_out,hexp_out,tau_out,t_out,ntable,age_tot)\n\n implicit none\n integer::ntable\n real(kind=8)::O_mat_0, O_vac_0, O_k_0\n real(kind=8)::alpha,axp_min!,age_tot\n real(kind=8),intent(out)::age_tot\n real(kind=8),dimension(0:ntable),intent(out)::axp_out,hexp_out,tau_out,t_out\n ! ######################################################!\n ! This subroutine assumes that axp = 1 at z = 0 (today) !\n ! and that t and tau = 0 at z = 0 (today). !\n ! axp is the expansion factor, hexp the Hubble constant !\n ! defined as hexp=1/axp*daxp/dtau, tau the conformal !\n ! time, and t the look-back time, both in unit of 1/H0. !\n ! alpha is the required accuracy and axp_min is the !\n ! starting expansion factor of the look-up table. !\n ! ntable is the required size of the look-up table. !\n ! ######################################################!\n real(kind=8)::axp_tau, axp_t\n real(kind=8)::axp_tau_pre, axp_t_pre\n real(kind=8)::dadtau, dadt\n real(kind=8)::dtau,dt\n real(kind=8)::tau,t\n integer::nstep,nout,nskip\n\n!!$ if( (O_mat_0+O_vac_0+O_k_0) .ne. 1.0D0 )then\n!!$ write(*,*)'Error: non-physical cosmological constants'\n!!$ write(*,*)'O_mat_0,O_vac_0,O_k_0=',O_mat_0,O_vac_0,O_k_0\n!!$ write(*,*)'The sum must be equal to 1.0, but '\n!!$ write(*,*)'O_mat_0+O_vac_0+O_k_0=',O_mat_0+O_vac_0+O_k_0\n!!$ stop\n!!$ end if\n\n axp_tau = 1.0D0\n axp_t = 1.0D0\n tau = 0.0D0\n t = 0.0D0\n nstep = 0\n\n ! Uncomment below for debugging\n !print*, 'Cosmology: ', O_mat_0, O_vac_0, O_k_0\n !print*, 'Params: ', alpha,axp_min\n \n do while ( (axp_tau .ge. axp_min) .or. (axp_t .ge. axp_min) ) \n \n nstep = nstep + 1\n dtau = alpha * axp_tau / dadtau(axp_tau,O_mat_0,O_vac_0,O_k_0)\n axp_tau_pre = axp_tau - dadtau(axp_tau,O_mat_0,O_vac_0,O_k_0)*dtau/2.d0\n axp_tau = axp_tau - dadtau(axp_tau_pre,O_mat_0,O_vac_0,O_k_0)*dtau\n tau = tau - dtau\n \n dt = alpha * axp_t / dadt(axp_t,O_mat_0,O_vac_0,O_k_0)\n axp_t_pre = axp_t - dadt(axp_t,O_mat_0,O_vac_0,O_k_0)*dt/2.d0\n axp_t = axp_t - dadt(axp_t_pre,O_mat_0,O_vac_0,O_k_0)*dt\n t = t - dt\n \n end do\n\n age_tot=-t\n !write(*,666)-t\n 666 format(' Age of the Universe (in unit of 1/H0)=',1pe10.3)\n\n nskip=nstep/ntable\n \n axp_t = 1.d0\n t = 0.d0\n axp_tau = 1.d0\n tau = 0.d0\n nstep = 0\n nout=0\n t_out(nout)=t\n tau_out(nout)=tau\n axp_out(nout)=axp_tau\n hexp_out(nout)=dadtau(axp_tau,O_mat_0,O_vac_0,O_k_0)/axp_tau\n\n do while ( (axp_tau .ge. axp_min) .or. (axp_t .ge. axp_min) ) \n \n nstep = nstep + 1\n dtau = alpha * axp_tau / dadtau(axp_tau,O_mat_0,O_vac_0,O_k_0)\n axp_tau_pre = axp_tau - dadtau(axp_tau,O_mat_0,O_vac_0,O_k_0)*dtau/2.d0\n axp_tau = axp_tau - dadtau(axp_tau_pre,O_mat_0,O_vac_0,O_k_0)*dtau\n tau = tau - dtau\n\n dt = alpha * axp_t / dadt(axp_t,O_mat_0,O_vac_0,O_k_0)\n axp_t_pre = axp_t - dadt(axp_t,O_mat_0,O_vac_0,O_k_0)*dt/2.d0\n axp_t = axp_t - dadt(axp_t_pre,O_mat_0,O_vac_0,O_k_0)*dt\n t = t - dt\n \n if(mod(nstep,nskip)==0)then\n nout=nout+1\n t_out(nout)=t\n tau_out(nout)=tau\n axp_out(nout)=axp_tau\n hexp_out(nout)=dadtau(axp_tau,O_mat_0,O_vac_0,O_k_0)/axp_tau\n end if\n\n end do\n t_out(ntable)=t\n tau_out(ntable)=tau\n axp_out(ntable)=axp_tau\n hexp_out(ntable)=dadtau(axp_tau,O_mat_0,O_vac_0,O_k_0)/axp_tau\n\nend subroutine friedmann\n\nfunction dadtau(axp_tau,O_mat_0,O_vac_0,O_k_0) \n real(kind=8)::dadtau,axp_tau,O_mat_0,O_vac_0,O_k_0\n dadtau = axp_tau*axp_tau*axp_tau * &\n & ( O_mat_0 + &\n & O_vac_0 * axp_tau*axp_tau*axp_tau + &\n & O_k_0 * axp_tau )\n dadtau = sqrt(dadtau)\n return\nend function dadtau\n\nfunction dadt(axp_t,O_mat_0,O_vac_0,O_k_0)\n real(kind=8)::dadt,axp_t,O_mat_0,O_vac_0,O_k_0\n dadt = (1.0D0/axp_t)* &\n & ( O_mat_0 + &\n & O_vac_0 * axp_t*axp_t*axp_t + &\n & O_k_0 * axp_t )\n dadt = sqrt(dadt)\n return\nend function dadt\n", "meta": {"hexsha": "4571a852b9cd21748f4dace6fe8590c495053448", "size": 4065, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "utils/f90/friedmann.f90", "max_stars_repo_name": "lconaboy/seren3", "max_stars_repo_head_hexsha": "5a2ec80adf0d69664d2ee874f5ba12cc02d6c337", "max_stars_repo_licenses": ["CNRI-Python"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-09-21T14:58:23.000Z", "max_stars_repo_stars_event_max_datetime": "2017-09-21T14:58:23.000Z", "max_issues_repo_path": "utils/f90/friedmann.f90", "max_issues_repo_name": "lconaboy/seren3", "max_issues_repo_head_hexsha": "5a2ec80adf0d69664d2ee874f5ba12cc02d6c337", "max_issues_repo_licenses": ["CNRI-Python"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-09-09T08:52:43.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-09T08:52:43.000Z", "max_forks_repo_path": "utils/f90/friedmann.f90", "max_forks_repo_name": "lconaboy/seren3", "max_forks_repo_head_hexsha": "5a2ec80adf0d69664d2ee874f5ba12cc02d6c337", "max_forks_repo_licenses": ["CNRI-Python"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-01-21T10:57:41.000Z", "max_forks_repo_forks_event_max_datetime": "2019-01-21T10:57:41.000Z", "avg_line_length": 32.2619047619, "max_line_length": 78, "alphanum_fraction": 0.6300123001, "num_tokens": 1685, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473779969194, "lm_q2_score": 0.7905303285397349, "lm_q1q2_score": 0.689617059328681}} {"text": "\nprogram fizzbuzz\n! print *, 'Hello, World!'\ndo i = 1 , 1000\n if (mod(i, 15) == 0) then\n print '(A)', 'FizzBuzz'\n elseif (mod(i, 3) == 0) then\n print '(A)', 'Fizz'\n elseif (mod(i, 5) == 0) then\n print '(A)', 'Buzz'\n else\n print '(I0)', i;\n end if\nend do\nend program fizzbuzz\n\n", "meta": {"hexsha": "c9bbdec9bfd81ebcf7d232ac83176f01cf97e35a", "size": 293, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/fizzbuzz.f90", "max_stars_repo_name": "YusukeSuzuki/FizzBuzzes", "max_stars_repo_head_hexsha": "a2b14e52b34a8ef11f3127aa7693b152d2fb2371", "max_stars_repo_licenses": ["MIT"], "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/fizzbuzz.f90", "max_issues_repo_name": "YusukeSuzuki/FizzBuzzes", "max_issues_repo_head_hexsha": "a2b14e52b34a8ef11f3127aa7693b152d2fb2371", "max_issues_repo_licenses": ["MIT"], "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/fizzbuzz.f90", "max_forks_repo_name": "YusukeSuzuki/FizzBuzzes", "max_forks_repo_head_hexsha": "a2b14e52b34a8ef11f3127aa7693b152d2fb2371", "max_forks_repo_licenses": ["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.2352941176, "max_line_length": 30, "alphanum_fraction": 0.5358361775, "num_tokens": 116, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.7905303211371898, "lm_q1q2_score": 0.6896170450004672}} {"text": "program weather_stats_parallel\n\n use mod_arrays, only: denan, mean\n use mod_io, only: read_buoy\n use mod_parallel, only: tile_indices\n\n implicit none\n\n character(len=5), allocatable :: ids(:)\n character(len=20), allocatable :: time(:)\n real, allocatable :: wind_speed(:)\n real, allocatable :: max_wind(:), mean_wind(:)\n real, allocatable :: gather(:)[:]\n integer :: is, ie, indices(2)\n integer :: i\n\n real :: min_mean_wind, max_mean_wind, max_max_wind\n\n ids = ['42001', '42002', '42003', '42020', '42035',&\n '42036', '42039', '42040', '42055']\n\n if (num_images() > size(ids)) error stop 'Error: Too many images'\n\n indices = tile_indices(size(ids))\n is = indices(1)\n ie = indices(2)\n\n allocate(max_wind(is:ie), mean_wind(is:ie))\n\n do i = is, ie\n call read_buoy('data/buoy_' // ids(i) // '.csv', time, wind_speed)\n wind_speed = denan(wind_speed)\n max_wind(i) = maxval(wind_speed)\n mean_wind(i) = mean(wind_speed)\n end do\n\n allocate(gather(size(ids))[*])\n\n gather(is:ie)[1] = max_wind \n sync all \n if (this_image() == 1) then\n write(*,*) 'Maximum wind speed measured is ', maxval(gather),&\n 'at station ', ids(maxloc(gather))\n end if\n\n gather(is:ie)[1] = mean_wind\n sync all\n if (this_image() == 1) then\n write(*,*) 'Highest mean wind speed is ', maxval(gather),&\n 'at station ', ids(maxloc(gather))\n write(*,*) 'Lowest mean wind speed is ', minval(gather),&\n 'at station ', ids(minloc(gather))\n end if\n\nend program weather_stats_parallel\n", "meta": {"hexsha": "d4ceaf07c5fd96fbf2ec63f94337d2b84c304f59", "size": 1505, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/weather_stats_parallel.f90", "max_stars_repo_name": "scivision/weather-buoys", "max_stars_repo_head_hexsha": "bf6606b73c9fac26ba57950c8395b84f79c12be3", "max_stars_repo_licenses": ["MIT"], "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/weather_stats_parallel.f90", "max_issues_repo_name": "scivision/weather-buoys", "max_issues_repo_head_hexsha": "bf6606b73c9fac26ba57950c8395b84f79c12be3", "max_issues_repo_licenses": ["MIT"], "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/weather_stats_parallel.f90", "max_forks_repo_name": "scivision/weather-buoys", "max_forks_repo_head_hexsha": "bf6606b73c9fac26ba57950c8395b84f79c12be3", "max_forks_repo_licenses": ["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.875, "max_line_length": 71, "alphanum_fraction": 0.6425249169, "num_tokens": 466, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.7905303137346446, "lm_q1q2_score": 0.6896170437899584}} {"text": "! Evaluate function of one variable X\r\nDOUBLE PRECISION FUNCTION EVALFUNC1(X)\r\n IMPLICIT NONE\r\n !\r\n REAL(8) R1 /1.0D0/\r\n REAL(8) R2 /2.0D0/\r\n REAL(8) R3 /3.0D0/\r\n !\r\n REAL(8) :: X\r\n !\r\n EVALFUNC1=R1-R3*X+EXP(R2*X)\r\n RETURN\r\nEND FUNCTION", "meta": {"hexsha": "ad373b76c58f443328cb4cc3bce3ed99a79dc6eb", "size": 266, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/evalfunc1.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/evalfunc1.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/evalfunc1.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": 20.4615384615, "max_line_length": 39, "alphanum_fraction": 0.5676691729, "num_tokens": 101, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.6896170428479369}} {"text": "*DECK POLINT\n SUBROUTINE POLINT (N, X, Y, C)\nC***BEGIN PROLOGUE POLINT\nC***PURPOSE Produce the polynomial which interpolates a set of discrete\nC data points.\nC***LIBRARY SLATEC\nC***CATEGORY E1B\nC***TYPE SINGLE PRECISION (POLINT-S, DPLINT-D)\nC***KEYWORDS POLYNOMIAL INTERPOLATION\nC***AUTHOR Huddleston, R. E., (SNLL)\nC***DESCRIPTION\nC\nC Written by Robert E. Huddleston, Sandia Laboratories, Livermore\nC\nC Abstract\nC Subroutine POLINT is designed to produce the polynomial which\nC interpolates the data (X(I),Y(I)), I=1,...,N. POLINT sets up\nC information in the array C which can be used by subroutine POLYVL\nC to evaluate the polynomial and its derivatives and by subroutine\nC POLCOF to produce the coefficients.\nC\nC Formal Parameters\nC N - the number of data points (N .GE. 1)\nC X - the array of abscissas (all of which must be distinct)\nC Y - the array of ordinates\nC C - an array of information used by subroutines\nC ******* Dimensioning Information *******\nC Arrays X,Y, and C must be dimensioned at least N in the calling\nC program.\nC\nC***REFERENCES L. F. Shampine, S. M. Davenport and R. E. Huddleston,\nC Curve fitting by polynomials in one variable, Report\nC SLA-74-0270, Sandia Laboratories, June 1974.\nC***ROUTINES CALLED XERMSG\nC***REVISION HISTORY (YYMMDD)\nC 740601 DATE WRITTEN\nC 861211 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE POLINT\n DIMENSION X(*),Y(*),C(*)\nC***FIRST EXECUTABLE STATEMENT POLINT\n IF (N .LE. 0) GO TO 91\n C(1)=Y(1)\n IF(N .EQ. 1) RETURN\n DO 10010 K=2,N\n C(K)=Y(K)\n KM1=K-1\n DO 10010 I=1,KM1\nC CHECK FOR DISTINCT X VALUES\n DIF = X(I)-X(K)\n IF (DIF .EQ. 0.0) GO TO 92\n C(K) = (C(I)-C(K))/DIF\n10010 CONTINUE\n RETURN\n! 91 CALL XERMSG ('SLATEC', 'POLINT', 'N IS ZERO OR NEGATIVE.', 2, 1)\n 91 RETURN\n! 92 CALL XERMSG ('SLATEC', 'POLINT',\n ! + 'THE ABSCISSAS ARE NOT DISTINCT.', 2, 1)\n 92 RETURN\n END\n\n", "meta": {"hexsha": "f34cb9611f607977e3c05b44025dff1c0acba51e", "size": 2236, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "polint.f", "max_stars_repo_name": "HerculesJack/grtrans", "max_stars_repo_head_hexsha": "bc005307d81dac1bdb9520e776e7627126dd690a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2016-02-11T01:52:14.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-16T02:15:42.000Z", "max_issues_repo_path": "polint.f", "max_issues_repo_name": "RAnantua/grtrans", "max_issues_repo_head_hexsha": "a0353a8516335412b27fe4866eabafcfc0fe498f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2016-11-10T15:25:20.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-18T15:15:57.000Z", "max_forks_repo_path": "polint.f", "max_forks_repo_name": "RAnantua/grtrans", "max_forks_repo_head_hexsha": "a0353a8516335412b27fe4866eabafcfc0fe498f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2016-02-11T14:13:01.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-10T01:56:02.000Z", "avg_line_length": 34.9375, "max_line_length": 72, "alphanum_fraction": 0.6435599284, "num_tokens": 752, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782092, "lm_q2_score": 0.7905303112671295, "lm_q1q2_score": 0.689617041637428}} {"text": "MODULE loss_during_routines\n\n implicit none\n\n private\n \n public tridag, GMRES, DDOTL, DAXPYL, ope\n \n contains \n \n SUBROUTINE tridag(a,b,c,r,u,n)\n IMPLICIT NONE\n integer, intent(in) :: n\n real a(n),b(n),c(n),r(n),u(n)\n real :: gam(N)\n integer :: j\n real :: bet\n! if(b(1).eq.0.)pause 'tridag: rewrite equations'\n bet=b(1)\n u(1)=r(1)/bet\n do j=2,n\n gam(j)=c(j-1)/bet\n bet=b(j)-a(j)*gam(j)\n if(bet.eq.0.)pause 'tridag failed'\n u(j)=(r(j)-a(j)*u(j-1))/bet\n end do\n do j=n-1,1,-1\n u(j)=u(j)-gam(j+1)*u(j+1)\n end do\n return\n END SUBROUTINE tridag\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n SUBROUTINE GMRES (N, IM, RHS, SOL, SS, EPS, MAXITS, IOUT, &\n c1,c2,c3)\n\n!C*************************************************************\n!c\n!c This is gmrd.f (double precision), the original Saad version\n!c of GMRES, with trivial changes in output format.\n!c\n!C GMRES ALGORITHM . SIMPLE VERSION . (MAY 23, 1985)\n!C PARAMETER LIST:\n!C N == SIZE OF PROBLEM\n!C IM == SIZE OF KRYLOV SUBSPACE: SHOULD NOT EXCEED 50 IN THIS\n!C VERSION (CAN BE RESET IN CODE. LOOKING AT COMMENT BELOW)\n!C RHS == RIGHT HAND SIDE\n!C SOL == INITIAL GUESS ON INPUT, APPROXIMATE SOLUTION ON OUTPUT\n!C SS == WORK SPACE OF SIZE N X (IM+1)\n!C EPS == TOLERANCE FOR STOPPING CRITERION. PROCESS IS STOPPED\n!C AS SOON AS ( ||.|| IS THE EUCLIDEAN NORM):\n!C || CURRENT RESIDUAL||/||INITIAL RESIDUAL|| <= EPS\n!C ON OUTPUT, EPS = ::FINAL RESIDUAL::/::INITIAL RESIDUAL::\n!C MAXITS== MAXIMUM NUMBER OF ITERATIONS ALLOWED ON INPUT\n!C ON OUTPUT, MAXITS = TOTAL NUMBER OF ITERATIONS\n!C IOUT == OUTPUT UNIT NUMBER NUMBER FOR PRINTING INTERMEDIATE RESULTS\n!C IF (IOUT .LE. 0) NO STATISTICS ARE PRINTED.\n!C ----------------------------------------------------------------\n!C SUBROUTINES USED =\n!C OPE(N,X,Y) == MATRIX BY VECTOR MULTIPLICATION DELIVERS Y=AX, GIVEN X.\n!C DDOTL == DOT PRODUCT FUNCTION. REPLACE BY BLAS ROUTINE DDOT\n!C DAXPYL == Y <-- Y+AX ROUTINE. REPLACE BY BLAS ROUTINE DAXPY\n!C*************************************************************\n!c IMPLICIT REAL*8 (A-H,O-Z)\n implicit none\n integer, intent (in) :: n, im, maxits, iout\n real, intent(in) :: c1(n),c2(n),c3(n)\n integer i, j, k, k1, ii, i1, n1, its\n REAL SS(N,IM+1), RHS(N), SOL(N)\n real HH(51,50), C(50), S(50), RS(51)\n real eps, eps1, gam, mcheps, ro, t\n\n!C-------------------------------------------------------------\n!C ARNOLDI SIZE SHOULD NOT EXCEED 50 IN THIS VERSION..\n!C TO RESET MODIFY SIZES OF HH, C, S, RS ----------------\n!C-------------------------------------------------------------\n mcheps = 1.d-30\n N1 = N + 1\n ITS = 0\n!C-------------------------------------------------------------\n!C ** OUTER LOOP STARTS HERE..\n!C-------------- COMPUTE INITIAL RESIDUAL VECTOR --------------\n 10 CONTINUE\n CALL ope (N, SOL, SS,c1,c2,c3)\n\n DO J=1,N\n SS(J,1) = RHS(J) - SS(J,1)\n ENDDO\n\n!C-------------------------------------------------------------\n\n RO = SQRT( DDOTL(N, SS,SS) )\n IF (RO .EQ. 0.0D0) RETURN\n DO J=1, N\n SS(J,1) = SS(J,1)/RO\n ENDDO\n IF (ITS .EQ. 0) EPS1=EPS*RO\n\n!C ** INITIALIZE 1-ST TERM OF RHS OF HESSENBERG SYSTEM..\n RS(1) = RO\n I = 0\n 4 I=I+1\n ITS = ITS + 1\n I1 = I + 1\n CALL ope (N, SS(1,I), SS(1,I1),c1,c2,c3)\n\n!C-----------------------------------------\n!C MODIFIED GRAM - SCHMIDT...\n!C-----------------------------------------\n DO J=1, I\n T = DDOTL(N, SS(1,J),SS(1,I1))\n HH(J,I) = T\n CALL DAXPYL(N, -T, SS(1,J), SS(1,I1))\n ENDDO\n T = SQRT(DDOTL(N, SS(1,I1), SS(1,I1)))\n HH(I1,I) = T\n DO K=1,N\n SS(K,I1) = SS(K,I1) / T\n ENDDO\n\n!C--------DONE WITH MODIFIED GRAM SCHIMD AND ARNOLDI STEP..\n!C NOW UPDATE FACTORIZATION OF HH\n!C---------------------------------------------------------\n IF (I .EQ. 1) GOTO 121\n!C-------- PERFROM PREVIOUS TRANSFORMATIONS ON I-TH COLUMN OF H\n DO K=2,I\n K1 = K-1\n T = HH(K1,I)\n HH(K1,I) = C(K1)*T + S(K1)*HH(K,I)\n HH(K,I) = -S(K1)*T + C(K1)*HH(K,I)\n ENDDO\n 121 GAM = SQRT(HH(I,I)**2 + HH(I1,I)**2)\n IF (GAM .EQ. 0.0D0) GAM = MCHEPS\n!C-----------# DETERMINE NEXT PLANE ROTATION #-------------------\n C(I) = HH(I,I)/GAM\n S(I) = HH(I1,I)/GAM\n RS(I1) = -S(I)*RS(I)\n RS(I) = C(I)*RS(I)\n!C---DETERMINE RESIDUAL NORM AND TEST FOR CONVERGENCE-\n HH(I,I) = C(I)*HH(I,I) + S(I)*HH(I1,I)\n RO = ABS(RS(I1))\n!c IF (IOUT .GT. 0)\n!c * WRITE(IOUT, 199) ITS, RO\n IF ( (I .LT. IM) .AND. (RO .GT. EPS1) .and. &\n (its .lt. maxits) ) GOTO 4\n!C\n!C NOW COMPUTE SOLUTION. FIRST SOLVE UPPER TRIANGULAR SYSTEM.\n!C\n RS(I) = RS(I)/HH(I,I)\n DO II=2,I\n K=I-II+1\n K1 = K+1\n T=RS(K)\n DO J=K1,I\n T = T-HH(K,J)*RS(J)\n ENDDO\n RS(K) = T/HH(K,K)\n ENDDO\n!C DONE WITH BACK SUBSTITUTION..\n!C NOW FORM LINEAR COMBINATION TO GET SOLUTION\n DO J=1, I\n T = RS(J)\n CALL DAXPYL(N, T, SS(1,J), SOL)\n ENDDO\n!C RESTART OUTER LOOP WHEN NECESSARY\n IF (RO .GT. EPS1 .AND. ITS .LT. MAXITS) GOTO 10\n 199 format(1x, i5, 3x, 1pe12.4 )\n EPS = (RO / EPS1) * EPS\n!crdk MAXITS = ITS\n!cjcm\n!crdk WRITE(IOUT, 199) ITS, RO\n!cjcm\n RETURN\n!C------------------------------- END OF GMRES ----------------------\n END SUBROUTINE GMRES\n\n!C------------------------------- BEG OF DDOTL ----------------------\n FUNCTION DDOTL(N,RVA,RVB)\n IMPLICIT NONE\n INTEGER I,N\n REAL RVA(N),RVB(N),DDOTL\n DDOTL = 0.0\n DO I=1,N\n DDOTL=DDOTL+RVA(I)*RVB(I)\n ENDDO\n RETURN\n END FUNCTION DDOTL\n!C------------------------------- END OF DDOTL ----------------------\n!C------------------------------- BEG OF DAXPYL ----------------------\n SUBROUTINE DAXPYL(N,ALPHA,X,Y)\n IMPLICIT NONE\n INTEGER I,N\n REAL X(N),Y(N),ALPHA\n DO I=1,N\n Y(I)=Y(I)+ALPHA*X(I)\n ENDDO \n RETURN\n END SUBROUTINE DAXPYL\n\n!C------------------------------- END OF DAXPYL ----------------------\n\n subroutine ope(n,sol,ss,c1,c2,c3)\n \n IMPLICIT NONE\n integer, intent(in) :: n\n real, intent (out) :: ss(n)\n real,intent(in) :: c1(n),c2(n),c3(n),sol(n)\n integer :: nx\n \n do nx=2,n-1\n ss(nx)=c1(nx)*sol(nx+1)+c2(nx)*sol(nx)+c3(nx)*sol(nx-1)\n enddo\n \n ss(1)=c1(1)*sol(2)+c2(1)*sol(1)\n ss(n)=c2(n)*sol(n)+c3(n)*sol(n-1)\n \n return\n end subroutine ope\n\n END MODULE loss_during_routines\n", "meta": {"hexsha": "aae4c385ba85bd9c0e5e1310a246f45f212debea", "size": 6944, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/Raster/m_loss_during_routines.f90", "max_stars_repo_name": "GEOS-ESM/GEOSgcm_GridComp", "max_stars_repo_head_hexsha": "e7ef8edc70e6251f7d6a6992e78fe595a0b8b645", "max_stars_repo_licenses": ["NASA-1.3", "ECL-2.0", "Apache-2.0"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2019-08-09T18:16:55.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-30T02:27:47.000Z", "max_issues_repo_path": "GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/Raster/m_loss_during_routines.f90", "max_issues_repo_name": "GEOS-ESM/GEOSgcm_GridComp", "max_issues_repo_head_hexsha": "e7ef8edc70e6251f7d6a6992e78fe595a0b8b645", "max_issues_repo_licenses": ["NASA-1.3", "ECL-2.0", "Apache-2.0"], "max_issues_count": 314, "max_issues_repo_issues_event_min_datetime": "2019-07-05T15:00:13.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T18:08:03.000Z", "max_forks_repo_path": "GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/Utils/Raster/m_loss_during_routines.f90", "max_forks_repo_name": "GEOS-ESM/GEOSgcm_GridComp", "max_forks_repo_head_hexsha": "e7ef8edc70e6251f7d6a6992e78fe595a0b8b645", "max_forks_repo_licenses": ["NASA-1.3", "ECL-2.0", "Apache-2.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2019-07-19T19:46:56.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-27T04:36:44.000Z", "avg_line_length": 31.2792792793, "max_line_length": 74, "alphanum_fraction": 0.4501728111, "num_tokens": 2308, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436395, "lm_q2_score": 0.774583389368527, "lm_q1q2_score": 0.6896071237141539}} {"text": "module grdtest\n!$$$ module documentation block\n! . . . .\n! module: grdtest\n! prgmmr: todling\n!\n! abstract: Routines and data to perform gradient test\n!\n! program history log:\n! 2009-01-18 todling\n! 2010-02-19 treadon - wrap module\n!\n! subroutines included:\n! sub grtest\n!\n! variable definition:\n!\n! attributes:\n! language: f90\n! machine:\n!\n!$$$ end documentation block\n\nimplicit none\nprivate\npublic grtest\n\ncontains\n\nsubroutine grtest(pdx,itertest,xhat_in)\n!$$$ subprogram documentation block\n! . . . .\n! subprogram: grtest\n! prggmr: todling\n!\n! abstract: The aim is to characterize mathematically the cost-function J on a\n! line in the KDIM-dimensional space defined by point X and direction H.\n! Arbitrarily H is defined by -gradJ(X), the useful direction for\n! minimization. Let us denote by f the real function f(a)=J(X+a.H). A\n! sequence of characteristic quantities are computed and displayed for\n! various values of a :\n! a=PDX, PDX*10, PDX*100 ... PDX*10**itertest\n! The sequence is prematuraly terminated if f(a)-f(0) changes of sign,\n! which normally indicates we are overshooting the minimum of f (assuming\n! J is convex and H points downwards the slope of J). The characteristic\n! quantities TC0,T1,TC1,T2... test increasingly high orders of regularity.\n! Refer to the comments below for the explanation of each quantity.\n! Owing to numerical truncation errors, the tests normally fail for very \n! small perturbations. The maximum quality of the test results, even for a\n! bug-free simulator, is limited to a few digits, depending on the machine.\n!\n! program history log:\n! 2009-01-18 todling - some quad precision changes (incomplete)\n! 2010-05-05 treadon - use r_kind constant in huge()\n! 2010-08-19 lueken - add only to module use\n!\n! input argument list:\n! xhat\n! pdx\n! itertest\n!\n! output argument list:\n!\n! attributes:\n! language: f90\n! machine:\n!\n!$$$ end documentation block\n\nuse kinds, only: i_kind, r_kind, r_quad\nuse constants, only: zero,zero_quad, one_quad\nuse mpimod, only: mype\nuse control_vectors, only: control_vector,allocate_cv, &\n random_cv,deallocate_cv,dot_product,assignment(=)\n\nimplicit none\n\nreal(r_quad) , intent(in ) :: pdx \ninteger(i_kind) , intent(in ) :: itertest \ntype(control_vector), optional, intent(in ) :: xhat_in\n\n! Local variables\nreal(r_quad), parameter :: half_quad=0.5_r_quad\nreal(r_quad), parameter :: two_quad=2.0_r_quad\ntype(control_vector) :: xdir,yhat,grad,xhat\nreal(r_quad) :: zabuf(itertest),zfabuf(itertest),ztf2buf(itertest)\nreal(r_quad) :: zfy,zf0,zdf0,za,zfa,zdfa\nreal(r_quad) :: ZT1,ZB,ZFB,ztco,ZTC1,ZT2,ZTC1A,ZTC2,ZTF2\nreal(r_quad) :: ZTF2L\nreal(r_quad) :: ZTC00,ZTC02,ZTC10,ZTC12\nreal(r_quad) :: ZERMIN,ZT1TST,ZREF\ninteger(i_kind) :: ibest,idig,jj,nprt,ii\nlogical :: lsavinc\n\n!-----------------------------------------------------------------------------\n\nif (mype==0) write(6,*)'grtest: starting'\nif (pdx<=EPSILON(pdx)) then\n if (mype==0) write(6,*)'grtest, pdx=',pdx\n write(6,*)'grtest: pdx too small',pdx\n call stop2(131)\nendif\nlsavinc=.false.\nnprt=1\n\ncall allocate_cv(xdir)\ncall allocate_cv(yhat)\ncall allocate_cv(grad)\ncall allocate_cv(xhat)\n\n! 1.0 Initial point\n! -------------\n\nif (present(xhat_in)) then\n xhat=xhat_in\n if (mype==0) write(6,*)'grtest: use input xhat'\nelse\n call random_cv(xhat)\n if (mype==0) write(6,*)'grtest: use random_cv(xhat)'\nendif\nyhat=xhat\ncall evaljgrad(yhat,zfy,grad,lsavinc,nprt,'grtest')\nzfy=half_quad*zfy\n\n! 1.1 Define perturbation direction ZH\n\nif (mype==0) write(6,*) 'The test direction is the opposite of the gradient'\ndo ii=1,xdir%lencv\n xdir%values(ii)=-grad%values(ii)\nend do\n\n! 1.2 Set function f value and derivative at origin\n\nzf0=zfy\nzdf0=dot_product(grad,xdir,r_quad)\nif (mype==0) write(6,*)'grtest: F(0)=',zf0,' DF(0)=',zdf0\n\nIF (ZDF0>zero_quad.and.mype==0) write(6,*) 'GRTEST Warning, DF should be negative'\nIF (ABS(ZDF0) < SQRT(EPSILON(ZDF0))) THEN\n if (mype==0) write(6,*) 'GRTEST WARNING, DERIVATIVE IS TOO SMALL'\nENDIF\n\n! 2. Loop on test point\n! ------------------\nztf2buf(1)=zero_quad\nDO jj=1,itertest\n\n za=pdx*(10.0_r_quad**(jj-1))\n\n if (mype==0) write(6,*)'grtest iter=',jj,' alpha=',za\n\n! 2.1 Compute f and df at new point y=x+a.h\n\n do ii=1,yhat%lencv\n yhat%values(ii) = xhat%values(ii) + za * xdir%values(ii)\n end do\n\n call evaljgrad(yhat,zfy,grad,lsavinc,nprt,'grtest')\n zfy=half_quad*zfy\n\n zfa=zfy\n zdfa=dot_product(grad,xdir,r_quad)\n\n if (mype==0) write(6,*)'grtest: alpha=',za,' F(a)=',zfa,' DF(a)=',zdfa\n\n zabuf(jj)=za\n zfabuf(jj)=zfa\n\n! 2.2 Quantity TC0=f(a)/f(0)-1\n\n! if f is continuous then TC0->1 at origin,\n! at least linearly with a.\n\n IF (ABS(zf0)<=TINY(zf0)) THEN\n! do not compute T1 in this unlikely case\n if (mype==0) write(6,*) 'grtest: Warning: zf0 is suspiciously small.'\n if (mype==0) write(6,*) 'grtest: F(a)-F(0)=',zfa-zf0\n ELSE\n ztco=zfa/zf0-one_quad\n if (mype==0) write(6,*)'grtest: continuity TC0=',ztco\n ENDIF\n\n! f(a)-f(0)\n! 2.3 Quantity T1=-----------\n! a.df(0)\n\n! if df is the gradient then T1->1 at origin,\n! linearly with a. T1 is undefined if df(0)=0.\n IF (ABS(za*zdf0)<=SQRT(TINY(zf0))) THEN\n if (mype==0) write(6,*)'grtest: Warning: could not compute ',&\n & 'gradient test T1, a.df(0)=',za*zdf0 \n ELSE\n zt1=(zfa-zf0)/(za*zdf0)\n if (mype==0) write(6,*)'grtest: gradient T1=',zt1\n ENDIF\n\n! 2.4 Quantity TC1=( f(a)-f(0)-a.df(0) )/a\n\n! if df is the gradient and df is continuous,\n! then TC1->0 linearly with a.\n ZTC1=(ZFA-ZF0-ZA*ZDF0)/ZA\n if (mype==0) write(6,*)'grtest: grad continuity TC1=',ZTC1\n\n! 2.5 Quantity T2=( f(a)-f(0)-a.df(0) )*2/a**2\n\n! if d2f exists then T2 -> d2f(0) linearly with a.\n ZT2=(ZFA-ZF0-ZA*ZDF0)*two_quad/(ZA**2)\n if (mype==0) write(6,*)'grtest: second derivative T2=',ZT2\n\n! 2.6 Quantity TC1A=df(a)-df(0)\n\n! if df is the gradient in a and df is continuous,\n! then TC1A->0 linearly with a.\n ZTC1A=ZDFA-ZDF0\n if (mype==0) write(6,*)'grtest: a-grad continuity TC1A=',ZTC1A\n\n! 2.7 Quantity TC2=( 2(f(0)-f(a))+ a(df(0)+df(a))/a**2\n\n! if f is exactly quadratic, then TC2=0, always: numerically\n! it has to -> 0 when a is BIG. Otherwise TC2->0 linearly for\n! small a is trivially implied by TC1A and T2.\n ZTC2=(two_quad*(ZF0-ZFA)+ZA*(ZDF0+ZDFA))/(ZA**2)\n if (mype==0) write(6,*)'grtest: quadraticity TC2=',ZTC2\n\n! 2 f(0)-f(b) f(a)-f(b)\n! 2.8 Quantity TF2=---( --------- + --------- )\n! a b a-b\n! if 0, a and b are distinct and f is quadratic then\n! TF2=d2f, always. The estimate is most stable when a,b are big.\n! This test works only after two loops, but it is immune against\n! gradient bugs. \n IF (jj>=2) THEN\n ZB =ZABUF (jj-1)\n ZFB=ZFABUF(jj-1)\n ZTF2=two_quad/ZA*((ZF0-ZFB)/ZB+(ZFA-ZFB)/(ZA-ZB))\n if (mype==0) write(6,*)'grtest: convexity ZTF2=',ZTF2\n ztf2buf(jj)=ztf2\n ENDIF\n\n! End loop\nENDDO\n\ncall deallocate_cv(xdir)\ncall deallocate_cv(yhat)\ncall deallocate_cv(grad)\ncall deallocate_cv(xhat)\n\n! 3. Comment on the results\n\n! TC0(0)/TC0(2)<.011 -> df looks continuous\n! item with (T1<1 and 1-T1 is min) = best grad test item\n! reldif(TF2(last),TF2(last-1)) = precision on quadraticity\n\n! 3.1 Fundamental checks\n\nif (mype==0) then\n write(6,*) 'GRTEST: TENTATIVE CONCLUSIONS :'\n\n ZTC00=ABS(zfabuf(1)-zf0)\n ZTC02=ABS(zfabuf(3)-zf0)\n IF( ZTC00/zabuf(1) <= 1.5_r_quad*(ZTC02/zabuf(3)) )THEN\n write(6,*) 'GRTEST: function f looks continous.'\n ELSE\n write(6,*) 'GRTEST: WARNING f does not look continuous',&\n & ' (perhaps truncation problem)' \n ENDIF\n\n! 3.2 Gradient quality\n\n IF (ABS(zdf0)<=SQRT(TINY(zf0))) THEN\n write(6,*) 'GRTEST: The gradient is 0, which is unusual !'\n ZTC10=ABS(zfabuf(1)-zf0)\n ZTC12=ABS(zfabuf(3)-zf0)\n IF( ZTC10/zabuf(1)**2 <= 1.1_r_quad*ZTC12/zabuf(3)**2)THEN\n write(6,*)'GRTEST: The gradient looks good anyway.'\n ENDIF\n ELSE\n! Find best gradient test index\n ZERMIN=HUGE(zero)\n ibest=-1\n DO jj=1,itertest\n ZT1TST=(zfabuf(jj)-zf0)/(zabuf(jj)*zdf0)\n ZT1TST=ABS(ZT1TST-one_quad)\n IF (ZT1TST>\nMODULE LIB_Norm\n!!## PURPOSE\n!! Puts the $\\ell^1$, $\\ell^2$, and $L^\\infty$ norms\n!! in one place.\n\n\n!!## USAGE\n!! * the $\\ell^\\infty$ norm,\n!\n! s = NormInfty( A [,W] )\n!\n!! * the $\\ell^2$ norm,\n!\n! s = NormEll2 ( A [,W] )\n!\n!! * the $\\ell^1$ norm,\n!\n! s = NormEll1 ( A [,W] )\n!\n!! * the squared $\\ell^2$ norm,\n!\n! s = NormEll2Sqr ( A [,W] )\n!\n\n!!#### EXTERNAL KINDS\nUSE KND_IntrinsicTypes,ONLY: KIND_Rsp,KIND_Rdp !!((01-A-KND_IntrinsicTypes.f90))\n\n\n!!#### EXTERNAL PROCEDURES\nUSE FUN_NormInfty !!((03-A-FUN_NormInfty.f90))\nUSE FUN_NormEll2 !!((03-A-FUN_NormEll2.f90))\nUSE FUN_NormEll1 !!((03-A-FUN_NormEll1.f90))\nUSE FUN_NormEll2Sqr !!((03-A-FUN_NormEll2Sqr.f90))\n\n\n!!#### DEFAULT IMPLICIT\nIMPLICIT NONE\n\n\n!!#### DEFAULT ACCESS\nPRIVATE\n\n\n!!#### PUBLIC ACCESS LIST\nPUBLIC :: NormInfty,NormEll2,NormEll1,NormEll2Sqr\n\n\nEND MODULE\n", "meta": {"hexsha": "d5f9dbdc45d04c3a9c026603f28770cc1a3e5c1c", "size": 996, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/04-B-LIB_Norm.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/04-B-LIB_Norm.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/04-B-LIB_Norm.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": 19.92, "max_line_length": 80, "alphanum_fraction": 0.5341365462, "num_tokens": 326, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357327, "lm_q2_score": 0.7799928900257127, "lm_q1q2_score": 0.6895443494993527}} {"text": " subroutine compute_ipsi()\n!***********************************************************************\n! Copyright 2011 Los Alamos National Security, LLC All rights reserved\n! Unless otherwise indicated, this information has been authored by an\n! employee or employees of the Los Alamos National Security, LLC (LANS),\n! operator of the Los Alamos National Laboratory under Contract No.\n! DE-AC52-06NA25396 with the U. S. Department of Energy. The U. S.\n! Government has rights to use, reproduce, and distribute this\n! information. The public may copy and use this information without\n! charge, provided that this Notice and any statement of authorship are\n! reproduced on all copies. Neither the Government nor LANS makes any\n! warranty, express or implied, or assumes any liability or\n! responsibility for the use of this information. \n!***********************************************************************\n! \n! Computes the inverse of the shapefunction matrix for hax elements\n!\n! Author : Sai Rapaka\n!\n use comfem, only: iPsi\n\n implicit none\n\n real*8 :: xc(8), yc(8), zc(8)\n real*8 :: zeta, eta, mu\n real*8 :: xmult, solved\n integer i,j,k\n real*8 :: Nmat(8, 8), rhs(8, 8)\n real*8 :: sol(8)\n\n xc = 1.0d0\n yc = 1.0d0\n zc = 1.0d0\n xc=(/-1.0d0, 1.0d0, 1.0d0, -1.0d0, -1.0d0, 1.0d0, 1.0d0, -1.0d0/)\n yc=(/-1.0d0, -1.0d0, 1.0d0, 1.0d0, -1.0d0, -1.0d0, 1.0d0, 1.0d0/)\n zc=(/-1.0d0, -1.0d0, -1.0d0, -1.0d0, 1.0d0, 1.0d0, 1.0d0, 1.0d0/)\n do i=1,8\n do j=1,8\n zeta = xc(i)/dsqrt(3.0d0)\n eta = yc(i)/dsqrt(3.0d0)\n mu = zc(i)/dsqrt(3.0d0)\n Nmat(i, j) = (1.0d0/8.0d0)*(1 + xc(j)*zeta)*\n & (1 + yc(j)*eta)*(1 + zc(j)*mu)\n enddo\n enddo\n\n rhs = 0.d00\n do i=1,8\n rhs(i,i) = 1.0d0\n enddo\n\n do k=1,7\n do i=k+1,8\n xmult = Nmat(i,k)/Nmat(k,k)\n do j=1,8\n Nmat(i,j) = Nmat(i,j) - xmult*Nmat(k,j)\n rhs(i,j) = rhs(i,j) - xmult*rhs(k,j)\n enddo\n enddo\n enddo\n\n do k=1,8\n ! Solve for the k-th column of rhs\n sol(8) = rhs(8, k)/Nmat(8,8)\n do j=7,1,-1\n solved = 0.0d0\n do i=j+1,8\n solved = solved + sol(i)*Nmat(j,i)\n enddo\n sol(j) = (rhs(j, k) - solved)/Nmat(j, j)\n enddo\n do j=1,8\n iPsi(j, k) = sol(j)\n enddo\n enddo\n\n return\n end subroutine compute_ipsi\n\n", "meta": {"hexsha": "87e583d074b1c10f12d8880ac5e068a0bf2bed2e", "size": 2555, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/compute_ipsi.f", "max_stars_repo_name": "satkarra/FEHM", "max_stars_repo_head_hexsha": "5d8d8811bf283fcca0a8a2a1479f442d95371968", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2018-08-09T04:55:28.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-31T21:46:32.000Z", "max_issues_repo_path": "src/compute_ipsi.f", "max_issues_repo_name": "satkarra/FEHM", "max_issues_repo_head_hexsha": "5d8d8811bf283fcca0a8a2a1479f442d95371968", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 19, "max_issues_repo_issues_event_min_datetime": "2018-04-06T16:17:14.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-14T04:40:14.000Z", "max_forks_repo_path": "src/compute_ipsi.f", "max_forks_repo_name": "satkarra/FEHM", "max_forks_repo_head_hexsha": "5d8d8811bf283fcca0a8a2a1479f442d95371968", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2018-06-07T21:11:55.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-11T13:48:22.000Z", "avg_line_length": 31.9375, "max_line_length": 72, "alphanum_fraction": 0.5064579256, "num_tokens": 929, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.924141826246517, "lm_q2_score": 0.7461389873857264, "lm_q1q2_score": 0.6895382464363721}} {"text": "*###[ ffxc0p0\n\tsubroutine ffxc0p0(cc0, xpi, ier)\n***#[*comment:***********************************************************\n*\t\t\t\t\t\t\t\t\t*\n*\tC0 function for all three momenta^2 = 0\t\t\t\t*\n*\tinput parameters as for ffxc0\t\t\t\t\t*\n*\t\t\t\t\t\t\t\t\t*\n*\toriginal code from David Garcia\t\t\t\t\t*\n*\t\t\t\t\t\t\t\t\t*\n***#]*comment:*********************************************************** \n* #[ declarations:\n\timplicit none\n*\n*\targuments\n*\n\tDOUBLE PRECISION xpi(6)\n\tDOUBLE COMPLEX cc0\n\tinteger ier\n\n\tDOUBLE PRECISION m1, m2, m3, m\n\tDOUBLE PRECISION eps\n\tparameter (eps = 1D-6)\n\n\tinclude 'ff.h'\n\n\tm1 = xpi(1)\n\tm2 = xpi(2)\n\tm3 = xpi(3)\n\n* sort the masses such that m1 >= m2 >= m3\n* this is important to avoid complex logs later\n\tif(m1 .lt. m2) then\n\t m = m2\n\t m2 = m1\n\t m1 = m\n\tendif\n\tif(m2 .lt. m3) then\n\t m = m3\n\t m3 = m2\n\t m2 = m\n\tendif\n\tif(m1 .lt. m2) then\n\t m = m2\n\t m2 = m1\n\t m1 = m\n\tendif\n\n\tm = m1 + m2 + m3\n\n\tif(m3/m .gt. eps) then\n\n* non-zero masses:\n\t if((m2 - m3)/m .gt. eps) then\n\t if((m1 - m2)/m .gt. eps) then\n* m1 != m2 != m3\n\t cc0 = (log(m3/m2) + m1/(m3 - m1)*log(m3/m1)\n + - m1/(m2 - m1)*log(m2/m1))/(m2 - m3)\n\t else\n* m1 = m2 != m3\n\t cc0 = (1 - m3/(m2 - m3)*log(m2/m3))/(m3 - m2)\n\t endif\n\t else\n\t if((m1 - m2)/m .gt. eps) then\n* m1 != m2 = m3\n\t cc0 = (1 - m1/(m2 - m1)*log(m2/m1))/(m1 - m2)\n\t else\n* m1 = m2 = m3\n\t cc0 = -.5D0/m1\n\t endif\n\t endif\n\n\telse\n\n* zero masses:\n\t if((m1 - m2)/m .gt. eps) then\n* m1 != m2, m3 = 0\n\t cc0 = log(m2/m1)/(m1 - m2)\n\t else\n* m1 = m2, m3 = 0\n\t cc0 = -1D0/m1\n\t endif\n\n\tendif\n\n\tend\n\n", "meta": {"hexsha": "c01b0828ba17cf302cadae94e0dd2331824f00c4", "size": 1575, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Tauola1_1_5/SANC/LoopTools-2.1/ff/ffxc0p0.f", "max_stars_repo_name": "klendathu2k/StarGenerator", "max_stars_repo_head_hexsha": "7dd407c41d4eea059ca96ded80d30bda0bc014a4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-12-24T19:37:00.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T06:57:20.000Z", "max_issues_repo_path": "Tauola1_1_5/SANC/LoopTools-2.1/ff/ffxc0p0.f", "max_issues_repo_name": "klendathu2k/StarGenerator", "max_issues_repo_head_hexsha": "7dd407c41d4eea059ca96ded80d30bda0bc014a4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Tauola1_1_5/SANC/LoopTools-2.1/ff/ffxc0p0.f", "max_forks_repo_name": "klendathu2k/StarGenerator", "max_forks_repo_head_hexsha": "7dd407c41d4eea059ca96ded80d30bda0bc014a4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-15T12:22:30.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-15T12:22:30.000Z", "avg_line_length": 18.1034482759, "max_line_length": 74, "alphanum_fraction": 0.4711111111, "num_tokens": 649, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418283357703, "lm_q2_score": 0.7461389817407016, "lm_q1q2_score": 0.6895382427784419}} {"text": " subroutine roe_solver(ixy,uv,enth,delta,wave_local,s_local,info)\n implicit none\n\n double precision :: uv(2),enth, delta(4)\n double precision :: wave_local(3,4), s_local(3)\n double precision :: euv, c2, c, u2v2, u,v\n double precision :: a1, a2, a3, a4, a5\n double precision :: gamma, gamma1\n integer :: m, p, mu, mv, ixy, i, j, k, info\n\n common /cparam/ gamma, gamma1\n\n\n info = 0\n\n gamma1 = gamma - 1.d0\n\n! # These are used even in the mapped case, but ixy is\n! # always set to 1; rotation matrix rot does switches\n! # coordinates for us.\n if (ixy == 1) then\n mu = 2\n mv = 3\n else\n mu = 3\n mv = 2\n endif\n\n u = uv(mu-1)\n v = uv(mv-1)\n\n u2v2 = u*u + v*v\n c2 = gamma1*(enth - 0.5d0*u2v2)\n if (c2 < 1e-13) then\n info = 1\n write(6,*) 'Roe solver : '\n write(6,'(A,E16.8, E16.8)') 'c2 .lt. 0; ', c2\n return\n ! stop\n endif\n c = sqrt(c2) !! sound speed\n euv = enth - u2v2\n\n a2 = (gamma1/c2) * (euv*delta(1) + u*delta(mu) + v*delta(mv) &\n - delta(4))\n a3 = delta(mv) - v*delta(1)\n a4 = (delta(mu) + (c-u)*delta(1) - c*a2) / (2.d0*c)\n a1 = delta(1) - a2 - a4\n\n! # 1-wave (rarefaction or shock)\n wave_local(1,1) = a1\n wave_local(1,mu) = a1*(u-c)\n wave_local(1,mv) = a1*v\n wave_local(1,4) = a1*(enth - u*c)\n s_local(1) = u - c\n\n! # contact discontinuity\n wave_local(2,1) = a2\n wave_local(2,mu) = a2*u\n wave_local(2,mv) = a2*v + a3\n wave_local(2,4) = a2*0.5d0*u2v2 + a3*v\n s_local(2) = u\n\n! # 3-wave (rarefaction or shock)\n wave_local(3,1) = a4\n wave_local(3,mu) = a4*(u+c)\n wave_local(3,mv) = a4*v\n wave_local(3,4) = a4*(enth + u*c)\n s_local(3) = u + c\n\n end subroutine roe_solver\n", "meta": {"hexsha": "6f38e419f7acc8c058f8954e7b1f4ee3985c2d5a", "size": 1796, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/euler_roe_solver_mapgrid.f90", "max_stars_repo_name": "ranocha/riemann", "max_stars_repo_head_hexsha": "d7b4d72d1147eee12e60a64f46a7e076b28a212d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 27, "max_stars_repo_stars_event_min_datetime": "2015-03-08T03:42:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-21T01:46:12.000Z", "max_issues_repo_path": "src/euler_roe_solver_mapgrid.f90", "max_issues_repo_name": "ranocha/riemann", "max_issues_repo_head_hexsha": "d7b4d72d1147eee12e60a64f46a7e076b28a212d", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 47, "max_issues_repo_issues_event_min_datetime": "2015-02-11T15:39:22.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-25T01:56:46.000Z", "max_forks_repo_path": "src/euler_roe_solver_mapgrid.f90", "max_forks_repo_name": "ranocha/riemann", "max_forks_repo_head_hexsha": "d7b4d72d1147eee12e60a64f46a7e076b28a212d", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 37, "max_forks_repo_forks_event_min_datetime": "2015-01-09T21:44:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-21T12:53:04.000Z", "avg_line_length": 24.9444444444, "max_line_length": 68, "alphanum_fraction": 0.5317371938, "num_tokens": 736, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92414182206801, "lm_q2_score": 0.7461389817407017, "lm_q1q2_score": 0.6895382381018217}} {"text": "C$Procedure LATCYL ( Latitudinal to cylindrical coordinates )\n \n SUBROUTINE LATCYL ( RADIUS, LONG, LAT, R, LONGC, Z )\n \nC$ Abstract\nC\nC Convert from latitudinal coordinates to cylindrical coordinates.\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 CONVERSION, COORDINATES\nC\nC$ Declarations\n \n DOUBLE PRECISION RADIUS\n DOUBLE PRECISION LONG\n DOUBLE PRECISION LAT\n DOUBLE PRECISION R\n DOUBLE PRECISION LONGC\n DOUBLE PRECISION Z\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC RADIUS I Distance of a point from the origin.\nC LONG I Angle of the point from the XZ plane in radians.\nC LAT I Angle of the point from the XY plane in radians.\nC R O Distance of the point from the Z axis.\nC LONGC O Angle of the point from the XZ plane in radians.\nC Z O Height of the point above the XY plane.\nC\nC$ Detailed_Input\nC\nC RADIUS Distance of a point from the origin.\nC\nC LONG Angle of the point from the XZ plane in radians.\nC\nC LAT Angle of the point from the XY plane in radians.\nC\nC$ Detailed_Output\nC\nC R Distance of the point from the Z axis. \nC\nC LONGC Angle of the point from the XZ plane in radians.\nC LONGC is set equal to LONG.\nC\nC Z Height of the point above the XY plane. \nC\nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC Error free.\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC This routine returns the cylindrical coordinates of a point\nC whose position is input in latitudinal coordinates.\nC\nC Latitudinal coordinates are defined by a distance from a central\nC reference point, an angle from a reference meridian, and an angle\nC above the equator of a sphere centered at the central reference\nC point.\nC\nC$ Examples\nC\nC Other than the obvious conversion between coordinate systems\nC this routine could be used to obtain the axial projection\nC from a sphere to a cylinder about the z-axis that contains\nC the equator of the sphere. The following code fragment\nC illustrates this idea.\nC\nC CALL LATCYL ( RADIUS, LONG, LAT, R, LONG, Z )\nC R = RADIUS\nC\nC R, LONG, and Z now contain the coordinates of the projected\nC point. Such a projection is valuable because it preserves the\nC areas between regions on the sphere and their projections to the\nC cylinder.\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC W.L. Taber (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.2, 26-JUL-2016 (BVS)\nC\nC Minor headers edits.\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 latitudinal to cylindrical coordinates\nC\nC-&\n \n \nC$ Revisions\nC\nC- Beta Version 1.0.1, 1-Feb-1989 (WLT)\nC\nC Example section of header upgraded.\nC\nC-&\n \n \nC\nC Local variables\nC\n DOUBLE PRECISION RH\n DOUBLE PRECISION ZZ\n \nC\nC Convert to cylindrical, storing in temporary variables\nC\n RH = RADIUS * DCOS(LAT)\n ZZ = RADIUS * DSIN(LAT)\n \nC\nC Move the results to output variables.\nC\n LONGC = LONG\n R = RH\n Z = ZZ\nC\n RETURN\n END\n", "meta": {"hexsha": "ca901dba20f0e0e49d15079e8252095fc0493fd9", "size": 4851, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/latcyl.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/latcyl.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/latcyl.f", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 26.8011049724, "max_line_length": 71, "alphanum_fraction": 0.6755308184, "num_tokens": 1359, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6895224112617016}} {"text": " subroutine root(a,b,c,x1,x2)\nc\nc + + + PURPOSE + + +\nc Finds roots for the equation y=a*x**2+b*x+c\nc\nc Called from subroutine XCRIT.\nc Author(s): G. Foster, M. Nearing\nc Reference in User Guide:\nc\nc Changes:\nc\nc Version: This module recoded from WEPP version 90.92.\nc Date recoded: 01/08/91.\nc Recoded by: Charles R. Meyer.\nc\nc + + + KEYWORDS + + +\nc\nc + + + ARGUMENT DECLARATIONS + + +\n real a, b\n double precision c, x1, x2\nc\nc a -\nc b -\nc c -\nc x1 -\nc x2 -\nc\nc + + + ARGUMENT DEFINITIONS + + +\nc\nc + + + LOCAL VARIABLES + + +\n double precision cc, part\n real b1, tmpvr1\nc cc -\nc part -\nc\nc + + + END SPECIFICATIONS + + +\nc\n b1 = -b\n tmpvr1 = 2.0 * a\n cc = -c\n part = sqrt(b**2-4.0*a*cc)\n x1 = (b1-part) / tmpvr1\n x2 = (b1+part) / tmpvr1\nc\n if (x1.gt.x2) then\n part = x2\n x2 = x1\n x1 = part\n end if\nc\n return\n end\n", "meta": {"hexsha": "7a9aec678e9b10aefd5521cad07d153a6fbfab7f", "size": 1016, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/wepp2012-src/root.for", "max_stars_repo_name": "jarad/dep", "max_stars_repo_head_hexsha": "fe73982f4c70039e1a31b9e8e2d9aac31502f803", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-11-26T17:49:19.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-26T17:49:19.000Z", "max_issues_repo_path": "src/wepp2012-src/root.for", "max_issues_repo_name": "jarad/dep", "max_issues_repo_head_hexsha": "fe73982f4c70039e1a31b9e8e2d9aac31502f803", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 54, "max_issues_repo_issues_event_min_datetime": "2018-12-12T18:02:31.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T19:14:25.000Z", "max_forks_repo_path": "src/wepp2012-src/root.for", "max_forks_repo_name": "akrherz/idep", "max_forks_repo_head_hexsha": "7189a26fbcec3d8c3cc7d7015107b8fb6c5f6a45", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-03-02T22:59:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-09T15:49:00.000Z", "avg_line_length": 19.1698113208, "max_line_length": 59, "alphanum_fraction": 0.4911417323, "num_tokens": 372, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.909907001151883, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6895224088334577}} {"text": " SUBROUTINE DC2FIT(XI,YI,SDI,NXY,B,NB,W,NW,YKNOT,YPKNOT,\n * SIGFAC, IERR1)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc>> 2000-12-01 DC2FIT Krogh Dim. SDI(*) instead NXY.\nc>> 1995-11-21 DC2FIT Krogh Converted from SFTRAN to Fortran 77.\nc>> 1994-10-19 DC2FIT Krogh Changes to use M77CON\nc>> 1994-01-31 DC2FIT CLL Added test for SDI(i) .le. 0 when SDI(1) > 0.\nc>> 1990-01-23 CLL Deleted ref to unused variable NX in call to IERM1\nC>> 1989-10-20 CLL\nC>> 1987-10-22 DC2FIT Lawson Initial code.\nc Least squares fit to discrete data by a C-2 cubic spline.\nc ------------------------------------------------------------------\nC Algorithm and program designed by C.L.Lawson and R.J.Hanson.\nc The general approach but not the complete code is given in\nC 'SOLVING LEAST SQUARES PROBLEMS', by Lawson and Hanson,\nC publ by Prentice-Hall, 1974.\nC Programming and later changes and corrections by Lawson,Hanson,\nC T.Lang, and D.Campbell, Sept 1968, Nov 1969, and Aug 1970.\nC Modified 1968 Sept 17 to provide C-2 continuity.\nC 1974 5/21, C.L.Lawson, Fixed bug that caused ISEG to get too big.\nC Also changed to exit immidiately if B() array is not\nC strictly increasing.\nc 1984 July 10. Modified for improved portability and to conform\nc to Fortran 77. C. L. Lawson, JPL.\nc Added calls to the error message subrs.\nc 7/23/87 CLL. Added the IERR1 argument.\nC 1989-10-20 CLL Changed code so there are no RETURN statements in\nc Sftran procedures. Previous code had such a RETURN that led to\nc a warning diagnostic from a Cray compiler due to unreachable\nc CONTINUE statements. Also introduced \"c--\" lines for CHGTYP.\nc ------------------------------------------------------------------\nc SUBROUTINE ARGUMENTS\nc\nc (XI(i),i=1,NXY) [in] Abcissas of data to be fitted. Require\nc this data be ordered so X(i) .le. X(i+1).\nc\nc (YI(i),i=1,NXY) [in] Ordinates of data to be fitted.\nc\nc (SDI(i),i=1,NXY) [in] User may use this array to assign an\nc a priori standard deviation of error to each\nc YI(i) value. The weighted fitting algorithm will take\nc account of these. Optionally the user may set SDI(1) to\nc a negative value. Then this subr will use ABS(SDI(1)) as\nc the standard deviation for each YI(i) value. In this case\nc the SDI() array can be dimensioned SDI(1).\nc If SDI(1) = 0., the subr issues an error message and returns.\nc\nc NXY [in] No. of data pairs, (XI(i), YI(i)), and no. of elts\nc in SDI() if SDI(1) is positive. Require NXY .ge. 4.\nc\nc (B(j),j=1,NB) [in] Breakpoints for the spline function,\nc including endpoints. These breakpoints must be\nc strictly increasing: B(j) .lt. B(j+1).\nc It is required that all abcissas, XI(i), lie in the\nc closed interval, [B(1), B(NB)].\nc\nc NB [in] No. of breakpoints, including endpoints.\nc The no. of parameters in the least squares problem\nc will be NB + 2.\nc To have a nonsingular problem one must have\nc NXY .ge. NB + 2, and the distribution of the breakpoints\nc must not be too skewed relative to the data abcissas.\nc If singularity is detected, an error message will be\nc issued by the subr that solves the band matrix.\nc\nc W() [scratch] Work space dimensioned W(NW,5).\nc\nc NW [in] First dimension of W(). Must satisfy NW .ge. NB + 4\nc Let KMAX denote the max no. of data abcissas, XI(i),\nc in any one breakpoint interval, i.e. between B(j) and\nc B(j+1) for some j. The subr will be more efficient\nc if NW is at least NB + 3 + KMAX.\nc\nc (YKNOT(k) and YPKNOT(k),k=1,NB) [out] The subr will return\nc values defining the fitted C2 spline curve in these arrays.\nc These values and first derivatives of the fitted curve at the\nc knot abcissae. YKNOT(j) = f(B(j)) and\nc YPKNOT(j) = fprime(B(j)) for j = 1,...,NB.\nc The user can then evaluate the fitted curve at any point by\nc Hermite interpolation. See subrs DHINT or SHINT.\nc\nc SIGFAC [out] The subr sets SIGFAC to RNORM / sqrt(DOF) where\nc RNORM = sqrt( sum over i of [( (yfit(i) - YI(i))/SDI(i))**2])\nc and DOF = max(1, NXY - (NB+2))\nC\nc IERR1 [out] Error status indicator. Note that IERR2 comes from\nc DBACC and IERR3 comes from DBSOL.\nc\nc = 0 means no errors detected.\nc = 100 means NB .lt. 2 .or. NXY .lt. NB+2\nc = 200 means B(I) .ge. B(I+1)\nc = 300 means NW .lt. NB+4\nc = 400 means XI(I-1) .gt. XI(I)\nc = 500 means B(1) .gt. XI(1) .or. B(NB) .lt. XI(NXY)\nc = 600 means Need larger dimension NW.\nc = 700 + IERR2 means IERR2 .ne. 0\nc = 800 + IERR2 means IERR2 .ne. 0\nc = 900 + IERR2 means IERR2 .ne. 0\nc = 1000 + IERR3 means IERR3 .ne. 0 due to singularity\nc detected in DBSOL.\nc = 1100 means SDI(1) = zero.\nc = 1200 means SDI(1) > zero and SDI(i) .le. zero for some i.\nc ------------------------------------------------------------------\nc Important internal variables.\nc\nc ISEG Index of current spline segment, starting with 1 for\nc the first segment.\nc Also tells the band matrix subroutine the column index\nc of the least squares matrix with which the first col\nc of the new block of data in G() is to be associated.\nC KSIZE Size of current block.\nC JPOINT Current data pointer.\nc ------------------------------------------------------------------\nc--D replaces \"?\": ?C2FIT, ?BACC, ?C2BAS, ?ERM1, ?ERV1, ?BSOL, ?TRC2C\nc Both versions use ERMSG, IERM1, IERV1\nc Lower level subrs needed: (D/S)HTCC, (D/S)NRM2, ERFIN\nc ------------------------------------------------------------------\n integer I, IERR1, IERR2, IERR3, IRNOW, ISEG, J, JPOINT, JTPREV\n integer K, KSIZE, N1, NB, NPARAM, NW, NXY\n integer NBAND, NBAND1\n parameter(NBAND = 4, NBAND1 = NBAND+1)\n double precision XI(NXY), YI(NXY), SDI(*), B(NB), W(NW, 5)\n double precision YKNOT(NB), YPKNOT(NB), P(4), ONE, ZERO\n double precision DOF, RNORM, sdijp, SIGFAC, WT, WT1\n logical NEWSEG, USEWT1\n parameter( ONE = 1.0D0, ZERO = 0.0D0)\nc ------------------------------------------------------------------\n IERR1 = 0\nC\nC EXIT IMMEDIATELY IF NB .lt. 2 OR NXY .LT NB+2 OR IF THE\nC BREAKPOINTS ARE NOT STRICTLY INCREASING.\nc\n NPARAM = NB+2\n IF ( NB .lt. 2 .or. NXY .lt. NPARAM) THEN\n IERR1 = 100\n call IERM1('DC2FIT',IERR1,0,\n * 'Require NB .ge. 2 and NXY .ge. NB+2', 'NB',NB,',')\n call IERV1('NXY',NXY,'.')\n go to 300\n END IF\nc\n N1 = NB-1\n DO 20 I = 1,N1\n IF (B(I) .ge. B(I+1)) THEN\n IERR1 = 200\n call IERM1('DC2FIT',IERR1,0,\n * 'Require knots, B(I), to be strictly increasing.',\n * 'I',I,',')\n call DERV1('B(I)',B(I),',')\n call DERV1('B(I+1)',B(I+1),'.')\n go to 300\n END IF\n 20 CONTINUE\nC\nC Require NW .ge. NB+4\nC\n IF (NW .lt. NB+4) THEN\n IERR1 = 300\n call IERM1('DC2FIT',IERR1,0,'Require NW .ge. NB+4','NW',NW,',')\n call IERV1('NB',NB,'.')\n go to 300\n END IF\nC\nc ------------------------------------------------------------------\nC TEST SDI(1)\n IF (SDI(1) .lt. ZERO) THEN\n WT1 = -ONE/SDI(1)\n USEWT1 = .true.\n ELSE IF ( SDI(1) .gt. ZERO) THEN\n USEWT1 = .false.\n ELSE\n IERR1 = 1100\n call ERMSG('DC2FIT',IERR1,0,'Require SD(1) .ne. Zero','.')\n return\n END IF\nC\nc Test ordering of XI() array.\nc\n DO 40 I=2,NXY\n IF (XI(I-1) .gt. XI(I)) THEN\n IERR1 = 400\n call IERM1('DC2FIT',IERR1,0,\n * 'Require abcissas, X(I), to be nondecreasing.',\n * 'I',I,',')\n call DERV1('X(I-1)',XI(I-1),',')\n call DERV1('X(I)',XI(I),'.')\n go to 300\n END IF\n 40 CONTINUE\nc\nC TEST THE FIRST AND LAST BREAKPOINT\nC FOR BRACKETING THE DATA ABCISSAS.\nc\n IF (B(1) .gt. XI(1) .or. B(NB) .lt. XI(NXY)) THEN\n IERR1 = 500\n call DERM1('DC2FIT',IERR1,0,\n * 'Require B(1) .LE. X(1) and B(NB) .ge. XI(NXY)',\n * 'B(1)',B(1),',')\n call DERV1('X(1)',XI(1),',')\n call DERV1('B(NB)',B(NB),',')\n call DERV1('X(NXY)',XI(NXY),'.')\n go to 300\n END IF\nC\nC BEGIN LOOP TO FORM EQUATIONS FOR C2 LEAST SQUARES FIT.\nC\n IRNOW = 1\n K = 1\n KSIZE = 0\n NEWSEG = .TRUE.\n ISEG = 1\n DO 120 JPOINT = 1, NXY\n IF( K .gt. NW ) THEN\n call DBACC(W, NW, NBAND, IRNOW, KSIZE, ISEG, JTPREV, IERR2)\n if(IERR2 .ne. 0) then\n IERR1 = 700 + IERR2\n go to 200\n end if\n\n IF(IRNOW .gt. NW) THEN\n IERR1 = 600\n call IERM1('DC2FIT',IERR1,0,\n * 'Need larger dimension NW.','NW',NW,'.')\n go to 300\n END IF\n K = IRNOW\n KSIZE = 0\n END IF\nc\nC DO WHILE( XI(JPOINT) .gt. B(ISEG+1) )\n 80 IF ( XI(JPOINT) .gt. B(ISEG+1) ) THEN\n call DBACC(W, NW, NBAND, IRNOW, KSIZE, ISEG, JTPREV, IERR2)\n if(IERR2 .ne. 0) then\n IERR1 = 800 + IERR2\n go to 200\n end if\n KSIZE = 0\n K = IRNOW\n ISEG = ISEG + 1\n NEWSEG = .TRUE.\n go to 80\n END IF\nc END WHILE\nc Build one equation\n call DC2BAS(XI(JPOINT), 0, ISEG,NEWSEG,B,NB,P)\n IF( USEWT1) THEN\n WT = WT1\n ELSE\n sdijp = sdi(jpoint)\n if(sdijp .gt. ZERO) then\n WT=ONE/sdijp\n else\n IERR1 = 1200\n call ERMSG('DC2FIT',IERR1,0,\n * 'With SD(1) > 0 require all SD(I) > 0.', ',')\n call DERV1('SD(1)',SDI(1),'.')\n call IERV1('I',jpoint,',')\n call DERV1('SD(I)',sdijp,'.')\n return\n end if\n END IF\n DO 100 J = 1,4\n W(K,J)=P(J)*WT\n 100 CONTINUE\n W(K,5)=YI(JPOINT)*WT\nc End of build one equation\n K = K+1\n KSIZE = KSIZE + 1\nc\n 120 CONTINUE\n call DBACC(W, NW, NBAND, IRNOW, KSIZE, ISEG, JTPREV, IERR2)\n if(IERR2 .ne. 0) then\n IERR1 = 900 + IERR2\n go to 200\n end if\nC\nC ALL DATA POINTS HAVE BEEN PROCESSED. CALL FOR SOLUTION.\nC\n call DBSOL(1,W, NW, NBAND, IRNOW, JTPREV, W(1,NBAND1),\n * NPARAM, RNORM, IERR3)\n if(IERR3 .ne. 0) then\n IERR1 = 1000 + IERR2\n call ERMSG('DC2FIT',IERR1,0,\n * 'Singularity noted in DBSOL.','.')\n go to 300\n end if\n\n DOF = MAX(1, NXY - NPARAM)\n SIGFAC = RNORM / sqrt(DOF)\nC\nC TRANSFORM PARAMETERS TO Y,YPRIME BASIS\nC\n call DTRC2C (B,NB,W(1,5),YKNOT,YPKNOT)\n RETURN\nc\nc Error in _BACC\n 200 call ERMSG('DC2FIT',IERR1,0,\n * 'Error detected in subroutine DBACC','.')\n\nc Set YKNOT() & YPKNOT() to zero\n 300 DO 320 I=1,NB\n YKNOT(I)=ZERO\n YPKNOT(I)=ZERO\n 320 CONTINUE\n return\n end\n", "meta": {"hexsha": "dc02aaf9cf0fd558e61c55d35cf96279bd6cd044", "size": 11750, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/dc2fit.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/dc2fit.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/dc2fit.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 38.0258899676, "max_line_length": 72, "alphanum_fraction": 0.524, "num_tokens": 3875, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070011518829, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6895224088334576}} {"text": " INTEGER FUNCTION MB03ND( N, THETA, Q2, E2, PIVMIN, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To find the number of singular values of the bidiagonal matrix\nC\nC |q(1) e(1) . ... 0 |\nC | 0 q(2) e(2) . |\nC J = | . . |\nC | . e(N-1)|\nC | 0 ... ... 0 q(N) |\nC\nC which are less than or equal to a given bound THETA.\nC\nC This routine is intended to be called only by other SLICOT\nC routines.\nC\nC ARGUMENTS\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The order of the bidiagonal matrix J. N >= 0.\nC\nC THETA (input) DOUBLE PRECISION\nC Given bound.\nC Note: If THETA < 0.0 on entry, then MB03ND is set to 0\nC as the singular values of J are non-negative.\nC\nC Q2 (input) DOUBLE PRECISION array, dimension (N)\nC This array must contain the squares of the diagonal\nC elements q(1),q(2),...,q(N) of the bidiagonal matrix J.\nC That is, Q2(i) = J(i,i)**2 for i = 1,2,...,N.\nC\nC E2 (input) DOUBLE PRECISION array, dimension (N-1)\nC This array must contain the squares of the superdiagonal\nC elements e(1),e(2),...,e(N-1) of the bidiagonal matrix J.\nC That is, E2(k) = J(k,k+1)**2 for k = 1,2,...,N-1.\nC\nC PIVMIN (input) DOUBLE PRECISION\nC The minimum absolute value of a \"pivot\" in the Sturm\nC sequence loop.\nC PIVMIN >= max( max( |q(i)|, |e(k)| )**2*sf_min, sf_min ),\nC where i = 1,2,...,N, k = 1,2,...,N-1, and sf_min is at\nC least the smallest number that can divide one without\nC overflow (see LAPACK Library routine DLAMCH).\nC Note that this condition is not checked by the routine.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value.\nC\nC METHOD\nC\nC The computation of the number of singular values s(i) of J which\nC are less than or equal to THETA is based on applying Sylvester's\nC Law of Inertia, or equivalently, Sturm sequences [1,p.52] to the\nC unreduced symmetric tridiagonal matrices associated with J as\nC follows. Let T be the following 2N-by-2N symmetric matrix\nC associated with J:\nC\nC | 0 J'|\nC T = | |.\nC | J 0 |\nC\nC (The eigenvalues of T are given by s(1),s(2),...,s(N),-s(1),-s(2),\nC ...,-s(N)). Then, by permuting the rows and columns of T into the\nC order 1, N+1, 2, N+2, ..., N, 2N it follows that T is orthogonally\nC similar to the tridiagonal matrix T\" with zeros on its diagonal\nC and q(1), e(1), q(2), e(2), ..., e(N-1), q(N) on its offdiagonals\nC [3,4]. If q(1),q(2),...,q(N) and e(1),e(2),...,e(N-1) are nonzero,\nC Sylvester's Law of Inertia may be applied directly to T\".\nC Otherwise, T\" is block diagonal and each diagonal block (which is\nC then unreduced) must be analysed separately by applying\nC Sylvester's Law of Inertia.\nC\nC REFERENCES\nC\nC [1] Parlett, B.N.\nC The Symmetric Eigenvalue Problem.\nC Prentice Hall, Englewood Cliffs, New Jersey, 1980.\nC\nC [2] Demmel, J. and Kahan, W.\nC Computing Small Singular Values of Bidiagonal Matrices with\nC Guaranteed High Relative Accuracy.\nC Technical Report, Courant Inst., New York, March 1988.\nC\nC [3] Van Huffel, S. and Vandewalle, J.\nC The Partial Total Least-Squares Algorithm.\nC J. Comput. and Appl. Math., 21, pp. 333-341, 1988.\nC\nC [4] Golub, G.H. and Kahan, W.\nC Calculating the Singular Values and Pseudo-inverse of a\nC Matrix.\nC SIAM J. Numer. Anal., Ser. B, 2, pp. 205-224, 1965.\nC\nC [5] Demmel, J.W., Dhillon, I. and Ren, H.\nC On the Correctness of Parallel Bisection in Floating Point.\nC Computer Science Division Technical Report UCB//CSD-94-805,\nC University of California, Berkeley, CA 94720, March 1994.\nC\nC NUMERICAL ASPECTS\nC\nC The singular values s(i) could also be obtained with the use of\nC the symmetric tridiagonal matrix T = J'J, whose eigenvalues are\nC the squared singular values of J [4,p.213]. However, the method\nC actually used by the routine is more accurate and equally\nC efficient (see [2]).\nC\nC To avoid overflow, matrix J should be scaled so that its largest\nC element is no greater than overflow**(1/2) * underflow**(1/4)\nC in absolute value (and not much smaller than that, for maximal\nC accuracy).\nC\nC With respect to accuracy the following condition holds (see [2]):\nC\nC If the established value is denoted by p, then at least p\nC singular values of J are less than or equal to\nC THETA/(1 - (3 x N - 1.5) x EPS) and no more than p singular values\nC are less than or equal to\nC THETA x (1 - (6 x N-2) x EPS)/(1 - (3 x N - 1.5) x EPS).\nC\nC CONTRIBUTOR\nC\nC Release 3.0: V. Sima, Katholieke Univ. Leuven, Belgium, Apr. 1997.\nC Supersedes Release 2.0 routine MB03BD by S. Van Huffel, Katholieke\nC University, Leuven, Belgium.\nC\nC REVISIONS\nC\nC July 10, 1997.\nC\nC KEYWORDS\nC\nC Bidiagonal matrix, singular values.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO\n PARAMETER ( ZERO = 0.0D0 )\nC .. Scalar Arguments ..\n INTEGER INFO, N\n DOUBLE PRECISION PIVMIN, THETA\nC .. Array Arguments ..\n DOUBLE PRECISION E2(*), Q2(*)\nC .. Local Scalars ..\n INTEGER J, NUMEIG\n DOUBLE PRECISION R, T\nC .. External Subroutines ..\n EXTERNAL XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC ABS\nC .. Executable Statements ..\nC\nC Test the input scalar arguments. PIVMIN is not checked.\nC\n INFO = 0\n IF( N.LT.0 ) THEN\n INFO = -1\nC\nC Error return.\nC\n CALL XERBLA( 'MB03ND', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF ( N.EQ.0 .OR. THETA.LT.ZERO ) THEN\n MB03ND = 0\n RETURN\n END IF\nC\n NUMEIG = N\n T = -THETA\n R = T\n IF ( ABS( R ).LT.PIVMIN ) R = -PIVMIN\nC\n DO 20 J = 1, N - 1\n R = T - Q2(J)/R\n IF ( ABS( R ).LT.PIVMIN ) R = -PIVMIN\n IF ( R.GT.ZERO ) NUMEIG = NUMEIG - 1\n R = T - E2(J)/R\n IF ( ABS( R ).LT.PIVMIN ) R = -PIVMIN\n IF ( R.GT.ZERO ) NUMEIG = NUMEIG - 1\n 20 CONTINUE\nC\n R = T - Q2(N)/R\n IF ( ABS( R ).LT.PIVMIN ) R = -PIVMIN\n IF ( R.GT.ZERO ) NUMEIG = NUMEIG - 1\n MB03ND = NUMEIG\nC\n RETURN\nC *** Last line of MB03ND ***\n END\n", "meta": {"hexsha": "e8355ef76df54e3fd668a2bf230da4c4a894efa3", "size": 6941, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB03ND.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB03ND.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB03ND.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 34.0245098039, "max_line_length": 72, "alphanum_fraction": 0.5706670509, "num_tokens": 2195, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9353465188527684, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6894983266596871}} {"text": "subroutine sum_with_use(x, res)\r\n use precision\r\n\r\n implicit none\r\n\r\n real(kind=rk), intent(in) :: x(:)\r\n real(kind=rk), intent(out) :: res\r\n\r\n integer :: i\r\n\r\n !print *, \"size(x) = \", size(x)\r\n\r\n res = 0.0\r\n\r\n do i = 1, size(x)\r\n res = res + x(i)\r\n enddo\r\n\r\n end subroutine\r\n", "meta": {"hexsha": "992147c7bb23ed65bf1a43b431e863abafc4cbd6", "size": 288, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "libs/numpy/f2py/tests/src/assumed_shape/foo_use.f90", "max_stars_repo_name": "rocketbot-cl/recognition", "max_stars_repo_head_hexsha": "cca8a87070ccaca3a26e37345c36ab1bf836e258", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 353, "max_stars_repo_stars_event_min_datetime": "2020-12-10T10:47:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:08:29.000Z", "max_issues_repo_path": "libs/numpy/f2py/tests/src/assumed_shape/foo_use.f90", "max_issues_repo_name": "rocketbot-cl/recognition", "max_issues_repo_head_hexsha": "cca8a87070ccaca3a26e37345c36ab1bf836e258", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 80, "max_issues_repo_issues_event_min_datetime": "2020-12-10T09:54:22.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T22:08:45.000Z", "max_forks_repo_path": "libs/numpy/f2py/tests/src/assumed_shape/foo_use.f90", "max_forks_repo_name": "rocketbot-cl/recognition", "max_forks_repo_head_hexsha": "cca8a87070ccaca3a26e37345c36ab1bf836e258", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 63, "max_forks_repo_forks_event_min_datetime": "2020-12-10T17:10:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-28T16:27:07.000Z", "avg_line_length": 14.4, "max_line_length": 36, "alphanum_fraction": 0.5347222222, "num_tokens": 93, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. Yes\n2. Yes", "lm_q1_score": 0.7371581626286834, "lm_q2_score": 0.9353465184022066, "lm_q1q2_score": 0.6894983209265066}} {"text": "!********************************************************************************\n! EFT: Error-Free Transformations and Compensated Arithmetic Routines\n! Author: Thomas R. Cameron and Aidan O'Neill\n! Institution: Davidson College, Mathematics and Computer Science Department\n! Last Modified: 29 March 2020\n!********************************************************************************\nmodule eft\n implicit none\n integer, parameter :: dp = kind(1.d0), factor = 2**27 + 1\n real(kind=dp), parameter :: big = huge(1.0_dp), eps = 2.0_dp**(-52), mu = 2.0_dp**(-53), small = tiny(1.0_dp)\n !********************************************************\n ! REFT: Real Error Free Transformation type.\n !********************************************************\n ! Made up of two real(kind=dp) variables x and y\n ! called primary and secondary, respectively. \n ! For TwoSum and TwoProd, x will denote floating-\n ! point result and y will denote error in result.\n ! For Split, x and y are the two parts of the\n ! floating-point number. \n !******************************************************** \n type REFT\n real(kind=dp) :: x ! primary\n real(kind=dp) :: y ! secondary\n end type REFT\n !********************************************************\n ! CEFTSum: Complex Error Free Transformation Sum.\n !********************************************************\n ! Made up of two complex(kind=dp) variables x and y\n ! called primary and secondary, respectively. \n ! For TwoSumCplx, x denotes the floating-point \n ! result and y denotes the error.\n !********************************************************\n type CEFTSum\n complex(kind=dp) :: x ! primary\n complex(kind=dp) :: y ! secondary\n end type CEFTSum\n !********************************************************\n ! CEFTProd: Complex Error Free Transformation Product.\n !********************************************************\n ! Made up of four complex(kind=dp) variables p, e, f,\n ! and g, which we call primary, secondary, tertiary,\n ! and quaternary, respectively. For TwoProductCplx,\n ! p denotes the floating-point result, and e, f, and g\n ! denote errors associated with the sum and product\n ! of real and imaginary parts. \n !********************************************************\n type CEFTProd\n complex(kind=dp) :: p ! primary\n complex(kind=dp) :: e ! secondary\n complex(kind=dp) :: f ! tertiary\n complex(kind=dp) :: g ! quaternary\n end type CEFTProd\n !********************************************************\n ! REFTHorner: Real Error Free Transformation Horner.\n !********************************************************\n ! Made up of a real(kind=dp) variable h to store result\n ! of standard Horner method and two real(kind=dp) \n ! allocatable variables to store polynomial coefficients\n ! p and q, where pi is the error in the product term\n ! and qi is the error in the sum term on the ith\n ! iteration of Horner's method. \n !********************************************************\n type REFTHorner\n real(kind=dp) :: h ! result\n real(kind=dp), allocatable :: p(:) ! error in product\n real(kind=dp), allocatable :: q(:) ! error in sum\n end type REFTHorner\n !********************************************************\n ! CEFTHorner: Complex Error Free Transformation Horner.\n !********************************************************\n ! Made up of a complex(kind=dp) variable h to store \n ! result of standard Horner method and four allocatable\n ! complex(kind=dp) variables to store polynomial \n ! coefficients p, q, r, and s, where pi, qi, ri is the\n ! error in the product term and si is the error in the\n ! sum term on the ith iteration of Horner's method. \n !********************************************************\n type CEFTHorner\n complex(kind=dp) :: h ! result\n complex(kind=dp), allocatable :: p(:) ! error in product\n complex(kind=dp), allocatable :: q(:) ! error in product\n complex(kind=dp), allocatable :: r(:) ! error in product\n complex(kind=dp), allocatable :: s(:) ! error in sum\n end type CEFTHorner\n\ncontains\n\n !********************************************************\n ! Two Sum *\n !********************************************************\n ! Computes the sum of two floating-point numbers\n ! a and b. The result and error is returned in\n ! comp which has type REFT. \n !********************************************************\n function TwoSum(a,b) result(comp)\n implicit none\n ! argument variables\n real(kind=dp) :: a, b\n ! local variables\n real(kind=dp) :: z\n type(REFT) :: comp\n\n ! compute floating-point sum\n comp%x = a + b\n z = comp%x - a\n ! compute error in floating-point sum\n comp%y = (a - (comp%x - z)) + (b - z)\n return\n end function TwoSum\n !********************************************************\n ! Two Sum Cplx *\n !********************************************************\n ! Computes the sum of two complex floating-point \n ! numbers a and b. The result and error is \n ! returned in comp which has type CEFTSum. \n !********************************************************\n function TwoSumCplx(a,b) result(comp)\n implicit none\n ! argument variables\n complex(kind=dp) :: a, b\n ! local variables\n type(REFT) :: rcomp, icomp\n type(CEFTSum) :: comp\n \n ! compute sum of real and imaginary parts\n rcomp = TwoSum(real(a),real(b))\n icomp = TwoSum(aimag(a),aimag(b))\n ! store primary and secondary complex numbers in comp\n comp%x = cmplx(rcomp%x,icomp%x,kind=dp)\n comp%y = cmplx(rcomp%y,icomp%y,kind=dp)\n return\n end function TwoSumCplx\n !********************************************************\n ! Split *\n !********************************************************\n ! Computes the splitting of a floating-point \n ! number a. Both parts have at most 26 nonzero bits \n ! and are returned in comp which has type REFT.\n !********************************************************\n function Split(a) result(comp)\n implicit none\n ! argument variables\n real(kind=dp) :: a\n ! local variables \n real(kind=dp) :: c\n type(REFT) :: comp\n \n ! factor a\n c = factor * a\n ! split into two 26-bit numbers\n comp%x = c - (c - a)\n comp%y = a - comp%x\n return\n end function Split\n !********************************************************\n ! Two Product *\n !********************************************************\n ! Computes the product of two floating-point\n ! numbers a and b. The result and error is \n ! returned in comp which has type REFT. \n !********************************************************\n function TwoProduct(a,b) result(comp)\n implicit none\n ! argument variables\n real(kind=dp) :: a, b\n ! local variables\n type(REFT) :: comp, sa, sb\n \n ! compute floating-point product\n comp%x = a * b\n ! split a and b\n sa = Split(a)\n sb = Split(b)\n ! compute error in floating-point product\n comp%y = sa%y * sb%y - (((comp%x - sa%x * sb%x) - sa%y * sb%x) - sa%x * sb%y)\n return\n end function TwoProduct\n !********************************************************\n ! Two Product Cplx *\n !********************************************************\n ! Computes the product of two complex floating-point \n ! numbers a and b. The result and error is returned \n ! in comp which has type CEFTP. \n !********************************************************\n function TwoProductCplx(a,b) result(comp)\n implicit none\n ! argument variables\n complex(kind=dp) :: a, b\n ! local variables\n real(kind=dp) :: z1, z2, z3, z4\n type(REFT) :: sra, sia, srb, sib, sumr, sumi\n type(CEFTProd) :: comp\n \n ! perform splitting of real(a), imag(a), real(b), imag(b)\n sra = Split(real(a)); sia = Split(aimag(a))\n srb = Split(real(b)); sib = Split(aimag(b))\n ! compute product of real and imaginary parts\n z1 = real(a) * real(b); z2 = aimag(a) * aimag(b)\n z3 = real(a) * aimag(b); z4 = aimag(a) * real(b)\n ! compute sum z1-z2\n sumr = TwoSum(z1,-z2)\n ! compute sum z3+z4\n sumi = TwoSum(z3,z4)\n ! floating-point result\n comp%p = cmplx(sumr%x,sumi%x,kind=dp)\n ! error in z1 and z3\n comp%e = cmplx(sra%y * srb%y - (((z1 - sra%x * srb%x) - sra%y * srb%x) - sra%x * srb%y),&\n sra%y * sib%y - (((z3 - sra%x * sib%x) - sra%y * sib%x) - sra%x * sib%y),kind=dp)\n ! error in z2 and z4\n comp%f = cmplx(-sia%y * sib%y + (((z2 - sia%x * sib%x) - sia%y * sib%x) - sia%x * sib%y),&\n sia%y * srb%y - (((z4 - sia%x * srb%x) - sia%y * srb%x) - sia%x * srb%y),kind=dp)\n ! error in sums\n comp%g = cmplx(sumr%y,sumi%y,kind=dp)\n return\n end function TwoProductCplx\n !********************************************************\n ! EFT Horner *\n !********************************************************\n ! Compute the evaluation of a polynomial at a\n ! floating-point number. The result and error\n ! is returned in comp which has type REFTHorner. \n !********************************************************\n function EFTHorner(poly,x,deg) result(comp)\n implicit none\n ! argument variables\n integer :: deg\n real(kind=dp) :: poly(:), x\n ! local variables\n integer :: k\n type(REFT) :: prod, sum\n type(REFTHorner) :: comp\n \n ! allocate memory for comp polynomials\n allocate(comp%p(deg),comp%q(deg))\n ! Horner's method\n comp%h = poly(deg+1)\n do k=deg,1,-1\n ! product and sum\n prod = TwoProduct(comp%h,x)\n sum = TwoSum(prod%x,poly(k))\n ! update comp\n comp%h = sum%x\n comp%p(k) = prod%y\n comp%q(k) = sum%y\n end do\n return\n end function EFTHorner\n !********************************************************\n ! EFT Horner Cplx *\n !********************************************************\n ! Compute the evaluation of a polynomial at a complex\n ! floating-point number. The result and error is returned\n ! in comp which has type CEFTHorner. \n !********************************************************\n function EFTHornerCplx(poly,x,deg) result(comp)\n implicit none\n ! argument variables\n integer :: deg\n complex(kind=dp) :: poly(:), x\n ! local variables\n integer :: k\n type(CEFTSum) :: sum\n type(CEFTProd) :: prod\n type(CEFTHorner) :: comp\n \n ! allocate memory for comp polynomials\n allocate(comp%p(deg),comp%q(deg),comp%r(deg),comp%s(deg))\n ! Horner's method\n comp%h = poly(deg+1)\n do k=deg,1,-1\n ! product and sum\n prod = TwoProductCplx(comp%h,x)\n sum = TwoSumCplx(prod%p,poly(k))\n ! update comp\n comp%h = sum%x\n comp%p(k) = prod%e\n comp%q(k) = prod%f\n comp%r(k) = prod%g\n comp%s(k) = sum%y\n end do\n return\n end function EFTHornerCplx\n !****************************************************\n ! Next Power Two *\n !****************************************************\n ! Computation of 2^ceil(log2(abs(p))), for p \\neq 0. \n !****************************************************\n function NextPowerTwo(p) result(comp)\n implicit none\n ! argument variables\n real(kind=dp) :: p\n ! local variables\n real(kind=dp) :: comp, q\n \n q = p/mu\n comp = abs((q+p)-q)\n if(comp==0.0_dp) then\n comp = abs(p)\n end if\n return\n end function NextPowerTwo\n !****************************************************\n ! Faith Sum *\n !****************************************************\n ! Computes the faithful sum of the real floating-\n ! point numbers a, b, c, and d. Result is returned\n ! in comp which has type real(kind=dp). \n !****************************************************\n function FaithSum(a,b,c,d) result(comp)\n implicit none\n ! argument variables\n real(kind=dp) :: a, b, c, d\n ! local variables\n integer :: n\n real(kind=dp) :: fac, m, Ms, phi, sigma\n real(kind=dp) :: comp, t, tau, tau1, tau2\n real(kind=dp), allocatable :: p(:), q(:)\n real(kind=dp), parameter :: realmin = tiny(1.0_dp)\n \n ! initialize arrays\n n = 4\n allocate(p(n),q(n))\n p(1)=a; p(2)=b; p(3)=c; p(4)=d\n ! check size and max\n 10 m = maxval(abs(p))\n if(n==0 .or. m==0.0_dp) then\n comp = 0.0_dp\n deallocate(p,q)\n return\n end if\n ! initialize variables\n Ms = NextPowerTwo((n+2)*1.0_dp)\n sigma = Ms*NextPowerTwo(m)\n phi = mu*Ms\n fac = eps*Ms*Ms\n ! main loop\n t = 0.0_dp\n do while(.True.)\n q = (sigma + p) - sigma\n tau = sum(q)\n p = p - q\n tau1 = t + tau\n ! check new approximation tau1\n if(abs(tau1)>=fac*sigma .or. sigma<=realmin) then\n tau2 = tau - (tau1 - t)\n comp = tau1 + (tau2 + sum(p))\n deallocate(p,q)\n return\n end if\n t = tau1\n ! accelerate zero sum case\n if(t==0.0_dp) then\n p = pack(p, p /= 0.0_dp)\n n = size(p)\n deallocate(q)\n allocate(q(n))\n go to 10\n end if\n ! new extraction unit\n sigma = phi*sigma\n end do\n end function FaithSum\n !****************************************************\n ! Faith Sum Cplx *\n !****************************************************\n ! Computes the faithful sum of the complex floating-\n ! point numbers a, b, c, and d. Result is returned\n ! in comp which has type complex(kind=dp). \n !****************************************************\n function FaithSumCplx(a,b,c,d) result(comp)\n implicit none\n ! argument variables\n complex(kind=dp) :: a, b, c, d\n ! local variables\n complex(kind=dp) :: comp\n \n comp = cmplx(FaithSum(real(a),real(b),real(c),real(d)),&\n FaithSum(aimag(a),aimag(b),aimag(c),aimag(d)),kind=dp)\n return\n end function FaithSumCplx\nend module eft", "meta": {"hexsha": "88889efabbb224721ce2bf6c90ce21644b80e93b", "size": 16348, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/eft.f90", "max_stars_repo_name": "trcameron/FPML-Comp", "max_stars_repo_head_hexsha": "f71c968b5a9fc490fcce7490b8543e6c54dc7c42", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/eft.f90", "max_issues_repo_name": "trcameron/FPML-Comp", "max_issues_repo_head_hexsha": "f71c968b5a9fc490fcce7490b8543e6c54dc7c42", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/eft.f90", "max_forks_repo_name": "trcameron/FPML-Comp", "max_forks_repo_head_hexsha": "f71c968b5a9fc490fcce7490b8543e6c54dc7c42", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.9081364829, "max_line_length": 132, "alphanum_fraction": 0.4122828481, "num_tokens": 3727, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094088947399, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.689495054125586}} {"text": "!-----------------------------------------------------------------------\n program test\n implicit none\n include 'ceed/fortran.h'\n\n integer ceed,err,i,j\n real*8 a(12),qr(12),a_qr(12),tau(3)\n\n character arg*32\n\n A = (/ 1, -1, 4, 1, 4, -2, 1, 4, 2, 1, -1, 0 /)\n qr = (/ 1, -1, 4, 1, 4, -2, 1, 4, 2, 1, -1, 0 /)\n a_qr = (/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /)\n\n call getarg(1,arg)\n\n call ceedinit(trim(arg)//char(0),ceed,err)\n call ceedqrfactorization(ceed,qr,tau,4,3,err)\n do i=1,3\n do j=i,3\n a_qr((i-1)*3+j)=qr((i-1)*3+j)\n enddo\n enddo\n call ceedhouseholderapplyq(a_qr,qr,tau,ceed_notranspose,4,3,3,3,1,err)\n\n do i=1,12\n if (abs(a(i)-a_qr(i))>1.0D-14) then\n! LCOV_EXCL_START\n write(*,*) 'Error in QR factorization a_qr(',i,') = ',a_qr(i),&\n & ' != a(',i,') = ',a(i)\n! LCOV_EXCL_STOP\n endif\n enddo\n\n call ceeddestroy(ceed,err)\n\n end\n!-----------------------------------------------------------------------\n", "meta": {"hexsha": "3496fbfa205a09c3a51660461cc833806537e6ed", "size": 1046, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/t301-basis-f.f90", "max_stars_repo_name": "AdelekeBankole/libCEED", "max_stars_repo_head_hexsha": "aae8ce39fa1e28b745979a9cbffc67a790eb3f5e", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 123, "max_stars_repo_stars_event_min_datetime": "2018-01-29T02:04:05.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T18:13:48.000Z", "max_issues_repo_path": "tests/t301-basis-f.f90", "max_issues_repo_name": "AdelekeBankole/libCEED", "max_issues_repo_head_hexsha": "aae8ce39fa1e28b745979a9cbffc67a790eb3f5e", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 781, "max_issues_repo_issues_event_min_datetime": "2017-12-22T17:20:35.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T21:34:34.000Z", "max_forks_repo_path": "tests/t301-basis-f.f90", "max_forks_repo_name": "AdelekeBankole/libCEED", "max_forks_repo_head_hexsha": "aae8ce39fa1e28b745979a9cbffc67a790eb3f5e", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 41, "max_forks_repo_forks_event_min_datetime": "2017-12-27T22:35:13.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-01T13:02:07.000Z", "avg_line_length": 26.8205128205, "max_line_length": 76, "alphanum_fraction": 0.4235181644, "num_tokens": 409, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094117351309, "lm_q2_score": 0.7718434873426302, "lm_q1q2_score": 0.689495051629637}} {"text": "module STEPSIZES\n! Description:\n! Contains the subroutine DSTEPSIZE used to compute the initial step size for\n! the distinct formulations according to the reference.\n! \n! Reference:\n! Amato D., Ba\u00f9 G., and Bombardelli C., \"Accurate numerical orbit propagation\n! of planetary close encounters\". Submitted to MNRAS. 2016.\n! \n! Author:\n! Davide Amato\n! Space Dynamics Group - Technical University of Madrid\n! d.amato@upm.es\n! \n! ==============================================================================\n\nuse KINDS, only: dk,qk\nimplicit none\n\n\ncontains\n\n\nfunction DSTEPSIZE(R,V,mu,DU,eqs,inSoI,tol)\n! Description:\n! Choose the initial stepsize according to the formulation and the sign of the\n! orbital energy.\n! \n! Reference:\n! [1] Battin R.H., \"An Introduction to the Mathematics and Methods of\n! Astrodynamics\", Revised Ed., AIAA, Reston, VA, USA. 1999.\n! [2] Amato D., Ba\u00f9 G., and Bombardelli C., \"Accurate numerical orbit\n! propagation of planetary close encounters\". Submitted to MNRAS. 2016.\n! \n! ==============================================================================\n\nuse CONSTANTS, only: twopi,pi,smaEarth\n\n! VARIABLES\n! Arguments\nreal(qk),intent(in) :: R(1:3),V(1:3),mu,DU\nreal(dk),intent(in) :: tol\ninteger,intent(in) :: eqs\nlogical,intent(in) :: inSoI\n! Function definition\nreal(dk) :: DSTEPSIZE\n! Angular momentum, energy, sma, eccentricity, semi-parameter\nreal(dk) :: rn,vsq\nreal(dk) :: h(1:3),En,sma,ecc,p\n! Intervals in true, Gudermannian, hyperbolic and hyperbolic mean anomalies\nreal(dk) :: fplus,zplus,Hplus,Nplus\nreal(dk) :: df,dH,dz,dN\n! Elliptic and hyperbolic intervals\nreal(dk) :: rlim\nreal(dk) :: ell,hyp\ninteger,parameter :: nell = 100, nhyp = 600\n\n! ==============================================================================\n\n! Compute energy and sma\nrn = sqrt(dot_product(R,R))\nvsq = dot_product(V,V)\nEn = 0.5_dk*vsq - mu/rn\nsma = -0.5_dk*mu/En\n\nif (En < 0._dk) then\n select case (eqs)\n case (-1,1)\n ell = twopi*sqrt(sma**3/mu)\n \n case (2)\n ell = twopi\n \n case (3)\n ell = twopi*sqrt(sma/mu)\n \n case (4)\n ! GDromo cannot integrate closed orbits.\n ell = 0._dk\n \n end select\n \n DSTEPSIZE = ell/nell\n \nelse\n if (inSoI) then\n ! Set rlim = 0.1 AU\n rlim = 0.1_dk*(smaEarth/DU)\n else\n rlim = 5._dk*(smaEarth/DU)\n end if\n \n ! Limiting true anomaly \"fplus\" corresponding to the point on the\n ! hyperbola at a distance \"rlim\" away from the primary, 0 <= fplus <= pi.\n h = [R(2)*V(3) - R(3)*V(2), R(3)*V(1) - R(1)*V(3), R(1)*V(2) - R(2)*V(1)]\n p = dot_product(h,h)/mu\n ecc = sqrt(1._dk - p/sma)\n fplus = acos((p/rlim - 1._dk)/ecc)\n df = 2._dk*fplus\n \n ! Limiting Gudermannian anomaly and interval of Gudermannian anomaly.\n zplus = 2._dk*atan(sqrt((ecc - 1._dk)/(ecc + 1._dk))*tan(0.5_dk*fplus))\n dz = 2._dk*zplus\n \n select case (eqs)\n case (-1,1)\n ! Limiting hyperbolic mean anomaly\n Nplus = ecc*tan(zplus) - log(tan(0.5_dk*zplus + 0.25_dk*pi))\n dN = 2._dk*Nplus\n \n hyp = sqrt((-sma)**3/mu)*dN\n \n case (2)\n hyp = dz\n \n case (3)\n ! EDromo cannot integrate open orbits.\n hyp = 0._dk\n \n case (4)\n ! Limiting hyperbolic anomaly\n Hplus = 2._dk*atanh(tan(0.5_dk*zplus))\n dH = 2._dk*Hplus\n \n hyp = dH\n \n end select\n \n DSTEPSIZE = hyp/nhyp\n \nend if\n\nDSTEPSIZE = -DSTEPSIZE/log10(tol)\n\nend function DSTEPSIZE\n\nend module STEPSIZES\n", "meta": {"hexsha": "86c4dfd94d021772bfcd3fbd94d3bfc44ec16f2f", "size": 3488, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "step_sizes.f90", "max_stars_repo_name": "dkamato/NAPLES", "max_stars_repo_head_hexsha": "fbbf2be8fe861ecaf47051bc0811ad947bb9dc82", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2016-10-31T16:47:26.000Z", "max_stars_repo_stars_event_max_datetime": "2019-01-15T01:18:54.000Z", "max_issues_repo_path": "step_sizes.f90", "max_issues_repo_name": "dkamato/NAPLES", "max_issues_repo_head_hexsha": "fbbf2be8fe861ecaf47051bc0811ad947bb9dc82", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "step_sizes.f90", "max_forks_repo_name": "dkamato/NAPLES", "max_forks_repo_head_hexsha": "fbbf2be8fe861ecaf47051bc0811ad947bb9dc82", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.2753623188, "max_line_length": 81, "alphanum_fraction": 0.5888761468, "num_tokens": 1158, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625069680098, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6894446668583094}} {"text": "PROGRAM p9\n\nIMPLICIT NONE\nINTERFACE\n REAL FUNCTION cube_root(x)\n END FUNCTION cube_root\nEND INTERFACE\n\nREAL :: a,b\nPRINT *, \"type a number:\"\nREAD *, a\n\nb = cube_root(a)\n\nPRINT *, \"cube root of \", a, \" is \", b\n\nSTOP\nEND PROGRAM p9\n\nREAL FUNCTION cube_root(x)\n IMPLICIT NONE\n REAL :: x, log_x\n log_x = LOG(x)\n cube_root = EXP(log_x/3.0)\nEND FUNCTION cube_root\n\n", "meta": {"hexsha": "6c298a0f6d2dd18b83fd5b505d36267a1ddae26e", "size": 365, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lab2/p9.f90", "max_stars_repo_name": "M1nified/UJ-Fortran", "max_stars_repo_head_hexsha": "3067d036e38a2bdf433bd63eb47498cc163dedaf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lab2/p9.f90", "max_issues_repo_name": "M1nified/UJ-Fortran", "max_issues_repo_head_hexsha": "3067d036e38a2bdf433bd63eb47498cc163dedaf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lab2/p9.f90", "max_forks_repo_name": "M1nified/UJ-Fortran", "max_forks_repo_head_hexsha": "3067d036e38a2bdf433bd63eb47498cc163dedaf", "max_forks_repo_licenses": ["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.5185185185, "max_line_length": 38, "alphanum_fraction": 0.6821917808, "num_tokens": 112, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.6893668151415477}} {"text": "PROGRAM main\n !\n ! Description:\n ! Program to compute the Singular\n ! Value Decomposition of a pre-\n ! viously computed K-Matrix from\n ! the CRTM using the LAPACK subroutine\n ! DGESVD.\n !\n ! The SVD has the following form:\n !\n ! K = U * S * V'\n !\n ! Author: P. Stegmann\n ! Date: 2019-12-02\n !\n IMPLICIT NONE\n\n ! Data Dictionary:\n INTEGER(KIND=8), PARAMETER :: M = 92 ! Atmospheric pressure levels\n INTEGER(KIND=8), PARAMETER :: N = 5 ! AMSU-A channels\n REAL(KIND=8), DIMENSION(M,N) :: K ! CRTM K-Matrix\n REAL(KIND=8), DIMENSION(M,N) :: s\n REAL(KIND=8), DIMENSION(M,M) :: u\n REAL(KIND=8), DIMENSION(N,N) :: v\n REAL(KIND=8), DIMENSION(MIN(M,N)) :: sdiag\n REAL(KIND=8), ALLOCATABLE, DIMENSION(:) :: work\n INTEGER(KIND=8) :: info\n INTEGER(KIND=8) :: lda\n INTEGER(KIND=8) :: ldu\n INTEGER(KIND=8) :: ldv\n CHARACTER :: jobu\n CHARACTER :: jobv\n INTEGER(KIND=4) :: lwork\n INTEGER(KIND=4) :: ii\n \n ! Instructions:\n \n ! Read in the K-Matrix for all AMSU-A channels:\n OPEN(66,FILE='output_K.txt',STATUS='OLD')\n READ(66,*) K\n CLOSE(66)\n \n ! Prepare DGESVD working arrays:\n lwork = MAX(3*MIN(M,N) + MAX(M,N), 5*MIN(M,N))\n ALLOCATE(work(1:lwork))\n jobu = 'A'\n jobv = 'A'\n lda = M\n ldu = M\n ldv = N\n !WRITE(*,*) K \n\n ! Compute SVD with LAPACK:\n CALL DGESVD(jobu,jobv,M,N,K,lda,sdiag,u,ldu,v,ldv, work,lwork,info)\n IF( info /= 0 ) THEN\n WRITE(*,*) 'Singular value decomposition failed!'\n END IF\n WRITE(*,*) 'INFO = ', info\n WRITE(*,*) 'The singular values are: '\n WRITE(*,*) sdiag\n DEALLOCATE(work)\n\n ! Result output:\n ! Singular values:\n OPEN(666,FILE='SVD_result.txt',STATUS='NEW')\n WRITE(666,*) sdiag\n CLOSE(666)\n\n !Singular vectors:\n OPEN(444,FILE='Singular_vectors.txt',STATUS='NEW')\n DO ii = 1, N\n WRITE(444,*) u(ii,:)\n END DO\n CLOSE(444)\nEND PROGRAM main\n", "meta": {"hexsha": "cb9c5356d6a0d24eaab52ed77627ca10d34b99b4", "size": 1827, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "K-Matrix_SVD/main.f90", "max_stars_repo_name": "StegmannJCSDA/CRTM_tutorial", "max_stars_repo_head_hexsha": "3e8ace4b69ca27093c8117b1d0872c4cdceed8b0", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-06-28T12:39:56.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-25T20:47:58.000Z", "max_issues_repo_path": "K-Matrix_SVD/main.f90", "max_issues_repo_name": "StegmannJCSDA/CRTM_tutorial", "max_issues_repo_head_hexsha": "3e8ace4b69ca27093c8117b1d0872c4cdceed8b0", "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": "K-Matrix_SVD/main.f90", "max_forks_repo_name": "StegmannJCSDA/CRTM_tutorial", "max_forks_repo_head_hexsha": "3e8ace4b69ca27093c8117b1d0872c4cdceed8b0", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-03-04T22:29:07.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-25T09:40:44.000Z", "avg_line_length": 23.7272727273, "max_line_length": 69, "alphanum_fraction": 0.6174055829, "num_tokens": 666, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970654616711, "lm_q2_score": 0.7826624688140726, "lm_q1q2_score": 0.6893668057784219}} {"text": " function wq_semianalyt(tres, tdel, term_m, prock, cprev, cint)\n \n!! ~ ~ ~ PURPOSE ~ ~ ~\n!! This function solves a semi-analytic solution for the QUAL2E equations (cfr Befekadu Woldegiorgis).\n\n!! ~ ~ ~ INCOMING VARIABLES ~ ~ ~\n!! name |units |definition\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\n!! xx |none |Exponential argument\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\n\n!! ~ ~ ~ OUTGOING VARIABLES ~ ~ ~\n!! name |units |definition\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\n!! tres |days |residence time in reach\n!! tdel |days |calculation time step\n!! term_m | |constant term in equation\n!! cprev |mg/l |concentration previous timestep\n!! cint |mg/l |incoming concentration \n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\n\n!! ~ ~ ~ SUBROUTINES/FUNCTIONS CALLED ~ ~ ~\n!! Intrinsic: Exp\n \n!! ~ ~ ~ ~ ~ ~ END SPECIFICATIONS ~ ~ ~ ~ ~ ~\n \n real, intent (in) :: tres\n real, intent (in) :: tdel\n real, intent (in) :: prock\n real, intent (in) :: term_m\n real, intent (in) :: cprev\n real, intent (in) :: cint\n real :: help1, help2, help3, help4, term1, term2, yy\n\n help1 = 1. / tres - prock\n help2 = exp(-tdel * help1)\n help3 = cint / tres + term_m\n help4 = help3 / help1\n term1 = cprev * help2\n term2 = help4 * (1. - help2)\n yy = term1 + term2\n wq_semianalyt = term1 + term2\n\n return\n end function\n \n function wq_k2m (t1, t2, tk, c1, c2)\n \n!! ~ ~ ~ PURPOSE ~ ~ ~\n!! This function solves a semi-analytic solution for the QUAL2E equations (cfr Befekadu Woldegiorgis).\n\n!! ~ ~ ~ INCOMING VARIABLES ~ ~ ~\n!! name |units |definition\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\n!! xx |none |Exponential argument\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\n\n!! ~ ~ ~ OUTGOING VARIABLES ~ ~ ~\n!! name |units |definition\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\n!! tres |days |residence time in reach\n!! tdel |days |calculation time step\n!! term_m | |constant term in equation\n!! cprev |mg/l |concentration previous timestep\n!! cint |mg/l |incoming concentration \n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\n\n!! ~ ~ ~ SUBROUTINES/FUNCTIONS CALLED ~ ~ ~\n!! Intrinsic: Exp\n \n!! ~ ~ ~ ~ ~ ~ END SPECIFICATIONS ~ ~ ~ ~ ~ ~\n\n real, intent (in) :: t1\n real, intent (in) :: t2\n real, intent (in) :: tk\n real, intent (in) :: c1\n real, intent (in) :: c2\n real :: h1, h2, help, tm, h3\n \n h1 = wq_semianalyt (t1, t2, 0., 0., c1, c2)\n h2 = wq_semianalyt (t1, t2, 0., tk, c1, c2)\n help = exp(-t2 / t1)\n \n tm = (h2 - c1 * help) / (t1 * (1. - help)) - c2 / t1\n h3 = wq_semianalyt (t1, t2, tm, 0., c1, c2)\n wq_k2m = tm\n\n return\n end function", "meta": {"hexsha": "dff5edca7c288f156ce722123b5beb76509137b0", "size": 3292, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/data/program_analysis/multifile_multimod/mfmm_02/ch_watqual_semi_analitical_function.f90", "max_stars_repo_name": "mikiec84/delphi", "max_stars_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2018-03-03T11:57:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-16T21:19:54.000Z", "max_issues_repo_path": "tests/data/program_analysis/multifile_multimod/mfmm_02/ch_watqual_semi_analitical_function.f90", "max_issues_repo_name": "mikiec84/delphi", "max_issues_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 385, "max_issues_repo_issues_event_min_datetime": "2018-02-21T16:52:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-17T07:44:56.000Z", "max_forks_repo_path": "tests/data/program_analysis/multifile_multimod/mfmm_02/ch_watqual_semi_analitical_function.f90", "max_forks_repo_name": "mikiec84/delphi", "max_forks_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2018-03-20T01:08:11.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-29T01:04:49.000Z", "avg_line_length": 36.9887640449, "max_line_length": 105, "alphanum_fraction": 0.4125151883, "num_tokens": 1160, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248191350352, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.6893564559709421}} {"text": "!-------------------------------------------------------------------------------!\r\n! ! \r\n\r\n subroutine basis(npt,nptperyear,f,g,yag,ydl) \r\n\r\n! ! \r\n! This subroutine computes sine and cosine basis functions !\r\n! to be used in the subroutine SEASON. It also computes !\r\n! polynomial basis functions to be used in the subroutine SAVGOL !\r\n! !\r\n! Authors: !\r\n! Per J\\\"onsson, Malm\\\"o University, Sweden !\r\n! e-mail per.jonsson@ts.mah.se !\r\n! !\r\n! Lars Eklundh, Lund University, Sweden !\r\n! e-mail lars.eklundh@nateko.lu.se !\r\n! !\r\n! Updated 1/11-2005 !\r\n! !\r\n!-------------------------------------------------------------------------------!\r\n\r\nimplicit none\r\n\r\ninteger :: i,j,npt,nptperyear\r\ndouble precision :: pi,width,fact(7),x(5),t(npt),f(npt,5),g(npt,3)\r\ndouble precision :: yag(2*nptperyear,7,2),ydl(2*nptperyear,5,2),arg(2*nptperyear)\r\n\r\n!---- Generate sine basis -------------------------------------------------------\r\n\r\npi = 2.d0*asin(1.d0)\r\nt = dble((/(i,i=1,npt)/))/dble(nptperyear)\r\n\r\nf(:,1) = 1.d0\r\nf(:,2) = sin(2.d0*pi*t)\r\nf(:,3) = cos(2.d0*pi*t)\r\nf(:,4) = sin(4.d0*pi*t)\r\nf(:,5) = cos(4.d0*pi*t)\r\n\r\n!---- Generate polynomial basis -------------------------------------------------\r\n\r\ng(:,1) = 1.d0\r\ng(:,2) = dble((/(i,i=1,npt)/))\r\ng(:,3) = dble((/(i,i=1,npt)/))**2.d0\r\n\r\n!---- Generate asymmetric gaussian basis ---------------------------------------\r\n\r\nwidth = nptperyear/4.d0\r\n\r\nt = dble((/(i,i=1,npt)/))\r\n\r\nfact(1:7) = (/ 0.2d0, 0.4d0, 0.7d0, 1.d0, 1.3d0, 1.7d0, 2.1d0 /)\r\nx(1) = nptperyear + 0.5d0\r\nx(3) = 3.d0\r\nx(5) = 3.d0\r\n\r\ndo i = 1,7\r\n do j = 1,2\r\n x(2) = width*fact(i)/(j*log(2.d0)**0.25d0)\r\n\tx(4) = x(2)\r\n\targ = (/ ((x(1)-t(1:nptperyear))/x(2))**x(3), &\r\n\t ((t(nptperyear+1:2*nptperyear)-x(1))/x(4))**x(5) /)\r\n yag(:,i,j) = exp(-arg) \r\n end do\r\nend do\r\n\r\n!---- Generate double logistic basis -------------------------------------------\r\n\r\nfact(1:5) = (/ 0.3d0, 0.6d0, 1.d0, 1.5d0, 1.9d0 /)\t\r\nx(2) = nptperyear/20.d0\r\nx(4) = x(2)\r\n\r\ndo i = 1,5\r\n do j = 1,2\r\n x(1) = nptperyear - width*fact(i)/j\r\n\tx(3) = nptperyear + width*fact(i)/j\r\n\tydl(:,i,j) = 1.d0/(1.d0 + exp((x(1)-t(1:2*nptperyear))/x(2))) &\r\n\t - 1.d0/(1.d0 + exp((x(3)-t(1:2*nptperyear))/x(4))) \r\n end do\r\nend do\r\n\r\nend subroutine basis\r\n ", "meta": {"hexsha": "efd7ab08475cacd0dff54be0beab10ef47e1bccc", "size": 3191, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/Smooth_Gapfill_LAI/basis.f90", "max_stars_repo_name": "bucricket/projectMASpreprocess", "max_stars_repo_head_hexsha": "608495d7cd6890ecca6ad2a8be0d15b5ea80f7c1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-28T20:26:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T20:26:59.000Z", "max_issues_repo_path": "source/Smooth_Gapfill_LAI/basis.f90", "max_issues_repo_name": "bucricket/projectMASpreprocess", "max_issues_repo_head_hexsha": "608495d7cd6890ecca6ad2a8be0d15b5ea80f7c1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/Smooth_Gapfill_LAI/basis.f90", "max_forks_repo_name": "bucricket/projectMASpreprocess", "max_forks_repo_head_hexsha": "608495d7cd6890ecca6ad2a8be0d15b5ea80f7c1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-04-20T21:04:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-16T08:05:44.000Z", "avg_line_length": 38.9146341463, "max_line_length": 152, "alphanum_fraction": 0.328737073, "num_tokens": 890, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248191350352, "lm_q2_score": 0.734119526900183, "lm_q1q2_score": 0.689356455970942}} {"text": "!***************************************************************\n!* Purpose: This program computes the spherical Bessel *\n!* functions yn(x) and yn'(x) using subroutine *\n!* SPHY *\n!* Input : x --- Argument of yn(x) ( x > 0 ) *\n!* n --- Order of yn(x) ( n = 0 to 250 ) *\n!* Output: SY(n) --- yn(x) *\n!* DY(n) --- yn'(x) *\n!* Example: x = 10.0 *\n!* n yn(x) yn'(x) *\n!* -------------------------------------------- *\n!* 0 .8390715291D-01 -.6279282638D-01 *\n!* 1 .6279282638D-01 .7134858763D-01 *\n!* 2 -.6506930499D-01 .8231361788D-01 *\n!* 3 -.9532747888D-01 -.2693831344D-01 *\n!* 4 -.1659930220D-02 -.9449751377D-01 *\n!* 5 .9383354168D-01 -.5796005523D-01 *\n!* ----------------------------------------------------------- *\n!* REFERENCE: \"Fortran Routines for Computation of Special *\n!* Functions, *\n!* jin.ece.uiuc.edu/routines/routines.html\". *\n!* *\n!* F90 Release By J-P Moreau, Paris. *\n!* (www.jpmoreau.fr) *\n!***************************************************************\n! PROGRAM MSPHY\n! IMPLICIT DOUBLE PRECISION (A-H,O-Z)\n! DIMENSION SY(0:250),DY(0:250)\n! WRITE(*,*)'Please enter n and x '\n! READ(*,*)N,X\n! WRITE(*,30)N,X\n! IF (N.LE.10) THEN\n! NS=1\n! ELSE\n! WRITE(*,*)'Please enter order step Ns'\n! READ(*,*)NS\n! ENDIF\n! CALL SPHY(N,X,NM,SY,DY)\n! WRITE(*,*)\n! WRITE(*,*)' n yn(x) yn''(x)'\n! WRITE(*,*)'--------------------------------------------'\n! DO 10 K=0,NM,NS\n!10 WRITE(*,20)K,SY(K),DY(K)\n!20 FORMAT(1X,I3,2D20.10)\n!30 FORMAT(3X,6HNmax =,I3,', ',2Hx=,F6.1)\n! END\n\n MODULE msphy\n CONTAINS\n\n SUBROUTINE SPHY(N,X,NM,SY,DY)\n\n! ======================================================\n! Purpose: Compute spherical Bessel functions yn(x) and\n! their derivatives\n! Input : x --- Argument of yn(x) ( x \u00f2 0 )\n! n --- Order of yn(x) ( n = 0,1,\u00fa\u00fa\u00fa )\n! Output: SY(n) --- yn(x)\n! DY(n) --- yn'(x)\n! NM --- Highest order computed\n! ======================================================\n\n IMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION SY(0:N),DY(0:N)\n NM=N\n IF (X.LT.1.0D-60) THEN\n DO 10 K=0,N\n SY(K)=-1.0D+300\n10 DY(K)=1.0D+300\n RETURN\n ENDIF\n SY(0)=-DCOS(X)/X\n SY(1)=(SY(0)-DSIN(X))/X\n F0=SY(0)\n F1=SY(1)\n DO 15 K=2,N\n F=(2.0D0*K-1.0D0)*F1/X-F0\n SY(K)=F\n IF (DABS(F).GE.1.0D+300) GO TO 20\n F0=F1\n15 F1=F\n20 NM=K-1\n DY(0)=(DSIN(X)+DCOS(X)/X)/X\n DO 25 K=1,NM\n25 DY(K)=SY(K-1)-(K+1.0D0)*SY(K)/X\n RETURN\n END\n\n END MODULE\n\n!end of file msphy.f90\n", "meta": {"hexsha": "7f93616ee7c9bcabb3060ad423851160aeb10aac", "size": 3505, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/SpherePEC/BESSEL_LIB/msphy.f90", "max_stars_repo_name": "Riarrieta/WindowedGreenFunctionMethod", "max_stars_repo_head_hexsha": "e6f965cac1acd8d9922e2bf94c33e3577ceb0dc9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/SpherePEC/BESSEL_LIB/msphy.f90", "max_issues_repo_name": "Riarrieta/WindowedGreenFunctionMethod", "max_issues_repo_head_hexsha": "e6f965cac1acd8d9922e2bf94c33e3577ceb0dc9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/SpherePEC/BESSEL_LIB/msphy.f90", "max_forks_repo_name": "Riarrieta/WindowedGreenFunctionMethod", "max_forks_repo_head_hexsha": "e6f965cac1acd8d9922e2bf94c33e3577ceb0dc9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.097826087, "max_line_length": 65, "alphanum_fraction": 0.3292439372, "num_tokens": 994, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513675912912, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.6892892190057253}} {"text": "c \nc A collection of functions to compute various moist thermodynamic quantities\nc\nc Rodrigo Caballero Augi 2000 (rca@dcess.ku.dk)\nc\nc References: Bolton (1980), Mon. Wea. Rev. 108, 1046-1053 \nc Bohren and Albrecht (1998), \"Atmospheric Thermodynamics\"\nc Flatau et al (1992), J. App. Met . 31, 1507-1513.\nc\nc------------------------------------------------------------------------\n real*8 function tdew(p,q)\nc\nc compute dew point temperature tdew [K] \nc at pressure p [mb] and specific humidity q [g/kg]\nc Use Bolton eqn (11)\nc\n real*8 p,q\n\n Rv = 461.5\n Rd = 287.04\n eps = Rd/Rv\n r = q/(1.e3 - q) * 1.e3 ! water vap. mixing ratio [g/kg]\n es = p*r/(r+eps*1.e3) ! vapor pressure of water vap\nc\n tdew = (243.5*log(es)-440.8)/(19.48-log(es))+273.15\nc\n end\nc------------------------------------------------------------------------\n real*8 function tstar(t,p,q)\nc\nc compute saturation point temperature tstar [K] \nc (i.e. temperature at lifting condensation level) \nc given temperature t [K], pressure p [mb], specific humidity q [g/kg].\nc Use Bolton eqn (12)\nc\n real*8 t,p,q\n external theta\n\n Rv = 461.5\n Rd = 287.04\n eps = Rd/Rv\n oneoverk = 3.504 ! Cp/Rd\n r = q/(1.e3 - q) * 1.e3 ! water vap. mixing ratio [g/kg]\nc\n th=theta(t,p,q)\n c=log(r/(r+eps*1.e3)/th**oneoverk/1.7743e-8)\n tstar=217.8*c/(12.992-c) + 273.15\nc\n end\nc------------------------------------------------------------------------\n real*8 function theta(t,p,q)\nc\nc compute potential temperature theta [K]\nc given temperature t [K], pressure p [mb], specific humidity q [g/kg].\nc Use Bolton eqn (7) \nc \n ak=0.2854 ! R_(dry air)/Cp\n r = q/(1.e3 - q) * 1.e3 ! water vap. mixing ratio [g/kg]\nc\n theta=t*(1000./p)**( ak*(1.-0.28e-3*r) )\nc \n end\nc------------------------------------------------------------------------\n real*8 function thetae(t,p,q)\nc\nc compute equivalent potential temperature thetae [K]\nc given temperature t [K], pressure p [mb], specific humidity q [g/kg].\nc Use Bolton eqn (38)\nc\n real*8 t,p,q\n external theta,tstar\n\n th=theta(t,p,q)\n ts=tstar(t,p,q)\n r = q/(1.e3 - q) * 1.e3 ! water vap. mixing ratio [g/kg]\n\n thetae = th * exp( (3.376/ts-0.00254)*r*(1.+0.81e-3*r) )\nc\n end\nc------------------------------------------------------------------------\n real*8 function es(t)\nc\nc Compute saturation partial pressure of water vapor es [mb]\nc at temperature t [K].\nc Use Bohren+Albrecht p. 198\nc \n real*8 t\n t0m1=1./273.15\nc\n es = 6.11 * exp( 6808.*(t0m1-1./t)-5.09*log(t*t0m1) )\nc\n end\nc------------------------------------------------------------------------\n real*8 function esflatau(t,i)\nc\nc Compute saturation partial pressure of water vapor es [mb]\nc at temperature t [K].\nc Use 8th oRder polynomial fit of Flatau et al (1992), Table 4\nc\nc i=1 => vapour pressure over water (valid -85C < t < 70C)\nc i=2 => vapour pressure over ice (valid -90C < t < 0C)\nc \n real*8 t,a(9,2)\n data a /\n & 6.11239921, 0.443987641, 0.142986287e-1, 0.264847430e-3,\n & 0.302950461e-5, 0.206739458e-7, 0.640689451e-10,-0.952447341e-13,\n & -0.976195544e-15,\n & 6.11147274, 0.503160820, 0.188439774e-1, 0.420895665e-3,\n & 0.615021634e-5, 0.602588177e-7, 0.385852041e-9, 0.146898966e-11,\n & 0.252751365e-14 /\nc\n t0=273.15\nc\n esflatau=a(9,i)\n do n=8,1,-1\n esflatau=esflatau*(t-t0) + a(n,i)\n enddo\nc\n end\nc------------------------------------------------------------------------\n real*8 function qs(t,p)\nc\nc Compute saturation specific humidity qs [g/kg]\nc at temperature t [K] and pressure p [mb]\nc use Bohren+Albrecht p. 186\nc \n real*8 t,p\n external es\n\n Rv=461.5\n Rd=287.04\n eps=Rd/Rv\nc\n ess=es(t)\n qs=eps*ess/p *1.e3\nc\n end\nc------------------------------------------------------------------------\n real*8 function qsflatau(t,p,i)\nc\nc Compute saturation specific humidity qs [g/kg]\nc at temperature t [K] and pressure p [mb]\nc Use 8th oRder polynomial fit of Flatau et al (1992), Table 4\nc\nc i=1 => sat. mix. rat. over water (valid -85C < t < 70C)\nc i=2 => sat. mix. rat. over ice (valid -90C < t < 0C)\nc\n real*8 t,p\n Rv=461.5\n Rd=287.04\n eps=Rd/Rv*1.e3\nc\n es=esflatau(t,i)\n qsflatau=eps*es/p\nc\n end\nc------------------------------------------------------------------------\n real*8 function ws(t,p)\nc\nc Compute saturation water vapor mass mixing ratio ws [g/kg]\nc at temperature t [K] and pressure p [mb]\nc use Bohren+Albrecht p. 186\nc \n real*8 t,p\n external es\n\n Rv=461.5\n Rd=287.04\n eps=Rd/Rv\nc\n ess=es(t)\n ws=eps*ess/(p-ess) *1.e3\nc\n end\nc------------------------------------------------------------------------\n real*8 function wsflatau(t,p,i)\nc\nc Compute saturation water vapor mass mixing ratio ws [g/kg]\nc at temperature t [K] and pressure p [mb]\nc Use 8th oRder polynomial fit of Flatau et al (1992), Table 4\nc\nc i=1 => sat. mix. rat. over water (valid -85C < t < 70C)\nc i=2 => sat. mix. rat. over ice (valid -90C < t < 0C)\nc\n real*8 t,p\n Rv=461.5\n Rd=287.04\n eps=Rd/Rv\nc\n es=esflatau(t,i)\n wsflatau=eps*es/(p-es) * 1.e3\nc\n end\nc------------------------------------------------------------------------\n real*8 function pdryadiab(t,theta,q)\nc\nc compute pressure level pdryadiab [mb] at which temperature is t [K]\nc on the dry (i.e. unsaturated) adiabat identified by \nc potential temperature theta [K] and mixing ratio q [g/kg].\nc Use Bolton eqn (7) \nc\n oneoverk=3.504 ! Cp/R_(dry air)\n r = q/(1.e3 - q) * 1.e3 ! water vap. mixing ratio [g/kg]\nc\n pdryadiab=1000.*(t/theta)**( oneoverk/(1.-0.28e-3*r) )\nc\n end\nc------------------------------------------------------------------------\n real*8 function tdryadiab(theta,p,q)\nc\nc Compute temperature [K] at level p [mb] \nc on the dry (i.e. unsaturated) adiabat identified by \nc potential temperature theta [K] and mixing ratio q [g/kg].\nc Use Bolton eqn (7) \nc\n real*8 theta,p,q\n ak=0.2854 ! R_(dry air)/Cp\n r = q/(1.e3 - q) * 1.e3 ! water vap. mixing ratio [g/kg]\nc\n tdryadiab=theta*(1000./p)**( -ak*(1.-0.28e-3*r) )\nc \n end\nc------------------------------------------------------------------------\n real*8 function tmoistadiab(thetaes,p)\nc\nc Compute temperature [K] at level p [mb] \nc on the moist (i.e. saturated) pseudo-adiabat identified \nc by saturation equivalent potential temperature thetaes [K].\nc Do it by varying t until \nc delthetae := thetaes - thetae(t,p,qs(t,p)) = 0\nc Use Bolton, eqn (43)\nc\n external delthetae,ridder\n real*8 thetaes,p,params(10)\n logical success\nc\n params(1)=thetaes\n params(2)=p\nc\nc bracket zero crossing to within 2K\n tmin=50.\n tmax=51.\n f1=delthetae(params,tmin)\n f2=delthetae(params,tmax)\n 1 continue\n if(tmax.gt.500.) goto 2\n if(f1*f2.lt.0.) goto 3\n tmax=tmax+1.\n f2=delthetae(params,tmax)\n goto 1\n 2 stop 'tmoistadiab(): cannot bracket root'\n 3 continue\n tmin=tmax-2.\nc\nc refine estimate using Ridder's method \n tmoistadiab=ridder(success,delthetae,params,tmin,tmax,0.0001)\n if (.not.success) stop 'tmoistadiab(): root not bracketed'\nc\n end\nc-----------------------------------------------------------------------\n real*8 function delthetae(params,t)\n external qs,thetae\n real*8 t,params(10)\n\n thetaes = params(1)\n p = params(2)\n q = qs(t,p)\n delthetae = thetaes - thetae(t,p,q)\n\n end\nc------------------------------------------------------------------------\n real*8 function ridder(success,func,params,xmin,xmax,acc)\nc\nc Find zero crossing of func(x) in range xmin < x < xmax with accuracy acc\nc Use Ridder's method (Numerical Recipes)\nc\n external func\n real*8 params(10),xmin,xmax,acc\n logical success\nc\n maxit=60 ! max number of iterations\n success=.true.\nc\n fl=func(params,xmin)\n fh=func(params,xmax)\nc\n if((fl.gt.0..and.fh.lt.0.).or.(fl.lt.0..and.fh.gt.0.))then\n xl=xmin\n xh=xmax\n ridder=-1.11e30\n do 11 j=1,maxit\n xm=0.5*(xl+xh)\n fm=func(params,xm)\n s=sqrt(fm**2-fl*fh)\n if(s.eq.0.)return\n xnew=xm+(xm-xl)*(sign(1.,fl-fh)*fm/s)\n if (abs(xnew-ridder).le.acc) return\n ridder=xnew\n fnew=func(params,ridder)\n if (fnew.eq.0.) return\n if(sign(fm,fnew).ne.fm) then\n xl=xm\n fl=fm\n xh=ridder\n fh=fnew\n else if(sign(fl,fnew).ne.fl) then\n xh=ridder\n fh=fnew\n else if(sign(fh,fnew).ne.fh) then\n xl=ridder\n fl=fnew\n else\n stop 'never get here in ridder'\n endif\n if(abs(xh-xl).le.acc) return\n11 continue\n stop 'ridder exceed maximum iterations maxit'\n else if (fl.eq.0.) then\n ridder=xmin\n else if (fh.eq.0.) then\n ridder=xmax\n else\n success=.false.\n endif\nc\n end\n\n\n", "meta": {"hexsha": "2da08b506b3aef98bd716a80e7b3a8548133bc74", "size": 9300, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/convection/emanuel/src/thermodyn.f", "max_stars_repo_name": "CliMT/climt-legacy", "max_stars_repo_head_hexsha": "adbd4fe77426c90deb8d2c046a2f3dc3b72df89e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/convection/emanuel/src/thermodyn.f", "max_issues_repo_name": "CliMT/climt-legacy", "max_issues_repo_head_hexsha": "adbd4fe77426c90deb8d2c046a2f3dc3b72df89e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/convection/emanuel/src/thermodyn.f", "max_forks_repo_name": "CliMT/climt-legacy", "max_forks_repo_head_hexsha": "adbd4fe77426c90deb8d2c046a2f3dc3b72df89e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.2674772036, "max_line_length": 77, "alphanum_fraction": 0.5203225806, "num_tokens": 3010, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513648201266, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6892892121308266}} {"text": "program test\n\tuse constants\n\tuse mylib\n\timplicit none\n\t\n\tinteger, parameter :: N = 1000\n\treal, dimension(N) :: x\n\tinteger :: i=0\n\t\n\tcall linspace(0., 10*PI, N, x)\n\topen(unit=10, file=\"data.dat\", status=\"replace\", action=\"write\")\n\tdo i=1,N\n\t\twrite(10,*) x(i), (sin(10*x(i)) + sin(15*x(i)))\n\tenddo\n\tclose(10)\nend program test", "meta": {"hexsha": "42d2d90f9b6c697cef596c4ca297966eeeb3734d", "size": 323, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "testing.f03", "max_stars_repo_name": "swapnilpravin/libfft", "max_stars_repo_head_hexsha": "e0d8cc6e16df0b7732f5f3c54654f4d3c6c4b5ff", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "testing.f03", "max_issues_repo_name": "swapnilpravin/libfft", "max_issues_repo_head_hexsha": "e0d8cc6e16df0b7732f5f3c54654f4d3c6c4b5ff", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "testing.f03", "max_forks_repo_name": "swapnilpravin/libfft", "max_forks_repo_head_hexsha": "e0d8cc6e16df0b7732f5f3c54654f4d3c6c4b5ff", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.1875, "max_line_length": 65, "alphanum_fraction": 0.6377708978, "num_tokens": 111, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513620489619, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6892892099995787}} {"text": "c\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc . .\nc . copyright (c) 1998 by UCAR .\nc . .\nc . University Corporation for Atmospheric Research .\nc . .\nc . all rights reserved .\nc . .\nc . .\nc . SPHEREPACK .\nc . .\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc\nc\nc\nc this code tests subroutine gaqd for computing \nc the Gauss Legendre points and weights in file gaqd.f\nc It tests only the april 2002 version and not the\nc older version in file gaqd.old.f\nc gauss points and weights are computed using newtons method\nc with equally spaced points as first guess. Points are\nc computed as theta_i where x_i = cos(theta_i)\nc the method is discussed in \"On computing the Gauss_Legendre\nc points and weights\" by Paul N Swarztrauber, accepted for \nc publication in the SIAM journal of scientific computing.\nc April 2002\nc\n program testint\n parameter (nlat=63)\n double precision theta(nlat),wts(nlat),work(nlat+2),\n 1 dtheta(nlat),dwts(nlat),dw(nlat+1)\n double precision dwmx,tmax,dwmax,dtmax\n dimension stheta(nlat),swts(nlat),swork(nlat+1)\n dimension diff(nlat),t1(2),t2(2)\n double precision sumw\nc\n lwork = nlat+1\n hold = etime(t1)\n hold = t1(1)\n call gsqd(nlat,theta,wts,work,lwork,ierror)\n tdoub = etime(t1)\n tdoub = t1(1)-hold\n if(ierror .ne. 0) write(6,4) ierror\n 4 format(' ierror=',i5) \n write(*,739) tdoub\n 739 format(' tdoub ',1pe15.6)\nc\nc compare double with double\nc\n ldw = nlat+2\n hold = etime(t1)\n hold = t1(1)\n call gaqd(nlat,dtheta,dwts,dw,ldw,ierror)\n tdoub = etime(t1)\n tdoub = t1(1)-hold\n if(ierror .ne. 0) write(6,30) ierror\n 30 format(' ierror=',i5) \n write(*,31) tdoub\n 31 format(' tdoub gaqd',1pe15.6)\nc \n dwmx = 0.0d0\n tmax = 0.0d0\n dwmax = 0.0d0\n dtmax = 0.0d0\n ido = (nlat+1)/2\n do 32 i=1,ido\n dtmax = max(dtmax,dabs(theta(i)-dtheta(i)))\n dwmax = max(dwmax,dabs(wts(i)-dwts(i)))\n tmax = max(tmax,abs(theta(i)))\n dwmx = max(dwmx,abs(wts(i)))\n 32 continue\n dtmax = dtmax/tmax\n dwmax = dwmax/dwmx\n write(*,33) nlat,dtmax,dwmax\n 33 format(' nlat',i6,' points ',1pd15.6,' weights ',d15.6)\nc\n sumw = 0.\n do i=1,nlat\n sumw = sumw+wts(i)\n end do\n write(*,638) sumw\n 638 format(' sumw ',1pd39.30)\nc if(0.eq.0) go to 671\n hold = etime(t2)\n hold = t2(1)\n lwork = nlat+2\n call sgaqd(nlat,stheta,swts,swork,lwork,ierror)\n tsing = etime(t2)\n tsing = t2(1)-hold\n if(ierror .ne. 0) write(6,5) ierror\n 5 format(' iserror=',i5) \n sums = 0.\n do i=1,nlat\n sums = sums+swts(i)\n end do\n write(*,636) sums\n 636 format(' sums ',1pe24.15)\n dmax = 0.\n wmax = 0.\n rmax = 0.\n ido = (nlat+1)/2\n do 6 i=1,ido\n diff(i) = wts(i)-swts(i)\n dmax = max(dmax,abs(diff(i)))\n wmax = max(wmax,abs(swts(i)))\n rerr = abs(diff(i)/swts(i))\n if(rerr.gt.rmax) then\n rmax = rerr\n irm = i\n end if\nc if(i.lt.121) write(*,27) wts(i),swts(i),rerr\n 27 format(' wts ',1pd15.6,' swts ',e15.6,' rpter ',e15.6)\n 6 continue\nc write(*,7) (diff(i),i=nlat-25,nlat)\n 7 format(' diff in weights'/(1p8e10.3))\n dmax = dmax/wmax\n write(*,9) nlat,irm,dmax,rmax\n 9 format(' weights: nlat ',i6,' irele ',i6,\n 1 ' dmax ',1pe15.6,' rmax ',1pe15.6)\n dmax = 0.\n pmax = 0.\n rmax = 0.\n do 10 i=1,ido\n diff(i) = theta(i)-stheta(i)\n dmax = max(dmax,abs(diff(i)))\n pmax = max(pmax,abs(stheta(i)))\n rerr = abs(diff(i)/stheta(i))\n if(rerr.gt.rmax) then\n rmax = rerr\n irm = i\n end if\n 10 continue\nc write(*,11) (diff(i),i=nlat-25,nlat)\n 11 format(' diff in points'/(1p8e10.3))\n dmax = dmax/pmax\n write(*,12) nlat,irm,dmax,rmax\n 12 format(' points: nlat ',i6,' irele ',i6,\n 1 ' dmax ',1pe15.6,' rmax ',1pe15.6)\n dmax = 0.\n do 110 i=1,nlat\n diff(i) = dcos(theta(i))-cos(stheta(i))\n dmax = max(dmax,abs(diff(i)))\n 110 continue\nc write(*,111) (diff(i),i=nlat-25,nlat)\n 111 format(' diff in points'/(1p8e10.3))\n write(*,112) dmax\n 112 format(' max difference in mu',1pe15.6)\n write(*,1) nlat,tsing,tdoub\n 1 format(' nlat',i6,' tsing',1pe15.6,' tdoub',e15.6)\n 671 end\nc\nc a single precision version of gaqd.\nc gauss points and weights are computed using newtons method\nc with equally spaced points as first guess. Points are\nc computed as theta_i where x_i = cos(theta_i)\nc the method is discussed in \"On computing the Gauss_Legendre\nc points and weights\" by Paul N Swarztrauber, accepted for \nc publication in the SIAM journal of scientific computing.\nc April 2002\nc\n subroutine gsqd(nlat,theta,wts,dwork,ldwork,ierror)\nc\nc\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc . .\nc . copyright (c) 2001 by ucar .\nc . .\nc . university corporation for atmospheric research .\nc . .\nc . all rights reserved .\nc . .\nc . .\nc . spherepack 3.0 .\nc . .\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc\nc\nc\nc subroutine gsqd computes the nlat gaussian colatitudes and weights\nc in double precision. The colatitudes are in radians and lie in the\nc in the interval (0,pi).\nc\nc input parameters\nc\nc nlat the number of gaussian colatitudes in the interval (0,pi)\nc (between the two poles). nlat must be greater than zero.\nc\nc dwork a double precision temporary work space.\nc\nc ldwork the length of the work space in the routine calling gsqd\nc ldwork must be at least nlat+1.\nc\nc output parameters\nc\nc theta a double precision vector of length nlat containing the\nc nlat gaussian colatitudes on the sphere in increasing radians\nc in the interval (0,pi).\nc\nc wts a double precision vector of length nlat containing the\nc nlat gaussian weights.\nc\nc ierror = 0 no errors\nc = 1 if ldwork.lt.nlat+1\nc = 2 if nlat.le.0\nc\nc *****************************************************************\nc\n dimension dwork(nlat+1),theta(nlat),wts(nlat)\n double precision pis2,x,theta,wts,dwork\n ierror = 1\nc\nc check work space length\nc\n if (ldwork.lt.nlat+1) return\n ierror = 2\n if (nlat.le.0) return\n ierror = 0\nc\nc compute weights and points analytically when nlat=1,2\nc\n if (nlat.eq.1) then\n theta(1) = dacos(0.0d0)\n wts(1) = 2.d0\n return\n end if\n if (nlat.eq.2) then\n x = dsqrt(1.0d0/3.0d0)\n theta(1) = dacos(x)\n theta(2) = dacos(-x)\n wts(1) = 1.d0\n wts(2) = 1.d0\n return\n end if\nc\nc compute points\nc\n call gsqd1(nlat,theta,dwork)\nc\nc compute weights\nc\n call egwts(nlat,theta,wts,dwork)\nc\nc extend points and weights via symmetries\nc\n pis2 = 4.0d0*datan(1.0d0)\n ns2 = nlat/2\n do i=1,ns2\n wts(nlat-i+1) = wts(i)\n theta(nlat-i+1) = pis2-theta(i)\n end do\n return\n end\nc\n subroutine gsqd1(nlat,theta,cp)\n double precision theta((nlat+1)/2),cp(nlat/2+1)\n double precision pi,pis2,dtheta,dthalf,\n 1 cmax,dcor,pb,dpb,sgnd,zero,zlast\nc\n eps = sqrt(dzeps(1.0d0))\n eps = eps*sqrt(eps)\n pis2 = 2.0d0*datan(1.0d0)\n pi = pis2+pis2 \n theta(1) = pis2 \n if(nlat.eq.1) go to 30\n ns2 = nlat/2\n nhalf = (nlat+1)/2\nc\n call dlfcz (nlat,cp)\nc\nc check fourier-legendre coefficients\nc\n sum = 0.\n do i=1,ns2+1\n sum = sum+cp(i) \n end do\n sum = sum/ns2\nc write(*,689) sum\n 689 format(' check on dble f-l coefficients ',1pe15.6)\nc\n dtheta = pis2/nhalf\n dthalf = dtheta/2.0d0\n cmax = .2d0*dtheta\n if(mod(nlat,2).ne.0) then\n theta(nhalf) = pis2\n zero = pis2-dtheta\n nix = nhalf-1\n else\n zero = pis2-dthalf\n nix = nhalf\n end if\n 9 it = 0\n 10 it = it+1\n zlast = zero\nc\nc newton iterations to convergence\nc\n call lft (0,nlat,zero,cp,pb)\n call dlft (0,nlat,zero,cp,dpb)\n dcor = pb/dpb\n sgnd = 1.0d0\n if(dcor .ne. 0.0d0) sgnd = dcor/dabs(dcor)\nc write(*,2) nix,zero,theta(nix),dcor,cmax,sgnd\n 2 format(i7,1p5d15.6)\n dcor = sgnd*min(dabs(dcor),cmax)\n zero = zero-dcor\n if(dabs(zero-zlast).gt.eps*dabs(zero)) go to 10\n theta(nix) = zero\n nix = nix-1\n if(nix.eq.0) go to 30\n if(nix.eq.nhalf-1) zero = 3.0d0*zero-pi\n if(nix.lt.nhalf-1) zero = zero+zero-theta(nix+2)\n go to 9\n 30 return\n end\n subroutine egwts(n,theta,wts,work)\nc\nc computes gauss weights as described in swarztrauber\nc and spotz, generalized harmonic transforms\nc\n double precision theta(n),wts(n),work(n+1)\nc\n call egwts1(n,theta,wts,work,work(n/2+2))\n return\n end\n subroutine egwts1(n,theta,wts,dcp,cp)\n double precision theta((n+1)/2),wts((n+1)/2),cp((n-1)/2+1),\n 1 dcp(n/2+1),fn,sqnn,pb,dpb \n fn = n\n sqnn = dsqrt((fn+fn-1)*(fn+fn+1))\n call dlfcz (n-1,cp)\n call dlfcz (n,dcp)\n nhalf = (n+1)/2\n do i=1,nhalf\n call lft (0,n-1,theta(i),cp,pb)\n call dlft (0,n,theta(i),dcp,dpb)\n wts(i) = -sqnn*dsin(theta(i))/(fn*pb*dpb)\n end do\n return\n end\n subroutine lfc (m,n,cp)\nc\n double precision cp,fnum,fden,fnmh,a1,b1,c1,cp2,fnnp1,fnmsq,fk,\n 1 t1,t2,pm1,sc10,sc20,sc40\n dimension cp(n/2+1)\n parameter (sc10=1024.d0)\n parameter (sc20=sc10*sc10)\n parameter (sc40=sc20*sc20)\nc\n cp(1) = 0.\n ma = iabs(m)\n if(ma .gt. n) return\n if(n-1) 2,3,5\n 2 cp(1) = dsqrt(2.d0)\n return\n 3 if(ma .ne. 0) go to 4\n cp(1) = dsqrt(1.5d0)\n return\n 4 cp(1) = dsqrt(.75d0)\n if(m .eq. -1) cp(1) = -cp(1)\n return\n 5 if(mod(n+ma,2) .ne. 0) go to 10\n nmms2 = (n-ma)/2\n fnum = n+ma+1\n fnmh = n-ma+1\n pm1 = 1.d0\n go to 15\n 10 nmms2 = (n-ma-1)/2\n fnum = n+ma+2\n fnmh = n-ma+2\n pm1 = -1.d0\nc t1 = 1.\nc t1 = 2.d0**(n-1)\nc t1 = 1.d0/t1\n 15 t1 = 1.d0/sc20\n nex = 20\n fden = 2.d0\n if(nmms2 .lt. 1) go to 20\n do 18 i=1,nmms2\n t1 = fnum*t1/fden\n if(t1 .gt. sc20) then\n t1 = t1/sc40\n nex = nex+40\n end if\n fnum = fnum+2.\n fden = fden+2.\n 18 continue\n 20 t1 = t1/2.d0**(n-1-nex)\n if(mod(ma/2,2) .ne. 0) t1 = -t1\n t2 = 1. \n if(ma .eq. 0) go to 26\n do 25 i=1,ma\n t2 = fnmh*t2/(fnmh+pm1)\n fnmh = fnmh+2.\n 25 continue\n 26 cp2 = t1*dsqrt((n+.5d0)*t2)\n fnnp1 = n*(n+1)\n fnmsq = fnnp1-2.d0*ma*ma\n l = (n+1)/2\n if(mod(n,2) .eq. 0 .and. mod(ma,2) .eq. 0) l = l+1\n cp(l) = cp2\n if(m .ge. 0) go to 29\n if(mod(ma,2) .ne. 0) cp(l) = -cp(l)\n 29 if(l .le. 1) return\n fk = n\n a1 = (fk-2.)*(fk-1.)-fnnp1\n b1 = 2.*(fk*fk-fnmsq)\n cp(l-1) = b1*cp(l)/a1\n 30 l = l-1\n if(l .le. 1) return\n fk = fk-2.\n a1 = (fk-2.)*(fk-1.)-fnnp1\n b1 = -2.*(fk*fk-fnmsq)\n c1 = (fk+1.)*(fk+2.)-fnnp1\n cp(l-1) = -(b1*cp(l)+c1*cp(l+1))/a1\n go to 30\n end\n subroutine lft (m,n,theta,cp,pb)\n double precision cp(*),pb,theta,cdt,sdt,cth,sth,chh\n cdt = dcos(theta+theta)\n sdt = dsin(theta+theta)\n nmod=mod(n,2)\n mmod=mod(m,2)\n if(nmod)1,1,2\n1 if(mmod)3,3,4\nc\nc n even, m even\nc\n3 kdo=n/2\n pb = .5*cp(1)\n if(n .eq. 0) return\n cth = cdt\n sth = sdt\n do 170 k=1,kdo\nc pb = pb+cp(k+1)*dcos(2*k*theta)\n pb = pb+cp(k+1)*cth\n chh = cdt*cth-sdt*sth\n sth = sdt*cth+cdt*sth\n cth = chh\n 170 continue\n return\nc\nc n even, m odd\nc\n 4 kdo = n/2\n pb = 0.\n cth = cdt\n sth = sdt\n do 180 k=1,kdo\nc pb = pb+cp(k)*dsin(2*k*theta)\n pb = pb+cp(k)*sth\n chh = cdt*cth-sdt*sth\n sth = sdt*cth+cdt*sth\n cth = chh\n 180 continue\n return\n2 if(mmod)13,13,14\nc\nc n odd, m even\nc\n13 kdo = (n+1)/2\n pb = 0.\n cth = dcos(theta)\n sth = dsin(theta)\n do 190 k=1,kdo\nc pb = pb+cp(k)*dcos((2*k-1)*theta)\n pb = pb+cp(k)*cth\n chh = cdt*cth-sdt*sth\n sth = sdt*cth+cdt*sth\n cth = chh\n 190 continue\n return\nc\nc n odd, m odd\nc\n 14 kdo = (n+1)/2\n pb = 0.\n cth = dcos(theta)\n sth = dsin(theta)\n do 200 k=1,kdo\nc pb = pb+cp(k)*dsin((2*k-1)*theta)\n pb = pb+cp(k)*sth\n chh = cdt*cth-sdt*sth\n sth = sdt*cth+cdt*sth\n cth = chh\n 200 continue\n return\n end\n subroutine dlft (m,n,theta,cp,pb)\nc\nc computes the derivative of pmn(theta) with respect to theta\nc\n dimension cp(1)\n double precision cp,pb,theta,cdt,sdt,cth,sth,chh\n cdt = dcos(theta+theta)\n sdt = dsin(theta+theta)\n nmod=mod(n,2)\n mmod=mod(abs(m),2)\n if(nmod)1,1,2\n1 if(mmod)3,3,4\nc\nc n even, m even\nc\n3 kdo=n/2\n pb = 0.d0\n if(n .eq. 0) return\n cth = cdt\n sth = sdt\n do 170 k=1,kdo\nc pb = pb+cp(k+1)*dcos(2*k*theta)\n pb = pb-2.d0*k*cp(k+1)*sth\n chh = cdt*cth-sdt*sth\n sth = sdt*cth+cdt*sth\n cth = chh\n 170 continue\n return\nc\nc n even, m odd\nc\n 4 kdo = n/2\n pb = 0.\n cth = cdt\n sth = sdt\n do 180 k=1,kdo\nc pb = pb+cp(k)*dsin(2*k*theta)\n pb = pb+2.d0*k*cp(k)*cth\n chh = cdt*cth-sdt*sth\n sth = sdt*cth+cdt*sth\n cth = chh\n 180 continue\n return\n2 if(mmod)13,13,14\nc\nc n odd, m even\nc\n13 kdo = (n+1)/2\n pb = 0.\n cth = dcos(theta)\n sth = dsin(theta)\n do 190 k=1,kdo\nc pb = pb+cp(k)*dcos((2*k-1)*theta)\n pb = pb-(2.d0*k-1)*cp(k)*sth\n chh = cdt*cth-sdt*sth\n sth = sdt*cth+cdt*sth\n cth = chh\n 190 continue\n return\nc\nc n odd, m odd\nc\n 14 kdo = (n+1)/2\n pb = 0.\n cth = dcos(theta)\n sth = dsin(theta)\n do 200 k=1,kdo\nc pb = pb+cp(k)*dsin((2*k-1)*theta)\n pb = pb+(2.d0*k-1)*cp(k)*cth\n chh = cdt*cth-sdt*sth\n sth = sdt*cth+cdt*sth\n cth = chh\n 200 continue\n return\n end\n subroutine dlfcz(n,cp)\nc\nc computes the fourier coefficients of the legendre\nc polynomials. n is the degree and integer(n/2+1)\nc coefficients are returned in cp\nc\n double precision cp(n/2+1)\n double precision cn,t1,t2,t3,t4,coef,fi\nc\n cn = 2.0d0\n write(*,9) cn\n 9 format(' check1 on dble cn ',1pd20.11)\n if(n.gt.0) then\n ic = 0\n fi = 0.0d0\n do i=1,n\n fi = fi+2.0d0 \n cn = (1.0d0-1.0d0/fi**2)*cn\n if(dabs(cn).gt. 5.0d0.and.ic.eq.0) then\n ic = 1\n write(*,7) i,cn\n 7 format(' i ',i7,' check3 on cn',1pd15.6)\n end if \n end do\n end if\n write(*,8) cn\n 8 format(' check2 on dble cn ',1pd20.11)\n cn = dsqrt(cn)\n ncp = n/2+1\n t1 = -1.0d0\n t2 = n+1.0d0\n t3 = 0.\n t4 = n+n+1.0d0\n cp(ncp) = cn\n coef = 1.0d0\n write(*,11) cn\n 11 format(' check on dble cn ',1pd20.11)\nc do j = ncp-1,1,-1\n j = ncp\n 10 j = j-1 \n t1 = t1+2.0d0\n t2 = t2-1.0d0\n t3 = t3+1.0d0\n t4 = t4-2.0d0\n coef = (t1*t2)/(t3*t4)*coef\n cp(j) = coef*cn\n if(j.gt.1) go to 10\nc end do\n return\n end\nc\n subroutine sgaqd(nlat,theta,wts,w,lwork,ierror)\nc\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc . .\nc . copyright (c) 2001 by ucar .\nc . .\nc . university corporation for atmospheric research .\nc . .\nc . all rights reserved .\nc . .\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc\nc February 2002\nc \nc gauss points and weights are computed using the fourier-newton\nc described in \"on computing the points and weights for \nc gauss-legendre quadrature\", paul n. swarztrauber, siam journal \nc on scientific computing that has been accepted for publication.\nc This routine is faster and more accurate than older program \nc with the same name.\nc\nc subroutine sgaqd computes the nlat gaussian colatitudes and\nc weights in single precision. the colatitudes are in radians\nc and lie in the interval (0,pi).\nc\nc input parameters\nc\nc nlat the number of gaussian colatitudes in the interval (0,pi)\nc (between the two poles). nlat must be greater than zero.\nc\nc w unused variable that permits a simple exchange with the\nc old routine with the same name in spherepack.\nc\nc lwork unused variable that permits a simple exchange with the\nc old routine with the same name in spherepack.\nc\nc output parameters\nc\nc theta a vector of length nlat containing the nlat gaussian \nc colatitudes on the sphere in increasing radians\nc in the interval (0,pi).\nc\nc wts a vector of length nlat containing the\nc nlat gaussian weights.\nc\nc ierror = 0 no errors\nc = 1 if nlat.le.0\nc\nc *****************************************************************\nc\n dimension theta(nlat),wts(nlat)\nc\nc check work space length\nc\n ierror = 1\n if (nlat.le.0) return\n ierror = 0\nc\nc compute weights and points analytically when nlat=1,2\nc\n if (nlat.eq.1) then\n theta(1) = acos(0.0d0)\n wts(1) = 2.0\n return\n end if\n if (nlat.eq.2) then\n x = sqrt(1.0/3.0)\n theta(1) = acos(x)\n theta(2) = acos(-x)\n wts(1) = 1.0\n wts(2) = 1.0\n return\n end if\n eps = sqrt(zeps(1.0))\n eps = eps*sqrt(eps)\n pis2 = 2.0*atan(1.0)\n pi = pis2+pis2 \n mnlat = mod(nlat,2)\n ns2 = nlat/2\n nhalf = (nlat+1)/2\n idx = ns2+2\nc\n call lfcz (nlat,cz,theta(ns2+1),wts(ns2+1))\nc\n dtheta = pis2/nhalf\n dthalf = dtheta/2.0\n cmax = .2*dtheta\nc\nc estimate first point next to theta = pi/2\nc\n if(mnlat.ne.0) then\n zprev = pis2\n zero = pis2-dtheta\n nix = nhalf-1\n else\n zero = pis2-dthalf\n nix = nhalf\n end if\n itmax = 0\n 9 it = 0\n 10 it = it+1\n zlast = zero\nc\nc newton iterations\nc\n call slpdp (nlat,zero,cz,theta(ns2+1),wts(ns2+1),pb,dpb)\n dcor = pb/dpb\n sgnd = 1.0\n if(dcor .ne. 0.0) sgnd = dcor/abs(dcor)\n dcor = sgnd*min(abs(dcor),cmax)\n zero = zero-dcor\n if(abs(zero-zlast).gt.eps*abs(zero)) go to 10\n theta(nix) = zero\n zhold = zero\nc wts(nix) = (nlat+nlat+1)/(dpb*dpb)\nc \nc yakimiw's formula permits using old pb and dpb\nc\n wts(nix) = (nlat+nlat+1)/(dpb+pb*cos(zlast)/sin(zlast))**2\n nix = nix-1\n if(nix.eq.0) go to 30\n if(nix.eq.nhalf-1) zero = 3.0*zero-pi\n if(nix.lt.nhalf-1) zero = zero+zero-zprev\n zprev = zhold \n go to 9\nc\nc extend points and weights via symmetries\nc\n 30 if(mnlat.ne.0) then\n theta(nhalf) = pis2\n call slpdp (nlat,pis2,cz,theta(ns2+1),wts(ns2+1),pb,dpb)\n wts(nhalf) = (nlat+nlat+1)/(dpb*dpb)\n end if\n do i=1,ns2\n wts(nlat-i+1) = wts(i)\n theta(nlat-i+1) = pi-theta(i)\n end do\n sum = 0.\n do i=1,nlat\n sum = sum+wts(i)\n end do\n do i=1,nlat\n wts(i) = 2.0*wts(i)/sum\n end do\n return\n end\n subroutine lfcz(n,cz,cp,dcp)\nc\nc computes the fourier coefficients of the legendre\nc polynomial p_n^0 and its derivative. \nc n is the degree and n/2 or (n+1)/2\nc coefficients are returned in cp depending on whether\nc n is even or odd. The same number of coefficients\nc are returned in dcp. For n even the constant \nc coefficient is returned in cz. \nc\n dimension cp((n+1)/2),dcp((n+1)/2)\n ncp = (n+1)/2\n t1 = -1.0\n t2 = n+1.0\n t3 = 0.\n t4 = n+n+1.0\n if(mod(n,2).eq.0) then\n cp(ncp) = 1.0\n do j = ncp,2,-1\n t1 = t1+2.0\n t2 = t2-1.0\n t3 = t3+1.0\n t4 = t4-2.0\n cp(j-1) = (t1*t2)/(t3*t4)*cp(j)\n end do\n t1 = t1+2.0\n t2 = t2-1.0\n t3 = t3+1.0\n t4 = t4-2.0\n cz = (t1*t2)/(t3*t4)*cp(1)\n do j=1,ncp\n dcp(j) = (j+j)*cp(j)\n end do\n else\n cp(ncp) = 1.0\n do j = ncp-1,1,-1\n t1 = t1+2.0\n t2 = t2-1.0\n t3 = t3+1.0\n t4 = t4-2.0\n cp(j) = (t1*t2)/(t3*t4)*cp(j+1)\n end do\n do j=1,ncp\n dcp(j) = (j+j-1)*cp(j)\n end do\n end if\nc write(*,23) (cp(j),dcp(j),j=1,ncp)\n 23 format(' coefficients '/(1p4e15.6))\n return\n end\n subroutine slpdp (n,theta,cz,cp,dcp,pb,dpb)\nc\nc computes pn(theta) and its derivative dpb(theta) with \nc respect to theta\nc\n dimension cp(n/2+1),dcp(n/2+1)\nc\n fn = float(n)\n cdt = cos(theta+theta)\n sdt = sin(theta+theta)\n if(mod(n,2) .eq.0) then\nc\nc n even\nc\n kdo = n/2\n pb = .5*cz\n dpb = 0.0\n if(n .gt. 0) then\n cth = cdt\n sth = sdt\n do 170 k=1,kdo\nc pb = pb+cp(k)*cos(2*k*theta)\n pb = pb+cp(k)*cth\nc dpb = dpb-(k+k)*cp(k)*sin(2*k*theta)\n dpb = dpb-dcp(k)*sth\n chh = cdt*cth-sdt*sth\n sth = sdt*cth+cdt*sth\n cth = chh\n 170 continue\n end if\n else\nc\nc n odd\nc\n kdo = (n+1)/2\n pb = 0.\n dpb = 0.\n cth = cos(theta)\n sth = sin(theta)\n do 190 k=1,kdo\nc pb = pb+cp(k)*cos((2*k-1)*theta)\n pb = pb+cp(k)*cth\nc dpb = dpb-(k+k-1)*cp(k)*sin((2*k-1)*theta)\n dpb = dpb-dcp(k)*sth\n chh = cdt*cth-sdt*sth\n sth = sdt*cth+cdt*sth\n cth = chh\n 190 continue\n end if\n return\n end\n real function zeps (x)\nc\nc estimate unit roundoff in quantities of size x.\nc\nc\nc this program should function properly on all systems\nc satisfying the following two assumptions,\nc 1. the base used in representing floating point\nc numbers is not a power of three.\nc 2. the quantity a in statement 10 is represented to \nc the accuracy used in floating point variables\nc that are stored in memory.\nc the statement number 10 and the go to 10 are intended to\nc force optimizing compilers to generate code satisfying \nc assumption 2.\nc under these assumptions, it should be true that,\nc a is not exactly equal to four-thirds,\nc b has a zero for its last bit or digit,\nc c is not exactly equal to one,\nc eps measures the separation of 1.0 from\nc the next larger floating point number.\nc the developers of eispack would appreciate being informed\nc about any systems where these assumptions do not hold.\nc\nc this version dated 4/6/83.\nc\n a = 4.0/3.0\n 10 b = a - 1.0\n c = b + b + b\n eps = abs(c-1.0)\n if (eps .eq. 0.0) go to 10\n zeps = eps*abs(x)\n return\n end\nc\n", "meta": {"hexsha": "20ecee612c10664a457208760f04949cb6852fed", "size": 24430, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/drivers/tgaqd.f", "max_stars_repo_name": "jprules321/colas", "max_stars_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/drivers/tgaqd.f", "max_issues_repo_name": "jprules321/colas", "max_issues_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/drivers/tgaqd.f", "max_forks_repo_name": "jprules321/colas", "max_forks_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.2352285396, "max_line_length": 75, "alphanum_fraction": 0.5058534589, "num_tokens": 8990, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677660619633, "lm_q2_score": 0.8128673246376009, "lm_q1q2_score": 0.6892852893777112}} {"text": "! Heat transport in 2D\n!\n! Parallelize the following serial code.\n!\n! $ gfortran -g -O0 -Wall -Wextra -Wpedantic -fcheck=all -fbacktrace heat_serial.f90\n! $ ./a.out < in.txt\nprogram heat_serial\n implicit none\n real, parameter :: alpha = 2.5e-4\n real, dimension(:, :), pointer :: prev_t, next_t, temp_t\n real :: diff_t\n integer :: s, i, time\n\n read *, s\n allocate(prev_t(0:s + 1, 0:s + 1))\n do i = 0, s + 1\n read *, prev_t(i, 0:s + 1)\n end do\n allocate(next_t(0:s + 1, 0:s + 1))\n next_t(:, :) = prev_t(:, :) ! copy boundaries\n\n time = 0\n do\n next_t(1:s, 1:s) = &\n (1.0 - 4.0 * alpha) * prev_t(1:s, 1:s) &\n + alpha * ( prev_t(0:s - 1, 1:s ) &\n + prev_t(2:s + 1, 1:s ) &\n + prev_t(1:s , 0:s - 1) &\n + prev_t(1:s , 2:s + 1) )\n diff_t = maxval(abs(next_t(1:s, 1:s) - prev_t(1:s, 1:s)))\n if (modulo(time, 10000) == 0) then\n print \"(a, i0, a, es12.5)\", \"time = \", time, \", diff_t = \", diff_t\n do i = 0, s + 1\n print \"(*(f4.0, 1x))\", prev_t(i, 0:s + 1)\n end do\n call sleep(1)\n end if\n if (diff_t < epsilon(0.0)) exit\n temp_t => prev_t; prev_t => next_t; next_t => temp_t\n time = time + 1\n end do\n print \"(a, i0)\", \"Final time is \", time\n deallocate(prev_t)\n deallocate(next_t)\nend program heat_serial\n", "meta": {"hexsha": "51753a0ea0d9d4ed74a9b932d982d6efee4a7d71", "size": 1524, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Lecture_14/heat_2d/heat_serial.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_14/heat_2d/heat_serial.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_14/heat_2d/heat_serial.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": 33.1304347826, "max_line_length": 84, "alphanum_fraction": 0.4593175853, "num_tokens": 524, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677660619633, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.6892852874556431}} {"text": "! Program to test array IO. Should print the numbers 1-20 in order\nprogram arrayio\n implicit none\n integer, dimension(5, 4) :: a\n integer i, j\n\n do j=1,4\n a(:, j) = (/ (i + (j - 1) * 5, i=1,5) /)\n end do\n\n write (*,*) a\nend program\n", "meta": {"hexsha": "8c333d437d292d3d11bb9641d3ad4dd9f572dd24", "size": 250, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.fortran-torture/compile/arrayio.f90", "max_stars_repo_name": "best08618/asylo", "max_stars_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-05-02T17:34:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-17T10:15:18.000Z", "max_issues_repo_path": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.fortran-torture/compile/arrayio.f90", "max_issues_repo_name": "best08618/asylo", "max_issues_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "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": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.fortran-torture/compile/arrayio.f90", "max_forks_repo_name": "best08618/asylo", "max_forks_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-27T00:22:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-01T09:41:02.000Z", "avg_line_length": 19.2307692308, "max_line_length": 67, "alphanum_fraction": 0.56, "num_tokens": 96, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677660619633, "lm_q2_score": 0.8128673087708699, "lm_q1q2_score": 0.6892852759232347}} {"text": "subroutine calc_bpf_coef(fl, fh, sample, m, n, h, c, gn)\n use constants, only : pi\n implicit none\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n !!! Butterworth band-pass filter by Saito(1978)\n !!! Input\n !!! fl, fh: low- and high- passband frequency (not normalized)\n !!! sample: sampling sequence (sec)\n !!! m, n: filter order (calculated by calc_bpf_order.f90)\n !!! h(4 * m) : filter coefficient\n !!! gn : gain factor\n !!! \n !!! Author : Masashi Ogiso (masashi.ogiso@gmail.com)\n !!! Reference: Saito, M. (1978) An automatic design algorithm for band selective recursive\n !!! digital filters, Geophysical Exploration, 31(4), 240-263 (In Japanese)\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n integer, intent(IN) :: m, n\n real*8, intent(IN) :: c, fl, fh, sample\n real*8, intent(OUT) :: h(4 * m)\n real*8, intent(OUT) :: gn\n\n real*8 :: g, fj, a1, dp, sigma_fl, sigma_fh, re, ri, wpc, wmc, clh\n complex*16 :: oj, r(2), cq\n integer :: i, j, k\n\n dp = pi / 2.0d0 / dble(n)\n sigma_fl = pi * fl * sample\n sigma_fh = pi * fh * sample\n\n clh = 1.0d0 / (cos(sigma_fl) * cos(sigma_fh))\n g = 1.0d0\n fj = 1.0d0\n k = 0\n\n do j = 1, int(n / 2)\n oj = dcmplx(cos(dp * fj), sin(dp * fj)) * 0.5d0\n fj = fj + 2.0d0\n cq = sqrt(oj ** 2 + c ** 2 * tan(sigma_fl) * tan(sigma_fh))\n r(1) = oj + cq\n r(2) = oj - cq\n g = g * c ** 2\n do i = 1, 2\n re = dble(r(i)) ** 2\n ri = imag(r(i))\n a1 = 1.0d0 / ((c + ri) ** 2 + re)\n g = g * a1\n h(k + 1) = 0.0d0\n h(k + 2) = -1.0d0\n h(k + 3) = 2.0d0 * ((ri - c) * (ri + c) + re) * a1\n h(k + 4) = ((ri - c) ** 2 + re) * a1\n k = k + 4\n enddo\n enddo\n gn = g\n if(n .ne. 2 * int(n / 2)) then\n wpc = c ** 2 * cos(sigma_fh - sigma_fl) * clh\n wmc = - c ** 2 * cos(sigma_fh + sigma_fl) * clh\n a1 = 1.0d0 / (wpc + c)\n gn = g * c * a1\n h(k + 1) = 0.0d0\n h(k + 2) = -1.0d0\n h(k + 3) = 2.0d0 * wmc * a1\n h(k + 4) = (wpc - c) * a1\n endif\n\n return\nend subroutine calc_bpf_coef\n\n", "meta": {"hexsha": "c3b5efce7d5a4222eb815674942f2e6957ab0d55", "size": 2058, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "calc_bpf_coef.f90", "max_stars_repo_name": "mogiso/AmplitudeSourceLocation", "max_stars_repo_head_hexsha": "ad00d36e0b14c0e1262b88c4bc2caf04e0570140", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2020-10-30T10:43:07.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-26T06:21:37.000Z", "max_issues_repo_path": "calc_bpf_coef.f90", "max_issues_repo_name": "mogiso/AmplitudeSourceLocation", "max_issues_repo_head_hexsha": "ad00d36e0b14c0e1262b88c4bc2caf04e0570140", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "calc_bpf_coef.f90", "max_forks_repo_name": "mogiso/AmplitudeSourceLocation", "max_forks_repo_head_hexsha": "ad00d36e0b14c0e1262b88c4bc2caf04e0570140", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-18T12:00:20.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T12:00:20.000Z", "avg_line_length": 29.4, "max_line_length": 104, "alphanum_fraction": 0.48202138, "num_tokens": 839, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632856092016, "lm_q2_score": 0.7431680199891789, "lm_q1q2_score": 0.6891867367768497}} {"text": "\tFUNCTION SND_RCH ( datain, nparm, k, deltaz, ivcord )\nC************************************************************************\nC* SND_RCH\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes the Richardson number for a layer.\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC*\t\tRICH = BFVQ ** 2 / SHRM ** 2\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* SND_RCH ( DATAIN, NPARM, CLEV, IVCORD )\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*\tDATAIN(NPARM,*)\tREAL\t\tStation data\t\t\t*\nC*\tNPARM\t\tINTEGER\t\tNumber of data set parameters\t*\nC*\tCLEV\t\tREAL\t\tVertical level\t\t\t*\nC*\tIVCORD\t\tINTEGER \tVertical coordinate number\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tSND_RCH\t\tREAL\t\tRichardson number\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* K. Brill/NMC\t\t 7/90\t\t\t\t\t\t*\nC* J. Whistler/SSAI\t 4/93\t\tModified for SNDIAG\t\t*\nC************************************************************************\n\tINCLUDE\t\t'GEMPRM.PRM'\n\tINCLUDE\t\t'sndiag.prm'\nC*\n\tREAL datain (*)\nC*\n\tREAL \tstndb (10), stndt (10), stndl (10)\n\tCHARACTER cvalue*20\nC*\n\tINCLUDE\t\t'ERMISS.FNC'\nC------------------------------------------------------------------------\n\tSND_RCH = RMISSD\nC\nC*\tGet information over a depth.\nC\n\tdepth = deltaz * 2.\n\tthtop = datain((k-1+1)*nparm+ITHTV)\n\tthbot = datain((k-1-1)*nparm+ITHTV)\n\ttheta = .5 * ( thtop + thbot )\n\tbvfsqd = ( GRAVTY / theta ) * ( thtop - thbot ) / depth\nC*\n\tutop = datain((k-1+1)*nparm+IUWND)\n\tvtop = datain((k-1+1)*nparm+IVWND)\n\tubot = datain((k-1-1)*nparm+IUWND)\n\tvbot = datain((k-1-1)*nparm+IVWND)\n\tdudz = ( utop - ubot ) / depth\n\tdvdz = ( vtop - vbot ) / depth\n\tshrsqd = ( dudz * dudz + dvdz * dvdz )\n\tIF ( shrsqd .eq. 0.0 ) RETURN\nC*\n\tSND_RCH = bvfsqd / shrsqd \nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "6f41107c9b0da3a624ca0eb2a4bb0373441c4506", "size": 1648, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/programs/sn/sndiag/sndrch.f", "max_stars_repo_name": "oxelson/gempak", "max_stars_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2015-06-03T15:26:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T22:36:03.000Z", "max_issues_repo_path": "gempak/source/programs/sn/sndiag/sndrch.f", "max_issues_repo_name": "oxelson/gempak", "max_issues_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 60, "max_issues_repo_issues_event_min_datetime": "2015-05-11T21:36:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T16:22:42.000Z", "max_forks_repo_path": "gempak/source/programs/sn/sndiag/sndrch.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": 28.9122807018, "max_line_length": 73, "alphanum_fraction": 0.5060679612, "num_tokens": 615, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273633016692236, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6891867328866464}} {"text": "program chol_ppal\n\nuse datasissim_interface\nuse sistu_interface\nuse sistl_interface\nuse chol_interface\nuse residuo_interface\n\nimplicit none\n\nreal, dimension(:,:), allocatable :: a\nreal, dimension(:,:), allocatable :: a_copia\nreal, dimension(:), allocatable :: b\nreal, dimension(:), allocatable :: u\nreal, dimension(:), allocatable :: w\nreal, dimension(:), allocatable :: r\n\nreal :: deter\n\ninteger :: n, i, j\n\nprint*\nprint*, 'Introduce o orde do sistema: '\nread*, n\nprint*\n\nprint*\nprint*, 'O orde introduce e: ', n\nprint*\n\nallocate(a(n,n), a_copia(n,n), b(n), u(n), w(n), r(n))\n\ncall datasissim(a, b)\n\nprint*, 'O termo independente b e: '\nprint*, b\nprint*,\n\na_copia = a\n\ndo j = 2, n\n do i = 1, j-1\n a_copia(i,j) = a_copia(j,i)\n end do\nend do\n\nprint*, 'A matriz A copia e: '\n\ndo i=1,n\n print*, a_copia(i,1:n)\nend do\n\n\ncall chol(a, deter)\n\nprint*, 'O termo independente b e: '\nprint*, b\nprint*,\n\ncall sistl(a,b,w)\n\n!call residuo(a, u, w, r)\n\nprint*,\nprint*, 'Vector w (Solucion): '\nprint*,\n\nprint*,\nprint*, w\nprint*,\n\ncall sistu(transpose(a),w,u)\n\nprint*,\nprint*, 'Vector u (Solucion): '\nprint*,\n\nprint*,\nprint*, u\nprint*,\n\ncall residuo(a_copia, b, u, r)\n\nif (allocated(a)) deallocate(a)\n\nif (allocated(b)) deallocate(b)\n\nif (allocated(u)) deallocate(u)\n\nend program\n", "meta": {"hexsha": "40f4483818ec592a7cbc166f9b56a08b7b87d618", "size": 1270, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Practica3_cholesky/chol_ppal.f95", "max_stars_repo_name": "UxioAndrade/Analisis-Numerico-Matricial", "max_stars_repo_head_hexsha": "1afa52b0994b9cf38822da903609a4d1c91bfab0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Practica3_cholesky/chol_ppal.f95", "max_issues_repo_name": "UxioAndrade/Analisis-Numerico-Matricial", "max_issues_repo_head_hexsha": "1afa52b0994b9cf38822da903609a4d1c91bfab0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Practica3_cholesky/chol_ppal.f95", "max_forks_repo_name": "UxioAndrade/Analisis-Numerico-Matricial", "max_forks_repo_head_hexsha": "1afa52b0994b9cf38822da903609a4d1c91bfab0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 13.956043956, "max_line_length": 54, "alphanum_fraction": 0.6566929134, "num_tokens": 419, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737807, "lm_q2_score": 0.7981867825403176, "lm_q1q2_score": 0.6891477712372769}} {"text": "! Name = ARPIT KUMAR JAIN ROLLNO = 180122009\nPROGRAM question3\n IMPLICIT NONE\n \n integer :: i\n real:: sum = 0.0, j\n ! Looping from 1 to 40\n do i = 1, 40\n ! finding only even number \n if(mod(i, 2) == 0) then\n ! converting ineger to real by multipling it to 1.0\n j = 1.0 * i \n ! Taking squre root of real number j which is equal to i and \n ! adding the squre root to sum \n sum = sum + sqrt(j)\n endif \n enddo\n ! printing sum on screen\n print *, sum\n\n STOP\nEND PROGRAM", "meta": {"hexsha": "d9647a416419b29d773595b92ef7c0608894f9ff", "size": 571, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "2. Evaluation-2/3.f90", "max_stars_repo_name": "arpitkekri/Code_With_FORTRAN", "max_stars_repo_head_hexsha": "fb731e6f8d8a47cfe38896fffd74a55d17efb2e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-02-21T05:24:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-27T10:25:24.000Z", "max_issues_repo_path": "2. Evaluation-2/3.f90", "max_issues_repo_name": "akhil18soni/Code_With_FORTRAN", "max_issues_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2. Evaluation-2/3.f90", "max_forks_repo_name": "akhil18soni/Code_With_FORTRAN", "max_forks_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-02-27T12:14:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T23:30:55.000Z", "avg_line_length": 25.9545454545, "max_line_length": 73, "alphanum_fraction": 0.5411558669, "num_tokens": 174, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916029436189, "lm_q2_score": 0.7981867777396212, "lm_q1q2_score": 0.6891477614810136}} {"text": "use std\nimplicit none\n\ninteger(int32),allocatable :: A(:,:), X(:),x1\n\n! Same as MATLAB rand\ncall print( rand() )\n\ncall print( rand(3) )\n\ncall print( rand(3,3) )\n\n\n! Same as MATLAB randi\n\nx1 = randi(10)\ncall print(X1)\n\nX = randi(10,10)\ncall print(X)\n\nA = randi([-10, 10],5,5)\ncall print(A)\n\nend", "meta": {"hexsha": "deff62601a337058c761c5876fd73e19d1e070f7", "size": 293, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/playon_std/MATLAB_like.f90", "max_stars_repo_name": "kazulagi/plantfem_min", "max_stars_repo_head_hexsha": "ba7398c031636644aef8acb5a0dad7f9b99fcb92", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2020-06-21T08:21:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-13T04:28:30.000Z", "max_issues_repo_path": "Tutorial/std/MATLAB_like.f90", "max_issues_repo_name": "kazulagi/plantFEM_binary", "max_issues_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-05-08T05:20:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T05:39:29.000Z", "max_forks_repo_path": "Tutorial/std/MATLAB_like.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": 11.72, "max_line_length": 45, "alphanum_fraction": 0.6313993174, "num_tokens": 104, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8633916099737806, "lm_q2_score": 0.7981867705385763, "lm_q1q2_score": 0.689147760875074}} {"text": "! Rice test\n!\nmodule module_bits\n\ncontains\n\n!-------------------------------------------------------------------------------\n! implicit result type\n!-------------------------------------------------------------------------------\n function number_of_bits1(i) result(num)\n num = 0\n itmp = i\n do while (itmp .gt. 0)\n num = num + 1\n itmp = ishft(itmp, -1)\n end do\n end function number_of_bits1\n\n\n!-------------------------------------------------------------------------------\n! result type in function definition\n!-------------------------------------------------------------------------------\n integer function number_of_bits2(i) result(num)\n implicit none\n integer :: i, itmp\n num = 0\n itmp = i\n do while (itmp .gt. 0)\n num = num + 1\n itmp = ishft(itmp, -1)\n end do\n end function number_of_bits2\n\n!-------------------------------------------------------------------------------\n! result type in type declaration\n!-------------------------------------------------------------------------------\n function number_of_bits3(i) result(num)\n implicit none\n integer :: i, itmp, num \n num = 0\n itmp = i\n do while (itmp .gt. 0)\n num = num + 1\n itmp = ishft(itmp, -1)\n end do\n end function number_of_bits3\n\n!-------------------------------------------------------------------------------\n! result type in function declaration\n!-------------------------------------------------------------------------------\n integer function number_of_bits4(i) \n implicit none\n integer :: i, itmp\n number_of_bits4 = 0\n itmp = i\n do while (itmp .gt. 0)\n number_of_bits4 = number_of_bits4 + 1\n itmp = ishft(itmp, -1)\n end do\n end function number_of_bits4\n\n\n!-------------------------------------------------------------------------------\n! result type in type declaration\n!-------------------------------------------------------------------------------\n function number_of_bits5(i) \n implicit none\n integer :: i, itmp, number_of_bits5\n number_of_bits5 = 0\n itmp = i\n do while (itmp .gt. 0)\n number_of_bits5 = number_of_bits5 + 1\n itmp = ishft(itmp, -1)\n end do\n end function number_of_bits5\n\nend module module_bits\n\n\nprogram test_module_bits\nuse module_bits\ninteger :: error\n\nerror = 0\nif (4 .ne. number_of_bits1(14)) then\n error = error + 1\nendif\nif (4 .ne. number_of_bits2(14)) then\n error = error + 1\nendif\nif (4 .ne. number_of_bits4(14)) then\n error = error + 1\nendif\nif (4 .ne. number_of_bits4(14)) then\n error = error + 1\nendif\nif (4 .ne. number_of_bits5(14)) then\n error = error + 1\nendif\n\nif (0 .ne. error) then\n write(*, '(A)') \"Test failed\"\nelse\n write(*, '(A)') \"Test passed\"\nendif\n\nend program test_module_bits\n", "meta": {"hexsha": "583ced015c78f3c12e407553d3a9036f81ea1bde", "size": 2746, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/CompileTests/Fortran_tests/test2011_Rice_funcdecl-1.f90", "max_stars_repo_name": "maurizioabba/rose", "max_stars_repo_head_hexsha": "7597292cf14da292bdb9a4ef573001b6c5b9b6c0", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/CompileTests/Fortran_tests/test2011_Rice_funcdecl-1.f90", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/CompileTests/Fortran_tests/test2011_Rice_funcdecl-1.f90", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 25.4259259259, "max_line_length": 80, "alphanum_fraction": 0.4566642389, "num_tokens": 677, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867777396212, "lm_q2_score": 0.8633915976709975, "lm_q1q2_score": 0.6891477572724769}} {"text": "module constants\n\n integer, parameter :: imiss=-99999\n integer, parameter :: ismth=0\n integer, parameter :: jsmth=0\n\n real, parameter :: cm2inch=1.0/2.54\n real, parameter :: cp=1005.7\n real, parameter :: grav=9.81\n real, parameter :: lapse=6.5E-03\n real, parameter :: lv=2.5E+06\n real, parameter :: m2feet=3.281\n real, parameter :: mps2knts=1.944\n real, parameter :: mps2mph=2.237\n real, parameter :: pi=3.141592654\n real, parameter :: p0=100000.0\n real, parameter :: r=287.04 ! 287.058 in Wikipedia\n real, parameter :: rv=461.5\n real, parameter :: t0=273.15\n real, parameter :: xmiss=-99999.9\n real, parameter :: cpog=cp/grav\n real, parameter :: cpor=cp/r\n real, parameter :: deg2rad=pi/180.\n real, parameter :: e=r/rv\n real, parameter :: gor=grav/r\n real, parameter :: kappa=r/cp\n real, parameter :: rad2deg=180./pi\n real, parameter :: rog=r/grav\n real, parameter :: rvolv=rv/lv\n real, parameter :: zero_thresh=1.e-10\n real, parameter :: eradius=6371200.\n\nend module constants\n", "meta": {"hexsha": "deff4f62efe250e3cf1fbf01d73c954623d4721f", "size": 1043, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/newlfmp/constants.f90", "max_stars_repo_name": "maxinye/laps-mirror", "max_stars_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_stars_repo_licenses": ["Intel", "Unlicense", "OLDAP-2.2.1", "NetCDF"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-04-05T12:28:22.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-29T06:37:29.000Z", "max_issues_repo_path": "src/newlfmp/constants.f90", "max_issues_repo_name": "longwosion/laps-mirror", "max_issues_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_issues_repo_licenses": ["Intel", "NetCDF", "OLDAP-2.2.1", "Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/newlfmp/constants.f90", "max_forks_repo_name": "longwosion/laps-mirror", "max_forks_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_forks_repo_licenses": ["Intel", "NetCDF", "OLDAP-2.2.1", "Unlicense"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-04-27T12:51:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-19T13:57:44.000Z", "avg_line_length": 30.6764705882, "max_line_length": 61, "alphanum_fraction": 0.6510067114, "num_tokens": 359, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898254600902, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6891417520552002}} {"text": "C*****************************************************************************\nC Unit test program TRFT2.F for subroutine RFT2\nC input image (gen'd) is real*4.\nC\nC Ported to UNIX 6/3/1993\nC*****************************************************************************\n include 'VICMAIN_FOR'\n subroutine main44\n\n dimension a(16,18)\n integer*4 n,m,iunit,stat,status,mp2\n real*4 s\n\nC FORTRAN-callable\n call xvmessage('**** FORTRAN-callable RFT2 ****',' ')\n m = 16\n\tn = 16\n call xvunit(iunit,'inp',1,stat,' ')\n call xvopen(iunit,stat,' ')\n do i=1,m\n call xvread(iunit,a(1,i),stat,'line',i,'nsamps',n,' ')\n end do\n \nc ***********************************************\nc forward transform..\nc Resulting transform contained in lines m=1 to 18\n\n call xvmessage('before forward transform:',' ')\n\tmp2 = m + 2\n\tdo 110 i=1,m\n110\tcall prnt(7,n,a(1,i),' ')\n\n\tcall rft2(a,m,n,1,status)\n if (status.ne.1) then\n if (status.eq.1) goto 3\n if (status.eq.2) goto 4\n if (status.eq.3) goto 5\n endif\n\n call xvmessage('after forward transform:',' ')\n\tdo 130 i=1,mp2\n130\tcall prnt(7,n,a(1,i),' ')\n\nc ***********************************************\nc the inverse transform..\n\n\tcall rft2(a,m,n,-1,status)\n if (status.ne.1) then\n if (status.eq.1) goto 3\n if (status.eq.2) goto 4\n if (status.eq.3) goto 5\n endif\n\n call xvmessage('after reverse transform:',' ') \n\ts = 2*m*n\n\n\tdo 160 i=1,m\n\tcall divv(7,n,s,a(1,i),0,1)\n160\tcall prnt(7,n,a(1,i),' ')\n\n call xvclose(iunit,stat,' ')\n\nc ****************************************************************\nc C-callable\n call xvmessage('**** C-callable RFT2 ****',' ')\n m = 16\n\tn = 16\n call xvunit(iunit,'inp',1,stat,' ')\n call xvopen(iunit,stat,' ')\n do i=1,m\n call xvread(iunit,a(1,i),stat,'line',i,'nsamps',n,' ')\n end do\n \nc ***********************************************\nc forward transform..\nc Resulting transform contained in lines m=1 to 18\n\n call xvmessage('before forward transform:',' ')\n\tmp2 = m + 2\n\tdo 210 i=1,m\n210\tcall prnt(7,n,a(1,i),' ')\n\n\tcall tzrft2(a,m,n,1,status)\n\n if (status.ne.1) then\n if (status.eq.1) goto 3\n if (status.eq.2) goto 4\n if (status.eq.3) goto 5\n endif\n\n call xvmessage('after forward transform:',' ')\n\tdo 230 i=1,mp2\n230\tcall prnt(7,n,a(1,i),' ')\n\nc ***********************************************\nc the inverse transform..\n\n\tcall tzrft2(a,m,n,-1,status)\n\n if (status.ne.1) then\n if (status.eq.1) goto 3\n if (status.eq.2) goto 4\n if (status.eq.3) goto 5\n endif\n\n call xvmessage('after reverse transform:',' ') \n\ts = 2*m*n\n\n\tdo 260 i=1,m\n\tcall divv(7,n,s,a(1,i),0,1)\n260\tcall prnt(7,n,a(1,i),' ')\n\n call xvclose(iunit,stat,' ')\n return\nc**************************************************************\n3\tcall xvmessage('m or n has too large a prime factor',' ')\n\treturn\n4\tcall xvmessage(\n + 'product of square-free factors of m or n too big',' ')\n\treturn\n5\tcall xvmessage('number of lines must be even',' ')\n\treturn\n\n end\n", "meta": {"hexsha": "a49c14b616b644d707f565e5adaa06bfb3d4b2c6", "size": 3321, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "vos/p2/sub/rft2/test/trft2.f", "max_stars_repo_name": "NASA-AMMOS/VICAR", "max_stars_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2020-10-21T05:56:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T10:02:01.000Z", "max_issues_repo_path": "vos/p2/sub/rft2/test/trft2.f", "max_issues_repo_name": "NASA-AMMOS/VICAR", "max_issues_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "vos/p2/sub/rft2/test/trft2.f", "max_forks_repo_name": "NASA-AMMOS/VICAR", "max_forks_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-03-09T01:51:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-23T00:23:24.000Z", "avg_line_length": 26.568, "max_line_length": 78, "alphanum_fraction": 0.4649202048, "num_tokens": 929, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898279984214, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6891417490702206}} {"text": "c program DRSRFT1\nc>> 1996-06-05 DRSRFT1 Krogh Fixes for conversion to C.\nc>> 1996-05-28 DRSRFT1 Krogh Moved formats up.\nc>> 1994-10-19 DRSRFT1 Krogh Changes to use M77CON\nc>> 1994-08-09 DRSRFT1 WVS Removed '0' from format\nc>> 1992-04-22 DRSRFT1 CAO, commented program statement\nc>> 1989-05-07 DRSRFT1 FTK, CLL\nc>> 1989-05-04 DRSRFT1 FTK, CLL\nc Demo driver for SRFT1 -- One-dimensional real Fourier transform\nc ------------------------------------------------------------------\nc--S replaces \"?\": DR?RFT1, ?RFT1\nc ------------------------------------------------------------------\n integer I, K, KLAST, M, MS, N, N2, N4\n parameter (M = 7)\nc parameter (N = 2**M)\n parameter (N = 128)\n parameter (N2 = N/2)\n parameter (N4 = N/4)\n real F(N), S(N4-1), T, DELTAT, TTIME, SIG\n real PI, TWOPI, RTWO, ZERO, ONE, FOUR, P1, P3\n real PIN, TB\n parameter (PI = 3.1415926535897932384E0)\n parameter (TWOPI = 2.E0 * PI)\n parameter (RTWO = 1.4142135623730950488E0)\n parameter (ZERO = 0.E0)\n parameter (ONE = 1.E0)\n parameter (FOUR = 4.E0)\n parameter (P1 = .1E0)\n parameter (P3 = .3E0)\n data TTIME /25.E0/\n 1111 format(/' Transform for K=21 to 41 using sigma factors')\n 2222 format(' K=', I3, ' TO', I3, 3(1P,E12.2, E10.2))\nc ------------------------------------------------------------------\n KLAST = N2 - 1\n DELTAT = TTIME / REAL(N)\n T = ZERO\nc Get sine table for use in getting sigma factors\n MS = -1\n call SRFT1(F, 'A', M, MS, S)\n PIN = PI / REAL(N)\n do 100 K = 1, KLAST\n T = T + DELTAT\n TB = TTIME - T\nc Get sigma factor\n if (K .GT. N4) then\n SIG = S(N2-K)\n ELSE if (K .LT. N4) then\n SIG = S(K)\n else\n SIG = ONE\n end if\n SIG = SIG / (PIN * REAL(N - 2*K))\nc\nc Compute F and apply sigma factors\nc\n F(K+1) = SIG*(SIN(TWOPI*(T+P1)) + FOUR*COS(TWOPI*(RTWO*T+P3)))\n F(N-K+1)=SIG*(SIN(TWOPI*(TB+P1))+FOUR*COS(TWOPI*(RTWO*TB+P3)))\n 100 continue\n F(1) = ZERO\n T = T + DELTAT\n F(N2+1) = SIN(TWOPI*(T+P1)) + FOUR*COS(TWOPI*(RTWO*T+P3))\n call SRFT1(F, 'A', M, MS, S)\n write (*, 1111)\n do 120 K = 21, 41, 3\n write (*, 2222) K, K+2, (F(I), I = 2*K-1, 2*K+4)\n 120 continue\n stop\n end\n", "meta": {"hexsha": "f4b8ede9cd74c356a76c74b660e28c19b744f5ff", "size": 2462, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drsrft1.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drsrft1.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drsrft1.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 35.6811594203, "max_line_length": 72, "alphanum_fraction": 0.4784727864, "num_tokens": 874, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898203834278, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6891417432778708}} {"text": "! *******************************************************************\r\n! * *\r\n! * function gamma *\r\n! * *\r\n! *******************************************************************\r\n! Single Precision Version 1.0\r\n! Written by Gordon A. Fenton, TUNS, 1991\r\n!\r\n! PURPOSE to return the Gamma (factorial) function\r\n!\r\n! This routine calculates the definite integral\r\n!\r\n! inf\r\n! gamma(z) = int t**(z-1)*exp(-t) dt\r\n! 0\r\n!\r\n! which is the Gamma function, for argument z. The method used\r\n! is a series expansion followed by a recursion relationship. The\r\n! coefficients used in the series expansion are obtained from Abramowitz\r\n! and Stegun (\"Handbook of Mathematical Functions\", US Dept. of Commerce,\r\n! 10th printing, 1972), pg 256. The result should have a relative accuracy\r\n! of better than 1.e-14. If gamma(zz) would result in a number bigger\r\n! than the maximum single precision number, \"big\", then \"big\" is\r\n! returned. This occurs also if zz is a negative integer.\r\n! Arguments are as follows;\r\n!\r\n! zz real value for which the gamma function is desired. (input)\r\n!\r\n! NOTES: 1) \"eps\" is the machine epsilon (smallest number which can be added\r\n! to 1.0 without being lost)\r\n! 2) \"big\" is the biggest floating point number\r\n! 3) set IDEBUG = 1 if error messages should be reported\r\n!--------------------------------------------------------------------------\r\n real function gammaf( zz )\r\n parameter (IDEBUG = 1)\r\n dimension c(26)\r\n data c/1.0000000000000000, 0.5772156649015329, &\r\n -0.6558780715202538, -0.0420026350340952, &\r\n 0.1665386113822915, -0.0421977345555443, &\r\n -0.0096219715278770, 0.0072189432466630, &\r\n -0.0011651675918591, -0.0002152416741149, &\r\n 0.0001280502823882, -0.0000201348547807, &\r\n -0.0000012504934821, 0.0000011330272320, &\r\n -0.0000002056338417, 0.0000000061160950, &\r\n 0.0000000050020075, -0.0000000011812746, &\r\n 0.0000000001043427, 0.0000000000077823, &\r\n -0.0000000000036968, 0.0000000000005100, &\r\n -0.0000000000000206, -0.0000000000000054, &\r\n 0.0000000000000014, 0.0000000000000001/\r\n data zero/0./, eps/0.119209e-06/, one/1./, big/1.701411733e+38/\r\n data pi/3.141592653589793238462643/\r\n\r\n 1 format(a,e13.6,a)\r\n!----------------------------- start executable statements\r\n z = abs(zz)\r\n\r\n q = z + eps\r\n n = int( q )\r\n f = z - float(n)\r\n!\t\t\t\t\tis z an integer?\r\n if( f .lt. q*eps ) then\r\n if( zz .le. zero ) go to 20\r\n n = n - 1\r\n f = one\r\n a = one\r\n else\r\n!\t\t\t\t\tseries expansion for f < 1.0\r\n a = f*(c(22) + f*(c(23) + f*(c(24) + f*(c(25) + f*c(26)))))\r\n a = f*(c(17) + f*(c(18) + f*(c(19) + f*(c(20) + f*(c(21)+a)))))\r\n a = f*(c(12) + f*(c(13) + f*(c(14) + f*(c(15) + f*(c(16)+a)))))\r\n a = f*(c( 7) + f*(c( 8) + f*(c( 9) + f*(c(10) + f*(c(11)+a)))))\r\n a = f*(c( 2) + f*(c( 3) + f*(c( 4) + f*(c( 5) + f*(c( 6)+a)))))\r\n a = one/(f*(c( 1) + a))\r\n endif\r\n!\t\t\t\t\tapply recursion and watch for overflow\r\n if( n .gt. 0 ) then\r\n a = a*f\r\n do 10 i = 1, n-1\r\n q = f + float(i)\r\n if( a .gt. (big/q) ) go to 20\r\n a = a*q\r\n 10 continue\r\n endif\r\n\r\n if( zz .lt. zero ) then\r\n gammaf = -pi/(z*a*sin(pi*z))\r\n else\r\n gammaf = a\r\n endif\r\n\r\n return\r\n!\t\t\t\toverflow error\r\n 20 if( IDEBUG .eq. 1 ) &\r\n write(0,1)'Overflow calculating Gamma(',zz,') in GAMMA.'\r\n gammaf = big\r\n return\r\n end\r\n", "meta": {"hexsha": "12bcb4d66a72fc7f72bd3131ca39e68b1315bff1", "size": 3982, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/libs/gaf95/gammaf.f95", "max_stars_repo_name": "leemargetts/PoreFEM", "max_stars_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/libs/gaf95/gammaf.f95", "max_issues_repo_name": "leemargetts/PoreFEM", "max_issues_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/libs/gaf95/gammaf.f95", "max_forks_repo_name": "leemargetts/PoreFEM", "max_forks_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.6326530612, "max_line_length": 78, "alphanum_fraction": 0.467604219, "num_tokens": 1248, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898153067649, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6891417394163039}} {"text": "integer(4) function coordinates_to_index(i,j,cells)\n\timplicit none!all variables must be declared\n\tinteger(4),intent(in)::cells!number of cells per side of the square to be used in the game\n\tinteger(4),intent(in)::i!first coordinate\n\tinteger(4),intent(in)::j!second coordinate\n\tcoordinates_to_index=j*cells+i!the conversion\nend function coordinates_to_index\n\n\n\ninteger(4) function index_to_first_coordinate(i,cells)\n\timplicit none!all variables must be declared\n\tinteger(4),intent(in)::cells!number of cells per side of the square to be used in the game\n\tinteger(4),intent(in)::i!index of the cell\n\tindex_to_first_coordinate=mod(i,cells)!the conversion\nend function index_to_first_coordinate\n\n\n\ninteger(4) function index_to_second_coordinate(i,cells)\n\timplicit none!all variables must be declared\n\tinteger(4),intent(in)::cells!number of cells per side of the square to be used in the game\n\tinteger(4),intent(in)::i!index of the cell\n\tindex_to_second_coordinate=i/cells!the conversion\nend function index_to_second_coordinate", "meta": {"hexsha": "fcdafffc23cae6702a1f1cb6a75772b0772df979", "size": 1023, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "coordinates_index.f08", "max_stars_repo_name": "jeruiznavarro/new2048", "max_stars_repo_head_hexsha": "091c03d9383c8f15a2842339a710af87314c72ae", "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": "coordinates_index.f08", "max_issues_repo_name": "jeruiznavarro/new2048", "max_issues_repo_head_hexsha": "091c03d9383c8f15a2842339a710af87314c72ae", "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": "coordinates_index.f08", "max_forks_repo_name": "jeruiznavarro/new2048", "max_forks_repo_head_hexsha": "091c03d9383c8f15a2842339a710af87314c72ae", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.92, "max_line_length": 91, "alphanum_fraction": 0.8035190616, "num_tokens": 255, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476793890012, "lm_q2_score": 0.7853085708384736, "lm_q1q2_score": 0.6890900469536911}} {"text": " PROGRAM xrkqs\r\nC driver for routine rkqs\r\n INTEGER N\r\n PARAMETER(N=4)\r\n INTEGER i,j\r\n REAL bessj,bessj0,bessj1\r\n REAL eps,hdid,hnext,htry,x,y(N),dydx(N),dysav(N),ysav(N),yscal(N)\r\n EXTERNAL derivs\r\n x=1.0\r\n ysav(1)=bessj0(x)\r\n ysav(2)=bessj1(x)\r\n ysav(3)=bessj(2,x)\r\n ysav(4)=bessj(3,x)\r\n call derivs(x,ysav,dysav)\r\n do 11 i=1,N\r\n yscal(i)=1.0\r\n11 continue\r\n htry=0.6\r\n write(*,'(/1x,t8,a,t19,a,t31,a,t43,a)')\r\n * 'eps','htry','hdid','hnext'\r\n do 13 i=1,15\r\n eps=exp(-float(i))\r\n x=1.0\r\n do 12 j=1,N\r\n y(j)=ysav(j)\r\n dydx(j)=dysav(j)\r\n12 continue\r\n call rkqs(y,dydx,n,x,htry,eps,yscal,hdid,hnext,derivs)\r\n write(*,'(2x,e12.4,f8.2,2x,2f12.6)') eps,htry,hdid,hnext\r\n13 continue\r\n END\r\n SUBROUTINE derivs(x,y,dydx)\r\n REAL x,y(*),dydx(*)\r\n dydx(1)=-y(2)\r\n dydx(2)=y(1)-(1.0/x)*y(2)\r\n dydx(3)=y(2)-(2.0/x)*y(3)\r\n dydx(4)=y(3)-(3.0/x)*y(4)\r\n return\r\n END\r\n", "meta": {"hexsha": "574b49076e0b66b05524b2c0da56c49096ac2662", "size": 1064, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xrkqs.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xrkqs.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xrkqs.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": 26.6, "max_line_length": 72, "alphanum_fraction": 0.4840225564, "num_tokens": 436, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.7853085708384735, "lm_q1q2_score": 0.6890900419212993}} {"text": "subroutine sistub(a, b, u)\n\nimplicit none\n\nreal, dimension(:,:), intent(in) :: a\nreal, dimension(:), intent(in) :: b\nreal, dimension(:), intent(out) :: u\n\ninteger :: n, i, j\n\nn = size(b)\n\nu = b\n\ndo i = n, 1, -1\n u(i) = u(i)/a(i,i)\n u(1:i-1) = u(1:i-1) - a(1:i-1, i)*u(i)\nend do\n\nend subroutine\n", "meta": {"hexsha": "15c7bcde0fea887539ae8e407f7c3511d7412774", "size": 296, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Practica2_sistu/sistub.f95", "max_stars_repo_name": "UxioAndrade/Analisis-Numerico-Matricial", "max_stars_repo_head_hexsha": "1afa52b0994b9cf38822da903609a4d1c91bfab0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2019-04-02T18:09:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-16T14:08:07.000Z", "max_issues_repo_path": "Practica2_sistu/sistub.f95", "max_issues_repo_name": "UxioAndrade/Analisis-Numerico-Matricial", "max_issues_repo_head_hexsha": "1afa52b0994b9cf38822da903609a4d1c91bfab0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Practica2_sistu/sistub.f95", "max_forks_repo_name": "UxioAndrade/Analisis-Numerico-Matricial", "max_forks_repo_head_hexsha": "1afa52b0994b9cf38822da903609a4d1c91bfab0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-04-05T13:18:12.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-04T10:32:14.000Z", "avg_line_length": 14.0952380952, "max_line_length": 40, "alphanum_fraction": 0.5472972973, "num_tokens": 121, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8774767810736693, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.6890900412979144}} {"text": "module constants\n !! Define universally constant mathematical and physical values\n implicit none\n\n private\n public :: dp, pi, zero, one, p_amb\n\n integer, parameter :: precision=15, range=307\n integer, parameter :: dp = selected_real_kind(precision, range)\n\n real(dp), parameter :: pi = 3.1415926539_dp\n real(dp), parameter :: zero = 0._dp\n real(dp), parameter :: one = 1._dp\n real(dp), parameter :: p_amb = 101325._dp ! atmospheric pressure\nend module constants\n", "meta": {"hexsha": "1c09aef61cd812eecdb5d6da4f6741b4e2d0ef79", "size": 472, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/refurbished/constants.f90", "max_stars_repo_name": "sourceryinstitute/rocket-science", "max_stars_repo_head_hexsha": "92c79b1008db7a715770e098db0dbda6a6062d54", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-09-23T15:09:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-24T05:50:57.000Z", "max_issues_repo_path": "src/refurbished/constants.f90", "max_issues_repo_name": "sourceryinstitute/rocket-science", "max_issues_repo_head_hexsha": "92c79b1008db7a715770e098db0dbda6a6062d54", "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/refurbished/constants.f90", "max_forks_repo_name": "sourceryinstitute/rocket-science", "max_forks_repo_head_hexsha": "92c79b1008db7a715770e098db0dbda6a6062d54", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2021-03-04T14:17:20.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-21T17:35:44.000Z", "avg_line_length": 29.5, "max_line_length": 66, "alphanum_fraction": 0.7139830508, "num_tokens": 129, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267898240861, "lm_q2_score": 0.793105953629227, "lm_q1q2_score": 0.6890716996820517}} {"text": "\nsubmodule(forlab_linalg) forlab_linalg_lu\n\n implicit none\n\ncontains\n\n module procedure lu_sp\n integer :: i, j, k, m\n\n if (is_square(A)) then\n m = size(A, 1)\n if (.not. allocated(L)) then\n allocate (L(m, m))\n call eye(L)\n end if\n if (.not. allocated(U)) then\n U = zeros(m, m)\n end if\n\n do i = 1, m\n do j = 1, m\n U(i, j) = A(i, j)\n do k = 1, i - 1\n U(i, j) = U(i, j) - L(i, k)*U(k, j)\n end do\n end do\n do j = i + 1, m\n L(j, i) = A(j, i)\n do k = 1, i - 1\n L(j, i) = L(j, i) - L(j, k)*U(k, i)\n end do\n L(j, i) = L(j, i)/U(i, i)\n end do\n end do\n else\n call error_stop(\"Error: in A = LU, A should be square.\")\n end if\n return\n end procedure\n module procedure lu_dp\n integer :: i, j, k, m\n\n if (is_square(A)) then\n m = size(A, 1)\n if (.not. allocated(L)) then\n allocate (L(m, m))\n call eye(L)\n end if\n if (.not. allocated(U)) then\n U = zeros(m, m)\n end if\n\n do i = 1, m\n do j = 1, m\n U(i, j) = A(i, j)\n do k = 1, i - 1\n U(i, j) = U(i, j) - L(i, k)*U(k, j)\n end do\n end do\n do j = i + 1, m\n L(j, i) = A(j, i)\n do k = 1, i - 1\n L(j, i) = L(j, i) - L(j, k)*U(k, i)\n end do\n L(j, i) = L(j, i)/U(i, i)\n end do\n end do\n else\n call error_stop(\"Error: in A = LU, A should be square.\")\n end if\n return\n end procedure\n\nend submodule forlab_linalg_lu\n", "meta": {"hexsha": "8e38754476ac9fa430b2217fba7ee7c8c815cf9e", "size": 1831, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/forlab_linalg_lu.f90", "max_stars_repo_name": "zoziha/forlab_z", "max_stars_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2021-08-31T15:23:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T02:44:46.000Z", "max_issues_repo_path": "src/forlab_linalg_lu.f90", "max_issues_repo_name": "zoziha/forlab_z", "max_issues_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-08-22T11:47:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-31T00:57:16.000Z", "max_forks_repo_path": "src/forlab_linalg_lu.f90", "max_forks_repo_name": "zoziha/forlab_z", "max_forks_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-07-16T03:16:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-31T13:09:42.000Z", "avg_line_length": 24.0921052632, "max_line_length": 64, "alphanum_fraction": 0.3670125614, "num_tokens": 580, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267830311355, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.689071685796996}} {"text": "module nonlinear_transport\n\nimplicit none\n\ncontains\n \n pure real(8) function exact4(x)\n\n real(8), intent(in) :: x\n\n exact4 = -1.0d0 + sqrt(4.0d0-(8.0d0/3.0d0)*x-x*x*x/3.0d0)\n\n end function exact4\n\n pure real(8) function exact3(x)\n\n real(8), intent(in) :: x\n\n exact3 = -1.0d0 + sqrt(4.0d0-2.0d0*x-x*x)\n \n end function exact3\n \n pure real(8) function exact2(x)\n\n real(8), intent(in) :: x\n\n exact2 = -1.0d0 + sqrt(4.0d0-3.0d0*x)\n\n end function exact2\n \n ! Model problem to solve\n pure subroutine assemble_residual_jacobian(sparse, npts, phi, Q, V, R)\n\n logical, intent(in) :: sparse \n integer, intent(in) :: npts \n real(8), intent(in) :: phi(:) ! current state\n real(8), intent(in) :: Q(:) ! source\n\n real(8), intent(inout) :: V(:,:) ! jacbian \n real(8), intent(inout) :: R(:) ! residual\n\n real(8), parameter :: a = 0.0d0, b = 1.0d0 ! bound of domain\n real(8), parameter :: L = 1.0d0\n\n real(8), parameter :: phi0 = 1.0d0\n real(8), parameter :: phiN = 0.0d0\n\n ! Local variables\n real(8) :: aa, bb, cc\n real(8) :: h \n integer :: m, n, i, j\n\n m = npts\n n = npts\n\n ! Mesh spacing\n h = (b-a)/dble(npts+1)\n\n ! Assemble the Residual for supplied source\n R = 0.0d0\n\n ! First node\n aa = 1.0d0 + phi(1)\n bb = phi0 - 2.0d0*(1.0d0+phi(1)) - phi(2)\n cc = 1.0d0 - phi(1) + 2.0d0*phi(2)\n R(1) = 0.0d0 + &\n & - ( phi(2) - 2.0d0*phi(1) + phi0 &\n & + phi(2)*phi(2) &\n & - phi(2)*phi(1) &\n & - phi(1)*phi(1) &\n & + phi(1)*phi0 &\n & + h*h*Q(1)/0.1d0 )\n\n ! Interior nodes\n do i = 2, m-1\n aa = 1.0d0 + phi(i)\n bb = phi(i-1) - 2.0d0*(1.0d0+phi(i)) - phi(i+1)\n cc = 1.0d0 - phi(i) + 2.0d0*phi(i+1)\n R(i) = -(phi(i+1) - 2.0d0*phi(i) + phi(i-1) &\n & + phi(i+1)*phi(i+1) &\n & - phi(i+1)*phi(i) &\n & - phi(i)*phi(i) &\n & + phi(i)*phi(i-1) &\n & + h*h*Q(i)/0.1d0)\n end do\n\n ! Last node\n aa = 1.0d0 + phi(npts)\n bb = phi(npts-1) - 2.0d0*(1.0d0+phi(npts)) - phiN\n cc = 1.0d0 - phi(npts) + 2.0d0*phiN\n R(npts) = 0.0 + & \n & - ( phiN - 2.0d0*phi(npts) + phi(npts-1) &\n & + phiN*phiN &\n & - phiN*phi(npts) &\n & - phi(npts)*phi(npts) &\n & + phi(npts)*phi(npts-1) &\n & + h*h*Q(npts)/0.1d0)\n\n ! Assemble the jacobian\n V = 0.0d0\n\n if (sparse .eqv. .false.) then\n \n do i = 1, m\n\n ! Create matrix coefficients\n if (i.eq.1) then\n ! First node\n aa = 1.0d0 + phi(1)\n bb = phi0 - 2.0d0*(1.0d0+phi(1)) - phi(2)\n cc = 1.0d0 - phi(1) + 2.0d0*phi(2)\n else if (i.eq.npts) then \n ! Last node\n aa = 1.0d0 + phi(npts)\n bb = phi(npts-1) - 2.0d0*(1.0d0+phi(npts)) - phiN\n cc = 1.0d0 - phi(npts) + 2.0d0*phiN\n else\n ! Interior nodes\n aa = 1.0d0 + phi(i)\n bb = phi(i-1) - 2.0d0*(1.0d0+phi(i)) - phi(i+1)\n cc = 1.0d0 - phi(i) + 2.0d0*phi(i+1)\n end if\n\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 else\n\n do concurrent(i=1:n)\n\n if (i.eq.1) then\n\n ! First node\n aa = 1.0d0 + phi(1)\n bb = phi0 - 2.0d0*(1.0d0+phi(1)) - phi(2)\n cc = 1.0d0 - phi(1) + 2.0d0*phi(2)\n\n V(i,:) = [0.0d0, bb, cc]\n\n else if (i.eq.npts) then \n\n ! Last node\n aa = 1.0d0 + phi(npts)\n bb = phi(npts-1) - 2.0d0*(1.0d0+phi(npts)) - phiN\n cc = 1.0d0 - phi(npts) + 2.0d0*phiN\n\n V(i,:) = [aa, bb, 0.0d0]\n\n else\n\n ! Interior nodes\n aa = 1.0d0 + phi(i)\n bb = phi(i-1) - 2.0d0*(1.0d0+phi(i)) - phi(i+1)\n cc = 1.0d0 - phi(i) + 2.0d0*phi(i+1)\n\n V(i,:) = [aa, bb, cc]\n\n end if\n\n end do\n\n end if\n\n end subroutine assemble_residual_jacobian\n\nend module nonlinear_transport\n", "meta": {"hexsha": "f48ae5a73d72f50d8845c638b473d9df7c69b90d", "size": 4362, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "physics/steady-transport/nonlinear_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/nonlinear_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/nonlinear_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": 24.3687150838, "max_line_length": 72, "alphanum_fraction": 0.4392480514, "num_tokens": 1727, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213853793453, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6889910067776506}} {"text": "program P17626\n implicit none\n integer :: n, i, j, sq\n integer, dimension(0:50000) :: save\n read *, n\n save(0) = 0\n do i = 1, n\n save(i) = i\n j = 1\n sq = 1\n do while (sq <= i)\n save(i) = min(save(i), save(i - sq) + 1)\n j = j + 1\n sq = j * j\n end do\n end do\n write (*, '(I0)') save(n)\nend program P17626", "meta": {"hexsha": "b7404b23b194e7da27ff0359ee66c92cf5c8bf8b", "size": 394, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "P17626.f95", "max_stars_repo_name": "daily-boj/kiwiyou", "max_stars_repo_head_hexsha": "ceca96ddfee95708871af67d1682048e0bed0257", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-04-08T09:04:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-16T07:30:24.000Z", "max_issues_repo_path": "P17626.f95", "max_issues_repo_name": "daily-boj/kiwiyou", "max_issues_repo_head_hexsha": "ceca96ddfee95708871af67d1682048e0bed0257", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "P17626.f95", "max_forks_repo_name": "daily-boj/kiwiyou", "max_forks_repo_head_hexsha": "ceca96ddfee95708871af67d1682048e0bed0257", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-04-16T05:32:06.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-28T13:40:56.000Z", "avg_line_length": 21.8888888889, "max_line_length": 52, "alphanum_fraction": 0.421319797, "num_tokens": 141, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6889909999074393}} {"text": " SUBROUTINE SRCVAL (X, Y, RC, IERR)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc>> 2001-07-16 SRCVAL Krogh Change -1.0 to -1.e0.\nc>> 1996-03-30 SRCVAL Krogh Added external statement.\nC>> 1995-11-17 SRCVAL Krogh Converted SFTRAN to Fortran 77.\nC>> 1994-10-19 SRCVAL Krogh Changes to use M77CON\nC>> 1991-10-31 SRCVAL WV Snyder JPL Incorporate changes from Carlson\nC>> 1990-12-20 SRCVAL WV Snyder JPL Convert from NSWC for Math 77.\nC\nC THIS SUBROUTINE COMPUTES THE ELEMENTARY INTEGRAL\nC\nC RC(X,Y) = INTEGRAL FROM ZERO TO INFINITY OF\nC\nC -1/2 -1\nC (1/2)(T+X) (T+Y) DT,\nC\nC WHERE X IS NONNEGATIVE AND Y IS NONZERO. IF Y IS NEGATIVE,\nC THE CAUCHY PRINCIPAL VALUE IS COMPUTED BY USING A PRELIMI-\nC NARY TRANSFORMATION TO MAKE Y POSITIVE; SEE EQUATION (2.12)\nC OF THE SECOND REFERENCE BELOW. WHEN Y IS POSITIVE, THE\nC DUPULICATION THEOREM IS ITERATED UNTIL THE VARIABLES ARE\nC NEARLY EQUAL, AND THE FUNCTION IS THEN EXPANDED IN TAYLOR\nC SERIES TO FIFTH ORDER. LOGARITHMIC, INVERSE CIRCULAR, AND\nC INVERSE HYPERBOLIC FUNCTIONS ARE EXPRESSED IN TERMS OF RC\nC BY EQUATIONS (4.9)-(4.13) OF THE SECOND REFERENCE BELOW.\nC\nC REFERENCES: B. C. CARLSON AND E. M. NOTIS, ALGORITHMS FOR\nC INCOMPLETE ELLIPTIC INTEGRALS, ACM TRANSACTIONS ON MATHEMA-\nC TICAL SOFTWARE, 7 (1981), 398-403;\nC B. C. CARLSON, COMPUTING ELLIPTIC INTEGRALS BY DUPLICATION,\nC NUMER. MATH. 33 (1979), 1-16.\nC AUTHORS: B. C. CARLSON AND ELAINE M. NOTIS, AMES LABORATORY-\nC DOE, IOWA STATE UNIVERSITY, AMES, IA 50011, AND R. L. PEXTON,\nC LAWRENCE LIVERMORE NATIONAL LABORATORY, LIVERMORE, CA 94550.\nC AUG. 1, 1979, REVISED SEPT. 1, 1987.\nC\nC CHECK VALUES: RC(0,1/4) = RC(1/16,1/8) = PI,\nC RC(9/4,2) = LN(2),\nC RC(1/4,-2) = LN(2)/3.\nC CHECK BY ADDITION THEOREM: RC(X,X+Z) + RC(Y,Y+Z) = RC(0,Z),\nC WHERE X, Y, AND Z ARE POSITIVE AND X * Y = Z * Z.\nC\nC ***** Formal Arguments ***********************************\nC\nC LOLIM AND UPLIM DETERMINE THE RANGE OF VALID ARGUMENTS.\nC LOLIM IS NOT LESS THAN THE MACHINE MINIMUM MULTIPLIED BY 5.\nC UPLIM IS NOT GREATER THAN THE MACHINE MAXIMUM DIVIDED BY 5.\nC\nC INPUT ...\nC\nC X AND Y ARE THE VARIABLES IN THE INTEGRAL RC(X,Y).\nC\nC OUTPUT ...\nC\nC RC IS THE VALUE OF THE INTEGRAL.\nC\nC IERR IS THE RETURN ERROR CODE.\nC 0 FOR NORMAL COMPLETION OF THE SUBROUTINE.\nC 1 X IS NEGATIVE, OR Y = 0.\nC 2 X+ABS(Y) IS TOO SMALL.\nC 3 X OR ABS(Y) IS TOO LARGE, OR X + ABS(Y) IS TOO LARGE.\nC 4 Y < -2.236/SQRT(LOLIM) AND 0 < X < (LOLIM*UPLIM)**2/25\nC\n REAL X, Y, RC\n INTEGER IERR\nC\nC--S replaces \"?\": ?ERM1, ?ERV1, ?RCVAL\nC\nC ***** External References ********************************\nC\n EXTERNAL R1MACH\n REAL R1MACH\nC\nC ***** Local Variables ************************************\nC\n REAL C1,C2,C3,C4,ERRTOL,LAMDA,LOLIM\n REAL MU,SN,UPLIM,XLU225,XN,Y2236L,YN,W\n PARAMETER (C1 = 3.0e0 / 10.0e0)\n PARAMETER (C2 = 1.0e0 / 7.0e0)\n PARAMETER (C3 = 3.0e0 / 8.0e0)\n PARAMETER (C4 = 9.0e0 / 22.0e0)\n SAVE ERRTOL, LOLIM, UPLIM, XLU225, Y2236L\n DATA LOLIM /-1.0e0/\nC\nC ERRTOL IS SET TO THE DESIRED ERROR TOLERANCE.\nC RELATIVE ERROR DUE TO TRUNCATION IS LESS THAN\nC 16 * ERRTOL ** 6 / (1 - 2 * ERRTOL).\nC\nC SAMPLE CHOICES ERRTOL RELATIVE TRUNCATION\nC ERROR LESS THAN\nC 1.E-3 2.E-17\nC 3.E-3 2.E-14\nC 1.E-2 2.E-11\nC 3.E-2 2.E-8\nC 1.E-1 2.E-5\nC\nC We could put in a Newton iteration to solve for ERRTOL in\nC terms of R1MACH(4), but it seems good enough to put\nC ERRTOL = (R1MACH(4)/16.0)**(1.0/6.0)\nC\nc ----------------------------------------------------------------------\nC WARNING. CHANGES IN THE PROGRAM MAY IMPROVE SPEED AT THE\nC EXPENSE OF ROBUSTNESS.\nc ----------------------------------------------------------------------\nC\n IF (X .LT. 0.0e0 .OR. Y .EQ. 0.0e0) THEN\n RC = 0.0e0\n CALL SERM1 ('SRCVAL',1,0,'X < 0 or Y = 0','X',X,',')\n CALL SERV1 ('Y',Y,'.')\n IERR = 1\n RETURN\n END IF\n IF (LOLIM .LT. 0.0e0) THEN\n LOLIM = 5.0e0 * R1MACH(1)\n UPLIM = R1MACH(2) / 5.0e0\n XLU225 = (LOLIM*UPLIM)**2 / 25.0e0\n Y2236L = -2.236e0/SQRT(LOLIM)\n ERRTOL = (R1MACH(4)/16.0e0) ** (1.0e0/6.0e0)\n END IF\n YN = ABS(Y)\n IF (X .GT. UPLIM .OR. YN .GT. UPLIM) THEN\n RC = 0.0e0\n CALL SERM1 ('SRCVAL',3,0,'X > UPLIM or ABS(Y) > UPLIM','X',X,',')\n CALL SERV1 ('Y',Y,',')\n CALL SERV1 ('UPLIM',UPLIM,'.')\n IERR = 3\n RETURN\n END IF\n IF (X + YN .LT. LOLIM) THEN\n RC = 0.0e0\n CALL SERM1 ('SRCVAL',2,0,'X + ABS(Y) < LOLIM','X',X,',')\n CALL SERV1 ('Y',Y,',')\n CALL SERV1 ('LOLIM',LOLIM,'.')\n IERR = 2\n RETURN\n END IF\n IF (X + YN .GT. UPLIM) THEN\n RC = 0.0e0\n CALL SERM1 ('SRCVAL',3,0,'X + ABS(Y) > UPLIM','X',X,',')\n CALL SERV1 ('Y',Y,',')\n CALL SERV1 ('UPLIM',UPLIM,'.')\n IERR = 3\n RETURN\n END IF\n IF (Y.LT.Y2236L .AND. X.GT.0.0e0 .AND. X.LT.XLU225) THEN\n RC = 0.0e0\n CALL SERM1 ('SRCVAL',4,0,\n 1 'Y < -2.236/SQRT(LOLIM) AND 0 < X < (LOLIM*UPLIM)**2/25',\n 2 'X',X,',')\n CALL SERV1 ('Y',Y,',')\n CALL SERV1 ('LOLIM',LOLIM,',')\n CALL SERV1 ('UPLIM',UPLIM,'.')\n IERR = 4\n RETURN\n END IF\nC\n IERR = 0\n IF (Y.GT.0.0e0) THEN\n XN = X\n W = 1.0e0\n ELSE\nC TRANSFORM TO POSITIVE Y\n XN = X - Y\n W = SQRT(X) / SQRT(XN)\n END IF\nC\n 20 CONTINUE\n MU = (XN + YN + YN) / 3.0e0\n SN = (YN + MU) / MU - 2.0e0\n IF (ABS(SN) .LT. ERRTOL) THEN\n RC = W * (1.0e0+SN*SN*(C1+SN*(C2+SN*(C3+SN*C4)))) / SQRT(MU)\n RETURN\n END IF\n LAMDA = 2.0 * SQRT(XN) * SQRT(YN) + YN\n XN = (XN + LAMDA) * 0.25e0\n YN = (YN + LAMDA) * 0.25e0\n GO TO 20\n END\n", "meta": {"hexsha": "3546226181b97ebac4b685b0b3db58c2a1f0d335", "size": 6477, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/srcval.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/srcval.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/srcval.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 35.7845303867, "max_line_length": 72, "alphanum_fraction": 0.519221862, "num_tokens": 2433, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213745668095, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6889909984920731}} {"text": " SUBROUTINE aniso_euclidean_s(D,x,y,nx,ny,ndx,ndy,cmin,cmax,sr,\n *nsr,symm)\n\ncf2py intent(inplace) D\ncf2py integer intent(optional) :: cmin=0\ncf2py integer intent(optional) :: cmax=-1\ncf2py logical intent(optional) :: symm=0\ncf2py intent(hide) nx, ny,ndx,ndy,nsr\ncf2py threadsafe\n\n DOUBLE PRECISION D(nx,ny), x(nx,ndx), y(ny,ndy), sr(nsr)\n INTEGER nx,ny,i,j,k,cmin,cmax,ndx,ndy,nsr\n LOGICAL symm\n DOUBLE PRECISION dist, dev\n\n if (cmax.EQ.-1) then\n cmax = ny\n end if\n ! print *,nsr,sr(1)\n\n if(symm) then\n\n do j=cmin+1,cmax\n D(j,j) = 0.0D0\n do i=1,j-1\n dist = 0.0D0\n do k=1,ndx\n if (k.GT.1) then\n dev=(x(i,k) - y(j,k))*sr(k-1)\n else\n dev=(x(i,k) - y(j,k))\n end if\n dist = dist + dev*dev\n enddo\n D(i,j) = dsqrt(dist)\n enddo\n enddo\n else\n do j=cmin+1,cmax\n do i=1,nx\n dist = 0.0D0\n do k=1,ndx\n dev=(x(i,k) - y(j,k))*sr(k)\n dist = dist + dev*dev\n enddo\n D(i,j) = dsqrt(dist)\n enddo \n enddo \n endif\n RETURN\n END\n", "meta": {"hexsha": "78c599fb4310e5b873f9106dc7e57c773c6e60f9", "size": 1259, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "templates/mydistance/src/mydistances.f", "max_stars_repo_name": "emirkmo/snpy", "max_stars_repo_head_hexsha": "2a0153c84477ba8a30310d7dbca3d5a8f24de3c6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-01-14T19:40:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-05T12:19:39.000Z", "max_issues_repo_path": "templates/mydistance/src/mydistances.f", "max_issues_repo_name": "emirkmo/snpy", "max_issues_repo_head_hexsha": "2a0153c84477ba8a30310d7dbca3d5a8f24de3c6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2017-04-25T20:06:22.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-09T20:46:41.000Z", "max_forks_repo_path": "templates/mydistance/src/mydistances.f", "max_forks_repo_name": "emirkmo/snpy", "max_forks_repo_head_hexsha": "2a0153c84477ba8a30310d7dbca3d5a8f24de3c6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2017-04-25T19:57:57.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-12T11:54:19.000Z", "avg_line_length": 24.2115384615, "max_line_length": 68, "alphanum_fraction": 0.4638602065, "num_tokens": 430, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213853793452, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6889909971800167}} {"text": "subroutine qinit(meqn,mbc,mx,xlower,dx,q,maux,aux)\n\n ! Set initial conditions for the q array.\n\n use geoclaw_module, only: sea_level\n use grid_module, only: xcell\n\n ! uncomment if any of these needed...\n !use geoclaw_module, only: dry_tolerance, grav\n\n implicit none\n\n integer, intent(in) :: meqn,mbc,mx,maux\n real(kind=8), intent(in) :: xlower,dx\n real(kind=8), intent(in) :: aux(maux,1-mbc:mx+mbc)\n real(kind=8), intent(inout) :: q(meqn,1-mbc:mx+mbc)\n\n !locals\n integer :: i\n\n real(kind=8) :: eta, width, x0, ampl\n\n width = 5.d3 ! controls width of Gaussian\n x0 = 0.d3 ! initial location of Gaussian\n ampl = 50.d0 ! amplitude\n\n do i=1,mx\n eta = ampl * exp(-((xcell(i)-x0)/width)**2)\n q(1,i) = max(sea_level, eta - aux(1,i))\n q(2,i) = 0.d0 !eta*sqrt(grav*q(1,i)) ! right-going\n\n enddo\n\n\nend subroutine qinit\n", "meta": {"hexsha": "33a176d7c2d422d53f1edefd5746bd3fe83399d1", "size": 885, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/shoaling_bouss/qinit.f90", "max_stars_repo_name": "clawpack/geoclaw_1d", "max_stars_repo_head_hexsha": "2272459a81f253720feaa3561094764433e7115a", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "examples/shoaling_bouss/qinit.f90", "max_issues_repo_name": "clawpack/geoclaw_1d", "max_issues_repo_head_hexsha": "2272459a81f253720feaa3561094764433e7115a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-01-22T19:35:11.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-22T17:32:43.000Z", "max_forks_repo_path": "examples/shoaling_bouss/qinit.f90", "max_forks_repo_name": "clawpack/geoclaw_1d", "max_forks_repo_head_hexsha": "2272459a81f253720feaa3561094764433e7115a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-01-04T04:39:16.000Z", "max_forks_repo_forks_event_max_datetime": "2019-01-04T04:39:16.000Z", "avg_line_length": 24.5833333333, "max_line_length": 58, "alphanum_fraction": 0.613559322, "num_tokens": 312, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213664574069, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6889909922778894}} {"text": "subroutine derv(neqn,t,u,ut)\n! \n! Subroutine derv computes the derivative vector\n! of the 2 x 2 ODE problem\n! \n! Double precision coding is used\nimplicit double precision(a-h,o-z)\n! \n! Size the arrays\ndimension u(neqn), ut(neqn)\n! \n! Problem parameters\ncall par(a,b)\n! \n! Derivative vector\nut(1)=-a*u(1)+b*u(2)\nut(2)= b*u(1)-a*u(2)\nreturn\n! \n! End of derv\nend", "meta": {"hexsha": "391242c9f85a54bc64173c43935a1376cbdb65ec", "size": 359, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ODE2X2/ODE/derv.f90", "max_stars_repo_name": "cunyizju/Runge-Kutta-ODE-FORTRAN", "max_stars_repo_head_hexsha": "457151ea85dd5b0b04d3fb5a157049ef997f8f67", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-09-30T09:09:38.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-30T09:09:38.000Z", "max_issues_repo_path": "ODE2X2/ODE/derv.f90", "max_issues_repo_name": "cunyizju/Runge-Kutta-ODE-FORTRAN", "max_issues_repo_head_hexsha": "457151ea85dd5b0b04d3fb5a157049ef997f8f67", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ODE2X2/ODE/derv.f90", "max_forks_repo_name": "cunyizju/Runge-Kutta-ODE-FORTRAN", "max_forks_repo_head_hexsha": "457151ea85dd5b0b04d3fb5a157049ef997f8f67", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.0952380952, "max_line_length": 48, "alphanum_fraction": 0.6852367688, "num_tokens": 126, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636754, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6889909916218617}} {"text": " double precision pi,pisq,pisqo6\n parameter(pi=3.1415926535897932385d0,pisq=pi*pi,pisqo6=pisq/6d0)\n\n double precision zip,half,one,two,three,four,eight\n parameter(zip=0d0,half=0.5d0,one=1d0,two=2d0)\n parameter(three=3d0,four=4d0,eight=8d0)\n\n double complex im,impi,czip,cone\n parameter(im=(0d0,1d0),impi=(0d0,3.1415926535897932385d0),\n . czip=(0d0,0d0),cone=(1d0,0d0))\n\n\n\n", "meta": {"hexsha": "3994b859512c8b3103baa0618233c709b2faf334", "size": 411, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "MCFM-JHUGen/TensorReduction/Include/TRconstants.f", "max_stars_repo_name": "tmartini/JHUGen", "max_stars_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-06-08T13:09:28.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-04T19:59:36.000Z", "max_issues_repo_path": "MCFM-JHUGen/TensorReduction/Include/TRconstants.f", "max_issues_repo_name": "tmartini/JHUGen", "max_issues_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 64, "max_issues_repo_issues_event_min_datetime": "2015-06-24T15:08:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-25T04:59:32.000Z", "max_forks_repo_path": "MCFM-JHUGen/TensorReduction/Include/TRconstants.f", "max_forks_repo_name": "tmartini/JHUGen", "max_forks_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2015-05-04T22:15:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-06T10:04:40.000Z", "avg_line_length": 29.3571428571, "max_line_length": 70, "alphanum_fraction": 0.6885644769, "num_tokens": 180, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8991213718636754, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6889909916218617}} {"text": "program factorial\n implicit none\n integer, parameter :: n_min = 0, n_max = 10\n integer :: n, factor, product\n\n do n = n_min, n_max\n product = 1\n do factor = 2, n\n product = product*factor\n end do\n print *, n, product\n end do\n\nend program factorial\n", "meta": {"hexsha": "f0bcdfba5398ca7f4f157f0ecd0c0af03fd7ec5d", "size": 302, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "hands-on/session_01/exercise_01.f90", "max_stars_repo_name": "gjbex/FortranForProgrammers", "max_stars_repo_head_hexsha": "0b23d3a4c325fa833333f83ef5326378e9e5e854", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-15T14:56:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-15T14:56:20.000Z", "max_issues_repo_path": "hands-on/session_01/exercise_01.f90", "max_issues_repo_name": "gjbex/FortranForProgrammers", "max_issues_repo_head_hexsha": "0b23d3a4c325fa833333f83ef5326378e9e5e854", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hands-on/session_01/exercise_01.f90", "max_forks_repo_name": "gjbex/FortranForProgrammers", "max_forks_repo_head_hexsha": "0b23d3a4c325fa833333f83ef5326378e9e5e854", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.1333333333, "max_line_length": 47, "alphanum_fraction": 0.5662251656, "num_tokens": 84, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6889909903098053}} {"text": " Program zhbevd_example\n\n! ZHBEVD Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use blas_interfaces, Only: dznrm2\n Use lapack_example_aux, Only: nagf_file_print_matrix_complex_gen\n Use lapack_interfaces, Only: zhbevd\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nin = 5, nout = 6\n! .. Local Scalars ..\n Complex (Kind=dp) :: scal\n Integer :: i, ifail, info, j, k, kd, ldab, ldz, liwork, lrwork, lwork, n\n Character (1) :: job, uplo\n! .. Local Arrays ..\n Complex (Kind=dp), Allocatable :: ab(:, :), work(:), z(:, :)\n Real (Kind=dp), Allocatable :: rwork(:), w(:)\n Integer, Allocatable :: iwork(:)\n! .. Intrinsic Procedures ..\n Intrinsic :: abs, conjg, max, maxloc, min\n! .. Executable Statements ..\n Write (nout, *) 'ZHBEVD Example Program Results'\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n, kd\n ldab = n\n ldz = n\n liwork = 5*n + 3\n lrwork = 2*n*n + 5*n + 1\n lwork = 2*n*n\n Allocate (ab(ldab,n), work(lwork), z(ldz,n), rwork(lrwork), w(n), &\n iwork(liwork))\n\n! Read A from data file\n\n Read (nin, *) uplo\n If (uplo=='U') Then\n Do i = 1, n\n Read (nin, *)(ab(kd+1+i-j,j), j=i, min(n,i+kd))\n End Do\n Else If (uplo=='L') Then\n Do i = 1, n\n Read (nin, *)(ab(1+i-j,j), j=max(1,i-kd), i)\n End Do\n End If\n\n Read (nin, *) job\n\n! Calculate all the eigenvalues and eigenvectors of A\n Call zhbevd(job, uplo, n, kd, ab, ldab, w, z, ldz, work, lwork, rwork, &\n lrwork, iwork, liwork, info)\n\n Write (nout, *)\n If (info>0) Then\n Write (nout, *) 'Failure to converge.'\n Else\n\n! Print eigenvalues and eigenvectors\n\n Write (nout, *) 'Eigenvalues'\n Do i = 1, n\n Write (nout, 100) i, w(i)\n End Do\n Write (nout, *)\n Flush (nout)\n\n! Normalize the eigenvectors, largest element real\n Do i = 1, n\n rwork(1:n) = abs(z(1:n,i))\n k = maxloc(rwork(1:n), 1)\n scal = conjg(z(k,i))/abs(z(k,i))/dznrm2(n, z(1,i), 1)\n z(1:n, i) = z(1:n, i)*scal\n End Do\n\n! ifail: behaviour on error exit\n! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft\n ifail = 0\n Call nagf_file_print_matrix_complex_gen('General', ' ', n, n, z, ldz, &\n 'Eigenvectors', ifail)\n\n End If\n\n100 Format (3X, I5, 5X, 2F8.4)\n End Program\n", "meta": {"hexsha": "5de2edbb6d5668b535ecdcc3914e884605c78970", "size": 2768, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/zhbevd_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/zhbevd_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/zhbevd_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 30.0869565217, "max_line_length": 90, "alphanum_fraction": 0.5404624277, "num_tokens": 897, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213691605411, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6889909895504671}} {"text": "\nprogram test\n\n use mpi\n\n use quadrature, only: trapezoid\n use functions, only: f, fevals_proc, k\n\n implicit none\n real(kind=8) :: a,b,int_true, int_approx, int_sub, dx_sub\n real(kind=8) :: ab_sub(2) ! to hold a and b for each subinterval\n\n integer :: i,j,jj,n_proc,proc_num, num_procs,ierr,n,fevals_total,nsub\n integer :: nextsub, numsent, sender\n integer, dimension(MPI_STATUS_SIZE) :: status\n\n call MPI_INIT(ierr)\n call MPI_COMM_SIZE(MPI_COMM_WORLD, num_procs, ierr)\n call MPI_COMM_RANK(MPI_COMM_WORLD, proc_num, ierr)\n\n ! All processes set these values so we don't have to broadcast:\n k = 1.d3 ! functions module variable \n a = 0.d0\n b = 2.d0\n int_true = (b-a) + (b**4 - a**4) / 4.d0 - (1.d0/k) * (cos(k*b) - cos(k*a))\n n = 1000\n !nsub = 4\n\n if (num_procs == 1) then\n print *, \"*** Error: need to use at least two processes\"\n go to 999\n endif\n\n\n ! Each process keeps track of number of fevals:\n fevals_proc = 0\n\n if (proc_num==0) then\n int_approx = 0.d0\n print 100, num_procs\n100 format(\"Using \",i3,\" processes\")\n\n print *, \"How many subintervals? \"\n read *, nsub\n\n print 10, int_true\n 10 format(\"true integral: \", es22.14)\n print *, \" \" ! blank line\n endif\n\n call MPI_BARRIER(MPI_COMM_WORLD,ierr) ! wait for process 0 to print\n call MPI_BCAST(nsub, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr)\n\n ! -----------------------------------------\n ! code for Master (Processor 0):\n ! -----------------------------------------\n\n if (proc_num == 0) then\n\n numsent = 0 ! keep track of how many subintervals sent\n\n dx_sub = (b-a) / nsub\n\n ! send the first batch to get all workers working:\n do j=1,min(num_procs-1, nsub)\n ab_sub(1) = a + (j-1)*dx_sub\n ab_sub(2) = a + j*dx_sub\n call MPI_SEND(ab_sub, 2, MPI_DOUBLE_PRECISION, j, j, &\n MPI_COMM_WORLD, ierr)\n numsent = numsent + 1\n enddo\n\n ! as results come back, send out more work...\n ! the variable sender tells who sent back a result and ready for more\n do j=1,nsub\n call MPI_RECV(int_sub, 1, MPI_DOUBLE_PRECISION, &\n MPI_ANY_SOURCE, MPI_ANY_TAG, &\n MPI_COMM_WORLD, status, ierr)\n sender = status(MPI_SOURCE)\n jj = status(MPI_TAG)\n ! print *,\"+++ int_sub, int_approx: \",int_sub, int_approx\n int_approx = int_approx + int_sub\n\n if (numsent < nsub) then\n ! still more work to do, the next subinterval will be sent and\n ! this index also used as the tag:\n nextsub = numsent + 1 \n ab_sub(1) = a + (nextsub-1)*dx_sub\n ab_sub(2) = a + nextsub*dx_sub\n \n call MPI_SEND(ab_sub, 2, MPI_DOUBLE_PRECISION, sender, nextsub, &\n MPI_COMM_WORLD, ierr)\n numsent = numsent + 1\n else\n ! send an empty message with tag=0 to indicate this worker\n ! is done:\n call MPI_SEND(MPI_BOTTOM, 0, MPI_INTEGER, &\n sender, 0, MPI_COMM_WORLD, ierr)\n endif\n enddo\n endif\n\n ! -----------------------------------------\n ! code for Workers (Processors 1, 2, ...):\n ! -----------------------------------------\n if (proc_num /= 0) then\n\n if (proc_num > nsub) go to 99 ! no work expected\n\n do while (.true.)\n ! repeat until message with tag==0 received...\n\n call MPI_RECV(ab_sub, 2, MPI_DOUBLE_PRECISION, &\n 0, MPI_ANY_TAG, &\n MPI_COMM_WORLD, status, ierr)\n\n j = status(MPI_TAG) ! this is the subinterval number\n\n !print 12, proc_num, j ! for debugging\n12 format(\"+++ Process \",i4,\" received message with tag \",i6)\n\n if (j==0) go to 99 ! received \"done\" message\n\n int_sub = trapezoid(f,ab_sub(1),ab_sub(2),n)\n\n call MPI_SEND(int_sub, 1, MPI_DOUBLE_PRECISION, &\n 0, j, MPI_COMM_WORLD, ierr)\n\n enddo\n endif\n\n99 continue ! might jump to here if finished early\n\n\n call MPI_BARRIER(MPI_COMM_WORLD,ierr) ! wait for all process to print\n\n ! print the number of function evaluations by each thread:\n print 101, proc_num, fevals_proc\n101 format(\"fevals by Process \",i2,\": \",i13)\n\n call MPI_BARRIER(MPI_COMM_WORLD,ierr) ! wait for all process to print\n\n call MPI_REDUCE(fevals_proc, fevals_total, 1, MPI_INTEGER, MPI_SUM, 0, &\n MPI_COMM_WORLD, ierr)\n\n if (proc_num==0) then\n print 13, nsub*n, int_approx\n13 format(\"Trapezoid approximation with \",i8,\" total points: \",es22.14)\n print 102, fevals_total\n102 format(\"Total number of fevals: \",i10)\n endif\n\n999 continue\n call MPI_FINALIZE(ierr)\n\nend program test\n", "meta": {"hexsha": "823458b5969b659a188455e1955c53108d088fa5", "size": 4946, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/2013/solutions/project/part1/test3.f90", "max_stars_repo_name": "philipwangdk/HPC", "max_stars_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "uwhpsc/2013/solutions/project/part1/test3.f90", "max_issues_repo_name": "philipwangdk/HPC", "max_issues_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "uwhpsc/2013/solutions/project/part1/test3.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": 31.5031847134, "max_line_length": 78, "alphanum_fraction": 0.5596441569, "num_tokens": 1340, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.828938825225204, "lm_q2_score": 0.8311430562234877, "lm_q1q2_score": 0.6889667486199836}} {"text": "!-*- mode: compilation; default-directory: \"/tmp/\" -*-\n!Compilation started at Tue May 21 21:43:12\n!\n!a=./f && make $a && OMP_NUM_THREADS=2 $a 1223334444\n!gfortran -std=f2008 -Wall -ffree-form -fall-intrinsics f.f08 -o f\n! Shannon entropy of 1223334444 is 1.84643936\n!\n!Compilation finished at Tue May 21 21:43:12\n\nprogram shannonEntropy\n implicit none\n integer :: num, L, status\n character(len=2048) :: s\n num = 1\n call get_command_argument(num, s, L, status)\n if ((0 /= status) .or. (L .eq. 0)) then\n write(0,*)'Expected a command line argument with some length.'\n else\n write(6,*)'Shannon entropy of '//(s(1:L))//' is ', se(s(1:L))\n endif\n\ncontains\n ! algebra\n !\n ! 2**x = y\n ! x*log(2) = log(y)\n ! x = log(y)/log(2)\n\n ! NB. The j solution\n ! entropy=: +/@:-@(* 2&^.)@(#/.~ % #)\n ! entropy '1223334444'\n !1.84644\n\n real function se(s)\n implicit none\n character(len=*), intent(in) :: s\n integer, dimension(256) :: tallies\n real, dimension(256) :: norm\n tallies = 0\n call TallyKey(s, tallies)\n ! J's #/. works with the set of items in the input.\n ! TallyKey is sufficiently close that, with the merge, gets the correct result.\n norm = tallies / real(len(s))\n se = sum(-(norm*log(merge(1.0, norm, norm .eq. 0))/log(2.0)))\n end function se\n\n subroutine TallyKey(s, counts)\n character(len=*), intent(in) :: s\n integer, dimension(256), intent(out) :: counts\n integer :: i, j\n counts = 0\n do i=1,len(s)\n j = iachar(s(i:i))\n counts(j) = counts(j) + 1\n end do\n end subroutine TallyKey\n\nend program shannonEntropy\n", "meta": {"hexsha": "9b2e70c195687de234398c41c50a4f0ddc8403a2", "size": 1606, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Entropy/Fortran/entropy.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/Entropy/Fortran/entropy.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/Entropy/Fortran/entropy.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 27.2203389831, "max_line_length": 83, "alphanum_fraction": 0.6120797011, "num_tokens": 549, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619883, "lm_q2_score": 0.8031738010682209, "lm_q1q2_score": 0.6889368751605736}} {"text": "! { dg-do link }\n!\n! This test checks whether the largest possible\n! floating-point number works. That's usually\n! REAL(16) -- either because the hardware supports it or\n! because of libquadmath. However, it can also be\n! REAL(10) or REAL(8)\n!\nprogram test_qp\n use iso_fortran_env, only: real_kinds\n implicit none\n integer, parameter :: QP = real_kinds(ubound(real_kinds,dim=1))\n real(QP), parameter :: Z1 = 1,HALF_PI = asin(Z1),PI = HALF_PI+HALF_PI\n real(QP) :: x = 0.124_QP\n complex(QP) :: z = 0.124_QP\n print *, 'kind = ', qp\n print *, x\n print *, PI\n print *, 16*atan(0.2_QP)-4*atan(Z1/239)\n print *, sin(PI)\n print *, cos(HALF_PI)\n print *, asinh(PI)\n print *, erfc(Z1)\n print *, epsilon(x)\n print *, precision(x)\n print *, digits(x)\n\n print *, z\n print *, PI*cmplx(0.0_qp, 1.0_qp)\n! Disable the complex functions as not all \"long-double\" systems have\n! a libm with those C99 functions. (libquadmath had), cf. PR 46584\n! print *, 16*atan(0.2_QP)-4*atan(Z1/239)\n! print *, sin(z)\n! print *, cos(z)\n! print *, sinh(z) ! asinh not implemented in libquadmath, cf. PR 46416\n print *, precision(z)\nend program test_qp\n", "meta": {"hexsha": "e75faacdb4a152ab264fea37f5dd4c2691de62b7", "size": 1165, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/quad_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/quad_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/quad_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": 30.6578947368, "max_line_length": 73, "alphanum_fraction": 0.6497854077, "num_tokens": 394, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681195338728, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.6889368749393313}} {"text": "!*******************************************************************\n!> author: Akira Kageyama\n! date: 2020.01.15\n!\n! Fortran\u5b9a\u6570\u3068\u6570\u5b66\u5b9a\u6570\n!\n!@note \u5b9a\u6570\u3067\u3042\u308b\u3053\u3068\u304c\u76ee\u3067\u898b\u3066\u308f\u304b\u308a\u3084\u3059\u3044\u3088\u3046\u306b\u5168\u3066\u306e\u6587\u5b57\u3092\n! \u5927\u6587\u5b57\u3067\u66f8\u304f\u3002\u30b3\u30f3\u30d1\u30a4\u30e9\u306b\u306f\u7121\u610f\u5473\u3067\u3042\u308b\u306e\u3067\u3001\n! si\u3068\u304bSi\u3068\u3044\u3063\u305f\u5909\u6570\u3092\u4f7f\u308f\u306a\u3044\u3088\u3046\u306b\u6ce8\u610f\u3002\n\nmodule constants_m\n implicit none\n\n ! << f90 constants >>\n integer, parameter :: SI = selected_int_kind(8) !! \u5358\u7cbe\u5ea6\u6574\u6570\u7a2e\u5225\u5024\n integer, parameter :: DI = selected_int_kind(16) !! \u500d\u7cbe\u5ea6\u6574\u6570\u7a2e\u5225\u5024\n integer, parameter :: SR = selected_real_kind(6) !! \u5358\u7cbe\u5ea6\u5b9f\u6570\u7a2e\u5225\u5024\n integer, parameter :: DR = selected_real_kind(12) !! \u500d\u7cbe\u5ea6\u5b9f\u6570\u7a2e\u5225\u5024\n\n ! << Mathematical constants >>\n real(DR), parameter :: PI = 3.1415926535897932_DR !! \u5186\u5468\u7387\n real(DR), parameter :: TWOPI = PI*2 !! \u5186\u5468\u7387\u306e2\u500d\nend module constants_m\n", "meta": {"hexsha": "2edfe8ab715a517dd399851909773735c2026027", "size": 729, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "warming_up/burgers_equation/doc/src/constants.f90", "max_stars_repo_name": "akageyama/class-hpc-smoke-ring", "max_stars_repo_head_hexsha": "2726669e9c84fca21337408be2a2ab838fa4c789", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "warming_up/burgers_equation/doc/src/constants.f90", "max_issues_repo_name": "akageyama/class-hpc-smoke-ring", "max_issues_repo_head_hexsha": "2726669e9c84fca21337408be2a2ab838fa4c789", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "warming_up/burgers_equation/doc/src/constants.f90", "max_forks_repo_name": "akageyama/class-hpc-smoke-ring", "max_forks_repo_head_hexsha": "2726669e9c84fca21337408be2a2ab838fa4c789", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2019-01-17T05:09:10.000Z", "max_forks_repo_forks_event_max_datetime": "2019-01-24T06:56:38.000Z", "avg_line_length": 30.375, "max_line_length": 68, "alphanum_fraction": 0.6172839506, "num_tokens": 317, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8577681195338728, "lm_q2_score": 0.8031737869342623, "lm_q1q2_score": 0.6889368688775016}} {"text": "program realcomp\n ! This program tests and compares the performance\n ! of single and double precision real problems\n !use ifport\n use flips\n use rand\n\n implicit none\n\n ! types\n type(flips_s) :: gs\n type(flips_d) :: gd\n\n ! data matrices\n real(sp), dimension(:,:), allocatable :: amat_s, smat_s, mmat_s\n real(dp), dimension(:,:), allocatable :: amat_d, smat_d, mmat_d\n\n\n ! Errors\n real(sp) :: maxerr_s,meanerr_s\n real(dp) :: maxerr_d,meanerr_d\n\n\n ! Residuals\n real(sp) :: res_s\n real(dp) :: res_d\n \n\n ! Clocks/times\n real(dp) :: cts,cte,ctime1,ctime2\n real(sp) :: wts,wte,wtime1,wtime2\n\n ! Aux variables\n integer :: ns,n,bs,id = 0\n\n ! Set random seed\n call set_rand_seed()\n\n ! Ask size\n write(*,*) 'Give matrix size:'\n read(*,*) ns\n write(*,*) 'Press 1 for binary files.'\n read(*,*) id\n\n bs = 10\n\n ! allocate things\n allocate(amat_s(ns,ns),amat_d(ns,ns),smat_s(ns,1),smat_d(ns,1),mmat_s(ns,1),mmat_d(ns,1))\n\n ! Single pprecision\n\n ! Create data (theory matrix random, soluton 1's)\n call random_number(amat_s)\n smat_s = 1.0\n mmat_s = matmul(amat_s,smat_s)\n\n ! init flips\n if (id==1) then\n call flips_init(gs,ns,1,idnum=100,buffersize=bs)\n\nwrite(*,*) 'FLIPS initialized'\n\n else\n call flips_init(gs,ns,1,buffersize=bs)\n end if\n \n!write(*,*) 'initialized' \n\n ! add data and solve with residual\n call cpu_time(cts)\n !call system_clock(wts)\n do n = 1,ns\n call flips_add(gs,1,amat_s(n,:),mmat_s(n,:))\n\nwrite(*,*) 'FLIPS data row added. n=',n\n\n end do\n!write(*,*) 'data added'\n call flips_solve(gs)\n\nwrite(*,*) 'FLIPS solved'\n\n!write(*,*) 'solved'\n call cpu_time(cte)\n !call system_clock(wte)\n !wtime1 = wte-wts\n ctime1 = cte-cts\n\n ! Calculate diagonal of the covariance\n call cpu_time(cts)\n !call system_clock(wts)\n call flips_calc_cov(gs,full=.TRUE.)\n\nwrite(*,*) 'FLIPS Covariance calculated'\n\n!write(*,*) 'covariance calculated'\n call cpu_time(cte)\n !call system_clock(wte)\n !wtime2 = wte-wts\n ctime2 = cte-cts\n\n if (id==1) then\n allocate(gs%solmat(ns),gs%cmat(ns))\n call flips_get('solu',gs,gs%solmat)\n\nwrite(*,*) 'FLIPS solution fetched'\n\n !call flips_get('cova',gs,gs%cmat)\n!write(*,*) 'solution got'\n end if\n\n ! Errors\n maxerr_s = maxval(abs(smat_s(:,1) - gs%solmat))\n meanerr_s = sum(smat_s(:,1) - gs%solmat)/ns\n\n ! Print results\n write(*,*) '----------------------------------'\n write(*,*) 'Single precision, size:',ns\n write(*,*) '----------------------------------'\n write(*,*) ' Solution, CPU time:',ctime1\n write(*,*) ' FLOP Count:',gs%fc\n write(*,*) ' GFLOPS:',gs%fc/ctime1/1.0E9\n !write(*,*) 'Solution, wall clock:',wtime1\n write(*,*) 'Covariance, CPU time:',ctime2\n !write(*,*) 'Covariance, wall clock:',wtime2\n write(*,*) ' Mean error:',meanerr_s\n write(*,*) ' Max. abs. error:',maxerr_s\n write(*,*) ' Residual:',gs%residual\n !write(*,*) gs%cmat\n write(*,*) '----------------------------------\\n'\n\n\n\n ! Double precision\n ! Create data (theory matrix random, soluton 1's)\n call random_number(amat_d)\n smat_d = 1.0D0\n mmat_d = matmul(amat_d,smat_d)\n\n ! init flips\n if (id==1) then\n call flips_init(gd,ns,1,idnum=200,buffersize=bs)\n else\n call flips_init(gd,ns,1,buffersize=bs)\n end if\n ! add data and solve with residual\n call cpu_time(cts)\n !call system_clock(wts)\n do n = 1,ns\n call flips_add(gd,1,amat_d(n,:),mmat_d(n,:))\n end do\n call flips_solve(gd)\n call cpu_time(cte)\n !call system_clock(wte)\n !wtime1 = wte-wts\n ctime1 = cte-cts\n\n ! Calculate diagonal of the covariance\n call cpu_time(cts)\n !call system_clock(wts)\n call flips_calc_cov(gd,full=.TRUE.)\n call cpu_time(cte)\n !call system_clock(wte)\n !wtime2 = wte-wts\n ctime2 = cte-cts\n\n if (id==1) then\n allocate(gd%solmat(ns))\n call flips_get('solu',gd,gd%solmat)\n end if\n\n ! Errors\n maxerr_d = maxval(abs(smat_d(:,1) - gd%solmat))\n meanerr_d = sum(smat_d(:,1) - gd%solmat)/ns\n\n ! Print results\n write(*,*) '----------------------------------'\n write(*,*) 'Double precision, size:',ns\n write(*,*) '----------------------------------'\n write(*,*) ' Solution, CPU time:',ctime1\n write(*,*) ' FLOP Count:',gd%fc\n write(*,*) ' GFLOPS:',gd%fc/ctime1/1.0D9\n !write(*,*) 'Solution, wall clock:',wtime1\n write(*,*) 'Covariance, CPU time:',ctime2\n !write(*,*) 'Covariance, wall clock:',wtime2\n write(*,*) ' Mean error:',meanerr_d\n write(*,*) ' Max. abs. error:',maxerr_d\n write(*,*) ' Residual:',gd%residual\n !write(*,*) gd%solmat(1:5)\n write(*,*) '----------------------------------\\n'\n\n\n\n\n\nend program realcomp\n", "meta": {"hexsha": "e61d46fcc541c7cc7928b9a6ef6a499415fd0dcb", "size": 4634, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/real_comp.f90", "max_stars_repo_name": "morispaa/flips", "max_stars_repo_head_hexsha": "f6c98bd33bf01261f98db3a5bd581c2adbe4e2e7", "max_stars_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-12-03T09:16:08.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-03T09:16:08.000Z", "max_issues_repo_path": "tests/real_comp.f90", "max_issues_repo_name": "morispaa/flips", "max_issues_repo_head_hexsha": "f6c98bd33bf01261f98db3a5bd581c2adbe4e2e7", "max_issues_repo_licenses": ["BSD-2-Clause-FreeBSD"], "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/real_comp.f90", "max_forks_repo_name": "morispaa/flips", "max_forks_repo_head_hexsha": "f6c98bd33bf01261f98db3a5bd581c2adbe4e2e7", "max_forks_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.5228426396, "max_line_length": 91, "alphanum_fraction": 0.5953819594, "num_tokens": 1600, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680904463333, "lm_q2_score": 0.8031738034238807, "lm_q1q2_score": 0.6889368596594208}} {"text": "\tFUNCTION PR_PKSS ( pspd ) \nC************************************************************************\nC* PR_PKSS\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes SPED from PSPD. PSPD is in the form DDFFF,\t*\nC* where DD is the wind direction in tens of degrees, and FFF is\t*\nC* either the wind speed or the wind speed plus 500, depending on\t*\nC* the unit digit of direction rounded to the nearest 5 degrees.\t*\nC* The following equation is used:\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* SPED = MOD ( INT (PSPD) , 500 )\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PR_PKSS ( PSPD )\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*\tPSPD\t\tREAL\t\tPacked speed and direction\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPR_PKSS\t\tREAL\t\tWind speed in knots\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* I. Graffman/CSC\t8/83\tOriginal source code\t\t\t*\nC* G. Huffman/GSC\t8/88\tDocumentation and modulus fix\t\t*\nC************************************************************************\n INCLUDE 'GEMPRM.PRM'\n INCLUDE 'ERMISS.FNC'\nC------------------------------------------------------------------------\nC*\tCheck for missing values.\nC\n\tIF ( ERMISS (pspd) ) THEN\n\t PR_PKSS = RMISSD\nC\nC* Formally, SPED is MOD ( PSPD, 1000 ), with 500 subtracted off if\nC* needed, but 1000 is a multiple of 500, so it is done in 1 step.\nC\n\t ELSE\n\t PR_PKSS = MOD ( IFIX (pspd), 500 )\n\tEND IF\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "0b064a17539dc67d0f66307254909f6247e4d25a", "size": 1379, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/pr/prpkss.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/prpkss.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/prpkss.f", "max_forks_repo_name": "oxelson/gempak", "max_forks_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 27, "max_forks_repo_forks_event_min_datetime": "2016-06-06T21:55:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T18:23:28.000Z", "avg_line_length": 32.8333333333, "max_line_length": 73, "alphanum_fraction": 0.5032632342, "num_tokens": 414, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096227509861, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6889259552510859}} {"text": "SUBROUTINE CHEGVX_F95( A, B, W, ITYPE, JOBZ, UPLO, VL, VU, IL, IU, &\n & M, IFAIL, ABSTOL, INFO )\n! .. USE STATEMENTS ..\n USE LA_PRECISION, ONLY: WP => SP\n USE LA_AUXMOD, ONLY: ERINFO, LSAME\n USE F77_LAPACK, ONLY: LAMCH_F77 => SLAMCH\n USE F77_LAPACK, ONLY: HEGVX_F77 => LA_HEGVX, ILAENV_F77 => ILAENV\n! .. IMPLICIT STATEMENT ..\n IMPLICIT NONE\n! .. CHARACTER ARGUMENTS ..\n CHARACTER(LEN=1), INTENT(IN), OPTIONAL :: JOBZ, UPLO\n! .. SCALAR ARGUMENTS ..\n INTEGER, INTENT(IN), OPTIONAL :: IL, IU, ITYPE\n INTEGER, INTENT(OUT), OPTIONAL :: INFO, M\n REAL(WP), INTENT(IN), OPTIONAL :: ABSTOL, VL, VU\n! .. ARRAY ARGUMENTS ..\n INTEGER, INTENT(OUT), OPTIONAL, TARGET :: IFAIL(:)\n COMPLEX(WP), INTENT(INOUT) :: A(:,:), B(:,:)\n REAL(WP), INTENT(OUT) :: W(:)\n!----------------------------------------------------------------------\n! \n! Purpose\n! =======\n! \n! LA_SYGVX and LA_HEGVX compute selected eigenvalues and, optionally,\n! the corresponding eigenvectors of generalized eigenvalue problems of \n! the form \n! A*z = lambda*B*z, A*B*z = lambda*z, and B*A*z = lambda*z,\n! where A and B are real symmetric in the case of LA_SYGVX and complex\n! Hermitian in the case of LA_HEGVX. In both cases B is positive \n! definite. Eigenvalues and eigenvectors can be selected by specifying\n! either a range of values or a range of indices for the desired \n! eigenvalues.\n! \n! =========\n! \n! SUBROUTINE LA_SYGVX / LA_HEGVX (A, B, W, ITYPE= itype, &\n! JOBZ= jobz, UPLO= uplo, VL= vl, VU= vu, IL= il, &\n! IU= iu, M= m, IFAIL= ifail, ABSTOL= abstol, INFO= info )\n! (), INTENT(INOUT) :: A(:,:), B(:,:)\n! REAL(), INTENT(OUT) :: W(:)\n! INTEGER, INTENT(IN), OPTIONAL :: ITYPE\n! CHARACTER(LEN=1), INTENT(IN), OPTIONAL :: JOBZ, UPLO\n! REAL(), INTENT(IN), OPTIONAL :: VL, VU\n! INTEGER, INTENT(IN), OPTIONAL :: IL, IU\n! INTEGER, INTENT(OUT), OPTIONAL :: M\n! INTEGER, INTENT(OUT), OPTIONAL :: IFAIL(:)\n! REAL(), INTENT(IN), OPTIONAL :: ABSTOL\n! INTEGER, INTENT(OUT), OPTIONAL :: INFO\n! where\n! ::= REAL | COMPLEX\n! ::= KIND(1.0) | KIND(1.0D0)\n! \n! Arguments\n! =========\n! \n! A (input/output) REAL or COMPLEX square array, shape (:,:).\n! On entry, the matrix A.\n! If UPLO = 'U', the upper triangular part of A contains the \n! upper triangular part of matrix A. If UPLO = 'L', the lower\n! triangular part of A contains the lower triangular part of \n! matrix A.\n! On exit, if JOBZ = 'V', the first M columns of A contain the\n! orthonormal eigenvectors corresponding to the selected \n! eigenvalues, with the i-th column of A holding the eigenvector\n! associated with the eigenvalue in W(i).\n! The eigenvectors are normalized as follows:\n! if ITYPE = 1 or 2: Z^H * B * Z = I ,\n! if ITYPE = 3: Z^H * B^-1 * Z = I .\n! If an eigenvector fails to converge, then that column of A \n! contains the latest approximation to the eigenvector and the \n! index of the eigenvector is returned in IFAIL.\n! If JOBZ = 'N', then the upper triangle (if UPLO = 'U') or the \n! lower triangle (if UPLO = 'L') of A, including the diagonal, is\n! destroyed.\n! B (input/output) REAL or COMPLEX square array, shape (:,:) with \n! size(B,1) = size(A,1).\n! On entry, the matrix B.\n! If UPLO = 'U', the upper triangular part of B contains the \n! upper triangular part of matrix B. If UPLO = 'L', the lower\n! triangular part of B contains the lower triangular part of \n! matrix B.\n! On exit, the part of B containing the matrix is overwritten by \n! the triangular factor U or L of the Cholesky factorization \n! B = U^H*U or B = L*L^H.\n! W (output) REAL array, shape (:) with size(W) = size(A,1).\n! The first M elements contain the selected eigenvalues in \n! ascending order.\n! ITYPE Optional (input) INTEGER.\n! Specifies the problem type to be solved:\n! = 1: A*z = lambda*B*z\n! = 2: A*B*z = lambda*z\n! = 3: B*A*z = lambda*z\n! Default value: 1.\n! JOBZ Optional (input) CHARACTER(LEN=1).\n! = 'N': Computes eigenvalues only;\n! = 'V': Computes eigenvalues and eigenvectors.\n! Default value: 'N'.\n! UPLO Optional (input) CHARACTER(LEN=1).\n! = 'U': Upper triangles of A and B are stored;\n! = 'L': Lower triangles of A and B are stored.\n! Default value: 'U'.\n! VL,VU Optional (input) REAL.\n! The lower and upper bounds of the interval to be searched for\n! eigenvalues. VL < VU.\n! Default values: VL = -HUGE() and VU = HUGE(), where \n! ::= KIND(1.0) | KIND(1.0D0).\n! Note: Neither VL nor VU may be present if IL and/or IU is\n! present.\n! IL,IU Optional (input) INTEGER.\n! The indices of the smallest and largest eigenvalues to be \n! returned. The IL-th through IU-th eigenvalues will be found. \n! 1<=IL<=IU<=size(A,1).\n! Default values: IL = 1 and IU = size(A,1).\n! Note: Neither IL nor IU may be present if VL and/or VU is\n! present.\n! Note: All eigenvalues are calculated if none of the arguments\n! VL, VU, IL and IU are present.\n! M Optional (output) INTEGER.\n! The total number of eigenvalues found. 0 <= M <= size(A,1).\n! Note: If IL and IU are present then M = IU - IL + 1.\n! IFAIL Optional (output) INTEGER array, shape (:) with size(IFAIL) = \n! size(A,1).\n! If INFO = 0, the first M elements of IFAIL are zero.\n! If INFO > 0, then IFAIL contains the indices of the \n! eigenvectors that failed to converge.\n! Note: IFAIL should be present if JOBZ = 'V'.\n! ABSTOL Optional (input) REAL.\n! The absolute error tolerance for the eigenvalues. An approximate\n! eigenvalue is accepted as converged when it is determined to lie\n! in an interval [a,b] of width less than or equal to\n! ABSTOL + EPSILON(1.0_) * max(| a |, | b |),\n! where is the working precision. If ABSTOL <= 0, then\n! EPSILON(1.0_)* ||T||1 will be used in its place, where \n! ||T||1 is the l1 norm of the tridiagonal matrix obtained by \n! reducing the generalized eigenvalue problem to tridiagonal form. \n! Eigenvalues will be computed most accurately when ABSTOL is set\n! to twice the underflow threshold 2 * LA_LAMCH(1.0_, 'S'),\n! not zero.\n! Default value: 0.0_.\n! Note: If this routine returns with 0 < INFO <= n, then some \n! eigenvectors did not converge.\n! Try setting ABSTOL to 2 * LA_LAMCH(1.0_, 'S').\n! INFO Optional (output) INTEGER.\n! = 0: successful exit.\n! < 0: if INFO = -i, the i-th argument had an illegal value.\n! > 0: the algorithm failed to converge or matrix B is not\n! positive definite:\n! <= n: the algorithm failed to converge; if INFO = i, then i\n! \t eigenvectors failed to converge. Their indices are stored\n! \t in array IFAIL.\n! > n: if INFO = n+i, for 1 <= i <= n, then the leading minor \n! \t of order i of B is not positive definite. The \n! \t factorization of B could not be completed and no \n! \t eigenvalues or eigenvectors were computed.\n! \t n is the order of A.\n! If INFO is not present and an error occurs, then the program is\n! terminated with an error message.\n!-----------------------------------------------------------------------\n! .. LOCAL PARAMETERS ..\n CHARACTER(LEN=8), PARAMETER :: SRNAME = 'LA_HEGVX'\n CHARACTER(LEN=6), PARAMETER :: BSNAME = 'ZHETRD'\n! .. LOCAL SCALARS ..\n CHARACTER(LEN=1) :: LJOBZ, LUPLO, LRANGE\n INTEGER :: N, LINFO, LDA, LDZ, LZ, LIL, LIU, LM, LWORK, NB, ISTAT, &\n & SIFAIL, LDB, LITYPE\n INTEGER, TARGET :: ISTAT1(1)\n REAL(WP) :: LABSTOL, LVL, LVU\n! .. LOCAL ARRAYS ..\n INTEGER, POINTER :: IWORK(:), LIFAIL(:)\n COMPLEX(WP), POINTER :: WORK(:), Z(:,:)\n REAL(WP), POINTER :: RWORK(:)\n! .. INTRINSIC FUNCTIONS ..\n INTRINSIC HUGE, PRESENT, SIZE\n! .. EXECUTABLE STATEMENTS ..\n N = SIZE(A,1); LDA = MAX(1,N); LDB=MAX(1,SIZE(B,1)); LINFO = 0; ISTAT = 0\n IF( PRESENT(ITYPE) )THEN; LITYPE = ITYPE; ELSE; LITYPE = 1; END IF \n IF( PRESENT(IFAIL) )THEN; SIFAIL = SIZE(IFAIL);ELSE; SIFAIL = N; END IF\n IF( PRESENT(JOBZ ) )THEN; LJOBZ=JOBZ; ELSE; LJOBZ = 'N'; ENDIF\n IF( PRESENT(UPLO) ) THEN; LUPLO = UPLO; ELSE; LUPLO = 'U'; END IF\n IF( PRESENT(VL) )THEN; LVL = VL; ELSE; LVL = -HUGE(LVL); ENDIF\n IF( PRESENT(VU) )THEN; LVU = VU; ELSE; LVU = HUGE(LVU); ENDIF\n IF( PRESENT(IL) )THEN; LIL = IL; ELSE; LIL = 1; ENDIF\n IF( PRESENT(IU) )THEN; LIU = IU; ELSE; LIU = N; ENDIF\n! .. TEST THE ARGUMENTS\n IF( PRESENT(VL) .OR. PRESENT(VU) )THEN ; LRANGE = 'V'; LM=N\n ELSE IF( PRESENT(IL) .OR. PRESENT(IU) )THEN ; LRANGE = 'I'; LM=LIU-LIL+1\n ELSE ; LRANGE = 'A'; LM=N; END IF\n IF( SIZE( A, 2 ) /= N .OR. N < 0 )THEN; LINFO = -1\n ELSE IF (SIZE (B, 2) /= N ) THEN; LINFO = -2\n ELSE IF( SIZE( W ) /= N )THEN; LINFO = -3\n ELSE IF( LITYPE < 1 .OR. LITYPE > 3 )THEN; LINFO = -4\n ELSE IF( .NOT.LSAME(LJOBZ,'V') .AND. .NOT.LSAME(LJOBZ,'N') )THEN; LINFO = -5\n ELSE IF( .NOT.LSAME(LUPLO,'U') .AND. .NOT.LSAME(LUPLO,'L') )THEN; LINFO = -6\n ELSE IF( LVU < LVL )THEN ; LINFO = -7\n ELSE IF( (PRESENT(VL) .OR. PRESENT(VU)) .AND. &\n (PRESENT(IL) .OR. PRESENT(IU)) )THEN; LINFO = -8\n ELSE IF( LSAME(LRANGE, 'I') .AND. ( LIU < MIN( N, LIL ) .OR. LIU>N))THEN; LINFO = -9\n ELSE IF( N < LIU )THEN; LINFO = -10\n ELSE IF( SIFAIL /= N )THEN; LINFO = -12\n ELSE IF( N > 0 )THEN\n\n IF(LSAME(LJOBZ, 'V')) THEN\n LDZ = MAX(1,N); LZ=LM\n ELSE\n LDZ = 1; LZ=1\n ENDIF\n IF( PRESENT(IFAIL) )THEN; LIFAIL => IFAIL\n ELSE; ALLOCATE( LIFAIL(N), STAT=ISTAT ); END IF\n! .. DETERMINE THE WORKSPACE\n NB = ILAENV_F77( 1, BSNAME, LUPLO, N, -1, -1, -1 )\n IF( NB < 5 .OR. NB >= N )THEN\n NB = 5\n END IF\n LWORK = N*(3+NB)\n \n ALLOCATE(Z(LDZ, LZ), STAT=ISTAT)\n IF (ISTAT /= 0) LINFO = -100\n \n ALLOCATE(IWORK(10*5*N), WORK(10*LWORK), RWORK(7*N), STAT=ISTAT)\n IF( ISTAT /= 0 )THEN\n DEALLOCATE(IWORK, WORK, STAT=ISTAT1(1))\n LWORK = N*8*10\n ALLOCATE(IWORK(10*5*N), WORK(LWORK), RWORK(7 *N), STAT=ISTAT)\n IF( ISTAT /= 0 ) THEN\n LINFO = - 100\n ELSE\n CALL ERINFO( -200, SRNAME, LINFO )\n ENDIF\n END IF\n IF( LINFO == 0 )THEN\n IF( PRESENT(ABSTOL) )THEN; LABSTOL = ABSTOL\n ELSE; LABSTOL = 2*LAMCH_F77('Safe minimum'); ENDIF\n! .. CALL LAPACK77 ROUTINE\n\t CALL HEGVX_F77( LITYPE, LJOBZ, LRANGE, LUPLO, N, A, LDA, B, &\n & LDB, LVL, LVU, LIL, LIU, LABSTOL, LM, W, Z, LDZ, WORK, &\n & LWORK, RWORK, IWORK, LIFAIL, LINFO )\n\n IF( PRESENT(M) ) M = LM\n\t IF (LSAME(LJOBZ,'V')) A(1:LDZ, 1:LM)=Z(1:LDZ, 1:LM)\n END IF\n DEALLOCATE(IWORK, WORK, RWORK, STAT=ISTAT1(1))\n DEALLOCATE(Z, STAT=ISTAT)\n END IF\n CALL ERINFO(LINFO,SRNAME,INFO,ISTAT)\nEND SUBROUTINE CHEGVX_F95\n", "meta": {"hexsha": "f35fdc8881ed96da3a35094cff7488c79a5528bd", "size": 11371, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "code_1D/couplage_1D/fortran90_source/liblapack95/SRC/la_chegvx.f90", "max_stars_repo_name": "IRFM/ALOHA", "max_stars_repo_head_hexsha": "e8e7a47a70c7095b339b3dea25dcd4b95f382959", "max_stars_repo_licenses": ["CECILL-B"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-12-29T15:07:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T10:09:22.000Z", "max_issues_repo_path": "code_1D/couplage_1D/fortran90_source/liblapack95/SRC/la_chegvx.f90", "max_issues_repo_name": "IRFM/ALOHA", "max_issues_repo_head_hexsha": "e8e7a47a70c7095b339b3dea25dcd4b95f382959", "max_issues_repo_licenses": ["CECILL-B"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-02-21T10:46:38.000Z", "max_issues_repo_issues_event_max_datetime": "2017-10-20T17:03:14.000Z", "max_forks_repo_path": "code_1D/couplage_1D/fortran90_source/liblapack95/SRC/la_chegvx.f90", "max_forks_repo_name": "IRFM/ALOHA", "max_forks_repo_head_hexsha": "e8e7a47a70c7095b339b3dea25dcd4b95f382959", "max_forks_repo_licenses": ["CECILL-B"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-12-29T15:34:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-15T07:12:40.000Z", "avg_line_length": 46.036437247, "max_line_length": 87, "alphanum_fraction": 0.5732125583, "num_tokens": 3717, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.91610961358942, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.68892595345305}} {"text": " SUBROUTINE DF01MD( SICO, N, DT, A, DWORK, INFO )\r\nC\r\nC SLICOT RELEASE 5.5.\r\nC\r\nC Copyright (c) 2002-2012 NICONET e.V.\r\nC\r\nC PURPOSE\r\nC\r\nC To compute the sine transform or cosine transform of a real\r\nC signal.\r\nC\r\nC ARGUMENTS\r\nC\r\nC Mode Parameters\r\nC\r\nC SICO CHARACTER*1\r\nC Indicates whether the sine transform or cosine transform\r\nC is to be computed as follows:\r\nC = 'S': The sine transform is computed;\r\nC = 'C': The cosine transform is computed.\r\nC\r\nC Input/Output Parameters\r\nC\r\nC N (input) INTEGER\r\nC The number of samples. N must be a power of 2 plus 1.\r\nC N >= 5.\r\nC\r\nC DT (input) DOUBLE PRECISION\r\nC The sampling time of the signal.\r\nC\r\nC A (input/output) DOUBLE PRECISION array, dimension (N)\r\nC On entry, this array must contain the signal to be\r\nC processed.\r\nC On exit, this array contains either the sine transform, if\r\nC SICO = 'S', or the cosine transform, if SICO = 'C', of the\r\nC given signal.\r\nC\r\nC Workspace\r\nC\r\nC DWORK DOUBLE PRECISION array, dimension (N+1)\r\nC\r\nC Error Indicator\r\nC\r\nC INFO INTEGER\r\nC = 0: successful exit;\r\nC < 0: if INFO = -i, the i-th argument had an illegal\r\nC value.\r\nC\r\nC METHOD\r\nC\r\nC Let A(1), A(2),..., A(N) be a real signal of N samples.\r\nC\r\nC If SICO = 'S', the routine computes the sine transform of A as\r\nC follows. First, transform A(i), i = 1,2,...,N, into the complex\r\nC signal B(i), i = 1,2,...,(N+1)/2, where\r\nC\r\nC B(1) = -2*A(2),\r\nC B(i) = {A(2i-2) - A(2i)} - j*A(2i-1) for i = 2,3,...,(N-1)/2,\r\nC B((N+1)/2) = 2*A(N-1) and j**2 = -1.\r\nC\r\nC Next, perform a discrete inverse Fourier transform on B(i) by\r\nC calling SLICOT Library Routine DG01ND, to give the complex signal\r\nC Z(i), i = 1,2,...,(N-1)/2, from which the real signal C(i) may be\r\nC obtained as follows:\r\nC\r\nC C(2i-1) = Re(Z(i)), C(2i) = Im(Z(i)) for i = 1,2,...,(N-1)/2.\r\nC\r\nC Finally, compute the sine transform coefficients S ,S ,...,S\r\nC 1 2 N\r\nC given by\r\nC\r\nC S = 0,\r\nC 1\r\nC { [C(k) + C(N+1-k)] }\r\nC S = DT*{[C(k) - C(N+1-k)] - -----------------------},\r\nC k { [2*sin(pi*(k-1)/(N-1))]}\r\nC\r\nC for k = 2,3,...,N-1, and\r\nC\r\nC S = 0.\r\nC N\r\nC\r\nC If SICO = 'C', the routine computes the cosine transform of A as\r\nC follows. First, transform A(i), i = 1,2,...,N, into the complex\r\nC signal B(i), i = 1,2,...,(N+1)/2, where\r\nC\r\nC B(1) = 2*A(1),\r\nC B(i) = 2*A(2i-1) + 2*j*{[A(2i-2) - A(2i)]}\r\nC for i = 2,3,...,(N-1)/2 and B((N+1)/2) = 2*A(N).\r\nC\r\nC Next, perform a discrete inverse Fourier transform on B(i) by\r\nC calling SLICOT Library Routine DG01ND, to give the complex signal\r\nC Z(i), i = 1,2,...,(N-1)/2, from which the real signal D(i) may be\r\nC obtained as follows:\r\nC\r\nC D(2i-1) = Re(Z(i)), D(2i) = Im(Z(i)) for i = 1,2,...,(N-1)/2.\r\nC\r\nC Finally, compute the cosine transform coefficients S ,S ,...,S\r\nC 1 2 N\r\nC given by\r\nC\r\nC S = 2*DT*[D(1) + A0],\r\nC 1\r\nC { [D(k) - D(N+1-k)] }\r\nC S = DT*{[D(k) + D(N+1-k)] - -----------------------},\r\nC k { [2*sin(pi*(k-1)/(N-1))]}\r\nC\r\nC\r\nC for k = 2,3,...,N-1, and\r\nC\r\nC S = 2*DT*[D(1) - A0],\r\nC N\r\nC (N-1)/2\r\nC where A0 = 2*SUM A(2i).\r\nC i=1\r\nC\r\nC REFERENCES\r\nC\r\nC [1] Rabiner, L.R. and Rader, C.M.\r\nC Digital Signal Processing.\r\nC IEEE Press, 1972.\r\nC\r\nC [2] Oppenheim, A.V. and Schafer, R.W.\r\nC Discrete-Time Signal Processing.\r\nC Prentice-Hall Signal Processing Series, 1989.\r\nC\r\nC NUMERICAL ASPECTS\r\nC\r\nC The algorithm requires 0( N*log(N) ) operations.\r\nC\r\nC CONTRIBUTORS\r\nC\r\nC Release 3.0: V. Sima, Katholieke Univ. Leuven, Belgium, Feb. 1997.\r\nC Supersedes Release 2.0 routine DF01AD by F. Dumortier, and\r\nC R.M.C. Dekeyser, State University of Gent, Belgium.\r\nC\r\nC REVISIONS\r\nC\r\nC V. Sima, Jan. 2003.\r\nC\r\nC KEYWORDS\r\nC\r\nC Digital signal processing, fast Fourier transform, complex\r\nC signals.\r\nC\r\nC ******************************************************************\r\nC\r\nC .. Parameters ..\r\n DOUBLE PRECISION ZERO, ONE, TWO, FOUR\r\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0, TWO = 2.0D0,\r\n $ FOUR = 4.0D0 )\r\nC .. Scalar Arguments ..\r\n CHARACTER SICO\r\n INTEGER INFO, N\r\n DOUBLE PRECISION DT\r\nC .. Array Arguments ..\r\n DOUBLE PRECISION A(*), DWORK(*)\r\nC .. Local Scalars ..\r\n LOGICAL LSICO, LSIG\r\n INTEGER I, I2, IND1, IND2, M, MD2\r\n DOUBLE PRECISION A0, PIBYM, W1, W2, W3\r\nC .. External Functions ..\r\n LOGICAL LSAME\r\n EXTERNAL LSAME\r\nC .. External Subroutines ..\r\n EXTERNAL DG01ND, XERBLA\r\nC .. Intrinsic Functions ..\r\n INTRINSIC ATAN, DBLE, MOD, SIN\r\nC .. Executable Statements ..\r\nC\r\n INFO = 0\r\n LSICO = LSAME( SICO, 'S' )\r\nC\r\nC Test the input scalar arguments.\r\nC\r\n IF( .NOT.LSICO .AND. .NOT.LSAME( SICO, 'C' ) ) THEN\r\n INFO = -1\r\n ELSE\r\n M = 0\r\n IF( N.GT.4 ) THEN\r\n M = N - 1\r\nC WHILE ( MOD( M, 2 ).EQ.0 ) DO\r\n 10 CONTINUE\r\n IF ( MOD( M, 2 ).EQ.0 ) THEN\r\n M = M/2\r\n GO TO 10\r\n END IF\r\nC END WHILE 10\r\n END IF\r\n IF ( M.NE.1 ) INFO = -2\r\n END IF\r\nC\r\n IF ( INFO.NE.0 ) THEN\r\nC\r\nC Error return.\r\nC\r\n CALL XERBLA( 'DF01MD', -INFO )\r\n RETURN\r\n END IF\r\nC\r\nC Initialisation.\r\nC\r\n M = N - 1\r\n MD2 = ( N + 1 )/2\r\n PIBYM = FOUR*ATAN( ONE )/DBLE( M )\r\n I2 = 1\r\n DWORK(MD2+1) = ZERO\r\n DWORK(2*MD2) = ZERO\r\nC\r\n IF ( LSICO ) THEN\r\nC\r\nC Sine transform.\r\nC\r\n LSIG = .TRUE.\r\n DWORK(1) = -TWO*A(2)\r\n DWORK(MD2) = TWO*A(M)\r\nC\r\n DO 20 I = 4, M, 2\r\n I2 = I2 + 1\r\n DWORK(I2) = A(I-2) - A(I)\r\n DWORK(MD2+I2) = -A(I-1)\r\n 20 CONTINUE\r\nC\r\n ELSE\r\nC\r\nC Cosine transform.\r\nC\r\n LSIG = .FALSE.\r\n DWORK(1) = TWO*A(1)\r\n DWORK(MD2) = TWO*A(N)\r\n A0 = A(2)\r\nC\r\n DO 30 I = 4, M, 2\r\n I2 = I2 + 1\r\n DWORK(I2) = TWO*A(I-1)\r\n DWORK(MD2+I2) = TWO*( A(I-2) - A(I) )\r\n A0 = A0 + A(I)\r\n 30 CONTINUE\r\nC\r\n A0 = TWO*A0\r\n END IF\r\nC\r\nC Inverse Fourier transform.\r\nC\r\n CALL DG01ND( 'Inverse', MD2-1, DWORK(1), DWORK(MD2+1), INFO )\r\nC\r\nC Sine or cosine coefficients.\r\nC\r\n IF ( LSICO ) THEN\r\n A(1) = ZERO\r\n A(N) = ZERO\r\n ELSE\r\n A(1) = TWO*DT*( DWORK(1) + A0 )\r\n A(N) = TWO*DT*( DWORK(1) - A0 )\r\n END IF\r\nC\r\n IND1 = MD2 + 1\r\n IND2 = N\r\nC\r\n DO 40 I = 1, M - 1, 2\r\n W1 = DWORK(IND1)\r\n W2 = DWORK(IND2)\r\n IF ( LSIG ) W2 = -W2\r\n W3 = TWO*SIN( PIBYM*DBLE( I ) )\r\n A(I+1) = DT*( W1 + W2 - ( W1 - W2 )/W3 )\r\n IND1 = IND1 + 1\r\n IND2 = IND2 - 1\r\n 40 CONTINUE\r\nC\r\n IND1 = 2\r\n IND2 = MD2 - 1\r\nC\r\n DO 50 I = 2, M - 2, 2\r\n W1 = DWORK(IND1)\r\n W2 = DWORK(IND2)\r\n IF ( LSIG ) W2 = -W2\r\n W3 = TWO*SIN( PIBYM*DBLE( I ) )\r\n A(I+1) = DT*( W1 + W2 - ( W1 - W2 )/W3 )\r\n IND1 = IND1 + 1\r\n IND2 = IND2 - 1\r\n 50 CONTINUE\r\nC\r\n RETURN\r\nC *** Last line of DF01MD ***\r\n END\r\n", "meta": {"hexsha": "824aff36d08a509c094ab015b40ba59407899634", "size": 8024, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "External/SLICOT/DF01MD.f", "max_stars_repo_name": "bgin/MissileSimulation", "max_stars_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2016-08-28T23:20:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-15T14:43:58.000Z", "max_issues_repo_path": "External/SLICOT/DF01MD.f", "max_issues_repo_name": "bgin/MissileSimulation", "max_issues_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-06-02T21:29:51.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-05T05:59:31.000Z", "max_forks_repo_path": "External/SLICOT/DF01MD.f", "max_forks_repo_name": "bgin/MissileSimulation", "max_forks_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-07-04T22:38:22.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-04T22:38:22.000Z", "avg_line_length": 28.0559440559, "max_line_length": 73, "alphanum_fraction": 0.4525174477, "num_tokens": 2747, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096090086368, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6889259398250895}} {"text": "! { dg-do run }\n! { dg-additional-options \"-fno-range-check\" }\n!\n! Check compile-time simplification of functions FRACTION, EXPONENT,\n! SPACING, RRSPACING and SET_EXPONENT for special values.\n\nprogram test\n implicit none\n real, parameter :: inf = 2 * huge(0.)\n real, parameter :: nan = 0. / 0.\n\n call check_positive_zero(fraction(0.))\n call check_negative_zero(fraction(-0.))\n if (.not. isnan(fraction(inf))) STOP 1\n if (.not. isnan(fraction(-inf))) STOP 2\n if (.not. isnan(fraction(nan))) STOP 3\n\n if (exponent(0.) /= 0) STOP 4\n if (exponent(-0.) /= 0) STOP 5\n if (exponent(inf) /= huge(0)) STOP 6\n if (exponent(-inf) /= huge(0)) STOP 7\n if (exponent(nan) /= huge(0)) STOP 8\n\n if (spacing(0.) /= spacing(tiny(0.))) STOP 9\n if (spacing(-0.) /= spacing(tiny(0.))) STOP 10\n if (.not. isnan(spacing(inf))) STOP 11\n if (.not. isnan(spacing(-inf))) STOP 12\n if (.not. isnan(spacing(nan))) STOP 13\n\n call check_positive_zero(rrspacing(0.))\n call check_positive_zero(rrspacing(-0.))\n if (.not. isnan(rrspacing(inf))) STOP 14\n if (.not. isnan(rrspacing(-inf))) STOP 15\n if (.not. isnan(rrspacing(nan))) STOP 16\n\n call check_positive_zero(set_exponent(0.,42))\n call check_negative_zero(set_exponent(-0.,42))\n if (.not. isnan(set_exponent(inf, 42))) STOP 17\n if (.not. isnan(set_exponent(-inf, 42))) STOP 18\n if (.not. isnan(set_exponent(nan, 42))) STOP 19\n\ncontains\n\n subroutine check_positive_zero(x)\n use ieee_arithmetic\n implicit none\n real, value :: x\n\n if (ieee_class (x) /= ieee_positive_zero) STOP 20\n end\n\n subroutine check_negative_zero(x)\n use ieee_arithmetic\n implicit none\n real, value :: x\n\n if (ieee_class (x) /= ieee_negative_zero) STOP 21\n end\n\nend\n", "meta": {"hexsha": "f0debeb38de280ca4003452a3b7941c75bb541dd", "size": 1712, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/ieee/intrinsics_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/ieee/intrinsics_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/ieee/intrinsics_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": 28.0655737705, "max_line_length": 68, "alphanum_fraction": 0.6658878505, "num_tokens": 572, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118111485245, "lm_q2_score": 0.8333245932423309, "lm_q1q2_score": 0.6889192837539749}} {"text": "program scalars\nuse M_anything,only : anyscalar_to_real\nuse,intrinsic :: iso_fortran_env, only : int8, int16, int32, int64 \nuse,intrinsic :: iso_fortran_env, only : real32, real64, real128\nimplicit none\ninteger :: ios\n\ninteger(kind=int8) :: tiny= huge(0_int8)\ninteger(kind=int16) :: small= huge(0_int16 )\ninteger(kind=int32) :: medium= huge(0_int32)\ninteger(kind=int64) :: large= huge(0_int64)\nreal(kind=real32) :: rs= huge(0.0_real32)\nreal(kind=real64) :: rm= huge(0.0_real64)\nreal(kind=real128) :: rl= huge(0.0_real128)\n\n101 format(a10,\"|\",i39,\"|\",i11,\"|\",i39)\n102 format(a10,\"|\",g0,t55,\"|\",i11,\"|\",g0)\n write(*,*)'First show the intrinsic variables of various KINDS we will be using'\n write(*,*) ' NAME |VALUE |KIND(VALUE)|10**RANGE(VALUE)'\n write(*,102) 'rs ',rs, kind(rs), 10.0_real32**range(rs)\n write(*,102) 'rm ',rm, kind(rm), 10.0_real64**range(rm)\n write(*,102) 'rl ',rl, kind(rl), 10.0_real128**range(rl)\n write(*,102) 'tiny ',tiny, kind(tiny) \n write(*,102) 'small ',small, kind(small) \n write(*,102) 'medium ',medium, kind(medium) \n write(*,102) 'large ',large, kind(large) \n\n write(*,*)'Test squarei with all INTEGER KINDs:'\n write(*,*)'(and given the following facts what is the expected output?)'\n write(*,*)'FACTS:'\n write(*,*)'127 * 127 = 16129'\n write(*,*)'32767 * 32767 = 1073676289'\n write(*,*)'2147483647 * 2147483647 = 4611686014132420609'\n write(*,*)'9223372036854775807 * 9223372036854775807 = 85070591730234615847396907784232501249'\n write(*,*)'170141183460469231731687303715884105727 * 170141183460469231731687303715884105727 =&\n &28948022309329048855892746252171976962977213799489202546401021394546514198529'\n write(*,*)'OUTPUT:'\n202 format(a,*(g0:,'; '))\n write(*,202,iostat=ios) 'SQUAREI() :',squarei(tiny), squarei(small), squarei(medium), squarei(large) \n write(*,202,iostat=ios) 'SQUAREI() :', squarei(rs), squarei(rm), squarei(rl) \n\ncontains\n\n!! THIS FUNCTION CAN TAKE AN INTEGER OR REAL OF ANY TYPE KNOWN TO ANYSCALAR_TO_REAL() AS AN ARGUMENT\nfunction squarei(invalue) result (dvalue) ! square an integer value generically\nuse M_anything, only : anyscalar_to_real\nimplicit none\nclass(*),intent(in) :: invalue\nreal :: invalue_local\nreal :: dvalue\nreal,parameter :: biggest=sqrt(real(0.0,kind=real128))\n invalue_local=anyscalar_to_real(invalue)\n !if(invalue_local.gt.biggest)then\n ! write(*,*)'ERROR:*squarei* input value to big=',invalue_local\n !endif\n dvalue=invalue_local*invalue_local\nend function squarei\n\nend program scalars\n", "meta": {"hexsha": "f64904e7254001fbd7011cf7483e64c851af61e2", "size": 2716, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "app/scalars.f90", "max_stars_repo_name": "urbanjost/M_anything", "max_stars_repo_head_hexsha": "6ff4a0f61348abfec4513fe549bbc973a9871337", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app/scalars.f90", "max_issues_repo_name": "urbanjost/M_anything", "max_issues_repo_head_hexsha": "6ff4a0f61348abfec4513fe549bbc973a9871337", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "app/scalars.f90", "max_forks_repo_name": "urbanjost/M_anything", "max_forks_repo_head_hexsha": "6ff4a0f61348abfec4513fe549bbc973a9871337", "max_forks_repo_licenses": ["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.2666666667, "max_line_length": 106, "alphanum_fraction": 0.6542709867, "num_tokens": 907, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245994514082, "lm_q2_score": 0.8267118026095991, "lm_q1q2_score": 0.6889192817713958}} {"text": "program Matrix_Transpose\r\nimplicit none\r\n integer,parameter :: rows1 = 2 , columns1 = 3\r\n integer,parameter :: rows2 = 3 , columns2 = 2\r\n integer :: matrix1(rows1,columns1),matrix2(rows2,columns2)\r\n integer :: r,c\r\n\r\n read*,((matrix1(r,c),c=1,columns1),r=1,rows1)\r\n\r\n do r=1 , rows1\r\n do c=1 , columns1\r\n matrix2(c,r) = matrix1(r,c)\n end do\n end do\r\n\r\n\r\n write(*,\"(3(2I4,/))\")((matrix2(c,r),r=1,columns2),c=1,rows2)\r\n\r\n\nend program\r\n", "meta": {"hexsha": "5cc3bcc02990a9c84f3d213f6bd238d8c0c5c117", "size": 482, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "GitHub_FortranHomework/A20211210.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/A20211210.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/A20211210.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": 22.9523809524, "max_line_length": 65, "alphanum_fraction": 0.5746887967, "num_tokens": 165, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118026095991, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.6889192800603567}} {"text": "module mod_sort\n implicit none\n private\n public :: swap, quick_sort, merge_sort, heap_sort, comb_sort\n public :: shell_sort, insertion_sort, gnome_sort, shaker_sort\n public :: bitonic_sort\ncontains\n subroutine swap(a,b)\n implicit none\n integer, intent(inout) :: a, b\n integer :: c\n c = a\n a = b\n b = c\n return\n end subroutine swap\n recursive subroutine quick_sort(a)\n implicit none\n integer, intent(inout) :: a(:)\n integer :: n, l, r, p\n n = size(a)\n l = 1\n r = n\n p = a((l+r)/2)+a(l)+a(r)-max(a((l+r)/2),a(l),a(r))-min(a((l+r)/2),a(l),a(r))\n do\n do while (a(l).lt.p)\n l = l+1\n end do\n do while (a(r).gt.p)\n r = r-1\n end do\n if (l.ge.r) exit\n call swap(a(l),a(r))\n l = l+1\n r = r-1\n end do\n if (l.gt.2) call quick_sort(a(1:l-1))\n if (n.gt.r+1) call quick_sort(a(r+1:n))\n return\n end subroutine quick_sort\n subroutine merge_sort(a)\n implicit none\n integer, intent(inout) :: a(:)\n integer :: n, m, l, i, u\n n = size(a)\n m = n\n l = 1\n do while (m.gt.1)\n do i = 1, m/2\n u = min(2*i*l,n)\n call merger(a(2*(i-1)*l+1:(2*i-1)*l),a((2*i-1)*l+1:u))\n end do\n l = 2*l\n m = (m+1)/2\n end do\n return\n end subroutine merge_sort\n subroutine merger(a1,a2)\n implicit none\n integer, intent(inout) :: a1(:), a2(:)\n integer :: a(size(a1)+size(a2))\n integer :: i1, i2, n1, n2\n i1 = 1\n i2 = 1\n n1 = size(a1)\n n2 = size(a2)\n do while (i1.le.n1.and.i2.le.n2)\n if (a1(i1).le.a2(i2)) then\n a(i1+i2-1) = a1(i1)\n i1 = i1+1\n else\n a(i1+i2-1) = a2(i2)\n i2 = i2+1\n end if\n end do\n if (i1.le.n1) then\n a(i1+i2-1:n1+n2) = a1(i1:n1)\n else if (i2.le.n2) then\n a(i1+i2-1:n1+n2) = a2(i2:n2)\n end if\n a1 = a(1:n1)\n a2 = a(n1+1:n1+n2)\n return\n end subroutine merger\n subroutine heap_sort(a)\n implicit none\n integer, intent(inout) :: a(:)\n integer :: n, i, j, k\n n = size(a)\n do i = 1, n\n j = i\n do while (j.gt.1)\n k = j/2\n if (a(j).gt.a(k)) call swap(a(j),a(k))\n j = k\n end do\n end do\n do i = n, 1, -1\n call swap(a(i),a(1))\n j = 1\n do while (2*j.lt.i)\n k = 2*j\n if ((k.lt.i-1).and.(a(k+1).gt.a(k))) k = k+1\n if (a(j).lt.a(k)) call swap(a(j),a(k))\n j = k\n end do\n end do\n return\n end subroutine heap_sort\n subroutine comb_sort(a)\n implicit none\n integer, intent(inout) :: a(:)\n logical :: ok\n integer :: n, i, h\n n = size(a)\n h = n\n ok = .false.\n do while ((h.gt.1).or.(.not.ok))\n if (h.gt.1) then\n h = (10*h)/13\n if ((h.eq.9).or.(h.eq.10)) h = 11\n end if\n ok = .true.\n do i = 1, n-h\n if (a(i).gt.a(i+h)) then\n call swap(a(i),a(i+h))\n ok = .false.\n end if\n end do\n end do\n return\n end subroutine comb_sort\n subroutine shell_sort(a)\n implicit none\n integer, intent(inout) :: a(:)\n integer :: n, i, h\n n = size(a)\n h = 1\n do while (3*h+1.lt.n)\n h = 3*h+1\n end do\n do while (h.ge.1)\n do i = 1, h\n call insertion_sort(a(i:n:h))\n end do\n h = (h-1)/3\n end do\n return\n end subroutine shell_sort\n subroutine insertion_sort(a)\n implicit none\n integer, intent(inout) :: a(:)\n integer :: n, i, j, t\n n = size(a)\n do i = 2, n\n if (a(i).ge.a(i-1)) cycle\n t = a(i)\n j = i\n do while ((j.gt.1).and.(t.lt.a(j-1)))\n a(j) = a(j-1)\n j = j-1\n end do\n a(j) = t\n end do\n return\n end subroutine insertion_sort\n subroutine gnome_sort(a)\n implicit none\n integer, intent(inout) :: a(:)\n integer :: n, i\n n = size(a)\n i = 2\n do while (i.le.n)\n if (a(i).ge.a(i-1)) then\n i = i+1\n cycle\n end if\n call swap(a(i),a(i-1))\n i = i-1\n if (i.eq.1) i = 2\n end do\n return\n end subroutine gnome_sort\n subroutine shaker_sort(a)\n implicit none\n integer, intent(inout) :: a(:)\n integer :: n, l, r, m, i\n n = size(a)\n l = 1\n r = n\n do\n m = l\n do i = l, r-1\n if (a(i).gt.a(i+1)) then\n call swap(a(i),a(i+1))\n m = i\n end if\n end do\n r = m\n if (l.eq.r) exit\n m = r\n do i = r, l+1, -1\n if (a(i).lt.a(i-1)) then\n call swap(a(i),a(i-1))\n m = i\n end if\n end do\n l = m\n if (l.eq.r) exit\n end do\n return\n end subroutine shaker_sort\n subroutine bitonic_sort(a)\n implicit none\n integer, intent(inout) :: a(:)\n integer :: n, i\n n = size(a)\n if (n.eq.1) return\n call bitonic_sorter(a(1:n/2),.false.)\n call bitonic_sorter(a(n/2+1:n),.true.)\n call bitonic_merger(a,.true.)\n return\n end subroutine bitonic_sort\n recursive subroutine bitonic_sorter(a,ascend)\n implicit none\n integer, intent(inout) :: a(:)\n logical, intent(in) :: ascend\n integer :: n, i\n n = size(a)\n if (n.eq.1) return\n call bitonic_sorter(a(1:n/2),.not.ascend)\n call bitonic_sorter(a(n/2+1:n),ascend)\n call bitonic_merger(a,ascend)\n return\n end subroutine bitonic_sorter\n recursive subroutine bitonic_merger(a,ascend)\n implicit none\n integer, intent(inout) :: a(:)\n logical, intent(in) :: ascend\n integer :: n, m, i\n n = size(a)\n if (n.eq.1) return\n m = max_pow_of_2(n)\n do i = 1, n-m\n if ((a(i).gt.a(i+m)).eqv.ascend) call swap(a(i),a(i+m))\n end do\n call bitonic_merger(a(1:m),ascend)\n call bitonic_merger(a(m+1:n),ascend)\n return\n end subroutine bitonic_merger\n function max_pow_of_2(n) result(p)\n implicit none\n integer, intent(in) :: n\n integer :: p\n p = 1\n do while (2*p.lt.n)\n p = 2*p\n end do\n return\n end function max_pow_of_2\nend module mod_sort\n", "meta": {"hexsha": "c19bfbe4a83cf1a9b30f342d571fae90e2ce81ec", "size": 5889, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran90/sort.f90", "max_stars_repo_name": "ue1221/fortran-utilities", "max_stars_repo_head_hexsha": "83037ee4e199e33f8d4774a9928fbfddeba2930e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fortran90/sort.f90", "max_issues_repo_name": "ue1221/fortran-utilities", "max_issues_repo_head_hexsha": "83037ee4e199e33f8d4774a9928fbfddeba2930e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran90/sort.f90", "max_forks_repo_name": "ue1221/fortran-utilities", "max_forks_repo_head_hexsha": "83037ee4e199e33f8d4774a9928fbfddeba2930e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.4770992366, "max_line_length": 80, "alphanum_fraction": 0.5099337748, "num_tokens": 2155, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246035907932, "lm_q2_score": 0.8267117855317474, "lm_q1q2_score": 0.6889192709620803}} {"text": "\t!------------------------------------------------------------------------\n\t!\n\t!\n\t! PURPOSE\n\t!\n\t! This program solves nonlinear Klein-Gordon equation in 1 dimension\n\t! u_{tt}-u_{xx}+u=Es*|u|^2u\n\t! using a second order implicit-explicit time stepping scheme.\n\t!\n\t! The boundary conditions are u(x=0)=u(2*Lx*\\pi), \n\t! The initial condition is u=sqrt(2)*sech((x-c*t)/sqrt(1-c^2));\n\t!\n\t! .. Parameters ..\n\t! Nx = number of modes in x - power of 2 for FFT\n\t! Nt\t\t\t= number of timesteps to take\n\t! Tmax\t\t\t= maximum simulation time\n\t! plotgap\t\t= number of timesteps between plots\n\t! pi = 3.14159265358979323846264338327950288419716939937510d0\n\t! Lx\t\t\t= width of box in x direction\n\t! ES\t\t\t= +1 for focusing and -1 for defocusing\n\t! .. Scalars ..\n\t! i\t\t\t= loop counter in x direction\n\t! n\t\t\t= loop counter for timesteps direction\t\n\t! allocatestatus\t= error indicator during allocation\n\t! start\t\t= variable to record start time of program\n\t! finish\t\t= variable to record end time of program\n\t! count_rate\t\t= variable for clock count rate\n\t! dt\t\t\t= timestep\n\t! ierr\t\t\t= error code\n\t! plotnum\t\t= number of plot\n\t! .. Arrays ..\n\t! unew \t\t= approximate solution\n\t! u \t\t\t= approximate solution\n\t! uold \t\t= approximate solution\n\t! nonlin \t\t= nonlinear term, u^3\n\t! .. Vectors ..\n\t! x\t\t\t= x locations\n\t! time\t\t\t= times at which save data\n\t! en\t\t\t= total energy\t\n\t! enstr\t\t= strain energy\n\t! enpot\t\t= potential energy\n\t! enkin\t\t= kinetic energy\n\t! name_config\t\t= array to store filename for data to be saved \t\t\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!\tgetgrid.f90\t-- Get initial grid of points\n\t! \tinitialdata.f90 -- Get initial data\n\t!\tenercalc.f90 -- Subroutine to calculate the energy\n\t!\tsavedata.f90 -- Save initial data\n\t!\tstoreold.f90 -- Store old data\n\t! External libraries required\n\t! \tOpenMP library\n\t\t\n\tPROGRAM Kg\n\tUSE omp_lib\t\t \t \n\t! Declare variables\n\tIMPLICIT NONE\t\t\t\t\t \n\tINTEGER(kind=4), PARAMETER\t\t:: Nx=1024\n\tINTEGER(kind=4), PARAMETER\t\t:: Nt=500 \n\tINTEGER(kind=4), PARAMETER\t\t:: plotgap=100\t\n INTEGER(kind=4), PARAMETER\t\t:: maxiter=50\n\tREAL(kind=8), PARAMETER\t\t\t:: &\n\t\tpi=3.14159265358979323846264338327950288419716939937510d0\n\tREAL(kind=8), PARAMETER\t\t\t:: Lx=9.0d0\n\tREAL(kind=8), PARAMETER\t\t\t:: Es=1.0d0\t\n REAL(kind=8), PARAMETER \t:: c=0.5\n REAL(kind=8), PARAMETER \t\t:: tol=0.1**12\n\tREAL(kind=8)\t\t\t\t:: dt=5.0d0/REAL(Nt,kind(0d0))\t\n\tREAL(kind=8), DIMENSION(1:Nx)\t :: r,rhs,Mp,p \n\tREAL(kind=8), DIMENSION(1:Nx)\t :: x\t\n\tREAL(kind=8), DIMENSION(1:Nx) :: u\n\tREAL(kind=8), DIMENSION(1:Nx) :: uold\n\tREAL(kind=8), DIMENSION(1:Nx) :: unew\n\tREAL(kind=8), DIMENSION(1:Nx) :: savearray\n\tREAL(kind=8), DIMENSION(1:Nt+1) :: time,enkin,enstr,enpot,en\n REAL(kind=8) :: rsum,rr,rrold,alpha,beta,dx\n\tINTEGER(kind=4)\t\t\t\t:: ierr,i,j,n,allocatestatus,numthreads\n\tINTEGER(kind=4)\t\t\t\t:: start, finish, count_rate, plotnum\n INTEGER(kind=4) :: ip,ipp,im,imm,iter\n\tCHARACTER*100\t\t\t\t:: name_config\n\t! Start short parallel region to count threads \n\tnumthreads=omp_get_max_threads()\n\tPRINT *,'There are ',numthreads,' threads.'\n\t\t\n\t! setup grid \n\tCALL getgrid(Nx,Lx,pi,name_config,x)\n dx=abs(x(2)-x(1))\n\tPRINT *,'Setup grid'\n\tCALL initialdata(Nx,dt,c,x,u,uold)\n\tplotnum=1\t\n\tname_config = 'data/u' \n\tsavearray=REAL(u)\n\tCALL savedata(Nx,plotnum,name_config,savearray)\n\n PRINT *,'Transformed initial data'\n\tCALL enercalc(Nx,dt,Es,&\n\t\t\tenkin(plotnum),enstr(plotnum),&\n\t\t\tenpot(plotnum),en(plotnum),&\n\t\t\tdx,u,uold)\n\t\t\t\n\tPRINT *,'Got initial data, starting timestepping'\n\ttime(plotnum)=0.0d0\n \tCALL system_clock(start,count_rate)\t\n\tDO n=1,Nt\t\t\t\t\t\n rr=0.0d0\n rsum=0.0d0\n\t\t!$OMP PARALLEL DO PRIVATE(i,ipp,ip,im,imm) reduction(+:rr,rsum) SCHEDULE(static)\n\t\tDO i=1,Nx\n ipp=1+mod(i+2+Nx-1,Nx)\n ip =1+mod(i+1+Nx-1,Nx)\n im =1+mod(i-1+Nx-1,Nx)\n imm=1+mod(i-2+Nx-1,Nx) \n\t\t\trhs(i)=Es*(u(i)**3) &\n +(2.0d0*u(i)-uold(i))/(dt*dt) &\n +0.25d0*(-(1.0d0/12.0d0)*(2.0d0*u(imm)+uold(imm)) &\n +(4.0d0/3.0d0)*(2.0d0*u(im)+uold(im)) &\n -(5.0d0/2.0d0)*(2.0d0*u(i)+uold(i)) &\n +(4.0d0/3.0d0)*(2.0d0*u(ip)+uold(ip)) &\n -(1.0d0/12.0d0)*(2.0d0*u(ipp)+uold(ipp)))/(dx*dx) &\n -0.25d0*(2.0d0*u(i)+uold(i))\n r(i)=rhs(i)-u(i)*(1.0d0/(dt*dt) + 0.25d0) &\n +0.25d0*(-(1.0d0/12.0d0)*u(imm) &\n +(4.0d0/3.0d0)*u(im) &\n -(5.0d0/2.0d0)*u(i) &\n +(4.0d0/3.0d0)*u(ip) &\n -(1.0d0/12.0d0)*u(ipp) )/(dx*dx) \n p(i)=r(i)\n unew(i)=u(i)\n rsum=rsum+abs(r(i))\n rr=rr+r(i)*r(i)\n\t\tEND DO\n\t\t!$OMP END PARALLEL DO\n iter=0\n DO WHILE (( iter .lt. maxiter ) .and. ( rsum .gt. tol))\n\t\t !$OMP PARALLEL DO PRIVATE(i,im,imm,ip,ipp) SCHEDULE(static)\n\t\t DO i=1,Nx\n ipp=1+mod(i+2+Nx-1,Nx)\n ip=1+mod(i+1+Nx-1,Nx)\n im=1+mod(i-1+Nx-1,Nx)\n imm=1+mod(i-2+Nx-1,Nx)\n\t\t\tMp(i)=p(i)*(1.0d0/(dt*dt) + 0.25d0) &\n -0.25d0*(-(1.0d0/12.0d0)*p(imm) &\n +(4.0d0/3.0d0)*p(im) &\n -(5.0d0/2.0d0)*p(i) &\n +(4.0d0/3.0d0)*p(ip) &\n -(1.0d0/12.0d0)*p(ipp) )/(dx*dx)\n\t\t END DO\n\t\t !$OMP END PARALLEL DO\n alpha=0.0d0\n !$OMP PARALLEL DO PRIVATE(i) REDUCTION(+:alpha) SCHEDULE(static)\n DO i=1,Nx\n alpha=alpha+Mp(i)*p(i)\n END DO\n !$OMP END PARALLEL DO\n alpha=rr/alpha\n\n !$OMP PARALLEL DO PRIVATE(i) SCHEDULE(static)\n DO i=1,Nx\n unew(i)=unew(i)+alpha*p(i)\n r(i)=r(i)-alpha*Mp(i)\n END DO\n !$OMP END PARALLEL DO\n\n rrold=rr\n rr=0.0d0\n !$OMP PARALLEL DO PRIVATE(i,im,imm,ip,ipp) REDUCTION(+:rr) SCHEDULE(static)\n DO i=1,Nx \n rr=rr+r(i)*r(i)\n END DO\n !$OMP END PARALLEL DO\n beta=rr/rrold\n rsum=0.0d0\n !$OMP PARALLEL DO PRIVATE(i,im,imm,ip,ipp) REDUCTION(+:rsum) SCHEDULE(static)\n DO i=1,Nx\n p(i)=r(i)+beta*p(i)\n rsum=rsum+abs(r(i))\n END DO\n !$OMP END PARALLEL DO\n iter=iter+1 \n END DO\n ! .. Update old values ..\n CALL storeold(Nx,unew,u,uold)\n\t\tIF (mod(n,plotgap)==0) then\n\t\t\tplotnum=plotnum+1\n\t\t\ttime(plotnum)=n*dt\n\t\t\tPRINT *,'time',n*dt,' iterations ',iter\n\t\t\tCALL enercalc(Nx,dt,Es,&\n\t\t\t\tenkin(plotnum),enstr(plotnum),&\n\t\t\t\tenpot(plotnum),en(plotnum),dx,&\n\t\t\t\tu,uold)\n\t\t\tCALL savedata(Nx,plotnum,name_config,unew)\n\t\tEND IF\n\tEND DO\t\t\n\tPRINT *,'Finished time stepping'\n\tCALL system_clock(finish,count_rate)\n\tPRINT*,'Program took ',&\n\t\tREAL(finish-start,kind(0d0))/REAL(count_rate,kind(0d0)),&\n\t\t'for Time stepping'\n\tCALL saveresults(Nt,plotgap,time(1:1+n/plotgap),en(1:1+n/plotgap),&\n\t\t\tenstr(1:1+n/plotgap),enkin(1:1+n/plotgap),&\n enpot(1:1+n/plotgap))\t\n\t\t\t\n\t! Save times at which output was made in text format\n\tPRINT *,'Saved data'\n CALL errorcalc(Nt,Nx,dt,c,x,u) \n\n\tPRINT *,'Program execution complete'\n\tEND PROGRAM Kg\n", "meta": {"hexsha": "cefc5d511e32c390be5614b8ee85635964f810c1", "size": 8369, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Codes/Fortran1DFiniteDifference4thOrderCompact/KgSemiImp1dOrig.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/Fortran1DFiniteDifference4thOrderCompact/KgSemiImp1dOrig.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/Fortran1DFiniteDifference4thOrderCompact/KgSemiImp1dOrig.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": 37.8687782805, "max_line_length": 95, "alphanum_fraction": 0.5005376986, "num_tokens": 2710, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425355825847, "lm_q2_score": 0.7490872131147276, "lm_q1q2_score": 0.6888924640413201}} {"text": "! la.f90\n! author: sunder\n\n!-----------------------------------------------------------------------\n! Find inverse of a matrix\n!-----------------------------------------------------------------------\n\nsubroutine MatrixInverse(N,A,iA)\n implicit none\n integer :: N\n double precision :: A(N,N), iA(N,N)\n !\n integer :: i,j,ml(1)\n double precision :: piv\n double precision :: temp(2*N)\n double precision :: C(2*N,N)\n !\n C(1:N,:) = TRANSPOSE(A)\n C(N+1:2*N,:) = 0. \n do i = 1, N\n C(N+i,i) = 1.0d0\n end do\n ! \n ! Forward elimination and row swapping (if necessary)\n ! \n do i = 1, N\n ! If pivot element is zero, then swap rows \n ml = MAXLOC(ABS(C(i,i:N))) \n j = i - 1 + ml(1) \n temp = C(:,j) \n C(:,j) = C(:,i)\n C(:,i) = temp \n if (C(i,i) .eq. 0.0d0) THEN\n print *, 'ERROR. Matrix is singular!'\n do j = 1, N\n print *, A(j,:)\n end do\n stop\n end if\n piv = 1.0d0/C(i,i)\n C(:,i) = C(:,i)*piv \n do j = i+1, N\n C(:,j) = C(:,j) - C(i,j)*C(:,i)\n end do\n end do\n !\n ! Back substitution\n !\n do i = N,1,-1\n do j = i-1,1,-1\n C(:,j) = C(:,j) - C(i,j)*C(:,i)\n end do\n end do\n !\n iA = transpose( C(N+1:2*N,:) )\n !\nend subroutine MatrixInverse\n", "meta": {"hexsha": "bb085eb9c07b1554fc80a1883aa5d708cd774e20", "size": 1289, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ADER-WENO-1D-LINEAR-CONVECTION/la.f90", "max_stars_repo_name": "dasikasunder/ADER-WENO", "max_stars_repo_head_hexsha": "8d40b341be7610ac89a144077a9f759a0154909a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-12-19T07:50:53.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-19T07:50:53.000Z", "max_issues_repo_path": "ADER-WENO-1D-LINEAR-CONVECTION/la.f90", "max_issues_repo_name": "dasikasunder/ADER-WENO", "max_issues_repo_head_hexsha": "8d40b341be7610ac89a144077a9f759a0154909a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ADER-WENO-1D-LINEAR-CONVECTION/la.f90", "max_forks_repo_name": "dasikasunder/ADER-WENO", "max_forks_repo_head_hexsha": "8d40b341be7610ac89a144077a9f759a0154909a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.224137931, "max_line_length": 72, "alphanum_fraction": 0.4103956555, "num_tokens": 442, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.919642526773001, "lm_q2_score": 0.7490872075132152, "lm_q1q2_score": 0.6888924522907846}} {"text": "program limits_test\n use, intrinsic :: iso_fortran_env, only : INT8, INT16, INT32, INT64, &\n REAL32, REAL64, REAL128 \n implicit none\n integer(kind=INT8) :: i8\n integer(kind=INT16) :: i16\n integer(kind=INT32) :: i32\n integer(kind=INT64) :: i64\n real(kind=REAL32) :: x32\n real(kind=REAL64) :: x64\n real(kind=REAL128) :: x128\n \n print '(A)', 'integer:'\n\n print '(A)', 'huge'\n print *, huge(i8)\n print *, huge(i16)\n print *, huge(i32)\n print *, huge(i64)\n\n print '(A)', 'digits'\n print *, digits(i8)\n print *, digits(i16)\n print *, digits(i32)\n print *, digits(i64)\n\n print '(A)', 'range'\n print *, range(i8)\n print *, range(i16)\n print *, range(i32)\n print *, range(i64)\n\n print '(A)', 'real:'\n\n print '(A)', 'huge:'\n print *, 32, huge(x32)\n print *, 64, huge(x64)\n print *, 128, huge(x128)\n\n print '(A)', 'tiny:'\n print *, 32, tiny(x32)\n print *, 64, tiny(x64)\n print *, 128, tiny(x128)\n\n print '(A)', 'epsilon:'\n print *, 32, epsilon(x32)\n print *, 64, epsilon(x64)\n print *, 128, epsilon(x128)\n\n print '(A)', 'range:'\n print *, 32, range(x32)\n print *, 64, range(x64)\n print *, 128, range(x128)\n\n print '(A)', 'minexponent:'\n print *, 32, minexponent(x32)\n print *, 64, minexponent(x64)\n print *, 128, minexponent(x128)\n\n print '(A)', 'maxexponent:'\n print *, 32, maxexponent(x32)\n print *, 64, maxexponent(x64)\n print *, 128, maxexponent(x128)\n\n print '(A)', 'precision:'\n print *, 32, precision(x32)\n print *, 64, precision(x64)\n print *, 128, precision(x128)\n\n print '(A)', 'digits:'\n print *, 32, digits(x32)\n print *, 64, digits(x64)\n print *, 128, digits(x128)\n\nend program limits_test\n", "meta": {"hexsha": "46e420d910e0f7778b1b4ab0c4f12d3279022030", "size": 1814, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran/Types/limits_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/Types/limits_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/Types/limits_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": 23.8684210526, "max_line_length": 74, "alphanum_fraction": 0.5446527012, "num_tokens": 572, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711832583695, "lm_q2_score": 0.8104789155369048, "lm_q1q2_score": 0.6888837228448631}} {"text": " subroutine sphere_setprob(revs_per_second)\n implicit none\n\n double precision revs_per_second, rps\n\n double precision pi\n common /compi/ pi\n\n common /spherecomm/ rps\n\n pi = 4.d0*atan(1.d0)\n\n rps = revs_per_second\n\n end\n", "meta": {"hexsha": "a54e222620e91864c3534e5293d4344229b88902", "size": 264, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "applications/clawpack/advection/2d/sphere/setprob.f", "max_stars_repo_name": "scivision/forestclaw", "max_stars_repo_head_hexsha": "4dae847a8abd1055e70acda9c2973cd3dd77d3f1", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-09T23:06:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-09T23:06:42.000Z", "max_issues_repo_path": "applications/clawpack/advection/2d/sphere/setprob.f", "max_issues_repo_name": "scottaiton/forestclaw", "max_issues_repo_head_hexsha": "2abaab636e6e93f5507a6f231490144a3f805b59", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "applications/clawpack/advection/2d/sphere/setprob.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": 16.5, "max_line_length": 48, "alphanum_fraction": 0.6287878788, "num_tokens": 73, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8499711832583696, "lm_q2_score": 0.8104789063814617, "lm_q1q2_score": 0.6888837150630004}} {"text": "module bac\n implicit none\n\ncontains\n\n subroutine Gennum(n)\n integer, intent(out) :: n(4)\n integer :: i, j\n real :: r\n\n call random_number(r)\n n(1) = int(r * 9.0) + 1\n i = 2\n\nouter: do while (i <= 4)\n call random_number(r)\n n(i) = int(r * 9.0) + 1\ninner: do j = i-1 , 1, -1\n if (n(j) == n(i)) cycle outer\n end do inner\n i = i + 1\n end do outer\n\n end subroutine Gennum\n\n subroutine Score(n, guess, b, c)\n character(*), intent(in) :: guess\n integer, intent(in) :: n(0:3)\n integer, intent(out) :: b, c\n integer :: digit, i, j, ind\n\n b = 0; c = 0\n do i = 1, 4\n read(guess(i:i), \"(i1)\") digit\n if (digit == n(i-1)) then\n b = b + 1\n else\n do j = i, i+2\n ind = mod(j, 4)\n if (digit == n(ind)) then\n c = c + 1\n exit\n end if\n end do\n end if\n end do\n\n end subroutine Score\n\nend module bac\n\nprogram Bulls_and_Cows\n use bac\n implicit none\n\n integer :: n(4)\n integer :: bulls=0, cows=0, tries=0\n character(4) :: guess\n\n call random_seed\n call Gennum(n)\n\n write(*,*) \"I have selected a number made up of 4 digits (1-9) without repetitions.\"\n write(*,*) \"You attempt to guess this number.\"\n write(*,*) \"Every digit in your guess that is in the correct position scores 1 Bull\"\n write(*,*) \"Every digit in your guess that is in an incorrect position scores 1 Cow\"\n write(*,*)\n\n do while (bulls /= 4)\n write(*,*) \"Enter a 4 digit number\"\n read*, guess\n if (verify(guess, \"123456789\") /= 0) then\n write(*,*) \"That is an invalid entry. Please try again.\"\n cycle\n end if\n tries = tries + 1\n call Score (n, guess, bulls, cows)\n write(*, \"(a, i1, a, i1, a)\") \"You scored \", bulls, \" bulls and \", cows, \" cows\"\n write(*,*)\n end do\n\n write(*,\"(a,i0,a)\") \"Congratulations! You correctly guessed the correct number in \", tries, \" attempts\"\n\nend program Bulls_and_Cows\n", "meta": {"hexsha": "f2d10f6c9e757d2ae8021d77afd38a4ddc178af2", "size": 1997, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Bulls-and-cows/Fortran/bulls-and-cows.f", "max_stars_repo_name": "mullikine/RosettaCodeData", "max_stars_repo_head_hexsha": "4f0027c6ce83daa36118ee8b67915a13cd23ab67", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Bulls-and-cows/Fortran/bulls-and-cows.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/Bulls-and-cows/Fortran/bulls-and-cows.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 23.4941176471, "max_line_length": 106, "alphanum_fraction": 0.5468202303, "num_tokens": 634, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.849971175657575, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.6888837069572509}} {"text": "MODULE ran001\n IMPLICIT NONE\n SAVE\n\n INTEGER :: n= 9876\nEND MODULE ran001\n\nSUBROUTINE random0(ran)\n USE ran001\n IMPLICIT NONE\n\n REAL,INTENT (out) :: ran\n n = MOD (8121 * n + 28411,134456)\n ran = REAL (n) / 134456.\nEND SUBROUTINE random0\n\n\nSUBROUTINE seed (iseed)\n USE ran001\nIMPLICIT NONE\n\nINTEGER, INTENT (in) :: iseed\n n = ABS (iseed)\nEND SUBROUTINE\n\n\nPROGRAM test_random0\n IMPLICIT NONE\n REAL :: ave\n INTEGER :: i\n INTEGER :: iseed\n INTEGER :: iseq\n REAL :: ran\n REAL :: sum\n\n WRITE (*,*) 'Enter seed: '\n READ (*,*) iseed\n\n CALL seed(iseed)\n WRITE (*,*) '10 random numbers '\n DO i = 1, 10\n CALL random0(ran)\n WRITE (*,'(3X,F16.6)') ran\n END DO\n WRITE (*,*) 'Average of 5 consecutive 1000-sample sequence'\n DO iseq = 1, 5\n sum = 0.\n DO i = 1, 1000\n CALL random0(ran)\n sum = sum + ran\n END DO\n ave = sum / 1000.\n WRITE (*,'(3X, F16.6)') ave\n END DO\nEND PROGRAM test_random0\n", "meta": {"hexsha": "212ed707caf33a4e910e80e2700dd4267558701c", "size": 941, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "basics/Module/random0.f90", "max_stars_repo_name": "ComplicatedPhenomenon/Fortran_Takeoff", "max_stars_repo_head_hexsha": "a13180050367e59a91973af96ab680c2b76097be", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "basics/Module/random0.f90", "max_issues_repo_name": "ComplicatedPhenomenon/Fortran_Takeoff", "max_issues_repo_head_hexsha": "a13180050367e59a91973af96ab680c2b76097be", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "basics/Module/random0.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": 16.8035714286, "max_line_length": 61, "alphanum_fraction": 0.6046758767, "num_tokens": 346, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711604559846, "lm_q2_score": 0.8104789063814616, "lm_q1q2_score": 0.6888836965821482}} {"text": "SUBROUTINE sparin(kv,kdiag)\n!\n! This subroutine performs Cholesky factorisation on a symmetric\n! skyline global matrix.\n!\n IMPLICIT NONE\n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\n REAL(iwp),INTENT(IN OUT)::kv(:)\n INTEGER,INTENT(IN)::kdiag(:)\n INTEGER::n,i,ki,l,kj,j,ll,m,k\n REAL(iwp)::x\n n=UBOUND(kdiag,1) \n kv(1)=SQRT(kv(1))\n DO i=2,n\n ki=kdiag(i)-i\n l=kdiag(i-1)-ki+1\n DO j=l,i\n x=kv(ki+j)\n kj=kdiag(j)-j\n IF(j/=1)THEN\n ll=kdiag(j-1)-kj+1\n ll=max(l,ll)\n IF(ll/=j)THEN\n m=j-1\n DO k=ll,m \n x=x-kv(ki+k)*kv(kj+k) \n END DO\n END IF\n END IF\n kv(ki+j)=x/kv(kj+j)\n END DO\n kv(ki+i)=SQRT(x)\n END DO\nRETURN\nEND SUBROUTINE sparin\n", "meta": {"hexsha": "6d2b150bc118101245fdbba18740efccf656949e", "size": 715, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "main/sparin.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/sparin.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/sparin.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": 19.8611111111, "max_line_length": 64, "alphanum_fraction": 0.5762237762, "num_tokens": 271, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147439, "lm_q2_score": 0.7549149978955811, "lm_q1q2_score": 0.688811738571248}} {"text": " subroutine fort_enforce_consistent_e(lo,hi,state, &\n state_l1,state_l2,state_l3,state_h1,state_h2,state_h3) & \n bind(C,name=\"fort_enforce_consistent_e\")\n\n use amrex_fort_module, only : rt => amrex_real\n use meth_params_module, only : NVAR, URHO, UMX, UMY, UMZ, UEDEN, UEINT\n\n implicit none\n\n integer :: lo(3), hi(3)\n integer :: state_l1,state_l2,state_l3,state_h1,state_h2,state_h3\n real(rt) :: state(state_l1:state_h1,state_l2:state_h2,state_l3:state_h3,NVAR)\n\n ! Local variables\n integer :: i,j,k\n real(rt) :: u, v, w, rhoInv\n\n ! \n ! Make sure to enforce (rho E) = (rho e) + 1/2 rho (u^2 +_ v^2 + w^2)\n !\n do k = lo(3), hi(3)\n do j = lo(2), hi(2)\n do i = lo(1), hi(1)\n\n rhoInv = 1.0d0 / state(i,j,k,URHO)\n\n u = state(i,j,k,UMX) * rhoInv\n v = state(i,j,k,UMY) * rhoInv\n w = state(i,j,k,UMZ) * rhoInv\n\n state(i,j,k,UEDEN) = state(i,j,k,UEINT) + &\n 0.5d0 * state(i,j,k,URHO) * (u*u + v*v + w*w)\n\n end do\n end do\n end do\n\n end subroutine fort_enforce_consistent_e\n", "meta": {"hexsha": "4f7bc2cf453e8a23481d441186fbb20647ef1d68", "size": 1212, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Source/Src_3d/enforce_consistent_e_3d.f90", "max_stars_repo_name": "Gosenca/axionyx_1.0", "max_stars_repo_head_hexsha": "7e2a723e00e6287717d6d81b23db32bcf6c3521a", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-02-18T09:13:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T21:27:46.000Z", "max_issues_repo_path": "Source/Src_3d/enforce_consistent_e_3d.f90", "max_issues_repo_name": "Gosenca/axionyx_1.0", "max_issues_repo_head_hexsha": "7e2a723e00e6287717d6d81b23db32bcf6c3521a", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-10-12T08:54:31.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-12T08:54:31.000Z", "max_forks_repo_path": "Source/Src_3d/enforce_consistent_e_3d.f90", "max_forks_repo_name": "Gosenca/axionyx_1.0", "max_forks_repo_head_hexsha": "7e2a723e00e6287717d6d81b23db32bcf6c3521a", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-09-04T10:26:25.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T23:51:51.000Z", "avg_line_length": 31.0769230769, "max_line_length": 97, "alphanum_fraction": 0.5255775578, "num_tokens": 399, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.912436167620237, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6888117324654287}} {"text": " subroutine convol(a, b, c, idima, jdima, idimb)\n\n!-------------------------------------------------------------\n! Convolve array A with kernel B to yield output array C.\n! Input matrix A is dimensioned idima x jdima\n! Input matrix B is dimensioned idimb x idimb (idimb must be an odd number)\n! Output matrix C is dimensioned idima x jdima\n!-------------------------------------------------------------\n implicit real(a-h,o-z)\n implicit integer(i-n)\n \n real(4) a(idima,jdima) ! matrix a\n real(4) b(idimb,idimb) ! matrix b\n real(4) c(idima,jdima) ! a convolved with b\n \n ihb = idimb/2\n c = sum(a)/(idima*jdima)\n \n do j = 1+ihb, jdima-ihb\n do i = 1+ihb, idima-ihb\n c(i,j) = sum(a(i-ihb:i+ihb, j-ihb:j+ihb)*b)\n enddo\n enddo\n\n return\n \nend subroutine convol\n", "meta": {"hexsha": "4fa18ba6081ea12ce17214655fd29a86c63fd926", "size": 815, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "convol.f90", "max_stars_repo_name": "teuben/ppmap", "max_stars_repo_head_hexsha": "2ff0b07350f883ee34ff4acc5eab374cdde8d327", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2018-05-31T16:15:35.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-12T14:22:57.000Z", "max_issues_repo_path": "convol.f90", "max_issues_repo_name": "teuben/ppmap", "max_issues_repo_head_hexsha": "2ff0b07350f883ee34ff4acc5eab374cdde8d327", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-09-05T20:28:54.000Z", "max_issues_repo_issues_event_max_datetime": "2018-09-05T20:28:54.000Z", "max_forks_repo_path": "convol.f90", "max_forks_repo_name": "teuben/ppmap", "max_forks_repo_head_hexsha": "2ff0b07350f883ee34ff4acc5eab374cdde8d327", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-05-31T16:15:28.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-07T16:35:39.000Z", "avg_line_length": 29.1071428571, "max_line_length": 75, "alphanum_fraction": 0.5300613497, "num_tokens": 252, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.91243616285804, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6888117288703748}} {"text": "MODULE constants\n\n ! Constants used by wrfpost\n\n REAL, PARAMETER :: CM2INCH = 1.0 / 2.54\n REAL, PARAMETER :: CP = 1005.7\n REAL, PARAMETER :: GRAV = 9.81\n INTEGER, PARAMETER :: IMISS = -99999\n INTEGER, PARAMETER :: ISMTH = 0\n INTEGER, PARAMETER :: JSMTH = 0\n REAL, PARAMETER :: LAPSE = 6.5E-03\n REAL, PARAMETER :: LV = 2.5E+06\n REAL, PARAMETER :: M2FEET = 3.281\n REAL, PARAMETER :: MPS2KNTS = 1.944\n REAL, PARAMETER :: MPS2MPH = 2.237\n REAL, PARAMETER :: PI = 3.1415927\n REAL, PARAMETER :: P0 = 100000.0\n REAL, PARAMETER :: R = 287.04\n REAL, PARAMETER :: RV = 461.5\n REAL, PARAMETER :: T0 = 273.15\n REAL, PARAMETER :: XMISS = -99999.9\n REAL, PARAMETER :: CPOG = CP / GRAV\n REAL, PARAMETER :: CPOR = CP / R\n REAL, PARAMETER :: DEG2RAD = PI / 180.0\n REAL, PARAMETER :: E = R / RV\n REAL, PARAMETER :: GOR = GRAV / R\n REAL, PARAMETER :: KAPPA = R / CP\n REAL, PARAMETER :: RAD2DEG = 180.0 / PI\n REAL, PARAMETER :: ROG = R / GRAV\n REAL, PARAMETER :: RVOLV = RV / LV\n REAL, PARAMETER :: rmissing = 1.e9\n \nEND MODULE constants\n\n\n", "meta": {"hexsha": "2c941e42ede1b93c7ee9db266f1a91a6d08580fa", "size": 1658, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/lib/bgdata/wrf/module_constants.f90", "max_stars_repo_name": "maxinye/laps-mirror", "max_stars_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_stars_repo_licenses": ["Intel", "Unlicense", "OLDAP-2.2.1", "NetCDF"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-04-05T12:28:22.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-29T06:37:29.000Z", "max_issues_repo_path": "src/lib/bgdata/wrf/module_constants.f90", "max_issues_repo_name": "longwosion/laps-mirror", "max_issues_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_issues_repo_licenses": ["Intel", "NetCDF", "OLDAP-2.2.1", "Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/lib/bgdata/wrf/module_constants.f90", "max_forks_repo_name": "longwosion/laps-mirror", "max_forks_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_forks_repo_licenses": ["Intel", "NetCDF", "OLDAP-2.2.1", "Unlicense"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-04-27T12:51:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-19T13:57:44.000Z", "avg_line_length": 46.0555555556, "max_line_length": 63, "alphanum_fraction": 0.3938480097, "num_tokens": 511, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147439, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6888117285089451}} {"text": "! =====================================================\nsubroutine rp1_ptwise(num_eqn, num_aux, num_waves, q_l, q_r, aux_l, aux_r, &\n wave, s, amdq, apdq)\n! =====================================================\n\n! # Pointwise Riemann solver for the acoustics equations in 1d, with\n! # variable coefficients (heterogeneous media)\n\n! waves: 2\n! equations: 2\n! aux fields: 2\n\n! Conserved quantities:\n! 1 pressure\n! 2 velocity\n\n! Auxiliary variables:\n! 1 impedance\n! 2 sound_speed\n\n! # auxl(1,i) should contain the impedance Z in cell i\n! # auxl(2,i) should contain the sound speed c in cell i\n\n! # On input, q_l contains the state vector on the left\n! # q_r contains the state vector on the right\n\n! # On output, wave contains the waves,\n! # s the speeds,\n! #\n! # amdq = A^- Delta q,\n! # apdq = A^+ Delta q,\n! # the decomposition of the flux difference\n! # f(q_l) - f(q_r)\n! # into leftgoing and rightgoing parts respectively.\n! #\n\n\n implicit none\n\n ! Input Arguments\n integer, intent(in) :: num_eqn, num_aux, num_waves\n real(kind=8), intent(in out) :: q_l(num_eqn), q_r(num_eqn)\n real(kind=8), intent(in out) :: aux_l(num_aux), aux_r(num_aux)\n\n ! Output arguments\n real(kind=8), intent(in out) :: wave(num_eqn, num_waves)\n real(kind=8), intent(in out) :: s(num_waves)\n real(kind=8), intent(in out) :: apdq(num_eqn), amdq(num_eqn)\n\n ! Locals\n real(kind=8) :: delta(2), a(2), zi, zim\n\n! # Split the jump in q into waves:\n\n! # Find a(1) and a(2), the coefficients of the 2 eigenvectors\n delta = q_r - q_l\n\n! # Impedances\n zi = aux_r(1)\n zim = aux_l(1)\n\n a(1) = (-delta(1) + zi*delta(2)) / (zim + zi)\n a(2) = (delta(1) + zim*delta(2)) / (zim + zi)\n \n! # Compute the waves:\n \n wave(1,1) = -a(1)*zim\n wave(2,1) = a(1)\n s(1) = -aux_l(2)\n \n wave(1,2) = a(2)*zi\n wave(2,2) = a(2)\n s(2) = aux_r(2)\n\n! # Compute the leftgoing and rightgoing fluctuations:\n! # Note s(1,i) < 0 and s(2,i) > 0.\n\n amdq = s(1)*wave(:,1)\n apdq = s(2)*wave(:,2)\n\n end subroutine rp1_ptwise\n", "meta": {"hexsha": "8bb55946ca29c6405ca1dc7a8217ca9c04db3842", "size": 2265, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/rp1_acoustics_variable_ptwise.f90", "max_stars_repo_name": "ranocha/riemann", "max_stars_repo_head_hexsha": "d7b4d72d1147eee12e60a64f46a7e076b28a212d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 27, "max_stars_repo_stars_event_min_datetime": "2015-03-08T03:42:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-21T01:46:12.000Z", "max_issues_repo_path": "src/rp1_acoustics_variable_ptwise.f90", "max_issues_repo_name": "ranocha/riemann", "max_issues_repo_head_hexsha": "d7b4d72d1147eee12e60a64f46a7e076b28a212d", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 47, "max_issues_repo_issues_event_min_datetime": "2015-02-11T15:39:22.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-25T01:56:46.000Z", "max_forks_repo_path": "src/rp1_acoustics_variable_ptwise.f90", "max_forks_repo_name": "ranocha/riemann", "max_forks_repo_head_hexsha": "d7b4d72d1147eee12e60a64f46a7e076b28a212d", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 37, "max_forks_repo_forks_event_min_datetime": "2015-01-09T21:44:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-21T12:53:04.000Z", "avg_line_length": 27.6219512195, "max_line_length": 79, "alphanum_fraction": 0.5262693157, "num_tokens": 724, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147439, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6888117285089451}} {"text": "MODULE shr_const_mod\n use shr_kind_mod\n integer(SHR_KIND_IN),parameter,private :: R8 = SHR_KIND_R8\n public\n real(R8),parameter :: SHR_CONST_PI = 3.14159265358979323846_R8\n real(R8),parameter :: SHR_CONST_CDAY = 86400.0_R8\n real(R8),parameter :: SHR_CONST_SDAY = 86164.0_R8\n real(R8),parameter :: SHR_CONST_OMEGA = 2.0_R8*SHR_CONST_PI/SHR_CONST_SDAY\n real(R8),parameter :: SHR_CONST_REARTH = 6.37122e6_R8\n real(R8),parameter :: SHR_CONST_G = 9.80616_R8\n real(R8),parameter :: SHR_CONST_STEBOL = 5.67e-8_R8\n real(R8),parameter :: SHR_CONST_BOLTZ = 1.38065e-23_R8\n real(R8),parameter :: SHR_CONST_AVOGAD = 6.02214e26_R8\n real(R8),parameter :: SHR_CONST_RGAS = SHR_CONST_AVOGAD*SHR_CONST_BOLTZ\n real(R8),parameter :: SHR_CONST_MWDAIR = 28.966_R8\n real(R8),parameter :: SHR_CONST_MWWV = 18.016_R8\n real(R8),parameter :: SHR_CONST_RDAIR = SHR_CONST_RGAS/SHR_CONST_MWDAIR\n real(R8),parameter :: SHR_CONST_RWV = SHR_CONST_RGAS/SHR_CONST_MWWV\n real(R8),parameter :: SHR_CONST_ZVIR = (SHR_CONST_RWV/SHR_CONST_RDAIR)-1.0_R8\n real(R8),parameter :: SHR_CONST_KARMAN = 0.4_R8\n real(R8),parameter :: SHR_CONST_PSTD = 101325.0_R8\n real(R8),parameter :: SHR_CONST_PDB = 0.0112372_R8\n real(R8),parameter :: SHR_CONST_TKTRIP = 273.16_R8\n real(R8),parameter :: SHR_CONST_TKFRZ = 273.15_R8\n real(R8),parameter :: SHR_CONST_TKFRZSW = SHR_CONST_TKFRZ - 1.8_R8\n real(R8),parameter :: SHR_CONST_RHODAIR = &\n SHR_CONST_PSTD/(SHR_CONST_RDAIR*SHR_CONST_TKFRZ)\n real(R8),parameter :: SHR_CONST_RHOFW = 1.000e3_R8\n real(R8),parameter :: SHR_CONST_RHOSW = 1.026e3_R8\n real(R8),parameter :: SHR_CONST_RHOICE = 0.917e3_R8\n real(R8),parameter :: SHR_CONST_CPDAIR = 1.00464e3_R8\n real(R8),parameter :: SHR_CONST_CPWV = 1.810e3_R8\n real(R8),parameter :: SHR_CONST_CPVIR = (SHR_CONST_CPWV/SHR_CONST_CPDAIR)-1.0_R8\n real(R8),parameter :: SHR_CONST_CPFW = 4.188e3_R8\n real(R8),parameter :: SHR_CONST_CPSW = 3.996e3_R8\n real(R8),parameter :: SHR_CONST_CPICE = 2.11727e3_R8\n real(R8),parameter :: SHR_CONST_LATICE = 3.337e5_R8\n real(R8),parameter :: SHR_CONST_LATVAP = 2.501e6_R8\n real(R8),parameter :: SHR_CONST_LATSUB = &\n SHR_CONST_LATICE + SHR_CONST_LATVAP\n real(R8),parameter :: SHR_CONST_OCN_REF_SAL = 34.7_R8\n real(R8),parameter :: SHR_CONST_ICE_REF_SAL = 4.0_R8\n real(R8),parameter :: SHR_CONST_SPVAL = 1.0e30_R8\nEND MODULE shr_const_mod\n", "meta": {"hexsha": "138e6796cfc5fa56344ed27791ede15af7d0719d", "size": 2433, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "WRF-CHEM/phys/module_cam_shr_const_mod.f90", "max_stars_repo_name": "ksetigui/paper_gmd-2020-50", "max_stars_repo_head_hexsha": "1c4bf2b0946bc31cfb443686c8aa1e33755d5fd2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "WRF-CHEM/phys/module_cam_shr_const_mod.f90", "max_issues_repo_name": "ksetigui/paper_gmd-2020-50", "max_issues_repo_head_hexsha": "1c4bf2b0946bc31cfb443686c8aa1e33755d5fd2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "WRF-CHEM/phys/module_cam_shr_const_mod.f90", "max_forks_repo_name": "ksetigui/paper_gmd-2020-50", "max_forks_repo_head_hexsha": "1c4bf2b0946bc31cfb443686c8aa1e33755d5fd2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.0666666667, "max_line_length": 83, "alphanum_fraction": 0.7295519934, "num_tokens": 907, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361509525462, "lm_q2_score": 0.7549149868676284, "lm_q1q2_score": 0.6888117249138908}} {"text": " double precision function DCOS1 (X)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc>> 1994-10-20 DCOS1 Krogh Changes to use M77CON\nc>> 1993-07-21 DCOS1 WV Snyder JPL Original code\nc\nc compute (1 - cos(x)) / x**2.\nc\nc--D replaces \"?\": ?COS1\nc\n double precision X\n double precision C, SINC\nc\n if (x .eq. 0.0d0) then\n dcos1 = 0.5d0\n else\n c = cos(x)\n if (c .le. 0.0) then\n dcos1 = (1.0d0 - c ) / x*x\n else\n sinc = sin(x) / x\n dcos1 = sinc**2 / (1.0d0 + c)\n end if\n end if\n return\n end\n", "meta": {"hexsha": "d20c8502ff0c2d6bca32d8450cda9f9bf9fc1566", "size": 706, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/dcos1.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/dcos1.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/dcos1.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": 25.2142857143, "max_line_length": 70, "alphanum_fraction": 0.5538243626, "num_tokens": 246, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147439, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6888117234777936}} {"text": "!\n! (c) 2019 Guide Star Engineering, LLC\n! This Software was developed for the US Nuclear Regulatory Commission (US NRC)\n! under contract \"Multi-Dimensional Physics Implementation into Fuel Analysis under\n! Steady-state and Transients (FAST)\", contract # NRC-HQ-60-17-C-0007\n!\n! NEMO - Numerical Engine (for) Multiphysics Operators\n! Copyright (c) 2007, Stefano Toninel\n! Gian Marco Bianchi University of Bologna\n! David P. Schmidt University of Massachusetts - Amherst\n! Salvatore Filippone University of Rome Tor Vergata\n! All rights reserved.\n!\n! Redistribution and use in source and binary forms, with or without modification,\n! are permitted provided that the following conditions are met:\n!\n! 1. Redistributions of source code must retain the above copyright notice,\n! this list of conditions and the following disclaimer.\n! 2. Redistributions in binary form must reproduce the above copyright notice,\n! this list of conditions and the following disclaimer in the documentation\n! and/or other materials provided with the distribution.\n! 3. Neither the name of the NEMO project nor the names of its contributors\n! may be used to endorse or promote products derived from this software\n! without specific prior written permission.\n!\n! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\n! ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n! WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n! DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR\n! ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n! (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON\n! ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n! (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\n! SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n!\n!---------------------------------------------------------------------------------\n!\n! $Id: geom_tet_dihedral_angle.f90 3093 2008-04-22 14:51:09Z sfilippo $\n!\n! Description:\n! Calculates the smallest dihedral angle (in radians).\n! Note that dihedral angle is equal to the angle between normal vectors.\n! WARNING! Only tets are currently supported.\n!\nSUBMODULE(tools_mesh_basics) geom_tet_dihedral_angle_implementation\n USE class_vector, ONLY : vector, OPERATOR(.dot.)\n IMPLICIT NONE\n\n CONTAINS\n\n MODULE PROCEDURE geom_tet_dihedral_angle\n USE class_psblas, ONLY : psb_dpk_\n USE tools_math, ONLY : Pi\n IMPLICIT NONE\n !!\n INTEGER :: if1, if2\n REAL(psb_dpk_) :: arg !! argument of the acos function\n REAL(psb_dpk_) :: angle !! between two faces\n TYPE(vector) :: unitnorm(4)\n\n unitnorm(:) = af(:)%unit()\n\n largest = 0.d0 !! Initialize to smallest possible value\n smallest = pi !! Initialize to largest possible value\n\n DO if2 = 1, 3\n DO if1 = if2 + 1, 4\n ! cosine = dot product of two vectors/divided by the product of their magnitude\n\n ! area contains the normal scaled so the mag. = the face area\n arg = (unitnorm(if1) .dot. unitnorm(if2))\n\n angle = ACOS(arg)\n\n largest = MAX(largest,angle)\n smallest = MIN(smallest,angle)\n ENDDO\n ENDDO\n\n END PROCEDURE geom_tet_dihedral_angle\n\nEND SUBMODULE geom_tet_dihedral_angle_implementation\n", "meta": {"hexsha": "4a28903b09b0a19622f11780534d89e013945811", "size": 3786, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/FV/src/mesh_basics/geom_tet_dihedral_angle.f90", "max_stars_repo_name": "sourceryinstitute/MORFEUS-Source", "max_stars_repo_head_hexsha": "38659b1097e89e3dea8f5e7e83acf98bfe6623bd", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 19, "max_stars_repo_stars_event_min_datetime": "2019-09-19T03:00:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T02:07:07.000Z", "max_issues_repo_path": "src/FV/src/mesh_basics/geom_tet_dihedral_angle.f90", "max_issues_repo_name": "sourceryinstitute/MORFEUS-Source", "max_issues_repo_head_hexsha": "38659b1097e89e3dea8f5e7e83acf98bfe6623bd", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 43, "max_issues_repo_issues_event_min_datetime": "2019-09-10T04:59:39.000Z", "max_issues_repo_issues_event_max_datetime": "2020-02-28T22:02:45.000Z", "max_forks_repo_path": "src/FV/src/mesh_basics/geom_tet_dihedral_angle.f90", "max_forks_repo_name": "sourceryinstitute/MORFEUS-Source", "max_forks_repo_head_hexsha": "38659b1097e89e3dea8f5e7e83acf98bfe6623bd", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-01-28T03:13:26.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-06T04:13:20.000Z", "avg_line_length": 45.0714285714, "max_line_length": 99, "alphanum_fraction": 0.6653460116, "num_tokens": 847, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951698485603, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.688797031970233}} {"text": "C\nC file hstcsp.f\nC\n SUBROUTINE HSTCSP (INTL,A,B,M,MBDCND,BDA,BDB,C,D,N,NBDCND,BDC,\n 1 BDD,ELMBDA,F,IDIMF,PERTRB,IERROR,W)\nC\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC * *\nC * copyright (c) 1999 by UCAR *\nC * *\nC * UNIVERSITY CORPORATION for ATMOSPHERIC RESEARCH *\nC * *\nC * all rights reserved *\nC * *\nC * FISHPACK version 4.1 *\nC * *\nC * A PACKAGE OF FORTRAN SUBPROGRAMS FOR THE SOLUTION OF *\nC * *\nC * SEPARABLE ELLIPTIC PARTIAL DIFFERENTIAL EQUATIONS *\nC * *\nC * BY *\nC * *\nC * JOHN ADAMS, PAUL SWARZTRAUBER AND ROLAND SWEET *\nC * *\nC * OF *\nC * *\nC * THE NATIONAL CENTER FOR ATMOSPHERIC RESEARCH *\nC * *\nC * BOULDER, COLORADO (80307) U.S.A. *\nC * *\nC * WHICH IS SPONSORED BY *\nC * *\nC * THE NATIONAL SCIENCE FOUNDATION *\nC * *\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC\nC\nC\nC DIMENSION OF BDA(N),BDB(N),BDC(M),BDD(M),F(IDIMF,N),\nC ARGUMENTS W(SEE ARGUMENT LIST)\nC\nC LATEST REVISION NOVEMBER 1988\nC\nC PURPOSE SOLVES THE STANDARD FIVE-POINT FINITE\nC DIFFERENCE APPROXIMATION ON A STAGGERED\nC GRID TO THE MODIFIED HELMHOLTZ EQUATION IN\nC SPHERICAL COORDINATES ASSUMING AXISYMMETRY\nC (NO DEPENDENCE ON LONGITUDE).\nC\nC THE EQUATION IS\nC\nC (1/R**2)(D/DR)(R**2(DU/DR)) +\nC 1/(R**2*SIN(THETA))(D/DTHETA)\nC (SIN(THETA)(DU/DTHETA)) +\nC (LAMBDA/(R*SIN(THETA))**2)U = F(THETA,R)\nC\nC WHERE THETA IS COLATITUDE AND R IS THE\nC RADIAL COORDINATE. THIS TWO-DIMENSIONAL\nC MODIFIED HELMHOLTZ EQUATION RESULTS FROM\nC THE FOURIER TRANSFORM OF THE THREE-\nC DIMENSIONAL POISSON EQUATION.\nC\nC\nC USAGE CALL HSTCSP (INTL,A,B,M,MBDCND,BDA,BDB,C,D,N,\nC NBDCND,BDC,BDD,ELMBDA,F,IDIMF,\nC PERTRB,IERROR,W)\nC\nC ARGUMENTS\nC ON INPUT INTL\nC\nC = 0 ON INITIAL ENTRY TO HSTCSP OR IF ANY\nC OF THE ARGUMENTS C, D, N, OR NBDCND\nC ARE CHANGED FROM A PREVIOUS CALL\nC\nC = 1 IF C, D, N, AND NBDCND ARE ALL\nC UNCHANGED FROM PREVIOUS CALL TO HSTCSP\nC\nC NOTE:\nC A CALL WITH INTL = 0 TAKES APPROXIMATELY\nC 1.5 TIMES AS MUCH TIME AS A CALL WITH\nC INTL = 1. ONCE A CALL WITH INTL = 0\nC HAS BEEN MADE THEN SUBSEQUENT SOLUTIONS\nC CORRESPONDING TO DIFFERENT F, BDA, BDB,\nC BDC, AND BDD CAN BE OBTAINED FASTER WITH\nC INTL = 1 SINCE INITIALIZATION IS NOT\nC REPEATED.\nC\nC A,B\nC THE RANGE OF THETA (COLATITUDE),\nC I.E. A .LE. THETA .LE. B. A\nC MUST BE LESS THAN B AND A MUST BE\nC NON-NEGATIVE. A AND B ARE IN RADIANS.\nC A = 0 CORRESPONDS TO THE NORTH POLE AND\nC B = PI CORRESPONDS TO THE SOUTH POLE.\nC\nC * * * IMPORTANT * * *\nC\nC IF B IS EQUAL TO PI, THEN B MUST BE\nC COMPUTED USING THE STATEMENT\nC B = PIMACH(DUM)\nC THIS INSURES THAT B IN THE USER'S PROGRAM\nC IS EQUAL TO PI IN THIS PROGRAM, PERMITTING\nC SEVERAL TESTS OF THE INPUT PARAMETERS THAT\nC OTHERWISE WOULD NOT BE POSSIBLE.\nC\nC * * * * * * * * * * * *\nC\nC M\nC THE NUMBER OF GRID POINTS IN THE INTERVAL\nC (A,B). THE GRID POINTS IN THE THETA-\nC DIRECTION ARE GIVEN BY\nC THETA(I) = A + (I-0.5)DTHETA\nC FOR I=1,2,...,M WHERE DTHETA =(B-A)/M.\nC M MUST BE GREATER THAN 4.\nC\nC MBDCND\nC INDICATES THE TYPE OF BOUNDARY CONDITIONS\nC AT THETA = A AND THETA = B.\nC\nC = 1 IF THE SOLUTION IS SPECIFIED AT\nC THETA = A AND THETA = B.\nC (SEE NOTES 1, 2 BELOW)\nC\nC = 2 IF THE SOLUTION IS SPECIFIED AT\nC THETA = A AND THE DERIVATIVE OF THE\nC SOLUTION WITH RESPECT TO THETA IS\nC SPECIFIED AT THETA = B\nC (SEE NOTES 1, 2 BELOW).\nC\nC = 3 IF THE DERIVATIVE OF THE SOLUTION\nC WITH RESPECT TO THETA IS SPECIFIED\nC AT THETA = A (SEE NOTES 1, 2 BELOW)\nC AND THETA = B.\nC\nC = 4 IF THE DERIVATIVE OF THE SOLUTION\nC WITH RESPECT TO THETA IS SPECIFIED AT\nC THETA = A (SEE NOTES 1, 2 BELOW) AND\nC THE SOLUTION IS SPECIFIED AT THETA = B.\nC\nC = 5 IF THE SOLUTION IS UNSPECIFIED AT\nC THETA = A = 0 AND THE SOLUTION IS\nC SPECIFIED AT THETA = B.\nC (SEE NOTE 2 BELOW)\nC\nC = 6 IF THE SOLUTION IS UNSPECIFIED AT\nC THETA = A = 0 AND THE DERIVATIVE OF\nC THE SOLUTION WITH RESPECT TO THETA IS\nC SPECIFIED AT THETA = B\nC (SEE NOTE 2 BELOW).\nC\nC = 7 IF THE SOLUTION IS SPECIFIED AT\nC THETA = A AND THE SOLUTION IS\nC UNSPECIFIED AT THETA = B = PI.\nC\nC = 8 IF THE DERIVATIVE OF THE SOLUTION\nC WITH RESPECT TO THETA IS SPECIFIED AT\nC THETA = A (SEE NOTE 1 BELOW)\nC AND THE SOLUTION IS UNSPECIFIED AT\nC THETA = B = PI.\nC\nC = 9 IF THE SOLUTION IS UNSPECIFIED AT\nC THETA = A = 0 AND THETA = B = PI.\nC\nC NOTE 1:\nC IF A = 0, DO NOT USE MBDCND = 1,2,3,4,7\nC OR 8, BUT INSTEAD USE MBDCND = 5, 6, OR 9.\nC\nC NOTE 2:\nC IF B = PI, DO NOT USE MBDCND = 1,2,3,4,5,\nC OR 6, BUT INSTEAD USE MBDCND = 7, 8, OR 9.\nC\nC NOTE 3:\nC WHEN A = 0 AND/OR B = PI THE ONLY\nC MEANINGFUL BOUNDARY CONDITION IS\nC DU/DTHETA = 0. SEE D. GREENSPAN,\nC 'NUMERICAL ANALYSIS OF ELLIPTIC\nC BOUNDARY VALUE PROBLEMS,'\nC HARPER AND ROW, 1965, CHAPTER 5.)\nC\nC BDA\nC A ONE-DIMENSIONAL ARRAY OF LENGTH N THAT\nC SPECIFIES THE BOUNDARY VALUES (IF ANY) OF\nC THE SOLUTION AT THETA = A.\nC\nC WHEN MBDCND = 1, 2, OR 7,\nC BDA(J) = U(A,R(J)), J=1,2,...,N.\nC\nC WHEN MBDCND = 3, 4, OR 8,\nC BDA(J) = (D/DTHETA)U(A,R(J)), J=1,2,...,N.\nC\nC WHEN MBDCND HAS ANY OTHER VALUE, BDA IS A\nC DUMMY VARIABLE.\nC\nC BDB\nC A ONE-DIMENSIONAL ARRAY OF LENGTH N THAT\nC SPECIFIES THE BOUNDARY VALUES OF THE\nC SOLUTION AT THETA = B.\nC\nC WHEN MBDCND = 1, 4, OR 5,\nC BDB(J) = U(B,R(J)), J=1,2,...,N.\nC\nC WHEN MBDCND = 2,3, OR 6,\nC BDB(J) = (D/DTHETA)U(B,R(J)), J=1,2,...,N.\nC\nC WHEN MBDCND HAS ANY OTHER VALUE, BDB IS\nC A DUMMY VARIABLE.\nC\nC C,D\nC THE RANGE OF R , I.E. C .LE. R .LE. D.\nC C MUST BE LESS THAN D AND NON-NEGATIVE.\nC\nC N\nC THE NUMBER OF UNKNOWNS IN THE INTERVAL\nC (C,D). THE UNKNOWNS IN THE R-DIRECTION\nC ARE GIVEN BY R(J) = C + (J-0.5)DR,\nC J=1,2,...,N, WHERE DR = (D-C)/N.\nC N MUST BE GREATER THAN 4.\nC\nC NBDCND\nC INDICATES THE TYPE OF BOUNDARY CONDITIONS\nC AT R = C AND R = D.\nC\nC\nC = 1 IF THE SOLUTION IS SPECIFIED AT\nC R = C AND R = D.\nC\nC = 2 IF THE SOLUTION IS SPECIFIED AT\nC R = C AND THE DERIVATIVE OF THE\nC SOLUTION WITH RESPECT TO R IS\nC SPECIFIED AT R = D. (SEE NOTE 1 BELOW)\nC\nC = 3 IF THE DERIVATIVE OF THE SOLUTION\nC WITH RESPECT TO R IS SPECIFIED AT\nC R = C AND R = D.\nC\nC = 4 IF THE DERIVATIVE OF THE SOLUTION\nC WITH RESPECT TO R IS\nC SPECIFIED AT R = C AND THE SOLUTION\nC IS SPECIFIED AT R = D.\nC\nC = 5 IF THE SOLUTION IS UNSPECIFIED AT\nC R = C = 0 (SEE NOTE 2 BELOW) AND THE\nC SOLUTION IS SPECIFIED AT R = D.\nC\nC = 6 IF THE SOLUTION IS UNSPECIFIED AT\nC R = C = 0 (SEE NOTE 2 BELOW)\nC AND THE DERIVATIVE OF THE SOLUTION\nC WITH RESPECT TO R IS SPECIFIED AT\nC R = D.\nC\nC NOTE 1:\nC IF C = 0 AND MBDCND = 3,6,8 OR 9, THE\nC SYSTEM OF EQUATIONS TO BE SOLVED IS\nC SINGULAR. THE UNIQUE SOLUTION IS\nC DETERMINED BY EXTRAPOLATION TO THE\nC SPECIFICATION OF U(THETA(1),C).\nC BUT IN THESE CASES THE RIGHT SIDE OF THE\nC SYSTEM WILL BE PERTURBED BY THE CONSTANT\nC PERTRB.\nC\nC NOTE 2:\nC NBDCND = 5 OR 6 CANNOT BE USED WITH\nC MBDCND =1, 2, 4, 5, OR 7\nC (THE FORMER INDICATES THAT THE SOLUTION IS\nC UNSPECIFIED AT R = 0; THE LATTER INDICATES\nC SOLUTION IS SPECIFIED).\nC USE INSTEAD NBDCND = 1 OR 2.\nC\nC BDC\nC A ONE DIMENSIONAL ARRAY OF LENGTH M THAT\nC SPECIFIES THE BOUNDARY VALUES OF THE\nC SOLUTION AT R = C. WHEN NBDCND = 1 OR 2,\nC BDC(I) = U(THETA(I),C), I=1,2,...,M.\nC\nC WHEN NBDCND = 3 OR 4,\nC BDC(I) = (D/DR)U(THETA(I),C), I=1,2,...,M.\nC\nC WHEN NBDCND HAS ANY OTHER VALUE, BDC IS\nC A DUMMY VARIABLE.\nC\nC BDD\nC A ONE-DIMENSIONAL ARRAY OF LENGTH M THAT\nC SPECIFIES THE BOUNDARY VALUES OF THE\nC SOLUTION AT R = D. WHEN NBDCND = 1 OR 4,\nC BDD(I) = U(THETA(I),D) , I=1,2,...,M.\nC\nC WHEN NBDCND = 2 OR 3,\nC BDD(I) = (D/DR)U(THETA(I),D), I=1,2,...,M.\nC\nC WHEN NBDCND HAS ANY OTHER VALUE, BDD IS\nC A DUMMY VARIABLE.\nC\nC ELMBDA\nC THE CONSTANT LAMBDA IN THE MODIFIED\nC HELMHOLTZ EQUATION. IF LAMBDA IS GREATER\nC THAN 0, A SOLUTION MAY NOT EXIST.\nC HOWEVER, HSTCSP WILL ATTEMPT TO FIND A\nC SOLUTION.\nC\nC F\nC A TWO-DIMENSIONAL ARRAY THAT SPECIFIES THE\nC VALUES OF THE RIGHT SIDE OF THE MODIFIED\nC HELMHOLTZ EQUATION. FOR I=1,2,...,M AND\nC J=1,2,...,N\nC\nC F(I,J) = F(THETA(I),R(J)) .\nC\nC F MUST BE DIMENSIONED AT LEAST M X N.\nC\nC IDIMF\nC THE ROW (OR FIRST) DIMENSION OF THE ARRAY\nC F AS IT APPEARS IN THE PROGRAM CALLING\nC HSTCSP. THIS PARAMETER IS USED TO SPECIFY\nC THE VARIABLE DIMENSION OF F.\nC IDIMF MUST BE AT LEAST M.\nC\nC W\nC A ONE-DIMENSIONAL ARRAY THAT MUST BE\nC PROVIDED BY THE USER FOR WORK SPACE.\nC WITH K = INT(LOG2(N))+1 AND L = 2**(K+1),\nC W MAY REQUIRE UP TO\nC (K-2)*L+K+MAX(2N,6M)+4(N+M)+5 LOCATIONS.\nC THE ACTUAL NUMBER OF LOCATIONS USED IS\nC COMPUTED BY HSTCSP AND IS RETURNED IN THE\nC LOCATION W(1).\nC\nC\nC ON OUTPUT F\nC CONTAINS THE SOLUTION U(I,J) OF THE FINITE\nC DIFFERENCE APPROXIMATION FOR THE GRID POINT\nC (THETA(I),R(J)) FOR I=1,2,..,M, J=1,2,...,N.\nC\nC PERTRB\nC IF A COMBINATION OF PERIODIC, DERIVATIVE,\nC OR UNSPECIFIED BOUNDARY CONDITIONS IS\nC SPECIFIED FOR A POISSON EQUATION\nC (LAMBDA = 0), A SOLUTION MAY NOT EXIST.\nC PERTRB IS A CONSTANT, CALCULATED AND\nC SUBTRACTED FROM F, WHICH ENSURES THAT A\nC SOLUTION EXISTS. HSTCSP THEN COMPUTES THIS\nC SOLUTION, WHICH IS A LEAST SQUARES SOLUTION\nC TO THE ORIGINAL APPROXIMATION.\nC THIS SOLUTION PLUS ANY CONSTANT IS ALSO\nC A SOLUTION; HENCE, THE SOLUTION IS NOT\nC UNIQUE. THE VALUE OF PERTRB SHOULD BE\nC SMALL COMPARED TO THE RIGHT SIDE F.\nC OTHERWISE, A SOLUTION IS OBTAINED TO AN\nC ESSENTIALLY DIFFERENT PROBLEM.\nC THIS COMPARISON SHOULD ALWAYS BE MADE TO\nC INSURE THAT A MEANINGFUL SOLUTION HAS BEEN\nC OBTAINED.\nC\nC IERROR\nC AN ERROR FLAG THAT INDICATES INVALID INPUT\nC PARAMETERS. EXCEPT FOR NUMBERS 0 AND 10,\nC A SOLUTION IS NOT ATTEMPTED.\nC\nC = 0 NO ERROR\nC\nC = 1 A .LT. 0 OR B .GT. PI\nC\nC = 2 A .GE. B\nC\nC = 3 MBDCND .LT. 1 OR MBDCND .GT. 9\nC\nC = 4 C .LT. 0\nC\nC = 5 C .GE. D\nC\nC = 6 NBDCND .LT. 1 OR NBDCND .GT. 6\nC\nC = 7 N .LT. 5\nC\nC = 8 NBDCND = 5 OR 6 AND\nC MBDCND = 1, 2, 4, 5, OR 7\nC\nC = 9 C .GT. 0 AND NBDCND .GE. 5\nC\nC = 10 ELMBDA .GT. 0\nC\nC = 11 IDIMF .LT. M\nC\nC = 12 M .LT. 5\nC\nC = 13 A = 0 AND MBDCND =1,2,3,4,7 OR 8\nC\nC = 14 B = PI AND MBDCND .LE. 6\nC\nC = 15 A .GT. 0 AND MBDCND = 5, 6, OR 9\nC\nC = 16 B .LT. PI AND MBDCND .GE. 7\nC\nC = 17 LAMBDA .NE. 0 AND NBDCND .GE. 5\nC\nC SINCE THIS IS THE ONLY MEANS OF INDICATING\nC A POSSIBLY INCORRECT CALL TO HSTCSP,\nC THE USER SHOULD TEST IERROR AFTER THE CALL.\nC\nC W\nC W(1) CONTAINS THE REQUIRED LENGTH OF W.\nC ALSO W CONTAINS INTERMEDIATE VALUES THAT\nC MUST NOT BE DESTROYED IF HSTCSP WILL BE\nC CALLED AGAIN WITH INTL = 1.\nC\nC I/O NONE\nC\nC PRECISION SINGLE\nC\nC REQUIRED LIBRARY BLKTRI AND COMF FROM FISHPACK\nC FILES\nC\nC LANGUAGE FORTRAN\nC\nC HISTORY WRITTEN BY ROLAND SWEET AT NCAR IN 1977.\nC RELEASED ON NCAR'S PUBLIC SOFTWARE LIBRARIES\nC IN JANUARY 1980.\nC\nC PORTABILITY FORTRAN 77\nC\nC ALGORITHM THIS SUBROUTINE DEFINES THE FINITE-DIFFERENCE\nC EQUATIONS, INCORPORATES BOUNDARY DATA, ADJUSTS\nC THE RIGHT SIDE WHEN THE SYSTEM IS SINGULAR\nC AND CALLS BLKTRI WHICH SOLVES THE LINEAR\nC SYSTEM OF EQUATIONS.\nC\nC\nC TIMING FOR LARGE M AND N, THE OPERATION COUNT IS\nC ROUGHLY PROPORTIONAL TO M*N*LOG2(N). THE\nC TIMING ALSO DEPENDS ON INPUT PARAMETER INTL.\nC\nC ACCURACY THE SOLUTION PROCESS EMPLOYED RESULTS IN\nC A LOSS OF NO MORE THAN FOUR SIGNIFICANT\nC DIGITS FOR N AND M AS LARGE AS 64.\nC MORE DETAILED INFORMATION ABOUT ACCURACY\nC CAN BE FOUND IN THE DOCUMENTATION FOR\nC SUBROUTINE BLKTRI WHICH IS THE ROUTINE\nC SOLVES THE FINITE DIFFERENCE EQUATIONS.\nC\nC REFERENCES P.N. SWARZTRAUBER, \"A DIRECT METHOD FOR\nC THE DISCRETE SOLUTION OF SEPARABLE ELLIPTIC\nC EQUATIONS\",\nC SIAM J. NUMER. ANAL. 11(1974), PP. 1136-1150.\nC\nC U. SCHUMANN AND R. SWEET, \"A DIRECT METHOD FOR\nC THE SOLUTION OF POISSON'S EQUATION WITH NEUMANN\nC BOUNDARY CONDITIONS ON A STAGGERED GRID OF\nC ARBITRARY SIZE,\" J. COMP. PHYS. 20(1976),\nC PP. 171-182.\nC***********************************************************************\n DIMENSION F(IDIMF,1) ,BDA(*) ,BDB(*) ,BDC(*) ,\n 1 BDD(*) ,W(*)\nC\n PI = PIMACH(DUM)\nC\nC CHECK FOR INVALID INPUT PARAMETERS\nC\n IERROR = 0\n IF (A.LT.0. .OR. B.GT.PI) IERROR = 1\n IF (A .GE. B) IERROR = 2\n IF (MBDCND.LT.1 .OR. MBDCND.GT.9) IERROR = 3\n IF (C .LT. 0.) IERROR = 4\n IF (C .GE. D) IERROR = 5\n IF (NBDCND.LT.1 .OR. NBDCND.GT.6) IERROR = 6\n IF (N .LT. 5) IERROR = 7\n IF ((NBDCND.EQ.5 .OR. NBDCND.EQ.6) .AND. (MBDCND.EQ.1 .OR.\n 1 MBDCND.EQ.2 .OR. MBDCND.EQ.4 .OR. MBDCND.EQ.5 .OR.\n 2 MBDCND.EQ.7))\n 3 IERROR = 8\n IF (C.GT.0. .AND. NBDCND.GE.5) IERROR = 9\n IF (IDIMF .LT. M) IERROR = 11\n IF (M .LT. 5) IERROR = 12\n IF (A.EQ.0. .AND. MBDCND.NE.5 .AND. MBDCND.NE.6 .AND. MBDCND.NE.9)\n 1 IERROR = 13\n IF (B.EQ.PI .AND. MBDCND.LE.6) IERROR = 14\n IF (A.GT.0. .AND. (MBDCND.EQ.5 .OR. MBDCND.EQ.6 .OR. MBDCND.EQ.9))\n 1 IERROR = 15\n IF (B.LT.PI .AND. MBDCND.GE.7) IERROR = 16\n IF (ELMBDA.NE.0. .AND. NBDCND.GE.5) IERROR = 17\n IF (IERROR .NE. 0) GO TO 101\n IWBM = M+1\n IWCM = IWBM+M\n IWAN = IWCM+M\n IWBN = IWAN+N\n IWCN = IWBN+N\n IWSNTH = IWCN+N\n IWRSQ = IWSNTH+M\n IWWRK = IWRSQ+N\n IERR1 = 0\n CALL HSTCS1 (INTL,A,B,M,MBDCND,BDA,BDB,C,D,N,NBDCND,BDC,BDD,\n 1 ELMBDA,F,IDIMF,PERTRB,IERR1,W,W(IWBM),W(IWCM),\n 2 W(IWAN),W(IWBN),W(IWCN),W(IWSNTH),W(IWRSQ),W(IWWRK))\n W(1) = W(IWWRK)+FLOAT(IWWRK-1)\n IERROR = IERR1\n 101 CONTINUE\n RETURN\n END\n SUBROUTINE HSTCS1 (INTL,A,B,M,MBDCND,BDA,BDB,C,D,N,NBDCND,BDC,\n 1 BDD,ELMBDA,F,IDIMF,PERTRB,IERR1,AM,BM,CM,AN,\n 2 BN,CN,SNTH,RSQ,WRK)\n DIMENSION BDA(*) ,BDB(*) ,BDC(*) ,BDD(*) ,\n 1 F(IDIMF,1) ,AM(*) ,BM(*) ,CM(*) ,\n 2 AN(*) ,BN(*) ,CN(*) ,SNTH(*) ,\n 3 RSQ(*) ,WRK(*)\n DTH = (B-A)/FLOAT(M)\n DTHSQ = DTH*DTH\n DO 101 I=1,M\n SNTH(I) = SIN(A+(FLOAT(I)-0.5)*DTH)\n 101 CONTINUE\n DR = (D-C)/FLOAT(N)\n DO 102 J=1,N\n RSQ(J) = (C+(FLOAT(J)-0.5)*DR)**2\n 102 CONTINUE\nC\nC MULTIPLY RIGHT SIDE BY R(J)**2\nC\n DO 104 J=1,N\n X = RSQ(J)\n DO 103 I=1,M\n F(I,J) = X*F(I,J)\n 103 CONTINUE\n 104 CONTINUE\nC\nC DEFINE COEFFICIENTS AM,BM,CM\nC\n X = 1./(2.*COS(DTH/2.))\n DO 105 I=2,M\n AM(I) = (SNTH(I-1)+SNTH(I))*X\n CM(I-1) = AM(I)\n 105 CONTINUE\n AM(1) = SIN(A)\n CM(M) = SIN(B)\n DO 106 I=1,M\n X = 1./SNTH(I)\n Y = X/DTHSQ\n AM(I) = AM(I)*Y\n CM(I) = CM(I)*Y\n BM(I) = ELMBDA*X*X-AM(I)-CM(I)\n 106 CONTINUE\nC\nC DEFINE COEFFICIENTS AN,BN,CN\nC\n X = C/DR\n DO 107 J=1,N\n AN(J) = (X+FLOAT(J-1))**2\n CN(J) = (X+FLOAT(J))**2\n BN(J) = -(AN(J)+CN(J))\n 107 CONTINUE\n ISW = 1\n NB = NBDCND\n IF (C.EQ.0. .AND. NB.EQ.2) NB = 6\nC\nC ENTER DATA ON THETA BOUNDARIES\nC\n GO TO (108,108,110,110,112,112,108,110,112),MBDCND\n 108 BM(1) = BM(1)-AM(1)\n X = 2.*AM(1)\n DO 109 J=1,N\n F(1,J) = F(1,J)-X*BDA(J)\n 109 CONTINUE\n GO TO 112\n 110 BM(1) = BM(1)+AM(1)\n X = DTH*AM(1)\n DO 111 J=1,N\n F(1,J) = F(1,J)+X*BDA(J)\n 111 CONTINUE\n 112 CONTINUE\n GO TO (113,115,115,113,113,115,117,117,117),MBDCND\n 113 BM(M) = BM(M)-CM(M)\n X = 2.*CM(M)\n DO 114 J=1,N\n F(M,J) = F(M,J)-X*BDB(J)\n 114 CONTINUE\n GO TO 117\n 115 BM(M) = BM(M)+CM(M)\n X = DTH*CM(M)\n DO 116 J=1,N\n F(M,J) = F(M,J)-X*BDB(J)\n 116 CONTINUE\n 117 CONTINUE\nC\nC ENTER DATA ON R BOUNDARIES\nC\n GO TO (118,118,120,120,122,122),NB\n 118 BN(1) = BN(1)-AN(1)\n X = 2.*AN(1)\n DO 119 I=1,M\n F(I,1) = F(I,1)-X*BDC(I)\n 119 CONTINUE\n GO TO 122\n 120 BN(1) = BN(1)+AN(1)\n X = DR*AN(1)\n DO 121 I=1,M\n F(I,1) = F(I,1)+X*BDC(I)\n 121 CONTINUE\n 122 CONTINUE\n GO TO (123,125,125,123,123,125),NB\n 123 BN(N) = BN(N)-CN(N)\n X = 2.*CN(N)\n DO 124 I=1,M\n F(I,N) = F(I,N)-X*BDD(I)\n 124 CONTINUE\n GO TO 127\n 125 BN(N) = BN(N)+CN(N)\n X = DR*CN(N)\n DO 126 I=1,M\n F(I,N) = F(I,N)-X*BDD(I)\n 126 CONTINUE\n 127 CONTINUE\nC\nC CHECK FOR SINGULAR PROBLEM. IF SINGULAR, PERTURB F.\nC\n PERTRB = 0.\n GO TO (137,137,128,137,137,128,137,128,128),MBDCND\n 128 GO TO (137,137,129,137,137,129),NB\n 129 IF (ELMBDA) 137,131,130\n 130 IERR1 = 10\n GO TO 137\n 131 CONTINUE\n ISW = 2\n DO 133 I=1,M\n X = 0.\n DO 132 J=1,N\n X = X+F(I,J)\n 132 CONTINUE\n PERTRB = PERTRB+X*SNTH(I)\n 133 CONTINUE\n X = 0.\n DO 134 J=1,N\n X = X+RSQ(J)\n 134 CONTINUE\n PERTRB = 2.*(PERTRB*SIN(DTH/2.))/(X*(COS(A)-COS(B)))\n DO 136 J=1,N\n X = RSQ(J)*PERTRB\n DO 135 I=1,M\n F(I,J) = F(I,J)-X\n 135 CONTINUE\n 136 CONTINUE\n 137 CONTINUE\n A2 = 0.\n DO 138 I=1,M\n A2 = A2+F(I,1)\n 138 CONTINUE\n A2 = A2/RSQ(1)\nC\nC INITIALIZE BLKTRI\nC\n IF (INTL .NE. 0) GO TO 139\n CALL BLKTRI (0,1,N,AN,BN,CN,1,M,AM,BM,CM,IDIMF,F,IERR1,WRK)\n 139 CONTINUE\nC\nC CALL BLKTRI TO SOLVE SYSTEM OF EQUATIONS.\nC\n CALL BLKTRI (1,1,N,AN,BN,CN,1,M,AM,BM,CM,IDIMF,F,IERR1,WRK)\n IF (ISW.NE.2 .OR. C.NE.0. .OR. NBDCND.NE.2) GO TO 143\n A1 = 0.\n A3 = 0.\n DO 140 I=1,M\n A1 = A1+SNTH(I)*F(I,1)\n A3 = A3+SNTH(I)\n 140 CONTINUE\n A1 = A1+RSQ(1)*A2/2.\n IF (MBDCND .EQ. 3)\n 1 A1 = A1+(SIN(B)*BDB(1)-SIN(A)*BDA(1))/(2.*(B-A))\n A1 = A1/A3\n A1 = BDC(1)-A1\n DO 142 I=1,M\n DO 141 J=1,N\n F(I,J) = F(I,J)+A1\n 141 CONTINUE\n 142 CONTINUE\n 143 CONTINUE\n RETURN\nC\nC REVISION HISTORY---\nC\nC SEPTEMBER 1973 VERSION 1\nC APRIL 1976 VERSION 2\nC JANUARY 1978 VERSION 3\nC DECEMBER 1979 VERSION 3.1\nC FEBRUARY 1985 DOCUMENTATION UPGRADE\nC NOVEMBER 1988 VERSION 3.2, FORTRAN 77 CHANGES\nC-----------------------------------------------------------------------\n END\n", "meta": {"hexsha": "18c00560dceb154bc60fa4b34616b027f58f5088", "size": 27087, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/src/hstcsp.f", "max_stars_repo_name": "ipelupessy/omuse", "max_stars_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2020-03-25T10:02:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-18T00:28:35.000Z", "max_issues_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/src/hstcsp.f", "max_issues_repo_name": "ipelupessy/omuse", "max_issues_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 45, "max_issues_repo_issues_event_min_datetime": "2020-03-03T16:07:16.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-14T09:01:07.000Z", "max_forks_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/src/hstcsp.f", "max_forks_repo_name": "ipelupessy/omuse", "max_forks_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-03-03T13:28:50.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-26T09:20:02.000Z", "avg_line_length": 39.600877193, "max_line_length": 72, "alphanum_fraction": 0.4054343412, "num_tokens": 7768, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951643678382, "lm_q2_score": 0.7371581510799253, "lm_q1q2_score": 0.6887970117434186}} {"text": " SUBROUTINE uice(ug, vg, ui, vi, nlong, nlat)\nC Compute the motion of the non-interacting floes.\nC Bob Grumbine 17 September 1993.\nC U10 wind rule implemented 15 March 2007 \n\n IMPLICIT none\nCD INCLUDE \"sicedrft.inc\"\n\nC Declare the arguments\n INTEGER nlat, nlong\n REAL ug(nlong, nlat), vg(nlong, nlat)\n REAL ui(nlong, nlat), vi(nlong, nlat)\n\nC Declare local utility variables\n INTEGER i, j\n\nC Declare the flow model.\n REAL pi, betar\n REAL alpha1, beta1\n REAL alpha2, beta2\nC These are the geostrophic wind values, superceded 15 March 2007\nCOLD PARAMETER (alpha1 = 0.008)\nCOLD PARAMETER (beta1 = 8.0)\nCOLD PARAMETER (alpha2 = 0.0303)\nCOLD PARAMETER (beta2 = -23.4)\n PARAMETER (alpha1 = 0.01468)\n PARAMETER (beta1 = 28.0)\n PARAMETER (alpha2 = 0.01468)\n PARAMETER (beta2 = -28.0)\n\n PARAMETER (pi = 3.141592654)\n\nC Operational Code.\nC Compute the gridded ice drift velocity field. Note j convention is\nC reversed from MRF standard, and runs south to north.\nC Northern Hemisphere\n betar = pi*beta1/180.\n DO 2000 j = nlat/2+1, nlat\n DO 2010 i = 1, nlong\n ui(i,j) = alpha1*(COS(betar)*ug(i,j)+SIN(betar)*vg(i,j))\n vi(i,j) = alpha1*(-SIN(betar)*ug(i,j)+COS(betar)*vg(i,j))\n 2010 CONTINUE\n 2000 CONTINUE\nC Southern Hemisphere\n betar = pi*beta2/180.\n DO 2100 j = 2, nlat/2\n DO 2110 i = 1, nlong\n ui(i,j) = alpha2*(COS(betar)*ug(i,j)+SIN(betar)*vg(i,j))\n vi(i,j) = alpha2*(-SIN(betar)*ug(i,j)+COS(betar)*vg(i,j))\n 2110 CONTINUE\n 2100 CONTINUE\n\n PRINT *,'debug max, min u, v ',MAXVAL(ui), MINVAL(ui), \n 1 MAXVAL(vi), MINVAL(vi)\n\n RETURN\n END\n", "meta": {"hexsha": "a8fb35b5ffb05ae8f146879081f38fcb2b66030d", "size": 1784, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "sorc/seaice_sicedrft.fd/uice.f", "max_stars_repo_name": "NOAA-EMC/drift_grumbine", "max_stars_repo_head_hexsha": "50da0714ecf4495fbd89acb3fb381d36509b68a3", "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": "sorc/seaice_sicedrft.fd/uice.f", "max_issues_repo_name": "NOAA-EMC/drift_grumbine", "max_issues_repo_head_hexsha": "50da0714ecf4495fbd89acb3fb381d36509b68a3", "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": "sorc/seaice_sicedrft.fd/uice.f", "max_forks_repo_name": "NOAA-EMC/drift_grumbine", "max_forks_repo_head_hexsha": "50da0714ecf4495fbd89acb3fb381d36509b68a3", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.7586206897, "max_line_length": 72, "alphanum_fraction": 0.6020179372, "num_tokens": 619, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951625409307, "lm_q2_score": 0.7371581510799253, "lm_q1q2_score": 0.6887970103966987}} {"text": "C Copyright 2021 Dennis Decker Jensen\nC Date: 9 May 2021\nC Purpose: Find prime permutations\nC Tectonics: gfortran --std=f95 -ffixed-form -o euler049 euler049.f primetest.f\n\n PROGRAM EULER049\n DIMENSION IDIGITS(9)\n EXTERNAL PRIME,PERM\n LOGICAL PRIME,PERM\n NDIG(N,M)=MOD(INT(N/10**(M-1)),10)\n\n DO 20 I=1000,3339\n J=I+3330\n K=J+3330 \nC PRINT *,I,PRIME(I),J,PRIME(J),K,PRIME(K)\n IF (K.LE.9999 .AND. PRIME(I).AND.PRIME(J).AND.PRIME(K)) THEN\n DO 10 L=1,9\n 10 IDIGITS(L)=0\n DO 15 L=1,4\n IDIGITS(NDIG(I,L))=IDIGITS(NDIG(I,L))+1\n IDIGITS(NDIG(J,L))=IDIGITS(NDIG(J,L))+1\n 15 IDIGITS(NDIG(K,L))=IDIGITS(NDIG(K,L))+1\nC PRINT *,I,J,K,IDIGITS\n DO 16 L=1,9\n IF (MOD(IDIGITS(L),3).NE.0) GOTO 20\n 16 CONTINUE\n PRINT '(3I0,'': '',3(I0,1X))',I,J,K,I,J,K\n ENDIF\n 20 CONTINUE\n END\n", "meta": {"hexsha": "20f81d5c3315942b8ae7ca8598221b7bbcdb4d45", "size": 1030, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "euler/euler049.f", "max_stars_repo_name": "dennisdjensen/Sketchbook", "max_stars_repo_head_hexsha": "efb4c7df592ba4fe84e9cdcb0883c93823d04bf5", "max_stars_repo_licenses": ["0BSD"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-04-26T19:30:58.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-12T16:34:23.000Z", "max_issues_repo_path": "euler/euler049.f", "max_issues_repo_name": "dennisdjensen/sketchbook", "max_issues_repo_head_hexsha": "efb4c7df592ba4fe84e9cdcb0883c93823d04bf5", "max_issues_repo_licenses": ["0BSD"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "euler/euler049.f", "max_forks_repo_name": "dennisdjensen/sketchbook", "max_forks_repo_head_hexsha": "efb4c7df592ba4fe84e9cdcb0883c93823d04bf5", "max_forks_repo_licenses": ["0BSD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.2258064516, "max_line_length": 79, "alphanum_fraction": 0.4980582524, "num_tokens": 369, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391706552538, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6887155225312295}} {"text": "subroutine nbody_system_properties\n! Calculates the various properties of the system\n! Includes energy, angular momentum and orbits\n\nuse embryodata\n\nimplicit none\n\ncall angular_momentum\ncall energy\n\ntotalmass = sum(mass)\ncall calc_orbit_from_vector(totalmass)\n\nend subroutine nbody_system_properties\n\nsubroutine angular_momentum\n! Calculate the angular momentum of all the bodies\n\nuse embryodata\n\nimplicit none\n\ninteger :: ix\n\n! Compute angular momentum = r x v\n\nangmom(1,:) = pos(2,:)*vel(3,:) - pos(3,:)*vel(2,:)\nangmom(2,:) = pos(3,:)*vel(1,:) - pos(1,:)*vel(3,:)\nangmom(3,:) = pos(1,:)*vel(2,:) - pos(2,:)*vel(1,:)\nangmag(:) = sqrt(angmom(1,:)*angmom(1,:) + angmom(2,:)*angmom(2,:) + angmom(3,:)*angmom(3,:))\n\ndo ix=1,3\nsystem_angmom(ix) = sum(angmom(ix,:))\nenddo\n\nsystem_ang =sqrt(system_angmom(1)*system_angmom(1) + system_angmom(2)*system_angmom(2)+system_angmom(3)*system_angmom(3))\n\nif(initial_system_ang>1.0e-30)then\ndL = (system_ang-initial_system_ang)/initial_system_ang\nelse\ndL=0.0\nendif\n\nend subroutine angular_momentum\n\n\nsubroutine energy\n! Calculate the orbital parameters of all the bodies\n! Also compute energy and angular momentum for error tracking\n\nuse embryodata\n\nimplicit none\n\ninteger :: ix, ibody,jbody\nreal :: relpos\nreal,dimension(nbodies) :: vmag\nreal,dimension(3) :: sep\n\n! Compute kinetic energy of the bodies\n\nvmag(:) = sqrt(vel(1,:)*vel(1,:) + vel(2,:)*vel(2,:) + vel(3,:)*vel(3,:))\nekin(:) = 0.5*vmag(:)*vmag(:)\n\n! Compute potential energy\n\ndo ibody=1,nbodies\n\nepot(ibody)=0.0\n\ndo jbody=1,nbodies\n\nif(ibody==jbody) cycle\n\ndo ix=1,3\nsep(ix) = pos(ix,ibody) - pos(ix,jbody)\nenddo\n\nrelpos = sqrt(sep(1)*sep(1) + sep(2)*sep(2)+sep(3)*sep(3) +rsoft*rsoft)\n\ndo ix=1,3\nepot(ibody) = epot(ibody) - mass(jbody)/(relpos)\nenddo\nenddo\n\nenddo\n\netot(:) = ekin(:) + epot(:)\n\nsystem_energy = sum(etot)\n\nif(initial_system_energy >1.0e-30) then\ndE = (system_energy-initial_system_energy)/initial_system_energy\nelse\ndE = 0.0\nendif\n\nend subroutine energy\n\n\n\n\n\n", "meta": {"hexsha": "b23c87d755dfc743b319353d05d7fa289e234061", "size": 1973, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/nbody/nbody_system_properties.f90", "max_stars_repo_name": "dh4gan/grapus", "max_stars_repo_head_hexsha": "456707db38dd8920d319807f7f4f7297d6278b4a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/nbody/nbody_system_properties.f90", "max_issues_repo_name": "dh4gan/grapus", "max_issues_repo_head_hexsha": "456707db38dd8920d319807f7f4f7297d6278b4a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/nbody/nbody_system_properties.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": 18.7904761905, "max_line_length": 121, "alphanum_fraction": 0.7116066903, "num_tokens": 658, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391579526935, "lm_q2_score": 0.7461389986757758, "lm_q1q2_score": 0.688715513053354}} {"text": " program main\n double precision x1,y1,z1, x2,y2,z2,length\n write(6,*) 'input 1st point:'\n read(5,*) x1,y1,z1\n write(6,*) 'input 2nd point:'\n read(5,*) x2,y2,z2\n\n length=sqrt((x2-x1)**2+(y2-y1)**2+(z2-z1)**2)\n\n write(6,*) 'length between Point 1 and 2 = ',length\n stop \n end\n", "meta": {"hexsha": "56c218f7e569c3378d5c29a16916eff57ac8294e", "size": 324, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "77/get3dimdistance.f", "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": "77/get3dimdistance.f", "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": "77/get3dimdistance.f", "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": 24.9230769231, "max_line_length": 57, "alphanum_fraction": 0.5277777778, "num_tokens": 125, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381605, "lm_q2_score": 0.7461389873857264, "lm_q1q2_score": 0.6887155105304259}} {"text": "integer :: i\ninteger, dimension (10) :: a = (/(i * i, i = 1, 10)/)\n", "meta": {"hexsha": "0bb766576432bd3c8ebaf029eb4cbc6a9ab6c164", "size": 67, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Arrays/Fortran/arrays-17.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/Arrays/Fortran/arrays-17.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/Arrays/Fortran/arrays-17.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.3333333333, "max_line_length": 53, "alphanum_fraction": 0.4925373134, "num_tokens": 28, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772482857833, "lm_q2_score": 0.7879312031126512, "lm_q1q2_score": 0.6887127378552127}} {"text": "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!! !!\n!! This file is part of SciFT project !!\n!! Copyright (c) 2011-2019 Nestor F. Aguirre (nfaguirrec@gmail.com) !!\n!! !!\n!! Redistribution and use in source and binary forms, with or without !!\n!! modification, are permitted provided that the following conditions are met: !!\n!! !!\n!! 1. Redistributions of source code must retain the above copyright notice, this !!\n!! list of conditions and the following disclaimer. !!\n!! 2. Redistributions in binary form must reproduce the above copyright notice, !!\n!! this list of conditions and the following disclaimer in the documentation !!\n!! and/or other materials provided with the distribution. !!\n!! 3. Neither the name of the copyright holders nor the names of its contributors !!\n!! may be used to endorse or promote products derived from this software !!\n!! without specific prior written permission. !!\n!! !!\n!! The copyright holders provide no reassurances that the source code provided !!\n!! does not infringe any patent, copyright, or any other intellectual property !!\n!! rights of third parties. The copyright holders disclaim any liability to any !!\n!! recipient for claims brought against recipient by any third party for !!\n!! infringement of that parties intellectual property rights. !!\n!! !!\n!! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND !!\n!! ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED !!\n!! WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE !!\n!! DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR !!\n!! ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES !!\n!! (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; !!\n!! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND !!\n!! ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT !!\n!! (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS !!\n!! SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. !!\n!! !!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\nmodule Math_\n\tuse ieee_arithmetic ! http://fortranwiki.org/fortran/show/ieee_arithmetic\n\timplicit none\n\tprivate\n\t\n\treal(8), public, parameter :: Math_PI = acos(-1.0_8)\n\treal(8), public, parameter :: Math_INF = 1.0_8/0.0_8\n! \treal(8), public, parameter :: Math_INF = 99999999999999999.0_8\n\treal(8), public, parameter :: Math_NAN = 0.0_8/0.0_8\n\tcomplex(8), public, parameter :: Math_I = cmplx(0.0_8,1.0_8)\n\t\n\tinteger, public, parameter :: Math_IINF = huge(0)\n\t\n\tpublic :: &\n\t\tMath_wigner3j, &\n\t\tMath_cart2Spher, &\n\t\tMath_spher2Cart, &\n\t\tMath_sort, &\n\t\tMath_fact, &\n\t\tMath_comb, &\n\t\tMath_combinationsNumber, &\n\t\tMath_combinations, &\n\t\tMath_multisetNumber, &\n\t\tMath_multisets, &\n\t\tMath_isOdd, &\n\t\tMath_isEven, &\n\t\tMath_fixPrecision, &\n\t\tMath_erfinv, &\n\t\tMath_ustep, &\n\t\tMath_ubox, &\n\t\tMath_sinc, &\n\t\tMath_nsinc, &\n\t\tMath_gaussian, &\n\t\tMath_lorentzian, &\n\t\tMath_erfTophat, &\n\t\tMath_flatTopWindow, &\n\t\tMath_average, &\n\t\tMath_stdev, &\n\t\tMath_skewness, &\n\t\tMath_floorDivision, &\n\t\tMath_isNaN, &\n\t\tMath_isInf, &\n\t\tMath_isIInf, &\n\t\tMath_dotProduct, &\n\t\tMath_crossProduct, &\n\t\tMath_pointLineDistance, &\n\t\tMath_test\n\t\t\n\tinterface Math_sort\n\t\tmodule procedure Math_isort\n\t\tmodule procedure Math_rsort\n\tend interface Math_sort\n\t\n\tinterface Math_floorDivision\n\t\tmodule procedure Math_iFloorDivision\n\t\tmodule procedure Math_rFloorDivision\n\tend interface Math_floorDivision\n\t\n\tinterface\n\t\tfunction prototypeMultisetConstraint( multisetPositions, current ) result( output )\n\t\t\tinteger, allocatable, intent(in) :: multisetPositions(:)\n\t\t\tinteger, intent(in) :: current\n\t\t\tlogical :: output\n\t\tend function prototypeMultisetConstraint\n\tend interface\n\t\n\tinteger, allocatable :: kCombChosen(:)\n\tinteger(8) :: kCombIterator = -1\n\t\n\tinteger, allocatable :: kMultiCombChosen(:)\n\tinteger(8) :: kMultiCombIterator = -1\n\t\n\tinteger, allocatable :: ids(:)\n\tprocedure(prototypeMultisetConstraint), pointer, private :: MSConstraint !<- This is neccesary only for Math_multisets\n\tlogical :: isMultisetLocated = .false.\n\t\n\tinteger, allocatable :: MyiArray(:) !<- This is only neccesary for test method\n\t\n\treal(8), private :: erfinv_a3 = -0.140543331_8\n\treal(8), private :: erfinv_a2 = 0.914624893_8\n\treal(8), private :: erfinv_a1 = -1.645349621_8\n\treal(8), private :: erfinv_a0 = 0.886226899_8\n\n\treal(8), private :: erfinv_b4 = 0.012229801_8\n\treal(8), private :: erfinv_b3 = -0.329097515_8\n\treal(8), private :: erfinv_b2 = 1.442710462_8\n\treal(8), private :: erfinv_b1 = -2.118377725_8\n\treal(8), private :: erfinv_b0 = 1.0_8\n\n\treal(8), private :: erfinv_c3 = 1.641345311_8\n\treal(8), private :: erfinv_c2 = 3.429567803_8\n\treal(8), private :: erfinv_c1 = -1.62490649_8\n\treal(8), private :: erfinv_c0 = -1.970840454_8\n\n\treal(8), private :: erfinv_d2 = 1.637067800_8\n\treal(8), private :: erfinv_d1 = 3.543889200_8\n\treal(8), private :: erfinv_d0 = 1.0_8\n\t\n\tcontains\n\t\n\t!>\n\t!! This function calculates the value of a Wigner-3j symbol.\n\t!! The equation used is equation 1.5 in \"The 3j and 6j symbols\" by\n\t!! Manuel Rotenber, R. Bivins, N.Metropolis and John K. Wooten, JR\n\t!! 1959, The Technology Press, Massachusett.\n\t!!\n\t!! The function has been tested for all sets, where j1d=j2d=5/2\n\t!! and j3d={0, 2, 4}, and m1d+m2d+m3d=0\n\t!! It has been tested to give zero for some vanishing terms\n\t!! If you should want to use it for higher js than the ones I have tested\n\t!! you might have to do something to avoid overflow in the expression with\n\t!! the many factorials\n\t!!\n\tfunction Math_wigner3j( j1, j2, j3, m1, m2, m3 ) result (w3j)\n\t\treal(8), intent(in) :: j1,j2,j3,m1,m2,m3\n\t\treal(8) :: w3j\n\t\t\n\t\tinteger:: i\n\t\treal(8) :: j1d,j2d,j3d,m1d,m2d,m3d\n\t\treal(8) :: k,kmin,kmax,ksum,divisor,sign\n\t\treal(8), dimension(0:200) ::lnfac\n\t\t\n\t\tj1d = real(j1,8)\n\t\tj2d = real(j2,8)\n\t\tj3d = real(j3,8)\n\t\tm1d = real(m1,8)\n\t\tm2d = real(m2,8)\n\t\tm3d = real(m3,8)\n\t\t\n\t\tlnfac(0)=0.d0\n\t\tlnfac(1)=0.d0\n\t\tdo i=2,200\n\t\t\tlnfac(i)=lnfac(i-1)+log(REAL(i))\n\t\tend do\n\t\t\n\t\tkmax = min(j1d+j2d-j3d, j1d-m1d,j2d+m2d)\n\t\tkmin = max(0.d0, j2d-j3d-m1d, j1d-j3d+m2d)\n\t\t\n\t\tksum=0.\n\t\tdo k = kmin, kmax\n\t\t\tdivisor=exp(lnfac(nint(k))+lnfac(nint(j1d+j2d-j3d-k))+ &\n\t\t\t\tlnfac(nint(j1d-m1d-k))+lnfac(nint(j2d+m2d-k))+ &\n\t\t\t\tlnfac(nint(j3d-j2d+m1d+k))+lnfac(nint(j3d-j1d-m2d+k)))\n\t\t\tksum=ksum+minusonetothe(int(k))/divisor\n\t\tend do !k\n\t\t\n\t\tw3j= minusonetothe(nint(j1d-j2d-m3d))*sqrt( &\n\t\t\t\texp(lnfac(nint(j1d+j2d-j3d))+lnfac(nint(j1d-j2d+j3d))+&\n\t\t\t\tlnfac(nint(-j1d+j2d+j3d))+&\n\t\t\t\tlnfac(nint(j1d+m1d))+lnfac(nint(j1d-m1d))+&\n\t\t\t\tlnfac(nint(j2d+m2d))+lnfac(nint(j2d-m2d))+&\n\t\t\t\tlnfac(nint(j3d+m3d))+lnfac(nint(j3d-m3d))-&\n\t\t\t\tlnfac(nint(j1d+j2d+j3d+1))))*ksum\n\tend function Math_wigner3j\n\t\n\t!>\n\t!! @brief Converts cartesian coordinates to spherical coordinates\n\t!! @param vec = [ x, y, z ]\n\t!! @return rvec = [ r, theta, phi ]\n\t!!\n\tfunction Math_cart2Spher( vec ) result( rvec )\n\t\treal(8), intent(in) :: vec(3)\n\t\treal(8) :: rvec(3)\n\t\t\n\t\treal(8) :: r\n\t\t\n\t\tr = sqrt(sum(vec**2))\n\t\trvec = [ r, acos(vec(3)/r), atan2(vec(2),vec(1)) ]\n\tend function Math_cart2Spher\n\t\n\t!>\n\t!! @brief Converts spherical coordinates to cartesian coordinates\n\t!! @param rvec = [ r, theta, phi ]\n\t!! @return vec = [ x, y, z ]\n\t!!\n\tfunction Math_spher2Cart( rvec ) result( vec )\n\t\treal(8), intent(in) :: rvec(3)\n\t\treal(8) :: vec(3)\n\t\t\n\t\tvec = [ rvec(1)*sin(rvec(2))*cos(rvec(3)), rvec(1)*sin(rvec(2))*sin(rvec(3)), rvec(1)*cos(rvec(2)) ]\n\tend function Math_spher2Cart\n\t\n\t!>\n\t!! @brief\n\t!!\n\tfunction minusonetothe(j) result (sgn)\n\t\tinteger :: i,j\n\t\treal*8 :: sgn\n\t\t\n\t\ti=j\n\t\tif (j<=0) i=-j\n\t\tif (mod(i,2)==0) then\n\t\t\tsgn=1\n\t\telse\n\t\t\tsgn=-1\n\t\tendif\n\tend function minusonetothe\n\t\n\t!>\n\t!! indexing array so that array(indexes(j)), j=1..n is in\n\t!! ascending numerical order.\n\t!! method is heapsort, see also subroutine hpsort.\n\t!! taken from numerical recipies, p 233.\n\t!!\n\tsubroutine Math_isort( array, indexes )\n\t\tinteger, allocatable, intent(in) :: array(:)\n\t\tinteger, allocatable, intent(inout) :: indexes(:)\n\t\t\n\t\tinteger :: i, j, l\n\t\tinteger :: n\n\t\tinteger :: id, ir\n\t\treal(8) :: value\n\t\t\n\t\tif( .not. allocated(array) ) then\n\t\t\twrite(*,*) \"Error in Math_sort, array not allocated\"\n\t\t\tstop\n\t\tend if\n\t\t\n\t\tif( .not. allocated(indexes) ) then\n\t\t\twrite(*,*) \"Error in Math_sort, indexes not allocated\"\n\t\t\tstop\n\t\tend if\n\t\t\n\t\tif( size(array) /= size(indexes) ) then\n\t\t\twrite(*,*) \"Error in Math_sort, array and indexes have different size\"\n\t\t\tstop\n\t\tend if\n\t\t\n\t\tn = size(array)\n\t\t\n\t\tdo j=1,n\n\t\t\tindexes(j)=j\n\t\tend do\n\t\t\n\t\tif( n == 1 ) return\n\t\t\n\t\tl=n/2+1\n\t\tir=n\n\t\t\n\t\tdo while( .true. )\n\t\t\tif( l > 1 ) then\n\t\t\t\tl = l-1\n\t\t\t\tid = indexes(l)\n\t\t\t\tvalue = array(id)\n\t\t\telse\n\t\t\t\tid=indexes(ir)\n\t\t\t\tvalue=array(id)\n\t\t\t\tindexes(ir)=indexes(1)\n\t\t\t\tir=ir-1\n\t\t\t\t\n\t\t\t\tif(ir == 1) then\n\t\t\t\t\tindexes(1)=id\n\t\t\t\t\treturn\n\t\t\t\tend if\n\t\t\tend if\n\t\t\t\n\t\t\ti = l\n\t\t\tj = 2*l\n\t\t\t\n\t\t\tdo while( j <= ir )\n\t\t\t\tif( j < ir ) then\n\t\t\t\t\tif( array(indexes(j)) < array(indexes(j+1)) ) then\n\t\t\t\t\t\tj=j+1\n\t\t\t\t\tend if\n\t\t\t\tend if\n\t\t\t\t\n\t\t\t\tif( value < array(indexes(j)) ) then\n\t\t\t\t\tindexes(i)=indexes(j)\n\t\t\t\t\ti=j\n\t\t\t\t\tj=2*j\n\t\t\t\telse\n\t\t\t\t\tj=ir+1\n\t\t\t\tend if\n\t\t\tend do\n\t\t\t\n\t\t\tindexes(i)=id\n\t\tend do\n\tend subroutine Math_isort\n\t\n\t!>\n\t!! indexing array so that array(indexes(j)), j=1..n is in\n\t!! ascending numerical order.\n\t!! method is heapsort, see also subroutine hpsort.\n\t!! taken from numerical recipies, p 233.\n\t!!\n\tsubroutine Math_rsort( array, indexes )\n\t\treal(8), allocatable, intent(in) :: array(:)\n\t\tinteger, allocatable, intent(inout) :: indexes(:)\n\t\t\n\t\tinteger :: i, j, l\n\t\tinteger :: n\n\t\tinteger :: id, ir\n\t\treal(8) :: value\n\t\t\n\t\tif( .not. allocated(array) ) then\n\t\t\twrite(*,*) \"Error in Math_sort, array not allocated\"\n\t\t\tstop\n\t\tend if\n\t\t\n\t\tif( .not. allocated(indexes) ) then\n\t\t\twrite(*,*) \"Error in Math_sort, indexes not allocated\"\n\t\t\tstop\n\t\tend if\n\t\t\n\t\tif( size(array) /= size(indexes) ) then\n\t\t\twrite(*,*) \"Error in Math_sort, array and indexes have different size\"\n\t\t\tstop\n\t\tend if\n\t\t\n\t\tn = size(array)\n\t\t\n\t\tdo j=1,n\n\t\t\tindexes(j)=j\n\t\tend do\n\t\t\n\t\tif( n == 1 ) return\n\t\t\n\t\tl=n/2+1\n\t\tir=n\n\t\t\n\t\tdo while( .true. )\n\t\t\tif( l > 1 ) then\n\t\t\t\tl = l-1\n\t\t\t\tid = indexes(l)\n\t\t\t\tvalue = array(id)\n\t\t\telse\n\t\t\t\tid=indexes(ir)\n\t\t\t\tvalue=array(id)\n\t\t\t\tindexes(ir)=indexes(1)\n\t\t\t\tir=ir-1\n\t\t\t\t\n\t\t\t\tif(ir == 1) then\n\t\t\t\t\tindexes(1)=id\n\t\t\t\t\treturn\n\t\t\t\tend if\n\t\t\tend if\n\t\t\t\n\t\t\ti = l\n\t\t\tj = 2*l\n\t\t\t\n\t\t\tdo while( j <= ir )\n\t\t\t\tif( j < ir ) then\n\t\t\t\t\tif( array(indexes(j)) < array(indexes(j+1)) ) then\n\t\t\t\t\t\tj=j+1\n\t\t\t\t\tend if\n\t\t\t\tend if\n\t\t\t\t\n\t\t\t\tif( value < array(indexes(j)) ) then\n\t\t\t\t\tindexes(i)=indexes(j)\n\t\t\t\t\ti=j\n\t\t\t\t\tj=2*j\n\t\t\t\telse\n\t\t\t\t\tj=ir+1\n\t\t\t\tend if\n\t\t\tend do\n\t\t\t\n\t\t\tindexes(i)=id\n\t\tend do\n\tend subroutine Math_rsort\n\t\n\t!>\n\t!! @brief Returns the factorial of n\n\t!! \n\tpure function Math_fact( n ) result( output )\n\t\tinteger, intent(in) :: n\n\t\tinteger :: output\n\t\t\n\t\tinteger :: i\n\t\t\n\t\toutput = 1\n\t\tdo i=n,1,-1\n\t\t\toutput = output*i\n\t\tend do\n\tend function Math_fact\n\t\n\t!>\n\t!!\n\t!! taken from http://orion.math.iastate.edu/burkardt/f_src/combo/combo.html\n\t!! COMB computes the combinatorial coefficient C(N,K).\n\t!!\n\t!! Real arithmetic is used, and C(N,K) is computed directly, via\n\t!! Gamma functions, rather than recursively.\n\t!!\n\t!! C(N,K) is the number of distinct combinations of K objects\n\t!! chosen from a set of N distinct objects. A combination is\n\t!! like a set, in that order does not matter.\n\t!!\n\t!! Examples:\n\t!! The number of combinations of 2 things chosen from 5 is 10.\n\t!!\n\t!! C(5,2) = ( 5 * 4 * 3 * 2 * 1 ) / ( ( 3 * 2 * 1 ) * ( 2 * 1 ) ) = 10.\n\t!!\n\t!! The actual combinations may be represented as:\n\t!!\n\t!! (1,2), (1,3), (1,4), (1,5), (2,3),\n\t!! (2,4), (2,5), (3,4), (3,5), (4,5).\n\t!!\n\t!! Formula:\n\t!! C(N,K) = N! / ( (N-K)! * K! )\n\t!!\n\t!! Modified:\n\t!! 16 June 1999\n\t!!\n\t!! Author:\n\t!! John Burkardt\n\t!!\n\t!! @param[in] n integer N, the value of N.\n\t!! @param[in] m integer K, the value of K.\n\t!! @output output real CNK, the value of C(N,K)\n\t!!\n\tpure function Math_comb( n, k ) result( output )\n\t\tinteger, intent(in) :: n, k\n\t\tinteger(8) :: output\n\t\t\n\t\treal(8) :: arg\n\t\treal(8) :: cnk\n\t\treal(8) :: fack\n\t\treal(8) :: facn\n\t\treal(8) :: facnmk\n\t\t\n\t\tif ( n < 0 ) then\n\t\t\tcnk = 0.0E+00\n\t\telse if ( k == 0 ) then\n\t\t\tcnk = 1.0E+00\n\t\telse if ( k == 1 ) then\n\t\t\tcnk = real( n )\n\t\telse if ( k > 1 .and. k < n-1 ) then\n\t\t\targ = real( n + 1 )\n\t\t\tfacn = log(gamma( arg ))\n\t\t\t\n\t\t\targ = real( k + 1 )\n\t\t\tfack = log(gamma( arg ))\n\t\t\t\n\t\t\targ = real( n - k + 1 )\n\t\t\tfacnmk = log(gamma( arg ))\n\t\t\t\n\t\t\tcnk = anint( exp ( facn - fack - facnmk ) )\n\t\telse if ( k == n-1 ) then\n\t\t\tcnk = real( n )\n\t\telse if ( k == n ) then\n\t\t\tcnk = 1.0E+00\n\t\telse\n\t\t\tcnk = 0.0E+00\n\t\tend if\n\t\t\n\t\toutput = int(cnk,8)\n\tend function Math_comb\n\t\n\t!>\n\t!! @brief Number of combinations with repetitions (same that Math_comb)\n\t!!\n\tfunction Math_combinationsNumber( nElems, sGroups ) result ( output )\n\t\tinteger, intent(in) :: nElems\n\t\tinteger, intent(in) :: sGroups\n\t\tinteger(8) :: output\n\t\t\n\t\toutput = Math_comb( nElems, sGroups )\n\tend function Math_combinationsNumber\n\t\n\t!>\n\t!! @brief Builds the combinations without repetitions\n\t!!\n\t!! @param[in] nElems Number of elements\n\t!! @param[in] sGroups size of the groups\n\t!! @param[out] items final groups\n\t!!\n\t!! example: if S={1,2,3,4,5} then the combination of these elements in groups of three elements are\n\t!! 1) 1 2 3\n\t!! 2) 1 2 4\n\t!! 3) 1 2 5\n\t!! 4) 1 3 4\n\t!! 5) 1 3 5\n\t!! 6) 1 4 5\n\t!! 7) 2 3 4\n\t!! 8) 2 3 5\n\t!! 9) 2 4 5\n\t!! 10) 3 4 5\n\tsubroutine Math_combinations( nElems, sGroups, items )\n\t\tinteger, intent(in) :: nElems\n\t\tinteger, intent(in) :: sGroups\n\t\tinteger, allocatable, intent(inout) :: items(:,:)\n\t\t\n\t\tif( allocated(items) ) deallocate( items )\n\t\tallocate( items( Math_comb(nElems,sGroups), sGroups ) )\n\t\t\n\t\tallocate( kCombChosen(sGroups) )\n\t\t\n\t\tkCombIterator=1\n\t\tcall combinationsBase( nElems, sGroups, items, 1 )\n\t\tkCombIterator=-1\n\t\t\n\t\tdeallocate( kCombChosen )\n\tend subroutine Math_combinations\n\t\n\t!>\n\t!! @brief Internal function\n\t!!\n\trecursive subroutine combinationsBase( nElems, sGroups, items, m )\n\t\tinteger, intent (in) :: nElems, sGroups\n\t\tinteger, allocatable, intent(inout) :: items(:,:)\n\t\tinteger, intent (in) :: m\n\t\tinteger :: n\n\t\t\n\t\tif( m > sGroups ) then\n\t\t\titems(kCombIterator,:) = kCombChosen\n\t\t\tkCombIterator = kCombIterator+1\n\t\telse\n\t\t\tdo n=1, nElems\n\t\t\t\tif( (m == 1) .or. (n > kCombChosen(m - 1)) ) then\n\t\t\t\t\tkCombChosen( m ) = n\n\t\t\t\t\tcall combinationsBase( nElems, sGroups, items, m + 1 )\n\t\t\t\tend if\n\t\t\tend do\n\t\tend if\n\tend subroutine combinationsBase\n\t\n\t!>\n\t!! @brief Number of combinations with repetitions\n\t!!\n\t!! The number of ways to sample sGroups elements from a set of nElems elements allowing for duplicates\n\t!!\n\tfunction Math_multisetNumber( nElems, sGroups ) result ( output )\n\t\tinteger, intent(in) :: nElems\n\t\tinteger, intent(in) :: sGroups\n\t\tinteger(8) :: output\n\t\t\n\t\toutput = Math_comb( nElems+sGroups-1, sGroups )\n\tend function Math_multisetNumber\n\t\n\t!>\n\t!! @brief Builds the combinations with repetitions\n\t!!\n\t!! A sGroups-combination with repetitions, or sGroups-multicombination, or multiset of size sGroups\n\t!! from a set S is given by a sequence of sGroups not necessarily distinct elements of S,\n\t!! where order is not taken into account.\n\t!!\n\t!! @param[in] nElems Number of elements\n\t!! @param[in] sGroups size of the groups\n\t!! @param[out] items final groups\n\t!!\n\t!! example: if S={a,b,c} then the combination of these elements in groups of two elements are\n\t!! 1) aa\n\t!! 2) ab\n\t!! 3) ac\n\t!! 4) bb\n\t!! 5) bc\n\t!! 6) cc\n\trecursive subroutine Math_multisets( nElems, sGroups, items, constrainFunction )\n\t\tinteger, intent(in) :: nElems\n\t\tinteger, intent(in) :: sGroups\n\t\tinteger, allocatable, intent(inout) :: items(:,:)\n\t\tprocedure(prototypeMultisetConstraint), optional :: constrainFunction\n\t\t\n\t\tinteger, allocatable :: itemsBase(:,:)\n\t\tinteger :: i\n\t\t\n\t\tif( allocated(kMultiCombChosen) ) deallocate( kMultiCombChosen )\n\t\t\n\t\tkMultiCombIterator = 1\n\t\t\n\t\tallocate( kMultiCombChosen(sGroups) )\n\t\tkMultiCombChosen = 0\n\t\t\n\t\tif( allocated(itemsBase) ) deallocate( itemsBase )\n\t\tallocate( itemsBase( Math_multisetNumber( nElems, sGroups ), sGroups ) )\n\t\titemsBase = 0\n\t\tMSConstraint => constrainFunction\n\t\t\n\t\tcall multisetsBase( nElems, sGroups, itemsBase )\n\t\t\n\t\tif( kMultiCombIterator-1 < 1 ) then\n\t\t\twrite(6,\"(A)\") \"### ERROR ### Math_multisets: There is not multisets with chosen constraint\"\n\t\t\twrite(6,\"(A)\") \" Don't forget that the constraint don't must be dependent of order of elements\"\n\t\t\tstop\n\t\tend if\n\t\t\n\t\tif( allocated(items) ) deallocate(items)\n\t\tallocate( items(kMultiCombIterator-1,sGroups) )\n\t\t\n\t\tdo i=1,size(items,dim=1)\n\t\t\titems(i,:) = itemsBase(i,:)\n\t\tend do\n\t\t\n\t\tdeallocate(itemsBase)\n\t\tMSConstraint => null()\n\t\tkMultiCombIterator = -1\n\t\tdeallocate( kMultiCombChosen )\n\tend subroutine Math_multisets\n\t\n\t!>\n\t!! @brief Internal function\n\t!!\n\trecursive subroutine multisetsBase( nElems, sGroups, items, nChosen, at )\n\t\tinteger, intent(in) :: nElems\n\t\tinteger, intent(in) :: sGroups\n\t\tinteger, allocatable, intent(inout) :: items(:,:)\n\t\tinteger, optional, intent(in) :: nChosen\n\t\tinteger, optional, intent(in) :: at\n\t\t\n\t\tinteger :: effNChosen\n\t\tinteger :: effAt\n\t\t\n\t\tlogical :: isMultisetOK, isBadWay\n\t\tinteger :: i\n\t\tinteger :: counter\n\t\t\n\t\teffNChosen = 1\n\t\tif( present(nChosen) ) effNChosen = nChosen\n\t\t\n\t\teffAt = 1\n\t\tif( present(at) ) effAt = at\n\t\t\n\t\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t\t! When this point is reached, the current combination\n\t\t! is the kMultiCombChosen vector\n\t\tif ( effNChosen == sGroups+1 ) then\n\t\t\tif( associated(MSConstraint) ) then\n\t\t\t\tisMultisetOK = MSConstraint( kMultiCombChosen, effNChosen-1 )\n\t\t\telse\n\t\t\t\tisMultisetOK = .true.\n\t\t\tend if\n\t\t\t\n\t\t\tif( isMultisetOK ) then\n\t\t\t\titems( kMultiCombIterator, : ) = kMultiCombChosen(:)\n\t\t\t\tkMultiCombIterator = kMultiCombIterator + 1\n\t\t\tend if\n\t\t\t\n\t\t\treturn\n\t\telse if( effNChosen > 1 ) then\n\t\t\tif( associated(MSConstraint) ) then\n\t\t\t\tisBadWay = MSConstraint( kMultiCombChosen, effNChosen-1 )\n\t\t\telse\n\t\t\t\tisBadWay = .false.\n\t\t\tend if\n\t\t\t\n\t\t\tif( isBadWay ) return\n\t\tend if\n\n\t\t\n\t\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t\t! Build all possibilities for each element in the item array\n\t\tdo i=effAt,nElems\n\t\t\tkMultiCombChosen(effNChosen) = i\n\t\t\t\n\t\t\tcall multisetsBase( nElems, sGroups, items, effNChosen+1, i )\n\t\tend do\n\t\t\n\t\treturn\n\tend subroutine multisetsBase\n\t\n\t!>\n\t!! @brief\n\t!!\n\tfunction Math_isOdd( n ) result( output )\n\t\tinteger, intent(in) :: n\n\t\tlogical :: output\n\t\t\n\t\toutput = ( mod(n,2)>0 )\n\tend function Math_isOdd\n\t\n\t!>\n\t!! @brief\n\t!!\n\tfunction Math_isEven( n ) result( output )\n\t\tinteger, intent(in) :: n\n\t\tlogical :: output\n\t\t\n\t\toutput = ( mod(n,2) == 0 )\n\tend function Math_isEven\n\t\n\t!>\n\t!! @brief\n\t!!\n\tfunction Math_fixPrecision( x, prec ) result( output )\n\t\treal(8), intent(in) :: x\n\t\tinteger, intent(in) :: prec\n\t\treal(8) :: output\n\t\t\n\t\toutput = real(ceiling(x*10**prec),8)/10**prec\n\tend function Math_fixPrecision\n\t\n\t!>\n\t!! @brief\n\t!! @todo La secci\u00f3n comentada puede hacer falta\n\t!! Tomada de https://www.google.es/search?q=error+%237768%3A+This+operation+on+this+data+type+is+currently+inaccurate.&oq=error+%237768%3A+This+operation+on+this+data+type+is+currently+inaccurate.&aqs=chrome..69i57.363j0j4&client=ubuntu-browser&sourceid=chrome&es_sm=91&ie=UTF-8\n\t!!\n\tfunction Math_erfinv( x_in ) result( r )\n\t\treal(8), intent(in) :: x_in\n\t\treal(8) :: r\n\t\t\n\t\treal(8) :: x, x2, y\n\t\tinteger :: sign_x\n\t\t\n\t\tx = x_in\n\n\t\tif( x < -1.0_8 .or. x > 1_8 ) then\n! \t\t\tr = Math_NAN\n\t\t\tr = sqrt(-1.0_8)\n\t\t\treturn\n\t\tend if\n\t\t\n\t\tif( x == 0.0_8 ) then\n\t\t\tr = 0.0_8\n\t\t\treturn\n\t\tend if\n\t\t\n\t\tif( x > 0.0_8 ) then\n\t\t\tsign_x = 1\n\t\telse\n\t\t\tsign_x = -1\n\t\t\tx = -x\n\t\tend if\n\n\t\tif( x <= 0.7_8 ) then\n\t\t\tx2 = x*x\n\t\t\tr = x*(((erfinv_a3 * x2 + erfinv_a2) * x2 + erfinv_a1) * x2 + erfinv_a0)\n! \t\t\tr = r/(((erfinv_b4 * x2 + erfinv_b3) * x2 + erfinv_b2) * x2 + erfinv_b1)*x2 + erfinv_b0\n\t\telse\n\t\t\ty = sqrt (-log ((1.0_8 - x) /2.0_8))\n\t\t\tr = (((erfinv_c3 * y + erfinv_c2) * y + erfinv_c1) * y + erfinv_c0)\n\t\t\tr = r/((erfinv_d2 * y + erfinv_d1) * y + erfinv_d0)\n\t\tend if\n\t\t\n\t\tr = r * sign_x\n\t\tx = x * sign_x\n\t\t\n\t\tr = r - (erf(r) - x) / (2.0_8/sqrt(Math_PI)*exp(-r*r))\n\t\tr = r - (erf(r) - x) / (2.0_8/sqrt(Math_PI)*exp(-r*r))\n\tend function Math_erfinv\n\t\n\t!>\n\t!! @brief\n\t!!\n\tpure function Math_ustep( x ) result( output )\n\t\treal(8), intent(in) :: x\n\t\treal(8) :: output\n\t\t\n\t\toutput = 0.5_8*( 1.0_8 + tanh( 1.0d12*x ) )\n\tend function Math_ustep\n\t\n\t!>\n\t!! @brief\n\t!!\n\tpure function Math_ubox( x ) result( output )\n\t\treal(8), intent(in) :: x\n\t\treal(8) :: output\n\t\t\n\t\toutput = Math_ustep( x+0.5_8 ) - Math_ustep( x-0.5_8 )\n\tend function Math_ubox\n\t\n\t!>\n\t!! @brief Unnormalized sinc function\n\t!!\n\tpure function Math_sinc( x ) result( output )\n\t\treal(8), intent(in) :: x\n\t\treal(8) :: output\n\t\t\n\t\toutput = sin(x)/x\n\tend function Math_sinc\n\t\n\t!>\n\t!! @brief Normalized sinc function\n\t!!\n\tpure function Math_nsinc( x ) result( output )\n\t\treal(8), intent(in) :: x\n\t\treal(8) :: output\n\t\t\n\t\toutput = sin(Math_PI*x)/Math_PI/x\n\tend function Math_nsinc\n\t\n\t!>\n\t!! @brief Gaussian function\n\t!!\n\tpure function Math_gaussian( x, x0, I0, FWHM ) result( output )\n\t\treal(8), intent(in) :: x, x0, I0, FWHM\n\t\treal(8) :: output\n\t\t\n\t\treal(8) :: width\n\t\t\n\t\twidth = FWHM/2.35482_8\n\t\toutput = I0*exp( -(x-x0)**2/2.0_8/width**2 )\n\tend function Math_gaussian\n\t\n\t!>\n\t!! @brief Gaussian lorentzian\n\t!!\n\tpure function Math_lorentzian( x, x0, I0, FWHM ) result( output )\n\t\treal(8), intent(in) :: x, x0, I0, FWHM\n\t\treal(8) :: output\n\t\t\n\t\treal(8) :: width\n\t\t\n\t\twidth = 0.5_8*FWHM\n\t\toutput = I0/( 1.0_8+((x-x0)/width)**2 )\n\tend function Math_lorentzian\n\t\n\t!>\n\t!! @brief\n\t!! @input t Independent variable (time)\n\t!! @input t0 Position of its center\n\t!! @input w tophat width of the pulse\n\t!! @input w turn-on/turn-off time\n\t!!\n\tfunction Math_erfTophat( t, t0, w, dw ) result( output )\n\t\treal(8) :: t\n\t\treal(8) :: t0\n\t\treal(8) :: w\n\t\treal(8) :: dw\n\t\treal(8) :: output\n\t\t\n\t\toutput = 0.0_8\n\t\tif ( t>t0-w/2-dw .and. t<=t0-w/2 ) then\n\t\t\toutput = 0.5*erf( 4.0*(t-(t0-w/2-dw/2))/dw )+0.5\n\t\telse if ( t>t0-w/2 .and. t<=t0+w/2 ) then\n\t\t\toutput = 1.0\n\t\telse if ( t>t0+w/2 .and. t\n\t!! @brief\n\t!! @input t Independent variable (time)\n\t!! @input t0 Position of its center\n\t!! @input w width of the window\n\t!!\n\tfunction Math_flatTopWindow( t, t0, w ) result( output )\n\t\treal(8) :: t\n\t\treal(8) :: t0\n\t\treal(8) :: w\n\t\treal(8) :: output\n\t\t\n\t\toutput = 0.0_8\n\t\tif ( t>=t0-w/2 .and. t<=t0+w/2 ) then\n\t\t\toutput = 1d-9*( 215578947.0 + 416631580.0*cos(2.0*Math_PI*(t-t0)/w) + 277263158.0*cos(4.0*Math_PI*(t-t0)/w)\\\n\t\t\t\t\t+83578947.0*cos(6.0*Math_PI*(t-t0)/w) + 6947368.0*cos(8.0*Math_PI*(t-t0)/w) )\n\t\tend if\n\tend function Math_flatTopWindow\n\t\n\t!>\n\t!! @brief\n\t!!\n\tfunction Math_average( array ) result( output )\n\t\treal(8), allocatable, intent(in) :: array(:)\n\t\treal(8) :: output\n\t\t\n\t\tinteger :: i\n\t\treal(8) :: ssum\n\t\t\n\t\tssum = 0.0_8\n\t\tdo i=1,size(array)\n\t\t\tssum = ssum + array(i)\n\t\tend do\n\t\t\n\t\toutput = ssum/real(size(array),8)\n\tend function Math_average\n\t\n\t!>\n\t!! @brief\n\t!!\n\tfunction Math_stdev( array, aver ) result( output )\n\t\treal(8), allocatable, intent(in) :: array(:)\n\t\treal(8), optional, intent(in) :: aver\n\t\treal(8) :: output\n\t\t\n\t\treal(8) :: effAver\n\t\t\n\t\tinteger :: i\n\t\treal(8) :: ssum\n\t\t\n\t\tif( present(aver) ) then\n\t\t\teffAver = aver\n\t\telse\n\t\t\teffAver = Math_average( array )\n\t\tend if\n\t\t\n\t\tssum = 0.0_8\n\t\tdo i=1,size(array)\n\t\t\tssum = ssum + ( array(i) - effAver )**2\n\t\tend do\n\t\t\n\t\toutput = sqrt( ssum/real(size(array),8) )\n\tend function Math_stdev\n\t\n\t!>\n\t!! @brief\n\t!!\n\tfunction Math_skewness( array ) result( output )\n\t\treal(8), allocatable, intent(in) :: array(:)\n\t\treal(8) :: output\n\t\t\n\t\tinteger :: i\n\t\treal(8) :: aver, stdev, ssum\n\t\t\n\t\taver = Math_average( array )\n\t\tstdev = Math_stdev( array, aver )\n\t\t\n\t\tssum = 0.0_8\n\t\tdo i=1,size(array)\n\t\t\tssum = ssum + ( array(i) - aver )**3\n\t\tend do\n\t\t\n\t\toutput = ssum/real(size(array),8)/stdev**3\n\t\t\n\t\t! Esto ocurre si stdev es cero, entonces es una delta de Dirac\n\t\t! y por lo tanto simetrica, por eso he puesto output=0\n\t\tif( Math_isNaN(output) ) output = 0.0_8\n\tend function Math_skewness\n\t\n\t!>\n\t!! @brief\n\t!!\n\tpure function Math_rFloorDivision( x, y ) result( output )\n\t\treal(8), intent(in) :: x\n\t\treal(8), intent(in) :: y\n\t\treal(8) :: output\n\t\t\n\t\toutput = floor( x/y )\n\tend function Math_rFloorDivision\n\t\n\t!>\n\t!! @brief\n\t!!\n\tpure function Math_iFloorDivision( x, y ) result( output )\n\t\tinteger, intent(in) :: x\n\t\tinteger, intent(in) :: y\n\t\treal(8) :: output\n\t\t\n\t\toutput = floor( real(x,8)/real(y,8) )\n\tend function Math_iFloorDivision\n\t\n\t!>\n\t!! This is only necessary for Math_test method\n\t!!\n\tfunction myStrConstrain( multisetPositions, current ) result( output )\n\t\tinteger, allocatable, intent(in) :: multisetPositions(:)\n\t\tinteger, intent(in) :: current\n\t\tlogical :: output\n\t\t\n\t\tinteger :: i, j\n\t\t\n\t\tif( current == size(multisetPositions) ) then\n\t\t\t!----------------------------------------------\n\t\t\t! \u00bf El multiset encontrado es correcto ?\n\t\t\t!----------------------------------------------\n\t\t\toutput = .false.\n\t\t\t\n\t\t\tdo i=1,size(multisetPositions)\n! \t\t\t\tdo j=1,size(multisetPositions)\n! \t\t\t\t\tif( multisetPositions(i) == 1 .and. multisetPositions(j) == 3 ) then ! Que la cadena tenga una \"a\" y una \"c\"\n! \t\t\t\t\t\toutput = .true.\n! \t\t\t\t\t\treturn\n! \t\t\t\t\tend if\n\n\t\t\t\t\tif( multisetPositions(i) == 1 ) then ! Que la cadena tenga una \"a\" en cualquier posici\u00f3n\n\t\t\t\t\t\toutput = .true.\n\t\t\t\t\t\treturn\n\t\t\t\t\tend if\n! \t\t\t\tend do\n\t\t\tend do\n\t\telse\n\t\t\t!----------------------------------------------\n\t\t\t! \u00bf El camino recorrido es incorrecto ?\n\t\t\t!----------------------------------------------\n\t\t\toutput = .false. ! La soluci\u00f3n solo se puede saber hasta el final\n\t\tend if\n\t\t\n\t\treturn\n\tend function myStrConstrain\n\t\n\t!>\n\t!! This is only necessary for RandomUtils_test method\n\t!!\n\tfunction myIntConstrainDebug( multisetPositions, current ) result( output )\n\t\tinteger, allocatable, intent(in) :: multisetPositions(:)\n\t\tinteger, intent(in) :: current\n\t\tlogical :: output\n\t\t\n\t\tinteger :: i\n\t\tinteger :: ssum\n\t\t\n\t\twrite(*,\"(A)\", advance=\"no\") \">>>\"\n\t\t\n\t\tssum = 0\n\t\tdo i=1,current\n\t\t\tssum = ssum + MyiArray( multisetPositions(i) )\n\t\t\t\n\t\t\twrite(*,\"(I1,A,I1,A)\", advance=\"no\") MyiArray( multisetPositions(i) ), \"(\", multisetPositions(i), \")\"\n\t\tend do\n\t\t\n\t\tif( current == size(multisetPositions) ) then\n\t\t\t!----------------------------------------------\n\t\t\t! \u00bf El multiset encontrado es correcto ?\n\t\t\t!----------------------------------------------\n\t\t\twrite(*,\"(A,I3,I5)\", advance=\"no\") \"<<<\", ssum, current\n\t\t\t\n\t\t\toutput = .false.\n\t\t\tif( ssum <= 8 ) then ! Que la suma no exceda 8\n\t\t\t\twrite(*,\"(A)\") \" OK\"\n\t\t\t\toutput = .true.\n\t\t\telse\n\t\t\t\twrite(*,\"(A)\") \" Failed\"\n\t\t\tend if\n\t\t\t\n\t\telse\n\t\t\t!----------------------------------------------\n\t\t\t! \u00bf El camino recorrido es incorrecto ?\n\t\t\t!----------------------------------------------\n\t\t\twrite(*,\"(A,I3,I5)\", advance=\"no\") \"<<<\", ssum\n\t\t\t\n\t\t\toutput = .true.\n\t\t\tif( ssum <= 8 ) then ! Que la suma no exceda 8\n\t\t\t\twrite(*,\"(A)\") \" right way\"\n\t\t\t\toutput = .false.\n\t\t\telse\n\t\t\t\twrite(*,\"(A)\") \" bad way\"\n\t\t\tend if\n\t\t\t\n\t\tend if\n\t\t\n\t\treturn\n\tend function myIntConstrainDebug\n\t\n\t!>\n\t!! This is only necessary for RandomUtils_test method\n\t!!\n\tfunction myIntConstrain( multisetPositions, current ) result( output )\n\t\tinteger, allocatable, intent(in) :: multisetPositions(:)\n\t\tinteger, intent(in) :: current\n\t\tlogical :: output\n\t\t\n\t\tinteger :: i\n\t\tinteger :: ssum\n\t\t\n\t\tssum = 0\n\t\tdo i=1,current\n\t\t\tssum = ssum + MyiArray( multisetPositions(i) )\n\t\tend do\n\t\t\n\t\tif( current == size(multisetPositions) ) then\n\t\t\t!----------------------------------------------\n\t\t\t! \u00bf El multiset encontrado es correcto ?\n\t\t\t!----------------------------------------------\n\t\t\toutput = .false.\n\t\t\tif( ssum <= 8 ) then ! Que la suma no exceda 8\n\t\t\t\toutput = .true.\n\t\t\tend if\n\t\telse\n\t\t\t!----------------------------------------------\n\t\t\t! \u00bf El camino recorrido es incorrecto ?\n\t\t\t!----------------------------------------------\n\t\t\toutput = .true.\n\t\t\tif( ssum <= 8 ) then ! Que la suma no exceda 8\n\t\t\t\toutput = .false.\n\t\t\tend if\n\t\tend if\n\t\t\n\t\treturn\n\tend function myIntConstrain\n\t\n\t!>\n\t!! This is only necessary for RandomUtils_test method\n\t!!\n\tfunction myMassConstrain( multisetPositions, current ) result( output )\n\t\tinteger, allocatable, intent(in) :: multisetPositions(:)\n\t\tinteger, intent(in) :: current\n\t\tlogical :: output\n\t\t\n\t\tinteger :: i\n\t\tinteger :: ssum\n\t\t\n\t\tssum = 0\n\t\tdo i=1,current\n\t\t\tssum = ssum + MyiArray( multisetPositions(i) )\n\t\tend do\n\t\t\n\t\tif( current == size(multisetPositions) ) then\n\t\t\t!----------------------------------------------\n\t\t\t! \u00bf El multiset encontrado es correcto ?\n\t\t\t!----------------------------------------------\n\t\t\toutput = .false.\n\t\t\tif( ssum <= MyiArray(size(MyiArray)) ) then\n\t\t\t\toutput = .true.\n\t\t\tend if\n\t\telse\n\t\t\t!----------------------------------------------\n\t\t\t! \u00bf El camino recorrido es incorrecto ?\n\t\t\t!----------------------------------------------\n\t\t\toutput = .true.\n\t\t\tif( ssum <= MyiArray(size(MyiArray)) ) then\n\t\t\t\toutput = .false.\n\t\t\tend if\n\t\tend if\n\t\t\n\t\treturn\n\tend function myMassConstrain\n\t\n\t!>\n\t!! @brief The result has the value true if the value of x is NaN; otherwise, false.\n\t!!\n\tfunction Math_isNaN( x ) result( output )\n\t\treal(8), intent(in) :: x\n\t\tlogical :: output\n\t\t\n\t\toutput = IEEE_IS_NAN( x )\n\tend function Math_isNaN\n\t\n\t!>\n\t!! @brief The result has the value true if the value of x is Inf; otherwise, false.\n\t!!\n\tfunction Math_isInf( x ) result( output )\n\t\treal(8), intent(in) :: x\n\t\tlogical :: output\n\t\t\n\t\toutput = .not. IEEE_IS_FINITE( x )\n\tend function Math_isInf\n\t\n\t!>\n\t!! @brief The result has the value true if the value of x is Inf; otherwise, false.\n\t!!\n\tfunction Math_isIInf( x ) result( output )\n\t\tinteger, intent(in) :: x\n\t\tlogical :: output\n\t\t\n\t\toutput = ( huge(0) == x )\n\tend function Math_isIInf\n\t\n\t!>\n\t!! @brief Returns the scalar product of two vectors (r1,r2),\n\t!! which must have the same length (same number of elements).\n\t!!\n\tfunction Math_dotProduct( r1, r2 ) result( output )\n\t\treal(8) :: r1(3), r2(3)\n\t\treal(8) :: output\n\t\t\n\t\toutput = DOT_PRODUCT( r1, r2 )\n\tend function Math_dotProduct\n\t\n\t!>\n\t!! @brief Returns the cross product of two vectors (r1,r2),\n\t!! which must have the same length (same number of elements).\n\t!!\n\tfunction Math_crossProduct( r1, r2 ) result( output )\n\t\treal(8) :: r1(3), r2(3)\n\t\treal(8) :: output(3)\n\t\t\n\t\toutput(1) = r1(2)*r2(3) - r1(3)*r2(2)\n\t\toutput(2) = r1(3)*r2(1) - r1(1)*r2(3)\n\t\toutput(3) = r1(1)*r2(2) - r1(2)*r2(1)\n\tend function Math_crossProduct\n\t\n\t!>\n\t!! @brief Returns the distance from the point r0 to the line specified by\n\t!! two points r1 and r2 lying on it. Only 3D case is available.\n\t!!\n\tfunction Math_pointLineDistance( r0, r1, r2 ) result( output )\n\t\treal(8) :: r0(3), r1(3), r2(3)\n\t\treal(8) :: output\n\t\t\n\t\toutput = norm2(Math_crossProduct( r0-r1, r0-r2 ))/norm2(r2-r1)\n\tend function Math_pointLineDistance\n\t\n\t!>\n\t!! @brief Test method\n\t!!\n\tsubroutine Math_test()\n\t\treal(8), allocatable :: rArray(:)\n\t\tinteger, allocatable :: iArray(:)\n\t\tinteger, allocatable :: indexes(:)\n\t\tinteger, allocatable :: iComb(:), iCombOld(:,:)\n\t\tcharacter(10), allocatable :: strArray(:), sComb(:)\n! \t\tcharacter(10), allocatable :: comb(:)\n\t\treal(8) :: x\n\t\t\n\t\tinteger :: i, j, k, l\n\t\tinteger :: nFrag\n\t\t\n! \t\twrite(*,*) \"\"\n! \t\twrite(*,*) \"Sorting vectors\"\n! \t\twrite(*,*) \"===============\"\n! \t\tallocate( rArray(19) )\n! \t\tallocate( indexes(19) )\n! \t\t\n! \t\trArray = [ -33.89007, -33.89007, -35.21007, -35.42677, -35.90699, &\n! \t\t\t -33.67374, -34.15396, -33.27902, -33.27902, -34.04338, &\n! \t\t\t -34.04338, -31.81726, -31.81726, -33.49329, -33.97351, &\n! \t\t\t -32.91849, -33.39871, -33.24224, -33.24224 ]\n! \t\t\t \n! \t\tcall Math_sort( rArray, indexes )\n! \t\t\n! \t\twrite(*,\"(5X,2A15)\") \"original\", \"sorted\"\n! \t\twrite(*,\"(5X,2A15)\") \"--------\", \"------\"\n! \t\tdo i=1,size(rArray)\n! \t\t\twrite(*,\"(I5,2F15.5)\") i, rArray(i), rArray( indexes(i) )\n! \t\tend do\n! \t\t\n! \t\tallocate( iArray(19) )\n! \t\t\n! \t\tiArray = [ -35, -33, -35, -35, -31, &\n! \t\t\t -32, -34, -33, -34, -32, &\n! \t\t\t -39, -31, -31, -31, -33, &\n! \t\t\t -31, -33, -33, -30 ]\n! \t\t\t \n! \t\tcall Math_sort( iArray, indexes )\n! \t\t\n! \t\twrite(*,\"(A)\") \"\"\n! \t\twrite(*,\"(5X,2A15)\") \"original\", \"sorted\"\n! \t\twrite(*,\"(5X,2A15)\") \"--------\", \"------\"\n! \t\tdo i=1,size(rArray)\n! \t\t\twrite(*,\"(I5,2I15)\") i, iArray(i), iArray( indexes(i) )\n! \t\tend do\n! \t\t\t \n! \t\tdeallocate( rArray )\n! \t\tdeallocate( iArray )\n! \t\tdeallocate( indexes )\n! \t\t\n! \t\twrite(*,*) \"\"\n! \t\twrite(*,*) \"3j symbols\"\n! \t\twrite(*,*) \"==========\"\n! \t\t\n! \t\twrite(*,*) \"(3/2 0 3/2; 0 0 0) = \", Math_wigner3j( 1.5_8, 0.0_8, 1.5_8, 0.0_8, 0.0_8, 0.0_8 )\n! \t\twrite(*,*) \"(3/2 0 3/2; 1/2 0 -1/2) = \", Math_wigner3j( 1.5_8, 0.0_8, 1.5_8, 0.5_8, 0.0_8,-0.5_8 )\n! \t\twrite(*,*) \"(3/2 0 3/2; -1/2 0 1/2) = \", Math_wigner3j( 1.5_8, 0.0_8, 1.5_8,-0.5_8, 0.0_8, 0.5_8 )\n! \t\twrite(*,*) \"(3/2 0 3/2; 3/2 0 -3/2) = \", Math_wigner3j( 1.5_8, 0.0_8, 1.5_8, 1.5_8, 0.0_8,-1.5_8 )\n! \t\twrite(*,*) \"(3/2 0 3/2; -3/2 0 3/2) = \", Math_wigner3j( 1.5_8, 0.0_8, 1.5_8,-1.5_8, 0.0_8, 1.5_8 )\n\t\t\n\t\twrite(*,*) \"\"\n\t\twrite(*,*) \"Combinatorial\"\n\t\twrite(*,*) \"=============\"\n\t\t\n\t\twrite(*,*) \"Gamma(0.5) = \", Gamma(0.5_8)\n\t\twrite(*,*) \"log_Gamma(0.5) = \", log_Gamma(0.5_8)\n\t\twrite(*,*) \"Gamma(7+1) = \", Gamma(8.0_8)\n\t\twrite(*,*) \"Math_fact(7) = \", Math_fact(7)\n\t\twrite(*,*) \"Math_comb(7,2) = \", Math_comb(7,2)\n\t\twrite(*,*) \"Math_multisetNumber(7,2) = \", Math_multisetNumber( 7, 2 )\n\t\twrite(*,*) \"\"\n\t\t\t\t\n! \t\tdeallocate( comb )\n\t\t!--------------------------------------------------------\n\t\t\n\t\tallocate( strArray(3) )\n\t\tstrArray = [\"a\", \"b\", \"c\"]\n\t\t\n\t\twrite(*,*)\n\t\twrite(*,\"(A,3A2,A)\") \" set = { \", strArray, \"}\"\n\t\twrite(*,*) \"Math_multisetNumber( nElems, 3 ) = \"\n\t\tcall Math_multisets( 3, 3, iCombOld, myStrConstrain )\n\t\t\n\t\tdo i=1,size(iCombOld,dim=1)\n\t\t\twrite(*,\"(I5,A)\", advance=\"no\") i, \") \"\n\t\t\tdo j=1,3\n\t\t\t\twrite(*,\"(A)\", advance=\"no\") trim(strArray( iCombOld(i,j) ))\n\t\t\tend do\n\t\t\twrite(*,*) \"\"\n\t\tend do\n\t\t\n\t\tdeallocate( strArray )\n\t\tdeallocate( iCombOld )\n\t\t\n\t\t!-----------------------------------------------------------------\n\t\tallocate( MyiArray(3) )\n\t\tMyiArray = [1, 3, 5]\n\t\t\n\t\twrite(*,*)\n\t\twrite(*,\"(A,3I2,A)\") \" set = { \", MyiArray, \" }\"\n\t\twrite(*,*) \"Math_multisetNumber( nElems, 3 ) = \", Math_multisetNumber( 3, 3 )\n\t\tcall Math_multisets( 3, 3, iCombOld, myIntConstrain )\n! \t\tcall Math_multisets( 3, 3, iCombOld, myIntConstrainDebug )\n\t\t\n\t\tdo i=1,size(iCombOld,dim=1)\n\t\t\twrite(*,\"(I5,A)\", advance=\"no\") i, \") \"\n\t\t\tdo j=1,3\n\t\t\t\twrite(*,\"(I1)\", advance=\"no\") MyiArray( iCombOld(i,j) )\n\t\t\tend do\n\t\t\twrite(*,*) \"\"\n\t\tend do\n\t\t\n\t\tdeallocate( MyiArray )\n\t\tdeallocate( iCombOld )\n\n\t\t!--------------------------------------------------------\n\t\t\n\t\tallocate( strArray(8) )\n\t\tstrArray = [\"H\", \"C\", \"CH\", \"C2\", \"H2\", \"C2H\", \"CH2\", \"C2H2\"]\n\t\t\n\t\tallocate( MyiArray(8) )\n\t\tMyiArray = [1, 6, 7, 12, 2, 13, 8, 14]\n\t\t\n\t\twrite(*,*)\n\t\twrite(*,\"(A,A5,A)\") \" set = { \", strArray, \" }\"\n\t\t\n\t\tk=1\n\t\tdo nFrag=1,size(strArray)\n\t\t\tcall Math_multisets( size(strArray), nFrag, iCombOld, myMassConstrain )\n\t\t\t\n\t\t\tdo i=1,size(iCombOld,dim=1)\n\t\t\t\twrite(*,\"(I5,A)\", advance=\"no\") k, \") \"\n\t\t\t\tdo j=1,nFrag-1\n\t\t\t\t\twrite(*,\"(A)\", advance=\"no\") trim(strArray( iCombOld(i,j) ))//\"+\"\n\t\t\t\tend do\n\t\t\t\twrite(*,\"(A)\", advance=\"no\") trim(strArray( iCombOld(i,nFrag) ))\n\t\t\t\twrite(*,*) \"\"\n\t\t\t\t\n\t\t\t\tk=k+1\n\t\t\tend do\n\t\tend do\n\t\t\n\t\tdeallocate( strArray )\n\t\tdeallocate( iCombOld )\n\t\t\n\t\t!--------------------------------------------------------\n\t\t\n! \t\tx = -0.99999_8\n! \t\tdo while( x < 1.0_8 )\n! \t\t\twrite(*,*) x, Math_erfinv(x)\n! \t\t\tx = x+0.001_8\n! \t\tend do\n\t\t\n! \t\twrite(*,\"(3F15.6)\") Math_erfinv(0.5_8), Math_erfinv(0.33_8), Math_erfinv(-1.0_8/3.0_8)\n! \t\twrite(*,\"(3F15.6)\") 0.4769362762, 0.3013321461, -0.3045701942\n! \t\twrite(*,\"(3F15.6)\") Math_erfinv(0.5_8)-0.4769362762, Math_erfinv(0.33_8)-0.3013321461, Math_erfinv(-1.0_8/3.0_8)-(-0.3045701942)\n\n\t\twrite(*,*) \"\"\n\t\twrite(*,*) \"Testing IEEE support\"\n\t\twrite(*,*) \"====================\"\n\t\twrite(*,*) \"isNaN( 2.0 ) = \", Math_isNaN( 2.0_8 )\n\t\twrite(*,*) \"isNaN( 1.0d500 ) = \", Math_isNaN( 1.0d500 )\n\t\twrite(*,*) \"isNaN( sqrt(-1.0_8) ) = \", Math_isNaN( sqrt(-1.0_8) )\n\t\twrite(*,*) \"1.0_8/Math_INF = \", 1.0_8/Math_INF\n\t\twrite(*,\"(A,F10.5)\") \"Math_INF = \", Math_INF\n\t\twrite(*,*) \"isInf( 1.0d56 ) = \", Math_isInf( 1.0d56 )\n\t\twrite(*,*) \"isInf( 1.0_8/0.0_8 ) = \", Math_isInf( 1.0_8/0.0_8 )\n\t\twrite(*,*) \"isInf( 1.0_8/0.0_8+10.0_8 ) = \", Math_isInf( 1.0_8/0.0_8+10.0_8 )\n\t\twrite(*,*) \"isInf( 1.0_8/0.0_8-10.0_8 ) = \", Math_isInf( 1.0_8/0.0_8-10.0_8 )\n\t\t\n\tend subroutine Math_test\n\t\nend module Math_\n\n", "meta": {"hexsha": "5334d4197b2919c7a4b4e9d7de9903fbb280199e", "size": 37732, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/Math.f90", "max_stars_repo_name": "nfaguirrec/scift", "max_stars_repo_head_hexsha": "2a38018bd495ad42e57a674f525041c4a854dccd", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI", "BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-05-28T02:04:45.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-28T02:04:45.000Z", "max_issues_repo_path": "src/Math.f90", "max_issues_repo_name": "bbw7561135/scift", "max_issues_repo_head_hexsha": "0e81e7d29889970d35cc563cc45e9a87fd1cf06d", "max_issues_repo_licenses": ["BSD-3-Clause-Open-MPI", "BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-10-14T21:21:21.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-15T04:37:58.000Z", "max_forks_repo_path": "src/Math.f90", "max_forks_repo_name": "bbw7561135/scift", "max_forks_repo_head_hexsha": "0e81e7d29889970d35cc563cc45e9a87fd1cf06d", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI", "BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-30T04:43:43.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-30T04:43:43.000Z", "avg_line_length": 27.4015976761, "max_line_length": 279, "alphanum_fraction": 0.5807802396, "num_tokens": 13179, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772417253256, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.6887127261568793}} {"text": "!---------------------------------------------------------------------- \n!---------------------------------------------------------------------- \n! ops : Optimization of periodic solutions \n!---------------------------------------------------------------------- \n!---------------------------------------------------------------------- \n\n SUBROUTINE FUNC(NDIM,U,ICP,PAR,IJAC,F,DFDU,DFDP) \n! ---------- ---- \n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: NDIM, ICP(*), IJAC\n DOUBLE PRECISION, INTENT(IN) :: U(NDIM), PAR(*)\n DOUBLE PRECISION, INTENT(OUT) :: F(NDIM)\n DOUBLE PRECISION, INTENT(INOUT) :: DFDU(NDIM,NDIM), DFDP(NDIM,*)\n\n DOUBLE PRECISION x,y,z,p1,p2,p3,p4\n INTEGER I,J\n\n x=U(1)\n y=U(2)\n z=U(3)\n\n p1=PAR(1)\n p2=PAR(2)\n p3=PAR(3)\n p4=PAR(4)\n\n F(1)=( -p4*(x**3/3-x) + (z-x)/p2 - y ) / p1 \n F(2)=x-p3 \n F(3)=-(z-x)/p2 \n\n IF(IJAC.EQ.0)RETURN\n\n DFDU(1,1)=( -p4*(x**2-1) - 1/p2 ) /p1\n DFDU(1,2)=-1/p1\n DFDU(1,3)=1/(p2*p1)\n\n DFDU(2,1)=1\n DFDU(2,2)=0\n DFDU(2,3)=0\n\n DFDU(3,1)=1/p2\n DFDU(3,2)=0\n DFDU(3,3)=-1/p2\n\n IF(IJAC.EQ.1)RETURN\n\n! *Parameter derivatives\n DO I=1,3\n DO J=1,9\n DFDP(I,J)=0.d0\n ENDDO\n ENDDO\n\n DFDP(1,1)=-( -p4*(x**3/3-x) + (z-x)/p2 - y )/p1**2\n DFDP(1,2)=-(z-x)/(p2**2*p1)\n DFDP(1,3)=0\n DFDP(1,4)=-(x**3/3-x)/p1\n\n DFDP(2,1)=0\n DFDP(2,2)=0\n DFDP(2,3)=-1\n DFDP(2,4)=0\n\n DFDP(3,1)=0\n DFDP(3,2)=(z-x)/p2**2\n DFDP(3,3)=0\n DFDP(3,4)=0\n\n END SUBROUTINE FUNC\n\n SUBROUTINE STPNT(NDIM,U,PAR,T)\n! ---------- ----- \n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: NDIM\n DOUBLE PRECISION, INTENT(INOUT) :: U(NDIM),PAR(*)\n DOUBLE PRECISION, INTENT(IN) :: T\n\n DOUBLE PRECISION p1,p2,p3,p4\n\n p1=0.5\n p2=4\n p3=0.9\n p4=2.\n\n U(1)=p3 \n U(2)=-p4*(p3**3/3-p3)\n U(3)=p3 \n\n PAR(1)=p1 \n PAR(2)=p2\n PAR(3)=p3 \n PAR(4)=p4\n\n END SUBROUTINE STPNT\n\n SUBROUTINE FOPT(NDIM,U,ICP,PAR,IJAC,FS,DFDU,DFDP)\n! ---------- ----\n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: NDIM, ICP(*), IJAC\n DOUBLE PRECISION, INTENT(IN) :: U(NDIM), PAR(*)\n DOUBLE PRECISION, INTENT(OUT) :: FS\n DOUBLE PRECISION, INTENT(INOUT) :: DFDU(NDIM),DFDP(*)\n\n INTEGER I\n\n FS=PAR(3)\n\n IF(IJAC.EQ.0)RETURN\n\n DO I=1,NDIM\n DFDU(I)=0.d0\n ENDDO\n\n IF(IJAC.EQ.1)RETURN\n\n! *Parameter derivatives\n DO I=1,9\n DFDP(I)=0.d0\n ENDDO\n\n DFDP(3)=1.d0\n\n END SUBROUTINE FOPT\n\n SUBROUTINE BCND \n END SUBROUTINE BCND\n\n SUBROUTINE ICND \n END SUBROUTINE ICND\n\n SUBROUTINE PVLS\n END SUBROUTINE PVLS\n", "meta": {"hexsha": "0f5302730831d5cd9c808af82be739cc434b7e1b", "size": 2842, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "07p/demos/ops/ops.f90", "max_stars_repo_name": "st970703/AUTO07P-Update-to-Python-3.0", "max_stars_repo_head_hexsha": "fb2d2aebf2127fa914064d01ed62c0acb5f6421c", "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": "07p/demos/ops/ops.f90", "max_issues_repo_name": "st970703/AUTO07P-Update-to-Python-3.0", "max_issues_repo_head_hexsha": "fb2d2aebf2127fa914064d01ed62c0acb5f6421c", "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": "07p/demos/ops/ops.f90", "max_forks_repo_name": "st970703/AUTO07P-Update-to-Python-3.0", "max_forks_repo_head_hexsha": "fb2d2aebf2127fa914064d01ed62c0acb5f6421c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.8970588235, "max_line_length": 72, "alphanum_fraction": 0.4232934553, "num_tokens": 1080, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648677, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.6887127253404526}} {"text": "program main\n ! compare the energy calculated from matrix diagonalization method and Numerov's method\n\n implicit none\n integer, parameter :: dp = selected_real_kind(8)\n\n ! local vars\n integer :: i, n(100)\n real(dp) :: EMD(100), EN(100)\n\n open(unit = 1, file = '3-energy-ExactDiagonalization.txt', status = 'unknown')\n do i = 1, 100\n read(1, '(i4,f20.8)') n(i), EMD(i)\n end do\n close(1)\n\n open(unit = 2, file = '3-energy-Numerov.txt', status = 'unknown')\n do i = 1, 100\n read(2, '(i4,f20.8)') n(i), EN(i)\n end do\n close(2)\n\n open(unit = 3, file = '3-energy-Compare.txt', status = 'unknown')\n do i = 1, 10\n write(3, '(i4,4f20.8)') n(i), EMD(i), EN(i), EMD(i) - EN(i), (EMD(i) - EN(i)) / EN(i)\n end do\n write(3, *)\n do i = 91, 100\n write(3, '(i4,4f20.8)') n(i), EMD(i), EN(i), EMD(i) - EN(i), (EMD(i) - EN(i)) / EN(i)\n end do\n close(3)\nend program main\n", "meta": {"hexsha": "a270252d42fbf95f65365bd672ef34d9fdd9e439", "size": 941, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Week-2-Assignment-1/Assignment/3-1DInfiPotWellWCntBrr-Compare.f90", "max_stars_repo_name": "Chen-Jialin/Computational-Physics-Exercises-and-Assignments", "max_stars_repo_head_hexsha": "592407af2e999b539473f473ca99186a12418b99", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-04-15T10:30:01.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T08:22:51.000Z", "max_issues_repo_path": "Week-2-Assignment-1/Assignment/3-1DInfiPotWellWCntBrr-Compare.f90", "max_issues_repo_name": "Chen-Jialin/Computational-Physics-Exercises-and-Assignments", "max_issues_repo_head_hexsha": "592407af2e999b539473f473ca99186a12418b99", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Week-2-Assignment-1/Assignment/3-1DInfiPotWellWCntBrr-Compare.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": 28.5151515152, "max_line_length": 93, "alphanum_fraction": 0.5430393199, "num_tokens": 348, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772318846386, "lm_q2_score": 0.7879312031126511, "lm_q1q2_score": 0.688712724932239}} {"text": "!-------------------------------------------------------------------------------!\r\n! !\r\n\r\nsubroutine linlsq(n,m,f,y,w,c)\r\n\r\n! This subroutine performs a fit of the datavalues (i,y(i)), i = 1,..,n !\r\n! to the linear modelfunction c(1)*f(:,1) + c(2)*f(:,2) + ... + c(m)*f(:,m) ! \r\n! !\r\n! see A. Garcia, Numerical methods for physics, ISBN 0-13-906744-2 !\r\n! pages 142-146 !\r\n! !\r\n! Authors: !\r\n! Per J\\\"onsson, Malm\\\"o University, Sweden !\r\n! e-mail per.jonsson@ts.mah.se !\r\n! !\r\n! Lars Eklundh, Lund University, Sweden !\r\n! e-mail lars.eklundh@nateko.lu.se !\r\n! !\r\n! Updated 26/3-2005 !\r\n! !\r\n!-------------------------------------------------------------------------------!\r\n\r\nimplicit none\r\n\r\ninteger :: i,j,n,m\r\ndouble precision :: f(n,m),y(n),w(n),wsq(n),a(m,m),b(m),c(m)\r\n\r\n!---- Construct the matrices a = A^T A and b = A^T y --------------------------\r\n\r\nwsq = w**2.d0 \r\ndo i = 1,m\r\n do j = i,m\r\n a(i,j) = sum(f(:,i)*f(:,j)*wsq)\r\n end do \r\n b(i) = sum(f(:,i)*y*wsq)\r\nend do\r\n \r\ndo i = 2,m\r\n do j = 1,i-1\r\n a(i,j) = a(j,i) \r\n end do\r\nend do\r\n \r\n!---- Solve the m x m normal equation A^T A c = A^T b -------------------------\r\n \r\ncall gauss(m,a,b,c)\r\n\r\nend subroutine linlsq\r\n", "meta": {"hexsha": "e55262be38414254d2c48007ff8860bacbef3e8c", "size": 2069, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/Smooth_Gapfill_LAI/linlsq.f90", "max_stars_repo_name": "bucricket/projectMASpreprocess", "max_stars_repo_head_hexsha": "608495d7cd6890ecca6ad2a8be0d15b5ea80f7c1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-28T20:26:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T20:26:59.000Z", "max_issues_repo_path": "source/Smooth_Gapfill_LAI/linlsq.f90", "max_issues_repo_name": "bucricket/projectMASpreprocess", "max_issues_repo_head_hexsha": "608495d7cd6890ecca6ad2a8be0d15b5ea80f7c1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/Smooth_Gapfill_LAI/linlsq.f90", "max_forks_repo_name": "bucricket/projectMASpreprocess", "max_forks_repo_head_hexsha": "608495d7cd6890ecca6ad2a8be0d15b5ea80f7c1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-04-20T21:04:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-16T08:05:44.000Z", "avg_line_length": 42.2244897959, "max_line_length": 86, "alphanum_fraction": 0.2542290962, "num_tokens": 427, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582516374121, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.6887013481425551}} {"text": "c =======fftpack.f subset==============================================\nc subroutine ezfftf(n,r,azero,a,b,wsave)\nc\nc subroutine ezfftf computes the fourier coefficients of a real\nc perodic sequence (fourier analysis). the transform is defined\nc below at output parameters azero,a and b. ezfftf is a simplified\nc but slower version of rfftf.\nc\nc input parameters\nc\nc n the length of the array r to be transformed. the method\nc is must efficient when n is the product of small primes.\nc\nc r a real array of length n which contains the sequence\nc to be transformed. r is not destroyed.\nc\nc\nc wsave a work array which must be dimensioned at least 3*n+15.\nc in the program that calls ezfftf. the wsave array must be\nc initialized by calling subroutine ezffti(n,wsave) and a\nc different wsave array must be used for each different\nc value of n. this initialization does not have to be\nc repeated so long as n remains unchanged thus subsequent\nc transforms can be obtained faster than the first.\nc the same wsave array can be used by ezfftf and ezfftb.\nc\nc output parameters\nc\nc azero the sum from i=1 to i=n of r(i)/n\nc\nc a,b for n even b(n/2)=0. and a(n/2) is the sum from i=1 to\nc i=n of (-1)**(i-1)*r(i)/n\nc\nc for n even define kmax=n/2-1\nc for n odd define kmax=(n-1)/2\nc\nc then for k=1,...,kmax\nc\nc a(k) equals the sum from i=1 to i=n of\nc\nc 2./n*r(i)*cos(k*(i-1)*2*pi/n)\nc\nc b(k) equals the sum from i=1 to i=n of\nc\nc 2./n*r(i)*sin(k*(i-1)*2*pi/n)\nc\nc\n SUBROUTINE DEZFFTF(N,R,AZERO,A,B,WSAVE)\n DOUBLE PRECISION R\n DOUBLE PRECISION AZERO\n DOUBLE PRECISION A\n DOUBLE PRECISION B\n DOUBLE PRECISION WSAVE\n DOUBLE PRECISION CF\n DOUBLE PRECISION CFM\n DIMENSION R(*),A(*),B(*),WSAVE(*)\nc\n IF (N-2.LE.0) THEN\n IF (N-2.NE.0) THEN\n AZERO = R(1)\n RETURN\n END IF\n AZERO = .5D0* (R(1)+R(2))\n A(1) = .5D0* (R(1)-R(2))\n RETURN\n END IF\n DO I = 1,N\n WSAVE(I) = R(I)\n END DO\n CALL DRFFTF(N,WSAVE,WSAVE(N+1))\n CF = 2.D0/DBLE(N)\n CFM = -CF\n AZERO = .5D0*CF*WSAVE(1)\n NS2 = (N+1)/2\n NS2M = NS2 - 1\n DO I = 1,NS2M\n A(I) = CF*WSAVE(2*I)\n B(I) = CFM*WSAVE(2*I+1)\n END DO\nC B(NS2) = 0.D0\n IF (MOD(N,2).EQ.1) RETURN\n A(NS2) = .5D0*CF*WSAVE(N)\n B(NS2) = 0.D0\n RETURN\n END\nc\nc =====================================================================\nc subroutine rfftf(n,r,wsave)\nc\nc subroutine rfftf computes the fourier coefficients of a real\nc perodic sequence (fourier analysis). the transform is defined\nc below at output parameter r.\nc\nc input parameters\nc\nc n the length of the array r to be transformed. the method\nc is most efficient when n is a product of small primes.\nc n may change so long as different work arrays are provided\nc\nc r a real array of length n which contains the sequence\nc to be transformed\nc\nc wsave a work array which must be dimensioned at least 2*n+15.\nc in the program that calls rfftf. the wsave array must be\nc initialized by calling subroutine rffti(n,wsave) and a\nc different wsave array must be used for each different\nc value of n. this initialization does not have to be\nc repeated so long as n remains unchanged thus subsequent\nc transforms can be obtained faster than the first.\nc the same wsave array can be used by rfftf and rfftb.\nc\nc\nc output parameters\nc\nc r r(1) = the sum from i=1 to i=n of r(i)\nc\nc if n is even set l =n/2 , if n is odd set l = (n+1)/2\nc\nc then for k = 2,...,l\nc\nc r(2*k-2) = the sum from i = 1 to i = n of\nc\nc r(i)*cos((k-1)*(i-1)*2*pi/n)\nc\nc r(2*k-1) = the sum from i = 1 to i = n of\nc\nc -r(i)*sin((k-1)*(i-1)*2*pi/n)\nc\nc if n is even\nc\nc r(n) = the sum from i = 1 to i = n of\nc\nc (-1)**(i-1)*r(i)\nc\nc ***** note\nc this transform is unnormalized since a call of rfftf\nc followed by a call of rfftb will multiply the input\nc sequence by n.\nc\nc wsave contains results which must not be destroyed between\nc calls of rfftf or rfftb.\nc\n SUBROUTINE DRFFTF(N,R,WSAVE)\n DOUBLE PRECISION R\n DOUBLE PRECISION WSAVE\n DIMENSION R(*),WSAVE(*)\nc\n IF (N.EQ.1) RETURN\n CALL DRFFTF1OLD(N,R,WSAVE,WSAVE(N+1),WSAVE(2*N+1))\n RETURN\n END\nc\n SUBROUTINE DRFFTF1OLD(N,C,CH,WA,IFAC)\n DOUBLE PRECISION C\n DOUBLE PRECISION CH\n DOUBLE PRECISION WA\n DIMENSION CH(*),C(*),WA(*),IFAC(*)\n\n NF = IFAC(2)\n DO K1 = 1,NF\n KH = NF - K1\n END DO\n NA = 1\n L2 = N\n IW = N\n DO K1 = 1,NF\n KH = NF - K1\n IP = IFAC(KH+3)\n L1 = L2/IP\n IDO = N/L2\n IDL1 = IDO*L1\n IW = IW - (IP-1)*IDO\n NA = 1 - NA\n IF (IP.EQ.4) THEN\n IX2 = IW + IDO\n IX3 = IX2 + IDO\n IF (NA.EQ.0) THEN\n CALL DRADF4(IDO,L1,C,CH,WA(IW),WA(IX2),WA(IX3))\n GO TO 110\n END IF\n CALL DRADF4(IDO,L1,CH,C,WA(IW),WA(IX2),WA(IX3))\n GO TO 110\n END IF\n IF (IP.EQ.2) THEN\n IF (NA.EQ.0) THEN\n CALL DRADF2(IDO,L1,C,CH,WA(IW))\n GO TO 110\n END IF\n CALL DRADF2(IDO,L1,CH,C,WA(IW))\n GO TO 110\n END IF\n 104 CONTINUE\n IF (IP.EQ.3) THEN\n IX2 = IW + IDO\n IF (NA.EQ.0) THEN\n CALL DRADF3(IDO,L1,C,CH,WA(IW),WA(IX2))\n GO TO 110\n END IF\n CALL DRADF3(IDO,L1,CH,C,WA(IW),WA(IX2))\n GO TO 110\n END IF\n 106 CONTINUE\n IF (IP.EQ.5) THEN\n IX2 = IW + IDO\n IX3 = IX2 + IDO\n IX4 = IX3 + IDO\n IF (NA.EQ.0) THEN\n CALL DRADF5(IDO,L1,C,CH,WA(IW),WA(IX2),WA(IX3),\n + WA(IX4))\n GO TO 110\n END IF\n CALL DRADF5(IDO,L1,CH,C,WA(IW),WA(IX2),WA(IX3),WA(IX4))\n GO TO 110\n END IF\n 108 CONTINUE\n IF (IDO.EQ.1) NA = 1 - NA\n IF (NA.EQ.0) THEN\n CALL DRADFG(IDO,IP,L1,IDL1,C,C,C,CH,CH,WA(IW))\n NA = 1\n ELSE\n CALL DRADFG(IDO,IP,L1,IDL1,CH,CH,CH,C,C,WA(IW))\n NA = 0\n END IF\n 110 CONTINUE\n L2 = L1\n END DO\n IF (NA.EQ.1) RETURN\n DO I = 1,N\n C(I) = CH(I)\n END DO\n RETURN\n END\nc ==============================================================\nc subroutine ezfftb(n,r,azero,a,b,wsave)\nc\nc subroutine ezfftb computes a real perodic sequence from its\nc fourier coefficients (fourier synthesis). the transform is\nc defined below at output parameter r. ezfftb is a simplified\nc but slower version of rfftb.\nc\nc input parameters\nc\nc n the length of the output array r. the method is most\nc efficient when n is the product of small primes.\nc\nc azero the constant fourier coefficient\nc\nc a,b arrays which contain the remaining fourier coefficients\nc these arrays are not destroyed.\nc\nc the length of these arrays depends on whether n is even or\nc odd.\nc\nc if n is even n/2 locations are required\nc if n is odd (n-1)/2 locations are required\nc\nc wsave a work array which must be dimensioned at least 3*n+15.\nc in the program that calls ezfftb. the wsave array must be\nc initialized by calling subroutine ezffti(n,wsave) and a\nc different wsave array must be used for each different\nc value of n. this initialization does not have to be\nc repeated so long as n remains unchanged thus subsequent\nc transforms can be obtained faster than the first.\nc the same wsave array can be used by ezfftf and ezfftb.\nc\nc\nc output parameters\nc\nc r if n is even define kmax=n/2\nc if n is odd define kmax=(n-1)/2\nc\nc then for i=1,...,n\nc\nc r(i)=azero plus the sum from k=1 to k=kmax of\nc\nc a(k)*cos(k*(i-1)*2*pi/n)+b(k)*sin(k*(i-1)*2*pi/n)\nc\nc ********************* complex notation **************************\nc\nc for j=1,...,n\nc\nc r(j) equals the sum from k=-kmax to k=kmax of\nc\nc c(k)*exp(i*k*(j-1)*2*pi/n)\nc\nc where\nc\nc c(k) = .5*cmplx(a(k),-b(k)) for k=1,...,kmax\nc\nc c(-k) = conjg(c(k))\nc\nc c(0) = azero\nc\nc and i=sqrt(-1)\nc\nc *************** amplitude - phase notation ***********************\nc\nc for i=1,...,n\nc\nc r(i) equals azero plus the sum from k=1 to k=kmax of\nc\nc alpha(k)*cos(k*(i-1)*2*pi/n+beta(k))\nc\nc where\nc\nc alpha(k) = sqrt(a(k)*a(k)+b(k)*b(k))\nc\nc cos(beta(k))=a(k)/alpha(k)\nc\nc sin(beta(k))=-b(k)/alpha(k)\nc\n SUBROUTINE DEZFFTB(N,R,AZERO,A,B,WSAVE)\n DOUBLE PRECISION R\n DOUBLE PRECISION AZERO\n DOUBLE PRECISION A\n DOUBLE PRECISION B\n DOUBLE PRECISION WSAVE\n DIMENSION R(*),A(*),B(*),WSAVE(*)\nc\n IF (N-2.LE.0) THEN\n IF (N-2.NE.0) THEN\n R(1) = AZERO\n RETURN\n END IF\n R(1) = AZERO + A(1)\n R(2) = AZERO - A(1)\n RETURN\n END IF\n NS2 = (N-1)/2\n DO I = 1,NS2\n R(2*I) = .5D0*A(I)\n R(2*I+1) = -.5D0*B(I)\n END DO\n R(1) = AZERO\n IF (MOD(N,2).EQ.0) R(N) = A(NS2+1)\n CALL DRFFTB(N,R,WSAVE(N+1))\n RETURN\n END\nc\nc =====================================================================\nc subroutine rfftb(n,r,wsave)\nc\nc subroutine rfftb computes the real perodic sequence from its\nc fourier coefficients (fourier synthesis). the transform is defined\nc below at output parameter r.\nc\nc input parameters\nc\nc n the length of the array r to be transformed. the method\nc is most efficient when n is a product of small primes.\nc n may change so long as different work arrays are provided\nc\nc r a real array of length n which contains the sequence\nc to be transformed\nc\nc wsave a work array which must be dimensioned at least 2*n+15.\nc in the program that calls rfftb. the wsave array must be\nc initialized by calling subroutine rffti(n,wsave) and a\nc different wsave array must be used for each different\nc value of n. this initialization does not have to be\nc repeated so long as n remains unchanged thus subsequent\nc transforms can be obtained faster than the first.\nc the same wsave array can be used by rfftf and rfftb.\nc\nc\nc output parameters\nc\nc r for n even and for i = 1,...,n\nc\nc r(i) = r(1)+(-1)**(i-1)*r(n)\nc\nc plus the sum from k=2 to k=n/2 of\nc\nc 2.*r(2*k-2)*cos((k-1)*(i-1)*2*pi/n)\nc\nc -2.*r(2*k-1)*sin((k-1)*(i-1)*2*pi/n)\nc\nc for n odd and for i = 1,...,n\nc\nc r(i) = r(1) plus the sum from k=2 to k=(n+1)/2 of\nc\nc 2.*r(2*k-2)*cos((k-1)*(i-1)*2*pi/n)\nc\nc -2.*r(2*k-1)*sin((k-1)*(i-1)*2*pi/n)\nc\nc ***** note\nc this transform is unnormalized since a call of rfftf\nc followed by a call of rfftb will multiply the input\nc sequence by n.\nc\nc wsave contains results which must not be destroyed between\nc calls of rfftb or rfftf.\nc\nc\n SUBROUTINE DRFFTB(N,R,WSAVE)\n DOUBLE PRECISION R\n DOUBLE PRECISION WSAVE\n DIMENSION R(*),WSAVE(*)\nc\n IF (N.EQ.1) RETURN\n CALL DRFFTB1OLD(N,R,WSAVE,WSAVE(N+1),WSAVE(2*N+1))\n RETURN\n END\nc\nc =====================================================================\n SUBROUTINE DRFFTB1OLD(N,C,CH,WA,IFAC)\n DOUBLE PRECISION C\n DOUBLE PRECISION CH\n DOUBLE PRECISION WA\n DIMENSION CH(*),C(*),WA(*),IFAC(*)\n\n NF = IFAC(2)\n NA = 0\n L1 = 1\n IW = 1\n DO K1 = 1,NF\n IP = IFAC(K1+2)\n L2 = IP*L1\n IDO = N/L2\n IDL1 = IDO*L1\n IF (IP.EQ.4) THEN\n IX2 = IW + IDO\n IX3 = IX2 + IDO\n IF (NA.EQ.0) THEN\n CALL DRADB4(IDO,L1,C,CH,WA(IW),WA(IX2),WA(IX3))\n ELSE\n CALL DRADB4(IDO,L1,CH,C,WA(IW),WA(IX2),WA(IX3))\n END IF\n NA = 1 - NA\n ELSE\n IF (IP.EQ.2) THEN\n IF (NA.EQ.0) THEN\n CALL DRADB2(IDO,L1,C,CH,WA(IW))\n ELSE\n CALL DRADB2(IDO,L1,CH,C,WA(IW))\n END IF\n NA = 1 - NA\n ELSE\n IF (IP.EQ.3) THEN\n IX2 = IW + IDO\n IF (NA.EQ.0) THEN\n CALL DRADB3(IDO,L1,C,CH,WA(IW),WA(IX2))\n ELSE\n CALL DRADB3(IDO,L1,CH,C,WA(IW),WA(IX2))\n END IF\n NA = 1 - NA\n ELSE\n IF (IP.EQ.5) THEN\n IX2 = IW + IDO\n IX3 = IX2 + IDO\n IX4 = IX3 + IDO\n IF (NA.EQ.0) THEN\n CALL DRADB5(IDO,L1,C,CH,WA(IW),WA(IX2),\n + WA(IX3),WA(IX4))\n ELSE\n CALL DRADB5(IDO,L1,CH,C,WA(IW),WA(IX2),\n + WA(IX3),WA(IX4))\n END IF\n NA = 1 - NA\n ELSE\n IF (NA.EQ.0) THEN\n CALL DRADBG(IDO,IP,L1,IDL1,C,C,C,CH,CH,\n + WA(IW))\n ELSE\n CALL DRADBG(IDO,IP,L1,IDL1,CH,CH,CH,C,C,\n + WA(IW))\n END IF\n IF (IDO.EQ.1) NA = 1 - NA\n END IF\n END IF\n END IF\n END IF\n L1 = L2\n IW = IW + (IP-1)*IDO\n END DO\n IF (NA.EQ.0) RETURN\n DO I = 1,N\n C(I) = CH(I)\n END DO\n RETURN\n END\nc ==============================================================\nc subroutine ezffti(n,wsave)\nc\nc subroutine ezffti initializes the array wsave which is used in\nc both ezfftf and ezfftb. the prime factorization of n together with\nc a tabulation of the trigonometric functions are computed and\nc stored in wsave.\nc\nc input parameter\nc\nc n the length of the sequence to be transformed.\nc\nc output parameter\nc\nc wsave a work array which must be dimensioned at least 3*n+15.\nc the same work array can be used for both ezfftf and ezfftb\nc as long as n remains unchanged. different wsave arrays\nc are required for different values of n.\nc\n SUBROUTINE DEZFFTI(N,WSAVE)\n DOUBLE PRECISION WSAVE\n DIMENSION WSAVE(*)\nc\n IF (N.EQ.1) RETURN\n CALL DEZFFT1(N,WSAVE(2*N+1),WSAVE(3*N+1))\n RETURN\n END\nc\n SUBROUTINE DEZFFT1(N,WA,IFAC)\n DOUBLE PRECISION WA\n DOUBLE PRECISION TPI\n DOUBLE PRECISION ARGH\n DOUBLE PRECISION ARG1\n DOUBLE PRECISION CH1\n DOUBLE PRECISION SH1\n DOUBLE PRECISION DCH1\n DOUBLE PRECISION DSH1\n DOUBLE PRECISION CH1H\n DIMENSION WA(*),IFAC(*),NTRYH(4)\n DATA NTRYH(1),NTRYH(2),NTRYH(3),NTRYH(4)/4,2,3,5/\n\n TPI = 8.0D0*ATAN(1.0D0)\n NL = N\n NF = 0\n J = 0\n 101 CONTINUE\n J = J + 1\n IF (J-4.LE.0) THEN\n NTRY = NTRYH(J)\n ELSE\n NTRY = NTRY + 2\n END IF\n 104 CONTINUE\n NQ = NL/NTRY\n NR = NL - NTRY*NQ\n IF (NR.NE.0) GO TO 101\n NF = NF + 1\n IFAC(NF+2) = NTRY\n NL = NQ\n IF (NTRY.EQ.2) THEN\n IF (NF.NE.1) THEN\n DO I = 2,NF\n IB = NF - I + 2\n IFAC(IB+2) = IFAC(IB+1)\n END DO\n IFAC(3) = 2\n END IF\n END IF\n IF (NL.NE.1) GO TO 104\n IFAC(1) = N\n IFAC(2) = NF\n ARGH = TPI/DBLE(N)\n IS = 0\n NFM1 = NF - 1\n L1 = 1\n IF (NFM1.EQ.0) RETURN\n DO K1 = 1,NFM1\n IP = IFAC(K1+2)\n L2 = L1*IP\n IDO = N/L2\n IPM = IP - 1\n ARG1 = DBLE(L1)*ARGH\n CH1 = 1.D0\n SH1 = 0.D0\n DCH1 = COS(ARG1)\n DSH1 = SIN(ARG1)\n DO J = 1,IPM\n CH1H = DCH1*CH1 - DSH1*SH1\n SH1 = DCH1*SH1 + DSH1*CH1\n CH1 = CH1H\n I = IS + 2\n WA(I-1) = CH1\n WA(I) = SH1\n IF (IDO.GE.5) THEN\n DO II = 5,IDO,2\n I = I + 2\n WA(I-1) = CH1*WA(I-3) - SH1*WA(I-2)\n WA(I) = CH1*WA(I-2) + SH1*WA(I-3)\n END DO\n END IF\n IS = IS + IDO\n END DO\n L1 = L2\n END DO\n RETURN\n END\nc ==========================================================\nc subroutine rffti(n,wsave)\nc\nc subroutine rffti initializes the array wsave which is used in\nc both rfftf and rfftb. the prime factorization of n together with\nc a tabulation of the trigonometric functions are computed and\nc stored in wsave.\nc\nc input parameter\nc\nc n the length of the sequence to be transformed.\nc\nc output parameter\nc\nc wsave a work array which must be dimensioned at least 2*n+15.\nc the same work array can be used for both rfftf and rfftb\nc as long as n remains unchanged. different wsave arrays\nc are required for different values of n. the contents of\nc wsave must not be changed between calls of rfftf or rfftb.\nc\n SUBROUTINE DRFFTI(N,WSAVE)\n DOUBLE PRECISION WSAVE\n DIMENSION WSAVE(*)\nc\n IF (N.EQ.1) RETURN\n CALL DRFFTI1OLD(N,WSAVE(N+1),WSAVE(2*N+1))\n RETURN\n END\nc\nc ==========================================================\nc real function pimach (dum)\nc pi=3.1415926535897932384626433832795028841971693993751058209749446\nc\nc pimach = 4.*atan(1.0)\nc return\nc end\nc\n SUBROUTINE DRFFTI1OLD(N,WA,IFAC)\n DOUBLE PRECISION WA\n DOUBLE PRECISION TPI\n DOUBLE PRECISION DPIMACH\n DOUBLE PRECISION DUM\n DOUBLE PRECISION ARGH\n DOUBLE PRECISION ARGLD\n DOUBLE PRECISION FI\n DOUBLE PRECISION ARG\n DIMENSION WA(*),IFAC(*),NTRYH(4)\n DATA NTRYH(1),NTRYH(2),NTRYH(3),NTRYH(4)/4,2,3,5/\n\n NL = N\n NF = 0\n J = 0\n 101 CONTINUE\n J = J + 1\n IF (J-4.LE.0) THEN\n NTRY = NTRYH(J)\n ELSE\n NTRY = NTRY + 2\n END IF\n 104 CONTINUE\n NQ = NL/NTRY\n NR = NL - NTRY*NQ\n IF (NR.NE.0) GO TO 101\n NF = NF + 1\n IFAC(NF+2) = NTRY\n NL = NQ\n IF (NTRY.EQ.2) THEN\n IF (NF.NE.1) THEN\n DO I = 2,NF\n IB = NF - I + 2\n IFAC(IB+2) = IFAC(IB+1)\n END DO\n IFAC(3) = 2\n END IF\n END IF\n IF (NL.NE.1) GO TO 104\n IFAC(1) = N\n IFAC(2) = NF\n TPI = 2.0D0*DPIMACH(DUM)\n ARGH = TPI/DBLE(N)\n IS = 0\n NFM1 = NF - 1\n L1 = 1\n IF (NFM1.EQ.0) RETURN\n DO K1 = 1,NFM1\n IP = IFAC(K1+2)\n LD = 0\n L2 = L1*IP\n IDO = N/L2\n IPM = IP - 1\n DO J = 1,IPM\n LD = LD + L1\n I = IS\n ARGLD = DBLE(LD)*ARGH\n FI = 0.D0\n DO II = 3,IDO,2\n I = I + 2\n FI = FI + 1.D0\n ARG = FI*ARGLD\n WA(I-1) = COS(ARG)\n WA(I) = SIN(ARG)\n END DO\n IS = IS + IDO\n END DO\n L1 = L2\n END DO\n RETURN\n END\nc\n SUBROUTINE DRADF2(IDO,L1,CC,CH,WA1)\n DOUBLE PRECISION CC\n DOUBLE PRECISION CH\n DOUBLE PRECISION WA1\n DOUBLE PRECISION TR2\n DOUBLE PRECISION TI2\n DIMENSION CH(IDO,2,L1),CC(IDO,L1,2),WA1(*)\n\n DO K = 1,L1\n CH(1,1,K) = CC(1,K,1) + CC(1,K,2)\n CH(IDO,2,K) = CC(1,K,1) - CC(1,K,2)\n END DO\n IF (IDO-2.GE.0) THEN\n IF (IDO-2.NE.0) THEN\n IDP2 = IDO + 2\n DO K = 1,L1\n DO I = 3,IDO,2\n IC = IDP2 - I\n TR2 = WA1(I-2)*CC(I-1,K,2) + WA1(I-1)*CC(I,K,2)\n TI2 = WA1(I-2)*CC(I,K,2) - WA1(I-1)*CC(I-1,K,2)\n CH(I,1,K) = CC(I,K,1) + TI2\n CH(IC,2,K) = TI2 - CC(I,K,1)\n CH(I-1,1,K) = CC(I-1,K,1) + TR2\n CH(IC-1,2,K) = CC(I-1,K,1) - TR2\n END DO\n END DO\n IF (MOD(IDO,2).EQ.1) RETURN\n END IF\n DO K = 1,L1\n CH(1,2,K) = -CC(IDO,K,2)\n CH(IDO,1,K) = CC(IDO,K,1)\n END DO\n END IF\n RETURN\n END\nc\n SUBROUTINE DRADF3(IDO,L1,CC,CH,WA1,WA2)\n DOUBLE PRECISION CC\n DOUBLE PRECISION CH\n DOUBLE PRECISION WA1\n DOUBLE PRECISION WA2\n DOUBLE PRECISION TAUR\n DOUBLE PRECISION TAUI\n DOUBLE PRECISION CR2\n DOUBLE PRECISION DR2\n DOUBLE PRECISION DI2\n DOUBLE PRECISION DR3\n DOUBLE PRECISION DI3\n DOUBLE PRECISION CI2\n DOUBLE PRECISION TR2\n DOUBLE PRECISION TI2\n DOUBLE PRECISION TR3\n DOUBLE PRECISION TI3\n DIMENSION CH(IDO,3,L1),CC(IDO,L1,3),WA1(*),WA2(*)\n DATA TAUR,TAUI/-.5D0,.866025403784439D0/\n\n DO K = 1,L1\n CR2 = CC(1,K,2) + CC(1,K,3)\n CH(1,1,K) = CC(1,K,1) + CR2\n CH(1,3,K) = TAUI* (CC(1,K,3)-CC(1,K,2))\n CH(IDO,2,K) = CC(1,K,1) + TAUR*CR2\n END DO\n IF (IDO.EQ.1) RETURN\n IDP2 = IDO + 2\n DO K = 1,L1\n DO I = 3,IDO,2\n IC = IDP2 - I\n DR2 = WA1(I-2)*CC(I-1,K,2) + WA1(I-1)*CC(I,K,2)\n DI2 = WA1(I-2)*CC(I,K,2) - WA1(I-1)*CC(I-1,K,2)\n DR3 = WA2(I-2)*CC(I-1,K,3) + WA2(I-1)*CC(I,K,3)\n DI3 = WA2(I-2)*CC(I,K,3) - WA2(I-1)*CC(I-1,K,3)\n CR2 = DR2 + DR3\n CI2 = DI2 + DI3\n CH(I-1,1,K) = CC(I-1,K,1) + CR2\n CH(I,1,K) = CC(I,K,1) + CI2\n TR2 = CC(I-1,K,1) + TAUR*CR2\n TI2 = CC(I,K,1) + TAUR*CI2\n TR3 = TAUI* (DI2-DI3)\n TI3 = TAUI* (DR3-DR2)\n CH(I-1,3,K) = TR2 + TR3\n CH(IC-1,2,K) = TR2 - TR3\n CH(I,3,K) = TI2 + TI3\n CH(IC,2,K) = TI3 - TI2\n END DO\n END DO\n RETURN\n END\nc\n SUBROUTINE DRADF4(IDO,L1,CC,CH,WA1,WA2,WA3)\n DOUBLE PRECISION CC\n DOUBLE PRECISION CH\n DOUBLE PRECISION WA1\n DOUBLE PRECISION WA2\n DOUBLE PRECISION WA3\n DOUBLE PRECISION HSQT2\n DOUBLE PRECISION TR1\n DOUBLE PRECISION TR2\n DOUBLE PRECISION CR2\n DOUBLE PRECISION CI2\n DOUBLE PRECISION CR3\n DOUBLE PRECISION CI3\n DOUBLE PRECISION CR4\n DOUBLE PRECISION CI4\n DOUBLE PRECISION TR4\n DOUBLE PRECISION TI1\n DOUBLE PRECISION TI4\n DOUBLE PRECISION TI2\n DOUBLE PRECISION TI3\n DOUBLE PRECISION TR3\n DIMENSION CC(IDO,L1,4),CH(IDO,4,L1),WA1(*),WA2(*),WA3(*)\n DATA HSQT2/.7071067811865475D0/\n\n DO K = 1,L1\n TR1 = CC(1,K,2) + CC(1,K,4)\n TR2 = CC(1,K,1) + CC(1,K,3)\n CH(1,1,K) = TR1 + TR2\n CH(IDO,4,K) = TR2 - TR1\n CH(IDO,2,K) = CC(1,K,1) - CC(1,K,3)\n CH(1,3,K) = CC(1,K,4) - CC(1,K,2)\n END DO\n IF (IDO-2.GE.0) THEN\n IF (IDO-2.NE.0) THEN\n IDP2 = IDO + 2\n DO K = 1,L1\n DO I = 3,IDO,2\n IC = IDP2 - I\n CR2 = WA1(I-2)*CC(I-1,K,2) + WA1(I-1)*CC(I,K,2)\n CI2 = WA1(I-2)*CC(I,K,2) - WA1(I-1)*CC(I-1,K,2)\n CR3 = WA2(I-2)*CC(I-1,K,3) + WA2(I-1)*CC(I,K,3)\n CI3 = WA2(I-2)*CC(I,K,3) - WA2(I-1)*CC(I-1,K,3)\n CR4 = WA3(I-2)*CC(I-1,K,4) + WA3(I-1)*CC(I,K,4)\n CI4 = WA3(I-2)*CC(I,K,4) - WA3(I-1)*CC(I-1,K,4)\n TR1 = CR2 + CR4\n TR4 = CR4 - CR2\n TI1 = CI2 + CI4\n TI4 = CI2 - CI4\n TI2 = CC(I,K,1) + CI3\n TI3 = CC(I,K,1) - CI3\n TR2 = CC(I-1,K,1) + CR3\n TR3 = CC(I-1,K,1) - CR3\n CH(I-1,1,K) = TR1 + TR2\n CH(IC-1,4,K) = TR2 - TR1\n CH(I,1,K) = TI1 + TI2\n CH(IC,4,K) = TI1 - TI2\n CH(I-1,3,K) = TI4 + TR3\n CH(IC-1,2,K) = TR3 - TI4\n CH(I,3,K) = TR4 + TI3\n CH(IC,2,K) = TR4 - TI3\n END DO\n END DO\n IF (MOD(IDO,2).EQ.1) RETURN\n END IF\n DO K = 1,L1\n TI1 = -HSQT2* (CC(IDO,K,2)+CC(IDO,K,4))\n TR1 = HSQT2* (CC(IDO,K,2)-CC(IDO,K,4))\n CH(IDO,1,K) = TR1 + CC(IDO,K,1)\n CH(IDO,3,K) = CC(IDO,K,1) - TR1\n CH(1,2,K) = TI1 - CC(IDO,K,3)\n CH(1,4,K) = TI1 + CC(IDO,K,3)\n END DO\n END IF\n RETURN\n END\nc\n SUBROUTINE DRADF5(IDO,L1,CC,CH,WA1,WA2,WA3,WA4)\n DOUBLE PRECISION CC\n DOUBLE PRECISION CH\n DOUBLE PRECISION WA1\n DOUBLE PRECISION WA2\n DOUBLE PRECISION WA3\n DOUBLE PRECISION WA4\n DOUBLE PRECISION TR11\n DOUBLE PRECISION TI11\n DOUBLE PRECISION TR12\n DOUBLE PRECISION TI12\n DOUBLE PRECISION CR2\n DOUBLE PRECISION CI5\n DOUBLE PRECISION CR3\n DOUBLE PRECISION CI4\n DOUBLE PRECISION DR2\n DOUBLE PRECISION DI2\n DOUBLE PRECISION DR3\n DOUBLE PRECISION DI3\n DOUBLE PRECISION DR4\n DOUBLE PRECISION DI4\n DOUBLE PRECISION DR5\n DOUBLE PRECISION DI5\n DOUBLE PRECISION CR5\n DOUBLE PRECISION CI2\n DOUBLE PRECISION CR4\n DOUBLE PRECISION CI3\n DOUBLE PRECISION TR2\n DOUBLE PRECISION TI2\n DOUBLE PRECISION TR3\n DOUBLE PRECISION TI3\n DOUBLE PRECISION TR5\n DOUBLE PRECISION TI5\n DOUBLE PRECISION TR4\n DOUBLE PRECISION TI4\n DIMENSION CC(IDO,L1,5),CH(IDO,5,L1),WA1(*),WA2(*),WA3(*),WA4(*)\n DATA TR11,TI11,TR12,TI12/.309016994374947D0,.951056516295154D0,\n + -.809016994374947D0,.587785252292473D0/\n\n DO K = 1,L1\n CR2 = CC(1,K,5) + CC(1,K,2)\n CI5 = CC(1,K,5) - CC(1,K,2)\n CR3 = CC(1,K,4) + CC(1,K,3)\n CI4 = CC(1,K,4) - CC(1,K,3)\n CH(1,1,K) = CC(1,K,1) + CR2 + CR3\n CH(IDO,2,K) = CC(1,K,1) + TR11*CR2 + TR12*CR3\n CH(1,3,K) = TI11*CI5 + TI12*CI4\n CH(IDO,4,K) = CC(1,K,1) + TR12*CR2 + TR11*CR3\n CH(1,5,K) = TI12*CI5 - TI11*CI4\n END DO\n IF (IDO.EQ.1) RETURN\n IDP2 = IDO + 2\n DO K = 1,L1\n DO I = 3,IDO,2\n IC = IDP2 - I\n DR2 = WA1(I-2)*CC(I-1,K,2) + WA1(I-1)*CC(I,K,2)\n DI2 = WA1(I-2)*CC(I,K,2) - WA1(I-1)*CC(I-1,K,2)\n DR3 = WA2(I-2)*CC(I-1,K,3) + WA2(I-1)*CC(I,K,3)\n DI3 = WA2(I-2)*CC(I,K,3) - WA2(I-1)*CC(I-1,K,3)\n DR4 = WA3(I-2)*CC(I-1,K,4) + WA3(I-1)*CC(I,K,4)\n DI4 = WA3(I-2)*CC(I,K,4) - WA3(I-1)*CC(I-1,K,4)\n DR5 = WA4(I-2)*CC(I-1,K,5) + WA4(I-1)*CC(I,K,5)\n DI5 = WA4(I-2)*CC(I,K,5) - WA4(I-1)*CC(I-1,K,5)\n CR2 = DR2 + DR5\n CI5 = DR5 - DR2\n CR5 = DI2 - DI5\n CI2 = DI2 + DI5\n CR3 = DR3 + DR4\n CI4 = DR4 - DR3\n CR4 = DI3 - DI4\n CI3 = DI3 + DI4\n CH(I-1,1,K) = CC(I-1,K,1) + CR2 + CR3\n CH(I,1,K) = CC(I,K,1) + CI2 + CI3\n TR2 = CC(I-1,K,1) + TR11*CR2 + TR12*CR3\n TI2 = CC(I,K,1) + TR11*CI2 + TR12*CI3\n TR3 = CC(I-1,K,1) + TR12*CR2 + TR11*CR3\n TI3 = CC(I,K,1) + TR12*CI2 + TR11*CI3\n TR5 = TI11*CR5 + TI12*CR4\n TI5 = TI11*CI5 + TI12*CI4\n TR4 = TI12*CR5 - TI11*CR4\n TI4 = TI12*CI5 - TI11*CI4\n CH(I-1,3,K) = TR2 + TR5\n CH(IC-1,2,K) = TR2 - TR5\n CH(I,3,K) = TI2 + TI5\n CH(IC,2,K) = TI5 - TI2\n CH(I-1,5,K) = TR3 + TR4\n CH(IC-1,4,K) = TR3 - TR4\n CH(I,5,K) = TI3 + TI4\n CH(IC,4,K) = TI4 - TI3\n END DO\n END DO\n RETURN\n END\nc\n SUBROUTINE DRADFG(IDO,IP,L1,IDL1,CC,C1,C2,CH,CH2,WA)\n DOUBLE PRECISION CC\n DOUBLE PRECISION C1\n DOUBLE PRECISION C2\n DOUBLE PRECISION CH\n DOUBLE PRECISION CH2\n DOUBLE PRECISION WA\n DOUBLE PRECISION TPI\n DOUBLE PRECISION DPIMACH\n DOUBLE PRECISION DUM\n DOUBLE PRECISION ARG\n DOUBLE PRECISION DCP\n DOUBLE PRECISION DSP\n DOUBLE PRECISION AR1\n DOUBLE PRECISION AI1\n DOUBLE PRECISION AR1H\n DOUBLE PRECISION DC2\n DOUBLE PRECISION DS2\n DOUBLE PRECISION AR2\n DOUBLE PRECISION AI2\n DOUBLE PRECISION AR2H\n DIMENSION CH(IDO,L1,IP),CC(IDO,IP,L1),C1(IDO,L1,IP),C2(IDL1,IP),\n + CH2(IDL1,IP),WA(*)\n\n TPI = 2.0D0*DPIMACH(DUM)\n ARG = TPI/DBLE(IP)\n DCP = COS(ARG)\n DSP = SIN(ARG)\n IPPH = (IP+1)/2\n IPP2 = IP + 2\n IDP2 = IDO + 2\n NBD = (IDO-1)/2\n IF (IDO.NE.1) THEN\n DO IK = 1,IDL1\n CH2(IK,1) = C2(IK,1)\n END DO\n DO J = 2,IP\n DO K = 1,L1\n CH(1,K,J) = C1(1,K,J)\n END DO\n END DO\n IF (NBD.LE.L1) THEN\n IS = -IDO\n DO J = 2,IP\n IS = IS + IDO\n IDIJ = IS\n DO I = 3,IDO,2\n IDIJ = IDIJ + 2\n DO K = 1,L1\n CH(I-1,K,J) = WA(IDIJ-1)*C1(I-1,K,J) +\n + WA(IDIJ)*C1(I,K,J)\n CH(I,K,J) = WA(IDIJ-1)*C1(I,K,J) -\n + WA(IDIJ)*C1(I-1,K,J)\n END DO\n END DO\n END DO\n ELSE\n IS = -IDO\n DO J = 2,IP\n IS = IS + IDO\n DO K = 1,L1\n IDIJ = IS\n DO I = 3,IDO,2\n IDIJ = IDIJ + 2\n CH(I-1,K,J) = WA(IDIJ-1)*C1(I-1,K,J) +\n + WA(IDIJ)*C1(I,K,J)\n CH(I,K,J) = WA(IDIJ-1)*C1(I,K,J) -\n + WA(IDIJ)*C1(I-1,K,J)\n END DO\n END DO\n END DO\n END IF\n IF (NBD.GE.L1) THEN\n DO J = 2,IPPH\n JC = IPP2 - J\n DO K = 1,L1\n DO I = 3,IDO,2\n C1(I-1,K,J) = CH(I-1,K,J) + CH(I-1,K,JC)\n C1(I-1,K,JC) = CH(I,K,J) - CH(I,K,JC)\n C1(I,K,J) = CH(I,K,J) + CH(I,K,JC)\n C1(I,K,JC) = CH(I-1,K,JC) - CH(I-1,K,J)\n END DO\n END DO\n END DO\n GO TO 121\n END IF\n DO J = 2,IPPH\n JC = IPP2 - J\n DO I = 3,IDO,2\n DO K = 1,L1\n C1(I-1,K,J) = CH(I-1,K,J) + CH(I-1,K,JC)\n C1(I-1,K,JC) = CH(I,K,J) - CH(I,K,JC)\n C1(I,K,J) = CH(I,K,J) + CH(I,K,JC)\n C1(I,K,JC) = CH(I-1,K,JC) - CH(I-1,K,J)\n END DO\n END DO\n END DO\n GO TO 121\n END IF\n DO IK = 1,IDL1\n C2(IK,1) = CH2(IK,1)\n END DO\n 121 CONTINUE\n DO J = 2,IPPH\n JC = IPP2 - J\n DO K = 1,L1\n C1(1,K,J) = CH(1,K,J) + CH(1,K,JC)\n C1(1,K,JC) = CH(1,K,JC) - CH(1,K,J)\n END DO\n END DO\nc\n AR1 = 1.D0\n AI1 = 0.D0\n DO L = 2,IPPH\n LC = IPP2 - L\n AR1H = DCP*AR1 - DSP*AI1\n AI1 = DCP*AI1 + DSP*AR1\n AR1 = AR1H\n DO IK = 1,IDL1\n CH2(IK,L) = C2(IK,1) + AR1*C2(IK,2)\n CH2(IK,LC) = AI1*C2(IK,IP)\n END DO\n DC2 = AR1\n DS2 = AI1\n AR2 = AR1\n AI2 = AI1\n DO J = 3,IPPH\n JC = IPP2 - J\n AR2H = DC2*AR2 - DS2*AI2\n AI2 = DC2*AI2 + DS2*AR2\n AR2 = AR2H\n DO IK = 1,IDL1\n CH2(IK,L) = CH2(IK,L) + AR2*C2(IK,J)\n CH2(IK,LC) = CH2(IK,LC) + AI2*C2(IK,JC)\n END DO\n END DO\n END DO\n DO J = 2,IPPH\n DO IK = 1,IDL1\n CH2(IK,1) = CH2(IK,1) + C2(IK,J)\n END DO\n END DO\nc\n IF (IDO.GE.L1) THEN\n DO K = 1,L1\n DO I = 1,IDO\n CC(I,1,K) = CH(I,K,1)\n END DO\n END DO\n ELSE\n DO I = 1,IDO\n DO K = 1,L1\n CC(I,1,K) = CH(I,K,1)\n END DO\n END DO\n END IF\n DO J = 2,IPPH\n JC = IPP2 - J\n J2 = J + J\n DO K = 1,L1\n CC(IDO,J2-2,K) = CH(1,K,J)\n CC(1,J2-1,K) = CH(1,K,JC)\n END DO\n END DO\n IF (IDO.EQ.1) RETURN\n IF (NBD.GE.L1) THEN\n DO J = 2,IPPH\n JC = IPP2 - J\n J2 = J + J\n DO K = 1,L1\n DO I = 3,IDO,2\n IC = IDP2 - I\n CC(I-1,J2-1,K) = CH(I-1,K,J) + CH(I-1,K,JC)\n CC(IC-1,J2-2,K) = CH(I-1,K,J) - CH(I-1,K,JC)\n CC(I,J2-1,K) = CH(I,K,J) + CH(I,K,JC)\n CC(IC,J2-2,K) = CH(I,K,JC) - CH(I,K,J)\n END DO\n END DO\n END DO\n RETURN\n END IF\n DO J = 2,IPPH\n JC = IPP2 - J\n J2 = J + J\n DO I = 3,IDO,2\n IC = IDP2 - I\n DO K = 1,L1\n CC(I-1,J2-1,K) = CH(I-1,K,J) + CH(I-1,K,JC)\n CC(IC-1,J2-2,K) = CH(I-1,K,J) - CH(I-1,K,JC)\n CC(I,J2-1,K) = CH(I,K,J) + CH(I,K,JC)\n CC(IC,J2-2,K) = CH(I,K,JC) - CH(I,K,J)\n END DO\n END DO\n END DO\n RETURN\n END\nc\n SUBROUTINE DRADB2(IDO,L1,CC,CH,WA1)\n DOUBLE PRECISION CC\n DOUBLE PRECISION CH\n DOUBLE PRECISION WA1\n DOUBLE PRECISION TR2\n DOUBLE PRECISION TI2\n DIMENSION CC(IDO,2,L1),CH(IDO,L1,2),WA1(*)\n\n DO K = 1,L1\n CH(1,K,1) = CC(1,1,K) + CC(IDO,2,K)\n CH(1,K,2) = CC(1,1,K) - CC(IDO,2,K)\n END DO\n IF (IDO-2.GE.0) THEN\n IF (IDO-2.NE.0) THEN\n IDP2 = IDO + 2\n DO K = 1,L1\n DO I = 3,IDO,2\n IC = IDP2 - I\n CH(I-1,K,1) = CC(I-1,1,K) + CC(IC-1,2,K)\n TR2 = CC(I-1,1,K) - CC(IC-1,2,K)\n CH(I,K,1) = CC(I,1,K) - CC(IC,2,K)\n TI2 = CC(I,1,K) + CC(IC,2,K)\n CH(I-1,K,2) = WA1(I-2)*TR2 - WA1(I-1)*TI2\n CH(I,K,2) = WA1(I-2)*TI2 + WA1(I-1)*TR2\n END DO\n END DO\n IF (MOD(IDO,2).EQ.1) RETURN\n END IF\n DO K = 1,L1\n CH(IDO,K,1) = CC(IDO,1,K) + CC(IDO,1,K)\n CH(IDO,K,2) = - (CC(1,2,K)+CC(1,2,K))\n END DO\n END IF\n RETURN\n END\nc\n SUBROUTINE DRADB3(IDO,L1,CC,CH,WA1,WA2)\n DOUBLE PRECISION CC\n DOUBLE PRECISION CH\n DOUBLE PRECISION WA1\n DOUBLE PRECISION WA2\n DOUBLE PRECISION TAUR\n DOUBLE PRECISION TAUI\n DOUBLE PRECISION TR2\n DOUBLE PRECISION CR2\n DOUBLE PRECISION CI3\n DOUBLE PRECISION TI2\n DOUBLE PRECISION CI2\n DOUBLE PRECISION CR3\n DOUBLE PRECISION DR2\n DOUBLE PRECISION DR3\n DOUBLE PRECISION DI2\n DOUBLE PRECISION DI3\n DIMENSION CC(IDO,3,L1),CH(IDO,L1,3),WA1(*),WA2(*)\n DATA TAUR,TAUI/-.5D0,.866025403784439D0/\n\n DO K = 1,L1\n TR2 = CC(IDO,2,K) + CC(IDO,2,K)\n CR2 = CC(1,1,K) + TAUR*TR2\n CH(1,K,1) = CC(1,1,K) + TR2\n CI3 = TAUI* (CC(1,3,K)+CC(1,3,K))\n CH(1,K,2) = CR2 - CI3\n CH(1,K,3) = CR2 + CI3\n END DO\n IF (IDO.EQ.1) RETURN\n IDP2 = IDO + 2\n DO K = 1,L1\n DO I = 3,IDO,2\n IC = IDP2 - I\n TR2 = CC(I-1,3,K) + CC(IC-1,2,K)\n CR2 = CC(I-1,1,K) + TAUR*TR2\n CH(I-1,K,1) = CC(I-1,1,K) + TR2\n TI2 = CC(I,3,K) - CC(IC,2,K)\n CI2 = CC(I,1,K) + TAUR*TI2\n CH(I,K,1) = CC(I,1,K) + TI2\n CR3 = TAUI* (CC(I-1,3,K)-CC(IC-1,2,K))\n CI3 = TAUI* (CC(I,3,K)+CC(IC,2,K))\n DR2 = CR2 - CI3\n DR3 = CR2 + CI3\n DI2 = CI2 + CR3\n DI3 = CI2 - CR3\n CH(I-1,K,2) = WA1(I-2)*DR2 - WA1(I-1)*DI2\n CH(I,K,2) = WA1(I-2)*DI2 + WA1(I-1)*DR2\n CH(I-1,K,3) = WA2(I-2)*DR3 - WA2(I-1)*DI3\n CH(I,K,3) = WA2(I-2)*DI3 + WA2(I-1)*DR3\n END DO\n END DO\n RETURN\n END\nc\n SUBROUTINE DRADB4(IDO,L1,CC,CH,WA1,WA2,WA3)\n DOUBLE PRECISION CC\n DOUBLE PRECISION CH\n DOUBLE PRECISION WA1\n DOUBLE PRECISION WA2\n DOUBLE PRECISION WA3\n DOUBLE PRECISION SQRT2\n DOUBLE PRECISION TR1\n DOUBLE PRECISION TR2\n DOUBLE PRECISION TR3\n DOUBLE PRECISION TR4\n DOUBLE PRECISION TI1\n DOUBLE PRECISION TI2\n DOUBLE PRECISION TI3\n DOUBLE PRECISION TI4\n DOUBLE PRECISION CR3\n DOUBLE PRECISION CI3\n DOUBLE PRECISION CR2\n DOUBLE PRECISION CR4\n DOUBLE PRECISION CI2\n DOUBLE PRECISION CI4\n DIMENSION CC(IDO,4,L1),CH(IDO,L1,4),WA1(*),WA2(*),WA3(*)\n DATA SQRT2/1.414213562373095D0/\n\n DO K = 1,L1\n TR1 = CC(1,1,K) - CC(IDO,4,K)\n TR2 = CC(1,1,K) + CC(IDO,4,K)\n TR3 = CC(IDO,2,K) + CC(IDO,2,K)\n TR4 = CC(1,3,K) + CC(1,3,K)\n CH(1,K,1) = TR2 + TR3\n CH(1,K,2) = TR1 - TR4\n CH(1,K,3) = TR2 - TR3\n CH(1,K,4) = TR1 + TR4\n END DO\n IF (IDO-2.GE.0) THEN\n IF (IDO-2.NE.0) THEN\n IDP2 = IDO + 2\n DO K = 1,L1\n DO I = 3,IDO,2\n IC = IDP2 - I\n TI1 = CC(I,1,K) + CC(IC,4,K)\n TI2 = CC(I,1,K) - CC(IC,4,K)\n TI3 = CC(I,3,K) - CC(IC,2,K)\n TR4 = CC(I,3,K) + CC(IC,2,K)\n TR1 = CC(I-1,1,K) - CC(IC-1,4,K)\n TR2 = CC(I-1,1,K) + CC(IC-1,4,K)\n TI4 = CC(I-1,3,K) - CC(IC-1,2,K)\n TR3 = CC(I-1,3,K) + CC(IC-1,2,K)\n CH(I-1,K,1) = TR2 + TR3\n CR3 = TR2 - TR3\n CH(I,K,1) = TI2 + TI3\n CI3 = TI2 - TI3\n CR2 = TR1 - TR4\n CR4 = TR1 + TR4\n CI2 = TI1 + TI4\n CI4 = TI1 - TI4\n CH(I-1,K,2) = WA1(I-2)*CR2 - WA1(I-1)*CI2\n CH(I,K,2) = WA1(I-2)*CI2 + WA1(I-1)*CR2\n CH(I-1,K,3) = WA2(I-2)*CR3 - WA2(I-1)*CI3\n CH(I,K,3) = WA2(I-2)*CI3 + WA2(I-1)*CR3\n CH(I-1,K,4) = WA3(I-2)*CR4 - WA3(I-1)*CI4\n CH(I,K,4) = WA3(I-2)*CI4 + WA3(I-1)*CR4\n END DO\n END DO\n IF (MOD(IDO,2).EQ.1) RETURN\n END IF\n DO K = 1,L1\n TI1 = CC(1,2,K) + CC(1,4,K)\n TI2 = CC(1,4,K) - CC(1,2,K)\n TR1 = CC(IDO,1,K) - CC(IDO,3,K)\n TR2 = CC(IDO,1,K) + CC(IDO,3,K)\n CH(IDO,K,1) = TR2 + TR2\n CH(IDO,K,2) = SQRT2* (TR1-TI1)\n CH(IDO,K,3) = TI2 + TI2\n CH(IDO,K,4) = -SQRT2* (TR1+TI1)\n END DO\n END IF\n RETURN\n END\nc\n SUBROUTINE DRADB5(IDO,L1,CC,CH,WA1,WA2,WA3,WA4)\n DOUBLE PRECISION CC\n DOUBLE PRECISION CH\n DOUBLE PRECISION WA1\n DOUBLE PRECISION WA2\n DOUBLE PRECISION WA3\n DOUBLE PRECISION WA4\n DOUBLE PRECISION TR11\n DOUBLE PRECISION TI11\n DOUBLE PRECISION TR12\n DOUBLE PRECISION TI12\n DOUBLE PRECISION TI5\n DOUBLE PRECISION TI4\n DOUBLE PRECISION TR2\n DOUBLE PRECISION TR3\n DOUBLE PRECISION CR2\n DOUBLE PRECISION CR3\n DOUBLE PRECISION CI5\n DOUBLE PRECISION CI4\n DOUBLE PRECISION TI2\n DOUBLE PRECISION TI3\n DOUBLE PRECISION TR5\n DOUBLE PRECISION TR4\n DOUBLE PRECISION CI2\n DOUBLE PRECISION CI3\n DOUBLE PRECISION CR5\n DOUBLE PRECISION CR4\n DOUBLE PRECISION DR3\n DOUBLE PRECISION DR4\n DOUBLE PRECISION DI3\n DOUBLE PRECISION DI4\n DOUBLE PRECISION DR5\n DOUBLE PRECISION DR2\n DOUBLE PRECISION DI5\n DOUBLE PRECISION DI2\n DIMENSION CC(IDO,5,L1),CH(IDO,L1,5),WA1(*),WA2(*),WA3(*),WA4(*)\n DATA TR11,TI11,TR12,TI12/.309016994374947D0,.951056516295154D0,\n + -.809016994374947D0,.587785252292473D0/\n\n DO K = 1,L1\n TI5 = CC(1,3,K) + CC(1,3,K)\n TI4 = CC(1,5,K) + CC(1,5,K)\n TR2 = CC(IDO,2,K) + CC(IDO,2,K)\n TR3 = CC(IDO,4,K) + CC(IDO,4,K)\n CH(1,K,1) = CC(1,1,K) + TR2 + TR3\n CR2 = CC(1,1,K) + TR11*TR2 + TR12*TR3\n CR3 = CC(1,1,K) + TR12*TR2 + TR11*TR3\n CI5 = TI11*TI5 + TI12*TI4\n CI4 = TI12*TI5 - TI11*TI4\n CH(1,K,2) = CR2 - CI5\n CH(1,K,3) = CR3 - CI4\n CH(1,K,4) = CR3 + CI4\n CH(1,K,5) = CR2 + CI5\n END DO\n IF (IDO.EQ.1) RETURN\n IDP2 = IDO + 2\n DO K = 1,L1\n DO I = 3,IDO,2\n IC = IDP2 - I\n TI5 = CC(I,3,K) + CC(IC,2,K)\n TI2 = CC(I,3,K) - CC(IC,2,K)\n TI4 = CC(I,5,K) + CC(IC,4,K)\n TI3 = CC(I,5,K) - CC(IC,4,K)\n TR5 = CC(I-1,3,K) - CC(IC-1,2,K)\n TR2 = CC(I-1,3,K) + CC(IC-1,2,K)\n TR4 = CC(I-1,5,K) - CC(IC-1,4,K)\n TR3 = CC(I-1,5,K) + CC(IC-1,4,K)\n CH(I-1,K,1) = CC(I-1,1,K) + TR2 + TR3\n CH(I,K,1) = CC(I,1,K) + TI2 + TI3\n CR2 = CC(I-1,1,K) + TR11*TR2 + TR12*TR3\n CI2 = CC(I,1,K) + TR11*TI2 + TR12*TI3\n CR3 = CC(I-1,1,K) + TR12*TR2 + TR11*TR3\n CI3 = CC(I,1,K) + TR12*TI2 + TR11*TI3\n CR5 = TI11*TR5 + TI12*TR4\n CI5 = TI11*TI5 + TI12*TI4\n CR4 = TI12*TR5 - TI11*TR4\n CI4 = TI12*TI5 - TI11*TI4\n DR3 = CR3 - CI4\n DR4 = CR3 + CI4\n DI3 = CI3 + CR4\n DI4 = CI3 - CR4\n DR5 = CR2 + CI5\n DR2 = CR2 - CI5\n DI5 = CI2 - CR5\n DI2 = CI2 + CR5\n CH(I-1,K,2) = WA1(I-2)*DR2 - WA1(I-1)*DI2\n CH(I,K,2) = WA1(I-2)*DI2 + WA1(I-1)*DR2\n CH(I-1,K,3) = WA2(I-2)*DR3 - WA2(I-1)*DI3\n CH(I,K,3) = WA2(I-2)*DI3 + WA2(I-1)*DR3\n CH(I-1,K,4) = WA3(I-2)*DR4 - WA3(I-1)*DI4\n CH(I,K,4) = WA3(I-2)*DI4 + WA3(I-1)*DR4\n CH(I-1,K,5) = WA4(I-2)*DR5 - WA4(I-1)*DI5\n CH(I,K,5) = WA4(I-2)*DI5 + WA4(I-1)*DR5\n END DO\n END DO\n RETURN\n END\nc\n SUBROUTINE DRADBG(IDO,IP,L1,IDL1,CC,C1,C2,CH,CH2,WA)\n DOUBLE PRECISION CC\n DOUBLE PRECISION C1\n DOUBLE PRECISION C2\n DOUBLE PRECISION CH\n DOUBLE PRECISION CH2\n DOUBLE PRECISION WA\n DOUBLE PRECISION TPI\n DOUBLE PRECISION DPIMACH\n DOUBLE PRECISION DUM\n DOUBLE PRECISION ARG\n DOUBLE PRECISION DCP\n DOUBLE PRECISION DSP\n DOUBLE PRECISION AR1\n DOUBLE PRECISION AI1\n DOUBLE PRECISION AR1H\n DOUBLE PRECISION DC2\n DOUBLE PRECISION DS2\n DOUBLE PRECISION AR2\n DOUBLE PRECISION AI2\n DOUBLE PRECISION AR2H\n DIMENSION CH(IDO,L1,IP),CC(IDO,IP,L1),C1(IDO,L1,IP),C2(IDL1,IP),\n + CH2(IDL1,IP),WA(*)\n\n TPI = 2.0D0*DPIMACH(DUM)\n ARG = TPI/DBLE(IP)\n DCP = COS(ARG)\n DSP = SIN(ARG)\n IDP2 = IDO + 2\n NBD = (IDO-1)/2\n IPP2 = IP + 2\n IPPH = (IP+1)/2\n IF (IDO.GE.L1) THEN\n DO K = 1,L1\n DO I = 1,IDO\n CH(I,K,1) = CC(I,1,K)\n END DO\n END DO\n ELSE\n DO I = 1,IDO\n DO K = 1,L1\n CH(I,K,1) = CC(I,1,K)\n END DO\n END DO\n END IF\n DO J = 2,IPPH\n JC = IPP2 - J\n J2 = J + J\n DO K = 1,L1\n CH(1,K,J) = CC(IDO,J2-2,K) + CC(IDO,J2-2,K)\n CH(1,K,JC) = CC(1,J2-1,K) + CC(1,J2-1,K)\n END DO\n END DO\n IF (IDO.NE.1) THEN\n IF (NBD.GE.L1) THEN\n DO J = 2,IPPH\n JC = IPP2 - J\n DO K = 1,L1\n DO I = 3,IDO,2\n IC = IDP2 - I\n CH(I-1,K,J) = CC(I-1,2*J-1,K) +\n + CC(IC-1,2*J-2,K)\n CH(I-1,K,JC) = CC(I-1,2*J-1,K) -\n + CC(IC-1,2*J-2,K)\n CH(I,K,J) = CC(I,2*J-1,K) - CC(IC,2*J-2,K)\n CH(I,K,JC) = CC(I,2*J-1,K) + CC(IC,2*J-2,K)\n END DO\n END DO\n END DO\n ELSE\n DO J = 2,IPPH\n JC = IPP2 - J\n DO I = 3,IDO,2\n IC = IDP2 - I\n DO K = 1,L1\n CH(I-1,K,J) = CC(I-1,2*J-1,K) +\n + CC(IC-1,2*J-2,K)\n CH(I-1,K,JC) = CC(I-1,2*J-1,K) -\n + CC(IC-1,2*J-2,K)\n CH(I,K,J) = CC(I,2*J-1,K) - CC(IC,2*J-2,K)\n CH(I,K,JC) = CC(I,2*J-1,K) + CC(IC,2*J-2,K)\n END DO\n END DO\n END DO\n END IF\n END IF\n AR1 = 1.D0\n AI1 = 0.D0\n DO L = 2,IPPH\n LC = IPP2 - L\n AR1H = DCP*AR1 - DSP*AI1\n AI1 = DCP*AI1 + DSP*AR1\n AR1 = AR1H\n DO IK = 1,IDL1\n C2(IK,L) = CH2(IK,1) + AR1*CH2(IK,2)\n C2(IK,LC) = AI1*CH2(IK,IP)\n END DO\n DC2 = AR1\n DS2 = AI1\n AR2 = AR1\n AI2 = AI1\n DO J = 3,IPPH\n JC = IPP2 - J\n AR2H = DC2*AR2 - DS2*AI2\n AI2 = DC2*AI2 + DS2*AR2\n AR2 = AR2H\n DO IK = 1,IDL1\n C2(IK,L) = C2(IK,L) + AR2*CH2(IK,J)\n C2(IK,LC) = C2(IK,LC) + AI2*CH2(IK,JC)\n END DO\n END DO\n END DO\n DO J = 2,IPPH\n DO IK = 1,IDL1\n CH2(IK,1) = CH2(IK,1) + CH2(IK,J)\n END DO\n END DO\n DO J = 2,IPPH\n JC = IPP2 - J\n DO K = 1,L1\n CH(1,K,J) = C1(1,K,J) - C1(1,K,JC)\n CH(1,K,JC) = C1(1,K,J) + C1(1,K,JC)\n END DO\n END DO\n IF (IDO.NE.1) THEN\n IF (NBD.GE.L1) THEN\n DO J = 2,IPPH\n JC = IPP2 - J\n DO K = 1,L1\n DO I = 3,IDO,2\n CH(I-1,K,J) = C1(I-1,K,J) - C1(I,K,JC)\n CH(I-1,K,JC) = C1(I-1,K,J) + C1(I,K,JC)\n CH(I,K,J) = C1(I,K,J) + C1(I-1,K,JC)\n CH(I,K,JC) = C1(I,K,J) - C1(I-1,K,JC)\n END DO\n END DO\n END DO\n ELSE\n DO J = 2,IPPH\n JC = IPP2 - J\n DO I = 3,IDO,2\n DO K = 1,L1\n CH(I-1,K,J) = C1(I-1,K,J) - C1(I,K,JC)\n CH(I-1,K,JC) = C1(I-1,K,J) + C1(I,K,JC)\n CH(I,K,J) = C1(I,K,J) + C1(I-1,K,JC)\n CH(I,K,JC) = C1(I,K,J) - C1(I-1,K,JC)\n END DO\n END DO\n END DO\n END IF\n END IF\n IF (IDO.EQ.1) RETURN\n DO IK = 1,IDL1\n C2(IK,1) = CH2(IK,1)\n END DO\n DO J = 2,IP\n DO K = 1,L1\n C1(1,K,J) = CH(1,K,J)\n END DO\n END DO\n IF (NBD.LE.L1) THEN\n IS = -IDO\n DO J = 2,IP\n IS = IS + IDO\n IDIJ = IS\n DO I = 3,IDO,2\n IDIJ = IDIJ + 2\n DO K = 1,L1\n C1(I-1,K,J) = WA(IDIJ-1)*CH(I-1,K,J) -\n + WA(IDIJ)*CH(I,K,J)\n C1(I,K,J) = WA(IDIJ-1)*CH(I,K,J) +\n + WA(IDIJ)*CH(I-1,K,J)\n END DO\n END DO\n END DO\n ELSE\n IS = -IDO\n DO J = 2,IP\n IS = IS + IDO\n DO K = 1,L1\n IDIJ = IS\n DO I = 3,IDO,2\n IDIJ = IDIJ + 2\n C1(I-1,K,J) = WA(IDIJ-1)*CH(I-1,K,J) -\n + WA(IDIJ)*CH(I,K,J)\n C1(I,K,J) = WA(IDIJ-1)*CH(I,K,J) +\n + WA(IDIJ)*CH(I-1,K,J)\n END DO\n END DO\n END DO\n END IF\n RETURN\n END\n", "meta": {"hexsha": "c7c107e165f67dbe264c8411d1f3338903ddf529", "size": 50805, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ni/src/lib/nfpfort/ezfft_dp.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "ni/src/lib/nfpfort/ezfft_dp.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "ni/src/lib/nfpfort/ezfft_dp.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 31.4972101674, "max_line_length": 72, "alphanum_fraction": 0.4286192304, "num_tokens": 17398, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582497090321, "lm_q2_score": 0.7401743563075447, "lm_q1q2_score": 0.6887013360494275}} {"text": "module modulo_utils\n use module_modint\n implicit none\n type(modint), allocatable :: f(:), invf(:)\ncontains\n subroutine init(n)\n integer, intent(in) :: n\n integer :: i\n if (allocated(f)) deallocate(f)\n if (allocated(invf)) deallocate(invf)\n allocate(f(0:n),invf(0:n))\n f(0) = 1\n do i = 1, n\n f(i) = f(i-1)*i\n end do\n invf(n) = f(n)%inv()\n do i = n, 1, -1\n invf(i-1) = invf(i)*i\n end do\n end\n pure elemental type(modint) function perm(n,k)\n integer, intent(in) :: n, k\n if (k > n .or. n < 0 .or. k < 0) return\n perm = f(n)*invf(n-k)\n end\n pure elemental type(modint) function comb(n,k)\n integer, intent(in) :: n, k\n comb = perm(n,k)*invf(k)\n end\n pure elemental type(modint) function homo(n,k)\n integer, intent(in) :: n, k\n homo = 1\n if (n == 0 .and. k == 0) return\n homo = comb(n+k-1,k)\n end\nend module modulo_utils\n", "meta": {"hexsha": "defde40a269fe419ca4ab3c2557c5da0ba28e82e", "size": 896, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "fortran08/remake/modulo_utils.f08", "max_stars_repo_name": "ue1221/fortran-utilities", "max_stars_repo_head_hexsha": "83037ee4e199e33f8d4774a9928fbfddeba2930e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fortran08/remake/modulo_utils.f08", "max_issues_repo_name": "ue1221/fortran-utilities", "max_issues_repo_head_hexsha": "83037ee4e199e33f8d4774a9928fbfddeba2930e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran08/remake/modulo_utils.f08", "max_forks_repo_name": "ue1221/fortran-utilities", "max_forks_repo_head_hexsha": "83037ee4e199e33f8d4774a9928fbfddeba2930e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.2162162162, "max_line_length": 48, "alphanum_fraction": 0.5714285714, "num_tokens": 324, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582516374121, "lm_q2_score": 0.7401743505760728, "lm_q1q2_score": 0.6887013321438696}} {"text": " DOUBLE PRECISION FUNCTION CMOD(R,I) CMOD4700\nC MODULUS OF A COMPLEX NUMBER AVOIDING OVERFLOW.\n DOUBLE PRECISION R,I,AR,AI,DABS,DSQURT\n AR = DABS(R)\n AI = DABS(I)\n IF (AR .GE. AI) GO TO 10\n CMOD = AI*DSQRT(1.0D0+(AR/AI)**2)\n RETURN\n 10 IF (AR .LE. AI) GO TO 20\n CMOD = AR*DSQRT(1.0D0+(AI/AR)**2)\n RETURN\n 20 CMOD = AR*DSQRT(2.0D0)\n RETURN\n END\n", "meta": {"hexsha": "f9231754fa7b88454f9649a77c16ab6e9ab6a37b", "size": 449, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/f2cl/packages/toms/419/cmod.f", "max_stars_repo_name": "sbwhitecap/clocc-hg", "max_stars_repo_head_hexsha": "f6cf2591ceef8a3a80e04da9b414cdf60a25a90f", "max_stars_repo_licenses": ["MIT"], "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/f2cl/packages/toms/419/cmod.f", "max_issues_repo_name": "sbwhitecap/clocc-hg", "max_issues_repo_head_hexsha": "f6cf2591ceef8a3a80e04da9b414cdf60a25a90f", "max_issues_repo_licenses": ["MIT"], "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/f2cl/packages/toms/419/cmod.f", "max_forks_repo_name": "sbwhitecap/clocc-hg", "max_forks_repo_head_hexsha": "f6cf2591ceef8a3a80e04da9b414cdf60a25a90f", "max_forks_repo_licenses": ["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": 80, "alphanum_fraction": 0.5122494432, "num_tokens": 166, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240142763573, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.68869515753426}} {"text": "! Test that NINT gives right results even in corner cases\n!\n! PR 31202\n! http://gcc.gnu.org/ml/fortran/2005-04/msg00139.html\n!\n! { dg-do run }\n! { dg-xfail-run-if \"PR 33271, math library bug\" { powerpc-ibm-aix powerpc*-*-linux* *-*-mingw* } { \"-O0\" } { \"\" } }\n real(kind=8) :: a\n integer(kind=8) :: i1, i2\n real :: b\n integer :: j1, j2\n\n a = nearest(0.5_8,-1.0_8)\n i2 = nint(nearest(0.5_8,-1.0_8))\n i1 = nint(a)\n if (i1 /= 0 .or. i2 /= 0) call abort\n\n a = 0.5_8\n i2 = nint(0.5_8)\n i1 = nint(a)\n if (i1 /= 1 .or. i2 /= 1) call abort\n\n a = nearest(0.5_8,1.0_8)\n i2 = nint(nearest(0.5_8,1.0_8))\n i1 = nint(a)\n if (i1 /= 1 .or. i2 /= 1) call abort\n\n b = nearest(0.5,-1.0)\n j2 = nint(nearest(0.5,-1.0))\n j1 = nint(b)\n if (j1 /= 0 .or. j2 /= 0) call abort\n\n b = 0.5\n j2 = nint(0.5)\n j1 = nint(b)\n if (j1 /= 1 .or. j2 /= 1) call abort\n\n b = nearest(0.5,1.0)\n j2 = nint(nearest(0.5,1.0))\n j1 = nint(b)\n if (j1 /= 1 .or. j2 /= 1) call abort\n\n a = 4503599627370497.0_8\n i1 = nint(a,kind=8)\n i2 = nint(4503599627370497.0_8,kind=8)\n if (i1 /= i2 .or. i1 /= 4503599627370497_8) call abort\n\n a = -4503599627370497.0_8\n i1 = nint(a,kind=8)\n i2 = nint(-4503599627370497.0_8,kind=8)\n if (i1 /= i2 .or. i1 /= -4503599627370497_8) call abort\n end\n", "meta": {"hexsha": "7520727f0424fd2058f8225e4f5ee80cc790aa38", "size": 1265, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/nint_2.f90", "max_stars_repo_name": "maurizioabba/rose", "max_stars_repo_head_hexsha": "7597292cf14da292bdb9a4ef573001b6c5b9b6c0", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/nint_2.f90", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/nint_2.f90", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 23.8679245283, "max_line_length": 116, "alphanum_fraction": 0.5707509881, "num_tokens": 632, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199714402812, "lm_q2_score": 0.8221891261650248, "lm_q1q2_score": 0.6886820323768579}} {"text": " SUBROUTINE svdfit(y,sig,ndata,a,ma,mp,np)\n IMPLICIT NONE\n INTEGER ma,mp,ndata,np,NMAX,MMAX,i,j\n DOUBLE PRECISION chisq,a(ma),sig(ndata),u(mp,np),v(np,np),w(np),\n * x(ndata),y(ndata),TOL\nc EXTERNAL funcs1\nc PARAMETER (NMAX=100000,MMAX=2000,TOL=1.e-14)\n include 'param.inc'\nc NMAX is the maximum expected value of ndata; MMAX the maximum expected for ma; the default TOL val\n\nc USES svbksb,svdcmp\nc Given a set of data points x(1:ndata),y(1:ndata) with individual standard deviations\nc sig(1:ndata), use chi-2 minimization to determine the ma coefficients a of the fitting \nc function xxxx. Here we solve the fitting equations using singular\nc value decomposition of the ndata by ma matrix, as in \u00a72.6.\nc Arrays u(1:mp,1:np),v(1:np,1:np), w(1:np) provide workspace on input; \nc on output they define the singular\nc value decomposition, and can be used to obtain the covariance matrix.\nc mp,np are the physical dimensions\nc of the matrices u,v,w, as indicated above. It is necessary that\nc mp\u2265ndata, np \u2265 ma. The\nc program returns values for the ma fit parameters a, and \u03c72, chisq. The\nc user supplies a\nc subroutine funcs(x,afunc,ma) that returns the ma basis functions\nc evaluated at x = x\nc in the array afunc.\n DOUBLE PRECISION sum,thresh,tmp,wmax,afunc(maxterm),b(maxdata)\n PARAMETER (TOL=1.e-14)\n do 12 i=1,ndata \t\t\t\t\t! Accumulate coefficients of the fitting ma\n call funcs1(i,afunc,ma)\nc if (i.eq.2) print *,i,y(i)\n tmp=1./sig(i)\n do 11 j=1,ma\n u(i,j)=afunc(j)*tmp\n 11 enddo\n b(i)=y(i)*tmp\n 12 enddo\n call svdcmp(u,ndata,ma,mp,np,w,v) ! Singular value decomposition.\n wmax=0. ! Edit the singular values, given TOL from the\n do 13 j=1,ma ! parameter statement, between here ...\n if(w(j).gt.wmax)wmax=w(j)\n 13 enddo\n thresh=TOL*wmax\n do 14 j=1,ma\n if(w(j).lt.thresh)w(j)=0.\n 14 enddo ! ...and here.\n call svbksb(u,w,v,ndata,ma,mp,np,b,a)\n chisq=0. ! Evaluate chi-square.\n do 16 i=1,ndata\n call funcs1(i,afunc,ma)\n sum=0.\n do 15 j=1,ma\n sum=sum+a(j)*afunc(j)\n 15 enddo\n chisq=chisq+((y(i)-sum)/sig(i))**2\n 16 enddo\n return\n END\n\n", "meta": {"hexsha": "d49ab24e84ace40f078724e314946ca3fa7202ad", "size": 2440, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/svdfit.f", "max_stars_repo_name": "mobergd/autofit", "max_stars_repo_head_hexsha": "79bbfd91c1a9f43553426d9899d7c9268a07d1a2", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-25T18:33:12.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T18:33:12.000Z", "max_issues_repo_path": "src/svdfit.f", "max_issues_repo_name": "mobergd/autofit", "max_issues_repo_head_hexsha": "79bbfd91c1a9f43553426d9899d7c9268a07d1a2", "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/svdfit.f", "max_forks_repo_name": "mobergd/autofit", "max_forks_repo_head_hexsha": "79bbfd91c1a9f43553426d9899d7c9268a07d1a2", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-05-19T15:51:56.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-19T15:51:56.000Z", "avg_line_length": 40.6666666667, "max_line_length": 108, "alphanum_fraction": 0.5983606557, "num_tokens": 755, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206791658465, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6886017994107542}} {"text": "!-------------------------------------------------------------------------------\n! Copyright (c) 2016 The University of Tokyo\n! This software is released under the MIT License, see LICENSE.txt\n!-------------------------------------------------------------------------------\n!> \\brief This module contains functions for interpolation in 4 node\n!! tetrahedron element (Langrange interpolation)\nmodule shape_tet4n\n integer, parameter, private :: kreal = kind(0.0d0)\n\ncontains\n subroutine ShapeFunc_tet4n(volcoord,func)\n real(kind=kreal), intent(in) :: volcoord(3)\n real(kind=kreal) :: func(4)\n func(2:4) = volcoord(1:3)\n func(1) = 1.d0-volcoord(1)-volcoord(2)-volcoord(3)\n end subroutine\n\n subroutine ShapeDeriv_tet4n(func)\n real(kind=kreal), intent(out) :: func(4,3)\n func(1,1) = -1.d0\n func(2,1) = 1.d0\n func(3,1) = 0.d0\n func(4,1) = 0.d0\n\n func(1,2) = -1.d0\n func(2,2) = 0.d0\n func(3,2) = 1.d0\n func(4,2) = 0.d0\n\n func(1,3) = -1.d0\n func(2,3) = 0.d0\n func(3,3) = 0.d0\n func(4,3) = 1.d0\n end subroutine\n\nend module\n", "meta": {"hexsha": "edd95c37a5ff8c26ffb29a8854af51d084bfed3f", "size": 1077, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fistr1/src/lib/element/tet4n.f90", "max_stars_repo_name": "tkoyama010/FrontISTR", "max_stars_repo_head_hexsha": "2ce1f0425b87df76261c86ddb93bb4b588f72718", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fistr1/src/lib/element/tet4n.f90", "max_issues_repo_name": "tkoyama010/FrontISTR", "max_issues_repo_head_hexsha": "2ce1f0425b87df76261c86ddb93bb4b588f72718", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fistr1/src/lib/element/tet4n.f90", "max_forks_repo_name": "tkoyama010/FrontISTR", "max_forks_repo_head_hexsha": "2ce1f0425b87df76261c86ddb93bb4b588f72718", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.1081081081, "max_line_length": 80, "alphanum_fraction": 0.5385329619, "num_tokens": 364, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206659843132, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6886017893468674}} {"text": "!=============================================================================!\n module diff\n!\n! Finite Difference coefficients\n!\n!=============================================================================!\n!.... First derivatives\n!=============================================================================!\n\n!.... second order central difference\n\n real, parameter :: gd1 = -5.000000000000000E-01\n real, parameter :: gd2 = 5.000000000000000E-01\n \n!.... second order one-sided difference\n\n real, parameter :: ge1 = -1.500000000000000E+00\n real, parameter :: ge2 = 2.000000000000000E+00\n real, parameter :: ge3 = -5.000000000000000E-01\n\n!.... first order one-sided difference\n\n real, parameter :: gf1 = -1.000000000000000E+00\n real, parameter :: gf2 = 1.000000000000000E+00\n\n end module diff\n\n!=============================================================================!\n subroutine grad( ndof, nx, ny, v, g1v, g2v, dx, dy, optx, opty, &\n xper, yper)\n!\n! Take the gradient of a 2-D field.\n! updated to fourth order accurate differencing\n!\n!=============================================================================!\n use diff\n implicit none\n \n integer ndof, nx, ny, optx, opty\n logical :: xper, yper\n real v(ny,ndof,nx), g1v(ny,ndof,nx), g2v(ny,ndof,nx)\n real dx, dy\n \n real, parameter :: one = 1.0\n real dxinv, dyinv\n!=============================================================================!\n\n dxinv = one / dx\n dyinv = one / dy\n\n!=============================================================================!\n!.... compute the gradient in x\n!=============================================================================!\n\n if (xper) then\n\n g1v(:,:,1) = ( gd1 * v(:,:,nx-1) + &\n gd2 * v(:,:,2 ) ) * dxinv\n\n g1v(:,:,nx) = g1v(:,:,1)\n \n else\n \n g1v(:,:,1) = ( gf1 * v(:,:,1) + &\n gf2 * v(:,:,2) ) * dxinv\n \n g1v(:,:,nx) = -( gf1 * v(:,:,nx ) + &\n gf2 * v(:,:,nx-1) ) * dxinv\n\n end if\n\n!.... interior\n\n g1v(:,:,2:nx-1) = ( gd1 * v(:,:,1:nx-2) + &\n gd2 * v(:,:,3:nx ) ) * dxinv\n\n!=============================================================================!\n!.... compute the gradient in y\n!=============================================================================!\n\n if (yper) then\n \n g2v(1,:,:) = ( gd1 * v(ny-1,:,:) + &\n gd2 * v(2,:,:) ) * dyinv\n \n g2v(ny,:,:) = g2v(1,:,:)\n\n else\n\n g2v(1,:,:) = ( gf1 * v(1,:,:) + &\n gf2 * v(2,:,:) ) * dyinv\n \n g2v(ny,:,:) = -( gf1 * v(ny ,:,:) + &\n gf2 * v(ny-1,:,:) ) * dyinv\n \n end if\n \n!.... interior\n\n g2v(2:ny-1,:,:) = ( gd1 * v(1:ny-2,:,:) + &\n gd2 * v(3:ny ,:,:) ) * dyinv \n\n return\n end\n", "meta": {"hexsha": "4f1904b3663e9f9374e64ea6b6dc9e566e7e7b72", "size": 3262, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "pre/src/grad.f90", "max_stars_repo_name": "sscollis/lns3d", "max_stars_repo_head_hexsha": "f87b06abbb188cce9248092075f71dcce4570493", "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": "pre/src/grad.f90", "max_issues_repo_name": "sscollis/lns3d", "max_issues_repo_head_hexsha": "f87b06abbb188cce9248092075f71dcce4570493", "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": "pre/src/grad.f90", "max_forks_repo_name": "sscollis/lns3d", "max_forks_repo_head_hexsha": "f87b06abbb188cce9248092075f71dcce4570493", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-02-20T09:24:25.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-20T09:24:25.000Z", "avg_line_length": 31.0666666667, "max_line_length": 79, "alphanum_fraction": 0.2961373391, "num_tokens": 807, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206686206199, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6886017865058747}} {"text": " Program dstegr_example\n\n! DSTEGR Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_example_aux, Only: nagf_file_print_matrix_real_gen\n Use lapack_interfaces, Only: dstegr\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Real (Kind=dp), Parameter :: vl = 0.0E0_dp\n Real (Kind=dp), Parameter :: vu = 0.0E0_dp\n Integer, Parameter :: il = 0, iu = 0, nin = 5, nout = 6\n Character (1), Parameter :: range = 'A'\n! .. Local Scalars ..\n Real (Kind=dp) :: abstol\n Integer :: i, ifail, info, ldz, liwork, lwork, m, n\n Character (1) :: jobz\n! .. Local Arrays ..\n Real (Kind=dp), Allocatable :: d(:), e(:), w(:), work(:), z(:, :)\n Integer, Allocatable :: isuppz(:), iwork(:)\n! .. Executable Statements ..\n Write (nout, *) 'DSTEGR Example Program Results'\n Write (nout, *)\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n\n ldz = n\n liwork = 10*n\n lwork = 18*n\n Allocate (d(n), e(n), w(n), work(lwork), z(ldz,n), isuppz(2*n), &\n iwork(liwork))\n\n! Read the symmetric tridiagonal matrix T from data file, first\n! the diagonal elements, then the off diagonal elements and then\n! JOBV ('N' - eigenvalues only, 'V' - vectors as well)\n\n Read (nin, *) d(1:n)\n Read (nin, *) e(1:n-1)\n Read (nin, *) jobz\n\n! Calculate all the eigenvalues of T. Set ABSTOL to zero so that\n! the default value is used.\n\n abstol = 0.0E0_dp\n Call dstegr(jobz, range, n, d, e, vl, vu, il, iu, abstol, m, w, z, ldz, &\n isuppz, work, lwork, iwork, liwork, info)\n\n If (info==0) Then\n\n! Print eigenvalues and eigenvectors\n\n Write (nout, *) 'Eigenvalues'\n Write (nout, 100) w(1:m)\n\n Write (nout, *)\n Flush (nout)\n\n! Standardize the eigenvectors so that first elements are non-negative.\n Do i = 1, m\n If (z(1,i)<0.0_dp) Then\n z(1:n, i) = -z(1:n, i)\n End If\n End Do\n\n! ifail: behaviour on error exit\n! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft\n ifail = 0\n Call nagf_file_print_matrix_real_gen('General', ' ', n, m, z, ldz, &\n 'Eigenvectors', ifail)\n\n Else\n Write (nout, 110) 'Failure to compute an eigenvalue, INFO = ', info\n End If\n\n100 Format ((3X,8F8.4))\n110 Format (1X, A, I10)\n End Program\n", "meta": {"hexsha": "fa1aad3a4ec0fa712fa4f591413bb3ee6f5f4d79", "size": 2656, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/dstegr_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/dstegr_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/dstegr_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 31.619047619, "max_line_length": 90, "alphanum_fraction": 0.5696536145, "num_tokens": 836, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.90192067652954, "lm_q2_score": 0.7634837527911057, "lm_q1q2_score": 0.6886017828366662}} {"text": " REAL FUNCTION SBESY1 (X)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc>> 1996-03-30 SBESY1 Krogh Added external statement.\nC>> 1995-11-03 SBESY1 Krogh Changes to simplify C conversion.\nC>> 1994-11-11 SBESY1 Krogh Declared all vars.\nC>> 1994-10-20 SBESY1 Krogh Changes to use M77CON\nC>> 1991-01-14 SBESY1 CLL Changed to generic name SIN.\nC>> 1990-11-29 CLL\nC>> 1985-08-02 SBESY1 Lawson Initial code.\nC JULY 1977 EDITION. W. FULLERTON, C3, LOS ALAMOS SCIENTIFIC LAB.\nC C.L.LAWSON & S.CHAN, JPL, 1984 FEB ADAPTED TO JPL MATH77 LIBRARY.\nc ------------------------------------------------------------------\nc--S replaces \"?\": ?BESY1, ?BESJ1, ?BMP1, ?INITS, ?CSEVL, ?ERM1\nc ------------------------------------------------------------------\n EXTERNAL R1MACH, SBESJ1, SCSEVL\n INTEGER NTY1\n REAL X, BY1CS(20), AMPL, THETA, TWODPI, XMIN, XSML,\n 1 Y, R1MACH, SCSEVL, SBESJ1\nC\nC SERIES FOR BY1 ON THE INTERVAL 0. TO 1.60000E+01\nC WITH WEIGHTED ERROR 8.65E-33\nC LOG WEIGHTED ERROR 32.06\nC SIGNIFICANT FIGURES REQUIRED 32.17\nC DECIMAL PLACES REQUIRED 32.71\nC\n SAVE NTY1, XMIN, XSML\nC\n DATA BY1CS / +.320804710061190862932352018628015E-1,\n * +.126270789743350044953431725999727E+1,\n * +.649996189992317500097490637314144E-2,\n * -.893616452886050411653144160009712E-1,\n * +.132508812217570954512375510370043E-1,\n * -.897905911964835237753039508298105E-3,\n * +.364736148795830678242287368165349E-4,\n * -.100137438166600055549075523845295E-5,\n * +.199453965739017397031159372421243E-7,\n * -.302306560180338167284799332520743E-9,\n * +.360987815694781196116252914242474E-11,\n * -.348748829728758242414552947409066E-13,\n * +.278387897155917665813507698517333E-15,\n * -.186787096861948768766825352533333E-17,\n * +.106853153391168259757070336000000E-19,\n * -.527472195668448228943872000000000E-22,\n * +.227019940315566414370133333333333E-24,\n * -.859539035394523108693333333333333E-27,\n * +.288540437983379456000000000000000E-29,\n * -.864754113893717333333333333333333E-32 /\nC\n DATA TWODPI / 0.636619772367581343075535053490057E0 /\n DATA NTY1, XMIN, XSML / 0, 2*0.E0 /\nC ------------------------------------------------------------------\n IF (NTY1 .EQ. 0) then\n call SINITS (BY1CS, 20, 0.1E0*R1MACH(3), NTY1)\nC\n XMIN = 1.571E0 * EXP (MAX(LOG(R1MACH(1)), -LOG(R1MACH(2))) +\n 1 0.01E0)\n XSML = SQRT (4.0E0*R1MACH(3))\n endif\nC\n IF (X .LE. 0.E0) THEN\n SBESY1 = 0.E0\n CALL SERM1 ('SBESY1',1,0,'X IS ZERO OR NEGATIVE','X',X,'.')\n ELSE IF (X .LE. XMIN) THEN\n SBESY1 = 0.E0\n CALL SERM1 ('SBESY1',2,0,'X SO SMALL Y1 OVERFLOWS','X',X,'.')\n ELSE IF (X .LE. 4.E0) THEN\n IF (X .LE. XSML) THEN\n Y = 0.E0\n ELSE\n Y = X * X\n END IF\n SBESY1 = TWODPI * LOG(0.5E0*X)*SBESJ1(X) + (0.5E0 +\n * SCSEVL (.125E0*Y-1.E0, BY1CS, NTY1))/X\n ELSE\n CALL SBMP1 (X, AMPL, THETA)\n SBESY1 = AMPL * SIN(THETA)\n END IF\n RETURN\n END\n", "meta": {"hexsha": "9cd292b1c34c380d8a3c7a77e25801d24e8679e5", "size": 3392, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/sbesy1.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/sbesy1.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/sbesy1.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 41.3658536585, "max_line_length": 72, "alphanum_fraction": 0.5757665094, "num_tokens": 1263, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818865, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6885455366555887}} {"text": "program invert_ppal\n\nuse datasissim_interface\nuse lu_interface\nuse sistu_interface\nuse sistl_interface\n\nimplicit none\n\nreal, dimension(:,:), allocatable :: a\nreal, dimension(:,:), allocatable :: a_copia\nreal, dimension(:,:), allocatable :: a_inverse\nreal, dimension(:,:), allocatable :: jd\nreal, dimension(:), allocatable :: b\nreal, dimension(:), allocatable :: w\n\nreal :: deter\n\ninteger :: n, i\n\nprint*\nprint*, 'Introduce o orde do sistema: '\nread*, n\nprint*\n\nprint*\nprint*, 'O orde introduce e: ', n\nprint*\n\nallocate(a(n,n), a_inverse(n,n), a_copia(n,n), jd(n,n), b(n), w(n))\n\ncall datasissim(a)\n\na_copia = a\n\ncall lu(a, deter)\n\ndo i = 1, n\n b = 0\n b(i) = 1\n\n call sistl(a,b,w)\n call sistu(a,w,a_inverse(:,i))\n\nend do\n\nprint*, 'A inversa de A \u00e9: '\n\ndo i=1,n\n print*, a_inverse(i,:)\nend do\n\njd = matmul(a_copia,a_inverse)\n\nprint*, 'Matriz identidade: '\n\ndo i=1,n\n print*, jd(i,:)\nend do\n\nif (allocated(a)) deallocate(a)\n\nif(allocated(a_inverse)) deallocate(a_inverse)\n\nif(allocated(jd)) deallocate(jd)\n\nend program\n", "meta": {"hexsha": "b8d1bd3d73bea6c4d0534dbdace0713411a6bad8", "size": 1022, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Practica3_inverse/invert_ppal.f95", "max_stars_repo_name": "UxioAndrade/Analisis-Numerico-Matricial", "max_stars_repo_head_hexsha": "1afa52b0994b9cf38822da903609a4d1c91bfab0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2019-04-02T18:09:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-16T14:08:07.000Z", "max_issues_repo_path": "Practica3_inverse/invert_ppal.f95", "max_issues_repo_name": "UxioAndrade/Analisis-Numerico-Matricial", "max_issues_repo_head_hexsha": "1afa52b0994b9cf38822da903609a4d1c91bfab0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Practica3_inverse/invert_ppal.f95", "max_forks_repo_name": "UxioAndrade/Analisis-Numerico-Matricial", "max_forks_repo_head_hexsha": "1afa52b0994b9cf38822da903609a4d1c91bfab0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-04-05T13:18:12.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-04T10:32:14.000Z", "avg_line_length": 15.0294117647, "max_line_length": 67, "alphanum_fraction": 0.6702544031, "num_tokens": 322, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179068309441, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6885455354358352}} {"text": "MODULE myjunk\nTYPE POINT\n REAL :: X, Y\nCONTAINS\nPROCEDURE, PASS :: LENGTH => POINT_LENGTH\nEND TYPE POINT\n\nCONTAINS\n\nREAL FUNCTION POINT_LENGTH(A,B)\nCLASS(POINT), INTENT(IN) :: A, B\nPOINT_LENGTH = SQRT((A%X-B%X)**2+(A%Y-B%Y)**2)\nEND FUNCTION POINT_LENGTH\nEND MODULE\n", "meta": {"hexsha": "30077a447beed02b495174506eecd0a71c296680", "size": 266, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/rule-tests/pp/R445a.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/rule-tests/pp/R445a.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/rule-tests/pp/R445a.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": 17.7333333333, "max_line_length": 46, "alphanum_fraction": 0.7142857143, "num_tokens": 85, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178969328287, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6885455329052205}} {"text": "module spectra\n use constants\n implicit none\n private\n\n public :: fourier\n\ncontains\n\n subroutine fourier(wave, spectrum)\n real(dp), intent(in) :: wave(:)\n complex(dp), intent(out) :: spectrum(:)\n\n integer :: n, m\n real(dp) :: omega, phi\n complex(dp) :: transform(size(spectrum), size(wave))\n\n omega = 2 * pi / size(wave)\n\n do m = 1, size(wave)\n do n = 1, size(spectrum)\n phi = n * m * omega\n transform(n, m) = cmplx(cos(phi), sin(phi), dp)\n end do\n end do\n\n spectrum = matmul(transform, wave) / size(wave)\n end subroutine fourier\nend module spectra\n", "meta": {"hexsha": "8af665680060f979f9208e750521859bec3e9daa", "size": 644, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/spectra.f90", "max_stars_repo_name": "janberges/Tonbandfetzen", "max_stars_repo_head_hexsha": "f64a7761e924001b938e1c97cb894d6b7701c925", "max_stars_repo_licenses": ["0BSD"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/spectra.f90", "max_issues_repo_name": "janberges/Tonbandfetzen", "max_issues_repo_head_hexsha": "f64a7761e924001b938e1c97cb894d6b7701c925", "max_issues_repo_licenses": ["0BSD"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/spectra.f90", "max_forks_repo_name": "janberges/Tonbandfetzen", "max_forks_repo_head_hexsha": "f64a7761e924001b938e1c97cb894d6b7701c925", "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": 21.4666666667, "max_line_length": 59, "alphanum_fraction": 0.5652173913, "num_tokens": 175, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178969328287, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.688545527935099}} {"text": "module stdlib_specialfunctions\n use stdlib_kinds, only: sp, dp, xdp, qp\n\n implicit none\n\n private\n\n public :: legendre \n public :: dlegendre \n\n\n interface legendre\n !! version: experimental\n !! \n !! Legendre polynomial\n pure elemental module function legendre_fp64(n,x) result(leg)\n integer, intent(in) :: n\n real(dp), intent(in) :: x\n real(dp) :: leg\n end function\n end interface\n\n interface dlegendre\n !! version: experimental\n !! \n !! First derivative Legendre polynomial\n pure elemental module function dlegendre_fp64(n,x) result(dleg)\n integer, intent(in) :: n\n real(dp), intent(in) :: x\n real(dp) :: dleg\n end function\n end interface\n\nend module stdlib_specialfunctions\n", "meta": {"hexsha": "a8f37bfacb7d6cb5fb77084ab95e5d2523374287", "size": 839, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/stdlib_specialfunctions.f90", "max_stars_repo_name": "freevryheid/stdlib", "max_stars_repo_head_hexsha": "084f3c4cef67e234895292c597c455d02f52840b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 653, "max_stars_repo_stars_event_min_datetime": "2019-12-14T23:20:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T06:31:07.000Z", "max_issues_repo_path": "src/stdlib_specialfunctions.f90", "max_issues_repo_name": "freevryheid/stdlib", "max_issues_repo_head_hexsha": "084f3c4cef67e234895292c597c455d02f52840b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 593, "max_issues_repo_issues_event_min_datetime": "2019-12-14T23:19:29.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T19:40:29.000Z", "max_forks_repo_path": "src/stdlib_specialfunctions.f90", "max_forks_repo_name": "freevryheid/stdlib", "max_forks_repo_head_hexsha": "084f3c4cef67e234895292c597c455d02f52840b", "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": 23.9714285714, "max_line_length": 71, "alphanum_fraction": 0.5864123957, "num_tokens": 196, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837705, "lm_q2_score": 0.7577943658046608, "lm_q1q2_score": 0.6885455192146092}} {"text": "C Example used by Khadija Immadoueddine, p. 7 in her report\nC\nC It seems that she has unrolled the j loop by hand and the i loop\nC with PIPS; in fact, she's used an unroll-and-jam\nC\nC Unlike unroll13 and 14, try tiling and unroll to emulate her\nC unroll-and-jam\n\n subroutine unroll15(n1, n2, a, b, c)\nC\n real a(0:n1+1,0:n2+1)\n real b(0:n1+1,0:n2+1)\n real c(0:n1+1,0:n2+1)\n\n do 200 j = 1, n2\n do 300 i = 1, n1\n a(i,j)=a(i+1,j)*b(i,j)+a(i,j+1)*c(i,j)\n 300 continue\n 200 continue\n\n END\n\n program main\n parameter (n1=10, n2=11)\n real a(0:n1+1,0:n2+1)\n real b(0:n1+1,0:n2+1)\n real c(0:n1+1,0:n2+1)\n\n do i = 0, n1+1\n do j = 0, n2+1\n a(i,j) = 3*i*(n1+2)+j\n b(i,j) = 3*i*(n1+2)+j+1\n c(i,j) = 3*i*(n1+2)+j+2\n enddo\n enddo\n\n call unroll15(n1, n2, a, b, c)\n\n print *, a(0,0), a(0,n2+1),a(n1+1,0), a(n1+1,n2+1)\n\n end\n", "meta": {"hexsha": "d41cb3f7f17b552fcd3664614f1d84e834b790f5", "size": 978, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "packages/PIPS/validation/Transformations/Unroll.sub/unroll15.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/Transformations/Unroll.sub/unroll15.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/Transformations/Unroll.sub/unroll15.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": 23.2857142857, "max_line_length": 70, "alphanum_fraction": 0.5030674847, "num_tokens": 428, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933271118221, "lm_q2_score": 0.8397339756938818, "lm_q1q2_score": 0.6884922832204946}} {"text": "program doloop_02\nimplicit none\ninteger :: i, j, a, b\nj = 0\na = 1\nb = 10\ndo i = a, b\n j = j + i\nend do\nif (j /= 55) error stop\n\na = 0\ndo i = 1, 10\n do j = 1, 10\n a = a + (i-1)*10+j\n end do\nend do\nif (a /= 100*101/2) error stop\n\na = 0\ndo i = 1, 10\n do j = 1, i\n a = a + j\n end do\nend do\nif (a /= 220) error stop\nend\n", "meta": {"hexsha": "64ba7347dee0ecccad3433f21574529c26bc311b", "size": 344, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "integration_tests/doloop_02.f90", "max_stars_repo_name": "Thirumalai-Shaktivel/lfortran", "max_stars_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 316, "max_stars_repo_stars_event_min_datetime": "2019-03-24T16:23:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:28:33.000Z", "max_issues_repo_path": "integration_tests/doloop_02.f90", "max_issues_repo_name": "Thirumalai-Shaktivel/lfortran", "max_issues_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-07-29T04:58:03.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-04T16:40:06.000Z", "max_forks_repo_path": "integration_tests/doloop_02.f90", "max_forks_repo_name": "Thirumalai-Shaktivel/lfortran", "max_forks_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2019-03-28T19:40:07.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T07:28:55.000Z", "avg_line_length": 12.2857142857, "max_line_length": 30, "alphanum_fraction": 0.4854651163, "num_tokens": 169, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528170040852, "lm_q2_score": 0.8080672158638527, "lm_q1q2_score": 0.6884351408838575}} {"text": "!\n! Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.\n! See https://llvm.org/LICENSE.txt for license information.\n! SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception\n!\n! test f2008 bessel_j1 intrinsic\n\nprogram p \n use ISO_C_BINDING\n use check_mod\n\n interface\n subroutine get_expected_f( src1, expct, n ) bind(C)\n use ISO_C_BINDING\n type(C_PTR), value :: src1\n type(C_PTR), value :: expct\n integer(C_INT), value :: n\n end subroutine\n \n subroutine get_expected_d( src1, expct, n ) bind(C)\n use ISO_C_BINDING\n type(C_PTR), value :: src1\n type(C_PTR), value :: expct\n integer(C_INT), value :: n\n end subroutine\n end interface\n \n\n integer, parameter :: N=22\n real*4, target, dimension(N) :: r_src1\n real*4, target, dimension(N) :: r_rslt\n real*4, target, dimension(N) :: r_expct\n real*8 :: valuer\n \n real*8, target, dimension(N) :: d_src1\n real*8, target, dimension(N) :: d_rslt\n real*8, target, dimension(N) :: d_expct\n real*8 :: value8\n \n valuer = -.2\n valued = -.2_8\n do i = 0,N-1 \n r_src1(i+1) = valuer + i\n d_src1(i+1) = valued + i\n enddo\n\n r_rslt = bessel_j1(r_src1)\n d_rslt = bessel_j1(d_src1)\n\n call get_expected_f(C_LOC(r_src1), C_LOC(r_expct), N)\n call get_expected_d(C_LOC(d_src1), C_LOC(d_expct), N)\n\n call checkr4( r_rslt, r_expct, N, rtoler=0.0000003)\n call checkr8( d_rslt, d_expct, N, rtoler=0.0000003_8)\n\n! print *, \"r_expct:\" \n! print *, r_expct\n! print *, \"r_rslt:\" \n! print *, r_rslt\n!\n! print *, \"d_expct:\" \n! print *, d_expct\n! print *, \"d_rslt:\" \n! print *, d_rslt\nend program \n", "meta": {"hexsha": "4fb9a11c9241391930987ff106ed87ccbc4e0350", "size": 1638, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/f90_correct/src/in18.f90", "max_stars_repo_name": "abrahamtovarmob/flang", "max_stars_repo_head_hexsha": "bcd84b29df046b6d6574f0bfa34ea5059092615a", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 716, "max_stars_repo_stars_event_min_datetime": "2017-05-17T17:58:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T11:20:58.000Z", "max_issues_repo_path": "test/f90_correct/src/in18.f90", "max_issues_repo_name": "abrahamtovarmob/flang", "max_issues_repo_head_hexsha": "bcd84b29df046b6d6574f0bfa34ea5059092615a", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 794, "max_issues_repo_issues_event_min_datetime": "2017-05-18T19:27:40.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T23:22:11.000Z", "max_forks_repo_path": "test/f90_correct/src/in18.f90", "max_forks_repo_name": "abrahamtovarmob/flang", "max_forks_repo_head_hexsha": "bcd84b29df046b6d6574f0bfa34ea5059092615a", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 157, "max_forks_repo_forks_event_min_datetime": "2017-05-17T18:50:33.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T07:06:45.000Z", "avg_line_length": 24.8181818182, "max_line_length": 79, "alphanum_fraction": 0.6434676435, "num_tokens": 560, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527944504227, "lm_q2_score": 0.808067204308405, "lm_q1q2_score": 0.6884351128142863}} {"text": "program pi\n\n use ISO_FORTRAN_ENV\n use mpi\n\n implicit none\n\n double precision :: step, x, s, finalsum, mypi, start, stop\n integer(kind=int64) :: num_steps, i, mymax, mymin\n character(len=:), allocatable :: a\n integer :: argl, rank, ierr, numprocs\n\n call MPI_INIT(ierr)\n call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)\n call MPI_COMM_SIZE(MPI_COMM_WORLD, numprocs, ierr)\n\n num_steps = 1000000000\n\n! Get command line args (Fortran 2003 standard)\n if (command_argument_count() > 0) then\n call get_command_argument(1, length=argl)\n allocate(character(argl) :: a)\n call get_command_argument(1, a)\n read(a,*) num_steps\n end if\n\n! Output start message\n\n if (rank == 0) then\n write(*,'(A)') \"Calculating PI using:\"\n write(*,'(A,1I16,A)') \" \",num_steps, \" slices\"\n write(*,'(A,1I16,A)') \" \",numprocs,\" process(es)\"\n end if\n\n! Initialise time counter and sum: set step size\n\n call MPI_BARRIER(MPI_COMM_WORLD, ierr)\n\n start = MPI_WTIME()\n s = 0d0\n step = 1.0d0 / num_steps\n\n! Remember Fortran loops from 1\n mymin = ((rank * num_steps)/numprocs) + 1\n mymax = ((rank + 1) * num_steps)/numprocs\n\n do i = mymin, mymax\n x = (i - 0.5d0) * step\n s = s + 4.0d0 / (1.0d0 + x*x)\n end do\n\n call MPI_Reduce(s, finalsum, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD, ierr)\n\n! Evaluate PI from the final sum value, and stop the clock\n\n mypi = finalsum * step\n\n call MPI_BARRIER(MPI_COMM_WORLD, ierr)\n stop = MPI_WTIME()\n\n! output value of PI and time taken\n! note cpu_time is only specified as being microsecond res\n\n if (rank == 0) then\n write(*,'(A,1F12.10,A)') \"Obtained value of PI: \", mypi\n write(*,'(A,1F12.5,A)') \"Time taken: \",(stop-start), \" seconds\"\n end if\n\n call MPI_FINALIZE(ierr)\n\nend program pi\n\n", "meta": {"hexsha": "60cc5cb32ff228f9ce8d199d026f2e89041b2a7a", "size": 1838, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran_mpi_pi_dir/pi.f90", "max_stars_repo_name": "adrianjhpc/pi_examples", "max_stars_repo_head_hexsha": "ba624038a865e194b361d783a0e8647f2a9bb376", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 19, "max_stars_repo_stars_event_min_datetime": "2016-04-13T11:39:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T19:22:06.000Z", "max_issues_repo_path": "fortran_mpi_pi_dir/pi.f90", "max_issues_repo_name": "adrianjhpc/pi_examples", "max_issues_repo_head_hexsha": "ba624038a865e194b361d783a0e8647f2a9bb376", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2016-05-24T11:28:57.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-14T16:22:17.000Z", "max_forks_repo_path": "fortran_mpi_pi_dir/pi.f90", "max_forks_repo_name": "adrianjhpc/pi_examples", "max_forks_repo_head_hexsha": "ba624038a865e194b361d783a0e8647f2a9bb376", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2017-10-12T15:08:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-25T09:35:21.000Z", "avg_line_length": 25.1780821918, "max_line_length": 79, "alphanum_fraction": 0.6294885745, "num_tokens": 589, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527869325346, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.6884351126461451}} {"text": "module math_module\n\n public\n\ncontains\n\n ! Compute the standard cross-product of two three-vectors.\n\n function cross_product(A,B) result(C)\n\n use amrex_fort_module, only : rt => amrex_real\n implicit none\n\n real(rt) :: A(3), B(3)\n real(rt) :: C(3)\n\n C(1) = A(2)*B(3) - A(3)*B(2)\n C(2) = A(3)*B(1) - A(1)*B(3)\n C(3) = A(1)*B(2) - A(2)*B(1)\n\n end function cross_product\n\nend module math_module\n", "meta": {"hexsha": "5f1536d4066459e6e58853413b5bb9dacd373e12", "size": 431, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Source/driver/math.f90", "max_stars_repo_name": "yingtchen/Castro", "max_stars_repo_head_hexsha": "5e9bd2f7a699a45447b92a1c9c3064f6c2e3552c", "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": "Source/driver/math.f90", "max_issues_repo_name": "yingtchen/Castro", "max_issues_repo_head_hexsha": "5e9bd2f7a699a45447b92a1c9c3064f6c2e3552c", "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": "Source/driver/math.f90", "max_forks_repo_name": "yingtchen/Castro", "max_forks_repo_head_hexsha": "5e9bd2f7a699a45447b92a1c9c3064f6c2e3552c", "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": 17.9583333333, "max_line_length": 60, "alphanum_fraction": 0.5754060325, "num_tokens": 156, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8652240964782012, "lm_q2_score": 0.7956581000631542, "lm_q1q2_score": 0.6884225607327048}} {"text": " PROGRAM MAIN\n\n INTEGER N, NMAX, JMAX, IL, IU, M, LDA, LDZ, ZERO,\n $ SEED\n PARAMETER (NMAX=1000, JMAX=NMAX, LDA=NMAX, LDZ=NMAX, ZERO=0, \n $ SEED=12)\n\n DOUBLE PRECISION VL, VU, W(NMAX) \n COMPLEX*16 A(NMAX,NMAX), Z(NMAX,JMAX)\n\n INTEGER I, J, IERR\n\n* external functions\n EXTERNAL ZHEEIG\n\n* Intialize Hermitian matrix A of size N-by-N\n N = 100\n\n CALL SRAND(SEED)\n DO 100, J=1,N\n DO 200, I=1,J\n IF (I .EQ. J) THEN\n A(I,J) = COMPLEX(RAND(),ZERO)\n ELSE\n A(I,J) = COMPLEX(RAND(),RAND())\n ENDIF\n 200 CONTINUE\n 100 CONTINUE\n\n DO 300, J=1,N\n DO 400, I=J+1,N\n A(I,J) = CONJG(A(J,I))\n 400 CONTINUE\n 300 CONTINUE\n\n\n* Solve the eigenproblem\n* The number of threads for the LAPACK routines are set by \n* OMP_NUM_THREADS or GOTO_NUM_THREADS or MKL_NUM_THREADS ... \n* depending on the BLAS used. For the tridiagonal stage with \n* PMR_NUM_THREADS. \n CALL ZHEEIG('V', 'A', 'L', N, A, LDA, VL, VU, IL, IU, \n $ M, W, Z, LDZ, IERR)\n IF (IERR .NE. 0) THEN\n WRITE(*,*) 'Routine has failed with error', IERR\n ENDIF\n\n\n WRITE(*,*) 'Sucessfully computed eigenpairs!'\n\n END\n", "meta": {"hexsha": "6d03dbefe7569d78a4c178a4e1f08449ef7e8526", "size": 1303, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "EXAMPLES/Hermitian/Fortran/main_all.f", "max_stars_repo_name": "petschow/mr3smp", "max_stars_repo_head_hexsha": "d41de0cf0e1ce83d1408d836ab20cb8a85cc4739", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "EXAMPLES/Hermitian/Fortran/main_all.f", "max_issues_repo_name": "petschow/mr3smp", "max_issues_repo_head_hexsha": "d41de0cf0e1ce83d1408d836ab20cb8a85cc4739", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "EXAMPLES/Hermitian/Fortran/main_all.f", "max_forks_repo_name": "petschow/mr3smp", "max_forks_repo_head_hexsha": "d41de0cf0e1ce83d1408d836ab20cb8a85cc4739", "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.0576923077, "max_line_length": 67, "alphanum_fraction": 0.5295471988, "num_tokens": 438, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.7956581073313276, "lm_q1q2_score": 0.6884225559607344}} {"text": " PROGRAM xddpoly\r\nC driver for routine ddpoly\r\n INTEGER NC,NCM1,NP\r\n PARAMETER(NC=6,NCM1=5,NP=20)\r\n INTEGER i,j\r\n REAL x,factrl,c(NC),pd(NCM1),d(NCM1,NP)\r\n CHARACTER a(NCM1)*15\r\n DATA a/'polynomial:','first deriv:','second deriv:',\r\n * 'third deriv:','fourth deriv:'/\r\n DATA c/-1.0,5.0,-10.0,10.0,-5.0,1.0/\r\n do 12 i=1,NP\r\n x=0.1*i\r\n call ddpoly(c,NC,x,pd,NC-1)\r\n do 11 j=1,NC-1\r\n d(j,i)=pd(j)\r\n11 continue\r\n12 continue\r\n do 14 i=1,NC-1\r\n write(*,'(1x,t7,a)') a(i)\r\n write(*,'(1x,t13,a,t25,a,t40,a)') 'X','DDPOLY','actual'\r\n do 13 j=1,NP\r\n x=0.1*j\r\n write(*,'(1x,3f15.6)') x,d(i,j),\r\n * factrl(NC-1)/factrl(NC-i)*((x-1.0)**(NC-i))\r\n13 continue\r\n write(*,*) 'press ENTER to continue...'\r\n read(*,*)\r\n14 continue\r\n END\r\n", "meta": {"hexsha": "245f4f8c81a176dedea05e34689277bc37b870bf", "size": 896, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xddpoly.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xddpoly.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xddpoly.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.8666666667, "max_line_length": 64, "alphanum_fraction": 0.4732142857, "num_tokens": 345, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.7956580976404297, "lm_q1q2_score": 0.6884225475759362}} {"text": "subroutine knots_lms(X, N, Nctl, k, t)\n\n !***DESCRIPTION\n !\n ! Written by Gaetan Kenway\n !\n ! Abstract knots_lms generates knots suitable for b-splines\n !\n ! Description of Arguments\n ! Input\n ! X - Real, size(N) The ordinates to use to make knot vector\n ! N - Integer, the number of ordinates\n ! Nctl - Integer, the desired number of control points\n ! k - order of spline\n !\n ! Ouput \n ! t - Real, size(Nctl+k) the resulting knots\n\n use precision\n implicit none\n\n ! Input\n integer, intent(in) :: N\n integer, intent(in) :: Nctl\n integer, intent(in) :: K\n real(kind=realType), intent(in) :: X(N)\n\n ! Output\n real(kind=realType), intent(out) :: T(Nctl+K)\n\n ! Working \n real(kind=realType) d, alpha\n integer I, J\n\n ! ----------------------------\n ! PUT K KNOTS AT EACH ENDPOINT -- Knot a knot conditions\n ! ----------------------------\n !\n DO J=1, K\n t(J) = X(1) ! Left\n t(Nctl+J) = X(N) ! right\n end do\n\n if (mod(N, 2) == 1) then ! Odd\n d = real(N/(Nctl-k+1.0))\n do j=1, Nctl-k\n i = floor(j*d)\n alpha = j*d-i\n t(k+j) = (1-alpha)*X(i) + alpha*X(i+2)\n end do\n else ! even\n d = real(N/(Nctl-k+1.0))\n do j=1, Nctl-k\n i = floor(j*d)\n alpha = j*d-i+0.5\n t(k+j) = (1-alpha)*X(i) + alpha*X(i+1)\n end do\n end if\n\nend subroutine knots_lms\n\nsubroutine knots_interp(X, deriv_ptr, n, nd , k, t)\n !***DESCRIPTION\n !\n ! Written by Gaetan Kenway\n !\n ! Abstract knots_lms generates knots suitable for b-spline\n ! interpolation\n !\n ! Description of Arguments\n ! Input\n ! X - Real, size(N) The ordinates to use to make knot vector\n ! deriv_ptr - Real, size(nd) Flags to determine if a derivative\n ! is specified\n ! n - Integer, the number of ordinates\n ! nd - Integer, the number of derivatives specified\n ! k - order of spline\n !\n ! Ouput \n ! t - Real, size(nNctl+k) the resulting knots\n\n use precision\n implicit none\n\n ! Input\n integer, intent(in) :: n, nd, k\n integer, intent(in) :: deriv_ptr(nd)\n real(kind=realType), intent(in) :: X(n)\n\n ! Output\n real(kind=realType), intent(out) :: t(n+nd+k)\n\n ! Working\n integer :: i, j, Nctl\n\n ! ----------------------------\n ! PUT K KNOTS AT EACH ENDPOINT -- Knot a knot conditions\n ! ----------------------------\n Nctl = n + nd\n\n DO J=1, K\n t(J) = X(1) ! Left\n t(Nctl+J) = X(N) ! right\n end do\n\n if (nd == n) then ! Full Length nd so we can use formulas in NURBS book\n if (k == 3) then\n do i=1, n-2\n t(k+2*i-1) = 0.5*(X(i) + X(i+1))\n t(k+2*i) = X(i+1)\n end do\n t(Nctl) = 0.5*(X(n-1) + 1)\n else if (k ==4) then\n t(5) = X(2)/2\n t(Nctl) = 0.5*(X(n-1) + 1)\n do i=1, n-3\n t(k+2*i ) = (1.0/3.0)*(2*X(i+1) + X(i+2))\n t(k+2*i+1) = (1.0/3.0)*(X(i+1) + 2*X(i+2))\n end do\n end if\n\n else if (nd == 0) then\n if (k ==2 ) then\n do j=1, N-k\n t(k+j) = X(j+1)\n end do\n else if (k == 3) then\n do j=1, N-k\n t(k+j) = 0.5*(X(j+1)+X(J+2))\n end do\n else if (k == 4) then\n do j=1, N-k\n t(K+j) = X(j+2)\n end do\n else\n print *, 'Error: Interpolation is only available for k=2, 3 or 4'\n stop\n end if\n else \n print *, 'Interp_knots with number of derivative != number of points is not yet supported' \n stop\n end if\nend subroutine knots_interp\n", "meta": {"hexsha": "e28b0a03fe8b07feea7dbc919ea7cc34f09e8eff", "size": 3633, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/knots.f90", "max_stars_repo_name": "eirikurj/pyspline", "max_stars_repo_head_hexsha": "91dd6d432deac3b1647508bf4fca985e704da77c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2019-04-18T00:49:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-20T14:40:08.000Z", "max_issues_repo_path": "src/knots.f90", "max_issues_repo_name": "eirikurj/pyspline", "max_issues_repo_head_hexsha": "91dd6d432deac3b1647508bf4fca985e704da77c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 23, "max_issues_repo_issues_event_min_datetime": "2019-10-17T20:39:11.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T15:27:42.000Z", "max_forks_repo_path": "src/knots.f90", "max_forks_repo_name": "eirikurj/pyspline", "max_forks_repo_head_hexsha": "91dd6d432deac3b1647508bf4fca985e704da77c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2019-05-29T16:56:15.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-08T13:51:24.000Z", "avg_line_length": 25.2291666667, "max_line_length": 96, "alphanum_fraction": 0.491879989, "num_tokens": 1243, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.6884225454797366}} {"text": "PROGRAM mairyzo\n \n! Code converted using TO_F90 by Alan Miller\n! Date: 2004-06-28 Time: 12:58:09\n\n! =========================================================\n! Purpose: This program computes the first NT zeros of Airy\n! functions Ai(x) and Ai'(x), and the associated\n! values of Ai(a') and Ai'(a), and the first NT\n! zeros of Airy functions Bi(x) and Bi'(x), and\n! the associated values of Bi(b') and Bi'(b) using\n! subroutine AIRYZO\n! Input : NT --- Total number of zeros\n! KF --- Function code\n! KF=1 for Ai(x) and Ai'(x)\n! KF=2 for Bi(x) and Bi'(x)\n! Output: XA(m) --- a, the m-th zero of Ai(x) or\n! b, the m-th zero of Bi(x)\n! XB(m) --- a', the m-th zero of Ai'(x) or\n! b', the m-th zero of Bi'(x)\n! XC(m) --- Ai(a') or Bi(b')\n! XD(m) --- Ai'(a) or Bi'(b)\n! ( m --- Serial number of zeros )\n! Example: NT=5\n\n! m a Ai'(a) a' Ai(a')\n! -----------------------------------------------------------\n! 1 -2.33810741 .70121082 -1.01879297 .53565666\n! 2 -4.08794944 -.80311137 -3.24819758 -.41901548\n! 3 -5.52055983 .86520403 -4.82009921 .38040647\n! 4 -6.78670809 -.91085074 -6.16330736 -.35790794\n! 5 -7.94413359 .94733571 -7.37217726 .34230124\n\n! m b Bi'(b) b' Bi(b')\n! -----------------------------------------------------------\n! 1 -1.17371322 .60195789 -2.29443968 -.45494438\n! 2 -3.27109330 -.76031014 -4.07315509 .39652284\n! 3 -4.83073784 .83699101 -5.51239573 -.36796916\n! 4 -6.16985213 -.88947990 -6.78129445 .34949912\n! 5 -7.37676208 .92998364 -7.94017869 -.33602624\n! ==========================================================\n\nIMPLICIT DOUBLE PRECISION (a-h,o-z)\nDIMENSION xa(50),xb(50),xc(50),xd(50)\nWRITE(*,35)\nWRITE(*,40)\nWRITE(*,*)'Please enter KF,NT '\n! READ(*,*)KF,NT\nkf=1\nnt=5\nWRITE(*,30)kf,nt\nIF (kf == 1) THEN\n WRITE(*,*)' m a Ai''(A) A''', &\n ' Ai(a'')'\nELSE IF (kf == 2) THEN\n WRITE(*,*)' m b Bi''(B) B''', &\n ' Bi(b'')'\nEND IF\nWRITE(*,*)'---------------------------------', &\n '---------------------------'\nCALL airyzo(nt,kf,xa,xb,xc,xd)\nDO k=1,nt\n WRITE(*,20)k,xa(k),xd(k),xb(k),xc(k)\nEND DO\n20 FORMAT(1X,i3,1X,3F14.8,f13.8)\n30 FORMAT(1X,3HKF=,i2,', ',3HNT=,i3)\n35 FORMAT(10X,'KF=1 for Ai(x) and Ai''(X); KF=2 FOR BI(X)', &\n ' and Bi''(X)')\n40 FORMAT(10X,'NT is the number of the zeros')\nEND PROGRAM mairyzo\n\n\nSUBROUTINE airyzo(nt,kf,xa,xb,xc,xd)\n\n! ========================================================\n! Purpose: Compute the first NT zeros of Airy functions\n! Ai(x) and Ai'(x), a and a', and the associated\n! values of Ai(a') and Ai'(a); and the first NT\n! zeros of Airy functions Bi(x) and Bi'(x), b and\n! b', and the associated values of Bi(b') and\n! Bi'(b)\n! Input : NT --- Total number of zeros\n! KF --- Function code\n! KF=1 for Ai(x) and Ai'(x)\n! KF=2 for Bi(x) and Bi'(x)\n! Output: XA(m) --- a, the m-th zero of Ai(x) or\n! b, the m-th zero of Bi(x)\n! XB(m) --- a', the m-th zero of Ai'(x) or\n! b', the m-th zero of Bi'(x)\n! XC(m) --- Ai(a') or Bi(b')\n! XD(m) --- Ai'(a) or Bi'(b)\n! ( m --- Serial number of zeros )\n! Routine called: AIRYB for computing Airy functions and\n! their derivatives\n! =======================================================\n\n\nIMPLICIT DOUBLE PRECISION (a-h,o-z)\nINTEGER, INTENT(IN) :: nt\nINTEGER, INTENT(IN) :: kf\nDOUBLE PRECISION, INTENT(OUT) :: xa(nt)\nDOUBLE PRECISION, INTENT(OUT) :: xb(nt)\nDOUBLE PRECISION, INTENT(OUT) :: xc(nt)\nDOUBLE PRECISION, INTENT(OUT) :: xd(nt)\n\n\npi=3.141592653589793D0\nDO i=1,nt\n IF (kf == 1) THEN\n u=3.0*pi*(4.0*i-1)/8.0D0\n u1=1/(u*u)\n rt0=-(u*u)**(1.0/3.0)*((((-15.5902*u1+.929844)*u1 &\n -.138889)*u1+.10416667D0)*u1+1.0D0)\n ELSE IF (kf == 2) THEN\n IF (i == 1) THEN\n rt0=-1.17371\n ELSE\n u=3.0*pi*(4.0*i-3.0)/8.0\n u1=1.0D0/(u*u)\n rt0=-(u*u)**(1.0/3.0)*((((-15.5902*u1+.929844)*u1 &\n -.138889)*u1+.10416667)*u1+1.0)\n END IF\n END IF\n rt=1.0E300\n DO WHILE (DABS((rt-rt0)/rt) > 1.d-9)\n x=rt0\n CALL airyb(x,ai,bi,ad,bd)\n IF (kf == 1) rt=rt0-ai/ad\n IF (kf == 2) rt=rt0-bi/bd\n IF (DABS((rt-rt0)/rt) > 1.d-9) THEN\n rt0=rt\n END IF\n END DO\n xa(i)=rt\n IF (kf == 1) xd(i)=ad\n IF (kf == 2) xd(i)=bd\nEND DO\nDO i=1,nt\n IF (kf == 1) THEN\n IF (i == 1) THEN\n rt0=-1.01879\n ELSE\n u=3.0*pi*(4.0*i-3.0)/8.0\n u1=1/(u*u)\n rt0=-(u*u)**(1.0/3.0)*((((15.0168*u1-.873954) &\n *u1+.121528)*u1-.145833D0)*u1+1.0D0)\n END IF\n ELSE IF (kf == 2) THEN\n IF (i == 1) THEN\n rt0=-2.29444\n ELSE\n u=3.0*pi*(4.0*i-1.0)/8.0\n u1=1.0/(u*u)\n rt0=-(u*u)**(1.0/3.0)*((((15.0168*u1-.873954) &\n *u1+.121528)*u1-.145833)*u1+1.0)\n END IF\n END IF\n rt=1.0E300\n DO WHILE (DABS((rt-rt0)/rt) > 1.0D-9)\n x=rt0\n CALL airyb(x,ai,bi,ad,bd)\n IF (kf == 1) rt=rt0-ad/(ai*x)\n IF (kf == 2) rt=rt0-bd/(bi*x)\n IF (DABS((rt-rt0)/rt) > 1.0D-9) THEN\n rt0=rt\n END IF\n END DO\n xb(i)=rt\n IF (kf == 1) xc(i)=ai\n IF (kf == 2) xc(i)=bi\nEND DO\nRETURN\nEND SUBROUTINE airyzo\n\n\nSUBROUTINE airyb(x,ai,bi,ad,bd)\n\n! =======================================================\n! Purpose: Compute Airy functions and their derivatives\n! Input: x --- Argument of Airy function\n! Output: AI --- Ai(x)\n! BI --- Bi(x)\n! AD --- Ai'(x)\n! BD --- Bi'(x)\n! =======================================================\n\n\nIMPLICIT DOUBLE PRECISION (a-h,o-z)\nDOUBLE PRECISION, INTENT(IN) :: x\nDOUBLE PRECISION, INTENT(OUT) :: ai\nDOUBLE PRECISION, INTENT(OUT) :: bi\nDOUBLE PRECISION, INTENT(OUT) :: ad\nDOUBLE PRECISION, INTENT(OUT) :: bd\nDIMENSION ck(41),dk(41)\n\neps=1.0D-15\npi=3.141592653589793D0\nc1=0.355028053887817D0\nc2=0.258819403792807D0\nsr3=1.732050807568877D0\nxa=DABS(x)\nxq=DSQRT(xa)\nIF (x > 0.0D0) xm=5.0\nIF (x <= 0.0D0) xm=8.0\nIF (x == 0.0D0) THEN\n ai=c1\n bi=sr3*c1\n ad=-c2\n bd=sr3*c2\n RETURN\nEND IF\nIF (xa <= xm) THEN\n fx=1.0D0\n r=1.0D0\n DO k=1,40\n r=r*x/(3.0D0*k)*x/(3.0D0*k-1.0D0)*x\n fx=fx+r\n IF (DABS(r/fx) < eps) EXIT\n END DO\n 15 gx=x\n r=x\n DO k=1,40\n r=r*x/(3.0D0*k)*x/(3.0D0*k+1.0D0)*x\n gx=gx+r\n IF (DABS(r/gx) < eps) EXIT\n END DO\n 25 ai=c1*fx-c2*gx\n bi=sr3*(c1*fx+c2*gx)\n df=.5D0*x*x\n r=df\n DO k=1,40\n r=r*x/(3.0D0*k)*x/(3.0D0*k+2.0D0)*x\n df=df+r\n IF (DABS(r/df) < eps) EXIT\n END DO\n 35 dg=1.0D0\n r=1.0D0\n DO k=1,40\n r=r*x/(3.0D0*k)*x/(3.0D0*k-2.0D0)*x\n dg=dg+r\n IF (DABS(r/dg) < eps) EXIT\n END DO\n 45 ad=c1*df-c2*dg\n bd=sr3*(c1*df+c2*dg)\nELSE\n xe=xa*xq/1.5D0\n xr1=1.0D0/xe\n xar=1.0D0/xq\n xf=DSQRT(xar)\n rp=.5641895835477563D0\n r=1.0D0\n DO k=1,40\n r=r*(6.0D0*k-1.0D0)/216.0D0*(6.0D0*k-3.0D0) &\n /k*(6.0D0*k-5.0D0)/(2.0D0*k-1.0D0)\n ck(k)=r\n dk(k)=-(6.0D0*k+1.0D0)/(6.0D0*k-1.0D0)*ck(k)\n END DO\n km=INT(24.5-xa)\n IF (xa < 6.0) km=14\n IF (xa > 15.0) km=10\n IF (x > 0.0D0) THEN\n sai=1.0D0\n sad=1.0D0\n r=1.0D0\n DO k=1,km\n r=-r*xr1\n sai=sai+ck(k)*r\n sad=sad+dk(k)*r\n END DO\n sbi=1.0D0\n sbd=1.0D0\n r=1.0D0\n DO k=1,km\n r=r*xr1\n sbi=sbi+ck(k)*r\n sbd=sbd+dk(k)*r\n END DO\n xp1=DEXP(-xe)\n ai=.5D0*rp*xf*xp1*sai\n bi=rp*xf/xp1*sbi\n ad=-.5D0*rp/xf*xp1*sad\n bd=rp/xf/xp1*sbd\n ELSE\n xcs=DCOS(xe+pi/4.0D0)\n xss=DSIN(xe+pi/4.0D0)\n ssa=1.0D0\n sda=1.0D0\n r=1.0D0\n xr2=1.0D0/(xe*xe)\n DO k=1,km\n r=-r*xr2\n ssa=ssa+ck(2*k)*r\n sda=sda+dk(2*k)*r\n END DO\n ssb=ck(1)*xr1\n sdb=dk(1)*xr1\n r=xr1\n DO k=1,km\n r=-r*xr2\n ssb=ssb+ck(2*k+1)*r\n sdb=sdb+dk(2*k+1)*r\n END DO\n ai=rp*xf*(xss*ssa-xcs*ssb)\n bi=rp*xf*(xcs*ssa+xss*ssb)\n ad=-rp/xf*(xcs*sda+xss*sdb)\n bd=rp/xf*(xss*sda-xcs*sdb)\n END IF\nEND IF\nRETURN\nEND SUBROUTINE airyb\n", "meta": {"hexsha": "1e26277cc228595a62559c25c042b1c960fa0012", "size": 8825, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "MATLAB/f2matlab/comp_spec_func/mairyzo.f90", "max_stars_repo_name": "vasaantk/bin", "max_stars_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MATLAB/f2matlab/comp_spec_func/mairyzo.f90", "max_issues_repo_name": "vasaantk/bin", "max_issues_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MATLAB/f2matlab/comp_spec_func/mairyzo.f90", "max_forks_repo_name": "vasaantk/bin", "max_forks_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.3762057878, "max_line_length": 67, "alphanum_fraction": 0.4495184136, "num_tokens": 3584, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240791017535, "lm_q2_score": 0.7956580927949807, "lm_q1q2_score": 0.6884225406183947}} {"text": "*----------------------------------------------------------------------_\n*\n Program MyEmp1\n*\n* Purpose: Solve the vibration problem\n*\n Implicit None\n*\n*-- Common Definitions\n*\n* Write file index\n Integer IOut, IOTmp\n Common /IO/ IOut, IOTmp\n* Calculation Parameter\n Double Precision Gmr\n Common /CalPar/ Gmr\n* Constants\n Double Precision Pi\n Common /Const/ Pi\n* Error Information\n Integer IStat\n Common /ErStat/ IStat\n* Global Integral grid number\n Integer IGridN\n Common /Grid/ IGridN\n* Zero Tolerence (Two values refers to the error or warning situation)\n Double Precision Thr0, ThrW0\n Common /ZeroTh/ Thr0, ThrW0\n* Deviation Threahold\n*!! Non-FORTRAN77 syntax: An effort to make the variables stored into\n*!! the memories of the same length\n Integer*8 ItrMax\n Double Precision DevX, DevY\n Common /DevThr/ ItrMax, DevX, DevY\n*\n*-- Internal Functions\n*\n Double Precision Itg5P1, Itg5P2, RtSecI, Func1\n External Itg5P1, ITg5P2, RtSecI, Func1\n Integer IFlr\n External IFlr\n*\n*-- Internal Variables\n*\n* Maximun Quantum Number (Related with DevX)\n Integer IQntN\n*\n*-----------------------------------------------------------------------\n\n*-- Initialize Common Variables\n\n* IO\n IOut = 11\n IOTmp = 12\n* CalPar\n Gmr = 200.0D0\n* Const\n Pi = DACos(-1.0D0)\n* ErStat\n IStat = 0\n* Grid\n IGridN = 100000\n* ZeroTh\n Thr0 = 1.0D-7\n ThrW0 = 1.0D-10\n* DevThr\n ItrMax = 150\n DevX = 1.0D-10\n DevY = 1.0D-10\n\n*-- File I/O \n Open(IOut, File='01-07.txt')\n\n*-- I/O Format\nC1000 Format (1x,A50)\nC1010 Format (1x,A50,A10,F15.7)\nC1020 Format (1x,A50,A10,8x,I7)\nC1030 Format (1x,A50,A10,D15.8)\n\n*-- Find Maximun Quantum Number and Call the Subroutine Main\n IQntN = IFlr(Func1(-DevX)/Pi-0.5D0)\n If (IQntN.EQ.0) then \n Print *, 'No acceptable quantum number! Exit Program!'\n Stop\n End If\n Call MainPg(IQntN)\n\n Stop\n End Program MyEmp1\n\n*----------------------------------------------------------------------_\n*\n Subroutine MainPg(IQntN)\n*\n* Purpose: Main program for this problem\n*\n Implicit None\n*\n*-- Common Definitions\n*\n* Write file index\n Integer IOut, IOTmp\n Common /IO/ IOut, IOTmp\n* Calculation Parameter\n Double Precision Gmr\n Common /CalPar/ Gmr\n* Constants\n Double Precision Pi\n Common /Const/ Pi\n* Error Information\n Integer IStat\n Common /ErStat/ IStat\n* Global Integral grid number\n Integer IGridN\n Common /Grid/ IGridN\n* Deviation Threahold\n*!! Non-FORTRAN77 syntax: An effort to make the variables stored into\n*!! the memories of the same length\n Integer*8 ItrMax\n Double Precision DevX, DevY\n Common /DevThr/ ItrMax, DevX, DevY\n*\n*-- Internal Functions\n*\n Double Precision Itg5P1, Itg5P2, RtSecI, Func1, IFlr\n External Itg5P1, ITg5P2, RtSecI, Func1, IFlr\n*\n*-- Internal Variables\n*\n* Dummy\n Integer I\n* Maximun Quantum Number (Related with DevX)\n Integer IQntN\n* Internal Root Guess \n Double Precision RtLoI, RtUpI\n* Internal Result Temporary Store\n Double Precision RtI\n* Result\n Integer IQntV(IQntN+1)\n Double Precision EngV(IQntN+1), ItgLoV(IQntN+1), ItgUpV(IQntN+1)\n*\n*-----------------------------------------------------------------------\n\n*-- I/O Format\n 1000 Format(A47)\n 1010 Format(A8,A15,2(A12))\n 1020 Format(I8,F15.6,2(F12.6))\n 1030 Format(I8,D15.5,2(F12.6))\n\n*-- Set the first root search condition\n RtLoI = -1.0D0+DevX\n RtUpI = -DevX\n \n Do 10 I = 0, IQntN\n* Root Solve\n RtI = RtSecI(Func1, (DBLE(I)+0.5D0)*Pi, RtLoI, RtUpI)\n* Result Write In\n IQntV(I+1) = I\n EngV(I+1) = RtI\n ItgLoV(I+1) = 1.5D0 - 0.5D0 * Sqrt(1.0D0 + RtI)\n ItgUpV(I+1) = 1.5D0 + 0.5D0 * Sqrt(1.0D0 + RtI)\n* Prepare for the next solve\n RtLoI = RtI\n RtUpI = RtI * 1.0D-5\n If (RtUpI.GT.-DevX) RtUpI = DevX\n 10 Continue\n\n Write(IOut,1000) '-----------------------------------------------'\n Write(IOut,1010) ' Level', ' Energy', ' XMin',\n $ ' XMax'\n Write(IOut,1000) '-----------------------------------------------'\n Do 20 I = 0, IQntN\n If(-EngV(I+1).GE.1.0D-2) then\n Write(IOut,1020) IQntV(I+1), EngV(I+1), ItgLoV(I+1), ItgUpV(I+1)\n Else\n Write(IOut,1030) IQntV(I+1), EngV(I+1), ItgLoV(I+1), ItgUpV(I+1)\n End If\n 20 Continue\n Write(IOut,1000) '-----------------------------------------------'\n\n End Subroutine MainPg\n\n************************************************************************\n* *\n* USER DEFINE SUBROUTINES *\n* *\n************************************************************************\n\n*-----------------------------------------------------------------------\n*\n Function Func1(Eng)\n*\n* Purpose: The integral of the Gmr * (e - v(x))^0.5\n* Note: This function actually has two variables: x, Gmr. Gmr is\n* pre-defined by the common blocks.\n*\n Implicit None\n*\n*-- Common Definitions\n Integer IOut, IOTmp\n Common /IO/ IOut, IOTmp\n* Error Information\n Integer IStat\n Common /ErStat/ IStat\n* Calculation Parameter\n Double Precision Gmr\n Common /CalPar/ Gmr\n* Global Integral grid number\n Integer IGridN\n Common /Grid/ IGridN\n*\n*-- Variables\n*\n Double Precision Func1, Eng\n*\n*-- Internal Variables\n*\n* Integral Limit\n Double Precision IntgLo, IntgUp\n* Integral Core Function\n Double Precision Func1C\n External Func1C\n* Integral Routine\n Double Precision Itg5P2\n External Itg5P2\n*\n*-----------------------------------------------------------------------\n\n IntgLo = 1.5D0 - 0.5D0 * Sqrt(1.0D0 + Eng)\n IntgUp = 1.5D0 + 0.5D0 * Sqrt(1.0D0 + Eng)\n\n Func1 = Gmr * Itg5P2(Func1C, Eng, IntgLo, IntgUp, IGridN)\n\n Call Err\n Return\n End Function Func1\n\n*-----------------------------------------------------------------------\n*\n Function Func1C(Eng, Var)\n*\n* Purpose: The integral core of Func1\n*\n Implicit None\n*\n*-- Common Definitions\n*\n* Write file index\n Integer IOut, IOTmp\n Common /IO/ IOut, IOTmp\n* Error Information\n Integer IStat\n Common /ErStat/ IStat\n*\n Double Precision Func1C, Eng, Var\n Double Precision Tmp\n*\n*-----------------------------------------------------------------------\n\n Tmp = Eng - 4.0D0 * (Var-1.5)**2 + 1 \n Call Test0(Tmp)\n Func1C = DSqrt(Tmp)\n\n End Function Func1C\n\n************************************************************************\n* *\n* MATHEMATICAL BACKGROUND UTILITIES *\n* *\n************************************************************************\n\n*-----------------------------------------------------------------------\n*\n Subroutine Err\n*\n* Purpose: The integral core of Func1\n*\n Implicit None\n*\n*-- Common Definitions\n*\n* Write file index\n Integer IOut, IOTmp\n Common /IO/ IOut, IOTmp\n* Error Information\n Integer IStat\n Common /ErStat/ IStat\n*\n*-----------------------------------------------------------------------\n\n If (IStat.GT.0) then\n Write(IOut,*) 'Error Return!'\n Write(IOut,*) 'Return Code: ', IStat\n Stop\n End If\n\n End Subroutine\n\n************************************************************************\n* *\n* MATHEMATICAL BACKGROUND UTILITIES *\n* *\n************************************************************************\n\n*-----------------------------------------------------------------------\n*\n Subroutine DmMath\n*\n* Purpose: Present the commonly used variables and subroutines\n* There should be no routines call this subroutine.\n*\n* Note: All variables are predefined as double precision; all\n* subroutines are specified by double precision. If\n* variables are defined as Integer / Single Float /\n* Logical, then the first letter of the names of the\n* variables should implicit it's precision (I/S/L), and\n* it's second letter should be upper case.\n*\n*-- Variables \n*\n Double Precision Var, Var1, Var2, Var3\n* Var(x) Input variables which need no explanations\n Integer IGridN\n* IGridN Grid numbers for various methods\n Double Precision DevThr(3)\n* DevThr 1: Maximun Iteration Number (Stored by double)\n* 2: Maximun Deviation by X axis\n* 3: Maximun Deviation by Y axis\n*\n*-- Subroutines\n*\n* \n*\n*-- Functions\n*\n* Integer DFlr Evaluate the floor of a double precision\n* float number\n* Double Itg5P1 Integral using Bode's method\n* Double RtSecI Find root inside certain area\n* \n*\n*-----------------------------------------------------------------------\n\n End subroutine DmMath\n\n*-----------------------------------------------------------------------\n*\n Function RtSecI(Func, Num, RtLo, RtUp)\n*\n* Purpose: Find the root with secant method, where the first two\n* guesses are provided mannually.\n* The root-finding problem should be expressed as:\n* Func(Root) == Num\n*\n Implicit None\n*\n*-- Common Blocks\n* Error Information\n Integer IStat\n Common /ErStat/ IStat\n* Deviation Threahold\n Integer*8 ItrMax\n Double Precision DevX, DevY\n Common /DevThr/ ItrMax, DevX, DevY\n*\n*-- Variables\n*\n Double Precision RtSecI, Func, Num, RtLo, RtUp\n External Func\n*\n* Func The function we are concerning\n* Num The right hand side of the equation\n* RtLo The minimun guess\n* RtUp The maximun guess\n* DevThr Deviation Threahold\n*\n* Note: Should have (Func(RtLo)-Num) * (Func(RtUp)-Num) < 0\n* or we probably have no or even roots inside within the maximun\n* guess or the minimun guess.\n*\n*-- Internal Variables\n*\n* Iteration Dummy\n Integer Itr\n* Internal maximun and minimun guess\n Double Precision RtLoI, RtUpI\n* Internal Result\n Double Precision FncLo, FncUp, FncSec\n*\n*-----------------------------------------------------------------------\n\n* Initialize internal guess\n RtLoI = RtLo\n RtUpI = RtUp\n Itr = 0\n FncLo = Func(RtLoI) - Num\n FncUp = Func(RtUpI) - Num\n\n* Find the root\n 10 Continue\n Itr = Itr + 1\n RtSecI = ( RtLoI * FncUp - RtUpI * FncLo ) / ( FncUp - FncLo )\n FncSec = Func(RtSecI) - Num\n RtLoI = RtUpI\n FncLo = FncUp\n RtUpI = RtSecI\n FncUp = FncSec\n* Converge Judgement\n If ( (Itr.LT.ItrMax).And.( DAbs(RtUpI-RtLoI).GT.DevX.Or.\n $ (DAbs(FncUp).GT.DevY.And.(FncUp-FncLo).GT.DevY))) then\n* Not converged\n Go To 10\n Else If ( (Itr.GE.ItrMax).And.( DAbs(RtUpI-RtLoI).GT.DevX.Or.\n $ (DAbs(FncUp).GT.DevY.And.(FncUp-FncLo).GT.DevY))) then\n* Not converged but reached the maximun iteration\n Print *, 'Error Info in Function [RtSecI]'\n Print *, 'Not converged but reached the maximun iteration'\n Print *, 'Last Iteration Information:'\n Print *, 'Upper Guess: ', RtUpI, ' Lower Guess: ', RtLoI, \n $ 'Upper Func: ', FncUp, ' Lower Guess: ', FncLo\n IStat = 1\n Else\n Return\n End If\n\n Call Err\n Return\n End Function RtSecI\n\n*-----------------------------------------------------------------------\n*\n Function Itg5P1(Func, IntgLo, IntgUp, IGridN)\n*\n* Purpose: Integral using Bode's method (Func(Var))\n*\n*-- Variables\n*\n Implicit None\n*\n Double Precision Itg5P1, Func, IntgLo, IntgUp\n Integer IGridN\n External Func\n*\n* Func The function integrated\n* IntgUp Upper limit of the integral\n* InteLo Lower limit of the integral\n*\n*-- Internal Variables\n*\n* Decleared elsewere\n Integer IFlr\n External IFlr\n* Dummy\n Integer I\n* Iteration Number\n Integer Itr\n* Iteration Maximun\n Integer ItrMax\n* Grid Seperation\n Double Precision H\n*\n*-----------------------------------------------------------------------\n\n* Redefining Integral grids and make the separation\n Itr = IFlr(DBLE(IGridN) / 4.0D0)\n H = (IntgUp - IntgLo) / (4.0D0 * DBLE(Itr))\n\n* Initial and final point calculation\n Itg5P1 = 7.0D0 * (Func(IntgLo) - Func(IntgUp))\n\n* Internal grid point calculation\n Do 10 I = 1, Itr\n Itg5P1 = Itg5P1 + 32.0D0 * Func(IntgLo + DBLE(I*4-3) * H)\n $ + 12.0D0 * Func(IntgLo + DBLE(I*4-2) * H)\n $ + 32.0D0 * Func(IntgLo + DBLE(I*4-1) * H)\n $ + 14.0D0 * Func(IntgLo + DBLE(I*4 ) * H)\n 10 Continue\n\n* Coefficient multiplication\n Itg5P1 = Itg5P1 * H * 2.0D0 / 45.0D0\n\n Call Err\n Return\n End Function \n\n*-----------------------------------------------------------------------\n*\n Function Itg5P2(Func, VM, IntgLo, IntgUp, IGridN)\n*\n* Purpose: Integral using Bode's method (Func(VM, VarMain,VarInt))\n*\n*-- Variables\n*\n Implicit None\n*\n Double Precision Itg5P2, Func, IntgLo, IntgUp, VM\n Integer IGridN\n External Func\n*\n* Func The function integrated\n* IntgUp Upper limit of the integral\n* InteLo Lower limit of the integral\n* VM Main Variable but not used in the integral\n*\n*-- Internal Variables\n*\n* Decleared elsewere\n Integer IFlr\n External IFlr\n* Dummy\n Integer I\n* Iteration Number\n Integer Itr\n* Iteration Maximun\n Integer ItrMax\n* Grid Seperation\n Double Precision H\n*\n*-----------------------------------------------------------------------\n\n* Redefining Integral grids and make the separation\n Itr = IFlr(DBLE(IGridN) / 4.0D0)\n H = (IntgUp - IntgLo) / (4.0D0 * DBLE(Itr))\n\n* Initial and final point calculation\n Itg5P2 = 7.0D0 * (Func(VM, IntgLo) - Func(VM, IntgUp))\n\n* Internal grid point calculation\n Do 10 I = 1, Itr\n Itg5P2 = Itg5P2 + 32.0D0 * Func(VM, IntgLo + DBLE(I*4-3) * H)\n $ + 12.0D0 * Func(VM, IntgLo + DBLE(I*4-2) * H)\n $ + 32.0D0 * Func(VM, IntgLo + DBLE(I*4-1) * H)\n $ + 14.0D0 * Func(VM, IntgLo + DBLE(I*4 ) * H)\n 10 Continue\n\n* Coefficient multiplication\n Itg5P2 = Itg5P2 * H * 2.0D0 / 45.0D0\n\n Call Err\n Return\n End Function \n\n*-----------------------------------------------------------------------\n* \n Function IFlr(Var)\n*\n* Purpose: Evaluate the floor of a double precision float number\n*\n*-- Variables \n*\n Implicit None\n*\n Integer IFlr\n Double Precision Var\n*\n*-----------------------------------------------------------------------\n\n IFlr = Int(Var)\n\n If (Var.LT.0.0D0) IFlr = IFlr - 1\n \n Return\n End Function IFlr\n\n\n*-----------------------------------------------------------------------\n*\n Subroutine Test0(Var)\n*\n Implicit None\n*\n*-- Common Definitions\n*\n* Write file index\n Integer IOut, IOTmp\n Common /IO/ IOut, IOTmp\n* Error Information\n Integer IStat\n Common /ErStat/ IStat\n* Zero Tolerence (Two values refers to the error or warning situation)\n Double Precision Thr0, ThrW0\n Common /ZeroTh/ Thr0, ThrW0\n*\n*-- Variables\n Double Precision Var\n*\n*-----------------------------------------------------------------------\n\n If (Var.LT.0) then\n If (-Var.LE.ThrW0) then\n Var = 0.0D0\n Else If (-Var.LE.Thr0) then\n Write(IOut,*)'Tested variable less than 0 but larger than 1.0D-15'\n Write(IOut,*) 'Variable value: ', Var\n Var = 0.0D0\n Else\n Write(IOut,*) 'Tested variable less than 0. Error return.'\n Write(IOut,*) 'Variable value: ', Var\n IStat = 1\n Return\n End If\n End If\n\n Call Err\n Return\n End Subroutine Test0\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "08428ce36f91f7946353f47e56e6fe631822607a", "size": 17167, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "Exercise/Chapter-01/01-07/01-07.for", "max_stars_repo_name": "ajz34/Comp-Phys-Koonin", "max_stars_repo_head_hexsha": "9fc371bdb44b7030025d254eda040a55bfa3b7cd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-10-29T12:21:38.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-31T17:03:43.000Z", "max_issues_repo_path": "Exercise/Chapter-01/01-07/01-07.for", "max_issues_repo_name": "ajz34/Comp-Phys-Koonin", "max_issues_repo_head_hexsha": "9fc371bdb44b7030025d254eda040a55bfa3b7cd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Exercise/Chapter-01/01-07/01-07.for", "max_forks_repo_name": "ajz34/Comp-Phys-Koonin", "max_forks_repo_head_hexsha": "9fc371bdb44b7030025d254eda040a55bfa3b7cd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.8233387358, "max_line_length": 72, "alphanum_fraction": 0.4815634648, "num_tokens": 4743, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240686758841, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.6884225344191668}} {"text": " SUBROUTINE mapxy (X,Y,ALAT,ALONG,SLAT,SLON,SGN,E,RE)\nC$*****************************************************************************\nC$ *\nC$ *\nC$ DESCRIPTION: *\nC$ *\nC$ This subroutine converts from Polar Stereographic (X,Y) coordinates *\nC$ to geodetic latitude and longitude for the polar regions. The equations *\nC$ are from Snyder, J. P., 1982, Map Projections Used by the U.S. *\nC$ Geological Survey, Geological Survey Bulletin 1532, U.S. Government *\nC$ Printing Office. See JPL Technical Memorandum 3349-85-101 for further *\nC$ details. *\nC$ *\nC$ *\nC$ ARGUMENTS: *\nC$ *\nC$ Variable Type I/O Description *\nC$ *\nC$ X REAL I Polar Stereographic X Coordinate (km) *\nC$ Y REAL I Polar Stereographic Y Coordinate (km) *\nC$ ALAT REAL O Geodetic Latitude (degrees, +90 to -90) *\nC$ ALONG REAL O Geodetic Longitude (degrees, 0 to 360) *\nC$ *\nC$ *\nC$ Written by C. S. Morris - April 29, 1985 *\nC$ Revised by C. S. Morris - December 11, 1985 *\nC$ *\nC$ Revised by V. J. Troisi - January 1990 *\nC$ SGN - provide hemisphere dependency (+/- 1) *\nC$ *\nC LAST MODIFIED 6 April 1994 Robert Grumbine *\nC$*****************************************************************************\n IMPLICIT none\n\n REAL X,Y,ALAT,ALONG,E,E2,CDR,PI, SLAT, SLON\n REAL CHI, CM, RE, RHO, SGN, SL, T\nC$*****************************************************************************\nC$ *\nC$ DEFINITION OF CONSTANTS: *\nC$ *\nC$ Conversion constant from degrees to radians = 57.29577951. *\n CDR=57.29577951\n E2=E*E\n PI=3.141592654\nC$ *\nC$*****************************************************************************\n SL = SLAT*PI/180.\n RHO=SQRT(X**2+Y**2)\n\n IF (RHO .LE. 0.1) THEN\n ALAT=90.*SGN\n ALONG=0.0\n ELSE\n CM=COS(SL)/SQRT(1.0-E2*(SIN(SL)**2))\n T=TAN((PI/4.0)-(SL/(2.0)))/((1.0-E*SIN(SL))/\n 1 (1.0+E*SIN(SL)))**(E/2.0)\n\n IF (ABS(SLAT-90.).LT.1.E-5) THEN\n T=RHO*SQRT((1.+E)**(1.+E)*(1.-E)**(1.-E))/2./RE\n ELSE\n T=RHO*T/(RE*CM)\n END IF\n CHI=(PI/2.0)-2.0*ATAN(T)\n ALAT=CHI + ((E2/2.0) + (5.0*E2**2.0/24.0) + \n 1 (E2**3.0/12.0))*SIN(2*CHI) + \n 2 ((7.0*E2**2.0/48.0) + (29.0*E2**3/240.0))*SIN(4.0*CHI) + \n 3 (7.0*E2**3.0/120.0)*SIN(6.0*CHI)\n\n ALAT = SGN*ALAT\n ALONG = ATAN2(SGN*Y, SGN*X)\n ALONG = SGN*ALONG\n ALAT = ALAT * CDR\n ALONG = ALONG * CDR - SLON \n\n ENDIF\n\n RETURN\n END\n", "meta": {"hexsha": "39ba9a1744f45458f591b2001c7aaad03ff6ebe0", "size": 4107, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "sorc/mapxy.f", "max_stars_repo_name": "rgrumbine/mmablib", "max_stars_repo_head_hexsha": "107ba1b1026c3cfed97346233c9a76d3d170d544", "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": "sorc/mapxy.f", "max_issues_repo_name": "rgrumbine/mmablib", "max_issues_repo_head_hexsha": "107ba1b1026c3cfed97346233c9a76d3d170d544", "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": "sorc/mapxy.f", "max_forks_repo_name": "rgrumbine/mmablib", "max_forks_repo_head_hexsha": "107ba1b1026c3cfed97346233c9a76d3d170d544", "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": 51.9873417722, "max_line_length": 79, "alphanum_fraction": 0.2963233504, "num_tokens": 950, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541659378681, "lm_q2_score": 0.7310585727705127, "lm_q1q2_score": 0.6884043505939453}} {"text": "module sw_utils\n implicit none\n private\n logical, save :: sw_allocated = .false.\n ! - double precision\n integer, parameter, public :: idp = kind(1.0d0)\n\n real(idp), parameter, public :: PI = 4.0_idp*atan(1.0)\n\n ! -------------------------------------\n ! number of point in x and y directions\n ! -------------------------------------\n integer, parameter, public :: NX = 101\n integer, parameter, public :: NY = 101\n\n ! --------------------\n ! number of time steps\n ! --------------------\n integer, parameter, public :: NT = 10001\n\n ! ----------------------------------------------\n ! upper and lower bounds for x and y dimensions\n ! ----------------------------------------------\n real(idp), parameter, public :: XUPPER = 5.0_idp ! xend\n real(idp), parameter, public :: XLOWER = -5.0_idp ! xstart\n real(idp), parameter, public :: YUPPER = 6.0_idp ! ystart\n real(idp), parameter, public :: YLOWER = -6.0_idp ! yend\n\n ! -----------------------------\n ! start and end point for time\n ! -----------------------------\n real(idp), parameter, public :: TSTART = 0.0_idp\n real(idp), parameter, public :: TEND = 1000.0_idp\n\n ! ----------------------------\n ! length of x-axis and y-axis\n ! ----------------------------\n real(idp), parameter, public :: XLENGTH = (XUPPER - XLOWER)\n real(idp), parameter, public :: YLENGTH = (YUPPER - YLOWER)\n\n ! -----------------------\n ! total time or duration\n ! -----------------------\n real(idp), parameter, public :: TLENGTH = (TEND - TSTART)\n\n ! ---------------------------\n ! spatial grid step dx and dy\n ! ---------------------------\n real(idp), parameter, public :: DX = XLENGTH/dble(NX-1)\n real(idp), parameter, public :: DY = YLENGTH/dble(NY-1)\n\n ! ----------\n ! time step\n ! ----------\n real(idp), parameter, public :: DT = TLENGTH/dble(NT-1)\n \n\n ! ---------------------\n ! gravitation constant\n ! ---------------------\n real(idp), parameter, public :: G = 9.8065_idp\n\n ! ------------\n ! base height\n ! ------------\n real(idp), parameter, public :: H0 = 1.0_idp\n\n ! --------------------------\n ! rotation parameter, omega\n ! --------------------------\n real(idp), parameter, public :: OMEGA = 0.1_idp\n\n ! -------------\n ! viscous drag\n ! -------------\n real(idp), parameter, public :: vd = 0.001_idp\n\n ! -----------------------\n ! viscosity of the fluid\n ! -----------------------\n real(idp), parameter, public :: nu = 0.000015_idp\n \n ! -------------\n ! perturbation\n ! -------------\n real(idp), parameter, public :: PERTURB = 0.01_idp\n\n ! ----------------------\n ! output data file name\n ! ----------------------\n character(len=*), parameter, public :: swfname = \"sw_data.nc\"\n\n ! =====================================\n ! public variables' name and constants\n ! =====================================\n real(idp), dimension(1:NX), public :: xdata\n real(idp), dimension(1:NY), public :: ydata\n real(idp), allocatable, public :: tdata(:)\n real(idp), allocatable, public :: xxdata(:, :)\n real(idp), allocatable, public :: yydata(:, :)\n real(idp), allocatable, public :: fdata(:, :)\n real(idp), allocatable, public :: udata(:, :, :)\n real(idp), allocatable, public :: vdata(:, :, :)\n real(idp), allocatable, public :: hdata(:, :, :)\n\n ! ---------------------------------\n ! public subroutines and functions\n ! ---------------------------------\n public swMeshgrid\n public swAllocateData\n public swDeallocateData\n public swSaveData\n\ncontains\n subroutine swAllocateData()\n implicit none\n if ( .not. sw_allocated ) then\n allocate(tdata(NT))\n allocate(xxdata(NX, NY))\n allocate(yydata(NX, NY))\n allocate(fdata(NX, NY))\n allocate(udata(NX, NY, NT))\n allocate(vdata(NX, NY, NT))\n allocate(hdata(NX, NY, NT))\n sw_allocated = .true.\n endif\n end subroutine swAllocateData\n\n subroutine swDeallocateData()\n implicit none\n if (sw_allocated) then\n deallocate(tdata)\n deallocate(xxdata)\n deallocate(yydata)\n deallocate(fdata)\n deallocate(udata)\n deallocate(vdata)\n deallocate(hdata)\n sw_allocated = .false.\n endif\n end subroutine swDeallocateData\n\n ! ---\n subroutine swMeshgrid(x, y, xx, yy, nx, ny)\n implicit none\n integer, intent(in) :: nx, ny\n real(kind=8), dimension(1:nx), intent(in) :: x\n real(kind=8), dimension(1:ny), intent(in) :: y\n real(kind=8), dimension(1:nx, 1:ny), intent(out) :: xx, yy\n xx = spread(x, 1, size(y))\n yy = spread(y, 2, size(x))\n end subroutine swMeshgrid\n\n subroutine swSaveData()\n use netcdf\n implicit none\n\n ! -----------------------------------------\n ! number of dimensions for large variables\n ! -----------------------------------------\n integer, parameter :: NDIMS3 = 3\n integer, parameter :: NDIMS2 = 2\n\n ! ------------------------\n ! id for netcdf variables\n ! ------------------------\n integer :: ncid\n\n ! ----------------\n ! dimension names\n ! ----------------\n character(len=*), parameter :: xname = \"X Distance\"\n character(len=*), parameter :: yname = \"Y Distance\"\n character(len=*), parameter :: tname = \"T Time\"\n\n ! --------------\n ! dimension ids\n ! --------------\n integer :: xdimID, ydimID, tdimID\n\n ! --------------------\n ! shape of dimensions\n ! --------------------\n integer :: dimID3(NDIMS3)\n integer :: dimID2(NDIMS2)\n\n ! ---------------\n ! variable names\n ! ---------------\n character(len=*), parameter :: uname = \"U_Velocity\"\n character(len=*), parameter :: vname = \"V_Velocity\"\n character(len=*), parameter :: hname = \"H_Level\"\n character(len=*), parameter :: fname = \"F_Coriolis\"\n\n ! ----------------------------------\n ! Units for the dimension variables\n ! ----------------------------------\n character(len=*), parameter :: units = \"units\"\n character(len=*), parameter :: u_units = \"m/s\"\n character(len=*), parameter :: v_units = \"m/s\"\n character(len=*), parameter :: h_units = \"m\"\n character(len=*), parameter :: f_units = \"1/s\"\n character(len=*), parameter :: x_units = \"meters_east\"\n character(len=*), parameter :: y_units = \"meters_north\"\n character(len=*), parameter :: t_units = \"seconds_forward\"\n\n ! ---------------------------\n ! variable IDs for variables\n ! ---------------------------\n integer :: uvarID, vvarID, hvarID, fvarID\n\n ! -----------------------------------------\n ! variable IDs for the dimension variables\n ! -----------------------------------------\n integer :: xvarID, yvarID, tvarID\n\n write(*, *) \"Defined all data variables and their IDs.\"\n\n ! ----------------\n ! create the file\n ! ----------------\n call check(nf90_create( &\n swfname, or(nf90_clobber, nf90_64bit_offset), ncid) &\n )\n \n ! ----------------------\n ! define the dimensions\n ! ----------------------\n call check(nf90_def_dim(ncid, xname, NX, xdimID))\n call check(nf90_def_dim(ncid, yname, NY, ydimID))\n call check(nf90_def_dim(ncid, tname, NT, tdimID))\n\n ! ---------------------------\n ! create dimension variables\n ! ---------------------------\n call check(nf90_def_var(ncid, xname, NF90_DOUBLE, xdimID, xvarID))\n call check(nf90_def_var(ncid, yname, NF90_DOUBLE, ydimID, yvarID))\n call check(nf90_def_var(ncid, tname, NF90_DOUBLE, tdimID, tvarID))\n\n ! ----------------------------------\n ! set attributes for the dimensions\n ! ----------------------------------\n call check(nf90_put_att(ncid, xvarID, units, x_units))\n call check(nf90_put_att(ncid, yvarID, units, y_units))\n call check(nf90_put_att(ncid, tvarID, units, t_units))\n\n write(*, *) \"Dimensions' unit attribute added\"\n\n ! ----------------------\n ! create variable slots\n ! ----------------------\n dimID3 = (/ xdimID, ydimID, tdimID /)\n dimID2 = (/ xdimID, ydimID /)\n\n call check(nf90_def_var(ncid, uname, NF90_DOUBLE, dimID3, uvarID))\n call check(nf90_def_var(ncid, vname, NF90_DOUBLE, dimID3, vvarID))\n call check(nf90_def_var(ncid, hname, NF90_DOUBLE, dimID3, hvarID))\n call check(nf90_def_var(ncid, fname, NF90_DOUBLE, dimID2, fvarID))\n\n write(*, *) \"Data variables created\"\n\n ! ----------------------------------\n ! set attribute for data variabales\n ! ----------------------------------\n call check(nf90_put_att(ncid, uvarID, units, u_units))\n call check(nf90_put_att(ncid, vvarID, units, v_units))\n call check(nf90_put_att(ncid, hvarID, units, h_units))\n call check(nf90_put_att(ncid, fvarID, units, f_units))\n\n write(*, *) \"Data variable unit attribute added\"\n\n ! --------------------------\n ! clode variable definition\n ! --------------------------\n call check(nf90_enddef(ncid))\n\n ! ------------------------------\n ! write the dimension variables\n ! ------------------------------\n call check(nf90_put_var(ncid, xvarID, xdata))\n write(*, *) \"Wrote x dimension variable\"\n call check(nf90_put_var(ncid, yvarID, ydata))\n write(*, *) \"Wrote y dimension variable\"\n call check(nf90_put_var(ncid, tvarID, tdata))\n write(*, *) \"Wrote t dimension variable\"\n\n ! -------------------------\n ! write the data variables\n ! -------------------------\n call check(nf90_put_var(ncid, uvarID, udata))\n write(*, *) \"Wrote u data variable\"\n call check(nf90_put_var(ncid, vvarID, vdata))\n write(*, *) \"Wrote v data variable\"\n call check(nf90_put_var(ncid, hvarID, hdata))\n write(*, *) \"Wrote h (i.e height) data variable\"\n call check(nf90_put_var(ncid, fvarID, fdata))\n write(*, *) \"Wrote f (i.e coriolis) data variable\"\n\n ! --------------\n ! close the file\n ! ---------------\n call check(nf90_close(ncid))\n \n contains\n subroutine check(status)\n implicit none\n integer, intent(in) :: status\n if(status /= nf90_noerr) then\n write(*, *) trim(nf90_strerror(status))\n stop \"Stopped\"\n endif\n end subroutine check\n end subroutine swSaveData\nend module sw_utils\n", "meta": {"hexsha": "08d28558cd3888f7865f654e6824cc9bd0aa3c08", "size": 10974, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "ShallowWater/src/sw_utils.f95", "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": "ShallowWater/src/sw_utils.f95", "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": "ShallowWater/src/sw_utils.f95", "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": 34.8380952381, "max_line_length": 74, "alphanum_fraction": 0.4669218152, "num_tokens": 2654, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.6884012169580551}} {"text": "PROGRAM gd_test\n USE randmod\n USE general_tools\n USE debug_tools\n USE checkpoint\n USE gd_tools\nIMPLICIT NONE\n INTEGER, PARAMETER :: &\n ip_xsize=512,&\n ip_ysize=510\n REAL(KIND=cp), PARAMETER ::&\n rp_xmin = -2*rp_pi,&\n rp_xmax = +2*rp_pi,&\n rp_ymin = -2*rp_pi,&\n rp_ymax = +2*rp_pi\n\n !CALL test_1D()\n CALL test_2D()\n\nCONTAINS\n\n SUBROUTINE test_1D()\n INTEGER :: ibi\n REAL(KIND=cp) :: rl_dx, rl_rand\n REAL(KIND=cp), DIMENSION(ip_xsize) :: rla_x, rla_phi, rla_f, rla_f_noise, rla_f_gd, rla_res\n TYPE(dyn_rVector), DIMENSION(4) :: tla_save\n\n rl_dx = (rp_xmax - rp_xmin)/REAL(ip_xsize-1)\n DO ibi = 1, ip_xsize\n rla_x(ibi) = rp_xmin+REAL(ibi-1, cp)*rl_dx\n END DO\n rla_f = 1.0*sin(rla_x)\n rla_phi = 1.0\n !initializing random numbers generator\n CALL init_normal_rand(mu=0.0_cp, sigma=0.5_cp, radius=1.5_cp, nright=256, stat=.FALSE.)\n !Adding noise\n DO ibi = 1, ip_xsize\n CALL normal_rand(rl_rand)\n rla_f_noise(ibi) = rla_f(ibi) + rl_rand\n rla_phi(ibi) = 1.0 - MIN( 1.0, ABS(rl_rand) )\n END DO\n\n CALL gd_projection(rla_f_noise, rla_f_gd, rla_phi, rl_dx, 50)\n rla_res = rla_f_gd-rla_f\n tla_save(1) = rla_x\n tla_save(2) = rla_f\n tla_save(3) = rla_f_noise\n tla_save(4) = rla_f_gd\n CALL debug('', 'Original noise *****************************')\n CALL debug(MAXVAL( ABS(rla_f_noise) ), ' MAXVAL = ')\n CALL debug(SUM( ABS(rla_f_noise) )/ip_xsize, ' MEAN = ')\n CALL debug(SQRT( SUM(rla_f_noise**2) ), ' L2 norm = ')\n CALL debug('', '********************************************')\n CALL debug('', 'Residual from GD ***************************')\n CALL debug(MAXVAL( ABS(rla_res) ), ' MAXVAL = ')\n CALL debug(SUM( ABS(rla_res) )/ip_xsize, ' MEAN = ')\n CALL debug(SQRT( SUM(rla_res**2) ), ' L2 norm = ')\n CALL debug('', '********************************************')\n\n CALL save_trj( tla_save(2:4), 'runtime_gd_test.dat', ld_column = .TRUE. )\n CALL reset_drv_array( tla_save )\n CALL finilize_normal_rand()\n CALL debug('', 'GD_test 1D end')\n END SUBROUTINE test_1D\n\n SUBROUTINE test_2D()\n INTEGER :: ibi, ibj\n REAL(KIND=cp) :: rl_dx, rl_dy, rl_rand\n REAL(KIND=cp), DIMENSION(ip_xsize, ip_ysize) :: rla_x, rla_y, rla_phi, rla_f, rla_f_noise, rla_f_gd, rla_res\n TYPE(dyn_rVector), DIMENSION(4) :: tla_save\n\n rl_dx = (rp_xmax - rp_xmin)/REAL(ip_xsize-1)\n rl_dy = (rp_ymax - rp_ymin)/REAL(ip_ysize-1)\n DO ibi = 1, ip_xsize\n rla_x(ibi, :) = rp_xmin+REAL(ibi-1, cp)*rl_dx\n END DO\n DO ibj = 1, ip_ysize\n rla_y(:, ibj) = rp_ymin+REAL(ibj-1, cp)*rl_dy\n END DO\n rla_f = 1.0*sin(SQRT(rla_x**2 + rla_y**2))\n rla_phi = 1.0\n !initializing random numbers generator\n CALL init_normal_rand(mu=0.0_cp, sigma=0.5_cp, radius=1.5_cp, nright=256, stat=.FALSE.)\n !Adding noise\n DO ibj = 1, ip_ysize\n DO ibi = 1, ip_xsize\n CALL normal_rand(rl_rand)\n rla_f_noise(ibi, ibj) = rla_f(ibi, ibj) + rl_rand\n rla_phi(ibi, ibj) = 1.0 - MIN( 1.0, ABS(rl_rand) )\n END DO\n END DO\n\n CALL debug('', 'Calling gd_projection')\n CALL gd_projection(rla_f_noise, rla_f_gd, rla_phi, rl_dx, rl_dy, 20)\n rla_res = rla_f_gd-rla_f\n CALL debug('', 'After gd_projection')\n CALL debug('', 'Original noise *****************************')\n CALL debug(MAXVAL( ABS(rla_f_noise) ), ' MAXVAL = ')\n CALL debug(SUM( ABS(rla_f_noise) )/(ip_xsize*ip_xsize), ' MEAN = ')\n CALL debug(SQRT( SUM(rla_f_noise**2) ), ' L2 norm = ')\n CALL debug('', '********************************************')\n CALL debug('', 'Residual from GD ***************************')\n CALL debug(MAXVAL( ABS(rla_res) ), ' MAXVAL = ')\n CALL debug(SUM( ABS(rla_res) )/(ip_xsize*ip_xsize), ' MEAN = ')\n CALL debug(SQRT( SUM(rla_res**2) ), ' L2 norm = ')\n CALL debug('', '********************************************')\n\n! tla_save(1) = rla_x\n! tla_save(2) = rla_f\n! tla_save(3) = rla_f_noise\n! tla_save(4) = rla_f_gd\n! CALL save_trj( tla_save(2:4), 'runtime_gd_test.dat', ld_column = .TRUE. )\n! CALL reset_drv_array( tla_save )\n CALL finilize_normal_rand()\n CALL debug('', 'GD_test 2D end')\n END SUBROUTINE test_2D\n\nEND PROGRAM gd_test", "meta": {"hexsha": "00f539f3cec7014f4116782bfee3280893c67f61", "size": 4322, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/GD/gd_test.f90", "max_stars_repo_name": "souopgui/da-toolbox", "max_stars_repo_head_hexsha": "f274cdec4db272cc10bb142fdff095e40e4a702a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2015-04-25T03:30:32.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-04T00:41:31.000Z", "max_issues_repo_path": "src/GD/gd_test.f90", "max_issues_repo_name": "souopgui/da-toolbox", "max_issues_repo_head_hexsha": "f274cdec4db272cc10bb142fdff095e40e4a702a", "max_issues_repo_licenses": ["MIT"], "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/GD/gd_test.f90", "max_forks_repo_name": "souopgui/da-toolbox", "max_forks_repo_head_hexsha": "f274cdec4db272cc10bb142fdff095e40e4a702a", "max_forks_repo_licenses": ["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.6271186441, "max_line_length": 112, "alphanum_fraction": 0.5747339195, "num_tokens": 1542, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.7772998611746911, "lm_q1q2_score": 0.688401216958055}} {"text": " DOUBLE PRECISION FUNCTION DDASNM (NEQ, V, WT, RWORK, IWORK)\nc Copyright (c) 2006, Math a la Carte, Inc.\nc>> 2003-03-06 ddasnm Hanson changed norm computation to use reciprocals.\nc>> 2001-11-23 ddasnm Krogh Changed many names per library conventions.\nc>> 2001-11-04 ddasnm Krogh Fixes for F77 and conversion to single\nc>> 2001-11-01 ddasnm Hanson Provide code to Math a la Carte.\nc--D replaces \"?\": ?DASNM, ?DASLX\nc IMPLICIT NONE\nC***BEGIN PROLOGUE DDASNM\nC***SUBSIDIARY\nC***PURPOSE Compute vector norm for DDASLX.\nC***LIBRARY SLATEC (DDASLX)\nC***TYPE DOUBLE PRECISION (SDASNM-S, DDASNM-D)\nC***AUTHOR Petzold, Linda R., (LLNL)\nC***DESCRIPTION\nc ----------------------------------------------------------------------\nC THIS FUNCTION ROUTINE COMPUTES THE WEIGHTED\nC ROOT-MEAN-SQUARE NORM OF THE VECTOR OF LENGTH\nC NEQ CONTAINED IN THE ARRAY V,WITH WEIGHTS\nC CONTAINED IN THE ARRAY WT OF LENGTH NEQ.\nC DDASNM=SQRT((1/NEQ)*SUM(V(I)/WT(I))**2)\nc ----------------------------------------------------------------------\nC***ROUTINES CALLED (NONE)\nC***REVISION HISTORY (YYMMDD)\nC 830315 DATE WRITTEN\nC 901009 Finished conversion to SLATEC 4.0 format (F.N.Fritsch)\nC 901019 Merged changes made by C. Ulrich with SLATEC 4.0 format.\nC 901026 Added explicit declarations for all variables and minor\nC cosmetic changes to prologue. (FNF)\nC***END PROLOGUE DDASNM\nC\n INTEGER NEQ, IWORK(*)\n DOUBLE PRECISION V(NEQ), WT(NEQ), RWORK(*)\nC\n INTEGER I\n DOUBLE PRECISION SUM, VMAX\n\n EXTERNAL D1MACH\n DOUBLE PRECISION D1MACH, G, H, T\n INTEGER L\n\nC***FIRST EXECUTABLE STATEMENT DDASNM\n\n H=sqrt(sqrt(d1mach(2)))\n G=d1mach(1)/d1mach(4)\n sum=0.d0\n vmax=0.d0\n DO 100 I=1,NEQ\n t=abs(v(i)*wt(i))\nC If a component will have a square .gt. sqrt(huge) then\nC shift to a scaled version of the norm.\n if(t .gt. H) GO TO 110\n sum=sum+t**2\n vmax=max(vmax, t)\n\n 100 CONTINUE\nC May have a damaging underflow here. If vmax = 0 then \nC vector was flat zero. If sum of squares is .le. tiny/epsilon\nC then underflows (set to zero) may hurt accuracy. So \nC shift to a scaled version of the norm.\n I=NEQ+1\n if(sum .le. G .and. vmax .gt. 0.D0) GO TO 110\n ddasnm=sqrt(sum/neq)\n return\n\n 110 CONTINUE\n DDASNM = 0.0D0\n\nC Can start loop at I since the first I-1 components have\nC been scanned for the max abs already.\n DO 10 L = I,NEQ\n IF(ABS(V(L)*WT(L)) .GT. VMAX) VMAX = ABS(V(L)*WT(L))\n10 CONTINUE\n IF(VMAX .LE. 0.0D0) GO TO 30\n SUM = 0.0D0\n DO 20 I = 1,NEQ\n20 SUM = SUM + ((V(I)*WT(I))/VMAX)**2\n DDASNM = VMAX*SQRT(SUM/NEQ)\n30 CONTINUE\n RETURN\nc -----END OF FUNCTION DDASNM------\n END\n", "meta": {"hexsha": "876a42ecb708239d5e749a5e3ec081f93438e14c", "size": 2786, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/ddasnm.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/ddasnm.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/ddasnm.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": 33.5662650602, "max_line_length": 73, "alphanum_fraction": 0.6145010768, "num_tokens": 935, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314617436727, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.6884012168342015}} {"text": "c # ------------------------------------------------------------------\nc # MAPC2M_PILLOWDISK\nc # ------------------------------------------------------------------\nc #\nc # Maps a logically rectangular Cartesian grid in [-1,1]x[-1,1] to\nc # the unit disk.\nc #\nc # ------------------------------------------------------------------\n subroutine mapc2m_pillowdisk(blockno,xc1,yc1,xp,yp,zp)\n implicit none\n\n double precision xc1,yc1,xp,yp,zp\n double precision xc,yc,zc\n integer blockno\n\nc # Map to [-1,1]x[-1,1]\n call mapc2m_cart(blockno,xc1,yc1,xc,yc,zc)\n\nc # Get circle of radius sqrt(2.d0)\n call mapc2p_disk_circle(xc,yc,xp,yp)\n\n xp = xp/sqrt(2.d0)\n yp = yp/sqrt(2.d0)\n zp = 0\n\n return\n end\n\n\n subroutine mapc2p_disk_circle(x1,y1,xp,yp)\n implicit none\n\n double precision xc,yc,xp,yp, x1,y1\n double precision xi,eta,x,y, minxy,maxxy\n\n xc = x1\n yc = y1\n\n xi = min(abs(xc),abs(yc))\n eta = max(abs(xc),abs(yc))\n eta = max(eta,1.d-10)\n\n call map_disk_north_sector(xi,eta,x,y)\n\n minxy = min(abs(x),abs(y))\n maxxy = max(abs(x),abs(y))\n\n if (abs(xc) .le. abs(yc)) then\nc # In NS sectors\n xp = sign(1.d0,xc)*minxy\n yp = sign(1.d0,yc)*maxxy\n else\nc # In EW sectors\n xp = sign(1.d0,xc)*maxxy\n yp = sign(1.d0,yc)*minxy\n endif\n\n\n end\n\n subroutine map_disk_north_sector(xi,eta,x,y)\n implicit none\n\n double precision xi,eta,x,y\n\n x = xi\n y = sqrt(2 - xi**2) - sqrt(2 - eta**2) + eta\n\n end\n", "meta": {"hexsha": "ae5d09b74f3785644a49f4d8154c854892d66fe3", "size": 1629, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/mappings/pillowdisk/mapc2m_pillowdisk.f", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2017-09-26T13:39:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:56:23.000Z", "max_issues_repo_path": "src/mappings/pillowdisk/mapc2m_pillowdisk.f", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 75, "max_issues_repo_issues_event_min_datetime": "2017-08-02T19:56:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T12:36:32.000Z", "max_forks_repo_path": "src/mappings/pillowdisk/mapc2m_pillowdisk.f", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-02-21T00:10:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T19:08:36.000Z", "avg_line_length": 23.2714285714, "max_line_length": 74, "alphanum_fraction": 0.4769797422, "num_tokens": 511, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037282594921, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6883992971009236}} {"text": "C PROGRAM No. 1: GRID GENERATOR FOR 2-D AIRFOILS\nC ----------------------------------------------\nC THIS PROGRAM IS AN AUTOMATED COMPLEX AIRFOIL TRANSFORMATION OF THE\nC TYPE PRESENTED BY VAN DE VOOREN AND DE JONG (1970). THE RESULTING\nC AIRFOIL MAY HAVE A NON-ZERO TRAILING EDGE ANGLE. THIS FORMULATION\nC IS FOR NON-CAMBERED AIRFOILS ONLY (PROGRAMMED BY STEVEN YON, 1989).\n\n OPEN(8,FILE='AFOIL2.DAT',STATUS='NEW')\n OPEN(10,FILE='CP.DAT',STATUS='NEW')\n\n WRITE(6,*) 'READY TO START VAN DE VOOREN TRANSFORMATION'\n WRITE(6,*) 'ENTER THICKNESS COEFF. E'\n READ(5,*) E\n WRITE(6,*) 'ENTER T.E. ANGLE COEFF. K'\n READ(5,*) AK\n TL=1.0\n A=2*TL*(E+1)**(AK-1)/(2**AK)\n WRITE(6,*) 'ENTER THE ANGLE OF ATTACK IN DEGREES'\n READ(5,*) ALPHA\n AL=ALPHA/57.2958\n WRITE(6,*) 'ENTER NUMBER OF AIRFOIL PANELS,M'\n WRITE(6,*) 'WITH WHICH TO MODEL THE AIRFOIL'\n WRITE(6,*)'(NOTE THAT M SHOULD BE AN EVEN FACTOR OF 360)'\n READ(5,*) M\n ITHETA=360/M\n\nC THE DO LOOP WILL RUN THROUGH THE CIRCLE PLANE WITH\nC THE SPECIFIED ANGULAR INTERVAL AND TRANSFORM EACH\nC POINT TO THE AIRFOIL PLANE\n\n DO I=0,360,ITHETA\n IF(I.EQ.0.OR.I.EQ.360) THEN\n X=1\n Y=0\n CP=1\n WRITE(8,*) X,' ,',Y\n IF(AK.EQ.2.AND.I.EQ.0) GOTO 25\n IF(AK.EQ.2.AND.I.EQ.360) GOTO 25\n WRITE(10,*) X,' ,',CP\n\n 25 CONTINUE\n GOTO 100\n ELSE\n GOTO 50\n END IF\n\n 50 CONTINUE\n TH=I/57.2958\n R1=SQRT((A*(COS(TH)-1))**2+(A*SIN(TH))**2)\n R2=SQRT((A*(COS(TH)-E))**2+(A*SIN(TH))**2)\n IF(TH.EQ.0) THEN\n TH1=1.5708\n ELSE\n TH1=(ATAN((A*SIN(TH))/(A*(COS(TH)-1))))+3.1415927\n END IF\n\n IF(COS(TH)-E.LT.0.AND.SIN(TH).GT.0) THEN\n TH2=(ATAN((A*SIN(TH))/(A*(COS(TH)-E))))+3.1415927\n ELSE IF(COS(TH)-E.LT.0.AND.SIN(TH).LT.0) THEN\n TH2=(ATAN((A*SIN(TH))/(A*(COS(TH)-E))))+3.1415927\n ELSE IF(COS(TH)-E.GT.0.AND.SIN(TH).LT.0) THEN\n TH2=(ATAN((A*SIN(TH))/(A*(COS(TH)-E))))+2*3.1415927\n ELSE\n TH2=(ATAN((A*SIN(TH))/(A*(COS(TH)-E))))\n END IF\n\nC THIS PART COMPUTES THE TRANSFORMED POSITIONS\n\n COM1=((R1**AK)/(R2**(AK-1)))/((COS((AK-1)*TH2))**2+(SIN((AK-1)*\n * TH2))**2)\n X=COM1*(COS(AK*TH1)*COS((AK-1)*TH2)+SIN(AK*TH1)*SIN((AK-1)*TH2))+\n * TL\n Y=COM1*(SIN(AK*TH1)*COS((AK-1)*TH2)-COS(AK*TH1)*SIN((AK-1)*TH2))\n\n WRITE(8,*) X,' ,',Y\n\nC THIS PART COMPUTES THE TRANSFORMED PRESSURE\nC DISTRIBUTION\n\n A1=COS((AK-1)*TH1)*COS(AK*TH2)+SIN((AK-1)*TH1)*SIN(AK*TH2)\n B1=SIN((AK-1)*TH1)*COS(AK*TH2)-COS((AK-1)*TH1)*SIN(AK*TH2)\n C1=(COS(AK*TH2))**2+(SIN(AK*TH2))**2\n P=A*(1-AK+AK*E)\n D1=A1*(A*COS(TH)-P)-B1*A*SIN(TH)\n D2=A1*A*SIN(TH)+B1*(A*COS(TH)-P)\n\n TEMP=2*C1*(SIN(AL)-SIN(AL-TH))/(D1**2+D2**2)\n COM2=TEMP*(R2**AK)/(R1**(AK-1))\n VX=D1*SIN(TH)+D2*COS(TH)\n VY=-(D1*COS(TH)-D2*SIN(TH))\n CP=1-COM2**2*(VX**2+VY**2)\n\n WRITE(10,*) X,' ,',CP\n\n 100 CONTINUE\n END DO\n\n CLOSE(8)\n CLOSE(10)\n STOP\n END\n", "meta": {"hexsha": "c4048263c49922c7185c8b48617a12254239ae57", "size": 3149, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/f77/AFGEN.f", "max_stars_repo_name": "Budhyant/KatzPlotkinPy", "max_stars_repo_head_hexsha": "60f96e17dd1c4fa53b0ae5e878d455151007c334", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2020-07-21T10:19:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-09T12:54:25.000Z", "max_issues_repo_path": "tests/f77/AFGEN.f", "max_issues_repo_name": "AlwinW/KatzPlotkinPy", "max_issues_repo_head_hexsha": "60f96e17dd1c4fa53b0ae5e878d455151007c334", "max_issues_repo_licenses": ["MIT"], "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/f77/AFGEN.f", "max_forks_repo_name": "AlwinW/KatzPlotkinPy", "max_forks_repo_head_hexsha": "60f96e17dd1c4fa53b0ae5e878d455151007c334", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-07-23T22:18:24.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-25T11:33:45.000Z", "avg_line_length": 30.8725490196, "max_line_length": 75, "alphanum_fraction": 0.5242934265, "num_tokens": 1325, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037343628702, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.68839929636762}} {"text": " Subroutine transpole(pole1,width1,x1,y,jac)\nc**********************************************************************\nc This routine transfers evenly spaced x values between 0 and 1\nc to y values with a pole at y=pole with width width and returns\nc the appropriate jacobian for this. If x1-del, uses\nc a linear transformation. This ensures ability to cover entire \nc region, even away from B.W.\nc\nc If pole<0 then assumes have sqrt(1d0/(x^2+a^2)) type pole\nc If pole<0 then assumes have x/(x^2+a^2) type pole\nc\nc**********************************************************************\n implicit none\nc\nc Constants\nc\n double precision del\n parameter (del=1d-22) !Must agree with del in untranspole\nc\nc Arguments\nc\n double precision pole,width,y,jac\n double precision x1\n\nc\nc Local\nc\n double precision z,zmin,zmax,xmin,xmax,ez\n double precision pole1,width1,x,xc\n double precision a,b\nc\nc small width treatment\nc\n double precision small_width_treatment\n common/narrow_width/small_width_treatment\nc-----\nc Begin Code\nc-----\n pole=pole1\n width=width1\n\n x = x1\n if (pole .gt. 0d0) then\n if (width.lt.pole*small_width_treatment)then\n width = pole * small_width_treatment\n jac = jac * width/width1\n endif\n\n zmin = atan((-pole)/width)/width\n zmax = atan((1d0-pole)/width)/width\n if (x .gt. del .and. x .lt. 1d0-del) then\n z = zmin+(zmax-zmin)*x\n y = pole+width*tan(width*z)\n jac = jac *(width/cos(width*z))**2*(zmax-zmin)\n elseif (x .lt. del) then\n xmin = 0d0\n z = zmin+(zmax-zmin)*del\n xmax = pole+width*tan(width*z)\n y = xmin+x*(xmax-xmin)/del\n jac = jac*(xmax-xmin)/del\n else\n xmax = 1d0\n z = zmin+(zmax-zmin)*(1d0-del)\n xmin = pole+width*tan(width*z)\n y = xmin+(x+del-1d0)*(xmax-xmin)/del\n jac = jac*(xmax-xmin)/del\n endif\n elseif(pole .gt. -1d0) then !1/sqrt(x^2+width^2) t-channel\n if (x .gt. .5d0) then !Don't do anything here t>0\n y=x\n else\n zmin = log(2d0*width) !2*width is because x->1-2*x\n zmax = log(1d0+sqrt(1d0+4d0*width*width))\n x=1d0-x*2d0\n z = zmin+(zmax-zmin)*x\n ez = exp(z)\n y = (1d0-.5d0*(ez-4d0*width*width/ez))/2d0\n jac = jac *(zmax-zmin)*.5d0*(ez+4d0*width*width/ez)\nc x = .5d0*(1d0-x)\n endif\nc-------\nc tjs 3/5/2011 Perform 1/x transformation using y=xo^(1-x)\nc-------\n elseif(pole .eq. -15d0 .and. width .gt. 0d0) then !1/x limit of width \nc if (x .lt. width) then !No transformation below cutoff\n xc = width\n xc = 1d0/(1d0-log(width))\n if (x .le. xc) then !No transformation below cutoff\n y=x*width/xc\n jac = jac * width / xc\n else\n z = (x-xc)/(1d0-xc)\n y=width**(1d0-z)\n jac = jac * y * (-log(width))/(1d0-xc)\nc write(*,*) \"trans\",x,y,z\n endif\nc write(*,*) 'Transpole called',x,y\n return\n elseif(pole .ge. -2d0 .and. width .gt. 0d0) then !1/x^2 limit of width\n if (x .lt. width) then !No transformation below cutoff\n y=x\n else\nc---------\nc tjs 5/1/2008 modified for any y=x^-n transformation \nc-----------\n z = 1d0 - x + width\n b = ( 1d0-width) / (width**(pole+1d0) - 1d0)\n a = width - b\n y = a + b * z**(pole+1)\n jac = jac * abs((pole+1d0) * b * z**(pole))\nc write(*,*) \"pre-trans\",x,y\nc call untranspole(pole,width,x,y,jac)\nc write(*,*) \"post-trans\",x,y\nc-----uncomment for 1/x^2 tjs -------\nc x = 1d0-x+width\nc y=width/x\nc jac = jac*width/(x*x)\nc------------------------------------\n \n\nc write(*,*) 'trans',x,width/(x*x)\n endif\n\n elseif(pole .gt. -1d99) then !1/sqrt(x^2+width^2) s-channel\n zmin = log(width)\n zmax = log(1d0+sqrt(1d0+width*width))\n if (x .gt. del .and. x .lt. 1d0-del) then\n z = zmin+(zmax-zmin)*x\n ez = exp(z)\n y = .5d0*(ez-width*width/ez)\n jac = jac *(zmax-zmin)*.5d0*(ez+width*width/ez)\n elseif (x .le. del) then\n xmin = 0d0\n z = zmin+(zmax-zmin)*del\n ez = exp(z)\n xmax = .5d0*(ez-width*width/ez)\n y = xmin+x*(xmax-xmin)/del\n jac = jac*(xmax-xmin)/del\n else\n xmax = 1d0\n z = zmin+(zmax-zmin)*(1d0-del)\n ez = exp(z)\n xmin = .5d0*(ez-width*width/ez)\n y = xmin+(x+del-1d0)*(xmax-xmin)/del\n jac = jac*(xmax-xmin)/del\n endif\n elseif(pole .gt. -8d99) then\n zmin = .5d0*log(width*width)\n zmax = .5d0*log(1d0+width*width)\n if (x .gt. del .and. x .lt. 1d0-del) then\n z = zmin+(zmax-zmin)*x\n ez = exp(2d0*z)\n y = sqrt(ez-width*width)\n jac = jac *(zmax-zmin)*ez/sqrt(ez-width*width)\n elseif (x .lt. del) then\n xmin = 0d0\n z = zmin+(zmax-zmin)*del\n xmax = sqrt(exp(2d0*z)-width*width)\n y = xmin+x*(xmax-xmin)/del\n jac = jac*(xmax-xmin)/del\n else\n xmax = 1d0\n z = zmin+(zmax-zmin)*(1d0-del)\n xmin = sqrt(exp(2d0*z)-width*width)\n y = xmin+(x+del-1d0)*(xmax-xmin)/del\n jac = jac*(xmax-xmin)/del\n endif\n endif\n end\n\n Subroutine untranspole(pole1,width1,x,y1,jac)\nc**********************************************************************\nc This routine transfers takes values of y for a given pole and\nc width, and returns the value of x (which an evenly placed\nc random number) would have been used to get that value of y.\nc it also returns the jacobian associated with this choice.\nc**********************************************************************\n implicit none\nc\nc Constants\nc\n double precision del\n parameter (del=1d-22) !Must agree with del in untranspole\nc\nc Arguments\nc\n double precision pole1,width1,y1,jac\n real*8 x\nc\nc small width treatment\nc\n double precision small_width_treatment\n common/narrow_width/small_width_treatment\nc\nc Local\nc\n double precision z,zmin,zmax,xmin,xmax,ez\n double precision pole,width,y,xc\n double precision a,b\n double precision xgmin,xgmax ! these should be identical \n parameter (xgmin=-1d0, xgmax=1d0) ! to the ones in genps.inc\nc-----\nc Begin Code\nc-----\n pole=pole1\n width=width1\n y = y1\n if (pole .gt. 0d0) then !BW \n if (width.lt.pole*small_width_treatment)then\n width = pole * small_width_treatment\n jac = jac * width/width1\n endif\n zmin = atan((-pole)/width)/width\n zmax = atan((1d0-pole)/width)/width\n z = atan((y-pole)/width)/width\n x = (z-zmin)/(zmax-zmin)\n if (x .le. del) then\n xmin = 0d0\n z = zmin+(zmax-zmin)*del\n xmax = pole+width*tan(width*z)\n if(xmin.lt.xmax) then\n x = (y-xmin)*del/(xmax-xmin)\n else\n x=xmin\n endif\n jac = jac*(xmax-xmin)/del\n elseif (x .ge. 1d0-del) then\n xmax = 1d0\n z = zmin+(zmax-zmin)*(1d0-del)\n xmin = pole+width*tan(width*z)\n if(xmin.lt.xmax) then\n x = (y-xmin)*del/(xmax-xmin)-del+1d0\n else\n x=xmin\n endif\n jac = jac*(xmax-xmin)/del\nc RF (2014/07/07): code is not protected against this special case. In this case,\nc simply set x to 1 and the jac to zero so that this PS point will not\nc contribute (but you do get the correct xbin_min and xbin_max in\nc sample_get_x)\n if (y.eq.xgmax .and. xmin.ge.xgmax) then\n x=1d0\n jac=0d0\n endif\n else\n jac = jac *(width/cos(width*z))**2*(zmax-zmin)\n endif\nc-------\nc tjs 3/5/2011 Perform 1/x transformation using y=xo^(1-x)\nc-------\n elseif(pole .eq. -15d0 .and. width .gt. 0d0) then !1/x limit of width\n xc = 1d0/(1d0-log(width))\nc xc = width\n if (y .le. width) then !No transformation below cutoff\n x = y*xc/width\n else\n z = 1d0-log(y)/log(width)\n x = z*(1d0-xc) + xc\nc write(*,*) \"untrans\",x,y,z\n endif\n return\n elseif(pole .gt. -1d0) then !1/sqrt((.5-x)^2+width^2) t-channel\n if (y .gt. .5d0) then\n x=y\n else\n zmin = log(width*2d0)\n zmax = log(1d0+sqrt(1d0+4d0*width*width))\n y = (1d0-2d0*y)\n z = log(y+sqrt(y*y+4d0*width*width))\n x = (z - zmin)/(zmax-zmin)\n x = .5d0*(1d0-x)\n ez = exp(z)\n jac = jac *(zmax-zmin)*.5d0*(ez+4d0*width*width/ez)\n y = (1d0-y)/2d0\n endif\n\n elseif(pole .gt. -5d0 .and. width .gt. 0d0) then !1/x^2 limit of width\n if (y .lt. width) then !No transformation below cutoff\n x=y\n else\nc---------\nc tjs 5/1/2008 modified for any y=x^-n transformation \nc-----------\n b = ( 1d0-width) / (width**(pole+1d0) - 1d0)\n a = width - b\n z = ((y-a)/b)**(1d0/(pole+1)) \n x = 1d0 - z + width\n jac = jac * abs((pole+1d0) * b * z**(pole))\n\nc-------------------\nc Uncomment below for y=1/x^2\nc-------------------\nc x=width/y\nc write(*,*) 'untr',x,width/(x*x)\nc jac = jac*width/(x*x)\nc x = 1d0-x+width\n endif\n\n elseif(pole .gt. -5d99) then !1/sqrt(x^2+width^2) s-channel\n zmin = log(width)\n zmax = log(1d0+sqrt(1d0+width*width))\n if (pole .gt. -1d0 .and. y .lt. -pole) y=-pole-y\n z = log(y+sqrt(y*y+width*width))\n x = (z - zmin)/(zmax-zmin)\n if (x .gt. del .and. x .lt. 1d0-del) then\n ez = exp(z)\n jac = jac *(zmax-zmin)*.5d0*(ez+width*width/ez)\n elseif (x .lt. del) then\n xmin = 0d0\n z = zmin+(zmax-zmin)*del\n ez = exp(z)\n xmax = .5d0*(ez-width*width/ez)\nc y = xmin+x*(xmax-xmin)/del\n if(xmin.lt.xmax) then\n x = (y-xmin)*del/(xmax-xmin)\n else\n x=xmin\n endif\n jac = jac*(xmax-xmin)/del\n else\n xmax = 1d0\n z = zmin+(zmax-zmin)*(1d0-del)\n ez = exp(z)\n xmin = .5d0*(ez-width*width/ez)\nc y = xmin+(x+del-1d0)*(xmax-xmin)/del\n x = (y-xmin)*del/(xmax-xmin)-del+1d0\n jac = jac*(xmax-xmin)/del\n endif\n endif\n end\n", "meta": {"hexsha": "3d2b640740622b8acb5da39dec3659bef2350465", "size": 11181, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Template/LO/Source/transpole.f", "max_stars_repo_name": "valassi/mg5amc_test", "max_stars_repo_head_hexsha": "2e04f23353051f64e1604b23105fe3faabd32869", "max_stars_repo_licenses": ["NCSA"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-07-09T00:05:56.000Z", "max_stars_repo_stars_event_max_datetime": "2016-07-09T00:05:56.000Z", "max_issues_repo_path": "Template/LO/Source/transpole.f", "max_issues_repo_name": "valassi/mg5amc_test", "max_issues_repo_head_hexsha": "2e04f23353051f64e1604b23105fe3faabd32869", "max_issues_repo_licenses": ["NCSA"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2022-03-10T09:13:31.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T16:15:01.000Z", "max_forks_repo_path": "Template/LO/Source/transpole.f", "max_forks_repo_name": "valassi/mg5amc_test", "max_forks_repo_head_hexsha": "2e04f23353051f64e1604b23105fe3faabd32869", "max_forks_repo_licenses": ["NCSA"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2016-07-09T00:06:15.000Z", "max_forks_repo_forks_event_max_datetime": "2016-07-09T00:06:15.000Z", "avg_line_length": 33.7794561934, "max_line_length": 86, "alphanum_fraction": 0.4804579197, "num_tokens": 3507, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037302939515, "lm_q2_score": 0.7431680029241322, "lm_q1q2_score": 0.68839929334373}} {"text": "program invert\n use gauss\n use mats\n implicit none\n real, allocatable :: mat(:, :), M(:, :)\n integer :: n\n\n print *, 'Enter matrix side length:'\n read (*, *) n\n allocate(mat(n, n))\n\n print *, 'Enter matrix values:'\n read (*, *) mat\n allocate(M(2 * n, n))\n M(:n, :) = mat\n M(n + 1:, :) = identity(n)\n\n call reduce(M)\n print *, 'Inverted matrix:'\n call print_mat(M(n + 1:, :))\nend program invert\n", "meta": {"hexsha": "21d2e5f1fa11d4afcf288d465ac77508640f74b9", "size": 410, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "invert.f90", "max_stars_repo_name": "Ergoold/matrix-maths", "max_stars_repo_head_hexsha": "4011f36ff1903d7b77b9a7eb8c3980f2d7a62775", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "invert.f90", "max_issues_repo_name": "Ergoold/matrix-maths", "max_issues_repo_head_hexsha": "4011f36ff1903d7b77b9a7eb8c3980f2d7a62775", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "invert.f90", "max_forks_repo_name": "Ergoold/matrix-maths", "max_forks_repo_head_hexsha": "4011f36ff1903d7b77b9a7eb8c3980f2d7a62775", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.6363636364, "max_line_length": 41, "alphanum_fraction": 0.5634146341, "num_tokens": 131, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037302939516, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.68839929334373}} {"text": "!----------------------------------------------------------------------\n! NEMO system team, System and Interface for oceanic RElocable Nesting\n!----------------------------------------------------------------------\n!\n! DESCRIPTION:\n!> @brief\n!> This module groups some useful mathematical function.\n!>\n!> @details\n!>\n!> to compute the mean of an array:
\n!> @code\n!> dl_value=math_mean( dl_value, dd_fill )\n!> @endcode\n!> - dl_value is 1D or 2D array\n!> - dd_fill is FillValue\n!>\n!> to compute the median of an array:
\n!> @code\n!> dl_value=math_median( dl_value, dd_fill )\n!> @endcode\n!> - dl_value is 1D or 2D array\n!> - dd_fill is FillValue\n!>\n!> to compute the mean without extremum of an array:
\n!> @code\n!> dl_value=math_mwe( dl_value, id_next, dd_fill )\n!> @endcode\n!> - dl_value is 1D or 2D array\n!> - id_next is the number of extremum to be removed\n!> - dd_fill is FillValue\n!>\n!> to sort an 1D array:
\n!> @code\n!> CALL math_QsortC(dl_value)\n!> @endcode\n!> - dl_value is 1D array\n!>\n!> to correct phase angles to produce smoother phase:
\n!> @code\n!> CALL math_unwrap(dl_value, [dl_discont])\n!> @endcode\n!> - dl_value is 1D array\n!> - dl_discont maximum discontinuity between values, default pi\n!>\n!> to compute simple operation\n!> @code\n!> dl_res=math_compute(cl_var)\n!> @endcode\n!> - cl_var operation to compute (string of character)\n!> - dl_res result of the operation, real(dp)\n!>\n!> to compute first derivative of 1D array:
\n!> @code\n!> dl_value(:)=math_deriv_1D( dd_value(:), dd_fill, [ld_discont] )\n!> @endcode\n!> - dd_value is 1D array of variable\n!> - dd_fill is FillValue of variable\n!> - ld_discont is logical to take into account longitudinal \n!> East-West discontinuity [optional]\n!>\n!> to compute first derivative of 2D array:
\n!> @code\n!> dl_value(:,:)=math_deriv_2D( dd_value(:,:), dd_fill, cd_dim, \n!> [ld_discont] )\n!> @endcode\n!> - dd_value is 2D array of variable\n!> - dd_fill is FillValue of variable\n!> - cd_dim is character to compute derivative on first (I) or\n!> second (J) dimension\n!> - ld_discont is logical to take into account longitudinal \n!> East-West discontinuity [optional]\n!>\n!> to compute first derivative of 3D array:
\n!> @code\n!> dl_value(:,:,:)=math_deriv_3D( dd_value(:,:,:), dd_fill, cd_dim,\n!> [ld_discont] )\n!> @endcode\n!> - dd_value is 3D array of variable\n!> - dd_fill is FillValue of variable\n!> - cd_dim is character to compute derivative on first (I), second (J),\n!> or third (K) dimension\n!> - ld_discont is logical to take into account longitudinal East-West \n!> discontinuity [optional]\n!>\n!>\n!> @author\n!> J.Paul\n!>\n!> @date January, 2015 - Initial version\n!>\n!> @note Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)\n!----------------------------------------------------------------------\nMODULE math\n\n USE kind ! F90 kind parameter\n USE global ! global variable\n USE phycst ! physical constant\n USE fct ! basic useful function\n IMPLICIT NONE\n ! NOTE_avoid_public_variables_if_possible\n\n ! function and subroutine\n PUBLIC :: math_mean !< return mean of an array\n PUBLIC :: math_median !< return median of an array\n PUBLIC :: math_mwe !< return mean without extremum of an array\n PUBLIC :: math_QsortC !< sort an 1D array\n PUBLIC :: math_unwrap !< correct phase angles to produce smoother phase\n PUBLIC :: math_compute !< compute simple operation\n PUBLIC :: math_deriv_1D !< compute first derivative of 1D array \n PUBLIC :: math_deriv_2D !< compute first derivative of 2D array \n PUBLIC :: math_deriv_3D !< compute first derivative of 3D array\n PUBLIC :: math_ortho !< compute orthodome distance\n PUBLIC :: math_euclid !< compute euclidian distance\n\n PRIVATE :: math__Partition\n PRIVATE :: math__mean_1d\n PRIVATE :: math__mean_2d\n PRIVATE :: math__median_1d\n PRIVATE :: math__median_2d\n PRIVATE :: math__mwe_1d\n PRIVATE :: math__mwe_2d\n PRIVATE :: math__parentheses\n\n\n INTERFACE math_mean\n MODULE PROCEDURE math__mean_1d ! return mean of an array 1D\n MODULE PROCEDURE math__mean_2d ! return mean of an array 2D\n END INTERFACE math_mean\n\n INTERFACE math_median\n MODULE PROCEDURE math__median_1d ! return median of an array 1D\n MODULE PROCEDURE math__median_2d ! return median of an array 2D\n END INTERFACE math_median\n\n INTERFACE math_mwe\n MODULE PROCEDURE math__mwe_1d ! return mean without extremum of an array 1D\n MODULE PROCEDURE math__mwe_2d ! return mean without extremum of an array 2D\n END INTERFACE math_mwe\n\nCONTAINS\n !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n PURE FUNCTION math__mean_1d(dd_array, dd_fill) &\n & RESULT (df_mean)\n !------------------------------------------------------------------- \n !> @brief This function compute the mean of a 1D array. \n !>\n !> @author J.Paul \n !> @date January, 2015 - Initial Version \n !>\n !> @param[in] dd_array 1D array \n !> @param[in] dd_fill fillValue\n !> @return mean value, real(dp)\n !------------------------------------------------------------------- \n\n IMPLICIT NONE\n\n ! Argument\n REAL(dp), DIMENSION(:), INTENT(IN) :: dd_array\n REAL(dp), INTENT(IN), OPTIONAL :: dd_fill\n\n ! function\n REAL(dp) :: df_mean\n\n ! local variable\n INTEGER(i4) :: il_count\n REAL(dp) :: dl_sum\n REAL(dp) :: dl_count\n !----------------------------------------------------------------\n \n IF( PRESENT(dd_fill) )THEN\n il_count=COUNT(dd_array(:)/=dd_fill)\n IF( il_count > 0 )THEN\n dl_sum =SUM ( dd_array(:), dd_array(:)/= dd_fill )\n dl_count=REAL( il_count, dp)\n\n df_mean=dl_sum/dl_count\n ELSE\n df_mean=dd_fill\n ENDIF\n ELSE\n il_count=SIZE(dd_array(:))\n IF( il_count > 0 )THEN\n dl_sum =SUM ( dd_array(:) )\n dl_count=REAL( il_count, dp)\n\n df_mean=dl_sum/dl_count\n ELSE\n df_mean=0\n ENDIF\n ENDIF\n\n END FUNCTION math__mean_1d\n !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n PURE FUNCTION math__mean_2d(dd_array, dd_fill) &\n & RESULT (df_mean)\n !------------------------------------------------------------------- \n !> @brief This function compute the mean of a 2D array. \n !>\n !> @author J.Paul \n !> @date January, 2015 - Initial Version \n !>\n !> @param[in] dd_array 2D array \n !> @param[in] dd_fill fillValue\n !> @return mean value, real(dp)\n !------------------------------------------------------------------- \n \n IMPLICIT NONE\n\n ! Argument\n REAL(dp), DIMENSION(:,:), INTENT(IN) :: dd_array\n REAL(dp), INTENT(IN), OPTIONAL :: dd_fill\n\n ! function\n REAL(dp) :: df_mean\n\n ! local variable\n INTEGER(i4) :: il_count\n\n REAL(dp), DIMENSION(:), ALLOCATABLE :: dl_list\n !----------------------------------------------------------------\n\n IF( PRESENT(dd_fill) )THEN\n il_count=COUNT(dd_array(:,:)/=dd_fill)\n IF( il_count > 0 )THEN\n ALLOCATE( dl_list(il_count) )\n dl_list(:)=PACK(dd_array(:,:),dd_array(:,:)/=dd_fill)\n ELSE\n df_mean=dd_fill\n ENDIF\n ELSE\n il_count=SIZE(dd_array)\n IF( il_count > 0 )THEN\n ALLOCATE( dl_list(il_count) )\n dl_list(:)=PACK(dd_array(:,:), MASK=.TRUE.)\n ELSE\n df_mean=0\n ENDIF\n ENDIF\n\n IF( ALLOCATED(dl_list) )THEN\n df_mean=math_mean(dl_list(:))\n DEALLOCATE( dl_list )\n ENDIF\n\n END FUNCTION math__mean_2d\n !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n PURE FUNCTION math__median_1d(dd_array, dd_fill) &\n & RESULT (df_median)\n !------------------------------------------------------------------- \n !> @brief This function compute the median of a 1D array. \n !>\n !> @author J.Paul \n !> @date January, 2015 - Initial Version \n !>\n !> @param[in] dd_array 1D array \n !> @param[in] dd_fill fillValue\n !> @return median value, real(dp)\n !-------------------------------------------------------------------\n \n IMPLICIT NONE\n\n ! Argument\n REAL(dp), DIMENSION(:), INTENT(IN) :: dd_array\n REAL(dp), INTENT(IN), OPTIONAL :: dd_fill\n\n ! function\n REAL(dp) :: df_median\n\n ! local variable\n INTEGER(i4) :: il_count\n\n REAL(dp), DIMENSION(:), ALLOCATABLE :: dl_list\n !----------------------------------------------------------------\n \n IF( PRESENT(dd_fill) )THEN\n il_count=COUNT(dd_array(:)/=dd_fill)\n IF( il_count > 0 )THEN\n ALLOCATE( dl_list(il_count) )\n dl_list(:)=PACK(dd_array(:),dd_array(:)/=dd_fill)\n ELSE\n df_median=dd_fill\n ENDIF\n ELSE\n il_count=SIZE(dd_array(:))\n IF( il_count > 0 )THEN\n ALLOCATE( dl_list(il_count) )\n dl_list(:)=dd_array(:)\n ELSE\n df_median=0\n ENDIF\n ENDIF\n\n IF( ALLOCATED(dl_list) )THEN\n CALL math_QsortC(dl_list(:))\n\n IF( MOD(il_count,2) == 0 )THEN\n df_median=(dl_list(il_count/2+1)+dl_list(il_count/2))/2_dp\n ELSE\n df_median=dl_list(il_count/2+1)\n ENDIF\n\n DEALLOCATE(dl_list)\n ENDIF\n\n END FUNCTION math__median_1d\n !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n PURE FUNCTION math__median_2d(dd_array, dd_fill) &\n & RESULT (df_median)\n !------------------------------------------------------------------- \n !> @brief This function compute the median of a 2D array. \n !> \n !> @author J.Paul \n !> @date January, 2015 - Initial Version \n !>\n !> @param[in] dd_array 2D array \n !> @param[in] dd_fill fillValue\n !> @return median value, real(dp)\n !-------------------------------------------------------------------\n \n IMPLICIT NONE\n\n ! Argument\n REAL(dp), DIMENSION(:,:), INTENT(IN) :: dd_array\n REAL(dp), INTENT(IN), OPTIONAL :: dd_fill\n\n ! funtion\n REAL(dp) :: df_median\n \n ! local variable\n INTEGER(i4) :: il_count\n\n REAL(dp), DIMENSION(:), ALLOCATABLE :: dl_list\n !----------------------------------------------------------------\n \n IF( PRESENT(dd_fill) )THEN\n il_count=COUNT(dd_array(:,:)/=dd_fill)\n IF( il_count > 0 )THEN\n ALLOCATE( dl_list(il_count) )\n dl_list(:)=PACK(dd_array(:,:),dd_array(:,:)/=dd_fill)\n ELSE\n df_median=dd_fill\n ENDIF\n ELSE\n il_count=SIZE(dd_array(:,:))\n IF( il_count > 0 )THEN\n ALLOCATE( dl_list(il_count) )\n dl_list(:)=PACK(dd_array(:,:), MASK=.TRUE.)\n ELSE\n df_median=0\n ENDIF\n ENDIF\n\n IF( ALLOCATED(dl_list) )THEN\n df_median=math_median(dl_list(:))\n DEALLOCATE(dl_list)\n ENDIF\n\n END FUNCTION math__median_2d\n !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n PURE FUNCTION math__mwe_1d(dd_array, id_next, dd_fill) &\n & RESULT (df_mwe)\n !------------------------------------------------------------------- \n !> @brief This function compute the mean without extremum of a 1D array. \n !> \n !> @author J.Paul \n !> @date January, 2015 - Initial Version \n !>\n !> @param[in] dd_array 1D array \n !> @param[in] id_next number of extremum to be removed\n !> @param[in] dd_fill fillValue\n !> @return median value, real(dp)\n !-------------------------------------------------------------------\n \n IMPLICIT NONE\n \n ! Argument\n REAL(dp), DIMENSION(:), INTENT(IN) :: dd_array\n INTEGER(i4) , INTENT(IN), OPTIONAL :: id_next\n REAL(dp), INTENT(IN), OPTIONAL :: dd_fill\n\n ! function\n REAL(dp) :: df_mwe\n\n ! local variable\n INTEGER(i4) :: il_next\n INTEGER(i4) :: il_count\n INTEGER(i4) :: il_size\n\n REAL(dp), DIMENSION(:), ALLOCATABLE :: dl_list\n !----------------------------------------------------------------\n\n il_next=2\n IF( PRESENT(id_next) ) il_next=id_next\n \n il_size=SIZE(dd_array(:))\n IF( PRESENT(dd_fill) )THEN\n il_count=COUNT(dd_array(:)/=dd_fill)\n IF( il_count > 0 )THEN\n ALLOCATE( dl_list(il_count) )\n dl_list(:)=PACK(dd_array(:),dd_array(:)/=dd_fill)\n ELSE\n df_mwe=dd_fill\n ENDIF\n ELSE\n il_count=SIZE(dd_array(:))\n IF( il_count > 0 )THEN\n ALLOCATE( dl_list(il_count) )\n dl_list(:)=dd_array(:)\n ELSE\n df_mwe=0\n ENDIF\n ENDIF\n\n IF( ALLOCATED(dl_list) )THEN\n CALL math_QsortC(dl_list(:))\n\n IF( il_count == il_size )THEN\n ! no fillValue\n df_mwe=math_mean(dl_list(il_next+1:il_size-il_next))\n ELSEIF( il_count > il_size-2*il_next )THEN\n ! remove one extremum each side\n df_mwe=math_mean(dl_list(2:il_size-1))\n ELSE ! il_count <= il_size-2*il_next\n ! more than 2*il_next fillValue\n ! compute mean only\n df_mwe=math_mean(dl_list(:))\n ENDIF\n\n DEALLOCATE(dl_list)\n ENDIF\n\n END FUNCTION math__mwe_1d\n !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n PURE FUNCTION math__mwe_2d(dd_array, id_next, dd_fill) &\n & RESULT (df_mwe)\n !------------------------------------------------------------------- \n !> @brief This function compute the mean without extremum of a 2D array. \n !>\n !> @author J.Paul \n !> @date January, 2015 - Initial Version \n !>\n !> @param[in] dd_array 2D array \n !> @param[in] id_next number of extremum to be removed\n !> @param[in] dd_fill fillValue\n !> @return median value, real(dp)\n !-------------------------------------------------------------------\n \n IMPLICIT NONE\n\n ! Argument\n REAL(dp), DIMENSION(:,:), INTENT(IN) :: dd_array\n INTEGER(i4) , INTENT(IN), OPTIONAL :: id_next\n REAL(dp), INTENT(IN), OPTIONAL :: dd_fill\n\n ! function\n REAL(dp) :: df_mwe\n\n ! local variable\n INTEGER(i4) :: il_count\n\n REAL(dp), DIMENSION(:), ALLOCATABLE :: dl_list\n !----------------------------------------------------------------\n \n IF( PRESENT(dd_fill) )THEN\n il_count=COUNT(dd_array(:,:)/=dd_fill)\n IF( il_count > 0 )THEN\n ALLOCATE( dl_list(il_count) )\n dl_list(:)=PACK(dd_array(:,:),dd_array(:,:)/=dd_fill)\n\n df_mwe=math_mwe(dl_list(:), id_next)\n ELSE\n df_mwe=dd_fill\n ENDIF\n ELSE\n il_count=SIZE(dd_array(:,:))\n IF( il_count > 0 )THEN\n ALLOCATE( dl_list(il_count) )\n dl_list(:)=PACK(dd_array(:,:), MASK=.TRUE.)\n\n df_mwe=math_mwe(dl_list(:), id_next)\n ELSE\n df_mwe=0\n ENDIF\n ENDIF\n\n IF( ALLOCATED(dl_list) ) DEALLOCATE(dl_list)\n\n END FUNCTION math__mwe_2d\n !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n PURE RECURSIVE SUBROUTINE math_QsortC(dd_array)\n !------------------------------------------------------------------- \n !> @brief This subroutine sort a 1D array. \n !>\n !> @details\n !> Recursive Fortran 95 quicksort routine\n !> sorts real numbers into ascending numerical order\n !> Author: Juli Rew, SCD Consulting (juliana@ucar.edu), 9/03\n !> Based on algorithm from Cormen et al., Introduction to Algorithms,\n !> 1997 printing\n !> \n !> @author J.Paul \n !> @date January, 2015 - Rewrite with SIREN coding rules \n !>\n !> @param[inout] dd_array 1D array \n !-------------------------------------------------------------------\n \n IMPLICIT NONE\n\n ! Argument\n REAL(dp), DIMENSION(:), INTENT(INOUT) :: dd_array\n\n ! local variable\n INTEGER(i4) :: il_iq\n !----------------------------------------------------------------\n \n IF( SIZE(dd_array(:)) > 1 )THEN\n CALL math__Partition(dd_array, il_iq)\n CALL math_QsortC(dd_array(:il_iq-1))\n CALL math_QsortC(dd_array(il_iq:))\n ENDIF\n\n END SUBROUTINE math_QsortC\n !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n PURE SUBROUTINE math__Partition(dd_array, id_marker)\n !------------------------------------------------------------------- \n !> @brief This subroutine partition a 1D array. \n !>\n !> @details\n !> Author: Juli Rew, SCD Consulting (juliana@ucar.edu), 9/03\n !> Based on algorithm from Cormen et al., Introduction to Algorithms,\n !> 1997 printing\n !> \n !> @author J.Paul \n !> @date January, 2015 - Rewrite with SIREN coding rules \n !> @date November, 2017\n !> - use the correct loop index to look for element bigger than pivot point.\n !>\n !> @param[inout] dd_array 1D array \n !> @param[in] id_marker \n !-------------------------------------------------------------------\n \n IMPLICIT NONE\n\n ! Argument\n REAL(dp) , DIMENSION(:), INTENT(INOUT) :: dd_array\n INTEGER(i4), INTENT( OUT) :: id_marker\n\n ! local variable\n REAL(dp) :: dl_temp\n REAL(dp) :: dl_x ! pivot point\n\n ! loop indices\n INTEGER(i4) :: ji\n INTEGER(i4) :: jj\n !----------------------------------------------------------------\n\n dl_x = dd_array(1)\n ji= 0\n jj= SIZE(dd_array(:)) + 1\n\n DO \n jj=jj-1\n DO\n IF( dd_array(jj) <= dl_x ) EXIT\n jj=jj-1\n ENDDO\n ji=ji+1\n DO\n IF( dd_array(ji) >= dl_x ) EXIT\n ji=ji+1\n ENDDO\n IF( ji < jj )THEN\n ! exchange dd_array(ji) and dd_array(jj)\n dl_temp= dd_array(ji)\n dd_array(ji) = dd_array(jj)\n dd_array(jj) = dl_temp\n ELSEIF( ji==jj )THEN\n id_marker=ji+1\n RETURN\n ELSE\n id_marker=ji\n RETURN\n ENDIF\n ENDDO\n\n END SUBROUTINE math__Partition\n !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n PURE SUBROUTINE math_unwrap(dd_array, dd_discont)\n !------------------------------------------------------------------- \n !> @brief This subroutine correct phase angles to produce smoother \n !> phase plots. \n !>\n !> @details\n !> This code is based on numpy unwrap function\n !>\n !> Unwrap by changing deltas between values to 2*pi complement.\n !>\n !> Unwrap radian phase `dd_array` by changing absolute jumps greater than\n !> `dd_discont` to their 2*pi complement.\n !>\n !> @note If the discontinuity in `dd_array` is smaller than ``pi``, \n !> but larger than `dd_discont`, no unwrapping is done because taking\n !> the 2*pi complement would only make the discontinuity larger.\n !>\n !> @author J.Paul \n !> @date Marsh, 2015 - Rewrite in fortran, with SIREN coding rules \n !>\n !> @param[inout] dd_array 1D array \n !> @param[in] dd_discont maximum discontinuity between values, default pi\n !-------------------------------------------------------------------\n \n IMPLICIT NONE\n \n ! Argument\n REAL(dp) , DIMENSION(:), INTENT(INOUT) :: dd_array\n REAL(dp) , INTENT(IN ), OPTIONAL :: dd_discont\n\n ! local variable\n INTEGER(i4) :: il_size\n\n REAL(dp) :: dl_discont\n\n REAL(dp), DIMENSION(:), ALLOCATABLE :: dl_diff\n REAL(dp), DIMENSION(:), ALLOCATABLE :: dl_mod\n REAL(dp), DIMENSION(:), ALLOCATABLE :: dl_correct\n REAL(dp), DIMENSION(:), ALLOCATABLE :: dl_tmp\n\n ! loop indices\n INTEGER(i4) :: ji\n !----------------------------------------------------------------\n dl_discont=dp_pi\n IF( PRESENT(dd_discont) ) dl_discont=dd_discont\n\n il_size=SIZE(dd_array)\n ALLOCATE(dl_diff(il_size-1))\n DO ji=1,il_size-1\n dl_diff(ji)=dd_array(ji+1)-dd_array(ji)\n ENDDO\n\n ALLOCATE(dl_mod(il_size-1))\n DO ji=1,il_size-1\n dl_mod(ji) = MOD(dl_diff(ji) + dp_pi, 2*dp_pi) - dp_pi\n ENDDO\n\n WHERE( (dl_mod(:) == -dp_pi) .AND. (dl_diff(:) > 0._dp ) )\n dl_mod(:)=dp_pi\n END WHERE\n\n ALLOCATE(dl_correct(il_size-1))\n dl_correct(:)=dl_mod(:)-dl_diff(:)\n\n DEALLOCATE(dl_mod)\n\n WHERE( ABS(dl_diff(:)) < dl_discont )\n dl_correct(:)=0._dp\n END WHERE\n\n DEALLOCATE(dl_diff)\n \n ALLOCATE(dl_tmp(il_size))\n dl_tmp(:)=dd_array(:)\n\n DO ji=1,il_size-1\n dd_array(ji+1)=dl_tmp(ji+1)+SUM(dl_correct(1:ji))\n ENDDO\n\n DEALLOCATE(dl_correct)\n DEALLOCATE(dl_tmp)\n\n END SUBROUTINE math_unwrap\n !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n RECURSIVE FUNCTION math_compute(cd_var) &\n & RESULT(df_res)\n !------------------------------------------------------------------- \n !> @brief This function compute simple operation \n !>\n !> @details\n !> - operation should be write as a string of character.\n !> - operators allowed are : +,-,*,/ \n !> - to ordered operation you should use parentheses\n !>\n !> exemples: '1e6/(16/122)', '(3/2)*(2+1)' \n !>\n !> @author J.Paul \n !> @date June, 2015 - initial version\n !>\n !> @param[in] cd_var operation to compute (string of character) \n !> @return result of the operation, real(dp)\n !-------------------------------------------------------------------\n \n IMPLICIT NONE\n \n ! Argument \n CHARACTER(LEN=*), INTENT(IN) :: cd_var\n \n ! fucntion\n REAL(dp) :: df_res\n\n ! local variables\n CHARACTER(LEN=lc) :: cl_var\n CHARACTER(LEN=lc) :: cl_str1\n CHARACTER(LEN=lc) :: cl_str2\n \n INTEGER(i4) :: il_ind\n ! loop indices\n !----------------------------------------------------------------\n \n \n IF(fct_is_real(cd_var))THEN\n READ(cd_var,*) df_res\n ELSE\n \n \n CALL math__parentheses(cd_var, cl_var)\n \n IF(fct_is_real(cl_var))THEN\n READ(cl_var,*) df_res\n ELSE\n il_ind=SCAN(TRIM(cl_var),'*')\n IF( il_ind /= 0 )THEN\n cl_str1=cl_var(1:il_ind-1)\n cl_str2=cl_var(il_ind+1:)\n df_res=math_compute(cl_str1)*math_compute(cl_str2)\n ELSE\n il_ind=SCAN(TRIM(cl_var),'/')\n IF( il_ind /= 0 )THEN\n cl_str1=cl_var(1:il_ind-1)\n cl_str2=cl_var(il_ind+1:)\n df_res=math_compute(cl_str1)/math_compute(cl_str2)\n ELSE\n il_ind=SCAN(TRIM(cl_var),'+')\n IF( il_ind /= 0 )THEN\n cl_str1=cl_var(1:il_ind-1)\n cl_str2=cl_var(il_ind+1:)\n df_res=math_compute(cl_str1)+math_compute(cl_str2)\n ELSE\n il_ind=SCAN(TRIM(cl_var),'-')\n IF( il_ind /= 0 )THEN\n cl_str1=cl_var(1:il_ind-1)\n cl_str2=cl_var(il_ind+1:)\n df_res=math_compute(cl_str1)-math_compute(cl_str2)\n ELSE\n df_res=dp_fill\n ENDIF\n ENDIF\n ENDIF\n ENDIF\n ENDIF\n ENDIF\n \n END FUNCTION math_compute\n !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n SUBROUTINE math__parentheses(cd_varin, cd_varout)\n !------------------------------------------------------------------- \n !> @brief This subroutine replace sub string inside parentheses\n !> by the value of the operation inside.\n !>\n !> @details\n !> exemple : \n !> - '2.6+(3/2)' => '2.6+1.5000'\n !>\n !> @author J.Paul \n !> @date June, 2015 - initial version\n !> \n !> @param[in] cd_varin string of character with operation inside\n !> parentheses \n !> @param[out] cd_varout string of character with result of \n !> operation inside parentheses\n !------------------------------------------------------------------- \n \n IMPLICIT NONE\n \n ! Argument \n CHARACTER(LEN=*) , INTENT(IN) :: cd_varin\n CHARACTER(LEN=lc), INTENT(OUT) :: cd_varout\n \n ! local variables\n CHARACTER(LEN=lc) :: cl_cpt\n INTEGER(i4) :: il_ind\n INTEGER(i4) :: il_count\n \n ! loop indices\n INTEGER(i4) :: ji\n !----------------------------------------------------------------\n il_ind=INDEX(cd_varin,'(')\n IF( il_ind /= 0 )THEN\n il_count=0\n DO ji=il_ind+1,LEN(cd_varin)\n IF( cd_varin(ji:ji) == '(' )THEN\n il_count=il_count+1\n ELSEIF( cd_varin(ji:ji) == ')' )THEN\n IF( il_count == 0 )THEN\n WRITE(cl_cpt,*) math_compute(cd_varin(il_ind+1:ji-1))\n cd_varout=TRIM(cd_varin(1:il_ind-1))//TRIM(ADJUSTL(cl_cpt))//&\n & TRIM(cd_varin(ji+1:))\n EXIT\n ELSE\n il_count=il_count-1\n ENDIF\n ENDIF\n ENDDO\n ELSE\n cd_varout=TRIM(cd_varin)\n ENDIF\n \n END SUBROUTINE math__parentheses\n !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n PURE FUNCTION math_deriv_1D(dd_value, dd_fill, ld_discont) &\n & RESULT (df_deriv)\n !-------------------------------------------------------------------\n !> @brief\n !> This function compute derivative of 1D array.\n !> \n !> @details \n !> optionaly you could specify to take into account east west discontinuity\n !> (-180\u00b0 180\u00b0 or 0\u00b0 360\u00b0 for longitude variable)\n !>\n !> @author J.Paul\n !> @date November, 2013 - Initial Version\n !>\n !> @param[in] dd_value 1D array of variable to be extrapolated\n !> @param[in] dd_fill FillValue of variable\n !> @param[in] ld_discont logical to take into account east west discontinuity \n !-------------------------------------------------------------------\n\n IMPLICIT NONE\n\n ! Argument\n REAL(dp) , DIMENSION(:), INTENT(IN) :: dd_value\n REAL(dp) , INTENT(IN) :: dd_fill\n LOGICAL , INTENT(IN), OPTIONAL :: ld_discont\n\n ! function\n REAL(dp), DIMENSION(SIZE(dd_value,DIM=1) ) :: df_deriv\n\n ! local variable\n INTEGER(i4) :: il_imin\n INTEGER(i4) :: il_imax\n INTEGER(i4), DIMENSION(1) :: il_shape\n\n REAL(dp) :: dl_min\n REAL(dp) :: dl_max\n REAL(dp) , DIMENSION(:), ALLOCATABLE :: dl_value\n\n LOGICAL :: ll_discont\n\n ! loop indices\n INTEGER(i4) :: ji\n\n INTEGER(i4) :: i1\n INTEGER(i4) :: i2\n !----------------------------------------------------------------\n ! init\n df_deriv(:)=dd_fill\n\n ll_discont=.FALSE.\n IF( PRESENT(ld_discont) ) ll_discont=ld_discont\n\n il_shape(:)=SHAPE(dd_value(:))\n\n ALLOCATE( dl_value(3))\n\n ! compute derivative in i-direction\n DO ji=1,il_shape(1)\n \n il_imin=MAX(ji-1,1)\n il_imax=MIN(ji+1,il_shape(1))\n\n IF( il_imin==ji-1 .AND. il_imax==ji+1 )THEN\n i1=1 ; i2=3\n ELSEIF( il_imin==ji .AND. il_imax==ji+1 )THEN\n i1=1 ; i2=2\n ELSEIF( il_imin==ji-1 .AND. il_imax==ji )THEN\n i1=2 ; i2=3\n ENDIF\n\n dl_value(i1:i2)=dd_value(il_imin:il_imax)\n IF( il_imin == 1 )THEN\n dl_value(:)=EOSHIFT( dl_value(:), &\n & DIM=1, &\n & SHIFT=-1, &\n & BOUNDARY=dl_value(1) )\n ENDIF\n IF( il_imax == il_shape(1) )THEN\n dl_value(:)=EOSHIFT( dl_value(:), &\n & DIM=1, &\n & SHIFT=1, &\n & BOUNDARY=dl_value(3))\n ENDIF\n\n IF( ll_discont )THEN\n dl_min=MINVAL( dl_value(:), dl_value(:)/=dd_fill )\n dl_max=MAXVAL( dl_value(:), dl_value(:)/=dd_fill )\n IF( dl_min < -170_dp .AND. dl_max > 170_dp )THEN\n WHERE( dl_value(:) < 0._dp ) \n dl_value(:) = dl_value(:)+360._dp\n END WHERE\n ELSEIF( dl_min < 10_dp .AND. dl_max > 350_dp )THEN\n WHERE( dl_value(:) > 180._dp ) \n dl_value(:) = dl_value(:)-180._dp\n END WHERE\n ENDIF\n ENDIF\n\n IF( dl_value( 2) /= dd_fill .AND. & ! ji\n & dl_value( 3) /= dd_fill .AND. & ! ji+1\n & dl_value( 1) /= dd_fill )THEN ! ji-1\n\n df_deriv(ji)= (dl_value(3) - dl_value(1)) / REAL(il_imax-il_imin,dp)\n\n ENDIF\n\n ENDDO\n\n DEALLOCATE( dl_value )\n\n END FUNCTION math_deriv_1D\n !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n FUNCTION math_deriv_2D(dd_value, dd_fill, cd_dim, ld_discont) &\n & RESULT (df_deriv)\n !-------------------------------------------------------------------\n !> @brief\n !> This function compute derivative of 2D array.\n !> you have to specify in which direction derivative have to be computed:\n !> first (I) or second (J) dimension. \n !>\n !> @details \n !> optionaly you could specify to take into account east west discontinuity\n !> (-180\u00b0 180\u00b0 or 0\u00b0 360\u00b0 for longitude variable)\n !>\n !> @author J.Paul\n !> @date November, 2013 - Initial Version\n !>\n !> @param[in] dd_value 2D array of variable to be extrapolated\n !> @param[in] dd_fill FillValue of variable\n !> @param[in] cd_dim compute derivative on first (I) or second (J) dimension \n !> @param[in] ld_discont logical to take into account east west discontinuity \n !-------------------------------------------------------------------\n\n IMPLICIT NONE\n\n ! Argument\n REAL(dp) , DIMENSION(:,:), INTENT(IN) :: dd_value\n REAL(dp) , INTENT(IN) :: dd_fill\n CHARACTER(LEN=*) , INTENT(IN) :: cd_dim\n LOGICAL , INTENT(IN), OPTIONAL :: ld_discont\n\n ! function\n REAL(dp), DIMENSION(SIZE(dd_value,DIM=1), &\n & SIZE(dd_value,DIM=2) ) :: df_deriv\n\n ! local variable\n INTEGER(i4) :: il_imin\n INTEGER(i4) :: il_imax\n INTEGER(i4) :: il_jmin\n INTEGER(i4) :: il_jmax\n INTEGER(i4), DIMENSION(2) :: il_shape\n\n REAL(dp) :: dl_min\n REAL(dp) :: dl_max\n REAL(dp) , DIMENSION(:,:), ALLOCATABLE :: dl_value\n\n LOGICAL :: ll_discont\n\n ! loop indices\n INTEGER(i4) :: ji\n INTEGER(i4) :: jj\n\n INTEGER(i4) :: i1\n INTEGER(i4) :: i2\n\n INTEGER(i4) :: j1\n INTEGER(i4) :: j2\n !----------------------------------------------------------------\n ! init\n df_deriv(:,:)=dd_fill\n\n ll_discont=.FALSE.\n IF( PRESENT(ld_discont) ) ll_discont=ld_discont\n\n il_shape(:)=SHAPE(dd_value(:,:))\n\n SELECT CASE(TRIM(fct_upper(cd_dim)))\n\n CASE('I')\n\n ALLOCATE( dl_value(3,il_shape(2)) )\n ! compute derivative in i-direction\n DO ji=1,il_shape(1)\n\n ! init\n dl_value(:,:)=dd_fill\n \n il_imin=MAX(ji-1,1)\n il_imax=MIN(ji+1,il_shape(1))\n\n IF( il_imin==ji-1 .AND. il_imax==ji+1 )THEN\n i1=1 ; i2=3\n ELSEIF( il_imin==ji .AND. il_imax==ji+1 )THEN\n i1=1 ; i2=2\n ELSEIF( il_imin==ji-1 .AND. il_imax==ji )THEN\n i1=2 ; i2=3\n ENDIF\n\n dl_value(i1:i2,:)=dd_value(il_imin:il_imax,:)\n IF( il_imin == 1 )THEN\n dl_value(:,:)=EOSHIFT( dl_value(:,:), &\n & DIM=1, &\n & SHIFT=-1, &\n & BOUNDARY=dl_value(1,:) )\n ENDIF\n IF( il_imax == il_shape(1) )THEN\n dl_value(:,:)=EOSHIFT( dl_value(:,:), &\n & DIM=1, &\n & SHIFT=1, &\n & BOUNDARY=dl_value(3,:))\n ENDIF\n\n IF( ll_discont )THEN\n dl_min=MINVAL( dl_value(:,:), dl_value(:,:)/=dd_fill )\n dl_max=MAXVAL( dl_value(:,:), dl_value(:,:)/=dd_fill )\n IF( dl_min < -170_dp .AND. dl_max > 170_dp )THEN\n WHERE( dl_value(:,:) < 0_dp ) \n dl_value(:,:) = dl_value(:,:)+360._dp\n END WHERE\n ELSEIF( dl_min < 10_dp .AND. dl_max > 350_dp )THEN\n WHERE( dl_value(:,:) > 180 ) \n dl_value(:,:) = dl_value(:,:)-180._dp\n END WHERE\n ENDIF\n ENDIF\n \n WHERE( dl_value(2,:) /= dd_fill .AND. & ! ji\n & dl_value(3,:) /= dd_fill .AND. & ! ji+1\n & dl_value(1,:) /= dd_fill ) ! ji-1\n\n df_deriv(ji,:)= (dl_value(3,:) - dl_value(1,:)) / REAL(il_imax-il_imin,dp)\n\n END WHERE\n\n ENDDO\n\n CASE('J')\n\n ALLOCATE( dl_value(il_shape(1),3) )\n ! compute derivative in j-direction\n DO jj=1,il_shape(2)\n \n il_jmin=MAX(jj-1,1)\n il_jmax=MIN(jj+1,il_shape(2))\n\n IF( il_jmin==jj-1 .AND. il_jmax==jj+1 )THEN\n j1=1 ; j2=3\n ELSEIF( il_jmin==jj .AND. il_jmax==jj+1 )THEN\n j1=1 ; j2=2\n ELSEIF( il_jmin==jj-1 .AND. il_jmax==jj )THEN\n j1=2 ; j2=3\n ENDIF\n\n dl_value(:,j1:j2)=dd_value(:,il_jmin:il_jmax)\n IF( il_jmin == 1 )THEN\n dl_value(:,:)=EOSHIFT( dl_value(:,:), &\n & DIM=2, &\n & SHIFT=-1, &\n & BOUNDARY=dl_value(:,1))\n ENDIF\n IF( il_jmax == il_shape(2) )THEN\n dl_value(:,:)=EOSHIFT( dl_value(:,:), &\n & DIM=2, &\n & SHIFT=1, &\n & BOUNDARY=dl_value(:,3))\n ENDIF\n\n IF( ll_discont )THEN\n dl_min=MINVAL( dl_value(:,:), dl_value(:,:)/=dd_fill )\n dl_max=MAXVAL( dl_value(:,:), dl_value(:,:)/=dd_fill )\n IF( dl_min < -170_dp .AND. dl_max > 170_dp )THEN\n WHERE( dl_value(:,:) < 0_dp ) \n dl_value(:,:) = dl_value(:,:)+360._dp\n END WHERE\n ELSEIF( dl_min < 10_dp .AND. dl_max > 350_dp )THEN\n WHERE( dl_value(:,:) > 180 ) \n dl_value(:,:) = dl_value(:,:)-180._dp\n END WHERE\n ENDIF\n ENDIF\n\n WHERE( dl_value(:, 2) /= dd_fill .AND. & ! jj\n & dl_value(:, 3) /= dd_fill .AND. & ! jj+1\n & dl_value(:, 1) /= dd_fill ) ! jj-1\n\n df_deriv(:,jj)= (dl_value(:,3) - dl_value(:,1)) / REAL(il_jmax-il_jmin,dp) \n\n END WHERE\n\n ENDDO\n \n END SELECT\n\n DEALLOCATE( dl_value )\n\n END FUNCTION math_deriv_2D\n !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n PURE FUNCTION math_deriv_3D(dd_value, dd_fill, cd_dim, ld_discont) &\n & RESULT (df_deriv)\n !-------------------------------------------------------------------\n !> @brief\n !> This function compute derivative of 3D array.\n !> you have to specify in which direction derivative have to be computed:\n !> first (I), second (J) or third (K) dimension.\n !> \n !> @details \n !> optionaly you could specify to take into account east west discontinuity\n !> (-180\u00b0 180\u00b0 or 0\u00b0 360\u00b0 for longitude variable)\n !>\n !> @author J.Paul\n !> @date November, 2013 - Initial Version\n !>\n !> @param[inout] dd_value 3D array of variable to be extrapolated\n !> @param[in] dd_fill FillValue of variable\n !> @param[in] cd_dim compute derivative on first (I) second (J) or third (K) dimension \n !> @param[in] ld_discont logical to take into account east west discontinuity\n !-------------------------------------------------------------------\n\n IMPLICIT NONE\n\n ! Argument\n REAL(dp) , DIMENSION(:,:,:), INTENT(IN) :: dd_value\n REAL(dp) , INTENT(IN) :: dd_fill\n CHARACTER(LEN=*) , INTENT(IN) :: cd_dim\n LOGICAL , INTENT(IN), OPTIONAL :: ld_discont\n\n ! function\n REAL(dp), DIMENSION(SIZE(dd_value,DIM=1), &\n & SIZE(dd_value,DIM=2), &\n & SIZE(dd_value,DIM=3)) :: df_deriv\n\n ! local variable\n INTEGER(i4) :: il_imin\n INTEGER(i4) :: il_imax\n INTEGER(i4) :: il_jmin\n INTEGER(i4) :: il_jmax\n INTEGER(i4) :: il_kmin\n INTEGER(i4) :: il_kmax\n INTEGER(i4), DIMENSION(3) :: il_shape\n\n REAL(dp) :: dl_min\n REAL(dp) :: dl_max\n REAL(dp) , DIMENSION(:,:,:), ALLOCATABLE :: dl_value\n\n LOGICAL :: ll_discont\n\n ! loop indices\n INTEGER(i4) :: ji\n INTEGER(i4) :: jj\n INTEGER(i4) :: jk\n\n INTEGER(i4) :: i1\n INTEGER(i4) :: i2\n\n INTEGER(i4) :: j1\n INTEGER(i4) :: j2\n \n INTEGER(i4) :: k1\n INTEGER(i4) :: k2 \n !----------------------------------------------------------------\n ! init\n df_deriv(:,:,:)=dd_fill\n\n ll_discont=.FALSE.\n IF( PRESENT(ld_discont) ) ll_discont=ld_discont\n\n il_shape(:)=SHAPE(dd_value(:,:,:))\n\n\n SELECT CASE(TRIM(fct_upper(cd_dim)))\n\n CASE('I')\n\n ALLOCATE( dl_value(3,il_shape(2),il_shape(3)) )\n ! compute derivative in i-direction\n DO ji=1,il_shape(1)\n \n il_imin=MAX(ji-1,1)\n il_imax=MIN(ji+1,il_shape(1))\n\n IF( il_imin==ji-1 .AND. il_imax==ji+1 )THEN\n i1=1 ; i2=3\n ELSEIF( il_imin==ji .AND. il_imax==ji+1 )THEN\n i1=1 ; i2=2\n ELSEIF( il_imin==ji-1 .AND. il_imax==ji )THEN\n i1=2 ; i2=3\n ENDIF\n\n dl_value(i1:i2,:,:)=dd_value(il_imin:il_imax,:,:)\n IF( il_imin == 1 )THEN\n dl_value(:,:,:)=EOSHIFT( dl_value(:,:,:), &\n & DIM=1, &\n & SHIFT=-1, &\n & BOUNDARY=dl_value(1,:,:) )\n ENDIF\n IF( il_imax == il_shape(1) )THEN\n dl_value(:,:,:)=EOSHIFT( dl_value(:,:,:), &\n & DIM=1, &\n & SHIFT=1, &\n & BOUNDARY=dl_value(3,:,:))\n ENDIF\n\n IF( ll_discont )THEN\n dl_min=MINVAL( dl_value(:,:,:), dl_value(:,:,:)/=dd_fill )\n dl_max=MAXVAL( dl_value(:,:,:), dl_value(:,:,:)/=dd_fill )\n IF( dl_min < -170_dp .AND. dl_max > 170_dp )THEN\n WHERE( dl_value(:,:,:) < 0_dp ) \n dl_value(:,:,:) = dl_value(:,:,:)+360._dp\n END WHERE\n ELSEIF( dl_min < 10_dp .AND. dl_max > 350_dp )THEN\n WHERE( dl_value(:,:,:) > 180 ) \n dl_value(:,:,:) = dl_value(:,:,:)-180._dp\n END WHERE\n ENDIF\n ENDIF\n\n WHERE( dl_value(2,:,:) /= dd_fill .AND. & ! ji\n & dl_value(3,:,:) /= dd_fill .AND. & !ji+1 \n & dl_value(1,:,:) /= dd_fill ) !ji-1\n\n df_deriv(ji,:,:)= (dl_value(3,:,:) - dl_value(1,:,:)) / REAL(il_imax-il_imin,dp)\n\n END WHERE\n\n ENDDO\n\n CASE('J')\n\n ALLOCATE( dl_value(il_shape(1),3,il_shape(3)) )\n ! compute derivative in j-direction\n DO jj=1,il_shape(2)\n \n il_jmin=MAX(jj-1,1)\n il_jmax=MIN(jj+1,il_shape(2))\n\n IF( il_jmin==jj-1 .AND. il_jmax==jj+1 )THEN\n j1=1 ; j2=3\n ELSEIF( il_jmin==jj .AND. il_jmax==jj+1 )THEN\n j1=1 ; j2=2\n ELSEIF( il_jmin==jj-1 .AND. il_jmax==jj )THEN\n j1=2 ; j2=3\n ENDIF\n\n dl_value(:,j1:j2,:)=dd_value(:,il_jmin:il_jmax,:)\n IF( il_jmin == 1 )THEN\n dl_value(:,:,:)=EOSHIFT( dl_value(:,:,:), &\n & DIM=2, &\n & SHIFT=-1, &\n & BOUNDARY=dl_value(:,1,:) )\n ENDIF\n IF( il_jmax == il_shape(2) )THEN\n dl_value(:,:,:)=EOSHIFT( dl_value(:,:,:), &\n & DIM=2, &\n & SHIFT=1, &\n & BOUNDARY=dl_value(:,3,:))\n ENDIF\n\n IF( ll_discont )THEN\n dl_min=MINVAL( dl_value(:,:,:), dl_value(:,:,:)/=dd_fill )\n dl_max=MAXVAL( dl_value(:,:,:), dl_value(:,:,:)/=dd_fill )\n IF( dl_min < -170_dp .AND. dl_max > 170_dp )THEN\n WHERE( dl_value(:,:,:) < 0_dp ) \n dl_value(:,:,:) = dl_value(:,:,:)+360._dp\n END WHERE\n ELSEIF( dl_min < 10_dp .AND. dl_max > 350_dp )THEN\n WHERE( dl_value(:,:,:) > 180 ) \n dl_value(:,:,:) = dl_value(:,:,:)-180._dp\n END WHERE\n ENDIF\n ENDIF\n\n WHERE( dl_value(:, 2,:) /= dd_fill .AND. & ! jj\n & dl_value(:, 3,:) /= dd_fill .AND. & ! jj+1\n & dl_value(:, 1,:) /= dd_fill ) ! jj-1\n\n df_deriv(:,jj,:)= (dl_value(:,3,:) - dl_value(:,1,:)) / REAL(il_jmax - il_jmin,dp) \n\n END WHERE\n\n ENDDO\n \n CASE('K')\n\n ALLOCATE( dl_value(il_shape(1),il_shape(2),3) )\n ! compute derivative in k-direction\n DO jk=1,il_shape(3)\n\n il_kmin=MAX(jk-1,1)\n il_kmax=MIN(jk+1,il_shape(3))\n\n IF( il_kmin==jk-1 .AND. il_kmax==jk+1 )THEN\n k1=1 ; k2=3\n ELSEIF( il_kmin==jk .AND. il_kmax==jk+1 )THEN\n k1=1 ; k2=2\n ELSEIF( il_kmin==jk-1 .AND. il_kmax==jk )THEN\n k1=2 ; k2=3\n ENDIF\n\n dl_value(:,:,k1:k2)=dd_value(:,:,il_kmin:il_kmax)\n IF( il_kmin == 1 )THEN\n dl_value(:,:,:)=EOSHIFT( dl_value(:,:,:), &\n & DIM=3, &\n & SHIFT=-1, &\n & BOUNDARY=dl_value(:,:,1) )\n ENDIF\n IF( il_kmax == il_shape(3) )THEN\n dl_value(:,:,:)=EOSHIFT( dl_value(:,:,:), &\n & DIM=3, &\n & SHIFT=1, &\n & BOUNDARY=dl_value(:,:,3))\n ENDIF\n\n IF( ll_discont )THEN\n dl_min=MINVAL( dl_value(:,:,:), dl_value(:,:,:)/=dd_fill )\n dl_max=MAXVAL( dl_value(:,:,:), dl_value(:,:,:)/=dd_fill )\n IF( dl_min < -170_dp .AND. dl_max > 170_dp )THEN\n WHERE( dl_value(:,:,:) < 0_dp ) \n dl_value(:,:,:) = dl_value(:,:,:)+360._dp\n END WHERE\n ELSEIF( dl_min < 10_dp .AND. dl_max > 350_dp )THEN\n WHERE( dl_value(:,:,:) > 180 ) \n dl_value(:,:,:) = dl_value(:,:,:)-180._dp\n END WHERE\n ENDIF\n ENDIF \n\n WHERE( dl_value(:,:,2) /= dd_fill .AND. & ! jk\n & dl_value(:,:,3) /= dd_fill .AND. & ! jk+1\n & dl_value(:,:,1) /= dd_fill ) ! jk-1\n\n df_deriv(:,:,jk)= (dl_value(:,:,3) - dl_value(:,:,1)) / REAL(il_kmax-il_kmin,dp) \n\n END WHERE\n\n ENDDO\n\n END SELECT\n\n DEALLOCATE( dl_value )\n\n END FUNCTION math_deriv_3D\n !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n FUNCTION math_ortho(dd_latm) &\n & RESULT(df_ortho)\n !-------------------------------------------------------------------\n !> @brief\n !> This function compute orthodome distance between opposite point of a cell\n !> of one degree.\n !> \n !> @details \n !>\n !> @author J.Paul\n !> @date April, 2017 - Initial Version\n !>\n !> @param[in] dd_latm mean latitude of the cell\n !> @return orthodome distance\n !-------------------------------------------------------------------\n \n IMPLICIT NONE\n\n ! Argument\n REAL(dp), TARGET :: dd_latm\n \n ! function\n REAL(dp) :: df_ortho\n \n ! local\n REAL(dp) :: dl_dlat\n REAL(dp) :: dl_dlon\n REAL(dp) :: dl_lat1\n REAL(dp) :: dl_lat2\n REAL(dp) :: dl_tmp\n !----------------------------------------------------------------\n\n ! one degree cell\n dl_dlat= 1._dp * dp_deg2rad\n dl_dlon= 1._dp * dp_deg2rad\n\n ! \n dl_lat1 = (dd_latm - 0.5_dp) * dp_deg2rad\n dl_lat2 = (dd_latm + 0.5_dp) * dp_deg2rad\n\n dl_tmp = SQRT( SIN(dl_dlat*0.5)**2 + &\n & COS(dl_lat1)*COS(dl_lat2)*SIN(dl_dlon*0.5)**2 )\n\n df_ortho= 2* dp_rearth * ASIN( dl_tmp )\n\n END FUNCTION math_ortho\n !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n FUNCTION math_euclid(dd_lonm,dd_latm) &\n & RESULT(df_euclid)\n !-------------------------------------------------------------------\n !> @brief\n !> This function compute euclidian distance between opposite point of a cell\n !> of one degree, center on (lonm,latm).\n !> \n !> @details \n !>\n !> @author J.Paul\n !> @date April, 2017 - Initial Version\n !>\n !> @param[in] dd_lonm mean longitude of the cell\n !> @param[in] dd_latm mean latitude of the cell\n !> @return orthodome distance\n !-------------------------------------------------------------------\n \n IMPLICIT NONE\n\n ! Argument\n REAL(dp), TARGET :: dd_lonm\n REAL(dp), TARGET :: dd_latm\n \n ! function\n REAL(dp) :: df_euclid\n \n ! local\n REAL(dp) :: dl_lata\n REAL(dp) :: dl_lona\n REAL(dp) :: dl_latb\n REAL(dp) :: dl_lonb\n REAL(dp) :: xa,ya,za\n REAL(dp) :: xb,yb,zb\n !----------------------------------------------------------------\n\n dl_lata=(dd_latm-0.5)*dp_deg2rad\n dl_lona=(dd_lonm-0.5)*dp_deg2rad\n\n xa = dp_rearth * COS(dl_lata) * COS(dl_lona)\n ya = dp_rearth * COS(dl_lata) * SIN(dl_lona)\n za = dp_rearth * SIN(dl_lata)\n\n dl_latb=(dd_latm+0.5)*dp_deg2rad\n dl_lonb=(dd_lonm+0.5)*dp_deg2rad\n\n xb = dp_rearth * COS(dl_latb) * COS(dl_lonb)\n yb = dp_rearth * COS(dl_latb) * SIN(dl_lonb)\n zb = dp_rearth * SIN(dl_latb)\n\n df_euclid = ((xb-xa)**2 + (yb-ya)**2 + (zb-za)**2)\n\n END FUNCTION math_euclid\n !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nEND MODULE math\n", "meta": {"hexsha": "0435cec813fae23140d89bef0b4766c9bcb6febd", "size": 48988, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/nemo_r4.0.4/tools/SIREN/src/math.f90", "max_stars_repo_name": "yumengch/nemo4_pdafomi", "max_stars_repo_head_hexsha": "c25fa7092ef0ae895d0fe3accdec74254cd85c55", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-03-24T11:08:31.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-05T12:32:14.000Z", "max_issues_repo_path": "src/nemo_r4.0.4/tools/SIREN/src/math.f90", "max_issues_repo_name": "yumengch/nemo4_pdafomi", "max_issues_repo_head_hexsha": "c25fa7092ef0ae895d0fe3accdec74254cd85c55", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-04-24T18:56:09.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-24T18:56:09.000Z", "max_forks_repo_path": "src/nemo_r4.0.4/tools/SIREN/src/math.f90", "max_forks_repo_name": "yumengch/nemo4_pdafomi", "max_forks_repo_head_hexsha": "c25fa7092ef0ae895d0fe3accdec74254cd85c55", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-04-09T16:25:26.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-09T16:25:26.000Z", "avg_line_length": 33.7615437629, "max_line_length": 106, "alphanum_fraction": 0.4521311342, "num_tokens": 12911, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037221561136, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.688399287295949}} {"text": "MODULE procedures\n IMPLICIT NONE\n\nCONTAINS\n SUBROUTINE foo(Y)\n\n DOUBLE PRECISION, DIMENSION(:,:,:,:), INTENT(IN) :: Y\n\n INTEGER :: i,j,k\n DOUBLE PRECISION, DIMENSION(SIZE(Y,4)) :: Ys\n\n !$omp target teams distribute parallel do collapse(3) default(none) &\n !$omp& private(i,j,k,Ys) &\n !$omp& shared(Y)\n DO i=1,SIZE(Y,1)\n DO j=1,SIZE(Y,2)\n DO k=1,SIZE(Y,3)\n\n Ys = MIN(MAX(Y(i,j,k,:), 0.0D0), 1.0D0)\n \n END DO ! k\n END DO ! j\n END DO ! i\n\n !$omp end target teams distribute parallel do\n\n END SUBROUTINE\nEND MODULE procedures\n\nPROGRAM fmain\n USE PROCEDURES\n IMPLICIT NONE\n\n DOUBLE PRECISION, ALLOCATABLE, DIMENSION(:,:,:,:) :: Y\n\n ALLOCATE(Y(32,32,32,8))\n\n CALL foo(Y)\n\nEND PROGRAM fmain\n", "meta": {"hexsha": "a08908c7366c7e33b46991c8bbb713e2ff752c28", "size": 737, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "testing/compiler_test_cases/omp_privatizer_bug/double_free.f90", "max_stars_repo_name": "bblakeley/FGPU", "max_stars_repo_head_hexsha": "0bf46c2487775a99c0be51e0bdfbdeaddeb967fe", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 31, "max_stars_repo_stars_event_min_datetime": "2019-03-18T23:55:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-07T08:37:48.000Z", "max_issues_repo_path": "testing/compiler_test_cases/omp_privatizer_bug/double_free.f90", "max_issues_repo_name": "bblakeley/FGPU", "max_issues_repo_head_hexsha": "0bf46c2487775a99c0be51e0bdfbdeaddeb967fe", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2019-03-13T20:33:03.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-15T17:02:49.000Z", "max_forks_repo_path": "testing/compiler_test_cases/omp_privatizer_bug/double_free.f90", "max_forks_repo_name": "bblakeley/FGPU", "max_forks_repo_head_hexsha": "0bf46c2487775a99c0be51e0bdfbdeaddeb967fe", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2019-05-24T17:22:36.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-07T08:40:34.000Z", "avg_line_length": 17.9756097561, "max_line_length": 72, "alphanum_fraction": 0.6146540027, "num_tokens": 249, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110396870287, "lm_q2_score": 0.7718435083355187, "lm_q1q2_score": 0.6883385616443828}} {"text": "! .................................................\r\n! ____ _ _ ____ _____ _ \r\n! | _ \\| | |_| | _ \\| ___| |_| \r\n! | |_) | |___ _ | |_) | |___ _ \r\n! | _ /| _ | | | | _ /|___ | | | \r\n! | | | | | | | | | | ___| | | | \r\n! |_| |_| |_| |_| |_| |_____| |_| \r\n! .................................................\r\n! PhiPsi: a general-purpose computational \r\n! mechanics program written in Fortran.\r\n! Website: http://phipsi.top \r\n! Author: Shi Fang from Huaiyin Institute of \r\n! Technology, HuaiAn, JiangSu, China \r\n! Contact me: shifang@hyit.edu.cn \r\n! ------------------------------------------------ \r\n! Please cite the following papers: \r\n! (1)Shi F, Wang X L, Liu C, Liu H, Wu H A. An \r\n! XFEM-based method with reduction technique \r\n! for modeling hydraulic fracture propagation \r\n! in formations containing frictional natural \r\n! fractures. Engineering Fracture Mechanics, \r\n! 2017, 173: 64-90. \r\n! (2)Shi F, Wang X L, Liu C, Liu H, Wu H A. A \r\n! coupled extended finite element approach \r\n! for modeling hydraulic fracturing in \r\n! consideration of proppant. Journal of \r\n! Natural Gas Science and Engineering, 2016, \r\n! 33: 885-897. \r\n! (3)Shi F, Wang X L, Liu C, Liu H, Wu H A. An \r\n! XFEM-based numerical model to calculate \r\n! conductivity of propped fracture considering \r\n! proppant transport, embedment and crushing. \r\n! Journal of Petroleum Science and Engineering, \r\n! 2018, 167: 615-626.. \r\n \r\n subroutine Cal_Coor_by_KesiYita(kesi,yita,X_NODES,Y_NODES,\r\n & Out_x,Out_y)\r\nC Calculate global coordinates using local coordinates kesi and yita.\r\n \r\n implicit none\r\n double precision,intent(in)::kesi,yita,X_NODES(4),Y_NODES(4)\r\n double precision,intent(out)::Out_x,Out_y\r\n double precision N(4)\r\n \r\n N = 0.25D0 * [(1-kesi)*(1-yita),(1+kesi)*(1-yita),\r\n & (1+kesi)*(1+yita),(1-kesi)*(1+yita)]\r\n \r\n Out_x = N(1)*X_NODES(1)+N(2)*X_NODES(2)+\r\n & N(3)*X_NODES(3)+N(4)*X_NODES(4)\r\n Out_y = N(1)*Y_NODES(1)+N(2)*Y_NODES(2)+\r\n & N(3)*Y_NODES(3)+N(4)*Y_NODES(4)\r\n \r\n return \r\n end SUBROUTINE Cal_Coor_by_KesiYita \r\n", "meta": {"hexsha": "0a6b12b9bfffdf3ff38cec0dae8f154bcf611186", "size": 2728, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Cal_Coor_by_KesiYita.f", "max_stars_repo_name": "PhiPsi-Software/PhiPsi_XFEM_Fortran_Codes_Early_Version", "max_stars_repo_head_hexsha": "1eae63a8f0dc968b9d5220397879645a83e5d083", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-04-15T11:56:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-14T11:49:59.000Z", "max_issues_repo_path": "Cal_Coor_by_KesiYita.f", "max_issues_repo_name": "PhiPsi-Software/PhiPsi_XFEM_Fortran_Codes_Early_Version", "max_issues_repo_head_hexsha": "1eae63a8f0dc968b9d5220397879645a83e5d083", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Cal_Coor_by_KesiYita.f", "max_forks_repo_name": "PhiPsi-Software/PhiPsi_XFEM_Fortran_Codes_Early_Version", "max_forks_repo_head_hexsha": "1eae63a8f0dc968b9d5220397879645a83e5d083", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2019-01-20T00:55:09.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T00:30:28.000Z", "avg_line_length": 49.6, "max_line_length": 74, "alphanum_fraction": 0.4413489736, "num_tokens": 702, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110540642805, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6883385587001039}} {"text": "program main\n\n use mo_kind, only: i4, i8, sp, dp\n use mo_functions, only: factorial, factln, gamm, gammln, beta\n use mo_ansi_colors, only: color, c_red, c_green\n use mo_utils, only: ne\n\n implicit none\n\n logical :: isgood\n\n isgood = .true.\n write(*,*) ''\n write(*,*) 'Test mo_functions'\n\n ! Factorial\n if ( factorial(5_i4) .ne. 120_i4 ) isgood = .false.\n if ( factorial(5_i8) .ne. 120_i8 ) isgood = .false.\n\n ! factln\n if ( nint(exp(factln(5_i4)),i4) .ne. 120_i4 ) isgood = .false.\n if ( nint(exp(factln(5_i8)),i8) .ne. 120_i8 ) isgood = .false.\n\n ! gamm\n if ( nint(gamm(6._sp),i4) .ne. 120_i4 ) isgood = .false.\n if ( nint(gamm(6._dp),i8) .ne. 120_i8 ) isgood = .false.\n\n ! gammln\n if ( nint(exp(gammln(6._sp)),i4) .ne. 120_i4 ) isgood = .false.\n if ( nint(exp(gammln(6._dp)),i8) .ne. 120_i8 ) isgood = .false.\n\n ! beta\n if ( ne(beta(0.5_sp, 0.5_sp), 3.1415935_sp)) isgood = .false.\n if ( ne(beta(0.5_dp, 0.5_dp), 3.1415926535897927_dp)) isgood = .false.\n\n write(*,*) ''\n if (isgood) then\n write(*,*) 'mo_functions ', color('o.k.', c_green)\n else\n write(*,*) 'mo_functions ', color('failed', c_red)\n end if\n\nend program main\n", "meta": {"hexsha": "330a4fbcd6dfaa31e61317d6fb823636ca633bf2", "size": 1195, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/test_mo_functions/main.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_functions/main.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_functions/main.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": 27.1590909091, "max_line_length": 72, "alphanum_fraction": 0.6, "num_tokens": 478, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110339361275, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6883385525251647}} {"text": "module Tools\n USE Inputs\n implicit none\n SAVE\n\ncontains\n \n ! Bin_Data subroutine enables the binning of data into a histogram\n !\n !\n ! ------------------------------Arguments-------------------------------------\n !\n ! HistoData: A 1xN array, where N is the number of bins in the histogram. N is usually the parameter bins\n !\n ! Data: A 1xM array, where M is the number of contributions to be added to HistoData. Each element is the value of a contribution\n !\n ! Weights: (OPTIONAL) A 1xM array containing the weights of each contribution in Data. If not present, the weight of a contribution is 1\n ! \n !\n ! Dropped: (OPTIONAL) A variable of type integer that keeps track of the number of contributions outside of a specified range\n ! If not present, dropped contributions are ignored\n !\n ! Max/Min: Type real. The maximum (Max) and minimum (Min) values to be counted. Contributions outside are not counted\n \n subroutine Bin_Data( HistoData, Data, Weights, Dropped, Max, Min, bins )\n implicit none\n real(dp), dimension(:), intent(in) :: Data\n real(dp), dimension(:), Optional, intent(in) :: Weights\n integer, intent(in) :: bins\n real(dp), intent(inout) :: HistoData(bins)\n real, intent(in) :: Max\n real, intent(in) :: Min\n real(dp), optional, intent(inout) :: Dropped\n integer Loop1, Loop2 !Loop integers\n \n ! since both Dropped and Weights are optional there are 2^2 different versions of this subroutine.\n\n !First is if both Dropped and Weights are present\n If ( Present(Dropped) .and. Present(Weights) ) then\n \n do Loop1 = 1,size(Data) !Loop through contributions\n if ( Weights(Loop1) .eq. 0 ) CYCLE !If a contribution has a weight of 0, ignore.\n if ( ( Data(Loop1) .lt. Min ) .or. ( Data(Loop1) .gt. Max ) ) then \n Dropped = Dropped + Weights(Loop1) !If a contribution is \\lt or \\gt min/max increment Dropped\n else\n Loop2 = FLOOR(bins*(Data(Loop1) - Min)/(Max - Min) + 1) !Find bin number of contribution\n if ( (Loop2 .gt. bins) .or. (Loop2 .lt. 1) ) then !Had some precision errors near the edge of the band, this ignore those\n Dropped = Dropped + Weights(Loop1)\n end if\n \n HistoData(Loop2) = HistoData(Loop2) + Weights(Loop1) !Increment Loop2 bin of HistoData by the Weight is the Loop2 element\n \n end if\n \n end do\n\n !Second is if Dropped is present and Weights is not\n else if ( Present(Dropped) .and. (.not. Present(Weights) ) ) then\n\n do Loop1 = 1,size(Data) \n if ( ( Data(Loop1) .lt. Min ) .or. ( Data(Loop1) .gt. Max ) ) then\n Dropped = Dropped + 1\n else \n Loop2 = FLOOR(bins*(Data(Loop1) - Min)/(Max - Min) + 1)\n if ( (Loop2 .gt. bins) .or. (Loop2 .lt. 1) ) CYCLE\n HistoData(Loop2) = HistoData(Loop2) + 1\n \n end if\n \n end do\n\n !Third is if Dropped is not present and Weights is present\n else if ( (.not. Present(Dropped)) .and. Present(Weights) ) then\n\n do Loop1 = 1,size(Data) \n if ( ( Data(Loop1) .lt. Min ) .or. ( Data(Loop1) .gt. Max ) ) CYCLE\n Loop2 = FLOOR(bins*(Data(Loop1) - Min)/(Max - Min) + 1)\n if ( (Loop2 .gt. bins) .or. (Loop2 .lt. 1) ) CYCLE\n HistoData(Loop2) = HistoData(Loop2) + Weights(Loop1)\n \n end do\n \n !Last is if neither Dropped nor Weights are present.\n else if ( .not. ( Present(Dropped) .or. Present(Weights) ) ) then\n\n do Loop1 = 1,size(Data) \n if ( ( Data(Loop1) .lt. Min ) .or. ( Data(Loop1) .gt. Max ) ) CYCLE\n Loop2 = FLOOR(bins*(Data(Loop1) - Min)/(Max - Min) + 1)\n if ( (Loop2 .gt. bins) .or. (Loop2 .lt. 1) ) CYCLE \n HistoData(Loop2) = HistoData(Loop2) + 1\n \n end do\n\n else\n print*, \"Bin_Data options exceeded\"\n STOP\n end if\n \n \n\n end subroutine Bin_Data\n \n ! OpenFile creates a file with comments detailing system parameters and contents of the file\n !\n !\n ! ------------------------------Arguments-------------------------------------\n !\n ! Unum : Integer variable that contains the unit number for the file. Usually on the order of 100\n !\n ! Name : Character variable with any length that specificies the base file name.\n !\n ! Contents : Character variable with any length that names the data inside\n !\n ! Column1 : Character Variable with any length. Specifies the information in the first column\n !\n ! Column2 : Character Variable with any length. Specifies the information in the second column\n\n \n subroutine OpenFile( Unum, Name, Contents, Column1, Column2, num_procs )\n implicit none\n integer, intent(in) :: Unum\n character(len=*), intent(in) :: Name, Contents, Column1, Column2\n integer, intent(in), optional :: num_procs\n character(len=25) :: filename\n character(len=8) :: FormatP, FormatB\n filename = Name\n filename = FileNamer(filename)\n open (unit = Unum, file = \"output/\"//trim(filename)//\"\" ,status ='unknown' )\n\n FormatP = '(A,F6.1)'\n FormatB = '(A,F6.2)'\n \n write(Unum,'(A,A)') \"#This file contains the following data type for the ensemble: \", Trim(Contents)\n write(Unum,'(A,A)') \"#First column is: \", Trim(Column1)\n write(Unum,'(A,A)') \"#Second column is: \", Trim(Column2)\n write(Unum,FormatP) \"#Disorder Strength = \", DELTA\n write(Unum,FormatB) \"#Bond Cutoff = \", bond_cutoff\n write(Unum,FormatB) \"#Pruned bonds cutoff = \", prune_cutoff\n write(Unum,'(A)') \"#Fraction of n.n. sites in which at least one orbital pair ignored = \"\n write(Unum,'(A,F6.3)') \"#\", real(PrunedBonds)/real(dim*systemn)\n write(Unum,'(A,F6.3)') \"#Fraction of prunings that are useful = \", real(StrongestBondsPruned)/real(PrunedBonds)\n write(Unum,FormatP) \"#Hopping = \", hop\n write(Unum,FormatP) \"#Interaction strength = \", uSite\n write(Unum,FormatP) \"#Chemical Potential = \", ChemPot\n write(Unum,'(A,I4)') \"#Dimensions = \", dim\n if ( Present(num_procs) ) then\n write(Unum,'(A,I4)') \"#Number of processes = \", num_procs\n write(Unum,'(A,I10)') \"#Number of systems = \", num_procs*systemn\n else if ( .not. Present(num_procs) ) then\n write(Unum,'(A,I10)') \"#Number of systems = \", systemn\n end if\n\n \n \n\n end subroutine OpenFile\n \n ! PrintFile prints the data to the file created in OpenFile\n !\n !\n ! ------------------------------Arguments-------------------------------------\n !\n ! Unum : Integer variable that contains the unit number for the file. Usually on the order of 100\n !\n ! Form : Character variable of any length. Specifies the form the printed data will take in the file\n !\n ! Max/Min : real variable specifying the max and min values for the data being printed. Used for bin sizes\n !\n ! BinNum : Integer variable. Number of bins to be printed.\n !\n ! Data : Real rank-one array. Data to be printed.\n !\n ! Dropped : (OPTIONAL) real variable. Counts the combined weight that is less than min or greater than max for the purposes of normalization\n \n subroutine PrintData( Unum, Form, Min, Max, BinNum, Data_DOS, Data_dp, Data_int, Dropped )\n implicit none\n integer, intent(in) :: Unum, BinNum\n character(len=*), intent(in) :: Form\n real, intent(in) :: Min, Max\n real(dp), optional, intent(in) :: Dropped\n real(dp), optional, intent(in), dimension(:) :: Data_DOS, Data_dp\n integer(ip), optional, intent(in), dimension(:) :: Data_int\n real(dp) :: width\n integer :: Loop1\n integer(ip) :: sum1\n\n !This is Dropped is present\n if ( Present(Data_DOS) ) then\n if ( Present(Dropped) ) then\n width = (Max-Min)/BinNum\n do Loop1=1,BinNum\n write(Unum,(Form)) Min + ( Max - Min )*Loop1/real(BinNum) - BinWidth/2, Data_DOS(Loop1)/ &\n ( (Sum(Data_DOS) + Dropped) * width )\n end do\n else\n !If not present this is used. Difference is minor but not dividing by Dropped or the sum of data.\n !Second part is to enable cumulative DOS (DOS with clustermax=1,2,3,4,5 normalized to the DOS with clustermax = 6)\n width = (Max-Min)/BinNum\n do Loop1=1,BinNum\n write(Unum,( Form)) Min + ( Max - Min )*Loop1/real(BinNum) - BinWidth/2, Data_DOS(Loop1)/( width )\n end do\n end if\n end if\n\n if ( Present(Data_dp) ) then\n width = (Max-Min)/BinNum\n do Loop1=1,BinNum\n write(Unum,(Form)) Min + ( Max - Min )*Loop1/real(BinNum) - BinWidth/2, Data_dp(Loop1)/( Sum(Data_dp)*width )\n end do\n end if\n\n if (Present(Data_int) ) then\n sum1=0\n do Loop1=1,BinNum\n sum1 = sum1 + Data_int(Loop1)\n end do\n width = (Max - Min)/real(BinNum)\n do Loop1=1,BinNum\n write(Unum,(Form)) Min + ( Max - Min )*Loop1/real(BinNum) - BinWidth/2, Data_int(Loop1)/(sum1*width)\n end do\n end if\n \n Close(Unum)\n\n end subroutine PrintData\n\n ! resize_array removes a number of elements from a rank-one array\n !\n !\n ! ------------------------------Arguments-------------------------------------\n !\n ! array : Real rank-one array that is to be resized\n !\n ! numRemove : Integer. The number of elements to remove starting from the element Start in array\n !\n ! Start : Integer. The first element to remove from array\n\n subroutine resize_array(array, numRemove, Start)\n real(dp), dimension(:), allocatable :: tmp_arr\n real(dp), dimension(:), allocatable, intent(inout) :: array\n integer, intent(in) :: numRemove ! Number of elements to remove from 'array'\n integer, intent(in) :: Start ! The element in which to start removing the array\n integer i, j ! Looping integer\n \n allocate(tmp_arr(size(array) - numRemove))\n\n tmp_arr(:) = 0.d0\n\n j=1\n\n if ( (Start + numRemove) .le. size(array) ) then\n\n\n do i = 1, Start - 1\n\n tmp_arr(i) = array(i)\n j = j + 1\n\n end do\n\n\n do i = (Start + numRemove), Size(array)\n\n tmp_arr(j) = array(i)\n j = j + 1\n\n end do\n\n\n\n else if ( (Start + numRemove) .gt. size(array) ) then\n\n do i = (Start + numRemove - size(array)) , Start-1\n\n tmp_arr(j) = array(i)\n j = j + 1\n\n end do\n\n\n end if\n\n deallocate(array)\n allocate(array(size(tmp_arr)))\n \n array = tmp_arr\n \n \n end subroutine resize_array\n \n subroutine DefineCluster( SitePotential, Sites, weakL, weakR, ClusterSize )\n implicit none\n\n ! Inputs\n real(dp), dimension(dim), intent(in) :: SitePotential\n integer, intent(in) :: weakL, weakR\n integer, intent(in) :: ClusterSize\n\n ! Outputs\n real(dp), dimension(ClusterSize), intent(out) :: Sites\n\n ! Other\n integer :: EndSite\n \n if ( (weakL .ge. weakR) .and. (ClusterSize .gt. 1) ) then !2, 3 site clusters which wrap around the \"edge\" of the system. As well as 4-site clusters with a single weak bond\n EndSite = dim - weakL\n Sites(1:EndSite) = SitePotential((weakL+1):dim)\n Sites((EndSite+1):ClusterSize) = SitePotential(1:weakR)\n else if ( ClusterSize .eq. 1 ) then !1-site clusters\n Sites = SitePotential(weakR:weakR)\n else if ( (ClusterSize .eq. dim) .and. (weakL .eq. 0) ) then !4-site clusters with no weak bonds\n Sites = SitePotential\n else !All other clusters\n Sites = SitePotential((weakL+1):weakR)\n end if\n\n end subroutine DefineCluster \n \n\n ! str(k) takes an integer k as input and returns a string with the same integer\n \n character(len=20) function str(k) \n integer, intent(in) :: k\n \n write (str, *) k\n str = adjustl(str)\n end function str\n \n ! FileNamer(Name) takes a base file name as input and adds a counter starting at 0 to the file name. If that exists, the counter is incremented by 1 (++)\n \n character(len=25) function FileNamer(Name) ! Increments filename labels Blah023.dat label:023\n character(len=25), intent(in) :: Name ! Initial filename. Would be 'Blah' from above example\n integer num ! Keeps track of the label increment as this continues to check for name existence\n logical Exist ! Used to store if a filename exists\n \n Exist = .true.\n num = 0\n FileNamer = \"\"//trim(Name)//\"000.text\" ! Takes Blah and puts it into the format 'Blah000.text'\n \n do while (Exist) ! Continue to change filename if the current one exists\n inquire( file = \"output/\"//trim(FileNamer)//\"\", exist = Exist ) ! Checks the current folder (where this .f90 file is found) if the current filename exists\n if ( Exist ) then ! If the file name exists\n num = num + 1 ! Increment the label\n \n if ( len(trim(str(num))) .eq. 1 ) then ! Labels can be from 000 to 999. To preserve filename length the leading zeros are required\n FileNamer = \"\"//trim(Name)//\"00\"//trim(str(num))//\".text\" ! This if statement (and the one below) check the length of the label (1 has length 1, 23 has length 2, 450 has length 3)\n else if ( len(trim(str(num))) .eq. 2) then ! This determines the number of leading zeros to add to the filename label\n FileNamer = \"\"//trim(Name)//\"0\"//trim(str(num))//\".text\"\n else\n FileNamer = \"\"//trim(Name)//trim(str(num))//\".text\"\n end if\n \n else if ( .not. Exist ) then ! If it does not exist. Note: Didn't increment 'num'\n if ( len(trim(str(num))) .eq. 1 ) then\n FileNamer = \"\"//trim(Name)//\"00\"//trim(str(num))//\".text\"\n else if ( len(trim(str(num))) .eq. 2) then\n FileNamer = \"\"//trim(Name)//\"0\"//trim(str(num))//\".text\"\n else\n FileNamer = \"\"//trim(Name)//trim(str(num))//\".text\"\n end if\n Exist = .false.\n else\n print*, \"You belong in a museum. Error: FileNameErr\" ! Outputs error if something strange happens. Can't imagine what\n end if\n end do\n end function FileNamer\n \n \n \nend module Tools\n \n \n \n", "meta": {"hexsha": "08a72358ba289802d4001f47ce61da46c7347c67", "size": 14954, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tools.f90", "max_stars_repo_name": "djallum/AHMCodePara", "max_stars_repo_head_hexsha": "d7adba435786a754aecfd606e9f753b28ea81dd2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Tools.f90", "max_issues_repo_name": "djallum/AHMCodePara", "max_issues_repo_head_hexsha": "d7adba435786a754aecfd606e9f753b28ea81dd2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Tools.f90", "max_forks_repo_name": "djallum/AHMCodePara", "max_forks_repo_head_hexsha": "d7adba435786a754aecfd606e9f753b28ea81dd2", "max_forks_repo_licenses": ["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.9839572193, "max_line_length": 197, "alphanum_fraction": 0.568677277, "num_tokens": 3971, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110425624792, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6883385498225134}} {"text": "!Program to test SET_EXPONENT intrinsic function.\n\nprogram test_set_exponent\n call test_real4()\n call test_real8()\nend\n\nsubroutine test_real4()\n real*4 x,y\n integer*4 i,n\n equivalence(x, i)\n\n n = -148\n x = 1024.0\n y = set_exponent (x, n)\n if ((y .ne. 0.0) .and. (exponent (y) .ne. n)) call abort()\n\n n = 8\n x = 1024.0\n y = set_exponent (x, n)\n if (exponent (y) .ne. n) call abort()\n\n n = 128\n i = 8388607\n x = transfer (i, x) ! z'007fffff' Positive denormalized floating-point.\n y = set_exponent (x, n)\n if (exponent (y) .ne. n) call abort()\n\n n = -148\n x = -1024.0\n y = set_exponent (x, n)\n if ((y .ne. 0.0) .and. (exponent (y) .ne. n)) call abort()\n\n n = 8\n x = -1024.0\n y = set_exponent (x, n)\n if (y .ne. -128.0) call abort()\n if (exponent (y) .ne. n) call abort()\n\n n = 128\n i = -2139095041\n x = transfer (i, x) ! z'807fffff' Negative denormalized floating-point.\n y = set_exponent (x, n)\n if (exponent (y) .ne. n) call abort()\n\nend\n\nsubroutine test_real8()\n implicit none\n real*8 x, y\n integer*8 i, n\n equivalence(x, i)\n\n n = -1073\n x = 1024.0_8\n y = set_exponent (x, n)\n if ((y .ne. 0.0_8) .and. (exponent (y) .ne. n)) call abort()\n\n n = 8\n x = 1024.0_8\n y = set_exponent (x, n)\n if (y .ne. 128.0) call abort()\n if (exponent (y) .ne. n) call abort()\n\n n = 1024\n i = 4503599627370495_8\n x = transfer (i, x) !z'000fffffffffffff' Positive denormalized floating-point.\n y = set_exponent (x, n)\n if (exponent (y) .ne. n) call abort()\n\n n = -1073\n x = -1024.0\n y = set_exponent (x, n)\n if ((y .ne. 0.0) .and. (exponent (y) .ne. n)) call abort()\n\n n = 8\n x = -1024.0\n y = set_exponent (x, n)\n if (y .ne. -128.0) call abort()\n if (exponent (y) .ne. n) call abort()\n\n n = 1024\n i = -9218868437227405313_8\n x = transfer (i, x)!z'800fffffffffffff' Negative denormalized floating-point.\n y = set_exponent (x, n)\n if (exponent (y) .ne. n) call abort()\nend\n", "meta": {"hexsha": "6f934e591c023ec256642228dba767630996baa4", "size": 1916, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_set_exponent.f90", "max_stars_repo_name": "best08618/asylo", "max_stars_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-05-02T17:34:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-17T10:15:18.000Z", "max_issues_repo_path": "llvm-gcc-4.2-2.9/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_set_exponent.f90", "max_issues_repo_name": "vidkidz/crossbridge", "max_issues_repo_head_hexsha": "ba0bf94aee0ce6cf7eb5be882382e52bc57ba396", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "llvm-gcc-4.2-2.9/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_set_exponent.f90", "max_forks_repo_name": "vidkidz/crossbridge", "max_forks_repo_head_hexsha": "ba0bf94aee0ce6cf7eb5be882382e52bc57ba396", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-27T00:22:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-01T09:41:02.000Z", "avg_line_length": 21.7727272727, "max_line_length": 80, "alphanum_fraction": 0.5965553236, "num_tokens": 806, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190939, "lm_q2_score": 0.8006920092299293, "lm_q1q2_score": 0.6883258899002875}} {"text": "module auxilary_subroutines\nimplicit none\ncontains\n!\n!--------------------------------------------------------\n! Combinations:\n!-------------------------------------------------------\n!\ninteger(kind=16) function combination_x_of_p(x,p)\nimplicit none\n!\ninteger(kind=16), intent(in) :: x, p\ninteger(kind=16) :: diff, prod, x_fact, p_x_fact, i\n!\ndiff = p - x\nwrite(*,*) 'x', x, 'p', p\nwrite(*,*) 'diff', diff\n!\n!--------------------\n! p-x > x :\n!--------------------\n!\nif (diff .ge. x) then\n write(*,*) 'p - x > x'\n prod = 1\n do i = 1, x\n prod = prod * (diff + i)\n write(*,*) 'prod', prod\n end do\n !\n if (x .ne. 0) then\n x_fact = 1\n do i = 1, x\n x_fact = x_fact * i\n end do\n end if\n if (x .eq. 0) then\n x_fact = 1\n end if\n !\n write(*,*) 'prod', prod\n write(*,*) 'x_fact', x_fact\n combination_x_of_p = prod/x_fact\n write(*,*) 'combination x of p', combination_x_of_p\n!\n!--------------------------\n! p-x < x :\n!--------------------------\n!\nelse if (diff .lt. x) then\n write(*,*) 'x > p - x'\n prod = 1\n do i = 1, diff\n prod = prod * (x+i)\n end do\n !\n p_x_fact = 1\n do i = 1, p - x\n p_x_fact = p_x_fact * i\n end do\n !\n combination_x_of_p = prod/p_x_fact\nend if\n!\n!-----------------------------------------------------------------\n! example -> x .lt. p-x\n!-----------------------------------------------------------------\n!\n! p = 8\n! x = 2\n! p - x = 6\n!\n! x < p-x\n!\n! 6! 7 8 p-x+1 p-x+2\n! -------------- = --------------------\n! 6! 2! x! \n!\n!-----------------------------------------------------------------\n! example -> x .gt. p=x\n!-----------------------------------------------------------------\n!\n! p = 8\n! x = 5\n! p - x = 3\n!\n! 5! 6 7 8 x+1 x+2 x+3\n! ------------ = ------------------\n! 5! 3! p - x!\n!\n! \nend function combination_x_of_p\n!\n!-----------------------------------------------------------------\n!Subroutine to generate the distance matrix for a structure:\n!-----------------------------------------------------------------\n!\nsubroutine distance_matrix (a_matrix, a_atoms, dist_matrix)\nimplicit none\ninteger, parameter :: dp = SELECTED_REAL_KIND(15)\n!\nreal(dp), allocatable, dimension(:,:), intent(in) :: a_matrix\ninteger, intent(in) :: a_atoms\nreal(dp), allocatable, dimension(:,:), intent(out) :: dist_matrix\ninteger :: i, j\n!\nallocate(dist_matrix(a_atoms,a_atoms))\ndo i = 1, a_atoms\n do j = 1, a_atoms\n dist_matrix(i,j) = sqrt( (a_matrix(i,1)-a_matrix(j,1))**(2.) + &\n (a_matrix(i,2)-a_matrix(j,2))**(2.) + &\n (a_matrix(i,3)-a_matrix(j,3))**(2.) )\n end do\nend do\n!\nwrite(*,*)'Distance matrix:'\nwrite(*,*)'----------------------------------------'\n!\ndo i = 1, a_atoms\n write(*,'(20F7.3)') (dist_matrix(i,j), j=1,a_atoms)\nend do\n!\nend subroutine distance_matrix\n! \n!----------------------------------------------------------------\n!Periodic system - read the mass for every atom in the molecule:\n!----------------------------------------------------------------\n!\nsubroutine periodic (labels_in, a, masses_out)\nImplicit none\ninteger, parameter :: dp = SELECTED_REAL_KIND(15)\n!\ncharacter(len=1), allocatable, dimension(:), intent(in) :: labels_in\ninteger :: a, i, k !number of atoms\nreal(dp), dimension(2) :: masses\ncharacter(len=1), dimension(2) :: atoms\nreal(dp), allocatable, dimension(:), intent(out) :: masses_out\n!\natoms = (/'B', 'V'/) \nmasses = (/10.81, 50.9415/)\n!\nallocate ( masses_out(a) )\n!\n!-----------------------\n!Assigning the masses:\n!-----------------------\n!\ndo i = 1, a\n do k = 1, 2\n if (labels_in(i) == atoms(k)) then\n masses_out(i) = masses(k)\n end if\n end do \nend do \n!\nend subroutine periodic\n!\n!---------------------------------------------------------\n!Calculate CPU time:\n!---------------------------------------------------------\n!\nsubroutine CPU (start, method15)\nimplicit none\n!\ninteger, parameter :: dp = SELECTED_REAL_KIND(15)\nreal(dp), intent(in) :: start\ncharacter(len=17), intent(in) :: method15\nreal(dp) :: finish, cputime\n!\ncall CPU_time(finish)\ncputime = finish - start\nwrite(25,*)\nwrite(25,'(A18)') method15, ':'\nwrite(25,*) 'CPU time:', cputime\n!\nend subroutine CPU\n!\nend module auxilary_subroutines\n", "meta": {"hexsha": "e31e64d868ea533735db7455cdc61ae5d232580b", "size": 4291, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "test_compare_procedure/test2/aux_mod.f95", "max_stars_repo_name": "ElenaKusevska/coordinates_on_a_grid", "max_stars_repo_head_hexsha": "6605c76d9c6561fee6eaaa844fb954f7784f623c", "max_stars_repo_licenses": ["MIT"], "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_compare_procedure/test2/aux_mod.f95", "max_issues_repo_name": "ElenaKusevska/coordinates_on_a_grid", "max_issues_repo_head_hexsha": "6605c76d9c6561fee6eaaa844fb954f7784f623c", "max_issues_repo_licenses": ["MIT"], "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_compare_procedure/test2/aux_mod.f95", "max_forks_repo_name": "ElenaKusevska/coordinates_on_a_grid", "max_forks_repo_head_hexsha": "6605c76d9c6561fee6eaaa844fb954f7784f623c", "max_forks_repo_licenses": ["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.9720670391, "max_line_length": 69, "alphanum_fraction": 0.4437194127, "num_tokens": 1209, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705732, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.68828747051038}} {"text": "!********************************************************************************\n! HORNER_RUNERR: Test compensated Horner running error bound\n! Authors: Thomas R. Cameron and Aidan O'Neill\n! Institution: Davidson College, Mathematics and Computer Science Department\n! Last Modified: 29 March 2020\n!********************************************************************************\nprogram horner_runErr\n use eft \n use mproutines\n implicit none\n ! paramters\n integer, parameter :: deg = 5, n = 2000\n real(kind=dp), parameter :: dx = 1E-5_dp\n ! polynomial variables\n real(kind=dp), allocatable :: poly(:), roots(:)\n complex(kind=dp), allocatable :: cpoly(:), croots(:)\n ! testing variables\n integer :: k\n real(kind=dp) :: abound, comp, error, exact, g, rbound, x\n complex(kind=dp) :: ccomp, cexact, z\n \n ! allocate polynomial variables\n allocate(poly(deg+1), roots(deg))\n roots = (/ (1.0_dp, k=1,deg)/)\n\tpoly(deg+1) = 1.0_dp\n call rootCoeff(deg,roots,poly)\n ! open file\n open(unit=1,file=\"data_files/horner_runErr_real.dat\")\n write(1,'(A)') 'x, a priori error bound, running error bound, forward error'\n ! run real test\n x = 0.99_dp\n do k=1,n+1\n ! multi-precision real Horner\n exact = MPHorner(poly,x,deg)\n ! compensated Horner and running error bound\n call CHorner(poly,x,deg,comp,rbound)\n ! a priori error bound\n g = 2*deg*mu/(1-2*deg*mu)\n abound = mu*abs(exact) + MPHorner(abs(poly),abs(x),deg)*g**2\n ! forward error\n error = CHornerErr(poly,x,deg,comp)\n ! write real test results\n write(1,'(ES15.5,A)', advance='no') x, ', '\n write(1,'(ES15.5,A)', advance='no') abound, ', '\n write(1,'(ES15.5,A)', advance='no') rbound, ', '\n write(1,'(ES15.5)') error\n ! update x\n x = x + dx\n end do\n ! deallocate polynomial variables\n deallocate(poly, roots)\n ! close file\n close(1)\n \n ! allocate polynomial variables\n allocate(cpoly(deg+1), croots(deg))\n croots = (/ (cmplx(1.0_dp,1.0_dp,kind=dp), k=1,deg)/)\n\tcpoly(deg+1) = cmplx(1.0_dp,0.0_dp,kind=dp)\n call rootCoeffCplx(deg,croots,cpoly)\n ! open file\n open(unit=1,file=\"data_files/horner_runErr_cmplx.dat\")\n write(1,'(A)') 'x, a priori error bound, running error bound, forward error'\n ! run complex test\n z = cmplx(0.99_dp,1.0_dp,kind=dp)\n do k=1,n+1\n ! multi-precision complex Horner\n cexact = MPHornerCplx(cpoly,z,deg)\n ! compensated Horner and running error bound\n call CHornerCplx(cpoly,z,deg,ccomp,rbound)\n ! a priori error bound\n g = 2*mu/(1-2*mu)\n g = 2*deg*sqrt(2.0_dp)*g/(1-2*deg*sqrt(2.0_dp)*g)\n abound = mu*abs(cexact) + MPHorner(abs(cpoly),abs(z),deg)*g**2\n ! forward error\n error = CHornerErrCplx(cpoly,z,deg,ccomp)\n ! write real test results\n write(1,'(ES15.5,A)', advance='no') real(z), ', '\n write(1,'(ES15.5,A)', advance='no') abound, ', '\n write(1,'(ES15.5,A)', advance='no') rbound, ', '\n write(1,'(ES15.5)') error\n ! update z\n z = z + cmplx(dx,0,kind=dp)\n end do\n ! deallocate polynomial variables\n deallocate(cpoly, croots)\n ! close file\n close(1)\ncontains\n \n !****************************************************\n ! Horner Sum *\n !****************************************************\n ! Computes the evaluation of the sum of two\n ! polynomials of degree (deg-1), at a floating-point \n ! number. Result is returned in comp which has type \n ! real(kind=dp).\n !****************************************************\n function HSum(p,q,x,deg) result(comp)\n implicit none\n ! argument variables\n integer :: deg\n real(kind=dp) :: p(:), q(:), x\n ! local variables\n integer :: k\n real(kind=dp) :: comp\n \n ! Horner's method\n comp = p(deg) + q(deg)\n do k=deg-1,1,-1\n comp = x*comp + (p(k) + q(k))\n end do\n return\n end function HSum\n !****************************************************\n ! HornerSumCplx *\n !****************************************************\n ! Computes the evaluation of the sum of four\n ! complex polynomials of degree deg-1, at a complex \n ! floating-point number. Result is returned in comp \n ! which has type complex(kind=dp).\n !****************************************************\n function HSumCplx(p,q,r,s,x,deg) result(comp)\n implicit none\n ! argument variables\n integer :: deg\n complex(kind=dp) :: p(:), q(:), r(:), s(:), x\n ! local variables\n integer :: k\n complex(kind=dp) :: comp\n \n ! Horner's method\n comp = FaithSumCplx(p(deg),q(deg),r(deg),s(deg))\n do k=deg-1,1,-1\n comp = x*comp + FaithSumCplx(p(k),q(k),r(k),s(k))\n end do\n return\n end function HSumCplx\n !****************************************************\n ! Compensated Horner *\n !****************************************************\n ! Computes the evaluation of a polynomial at\n ! a floating point number using the compensated\n ! Horner routine. The result is stored in comp and the\n ! running relative forward error is stored in error.\n !****************************************************\n subroutine CHorner(poly,x,deg,comp,error)\n implicit none\n ! argument variables\n integer, intent(in) :: deg\n real(kind=dp), intent(in) :: poly(:), x\n real(kind=dp), intent(out) :: comp, error\n ! local variables\n real(kind=dp) :: g\n type(REFTHorner) :: eft\n \n ! compute EFTHorner\n eft = EFTHorner(poly,x,deg)\n ! compute error using HSum and add back to result\n comp = eft%h + HSum(eft%p,eft%q,x,deg)\n ! compute running forward error\n g = (4*deg+2)*mu/(1-(4*deg+2)*mu)\n error = mu*abs(comp) + (2*mu**2*abs(comp) + g*HSum(abs(eft%p),abs(eft%q),abs(x),deg))\n ! deallocate error polynomials in eft\n deallocate(eft%p,eft%q)\n end subroutine CHorner\n !****************************************************\n ! Compensated Horner Cplx *\n !****************************************************\n ! Computes the evaluation of a polynomial at\n ! a floating point number using the compensated\n ! Horner routine. The result is stored in comp and the\n ! running relative forward error is stored in error.\n !****************************************************\n subroutine CHornerCplx(poly,x,deg,comp,error)\n implicit none\n ! argument variables\n integer, intent(in) :: deg\n complex(kind=dp), intent(in) :: poly(:), x\n real(kind=dp), intent(out) :: error\n complex(kind=dp), intent(out) :: comp\n ! local variables\n integer :: k\n real(kind=dp) :: g\n type(CEFTHorner) :: eft\n \n ! compute EFTHornerCplx\n eft = EFTHornerCplx(poly,x,deg)\n ! compute error using HSumCplx and add back to result\n comp = eft%h + HSumCplx(eft%p,eft%q,eft%r,eft%s,x,deg)\n ! compute running forward error\n g = 2*mu/(1-2*mu)\n g = (4*deg+2)*sqrt(2.0_dp)*g/(1-(4*deg+2)*sqrt(2.0_dp)*g)\n error = FaithSum(abs(eft%p(deg)),abs(eft%q(deg)),abs(eft%r(deg)),abs(eft%s(deg)))\n do k=deg-1,1,-1\n error = abs(x)*error + FaithSum(abs(eft%p(k)),abs(eft%q(k)),abs(eft%r(k)),abs(eft%s(k)))\n end do\n error = mu*abs(comp) + (g*error + 2*mu**2*abs(comp))\n ! deallocate error polynomials in eft\n deallocate(eft%p,eft%q,eft%r,eft%s)\n end subroutine CHornerCplx\n !****************************************************\n ! Compensated Horner Error *\n !****************************************************\n ! Compute error in compensated Horner evaluation vs.\n ! MP Horner evaluation. \n !****************************************************\n function CHornerErr(poly,x,deg,comp) result(err)\n implicit none\n ! argument variables\n integer :: deg\n real(kind=dp) :: poly(:), x, comp\n ! local variables\n integer :: k\n real(kind=dp) :: err\n type(mp_real) :: mp_comp, mp_err, mp_horner, mp_poly(deg+1), mp_x\n \n ! convert to mp-type\n mp_comp = mpreald(comp)\n do k=1,deg+1\n mp_poly(k) = mpreald(poly(k))\n end do\n mp_x = mpreald(x)\n ! Horner's method\n mp_horner = mp_poly(deg+1)\n do k=deg,1,-1\n mp_horner = mp_x*mp_horner + mp_poly(k)\n end do\n ! error\n mp_err = abs(mp_comp - mp_horner)\n ! convert to dp-precision\n err = mpreal(mp_err)\n end function CHornerErr\n !****************************************************\n ! Compensated Horner Error Cplx *\n !****************************************************\n ! Compute error in compensated Horner evaluation vs.\n ! MP Horner evaluation. \n !****************************************************\n function CHornerErrCplx(poly,x,deg,comp) result(err)\n implicit none\n ! argument variables\n integer :: deg\n complex(kind=dp) :: poly(:), x, comp\n ! local variables\n integer :: k\n real(kind=dp) :: err\n type(mp_real) :: mp_err\n type(mp_complex) :: mp_comp, mp_horner, mp_poly(deg+1), mp_x\n \n ! convert to mp-type\n mp_comp = mpcmplxdc(comp)\n do k=1,deg+1\n mp_poly(k) = mpcmplxdc(poly(k))\n end do\n mp_x = mpcmplxdc(x)\n ! Horner's method\n mp_horner = mp_poly(deg+1)\n do k=deg,1,-1\n mp_horner = mp_x*mp_horner + mp_poly(k)\n end do\n ! error\n mp_err = abs(mp_comp - mp_horner)\n ! convert to dp-precision\n err = mpreal(mp_err)\n end function CHornerErrCplx\nend program horner_runErr", "meta": {"hexsha": "dc0021ac1e5b029633620ea60901ea80842e9540", "size": 10562, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/horner_runErr.f90", "max_stars_repo_name": "trcameron/FPML-Comp", "max_stars_repo_head_hexsha": "f71c968b5a9fc490fcce7490b8543e6c54dc7c42", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/horner_runErr.f90", "max_issues_repo_name": "trcameron/FPML-Comp", "max_issues_repo_head_hexsha": "f71c968b5a9fc490fcce7490b8543e6c54dc7c42", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/horner_runErr.f90", "max_forks_repo_name": "trcameron/FPML-Comp", "max_forks_repo_head_hexsha": "f71c968b5a9fc490fcce7490b8543e6c54dc7c42", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.7067669173, "max_line_length": 100, "alphanum_fraction": 0.4819163037, "num_tokens": 2799, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278571786139, "lm_q2_score": 0.7799929002541067, "lm_q1q2_score": 0.6882874635857638}} {"text": "c...............................................\n function ylag(xi,x,y,ind1,n1,imax,iex)\nc\nc lagrangian interpolation\nc modified from subroutine polint from Numerical Recipe, by Press et al.\nc xi is intepolated entry into x-array\nc n is the order of lagrangran interpolation\nc y is array from which ylag is obtained by interpolation\nc ind is the min-i for x(i).gt.xi\nc if ind=0,x-array will be searched\nc imax is max index of x-and y-arrays\nc extrapolation can occur,iex=-1 or +1\nc\n implicit real*8(a-h,o-z)\n parameter(nmax=10)\n real*8 x(*),y(*)\n real*8 c(nmax),d(nmax),dx(nmax)\nc\n ind=ind1\n n=n1\n iex=0\n if (n.le.imax) go to 10\n n=imax\n iex=n\n 10 if (ind.gt.0) go to 40\n do 20 j = 1,imax\n if (xi-x(j) .lt. 0.0) goto 30\n if (xi-x(j) .eq. 0.0) goto 130\n 20 continue\n iex=1\n go to 70\n 30 ind=j\n 40 if (ind.le.1) iex=-1\n inl=max(0,ind-ishft(n+1,-1))\n inu=inl+n\n if (inu.le.imax) go to 80\n 70 inl=imax-n\n inu=imax\n 80 dif=abs(xi-x(inl+1))\n ns=1\n do 105 j=1,inu-inl\n\t j1=j+inl\n\t dx(j)=xi-x(j1)\n dift=abs(dx(j))\n if(dift.lt.dif) then\n ns=j\n dif=dift\n endif\n c(j)=y(j1)\n d(j)=y(j1)\n 105 continue\n ylag=y(inl+ns)\n ns=ns-1\n do 110 j=inl+1,inu-1\n do 100 i=1,inu-j\n\t ij=i+j\n den=x(i+inl)-x(ij)\n if(den.eq.0.d0) stop'Two xs are the same in ylag.'\n den=(d(i)-c(i+1))/den\n d(i)=dx(ij-inl)*den\n c(i)=dx(i)*den\n 100 continue\n if(ishft(ns,1).lt.inu-j) then\n ylag=ylag+c(2*ns+1)\n else\n ylag=ylag+d(ns)\n ns=ns-1\n endif\n 110 continue\n return\n 130 ylag=y(j)\n return\n end\n", "meta": {"hexsha": "c55c775f857682e27d64878fa533e98174b1ec92", "size": 1829, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/Misc/ylag.f", "max_stars_repo_name": "rdietric/lsms", "max_stars_repo_head_hexsha": "8d0d5f01186abf9a1cc54db3f97f9934b422cf92", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2020-01-05T20:05:31.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T09:08:01.000Z", "max_issues_repo_path": "src/Misc/ylag.f", "max_issues_repo_name": "rdietric/lsms", "max_issues_repo_head_hexsha": "8d0d5f01186abf9a1cc54db3f97f9934b422cf92", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2019-07-30T13:59:18.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T17:43:35.000Z", "max_forks_repo_path": "lsms/src/Misc/ylag.f", "max_forks_repo_name": "hkershaw-brown/MuST", "max_forks_repo_head_hexsha": "9db4bc5061c2f2c4d7dfd92f53b4ef952602c070", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2020-02-11T17:04:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-28T09:23:46.000Z", "avg_line_length": 24.7162162162, "max_line_length": 74, "alphanum_fraction": 0.5051940951, "num_tokens": 673, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278571786139, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6882874590728539}} {"text": "program do_cycle\n\n implicit none\n\n integer :: i\n real, parameter :: pi = 3.141592653\n real :: x, y\n\n do i = 0, 360, 10\n x = cos(real(i)*pi/180)\n y = sin(real(i)*pi/180)\n\n if (abs(x) < 1E-7) then\n print *, \"Small denominator (cycle)\"\n cycle\n end if\n print *, i, x, y, y/x\n end do\n\n print *, 'Final values:', i, x\n\nend program\n", "meta": {"hexsha": "1cd325022217d66976abb76ac296026d0af9906c", "size": 380, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "files/advanced/example_06.f90", "max_stars_repo_name": "WVUHPC/Modern-Fortran", "max_stars_repo_head_hexsha": "97c4db834d4e6ca43802318e4dc63ce4faa641aa", "max_stars_repo_licenses": ["CC-BY-4.0"], "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": "files/advanced/example_06.f90", "max_issues_repo_name": "WVUHPC/Modern-Fortran", "max_issues_repo_head_hexsha": "97c4db834d4e6ca43802318e4dc63ce4faa641aa", "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": "files/advanced/example_06.f90", "max_forks_repo_name": "WVUHPC/Modern-Fortran", "max_forks_repo_head_hexsha": "97c4db834d4e6ca43802318e4dc63ce4faa641aa", "max_forks_repo_licenses": ["CC-BY-4.0"], "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": 16.5217391304, "max_line_length": 45, "alphanum_fraction": 0.5131578947, "num_tokens": 130, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972818382005, "lm_q2_score": 0.7905303236047048, "lm_q1q2_score": 0.688233550940929}} {"text": " SUBROUTINE crank(n,w,s)\r\n INTEGER n\r\n REAL s,w(n)\r\n INTEGER j,ji,jt\r\n REAL rank,t\r\n s=0.\r\n j=1\r\n1 if(j.lt.n)then\r\n if(w(j+1).ne.w(j))then\r\n w(j)=j\r\n j=j+1\r\n else\r\n do 11 jt=j+1,n\r\n if(w(jt).ne.w(j))goto 2\r\n11 continue\r\n jt=n+1\r\n2 rank=0.5*(j+jt-1)\r\n do 12 ji=j,jt-1\r\n w(ji)=rank\r\n12 continue\r\n t=jt-j\r\n s=s+t**3-t\r\n j=jt\r\n endif\r\n goto 1\r\n endif\r\n if(j.eq.n)w(n)=n\r\n return\r\n END\r\n", "meta": {"hexsha": "70201f649426f423cea4707a61b370214e35256c", "size": 583, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/crank.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/crank.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/crank.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": 19.4333333333, "max_line_length": 36, "alphanum_fraction": 0.3636363636, "num_tokens": 196, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934408, "lm_q2_score": 0.7905303087996143, "lm_q1q2_score": 0.6882335221266144}} {"text": "!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 2005 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Fishpack *\n! * *\n! * A Package of Fortran *\n! * *\n! * Subroutines and Example Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams, Paul Swarztrauber and Roland Sweet *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\nprogram test_hstplr\n\n use fishpack\n\n ! Explicit typing only\n implicit none\n\n ! Dictionary\n integer(ip), parameter :: M = 50, N = 48\n integer(ip), parameter :: IDIMF = M + 1, NP1 = N + 1\n integer(ip) :: mbdcnd, nbdcnd, i, j, ierror\n real(wp) :: f(IDIMF, NP1)\n real(wp), dimension(N) :: bdb, theta\n real(wp), dimension(M) :: bdc, bdd, r\n real(wp) :: a, b, c, d, bda(1), dr, dtheta\n real(wp) :: elmbda, pertrb\n real(wp), parameter :: ZERO = 0.0_wp, HALF = 0.5_wp\n real(wp), parameter :: ONE = 1.0_wp, FOUR = 4.0_wp\n\n ! Set domain\n a = ZERO\n b = ONE\n c = ZERO\n d = HALF_PI\n\n ! Set boundary conditions\n mbdcnd = 5\n nbdcnd = 3\n\n ! Set helmholtz constant\n elmbda = ZERO\n\n ! Set mesh sizes\n dr = (b - a)/M\n dtheta = (d - c)/N\n\n ! Generate and store grid points for the purpose of computing\n ! boundary data and the right side of the poisson equation.\n do i = 1, M\n r(i) = (real(i, kind=wp) - HALF) * dr\n end do\n\n do j = 1, N\n theta(j) = (real(j, kind=wp) - HALF) * dtheta\n end do\n\n ! Generate boundary data. In our example, bda is a 1-dimensional dummy variable.\n bdb = ONE - cos(FOUR*theta)\n bdc = ZERO\n bdd = ZERO\n\n ! Generate right side of equation.\n block\n real(wp), parameter :: SIXTEEN = 16.0_wp\n\n do i = 1, M\n f(i, :N) = SIXTEEN * r(i)**2\n end do\n end block\n\n ! Solve 2D Helmholtz in polar coordinates on staggered grid\n call hstplr(a, b, M, mbdcnd, bda, bdb, c, d, N, nbdcnd, bdc, bdd, &\n elmbda, f, IDIMF, pertrb, ierror)\n\n ! Compute discretization error. the exact solution is\n !\n ! u(r, theta) = r**4*(1 - cos(4*theta))\n block\n real(wp), parameter :: KNOWN_ERROR = 0.113037945648764e-2_wp\n real(wp) :: discretization_error\n real(wp) :: exact_solution(M,N)\n\n do j = 1, N\n do i = 1, M\n exact_solution(i,j) = (r(i)**4) * (ONE - cos(FOUR * theta(j)))\n end do\n end do\n\n ! Set discretization error\n discretization_error = maxval(abs(exact_solution - f(:M,:N)))\n\n call check_output('hstplr', ierror, KNOWN_ERROR, discretization_error)\n end block\n\nend program test_hstplr\n", "meta": {"hexsha": "9a421a0d301f609a3b345283e4790dc640f67af5", "size": 4550, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/thstplr.f90", "max_stars_repo_name": "jlokimlin/fishpack", "max_stars_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2018-03-12T11:31:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-27T07:58:23.000Z", "max_issues_repo_path": "examples/thstplr.f90", "max_issues_repo_name": "jlokimlin/fishpack", "max_issues_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2016-05-07T22:42:47.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-15T17:44:58.000Z", "max_forks_repo_path": "examples/thstplr.f90", "max_forks_repo_name": "jlokimlin/fishpack", "max_forks_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-09-07T15:43:32.000Z", "max_forks_repo_forks_event_max_datetime": "2018-06-16T21:30:13.000Z", "avg_line_length": 38.2352941176, "max_line_length": 84, "alphanum_fraction": 0.3501098901, "num_tokens": 1070, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789457685656, "lm_q2_score": 0.7690802476562641, "lm_q1q2_score": 0.6881648977170985}} {"text": "program bmi\n implicit none\n real :: height, weight\n\n print *, 'Weight, please! (in kg)'\n read (*,*) weight\n\n print *, 'Now, your height (in m)'\n read(*,*) height\n\n write(*,'(A, F10.2') 'Your bmi is ', (weight / (height**2))\nend program bmi\n\n", "meta": {"hexsha": "86654d37ce825970eb4a5bebf66a48ee66d581bf", "size": 291, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "bmi.f90", "max_stars_repo_name": "yadunut/bmi-a", "max_stars_repo_head_hexsha": "56f7849626b067214a4ff7c21ede8a47a48b9f10", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "bmi.f90", "max_issues_repo_name": "yadunut/bmi-a", "max_issues_repo_head_hexsha": "56f7849626b067214a4ff7c21ede8a47a48b9f10", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "bmi.f90", "max_forks_repo_name": "yadunut/bmi-a", "max_forks_repo_head_hexsha": "56f7849626b067214a4ff7c21ede8a47a48b9f10", "max_forks_repo_licenses": ["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.7857142857, "max_line_length": 68, "alphanum_fraction": 0.4982817869, "num_tokens": 82, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.894789468908171, "lm_q2_score": 0.7690802317779601, "lm_q1q2_score": 0.688164892140374}} {"text": "module linalg\n contains\nfunction expm(a)\n ! ----------------------------------------------------------------------- !\n real(kind=8) :: expm(3,3)\n real(kind=8), intent(in) :: a(3,3)\n integer, parameter :: m=3, ldh=3, ideg=6, lwsp=4*m*m+ideg+1\n integer, parameter :: n=3, lwork=3*n-1\n real(kind=8) :: t, wsp(lwsp), v(3,3)\n real(kind=8) :: w(n), work(lwork), l(3,3)\n integer :: ipiv(m), iexph, ns, iflag, info\n character*120 :: msg\n ! ----------------------------------------------------------------------- !\n expm = 0.e+00_8\n if (all(abs(a) <= epsilon(a))) then\n expm = eye(3)\n return\n else if (isdiag(a)) then\n expm(1,1) = exp(a(1,1))\n expm(2,2) = exp(a(2,2))\n expm(3,3) = exp(a(3,3))\n return\n end if\n\n ! try dgpadm (usually good)\n t = 1.e+00_8\n iflag = 0\n call DGPADM(ideg, m, t, a, ldh, wsp, lwsp, ipiv, iexph, ns, iflag)\n if (iflag >= 0) then\n expm = reshape(wsp(iexph:iexph+m*m-1), shape(expm))\n return\n end if\n\n ! problem with dgpadm, use other method\n if (iflag == -8) then\n msg = '*** ERROR: bad sizes (in input of DGPADM)'\n else if (iflag == -9) then\n msg = '*** ERROR: Error - null H in input of DGPADM.'\n else if (iflag == -7) then\n msg = '*** ERROR: Problem in DGESV (within DGPADM)'\n end if\n print*, msg\n stop\n\n v = a\n call DSYEV(\"V\", \"L\", 3, v, 3, w, work, lwork, info)\n l = 0.e+00_8\n l(1,1) = exp(w(1))\n l(2,2) = exp(w(2))\n l(3,3) = exp(w(3))\n expm = matmul(matmul(v, l ), transpose(v))\n return\nend function expm\n\n! ------------------------------------------------------------------------- !\nfunction powm(a, m)\n ! ----------------------------------------------------------------------- !\n ! Computes the matrix power\n ! ----------------------------------------------------------------------- !\n real(kind=8) :: powm(3,3)\n real(kind=8), intent(in) :: a(3,3), m\n integer, parameter :: n=3, lwork=3*n-1\n real(kind=8) :: w(n), work(lwork), v(3,3), l(3,3)\n integer :: info\n ! eigenvalues/vectors of a\n v = a\n powm = 0.e+00_8\n if (isdiag(a)) then\n powm(1,1) = a(1,1) ** m\n powm(2,2) = a(2,2) ** m\n powm(3,3) = a(3,3) ** m\n else\n call DSYEV(\"V\", \"L\", 3, v, 3, w, work, lwork, info)\n l = 0.e+00_8\n l(1,1) = w(1) ** m\n l(2,2) = w(2) ** m\n l(3,3) = w(3) ** m\n powm = matmul(matmul(v, l ), transpose(v))\n end if\n return\nend function powm\n\n! ------------------------------------------------------------------------- !\nfunction sqrtm(a)\n ! ----------------------------------------------------------------------- !\n ! Computes the matrix sqrt\n ! ----------------------------------------------------------------------- !\n real(kind=8) :: sqrtm(3,3)\n real(kind=8), intent(in) :: a(3,3)\n integer, parameter :: n=3, lwork=3*n-1\n real(kind=8) :: w(n), work(lwork), v(3,3), l(3,3)\n integer :: info\n sqrtm = 0.e+00_8\n if (isdiag(a)) then\n sqrtm(1,1) = sqrt(a(1,1))\n sqrtm(2,2) = sqrt(a(2,2))\n sqrtm(3,3) = sqrt(a(3,3))\n else\n ! eigenvalues/vectors of a\n v = a\n call DSYEV(\"V\", \"L\", 3, v, 3, w, work, lwork, info)\n l = 0.e+00_8\n l(1,1) = sqrt(w(1))\n l(2,2) = sqrt(w(2))\n l(3,3) = sqrt(w(3))\n sqrtm = matmul(matmul(v, l ), transpose(v))\n end if\n return\nend function sqrtm\n\n! ------------------------------------------------------------------------- !\nfunction logm(a)\n ! ----------------------------------------------------------------------- !\n ! Computes the matrix logarithm\n ! ----------------------------------------------------------------------- !\n real(kind=8) :: logm(3,3)\n real(kind=8), intent(in) :: a(3,3)\n integer, parameter :: n=3, lwork=3*n-1\n real(kind=8) :: w(n), work(lwork), v(3,3), l(3,3)\n integer :: info\n if (isdiag(a)) then\n logm = 0.e+00_8\n logm(1,1) = log(a(1,1))\n logm(2,2) = log(a(2,2))\n logm(3,3) = log(a(3,3))\n else\n ! eigenvalues/vectors of a\n v = a\n call DSYEV(\"V\", \"L\", 3, v, 3, w, work, lwork, info)\n l = 0.e+00_8\n l(1,1) = log(w(1))\n l(2,2) = log(w(2))\n l(3,3) = log(w(3))\n logm = matmul(matmul(v, l), transpose(v))\n end if\n return\nend function logm\n\n! ------------------------------------------------------------------------- !\nfunction isdiag(a)\n logical :: isdiag\n real(kind=8), intent(in) :: a(3,3)\n isdiag = all(abs((/a(1,2),a(1,3),a(2,1),a(2,3),a(3,1),a(3,2)/)) <= epsilon(a))\n return\nend function isdiag\n\nfunction eye(n)\n integer, intent(in) :: n\n real(kind=8) :: eye(n,n)\n integer :: i\n eye = 0.e+00_8\n forall(i=1:n) eye(i,i) = 1.e+00_8\n return\nend function eye\n\n! ------------------------------------------------------------------------- !\n\nfunction det(a)\n ! ----------------------------------------------------------------------- !\n ! determinant of 3x3\n ! ----------------------------------------------------------------------- !\n implicit none\n real(kind=8) :: det\n real(kind=8), intent(in) :: a(3,3)\n det = a(1,1)*a(2,2)*a(3,3) &\n - a(1,1)*a(2,3)*a(3,2) &\n - a(1,2)*a(2,1)*a(3,3) &\n + a(1,2)*a(2,3)*a(3,1) &\n + a(1,3)*a(2,1)*a(3,2) &\n - a(1,3)*a(2,2)*a(3,1)\n return\nend function det\n\n! ------------------------------------------------------------------------- !\nfunction inv(a)\n ! ----------------------------------------------------------------------- !\n ! inverse of 3x3\n ! ----------------------------------------------------------------------- !\n implicit none\n real(kind=8) :: inv(3,3)\n real(kind=8), intent(in) :: a(3,3)\n real(kind=8) :: deta\n real(kind=8) :: cof(3,3)\n deta = det(a)\n if (abs(deta) .le. epsilon(deta)) then\n inv = 0.e+00_8\n stop \"non-invertible matrix sent to inv\"\n end if\n cof(1,1) = +(a(2,2)*a(3,3)-a(2,3)*a(3,2))\n cof(1,2) = -(a(2,1)*a(3,3)-a(2,3)*a(3,1))\n cof(1,3) = +(a(2,1)*a(3,2)-a(2,2)*a(3,1))\n cof(2,1) = -(a(1,2)*a(3,3)-a(1,3)*a(3,2))\n cof(2,2) = +(a(1,1)*a(3,3)-a(1,3)*a(3,1))\n cof(2,3) = -(a(1,1)*a(3,2)-a(1,2)*a(3,1))\n cof(3,1) = +(a(1,2)*a(2,3)-a(1,3)*a(2,2))\n cof(3,2) = -(a(1,1)*a(2,3)-a(1,3)*a(2,1))\n cof(3,3) = +(a(1,1)*a(2,2)-a(1,2)*a(2,1))\n inv = transpose(cof) / deta\n return\nend function inv\n\nsubroutine polar_decomp(F, R, U, ierr)\n implicit none\n real(kind=8), intent(in) :: F(3,3)\n real(kind=8), intent(out) :: R(3,3), U(3,3)\n integer, intent(out) :: ierr\n real(kind=8) :: I(3,3)\n integer :: j\n I = eye(3)\n R = F\n ierr = 0\n do j = 1, 20\n R = .5 * matmul(R, 3. * I - matmul(transpose(R), R))\n if (maxval(abs(matmul(transpose(R), R) - I)) < 1.e-6_8) then\n U = matmul(transpose(R), F)\n return\n end if\n end do\n ierr = 1\nend subroutine polar_decomp\nend module linalg\n", "meta": {"hexsha": "fe0c980d0790a7d82c682bae36d70a8b38ff50bb", "size": 6618, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "matmodlab2/ext_helpers/matrix_funcs.f90", "max_stars_repo_name": "matmodlab/matmodlab2", "max_stars_repo_head_hexsha": "97bb858e2b625cca5f3291db5d50bdbb6352e976", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2017-02-14T02:04:56.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-03T04:53:32.000Z", "max_issues_repo_path": "matmodlab2/ext_helpers/matrix_funcs.f90", "max_issues_repo_name": "tjfulle/matmodlab2", "max_issues_repo_head_hexsha": "97bb858e2b625cca5f3291db5d50bdbb6352e976", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 10, "max_issues_repo_issues_event_min_datetime": "2017-01-21T00:00:06.000Z", "max_issues_repo_issues_event_max_datetime": "2017-01-22T07:39:44.000Z", "max_forks_repo_path": "matmodlab2/ext_helpers/matrix_funcs.f90", "max_forks_repo_name": "tjfulle/matmodlab2", "max_forks_repo_head_hexsha": "97bb858e2b625cca5f3291db5d50bdbb6352e976", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-10-20T22:53:59.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-13T07:17:24.000Z", "avg_line_length": 29.8108108108, "max_line_length": 80, "alphanum_fraction": 0.4200664853, "num_tokens": 2482, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505453836383, "lm_q2_score": 0.760650658103136, "lm_q1q2_score": 0.6881230326994254}} {"text": " SUBROUTINE NODAG(N, SIGMA, A, LAMBD, EPS, ALPHA, MAXITR)\nc NODAG routine (version 0.0.3) \nc gherardo varando (2020) \nc\nc Find a sparse parametrization of the inverse covariance\nc matrix as A A**t using a proximal gradient algorithm \nc for the problem\nc minimize -2log(det(A)) + trace(A^t Sigma A) + LAMBD * ||A||_1 \nc A invertible\nc\nc integer variables \n INTEGER N,MAXITR\nc double precision variables\n DOUBLE PRECISION SIGMA(N,N),A(N,N),LAMBD,EPS,ALPHA \nccccc comment block f2py \ncf2py intent(in) n\ncf2py intent(in) sigma\ncf2py intent(out) a \ncf2py double precision intent(in) lambd\ncf2py double precision intent(in,out) :: eps = 0.0001\ncf2py double precision intent(in,out) :: alpha = 0.5\ncf2py integer intent(in,out) :: maxitr = 100 \nccccc end comment block f2py\nc on entry\nc N integer\nc size of the problem \nc SIGMA double precision (N,N)\nc empirical covariance matrix \nc A double precision (N,N) \nc LAMBD double precision \nc penalization coefficient \nc EPS double precision \nc tollerance for termination\nc ALPHA double precision \nc coefficient for line search \nc MAXITR integer\nc maximum number of iterations \nc on exit\nc A results of the optimization \nc EPS last difference in objective function \nc ALPHA minus log-likelhood on exit\nc MAXITR number of iterations \nc \nc \nc external subroutine from LAPACK \n EXTERNAL DGETRI, DGETRF, DSYMM\nc intrinsic functions\n INTRINSIC ABS, LOG, SIGN\nc internal variables\n INTEGER I,J,ITR, IPIV(N),INFO\n DOUBLE PRECISION F,FNW,TMP(N,N),GRD(N,N), D(N,N),\n * ONE, ZERO, STEP, G, GNW, AOLD(N,N), DIFF\n PARAMETER ( ONE = 1.0E+0 )\n PARAMETER ( ZERO = 0.0E+0 )\n ITR = 0\n F = 0.0E+0\nc initialize penalty for A = identity \n G = LAMBD * N\nc initialize matrices and F = trace(SIGMA) \n DO 20 J = 1,N \n DO 10 I = 1,N\n A(I,J) = 0.0E+0\n TMP(I,J) = 0.0E+0\n D(I,J) = SIGMA(I,J)\n 10 CONTINUE \n A(J,J) = 1.0E+0\n TMP(J,J) = 1.0E+0\n IPIV(J) = J\n F = F + SIGMA(J,J)\n 20 CONTINUE \nc compute initial objective function in A = identity\nc compute TMP = PLU \nc main loop here, increase iteration counter\n 500 CONTINUE \n ITR = ITR + 1\nc compute TMP = TMP**-1\n CALL DGETRI(N, TMP, N, IPIV, AOLD, N**2, INFO)\nc compute GRD = 2*(D - TMP**t)\nc and copy A before starting line search \n DO 40 J=1,N\n DO 30 I=1,N\n GRD(I,J) = 2*(D(I,J) - TMP(J,I))\n AOLD(I,J) = A(I,J)\n 30 CONTINUE \n 40 CONTINUE\n STEP = 1\nc line search loop\n 600 CONTINUE \nc gradient step\nc and soft thresholding\n DO 110 J =1,N\n DO 100 I=1,N\n A(I,J) = AOLD(I,J) - STEP * GRD(I,J) \n A(I,J) = SIGN(ONE,A(I,J))*(ABS(A(I,J))-STEP*LAMBD) \n IF (ABS(A(I,J)) .LE. STEP*LAMBD) THEN\n A(I,J) = 0.0E+0\n ENDIF\n TMP(I,J) = A(I,J)\n 100 CONTINUE\n 110 CONTINUE\nc compute TMP = PLU \n CALL DGETRF(N, N, TMP, N, IPIV,INFO) \n IF (INFO .GT. 0) THEN\n STEP = ALPHA * STEP\n GOTO 600\n ENDIF\nc compute D = SIGMA * A\n CALL DSYMM(\"L\",\"U\", N, N, ONE, SIGMA, N, A, N, ZERO, D, N) \nc compute FNW, GNW in new A\n FNW = 0.0E+0\n GNW = 0.0E+0\n DIFF = 0.0E+0\nc compute F = -2*LOG(DET(A)) + trace(A**t SIGMA A) \nc and G = ||A||_1\n DO 150 J=1,N\n FNW = FNW - 2 * LOG(ABS(TMP(J,J))) \n DO 140 I=1,N\n DIFF = DIFF + ((A(I,J) - AOLD(I,J))**2)/(2*STEP) + \n * (A(I,J) - AOLD(I,J)) * GRD(I,J) \n FNW = FNW + A(I,J)*D(I,J)\n GNW = GNW + LAMBD * ABS(A(I,J))\n 140 CONTINUE\n 150 CONTINUE\nc line search condition \n IF (FNW .GT. F + DIFF .OR. FNW + GNW .GT. F + G ) THEN\n STEP = STEP * ALPHA\n GOTO 600\n ENDIF\nc check stopping criteria\n IF (((F+G-FNW-GNW).LE.EPS).OR.(ITR.GE.MAXITR))THEN\nc terminate and save additional outputs\n ALPHA = FNW \n EPS = F + G - FNW - GNW \n MAXITR = ITR\n GOTO 900 \n ENDIF \nc update value of objective function and repeat\n F = FNW\n G = GNW\n GOTO 500\n 900 CONTINUE\n RETURN\nc last line of NODAG\n END\n", "meta": {"hexsha": "927866324cbf464f970335b71eba6aa3d49f4c7f", "size": 4590, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "nodag.f", "max_stars_repo_name": "gherardovarando/nodag", "max_stars_repo_head_hexsha": "d7c1272da4b1d3a41e3d28dd529bdd1508aa2be7", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-10-07T20:35:20.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-23T03:11:58.000Z", "max_issues_repo_path": "nodag.f", "max_issues_repo_name": "gherardovarando/nodag", "max_issues_repo_head_hexsha": "d7c1272da4b1d3a41e3d28dd529bdd1508aa2be7", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-01-26T14:27:03.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-26T14:27:03.000Z", "max_forks_repo_path": "nodag.f", "max_forks_repo_name": "gherardovarando/nodag", "max_forks_repo_head_hexsha": "d7c1272da4b1d3a41e3d28dd529bdd1508aa2be7", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-05-29T12:41:31.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-29T12:41:31.000Z", "avg_line_length": 31.6551724138, "max_line_length": 71, "alphanum_fraction": 0.5355119826, "num_tokens": 1542, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.904650527388829, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.6881230190116617}} {"text": "program main\r\n\timplicit none\r\n\treal,external :: freeFall\r\n open(unit=1, file='out.txt')\r\n\twrite (1, \"('There are some ball''s velocity when they free fall to ground.')\")\r\n\twrite (1, \"('high velocity')\")\r\n\twrite (1, \"('1 ', F0.6)\") freeFall(1.0)\r\n\twrite (1, \"('10 ', F0.6)\") freeFall(10.0)\r\n\twrite (1, \"('100 ', F0.6)\") freeFall(100.0)\r\n\tclose(11)\r\n\tstop\r\nend program main\r\n\r\nfunction freeFall(high)\r\n\timplicit none\r\n\treal,parameter :: g = 9.80665\r\n real :: high\r\n\treal :: freeFall\r\n\tfreeFall = (2 * g * high) ** 0.5\r\n\treturn\r\nend function\r\n", "meta": {"hexsha": "305d064e9dfa5513b35035d1881ddeb548537a19", "size": 564, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "homework/chapter4/4_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/chapter4/4_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/chapter4/4_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": 25.6363636364, "max_line_length": 81, "alphanum_fraction": 0.5868794326, "num_tokens": 177, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595163, "lm_q2_score": 0.7606506526772883, "lm_q1q2_score": 0.6881230160585609}} {"text": "! This routine performs a cubic interpolation of the curve that\n! passes through x,y to xx,yy\n!\nSubroutine Cubic_interp(nn, x, y, xx, yy)\n Implicit None\n Integer :: nn, i\n Real, dimension (4) :: x, y\n Real, dimension (nn) :: xx, yy\n Real :: den, a, b, c, d, x1, x2, x3, x4, y1, y2, y3, y4\n!\n x1=x(1)\n x2=x(2)\n x3=x(3)\n x4=x(4)\n y1=y(1)\n y2=y(2)\n y3=y(3)\n y4=y(4)\n den = (x1 - x2)*(x1 - x3)*(x2 - x3)*(x1 - x4)*(x2 - x4)*(x3 - x4)\n a=(x1*x4*(x1-x4)*(y2-y3) + x3*x3*(x4*(y1-y2)+x1*(y2-y4))+x2* &\n (x4*x4*(y1-y3)+x1*x1*(y3-y4)+x3*x3*(y4-y1))+ &\n x3*(x4*x4*(y2-y1)+x1*x1*(y4-y2))+ x2*x2* &\n (x4*(y3-y1)+x3*(y1-y4)+x1*(y4-y3)))/den\n\n b=(-x1*x4*(x1*x1-x4*x4)*(y2-y3)+x3*(x4*x4*x4*(y1-y2)+ &\n x1*x1*x1*(y2-y4))+x2*x2*x2*(x4*(y1-y3)+x1*(y3-y4)+ &\n x3*(y4-y1))+x3*x3*x3*(x4*(y2-y1)+x1*(y4-y2))+ &\n x2*(x4*x4*x4*(y3-y1)+x3*x3*x3*(y1-y1)+x1*x1*x1*(y4-y3)))/den\n\n c=(x1*x1*(x1-x4)*x4*x4*(y2-y3)+x3*x3*x3*(x4*x4*(y1-y2)+x1*x1*(y2-y4))+ &\n x2*x2*(x4*x4*x4*(y1-y3)+x1*x1*x1*(y3-y4)+x3*x3*x3*(y4-y1))+ &\n x3*x3*(x4*x4*x4*(y2-y1)+x1*x1*x1*(y4-y2))+ &\n x2*x2*x2*(x4*x4*(y3-y1)+x3*x3*(y1-y4)+x1*x1*(y4-y3)))/den\n\n d=(x1*(x1-x3)*x3*(x1-x4)*(x3-x4)*x4*y2+x2*x2*x2*(x1*(x1-x4)*x4*y3+ &\n x3*x3*(x1*y4-x4*y1)+x3*(x4*x4*y1-x1*x1*y4))+ &\n x2*(x1*x1*(x1-x4)*x4*x4*y3+x3*x3*x3*(x1*x1*y4-x4*x4*y1)+ &\n x3*x3*(x4*x4*x4*y1-x1*x1*x1*y4))+ &\n x2*x2*(x1*x4*(x4*x4-x1*x1)*y3+x3*x3*x3*(x4*y1-x1*y4)+ &\n x3*(x1*x1*x1*y4-x4*x4*x4*y1)))/den\n\n yy = a*(xx**3) + b*(xx**2) + c*xx + d\n\n Return\nEnd Subroutine Cubic_interp\n", "meta": {"hexsha": "f6b319d8b25e26a4f59a5809bafc6155adf56101", "size": 1583, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "inversor/database/NICOLE/misc/cubic_interp.f90", "max_stars_repo_name": "aasensio/DeepLearning", "max_stars_repo_head_hexsha": "71838115ce93e0ca96c8314cff3f07de1d64c235", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "inversor/database/NICOLE/misc/cubic_interp.f90", "max_issues_repo_name": "aasensio/DeepLearning", "max_issues_repo_head_hexsha": "71838115ce93e0ca96c8314cff3f07de1d64c235", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "inversor/database/NICOLE/misc/cubic_interp.f90", "max_forks_repo_name": "aasensio/DeepLearning", "max_forks_repo_head_hexsha": "71838115ce93e0ca96c8314cff3f07de1d64c235", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.4130434783, "max_line_length": 74, "alphanum_fraction": 0.5085281112, "num_tokens": 902, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308128813471, "lm_q2_score": 0.7371581568543044, "lm_q1q2_score": 0.688086137574629}} {"text": "submodule(euler_interface_m) euler_prob_0023_m\n implicit none\n\ncontains\n\n module character(len=20) function euler0023()\n write (euler0023, \"(i20)\") ans()\n end function euler0023\n\n function ans() result(ret)\n integer, allocatable :: abundant(:)\n integer, parameter :: min_ = 12, max_ = 28123\n logical, allocatable :: cannot_be_written(:)\n integer :: i, j, ret\n\n gen_abundant_arr: do i = min_, max_\n if (is_abundant(i)) call append(abundant, i)\n end do gen_abundant_arr\n\n allocate (cannot_be_written(max_))\n cannot_be_written = .true.\n do i = 1, size(abundant)\n do j = i, size(abundant)\n associate (x => abundant(i) + abundant(j))\n if (x <= max_) cannot_be_written(x) = .false.\n end associate\n end do\n end do\n ret = sum(pack([(i, i=1, max_)], cannot_be_written))\n end function ans\n\n function is_abundant(val) result(ret)\n integer, intent(in) :: val\n logical :: ret\n\n ret = .false.\n if (sum_of_proper_divisors(val) > val) ret = .true.\n end function is_abundant\n\n function sum_of_proper_divisors(val) result(ret)\n integer, intent(in) :: val\n integer :: ret, i\n\n ret = 1\n do i = 2, int(sqrt(real(val)))\n if (mod(val, i) == 0) then\n if (val/i == i) then\n ret = ret + i\n else\n ret = ret + i + val/i\n end if\n end if\n end do\n end function sum_of_proper_divisors\n\nend submodule euler_prob_0023_m\n", "meta": {"hexsha": "6d98c35bb540a46595da17c067627b61309da42a", "size": 1647, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/euler/prob_0023_m.f90", "max_stars_repo_name": "han190/PE-Fortran", "max_stars_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-02-09T07:07:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-31T07:45:48.000Z", "max_issues_repo_path": "docs/src/prob_0023_m.f90", "max_issues_repo_name": "han190/PE-Fortran", "max_issues_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-14T00:48:58.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-14T00:48:58.000Z", "max_forks_repo_path": "docs/src/prob_0023_m.f90", "max_forks_repo_name": "han190/PE-Fortran", "max_forks_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-04T21:29:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T21:29:45.000Z", "avg_line_length": 28.8947368421, "max_line_length": 65, "alphanum_fraction": 0.5452337583, "num_tokens": 431, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146780175245, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6880752027922256}} {"text": " program prog\n parameter(val=1.2**3.4)\n write(6, '(f5.3)') val\n x = 1.2 + 3.4**5.6 / 7.8\n write(6, '(f5.1)') x\n x = (1.2 + 3.4)**5.6 / 7.8\n write(6, '(f5.1)') x\n x = (1.2 + 3.4)**(5.6 / 7.8)\n write(6, '(f5.3)') x\n x = -1.3**2\n write(6, '(f5.2)') x\n x = (-1.3)**2\n write(6, '(f4.2)') x\n x = (-1.4)**1\n write(6, '(f5.2)') x\n x = (-1.5)**3\n write(6, '(f5.2)') x\n x = (-1.6)**4\n write(6, '(f4.2)') x\n end\n", "meta": {"hexsha": "eb21d71b20c56a048db8062ff703d3ceecf3e917", "size": 501, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "fable/test/valid/power.f", "max_stars_repo_name": "rimmartin/cctbx_project", "max_stars_repo_head_hexsha": "644090f9432d9afc22cfb542fc3ab78ca8e15e5d", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 155, "max_stars_repo_stars_event_min_datetime": "2016-11-23T12:52:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T15:35:44.000Z", "max_issues_repo_path": "fable/test/valid/power.f", "max_issues_repo_name": "rimmartin/cctbx_project", "max_issues_repo_head_hexsha": "644090f9432d9afc22cfb542fc3ab78ca8e15e5d", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": 590, "max_issues_repo_issues_event_min_datetime": "2016-12-10T11:31:18.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T23:10:09.000Z", "max_forks_repo_path": "fable/test/valid/power.f", "max_forks_repo_name": "rimmartin/cctbx_project", "max_forks_repo_head_hexsha": "644090f9432d9afc22cfb542fc3ab78ca8e15e5d", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": 115, "max_forks_repo_forks_event_min_datetime": "2016-11-15T08:17:28.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-09T15:30:14.000Z", "avg_line_length": 23.8571428571, "max_line_length": 34, "alphanum_fraction": 0.3373253493, "num_tokens": 262, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107966642556, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.688024746652907}} {"text": " SUBROUTINE AB13DD( DICO, JOBE, EQUIL, JOBD, N, M, P, FPEAK,\n $ A, LDA, E, LDE, B, LDB, C, LDC, D, LDD, GPEAK,\n $ TOL, IWORK, DWORK, LDWORK, CWORK, LCWORK,\n $ INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute the L-infinity norm of a continuous-time or\nC discrete-time system, either standard or in the descriptor form,\nC\nC -1\nC G(lambda) = C*( lambda*E - A ) *B + D .\nC\nC The norm is finite if and only if the matrix pair (A,E) has no\nC eigenvalue on the boundary of the stability domain, i.e., the\nC imaginary axis, or the unit circle, respectively. It is assumed\nC that the matrix E is nonsingular.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC DICO CHARACTER*1\nC Specifies the type of the system, as follows:\nC = 'C': continuous-time system;\nC = 'D': discrete-time system.\nC\nC JOBE CHARACTER*1\nC Specifies whether E is a general square or an identity\nC matrix, as follows:\nC = 'G': E is a general square matrix;\nC = 'I': E is the identity matrix.\nC\nC EQUIL CHARACTER*1\nC Specifies whether the user wishes to preliminarily\nC equilibrate the system (A,E,B,C) or (A,B,C), as follows:\nC = 'S': perform equilibration (scaling);\nC = 'N': do not perform equilibration.\nC\nC JOBD CHARACTER*1\nC Specifies whether or not a non-zero matrix D appears in\nC the given state space model:\nC = 'D': D is present;\nC = 'Z': D is assumed a zero matrix.\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The order of the system. N >= 0.\nC\nC M (input) INTEGER\nC The column size of the matrix B. M >= 0.\nC\nC P (input) INTEGER\nC The row size of the matrix C. P >= 0.\nC\nC FPEAK (input/output) DOUBLE PRECISION array, dimension (2)\nC On entry, this parameter must contain an estimate of the\nC frequency where the gain of the frequency response would\nC achieve its peak value. Setting FPEAK(2) = 0 indicates an\nC infinite frequency. An accurate estimate could reduce the\nC number of iterations of the iterative algorithm. If no\nC estimate is available, set FPEAK(1) = 0, and FPEAK(2) = 1.\nC FPEAK(1) >= 0, FPEAK(2) >= 0.\nC On exit, if INFO = 0, this array contains the frequency\nC OMEGA, where the gain of the frequency response achieves\nC its peak value GPEAK, i.e.,\nC\nC || G ( j*OMEGA ) || = GPEAK , if DICO = 'C', or\nC\nC j*OMEGA\nC || G ( e ) || = GPEAK , if DICO = 'D',\nC\nC where OMEGA = FPEAK(1), if FPEAK(2) > 0, and OMEGA is\nC infinite, if FPEAK(2) = 0.\nC\nC A (input) DOUBLE PRECISION array, dimension (LDA,N)\nC The leading N-by-N part of this array must contain the\nC state dynamics matrix A.\nC\nC LDA INTEGER\nC The leading dimension of the array A. LDA >= max(1,N).\nC\nC E (input) DOUBLE PRECISION array, dimension (LDE,N)\nC If JOBE = 'G', the leading N-by-N part of this array must\nC contain the descriptor matrix E of the system.\nC If JOBE = 'I', then E is assumed to be the identity\nC matrix and is not referenced.\nC\nC LDE INTEGER\nC The leading dimension of the array E.\nC LDE >= MAX(1,N), if JOBE = 'G';\nC LDE >= 1, if JOBE = 'I'.\nC\nC B (input) DOUBLE PRECISION array, dimension (LDB,M)\nC The leading N-by-M part of this array must contain the\nC system input matrix B.\nC\nC LDB INTEGER\nC The leading dimension of the array B. LDB >= max(1,N).\nC\nC C (input) DOUBLE PRECISION array, dimension (LDC,N)\nC The leading P-by-N part of this array must contain the\nC system output matrix C.\nC\nC LDC INTEGER\nC The leading dimension of the array C. LDC >= max(1,P).\nC\nC D (input) DOUBLE PRECISION array, dimension (LDD,M)\nC If JOBD = 'D', the leading P-by-M part of this array must\nC contain the direct transmission matrix D.\nC The array D is not referenced if JOBD = 'Z'.\nC\nC LDD INTEGER\nC The leading dimension of array D.\nC LDD >= MAX(1,P), if JOBD = 'D';\nC LDD >= 1, if JOBD = 'Z'.\nC\nC GPEAK (output) DOUBLE PRECISION array, dimension (2)\nC The L-infinity norm of the system, i.e., the peak gain\nC of the frequency response (as measured by the largest\nC singular value in the MIMO case), coded in the same way\nC as FPEAK.\nC\nC Tolerances\nC\nC TOL DOUBLE PRECISION\nC Tolerance used to set the accuracy in determining the\nC norm. 0 <= TOL < 1.\nC\nC Workspace\nC\nC IWORK INTEGER array, dimension (N)\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0, DWORK(1) contains the optimal value\nC of LDWORK.\nC\nC LDWORK INTEGER\nC The dimension of the array DWORK.\nC LDWORK >= K, where K can be computed using the following\nC pseudo-code (or the Fortran code included in the routine)\nC\nC d = 6*MIN(P,M);\nC c = MAX( 4*MIN(P,M) + MAX(P,M), d );\nC if ( MIN(P,M) = 0 ) then\nC K = 1;\nC else if( N = 0 or B = 0 or C = 0 ) then\nC if( JOBD = 'D' ) then\nC K = P*M + c;\nC else\nC K = 1;\nC end\nC else\nC if ( DICO = 'D' ) then\nC b = 0; e = d;\nC else\nC b = N*(N+M); e = c;\nC if ( JOBD = Z' ) then b = b + P*M; end\nC end\nC if ( JOBD = 'D' ) then\nC r = P*M;\nC if ( JOBE = 'I', DICO = 'C',\nC N > 0, B <> 0, C <> 0 ) then\nC K = P*P + M*M;\nC r = r + N*(P+M);\nC else\nC K = 0;\nC end\nC K = K + r + c; r = r + MIN(P,M);\nC else\nC r = 0; K = 0;\nC end\nC r = r + N*(N+P+M);\nC if ( JOBE = 'G' ) then\nC r = r + N*N;\nC if ( EQUIL = 'S' ) then\nC K = MAX( K, r + 9*N );\nC end\nC K = MAX( K, r + 4*N + MAX( M, 2*N*N, N+b+e ) );\nC else\nC K = MAX( K, r + N +\nC MAX( M, P, N*N+2*N, 3*N+b+e ) );\nC end\nC w = 0;\nC if ( JOBE = 'I', DICO = 'C' ) then\nC w = r + 4*N*N + 11*N;\nC if ( JOBD = 'D' ) then\nC w = w + MAX(M,P) + N*(P+M);\nC end\nC end\nC if ( JOBE = 'E' or DICO = 'D' or JOBD = 'D' ) then\nC w = MAX( w, r + 6*N + (2*N+P+M)*(2*N+P+M) +\nC MAX( 2*(N+P+M), 8*N*N + 16*N ) );\nC end\nC K = MAX( 1, K, w, r + 2*N + e );\nC end\nC\nC For good performance, LDWORK must generally be larger.\nC\nC An easily computable upper bound is\nC\nC K = MAX( 1, 15*N*N + P*P + M*M + (6*N+3)*(P+M) + 4*P*M +\nC N*M + 22*N + 7*MIN(P,M) ).\nC\nC The smallest workspace is obtained for DICO = 'C',\nC JOBE = 'I', and JOBD = 'Z', namely\nC\nC K = MAX( 1, N*N + N*P + N*M + N +\nC MAX( N*N + N*M + P*M + 3*N + c,\nC 4*N*N + 10*N ) ).\nC\nC for which an upper bound is\nC\nC K = MAX( 1, 6*N*N + N*P + 2*N*M + P*M + 11*N + MAX(P,M) +\nC 6*MIN(P,M) ).\nC\nC CWORK COMPLEX*16 array, dimension (LCWORK)\nC On exit, if INFO = 0, CWORK(1) contains the optimal\nC LCWORK.\nC\nC LCWORK INTEGER\nC The dimension of the array CWORK.\nC LCWORK >= 1, if N = 0, or B = 0, or C = 0;\nC LCWORK >= MAX(1, (N+M)*(N+P) + 2*MIN(P,M) + MAX(P,M)),\nC otherwise.\nC For good performance, LCWORK must generally be larger.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value;\nC = 1: the matrix E is (numerically) singular;\nC = 2: the (periodic) QR (or QZ) algorithm for computing\nC eigenvalues did not converge;\nC = 3: the SVD algorithm for computing singular values did\nC not converge;\nC = 4: the tolerance is too small and the algorithm did\nC not converge.\nC\nC METHOD\nC\nC The routine implements the method presented in [1], with\nC extensions and refinements for improving numerical robustness and\nC efficiency. Structure-exploiting eigenvalue computations for\nC Hamiltonian matrices are used if JOBE = 'I', DICO = 'C', and the\nC symmetric matrices to be implicitly inverted are not too ill-\nC conditioned. Otherwise, generalized eigenvalue computations are\nC used in the iterative algorithm of [1].\nC\nC REFERENCES\nC\nC [1] Bruinsma, N.A. and Steinbuch, M.\nC A fast algorithm to compute the Hinfinity-norm of a transfer\nC function matrix.\nC Systems & Control Letters, vol. 14, pp. 287-293, 1990.\nC\nC NUMERICAL ASPECTS\nC\nC If the algorithm does not converge in MAXIT = 30 iterations\nC (INFO = 4), the tolerance must be increased.\nC\nC FURTHER COMMENTS\nC\nC If the matrix E is singular, other SLICOT Library routines\nC could be used before calling AB13DD, for removing the singular\nC part of the system.\nC\nC CONTRIBUTORS\nC\nC D. Sima, University of Bucharest, May 2001.\nC V. Sima, Research Institute for Informatics, Bucharest, May 2001.\nC Partly based on SLICOT Library routine AB13CD by P.Hr. Petkov,\nC D.W. Gu and M.M. Konstantinov.\nC\nC REVISIONS\nC\nC V. Sima, Research Institute for Informatics, Bucharest, June 2001,\nC May 2003, Aug. 2005, March 2008, May 2009, Sep. 2009.\nC\nC KEYWORDS\nC\nC H-infinity optimal control, robust control, system norm.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n INTEGER MAXIT\n PARAMETER ( MAXIT = 30 )\n DOUBLE PRECISION ZERO, ONE, TWO, FOUR, P25\n PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0, TWO = 2.0D+0,\n $ FOUR = 4.0D+0, P25 = 0.25D+0 )\n DOUBLE PRECISION TEN, HUNDRD, THOUSD\n PARAMETER ( TEN = 1.0D+1, HUNDRD = 1.0D+2,\n $ THOUSD = 1.0D+3 )\nC ..\nC .. Scalar Arguments ..\n CHARACTER DICO, EQUIL, JOBD, JOBE\n INTEGER INFO, LCWORK, LDA, LDB, LDC, LDD, LDE, LDWORK,\n $ M, N, P\n DOUBLE PRECISION TOL\nC ..\nC .. Array Arguments ..\n COMPLEX*16 CWORK( * )\n DOUBLE PRECISION A( LDA, * ), B( LDB, * ), C( LDC, * ),\n $ D( LDD, * ), DWORK( * ), E( LDE, * ),\n $ FPEAK( 2 ), GPEAK( 2 )\n INTEGER IWORK( * )\nC ..\nC .. Local Scalars ..\n CHARACTER VECT\n LOGICAL DISCR, FULLE, ILASCL, ILESCL, LEQUIL, NODYN,\n $ USEPEN, WITHD\n INTEGER I, IA, IAR, IAS, IB, IBS, IBT, IBV, IC, ICU,\n $ ID, IE, IERR, IES, IH, IH12, IHI, II, ILO, IM,\n $ IMIN, IPA, IPE, IR, IS, ISB, ISC, ISL, ITAU,\n $ ITER, IU, IV, IWRK, J, K, LW, MAXCWK, MAXWRK,\n $ MINCWR, MINPM, MINWRK, N2, N2PM, NEI, NN, NWS,\n $ NY, PM\n DOUBLE PRECISION ANRM, ANRMTO, BIGNUM, BNORM, BOUND, CNORM,\n $ ENRM, ENRMTO, EPS, FPEAKI, FPEAKS, GAMMA,\n $ GAMMAL, GAMMAS, MAXRED, OMEGA, PI, RAT, RCOND,\n $ RTOL, SAFMAX, SAFMIN, SMLNUM, TM, TOLER, WMAX,\n $ WRMIN\nC ..\nC .. Local Arrays ..\n DOUBLE PRECISION TEMP( 1 )\nC ..\nC .. External Functions ..\n DOUBLE PRECISION AB13DX, DLAMCH, DLANGE, DLAPY2\n LOGICAL LSAME\n EXTERNAL AB13DX, DLAMCH, DLANGE, DLAPY2, LSAME\nC ..\nC .. External Subroutines ..\n EXTERNAL DCOPY, DGEBAL, DGEHRD, DGEMM, DGEQRF, DGESVD,\n $ DGGBAL, DGGEV, DHGEQZ, DHSEQR, DLABAD, DLACPY,\n $ DLASCL, DLASRT, DORGQR, DORMHR, DSWAP, DSYRK,\n $ DTRCON, MA02AD, MB01SD, MB03XD, TB01ID, TG01AD,\n $ TG01BD, XERBLA\nC ..\nC .. Intrinsic Functions ..\n INTRINSIC ABS, ATAN, ATAN2, COS, DBLE, INT, LOG, MAX,\n $ MIN, SIN, SQRT\nC ..\nC .. Executable Statements ..\nC\nC Test the input scalar parameters.\nC\n N2 = 2*N\n NN = N*N\n PM = P + M\n N2PM = N2 + PM\n MINPM = MIN( P, M )\n INFO = 0\n DISCR = LSAME( DICO, 'D' )\n FULLE = LSAME( JOBE, 'G' )\n LEQUIL = LSAME( EQUIL, 'S' )\n WITHD = LSAME( JOBD, 'D' )\nC\n IF( .NOT. ( DISCR .OR. LSAME( DICO, 'C' ) ) ) THEN\n INFO = -1\n ELSE IF( .NOT. ( FULLE .OR. LSAME( JOBE, 'I' ) ) ) THEN\n INFO = -2\n ELSE IF( .NOT. ( LEQUIL .OR. LSAME( EQUIL, 'N' ) ) ) THEN\n INFO = -3\n ELSE IF( .NOT. ( WITHD .OR. LSAME( JOBD, 'Z' ) ) ) THEN\n INFO = -4\n ELSE IF( N.LT.0 ) THEN\n INFO = -5\n ELSE IF( M.LT.0 ) THEN\n INFO = -6\n ELSE IF( P.LT.0 ) THEN\n INFO = -7\n ELSE IF( MIN( FPEAK( 1 ), FPEAK( 2 ) ).LT.ZERO ) THEN\n INFO = -8\n ELSE IF( LDA.LT.MAX( 1, N ) ) THEN\n INFO = -10\n ELSE IF( LDE.LT.1 .OR. ( FULLE .AND. LDE.LT.N ) ) THEN\n INFO = -12\n ELSE IF( LDB.LT.MAX( 1, N ) ) THEN\n INFO = -14\n ELSE IF( LDC.LT.MAX( 1, P ) ) THEN\n INFO = -16\n ELSE IF( LDD.LT.1 .OR. ( WITHD .AND. LDD.LT.P ) ) THEN\n INFO = -18\n ELSE IF( TOL.LT.ZERO .OR. TOL.GE.ONE ) THEN\n INFO = -20\n ELSE\n BNORM = DLANGE( '1-norm', N, M, B, LDB, DWORK )\n CNORM = DLANGE( '1-norm', P, N, C, LDC, DWORK )\n NODYN = N.EQ.0 .OR. MIN( BNORM, CNORM ).EQ.ZERO\n USEPEN = FULLE .OR. DISCR\nC\nC Compute workspace.\nC\n ID = 6*MINPM\n IC = MAX( 4*MINPM + MAX( P, M ), ID )\n IF( MINPM.EQ.0 ) THEN\n MINWRK = 1\n ELSE IF( NODYN ) THEN\n IF( WITHD ) THEN\n MINWRK = P*M + IC\n ELSE\n MINWRK = 1\n END IF\n ELSE\n IF ( DISCR ) THEN\n IB = 0\n IE = ID\n ELSE\n IB = N*( N + M )\n IF ( .NOT.WITHD )\n $ IB = IB + P*M\n IE = IC\n END IF\n IF ( WITHD ) THEN\n IR = P*M\n IF ( .NOT.USEPEN ) THEN\n MINWRK = P*P + M*M\n IR = IR + N*PM\n ELSE\n MINWRK = 0\n END IF\n MINWRK = MINWRK + IR + IC\n IR = IR + MINPM\n ELSE\n IR = 0\n MINWRK = 0\n END IF\n IR = IR + N*( N + PM )\n IF ( FULLE ) THEN\n IR = IR + NN\n IF ( LEQUIL )\n $ MINWRK = MAX( MINWRK, IR + 9*N )\n MINWRK = MAX( MINWRK, IR + 4*N + MAX( M, 2*NN,\n $ N + IB + IE ) )\n ELSE\n MINWRK = MAX( MINWRK, IR + N + MAX( M, P, NN + N2,\n $ 3*N + IB + IE ) )\n END IF\n LW = 0\n IF ( .NOT.USEPEN ) THEN\n LW = IR + 4*NN + 11*N\n IF ( WITHD )\n $ LW = LW + MAX( M, P ) + N*PM\n END IF\n IF ( USEPEN .OR. WITHD )\n $ LW = MAX( LW, IR + 6*N + N2PM*N2PM +\n $ MAX( N2PM + PM, 8*( NN + N2 ) ) )\n MINWRK = MAX( 1, MINWRK, LW, IR + N2 + IE )\n END IF\nC\n IF( LDWORK.LT.MINWRK ) THEN\n INFO = -23\n ELSE\n IF ( NODYN ) THEN\n MINCWR = 1\n ELSE\n MINCWR = MAX( 1, ( N + M )*( N + P ) +\n $ 2*MINPM + MAX( P, M ) )\n END IF\n IF( LCWORK.LT.MINCWR )\n $ INFO = -25\n END IF\n END IF\nC\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'AB13DD', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF( M.EQ.0 .OR. P.EQ.0 ) THEN\n GPEAK( 1 ) = ZERO\n FPEAK( 1 ) = ZERO\n GPEAK( 2 ) = ONE\n FPEAK( 2 ) = ONE\n DWORK( 1 ) = ONE\n CWORK( 1 ) = ONE\n RETURN\n END IF\nC\nC Determine the maximum singular value of G(infinity) = D .\nC If JOBE = 'I' and DICO = 'C', the full SVD of D, D = U*S*V', is\nC computed and saved for later use.\nC\nC (Note: Comments in the code beginning \"Workspace:\" describe the\nC minimal amount of real workspace needed at that point in the\nC code, as well as the preferred amount for good performance.\nC NB refers to the optimal block size for the immediately\nC following subroutine, as returned by ILAENV.)\nC\n ID = 1\n IF ( WITHD ) THEN\n IS = ID + P*M\n IF ( USEPEN .OR. NODYN ) THEN\n IU = IS + MINPM\n IV = IU\n IWRK = IV\n VECT = 'N'\n ELSE\n IBV = IS + MINPM\n ICU = IBV + N*M\n IU = ICU + P*N\n IV = IU + P*P\n IWRK = IV + M*M\n VECT = 'A'\n END IF\nC\nC Workspace: need P*M + MIN(P,M) + V +\nC MAX( 3*MIN(P,M) + MAX(P,M), 5*MIN(P,M) ),\nC where V = N*(M+P) + P*P + M*M,\nC if JOBE = 'I' and DICO = 'C',\nC and N > 0, B <> 0, C <> 0,\nC V = 0, otherwise;\nC prefer larger.\nC\n CALL DLACPY( 'Full', P, M, D, LDD, DWORK( ID ), P )\n CALL DGESVD( VECT, VECT, P, M, DWORK( ID ), P, DWORK( IS ),\n $ DWORK( IU ), P, DWORK( IV ), M, DWORK( IWRK ),\n $ LDWORK-IWRK+1, IERR )\n IF( IERR.GT.0 ) THEN\n INFO = 3\n RETURN\n END IF\n GAMMAL = DWORK( IS )\n MAXWRK = INT( DWORK( IWRK ) ) + IWRK - 1\nC\nC Restore D for later calculations.\nC\n CALL DLACPY( 'Full', P, M, D, LDD, DWORK( ID ), P )\n ELSE\n IWRK = 1\n GAMMAL = ZERO\n MAXWRK = 1\n END IF\nC\nC Quick return if possible.\nC\n IF( NODYN ) THEN\n GPEAK( 1 ) = GAMMAL\n FPEAK( 1 ) = ZERO\n GPEAK( 2 ) = ONE\n FPEAK( 2 ) = ONE\n DWORK( 1 ) = MAXWRK\n CWORK( 1 ) = ONE\n RETURN\n END IF\nC\n IF ( .NOT.USEPEN .AND. WITHD ) THEN\nC\nC Standard continuous-time case, D <> 0: Compute B*V and C'*U .\nC\n CALL DGEMM( 'No Transpose', 'Transpose', N, M, M, ONE, B, LDB,\n $ DWORK( IV ), M, ZERO, DWORK( IBV ), N )\n CALL DGEMM( 'Transpose', 'No Transpose', N, P, P, ONE, C,\n $ LDC, DWORK( IU ), P, ZERO, DWORK( ICU ), N )\nC\nC U and V are no longer needed: free their memory space.\nC Total workspace here: need P*M + MIN(P,M) + N*(M+P)\nC (JOBE = 'I', DICO = 'C', JOBD = 'D').\nC\n IWRK = IU\n END IF\nC\nC Get machine constants.\nC\n EPS = DLAMCH( 'Epsilon' )\n SAFMIN = DLAMCH( 'Safe minimum' )\n SAFMAX = ONE / SAFMIN\n CALL DLABAD( SAFMIN, SAFMAX )\n SMLNUM = SQRT( SAFMIN ) / DLAMCH( 'Precision' )\n BIGNUM = ONE / SMLNUM\n TOLER = SQRT( EPS )\nC\nC Initiate the transformation of the system to an equivalent one,\nC to be used for eigenvalue computations.\nC\nC Additional workspace: need N*N + N*M + P*N + 2*N, if JOBE = 'I';\nC 2*N*N + N*M + P*N + 2*N, if JOBE = 'G'.\nC\n IA = IWRK\n IE = IA + NN\n IF ( FULLE ) THEN\n IB = IE + NN\n ELSE\n IB = IE\n END IF\n IC = IB + N*M\n IR = IC + P*N\n II = IR + N\n IBT = II + N\nC\n CALL DLACPY( 'Full', N, N, A, LDA, DWORK( IA ), N )\n CALL DLACPY( 'Full', N, M, B, LDB, DWORK( IB ), N )\n CALL DLACPY( 'Full', P, N, C, LDC, DWORK( IC ), P )\nC\nC Scale A if maximum element is outside the range [SMLNUM,BIGNUM].\nC\n ANRM = DLANGE( 'Max', N, N, DWORK( IA ), N, DWORK )\n ILASCL = .FALSE.\n IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN\n ANRMTO = SMLNUM\n ILASCL = .TRUE.\n ELSE IF( ANRM.GT.BIGNUM ) THEN\n ANRMTO = BIGNUM\n ILASCL = .TRUE.\n END IF\n IF( ILASCL )\n $ CALL DLASCL( 'General', 0, 0, ANRM, ANRMTO, N, N, DWORK( IA ),\n $ N, IERR )\nC\n IF ( FULLE ) THEN\nC\nC Descriptor system.\nC\nC Additional workspace: need N.\nC\n IWRK = IBT + N\n CALL DLACPY( 'Full', N, N, E, LDE, DWORK( IE ), N )\nC\nC Scale E if maximum element is outside the range\nC [SMLNUM,BIGNUM].\nC\n ENRM = DLANGE( 'Max', N, N, DWORK( IE ), N, DWORK )\n ILESCL = .FALSE.\n IF( ENRM.GT.ZERO .AND. ENRM.LT.SMLNUM ) THEN\n ENRMTO = SMLNUM\n ILESCL = .TRUE.\n ELSE IF( ENRM.GT.BIGNUM ) THEN\n ENRMTO = BIGNUM\n ILESCL = .TRUE.\n ELSE IF( ENRM.EQ.ZERO ) THEN\nC\nC Error return: Matrix E is 0.\nC\n INFO = 1\n RETURN\n END IF\n IF( ILESCL )\n $ CALL DLASCL( 'General', 0, 0, ENRM, ENRMTO, N, N,\n $ DWORK( IE ), N, IERR )\nC\nC Equilibrate the system, if required.\nC\nC Additional workspace: need 6*N.\nC\n IF( LEQUIL )\n $ CALL TG01AD( 'All', N, N, M, P, ZERO, DWORK( IA ), N,\n $ DWORK( IE ), N, DWORK( IB ), N, DWORK( IC ), P,\n $ DWORK( II ), DWORK( IR ), DWORK( IWRK ),\n $ IERR )\nC\nC For efficiency of later calculations, the system (A,E,B,C) is\nC reduced to an equivalent one with the state matrix A in\nC Hessenberg form, and E upper triangular.\nC First, permute (A,E) to make it more nearly triangular.\nC\n CALL DGGBAL( 'Permute', N, DWORK( IA ), N, DWORK( IE ), N, ILO,\n $ IHI, DWORK( II ), DWORK( IR ), DWORK( IWRK ),\n $ IERR )\nC\nC Apply the permutations to (the copies of) B and C.\nC\n DO 10 I = N, IHI + 1, -1\n K = DWORK( II+I-1 )\n IF( K.NE.I )\n $ CALL DSWAP( M, DWORK( IB+I-1 ), N,\n $ DWORK( IB+K-1 ), N )\n K = DWORK( IR+I-1 )\n IF( K.NE.I )\n $ CALL DSWAP( P, DWORK( IC+(I-1)*P ), 1,\n $ DWORK( IC+(K-1)*P ), 1 )\n 10 CONTINUE\nC\n DO 20 I = 1, ILO - 1\n K = DWORK( II+I-1 )\n IF( K.NE.I )\n $ CALL DSWAP( M, DWORK( IB+I-1 ), N,\n $ DWORK( IB+K-1 ), N )\n K = DWORK( IR+I-1 )\n IF( K.NE.I )\n $ CALL DSWAP( P, DWORK( IC+(I-1)*P ), 1,\n $ DWORK( IC+(K-1)*P ), 1 )\n 20 CONTINUE\nC\nC Reduce (A,E) to generalized Hessenberg form and apply the\nC transformations to B and C.\nC Additional workspace: need N + MAX(N,M);\nC prefer N + MAX(N,M)*NB.\nC\n CALL TG01BD( 'General', 'No Q', 'No Z', N, M, P, ILO, IHI,\n $ DWORK( IA ), N, DWORK( IE ), N, DWORK( IB ), N,\n $ DWORK( IC ), P, DWORK, 1, DWORK, 1, DWORK( IWRK ),\n $ LDWORK-IWRK+1, IERR )\n MAXWRK = MAX( INT( DWORK( IWRK ) ) + IWRK - 1, MAXWRK )\nC\nC Check whether matrix E is nonsingular.\nC Additional workspace: need 3*N.\nC\n CALL DTRCON( '1-norm', 'Upper', 'Non Unit', N, DWORK( IE ), N,\n $ RCOND, DWORK( IWRK ), IWORK, IERR )\n IF( RCOND.LE.TEN*DBLE( N )*EPS ) THEN\nC\nC Error return: Matrix E is numerically singular.\nC\n INFO = 1\n RETURN\n END IF\nC\nC Perform QZ algorithm, computing eigenvalues. The generalized\nC Hessenberg form is saved for later use.\nC Additional workspace: need 2*N*N + N;\nC prefer larger.\nC\n IAS = IWRK\n IES = IAS + NN\n IWRK = IES + NN\n CALL DLACPY( 'Full', N, N, DWORK( IA ), N, DWORK( IAS ), N )\n CALL DLACPY( 'Full', N, N, DWORK( IE ), N, DWORK( IES ), N )\n CALL DHGEQZ( 'Eigenvalues', 'No Vectors', 'No Vectors', N, ILO,\n $ IHI, DWORK( IAS ), N, DWORK( IES ), N,\n $ DWORK( IR ), DWORK( II ), DWORK( IBT ), DWORK, N,\n $ DWORK, N, DWORK( IWRK ), LDWORK-IWRK+1, IERR )\n IF( IERR.NE.0 ) THEN\n INFO = 2\n RETURN\n END IF\n MAXWRK = MAX( INT( DWORK( IWRK ) ) + IWRK - 1, MAXWRK )\nC\nC Check if unscaling would cause over/underflow; if so, rescale\nC eigenvalues (DWORK( IR+I-1 ),DWORK( II+I-1 ),DWORK( IBT+I-1 ))\nC so DWORK( IBT+I-1 ) is on the order of E(I,I) and\nC DWORK( IR+I-1 ) and DWORK( II+I-1 ) are on the order of A(I,I).\nC\n IF( ILASCL ) THEN\nC\n DO 30 I = 1, N\n IF( DWORK( II+I-1 ).NE.ZERO ) THEN\n IF( ( DWORK( IR+I-1 ) / SAFMAX ).GT.( ANRMTO / ANRM )\n $ .OR.\n $ ( SAFMIN / DWORK( IR+I-1 ) ).GT.( ANRM / ANRMTO )\n $ ) THEN\n TM = ABS( DWORK( IA+(I-1)*N+I ) / DWORK( IR+I-1 ) )\n DWORK( IBT+I-1 ) = DWORK( IBT+I-1 )*TM\n DWORK( IR+I-1 ) = DWORK( IR+I-1 )*TM\n DWORK( II+I-1 ) = DWORK( II+I-1 )*TM\n ELSE IF( ( DWORK( II+I-1 ) / SAFMAX ).GT.\n $ ( ANRMTO / ANRM ) .OR.\n $ ( SAFMIN / DWORK( II+I-1 ) ).GT.( ANRM / ANRMTO ) )\n $ THEN\n TM = ABS( DWORK( IA+I*N+I ) / DWORK( II+I-1 ) )\n DWORK( IBT+I-1 ) = DWORK( IBT+I-1 )*TM\n DWORK( IR+I-1 ) = DWORK( IR+I-1 )*TM\n DWORK( II+I-1 ) = DWORK( II+I-1 )*TM\n END IF\n END IF\n 30 CONTINUE\nC\n END IF\nC\n IF( ILESCL ) THEN\nC\n DO 40 I = 1, N\n IF( DWORK( II+I-1 ).NE.ZERO ) THEN\n IF( ( DWORK( IBT+I-1 ) / SAFMAX ).GT.( ENRMTO / ENRM )\n $ .OR.\n $ ( SAFMIN / DWORK( IBT+I-1 ) ).GT.( ENRM / ENRMTO )\n $ ) THEN\n TM = ABS( DWORK( IE+(I-1)*N+I ) / DWORK( IBT+I-1 ))\n DWORK( IBT+I-1 ) = DWORK( IBT+I-1 )*TM\n DWORK( IR+I-1 ) = DWORK( IR+I-1 )*TM\n DWORK( II+I-1 ) = DWORK( II+I-1 )*TM\n END IF\n END IF\n 40 CONTINUE\nC\n END IF\nC\nC Undo scaling.\nC\n IF( ILASCL ) THEN\n CALL DLASCL( 'Hessenberg', 0, 0, ANRMTO, ANRM, N, N,\n $ DWORK( IA ), N, IERR )\n CALL DLASCL( 'General', 0, 0, ANRMTO, ANRM, N, 1,\n $ DWORK( IR ), N, IERR )\n CALL DLASCL( 'General', 0, 0, ANRMTO, ANRM, N, 1,\n $ DWORK( II ), N, IERR )\n END IF\nC\n IF( ILESCL ) THEN\n CALL DLASCL( 'Upper', 0, 0, ENRMTO, ENRM, N, N,\n $ DWORK( IE ), N, IERR )\n CALL DLASCL( 'General', 0, 0, ENRMTO, ENRM, N, 1,\n $ DWORK( IBT ), N, IERR )\n END IF\nC\n ELSE\nC\nC Standard state-space system.\nC\n IF( LEQUIL ) THEN\nC\nC Equilibrate the system.\nC\n MAXRED = HUNDRD\n CALL TB01ID( 'All', N, M, P, MAXRED, DWORK( IA ), N,\n $ DWORK( IB ), N, DWORK( IC ), P, DWORK( II ),\n $ IERR )\n END IF\nC\nC For efficiency of later calculations, the system (A,B,C) is\nC reduced to a similar one with the state matrix in Hessenberg\nC form.\nC\nC First, permute the matrix A to make it more nearly triangular\nC and apply the permutations to B and C.\nC\n CALL DGEBAL( 'Permute', N, DWORK( IA ), N, ILO, IHI,\n $ DWORK( IR ), IERR )\nC\n DO 50 I = N, IHI + 1, -1\n K = DWORK( IR+I-1 )\n IF( K.NE.I ) THEN\n CALL DSWAP( M, DWORK( IB+I-1 ), N,\n $ DWORK( IB+K-1 ), N )\n CALL DSWAP( P, DWORK( IC+(I-1)*P ), 1,\n $ DWORK( IC+(K-1)*P ), 1 )\n END IF\n 50 CONTINUE\nC\n DO 60 I = 1, ILO - 1\n K = DWORK( IR+I-1 )\n IF( K.NE.I ) THEN\n CALL DSWAP( M, DWORK( IB+I-1 ), N,\n $ DWORK( IB+K-1 ), N )\n CALL DSWAP( P, DWORK( IC+(I-1)*P ), 1,\n $ DWORK( IC+(K-1)*P ), 1 )\n END IF\n 60 CONTINUE\nC\nC Reduce A to upper Hessenberg form and apply the transformations\nC to B and C.\nC Additional workspace: need N; (from II)\nC prefer N*NB.\nC\n ITAU = IR\n IWRK = ITAU + N\n CALL DGEHRD( N, ILO, IHI, DWORK( IA ), N, DWORK( ITAU ),\n $ DWORK( IWRK ), LDWORK-IWRK+1, IERR )\n MAXWRK = MAX( INT( DWORK( IWRK ) ) + IWRK - 1, MAXWRK )\nC\nC Additional workspace: need M;\nC prefer M*NB.\nC\n CALL DORMHR( 'Left', 'Transpose', N, M, ILO, IHI, DWORK( IA ),\n $ N, DWORK( ITAU ), DWORK( IB ), N, DWORK( IWRK ),\n $ LDWORK-IWRK+1, IERR )\n MAXWRK = MAX( INT( DWORK( IWRK ) ) + IWRK - 1, MAXWRK )\nC\nC Additional workspace: need P;\nC prefer P*NB.\nC\n CALL DORMHR( 'Right', 'NoTranspose', P, N, ILO, IHI,\n $ DWORK( IA ), N, DWORK( ITAU ), DWORK( IC ), P,\n $ DWORK( IWRK ), LDWORK-IWRK+1, IERR )\n MAXWRK = MAX( INT( DWORK( IWRK ) ) + IWRK - 1, MAXWRK )\nC\nC Compute the eigenvalues. The Hessenberg form is saved for\nC later use.\nC Additional workspace: need N*N + N; (from IBT)\nC prefer larger.\nC\n IAS = IBT\n IWRK = IAS + NN\n CALL DLACPY( 'Full', N, N, DWORK( IA ), N, DWORK( IAS ), N )\n CALL DHSEQR( 'Eigenvalues', 'No Vectors', N, ILO, IHI,\n $ DWORK( IAS ), N, DWORK( IR ), DWORK( II ), DWORK,\n $ N, DWORK( IWRK ), LDWORK-IWRK+1, IERR )\n IF( IERR.GT.0 ) THEN\n INFO = 2\n RETURN\n END IF\n MAXWRK = MAX( INT( DWORK( IWRK ) ) + IWRK - 1, MAXWRK )\nC\n IF( ILASCL ) THEN\nC\nC Undo scaling for the Hessenberg form of A and eigenvalues.\nC\n CALL DLASCL( 'Hessenberg', 0, 0, ANRMTO, ANRM, N, N,\n $ DWORK( IA ), N, IERR )\n CALL DLASCL( 'General', 0, 0, ANRMTO, ANRM, N, 1,\n $ DWORK( IR ), N, IERR )\n CALL DLASCL( 'General', 0, 0, ANRMTO, ANRM, N, 1,\n $ DWORK( II ), N, IERR )\n END IF\nC\n END IF\nC\nC Look for (generalized) eigenvalues on the boundary of the\nC stability domain. (Their existence implies an infinite norm.)\nC Additional workspace: need 2*N. (from IAS)\nC\n IM = IAS\n IAR = IM + N\n IMIN = II\n WRMIN = SAFMAX\n BOUND = EPS*THOUSD\nC\n IF ( DISCR ) THEN\n GAMMAL = ZERO\nC\nC For discrete-time case, compute the logarithm of the non-zero\nC eigenvalues and save their moduli and absolute real parts.\nC (The logarithms are overwritten on the eigenvalues.)\nC Also, find the minimum distance to the unit circle.\nC\n IF ( FULLE ) THEN\nC\n DO 70 I = 0, N - 1\n TM = DLAPY2( DWORK( IR+I ), DWORK( II+I ) )\n IF ( ( DWORK( IBT+I ).GE.ONE ) .OR.\n $ ( DWORK( IBT+I ).LT.ONE .AND.\n $ TM.LT.SAFMAX*DWORK( IBT+I ) ) ) THEN\n TM = TM / DWORK( IBT+I )\n ELSE\nC\nC The pencil has too large eigenvalues. SAFMAX is used.\nC\n TM = SAFMAX\n END IF\n IF ( TM.NE.ZERO ) THEN\n DWORK( II+I ) = ATAN2( DWORK( II+I ), DWORK( IR+I ) )\n DWORK( IR+I ) = LOG( TM )\n END IF\n DWORK( IM ) = DLAPY2( DWORK( IR+I ), DWORK( II+I ) )\n TM = ABS( ONE - TM )\n IF( TM.LT.WRMIN ) THEN\n IMIN = II + I\n WRMIN = TM\n END IF\n IM = IM + 1\n DWORK( IAR+I ) = ABS( DWORK( IR+I ) )\n 70 CONTINUE\nC\n ELSE\nC\n DO 80 I = 0, N - 1\n TM = DLAPY2( DWORK( IR+I ), DWORK( II+I ) )\n IF ( TM.NE.ZERO ) THEN\n DWORK( II+I ) = ATAN2( DWORK( II+I ), DWORK( IR+I ) )\n DWORK( IR+I ) = LOG( TM )\n END IF\n DWORK( IM ) = DLAPY2( DWORK( IR+I ), DWORK( II+I ) )\n TM = ABS( ONE - TM )\n IF( TM.LT.WRMIN ) THEN\n IMIN = II + I\n WRMIN = TM\n END IF\n IM = IM + 1\n DWORK( IAR+I ) = ABS( DWORK( IR+I ) )\n 80 CONTINUE\nC\n END IF\nC\n ELSE\nC\nC For continuous-time case, save moduli of eigenvalues and\nC absolute real parts and find the maximum modulus and minimum\nC absolute real part.\nC\n WMAX = ZERO\nC\n IF ( FULLE ) THEN\nC\n DO 90 I = 0, N - 1\n TM = ABS( DWORK( IR+I ) )\n DWORK( IM ) = DLAPY2( DWORK( IR+I ), DWORK( II+I ) )\n IF ( ( DWORK( IBT+I ).GE.ONE ) .OR.\n $ ( DWORK( IBT+I ).LT.ONE .AND.\n $ DWORK( IM ).LT.SAFMAX*DWORK( IBT+I ) ) )\n $ THEN\n TM = TM / DWORK( IBT+I )\n DWORK( IM ) = DWORK( IM ) / DWORK( IBT+I )\n ELSE\n IF ( TM.LT.SAFMAX*DWORK( IBT+I ) ) THEN\n TM = TM / DWORK( IBT+I )\n ELSE\nC\nC The pencil has too large eigenvalues.\nC SAFMAX is used.\nC\n TM = SAFMAX\n END IF\n DWORK( IM ) = SAFMAX\n END IF\n IF( TM.LT.WRMIN ) THEN\n IMIN = II + I\n WRMIN = TM\n END IF\n DWORK( IAR+I ) = TM\n IF( DWORK( IM ).GT.WMAX )\n $ WMAX = DWORK( IM )\n IM = IM + 1\n 90 CONTINUE\nC\n ELSE\nC\n DO 100 I = 0, N - 1\n TM = ABS( DWORK( IR+I ) )\n IF( TM.LT.WRMIN ) THEN\n IMIN = II + I\n WRMIN = TM\n END IF\n DWORK( IM ) = DLAPY2( DWORK( IR+I ), DWORK( II+I ) )\n IF( DWORK( IM ).GT.WMAX )\n $ WMAX = DWORK( IM )\n IM = IM + 1\n DWORK( IAR+I ) = TM\n 100 CONTINUE\nC\n END IF\nC\n BOUND = BOUND + EPS*WMAX\nC\n END IF\nC\n IM = IM - N\nC\n IF( WRMIN.LT.BOUND ) THEN\nC\nC The L-infinity norm was found as infinite.\nC\n GPEAK( 1 ) = ONE\n GPEAK( 2 ) = ZERO\n TM = ABS( DWORK( IMIN ) )\n IF ( DISCR )\n $ TM = ABS( ATAN2( SIN( TM ), COS( TM ) ) )\n FPEAK( 1 ) = TM\n IF ( TM.LT.SAFMAX ) THEN\n FPEAK( 2 ) = ONE\n ELSE\n FPEAK( 2 ) = ZERO\n END IF\nC\n DWORK( 1 ) = MAXWRK\n CWORK( 1 ) = ONE\n RETURN\n END IF\nC\nC Determine the maximum singular value of\nC G(lambda) = C*inv(lambda*E - A)*B + D,\nC over a selected set of frequencies. Besides the frequencies w = 0,\nC w = pi (if DICO = 'D'), and the given value FPEAK, this test set\nC contains the peak frequency for each mode (or an approximation\nC of it). The (generalized) Hessenberg form of the system is used.\nC\nC First, determine the maximum singular value of G(0) and set FPEAK\nC accordingly.\nC Additional workspace:\nC complex: need 1, if DICO = 'C';\nC (N+M)*(N+P)+2*MIN(P,M)+MAX(P,M)), otherwise;\nC prefer larger;\nC real: need LDW0+LDW1+LDW2, where\nC LDW0 = N*N+N*M, if DICO = 'C';\nC LDW0 = 0, if DICO = 'D';\nC LDW1 = P*M, if DICO = 'C', JOBD = 'Z';\nC LDW1 = 0, otherwise;\nC LDW2 = MIN(P,M)+MAX(3*MIN(P,M)+MAX(P,M),\nC 5*MIN(P,M)),\nC if DICO = 'C';\nC LDW2 = 6*MIN(P,M), otherwise.\nC prefer larger.\nC\n IF ( DISCR ) THEN\n IAS = IA\n IBS = IB\n IWRK = IAR + N\n ELSE\n IAS = IAR + N\n IBS = IAS + NN\n IWRK = IBS + N*M\n CALL DLACPY( 'Upper', N, N, DWORK( IA ), N, DWORK( IAS ), N )\n CALL DCOPY( N-1, DWORK( IA+1 ), N+1, DWORK( IAS+1 ), N+1 )\n CALL DLACPY( 'Full', N, M, DWORK( IB ), N, DWORK( IBS ), N )\n END IF\n GAMMA = AB13DX( DICO, JOBE, JOBD, N, M, P, ZERO, DWORK( IAS ), N,\n $ DWORK( IE ), N, DWORK( IBS ), N, DWORK( IC ), P,\n $ DWORK( ID ), P, IWORK, DWORK( IWRK ),\n $ LDWORK-IWRK+1, CWORK, LCWORK, IERR )\n MAXWRK = MAX( INT( DWORK( IWRK ) ) + IWRK - 1, MAXWRK )\n IF( IERR.GE.1 .AND. IERR.LE.N ) THEN\n GPEAK( 1 ) = ONE\n FPEAK( 1 ) = ZERO\n GPEAK( 2 ) = ZERO\n FPEAK( 2 ) = ONE\n GO TO 340\n ELSE IF( IERR.EQ.N+1 ) THEN\n INFO = 3\n RETURN\n END IF\nC\n FPEAKS = FPEAK( 1 )\n FPEAKI = FPEAK( 2 )\n IF( GAMMAL.LT.GAMMA ) THEN\n GAMMAL = GAMMA\n FPEAK( 1 ) = ZERO\n FPEAK( 2 ) = ONE\n ELSE IF( .NOT.DISCR ) THEN\n FPEAK( 1 ) = ONE\n FPEAK( 2 ) = ZERO\n END IF\nC\n MAXCWK = INT( CWORK( 1 ) )\nC\n IF( DISCR ) THEN\nC\nC Try the frequency w = pi.\nC\n PI = FOUR*ATAN( ONE )\n GAMMA = AB13DX( DICO, JOBE, JOBD, N, M, P, PI, DWORK( IA ),\n $ N, DWORK( IE ), N, DWORK( IB ), N, DWORK( IC ),\n $ P, DWORK( ID ), P, IWORK, DWORK( IWRK ),\n $ LDWORK-IWRK+1, CWORK, LCWORK, IERR )\n MAXCWK = MAX( INT( CWORK( 1 ) ), MAXCWK )\n MAXWRK = MAX( INT( DWORK( IWRK ) ) + IWRK - 1, MAXWRK )\n IF( IERR.GE.1 .AND. IERR.LE.N ) THEN\n GPEAK( 1 ) = ONE\n FPEAK( 1 ) = PI\n GPEAK( 2 ) = ZERO\n FPEAK( 2 ) = ONE\n GO TO 340\n ELSE IF( IERR.EQ.N+1 ) THEN\n INFO = 3\n RETURN\n END IF\nC\n IF( GAMMAL.LT.GAMMA ) THEN\n GAMMAL = GAMMA\n FPEAK( 1 ) = PI\n FPEAK( 2 ) = ONE\n END IF\nC\n ELSE\n IWRK = IAS\nC\nC Restore D, if needed.\nC\n IF ( WITHD )\n $ CALL DLACPY( 'Full', P, M, D, LDD, DWORK( ID ), P )\n END IF\nC\nC Build the remaining set of frequencies.\nC Complex workspace: need (N+M)*(N+P)+2*MIN(P,M)+MAX(P,M));\nC prefer larger.\nC Real workspace: need LDW2, see above;\nC prefer larger.\nC\n IF ( MIN( FPEAKS, FPEAKI ).NE.ZERO ) THEN\nC\nC Compute also the norm at the given (finite) frequency.\nC\n GAMMA = AB13DX( DICO, JOBE, JOBD, N, M, P, FPEAKS, DWORK( IA ),\n $ N, DWORK( IE ), N, DWORK( IB ), N, DWORK( IC ),\n $ P, DWORK( ID ), P, IWORK, DWORK( IWRK ),\n $ LDWORK-IWRK+1, CWORK, LCWORK, IERR )\n MAXCWK = MAX( INT( CWORK( 1 ) ), MAXCWK )\n MAXWRK = MAX( INT( DWORK( IWRK ) ) + IWRK - 1, MAXWRK )\n IF ( DISCR ) THEN\n TM = ABS( ATAN2( SIN( FPEAKS ), COS( FPEAKS ) ) )\n ELSE\n TM = FPEAKS\n END IF\n IF( IERR.GE.1 .AND. IERR.LE.N ) THEN\n GPEAK( 1 ) = ONE\n FPEAK( 1 ) = TM\n GPEAK( 2 ) = ZERO\n FPEAK( 2 ) = ONE\n GO TO 340\n ELSE IF( IERR.EQ.N+1 ) THEN\n INFO = 3\n RETURN\n END IF\nC\n IF( GAMMAL.LT.GAMMA ) THEN\n GAMMAL = GAMMA\n FPEAK( 1 ) = TM\n FPEAK( 2 ) = ONE\n END IF\nC\n END IF\nC\n DO 110 I = 0, N - 1\n IF( DWORK( II+I ).GE.ZERO .AND. DWORK( IM+I ).GT.ZERO ) THEN\n IF ( ( DWORK( IM+I ).GE.ONE ) .OR. ( DWORK( IM+I ).LT.ONE\n $ .AND. DWORK( IAR+I ).LT.SAFMAX*DWORK( IM+I ) ) ) THEN\n RAT = DWORK( IAR+I ) / DWORK( IM+I )\n ELSE\n RAT = ONE\n END IF\n OMEGA = DWORK( IM+I )*SQRT( MAX( P25, ONE - TWO*RAT**2 ) )\nC\n GAMMA = AB13DX( DICO, JOBE, JOBD, N, M, P, OMEGA,\n $ DWORK( IA ), N, DWORK( IE ), N, DWORK( IB ),\n $ N, DWORK( IC ), P, DWORK( ID ), P, IWORK,\n $ DWORK( IWRK ), LDWORK-IWRK+1, CWORK, LCWORK,\n $ IERR )\n MAXCWK = MAX( INT( CWORK( 1 ) ), MAXCWK )\n MAXWRK = MAX( INT( DWORK( IWRK ) ) + IWRK - 1, MAXWRK )\n IF ( DISCR ) THEN\n TM = ABS( ATAN2( SIN( OMEGA ), COS( OMEGA ) ) )\n ELSE\n TM = OMEGA\n END IF\n IF( IERR.GE.1 .AND. IERR.LE.N ) THEN\n GPEAK( 1 ) = ONE\n FPEAK( 1 ) = TM\n GPEAK( 2 ) = ZERO\n FPEAK( 2 ) = ONE\n GO TO 340\n ELSE IF( IERR.EQ.N+1 ) THEN\n INFO = 3\n RETURN\n END IF\nC\n IF( GAMMAL.LT.GAMMA ) THEN\n GAMMAL = GAMMA\n FPEAK( 1 ) = TM\n FPEAK( 2 ) = ONE\n END IF\nC\n END IF\n 110 CONTINUE\nC\nC Return if the lower bound is zero.\nC\n IF( GAMMAL.EQ.ZERO ) THEN\n GPEAK( 1 ) = ZERO\n FPEAK( 1 ) = ZERO\n GPEAK( 2 ) = ONE\n FPEAK( 2 ) = ONE\n GO TO 340\n END IF\nC\nC Start the modified gamma iteration for the Bruinsma-Steinbuch\nC algorithm.\nC\n IF ( .NOT.DISCR )\n $ RTOL = HUNDRD*TOLER\n ITER = 0\nC\nC WHILE ( Iteration may continue ) DO\nC\n 120 CONTINUE\nC\n ITER = ITER + 1\n GAMMA = ( ONE + TOL )*GAMMAL\n USEPEN = FULLE .OR. DISCR\n IF ( .NOT.USEPEN .AND. WITHD ) THEN\nC\nC Check whether one can use an explicit Hamiltonian matrix:\nC compute\nC min(rcond(GAMMA**2*Im - S'*S), rcond(GAMMA**2*Ip - S*S')).\nC If P = M = 1, then GAMMA**2 - S(1)**2 is used instead.\nC\n IF ( M.NE.P ) THEN\n RCOND = ONE - ( DWORK( IS ) / GAMMA )**2\n ELSE IF ( MINPM.GT.1 ) THEN\n RCOND = ( GAMMA**2 - DWORK( IS )**2 ) /\n $ ( GAMMA**2 - DWORK( IS+P-1 )**2 )\n ELSE\n RCOND = GAMMA**2 - DWORK( IS )**2\n END IF\nC\n USEPEN = RCOND.LT.RTOL\n END IF\nC\n IF ( USEPEN ) THEN\nC\nC Use the QZ algorithm on a pencil.\nC Additional workspace here: need 6*N. (from IR)\nC\n II = IR + N2\n IBT = II + N2\n IH12 = IBT + N2\n IM = IH12\nC\nC Set up the needed parts of the Hamiltonian pencil (H,J),\nC\nC ( H11 H12 )\nC H = ( ) ,\nC ( H21 H22 )\nC\nC with\nC\nC ( A 0 ) ( 0 B ) ( E 0 )\nC H11 = ( ), H12 = ( )/nB, J11 = ( ),\nC ( 0 -A' ) ( C' 0 ) ( 0 E' )\nC\nC ( C 0 ) ( Ip D/g )\nC H21 = ( )*nB, H22 = ( ),\nC ( 0 -B' ) ( D'/g Im )\nC\nC if DICO = 'C', and\nC\nC ( A 0 ) ( B 0 ) ( E 0 )\nC H11 = ( ), H12 = ( )/nB, J11 = ( ),\nC ( 0 E' ) ( 0 C' ) ( 0 A')\nC\nC ( 0 0 ) ( Im D'/g ) ( 0 B')\nC H21 = ( )*nB, H22 = ( ), J21 = ( )*nB,\nC ( C 0 ) ( D/g Ip ) ( 0 0 )\nC\nC if DICO = 'D', where g = GAMMA, and nB = norm(B,1).\nC First build [H12; H22].\nC\n TEMP( 1 ) = ZERO\n IH = IH12\nC\n IF ( DISCR ) THEN\nC\n DO 150 J = 1, M\nC\n DO 130 I = 1, N\n DWORK( IH ) = B( I, J ) / BNORM\n IH = IH + 1\n 130 CONTINUE\nC\n CALL DCOPY( N+M, TEMP, 0, DWORK( IH ), 1 )\n DWORK( IH+N+J-1 ) = ONE\n IH = IH + N + M\nC\n DO 140 I = 1, P\n DWORK( IH ) = D( I, J ) / GAMMA\n IH = IH + 1\n 140 CONTINUE\nC\n 150 CONTINUE\nC\n DO 180 J = 1, P\n CALL DCOPY( N, TEMP, 0, DWORK( IH ), 1 )\n IH = IH + N\nC\n DO 160 I = 1, N\n DWORK( IH ) = C( J, I ) / BNORM\n IH = IH + 1\n 160 CONTINUE\nC\n DO 170 I = 1, M\n DWORK( IH ) = D( J, I ) / GAMMA\n IH = IH + 1\n 170 CONTINUE\nC\n CALL DCOPY( P, TEMP, 0, DWORK( IH ), 1 )\n DWORK( IH+J-1 ) = ONE\n IH = IH + P\n 180 CONTINUE\nC\n ELSE\nC\n DO 210 J = 1, P\n CALL DCOPY( N, TEMP, 0, DWORK( IH ), 1 )\n IH = IH + N\nC\n DO 190 I = 1, N\n DWORK( IH ) = C( J, I ) / BNORM\n IH = IH + 1\n 190 CONTINUE\nC\n CALL DCOPY( P, TEMP, 0, DWORK( IH ), 1 )\n DWORK( IH+J-1 ) = ONE\n IH = IH + P\nC\n DO 200 I = 1, M\n DWORK( IH ) = D( J, I ) / GAMMA\n IH = IH + 1\n 200 CONTINUE\nC\n 210 CONTINUE\nC\n DO 240 J = 1, M\nC\n DO 220 I = 1, N\n DWORK( IH ) = B( I, J ) / BNORM\n IH = IH + 1\n 220 CONTINUE\nC\n CALL DCOPY( N, TEMP, 0, DWORK( IH ), 1 )\n IH = IH + N\nC\n DO 230 I = 1, P\n DWORK( IH ) = D( I, J ) / GAMMA\n IH = IH + 1\n 230 CONTINUE\nC\n CALL DCOPY( M, TEMP, 0, DWORK( IH ), 1 )\n DWORK( IH+J-1 ) = ONE\n IH = IH + M\n 240 CONTINUE\nC\n END IF\nC\nC Compute the QR factorization of [H12; H22].\nC For large P and M, it could be more efficient to exploit the\nC structure of [H12; H22] and use the factored form of Q.\nC Additional workspace: need (2*N+P+M)*(2*N+P+M)+2*(P+M);\nC prefer (2*N+P+M)*(2*N+P+M)+P+M+\nC (P+M)*NB.\nC\n ITAU = IH12 + N2PM*N2PM\n IWRK = ITAU + PM\n CALL DGEQRF( N2PM, PM, DWORK( IH12 ), N2PM, DWORK( ITAU ),\n $ DWORK( IWRK ), LDWORK-IWRK+1, IERR )\n MAXWRK = MAX( INT( DWORK( IWRK ) ) + IWRK - 1, MAXWRK )\nC\nC Apply part of the orthogonal transformation:\nC Q1 = Q(:,P+M+(1:2*N))' to the matrix [H11; H21/GAMMA].\nC If DICO = 'C', apply Q(1:2*N,P+M+(1:2*N))' to the\nC matrix J11.\nC If DICO = 'D', apply Q1 to the matrix [J11; J21/GAMMA].\nC H11, H21, J11, and J21 are not fully built.\nC First, build the (2*N+P+M)-by-(2*N+P+M) matrix Q.\nC Using Q will often provide better efficiency than the direct\nC use of the factored form of Q, especially when P+M < N.\nC Additional workspace: need P+M+2*N+P+M;\nC prefer P+M+(2*N+P+M)*NB.\nC\n CALL DORGQR( N2PM, N2PM, PM, DWORK( IH12 ), N2PM,\n $ DWORK( ITAU ), DWORK( IWRK ), LDWORK-IWRK+1,\n $ IERR )\n MAXWRK = MAX( INT( DWORK( IWRK ) ) + IWRK - 1, MAXWRK )\nC\nC Additional workspace: need 8*N*N.\nC\n IPA = ITAU\n IPE = IPA + 4*NN\n IWRK = IPE + 4*NN\n CALL DGEMM( 'Transpose', 'No Transpose', N2, N, N, ONE,\n $ DWORK( IH12+PM*N2PM ), N2PM, A, LDA, ZERO,\n $ DWORK( IPA ), N2 )\n IF ( DISCR ) THEN\n CALL DGEMM( 'Transpose', 'No Transpose', N2, N, P,\n $ BNORM/GAMMA, DWORK( IH12+PM*N2PM+N2+M), N2PM,\n $ C, LDC, ONE, DWORK( IPA ), N2 )\n IF ( FULLE ) THEN\n CALL DGEMM( 'Transpose', 'Transpose', N2, N, N, ONE,\n $ DWORK( IH12+PM*N2PM+N ), N2PM, E, LDE,\n $ ZERO, DWORK( IPA+2*NN ), N2 )\n ELSE\n CALL MA02AD( 'Full', N, N2, DWORK( IH12+PM*N2PM+N ),\n $ N2PM, DWORK( IPA+2*NN ), N2 )\n NY = N\n END IF\n ELSE\n CALL DGEMM( 'Transpose', 'No Transpose', N2, N, P,\n $ BNORM/GAMMA, DWORK( IH12+PM*N2PM+N2), N2PM,\n $ C, LDC, ONE, DWORK( IPA ), N2 )\n CALL DGEMM( 'Transpose', 'Transpose', N2, N, N, -ONE,\n $ DWORK( IH12+PM*N2PM+N ), N2PM, A, LDA, ZERO,\n $ DWORK( IPA+2*NN ), N2 )\n CALL DGEMM( 'Transpose', 'Transpose', N2, N, M,\n $ -BNORM/GAMMA, DWORK( IH12+PM*N2PM+N2+P),\n $ N2PM, B, LDB, ONE, DWORK( IPA+2*NN ), N2 )\n NY = N2\n END IF\nC\n IF ( FULLE ) THEN\n CALL DGEMM( 'Transpose', 'No Transpose', N2, N, N, ONE,\n $ DWORK( IH12+PM*N2PM ), N2PM, E, LDE, ZERO,\n $ DWORK( IPE ), N2 )\n ELSE\n CALL MA02AD( 'Full', NY, N2, DWORK( IH12+PM*N2PM ),\n $ N2PM, DWORK( IPE ), N2 )\n END IF\n IF ( DISCR ) THEN\n CALL DGEMM( 'Transpose', 'Transpose', N2, N, N, ONE,\n $ DWORK( IH12+PM*N2PM+N ), N2PM, A, LDA,\n $ ZERO, DWORK( IPE+2*NN ), N2 )\n CALL DGEMM( 'Transpose', 'Transpose', N2, N, M,\n $ BNORM/GAMMA, DWORK( IH12+PM*N2PM+N2 ), N2PM,\n $ B, LDB, ONE, DWORK( IPE+2*NN ), N2 )\n ELSE\n IF ( FULLE )\n $ CALL DGEMM( 'Transpose', 'Transpose', N2, N, N, ONE,\n $ DWORK( IH12+PM*N2PM+N ), N2PM, E, LDE,\n $ ZERO, DWORK( IPE+2*NN ), N2 )\n END IF\nC\nC Compute the eigenvalues of the Hamiltonian pencil.\nC Additional workspace: need 16*N;\nC prefer larger.\nC\n CALL DGGEV( 'No Vectors', 'No Vectors', N2, DWORK( IPA ),\n $ N2, DWORK( IPE ), N2, DWORK( IR ), DWORK( II ),\n $ DWORK( IBT ), DWORK, N2, DWORK, N2,\n $ DWORK( IWRK ), LDWORK-IWRK+1, IERR )\n IF( IERR.GT.0 ) THEN\n INFO = 2\n RETURN\n END IF\n MAXWRK = MAX( INT( DWORK( IWRK ) ) + IWRK - 1, MAXWRK )\nC\n ELSE IF ( .NOT.WITHD ) THEN\nC\nC Standard continuous-time case with D = 0.\nC Form the needed part of the Hamiltonian matrix explicitly:\nC H = H11 - H12*inv(H22)*H21/g.\nC Additional workspace: need 2*N*N+N. (from IBT)\nC\n IH = IBT\n IH12 = IH + NN\n ISL = IH12 + NN + N\n CALL DLACPY( 'Full', N, N, A, LDA, DWORK( IH ), N )\nC\nC Compute triangles of -C'*C/GAMMA and B*B'/GAMMA.\nC\n CALL DSYRK( 'Lower', 'Transpose', N, P, -ONE/GAMMA, C, LDC,\n $ ZERO, DWORK( IH12 ), N )\n CALL DSYRK( 'Upper', 'No Transpose', N, M, ONE/GAMMA, B,\n $ LDB, ZERO, DWORK( IH12+N ), N )\nC\n ELSE\nC\nC Standard continuous-time case with D <> 0 and the SVD of D\nC can be used. Compute explicitly the needed part of the\nC Hamiltonian matrix:\nC\nC (A+B1*S'*inv(g^2*Ip-S*S')*C1' g*B1*inv(g^2*Im-S'*S)*B1')\nC H = ( )\nC ( -g*C1*inv(g^2*Ip-S*S')*C1' -H11' )\nC\nC where g = GAMMA, B1 = B*V, C1 = C'*U, and H11 is the first\nC block of H.\nC Primary additional workspace: need 2*N*N+N (from IBT)\nC (for building the relevant part of the Hamiltonian matrix).\nC\nC Compute C1*sqrt(inv(g^2*Ip-S*S')) .\nC Additional workspace: need MAX(M,P)+N*P.\nC\n IH = IBT\n IH12 = IH + NN\n ISL = IH12 + NN + N\nC\n DO 250 I = 0, MINPM - 1\n DWORK( ISL+I ) = ONE/SQRT( GAMMA**2 - DWORK( IS+I )**2 )\n 250 CONTINUE\nC\n IF ( M.LT.P ) THEN\n DWORK( ISL+M ) = ONE / GAMMA\n CALL DCOPY( P-M-1, DWORK( ISL+M ), 0, DWORK( ISL+M+1 ),\n $ 1 )\n END IF\n ISC = ISL + MAX( M, P )\n CALL DLACPY( 'Full', N, P, DWORK( ICU ), N, DWORK( ISC ),\n $ N )\n CALL MB01SD( 'Column', N, P, DWORK( ISC ), N, DWORK,\n $ DWORK( ISL ) )\nC\nC Compute B1*S' .\nC Additional workspace: need N*M.\nC\n ISB = ISC + P*N\n CALL DLACPY( 'Full', N, M, DWORK( IBV ), N, DWORK( ISB ),\n $ N )\n CALL MB01SD( 'Column', N, MINPM, DWORK( ISB ), N, DWORK,\n $ DWORK( IS ) )\nC\nC Compute B1*S'*sqrt(inv(g^2*Ip-S*S')) .\nC\n CALL MB01SD( 'Column', N, MINPM, DWORK( ISB ), N, DWORK,\n $ DWORK( ISL ) )\nC\nC Compute H11 .\nC\n CALL DLACPY( 'Full', N, N, A, LDA, DWORK( IH ), N )\n CALL DGEMM( 'No Transpose', 'Transpose', N, N, MINPM, ONE,\n $ DWORK( ISB ), N, DWORK( ISC ), N, ONE,\n $ DWORK( IH ), N )\nC\nC Compute B1*sqrt(inv(g^2*Im-S'*S)) .\nC\n IF ( P.LT.M ) THEN\n DWORK( ISL+P ) = ONE / GAMMA\n CALL DCOPY( M-P-1, DWORK( ISL+P ), 0, DWORK( ISL+P+1 ),\n $ 1 )\n END IF\n CALL DLACPY( 'Full', N, M, DWORK( IBV ), N, DWORK( ISB ),\n $ N )\n CALL MB01SD( 'Column', N, M, DWORK( ISB ), N, DWORK,\n $ DWORK( ISL ) )\nC\nC Compute the lower triangle of H21 and the upper triangle\nC of H12.\nC\n CALL DSYRK( 'Lower', 'No Transpose', N, P, -GAMMA,\n $ DWORK( ISC ), N, ZERO, DWORK( IH12 ), N )\n CALL DSYRK( 'Upper', 'No Transpose', N, M, GAMMA,\n $ DWORK( ISB ), N, ZERO, DWORK( IH12+N ), N )\n END IF\nC\n IF ( .NOT.USEPEN ) THEN\nC\nC Compute the eigenvalues of the Hamiltonian matrix by the\nC symplectic URV and the periodic Schur decompositions.\nC Additional workspace: need (2*N+8)*N;\nC prefer larger.\nC\n IWRK = ISL + NN\n CALL MB03XD( 'Both', 'Eigenvalues', 'No vectors',\n $ 'No vectors', N, DWORK( IH ), N, DWORK( IH12 ),\n $ N, DWORK( ISL ), N, TEMP, 1, TEMP, 1, TEMP, 1,\n $ TEMP, 1, DWORK( IR ), DWORK( II ), ILO,\n $ DWORK( IWRK ), DWORK( IWRK+N ),\n $ LDWORK-IWRK-N+1, IERR )\n IF( IERR.GT.0 ) THEN\n INFO = 2\n RETURN\n END IF\n MAXWRK = MAX( INT( DWORK( IWRK ) ) + IWRK + N - 1, MAXWRK )\n END IF\nC\nC Detect eigenvalues on the boundary of the stability domain,\nC if any. The test is based on a round-off level of eps*rho(H)\nC (after balancing) resulting in worst-case perturbations of\nC order sqrt(eps*rho(H)), for continuous-time systems, on the\nC real part of poles of multiplicity two (typical as GAMMA\nC approaches the infinity norm). Similarly, in the discrete-time\nC case. Above, rho(H) is the maximum modulus of eigenvalues\nC (continuous-time case).\nC\nC Compute maximum eigenvalue modulus and check the absolute real\nC parts (if DICO = 'C'), or moduli (if DICO = 'D').\nC\n WMAX = ZERO\nC\n IF ( USEPEN ) THEN\nC\nC Additional workspace: need 2*N, if DICO = 'D'; (from IM)\nC 0, if DICO = 'C'.\nC\n DO 260 I = 0, N2 - 1\n TM = DLAPY2( DWORK( IR+I ), DWORK( II+I ) )\n IF ( ( DWORK( IBT+I ).GE.ONE ) .OR.\n $ ( DWORK( IBT+I ).LT.ONE .AND.\n $ TM.LT.SAFMAX*DWORK( IBT+I ) ) ) THEN\n TM = TM / DWORK( IBT+I )\n ELSE\nC\nC The pencil has too large eigenvalues. SAFMAX is used.\nC\n TM = SAFMAX\n END IF\n WMAX = MAX( WMAX, TM )\n IF ( DISCR )\n $ DWORK( IM+I ) = TM\n 260 CONTINUE\nC\n ELSE\nC\n DO 270 I = 0, N - 1\n TM = DLAPY2( DWORK( IR+I ), DWORK( II+I ) )\n WMAX = MAX( WMAX, TM )\n 270 CONTINUE\nC\n END IF\nC\n NEI = 0\nC\n IF ( USEPEN ) THEN\nC\n DO 280 I = 0, N2 - 1\n IF ( DISCR ) THEN\n TM = ABS( ONE - DWORK( IM+I ) )\n ELSE\n TM = ABS( DWORK( IR+I ) )\n IF ( ( DWORK( IBT+I ).GE.ONE ) .OR.\n $ ( DWORK( IBT+I ).LT.ONE .AND.\n $ TM.LT.SAFMAX*DWORK( IBT+I ) ) ) THEN\n TM = TM / DWORK( IBT+I )\n ELSE\nC\nC The pencil has too large eigenvalues.\nC SAFMAX is used.\nC\n TM = SAFMAX\n END IF\n END IF\n IF ( TM.LE.TOLER*SQRT( HUNDRD + WMAX ) ) THEN\n DWORK( IR+NEI ) = DWORK( IR+I ) / DWORK( IBT+I )\n DWORK( II+NEI ) = DWORK( II+I ) / DWORK( IBT+I )\n NEI = NEI + 1\n END IF\n 280 CONTINUE\nC\n ELSE\nC\n DO 290 I = 0, N - 1\n TM = ABS( DWORK( IR+I ) )\n IF ( TM.LE.TOLER*SQRT( HUNDRD + WMAX ) ) THEN\n DWORK( IR+NEI ) = DWORK( IR+I )\n DWORK( II+NEI ) = DWORK( II+I )\n NEI = NEI + 1\n END IF\n 290 CONTINUE\nC\n END IF\nC\n IF( NEI.EQ.0 ) THEN\nC\nC There is no eigenvalue on the boundary of the stability\nC domain for G = ( ONE + TOL )*GAMMAL. The norm was found.\nC\n GPEAK( 1 ) = GAMMAL\n GPEAK( 2 ) = ONE\n GO TO 340\n END IF\nC\nC Compute the frequencies where the gain G is attained and\nC generate new test frequencies.\nC\n NWS = 0\nC\n IF ( DISCR ) THEN\nC\n DO 300 I = 0, NEI - 1\n TM = ATAN2( DWORK( II+I ), DWORK( IR+I ) )\n DWORK( IR+I ) = MAX( EPS, TM )\n NWS = NWS + 1\n 300 CONTINUE\nC\n ELSE\nC\n J = 0\nC\n DO 310 I = 0, NEI - 1\n IF ( DWORK( II+I ).GT.EPS ) THEN\n DWORK( IR+NWS ) = DWORK( II+I )\n NWS = NWS + 1\n ELSE IF ( DWORK( II+I ).EQ.EPS ) THEN\n J = J + 1\n IF ( J.EQ.1 ) THEN\n DWORK( IR+NWS ) = EPS\n NWS = NWS + 1\n END IF\n END IF\n 310 CONTINUE\nC\n END IF\nC\n CALL DLASRT( 'Increasing', NWS, DWORK( IR ), IERR )\n LW = 1\nC\n DO 320 I = 0, NWS - 1\n IF ( DWORK( IR+LW-1 ).NE.DWORK( IR+I ) ) THEN\n DWORK( IR+LW ) = DWORK( IR+I )\n LW = LW + 1\n END IF\n 320 CONTINUE\nC\n IF ( LW.EQ.1 ) THEN\n IF ( ITER.EQ.1 .AND. NWS.GE.1 ) THEN\nC\nC Duplicate the frequency trying to force iteration.\nC\n DWORK( IR+1 ) = DWORK( IR )\n LW = LW + 1\n ELSE\nC\nC The norm was found.\nC\n GPEAK( 1 ) = GAMMAL\n GPEAK( 2 ) = ONE\n GO TO 340\n END IF\n END IF\nC\nC Form the vector of mid-points and compute the gain at new test\nC frequencies. Save the current lower bound.\nC\n IWRK = IR + LW\n GAMMAS = GAMMAL\nC\n DO 330 I = 0, LW - 2\n IF ( DISCR ) THEN\n OMEGA = ( DWORK( IR+I ) + DWORK( IR+I+1 ) ) / TWO\n ELSE\n OMEGA = SQRT( DWORK( IR+I )*DWORK( IR+I+1 ) )\n END IF\nC\nC Additional workspace: need LDW2, see above;\nC prefer larger.\nC\n GAMMA = AB13DX( DICO, JOBE, JOBD, N, M, P, OMEGA,\n $ DWORK( IA ), N, DWORK( IE ), N, DWORK( IB ),\n $ N, DWORK( IC ), P, DWORK( ID ), P, IWORK,\n $ DWORK( IWRK ), LDWORK-IWRK+1, CWORK, LCWORK,\n $ IERR )\n MAXCWK = MAX( INT( CWORK( 1 ) ), MAXCWK )\n MAXWRK = MAX( INT( DWORK( IWRK ) ) + IWRK - 1, MAXWRK )\n IF ( DISCR ) THEN\n TM = ABS( ATAN2( SIN( OMEGA ), COS( OMEGA ) ) )\n ELSE\n TM = OMEGA\n END IF\n IF( IERR.GE.1 .AND. IERR.LE.N ) THEN\n GPEAK( 1 ) = ONE\n FPEAK( 1 ) = TM\n GPEAK( 2 ) = ZERO\n FPEAK( 2 ) = ONE\n GO TO 340\n ELSE IF( IERR.EQ.N+1 ) THEN\n INFO = 3\n RETURN\n END IF\nC\n IF( GAMMAL.LT.GAMMA ) THEN\n GAMMAL = GAMMA\n FPEAK( 1 ) = TM\n FPEAK( 2 ) = ONE\n END IF\n 330 CONTINUE\nC\nC If the lower bound has not been improved, return. (This is a\nC safeguard against undetected modes of Hamiltonian matrix on the\nC boundary of the stability domain.)\nC\n IF ( GAMMAL.LT.GAMMAS*( ONE + TOL/TEN ) ) THEN\n GPEAK( 1 ) = GAMMAL\n GPEAK( 2 ) = ONE\n GO TO 340\n END IF\nC\nC END WHILE\nC\n IF ( ITER.LE.MAXIT ) THEN\n GO TO 120\n ELSE\n INFO = 4\n RETURN\n END IF\nC\n 340 CONTINUE\n DWORK( 1 ) = MAXWRK\n CWORK( 1 ) = MAXCWK\n RETURN\nC *** Last line of AB13DD ***\n END\n", "meta": {"hexsha": "e08d8f04860fdb8e1500fbc3b6647871c86d5fa5", "size": 64696, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/AB13DD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/AB13DD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/AB13DD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 34.8765498652, "max_line_length": 72, "alphanum_fraction": 0.4260696179, "num_tokens": 20783, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9372107966642556, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.688024746652907}} {"text": "c=============================================================================c\n subroutine elliptic( nx, ny, x, ldx, y, ldy, eps, nmax )\nc\nc This routine performs an elliptic smoothing of the input grid\nc \nc Author: Scott Collis\nc\nc Date: 6-17-97\nc\nc=============================================================================c\n implicit none\n\n integer nx, ny, ldx, ldy, nmax\n real x(ldx,ny), y(ldy,ny), eps\n\n real zero, pt5, one, two\n parameter (zero=0.0, pt5=0.5, one=1.0, two=2.0)\n\n integer n, i, j\n real dxi, deta, xeta, yeta, xxi, yxi, a, b, c, xnew, ynew, err\n\n integer mx\n parameter (mx=1000)\n real w, rx(mx), ry(mx), ad(mx), bd(mx), cd(mx), xl(mx), yl(mx)\nc=============================================================================c\n if (nx.gt.mx) then\n write(*,*) 'Increase mx in elliptic'\n stop\n end if\n\n dxi = one / float(nx-1)\n deta = one / float(ny-1)\nc\nc.... Gauss-Siedel\nc\n if (.false.) then\n\n n = 0\n 10 continue\n n = n + 1\n err = zero\n do i = 2, nx-1\n do j = 2, ny-1\n xeta = (x(i,j+1)-x(i,j-1)) / (two * deta)\n yeta = (y(i,j+1)-y(i,j-1)) / (two * deta)\n xxi = (x(i+1,j)-x(i-1,j)) / (two * dxi)\n yxi = (y(i+1,j)-y(i-1,j)) / (two * dxi)\n\n a = (xeta**2 + yeta**2) / dxi**2\n b = (xxi*xeta + yxi*yeta) / ( two * dxi * deta )\n c = (xxi**2 + yxi**2) / deta**2\n \n xnew = (a * (x(i+1,j) + x(i-1,j)) + c * (x(i,j+1) + x(i,j-1))\n & - b * (x(i+1,j+1) - x(i+1,j-1) + x(i-1,j-1) -\n & x(i-1,j+1)) ) / ( two * (a + c) )\n ynew = (a * (y(i+1,j) + y(i-1,j)) + c * (y(i,j+1) + y(i,j-1))\n & - b * (y(i+1,j+1) - y(i+1,j-1) + y(i-1,j-1) -\n & y(i-1,j+1)) ) / ( two * (a + c) )\n\n err = err + abs(x(i,j)-xnew) + abs(y(i,j)-ynew)\n\n x(i,j) = xnew\n y(i,j) = ynew\n end do\n end do\n err = err / real( (nx-2)*(ny-2) )\n write(*,\"(i5,1x,1pe13.6)\") n, err\n if ( err .gt. eps .and. n .lt. nmax) goto 10\nc\nc.... Line Gauss-Siedel with SOR (because of the nonlinearity, SOR is unstable\nc.... for w > 1.\nc\n else\n\n write(*,\"(/,'Enter the SOR parmameter (0 < w < 2, w = 1.78) ==>',$)\")\n read(*,*) w\n n = 0\n 20 continue\n n = n + 1\n err = zero\n do j = 2, ny-1\n do i = 2, nx-1\n xeta = (x(i,j+1)-x(i,j-1)) / (two * deta)\n yeta = (y(i,j+1)-y(i,j-1)) / (two * deta)\n xxi = (x(i+1,j)-x(i-1,j)) / (two * dxi)\n yxi = (y(i+1,j)-y(i-1,j)) / (two * dxi)\n\n a = (xeta**2 + yeta**2) / dxi**2\n b = (xxi*xeta + yxi*yeta) / ( two * dxi * deta )\n c = (xxi**2 + yxi**2) / deta**2\n \n rx(i) = -two*(one-w)*(a + c) * x(i,j) + w*b*(x(i+1,j+1) -\n & x(i+1,j-1) + x(i-1,j-1) - x(i-1,j+1)) -\n & w*c*(x(i,j+1) + x(i,j-1))\n\n ry(i) = -two*(one-w)*(a + c) * y(i,j) + w*b*(y(i+1,j+1) -\n & y(i+1,j-1) + y(i-1,j-1) - y(i-1,j+1)) -\n & w*c*(y(i,j+1) + y(i,j-1))\n\n ad(i) = w * a\n bd(i) = -two * (a + c)\n cd(i) = w * a\n end do\nc\nc.... apply the boundary conditions\nc\n rx(1) = x(1,j)\n ry(1) = y(1,j)\n rx(nx) = x(nx,j)\n ry(nx) = y(nx,j)\n \n ad(1) = zero\n bd(1) = one\n cd(1) = zero\n \n ad(nx) = zero\n bd(nx) = one\n cd(nx) = zero\n \n call tridag( ad, bd, cd, rx, xl, nx )\n call tridag( ad, bd, cd, ry, yl, nx )\n \n do i = 2, nx-1\n err = err + abs(x(i,j)-xl(i)) + abs(y(i,j)-yl(i))\n x(i,j) = xl(i)\n y(i,j) = yl(i)\n end do\n end do\n\n err = err / real( (nx-2)*(ny-2) )\n write(*,\"(i5,1x,1pe13.6)\") n, err\n if ( err .gt. eps .and. n .lt. nmax) goto 20\n\n end if\n\n return\n end\n\n SUBROUTINE TRIDAG(A,B,C,R,U,N)\n DIMENSION A(N),B(N),C(N),R(N),U(N)\n INTEGER NMAX\n PARAMETER (NMAX=1000)\n DIMENSION GAM(NMAX)\n IF(N.GT.NMAX)PAUSE\n IF(B(1).EQ.0.)PAUSE\n BET=B(1)\n U(1)=R(1)/BET\n DO 11 J=2,N\n GAM(J)=C(J-1)/BET\n BET=B(J)-A(J)*GAM(J)\n IF(BET.EQ.0.)PAUSE\n U(J)=(R(J)-A(J)*U(J-1))/BET\n11 CONTINUE\n DO 12 J=N-1,1,-1\n U(J)=U(J)-GAM(J+1)*U(J+1)\n12 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "88b521b1e9cf0a3a4771355b758267be501f387a", "size": 4761, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "mesh/elliptic.f", "max_stars_repo_name": "sscollis/lns3d", "max_stars_repo_head_hexsha": "f87b06abbb188cce9248092075f71dcce4570493", "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": "mesh/elliptic.f", "max_issues_repo_name": "sscollis/lns3d", "max_issues_repo_head_hexsha": "f87b06abbb188cce9248092075f71dcce4570493", "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": "mesh/elliptic.f", "max_forks_repo_name": "sscollis/lns3d", "max_forks_repo_head_hexsha": "f87b06abbb188cce9248092075f71dcce4570493", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-02-20T09:24:25.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-20T09:24:25.000Z", "avg_line_length": 29.9433962264, "max_line_length": 79, "alphanum_fraction": 0.3547574039, "num_tokens": 1767, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107949104866, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.688024745365431}} {"text": "! A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,\n!\n! a^2 + b^2 = c^2\n!\n! For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.\n! There exists exactly one Pythagorean triplet for which a + b + c = 1000.\n! Find the product abc.\nmodule Problem9\n\n implicit none\n private\n\n public :: solve\ncontains\n subroutine solve\n write (*, '(A)') 'Problem 9. Special Pythagorean triplet.'\n\n write (*, '(A, I)') 'Product 1: ', product1()\n end subroutine\n\n pure function product1()\n integer, parameter:: limit = 1000\n integer product1\n integer a\n integer b\n integer c\n\n ! initial value\n product1 = 0\n\n do c = 1, limit\n do b = 1, c - 1\n do a = 1, b - 1\n if (a + b + c == limit) then\n if ((a**2) + (b**2) == (c**2)) then\n product1 = a * b * c\n\n return\n end if\n end if\n end do\n end do\n end do\n end function\nend module\n", "meta": {"hexsha": "57b6dfc439aa7ba4025b7a5d22aa2f7819597f19", "size": 1115, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Problem9.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": "Problem9.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": "Problem9.f", "max_forks_repo_name": "andreypudov/projecteuler", "max_forks_repo_head_hexsha": "898b1db49c6fdde8fa42c7a2bc471a0ed3bc73e9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.2391304348, "max_line_length": 80, "alphanum_fraction": 0.4582959641, "num_tokens": 311, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802440252811, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6880218062978326}} {"text": "c\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc . .\nc . copyright (c) 1998 by UCAR .\nc . .\nc . University Corporation for Atmospheric Research .\nc . .\nc . all rights reserved .\nc . .\nc . .\nc . SPHEREPACK .\nc . .\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc\nc\nc\nc ... file igradgc.f\nc\nc this file includes documentation and code for\nc subroutine igradgc i\nc\nc ... files which must be loaded with igradgc.f\nc\nc sphcom.f, hrfft.f, shsgc.f,vhagc.f\nc\nc subroutine igradgc(nlat,nlon,isym,nt,sf,isf,jsf,br,bi,mdb,ndb,\nc + wshsgc,lshsgc,work,lwork,ierror)\nc\nc let br,bi,cr,ci be the vector spherical harmonic coefficients\nc precomputed by vhagc for a vector field (v,w). let (v',w') be\nc the irrotational component of (v,w) (i.e., (v',w') is generated\nc by assuming cr,ci are zero and synthesizing br,bi with vhsgs).\nc then subroutine igradgc computes a scalar field sf such that\nc\nc gradient(sf) = (v',w').\nc\nc i.e.,\nc\nC*PL*ERROR* Comment line too long\nc v'(i,j) = d(sf(i,j))/dtheta (colatitudinal component of\nc the gradient)\nc and\nc\nC*PL*ERROR* Comment line too long\nc w'(i,j) = 1/sint*d(sf(i,j))/dlambda (east longitudinal component\nc of the gradient)\nc\nc at the gaussian colatitude theta(i) (see nlat as input parameter)\nC*PL*ERROR* Comment line too long\nc and longitude lambda(j) = (j-1)*2*pi/nlon where sint = sin(theta(i)).\nc\nc note: for an irrotational vector field (v,w), subroutine igradgc\nc computes a scalar field whose gradient is (v,w). in ay case,\nc subroutine igradgc \"inverts\" the gradient subroutine gradgc.\nc\nc input parameters\nc\nc nlat the number of points in the gaussian colatitude grid on the\nC*PL*ERROR* Comment line too long\nc full sphere. these lie in the interval (0,pi) and are computed\nC*PL*ERROR* Comment line too long\nc in radians in theta(1) <...< theta(nlat) by subroutine gaqd.\nC*PL*ERROR* Comment line too long\nc if nlat is odd the equator will be included as the grid point\nc theta((nlat+1)/2). if nlat is even the equator will be\nc excluded as a grid point and will lie half way between\nc theta(nlat/2) and theta(nlat/2+1). nlat must be at least 3.\nc note: on the half sphere, the number of grid points in the\nc colatitudinal direction is nlat/2 if nlat is even or\nc (nlat+1)/2 if nlat is odd.\nc\nc nlon the number of distinct londitude points. nlon determines\nc the grid increment in longitude as 2*pi/nlon. for example\nc nlon = 72 for a five degree grid. nlon must be greater than\nc 3. the efficiency of the computation is improved when nlon\nc is a product of small prime numbers.\nc\nc\nc isym a parameter which determines whether the scalar field sf is\nc computed on the full or half sphere as follows:\nc\nc = 0\nc\nc the symmetries/antsymmetries described in isym=1,2 below\nc do not exist in (v,w) about the equator. in this case sf\nc is neither symmetric nor antisymmetric about the equator.\nc sf is computed on the entire sphere. i.e., in the array\nc sf(i,j) for i=1,...,nlat and j=1,...,nlon\nc\nc = 1\nc\nc w is antisymmetric and v is symmetric about the equator.\nc in this case sf is antisymmetyric about the equator and\nc is computed for the northern hemisphere only. i.e.,\nc if nlat is odd sf is computed in the array sf(i,j) for\nc i=1,...,(nlat+1)/2 and for j=1,...,nlon. if nlat is even\nc sf is computed in the array sf(i,j) for i=1,...,nlat/2\nc and j=1,...,nlon.\nc\nc = 2\nc\nc w is symmetric and v is antisymmetric about the equator.\nc in this case sf is symmetyric about the equator and\nc is computed for the northern hemisphere only. i.e.,\nc if nlat is odd sf is computed in the array sf(i,j) for\nc i=1,...,(nlat+1)/2 and for j=1,...,nlon. if nlat is even\nc sf is computed in the array sf(i,j) for i=1,...,nlat/2\nc and j=1,...,nlon.\nc\nc\nc nt nt is the number of scalar and vector fields. some\nc computational efficiency is obtained for multiple fields.\nC*PL*ERROR* Comment line too long\nc the arrays br,bi, and sf can be three dimensional corresponding\nc to an indexed multiple vector field (v,w). in this case,\nc multiple scalar synthesis will be performed to compute each\nC*PL*ERROR* Comment line too long\nc scalar field. the third index for br,bi, and sf is the synthesis\nc index which assumes the values k = 1,...,nt. for a single\nc synthesis set nt = 1. the description of the remaining\nC*PL*ERROR* Comment line too long\nc parameters is simplified by assuming that nt=1 or that br,bi,\nc and sf are two dimensional arrays.\nc\nc isf the first dimension of the array sf as it appears in\nc the program that calls igradgc. if isym = 0 then isf\nc must be at least nlat. if isym = 1 or 2 and nlat is\nc even then isf must be at least nlat/2. if isym = 1 or 2\nc and nlat is odd then isf must be at least (nlat+1)/2.\nc\nc jsf the second dimension of the array sf as it appears in\nc the program that calls igradgc. jsf must be at least nlon.\nc\nc br,bi two or three dimensional arrays (see input parameter nt)\nc that contain vector spherical harmonic coefficients\nc of the vector field (v,w) as computed by subroutine vhagc.\nc *** br,bi must be computed by vhagc prior to calling igradgc.\nc\nC*PL*ERROR* Comment line too long\nc mdb the first dimension of the arrays br and bi as it appears in\nc the program that calls igradgc (and vhagc). mdb must be at\nc least min0(nlat,nlon/2) if nlon is even or at least\nc min0(nlat,(nlon+1)/2) if nlon is odd.\nc\nC*PL*ERROR* Comment line too long\nc ndb the second dimension of the arrays br and bi as it appears in\nc the program that calls igradgc (and vhagc). ndb must be at\nc least nlat.\nc\nc\nc wshsgc an array which must be initialized by subroutine shsgci.\nc once initialized,\nc wshsgc can be used repeatedly by igradgc as long as nlon\nc and nlat remain unchanged. wshsgc must not be altered\nc between calls of igradgc.\nc\nc\nc lshsgc the dimension of the array wshsgc as it appears in the\nc program that calls igradgc. define\nc\nc l1 = min0(nlat,(nlon+2)/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc and\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd.\nc\nc\nc then lshsgc must be at least\nc\nc nlat*(2*l2+3*l1-2)+3*l1*(1-l1)/2+nlon+15\nc\nc\nc work a work array that does not have to be saved.\nc\nc lwork the dimension of the array work as it appears in the\nc program that calls igradgc define\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc l1 = min0(nlat,(nlon+2)/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\n\nc if isym is zero then lwork must be at least\nc\nc nlat*(nlon*nt+max0(3*l2,nlon)+2*nt*l1+1)\nc\nc if isym is not zero then lwork must be at least\nc\nc l2*(nlon*nt+max0(3*nlat,nlon)) + nlat*(2*nt*l1+1)\nc\nc\nc\nc **************************************************************\nc\nc output parameters\nc\nc\nC*PL*ERROR* Comment line too long\nc sf a two or three dimensional array (see input parameter nt) that\nc contain a scalar field whose gradient is the irrotational\nc component of the vector field (v,w). the vector spherical\nc harmonic coefficients br,bi were precomputed by subroutine\nc vhagc. sf(i,j) is given at the gaussian colatitude theta(i)\nc and longitude lambda(j) = (j-1)*2*pi/nlon. the index ranges\nc are defined at input parameter isym.\nc\nc\nc ierror = 0 no errors\nc = 1 error in the specification of nlat\nc = 2 error in the specification of nlon\nc = 3 error in the specification of isym\nc = 4 error in the specification of nt\nc = 5 error in the specification of isf\nc = 6 error in the specification of jsf\nc = 7 error in the specification of mdb\nc = 8 error in the specification of ndb\nc = 9 error in the specification of lshsgc\nc = 10 error in the specification of lwork\nc\nc **********************************************************************\nc\n SUBROUTINE DIGRADGC(NLAT,NLON,ISYM,NT,SF,ISF,JSF,BR,BI,MDB,NDB,\n + WSHSGC,LSHSGC,WORK,LWORK,IERROR)\n DOUBLE PRECISION SF\n DOUBLE PRECISION BR\n DOUBLE PRECISION BI\n DOUBLE PRECISION WSHSGC\n DOUBLE PRECISION WORK\n DIMENSION SF(ISF,JSF,NT)\n DIMENSION BR(MDB,NDB,NT),BI(MDB,NDB,NT)\n DIMENSION WSHSGC(LSHSGC),WORK(LWORK)\nc\nc check input parameters\nc\n IERROR = 1\n IF (NLAT.LT.3) RETURN\n IERROR = 2\n IF (NLON.LT.4) RETURN\n IERROR = 3\n IF (ISYM.LT.0 .OR. ISYM.GT.2) RETURN\n IERROR = 4\n IF (NT.LT.0) RETURN\n IERROR = 5\n IMID = (NLAT+1)/2\n IF ((ISYM.EQ.0.AND.ISF.LT.NLAT) .OR.\n + (ISYM.NE.0.AND.ISF.LT.IMID)) RETURN\n IERROR = 6\n IF (JSF.LT.NLON) RETURN\n IERROR = 7\n MMAX = MIN0(NLAT, (NLON+2)/2)\n IF (MDB.LT.MIN0(NLAT, (NLON+1)/2)) RETURN\n IERROR = 8\n IF (NDB.LT.NLAT) RETURN\n IERROR = 9\nc\nc verify saved work space length\nc\n L2 = (NLAT+MOD(NLAT,2))/2\n L1 = MIN0((NLON+2)/2,NLAT)\n IF (LSHSGC.LT.NLAT* (2*L2+3*L1-2)+3*L1* (1-L1)/2+NLON+15) RETURN\n IERROR = 10\nc\nc set minimum and verify unsaved work space\nc\n LS = NLAT\n IF (ISYM.GT.0) LS = IMID\n NLN = NT*LS*NLON\nc\nc set first dimension for a,b (as requried by shsgc)\nc\n MAB = MIN0(NLAT,NLON/2+1)\n MN = MAB*NLAT*NT\nc lwkmin = nln+ls*nlon+2*mn+nlat\n IF (ISYM.EQ.0) THEN\n LWKMIN = NLAT* (NT*NLON+MAX0(3*L2,NLON)+2*NT*L1+1)\n ELSE\n LWKMIN = L2* (NT*NLON+MAX0(3*NLAT,NLON)) + NLAT* (2*NT*L1+1)\n END IF\n IF (LWORK.LT.LWKMIN) RETURN\n IERROR = 0\nc\nc set work space pointers\nc\n IA = 1\n IB = IA + MN\n IS = IB + MN\n IWK = IS + NLAT\n LIWK = LWORK - 2*MN - NLAT\n CALL DIGRDGC1(NLAT,NLON,ISYM,NT,SF,ISF,JSF,WORK(IA),WORK(IB),MAB,\n + WORK(IS),MDB,NDB,BR,BI,WSHSGC,LSHSGC,WORK(IWK),LIWK,\n + IERROR)\n RETURN\n END\n\n SUBROUTINE DIGRDGC1(NLAT,NLON,ISYM,NT,SF,ISF,JSF,A,B,MAB,SQNN,MDB,\n + NDB,BR,BI,WSAV,LSAV,WK,LWK,IERROR)\n DOUBLE PRECISION SF\n DOUBLE PRECISION A\n DOUBLE PRECISION B\n DOUBLE PRECISION SQNN\n DOUBLE PRECISION BR\n DOUBLE PRECISION BI\n DOUBLE PRECISION WSAV\n DOUBLE PRECISION WK\n DOUBLE PRECISION FN\n DIMENSION SF(ISF,JSF,NT)\n DIMENSION BR(MDB,NDB,NT),BI(MDB,NDB,NT),SQNN(NLAT)\n DIMENSION A(MAB,NLAT,NT),B(MAB,NLAT,NT)\n DIMENSION WSAV(LSAV),WK(LWK)\nc\nc preset coefficient multiplyers in vector\nc\n DO 1 N = 2,NLAT\n FN = DBLE(N-1)\n SQNN(N) = 1.0D0/SQRT(FN* (FN+1.D0))\n 1 CONTINUE\nc\nc set upper limit for vector m subscript\nc\n MMAX = MIN0(NLAT, (NLON+1)/2)\nc\nc compute multiple scalar field coefficients\nc\n DO 2 K = 1,NT\nc\nc preset to 0.0\nc\n DO 3 N = 1,NLAT\n DO 4 M = 1,MAB\n A(M,N,K) = 0.0D0\n B(M,N,K) = 0.0D0\n 4 CONTINUE\n 3 CONTINUE\nc\nc compute m=0 coefficients\nc\n DO 5 N = 2,NLAT\n A(1,N,K) = BR(1,N,K)*SQNN(N)\n B(1,N,K) = BI(1,N,K)*SQNN(N)\n 5 CONTINUE\nc\nc compute m>0 coefficients\nc\n DO 6 M = 2,MMAX\n DO 7 N = M,NLAT\n A(M,N,K) = SQNN(N)*BR(M,N,K)\n B(M,N,K) = SQNN(N)*BI(M,N,K)\n 7 CONTINUE\n 6 CONTINUE\n 2 CONTINUE\nc\nc scalar sythesize a,b into sf\nc\n CALL DSHSGC(NLAT,NLON,ISYM,NT,SF,ISF,JSF,A,B,MAB,NLAT,WSAV,LSAV,\n + WK,LWK,IERROR)\n RETURN\n END\n", "meta": {"hexsha": "891cbd6d131307fbead6ccecc8a8f30a2a21a7f7", "size": 13216, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "external/sphere3.1_dp/igradgc.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "external/sphere3.1_dp/igradgc.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "external/sphere3.1_dp/igradgc.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 36.7111111111, "max_line_length": 78, "alphanum_fraction": 0.559246368, "num_tokens": 4117, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802417938535, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6880218046262987}} {"text": "!---------------------------------------------------!\n! Copyright (c) 2017 Shunsuke A. Sato !\n! Released under the MIT license !\n! https://opensource.org/licenses/mit-license.php !\n!---------------------------------------------------!\n!-------10--------20--------30--------40--------50--------60--------70--------80--------90\nsubroutine set_ddeps_dkz\n use global_variables\n implicit none\n integer :: ikr,ikz\n\n select case(nband_type)\n case(N_PARABOLIC_BAND)\n!$omp parallel do private(ikz, ikr)\n do ikz = -NKz,NKz\n do ikr = 1,NKr\n ddeps_dkz(ikr,ikz) = kz(ikz)/mass_r\n end do\n end do\n case(N_NONPARABOLIC_BAND)\n!$omp parallel do private(ikz, ikr)\n do ikz = -NKz,NKz\n do ikr = 1,NKr\n ddeps_dkz(ikr,ikz)=kz(ikz)/mass_r/sqrt(1d0+(kr(ikr)**2+kz(ikz)**2)/(mass_r*eps_g)) \n end do\n end do\n case default\n write(*,\"(A,2x,A)\")\"Invalid nband_type\",nband_type\n stop\n end select\n\n\nend subroutine set_ddeps_dkz\n", "meta": {"hexsha": "c97aeab760510bc226789a54fe8919728a7d99e8", "size": 991, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/preparation/set_ddeps_dkz.f90", "max_stars_repo_name": "shunsuke-sato/two_band_model", "max_stars_repo_head_hexsha": "27653b364b8f08f12eaa273a094c15f7154bdfc9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-07-12T15:46:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T11:32:46.000Z", "max_issues_repo_path": "src/preparation/set_ddeps_dkz.f90", "max_issues_repo_name": "shunsuke-sato/two_band_model", "max_issues_repo_head_hexsha": "27653b364b8f08f12eaa273a094c15f7154bdfc9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-09T02:08:03.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-09T02:20:22.000Z", "max_forks_repo_path": "src/preparation/set_ddeps_dkz.f90", "max_forks_repo_name": "shunsuke-sato/two_band_model", "max_forks_repo_head_hexsha": "27653b364b8f08f12eaa273a094c15f7154bdfc9", "max_forks_repo_licenses": ["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.1470588235, "max_line_length": 91, "alphanum_fraction": 0.5247225025, "num_tokens": 315, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802373309982, "lm_q2_score": 0.7490872131147276, "lm_q1q2_score": 0.688021801283231}} {"text": "MODULE PS7PARA\n IMPLICIT NONE\n REAL(KIND=8), PARAMETER:: BETA=0.99, SIGMA=1, ALPHA=0.36\n INTEGER, PARAMETER:: NK=40, NAK=40\n INTEGER:: I\n REAL(KIND=8), PARAMETER:: K_MIN=0.01, K_MAX=0.5, STEP=(0.5-0.01)/FLOAT(NK-1)\n REAL(KIND=8), DIMENSION(NK), PARAMETER:: K_GRID=(/(I*STEP, I=1, NK)/) +K_MIN - STEP\n REAL(KIND=8), PARAMETER:: KBAR_MIN=0.15, KBAR_MAX=0.25, BAR_STEP=0.1/FLOAT(NAK-1)\n REAL(KIND=8), DIMENSION(NAK), PARAMETER:: AK_GRID=(/(I*BAR_STEP, I=1, NAK)/) +KBAR_MIN - BAR_STEP\n REAL(KIND=8):: A0=0.01, A1=0.99\n REAL(KIND=8), PARAMETER:: CRIT=1E-3\nEND MODULE\n\nMODULE PS7RES\n USE PS7PARA\n IMPLICIT NONE\n REAL(KIND=8), DIMENSION(NAK):: INTEREST, WAGE\n INTEGER, DIMENSION(NK, NAK):: PFUNC\n REAL(KIND=8), DIMENSION(NK, NAK):: VFUNC, VFUNC_NEW\n REAL(KIND=8), DIMENSION(NK):: KPR_EST\n REAL(KIND=8), DIMENSION(NK, NAK, NK):: UTIL, CONSUM\n CONTAINS\n SUBROUTINE INIT_RW()\n DO I=1, NAK\n INTEREST(I)= ALPHA*(AK_GRID(I)**(ALPHA-1.))\n WAGE(I)= (1.-ALPHA)*(AK_GRID(I)**ALPHA)\n ENDDO\n END SUBROUTINE\nEND MODULE\n\nPROGRAM PS7\n USE PS7PARA\n USE PS7RES\n USE OMP_LIB\n IMPLICIT NONE\n INTEGER:: KIDX, AKIDX, KPIDX\n REAL(KIND=8):: ERROR_VFI\n\n CALL INIT_RW()\n\n ! FOR PARALLEL CALCULATION, REDUCE PRIVATE VARIABLES IN MAIN LOOP\n ! PRE CALCULATE THE KPR, CONSUM, UTILTIY\n DO AKIDX=1,NAK\n KPR_EST(AKIDX) = AK_GRID(AKIDX) ! NO MOTION\n PRINT*, KPR_EST(AKIDX)\n ENDDO\n\n UTIL = -1e12\n !$OMP PARALLEL DO DEFAULT(SHARED) PRIVATE(AKIDX, KIDX, KPIDX)\n DO AKIDX=1,NAK\n DO KIDX=1,NK\n DO KPIDX=1,NK ! NEXT PERIOD K CHOICE\n CONSUM(KIDX, AKIDX, KPIDX) = (INTEREST(AKIDX))*K_GRID(KIDX)&\n +WAGE(AKIDX)-K_GRID(KPIDX)\n IF (CONSUM(KIDX, AKIDX, KPIDX)>0.) THEN\n UTIL(KIDX, AKIDX, KPIDX)= LOG(CONSUM(KIDX, AKIDX, KPIDX))\n ENDIF\n ENDDO\n ENDDO\n ENDDO\n !$OMP END PARALLEL DO\n\n ERROR_VFI = 100.\n DO AKIDX=1,NAK ! INIT VALUE\n DO KIDX=1,NK\n VFUNC(KIDX, AKIDX)= MAXVAL(UTIL(KIDX, AKIDX, :),1)\n ENDDO\n ENDDO\n DO WHILE (ERROR_VFI > CRIT)\n CALL VFI()\n ERROR_VFI = MAXVAL(ABS(VFUNC-VFUNC_NEW))\n VFUNC = VFUNC_NEW\n ENDDO\n\n CALL WRITE_ALL()\nEND PROGRAM PS7\n\nSUBROUTINE VFI()\n USE PS7PARA\n USE PS7RES\n USE OMP_LIB\n IMPLICIT NONE\n INTEGER:: AKIDX, KIDX, KPIDX\n REAL(KIND=8), DIMENSION(1):: NEXTU, KPR, SMALL_KPR\n REAL(KIND=8), DIMENSION(NK, NAK, NK):: VFUNC_TMP\n\n\n !$OMP PARALLEL DO DEFAULT(SHARED) PRIVATE(AKIDX, KIDX, KPIDX)\n DO AKIDX=1,NAK\n KPR(1) = KPR_EST(AKIDX)\n DO KIDX=1,NK\n DO KPIDX=1,NK ! NEXT PERIOD K CHOICE\n SMALL_KPR(1) = K_GRID(KPIDX)\n CALL PWL_INTERP_2D(NK, NAK, K_GRID, AK_GRID, VFUNC, 1, SMALL_KPR, KPR, NEXTU)\n IF (NEXTU(1)>1E10 .OR. -1E10>NEXTU(1)) THEN\n PRINT*, SMALL_KPR(1),KPR(1), AK_GRID(NAK), K_GRID(NK),AK_GRID(1), K_GRID(1)\n ENDIF\n VFUNC_TMP(KIDX, AKIDX, KPIDX) = UTIL(KIDX, AKIDX, KPIDX)+BETA*NEXTU(1)\n ENDDO\n VFUNC_NEW(KIDX, AKIDX) = MAXVAL(VFUNC_TMP(KIDX, AKIDX, :),1)\n PFUNC(KIDX,AKIDX) = MAXLOC(VFUNC_TMP(KIDX, AKIDX, :),1)\n ENDDO\n ENDDO\n !$OMP END PARALLEL DO\nEND SUBROUTINE\n\nsubroutine pwl_interp_2d ( nxd, nyd, xd, yd, zd, ni, xi, yi, zi )\n\n!*****************************************************************************80\n!\n!! PWL_INTERP_2D: piecewise linear interpolant to data defined on a 2D grid.\n!\n! Discussion:\n!\n! Thanks to Adam Hirst for pointing out an error in the formula that\n! chooses the interpolation triangle, 04 February 2018.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 04 February 2018\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) NXD, NYD, the number of X and Y data values.\n!\n! Input, real ( kind = 8 ) XD(NXD), YD(NYD), the sorted X and Y data.\n!\n! Input, real ( kind = 8 ) ZD(NXD,NYD), the Z data.\n!\n! Input, integer ( kind = 4 ) NI, the number of interpolation points.\n!\n! Input, real ( kind = 8 ) XI(NI), YI(NI), the coordinates of the\n! interpolation points.\n!\n! Output, real ( kind = 8 ) ZI(NI), the value of the interpolant.\n!\n implicit none\n\n integer ( kind = 4 ):: ni\n integer ( kind = 4 ):: nxd\n integer ( kind = 4 ):: nyd\n\n real ( kind = 8 ):: alpha1\n real ( kind = 8 ):: beta1\n real ( kind = 8 ):: det\n real ( kind = 8 ):: dxa\n real ( kind = 8 ):: dxb\n real ( kind = 8 ):: dxi\n real ( kind = 8 ):: dya\n real ( kind = 8 ):: dyb\n real ( kind = 8 ):: dyi\n real ( kind = 8 ):: gamma\n integer ( kind = 4 ):: i1\n integer ( kind = 4 ):: j\n integer ( kind = 4 ):: k\n real ( kind = 8 ):: r8_huge= 1.79769313486231571D+308\n integer ( kind = 4 ):: r8vec_bracket5\n real ( kind = 8 ):: xd(nxd)\n real ( kind = 8 ):: xi(ni)\n real ( kind = 8 ):: yd(nyd)\n real ( kind = 8 ):: yi(ni)\n real ( kind = 8 ):: zd(nxd,nyd)\n real ( kind = 8 ):: zi(ni)\n\n do k = 1, ni\n!\n! For interpolation point (xi(k),yi(k)), find data intervals I and J so that:\n!\n! xd(i) <= xi(k) <= xd(i+1),\n! yd(j) <= yi(k) <= yd(j+1).\n!\n! But if the interpolation point is not within a data interval,\n! assign the dummy interpolant value zi(k) = infinity.\n!\n i1 = r8vec_bracket5 ( nxd, xd, xi(k) )\n if ( i1 == -1 ) then\n zi(k) = r8_huge\n cycle\n end if\n\n j = r8vec_bracket5 ( nyd, yd, yi(k) )\n if ( j == -1 ) then\n zi(k) = r8_huge\n cycle\n end if\n!\n! The rectangular cell is arbitrarily split into two triangles.\n! The linear interpolation formula depends on which triangle\n! contains the data point.\n!\n! (I,J+1)--(I+1,J+1)\n! |\\ |\n! | \\ |\n! | \\ |\n! | \\ |\n! | \\ |\n! | \\ |\n! (I,J)---(I+1,J)\n!\n if ( yi(k) < yd(j+1) &\n + ( yd(j) - yd(j+1) ) * ( xi(k) - xd(i1) ) / ( xd(i1+1) - xd(i1) ) ) then\n\n dxa = xd(i1+1) - xd(i1)\n dya = yd(j) - yd(j)\n\n dxb = xd(i1) - xd(i1)\n dyb = yd(j+1) - yd(j)\n\n dxi = xi(k) - xd(i1)\n dyi = yi(k) - yd(j)\n\n det = dxa * dyb - dya * dxb\n\n alpha1 = ( dxi * dyb - dyi * dxb ) / det\n beta1 = ( dxa * dyi - dya * dxi ) / det\n gamma = 1.0D+00 - alpha1 - beta1\n\n zi(k) = alpha1 * zd(i1+1,j) + beta1 * zd(i1,j+1) + gamma * zd(i1,j)\n\n else\n\n dxa = xd(i1) - xd(i1+1)\n dya = yd(j+1) - yd(j+1)\n\n dxb = xd(i1+1) - xd(i1+1)\n dyb = yd(j) - yd(j+1)\n\n dxi = xi(k) - xd(i1+1)\n dyi = yi(k) - yd(j+1)\n\n det = dxa * dyb - dya * dxb\n\n alpha1 = ( dxi * dyb - dyi * dxb ) / det\n beta1 = ( dxa * dyi - dya * dxi ) / det\n gamma = 1.0D+00 - alpha1 - beta1\n\n zi(k) = alpha1 * zd(i1,j+1) + beta1 * zd(i1+1,j) + gamma * zd(i1+1,j+1)\n\n end if\n end do\nend subroutine\n\nfunction r8vec_bracket5 ( nd, xd, xi )\n\n!*****************************************************************************80\n!\n!! R8VEC_BRACKET5 brackets data between successive entries of a sorted R8VEC.\n!\n! Discussion:\n!\n! We assume XD is sorted.\n!\n! If XI is contained in the interval [XD(1),XD(N)], then the returned\n! value B indicates that XI is contained in [ XD(B), XD(B+1) ].\n!\n! If XI is not contained in the interval [XD(1),XD(N)], then B = -1.\n!\n! This code implements a version of binary search which is perhaps more\n! understandable than the usual ones.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 14 October 2012\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) ND, the number of data values.\n!\n! Input, real ( kind = 8 ) XD(N), the sorted data.\n!\n! Input, real ( kind = 8 ) XD, the query value.\n!\n! Output, integer ( kind = 4 ) R8VEC_BRACKET5, the bracket information.\n!\n implicit none\n\n integer ( kind = 4 ) nd\n\n integer ( kind = 4 ) b\n integer ( kind = 4 ) l\n integer ( kind = 4 ) m\n integer ( kind = 4 ) r\n integer ( kind = 4 ) r8vec_bracket5\n real ( kind = 8 ) xd(nd)\n real ( kind = 8 ) xi\n\n if ( xi < xd(1) .or. xd(nd) < xi ) then\n\n b = -1\n\n else\n\n l = 1\n r = nd\n\n do while ( l + 1 < r )\n m = ( l + r ) / 2\n if ( xi < xd(m) ) then\n r = m\n else\n l = m\n end if\n end do\n\n b = l\n\n end if\n\n r8vec_bracket5 = b\n\n return\nend\n\nSUBROUTINE WRITE_ALL()\n USE PS7RES\n USE PS7PARA\n IMPLICIT NONE\n INTEGER:: SROWIDX\n CHARACTER(LEN=130):: PATH=\"/Users/chek_choi/Downloads/fortran/\"\n CHARACTER(LEN=150):: FILE_NAME\n REAL(KIND=8), DIMENSION(1):: NEXTU, SMALL_KPR\n\n FILE_NAME = TRIM(PATH)//\"VFUNC\"\n OPEN(UNIT=1, FILE=FILE_NAME, STATUS='REPLACE') ! START WITH THE TWO VALUE FUNCTIONS\n DO SROWIDX=1, NAK\n WRITE(UNIT=1,FMT=*) VFUNC(16,SROWIDX)\n ENDDO\n CLOSE(UNIT=1)\n\n FILE_NAME = TRIM(PATH)//\"VFUNC_SS\"\n SMALL_KPR(1) = 0.1995\n OPEN(UNIT=3, FILE=FILE_NAME, STATUS='REPLACE') ! START WITH THE TWO VALUE FUNCTIONS\n DO SROWIDX=1, NAK\n CALL PWL_INTERP_2D(NK, NAK, K_GRID, AK_GRID, VFUNC, 1, SMALL_KPR, AK_GRID(SROWIDX), NEXTU)\n IF (NEXTU(1)> 1E12) THEN\n PRINT*, AK_GRID(SROWIDX), K_GRID(NK), AK_GRID(NAK)\n ENDIF\n WRITE(UNIT=3,FMT=*) NEXTU(1)\n ENDDO\n CLOSE(UNIT=3)\n\n FILE_NAME = TRIM(PATH)//\"PFUNC\"\n OPEN(UNIT=2, FILE=FILE_NAME, STATUS='REPLACE') ! ALSO SAVE POLICY FUNCTIONS\n DO SROWIDX=1, NK\n WRITE(UNIT=2,FMT=*) K_GRID(PFUNC(SROWIDX,NAK/2))\n ENDDO\n CLOSE(UNIT=2)\n\n FILE_NAME = TRIM(PATH)//\"KGRID\"\n OPEN(UNIT=4, FILE=FILE_NAME, STATUS='REPLACE') ! ALSO SAVE POLICY FUNCTIONS\n DO SROWIDX=1, NAK\n WRITE(UNIT=4,FMT=*) K_GRID(SROWIDX)\n ENDDO\n CLOSE(UNIT=4)\n\n\nEND SUBROUTINE\n\n", "meta": {"hexsha": "51ed105266998a74b756462e67e4b2651caef35f", "size": 9921, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "ps7.f95", "max_stars_repo_name": "hkchekc/EconComputations", "max_stars_repo_head_hexsha": "83f804b6f3b9d1b18a242389a64e6e9b970168b0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ps7.f95", "max_issues_repo_name": "hkchekc/EconComputations", "max_issues_repo_head_hexsha": "83f804b6f3b9d1b18a242389a64e6e9b970168b0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-10-05T08:42:15.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-05T08:42:15.000Z", "max_forks_repo_path": "ps7.f95", "max_forks_repo_name": "hkchekc/EconComputations", "max_forks_repo_head_hexsha": "83f804b6f3b9d1b18a242389a64e6e9b970168b0", "max_forks_repo_licenses": ["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.456, "max_line_length": 102, "alphanum_fraction": 0.5527668582, "num_tokens": 3612, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802484881361, "lm_q2_score": 0.7490872019117029, "lm_q1q2_score": 0.6880217993511435}} {"text": " PROGRAM max_min\n IMPLICIT NONE\n\n INTEGER (KIND=8),PARAMETER::nH=100,nS=2000\n INTEGER (KIND=8),PARAMETER::N=10000\n REAL (KIND=8),PARAMETER:: Jmp=0.44\n REAL (KIND=8),PARAMETER:: Jc=1./2.28, H0=0.43\n REAL (KIND=8),PARAMETER:: Smin=-1.,Smax=1,z=4.\n\n INTEGER (KIND=8) :: i,iS\n REAL (KIND=8) :: T,J,S,delS,JMF\n \n REAL (KIND=8),DIMENSION(nS) :: Smp,P,F,FMF\n\n!!!=======================================================================================\n!!!======================================================================================= \n\n!!!! =====================================================================================\n!!! F by mean field\n\n OPEN(13,file='FMF.dat')\n\n !JMF=(1./z/Jc)*Jmp\n JMF=1.1/z\n \n WRITE(*,*)'JMF=',JMF\n\n IF (nS==1) THEN\n delS=0.\n ELSE\n delS=(Smax-Smin)/real(nS)\n END IF\n\n \n DO iS=1,nS\n S=Smin+delS*real(iS-0.5)\n\n !FMF=-0.5*z*JMF*S*S + S*(1.+exp(-2.*S))/(1.-exp(-2.*S))+0.5*log(1.-S*S)\n \n !FMF=-0.5*z*JMF*S*S + S*(exp(S)+exp(-S))/(exp(S)-exp(-S))+0.5*log(1.-(S*S))\n \n FMF(iS)=-0.5*z*JMF*S*S + S*0.5*log((1.+S)/(1.-S))+0.5*log(1.-(S*S))\n \n !FMF(iS)=-log(2.)+0.5*(1.-z*JMF)*S*S+(1./12.)*(S**4.)\n\n WRITE(13,*)S,FMF(iS) \n END DO\n\n\n!!!! =====================================================================================\n!!! F by numerical method\n\n\n!!! Doc gia tri\n OPEN(unit=11,file='P044.txt')\n OPEN(unit=12,file='F.dat')\n\n DO i=1,nS\n READ(11,*)T,J,Smp(i),P(i)\n\n F(i)=log(P(i))/real(N) \n\n END DO \n \n DO i=1,nS\n !!WRITE(12,*)Smp(i)/N,F(i)*FMF(1001)/F(1001)\n \n WRITE(12,*)Smp(i)/N,F(i)\n END DO \n \n\n CLOSE(11)\n CLOSE(12)\n \n END PROGRAM max_min\n\n", "meta": {"hexsha": "1d3054e2c1a028d02d647ea8d1b51d2e8cdc5d9e", "size": 1734, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Simulation Result/0FMF_Calculation_2015.04.11/0.450_J/F_MF.f90", "max_stars_repo_name": "danhtaihoang/irreversible-entropy-production", "max_stars_repo_head_hexsha": "e3cc8615712d18ac63b6ee7b7947eeaa0f748e60", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Simulation Result/0FMF_Calculation_2015.04.11/0.450_J/F_MF.f90", "max_issues_repo_name": "danhtaihoang/irreversible-entropy-production", "max_issues_repo_head_hexsha": "e3cc8615712d18ac63b6ee7b7947eeaa0f748e60", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Simulation Result/0FMF_Calculation_2015.04.11/0.450_J/F_MF.f90", "max_forks_repo_name": "danhtaihoang/irreversible-entropy-production", "max_forks_repo_head_hexsha": "e3cc8615712d18ac63b6ee7b7947eeaa0f748e60", "max_forks_repo_licenses": ["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.5194805195, "max_line_length": 91, "alphanum_fraction": 0.3892733564, "num_tokens": 626, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009596336303, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6880170304742541}} {"text": "subroutine lca(basis, stimuli, eta, lamb, nIter, softThresh, adapt, s, u, thresh, nBasis, nStimuli, length)\n implicit none\n!\n! Inputs\n!\n integer, parameter :: dp = KIND(1.0d0)\n integer, parameter :: li = SELECTED_INT_KIND(8)\n real(dp), parameter :: alpha = 1.0\n real(dp), parameter :: beta = 0.0\n integer(li), intent(in) :: nIter, softThresh, nBasis, nStimuli, length\n real(dp), intent(in), dimension(0:nBasis-1, 0:length-1) :: basis\n real(dp), intent(in), dimension(0:nStimuli-1, 0:length-1) :: stimuli\n real(dp), intent(in) :: eta, lamb, adapt\n!\n! Outputs\n!\n real(dp), intent(inout), dimension(0:nStimuli-1, 0:nBasis-1) :: u\n !f2py intent(inout) :: u\n real(dp), intent(inout), dimension(0:nStimuli-1, 0:nBasis-1) :: s\n !f2py intent(inout) :: s\n real(dp), intent(inout), dimension(0:nStimuli-1) :: thresh\n !f2py intent(inout) :: thresh\n\n real(dp), dimension(0:nStimuli-1, 0:nBasis-1) :: b, ci\n real(dp), dimension(0:nBasis-1,0:nBasis-1) :: c\n integer(li) :: ii,jj,kk\n\n external :: DGEMM, DSYMM\n real(dp), external :: DDOT\n\n call DGEMM(\"n\",\"t\",nBasis,nBasis,length,alpha,basis,nBasis,basis,nBasis,beta,c,nBasis)\n do ii=0,nbasis-1\n c(ii,ii) = 0.0\n end do\n call DGEMM(\"n\",\"t\",nStimuli,nBasis,length,alpha,stimuli,nStimuli,basis,nBasis,beta,b,nStimuli)\n do ii=0,nStimuli-1\n do jj=0,nBasis-1\n thresh(ii) = thresh(ii)+ABS(b(ii,jj))\n end do\n thresh(ii) = thresh(ii)/nBasis\n end do\n do jj=0,nIter-1\n call DSYMM(\"r\",\"l\",nStimuli,nBasis,alpha,c,nBasis,s,nStimuli,beta,ci,nStimuli)\n u = eta*(b-ci)+(1-eta)*u\n do kk=0,nBasis-1\n do ii=0,nStimuli-1\n if ((u(ii,kk) < thresh(ii)) .and. (u(ii,kk) > -thresh(ii))) then\n s(ii,kk) = 0.\n else if (softThresh .eq. 1) then\n s(ii,kk) = u(ii,kk)-sign(u(ii,kk),u(ii,kk))*thresh(ii)\n else\n s(ii,kk) = u(ii,kk)\n end if\n end do\n end do\n do ii=0,nStimuli-1\n if (thresh(ii) > lamb) then\n thresh(ii) = adapt*thresh(ii)\n end if\n end do\n end do\nend subroutine\n\n", "meta": {"hexsha": "86c0a2bbe4f8e9827e4ad9f8d4e455f69ea2304b", "size": 2065, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "LCAfortran/lca.f90", "max_stars_repo_name": "asudeeaydin/LCAversions", "max_stars_repo_head_hexsha": "dd4c8abfabc45ac8af61647e48d8b115042af4fb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-04-04T16:58:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T00:08:07.000Z", "max_issues_repo_path": "LCAfortran/lca.f90", "max_issues_repo_name": "dlacombejr/LCAversions", "max_issues_repo_head_hexsha": "c5416cb532f0be3d93b1739d845340936ec8a36b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2015-02-23T20:29:36.000Z", "max_issues_repo_issues_event_max_datetime": "2015-02-23T22:03:21.000Z", "max_forks_repo_path": "LCAfortran/lca.f90", "max_forks_repo_name": "dlacombejr/LCAversions", "max_forks_repo_head_hexsha": "c5416cb532f0be3d93b1739d845340936ec8a36b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-04-04T16:57:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-11T20:42:49.000Z", "avg_line_length": 32.265625, "max_line_length": 107, "alphanum_fraction": 0.603874092, "num_tokens": 789, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009596336303, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6880170304742541}} {"text": " SUBROUTINE broydn(x,n,check)\r\n INTEGER n,nn,NP,MAXITS\r\n REAL x(n),fvec,EPS,TOLF,TOLMIN,TOLX,STPMX\r\n LOGICAL check\r\n PARAMETER (NP=40,MAXITS=200,EPS=1.e-7,TOLF=1.e-4,TOLMIN=1.e-6,\r\n *TOLX=EPS,STPMX=100.)\r\n COMMON /newtv/ fvec(NP),nn\r\nCU USES fdjac,fmin,lnsrch,qrdcmp,qrupdt,rsolv\r\n INTEGER i,its,j,k\r\n REAL den,f,fold,stpmax,sum,temp,test,c(NP),d(NP),fvcold(NP),g(NP),\r\n *p(NP),qt(NP,NP),r(NP,NP),s(NP),t(NP),w(NP),xold(NP),fmin\r\n LOGICAL restrt,sing,skip\r\n EXTERNAL fmin\r\n nn=n\r\n f=fmin(x)\r\n test=0.\r\n do 11 i=1,n\r\n if(abs(fvec(i)).gt.test)test=abs(fvec(i))\r\n11 continue\r\n if(test.lt..01*TOLF)then\r\n check=.false.\r\n return\r\n endif\r\n sum=0.\r\n do 12 i=1,n\r\n sum=sum+x(i)**2\r\n12 continue\r\n stpmax=STPMX*max(sqrt(sum),float(n))\r\n restrt=.true.\r\n do 44 its=1,MAXITS\r\n if(restrt)then\r\n call fdjac(n,x,fvec,NP,r)\r\n call qrdcmp(r,n,NP,c,d,sing)\r\n if(sing) pause 'singular Jacobian in broydn'\r\n do 14 i=1,n\r\n do 13 j=1,n\r\n qt(i,j)=0.\r\n13 continue\r\n qt(i,i)=1.\r\n14 continue\r\n do 18 k=1,n-1\r\n if(c(k).ne.0.)then\r\n do 17 j=1,n\r\n sum=0.\r\n do 15 i=k,n\r\n sum=sum+r(i,k)*qt(i,j)\r\n15 continue\r\n sum=sum/c(k)\r\n do 16 i=k,n\r\n qt(i,j)=qt(i,j)-sum*r(i,k)\r\n16 continue\r\n17 continue\r\n endif\r\n18 continue\r\n do 21 i=1,n\r\n r(i,i)=d(i)\r\n do 19 j=1,i-1\r\n r(i,j)=0.\r\n19 continue\r\n21 continue\r\n else\r\n do 22 i=1,n\r\n s(i)=x(i)-xold(i)\r\n22 continue\r\n do 24 i=1,n\r\n sum=0.\r\n do 23 j=i,n\r\n sum=sum+r(i,j)*s(j)\r\n23 continue\r\n t(i)=sum\r\n24 continue\r\n skip=.true.\r\n do 26 i=1,n\r\n sum=0.\r\n do 25 j=1,n\r\n sum=sum+qt(j,i)*t(j)\r\n25 continue\r\n w(i)=fvec(i)-fvcold(i)-sum\r\n if(abs(w(i)).ge.EPS*(abs(fvec(i))+abs(fvcold(i))))then\r\n skip=.false.\r\n else\r\n w(i)=0.\r\n endif\r\n26 continue\r\n if(.not.skip)then\r\n do 28 i=1,n\r\n sum=0.\r\n do 27 j=1,n\r\n sum=sum+qt(i,j)*w(j)\r\n27 continue\r\n t(i)=sum\r\n28 continue\r\n den=0.\r\n do 29 i=1,n\r\n den=den+s(i)**2\r\n29 continue\r\n do 31 i=1,n\r\n s(i)=s(i)/den\r\n31 continue\r\n call qrupdt(r,qt,n,NP,t,s)\r\n do 32 i=1,n\r\n if(r(i,i).eq.0.) pause 'r singular in broydn'\r\n d(i)=r(i,i)\r\n32 continue\r\n endif\r\n endif\r\n do 34 i=1,n\r\n sum=0.\r\n do 33 j=1,n\r\n sum=sum+qt(i,j)*fvec(j)\r\n33 continue\r\n g(i)=sum\r\n34 continue\r\n do 36 i=n,1,-1\r\n sum=0.\r\n do 35 j=1,i\r\n sum=sum+r(j,i)*g(j)\r\n35 continue\r\n g(i)=sum\r\n36 continue\r\n do 37 i=1,n\r\n xold(i)=x(i)\r\n fvcold(i)=fvec(i)\r\n37 continue\r\n fold=f\r\n do 39 i=1,n\r\n sum=0.\r\n do 38 j=1,n\r\n sum=sum+qt(i,j)*fvec(j)\r\n38 continue\r\n p(i)=-sum\r\n39 continue\r\n call rsolv(r,n,NP,d,p)\r\n call lnsrch(n,xold,fold,g,p,x,f,stpmax,check,fmin)\r\n test=0.\r\n do 41 i=1,n\r\n if(abs(fvec(i)).gt.test)test=abs(fvec(i))\r\n41 continue\r\n if(test.lt.TOLF)then\r\n check=.false.\r\n return\r\n endif\r\n if(check)then\r\n if(restrt)then\r\n return\r\n else\r\n test=0.\r\n den=max(f,.5*n)\r\n do 42 i=1,n\r\n temp=abs(g(i))*max(abs(x(i)),1.)/den\r\n if(temp.gt.test)test=temp\r\n42 continue\r\n if(test.lt.TOLMIN)then\r\n return\r\n else\r\n restrt=.true.\r\n endif\r\n endif\r\n else\r\n restrt=.false.\r\n test=0.\r\n do 43 i=1,n\r\n temp=(abs(x(i)-xold(i)))/max(abs(x(i)),1.)\r\n if(temp.gt.test)test=temp\r\n43 continue\r\n if(test.lt.TOLX)return\r\n endif\r\n44 continue\r\n pause 'MAXITS exceeded in broydn'\r\n END\r\n", "meta": {"hexsha": "754cedb871961eb134e1d05dc6121876f7d2287f", "size": 4561, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/broydn.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/broydn.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/broydn.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": 26.6725146199, "max_line_length": 73, "alphanum_fraction": 0.4091208068, "num_tokens": 1379, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009526726544, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6880170252395126}} {"text": "module utility_interpolate\n\n use define_indexes\n use define_indexes\n use define_keys\n use define_globals\n use define_settings\n use utility_allocate\n\n implicit none\n\n public :: util_curve_lookup_singular\n public :: util_interpolate_linear\n\n private\n\ncontains\n!% \n!%==========================================================================\n!%==========================================================================\n!%\n\n real(8) function util_interpolate_linear(X, X1, X2, Y1, Y2) result (Y)\n !% This is a linear interpolation function\n real(8), intent(in) :: X, X1, X2, Y1, Y2\n if (Y1 == Y2) then\n Y = Y1\n return\n end if\n Y = Y1 + (X - X1) * (Y2 - Y1) / (X2 - X1)\n end function util_interpolate_linear\n!% \n!%==========================================================================\n!%==========================================================================\n!%\n subroutine util_curve_lookup_singular(curveID, er_inCol, er_outCol, &\n xVal_col, yVal_col)\n !%-----------------------------------------------------------------------------\n !% Description:\n !% look up from a curve and returns a interpolated value\n !% Inputs/Outputs:\n !% curveID\n !% er_inCol\n !% er_outCol\n !% xVal_col\n !% yVal_col \n !%-----------------------------------------------------------------------------\n integer, intent(in) :: curveID, er_inCol, er_outCol, xVal_col, yVal_col\n real(8), pointer :: x, y\n integer, pointer :: nRows, ElemIdx\n real(8) :: x1, x2, y1, y2, slope\n integer :: ii\n\n character(64) :: subroutine_name = 'util_curve_lookup_singular'\n !%-----------------------------------------------------------------------------\n !% pointers:\n ElemIdx => curve(curveID)%ElemIdx\n nRows => curve(curveID)%NumRows\n x => elemR(ElemIdx,er_inCol)\n y => elemR(ElemIdx,er_outCol)\n\n x1 = curve(curveID)%ValueArray(1,xVal_col)\n y1 = curve(curveID)%ValueArray(1,yVal_col)\n\n !% check if inVal is smaller than the first table entry\n if (x <= x1) then\n if (x1 > zeroR) then\n y = x/x1*y1\n return\n else\n y = y1\n return\n end if\n end if\n\n !% else loop through the table to find the position and interpolate\n do ii = 2,nRows\n x2 = curve(curveID)%ValueArray(ii,xVal_col)\n y2 = curve(curveID)%ValueArray(ii,yVal_col)\n if (x2 /= x1) slope = (y2 - y1) / (x2 - x1)\n\n if (x <= x2) then\n y = util_interpolate_linear(x, x1, x2, y1, y2)\n return\n end if\n x1 = x2\n y1 = y2\n if (slope < zeroR) slope = zeroR \n y = y1 + slope * (x - x1)\n end do\n\n end subroutine util_curve_lookup_singular\n!% \n!%==========================================================================\n!%==========================================================================\n!%\nend module utility_interpolate", "meta": {"hexsha": "4e5d04b31c3b86942152538dcdc264b3c7f9178a", "size": 3215, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "utility/utility_interpolate.f90", "max_stars_repo_name": "CIMM-ORG/SWMM5plus", "max_stars_repo_head_hexsha": "dc81a1fa0fce39ff0011403ebf5e3a19ab9e2215", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2022-01-10T19:27:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-04T04:52:30.000Z", "max_issues_repo_path": "utility/utility_interpolate.f90", "max_issues_repo_name": "CIMM-ORG/SWMM5plus", "max_issues_repo_head_hexsha": "dc81a1fa0fce39ff0011403ebf5e3a19ab9e2215", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-01-25T17:47:15.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-26T15:37:27.000Z", "max_forks_repo_path": "utility/utility_interpolate.f90", "max_forks_repo_name": "CIMM-ORG/SWMM5plus", "max_forks_repo_head_hexsha": "dc81a1fa0fce39ff0011403ebf5e3a19ab9e2215", "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.1443298969, "max_line_length": 87, "alphanum_fraction": 0.4158631415, "num_tokens": 756, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009642742806, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6880170237943625}} {"text": "C\n\tSUBROUTINE ROTATE_X(ANGLE,X_INIT,X_TRANS)\nC\n\tREAL X_INIT(3),X_TRANS(3)\nC\n\tX_TRANS(1)=X_INIT(1)\n\tX_TRANS(2)=X_INIT(2)*COS(ANGLE)+X_INIT(3)*SIN(ANGLE)\n\tX_TRANS(3)=X_INIT(3)*COS(ANGLE)-X_INIT(2)*SIN(ANGLE)\nC\n\tRETURN\n\tEND\n", "meta": {"hexsha": "64802d4fe11424e24dba8ab74a4f11c5fee820e4", "size": 221, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "PyGCPM/__data/libgcpm/xform/Rotate_x.for", "max_stars_repo_name": "mattkjames7/PyGCPM", "max_stars_repo_head_hexsha": "90d1c29b82b7b286f570eb49f7bf7618ddc4717b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "PyGCPM/__data/libgcpm/xform/Rotate_x.for", "max_issues_repo_name": "mattkjames7/PyGCPM", "max_issues_repo_head_hexsha": "90d1c29b82b7b286f570eb49f7bf7618ddc4717b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "PyGCPM/__data/libgcpm/xform/Rotate_x.for", "max_forks_repo_name": "mattkjames7/PyGCPM", "max_forks_repo_head_hexsha": "90d1c29b82b7b286f570eb49f7bf7618ddc4717b", "max_forks_repo_licenses": ["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.4166666667, "max_line_length": 53, "alphanum_fraction": 0.7194570136, "num_tokens": 99, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9149009549929796, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6880170168147075}} {"text": "program matrixMultiplication\n implicit none\n integer, parameter :: n = 30000 ! Parameter N defining size of matrices\n real(kind=8),allocatable::m1(:,:),v1(:),v_res(:) ! Defining 1 matrix that will be allocatated in memory during executions\n ! plus two vectors\n integer(kind=4)::i, j, k ! Iterators\n real::start,finish ! Variables to make timing\n\nallocate(m1(n,n),v1(n),v_res(n)) ! Alocating the matrices based on parameter n\n\n! Filling up vpalues to matrix 1\ndo i = 1, n\n do j = 1, n\n m1(i, j) = i*i*1.7453+j*3.674528 ! This is a \"random\" operation in order not to allow the compiler taking advantage of the matrix value\n end do\nend do\n\n! Filling up values to matrix 2\ndo i = 1, n\n v1(i) = i*i*1.3569875*6.76512 ! This is a \"random\" operation in order not to allow the compiler taking advantage of the matrix value\nend do\n\ncall cpu_time(start) ! Start timing\ndo i = 1, n\n do j = 1, n\n v_res(i) = v_res(i) + (m1(i,j) * v1(j))\n end do\nend do\ncall cpu_time(finish) ! Finish timing\nprint '(\"Time to Row = \",f15.3,\" seconds. Started:\",f6.3,\" - Finished:\",f15.3,\".\")',finish-start,start,finish !Prints the time\n\ncall cpu_time(start) ! Start timing\ndo j = 1, n\n do i = 1, n\n v_res(i) = v_res(i) + (m1(i,j) * v1(j))\n end do\nend do\ncall cpu_time(finish) ! Finish timing\nprint '(\"Time to Column = \",f15.3,\" seconds. Started:\",f6.3,\" - Finished:\",f15.3,\".\")',finish-start,start,finish !Prints the time\n\nprint*, 'Matrix Multiplication: Result Matrix' ! Show a result just to make sure...\n\nprint*, v_res(1), ' ' , v_res(2) , ' ' , v_res(3)\n\nend program matrixMultiplication", "meta": {"hexsha": "2c7debc36f646b6abcbc7d11951f9b58b8624a2c", "size": 1587, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Trabalho 1/fortran/f_matrix.f95", "max_stars_repo_name": "phasath/comp-alto-desempenho-1", "max_stars_repo_head_hexsha": "8c0ec5c7bb4cc1c2e236da65823b6ecf53147017", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Trabalho 1/fortran/f_matrix.f95", "max_issues_repo_name": "phasath/comp-alto-desempenho-1", "max_issues_repo_head_hexsha": "8c0ec5c7bb4cc1c2e236da65823b6ecf53147017", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Trabalho 1/fortran/f_matrix.f95", "max_forks_repo_name": "phasath/comp-alto-desempenho-1", "max_forks_repo_head_hexsha": "8c0ec5c7bb4cc1c2e236da65823b6ecf53147017", "max_forks_repo_licenses": ["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.2666666667, "max_line_length": 139, "alphanum_fraction": 0.6735979836, "num_tokens": 527, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009596336303, "lm_q2_score": 0.7520125626441471, "lm_q1q2_score": 0.6880170152196756}} {"text": "module array_utils\n\n use numeric_kinds, only: dp\n use lapack_wrapper, only: lapack_generalized_eigensolver, lapack_matmul, lapack_matrix_vector, &\n lapack_qr, lapack_solver, lapack_sort\n implicit none\n\n !> \\private\n private\n !> \\public\n public :: concatenate, diagonal,eye, generate_diagonal_dominant, norm, &\n generate_preconditioner\n\ncontains\n\n pure function eye(m, n, alpha)\n !> Create a matrix with ones in the diagonal and zero everywhere else\n !> \\param m: number of rows\n !> \\param n: number of colums\n !> \\param alpha: optional diagonal value\n !> \\return matrix of size n x m\n integer, intent(in) :: n, m\n real(dp), dimension(m, n) :: eye\n real(dp), intent(in), optional :: alpha\n \n !local variable\n integer :: i, j\n real(dp) :: x\n\n ! check optional values\n x = 1.d0\n if (present(alpha)) x = alpha\n \n do i=1, m\n do j=1, n\n if (i /= j) then\n eye(i, j) = 0.d0\n else\n eye(i, i) = x\n end if\n end do\n end do\n \n end function eye\n\n pure function norm(vector)\n !> compute the norm-2 of a vector\n real(dp), dimension(:), intent(in) :: vector\n real(dp) :: norm\n\n norm = sqrt(sum(vector ** 2.d0))\n\n end function norm\n \n subroutine concatenate(arr, brr)\n\n !> Concatenate two matrices\n !> \\param arr: first array\n !> \\param brr: second array\n !> \\return arr concatenate brr (overwrites arr)\n\n real(dp), dimension(:, :), intent(inout), allocatable :: arr\n real(dp), dimension(:, :), intent(in) :: brr\n real(dp), dimension(:, :), allocatable :: tmp_array\n integer :: new_dim, dim_cols, dim_rows\n \n ! dimension\n dim_rows = size(arr, 1)\n dim_cols = size(arr, 2)\n\n ! Number of columns of the new matrix\n new_dim = dim_cols + size(brr, 2)\n\n ! move to temporal array\n allocate(tmp_array(dim_rows, new_dim))\n tmp_array(:, :dim_cols) = arr\n \n ! Move to new expanded matrix\n deallocate(arr)\n call move_alloc(tmp_array, arr)\n\n arr(:, dim_cols + 1:) = brr\n\n end subroutine concatenate\n \n function generate_diagonal_dominant(m, sparsity, diag_val) result(arr)\n !> Generate a diagonal dominant square matrix of dimension m\n !> \\param m dimension of the matrix\n !> \\param sparsity magnitude order of the off-diagonal values\n \n integer, intent(in) :: m ! size of the square matrix\n real(dp), optional :: diag_val\n integer :: i, j\n real(dp) :: sparsity \n real(dp), dimension(m, m) :: arr\n call random_number(arr)\n\n arr = arr * sparsity\n do j=1, m\n do i=1, m\n if (i > j) then\n arr(i, j) = arr(j, i)\n else if(i == j) then\n if (present(diag_val))then\n arr(i,i) = diag_val\n else\n arr(i, i) = i\n end if\n end if\n end do\n end do\n\n end function generate_diagonal_dominant\n\n function diagonal(matrix)\n !> return the diagonal of a matrix\n real(dp), dimension(:, :), intent(in) :: matrix\n real(dp), dimension(size(matrix, 1)) :: diagonal\n\n ! local variables\n integer :: i, j, m\n\n ! dimension of the matrix\n m = size(matrix, 1)\n \n do i=1,m\n do j=1,m\n if (i == j) then\n diagonal(i) = matrix(i, j)\n end if\n end do\n end do\n\n end function diagonal \n\n function generate_preconditioner(diag, dim_sub) result(precond)\n !> \\brief generates a diagonal preconditioner for `matrix`.\n !> \\return diagonal matrix\n\n ! input variable\n real(dp), dimension(:), intent(inout) :: diag\n integer, intent(in) :: dim_sub\n\n ! local variables\n real(dp), dimension(size(diag), dim_sub) :: precond\n integer, dimension(size(diag)) :: keys\n integer :: i, k\n \n ! sort diagonal\n keys = lapack_sort('I', diag)\n ! Fill matrix with zeros\n precond = 0.0_dp\n\n ! Add one depending on the order of the matrix diagonal\n do i=1, dim_sub\n k = search_key(keys, i)\n precond(k, i) = 1.d0\n end do\n \n end function generate_preconditioner\n\n function search_key(keys, i) result(k)\n !> \\brief Search for a given index `i` in a vector `keys`\n !> \\param keys Vector of index\n !> \\param i Index to search for\n !> \\return index of i inside keys\n\n integer, dimension(:), intent(in) :: keys\n integer, intent(in) :: i\n integer :: j, k\n \n do j=1,size(keys)\n if (keys(j) == i) then\n k = j\n exit\n end if\n end do\n\n end function search_key\n \nend module array_utils\n", "meta": {"hexsha": "b242712781a530e5a3d9a1453a49d399c46c961b", "size": 4559, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/array_utils.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/array_utils.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/array_utils.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": 25.0494505495, "max_line_length": 98, "alphanum_fraction": 0.5944286028, "num_tokens": 1280, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951025545426, "lm_q2_score": 0.8152324983301568, "lm_q1q2_score": 0.6879707127841236}} {"text": " SUBROUTINE NON_LINEAR09 (IS, L, M, U, X, Y)\n\n IMPLICIT REAL*8 (A-H, O-Z)\n DIMENSION U(1), X(1), Y(1)\nC\nC Set initial parameters.\nC\n N = 2 ** M\n K = U(1)\n NU = K / 64\n N1 = N / 2\n LK = 2 ** (L - 1)\n LI = 2 ** (M - L)\n LJ = 2 * LI\n KU = LI + 1\n KN = KU + NU\nC\n DO 100 K = 0, LK - 1\n I11 = K * LJ + 1\n I12 = I11 + LI\n I21 = K * LI + 1\n I22 = I21 + N1\nC\nC This loop is vectorizable.\nC\n DO 100 I = 0, LI - 1\n U1 = U(KU+I)\n U2 = IS * U(KN+I)\n X11 = X(I11+I)\n X12 = X(I11+I+N)\n X21 = X(I12+I)\n X22 = X(I12+I+N)\n T1 = X11 - X21\n T2 = X12 - X22\n Y(I21+I) = X11 + X21\n Y(I21+I+N) = X12 + X22\n Y(I22+I) = U1 * T1 - U2 * T2\n Y(I22+I+N) = U1 * T2 + U2 * T1\n 100 CONTINUE\nC\n RETURN\n END\n", "meta": {"hexsha": "5e4cd85b61f73e1844ea5def9da12f3750d0336b", "size": 897, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "packages/PIPS/validation/Semantics/non_linear09.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/Semantics/non_linear09.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/Semantics/non_linear09.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.8604651163, "max_line_length": 49, "alphanum_fraction": 0.3745819398, "num_tokens": 391, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951025545425, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.6879707071016566}} {"text": "PROGRAM SELF_Geometry1D_IO\n\nUSE SELF_Constants\nUSE SELF_Lagrange\nUSE SELF_Mesh\nUSE SELF_Geometry\n\n IMPLICIT NONE\n INTEGER, PARAMETER :: N = 7 ! Polynomial degree of solution\n INTEGER, PARAMETER :: quadrature = GAUSS ! Quadrature\n INTEGER, PARAMETER :: M = 15 ! Number of points in the uniform plotting mesh\n INTEGER, PARAMETER :: nXe = 1 ! Number of elements in the x-direction\n INTEGER, PARAMETER :: nvar = 1 ! The number of tracer fields\n REAL(prec), PARAMETER :: Lx = 1.0_prec ! Length of the domain in the x-direction \n REAL(prec), PARAMETER :: tolerance=10.0_prec*epsilon(1.0_prec) ! Error tolerance\n\n TYPE(Lagrange),TARGET :: interp\n TYPE(Mesh1D),TARGET :: mesh\n TYPE(Geometry1D),TARGET :: geometry\n REAL(prec) :: dxdsExpect\n REAL(prec) :: error\n INTEGER :: i, iEl\n LOGICAL :: fail\n\n\n fail = .FALSE.\n\n ! Create an interpolant\n CALL interp % Init(N,quadrature,M,UNIFORM)\n\n ! Create a uniform block mesh\n CALL mesh % UniformBlockMesh(N,nXe,(/0.0_prec,Lx/))\n\n ! Generate geometry (metric terms) from the mesh elements\n CALL geometry % Init(interp,mesh % nElem)\n CALL geometry % GenerateFromMesh(mesh)\n\n dxdsExpect = 0.5_prec*Lx/REAL(nXe,prec)\n error = 0.0_prec\n DO iEl = 1, mesh % nElem\n DO i = 0, interp % N\n error = MAX(ABS(geometry % dxds % interior % hostData(i,1,iEl)-dxdsExpect),error)\n ENDDO\n ENDDO\n\n IF( error > tolerance )THEN\n 1000 FORMAT('Element interior metric term error max(|dxds-exact|) greater than tolerance : ',E12.5, ' > ', E12.5)\n WRITE(*,1000) error, tolerance \n fail=.TRUE.\n ENDIF\n\n error = 0.0_prec\n DO iEl = 1, mesh % nElem\n error = MAX(ABS(geometry % dxds % boundary % hostData(1,1,iEl)-dxdsExpect),error)\n error = MAX(ABS(geometry % dxds % boundary % hostData(1,2,iEl)-dxdsExpect),error)\n ENDDO\n\n IF( error > tolerance )THEN\n 1001 FORMAT('Element boundary metric term error max(|dxds-exact|) greater than tolerance : ',E12.5, ' > ', E12.5)\n WRITE(*,1001) error, tolerance \n fail=.TRUE.\n ENDIF\n\n CALL geometry % Write()\n CALL geometry % WriteTecplot()\n\n CALL geometry % Free()\n CALL mesh % Free()\n CALL interp % Free()\n\n IF( fail )THEN\n STOP 1\n ENDIF\n\nEND PROGRAM SELF_Geometry1D_IO\n", "meta": {"hexsha": "085cf8da34634d2a3e8945b19f3e80e6ffb5f62c", "size": 2267, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/SELF_Geometry1D_IO.f90", "max_stars_repo_name": "FluidNumerics/self-fluids", "max_stars_repo_head_hexsha": "98293579cd438e51d45ea136eecb930ff54c3f25", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-07-22T15:03:31.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-22T15:03:31.000Z", "max_issues_repo_path": "examples/SELF_Geometry1D_IO.f90", "max_issues_repo_name": "FluidNumerics/self-fluids", "max_issues_repo_head_hexsha": "98293579cd438e51d45ea136eecb930ff54c3f25", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 15, "max_issues_repo_issues_event_min_datetime": "2018-05-30T14:51:15.000Z", "max_issues_repo_issues_event_max_datetime": "2018-07-13T06:06:00.000Z", "max_forks_repo_path": "examples/SELF_Geometry1D_IO.f90", "max_forks_repo_name": "FluidNumerics/SELF-Fluids", "max_forks_repo_head_hexsha": "98293579cd438e51d45ea136eecb930ff54c3f25", "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.8289473684, "max_line_length": 119, "alphanum_fraction": 0.6616674019, "num_tokens": 699, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950868503682, "lm_q2_score": 0.8152324848629214, "lm_q1q2_score": 0.6879706886166366}} {"text": "subroutine relative_vorticity(m,n,o,u,v,deltax,deltay,output_array)\nimplicit none\ninteger :: m,n,o,mone,none\ninteger :: x,y,t\ndouble precision ::deltax(n),deltay\ndouble precision :: u(m,n,o)\ndouble precision :: v(m,n,o)\ndouble precision :: output_array(m,n,o)\ndouble precision :: a\na= 0.5\nmone=m-2\nnone=n-2\ndo t=1,o \n do x=2,mone\n do y=2,none\n output_array(x,y,t) = (-1.00 *a * v(x,y-1,t)/deltax(y)) &\n + (a * v(x,y+1,t)/deltax(y)) &\n - (-1.00 * a * u(x-1,y,t)/deltay) &\n + (a * u(x+1,y,t)/deltay) \t \n end do \n end do \t\nend do \nend subroutine relative_vorticity\n\n", "meta": {"hexsha": "ea6a3adc1c1f148e634063ba95457c275ea85275", "size": 579, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "fortran_subroutines/vorticity.f", "max_stars_repo_name": "ahmathlete/TC_PDFs", "max_stars_repo_head_hexsha": "ed7d0083a20b630df9edfd9188a1a82d4c1101b2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-09-07T15:25:03.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-08T10:39:53.000Z", "max_issues_repo_path": "fortran_subroutines/vorticity.f", "max_issues_repo_name": "ahmathlete/TC_PDFs", "max_issues_repo_head_hexsha": "ed7d0083a20b630df9edfd9188a1a82d4c1101b2", "max_issues_repo_licenses": ["MIT"], "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_subroutines/vorticity.f", "max_forks_repo_name": "ahmathlete/TC_PDFs", "max_forks_repo_head_hexsha": "ed7d0083a20b630df9edfd9188a1a82d4c1101b2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-17T06:26:59.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-17T06:26:59.000Z", "avg_line_length": 23.16, "max_line_length": 67, "alphanum_fraction": 0.6252158895, "num_tokens": 222, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403999037782, "lm_q2_score": 0.7401743505760728, "lm_q1q2_score": 0.6879479443979445}} {"text": "PROGRAM SPIRAL\n\n IMPLICIT NONE\n\n INTEGER, PARAMETER :: size = 5\n INTEGER :: i, x = 0, y = 1, count = size, n = 0\n INTEGER :: array(size,size)\n\n DO i = 1, count\n x = x + 1\n array(x,y) = n\n n = n + 1\n END DO\n\n DO\n count = count - 1\n DO i = 1, count\n y = y + 1\n array(x,y) = n\n n = n + 1\n END DO\n DO i = 1, count\n x = x - 1\n array(x,y) = n\n n = n + 1\n END DO\n IF (n > size*size-1) EXIT\n count = count - 1\n DO i = 1, count\n y = y - 1\n array(x,y) = n\n n = n + 1\n END DO\n DO i = 1, count\n x = x + 1\n array(x,y) = n\n n = n + 1\n END DO\t\n IF (n > size*size-1) EXIT\n END DO\n\n DO y = 1, size\n DO x = 1, size\n WRITE (*, \"(I4)\", ADVANCE=\"NO\") array (x, y)\n END DO\n WRITE (*,*)\n END DO\n\nEND PROGRAM SPIRAL\n", "meta": {"hexsha": "ffa1d09465e37bb76fe329b69fcad07f2a6c9678", "size": 870, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Spiral-matrix/Fortran/spiral-matrix.f", "max_stars_repo_name": "mullikine/RosettaCodeData", "max_stars_repo_head_hexsha": "4f0027c6ce83daa36118ee8b67915a13cd23ab67", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Spiral-matrix/Fortran/spiral-matrix.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/Spiral-matrix/Fortran/spiral-matrix.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 17.4, "max_line_length": 50, "alphanum_fraction": 0.4137931034, "num_tokens": 339, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127678225575, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.6879396123399295}} {"text": "C@a====================================================================*\n PROGRAM profile\n*----------------------------------------------------------------------*\nC! Outputs the velocity profile to be used as input for T-Rex *\nC@e--------------------------------------------------------------------*\n IMPLICIT NONE\n*----------------------------------------------------------------------*\n REAL*8 L, x, v\n INTEGER N, i\nc#rcs-----------------------\n character*80 rcs1,rcs2\n data rcs1/\n >'$Id: profile.f,v 1.3 2002/06/01 17:17:40 bojan Exp $'/\n data rcs2/\n >'$Source: /home/IUS/mhadziabdic/.CVSROOT/T-Rex/Test/profile.f,v $'/\nC@d====================================================================*\n\n* Number of points\n N=200\n\n write(*,'(A20)') '#==================#'\n write(*,'(A20)') '# Number of points #'\n write(*,'(A20)') '#==================#'\n write(*,*) N \n write(*,'(A13)') '#===========#'\n write(*,'(A13)') '# Direction #'\n write(*,'(A13)') '#===========#'\n write(*,*) 'z' \n write(*,'(A20)') '#==================#'\n write(*,'(A20)') '# coordinate U V W #'\n write(*,'(A20)') '#==================#'\n* Parabolic profile in range 0:2, extrema=1 *\nc L = 2.d0\nc do i=0,N\nc x = real(i) * L/real(n)\nc v = 1.d0 - (x-L/2.d0)**2\nc write(*,'(4F18.6)') x, v, 0.d0, 0.d0\nc end do\n\n* Parabolic profile in range 0:3, extrema=1 *\n! L = 3.d0\n! do i=0,N\n! x = real(i) * L/real(N)\n! v = (2.25-(x-1.5)*(x-1.5))/2.25\n! write(*,'(4F18.6)') x, v, 0.d0, 0.d0\n! end do\n\n* Parabolic profile in range 0:1, extrema=1 *\n L = 1.d0\n do i=0,N\n x = real(i) * L/real(n)\n v = 6.d0 * x * (1.d0 - x)\n write(*,'(5F18.6)') x, v, 0.d0, 0.d0, 0.d0\n end do\n\n END\n", "meta": {"hexsha": "899777d9d794229bc8229eda89d9b987153cb4d3", "size": 1862, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Generate/Library_cases/profile.f", "max_stars_repo_name": "palkinev/T-FlowS-old-compressible", "max_stars_repo_head_hexsha": "7aa7219aa5526ac270b39d52ba8c12847e1d71a2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Generate/Library_cases/profile.f", "max_issues_repo_name": "palkinev/T-FlowS-old-compressible", "max_issues_repo_head_hexsha": "7aa7219aa5526ac270b39d52ba8c12847e1d71a2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Generate/Library_cases/profile.f", "max_forks_repo_name": "palkinev/T-FlowS-old-compressible", "max_forks_repo_head_hexsha": "7aa7219aa5526ac270b39d52ba8c12847e1d71a2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.6666666667, "max_line_length": 73, "alphanum_fraction": 0.3394199785, "num_tokens": 605, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127603871312, "lm_q2_score": 0.8056321913146128, "lm_q1q2_score": 0.6879396083421944}} {"text": "module numerical\n\nimplicit none\n\ncontains\n\nelemental logical function isprime(i)\n\ninteger, intent(in) :: i\ninteger :: j\n\nisprime = .false.\n\n!! trivial tests\n\nif (i<=1) return\n\nif (i==2 .or. i==3) then\n isprime = .true.\n return\nendif\n\nif (modulo(i,2) == 0 .or. modulo(i,3) == 0) return\n\n!! 6k+1 test\n\ndo j = 5, int(sqrt(real(i))), 6\n if (modulo(i,j) == 0 .or. modulo(i,j+2) == 0) return\nenddo\n\nisprime = .true.\n\nend function isprime\n\nend module numerical\n", "meta": {"hexsha": "ca27692d1d07c98bf70dffd8423d927a6da76b84", "size": 457, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "numerical.f90", "max_stars_repo_name": "scivision/preschool-coding", "max_stars_repo_head_hexsha": "0cd63b0693b31b1381aaa484a3b8b3671b036270", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "numerical.f90", "max_issues_repo_name": "scivision/preschool-coding", "max_issues_repo_head_hexsha": "0cd63b0693b31b1381aaa484a3b8b3671b036270", "max_issues_repo_licenses": ["MIT"], "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.f90", "max_forks_repo_name": "scivision/preschool-coding", "max_forks_repo_head_hexsha": "0cd63b0693b31b1381aaa484a3b8b3671b036270", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 12.6944444444, "max_line_length": 54, "alphanum_fraction": 0.6389496718, "num_tokens": 161, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8539127529517043, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.687939602351975}} {"text": "program sqrt\n\nuse, intrinsic :: iso_c_binding\nimplicit none\n\ncharacter(len=5) :: arg\ninteger :: nargs\n\ninterface\n integer(c_int) function passarrays (in, out) bind (c)\n use iso_c_binding\n implicit none\n real(c_double), intent(in) :: in(4)\n real(c_double), intent(out) :: out(4)\n end function\n function initializer () bind (c)\n use iso_c_binding\n integer(c_int) :: initializer\n end function\n function nr_sqrt ( input, x0, iterations, printIts ) bind (c)\n use iso_c_binding\n real(c_double), value :: input\n real(c_double), value :: x0\n integer(c_int), value :: iterations\n logical(c_bool), value :: printIts\n real(c_double) :: nr_sqrt\n end function nr_sqrt\nend interface\n\n! arguments for the c routines\ninteger(c_int) :: errstat\nreal(c_double) :: input\nreal(c_double) :: x0 = 10\ninteger(c_int) :: iterations = 10\nlogical(c_bool) :: printIts = .TRUE.\nreal(c_double) :: result\ninteger ( c_int ) :: result_int\nreal(C_DOUBLE), dimension(0:3) :: in, out\n\n! passing arrays to c and back\nin = (/1,2,3,4/)\nprint *, \"uninitialized out: \", out\nresult_int = passarrays(in, out)\nprint *, \"after c out: \", out\n\n! initialize the c routines\nerrstat = initializer()\n\n! read the input argument and convert to real\nnargs = command_argument_count()\nif (nargs.ne.1) then\n print *, \"Usage: sqrt N where N is a real number\"\n stop 1\nendif\n\ncall getarg(1, arg)\nread(arg,*) input\n\n! get the square root from newton raphson method\nresult = nr_sqrt(input, x0, iterations, printIts)\n\n! display the results\nprint \"(3A,F10.4)\", \"The square root of \",trim(arg),\" is \",result\n\nend program\n", "meta": {"hexsha": "342a781cfca4560d0e9d21df2b27d4271025e6d0", "size": 1635, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "sqrt_c.f90", "max_stars_repo_name": "rafaelmudafort/sqrt", "max_stars_repo_head_hexsha": "b8db75c0fa29360aea056bd1640d46cacf75379b", "max_stars_repo_licenses": ["Xnet", "X11"], "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_c.f90", "max_issues_repo_name": "rafaelmudafort/sqrt", "max_issues_repo_head_hexsha": "b8db75c0fa29360aea056bd1640d46cacf75379b", "max_issues_repo_licenses": ["Xnet", "X11"], "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_c.f90", "max_forks_repo_name": "rafaelmudafort/sqrt", "max_forks_repo_head_hexsha": "b8db75c0fa29360aea056bd1640d46cacf75379b", "max_forks_repo_licenses": ["Xnet", "X11"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-10-30T19:55:52.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-12T15:59:05.000Z", "avg_line_length": 24.7727272727, "max_line_length": 65, "alphanum_fraction": 0.6788990826, "num_tokens": 456, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517043, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.6879395983670078}} {"text": "!+MODULE NAME\n! INTERPOLATION\n!\n!+MODULE DESCRIPTION\n! This module contains routines for trilinear and tricubic interpolation of 3D gridded\n! data. Trilinear interpolation is a triply-iterated linear interpolation. Tricubic is\n! an implementation of a local tricubic interpolation scheme based on the paper\n! by F. Leiken and J. Marsden, \"Tricubic Interpolation in Three Dimensions\".\n! This implementation differs from others (e.g., iterated cubic spline) because it is purely local -- \n! rather than using multiple points, it relies on multiple derivatives. When these derivatives are\n! not explicitly available, they can be approximated using finite difference methods. Currently,\n! finite differences are approximated using the FINITE_DIFFERENCES_CS2 module which estimates the \n! derivatives using a quadratic polynomial fit.\n!\n! This code is not currently configured to directly handle AMR grids, so such data must be\n! pre-processed onto a cartesian mesh.\n!\n!+GLOBAL DATA\n! GRID data type\n!\n!+ROUTINES\n! TRICUBIC_INIT Subroutine -> Calcluate tricubic interpolation coefficients for a given grid cell\n! GRID_INIT Subroutine -> Initialize a grid object\n! TRILINEAR_INTERPOLATE Subroutine -> Evaluate a trilinear interpolant using the data in a GRID object\n! TRICUBIC_INTERPOLATE Subroutine -> Evaluate a tricubic interpolant using pre-calculated coefficients from TRICUBIC_INIT and the data in a GRID object\n! LOCATE Function -> Search an ordered array for the lower bracketing index, i.e. the index of the\n! element of the array whose value is closest to a specified value without going over\n!\n!+DEPENDENCIES\n! NONE\n!\n!+USAGE\n! 1. Initialize the grid by calling GRID_INIT()\n! 2. Determine the local interpolation coefficients by calling TRICUBIC_INIT() \n! with appropriate inputs\n! 3. Calculate the local value of the desired quantities using trilinear_interpolate() and\n! tricubic_interpolate() routines with appropriate inputs\n! 4. Note that repeated evaluations of the tricubic interpolant can be carried out for different values \n! of the independent variables so long as they remain within the region of validity for the grid object\n!\n!+AUTHOR\n! Jesse Woodroffe\n! jwoodroffe@lanl.gov\n!\n!+REVISION HISTORY\n! 16 January 2015: Original code\n! 17 January 2015: Added tricubic_init and removed calculation of B_INV from tricubic_setup\n! 18 January 2015: Added matrix_inverse module with matrix inversion routine \n! Added INTERPOLANT data type and code snippets for use in future implementations\n! 20 January 2015: Changed code to fully support use of interpolant data type and added test program\n! 21 January 2015: ::CODE FORKED TO VERSION 2:: Revised derivative scaling in test program. Modified \n! interpolant object and moved derivative scaling to the evaluation procedures so \n! that interpolation is transparent to the user. The example program has been \n! modified to minimize the number of times tricubic_setup() has to be called.\n! 22 January 2015: ::CODE FORKED TO VERSION 3:: Added setup and evaluation methods to INTERPOLANT class.\n! The interpolation process has been converted to a more object-oriented flow that\n! permits the simultaneous existence of multiple interpolants. Added an explicit definiton\n! of the B_INV matrix and removed the routines originally used to calculate it.\n! 23 January 2015: Added locate function to search ordered but non-uniformly spaced (\"stretched\") grids. \n! 11 March 2015: Fixed an error in some of the mixed derivative routines\n! 17 March 2015: Intoroduced GRID object to streamline data sharing amongst interpolants. Added trilinear\n! interpolation routine for electric fields\n! 04 March 2015: Changed interpolant object to 64-element array, altered some variable names.\n! 13 August 2015: Fixed error in B_INV array\n\nmodule interpolation\n\nuse global\n\n! The B_INV array is a bunch of constants that are used to determine the interpolation weights.\n! There is no need to recalculate this array, so I've included it here as a monstrously large constant.\n! Note that the square bracket [] notation for array definition is only supported by the FORTRAN standard\n! since 2008, but the Intel ifort compiler doesn't complain.\n\n! The B_INV matrix relates the derivatives to the coefficients of the interpolant. This is a geometrical constant for a 1 x 1 x 1 cube, so no need to actually calculate it on the fly.\n! The bracket assignment notation is not supported by all Fortran compilers, so use with others may require us to put the array in a file and read it once at the beginning of the simulation.\nreal(dp),dimension(64,64), parameter :: B_INV = reshape([&\n[ 1, 0, -3, 2, 0, 0, 0, 0, -3, 0, 9, -6, 2, 0, -6, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -3, 0, 9, -6, 0, 0, 0, 0, 9, 0, -27, 18, -6, 0, 18, -12, 2, 0, -6, 4, 0, 0, 0, 0, -6, 0, 18, -12, 4, 0, -12, 8], &\n[ 0, 0, 3, -2, 0, 0, 0, 0, 0, 0, -9, 6, 0, 0, 6, -4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -9, 6, 0, 0, 0, 0, 0, 0, 27, -18, 0, 0, -18, 12, 0, 0, 6, -4, 0, 0, 0, 0, 0, 0, -18, 12, 0, 0, 12, -8], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, -9, 6, -2, 0, 6, -4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -9, 0, 27, -18, 6, 0, -18, 12, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, -18, 12, -4, 0, 12, -8], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, -6, 0, 0, -6, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -27, 18, 0, 0, 18, -12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, -12, 0, 0, -12, 8], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, -9, 6, 0, 0, 0, 0, -9, 0, 27, -18, 6, 0, -18, 12, -2, 0, 6, -4, 0, 0, 0, 0, 6, 0, -18, 12, -4, 0, 12, -8], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, -6, 0, 0, 0, 0, 0, 0, -27, 18, 0, 0, 18, -12, 0, 0, -6, 4, 0, 0, 0, 0, 0, 0, 18, -12, 0, 0, -12, 8], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, -27, 18, -6, 0, 18, -12, 0, 0, 0, 0, 0, 0, 0, 0, -6, 0, 18, -12, 4, 0, -12, 8], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, -18, 0, 0, -18, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -18, 12, 0, 0, 12, -8], &\n[ 0, 1, -2, 1, 0, 0, 0, 0, 0, -3, 6, -3, 0, 2, -4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -3, 6, -3, 0, 0, 0, 0, 0, 9, -18, 9, 0, -6, 12, -6, 0, 2, -4, 2, 0, 0, 0, 0, 0, -6, 12, -6, 0, 4, -8, 4], &\n[ 0, 0, -1, 1, 0, 0, 0, 0, 0, 0, 3, -3, 0, 0, -2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, -3, 0, 0, 0, 0, 0, 0, -9, 9, 0, 0, 6, -6, 0, 0, -2, 2, 0, 0, 0, 0, 0, 0, 6, -6, 0, 0, -4, 4], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, -6, 3, 0, -2, 4, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -9, 18, -9, 0, 6, -12, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, -12, 6, 0, -4, 8, -4], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -3, 3, 0, 0, 2, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, -9, 0, 0, -6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -6, 6, 0, 0, 4, -4], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, -6, 3, 0, 0, 0, 0, 0, -9, 18, -9, 0, 6, -12, 6, 0, -2, 4, -2, 0, 0, 0, 0, 0, 6, -12, 6, 0, -4, 8, -4], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -3, 3, 0, 0, 0, 0, 0, 0, 9, -9, 0, 0, -6, 6, 0, 0, 2, -2, 0, 0, 0, 0, 0, 0, -6, 6, 0, 0, 4, -4], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, -18, 9, 0, -6, 12, -6, 0, 0, 0, 0, 0, 0, 0, 0, 0, -6, 12, -6, 0, 4, -8, 4], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -9, 9, 0, 0, 6, -6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, -6, 0, 0, -4, 4], &\n[ 0, 0, 0, 0, 1, 0, -3, 2, -2, 0, 6, -4, 1, 0, -3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -3, 0, 9, -6, 6, 0, -18, 12, -3, 0, 9, -6, 0, 0, 0, 0, 2, 0, -6, 4, -4, 0, 12, -8, 2, 0, -6, 4], &\n[ 0, 0, 0, 0, 0, 0, 3, -2, 0, 0, -6, 4, 0, 0, 3, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -9, 6, 0, 0, 18, -12, 0, 0, -9, 6, 0, 0, 0, 0, 0, 0, 6, -4, 0, 0, -12, 8, 0, 0, 6, -4], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 3, -2, 1, 0, -3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, -9, 6, -3, 0, 9, -6, 0, 0, 0, 0, 0, 0, 0, 0, -2, 0, 6, -4, 2, 0, -6, 4], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -3, 2, 0, 0, 3, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, -6, 0, 0, -9, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -6, 4, 0, 0, 6, -4], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, -9, 6, -6, 0, 18, -12, 3, 0, -9, 6, 0, 0, 0, 0, -2, 0, 6, -4, 4, 0, -12, 8, -2, 0, 6, -4], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, -6, 0, 0, -18, 12, 0, 0, 9, -6, 0, 0, 0, 0, 0, 0, -6, 4, 0, 0, 12, -8, 0, 0, -6, 4], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -3, 0, 9, -6, 3, 0, -9, 6, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, -6, 4, -2, 0, 6, -4], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -9, 6, 0, 0, 9, -6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, -4, 0, 0, -6, 4], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, -3, 2, 0, 0, 0, 0, -3, 0, 9, -6, 2, 0, -6, 4, -2, 0, 6, -4, 0, 0, 0, 0, 6, 0, -18, 12, -4, 0, 12, -8, 1, 0, -3, 2, 0, 0, 0, 0, -3, 0, 9, -6, 2, 0, -6, 4], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, -2, 0, 0, 0, 0, 0, 0, -9, 6, 0, 0, 6, -4, 0, 0, -6, 4, 0, 0, 0, 0, 0, 0, 18, -12, 0, 0, -12, 8, 0, 0, 3, -2, 0, 0, 0, 0, 0, 0, -9, 6, 0, 0, 6, -4], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, -9, 6, -2, 0, 6, -4, 0, 0, 0, 0, 0, 0, 0, 0, -6, 0, 18, -12, 4, 0, -12, 8, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, -9, 6, -2, 0, 6, -4], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, -6, 0, 0, -6, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -18, 12, 0, 0, 12, -8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, -6, 0, 0, -6, 4], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 3, -2, 0, 0, 0, 0, 3, 0, -9, 6, -2, 0, 6, -4, 1, 0, -3, 2, 0, 0, 0, 0, -3, 0, 9, -6, 2, 0, -6, 4], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -3, 2, 0, 0, 0, 0, 0, 0, 9, -6, 0, 0, -6, 4, 0, 0, 3, -2, 0, 0, 0, 0, 0, 0, -9, 6, 0, 0, 6, -4], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -3, 0, 9, -6, 2, 0, -6, 4, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, -9, 6, -2, 0, 6, -4], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -9, 6, 0, 0, 6, -4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, -6, 0, 0, -6, 4], &\n[ 0, 0, 0, 0, 0, 1, -2, 1, 0, -2, 4, -2, 0, 1, -2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -3, 6, -3, 0, 6, -12, 6, 0, -3, 6, -3, 0, 0, 0, 0, 0, 2, -4, 2, 0, -4, 8, -4, 0, 2, -4, 2], &\n[ 0, 0, 0, 0, 0, 0, -1, 1, 0, 0, 2, -2, 0, 0, -1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, -3, 0, 0, -6, 6, 0, 0, 3, -3, 0, 0, 0, 0, 0, 0, -2, 2, 0, 0, 4, -4, 0, 0, -2, 2], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 2, -1, 0, 1, -2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, -6, 3, 0, -3, 6, -3, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2, 4, -2, 0, 2, -4, 2], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, 0, 0, -1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -3, 3, 0, 0, 3, -3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, -2, 0, 0, -2, 2], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, -6, 3, 0, -6, 12, -6, 0, 3, -6, 3, 0, 0, 0, 0, 0, -2, 4, -2, 0, 4, -8, 4, 0, -2, 4, -2], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -3, 3, 0, 0, 6, -6, 0, 0, -3, 3, 0, 0, 0, 0, 0, 0, 2, -2, 0, 0, -4, 4, 0, 0, 2, -2], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -3, 6, -3, 0, 3, -6, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, -4, 2, 0, -2, 4, -2], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, -3, 0, 0, -3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2, 2, 0, 0, 2, -2], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -2, 1, 0, 0, 0, 0, 0, -3, 6, -3, 0, 2, -4, 2, 0, -2, 4, -2, 0, 0, 0, 0, 0, 6, -12, 6, 0, -4, 8, -4, 0, 1, -2, 1, 0, 0, 0, 0, 0, -3, 6, -3, 0, 2, -4, 2], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 1, 0, 0, 0, 0, 0, 0, 3, -3, 0, 0, -2, 2, 0, 0, 2, -2, 0, 0, 0, 0, 0, 0, -6, 6, 0, 0, 4, -4, 0, 0, -1, 1, 0, 0, 0, 0, 0, 0, 3, -3, 0, 0, -2, 2], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, -6, 3, 0, -2, 4, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, -6, 12, -6, 0, 4, -8, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, -6, 3, 0, -2, 4, -2], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -3, 3, 0, 0, 2, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, -6, 0, 0, -4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -3, 3, 0, 0, 2, -2], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 2, -1, 0, 0, 0, 0, 0, 3, -6, 3, 0, -2, 4, -2, 0, 1, -2, 1, 0, 0, 0, 0, 0, -3, 6, -3, 0, 2, -4, 2], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, 0, 0, 0, 0, 0, 0, -3, 3, 0, 0, 2, -2, 0, 0, -1, 1, 0, 0, 0, 0, 0, 0, 3, -3, 0, 0, -2, 2], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -3, 6, -3, 0, 2, -4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, -6, 3, 0, -2, 4, -2], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, -3, 0, 0, -2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -3, 3, 0, 0, 2, -2], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, -3, 2, -2, 0, 6, -4, 1, 0, -3, 2, 0, 0, 0, 0, -2, 0, 6, -4, 4, 0, -12, 8, -2, 0, 6, -4, 0, 0, 0, 0, 1, 0, -3, 2, -2, 0, 6, -4, 1, 0, -3, 2], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, -2, 0, 0, -6, 4, 0, 0, 3, -2, 0, 0, 0, 0, 0, 0, -6, 4, 0, 0, 12, -8, 0, 0, -6, 4, 0, 0, 0, 0, 0, 0, 3, -2, 0, 0, -6, 4, 0, 0, 3, -2], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 3, -2, 1, 0, -3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, -6, 4, -2, 0, 6, -4, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 3, -2, 1, 0, -3, 2], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -3, 2, 0, 0, 3, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, -4, 0, 0, -6, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -3, 2, 0, 0, 3, -2], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 3, -2, 2, 0, -6, 4, -1, 0, 3, -2, 0, 0, 0, 0, 1, 0, -3, 2, -2, 0, 6, -4, 1, 0, -3, 2], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -3, 2, 0, 0, 6, -4, 0, 0, -3, 2, 0, 0, 0, 0, 0, 0, 3, -2, 0, 0, -6, 4, 0, 0, 3, -2], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, -3, 2, -1, 0, 3, -2, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 3, -2, 1, 0, -3, 2], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, -2, 0, 0, -3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -3, 2, 0, 0, 3, -2], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -2, 1, 0, -2, 4, -2, 0, 1, -2, 1, 0, 0, 0, 0, 0, -2, 4, -2, 0, 4, -8, 4, 0, -2, 4, -2, 0, 0, 0, 0, 0, 1, -2, 1, 0, -2, 4, -2, 0, 1, -2, 1], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 1, 0, 0, 2, -2, 0, 0, -1, 1, 0, 0, 0, 0, 0, 0, 2, -2, 0, 0, -4, 4, 0, 0, 2, -2, 0, 0, 0, 0, 0, 0, -1, 1, 0, 0, 2, -2, 0, 0, -1, 1], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 2, -1, 0, 1, -2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, -4, 2, 0, -2, 4, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 2, -1, 0, 1, -2, 1], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, 0, 0, -1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2, 2, 0, 0, 2, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, 0, 0, -1, 1], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 2, -1, 0, 2, -4, 2, 0, -1, 2, -1, 0, 0, 0, 0, 0, 1, -2, 1, 0, -2, 4, -2, 0, 1, -2, 1], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, 0, 0, -2, 2, 0, 0, 1, -1, 0, 0, 0, 0, 0, 0, -1, 1, 0, 0, 2, -2, 0, 0, -1, 1], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -2, 1, 0, -1, 2, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 2, -1, 0, 1, -2, 1], &\n[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 1, 0, 0, 1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, 0, 0, -1, 1]],[64,64])\n\ncontains\n\n subroutine grid_init(myGrid, im, jm, km, lm, dx, dy, dz, dt)\n ! Initialize a grid object used in trilinear and tricubic interpolation\n implicit none\n\n type(grid) :: myGrid\n integer, intent(in) :: im, jm, km, lm\n real(dp), intent(in) :: dx, dy, dz, dt\n\n myGrid%im = im\n myGrid%jm = jm\n myGrid%km = km\n myGrid%lm = lm\n myGrid%dx = dx\n myGrid%dy = dy\n myGrid%dz = dz\n myGrid%dt = dt\n\n return\n\n end subroutine grid_init\n\n!\n\n function trilinear_interpolate(myGrid,xw,yw,zw,F) result(h)\n ! Find the value of a three-dimensional function at a point using\n ! trilinear interpolation of gridded values\n implicit none\n\n type(grid) :: myGrid\n real(dp), intent(in) :: xw, yw, zw\n real(dp), dimension(2,2,2) :: F\n real(dp) :: x, y, z\n real(dp) :: f00, f10, f01, f11\n real(dp) :: g0, g1\n real(dp) :: h\n\n x = (xw-xgrid(myGrid%im))/myGrid%dx\n y = (yw-ygrid(myGrid%jm))/myGrid%dy\n z = (zw-zgrid(myGrid%km))/myGrid%dz\n\n f00 = (1-x)*F(1,1,1)+x*F(2,1,1)\n f10 = (1-x)*F(1,2,1)+x*F(2,2,1)\n f01 = (1-x)*F(1,1,2)+x*F(2,1,2)\n f11 = (1-x)*F(1,2,2)+x*F(2,2,2)\n g0 = (1-y)*f00+y*f10\n g1 = (1-y)*f01+y*f11\n h = (1-z)*g0+z*g1\n\n return\n\n end function trilinear_interpolate\n\n!\n\n subroutine tricubic_init(myCoeffs,myGrid,F,FX,FY,FZ,FXY,FXZ,FYZ,FXYZ)\n ! Calculate the interpolation coefficients for an interpolant object\n implicit none\n \n real(dp), dimension(64) :: myCoeffs\n type(grid) :: myGrid\n real(dp), dimension(2,2,2), intent(in) :: F,FX,FY,FZ,FXY,FXZ,FYZ,FXYZ\n real(dp), dimension(64) :: bbar\n integer :: ix, iy, iz, irow\n \n !Determine the coefficients of the interpolation using abar = B_INV . bbar\n ! We only need to save the results of this calculation, bbar is not needed later.\n\n irow=0\n do iz=1,2\n do iy=1,2\n do ix=1,2\n irow=irow+1\n bbar(irow ) = F(ix,iy,iz)\n bbar(irow+8 ) = FX(ix,iy,iz)*myGrid%dx\n bbar(irow+16) = FY(ix,iy,iz)*myGrid%dy\n bbar(irow+24) = FZ(ix,iy,iz)*myGrid%dz\n bbar(irow+32) = FXY(ix,iy,iz)*myGrid%dx*myGrid%dy\n bbar(irow+40) = FXZ(ix,iy,iz)*myGrid%dx*myGrid%dz\n bbar(irow+48) = FYZ(ix,iy,iz)*myGrid%dy*myGrid%dz\n bbar(irow+56) = FXYZ(ix,iy,iz)*myGrid%dx*myGrid%dy*myGrid%dz\n enddo\n enddo\n enddo\n\n ! This is a matrix-vector multiply between a 64x64 matrix and a 64 element vector. Tests indicate that\n ! vendor-optimized matmuls (such as mkl) are more efficient than a call to the L2 BLAS DGEMV routine\n ! (results may differ for an optimized BLAS library, but the times weren't even particularly close).\n\n myCoeffs = matmul(B_INV,bbar)\n \n return\n \n end subroutine tricubic_init\n\n!\n\n subroutine tricubic_interpolate(myCoeffs, myGrid, x0, y0, z0, f0, gradf)\n ! Evaluate a tricubic interpolant at a point. You can also request the gradient of\n ! the function by including the optional gradf vector.\n implicit none\n\n real(dp), dimension(64) :: myCoeffs\n type(grid) :: myGrid\n real(dp), intent(in) :: x0, y0, z0\n real(dp), intent(out) :: f0\n real(dp), dimension(3), intent(out), optional :: gradf\n real(dp) :: x, y, z\n real(dp) :: xpow, ypow, zpow\n real(dp) :: xder, yder, zder\n integer :: i, j, k, idex\n \n ! Map the simulation cell to a unit cube\n x = (x0-xgrid(myGrid%im))/myGrid%dx\n y = (y0-ygrid(myGrid%jm))/myGrid%dy\n z = (z0-zgrid(myGrid%km))/myGrid%dz\n\n ! Calculate the value of the function based on tricubic interpolation coefficients\n ! previously calculated during a call to tricubic_setup. Also calculate the gradient\n ! of the function if the gradf argument is present\n\n f0 = 0.d0\n if(present(gradf)) gradf = 0.d0\n\n ! These #pow and #der variables are used to avoid using the exponentiation operator, \n ! and they turn out to be a fairly efficient way of expressing the algorithm.\n\n idex=0\n zder = 0.d0\n zpow = 1.d0\n do k=0,3\n yder = 0.d0\n ypow = 1.d0\n do j=0,3\n xder = 0.d0\n xpow = 1.d0\n do i=0,3\n idex = idex+1\n f0 = f0+myCoeffs(idex)*xpow*ypow*zpow\n if(present(gradf)) then ! Calculate the gradient\n gradf(1) = gradf(1)+myCoeffs(idex)*i*xder*ypow*zpow\n gradf(2) = gradf(2)+myCoeffs(idex)*j*xpow*yder*zpow\n gradf(3) = gradf(3)+myCoeffs(idex)*k*xpow*ypow*zder\n endif\n xder = xpow\n xpow = xpow*x\n enddo\n yder = ypow\n ypow = ypow*y\n enddo\n zder = zpow\n zpow = zpow*z\n enddo\n \n if(present(gradf)) then ! Scale derivatives by actual size of the cell\n gradf(1) = gradf(1)/myGrid%dx\n gradf(2) = gradf(2)/myGrid%dy\n gradf(3) = gradf(3)/myGrid%dz\n endif\n\n return\n \n end subroutine tricubic_interpolate\n\n!\n\n function locate(v,x,ih) result(i0)\n ! Seach for the lower bracketing index, i.e. the index of array element of a monotonically\n ! increasing array v that is closest to the value x without being larger than x. If you know\n ! approximately where to look, you can specify an optional \"hunting index\". This function\n ! is essentially an amalgam of the Numerical Recipes \"locate\" and \"hunt\" routines.\n implicit none\n\n real(dp), dimension(:), intent(in) :: v\n real(dp), intent(in) :: x\n integer, intent(in), optional :: ih\n integer :: dh\n integer :: i0\n integer :: ilo, ihi, imid\n integer :: n \n\n n = size(v)\n\n ! Check that the value is actually bracketed. It's up to the user to handle these exceptional cases. \n if(xv(n)) then\n i0 = n+1 \n return\n endif\n\n ! If the user has specified a starting index, we will hunt from that point to determine the bracket\n if(present(ih)) then ! Hunt\n dh = 1 ! Initialize the search range to one cell; if we're lucky, we'll already be bracketing the value\n ihi = ih\n do\n ilo = ihi\n ihi = ilo+dh\n if(ihi > n) then ! That's as far as we can go, truncate search range to last element\n ihi = n\n exit\n endif\n if(v(ihi) > x) exit ! Hunt is successful\n dh = 2*dh ! The hunt hasn't yet succeeded, so we expand the search range and try again\n enddo\n ilo = ih\n ihi = ih+dh\n else ! We don't know where to start, so use the entire interval\n ilo = 1\n ihi = n\n endif\n ! Bisection search\n do\n if(ihi - ilo == 1) exit\n imid = (ihi+ilo)/2\n if(v(imid) == x) then\n ilo = imid\n exit\n else if(v(imid) > x) then\n ihi = imid\n else\n ilo = imid\n endif\n enddo\n i0 = ilo\n return\n end function locate\n \nend module interpolation\n", "meta": {"hexsha": "7b9aab1567ea23200e699ba5b15483d375f7f163", "size": 32223, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/interpolation.f90", "max_stars_repo_name": "Pheosics/SHIELDS-PTM", "max_stars_repo_head_hexsha": "b6bdad6a9184530e03e01ef7d20a6a83be460044", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/interpolation.f90", "max_issues_repo_name": "Pheosics/SHIELDS-PTM", "max_issues_repo_head_hexsha": "b6bdad6a9184530e03e01ef7d20a6a83be460044", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2021-06-01T22:22:01.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-20T19:58:27.000Z", "max_forks_repo_path": "src/interpolation.f90", "max_forks_repo_name": "Pheosics/SHIELDS-PTM", "max_forks_repo_head_hexsha": "b6bdad6a9184530e03e01ef7d20a6a83be460044", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-06-01T23:29:34.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-11T17:57:48.000Z", "avg_line_length": 86.1577540107, "max_line_length": 331, "alphanum_fraction": 0.3717841293, "num_tokens": 19880, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333483, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6878981915753632}} {"text": "program ch0811\n ! Rank 2 Arrays and the Sum Intrinsic Funcoltion\n implicit none\n\n integer, parameter :: nrow = 5\n integer, parameter :: ncol = 6\n real, dimension(1:nrow*ncol) :: results = [ &\n 50., 47., 28., 89., 30., 46., 37., 67., 34., 65., 68., &\n 98., 25., 45., 26., 48., 10., 36., 89., 56., 33., 45., &\n 30., 65., 68., 78., 38., 76., 98., 65. ]\n real, dimension(1:nrow,1:ncol) :: exam_results = 0.\n real, dimension(1:nrow) :: people_average = 0.\n real, dimension(1:ncol) :: subject_average = 0.\n\n exam_results = reshape(results, [nrow,ncol], [0.,0.], [2,1])\n exam_results(1:nrow,3) = exam_results(1:nrow,3)*2.5\n people_average = sum(exam_results, 2)\n people_average = people_average/ncol\n subject_average = sum(exam_results, 1)\n subject_average = subject_average/nrow\n print *, ' People averages'\n print *, people_average\n print *, ' Subject averages'\n print *, subject_average\nend program\n", "meta": {"hexsha": "1e20cf744bddb63b5dbeac889120144545277e04", "size": 970, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ch08/ch0811.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": "ch08/ch0811.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": "ch08/ch0811.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": 37.3076923077, "max_line_length": 64, "alphanum_fraction": 0.6072164948, "num_tokens": 334, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952811593496, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6878981873806729}} {"text": "PROGRAM test_cst\r\n! Test of sine, cosine & tangent\r\n! 1. sin(2.x) = 2.sin(x).cos(x)\r\n! 2. cos(2.x) = (cos(x) + sin(x)).(cos(x) - sin(x))\r\n! 3. sec(x)**2 = 1 + tan(x)**2\r\n\r\nUSE quadruple_precision\r\nIMPLICIT NONE\r\n\r\nTYPE (quad) :: x, twox, sine, cosine, tangent, lhs, rhs, diff\r\nREAL (dp) :: half = 0.5_dp, small = EPSILON(half), r\r\nINTEGER, ALLOCATABLE :: seed(:)\r\nINTEGER :: k, i\r\n\r\n! Set the random number seed.\r\n\r\nCALL RANDOM_SEED(size=k)\r\nALLOCATE (seed(k))\r\nCALL RANDOM_SEED(get=seed)\r\nWRITE(*, *)'Old random number seeds: ', seed\r\n\r\nWRITE(*, '(1x, a, i4, a)') 'Enter ', k, ' integers as random number seeds: '\r\nREAD(*, *) seed\r\nCALL RANDOM_SEED(put=seed)\r\n\r\nDO i = 1, 100\r\n CALL RANDOM_NUMBER(x%hi)\r\n CALL RANDOM_NUMBER(r)\r\n x%hi = (x%hi - half) / r\r\n x%lo = x%hi * small\r\n ! sin(2.x) = 2.sin(x).cos(x)\r\n twox = 2._dp * x\r\n lhs = SIN(twox)\r\n sine = SIN(x)\r\n cosine = COS(x)\r\n rhs = sine * cosine\r\n rhs = 2._dp * rhs\r\n diff = lhs - rhs\r\n WRITE(*, '(\" sin(2x) lhs =\", g13.5, \" Diff. =\", g12.4)') lhs%hi, diff%hi\r\n ! cos(2.x) = (cos(x) + sin(x)).(cos(x) - sin(x))\r\n lhs = COS(twox)\r\n rhs = (cosine + sine) * (cosine - sine)\r\n diff = lhs - rhs\r\n WRITE(*, '(\" cos(2x) lhs =\", g13.5, \" Diff. =\", g12.4)') lhs%hi, diff%hi\r\n ! sec(x)**2 = 1 + tan(x)**2\r\n diff%hi = 1._dp\r\n diff%lo = 0._dp\r\n lhs = diff / cosine\r\n lhs = lhs * lhs\r\n tangent = TAN(x)\r\n rhs = diff + tangent * tangent\r\n diff = lhs - rhs\r\n WRITE(*, '(\" sec(x)^2 lhs =\", g13.5, \" Diff. =\", g12.4)') lhs%hi, diff%hi\r\nEND DO\r\n\r\nSTOP\r\nEND PROGRAM test_cst\r\n", "meta": {"hexsha": "938494a17ae6689f836e29b2d782f1b7501991e1", "size": 1673, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/t_cst.f90", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/amil/t_cst.f90", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/amil/t_cst.f90", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 28.8448275862, "max_line_length": 79, "alphanum_fraction": 0.5074716079, "num_tokens": 608, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333484, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.6878981867841578}} {"text": "module constants\r\n real, parameter :: pi=3.1415926\r\n real, parameter :: twopi=2.*pi\r\n real, parameter :: rad=pi/180.\r\n real, parameter :: ftm=12./39.37\r\n real, parameter :: mtf=1/ftm\r\n real, parameter :: rpm=60./twopi\r\n ! ft/s^2\r\n real, parameter :: g=32.179\r\n real, parameter :: circ=9.125\r\n ! radius of ball in ft\r\n real, parameter :: radius=circ/twopi/12\r\nend module constants\r\n\r\nprogram test\r\n\r\n use constants\r\n\r\n ! Original version by Alan Nathan\r\n ! Modifcations by Chris Long\r\n\r\n interface dist\r\n subroutine dist(t,x,range,time)\r\n real, dimension(:), intent(in) :: t\r\n real, dimension(:,:), intent(in) :: x\r\n real, intent(out) :: range\r\n real, intent(out) :: time\r\n end subroutine dist\r\n end interface dist\r\n\r\n !parameter(noptmax=7)\r\n integer, parameter :: noptmax=7\r\n \r\n !parameter(pi=3.1415926,twopi=2.*pi,rad=pi/180,ftm=12./39.37,\r\n ! mtf=1/ftm,rpm=60./twopi)\r\n !real, parameter :: pi=3.1415926\r\n !real, parameter :: twopi=2.*pi\r\n \r\n !parameter(rad=pi/180,ftm=12./39.37,mtf=1/ftm,rpm=60./twopi)\r\n !real, parameter :: rad=pi/180\r\n !real, parameter :: ftm=12./39.37\r\n !real, parameter :: mtf=1/ftm\r\n !real, parameter :: rpm=60./twopi\r\n\r\n real :: rhodata,vdata,thetadata,vwind\r\n common/data/ rhodata,vdata,thetadata,vwind\r\n common/flag/iflag\r\n \r\n !parameter(const0=5.283e-3,rho0=1.175)\r\n real, parameter :: const0=5.283e-3\r\n real, parameter :: rho0=1.175\r\n \r\n common/spin/ctht,stht,cphi,sphi\r\n\r\n ! local version of best fit trajectory parameters\r\n common/fitting/cd0,cddot,cdspin,w0,theta0,tau0\r\n\r\n ! local version of input parameters\r\n ! in mph,det,kg/m^3,mph,mph\r\n common/input/v0,theta,rho,const,vwx,vwy\r\n\r\n ! in ft/s^2,ft\r\n !common/constants/g,radius\r\n\r\n !parameter(nterms=8,npts=1000)\r\n integer, parameter :: nterms=8\r\n integer, parameter :: npts=1000\r\n \r\n common/initial/xstart(nterms)\r\n common/path/t(npts),x(nterms,npts)\r\n\r\n ! ft/s^2\r\n !g=32.179\r\n !circ=9.125\r\n ! radius of ball in ft\r\n !radius=circ/twopi/12\r\n\r\n ! no wind\r\n vwx=0.\r\n vwy=0.\r\n\r\n ! index i:\r\n ! 1,2,3 ==> xi,yi,zi\r\n ! 4,5,6 ==> vx,vy,vz\r\n ! 7,8 ==> r*wb,r*ws\r\n\r\n ! wb=backspin rate\r\n ! ws=sidespin rate\r\n\r\n ! note on the right-handed coordinate: \r\n ! z is vertical with positive upward\r\n ! y is catcher-pitcher line\r\n ! x points to catcher's right\r\n\r\n ! NOTE: This current version is 2D, so that x=vx=ws=0\r\n ! It is easy to reinstate these to make it full 3D\r\n\r\n ! read in parameters for Cd,wb\r\n\r\n ! cd0, cddot, cdspin, w0, theta0, tau0\r\n\r\n ! input paramters\r\n open(unit=20,file='parameters.csv',status='old')\r\n read(20,*)\r\n read(20,*) cd0, cddot, cdspin, w0, theta0, tau0\r\n close(20)\r\n\r\n ! output file\r\n !open(unit=21,file='TrajectoryCalculatorOutput.csv',status='unknown')\t\t\r\n ! Default status should be unknown\r\n ! output file\r\n open(unit=21,file='TrajectoryCalculatorOutput.csv')\r\n\r\n ! rhodata, vdata, thetadata, vwind\r\n \r\n open(unit=20,file='trajectory_input.csv',status='old')\r\n ! input data\r\n ! skip header\r\n read(20,*)\r\n read(20,*) rhodata, vdata, thetadata, vwind\r\n ndata=1\r\n tmax=10.\r\n ! write header\r\n write(21,251)\r\n \r\n rho=rhodata\r\n const=const0*(rho/rho0)\r\n v0=vdata\r\n theta=thetadata\r\n vwy=vwind*1.467\r\n vwx=0.\r\n xstart(1)=0.\r\n xstart(2)=2.\r\n xstart(3)=3.\r\n xstart(4)=0.\r\n ctht=cos(theta*rad)\r\n stht=sin(theta*rad)\r\n xstart(5)=(v0*1.467)*ctht\r\n xstart(6)=(v0*1.467)*stht\r\n cphi=1.\r\n sphi=0.\r\n spin=(w0/rpm)*(v0/100.)*(theta-theta0)/(27.5-theta0)\r\n xstart(7)=radius*spin\r\n xstart(8)=0.\r\n\r\n ! spin rate=w0 at v0=100. and theta=27.5 and 0 at theta=aparm(5)\r\n\r\n ! integrate to get trajectory, then distance\r\n\r\n call rkdumb(xstart,nterms,0.,tmax,npts)\r\n\r\n call dist(t,x,range,time)\r\n \r\n sfact=xstart(7)/(1.467*v0)\r\n cdi=cd0*(1.+cddot*(100.-v0))*(1.+cdspin*sfact**2)\r\n \r\n write(21,250) rho, v0, theta, spin*rpm, sfact, cdi, vwind, range, time\r\n write(6,250) rho, v0, theta, spin*rpm, sfact, cdi, vwind, range, time\r\n\r\n251 format(' rho, v0, theta, spin, sfact, cdi, vwind, distance, tof')\r\n250 format(f8.3,2(',',f8.1),1(',',f8.0),2(',',f8.3),3(',',f8.1))\r\n close(21)\r\n !stop\r\n\r\nend program test\r\n\r\nsubroutine derivs(t,x,dxdt)\r\n\r\n use constants\r\n\r\n ! Given the values of t and x, returns derivatives dxdt=dv/dt\r\n\r\n ! local version of fitting parameters\r\n common/fitting/cd0,cddot,cdspin,w0,theta0,tau0\r\n\r\n ! local version of input parameters\r\n ! in mph,det,kg/m^3,mph,mph\r\n common/input/v0,theta,rho,const,vwx,vwy\r\n \r\n !in ft/s^2,ft\r\n !common/constants/g,radius\t\t\t\r\n common/spin/ctht,stht,cphi,sphi\r\n\r\n dimension x(8),dxdt(8)\r\n real drag,lift\r\n \r\n ! Change to constants?\r\n !parameter(pi=3.1415926)\r\n !parameter(twopi=2.*pi)\r\n !parameter(rad=pi/180,ftm=12./39.37,rpm=60./twopi)\r\n\r\n ! 1,2,4 ==> x,y,z\r\n ! 4,5,6 ==> vx,vy,vz\r\n ! 7,8 ==> r*wb,r*ws\r\n\r\n ! NOTE: this is 2D problem, so x(1),dxdt(1) are both fixed at 0\r\n\r\n ! vwx,wwy are x,y components of wind speed\r\n\r\n ! components of radius*spin\r\n\r\n rwb=x(7)\r\n rws=x(8)\r\n romega=sqrt(rwb**2+rws**2)\r\n\r\n ! speed of ball\r\n vt=sqrt((x(4)-vwx)**2+(x(5)-vwy)**2+x(6)**2)\r\n\r\n ! spin factor\r\n sfact=romega/vt\t\t\t\t\r\n\r\n ! note that spin is pure backspin (i.e, rws=0)\r\n\r\n cd=cd0*(1.+cddot*(100.-v0))*(1.+cdspin*sfact**2)\r\n ! Cross prescription\r\n cl=sfact/(2.32*sfact+0.4)\r\n !print*,cd,cl,sfact,g,x(7),vt\r\n !pause\r\n\r\n ! actually drag/(m*vt)\r\n drag=const*cd*vt\r\n ! actually lift/(m*vt)\r\n lift=const*cl*vt\r\n\r\n ! components of spin\r\n ! NOTE: For 2D, ws=0; cphi=1; sphi=0; this means wy=yz=0 and wx=wb\r\n\r\n wx1=rwb\r\n wy1=-rws*stht\r\n wz=rws*ctht\r\n wx=wx1*cphi+wy1*sphi\r\n wy=-wx1*sphi+wy1*cphi\r\n\r\n ! the preceding five statement assure the the spin vector is normal\r\n ! to the initial velocity vector\r\n\r\n !=0 for 2D\r\n liftx=lift*(wy*x(6)-wz*(x(5)-vwy))/romega\r\n lifty=lift*(wz*(x(4)-vwx)-wx*x(6))/romega\r\n liftz=lift*(wx*(x(5)-vwy)-wy*(x(4)-vwx))/romega\r\n !=0 for 2D\r\n dxdt(1)=x(4)\r\n dxdt(2)=x(5)\r\n dxdt(3)=x(6)\r\n !=0 for 2D\r\n dxdt(4)=-drag*(x(4)-vwx)+liftx\r\n dxdt(5)=-drag*(x(5)-vwy)+lifty\r\n dxdt(6)=-drag*x(6)+liftz-g\r\n !no spin-down\r\n dxdt(7)=0.\r\n !no spin-down\r\n dxdt(8)=0.\r\n\t\r\n return\r\nend subroutine derivs\r\n\r\nsubroutine RK4(Y,DYDX,N,X,H,YOUT)\r\n\r\n ! Given values for N variables y and their derivatives DYDX known\r\n ! at X, use the fourth-order Runge-Kutta method to advance the\r\n ! solution over an interval H and return the incremented variables\r\n ! as YOUT, which need not be a distinct array from Y. The user\r\n ! supplies the subroutine DERIVS(X,Y,DYDX) which returns the\r\n ! derivatives DYDX at X\r\n\r\n ! Routine taken from Numerical Recipes, 15.1, p. 553\r\n\r\n ! set to the maximum number of functions\r\n parameter (nmax=10)\r\n dimension Y(N),DYDX(N),YOUT(N),YT(NMAX),DYT(NMAX),DYM(NMAX)\r\n \r\n hh=h*0.5\r\n h6=h/6.\r\n xh=x+hh\r\n \r\n ! first step\r\n do i=1,n\r\n yt(i)=y(i)+hh*dydx(i)\r\n end do\r\n ! second step\r\n call derivs(xh,yt,dyt)\r\n do i=1,n\r\n yt(i)=y(i)+hh*dyt(i)\r\n end do\r\n ! third step\r\n call derivs(xh,yt,dym)\r\n do i=1,n\r\n yt(i)=y(i)+h*dym(i)\r\n dym(i)=dyt(i)+dym(i)\r\n end do\r\n ! fourth step\r\n call derivs(x+h,yt,dyt)\r\n do i=1,n\r\n yout(i)=y(i)+h6*(dydx(i)+dyt(i)+2.*dym(i))\r\n end do\r\n return\r\nend subroutine RK4\r\n\r\nsubroutine rkdumb(vstart, nvar, x1, x2, nstep)\r\n\r\n ! Starting from initial values VSTART for NVAR functions, known at\r\n ! X1, use fourth-order Runge-Kutta to advance npts equal increments\r\n ! to X2. The user supplied subroutine DERIVS(X,V,DVDX) evaluates\r\n ! derivatives. Results are stored in the common block PATH. Be sure\r\n ! to dimension the common block appropriately\r\n\r\n ! Routine taken from Numerical Recipes, 15.1, p. 554\r\n common/coeff/cdprime,cm,cl,rey,sfact,vt\r\n\r\n !set to the maximum number of functions\r\n parameter(nmax=10)\r\n parameter(nterms=8)\r\n parameter(npts=1000)\r\n !nterms functions; npts values\r\n common/path/xx(npts),y(nterms,npts)\r\n dimension vstart(nvar),v(nmax),dv(nmax)\r\n \r\n ! load starting values\r\n do i=1,nvar\t\t\r\n v(i)=vstart(i)\r\n y(i,1)=v(i)\r\n end do\r\n xx(1)=x1\r\n x=x1\r\n h=(x2-x1)/nstep\r\n\r\n ! take nsetp steps\r\n do k=1,nstep-1\r\n call derivs(x,v,dv)\r\n call rk4(v,dv,nvar,x,h,v)\r\n \r\n ! Commented out - replace with error code\r\n !if (x+h.eq.x)pause 'Stepsize not significant in RKDUMB'\r\n x=x+h\r\n !store intermediate steps\r\n xx(k+1)=x\r\n do i=1,nvar\r\n y(i,k+1)=v(i)\r\n end do\r\n\r\n end do\r\n return\r\nend subroutine rkdumb\r\n\r\nsubroutine dist(t,x,range,time)\r\n\r\n use constants\r\n\r\n real, dimension(:), intent(in) :: t\r\n real, dimension(:,:), intent(in) :: x\r\n real, intent(out) :: range\r\n real, intent(out) :: time\r\n\r\n !parameter(nterms=8,pi=3.1415926,twopi=2.*pi,rad=pi/180.)\r\n\r\n integer :: npts\r\n npts=size(t)\r\n \r\n ! Fortran does not have repeat-until\r\n do i=1,npts\r\n if(x(3,i).le.0..and.i.gt.1) exit\r\n end do\r\n \r\n ! linear interpolation to get range\r\n frac=x(3,i-1)/(x(3,i-1)-x(3,i))\r\n d1=sqrt(x(2,i-1)**2+x(1,i-1)**2)\r\n d2=sqrt(x(2,i)**2+x(1,i)**2)\r\n range=d1+frac*(d2-d1)\r\n time=t(i)\r\n return\r\nend subroutine dist\r\n", "meta": {"hexsha": "f4e9093e54cf3bb0ce99e4b5da0101a4c6d1b083", "size": 9068, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "trajectories/fortran/single3.f90", "max_stars_repo_name": "octonion/baseball-public", "max_stars_repo_head_hexsha": "66c406b5855b61d851303069487c8f7e5a885812", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 41, "max_stars_repo_stars_event_min_datetime": "2015-01-04T21:41:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-22T12:09:57.000Z", "max_issues_repo_path": "trajectories/fortran/single3.f90", "max_issues_repo_name": "octonion/baseball-public", "max_issues_repo_head_hexsha": "66c406b5855b61d851303069487c8f7e5a885812", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2015-01-10T08:05:55.000Z", "max_issues_repo_issues_event_max_datetime": "2015-01-10T08:05:55.000Z", "max_forks_repo_path": "trajectories/fortran/single3.f90", "max_forks_repo_name": "octonion/baseball-public", "max_forks_repo_head_hexsha": "66c406b5855b61d851303069487c8f7e5a885812", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2015-01-10T20:15:00.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-22T12:09:58.000Z", "avg_line_length": 24.376344086, "max_line_length": 74, "alphanum_fraction": 0.6186590207, "num_tokens": 3369, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952811593496, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.6878981825894673}} {"text": "! **********************************************************************************\n! * ROUTINES FOR NUMERICAL INTEGRATION *\n! * ---------------------------------------------------------------------- *\n! * Partial list of subroutines: *\n! * Gauss_Legendre, Laguerre, Simpson, Trapez, *\n! * Gauss_Legendre1, Laguerre1, Lgroot, Lgrecr, *\n! * gaussq, class, gausq2, readinputIntegr *\n! **********************************************************************************\nsubroutine Gauss_Legendre (x1, x2, Np, wp, xp)\n!------------------------------------------------------------------------------------ \n! The routine computes the weights and nodes for the Gauss-Legendre quadrature !\n! method. !\n! !\n! Input parameters: !\n! - x1, x2 (real variables) - lower and upper integration limits. !\n! - Np (integer) - number of quadrature points. !\n! !\n! Output parameters: !\n! - wp (real array) - weights. !\n! - xp (real array) - quadrature points (nodes). !\n! !\n! The following parameters (specified in the group statement \"Integration\" !\n! from the input file \"../INPUTFILES/Input.dat\") control the integration !\n! process: !\n! !\n! - TypeIntegr (character array) - specifies the source of the numerical !\n! integration routines. The permissive values are: !\n! - 'MET1' - routines from Numerical Recipes, !\n! - 'MET2' - modified routines from Slatec library. !\n! The recommended value of the parameter TypeIntegr is 'MET1'. !\n! !\n! - epsGauss (real) - tolerance for computing the roots of the Legendre polynomials.!\n! The accuracy of the T-matrix calculation strongly depends on epsGauss. The !\n! value of this parameter should be set AS SMALL AS POSSIBLE. For double !\n! precision arithmetic, epsGauss = 1.e-15,...,1.e-12. !\n!------------------------------------------------------------------------------------\n use parameters\n implicit none\n integer :: Np, i\n real(O) :: x1, x2, wp(Np), xp(Np), epsGauss, epsLaguerre, xs, xd\n character(20) :: TypeIntegr\n real(O),allocatable :: work(:)\n! \n call readinputIntegr ( TypeIntegr, epsGauss, epsLaguerre ) \n call check_Integration (TypeIntegr) \n if (TypeIntegr(1:4) == 'MET1') then\n call Gauss_Legendre1 (x1, x2, Np, wp, xp, epsGauss)\n else if (TypeIntegr(1:4) == 'MET2') then \n allocate (work(Np))\n call gaussq (1, Np, work, xp, wp) \n xd = (x2 - x1) / 2._O\n xs = (x2 + x1) / 2._O\n do i = 1, Np\n wp(i) = xd * wp(i)\n xp(i) = xd * xp(i) + xs\n end do\n deallocate (work)\n end if\nend subroutine Gauss_Legendre\n! **********************************************************************************\nsubroutine Laguerre (n, x, a)\n!------------------------------------------------------------------------------------ \n! The routine computes the weights and nodes for the Laguerre quadrature method. !\n! !\n! Input parameters: !\n! - n (integer) - number of quadrature points. !\n! !\n! Output parameters: !\n! - x (real array) - quadrature points (nodes). !\n! - a (real array) - weights. !\n! !\n! The following parameters (specified in the group statement \"Integration\" !\n! from the input file \"../INPUTFILES/Input.dat\") control the integration !\n! process: !\n! !\n! - TypeIntegr (character array) - specifies the source of the numerical !\n! integration routines. The permissive values are: !\n! - 'MET1' - routines from Numerical Recipes, !\n! - 'MET2' - modified routines from Slatec library. !\n! The recommended value of the parameter TypeIntegr is 'MET1'. !\n! !\n! - epsLaguerre (real) - tolerance for computing the roots of the Laguerre !\n! polynoms. The default value is 1.e-10. !\n!------------------------------------------------------------------------------------\n use parameters\n implicit none \n integer :: n\n real(O) :: x(n), a(n), epsGauss, epsLaguerre\n character(20) :: TypeIntegr\n real(O),allocatable :: work(:) \n! \n call readinputIntegr ( TypeIntegr, epsGauss, epsLaguerre ) \n call check_Integration (TypeIntegr) \n close (unit = iInput)\n if (TypeIntegr(1:4) == 'MET1') then\n call Laguerre1 (n, x, a, epsLaguerre)\n else if (TypeIntegr(1:4) == 'MET2') then \n allocate (work(n))\n call gaussq (2, n, work, x, a) \n deallocate (work)\n end if\nend subroutine Laguerre\n! **********************************************************************************\nsubroutine readinputIntegr ( TypeIntegr, epsGauss, epsLaguerre )\n use parameters\n implicit none\n integer :: ios\n real(O) :: epsGauss, epsLaguerre\n character(20) :: TypeIntegr\n character(80) :: string\n logical :: XFindPar\n!\n open (unit = iInput, file = FileInput, status = \"old\", position = \"rewind\")\n TypeIntegr = 'MET1' \n epsGauss = 1.e-10_O \n epsLaguerre = 1.e-10_O\n string = 'Integration'\n if (XFindPar (iInput, string)) then\n read (iInput, *, iostat = ios) TypeIntegr\n if (ios /= 0) then\n print \"(/,2x,'Error by reading the input variable TypeIntegr;')\"\n stop\n end if\n read (iInput, *, iostat = ios) epsGauss\n if (ios /= 0) then\n print \"(/,2x,'Error by reading the input variable epsGauss;')\"\n stop\n end if\n read (iInput, *, iostat = ios) epsLaguerre\n if (ios /= 0) then\n print \"(/,2x,'Error by reading the input variable epsLaguerre;')\"\n stop\n end if\n else\n print \"(/,2x,'Group name Integration not found;')\"\n stop \n end if \n call check_Integration (TypeIntegr) \n close (unit = iInput) \nend subroutine readinputIntegr \n!***********************************************************************************\nsubroutine Simpson (a, b, N, x, w)\n!------------------------------------------------------------------------------------ \n! The routine computes the weights and nodes for the Simpson quadrature method. !\n! !\n! Input parameters: !\n! - a, b (real variables) - lower and upper integration limits. !\n! - N (integer) - number of quadrature points. !\n! !\n! Output parameters: !\n! - w (real array) - weights. !\n! - x (real array) - quadrature points (nodes). !\n! !\n! Note: The number of integration points must be an odd number. !\n!------------------------------------------------------------------------------------\n use parameters\n implicit none\n integer :: N, i\n real(O) :: a, b, h, x(N), w(N), N1r, i1r\n! \n N1r = real(N - 1,O)\n h = (b - a) / N1r\n do i = 1, N\n i1r = real(i - 1,O)\n x(i) = a + i1r * h\n end do \n if (mod(N - 1,2) == 0) then\n w(1) = h / 3._O\n w(N) = h / 3._O\n do i = 2, N - 1, 2\n w(i) = 4._O * h / 3._O\n end do\n do i = 3, N - 2, 2\n w(i) = 2._O * h / 3._O\n end do\n else\n print \"(/,2x,'Warning in subroutine Simpson in module Integr:')\"\n print \"( 2x,'the number of integration points is an even number and therefore')\"\n print \"( 2x,'the last interval integration is performed with the trapez rule;')\"\n w(1) = h / 3._O\n w(N-1) = 5._O * h / 6._O\n w(N) = h / 2._O\n do i = 2, N - 2, 2\n w(i) = 4._O * h / 3._O\n end do\n do i = 3, N - 3, 2\n w(i) = 2._O * h / 3._O\n end do \n end if\nend subroutine Simpson\n!***********************************************************************************\nsubroutine Trapez (a, b, N, x, w)\n!------------------------------------------------------------------------------------ \n! The routine computes the weights and nodes for the trapez integration method. !\n! !\n! Input parameters: !\n! - a, b (real variables) - lower and upper integration limits. !\n! - N (integer) - number of quadrature points. !\n! !\n! Output parameters: !\n! - w (real array) - weights. !\n! - x (real array) - quadrature points (nodes). !\n!------------------------------------------------------------------------------------\n use parameters\n implicit none\n integer :: N, i\n real(O) :: a, b, h, x(N), w(N), N1r, i1r\n! \n N1r = real(N - 1,O)\n h = (b - a) / N1r\n do i = 1, N\n i1r = real(i - 1,O)\n x(i) = a + i1r * h\n end do \n w(1) = 0.5_O * h\n w(N) = 0.5_O * h\n do i = 2, N - 1\n w(i) = h\n end do \nend subroutine Trapez\n! **********************************************************************************\n! * ROUTINES FOR COMPUTING THE NODES AND WEIGHTS *\n! * FOR GAUSSIAN-TYPE QUADRATURE RULES - NUMERICAL RECIPES *\n! **********************************************************************************\nsubroutine Gauss_Legendre1 (x1, x2, Np, wp, xp, epsGauss)\n!-----------------------------------------------------------------------------------\n! The significance of the input and ouput parameters is as in the routine !\n! Gauss_Legendre. The following parmeters control the computation: !\n! - TolRootPol (real) - if epsGauss < TolRootPol, then epsGauss is setted to !\n! TolRootPol. Default value: TolRootPol = MachEps. !\n! - NIterPol (integer) - maximum number of iteration for computing the roots !\n! with the desired accuracy. Default value: NIterPol = 100000. !\n! These parameters are specified in the routine \"DrvParameters\" from the file !\n! '../TMATROUTINES/MachParam.f90'. !\n!-----------------------------------------------------------------------------------\n use parameters\n use derived_parameters\n implicit none\n integer :: Np, i, j, M, iter\n real(O) :: x1, x2, wp(Np), xp(Np), xm, xl, z, p1, p2, p3, pp, z1, &\n jr, j1r, j2r, Npr, ir, epsGauss\n logical :: more\n! \n if (epsGauss < TolRootPol) then\n epsGauss = TolRootPol \n print \"(/,2x,'Warning in subroutine Gauss_Legendre in module Integr:')\"\n print \"( 2x,'the tolerance epsGauss is too low and epsGauss has been setted')\" \n print \"( 2x,'to TolRootPol, where TolRootPol =',1pe13.4,';')\", TolRootPol \n end if\n Npr = real(Np,O)\n M = int(0.5_O * (Npr + 1._O))\n xm = 0.5_O * (x1 + x2)\n xl = 0.5_O * (x2 - x1)\n do i = 1, M\n ir = real(i,O)\n z = cos(Pi * (ir - 0.25_O) / (Npr + 0.5_O))\n more =.true.\n iter = 0\n do while (more)\n iter = iter + 1 \n p1 = 1._O\n p2 = 0._O\n do j = 1,Np\n p3 = p2\n p2 = p1\n jr = real(j,O)\n j1r = real(j - 1,O)\n j2r = real(2 * j - 1,O)\n p1 = (j2r * z * p2 - j1r * p3) / jr\n end do\n pp = Npr * (z * p1 - p2) / (z * z - 1._O)\n z1 = z\n z = z1 - p1 / pp \n if (abs(z - z1) <= epsGauss .or. iter == NIterPol) more = .false.\n end do \n if (abs(z - z1) > epsGauss ) then \n print \"(/,2x,'Error in subroutine Gauss_Legendre in module Integr:')\"\n print \"( 2x,'the root was not determined with the prescribed accuracy because ')\"\n print \"( 2x,'the tolerance epsGauss or the iteration number NIterPol specified ')\"\n print \"( 2x,'in the subroutine MachParam are too low;')\"\n stop \n end if \n xp(i) = xm - xl * z\n xp(Np+1-i) = xm + xl * z\n wp(i) = 2._O * xl / ((1._O - z * z) * pp * pp)\n wp(Np+1-i) = wp(i)\n end do \nend subroutine Gauss_Legendre1\n! **********************************************************************************\nsubroutine Laguerre1 (n, x, a, epsLaguerre)\n!-----------------------------------------------------------------------------------\n! The significance of the input and ouput parameters is as in the routine !\n! Laquerre. The parameter NIterPol specifies the maximum number of iteration !\n! for computing the roots with the desired accuracy. NIterPol is specified in !\n! the routine \"DrvParameters\" from the file '../TMATROUTINES/MachParam.f90' and !\n! the default value is NIterPol = 100000. !\n!-----------------------------------------------------------------------------------\n use parameters\n implicit none\n integer :: n\n real(O) :: x(n), a(n), epsLaguerre\n! \n integer :: i, exp, j\n real(O) :: csx, csa, r1, dpn, pn1, xt, nr, i2r, tmp\n! \n nr = real(n,O) \n csx = 0._O\n csa = 0._O\n do i = 1, n\n if (i == 1) xt = 3._O / (1._O + 2.4_O * nr) \n if (i == 2) xt = xt + 15._O / (1._O + 2.5_O * nr) \n if (i > 2) then\n i2r = real(i - 2,O)\n r1 = (1._O + 2.55_O * i2r) / (1.9_O * i2r)\n xt = xt + r1 * (xt - x(i-2))\n end if\n call Lgroot (xt, n, dpn, pn1, epsLaguerre, exp)\n x(i) = xt\n tmp = 1._O / dpn / pn1 / nr\n if (exp > 0) then\n do j = 1, 2 * exp\n tmp = tmp * 0.1_O\n end do\n end if\n a(i) = tmp \n csx = csx + xt\n csa = csa + a(i)\n end do \nend subroutine Laguerre1\n! **********************************************************************************\nsubroutine Lgroot (x, n, dpn, pn1, epsLaguerre, exp)\n use parameters\n use derived_parameters\n implicit none \n integer :: n, exp\n real(O) :: x, dpn, pn1, epsLaguerre\n! \n integer :: iter\n real(O) :: p, d, dp\n logical :: more\n!\n iter = 0\n more = .true.\n do while (more)\n iter = iter + 1\n call Lgrecr (p, dp, pn1, x, n, exp)\n d = p / dp\n x = x - d \n if (abs(d / x) <= epsLaguerre .or. iter == NIterPol) more = .false. \n end do\n if (abs(d / x) > epsLaguerre ) then\n print \"(/,2x,'Error in subroutine Laguerre in module Integr:')\"\n print \"( 2x,'the root was not determined with the prescribed accuracy because the')\"\n print \"( 2x,'tolerance epsLaguerre or the iteration number NIterPol specified')\"\n print \"( 2x,'in the subroutine MachParam are too low;')\"\n stop\n end if\n dpn = dp \nend subroutine Lgroot\n! ******** *************************************************************************\nsubroutine Lgrecr (pn, dpn, pn1, x, n, exp)\n use parameters\n implicit none\n integer :: n, exp\n real(O) :: pn, dpn, pn1, x\n! \n integer :: j, dexp\n real(O) :: p1, p, dp1, dp, q, dq, jr, j1r, j2r, big, low\n!\n p1 = 1._O\n p = x - 1._O\n dp1 = 0._O\n dp = 1._O\n exp = 0\n big = 1.e+3_O\n low = 1.e-3_O \n dexp = int(log10(big))\n do j = 2, n\n jr = real(j,O)\n j1r = real(j - 1,O)\n j2r = real(2*j - 1,O)\n q = (x - j2r) * p / jr - j1r * p1 / jr\n dq = (x - j2r) * dp / jr + p / jr - j1r * dp1 / jr\n if (q > big .or. dq > big) then\n q = q * low\n dq = dq * low\n p = p * low\n dp = dp * low\n exp = exp + dexp\n end if\n p1 = p\n p = q\n dp1 = dp\n dp = dq\n end do\n pn = p\n dpn = dp\n pn1 = p1 \nend subroutine Lgrecr\n! **********************************************************************************\n! * ROUTINES FOR COMPUTING THE NODES AND WEIGHTS FOR GAUSSIAN-TYPE *\n! * QUADRATURE RULES - SIMPLIFIED VERSION FROM SLATEC LIBRARY *\n! **********************************************************************************\nsubroutine gaussq (kindt, n, b, t, w) \n!-----------------------------------------------------------------------------------\n! Input parameters: !\n! - kindt (integer) - specifies the type of quadrature rule, i.e., !\n! kindt = 1 for Legendre quadrature with w(x) = 1 on (-1, 1), and !\n! kindt = 2 for the generalized Laguerre quadrature with w(x) = exp(-x) on !\n! (0, +infinity). !\n! - n (integer) - number of points used for the quadrature rule. ! \n! - b (real array) - scratch array of length n. ! \n! !\n! Output parameters: !\n! - t (real array) - quadrature nodes. !\n! - w (real array) - weights. !\n!-----------------------------------------------------------------------------------\n use parameters \n implicit none\n integer :: kindt, n\n real(O) :: b(n), t(n), w(n)\n! \n integer :: i \n real(O) :: muzero \n! \n call class (kindt, n, b, t, muzero) \n w(1) = 1._O\n do i = 2, n\n w(i) = 0._O\n end do\n call gausq2 (kindt, n, t, b, w)\n do i = 1, n\n w(i) = muzero * w(i) * w(i)\n end do \nend subroutine gaussq\n!***********************************************************************************\nsubroutine class (kindt, n, b, a, muzero)\n use parameters\n implicit none\n integer :: kindt, n\n real(O) :: a(n), b(n), muzero\n! \n integer :: nm1, i \n real(O) :: abi\n!\n nm1 = n - 1\n if (kindt == 1) then\n muzero = 2._O\n do i = 1, nm1\n a(i) = 0._O\n abi = i\n b(i) = abi / sqrt(4._O * abi * abi - 1._O)\n end do\n a(n) = 0._O \n else if (kindt == 2) then \n muzero = 1._O \n do i = 1, nm1\n a(i) = 2._O * i - 1._O \n b(i) = real(i,O) \n end do\n a(n) = 2._O * n - 1 \n end if \nend subroutine class\n!***********************************************************************************\nsubroutine gausq2 (kindt, n, d, e, z)\n use parameters\n use derived_parameters\n implicit none\n integer :: kindt, n\n real(O) :: d(n), e(n), z(n)\n!\n integer :: i, j, k, l, m, ii, mml\n real(O) :: b, c, f, g, p, r, s\n! \n e(n) = 0._O\n do l = 1, n\n j = 0\n do while (j < NIterPol)\n j = j + 1 \n m = l - 1\n do while (m < n)\n m = m + 1 \n if (m < n .and. abs(e(m)) <= MachEps * (abs(d(m)) + abs(d(m+1)))) exit\n end do\n p = d(l)\n if (m == l) exit \n g = (d(l+1) - p) / (2._O * e(l))\n r = sqrt(g * g + 1._O)\n g = d(m) - p + e(l) / (g + sign(r, g))\n s = 1._O\n c = 1._O\n p = 0._O\n mml = m - l \n do ii = 1, mml\n i = m - ii\n f = s * e(i)\n b = c * e(i)\n if (abs(f) < abs(g)) then\n s = f / g\n r = sqrt(s * s + 1._O)\n e(i+1) = g * r\n c = 1._O / r\n s = s * c \n else\n c = g / f\n r = sqrt(c * c + 1._O)\n e(i+1) = f * r\n s = 1._O / r\n c = c * s\n end if \n g = d(i+1) - p\n r = (d(i) - g) * s + 2._O * c * b\n p = s * r\n d(i+1) = g + p\n g = c * r - b\n f = z(i+1)\n z(i+1) = s * z(i) + c * f\n z(i) = c * z(i) - s * f\n end do \n d(l) = d(l) - p\n e(l) = g\n e(m) = 0._O\n end do\n if (j == NIterPol) then\n if (kindt == 1) then\n print \"(/,2x,'Error in subroutine gausq2 in module Integr:')\"\n print \"( 2x,'the Legendre quadratures were not determined with the prescribed ')\"\n print \"( 2x,'accuracy, because the iteration number NIterPol specified in the')\"\n print \"( 2x,'subroutine MachParam is too low;')\"\n else if (kindt == 2) then\n print \"(/,2x,'Error in subroutine gausq2 in module Integr:')\"\n print \"( 2x,'the Laguerre quadratures were not determined with the prescribed ')\"\n print \"( 2x,'accuracy, because the iteration number NIterPol specified in the')\"\n print \"( 2x,'subroutine MachParam is too low;')\"\n end if \n stop\n end if \n end do \n do ii = 2, n\n i = ii - 1\n k = i\n p = d(i)\n do j = ii, n\n if (d(j) < p) then\n k = j\n p = d(j)\n end if \n end do\n if (k /= i) then\n d(k) = d(i)\n d(i) = p\n p = z(i)\n z(i) = z(k)\n z(k) = p\n end if \n end do \nend subroutine gausq2\n", "meta": {"hexsha": "abac1a34c7dd21d25cd6f23cc1bf24a1ce624427", "size": 22846, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "smuthi/linearsystem/tmatrix/nfmds/NFM-DS/TMATSOURCES/Integr.f90", "max_stars_repo_name": "parkerwray/smuthi-1", "max_stars_repo_head_hexsha": "a5ced07461b8fd223dc37d28259261ceed78aed5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "smuthi/linearsystem/tmatrix/nfmds/NFM-DS/TMATSOURCES/Integr.f90", "max_issues_repo_name": "parkerwray/smuthi-1", "max_issues_repo_head_hexsha": "a5ced07461b8fd223dc37d28259261ceed78aed5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "smuthi/linearsystem/tmatrix/nfmds/NFM-DS/TMATSOURCES/Integr.f90", "max_forks_repo_name": "parkerwray/smuthi-1", "max_forks_repo_head_hexsha": "a5ced07461b8fd223dc37d28259261ceed78aed5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.9426523297, "max_line_length": 96, "alphanum_fraction": 0.3940295894, "num_tokens": 6125, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218391455085, "lm_q2_score": 0.746138993030751, "lm_q1q2_score": 0.6878818327130878}} {"text": "module subgenerator\n implicit none\n\n integer, parameter :: modulus = 1000000000\n integer :: s(0:54), r(0:54)\n\ncontains\n\nsubroutine initgen(seed)\n integer :: seed\n integer :: n, rnum\n\n s(0) = seed\n s(1) = 1\n\n do n = 2, 54\n s(n) = mod(s(n-2) - s(n-1), modulus)\n if (s(n) < 0) s(n) = s(n) + modulus\n end do\n\n do n = 0, 54\n r(n) = s(mod(34*(n+1), 55))\n end do\n\n do n = 1, 165\n rnum = subrand()\n end do\n\nend subroutine initgen\n\ninteger function subrand()\n integer, save :: p1 = 0\n integer, save :: p2 = 31\n\n r(p1) = mod(r(p1) - r(p2), modulus)\n if (r(p1) < 0) r(p1) = r(p1) + modulus\n subrand = r(p1)\n p1 = mod(p1 + 1, 55)\n p2 = mod(p2 + 1, 55)\n\nend function subrand\nend module subgenerator\n\nprogram subgen_test\n use subgenerator\n implicit none\n\n integer :: seed = 292929\n integer :: i\n\n call initgen(seed)\n do i = 1, 10\n write(*,*) subrand()\n end do\n\nend program\n", "meta": {"hexsha": "b93c73dc483bd93623d2ee215db1eae065b8cf61", "size": 901, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Subtractive-generator/Fortran/subtractive-generator.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/Subtractive-generator/Fortran/subtractive-generator.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/Subtractive-generator/Fortran/subtractive-generator.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": 15.8070175439, "max_line_length": 44, "alphanum_fraction": 0.5837957825, "num_tokens": 357, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218348550491, "lm_q2_score": 0.7461389930307512, "lm_q1q2_score": 0.6878818295118088}} {"text": "\n\n subroutine hencky_elasticity(matData,F,stre,cc,finite)\n\n implicit none\n\n integer finite,\n * i, round\n double precision matData(*), F(3,*), stre(*), cc(6,*),\n * mu, K, Lamb, b(6), fact, h(6),\n * tau(6), dtaudb(6,6),\n * det_u, r1dJ, J, J2\n\n if (finite.eq.0) then\n call small_strain_elasticity(matData,F,stre,cc)\n return\n endif\n\n K = matData(1)\n mu = matData(2)\n\n call calcB(b,F)\n\n J = det_u(F)\n\n J2 = J * J\n\n call log_s(tau,dtaudb,b,10)\n\n call set_s_f(tau,tau,mu)\n\n fact = K * .5d0 * (J2 - 1.d0) - mu / 1.5d0 * log(J)\n\n call unit_s_p(h)\n call set_s_af(tau,h,fact)\n\n call set_4_f(dtaudb,dtaudb,mu)\n\n call pzero(stre,6)\n call pzero(cc, 36)\n\n call taub2sigccPart1(stre,cc,tau,dtaudb,b,J)\n\n fact = K * J - mu / (J*1.5d0)\n\n do i=1, 3\n cc(i,1) = cc(i,1) + fact\n cc(i,2) = cc(i,2) + fact\n cc(i,3) = cc(i,3) + fact\n enddo\n\n call taub2sigccPart2(stre,cc)\n\n return\n\n end\n\n\n\n\n\n", "meta": {"hexsha": "8b297c0b2e5e3243726152491898eb996c3b6297", "size": 1131, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/material/hencky_elasticity.for", "max_stars_repo_name": "chennachaos/mpap", "max_stars_repo_head_hexsha": "99d02bc9075b72b899a167d1bbc2bf73584b85bc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-12-30T16:45:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-29T23:27:29.000Z", "max_issues_repo_path": "src/material/hencky_elasticity.for", "max_issues_repo_name": "chennachaos/mpap", "max_issues_repo_head_hexsha": "99d02bc9075b72b899a167d1bbc2bf73584b85bc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2019-11-22T12:57:55.000Z", "max_issues_repo_issues_event_max_datetime": "2020-11-04T22:01:42.000Z", "max_forks_repo_path": "src/material/hencky_elasticity.for", "max_forks_repo_name": "chennachaos/mpap", "max_forks_repo_head_hexsha": "99d02bc9075b72b899a167d1bbc2bf73584b85bc", "max_forks_repo_licenses": ["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.2419354839, "max_line_length": 60, "alphanum_fraction": 0.4712643678, "num_tokens": 409, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218262741297, "lm_q2_score": 0.7461389930307512, "lm_q1q2_score": 0.6878818231092502}} {"text": "real(kind=8) pure function get_max_speed(val,mitot,mjtot,nvar,aux,naux,nghost,hx,hy)\n\n use geoclaw_module, only: dry_tolerance, coordinate_system\n use geoclaw_module, only: grav, earth_radius, DEG2RAD\n \n implicit none\n \n ! Arguments\n integer, intent(in) :: mitot,mjtot,nvar,naux,nghost\n real(kind=8), intent(in) :: hx,hy\n real(kind=8), intent(in) :: val(nvar,mitot,mjtot), aux(naux,mitot,mjtot)\n \n ! Locals\n integer :: i,j\n real(kind=8) :: ymetric,hyphys,xmetric,hxphys,u,v,sig,sp_over_h\n\n\n sp_over_h = 0.d0 ! compute max speed over h, since dx may not equal dy\n if (coordinate_system == 2) then\n do j = nghost+1, mjtot-nghost\n ymetric = earth_radius*deg2rad\n hyphys = ymetric*hy\n\n do i = nghost+1, mitot-nghost\n xmetric = cos(aux(3,i,j)) * earth_radius * DEG2RAD\n hxphys = xmetric * hx\n if (val(1,i,j) > dry_tolerance) then\n u = val(2,i,j) / val(1,i,j)\n v = val(3,i,j) / val(1,i,j)\n else\n u = 0.d0\n v = 0.d0\n endif\n sig = sqrt(grav*val(1,i,j))\n sp_over_h = max((abs(u)+sig)/hxphys,(abs(v)+sig)/hyphys,sp_over_h)\n end do\n end do\n else ! speeds in cartesian coords, no metrics needed\n do j = nghost+1, mjtot-nghost\n do i = nghost+1, mitot-nghost\n if (val(1,i,j) > dry_tolerance) then\n u = val(2,i,j) / val(1,i,j)\n v = val(3,i,j) / val(1,i,j)\n else\n u = 0.d0\n v = 0.d0\n endif\n sig = sqrt(grav*val(1,i,j))\n sp_over_h = max((abs(u)+sig)/hx,(abs(v)+sig)/hy,sp_over_h)\n end do\n end do\n endif\n \n get_max_speed = sp_over_h\n\nend function get_max_speed\n", "meta": {"hexsha": "4940deaa49f512de7051fecb3297c90c4a28cd61", "size": 1937, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/2d/shallow/getmaxspeed.f90", "max_stars_repo_name": "delgadom/geoclaw", "max_stars_repo_head_hexsha": "8893cf487e2972bf67e455bbb58b236ec24150bb", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2017-01-04T18:19:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-21T01:46:33.000Z", "max_issues_repo_path": "src/2d/shallow/getmaxspeed.f90", "max_issues_repo_name": "delgadom/geoclaw", "max_issues_repo_head_hexsha": "8893cf487e2972bf67e455bbb58b236ec24150bb", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 19, "max_issues_repo_issues_event_min_datetime": "2018-09-06T17:30:42.000Z", "max_issues_repo_issues_event_max_datetime": "2019-04-12T00:24:22.000Z", "max_forks_repo_path": "src/2d/shallow/getmaxspeed.f90", "max_forks_repo_name": "BrisaDavis/geoclaw", "max_forks_repo_head_hexsha": "ccab58669bc2950de13cf0f35c10b3cd1cb1cda6", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2016-09-22T20:20:06.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-13T14:48:32.000Z", "avg_line_length": 33.9824561404, "max_line_length": 84, "alphanum_fraction": 0.5054207537, "num_tokens": 582, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218348550491, "lm_q2_score": 0.7461389817407016, "lm_q1q2_score": 0.6878818191032656}} {"text": "SUBROUTINE emb_2d_geom(iel,nx1,nx2,ny1,ny2,w1,s1,w2,h1,h2,coord,num)\n! Used in p64\n! This subroutine forms the nodal coordinates and numbering for a 2-d\n! slope of 8-node quadrilaterals. Nodes numbering in the y-direction,\n! elements numbered in the x-direction.\n!\n IMPLICIT NONE\n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\n REAL(iwp),INTENT(IN)::w1,s1,w2,h1,h2\n INTEGER,INTENT(IN)::iel,nx1,nx2,ny1,ny2\n REAL(iwp),INTENT(OUT)::coord(:,:)\n INTEGER,INTENT(OUT)::num(:)\n REAL(iwp)::facx,facy,facb,facs,frh,zero=0.0_iwp,pt5=0.5_iwp,one=1.0_iwp\n INTEGER::nxe,nye,nc,nt,ip,iq\n nxe=nx1+nx2\n nye=ny1+ny2\n nt=nx1*ny1\n nc=(3*nye+2)*nx1+2*ny1\n facx=s1/ny1\n facy=h1/ny1\n facb=(w1+s1)/nx1\n facs=zero\n IF(ny2/=0)facs=h2/ny2\n frh=zero\n IF(nx2/=0)frh=w2/nx2\n IF(iel<=nt)THEN\n iq=(iel-1)/nx1+1\n ip=iel-(iq-1)*nx1\n ELSE\n iq=(iel-nt-1)/nxe+ny1+1\n ip=iel-nt-(iq-ny1-1)*nxe\n END IF\n IF(ip<=nx1)THEN\n num(1)=(ip-1)*(3*nye+2)+2*iq+1\n num(2)=num(1)-1\n num(3)=num(1)-2\n num(4)=(ip-1)*(3*nye+2)+2*nye+iq+1\n num(5)=ip*(3*nye+2)+2*iq-1\n num(6)=num(5)+1\n num(7)=num(5)+2\n num(8)=num(4)+1\n IF(iq<=ny1)THEN\n coord(1,1)=(ip-one)*(w1+iq*facx)/nx1\n coord(3,1)=(ip-one)*(w1+(iq-1)*facx)/nx1\n coord(5,1)=ip*(w1+(iq-1)*facx)/nx1\n coord(7,1)=ip*(w1+iq*facx)/nx1\n coord(1,2)=-iq*facy\n coord(3,2)=-(iq-1)*facy\n coord(5,2)=-(iq-1)*facy\n coord(7,2)=-iq*facy\n ELSE\n coord(1,1)=(ip-one)*facb\n coord(3,1)=(ip-one)*facb\n coord(5,1)=ip*facb\n coord(7,1)=ip*facb\n coord(1,2)=-h1-(iq-ny1)*facs\n coord(3,2)=-h1-(iq-ny1-1)*facs\n coord(5,2)=-h1-(iq-ny1-1)*facs\n coord(7,2)=-h1-(iq-ny1)*facs\n END IF\n ELSE\n num(1)=nc+(ip-nx1-1)*(3*ny2+2)+2*(iq-ny1)+1\n num(2)=num(1)-1\n num(3)=num(1)-2\n num(4)=nc+(ip-nx1-1)*(3*ny2+2)+2*ny2+iq-ny1+1\n num(5)=nc+(ip-nx1)*(3*ny2+2)+2*(iq-ny1)-1\n num(6)=num(5)+1\n num(7)=num(5)+2\n num(8)=num(4)+1\n coord(1,1)=w1+s1+(ip-nx1-1)*frh\n coord(3,1)=coord(1,1)\n coord(5,1)=w1+s1+(ip-nx1)*frh\n coord(7,1)=coord(5,1)\n coord(1,2)=-h1-(iq-ny1)*facs\n coord(3,2)=-h1-(iq-ny1-1)*facs\n coord(5,2)=-h1-(iq-ny1-1)*facs\n coord(7,2)=-h1-(iq-ny1)*facs\n END IF\n coord(2:6:2,:)=pt5*(coord(1:5:2,:)+coord(3:7:2,:))\n coord(8,:)=pt5*(coord(7,:)+coord(1,:))\nRETURN\nEND SUBROUTINE emb_2d_geom\n", "meta": {"hexsha": "b1757e6730d6884793f373e21ee177c33abacc3f", "size": 2269, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "geom/emb_2d_geom.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": "geom/emb_2d_geom.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": "geom/emb_2d_geom.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": 27.3373493976, "max_line_length": 72, "alphanum_fraction": 0.5985015425, "num_tokens": 1176, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218262741297, "lm_q2_score": 0.7461389873857265, "lm_q1q2_score": 0.6878818179049787}} {"text": "program test_qr_factorization\n use mod_orrb\n implicit none\n\n character(len=40) :: test_name\n character(len=*), parameter :: fmt=\"(A40, 'Time: ',ES8.2,', lbw: ',I3,', ubw: ', I3,', error: ',ES8.2, ', ', A10)\"\n\n real(kind=dp) :: t0, t1\n integer(kind=int32) :: na, lbwa, ubwa\n type(error_info) :: error\n real(kind=dp), parameter :: tol=1e-15, c=2.5\n !\n\n real(kind=dp), dimension(:,:), allocatable :: a_d, a0_d\n complex(kind=dp), dimension(:,:), allocatable :: a_z, a0_z\n\n type(d_bv), allocatable :: bv_d\n type(z_bv), allocatable :: bv_z\n type(d_qr), allocatable :: swub_d\n type(z_qr), allocatable :: swub_z\n\n call initialize_errors\n print *\n print *, \"--------------------------------\"\n print *\n print *, \"Real QR Factorization Tests\"\n print *\n !\n ! full qr factorization\n !\n na=40; lbwa=3; ubwa=5\n bv_d=d_random_bv(na,lbwa,ubwa,error=error)\n a_d = general(bv_d,error)\n a0_d = a_d\n call cpu_time(t0)\n swub_d=qr_of(bv_d,error)\n call cpu_time(t1) \n a_d = general(swub_d%ub,error)\n a_d = swub_d%sw * a_d\n test_name = \"Random Real QR Factorization\"\n call d_output_result(test_name,a0_d,a_d,0, &\n swub_d%ub%lbw, min(ubwa+lbwa,na-1),swub_d%ub%ubw,t0,t1,c*tol,error)\n\n na=1; lbwa=0; ubwa=0\n bv_d=d_random_bv(na,lbwa,ubwa,error=error)\n a_d = general(bv_d,error)\n a0_d = a_d\n call cpu_time(t0)\n swub_d=qr_of(bv_d,error)\n call cpu_time(t1) \n a_d = general(swub_d%ub,error)\n a_d = swub_d%sw * a_d\n test_name = \"Random Real QR Factorization, n=1\"\n call d_output_result(test_name,a0_d,a_d,0, &\n swub_d%ub%lbw, min(ubwa+lbwa,na-1), swub_d%ub%ubw,t0,t1,c*tol,error)\n\n na=2; lbwa=1; ubwa=1\n bv_d=d_random_bv(na,lbwa,ubwa,error=error)\n a_d = general(bv_d,error)\n a0_d = a_d\n call cpu_time(t0)\n swub_d=qr_of(bv_d,error)\n call cpu_time(t1) \n a_d = general(swub_d%ub,error)\n a_d = swub_d%sw * a_d\n test_name = \"Random Real QR Factorization, n=2\"\n call d_output_result(test_name,a0_d,a_d,0, &\n swub_d%ub%lbw, min(ubwa+lbwa,na-1), swub_d%ub%ubw,t0,t1,c*tol,error)\n\n na=3; lbwa=1; ubwa=1\n bv_d=d_random_bv(na,lbwa,ubwa,error=error)\n a_d = general(bv_d,error)\n a0_d = a_d\n call cpu_time(t0)\n swub_d=qr_of(bv_d,error)\n call cpu_time(t1) \n a_d = general(swub_d%ub,error)\n a_d = swub_d%sw * a_d\n test_name = \"Random Real QR Factorization, n=3\"\n call d_output_result(test_name,a0_d,a_d,0, &\n swub_d%ub%lbw, min(ubwa+lbwa,na-1), swub_d%ub%ubw,t0,t1,c*tol,error)\n\n na=4; lbwa=2; ubwa=2\n bv_d=d_random_bv(na,lbwa,ubwa,error=error)\n a_d = general(bv_d,error)\n a0_d = a_d\n call cpu_time(t0)\n swub_d=qr_of(bv_d,error)\n call cpu_time(t1) \n a_d = general(swub_d%ub,error)\n a_d = swub_d%sw * a_d\n test_name = \"Random Real QR Factorization, n=4\"\n call d_output_result(test_name,a0_d,a_d,0, &\n swub_d%ub%lbw, min(ubwa+lbwa,na-1), swub_d%ub%ubw,t0,t1,c*tol,error)\n \n !\n print *\n print *, \"--------------------------------\"\n print *\n print *, \"Complex QR Factorization Tests\"\n print *\n\n na=40; lbwa=3; ubwa=5\n bv_z=z_random_bv(na,lbwa,ubwa,error=error)\n a_z = general(bv_z,error)\n a0_z = a_z\n call cpu_time(t0)\n swub_z=qr_of(bv_z,error)\n call cpu_time(t1) \n a_z = general(swub_z%ub,error)\n a_z = swub_z%sw * a_z\n test_name = \"Random Complex QR Factorization\"\n call z_output_result(test_name,a0_z,a_z,0, &\n swub_z%ub%lbw, min(ubwa+lbwa,na-1),swub_z%ub%ubw,t0,t1,c*tol,error)\n\n na=1; lbwa=0; ubwa=0\n bv_z=z_random_bv(na,lbwa,ubwa,error=error)\n a_z = general(bv_z,error)\n a0_z = a_z\n call cpu_time(t0)\n swub_z=qr_of(bv_z,error)\n call cpu_time(t1) \n a_z = general(swub_z%ub,error)\n a_z = swub_z%sw * a_z\n test_name = \"Random Complex QR Factorization, n=1\"\n call z_output_result(test_name,a0_z,a_z,0, &\n swub_z%ub%lbw, min(ubwa+lbwa,na-1), swub_z%ub%ubw,t0,t1,c*tol,error)\n\n na=2; lbwa=1; ubwa=1\n bv_z=z_random_bv(na,lbwa,ubwa,error=error)\n a_z = general(bv_z,error)\n a0_z = a_z\n call cpu_time(t0)\n swub_z=qr_of(bv_z,error)\n call cpu_time(t1) \n a_z = general(swub_z%ub,error)\n a_z = swub_z%sw * a_z\n test_name = \"Random Complex QR Factorization, n=2\"\n call z_output_result(test_name,a0_z,a_z,0, &\n swub_z%ub%lbw, min(ubwa+lbwa,na-1), swub_z%ub%ubw,t0,t1,c*tol,error)\n\n na=3; lbwa=1; ubwa=1\n bv_z=z_random_bv(na,lbwa,ubwa,error=error)\n a_z = general(bv_z,error)\n a0_z = a_z\n call cpu_time(t0)\n swub_z=qr_of(bv_z,error)\n call cpu_time(t1) \n a_z = general(swub_z%ub,error)\n a_z = swub_z%sw * a_z\n test_name = \"Random Complex QR Factorization, n=3\"\n call z_output_result(test_name,a0_z,a_z,0, &\n swub_z%ub%lbw, min(ubwa+lbwa,na-1), swub_z%ub%ubw,t0,t1,c*tol,error)\n\n na=4; lbwa=2; ubwa=2\n bv_z=z_random_bv(na,lbwa,ubwa,error=error)\n a_z = general(bv_z,error)\n a0_z = a_z\n call cpu_time(t0)\n swub_z=qr_of(bv_z,error)\n call cpu_time(t1) \n a_z = general(swub_z%ub,error)\n a_z = swub_z%sw * a_z\n test_name = \"Random Complex QR Factorization, n=4\"\n call z_output_result(test_name,a0_z,a_z,0, &\n swub_z%ub%lbw, min(ubwa+lbwa,na-1), swub_z%ub%ubw,t0,t1,c*tol,error)\n\ncontains\n\n subroutine d_output_result(name,a0,a1,lbw0,lbw1,ubw0,ubw1,t0,t1,bnd,error)\n character(len=*) :: name\n real(kind=dp), dimension(:,:) :: a0, a1 \n real(kind=dp) :: bnd, t0, t1\n integer(kind=int32) :: lbw0, lbw1, ubw0, ubw1\n type(error_info) :: error\n\n real(kind=dp) :: berr\n character(len=10) :: test_result\n\n if (error%code > 0) then\n print *, \"Calling error in test: \", name\n else\n berr = maxabs(a1-a0)\n if (lbw0==lbw1 .and. ubw0==ubw1 .and. berr < bnd) then\n test_result=\"PASSED\"\n else\n test_result=\" FAILED\"\n end if\n write (*,fmt) name, t1-t0, lbw1, ubw1, berr, test_result\n end if\n end subroutine d_output_result\n\n subroutine z_output_result(name,a0,a1,lbw0,lbw1,ubw0,ubw1,t0,t1,bnd,error)\n character(len=*) :: name\n complex(kind=dp), dimension(:,:) :: a0, a1 \n real(kind=dp) :: bnd, t0, t1\n integer(kind=int32) :: lbw0, lbw1, ubw0, ubw1\n type(error_info) :: error\n\n real(kind=dp) :: berr\n character(len=10) :: test_result\n\n if (error%code > 0) then\n print *, \"Calling error in test: \", name\n else\n berr = maxabs(a1-a0)\n if (lbw0==lbw1 .and. ubw0==ubw1 .and. berr < bnd) then\n test_result=\"PASSED\"\n else\n test_result=\" FAILED\"\n end if\n write (*,fmt) name, t1-t0, lbw1, ubw1, berr, test_result\n end if\n end subroutine z_output_result\n \nend program test_qr_factorization\n", "meta": {"hexsha": "cb5f0fc55c7e93c7e590810dccc5ec1b90cfd153", "size": 6487, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/test_qr_factorization.f90", "max_stars_repo_name": "m-a-stewart/BandGivensWeight", "max_stars_repo_head_hexsha": "f7858d3d0dd95e87a891dc583233e64650209288", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/test_qr_factorization.f90", "max_issues_repo_name": "m-a-stewart/BandGivensWeight", "max_issues_repo_head_hexsha": "f7858d3d0dd95e87a891dc583233e64650209288", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/test_qr_factorization.f90", "max_forks_repo_name": "m-a-stewart/BandGivensWeight", "max_forks_repo_head_hexsha": "f7858d3d0dd95e87a891dc583233e64650209288", "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": 29.8940092166, "max_line_length": 116, "alphanum_fraction": 0.6511484507, "num_tokens": 2541, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797148356994, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6878632274834647}} {"text": "!--------------------------------------------------------------------------------------\n!\n!Copyright (C) 2014 TopCoder Inc., All Rights Reserved.\n!\n!--------------------------------------------------------------------------------------\n\n! This module computes the influence coefficient according to R2 for the regular part and\n! to R1 for the rankine part. It only perform the computation for the infinite depth case\n!\n! R1 Distributions of sources and normal dipoles\n!over a quadrilateral panel (Available in another contest (Dipoles, request permission) document paper 2\n!http://community.topcoder.com/tc?\n!module=DownloadDocument&docid=27516374 )\n!\n! R2 A second order Ordinary Differential Equation for the frequency\n!domain Green function http://www.iwwwfb.org/Abstracts/iwwwfb28/iwwwfb28_12.pdf\n!\n! Contest Code Acceleration of the Calculation of Influence Coefficients of Nemoh\n!\n! @author yedtoss\n! @version 1.0\n\nmodule COMPUTE_INFLUENCE_ODE\n\n USE ODE\n USE COM_VAR\n USE COMMON_TYPE\n implicit none\n\n\ncontains\n\n complex function influence_infinite_source_wave_part(w,y, param)\n ! This is the function representing the expression of the ODE of the green function\n ! See equation 11 of reference R2\n real r, w, Z\n complex y(0:10)\n TYPE(ParamsCommonInf) :: param\n complex tmp\n\n r = param%r\n Z = param%Z\n\n tmp = 2.*(1. + Z*w**2)/(sqrt(r**2 + Z**2)) + w*(w**2*Z + 3./4.)*y(1)\n\n tmp = tmp - (w**4*(r**2 + Z**2) + w**2*Z +1 )* y(0)\n if(abs(w) < tolerance) then\n tmp = 0\n else\n tmp = tmp/(w**2/4.)\n end if\n\n influence_infinite_source_wave_part = tmp\n end function\n\n\n complex function influence_infinite_dipoles_wave_part(w,y, param)\n ! This is the function representing the expression of the ODE of the derivative of the green function with\n ! respect to r\n ! See corresponding equation in Deployment guide\n\n real r, w, Z\n complex y(0:10)\n TYPE(ParamsCommonInf) :: param\n complex tmp\n\n r = param%r\n Z = param%Z\n\n tmp = -6.*r*(1. + Z*w**2)/((r**2 + Z**2)**(3./2.))\n tmp = tmp + w*(w**2*Z + 3./4.)*y(1)\n\n tmp = tmp - (w**4*(r**2 + Z**2) + 3.*w**2*Z + 3 )* y(0)\n\n if(abs(w) < tolerance) then\n tmp = 0\n else\n tmp = tmp/(w**2/4.)\n end if\n\n influence_infinite_dipoles_wave_part = tmp\n\n end function\n\n\n complex function influence_infinite_dipoles_wave_part_z(w,y, param)\n ! This is the function representing the expression of the ODE of the derivative of the green function with\n ! respect to z\n ! See corresponding equation in Deployment guide\n\n real r, w, z\n complex y(0:10)\n TYPE(ParamsCommonInf) :: param\n complex tmp\n\n r = param%r\n Z = param%Z\n\n tmp = (-8.*Z -(w**2)*(4.*Z**2 - 2.*r**2))/((r**2 + Z**2)**(3./2.))\n tmp = tmp + w*(w**2*Z + 3./4.)*y(1)\n\n tmp = tmp - (w**4*(r**2 + Z**2) + 3.*w**2*Z + 4 )* y(0)\n\n if(abs(w) < tolerance) then\n tmp = 0\n else\n tmp = tmp/(w**2/4.)\n end if\n\n influence_infinite_dipoles_wave_part_z = tmp\n\n end function\n\n real function compute_rankine_dipoles(ISP, IFP)\n\n ! Computing formula 2.14 with 2.15 as insight of\n ! Distributions of sources and normal dipoles over a quadrilateral panel\n\n INTEGER :: ISP ! source point\n\n INTEGER :: IFP !Field point\n\n INTEGER:: I, M(4)\n\n REAL:: s1, c1, s2, c2, nu_n, nu_n1, psi_n, psi_n1, delta_n, delta_n1, rn, rn_1, xx, yy, zz\n\n REAL :: s3, c3\n\n REAL, PARAMETER :: PI=4.*ATAN(1.)\n\n !!$OMP CRITICAL\n !We are safe without a critical or atomic operation. Although we are\n ! using it's value, a value of 0 is safe and when it is 1 it is also safe\n IF(is_rankine_dipoles_computed == 1) THEN\n compute_rankine_dipoles = rankine_dipoles_cache(ISP, IFP)\n RETURN\n END IF\n !!$OMP END CRITICAL\n\n\n ! Getting index of the coordinate of the 4 vertices\n M(1) = M1(IFP)\n M(2) = M2(IFP)\n M(3) = M3 (IFP)\n M(4) = M4 (IFP)\n\n compute_rankine_dipoles = 0\n\n ! Getting centroid coordinate\n xx = XG(ISP) ! Source point x\n yy = YG(ISP) ! Source point y\n zz = ZG(ISP) ! Source point z\n\n\n DO I =1,4\n\n nu_n = Y(M(I)) ! y coordinate of vertice n\n nu_n1 = Y(modulo(M(I),4) +1) ! y coordinate of vertice n +1\n psi_n = X(M(I)) ! x coordinate of vertice n\n psi_n1 = X(modulo(M(I),4) +1) ! x coordinate of vertice n +1\n\n delta_n = nu_n1 - nu_n\n delta_n1 = Y(modulo(M(I+1),4) + 1) - nu_n1\n\n ! If both vertices are the same, it means we have a triangle instead of quadrilateral.\n ! We can thus skip this point\n if (abs(delta_n) < tolerance .and. abs(psi_n1 - psi_n) < tolerance) then\n CYCLE\n end if\n\n\n ! Spherical coordinate http://mathworld.wolfram.com/SphericalCoordinates.html\n ! Radial distance between vertice n and the field point\n rn = sqrt((xx - psi_n)**2 + (yy - nu_n)**2 + zz**2)\n ! Radial distance between vertice n+1 and the field point\n rn_1 = sqrt((xx - psi_n1)**2 + (yy - nu_n1)**2 + zz**2)\n\n s1 = delta_n* ((xx -psi_n)**2 + zz**2) - delta_n* (xx -psi_n) *(yy -nu_n)\n c1 = rn*zz* delta_n\n\n s2 = delta_n* ((xx -psi_n1)**2 + zz**2) - delta_n* (xx -psi_n1) *(yy -nu_n1)\n c2 = rn_1*zz* delta_n\n\n\n s3 = s1*c2 - s2*c1\n c3 = c1*c2 + s1*s2\n\n ! If c3 is near 0 the angle tends to pi/2\n if (abs(c3) < tolerance) then\n compute_rankine_dipoles = compute_rankine_dipoles + PI/2.\n else\n compute_rankine_dipoles = compute_rankine_dipoles + atan(s3/c3)\n end if\n\n END DO\n\n !!$OMP CRITICAL\n !We are safe without a critical or atomic operation. Although we are\n ! updating it's value, any thread updating it simulatenous will do so with the same value\n rankine_dipoles_cache(ISP, IFP) = compute_rankine_dipoles\n !!$OMP END CRITICAL\n\n\n end function\n\n\n real function compute_rankine_sources(ISP, IFP)\n\n\n ! Computing formula 3.10\n ! Distributions of sources and normal dipoles over a quadrilateral panel\n\n INTEGER :: ISP ! source point\n\n INTEGER :: IFP !Field point\n\n REAL:: s1, c1, s2, c2, nu_n, nu_n1, psi_n, psi_n1, delta_n, delta_n1, rn, rn_1, xx, yy, zz\n\n REAL :: s3, c3,s ,c, theta_n, theta_n1, sn\n\n INTEGER:: I, M(4)\n\n REAL, PARAMETER :: PI=4.*ATAN(1.)\n\n !!$OMP CRITICAL\n !We are safe without a critical or atomic operation. Although we are\n ! using it's value, a value of 0 is safe and when it is 1 it is also safe\n IF(is_rankine_sources_computed == 1) THEN\n compute_rankine_sources = rankine_sources_cache(ISP, IFP)\n RETURN\n END IF\n !!$OMP END CRITICAL\n\n ! Getting index of the coordinate of the 4 vertices\n M(1) = M1(IFP)\n M(2) = M2(IFP)\n M(3) = M3 (IFP)\n M(4) = M4 (IFP)\n\n compute_rankine_sources = 0\n\n ! Getting centroid coordinate\n xx = XG(ISP) ! Source point x\n yy = YG(ISP) ! Source point y\n zz = ZG(ISP) ! Source point z\n\n\n DO I =1,4\n\n nu_n = Y(M(I)) ! y coordinate of vertice n\n nu_n1 = Y(modulo(M(I),4) +1) ! y coordinate of vertice n +1\n psi_n = X(M(I)) ! x coordinate of vertice n\n psi_n1 = X(modulo(M(I),4) +1) ! x coordinate of vertice n +1\n\n delta_n = nu_n1 - nu_n\n delta_n1 = Y(modulo(M(I+1),4) + 1) - nu_n1\n\n ! If both vertices are the same, it means we have a triangle instead of quadrilateral.\n ! We can thus skip this point\n if (abs(delta_n) < tolerance .and. abs(psi_n1 - psi_n) < tolerance) then\n CYCLE\n end if\n\n ! If delta_n is near 0 the angle tends to pi/2\n if (abs(delta_n) < tolerance) then\n theta_n = PI/2.\n else\n !http://stackoverflow.com/questions/2676719/calculating-the-angle-between-the-line-defined-by-two-points\n theta_n = atan(delta_n/(psi_n1 - psi_n))\n endif\n\n ! sn is the length between vertices n and vertices n+1. Note that z=0 because it is a flat panel\n sn = sqrt((psi_n1 - psi_n)**2 + (delta_n1- delta_n)**2)\n\n\n\n ! Spherical coordinate http://mathworld.wolfram.com/SphericalCoordinates.html\n ! Radial distance between vertice n and the field point\n rn = sqrt((xx - psi_n)**2 + (yy - nu_n)**2 + zz**2)\n ! Radial distance between vertice n+1 and the field point\n rn_1 = sqrt((xx - psi_n1)**2 + (yy - nu_n1)**2 + zz**2)\n\n ! Using intermediate variable s to avoid long expression or complicated multi line expressions\n s = (xx- psi_n)* sin(theta_n) - (yy - nu_n)*cos(theta_n)*log((rn + rn_1 + sn)/(rn + rn_1 - sn))\n\n compute_rankine_sources = compute_rankine_sources + s\n\n\n\n END DO\n\n compute_rankine_sources = compute_rankine_sources - zz*compute_rankine_dipoles(ISP, IFP)\n !!$OMP CRITICAL\n !We are safe without a critical or atomic operation. Although we are\n ! updating it's value, any thread updating it simulatenous will do so with the same value\n rankine_sources_cache(ISP, IFP) = compute_rankine_sources\n !!$OMP END CRITICAL\n end function\n\n subroutine compute_influence_infinite_sources(w, ZIJ)\n\n INTEGER :: ISP ! source point\n\n INTEGER :: IFP !Field point\n\n REAL:: r, G0, dG0, Z, w\n\n complex yi(0:10),t(50)\n COMPLEX, DIMENSION(:, :):: ZIJ ! influence coefficients\n COMPLEX:: Gn(IMX, IMX) ! Cache of green function\n\n TYPE(ParamsCommonInf) :: param\n\n DO ISP=1,IMX\n\n DO IFP=1,IMX\n\n Z = ZG(ISP) + ZG(IFP)\n r = sqrt((XG(ISP) - XG(IFP))**2 + (YG(ISP) - YG(IFP))**2 )\n\n G0 = cmplx(2./(sqrt(r**2 + Z**2)), 0.)\n dG0 = cmplx(0 , 0)\n\n yi(0) = G0\n yi(1) = dG0\n\n param%w = w\n param%Z = Z\n param%r = r\n\n\n ! Compute Wave part/ regular part of green function\n if(ISP <= IFP) then\n ! A 3x4 runge kutta is enough for convergence\n t = Equadifnc(influence_infinite_source_wave_part, 0., w, yi, 1, 2, 3, param )\n Gn(ISP, IFP) = t(2)\n Gn(IFP, ISP) = t(2)\n else\n t(2) = Gn(IFP, ISP)\n end if\n\n ! Double integral done by multiplying by the area\n ZIJ(ISP, IFP) = t(2)* AIRE(IFP) + compute_rankine_sources(ISP, IFP)\n\n END DO\n\n END DO\n end subroutine compute_influence_infinite_sources\n\n\n\n subroutine compute_influence_infinite_dipoles(w, ZIJ)\n ! This compute the influence coefficients containing the derivative of the green function\n !\n\n INTEGER :: ISP ! source point correspond to the collocation point\n\n INTEGER :: IFP !Field point correspond to the flat panel\n\n REAL:: r, G0, dG0, Z, w\n\n complex yi(0:10),t(50), yi1(0:10),t1(50), tmp\n COMPLEX, DIMENSION(:, :):: ZIJ ! influence coefficients\n COMPLEX, DIMENSION(IMX, IMX):: GR, GZ ! Cache of green function derivative with respect to r and z respectively\n\n TYPE(ParamsCommonInf) :: param\n\n DO ISP=1,IMX\n DO IFP=1,IMX\n\n Z = ZG(ISP) + ZG(IFP)\n r = sqrt((XG(ISP) - XG(IFP))**2 + (YG(ISP) - YG(IFP))**2 )\n if(abs(r) < tolerance .or. ISP == IFP) then\n ZIJ(ISP, IFP) = 0.5\n CYCLE\n end if\n\n G0 = cmplx(-2.*r/((r**2 + Z**2)**(3./2.)), 0.)\n dG0 = cmplx(0, 0)\n\n yi(0) = G0\n yi(1) = dG0\n\n param%w = w\n param%Z = Z\n param%r = r\n\n ! Compute Wave part/ regular part of green function derivative with respect to r\n if(ISP <= IFP) then\n ! A 3x4 runge kutta is enough for convergence\n t = Equadifnc(influence_infinite_dipoles_wave_part, 0., w, yi, 1, 2, 3, param )\n GR(ISP, IFP) = t(2)\n GR(IFP, ISP) = t(2)\n else\n t(2) = GR(IFP, ISP)\n end if\n\n ! Compute Wave part/ regular part of green function derivative with respect to Z\n yi1(0) = cmplx((-2.*Z)/((r**2 + Z**2)**(3./2.)), 0.)\n yi1(1) = cmplx(0, 0)\n if (abs(ZN(IFP)) < tolerance) then\n t1(2) = 0\n else\n if(ISP <= IFP) then\n ! A 3x4 runge kutta is enough for convergence\n t1 = Equadifnc(influence_infinite_dipoles_wave_part_z, 0., w, yi1, 1, 2, 3, param )\n GZ(ISP, IFP) = t1(2)\n GZ(IFP, ISP) = t1(2)\n else\n t1(2) = GZ(IFP, ISP)\n end if\n end if\n\n ! Compute coefficient transforming derivative in nM' to derivative in r and z\n tmp = cmplx(-XN(IFP)*(XG(ISP) - XG(IFP))/r -YN(IFP)*(YG(ISP) - YG(IFP))/r, 0)\n ! Double integral done by multiplying by the area\n ZIJ(ISP, IFP) = (t(2)*tmp + ZN(IFP)*t1(2))* AIRE(IFP) + compute_rankine_dipoles(ISP, IFP)\n\n END DO\n END DO\n end subroutine compute_influence_infinite_dipoles\nend module COMPUTE_INFLUENCE_ODE\n", "meta": {"hexsha": "099d371a64243ebcd49d4233f1903e13433c4e06", "size": 14070, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/NemohImproved/Nemoh/Solver/Core/COMPUTE_INFLUENCE_ODE.f90", "max_stars_repo_name": "NREL/OpenWARP", "max_stars_repo_head_hexsha": "ca49c4cbde17e0cead69bd9e55a81d5c0fafe4df", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2015-06-22T07:35:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-23T05:10:09.000Z", "max_issues_repo_path": "source/NemohImproved/Nemoh/Solver/Core/COMPUTE_INFLUENCE_ODE.f90", "max_issues_repo_name": "rhydar/Test", "max_issues_repo_head_hexsha": "32dd54af2c3657d0c49177395d5b1c1f7bd8e127", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2015-07-30T20:01:35.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-28T17:29:18.000Z", "max_forks_repo_path": "source/NemohImproved/Nemoh/Solver/Core/COMPUTE_INFLUENCE_ODE.f90", "max_forks_repo_name": "rhydar/Test", "max_forks_repo_head_hexsha": "32dd54af2c3657d0c49177395d5b1c1f7bd8e127", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2016-04-01T07:45:27.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-06T08:33:33.000Z", "avg_line_length": 33.2624113475, "max_line_length": 120, "alphanum_fraction": 0.537384506, "num_tokens": 4057, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797100118214, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6878632188176235}} {"text": "!--------------------------------------------------\n!PHY2063 Task1\n!URN 6309823 - Penguin Lab Group 1B\n!November 19th 2015\n!--------------------------------------------------\n\nprogram Task1\n implicit none\n\n integer,parameter :: n=80\n real :: phi(-n:n,-n:n)\n real,parameter :: h=0.05,e0=8.854E-12,e_elec=1.602E-19,c=3E26,T=310\n real,parameter :: k=1.381E-23,ep_water=80.0*e0,r_dna=1\n integer :: i,j,flag,iter\n real :: x,y,phi_s,accuracy,oldval,a,b,kappa\n\n! ep=effective permittivity, c=concentration, e0=permittivity of free space\n! T=temperature, e_elec=charge on an electron, iter=# iterations\n! k=Boltzman constant\n\n! A NUMBER OF N ITTERATIONS HAS TO BE GIVEN AS DO THE BOUNDARY CONDITIONS PHI_S\n\n! The second derivatives of the Poisson-Boltzmann equation in both x and y\n\n! where h is the grid spacing of the array\n! r_dna is the radius of each double helix\n\n OPEN(unit=12,file='Task1.dat')\n\n write(6,*)\"The role of this program is to determine the electrostatic\"\n write(6,*)\"potential in the xy plane in the persence of a DNA double helix\"\n write(6,*)\"aligned with its axis along the z axis.\"\n write(6,*)\" \"\n write(6,*)\"In this program the double helix is modelled as a very long rigid\"\n write(6,*)\"charged cylinder of radius r_DNA = 1nm, parllel to the z axis and\"\n write(6,*)\"at the origin in the xy plane.\"\n write(6,*)\" \"\n write(6,*)\" \"\n\n! phi=0.0 is the initial guess for the Gauss-Seidel iteration\n\n phi=0.0\n phi_s=100\n do i=-n,n\n\n! This do loop conducts the Gaus-Seidel iteration\n! The Gauss-Seidel iteration starts with a guess at the solution\n! which should include the imposed BCs\n\n do j=-n,n\n\n! phi_s is a boundary condition value\n\n x=real(i)*h\n y=real(j)*h\n if(x**2+y**2accuracy)flag=1\n endif\n enddo\n enddo\n if(flag==0)exit\n enddo\n\n write(6,*)\"The number of iterations is\",iter\n write(6,*)\" \"\n write(6,*)\" \"\n write(6,*)\"The values of x,y and phi(i,j) are written to the file Task1.dat\"\n write(6,*)\" \"\n write(6,*)\" \"\n write(6,*)\"In order to view a 3D representation of the data open gnuplot in\"\n write(6,*)\"the terminal, type (splot 'Task1.dat') in the terminal.\"\n\n! Note that when we loop over the array we need to avoid changing the values\n! of phi elements at the boundaries because these need to remain at the values\n! already set by the BC's. Thus the loops are from -n+1 to n-1.\n\n! This do loop writes the values of x,y and phi to the file Task1.dat\n\n do i=-n+1,n-1\n do j=-n+1,n-1\n x=real(i)*h\n y=real(j)*h\n write(12,*)x,y,phi(i,j)\n end do\n end do\nend program Task1\n", "meta": {"hexsha": "c8364072bd5e72e29f1606634d46681f0d647d52", "size": 3844, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "assignment-2/Task1.f90", "max_stars_repo_name": "WilliamHoltam/numerical-physics", "max_stars_repo_head_hexsha": "00e51192872a8581df4f9556f2565cf14a01e70d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assignment-2/Task1.f90", "max_issues_repo_name": "WilliamHoltam/numerical-physics", "max_issues_repo_head_hexsha": "00e51192872a8581df4f9556f2565cf14a01e70d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-07-18T13:37:07.000Z", "max_issues_repo_issues_event_max_datetime": "2019-07-18T13:37:07.000Z", "max_forks_repo_path": "assignment-2/Task1.f90", "max_forks_repo_name": "WilliamHoltam/energy-entropy-and-numerical-physics", "max_forks_repo_head_hexsha": "00e51192872a8581df4f9556f2565cf14a01e70d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.5079365079, "max_line_length": 79, "alphanum_fraction": 0.6347554631, "num_tokens": 1201, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797027760038, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6878632183794198}} {"text": "SUBROUTINE chillu(bctchillucum,day_max_temp,day_min_temp)\n!\nIMPLICIT NONE\n!\n! PARAMETER definitions\n!\nREAL,PARAMETER :: tmin = 0.0,tmax = 18.0,topt = 7.0,tdev = 30.0,daylim = 10.0, &\n & daydev = -0.5\n!\n! Subroutine arguments\n!\nREAL :: bctchillucum,day_max_temp,day_min_temp\n!\n! Local variables\n!\nREAL :: relvern,tavg\n!\n! + + + purpose + + +\n! calculates the vernalization effectiveness of a day. for fully\n! effective tmeperatures, a full day is returned. for temperatures\n! that are less than fully effective, a partial day or zero is\n! returned. if temperatures are above the upper temperature\n! threshold and insufficient chill days are accumulated, devernalization\n! occurs.\n \n! method taken from: ritchie, j.t. 1991. wheat phasic development in:\n! hanks, j. and ritchie, j.t. eds. modeling plant and soil systems.\n! agronomy monograph 31, pages 34-36.\n \n! + + + keywords + + +\n! vernalization chill units\n \n! + + + argument declarations + + +\n \n! + + + argument definitions + + +\n! bctchillucum - accumulated chilling units (days)\n! day_max_temp - daily maximum temperature (deg.c)\n! day_min_temp - daily minimum temperature (deg.c)\n \n! + + + local variables + + +\n \n \n! + + + local variable definitions + + +\n! tavg - daily average temperature (deg.c)\n! relvern - relative vernalization effectiveness\n! tmin - minimum temperature in vernalization function (deg.c)\n! tmax - maximum temperature in vernalization function (deg.c)\n! topt - optimum temperature in vernalization function (deg.c)\n! tdev - temperature above which devernalization can occur (deg.c)\n! daylim - vernalization days beyond which no devernalization can \n! occur (days)\n! daydev - devernalization days subtracted for each degree c above \n! tdev (days)\n \n ! find average temperature\ntavg = 0.5*(day_max_temp+day_min_temp)\n \nIF ((tavg.GE.tmin).AND.(tavg.LE.tmax)) THEN\n IF (tavg.LE.topt) THEN\n ! full vernalization effectiveness\n relvern = 1.0\n ELSE\n ! reduced vernalization effectiveness\n relvern = (tmax-tavg)/(tmax-topt)\n END IF\nELSE IF ((day_max_temp.GT.tdev).AND.(bctchillucum.LT.daylim)) THEN\n ! devernalization\n relvern = daydev*(day_max_temp-tdev)\nELSE\n relvern = 0.0\nEND IF\n! \nbctchillucum = bctchillucum + relvern\n!\nEND SUBROUTINE chillu\n", "meta": {"hexsha": "032085ec1d11f382d76234d9cb0c391235d7f56a", "size": 2454, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Project Documents/Source Code Original/Chillu.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/Chillu.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/Chillu.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": 32.2894736842, "max_line_length": 81, "alphanum_fraction": 0.6605541972, "num_tokens": 707, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998823, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.687863211972591}} {"text": "MODULE constants\n!\n! Define some constants\n!\n INTEGER, PARAMETER :: db = SELECTED_REAL_KIND(8)\n!\n DOUBLE PRECISION, PARAMETER :: vlight = 299792458.0_db ! c\n DOUBLE PRECISION, PARAMETER :: vacimp = 376.73031346177066_db ! \\mu_0*c\n DOUBLE PRECISION, PARAMETER :: eev = 510998.89613320108_db ! m_e*c^2/e\n DOUBLE PRECISION, PARAMETER :: pi = 3.1415926535897931_db\nEND MODULE constants\n", "meta": {"hexsha": "b45f5f12634e81003b0ffee304822847464d5aae", "size": 416, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/constants.f90", "max_stars_repo_name": "alexbovet/fastpart", "max_stars_repo_head_hexsha": "9aabbc1f50c1419f4a7587600029cb2e4e91baef", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2015-07-30T14:13:44.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-22T08:24:27.000Z", "max_issues_repo_path": "src/constants.f90", "max_issues_repo_name": "alexbovet/fastpart", "max_issues_repo_head_hexsha": "9aabbc1f50c1419f4a7587600029cb2e4e91baef", "max_issues_repo_licenses": ["MIT"], "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/constants.f90", "max_forks_repo_name": "alexbovet/fastpart", "max_forks_repo_head_hexsha": "9aabbc1f50c1419f4a7587600029cb2e4e91baef", "max_forks_repo_licenses": ["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.6666666667, "max_line_length": 76, "alphanum_fraction": 0.6899038462, "num_tokens": 135, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797051879431, "lm_q2_score": 0.7549149758396752, "lm_q1q2_score": 0.6878632051275584}} {"text": " double precision function psi(xp,yp)\n implicit none\n\n double precision xp,yp,pi\n common /compi/ pi\n\n psi = ((sin(pi*xp))**2 * (sin(pi*yp))**2) / pi\n\n return\n end\n", "meta": {"hexsha": "1eea276c9fb6ea89d89464317dd83e58c91037a0", "size": 198, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "applications/metric/2d/mesh/psi.f", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2017-09-26T13:39:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:56:23.000Z", "max_issues_repo_path": "applications/metric/2d/mesh/psi.f", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 75, "max_issues_repo_issues_event_min_datetime": "2017-08-02T19:56:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T12:36:32.000Z", "max_forks_repo_path": "applications/metric/2d/mesh/psi.f", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-02-21T00:10:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T19:08:36.000Z", "avg_line_length": 18.0, "max_line_length": 52, "alphanum_fraction": 0.5353535354, "num_tokens": 61, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9111797003640646, "lm_q2_score": 0.7549149758396752, "lm_q1q2_score": 0.6878632014859403}} {"text": " Program dsygv_example\n\n! DSYGV Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_example_aux, Only: nagf_blas_damax_val, &\n nagf_file_print_matrix_real_gen\n Use lapack_interfaces, Only: ddisna, dlansy, dsygv, dtrcon\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Real (Kind=dp), Parameter :: zero = 0.0_dp\n Integer, Parameter :: nb = 64, nin = 5, nout = 6\n! .. Local Scalars ..\n Real (Kind=dp) :: anorm, bnorm, eps, r, rcond, rcondb, t1, t2, t3\n Integer :: i, ifail, info, k, lda, ldb, lwork, n\n! .. Local Arrays ..\n Real (Kind=dp), Allocatable :: a(:, :), b(:, :), eerbnd(:), rcondz(:), &\n w(:), work(:), zerbnd(:)\n Real (Kind=dp) :: dummy(1)\n Integer, Allocatable :: iwork(:)\n! .. Intrinsic Procedures ..\n Intrinsic :: abs, epsilon, max, nint\n! .. Executable Statements ..\n Write (nout, *) 'DSYGV Example Program Results'\n Write (nout, *)\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n\n lda = n\n ldb = n\n Allocate (a(lda,n), b(ldb,n), eerbnd(n), rcondz(n), w(n), zerbnd(n), &\n iwork(n))\n\n! Use routine workspace query to get optimal workspace.\n lwork = -1\n Call dsygv(1, 'Vectors', 'Upper', n, a, lda, b, ldb, w, dummy, lwork, &\n info)\n\n! Make sure that there is enough workspace for block size nb.\n lwork = max((nb+2)*n, nint(dummy(1)))\n Allocate (work(lwork))\n\n! Read the upper triangular parts of the matrices A and B\n\n Read (nin, *)(a(i,i:n), i=1, n)\n Read (nin, *)(b(i,i:n), i=1, n)\n\n! Compute the one-norms of the symmetric matrices A and B\n\n anorm = dlansy('One norm', 'Upper', n, a, lda, work)\n bnorm = dlansy('One norm', 'Upper', n, b, ldb, work)\n\n! Solve the generalized symmetric eigenvalue problem\n! A*x = lambda*B*x (ITYPE = 1)\n\n Call dsygv(1, 'Vectors', 'Upper', n, a, lda, b, ldb, w, work, lwork, &\n info)\n\n If (info==0) Then\n\n! Print solution\n\n Write (nout, *) 'Eigenvalues'\n Write (nout, 100) w(1:n)\n\n Write (nout, *)\n Flush (nout)\n\n! Normalize the eigenvectors, largest positive\n Do i = 1, n\n Call nagf_blas_damax_val(n, a(1,i), 1, k, r)\n If (a(k,i)=eps) Then\n\n! Call DDISNA to estimate reciprocal condition\n! numbers for the eigenvectors of (A - lambda*B)\n\n Call ddisna('Eigenvectors', n, n, w, rcondz, info)\n\n! Compute the error estimates for the eigenvalues and\n! eigenvectors\n\n t1 = eps/rcondb\n t2 = anorm/bnorm\n t3 = t2/rcond\n Do i = 1, n\n eerbnd(i) = t1*(t2+abs(w(i)))\n zerbnd(i) = t1*(t3+abs(w(i)))/rcondz(i)\n End Do\n\n! Print the approximate error bounds for the eigenvalues\n! and vectors\n\n Write (nout, *)\n Write (nout, *) 'Error estimates for the eigenvalues'\n Write (nout, 110) eerbnd(1:n)\n Write (nout, *)\n Write (nout, *) 'Error estimates for the eigenvectors'\n Write (nout, 110) zerbnd(1:n)\n Else\n Write (nout, *)\n Write (nout, *) 'B is very ill-conditioned, error ', &\n 'estimates have not been computed'\n End If\n Else If (info>n .And. info<=2*n) Then\n i = info - n\n Write (nout, 120) 'The leading minor of order ', i, &\n ' of B is not positive definite'\n Else\n Write (nout, 130) 'Failure in DSYGV. INFO =', info\n End If\n\n100 Format (3X, (6F11.4))\n110 Format (4X, 1P, 6E11.1)\n120 Format (1X, A, I4, A)\n130 Format (1X, A, I4)\n End Program\n", "meta": {"hexsha": "29e1784635d3766ce20acb0505eb162b9f41e436", "size": 4909, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/dsygv_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/dsygv_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/dsygv_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 31.8766233766, "max_line_length": 90, "alphanum_fraction": 0.5577510695, "num_tokens": 1522, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111796979521253, "lm_q2_score": 0.7549149758396752, "lm_q1q2_score": 0.6878631996651312}} {"text": " MODULE m_angle\n CONTAINS\n REAL ELEMENTAL FUNCTION angle(x,y)\n \nc----------------------------------------------\nc calculates an angle of a vector\nc given by rectangular coordinates (x,y)\nc-----------------------------------------------\n\n USE m_constants\n IMPLICIT NONE\n\n REAL, INTENT (IN) :: x,y\n\n IF (x.NE.0.0) THEN\n IF (y.NE.0.0) THEN\n IF (y.GT.0.0) THEN\n IF (x.LT.0.0) angle = pi_const - ATAN(y/abs(x))\n IF (x.GT.0.0) angle = ATAN(y/x)\n ELSE\n IF (x.GT.0.0) angle = - ATAN(abs(y)/x)\n IF (x.LT.0.0) angle = - pi_const \n + + ATAN(abs(y)/abs(x))\n END IF\n ELSE\n IF (x.LT.0.0) angle = -pi_const\n IF (x.GT.0.0) angle = 0.0\n END IF\n ELSE\n IF (y.LT.0.0) angle = -pi_const/2.\n IF (y.EQ.0.0) angle = 0.0 \n IF (y.GT.0.0) angle = pi_const/2.\n END IF \n \n END FUNCTION angle\n END MODULE m_angle\n", "meta": {"hexsha": "530cff7b5354335ef77fcd0e2ff84845a443a9c3", "size": 1055, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "math/angle.f", "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/angle.f", "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/angle.f", "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": 28.5135135135, "max_line_length": 62, "alphanum_fraction": 0.409478673, "num_tokens": 320, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172659321807, "lm_q2_score": 0.7248702702332475, "lm_q1q2_score": 0.6878419149852542}} {"text": "!-----------------------------------------------------------------------\r\n! Saturation specific humidity\r\n!-----------------------------------------------------------------------\r\nsubroutine QSAT(water,P,T,Qs)\r\n\r\nuse Constants, only : &\r\n eps, &! Ratio of molecular weights of water and dry air\r\n e0, &! Saturation vapour pressure at Tm (Pa)\r\n Tm ! Melting point (K)\r\n\r\nimplicit none\r\n\r\nlogical, intent(in) :: &\r\n water ! Saturation wrt water if TRUE\r\n\r\nreal, intent(in) :: &\r\n P, &! Air pressure (Pa)\r\n T ! Temperature (K)\r\n\r\nreal, intent(out) :: &\r\n Qs ! Saturation specific humidity\r\n\r\nreal :: &\r\n Tc, &! Temperature (C)\r\n es ! Saturation vapour pressure (Pa)\r\n\r\nTc = T - Tm\r\nif (Tc > 0 .or. water) then\r\n es = e0*exp(17.5043*Tc / (241.3 + Tc))\r\nelse\r\n es = e0*exp(22.4422*Tc / (272.186 + Tc))\r\nend if\r\nQs = eps*es / P\r\n\r\nend subroutine QSAT\r\n", "meta": {"hexsha": "66f2e71a7fff5cb6dbad8a32e42f8f1b0882c568", "size": 1000, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/QSAT.f90", "max_stars_repo_name": "wk1984/FSM_W", "max_stars_repo_head_hexsha": "8412ad62e2c0080721d1228ef27db86062ada171", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2015-04-16T04:04:37.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-17T01:45:10.000Z", "max_issues_repo_path": "src/QSAT.f90", "max_issues_repo_name": "wk1984/FSM_W", "max_issues_repo_head_hexsha": "8412ad62e2c0080721d1228ef27db86062ada171", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-05-16T13:33:34.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-03T18:47:06.000Z", "max_forks_repo_path": "src/QSAT.f90", "max_forks_repo_name": "wk1984/FSM_W", "max_forks_repo_head_hexsha": "8412ad62e2c0080721d1228ef27db86062ada171", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2015-07-17T15:53:49.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-28T07:14:58.000Z", "avg_line_length": 27.7777777778, "max_line_length": 73, "alphanum_fraction": 0.435, "num_tokens": 259, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172572644806, "lm_q2_score": 0.7248702702332475, "lm_q1q2_score": 0.6878419087022961}} {"text": "c Subroutine to convert from stnpres to sealevel pressure\r\nc AJ_Kettle, Nov07/2017\r\n\r\n SUBROUTINE slpres_from_stnpres(f_p_hpa,f_e_hpa,f_hght_m,f_airt_c,\r\n + f_slpres_hpa)\r\n\r\n IMPLICIT NONE\r\nc************************************************************************\r\n INTEGER :: i,j,k,ii,jj,kk\r\n\r\nc Inputs\r\n REAL :: f_p_hpa\r\n REAL :: f_e_hpa\r\n REAL :: f_hght_m\r\n REAL :: f_airt_c\r\n\r\nc Output\r\n REAL :: f_slpres_hpa\r\n\r\nc INTERNAL CONSTANTS\r\n REAL :: f_grav_ms2\r\n REAL :: f_gasconstant_jkgk\r\n REAL :: f_airt_k\r\n REAL :: f_alapse_km\r\n REAL :: f_ccoef_khpa\r\nc************************************************************************\r\n f_grav_ms2 =9.80665\r\n f_gasconstant_jkgk =287.05\r\n f_airt_k =273.15+f_airt_c\r\n f_alapse_km =0.0065\r\n f_ccoef_khpa =0.12\r\n\r\n f_slpres_hpa=f_p_hpa*\r\n + EXP( \r\n + (f_grav_ms2*f_hght_m/f_gasconstant_jkgk)/\r\n + (f_airt_k+f_alapse_km*f_hght_m/2.0+f_e_hpa*f_ccoef_khpa)\r\n + )\r\n \r\n \r\nc************************************************************************\r\n RETURN\r\n END", "meta": {"hexsha": "669464a9ff18a8e158c52fb74e7e4fa960ecee3c", "size": 1359, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "P20171014_dwdsub/Subroutine/slpres_from_stnpres.f", "max_stars_repo_name": "ajkettle/glamod-nuim", "max_stars_repo_head_hexsha": "beb37a3c2acab3f334918dda3e366c7882cc0960", "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": "P20171014_dwdsub/Subroutine/slpres_from_stnpres.f", "max_issues_repo_name": "ajkettle/glamod-nuim", "max_issues_repo_head_hexsha": "beb37a3c2acab3f334918dda3e366c7882cc0960", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 23, "max_issues_repo_issues_event_min_datetime": "2022-01-28T13:57:39.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T09:34:41.000Z", "max_forks_repo_path": "P20171014_dwdsub/Subroutine/slpres_from_stnpres.f", "max_forks_repo_name": "ajkettle/glamod-nuim", "max_forks_repo_head_hexsha": "beb37a3c2acab3f334918dda3e366c7882cc0960", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-01-24T12:06:06.000Z", "max_forks_repo_forks_event_max_datetime": "2019-01-24T12:06:06.000Z", "avg_line_length": 32.3571428571, "max_line_length": 74, "alphanum_fraction": 0.4039735099, "num_tokens": 350, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9790357555117625, "lm_q2_score": 0.702530051167069, "lm_q1q2_score": 0.6878020394140686}} {"text": "Subroutine zprota(xn1, xn2, xn3, theta, v1, v2, v3)\n Implicit Double Precision (A-H, O-Z)\n Save\n vx = v1\n vy = v2\n vz = v3\n c = cos(theta)\n omc = 1D0 - c\n s = sin(theta)\n a11 = xn1**2*omc + c\n a12 = xn1*xn2*omc - s*xn3\n a13 = xn1*xn3*omc + s*xn2\n a21 = xn1*xn2*omc + s*xn3\n a22 = xn2**2*omc + c\n a23 = xn2*xn3*omc - s*xn1\n a31 = xn1*xn3*omc - s*xn2\n a32 = xn3*xn2*omc + s*xn1\n a33 = xn3**2*omc + c\n v1 = vx*a11 + vy*a12 + vz*a13\n v2 = vx*a21 + vy*a22 + vz*a23\n v3 = vx*a31 + vy*a32 + vz*a33\n Return\nEnd Subroutine zprota\n", "meta": {"hexsha": "ceb65a8bbadbacb38dd21728597bd9932e5d5988", "size": 542, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/zprota.f90", "max_stars_repo_name": "xiaohaijin/AMPT", "max_stars_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-12-24T19:37:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-14T12:58:59.000Z", "max_issues_repo_path": "src/zprota.f90", "max_issues_repo_name": "xiaohaijin/AMPT", "max_issues_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_issues_repo_licenses": ["MIT"], "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/zprota.f90", "max_forks_repo_name": "xiaohaijin/AMPT", "max_forks_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.5833333333, "max_line_length": 51, "alphanum_fraction": 0.5701107011, "num_tokens": 289, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897509188344, "lm_q2_score": 0.731058584489497, "lm_q1q2_score": 0.6877724236089495}} {"text": "MODULE polint_module\n\n implicit none\n\n PRIVATE\n PUBLIC :: polint, dpolint\n\nCONTAINS\n\n\n SUBROUTINE polint( xa,ya,n,x,y,dy )\n\n implicit none\n integer,intent(IN) :: n\n real(8),intent(IN) :: xa(n),ya(n),x\n real(8),intent(OUT) :: y,dy\n integer :: i,m\n real(8) :: a,b,f0nm,f0nm_0\n real(8),allocatable :: f0(:)\n\n allocate( f0(n) )\n f0(:) = ya(:)\n\n f0nm = ya(1)\n\n do m=1,n-1\n do i=1,n-m\n a = x-xa(i)\n b = x-xa(i+m)\n f0(i) = ( b*f0(i) - a*f0(i+1) )/( b - a )\n end do\n f0nm_0 = f0nm\n f0nm = sum( f0(1:n-m) )/(n-m)\n end do\n y = f0(1)\n dy = f0nm - f0nm_0\n\n deallocate( f0 )\n\n return\n END SUBROUTINE polint\n\n\n SUBROUTINE dpolint( xa,ya,n,x,y,dy )\n\n implicit none\n integer,intent(IN) :: n\n real(8),intent(IN) :: xa(n),ya(n),x\n real(8),intent(OUT) :: y,dy\n integer :: i,m\n real(8) :: a,b,f1nm,f1nm_0\n real(8),allocatable :: f0(:),f1(:)\n\n allocate( f0(n),f1(n) )\n f0(:) = ya(:)\n f1(:) = 0.0d0\n\n f1nm = ( ya(2)-ya(1) )/( xa(2)-xa(1) )\n\n do m=1,n-1\n do i=1,n-m\n a = x-xa(i)\n b = x-xa(i+m)\n f1(i) = ( f0(i) - f0(i+1) + b*f1(i) -a*f1(i+1) )/( b - a )\n f0(i) = ( b*f0(i) - a*f0(i+1) )/( b - a )\n end do\n f1nm_0 = f1nm\n f1nm = sum( f1(1:n-m) )/(n-m)\n end do\n\n y = f1(1)\n dy = f1nm - f1nm_0\n\n deallocate( f0,f1 )\n\n return\n END SUBROUTINE dpolint\n\n\nEND MODULE polint_module\n", "meta": {"hexsha": "196b07d66afff31707a7390e9099f54d1cc975bd", "size": 1477, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/polint_module.f90", "max_stars_repo_name": "j-iwata/RSDFT", "max_stars_repo_head_hexsha": "2a961b2c8339a49de9bd09f55e7d6a45b6159d2e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2016-10-31T02:11:39.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-04T17:45:30.000Z", "max_issues_repo_path": "src/polint_module.f90", "max_issues_repo_name": "j-iwata/RSDFT", "max_issues_repo_head_hexsha": "2a961b2c8339a49de9bd09f55e7d6a45b6159d2e", "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/polint_module.f90", "max_forks_repo_name": "j-iwata/RSDFT", "max_forks_repo_head_hexsha": "2a961b2c8339a49de9bd09f55e7d6a45b6159d2e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-10-31T02:11:41.000Z", "max_forks_repo_forks_event_max_datetime": "2020-04-18T14:26:38.000Z", "avg_line_length": 18.2345679012, "max_line_length": 68, "alphanum_fraction": 0.4685172647, "num_tokens": 634, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319862, "lm_q2_score": 0.7853085859124003, "lm_q1q2_score": 0.6877630490634961}} {"text": "module Mod_BlasiusProfile\n use typre\n implicit none\n \n !Using: http://www.calpoly.edu/~kshollen/ME347/Handouts/Blasius.pdf\n\n type :: BlasiusProfileGenerator\n real(rp) :: UFree = 1.0_rp, nu = 1.0_rp, X = 1.0_rp\n \n real(rp) :: sqrtUdivNuX !sqrt(U/nu*x)\n \n real(rp) :: EtaTable(17) = (/ 0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0, 7.5, 8.0 /)\n real(rp) :: FTable(17) = (/ 0.0000, 0.1659, 0.3298, 0.4868, 0.6298, 0.7513, 0.8461, 0.9131, 0.9555, 0.9795, 0.9916, 0.9969, 0.9990, 0.9997, 0.9999, 1.0000, 1.0000 /) \ncontains\n \n procedure :: SetUFree\n procedure :: SetNu\n procedure :: SetDistanceXFromPlateStartingPoint\n procedure :: GetU\n \n \n end type\n \n \n \ncontains\n \n subroutine SetUFree(a,UFree)\n class(BlasiusProfileGenerator) :: a\n real(rp) :: UFree\n \n a%UFree = UFree;\n call ComputeSqrtUdivNux(a)\n end subroutine\n \n subroutine SetNu(a,nu)\n class(BlasiusProfileGenerator) :: a\n real(rp) :: nu\n \n a%nu = nu\n call ComputeSqrtUdivNux(a)\n end subroutine\n \n subroutine SetDistanceXFromPlateStartingPoint(a,X)\n class(BlasiusProfileGenerator) :: a\n real(rp) :: X\n \n a%X = X;\n call ComputeSqrtUdivNux(a)\n end subroutine\n \n subroutine ComputeSqrtUdivNux(a)\n class(BlasiusProfileGenerator) :: a\n \n a%sqrtUdivNuX = sqrt(a%UFree/(a%nu*a%X))\n end subroutine\n \n \n subroutine GetU(a,y,U)\n class(BlasiusProfileGenerator) :: a\n real(rp) :: y,u\n \n real(rp) :: eta\n integer(ip) :: pos\n \n real(rp) :: eta0,eta1,etadist,coeff0,coeff1,Fval0,Fval1\n \n eta = y*a%sqrtUdivNuX\n \n if (eta > 8) then\n U = a%UFree;\n elseif (eta < 0.0_rp) then\n U = 0.0_rp\n else\n pos = floor(eta/0.5_rp)+1\n \n etadist = a%EtaTable(pos+1)- a%EtaTable(pos)\n eta0 = a%EtaTable(pos)\n eta1 = a%EtaTable(pos+1)\n \n coeff0 = 1.0_rp-(eta-eta0)/etadist\n coeff1 = 1.0_rp-coeff0\n \n Fval0 = a%FTable(pos)\n Fval1 = a%Ftable(pos+1)\n \n U = a%UFree*(coeff0*Fval0+coeff1*Fval1)\n \n \n \n \n endif\n end subroutine\n \n \n \nend module\n\n\n\n\n \n", "meta": {"hexsha": "89c3d0b0ce4501386b8609df2e6f9139e5f33635", "size": 2322, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Sources/modules/nstinc/TurbulentInlet/Mod_BlasiusProfile.f90", "max_stars_repo_name": "ciaid-colombia/InsFEM", "max_stars_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-24T08:19:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-24T08:19:54.000Z", "max_issues_repo_path": "Sources/modules/nstinc/TurbulentInlet/Mod_BlasiusProfile.f90", "max_issues_repo_name": "ciaid-colombia/InsFEM", "max_issues_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Sources/modules/nstinc/TurbulentInlet/Mod_BlasiusProfile.f90", "max_forks_repo_name": "ciaid-colombia/InsFEM", "max_forks_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.5436893204, "max_line_length": 174, "alphanum_fraction": 0.5396210164, "num_tokens": 840, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319862, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.687763049063496}} {"text": " Program dgelsy_example\n\n! DGELSY Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_interfaces, Only: dgelsy\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nb = 64, nin = 5, nout = 6\n! .. Local Scalars ..\n Real (Kind=dp) :: rcond\n Integer :: i, info, lda, lwork, m, n, rank\n! .. Local Arrays ..\n Real (Kind=dp), Allocatable :: a(:, :), b(:), work(:)\n Integer, Allocatable :: jpvt(:)\n! .. Executable Statements ..\n Write (nout, *) 'DGELSY Example Program Results'\n Write (nout, *)\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) m, n\n lda = m\n lwork = 3*n + nb*(n+1)\n Allocate (a(lda,n), b(m), work(lwork), jpvt(n))\n\n! Read A and B from data file\n\n Read (nin, *)(a(i,1:n), i=1, m)\n Read (nin, *) b(1:m)\n\n! Initialize JPVT to be zero so that all columns are free\n\n jpvt(1:n) = 0\n\n! Choose RCOND to reflect the relative accuracy of the input data\n\n rcond = 0.01_dp\n\n! Solve the least squares problem min( norm2(b - Ax) ) for the x\n! of minimum norm.\n\n Call dgelsy(m, n, 1, a, lda, b, m, jpvt, rcond, rank, work, lwork, info)\n\n! Print solution\n\n Write (nout, *) 'Least squares solution'\n Write (nout, 100) b(1:n)\n\n! Print the effective rank of A\n\n Write (nout, *)\n Write (nout, *) 'Tolerance used to estimate the rank of A'\n Write (nout, 110) rcond\n Write (nout, *) 'Estimated rank of A'\n Write (nout, 120) rank\n\n100 Format (1X, 7F11.4)\n110 Format (3X, 1P, E11.2)\n120 Format (1X, I6)\n End Program\n", "meta": {"hexsha": "614460f63552521e8f55be8c3a6f8a13bb2f46ff", "size": 1869, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/dgelsy_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/dgelsy_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/dgelsy_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 27.8955223881, "max_line_length": 90, "alphanum_fraction": 0.5794542536, "num_tokens": 589, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479466, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.68776304837204}} {"text": " PROGRAM xgamdev\r\nC driver for routine gamdev\r\n INTEGER N,NPTS,ISCAL,LLEN\r\n PARAMETER(N=20,NPTS=10000,ISCAL=200,LLEN=50)\r\n INTEGER i,ia,idum,j,k,klim\r\n REAL gamdev,dist(21)\r\n CHARACTER text(50)*1\r\n idum=-13\r\n10 do 11 j=1,21\r\n dist(j)=0.0\r\n11 continue\r\n write(*,*) 'Order of Gamma distribution (n=1..20); -1 to END.'\r\n read(*,*) ia\r\n if (ia.le.0) goto 99\r\n if (ia.gt.20) goto 10\r\n do 12 i=1,NPTS\r\n j=int(gamdev(ia,idum))+1\r\n if ((j.ge.1).and.(j.le.21)) dist(j)=dist(j)+1\r\n12 continue\r\n write(*,'(1x,a,i2,a,i6,a)') 'Gamma-distribution deviate, order ',\r\n * ia,' of ',NPTS,' points'\r\n write(*,'(1x,t6,a,t14,a,t23,a)') 'x','p(x)','graph:'\r\n do 15 j=1,20\r\n dist(j)=dist(j)/NPTS\r\n do 13 k=1,50\r\n text(k)=' '\r\n13 continue\r\n klim=int(ISCAL*dist(j))\r\n if (klim.gt.LLEN) klim=LLEN\r\n do 14 k=1,klim\r\n text(k)='*'\r\n14 continue\r\n write(*,'(1x,f7.2,f10.4,4x,50a1)')\r\n * float(j),dist(j),(text(k),k=1,50)\r\n15 continue\r\n goto 10\r\n99 END\r\n", "meta": {"hexsha": "5501acbe4e2786b20c146d5664d274cae7d20f7c", "size": 1130, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xgamdev.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xgamdev.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xgamdev.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.7368421053, "max_line_length": 72, "alphanum_fraction": 0.4982300885, "num_tokens": 414, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869786798663, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.6877630381880953}} {"text": " program drdilu\nc>> 2001-05-22 DRDILU Krogh Minor change for making .f90 version.\nc>> 1994-12-21 DRDILU Krogh Latest version.\nc--D replaces \"?\": DR?ILU, ?ILUP\nc Demonstration driver for DILUP.\nc Given table of sin(x), x = 0, .5, 1., ..., interpolates for x =\nc -.1, .1, and, 8.3 using polynomial degrees 2, 3, 4, ..., 10. Errors\nc are estimated in all cases.\nc\n integer NTAB, NX, NDEG1, NDEG2\n parameter (NTAB=40, NX=3, NDEG1=2, NDEG2=10)\n double precision XT(2), YT(NTAB), X(NX), Y, EOPT(1), H, ANS\n parameter (H = .5D0)\n integer I, NDEG, IOPT(3), LUP\n data X / -.1D0, .1D0, 8.3D0 /\nc Set IOPT to get an error estimate.\n data IOPT / 0, 1, 0 /\n data LUP / 3 /\nc\nc Compute the XT and YT tables\n XT(1) = 0.D0\n XT(2) = H\n do 10 I = 1, NTAB\n YT(I) = sin(dble(I-1) * H)\n 10 continue\n print *, 'IOP(1) NDEG X Y Est. Error True Error'\n do 30 I = 1, NX\n ANS = sin(X(I))\n do 20 NDEG = NDEG1, NDEG2\n call DILUP (X(I), Y, NTAB, XT, YT, NDEG, LUP, IOPT, EOPT)\n print '(I5, I5, F9.4, F12.8, 1P,E10.2, E11.2)',\n 1 IOPT(1), NDEG, X(I), Y, EOPT(1), Y - ANS\n 20 continue\n print *\n 30 continue\n stop\n end\n", "meta": {"hexsha": "879e08e09320aed46135923d173e12673f04d191", "size": 1277, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drdilup.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drdilup.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drdilup.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": 33.6052631579, "max_line_length": 70, "alphanum_fraction": 0.5324980423, "num_tokens": 523, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479466, "lm_q2_score": 0.7853085708384736, "lm_q1q2_score": 0.6877630307699751}} {"text": "\n\nprogram main\n\n implicit none\n\n integer :: c = 1, i;\n\n integer :: maximum = 10000000\n\n ! c is the count of how many number chains arrive at 89\n\n do i = 1, MAXIMUM\n\n if(number_chain(i) == 89) then\n call inc(c, 1)\n endif\n\n enddo\n\n print*, c\n\n\ncontains\n\n\n ! Increment a number i by the value x.\n ! This is here because I miss += \n subroutine inc(base, offset)\n\n integer, intent (in):: offset\n integer, intent (out):: base\n\n base = base + offset\n return\n\n end subroutine inc\n\n\n function number_chain(r)\n\n integer, intent (in) :: r\n\n integer :: i\n integer :: sumx, number_chain\n i = r\n\n outer: do\n\n sumx = 0\n \n inner: do while (i /= 0)\n call inc(sumx, mod(i, 10) ** 2)\n i = i / 10\n end do inner\n\n i = sumx\n\n if(sumx == 1 .OR. sumx == 89) then\n number_chain = sumx;\n exit\n endif\n\n end do outer\n\n return\n\n end function number_chain \n\n\nend program main\n\n", "meta": {"hexsha": "88c512d9d3250c16d71ef1bfe076a5017ada5fbc", "size": 1444, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "fortran/square_digit_chains.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/square_digit_chains.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/square_digit_chains.f95", "max_forks_repo_name": "guynan/project_euler", "max_forks_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-11-03T01:14:28.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-26T13:52:51.000Z", "avg_line_length": 19.7808219178, "max_line_length": 63, "alphanum_fraction": 0.3753462604, "num_tokens": 291, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412809, "lm_q2_score": 0.798186768138228, "lm_q1q2_score": 0.6876684046886579}} {"text": " PROGRAM xmnewt\r\nC driver for routine mnewt\r\n INTEGER NTRIAL,N,NP\r\n REAL TOLX,TOLF\r\n PARAMETER(NTRIAL=5,TOLX=1.0E-6,N=4,TOLF=1.0E-6,NP=15)\r\n INTEGER i,j,k,kk\r\n REAL xx,fjac(NP,NP),fvec(NP),x(NP)\r\n do 15 kk=-1,1,2\r\n do 14 k=1,3\r\n xx=0.2001*k*kk\r\n write(*,'(/1x,a,i2)') 'Starting vector number',k\r\n do 11 i=1,N\r\n x(i)=xx+0.2*i\r\n write(*,'(1x,t5,a,i1,a,f5.2)') 'X(',i,') = ',x(i)\r\n11 continue\r\n do 13 j=1,NTRIAL\r\n call mnewt(1,x,N,TOLX,TOLF)\r\n call usrfun(x,n,NP,fvec,fjac)\r\n write(*,'(/1x,t5,a,t14,a,t29,a/)') 'I','X(I)','F'\r\n do 12 i=1,N\r\n write(*,'(1x,i4,2e15.6)') i,x(i),fvec(i)\r\n12 continue\r\n write(*,'(/1x,a)') 'press RETURN to continue...'\r\n read(*,*)\r\n13 continue\r\n14 continue\r\n15 continue\r\n END\r\n SUBROUTINE usrfun(x,n,np,fvec,fjac)\r\n INTEGER i,n,np\r\n REAL fjac(np,np),fvec(np),x(np)\r\n fjac(1,1)=-2.0*x(1)\r\n fjac(1,2)=-2.0*x(2)\r\n fjac(1,3)=-2.0*x(3)\r\n fjac(1,4)=1.0\r\n do 11 i=1,n\r\n fjac(2,i)=2.0*x(i)\r\n11 continue\r\n fjac(3,1)=1.0\r\n fjac(3,2)=-1.0\r\n fjac(3,3)=0.0\r\n fjac(3,4)=0.0\r\n fjac(4,1)=0.0\r\n fjac(4,2)=1.0\r\n fjac(4,3)=-1.0\r\n fjac(4,4)=0.0\r\n fvec(1)=-x(1)**2-x(2)**2-x(3)**2+x(4)\r\n fvec(2)=x(1)**2+x(2)**2+x(3)**2+x(4)**2-1.0\r\n fvec(3)=x(1)-x(2)\r\n fvec(4)=x(2)-x(3)\r\n END\r\n", "meta": {"hexsha": "c7dec7270e92adc6289d6cbb4d045f99765ab473", "size": 1517, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xmnewt.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xmnewt.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xmnewt.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.1730769231, "max_line_length": 62, "alphanum_fraction": 0.4370468029, "num_tokens": 648, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.793105953629227, "lm_q1q2_score": 0.687651223108542}} {"text": "subroutine fibonacci(n, a_out)\n implicit none\n integer, intent(in) :: n\n real*8, dimension(n) :: a_out\n\n integer :: i\n\n do i = 1, n\n if (i.eq.1) then\n a_out(i) = 1.0\n elseif (i.eq.2) then\n a_out(i) = 1.0\n else\n a_out(i) = a_out(i-1) + a_out(i-2)\n end if\n end do\n\n return\n\nend subroutine fibonacci\n", "meta": {"hexsha": "bfd257e1a5c9ed6458b4cb02ab1d9aa35c2a9f1e", "size": 331, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "resources/code/fibonacci.f90", "max_stars_repo_name": "james-grant1/perf-python", "max_stars_repo_head_hexsha": "3ca8e2d4dc419d6d8aa1a7f99a3a45b8ed1834d9", "max_stars_repo_licenses": ["CC-BY-4.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": "resources/code/fibonacci.f90", "max_issues_repo_name": "james-grant1/perf-python", "max_issues_repo_head_hexsha": "3ca8e2d4dc419d6d8aa1a7f99a3a45b8ed1834d9", "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": "resources/code/fibonacci.f90", "max_forks_repo_name": "james-grant1/perf-python", "max_forks_repo_head_hexsha": "3ca8e2d4dc419d6d8aa1a7f99a3a45b8ed1834d9", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.7619047619, "max_line_length": 40, "alphanum_fraction": 0.5679758308, "num_tokens": 126, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.7931059487389968, "lm_q1q2_score": 0.6876512188685375}} {"text": " function rs(chd,radius,rsmax)\nc\nc purpose: convert a charge density value to the equivalent r_s \nc where 4*pi*(r_s)**3*chd/3 = 1, \nc i.e. r_s is the radius of a sphere containing exactly one\nc electron in a homogeneous electron gas of density chd. \nc\nc charge density may be of the form n(r) (radius = 0.d0)\nc or 4*pi*r**2*n(r), in which case radius is the r-value.\nc\nc method: check that chd is not zero or -ve; if it is, rs is set to\nc rsmax (rsmax = 1.d3 => charge density around 2.4d-10 e/(au^3))\nc\nc calls: system function datan\nc\nc written: philip sterne, sterne1@llnl.gov\nc date: April 21, 1998\nc changes: none\nc comments: \nc\n implicit none\nc\nc input variables\nc\n real*8 chd ! charge density - either n(r) or 4*pi*r**2*n(r)\n real*8 radius ! radius r if input chd is 4*pi*r**2*n(r)\n real*8 rsmax ! maximum allowable r_s value (very low cd limit)\nc\nc output variables\nc \n real*8 rs ! r_s value for this charge density\nc\nc internal variables and functions\nc\n real*8 pi ! pi\n real*8 chdmin ! minimum charge density - corresponds to rsmax\nc \nc set rsmax and chdmin values for vanishingly small charge densities\nc\n rs = rsmax\n pi = 4.d0*datan(1.d0)\n if(radius.eq.0.d0) then\n chdmin = 3.d0/(4.d0*pi*rsmax**3)\n if(chd.gt.chdmin) rs = (3.d0/(4.d0*pi*chd))**(1.d0/3.d0)\n else\n chdmin = 3.d0*radius**2/(rsmax**3)\n if(chd.gt.chdmin) rs = (3.d0*radius**2/chd)**(1.d0/3.d0)\n endif\nc\n return\n end\n\n", "meta": {"hexsha": "0d3ada1bd2c692b4d43ad00466a41fb7aa5648ad", "size": 1631, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/Potential/rs.f", "max_stars_repo_name": "rdietric/lsms", "max_stars_repo_head_hexsha": "8d0d5f01186abf9a1cc54db3f97f9934b422cf92", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2020-01-05T20:05:31.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T09:08:01.000Z", "max_issues_repo_path": "src/Potential/rs.f", "max_issues_repo_name": "rdietric/lsms", "max_issues_repo_head_hexsha": "8d0d5f01186abf9a1cc54db3f97f9934b422cf92", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2019-07-30T13:59:18.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T17:43:35.000Z", "max_forks_repo_path": "lsms/src/Potential/rs.f", "max_forks_repo_name": "hkershaw-brown/MuST", "max_forks_repo_head_hexsha": "9db4bc5061c2f2c4d7dfd92f53b4ef952602c070", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2020-02-11T17:04:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-28T09:23:46.000Z", "avg_line_length": 30.7735849057, "max_line_length": 75, "alphanum_fraction": 0.5965665236, "num_tokens": 549, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299591537478, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6876013062528981}} {"text": "program rationals\nuse rationals_mod\nimplicit none\ntype(rational) :: a, b, c, d\n\na = rational(2, 3)\ncall rat_print(a)\nb = rational(1, 5)\ncall rat_print(b)\nd = a + b\ncall rat_print(d)\na = rational(1, 4)\nb = rational(1, 4)\nd = a + b\ncall rat_print(d)\n\na = rational(-2, 4)\nb = rational(1, 4)\nd = a + b\ncall rat_print(d)\n\na = rational(2, -4)\nb = rational(1, 4)\nd = a + b\ncall rat_print(d)\n\na = rational(2, -4)\nb = rational(1, 4)\nd = a*b\ncall rat_print(d)\n\na = rational(2, -4)\nd = 3*a\ncall rat_print(d)\n\nc = rational(3, 0)\ncall rat_print(c)\n\nend program rationals\n", "meta": {"hexsha": "3f313c317ec5384004b6c600f4ad61d4374554bd", "size": 558, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran/OOProgramming/rationals.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/OOProgramming/rationals.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/OOProgramming/rationals.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": 13.95, "max_line_length": 28, "alphanum_fraction": 0.6362007168, "num_tokens": 218, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312226373181, "lm_q2_score": 0.7577943822145998, "lm_q1q2_score": 0.6875561080602178}} {"text": " SUBROUTINE zroots(a,m,roots,polish)\r\n INTEGER m,MAXM\r\n REAL EPS\r\n COMPLEX a(m+1),roots(m)\r\n LOGICAL polish\r\n PARAMETER (EPS=1.e-6,MAXM=101)\r\nCU USES laguer\r\n INTEGER i,j,jj,its\r\n COMPLEX ad(MAXM),x,b,c\r\n do 11 j=1,m+1\r\n ad(j)=a(j)\r\n11 continue\r\n do 13 j=m,1,-1\r\n x=cmplx(0.,0.)\r\n call laguer(ad,j,x,its)\r\n if(abs(aimag(x)).le.2.*EPS**2*abs(real(x))) x=cmplx(real(x),0.)\r\n roots(j)=x\r\n b=ad(j+1)\r\n do 12 jj=j,1,-1\r\n c=ad(jj)\r\n ad(jj)=b\r\n b=x*b+c\r\n12 continue\r\n13 continue\r\n if (polish) then\r\n do 14 j=1,m\r\n call laguer(a,m,roots(j),its)\r\n14 continue\r\n endif\r\n do 16 j=2,m\r\n x=roots(j)\r\n do 15 i=j-1,1,-1\r\n if(real(roots(i)).le.real(x))goto 10\r\n roots(i+1)=roots(i)\r\n15 continue\r\n i=0\r\n10 roots(i+1)=x\r\n16 continue\r\n return\r\n END\r\n", "meta": {"hexsha": "be06ac63b25ae5143c9ea120dc63ae51e55e74f2", "size": 968, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/zroots.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/zroots.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/zroots.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.6097560976, "max_line_length": 72, "alphanum_fraction": 0.4617768595, "num_tokens": 335, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122313857378, "lm_q2_score": 0.7577943767446201, "lm_q1q2_score": 0.6875561068957258}} {"text": "program main\n\n use open_linalg_m, only: solve\n\n real :: a(2, 2) = reshape([1.0, 3.0, 2.0, 4.0], [2, 2]), &\n b(2, 1) = reshape([7.0, 15.0], [2, 1])\n\n b = solve(a, b)\n print 100, b\n\n100 format(*(f6.2))\n\nend program main\n\n! 1.00 3.00\n", "meta": {"hexsha": "43d902a489ce213d2d80780675137696d24d51eb", "size": 257, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/demo_solve.f90", "max_stars_repo_name": "zoziha/open_linalg", "max_stars_repo_head_hexsha": "219c7b4e014719a6d80581c132803712dcddc43c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2022-03-09T10:40:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-13T08:59:14.000Z", "max_issues_repo_path": "example/demo_solve.f90", "max_issues_repo_name": "zoziha/open_linalg", "max_issues_repo_head_hexsha": "219c7b4e014719a6d80581c132803712dcddc43c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-03-09T16:57:28.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-10T00:29:32.000Z", "max_forks_repo_path": "example/demo_solve.f90", "max_forks_repo_name": "zoziha/open_linalg", "max_forks_repo_head_hexsha": "219c7b4e014719a6d80581c132803712dcddc43c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.0625, "max_line_length": 62, "alphanum_fraction": 0.4902723735, "num_tokens": 118, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9073122213606241, "lm_q2_score": 0.7577943822145998, "lm_q1q2_score": 0.6875561042617303}} {"text": "\nc\nc THis subprogram is to find the mean and rms of the qv,\nc Qc, S, and Temperature\nc\n\n\tsubroutine mean_rms(m1,m4,TH1,Th2,TH3,Th4,Th1_mean,TH2_mean,\n $ TH3_mean,Th4_mean,Th1_rms,Th2_rms,TH3_rms,TH4_rms,ip,\n $ mip,igrid)\n\n\tinteger*4 igrid\n real*8 Th1(igrid),Th2(igrid),Th3(igrid),Th4(igrid)\n\treal*8 th1_mean(0:mip),th2_mean(0:mip),th3_mean(0:mip)\n $ ,th4_mean(0:mip)\n\treal*8 th1_rms(0:mip),th2_rms(0:mip),th3_rms(0:mip),\n $ th4_rms(0:mip)\n\n\tsum1=0.\n\tsum2=0.\n\tsum3=0.\n\tsum4=0.\n\t\n\tDO i=m1,m4\n\tsum1=sum1+TH1(i)\n\tsum2=sum2+TH2(i)\n\tsum3=sum3+Th3(i)\n\tsum4=sum4+TH4(i)\n\tend do\n\t\n\tN=m4-m1+1\n\tth1_mean(ip)=sum1/float(N)\n\tth2_mean(ip)=sum2/float(n)\n\tth3_mean(ip)=sum3/float(N)\n\tth4_mean(ip)=sum4/float(N)\n\n\tprim1=0.\n\tprim2=0.\n\tprim3=0.\n\tprim4=0.\n\n\tDo i=m1,m4\n\tprim1=prim1+(TH1(i)-th1_mean(ip))**2.\n\tprim2=prim2+(TH2(i)-th2_mean(ip))**2.\n\tprim3=prim3+(TH3(i)-TH3_mean(ip))**2.\n\tprim4=prim4+(TH4(i)-TH4_mean(ip))**2.\n\tend do\n\n\tTH1_rms(ip)=(prim1/float(n))**.5\n\tTH2_rms(ip)=(prim2/float(n))**.5\n\tTH3_rms(ip)=(prim3/float(n))**.5\n\tTh4_rms(ip)=(prim4/float(n))**.5\nc\twrite(*,*)'mean and rms'\nc\twrite(*,*)th1_mean(ip),Th2_mean(ip),Th3_mean(ip),Th4_mean(ip)\nc\twrite(*,*)TH1_rms(ip),TH2_rms(ip),Th3_rms(ip),Th4_rms(ip)\n\treturn \n\tend\n", "meta": {"hexsha": "5f71ab95529b83824f75427765f5aaca16d5404f", "size": 1269, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/mean_rms.f", "max_stars_repo_name": "phaustin/empm", "max_stars_repo_head_hexsha": "13bbb7c6568e374c973ea570b064f34a48c6cd8e", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/mean_rms.f", "max_issues_repo_name": "phaustin/empm", "max_issues_repo_head_hexsha": "13bbb7c6568e374c973ea570b064f34a48c6cd8e", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/mean_rms.f", "max_forks_repo_name": "phaustin/empm", "max_forks_repo_head_hexsha": "13bbb7c6568e374c973ea570b064f34a48c6cd8e", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2015-08-24T14:59:46.000Z", "max_forks_repo_forks_event_max_datetime": "2015-08-24T14:59:46.000Z", "avg_line_length": 22.2631578947, "max_line_length": 67, "alphanum_fraction": 0.6446020489, "num_tokens": 579, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122313857378, "lm_q2_score": 0.7577943658046609, "lm_q1q2_score": 0.6875560969697669}} {"text": "subroutine line_gs_solver(phi, ap_phi, aw_phi, ae_phi, as_phi, an_phi, b_phi, f_phi, nx, ny, alpha, xi, xf)\nuse kind_parameters\nimplicit none\n\ninteger, intent(in):: nx, ny, xi, xf\nreal(kind=dp), intent(inout), dimension(nx,xi-1:xf+1):: phi\nreal(kind=dp), intent(in), dimension(nx,xi-1:xf+1):: ap_phi, aw_phi, ae_phi, as_phi, an_phi, b_phi, f_phi\nreal(kind=dp), intent(in):: alpha\n\ninteger:: i, j, N\nreal(kind=dp):: alpha_inv\nreal(kind=dp), allocatable:: a(:,:), b(:)\n!real(kind=dp):: dx(nx), dy(ny), delx(-2:nx+2), dely(-2:ny+2)\n\nalpha_inv = 1.0d0/alpha\n\n!\tSweep from bottom to top\n!\tImplicit in X\n\nN = nx-2\nallocate(a(N,3), b(N))\n\na(1,1) = 0.0d0\na(nx-2,3) = 0.0d0\n\ndo j = xi,xf\n\n a(1,2) = ap_phi(2,j)*alpha_inv\n a(1,3) = -ae_phi(2,j)\n b(1) = as_phi(2,j)*phi(2,j-1) + an_phi(2,j)*phi(2,j+1) + phi(2,j)*ap_phi(2,j)*(alpha_inv-1.0d0) + aw_phi(2,j)*phi(1,j) + b_phi(2,j) + f_phi(2,j)\n\n do i=3,nx-2\n\n a(i-1,1) = -aw_phi(i,j)\n a(i-1,2) = ap_phi(i,j)*alpha_inv\n a(i-1,3) = -ae_phi(i,j)\n b(i-1) = an_phi(i,j)*phi(i,j+1) + as_phi(i,j)*phi(i,j-1) + ap_phi(i,j)*(alpha_inv-1.0d0)*phi(i,j) + b_phi(i,j) + f_phi(i,j)\n\n end do\n\n a(nx-2,1) = -aw_phi(nx-1,j)\n a(nx-2,2) = ap_phi(nx-1,j)*alpha_inv\n b(nx-2) = as_phi(nx-1,j)*phi(nx-1,j-1) + an_phi(nx-1,j)*phi(nx-1,j+1) + ap_phi(nx-1,j)*phi(nx-1,j)*(alpha_inv-1.0d0) + ae_phi(nx-1,j)*phi(nx,j) + b_phi(nx-1,j) + f_phi(nx-1,j)\n\n call tdma(a, b, N)\n\n do i = 1,N\n\n phi(i+1,j) = b(i)\n\n end do\n\nend do\n\ncall exchange_data(phi, nx, xi, xf)\n\n!\tSweep from top to bottom\n!\tImplicit in X\n\n\ndo j = xf,xi,-1\n\n a(1,2) = ap_phi(2,j)*alpha_inv\n a(1,3) = -ae_phi(2,j)\n b(1) = as_phi(2,j)*phi(2,j-1) + an_phi(2,j)*phi(2,j+1) + phi(2,j)*ap_phi(2,j)*(alpha_inv-1.0d0) + aw_phi(2,j)*phi(1,j) + b_phi(2,j)+ f_phi(2,j)\n\n do i=3,nx-2\n\n a(i-1,1) = -aw_phi(i,j)\n a(i-1,2) = ap_phi(i,j)*alpha_inv\n a(i-1,3) = -ae_phi(i,j)\n b(i-1) = an_phi(i,j)*phi(i,j+1) + as_phi(i,j)*phi(i,j-1) + ap_phi(i,j)*(alpha_inv-1.0d0)*phi(i,j) + b_phi(i,j) + f_phi(i,j)\n\n end do\n\n a(nx-2,1) = -aw_phi(nx-1,j)\n a(nx-2,2) = ap_phi(nx-1,j)*alpha_inv\n b(nx-2) = as_phi(nx-1,j)*phi(nx-1,j-1) + an_phi(nx-1,j)*phi(nx-1,j+1) + ap_phi(nx-1,j)*phi(nx-1,j)*(alpha_inv-1.0d0) + ae_phi(nx-1,j)*phi(nx,j) + b_phi(nx-1,j) + f_phi(nx-1,j)\n\n call tdma(a, b, N)\n\n do i = 1,N\n\n phi(i+1,j) = b(i)\n\n end do\n\nend do\n\n\ndeallocate(a,b)\n\ncall exchange_data(phi, nx, xi, xf)\n\nend subroutine\n", "meta": {"hexsha": "a67c8551c9be8fd63c214f7f53b3ce0743729023", "size": 2614, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "line_gs_solver.f90", "max_stars_repo_name": "pratanuroy/Multigrid_Cavity", "max_stars_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-09-11T12:01:52.000Z", "max_stars_repo_stars_event_max_datetime": "2017-09-11T12:01:52.000Z", "max_issues_repo_path": "line_gs_solver.f90", "max_issues_repo_name": "pratanuroy/Multigrid_Cavity", "max_issues_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "line_gs_solver.f90", "max_forks_repo_name": "pratanuroy/Multigrid_Cavity", "max_forks_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.2291666667, "max_line_length": 183, "alphanum_fraction": 0.5359602142, "num_tokens": 1112, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122188543453, "lm_q2_score": 0.7577943658046608, "lm_q1q2_score": 0.6875560874735481}} {"text": "\n\n*$ Section 1: Special Functions\n* ----------------------------\n\n*+ fun_gammp\n\n real function fun_gammp( a, x, istat )\nC --------------------------------------\nC\nC Returns the incomplete gamma function P(a,x) by argument\nC\nC Given:\nC parameters for the function\n real*4 a, x\nC Updated:\nC error return\n integer istat\nC\nC The incomplete Gamma function P(a,x) is defined by:\nC \\[\nC P(a,x) = \\frac{1}{\\Gamma(a)} \\int_{0}^{x} e^{-t}t^{a-1} dt\nC \\]\nC for $a > 0$.\n\nC ISTAT should be zero on entry. The values set by this routine are:\nC ILL_INPUTS == illegal ranges on input data.\nC ILL_PRECISION == unable to calculate function to sufficient\nC precision. This error can be returned from\nC one of the internal routines and results from\nC a to large or not enough iterations within\nC the respective routine. This error MUST\nC be reported.\nC\nC P. Alexander, MRAO, Cambridge.\nC Ref: Numerical Recipes, Press et al., Cambridge. pg. 160.\nC-\n\n include '../include/utilities_errors.inc'\n\nC local variables\n real*4 gamser, gammcf, gln\n\n if (istat.ne.0) return\n\n if (x.lt.0.0 .or. a.le.0.0) then\n istat = ill_inputs\n fun_gammp = 0.0\n else\n if (x.lt.a+1.0) then\nC .. use series representation\n call fun_gser(gamser,a,x,gln,istat)\n fun_gammp = gamser\n else\nC .. use continued fraction\n call fun_gcf(gammcf,a,x,gln,istat)\nC .. take complement\n fun_gammp = 1.0 - gammcf\n end if\n end if\n call utl_err( istat,'fun_gammp','Failed' )\n end\n", "meta": {"hexsha": "46f228e009a563c25cb46bcfe7d4d36aa0506adc", "size": 1742, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "image_lib/fun_gammp.f", "max_stars_repo_name": "CavendishAstrophysics/anmap", "max_stars_repo_head_hexsha": "efb611d7f80a3d14dc55e46cd01e8a622f6fd294", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-09-01T12:40:45.000Z", "max_stars_repo_stars_event_max_datetime": "2015-09-01T12:40:45.000Z", "max_issues_repo_path": "image_lib/fun_gammp.f", "max_issues_repo_name": "CavendishAstrophysics/anmap", "max_issues_repo_head_hexsha": "efb611d7f80a3d14dc55e46cd01e8a622f6fd294", "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": "image_lib/fun_gammp.f", "max_forks_repo_name": "CavendishAstrophysics/anmap", "max_forks_repo_head_hexsha": "efb611d7f80a3d14dc55e46cd01e8a622f6fd294", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.6507936508, "max_line_length": 73, "alphanum_fraction": 0.552238806, "num_tokens": 482, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9073122113355091, "lm_q2_score": 0.757794360334681, "lm_q1q2_score": 0.6875560768128369}} {"text": "\tPROGRAM TEST\nC\n\tDO N = 1,100\n\t Y = (-50. +N)/10.\n\t DL = ALOG(COSH(Y))\n\t PRINT*,N,Y,DL\n\t WRITE(33,*) N,Y,DL\n\tENDDO\n\tSTOP\n\tEND\n", "meta": {"hexsha": "1ac10a78cb5b4142eb8ea1610a3d8ebf41ca70c2", "size": 130, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/test_2.for", "max_stars_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_stars_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/test_2.for", "max_issues_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_issues_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/test_2.for", "max_forks_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_forks_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 11.8181818182, "max_line_length": 21, "alphanum_fraction": 0.5230769231, "num_tokens": 64, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9005297914570319, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6875398792206618}} {"text": "subroutine sldsup_GetPhysicalParameters_lin(a,ndime,sz,densi,K,G,C_dev,D,D_dev,Dv_scalar,id,ielem)\n use typre\n use Mod_SUPSolids_lin\n implicit none\n class(SUPSolidsProblem_lin), target :: a\n integer(ip),intent(in) :: ndime,sz\n real(rp), intent(out):: densi,K,G,Dv_scalar\n real(rp), intent(out):: C_dev(sz,sz),D(sz,sz),D_dev(sz,sz),id(sz,sz)\n integer(ip),optional :: ielem\n real(rp) :: D_vol(sz,sz)\n real(rp) :: D_aux(sz,1)\n real(rp) :: ii_tt(sz,sz),iv(sz,sz)\n \n densi = a%densi\n K = a%bulkMod\n G = a%mu\n\n call get4thIITensor(ndime,sz,ii_tt)\n call get4thIIVolumetricTensor(ndime,sz,iv)\n\n !Also known as P\n id = ii_tt - iv\n\n C_dev = (2.0_rp*G)*id\n\n D_vol = (ndime/K)*iv\n D_dev = (1.0_rp/(2.0_rp*G))*id\n\n D = D_vol + D_dev \n\n if(ndime==2) then\n Dv_scalar= 16.0_rp/(27.0_rp*K)\n else \n Dv_scalar= 1.0_rp/K\n endif\n\nend subroutine\n", "meta": {"hexsha": "b966ccd3bfaf1aacaa6b42cc18d8f7fcfb513f5d", "size": 948, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Sources/modules/solids/models/sldsup/Elmopes/linear/sldsup_GetPhysicalParameters.f90", "max_stars_repo_name": "ciaid-colombia/InsFEM", "max_stars_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-24T08:19:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-24T08:19:54.000Z", "max_issues_repo_path": "Sources/modules/solids/models/sldsup/Elmopes/linear/sldsup_GetPhysicalParameters.f90", "max_issues_repo_name": "ciaid-colombia/InsFEM", "max_issues_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Sources/modules/solids/models/sldsup/Elmopes/linear/sldsup_GetPhysicalParameters.f90", "max_forks_repo_name": "ciaid-colombia/InsFEM", "max_forks_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.9473684211, "max_line_length": 98, "alphanum_fraction": 0.5959915612, "num_tokens": 347, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178929, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6875398751443159}} {"text": "! Fundamental constants taken from NIST's 2010 CODATA recommended values\n\nmodule fundamental_constants_module\n\n use bl_types\n\n implicit none\n\n ! newton's gravitational constant\n real(kind=dp_t), parameter :: Gconst = 6.67428e-8_dp_t ! cm^3/g/s^2\n! new value; if uncommented initial models will need to be re-HSE'ed\n! real(kind=dp_t), parameter :: Gconst = 6.67384e-8_dp_t ! cm^3/g/s^2\n\n ! boltzmann's constant\n real(kind=dp_t), parameter :: k_B = 1.3806488e-16_dp_t ! erg/K\n\n ! planck's constant over 2pi\n real(kind=dp_t), parameter :: hbar = 1.054571726e-27_dp_t ! erg s\n\n ! planck's constant \n real(kind=dp_t), parameter :: hplanck = 6.62606957e-27_dp_t ! erg s\n\n ! avogradro's Number\n real(kind=dp_t), parameter :: n_A = 6.02214129e23_dp_t ! mol^-1\n\n ! convert eV to erg\n real(kind=dp_t), parameter :: ev2erg = 1.602176487e-12_dp_t\n\n ! convert MeV to eV\n real(kind=dp_t), parameter :: MeV2eV = 1.0e6_dp_t\n\n ! mass of proton\n real(kind=dp_t), parameter :: m_p = 1.672621777e-24_dp_t ! g\n\n ! mass of neutron\n real(kind=dp_t), parameter :: m_n = 1.674927351e-24_dp_t ! g\n\n ! mass of electron\n real(kind=dp_t), parameter :: m_e = 9.10938291e-28_dp_t ! g\n\n ! speed of light in vacuum\n real(kind=dp_t), parameter :: c_light = 2.99792458e10_dp_t ! cm/s\n\n ! electron charge\n ! NIST: q_e = 1.602176565e-19 C\n !\n ! C is the SI unit Coulomb; in cgs we have the definition:\n ! 1 C = 0.1 * |c_light| * 1 statC\n ! where statC is the cgs unit statCoulomb; 1 statC = 1 erg^1/2 cm^1/2\n ! and |c_light| is the speed of light in cgs (but without units)\n real(kind=dp_t), parameter :: q_e = 4.80320451e-10_dp_t ! erg^1/2 cm^1/2\n\n ! stefan-boltzmann constant\n real(kind=dp_t), parameter :: sigma_SB = 5.670373e-5_dp_t ! erg/s/cm^2/K^4\n\n ! radiation constant\n real(kind=dp_t), parameter :: a_rad = 4.0_dp_t*sigma_SB/c_light\n\n ! Hubble constant (in s^{-1}, converted from 100 (km/s)/Mpc by dividing by 3.08568025e19km/Mpc)\n real(kind=dp_t), parameter :: Hubble_const = 32.407764868e-19\n\nend module fundamental_constants_module\n", "meta": {"hexsha": "81585604884d740e74055447ae5d50e9ff5e2c1f", "size": 2096, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Source/constants_cgs.f90", "max_stars_repo_name": "sailoridy/MAESTRO", "max_stars_repo_head_hexsha": "f957d148d2028324a2a1076be244f73dad63fd67", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2017-05-15T15:28:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-09T08:13:32.000Z", "max_issues_repo_path": "Source/constants_cgs.f90", "max_issues_repo_name": "sailoridy/MAESTRO", "max_issues_repo_head_hexsha": "f957d148d2028324a2a1076be244f73dad63fd67", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": 17, "max_issues_repo_issues_event_min_datetime": "2017-06-14T23:05:00.000Z", "max_issues_repo_issues_event_max_datetime": "2018-11-28T16:40:42.000Z", "max_forks_repo_path": "Source/constants_cgs.f90", "max_forks_repo_name": "sailoridy/MAESTRO", "max_forks_repo_head_hexsha": "f957d148d2028324a2a1076be244f73dad63fd67", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2017-06-14T14:52:09.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-04T07:16:09.000Z", "avg_line_length": 33.2698412698, "max_line_length": 97, "alphanum_fraction": 0.6798664122, "num_tokens": 765, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297807787537, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6875398613753997}} {"text": " SUBROUTINE DLESUM(X,N,A,SUM)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nC>> 1994-10-20 DLESUM Krogh Changes to use M77CON\nC>> 1994-04-20 DLESUM CLL Edited to make DP & SP files similar.\nC>> 1992-03-13 DLESUM FTK Removed implicit statements.\nC>> 1985-08-02 DLESUM Lawson Initial code.\nC\nC THIS SUBROUTINE EVALUATES THE SUM OF\nC A(J) * P(J) FOR J = 0,...,N,\nC WHERE P(J)'S ARE LEGENDRE POLYNOMIALS OF DEGREE J.\nC\nC THE RECURSION FORMULA IS :\nC B(K) = X+B(K+1)*(2*K+1)/(K+1)-B(K+2)*(K+1)/(K+2)+A(K)\nC\nC C.L.LAWSON & S.CHAN, JPL, 1983 JUNE 9\nC\nC -------------------------------------------------------------\nC SUBROUTINE ARGUMENTS\nC --------------------\nC X ARGUMENT OF LEG POLYS, X SHOULD BE NON-NEGATIVE.\nC N SUM IS TO INCLUDE LEGENDRE POLYS OF DEGREE ZERO\nC THRU N.\nC A() A,...,A(N) CONTAIN COEFFS TO BE USED IN\nC FORMING THE SUM.\nC SUM SUM OF COMBINATION\nC\nC -------------------------------------------------------------\nc--D replaces \"?\": ?LESUM\nC -------------------------------------------------------------\n INTEGER K,N\n DOUBLE PRECISION A(0:N),B,B1,B2,C1,C2,C3\n DOUBLE PRECISION ONE,SUM,TWO,X,ZERO\n DATA ZERO,ONE,TWO / 0.D0, 1.D0, 2.D0 /\nC -------------------------------------------------------------\n IF (N .lt. 0) then\n SUM = ZERO\n RETURN\n endif\nC\n C1 = DBLE(N+1)\n C3 = C1 + C1 - ONE\n B1 = ZERO\n B = A(N)\nC\n DO 10 K = N-1,0,-1\nC\nC C1 = K + 1, C3 = 2K + 1\nC\n C2 = C1\n C1 = C1 - ONE\n C3 = C3 - TWO\n B2 = B1\n B1 = B\n B = X * B1 * C3 / C1 - B2 * C1 / C2 + A(K)\n 10 CONTINUE\n SUM = B\n RETURN\n END\n", "meta": {"hexsha": "478ea6de2616821dade36d2fa89083684a5d9219", "size": 1856, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/dlesum.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/dlesum.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/dlesum.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": 30.4262295082, "max_line_length": 70, "alphanum_fraction": 0.4719827586, "num_tokens": 630, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.900529778109184, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6875398593372266}} {"text": " subroutine krnlcolumnupdate( m, n, A, ldA, cvec, svec )\n\n implicit none\n\n*\n* PURPOSE\n* =======\n*\n* Applies a decreasing sequence of n - 1 column rotations to a\n* rectangular m-by-n matrix A.\n*\n* More specifically, the following update of A is performed:\n*\n* A := A * G(k) * G(k-1) * ... * G(2)\n*\n* where G(k) for k = 2, 3, ..., n affects only columns k - 1 and k\n* in the following way. Let x denote column k - 1 and y denote\n* column k. Furthermore, define c = cvec(k) and s = svec(k). Then\n* the effect of A * G(k) is equivalent to the update\n*\n* [ x y ] := [ x y ] * [ c -s ]\n* [ s c ].\n*\n*\n* ARGUMENTS\n* =========\n*\n* m (input) INTEGER\n*\n* The number of rows in A.\n*\n* n (input) INTEGER\n*\n* The number of columns in A.\n*\n* A (input/output) DOUBLE PRECISION array\n* dimension ldA-by-n\n*\n* The matrix A.\n*\n* ldA (input) INTEGER\n*\n* The column stride of A.\n*\n* cvec (input) DOUBLE PRECISION array\n* dimension n\n* \n* cvec(k) is the c-parameter of G(k).\n*\n* svec (input) DOUBLE PRECISION array\n* dimension m\n*\n* svec(k) is the s-parameter of G(k).\n* \n\n* \n* Scalar arguments.\n* \n integer m, n, ldA\n\n*\n* Array arguments.\n* \n double precision A( ldA, * ), cvec( * ), svec( * )\n\n*\n* Local scalars.\n* \n integer i, j\n double precision c, s, x, y\n\n do j = n, 2, -1\n c = cvec( j )\n s = svec( j )\n do i = 1, m\n x = A( i, j - 1 )\n y = A( i, j )\n A( i, j - 1 ) = c * x - s * y\n A( i, j ) = s * x + c * y\n end do\n end do\n \n end subroutine\n\n", "meta": {"hexsha": "c2b01d64c08b1c860c9d74de0d02b622d2169060", "size": 1932, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/3rdparty/pdgghrd/KRNLCOLUMNUPDATE.f", "max_stars_repo_name": "NLAFET/StarNEig", "max_stars_repo_head_hexsha": "d47ed4dfbcdaec52e44f0b02d14a6e0cde64d286", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2019-04-28T17:13:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-24T12:30:19.000Z", "max_issues_repo_path": "src/3rdparty/pdgghrd/KRNLCOLUMNUPDATE.f", "max_issues_repo_name": "NLAFET/StarNEig", "max_issues_repo_head_hexsha": "d47ed4dfbcdaec52e44f0b02d14a6e0cde64d286", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/3rdparty/pdgghrd/KRNLCOLUMNUPDATE.f", "max_forks_repo_name": "NLAFET/StarNEig", "max_forks_repo_head_hexsha": "d47ed4dfbcdaec52e44f0b02d14a6e0cde64d286", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2019-04-30T12:14:12.000Z", "max_forks_repo_forks_event_max_datetime": "2020-04-14T09:41:23.000Z", "avg_line_length": 22.7294117647, "max_line_length": 70, "alphanum_fraction": 0.4270186335, "num_tokens": 561, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297781091839, "lm_q2_score": 0.7634837527911057, "lm_q1q2_score": 0.6875398544909415}} {"text": "PROGRAM test_selected_kinds\r\n!\r\n! Purpose: \r\n! To determine selected real kinds.\r\n! \r\nIMPLICIT NONE\r\nINTEGER :: kind_number ! Resulting kind number\r\n\r\n! Display kind numbers\r\nkind_number = SELECTED_REAL_KIND(p=6,r=37)\r\nWRITE (*,*) 'SELECTED_REAL_KIND(p=6,r=37) = ', kind_number\r\nkind_number = SELECTED_REAL_KIND(p=12) \r\nWRITE (*,*) 'SELECTED_REAL_KIND(p=12) = ', kind_number\r\nkind_number = SELECTED_REAL_KIND(r=100) \r\nWRITE (*,*) 'SELECTED_REAL_KIND(r=100) = ', kind_number\r\nkind_number = SELECTED_REAL_KIND(13,200) \r\nWRITE (*,*) 'SELECTED_REAL_KIND(13,200) = ', kind_number\r\nkind_number = SELECTED_REAL_KIND(13) \r\nWRITE (*,*) 'SELECTED_REAL_KIND(13) = ', kind_number\r\nkind_number = SELECTED_REAL_KIND(p=17) \r\nWRITE (*,*) 'SELECTED_REAL_KIND(p=17) = ', kind_number\r\n \r\nEND PROGRAM test_selected_kinds\r\n", "meta": {"hexsha": "9c59d3e4fe1a6aed8802aec36788016bf275896d", "size": 819, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap11/test_selected_kinds.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/test_selected_kinds.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/test_selected_kinds.f90", "max_forks_repo_name": "yangyang14641/FortranLearning", "max_forks_repo_head_hexsha": "3d4a91aacd957361aff5873054edf35c586e8a55", "max_forks_repo_licenses": ["AFL-3.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-05-11T02:36:25.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-05T06:36:55.000Z", "avg_line_length": 34.125, "max_line_length": 59, "alphanum_fraction": 0.706959707, "num_tokens": 239, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737869342623, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.6873972082382447}} {"text": "PROGRAM SELECTION\n\n IMPLICIT NONE\n\n INTEGER :: intArray(10) = (/ 4, 9, 3, -2, 0, 7, -5, 1, 6, 8 /)\n\n WRITE(*,\"(A,10I5)\") \"Unsorted array:\", intArray\n CALL Selection_sort(intArray)\n WRITE(*,\"(A,10I5)\") \"Sorted array :\", intArray\n\nCONTAINS\n\n SUBROUTINE Selection_sort(a)\n INTEGER, INTENT(IN OUT) :: a(:)\n INTEGER :: i, minIndex, temp\n\n DO i = 1, SIZE(a)-1\n minIndex = MINLOC(a(i:), 1) + i - 1\n IF (a(i) > a(minIndex)) THEN\n temp = a(i)\n a(i) = a(minIndex)\n a(minIndex) = temp\n END IF\n END DO\n END SUBROUTINE Selection_sort\n\nEND PROGRAM SELECTION\n", "meta": {"hexsha": "ed99785d8c43d1c793f4347fe4577dd3a2d15b54", "size": 609, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Sorting-algorithms-Selection-sort/Fortran/sorting-algorithms-selection-sort.f", "max_stars_repo_name": "mullikine/RosettaCodeData", "max_stars_repo_head_hexsha": "4f0027c6ce83daa36118ee8b67915a13cd23ab67", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Sorting-algorithms-Selection-sort/Fortran/sorting-algorithms-selection-sort.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Sorting-algorithms-Selection-sort/Fortran/sorting-algorithms-selection-sort.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 21.75, "max_line_length": 64, "alphanum_fraction": 0.5665024631, "num_tokens": 216, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511322604133, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.6873972050300429}} {"text": "program serial\n implicit none\n\n integer, parameter :: width=1000\n integer, parameter :: height=1000\n double precision, parameter :: temp_tolerance=0.01\n\n integer :: i, j, iteration=1\n double precision :: worst_dt=100.0\n real :: start_time, stop_time\n\n double precision, dimension(0:height+1,0:width+1) :: temperature, temperature_previous\n\n call cpu_time(start_time)\n\n call initialize(temperature_previous)\n\n do while ( worst_dt > temp_tolerance )\n\n do j=1,width\n do i=1,height\n temperature(i,j)=0.25*(temperature_previous(i+1,j)+temperature_previous(i-1,j)+ &\n temperature_previous(i,j+1)+temperature_previous(i,j-1) )\n enddo\n enddo\n\n worst_dt=0.0\n\n do j=1,width\n do i=1,height\n worst_dt = max( abs(temperature(i,j) - temperature_previous(i,j)), worst_dt )\n temperature_previous(i,j) = temperature(i,j)\n enddo\n enddo\n\n if( mod(iteration,100).eq.0 ) then\n call track_progress(temperature, iteration)\n endif\n\n iteration = iteration+1\n\n enddo\n\n call cpu_time(stop_time)\n\n print*, 'Max error at iteration ', iteration-1, ' was ',worst_dt\n print*, 'Total time was ',stop_time-start_time, ' seconds.'\n\nend program serial\n\n\nsubroutine initialize( temperature_previous )\n implicit none\n\n integer, parameter :: width=1000\n integer, parameter :: height=1000\n integer :: i,j\n\n double precision, dimension(0:height+1,0:width+1) :: temperature_previous\n\n temperature_previous = 0.0\n\n do i=0,height+1\n temperature_previous(i,0) = 0.0\n temperature_previous(i,width+1) = (100.0/height) * i\n enddo\n\n do j=0,width+1\n temperature_previous(0,j) = 0.0\n temperature_previous(height+1,j) = ((100.0)/width) * j\n enddo\n\nend subroutine initialize\n\n\nsubroutine track_progress(temperature, iteration)\n implicit none\n\n integer, parameter :: width=1000\n integer, parameter :: height=1000\n integer :: i,iteration\n\n double precision, dimension(0:height+1,0:width+1) :: temperature\n\n print *, '---------- Iteration number: ', iteration, ' ---------------'\n do i=5,0,-1\n write (*,'(\"(\"i4,\",\",i4,\"):\",f6.2,\" \")',advance='no') &\n height-i,width-i,temperature(height-i,width-i)\n enddo\n print *\nend subroutine track_progress\n", "meta": {"hexsha": "9372d3c8e336e5026d0e1252539b32d17256932d", "size": 2699, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Code_Examples/Chapter_04/laplace_serial.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_04/laplace_serial.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_04/laplace_serial.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": 29.3369565217, "max_line_length": 96, "alphanum_fraction": 0.5557613931, "num_tokens": 640, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.6873497099461418}} {"text": "program test_interp2\n!! Need program statement for FORD\nuse phys_consts, only: wp,pi\nuse interpolation, only : interp2\nuse h5fortran, only : hdf5_file\n\nimplicit none (type, external)\n\ntype(hdf5_file) :: hout\ninteger, parameter :: lx1=50, lx2=100, lx1i=500, lx2i=1000\n!integer, parameter :: lx1=1000, lx2=1000\n!integer, parameter :: lx1i=8000, lx2i=8000\nreal(wp), parameter :: stride=0.5_wp\n\nreal(wp), allocatable, dimension(:,:) :: f, fi\nreal(wp), allocatable, dimension(:) :: x1ilist, x2ilist, filist, x1, x2, x1i, x2i\n\ninteger :: ix1,ix2,ik\n\nallocate(x1(lx1), x2(lx2), f(lx1,lx2),x1i(lx1i), x2i(lx2i), fi(lx1i,lx2i))\nallocate(x1ilist(1:lx1i*lx2i), x2ilist(1:lx1i*lx2i), filist(1:lx1i*lx2i))\n\n!grid for original data\nx1=[ ((real(ix1,wp)-1._wp)*stride, ix1=1,lx1) ]\nx2=[ ((real(ix2,wp)-1._wp)*stride, ix2=1,lx2) ]\n\n\n!center grid points at zero\nx1=x1-sum(x1)/size(x1,1)\nx2=x2-sum(x2)/size(x2,1)\n\n\n!test function\ndo ix2=1,lx2\n f(:,ix2)=sin(2._wp*pi/5._wp*x1)*cos(2._wp*pi/50._wp*x2(ix2))\nend do\n\n\n!> grid for interpolated data\nx1i=[ ((real(ix1,wp)-1)*stride/(lx1i/lx1), ix1=1,lx1i) ]\nx2i=[ ((real(ix2,wp)-1)*stride/(lx2i/lx2), ix2=1,lx2i) ]\n\n\n!> center grid points at zero\nx1i=x1i-sum(x1i)/size(x1i,1)\nx2i=x2i-sum(x2i)/size(x2i,1)\n\n\n!> try a 2d interpolation\n!fi=interp2_plaid(x1,x2,f,x1i,x2i)\ndo ix2=1,lx2i\n do ix1=1,lx1i\n ik=(ix2-1)*lx1i+ix1\n x1ilist(ik)=x1i(ix1)\n x2ilist(ik)=x2i(ix2)\n end do\nend do\nfilist=interp2(x1,x2,f,x1ilist,x2ilist)\nfi=reshape(filist,[lx1i,lx2i])\n\n\n!! dump results to a file so we can check things\ncall hout%initialize(\"input2d.h5\", status=\"replace\", action=\"write\")\n\ncall hout%write(\"/lx1\", lx1)\ncall hout%write(\"/lx2\", lx2)\ncall hout%write(\"/x1\", x1)\ncall hout%write(\"/x2\", x2)\ncall hout%write(\"/f\", f)\n\ncall hout%finalize()\n\n\ncall hout%initialize(\"output2d.h5\", status=\"replace\", action=\"write\")\n\ncall hout%write(\"/lx1\", lx1i)\ncall hout%write(\"/lx2\", lx2i)\ncall hout%write(\"/x1\", x1i)\ncall hout%write(\"/x2\", x2i)\ncall hout%write(\"/f\", fi)\n\ncall hout%finalize()\n\nend program\n\n\n!> has no problem with > 2GB output files\n! block\n! integer :: u\n! open(newunit=u,file='input2d.dat',status='replace',form='unformatted',access='stream', action='write')\n! write(u) lx1,lx2\n! write(u) x1,x2,f\n! close(u)\n! end block\n\n! block\n! integer :: u\n! open(newunit=u,file='output2d.dat',status='replace',form='unformatted',access='stream', action='write')\n! write(u) lx1i,lx2i\n! write(u) x1i,x2i,fi !since only interpolating in x1\n! close(u)\n! end block\n", "meta": {"hexsha": "31f3513baae687cf76ce39454053d0e3951c6edc", "size": 2498, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/numerical/interpolation/testinterp2.f90", "max_stars_repo_name": "jklenzing/gemini", "max_stars_repo_head_hexsha": "aed028fbb6f6187ca951e4cd243fdec929514b2a", "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/numerical/interpolation/testinterp2.f90", "max_issues_repo_name": "jklenzing/gemini", "max_issues_repo_head_hexsha": "aed028fbb6f6187ca951e4cd243fdec929514b2a", "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/numerical/interpolation/testinterp2.f90", "max_forks_repo_name": "jklenzing/gemini", "max_forks_repo_head_hexsha": "aed028fbb6f6187ca951e4cd243fdec929514b2a", "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.2524271845, "max_line_length": 107, "alphanum_fraction": 0.676541233, "num_tokens": 1030, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.6873497047163112}} {"text": " SUBROUTINE DGELS_F95( A, B, TRANS, INFO )\n!\n! -- LAPACK95 interface driver routine (version 3.0) --\n! UNI-C, Denmark; Univ. of Tennessee, USA; NAG Ltd., UK\n! September, 2000\n!\n! .. USE STATEMENTS ..\n USE LA_PRECISION, ONLY: WP => DP\n USE LA_AUXMOD, ONLY: ERINFO, LSAME, LA_WS_GELS\n USE F77_LAPACK, ONLY: GELS_F77 => LA_GELS\n! .. IMPLICIT STATEMENT ..\n IMPLICIT NONE\n! .. SCALAR ARGUMENTS ..\n CHARACTER(LEN=1), INTENT(IN), OPTIONAL :: TRANS\n INTEGER, INTENT(OUT), OPTIONAL :: INFO\n! .. ARRAY ARGUMENTS ..\n REAL(WP), INTENT(INOUT) :: A(:,:), B(:,:)\n!----------------------------------------------------------------------\n! \n! Purpose\n! =======\n! \n! LA_GELS computes the minimum-norm least squares solution to one \n! or more real or complex linear systems of the form A*x = b, A^T*x = b\n! or A^H*x = b using a QR or LQ factorization of A. Matrix A is \n! rectangular assumed to be of full rank. The vectors b and correspon-\n! ding solution vectors x are the columns of matrices denoted B and X,\n! respectively.\n! \n! ==========\n! \n! SUBROUTINE LA_GELS( A, B, TRANS=trans, INFO=info )\n! (), INTENT( INOUT ) :: A( :, : ), \n! \t CHARACTER(LEN=1), INTENT(IN), OPTIONAL :: TRANS\n! \t INTEGER, INTENT(OUT), OPTIONAL :: INFO\n! where\n! ::= REAL | COMPLEX\n! \t ::= KIND(1.0) | KIND(1.0D0)\n! ::= B(:,:) | B(:)\n! \n! Arguments\n! =========\n! \n! A (input/output) REAL or COMPLEX rectangular array, shape (:,:).\n! On entry, the matrix A.\n! \t On exit, if size(A,1) >= size(A,2), A is overwritten by\n! \t details of its QR factorization. If size(A,1) < size(A,2), A \n! \t is overwritten by details of its LQ factorization.\n! B (input/output) REAL or COMPLEX array, shape (:,:) with \n! size(B,1) = max(size(A,1), size(A,2)) or shape (:) with \n! \t size(B) = max(size(A,1); size(A,2)).\n! \t On entry, the matrix B.\n! \t On exit, the solution matrix X. There are four cases:\n! \t 1. If TRANS = 'N' and size(A,1) >= size(A,2), then rows 1 \n! \t to size(A,2) of B contain, columnwise, the least squares\n! \t solution vector(s); the residual sum of squares for the \n! \t solution vector in a column of B is given by the sum of\n! \t squares of elements in rows size(A,2)+1 to size(A,1) of\n! \t that column.\n! \t 2. If TRANS = 'N' and size(A,1) < size(A,2), then rows 1 \n! \t to size(A,2) of B contain, columnwise, the minimum norm \n! \t solution vector(s).\n! \t 3. If TRANS = 'T' or TRANS = 'C', and size(A,1)>=size(A,2),\n! \t then rows 1 to size(A,1) of B contain, columnwise, the \n! \t minimum norm solution vector(s).\n! \t 4. If TRANS = 'T' or TRANS = 'C', and size(A,1) < size(A,2),\n! \t then rows 1 to size(A,1) of B contain, columnwise, the \n! \t least squares solution vector(s); the residual sum of \n! \t squares for the solution vector in a column of B is given\n! \t by the sum of squares of elements in rows size(A,1)+1 to \n! \t size(A,2) of that column.\n! TRANS Optional (input) CHARACTER(LEN=1).\n! Specifies the form of the system of equations:\n! \t = 'N': Ax = b (No transpose)\n! = 'T': A^T*x = b (Transpose)\n! \t = 'C': A^H*x = b (Conjugate transpose)\n! \t Default value: 'N'.\n! INFO Optional (output) INTEGER\n! = 0: successful exit.\n! \t < 0: if INFO = -i, the i-th argument had an illegal value.\n! \t If INFO is not present and an error occurs, then the program\n! \t is terminated with an error message.\n!---------------------------------------------------------------------\n! .. PARAMETERS ..\n CHARACTER(LEN=7), PARAMETER :: SRNAME = 'LA_GELS'\n CHARACTER(LEN=1), PARAMETER :: VER = 'D'\n! .. LOCAL SCALARS ..\n CHARACTER(LEN=1) :: LTRANS\n INTEGER :: LINFO, ISTAT, ISTAT1, LWORK, N, M, NRHS\n! .. LOCAL POINTERS ..\n REAL(WP), POINTER :: WORK(:)\n! .. INTRINSIC FUNCTIONS ..\n INTRINSIC SIZE, PRESENT, MAX, MIN\n! .. EXECUTABLE STATEMENTS ..\n LINFO = 0; ISTAT = 0; M = SIZE(A,1); N = SIZE(A,2); NRHS = SIZE(B,2)\n IF( PRESENT(TRANS) )THEN; LTRANS = TRANS; ELSE; LTRANS = 'N'; ENDIF\n! .. TEST THE ARGUMENTS\n IF( M < 0 .OR. N < 0 ) THEN; LINFO = -1\n ELSE IF( SIZE( B, 1 ) /= MAX(1,M,N) .OR. NRHS < 0 ) THEN; LINFO = -2\n ELSE IF( .NOT.( LSAME(LTRANS,'N') .OR. LSAME(LTRANS,'T') ) )THEN; LINFO = -3\n ELSE\n! .. CALCULATE THE OPTIMAL WORKSPACE ..\n LWORK = LA_WS_GELS( VER, M, N, NRHS, LTRANS )\n ALLOCATE( WORK(LWORK), STAT = ISTAT )\n IF( ISTAT /= 0 ) THEN\n DEALLOCATE( WORK, STAT=ISTAT1 ); LWORK = MIN(M,N) + MAX(1,M,N,NRHS)\n ALLOCATE( WORK(LWORK), STAT = ISTAT )\n IF( ISTAT /= 0 ) CALL ERINFO( -200, SRNAME, LINFO )\n END IF\n IF ( ISTAT == 0 ) THEN\n! .. CALL LAPACK77 ROUTINE\n CALL GELS_F77( LTRANS, M, N, NRHS, A, MAX(1,M), B, MAX(1,M,N), &\n WORK, LWORK, LINFO )\n ELSE; LINFO = -100; END IF\n DEALLOCATE(WORK, STAT = ISTAT1 )\n END IF\n CALL ERINFO( LINFO, SRNAME, INFO, ISTAT )\n END SUBROUTINE DGELS_F95\n", "meta": {"hexsha": "2310e5a7edda89695e929f7e056d5995dbfb462a", "size": 5101, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/la_dgels.f90", "max_stars_repo_name": "MattBurn/LAPACK95", "max_stars_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-12-29T15:07:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T10:09:22.000Z", "max_issues_repo_path": "src/la_dgels.f90", "max_issues_repo_name": "MattBurn/LAPACK95", "max_issues_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-02-21T10:46:38.000Z", "max_issues_repo_issues_event_max_datetime": "2017-10-20T17:03:14.000Z", "max_forks_repo_path": "src/la_dgels.f90", "max_forks_repo_name": "MattBurn/LAPACK95", "max_forks_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-12-29T15:34:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-15T07:12:40.000Z", "avg_line_length": 42.8655462185, "max_line_length": 80, "alphanum_fraction": 0.5614585375, "num_tokens": 1654, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.787931190663057, "lm_q1q2_score": 0.6873497003721628}} {"text": "module mod_post\n use mod_types\n implicit none\n private\n public vorticity,rotation_rate,strain_rate,q_criterion\n contains\n subroutine vorticity(n,dli,dzci,ux,uy,uz,vox,voy,voz)\n !\n ! computes the vorticity field\n !\n implicit none\n integer , intent(in ), dimension(3) :: n\n real(rp), intent(in ), dimension(3) :: dli\n real(rp), intent(in ), dimension(0:) :: dzci\n real(rp), intent(in ), dimension(0:,0:,0:) :: ux ,uy ,uz\n real(rp), intent(out), dimension( :, :, :) :: vox,voy,voz\n real(rp) :: dxi,dyi\n integer :: i,j,k\n dxi = dli(1)\n dyi = dli(2)\n !$OMP PARALLEL DEFAULT(none) &\n !$OMP SHARED(n,dxi,dyi,dzci,ux,uy,uz,vox,voy,voz) &\n !$OMP PRIVATE(i,j,k)\n !$OMP DO\n do k=1,n(3)\n do j=1,n(2)\n do i=1,n(1)\n !\n ! x component of the vorticity at cell center\n !\n vox(i,j,k) = 0.25_rp*( &\n (uz(i,j+1,k )-uz(i,j ,k ))*dyi - (uy(i,j ,k+1)-uy(i,j ,k ))*dzci(k ) + &\n (uz(i,j+1,k-1)-uz(i,j ,k-1))*dyi - (uy(i,j ,k )-uy(i,j ,k-1))*dzci(k-1) + &\n (uz(i,j ,k )-uz(i,j-1,k ))*dyi - (uy(i,j-1,k+1)-uy(i,j-1,k ))*dzci(k ) + &\n (uz(i,j ,k-1)-uz(i,j-1,k-1))*dyi - (uy(i,j-1,k )-uy(i,j-1,k-1))*dzci(k-1) &\n )\n !\n ! y component of the vorticity at cell center\n !\n voy(i,j,k) = 0.25_rp*( &\n (ux(i ,j,k+1)-ux(i ,j,k ))*dzci(k ) - (uz(i+1,j,k )-uz(i ,j,k ))*dxi + &\n (ux(i ,j,k )-ux(i ,j,k-1))*dzci(k-1) - (uz(i+1,j,k-1)-uz(i ,j,k-1))*dxi + &\n (ux(i-1,j,k+1)-ux(i-1,j,k ))*dzci(k ) - (uz(i ,j,k )-uz(i-1,j,k ))*dxi + &\n (ux(i-1,j,k )-ux(i-1,j,k-1))*dzci(k-1) - (uz(i ,j,k-1)-uz(i-1,j,k-1))*dxi &\n )\n !\n ! z component of the vorticity at cell center\n !\n voz(i,j,k) = 0.25_rp*( &\n (uy(i+1,j ,k)-uy(i ,j ,k))*dxi - (ux(i ,j+1,k)-ux(i ,j ,k))*dyi + &\n (uy(i+1,j-1,k)-uy(i ,j-1,k))*dxi - (ux(i ,j ,k)-ux(i ,j-1,k))*dyi + &\n (uy(i ,j ,k)-uy(i-1,j ,k))*dxi - (ux(i-1,j+1,k)-ux(i-1,j ,k))*dyi + &\n (uy(i ,j-1,k)-uy(i-1,j-1,k))*dxi - (ux(i-1,j ,k)-ux(i-1,j-1,k))*dyi &\n )\n end do\n end do\n end do\n !$OMP END PARALLEL\n end subroutine vorticity\n !\n subroutine strain_rate(n,dli,dzci,dzfi,ux,uy,uz,str)\n implicit none\n integer , intent(in ), dimension(3) :: n\n real(rp), intent(in ), dimension(3) :: dli\n real(rp), intent(in ), dimension(0:) :: dzci,dzfi\n real(rp), intent(in ), dimension(0:,0:,0:) :: ux,uy,uz\n real(rp), intent(out), dimension(1:,1:,1:) :: str\n real(rp) :: s11,s22,s33,s12,s13,s23\n real(rp) :: dxi,dyi\n integer :: i,j,k\n dxi = dli(1)\n dyi = dli(2)\n !\n ! compute sijsij, where sij = (1/2)(du_i/dx_j + du_j/dx_i)\n !\n !$OMP PARALLEL DEFAULT(none) &\n !$OMP SHARED(n,dxi,dyi,dzci,dzfi,ux,uy,uz,str) &\n !$OMP PRIVATE(i,j,k,s11,s12,s13,s22,s23,s33)\n !$OMP DO\n do k=1,n(3)\n do j=1,n(2)\n do i=1,n(1)\n s11 = ((ux(i,j,k)-ux(i-1,j,k))*dxi )**2\n s22 = ((uy(i,j,k)-uy(i,j-1,k))*dyi )**2\n s33 = ((uz(i,j,k)-uz(i,j,k-1))*dzfi(k))**2\n s12 = .25_rp*( &\n ((ux(i ,j+1,k)-ux(i ,j ,k))*dyi + (uy(i+1,j ,k)-uy(i ,j ,k))*dxi)**2 + &\n ((ux(i ,j ,k)-ux(i ,j-1,k))*dyi + (uy(i+1,j-1,k)-uy(i ,j-1,k))*dxi)**2 + &\n ((ux(i-1,j+1,k)-ux(i-1,j ,k))*dyi + (uy(i ,j ,k)-uy(i-1,j ,k))*dxi)**2 + &\n ((ux(i-1,j ,k)-ux(i-1,j-1,k))*dyi + (uy(i ,j-1,k)-uy(i-1,j-1,k))*dxi)**2 &\n )*.25_rp\n s13 = .25_rp*( &\n ((ux(i ,j,k+1)-ux(i ,j,k ))*dzci(k ) + (uz(i+1,j,k )-uz(i ,j,k ))*dxi)**2 + &\n ((ux(i ,j,k )-ux(i ,j,k-1))*dzci(k-1) + (uz(i+1,j,k-1)-uz(i ,j,k-1))*dxi)**2 + &\n ((ux(i-1,j,k+1)-ux(i-1,j,k ))*dzci(k ) + (uz(i ,j,k )-uz(i-1,j,k ))*dxi)**2 + &\n ((ux(i-1,j,k )-ux(i-1,j,k-1))*dzci(k-1) + (uz(i ,j,k-1)-uz(i-1,j,k-1))*dxi)**2 &\n )*.25_rp\n s23 = .25_rp*( &\n ((uy(i,j ,k+1)-uy(i,j ,k ))*dzci(k ) + (uz(i,j+1,k )-uz(i,j ,k ))*dyi)**2 + &\n ((uy(i,j ,k )-uy(i,j ,k-1))*dzci(k-1) + (uz(i,j+1,k-1)-uz(i,j ,k-1))*dyi)**2 + &\n ((uy(i,j-1,k+1)-uy(i,j-1,k ))*dzci(k ) + (uz(i,j ,k )-uz(i,j-1,k ))*dyi)**2 + &\n ((uy(i,j-1,k )-uy(i,j-1,k-1))*dzci(k-1) + (uz(i,j ,k-1)-uz(i,j-1,k-1))*dyi)**2 &\n )*.25_rp\n str(i,j,k) = s11+s22+s33 + 2*(s12+s13+s23)\n end do\n end do\n end do\n !$OMP END PARALLEL\n end subroutine strain_rate\n !\n subroutine rotation_rate(n,dli,dzci,ux,uy,uz,ens)\n implicit none\n integer , intent(in ), dimension(3) :: n\n real(rp), intent(in ), dimension(3) :: dli\n real(rp), intent(in ), dimension(0:) :: dzci\n real(rp), intent(in ), dimension(0:,0:,0:) :: ux,uy,uz\n real(rp), intent(out), dimension(1:,1:,1:) :: ens\n real(rp) :: e12,e13,e23\n real(rp) :: dxi,dyi\n integer :: i,j,k\n !\n ! compute wijwij, where wij = (1/2)(du_i/dx_j - du_j/dx_i)\n !\n dxi = dli(1)\n dyi = dli(2)\n !$OMP PARALLEL DEFAULT(none) &\n !$OMP SHARED(n,dxi,dyi,dzci,ux,uy,uz,ens) &\n !$OMP PRIVATE(i,j,k,e12,e13,e23)\n !$OMP DO\n do k=1,n(3)\n do j=1,n(2)\n do i=1,n(1)\n e12 = .25_rp*( &\n ((ux(i ,j+1,k)-ux(i ,j ,k))*dyi - (uy(i+1,j ,k)-uy(i ,j ,k))*dxi)**2 + &\n ((ux(i ,j ,k)-ux(i ,j-1,k))*dyi - (uy(i+1,j-1,k)-uy(i ,j-1,k))*dxi)**2 + &\n ((ux(i-1,j+1,k)-ux(i-1,j ,k))*dyi - (uy(i ,j ,k)-uy(i-1,j ,k))*dxi)**2 + &\n ((ux(i-1,j ,k)-ux(i-1,j-1,k))*dyi - (uy(i ,j-1,k)-uy(i-1,j-1,k))*dxi)**2 &\n )*.25_rp\n e13 = .25_rp*( &\n ((ux(i ,j,k+1)-ux(i ,j,k ))*dzci(k ) - (uz(i+1,j,k )-uz(i ,j,k ))*dxi)**2 + &\n ((ux(i ,j,k )-ux(i ,j,k-1))*dzci(k-1) - (uz(i+1,j,k-1)-uz(i ,j,k-1))*dxi)**2 + &\n ((ux(i-1,j,k+1)-ux(i-1,j,k ))*dzci(k ) - (uz(i ,j,k )-uz(i-1,j,k ))*dxi)**2 + &\n ((ux(i-1,j,k )-ux(i-1,j,k-1))*dzci(k-1) - (uz(i ,j,k-1)-uz(i-1,j,k-1))*dxi)**2 &\n )*.25_rp\n e23 = .25_rp*( &\n ((uy(i,j ,k+1)-uy(i,j ,k ))*dzci(k ) - (uz(i,j+1,k )-uz(i,j ,k ))*dyi)**2 + &\n ((uy(i,j ,k )-uy(i,j ,k-1))*dzci(k-1) - (uz(i,j+1,k-1)-uz(i,j ,k-1))*dyi)**2 + &\n ((uy(i,j-1,k+1)-uy(i,j-1,k ))*dzci(k ) - (uz(i,j ,k )-uz(i,j-1,k ))*dyi)**2 + &\n ((uy(i,j-1,k )-uy(i,j-1,k-1))*dzci(k-1) - (uz(i,j ,k-1)-uz(i,j-1,k-1))*dyi)**2 &\n )*.25_rp\n ens(i,j,k) = 2._rp*(e12+e13+e23)\n end do\n end do\n end do\n !$OMP END PARALLEL\n end subroutine rotation_rate\n !\n subroutine q_criterion(n,ens,str,qcr)\n implicit none\n integer , intent(in ), dimension(3) :: n\n real(rp), intent(in ), dimension(1:,1:,1:) :: ens,str\n real(rp), intent(out), dimension(0:,0:,0:) :: qcr\n integer :: i,j,k\n !$OMP PARALLEL DEFAULT(none) &\n !$OMP SHARED(n,ens,str,qcr) &\n !$OMP PRIVATE(i,j,k)\n !$OMP DO\n do k=1,n(3)\n do j=1,n(2)\n do i=1,n(1)\n qcr(i,j,k) = .5_rp*(ens(i,j,k)-str(i,j,k))\n end do\n end do\n end do\n !$OMP END PARALLEL\n end subroutine q_criterion\nend module mod_post\n", "meta": {"hexsha": "3c37b3117077572aba51d223f17ca88fe16b4223", "size": 8038, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/post.f90", "max_stars_repo_name": "GabrieleBoga/CaNS", "max_stars_repo_head_hexsha": "fd9c56c389640ba9a602fe3cf82be654f5afdf66", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 117, "max_stars_repo_stars_event_min_datetime": "2017-06-26T23:02:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-26T14:39:00.000Z", "max_issues_repo_path": "src/post.f90", "max_issues_repo_name": "GabrieleBoga/CaNS", "max_issues_repo_head_hexsha": "fd9c56c389640ba9a602fe3cf82be654f5afdf66", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 18, "max_issues_repo_issues_event_min_datetime": "2017-07-05T21:32:33.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-05T22:32:09.000Z", "max_forks_repo_path": "src/post.f90", "max_forks_repo_name": "GabrieleBoga/CaNS", "max_forks_repo_head_hexsha": "fd9c56c389640ba9a602fe3cf82be654f5afdf66", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 45, "max_forks_repo_forks_event_min_datetime": "2017-08-09T05:13:51.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-11T20:32:46.000Z", "avg_line_length": 45.1573033708, "max_line_length": 111, "alphanum_fraction": 0.3983578004, "num_tokens": 3194, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.6873497003721627}} {"text": "SUBROUTINE kepler_z2k (r,v,GM , kepler)\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! SUBROUTINE: kepler_z2k.f90\r\n! ----------------------------------------------------------------------\r\n! Purpose:\r\n! Conversion of Position and Velocity vectors cartesian coordinates to \r\n! Keplerian elements [a,e,i,Omega,omega,f,M,E,u]\r\n! ----------------------------------------------------------------------\r\n! Input arguments:\r\n! - r: \t\tposition (m)\r\n! - v: \t\tvelocity (m/sec)\r\n! - GM: \t\tEarth gravity constant, m^3/sec^2\r\n!\r\n! Output arguments:\r\n! - kepler:\tKepler elements\r\n! a: \tsemi-major axis (m)\r\n! e: \teccentricity\r\n! i: \tinclination (degrees)\r\n! Omega: \tright ascension of the ascending node (degrees)\r\n! omega: \targument of perigee (degrees)\r\n! f: \ttrue anomaly (degrees)\r\n! E: \teccentric anomaly (degrees)\r\n! M: \tMean anomaly (degrees)\r\n! u: \targument of latitude (degrees)\r\n! ----------------------------------------------------------------------\r\n! Dr. Thomas Papanikolaou, Geoscience Australia 21 April 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) :: r(3), v(3), GM\r\n! OUT\r\n REAL (KIND = prec_q), INTENT(OUT) :: kepler(9)\r\n! ----------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n! Local variables declaration\r\n! ----------------------------------------------------------------------\r\n REAL (KIND = prec_q) :: X,Y,Z, Vx,Vy,Vz\r\n REAL (KIND = prec_q) :: r_norm, v_norm\r\n REAL (KIND = prec_q) :: rr_dot, vv_dot, rv_dot, rv_norm\r\n REAL (KIND = prec_q) :: h(3), hh_dot, h_norm\r\n REAL (KIND = prec_q) :: W(3), Wx, Wy, Wz, p\r\n REAL (KIND = prec_q) :: i_y, i_x, i_rad\r\n REAL (KIND = prec_q) :: Omega_asc_rad, a, n, e, M_rad \r\n REAL (KIND = prec_q) :: E_y, E_x, E_rad\r\n REAL (KIND = prec_q) :: u_y, u_x, u_rad\r\n REAL (KIND = prec_q) :: f_y, f_x, f_rad\r\n REAL (KIND = prec_q) :: i_deg, Omega_asc_deg, E_deg, M_deg, u_deg, f_deg, omega_per_deg \r\n! ----------------------------------------------------------------------\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! Position vector r = [ X Y Z ]'\r\nX = r(1)\r\nY = r(2)\r\nZ = r(3)\r\n\r\n! Velocity vector v = [ Vx Vy Vz ]'\r\nVx = v(1)\r\nVy = v(2)\r\nVz = v(3)\r\n! ----------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n! r vector magnitude (norm)\r\n CALL productdot(r, r, rr_dot)\r\n r_norm = sqrt(rr_dot)\r\n! v vector magnitude (norm)\r\n CALL productdot(v, v, vv_dot)\r\n v_norm = sqrt(vv_dot)\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! h: angular momentum (areal velocity vector)\r\n!h = [ Y*Vz-Z*Vy\r\n! Z*Vx-X*Vz\r\n! X*Vy-Y*Vx ];\r\n h(1) = Y * Vz - Z * Vy\r\n h(2) = Z * Vx - X * Vz\r\n h(3) = X * Vy - Y * Vx\r\n! ----------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n! W (unit vector of h)\r\n!W = h/sqrt(h'*h);\r\n!Wx = W([1]);\r\n!Wy = W([2]);\r\n!Wz = W([3]);\r\n\r\n! h length (norm)\r\n !h_norm = sqrt(h(1)**2 + h(2)**2 + h(3)**2)\r\n CALL productdot(h, h, hh_dot)\r\n h_norm = sqrt(hh_dot)\r\n\r\n W(1) = h(1) * (1.0D0 / h_norm)\r\n W(2) = h(2) * (1.0D0 / h_norm)\r\n W(3) = h(3) * (1.0D0 / h_norm)\r\n Wx = W(1)\r\n Wy = W(2)\r\n Wz = W(3)\r\n! ----------------------------------------------------------------------\r\n\t \r\n! ----------------------------------------------------------------------\r\n! parameter p: semi-latus rectum\r\n!p = (h'*h)/GM;\r\n p = hh_dot / GM\r\n! ----------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n! i: inclination (in radians)\r\n!i = arctan( sqrt(Wx^2+Wy^2) , Wz );\r\n!i_deg = i * (180/pi);\r\n i_y = sqrt(Wx**2 + Wy**2) \r\n i_x = Wz\r\n CALL arctan ( i_y, i_x , i_rad )\r\n! ----------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n! Omega: the right ascension of the ascending node (in radians)\r\n!Omega = arctan( Wx , -Wy );\r\n!Omega_deg = Omega * (180/pi);\r\n CALL arctan ( Wx, -1.0D0 * Wy , Omega_asc_rad )\r\n! ----------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n! a: semi-major axis\r\n!a = 1/( (2/sqrt(r'*r))-(v'*v)/ GM );\r\n a = 1.0D0 / ( 2.0D0 / r_norm - v_norm**2 / GM )\r\n! ----------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n! n: the mean motion\r\n!n = sqrt( GM /a^3);\r\n n = sqrt(GM / a**3)\r\n! ----------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n! e: the eccentricity\r\n!e = sqrt(1- (p/a) );\r\n e = sqrt(1.0D0 - (p/a) )\r\n! ----------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n! E: the eccentric anomaly (in radians)\r\n!E = arctan( (r'*v)/(a^2*n) , 1-sqrt(r'*r)/a );\r\n!E_deg = E * (180/pi);\r\n CALL productdot(r, v, rv_dot)\r\n rv_norm = sqrt(rv_dot)\r\n E_y = rv_dot / (a**2 * n)\r\n E_x = 1.0D0 - r_norm / a\r\n CALL arctan ( E_y, E_x , E_rad )\r\n! ----------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n! M: Mean anomaly (in radians)\r\n!M = E - e*sin(E);\r\n!% converse in degrees\r\n!M_deg = M * (180/pi);\r\n M_rad = E_rad - e * sin(E_rad)\r\n! ----------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n! u: Argument of latitude (in radians)\r\n!u = arctan( Z , -X*Wy+Y*Wx );\r\n!% converse in degrees\r\n!u_deg = u * (180/pi);\r\n u_y = Z\r\n u_x = -1.0D0 * X * Wy + Y * Wx\r\n CALL arctan ( u_y, u_x , u_rad )\r\n! ----------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n! f : True anomaly (in radians)\r\n!f = arctan( sqrt(1-e^2)*sin(E) , cos(E)-e );\r\n!% converse in degrees\r\n!f_deg = f * (180/pi);\r\n f_y = sqrt(1.0D0 - e**2) * sin(E_rad)\r\n f_x = cos(E_rad) - e\r\n CALL arctan ( f_y, f_x , f_rad )\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! Angular elements: radians to degrees\r\n i_deg = i_rad * (180D0 / PI_global)\r\n Omega_asc_deg = Omega_asc_rad * (180D0 / PI_global)\r\n E_deg = E_rad * (180D0 / PI_global)\r\n M_deg = M_rad * (180D0 / PI_global)\r\n u_deg = u_rad * (180D0 / PI_global)\r\n f_deg = f_rad * (180D0 / PI_global)\r\n! ----------------------------------------------------------------------\r\n\t \r\n! ----------------------------------------------------------------------\r\n! omega : Argument of perigee (degrees)\r\n!omega_deg = u_deg - f_deg;\r\n!if omega_deg < 0\r\n! omega_deg = omega_deg + 360;\r\n!end\r\n\r\n omega_per_deg = u_deg - f_deg\r\n if (omega_per_deg < 0.0D0) then\r\n omega_per_deg = omega_per_deg + 360D0\r\n end if\r\n! ----------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n! Keplerian elements (angular elements in degrees)\r\n! - kepler:\tKepler elements\r\n! a: \tsemi-major axis (m)\r\n! e: \teccentricity\r\n! i: \tinclination\r\n! Omega: \tright ascension of the ascending node\r\n! omega: \targument of perigee\r\n! f: \ttrue anomaly\r\n! E: \teccentric anomaly\r\n! M: \tMean anomaly\r\n! u: \targument of latitude\r\n\r\n! kepler = [a,e,i,Omega,omega,f,M,E,u] \r\n kepler(1) = a\r\n kepler(2) = e\r\n kepler(3) = i_deg\r\n kepler(4) = Omega_asc_deg\r\n kepler(5) = omega_per_deg\r\n kepler(6) = f_deg\r\n kepler(7) = E_deg\r\n kepler(8) = M_deg\r\n kepler(9) = u_deg\r\n! ----------------------------------------------------------------------\r\n\r\n\r\nend\r\n", "meta": {"hexsha": "5fbc5a0e73368b9eb95b59b2a5d507019070d690", "size": 8832, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/kepler_z2k.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_z2k.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_z2k.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.1967213115, "max_line_length": 96, "alphanum_fraction": 0.3336730072, "num_tokens": 2167, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850110816422, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6873451148254112}} {"text": " SUBROUTINE MC03ND( MP, NP, DP, P, LDP1, LDP2, DK, GAM, NULLSP,\n $ LDNULL, KER, LDKER1, LDKER2, TOL, IWORK, DWORK,\n $ LDWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute the coefficients of a minimal polynomial basis\nC DK\nC K(s) = K(0) + K(1) * s + ... + K(DK) * s\nC\nC for the right nullspace of the MP-by-NP polynomial matrix of\nC degree DP, given by\nC DP\nC P(s) = P(0) + P(1) * s + ... + P(DP) * s ,\nC\nC which corresponds to solving the polynomial matrix equation\nC P(s) * K(s) = 0.\nC\nC ARGUMENTS\nC\nC Input/Output Parameters\nC\nC MP (input) INTEGER\nC The number of rows of the polynomial matrix P(s).\nC MP >= 0.\nC\nC NP (input) INTEGER\nC The number of columns of the polynomial matrix P(s).\nC NP >= 0.\nC\nC DP (input) INTEGER\nC The degree of the polynomial matrix P(s). DP >= 1.\nC\nC P (input) DOUBLE PRECISION array, dimension (LDP1,LDP2,DP+1)\nC The leading MP-by-NP-by-(DP+1) part of this array must\nC contain the coefficients of the polynomial matrix P(s).\nC Specifically, P(i,j,k) must contain the (i,j)-th element\nC of P(k-1), which is the cofficient of s**(k-1) of P(s),\nC where i = 1,2,...,MP, j = 1,2,...,NP and k = 1,2,...,DP+1.\nC\nC LDP1 INTEGER\nC The leading dimension of array P. LDP1 >= MAX(1,MP).\nC\nC LDP2 INTEGER\nC The second dimension of array P. LDP2 >= MAX(1,NP).\nC\nC DK (output) INTEGER\nC The degree of the minimal polynomial basis K(s) for the\nC right nullspace of P(s) unless DK = -1, in which case\nC there is no right nullspace.\nC\nC GAM (output) INTEGER array, dimension (DP*MP+1)\nC The leading (DK+1) elements of this array contain\nC information about the ordering of the right nullspace\nC vectors stored in array NULLSP.\nC\nC NULLSP (output) DOUBLE PRECISION array, dimension\nC (LDNULL,(DP*MP+1)*NP)\nC The leading NP-by-SUM(i*GAM(i)) part of this array\nC contains the right nullspace vectors of P(s) in condensed\nC form (as defined in METHOD), where i = 1,2,...,DK+1.\nC\nC LDNULL INTEGER\nC The leading dimension of array NULLSP.\nC LDNULL >= MAX(1,NP).\nC\nC KER (output) DOUBLE PRECISION array, dimension\nC (LDKER1,LDKER2,DP*MP+1)\nC The leading NP-by-nk-by-(DK+1) part of this array contains\nC the coefficients of the minimal polynomial basis K(s),\nC where nk = SUM(GAM(i)) and i = 1,2,...,DK+1. Specifically,\nC KER(i,j,m) contains the (i,j)-th element of K(m-1), which\nC is the coefficient of s**(m-1) of K(s), where i = 1,2,...,\nC NP, j = 1,2,...,nk and m = 1,2,...,DK+1.\nC\nC LDKER1 INTEGER\nC The leading dimension of array KER. LDKER1 >= MAX(1,NP).\nC\nC LDKER2 INTEGER\nC The second dimension of array KER. LDKER2 >= MAX(1,NP).\nC\nC Tolerances\nC\nC TOL DOUBLE PRECISION\nC A tolerance below which matrix elements are considered\nC to be zero. If the user sets TOL to be less than\nC 10 * EPS * MAX( ||A|| , ||E|| ), then the tolerance is\nC F F\nC taken as 10 * EPS * MAX( ||A|| , ||E|| ), where EPS is the\nC F F\nC machine precision (see LAPACK Library Routine DLAMCH) and\nC A and E are matrices (as defined in METHOD).\nC\nC Workspace\nC\nC IWORK INTEGER array, dimension (m+2*MAX(n,m+1)+n),\nC where m = DP*MP and n = (DP-1)*MP + NP.\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC\nC LDWORK The length of the array DWORK.\nC LDWORK >= m*n*n + 2*m*n + 2*n*n.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value.\nC > 0: if incorrect rank decisions were taken during the\nC computations. This failure is not likely to occur.\nC The possible values are:\nC k, 1 <= k <= DK+1, the k-th diagonal submatrix had\nC not a full row rank;\nC DK+2, if incorrect dimensions of a full column\nC rank submatrix;\nC DK+3, if incorrect dimensions of a full row rank\nC submatrix.\nC\nC METHOD\nC\nC The computation of the right nullspace of the MP-by-NP polynomial\nC matrix P(s) of degree DP given by\nC DP-1 DP\nC P(s) = P(0) + P(1) * s + ... + P(DP-1) * s + P(DP) * s\nC\nC is performed via the pencil s*E - A, associated with P(s), where\nC\nC | I | | 0 -P(DP) |\nC | . | | I . . |\nC A = | . | and E = | . . . |. (1)\nC | . | | . 0 . |\nC | I | | I 0 -P(2) |\nC | P(0) | | I -P(1) |\nC\nC The pencil s*E - A is transformed by unitary matrices Q and Z such\nC that\nC\nC | sE(eps)-A(eps) | X | X |\nC |----------------|----------------|------------|\nC | 0 | sE(inf)-A(inf) | X |\nC Q'(s*E-A)Z = |=================================|============|.\nC | | |\nC | 0 | sE(r)-A(r) |\nC\nC Since s*E(inf)-A(inf) and s*E(r)-A(r) have full column rank, the\nC minimal polynomial basis for the right nullspace of Q'(s*E-A)Z\nC (and consequently the basis for the right nullspace of s*E - A) is\nC completely determined by s*E(eps)-A(eps).\nC\nC Let Veps(s) be a minimal polynomial basis for the right nullspace\nC of s*E(eps)-A(eps). Then\nC\nC | Veps(s) |\nC V(s) = Z * |---------|\nC | 0 |\nC\nC is a minimal polynomial basis for the right nullspace of s*E - A.\nC From the structure of s*E - A it can be shown that if V(s) is\nC partitioned as\nC\nC | Vo(s) | (DP-1)*MP\nC V(s) = |------ |\nC | Ve(s) | NP\nC\nC then the columns of Ve(s) form a minimal polynomial basis for the\nC right nullspace of P(s).\nC\nC The vectors of Ve(s) are computed and stored in array NULLSP in\nC the following condensed form:\nC\nC || || | || | | || | |\nC || U1,0 || U2,0 | U2,1 || U3,0 | U3,1 | U3,2 || U4,0 | ... |,\nC || || | || | | || | |\nC\nC where Ui,j is an NP-by-GAM(i) matrix which contains the i-th block\nC of columns of K(j), the j-th coefficient of the polynomial matrix\nC representation for the right nullspace\nC DK\nC K(s) = K(0) + K(1) * s + . . . + K(DK) * s .\nC\nC The coefficients K(0), K(1), ..., K(DK) are NP-by-nk matrices\nC given by\nC\nC K(0) = | U1,0 | U2,0 | U3,0 | . . . | U(DK+1,0) |\nC\nC K(1) = | 0 | U2,1 | U3,1 | . . . | U(DK+1,1) |\nC\nC K(2) = | 0 | 0 | U3,2 | . . . | U(DK+1,2) |\nC\nC . . . . . . . . . .\nC\nC K(DK) = | 0 | 0 | 0 | . . . | 0 | U(DK+1,DK)|.\nC\nC Note that the degree of K(s) satisfies the inequality DK <=\nC DP * MIN(MP,NP) and that the dimension of K(s) satisfies the\nC inequality (NP-MP) <= nk <= NP.\nC\nC REFERENCES\nC\nC [1] Beelen, Th.G.J.\nC New Algorithms for Computing the Kronecker structure of a\nC Pencil with Applications to Systems and Control Theory.\nC Ph.D.Thesis, Eindhoven University of Technology, 1987.\nC\nC [2] Van Den Hurk, G.J.H.H.\nC New Algorithms for Solving Polynomial Matrix Problems.\nC Master's Thesis, Eindhoven University of Technology, 1987.\nC\nC NUMERICAL ASPECTS\nC\nC The algorithm used by the routine involves the construction of a\nC special block echelon form with pivots considered to be non-zero\nC when they are larger than TOL. These pivots are then inverted in\nC order to construct the columns of the kernel of the polynomial\nC matrix. If TOL is chosen to be too small then these inversions may\nC be sensitive whereas increasing TOL will make the inversions more\nC robust but will affect the block echelon form (and hence the\nC column degrees of the polynomial kernel). Furthermore, if the\nC elements of the computed polynomial kernel are large relative to\nC the polynomial matrix, then the user should consider trying\nC several values of TOL.\nC\nC FURTHER COMMENTS\nC\nC It also possible to compute a minimal polynomial basis for the\nC right nullspace of a pencil, since a pencil is a polynomial matrix\nC of degree 1. Thus for the pencil (s*E - A), the required input is\nC P(1) = E and P(0) = -A.\nC\nC The routine can also be used to compute a minimal polynomial\nC basis for the left nullspace of a polynomial matrix by simply\nC transposing P(s).\nC\nC CONTRIBUTOR\nC\nC Release 3.0: V. Sima, Katholieke Univ. Leuven, Belgium, Mar. 1997.\nC Supersedes Release 2.0 routine MC03BD by A.J. Geurts and MC03BZ by\nC Th.G.J. Beelen, A.J. Geurts, and G.J.H.H. van den Hurk.\nC\nC REVISIONS\nC\nC Jan. 1998.\nC\nC KEYWORDS\nC\nC Echelon form, elementary polynomial operations, input output\nC description, polynomial matrix, polynomial operations.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, ONE, TEN\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0, TEN = 10.0D0 )\nC .. Scalar Arguments ..\n INTEGER DK, DP, INFO, LDKER1, LDKER2, LDNULL, LDP1,\n $ LDP2, LDWORK, MP, NP\n DOUBLE PRECISION TOL\nC .. Array Arguments ..\n INTEGER GAM(*), IWORK(*)\n DOUBLE PRECISION DWORK(*), KER(LDKER1,LDKER2,*),\n $ NULLSP(LDNULL,*), P(LDP1,LDP2,*)\nC .. Local Scalars ..\n INTEGER GAMJ, H, I, IDIFF, IFIR, J, JWORKA, JWORKE,\n $ JWORKQ, JWORKV, JWORKZ, K, M, MUK, N, NBLCKS,\n $ NBLCKI, NCA, NCV, NRA, NUK, RANKE, SGAMK, TAIL,\n $ VC1, VR2\n DOUBLE PRECISION TOLER\nC .. Local Arrays ..\n INTEGER MNEI(3)\nC .. External Functions ..\n DOUBLE PRECISION DLAMCH, DLANGE, DLAPY2\n EXTERNAL DLAMCH, DLANGE, DLAPY2\nC .. External Subroutines ..\n EXTERNAL DGEMM, DLACPY, DLASET, MB04UD, MB04VD, MC03NX,\n $ MC03NY, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC DBLE, MAX, SQRT\nC .. Executable Statements ..\nC\nC Test the input scalar arguments.\nC\n M = DP*MP\n H = M - MP\n N = H + NP\n INFO = 0\n IF( MP.LT.0 ) THEN\n INFO = -1\n ELSE IF( NP.LT.0 ) THEN\n INFO = -2\n ELSE IF( DP.LE.0 ) THEN\n INFO = -3\n ELSE IF( LDP1.LT.MAX( 1, MP ) ) THEN\n INFO = -5\n ELSE IF( LDP2.LT.MAX( 1, NP ) ) THEN\n INFO = -6\n ELSE IF( LDNULL.LT.MAX( 1, NP ) ) THEN\n INFO = -10\n ELSE IF( LDKER1.LT.MAX( 1, NP ) ) THEN\n INFO = -12\n ELSE IF( LDKER2.LT.MAX( 1, NP ) ) THEN\n INFO = -13\n ELSE IF( LDWORK.LT.( N*( M*N + 2*( M + N ) ) ) ) THEN\n INFO = -17\n END IF\nC\n IF ( INFO.NE.0 ) THEN\nC\nC Error return.\nC\n CALL XERBLA( 'MC03ND', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF ( MP.EQ.0 .OR. NP.EQ.0 ) THEN\n DK = -1\n RETURN\n END IF\nC\n JWORKA = 1\n JWORKE = JWORKA + M*N\n JWORKZ = JWORKE + M*N\n JWORKV = JWORKZ + N*N\n JWORKQ = JWORKA\nC\nC Construct the matrices A and E in the pencil s*E-A in (1).\nC Workspace: 2*M*N.\nC\n CALL MC03NX( MP, NP, DP, P, LDP1, LDP2, DWORK(JWORKA), M,\n $ DWORK(JWORKE), M )\nC\nC Computation of the tolerance.\nC\n TOLER = MAX( DLANGE( 'F', M, NP, DWORK(JWORKE+H*M), M, DWORK ),\n $ DLANGE( 'F', MP, NP, P, LDP1, DWORK ) )\n TOLER = TEN*DLAMCH( 'Epsilon' )\n $ *DLAPY2( TOLER, SQRT( DBLE( H ) ) )\n IF ( TOLER.LE.TOL ) TOLER = TOL\nC\nC Reduction of E to column echelon form E0 = Q' x E x Z and\nC transformation of A, A0 = Q' x A x Z.\nC Workspace: 2*M*N + N*N + max(M,N).\nC\n CALL MB04UD( 'No Q', 'Identity Z', M, N, DWORK(JWORKA), M,\n $ DWORK(JWORKE), M, DWORK(JWORKQ), M, DWORK(JWORKZ), N,\n $ RANKE, IWORK, TOLER, DWORK(JWORKV), INFO )\nC\nC The contents of ISTAIR is transferred from MB04UD to MB04VD by\nC IWORK(i), i=1,...,M.\nC In the sequel the arrays IMUK and INUK are part of IWORK, namely:\nC IWORK(i), i = M+1,...,M+max(N,M+1), contains IMUK,\nC IWORK(i), i = M+max(N,M+1)+1,...,M+2*max(N,M+1), contains INUK.\nC IWORK(i), i = M+2*max(N,M+1)+1,...,M+2*max(N,M+1)+N, contains\nC IMUK0 (not needed), and is also used as workspace.\nC\n MUK = M + 1\n NUK = MUK + MAX( N, M+1 )\n TAIL = NUK + MAX( N, M+1 )\nC\n CALL MB04VD( 'Separation', 'No Q', 'Update Z', M, N, RANKE,\n $ DWORK(JWORKA), M, DWORK(JWORKE), M, DWORK(JWORKQ), M,\n $ DWORK(JWORKZ), N, IWORK, NBLCKS, NBLCKI, IWORK(MUK),\n $ IWORK(NUK), IWORK(TAIL), MNEI, TOLER, IWORK(TAIL),\n $ INFO )\n IF ( INFO.GT.0 ) THEN\nC\nC Incorrect rank decisions.\nC\n INFO = INFO + NBLCKS\n RETURN\n END IF\nC\nC If NBLCKS < 1, or the column dimension of s*E(eps) - A(eps) is\nC zero, then there is no right nullspace.\nC\n IF ( NBLCKS.LT.1 .OR. MNEI(2).EQ.0 ) THEN\n DK = -1\n RETURN\n END IF\nC\nC Start of the computation of the minimal basis.\nC\n DK = NBLCKS - 1\n NRA = MNEI(1)\n NCA = MNEI(2)\nC\nC Determine a minimal basis VEPS(s) for the right nullspace of the\nC pencil s*E(eps)-A(eps) associated with the polynomial matrix P(s).\nC Workspace: 2*M*N + N*N + N*N*(M+1).\nC\n CALL MC03NY( NBLCKS, NRA, NCA, DWORK(JWORKA), M, DWORK(JWORKE), M,\n $ IWORK(MUK), IWORK(NUK), DWORK(JWORKV), N, INFO )\nC\n IF ( INFO.GT.0 )\n $ RETURN\nC\n NCV = IWORK(MUK) - IWORK(NUK)\n GAM(1) = NCV\n IWORK(1) = 0\n IWORK(TAIL) = IWORK(MUK)\nC\n DO 20 I = 2, NBLCKS\n IDIFF = IWORK(MUK+I-1) - IWORK(NUK+I-1)\n GAM(I) = IDIFF\n IWORK(I) = NCV\n NCV = NCV + I*IDIFF\n IWORK(TAIL+I-1) = IWORK(TAIL+I-2) + IWORK(MUK+I-1)\n 20 CONTINUE\nC\nC Determine a basis for the right nullspace of the polynomial\nC matrix P(s). This basis is stored in array NULLSP in condensed\nC form.\nC\n CALL DLASET( 'Full', NP, NCV, ZERO, ZERO, NULLSP, LDNULL )\nC\nC |VEPS(s)|\nC The last NP rows of the product matrix Z x |-------| contain the\nC | 0 |\nC polynomial basis for the right nullspace of the polynomial matrix\nC P(s) in condensed form. The multiplication is restricted to the\nC nonzero submatrices Vij,k of VEPS, the result is stored in the\nC array NULLSP.\nC\n VC1 = 1\nC\n DO 60 I = 1, NBLCKS\n VR2 = IWORK(TAIL+I-1)\nC\n DO 40 J = 1, I\nC\nC Multiplication of Z(H+1:N,1:VR2) with V.i,j-1 stored in\nC VEPS(1:VR2,VC1:VC1+GAM(I)-1).\nC\n CALL DGEMM( 'No transpose', 'No transpose', NP, GAM(I), VR2,\n $ ONE, DWORK(JWORKZ+H), N,\n $ DWORK(JWORKV+(VC1-1)*N), N, ZERO, NULLSP(1,VC1),\n $ LDNULL )\n VC1 = VC1 + GAM(I)\n VR2 = VR2 - IWORK(MUK+I-J)\n 40 CONTINUE\nC\n 60 CONTINUE\nC\nC Transfer of the columns of NULLSP to KER in order to obtain the\nC polynomial matrix representation of K(s), the right nullspace\nC of P(s).\nC\n SGAMK = 1\nC\n DO 100 K = 1, NBLCKS\n CALL DLASET( 'Full', NP, SGAMK-1, ZERO, ZERO, KER(1,1,K),\n $ LDKER1 )\n IFIR = SGAMK\nC\nC Copy the appropriate columns of NULLSP into KER(k).\nC SGAMK = 1 + SUM(i=1,..,k-1) GAM(i), is the first nontrivial\nC column of KER(k), the first SGAMK - 1 columns of KER(k) are\nC zero. IFIR denotes the position of the first column in KER(k)\nC in the set of columns copied for a value of J.\nC VC1 is the first column of NULLSP to be copied.\nC\n DO 80 J = K, NBLCKS\n GAMJ = GAM(J)\n VC1 = IWORK(J) + (K-1)*GAMJ + 1\n CALL DLACPY( 'Full', NP, GAMJ, NULLSP(1,VC1), LDNULL,\n $ KER(1,IFIR,K), LDKER1 )\n IFIR = IFIR + GAMJ\n 80 CONTINUE\nC\n SGAMK = SGAMK + GAM(K)\n 100 CONTINUE\nC\n RETURN\nC *** Last line of MC03ND ***\n END\n", "meta": {"hexsha": "e85291c0b1b2f9b078d18d503cbb7a4079587b62", "size": 17607, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MC03ND.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MC03ND.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MC03ND.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 36.5290456432, "max_line_length": 72, "alphanum_fraction": 0.5126370194, "num_tokens": 5635, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9362850093037731, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.687345102627396}} {"text": "\tFUNCTION PS_STAP ( datain, nparm, clev, ivcord )\nC************************************************************************\nC* PS_STAP\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes the stability as the negative of the\t\t*\nC* potential temperature vertical gradient with respect to pressure.\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PS_STAP ( DATAIN, NPARM, CLEV, IVCORD )\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tDATAIN\t\tREAL\t\tStation data\t\t\t*\nC*\tNPARM\t\tINTEGER\t\tNumber of data set parameters\t*\nC*\tCLEV\t\tREAL\t\tVertical level\t\t\t*\nC*\tIVCORD\t\tINTEGER \tVertical coordinate number\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPS_STAP\t\tREAL\t\tStability ( - d THETA / dp)\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* J. Nielsen/SUNYA\t 8/90\t\t\t\t\t\t*\nC* T. Lee/GSC\t\t 8/97\tChanged default depth to RMISSD\t\t*\nC************************************************************************\n\tINCLUDE\t\t'GEMPRM.PRM'\nC*\n\tREAL\t\tstndl (10), stndb (10), stndt (10)\nC*\n\tINCLUDE\t\t'ERMISS.FNC'\nC-----------------------------------------------------------------------------\n\tPS_STAP = RMISSD\nC\nC*\tGet the depth.\nC\n\tdfdpth = RMISSD\n\tidfcrd = 1\n\tCALL PC_DPTH ( datain, nparm, clev, ivcord, dfdpth, idfcrd, 1,\n +\t\t\tdepth, idcord, stndl, stndb, stndt, ier )\nC\nC*\tCheck for missing data.\nC\n\tIF ( ( ier .ne. 0 ) .or. ERMISS ( stndt (2) ) .or.\n +\t ERMISS ( stndb (2) ) ) RETURN\n\tdeltap = stndt (1) - stndb (1)\n\tIF ( deltap .eq. 0.0 ) RETURN\nC*\n\tthtop = PR_THTA ( stndt (2), stndt (1) )\n\tthbot = PR_THTA ( stndb (2), stndb (1) )\n\n\tPS_STAP = - (( thtop - thbot ) / ( deltap * 100.0 ))\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "dfe57e179d973446b22c444879dc5d9e4327390b", "size": 1566, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/ps/psstap.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/ps/psstap.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/ps/psstap.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.1153846154, "max_line_length": 78, "alphanum_fraction": 0.5108556833, "num_tokens": 560, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362849986365572, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.687345100242808}} {"text": "* This file contains the following subroutines, related to the\n* spherical geometry of the Earth's atmosphere\n* sphers\n* airmas\n*=============================================================================*\n\n SUBROUTINE sphers(nz, z, zen, dsdh, nid)\n\n*-----------------------------------------------------------------------------*\n*= PURPOSE: =*\n*= Calculate slant path over vertical depth ds/dh in spherical geometry. =*\n*= Calculation is based on: A.Dahlback, and K.Stamnes, A new spheric model =*\n*= for computing the radiation field available for photolysis and heating =*\n*= at twilight, Planet.Space Sci., v39, n5, pp. 671-683, 1991 (Appendix B) =*\n*-----------------------------------------------------------------------------*\n*= PARAMETERS: =*\n*= NZ - INTEGER, number of specified altitude levels in the working (I)=*\n*= grid =*\n*= Z - REAL, specified altitude working grid (km) (I)=*\n*= ZEN - REAL, solar zenith angle (degrees) (I)=*\n*= DSDH - REAL, slant path of direct beam through each layer crossed (O)=*\n*= when travelling from the top of the atmosphere to layer i; =*\n*= DSDH(i,j), i = 0..NZ-1, j = 1..NZ-1 =*\n*= NID - INTEGER, number of layers crossed by the direct beam when (O)=*\n*= travelling from the top of the atmosphere to layer i; =*\n*= NID(i), i = 0..NZ-1 =*\n*-----------------------------------------------------------------------------*\n*= EDIT HISTORY: =*\n*= double precision fix for shallow layers - Julia Lee-Taylor Dec 2000 =*\n*-----------------------------------------------------------------------------*\n*= This program is free software; you can redistribute it and/or modify =*\n*= it under the terms of the GNU General Public License as published by the =*\n*= Free Software Foundation; either version 2 of the license, or (at your =*\n*= option) any later version. =*\n*= The TUV package is distributed in the hope that it will be useful, but =*\n*= WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBI- =*\n*= LITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public =*\n*= License for more details. =*\n*= To obtain a copy of the GNU General Public License, write to: =*\n*= Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. =*\n*-----------------------------------------------------------------------------*\n*= To contact the authors, please mail to: =*\n*= Sasha Madronich, NCAR/ACD, P.O.Box 3000, Boulder, CO, 80307-3000, USA or =*\n*= send email to: sasha@ucar.edu =*\n*-----------------------------------------------------------------------------*\n\n IMPLICIT NONE\n INCLUDE 'params'\n\n* input\n INTEGER nz\n REAL zen, z(kz)\n\n* output\n INTEGER nid(0:kz)\n REAL dsdh(0:kz,kz)\n\n* more program constants\n REAL re, ze(kz)\n REAL dr\n PARAMETER ( dr = pi/180.)\n\n* local \n\n DOUBLE PRECISION zenrad, rpsinz, rj, rjp1, dsj, dhj, ga, gb, sm\n INTEGER i, j, k\n INTEGER id\n\n INTEGER nlayer\n REAL zd(0:kz-1)\n\n*-----------------------------------------------------------------------------\n\n zenrad = zen*dr\n\n* number of layers:\n nlayer = nz - 1\n\n* include the elevation above sea level to the radius of the earth:\n re = radius + z(1)\n* correspondingly z changed to the elevation above earth surface:\n DO k = 1, nz\n ze(k) = z(k) - z(1)\n END DO\n\n* inverse coordinate of z\n zd(0) = ze(nz)\n DO k = 1, nlayer\n zd(k) = ze(nz - k)\n END DO\n\n* initialize dsdh(i,j), nid(i)\n DO i = 0, kz\n nid(i) = 0\n DO j = 1, kz\n dsdh(i,j) = 0.\n END DO\n END DO\n\n* calculate ds/dh of every layer\n DO 100 i = 0, nlayer\n\n rpsinz = (re + zd(i)) * SIN(zenrad)\n \n IF ( (zen .GT. 90.0) .AND. (rpsinz .LT. re) ) THEN\n nid(i) = -1\n ELSE\n\n*\n* Find index of layer in which the screening height lies\n*\n id = i \n IF( zen .GT. 90.0 ) THEN\n DO 10 j = 1, nlayer\n IF( (rpsinz .LT. ( zd(j-1) + re ) ) .AND.\n $ (rpsinz .GE. ( zd(j) + re )) ) id = j\n 10 CONTINUE\n END IF\n \n DO 20 j = 1, id\n\n sm = 1.0\n IF(j .EQ. id .AND. id .EQ. i .AND. zen .GT. 90.0)\n $ sm = -1.0\n \n rj = re + zd(j-1)\n rjp1 = re + zd(j)\n \n dhj = zd(j-1) - zd(j)\n \n ga = rj*rj - rpsinz*rpsinz\n gb = rjp1*rjp1 - rpsinz*rpsinz\n IF (ga .LT. 0.0) ga = 0.0\n IF (gb .LT. 0.0) gb = 0.0\n \n IF(id.GT.i .AND. j.EQ.id) THEN\n dsj = SQRT( ga )\n ELSE\n dsj = SQRT( ga ) - sm*SQRT( gb )\n END IF\n dsdh(i,j) = dsj / dhj\n 20 CONTINUE\n \n nid(i) = id\n \n END IF\n\n 100 CONTINUE\n\n*-----------------------------------------------------------------------------\n\n RETURN\n END\n\n*=============================================================================*\n\n SUBROUTINE airmas(nz, dsdh, nid, cz,\n $ vcol, scol)\n\n*-----------------------------------------------------------------------------*\n*= PURPOSE: =*\n*= Calculate vertical and slant air columns, in spherical geometry, as a =*\n*= function of altitude. =*\n*-----------------------------------------------------------------------------*\n*= PARAMETERS: =*\n*= NZ - INTEGER, number of specified altitude levels in the working (I)=*\n*= grid =*\n*= DSDH - REAL, slant path of direct beam through each layer crossed (O)=*\n*= when travelling from the top of the atmosphere to layer i; =*\n*= DSDH(i,j), i = 0..NZ-1, j = 1..NZ-1 =*\n*= NID - INTEGER, number of layers crossed by the direct beam when (O)=*\n*= travelling from the top of the atmosphere to layer i; =*\n*= NID(i), i = 0..NZ-1 =*\n*= VCOL - REAL, output, vertical air column, molec cm-2, above level iz =*\n*= SCOL - REAL, output, slant air column in direction of sun, above iz =*\n*= also in molec cm-2 =*\n*-----------------------------------------------------------------------------*\n\n IMPLICIT NONE\n INCLUDE 'params'\n\n* Input:\n\n INTEGER nz\n INTEGER nid(0:kz)\n REAL dsdh(0:kz,kz)\n REAL cz(kz)\n\n* output: \n\n REAL vcol(kz), scol(kz)\n\n* internal:\n\n INTEGER id, j\n REAL sum, vsum\n\n* calculate vertical and slant column from each level:\n* work downward\n\n vsum = 0.\n DO id = 0, nz - 1\n vsum = vsum + cz(nz-id)\n vcol(nz-id) = vsum\n sum = 0.\n IF(nid(id) .LT. 0) THEN\n sum = largest\n ELSE\n\n* single pass layers:\n\n DO j = 1, MIN(nid(id), id)\n sum = sum + cz(nz-j)*dsdh(id,j)\n ENDDO\n\n* double pass layers:\n\n DO j = MIN(nid(id),id)+1, nid(id)\n sum = sum + 2.*cz(nz-j)*dsdh(id,j)\n ENDDO\n\n ENDIF\n scol(nz - id) = sum\n\n ENDDO\n\n RETURN\n END\n\n\n\n\n", "meta": {"hexsha": "5da0c3d0b80e582523315f596d7e850252d6085a", "size": 7998, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "V5.4/sphers.f", "max_stars_repo_name": "SeregaOsipov/TUV", "max_stars_repo_head_hexsha": "fdf9945d6a1e38805c7e687fc55b6888bf426b2e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-02-27T11:21:59.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-26T10:04:41.000Z", "max_issues_repo_path": "V5.4/sphers.f", "max_issues_repo_name": "SeregaOsipov/TUV", "max_issues_repo_head_hexsha": "fdf9945d6a1e38805c7e687fc55b6888bf426b2e", "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": "V5.4/sphers.f", "max_forks_repo_name": "SeregaOsipov/TUV", "max_forks_repo_head_hexsha": "fdf9945d6a1e38805c7e687fc55b6888bf426b2e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-02-27T11:51:33.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-27T11:51:33.000Z", "avg_line_length": 34.3261802575, "max_line_length": 79, "alphanum_fraction": 0.4054763691, "num_tokens": 1955, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545377452442, "lm_q2_score": 0.7248702702332475, "lm_q1q2_score": 0.687289035998275}} {"text": "\n subroutine cross_section_Rayleigh( &\n nsmax, wavelength_ns, relN2, &\n relO2, relAr, eps_N2, & \n eps_O2, eps_Ar, csray_N2, &\n csray_O2, csray_Ar)\n\n!-----------------------------------------------------------\n! Subroutine:\n! csray\n! \n! Purpose:\n! Calculate Rayleigh cross section for \n! N2, O2, Ar, and air\n!------------------------------------------------------------------\n\n implicit none\n\n integer,parameter::dp=selected_real_kind(8) !double precision\n \n! nr of wavelengths\n integer,intent(in):: &\n nsmax\n! wavelengths around incident light (ns_elas) [nm]\n real(kind=dp):: &\n wavelength_ns(0:nsmax) \n\n real(kind=dp),intent(in):: & \n relN2, & !N2 volume mixing ratio\n relO2, & !O2 volume mixing ratio\n relAr !Ar volume mixing ratio\n\n real(kind=dp),dimension(0:nsmax):: &\n rn_N2, & !refraction index of N2\n rn_O2, & !refraction index of O2\n rn_Ar !refraction index of Ar\n\n real(kind=dp):: &\n Wcm, & !wavelengthlength [cm]\n WNmu, & !1/wavelengthlength [um-1]\n frac_rn_N2, &\n frac_rn_O2, &\n frac_rn_Ar, &\n rn_N2m1, & \n rn_O2m1, &\n rn_Arm1, &\n fk_N2, & !King factor\n fk_O2, &\n fk_Ar, &\n dens\n\n! parametrization of refraction index of N2 and O2 ( Bates 1984 )\n real(kind=dp):: &\n a_N2(3), &\n b_N2(3), & \n a_O2(4), &\n b_O2(4)\n data &\n a_N2 / 6855.200d0, 5989.242d0, 6998.749d0 /, &\n b_N2 / 3243157.0d0, 3363266.3d0, 3233582.0d0 /, &\n a_O2 / 21351.1d0, 20564.8d0, 22120.4d0, 23796.7d0 /, &\n b_O2 / 218567.0d0, 248089.9d0, 203187.6d0, 168988.4d0 / \n \n real(kind=dp),parameter:: & \n pi = 3.141592653589793115997963468544d0, &\n temp_std = 273.15d0, & !standard temperature [K]\n Dair = 2.54743D+19 !molar nrdensity air [part. cm-3]\n\n integer::ni\n\n real(kind=dp),dimension(0:nsmax):: &\n csray_air !Rayleigh cross sections for air\n\n real(kind=dp),dimension(0:nsmax),intent(out):: &\n eps_N2, & !epsilon for N2 \n eps_O2, & !epsilon for O2\n eps_AR, & !epsilon for Ar = 0\n csray_O2, & !Rayleigh cross sections for O2 molecules\n csray_N2, & !Rayleigh cross sections for N2 molecules\n csray_Ar !Rayleigh cross sections for Ar atoms\n\n integer::ns\n\n do ns=0,nsmax\n\n WNmu = (1.d+07/wavelength_ns(ns)) * 1.d-4\n\n! King correction factor\n fk_N2 = 1.034d0 + 3.17d-4 * WNmu**2\n fk_O2 = 1.096d0 + 1.385d-03*WNmu**2 + 1.448d-4*WNmu**4\n fk_Ar = 1.d0\n\n! anisotropic polarizability factor eps\n eps_N2(ns) = 9.d0/2.d0 * (fk_N2-1.d0)\n eps_O2(ns) = 9.d0/2.d0 * (fk_O2-1.d0)\n eps_Ar(ns) = 0.d0\n\n! refraction index of N2 (n(N2)-1) [Bates1984]\n ni = 1 \n if(wavelength_ns(ns).lT.468.d0) ni = 2 \n if(wavelength_ns(ns).lT.254.d0) ni = 3 \n rn_N2m1 = (a_N2(ni) + b_N2(ni)/(144.d0-WNmu**2))*1.d-08\n rn_N2(ns) = 1.d0 + rn_N2m1\n \n! refraction index of O2 (n(O2)-1) [Bates1984]\n ni = 1\n if(wavelength_ns(ns).lT.546.d0) ni = 2 \n if(wavelength_ns(ns).lT.288.d0) ni = 3 \n if(wavelength_ns(ns).lT.221.d0) ni = 4 \n rn_O2m1 = (a_O2(ni) + b_O2(ni)/(40.90d0-WNmu**2))*1.d-08\n rn_O2(ns) = 1.d0 + rn_O2m1\n \n! refraction index of Ar (n(Ar)-1) [Peck and Fisher1964]\n rn_Arm1 = (678.6711d0 + 301829.43d0/(144.d0-WNmu**2))*1.d-07\n rn_Ar(ns) = 1.d0 + rn_Arm1\n\n! (n**2-1)/(n**2+2)\n frac_rn_N2 = (rn_N2(ns)**2-1.d0)**2/(rn_N2(ns)**2+2.d0)**2\n frac_rn_O2 = (rn_O2(ns)**2-1.d0)**2/(rn_O2(ns)**2+2.d0)**2\n frac_rn_Ar = (rn_Ar(ns)**2-1.d0)**2/(rn_Ar(ns)**2+2.d0)**2\n \n! Dair is given for 15 degree Celius\n! scale to standard temp T = 273.15 K because of refractive index\n\n dens = (288.16d0/temp_std) * Dair\n\n Wcm = wavelength_ns(ns) * 1.d-7 !change units nm -> cm\n\n csray_N2(ns) = 24.d0*pi**3/(Wcm**4*dens**2)*frac_rn_N2*fk_N2\n csray_O2(ns) = 24.d0*pi**3/(Wcm**4*dens**2)*frac_rn_O2*fk_O2\n csray_Ar(ns) = 24.d0*pi**3/(Wcm**4*dens**2)*frac_rn_Ar*fk_Ar\n \n csray_air(ns) = relN2 * csray_N2(ns) + &\n relO2 * csray_O2(ns) + &\n relAr * csray_Ar(ns) \n\n enddo\n\n return\n\nend subroutine cross_section_Rayleigh\n", "meta": {"hexsha": "1c1eba974acebca7b881c2bdedb6bc68ab937c71", "size": 4316, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/csray.f90", "max_stars_repo_name": "rutgervandeelen/das", "max_stars_repo_head_hexsha": "4727a8daaf87c817fb49fbe6ce8eaa996210e7dc", "max_stars_repo_licenses": ["MIT"], "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/csray.f90", "max_issues_repo_name": "rutgervandeelen/das", "max_issues_repo_head_hexsha": "4727a8daaf87c817fb49fbe6ce8eaa996210e7dc", "max_issues_repo_licenses": ["MIT"], "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/csray.f90", "max_forks_repo_name": "rutgervandeelen/das", "max_forks_repo_head_hexsha": "4727a8daaf87c817fb49fbe6ce8eaa996210e7dc", "max_forks_repo_licenses": ["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.3943661972, "max_line_length": 68, "alphanum_fraction": 0.5530583874, "num_tokens": 1717, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545318852121, "lm_q2_score": 0.7248702702332475, "lm_q1q2_score": 0.6872890317505119}} {"text": "program foo\n integer, dimension (2, 3) :: a\n integer, dimension (2, 2, 3) :: b\n character (len=80) line1, line2, line3\n\n a = reshape ((/1, 2, 3, 4, 5, 6/), (/2, 3/))\n b = spread (a, 1, 2)\n if (any (b .ne. reshape ((/1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6/), &\n (/2, 2, 3/)))) &\n call abort\n write(line1, 9000) b\n write(line2, 9000) spread (a, 1, 2)\n if (line1 /= line2) call abort\n write(line3, 9000) spread (a, 1, 2) + 0\n if (line1 /= line3) call abort\n9000 format(12I3)\nend program\n", "meta": {"hexsha": "8a89b2d731a67c127817a5b96faf4b79f04a9463", "size": 534, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_spread.f90", "max_stars_repo_name": "best08618/asylo", "max_stars_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-05-02T17:34:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-17T10:15:18.000Z", "max_issues_repo_path": "llvm-gcc-4.2-2.9/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_spread.f90", "max_issues_repo_name": "vidkidz/crossbridge", "max_issues_repo_head_hexsha": "ba0bf94aee0ce6cf7eb5be882382e52bc57ba396", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "llvm-gcc-4.2-2.9/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_spread.f90", "max_forks_repo_name": "vidkidz/crossbridge", "max_forks_repo_head_hexsha": "ba0bf94aee0ce6cf7eb5be882382e52bc57ba396", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-27T00:22:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-01T09:41:02.000Z", "avg_line_length": 29.6666666667, "max_line_length": 69, "alphanum_fraction": 0.5074906367, "num_tokens": 245, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936879, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.6872599829924885}} {"text": "subroutine djpi2(dj, lmax, exitstatus)\n!------------------------------------------------------------------------------\n!\n! This subroutine computes\n! j\n! d (pi/2)\n! m N\n!\n! for all posible values of m (>=0) and N for 0 errbnd) &\r\nier = 2\r\nIF (limit == 1) ier = 1\r\nIF (ier /= 0 .OR. (abserr <= errbnd .AND. abserr /= resabs) &\r\n.OR. abserr == 0.0D0) GO TO 130\r\n\r\n! INITIALIZATION\r\n! --------------\r\n\r\nrlist2(1) = result\r\nerrmax = abserr\r\nmaxerr = 1\r\narea = result\r\nerrsum = abserr\r\nabserr = oflow\r\ncorrec = 0.0D0\r\nnrmax = 1\r\nnres = 0\r\nktmin = 0\r\nnumrl2 = 2\r\nextrap = .false.\r\nnoext = .false.\r\nierro = 0\r\niroff1 = 0\r\niroff2 = 0\r\niroff3 = 0\r\nksgn = -1\r\nIF (dres >= (1.0D0 - 50.0D0*epmach)*defabs) ksgn = 1\r\nt = 1.0D0 + 100.0D0*epmach\r\n\r\n! MAIN DO-LOOP\r\n! ------------\r\n\r\nDO last = 2,limit\r\n \r\n! BISECT THE SUBINTERVAL WITH NRMAX-TH LARGEST ERROR ESTIMATE.\r\n \r\n a1 = alist(maxerr)\r\n b1 = 0.5D0*(alist(maxerr) + blist(maxerr))\r\n a2 = b1\r\n b2 = blist(maxerr)\r\n erlast = errmax\r\n CALL qk15i (f, boun, inf, a1, b1, area1, error1, &\r\n resabs, defab1, epmach, uflow)\r\n CALL qk15i (f, boun, inf, a2, b2, area2, error2, &\r\n resabs, defab2, epmach, uflow)\r\n \r\n! IMPROVE PREVIOUS APPROXIMATIONS TO INTEGRAL AND ERROR\r\n! AND TEST FOR ACCURACY.\r\n \r\n area12 = area1 + area2\r\n erro12 = error1 + error2\r\n errsum = errsum + erro12 - errmax\r\n area = area + area12 - rlist(maxerr)\r\n IF (defab1 == error1 .OR. defab2 == error2) GO TO 15\r\n IF (ABS(rlist(maxerr) - area12) > 0.1D-04*ABS(area12) &\r\n .OR. erro12 < 0.99D0*errmax) GO TO 10\r\n IF (extrap) iroff2 = iroff2 + 1\r\n IF (.NOT.extrap) iroff1 = iroff1 + 1\r\n 10 IF (last > 10 .AND. erro12 > errmax) iroff3 = iroff3 + 1\r\n 15 rlist(maxerr) = area1\r\n rlist(last) = area2\r\n errbnd = MAX(epsabs,rerr*ABS(area))\r\n \r\n! TEST FOR ROUNDOFF ERROR AND EVENTUALLY SET ERROR FLAG.\r\n \r\n IF (iroff1 + iroff2 >= 10 .OR. iroff3 >= 20) ier = 2\r\n IF (iroff2 >= 5) ierro = 3\r\n \r\n! SET ERROR FLAG IN THE CASE THAT THE NUMBER OF\r\n! SUBINTERVALS EQUALS LIMIT.\r\n \r\n IF (last == limit) ier = 1\r\n \r\n! SET ERROR FLAG IN THE CASE OF BAD INTEGRAND BEHAVIOUR\r\n! AT SOME POINTS OF THE INTEGRATION RANGE.\r\n \r\n \r\n IF (MAX(ABS(a1),ABS(b2)) <= t*(ABS(a2) + 0.1D+04*uflow)) ier = 4\r\n \r\n! APPEND THE NEWLY-CREATED INTERVALS TO THE LIST.\r\n \r\n IF (error2 > error1) GO TO 20\r\n alist(last) = a2\r\n blist(maxerr) = b1\r\n blist(last) = b2\r\n elist(maxerr) = error1\r\n elist(last) = error2\r\n GO TO 30\r\n 20 alist(maxerr) = a2\r\n alist(last) = a1\r\n blist(last) = b1\r\n rlist(maxerr) = area2\r\n rlist(last) = area1\r\n elist(maxerr) = error2\r\n elist(last) = error1\r\n \r\n! CALL SUBROUTINE QPSRT TO MAINTAIN THE DESCENDING ORDERING\r\n! IN THE LIST OF ERROR ESTIMATES AND SELECT THE SUBINTERVAL WITH\r\n! NRMAX-TH LARGEST ERROR ESTIMATE (TO BE BISECTED NEXT).\r\n \r\n 30 CALL qpsrt (limit,last,maxerr,errmax,elist,iord,nrmax)\r\n IF (errsum <= errbnd) GO TO 115\r\n IF (ier /= 0) GO TO 100\r\n IF (last == 2) GO TO 80\r\n IF (noext) CYCLE\r\n erlarg = erlarg - erlast\r\n IF (ABS(b1 - a1) > small) erlarg = erlarg + erro12\r\n IF (extrap) GO TO 40\r\n \r\n! TEST WHETHER THE INTERVAL TO BE BISECTED NEXT IS THE\r\n! SMALLEST INTERVAL.\r\n \r\n IF (ABS(blist(maxerr) - alist(maxerr)) > small) CYCLE\r\n extrap = .true.\r\n nrmax = 2\r\n 40 IF (ierro == 3 .OR. erlarg <= ertest) GO TO 60\r\n \r\n! THE SMALLEST INTERVAL HAS THE LARGEST ERROR.\r\n! BEFORE BISECTING DECREASE THE SUM OF THE ERRORS\r\n! OVER THE LARGER INTERVALS (ERLARG) AND PERFORM EXTRAPOLATION.\r\n \r\n id = nrmax\r\n jupbnd = last\r\n IF (last > (2 + limit/2)) jupbnd = limit + 3 - last\r\n DO k = id,jupbnd\r\n maxerr = iord(nrmax)\r\n errmax = elist(maxerr)\r\n IF (ABS(blist(maxerr) - alist(maxerr)) > small) CYCLE\r\n nrmax = nrmax + 1\r\n END DO\r\n \r\n! PERFORM EXTRAPOLATION.\r\n \r\n 60 numrl2 = numrl2 + 1\r\n rlist2(numrl2) = area\r\n CALL qelg (numrl2, rlist2, reseps, abseps, res3la, nres,epmach, oflow)\r\n ktmin = ktmin + 1\r\n IF (ktmin > 5 .AND. abserr < 0.1D-02*errsum) ier = 5\r\n IF (abseps >= abserr) GO TO 70\r\n ktmin = 0\r\n abserr = abseps\r\n result = reseps\r\n correc = erlarg\r\n ertest = MAX(epsabs,rerr*ABS(reseps))\r\n IF (abserr <= ertest) GO TO 100\r\n \r\n! PREPARE BISECTION OF THE SMALLEST INTERVAL.\r\n \r\n 70 IF (numrl2 == 1) noext = .true.\r\n IF (ier == 5) GO TO 100\r\n maxerr = iord(1)\r\n errmax = elist(maxerr)\r\n nrmax = 1\r\n extrap = .false.\r\n small = small*0.5D0\r\n erlarg = errsum\r\n CYCLE\r\n 80 small = 0.375D0\r\n erlarg = errsum\r\n ertest = errbnd\r\n rlist2(2) = area\r\nEND DO\r\n\r\n! SET FINAL RESULT AND ERROR ESTIMATE.\r\n! ------------------------------------\r\n\r\n100 IF (abserr == oflow) GO TO 115\r\nIF (ier + ierro == 0) GO TO 110\r\nIF (ierro == 3) abserr = abserr + correc\r\nIF (ier == 0) ier = 3\r\nIF (result /= 0.0D0 .AND. area /= 0.0D0) GO TO 105\r\nIF (abserr > errsum) GO TO 115\r\nIF (area == 0.0D0) GO TO 130\r\nGO TO 110\r\n105 IF (abserr/ABS(result) > errsum/ABS(area)) GO TO 115\r\n\r\n! TEST ON DIVERGENCE\r\n\r\n110 IF (ksgn == -1 .AND. MAX(ABS(result),ABS(area)) <= &\r\ndefabs*0.1D-01) GO TO 130\r\nIF (0.1D-01 > (result/area) .OR. (result/area) > 0.1D+03 &\r\n.OR. errsum > ABS(area)) ier = 6\r\nGO TO 130\r\n\r\n! COMPUTE GLOBAL INTEGRAL SUM.\r\n\r\n115 result = 0.0D0\r\nDO k = 1,last\r\n result = result + rlist(k)\r\nEND DO\r\nabserr = errsum\r\n130 neval = 30*last - 15\r\nIF (inf == 2) neval = 2*neval\r\nIF (ier > 2) ier = ier - 1\r\n999 RETURN\r\nEND SUBROUTINE qagie\r\n\r\n\r\n\r\nSUBROUTINE qk15i (f, boun, inf, a, b, result, abserr, resabs, &\r\n resasc, epmach, uflow)\r\n!-----------------------------------------------------------------------\r\n\r\n! 1. PURPOSE\r\n! THE ORIGINAL (INFINITE) INTEGRATION RANGE IS MAPPED\r\n! ONTO THE INTERVAL (0,1) AND (A,B) IS A PART OF (0,1).\r\n! IT IS THE PURPOSE TO COMPUTE\r\n! I = INTEGRAL OF TRANSFORMED INTEGRAND OVER (A,B),\r\n! J = INTEGRAL OF ABS(TRANSFORMED INTEGRAND) OVER (A,B).\r\n\r\n! 2. PARAMETERS\r\n! ON ENTRY\r\n! F - REAL\r\n! FUNCTION SUBPROGRAM DEFINING THE INTEGRAND FUNCTION F(X).\r\n! THE ACTUAL NAME FOR F NEEDS TO BE DECLARED E X T E R N A L\r\n! IN THE CALLING PROGRAM.\r\n\r\n! BOUN - REAL\r\n! FINITE BOUND OF ORIGINAL INTEGRATION\r\n! RANGE (SET TO ZERO IF INF = +2)\r\n\r\n! INF - INTEGER\r\n! IF INF = -1, THE ORIGINAL INTERVAL IS\r\n! (-INFINITY,BOUND),\r\n! IF INF = +1, THE ORIGINAL INTERVAL IS\r\n! (BOUND,+INFINITY),\r\n! IF INF = +2, THE ORIGINAL INTERVAL IS\r\n! (-INFINITY,+INFINITY) AND\r\n! THE INTEGRAL IS COMPUTED AS THE SUM OF TWO INTEGRALS,\r\n! ONE OVER (-INFINITY,0) AND ONE OVER (0,+INFINITY).\r\n\r\n! A - REAL\r\n! LOWER LIMIT FOR INTEGRATION OVER SUBRANGE OF (0,1)\r\n\r\n! B - REAL\r\n! UPPER LIMIT FOR INTEGRATION OVER SUBRANGE OF (0,1)\r\n\r\n! EPMACH - REAL\r\n! THE RELATIVE PRECISION OF THE FLOATING ARITHMETIC BEING USED.\r\n\r\n! UFLOW - REAL\r\n! THE SMALLEST POSITIVE MAGNITUDE.\r\n\r\n! ON RETURN\r\n! RESULT - REAL\r\n! APPROXIMATION TO THE INTEGRAL I\r\n! RESULT IS COMPUTED BY APPLYING THE 15-POINT KRONROD RULE\r\n! (RESK) OBTAINED BY OPTIMAL ADDITION OF ABSCISSAE TO THE\r\n! 7-POINT GAUSS RULE(RESG).\r\n\r\n! ABSERR - REAL\r\n! ESTIMATE OF THE MODULUS OF THE ABSOLUTE ERROR,\r\n! WHICH SHOULD EQUAL OR EXCEED ABS(I-RESULT)\r\n\r\n! RESABS - REAL\r\n! APPROXIMATION TO THE INTEGRAL J\r\n\r\n! RESASC - REAL\r\n! APPROXIMATION TO THE INTEGRAL OF\r\n! ABS((TRANSFORMED INTEGRAND)-I/(B-A)) OVER (A,B)\r\n\r\n! 3. SUBROUTINES OR FUNCTIONS NEEDED\r\n! - F (USER-PROVIDED FUNCTION)\r\n\r\n!-----------------------------------------------------------------------\r\n\r\nREAL (dp), INTENT(IN) :: boun, a, b, epmach, uflow\r\nINTEGER, INTENT(IN) :: inf\r\nREAL (dp), INTENT(OUT) :: result, abserr, resabs, resasc\r\n\r\nREAL (dp) :: fv1(7), fv2(7)\r\n\r\nINTERFACE\r\n FUNCTION f(x) RESULT(fx)\r\n USE constants_NSWC\r\n IMPLICIT NONE\r\n REAL (dp), INTENT(IN) :: x\r\n REAL (dp) :: fx\r\n END FUNCTION f\r\nEND INTERFACE\r\n\r\n! THE ABSCISSAE AND WEIGHTS ARE SUPPLIED FOR THE INTERVAL\r\n! (-1,1). BECAUSE OF SYMMETRY ONLY THE POSITIVE ABSCISSAE AND\r\n! THEIR CORRESPONDING WEIGHTS ARE GIVEN.\r\n\r\n! XGK - ABSCISSAE OF THE 15-POINT KRONROD RULE\r\n! XGK(2), XGK(4), ... ABSCISSAE OF THE 7-POINT GAUSS RULE\r\n! XGK(1), XGK(3), ... ABSCISSAE WHICH ARE OPTIMALLY\r\n! ADDED TO THE 7-POINT GAUSS RULE\r\n\r\n! WGK - WEIGHTS OF THE 15-POINT KRONROD RULE\r\n\r\n! WG - WEIGHTS OF THE 7-POINT GAUSS RULE, CORRESPONDING TO THE\r\n! ABSCISSAE XGK(2), XGK(4), ... WG(1), WG(3), ...\r\n! ARE SET TO ZERO.\r\n\r\nREAL (dp) :: absc, absc1, absc2, centr, dinf, fc, fsum, fval1, fval2, &\r\n hlgth, resg, resk, reskh, tabsc1, tabsc2, tol\r\nINTEGER :: j\r\nREAL (dp), DIMENSION(8) :: xgk = (/ &\r\n 0.9914553711208126D+00, 0.9491079123427585D+00, &\r\n 0.8648644233597691D+00, 0.7415311855993944D+00, &\r\n 0.5860872354676911D+00, 0.4058451513773972D+00, &\r\n 0.2077849550078985D+00, 0.0000000000000000D+00 /), &\r\n wgk = (/ &\r\n 0.2293532201052922D-01, 0.6309209262997855D-01, &\r\n 0.1047900103222502D+00, 0.1406532597155259D+00, &\r\n 0.1690047266392679D+00, 0.1903505780647854D+00, &\r\n 0.2044329400752989D+00, 0.2094821410847278D+00 /), &\r\n wg = (/ &\r\n 0.0000000000000000D+00, 0.1294849661688697D+00, &\r\n 0.0000000000000000D+00, 0.2797053914892767D+00, &\r\n 0.0000000000000000D+00, 0.3818300505051189D+00, &\r\n 0.0000000000000000D+00, 0.4179591836734694D+00 /)\r\n\r\n! LIST OF MAJOR VARIABLES\r\n! -----------------------\r\n\r\n! CENTR - MID POINT OF THE INTERVAL\r\n! HLGTH - HALF-LENGTH OF THE INTERVAL\r\n! ABSC* - ABSCISSA\r\n! TABSC* - TRANSFORMED ABSCISSA\r\n! FVAL* - FUNCTION VALUE\r\n! RESG - RESULT OF THE 7-POINT GAUSS FORMULA\r\n! RESK - RESULT OF THE 15-POINT KRONROD FORMULA\r\n! RESKH - APPROXIMATION TO THE MEAN VALUE OF THE TRANSFORMED\r\n! INTEGRAND OVER (A,B), I.E. TO I/(B-A)\r\n\r\ndinf = MIN(1,inf)\r\n\r\ncentr = 0.5D0*(a + b)\r\nhlgth = 0.5D0*(b - a)\r\ntabsc1 = boun + dinf*(1.0D0 - centr)/centr\r\nfval1 = f(tabsc1)\r\nIF (inf == 2) fval1 = fval1 + f(-tabsc1)\r\nfc = (fval1/centr)/centr\r\n\r\n! COMPUTE THE 15-POINT KRONROD APPROXIMATION TO THE INTEGRAL,\r\n! AND ESTIMATE THE ERROR.\r\n\r\nresg = wg(8)*fc\r\nresk = wgk(8)*fc\r\nresabs = ABS(resk)\r\nDO j = 1,7\r\n absc = hlgth*xgk(j)\r\n absc1 = centr - absc\r\n absc2 = centr + absc\r\n tabsc1 = boun + dinf*(1.0D0 - absc1)/absc1\r\n tabsc2 = boun + dinf*(1.0D0 - absc2)/absc2\r\n fval1 = f(tabsc1)\r\n fval2 = f(tabsc2)\r\n IF (inf == 2) fval1 = fval1 + f(-tabsc1)\r\n IF (inf == 2) fval2 = fval2 + f(-tabsc2)\r\n fval1 = (fval1/absc1)/absc1\r\n fval2 = (fval2/absc2)/absc2\r\n fv1(j) = fval1\r\n fv2(j) = fval2\r\n fsum = fval1 + fval2\r\n resg = resg + wg(j)*fsum\r\n resk = resk + wgk(j)*fsum\r\n resabs = resabs + wgk(j)*(ABS(fval1) + ABS(fval2))\r\nEND DO\r\nreskh = resk / 2\r\nresasc = wgk(8)*ABS(fc - reskh)\r\nDO j = 1,7\r\n resasc = resasc + wgk(j)*(ABS(fv1(j)-reskh) + ABS(fv2(j)-reskh))\r\nEND DO\r\nresult = resk*hlgth\r\nresasc = resasc*hlgth\r\nresabs = resabs*hlgth\r\nabserr = ABS((resk - resg)*hlgth)\r\nIF (resasc /= 0.0D0 .AND. abserr /= 0.0D0) abserr = resasc* &\r\n MIN(1.0D0, (0.2D+03*abserr/resasc)**1.5D0)\r\ntol = 50.0D0*epmach\r\nIF (resabs > uflow/tol) abserr = MAX(abserr, tol*resabs)\r\n\r\nRETURN\r\nEND SUBROUTINE qk15i\r\n\r\n\r\n\r\nSUBROUTINE qpsrt(limit, last, maxerr, ermax, elist, iord, nrmax)\r\n! ..................................................................\r\n\r\n! 1. QPSRT\r\n! ORDERING ROUTINE\r\n! STANDARD FORTRAN SUBROUTINE\r\n! REAL VERSION\r\n\r\n! 2. PURPOSE\r\n! THIS ROUTINE MAINTAINS THE DESCENDING ORDERING IN THE LIST OF THE\r\n! LOCAL ERROR ESTIMATES RESULTING FROM THE INTERVAL SUBDIVISION\r\n! PROCESS. AT EACH CALL TWO ERROR ESTIMATES ARE INSERTED USING THE\r\n! SEQUENTIAL SEARCH METHOD, TOP-DOWN FOR THE LARGEST ERROR ESTIMATE\r\n! AND BOTTOM-UP FOR THE SMALLEST ERROR ESTIMATE.\r\n\r\n! 3. CALLING SEQUENCE\r\n! CALL QPSRT(LIMIT, LAST, MAXERR, ERMAX, ELIST, IORD, NRMAX)\r\n\r\n! PARAMETERS (MEANING AT OUTPUT)\r\n! LIMIT - INTEGER\r\n! MAXIMUM NUMBER OF ERROR ESTIMATES THE LIST CAN CONTAIN\r\n\r\n! LAST - INTEGER\r\n! NUMBER OF ERROR ESTIMATES CURRENTLY IN THE LIST\r\n\r\n! MAXERR - INTEGER\r\n! MAXERR POINTS TO THE NRMAX-TH LARGEST ERROR ESTIMATE\r\n! CURRENTLY IN THE LIST\r\n\r\n! ERMAX - REAL\r\n! NRMAX-TH LARGEST ERROR ESTIMATE\r\n! ERMAX = ELIST(MAXERR)\r\n\r\n! ELIST - REAL\r\n! VECTOR OF DIMENSION LAST CONTAINING THE ERROR ESTIMATES\r\n\r\n! IORD - INTEGER\r\n! VECTOR OF DIMENSION LAST, THE FIRST K ELEMENTS OF\r\n! WHICH CONTAIN POINTERS TO THE ERROR ESTIMATES,\r\n! SUCH THAT ELIST(IORD(1)), ... , ELIST(IORD(K))\r\n! FORM A DECREASING SEQUENCE, WITH K = LAST IF\r\n! LAST <= (LIMIT/2+2), AND K = LIMIT+1-LAST OTHERWISE\r\n\r\n! NRMAX - INTEGER\r\n! MAXERR = IORD(NRMAX)\r\n\r\n! 4. NO SUBROUTINES OR FUNCTIONS NEEDED\r\n\r\n! ..................................................................\r\n\r\n\r\nINTEGER, INTENT(IN) :: limit, last\r\nREAL (dp), DIMENSION(:), INTENT(IN) :: elist\r\nINTEGER, INTENT(IN OUT) :: nrmax\r\nINTEGER, DIMENSION(:), INTENT(OUT) :: iord\r\nINTEGER, INTENT(OUT) :: maxerr\r\nREAL (dp), INTENT(OUT) :: ermax\r\n\r\nREAL (dp) :: errmax, errmin\r\nINTEGER :: i, ibeg, ido, isucc, j, jbnd, jupbn, k\r\n\r\n! CHECK WHETHER THE LIST CONTAINS MORE THAN TWO ERROR ESTIMATES.\r\n\r\n!***FIRST EXECUTABLE STATEMENT QPSRT\r\nIF(last > 2) GO TO 10\r\niord(1) = 1\r\niord(2) = 2\r\nGO TO 90\r\n\r\n! THIS PART OF THE ROUTINE IS ONLY EXECUTED IF,\r\n! DUE TO A DIFFICULT INTEGRAND, SUBDIVISION INCREASED\r\n! THE ERROR ESTIMATE. IN THE NORMAL CASE THE INSERT PROCEDURE\r\n! SHOULD START AFTER THE NRMAX-TH LARGEST ERROR ESTIMATE.\r\n\r\n10 errmax = elist(maxerr)\r\nIF(nrmax == 1) GO TO 30\r\nido = nrmax-1\r\nDO i = 1, ido\r\n isucc = iord(nrmax-1)\r\n! ***JUMP OUT OF DO-LOOP\r\n IF(errmax <= elist(isucc)) EXIT\r\n iord(nrmax) = isucc\r\n nrmax = nrmax-1\r\nEND DO\r\n\r\n! COMPUTE THE NUMBER OF ELEMENTS IN THE LIST TO\r\n! BE MAINTAINED IN DESCENDING ORDER. THIS NUMBER\r\n! DEPENDS ON THE NUMBER OF SUBDIVISIONS STILL ALLOWED.\r\n\r\n30 jupbn = last\r\nIF(last > (limit/2+2)) jupbn = limit+3-last\r\nerrmin = elist(last)\r\n\r\n! INSERT ERRMAX BY TRAVERSING THE LIST TOP-DOWN,\r\n! STARTING COMPARISON FROM THE ELEMENT ELIST(IORD(NRMAX+1)).\r\n\r\njbnd = jupbn-1\r\nibeg = nrmax+1\r\nDO i=ibeg, jbnd\r\n isucc = iord(i)\r\n! ***JUMP OUT OF DO-LOOP\r\n IF(errmax >= elist(isucc)) GO TO 60\r\n iord(i-1) = isucc\r\nEND DO\r\niord(jbnd) = maxerr\r\niord(jupbn) = last\r\nGO TO 90\r\n\r\n! INSERT ERRMIN BY TRAVERSING THE LIST BOTTOM-UP.\r\n\r\n60 iord(i-1) = maxerr\r\nk = jbnd\r\nDO j=i, jbnd\r\n isucc = iord(k)\r\n! ***JUMP OUT OF DO-LOOP\r\n IF(errmin < elist(isucc)) GO TO 80\r\n iord(k+1) = isucc\r\n k = k-1\r\nEND DO\r\niord(i) = last\r\nGO TO 90\r\n80 iord(k+1) = last\r\n\r\n! SET MAXERR AND ERMAX.\r\n\r\n90 maxerr = iord(nrmax)\r\nermax = elist(maxerr)\r\nRETURN\r\nEND SUBROUTINE qpsrt\r\n\r\n\r\n\r\nSUBROUTINE qelg (n, epstab, result, abserr, res3la, nres, epmach, oflow)\r\n!-----------------------------------------------------------------------\r\n\r\n! 1. PURPOSE\r\n! THE ROUTINE DETERMINES THE LIMIT OF A GIVEN SEQUENCE OF\r\n! APPROXIMATIONS, BY MEANS OF THE EPSILON ALGORITHM OF P. WYNN.\r\n! AN ESTIMATE OF THE ABSOLUTE ERROR IS ALSO GIVEN.\r\n! THE CONDENSED EPSILON TABLE IS COMPUTED. ONLY THOSE ELEMENTS NEEDED\r\n! FOR THE COMPUTATION OF THE NEXT DIAGONAL ARE PRESERVED.\r\n\r\n! 2. PARAMETERS\r\n! N - INTEGER\r\n! EPSTAB(N) CONTAINS THE NEW ELEMENT IN THE\r\n! FIRST COLUMN OF THE EPSILON TABLE.\r\n\r\n! EPSTAB - REAL\r\n! VECTOR OF DIMENSION 52 CONTAINING THE ELEMENTS OF THE TWO\r\n! LOWER DIAGONALS OF THE TRIANGULAR EPSILON TABLE.\r\n! THE ELEMENTS ARE NUMBERED STARTING AT THE RIGHT-HAND\r\n! CORNER OF THE TRIANGLE.\r\n\r\n! RESULT - REAL\r\n! RESULTING APPROXIMATION TO THE INTEGRAL\r\n\r\n! ABSERR - REAL\r\n! ESTIMATE OF THE ABSOLUTE ERROR COMPUTED FROM\r\n! RESULT AND THE 3 PREVIOUS RESULTS\r\n\r\n! RES3LA - REAL\r\n! VECTOR OF DIMENSION 3 CONTAINING THE LAST 3 RESULTS\r\n\r\n! NRES - INTEGER\r\n! NUMBER OF CALLS TO THE ROUTINE\r\n! (SHOULD BE ZERO AT FIRST CALL)\r\n\r\n! EPMACH - REAL\r\n! THE RELATIVE PRECISION OF THE FLOATING ARITHMETIC BEING USED.\r\n\r\n! OFLOW - REAL\r\n! THE LARGEST POSITIVE MAGNITUDE.\r\n\r\n! 3. NO SUBROUTINES OR FUNCTIONS USED\r\n\r\n!-----------------------------------------------------------------------\r\n\r\nINTEGER, INTENT(IN OUT) :: n, nres\r\nREAL (dp), INTENT(IN) :: epmach, oflow\r\nREAL (dp), INTENT(OUT) :: abserr, result\r\nREAL (dp), DIMENSION(:), INTENT(IN OUT) :: epstab, res3la\r\n!---------------------\r\n\r\n! LIST OF MAJOR VARIABLES\r\n! -----------------------\r\n\r\n! E0 - THE 4 ELEMENTS ON WHICH THE\r\n! E1 COMPUTATION OF A NEW ELEMENT IN\r\n! E2 THE EPSILON TABLE IS BASED\r\n! E3 E0\r\n! E3 E1 NEW\r\n! E2\r\n! NEWELM - NUMBER OF ELEMENTS TO BE COMPUTED IN THE NEW DIAGONAL\r\n! ERROR - ERROR = ABS(E1-E0)+ABS(E2-E1)+ABS(NEW-E2)\r\n! RESULT - THE ELEMENT IN THE NEW DIAGONAL WITH LEAST VALUE OF ERROR\r\n\r\n! LIMEXP IS THE MAXIMUM NUMBER OF ELEMENTS THE EPSILON TABLE CAN CONTAIN.\r\n! IF THIS NUMBER IS REACHED, THE UPPER DIAGONAL OF THE EPSILON TABLE IS\r\n! DELETED.\r\n\r\nREAL (dp) :: delta1, delta2, delta3, epsinf, error, err1, err2, err3, e0, &\r\n e1, e1abs, e2, e3, res, ss, tol1, tol2, tol3\r\nINTEGER :: i, ib, ib2, ie, indx, k1, k2, k3, limexp, newelm, num\r\n\r\nnres = nres + 1\r\nabserr = oflow\r\nresult = epstab(n)\r\nIF (n < 3) GO TO 100\r\nlimexp = 50\r\nepstab(n + 2) = epstab(n)\r\nnewelm = (n - 1)/2\r\nepstab(n) = oflow\r\nnum = n\r\nk1 = n\r\nDO i = 1, newelm\r\n k2 = k1 - 1\r\n k3 = k1 - 2\r\n res = epstab(k1 + 2)\r\n e0 = epstab(k3)\r\n e1 = epstab(k2)\r\n e2 = res\r\n e1abs = ABS(e1)\r\n delta2 = e2 - e1\r\n err2 = ABS(delta2)\r\n tol2 = MAX(ABS(e2),e1abs)*epmach\r\n delta3 = e1 - e0\r\n err3 = ABS(delta3)\r\n tol3 = MAX(e1abs,ABS(e0))*epmach\r\n IF (err2 > tol2 .OR. err3 > tol3) GO TO 10\r\n\r\n! IF E0, E1 AND E2 ARE EQUAL TO WITHIN MACHINE ACCURACY,\r\n! CONVERGENCE IS ASSUMED.\r\n! RESULT = E2\r\n! ABSERR = ABS(E1-E0) + ABS(E2-E1)\r\n\r\n result = res\r\n abserr = err2 + err3\r\n! ***JUMP OUT OF DO-LOOP\r\n GO TO 100\r\n 10 e3 = epstab(k1)\r\n epstab(k1) = e1\r\n delta1 = e1 - e3\r\n err1 = ABS(delta1)\r\n tol1 = MAX(e1abs,ABS(e3))*epmach\r\n\r\n! IF TWO ELEMENTS ARE VERY CLOSE TO EACH OTHER, OMIT\r\n! A PART OF THE TABLE BY ADJUSTING THE VALUE OF N\r\n\r\n IF (err1 <= tol1 .OR. err2 <= tol2 .OR. err3 <= tol3) GO TO 20\r\n ss = 1.0D0/delta1 + 1.0D0/delta2 - 1.0D0/delta3\r\n epsinf = ABS(ss*e1)\r\n\r\n! TEST TO DETECT IRREGULAR BEHAVIOUR IN THE TABLE, AND EVENTUALLY\r\n! OMIT A PART OF THE TABLE ADJUSTING THE VALUE OF N.\r\n\r\n IF (epsinf > 0.1D-03) GO TO 30\r\n 20 n = i + i - 1\r\n! ***JUMP OUT OF DO-LOOP\r\n GO TO 50\r\n\r\n! COMPUTE A NEW ELEMENT AND EVENTUALLY ADJUST THE VALUE OF RESULT.\r\n\r\n 30 res = e1 + 1.0D0/ss\r\n epstab(k1) = res\r\n k1 = k1 - 2\r\n error = err2 + ABS(res - e2) + err3\r\n IF (error > abserr) CYCLE\r\n abserr = error\r\n result = res\r\nEND DO\r\n\r\n! SHIFT THE TABLE.\r\n\r\n50 IF (n == limexp) n = 2*(limexp/2) - 1\r\nib = 1\r\nIF ((num/2)*2 == num) ib = 2\r\nie = newelm + 1\r\nDO i = 1, ie\r\n ib2 = ib + 2\r\n epstab(ib) = epstab(ib2)\r\n ib = ib2\r\nEND DO\r\nIF (num == n) GO TO 80\r\nindx = num - n + 1\r\nDO i = 1, n\r\n epstab(i) = epstab(indx)\r\n indx = indx + 1\r\nEND DO\r\n80 IF (nres >= 4) GO TO 90\r\nres3la(nres) = result\r\nabserr = oflow\r\nGO TO 100\r\n\r\n! COMPUTE ERROR ESTIMATE\r\n\r\n90 abserr = ABS(result - res3la(3)) + ABS(result - res3la(2)) + &\r\n ABS(result - res3la(1))\r\nres3la(1) = res3la(2)\r\nres3la(2) = res3la(3)\r\nres3la(3) = result\r\n100 abserr = MAX(abserr,5.0D0*epmach*ABS(result))\r\nRETURN\r\nEND SUBROUTINE qelg\r\n\r\nEND MODULE adapt_quad_infinite\r\n", "meta": {"hexsha": "bfef1c773004384dfe574c9de2e58a2b476f4793", "size": 38151, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/qagi.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/qagi.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/qagi.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": 34.6827272727, "max_line_length": 80, "alphanum_fraction": 0.5427904904, "num_tokens": 11867, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818986, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.6872139366516299}} {"text": "PROGRAM Triangle\n IMPLICIT NONE\n REAL :: a, b, c, Area\n PRINT *, 'Welcome, please enter the&\n &lengths of the 3 sides.'\n READ *, a, b, c\n PRINT *, 'Triangle''s area: ', Area(a,b,c)\nEND PROGRAM Triangle\nFUNCTION Area(x,y,z)\n IMPLICIT NONE\n REAL :: Area ! function type\n REAL, INTENT( IN ) :: x, y, z\n REAL :: theta, height\n theta = ACOS((x**2+y**2-z**2)/(2.0*x*y))\n height = x*SIN(theta); Area = 0.5*y*height\nEND FUNCTION Area\n", "meta": {"hexsha": "67cd250c384eb9ac6f48944601a17f20d390cb47", "size": 482, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "samples/code/example.f90", "max_stars_repo_name": "Jason-Rev/vscode-spell-checker", "max_stars_repo_head_hexsha": "6781e5e952a0007f78ceff1d157763709c2c7762", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 255, "max_stars_repo_stars_event_min_datetime": "2016-06-02T10:33:49.000Z", "max_stars_repo_stars_event_max_datetime": "2019-05-10T15:32:10.000Z", "max_issues_repo_path": "samples/code/example.f90", "max_issues_repo_name": "Jason-Rev/vscode-spell-checker", "max_issues_repo_head_hexsha": "6781e5e952a0007f78ceff1d157763709c2c7762", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 334, "max_issues_repo_issues_event_min_datetime": "2016-06-02T10:33:44.000Z", "max_issues_repo_issues_event_max_datetime": "2019-05-09T09:18:07.000Z", "max_forks_repo_path": "samples/code/example.f90", "max_forks_repo_name": "Jason-Rev/vscode-spell-checker", "max_forks_repo_head_hexsha": "6781e5e952a0007f78ceff1d157763709c2c7762", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 45, "max_forks_repo_forks_event_min_datetime": "2016-06-22T08:02:27.000Z", "max_forks_repo_forks_event_max_datetime": "2019-05-05T10:02:45.000Z", "avg_line_length": 28.3529411765, "max_line_length": 47, "alphanum_fraction": 0.5622406639, "num_tokens": 154, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171067, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.6872139366480624}} {"text": " SUBROUTINE RNARRY(AA,N)\nC FORTRAN 77 version of \"ran_array\"\nC from Seminumerical Algorithms by D E Knuth, 3rd edition (1997)\nC including the MODIFICATIONS made in the 9th printing (2002)\nC and a bugfix to make this compatible with rng.c (2012)\nC ********* see the book for explanations and caveats! *********\n IMPLICIT INTEGER (A-Z)\n DIMENSION AA(*)\n PARAMETER (KK=100)\n PARAMETER (LL=37)\n PARAMETER (MM=2**30)\n COMMON /RSTATE/ RANX(KK)\n SAVE /RSTATE/\n DO 1 J=1,KK\n 1 AA(J)=RANX(J)\n DO 2 J=KK+1,N\n AA(J)=AA(J-KK)-AA(J-LL)\n IF (AA(J) .LT. 0) AA(J)=AA(J)+MM\n 2 CONTINUE\n DO 3 J=1,LL\n RANX(J)=AA(N+J-KK)-AA(N+J-LL)\n IF (RANX(J) .LT. 0) RANX(J)=RANX(J)+MM\n 3 CONTINUE\n DO 4 J=LL+1,KK\n RANX(J)=AA(N+J-KK)-RANX(J-LL)\n IF (RANX(J) .LT. 0) RANX(J)=RANX(J)+MM\n 4 CONTINUE\n END\n\n\n SUBROUTINE RNSTRT(SEED)\n IMPLICIT INTEGER (A-Z)\n PARAMETER (KK=100)\n PARAMETER (LL=37)\n PARAMETER (MM=2**30)\n PARAMETER (TT=70)\n PARAMETER (KKK=KK+KK-1)\n DIMENSION X(KKK)\n COMMON /RSTATE/ RANX(KK)\n SAVE /RSTATE/\n IF (SEED .LT. 0) THEN\n SSEED=MM-1-MOD(-1-SEED,MM)\n ELSE\n SSEED=MOD(SEED,MM)\n END IF\n SS=SSEED-MOD(SSEED,2)+2\n DO 1 J=1,KK\n X(J)=SS\n SS=SS+SS\n IF (SS .GE. MM) SS=SS-MM+2\n 1 CONTINUE\n X(2)=X(2)+1\n SS=SSEED\n T=TT-1\n 10 DO 12 J=KK,2,-1\n X(J+J-1)=X(J)\n 12 X(J+J-2)=0\n DO 14 J=KKK,KK+1,-1\n X(J-(KK-LL))=X(J-(KK-LL))-X(J)\n IF (X(J-(KK-LL)) .LT. 0) X(J-(KK-LL))=X(J-(KK-LL))+MM\n X(J-KK)=X(J-KK)-X(J)\n IF (X(J-KK) .LT. 0) X(J-KK)=X(J-KK)+MM\n 14 CONTINUE\n IF (MOD(SS,2) .EQ. 1) THEN\n DO 16 J=KK,1,-1\n 16 X(J+1)=X(J)\n X(1)=X(KK+1)\n X(LL+1)=X(LL+1)-X(KK+1)\n IF (X(LL+1) .LT. 0) X(LL+1)=X(LL+1)+MM\n END IF\n IF (SS .NE. 0) THEN\n SS=SS/2\n ELSE\n T=T-1\n END IF\n IF (T .GT. 0) GO TO 10\n DO 20 J=1,LL\n 20 RANX(J+KK-LL)=X(J)\n DO 21 J=LL+1,KK\n 21 RANX(J-LL)=X(J)\n DO 22 J=1,10\n 22 CALL RNARRY(X,KKK)\n END\n\n\n PROGRAM MAIN\nC a rudimentary test program:\n IMPLICIT INTEGER (A-Z)\n DIMENSION A(2009)\n EXTERNAL RNSTRT, RNARRY\n CALL RNSTRT(310952)\n DO 1 I=1,2009\n CALL RNARRY(A,1009)\n 1 CONTINUE \n PRINT '(I15)',A(1)\nC the number should be 995235265\n CALL RNSTRT(310952)\n DO 2 I=1,1009\n CALL RNARRY(A,2009)\n 2 CONTINUE \n PRINT '(I15)',A(1)\nC again, 995235265\n END\n", "meta": {"hexsha": "4247dd4b1a3b4ecc07756095a7b0ab9ed28b1c29", "size": 2744, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Presents/RandomWalks/Resources/Codes/frng.f", "max_stars_repo_name": "hwborchers/Presentations", "max_stars_repo_head_hexsha": "7abcaccf6209c8601e0425c2e60d35a6f1b5c805", "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": "Presents/RandomWalks/Resources/Codes/frng.f", "max_issues_repo_name": "hwborchers/Presentations", "max_issues_repo_head_hexsha": "7abcaccf6209c8601e0425c2e60d35a6f1b5c805", "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": "Presents/RandomWalks/Resources/Codes/frng.f", "max_forks_repo_name": "hwborchers/Presentations", "max_forks_repo_head_hexsha": "7abcaccf6209c8601e0425c2e60d35a6f1b5c805", "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.3846153846, "max_line_length": 70, "alphanum_fraction": 0.4825072886, "num_tokens": 1091, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045817875224, "lm_q2_score": 0.7745833841649232, "lm_q1q2_score": 0.6872139274076045}} {"text": "c Subroutine to convert from stnpres to sealevel pressure\r\nc copied from earlier dwdsub analysis\r\nc AJ_Kettle, Nov29/2017\r\n\r\n SUBROUTINE slpres_from_stnpres_dwdday(\r\n + f_p_hpa,f_e_hpa,f_hght_m,f_airt_c,\r\n + f_slpres_hpa)\r\n\r\n IMPLICIT NONE\r\nc************************************************************************\r\n INTEGER :: i,j,k,ii,jj,kk\r\n\r\nc Inputs\r\n REAL :: f_p_hpa\r\n REAL :: f_e_hpa\r\n REAL :: f_hght_m\r\n REAL :: f_airt_c\r\n\r\nc Output\r\n REAL :: f_slpres_hpa\r\n\r\nc INTERNAL CONSTANTS\r\n REAL :: f_grav_ms2\r\n REAL :: f_gasconstant_jkgk\r\n REAL :: f_airt_k\r\n REAL :: f_alapse_km\r\n REAL :: f_ccoef_khpa\r\n\r\nc REAL :: f_numer\r\nc REAL :: f_denom1\r\nc REAL :: f_denom2\r\nc REAL :: f_denom3\r\nc************************************************************************\r\n f_grav_ms2 =9.80665\r\n f_gasconstant_jkgk =287.05\r\n f_airt_k =273.15+f_airt_c\r\n f_alapse_km =0.0065\r\n f_ccoef_khpa =0.12\r\n\r\nc f_numer =f_grav_ms2*f_hght_m/f_gasconstant_jkgk\r\nc f_denom1=f_airt_k\r\nc f_denom2=f_alapse_km*f_hght_m/2.0\r\nc f_denom3=f_e_hpa*f_ccoef_khpa\r\n\r\n f_slpres_hpa=f_p_hpa*\r\n + EXP( \r\n + (f_grav_ms2*f_hght_m/f_gasconstant_jkgk)/\r\n + (f_airt_k+f_alapse_km*f_hght_m/2.0+f_e_hpa*f_ccoef_khpa)\r\n + )\r\n\r\nc print*,'f_numer =',f_numer\r\nc print*,'f_denom1=',f_denom1\r\nc print*,'f_denom2=',f_denom2\r\nc print*,'f_denom3=',f_denom3\r\nc print*,'f_p_hpa=',f_p_hpa\r\nc call sleep(5)\r\n\r\nc print*,'just leaving slpres_from_stnpres_dwdday'\r\nc************************************************************************\r\n RETURN\r\n END", "meta": {"hexsha": "889994aa828320e3e7770e24781bb226356fbef8", "size": 1994, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "P20170927_dwdday/Subroutine/slpres_from_stnpres_dwdday.f", "max_stars_repo_name": "ajkettle/glamod-nuim", "max_stars_repo_head_hexsha": "beb37a3c2acab3f334918dda3e366c7882cc0960", "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": "P20170927_dwdday/Subroutine/slpres_from_stnpres_dwdday.f", "max_issues_repo_name": "ajkettle/glamod-nuim", "max_issues_repo_head_hexsha": "beb37a3c2acab3f334918dda3e366c7882cc0960", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 23, "max_issues_repo_issues_event_min_datetime": "2022-01-28T13:57:39.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T09:34:41.000Z", "max_forks_repo_path": "P20170927_dwdday/Subroutine/slpres_from_stnpres_dwdday.f", "max_forks_repo_name": "ajkettle/glamod-nuim", "max_forks_repo_head_hexsha": "beb37a3c2acab3f334918dda3e366c7882cc0960", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-01-24T12:06:06.000Z", "max_forks_repo_forks_event_max_datetime": "2019-01-24T12:06:06.000Z", "avg_line_length": 32.6885245902, "max_line_length": 74, "alphanum_fraction": 0.4603811434, "num_tokens": 568, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9648551566309688, "lm_q2_score": 0.7122321903471563, "lm_q1q2_score": 0.6872009015750234}} {"text": "subroutine pressure\n\n use m_parameters\n use m_fields\n use m_work\n use x_fftw\n\n implicit none\n\n integer :: i, j, k, n\n real*8 :: div1, div2, lapl1, lapl2, p1, p2\n\n ! pressure poisson equation\n do k = 1, nz\n do j = 1, ny\n do i = 1, nx + 1, 2\n\n ! getting the divergence (i*k*\\hat(u))\n ! remember that in the Fourier space indicies go as (ix,iz,iy)\n\n ! getting divergence\n div2 = akx(i)*fields(i, j, k, 1) + aky(k)*fields(i, j, k, 2) + akz(j)*fields(i, j, k, 3)\n div1 = -(akx(i + 1)*fields(i + 1, j, k, 1) + aky(k)*fields(i + 1, j, k, 2) + akz(j)*fields(i + 1, j, k, 3))\n\n ! inverse laplace operator\n lapl1 = akx(i)**2 + aky(k)**2 + akz(j)**2\n lapl2 = akx(i + 1)**2 + aky(k)**2 + akz(j)**2\n\n if (lapl1 .eq. 0.d0) lapl1 = 9e20\n if (lapl2 .eq. 0.d0) lapl2 = 9e20\n\n ! calculating pressure\n p1 = -div1/lapl1\n p2 = -div2/lapl2\n\n ! Taking derivatives of the pressure and subtracting from the corresponding velocities\n fields(i, j, k, 1) = fields(i, j, k, 1) + p2*akx(i + 1)\n fields(i + 1, j, k, 1) = fields(i + 1, j, k, 1) - p1*akx(i)\n\n fields(i, j, k, 2) = fields(i, j, k, 2) + p2*aky(k)\n fields(i + 1, j, k, 2) = fields(i + 1, j, k, 2) - p1*aky(k)\n\n fields(i, j, k, 3) = fields(i, j, k, 3) + p2*akz(j)\n fields(i + 1, j, k, 3) = fields(i + 1, j, k, 3) - p1*akz(j)\n\n ! store the pressures in a new array dedicated to the pressures\n pressure_field(i, j, k, 1) = p2 + akx(i + 1)\n pressure_field(i + 1, j, k, 1) = -p1 + akx(i)\n\n pressure_field(i, j, k, 2) = p2 + aky(k)\n pressure_field(i + 1, j, k, 2) = -p1 + aky(k)\n\n pressure_field(i, j, k, 3) = p2 + akz(j)\n pressure_field(i + 1, j, k, 3) = -p1 + akz(j)\n\n end do\n end do\n end do\n\n return\nend subroutine pressure\n\nsubroutine divergence\n\n use m_openmpi\n use m_parameters\n use m_fields\n use m_work\n use x_fftw\n\n implicit none\n\n integer :: i, j, k\n real*8 :: dmin, dmax, d1\n\n wrk(:, :, :, 1:3) = fields(:, :, :, 1:3)\n\n call x_derivative(1, 'x', 4)\n call x_derivative(2, 'y', 5)\n call x_derivative(3, 'z', 6)\n\n call xFFT3d(-1, 4)\n call xFFT3d(-1, 5)\n call xFFT3d(-1, 6)\n\n wrk(:, :, :, 0) = wrk(:, :, :, 4) + wrk(:, :, :, 5) + wrk(:, :, :, 6)\n\n d1 = minval(wrk(1:nx, :, :, 0))\n call MPI_REDUCE(d1, dmin, 1, MPI_REAL8, MPI_MIN, 0, MPI_COMM_TASK, mpi_err)\n d1 = maxval(wrk(1:nx, :, :, 0))\n call MPI_REDUCE(d1, dmax, 1, MPI_REAL8, MPI_MAX, 0, MPI_COMM_TASK, mpi_err)\n\n if (myid .eq. 0) then\n write (out, *) 'divergence:', dmin, dmax\n!!$ print *, 'divergence:',dmin,dmax\n call flush (out)\n end if\n\n return\nend subroutine divergence\n", "meta": {"hexsha": "03ae04531ce2cc0ee011e96f79b5d31c39ff6344", "size": 3023, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/pressure.f90", "max_stars_repo_name": "Fluid-Dynamics-Group/hit3d", "max_stars_repo_head_hexsha": "6ce4d111479ba18a2be7764791281e58823dbc19", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pressure.f90", "max_issues_repo_name": "Fluid-Dynamics-Group/hit3d", "max_issues_repo_head_hexsha": "6ce4d111479ba18a2be7764791281e58823dbc19", "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/pressure.f90", "max_forks_repo_name": "Fluid-Dynamics-Group/hit3d", "max_forks_repo_head_hexsha": "6ce4d111479ba18a2be7764791281e58823dbc19", "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": 29.9306930693, "max_line_length": 123, "alphanum_fraction": 0.4809791598, "num_tokens": 1114, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088045171238, "lm_q2_score": 0.7401743505760728, "lm_q1q2_score": 0.6871843839525703}} {"text": "PROGRAM Triangle\nIMPLICIT NONE\nREAL :: a, b, c, Area\nPRINT *, 'Welcome, please enter the&\n &lengths of the 3 sides.'\nREAD *, a, b, c\nPRINT *, 'Triangle''s area: ', Area(a,b,c)\nEND PROGRAM Triangle\nFUNCTION Area(x,y,z)\nIMPLICIT NONE\nREAL :: Area ! function type\nREAL, INTENT( IN ) :: x, y, z\nREAL :: theta, height\ntheta = ACOS((x**2+y**2-z**2)/(2.0*x*y))\nheight = x*SIN(theta); Area = 0.5*y*height\nEND FUNCTION Area", "meta": {"hexsha": "ad7ab345a87fae72c94dbf93ca303901f03a073b", "size": 435, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "demo-scripts/fortran.f90", "max_stars_repo_name": "trallard/Pitaya-milkshake", "max_stars_repo_head_hexsha": "c1bf1a3a1885f17dbf7c1802850e8c09595b2727", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2020-01-03T16:21:43.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-15T19:10:52.000Z", "max_issues_repo_path": "demo-scripts/fortran.f90", "max_issues_repo_name": "trallard/Pitaya-milkshake", "max_issues_repo_head_hexsha": "c1bf1a3a1885f17dbf7c1802850e8c09595b2727", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2020-01-07T16:07:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-14T20:30:48.000Z", "max_forks_repo_path": "demo-scripts/fortran.f90", "max_forks_repo_name": "trallard/Pitaya-milkshake", "max_forks_repo_head_hexsha": "c1bf1a3a1885f17dbf7c1802850e8c09595b2727", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-08T01:21:08.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-16T03:08:49.000Z", "avg_line_length": 27.1875, "max_line_length": 43, "alphanum_fraction": 0.6229885057, "num_tokens": 142, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087965937711, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6871843834090566}} {"text": " Program ztrsen_example\n\n! ZTRSEN Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use blas_interfaces, Only: zgemm\n Use lapack_example_aux, Only: nagf_file_print_matrix_complex_gen_comp\n Use lapack_interfaces, Only: zlange, ztrsen\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nin = 5, nout = 6\n! .. Local Scalars ..\n Complex (Kind=dp) :: alpha, beta\n Real (Kind=dp) :: norm, s, sep\n Integer :: i, ifail, info, lda, ldc, ldq, ldt, lwork, m, n\n! .. Local Arrays ..\n Complex (Kind=dp), Allocatable :: a(:, :), c(:, :), q(:, :), t(:, :), &\n w(:), work(:)\n Real (Kind=dp) :: rwork(1)\n Logical, Allocatable :: select(:)\n Character (1) :: clabs(1), rlabs(1)\n! .. Intrinsic Procedures ..\n Intrinsic :: cmplx, epsilon\n! .. Executable Statements ..\n Write (nout, *) 'ZTRSEN Example Program Results'\n Write (nout, *)\n Flush (nout)\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n\n ldc = n\n lda = n\n ldq = n\n ldt = n\n lwork = (n*n)/2\n Allocate (a(lda,n), c(ldc,n), q(ldq,n), t(ldt,n), w(n), work(lwork), &\n select(n))\n\n! Read T, Q and the logical array SELECT from data file\n\n Read (nin, *)(t(i,1:n), i=1, n)\n Read (nin, *)\n Read (nin, *)(q(i,1:n), i=1, n)\n Read (nin, *)\n Read (nin, *) select(1:n)\n\n! Compute Q * T * Q**T to find A\n alpha = cmplx(1, kind=dp)\n beta = cmplx(0, kind=dp)\n Call zgemm('N', 'N', n, n, n, alpha, q, ldq, t, ldt, beta, c, ldc)\n Call zgemm('N', 'C', n, n, n, alpha, c, ldc, q, ldq, beta, a, lda)\n\n! Print Matrix A, as computed from Q * T * Q**T\n! ifail: behaviour on error exit\n! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft\n ifail = 0\n Call nagf_file_print_matrix_complex_gen_comp('General', ' ', n, n, a, &\n lda, 'Bracketed', 'F7.4', 'Matrix A created from Q*T*Q^T', 'Integer', &\n rlabs, 'Integer', clabs, 80, 0, ifail)\n\n Write (nout, *)\n Flush (nout)\n\n! Reorder the Schur factor T and update the matrix Q to obtain TT and QT\n\n Call ztrsen('Both', 'Vectors', select, n, t, ldt, q, ldq, w, m, s, sep, &\n work, lwork, info)\n\n! Compute (Q * T * Q^H) - (QT * TT * QT^H) and store in A,\n! i.e. the difference between reconstructed A using Schur and reordered\n! Schur decompositions.\n alpha = cmplx(1, kind=dp)\n beta = cmplx(0, kind=dp)\n Call zgemm('N', 'N', n, n, n, alpha, q, ldq, t, ldt, beta, c, ldc)\n alpha = cmplx(-1, kind=dp)\n beta = cmplx(1, kind=dp)\n Call zgemm('N', 'C', n, n, n, alpha, c, ldc, q, ldq, beta, a, lda)\n\n! Find norm of difference matrix and print warning if it is too large\n norm = zlange('O', lda, n, a, lda, rwork)\n If (norm>epsilon(1.0E0_dp)**0.5_dp) Then\n Write (nout, *) 'Norm of A - (QT * TT * QT^H) is much greater than 0.'\n Write (nout, *) 'Schur factorization has failed.'\n Else\n! Print condition estimates\n Write (nout, 100) 'Condition number estimate', &\n ' of the selected cluster of eigenvalues = ', 1.0_dp/s\n Write (nout, *)\n Write (nout, 100) 'Condition number estimate of the specified ', &\n 'invariant subspace = ', 1.0_dp/sep\n End If\n\n100 Format (1X, A, A, 1P, E10.2)\n End Program\n", "meta": {"hexsha": "66ba40ddc3a2c28e95978c12d2047677494eb6c9", "size": 3646, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/ztrsen_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/ztrsen_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/ztrsen_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 36.099009901, "max_line_length": 90, "alphanum_fraction": 0.5584201865, "num_tokens": 1199, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004185, "lm_q2_score": 0.7718435030872967, "lm_q1q2_score": 0.6871678097750484}} {"text": "! This source file is part of GAME-DA, which is released under the MIT license.\n! Github repository: https://github.com/OpenNWP/GAME-DA\n\n! This module contains linear algebra functions.\n\nmodule lin_algebra\n\n use iso_c_binding\n\n implicit none\n\n ! precision of doubles\n integer, parameter :: wp = c_double\n \n contains\n \n subroutine gauss(to_be_inverted, inv, matrix_size) &\n bind(c, name = \"gauss\")\n\n ! This subroutine computes the inverse inv of the matrix to_be_inverted, using the Gauss scheme.\n ! CAUTION: in the process, to_be_inverted will be modified.\n \n real(wp), intent(inout) :: to_be_inverted(matrix_size,matrix_size)\n real(wp), intent(inout) :: inv (matrix_size,matrix_size)\n integer, intent(in) :: matrix_size\n\n ! local variables\n integer :: permute_index_found, permute_index_counter\n real(wp) :: factor\n ! loop indices\n integer :: i, j, k\n\n ! firstly, the inverse is initialized with the unity matrix\n !$omp parallel\n !$omp do private(i)\n do i = 1,matrix_size\n inv(i,i) = 1._wp\n enddo\n !$omp end do\n !$omp end parallel\n\n ! Gaussian downwards\n ! ------------------\n ! we will start to modify to_be_inverted now (misuse of name)\n do i = 1,matrix_size-1\n ! checking if a permutation is necessary\n ! Firstly, the permutation index has to be found.\n permute_index_found = 0\n permute_index_counter = i\n do while (permute_index_found == 0)\n if (to_be_inverted(permute_index_counter,i) /= 0._wp) then\n permute_index_found = 1\n else\n permute_index_counter = permute_index_counter + 1\n endif\n enddo\n ! actually performing the permutation\n if (permute_index_counter > i) then\n call permute_lines(to_be_inverted, i, permute_index_counter, matrix_size)\n call permute_lines(inv, i, permute_index_counter, matrix_size)\n endif\n\n ! permutation is done, now comes the actual calculation\n ! dividing the line by to_be_inverted(i,i)\n factor = 1._wp/to_be_inverted(i,i)\n !$omp parallel\n !$omp do private(j)\n do j=i,matrix_size\n to_be_inverted(i,j) = factor*to_be_inverted(i,j)\n enddo\n !$omp end do\n !$omp end parallel\n inv(i,:) = factor*inv(i,:)\n ! loop over all the lines that are below the current line\n !$omp parallel\n !$omp do private(factor,j,k)\n do j=i+1,matrix_size\n factor = -to_be_inverted(j,i)\n do k=i,matrix_size\n to_be_inverted(j,k) = to_be_inverted(j,k) + factor*to_be_inverted(i,k)\n enddo\n inv(j,:) = inv(j,:) + factor*inv(i,:)\n enddo\n !$omp end do\n !$omp end parallel\n enddo\n \n inv(matrix_size,:) = inv(matrix_size,:)/to_be_inverted(matrix_size,matrix_size)\n to_be_inverted(matrix_size,matrix_size) = 1._wp\n\n ! Gaussian upwards\n ! ----------------\n do i = matrix_size,2,-1\n !$omp parallel\n !$omp do private(j)\n do j = i-1,1,-1\n inv(j,:) = inv(j,:) - to_be_inverted(j,i)*inv(i,:)\n enddo\n !$omp end do\n !$omp end parallel\n enddo\n \n end subroutine gauss\n\n subroutine permute_lines(matrix, line_a, line_b, matrix_size)\n\n ! This subroutine permutes line_a with line_b of matrix.\n\n ! arguments\n real(wp), intent(inout) :: matrix(matrix_size,matrix_size)\n integer, intent(in) :: line_a\n integer, intent(in) :: line_b\n integer, intent(in) :: matrix_size\n\n ! local variables\n real(wp) :: line_a_pre(matrix_size)\n\n line_a_pre(:) = matrix(line_a,:)\n matrix(line_a,:) = matrix(line_b,:)\n matrix(line_b,:) = line_a_pre(:)\n\n end subroutine permute_lines\n\nend module lin_algebra\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "7cf01a2703cdc4bcb5fdd6f772c6e73e2c998601", "size": 3778, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/lin_algebra.f90", "max_stars_repo_name": "OpenNWP/GAME-DA", "max_stars_repo_head_hexsha": "6e6ed822cc4a8166e265f34d059cfdbbfd48dfc2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-08-01T16:28:33.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-01T16:28:33.000Z", "max_issues_repo_path": "src/lin_algebra.f90", "max_issues_repo_name": "OpenNWP/ndvar", "max_issues_repo_head_hexsha": "6e6ed822cc4a8166e265f34d059cfdbbfd48dfc2", "max_issues_repo_licenses": ["MIT"], "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/lin_algebra.f90", "max_forks_repo_name": "OpenNWP/ndvar", "max_forks_repo_head_hexsha": "6e6ed822cc4a8166e265f34d059cfdbbfd48dfc2", "max_forks_repo_licenses": ["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.4060150376, "max_line_length": 100, "alphanum_fraction": 0.6265219693, "num_tokens": 1000, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436395, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6871678094168693}} {"text": " Program dbdsdc_example\n\n! DBDSDC Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_interfaces, Only: dbdsdc\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nin = 5, nout = 6\n! .. Local Scalars ..\n Integer :: info, ldb, ldu, ldvt, n\n! .. Local Arrays ..\n Real (Kind=dp), Allocatable :: b(:, :), d(:), e(:), u(:, :), vt(:, :), &\n work(:)\n Real (Kind=dp) :: q(1)\n Integer :: iq(1)\n Integer, Allocatable :: iwork(:)\n! .. Executable Statements ..\n Write (nout, *) 'DBDSDC Example Program Results'\n Write (nout, *)\n Flush (nout)\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n\n ldb = n\n ldu = n\n ldvt = n\n Allocate (b(ldb,n), d(n), e(n-1), u(ldu,n), vt(ldvt,n), work(n*(3*n+ &\n 4)), iwork(8*n))\n\n! Read the bidiagonal matrix B from data file, first\n! the diagonal elements, and then the off diagonal elements\n\n Read (nin, *) d(1:n)\n Read (nin, *) e(1:n-1)\n\n! Calculate the singular values and left and right singular\n! vectors of B.\n\n Call dbdsdc('Upper', 'I', n, d, e, u, ldu, vt, ldvt, q, iq, work, iwork, &\n info)\n\n If (info==0) Then\n! Print the singular values of B.\n\n Write (nout, *) 'Singular values of B:'\n Write (nout, 100) d(1:n)\n Else\n Write (nout, 110) '** DBDSDC failed with INFO = ', info\n End If\n\n100 Format (1X, 4(3X,F11.4))\n110 Format (1X, A, I10)\n End Program\n", "meta": {"hexsha": "bbda69e8dfcb1c63ee7be76d86d13d6e316ca0a6", "size": 1768, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/dbdsdc_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/dbdsdc_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/dbdsdc_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 28.9836065574, "max_line_length": 90, "alphanum_fraction": 0.5531674208, "num_tokens": 550, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.7718434978390746, "lm_q1q2_score": 0.6871678051025867}} {"text": "subroutine SHReturnTapersM(theta0, lmax, m, tapers, eigenvalues, shannon, &\n degrees, ntapers, exitstatus)\n!------------------------------------------------------------------------------\n!\n! This subroutine will return all the eigenvalues and eigenfunctions for the\n! space-concentration problem of a spherical cap of angular radius theta0.\n! The returned eigenfunctions correspond to \"geodesy\" normalized spherical\n! harmonic coefficients, and the eigenfunctions are further normalized such\n! that they have unit power (i.e., the integral of the function squared over\n! the sphere divided by 4 pi is 1, and the sum of the squares of their\n! coefficients is 1). If the optional vector DEGREES is specified, then the\n! eigenfunctions will be computed using only those degrees where DEGREES(l+1)\n! is not zero.\n!\n! When possible, the eigenfunctions are calculated using the kernel of\n! Grunbaum et al. 1982 and the eigenvalues are then calculated by integration\n! using the definition of the space-concentration problem. Use of the\n! Grunbaum et al. kernel is prefered over the space-concentration kernel as\n! the eigenfunctions of the later are unreliable when there are several\n! eigenvalues identical (within machine precision) to either 1 or zero. If,\n! the optional parameter DEGREES is specified, and at least one element is\n! zero for degrees greater or equal to abs(m), then the eigenfunctions and\n! eigenvalues will instead be computed directly using the space-concentration\n! kernel.\n!\n! Calling Parameters\n!\n! IN\n! theta0 Angular radius of spherical cap in RADIANS.\n! lmax Maximum spherical harmonic degree\n! for the concentration problem.\n! m Angular order of the concentration\n! problem (m=0 corresponds to isotropic case).\n!\n! OUT\n! tapers An (lmax+1) by (lmax+1-abs(m)) array containing\n! all the eigenfunctions of the space-\n! concentration kernel. Eigenfunctions\n! are listed by columns in decreasing order\n! corresponding to value of their eigenvalue.\n! Only the first ntapers columns are non-zero.\n! eigenvalues A vector of length lmax+1-abs(m) containing the\n! eigenvalued corresponding to the individual\n! eigenfunctions.\n!\n! OPTIONAL (IN)\n! degrees Specify those degrees of the coupling matrix to\n! compute. If degrees(l+1) is zero, degree l will not\n! be computed.\n!\n! OPTIONAL (OUT)\n! shannon Shannon number as calculated from the trace of the\n! kernel.\n! ntapers The number of non-zero tapers.\n! exitstatus If present, instead of executing a STOP when an error\n! is encountered, the variable exitstatus will be\n! returned describing the error.\n! 0 = No errors;\n! 1 = Improper dimensions of input array;\n! 2 = Improper bounds for input variable;\n! 3 = Error allocating memory;\n! 4 = File IO error.\n!\n! Copyright (c) 2005-2019, SHTOOLS\n! All rights reserved.\n!\n!------------------------------------------------------------------------------\n use SHTOOLS, only: ComputeDG82, ComputeDm, EigValVecSymTri, EigValVecSym, &\n PreGLQ, PlmBar, PlmIndex\n use ftypes\n\n implicit none\n\n real(dp), intent(in) :: theta0\n integer, intent(in) :: lmax, m\n real(dp), intent(out) :: tapers(:,:), eigenvalues(:)\n real(dp), intent(out), optional :: shannon\n integer, intent(in), optional :: degrees(:)\n integer, intent(out), optional :: ntapers\n integer, intent(out), optional :: exitstatus\n integer :: l, n, n_int, j, i, astat(3), ind(lmax+1), use_dg82\n real(dp) :: eval(lmax+1), pi, upper, lower, zero(lmax+1), w(lmax+1), h\n real(dp), allocatable :: evec(:,:), dllmtri(:,:), p(:), dllm(:,:)\n\n use_dg82 = 1\n\n if (present(exitstatus)) exitstatus = 0\n\n if (size(tapers(:,1)) < (lmax+1) .or. &\n size(tapers(1,:)) < (lmax+1-abs(m)) ) then\n print*, \"Error --- SHReturnTapersM\"\n print*, \"TAPERS must be dimensioned as (LMAX+1, LMAX+1-ABS(M)) \" // &\n \"where LMAX is \", lmax\n print*, \"Input array is dimensioned as \", size(tapers(:,1)), &\n size(tapers(1,:))\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n else if(size(eigenvalues) < (lmax+1-abs(m)) ) then\n print*, \"Error --- SHReturnTapersM\"\n print*, \"EIGENVALUES must be dimensioned as (LMAX+1-ABS(m)) \" // &\n \"where LMAX is \", lmax\n print*, \"Input array is dimensioned as \", size(eigenvalues)\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n else if (m > lmax) then\n print*, \"Error --- SHReturnTapersM\"\n print*, \"M must be less than or equal to LMAX.\"\n print*, \"M = \", m\n print*, \"LMAX = \", lmax\n if (present(exitstatus)) then\n exitstatus = 2\n return\n else\n stop\n end if\n\n end if\n\n if (present(degrees)) then\n if (size(degrees) < lmax+1) then\n print*, \"Error --- SHReturnTapersM\"\n print*, \"DEGREES must have dimension LMAX+1, where LMAX is \", lmax\n print*, \"Input array is dimensioned as \", size(degrees)\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n end if\n end if\n\n if (present(degrees)) then\n if (sum(degrees(1+abs(m):lmax+1)) /= lmax + 1 - abs(m)) use_dg82 = 0\n end if\n\n allocate (evec(lmax+1, lmax+1-abs(m)), stat = astat(1))\n allocate (dllmtri(lmax+1, lmax+1), stat = astat(2))\n allocate (p((lmax+1)*(lmax+2)/2), stat = astat(3))\n\n if (astat(1) /= 0 .or. astat(2) /= 0 .or. astat(3) /= 0) then\n print*, \"Error --- SHReturnTapersM\"\n print*, \"Problem allocating arrays EVEC, DLLMTRI, and P\", &\n astat(1), astat(2), astat(3)\n if (present(exitstatus)) then\n exitstatus = 3\n return\n else\n stop\n end if\n\n end if\n\n pi = acos(-1.0_dp)\n\n tapers = 0.0_dp\n eigenvalues = 0.0_dp\n eval = 0.0_dp\n evec = 0.0_dp\n\n if (use_dg82 == 1) then\n !----------------------------------------------------------------------\n !\n ! Calculate space-concentration kernel and the corresponding\n ! eigenfunctions of the Grunbaum et al. kernel.\n !\n !----------------------------------------------------------------------\n n = lmax + 1 - abs(m)\n\n if (present(exitstatus)) then\n call ComputeDG82(dllmtri(1:n,1:n), lmax, m, theta0, &\n exitstatus = exitstatus)\n if (exitstatus /= 0) return\n call EigValVecSymTri(dllmtri(1:n,1:n), n, eval(1:n), &\n tapers(1+abs(m):lmax+1,1:n), &\n exitstatus = exitstatus)\n if (exitstatus /= 0) return\n else\n call ComputeDG82(dllmtri(1:n,1:n), lmax, m, theta0)\n call EigValVecSymTri(dllmtri(1:n,1:n), n, eval(1:n), &\n tapers(1+abs(m):lmax+1,1:n))\n end if\n\n !----------------------------------------------------------------------\n !\n ! Calculate true eigenvalues\n !\n !----------------------------------------------------------------------\n upper = 1.0_dp\n lower = cos(theta0)\n n_int = lmax + 1\n\n if (present(exitstatus)) then\n call PreGLQ(lower, upper, n_int, zero, w, exitstatus = exitstatus)\n if (exitstatus /= 0) return\n else\n call PreGLQ(lower, upper, n_int, zero, w)\n end if\n\n do i=1, n_int\n if (present(exitstatus)) then\n call PlmBar(p, lmax, zero(i), exitstatus = exitstatus)\n if (exitstatus /= 0) return\n else\n call PlmBar(p, lmax, zero(i))\n end if\n\n do j = 1, n\n h = 0.0_dp\n\n do l = abs(m), lmax\n h = h + p(PlmIndex(l, abs(m))) * tapers(l+1, j)\n\n end do\n\n eigenvalues(j) = eigenvalues(j) + w(i) * h**2\n\n end do\n end do\n\n if (m == 0) then\n eigenvalues(1:n) = eigenvalues(1:n) / 2.0_dp\n\n else\n eigenvalues(1:n) = eigenvalues(1:n) / 4.0_dp\n\n end if\n\n else\n !----------------------------------------------------------------------\n !\n ! Calculate space-concentration kernel and the corresponding\n ! eigenfunctions.\n !\n !----------------------------------------------------------------------\n ind = 0\n i = 0\n\n do l=abs(m), lmax, 1\n if (degrees(l+1) /= 0) then\n i = i + 1\n ind(i) = l + 1\n end if\n end do\n\n n = i\n\n if (n /= 0) then\n\n allocate (dllm(n, n), stat = astat(1))\n if (astat(1) /= 0) then\n print*, \"Error --- SHReturnTapersM\"\n print*, \"Problem allocating array DLLM \", astat(1)\n if (present(exitstatus)) then\n exitstatus = 3\n return\n else\n stop\n end if\n end if\n\n dllm = 0.0_dp\n\n if (present(exitstatus)) then\n call ComputeDm(dllmtri, lmax, m, theta0, degrees=degrees, &\n exitstatus=exitstatus)\n if (exitstatus /= 0) return\n else\n call ComputeDm(dllmtri, lmax, m, theta0, degrees=degrees)\n end if\n\n do i=1, n\n do j=1, n\n dllm(i, j) = dllmtri(ind(i), ind(j))\n end do\n end do\n\n if (present(exitstatus)) then\n call EigValVecSym(dllm(1:n, 1:n), n, &\n eval(1:n), evec(1:n,1:n), &\n exitstatus = exitstatus)\n if (exitstatus /= 0) return\n else\n call EigValVecSym(dllm, n, eval(1:n),&\n evec(1:n,1:n))\n end if\n\n do i=1, n\n tapers(ind(i), 1:n) = evec(i, 1:n)\n end do\n\n eigenvalues(1:n) = eval(1:n)\n\n end if\n\n end if\n\n if (present(shannon)) then\n shannon = sum(eigenvalues(1:lmax+1-abs(m)))\n end if\n\n if (present(ntapers)) then\n ntapers = n\n end if\n\n ! deallocate memory\n call PlmBar (p, -1, zero(1))\n deallocate (evec)\n deallocate (dllmtri)\n deallocate (p)\n if (use_dg82 == 0 .and. n /= 0) deallocate (dllm)\n\nend subroutine SHReturnTapersM\n", "meta": {"hexsha": "471f07fc6f018cd6e37d23047ed84292d3ba6d58", "size": 11372, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/SHReturnTapersM.f95", "max_stars_repo_name": "dilkins/SHTOOLS", "max_stars_repo_head_hexsha": "7bb13a0f7e05bdc66ab534dcd6a8d01e74bda886", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-01-28T13:35:22.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-28T13:35:22.000Z", "max_issues_repo_path": "src/SHReturnTapersM.f95", "max_issues_repo_name": "dilkins/SHTOOLS", "max_issues_repo_head_hexsha": "7bb13a0f7e05bdc66ab534dcd6a8d01e74bda886", "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/SHReturnTapersM.f95", "max_forks_repo_name": "dilkins/SHTOOLS", "max_forks_repo_head_hexsha": "7bb13a0f7e05bdc66ab534dcd6a8d01e74bda886", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.0987654321, "max_line_length": 79, "alphanum_fraction": 0.4900633134, "num_tokens": 2883, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.7718434873426302, "lm_q1q2_score": 0.6871678002510352}} {"text": "!\n! file hwsplr.f90\n!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 2005 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Fishpack *\n! * *\n! * A Package of Fortran *\n! * *\n! * Subroutines and Example Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams, Paul Swarztrauber and Roland Sweet *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\n! SUBROUTINE hwsplr(a, b, m, mbdcnd, bda, bdb, c, d, n, nbdcnd, bdc, bdd,\n! elmbda, f, idimf, pertrb, ierror)\n!\n!\n! DIMENSION OF bda(n), bdb(n), bdc(m), bdd(m), f(idimf, n+1)\n! ARGUMENTS\n!\n! LATEST REVISION May 2016\n!\n! PURPOSE Solves a finite difference approximation to\n! the helmholtz equation in polar coordinates.\n! the equation is\n!\n! (1/r)(d/dr)(r(du/dr)) +\n! (1/r**2)(d/dtheta)(du/dtheta) +\n! lambda*u = f(r, theta).\n!\n! USAGE call hwsplr(a, b, m, mbdcnd, bda, bdb, c, d, n,\n! nbdcnd, bdc, bdd, elmbda, f, idimf,\n! pertrb, ierror, w)\n!\n! ARGUMENTS\n! ON INPUT a, b\n! the range of r, i.e., a <= r <= b.\n! a must be less than b and a must be\n! non-negative.\n!\n! m\n! the number of panels into which the\n! interval (a, b) is subdivided. hence,\n! there will be m+1 grid points in the\n! r-direction given by r(i) = a+(i-1)dr,\n! for i = 1, 2, ..., m+1,\n! where dr = (b-a)/m is the panel width.\n! m must be greater than 3.\n!\n! mbdcnd\n! indicates the type of boundary condition\n! at r = a and r = b.\n!\n! = 1 if the solution is specified at\n! r = a and r = b.\n! = 2 if the solution is specified at\n! r = a and the derivative of\n! the solution with respect to r is\n! specified at r = b.\n! = 3 if the derivative of the solution\n! with respect to r is specified at\n! r = a (see note below) and r = b.\n! = 4 if the derivative of the solution\n! with respect to r is specified at\n! r = a (see note below) and the\n! solution is specified at r = b.\n! = 5 if the solution is unspecified at\n! r = a = 0 and the solution is\n! specified at r = b.\n! = 6 if the solution is unspecified at\n! r = a = 0 and the derivative of the\n! solution with respect to r is specified\n! at r = b.\n!\n! note:\n! if a = 0, do not use mbdcnd = 3 or 4, but\n! instead use mbdcnd = 1, 2, 5, or 6 .\n!\n! bda\n! a one-dimensional array of length n+1 that\n! specifies the values of the derivative of\n! the solution with respect to r at r = a.\n!\n! when mbdcnd = 3 or 4,\n! bda(j) = (d/dr)u(a, theta(j)),\n! j = 1, 2, ..., n+1 .\n!\n! when mbdcnd has any other value, bda is\n! a dummy variable.\n!\n! bdb\n! a one-dimensional array of length n+1 that\n! specifies the values of the derivative of\n! the solution with respect to r at r = b.\n!\n! when mbdcnd = 2, 3, or 6,\n! bdb(j) = (d/dr)u(b, theta(j)),\n! j = 1, 2, ..., n+1 .\n!\n! when mbdcnd has any other value, bdb is\n! a dummy variable.\n!\n! c, d\n! the range of theta, i.e., c <=\n! theta <= d. c must be less than d.\n!\n! n\n! the number of panels into which the\n! interval (c, d) is subdivided. hence,\n! there will be n+1 grid points in the\n! theta-direction given by\n! theta(j) = c+(j-1)dtheta for\n! j = 1, 2, ..., n+1, where\n! dtheta = (d-c)/n is the panel width.\n! n must be greater than 3.\n!\n! nbdcnd\n! indicates the type of boundary conditions\n! at theta = c and at theta = d.\n!\n! = 0 if the solution is periodic in theta,\n! i.e., u(i, j) = u(i, n+j).\n! = 1 if the solution is specified at\n! theta = c and theta = d\n! (see note below).\n! = 2 if the solution is specified at\n! theta = c and the derivative of the\n! solution with respect to theta is\n! specified at theta = d\n! (see note below).\n! = 4 if the derivative of the solution\n! with respect to theta is specified\n! at theta = c and the solution is\n! specified at theta = d\n! (see note below).\n!\n! note:\n! when nbdcnd = 1, 2, or 4, do not use\n! mbdcnd = 5 or 6\n! (the former indicates that the solution\n! is specified at r = 0, the latter indicates\n! the solution is unspecified at r = 0).\n! use instead mbdcnd = 1 or 2 .\n!\n! bdc\n! a one-dimensional array of length m+1 that\n! specifies the values of the derivative\n! of the solution with respect to theta at\n! theta = c. when nbdcnd = 3 or 4,\n!\n! bdc(i) = (d/dtheta)u(r(i), c),\n! i = 1, 2, ..., m+1 .\n!\n! when nbdcnd has any other value, bdc is\n! a dummy variable.\n!\n! bdd\n! a one-dimensional array of length m+1 that\n! specifies the values of the derivative\n! of the solution with respect to theta at\n! theta = d. when nbdcnd = 2 or 3,\n!\n! bdd(i) = (d/dtheta)u(r(i), d),\n! i = 1, 2, ..., m+1 .\n!\n! when nbdcnd has any other value, bdd is\n! a dummy variable.\n!\n! elmbda\n! the constant lambda in the helmholtz\n! equation. if lambda < 0, a solution\n! may not exist. however, hwsplr will\n! attempt to find a solution.\n!\n! f\n! a two-dimensional array, of dimension at\n! least (m+1)*(n+1), specifying values\n! of the right side of the helmholtz\n! equation and boundary data (if any).\n!\n! on the interior, f is defined as follows:\n! for i = 2, 3, ..., m and j = 2, 3, ..., n\n! f(i, j) = f(r(i), theta(j)).\n!\n! on the boundaries f is defined as follows:\n! for j = 1, 2, ..., n+1 and i = 1, 2, ..., m+1\n!\n! mbdcnd f(1, j) f(m+1, j)\n! ------ ------------- -------------\n!\n! 1 u(a, theta(j)) u(b, theta(j))\n! 2 u(a, theta(j)) f(b, theta(j))\n! 3 f(a, theta(j)) f(b, theta(j))\n! 4 f(a, theta(j)) u(b, theta(j))\n! 5 f(0, 0) u(b, theta(j))\n! 6 f(0, 0) f(b, theta(j))\n!\n! nbdcnd f(i, 1) f(i, n+1)\n! ------ --------- ---------\n!\n! 0 f(r(i), c) f(r(i), c)\n! 1 u(r(i), c) u(r(i), d)\n! 2 u(r(i), c) f(r(i), d)\n! 3 f(r(i), c) f(r(i), d)\n! 4 f(r(i), c) u(r(i), d)\n!\n! note:\n! if the table calls for both the solution\n! u and the right side f at a corner then\n! then the solution must be specified.\n!\n! idimf\n! the row (or first) dimension of the array\n! f as it appears in the program calling\n! hwsplr. this parameter is used to specify\n! the variable dimension of f. idimf must\n! be at least m+1.\n!\n! ON OUTPUT f\n! contains the solution u(i, j) of the finite\n! difference approximation for the grid point\n! (r(i), theta(j)),\n! i = 1, 2, ..., m+1, j = 1, 2, ..., n+1 .\n!\n! pertrb\n! if a combination of periodic, derivative,\n! or unspecified boundary conditions is\n! specified for a poisson equation\n! (lambda = 0), a solution may not exist.\n! pertrb is a constant, calculated and\n! subtracted from f, which ensures that a\n! solution exists. hwsplr then computes\n! this solution, which is a least squares\n! solution to the original approximation.\n! this solution plus any constant is also\n! a solution. hence, the solution is not\n! unique. pertrb should be small compared\n! to the right side. otherwise, a solution\n! is obtained to an essentially different\n! problem. this comparison should always\n! be made to insure that a meaningful\n! solution has been obtained.\n!\n! ierror\n! An error flag that indicates invalid input\n! parameters. Except for numbers 0 and 11,\n! a solution is not attempted.\n!\n! = 0 no error.\n! = 1 a < 0 .\n! = 2 a >= b.\n! = 3 mbdcnd < 1 or mbdcnd > 6 .\n! = 4 c >= d.\n! = 5 n <= 3\n! = 6 nbdcnd < 0 or > 4 .\n! = 7 a = 0, mbdcnd = 3 or 4 .\n! = 8 a > 0, mbdcnd >= 5 .\n! = 9 mbdcnd >= 5, nbdcnd /= 0\n! and nbdcnd /= 3 .\n! = 10 idimf < m+1 .\n! = 11 lambda > 0 .\n! = 12 m <= 3\n! = 20 If the dynamic allocation of real and\n! complex workspace required for solution\n! fails (for example if n, m are too large\n! for your computer)\n!\n! Since this is the only means of indicating\n! a possibly incorrect call to hwsplr, the\n! user should test ierror after the call.\n!\n! SPECIAL CONDITIONS None\n!\n! I/O None\n!\n! PRECISION 64-bit double precision\n!\n! REQUIRED files type_FishpackWorkspace.f90, genbun.f90, type_CyclicReductionUtility.f9090\n!\n! STANDARD Fortran 2008\n!\n! HISTORY * Written by Roland Sweet at NCAR in the late\n! 1970's. Released on NCAR's public software\n! libraries in January 1980.\n! * Revised in June 2004 by John Adams using\n! Fortran 90 dynamically allocated workspace.\n!\n! ALGORITHM The routine defines the finite difference\n! equations, incorporates boundary data, and\n! adjusts the right side of singular systems\n! and then calls genbun to solve the system.\n!\n! TIMING For large m and n, the operation count\n! is roughly proportional to\n!\n! m*n*log2(n)\n!\n! but also depends on input parameters nbdcnd\n! and mbdcnd.\n!\n! ACCURACY The solution process employed results in a loss\n! of no more than three significant digits for n\n! and m as large as 64. More details about\n! accuracy can be found in the documentation for\n! subroutine genbun which is the routine that\n! solves the finite difference equations.\n!\n! REFERENCES Swarztrauber, P. and R. Sweet, \"Efficient\n! FORTRAN subprograms for the solution of\n! elliptic equations\"\n! NCAR TN/IA-109, July, 1975, 138 pp.\n!\nsubmodule (centered_helmholtz_solvers) centered_polar_solver\n\ncontains\n\n module subroutine hwsplr(a, b, m, mbdcnd, bda, bdb, c, d, n, nbdcnd, bdc, &\n bdd, elmbda, f, idimf, pertrb, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: m\n integer(ip), intent(in) :: mbdcnd\n integer(ip), intent(in) :: n\n integer(ip), intent(in) :: nbdcnd\n integer(ip), intent(in) :: idimf\n integer(ip), intent(out) :: ierror\n real(wp), intent(in) :: a\n real(wp), intent(in) :: b\n real(wp), intent(in) :: c\n real(wp), intent(in) :: d\n real(wp), intent(in) :: elmbda\n real(wp), intent(out) :: pertrb\n real(wp), intent(in) :: bda(:)\n real(wp), intent(in) :: bdb(:)\n real(wp), intent(in) :: bdc(:)\n real(wp), intent(in) :: bdd(:)\n real(wp), intent(inout) :: f(:,:)\n\n ! Local variables\n type(FishpackWorkspace) workspace\n\n ! Check input arguments\n call hwsplr_check_input_arguments(a, b, m, mbdcnd, c, d, n, nbdcnd, idimf, ierror)\n\n ! Check error flag\n if (ierror /= 0) return\n\n ! Allocate memory\n call workspace%initialize_centered_workspace(n, m)\n\n ! Solve system\n associate( rew => workspace%real_workspace )\n call hwsplr_lower_routine(a, b, m, mbdcnd, bda, bdb, c, d, n, &\n nbdcnd, bdc, bdd, elmbda, f, idimf, pertrb, ierror, rew)\n end associate\n\n ! Release memory\n call workspace%destroy()\n\n end subroutine hwsplr\n\n pure subroutine hwsplr_check_input_arguments(a, b, m, mbdcnd, c, d, n, nbdcnd, idimf, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: m\n integer(ip), intent(in) :: mbdcnd\n integer(ip), intent(in) :: n\n integer(ip), intent(in) :: nbdcnd\n integer(ip), intent(in) :: idimf\n integer(ip), intent(out) :: ierror\n real(wp), intent(in) :: a\n real(wp), intent(in) :: b\n real(wp), intent(in) :: c\n real(wp), intent(in) :: d\n\n if (a < ZERO) then\n ierror = 1\n else if (a >= b) then\n ierror = 2\n else if (mbdcnd <= 0 .or. mbdcnd >= 7) then\n ierror = 3\n else if (d <= c) then\n ierror = 4\n else if (n <= 3) then\n ierror = 5\n else if (nbdcnd <= -1 .or. 5 <= nbdcnd) then\n ierror = 6\n else if (a == ZERO .and. (mbdcnd==3 .or. mbdcnd==4)) then\n ierror = 7\n else if (a > ZERO .and. 5 <= mbdcnd) then\n ierror = 8\n else if (5 <= mbdcnd .and. nbdcnd /= 0 .and. nbdcnd /= 3) then\n ierror = 9\n else if (idimf < m + 1) then\n ierror = 10\n else if (m <= 3) then\n ierror = 12\n else\n ierror = 0\n end if\n\n end subroutine hwsplr_check_input_arguments\n\n subroutine hwsplr_lower_routine(a, b, m, mbdcnd, bda, bdb, c, d, n, nbdcnd, bdc, &\n bdd, elmbda, f, idimf, pertrb, ierror, w)\n\n ! Dummy arguments\n integer(ip), intent(in) :: m\n integer(ip), intent(in) :: mbdcnd\n integer(ip), intent(in) :: n\n integer(ip), intent(in) :: nbdcnd\n integer(ip), intent(in) :: idimf\n integer(ip), intent(out) :: ierror\n real(wp), intent(in) :: a\n real(wp), intent(in) :: b\n real(wp), intent(in) :: c\n real(wp), intent(in) :: d\n real(wp), intent(in) :: elmbda\n real(wp), intent(out) :: pertrb\n real(wp), intent(in) :: bda(:)\n real(wp), intent(in) :: bdb(:)\n real(wp), intent(in) :: bdc(:)\n real(wp), intent(in) :: bdd(:)\n real(wp), intent(inout) :: f(:,:)\n real(wp), intent(inout) :: w(:)\n\n ! Local variables\n integer(ip) :: mp1, np1, np, mstart, mstop, munk, nstart, nstop, nunk\n integer(ip) :: id2, id3, id4, id5, id6, ij, i\n integer(ip) :: j, l, lp, k, i1, local_error_flag, iip\n real(wp) :: dr, half_dr, dr2, dt, dt2\n real(wp) :: a1, r, s2, a2, s, s1, ypole\n type(CenteredCyclicReductionUtility) :: util\n\n mp1 = m + 1\n dr = (b - a)/m\n half_dr = dr/2\n dr2 = dr**2\n np1 = n + 1\n dt = (d - c)/n\n dt2 = dt**2\n np = nbdcnd + 1\n !\n ! Define range of indices i and j for unknowns u(i, j).\n !\n mstart = 2\n mstop = mp1\n\n select case (mbdcnd)\n case (1)\n mstop = m\n case (3)\n mstart = 1\n case (4)\n mstart = 1\n mstop = m\n case (5)\n mstop = m\n end select\n\n munk = mstop - mstart + 1\n nstart = 1\n nstop = n\n\n select case (np)\n case (2)\n nstart = 2\n case (3)\n nstart = 2\n nstop = np1\n case (4)\n nstop = np1\n end select\n\n nunk = nstop - nstart + 1\n !\n ! Define a, b, c coefficients in w-array.\n !\n id2 = munk\n id3 = id2 + munk\n id4 = id3 + munk\n id5 = id4 + munk\n id6 = id5 + munk\n a1 = TWO/dr2\n ij = 0\n\n if (mbdcnd == 3 .or. mbdcnd == 4) ij = 1\n\n do i = 1, munk\n r = a + real(i - ij, kind=wp)*dr\n j = id5 + i\n w(j) = r\n j = id6 + i\n w(j) = ONE/r**2\n w(i) = (r - half_dr)/(r*dr2)\n j = id3 + i\n w(j) = (r + half_dr)/(r*dr2)\n j = id2 + i\n w(j) = (-a1) + elmbda\n end do\n\n select case (mbdcnd)\n case (2, 6)\n w(id2) = a1\n case (3)\n w(id2) = a1\n w(id3+1) = a1\n case (4)\n w(id3+1) = a1\n end select\n\n select case (mbdcnd)\n case (1:2)\n a1 = w(1)\n f(2, nstart:nstop) = f(2, nstart:nstop) - a1*f(1, nstart:nstop)\n case (3:4)\n a1 = TWO * dr*w(1)\n f(1, nstart:nstop) = f(1, nstart:nstop) + a1*bda(nstart:nstop)\n end select\n\n select case (mbdcnd)\n case (1, 4:5)\n a1 = w(id4)\n f(m, nstart:nstop) = f(m, nstart:nstop) - a1*f(mp1, nstart:nstop)\n case (2:3, 6)\n a1 = TWO * dr*w(id4)\n f(mp1, nstart:nstop) = f(mp1, nstart:nstop) - a1*bdb(nstart:nstop)\n end select\n\n !\n ! Enter boundary data for theta-boundaries.\n !\n a1 = ONE/dt2\n l = id5 - mstart + 1\n lp = id6 - mstart + 1\n\n if (np /= 1) then\n select case (np)\n case (2:3)\n f(mstart:mstop, 2) = f(mstart:mstop, 2) - a1*w(mstart+lp:mstop+lp)*f &\n (mstart:mstop, 1)\n case (4:5)\n a1 = TWO/dt\n f(mstart:mstop, 1) = f(mstart:mstop, 1) + a1*w(mstart+lp:mstop+lp)* &\n bdc(mstart:mstop)\n end select\n\n a1 = ONE/dt2\n\n select case (np)\n case (2, 5)\n f(mstart:mstop, n) = f(mstart:mstop, n) &\n - a1*w(mstart+lp:mstop+lp) * f(mstart:mstop, np1)\n case (3:4)\n a1 = TWO/dt\n f(mstart:mstop, np1) = f(mstart:mstop, np1) &\n - a1 * w(mstart+lp:mstop+lp) * bdd(mstart:mstop)\n end select\n end if\n\n if ((mbdcnd >= 5) .and. (nbdcnd == 3)) then\n f(1, 1) = f(1, 1) - (bdd(2)-bdc(2))* 4.0_wp/(real(n, kind=wp)*dt*dr2)\n end if\n !\n ! adjust right side of singular problems to insure existence of a\n ! solution.\n !\n pertrb = ZERO\n\n if_construct: if (elmbda >= ZERO) then\n if (elmbda /= ZERO) then\n ierror = 11\n return\n else\n if (nbdcnd == 0 .or. nbdcnd == 3) then\n s2 = ZERO\n select case (mbdcnd)\n case (1:2, 4:5)\n exit if_construct\n case (3)\n w(id5+1) = HALF * (w(id5+2)-half_dr)\n s2 = 0.25_wp * dr\n end select\n\n if (nbdcnd == 0) then\n a2 = ONE\n else\n a2 = TWO\n end if\n\n j = id5 + munk\n w(j) = HALF * (w(j-1)+half_dr)\n s = ZERO\n\n do i = mstart, mstop\n s1 = ZERO\n ij = nstart + 1\n k = nstop - 1\n s1 = sum(f(i, ij:k))\n j = i + l\n s = s + (a2*s1 + f(i, nstart)+f(i, nstop))*w(j)\n end do\n\n s2=real(m, kind=wp)*a+dr*(real((m-1)*(m+1), kind=wp)*HALF+0.25_wp)+s2\n s1 = (TWO + a2*real(nunk - 2, kind=wp))*s2\n\n if (mbdcnd /= 3) then\n s2 = (real(n, kind=wp)*a2*dr)/8\n s = s + f(1, 1)*s2\n s1 = s1 + s2\n end if\n\n pertrb = s/s1\n f(mstart:mstop, nstart:nstop) = &\n f(mstart:mstop, nstart:nstop) - pertrb\n end if\n end if\n end if if_construct\n\n\n do i = mstart, mstop\n k = i - mstart + 1\n j = i + lp\n a1 = dt2/w(j)\n w(k) = a1*w(k)\n j = id2 + k\n w(j) = a1*w(j)\n j = id3 + k\n w(j) = a1*w(j)\n f(i, nstart:nstop) = a1*f(i, nstart:nstop)\n end do\n\n w(1) = ZERO\n w(id4) = ZERO\n !\n ! Solve the system of equations.\n !\n i1 = 1\n local_error_flag = 0\n associate( &\n a_arg => w(1:munk), &\n b_arg => w(id2+1:id2+1+munk), &\n c_arg => w(id3+1:id3+1+munk), &\n y_arg => f(mstart:,nstart:nstart+nunk), &\n w_arg => w(id4+1:) &\n )\n call util%genbun_lower_routine(nbdcnd, nunk, i1, munk, a_arg, b_arg, c_arg, &\n idimf, y_arg, local_error_flag, w_arg)\n end associate\n\n ! Check error flag\n if (local_error_flag /= 0) then\n error stop 'fishpack library: genbun_lower_routine call failed in hwsplr_lower_routine'\n end if\n\n\n select case (mbdcnd)\n case (1:4)\n if (nbdcnd == 0) f(mstart:mstop, np1) = f(mstart:mstop, 1)\n case (5)\n j = id5 + munk\n w(j) = w(id2)/w(id3)\n\n do iip = 3, munk\n i = munk - iip + 2\n j = id5 + i\n lp = id2 + i\n k = id3 + i\n w(j) = w(i)/(w(lp)-w(k)*w(j+1))\n end do\n\n w(id5+1) = -HALF * dt2/(w(id2+1)-w(id3+1)*w(id5+2))\n\n do i = 2, munk\n j = id5 + i\n w(j) = -w(j)*w(j-1)\n end do\n\n s = ZERO\n s = sum(f(2, nstart:nstop))\n a2 = nunk\n\n if (nbdcnd /= 0) then\n s = s - HALF * (f(2, nstart)+f(2, nstop))\n a2 = a2 - ONE\n end if\n\n ypole = (0.25_wp *dr2*f(1, 1)-s/a2)/(w(id5+1)-ONE + elmbda*dr2* 0.25_wp)\n\n do i = mstart, mstop\n k = l + i\n f(i, nstart:nstop) = f(i, nstart:nstop) + ypole*w(k)\n end do\n\n f(1, :np1) = ypole\n\n if (nbdcnd == 0) f(mstart:mstop, np1) = f(mstart:mstop, 1)\n\n case (6)\n !\n ! Adjust the solution as necessary for the problems where a = 0.\n !\n if (elmbda == ZERO) then\n ypole = ZERO\n f(1, :np1) = ypole\n if (nbdcnd == 0) f(mstart:mstop, np1) = f(mstart:mstop, 1)\n end if\n end select\n\n end subroutine hwsplr_lower_routine\n\nend submodule centered_polar_solver\n!\n! REVISION HISTORY\n!\n! September 1973 Version 1\n! April 1976 Version 2\n! January 1978 Version 3\n! December 1979 Version 3.1\n! February 1985 Documentation upgrade\n! November 1988 Version 3.2, FORTRAN 77 changes\n! June 2004 Version 5.0, Fortran 90 changes\n! May 2016 Fortran 2008 changes\n!\n", "meta": {"hexsha": "e0ac53ed9c8c9141eb4c08e64654de0be21a1e20", "size": 29566, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/centered_polar_solver.f90", "max_stars_repo_name": "jlokimlin/fishpack", "max_stars_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2018-03-12T11:31:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-27T07:58:23.000Z", "max_issues_repo_path": "src/centered_polar_solver.f90", "max_issues_repo_name": "jlokimlin/fishpack", "max_issues_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2016-05-07T22:42:47.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-15T17:44:58.000Z", "max_forks_repo_path": "src/centered_polar_solver.f90", "max_forks_repo_name": "jlokimlin/modern_fishpack", "max_forks_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-01-26T20:49:05.000Z", "max_forks_repo_forks_event_max_datetime": "2017-01-27T16:44:58.000Z", "avg_line_length": 39.5796519411, "max_line_length": 99, "alphanum_fraction": 0.3721842657, "num_tokens": 7374, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942173896132, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6871677981834388}} {"text": "! { dg-do run }\n! { dg-options \"\" }\n! Test various exponentations\n! initially designed for patch to PR31120\n\nprogram test\n call run_me (1.0, 1, (1.0,0.0))\n call run_me (-1.1, -1, (0.0,-1.0))\n call run_me (42.0, 12, (1.0,7.0))\nend program test\n\n! This subroutine is for runtime tests\nsubroutine run_me(a, i, z)\n implicit none\n\n real, intent(in) :: a\n integer, intent(in) :: i\n complex, intent(in) :: z\n\n call check_equal_i (i**0, 1)\n call check_equal_i (i**1, i)\n call check_equal_i (i**2, i*i)\n call check_equal_i (i**3, i*(i**2))\n\n ! i has default integer kind.\n call check_equal_i (int(i**0_8,kind=kind(i)), 1)\n call check_equal_i (int(i**1_8,kind=kind(i)), i)\n call check_equal_i (int(i**2_8,kind=kind(i)), i*i)\n call check_equal_i (int(i**3_8,kind=kind(i)), i*i*i)\n\n call check_equal_r (a**0.0, 1.0)\n call check_equal_r (a**1.0, a)\n call check_equal_r (a**2.0, a*a)\n call check_equal_r (a**3.0, a*(a**2))\n call check_equal_r (a**(-1.0), 1/a)\n call check_equal_r (a**(-2.0), (1/a)*(1/a))\n\n call check_equal_r (a**0, 1.0)\n call check_equal_r (a**1, a)\n call check_equal_r (a**2, a*a)\n call check_equal_r (a**3, a*(a**2))\n call check_equal_r (a**(-1), 1/a)\n call check_equal_r (a**(-2), (1/a)*(1/a))\n\n call check_equal_r (a**0_8, 1.0)\n call check_equal_r (a**1_8, a)\n call check_equal_r (a**2_8, a*a)\n call check_equal_r (a**3_8, a*(a**2))\n call check_equal_r (a**(-1_8), 1/a)\n call check_equal_r (a**(-2_8), (1/a)*(1/a))\n\n call check_equal_c (z**0.0, (1.0,0.0))\n call check_equal_c (z**1.0, z)\n call check_equal_c (z**2.0, z*z)\n call check_equal_c (z**3.0, z*(z**2))\n call check_equal_c (z**(-1.0), 1/z)\n call check_equal_c (z**(-2.0), (1/z)*(1/z))\n\n call check_equal_c (z**(0.0,0.0), (1.0,0.0))\n call check_equal_c (z**(1.0,0.0), z)\n call check_equal_c (z**(2.0,0.0), z*z)\n call check_equal_c (z**(3.0,0.0), z*(z**2))\n call check_equal_c (z**(-1.0,0.0), 1/z)\n call check_equal_c (z**(-2.0,0.0), (1/z)*(1/z))\n\n call check_equal_c (z**0, (1.0,0.0))\n call check_equal_c (z**1, z)\n call check_equal_c (z**2, z*z)\n call check_equal_c (z**3, z*(z**2))\n call check_equal_c (z**(-1), 1/z)\n call check_equal_c (z**(-2), (1/z)*(1/z))\n\n call check_equal_c (z**0_8, (1.0,0.0))\n call check_equal_c (z**1_8, z)\n call check_equal_c (z**2_8, z*z)\n call check_equal_c (z**3_8, z*(z**2))\n call check_equal_c (z**(-1_8), 1/z)\n call check_equal_c (z**(-2_8), (1/z)*(1/z))\n\n\ncontains\n\n subroutine check_equal_r (a, b)\n real, intent(in) :: a, b\n if (abs(a - b) > 1.e-5 * abs(b)) call abort\n end subroutine check_equal_r\n\n subroutine check_equal_c (a, b)\n complex, intent(in) :: a, b\n if (abs(a - b) > 1.e-5 * abs(b)) call abort\n end subroutine check_equal_c\n\n subroutine check_equal_i (a, b)\n integer, intent(in) :: a, b\n if (a /= b) call abort\n end subroutine check_equal_i\n\nend subroutine run_me\n\n! subroutine foo is used for compilation test only\nsubroutine foo(a)\n implicit none\n\n real, intent(in) :: a\n integer :: i\n complex :: z\n\n ! Integer\n call gee_i(i**0_1)\n call gee_i(i**1_1)\n call gee_i(i**2_1)\n call gee_i(i**3_1)\n call gee_i(i**(-1_1))\n call gee_i(i**(-2_1))\n call gee_i(i**(-3_1))\n call gee_i(i**huge(0_1))\n call gee_i(i**(-huge(0_1)))\n call gee_i(i**(-huge(0_1)-1_1))\n\n call gee_i(i**0_2)\n call gee_i(i**1_2)\n call gee_i(i**2_2)\n call gee_i(i**3_2)\n call gee_i(i**(-1_2))\n call gee_i(i**(-2_2))\n call gee_i(i**(-3_2))\n call gee_i(i**huge(0_2))\n call gee_i(i**(-huge(0_2)))\n call gee_i(i**(-huge(0_2)-1_2))\n\n call gee_i(i**0_4)\n call gee_i(i**1_4)\n call gee_i(i**2_4)\n call gee_i(i**3_4)\n call gee_i(i**(-1_4))\n call gee_i(i**(-2_4))\n call gee_i(i**(-3_4))\n call gee_i(i**huge(0_4))\n call gee_i(i**(-huge(0_4)))\n call gee_i(i**(-huge(0_4)-1_4))\n\n call gee_i(i**0_8) ! { dg-warning \"Type mismatch in argument\" }\n call gee_i(i**1_8) ! { dg-warning \"Type mismatch in argument\" }\n call gee_i(i**2_8) ! { dg-warning \"Type mismatch in argument\" }\n call gee_i(i**3_8) ! { dg-warning \"Type mismatch in argument\" }\n call gee_i(i**(-1_8)) ! { dg-warning \"Type mismatch in argument\" }\n call gee_i(i**(-2_8)) ! { dg-warning \"Type mismatch in argument\" }\n call gee_i(i**(-3_8)) ! { dg-warning \"Type mismatch in argument\" }\n call gee_i(i**huge(0_8)) ! { dg-warning \"Type mismatch in argument\" }\n call gee_i(i**(-huge(0_8))) ! { dg-warning \"Type mismatch in argument\" }\n call gee_i(i**(-huge(0_8)-1_8)) ! { dg-warning \"Type mismatch in argument\" }\n\n ! Real\n call gee_r(a**0_1)\n call gee_r(a**1_1)\n call gee_r(a**2_1)\n call gee_r(a**3_1)\n call gee_r(a**(-1_1))\n call gee_r(a**(-2_1))\n call gee_r(a**(-3_1))\n call gee_r(a**huge(0_1))\n call gee_r(a**(-huge(0_1)))\n call gee_r(a**(-huge(0_1)-1_1))\n\n call gee_r(a**0_2)\n call gee_r(a**1_2)\n call gee_r(a**2_2)\n call gee_r(a**3_2)\n call gee_r(a**(-1_2))\n call gee_r(a**(-2_2))\n call gee_r(a**(-3_2))\n call gee_r(a**huge(0_2))\n call gee_r(a**(-huge(0_2)))\n call gee_r(a**(-huge(0_2)-1_2))\n\n call gee_r(a**0_4)\n call gee_r(a**1_4)\n call gee_r(a**2_4)\n call gee_r(a**3_4)\n call gee_r(a**(-1_4))\n call gee_r(a**(-2_4))\n call gee_r(a**(-3_4))\n call gee_r(a**huge(0_4))\n call gee_r(a**(-huge(0_4)))\n call gee_r(a**(-huge(0_4)-1_4))\n\n call gee_r(a**0_8)\n call gee_r(a**1_8)\n call gee_r(a**2_8)\n call gee_r(a**3_8)\n call gee_r(a**(-1_8))\n call gee_r(a**(-2_8))\n call gee_r(a**(-3_8))\n call gee_r(a**huge(0_8))\n call gee_r(a**(-huge(0_8)))\n call gee_r(a**(-huge(0_8)-1_8))\n\n ! Complex\n call gee_z(z**0_1)\n call gee_z(z**1_1)\n call gee_z(z**2_1)\n call gee_z(z**3_1)\n call gee_z(z**(-1_1))\n call gee_z(z**(-2_1))\n call gee_z(z**(-3_1))\n call gee_z(z**huge(0_1))\n call gee_z(z**(-huge(0_1)))\n call gee_z(z**(-huge(0_1)-1_1))\n\n call gee_z(z**0_2)\n call gee_z(z**1_2)\n call gee_z(z**2_2)\n call gee_z(z**3_2)\n call gee_z(z**(-1_2))\n call gee_z(z**(-2_2))\n call gee_z(z**(-3_2))\n call gee_z(z**huge(0_2))\n call gee_z(z**(-huge(0_2)))\n call gee_z(z**(-huge(0_2)-1_2))\n\n call gee_z(z**0_4)\n call gee_z(z**1_4)\n call gee_z(z**2_4)\n call gee_z(z**3_4)\n call gee_z(z**(-1_4))\n call gee_z(z**(-2_4))\n call gee_z(z**(-3_4))\n call gee_z(z**huge(0_4))\n call gee_z(z**(-huge(0_4)))\n call gee_z(z**(-huge(0_4)-1_4))\n\n call gee_z(z**0_8)\n call gee_z(z**1_8)\n call gee_z(z**2_8)\n call gee_z(z**3_8)\n call gee_z(z**(-1_8))\n call gee_z(z**(-2_8))\n call gee_z(z**(-3_8))\n call gee_z(z**huge(0_8))\n call gee_z(z**(-huge(0_8)))\n call gee_z(z**(-huge(0_8)-1_8))\nend subroutine foo\n\nsubroutine gee_i(i)\n integer :: i\nend subroutine gee_i\n\nsubroutine gee_r(r)\n real :: r\nend subroutine gee_r\n\nsubroutine gee_z(c)\n complex :: c\nend subroutine gee_z\n", "meta": {"hexsha": "d55f70c9a95b8cfc3a16c74291f95b6805cd17cd", "size": 6648, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/integer_exponentiation_2.f90", "max_stars_repo_name": "maurizioabba/rose", "max_stars_repo_head_hexsha": "7597292cf14da292bdb9a4ef573001b6c5b9b6c0", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/integer_exponentiation_2.f90", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/integer_exponentiation_2.f90", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 26.0705882353, "max_line_length": 78, "alphanum_fraction": 0.6095066185, "num_tokens": 2751, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563336, "lm_q2_score": 0.7772998611746911, "lm_q1q2_score": 0.6871636157237009}} {"text": "! { dg-do run }\n! Test fix for PR fortran/38823.\nprogram power\n\n implicit none\n\n integer, parameter :: &\n & s = kind(1.e0), &\n & d = kind(1.d0), &\n & e = max(selected_real_kind(precision(1.d0)+1), d)\n\n real(s), parameter :: ris = 2.e0_s**2\n real(d), parameter :: rid = 2.e0_d**2\n real(e), parameter :: rie = 2.e0_e**2 \n complex(s), parameter :: cis = (2.e0_s,1.e0_s)**2\n complex(d), parameter :: cid = (2.e0_d,1.e0_d)**2\n complex(e), parameter :: cie = (2.e0_e,1.e0_e)**2\n\n real(s), parameter :: rrs = 2.e0_s**2.e0\n real(d), parameter :: rrd = 2.e0_d**2.e0\n real(e), parameter :: rre = 2.e0_e**2.e0\n complex(s), parameter :: crs = (2.e0_s,1.e0_s)**2.e0\n complex(d), parameter :: crd = (2.e0_d,1.e0_d)**2.e0\n complex(e), parameter :: cre = (2.e0_e,1.e0_e)**2.e0\n\n real(s), parameter :: rds = 2.e0_s**2.e0_d\n real(d), parameter :: rdd = 2.e0_d**2.e0_d\n real(e), parameter :: rde = 2.e0_e**2.e0_d\n complex(s), parameter :: cds = (2.e0_s,1.e0_s)**2.e0_d\n complex(d), parameter :: cdd = (2.e0_d,1.e0_d)**2.e0_d\n complex(e), parameter :: cde = (2.e0_e,1.e0_e)**2.e0_d\n\n real(s), parameter :: eps_s = 1.e-5_s\n real(d), parameter :: eps_d = 1.e-10_d\n real(e), parameter :: eps_e = 1.e-10_e\n\n if (abs(ris - 4) > eps_s) call abort\n if (abs(rid - 4) > eps_d) call abort\n if (abs(rie - 4) > eps_e) call abort\n if (abs(real(cis, s) - 3) > eps_s .or. abs(aimag(cis) - 4) > eps_s) call abort\n if (abs(real(cid, d) - 3) > eps_d .or. abs(aimag(cid) - 4) > eps_d) call abort\n if (abs(real(cie, e) - 3) > eps_e .or. abs(aimag(cie) - 4) > eps_e) call abort\n\n if (abs(rrs - 4) > eps_s) call abort\n if (abs(rrd - 4) > eps_d) call abort\n if (abs(rre - 4) > eps_e) call abort\n if (abs(real(crs, s) - 3) > eps_s .or. abs(aimag(crs) - 4) > eps_s) call abort\n if (abs(real(crd, d) - 3) > eps_d .or. abs(aimag(crd) - 4) > eps_d) call abort\n if (abs(real(cre, e) - 3) > eps_e .or. abs(aimag(cre) - 4) > eps_e) call abort\n\n if (abs(rds - 4) > eps_s) call abort\n if (abs(rdd - 4) > eps_d) call abort\n if (abs(rde - 4) > eps_e) call abort\n if (abs(real(cds, s) - 3) > eps_s .or. abs(aimag(cds) - 4) > eps_s) call abort\n if (abs(real(cdd, d) - 3) > eps_d .or. abs(aimag(cdd) - 4) > eps_d) call abort\n if (abs(real(cde, e) - 3) > eps_e .or. abs(aimag(cde) - 4) > eps_e) call abort\n\nend program power\n", "meta": {"hexsha": "50dbac2756dcc5e40155bff105eb54ee04eb83cb", "size": 2345, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/power1.f90", "max_stars_repo_name": "maurizioabba/rose", "max_stars_repo_head_hexsha": "7597292cf14da292bdb9a4ef573001b6c5b9b6c0", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/power1.f90", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/power1.f90", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 39.7457627119, "max_line_length": 80, "alphanum_fraction": 0.581663113, "num_tokens": 1003, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357327, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.6871635971032454}} {"text": "program fexample\n use fftwpp ! access the wrapper for FFTW++\n use, intrinsic :: ISO_C_Binding\n implicit NONE\n include 'fftw3.f03'\n\n integer(c_int) :: nthreads\n integer(c_int) :: mx, my, mz\n integer(c_int) :: mxp, myp\n integer(c_int) :: i, j, k\n \n integer :: returnflag\n\n complex(C_DOUBLE_COMPLEX), pointer :: f(:), g(:)\n complex(C_DOUBLE_COMPLEX), pointer :: ff(:,:), gg(:,:)\n complex(C_DOUBLE_COMPLEX), pointer :: fff(:,:,:), ggg(:,:,:)\n\n type(C_PTR) :: pf, pg, pconv\n !type(C_PTR) :: pu, pv, pw, pu2, pv2, pu1, pv1, pw1, pu3, pv3\n\n returnflag=0 ! return value for tests\n\n write(*,*) \"Example of calling fftw++ convolutions from Fortran:\"\n\n nthreads = 2 ! specify number of threads\n\n call set_fftwpp_maxthreads(nthreads);\n\n\n!!! cconv \n write(*,*) \"1d non-centered complex convolution:\"\n\n mx = 8 ! problem size\n\n ! Allocate the memory using FFTW.\n pf = fftw_alloc_complex(int(mx, C_SIZE_T))\n pg = fftw_alloc_complex(int(mx, C_SIZE_T))\n\n ! Create the pointer to the convolution\n pconv = cconv1d_create(mx)\n\n ! Make the FORTRAN pointer pf point to the same memory as f, and\n ! give it the correct shape.\n call c_f_pointer(pf, f, [mx])\n call c_f_pointer(pg, g, [mx])\n\n call init(f, g, mx)\n write(*,*) \"Input f:\"\n call output(f, mx)\n write(*,*) \"Input g:\"\n call output(g, mx)\n \n call cconv1d_convolve(pconv, pf, pg)\n\n write(*,*) \"Output:\"\n call output(f, mx)\n\n call delete_cconv1d(pconv)\n call fftw_free(pf)\n call fftw_free(pg)\n\n write(*,*)\n\n!!! hconv\n write(*,*) \"1d centered Hermitian-symmetric complex convolution:\"\n \n mx = 8 ! problem size\n \n pf = fftw_alloc_complex(int(mx, C_SIZE_T))\n pg = fftw_alloc_complex(int(mx, C_SIZE_T))\n pconv = hconv1d_create(mx)\n\n call c_f_pointer(pf, f, [mx])\n call c_f_pointer(pg, g, [mx])\n \n call init(f, g, mx)\n write(*,*) \"Input f:\"\n call output(f, mx)\n write(*,*) \"Input g:\"\n call output(g, mx)\n\n call hconv1d_convolve(pconv, pf, pg)\n\n write(*,*) \"Output:\"\n call output(f, mx)\n\n call fftw_free(pf)\n call fftw_free(pg)\n call delete_hconv1d(pconv)\n\n write(*,*)\n \n!!! cconv2\n write(*,*) \"2d non-centered complex convolution:\"\n mx = 4\n my = 4\n \n pf = fftw_alloc_complex(int(mx * my, C_SIZE_T))\n pg = fftw_alloc_complex(int(mx * my, C_SIZE_T))\n pconv = cconv2d_create(mx, my)\n\n call c_f_pointer(pf, ff, [my, mx])\n call c_f_pointer(pg, gg, [my, mx])\n call init2(ff, gg, my, mx)\n \n write(*,*) \"Input f:\"\n call output2(ff, my, mx)\n write(*,*) \"Input g:\"\n call output2(gg, my, mx)\n \n call cconv2d_convolve(pconv, pf, pg)\n\n write(*,*) \"Output:\"\n call output2(ff, mx, my)\n\n call delete_cconv2d(pconv)\n call fftw_free(pf)\n call fftw_free(pg)\n \n!!! hconv2\n write(*,*) \"2d centered complex convolution:\"\n mx = 4\n my = 4\n mxp = 2 * mx - 1\n \n pf = fftw_alloc_complex(int(mxp * my, C_SIZE_T))\n pg = fftw_alloc_complex(int(mxp * my, C_SIZE_T))\n pconv = hconv2d_create(mx, my)\n\n call c_f_pointer(pf, ff, [my, mxp])\n call c_f_pointer(pg, gg, [my, mxp])\n\n call init2(ff, gg, my, mxp)\n \n write(*,*) \"Input f:\"\n call output2(ff, my, mxp)\n write(*,*) \"Input g:\"\n call output2(gg, my, mxp)\n\n call hconv2d_convolve(pconv, pf, pg)\n\n write(*,*) \"Output:\"\n call output2(ff, my, mxp)\n\n call delete_hconv2d(pconv)\n call fftw_free(pf)\n call fftw_free(pg)\n\n!!! cconv3\n write(*,*) \"3d non-centered complex convolution:\"\n mx = 4\n my = 4\n mz = 4\n \n pf = fftw_alloc_complex(int(mx * my * mz, C_SIZE_T))\n pg = fftw_alloc_complex(int(mx * my * mz, C_SIZE_T))\n pconv = cconv3d_create(mx, my, mz)\n\n call c_f_pointer(pf, fff, [mz, my, mx])\n call c_f_pointer(pg, ggg, [mz, my, mx])\n call init3(fff, ggg, mz, my, mx)\n \n write(*,*) \"Input f:\"\n call output3(fff, mz, my, mx)\n write(*,*) \"Input g:\"\n call output3(ggg, mz, my, mx)\n \n call cconv3d_convolve(pconv, pf, pg)\n\n write(*,*) \"Output:\"\n call output3(fff, mz, my, mx)\n\n call delete_cconv3d(pconv)\n call fftw_free(pf)\n call fftw_free(pg)\n\n !!! hconv2\n write(*,*) \"2d centered complex convolution:\"\n mx = 4\n my = 4\n mz = 4\n mxp = 2 * mx - 1\n myp = 2 * my - 1\n \n pf = fftw_alloc_complex(int(mxp * myp * mz, C_SIZE_T))\n pg = fftw_alloc_complex(int(mxp * myp * mz, C_SIZE_T))\n pconv = hconv3d_create(mx, my, mz)\n\n call c_f_pointer(pf, fff, [mz, myp, mxp])\n call c_f_pointer(pg, ggg, [mz, myp, mxp])\n\n call init3(fff, ggg, mz, myp, mxp)\n \n write(*,*) \"Input f:\"\n call output3(fff, mz, myp, mxp)\n write(*,*) \"Input g:\"\n call output3(ggg, mz, myp, mxp)\n\n call hconv3d_convolve(pconv, pf, pg)\n\n write(*,*) \"Output:\"\n call output3(fff, mz, myp, mxp)\n\n call delete_hconv3d(pconv)\n call fftw_free(pf)\n call fftw_free(pg)\n \n call EXIT(returnflag)\n\ncontains\n subroutine init(f, g, m)\n use,intrinsic :: ISO_C_Binding\n implicit NONE\n integer :: i\n integer(c_int), intent(in) :: m\n complex(C_DOUBLE_COMPLEX), pointer, intent(inout) :: f(:), g(:)\n do i = 0 ,m - 1\n f(i + 1) = cmplx(i, i + 1)\n g(i + 1) = cmplx(i, 2 * i + 1)\n end do\n end subroutine init\n\n subroutine init2(f, g, my, mx)\n use,intrinsic :: ISO_C_Binding\n implicit NONE\n integer :: i,j\n integer(c_int),intent(in) :: my, mx\n complex(C_DOUBLE_COMPLEX), pointer, intent(inout) :: f(:,:), g(:,:)\n do j = 0, my - 1\n do i = 0, mx - 1\n f(j + 1, i + 1) = cmplx(i, j)\n g(j + 1, i + 1) = cmplx(2 * i, j + 1)\n end do\n end do\n end subroutine init2\n\n subroutine init3(f, g, mz, my, mx)\n use,intrinsic :: ISO_C_Binding\n implicit NONE\n integer :: i,j\n integer(c_int),intent(in) :: mz, my, mx\n complex(C_DOUBLE_COMPLEX), pointer, intent(inout) :: f(:,:,:), g(:,:,:)\n do k = 0, mz - 1\n do j = 0, my - 1\n do i = 0, mx - 1\n f(k + 1, j + 1, i + 1) = cmplx(i + k, j + k)\n g(k + 1, j + 1, i + 1) = cmplx(2 * i + k, j + 1 + k)\n end do\n end do\n end do\n end subroutine init3\n\n subroutine output(f, m)\n use,intrinsic :: ISO_C_Binding\n implicit NONE\n integer :: i\n integer(c_int),intent(in) :: m\n complex(C_DOUBLE_COMPLEX),pointer,intent(inout) :: f(:)\n do i=1,m\n print*,f(i)\n end do\n end subroutine output\n\n subroutine output2(f, my, mx)\n use,intrinsic :: ISO_C_Binding\n implicit NONE\n integer :: j, i\n integer(c_int), intent(in) :: my, mx\n complex(C_DOUBLE_COMPLEX), pointer, intent(in) :: f(:,:)\n do j = 1, my\n do i = 1, mx\n print*,f(j,i)\n end do\n write(*,*)\n end do\n end subroutine output2\n\n subroutine output3(f, mz, my, mx)\n use,intrinsic :: ISO_C_Binding\n implicit NONE\n integer :: i,j\n integer(c_int),intent(in) :: mz, my, mx\n complex(C_DOUBLE_COMPLEX),pointer,intent(inout) :: f(:,:,:)\n do k=1,mz\n do j=1,my\n do i=1,mx\n print*,f(k,j,i)\n end do\n write(*,*)\n end do\n write(*,*)\n end do\n end subroutine output3\n\nend program fexample\n\n", "meta": {"hexsha": "0e872305f0b108fe78bb930f9454e1daa6e9bebd", "size": 7001, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Library/Utilities/fftw++-2.05/wrappers/fexample.f90", "max_stars_repo_name": "stevend12/SolutioCpp", "max_stars_repo_head_hexsha": "6fa8a12207cd1e7e806a8ef5de93dc137c33856e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2017-06-27T14:04:46.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-17T17:38:03.000Z", "max_issues_repo_path": "Library/Utilities/fftw++-2.05/wrappers/fexample.f90", "max_issues_repo_name": "stevend12/SolutioCpp", "max_issues_repo_head_hexsha": "6fa8a12207cd1e7e806a8ef5de93dc137c33856e", "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": "Library/Utilities/fftw++-2.05/wrappers/fexample.f90", "max_forks_repo_name": "stevend12/SolutioCpp", "max_forks_repo_head_hexsha": "6fa8a12207cd1e7e806a8ef5de93dc137c33856e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-06-23T20:10:44.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-13T10:09:46.000Z", "avg_line_length": 23.5723905724, "max_line_length": 75, "alphanum_fraction": 0.587916012, "num_tokens": 2410, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392725805823, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.6871635947284774}} {"text": "!*********************************************************************\n! This file is part of Polylogarithm.\n!\n! Polylogarithm is licenced under the MIT License.\n!*********************************************************************\n\n!*********************************************************************\n!> @brief Clausen function \\f$\\operatorname{Cl}_6(\\theta) = \\operatorname{Im}(\\operatorname{Li}_6(e^{i\\theta}))\\f$\n!> @param x real angle\n!> @return \\f$\\operatorname{Cl}_6(\\theta)\\f$\n!> @author Alexander Voigt\n!> Implemented as rational function approximation.\n!*********************************************************************\n\ndouble precision function dcl6(x)\n implicit none\n double precision :: x, y, z, z2, z4, p, q, p0, p1, h, sgn\n double precision, parameter :: PI = 3.14159265358979324D0\n double precision, parameter :: PI2 = 2*PI, PIH = PI/2, PI28 = PI*PI/8\n double precision, parameter :: zeta3 = 1.2020569031595943D0\n double precision, parameter :: cp(4) = (/ &\n 1.0369277551433699D+0, &\n -2.0871954441071750D-1, &\n 2.0652251045312954D-2, &\n -1.3834381382568400D-4 /)\n double precision, parameter :: cq(4) = (/ &\n 1.0000000000000000D+0, &\n -8.0784096827362542D-3, &\n 5.8074568862993102D-6, &\n -5.1960620033050114D-10 /)\n double precision, parameter :: cr(5) = (/ &\n 7.9544504578027050D-1, &\n -1.9255025309738589D-1, &\n 1.5805208288846591D-2, &\n -5.4175380521534706D-4, &\n 6.7577493541009068D-6 /)\n double precision, parameter :: cs(6) = (/ &\n 1.0000000000000000D+0, &\n -7.0798422394109274D-2, &\n 7.1744189715634762D-4, &\n 3.9098747334347093D-6, &\n 3.5669441618295266D-8, &\n 2.5315391843409925D-10 /)\n\n sgn = 1\n\n if (x .lt. 0) then\n x = -x\n sgn = -1\n endif\n\n if (x .ge. PI2) then\n x = mod(x, PI2)\n endif\n\n if (x .gt. PI) then\n p0 = 6.28125D0\n p1 = 0.0019353071795864769253D0\n x = (p0 - x) + p1\n sgn = -sgn\n endif\n\n if (x .eq. 0 .or. x .eq. PI) then\n dcl6 = 0\n return\n endif\n\n if (x .lt. PIH) then\n y = x*x\n z = y*y\n p = cp(1) + y * cp(2) + z * (cp(3) + y * cp(4))\n q = cq(1) + y * cq(2) + z * (cq(3) + y * cq(4))\n h = x*(p/q - 1.0D0/120*z*log(x))\n else\n y = PI - x\n z = y*y - PI28\n z2 = z*z\n z4 = z2*z2\n p = cr(1) + z * cr(2) + z2 * (cr(3) + z * cr(4)) + &\n z4 * cr(5)\n q = cs(1) + z * cs(2) + z2 * (cs(3) + z * cs(4)) + &\n z4 * (cs(5) + z * cs(6))\n h = y*p/q\n endif\n\n dcl6 = sgn*h\n\nend function dcl6\n", "meta": {"hexsha": "5f395802cb500935d062a72bc619c23cfa1d4dab", "size": 2803, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/Cl6.f90", "max_stars_repo_name": "Expander/dilogarithm", "max_stars_repo_head_hexsha": "ad86038206895ab5bff79a26294f4bb5c5634eb5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-05-04T14:47:41.000Z", "max_stars_repo_stars_event_max_datetime": "2017-08-02T13:13:45.000Z", "max_issues_repo_path": "src/fortran/Cl6.f90", "max_issues_repo_name": "Expander/dilogarithm", "max_issues_repo_head_hexsha": "ad86038206895ab5bff79a26294f4bb5c5634eb5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/fortran/Cl6.f90", "max_forks_repo_name": "Expander/dilogarithm", "max_forks_repo_head_hexsha": "ad86038206895ab5bff79a26294f4bb5c5634eb5", "max_forks_repo_licenses": ["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.4943820225, "max_line_length": 114, "alphanum_fraction": 0.4484480913, "num_tokens": 1000, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026482819236, "lm_q2_score": 0.7490872187162397, "lm_q1q2_score": 0.6871396895225472}} {"text": "! Copyright (C) 2012 The SPEED FOUNDATION\n! Author: Ilario Mazzieri\n!\n! This file is part of SPEED.\n!\n! SPEED is free software; you can redistribute it and/or modify it\n! under the terms of the GNU Affero General Public License as\n! published by the Free Software Foundation, either version 3 of the\n! License, or (at your option) any later version.\n!\n! SPEED is distributed in the hope that it will be useful, but\n! WITHOUT ANY WARRANTY; without even the implied warranty of\n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n! Affero General Public License for more details.\n!\n! You should have received a copy of the GNU Affero General Public License\n! along with SPEED. If not, see .\n\n!> @brief Compute the Rayleigh damping matrix C = A0 M + A1 K,\n!! M = mass matrix, K= stiffness matrix\n!! @author Ilario Mazzieri\n!> @date November, 2014 \n!> @version 1.0\n!> @param[in] nn polynomial degree + 1\n!> @param[in] ct LGL nodes\n!> @param[in] ww LGL weights\n!> @param[in] dd matrix of spectral derivates \n!> @param[in] rho mass density\n!> @param[in] A11,...,DD3 coefficients for the bilinear map\n!> @param[out] mc_el Rayleigh damping matrix\n\n subroutine MAKE_RAYLEIGH_DAMPING_MATRIX(nn,ct,ww,dd,rho,& \n A11,A12,A13,A21,A22,A23,& \n A31,A32,A33,B11,B12,B13,& \n B21,B22,B23,B31,B32,B33,& \n GG1,GG2,GG3,DD1,DD2,DD3,& \n mc_el)\n \n \n implicit none \n \n integer*4 :: nn \n integer*4 :: i,j,k \n\n real*8 :: A11,A12,A13,A21,A22,A23,A31,A32,A33 \n real*8 :: B11,B12,B13,B21,B22,B23,B31,B32,B33 \n real*8 :: GG1,GG2,GG3,DD1,DD2,DD3 \n real*8 :: dxdx,dxdy,dxdz,dydx,dydy,dydz,dzdx,dzdy,dzdz,det_j \n\n real*8, dimension(nn) :: ct,ww \n\n real*8, dimension(nn,nn) :: dd \n\n real*8, dimension(nn,nn,nn) :: rho,gamma\n real*8, dimension(nn,nn,nn) :: mc_el,mck_el \n\n \n \n do k = 1,nn \n do j = 1,nn \n do i = 1,nn \n dxdx = A11 +B12*ct(k) +B13*ct(j) & \n + GG1*ct(j)*ct(k) \n dydx = A21 +B22*ct(k) +B23*ct(j) & \n + GG2*ct(j)*ct(k) \n dzdx = A31 +B32*ct(k) +B33*ct(j) & \n + GG3*ct(j)*ct(k) \n \n dxdy = A12 +B11*ct(k) +B13*ct(i) & \n + GG1*ct(k)*ct(i) \n dydy = A22 +B21*ct(k) +B23*ct(i) & \n + GG2*ct(k)*ct(i) \n dzdy = A32 +B31*ct(k) +B33*ct(i) & \n + GG3*ct(k)*ct(i) \n \n dxdz = A13 +B11*ct(j) +B12*ct(i) & \n + GG1*ct(i)*ct(j) \n dydz = A23 +B21*ct(j) +B22*ct(i) & \n + GG2*ct(i)*ct(j) \n dzdz = A33 +B31*ct(j) +B32*ct(i) & \n + GG3*ct(i)*ct(j) \n \n det_j = dxdz * (dydx*dzdy - dzdx*dydy) & \n - dydz * (dxdx*dzdy - dzdx*dxdy) & \n + dzdz * (dxdx*dydy - dydx*dxdy) \n\n\n \n mc_el(i,j,k) = rho(i,j,k) & \n * det_j * ww(i) * ww(j) * ww(k) \n \n \n\n enddo \n enddo \n enddo \n \n return \n \n end subroutine MAKE_RAYLEIGH_DAMPING_MATRIX\n\n", "meta": {"hexsha": "ee76e06bb33acecdec35b72162111724b51586ae", "size": 3556, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "SRC/SPEED-MDOF190510/MAKE_RAYLEIGH_DAMPING_MATRIX.f90", "max_stars_repo_name": "research-group-of-Xinzheng-Lu/SCI-effects-simulation", "max_stars_repo_head_hexsha": "6f91a4afce51303ac33d9dce005247290679b428", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2019-05-11T17:26:13.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-31T12:41:29.000Z", "max_issues_repo_path": "SRC/SPEED-MDOF190510/MAKE_RAYLEIGH_DAMPING_MATRIX.f90", "max_issues_repo_name": "research-group-of-Xinzheng-Lu/SCI-effects-simulation", "max_issues_repo_head_hexsha": "6f91a4afce51303ac33d9dce005247290679b428", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SRC/SPEED-MDOF190510/MAKE_RAYLEIGH_DAMPING_MATRIX.f90", "max_forks_repo_name": "research-group-of-Xinzheng-Lu/SCI-effects-simulation", "max_forks_repo_head_hexsha": "6f91a4afce51303ac33d9dce005247290679b428", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-05-15T06:26:21.000Z", "max_forks_repo_forks_event_max_datetime": "2020-01-10T07:22:41.000Z", "avg_line_length": 34.862745098, "max_line_length": 103, "alphanum_fraction": 0.4732845894, "num_tokens": 1090, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026482819236, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6871396843842652}} {"text": "program gen_crc14\n\n character m77*77,c14*14\n\n integer mc(96),r(15),p(15),ncrc\n! polynomial for 14-bit CRC 0x6757\n data p/1,1,0,0,1,1,1,0,1,0,1,0,1,1,1/\n \n nargs=iargc()\n if(nargs.ne.1) then\n print*,'Usage: gen_crc14 <77-bit message>'\n print*,'Example: gen_crc14 \"00000000000000000000000000100000010011011111110011011100100010100001010000001\"'\n go to 999\n endif\n\n! pad the 77bit message out to 96 bits\n call getarg(1,m77)\n read(m77,'(77i1)') mc(1:77)\n mc(78:96)=0\n\n! divide by polynomial\n r=mc(1:15)\n do i=0,81\n r(15)=mc(i+15)\n r=mod(r+r(1)*p,2)\n r=cshift(r,1)\n enddo\n\n! the crc is in r(1:14) - print it in various ways:\n write(c14,'(14b1)') r(1:14)\n write(*,'(a40,1x,a14)') 'crc14 as a string: ',c14\n read(c14,'(b14.14)') ncrc\n write(*,'(a40,i6)') 'crc14 as an integer: ',ncrc\n write(*,'(a40,1x,b14.14)') 'binary representation of the integer: ',ncrc\n\n999 end program gen_crc14\n", "meta": {"hexsha": "e4ec12294d207faf7a7016d094df96e94ec3e549", "size": 919, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ft4_ft8_public/gen_crc14.f90", "max_stars_repo_name": "jcyfkimi/ft8_lib", "max_stars_repo_head_hexsha": "6a93e6941000518c55b78b264b1fcc344a8827d0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 102, "max_stars_repo_stars_event_min_datetime": "2018-10-20T19:11:20.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-27T12:05:18.000Z", "max_issues_repo_path": "ft4_ft8_public/gen_crc14.f90", "max_issues_repo_name": "kholia/ft8_lib", "max_issues_repo_head_hexsha": "5fb933b0d49cb91365db8401b2a465cf2c1267dd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 15, "max_issues_repo_issues_event_min_datetime": "2018-11-01T14:54:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-06T19:28:43.000Z", "max_forks_repo_path": "ft4_ft8_public/gen_crc14.f90", "max_forks_repo_name": "kholia/ft8_lib", "max_forks_repo_head_hexsha": "5fb933b0d49cb91365db8401b2a465cf2c1267dd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 37, "max_forks_repo_forks_event_min_datetime": "2018-11-16T12:35:02.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-17T03:01:13.000Z", "avg_line_length": 24.8378378378, "max_line_length": 112, "alphanum_fraction": 0.6463547334, "num_tokens": 393, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026528034426, "lm_q2_score": 0.749087201911703, "lm_q1q2_score": 0.6871396774947132}} {"text": " SUBROUTINE MB05OD( BALANC, N, NDIAG, DELTA, A, LDA, MDIG, IDIG,\n $ IWORK, DWORK, LDWORK, IWARN, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute exp(A*delta) where A is a real N-by-N matrix and delta\nC is a scalar value. The routine also returns the minimal number of\nC accurate digits in the 1-norm of exp(A*delta) and the number of\nC accurate digits in the 1-norm of exp(A*delta) at 95% confidence\nC level.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC BALANC CHARACTER*1\nC Specifies whether or not a balancing transformation (done\nC by SLICOT Library routine MB04MD) is required, as follows:\nC = 'N', do not use balancing;\nC = 'S', use balancing (scaling).\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The order of the matrix A. N >= 0.\nC\nC NDIAG (input) INTEGER\nC The specified order of the diagonal Pade approximant.\nC In the absence of further information NDIAG should\nC be set to 9. NDIAG should not exceed 15. NDIAG >= 1.\nC\nC DELTA (input) DOUBLE PRECISION\nC The scalar value delta of the problem.\nC\nC A (input/output) DOUBLE PRECISION array, dimension (LDA,N)\nC On input, the leading N-by-N part of this array must\nC contain the matrix A of the problem. (This is not needed\nC if DELTA = 0.)\nC On exit, if INFO = 0, the leading N-by-N part of this\nC array contains the solution matrix exp(A*delta).\nC\nC LDA INTEGER\nC The leading dimension of array A. LDA >= MAX(1,N).\nC\nC MDIG (output) INTEGER\nC The minimal number of accurate digits in the 1-norm of\nC exp(A*delta).\nC\nC IDIG (output) INTEGER\nC The number of accurate digits in the 1-norm of\nC exp(A*delta) at 95% confidence level.\nC\nC Workspace\nC\nC IWORK INTEGER array, dimension (N)\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC\nC LDWORK INTEGER\nC The length of the array DWORK.\nC LDWORK >= N*(2*N+NDIAG+1)+NDIAG, if N > 1.\nC LDWORK >= 1, if N <= 1.\nC\nC Warning Indicator\nC\nC IWARN INTEGER\nC = 0: no warning;\nC = 1: if MDIG = 0 and IDIG > 0, warning for possible\nC inaccuracy (the exponential has been computed);\nC = 2: if MDIG = 0 and IDIG = 0, warning for severe\nC inaccuracy (the exponential has been computed);\nC = 3: if balancing has been requested, but it failed to\nC reduce the matrix norm and was not actually used.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value;\nC = 1: if the norm of matrix A*delta (after a possible\nC balancing) is too large to obtain an accurate\nC result;\nC = 2: if the coefficient matrix (the denominator of the\nC Pade approximant) is exactly singular; try a\nC different value of NDIAG;\nC = 3: if the solution exponential would overflow, possibly\nC due to a too large value DELTA; the calculations\nC stopped prematurely. This error is not likely to\nC appear.\nC\nC METHOD\nC\nC The exponential of the matrix A is evaluated from a diagonal Pade\nC approximant. This routine is a modification of the subroutine\nC PADE, described in reference [1]. The routine implements an\nC algorithm which exploits the identity\nC\nC (exp[(2**-m)*A]) ** (2**m) = exp(A),\nC\nC where m is an integer determined by the algorithm, to improve the\nC accuracy for matrices with large norms.\nC\nC REFERENCES\nC\nC [1] Ward, R.C.\nC Numerical computation of the matrix exponential with accuracy\nC estimate.\nC SIAM J. Numer. Anal., 14, pp. 600-610, 1977.\nC\nC NUMERICAL ASPECTS\nC 3\nC The algorithm requires 0(N ) operations.\nC\nC CONTRIBUTOR\nC\nC Release 3.0: V. Sima, Katholieke Univ. Leuven, Belgium, Apr. 1997.\nC Supersedes Release 2.0 routine MB05CD by T.W.C. Williams, Kingston\nC Polytechnic, March 1982.\nC\nC REVISIONS\nC\nC June 14, 1997, April 25, 2003, December 12, 2004.\nC\nC KEYWORDS\nC\nC Continuous-time system, matrix algebra, matrix exponential,\nC matrix operations, Pade approximation.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, HALF, ONE, TWO, FOUR, EIGHT, TEN, TWELVE,\n $ NINTEN, TWO4, FOUR7, TWOHND\n PARAMETER ( ZERO = 0.0D0, HALF = 0.5D0, ONE = 1.0D0,\n $ TWO = 2.0D0, FOUR = 4.0D0, EIGHT = 8.0D0,\n $ TEN = 10.0D0, TWELVE = 12.0D0,\n $ NINTEN = 19.0D0, TWO4 = 24.0D0,\n $ FOUR7 = 47.0D0, TWOHND = 200.0D0 )\nC .. Scalar Arguments ..\n CHARACTER BALANC\n INTEGER IDIG, INFO, IWARN, LDA, LDWORK, MDIG, N,\n $ NDIAG\n DOUBLE PRECISION DELTA\nC .. Array Arguments ..\n INTEGER IWORK(*)\n DOUBLE PRECISION A(LDA,*), DWORK(*)\nC .. Local Scalars ..\n LOGICAL LBALS\n CHARACTER ACTBAL\n INTEGER BASE, I, IFAIL, IJ, IK, IM1, J, JWORA1, JWORA2,\n $ JWORA3, JWORV1, JWORV2, K, M, MPOWER, NDAGM1,\n $ NDAGM2, NDEC, NDECM1\n DOUBLE PRECISION ANORM, AVGEV, BD, BIG, EABS, EAVGEV, EMNORM,\n $ EPS, FACTOR, FN, GN, MAXRED, OVRTH2, OVRTHR, P,\n $ RERL, RERR, S, SD2, SIZE, SMALL, SS, SUM2D,\n $ TEMP, TMP1, TR, U, UNDERF, VAR, VAREPS, XN\nC .. External Functions ..\n LOGICAL LSAME\n DOUBLE PRECISION DASUM, DLAMCH, DLANGE, DNRM2\n EXTERNAL DASUM, DLAMCH, DLANGE, DNRM2, LSAME\nC .. External Subroutines ..\n EXTERNAL DCOPY, DGEMM, DGEMV, DGETRF, DGETRS, DLACPY,\n $ DLASCL, DLASET, DSCAL, MB04MD, MB05OY, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC DBLE, EXP, INT, LOG, LOG10, MAX, MIN, MOD, SQRT\nC .. Executable Statements ..\nC\n IWARN = 0\n INFO = 0\n LBALS = LSAME( BALANC, 'S' )\nC\nC Test the input scalar arguments.\nC\n IF( .NOT.( LSAME( BALANC, 'N' ) .OR. LBALS ) ) THEN\n INFO = -1\n ELSE IF( N.LT.0 ) THEN\n INFO = -2\n ELSE IF( NDIAG.LT.1 ) THEN\n INFO = -3\n ELSE IF( LDA.LT.MAX( 1, N ) ) THEN\n INFO = -6\n ELSE IF( LDWORK.LT.1 .OR.\n $ ( LDWORK.LT.N*( 2*N + NDIAG + 1 ) + NDIAG .AND. N.GT.1 )\n $ ) THEN\n INFO = -11\n END IF\nC\n IF ( INFO.NE.0 ) THEN\nC\nC Error return.\nC\n CALL XERBLA( 'MB05OD', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n EPS = DLAMCH( 'Epsilon' )\n NDEC = INT( LOG10( ONE/EPS ) + ONE )\nC\n IF ( N.EQ.0 ) THEN\n MDIG = NDEC\n IDIG = NDEC\n RETURN\n END IF\nC\nC Set some machine parameters.\nC\n BASE = DLAMCH( 'Base' )\n NDECM1 = NDEC - 1\n UNDERF = DLAMCH( 'Underflow' )\n OVRTHR = DLAMCH( 'Overflow' )\n OVRTH2 = SQRT( OVRTHR )\nC\n IF ( DELTA.EQ.ZERO ) THEN\nC\nC The DELTA = 0 case.\nC\n CALL DLASET( 'Full', N, N, ZERO, ONE, A, LDA )\n MDIG = NDECM1\n IDIG = NDECM1\n RETURN\n END IF\nC\n IF ( N.EQ.1 ) THEN\nC\nC The 1-by-1 case.\nC\n A(1,1) = EXP( A(1,1)*DELTA )\n MDIG = NDECM1\n IDIG = NDECM1\n RETURN\n END IF\nC\nC Set pointers for the workspace.\nC\n JWORA1 = 1\n JWORA2 = JWORA1 + N*N\n JWORA3 = JWORA2 + N*NDIAG\n JWORV1 = JWORA3 + N*N\n JWORV2 = JWORV1 + N\nC\nC Compute Pade coefficients in DWORK(JWORV2:JWORV2+NDIAG-1).\nC\n DWORK(JWORV2) = HALF\nC\n DO 20 I = 2, NDIAG\n IM1 = I - 1\n DWORK(JWORV2+IM1) = DWORK(JWORV2+I-2)*DBLE( NDIAG - IM1 )/\n $ DBLE( I*( 2*NDIAG - IM1 ) )\n 20 CONTINUE\nC\n VAREPS = EPS**2*( ( DBLE( BASE )**2 - ONE )/\n $ ( TWO4*LOG( DBLE( BASE ) ) ) )\n XN = DBLE( N )\n TR = ZERO\nC\nC Apply a translation with the mean of the eigenvalues of A*DELTA.\nC\n DO 40 I = 1, N\n CALL DSCAL( N, DELTA, A(1,I), 1 )\n TR = TR + A(I,I)\n 40 CONTINUE\nC\n AVGEV = TR/XN\n IF ( AVGEV.GT.LOG( OVRTHR ) .OR. AVGEV.LT.LOG( UNDERF ) )\n $ AVGEV = ZERO\n IF ( AVGEV.NE.ZERO ) THEN\n ANORM = DLANGE( '1-norm', N, N, A, LDA, DWORK(JWORA1) )\nC\n DO 60 I = 1, N\n A(I,I) = A(I,I) - AVGEV\n 60 CONTINUE\nC\n TEMP = DLANGE( '1-norm', N, N, A, LDA, DWORK(JWORA1) )\n IF ( TEMP.GT.HALF*ANORM ) THEN\nC\n DO 80 I = 1, N\n A(I,I) = A(I,I) + AVGEV\n 80 CONTINUE\nC\n AVGEV = ZERO\n END IF\n END IF\n ACTBAL = BALANC\n IF ( LBALS ) THEN\nC\nC Balancing (scaling) has been requested. First, save A.\nC\n CALL DLACPY( 'Full', N, N, A, LDA, DWORK(JWORA1), N )\n MAXRED = TWOHND\n CALL MB04MD( N, MAXRED, A, LDA, DWORK(JWORV1), INFO )\n IF ( MAXRED.LT.ONE ) THEN\nC\nC Recover the matrix and reset DWORK(JWORV1,...,JWORV1+N-1)\nC to 1, as no reduction of the norm occured (unlikely event).\nC\n CALL DLACPY( 'Full', N, N, DWORK(JWORA1), N, A, LDA )\n ACTBAL = 'N'\n DWORK(JWORV1) = ONE\n CALL DCOPY( N-1, DWORK(JWORV1), 0, DWORK(JWORV1+1), 1 )\n IWARN = 3\n END IF\n END IF\nC\nC Scale the matrix by 2**(-M), where M is the minimum integer\nC so that the resulted matrix has the 1-norm less than 0.5.\nC\n ANORM = DLANGE( '1-norm', N, N, A, LDA, DWORK(JWORA1) )\n M = 0\n IF ( ANORM.GE.HALF ) THEN\n MPOWER = INT( LOG( OVRTHR )/LOG( TWO ) )\n M = INT( LOG( ANORM )/LOG( TWO ) ) + 1\n IF ( M.GT.MPOWER ) THEN\nC\nC Error return: The norm of A*DELTA is too large.\nC\n INFO = 1\n RETURN\n END IF\n FACTOR = TWO**M\n IF ( M+1.LT.MPOWER ) THEN\n M = M + 1\n FACTOR = FACTOR*TWO\n END IF\nC\n DO 120 I = 1, N\n CALL DSCAL( N, ONE/FACTOR, A(1,I), 1 )\n 120 CONTINUE\nC\n END IF\n NDAGM1 = NDIAG - 1\n NDAGM2 = NDAGM1 - 1\n IJ = 0\nC\nC Compute the factors of the diagonal Pade approximant.\nC The loop 200 takes the accuracy requirements into account:\nC Pade coefficients decrease with K, so the calculations should\nC be performed in backward order, one column at a time.\nC (A BLAS 3 implementation in forward order, using DGEMM, could\nC possibly be less accurate.)\nC\n DO 200 J = 1, N\n CALL DGEMV( 'No transpose', N, N, ONE, A, LDA, A(1,J), 1, ZERO,\n $ DWORK(JWORA2), 1 )\n IK = 0\nC\n DO 140 K = 1, NDAGM2\n CALL DGEMV( 'No transpose', N, N, ONE, A, LDA,\n $ DWORK(JWORA2+IK), 1, ZERO, DWORK(JWORA2+IK+N),\n $ 1 )\n IK = IK + N\n 140 CONTINUE\nC\n DO 180 I = 1, N\n S = ZERO\n U = ZERO\n IK = NDAGM2*N + I - 1\nC\n DO 160 K = NDAGM1, 1, -1\n P = DWORK(JWORV2+K)*DWORK(JWORA2+IK)\n IK = IK - N\n S = S + P\n IF ( MOD( K+1, 2 ).EQ.0 ) THEN\n U = U + P\n ELSE\n U = U - P\n END IF\n 160 CONTINUE\nC\n P = DWORK(JWORV2)*A(I,J)\n S = S + P\n U = U - P\n IF ( I.EQ.J ) THEN\n S = S + ONE\n U = U + ONE\n END IF\n DWORK(JWORA3+IJ) = S\n DWORK(JWORA1+IJ) = U\n IJ = IJ + 1\n 180 CONTINUE\nC\n 200 CONTINUE\nC\nC Compute the exponential of the scaled matrix, using diagonal Pade\nC approximants. As, in theory [1], the denominator of the Pade\nC approximant should be very well conditioned, no condition estimate\nC is computed.\nC\n CALL DGETRF( N, N, DWORK(JWORA1), N, IWORK, IFAIL )\n IF ( IFAIL.GT.0 ) THEN\nC\nC Error return: The matrix is exactly singular.\nC\n INFO = 2\n RETURN\n END IF\nC\n CALL DLACPY( 'Full', N, N, DWORK(JWORA3), N, A, LDA )\n CALL DGETRS( 'No transpose', N, N, DWORK(JWORA1), N, IWORK, A,\n $ LDA, IFAIL )\nC\nC Prepare for the calculation of the accuracy estimates.\nC Note that ANORM here is in the range [1, e].\nC\n ANORM = DLANGE( '1-norm', N, N, A, LDA, DWORK(JWORA1) )\n IF ( ANORM.GE.ONE ) THEN\n EABS = ( NINTEN*XN + FOUR7 )*( EPS*ANORM )\n ELSE\n EABS = ( ( NINTEN*XN + FOUR7 )*EPS )*ANORM\n END IF\n IF ( M.NE.0 ) THEN\n VAR = XN*VAREPS\n FN = ( FOUR*XN )/( ( XN + TWO )*( XN + ONE ) )\n GN = ( ( TWO*XN + TEN )*XN - FOUR )/( ( ( XN + TWO )**2 )\n $ *( ( XN + ONE )**2 ) )\nC\nC Square-up the computed exponential matrix M times, with caution\nC for avoiding overflows.\nC\n DO 220 K = 1, M\n IF ( ANORM.GT.OVRTH2 ) THEN\nC\nC The solution could overflow.\nC\n CALL DGEMM( 'No transpose', 'No transpose', N, N, N,\n $ ONE/ANORM, A, LDA, A, LDA, ZERO,\n $ DWORK(JWORA1), N )\n S = DLANGE( '1-norm', N, N, DWORK(JWORA1), N,\n $ DWORK(JWORA1) )\n IF ( ANORM.LE.OVRTHR/S ) THEN\n CALL DLASCL( 'General', N, N, ONE, ANORM, N, N,\n $ DWORK(JWORA1), N, INFO )\n TEMP = OVRTHR\n ELSE\nC\nC Error return: The solution would overflow.\nC This will not happen on most machines, due to the\nC selection of M.\nC\n INFO = 3\n RETURN\n END IF\n ELSE\n CALL DGEMM( 'No transpose', 'No transpose', N, N, N, ONE,\n $ A, LDA, A, LDA, ZERO, DWORK(JWORA1), N )\n TEMP = ANORM**2\n END IF\n IF ( EABS.LT.ONE ) THEN\n EABS = ( TWO*ANORM + EABS )*EABS + XN*( EPS*TEMP )\n ELSE IF ( EABS.LT.SQRT( ONE - XN*EPS + OVRTHR/TEMP )*ANORM -\n $ ANORM ) THEN\n EABS = XN*( EPS*TEMP ) + TWO*( ANORM*EABS ) + EABS**2\n ELSE\n EABS = OVRTHR\n END IF\nC\n TMP1 = FN*VAR + GN*( TEMP*VAREPS )\n IF ( TMP1.GT.OVRTHR/TEMP ) THEN\n VAR = OVRTHR\n ELSE\n VAR = TMP1*TEMP\n END IF\nC\n CALL DLACPY( 'Full', N, N, DWORK(JWORA1), N, A, LDA )\n ANORM = DLANGE( '1-norm', N, N, A, LDA, DWORK(JWORA1) )\n 220 CONTINUE\nC\n ELSE\n VAR = ( TWELVE*XN )*VAREPS\n END IF\nC\nC Apply back transformations, if balancing was effectively used.\nC\n CALL MB05OY( ACTBAL, N, 1, N, A, LDA, DWORK(JWORV1), INFO )\n EAVGEV = EXP( AVGEV )\n EMNORM = DLANGE( '1-norm', N, N, A, LDA, DWORK(JWORA1) )\nC\nC Compute auxiliary quantities needed for the accuracy estimates.\nC\n BIG = ONE\n SMALL = ONE\n IF ( LBALS ) THEN\nC\nC Compute norms of the diagonal scaling matrix and its inverse.\nC\n DO 240 I = 1, N\n U = DWORK(JWORV1+I-1)\n IF ( BIG.LT.U ) BIG = U\n IF ( SMALL.GT.U ) SMALL = U\n 240 CONTINUE\nC\n SUM2D = DNRM2( N, DWORK(JWORV1), 1 )\n ELSE\n SUM2D = SQRT( XN )\n END IF\nC\nC Update the exponential for the initial translation, and update the\nC auxiliary quantities needed for the accuracy estimates.\nC\n SD2 = SQRT( EIGHT*XN*VAREPS )*ANORM\n BD = SQRT( VAR )\n SS = MAX( BD, SD2 )\n BD = MIN( BD, SD2 )\n SD2 = SS*SQRT( ONE + ( BD/SS )**2 )\n IF ( SD2.LE.ONE ) THEN\n SD2 = ( TWO/XN )*SUM2D*SD2\n ELSE IF ( SUM2D/XN.LT.OVRTHR/TWO/SD2 ) THEN\n SD2 = ( TWO/XN )*SUM2D*SD2\n ELSE\n SD2 = OVRTHR\n END IF\n IF ( LBALS ) THEN\n SIZE = ZERO\n ELSE\n IF ( SD2.LT.OVRTHR - EMNORM ) THEN\n SIZE = EMNORM + SD2\n ELSE\n SIZE = OVRTHR\n END IF\n END IF\nC\n DO 260 J = 1, N\n SS = DASUM( N, A(1,J), 1 )\n CALL DSCAL( N, EAVGEV, A(1,J), 1 )\n IF ( LBALS ) THEN\n BD = DWORK(JWORV1+J-1)\n SIZE = MAX( SIZE, SS + SD2/BD )\n END IF\n 260 CONTINUE\nC\nC Set the accuracy estimates and warning errors, if any.\nC\n RERR = LOG10( BIG ) + LOG10( EABS ) - LOG10( SMALL ) -\n $ LOG10( EMNORM ) - LOG10( EPS )\n IF ( SIZE.GT.EMNORM ) THEN\n RERL = LOG10( ( SIZE/EMNORM - ONE )/EPS )\n ELSE\n RERL = ZERO\n END IF\n MDIG = MIN( NDEC - INT( RERR + HALF ), NDECM1 )\n IDIG = MIN( NDEC - INT( RERL + HALF ), NDECM1 )\nC\n IF ( MDIG.LE.0 ) THEN\n MDIG = 0\n IWARN = 1\n END IF\n IF ( IDIG.LE.0 ) THEN\n IDIG = 0\n IWARN = 2\n END IF\nC\n RETURN\nC *** Last line of MB05OD ***\n END\n", "meta": {"hexsha": "10dbdc5d3c091354ee4d82157d6ae797124eb669", "size": 17591, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB05OD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB05OD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB05OD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 31.3565062389, "max_line_length": 72, "alphanum_fraction": 0.5069637883, "num_tokens": 5793, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9399133498259924, "lm_q2_score": 0.7310585727705126, "lm_q1q2_score": 0.6871317120517415}} {"text": "! PR tree-optimization/65450\n! { dg-do run }\n! { dg-additional-options \"-mtune=amdfam10\" { target x86_64-*-* i?86-*-* } }\n\nprogram pr65450\n integer :: n, m, o, i, k\n double precision :: u(500,60,3), h(500,60,3)\n double precision :: v(500,60)\n u = 0\n h = 0\n o = 1\n m = 2\n n = 3\n do k = 1, 50\n v = foo (u(:,:,m))\n u(2:499,1:60,n) = u(2:499,1:60,o)+16.d0\n h(1:500,2:59,n) = h(1:500,2:59,o)-4.d0*v(1:500,2:59)-32.0d0\n i = o\n o = m\n m = n\n n = i\n end do\n if (abs (v(17, 23) + h(17, 23, 2) + 768.0d0) > 0.5d0) STOP 1\ncontains\n function foo(a)\n double precision :: a(:,:)\n double precision :: foo(size(a,dim=1),size(a,dim=2))\n integer :: i, j\n i = size(a,dim=1)\n j = size(a,dim=2)\n foo(2:i-1,1:j) = a(3:i,1:j)-a(1:i-2,1:j)\n foo(1,1:j) = 2*(a(2,1:j)-a(1,1:j))\n foo(i,1:j) = 2*(a(i,1:j)-a(i-1,1:j))\n end function foo\nend program pr65450\n", "meta": {"hexsha": "856eed590cd43c2d08acb5bf6c3289dba18b2fe7", "size": 886, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/pr65450.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/pr65450.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/pr65450.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.6111111111, "max_line_length": 76, "alphanum_fraction": 0.5158013544, "num_tokens": 430, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118111485245, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.6871157796051431}} {"text": "!program:\n!this program is based on Conjugate Gradient.\n!it's purpose is to get x from Ax=b with a positive definite and symmetrical mat!rix A\n!history:\n!2012/3/2(finished)\tdon \tfirst release\n\n\nmodule sub1\n\tcontains \n!The following subroutine is the to get x from Ax=b by Conjugate Gradient\n!N is the N_max ,this method is come from \"\u77e9\u9635\u8ba1\u7b97\u7684\u7406\u8bba\u4e0e\u65b9\u6cd5\"\u5317\u5927\u5f90\u6811\u65b9p154 \n!with a little change\n\tsubroutine cg(A,b,x,N)\n\t!variable\tmeaning\n\t!A\t\ta matrix,from main program,is coefficient matrix of Ax=b\n\t!b\t\ta vector,from main program,is righthand of Ax=b\n\t!x\t\ta vector,the answer of Ax=b,is what we need,our goal\n\t!r\t\ta vector,minus grads of 0.5xAx-bx at x point,says b-Ax\n\t!p\t\ta vector,the direction of iteration better than r\n\t!w\t\ta vector,value is A*p,is useful to simplify the process\n\t!q0\t\ta number,value is r0*r0,is standard of loop times\n\t!q1\t\ta number,value is rk-1*rk-1\n\t!q2\t\ta number, value is rk*rk\n\t!ba,ar\t\ta number,named by their pronounciation\n\t!e\t\ta number,standard of loop times,input by client\n\t!test\t\ta number,value is matmul(r,w)\n\t!pw\t\ta number,value is matmul(p,w)\n\t!i\t\ta number,count variable\n\t!N\t\ta number,the degree of A\n\t\treal*8 A(N,N)\n\t\treal*8 b(N),x(N),r(N),p(N),w(N)\n\t\t!real*8 A(2,2),b(2),x(2),r(2),p(2),w(2)\n\t\treal*8 q0,q1,q2,ba,ar,e,test,pw\n\t\tinteger i,N\n\t\twrite(*,*)\"you want the x_error less than\"\n\t\tread(*,*)e\n\t\tx=0.0\n\t\tr=b\n\t\tcall onedimenmul(r,r,N,q0)\n\t\tq2=q0\n\t\tp=r\n\n\t!\tw=matmul(A,p)\n\t!\tcall onedimenmul(r,w,2,test)\n\t!\tar=q2/test\n\t!\tx=x+ar*p\n\t!\tr=r-ar*w\n\t!\tq1=q2;call onedimenmul(r,r,2,q2)\n\t!\t!r=r-a*w\n\t\ti=1\n\t\tdo while(q2>=q0*e)\n\t\tq1=q2\n\t!\tba=q2/q1\n\t!\tp=r+ba*p\n\t\t\n\t\tw=matmul(A,p)\n\t\tcall onedimenmul(p,w,N,pw)!pw is p*w\n\t\tar=q1/pw\n\t\tx=x+ar*p\n\t\tr=r-ar*w\n\t\tcall onedimenmul(r,r,N,q2)\n\t\t!r=r-a*w\n\t\tba=q2/q1\n\t\ti=i+1\n\t\tp=r+ba*p\n\t\tend do\n\twrite(*,*)\"x\",x\n\twrite(*,*)\"i\",i\n\tend subroutine cg\n\n\t!This subroutine is to solve one dimention's multiplication\n\tsubroutine onedimenmul(m1,m2,n,ans)\n\tinteger n\n\treal*8 m1(n),m2(n),ans\n\tans=0\n\tdo i=1,n\n\t\tans=m1(i)*m2(i)+ans\n\tend do\n\t\n\tend subroutine onedimenmul\nend module sub1\n\n", "meta": {"hexsha": "010c530613d5a9e88331a9de73d7d7a98e6a8f02", "size": 2026, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "conjugate_gradient/sub1.f90", "max_stars_repo_name": "DearDon/Matrix", "max_stars_repo_head_hexsha": "b76477860e673f9c124ad7a9bc83f9b0eaca1661", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "conjugate_gradient/sub1.f90", "max_issues_repo_name": "DearDon/Matrix", "max_issues_repo_head_hexsha": "b76477860e673f9c124ad7a9bc83f9b0eaca1661", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "conjugate_gradient/sub1.f90", "max_forks_repo_name": "DearDon/Matrix", "max_forks_repo_head_hexsha": "b76477860e673f9c124ad7a9bc83f9b0eaca1661", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.4096385542, "max_line_length": 86, "alphanum_fraction": 0.6712734452, "num_tokens": 815, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765328159727, "lm_q2_score": 0.7520125848754472, "lm_q1q2_score": 0.687096251182976}} {"text": " SUBROUTINE JuLDATE(IC,MONTH,DAY,YEAR,DATE)\nC\nC PURPOSE\nC TO CONVERT GREGORIAN DATES TO MODIFIED JULIAN DATES AND\nC MODIFIED JULIAN DATES (MJD = JD - 2440000.) TO GREGORIAN\nC\nC FORTRAN USAGE\nC CALL JLDATE(IC,MONTH,DAY,YEAR,DATE)\nC IC -=0 IF CONVERSION IS GREGORIAN TO JULIAN\nC =1 IF CONVERSION IS JULIAN TO GREGORIAN\nC MONTH- MONTH(INTEGER)\nC DAY - DAY(INTEGER)\nC YEAR - YEAR(INTEGER)\nC DATE - JULIAN DATE(FLOATING POINT)\nC\nc IMPLICIT UNDEFINED(A-Z)\n INTEGER MTHDAY(12) \n INTEGER DAY,YEAR,IC,ND,MONTH,I\n REAL*8 DATE\n DATA MTHDAY/31,28,31,30,31,30,31,31,30,31,30,31/\n IF(IC)1,1,6\n 1 ND=DAY+365.25*YEAR\n IF(YEAR/4*4-YEAR)4,2,4\n 2 IF(MONTH.LE.2)ND=ND-1\n 4 DO 5 I=2,MONTH\n 5 ND=ND+MTHDAY(I-1)\n DATE=ND-718955.5\n RETURN\nC THE NEXT LINE INSERTED OCT 78 TO IMPROVE PRECISION TO A FEW MS\nC DATE=IDINT(DATE)+0.5\n 6 ND=DATE+718955.5\n YEAR=ND/365.25\n ND = ND - INT(365.25*YEAR)\n IF(YEAR/4*4-YEAR)10,7,10\n7 IF(ND-59)9,8,10\n8 MONTH = 2\n DAY = 29\n RETURN\n9 ND = ND + 1 \n10 DO 11 I = 1,12 \n IF(ND.LE.MTHDAY(I)) GO TO 12 \n11 ND = ND - MTHDAY(I) \n I = 12 \n12 MONTH = I \n DAY = ND \n RETURN \n END \n", "meta": {"hexsha": "b75979e5e16905e36e988dee6024530c0dd20960", "size": 1768, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Base/Formats/UVM/uvmlib/juldate.f", "max_stars_repo_name": "xuanyuanstar/psrchive_CDFT", "max_stars_repo_head_hexsha": "453c4dc05b8e901ea661cd02d4f0a30665dcaf35", "max_stars_repo_licenses": ["AFL-2.1"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Base/Formats/UVM/uvmlib/juldate.f", "max_issues_repo_name": "xuanyuanstar/psrchive_CDFT", "max_issues_repo_head_hexsha": "453c4dc05b8e901ea661cd02d4f0a30665dcaf35", "max_issues_repo_licenses": ["AFL-2.1"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Base/Formats/UVM/uvmlib/juldate.f", "max_forks_repo_name": "xuanyuanstar/psrchive_CDFT", "max_forks_repo_head_hexsha": "453c4dc05b8e901ea661cd02d4f0a30665dcaf35", "max_forks_repo_licenses": ["AFL-2.1"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-02-13T20:08:14.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-13T20:08:14.000Z", "avg_line_length": 36.8333333333, "max_line_length": 83, "alphanum_fraction": 0.4230769231, "num_tokens": 523, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765257642905, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.687096240801968}} {"text": " SUBROUTINE VCC(X1,Y1,X2,Y2,NS,R2)\n IMPLICIT none\n!\n! PROGRAM IN FORTRAN 77 TO CALCULATE THE VECTOR CORRELATION\n! COEFFICIENT OF JUPP AND MARDIA(BIOMETRIKA,1980).\n!\n! THE FOLLOWING PROGRAM CALCULATES THE VECTOR CORRELATION BETWEEN\n! SEQUENCES OF TWO-DIMENSIONAL VECTORS. THESE VECTORS MUST BE\n! SPECIFIED IN TERMS OF THEIR U(X1,Y1) AND V(X2,Y2) COMPONENTS.\n! FOR TWO-DIMENSIONAL VECTORS, THE VECTOR CORRELATION COEFFICIENT\n! (SQUARED) WILL VARY BETWEEN 0.0(UNCORRELATED) AND 2.0\n! (COMPLETELY CORRELATED).\n!\n! VECTOR CORRELATION COEFFICIENTS CALCULATED ACCORDING TO THE\n! FOLLOWING PROGRAM SHOULD BE ACCURATE TO AT LEAST THREE DECIMAL\n! PLACES USING SINGLE PRECISION ARITHMETIC.\n!\n! NS IS THE SAMPLE SIZE - SAMPLE SIZES LESS THAN 8 ARE NOT\n! RECOMMENDED BECAUSE THE ASYMPTOTIC CHI-SQUARE DISTRIBUTION\n! BREAKS DOWN FOR SMALLER VALUES.\n!\n! Origin: Crosby, Breaker, Gemmill\n!\n! Maintenance: Robert Grumbine\n! Dec 1998\n!\n INTEGER NS\n REAL VAR1,VAR2,VAR3,VAR4,COV12,COV13,COV14,COV23,COV24,\n *COV34,X1(NS),Y1(NS),X2(NS),Y2(NS),R2\n!\n CALL STAT1(X1,Y1,X2,Y2,NS,VAR1,VAR2,COV12)\n CALL STAT2(X1,Y1,X2,Y2,NS,VAR1,VAR3,COV13)\n CALL STAT3(X1,Y1,X2,Y2,NS,VAR1,VAR4,COV14)\n CALL STAT4(X1,Y1,X2,Y2,NS,VAR2,VAR3,COV23)\n CALL STAT5(X1,Y1,X2,Y2,NS,VAR2,VAR4,COV24)\n CALL STAT6(X1,Y1,X2,Y2,NS,VAR3,VAR4,COV34)\n CALL RSQ(VAR1,VAR2,VAR3,VAR4,COV12,COV13,COV14,COV23,\n * COV24,COV34,R2)\n RETURN\n END\n SUBROUTINE STAT1(X1,Y1,X2,Y2,NS,VAR1,VAR2,COV12)\n IMPLICIT none\n INTEGER I, NS\n REAL VAR1,VAR2,COV12,SUMX1,SUMY1,SX1SQ,SY1SQ,SX1Y1,\n *X1(*),Y1(*),X2(*),Y2(*)\n SUMX1 = 0.0\n SUMY1 = 0.0\n SX1SQ = 0.0\n SY1SQ = 0.0\n SX1Y1 = 0.0\n DO I = 1,NS\n SUMX1 = SUMX1 + X1(I)\n SUMY1 = SUMY1 + Y1(I)\n SX1SQ = SX1SQ + X1(I)*X1(I)\n SY1SQ = SY1SQ + Y1(I)*Y1(I)\n SX1Y1 = SX1Y1 + X1(I)*Y1(I)\n ENDDO\n VAR1 = (FLOAT(NS) * SX1SQ - SUMX1 * SUMX1) / FLOAT(NS * (NS - 1))\n VAR2 = (FLOAT(NS) * SY1SQ - SUMY1 * SUMY1) / FLOAT(NS * (NS - 1))\n COV12 = (FLOAT(NS) * SX1Y1 - SUMX1 * SUMY1) / FLOAT(NS * (NS - 1))\n RETURN\n END\n SUBROUTINE STAT2(X1,Y1,X2,Y2,NS,VAR1,VAR3,COV13)\n IMPLICIT none\n INTEGER I, NS\n REAL VAR1,VAR3,COV13,SUMX1,SUMX2,SX1SQ,SX2SQ,SX1X2,\n *X1(*),Y1(*),X2(*),Y2(*)\n SUMX1 = 0.0\n SUMX2 = 0.0\n SX1SQ = 0.0\n SX2SQ = 0.0\n SX1X2 = 0.0\n DO I = 1,NS\n SUMX1 = SUMX1 + X1(I)\n SUMX2 = SUMX2 + X2(I)\n SX1SQ = SX1SQ + X1(I)*X1(I)\n SX2SQ = SX2SQ + X2(I)*X2(I)\n SX1X2 = SX1X2 + X1(I)*X2(I)\n ENDDO\n VAR1 = (FLOAT(NS) * SX1SQ - SUMX1 * SUMX1) / FLOAT(NS * (NS - 1))\n VAR3 = (FLOAT(NS) * SX2SQ - SUMX2 * SUMX2) / FLOAT(NS * (NS - 1))\n COV13 = (FLOAT(NS) * SX1X2 - SUMX1 * SUMX2) / FLOAT(NS * (NS - 1))\n RETURN\n END\n SUBROUTINE STAT3(X1,Y1,X2,Y2,NS,VAR1,VAR4,COV14)\n IMPLICIT none\n INTEGER I, NS\n REAL VAR1,VAR4,COV14,SUMX1,SUMY2,SX1SQ,SY2SQ,SX1Y2,\n *X1(*),Y1(*),X2(*),Y2(*)\n SUMX1 = 0.0\n SUMY2 = 0.0\n SX1SQ = 0.0\n SY2SQ = 0.0\n SX1Y2 = 0.0\n DO I = 1,NS\n SUMX1 = SUMX1 + X1(I)\n SUMY2 = SUMY2 + Y2(I)\n SX1SQ = SX1SQ + X1(I)*X1(I)\n SY2SQ = SY2SQ + Y2(I)*Y2(I)\n SX1Y2 = SX1Y2 + X1(I)*Y2(I)\n ENDDO\n VAR1 = (FLOAT(NS) * SX1SQ - SUMX1 * SUMX1) / FLOAT(NS * (NS - 1))\n VAR4 = (FLOAT(NS) * SY2SQ - SUMY2 * SUMY2) / FLOAT(NS * (NS - 1))\n COV14 = (FLOAT(NS) * SX1Y2 - SUMX1 * SUMY2) / FLOAT(NS * (NS - 1))\n RETURN\n END\n SUBROUTINE STAT4(X1,Y1,X2,Y2,NS,VAR2,VAR3,COV23)\n IMPLICIT none\n INTEGER I, NS\n REAL VAR2,VAR3,COV23,SUMY1,SUMX2,SY1SQ,SX2SQ,SY1X2,\n *X1(*),Y1(*),X2(*),Y2(*)\n SUMY1 = 0.0\n SUMX2 = 0.0\n SY1SQ = 0.0\n SX2SQ = 0.0\n SY1X2 = 0.0\n DO I = 1,NS\n SUMY1 = SUMY1 + Y1(I)\n SUMX2 = SUMX2 + X2(I)\n SY1SQ = SY1SQ + Y1(I)*Y1(I)\n SX2SQ = SX2SQ + X2(I)*X2(I)\n SY1X2 = SY1X2 + Y1(I)*X2(I)\n ENDDO\n VAR2 = (FLOAT(NS) * SY1SQ - SUMY1 * SUMY1) / FLOAT(NS * (NS - 1))\n VAR3 = (FLOAT(NS) * SX2SQ - SUMX2 * SUMX2) / FLOAT(NS * (NS - 1))\n COV23 = (FLOAT(NS) * SY1X2 - SUMY1 * SUMX2) / FLOAT(NS * (NS - 1))\n RETURN\n END\n SUBROUTINE STAT5(X1,Y1,X2,Y2,NS,VAR2,VAR4,COV24)\n IMPLICIT none\n INTEGER I, NS\n REAL VAR2,VAR4,COV24,SUMY1,SUMY2,SY1SQ,SY2SQ,SY1Y2,\n *X1(*),Y1(*),X2(*),Y2(*)\n SUMY1 = 0.0\n SUMY2 = 0.0\n SY1SQ = 0.0\n SY2SQ = 0.0\n SY1Y2 = 0.0\n DO I = 1,NS\n SUMY1 = SUMY1 + Y1(I)\n SUMY2 = SUMY2 + Y2(I)\n SY1SQ = SY1SQ + Y1(I)*Y1(I)\n SY2SQ = SY2SQ + Y2(I)*Y2(I)\n SY1Y2 = SY1Y2 + Y1(I)*Y2(I)\n ENDDO\n VAR2 = (FLOAT(NS) * SY1SQ - SUMY1 * SUMY1) / FLOAT(NS * (NS - 1))\n VAR4 = (FLOAT(NS) * SY2SQ - SUMY2 * SUMY2) / FLOAT(NS * (NS - 1))\n COV24 = (FLOAT(NS) * SY1Y2 - SUMY1 * SUMY2) / FLOAT(NS * (NS - 1))\n RETURN\n END\n SUBROUTINE STAT6(X1,Y1,X2,Y2,NS,VAR3,VAR4,COV34)\n IMPLICIT none\n INTEGER I, NS\n REAL VAR3,VAR4,COV34,SUMX2,SUMY2,SX2SQ,SY2SQ,SX2Y2,\n *X1(*),Y1(*),X2(*),Y2(*)\n SUMX2 = 0.0\n SUMY2 = 0.0\n SX2SQ = 0.0\n SY2SQ = 0.0\n SX2Y2 = 0.0\n DO I = 1,NS\n SUMX2 = SUMX2 + X2(I)\n SUMY2 = SUMY2 + Y2(I)\n SX2SQ = SX2SQ + X2(I)*X2(I)\n SY2SQ = SY2SQ + Y2(I)*Y2(I)\n SX2Y2 = SX2Y2 + X2(I)*Y2(I)\n ENDDO\n VAR3 = (FLOAT(NS) * SX2SQ - SUMX2 * SUMX2) / FLOAT(NS * (NS - 1))\n VAR4 = (FLOAT(NS) * SY2SQ - SUMY2 * SUMY2) / FLOAT(NS * (NS - 1))\n COV34 = (FLOAT(NS) * SX2Y2 - SUMX2 * SUMY2) / FLOAT(NS * (NS - 1))\n RETURN\n END\n SUBROUTINE RSQ(VAR1,VAR2,VAR3,VAR4,COV12,COV13,COV14,\n *COV23,COV24,COV34,R2)\n IMPLICIT none\n REAL R,R2,VAR1,VAR2,VAR3,VAR4,COV12,COV13,COV14,COV23,\n *COV24,COV34,A1,A2,A3,A4,A5,A6,A7,A8,B1,B2,B3,B4,B5,B6,\n *B7,B8,C,D,E,F,G,H,I,J,M,N,T1,T2,U1,U2,T,U,P\n A1 = VAR2 * COV13\n A2 = COV12 * COV23\n A3 = VAR4 * COV13\n A4 = COV34 * COV14\n A5 = VAR2 * COV14\n A6 = COV12 * COV24\n A7 = COV34 * COV13\n A8 = VAR3 * COV14\n B1 = COV12 * COV13\n B2 = VAR1 * COV23\n B3 = VAR4 * COV23\n B4 = COV34 * COV24\n B5 = COV12 * COV14\n B6 = VAR1 * COV24\n B7 = COV34 * COV23\n B8 = VAR3 * COV24\n C = A1 - A2\n D = A3 - A4\n E = A5 - A6\n F = A8 - A7\n G = B2 - B1\n H = B3 - B4\n I = B6 - B5\n J = B8 - B7\n M = C*D + E*F\n N = G*H + I*J\n T1 = VAR1 * VAR2\n T2 = COV12 * COV12\n U1 = VAR3 * VAR4\n U2 = COV34 * COV34\n T = T1 - T2\n U = U1 - U2\n P = T * U\n R2 = (M + N)/P\n R = SQRT(R2)\n RETURN\n END\n", "meta": {"hexsha": "1629195d417da8346a13f7fd49b7003c734ea9b7", "size": 6828, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "sorc/VCC.f", "max_stars_repo_name": "rgrumbine/mmablib", "max_stars_repo_head_hexsha": "107ba1b1026c3cfed97346233c9a76d3d170d544", "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": "sorc/VCC.f", "max_issues_repo_name": "rgrumbine/mmablib", "max_issues_repo_head_hexsha": "107ba1b1026c3cfed97346233c9a76d3d170d544", "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": "sorc/VCC.f", "max_forks_repo_name": "rgrumbine/mmablib", "max_forks_repo_head_hexsha": "107ba1b1026c3cfed97346233c9a76d3d170d544", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.6111111111, "max_line_length": 72, "alphanum_fraction": 0.5311950791, "num_tokens": 3103, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.913676530465412, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6870962392592163}} {"text": "!*********************************************************************\n! This file is part of Polylogarithm.\n!\n! Polylogarithm is licenced under the MIT License.\n!*********************************************************************\n\n!*********************************************************************\n!> @brief Clausen function \\f$\\operatorname{Cl}_2(\\theta) = \\operatorname{Im}(\\operatorname{Li}_2(e^{i\\theta}))\\f$\n!> @param x real angle\n!> @return \\f$\\operatorname{Cl}_2(\\theta)\\f$\n!> @author Alexander Voigt\n!> Implemented as rational function approximation.\n!*********************************************************************\n\ndouble precision function dcl2(x)\n implicit none\n double precision :: x, y, z, z2, z4, p, q, p0, p1, h, sgn\n double precision, parameter :: PI = 3.14159265358979324D0\n double precision, parameter :: PI2 = 2*PI, PIH = PI/2, PI28 = PI*PI/8\n double precision, parameter :: cp(4) = (/ &\n 1.3888888888888889D-2, &\n -4.3286930203743071D-4, &\n 3.2779814789973427D-6, &\n -3.6001540369575084D-9 /)\n double precision, parameter :: cq(4) = (/ &\n 1.0000000000000000D+0, &\n -3.6166589746694121D-2, &\n 3.6015827281202639D-4, &\n -8.3646182842184428D-7 /)\n double precision, parameter :: cr(6) = (/ &\n 6.4005702446195512D-1, &\n -2.0641655351338783D-1, &\n 2.4175305223497718D-2, &\n -1.2355955287855728D-3, &\n 2.5649833551291124D-5, &\n -1.4783829128773320D-7 /)\n double precision, parameter :: cs(6) = (/ &\n 1.0000000000000000D+0, &\n -2.5299102015666356D-1, &\n 2.2148751048467057D-2, &\n -7.8183920462457496D-4, &\n 9.5432542196310670D-6, &\n -1.8184302880448247D-8 /)\n\n sgn = 1\n\n if (x .lt. 0) then\n x = -x\n sgn = -1\n endif\n\n if (x .ge. PI2) then\n x = mod(x, PI2)\n endif\n\n if (x .gt. PI) then\n p0 = 6.28125D0\n p1 = 0.0019353071795864769253D0\n x = (p0 - x) + p1\n sgn = -sgn\n endif\n\n if (x .eq. 0 .or. x .eq. PI) then\n dcl2 = 0\n return\n endif\n\n if (x .lt. PIH) then\n y = x*x\n z = y*y\n p = cp(1) + y * cp(2) + z * (cp(3) + y * cp(4))\n q = cq(1) + y * cq(2) + z * (cq(3) + y * cq(4))\n h = x*(1 - log(x) + y*p/q)\n else\n y = PI - x\n z = y*y - PI28\n z2 = z*z\n z4 = z2*z2\n p = cr(1) + z * cr(2) + z2 * (cr(3) + z * cr(4)) + &\n z4 * (cr(5) + z * cr(6))\n q = cs(1) + z * cs(2) + z2 * (cs(3) + z * cs(4)) + &\n z4 * (cs(5) + z * cs(6))\n h = y*p/q\n endif\n\n dcl2 = sgn*h\n\nend function dcl2\n", "meta": {"hexsha": "457ec1120ac7a29063421a6f5cdba0eb2481412f", "size": 2795, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/Cl2.f90", "max_stars_repo_name": "Expander/dilogarithm", "max_stars_repo_head_hexsha": "ad86038206895ab5bff79a26294f4bb5c5634eb5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-05-04T14:47:41.000Z", "max_stars_repo_stars_event_max_datetime": "2017-08-02T13:13:45.000Z", "max_issues_repo_path": "src/fortran/Cl2.f90", "max_issues_repo_name": "Expander/dilogarithm", "max_issues_repo_head_hexsha": "ad86038206895ab5bff79a26294f4bb5c5634eb5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/fortran/Cl2.f90", "max_forks_repo_name": "Expander/dilogarithm", "max_forks_repo_head_hexsha": "ad86038206895ab5bff79a26294f4bb5c5634eb5", "max_forks_repo_licenses": ["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.404494382, "max_line_length": 114, "alphanum_fraction": 0.4379248658, "num_tokens": 997, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765234137297, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6870962390343167}} {"text": "! written by jxzou at 20180616\n\n! This subroutine/program will first compute the U matrix between two sets of MO (coeff1 and lo_coeff1)\n! then apply U onto coeff2 and the result is stored in new_coeff2\n\n! For GNU compiler, use\n! ------------------------------------------------------\n! f2py -m assoc_rot -c assoc_rot.f90 --link-lapack_opt\n! ------------------------------------------------------\n! For INTEL compiler, use\n! ---------------------------------------------------------------------------------------------\n! f2py -m assoc_rot -c assoc_rot.f90 --link-lapack_opt --fcompiler=intelem --compiler=intelem\n! ---------------------------------------------------------------------------------------------\n\nsubroutine assoc_rot(nbf, nmo, coeff1, lo_coeff1, coeff2, new_coeff2)\n implicit none\n integer i, info\n integer nbf, nmo\n!f2py intent(in) :: nbf, nmo\n integer, allocatable :: ipiv(:)\n real(kind=8) coeff1(nbf,nmo), lo_coeff1(nbf,nmo), coeff2(nbf,nmo)\n real(kind=8) new_coeff2(nbf,nmo)\n!f2py intent(in,copy) :: coeff1, lo_coeff1\n!f2py intent(in) :: coeff2\n!f2py intent(out) :: new_coeff2\n!f2py depend(nbf,nmo) coeff1, lo_coeff1, coeff2, new_coeff2\n\n ! mkl Syntax FORTRAN 77:\n ! ?getrf: Computes the LU factorization of a general m-by-n matrix\n ! call dgetrf(m, n, a, lda, ipiv, info)\n\n ! ?getrs: Solves a system of linear equations with an LU-factored square\n ! matrix, with multiple right-hand sides.\n ! call dgetrs(trans, n, nrhs, a, lda, ipiv, b, ldb, info)\n\n ! ?gemm: Computes a matrix-matrix product with general matrix\n ! call dgemm(transa, transb, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc)\n\n ! find the unitary (orthogonal) matrix between coeff1 and lo_coeff1,\n ! where coeff1*U = lo_coeff1\n allocate(ipiv(min(nbf,nmo)))\n ipiv = 0\n call dgetrf(nbf, nmo, coeff1, nbf, ipiv, info)\n call dgetrs('N', nmo, nmo, coeff1, nbf, ipiv, lo_coeff1, nbf, info)\n deallocate(ipiv)\n\n ! reverse the coeff2\n forall(i = 1:nmo)\n coeff1(:,i) = coeff2(:,nmo-i+1)\n end forall\n coeff2 = coeff1\n ! rotate the coeff2\n new_coeff2 = 0d0\n call dgemm('N', 'N', nbf, nmo, nmo, 1d0, coeff2, nbf, lo_coeff1, nbf, 0d0, new_coeff2, nbf)\n ! reverse the coeff2 again\n forall(i = 1:nmo)\n coeff1(:,i) = new_coeff2(:,nmo-i+1)\n end forall\n new_coeff2 = coeff1\n return\nend subroutine assoc_rot\n\n", "meta": {"hexsha": "d8146118bde07915232e49e05d662d0c64a5e7e6", "size": 2279, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/assoc_rot.f90", "max_stars_repo_name": "1234zou/MOKIT", "max_stars_repo_head_hexsha": "47171b0c168212ef27281882085fbb23055c3ea3", "max_stars_repo_licenses": ["FSFAP"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2022-01-19T09:25:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-30T06:12:43.000Z", "max_issues_repo_path": "src/assoc_rot.f90", "max_issues_repo_name": "1234zou/MOKIT", "max_issues_repo_head_hexsha": "47171b0c168212ef27281882085fbb23055c3ea3", "max_issues_repo_licenses": ["FSFAP"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-01-21T14:00:28.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-21T15:02:39.000Z", "max_forks_repo_path": "src/assoc_rot.f90", "max_forks_repo_name": "1234zou/MOKIT", "max_forks_repo_head_hexsha": "47171b0c168212ef27281882085fbb23055c3ea3", "max_forks_repo_licenses": ["FSFAP"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.1746031746, "max_line_length": 103, "alphanum_fraction": 0.6147433085, "num_tokens": 705, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765187126079, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6870962304209598}} {"text": " subroutine dchex(r,ldr,p,k,l,z,ldz,nz,c,s,job)\n integer ldr,p,k,l,ldz,nz,job\n double precision r(ldr,1),z(ldz,1),s(1)\n double precision c(1)\nc\nc dchex updates the cholesky factorization\nc\nc a = trans(r)*r\nc\nc of a positive definite matrix a of order p under diagonal\nc permutations of the form\nc\nc trans(e)*a*e\nc\nc where e is a permutation matrix. specifically, given\nc an upper triangular matrix r and a permutation matrix\nc e (which is specified by k, l, and job), dchex determines\nc a orthogonal matrix u such that\nc\nc u*r*e = rr,\nc\nc where rr is upper triangular. at the users option, the\nc transformation u will be multiplied into the array z.\nc if a = trans(x)*x, so that r is the triangular part of the\nc qr factorization of x, then rr is the triangular part of the\nc qr factorization of x*e, i.e. x with its columns permuted.\nc for a less terse description of what dchex does and how\nc it may be applied, see the linpack guide.\nc\nc the matrix q is determined as the product u(l-k)*...*u(1)\nc of plane rotations of the form\nc\nc ( c(i) s(i) )\nc ( ) ,\nc ( -s(i) c(i) )\nc\nc where c(i) is double precision, the rows these rotations operate\nc on are described below.\nc\nc there are two types of permutations, which are determined\nc by the value of job.\nc\nc 1. right circular shift (job = 1).\nc\nc the columns are rearranged in the following order.\nc\nc 1,...,k-1,l,k,k+1,...,l-1,l+1,...,p.\nc\nc u is the product of l-k rotations u(i), where u(i)\nc acts in the (l-i,l-i+1)-plane.\nc\nc 2. left circular shift (job = 2).\nc the columns are rearranged in the following order\nc\nc 1,...,k-1,k+1,k+2,...,l,k,l+1,...,p.\nc\nc u is the product of l-k rotations u(i), where u(i)\nc acts in the (k+i-1,k+i)-plane.\nc\nc on entry\nc\nc r double precision(ldr,p), where ldr.ge.p.\nc r contains the upper triangular factor\nc that is to be updated. elements of r\nc below the diagonal are not referenced.\nc\nc ldr integer.\nc ldr is the leading dimension of the array r.\nc\nc p integer.\nc p is the order of the matrix r.\nc\nc k integer.\nc k is the first column to be permuted.\nc\nc l integer.\nc l is the last column to be permuted.\nc l must be strictly greater than k.\nc\nc z double precision(ldz,nz), where ldz.ge.p.\nc z is an array of nz p-vectors into which the\nc transformation u is multiplied. z is\nc not referenced if nz = 0.\nc\nc ldz integer.\nc ldz is the leading dimension of the array z.\nc\nc nz integer.\nc nz is the number of columns of the matrix z.\nc\nc job integer.\nc job determines the type of permutation.\nc job = 1 right circular shift.\nc job = 2 left circular shift.\nc\nc on return\nc\nc r contains the updated factor.\nc\nc z contains the updated matrix z.\nc\nc c double precision(p).\nc c contains the cosines of the transforming rotations.\nc\nc s double precision(p).\nc s contains the sines of the transforming rotations.\nc\nc linpack. this version dated 08/14/78 .\nc g.w. stewart, university of maryland, argonne national lab.\nc\nc dchex uses the following functions and subroutines.\nc\nc blas drotg\nc fortran min0\nc\n integer i,ii,il,iu,j,jj,km1,kp1,lmk,lm1\n double precision rjp1j,t\nc\nc initialize\nc\n km1 = k - 1\n kp1 = k + 1\n lmk = l - k\n lm1 = l - 1\nc\nc perform the appropriate task.\nc\n go to (10,130), job\nc\nc right circular shift.\nc\n 10 continue\nc\nc reorder the columns.\nc\n do 20 i = 1, l\n ii = l - i + 1\n s(i) = r(ii,l)\n 20 continue\n do 40 jj = k, lm1\n j = lm1 - jj + k\n do 30 i = 1, j\n r(i,j+1) = r(i,j)\n 30 continue\n r(j+1,j+1) = 0.0d0\n 40 continue\n if (k .eq. 1) go to 60\n do 50 i = 1, km1\n ii = l - i + 1\n r(i,k) = s(ii)\n 50 continue\n 60 continue\nc\nc calculate the rotations.\nc\n t = s(1)\n do 70 i = 1, lmk\n call drotg(s(i+1),t,c(i),s(i))\n t = s(i+1)\n 70 continue\n r(k,k) = t\n do 90 j = kp1, p\n il = max0(1,l-j+1)\n do 80 ii = il, lmk\n i = l - ii\n t = c(ii)*r(i,j) + s(ii)*r(i+1,j)\n r(i+1,j) = c(ii)*r(i+1,j) - s(ii)*r(i,j)\n r(i,j) = t\n 80 continue\n 90 continue\nc\nc if required, apply the transformations to z.\nc\n if (nz .lt. 1) go to 120\n do 110 j = 1, nz\n do 100 ii = 1, lmk\n i = l - ii\n t = c(ii)*z(i,j) + s(ii)*z(i+1,j)\n z(i+1,j) = c(ii)*z(i+1,j) - s(ii)*z(i,j)\n z(i,j) = t\n 100 continue\n 110 continue\n 120 continue\n go to 260\nc\nc left circular shift\nc\n 130 continue\nc\nc reorder the columns\nc\n do 140 i = 1, k\n ii = lmk + i\n s(ii) = r(i,k)\n 140 continue\n do 160 j = k, lm1\n do 150 i = 1, j\n r(i,j) = r(i,j+1)\n 150 continue\n jj = j - km1\n s(jj) = r(j+1,j+1)\n 160 continue\n do 170 i = 1, k\n ii = lmk + i\n r(i,l) = s(ii)\n 170 continue\n do 180 i = kp1, l\n r(i,l) = 0.0d0\n 180 continue\nc\nc reduction loop.\nc\n do 220 j = k, p\n if (j .eq. k) go to 200\nc\nc apply the rotations.\nc\n iu = min0(j-1,l-1)\n do 190 i = k, iu\n ii = i - k + 1\n t = c(ii)*r(i,j) + s(ii)*r(i+1,j)\n r(i+1,j) = c(ii)*r(i+1,j) - s(ii)*r(i,j)\n r(i,j) = t\n 190 continue\n 200 continue\n if (j .ge. l) go to 210\n jj = j - k + 1\n t = s(jj)\n call drotg(r(j,j),t,c(jj),s(jj))\n 210 continue\n 220 continue\nc\nc apply the rotations to z.\nc\n if (nz .lt. 1) go to 250\n do 240 j = 1, nz\n do 230 i = k, lm1\n ii = i - km1\n t = c(ii)*z(i,j) + s(ii)*z(i+1,j)\n z(i+1,j) = c(ii)*z(i+1,j) - s(ii)*z(i,j)\n z(i,j) = t\n 230 continue\n 240 continue\n 250 continue\n 260 continue\n return\n end\n", "meta": {"hexsha": "e1e7a405ea20670654ba6f5fc828875441de4d12", "size": 6939, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "chollrup/dchex.f", "max_stars_repo_name": "maolingao/chollrup", "max_stars_repo_head_hexsha": "c93a00912e327abcf8a21fef7874a6371b827d61", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-10-30T00:53:35.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-23T21:50:19.000Z", "max_issues_repo_path": "chollrup/dchex.f", "max_issues_repo_name": "maolingao/chollrup", "max_issues_repo_head_hexsha": "c93a00912e327abcf8a21fef7874a6371b827d61", "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": "chollrup/dchex.f", "max_forks_repo_name": "maolingao/chollrup", "max_forks_repo_head_hexsha": "c93a00912e327abcf8a21fef7874a6371b827d61", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-23T21:50:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-20T08:08:13.000Z", "avg_line_length": 27.9798387097, "max_line_length": 70, "alphanum_fraction": 0.4826343854, "num_tokens": 2155, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765140114859, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.687096226885657}} {"text": "MODULE VTMOP_FUNC_MOD\n\nCONTAINS\n\nSUBROUTINE CONVEX(X, F, IFLAG)\n! Multiobjective test function whose component functions are each\n! quadratics. Let D denote the number of design variables and let P\n! denote the number of objectives. Then D must be greater than P >= 2, \n! and the recommended bounds are 0 < X(:) < 1. Both D and P are\n! assumed based on the dimensions of X(:) and F(:).\n!\n! For I = 1, ..., P, F(I) = ||X - 0.5e_I - 0.1e||^2, where e_I is the Ith\n! standard basis vector and e = (1, ..., 1).\n!\n!\n! On input:\n!\n! X(:) is a real valued design point in R^D.\n!\n!\n! On output:\n!\n! P(:) is a real valued objective point P = F(X).\n!\n! IFLAG is an error flag. With the following error codes:\n! 0 : Successful evaluation of DTLZ3\n! -1 : The design dimension D is not legal\n! -2 : The objective dimension P is not legal\n!\nUSE REAL_PRECISION, ONLY : R8\nIMPLICIT NONE\n! Input parameters.\nREAL(KIND=R8), INTENT(IN) :: X(:) ! Input design vector.\nREAL(KIND=R8), INTENT(OUT) :: F(:) ! Output objective vector.\nINTEGER, INTENT(OUT) :: IFLAG ! Error flag.\n! Local variables.\nINTEGER :: D, P ! Problem dimensions.\nINTEGER :: I ! Loop indexing variables.\nREAL(KIND=R8) :: E(SIZE(X,1)) ! Vector of standard basis vectors.\n! Get problem dimensions.\nD = SIZE(X,1)\nP = SIZE(F,1)\n! Throw errors for illegal inputs.\nIFLAG = 0\nIF (D < 1) THEN\n IFLAG = -1\n RETURN\nEND IF\nIF (D < P) THEN\n IFLAG = -2\n RETURN\nEND IF\n! Compute each component function.\nDO I = 1, P\n ! Set E(:) = 0.5e_I + 0.1e.\n E(:) = 0.1_R8\n E(I) = 0.6_R8\n ! Compute the value of F(I).\n F(I) = DOT_PRODUCT(X(:) - E(:), X(:) - E(:))\nEND DO\nRETURN\nEND SUBROUTINE CONVEX\n\nSUBROUTINE DTLZ1(X, F, IFLAG)\n! Multiobjective test function with a planar Pareto front. Let D\n! denote the number of design variables and let P denote the number\n! of objectives. Then it is a requirement that D >= P >= 2, and \n! the recommended bounds are 0 < X(:) < 1. Both D and P are\n! assumed based on the dimensions of X(:) and F(:).\n!\n! Credit for the design of this test function goes to\n!\n! K. Deb, L. Thiele, M. Laumanns, and E. Zitzler. 2005. Scalable test\n! problems for evolutionary multiobjective optimization. In Evolutionary\n! multiobjective optimization (pp. 105-145). Springer, London.\n!\n!\n! On input:\n!\n! X(:) is a real valued design point in R^D.\n!\n!\n! On output:\n!\n! P(:) is a real valued objective point P = F(X).\n!\n! IFLAG is an error flag. With the following error codes:\n! 0 : Successful evaluation of DTLZ3\n! -1 : The design dimension D is not legal\n! -2 : The objective dimension P is not legal\n!\nUSE REAL_PRECISION, ONLY : R8\nIMPLICIT NONE\n! Input parameters.\nREAL(KIND=R8), INTENT(IN) :: X(:) ! Input design vector.\nREAL(KIND=R8), INTENT(OUT) :: F(:) ! Output objective vector.\nINTEGER, INTENT(OUT) :: IFLAG ! Error flag.\n! Local variables.\nINTEGER :: D, P ! Problem dimensions.\nINTEGER :: I, J ! Loop indexing variables.\nREAL(KIND=R8) :: PI ! Constant value of pi.\n! Get problem dimensions.\nD = SIZE(X,1)\nP = SIZE(F,1)\n! Compute the value of PI.\nPI = 4.0_R8 * ATAN(1.0_R8)\n! Throw errors for illegal inputs.\nIFLAG = 0\nIF (D < 1) THEN\n IFLAG = -1\n RETURN\nEND IF\nIF (D < P) THEN\n IFLAG = -2\n RETURN\nEND IF\n! Get the first objective value.\nF(1) = 0.5_R8 * (1.0_R8 + G(X))\nDO J = 1, P-1\n F(1) = F(1) * X(J)\nEND DO\n! Get other objective values.\nDO I = 2, P\n F(I) = 0.5_R8 * (1.0_R8 + G(X)) * (1.0_R8 - X(P-I+1))\n DO J = 1, P-I\n F(I) = F(I) * X(J)\n END DO\nEND DO\nRETURN\n\nCONTAINS\n\nFUNCTION G(Z)\n! A scalar valued kernel function G_2, which produces many local Pareto\n! fonts in the landscape of DTLZ1.\n! Parameters.\nREAL(KIND=R8), INTENT(IN) :: Z(:) ! Input vector.\nREAL(KIND=R8) :: G ! Output scalar.\n! Local variables.\nINTEGER :: K\n! Compute the kernel function G(Z) for DTLZ1.\nG = 2.0_R8 * ( REAL(D-P,KIND=R8) + 1.0_R8 + &\n DOT_PRODUCT(Z(P:D) - 0.6_R8, Z(P:D) - 0.6_R8) )\nDO K = P, D\n G = G - 2.0_R8 * COS(20.0_R8 * PI * (Z(K) - 0.6_R8))\nEND DO\nRETURN\nEND FUNCTION G\n\nEND SUBROUTINE DTLZ1\n\nSUBROUTINE DTLZ2(X, F, IFLAG)\n! Multiobjective test function with a concave global Pareto front, shaped\n! like the unit sphere restricted to the positive orthant. Let D denote the\n! number of design variables and let P denote the number of objectives.\n! Then it is a requirement that D >= P >= 2, and the recommended bounds\n! are 0 < X(:) < 1. Both D and P are assumed based on the dimensions\n! of X(:) and F(:).\n!\n! Credit for the design of this test function goes to\n!\n! K. Deb, L. Thiele, M. Laumanns, and E. Zitzler. 2005. Scalable test\n! problems for evolutionary multiobjective optimization. In Evolutionary\n! multiobjective optimization (pp. 105-145). Springer, London.\n!\n!\n! On input:\n!\n! X(:) is a real valued design point in R^D.\n!\n!\n! On output:\n!\n! P(:) is a real valued objective point P = F(X).\n!\n! IFLAG is an error flag. With the following error codes:\n! 0 : Successful evaluation of DTLZ3\n! -1 : The design dimension D is not legal\n! -2 : The objective dimension P is not legal\n!\nUSE REAL_PRECISION, ONLY : R8\nIMPLICIT NONE\n! Input parameters.\nREAL(KIND=R8), INTENT(IN) :: X(:) ! Input design vector.\nREAL(KIND=R8), INTENT(OUT) :: F(:) ! Output objective vector.\nINTEGER, INTENT(OUT) :: IFLAG ! Error flag.\n! Local variables.\nINTEGER :: D, P ! Problem dimensions.\nINTEGER :: I, J ! Loop indexing variables.\nREAL(KIND=R8) :: PI ! Constant value of pi.\n! Get problem dimensions.\nD = SIZE(X,1)\nP = SIZE(F,1)\n! Compute the value of PI.\nPI = 4.0_R8 * ATAN(1.0_R8)\n! Throw errors for illegal inputs.\nIFLAG = 0\nIF (D < 1) THEN\n IFLAG = -1\n RETURN\nEND IF\nIF (D < P) THEN\n IFLAG = -2\n RETURN\nEND IF\n! Get the first objective value.\nF(1) = 1.0_R8 + G(X)\nDO J = 1, P-1\n F(1) = F(1) * COS(PI * X(J) / 2.0_R8)\nEND DO\n! Get other objective values.\nDO I = 1, P-1\n F(I+1) = (1.0_R8 + G(X)) * SIN(PI * X(P-I) / 2.0_R8)\n DO J = 1, P-I-1\n F(I+1) = F(I+1) * COS(PI * X(J) / 2.0_R8)\n END DO\nEND DO\n!IF (F(P) < 0.1_R8) IFLAG = -1 ! Tests taboo list when uncommented.\nRETURN\n\nCONTAINS\n\nFUNCTION G(Z)\n! A scalar valued kernel function G, which produces a single global/local\n! Pareto front for DTLZ2.\n! Parameters.\nREAL(KIND=R8), INTENT(IN) :: Z(:) ! Input vector.\nREAL(KIND=R8) :: G ! Output scalar.\n! Compute the kernel function G(Z) for DTLZ3.\nG = DOT_PRODUCT(Z(P:D) - 0.6_R8, Z(P:D) - 0.6_R8)\nRETURN\nEND FUNCTION G\n\nEND SUBROUTINE DTLZ2\n\nSUBROUTINE DTLZ3(X, F, IFLAG)\n! Multiobjective test function with a concave global Pareto front, shaped\n! like the unit sphere restricted to the positive orthant. Let D denote the\n! number of design variables and let P denote the number of objectives.\n! Then it is a requirement that D >= P >= 2, and the recommended bounds\n! are 0 < X(:) < 1. Both D and P are assumed based on the dimensions\n! of X(:) and F(:). There are 3^(1+P-D)-1 local Pareto fronts, where\n! a multiobjective optimization algorithm could get stuck.\n!\n! Credit for the design of this test function goes to\n!\n! K. Deb, L. Thiele, M. Laumanns, and E. Zitzler. 2005. Scalable test\n! problems for evolutionary multiobjective optimization. In Evolutionary\n! multiobjective optimization (pp. 105-145). Springer, London.\n!\n!\n! On input:\n!\n! X(:) is a real valued design point in R^D.\n!\n!\n! On output:\n!\n! P(:) is a real valued objective point P = F(X).\n!\n! IFLAG is an error flag. With the following error codes:\n! 0 : Successful evaluation of DTLZ3\n! -1 : The design dimension D is not legal\n! -2 : The objective dimension P is not legal\n!\nUSE REAL_PRECISION, ONLY : R8\nIMPLICIT NONE\n! Input parameters.\nREAL(KIND=R8), INTENT(IN) :: X(:) ! Input design vector.\nREAL(KIND=R8), INTENT(OUT) :: F(:) ! Output objective vector.\nINTEGER, INTENT(OUT) :: IFLAG ! Error flag.\n! Local variables.\nINTEGER :: D, P ! Problem dimensions.\nINTEGER :: I, J ! Loop indexing variables.\nREAL(KIND=R8) :: PI ! Constant value of pi.\n! Get problem dimensions.\nD = SIZE(X,1)\nP = SIZE(F,1)\n! Compute the value of PI.\nPI = 4.0_R8 * ATAN(1.0_R8)\n! Throw errors for illegal inputs.\nIFLAG = 0\nIF (D < 1) THEN\n IFLAG = -1\n RETURN\nEND IF\nIF (D < P) THEN\n IFLAG = -2\n RETURN\nEND IF\n! Get the first objective value.\nF(1) = 1.0_R8 + G(X)\nDO J = 1, P-1\n F(1) = F(1) * COS(PI * X(J) / 2.0_R8)\nEND DO\n! Get other objective values.\nDO I = 1, P-1\n F(I+1) = (1.0_R8 + G(X)) * SIN(PI * X(P-I) / 2.0_R8)\n DO J = 1, P-I-1\n F(I+1) = F(I+1) * COS(PI * X(J) / 2.0_R8)\n END DO\nEND DO\n!IF (F(P) < 0.1_R8) IFLAG = -1 ! Tests taboo list when uncommented.\nRETURN\n\nCONTAINS\n\nFUNCTION G(Z)\n! A scalar valued kernel function G, which produces many local Pareto\n! fonts in the landscape of DTLZ3.\n! Parameters.\nREAL(KIND=R8), INTENT(IN) :: Z(:) ! Input vector.\nREAL(KIND=R8) :: G ! Output scalar.\n! Local variables.\nINTEGER :: K\n! Compute the kernel function G(Z) for DTLZ3.\nG = 2.0_R8 * ( REAL(D-P,KIND=R8) + 1.0_R8 + &\n DOT_PRODUCT(Z(P:D) - 0.6_R8, Z(P:D) - 0.6_R8) )\nDO K = P, D\n G = G - 2.0_R8 * COS(20.0_R8 * PI * (Z(K) - 0.6_R8))\nEND DO\nRETURN\nEND FUNCTION G\n\nEND SUBROUTINE DTLZ3\n\nSUBROUTINE DTLZ5(X, F, IFLAG)\n! Multiobjective test function with a 2D concave global Pareto curve, \n! embedded in a higher-dimensional objective space. Let D denote the\n! number of design variables and let P denote the number of objectives.\n! Then it is a requirement that D >= P >= 2, and the recommended bounds\n! are 0 < X(:) < 1. Both D and P are assumed based on the dimensions\n! of X(:) and F(:).\n!\n! Credit for the design of this test function goes to\n!\n! K. Deb, L. Thiele, M. Laumanns, and E. Zitzler. 2005. Scalable test\n! problems for evolutionary multiobjective optimization. In Evolutionary\n! multiobjective optimization (pp. 105-145). Springer, London.\n!\n!\n! On input:\n!\n! X(:) is a real valued design point in R^D.\n!\n!\n! On output:\n!\n! P(:) is a real valued objective point P = F(X).\n!\n! IFLAG is an error flag. With the following error codes:\n! 0 : Successful evaluation of DTLZ3\n! -1 : The design dimension D is not legal\n! -2 : The objective dimension P is not legal\n!\nUSE REAL_PRECISION, ONLY : R8\nIMPLICIT NONE\n! Input parameters.\nREAL(KIND=R8), INTENT(IN) :: X(:) ! Input design vector.\nREAL(KIND=R8), INTENT(OUT) :: F(:) ! Output objective vector.\nINTEGER, INTENT(OUT) :: IFLAG ! Error flag.\n! Local variables.\nINTEGER :: D, P ! Problem dimensions.\nINTEGER :: I, J ! Loop indexing variables.\nREAL(KIND=R8) :: GX ! Kernel function value.\nREAL(KIND=R8) :: PI ! Constant value of pi.\nREAL(KIND=R8) :: THETA(SIZE(F,1)-1) ! Vector of auxiliary variables.\n! Get problem dimensions.\nD = SIZE(X,1)\nP = SIZE(F,1)\n! Compute the value of PI.\nPI = 4.0_R8 * ATAN(1.0_R8)\n! Throw errors for illegal inputs.\nIFLAG = 0\nIF (D < 1) THEN\n IFLAG = -1\n RETURN\nEND IF\nIF (D < P) THEN\n IFLAG = -2\n RETURN\nEND IF\n! Compute the kernel function value.\nGX = DOT_PRODUCT(X(P:D)-0.6_R8, X(P:D)-0.6_R8)\n! Compute the first objective value and the auxiliary variables.\nTHETA(1) = PI * X(1) / 2.0_R8\nF(1) = (1.0_R8 + GX) * COS(THETA(1))\nDO J = 2, P-1\n ! Compute the auxiliary variable THETA(J).\n THETA(J) = (PI / 2.0_R8) * (1.0_R8 + 2.0_R8 * GX * X(J)) / &\n (2.0_R8 * (1.0_R8 + GX))\n ! Use THETA(J) to compute the first objective function.\n F(1) = F(1) * COS(THETA(J))\nEND DO\n! Compute the remaining objective values.\nDO I = 1, P-1\n F(I+1) = (1.0_R8 + GX) * SIN(THETA(P-I))\n DO J = 1, P-I-1\n F(I+1) = F(I+1) * COS(THETA(J))\n END DO\nEND DO\nRETURN\nEND SUBROUTINE DTLZ5\n\nSUBROUTINE DTLZ7(X, F, IFLAG)\n! Multiobjective test function with a discontinuous Pareto front. Let D\n! denote the number of design variables and let P denote the number of\n! objectives. Then it is a requirement that D >= P >= 2, and the\n! recommended bounds are 0 < X(:) < 1. Both D and P are assumed based\n! on the dimensions of X(:) and F(:).\n!\n! Credit for the design of this test function goes to\n!\n! K. Deb, L. Thiele, M. Laumanns, and E. Zitzler. 2005. Scalable test\n! problems for evolutionary multiobjective optimization. In Evolutionary\n! multiobjective optimization (pp. 105-145). Springer, London.\n!\n!\n! On input:\n!\n! X(:) is a real valued design point in R^D.\n!\n!\n! On output:\n!\n! P(:) is a real valued objective point P = F(X).\n!\n! IFLAG is an error flag. With the following error codes:\n! 0 : Successful evaluation of DTLZ3\n! -1 : The design dimension D is not legal\n! -2 : The objective dimension P is not legal\n!\nUSE REAL_PRECISION, ONLY : R8\nIMPLICIT NONE\n! Input parameters.\nREAL(KIND=R8), INTENT(IN) :: X(:) ! Input design vector.\nREAL(KIND=R8), INTENT(OUT) :: F(:) ! Output objective vector.\nINTEGER, INTENT(OUT) :: IFLAG ! Error flag.\n! Local variables.\nINTEGER :: D, P ! Problem dimensions.\nINTEGER :: I ! Loop indexing variables.\nREAL(KIND=R8) :: GX ! Value of kernel function G(X).\nREAL(KIND=R8) :: HX ! Value of kernel function H(X).\nREAL(KIND=R8) :: PI ! Constant value of pi.\n! Get problem dimensions.\nD = SIZE(X,1)\nP = SIZE(F,1)\n! Compute the value of PI.\nPI = 4.0_R8 * ATAN(1.0_R8)\n! Throw errors for illegal inputs.\nIFLAG = 0\nIF (D < 1) THEN\n IFLAG = -1\n RETURN\nEND IF\nIF (D < P) THEN\n IFLAG = -2\n RETURN\nEND IF\n! Compute the kernel functions G and H.\nGX = 1.0_R8 + 9.0_R8 * SUM(ABS(X(P:D)-0.6_R8), DIM=1) / (REAL(D-P+1, KIND=R8))\nHX = REAL(P, KIND=R8)\nDO I = 1, P-1\n HX = HX - ( (X(I) / (1.0_R8 + GX)) * (1.0_R8 + SIN(3.0_R8 * PI * X(I))) )\nEND DO\n! Compute the first M-1 objective values.\nDO I = 1, P-1\n F(I) = X(I)\nEND DO\n! Compute the final objective value.\nF(P) = (1.0_R8 + GX) * HX\nRETURN\nEND SUBROUTINE DTLZ7\n\nEND MODULE VTMOP_FUNC_MOD\n", "meta": {"hexsha": "cd756c5480abb1ed479a82a5437d28cbc593ead9", "size": 13532, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/vtmop_func.f90", "max_stars_repo_name": "vtopt/vtmop", "max_stars_repo_head_hexsha": "e68152e880af81678c11e7bbf955997ddc8b1105", "max_stars_repo_licenses": ["MIT"], "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/vtmop_func.f90", "max_issues_repo_name": "vtopt/vtmop", "max_issues_repo_head_hexsha": "e68152e880af81678c11e7bbf955997ddc8b1105", "max_issues_repo_licenses": ["MIT"], "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/vtmop_func.f90", "max_forks_repo_name": "vtopt/vtmop", "max_forks_repo_head_hexsha": "e68152e880af81678c11e7bbf955997ddc8b1105", "max_forks_repo_licenses": ["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.4285714286, "max_line_length": 78, "alphanum_fraction": 0.6582175584, "num_tokens": 4591, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246118695629, "lm_q2_score": 0.8244619220634457, "lm_q1q2_score": 0.6870444112047547}} {"text": " subroutine fadpt(x,y,z,mat,nvec,time,f)\nC #####################################################################\nC\nC PURPOSE -\nC\nC Adaption function for smoothing algorithms. This is the\nC 'gyroscope' function wherein the function has large\nC second derivatives near each of three rings in the\nC three coordinate planes.\nC\nC INPUT ARGUMENTS -\nC\nC X,Y,Z - Input spatial coordinate arrays.\nC MAT - Material type arrays. (This is for cases where the\nC function value depends BOTH on position and material\nC type.)\nC NV - Length of spatial arrays. (Evaluate function at each\nC spatial coordinate.)\nC TIME - Current time (for time dependent adaption).\nC\nC OUTPUT ARGUMENTS -\nC\nC F - Array of adaption function values.\nC\nC CHANGE HISTORY -\nC\nC ######################################################################\n implicit none\n \n integer lenptr\n parameter (lenptr=1000000)\n\n real*8 x(lenptr),y(lenptr),z(lenptr),f(lenptr)\n integer nvec, i, mat(lenptr)\n real*8 r0,z0,epssq,r,dsq,x0,y0,time\n\nc.... Radius of rings\n\n r0=0.5\n\nc.... Center of rings\n\n x0=0.\n y0=0.\n z0=0.\n \nc.... Square of epsilon. The function does not go to infinity\nc.... on the ring because epsilon is nonzero. More precisely, the\nc.... function is \nc.... f(x,y,z)=1/( d(x,y,z)**2 +epsilon**2 ).\nc....\nc.... That is, the function is 1 divided by the smallest distance\nc.... to any of the three rings (squared) plus epsilon squared. \nc.... This implies that the 'characteristic length' of the function\nc.... AT each of the rings is epsilon.\n\n epssq=.1**2\n\nc.... Loop over vector of input values and compute function values.\n\n do i=1,nvec\n\n r=sqrt(x(i)**2+y(i)**2)\n dsq=(r-r0)**2+(z(i)-z0)**2\n\n r=sqrt(y(i)**2+z(i)**2)\n dsq=min(dsq,(r-r0)**2+(x(i)-x0)**2)\n\n r=sqrt(z(i)**2+x(i)**2)\n dsq=min(dsq,(r-r0)**2+(y(i)-y0)**2)\n\n f(i)=1./(dsq+epssq)\n\n enddo\n\n return\n end\n\n", "meta": {"hexsha": "3075552d81de412d36f8b97ca5b6ba3156d9f36d", "size": 2107, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "pages/fadpt_gyro.f", "max_stars_repo_name": "github-livingston/lagrit_site", "max_stars_repo_head_hexsha": "4c596616bcd4cafeed3ba0a13ba64df5632b004c", "max_stars_repo_licenses": ["CC0-1.0"], "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": "pages/fadpt_gyro.f", "max_issues_repo_name": "github-livingston/lagrit_site", "max_issues_repo_head_hexsha": "4c596616bcd4cafeed3ba0a13ba64df5632b004c", "max_issues_repo_licenses": ["CC0-1.0"], "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": "docs/pages/fadpt_gyro.f", "max_forks_repo_name": "daniellivingston/LaGriT", "max_forks_repo_head_hexsha": "decd0ce0e5dab068034ef382cabcd134562de832", "max_forks_repo_licenses": ["Intel"], "max_forks_count": 63, "max_forks_repo_forks_event_min_datetime": "2017-02-08T21:56:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T06:48:36.000Z", "avg_line_length": 26.6708860759, "max_line_length": 72, "alphanum_fraction": 0.5467489321, "num_tokens": 573, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896824119663, "lm_q2_score": 0.7461389873857264, "lm_q1q2_score": 0.6870370812300891}} {"text": "C 2 JAN 95 ...CRI... MSTP S/W CONVERSION (VICAR PORTING)\nC\n INCLUDE 'VICMAIN_FOR'\n SUBROUTINE MAIN44\nC IBIS ROUTINE IBISREGR\nC\nC PURPOSE: \nC\tIBISREGR PERFORMS A SERIES OF MULTIPLE REGRESSION ANALYSES\nC ON VARIOUS COMBINATIONS OF COLUMNS IN AN IBIS TABULAR FILE,\nC SEARCHING FOR OPTIMAL FITS.\n\nC THIS PROGRAM IS BASED ON PROGRAM 'IBISSTAT'\n\n\tIMPLICIT NONE\n\n\tINTEGER\tMAXCOLLEN, MAXTOTLEN, MAXCOLS, MAXSOLNS\n\tPARAMETER( MAXCOLLEN = 500, MAXTOTLEN=10000, MAXCOLS=40)\n\tPARAMETER( MAXSOLNS = 20)\n\n\tINTEGER\tUNIT, OUTUNIT, STATUS, COUNT, DEF, IBIS, OUTIBIS\n\tINTEGER\tCLEN, NCOL, NINCOLS, MAXINCOLS, MININC, MAXINC\n\tINTEGER INCOLNO(MAXCOLS), INCOLS(MAXCOLS), TEMP(2)\n\tINTEGER BESTCOLS(MAXCOLS,MAXSOLNS), MBEST(MAXSOLNS)\n\tINTEGER\tI, J, K, M, N, BUFPTR, DEPCOL, ERR, IPIV(MAXCOLS+1)\n\tINTEGER\tNBEST, NBEST1, ICOL, JCOL\n\n\tREAL ALLDATA(MAXCOLLEN,MAXCOLS), OUTDATA(MAXCOLLEN)\n\tREAL DATA(MAXTOTLEN), DATA2(MAXTOTLEN)\n\tREAL RESID(MAXCOLLEN), BESTRES( MAXCOLLEN, MAXSOLNS)\n\tREAL DEPDATA(MAXCOLLEN), DEPDATA2(MAXCOLLEN), WORK(MAXTOTLEN)\n\tREAL BESTRSQ(MAXSOLNS), BESTSIG(MAXSOLNS)\n\tREAL SOLUTION(MAXCOLS+1), BESTSOL( MAXCOLS+1, MAXSOLNS)\n\tREAL INTERVALS(MAXCOLS+1), SSR, RSQUARED, SEE, EPSILON\n\n\tLOGICAL NOPRINT, XVPTST, EITHER, BOTH, RSONLY, SDONLY\n\n\tCHARACTER*8 COLNAMES(MAXCOLS), DEPNAME\n\tCHARACTER*80 STRING\n\tCHARACTER*16 FSTR,TMP1,TMP2\n\nC---------------------------------------------------------------------\n CALL IFMESSAGE('IBISREGR version 2-JAN-95')\n CALL XVEACTION('SA',' ')\n\n\tNOPRINT = XVPTST( 'NOPRINT')\n\tBOTH = XVPTST( 'BOTH')\n\tEITHER = XVPTST( 'EITHER')\n\tRSONLY = XVPTST( 'RSQUARED')\n\tSDONLY = XVPTST( 'STDERR')\n\t\nC\t\tOPEN IBIS INTERFACE FILE\n CALL XVUNIT(UNIT, 'INP', 1, STATUS, ' ')\n\n\tCALL IBIS_FILE_OPEN(UNIT,IBIS,'READ',0,0,' ',' ',STATUS)\n IF (STATUS.NE.1) CALL IBIS_SIGNAL_U(UNIT,STATUS,1)\n CALL IBIS_FILE_GET(IBIS,'NC',NCOL,1,1)\n CALL IBIS_FILE_GET(IBIS,'NR',CLEN,1,1)\n\n\tN = CLEN\n\tIF (N .LT. 2) CALL MABEND('COLUMN LENGTH TOO SHORT')\n\tIF (N .GT. MAXCOLLEN) CALL MABEND('COLUMN LENGTH TOO LONG')\n\n\tCALL XVPARM( 'COLNAMES', COLNAMES, COUNT, DEF, MAXCOLS)\n\tDO I = COUNT+1, NCOL\n\t IF (I.LE.9) THEN\n\t\tWRITE( COLNAMES(I), '(A6,I1)') 'COLUMN', I\n\t ELSE\n\t\tWRITE( COLNAMES(I), '(A6,I2)') 'COLUMN', I\n\t ENDIF\n\tENDDO\n\nC GET THE DATA FOR THE DEPENDANT VARIABLE:\n\tCALL XVPARM( 'DEPCOL', DEPCOL, COUNT, DEF, 1)\n\tIF (COUNT.EQ.0) DEPCOL = NCOL\n\tCALL XVPARM( 'DEPNAME', DEPNAME, COUNT, DEF, 1)\n\tIF (COUNT.EQ.0) DEPNAME = COLNAMES(DEPCOL)\n\tCALL IBIS_COLUMN_READ(IBIS,DEPDATA,DEPCOL,1,CLEN,STATUS)\n IF (STATUS.NE.1) CALL IBIS_SIGNAL(IBIS,STATUS,1)\n\nC COLUMNS TO SEARCH THROUGH FOR INDEPENDENT VARIABLES:\n\tCALL XVPARM( 'COLS', INCOLNO, MAXINCOLS, DEF, MAXCOLS)\n\tIF (MAXINCOLS.EQ.0) THEN\n\t MAXINCOLS = NCOL-1\n\t J = 0\n\t DO I = 1,NCOL\n\t IF (I.NE.DEPCOL) THEN\n\t J = J+1\n\t INCOLNO(J) = I\n\t ENDIF\n\t ENDDO\n\tENDIF\n\nC GET MINIMUM/MAXIMUM NUMBER OF COLUMN COMBINATIONS TO TRY:\n\tCALL XVPARM( 'COLRANGE', TEMP, COUNT, DEF, 2)\n\tIF (COUNT.EQ.0) THEN\n\t MININC = 2\n\t MAXINC = MAXINCOLS\n ELSE\n\t MININC = TEMP(1)\n\t MAXINC = TEMP(2)\n\tENDIF\n\tIF (MAXINC.GT.MAXINCOLS) CALL MABEND('RANGE TOO HIGH')\n\n\tIF ((MAXINCOLS+1)*N .GT. MAXTOTLEN) \n +\t\t\tCALL MABEND('TOO MUCH DATA FOR BUFFER')\n\tIF (N .LT. MAXINC+1) CALL MABEND('NOT ENOUGH ROWS OF DATA')\n\nC READ ALL THE COLUMN DATA TO BE SEARCHED INTO WORKING BUFFER:\n\tDO I = 1,MAXINCOLS\n\t CALL IBIS_COLUMN_READ(IBIS,ALLDATA(1,I),INCOLNO(I),\n + 1,N,STATUS)\n IF (STATUS.NE.1) CALL IBIS_SIGNAL(IBIS,STATUS,1)\n\tENDDO\n\n\tCALL XVPARM( 'NBEST', NBEST, I, DEF, 1)\n\tIF (NBEST.GT.MAXSOLNS) CALL MABEND('NBEST TOO BIG')\n\n\tCALL XVMESSAGE('MULTIPLE REGRESSION SEARCH',' ')\n\tWRITE( STRING, '(2A)') 'DEPENDENT VARIABLE: ', DEPNAME\n\tCALL XVMESSAGE(STRING,' ')\n\nC START LOOPING OVER ALL POSSIBLE COMBINATIONS OF BETWEEN 'MININC'\nC AND 'MAXINC' COLUMNS. WE MUST STORE THE 'NBEST' BEST SOLUTIONS.\n\tDO I = 1,NBEST\n\t BESTRSQ(I) = -1.E30\n\t BESTSIG(I) = 1.E30\n\tENDDO\n\nC OUTERMOST LOOP IS OVER THE NUMBER OF COLUMNS, 'NINCOLS', WHICH VARIES\nC FROM 'MININC' TO 'MAXINC'.\nC THEN WE LOOP OVER THE COMBINATIONS OF COLUMNS, VARYING THE LAST\nC ONE MOST RAPIDLY AND THE FIRST ONE LEAST RAPIDLY. (THIS CORRESPONDS\nC TO 'NINCOLS' EMBEDDED DO-LOOPS.) \n\n\tNINCOLS = MININC\n100\tDO I = 1,NINCOLS\t\t\t! BEGIN LOOP OVER # COLUMNS\n\t INCOLS(I) = I\n\tENDDO\n\nC BEGIN LOOP OVER COLUMNS:\nC PERFORM LEAST-SQS FIT FOR CURRENT 'INCOLS' COMBINATION:\n200\tIF (.NOT. NOPRINT) THEN\n\t CALL XVMESSAGE(' ',' ')\n\t WRITE( STRING, '(A6)') 'COLS: '\n J=7\n \t DO I=1,NINCOLS\n\t WRITE(STRING(J+3*(I-1):J+3*(I-1)+2),'(I3)')\n * INCOLNO(INCOLS(I))\n ENDDO\n\t CALL XVMESSAGE(STRING,' ')\n\tENDIF\n\n\tDO I = 1, N\n\t DATA(I) = 1.0\n\tENDDO\n\tDO I = 1, NINCOLS\n\t BUFPTR = I*N + 1\n\t CALL MVE( 7, N, ALLDATA(1,INCOLS(I)), DATA(BUFPTR),1,1)\n\tENDDO\n\tM = NINCOLS + 1\n\n\tDO I = 1, N*M\n\t DATA2(I) = DATA(I)\n\tENDDO\n\tDO I = 1, N\n\t DEPDATA2(I) = DEPDATA(I)\n\tENDDO\n\t\n\tEPSILON = 1.0E-7\n\tCALL LLSQ( DATA2, DEPDATA2, N, M, 1,\n +\t\t\tSOLUTION, IPIV, EPSILON, ERR, WORK)\n\tIF (ERR.NE.0) CALL MABEND('** COLUMNS ARE DEPENDENT **')\n\tSSR = WORK(1)\n\n\tCALL CALCRES( DATA, DEPDATA, SOLUTION, RESID, N, M, SSR)\n\n\tCALL REGSTAT (DATA, DEPDATA, N, M, SSR, SEE, RSQUARED, INTERVALS)\n\n\tIF (.NOT. NOPRINT) THEN\n\t CALL XVMESSAGE(' ',' ')\n\t WRITE (STRING, '(A)') \n +\t\t\t' VARIABLE COEFFICIENT ERROR'\n\t CALL XVMESSAGE(STRING,' ')\n TMP1=FSTR(SOLUTION(1),12,6)\n TMP2=FSTR(INTERVALS(1),12,6)\n\t WRITE (STRING, '(A,3X,A12,3X,A12)') ' CONSTANT', TMP1,TMP2\n\t CALL XVMESSAGE(STRING,' ')\n\t DO I = 2, M\n TMP1=FSTR(SOLUTION(I),12,6)\n TMP2=FSTR(INTERVALS(I),12,6)\n\t WRITE (STRING, '(2X,A,3X,A12,3X,A12)') \n +\t\t COLNAMES( INCOLNO(INCOLS(I-1))), TMP1,TMP2\n\t CALL XVMESSAGE(STRING,' ')\n\t ENDDO\n\t CALL XVMESSAGE(' ',' ')\n\t WRITE (STRING, '(A,F7.4)') 'R SQUARED = ', RSQUARED\n\t CALL XVMESSAGE(STRING,' ')\n TMP1=FSTR(SEE,11,4)\n\t WRITE (STRING, '(A,A11)') 'STD ERR OF EST = ', TMP1\n\t CALL XVMESSAGE(STRING,' ')\n\tENDIF\n\nC SEE IF THIS IS ONE OF THE 'NBEST' SOLUTIONS:\n\tDO I = 1,NBEST\n\t IF ( (BOTH .AND. RSQUARED.GT.BESTRSQ(I) .AND. \n & SEE.LT.BESTSIG(I))\n &\t .OR. (EITHER .AND. (RSQUARED.GT.BESTRSQ(I) .OR.\n &\t SEE.LT.BESTSIG(I)))\n &\t .OR. (RSONLY .AND. RSQUARED.GT.BESTRSQ(I)) \n &\t .OR. (SDONLY .AND. SEE.LT.BESTSIG(I))) THEN\n\t GO TO 300\n\t ENDIF\n\tENDDO\n\tGO TO 310\n300\tDO J = NBEST,I+1,-1\n\t BESTRSQ(J) = BESTRSQ(J-1)\n\t BESTSIG(J) = BESTSIG(J-1)\n\t MBEST(J) = MBEST(J-1)\n\t CALL MVE( 4, NINCOLS, BESTCOLS(1,J-1), BESTCOLS(1,J),1,1)\n\t CALL MVE( 7, NINCOLS+1, BESTSOL(1,J-1), BESTSOL(1,J),1,1)\n\t CALL MVE( 7, N, BESTRES(1,J-1), BESTRES(1,J),1,1)\n\tENDDO\n\tBESTRSQ(I) = RSQUARED\n\tBESTSIG(I) = SEE\n\tMBEST(I) = NINCOLS+1\n\tDO J = 1,NINCOLS\n\t BESTCOLS(J,I) = INCOLNO( INCOLS(J))\n\tENDDO\n\tDO J = 1,NINCOLS+1\n\t BESTSOL(J,I) = SOLUTION(J)\n\tENDDO\n\tCALL MVE( 7, N, RESID, BESTRES(1,I),1,1)\n\n310\tDO ICOL = NINCOLS,1,-1\n\t IF (INCOLS(ICOL) .LT. MAXINCOLS-NINCOLS+ICOL) GO TO 400\n\tENDDO\n\tGO TO 500\t\t! END OF ALL COMBINATIONS OF CURRENT # COL'S\n\n400\tINCOLS(ICOL) = INCOLS(ICOL)+1\n\tDO JCOL = ICOL+1,NINCOLS\n\t INCOLS(JCOL) = INCOLS(JCOL-1)+1\n\tENDDO\n\tGO TO 200\t\t\t\t! END LOOP OVER COLUMNS\n\n500\tNINCOLS = NINCOLS+1\t\t\t! END LOOP OVER NUMBER OF COL'S\n\tIF (NINCOLS.LE.MAXINC) GO TO 100\n\nC OUTPUT THE 'NBEST' BEST SOLUTIONS TO DISK & TERMINAL:\n\nC FIRST CHECK THAT THERE WERE AT LEAST 'NBEST' SOLUTIONS:\n\tDO I = 1,NBEST\n\t IF (BESTRSQ(I).GT.0.) NBEST1 = I\n\tENDDO\n\tNBEST = NBEST1\n\n\tCALL XVPCNT( 'OUT', COUNT)\n\tIF (COUNT.GE.1) THEN\nC OPEN CORRECT SIZED IBIS OUTPUT FILE\n CALL XVUNIT(OUTUNIT, 'OUT', 1, STATUS, ' ')\n\n\t CALL IBIS_FILE_OPEN(OUTUNIT,OUTIBIS,'WRITE',3*NBEST,N,\n * ' ',' ',STATUS)\n IF (STATUS.NE.1) CALL IBIS_SIGNAL_U(OUTUNIT,STATUS,1)\n\n\t DO J = 1,NBEST\n CALL IBIS_COLUMN_SET(OUTIBIS,'FORMAT','FULL',3*J-2,STATUS)\n CALL IBIS_COLUMN_WRITE(OUTIBIS,BESTCOLS(1,J),3*J-2,\n + 2,MBEST(J)+1,status)\n IF (STATUS.NE.1) CALL IBIS_SIGNAL(OUTIBIS,STATUS,1)\n\t CALL ZIA( OUTDATA, MAXINC+1)\n\t DO I = 1, MBEST(J)\n\t OUTDATA(I) = BESTSOL(I,J)\n\t ENDDO\n CALL IBIS_COLUMN_WRITE(OUTIBIS,OUTDATA,3*J-1,\n + 1,MBEST(J),status)\n IF (STATUS.NE.1) CALL IBIS_SIGNAL(OUTIBIS,STATUS,1)\n CALL IBIS_COLUMN_WRITE(OUTIBIS,BESTRES(1,J),3*J,\n + 1,N,status)\n IF (STATUS.NE.1) CALL IBIS_SIGNAL(OUTIBIS,STATUS,1)\n\t ENDDO\n\t CALL IBIS_FILE_CLOSE(OUTIBIS,' ',STATUS)\n IF (STATUS.NE.1) CALL IBIS_SIGNAL_U(OUTUNIT,STATUS,1)\n\tENDIF\n\n CALL XVMESSAGE(' ',' ')\n\tCALL XVMESSAGE('BEST SOLUTIONS FOUND:',' ')\n\n\tDO J = 1,NBEST\n\t CALL XVMESSAGE(' ',' ')\n\t M = MBEST(J)-1\n\t WRITE( STRING, '(A6)') 'COLS: '\n K=7\n \t DO I=1,M\n\t WRITE(STRING(K+3*(I-1):K+3*(I-1)+2),'(I3)') BESTCOLS(I,J)\n ENDDO\n\t CALL XVMESSAGE(STRING,' ')\n TMP1=FSTR(BESTSIG(J),11,4)\n\t WRITE( STRING, '(A,F7.4,A,A11)') 'R SQUARED = ', BESTRSQ(J),\n &\t ' STD ERR = ', TMP1\n\t CALL XVMESSAGE(STRING,' ')\n\tENDDO\n\n\tCALL IBIS_FILE_CLOSE(IBIS,' ',STATUS)\n IF (STATUS.NE.1) CALL IBIS_SIGNAL_U(UNIT,STATUS,1)\n\n\tRETURN\n\tEND\n\n\n\n\n\tCHARACTER*16 FUNCTION FSTR( VALUE, FIELDWIDTH, NDECIMALS)\n\tIMPLICIT NONE\n\tREAL\tVALUE\n\tINTEGER\tFIELDWIDTH, NDECIMALS\n\n\tIF ( ABS(VALUE) .GE. 10**(FIELDWIDTH-NDECIMALS-2) .OR. \n +\t ( ABS(VALUE) .LT. 0.1**NDECIMALS .AND. VALUE .NE. 0.0) ) THEN\n IF (FIELDWIDTH .EQ. 11) THEN\n\t WRITE( FSTR, '(E11.4)', ERR=100 ) VALUE\n\t ELSE\n\t WRITE( FSTR, '(E12.6)', ERR=100 ) VALUE\n END IF\n\tELSE\n IF (FIELDWIDTH .EQ. 11) THEN\n\t WRITE( FSTR, '(F11.4)', ERR=100 ) VALUE\n\t ELSE\n\t WRITE( FSTR, '(F12.6)', ERR=100 ) VALUE\n END IF\n\tENDIF\n\tRETURN\n\n100\tFSTR = '****************'\n\tRETURN\n\tEND\n\n\n\n\tSUBROUTINE REGSTAT(C, Y, N, M, SSR, SEE, RSQUARED, INTERVALS)\n\tIMPLICIT NONE\n\tINTEGER\tN, M\n\tREAL\tC(N,M), Y(N), SSR, SEE, RSQUARED, INTERVALS(M)\n\tINTEGER\tI, J, K, L, ERR, WORK2(41), WORK3(41)\n\tREAL\tA(41*41), SUM, EPS, WORK1(41)\n\tREAL\tMEAN, SUMSQR\n\n\n\tSUM = 0.0\n\tDO I = 1, N\n\t SUM = SUM + Y(I)\n\tENDDO\n\tMEAN = SUM/N\n\tSUMSQR = 0.0\n\tDO I = 1, N\n\t SUMSQR = SUMSQR + (Y(I) - MEAN)**2\n\tENDDO\n\tRSQUARED = (SUMSQR - SSR) / SUMSQR\n\tSEE = SQRT(SSR/(N-M))\n\n\nC\t\tCALCULATE CONFIDENCE INTERVALS FOR THE REGRESSION COEFS\n\tL = 1\n\tDO J = 1, M\n\t DO K = 1, M\n\t\tSUM = 0.0\n\t\tDO I = 1, N\n\t\t SUM = SUM + C(I,J)*C(I,K)\n\t\tENDDO\n\t\tA(L) = SUM\n\t\tL = L + 1\n\t ENDDO\n\tENDDO\n\n\tEPS = 1.0E-7\n\tCALL MINV (A, M, EPS, ERR, WORK1, WORK2, WORK3)\n\tIF (ERR .NE. 0) CALL MABEND ('SINGULAR MATRIX')\n\n\tDO K = 1, M\n\t INTERVALS(K) = SEE*SQRT(A(K+M*(K-1)))\n\tENDDO\n\n\tRETURN\n\tEND\n\n\n\tSUBROUTINE CALCRES( A, B, X, RES, N, M, SSR)\n\tIMPLICIT NONE\n\tINTEGER\tI,J, N,M\n\tREAL\tA(N,M), B(N), X(M), RES(N), SSR, SUM\n\n\tDO I = 1, N\n\t SUM = B(I)\n\t DO J = 1, M\n\t\tSUM = SUM - A(I,J)*X(J)\n\t ENDDO\n\t RES(I) = SUM\n\tENDDO\n\n\tSSR = 0.0\n\tDO I = 1, N\n\t SSR = SSR + RES(I)**2\n\tENDDO\n\n\tRETURN\n\tEND\n\n\n\n SUBROUTINE MINV( A,N,E,K,X,J2,I2)\nC* MATRIX INVERSION ROUTINE-FORMULATED BY E. G. CLAYTON\nC\nC A--SQUARE ARRAY (SINGLE PRECISION) CONTAINING ORIGINAL MATRIX\nC N--ORDER OF ORIGINAL MATRIX\nC E--TEST CRITERION FOR NEAR ZERO DIVISOR\nC K--LOCATION FOR SINGULARITY OR ILL-CONDITION INDICATOR\nC K=0 =) MATRIX NONSINGULAR.\nC K=1 =) MATRIX SINGULAR (OR ILL-CONDITIONED)\nC X--A WORK VECTOR OF SIZE N\nC J2--AN INTEGER WORK VECTOR OF SIZE N\nC I2--AN INTEGER WORK VECTOR OF SIZE N\nC\n DIMENSION A(N,N),X(N),J2(N),I2(N)\nC\nC INITIALIZATION\nC\n K=1\n I2(1)=0\n J2(1)=0\nC\nC BEGIN COMPUTATION OF INVERSE\nC\n DO 15 L=1,N\n L1=L-1\n IF(L1.EQ.0)L1=1\n BIGA=-1.0\nC\nC LOOK FOR THE ELEMENT OF GREATEST ABSOLUTE VALUE,CHOOSING\nC ONE FROM A ROW AND COLUMN NOT PREVIOUSLY USED.\nC\n DO 5 I=1,N\n DO 1 I3=1,L1\n IF(I .EQ. I2(I3)) GO TO 5\n 1 CONTINUE\n DO 4 J=1,N\n DO 2 I3=1,L1\n IF(J .EQ. J2(I3)) GO TO 4\n 2 CONTINUE\n AT=ABS(A(I,J))\n IF(BIGA .GE. AT) GO TO 4\n BIGA=AT\n J1=J\n I1=I\n 4 CONTINUE\n 5 CONTINUE\nC\nC TAG THE ROW AND COLUMN FROM WHICH THE ELEMENT IS CHOSEN.\nC\n J2(L)=J1\n I2(L)=I1\n DIV=A(I1,J1)\nC\nC TEST ELEMENT AGAINST ZERO CRITERION\n IF(ABS(DIV) .LE. E) GO TO 221\nC\nC PERFORM THE COMPUTATIONS\nC\n OOD = 1./DIV\n DO 7 J=1,N\n A(I1,J)=A(I1,J)*OOD\n 7 CONTINUE\n A(I1,J1)=OOD\n DO 11 I=1,N\n IF(I1 .EQ. I) GO TO 11\n DO 10 J=1,N\n IF(J1 .EQ. J) GO TO 10\n A(I,J)=A(I,J)-A(I1,J)*A(I,J1)\n 10 CONTINUE\n 11 CONTINUE\n DO 14 I=1,N\n IF(I1 .EQ. I) GO TO 14\n A(I,J1)=-A(I,J1)*A(I1,J1)\n 14 CONTINUE\n 15 CONTINUE\nC\nC COMPUTATION COMPLETE AT THIS POINT\nC UNSCRAMBLE THE INVERSE\nC\n DO 18 J=1,N\n DO 16 I=1,N\n I1=I2(I)\n J1=J2(I)\n X(J1)=A(I1,J)\n 16 CONTINUE\n DO 17 I=1,N\n A(I,J)=X(I)\n17 CONTINUE\n 18 CONTINUE\n DO 21 I=1,N\n DO 19 J=1,N\n I1=I2(J)\n J1=J2(J)\n X(I1)=A(I,J1)\n 19 CONTINUE\n DO 20 J=1,N\n A(I,J)=X(J)\n 20 CONTINUE\n 21 CONTINUE\n K=0\n 221 RETURN\n END\n\n", "meta": {"hexsha": "f70860c64813097b6afe2c93a33bf79dc21df36a", "size": 13357, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "vos/p2/prog/ibisregr/ibisregr.f", "max_stars_repo_name": "NASA-AMMOS/VICAR", "max_stars_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2020-10-21T05:56:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T10:02:01.000Z", "max_issues_repo_path": "vos/p2/prog/ibisregr/ibisregr.f", "max_issues_repo_name": "NASA-AMMOS/VICAR", "max_issues_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "vos/p2/prog/ibisregr/ibisregr.f", "max_forks_repo_name": "NASA-AMMOS/VICAR", "max_forks_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-03-09T01:51:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-23T00:23:24.000Z", "avg_line_length": 26.087890625, "max_line_length": 72, "alphanum_fraction": 0.5972898106, "num_tokens": 5341, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543487, "lm_q2_score": 0.7690802476562641, "lm_q1q2_score": 0.6870266192419487}} {"text": "*> \\brief \\b DLARTGS generates a plane rotation designed to introduce a bulge in implicit QR iteration for the bidiagonal SVD problem.\n*\n* =========== DOCUMENTATION ===========\n*\n* Online html documentation available at\n* http://www.netlib.org/lapack/explore-html/\n*\n*> \\htmlonly\n*> Download DLARTGS + dependencies\n*> \n*> [TGZ]\n*> \n*> [ZIP]\n*> \n*> [TXT]\n*> \\endhtmlonly\n*\n* Definition:\n* ===========\n*\n* SUBROUTINE DLARTGS( X, Y, SIGMA, CS, SN )\n*\n* .. Scalar Arguments ..\n* DOUBLE PRECISION CS, SIGMA, SN, X, Y\n* ..\n*\n*\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*>\n*> DLARTGS generates a plane rotation designed to introduce a bulge in\n*> Golub-Reinsch-style implicit QR iteration for the bidiagonal SVD\n*> problem. X and Y are the top-row entries, and SIGMA is the shift.\n*> The computed CS and SN define a plane rotation satisfying\n*>\n*> [ CS SN ] . [ X^2 - SIGMA ] = [ R ],\n*> [ -SN CS ] [ X * Y ] [ 0 ]\n*>\n*> with R nonnegative. If X^2 - SIGMA and X * Y are 0, then the\n*> rotation is by PI/2.\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in] X\n*> \\verbatim\n*> X is DOUBLE PRECISION\n*> The (1,1) entry of an upper bidiagonal matrix.\n*> \\endverbatim\n*>\n*> \\param[in] Y\n*> \\verbatim\n*> Y is DOUBLE PRECISION\n*> The (1,2) entry of an upper bidiagonal matrix.\n*> \\endverbatim\n*>\n*> \\param[in] SIGMA\n*> \\verbatim\n*> SIGMA is DOUBLE PRECISION\n*> The shift.\n*> \\endverbatim\n*>\n*> \\param[out] CS\n*> \\verbatim\n*> CS is DOUBLE PRECISION\n*> The cosine of the rotation.\n*> \\endverbatim\n*>\n*> \\param[out] SN\n*> \\verbatim\n*> SN is DOUBLE PRECISION\n*> The sine of the rotation.\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee\n*> \\author Univ. of California Berkeley\n*> \\author Univ. of Colorado Denver\n*> \\author NAG Ltd.\n*\n*> \\ingroup auxOTHERcomputational\n*\n* =====================================================================\n SUBROUTINE DLARTGS( X, Y, SIGMA, CS, SN )\n*\n* -- LAPACK computational routine --\n* -- LAPACK is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n*\n* .. Scalar Arguments ..\n DOUBLE PRECISION CS, SIGMA, SN, X, Y\n* ..\n*\n* ===================================================================\n*\n* .. Parameters ..\n DOUBLE PRECISION NEGONE, ONE, ZERO\n PARAMETER ( NEGONE = -1.0D0, ONE = 1.0D0, ZERO = 0.0D0 )\n* ..\n* .. Local Scalars ..\n DOUBLE PRECISION R, S, THRESH, W, Z\n* ..\n* .. External Subroutines ..\n EXTERNAL DLARTGP\n* ..\n* .. External Functions ..\n DOUBLE PRECISION DLAMCH\n EXTERNAL DLAMCH\n* .. Executable Statements ..\n*\n THRESH = DLAMCH('E')\n*\n* Compute the first column of B**T*B - SIGMA^2*I, up to a scale\n* factor.\n*\n IF( (SIGMA .EQ. ZERO .AND. ABS(X) .LT. THRESH) .OR.\n $ (ABS(X) .EQ. SIGMA .AND. Y .EQ. ZERO) ) THEN\n Z = ZERO\n W = ZERO\n ELSE IF( SIGMA .EQ. ZERO ) THEN\n IF( X .GE. ZERO ) THEN\n Z = X\n W = Y\n ELSE\n Z = -X\n W = -Y\n END IF\n ELSE IF( ABS(X) .LT. THRESH ) THEN\n Z = -SIGMA*SIGMA\n W = ZERO\n ELSE\n IF( X .GE. ZERO ) THEN\n S = ONE\n ELSE\n S = NEGONE\n END IF\n Z = S * (ABS(X)-SIGMA) * (S+SIGMA/X)\n W = S * Y\n END IF\n*\n* Generate the rotation.\n* CALL DLARTGP( Z, W, CS, SN, R ) might seem more natural;\n* reordering the arguments ensures that if Z = 0 then the rotation\n* is by PI/2.\n*\n CALL DLARTGP( W, Z, SN, CS, R )\n*\n RETURN\n*\n* End DLARTGS\n*\n END\n\n", "meta": {"hexsha": "2310df87fa9aafdb1cb5792ed259014944b7a282", "size": 4216, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "SRC/dlartgs.f", "max_stars_repo_name": "sergey-v-kuznetsov/lapack", "max_stars_repo_head_hexsha": "799ef93faa5878aa8702f7cf9980cfc649cc39cc", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 998, "max_stars_repo_stars_event_min_datetime": "2016-05-04T20:50:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T17:43:13.000Z", "max_issues_repo_path": "SRC/dlartgs.f", "max_issues_repo_name": "sergey-v-kuznetsov/lapack", "max_issues_repo_head_hexsha": "799ef93faa5878aa8702f7cf9980cfc649cc39cc", "max_issues_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_issues_count": 603, "max_issues_repo_issues_event_min_datetime": "2016-06-04T07:28:21.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T21:16:50.000Z", "max_forks_repo_path": "SRC/dlartgs.f", "max_forks_repo_name": "sergey-v-kuznetsov/lapack", "max_forks_repo_head_hexsha": "799ef93faa5878aa8702f7cf9980cfc649cc39cc", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 373, "max_forks_repo_forks_event_min_datetime": "2016-06-04T06:05:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T17:25:45.000Z", "avg_line_length": 26.5157232704, "max_line_length": 134, "alphanum_fraction": 0.5294117647, "num_tokens": 1250, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.893309411735131, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6870266141547673}} {"text": "PROGRAM MAIN\n USE QR_mod\n USE wrtmat_mod\n USE upmatrix_mod\n IMPLICIT NONE\n INTEGER(4)::m,n,i\n CHARACTER(20):: words\n REAL(4),ALLOCATABLE::A(:,:),Q(:,:),R(:,:)\n REAL(4),ALLOCATABLE::b(:,:)\n !----------------------------------------\n ! read the input file and make the matrix\n OPEN(99,FILE='input')\n DO \n READ(99,'(A80)',END=100) words\n IF(words=='m =') READ(99,*) m\n IF(words=='n =') READ(99,*) n\n IF(words=='A =') then\n ALLOCATE(A(m,n))\n DO i=1,m\n READ(99,*) A(i,1:n)\n END DO\n END IF\n IF(words=='bt=') then\n ALLOCATE(b(m,1))\n READ(99,*) b(1:m,1)\n END IF \n END DO\n100 CLOSE(99)\n !----------------------------------------\n !----------------------------------------\n !do A=QR,then b=Qt*b,next x=b*R-1, print A,b,Q,R,x in the output file\n OPEN(100,file='output')\n WRITE(*,*)'A='\n WRITE(100,*)'A='\n CALL wrtmat(A)\n WRITE(*,*)'b='\n WRITE(100,*)'b='\n CALL wrtmat(b)\n ALLOCATE(Q(m,m))\n ALLOCATE(R(m,n))\n CALL makeQR(m,n,A,Q,R) !make Q,R,st A=QR\n WRITE(*,*)'R='\n WRITE(100,*)'R='\n CALL wrtmat(R)\n WRITE(*,*)'Q='\n WRITE(100,*)'Q='\n CALL wrtmat(Q)\n b=MATMUL(transpose(Q),b) !caculate b=Qt*b\n CALL upmatrix(R,b) !CALCULATE THE Rx=b ,then b=x\n WRITE(*,*)'x='\n WRITE(100,*)'x='\n CALL wrtmat(b)\n CLOSE(100)\n !--------------------------------------- \n DEALLOCATE(b)\n DEALLOCATE(A)\n DEALLOCATE(Q)\n DEALLOCATE(R)\nEND PROGRAM", "meta": {"hexsha": "2369a5b6a9aec6246164abe77ea1e814df36f94f", "size": 1564, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "QR/src/main.f90", "max_stars_repo_name": "Huang-Yihan/jisuanfangfa", "max_stars_repo_head_hexsha": "1e48104988b01f66da216f639fd0654a6b1ff6c4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "QR/src/main.f90", "max_issues_repo_name": "Huang-Yihan/jisuanfangfa", "max_issues_repo_head_hexsha": "1e48104988b01f66da216f639fd0654a6b1ff6c4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "QR/src/main.f90", "max_forks_repo_name": "Huang-Yihan/jisuanfangfa", "max_forks_repo_head_hexsha": "1e48104988b01f66da216f639fd0654a6b1ff6c4", "max_forks_repo_licenses": ["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.5084745763, "max_line_length": 73, "alphanum_fraction": 0.442455243, "num_tokens": 519, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094032139577, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.6870266123293807}} {"text": "SUBROUTINE cgamma(mo, z, w)\r\n!-----------------------------------------------------------------------\r\n\r\n! EVALUATION OF THE COMPLEX GAMMA AND LOGGAMMA FUNCTIONS\r\n\r\n! ---------------\r\n\r\n! MO IS AN INTEGER, Z A COMPLEX ARGUMENT, AND W A COMPLEX VARIABLE.\r\n\r\n! W = GAMMA(Z) IF MO = 0\r\n! W = LN(GAMMA(Z)) OTHERWISE\r\n\r\n!-----------------------------------------------------------------------\r\n! WRITTEN BY ALFRED H. MORRIS, JR.\r\n! NAVAL SURFACE WARFARE CENTER\r\n! DAHLGREN, VIRGINIA\r\n\r\n! This version, in a subset of Fortran 90, prepared by\r\n! Alan.Miller @ vic.cmis.csiro.au\r\n! http://www.ozemail.com.au/~milleraj\r\n\r\n! This version is accurate to within 5 in the 14th significant\r\n! decimal digit.\r\n!-----------------------------------------------------------------------\r\n\r\nIMPLICIT NONE\r\nINTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(14, 60)\r\n\r\nINTEGER, INTENT(IN) :: mo\r\nCOMPLEX (dp), INTENT(IN) :: z\r\nCOMPLEX (dp), INTENT(OUT) :: w\r\n\r\n! Local variables\r\nCOMPLEX (dp) :: eta, eta2, sum\r\nREAL (dp), PARAMETER :: c0(12) = (/ .833333333333333E-01_dp, &\r\n -.277777777777778E-02_dp, .793650793650794E-03_dp, &\r\n -.595238095238095E-03_dp, .841750841750842E-03_dp, &\r\n -.191752691752692E-02_dp, .641025641025641E-02_dp, &\r\n -.295506535947712E-01_dp, .179644372368831_dp, &\r\n -1.39243221690590_dp, 13.4028640441684_dp, &\r\n -156.848284626002_dp /), pi = 3.14159265358979_dp, &\r\n pi2 = 6.28318530717959_dp, alpi = 1.14472988584940_dp, &\r\n hl2p = .918938533204673_dp, half = 0.5_dp\r\nREAL (dp) :: a, a1, a2, c, cn, cut, d, eps, et, e2t, h1, h2, s, sn, &\r\n s1, s2, t, t1, t2, u, u1, u2, v1, v2, w1, w2, x, y, y2\r\nINTEGER :: j, k, l, m, max, n, nm1\r\n!---------------------------\r\n! ALPI = LOG(PI)\r\n! HL2P = 0.5 * LOG(2*PI)\r\n!---------------------------\r\n\r\n! ****** MAX AND EPS ARE MACHINE DEPENDENT CONSTANTS.\r\n! MAX IS THE LARGEST POSITIVE INTEGER THAT MAY\r\n! BE USED, AND EPS IS THE SMALLEST REAL NUMBER\r\n! SUCH THAT 1.0 + EPS > 1.0.\r\n\r\n! MAX = IPMPAR(3)\r\nmax = HUGE(3)\r\neps = EPSILON(1.0_dp)\r\n\r\n!---------------------------\r\nx = REAL(z, KIND=dp)\r\ny = AIMAG(z)\r\nIF (x < 0.0_dp) THEN\r\n!-----------------------------------------------------------------------\r\n! CASE WHEN THE REAL PART OF Z IS NEGATIVE\r\n!-----------------------------------------------------------------------\r\n y = ABS(y)\r\n t = -pi * y\r\n et = EXP(t)\r\n e2t = et * et\r\n\r\n! SET A1 = (1 + E2T)/2 AND A2 = (1 - E2T)/2\r\n\r\n a1 = half * (1.0_dp + e2t)\r\n t2 = t + t\r\n IF (t2 >= -0.15_dp) THEN\r\n a2 = -half * rexp(t2)\r\n ELSE\r\n a2 = half * (half + (half - e2t))\r\n END IF\r\n\r\n! COMPUTE SIN(PI*X) AND COS(PI*X)\r\n\r\n IF (ABS(x) >= MIN(REAL(MAX), 1.0_dp/eps)) GO TO 70\r\n k = ABS(x)\r\n u = x + k\r\n k = MOD(k,2)\r\n IF (u <= -half) THEN\r\n u = half + (half + u)\r\n k = k + 1\r\n END IF\r\n u = pi * u\r\n sn = SIN(u)\r\n cn = COS(u)\r\n IF (k == 1) THEN\r\n sn = -sn\r\n cn = -cn\r\n END IF\r\n\r\n! SET H1 + H2*I TO PI/SIN(PI*Z) OR LOG(PI/SIN(PI*Z))\r\n\r\n a1 = sn * a1\r\n a2 = cn * a2\r\n a = a1 * a1 + a2 * a2\r\n IF (a == 0.0_dp) GO TO 70\r\n IF (mo == 0) THEN\r\n\r\n h1 = a1 / a\r\n h2 = -a2 / a\r\n c = pi * et\r\n h1 = c * h1\r\n h2 = c * h2\r\n ELSE\r\n\r\n h1 = (alpi+t) - half * LOG(a)\r\n h2 = -ATAN2(a2,a1)\r\n END IF\r\n IF (AIMAG(z) >= 0.0_dp) THEN\r\n x = 1.0_dp - x\r\n y = -y\r\n ELSE\r\n h2 = -h2\r\n x = 1.0_dp - x\r\n END IF\r\nEND IF\r\n!-----------------------------------------------------------------------\r\n! CASE WHEN THE REAL PART OF Z IS NONNEGATIVE\r\n!-----------------------------------------------------------------------\r\nw1 = 0.0_dp\r\nw2 = 0.0_dp\r\nn = 0\r\nt = x\r\ny2 = y * y\r\na = t * t + y2\r\ncut = 36.0_dp\r\nIF (eps > 1.e-8_dp) cut = 16.0_dp\r\nIF (a < cut) THEN\r\n IF (a == 0.0_dp) GO TO 70\r\n 10 n = n + 1\r\n t = t + 1.0_dp\r\n a = t * t + y2\r\n IF (a < cut) GO TO 10\r\n\r\n! LET S1 + S2*I BE THE PRODUCT OF THE TERMS (Z+J)/(Z+N)\r\n\r\n u1 = (x*t+y2) / a\r\n u2 = y / a\r\n s1 = u1\r\n s2 = n * u2\r\n IF (n >= 2) THEN\r\n u = t / a\r\n nm1 = n - 1\r\n DO j = 1, nm1\r\n v1 = u1 + j * u\r\n v2 = (n-j) * u2\r\n c = s1 * v1 - s2 * v2\r\n d = s1 * v2 + s2 * v1\r\n s1 = c\r\n s2 = d\r\n END DO\r\n END IF\r\n\r\n! SET W1 + W2*I = LOG(S1 + S2*I) WHEN MO IS NONZERO\r\n\r\n s = s1 * s1 + s2 * s2\r\n IF (mo /= 0) THEN\r\n w1 = half * LOG(s)\r\n w2 = ATAN2(s2,s1)\r\n END IF\r\nEND IF\r\n\r\n! SET V1 + V2*I = (Z - 0.5) * LOG(Z + N) - Z\r\n\r\nt1 = half * LOG(a) - 1.0_dp\r\nt2 = ATAN2(y,t)\r\nu = x - half\r\nv1 = (u*t1-half) - y * t2\r\nv2 = u * t2 + y * t1\r\n\r\n! LET A1 + A2*I BE THE ASYMPTOTIC SUM\r\n\r\neta = CMPLX(t/a, -y/a, KIND=dp)\r\neta2 = eta * eta\r\nm = 12\r\nIF (a >= 289.0_dp) m = 6\r\nIF (eps > 1.e-8) m = m / 2\r\nsum = CMPLX(c0(m), 0.0_dp, KIND=dp)\r\nl = m\r\nDO j = 2, m\r\n l = l - 1\r\n sum = CMPLX(c0(l), 0.0_dp, KIND=dp) + sum * eta2\r\nEND DO\r\nsum = sum * eta\r\na1 = REAL(sum, KIND=dp)\r\na2 = AIMAG(sum)\r\n!-----------------------------------------------------------------------\r\n! GATHERING TOGETHER THE RESULTS\r\n!-----------------------------------------------------------------------\r\nw1 = (((a1 + hl2p) - w1) + v1) - n\r\nw2 = (a2 - w2) + v2\r\nIF (REAL(z, KIND=dp) < 0.0_dp) GO TO 50\r\nIF (mo == 0) THEN\r\n\r\n! CASE WHEN THE REAL PART OF Z IS NONNEGATIVE AND MO = 0\r\n\r\n a = EXP(w1)\r\n w1 = a * COS(w2)\r\n w2 = a * SIN(w2)\r\n IF (n == 0) GO TO 60\r\n c = (s1*w1 + s2*w2) / s\r\n d = (s1*w2 - s2*w1) / s\r\n w1 = c\r\n w2 = d\r\n GO TO 60\r\nEND IF\r\n\r\n! CASE WHEN THE REAL PART OF Z IS NONNEGATIVE AND MO IS NONZERO.\r\n! THE ANGLE W2 IS REDUCED TO THE INTERVAL -PI < W2 <= PI.\r\n\r\n40 IF (w2 <= pi) THEN\r\n k = half - w2 / pi2\r\n w2 = w2 + pi2 * k\r\n GO TO 60\r\nEND IF\r\nk = w2 / pi2 - half\r\nw2 = w2 - pi2 * REAL(k+1)\r\nIF (w2 <= -pi) w2 = pi\r\nGO TO 60\r\n\r\n! CASE WHEN THE REAL PART OF Z IS NEGATIVE AND MO IS NONZERO\r\n\r\n50 IF (mo /= 0) THEN\r\n w1 = h1 - w1\r\n w2 = h2 - w2\r\n GO TO 40\r\nEND IF\r\n\r\n! CASE WHEN THE REAL PART OF Z IS NEGATIVE AND MO = 0\r\n\r\na = EXP(-w1)\r\nt1 = a * COS(-w2)\r\nt2 = a * SIN(-w2)\r\nw1 = h1 * t1 - h2 * t2\r\nw2 = h1 * t2 + h2 * t1\r\nIF (n /= 0) THEN\r\n c = w1 * s1 - w2 * s2\r\n d = w1 * s2 + w2 * s1\r\n w1 = c\r\n w2 = d\r\nEND IF\r\n\r\n! TERMINATION\r\n\r\n60 w = CMPLX(w1, w2, KIND=dp)\r\nRETURN\r\n!-----------------------------------------------------------------------\r\n! THE REQUESTED VALUE CANNOT BE COMPUTED\r\n!-----------------------------------------------------------------------\r\n70 w = (0.0_dp, 0.0_dp)\r\nRETURN\r\n\r\nCONTAINS\r\n\r\n\r\nFUNCTION rexp(x) RESULT(fn_val)\r\n!-----------------------------------------------------------------------\r\n! EVALUATION OF THE FUNCTION EXP(X) - 1\r\n!-----------------------------------------------------------------------\r\nREAL (dp), INTENT(IN) :: x\r\nREAL (dp) :: fn_val\r\n\r\n! Local variables\r\nREAL (dp), PARAMETER :: p1 = .914041914819518E-09_dp, &\r\n p2 = .238082361044469E-01_dp, q1 = -.499999999085958_dp, &\r\n q2 = .107141568980644_dp, q3 = -.119041179760821E-01_dp, &\r\n q4 = .595130811860248E-03_dp\r\nREAL (dp) :: e\r\n!-----------------------\r\nIF (ABS(x) <= 0.15_dp) THEN\r\n fn_val = x * (((p2*x + p1)*x + 1.0_dp) / &\r\n ((((q4*x + q3)*x + q2)*x + q1)*x + 1.0_dp))\r\n RETURN\r\nEND IF\r\n\r\nIF (x >= 0.0_dp) THEN\r\n e = EXP(x)\r\n fn_val = e * (half + (half - 1.0_dp/e))\r\n RETURN\r\nEND IF\r\nIF (x >= -37.0_dp) THEN\r\n fn_val = (EXP(x) - half) - half\r\n RETURN\r\nEND IF\r\nfn_val = -1.0_dp\r\nRETURN\r\nEND FUNCTION rexp\r\n\r\nEND SUBROUTINE cgamma\r\n", "meta": {"hexsha": "605498b66288f7d5f0891174549d09f5329467ac", "size": 7671, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/cgamma.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/cgamma.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/cgamma.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": 25.57, "max_line_length": 73, "alphanum_fraction": 0.430452353, "num_tokens": 2857, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.687026600688733}} {"text": "subroutine residuo(a, b, u, r)\n\nimplicit none\n\nreal, dimension(:,:), intent(in) :: a\nreal, dimension(:), intent(in) :: b\nreal, dimension(:), intent(in) :: u\n\nreal, dimension(:), intent(inout) :: r\n\ninteger :: n, i\n\nn = size(b)\n\nr = matmul(A,u) - b\n\nprint*,\nprint*, 'Residuo: ', sqrt(dot_product(r,r))\nprint*, r(:)\nprint*,\n\nend subroutine\n", "meta": {"hexsha": "e2a237715e0bd70eaea9159d29f980cfb51fba8e", "size": 338, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Practica1_residuo/residuo.f95", "max_stars_repo_name": "UxioAndrade/Analisis-Numerico-Matricial", "max_stars_repo_head_hexsha": "1afa52b0994b9cf38822da903609a4d1c91bfab0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Practica1_residuo/residuo.f95", "max_issues_repo_name": "UxioAndrade/Analisis-Numerico-Matricial", "max_issues_repo_head_hexsha": "1afa52b0994b9cf38822da903609a4d1c91bfab0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Practica1_residuo/residuo.f95", "max_forks_repo_name": "UxioAndrade/Analisis-Numerico-Matricial", "max_forks_repo_head_hexsha": "1afa52b0994b9cf38822da903609a4d1c91bfab0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 14.6956521739, "max_line_length": 43, "alphanum_fraction": 0.6124260355, "num_tokens": 109, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8807970654616711, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.687015462129325}} {"text": "subroutine area(r,a)\n\n use constants, only: pi\n implicit none\n real(kind=8), intent(in) :: r\n real(kind=8), intent(in) :: a\n\n\n a = pi * r**2\n \nend subroutine area\n", "meta": {"hexsha": "98ec50e9e16aaaea5c5a7b9b2baabdab5d884d86", "size": 181, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/labs/lab8/problem1/area.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/lab8/problem1/area.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/lab8/problem1/area.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": 15.0833333333, "max_line_length": 33, "alphanum_fraction": 0.5745856354, "num_tokens": 55, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6870154580014636}} {"text": "C******************************************************************************\nC FILE: omp_mm.f\nC DESCRIPTION: \nC OpenMp Example - Matrix Multiply - Fortran Version \nC Demonstrates a matrix multiply using OpenMP. Threads share row iterations\nC according to a predefined chunk size.\nC AUTHOR: Blaise Barney\nC LAST REVISED: 1/5/04 Blaise Barney\nC******************************************************************************\n\n PROGRAM MATMULT\n\n INTEGER NRA, NCA, NCB, TID, NTHREADS, I, J, K, CHUNK,\n + OMP_GET_NUM_THREADS, OMP_GET_THREAD_NUM\nC number of rows in matrix A \n PARAMETER (NRA=62)\nC number of columns in matrix A\n PARAMETER (NCA=15)\nC number of columns in matrix B\n PARAMETER (NCB=7)\n\n REAL*8 A(NRA,NCA), B(NCA,NCB), C(NRA,NCB)\n\nC Set loop iteration chunk size \n CHUNK = 10\n\nC Spawn a parallel region explicitly scoping all variables\n!$OMP PARALLEL SHARED(A,B,C,NTHREADS,CHUNK) PRIVATE(TID,I,J,K)\n TID = OMP_GET_THREAD_NUM()\n IF (TID .EQ. 0) THEN\n NTHREADS = OMP_GET_NUM_THREADS()\n PRINT *, 'Starting matrix multiple example with', NTHREADS,\n + 'threads'\n PRINT *, 'Initializing matrices'\n END IF\n\nC Initialize matrices\n!$OMP DO SCHEDULE(STATIC, CHUNK)\n DO 30 I=1, NRA\n DO 30 J=1, NCA\n A(I,J) = (I-1)+(J-1)\n 30 CONTINUE\n!$OMP DO SCHEDULE(STATIC, CHUNK)\n DO 40 I=1, NCA\n DO 40 J=1, NCB\n B(I,J) = (I-1)*(J-1)\n 40 CONTINUE\n!$OMP DO SCHEDULE(STATIC, CHUNK)\n DO 50 I=1, NRA\n DO 50 J=1, NCB\n C(I,J) = 0\n 50 CONTINUE\n\nC Do matrix multiply sharing iterations on outer loop\nC Display who does which iterations for demonstration purposes\n PRINT *, 'Thread', TID, 'starting matrix multiply...'\n!$OMP DO SCHEDULE(STATIC, CHUNK)\n DO 60 I=1, NRA\n PRINT *, 'Thread', TID, 'did row', I\n DO 60 J=1, NCB\n DO 60 K=1, NCA\n C(I,J) = C(I,J) + A(I,K) * B(K,J)\n 60 CONTINUE\n\nC End of parallel region \n!$OMP END PARALLEL\n\nC Print results\n PRINT *, '******************************************************'\n PRINT *, 'Result Matrix:'\n DO 90 I=1, NRA\n DO 80 J=1, NCB\n WRITE(*,70) C(I,J)\n 70 FORMAT(2x,f8.2,$)\n 80 CONTINUE\n PRINT *, ' '\n 90 CONTINUE\n PRINT *, '******************************************************'\n PRINT *, 'Done.'\n\n END\n", "meta": {"hexsha": "670f62305fe3b9f311315323cd35a03dced47752", "size": 2453, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "openmp/code_examples/Fortran/omp_mm.f", "max_stars_repo_name": "davidleitw/HPC-Tutorials", "max_stars_repo_head_hexsha": "98a9ecdfde322950cc18710091b247a67998840b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 93, "max_stars_repo_stars_event_min_datetime": "2021-03-15T20:40:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T08:57:40.000Z", "max_issues_repo_path": "openmp/code_examples/Fortran/omp_mm.f", "max_issues_repo_name": "davidleitw/HPC-Tutorials", "max_issues_repo_head_hexsha": "98a9ecdfde322950cc18710091b247a67998840b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-05-14T04:55:45.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T16:33:20.000Z", "max_forks_repo_path": "openmp/code_examples/Fortran/omp_mm.f", "max_forks_repo_name": "davidleitw/HPC-Tutorials", "max_forks_repo_head_hexsha": "98a9ecdfde322950cc18710091b247a67998840b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 63, "max_forks_repo_forks_event_min_datetime": "2021-03-10T00:31:09.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T13:48:30.000Z", "avg_line_length": 29.9146341463, "max_line_length": 79, "alphanum_fraction": 0.5226253567, "num_tokens": 712, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6870154580014636}} {"text": "c=======================================================================\nc\nc Linear Algebra - Utilities Functions \nc\nc Note: used vectorized matrix operations for dimension < 1000\nc\nc-----------------------------------------------------------------------\nc\nc sub-programs names convention \nc -----------------------------\nc\nc first letter : operation type\nc A : Arrangement\nc C : Conversion\nc D : Difference\nc E : Extremum\nc I : initalization\nc J : Inversion\nc M : Mean \nc N : Norm \nc O : multiple Operations\nc P : Product\nc R : Transpose\nc S : Sum\nc T : Trace\nc W : who ?\nc X : scalar product\nc Y : copy\nc Z : symetrization\nc (A)\nc AVOC : sort a vector in increase order\nc AVOD : sort a vector in decrease order\nc AVOCI : sort a vector in increase order (index in old vector)\nc AVODI : sort a vector in decrease order (index in old vector)\nc (C)\nc CMCML : converting a full square matrix (n*n) in low triangular matrix (n*n)\nc CMCMS : converting a full square matrix (n*n) in symmetric matrix (n*(n+1)/2)\nc CMCMU : converting a full square matrix (n*n) in up triangular matrix (n*n)\nc CMDV : converting the diagonal of a matrix(n*n) in vector(n)\nc CMDSV : converting the diagonal of a symmetric matrix(n*(n+1)/2) in vector(n)\nc CMLMC : converting a low triangular matrix (n*n) in full square matrix (n*n)\nc CMSMC : converting a symmetric matrix (n*(n+1)/2) in full square matrix (n*n)\nc CMUMC : converting an up triangular matrix (n*n) in full square matrix (n*n)\nc CVMD : converting a vector (n) in diagonal matrix (n*n)\nc CVMDS : converting a vector (n) in symmetric diagonal matrix (n*(n+1)/2)\nc (D)\nc DM : difference of 2 matrices (vectorized full)\nc DMS : difference of 2 matrices (vectorized symmetric)\nc (E)\nc EMBOR : matrix (general) minimum and maximum elements\nc EMMAX : matrix (general) maximum element\nc EMMIN : matrix (general) minimum element\nc EMDBOR : matrix (diagonal) minimum and maximum elements\nc EMDMAX : matrix (diagonal) maximum element\nc EMDMIN : matrix (diagonal) minimum element\nc EVBOR : vector minimum and maximum elements\nc EVMAX : vector maximum element\nc EVMAXI : vector maximum element and index\nc EVMIN : vector minimum element\nc EVMINI : vector minimum element and index\nc (I)\nc IMX : matrix (general) scalar initialization\nc IMDX : matrix (diagonal) scalar initialization\nc IMSX : matrix (symmetric) scalar initialization\nc IVX : vector scalar initialization\nc (J)\nc JMC : matrix inverse, invA(n*n) <- A(n*n)^(-1)\nc JMS : matrix (symmetric) inverse, invA(n*n) <- A(n*n)^(-1)\nc (M)\nc MCM : matrix (general) mean on each column\nc MCMI : matrix (general) mean on the i-th column\nc MLM : matrix (general) mean on each row\nc MLMI : matrix (general) mean on the j-th row\nc MM : matrix (general) mean \nc MMS : matrix (symmetric) mean\nc MV : vector mean\nc (N)\nc NDM : Frobenius norm of the difference between two matrices (vectorized full)\nc NDMS : Frobenius norm of the difference between two matrices (vectorized symmetric)\nc NDVL1 : L1-norm of the difference between two vectors\nc NDVL2 : L2-norm of the difference between two vectors\nc NM : matrix Frobenius norm (vectorized full)\nc NM1 : matrix L1-norm (vectorized full)\nc NM2 : matrix L2-norm (vectorized full)\nc NMINF : matrix Infinite-norm (vectorized full)\nc NMS : matrix Frobenius norm (vectorized symmetric)\nc NSV : L2-norm of the sum of two vectors\nc NV : vector L2-norm\nc NV1 : vector L1-norm\nc NV2 : vector L2-norm square\nc NVINF : vector Infinite-norm\nc (S)\nc SCM : sum of the elements of the columns of a matrix\nc SEM : sum of the elements of a matrix\nc SEMDX : sum of the diagonal elements of a matrix with a scalar : B = A + x*I\nc ( A square matrix(n*n), x scalar, gives B square matrix(n*n) )\nc SEV : sum of the elements of a vector\nc SEVP : sum of the elements of a part of a vector\nc SLM : sum of the elements of the rows of a matrix\nc SM : M1 + M2 -> M (general)\nc SMbis : sum of 2 matrices ??? \nc SMS : M1 + M2 -> M (vectorized symmetric)\nc SMX : M + x -> M\nc (T)\nc TM : Trace of a matrix (general)\nc TMS : Trace of a matrix (symmetric)\nc (W)\nc WVEQ : who is equal to x in a vector ? (+/- epsilon) gives a vector of indexes\nc WVGT : who is greater than x in a vector ? gives a vector of indexes\nc WVLT : who is lower than x in a vector ? gives a vector of indexes\nc (X)\nc XM : scalar product of two matrices (general)\nc (M1 matrix n*m, M2 matrix n*m, gives M1.M2= scalar)\nc XMS : scalar product of two matrices (symmetric)\nc (M1 sym. matrix n*m, M2 sym.matrix n*m, gives scalar)\nc (Y)\nc YCMV : copy a column of a vectorized matrix in a vector\nc YLMV : copy a row of a vectorized matrix in a vector\nc YMCPI : copy a part of a square matrix in a smaller square matrix with index\nc YMCPIR : copy a square matrix in a part of a bigger square matrix with index\nc YMP : copy a part of a vectorized matrix in a vectorized matrix\nc YMPMP : copy a part of a vectorized matrix in a part of a vectorized matrix\nc YVCM : copy a vector in a column of a vectorized matrix\nc YVLM : copy a vector in a row of a vectorized matrix\nc YVP : copy a part of a vector in a vector\nc YVPIR : copy a vector in a part of a bigger vector as index\nc YVPVP : copy a part of a vector in a part of a vector\nc\nc=======================================================================\nc\nc subroutine AVOC\nc\nc Sort a vector in increase order\nc\nc-----------------------------------------------------------------------\n SUBROUTINE AVOC ( n, x, y )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : size (n>0) integer\nc x : input vector (n) double\nc\nc OUTPUT \nc y : sorted vector (n) double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\nc\nc i/o arguments\n INTEGER n\n DOUBLE PRECISION x(*), y(*)\nc\nc local variables\n INTEGER i, j, indic, nout\n DOUBLE PRECISION a\nc\nc-----------------------------------------------------------------------\nc\n y(1) = x(1)\nc\nc if n=1 exit\n IF (n .EQ. 1) RETURN\nc \n nout = 2\n indic = 1\n DO i = 2,n\n a = x(i)\nc\nc rank \n indic = 1\n DO WHILE ( (indic .LT. nout) .AND. (a .GT. y(indic)) )\n indic = indic + 1\n ENDDO\nc\nc decalage\n DO j = nout,indic+1,-1\n y(j) = y(j-1)\n ENDDO\nc\n y(indic) = a\n nout = nout + 1\n ENDDO\nc\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine AVOD\nc\nc Sort a vector in decrease order\nc\nc-----------------------------------------------------------------------\n SUBROUTINE AVOD ( nvect, vecin, vecout )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc nvect : size of the vector integer\nc vecin : vector to sort (nvect) double\nc\nc OUTPUT \nc vecout : sorted vector (nvect) double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\nc\n integer nvect\n double precision vecin(*), vecout(*)\nc\n integer i, j, indic, nout\n double precision a\nc\nc-----------------------------------------------------------------------\nc\n vecout(1) = vecin(1)\nc\n if (nvect.gt.1) then\nc\n nout = 2\n indic = 1\n vecout(1) = vecin(1)\n do i=2,nvect\n a = vecin(i)\nc\nc recherche du rang \nc\n indic = 1\n do while ( (indic.lt.nout) .and. (a.lt.vecout(indic)) )\n indic = indic + 1\n end do\nc\nc decalage\nc\n do j=nout,indic+1,-1\n vecout(j) = vecout(j-1)\n end do\nc\n vecout(indic) = a\n nout = nout + 1\nc\n end do\nc\n endif\nc\n return\n end\nc\nc=======================================================================\nc\nc subroutine AVOCI\nc\nc Sort a vector in increase order with index in old vector\nc\nc-----------------------------------------------------------------------\n SUBROUTINE AVOCI ( nvect, vecin, vecout, ind )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc nvect : size of the vector integer\nc vecin : vector to sort (nvect) double\nc\nc OUTPUT \nc vecout : sorted vector (nvect) double\nc index : indices of vector elements integer\nc in the old vector vector(nvect)\nc\nc-----------------------------------------------------------------------\nc\n implicit none\nc\n integer nvect\n integer ind(*)\n double precision vecin(*), vecout(*)\nc\n integer i, j, indic, nout\n double precision a\nc\nc-----------------------------------------------------------------------\nc\n ind(1) = 1\n vecout(1) = vecin(1)\nc\n if (nvect.gt.1) then\nc\n nout = 2\n indic = 1\n do i=2,nvect\n a = vecin(i)\nc\nc recherche du rang \nc\n indic = 1\n do while ( (indic.lt.nout) .and. (a.gt.vecout(indic)) )\n indic = indic + 1\n end do\nc\nc decalage\nc\n do j=nout,indic+1,-1\n vecout(j) = vecout(j-1)\n ind(j) = ind(j-1)\n end do\nc\n vecout(indic) = a\n ind(indic) = i\n nout = nout + 1\nc\n end do\nc\n endif\nc\n return\n end\nc\nc=======================================================================\nc\nc subroutine AVODI\nc\nc Sort a vector in decrease order with index in old vector\nc\nc-----------------------------------------------------------------------\n SUBROUTINE AVODI ( nvect, vecin, vecout, index )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc nvect : size of the vector integer\nc vecin : vector to sort (nvect) double\nc\nc OUTPUT \nc vecout : sorted vector (nvect) double\nc index : indices of vector elements integer\nc in the old vector vector(nvect)\nc\nc-----------------------------------------------------------------------\nc\n implicit none\nc\n integer nvect\n integer index(*)\n double precision vecin(*), vecout(*)\nc\n integer i, j, indic, nout\n double precision a\nc\nc-----------------------------------------------------------------------\nc\n index(1) = 1\n vecout(1) = vecin(1)\nc\n if (nvect.gt.1) then\nc\n nout = 2\n indic = 1\n do i=2,nvect\n a = vecin(i)\nc\nc recherche du rang \nc\n indic = 1\n do while ( (indic.lt.nout) .and. (a.lt.vecout(indic)) )\n indic = indic + 1\n end do\nc\nc decalage\nc\n do j=nout,indic+1,-1\n vecout(j) = vecout(j-1)\n index(j) = index(j-1)\n end do\nc\n vecout(indic) = a\n index(indic) = i\n nout = nout + 1\nc\n end do\nc\n endif\nc\n return\n end\nc\nc=======================================================================\nc\nc subroutine CMCML\nc\nc converting a full square matrix (n*n) in low triangular matrix (n*n)\nc\nc-----------------------------------------------------------------------\n SUBROUTINE CMCML ( n, A, ltA )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : matrix size integer\nc A : matrix (n*n) double\nc\nc OUTPUT \nc ltA : low triangular matrix (n*n) double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER n, i, j, k\n DOUBLE PRECISION A(n,*), ltA(n,*)\nc\n k = 0\n DO j = 1,n\n DO i = 1,n\n IF (i .GE. j) THEN\n ltA(i,j) = A(i,j)\n ELSE\n ltA(i,j) = 0.0\n ENDIF\n ENDDO\n ENDDO\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine CMCMS\nc\nc converting a full square matrix (n*n) in symmetric matrix (n*(n+1)/2)\nc\nc-----------------------------------------------------------------------\n SUBROUTINE CMCMS ( n, A, B )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : matrix size integer\nc A : matrix (n*n) double\nc\nc OUTPUT \nc B : symmetric matrix (n*(n+1)/2) double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER n, i, j, k\n DOUBLE PRECISION A(n,*), B(*)\nc\n k = 0\n DO j = 1,n\n DO i = 1,j\n k = k + 1\n B(k) = A(i,j)\n ENDDO\n ENDDO\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine CMCMU\nc\nc converting a full square matrix (n*n) in upper triangular matrix (n*n)\nc\nc-----------------------------------------------------------------------\n SUBROUTINE CMCMU ( n, A, utA )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : matrix size integer\nc A : matrix (n*n) double\nc\nc OUTPUT \nc utA : upper triangular matrix (n*n) double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER n, i, j, k\n DOUBLE PRECISION A(n,*), utA(n,*)\nc\n k = 0\n DO j = 1,n\n DO i = 1,n\n IF (i .LE. j) THEN\n utA(i,j) = A(i,j)\n ELSE\n utA(i,j) = 0.\n ENDIF\n ENDDO\n ENDDO\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine CMDV\nc\nc Converting the diagonal of a matrix(n*n) in vector(n)\nc\nc-----------------------------------------------------------------------\n SUBROUTINE CMDV ( n, A, diagA )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : matrix size integer\nc A : matrix (n*n) double\nc\nc OUTPUT \nc diagA : vector (n) double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER n, i\n DOUBLE PRECISION A(n,*), diagA(*)\nc\n DO i = 1,n\n diagA(i) = A(i,i)\n ENDDO\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine CMDSV\nc\nc Converting the diagonal of a symmetric matrix(n*(n+1)/2) in vector(n)\nc\nc\nc=======================================================================\n subroutine CMDSV ( n, A, diagA )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : matrix size integer\nc A : symmetric matrix (n*(n+1)/2) double\nc\nc OUTPUT \nc diagA : vector (n) double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER n, i, k\n DOUBLE PRECISION A(*), diagA(*)\nc\n k = 0\n DO i = 1,n\n k = k + i\n diagA(i) = A(k)\n ENDDO\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine CMLMC\nc\nc converting a low triangular matrix (n*n) in full square matrix (n*n)\nc\nc-----------------------------------------------------------------------\n SUBROUTINE CMLMC ( n, ltA, A )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : matrix size integer\nc ltA : low triangular matrix (n*n) double\nc\nc OUTPUT \nc A : matrix (n*n) double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER n, i, j\n DOUBLE PRECISION A(n,*), ltA(n,*)\nc\n DO j = 1,n\n DO i = j,n\n A(i,j) = ltA(i,j)\n IF (i .NE. j) THEN\n A(j,i) = A(i,j)\n ENDIF\n ENDDO\n ENDDO\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine CMSMC\nc\nc Converting a symmetric matrix (n*(n+1)/2) in full square matrix (n*n)\nc\nc-----------------------------------------------------------------------\n SUBROUTINE CMSMC ( n, symA, A)\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : matrix size integer\nc symA : symmetric matrix (n*(n+1)/2) double\nc\nc OUTPUT \nc A : matrix (n*n) double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER n, i, j, k\n DOUBLE PRECISION symA(*), A(n,*)\nc\n k = 0\n DO j = 1,n\n DO i = 1,j\n k = k + 1\n A(i,j) = symA(k)\n IF ( i .NE. j ) A(j,i) = symA(k)\n ENDDO\n ENDDO\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine CMUMC\nc\nc converting upper triangular matrix (n*n) to matrix (n*n)\nc\nc-----------------------------------------------------------------------\n subroutine CMUMC ( n, utA, A )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : matrix size integer\nc utA : upper triangular matrix (n*n) double\nc\nc OUTPUT \nc A : matrix (n*n) double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER n, i, j\n DOUBLE PRECISION A(n,*), utA(n,*)\nc\n DO j = 1,n\n DO i = 1,j\n A(i,j) = utA(i,j)\n IF (i .NE. j) THEN\n A(j,i) = A(i,j)\n ENDIF\n ENDDO\n ENDDO\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine CVMD\nc\nc Converting a vector (n) in full diagonal matrix (n*n)\nc\nc-----------------------------------------------------------------------\n SUBROUTINE CVMD ( n, V, A)\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : vector size integer\nc V : vector (n) double\nc\nc OUTPUT \nc A : diagonal matrix (n*n) double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER n, i\n DOUBLE PRECISION alpha, A(n,*), V(*)\n PARAMETER (alpha = 0.0)\nc\n CALL PMX2 ( n, n, A, alpha)\n DO i = 1,n\n A(i,i) = V(i)\n ENDDO\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine CVMDS\nc\nc Converting a vector (n) in symmetric diagonal matrix (n*(n+1)/2)\nc\nc-----------------------------------------------------------------------\n SUBROUTINE CVMDS ( n, V, A)\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : vector size integer\nc V : vector (n) double\nc\nc OUTPUT \nc A : diagonal matrix (n*(n+1)/2) double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER n, i, j, k\n DOUBLE PRECISION A(*), V(*)\nc\n A(1) = V(1)\n IF ( n .GT. 1) THEN\n k = 1\n DO j = 2,n\n DO i = 1,j-1\n k = k + 1\n A(k) = 0.0\n ENDDO\n k = k + 1\n A(k) = V(j)\n ENDDO\n ENDIF\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine DM\nc\nc A - B -> C (difference of two general matrices)\nc\nc-----------------------------------------------------------------------\n SUBROUTINE DM ( n, m, A, B, C )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : number of rows of the matrices integer\nc m : number of columns of the matrices integer\nc A : matrix (n*m) double\nc B : matrix (n*m) double\nc\nc OUTPUT \nc C : A - B, matrix (n*m) double\nc\nc-----------------------------------------------------------------------\nc\n implicit none\nc\nc i/o arguments\n INTEGER n, m\n DOUBLE PRECISION A(n,*), B(n,*), C(n,*)\nc\n INTEGER i, j\nc\nc-----------------------------------------------------------------------\nc\n DO j = 1,m\n DO i = 1,n\n C(i,j) = A(i,j) - B(i,j)\n ENDDO\n ENDDO\nc\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine DMS\nc\nc A - B -> C (difference of two vectorized symmetric matrices)\nc\nc-----------------------------------------------------------------------\n SUBROUTINE DMS ( n, A, B, C )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : size (n>0) integer\nc A : symmetric matrix as vector(n*(n+1)/2) double\nc B : symmetric matrix as vector(n*(n+1)/2) double\nc\nc OUTPUT \nc C : A - B, symmetric matrix as vector(n*(n+1)/2) double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\nc\nc i/o arguments\n INTEGER n\n DOUBLE PRECISION A(*), B(*), C(*)\nc\nc local variables\n INTEGER k\nc\nc-----------------------------------------------------------------------\nc\n k = n*(n+1)/2\n CALL DV ( k, A, B, C )\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine EMBOR\nc\nc matrix minimum and maximum, min A(n,m) and max A(n,m)\nc\nc-----------------------------------------------------------------------\n SUBROUTINE EMBOR ( n, m, A, Amin, Amax )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : number of rows integer\nc m : number of columns integer\nc A : matrix (n*m) double\nc\nc OUTPUT \nc Amin : matrix minimum double\nc Amax : matrix maximum double\nc \nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER n, m, p\n DOUBLE PRECISION Amin, Amax, A(*)\nc\n p = n*m\n CALL EVBOR ( p, A, Amin, Amax )\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine EMDBOR\nc\nc matrix minimum and maximum, min A(n,n) and max A(n,n)\nc\nc-----------------------------------------------------------------------\n SUBROUTINE EMDBOR ( n, A, Amin, Amax )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : matrix size integer\nc A : matrix (n*n) double\nc\nc OUTPUT \nc Amin : matrix minimum double\nc Amax : matrix maximum double\nc \nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER n, i\n DOUBLE PRECISION Amin, Amax, x, A(n,*)\nc\n Amin = A(1,1)\n Amax = A(1,1)\n IF (n .EQ. 1) RETURN \n DO i = 2,n\n x = A(i, i)\n IF (x .LT. Amin) Amin = x\n IF (x .GT. Amax) Amax = x\n ENDDO\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine EMDMAX\nc\nc diagonal matrix maximum, max diag[A(n,n)]\nc\nc-----------------------------------------------------------------------\n SUBROUTINE EMDMAX ( n, A, Amax )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : matrix size integer\nc A : matrix (n*n) double\nc\nc OUTPUT \nc Amax : matrix maximum double\nc \nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER n, i\n DOUBLE PRECISION Amax, x, A(n,*)\nc\n Amax = A(1,1)\n IF (n .EQ. 1) RETURN\n DO i = 2,n\n x = A(i, i)\n IF (x .GT. Amax) Amax = x\n ENDDO\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine EMDMIN\nc\nc diagonal matrix minimum, min diag[A(n,n)]\nc\nc-----------------------------------------------------------------------\n SUBROUTINE EMDMIN ( n, A, Amin )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : matrix size integer\nc A : matrix (n*n) double\nc\nc OUTPUT \nc Amin : matrix minimum double\nc \nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER n, i\n DOUBLE PRECISION Amin, x, A(n,*)\nc\n Amin = A(1,1)\n IF (n .EQ. 1) RETURN\n DO i = 2,n\n x = A(i,i)\n IF (x .LT. Amin) Amin = x\n ENDDO\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine EMMAX\nc\nc matrix maximum, max A(n,m), A vetctorized\nc\nc-----------------------------------------------------------------------\n subroutine EMMAX ( n, m, A, Amax )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : number of rows integer\nc m : number of columns integer\nc A : matrix (n*m) double\nc\nc OUTPUT \nc Amax : matrix maximum double\nc \nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER n, m, p\n DOUBLE PRECISION Amax, A(*)\nc\n p = n*m\n CALL EVMAX ( p, A, Amax )\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine EMMIN\nc\nc matrix minimum, min A(n,m), A vetctorized\nc\nc-----------------------------------------------------------------------\n SUBROUTINE EMMIN ( n, m, A, Amin )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : number of rows integer\nc m : number of columns integer\nc A : matrix (n*m) double\nc\nc OUTPUT \nc Amin : matrix minimum double\nc \nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER n, m, p\n DOUBLE PRECISION Amin, A(*)\nc\n p = n*m\n CALL EVMIN ( p, A, Amin )\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine EVBOR\nc\nc vector minimum and maximum, max V(n) and min V(n)\nc\nc-----------------------------------------------------------------------\n SUBROUTINE EVBOR ( n, V, Vmin, Vmax )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : vector size integer\nc V : vector (n) double\nc\nc OUTPUT \nc Vmin : vector minimum double\nc Vmax : vector maximum double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER n, i\n DOUBLE PRECISION Vmin, Vmax, x, V(*)\nc\n Vmin = V(1)\n Vmax = V(1)\n IF (n .EQ. 1) RETURN\n DO i = 2,n\n x = V(i)\n IF (x .LT. Vmin) Vmin = x\n IF (x .GT. Vmax) Vmax = x\n ENDDO\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine EVMAX\nc\nc vector maximum, max V(n)\nc\nc-----------------------------------------------------------------------\n SUBROUTINE EVMAX ( n, V, Vmax )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : vector size integer\nc V : vector (n) double\nc\nc OUTPUT \nc Vmax : vector maximum element double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER n, i\n DOUBLE PRECISION Vmax, x, V(*)\nc\n Vmax = V(1)\n IF (n .EQ. 1) RETURN\n DO i = 2,n\n x = V(i)\n IF (x .GT. Vmax) Vmax = x\n ENDDO\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine EVMAXI\nc\nc vector maximum element and index, Vmax(index) = max V(n)\nc\nc-----------------------------------------------------------------------\n SUBROUTINE EVMAXI ( n, V, Vmax, ind )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : vector size integer\nc V : vector (n) double\nc\nc OUTPUT \nc Vmax : vector maximum element double\nc ind : index of maximum integer\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER n, ind, i\n DOUBLE PRECISION Vmax, x, V(*)\nc\n Vmax = V(1)\n ind = 1\n IF (n .EQ. 1) RETURN\n DO i = 2,n\n x = V(i)\n IF (x .GT. Vmax) THEN\n Vmax = x\n ind = i\n ENDIF\n ENDDO\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine EVMIN\nc\nc vector minimum, max V(n)\nc\nc-----------------------------------------------------------------------\n SUBROUTINE EVMIN ( n, V, vmin )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : vector size integer\nc V : vector (n) double\nc\nc OUTPUT \nc Vmin : vector minimum element double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER n, i\n DOUBLE PRECISION Vmin, x, V(*)\nc\n Vmin = V(1)\n IF (n .EQ. 1) RETURN\n DO i = 2,n\n x = V(i)\n IF (x .LT. Vmin) Vmin = x\n ENDDO\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine EVMINI\nc\nc vector minimum element and index, Vmin(index) = min V(n)\nc\nc-----------------------------------------------------------------------\n SUBROUTINE EVMINI ( n, V, Vmin, ind )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : vector size integer\nc V : vector (n) double\nc\nc OUTPUT \nc Vmin : vector minimum element double\nc ind : index of minimum integer\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER n, ind, i\n DOUBLE PRECISION Vmin, x, V(*)\nc\n Vmin = V(1)\n ind = 1\n IF (n .EQ. 1) RETURN\n DO i = 2,n\n x = V(i)\n IF (x .LT. Vmin) THEN\n Vmin = x\n ind = i\n ENDIF\n ENDDO\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine IMX\nc\nc matrix scalar initialization, A(i,j) = alpha\nc\nc-----------------------------------------------------------------------\n SUBROUTINE IMX ( n, p, A, alpha )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : number of rows (n>0) integer\nc p : number of columns (p>0) integer\nc alpha : scalar double\nc\nc INPUT/OUTPUT \nc A : matrix (n*p) double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER n, p, i, j\n DOUBLE PRECISION alpha, A(n,*)\nc\n DO j = 1,p\n DO i = 1,n\n A(i,j) = alpha\n ENDDO\n ENDDO\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine IMDX\nc\nc diagonal matrix scalar initialization, D(i,j) = 0.0 \nc = alpha if i=j\nc-----------------------------------------------------------------------\n SUBROUTINE IMDX ( n, D, alpha )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : matrix size integer\nc alpha : scalar double\nc\nc INPUT/OUTPUT \nc D : diagonal matrix (n*n) double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER n, i\n DOUBLE PRECISION alpha, ZERO, D(n,*)\n PARAMETER (ZERO = 0.0)\nc\n CALL IMX (n, n, D, ZERO)\n DO i = 1,n\n D(i,i) = alpha\n ENDDO\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine IMSX\nc\nc symmetric matrix scalar initialization\nc\nc-----------------------------------------------------------------------\n SUBROUTINE IMSX ( n, A, alpha )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : matrix size integer\nc alpha : scalar double\nc\nc INPUT/OUTPUT \nc A : symmetric matrix (n*(n+1)/2) double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER n, p\n DOUBLE PRECISION alpha, A(*)\nc\n p = n*(n + 1)/2\n CALL IVX ( p, A, alpha )\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine IVX\nc\nc vector scalar initialization, V(n) = alpha\nc\nc-----------------------------------------------------------------------\n SUBROUTINE IVX ( n, V, alpha )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : vector size integer\nc alpha : scalar double\nc\nc INPUT/OUTPUT \nc V : vector (n) double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER n, i\n DOUBLE PRECISION alpha, V(*)\nc\n DO i = 1,n\n V(i) = alpha\n ENDDO\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine JMC\nc\nc matrix inverse, invA(n*n) <- A(n*n)^(-1)\nc\nc-----------------------------------------------------------------------\n SUBROUTINE JMC ( n, A, iwork, dwork, invA, info )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : matrix size integer\nc A : matrix(n*n) double\nc\nc WORKSPACE \nc iwork : n integer\nc dwork : n double\nc\nc OUTPUT\nc invA : inverse matrix (n*n) double\nc info : diagnostic argument integer\nc\nc CALL \nc YM : matrix copy\nc DGETRF : LU factorization of a general matrix (LAPACK)\nc DGETRI : inverse a LU factorized matrix (LAPACK)\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\nc\nc i/o arguments\n INTEGER n, info\n DOUBLE PRECISION A(*), invA(*)\nc\nc workspaces\n INTEGER iwork(*)\n DOUBLE PRECISION dwork(*)\nc\nc local variables\n INTEGER lwork, ppi, pdw\nc\nc-----------------------------------------------------------------------\nc\nc initialization\n info = 0\n lwork = n\nc\nc pointers for integer work space : iwork\nc ---------------------------------------\n ppi = 1\nc ppi : pointer for pivot indices of DGETRF, DGETRI (n)\nc\nc total size of iwork array = (n)\nc\nc pointers for double precision work space : dwork\nc -------------------------------------------------\n pdw = 1\nc pdw : pointer for DGETRI workspace (n)\nc\nc total size of dwork array : n\nc\nc----------------------------------------------------------------------\nc\n CALL YM ( n, n, A, invA )\n CALL DGETRF ( n, n, invA, n, iwork(ppi), info )\n CALL DGETRI ( n, invA, n, iwork(ppi), dwork(pdw), lwork, info )\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine JMS\nc\nc matrix (symmetric) inverse, invA(n*n) <- A(n*n)^(-1)\nc\nc-----------------------------------------------------------------------\n SUBROUTINE JMS ( n, A, dwork, invA, info )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : matrix size integer\nc A : matrix (n*n) double\nc\nc WORKSPACE \nc dwork : n*n double\nc\nc OUTPUT \nc invA : inverse matrix (n*n) double\nc info : dignostic argument integer\nc\nc CALL \nc YM : matrix copy \nc DPOTRF : Choleski factorization (LAPACK)\nc DPOTRI : inverse a Choleski factorized matrix (LAPACK)\nc CMLMC : low triangular matrix (n*n)-> square matrix (n*n)\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\nc\nc i/o arguments\n INTEGER n, info\n DOUBLE PRECISION A(*), invA(*)\nc\nc workspaces\n DOUBLE PRECISION dwork(*)\nc\nc local variables\n INTEGER pda\nc\nc-----------------------------------------------------------------------\nc\nc initialization\n info = 0\nc\nc pointers for double precision work space : dwork\nc -------------------------------------------------\n pda = 1\nc pda : pointer temporary matrix (n*n) \nc\nc total size of dwork array : n*n\nc\nc-----------------------------------------------------------------------\nc\n CALL YM ( n, n, A, dwork(pda) )\n CALL DPOTRF ( 'L', n, dwork(pda), n, info )\n CALL DPOTRI ( 'L', n, dwork(pda), n, info )\n CALL CMLMC ( n, dwork(pda), invA )\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine MCM\nc\nc mean of each column of matrix (general)\nc\nc-----------------------------------------------------------------------\n SUBROUTINE MCM ( n, m, A, mean )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : number of rows integer\nc m : number of columns integer\nc A : matrix (n*m) double\nc\nc OUTPUT \nc mean : mean vector (m) double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER n, m, i, j\n double precision sum, A(n,*), mean(*)\nc\n DO j = 1,m\n sum = 0.0\n DO i = 1,n\n sum = sum + A(i,j)\n ENDDO\n mean(j) = sum / n\n ENDDO\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine MCMI\nc\nc mean of an index column of matrix (general)\nc\nc-----------------------------------------------------------------------\n SUBROUTINE MCMI ( n, m, A, ind, mean )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : number of rows integer\nc m : number of columns integer\nc A : matrix (n*m) double\nc ind : column index integer\nc\nc OUTPUT \nc mean : mean of the index column double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER n, m, ind, i\n DOUBLE PRECISION mean, sum, A(n,*)\nc\n IF (ind .GT. m) RETURN\n sum = 0.0\n DO i = 1,n\n sum = sum + A(i,ind)\n ENDDO\n mean = sum / n\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine MLM\nc\nc mean of each row of matrix (general)\nc\nc-----------------------------------------------------------------------\n SUBROUTINE MLM ( n, m, A, mean )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : number of rows integer\nc m : number of columns integer\nc A : matrix (n*m) double\nc\nc OUTPUT \nc mean : mean vector (n) double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER n, m, i, j\n DOUBLE PRECISION sum, mean(*), A(n,*)\nc\n DO j = 1,n\n sum = 0.0\n DO i = 1,m\n sum = sum + A(j,i)\n ENDDO\n mean(j) = sum / m\n ENDDO\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine MLMI\nc\nc mean of the index row of matrix (general)\nc\nc-----------------------------------------------------------------------\n SUBROUTINE MLMI ( n, m, A, ind, mean )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : number of rows integer\nc m : number of columns integer\nc A : matrix (n*m) double\nc ind : row index integer\nc\nc OUTPUT \nc mean : mean of the index row double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER n, m, ind, i\n DOUBLE PRECISION mean, sum, A(n,*)\nc\n IF (ind .GT. n) RETURN\n sum = 0.0\n DO i = 1,m\n sum = sum + A(ind,i)\n ENDDO\n mean = sum / m\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine MM\nc\nc matrix mean\nc\nc-----------------------------------------------------------------------\n SUBROUTINE MM ( n, m, A, mean )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : number of rows integer\nc m : number of columns integer\nc A : matrix (n*m) double\nc\nc OUTPUT \nc mean : matrix mean double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER n, m\n DOUBLE PRECISION mean, A(n,*)\nc\n CALL SEM ( n, m, A, mean )\n mean = mean / (n*m)\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine MMS\nc\nc mean of a vectorized matrix\nc\nc-----------------------------------------------------------------------\nc\nc INPUT\nc nmat : size of the matrix integer\nc mat : matrix as vector (nlmat*ncmat) double\nc\nc OUTPUT\nc moy : mean of the matrix double\nc\nc-----------------------------------------------------------------------\nc\n subroutine MMS ( nmat, mat, moy )\nc\n implicit none\nc\n integer nmat\n double precision mat(*)\n double precision moy\nc\n integer ssm, i, idiag, icol\n double precision som\nc\nc-----------------------------------------------------------------------\nc\n ssm = nmat*(nmat+1)/2\n som = 0.\n icol = 1\nc\n do i=1,ssm\n idiag = icol*(icol+1)/2\n if ( i.eq.idiag ) then\n som = som + mat(i)\n icol = icol + 1\n else\n som = som + 2.*mat(i)\n end if\n end do\nc\n moy = som / (nmat*nmat)\nc\n return\n end\nc\nc=======================================================================\nc\nc subroutine MV\nc\nc mean of a vector\nc\nc-----------------------------------------------------------------------\n SUBROUTINE MV ( n, V, mean )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : vector size integer\nc V : vector (n) double\nc\nc OUTPUT \nc mean : vector mean double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER n\n DOUBLE PRECISION mean, V(*)\nc\n CALL SEV ( n, V, mean )\n mean = mean / n\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine NDM\nc\nc Frobenius-norm of the difference between two matrices, ||A-B||_F\nc SQRT[DIAG[(A-B)'*(A-B)]]\nc\nc-----------------------------------------------------------------------\n SUBROUTINE NDM ( n, m, A, B, normF )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : number of rows integer\nc m : number of columns integer\nc A : matrix (n*m) double\nc B : matrix (n*m) double\nc\nc OUTPUT \nc normF : A - B Frobenius norm double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER n, m, i, j\n DOUBLE PRECISION normF, x, A(n,*), B(n,*)\nc\n normF = 0.\n DO i = 1,m\n DO j = 1,n\n x = A(j,i) - B(j,i)\n normF = normF + x*x\n ENDDO\n ENDDO\n normF = SQRT(normF)\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine NDMS\nc\nc Frobenius-norm of the difference between two matrices, ||A-B||_F\nc A and B symmetrics\nc\nc-----------------------------------------------------------------------\nc\nc INPUT \nc nmat : size of the matrix integer\nc mat1 : matrix 1 as vector(nmat*(nmat+1)/2) double\nc mat2 : matrix 2 as vector(nmat*(nmat+1)/2) double\nc\nc OUTPUT \nc result : scalar = sqrt( sum( diag(M'*M) ) double\nc\nc-----------------------------------------------------------------------\nc\n subroutine NDMS ( nmat, mat1, mat2, normF )\nc\n implicit none\n integer nmat\n double precision normF, mat1(*), mat2(*)\n integer i, im, iv1, incv, k\n double precision am\nc\n normF = 0.0\n im = 1\n do i=1,nmat\n incv = 2*i - 1\n do k=1,nmat\n iv1 = im\n if ( k.le.i ) then\n iv1 = iv1 + k - 1\n else\n iv1 = iv1 + incv\n incv = incv + k\n end if\n am = mat1(iv1) - mat2(iv1)\n normF = normF + am*am\n end do\n im = im + i\n end do\n normf = SQRT(normF)\n return\n end\nc\nc=======================================================================\nc\nc subroutine NDVL1\nc\nc L1-norm of the difference of two vectors, ||x(n) - y(n)||_L1\nc\nc-----------------------------------------------------------------------\nc\nc INPUT \nc nvect : size of the vector integer\nc vect1 : vector(nvect) double\nc vect2 : vector(nvect) double\nc\nc OUTPUT \nc result : double\nc\nc-----------------------------------------------------------------------\nc\n subroutine NDVL1 ( nvect, vect1, vect2, result )\nc\n implicit none\nc\n integer nvect\n double precision result\n double precision vect1(*), vect2(*)\nc\n integer i\nc\nc-----------------------------------------------------------------------\nc\n result = 0.\n do i=1,nvect\n result = result + abs( vect1(i) - vect2(i) )\n end do\nc\n return\n end\nc\nc=======================================================================\nc\nc subroutine NDVL2\nc\nc L2-norm of the difference of two vectors, , ||x(n) - y(n)||_L2\nc\nc-----------------------------------------------------------------------\nc\nc INPUT \nc nvect : size of the vector integer\nc vect1 : vector(nvect) double\nc vect2 : vector(nvect) double\nc\nc OUTPUT \nc result : scalar = sqrt(V'*V) double\nc V = vect1 - vect2\nc\nc-----------------------------------------------------------------------\nc\n subroutine NDVL2 ( nvect, vect1, vect2, result )\nc\n implicit none\nc\n integer nvect\n double precision result\n double precision vect1(*), vect2(*)\nc\n integer i\n double precision diff\nc\nc-----------------------------------------------------------------------\nc\n result = 0.\n do i=1,nvect\n diff = vect1(i) - vect2(i)\n result = result + diff*diff\n end do\n result = sqrt(result)\nc\n return\n end\nc\nc=======================================================================\nc\nc subroutine NM \nc\nc Frobenius norm of a vectorized full matrix\nc The Frobenius norm, sometimes also called the Euclidean norm \nc (which may cause confusion with the vector -norm which also sometimes \nc known as the Euclidean norm), is matrix norm of an matrix defined \nc as the square root of the sum of the absolute squares of its elements\nc\nc / __ __ \\ (1/2)\nc | \\ \\ 2 |\nc || X || = | /_ /_ X(i,j) | \nc \\ i j /\nc \nc _____________ \nc || X || = \\/ Trace (X*X') \nc\nc-----------------------------------------------------------------------\n SUBROUTINE NM ( n, p, x, norm )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : number of rows integer\nc p : number of columns integer\nc x : matrix (n*p) double\nc\nc OUTPUT \nc norm : Frobenius norm double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\nc\nc i/o argument\n INTEGER n, p\n DOUBLE PRECISION norm, x(n,*)\nc\nc local variables\n INTEGER i,j\n DOUBLE PRECISION tmp\nc\n norm = 0.0\n DO i = 1,p\n DO j = 1,n\n tmp = x(j, i)\n norm = norm + tmp*tmp\n ENDDO\n ENDDO\n norm = SQRT(norm)\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine NM1 \nc\nc L1-norm of a vectorized full matrix\nc\nc The L1-norm is the maximum absolute column sum norm defined as: \nc __\nc \\\nc || X || = max /_ |X(i,j)| \nc j=1,...p i\nc\nc-----------------------------------------------------------------------\n subroutine NM1 ( n, p, x, norm )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : number of rows (n>0) integer\nc p : number of columns (p>0) integer\nc x : matrix (n*p) double\nc\nc OUTPUT \nc norm : L1-norm double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\nc\nc i/o argument\n INTEGER n, p\n DOUBLE PRECISION norm, x(n,*)\nc\nc local variables\n INTEGER i, j\n DOUBLE PRECISION sum\nc\n norm = 0.0\n DO i = 1,p\n sum = 0.0\n DO j = 1,n\n sum = sum + abs(x(j, i))\n ENDDO\n IF (sum .GT. norm) norm = sum\n ENDDO\n RETURN\n END \nc\nc=======================================================================\nc\nc subroutine NMINF version 1.0\nc\nc Infinte norm of a matrix\nc The infinite norm is the maximum absolute row sum norm defined by: \nc __\nc \\\nc || X || = max /_ |X(i,j)| \nc i=1,...,n j\nc\nc-----------------------------------------------------------------------\n SUBROUTINE NMINF ( n, p, x, norm )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : nb rows of the matrix (n>0) integer\nc p : nb columns of the matrix (p>0) integer\nc x : input matrix (n*p) double\nc\nc OUTPUT \nc norm : infinite norm double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\nc\nc i/o arguments\n INTEGER n, p\n DOUBLE PRECISION norm, x(n,*)\nc\nc local variables\n INTEGER i,j\n DOUBLE PRECISION sum\nc\n norm = 0.0\n DO i = 1,n\n sum = 0.0\n DO j = 1,p\n sum = sum + ABS(x(i, j))\n ENDDO\n IF (sum .GT. norm) norm = sum\n ENDDO\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine NMS\nc\nc Frobenius-norm of a vectorized symmetric matrix\nc\nc-----------------------------------------------------------------------\nc\nc INPUT \nc nmat : size of the matrix integer\nc mat : matrix as vector(nmat*(nmat+1)/2) double\nc\nc OUTPUT \nc result : scalar = sqrt( sum( diag(M'*M) ) double\nc\nc-----------------------------------------------------------------------\nc\n subroutine NMS ( nmat, mat, norm )\nc\n implicit none\nc\n integer nmat\n double precision norm, mat(*)\n integer i, im, iv1, incv, k\n double precision am\nc\n norm = 0.\n im = 1\n do i=1,nmat\n incv = 2*i - 1\n do k=1,nmat\n iv1 = im\n if ( k.le.i ) then\n iv1 = iv1 + k - 1\n else\n iv1 = iv1 + incv\n incv = incv + k\n end if\n am = mat(iv1)\n norm = norm + am*am\n end do\n im = im + i\n end do\n norm = SQRT(norm)\n return\n end\nc\nc=======================================================================\nc\nc subroutine NSV\nc\nc L2-norm of the sum of 2 vectors\nc\nc-----------------------------------------------------------------------\nc\nc INPUT \nc nvect : size of the vector integer\nc vect1 : vector(nvect) double\nc vect2 : vector(nvect) double\nc\nc OUTPUT \nc result : scalar = sqrt(V'*V) double\nc V = vect1 + vect2\nc\nc-----------------------------------------------------------------------\nc\n subroutine NSV ( nvect, vect1, vect2, norm )\nc\n implicit none\nc\n integer nvect, i\n double precision norm, sum, vect1(*), vect2(*)\nc\n norm = 0.0\n do i=1,nvect\n sum = vect1(i) + vect2(i)\n norm = norm + sum*sum\n end do\n norm = SQRT(norm)\n return\n end\nc\nc=======================================================================\nc\nc subroutine NV\nc _________________\nc L2-norm of a vector, ||x|| = \\/ sum of x(i)*x(i)\nc = sqrt(x'*x)\nc\nc-----------------------------------------------------------------------\n subroutine NV ( n, x, norm )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : size (n>0) integer\nc x : input vector (n) double\nc\nc OUTPUT \nc norm : L2-norm double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\nc\nc i/o arguments\n INTEGER n\n DOUBLE PRECISION norm, x(*)\nc \nc external functions\n DOUBLE PRECISION dnrm2\n EXTERNAL dnrm2 \nc\nc local variables \n INTEGER incx\n PARAMETER( incx=1 )\nc\n norm = dnrm2(n, x, incx)\n RETURN\n END \nc\nc=======================================================================\nc\nc subroutine NV1\nc\nc L1-norm of a vector, ||x|| = sum of the elements |x(i)|\nc\nc-----------------------------------------------------------------------\n SUBROUTINE NV1 ( nvect, vect, norm )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc nvect : size of the vectors integer\nc vect : vector (nvect) double\nc\nc OUTPUT \nc norm : L1-norm double\nc\nc-----------------------------------------------------------------------\nc\n implicit none\nc\n integer nvect, i\n double precision norm, vect(*)\nc\n norm = 0.0\n do i=1,nvect\n norm = norm + DABS(vect(i))\n end do\n return\n end \n \nc\nc=======================================================================\nc\nc subroutine NV2\nc\nc L2-norm square of a vector\nc\nc-----------------------------------------------------------------------\nc\nc INPUT \nc nvect : size of the vectors integer\nc vect : vector (nvect) double\nc\nc OUTPUT \nc result : scalar = V'*V double\nc\nc-----------------------------------------------------------------------\nc\n subroutine NV2 ( nvect, vect, norm )\nc\n implicit none\nc\n integer nvect, i\n double precision norm, av, vect(*)\nc\n norm = 0.0\n do i=1,nvect\n av = vect(i)\n norm = norm + av*av\n end do\n return\n end\nc\nc=======================================================================\nc\nc subroutine NVINF\nc\nc Infinite-norm of a vector, ||x|| = max|x(i)|\nc i\nc\nc-----------------------------------------------------------------------\n SUBROUTINE NVINF ( n, x, norm )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : size (n>0) integer\nc x : input vector (n) double\nc\nc OUTPUT \nc norm : infinite-norm double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\nc\nc i/o arguments\n INTEGER n\n DOUBLE PRECISION norm, x(*)\nc\nc local parameters\n INTEGER i\n DOUBLE PRECISION tmp\nc\n norm = abs(x(1))\n IF (n .EQ. 1) RETURN\n DO i = 2,n\n tmp = abs(x(i))\n IF (tmp .GT. norm) norm = tmp\n ENDDO\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine SCM\nc\nc Computes the sum of columns of a matrix\nc\nc-----------------------------------------------------------------------\n SUBROUTINE SCM ( nlmat, ncmat, mat, svect )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc nlmat : number of rows of the matrix mat integer\nc ncmat : number of columns of the matrix mat integer\nc mat : matrix as vector (nlmat*ncmat) double\nc\nc OUTPUT \nc svect : sum of each column vector(ncmat) double\nc\nc-----------------------------------------------------------------------\nc\n implicit none\nc\n integer nlmat, ncmat\n double precision mat(nlmat,*)\n double precision svect(*)\nc\n integer i,j\n double precision sum\nc\nc-----------------------------------------------------------------------\nc\nc y(m) = A'(n,m)*x(n) where x(i)=1.0 i=1,...,n \nc CALL PMTV ( n, m, A, x, y )\n\n do j=1,ncmat\n sum = 0.\n do i=1,nlmat\n sum = sum + mat(i,j)\n end do\n svect(j) = sum\n end do\nc\n return\n end\nc\nc=======================================================================\nc\nc subroutine SEM\nc\nc sum of the elements of a matrix \nc\nc-----------------------------------------------------------------------\n SUBROUTINE SEM ( n, m, A, sum )\nc----------------------------------------------------------------------- \nc\nc INPUT \nc n : number of rows integer\nc m : number of columns integer\nc A : matrix (n*m) double\nc\nc OUTPUT \nc sum : sum of the elements of A(n,m) double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER n, m, p\n DOUBLE PRECISION sum, A(*)\nc\n p = n*m\n CALL SEV ( p, A, sum )\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine SEMDX\nc\nc sum matrix/scalar, B(n,n) <- A(n,n) + x*Id\nc\nc-----------------------------------------------------------------------\n subroutine SEMDX ( n, A, alpha, B )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : matrix size integer\nc A : matrix (n*n) double\nc alpha : scalar double\nc\nc OUTPUT \nc B : matrix (n*n) double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER i, n\n DOUBLE PRECISION alpha, A(n,*), B(n,*)\nc\nc copy B <- A\n CALL YM ( n, n, A, B )\n DO i = 1,n\n B(i,i) = B(i,i) + alpha\n ENDDO\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine SEV\nc\nc sum of the elements of a vector\nc\nc-----------------------------------------------------------------------\n SUBROUTINE SEV ( n, x, sum )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : vector size integer\nc x : vector (n) double\nc\nc OUTPUT \nc sum : sum of the elements of x(n) double\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\n INTEGER i, n\n DOUBLE PRECISION sum, x(*)\nc\n sum = 0.0\n DO i = 1,n\n sum = sum + x(i)\n ENDDO\n RETURN\n END\nc\nc=======================================================================\nc\nc subroutine SEVP\nc\nc Computing the sum of the elements of a part of a vector\nc\nc-----------------------------------------------------------------------\nc\nc INPUT \nc nvect : size of the vector integer\nc vect : vector(nvect) double\nc efirst : first element of vect to sum integer\nc nsum : number of element of vect to sum integer\nc\nc OUTPUT \nc sum : sum of the elements of the vector double\nc info : = 0 successful exit integer\nc\nc-----------------------------------------------------------------------\nc\n subroutine SEVP ( nvect, vect, efirst, nsum, sum, info )\nc\n implicit none\nc\n integer nvect, efirst, nsum, info\n double precision vect(*)\n double precision sum\nc\n integer i\nc\nc-----------------------------------------------------------------------\nc\nc initialization\n info = 0\nc\n if ( efirst+nsum-1.gt.nvect ) then\n info = -2\n return\n endif\n \n sum = 0.\n do i=1,nsum\n sum = sum + vect(efirst+i-1)\n end do\nc\n return\n end\nc\nc=======================================================================\nc\nc subroutine SLM\nc\nc Computes the sum of rows of a matrix\nc\nc-----------------------------------------------------------------------\nc\nc INPUT \nc nlmat : number of rows of the matrix mat integer\nc ncmat : number of columns of the matrix mat integer\nc mat : matrix as vector (nlmat*ncmat) double\nc\nc OUTPUT \nc svect : sum of each row vector(nlmat) double\nc\nc-----------------------------------------------------------------------\nc\n subroutine SLM ( nlmat, ncmat, mat, svect )\nc\n implicit none\nc\n integer nlmat, ncmat\n double precision mat(nlmat,*)\n double precision svect(*)\nc\n integer i,j\n double precision sum\nc\nc-----------------------------------------------------------------------\nc\n do j=1,nlmat\n sum = 0.0\n do i=1,ncmat\n sum = sum + mat(j,i)\n end do\n svect(j) = sum\n end do\nc\n return\n end\nc\nc=======================================================================\nc\nc subroutine SM\nc\nc Computing the sum of 2 matrices\nc\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : number of rows of the matrices integer\nc m : number of columns of the matrices integer\nc mat1 : matrix(n*m) double\nc mat2 : matrix(n*m) double\nc\nc OUTPUT \nc mats : mat1 + mat2 matrix(n*m) double\nc\nc-----------------------------------------------------------------------\nc\n subroutine SM ( n, m, mat1, mat2, mats )\nc\n implicit none\nc\n integer n, m\n double precision mat1(n,*), mat2(n,*), mats(n,*)\nc\n integer i, j\nc\nc-----------------------------------------------------------------------\nc\n do j=1,m\n do i=1,n\n mats(i,j) = mat1(i,j) + mat2(i,j)\n end do\n end do\nc\n return\n end\nc\nc=======================================================================\nc\nc subroutine SMbis\nc\nc Computing the sum of 2 matrices\nc\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : number of rows of the matrices integer\nc m : number of columns of the matrices integer\nc mat1 : matrix(n*m) double\nc\nc INPUT/OUTPUT \nc mats : mat1 + mats matrix(n*m) double\nc\nc-----------------------------------------------------------------------\nc\n subroutine SMbis ( n, m, mat1, mats )\nc\n implicit none\nc\n integer n, m\n double precision mat1(n,*), mats(n,*)\nc\n integer i, j\nc\nc-----------------------------------------------------------------------\nc\n do j=1,m\n do i=1,n\n mats(i,j) = mat1(i,j) + mats(i,j)\n end do\n end do\nc\n return\n end \nc\nc=======================================================================\nc\nc subroutine SMS\nc\nc Computing the sum of 2 vectorized symmetric matrices\nc\nc-----------------------------------------------------------------------\nc\nc INPUT \nc nmat : size of matrices integer\nc vect1 : symmetric matrix as vector(nmat*(nmat+1)/2) double\nc vect2 : symmetric matrix as vector(nmat*(nmat+1)/2) double\nc\nc OUTPUT \nc vects : vect1 + vect2\nc symmetric matrix as vector(nmat*(nmat+1)/2) double\nc\nc-----------------------------------------------------------------------\nc\n subroutine SMS ( nmat, vect1, vect2, vects )\nc\n implicit none\nc\n integer nmat\n double precision vect1(*), vect2(*), vects(*)\nc\n integer i, j, k\nc\nc-----------------------------------------------------------------------\nc\n k = 0\n do j=1,nmat\n do i=1,j\n k = k + 1\n vects(k) = vect1(k) + vect2(k)\n end do\n end do\nc\n return\n end\nc\nc=======================================================================\nc\nc subroutine SMX\nc\nc computing the sum of a matrix with a scalar\nc\nc-----------------------------------------------------------------------\nc\nc INPUT \nc nlmat : number of rows of the matrix mat integer\nc ncmat : number of columns of the matrix mat integer\nc mat : matrix (nlmat*ncmat) double\nc scal : scalar double\nc\nc OUTPUT \nc mout : matrix (nlmat*ncmat) double\nc\nc-----------------------------------------------------------------------\nc\n subroutine SMX ( nlmat, ncmat, mat, scal, mout )\nc\n implicit none\nc\n integer nlmat, ncmat\n double precision mat(*), mout(*)\n double precision scal\nc\n integer i\nc\nc-----------------------------------------------------------------------\nc\n do i=1,nlmat*ncmat\n mout(i) = mat(i) + scal\n end do\nc\n return\n end\nc\nc=======================================================================\nc\nc subroutine TM\nc\nc Computing the trace of a full square matrix\nc\nc-----------------------------------------------------------------------\nc\nc INPUT \nc nmat : size of matrix mat integer\nc mat : square matrix(nmat*nmat) double\nc\nc OUTPUT \nc trace : matrix trace double\nc\nc-----------------------------------------------------------------------\nc\n subroutine TM ( nmat, mat, trace )\nc\n implicit none\nc\n integer nmat\n double precision mat(nmat,*), trace\nc\n integer i\nc\nc-----------------------------------------------------------------------\nc\n trace = 0.\n do i=1,nmat\n trace = trace + mat(i,i)\n end do\nc\n return\n end\nc\nc=======================================================================\nc\nc subroutine TMS\nc\nc Computing the trace of a symmetric matrix\nc\nc-----------------------------------------------------------------------\nc\nc INPUT \nc nmat : size of matrix mat integer\nc vect : symmetric matrix as vector(nmat*(nmat+1)/2) double\nc\nc OUTPUT \nc trace : matrix trace double\nc\nc-----------------------------------------------------------------------\nc\n subroutine TMS ( nmat, vect, trace )\nc\n implicit none\nc\n integer nmat\n double precision vect(*), trace\nc\n integer i, k\nc\nc-----------------------------------------------------------------------\nc\n trace = 0.\n k = 0\n do i=1,nmat\n k = k + i\n trace = trace + vect(k)\n end do\nc\n return\n end\nc\nc=======================================================================\nc\nc subroutine WVEQ\nc\nc who is equal to x in a vector ? (+/- epsilon) -> index vector\nc\nc-----------------------------------------------------------------------\nc\nc INPUT\nc nvect : size of the vector integer\nc vect : vector(nvect) double\nc val : value double\nc eps : tolerance double\nc\nc OUTPUT\nc nind : size of the indexes vector (max : nvect) integer\nc index : index of elements = value(+/- epsilon),\nc vector(nind) integer\nc\nc-----------------------------------------------------------------------\nc\n subroutine WVEQ ( nvect, vect, val, eps, nind, index )\nc\n implicit none\nc\n integer nvect, nind\n integer index(*)\n double precision val, eps\n double precision vect(*)\nc\n integer i\nc\nc-----------------------------------------------------------------------\nc\n nind = 0\n do i=1,nvect\nc\n if ( abs(vect(i)-val).lt.eps ) then\n nind = nind + 1\n index(nind) = i\n endif\nc\n end do\nc \n return\n end\nc\nc=======================================================================\nc\nc subroutine WVGT\nc\nc who is greater than x in a vector ? gives a vector of indexes\nc\nc-----------------------------------------------------------------------\nc\nc INPUT\nc nvect : size of the vector integer\nc vect : vector(nvect) double\nc val : value double\nc\nc OUTPUT\nc nind : size of the indexes vector (max : nvect) integer\nc index : index of elements > value, vector(nind) integer\nc\nc-----------------------------------------------------------------------\nc\n subroutine WVGT ( nvect, vect, val, nind, index )\nc\n implicit none\nc\n integer nvect, nind\n integer index(*)\n double precision val\n double precision vect(*)\nc\n integer i\nc\nc-----------------------------------------------------------------------\nc\n nind = 0\n do i=1,nvect\nc\n if ( vect(i).gt.val ) then\n nind = nind + 1\n index(nind) = i\n endif\nc\n end do\nc \n return\n end\nc\nc=======================================================================\nc\nc subroutine WVLT\nc\nc who is lower than x in a vector ? gives a vector of indexes\nc\nc-----------------------------------------------------------------------\nc\nc INPUT\nc nvect : size of the vector integer\nc vect : vector(nvect) double\nc val : value double\nc\nc OUTPUT\nc nind : size of the indexes vector (max : nvect) integer\nc index : index of elements < value, vector(nind) integer\nc\nc-----------------------------------------------------------------------\nc\n subroutine WVLT ( nvect, vect, val, nind, index )\nc\n implicit none\nc\n integer nvect, nind\n integer index(*)\n double precision val\n double precision vect(*)\nc\n integer i\nc\nc-----------------------------------------------------------------------\nc\n nind = 0\n do i=1,nvect\nc\n if ( vect(i).lt.val ) then\n nind = nind + 1\n index(nind) = i\n endif\nc\n end do\nc \n return\n end\nc\nc=======================================================================\nc\nc subroutine XM\nc\nc Computing scalar product of 2 matrices\nc (M1 matrix n*m, M2 matrix n*m, gives M1.M2= scalar )\nc\nc-----------------------------------------------------------------------\nc\nc INPUT \nc nlmat : number of raws of matrices integer\nc ncmat : number of columns in matrices integer\nc mat1 : symmetric matrix 1 vector(nlmat*ncmat) double\nc mat2 : symmetric matrix 2 vector(nlmat*ncmat) double\nc OUTPUT\nc scapro : scalar product double\nc\nc-----------------------------------------------------------------------\nc\n subroutine XM ( nlmat, ncmat, mat1, mat2, scapro )\nc\n implicit none\nc\n integer nlmat, ncmat\n double precision mat1(nlmat,*), mat2(nlmat,*)\n double precision scapro\nc\n integer i, j\nc\nc-----------------------------------------------------------------------\nc\n scapro = 0.0\n do j=1,ncmat\n do i=1,nlmat\n scapro = scapro + mat1(i,j)*mat2(i,j)\n end do\n end do\nc\n return\n end\nc\nc=======================================================================\nc\nc subroutine XMS\nc\nc Computing scalar product of 2 symmetric matrices\nc (M1 symmetric matrix n*n, M2 symmetric matrix n*n, gives scalar )\nc\nc-----------------------------------------------------------------------\nc\nc INPUT\nc nmat : size of the matrix mat1 and mat2 integer\nc mat1 : symmetric matrix 1 vector(nmat*(nmat+1)/2) double\nc mat2 : symmetric matrix 2 vector(nmat*(nmat+1)/2) double\nc OUTPUT\nc scapro : scalar product double\nc\nc-----------------------------------------------------------------------\nc\n subroutine XMS ( nmat, mat1, mat2, scapro )\nc\n implicit none\nc\n integer nmat\n double precision mat1(*), mat2(*)\n double precision scapro\nc\n integer i, j, ivect\nc\nc-----------------------------------------------------------------------\nc\n scapro = 0.0\n ivect = 0\n do i=1,nmat\n do j=1,i\n ivect = ivect + 1\n if (i.eq.j) then\n scapro = scapro + mat1(ivect)*mat2(ivect)\n else\n scapro = scapro + 2.*mat1(ivect)*mat2(ivect)\n end if\n end do\n end do\nc\n return\n end\nc\nc=======================================================================\nc\nc subroutine YCMV\nc\nc Copy a column of a vectorized matrix in a vector\nc\nc-----------------------------------------------------------------------\nc\nc INPUT \nc nlmat : number of rows of the matrix mat integer\nc ncmat : number of columns of the matrix mat integer\nc matin : input matrix as vector(nlmat*ncmat) double\nc ncol : number of the column to copy (= real64 ! working precision\n\n implicit none\n\n private\n\n real(wp), parameter, private :: zero = 0.0_wp !< numeric constant\n real(wp), parameter, private :: one = 1.0_wp !< numeric constant\n\n type, public, abstract :: linear_interp_class\n !< Base class for the linear interpolation types\n private\n logical :: initialized = .false. !< if the class was properly initialized\n contains\n private\n procedure(destroy_func), deferred, public :: destroy !< destructor\n procedure :: check_inputs\n endtype linear_interp_class\n\n abstract interface\n pure elemental subroutine destroy_func(me) !< interface for bspline destructor routines\n import :: linear_interp_class\n implicit none\n class(linear_interp_class), intent(inout) :: me\n endsubroutine destroy_func\n endinterface\n\n type, extends(linear_interp_class), public :: linear_interp_1d\n !< Class for 1d linear interpolation.\n private\n real(wp), dimension(:), allocatable :: f\n real(wp), dimension(:), allocatable :: x\n integer :: ilox = 1\n contains\n private\n procedure, public :: initialize => initialize_1d\n procedure, public :: evaluate => interp_1d\n procedure, public :: destroy => destroy_1d\n final :: finalize_1d\n endtype linear_interp_1d\n\n type, extends(linear_interp_class), public :: linear_interp_2d\n !< Class for 2d linear interpolation.\n private\n real(wp), dimension(:, :), allocatable :: f\n real(wp), dimension(:), allocatable :: x\n real(wp), dimension(:), allocatable :: y\n integer :: ilox = 1\n integer :: iloy = 1\n contains\n private\n procedure, public :: initialize => initialize_2d\n procedure, public :: evaluate => interp_2d\n procedure, public :: destroy => destroy_2d\n final :: finalize_2d\n endtype linear_interp_2d\n\n type, extends(linear_interp_class), public :: linear_interp_3d\n !< Class for 3d linear interpolation.\n private\n real(wp), dimension(:, :, :), allocatable :: f\n real(wp), dimension(:), allocatable :: x\n real(wp), dimension(:), allocatable :: y\n real(wp), dimension(:), allocatable :: z\n integer :: ilox = 1\n integer :: iloy = 1\n integer :: iloz = 1\n contains\n private\n procedure, public :: initialize => initialize_3d\n procedure, public :: evaluate => interp_3d\n procedure, public :: destroy => destroy_3d\n final :: finalize_3d\n endtype linear_interp_3d\n\n type, extends(linear_interp_class), public :: linear_interp_4d\n !< Class for 4d linear interpolation.\n private\n real(wp), dimension(:, :, :, :), allocatable :: f\n real(wp), dimension(:), allocatable :: x\n real(wp), dimension(:), allocatable :: y\n real(wp), dimension(:), allocatable :: z\n real(wp), dimension(:), allocatable :: q\n integer :: ilox = 1\n integer :: iloy = 1\n integer :: iloz = 1\n integer :: iloq = 1\n contains\n private\n procedure, public :: initialize => initialize_4d\n procedure, public :: evaluate => interp_4d\n procedure, public :: destroy => destroy_4d\n final :: finalize_4d\n endtype linear_interp_4d\n\n type, extends(linear_interp_class), public :: linear_interp_5d\n !< Class for 5d linear interpolation.\n private\n real(wp), dimension(:, :, :, :, :), allocatable :: f\n real(wp), dimension(:), allocatable :: x\n real(wp), dimension(:), allocatable :: y\n real(wp), dimension(:), allocatable :: z\n real(wp), dimension(:), allocatable :: q\n real(wp), dimension(:), allocatable :: r\n integer :: ilox = 1\n integer :: iloy = 1\n integer :: iloz = 1\n integer :: iloq = 1\n integer :: ilor = 1\n contains\n private\n procedure, public :: initialize => initialize_5d\n procedure, public :: evaluate => interp_5d\n procedure, public :: destroy => destroy_5d\n final :: finalize_5d\n endtype linear_interp_5d\n\n type, extends(linear_interp_class), public :: linear_interp_6d\n !< Class for 6d linear interpolation.\n private\n real(wp), dimension(:, :, :, :, :, :), allocatable :: f\n real(wp), dimension(:), allocatable :: x\n real(wp), dimension(:), allocatable :: y\n real(wp), dimension(:), allocatable :: z\n real(wp), dimension(:), allocatable :: q\n real(wp), dimension(:), allocatable :: r\n real(wp), dimension(:), allocatable :: s\n integer :: ilox = 1\n integer :: iloy = 1\n integer :: iloz = 1\n integer :: iloq = 1\n integer :: ilor = 1\n integer :: ilos = 1\n contains\n private\n procedure, public :: initialize => initialize_6d\n procedure, public :: evaluate => interp_6d\n procedure, public :: destroy => destroy_6d\n final :: finalize_6d\n endtype linear_interp_6d\n\n type, extends(linear_interp_1d), public :: nearest_interp_1d\n !< Class for 1d nearest neighbor interpolation.\n contains\n procedure, public :: evaluate => nearest_1d\n endtype nearest_interp_1d\n\n type, extends(linear_interp_2d), public :: nearest_interp_2d\n !< Class for 2d nearest neighbor interpolation.\n contains\n procedure, public :: evaluate => nearest_2d\n endtype nearest_interp_2d\n\n type, extends(linear_interp_3d), public :: nearest_interp_3d\n !< Class for 3d nearest neighbor interpolation.\n contains\n procedure, public :: evaluate => nearest_3d\n endtype nearest_interp_3d\n\n type, extends(linear_interp_4d), public :: nearest_interp_4d\n !< Class for 4d nearest neighbor interpolation.\n contains\n procedure, public :: evaluate => nearest_4d\n endtype nearest_interp_4d\n\n type, extends(linear_interp_5d), public :: nearest_interp_5d\n !< Class for 5d nearest neighbor interpolation.\n contains\n procedure, public :: evaluate => nearest_5d\n endtype nearest_interp_5d\n\n type, extends(linear_interp_6d), public :: nearest_interp_6d\n !< Class for 6d nearest neighbor interpolation.\n contains\n procedure, public :: evaluate => nearest_6d\n endtype nearest_interp_6d\n\ncontains\n!*****************************************************************************************\n\n!*****************************************************************************************\n!<\n! Finalizer for a [[linear_interp_1d]] type.\n\n pure elemental subroutine finalize_1d(me)\n\n implicit none\n\n type(linear_interp_1d), intent(inout) :: me\n call me%destroy()\n\n endsubroutine finalize_1d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!<\n! Finalizer for a [[linear_interp_2d]] type.\n\n pure elemental subroutine finalize_2d(me)\n\n implicit none\n\n type(linear_interp_2d), intent(inout) :: me\n call me%destroy()\n\n endsubroutine finalize_2d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!<\n! Finalizer for a [[linear_interp_3d]] type.\n\n pure elemental subroutine finalize_3d(me)\n\n implicit none\n\n type(linear_interp_3d), intent(inout) :: me\n call me%destroy()\n\n endsubroutine finalize_3d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!<\n! Finalizer for a [[linear_interp_4d]] type.\n\n pure elemental subroutine finalize_4d(me)\n\n implicit none\n\n type(linear_interp_4d), intent(inout) :: me\n call me%destroy()\n\n endsubroutine finalize_4d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!<\n! Finalizer for a [[linear_interp_5d]] type.\n\n pure elemental subroutine finalize_5d(me)\n\n implicit none\n\n type(linear_interp_5d), intent(inout) :: me\n call me%destroy()\n\n endsubroutine finalize_5d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!<\n! Finalizer for a [[linear_interp_6d]] type.\n\n pure elemental subroutine finalize_6d(me)\n\n implicit none\n\n type(linear_interp_6d), intent(inout) :: me\n call me%destroy()\n\n endsubroutine finalize_6d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!<\n! Destructor for a [[linear_interp_1d]] class.\n\n pure elemental subroutine destroy_1d(me)\n\n implicit none\n\n class(linear_interp_1d), intent(inout) :: me\n\n if(allocated(me%f)) deallocate(me%f)\n if(allocated(me%x)) deallocate(me%x)\n me%ilox = 1\n me%initialized = .false.\n\n endsubroutine destroy_1d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!<\n! Destructor for a [[linear_interp_2d]] class.\n\n pure elemental subroutine destroy_2d(me)\n\n implicit none\n\n class(linear_interp_2d), intent(inout) :: me\n\n if(allocated(me%f)) deallocate(me%f)\n if(allocated(me%x)) deallocate(me%x)\n if(allocated(me%y)) deallocate(me%y)\n me%ilox = 1\n me%iloy = 1\n me%initialized = .false.\n\n endsubroutine destroy_2d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!<\n! Destructor for a [[linear_interp_3d]] class.\n\n pure elemental subroutine destroy_3d(me)\n\n implicit none\n\n class(linear_interp_3d), intent(inout) :: me\n\n if(allocated(me%f)) deallocate(me%f)\n if(allocated(me%x)) deallocate(me%x)\n if(allocated(me%y)) deallocate(me%y)\n if(allocated(me%z)) deallocate(me%z)\n me%ilox = 1\n me%iloy = 1\n me%iloz = 1\n me%initialized = .false.\n\n endsubroutine destroy_3d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!<\n! Destructor for a [[linear_interp_4d]] class.\n\n pure elemental subroutine destroy_4d(me)\n\n implicit none\n\n class(linear_interp_4d), intent(inout) :: me\n\n if(allocated(me%f)) deallocate(me%f)\n if(allocated(me%x)) deallocate(me%x)\n if(allocated(me%y)) deallocate(me%y)\n if(allocated(me%z)) deallocate(me%z)\n if(allocated(me%q)) deallocate(me%q)\n me%ilox = 1\n me%iloy = 1\n me%iloz = 1\n me%iloq = 1\n me%initialized = .false.\n\n endsubroutine destroy_4d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!<\n! Destructor for a [[linear_interp_5d]] class.\n\n pure elemental subroutine destroy_5d(me)\n\n implicit none\n\n class(linear_interp_5d), intent(inout) :: me\n\n if(allocated(me%f)) deallocate(me%f)\n if(allocated(me%x)) deallocate(me%x)\n if(allocated(me%y)) deallocate(me%y)\n if(allocated(me%z)) deallocate(me%z)\n if(allocated(me%q)) deallocate(me%q)\n if(allocated(me%r)) deallocate(me%r)\n me%ilox = 1\n me%iloy = 1\n me%iloz = 1\n me%iloq = 1\n me%ilor = 1\n me%initialized = .false.\n\n endsubroutine destroy_5d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!<\n! Destructor for a [[linear_interp_6d]] class.\n\n pure elemental subroutine destroy_6d(me)\n\n implicit none\n\n class(linear_interp_6d), intent(inout) :: me\n\n if(allocated(me%f)) deallocate(me%f)\n if(allocated(me%x)) deallocate(me%x)\n if(allocated(me%y)) deallocate(me%y)\n if(allocated(me%z)) deallocate(me%z)\n if(allocated(me%q)) deallocate(me%q)\n if(allocated(me%r)) deallocate(me%r)\n if(allocated(me%s)) deallocate(me%s)\n me%ilox = 1\n me%iloy = 1\n me%iloz = 1\n me%iloq = 1\n me%ilor = 1\n me%ilos = 1\n me%initialized = .false.\n\n endsubroutine destroy_6d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!<\n! Constructor for a [[linear_interp_1d]] class.\n\n pure subroutine initialize_1d(me, x, f, istat)\n\n implicit none\n\n class(linear_interp_1d), intent(inout) :: me\n real(wp), dimension(:), intent(in) :: x\n real(wp), dimension(:), intent(in) :: f\n integer, intent(out) :: istat !< `0` : no problems,\n!< `1` : `x` is not strictly increasing,\n!< `10` : `x` is not equal to size(f,1),\n!< `100` : cannot use linear interpolation for only one point.\n\n call me%destroy()\n\n istat = 0\n\n if(istat == 0 .and. size(x) /= size(f, 1)) istat = 10\n\n if(istat == 0) then\n call me%check_inputs(x=x, ierr=istat)\n if(istat == 0) then\n allocate(me%f(size(x))); me%f = f\n allocate(me%x(size(x))); me%x = x\n me%initialized = .true.\n endif\n endif\n\n endsubroutine initialize_1d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!<\n! Constructor for a [[linear_interp_2d]] class.\n\n pure subroutine initialize_2d(me, x, y, f, istat)\n\n implicit none\n\n class(linear_interp_2d), intent(inout) :: me\n real(wp), dimension(:), intent(in) :: x\n real(wp), dimension(:), intent(in) :: y\n real(wp), dimension(:, :), intent(in) :: f\n integer, intent(out) :: istat !< `0` : no problems,\n!< `1` : `x` is not strictly increasing,\n!< `2` : `y` is not strictly increasing,\n!< `10` : `x` is not equal to size(f,1),\n!< `20` : `y` is not equal to size(f,2),\n!< `100` : cannot use linear interpolation for only one point.\n\n call me%destroy()\n\n istat = 0\n\n if(istat == 0 .and. size(x) /= size(f, 1)) istat = 10\n if(istat == 0 .and. size(y) /= size(f, 2)) istat = 20\n\n if(istat == 0) then\n call me%check_inputs(x=x, y=y, ierr=istat)\n if(istat == 0) then\n allocate(me%f(size(x), size(y))); me%f = f\n allocate(me%x(size(x))); me%x = x\n allocate(me%y(size(y))); me%y = y\n me%initialized = .true.\n endif\n endif\n\n endsubroutine initialize_2d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!<\n! Constructor for a [[linear_interp_3d]] class.\n\n pure subroutine initialize_3d(me, x, y, z, f, istat)\n\n implicit none\n\n class(linear_interp_3d), intent(inout) :: me\n real(wp), dimension(:), intent(in) :: x\n real(wp), dimension(:), intent(in) :: y\n real(wp), dimension(:), intent(in) :: z\n real(wp), dimension(:, :, :), intent(in) :: f\n integer, intent(out) :: istat !< `0` : no problems,\n!< `1` : `x` is not strictly increasing,\n!< `2` : `y` is not strictly increasing,\n!< `3` : `z` is not strictly increasing,\n!< `10` : `x` is not equal to size(f,1),\n!< `20` : `y` is not equal to size(f,2),\n!< `30` : `z` is not equal to size(f,3),\n!< `100` : cannot use linear interpolation for only one point.\n\n call me%destroy()\n\n istat = 0\n\n if(istat == 0 .and. size(x) /= size(f, 1)) istat = 10\n if(istat == 0 .and. size(y) /= size(f, 2)) istat = 20\n if(istat == 0 .and. size(z) /= size(f, 3)) istat = 30\n\n if(istat == 0) then\n call me%check_inputs(x=x, y=y, z=z, ierr=istat)\n if(istat == 0) then\n allocate(me%f(size(x), size(y), size(z))); me%f = f\n allocate(me%x(size(x))); me%x = x\n allocate(me%y(size(y))); me%y = y\n allocate(me%z(size(z))); me%z = z\n me%initialized = .true.\n endif\n endif\n\n endsubroutine initialize_3d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!<\n! Constructor for a [[linear_interp_4d]] class.\n\n pure subroutine initialize_4d(me, x, y, z, q, f, istat)\n\n implicit none\n\n class(linear_interp_4d), intent(inout) :: me\n real(wp), dimension(:), intent(in) :: x\n real(wp), dimension(:), intent(in) :: y\n real(wp), dimension(:), intent(in) :: z\n real(wp), dimension(:), intent(in) :: q\n real(wp), dimension(:, :, :, :), intent(in) :: f\n integer, intent(out) :: istat !< `0` : no problems,\n!< `1` : `x` is not strictly increasing,\n!< `2` : `y` is not strictly increasing,\n!< `3` : `z` is not strictly increasing,\n!< `4` : `q` is not strictly increasing,\n!< `10` : `x` is not equal to size(f,1),\n!< `20` : `y` is not equal to size(f,2),\n!< `30` : `z` is not equal to size(f,3),\n!< `40` : `q` is not equal to size(f,4),\n!< `100` : cannot use linear interpolation for only one point.\n\n call me%destroy()\n\n istat = 0\n\n if(istat == 0 .and. size(x) /= size(f, 1)) istat = 10\n if(istat == 0 .and. size(y) /= size(f, 2)) istat = 20\n if(istat == 0 .and. size(z) /= size(f, 3)) istat = 30\n if(istat == 0 .and. size(q) /= size(f, 4)) istat = 40\n\n if(istat == 0) then\n call me%check_inputs(x=x, y=y, z=z, q=q, ierr=istat)\n if(istat == 0) then\n allocate(me%f(size(x), size(y), size(z), size(q))); me%f = f\n allocate(me%x(size(x))); me%x = x\n allocate(me%y(size(y))); me%y = y\n allocate(me%z(size(z))); me%z = z\n allocate(me%q(size(q))); me%q = q\n me%initialized = .true.\n endif\n endif\n\n endsubroutine initialize_4d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!<\n! Constructor for a [[linear_interp_5d]] class.\n\n pure subroutine initialize_5d(me, x, y, z, q, r, f, istat)\n\n implicit none\n\n class(linear_interp_5d), intent(inout) :: me\n real(wp), dimension(:), intent(in) :: x\n real(wp), dimension(:), intent(in) :: y\n real(wp), dimension(:), intent(in) :: z\n real(wp), dimension(:), intent(in) :: q\n real(wp), dimension(:), intent(in) :: r\n real(wp), dimension(:, :, :, :, :), intent(in) :: f\n integer, intent(out) :: istat !< `0` : no problems,\n!< `1` : `x` is not strictly increasing,\n!< `2` : `y` is not strictly increasing,\n!< `3` : `z` is not strictly increasing,\n!< `4` : `q` is not strictly increasing,\n!< `5` : `r` is not strictly increasing,\n!< `10` : `x` is not equal to size(f,1),\n!< `20` : `y` is not equal to size(f,2),\n!< `30` : `z` is not equal to size(f,3),\n!< `40` : `q` is not equal to size(f,4),\n!< `50` : `r` is not equal to size(f,5),\n!< `100` : cannot use linear interpolation for only one point.\n\n call me%destroy()\n\n istat = 0\n\n if(istat == 0 .and. size(x) /= size(f, 1)) istat = 10\n if(istat == 0 .and. size(y) /= size(f, 2)) istat = 20\n if(istat == 0 .and. size(z) /= size(f, 3)) istat = 30\n if(istat == 0 .and. size(q) /= size(f, 4)) istat = 40\n if(istat == 0 .and. size(r) /= size(f, 5)) istat = 50\n\n if(istat == 0) then\n call me%check_inputs(x=x, y=y, z=z, q=q, r=r, ierr=istat)\n if(istat == 0) then\n allocate(me%f(size(x), size(y), size(z), size(q), size(r))); me%f = f\n allocate(me%x(size(x))); me%x = x\n allocate(me%y(size(y))); me%y = y\n allocate(me%z(size(z))); me%z = z\n allocate(me%q(size(q))); me%q = q\n allocate(me%r(size(r))); me%r = r\n me%initialized = .true.\n endif\n endif\n\n endsubroutine initialize_5d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!<\n! Constructor for a [[linear_interp_6d]] class.\n\n pure subroutine initialize_6d(me, x, y, z, q, r, s, f, istat)\n\n implicit none\n\n class(linear_interp_6d), intent(inout) :: me\n real(wp), dimension(:), intent(in) :: x\n real(wp), dimension(:), intent(in) :: y\n real(wp), dimension(:), intent(in) :: z\n real(wp), dimension(:), intent(in) :: q\n real(wp), dimension(:), intent(in) :: r\n real(wp), dimension(:), intent(in) :: s\n real(wp), dimension(:, :, :, :, :, :), intent(in) :: f\n integer, intent(out) :: istat !< `0` : no problems,\n!< `1` : `x` is not strictly increasing,\n!< `2` : `y` is not strictly increasing,\n!< `3` : `z` is not strictly increasing,\n!< `4` : `q` is not strictly increasing,\n!< `5` : `r` is not strictly increasing,\n!< `6` : `s` is not strictly increasing,\n!< `10` : `x` is not equal to size(f,1),\n!< `20` : `y` is not equal to size(f,2),\n!< `30` : `z` is not equal to size(f,3),\n!< `40` : `q` is not equal to size(f,4),\n!< `50` : `r` is not equal to size(f,5),\n!< `60` : `s` is not equal to size(f,6),\n!< `100` : cannot use linear interpolation for only one point.\n\n call me%destroy()\n\n istat = 0\n\n if(istat == 0 .and. size(x) /= size(f, 1)) istat = 10\n if(istat == 0 .and. size(y) /= size(f, 2)) istat = 20\n if(istat == 0 .and. size(z) /= size(f, 3)) istat = 30\n if(istat == 0 .and. size(q) /= size(f, 4)) istat = 40\n if(istat == 0 .and. size(r) /= size(f, 5)) istat = 50\n if(istat == 0 .and. size(s) /= size(f, 6)) istat = 60\n\n if(istat == 0) then\n call me%check_inputs(x=x, y=y, z=z, q=q, r=r, s=s, ierr=istat)\n if(istat == 0) then\n allocate(me%f(size(x), size(y), size(z), size(q), size(r), size(s))); me%f = f\n allocate(me%x(size(x))); me%x = x\n allocate(me%y(size(y))); me%y = y\n allocate(me%z(size(z))); me%z = z\n allocate(me%q(size(q))); me%q = q\n allocate(me%r(size(r))); me%r = r\n allocate(me%s(size(s))); me%s = s\n me%initialized = .true.\n endif\n endif\n\n endsubroutine initialize_6d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!<\n! 1D linear interpolation routine.\n\n pure subroutine interp_1d(me, x, f, istat)\n\n implicit none\n\n class(linear_interp_1d), intent(inout) :: me\n real(wp), intent(in) :: x\n real(wp), intent(out) :: f !< Interpolated \\( f(x) \\)\n integer, intent(out), optional :: istat !< `0` : no problems,\n!< `-1` : class has not been initialized\n\n integer, dimension(2) :: ix\n real(wp) :: p1\n real(wp) :: q1\n integer :: mflag\n\n if(me%initialized) then\n\n call dintrv(me%x, x, me%ilox, ix(1), ix(2), mflag)\n\n q1 = (x - me%x(ix(1))) / (me%x(ix(2)) - me%x(ix(1)))\n p1 = one - q1\n\n f = p1 * me%f(ix(1)) + q1 * me%f(ix(2))\n if(present(istat)) istat = 0\n\n else\n\n if(present(istat)) istat = -1\n f = zero\n\n endif\n\n endsubroutine interp_1d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!<\n! 2D linear interpolation routine.\n\n pure subroutine interp_2d(me, x, y, f, istat)\n\n implicit none\n\n class(linear_interp_2d), intent(inout) :: me\n real(wp), intent(in) :: x\n real(wp), intent(in) :: y\n real(wp), intent(out) :: f !< Interpolated \\( f(x,y) \\)\n integer, intent(out), optional :: istat !< `0` : no problems,\n!< `-1` : class has not been initialized\n\n integer, dimension(2) :: ix, iy\n real(wp) :: p1, p2\n real(wp) :: q1, q2\n integer :: mflag\n real(wp) :: fx1, fx2\n\n if(me%initialized) then\n\n call dintrv(me%x, x, me%ilox, ix(1), ix(2), mflag)\n call dintrv(me%y, y, me%iloy, iy(1), iy(2), mflag)\n\n q1 = (x - me%x(ix(1))) / (me%x(ix(2)) - me%x(ix(1)))\n q2 = (y - me%y(iy(1))) / (me%y(iy(2)) - me%y(iy(1)))\n p1 = one - q1\n p2 = one - q2\n\n fx1 = p1 * me%f(ix(1), iy(1)) + q1 * me%f(ix(2), iy(1))\n fx2 = p1 * me%f(ix(1), iy(2)) + q1 * me%f(ix(2), iy(2))\n\n f = p2 * fx1 + q2 * fx2\n if(present(istat)) istat = 0\n\n else\n\n if(present(istat)) istat = -1\n f = zero\n\n endif\n\n endsubroutine interp_2d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!<\n! 3D linear interpolation routine.\n\n pure subroutine interp_3d(me, x, y, z, f, istat)\n\n implicit none\n\n class(linear_interp_3d), intent(inout) :: me\n real(wp), intent(in) :: x\n real(wp), intent(in) :: y\n real(wp), intent(in) :: z\n real(wp), intent(out) :: f !< Interpolated \\( f(x,y,z) \\)\n integer, intent(out), optional :: istat !< `0` : no problems,\n!< `-1` : class has not been initialized\n\n integer, dimension(2) :: ix, iy, iz\n real(wp) :: p1, p2, p3\n real(wp) :: q1, q2, q3\n integer :: mflag\n real(wp) :: fx11, fx21, fx12, fx22, fxy1, fxy2\n\n if(me%initialized) then\n\n call dintrv(me%x, x, me%ilox, ix(1), ix(2), mflag)\n call dintrv(me%y, y, me%iloy, iy(1), iy(2), mflag)\n call dintrv(me%z, z, me%iloz, iz(1), iz(2), mflag)\n\n q1 = (x - me%x(ix(1))) / (me%x(ix(2)) - me%x(ix(1)))\n q2 = (y - me%y(iy(1))) / (me%y(iy(2)) - me%y(iy(1)))\n q3 = (z - me%z(iz(1))) / (me%z(iz(2)) - me%z(iz(1)))\n p1 = one - q1\n p2 = one - q2\n p3 = one - q3\n\n fx11 = p1 * me%f(ix(1), iy(1), iz(1)) + q1 * me%f(ix(2), iy(1), iz(1))\n fx21 = p1 * me%f(ix(1), iy(2), iz(1)) + q1 * me%f(ix(2), iy(2), iz(1))\n fx12 = p1 * me%f(ix(1), iy(1), iz(2)) + q1 * me%f(ix(2), iy(1), iz(2))\n fx22 = p1 * me%f(ix(1), iy(2), iz(2)) + q1 * me%f(ix(2), iy(2), iz(2))\n fxy1 = p2 * fx11 + q2 * fx21\n fxy2 = p2 * fx12 + q2 * fx22\n\n f = p3 * fxy1 + q3 * fxy2\n if(present(istat)) istat = 0\n\n else\n\n if(present(istat)) istat = -1\n f = zero\n\n endif\n\n endsubroutine interp_3d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!<\n! 4D linear interpolation routine.\n\n pure subroutine interp_4d(me, x, y, z, q, f, istat)\n\n implicit none\n\n class(linear_interp_4d), intent(inout) :: me\n real(wp), intent(in) :: x\n real(wp), intent(in) :: y\n real(wp), intent(in) :: z\n real(wp), intent(in) :: q\n real(wp), intent(out) :: f !< Interpolated \\( f(x,y,z,q) \\)\n integer, intent(out), optional :: istat !< `0` : no problems,\n!< `-1` : class has not been initialized\n\n integer, dimension(2) :: ix, iy, iz, iq\n real(wp) :: p1, p2, p3, p4\n real(wp) :: q1, q2, q3, q4\n integer :: mflag\n real(wp) :: fx111, fx211, fx121, fx221, fxy11, fxy21, fxyz1, &\n fx112, fx212, fx122, fx222, fxy12, fxy22, fxyz2\n\n if(me%initialized) then\n\n call dintrv(me%x, x, me%ilox, ix(1), ix(2), mflag)\n call dintrv(me%y, y, me%iloy, iy(1), iy(2), mflag)\n call dintrv(me%z, z, me%iloz, iz(1), iz(2), mflag)\n call dintrv(me%q, q, me%iloq, iq(1), iq(2), mflag)\n\n q1 = (x - me%x(ix(1))) / (me%x(ix(2)) - me%x(ix(1)))\n q2 = (y - me%y(iy(1))) / (me%y(iy(2)) - me%y(iy(1)))\n q3 = (z - me%z(iz(1))) / (me%z(iz(2)) - me%z(iz(1)))\n q4 = (q - me%q(iq(1))) / (me%q(iq(2)) - me%q(iq(1)))\n p1 = one - q1\n p2 = one - q2\n p3 = one - q3\n p4 = one - q4\n\n fx111 = p1 * me%f(ix(1), iy(1), iz(1), iq(1)) + q1 * me%f(ix(2), iy(1), iz(1), iq(1))\n fx211 = p1 * me%f(ix(1), iy(2), iz(1), iq(1)) + q1 * me%f(ix(2), iy(2), iz(1), iq(1))\n fx121 = p1 * me%f(ix(1), iy(1), iz(2), iq(1)) + q1 * me%f(ix(2), iy(1), iz(2), iq(1))\n fx221 = p1 * me%f(ix(1), iy(2), iz(2), iq(1)) + q1 * me%f(ix(2), iy(2), iz(2), iq(1))\n fx112 = p1 * me%f(ix(1), iy(1), iz(1), iq(2)) + q1 * me%f(ix(2), iy(1), iz(1), iq(2))\n fx212 = p1 * me%f(ix(1), iy(2), iz(1), iq(2)) + q1 * me%f(ix(2), iy(2), iz(1), iq(2))\n fx122 = p1 * me%f(ix(1), iy(1), iz(2), iq(2)) + q1 * me%f(ix(2), iy(1), iz(2), iq(2))\n fx222 = p1 * me%f(ix(1), iy(2), iz(2), iq(2)) + q1 * me%f(ix(2), iy(2), iz(2), iq(2))\n\n fxy11 = p2 * fx111 + q2 * fx211\n fxy21 = p2 * fx121 + q2 * fx221\n fxy12 = p2 * fx112 + q2 * fx212\n fxy22 = p2 * fx122 + q2 * fx222\n\n fxyz1 = p3 * fxy11 + q3 * fxy21\n fxyz2 = p3 * fxy12 + q3 * fxy22\n\n f = p4 * fxyz1 + q4 * fxyz2\n if(present(istat)) istat = 0\n\n else\n\n if(present(istat)) istat = -1\n f = zero\n\n endif\n\n endsubroutine interp_4d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!<\n! 5D linear interpolation routine.\n\n pure subroutine interp_5d(me, x, y, z, q, r, f, istat)\n\n implicit none\n\n class(linear_interp_5d), intent(inout) :: me\n real(wp), intent(in) :: x\n real(wp), intent(in) :: y\n real(wp), intent(in) :: z\n real(wp), intent(in) :: q\n real(wp), intent(in) :: r\n real(wp), intent(out) :: f !< Interpolated \\( f(x,y,z,q,r) \\)\n integer, intent(out), optional :: istat !< `0` : no problems,\n!< `-1` : class has not been initialized\n\n integer, dimension(2) :: ix, iy, iz, iq, ir\n real(wp) :: p1, p2, p3, p4, p5\n real(wp) :: q1, q2, q3, q4, q5\n integer :: mflag\n real(wp) :: fx1111, fx2111, fx1211, fx2211, fx1121, fx2121, fx1221, fx2221, &\n fxy111, fxy211, fxy121, fxy221, fxyz11, fxyz21, fxyzq1, fx1112, &\n fx2112, fx1212, fx2212, fx1122, fx2122, fx1222, fx2222, fxy112, &\n fxy212, fxy122, fxy222, fxyz12, fxyz22, fxyzq2\n\n if(me%initialized) then\n\n call dintrv(me%x, x, me%ilox, ix(1), ix(2), mflag)\n call dintrv(me%y, y, me%iloy, iy(1), iy(2), mflag)\n call dintrv(me%z, z, me%iloz, iz(1), iz(2), mflag)\n call dintrv(me%q, q, me%iloq, iq(1), iq(2), mflag)\n call dintrv(me%r, r, me%ilor, ir(1), ir(2), mflag)\n\n q1 = (x - me%x(ix(1))) / (me%x(ix(2)) - me%x(ix(1)))\n q2 = (y - me%y(iy(1))) / (me%y(iy(2)) - me%y(iy(1)))\n q3 = (z - me%z(iz(1))) / (me%z(iz(2)) - me%z(iz(1)))\n q4 = (q - me%q(iq(1))) / (me%q(iq(2)) - me%q(iq(1)))\n q5 = (r - me%r(ir(1))) / (me%r(ir(2)) - me%r(ir(1)))\n p1 = one - q1\n p2 = one - q2\n p3 = one - q3\n p4 = one - q4\n p5 = one - q5\n\n fx1111 = p1 * me%f(ix(1), iy(1), iz(1), iq(1), ir(1)) + q1 * me%f(ix(2), iy(1), iz(1), iq(1), ir(1))\n fx2111 = p1 * me%f(ix(1), iy(2), iz(1), iq(1), ir(1)) + q1 * me%f(ix(2), iy(2), iz(1), iq(1), ir(1))\n fx1211 = p1 * me%f(ix(1), iy(1), iz(2), iq(1), ir(1)) + q1 * me%f(ix(2), iy(1), iz(2), iq(1), ir(1))\n fx2211 = p1 * me%f(ix(1), iy(2), iz(2), iq(1), ir(1)) + q1 * me%f(ix(2), iy(2), iz(2), iq(1), ir(1))\n fx1121 = p1 * me%f(ix(1), iy(1), iz(1), iq(2), ir(1)) + q1 * me%f(ix(2), iy(1), iz(1), iq(2), ir(1))\n fx2121 = p1 * me%f(ix(1), iy(2), iz(1), iq(2), ir(1)) + q1 * me%f(ix(2), iy(2), iz(1), iq(2), ir(1))\n fx1221 = p1 * me%f(ix(1), iy(1), iz(2), iq(2), ir(1)) + q1 * me%f(ix(2), iy(1), iz(2), iq(2), ir(1))\n fx2221 = p1 * me%f(ix(1), iy(2), iz(2), iq(2), ir(1)) + q1 * me%f(ix(2), iy(2), iz(2), iq(2), ir(1))\n fx1112 = p1 * me%f(ix(1), iy(1), iz(1), iq(1), ir(2)) + q1 * me%f(ix(2), iy(1), iz(1), iq(1), ir(2))\n fx2112 = p1 * me%f(ix(1), iy(2), iz(1), iq(1), ir(2)) + q1 * me%f(ix(2), iy(2), iz(1), iq(1), ir(2))\n fx1212 = p1 * me%f(ix(1), iy(1), iz(2), iq(1), ir(2)) + q1 * me%f(ix(2), iy(1), iz(2), iq(1), ir(2))\n fx2212 = p1 * me%f(ix(1), iy(2), iz(2), iq(1), ir(2)) + q1 * me%f(ix(2), iy(2), iz(2), iq(1), ir(2))\n fx1122 = p1 * me%f(ix(1), iy(1), iz(1), iq(2), ir(2)) + q1 * me%f(ix(2), iy(1), iz(1), iq(2), ir(2))\n fx2122 = p1 * me%f(ix(1), iy(2), iz(1), iq(2), ir(2)) + q1 * me%f(ix(2), iy(2), iz(1), iq(2), ir(2))\n fx1222 = p1 * me%f(ix(1), iy(1), iz(2), iq(2), ir(2)) + q1 * me%f(ix(2), iy(1), iz(2), iq(2), ir(2))\n fx2222 = p1 * me%f(ix(1), iy(2), iz(2), iq(2), ir(2)) + q1 * me%f(ix(2), iy(2), iz(2), iq(2), ir(2))\n\n fxy111 = p2 * fx1111 + q2 * fx2111\n fxy211 = p2 * fx1211 + q2 * fx2211\n fxy121 = p2 * fx1121 + q2 * fx2121\n fxy221 = p2 * fx1221 + q2 * fx2221\n fxy112 = p2 * fx1112 + q2 * fx2112\n fxy212 = p2 * fx1212 + q2 * fx2212\n fxy122 = p2 * fx1122 + q2 * fx2122\n fxy222 = p2 * fx1222 + q2 * fx2222\n\n fxyz11 = p3 * fxy111 + q3 * fxy211\n fxyz21 = p3 * fxy121 + q3 * fxy221\n fxyz12 = p3 * fxy112 + q3 * fxy212\n fxyz22 = p3 * fxy122 + q3 * fxy222\n\n fxyzq1 = p4 * fxyz11 + q4 * fxyz21\n fxyzq2 = p4 * fxyz12 + q4 * fxyz22\n\n f = p5 * fxyzq1 + q5 * fxyzq2\n if(present(istat)) istat = 0\n\n else\n\n if(present(istat)) istat = -1\n f = zero\n\n endif\n\n endsubroutine interp_5d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!<\n! 6D linear interpolation routine.\n\n pure subroutine interp_6d(me, x, y, z, q, r, s, f, istat)\n\n implicit none\n\n class(linear_interp_6d), intent(inout) :: me\n real(wp), intent(in) :: x\n real(wp), intent(in) :: y\n real(wp), intent(in) :: z\n real(wp), intent(in) :: q\n real(wp), intent(in) :: r\n real(wp), intent(in) :: s\n real(wp), intent(out) :: f !< Interpolated \\( f(x,y,z,q,r,s) \\)\n integer, intent(out), optional :: istat !< `0` : no problems,\n!< `-1` : class has not been initialized\n\n integer, dimension(2) :: ix, iy, iz, iq, ir, is\n real(wp) :: p1, p2, p3, p4, p5, p6\n real(wp) :: q1, q2, q3, q4, q5, q6\n integer :: mflag\n real(wp) :: fx11111, fx21111, fx12111, fx22111, fx11211, fx21211, fx12211, &\n fx22211, fxy1111, fxy2111, fxy1211, fxy2211, fxyz111, fxyz211, &\n fxyzq11, fx11121, fx21121, fx12121, fx22121, fx11221, fx21221, &\n fx12221, fx22221, fxy1121, fxy2121, fxy1221, fxy2221, fxyz121, &\n fxyz221, fxyzq21, fx11112, fx21112, fx12112, fx22112, fx11212, &\n fx21212, fx12212, fx22212, fxy1112, fxy2112, fxy1212, fxy2212, &\n fxyz112, fxyz212, fxyzq12, fx11122, fx21122, fx12122, fx22122, &\n fx11222, fx21222, fx12222, fx22222, fxy1122, fxy2122, fxy1222, &\n fxy2222, fxyz122, fxyz222, fxyzq22, fxyzqr1, fxyzqr2\n\n if(me%initialized) then\n\n call dintrv(me%x, x, me%ilox, ix(1), ix(2), mflag)\n call dintrv(me%y, y, me%iloy, iy(1), iy(2), mflag)\n call dintrv(me%z, z, me%iloz, iz(1), iz(2), mflag)\n call dintrv(me%q, q, me%iloq, iq(1), iq(2), mflag)\n call dintrv(me%r, r, me%ilor, ir(1), ir(2), mflag)\n call dintrv(me%s, s, me%ilos, is(1), is(2), mflag)\n\n q1 = (x - me%x(ix(1))) / (me%x(ix(2)) - me%x(ix(1)))\n q2 = (y - me%y(iy(1))) / (me%y(iy(2)) - me%y(iy(1)))\n q3 = (z - me%z(iz(1))) / (me%z(iz(2)) - me%z(iz(1)))\n q4 = (q - me%q(iq(1))) / (me%q(iq(2)) - me%q(iq(1)))\n q5 = (r - me%r(ir(1))) / (me%r(ir(2)) - me%r(ir(1)))\n q6 = (s - me%s(is(1))) / (me%s(is(2)) - me%s(is(1)))\n p1 = one - q1\n p2 = one - q2\n p3 = one - q3\n p4 = one - q4\n p5 = one - q5\n p6 = one - q6\n\n fx11111 = p1 * me%f(ix(1), iy(1), iz(1), iq(1), ir(1), is(1)) + q1 * me%f(ix(2), iy(1), iz(1), iq(1), ir(1), is(1))\n fx21111 = p1 * me%f(ix(1), iy(2), iz(1), iq(1), ir(1), is(1)) + q1 * me%f(ix(2), iy(2), iz(1), iq(1), ir(1), is(1))\n fx12111 = p1 * me%f(ix(1), iy(1), iz(2), iq(1), ir(1), is(1)) + q1 * me%f(ix(2), iy(1), iz(2), iq(1), ir(1), is(1))\n fx22111 = p1 * me%f(ix(1), iy(2), iz(2), iq(1), ir(1), is(1)) + q1 * me%f(ix(2), iy(2), iz(2), iq(1), ir(1), is(1))\n fx11211 = p1 * me%f(ix(1), iy(1), iz(1), iq(2), ir(1), is(1)) + q1 * me%f(ix(2), iy(1), iz(1), iq(2), ir(1), is(1))\n fx21211 = p1 * me%f(ix(1), iy(2), iz(1), iq(2), ir(1), is(1)) + q1 * me%f(ix(2), iy(2), iz(1), iq(2), ir(1), is(1))\n fx12211 = p1 * me%f(ix(1), iy(1), iz(2), iq(2), ir(1), is(1)) + q1 * me%f(ix(2), iy(1), iz(2), iq(2), ir(1), is(1))\n fx22211 = p1 * me%f(ix(1), iy(2), iz(2), iq(2), ir(1), is(1)) + q1 * me%f(ix(2), iy(2), iz(2), iq(2), ir(1), is(1))\n fx11121 = p1 * me%f(ix(1), iy(1), iz(1), iq(1), ir(2), is(1)) + q1 * me%f(ix(2), iy(1), iz(1), iq(1), ir(2), is(1))\n fx21121 = p1 * me%f(ix(1), iy(2), iz(1), iq(1), ir(2), is(1)) + q1 * me%f(ix(2), iy(2), iz(1), iq(1), ir(2), is(1))\n fx12121 = p1 * me%f(ix(1), iy(1), iz(2), iq(1), ir(2), is(1)) + q1 * me%f(ix(2), iy(1), iz(2), iq(1), ir(2), is(1))\n fx22121 = p1 * me%f(ix(1), iy(2), iz(2), iq(1), ir(2), is(1)) + q1 * me%f(ix(2), iy(2), iz(2), iq(1), ir(2), is(1))\n fx11221 = p1 * me%f(ix(1), iy(1), iz(1), iq(2), ir(2), is(1)) + q1 * me%f(ix(2), iy(1), iz(1), iq(2), ir(2), is(1))\n fx21221 = p1 * me%f(ix(1), iy(2), iz(1), iq(2), ir(2), is(1)) + q1 * me%f(ix(2), iy(2), iz(1), iq(2), ir(2), is(1))\n fx12221 = p1 * me%f(ix(1), iy(1), iz(2), iq(2), ir(2), is(1)) + q1 * me%f(ix(2), iy(1), iz(2), iq(2), ir(2), is(1))\n fx22221 = p1 * me%f(ix(1), iy(2), iz(2), iq(2), ir(2), is(1)) + q1 * me%f(ix(2), iy(2), iz(2), iq(2), ir(2), is(1))\n fx11112 = p1 * me%f(ix(1), iy(1), iz(1), iq(1), ir(1), is(2)) + q1 * me%f(ix(2), iy(1), iz(1), iq(1), ir(1), is(2))\n fx21112 = p1 * me%f(ix(1), iy(2), iz(1), iq(1), ir(1), is(2)) + q1 * me%f(ix(2), iy(2), iz(1), iq(1), ir(1), is(2))\n fx12112 = p1 * me%f(ix(1), iy(1), iz(2), iq(1), ir(1), is(2)) + q1 * me%f(ix(2), iy(1), iz(2), iq(1), ir(1), is(2))\n fx22112 = p1 * me%f(ix(1), iy(2), iz(2), iq(1), ir(1), is(2)) + q1 * me%f(ix(2), iy(2), iz(2), iq(1), ir(1), is(2))\n fx11212 = p1 * me%f(ix(1), iy(1), iz(1), iq(2), ir(1), is(2)) + q1 * me%f(ix(2), iy(1), iz(1), iq(2), ir(1), is(2))\n fx21212 = p1 * me%f(ix(1), iy(2), iz(1), iq(2), ir(1), is(2)) + q1 * me%f(ix(2), iy(2), iz(1), iq(2), ir(1), is(2))\n fx12212 = p1 * me%f(ix(1), iy(1), iz(2), iq(2), ir(1), is(2)) + q1 * me%f(ix(2), iy(1), iz(2), iq(2), ir(1), is(2))\n fx22212 = p1 * me%f(ix(1), iy(2), iz(2), iq(2), ir(1), is(2)) + q1 * me%f(ix(2), iy(2), iz(2), iq(2), ir(1), is(2))\n fx11122 = p1 * me%f(ix(1), iy(1), iz(1), iq(1), ir(2), is(2)) + q1 * me%f(ix(2), iy(1), iz(1), iq(1), ir(2), is(2))\n fx21122 = p1 * me%f(ix(1), iy(2), iz(1), iq(1), ir(2), is(2)) + q1 * me%f(ix(2), iy(2), iz(1), iq(1), ir(2), is(2))\n fx12122 = p1 * me%f(ix(1), iy(1), iz(2), iq(1), ir(2), is(2)) + q1 * me%f(ix(2), iy(1), iz(2), iq(1), ir(2), is(2))\n fx22122 = p1 * me%f(ix(1), iy(2), iz(2), iq(1), ir(2), is(2)) + q1 * me%f(ix(2), iy(2), iz(2), iq(1), ir(2), is(2))\n fx11222 = p1 * me%f(ix(1), iy(1), iz(1), iq(2), ir(2), is(2)) + q1 * me%f(ix(2), iy(1), iz(1), iq(2), ir(2), is(2))\n fx21222 = p1 * me%f(ix(1), iy(2), iz(1), iq(2), ir(2), is(2)) + q1 * me%f(ix(2), iy(2), iz(1), iq(2), ir(2), is(2))\n fx12222 = p1 * me%f(ix(1), iy(1), iz(2), iq(2), ir(2), is(2)) + q1 * me%f(ix(2), iy(1), iz(2), iq(2), ir(2), is(2))\n fx22222 = p1 * me%f(ix(1), iy(2), iz(2), iq(2), ir(2), is(2)) + q1 * me%f(ix(2), iy(2), iz(2), iq(2), ir(2), is(2))\n\n fxy1111 = p2 * fx11111 + q2 * fx21111\n fxy2111 = p2 * fx12111 + q2 * fx22111\n fxy1211 = p2 * fx11211 + q2 * fx21211\n fxy2211 = p2 * fx12211 + q2 * fx22211\n fxy1121 = p2 * fx11121 + q2 * fx21121\n fxy2121 = p2 * fx12121 + q2 * fx22121\n fxy1221 = p2 * fx11221 + q2 * fx21221\n fxy2221 = p2 * fx12221 + q2 * fx22221\n fxy1112 = p2 * fx11112 + q2 * fx21112\n fxy2112 = p2 * fx12112 + q2 * fx22112\n fxy1212 = p2 * fx11212 + q2 * fx21212\n fxy2212 = p2 * fx12212 + q2 * fx22212\n fxy1122 = p2 * fx11122 + q2 * fx21122\n fxy2122 = p2 * fx12122 + q2 * fx22122\n fxy1222 = p2 * fx11222 + q2 * fx21222\n fxy2222 = p2 * fx12222 + q2 * fx22222\n\n fxyz111 = p3 * fxy1111 + q3 * fxy2111\n fxyz211 = p3 * fxy1211 + q3 * fxy2211\n fxyz121 = p3 * fxy1121 + q3 * fxy2121\n fxyz221 = p3 * fxy1221 + q3 * fxy2221\n fxyz112 = p3 * fxy1112 + q3 * fxy2112\n fxyz212 = p3 * fxy1212 + q3 * fxy2212\n fxyz122 = p3 * fxy1122 + q3 * fxy2122\n fxyz222 = p3 * fxy1222 + q3 * fxy2222\n\n fxyzq11 = p4 * fxyz111 + q4 * fxyz211\n fxyzq21 = p4 * fxyz121 + q4 * fxyz221\n fxyzq12 = p4 * fxyz112 + q4 * fxyz212\n fxyzq22 = p4 * fxyz122 + q4 * fxyz222\n\n fxyzqr1 = p5 * fxyzq11 + q5 * fxyzq21\n fxyzqr2 = p5 * fxyzq12 + q5 * fxyzq22\n\n f = p6 * fxyzqr1 + q6 * fxyzqr2\n if(present(istat)) istat = 0\n\n else\n\n if(present(istat)) istat = -1\n f = zero\n\n endif\n\n endsubroutine interp_6d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!<\n! Returns the indices in `xt` that bound `x`, to use for interpolation.\n! If outside the range, then the indices are returned that can\n! be used for extrapolation.\n! Precisely,\n!\n!```fortran\n! if x < xt(1) then ileft=1, iright=2, mflag=-1\n! if xt(i) <= x < xt(i+1) then ileft=i, iright=i+1, mflag=0\n! if xt(n) <= x then ileft=n-1, iright=n, mflag=1\n!```\n!\n!### History\n!\n! * interv written by carl de boor [5]\n! * dintrv author: amos, d. e., (snla) : date written 800901\n! * revision date 820801\n! * Jacob Williams, 2/24/2015 : updated to free-form Fortran.\n! * Jacob Williams, 2/17/2016 : additional refactoring (eliminated GOTOs).\n! * Jacob Williams, 2/22/2016 : modified bspline-fortran `dintrv` routine for\n! linear interpolation/extrapolation use.\n! * Jacob Williams, 10/9/2019 : added optional `inearest` output.\n\n pure subroutine dintrv(xt, x, ilo, ileft, iright, mflag, inearest)\n\n implicit none\n\n real(wp), dimension(:), intent(in) :: xt !< a knot or break point vector\n real(wp), intent(in) :: x !< argument\n integer, intent(inout) :: ilo !< an initialization parameter which must be set\n!< to 1 the first time the array `xt` is\n!< processed by dintrv. `ilo` contains information for\n!< efficient processing after the initial call and `ilo`\n!< must not be changed by the user. each dimension\n!< requires a distinct `ilo` parameter.\n integer, intent(out) :: ileft !< left index\n integer, intent(out) :: iright !< right index\n integer, intent(out) :: mflag !< signals when `x` lies out of bounds\n integer, intent(out), optional :: inearest !< nearest index\n\n integer :: ihi, istep, imid, n\n\n n = size(xt)\n\n if(n == 1) then\n! this is only allowed for nearest interpolation\n if(present(inearest)) then\n inearest = 1\n return\n endif\n endif\n\n ihi = ilo + 1\n if(ihi >= n) then\n if(x >= xt(n)) then\n mflag = 1\n ileft = n - 1\n iright = n\n if(present(inearest)) inearest = n\n return\n endif\n if(n <= 1) then\n mflag = -1\n ileft = 1\n iright = 2\n if(present(inearest)) inearest = 1\n return\n endif\n ilo = n - 1\n ihi = n\n endif\n\n if(x >= xt(ihi)) then\n\n! now x >= xt(ilo). find upper bound\n istep = 1\n do\n ilo = ihi\n ihi = ilo + istep\n if(ihi >= n) then\n if(x >= xt(n)) then\n mflag = 1\n ileft = n - 1\n iright = n\n if(present(inearest)) inearest = n\n return\n endif\n ihi = n\n elseif(x >= xt(ihi)) then\n istep = istep * 2\n cycle\n endif\n exit\n enddo\n\n else\n\n if(x >= xt(ilo)) then\n mflag = 0\n ileft = ilo\n iright = ilo + 1\n if(present(inearest)) then\n if(abs(x - xt(ileft)) <= abs(x - xt(iright))) then\n inearest = ileft\n else\n inearest = iright\n endif\n endif\n return\n endif\n! now x <= xt(ihi). find lower bound\n istep = 1\n do\n ihi = ilo\n ilo = ihi - istep\n if(ilo <= 1) then\n ilo = 1\n if(x < xt(1)) then\n mflag = -1\n ileft = 1\n iright = 2\n if(present(inearest)) inearest = 1\n return\n endif\n elseif(x < xt(ilo)) then\n istep = istep * 2\n cycle\n endif\n exit\n enddo\n\n endif\n\n! now xt(ilo) <= x < xt(ihi). narrow the interval\n do\n imid = (ilo + ihi) / 2\n if(imid == ilo) then\n mflag = 0\n ileft = ilo\n iright = ilo + 1\n if(present(inearest)) then\n if(abs(x - xt(ileft)) <= abs(x - xt(iright))) then\n inearest = ileft\n else\n inearest = iright\n endif\n endif\n return\n endif\n! note. it is assumed that imid = ilo in case ihi = ilo+1\n if(x < xt(imid)) then\n ihi = imid\n else\n ilo = imid\n endif\n enddo\n\n endsubroutine dintrv\n!*****************************************************************************************\n\n!*****************************************************************************************\n!<\n! 1D nearest neighbor interpolation routine.\n\n pure subroutine nearest_1d(me, x, f, istat)\n\n implicit none\n\n class(nearest_interp_1d), intent(inout) :: me\n real(wp), intent(in) :: x\n real(wp), intent(out) :: f !< Nearest \\( f(x) \\)\n integer, intent(out), optional :: istat !< `0` : no problems,\n!< `-1` : class has not been initialized\n\n integer :: mflag\n integer, dimension(2) :: ix\n integer :: i\n\n if(me%initialized) then\n\n call dintrv(me%x, x, me%ilox, ix(1), ix(2), mflag, i)\n\n f = me%f(i)\n if(present(istat)) istat = 0\n\n else\n\n if(present(istat)) istat = -1\n f = zero\n\n endif\n\n endsubroutine nearest_1d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!<\n! 2D nearest neighbor interpolation routine.\n\n pure subroutine nearest_2d(me, x, y, f, istat)\n\n implicit none\n\n class(nearest_interp_2d), intent(inout) :: me\n real(wp), intent(in) :: x\n real(wp), intent(in) :: y\n real(wp), intent(out) :: f !< Nearest \\( f(x,y) \\)\n integer, intent(out), optional :: istat !< `0` : no problems,\n!< `-1` : class has not been initialized\n\n integer :: mflag\n integer, dimension(2) :: ix, iy\n integer :: i, j\n\n if(me%initialized) then\n\n call dintrv(me%x, x, me%ilox, ix(1), ix(2), mflag, i)\n call dintrv(me%y, y, me%iloy, iy(1), iy(2), mflag, j)\n\n f = me%f(i, j)\n if(present(istat)) istat = 0\n\n else\n\n if(present(istat)) istat = -1\n f = zero\n\n endif\n\n endsubroutine nearest_2d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!<\n! 3D nearest neighbor interpolation routine.\n\n pure subroutine nearest_3d(me, x, y, z, f, istat)\n\n implicit none\n\n class(nearest_interp_3d), intent(inout) :: me\n real(wp), intent(in) :: x\n real(wp), intent(in) :: y\n real(wp), intent(in) :: z\n real(wp), intent(out) :: f !< Nearest \\( f(x,y,z) \\)\n integer, intent(out), optional :: istat !< `0` : no problems,\n!< `-1` : class has not been initialized\n\n integer :: mflag\n integer, dimension(2) :: ix, iy, iz\n integer :: i, j, k\n\n if(me%initialized) then\n\n call dintrv(me%x, x, me%ilox, ix(1), ix(2), mflag, i)\n call dintrv(me%y, y, me%iloy, iy(1), iy(2), mflag, j)\n call dintrv(me%z, z, me%iloz, iz(1), iz(2), mflag, k)\n\n f = me%f(i, j, k)\n if(present(istat)) istat = 0\n\n else\n\n if(present(istat)) istat = -1\n f = zero\n\n endif\n\n endsubroutine nearest_3d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!<\n! 4D nearest neighbor interpolation routine.\n\n pure subroutine nearest_4d(me, x, y, z, q, f, istat)\n\n implicit none\n\n class(nearest_interp_4d), intent(inout) :: me\n real(wp), intent(in) :: x\n real(wp), intent(in) :: y\n real(wp), intent(in) :: z\n real(wp), intent(in) :: q\n real(wp), intent(out) :: f !< Nearest \\( f(x,y,z,q) \\)\n integer, intent(out), optional :: istat !< `0` : no problems,\n!< `-1` : class has not been initialized\n\n integer :: mflag\n integer, dimension(2) :: ix, iy, iz, iq\n integer :: i, j, k, l\n\n if(me%initialized) then\n\n call dintrv(me%x, x, me%ilox, ix(1), ix(2), mflag, i)\n call dintrv(me%y, y, me%iloy, iy(1), iy(2), mflag, j)\n call dintrv(me%z, z, me%iloz, iz(1), iz(2), mflag, k)\n call dintrv(me%q, q, me%iloq, iq(1), iq(2), mflag, l)\n\n f = me%f(i, j, k, l)\n if(present(istat)) istat = 0\n\n else\n\n if(present(istat)) istat = -1\n f = zero\n\n endif\n\n endsubroutine nearest_4d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!<\n! 5D nearest neighbor interpolation routine.\n\n pure subroutine nearest_5d(me, x, y, z, q, r, f, istat)\n\n implicit none\n\n class(nearest_interp_5d), intent(inout) :: me\n real(wp), intent(in) :: x\n real(wp), intent(in) :: y\n real(wp), intent(in) :: z\n real(wp), intent(in) :: q\n real(wp), intent(in) :: r\n real(wp), intent(out) :: f !< Nearest \\( f(x,y,z,q,r) \\)\n integer, intent(out), optional :: istat !< `0` : no problems,\n!< `-1` : class has not been initialized\n\n integer :: mflag\n integer, dimension(2) :: ix, iy, iz, iq, ir\n integer :: i, j, k, l, m\n\n if(me%initialized) then\n\n call dintrv(me%x, x, me%ilox, ix(1), ix(2), mflag, i)\n call dintrv(me%y, y, me%iloy, iy(1), iy(2), mflag, j)\n call dintrv(me%z, z, me%iloz, iz(1), iz(2), mflag, k)\n call dintrv(me%q, q, me%iloq, iq(1), iq(2), mflag, l)\n call dintrv(me%r, r, me%ilor, ir(1), ir(2), mflag, m)\n\n f = me%f(i, j, k, l, m)\n if(present(istat)) istat = 0\n\n else\n\n if(present(istat)) istat = -1\n f = zero\n\n endif\n\n endsubroutine nearest_5d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!<\n! 6D nearest neighbor interpolation routine.\n\n pure subroutine nearest_6d(me, x, y, z, q, r, s, f, istat)\n\n implicit none\n\n class(nearest_interp_6d), intent(inout) :: me\n real(wp), intent(in) :: x\n real(wp), intent(in) :: y\n real(wp), intent(in) :: z\n real(wp), intent(in) :: q\n real(wp), intent(in) :: r\n real(wp), intent(in) :: s\n real(wp), intent(out) :: f !< Nearest \\( f(x,y,z,q,r,s) \\)\n integer, intent(out), optional :: istat !< `0` : no problems,\n!< `-1` : class has not been initialized\n\n integer :: mflag\n integer, dimension(2) :: ix, iy, iz, iq, ir, is\n integer :: i, j, k, l, m, n\n\n if(me%initialized) then\n\n call dintrv(me%x, x, me%ilox, ix(1), ix(2), mflag, i)\n call dintrv(me%y, y, me%iloy, iy(1), iy(2), mflag, j)\n call dintrv(me%z, z, me%iloz, iz(1), iz(2), mflag, k)\n call dintrv(me%q, q, me%iloq, iq(1), iq(2), mflag, l)\n call dintrv(me%r, r, me%ilor, ir(1), ir(2), mflag, m)\n call dintrv(me%s, s, me%ilos, is(1), is(2), mflag, n)\n\n f = me%f(i, j, k, l, m, n)\n if(present(istat)) istat = 0\n\n else\n\n if(present(istat)) istat = -1\n f = zero\n\n endif\n\n endsubroutine nearest_6d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!<\n! Returns true if all the elements in the array `x` are unique.\n! Note: the array must be sorted.\n!\n!@note This routine is not currently used in the module.\n\n pure function check_if_unique(x) result(unique)\n\n implicit none\n\n real(wp), dimension(:), intent(in) :: x !< a sorted array\n logical :: unique !< true if all elements are unique\n\n integer :: i !< counter\n\n unique = .true. ! initialize\n\n do i = 1, size(x) - 1\n if(x(i) == x(i + 1)) then\n unique = .false.\n exit\n endif\n enddo\n\n endfunction check_if_unique\n!*****************************************************************************************\n\n!*****************************************************************************************\n!<\n! Sorts an array `dx` in increasing order,\n! carrying along an additional array `dy`.\n!\n! Uses a non-recursive quicksort, reverting to insertion sort on arrays of\n! size <= 20. Dimension of `stack` limits array size to about \\(2^32\\).\n!\n!### License\n! * [Original LAPACK license](http://www.netlib.org/lapack/LICENSE.txt)\n!\n!### History\n! * Based on the LAPACK routine [DLASRT](http://www.netlib.org/lapack/explore-html/df/ddf/dlasrt_8f.html).\n! * Extensively modified by Jacob Williams, Feb. 2016. Converted to\n! modern Fortran and added the `dy` output. Removed the descending sort option.\n!\n!@note This routine is not currently used in the module.\n\n pure subroutine sort(dx, dy)\n\n implicit none\n\n real(wp), dimension(:), intent(inout) :: dx !< on entry, the array to be sorted.\n!< on exit, `dx` has been sorted into increasing order\n!< (`dx(1) <= ... <= dx(n)`) or into decreasing order\n!< (`dx(1) >= ... >= dx(n)`), depending on `id`.\n real(wp), dimension(:), intent(inout) :: dy !< array carried along with `dx`.\n\n integer, parameter :: select = 20 !< max size for using insertion sort.\n\n integer :: endd, i, j, n, start, stkpnt\n real(wp) :: d1, d2, d3, dmnmx, dmnmy, tmp\n integer, dimension(2, 32) :: stack\n\n! number of elements to sort:\n n = size(dx)\n\n if(n > 1) then\n\n stkpnt = 1\n stack(1, 1) = 1\n stack(2, 1) = n\n\n do\n\n start = stack(1, stkpnt)\n endd = stack(2, stkpnt)\n stkpnt = stkpnt - 1\n if(endd - start <= select .and. endd > start) then\n\n! do insertion sort on dx( start:endd )\n insertion: do i = start + 1, endd\n do j = i, start + 1, -1\n if(dx(j) >= dx(j - 1)) cycle insertion\n dmnmx = dx(j)\n dx(j) = dx(j - 1)\n dx(j - 1) = dmnmx\n dmnmy = dy(j)\n dy(j) = dy(j - 1)\n dy(j - 1) = dmnmy\n enddo\n enddo insertion\n\n elseif(endd - start > select) then\n\n! partition dx( start:endd ) and stack parts, largest one first\n! choose partition entry as median of 3\n\n d1 = dx(start)\n d2 = dx(endd)\n i = (start + endd) / 2\n d3 = dx(i)\n if(d1 < d2) then\n if(d3 < d1) then\n dmnmx = d1\n elseif(d3 < d2) then\n dmnmx = d3\n else\n dmnmx = d2\n endif\n elseif(d3 < d2) then\n dmnmx = d2\n elseif(d3 < d1) then\n dmnmx = d3\n else\n dmnmx = d1\n endif\n\n i = start - 1\n j = endd + 1\n do\n do\n j = j - 1\n if(dx(j) <= dmnmx) exit\n enddo\n do\n i = i + 1\n if(dx(i) >= dmnmx) exit\n enddo\n if(i < j) then\n tmp = dx(i)\n dx(i) = dx(j)\n dx(j) = tmp\n tmp = dy(i)\n dy(i) = dy(j)\n dy(j) = tmp\n else\n exit\n endif\n enddo\n if(j - start > endd - j - 1) then\n stkpnt = stkpnt + 1\n stack(1, stkpnt) = start\n stack(2, stkpnt) = j\n stkpnt = stkpnt + 1\n stack(1, stkpnt) = j + 1\n stack(2, stkpnt) = endd\n else\n stkpnt = stkpnt + 1\n stack(1, stkpnt) = j + 1\n stack(2, stkpnt) = endd\n stkpnt = stkpnt + 1\n stack(1, stkpnt) = start\n stack(2, stkpnt) = j\n endif\n\n endif\n\n if(stkpnt <= 0) exit\n\n enddo\n\n endif\n\n endsubroutine sort\n!*****************************************************************************************\n\n!*****************************************************************************************\n!<\n! Check the validity of the inputs to the initialize routines.\n! Prints warning message if there is an error,\n! and also sets `ierr` (/=0 if there were any errors).\n!\n! Supports up to 6D: x,y,z,q,r,s\n!\n!# History\n! * Jacob Williams, 2/24/2015 : Created this routine.\n! * Jacob Williams, 2/23/2016 : modified for linear interp module.\n\n pure subroutine check_inputs(me, x, y, z, q, r, s, ierr)\n\n implicit none\n\n class(linear_interp_class), intent(in) :: me\n real(wp), dimension(:), intent(in), optional :: x !< `x` abscissa vector\n real(wp), dimension(:), intent(in), optional :: y !< `y` abscissa vector\n real(wp), dimension(:), intent(in), optional :: z !< `z` abscissa vector\n real(wp), dimension(:), intent(in), optional :: q !< `q` abscissa vector\n real(wp), dimension(:), intent(in), optional :: r !< `r` abscissa vector\n real(wp), dimension(:), intent(in), optional :: s !< `s` abscissa vector\n integer, intent(out) :: ierr !< `0` : no problems,\n!< `1` : `x` is not strictly increasing,\n!< `2` : `y` is not strictly increasing,\n!< `3` : `z` is not strictly increasing,\n!< `4` : `q` is not strictly increasing,\n!< `5` : `r` is not strictly increasing,\n!< `6` : `s` is not strictly increasing,\n!< `100` : cannot use linear interpolation for only one point.\n\n ierr = 0 ! initialize\n\n if(present(x)) call check(x, 1, ierr); if(ierr /= 0) return\n if(present(y)) call check(y, 2, ierr); if(ierr /= 0) return\n if(present(z)) call check(z, 3, ierr); if(ierr /= 0) return\n if(present(q)) call check(q, 4, ierr); if(ierr /= 0) return\n if(present(r)) call check(r, 5, ierr); if(ierr /= 0) return\n if(present(s)) call check(s, 6, ierr); if(ierr /= 0) return\n\n if(ierr == 0) then\n select type(me)\n class is(nearest_interp_1d)\n class is(nearest_interp_2d)\n class is(nearest_interp_3d)\n class is(nearest_interp_4d)\n class is(nearest_interp_5d)\n class is(nearest_interp_6d)\n class default\n! need at least two points for linear interpolation:\n if(size(x) == 1) ierr = 100\n endselect\n endif\n\n contains\n!*****************************************************************************************\n\n pure subroutine check(v, error_code, ierr)\n\n implicit none\n\n real(wp), dimension(:), intent(in) :: v !< abcissae vector\n integer, intent(in) :: error_code !< error code for check\n integer, intent(inout) :: ierr !< will be set to `error_code` if there is a problem\n\n integer :: i !< counter\n integer :: n !< size of the input `v` array\n\n n = size(v)\n do i = 2, n\n if(v(i) <= v(i - 1)) then\n ierr = error_code\n exit\n endif\n enddo\n\n endsubroutine check\n\n endsubroutine check_inputs\n!*****************************************************************************************\n\n!*****************************************************************************************\nendmodule linear_interpolation_module\n!*****************************************************************************************\n", "meta": {"hexsha": "0427d0f5eaf230cfddbcc7c2095021748e41545c", "size": 63438, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/third_party/finterp/linear_interpolation_module.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/third_party/finterp/linear_interpolation_module.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/third_party/finterp/linear_interpolation_module.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": 34.9328193833, "max_line_length": 121, "alphanum_fraction": 0.4882404868, "num_tokens": 20340, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391624034103, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.6869645350058954}} {"text": "program test_fftw\nuse iso_c_binding, only: c_ptr\nuse types, only: dp\nuse constants, only: i_\nuse fftw, only: fftw_plan_dft_1d, fftw_plan_dft_3d, FFTW_FORWARD, &\n FFTW_ESTIMATE, fftw_execute_dft, fftw_destroy_plan, &\n FFTW_MEASURE, alloc1d, alloc3d, free\nimplicit none\n\ntype(c_ptr) :: plan\ncomplex(dp), dimension(4, 8, 16) :: y3, ydft3\ninteger :: n\ncomplex(dp), pointer :: x(:), xdft(:), x3(:, :, :), xdft3(:, :, :)\nreal(dp) :: t1, t2, t3\n\n! This works, but is slow due to y,ydft not being aligned to exploit SIMD\n! The dimensions (4, 8, 16) must be reversed:\nplan = fftw_plan_dft_3d(16, 8, 4, y3, ydft3, FFTW_FORWARD, FFTW_ESTIMATE)\ny3 = 0\ncall fftw_execute_dft(plan, y3, ydft3)\ncall fftw_destroy_plan(plan)\n\nn = 1024**2\n\n! This is fast\nprint *, \"1D FFT of size n=\", n, \"with FFTW allocation\"\nx => alloc1d(n)\nxdft => alloc1d(n)\nx = 0\ncall cpu_time(t1)\n!plan = fftw_plan_dft_1d(n, x, xdft, FFTW_FORWARD, FFTW_ESTIMATE)\nplan = fftw_plan_dft_1d(n, x, xdft, FFTW_FORWARD, FFTW_MEASURE)\ncall cpu_time(t2)\ncall fftw_execute_dft(plan, x, xdft)\ncall cpu_time(t3)\nprint *, \"Total time:\", (t3-t1)*1000, \"ms\"\nprint *, \"init: \", (t2-t1)*1000, \"ms\"\nprint *, \"calc: \", (t3-t2)*1000, \"ms\"\ncall fftw_destroy_plan(plan)\ncall free(x)\ncall free(xdft)\n\nn = 256\n\n! This is fast\nprint *, \"1D FFT of size n=\", n, \"^3 with FFTW allocation\"\nx3 => alloc3d(n, n, n)\nxdft3 => alloc3d(n, n, n)\nx3 = 0\ncall cpu_time(t1)\nplan = fftw_plan_dft_3d(n, n, n, x3, xdft3, FFTW_FORWARD, FFTW_MEASURE)\ncall cpu_time(t2)\ncall fftw_execute_dft(plan, x3, xdft3)\ncall cpu_time(t3)\nprint *, \"Total time:\", (t3-t1)*1000, \"ms\"\nprint *, \"init: \", (t2-t1)*1000, \"ms\"\nprint *, \"calc: \", (t3-t2)*1000, \"ms\"\ncall fftw_destroy_plan(plan)\ncall free(x3)\ncall free(xdft3)\nend program\n", "meta": {"hexsha": "9ed1afc602ebc07638b288eec7fba1e60ee724a2", "size": 1755, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/test_fftw.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/tests/test_fftw.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/tests/test_fftw.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": 28.3064516129, "max_line_length": 73, "alphanum_fraction": 0.6786324786, "num_tokens": 678, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391595913457, "lm_q2_score": 0.7956580927949807, "lm_q1q2_score": 0.6869645105397159}} {"text": "! ============================================================================\n! Sets aux arrays\n! aux(:,1) = Bathymetry\n! aux(:,2) = Wind field\n! aux(:,3) = Initial steady state, top layer depth, h_1 = eta_1 - eta_2\n! aux(:,4) = Initial steady state, bottom layer depth, h_2 = eta_2 - b\n! ============================================================================\nsubroutine setaux(maxmx,mbc,mx,xlower,dx,maux,aux)\n \n use parameters_module\n \n implicit none\n \n ! Input parameters\n integer, intent(in) :: maxmx,mbc,mx,maux\n double precision, intent(in) :: xlower,dx\n \n ! Auxillary array \n double precision, intent(inout) :: aux(1-mbc:maxmx+mbc, maux)\n \n ! Local\n integer, parameter :: out_unit = 13\n integer :: i, ios\n double precision :: x\n \n do i=1-mbc,mx+mbc\n x = xlower+(i-0.5)*dx\n ! Jump in bathymetry\n if (bathy_type == 1) then\n if (x < bathy_location) then\n aux(i,1) = bathy_left\n else\n aux(i,1) = bathy_right\n endif\n ! Simple shelf\n else if (bathy_type == 2) then\n if (x < x0) then\n aux(i,1) = basin_depth\n else if (x0 <= x .and. x < x1) then\n aux(i,1) = shelf_slope * (x-x0) + basin_depth\n else if (x1 <= x) then\n aux(i,1) = shelf_depth\n endif\n endif\n \n ! Set initial states\n if (x < init_location) then\n if (eta_left(2) > aux(i,1)) then\n aux(i,3) = eta_left(1) - eta_left(2)\n aux(i,4) = eta_left(2) - aux(i,1)\n else\n aux(i,3) = eta_left(1) - aux(i,1)\n endif\n else\n if (eta_right(2) > aux(i,1)) then\n aux(i,3) = eta_right(1) - eta_right(2)\n aux(i,4) = eta_right(2) - aux(i,1)\n else\n aux(i,3) = eta_right(1) - aux(i,1)\n endif\n endif\n enddo\n \n \n \n ! Calculate initial wind field\n call set_wind(maxmx,mbc,mx,xlower,dx,0.d0,aux(:,2))\n \n ! Write out auxillary array\n print *,\"Outputting bathymetry to 'fort.aux' file.\"\n open(unit=out_unit, file='fort.aux', iostat=ios, action=\"write\")\n if ( ios /= 0 ) stop \"Error opening file name\"\n \n do i=1,mx\n write(unit=out_unit, fmt=\"(d16.8)\") aux(i,1)\n enddo\n \n close(out_unit)\n \nend subroutine setaux\n", "meta": {"hexsha": "c25aa7fdf5a7dc44964005aeea861d94af608c24", "size": 2459, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/1d/multilayer/setaux.f90", "max_stars_repo_name": "AsianHam/geoclaw", "max_stars_repo_head_hexsha": "b5f9ee8cd6e64d107ba8bba1e6d588aa7bf6d417", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 51, "max_stars_repo_stars_event_min_datetime": "2015-07-01T13:39:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T16:13:17.000Z", "max_issues_repo_path": "src/1d/multilayer/setaux.f90", "max_issues_repo_name": "AsianHam/geoclaw", "max_issues_repo_head_hexsha": "b5f9ee8cd6e64d107ba8bba1e6d588aa7bf6d417", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 274, "max_issues_repo_issues_event_min_datetime": "2015-02-20T18:25:04.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-09T23:51:47.000Z", "max_forks_repo_path": "src/1d/multilayer/setaux.f90", "max_forks_repo_name": "BrisaDavis/geoclaw", "max_forks_repo_head_hexsha": "ccab58669bc2950de13cf0f35c10b3cd1cb1cda6", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 66, "max_forks_repo_forks_event_min_datetime": "2015-01-10T00:05:00.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-24T22:05:16.000Z", "avg_line_length": 30.3580246914, "max_line_length": 78, "alphanum_fraction": 0.4753965026, "num_tokens": 711, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070158103778, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6869024428912541}} {"text": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\ncc cc\ncc mnpade : parder test program cc\ncc cc\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\n real fac,facx\n integer i,ix,iy,ier,j,kx,kx1,ky,ky1,mx,my,m0,m1,m2,m3,nc,\n * nkx1,nky1,nux,nuy,nx,ny\n real tx(15),ty(15),c(100),x(6),y(6),z(36),wrk(200)\n integer iwrk(20)\nc we set up the grid points for evaluating the spline derivatives.\n mx = 6\n my = 6\n do 10 i=1,6\n x(i) = (i-1)*0.2\n y(i) = x(i)\n 10 continue\nc loop for different spline degrees with respect to the x-variable\n do 300 kx=3,5,2\nc the knots in the x-direction\n tx(kx+2) = 0.4\n tx(kx+3) = 0.7\n tx(kx+4) = 0.9\n kx1 = kx+1\n nx = 3+2*kx1\n j = nx\n do 20 i=1,kx1\n tx(i) = 0.\n tx(j) = 1.\n j = j-1\n 20 continue\nc loop for different spline degrees with respect to the y-variable\n do 200 ky=2,3\nc the knots in the y-direction\n ty(ky+2) = 0.3\n ty(ky+3) = 0.8\n ky1 = ky+1\n ny = 2+2*ky1\n j = ny\n do 30 i=1,ky1\n ty(i) = 0.\n ty(j) = 1.\n j = j-1\n 30 continue\nc we generate the b-spline coefficients for the test function x*y\n nkx1 = nx-kx1\n nky1 = ny-ky1\n do 40 i=1,nky1\n c(i) = 0.\n 40 continue\n do 50 i=2,nkx1\n c((i-1)*nky1+1) = 0.\n 50 continue\n fac = kx*ky\n m0 = 1\n do 70 i=2,nkx1\n m1 = m0+nky1\n facx = (tx(i+kx)-tx(i))/fac\n do 60 j=2,nky1\n m2 = m0+1\n m3 = m1+1\n c(m3) = c(m1)+c(m2)-c(m0)+facx*(ty(j+ky)-ty(j))\n m0 = m0+1\n m1 = m1+1\n 60 continue\n m0 = m0+1\n 70 continue\nc printing of the results\n write(6,900) kx,ky\n write(6,910)\n write(6,920) (tx(i),i=1,nx)\n write(6,930)\n write(6,920) (ty(i),i=1,ny)\n nc = nkx1*nky1\n write(6,940)\n write(6,950) (c(i),i=1,nc)\nc loop for different orders of spline derivatives\n do 100 ix=1,2\n nux = ix-1\n do 100 iy=1,2\n nuy = iy-1\nc evaluation of the spline derivative\n call parder(tx,nx,ty,ny,c,kx,ky,nux,nuy,x,mx,y,my,z,\n * wrk,200,iwrk,20,ier)\n write(6,960) nux,nuy\n write(6,970) (y(i),i=1,my)\n write(6,980)\n m2 = 0\n do 90 i=1,mx\n m1 = m2+1\n m2 = m2+my\n write(6,990) x(i),(z(j),j=m1,m2)\n 90 continue\n 100 continue\n 200 continue\n 300 continue\n stop\nc format statements.\n 900 format(33h0tensor product spline of degrees,2i3)\n 910 format(1x,40hposition of the knots in the x-direction)\n 920 format(1x,15f5.1)\n 930 format(1x,40hposition of the knots in the y-direction)\n 940 format(23h b-spline coefficients )\n 950 format(1x,8f9.4)\n 960 format(1h0,26hspline derivative of order,2i4)\n 970 format(1h0,8x,1hy,4x,6(4x,f4.1))\n 980 format(1h ,7x,1hx)\n 990 format(6x,f4.1,5x,6f8.2)\n end\n\n", "meta": {"hexsha": "87d9a4e6b82cb028ddcfeb9ed231b9f0adacfa3c", "size": 3221, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ApproxSpline/Resources/F77-Sources/ex/mnpade.f", "max_stars_repo_name": "modelica-3rdparty/ApproxSpline", "max_stars_repo_head_hexsha": "28420f5c1a88c9cd069defbd8c05e4a78a090675", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-07-13T17:24:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-18T16:16:02.000Z", "max_issues_repo_path": "ApproxSpline/Resources/F77-Sources/ex/mnpade.f", "max_issues_repo_name": "tbeu/ApproxSpline", "max_issues_repo_head_hexsha": "28420f5c1a88c9cd069defbd8c05e4a78a090675", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-03-28T09:08:23.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T07:35:48.000Z", "max_forks_repo_path": "ApproxSpline/Resources/F77-Sources/ex/mnpade.f", "max_forks_repo_name": "modelica-3rdparty/ApproxSpline", "max_forks_repo_head_hexsha": "28420f5c1a88c9cd069defbd8c05e4a78a090675", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-10-21T07:46:49.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T20:02:06.000Z", "avg_line_length": 29.018018018, "max_line_length": 72, "alphanum_fraction": 0.5113318845, "num_tokens": 1228, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.909907001151883, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6869024368425426}} {"text": " SUBROUTINE theta_f (icoil, th0, th1, th2)\n!-----------------------------------------------\n! M o d u l e s\n!-----------------------------------------------\n USE modular_coils\n USE Vwire\n USE coils\n IMPLICIT NONE\n!-----------------------------------------------\n! L o c a l V a r i a b l e s\n!-----------------------------------------------\n INTEGER :: i, mu, icoil\n REAL(rprec) :: theta, th0, th1, th2, t0, t1, t2\n REAL(rprec) :: rs, rc, sk, ck\n!-----------------------------------------------\n!\n! Computes u(s) and u', u'', from Eq. 2 in Strickler, et al\n! u(s) = theta/2*pi + SUM(rhoc*cos(m*theta)+rhos*sin(m*theta))\n! where theta=2*pi*s\n!\n i = icoil\n theta = th0\n t0 = theta\n t1 = 1\n t2 = 0\n DO mu = 0, nf_rho\n rs = modular(i)%rhos(mu)\n rc = modular(i)%rhoc(mu)\n sk = SIN(mu*theta)\n ck = COS(mu*theta)\n t0 = t0 + rs*sk + rc*ck\n t1 = t1 + mu*(rs*ck - rc*sk) !1st derivative \n t2 = t2 - mu**2*(rs*sk + rc*ck) !2nd derivative (for curvature)\n END DO\n th0 = t0\n th1 = t1\n th2 = t2\n\n END SUBROUTINE theta_f\n", "meta": {"hexsha": "23b47a7172a782f1cf7c9eb3d6a9cc21c20f03eb", "size": 1184, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "COILOPT/Sources/General/theta_f.f", "max_stars_repo_name": "joseluisvelasco/STELLOPT", "max_stars_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2020-05-08T01:47:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T10:35:28.000Z", "max_issues_repo_path": "COILOPT/Sources/General/theta_f.f", "max_issues_repo_name": "joseluisvelasco/STELLOPT", "max_issues_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 77, "max_issues_repo_issues_event_min_datetime": "2020-05-08T07:18:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:20:33.000Z", "max_forks_repo_path": "COILOPT/Sources/General/theta_f.f", "max_forks_repo_name": "joseluisvelasco/STELLOPT", "max_forks_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-02-10T13:47:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T12:53:43.000Z", "avg_line_length": 29.6, "max_line_length": 75, "alphanum_fraction": 0.3885135135, "num_tokens": 372, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070011518829, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6869024368425426}} {"text": "module convolution\n use, intrinsic :: iso_c_binding\n use types\n\n implicit none\n\n include 'fftw3.f03'\n\n\n type :: CONV_T\n real(kind=8), allocatable :: A(:,:,:), B(:,:,:), conv(:,:,:)\n complex(kind=8), allocatable :: dftA(:,:,:), dftB(:,:,:), dftConv(:,:,:)\n contains\n procedure :: init_A => conv_init_A\n procedure :: init_B => conv_init_B\n procedure :: execute => conv_execute\n procedure :: free => conv_free\n end type CONV_T\n\n real(kind=8), parameter :: pi = 3.14159265358979d0\n private :: pi\n\ncontains\n !> Generate a 3d gaussian kernel\n !! parameters:\n !! s: the number of elements in the kernel\n !! sigma: the sigma of the kernel\n !! kernel: a 3d array containing the kernel\n subroutine kernel_gaussian3d(s, sigma, kernel)\n integer, intent(in) :: s\n real(kind=8), intent(in) :: sigma\n real(kind=8), dimension(s, s, s), intent(out) :: kernel\n\n integer :: i, j, k\n real(kind=8) :: sizeo2, sq_sum\n\n sizeo2 = s/2.\n\n do k = 1, s\n do j = 1, s\n do i = 1, s\n sq_sum = (i - sizeo2)**2 + (j - sizeo2)**2 + (k - sizeo2)**2\n kernel(i,j,k) = 1/(sqrt(2*pi) * sigma)**3 * exp(-sq_sum / (2*sigma**2))\n end do\n end do\n end do\n\n end subroutine kernel_gaussian3d\n\n !> Compute the fft of in, putting the result in out\n subroutine fft(in, out)\n real(kind=8), intent(inout), dimension(:,:,:) :: in\n complex(kind=8), intent(out), dimension(size(in, 1), size(in, 2),&\n & size(in, 3)) :: out\n complex(kind=8), dimension(size(in, 1), size(in, 2),&\n & size(in, 3)) :: cplx_in\n\n type(C_PTR) :: plan\n\n integer :: L, N, M\n\n L = size(in, 1)\n M = size(in, 2)\n N = size(in, 3)\n\n cplx_in = cmplx(in, 0, 8)\n\n ! create plan\n plan = fftw_plan_dft_3d(N, M, L, cplx_in, out, FFTW_FORWARD, FFTW_ESTIMATE)\n\n ! execute it\n call fftw_execute_dft(plan, cplx_in, out)\n\n ! delete plan\n call fftw_destroy_plan(plan)\n\n end subroutine fft\n\n subroutine ifft(in, out)\n complex(kind=8), intent(inout), dimension(:,:,:) :: in\n\n real(kind=8), intent(out), dimension(size(in, 1), size(in, 2), size(in, 3)) :: out\n\n complex(kind=8), dimension(size(in, 1), size(in, 2), size(in, 3)) :: cplx_out\n\n type(C_PTR) :: plan\n\n integer :: L, N, M\n\n L = size(in, 1)\n M = size(in, 2)\n N = size(in, 3)\n\n ! create plan\n plan = fftw_plan_dft_3d(N, M, L, in, cplx_out, FFTW_BACKWARD, FFTW_ESTIMATE)\n\n ! execute it\n call fftw_execute_dft(plan, in, cplx_out)\n\n out = real(cplx_out, 8) / (L*M*N)\n\n ! delete plan\n call fftw_destroy_plan(plan)\n\n end subroutine ifft\n\n !> Prepare the convolution A*B by giving A\n subroutine conv_init_A (self, A)\n real(kind=8), intent(in) :: A(:,:,:)\n class(CONV_T), intent(inout) :: self\n\n if (allocated(self%A)) deallocate(self%A)\n if (allocated(self%dftA)) deallocate(self%dftA)\n\n allocate(self%A(size(A, 1), size(A, 2), size(A, 3)))\n allocate(self%dftA(size(A, 1), size(A, 2), size(A, 3)))\n self%A = A\n\n call fft(self%A, self%dftA)\n end subroutine conv_init_A\n\n !> Prepare the convolution A*B by giving B\n subroutine conv_init_B (self, B)\n real(kind=8), intent(in) :: B(:,:,:)\n class(CONV_T), intent(inout) :: self\n\n if (allocated(self%B)) deallocate(self%B)\n if (allocated(self%dftB)) deallocate(self%dftB)\n\n allocate(self%B(size(B, 1), size(B, 2), size(B, 3)))\n allocate(self%dftB(size(B, 1), size(B, 2), size(B, 3)))\n self%B = B\n\n call fft(self%B, self%dftB)\n end subroutine conv_init_B\n\n !> Execute the convolution\n subroutine conv_execute(self)\n class(CONV_T), intent(inout) :: self\n\n integer :: L, M, N\n L = size(self%dftA, 1)\n M = size(self%dftA, 2)\n N = size(self%dftA, 3)\n\n if (allocated(self%conv)) deallocate(self%conv)\n if (allocated(self%dftConv)) deallocate(self%dftConv)\n\n allocate(self%dftConv(L, M, N))\n allocate(self%conv(L, M, N))\n\n call conv_prod(self%dftA, self%dftB, self%dftConv)\n call ifft(self%dftConv, self%conv)\n end subroutine conv_execute\n\n !> Compute the convolution product of A, B in fourier space\n subroutine conv_prod(A, B, C)\n complex(kind=8), intent(in) :: A(:,:,:), B(:,:,:)\n complex(kind=8), intent(out) :: C(size(A, 1), size(A, 2), size(A, 3))\n\n integer :: i,j,k\n do k = 1, size(A, 3)\n do j = 1, size(A, 2)\n do i = 1, size(A, 1)\n ! from\n ! http://www.fftw.org/faq/section3.html#centerorigin\n ! with special care with the fact that fortran starts\n ! indexing at 1, not 0!\n C(i,j,k) = A(i,j,k) * B(i,j,k) * (-1)**(i+j+k+1)\n end do\n end do\n end do\n\n end subroutine conv_prod\n\n !! Compute the 3d histogram of data, using nbin and weights and\n !! store it into bins\n subroutine conv_hist3d(data, nbin, weights, hist, edges)\n real(kind=8), dimension(:,:), intent(in) :: data !! data(ndim, nparts)\n real(kind=8), dimension(size(data, 2)), &\n intent(in), optional :: weights ! weights(nparts)\n integer, intent(in) :: nbin\n\n real(kind=8), dimension(nbin, nbin, nbin), intent(out) :: hist\n real(kind=8), dimension(3, nbin+1), intent(out), optional :: edges\n\n real(kind=8), dimension(3) :: maxis, minis, spans\n\n integer :: i, j, k, part_i, ndim, nparts\n\n ! get the dimensions\n ndim = size(data, 1)\n nparts = size(data, 2)\n ! compute the edges\n maxis = maxval(data, 2)\n minis = minval(data, 2)\n spans = maxis - minis\n\n do i = 1, nbin + 1\n edges(:, i) = minis + (maxis - minis) * (i-1) / nbin\n end do\n print*, minis, maxis\n\n print*, nparts\n ! project the data onto the edges\n do part_i = 1, nparts\n ! get the position in the grid\n i = floor((data(1, part_i) - minis(1)) * nbin / spans(1)) + 1\n j = floor((data(2, part_i) - minis(2)) * (nbin * 1d0) / spans(2)) + 1\n k = floor((data(3, part_i) - minis(3)) * nbin / spans(3)) + 1\n\n ! because of rounding errors, the maxima aren't well found,\n ! fix that\n if (data(1, part_i) == maxis(1)) i = nbin\n if (data(2, part_i) == maxis(2)) j = nbin\n if (data(3, part_i) == maxis(3)) k = nbin\n\n ! print*, i,j,k\n ! TODO: linear approximation of density\n ! increment the histogram\n if ((i <= 0) .or. (i > nbin) .or. (j <= 0) .or. (j > nbin) .or.&\n (k <= 0) .or. (k > nbin)) then\n print*, 'Dafuk ?!'\n print*, (data(:, part_i) - maxis) == 0\n print*, i, j, k\n end if\n\n if (present(weights)) then\n hist(i, j, k) = hist(i, j, k) + weights(part_i)\n else\n hist(i, j, k) = hist(i, j, k) + 1\n end if\n end do\n\n print*, nparts, ndim\n end subroutine conv_hist3d\n\n !! Estimate the density\n subroutine conv_density(data, nbin, dens, edges)\n real(kind=8), dimension(:,:), intent(in) :: data !! data(ndim, nparts)\n integer, intent(in) :: nbin\n\n real(kind=8), dimension(nbin, nbin, nbin), intent(out) :: dens\n real(kind=8), dimension(3, nbin+1), intent(out), optional:: edges\n\n real(kind=8), dimension(3) :: maxis, minis, spans\n\n integer :: i, j, k, part_i, ndim, nparts, i0, j0, k0, imax, jmax, kmax, imin, jmin, kmin\n real(kind=8) :: ri, rj, rk\n\n ! get the dimensions\n ndim = size(data, 1)\n nparts = size(data, 2)\n ! compute the bins\n maxis = maxval(data, 2)\n minis = minval(data, 2)\n\n spans = (maxis - minis)\n\n do i = 1, nbin + 1\n edges(:, i) = minis + spans * (i-1) / nbin\n end do\n\n ! project the data onto the bins\n do part_i = 1, nparts\n ! get the position in the grid\n ri = (data(1, part_i) - minis(1)) * nbin / spans(1) + 0.5\n rj = (data(2, part_i) - minis(2)) * nbin / spans(2) + 0.5\n rk = (data(3, part_i) - minis(3)) * nbin / spans(3) + 0.5\n\n ! the max and min are actually only half in leftmost/rightmost bin\n ! so the min has ri = 0.5\n ! and the max has ri = nbin + 0.5\n\n i0 = floor(ri)\n j0 = floor(rj)\n k0 = floor(rk)\n\n imin = max(1, i0)\n jmin = max(1, j0)\n kmin = max(1, k0)\n\n imax = min(nbin, i0 + 1)\n jmax = min(nbin, j0 + 1)\n kmax = min(nbin, k0 + 1)\n\n do k = kmin, kmax\n do j = jmin, jmax\n do i = imin, imax\n ! add the proportion of the particle in the box\n dens(i, j, k) = dens(i, j, k) + abs((ri - i)*(rj - j)*(rk - k))\n end do\n end do\n end do\n end do\n\n ! Convert the number density into a mass density (assuming uniform mass)\n ! TODO: don't assume uniform mass\n dens = dens * nbin**3 / product(maxis-minis)\n\n end subroutine conv_density\n\n subroutine conv_free(self)\n class(CONV_T), intent(inout) :: self\n if (allocated(self%A)) deallocate(self%A)\n if (allocated(self%B)) deallocate(self%B)\n if (allocated(self%conv)) deallocate(self%conv)\n\n if (allocated(self%dftA)) deallocate(self%dftA)\n if (allocated(self%dftB)) deallocate(self%dftB)\n if (allocated(self%dftConv)) deallocate(self%dftConv)\n\n end subroutine conv_free\n\nend module convolution\n", "meta": {"hexsha": "58816519f0238a689b29761be2fd2e4cdacc97ba", "size": 9195, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tools/convolution.f90", "max_stars_repo_name": "cphyc/cosmo_z17to0", "max_stars_repo_head_hexsha": "20fb1bbdfff79b3575b70be6413d1f3bb5466165", "max_stars_repo_licenses": ["CC-BY-4.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": "tools/convolution.f90", "max_issues_repo_name": "cphyc/cosmo_z17to0", "max_issues_repo_head_hexsha": "20fb1bbdfff79b3575b70be6413d1f3bb5466165", "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": "tools/convolution.f90", "max_forks_repo_name": "cphyc/cosmo_z17to0", "max_forks_repo_head_hexsha": "20fb1bbdfff79b3575b70be6413d1f3bb5466165", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.0981012658, "max_line_length": 92, "alphanum_fraction": 0.5691136487, "num_tokens": 3051, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070035949657, "lm_q2_score": 0.7549149758396752, "lm_q1q2_score": 0.6869024236352447}} {"text": "! BUCKLING_CPANEL_BARDELL program\n!\n! Buckling of cylindrical panels.\n!\n! The required inputs that should be given are described below.\n! \n! Run control\n! -----------\n! NUM : integer\n! Number of returned eigenvalues\n!\n! M : integer\n! Number of terms along x\n!\n! N : integer\n! Number of terms along x\n!\n! Geometry\n! --------\n! a : float\n! The panel length (dimension along x)\n! b : float\n! The panel circumferential width (dimension along y)\n! r : float\n! The panel radius. (Set a high value to simulate a plate)\n! t : float, optional (used with ISOTROPIC flag)\n! Panel thickness\n!\n! Isotropic Material Properties\n! -----------------------------\n! ISOTROPIC : flag\n! If present in the input, matrix ABD will be calculated based on\n! E, nu and t.\n! E : float\n! Elastic modulus\n! nu : float\n! Poisson's ratio\n!\n! Applied Loads\n! -------------\n! Nxx : float\n! Nxx stress\n! Nyy : float\n! Nyy stress\n! Nxy : float\n! Nxy stress\n!\n! Laminate Constitutive Varibles (matrix ABD)\n! -------------------------------------------\n! ONLY used if ISOTROPIC = FALSE\n!\n! A11 : float\n! Membrane stiffness along x\n! A12 : float\n! Membrane stiffness\n! A16 : float\n! Shear-extension coupling\n! A22 : float\n! Membrane stiffness along y\n! A26 : float\n! Shear-extension coupling\n! A66 : float\n! Membrane Shear stiffness\n! B11 : float\n! Bending-extension coupling\n! B12 : float\n! Bending-extension coupling\n! B16 : float\n! Bending-extension coupling\n! B22 : float\n! Bending-extension coupling\n! B26 : float\n! Bending-extension coupling\n! B66 : float\n! Bending-extension coupling\n! D11 : float\n! Bending stiffness\n! D12 : float\n! Bending stiffness\n! D16 : float\n! Bending-twist stiffness\n! D22 : float\n! Bending stiffness\n! D26 : float\n! Bending-twist stiffness\n! D66 : float\n! Twist (torsion) stiffness\n!\n! Boundary conditions\n! -------------------\n! u1tx : float\n! If 1. the edge at x=0 can translate along u \n! If 0. the edge at x=0 cannot translate along u \n! u1rx : float\n! If 1. the end at x=0 can rotate\n! If 0. the end at x=0 cannot translate along u \n! u2tx : float\n! If 1. the edge at x=a can translate along u \n! If 0. the edge at x=a cannot translate along u \n! u2rx : float\n! If 1. the end at x=a can rotate\n! If 0. the end at x=a cannot translate along u \n! u1ty : float\n! If 1. the edge at y=0 can translate along u \n! If 0. the edge at y=0 cannot translate along u \n! u1ry : float\n! If 1. the end at y=0 can rotate\n! If 0. the end at y=0 cannot translate along u \n! u2ty : float\n! If 1. the edge at y=b can translate along u \n! If 0. the edge at y=b cannot translate along u \n! u2ry : float\n! If 1. the end at y=b can rotate\n! If 0. the end at y=b cannot translate along u \n! v1tx : float\n! If 1. the edge at x=0 can translate along v \n! If 0. the edge at x=0 cannot translate along v \n! v1rx : float\n! If 1. the end at x=0 can rotate\n! If 0. the end at x=0 cannot translate along v \n! v2tx : float\n! If 1. the edge at x=a can translate along v \n! If 0. the edge at x=a cannot translate along v \n! v2rx : float\n! If 1. the end at x=a can rotate\n! If 0. the end at x=a cannot translate along v \n! v1ty : float\n! If 1. the edge at y=0 can translate along v \n! If 0. the edge at y=0 cannot translate along v \n! v1ry : float\n! If 1. the end at y=0 can rotate\n! If 0. the end at y=0 cannot translate along v \n! v2ty : float\n! If 1. the edge at y=b can translate along v \n! If 0. the edge at y=b cannot translate along v \n! v2ry : float\n! If 1. the end at y=b can rotate\n! If 0. the end at y=b cannot translate along v \n! w1tx : float\n! If 1. the edge at x=0 can translate along w \n! If 0. the edge at x=0 cannot translate along w \n! w1rx : float\n! If 1. the end at x=0 can rotate\n! If 0. the end at x=0 cannot translate along w \n! w2tx : float\n! If 1. the edge at x=a can translate along w \n! If 0. the edge at x=a cannot translate along w \n! w2rx : float\n! If 1. the end at x=a can rotate\n! If 0. the end at x=a cannot translate along w \n! w1ty : float\n! If 1. the edge at y=0 can translate along w \n! If 0. the edge at y=0 cannot translate along w \n! w1ry : float\n! If 1. the end at y=0 can rotate\n! If 0. the end at y=0 cannot translate along w \n! w2ty : float\n! If 1. the edge at y=b can translate along w \n! If 0. the edge at y=b cannot translate along w \n! w2ry : float\n! If 1. the end at y=b can rotate\n! If 0. the end at y=b cannot translate along w \n\nINCLUDE 'calc_matrices.f90'\nINCLUDE '../bardell.f90'\n\nPROGRAM BUCKLING_CPANEL_BARDELL\n IMPLICIT NONE\n INTERFACE\n SUBROUTINE integral_ff(i, j, x1t, x1r, x2t, x2r, y1t, y1r, y2t, y2r, out)\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: i, j\n REAL*8, INTENT(IN) :: x1t, x1r, x2t, x2r, y1t, y1r, y2t, y2r\n REAL*8, INTENT(OUT) :: out\n END SUBROUTINE\n SUBROUTINE integral_ffxi(i, j, x1t, x1r, x2t, x2r, y1t, y1r, y2t, y2r, out)\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: i, j\n REAL*8, INTENT(IN) :: x1t, x1r, x2t, x2r, y1t, y1r, y2t, y2r\n REAL*8, INTENT(OUT) :: out\n END SUBROUTINE\n SUBROUTINE integral_ffxixi(i, j, x1t, x1r, x2t, x2r, y1t, y1r, y2t, y2r, out)\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: i, j\n REAL*8, INTENT(IN) :: x1t, x1r, x2t, x2r, y1t, y1r, y2t, y2r\n REAL*8, INTENT(OUT) :: out\n END SUBROUTINE\n SUBROUTINE integral_fxifxi(i, j, x1t, x1r, x2t, x2r, y1t, y1r, y2t, y2r, out)\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: i, j\n REAL*8, INTENT(IN) :: x1t, x1r, x2t, x2r, y1t, y1r, y2t, y2r\n REAL*8, INTENT(OUT) :: out\n END SUBROUTINE\n SUBROUTINE integral_fxifxixi(i, j, x1t, x1r, x2t, x2r, y1t, y1r, y2t, y2r, out)\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: i, j\n REAL*8, INTENT(IN) :: x1t, x1r, x2t, x2r, y1t, y1r, y2t, y2r\n REAL*8, INTENT(OUT) :: out\n END SUBROUTINE\n SUBROUTINE integral_fxixifxixi(i, j, x1t, x1r, x2t, x2r, y1t, y1r, y2t, y2r, out)\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: i, j\n REAL*8, INTENT(IN) :: x1t, x1r, x2t, x2r, y1t, y1r, y2t, y2r\n REAL*8, INTENT(OUT) :: out\n END SUBROUTINE\n SUBROUTINE CALC_K0(M, N, K, a, b, r, &\n A11, A12, A16, A22, A26, A66, B11, B12, B16, B22, B26, B66, D11, D12, D16, D22, D26, D66, &\n u1tx, u1rx, u2tx, u2rx, u1ty, u1ry, u2ty, u2ry, &\n v1tx, v1rx, v2tx, v2rx, v1ty, v1ry, v2ty, v2ry, &\n w1tx, w1rx, w2tx, w2rx, w1ty, w1ry, w2ty, w2ry)\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: M, N\n REAL*8, INTENT(IN) :: a, b, r\n REAL*8, INTENT(IN) :: A11, A12, A16, A22, A26, A66\n REAL*8, INTENT(IN) :: B11, B12, B16, B22, B26, B66\n REAL*8, INTENT(IN) :: D11, D12, D16, D22, D26, D66\n REAL*8, INTENT(IN) :: u1tx, u1rx, u2tx, u2rx, u1ty, u1ry, u2ty, u2ry\n REAL*8, INTENT(IN) :: v1tx, v1rx, v2tx, v2rx, v1ty, v1ry, v2ty, v2ry\n REAL*8, INTENT(IN) :: w1tx, w1rx, w2tx, w2rx, w1ty, w1ry, w2ty, w2ry\n REAL*8, INTENT(OUT) :: K(3*M*N, 3*M*N)\n END SUBROUTINE\n SUBROUTINE CALC_KG0(M, N, K, a, b, Nxx, Nyy, Nxy, w1tx, w1rx, w2tx, w2rx, w1ty, w1ry, w2ty, w2ry)\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: M, N\n REAL*8, INTENT(IN) :: a, b, Nxx, Nyy, Nxy\n REAL*8, INTENT(IN) :: w1tx, w1rx, w2tx, w2rx, w1ty, w1ry, w2ty, w2ry\n REAL*8, INTENT(OUT) :: K(3*M*N, 3*M*N)\n END SUBROUTINE\n END INTERFACE\n\n ! inputs\n CHARACTER BALANC, JOBVL, JOBVR, SENSE\n INTEGER NT, nulls, NUM, M, N\n REAL*8, ALLOCATABLE :: K0(:, :), KG0(:, :), K02(:, :), KG02(:, :)\n REAL*8 A11, A12, A16, A22, A26, A66\n REAL*8 B11, B12, B16, B22, B26, B66\n REAL*8 D11, D12, D16, D22, D26, D66\n REAL*8 u1tx, u1rx, u2tx, u2rx, u1ty, u1ry, u2ty, u2ry\n REAL*8 v1tx, v1rx, v2tx, v2rx, v1ty, v1ry, v2ty, v2ry\n REAL*8 w1tx, w1rx, w2tx, w2rx, w1ty, w1ry, w2ty, w2ry\n REAL*8 a, b, r, Nxx, Nyy, Nxy\n INTEGER LDA, LDB, LDZ\n\n ! workspace\n CHARACTER (LEN=100) :: line\n CHARACTER (LEN=400) :: input_file, output_file\n INTEGER stat, i, j, id, jd\n INTEGER LWORK\n INTEGER, ALLOCATABLE :: IWORK(:)\n REAL*8, ALLOCATABLE :: WORK(:)\n REAL*8 E11, nu, G12, t, NULLTOL\n CHARACTER (LEN=5) :: ISOTROPIC\n INTEGER, ALLOCATABLE :: TMP(:)\n\n ! outputs\n INTEGER Mout, INFO\n INTEGER, ALLOCATABLE :: IFAIL(:)\n REAL*8, ALLOCATABLE :: EIGVALS(:), EIGVECS(:, :)\n\n\n BALANC = 'N'\n JOBVL = 'N'\n JOBVR = 'N'\n SENSE = 'N' \n\n NUM = 10\n M = 15\n N = 15\n\n ! Tolerance to consider a zero in K0 and KG0\n NULLTOL = 1.e-15 \n\n ISOTROPIC = \"FALSE\"\n\n ! Default boundary conditions (simply supported)\n u1tx = 0.\n u1rx = 1.\n u2tx = 0.\n u2rx = 1.\n u1ty = 0.\n u1ry = 1.\n u2ty = 0.\n u2ry = 1.\n v1tx = 0.\n v1rx = 1.\n v2tx = 0.\n v2rx = 1.\n v1ty = 0.\n v1ry = 1.\n v2ty = 0.\n v2ry = 1.\n w1tx = 0.\n w1rx = 1.\n w2tx = 0.\n w2rx = 1.\n w1ty = 0.\n w1ry = 1.\n w2ty = 0.\n w2ry = 1.\n\n IF (COMMAND_ARGUMENT_COUNT() .NE. 2) THEN\n STOP \"This program should be called as: 'buckling_cpanel_bardell input output'\"\n ELSE\n CALL GET_COMMAND_ARGUMENT(1, VALUE=input_file, STATUS=stat)\n CALL GET_COMMAND_ARGUMENT(2, VALUE=output_file, STATUS=stat)\n END IF\n\n OPEN(10, FILE=input_file)\n DO \n READ(10, *) line\n IF (TRIM(line) == \"NUM\") READ(10, *) NUM\n IF (TRIM(line) == \"M\") READ(10, *) M\n IF (TRIM(line) == \"N\") READ(10, *) N\n IF (TRIM(line) == \"a\") READ(10, *) a\n IF (TRIM(line) == \"b\") READ(10, *) b\n IF (TRIM(line) == \"r\") READ(10, *) r\n IF (TRIM(line) == \"Nxx\") READ(10, *) Nxx\n IF (TRIM(line) == \"Nyy\") READ(10, *) Nyy\n IF (TRIM(line) == \"Nxy\") READ(10, *) Nxy\n\n IF (TRIM(line) == \"ISOTROPIC\") ISOTROPIC = \"TRUE\"\n IF (TRIM(line) == \"E\") READ(10, *) E11\n IF (TRIM(line) == \"nu\") READ(10, *) nu\n IF (TRIM(line) == \"t\") READ(10, *) t\n\n IF (TRIM(line) == \"A11\") READ(10, *) A11\n IF (TRIM(line) == \"A12\") READ(10, *) A12\n IF (TRIM(line) == \"A16\") READ(10, *) A16\n IF (TRIM(line) == \"A22\") READ(10, *) A22\n IF (TRIM(line) == \"A26\") READ(10, *) A26\n IF (TRIM(line) == \"A66\") READ(10, *) A66\n\n IF (TRIM(line) == \"B11\") READ(10, *) B11\n IF (TRIM(line) == \"B12\") READ(10, *) B12\n IF (TRIM(line) == \"B16\") READ(10, *) B16\n IF (TRIM(line) == \"B22\") READ(10, *) B22\n IF (TRIM(line) == \"B26\") READ(10, *) B26\n IF (TRIM(line) == \"B66\") READ(10, *) B66\n\n IF (TRIM(line) == \"D11\") READ(10, *) D11\n IF (TRIM(line) == \"D12\") READ(10, *) D12\n IF (TRIM(line) == \"D16\") READ(10, *) D16\n IF (TRIM(line) == \"D22\") READ(10, *) D22\n IF (TRIM(line) == \"D26\") READ(10, *) D26\n IF (TRIM(line) == \"D66\") READ(10, *) D66\n\n IF (TRIM(line) == \"u1tx\") READ(10, *) u1tx\n IF (TRIM(line) == \"u1rx\") READ(10, *) u1rx\n IF (TRIM(line) == \"u2tx\") READ(10, *) u2tx\n IF (TRIM(line) == \"u2rx\") READ(10, *) u2rx\n IF (TRIM(line) == \"u1ty\") READ(10, *) u1ty\n IF (TRIM(line) == \"u1ry\") READ(10, *) u1ry\n IF (TRIM(line) == \"u2ty\") READ(10, *) u2ty\n IF (TRIM(line) == \"u2ry\") READ(10, *) u2ry\n \n IF (TRIM(line) == \"v1tx\") READ(10, *) v1tx\n IF (TRIM(line) == \"v1rx\") READ(10, *) v1rx\n IF (TRIM(line) == \"v2tx\") READ(10, *) v2tx\n IF (TRIM(line) == \"v2rx\") READ(10, *) v2rx\n IF (TRIM(line) == \"v1ty\") READ(10, *) v1ty\n IF (TRIM(line) == \"v1ry\") READ(10, *) v1ry\n IF (TRIM(line) == \"v2ty\") READ(10, *) v2ty\n IF (TRIM(line) == \"v2ry\") READ(10, *) v2ry\n\n IF (TRIM(line) == \"w1tx\") READ(10, *) w1tx\n IF (TRIM(line) == \"w1rx\") READ(10, *) w1rx\n IF (TRIM(line) == \"w2tx\") READ(10, *) w2tx\n IF (TRIM(line) == \"w2rx\") READ(10, *) w2rx\n IF (TRIM(line) == \"w1ty\") READ(10, *) w1ty\n IF (TRIM(line) == \"w1ry\") READ(10, *) w1ry\n IF (TRIM(line) == \"w2ty\") READ(10, *) w2ty\n IF (TRIM(line) == \"w2ry\") READ(10, *) w2ry\n IF (TRIM(line) == \"END\") EXIT \n END DO\n\n NT = 3*M*N\n\n ! Calculating ABD\n\n IF (ISOTROPIC == \"TRUE\") THEN\n G12 = E11/(2*(1 + nu))\n\n A11 = E11*t/(1 - nu**2)\n A12 = nu*E11*t/(1 - nu**2)\n A16 = 0\n A22 = E11*t/(1 - nu**2)\n A26 = 0\n A66 = G12*t\n\n B11 = 0\n B12 = 0\n B16 = 0\n B22 = 0\n B26 = 0\n B66 = 0\n\n D11 = E11*t**3/(12*(1 - nu**2))\n D12 = nu*E11*t**3/(12*(1 - nu**2))\n D16 = 0\n D22 = E11*t**3/(12*(1 - nu**2))\n D26 = 0\n D66 = G12*t**3/12\n END IF\n\n ! allocating arrays\n ALLOCATE(K0(NT, NT))\n ALLOCATE(KG0(NT, NT))\n\n ! constitutive stiffness matrix\n CALL CALC_K0(M, N, K0, a, b, r, &\n A11, A12, A16, A22, A26, A66, B11, B12, B16, B22, B26, B66, D11, D12, D16, D22, D26, D66, &\n u1tx, u1rx, u2tx, u2rx, u1ty, u1ry, u2ty, u2ry, &\n v1tx, v1rx, v2tx, v2rx, v1ty, v1ry, v2ty, v2ry, &\n w1tx, w1rx, w2tx, w2rx, w1ty, w1ry, w2ty, w2ry)\n\n ! geometric stiffness matrix\n CALL CALC_KG0(M, N, KG0, a, b, Nxx, Nyy, Nxy, w1tx, w1rx, w2tx, w2rx, w1ty, w1ry, w2ty, w2ry)\n\n ! removing null rows and columns\n ALLOCATE(TMP(NT)) \n TMP = 0\n WHERE (ABS(SUM(K0, DIM=1)) <= NULLTOL) TMP = 1\n nulls = SUM(TMP)\n WRITE(*, *) \"Number of removed cols:\", nulls\n\n ALLOCATE(K02(NT-nulls, NT-nulls))\n ALLOCATE(KG02(NT-nulls, NT-nulls))\n\n jd = 0\n DO j=1, NT\n IF (TMP(j) == 1) THEN\n jd = jd+1\n CYCLE\n END IF\n id = 0\n DO i=1, NT\n IF (TMP(i) == 1) THEN\n id = id+1\n CYCLE\n END IF\n K02(i-id, j-jd) = K0(i, j)\n KG02(i-id, j-jd) = KG0(i, j)\n END DO\n END DO\n DEALLOCATE(TMP)\n\n ! allocating arrays\n ALLOCATE(IWORK((NT-nulls)*25))\n\n ! allocating output arrays\n ALLOCATE(EIGVALS(NT-nulls))\n ALLOCATE(EIGVECS(NT-nulls, NT-nulls))\n ALLOCATE(IFAIL(NT-nulls))\n\n LDA = NT-nulls\n LDB = NT-nulls\n LDZ = NT-nulls\n\n WRITE(*, *) 'Eigenvalue analysis started...'\n\n ! signature of eigenvalue solver used:\n !\n ! CALL DSYGVX(ITYPE, JOBZ, RANGE, UPLO, N, A, LDA, B, LDB, &\n ! VL, VU, IL, IU, ABSTOL, Mout, W, Z, LDZ, &\n ! WORK, LWORK, IWORK, IFAIL, INFO)\n\n EIGVALS = EIGVALS*0\n\n ! Workspace query\n LWORK = -1\n ALLOCATE(WORK(10)) \n CALL DSYGVX(1, \"N\", \"I\", \"U\", (NT-nulls), KG02, LDB, K02, LDA, &\n -1.D10, 0, 1, NUM, 0., Mout, EIGVALS, EIGVECS, LDZ, &\n WORK, LWORK, IWORK, IFAIL, INFO)\n LWORK = WORK(1)\n DEALLOCATE(WORK)\n ! Eigensolver query\n ALLOCATE(WORK(LWORK))\n CALL DSYGVX(1, \"N\", \"I\", \"U\", (NT-nulls), KG02, LDB, K02, LDA, &\n -1.D10, 0, 1, NUM, 0., Mout, EIGVALS, EIGVECS, LDZ, &\n WORK, LWORK, IWORK, IFAIL, INFO)\n DEALLOCATE(WORK)\n\n WHERE(EIGVALS /= 0) EIGVALS = -1/EIGVALS\n\n WRITE(*, *) \"Eigenvalue analysis completed!\"\n\n ! Writing eigenvalues\n OPEN(11, FILE=output_file, ACTION=\"WRITE\", STATUS=\"REPLACE\")\n DO i=1, NUM\n WRITE(11, *) EIGVALS(i)\n END DO\n\n WRITE(*, *) 'EIGVALS:'\n WRITE(*, *) ' 1st) ', EIGVALS(1)\n WRITE(*, *) ' 2nd) ', EIGVALS(2)\n WRITE(*, *) ' 3rd) ', EIGVALS(3)\n WRITE(*, *) ' 4th) ', EIGVALS(4)\n WRITE(*, *) ' 5th) ', EIGVALS(5)\n IF (INFO /= 0) THEN\n WRITE(*, *) 'Mout', Mout\n WRITE(*, *) 'INFO', NT-nulls, INFO\n !WRITE(*, *) 'IFAIL', IFAIL\n WRITE(*, *) 'MIN(K02), MAX(K02)', MINVAL(K02), MAXVAL(K02)\n WRITE(*, *) 'SUM(K02), SUM(KG02)', SUM(K02), SUM(KG02)\n END IF\n\n DEALLOCATE(K0)\n DEALLOCATE(KG0)\n DEALLOCATE(K02)\n DEALLOCATE(KG02)\n DEALLOCATE(IWORK)\n DEALLOCATE(EIGVALS)\n DEALLOCATE(EIGVECS)\n DEALLOCATE(IFAIL)\n\nEND PROGRAM BUCKLING_CPANEL_BARDELL\n", "meta": {"hexsha": "5f9f9a25dcde8fe5d221bc9db8a33336e40c6cd8", "size": 16391, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "FORTRAN/bardell/linear_buckling_cpanel/buckling_cpanel_bardell.f90", "max_stars_repo_name": "mrosemeier/compmech", "max_stars_repo_head_hexsha": "f18f6d0471c72b26a3b014d2df41df3463505eae", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-02-05T06:12:12.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T14:41:18.000Z", "max_issues_repo_path": "FORTRAN/bardell/linear_buckling_cpanel/buckling_cpanel_bardell.f90", "max_issues_repo_name": "mrosemeier/compmech", "max_issues_repo_head_hexsha": "f18f6d0471c72b26a3b014d2df41df3463505eae", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "FORTRAN/bardell/linear_buckling_cpanel/buckling_cpanel_bardell.f90", "max_forks_repo_name": "mrosemeier/compmech", "max_forks_repo_head_hexsha": "f18f6d0471c72b26a3b014d2df41df3463505eae", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-06-05T07:19:35.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-29T00:22:18.000Z", "avg_line_length": 31.6428571429, "max_line_length": 118, "alphanum_fraction": 0.5382221951, "num_tokens": 6362, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069987088003, "lm_q2_score": 0.7549149758396752, "lm_q1q2_score": 0.6869024199466053}} {"text": "\nPROGRAM main\n\n IMPLICIT NONE\n\n REAL :: a, b, c, root1, root2\n REAL :: determinant\n\n PRINT*, \"Enter coefficients for polynomial a x^2 + b x + c: \"\n\n READ(*, *) a, b, c\n\n determinant = b**2 - 4.0 * a * c\n\n ! NOTE: we can't decide if the polynomial has only ONE root because\n ! we can't be sure if the determinant is exactly 0 or just too small\n ! to store in our real.\n\n IF(determinant < 0) THEN\n PRINT*, \"The polynomial has no real roots\"\n ELSE\n root1 = -b + sqrt(determinant)\n root2 = -b - sqrt(determinant)\n PRINT*, \"The roots are \", root1, \" and \", root2\n END IF\n\nEND PROGRAM\n", "meta": {"hexsha": "2f132ba0014cd19aad545b586920792fcf2aa0f4", "size": 603, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ModelSolutions/QuadraticEquation.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/QuadraticEquation.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/QuadraticEquation.f90", "max_forks_repo_name": "WarwickRSE/Fortran4Researchers", "max_forks_repo_head_hexsha": "14467a32a516fdc0cf33341aea8d5b26f4501b51", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.5357142857, "max_line_length": 70, "alphanum_fraction": 0.6301824212, "num_tokens": 192, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9099069962657177, "lm_q2_score": 0.754914975839675, "lm_q1q2_score": 0.6869024181022856}} {"text": " program demo_product\n implicit none\n integer :: x(5) = [ 1, 2, 3, 4 ,5 ]\n print *, product(x) ! all elements, product = 120\n print *, product(x, mask=mod(x, 2)==1) ! odd elements, product = 15\n end program demo_product\n", "meta": {"hexsha": "e2b5147977afc2571afdf1231b3d70a8dd9f1975", "size": 305, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/demo_product.f90", "max_stars_repo_name": "urbanjost/fortran-intrinsic-manpages", "max_stars_repo_head_hexsha": "672e0545bcbef3dd6c8169c8f6b8424dbb3f0880", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-06-30T07:29:39.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-10T07:36:25.000Z", "max_issues_repo_path": "example/demo_product.f90", "max_issues_repo_name": "urbanjost/fortran-intrinsic-manpages", "max_issues_repo_head_hexsha": "672e0545bcbef3dd6c8169c8f6b8424dbb3f0880", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-10-07T21:29:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-07T00:19:52.000Z", "max_forks_repo_path": "example/demo_product.f90", "max_forks_repo_name": "urbanjost/fortran-intrinsic-manpages", "max_forks_repo_head_hexsha": "672e0545bcbef3dd6c8169c8f6b8424dbb3f0880", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-10-08T00:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-08T00:41:17.000Z", "avg_line_length": 43.5714285714, "max_line_length": 81, "alphanum_fraction": 0.4721311475, "num_tokens": 79, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8688267898240862, "lm_q2_score": 0.7905303162021597, "lm_q1q2_score": 0.6868339168845423}} {"text": "module commondata\n implicit none\n \n integer, parameter :: total_nx = 65, total_ny = 65, total_nz = 65\n integer :: nx, ny, nz\n real(8), parameter :: Reynolds=1000.0d0\n real(8), parameter :: rho0=1.0d0\n real(8), parameter :: U0=0.1d0\n real(8), parameter :: tauf=U0*dble(total_nx)/Reynolds*3.0d0+0.5d0\n \n integer :: itc\n integer, parameter :: itc_max=INT(50000000)\n \n real(8) :: errorU\n real(8), parameter :: eps=1e-6\n \n real(8) :: xp(0:total_nx+1), yp(0:total_ny+1), zp(0:total_nz+1)\n real(8), allocatable :: u(:, :, :), v(:, :, :), w(:, :, :)\n real(8), allocatable :: rho(:, :, :)\n real(8), allocatable :: up(:, :, :), vp(:, :, :), wp(:, :, :)\n \n real(8), allocatable :: f(:, :, :, :), f_post(:, :, :, :)\n \n integer :: idx\n ! real(8), parameter :: omega(0:18) = (/ 1.0d0/3.0d0, & \n ! 1.0d0/18.0d0, 1.0d0/18.0d0, 1.0d0/18.0d0, 1.0d0/18.0d0, 1.0d0/18.0d0, 1.0d0/18.0d0, &\n ! 1.0d0/36.0d0, 1.0d0/36.0d0, 1.0d0/36.0d0, 1.0d0/36.0d0, 1.0d0/36.0d0, 1.0d0/36.0d0, &\n ! 1.0d0/36.0d0, 1.0d0/36.0d0, 1.0d0/36.0d0, 1.0d0/36.0d0, 1.0d0/36.0d0, 1.0d0/36.0d0 /)\n real(8), parameter :: omega(0:18) = (/ 1.0d0/3.0d0, &\n (1.0d0/18.0d0, idx = 1, 6), &\n (1.0d0/36.0d0, idx = 7, 18) /) \n integer, parameter :: ex(0:18) = (/ 0, &\n 1, -1, 0, 0, 0, 0, &\n 1, -1, 1, -1, 1, -1, 1, -1, 0, 0, 0, 0 /)\n integer, parameter :: ey(0:18) = (/ 0, &\n 0, 0, 1, -1, 0, 0, &\n 1, 1, -1, -1, 0, 0, 0, 0, 1, -1, 1, -1 /) \n integer, parameter :: ez(0:18) = (/ 0, &\n 0, 0, 0, 0, 1, -1, &\n 0, 0, 0, 0, 1, 1, -1, -1, 1, 1, -1, -1 /)\n \n real(8), parameter :: Snu=1.0d0/tauf, Sq=8.0d0*(2.0d0*tauf-1.0d0)/(8.0d0*tauf-1.0d0)\n \n\n ! mpi data\n integer :: rc, rank, num_process \n integer :: dims(0:2) = (/ 0, 0, 0 /), coords(0:2)\n logical :: periods(0:2) = (/ .false., .false., .false. /)\n integer :: comm3d, rank3d\n integer :: nbr_surface(1:6)\n integer :: nbr_line(7:18) \n integer :: surface_x, surface_y, surface_z ! surface data perpendicular to axis x, y, z\n integer :: line_x, line_y, line_z ! line data parallel to axis x, y, z\n\nend module commondata", "meta": {"hexsha": "3da6330d3ea210a9d0d493699fcab3f55ba6e40a", "size": 2510, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "MPI/Lid_driven_cavity/fortran/3d/mpi_3d_blocked/commondata.f90", "max_stars_repo_name": "cheryli/parallel", "max_stars_repo_head_hexsha": "a6b3f3ea479e64476a56f08e8c9e28c632a1b68b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-12-10T06:44:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-26T16:06:48.000Z", "max_issues_repo_path": "MPI/Lid_driven_cavity/fortran/3d/mpi_3d_blocked/commondata.f90", "max_issues_repo_name": "cheryli/parallel", "max_issues_repo_head_hexsha": "a6b3f3ea479e64476a56f08e8c9e28c632a1b68b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-12-11T12:50:24.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-11T14:11:56.000Z", "max_forks_repo_path": "MPI/Lid_driven_cavity/fortran/3d/mpi_3d_blocked/commondata.f90", "max_forks_repo_name": "cheryli/MGLC", "max_forks_repo_head_hexsha": "a6b3f3ea479e64476a56f08e8c9e28c632a1b68b", "max_forks_repo_licenses": ["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.6363636364, "max_line_length": 99, "alphanum_fraction": 0.4462151394, "num_tokens": 1111, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267694452331, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.6868339072059704}} {"text": "c program DRDMPVAL\nc Demonstrates DMPDRV, DMPINT, and DMPVAL.\nc>> 1997-05-29 DRDMPVAL Krogh Special code for C conversion.\nc>> 1996-05-28 DRDMPVAL Krogh Added external statement.\nc>> 1994-10-19 DRDMPVAL Krogh Changes to use M77CON\nc>> 1993-02-04 DRDMPVAL CLL\nc>> 1987-12-09 DRDMPVAL Lawson Initial Code.\nc ------------------------------------------------------------------\nc--D replaces \"?\": DR?MPVAL, ?MPDRV, ?MPINT, ?MPVAL\nc ------------------------------------------------------------------\nc++ Code for .C. is inactive\nc%% long int n;\nc++ End\n integer NQ, NR\n external DMPVAL\n double precision P(6),Q(7),R(6),Z,DMPVAL\n data P/ 5.D0, 2.D0, 4.D0, -4.D0, 12.D0, 16.D0 /\nc ------------------------------------------------------------------\n call DMPINT(P, 3,Q,NQ)\n call DMPDRV(Q,NQ,R,NR)\n Z = DMPVAL(Q,NQ,6.D0) - DMPVAL(Q,NQ,4.D0)\nc++ Code for ~.C. is active\n print '(21x,''P ='',2f4.0,2x,4f7.2/)', P\n print '('' INTEGRAL OF P. Q ='',2f4.0,2x,5f7.2/)', Q\n print '('' DERIVATIVE OF Q. R ='',2f4.0,2x,4f7.2/)', R\n print '('' DEFINITE INTEGRAL. Z ='',f20.8)', Z\nc++ Code for .C. is inactive\nc%% printf( \" P =%4.0f%4.0f\", p[0], p[1] );\nc%% for(n=2L; n < (long)(sizeof(p)/sizeof(p[1])); n++)\nc%% printf( \"%7.2f\", p[n] );\nc%% printf( \"\\n\" );\nc%% printf( \" INTEGRAL OF P. Q =%4.0f%4.0f\", q[0], q[1] );\nc%% for(n=2L; n < (long)(sizeof(q)/sizeof(q[1])); n++)\nc%% printf( \"%7.2f\", q[n] );\nc%% printf( \"\\n\" );\nc%% printf( \" DERIVATIVE OF Q. R =%4.0f%4.0f\", r[0], r[1] );\nc%% for(n=2L; n < (long)(sizeof(r)/sizeof(r[1])); n++)\nc%% printf( \"%7.2f\", r[n] );\nc%% printf( \"\\n\" );\nc%% printf( \" DEFINITE INTEGRAL. Z =%20.8f\\n\", z );\nc++ End\n stop\n end\n", "meta": {"hexsha": "bcef2a58b5f2dd94d1f5575c38eff41a0f063fc5", "size": 1820, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drdmpval.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drdmpval.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drdmpval.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 41.3636363636, "max_line_length": 72, "alphanum_fraction": 0.4615384615, "num_tokens": 707, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711604559846, "lm_q2_score": 0.8080672066194945, "lm_q1q2_score": 0.6868338213367976}} {"text": "program main\n use mpi\n implicit none\n integer :: ntasks, rank, ierr\n integer, allocatable :: status(:)\n integer, parameter :: n = 500\n integer :: i, j, k\n real(8), parameter :: pi = acos(-1.d0)\n real(8), parameter :: phi_l = 0.d0, phi_u = 2 * pi, rho_l = 0.d0, rho_u = 3.d0, z_l = -3.d0, z_u = 3.d0\n real(8), parameter :: d_phi = (phi_u - phi_l) / dble(n), d_rho = (rho_u - rho_l) / dble(n), d_z = (z_u - z_l) / dble(n)\n real(8) :: phi, rho, z, f, H\n real(8) :: integral_local = 0.d0, integral\n real :: start, finish, time\n\n\n ! initialize the MPI environment\n call MPI_INIT(ierr)\n call MPI_COMM_SIZE(MPI_COMM_WORLD, ntasks, ierr)\n call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)\n allocate(status(MPI_STATUS_SIZE))\n\n call CPU_TIME(start)\n\n phi = phi_l - d_phi / dble(2)\n do i = 1, n\n phi = phi + d_phi\n rho = rho_l - d_rho + d_rho / dble(ntasks) / dble(2) + d_rho / dble(ntasks) * dble(rank)\n do j = 1, n\n rho = rho + d_rho\n z = z_l - d_z / dble(2)\n do k = 1, n\n z = z + d_z\n call func(phi, rho, z, f)\n call inArea(phi, rho, z, H)\n integral_local = integral_local + f * H\n end do\n end do\n end do\n \n call MPI_REDUCE(integral_local, integral, 1, MPI_REAL8, MPI_SUM, 0, MPI_COMM_WORLD, ierr)\n\n if (rank == 0) then\n integral = (phi_u - phi_l) * (rho_u - rho_l) * (z_u - z_l) / dble(ntasks) / dble(n**3) * integral\n write(*,'(f10.5)') integral\n end if\n\n call CPU_TIME(finish)\n call MPI_REDUCE(finish - start, time, 1, MPI_REAL, MPI_SUM, 0, MPI_COMM_WORLD, ierr)\n if (rank == 0) then\n write(*,'(f10.5)') time\n end if\n\n call MPI_FINALIZE(ierr)\nend program main\n\nsubroutine func(phi, rho, z, f)\n ! the function to be integrated\n implicit none\n real(8), intent(in) :: phi, rho, z\n real(8), intent(out) :: f\n\n f = rho**3\nend subroutine func\n\nsubroutine inArea(phi, rho, z, H)\n ! judge whether the dot is in the integral area\n real(8), intent(in) :: phi, rho, z\n real(8), intent(out) :: H\n\n if ((z > -sqrt(9.d0 - rho**2)) .and. (z < sqrt(9.d0 - rho**2))) then\n H = 1.d0\n else\n H = 0.d0\n end if\nend subroutine inArea\n", "meta": {"hexsha": "0d29787ac14d8a755420043b62848f4acb5d8dcc", "size": 2292, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Week-11-Assignment-3/Assignment/2-conventional-integration-mpi.f90", "max_stars_repo_name": "Chen-Jialin/Computational-Physics-Exercises-and-Assignments", "max_stars_repo_head_hexsha": "592407af2e999b539473f473ca99186a12418b99", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-04-15T10:30:01.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T08:22:51.000Z", "max_issues_repo_path": "Week-11-Assignment-3/Assignment/2-conventional-integration-mpi.f90", "max_issues_repo_name": "Chen-Jialin/Computational-Physics-Exercises-and-Assignments", "max_issues_repo_head_hexsha": "592407af2e999b539473f473ca99186a12418b99", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Week-11-Assignment-3/Assignment/2-conventional-integration-mpi.f90", "max_forks_repo_name": "Chen-Jialin/Computational-Physics-Exercises-and-Assignments", "max_forks_repo_head_hexsha": "592407af2e999b539473f473ca99186a12418b99", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.1578947368, "max_line_length": 123, "alphanum_fraction": 0.5589005236, "num_tokens": 775, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.8006920092299293, "lm_q1q2_score": 0.6868080674378751}} {"text": "!---------------------------------------------------------------------- \n!---------------------------------------------------------------------- \n! Example 3: The A->B->C chemical reaction\n!---------------------------------------------------------------------- \n!---------------------------------------------------------------------- \n! \n!----------------------------------------------------------------------\n\n SUBROUTINE FUNC(NDIM,U,ICP,PAR,IJAC,F,DFDU,DFDP)\n!---------- ---- \n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: NDIM, IJAC, ICP(*)\n DOUBLE PRECISION, INTENT(IN) :: U(NDIM), PAR(*)\n DOUBLE PRECISION, INTENT(OUT) :: F(NDIM), DFDU(NDIM,*), DFDP(NDIM,*)\n\n DOUBLE PRECISION x1,x2,x3,d,alpha,beta,b,s,e,x1c\n\n x1 = U(1)\n x2 = U(2)\n x3 = U(3)\n\n d = PAR(1)\n alpha = PAR(2)\n beta = PAR(3)\n b = PAR(4)\n s = PAR(5)\n\n e = dexp(X3)\n x1c = 1 - X1\n\n F(1) = -x1 + d*x1c*e\n F(2) = -x2 + d*e*(x1c - s*x2)\n F(3) = -x3 - beta*x3 + d*b*e*(x1c + alpha*s*x2)\n\n IF(IJAC.EQ.0)RETURN \n\n DFDU(1,1) = -1.D0 - d*e\n DFDU(1,2) = 0.D0\n DFDU(1,3) = d*x1c*e\n\n DFDU(2,1) = -d*e\n DFDU(2,2) = -1.D0 - d*e*s\n DFDU(2,3) = d*e*(x1c - s*x2)\n\n DFDU(3,1) = -d*b*e\n DFDU(3,2) = d*b*e*alpha*s\n DFDU(3,3) = -1.D0 - beta + d*b*e*(x1c + alpha*s*x2)\n\n IF(IJAC.EQ.1)RETURN\n\n DFDP(1,1) = x1c*e\n DFDP(1,2) = 0.D0\n DFDP(1,3) = 0.D0\n DFDP(1,4) = 0.D0\n DFDP(1,5) = 0.D0\n DFDP(2,1) = e*(x1c - s*x2)\n DFDP(2,2) = 0.D0\n DFDP(2,3) = 0.D0\n DFDP(2,4) = 0.D0\n DFDP(2,5) = -d*e*x2\n DFDP(3,1) = b*e*(x1c + alpha*s*x2)\n DFDP(3,2) = d*b*e*s*x2\n DFDP(3,3) = -x3\n DFDP(3,4) = d*e*(x1c + alpha*s*x2)\n DFDP(3,5) = d*b*e*alpha*x2\n\n END SUBROUTINE FUNC\n\n SUBROUTINE STPNT(NDIM,U,PAR,T) \n!---------- ----- \n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: NDIM\n DOUBLE PRECISION, INTENT(IN) :: T\n DOUBLE PRECISION, INTENT(OUT) :: U(NDIM), PAR(*)\n\n PAR(1:5)=(/0.0,1.0,1.55,8.,0.04/)\n\n U(1:3)=0.\n\n END SUBROUTINE STPNT\n\n SUBROUTINE BCND \n END SUBROUTINE BCND\n\n SUBROUTINE ICND \n END SUBROUTINE ICND\n\n SUBROUTINE FOPT \n END SUBROUTINE FOPT\n\n SUBROUTINE PVLS\n END SUBROUTINE PVLS\n", "meta": {"hexsha": "36d39c22ec7db68e620bf23fc999ca693790295b", "size": 2102, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "07p/demos/abcb/abcb.f90", "max_stars_repo_name": "st970703/AUTO07P-Update-to-Python-3.0", "max_stars_repo_head_hexsha": "fb2d2aebf2127fa914064d01ed62c0acb5f6421c", "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": "07p/demos/abcb/abcb.f90", "max_issues_repo_name": "st970703/AUTO07P-Update-to-Python-3.0", "max_issues_repo_head_hexsha": "fb2d2aebf2127fa914064d01ed62c0acb5f6421c", "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": "07p/demos/abcb/abcb.f90", "max_forks_repo_name": "st970703/AUTO07P-Update-to-Python-3.0", "max_forks_repo_head_hexsha": "fb2d2aebf2127fa914064d01ed62c0acb5f6421c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.1263157895, "max_line_length": 72, "alphanum_fraction": 0.4410085633, "num_tokens": 887, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681195338727, "lm_q2_score": 0.8006919925839875, "lm_q1q2_score": 0.6868080648045964}} {"text": "subroutine compute_percentile(arr_unsorted,length,percentile,p_percentile)\nuse nrtype;use dimensions;use grids\nimplicit none\ninteger,intent(in)::length,percentile\nreal(SP),intent(in)::arr_unsorted(length)\nreal(SP),intent(out)::p_percentile\nreal(SP)::arr(length)\ninterface\n function kernel_d(u)\n use nrtype\n implicit none\n real(SP)::kernel_d\n real(SP)::u\n end function\nend interface\n\narr=arr_unsorted\ncall sort(arr,length)\np_percentile=arr(int(real(length)*real(percentile)/100.0_sp))\n\nend subroutine\n\nsubroutine compute_pdf(arr_unsorted,length,point,density_p)\n use nrtype;use dimensions;use grids\n implicit none\n integer,intent(in)::length\n real(SP),intent(in)::arr_unsorted(length),point\n real(SP),intent(out)::density_p\n real(SP)::arr(length)\n real(SP)::h_i(length),pdf_i(length)\n real(SP),dimension(nkk)::x\n real(SP)::h,std\n integer::x_l,x_l2\n character::pause_k\n interface\n function kernel_d(u)\n use nrtype\n implicit none\n real(SP)::kernel_d\n real(SP)::u\n end function\n end interface\n\n arr=arr_unsorted\n call sort(arr,length)\n\n !Optimal bandwidth\n std=sum((arr-sum(arr)/dble(length))**2)/(dble(length)-1)\n if (arr(int(real(length)/4.0_sp*3.0_sp))-arr(int(real(length)/4.0_sp))>0.0_sp) then\n h=0.9_sp*real(length)**(-1.0_sp/5.0_sp)*min(std,1.34_sp*(arr(int(real(length)/4.0_sp*3.0_sp))-arr(int(real(length)/4.0_sp))))\n else\n h=0.9_sp*real(length)**(-1.0_sp/5.0_sp)*std\n end if\n do x_l=1,length\n pdf_i(x_l)=0.0_sp\n do x_l2=1,length\n pdf_i(x_l)=pdf_i(x_l)+kernel_d((arr(x_l)-arr(x_l2))/h)\n end do\n pdf_i(x_l)=pdf_i(x_l)/real(length)/h\n end do\n !Variable bandwidth following Silverman \n h_i=log(pdf_i)-1.0/dble(length)*sum(log(pdf_i))\n h_i=exp(-0.5_sp*h_i)*h !sensitivity parameter\n density_p=0.0_sp\n do x_l2=1,length\n density_p=density_p+1.0_sp/h_i(x_l2)*kernel_d((point-arr(x_l2))/h_i(x_l2)) !sum(exp(-((x(x_l)-arr)/h_i)**2.0_sp/2.0_sp)/sqrt(2.0_sp*PI)/h_i)/real(length)\n end do\n density_p=density_p/real(length)\n \n if (isnan(density_p)) then\n print*,'error in compute_pdf'\n print*,point\n print*,arr\n read*,pause_k\n end if\n\n \nend subroutine\n \nfunction kernel_d(u)\n use nrtype\n implicit none\n real(SP)::kernel_d\n real(SP)::u\n \n !Epanechnikov\n if (abs(u)<=1.0_sp) then\n kernel_d=3.0_sp/4.0_sp*(1.0_sp-u**2.0_sp)\n else\n kernel_d=0.0_sp\n end if\n !Gaussian Kernel\n !kernel_d=1.0_sp/sqrt(2*pi)*exp(-0.5_sp*u**2)\n \nend function\n\n \n ", "meta": {"hexsha": "4c8e957d66c9a3c14d2b11578d6287e4305a03fd", "size": 2632, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "new_model/new_model/compute_median.f90", "max_stars_repo_name": "jesusbueren/new_model", "max_stars_repo_head_hexsha": "8d7b7bc02a36571c7dea843bbd1bcb3d865598e9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "new_model/new_model/compute_median.f90", "max_issues_repo_name": "jesusbueren/new_model", "max_issues_repo_head_hexsha": "8d7b7bc02a36571c7dea843bbd1bcb3d865598e9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "new_model/new_model/compute_median.f90", "max_forks_repo_name": "jesusbueren/new_model", "max_forks_repo_head_hexsha": "8d7b7bc02a36571c7dea843bbd1bcb3d865598e9", "max_forks_repo_licenses": ["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.8571428571, "max_line_length": 162, "alphanum_fraction": 0.6458966565, "num_tokens": 845, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418241572635, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6867926391344592}} {"text": "module initial_mod\n\n use real_type_mod\n use parameters_mod\n use variables_mod\n use conversion_mod\n\n implicit none\n\ncontains\n\n subroutine initial(x, n_up)\n\n real(kind=wp), dimension(1-gz:np+gz), intent(out) :: x\n real(kind=wp), dimension(NF, NV, 1-gz:np+gz), intent(out) :: n_up\n\n real(kind=wp) :: n, v, w\n real(kind=wp) :: pi = 4.d0 * atan(1.d0)\n\n integer :: i, f\n\n do i = 1-gz, np+gz\n x(i) = (dble(i) - 0.5_wp) * dx + xmin\n\n!!$ Primitive variables; simple trig functions for now\n!!$ This is essentially random - something more useful should be found\n\n do f = 1, NF\n\n select case (perturbation_type)\n\n case ('trig')\n\n n = initial_n(f) * (1.0_wp + &\n initial_ptbn_n(f) * sin( pi * initial_period_n(f) * &\n (x(i) - initial_phase_n(f)) ) )\n v = initial_v(f) + &\n initial_ptbn_v(f) * sin( pi * initial_period_v(f) * &\n (x(i) - initial_phase_v(f)) ) \n\n case ('gaussian')\n\n n = initial_n(f) * (1.0_wp + &\n initial_ptbn_n(f) * &\n exp(-(x(i) - 0.5_wp * (xmin + xmax))**2 / 0.05_wp**2) )\n v = initial_v(f) + initial_ptbn_v(f) * &\n exp(-(x(i) - 0.5_wp * (xmin + xmax))**2 / 0.15_wp**2) \n\n case ('doublegaussian')\n\n n = initial_n(f) * (1.0_wp + &\n initial_ptbn_n(f) * &\n exp(-(x(i) - &\n 1.0_wp / 3.0_wp * (xmin + xmax))**2 / 0.075_wp**2) + &\n initial_ptbn_n(f) * &\n exp(-(x(i) - &\n 2.0_wp / 3.0_wp * (xmin + xmax))**2 / 0.075_wp**2) )\n v = initial_v(f) + initial_ptbn_v(f) * &\n exp(-(x(i) - &\n 1.0_wp / 3.0_wp * (xmin + xmax))**2 / 0.075_wp**2) + &\n initial_ptbn_v(f) * &\n exp(-(x(i) - &\n 2.0_wp / 3.0_wp * (xmin + xmax))**2 / 0.075_wp**2) \n\n case default\n\n write(*,*) &\n 'Parameter ''perturbation_type'' takes an unknown value ', &\n perturbation_type\n stop\n\n end select\n\n w = 1.0_wp / sqrt(1.0_wp - v**2)\n\n n_up(f, 1, i) = n * w\n n_up(f, 2, i) = n * w * v\n \n end do\n \n end do\n\n end subroutine initial\n \nend module initial_mod\n", "meta": {"hexsha": "8c84906797341ba86a03f2f16d49af0f9a5bcb8f", "size": 2426, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "initial_mod.f90", "max_stars_repo_name": "IanHawke/MultiFluid1d", "max_stars_repo_head_hexsha": "010847acd0ae8596936c554d0dfc7ab0722a1f78", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "initial_mod.f90", "max_issues_repo_name": "IanHawke/MultiFluid1d", "max_issues_repo_head_hexsha": "010847acd0ae8596936c554d0dfc7ab0722a1f78", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "initial_mod.f90", "max_forks_repo_name": "IanHawke/MultiFluid1d", "max_forks_repo_head_hexsha": "010847acd0ae8596936c554d0dfc7ab0722a1f78", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.2093023256, "max_line_length": 77, "alphanum_fraction": 0.44641385, "num_tokens": 735, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418220680099, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6867926375817928}} {"text": "\tFUNCTION PS_BVPD ( datain, nparm, clev, ivcord )\nC************************************************************************\nC* PS_BVPD\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes the Brunt-Vaisala Period.\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PS_BVPD ( DATAIN, NPARM, CLEV, IVCORD )\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tDATAIN\t\tREAL\t\tStation data\t\t\t*\nC*\tNPARM\t\tINTEGER\t\tNumber of data set parameters\t*\nC*\tCLEV\t\tREAL\t\tVertical level\t\t\t*\nC*\tIVCORD\t\tINTEGER \tVertical coordinate number\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPS_BVPD\t\tREAL\t\tBrunt-Vaisala Period\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* K. Brill /NMC\t 7/90\t\t\t\t\t\t*\nC* T. Lee/GSC\t\t 8/97\tChanged default depth to RMISSD \t*\nC************************************************************************\n\tINCLUDE\t\t'GEMPRM.PRM'\nC*\n\tREAL\t\tstndb (10), stndt (10), stndl (10)\nC*\n\tINCLUDE\t\t'ERMISS.FNC'\nC-----------------------------------------------------------------------------\n\tPS_BVPD = RMISSD\nC\nC*\tGet depth information.\nC\n\tdfdpth = RMISSD\n\tidfcrd = 3\n\tCALL PC_DPTH ( datain, nparm, clev, ivcord, dfdpth, idfcrd, 1,\n +\t\t\tdepth, idcord, stndl, stndb, stndt, ier )\nC\nC*\tCheck for missing data.\nC\t\n\tIF ( ( ier .ne. 0 ) .or. ERMISS ( stndt (1) ) .or. \n +\t\tERMISS ( stndb (1) ) .or. ERMISS ( stndt (2) ) .or.\n +\t\tERMISS ( stndb (2) ) .or. ERMISS ( stndt (6) ) .or.\n +\t\tERMISS ( stndb (6) ) ) RETURN\n\tdepth = stndt (6) - stndb (6)\n\tIF ( depth .eq. 0.0 ) RETURN\nC*\n\tthtop = PR_THTA ( stndt (2), stndt (1) )\n\tthbot = PR_THTA ( stndb (2), stndb (1) )\n theta = .5 * ( thtop + thbot )\n bvfsqd = ( GRAVTY / theta ) * ( thtop - thbot ) / depth\n\tIF ( bvfsqd .le. 0.0 ) RETURN\nC*\n\tPS_BVPD = 2. * PI / SQRT ( bvfsqd )\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "5430b2dd0ce84d4e654c8de7da405403cd293106", "size": 1718, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/ps/psbvpd.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/ps/psbvpd.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/ps/psbvpd.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.6785714286, "max_line_length": 78, "alphanum_fraction": 0.4959254948, "num_tokens": 660, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418199787564, "lm_q2_score": 0.7431680086124812, "lm_q1q2_score": 0.6867926360291265}} {"text": "!##############################################################################\n!# Tutorial 005a: Basic math\n!##############################################################################\n\nmodule tutorial005a\n\n ! Include basic Feat-2 modules\n use fsystem\n use genoutput\n use mprimitives\n\n implicit none\n private\n\n public :: start_tutorial005a\n\ncontains\n\n ! ***************************************************************************\n\n subroutine start_tutorial005a\n\n ! Declare some variables\n real(DP) :: dval1, dval2, dval3\n real(DP), dimension(4) :: Dcoeff\n\n ! Print a message\n call output_lbrk()\n call output_separator (OU_SEP_STAR)\n call output_line (\"This is FEAT-2. Tutorial 005a\")\n call output_separator (OU_SEP_MINUS)\n\n ! =================================\n ! Kronecker Symbol\n ! =================================\n\n call output_line (\"kronecker(3,5) = \" // trim(sys_siL(mprim_kronecker(3,5),10)) )\n call output_line (\"kronecker(5,5) = \" // trim(sys_siL(mprim_kronecker(5,5),10)) )\n\n ! =================================\n ! Signum\n ! =================================\n\n call output_line (\"signum(-5) = \" // trim(sys_siL(mprim_signum(-5_I32),10)) )\n call output_line (\"signum( 0) = \" // trim(sys_siL(mprim_signum( 0_I32),10)) )\n call output_line (\"signum( 2) = \" // trim(sys_siL(mprim_signum( 2_I32),10)) )\n\n ! =================================\n ! Linear rescaling\n ! =================================\n\n ! Linear interpolation of [0,1] to [5,7]\n call mprim_linearRescale(0.00_DP,0.0_DP,1.0_DP,5.0_DP,7.0_DP,dval1)\n call mprim_linearRescale(0.25_DP,0.0_DP,1.0_DP,5.0_DP,7.0_DP,dval2)\n call mprim_linearRescale(1.00_DP,0.0_DP,1.0_DP,5.0_DP,7.0_DP,dval3)\n\n call output_line (\"linrescale(0.00,[0,1],[5,7]) = \" // trim(sys_sdL(dval1,10)) )\n call output_line (\"linrescale(0.25,[0,1],[5,7]) = \" // trim(sys_sdL(dval2,10)) )\n call output_line (\"linrescale(1.00,[0,1],[5,7]) = \" // trim(sys_sdL(dval3,10)) )\n\n ! =================================\n ! Quadratic interpolation\n ! =================================\n\n ! Quadratic interpolation, i.e. evaluate a quadratic\n ! polynomial p with p(-1)=2, p(0)=0, p(1)=2\n call mprim_quadraticInterpolation (-1.0_DP,2.0_DP,0.0_DP,2.0_DP,dval1)\n call mprim_quadraticInterpolation ( 0.0_DP,2.0_DP,0.0_DP,2.0_DP,dval2)\n call mprim_quadraticInterpolation ( 0.5_DP,2.0_DP,0.0_DP,2.0_DP,dval3)\n\n call output_line (\"quadinterpol(-1.0,[2,0,2]) = \" // trim(sys_sdL(dval1,10)) )\n call output_line (\"quadinterpol( 0.0,[2,0,2]) = \" // trim(sys_sdL(dval2,10)) )\n call output_line (\"quadinterpol( 0.5,[2,0,2]) = \" // trim(sys_sdL(dval3,10)) )\n\n ! =================================\n ! Parabolic profile\n ! =================================\n\n ! This is a quadratic polynomial p with p(0)=p(len)=0, p(mid)=max.\n dval1 = mprim_getParabolicProfile (0.5_DP,2.0_DP,10.0_DP)\n dval2 = mprim_getParabolicProfile (1.0_DP,2.0_DP,10.0_DP)\n dval3 = mprim_getParabolicProfile (1.5_DP,2.0_DP,10.0_DP)\n\n call output_line (\"parprofile(0.5,len=2,max=10) = \" // trim(sys_sdL(dval1,10)) )\n call output_line (\"parprofile(1.0,len=2,max=10) = \" // trim(sys_sdL(dval2,10)) )\n call output_line (\"parprofile(1.5,len=2,max=10) = \" // trim(sys_sdL(dval3,10)) )\n\n ! =================================\n ! Conversion of polar coordinates\n ! in cartesian coordinates\n ! =================================\n\n call mprim_polarToCartesian(0.5_DP,0.0_DP,dval1,dval2)\n call output_line (\"polar(0.5,0.0 ) = \" // trim(sys_sdL(dval1,10)) // \",\" &\n // trim(sys_sdL(dval2,10)))\n\n call mprim_polarToCartesian(0.5_DP,0.25_DP*SYS_PI,dval1,dval2)\n call output_line (\"polar(0.5,0.25 Pi) = \" // trim(sys_sdL(dval1,10)) // \",\" &\n // trim(sys_sdL(dval2,10)))\n\n call mprim_polarToCartesian(0.5_DP,-0.75*SYS_PI,dval1,dval2)\n call output_line (\"polar(0.5,-0.75 Pi) = \" // trim(sys_sdL(dval1,10)) // \",\" &\n // trim(sys_sdL(dval2,10)))\n\n ! =================================\n ! Conversion of cartesian coordinates\n ! in polar coordinates\n ! =================================\n\n call mprim_cartesianToPolar(0.5_DP,0.0_DP,dval1,dval2)\n call output_line (\"cartesian(0.5,0.0) = \" // trim(sys_sdL(dval1,10)) // \",\" &\n // trim(sys_sdL(dval2,10)))\n\n call mprim_cartesianToPolar(0.25_DP*sqrt(2.0_DP),0.25_DP*sqrt(2.0_DP),dval1,dval2)\n call output_line (\"cartesian(0.3535,0.3535) = \" // trim(sys_sdL(dval1,10)) // \",\" &\n // trim(sys_sdL(dval2,10)))\n\n call mprim_cartesianToPolar(-0.25_DP*sqrt(2.0_DP),-0.25_DP*sqrt(2.0_DP),dval1,dval2)\n call output_line (\"cartesian(-0.3535,-0.3535) = \" // trim(sys_sdL(dval1,10)) // \",\" &\n // trim(sys_sdL(dval2,10)))\n\n ! =================================\n ! Horner scheme\n ! =================================\n\n ! Initialise a cubic polynomial: p(x,y) = x^3 - 2x^2 - 3*x + 4\n Dcoeff(:) = (/ 4.0_DP, 3.0_DP, -2.0_DP, 1.0_DP /)\n\n ! Get the function value as well as 1st and 2nd derivative in x=2.\n dval1 = mprim_horner (2.0_DP,Dcoeff)\n dval2 = mprim_hornerd1 (2.0_DP,Dcoeff)\n dval3 = mprim_hornerd2 (2.0_DP,Dcoeff)\n\n call output_line (\"p (2.0) = \" // trim(sys_sdL(dval1,10)) )\n call output_line (\"p' (2.0) = \" // trim(sys_sdL(dval2,10)) )\n call output_line (\"p''(2.0) = \" // trim(sys_sdL(dval3,10)) )\n\n end subroutine\n\nend module\n", "meta": {"hexsha": "47a95bd8c32e1d87c6dbc0fe8b134799db1cfff8", "size": 5683, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tutorials/tutorial01/src/tutorial005a.f90", "max_stars_repo_name": "trmcnealy/Featflow2", "max_stars_repo_head_hexsha": "4af17507bc2d80396bf8ea85c9e30e9e4d2383df", "max_stars_repo_licenses": ["Intel", "Unlicense"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2017-08-02T11:51:34.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-10T14:14:21.000Z", "max_issues_repo_path": "tutorials/tutorial01/src/tutorial005a.f90", "max_issues_repo_name": "tudo-math-ls3/FeatFlow2", "max_issues_repo_head_hexsha": "56159aff28f161aca513bc7c5e2014a2d11ff1b3", "max_issues_repo_licenses": ["Intel", "Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tutorials/tutorial01/src/tutorial005a.f90", "max_forks_repo_name": "tudo-math-ls3/FeatFlow2", "max_forks_repo_head_hexsha": "56159aff28f161aca513bc7c5e2014a2d11ff1b3", "max_forks_repo_licenses": ["Intel", "Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.304964539, "max_line_length": 89, "alphanum_fraction": 0.5178602851, "num_tokens": 1800, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418220680099, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6867926323249516}} {"text": "program test\nuse iso_fortran_env, only: real64, real32\n!use f95_precision\nuse blas95\nuse lapack95\nimplicit none\ninteger, parameter :: n = 1000, pr = real64\nreal(pr) :: a(n,n), b(n,n), c(n,n)\nreal(pr) :: x(n), sigma \ninteger :: i, j, info, ipiv(n)\n\n! construct a symmetric positive definite matrix\ncall random_number(x)\nx = n*x\nsigma = 1.0\ndo i = 1, n\n a(i,i) = 1.0\nend do\ndo i = 1, n-1\n do j = i+1, n\n a(i,j) = exp( -(x(i)-x(j))**2/(2*sigma**2) )\n a(j,i) = a(i,j) \n end do\nend do\n\n! b is going to be inverse of a\nb = a\n\n! use lapack for inversion \ncall getrf(b,ipiv,info)\nif( info/=0 ) call sysexit('LU decompositions not successful')\ncall getri(b,ipiv,info)\nif( info/=0 ) call sysexit('Inversion not successful')\n\n! c = I\n!c = matmul( a, b )\ncall gemm( a, b, c )\n\n! check if c = I\ndo i = 1, n\n c(i,i) = c(i,i) - 1.0\nend do\nwrite(*,*) 'residual:', sum( c**2 )/n**2\n\ncontains\n\n subroutine show_matrix(a)\n implicit none\n real a(:,:)\n integer i\n do i = 1, size(a,1)\n write(*,*) ( a(i,j), j=1,size(a,2) )\n end do\n end subroutine\n\n subroutine sysexit(input)\n class(*), intent(in) :: input\n select type(input)\n type is (character(len=*))\n print*, input\n end select\n stop\n end subroutine\n\nend program\n", "meta": {"hexsha": "0d752c4228b3b61e73f27697b3e9aa78364866d1", "size": 1366, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "lapack/lapack_matrix_inversion.f08", "max_stars_repo_name": "amirhajibabaei/fortran-examples", "max_stars_repo_head_hexsha": "bddc74d5dcd41e725c7bbcfaf856448153ae1464", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lapack/lapack_matrix_inversion.f08", "max_issues_repo_name": "amirhajibabaei/fortran-examples", "max_issues_repo_head_hexsha": "bddc74d5dcd41e725c7bbcfaf856448153ae1464", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lapack/lapack_matrix_inversion.f08", "max_forks_repo_name": "amirhajibabaei/fortran-examples", "max_forks_repo_head_hexsha": "bddc74d5dcd41e725c7bbcfaf856448153ae1464", "max_forks_repo_licenses": ["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.696969697, "max_line_length": 62, "alphanum_fraction": 0.5512445095, "num_tokens": 463, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418158002493, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6867926276669525}} {"text": "program main\n use timers\n type(TimerType) :: seriesTime,monteTime,totalTime\n \n integer npoints,nthreads,maxthreads,i,ierr\n parameter (npoints=300000,maxthreads=16)\n complex*16 c(npoints)\n real*8 r1,r2,halfpi,err1,area,err2\n real rand\n integer numinside,lnuminside(maxthreads)\n integer omp_get_num_threads\n external monte\n external omp_set_num_threads,omp_get_num_threads\n\n call TimerCreate(seriesTime,\"series\")\n call TimerCreate(monteTime,\"monte\")\n call TimerCreate(totalTime,\"Series+monte\") \n\n! GENERATE RANDOM NUMBERS\n\n call srand(54321)\n do i=1,npoints\n r1=rand()\n r2=rand()\n c(i)=CMPLX(-2.0+2.5*r1,1.125*r2)\n end do\n\n call TimerOn(totalTime)\n\n! CALCULATE PI/2 FROM GREGORY'S FORMULA\n\n call TimerOn(seriesTime)\n call series(halfpi,err1)\n call TimerOff(seriesTime)\n\n! CALCULATE AREA OF MANDELBROT SET BY MONTE CARLO SAMPLING\n\n call TimerOn(monteTime)\n! INVOKE monte in parallel\n\n!$omp parallel\n\n! GET NUMBER OF THREADS BEING USED\n nthreads = omp_get_num_threads()\n\n call monte(c,lnuminside)\n!$omp end parallel\n\n! SUM UP CONTRIBUTIONS FROM EACH THREAD \n numinside = 0\n do i=1,nthreads\n numinside = numinside + lnuminside(i)\n end do\n\n call TimerOff(monteTime)\n call TimerOff(totalTime)\n\n! OUTPUT RESULTS\n\n area = 2.0*2.5*1.125 * real(numinside)/real(npoints)\n err2 = area/sqrt(real(npoints))\n print *, \"Pi/2 = \", halfpi,\" +/- \",err1\n print *, \"Area of Mandelbrot set = \",area,\" +/- \",err2\n\n! OUTPUT TIMING DATA\n\n call TimerPrint(seriesTime)\n call TimerPrint(monteTime)\n call TimerPrint(totalTime)\n\n stop\nend program main\n\nsubroutine series(halfpi,err)\n \n real*8 halfpi,err,sum\n integer sign,terms,denom,i\n parameter (terms = 100000000)\n\n sum=0.0d0\n sign=1\n denom=1\n\n do i=1,terms\n sum=sum + sign*(1.0d0/denom)\n sign=(-sign)\n denom=denom + 2\n end do\n\n halfpi = 2.0d0 * sum \n err = 2.0d0/terms\n return\nend subroutine series\n\t\nsubroutine monte(c,lnuminside)\n\n integer npoints,maxiter,i,j,num,slice,myid,ilo,ihi\n integer nthreads,maxthreads\n parameter (npoints=300000,maxiter=10000,maxthreads=16)\n complex*16 c(npoints),z\n integer lnuminside(maxthreads)\n integer omp_get_num_threads,omp_get_thread_num\n external omp_get_num_threads,omp_get_thread_num\n\n nthreads = omp_get_num_threads()\n slice = (npoints+nthreads-1)/nthreads\n myid = omp_get_thread_num()\n ilo = slice * myid + 1\n ihi = min(npoints,(myid+1)*slice)\n\n num=0\n do i=ilo,ihi\n z=(0.0,0.0)\n do j=1,maxiter\n z = z*z +c(i)\t \n if (abs(z).gt.2.0) goto 10\n end do\n num = num +1\n10 continue\n end do\n\n lnuminside(myid+1) = num\n\n return\nend subroutine monte\n\n\n\n", "meta": {"hexsha": "99fb2cfc50f5c529cafc9cd023df1e39438c61e6", "size": 2642, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/lab2/mandel_par.f90", "max_stars_repo_name": "arturocastro/SOR", "max_stars_repo_head_hexsha": "eb63341ca4082cb8f79f256d71c706912bc2852c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-09-24T18:13:05.000Z", "max_stars_repo_stars_event_max_datetime": "2017-09-24T18:13:05.000Z", "max_issues_repo_path": "source/lab2/mandel_par.f90", "max_issues_repo_name": "arturocastro/SOR", "max_issues_repo_head_hexsha": "eb63341ca4082cb8f79f256d71c706912bc2852c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/lab2/mandel_par.f90", "max_forks_repo_name": "arturocastro/SOR", "max_forks_repo_head_hexsha": "eb63341ca4082cb8f79f256d71c706912bc2852c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.480620155, "max_line_length": 59, "alphanum_fraction": 0.700984103, "num_tokens": 879, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336202, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6867917202723575}} {"text": "!\n! The Great Computer Language Shootout\n! http://shootout.alioth.debian.org/\n!\n! Contributed by Sebastien Loisel\n!\n! OVERVIEW: In this test, we solve an ordinary differential equation\n! u'=f(t,u)\n! using the Trapezoid numerical method, which can be written as\n! (u[k+1]-u[k])=(f(t[k],u[k])+f(t[k]+dt,u[k+1]))*dt/2,\n! where t[k], u[k], dt and the function f are known and u[k+1] is the\n! unknown.\n!\n! Since u[k+1] appears on both sides of the equation, we use an iterative\n! solver called the newton iteration to compute u[k+1]. The newton iteration\n! computes the solution to\n! h(x)=0\n! where h is a known function and x is the unknown 0 of h, using the method\n! x[k+1]=x[k]-f(x[k])/f'(x[k]).\n! Here, f' denotes the derivative of f.\n!\n! This version uses the traditional central-difference approximation to f'\n!\n! Summary of classes:\n!\n! fl -- low precision floating point type\n! mycomplex -- complex numbers whose real and imaginary parts can be fl\n! trapezoid_method_rooter -- implements the function that the trapezoid method\n! must solve\n\nprogram implicitode\n use function_params\n implicit none\n\n real*8, external :: mysqrt, rat, simple\n real*8 :: res\n type(fdata) :: gparams\n type(fdata) :: tparams\n character(len=33) :: str\n real*8 :: x, dt, y0, r, u_t0, t1, t0\n integer :: i,n,ns\n character(len=8) :: argv\n\n call getarg(1,argv)\n if (len(trim(argv)) == 0) then\n n = 50\n else\n read(argv,*) n\n end if\n x = rat(0.25d0)\n res = D(rat,0.25d0)\n write(*,'(2(a,es27.20e2))') 'rational_taylor_series: ',x,' ',res\n\n gparams%a = 2.0d0\n x = newton(mysqrt,gparams,1.0d0,10)\n write(*,'(2(a,es27.20e2))') 'newton-sqrt_2:',x\n x = newton(rat,gparams,-1.0d0,6)\n res = rat(x)\n write(*,'(a,es27.20e2)') 'newton-rat: ',x\n !\n ! Simple case that enables easy verification of the trapezoidal implementation:\n !\n ! u' = 1/(2u) with u(1) = 2\n !\n ! => u = sqrt(t+3)\n !\n ! so the test is to ensure u(6) = 3\n !\n t0 = 1.0d0 ! Initial value of the parameter\n u_t0 = 2.0d0 ! Value of u at t0: u(1) = 2\n t1 = 6.0d0 ! Final (target) value of parameter t\n dt = (t1 - t0)/n ! Parameter step size\n call trapezoidal(simple,gparams,t0,dt,u_t0,n,r)\n write(*,'(a,es27.20e2)') 'u(6) = ',r\n call rk4(simple,gparams,t0,dt,u_t0,n,r)\n write(*,'(a,es27.20e2)') 'u(6) = ',r\n\n x = 1.0d0\n dt = 0.02d0\n y0 = 1.0d0/(4*n)\n! call integrate_functions(x,dt,y0,4*n)\n\ncontains\n \n subroutine integrate_functions(t0,dt,y0,n)\n real*8, intent(in) :: t0\n real*8, intent(in) :: dt\n real*8, intent(in) :: y0\n integer, intent(in) :: n\n call trapezoidal(mysqrt,gparams,x,dt,y0,n,r)\n print *, 'trap 1: ',r\n call rk4(mysqrt,gparams,x,dt,y0,n,r)\n print *, 'rk4 1: ',r\n call trapezoidal(rat,gparams,x,dt,y0,n,r)\n print *, 'i2: ',r\n end subroutine integrate_functions\n\n subroutine trapezoidal(g,gparams,t0,dt,y0,numsteps,r)\n real*8, external :: g\n type(fdata), intent(in) :: gparams\n real*8, intent(in) :: t0\n real*8, intent(in) :: dt\n real*8, intent(in) :: y0\n integer, intent(in) :: numsteps\n real*8, intent(inout) :: r\n\n real*8 :: y, y1\n integer :: i, j\n real*8 :: t1\n ! (u[k+1]-u[k])=(f(t[k],u[k])+f(t[k]+dt,u[k+1]))*dt/2,\n y = y0\n do i=1,numsteps\n t1 = t0 + i*dt\n y1 = y\n do j=1,10\n y1 = y1 - ((g(y,gparams) + g(y1,gparams))*(dt/2.0d0) + y - y1)/(D(g,y1,gparams)*(dt/2.0d0) - 1.0d0)\n end do\n y = y1\n end do\n r = y\n end subroutine trapezoidal\n\n subroutine rk4(g,gparams,t0,dt,y0,numsteps,r)\n real*8, external :: g\n type(fdata), intent(in) :: gparams\n real*8, intent(in) :: t0\n real*8, intent(in) :: dt\n real*8, intent(in) :: y0\n integer, intent(in) :: numsteps\n real*8, intent(inout) :: r\n\n real*8 :: y, y1\n integer :: i, j\n real*8 :: t1\n real*8 :: k1, k2, k3, k4\n !\n ! u[k+1] = u[k] + k1/6 + k2/3 + k3/3 + k4/6\n !\n ! k1 = h*f(t[n] ,u[k])\n !\n ! k2 = h*f(t[n]+h/2,u[n]+k1/2)\n !\n ! k3 = h*f(t[n]+h/2,u[n]+k2/2)\n !\n ! k4 = h*f(t[n]+h ,u[n]+k3)\n !\n y = y0\n do i=1,numsteps\n t1 = t0 + i*dt\n k1 = dt*g(y,gparams)\n k2 = dt*g(y+0.5d0*k1,gparams)\n k3 = dt*g(y+0.5d0*k2,gparams)\n k4 = dt*g(y,k3,gparams)\n y1 = y + (k1 + 2*k2 + 2*k3 + k4)/6\n y = y1\n end do\n r = y\n\n end subroutine rk4\n\n subroutine irk4(g,gparams,t0,dt,y0,numsteps,r)\n ! Hammer-Hollingsworth\n real*8, external :: g\n type(fdata), intent(in) :: gparams\n real*8, intent(in) :: t0\n real*8, intent(in) :: dt\n real*8, intent(in) :: y0\n integer, intent(in) :: numsteps\n real*8, intent(inout) :: r\n\n real*8 :: y, y1\n integer :: i, j\n real*8 :: t1\n real*8 :: k1, k2, k3, k4, c1, c2, b1, b2\n real*8, dimension(2,2) :: A\n real*8, dimension(2) :: b, c, k, ks\n !\n ! u[k+1] = u[k] + h * _b_ . _k_\n !\n ! k[i] = f(t0+c[i]*h, y0 + A[i]*_k_)\n !\n c = (/ (3-sqrt(3.0d0))/6 , (3+sqrt(3.0d0))/6 /)\n b = (/0.5d0 , 0.5d0/)\n A = reshape((/0.25d0,0.25d0-sqrt(3.0d0)/6,0.25d0+sqrt(3.0d0)/6,0.25d0/),(/2,2/))\n y = y0\n do i=1,numsteps\n t1 = t0 + i*dt\n do j=1,10\n\n end do\n y1 = y + dt*dot_product(b,k)\n y = y1\n end do\n r = y\n\n end subroutine irk4\n\n real*8 function newton(g,params,x,n)\n real*8, external :: g\n real*8, intent(in) :: x\n type(fdata), optional, intent(in) :: params\n integer, optional, intent(in) :: n\n integer :: i\n if (present(n)) then\n ns = n\n else\n ns = 10\n end if\n newton = x\n do i=1,ns\n newton = newton - g(newton,params)/D(g,newton,params)\n end do\n end function newton\n\n real*8 function D(g,x,params,step)\n ! Calculate the central-difference approximation to g'(x)\n real*8, external :: g\n real*8, intent(in) :: x\n type(fdata), intent(in), optional :: params\n real*8, intent(in), optional :: step\n real*8, parameter :: fstep = 1.0d-6\n real*8 :: lstep\n if (present(step)) then\n lstep = step\n else\n lstep = fstep\n end if\n D = (g(x+0.5d0*lstep,params) - g(x-0.5d0*lstep,params))/lstep\n end function D\n\nend program implicitode\n\n\nreal*8 function rat(x, params)\n use function_params\n\n real*8, intent(in) :: x\n type(fdata), intent(in), optional :: params\n\n rat = (1 + 2*x + 3*x**2 + 7*x**6 + 5*x**11) / (2 + 5*x - 6*x**3 - 3*x**7)\n\nend function rat\n\nreal*8 function mysqrt(x, params)\n use function_params\n\n real*8, intent(in) :: x\n type(fdata), intent(in), optional :: params\n mysqrt = x*x - params%a\nend function mysqrt\n\nreal*8 function simple(x, params)\n use function_params\n\n real*8, intent(in) :: x\n type(fdata), intent(in), optional :: params\n\n simple = 0.5d0/x\nend function simple\n", "meta": {"hexsha": "0bd6aa68d2aac40010c059ea329ef85cb3af05fe", "size": 7244, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "bench/implicitode/implicitode_trad.f90", "max_stars_repo_name": "kragen/shootout", "max_stars_repo_head_hexsha": "71aa4ec4cd15940c59f1a1bb71ac1ff1572a55c2", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2015-04-02T01:10:35.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-10T05:39:38.000Z", "max_issues_repo_path": "bench/implicitode/implicitode_trad.f90", "max_issues_repo_name": "ym222bs/shootout", "max_issues_repo_head_hexsha": "71aa4ec4cd15940c59f1a1bb71ac1ff1572a55c2", "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": "bench/implicitode/implicitode_trad.f90", "max_forks_repo_name": "ym222bs/shootout", "max_forks_repo_head_hexsha": "71aa4ec4cd15940c59f1a1bb71ac1ff1572a55c2", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2015-05-03T20:27:15.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-16T23:03:52.000Z", "avg_line_length": 27.8615384615, "max_line_length": 109, "alphanum_fraction": 0.5313362783, "num_tokens": 2671, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513648201266, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6867917139017802}} {"text": "program main\n use plantfem\n implicit none\n\n type(Random_) :: random\n type(IO_) :: f,z\n integer(int32) :: i, n, nn,count\n real(real64) :: g_n, g_nn, period, period_list(1000)\n real(real64),allocatable :: histogram(:,:)\n\n ! get random wave & zero crossing\n call f%open(\"random_wave.csv\")\n \n g_n = -1.0d0\n g_nn= 0.0d0\n n = 0\n nn = 0\n period = 0.0d0 \n count=0\n period_list(:) = 0.0d0\n do i=1,1000\n g_nn = random%Gauss(mu=0.0d0, sigma=1.0d0) \n !g_nn = random%ChiSquared(k=1.0d0) \n \n if( g_n*g_nn < 0.0d0 )then\n count=count+1\n nn = i\n period = dble(nn) - dble(n)\n period_list(count) = period\n n = nn\n g_n = g_nn\n endif\n \n call f%write( trim(str(dble(i))) //\", \"//str(g_nn) )\n \n enddo\n call f%close()\n\n ! get histogram\n histogram = random%histogram(list=period_list,division=20)\n call z%open(\"zero_cross.csv\")\n \n do i=1,size(histogram,1)\n write(z%fh,*) histogram(i,1),histogram(i,2)\n enddo\n \n call z%close()\n \nend program main", "meta": {"hexsha": "df49f4baac91e474436156a5875ed339b6a4a518", "size": 1136, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/playon_std/random_wave_zero_crossing.f90", "max_stars_repo_name": "kazulagi/plantfem_min", "max_stars_repo_head_hexsha": "ba7398c031636644aef8acb5a0dad7f9b99fcb92", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2020-06-21T08:21:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-13T04:28:30.000Z", "max_issues_repo_path": "Tutorial/std/random_wave_zero_crossing.f90", "max_issues_repo_name": "kazulagi/plantFEM_binary", "max_issues_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-05-08T05:20:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T05:39:29.000Z", "max_forks_repo_path": "Tutorial/std/random_wave_zero_crossing.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": 23.1836734694, "max_line_length": 63, "alphanum_fraction": 0.5281690141, "num_tokens": 377, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476793890012, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6867681671779418}} {"text": "program reductions\n\n implicit none\n real(kind=4), dimension(10) :: v\n integer :: i\n\n do i = 1, size(v)\n v(i) = size(v) + 1 - i\n end do\n\n write(*,*) \"shape of original v: \", shape(v);\n write(*,*) \"original v = \", v\n v = reshape((/1,2,3,4,5,6,7,8,9,10/), (/10/))\n write(*,*) \"shape of v reshaped: \", shape(v);\n write(*,*) \"v reshaped = \", v\n\n ! all, any, count\n print *, all(v > 5)\n print *, all(v > 5, 1)\n print *, any(v > 50)\n print *, any(v > 50, 1)\n print *, count(v > 5)\n print *, count(v > 5, 1)\n\n ! maxval, minval\n print *, maxval(v)\n print *, maxval(v, 1)\n print *, maxval(v, v > 5)\n print *, maxval(v, 1, v > 5)\n print *, minval(v)\n print *, minval(v, 1)\n print *, minval(v, v > 5)\n print *, minval(v, 1, v > 5)\n\n ! product, sum\n print *, product(v)\n print *, product(v, 1)\n print *, product(v, v > 5)\n print *, product(v, 1, v > 5)\n print *, sum(v)\n print *, sum(v, 1)\n print *, sum(v, v > 5)\n print *, sum(v, 1, v > 5)\n\nend program reductions\n", "meta": {"hexsha": "1350c6df8abbeb7080f857e7c16940cd228a84b0", "size": 1084, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "arrays/static/reductions.f90", "max_stars_repo_name": "gmengaldo/fortran-gym", "max_stars_repo_head_hexsha": "e1e1f8e3256af8ec71bca87d8d9f10de0e531559", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "arrays/static/reductions.f90", "max_issues_repo_name": "gmengaldo/fortran-gym", "max_issues_repo_head_hexsha": "e1e1f8e3256af8ec71bca87d8d9f10de0e531559", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "arrays/static/reductions.f90", "max_forks_repo_name": "gmengaldo/fortran-gym", "max_forks_repo_head_hexsha": "e1e1f8e3256af8ec71bca87d8d9f10de0e531559", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.5652173913, "max_line_length": 49, "alphanum_fraction": 0.4760147601, "num_tokens": 398, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476793890012, "lm_q2_score": 0.7826624688140726, "lm_q1q2_score": 0.6867681538330139}} {"text": "program ch1006\n ! Reading Using Array Sections\n implicit none\n\n integer, parameter :: nrow = 5\n integer, parameter :: ncol = 6\n real, dimension(1:nrow,1:ncol) :: exam_results = 0.\n real, dimension(1:nrow) :: people_average = 0.\n real, dimension(1:ncol) :: subject_average = 0.\n integer :: r, c\n\n open(100,file='ch1006.txt',status='old')\n do r = 1, nrow\n read(100,100) exam_results(r, 1:ncol)\n people_average(r) = sum(exam_results(r,1:ncol))\n end do\n close(100)\n\n people_average = people_average/ncol\n do c = 1, ncol\n subject_average(c) = sum(exam_results(1:nrow,c))\n end do\n subject_average = subject_average/nrow\n do r = 1, nrow\n print 110, (exam_results(r,c),c=1,ncol), people_average(r)\n end do\n print *, ' ==== ==== ==== ==== ==== ===='\n print 120, subject_average(1:ncol)\n\n100 format(1x,6(1x,f5.1))\n110 format(1x,6(1x,f5.1),' = ',f6.2)\n120 format(1x,6(1x,f5.1))\nend program\n", "meta": {"hexsha": "de66d48052f5aaf2a2d06c8f9be80e7704c034b4", "size": 974, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ch10/ch1006.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": "ch10/ch1006.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": "ch10/ch1006.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": 28.6470588235, "max_line_length": 66, "alphanum_fraction": 0.6026694045, "num_tokens": 339, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.8198933403143929, "lm_q1q2_score": 0.6867590296513497}} {"text": "!\r\n! The Laboratory of Algorithms\r\n!\r\n! The MIT License\r\n!\r\n! Copyright 2011-2015 Andrey Pudov.\r\n!\r\n! Permission is hereby granted, free of charge, to any person obtaining a copy\r\n! of this software and associated documentation files (the 'Software'), to deal\r\n! in the Software without restriction, including without limitation the rights\r\n! to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n! copies of the Software, and to permit persons to whom the Software is\r\n! furnished to do so, subject to the following conditions:\r\n!\r\n! The above copyright notice and this permission notice shall be included in\r\n! all copies or substantial portions of the Software.\r\n!\r\n! THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r\n! THE SOFTWARE.\r\n!\r\n\r\n! Even Fibonacci numbers\r\n!\r\n! Each new term in the Fibonacci sequence is generated by adding the previous\r\n! two terms. By starting with 1 and 2, the first 10 terms will be:\r\n! 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...\r\n! By considering the terms in the Fibonacci sequence whose values do not exceed\r\n! four million, find the sum of the even-valued terms.\r\nmodule MPEProblem2\r\n\r\n implicit none\r\n private\r\n\r\n type, public :: TPEProblem2\r\n contains\r\n procedure, nopass :: present\r\n end type\r\ncontains\r\n subroutine present\r\n write (*, '(A)') 'Problem 2. Even Fibonacci numbers.'\r\n\r\n write (*, '(A, I)') 'Even 1: ', even1()\r\n write (*, '(A, I)') 'Even 2: ', even2()\r\n end subroutine\r\n\r\n ! A direct translation of the problem statement\r\n function even1()\r\n integer even1\r\n integer prev\r\n integer cur\r\n integer temp\r\n\r\n ! initial values\r\n even1 = 0\r\n prev = 1\r\n cur = 1\r\n temp = 0\r\n\r\n do while (cur <= 4000000)\r\n if (mod(cur, 2) .eq. 0) then\r\n even1 = even1 + cur\r\n end if\r\n\r\n temp = cur\r\n cur = cur + prev\r\n prev = temp\r\n end do\r\n end function\r\n\r\n ! only every third number is added\r\n function even2()\r\n integer even2\r\n integer prev\r\n integer cur\r\n integer temp\r\n\r\n ! initial values\r\n even2 = 0\r\n prev = 1\r\n cur = 1\r\n temp = prev + cur\r\n\r\n do while (temp < 4000000)\r\n even2 = even2 + temp\r\n prev = cur + temp\r\n cur = temp + prev\r\n temp = prev + cur\r\n end do\r\n end function\r\nend module\r\n", "meta": {"hexsha": "049b6db5b19b3c91e4493b8cdd5b44addd36071b", "size": 2923, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Problems/ProjectEuler/Problem2.f", "max_stars_repo_name": "andreypudov/Algorithms", "max_stars_repo_head_hexsha": "9693efa0abed30a38fcb9c3f7eebbd5b92b734f5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2016-02-15T14:45:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-01T22:42:32.000Z", "max_issues_repo_path": "Problems/ProjectEuler/Problem2.f", "max_issues_repo_name": "jlokimlin/Algorithms", "max_issues_repo_head_hexsha": "d981990394d940fd999334b0b65b118567670d1a", "max_issues_repo_licenses": ["MIT"], "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/ProjectEuler/Problem2.f", "max_forks_repo_name": "jlokimlin/Algorithms", "max_forks_repo_head_hexsha": "d981990394d940fd999334b0b65b118567670d1a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2016-02-24T15:47:02.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-01T10:45:03.000Z", "avg_line_length": 30.4479166667, "max_line_length": 80, "alphanum_fraction": 0.6082791652, "num_tokens": 713, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933359135361, "lm_q2_score": 0.8376199572530448, "lm_q1q2_score": 0.6867590209799525}} {"text": "module RPAdielectric\n use utils, only : dp, pi\n implicit none\n private\n public FDD, redielectric, imdielectric, elf\n \ncontains\n \n function FDD(E, a, b, g_in)\n ! Fermi-Dirac Distriution function.\n real(dp), intent(in) :: E, a, b\n real(dp), intent(in), optional :: g_in ! density of states\n real(dp) :: FDD, maxarg, g\n\n if (present(g_in)) then\n g = g_in\n else\n g = 1\n end if\n\n maxarg = 300. ! Upper cutoff for exponential function\n FDD = g/(1+exp(min((E-a)/b, maxarg)))\n end function FDD\n \n \n function reintegrand(p, k, w, kbT, mu, singulartol)\n ! The integrand in the integral to calculate the real part of the dielectric\n ! function. Assuming p, k, w are positive.\n ! \n ! Parameters:\n ! ___________\n ! p: scalar\n ! The integration variable, which is also the momemtum of the electronic\n ! state.\n ! k: scalar\n ! The change of momentum for an incident photon with momentum k0 \n ! scattering to a state with momentum k1: k = |k1-k0|, in a.u.\n ! w: scalar\n ! The change of energy for an incident photon with energy w0 \n ! scattering to a state with energy w1: w = w0-w1, in a.u.\n ! kbT: scalar\n ! Thermal energy (kb - Boltzmann's constant, T is temperature) in a.u.\n ! mu: scalar\n ! Chemical potential in a.u.\n ! singulartol: scalar\n ! tolerance to handle singularities, where the arguments in the\n ! logarithms become 0.\n \n real(dp), intent(in) :: p, k, w, mu, kbT, singulartol\n real(dp) :: logpart, reintegrand, logtol, a, b, c, d, p1, p2\n\n logtol = 1e-3\n \n a = k**2 + 2*p*k + 2*w\n b = k**2 - 2*p*k + 2*w\n c = k**2 + 2*p*k - 2*w\n d = k**2 - 2*p*k - 2*w\n\n p1 = k**2 / (2*p*k + 2*w)\n p2 = k**2 / (2*p*k - 2*w)\n\n ! low \"x\" approximation for log(1+x)\n if (abs(p2) < logtol) then ! p1 < p2\n logpart = 2*p1 + 2*p2\n else\n ! tol avoids the singularities\n logpart = 0.5 * log((a**2 + singulartol)/(d**2 + singulartol)) &\n + 0.5*log((c**2 + singulartol)/(b**2 + singulartol))\n ! ! Equivalent expression\n ! logpart = log(abs(1+p1)) - log(abs(1-p1)) &\n ! + log(abs(1+p2)) - log(abs(1-p2))\n \n end if\n\n reintegrand = FDD(p**2/2, mu, kbT)*p*logpart \n \n end function reintegrand\n\n function redielectric(k, w, kbT, mu, usertol, printmssg_in) result(er)\n ! Returns the real part of the RPA dielectric function.\n ! Integrates reintegrand while avoiding the singularities.\n !\n ! Parameters:\n ! ___________\n ! usertol: scalar\n ! A user set tolerance used to decide if an approximation of the\n ! integral is okay. This is to make sure our treatment of the singular\n ! points is fine.\n \n real(dp), intent(in) :: k, w, mu, kbT\n real(dp), intent(in), optional :: usertol\n logical, optional :: printmssg_in ! Print warning message if .true.\n real(dp) :: xmax, x, dx, er, er2, tol, singular_tol, error\n integer :: i, imax, loopcount\n logical :: printmssg\n\n if (present(usertol)) then\n tol = usertol\n else\n tol = 1e-4\n end if\n\n if (.not. present(printmssg_in)) then\n printmssg = .false.\n else\n printmssg = .true.\n end if\n \n singular_tol = 1e-6 ! singularity tolerance\n \n xmax = sqrt(2*(mu + 20*kbT)) ! 1/exp(20) \\approx 1e-9\n imax = 2000\n dx = xmax/imax\n\n ! integrate\n er = 0.0\n do i=1,imax\n x = i*dx\n er = er + reintegrand(x, k, w, kbT, mu, singular_tol)*dx\n end do\n er2 = er ! treat er2 as a temporary place holder\n er = er2 + tol + 1 ! Need to get into do-while loop\n \n ! integrate at least twice to make sure our treatment of singularities is\n ! satisfactory.\n error = abs(er - er2)/er\n loopcount = 0\n do while ((er /= 0) .and. (error > tol)) ! Just a while loop\n ! Don't get stuck in a loop forever.\n if (loopcount >= 10) then\n ! We failed. Go home!\n if (printmssg) then\n print *, \"RPAdielectric: Convergence failed due to singularities in \",&\n \"redielectric(): \"\n print \"(a, e9.4, a, e9.4, a, e9.2)\", \"k = \", k, \"; w = \", w,&\n \"; confidence in result: \", error\n end if\n ! Return our best guess\n er = 1 + 2 / pi / k**3 * er2 \n return \n end if\n loopcount = loopcount + 1\n \n er = er2 ! Hold previous er2 value\n er2 = 0.\n ! Try a smaller number for the singularities\n singular_tol = singular_tol/10\n \n do i=1,imax\n x = i*dx\n er2 = er2 + reintegrand(x, k, w, kbT, mu, singular_tol)*dx\n end do\n error = abs(er - er2)/er\n end do\n \n er = 1 + 2 / pi / k**3 * er2\n\n end function redielectric\n\n function imdielectric(k, w, kbT, mu) result(ei)\n ! Returns the imaginary part of the RPA dielectric.\n\n real(dp), intent(in) :: k, w, mu, kbT\n real(dp) :: ei, a, b\n\n a=abs(2*w-k**2)/2./k\n b=abs(2*w+k**2)/2./k\n ei=2 * kbT/k**3 * log(FDD(mu, b**2/2, kbT)/FDD(mu, a**2/2, kbT)) \n end function imdielectric\n\n\n function elf(k, w, kbT, mu, printmssg)\n real(dp), intent(in) :: k, w, mu, kbT\n logical, intent(in), optional :: printmssg\n real(dp) :: elf, er, ei\n\n ! I'm surprised passing an optional arg unchecked worked (for now)...\n er = redielectric(k, w, kbT, mu, printmssg_in=printmssg)\n ei = imdielectric(k, w, kbT, mu)\n elf = ei / (ei**2 + er**2)\n end function elf\n \nend module RPAdielectric\n", "meta": {"hexsha": "d2c625859b671589c3e438062f1525e486a50b69", "size": 5535, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "RPAdielectric.f90", "max_stars_repo_name": "tomhent/dielectric-stopping-fortran", "max_stars_repo_head_hexsha": "ed3061aaaa48d5ae0d4f54f5a36ada9d7a24cfd0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "RPAdielectric.f90", "max_issues_repo_name": "tomhent/dielectric-stopping-fortran", "max_issues_repo_head_hexsha": "ed3061aaaa48d5ae0d4f54f5a36ada9d7a24cfd0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "RPAdielectric.f90", "max_forks_repo_name": "tomhent/dielectric-stopping-fortran", "max_forks_repo_head_hexsha": "ed3061aaaa48d5ae0d4f54f5a36ada9d7a24cfd0", "max_forks_repo_licenses": ["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.0815217391, "max_line_length": 84, "alphanum_fraction": 0.5691056911, "num_tokens": 1840, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465152482724, "lm_q2_score": 0.7341195385342971, "lm_q1q2_score": 0.6866561521437247}} {"text": "! Simplified calling sequence for blas matrix multiplication ZGEMM on square matrices.\n! Computes R = c * A*B where A,B matrices and c is a scaler.\n! Arguments\n! A (input) Complex*16, dimension(NxN) - Matrix A\n! B (input) Complex*16, dimension(NxN) - Matrix B\n! c (input) Complex*16 - scaler c\n! R (output) Complex*16 - Matrix R = c*A*B\n\nsubroutine ZMM(A,B,c,R)\n implicit none\n complex(dp), intent(in) :: A(:,:), B(:,:), c\n complex(dp), intent(out) :: R(:,:)\n integer :: n\n n = size(A,1)\n ! For Details http://www.math.utah.edu/software/lapack/lapack-blas/zgemm.html\n call ZGEMM('N','N',n,n,n,c,A,n,B,n,0.0_dp,R,n)\nend subroutine ZMM", "meta": {"hexsha": "b2d9616513f35cccc469410681807cd85f490fa2", "size": 675, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "partitioned/fortran/tools/subroutines/ZMM.f90", "max_stars_repo_name": "buvoli/epbm", "max_stars_repo_head_hexsha": "32ffe175a2e3456799ebc3e6feeb085ff5c83f81", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "partitioned/fortran/tools/subroutines/ZMM.f90", "max_issues_repo_name": "buvoli/epbm", "max_issues_repo_head_hexsha": "32ffe175a2e3456799ebc3e6feeb085ff5c83f81", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "partitioned/fortran/tools/subroutines/ZMM.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": 39.7058823529, "max_line_length": 86, "alphanum_fraction": 0.6281481481, "num_tokens": 222, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625107731764, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6866351983776724}} {"text": "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC Logical function INSIDE: Returns TRUE if point is inside or on boundary of a\nC polygon with N corners. Returns FALSE otherwise.\nC\nC The method is to trace a ray from the POINT in the positive x direction\nC (ie, a horizontal ray to the right), and count the number of intersections\nC with the edge. If the point is inside the polygon, it will have an odd\nC number of intersections; if it is outside, the number of intersections\nC will be even. Special handling is necessary for the case where the ray\nC touches a vertex, but does not cross the polygon boundary. This does\nC not count as an intersection.\nC\n LOGICAL FUNCTION INSIDE(POINT,CORNER,N)\n IMPLICIT NONE\n INTEGER N\t\t!Number of vertices in the polygon\n REAL POINT(2)\t! (x,y) coordinates of the given point\n REAL CORNER(2,N)\t! (x,y) coordinates of the N vertices of the polygon\n\nC POINT and CORNER may be given as (x,y), (LINE,SAMPLE), or (SAMPLE,LINE)\nC as long the usage is consistent between POINT and CORNER.\n\n INTEGER I,I2,NUM\n REAL X,Y,X0,X1,X2,Y1,Y2\n REAL XMIN,YMIN,XMAX,YMAX\n\n INSIDE = .TRUE.\n NUM = 0\n X = POINT(1)\n Y = POINT(2)\n\n DO 50 I=1,N\t\t!Loop through each edge of polygon\n I2 = MOD(I,N) + 1\n X1 = CORNER(1,I)\t\t!First vertex is (X1,Y1)\n Y1 = CORNER(2,I)\n X2 = CORNER(1,I2)\t\t!Second vertex is (X2,Y2)\n Y2 = CORNER(2,I2)\n\nC ...Eliminate obvious cases where ray would never intersect edge\n YMIN = MIN(Y1,Y2)\n YMAX = MAX(Y1,Y2)\n IF (Y.LT.YMIN .OR. Y.GT.YMAX) GOTO 50\n XMIN = MIN(X1,X2)\n XMAX = MAX(X1,X2)\n IF (X.GT.XMAX) GOTO 50\n\nC ...Horizontal edges are ignored unless the point is on it\n IF (Y1 .EQ. Y2) THEN\n IF (X.GE.XMIN) RETURN\t\t!Point is on this edge\n GOTO 50\n ENDIF\n\nC ...Check if ray passes through a vertex\n IF (Y.EQ.YMIN) THEN\t\t!Ignore YMAX case to avoid dble-counting\n X0 = X1\t\t\t!Find the X associated with YMIN\n IF (Y2.LT.Y1) X0=X2\n IF (X.LT.X0) THEN\t\t!Ray passes through vertex\n NUM = NUM + 1\n GOTO 50\n ENDIF\n ENDIF\n\nC ...Normal case: Y is between Y1 and Y2\n X0 = (Y-Y2)*(X2-X1)/(Y2-Y1) + X2\t!compute intersection\n IF (X.EQ.X0) RETURN\t\t!Point is on this edge\n IF (Y.EQ.Y1 .OR. Y.EQ.Y2) GOTO 50\t!Skip to avoid double-counting\n IF (X.LT.X0) NUM=NUM+1\t\t!Ray intersects edge\n 50 CONTINUE\n\n INSIDE = MOD(NUM,2) .NE. 0\n RETURN\n END\n", "meta": {"hexsha": "73638c889dba3c7d024ef2ef8dada46c532ff9f7", "size": 2559, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "vos/p2/sub/inside/inside.f", "max_stars_repo_name": "NASA-AMMOS/VICAR", "max_stars_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2020-10-21T05:56:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T10:02:01.000Z", "max_issues_repo_path": "vos/p2/sub/inside/inside.f", "max_issues_repo_name": "NASA-AMMOS/VICAR", "max_issues_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "vos/p2/sub/inside/inside.f", "max_forks_repo_name": "NASA-AMMOS/VICAR", "max_forks_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-03-09T01:51:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-23T00:23:24.000Z", "avg_line_length": 35.5416666667, "max_line_length": 79, "alphanum_fraction": 0.6393122313, "num_tokens": 824, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898127684335, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6865539855038303}} {"text": "C$PROCEDURE MMAB\n SUBROUTINE MMAB (A,B,N,M,L,C,NN,MM,LL)\nC$ PURPOSE\nC SUBROUTINE MMAB AND ITS ENTRY POINTS MMABT AND MMATB\nC PERFORM MATRIX MULTIPLICATION BETWEEN MATRICES A AND B\nC IN THREE DIFFERENT WAYS:\nC 1) MMAB COMPUTES C = A*B\nC 2) MMABT COMPUTES C1 = A*(B Transpose)\nC 3) MMATB COMPUTES C2 = (A Transpose)*B\nC$ INPUT_ARGUMENTS\nC CALLING SEQUENCE ARGUMENTS FOR MMAB --\nC\nC NAME DESCRIPTION\nC\nC A DP MATRIX PREMULTIPLIED ON DP MATRIX B\nC\nC B DP MATRIX POSTMULTIPLIED ON DP MATRIX A\nC\nC L NUMBER OF COLUMNS IN OUTPUT MATRIX C AND FROM B\nC\nC LL ROW DIMENSION OF PRODUCT MATRIX C\nC\nC M NUMBER OF COLUMNS OF A AND ROWS OF B IN \nC MATRIX PRODUCT\nC\nC MM ROW DIMENSION OF MATRIX B\nC\nC N NUMBER OF ROWS OF A IN MATRIX PRODUCT AND\nC IN OUTPUT MATRIX C\nC\nC NN ROW DIMENSION OF MATRIX A\nC\nC CALLING SEQUENCE ARGUMENTS FOR MMABT --\nC\nC A DP MATRIX POSTMULTIPLIED BY B TRANSPOSE\nC\nC B DP MATRIX WHOSE TRANSPOSE IS PREMULTIPLIED BY A\nC\nC L NUMBER OF ROWS IN OUTPUT MATRIX AND FROM A \nC\nC LL SAME AS FOR MMAB\nC\nC M NUMBER OF COLUMNS OF MATRICES A AND B IN PRODUCT\nC\nC MM SAME AS FOR MMAB\nC\nC N NUMBER OF COLUMNS IN OUTPUT MATRIX AND ROWS FROM B\nC\nC NN SAME AS FOR MMAB\nC\nC CALLING SEQUENCE ARGUMENTS FOR MMATB --\nC\nC A DP MATRIX WHOSE TRANSPOSE IS POSTMULTIPLIED BY B\nC\nC B DP MATRIX WHICH IS PREMULTIPLIED BY A TRANSPOSE\nC\nC L NUMBER OF COLUMNS IN OUTPUT MATRIX AND FROM B\nC\nC LL SAME AS FOR MMAB\nC\nC M NUMBER OF ROWS FROM BOTH MATRICES A AND B IN PRODUCT\nC\nC MM SAME AS FOR MMAB\nC\nC N NUMBER OF ROWS IN OUTPUT MATRIX AND COLUMNS FROM A\nC\nC NN SAME AS FOR MMAB\nC$ OUTPUT_ARGUMENTS\nC CALLING SEQUENCE ARGUMENTS --\nC\nC NAME DESCRIPTION\nC\nC C OUTPUT MATRIX FROM MMAB\nC\nC C1 OUTPUT MATRIX FROM ENTRY POINT MMABT\nC\nC C2 OUTPUT MATRIX FROM ENTRY POINT MMATB\nC-&\n DOUBLE PRECISION A(NN,1),B(MM,1),C(LL,1)\n DOUBLE PRECISION C1(LL,1),C2(LL,1)\nC$ METHOD\nC-&\nC1 SEE PURPOSE AND ARGUMENT DESCRIPTIONS. MATRIX MULTIPLICATIONS ARE\nC1 PERFORMED THROUGH THE STANDARD NESTED DO LOOP APPROACH.\nC\nC A(N,M) B(M,L) C(N,L)\nC\nC MULTIPLY TWO MATRICES, A*B, PLACE PRODUCT IN C\nC A - FIRST INPUT MATRIX\nC B - SECOND INPUT MATRIX\nC C - PRODUCT MATRIX A*B\nC\nC NN- ROW DIMENSION OF A MATRIX\nC MM- ROW DIMENSION OF B MATRIX\nC LL- ROW DIMENSION OF C MATRIX\nC\nC N - NUMBER OF ROWS OF A, ROWS OF C\nC M - NUMBER OF COLS OF A, ROWS OF B\nC L - NUMBER OF COLS OF B, COLS OF C\nC\n DO 100 I=1,N\n DO 100 J=1,L\n C(I,J)=0.D0\n DO 100 K=1,M\n 100 C(I,J)=C(I,J)+A(I,K)*B(K,J)\n RETURN\n ENTRY MMABT(A,B,L,M,N,C1,NN,MM,LL)\nC\nC B(N,M)\nC A(L,M) BT(M,N) C(L,N)\nC\nC FORM PRODUCT A POSTMULTIPLIED BY TRANSPOSE OF B\nC A - FIRST INPUT MATRIX\nC B - SECOND INPUT MATRIX\nC C - PRODUCT MATIRX A*BT\nC\nC L - NUMBER OF ROWS OF C\nC M - NUMBER OF COLS OF A, COLS OF B\nC N - NUMBER OF ROWS OF B, COLS OF C\nC\n DO 200 I=1,L\n DO 200 J=1,N\n C1(I,J)=0.D0\n DO 200 K=1,M\n 200 C1(I,J)=C1(I,J)+A(I,K)*B(J,K)\n RETURN\n ENTRY MMATB(A,B,M,N,L,C2,NN,MM,LL)\nC\nC A(M,N)\nC AT(N,M) B(M,L) C(N,L)\nC\nC FORM PRODUCT A-TRANSPOSE POSTMULTIPLIED BY B, PRODUCT IN C\nC\nC A - FIRST INPUT MATRIX\nC B - SECOND INPUT MATRIX\nC C - PRODUCT MATRIX AT*B\nC\nC\nC M - NUMBER OF ROWS OF A, ROWS OF B\nC N - NUMBER OF COLS OF A, ROWS OF C\nC L - NUMBER OF COLS OF B,COLS OF C\nC\n DO 300 I=1,N\n DO 300 J=1,L\n C2(I,J)=0.D0\n DO 300 K=1,M\n 300 C2(I,J)=C2(I,J)+A(K,I)*B(K,J)\n RETURN\n END\n", "meta": {"hexsha": "1e8eeaccf4ef5bc618fc1db7b0d7d4d4947a36c5", "size": 3926, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "npo-16671/mmab.for", "max_stars_repo_name": "SteveDoyle2/nasa-cosmic", "max_stars_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_stars_repo_licenses": ["BSD-Source-Code"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2015-03-14T07:26:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-16T12:23:17.000Z", "max_issues_repo_path": "npo-16671/mmab.for", "max_issues_repo_name": "SteveDoyle2/nasa-cosmic", "max_issues_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_issues_repo_licenses": ["BSD-Source-Code"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "npo-16671/mmab.for", "max_forks_repo_name": "SteveDoyle2/nasa-cosmic", "max_forks_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_forks_repo_licenses": ["BSD-Source-Code"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2016-02-12T22:18:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-08T17:46:54.000Z", "avg_line_length": 26.1733333333, "max_line_length": 71, "alphanum_fraction": 0.5955170657, "num_tokens": 1354, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989815306765, "lm_q2_score": 0.7577943658046608, "lm_q1q2_score": 0.6865539775158718}} {"text": "FUNCTION rtbis_s(func,x1,x2,xacc)\n USE mo_kind, only: sp, i4\n USE mo_nrutil, ONLY : nrerror\n IMPLICIT NONE\n REAL(SP), INTENT(IN) :: x1,x2,xacc\n REAL(SP) :: rtbis_s\n INTERFACE\n FUNCTION func(x)\n USE mo_kind\n IMPLICIT NONE\n REAL(SP), INTENT(IN) :: x\n REAL(SP) :: func\n END FUNCTION func\n END INTERFACE\n INTEGER(I4), PARAMETER :: MAXIT=40\n INTEGER(I4) :: j\n REAL(SP) :: dx,f,fmid,xmid\n fmid=func(x2)\n f=func(x1)\n if (f*fmid >= 0.0_sp) call nrerror('rtbis_s: root must be bracketed')\n if (f < 0.0_sp) then\n rtbis_s=x1\n dx=x2-x1\n else\n rtbis_s=x2\n dx=x1-x2\n end if\n do j=1,MAXIT\n dx=dx*0.5_sp\n xmid=rtbis_s+dx\n fmid=func(xmid)\n if (fmid <= 0.0_sp) rtbis_s=xmid\n if (abs(dx) < xacc .or. fmid == 0.0_sp) RETURN\n end do\n call nrerror('rtbis_s: too many bisections')\nEND FUNCTION rtbis_s\n\nFUNCTION rtbis_d(func,x1,x2,xacc)\n USE mo_kind, only: dp, i4\n USE mo_nrutil, ONLY : nrerror\n IMPLICIT NONE\n REAL(DP), INTENT(IN) :: x1,x2,xacc\n REAL(DP) :: rtbis_d\n INTERFACE\n FUNCTION func(x)\n USE mo_kind\n IMPLICIT NONE\n REAL(DP), INTENT(IN) :: x\n REAL(DP) :: func\n END FUNCTION func\n END INTERFACE\n INTEGER(I4), PARAMETER :: MAXIT=40\n INTEGER(I4) :: j\n REAL(DP) :: dx,f,fmid,xmid\n fmid=func(x2)\n f=func(x1)\n if (f*fmid >= 0.0_dp) call nrerror('rtbis_d: root must be bracketed')\n if (f < 0.0_dp) then\n rtbis_d=x1\n dx=x2-x1\n else\n rtbis_d=x2\n dx=x1-x2\n end if\n do j=1, MAXIT\n dx=dx*0.5_dp\n xmid=rtbis_d+dx\n fmid=func(xmid)\n if (fmid <= 0.0_dp) rtbis_d=xmid\n if (abs(dx) < xacc .or. fmid == 0.0_dp) RETURN\n end do\n call nrerror('rtbis_d: too many bisections')\nEND FUNCTION rtbis_d\n", "meta": {"hexsha": "6fa52078e187d8333436352a1fc934a6a802122b", "size": 1734, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "nr_jams/rtbis.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/rtbis.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/rtbis.f90", "max_forks_repo_name": "mcuntz/jams_fortran", "max_forks_repo_head_hexsha": "a1dcab78eda21f930aa6c8c3633598a522f01659", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-08-09T08:08:56.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-09T08:08:56.000Z", "avg_line_length": 23.4324324324, "max_line_length": 71, "alphanum_fraction": 0.6124567474, "num_tokens": 677, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722394, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.6865450568953699}} {"text": " SUBROUTINE CIROVA( RAD1, RAD2, DCEN, AREA, PI)\n IMPLICIT NONE\nC ********************************************************************\nC * *\nC * This software is an unpublished work containing confidential and *\nC * proprietary information of Birkbeck College. Use, disclosure, *\nC * reproduction and transfer of this work without the express *\nC * written consent of Birkbeck College are prohibited. This notice *\nC * must be attached to all copies or extracts of the software. *\nC * *\nC * (c) 1996 Oliver Smart & Birkbeck College, All rights reserved *\nC * *\nC ********************************************************************\n\nC this s/r calculates the overlap area of two circles radius RAD1\nC and RAD2. Their centres are distance DCEN apart. \nC The result is returned as AREA.\n\nC passed variables *********************\n\nC see opening comment - leave all unchanged expect area on return\n DOUBLE PRECISION\t\t\tRAD1, RAD2, DCEN, AREA\n\nC constant PI\n DOUBLE PRECISION\t\t\tPI\n\nC internal vbles ***********************\n\nC two distances, two angles\n DOUBLE PRECISION\t\t\tB, C, ALPHA, BETA\n\nC end of decs **************************\n\nC possibilities\nC (a) no overlap\n IF (DCEN.GT.(RAD1+RAD2)) THEN\n AREA = 0.\n\nC (b) circle 2 is completly within circle 1\n ELSEIF ((DCEN+RAD2).LE.RAD1) THEN\n AREA = PI*(RAD2**2)\n\nC (c) circle 1 is completly within circle 2\n ELSEIF ((DCEN+RAD1).LE.RAD2) THEN\n AREA = PI*(RAD1**2)\n\nC (d) a partial overlap has occured\n ELSE\nC formulae on j100 lab-book\n B = (RAD2**2 + DCEN**2 - RAD1**2)/(2.*DCEN)\n ALPHA = ACOS((DCEN-B)/RAD1)\n BETA = ACOS(B/RAD2)\n C = RAD2*SIN(BETA)\n AREA = ALPHA*(RAD1**2) + BETA*(RAD2**2) - DCEN*C\n ENDIF\n\nC return here\n RETURN\n END\n", "meta": {"hexsha": "6a52eb7940bb662bdc42f71e14b1adae7cf5337c", "size": 2007, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/cirova.f", "max_stars_repo_name": "MDAnalysis/hole2", "max_stars_repo_head_hexsha": "ed28b2ac0dfc714933ddf2befe0a06ed87ede98e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2017-06-09T14:42:10.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T09:23:08.000Z", "max_issues_repo_path": "src/cirova.f", "max_issues_repo_name": "MDAnalysis/hole2", "max_issues_repo_head_hexsha": "ed28b2ac0dfc714933ddf2befe0a06ed87ede98e", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-01-06T11:08:01.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-06T11:08:01.000Z", "max_forks_repo_path": "src/cirova.f", "max_forks_repo_name": "MDAnalysis/hole2", "max_forks_repo_head_hexsha": "ed28b2ac0dfc714933ddf2befe0a06ed87ede98e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2017-06-09T14:42:17.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-27T03:38:01.000Z", "avg_line_length": 33.45, "max_line_length": 70, "alphanum_fraction": 0.5181863478, "num_tokens": 494, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248191350351, "lm_q2_score": 0.731058584489497, "lm_q1q2_score": 0.6864821550773648}} {"text": " module MOD_WMOM0_F\r\n contains\r\n SUBROUTINE WMOM0_F (ND,NP,R,p,WLK)\r\nC*** The Following Modul computes the Integration Weights for the\r\nC*** calculation of the 0-order Moment in COMPXJ\r\n \r\nC*** INTEGRATION OF THE ZERO-MOMENT OF THE RADIATION FIELD (MEAN INTENSITY)\r\nC*** THE INTEGRATION WEIGHTS ARE GENERATED (ARRAY WLK)\r\nC*** RADIUS-MESH R and P-mesh ARE GIVEN\r\nC*** WEIGHTS ARE ACCORDING TO TRAPEZOIDAL RULE IN Z=SQRT(R*R-P*P)\r\n implicit real*8(a-h,o-z)\r\n \r\nc-old DIMENSION R(ND),Z(ND,NP),WLK(ND,NP)\r\n DIMENSION R(ND),p(NP),WLK(ND,NP)\r\n DO L=1,ND\r\n DO JP=1,NP\r\n WLK(L,JP)=0.0\r\n ENDDO\r\n ENDDO\r\n DO L=1,ND\r\n JMAX=NP-(L-1)\r\n RL2=2.*R(L)\r\n rr =r(l)*r(l)\r\nC*** FIRST STEP\r\nc-old ZJ=Z(L,1)\r\nc-old ZNEXT=Z(L,2)\r\n zj = sqrt(rr - p(1)*p(1) )\r\n znext = sqrt(rr - p(2)*p(2) )\r\n WLK(L,1)=(ZJ-ZNEXT)/RL2\r\nC*** MIDDLE STEPS\r\n DO 1 J=3,JMAX\r\n ZLAST=ZJ\r\n ZJ=ZNEXT\r\nc-old ZNEXT=Z(L,J)\r\n znext = sqrt(rr-p(j)*p(j))\r\n WLK(L,J-1)=(ZLAST-ZNEXT)/RL2\r\n 1 CONTINUE\r\nC*** LAST STEP, IMPLYING Z(L,JMAX)=.0\r\n 2 WLK(L,JMAX)=ZJ/RL2\r\n 3 CONTINUE\r\n ENDDO\r\n\r\n RETURN\r\n END subroutine\r\n end module", "meta": {"hexsha": "ecb7dacb98fd721291364ebd868778b60957fe0f", "size": 1287, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/wmom0_f.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/wmom0_f.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/wmom0_f.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": 28.6, "max_line_length": 77, "alphanum_fraction": 0.5322455322, "num_tokens": 473, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248157222395, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6864821470802027}} {"text": "\\ Double Number Arithmetic by Wil Baden, tweaked by Brad Eckert\n\\\n\\ TUM* TUM/ triple Unsigned Mixed Multiply and Divide.\n\\\n\\ T+ T- triple Add and Subtract.\n\\\n\\ DU/MOD Double Unsigned Division with Remainder. Given an unsigned 2-\n\\ cell dividend and an unsigned 2-cell divisor, return a 2-cell\n\\ remainder and a 2-cell quotient. The algorithm is based on Knuth's\n\\ algorithm in volume 2 of his Art of Computer Programming, simplified\n\\ for two-cell dividend and two-cell divisor.\n\nthere\napplets [if] .( Applet bytes: { ) \\ }\npaged applet paged [then]\n\n: +carry ( a b -- a+b carry ) \\ 0 tuck d+\n +c carry \\ speeds up t\n;\n: -borrow ( a b -- a-b borrow ) \\ 0 tuck d-\n swap invert +c invert carry negate \\ speeds up t-\n;\n\n: tum* ( n . mpr -- t . . ) 2>r r@ um* 0 2r> um* d+ ;\n: tum/ ( t . . dvr -- n . ) dup >r um/mod r> swap >r um/mod nip r> ;\n\n: t+ ( t1 . . t2 . . -- t3 . . )\n >r rot >r >r swap >r +carry 0 r> r> +carry d+ r> r> + +\n;\n: t- ( t1 . . t2 . . -- t3 . . )\n >r rot >r >r swap >r -borrow s>d r> r> -borrow d+ r> r> - +\n;\n\n: normalize-divisor ( divr . -- divr' . shift )\n 0 >r begin dup 0< 0= while\n d2* r> 1+ >r\n repeat r> ;\n\n: du/mod ( divd . divr . -- rem . quot . )\n 4 stack(\n ?dup 0= if ( there is a leading zero \"digit\" in divisor. )\n >r 0 r@ um/mod r> swap >r um/mod 0 swap r> )stack exit\n then normalize-divisor dup >r rot rot 2>r\n 1 swap lshift tum*\n ( guess leading \"digit\" of quotient. )\n dup r@ = if -1 else 2dup r@ um/mod nip then\n ( multiply divisor by trial quot and subtract from divd. )\n 2r@ rot dup >r tum* t-\n dup 0< if ( if negative, decrement quot and add to dividend. )\n r> 1- 2r@ rot >r 0 t+\n dup 0< if ( if still negative, do it one more time. )\n r> 1- 2r@ rot >r 0 t+\n then then ( undo normalization of dividend to get remainder. )\n r> 2r> 2drop 1 r> rot >r lshift tum/ r> 0 )stack\n;\n\n\\ Ratio search, based on the Farey sequence, by Brad Eckert\n\\\n\\ Given an unsigned double number `frac` between 0 and 1 scaled to\n\\ 2^(2*cellsize) = 1, find two integers that fit into a specified bit\n\\ width and most closely approximate `frac` using unsigned integer\n\\ division.\n\\\n\\ For vast majority of cases, a very accurate fraction can be found.\n\\ Less than 0.1% of the time, there is significant error.\n\\ If you can work around these cases, it's a good way to get very\n\\ precise scale factors.\n\n2variable ratio_x1 \\ a c\n2variable ratio_x2 \\ b d\n2variable expected \\ unsigned 0 to 1\nvariable maxden \\ maximum allowed denominator\n\n: dfrac ( num denom -- d_frac ) \\ (num << (2*b/cell)) / den\n >r >r 0 dup r> r> tum/\n;\n: exhausted? ( -- flag ) \\ finished with search?\n ratio_x2 2@ maxden @ u< swap maxden @ u< and 0=\n;\n: /ratio ( maxden -- ) \\ initialize\n maxden !\n 0 1 ratio_x1 2!\n 1 1 ratio_x2 2!\n;\n: ratio/ ( flag -- n d )\n 0= cell and \\ true returns c d\n dup>r ratio_x1 + @ ratio_x2 r> + @ \\ false returns a b\n;\n\n\\ Find the (num, den) pair that best satisfies frac = num / den.\n\\ `bits` is the width of the num and den results.\n\\ Don't search for anything very close to 0, it will take forever.\n\n: ratio ( d_frac maxden -- num den )\n 3 stack(\n /ratio expected 2!\n begin\n ratio_x1 2@ + ratio_x2 2@ + 2dup dfrac \\ a+c b+d d_actual\n 2dup expected 2@ d= if \\ exact match\n 2drop dup\n maxden @ u< if exit then \\ a+c b+d\n 2drop ratio_x2 2@ u< ratio/ exit\n then\n expected 2@ du< cell and\n dup>r ratio_x2 + ! r> ratio_x1 + !\n exhausted? until\n ratio_x2 @ maxden @ u< ratio/\n )stack\n;\n\n\\ For 24-bit cells and 20-bit results, you can usually get to within\n\\ 0.01 PPB on the approximation of d_frac. The error of the compound\n\\ number (a + b/c) would be less by a factor of a.\n\\\n\\ Examples on a 24-bit machine:\n\\ 100000000005000. 1048575 ratio swap . . \\ dfrac = 323978 / 911917\n\\ 100000000005500. 1048575 ratio swap . . \\ dfrac = 194159 / 546509\n\\\n\\ `ud*` supports scaling of d_frac at this precision.\n\napplets [if] end-applet paged swap - . .( }; ) [then]\n\n\\ Probably want this in the kernel to keep it fast.\n\\ A short applet would save 40 instructions.\n\n: d+c ( d1 d2 -- d3 carry ) \\ double add with carry out\n >r swap >r +c carry r> + r> +c carry\n;\n\n\\ Unsigned double * double -> quad product\n: ud* ( ud1 ud2 -- uq )\n over >r ratio_x2 2!\n over >r ratio_x1 2! r> r> um*\n ratio_x1 @ dup>r\n ratio_x2 @ dup>r um* \\ d_low d_hi | H1 H2\n r> [ ratio_x1 cell + ] literal @ um*\n r> [ ratio_x2 cell + ] literal @ um* d+c t+\n;\n\nthere swap - . .( instructions used by bignum) cr\n", "meta": {"hexsha": "07bd8355239e8a019646efc783fe22c49d70c763", "size": 4861, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "forth/bignum.f", "max_stars_repo_name": "bradleyeckert/chad", "max_stars_repo_head_hexsha": "30d70e457f959f4528b32f6834606ef8079f5bdd", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2020-08-31T20:07:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T02:59:13.000Z", "max_issues_repo_path": "forth/bignum.f", "max_issues_repo_name": "bradleyeckert/chad", "max_issues_repo_head_hexsha": "30d70e457f959f4528b32f6834606ef8079f5bdd", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-04-21T11:04:10.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-22T10:12:18.000Z", "max_forks_repo_path": "forth/bignum.f", "max_forks_repo_name": "bradleyeckert/chad", "max_forks_repo_head_hexsha": "30d70e457f959f4528b32f6834606ef8079f5bdd", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-09-21T08:59:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-16T07:30:02.000Z", "avg_line_length": 34.475177305, "max_line_length": 71, "alphanum_fraction": 0.5852705205, "num_tokens": 1635, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213691605412, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6864645716574838}} {"text": " DOUBLE PRECISION FUNCTION LOOKUP(TAB,NTAB,POS)\n*\n* Module number: HRS/FOS UTILITY\n*\n* Module name: LOOKUP\n*\n* Keyphrase:\n* ----------\n* Tabular function value\n* Description:\n* ------------\n* This routines looks for the value in a table\n* at a given position.\n* It is equivalent to result=TAB(POS) except\n* that POS is may be a fractional table position.\n* Therefore linear interpolation/extrapolation is\n* used to compute the value.\n*\n* FORTRAN name: lookup.for\n*\n* Keywords of accessed files and tables:\n* --------------------------------------\n* none\n*\n* Subroutines Called:\n* -------------------\n* none\n*\n* History:\n* --------\n* Version Date Author Description\n* 1 Sept. 87 D. Lindler Designed and coded\n*-------------------------------------------------------------------------------\nC\nC INPUT PARAMETERS\nC\nC TAB - VECTOR OF VALUES (REAL*8)\nC NTAB - NUMBER OF VALUES IN TAB (INTEGER)\nC POS - POSITION IN TABLE DESIRED (REAL*8)\nC\nC OUTPUT PARAMETERS\nC RESULT IS RETURNED AS FUNCTION VALUE\nC\nC----------------------------------------------------------------------------\n\tIMPLICIT NONE\n DOUBLE PRECISION TAB(*),POS\n INTEGER NTAB,IPOS\nC\nC DETERMINE FIRST OF PAIR OF TABLE VALUES TO USE\nC\n IPOS=POS\n IF(IPOS.LT.1)IPOS=1\n IF(IPOS.GE.NTAB)IPOS=NTAB-1\nC\nC INTERPOLATE\nC\n LOOKUP=TAB(IPOS)+(POS-IPOS)*(TAB(IPOS+1)-TAB(IPOS))\n RETURN\n END\n", "meta": {"hexsha": "10f5d46ec67a78114478cb3c5b75f6ab180ab26a", "size": 1526, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "stsdas/pkg/hst_calib/fos/lib/lookup.f", "max_stars_repo_name": "iraf-community/stsdas", "max_stars_repo_head_hexsha": "043c173fd5497c18c2b1bfe8bcff65180bca3996", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-12-20T10:06:48.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-20T10:06:48.000Z", "max_issues_repo_path": "stsdas/pkg/hst_calib/fos/lib/lookup.f", "max_issues_repo_name": "spacetelescope/stsdas_stripped", "max_issues_repo_head_hexsha": "043c173fd5497c18c2b1bfe8bcff65180bca3996", "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": "stsdas/pkg/hst_calib/fos/lib/lookup.f", "max_forks_repo_name": "spacetelescope/stsdas_stripped", "max_forks_repo_head_hexsha": "043c173fd5497c18c2b1bfe8bcff65180bca3996", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-10-12T20:01:16.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-19T08:04:30.000Z", "avg_line_length": 25.4333333333, "max_line_length": 80, "alphanum_fraction": 0.5209698558, "num_tokens": 393, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636752, "lm_q2_score": 0.7634837527911057, "lm_q1q2_score": 0.686464559205166}} {"text": "module globalmodule\n\n integer, parameter :: fdp = selected_real_kind(10, 200)\n integer, parameter :: fsp = selected_real_kind(5, 50)\n integer, parameter :: idp = selected_int_kind(9)\n integer, parameter :: isp = selected_int_kind(6)\n integer, parameter :: cdp = fdp\n integer, parameter :: csp = fsp\n\n real(fdp), parameter :: pi = 3.14159265359, &\n & h = 6.626075540d-34, &\n & hbar = h/2.0d0/pi\n\n complex(cdp), parameter :: ii = (0.0d0, 1.0d0)\n \nend module globalmodule\n", "meta": {"hexsha": "70707e28d6c44403a9a0263d245f2502f2328a33", "size": 490, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lectures1and2/example/globalmodule.f90", "max_stars_repo_name": "sdm900/fortran_course", "max_stars_repo_head_hexsha": "6f2db3fcc7b616b94c4e1fe8875a3158a01117b2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lectures1and2/example/globalmodule.f90", "max_issues_repo_name": "sdm900/fortran_course", "max_issues_repo_head_hexsha": "6f2db3fcc7b616b94c4e1fe8875a3158a01117b2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lectures1and2/example/globalmodule.f90", "max_forks_repo_name": "sdm900/fortran_course", "max_forks_repo_head_hexsha": "6f2db3fcc7b616b94c4e1fe8875a3158a01117b2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.8235294118, "max_line_length": 57, "alphanum_fraction": 0.6591836735, "num_tokens": 163, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772482857833, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.6864203678295103}} {"text": " program demo_acos\n use, intrinsic :: iso_fortran_env, only : real_kinds,real32,real64,real128\n implicit none\n character(len=*),parameter :: all='(*(g0,1x))'\n real(kind=real64) :: x = 0.866_real64\n real(kind=real64),parameter :: d2r=acos(-1.0_real64)/180.0_real64\n\n print all,'acos(',x,') is ', acos(x)\n print all,'90 degrees is ', d2r*90.0_real64, ' radians'\n print all,'180 degrees is ', d2r*180.0_real64, ' radians'\n print all,'for reference &\n &PI ~ 3.14159265358979323846264338327950288419716939937510'\n print all,'elemental',acos([-1.0,-0.5,0.0,0.50,1.0])\n\n end program demo_acos\n", "meta": {"hexsha": "4cd6fe0201e0ce3eca2140fbac710291893cd1c9", "size": 649, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/acos.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/acos.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/acos.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": 40.5625, "max_line_length": 78, "alphanum_fraction": 0.6409861325, "num_tokens": 221, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772482857833, "lm_q2_score": 0.7853085758631158, "lm_q1q2_score": 0.6864203590456595}} {"text": "MODULE spline_mod\n\nCONTAINS\n\nSUBROUTINE spl2d(nx,ny,hx,hy,mx,my,f,spl)\n\n! Makes a 2-dimensional cubic spline of function f(x,y)\n!\n! Input: nx, ny number of values in x and y \n! hx, hy step size in x and y (aequidistant)\n! mx, my spline mode (0: standard, 1: periodic)\n! f(nx,ny) f(x,y)-values\n! Output: spl Array with spline parameters\n\n USE neo_precision\n\n IMPLICIT NONE\n\n INTEGER, INTENT(in) :: nx, ny, mx, my\n REAL(kind=dp), INTENT(in) :: hx, hy\n REAL(kind=dp), DIMENSION(nx,ny) , INTENT(in) :: f\n REAL(kind=dp), DIMENSION(4,4,nx,ny), INTENT(out) :: spl\n \n REAL(kind=dp), DIMENSION(:), ALLOCATABLE :: bi, ci, di, s\n INTEGER :: i, j, k\n\n ALLOCATE ( bi(nx), ci(nx), di(nx), s(nx) )\n DO j = 1,ny\n DO i = 1,nx\n s(i) = f(i,j)\n END DO\n IF (mx .EQ. 0) THEN\n CALL splreg(nx,hx,s,bi,ci,di)\n ELSE\n CALL splper(nx,hx,s,bi,ci,di)\n ENDIF\n DO i = 1,nx\n spl(1,1,i,j) = s(i)\n spl(2,1,i,j) = bi(i)\n spl(3,1,i,j) = ci(i)\n spl(4,1,i,j) = di(i)\n END DO\n END DO\n DEALLOCATE ( bi, ci, di, s )\n\n ALLOCATE ( bi(ny), ci(ny), di(ny), s(ny) )\n DO k = 1,4\n DO i = 1,nx\n DO j = 1,ny\n s(j) = spl(k,1,i,j)\n END DO\n IF (my .EQ. 0) THEN\n CALL splreg(ny,hy,s,bi,ci,di)\n ELSE\n CALL splper(ny,hy,s,bi,ci,di)\n ENDIF\n DO j=1,ny\n spl(k,2,i,j)=bi(j)\n spl(k,3,i,j)=ci(j)\n spl(k,4,i,j)=di(j)\n END DO\n END DO\n END DO\n DEALLOCATE ( bi, ci, di, s )\n\n RETURN\nEND SUBROUTINE spl2d\n!=====================================================\nSUBROUTINE eva2d(nx,ny,ix,iy,dx,dy,spl,spval)\n\n! Evaluates a 2-dimensional cubic spline of function f(x,y)\n!\n! Input: nx, ny number of values in x and y \n! ix, iy pointer into the spline array spl\n! dx, dy distance from x(ix) and y(iy)\n! spl array with spline data\n! Output: spval evaluated function value\n\n USE neo_precision\n \n IMPLICIT NONE\n \n INTEGER, INTENT(in) :: nx, ny, ix, iy\n REAL(kind=dp), INTENT(in) :: dx, dy\n REAL(kind=dp), DIMENSION(4,4,nx,ny), INTENT(in) :: spl\n REAL(kind=dp), INTENT(out) :: spval\n\n REAL(kind=dp), DIMENSION(4) :: a\n INTEGER :: l\n\n DO l=1,4\n a(l) = spl(1,l,ix,iy) + dx*(spl(2,l,ix,iy) + & \n dx*(spl(3,l,ix,iy) + dx* spl(4,l,ix,iy)))\n END DO\n spval = a(1)+dy*(a(2)+dy*(a(3)+dy*a(4)))\n\n RETURN\nEND SUBROUTINE eva2d\n!=====================================================\nSUBROUTINE eva2d_fd(nx,ny,ix,iy,dx,dy,spl,spval)\n\n! Evaluates the first derivatives of 2-dimensional cubic spline of function f(x,y)\n!\n! Input: nx, ny number of values in x and y \n! ix, iy pointer into the spline array spl\n! dx, dy distance from x(ix) and y(iy)\n! spl array with spline data\n! Output: spval(2) evaluated function value\n! spval(1) = df/dx\n! spval(2) = df/dy\n\n USE neo_precision\n \n IMPLICIT NONE\n \n INTEGER, INTENT(in) :: nx, ny, ix, iy\n REAL(kind=dp), INTENT(in) :: dx, dy\n REAL(kind=dp), DIMENSION(4,4,nx,ny), INTENT(in) :: spl\n REAL(kind=dp), DIMENSION(2), INTENT(out) :: spval\n\n INTEGER :: i,j\n REAL(kind=dp) :: muli, mulj\n\n spval = 0.0_dp\n\n! df/dx\n DO i=2,4\n IF (i == 2) THEN\n muli = 1.0_dp\n ELSE\n muli = dx**(i-2)\n END IF\n muli = muli * (i-1)\n DO j=1,4\n IF (j == 1) THEN\n mulj = 1.0_dp\n ELSE\n mulj = dy**(j-1)\n END IF\n spval(1) = spval(1) + spl(i,j,ix,iy) * muli * mulj\n END DO\n END DO\n\n! df/dy\n DO i=1,4\n IF (i == 1) THEN\n muli = 1.0_dp\n ELSE\n muli = dx**(i-1)\n END IF\n DO j=2,4\n IF (j == 2) THEN\n mulj = 1.0_dp\n ELSE\n mulj = dy**(j-2)\n END IF\n mulj = mulj * (j-1)\n spval(2) = spval(2) + spl(i,j,ix,iy) * muli * mulj \n END DO\n END DO\n\n RETURN\nEND SUBROUTINE eva2d_fd\n!=====================================================\nSUBROUTINE eva2d_sd(nx,ny,ix,iy,dx,dy,spl,spval)\n\n! Evaluates the second derivatives of 2-dimensional cubic spline of function f(x,y)\n!\n! Input: nx, ny number of values in x and y \n! ix, iy pointer into the spline array spl\n! dx, dy distance from x(ix) and y(iy)\n! spl array with spline data\n! Output: spval(3) evaluated function values\n! spval(1) = d^2f/dx^2\n! spval(2) = d^2f/(dxdy)\n! spval(3) = d^2f/dy^2\n\n USE neo_precision\n \n IMPLICIT NONE\n \n INTEGER, INTENT(in) :: nx, ny, ix, iy\n REAL(kind=dp), INTENT(in) :: dx, dy\n REAL(kind=dp), DIMENSION(4,4,nx,ny), INTENT(in) :: spl\n REAL(kind=dp), DIMENSION(3), INTENT(out) :: spval\n\n INTEGER :: i,j\n REAL(kind=dp) :: muli, mulj\n\n spval = 0.0_dp\n\n! d^2f/dx^2\n DO i=3,4\n IF (i == 3) THEN\n muli = 1.0_dp\n ELSE\n muli = dx**(i-3)\n END IF\n muli = muli * (i-1) * (i-2)\n DO j=1,4\n IF (j == 1) THEN\n mulj = 1.0_dp\n ELSE\n mulj = dy**(j-1)\n END IF\n spval(1) = spval(1) + spl(i,j,ix,iy) * muli * mulj\n END DO\n END DO\n\n! d^2f/(dxdy)\n DO i=2,4\n IF (i == 2) THEN\n muli = 1.0_dp\n ELSE\n muli = dx**(i-2)\n END IF\n muli = muli * (i-1)\n DO j=2,4\n IF (j == 2) THEN\n mulj = 1.0_dp\n ELSE\n mulj = dy**(j-2)\n END IF\n mulj = mulj * (j-1)\n spval(2) = spval(2) + spl(i,j,ix,iy) * muli * mulj\n END DO\n END DO\n\n! d^2f/dy^2\n DO i=1,4\n IF (i == 1) THEN\n muli = 1.0_dp\n ELSE\n muli = dx**(i-1)\n END IF\n DO j=3,4\n IF (j == 3) THEN\n mulj = 1.0_dp\n ELSE\n mulj = dy**(j-3)\n END IF\n mulj = mulj * (j-1) * (j-2)\n spval(3) = spval(3) + spl(i,j,ix,iy) * muli * mulj\n END DO\n END DO\n\n RETURN\nEND SUBROUTINE eva2d_sd\n!=====================================================\nSUBROUTINE splreg(n,h,y,bi,ci,di)\n\n! Makes a cubic spline of function y(x)\n!\n! Input: n number of values in y \n! h step size in x (aequidistant)\n! y(n) y-values\n! Output: bi(n),ci(n),di(n) Spline parameters\n\n USE neo_precision\n\n IMPLICIT NONE\n\n INTEGER, INTENT(in) :: n\n REAL(kind=dp), INTENT(in) :: h\n REAL(kind=dp), DIMENSION(n), INTENT(in) :: y\n REAL(kind=dp), DIMENSION(n), INTENT(out) :: bi, ci, di\n\n REAL(kind=dp) :: ak1, ak2, am1, am2, c, e, c1\n REAL(kind=dp), DIMENSION(:), ALLOCATABLE :: al, bt\n INTEGER :: k, n2, i, i5\n\n ALLOCATE ( al(n), bt(n) )\n\n ak1 = 0.d0\n ak2 = 0.d0\n am1 = 0.d0\n am2 = 0.d0\n k = n-1\n al(1) = ak1\n bt(1) = am1\n n2 = n-2\n c = -4.d0*h\n DO i = 1,n2\n e = -3.d0*((y(i+2)-y(i+1))-(y(i+1)-y(i)))/h\n c1 = c-al(i)*h\n al(i+1) = h/c1\n bt(i+1) = (h*bt(i)+e)/c1\n END DO\n ci(n) = (am2+ak2*bt(k))/(1.d0-al(k)*ak2)\n DO i = 1,k\n i5 = n-i\n ci(i5) = al(i5)*ci(i5+1)+bt(i5)\n END DO\n n2 = n-1\n DO i = 1,n2\n bi(i) = (y(i+1)-y(i))/h-h*(ci(i+1)+2.d0*ci(i))/3.d0\n di(i) = (ci(i+1)-ci(i))/h/3.d0\n END DO\n DEALLOCATE ( al, bt )\n\n RETURN\nEND SUBROUTINE splreg\n!=====================================================\nSUBROUTINE splper(n,h,y,bi,ci,di)\n\n! Makes a cubic spline of periodic function y(x)\n!\n! Input: n number of values in y\n! h step size in x (aequidistant)\n! y(n) y-values\n! Output: bi(n),ci(n),di(n) Spline parameters\n\n USE neo_precision\n\n IMPLICIT NONE\n\n INTEGER, INTENT(in) :: n\n REAL(kind=dp), INTENT(in) :: h\n REAL(kind=dp), DIMENSION(n), INTENT(in) :: y\n REAL(kind=dp), DIMENSION(n), INTENT(out) :: bi, ci, di\n\n REAL(kind=dp) :: psi, ss\n REAL(kind=dp), DIMENSION(:), ALLOCATABLE :: bmx, yl\n REAL(kind=dp), DIMENSION(:), ALLOCATABLE :: amx1, amx2, amx3\n INTEGER :: nmx, n1, n2, i, i1\n\n ALLOCATE ( bmx(n), yl(n), amx1(n), amx2(n), amx3(n) )\n \n bmx(1) = 1.d30\n\n nmx=n-1\n n1=nmx-1\n n2=nmx-2\n psi=3.d0/h/h\n\n CALL spfper(n,amx1,amx2,amx3)\n\n bmx(nmx) = (y(nmx+1)-2.d0*y(nmx)+y(nmx-1))*psi\n bmx(1) =(y(2)-y(1)-y(nmx+1)+y(nmx))*psi\n DO i = 3,nmx\n bmx(i-1) = (y(i)-2.d0*y(i-1)+y(i-2))*psi\n END DO\n yl(1) = bmx(1)/amx1(1)\n DO i = 2,n1\n i1 = i-1\n yl(i) = (bmx(i)-yl(i1)*amx2(i1))/amx1(i)\n END DO\n ss = 0.d0\n DO i = 1,n1\n ss = ss+yl(i)*amx3(i)\n END DO\n yl(nmx) = (bmx(nmx)-ss)/amx1(nmx)\n bmx(nmx) = yl(nmx)/amx1(nmx)\n bmx(n1) = (yl(n1)-amx2(n1)*bmx(nmx))/amx1(n1)\n DO i = n2,1,-1\n bmx(i) = (yl(i)-amx3(i)*bmx(nmx)-amx2(i)*bmx(i+1))/amx1(i)\n END DO\n DO i = 1,nmx\n ci(i) = bmx(i)\n END DO\n\n DO i = 1,n1\n bi(i) = (y(i+1)-y(i))/h-h*(ci(i+1)+2.d0*ci(i))/3.d0\n di(i) = (ci(i+1)-ci(i))/h/3.d0\n END DO\n bi(nmx) = (y(n)-y(n-1))/h-h*(ci(1)+2.d0*ci(nmx))/3.d0\n di(nmx) = (ci(1)-ci(nmx))/h/3.d0\n!\n! Fix of problems at upper periodicity boundary\n!\n bi(n) = bi(1)\n ci(n) = ci(1)\n di(n) = di(1)\n\n DEALLOCATE ( bmx, yl, amx1, amx2, amx3 )\n\n RETURN\nEND SUBROUTINE splper\n!=====================================================\nSUBROUTINE spfper(np1,amx1,amx2,amx3)\n\n! Helper routine for splfi\n\n USE neo_precision\n\n IMPLICIT NONE\n\n INTEGER, INTENT(in) :: np1\n REAL(kind=dp), DIMENSION(np1), INTENT(out) :: amx1, amx2, amx3\n REAL(kind=dp) :: beta, ss\n INTEGER :: n, n1, i, i1\n\n n = np1-1\n\n n1 = n-1\n amx1(1) = 2.d0\n amx2(1) = 0.5d0\n amx3(1) = 0.5d0\n amx1(2) = SQRT(15.d0)/2.d0\n amx2(2) = 1.d0/amx1(2)\n amx3(2) = -.25d0/amx1(2)\n beta = 3.75d0\n DO i = 3,n1\n i1 = i-1\n beta = 4.d0-1.d0/beta\n amx1(i) = SQRT(beta)\n amx2(i) = 1.d0/amx1(i)\n amx3(i) = -amx3(i1)/amx1(i)/amx1(i1)\n END DO\n amx3(n1) = amx3(n1)+1.d0/amx1(n1)\n amx2(n1) = amx3(n1)\n ss = 0.0d0\n DO i = 1,n1\n ss = ss+amx3(i)*amx3(i)\n END DO\n amx1(n) = SQRT(4.d0-ss)\n\n RETURN\nEND SUBROUTINE spfper\n!=====================================================\nSUBROUTINE poi2d(hx,hy,mx,my, &\n xmin,xmax,ymin,ymax, &\n x,y,ix,iy,dx,dy,ierr)\n! Creates Pointers for eva2d\n!\n! Input: hx, hy increment in x and y \n! mx, my standard (0) or periodic (1) spline\n! xmin, xmax Minimum and maximum x\n! ymin, ymax Minimum and maximum y\n! x, y x and y values for spline avaluation\n! Output: spval evaluated function value\n! ix, iy pointer into the spline array spl\n! dx, dy distance from x(ix) and y(iy)\n! ierr error (> 0)\n\n USE neo_precision\n\n IMPLICIT NONE\n\n REAL(kind=dp), INTENT(in) :: hx, hy\n INTEGER, INTENT(in) :: mx, my\n REAL(kind=dp), INTENT(in) :: xmin, xmax, ymin, ymax\n REAL(kind=dp), INTENT(in) :: x, y\n\n INTEGER, INTENT(out) :: ix, iy\n REAL(kind=dp), INTENT(out) :: dx, dy\n INTEGER, INTENT(out) :: ierr\n\n REAL(kind=dp) :: dxx, x1, dyy, y1\n REAL(kind=dp) :: dxmax, dymax\n\n ierr = 0\n\n dxx = x-xmin\n IF (mx .EQ. 0) THEN\n IF (dxx .LT. 0.d0) THEN\n ierr = 1\n RETURN\n END IF\n IF (x .GT. xmax) THEN\n ierr = 2\n RETURN\n END IF\n ELSE\n dxmax = xmax - xmin\n IF(dxx .LT. 0.d0) THEN\n dxx = dxx+DBLE(float(1+INT(ABS(dxx/dxmax))))*dxmax\n ELSE IF(dxx .GT. dxmax) THEN\n dxx = dxx-DBLE(float(INT(ABS(dxx/dxmax))))*dxmax\n END IF\n END IF\n x1 = dxx/hx\n ix = INT(x1)\n dx = hx*(x1-DBLE(float(ix)))\n ix = ix+1\n\n dyy = y-ymin\n IF (my .EQ. 0) THEN\n IF (dyy .LT. 0.d0) THEN\n ierr = 3\n RETURN\n END IF\n IF (y .GT. ymax) THEN\n ierr = 4\n RETURN\n END IF\n ELSE\n dymax = ymax - ymin\n IF(dyy .LT. 0.d0) THEN\n dyy = dyy+DBLE(float(1+INT(ABS(dyy/dymax))))*dymax\n ELSE IF(dyy .GT. dymax) THEN\n dyy = dyy-DBLE(float(INT(ABS(dyy/dymax))))*dymax\n END IF\n END IF\n y1 = dyy/hy\n iy = INT(y1)\n dy = hy*(y1-DBLE(float(iy)))\n iy = iy+1\n\n RETURN\nEND SUBROUTINE poi2d\n\nEND MODULE spline_mod\n\n\n\n\n\n", "meta": {"hexsha": "4208de25b92388b3b15195029daca008e599a32d", "size": 13307, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "MC/CODE/pspline.f90", "max_stars_repo_name": "itpplasma/NEO-RT", "max_stars_repo_head_hexsha": "b0b8022d522bc97d0ffa721fd30167e74a0965a3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MC/CODE/pspline.f90", "max_issues_repo_name": "itpplasma/NEO-RT", "max_issues_repo_head_hexsha": "b0b8022d522bc97d0ffa721fd30167e74a0965a3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-10-29T12:44:06.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-29T12:45:04.000Z", "max_forks_repo_path": "MC/CODE/pspline.f90", "max_forks_repo_name": "itpplasma/NEO-RT", "max_forks_repo_head_hexsha": "b0b8022d522bc97d0ffa721fd30167e74a0965a3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-02T13:03:35.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-02T13:03:35.000Z", "avg_line_length": 26.1434184676, "max_line_length": 83, "alphanum_fraction": 0.4512662508, "num_tokens": 4833, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772318846387, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.6864203549495507}} {"text": "! *********************************************************************\r\n! * *\r\n! * subroutine chkne3 *\r\n! * *\r\n! *********************************************************************\r\n! Single Precision Version 1.11\r\n! Written by Gordon A. Fenton, TUNS, Jul 14, 2000\r\n! Latest Update: Oct 18, 2002\r\n!\r\n! PURPOSE\tchecks nxe, nye, and nze to ensure that they are compatible\r\n!\t\twith random fields produced by LAS3G\r\n!\r\n! DESCRIPTION\r\n! This routine checks nxe, nye, and nze to ensure that they can be written\r\n! in the form;\r\n!\t\tnxe = k1*(2**m)\r\n!\t\tnye = k2*(2**m)\r\n!\t\tnze = k3*(2**m)\r\n!\r\n! If not, the random field size given by (nrfx,nrfy,nrfz) is adjusted\r\n! upwards until the integers nrfx, nrfy, and nrfz do satisfy the\r\n! above equations for some non-negative integer m and positive integers\r\n! (k1,k2,k3) with k1*k2*k3 <= MXK.\r\n!\r\n! ARGUMENTS\r\n!\r\n! istat\tunit number connected to a file to which error and warning\r\n!\t\tmessages can be issued. (input)\r\n!\r\n! iterm\tunit number connected to the screen. If verbos is true, then\r\n!\t\terror and warning messages are also sent to the screen. (input)\r\n!\r\n! verbos\tlogical flag which is true if error, warning, and progress\r\n!\t\tmessages are allowed to be sent to the screen. (output)\r\n!\r\n! nxe\tinteger giving the number of elements describing the pillar\r\n!\t\tin the x-direction (width). (input)\r\n!\r\n! nye\tinteger giving the number of elements describing the pillar\r\n!\t\tin the y-direction (depth). (input)\r\n!\r\n! nze\tinteger giving the number of elements describing the pillar\r\n!\t\tin the z-direction (height). (input)\r\n!\r\n! nrfx\tinteger giving the number of cells in the x-direction in the\r\n!\t\tsimulated random field. This is normally equal to nxe, but if\r\n!\t\tnxe is not an integer of the form nxe = k1*(2**m), where m is\r\n!\t\ta non-negative integer, and k1 is a positive integer with\r\n!\t\tk1*k2*k3 < MXK then nrfx is set to the next larger\r\n!\t\tpossible integer that does satisfy this requirement of LAS3G.\r\n!\t\t(input)\r\n!\r\n! nrfy\tinteger giving the number of cells in the y-direction in the\r\n!\t\tsimulated random field. This is normally equal to nye, but if\r\n!\t\tnye is not an integer of the form nye = k2*(2**m), where m is\r\n!\t\ta non-negative integer, and k2 is a positive integer with\r\n!\t\tk1*k2*k3 < MXK then nrfy is set to the next larger\r\n!\t\tpossible integer that does satisfy this requirement of LAS3G.\r\n!\t\t(input)\r\n!\r\n! nrfz\tinteger giving the number of cells in the z-direction in the\r\n!\t\tsimulated random field. This is normally equal to nze, but if\r\n!\t\tnze is not an integer of the form nze = k3*(2**m), where m is\r\n!\t\ta non-negative integer, and k3 is a positive integer with\r\n!\t\tk1*k2*k3 < MXK then nrfz is set to the next larger\r\n!\t\tpossible integer that does satisfy this requirement of LAS3G.\r\n!\t\t(input)\r\n!\r\n! PARAMETERS:\r\n! MXK\tmaximum value that k1*k2*k3 can be. This should be identical to that\r\n!\tprescribed in GAF77 library routine las3g.f.\r\n!\r\n! REVISION HISTORY:\r\n! 1.11\tadded data definition for zero (Oct 18/02)\r\n!-------------------------------------------------------------------------\r\n subroutine chkne3(istat,iterm,verbos,nxe,nye,nze,nrfx,nrfy,nrfz)\r\n parameter (MXK = 512)\r\n logical verbos\r\n data zero/0.0/, half/0.5/, pt9/0.99999/, two/2.0/\r\n\r\n 1 format(a)\r\n!\t\t\t\t\tcompute minimum m\r\n aa = float(nxe*nye*nze)/float(MXK)\r\n am = alog(aa)/(two*alog(two))\r\n if( am .lt. zero ) am = zero\r\n m = int(am + pt9)\t\t! round m up\r\n tm = two**m\r\n!\t\t\t\t\tnow compute minimum k's\r\n ak1 = float(nxe)/tm\r\n k1 = int(ak1 + pt9)\r\n ak2 = float(nye)/tm\r\n k2 = int(ak2 + pt9)\r\n ak3 = float(nze)/tm\r\n k3 = int(ak3 + pt9)\r\n!\t\t\t\t\tnew nxe, nye, and nze\r\n nrfx = k1*int(tm + half)\r\n nrfy = k2*int(tm + half)\r\n nrfz = k3*int(tm + half)\r\n!\t\t\t\t\twarn if we're changing anything\r\n\r\n if( (nrfx .ne. nxe) .or. &\r\n (nrfy .ne. nye) .or. &\r\n (nrfz .ne. nze) ) then\r\n if( verbos ) then\r\n call print3(iterm, &\r\n 'Note: desired number of elements (%i, %i, %i)%n', &\r\n nxe,nye,nze)\r\n write(iterm,1)' incompatible with LAS3G simulator.'\r\n call print3(iterm, &\r\n ' Adjusting random field size to (%i, %i, %i)%n', &\r\n nrfx,nrfy,nrfz)\r\n endif\r\n call print3(istat, &\r\n 'Note: desired number of elements (%i, %i, %i)%n', &\r\n nxe,nye,nze)\r\n write(istat,1)' incompatible with LAS3G simulator.'\r\n call print3(istat, &\r\n ' Adjusting random field size to (%i, %i, %i)%n', &\r\n nrfx,nrfy,nrfz)\r\n endif\r\n\r\n return\r\n end\r\n", "meta": {"hexsha": "7fca8032539dbb1a8bc8360b8d28822709119a1d", "size": 5198, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/libs/gaf95/chkne3.f95", "max_stars_repo_name": "leemargetts/PoreFEM", "max_stars_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/libs/gaf95/chkne3.f95", "max_issues_repo_name": "leemargetts/PoreFEM", "max_issues_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/libs/gaf95/chkne3.f95", "max_forks_repo_name": "leemargetts/PoreFEM", "max_forks_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.9193548387, "max_line_length": 76, "alphanum_fraction": 0.5296267795, "num_tokens": 1450, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648677, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.6864203531336174}} {"text": "\nc---------------------------------------------------------------------\nc---------------------------------------------------------------------\n\n subroutine error_norm(rms)\n\nc---------------------------------------------------------------------\nc---------------------------------------------------------------------\n\nc---------------------------------------------------------------------\nc this function computes the norm of the difference between the\nc computed solution and the exact solution\nc---------------------------------------------------------------------\n\n include 'header.h'\n\n integer i, j, k, m, d\n double precision xi, eta, zeta, u_exact(5), rms(5), add\n\n double precision rmsz(5,0:KMAX-1)\n!hpf$ distribute(*,block) :: rmsz\n\n interface\n extrinsic (hpf_local) pure subroutine\n > exact_solution(xi,eta,zeta,dtemp)\n double precision, intent(in):: xi, eta, zeta\n double precision, dimension (:), intent(out) :: dtemp\n end subroutine exact_solution\n end interface\n\n!hpf$ independent, new(add, u_exact)\n do k = 0, grid_points(3)-1\n do m = 1, 5\n rmsz(m,k) = 0.0d0\n end do\n\n zeta = dble(k) * dnzm1\n do j = 0, grid_points(2)-1\n eta = dble(j) * dnym1\n do i = 0, grid_points(1)-1\n xi = dble(i) * dnxm1\n call exact_solution(xi, eta, zeta, u_exact(:))\n do m = 1, 5\n add = u(m,i,j,k)-u_exact(m)\n rmsz(m,k) = rmsz(m,k) + add*add\n end do\n end do\n end do\n end do\n\n do m = 1, 5\n rms(m) = sum( rmsz(m,0:grid_points(3)-1) )\n do d = 1, 3\n rms(m) = rms(m) / dble(grid_points(d)-2)\n end do\n rms(m) = dsqrt(rms(m))\n end do\n\n return\n end\n\n\n\n subroutine rhs_norm(rms)\n\n include 'header.h'\n\n integer i, j, k, d, m\n double precision rms(5), add\n\n double precision rmsz(5,0:KMAX-1)\n!hpf$ distribute(*,block) :: rmsz\n\n!hpf$ independent, new(add)\n do k = 1, nz2\n do m = 1, 5\n rmsz(m,k) = 0.0d0\n end do\n\n do j = 1, ny2\n do i = 1, nx2\n \t do m = 1, 5\n add = rhs(m,i,j,k)\n rmsz(m,k) = rmsz(m,k) + add*add\n end do \n end do \n end do \n end do \n\n do m = 1, 5\n rms(m) = sum( rmsz(m,1:nz2) )\n do d = 1, 3\n rms(m) = rms(m) / dble(grid_points(d)-2)\n end do\n rms(m) = dsqrt(rms(m))\n end do\n\n return\n end\n\n\n", "meta": {"hexsha": "092f3d321e6296e16e66dab3d7dfba8af7f565c5", "size": 2722, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "NPB3.0-HPF/SP/error.f", "max_stars_repo_name": "josevnz/NPB3.0-JAV-FORK", "max_stars_repo_head_hexsha": "4d917796d534fab7df30a08c74a756b9a44f38b7", "max_stars_repo_licenses": ["NASA-1.3"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NPB3.0-HPF/SP/error.f", "max_issues_repo_name": "josevnz/NPB3.0-JAV-FORK", "max_issues_repo_head_hexsha": "4d917796d534fab7df30a08c74a756b9a44f38b7", "max_issues_repo_licenses": ["NASA-1.3"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NPB3.0-HPF/SP/error.f", "max_forks_repo_name": "josevnz/NPB3.0-JAV-FORK", "max_forks_repo_head_hexsha": "4d917796d534fab7df30a08c74a756b9a44f38b7", "max_forks_repo_licenses": ["NASA-1.3"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.6862745098, "max_line_length": 70, "alphanum_fraction": 0.3842762675, "num_tokens": 724, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.874077222043951, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.6864203428296489}} {"text": "!this module is use to solve the three diag matrix Ax=b\nMODULE threediag_mod\n IMPLICIT NONE\n PUBLIC threediag\nCONTAINS\n SUBROUTINE threediag(n,a,b,c,d,x)\n INTEGER(4),INTENT(IN)::n\n REAL(8),DIMENSION(:),INTENT(IN)::a(n),b(n),c(n),d(n)\n REAL(8),DIMENSION(:),INTENT(INOUT)::x(n)\n REAL(8),ALLOCATABLE::y(:),u(:),l(:)\n INTEGER(4)::i\n ALLOCATE(y(n))\n ALLOCATE(u(n))\n ALLOCATE(l(n))\n x=0\n y=0\n u=0\n l=0\n u(1)=b(1)\n y(1)=d(1)\n DO i=2,n\n l(i)=a(i)/u(i-1)\n u(i)=b(i)-l(i)*c(i-1)\n y(i)=d(i)-l(i)*y(i-1)\n END DO\n x(n)=y(n)/u(n)\n DO i=n-1,1,-1\n x(i)=(y(i)-c(i)*x(i+1))/u(i)\n END DO\n DEALLOCATE(y)\n DEALLOCATE(u)\n DEALLOCATE(l)\n END SUBROUTINE\nEND MODULE", "meta": {"hexsha": "33ef6fd147629c796e68728a334eb61118bcbfc1", "size": 850, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "CSI/src/threediag_mod.f90", "max_stars_repo_name": "Huang-Yihan/jisuanfangfa", "max_stars_repo_head_hexsha": "1e48104988b01f66da216f639fd0654a6b1ff6c4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "CSI/src/threediag_mod.f90", "max_issues_repo_name": "Huang-Yihan/jisuanfangfa", "max_issues_repo_head_hexsha": "1e48104988b01f66da216f639fd0654a6b1ff6c4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "CSI/src/threediag_mod.f90", "max_forks_repo_name": "Huang-Yihan/jisuanfangfa", "max_forks_repo_head_hexsha": "1e48104988b01f66da216f639fd0654a6b1ff6c4", "max_forks_repo_licenses": ["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.0, "max_line_length": 60, "alphanum_fraction": 0.4576470588, "num_tokens": 310, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273633016692236, "lm_q2_score": 0.7401743735019595, "lm_q1q2_score": 0.6864105508217263}} {"text": "! Generic math subroutines\r\nmodule math_mod\r\n\r\n implicit none\r\n real,parameter :: pi = 3.14159265358979323846264338327950288419716939937510 ! No, this is not at all excessive\r\n real,parameter :: inf = huge(0.) ! Reason #403929 why Fortran is the best: huge() is an intrinsic function\r\n \r\ncontains\r\n\r\n\r\nfunction isinf(x) result(is)\r\n ! Checks if x is infinite\r\n\r\n implicit none\r\n\r\n real,intent(in) :: x\r\n\r\n logical :: is\r\n\r\n ! Check for infinity\r\n if (x >= inf .or. x <= -inf) then\r\n is = .true.\r\n else\r\n is = .false.\r\n end if\r\n\r\nend function isinf\r\n\r\n\r\nfunction sign(x) result(s)\r\n ! Returns the sign of x\r\n\r\n implicit none\r\n\r\n real,intent(in) :: x\r\n\r\n integer :: s\r\n\r\n if (x < 0.) then\r\n s = -1\r\n else if (x > 0.) then\r\n s = 1\r\n else\r\n s = 0\r\n end if\r\n\r\nend function sign\r\n\r\n\r\nfunction plane_normal(p1, p2, p3) result(n)\r\n ! Computes the normal vector to a plane defined by 3 points\r\n\r\n implicit none\r\n\r\n real,dimension(3),intent(in) :: p1, p2, p3\r\n real,dimension(3) :: a, b, n\r\n\r\n a = p2 - p1\r\n b = p3 - p1\r\n n = cross(a,b)\r\n n = n/norm(n)\r\n\r\nend function plane_normal\r\n\r\n\r\nfunction reflect_point(A, B, C, D, P) result(P_refl)\r\n ! Somehow reflects a point P\r\n\r\n implicit none\r\n\r\n real,intent(in) :: A, B, C, D\r\n real,dimension(3),intent(in) :: P(3)\r\n real,dimension(3) :: P_refl\r\n\r\n real :: mult\r\n\r\n mult = 2.0*(A*P(1) + B*P(2) + C*P(3) + D)/(A**2 + B**2 + C**2)\r\n\r\n P_refl(1) = P(1) - mult*A\r\n P_refl(2) = P(2) - mult*B\r\n P_refl(3) = P(3) - mult*C\r\n\r\nend function reflect_point\r\n\r\n\r\nfunction dist(a, b) result(c)\r\n ! Calculates the cartesian distance between 2 points\r\n\r\n implicit none\r\n\r\n real,dimension(3),intent(in) :: a, b\r\n real :: c\r\n\r\n c = sqrt(sum((a-b)**2))\r\n\r\nend function dist\r\n\r\n\r\nfunction cross(a, b) result(c)\r\n ! Calculates the cross-product of two 3-element vectors\r\n\r\n implicit none\r\n\r\n real,dimension(3),intent(in) :: a, b\r\n\r\n real,dimension(3) :: c\r\n\r\n c(1) = a(2)*b(3) - a(3)*b(2)\r\n c(2) = a(3)*b(1) - a(1)*b(3)\r\n c(3) = a(1)*b(2) - a(2)*b(1)\r\n\r\nend function cross\r\n\r\n\r\nfunction inner(a, b) result(c)\r\n ! Calculates the 3D Euclidean inner product\r\n\r\n implicit none\r\n real, dimension(3) :: a, b\r\n real :: c\r\n\r\n c = a(1)*b(1)+a(2)*b(2)+a(3)*b(3)\r\n\r\nend function inner\r\n\r\n\r\nfunction inner2(a, b) result(c)\r\n ! Calculates the 2D Euclidean inner product\r\n\r\n implicit none\r\n real, dimension(2) :: a, b\r\n real :: c\r\n\r\n c = a(1)*b(1)+a(2)*b(2)\r\n\r\nend function inner2\r\n\r\n\r\nfunction outer(a, b) result(c)\r\n ! Calculates the outer product of two vectors\r\n\r\n implicit none\r\n\r\n real,dimension(3) :: a, b\r\n real,dimension(3,3) :: c\r\n\r\n integer :: i\r\n\r\n c = 0.\r\n\r\n do i=1,3\r\n c(i,:) = a(i)*b(:)\r\n end do\r\n\r\nend function\r\n\r\n\r\nfunction norm(a) result(c)\r\n ! Calculates the norm of the vector\r\n\r\n implicit none\r\n real, dimension(3) :: a\r\n real :: c\r\n\r\n c = sqrt(inner(a, a))\r\n\r\nend function norm\r\n\r\n\r\nfunction det3(a) result(c)\r\n ! Calculates the determinant of a 3x3 matrix\r\n\r\n implicit none\r\n\r\n real,dimension(3,3) :: a\r\n real :: c\r\n\r\n c = a(1,1)*(a(2,2)*a(3,3)-a(2,3)*a(3,2))\r\n c = c - a(1,2)*(a(2,1)*a(3,3)-a(2,3)*a(3,1))\r\n c = c + a(1,3)*(a(2,1)*a(3,2)-a(3,1)*a(2,2))\r\n\r\nend function det3\r\n\r\n\r\nfunction rot_x(v, theta) result(v_rot)\r\n ! Rotates v about the x axis by theta (in radians)\r\n\r\n implicit none\r\n\r\n real,dimension(3),intent(in) :: v\r\n real,intent(in) :: theta\r\n real,dimension(3) :: v_rot\r\n\r\n real,dimension(3,3) :: rm(3,3) = 0.\r\n\r\n rm(1,1) = 1.\r\n rm(2,2) = cos(theta)\r\n rm(2,3) = -sin(theta)\r\n rm(3,2) = sin(theta)\r\n rm(3,3) = cos(theta)\r\n\r\n v_rot = matmul(rm, v)\r\n\r\nend function rot_x\r\n\r\n\r\nfunction rot_y(v, theta) result(v_rot)\r\n ! Rotates v about the y axis by theta (in radians)\r\n\r\n implicit none\r\n\r\n real,dimension(3),intent(in) :: v\r\n real,intent(in) :: theta\r\n real,dimension(3) :: v_rot\r\n\r\n real,dimension(3,3) :: rm(3,3) = 0.\r\n\r\n rm(1,1) = cos(theta)\r\n rm(1,3) = sin(theta)\r\n rm(2,2) = 1.0\r\n rm(3,1) = -sin(theta)\r\n rm(3,3) = cos(theta)\r\n\r\n v_rot = matmul(rm, v)\r\n\r\nend function rot_y\r\n\r\n\r\nfunction rot_z(v, theta) result(v_rot)\r\n ! Rotates v about the z axis by theta (in radians)\r\n\r\n implicit none\r\n\r\n real,dimension(3),intent(in) :: v\r\n real,intent(in) :: theta\r\n real,dimension(3) :: v_rot\r\n\r\n real,dimension(3,3) :: rm(3,3) = 0.\r\n\r\n rm(1,1) = cos(theta)\r\n rm(1,2) = -sin(theta)\r\n rm(2,1) = sin(theta)\r\n rm(2,2) = cos(theta)\r\n rm(3,3) = 1.0\r\n\r\n v_rot = matmul(rm, v)\r\n\r\nend function rot_z\r\n\r\nend module math_mod", "meta": {"hexsha": "8e2c6b0869ac5ddb5d04bca5c24ee7a4dfb41093", "size": 4573, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "common/math.f95", "max_stars_repo_name": "usuaero/MachLine", "max_stars_repo_head_hexsha": "dacc984e8430bcbff2773ff325bb471503ff47fc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2022-02-17T21:41:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T23:11:43.000Z", "max_issues_repo_path": "common/math.f95", "max_issues_repo_name": "usuaero/MachLine", "max_issues_repo_head_hexsha": "dacc984e8430bcbff2773ff325bb471503ff47fc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-01-26T02:04:43.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-07T17:07:23.000Z", "max_forks_repo_path": "common/math.f95", "max_forks_repo_name": "usuaero/MachLine", "max_forks_repo_head_hexsha": "dacc984e8430bcbff2773ff325bb471503ff47fc", "max_forks_repo_licenses": ["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.292, "max_line_length": 115, "alphanum_fraction": 0.5637437131, "num_tokens": 1599, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632856092014, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6864105229890403}} {"text": "! Fizzbuzz program in FORTRAN\n! SupreethRao99\nPROGRAM fizzbuzz\n IMPLICIT NONE\n INTEGER :: counter \n \n DO counter=0,100\n IF (MOD(counter,15) == 0) THEN\n WRITE (*,'(A8)') \"FizzBuzz\"\n ELSE IF (MOD(counter,5) == 0) THEN\n WRITE (*,'(A4)') \"Buzz\"\n ELSE IF (MOD(counter,3) == 0) THEN\n WRITE (*,'(A4)') \"Fizz\"\n ELSE \n WRITE (*,'(I2)') counter\n END IF\n END DO\n\nEND PROGRAM fizzbuzz", "meta": {"hexsha": "6239467476697f3c68d803a3ee2b9342680b865e", "size": 494, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "FORTRAN/FizzBuzz.f90", "max_stars_repo_name": "RDxR10/Hacktoberfest-2020-FizzBuzz", "max_stars_repo_head_hexsha": "c9a8e3a0ac1ff9886c013a6b5628b7f64eb0d342", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 80, "max_stars_repo_stars_event_min_datetime": "2020-10-01T00:32:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-08T21:56:09.000Z", "max_issues_repo_path": "FORTRAN/FizzBuzz.f90", "max_issues_repo_name": "RDxR10/Hacktoberfest-2020-FizzBuzz", "max_issues_repo_head_hexsha": "c9a8e3a0ac1ff9886c013a6b5628b7f64eb0d342", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 672, "max_issues_repo_issues_event_min_datetime": "2020-09-30T22:53:47.000Z", "max_issues_repo_issues_event_max_datetime": "2020-11-01T12:39:59.000Z", "max_forks_repo_path": "FORTRAN/FizzBuzz.f90", "max_forks_repo_name": "RDxR10/Hacktoberfest-2020-FizzBuzz", "max_forks_repo_head_hexsha": "c9a8e3a0ac1ff9886c013a6b5628b7f64eb0d342", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 618, "max_forks_repo_forks_event_min_datetime": "2020-09-30T22:21:12.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-31T21:28:06.000Z", "avg_line_length": 26.0, "max_line_length": 44, "alphanum_fraction": 0.479757085, "num_tokens": 147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528019683106, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.6863605987705336}} {"text": "! $UWHPSC/codes/fortran/optimize/timings.f90\n\n! Illustrate timing utilities in Fortran.\n! system_clock can be used to compute elapsed time between\n! two calls (wall time)\n! cpu_time can be used to compute CPU time used between two calls.\n\n! Try compiling with different levels of optimization, e.g. -O3\n\n\nprogram timings\n\n implicit none\n integer, parameter :: ntests = 20\n integer :: n \n real(kind=8), allocatable, dimension(:,:) :: a,b,c\n real(kind=8) :: t1, t2, elapsed_time\n integer(kind=8) :: tclock1, tclock2, clock_rate\n integer :: i,j,k,itest\n\n call system_clock(tclock1)\n\n print *, \"Will multiply n by n matrices, input n: \"\n read *, n\n\n allocate(a(n,n), b(n,n), c(n,n))\n\n ! fill a and b with 1's just for demo purposes:\n a = 1.d0\n b = 1.d0\n\n call cpu_time(t1) ! start cpu timer\n do itest=1,ntests\n do j = 1,n\n do i = 1,n\n c(i,j) = 0.d0\n do k=1,n\n c(i,j) = c(i,j) + a(i,k)*b(k,j)\n enddo\n enddo\n enddo\n enddo\n\n call cpu_time(t2) ! end cpu timer\n print 10, ntests, t2-t1\n 10 format(\"Performed \",i4, \" matrix multiplies: CPU time = \",f12.8, \" seconds\")\n\n \n call system_clock(tclock2, clock_rate)\n elapsed_time = float(tclock2 - tclock1) / float(clock_rate)\n print 11, elapsed_time\n 11 format(\"Elapsed time = \",f12.8, \" seconds\")\n\nend program timings\n\n", "meta": {"hexsha": "5d918b9b1605ac8e620164bfd35fcb03d84d78d2", "size": 1452, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/codes/fortran/timings.f90", "max_stars_repo_name": "philipwangdk/HPC", "max_stars_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "uwhpsc/codes/fortran/timings.f90", "max_issues_repo_name": "philipwangdk/HPC", "max_issues_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "uwhpsc/codes/fortran/timings.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": 25.9285714286, "max_line_length": 80, "alphanum_fraction": 0.5902203857, "num_tokens": 439, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528019683106, "lm_q2_score": 0.8056321796478255, "lm_q1q2_score": 0.6863605928068023}} {"text": "PROGRAM diffusion_test\n\nUSE omp_lib\nUSE diffusion, only : GetRHSDiffusion, InitializeDiffusion\n\nIMPLICIT NONE\n\nINCLUDE 'mpif.h'\n\nDOUBLE PRECISION, PARAMETER :: pi = 3.1415926535897932_8 ! underscore indicates rounding to real(8) precision\nINTEGER, PARAMETER :: Nthreads = 1\n\nDOUBLE PRECISION, ALLOCATABLE, DIMENSION(:,:,:,:) :: Q, RQ, RQex\nDOUBLE PRECISION :: dx, dy, dz, x, y, z\nINTEGER :: mpi_thread_provided, ierr, Nx, Ny, Nz, i, j, k, nt, &\n i_start, j_start, k_start, i_end, j_end, k_end, order, nn\n\nINTEGER, DIMENSION(6), PARAMETER :: N_v = (/ 10, 100, 200, 300, 400, 500 /)\nDOUBLE PRECISION, ALLOCATABLE, DIMENSION(:) :: err_v, convrate\n\n\nCALL MPI_INIT_THREAD(MPI_THREAD_FUNNELED, mpi_thread_provided, ierr)\n\nDO order=2,4,2\n\n i_start = 1\n j_start = 1\n k_start = 1\n\n ALLOCATE(err_v(1:SIZE(N_v)))\n ALLOCATE(convrate(1:SIZE(N_v)-1))\n\n DO nn=1,SIZE(N_v)\n\n Nx = N_v(nn)\n Ny = N_v(nn)\n Nz = N_v(nn)\n\n i_end = i_start + Nx - 1\n j_end = j_start + Ny - 1\n k_end = k_start + Nz - 1\n\n dx = 1.0/DBLE(Nx)\n dy = 1.0/DBLE(Ny)\n dz = 1.0/DBLE(Nz)\n\n ALLOCATE(Q( i_start-2:i_end+2, j_start-2:j_end+2, k_start-2:k_end+2, 0:Nthreads-1))\n ALLOCATE(RQ( i_start-2:i_end+2, j_start-2:j_end+2, k_start-2:k_end+2, 0:Nthreads-1))\n ALLOCATE(RQex(i_start-2:i_end+2, j_start-2:j_end+2, k_start-2:k_end+2, 0:Nthreads-1))\n\n CALL InitializeDiffusion(i_start-2, i_end+2, j_start-2, j_end+2, k_start-2, k_end+2, DBLE(1.0))\n !$OMP PARALLEL DO schedule(static)\n DO nt=0,Nthreads-1\n Q(:,:,:,nt) = 0.0\n RQ(:,:,:,nt) = 0.0\n END DO\n !$OMP END PARALLEL DO\n\n DO k=k_start-2,k_end+2\n DO j=j_start-2,j_end+2\n DO i=i_start-2,i_end+2\n x = 0.5*dx + DBLE(i - i_start)*dx\n y = 0.5*dy + DBLE(j - j_start)*dy\n z = 0.5*dz + DBLE(k - k_start)*dz \n \n Q(i,j,k,:) = SIN(2.0*pi*x)*SIN(2.0*pi*y)*SIN(2.0*pi*z)\n RQex(i,j,k,:) = -12.0*pi*pi*SIN(2.0*pi*x)*SIN(2.0*pi*y)*SIN(2.0*pi*z)\n \n END DO\n END DO\n END DO\n\n !$OMP PARALLEL DO schedule(static)\n DO nt=0,Nthreads-1\n CALL GetRHSDiffusion(Q(:,:,:,nt), RQ(:,:,:,nt), dx, dy, dz, i_start, i_end, j_start, j_end, k_start, k_end, order)\n END DO\n !$OMP END PARALLEL DO\n\n err_v(nn) = MAXVAL(ABS(RQ(i_start:i_end,j_start:j_end,k_start:k_end,:) & \n -RQex(i_start:i_end,j_start:j_end,k_start:k_end,:)))/MAXVAL(ABS(RQex(i_start:i_end,j_start:j_end,k_start:k_end,:)))\n \n DEALLOCATE(Q)\n DEALLOCATE(RQ)\n DEALLOCATE(RQex)\n\n END DO\n\n DO nn=2,SIZE(N_v)\n convrate(nn-1) = LOG10(err_v(nn)/err_v(nn-1)) / LOG10( DBLE(N_v(nn-1)) / DBLE(N_v(nn)) )\n END DO\n \n IF (MINVAL(convrate)<=0.95*order) THEN\n WRITE(*,'(A, I1)') 'ERROR: Failed to verify convergence order for order = ', order\n DO nn=1,SIZE(N_v)\n WRITE(*,'(F9.3)') convrate(nn)\n END DO\n STOP\n END IF\n \n DEALLOCATE(err_v)\n DEALLOCATE(convrate)\n\nEND DO\n\nCALL MPI_FINALIZE(ierr)\n\nPRINT*, '\\x1B[32m[0] -- Successful: Diffusion module produces expected rates of convergence.\\x1B[0m'\n\nEND PROGRAM diffusion_test", "meta": {"hexsha": "776ba16487a16ca637e3ed1c0c0d4832170dc19c", "size": 3369, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/src/diffusion_test.f90", "max_stars_repo_name": "Parallel-in-Time/PararealF90", "max_stars_repo_head_hexsha": "a8318a79b92465a8a3cf775cc7fd096ff0494529", "max_stars_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2017-03-17T15:04:00.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-10T08:05:52.000Z", "max_issues_repo_path": "test/src/diffusion_test.f90", "max_issues_repo_name": "Parallel-in-Time/PararealF90", "max_issues_repo_head_hexsha": "a8318a79b92465a8a3cf775cc7fd096ff0494529", "max_issues_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2015-09-23T09:08:12.000Z", "max_issues_repo_issues_event_max_datetime": "2015-09-23T09:32:24.000Z", "max_forks_repo_path": "test/src/diffusion_test.f90", "max_forks_repo_name": "Parallel-in-Time/PararealF90", "max_forks_repo_head_hexsha": "a8318a79b92465a8a3cf775cc7fd096ff0494529", "max_forks_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-10-24T20:15:26.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-10T08:05:36.000Z", "avg_line_length": 30.9082568807, "max_line_length": 127, "alphanum_fraction": 0.5666369843, "num_tokens": 1163, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527944504226, "lm_q2_score": 0.8056321843145404, "lm_q1q2_score": 0.6863605907259707}} {"text": " function dasum ( n, dx, incx )\n\nc*********************************************************************72\nc\ncc DASUM takes the sum of the absolute values.\nc\nc Discussion:\nc\nc This routine uses double precision real arithmetic.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 18 December 2008\nc\nc Author:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart\nc\nc Reference:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\nc LINPACK User's Guide,\nc SIAM, 1979,\nc ISBN13: 978-0-898711-72-1,\nc LC: QA214.L56.\nc\nc Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,\nc Basic Linear Algebra Subprograms for FORTRAN usage,\nc ACM Transactions on Mathematical Software,\nc Volume 5, Number 3, pages 308-323, 1979.\nc\nc Parameters:\nc\nc Input, integer N, the number of entries in the vector.\nc\nc Input, double precision X(*), the vector to be examined.\nc\nc Input, integer INCX, the increment between successive entries of X.\nc INCX must not be negative.\nc\nc Output, double precision DASUM, the sum of the absolute values of X.\nc\n implicit none\n\n double precision dasum\n double precision dtemp\n double precision dx(*)\n integer i\n integer incx\n integer m\n integer n\n integer nincx\n\n dasum = 0.0D+00\n dtemp = 0.0D+00\n\n if ( n .le. 0 ) then\n return\n end if\n\n if ( incx .le. 0 ) then\n return\n end if\n\n if ( incx .ne. 1 ) then\n\n nincx = n * incx\n do i = 1, nincx, incx\n dtemp = dtemp + dabs ( dx(i) )\n end do\n\n else\n\n m = mod ( n, 6 )\n\n do i = 1, m\n dtemp = dtemp + dabs ( dx(i) )\n end do\n\n do i = m + 1, n, 6\n dtemp = dtemp \n & + dabs ( dx(i) ) \n & + dabs ( dx(i+1) ) \n & + dabs ( dx(i+2) )\n & + dabs ( dx(i+3) ) \n & + dabs ( dx(i+4) ) \n & + dabs ( dx(i+5) )\n end do\n\n end if\n\n dasum = dtemp\n\n return\n end\n subroutine daxpy ( n, da, dx, incx, dy, incy )\n\nc*********************************************************************72\nc\ncc DAXPY computes constant times a vector plus a vector.\nc\nc Discussion:\nc\nc This routine uses double precision real arithmetic.\nc\nc This routine uses unrolled loops for increments equal to one.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 18 December 2008\nc\nc Author:\nc\nc Jack Dongarra\nc\nc Reference:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\nc LINPACK User's Guide,\nc SIAM, 1979,\nc ISBN13: 978-0-898711-72-1,\nc LC: QA214.L56.\nc\nc Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,\nc Basic Linear Algebra Subprograms for FORTRAN usage,\nc ACM Transactions on Mathematical Software,\nc Volume 5, Number 3, pages 308-323, 1979.\nc\nc Parameters:\nc\nc Input, integer N, the number of elements in DX and DY.\nc\nc Input, double precision DA, the multiplier of DX.\nc\nc Input, double precision DX(*), the first vector.\nc\nc Input, integer INCX, the increment between successive entries of DX.\nc\nc Input/output, double precision DY(*), the second vector.\nc On output, DY(*) has been replaced by DY(*) + DA * DX(*).\nc\nc Input, integer INCY, the increment between successive entries of DY.\nc\n implicit none\n\n double precision da\n double precision dx(*)\n double precision dy(*)\n integer i\n integer incx\n integer incy\n integer ix\n integer iy\n integer m\n integer n\n\n if ( n .le. 0 ) then\n return\n end if\n\n if ( da .eq. 0.0d0 ) then\n return\n end if\n\n if ( incx .ne. 1 .or. incy .ne. 1 ) then\n\n ix = 1\n iy = 1\n if ( incx .lt. 0 ) then\n ix = (-n+1) * incx + 1\n end if\n\n if ( incy .lt. 0 ) then\n iy = (-n+1) * incy + 1\n end if\n\n do i = 1, n\n dy(iy) = dy(iy) + da * dx(ix)\n ix = ix + incx\n iy = iy + incy\n end do\n\n else\n\n m = mod ( n, 4 )\n\n do i = 1, m\n dy(i) = dy(i) + da * dx(i)\n end do\n\n do i = m + 1, n, 4\n dy(i) = dy(i) + da * dx(i)\n dy(i + 1) = dy(i + 1) + da * dx(i + 1)\n dy(i + 2) = dy(i + 2) + da * dx(i + 2)\n dy(i + 3) = dy(i + 3) + da * dx(i + 3)\n end do\n\n end if\n\n return\n end\n subroutine dcopy ( n, dx, incx, dy, incy )\n\nc*********************************************************************72\nc\ncc DCOPY copies a vector.\nc\nc Discussion:\nc\nc This routine uses double precision real arithmetic.\nc\nc The routine uses unrolled loops for increments equal to one.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 07 July 2007\nc\nc Author:\nc\nc Jack Dongarra\nc\nc Reference:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\nc LINPACK User's Guide,\nc SIAM, 1979,\nc ISBN13: 978-0-898711-72-1,\nc LC: QA214.L56.\nc\nc Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,\nc Basic Linear Algebra Subprograms for FORTRAN usage,\nc ACM Transactions on Mathematical Software,\nc Volume 5, Number 3, pages 308-323, 1979.\nc\nc Parameters:\nc\nc Input, integer N, the number of elements in DX and DY.\nc\nc Input, double precision DX(*), the first vector.\nc\nc Input, integer INCX, the increment between successive entries of DX.\nc\nc Output, double precision DY(*), the second vector.\nc\nc Input, integer INCY, the increment between successive entries of DY.\nc\n implicit none\n\n double precision dx(*)\n double precision dy(*)\n integer i\n integer incx\n integer incy\n integer ix\n integer iy\n integer m\n integer n\n\n if ( n .le. 0 ) then\n return\n end if\n\n if ( incx .ne. 1 .or. incy .ne. 1 ) then\n\n ix = 1\n iy = 1\n if(incx.lt.0)ix = (-n+1)*incx + 1\n if(incy.lt.0)iy = (-n+1)*incy + 1\n do i = 1, n\n dy(iy) = dx(ix)\n ix = ix + incx\n iy = iy + incy\n end do\n\n else\n\n m = mod(n,7)\n\n do i = 1,m\n dy(i) = dx(i)\n end do\n\n do i = m + 1, n, 7\n dy(i) = dx(i)\n dy(i + 1) = dx(i + 1)\n dy(i + 2) = dx(i + 2)\n dy(i + 3) = dx(i + 3)\n dy(i + 4) = dx(i + 4)\n dy(i + 5) = dx(i + 5)\n dy(i + 6) = dx(i + 6)\n end do\n\n end if\n\n return\n end\n function ddot ( n, dx, incx, dy, incy )\n\nc*********************************************************************72\nc\ncc DDOT forms the dot product of two vectors.\nc\nc Discussion:\nc\nc This routine uses double precision real arithmetic.\nc\nc This routine uses unrolled loops for increments equal to one.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc \nc Modified:\nc\nc 09 February 2014\nc\nc Author:\nc\nc Original FORTRAN77 version by Jack Dongarra.\nc This version by John Burkardt\nc\nc Reference:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\nc LINPACK User's Guide,\nc SIAM, 1979,\nc ISBN13: 978-0-898711-72-1,\nc LC: QA214.L56.\nc\nc Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,\nc Basic Linear Algebra Subprograms for FORTRAN usage,\nc ACM Transactions on Mathematical Software,\nc Volume 5, Number 3, pages 308-323, 1979.\nc\nc Parameters:\nc\nc Input, integer N, the number of entries in the vectors.\nc\nc Input, double precision DX(*), the first vector.\nc\nc Input, integer INCX, the increment between successive entries in DX.\nc\nc Input, double precision DY(*), the second vector.\nc\nc Input, integer INCY, the increment between successive entries in DY.\nc\nc Output, double precision DDOT, the sum of the product of the \nc corresponding entries of DX and DY.\nc\n implicit none\n\n double precision ddot\n double precision dx(*)\n double precision dy(*)\n double precision dtemp\n integer i\n integer incx\n integer incy\n integer ix\n integer iy\n integer m\n integer n\n\n ddot = 0.0D+00\n dtemp = 0.0D+00\n\n if ( n .le. 0 ) then\n return\n end if\n\n if ( incx .eq. 1 .and. incy .eq. 1 ) then\n\n m = mod ( n, 5 )\n\n do i = 1, m\n dtemp = dtemp + dx(i) * dy(i)\n end do\n\n do i = m + 1, n, 5\n dtemp = dtemp \n & + dx(i) * dy(i) \n & + dx(i+1) * dy(i+1) \n & + dx(i+2) * dy(i+2) \n & + dx(i+3) * dy(i+3) \n & + dx(i+4) * dy(i+4)\n end do\nc\nc Code for unequal increments or equal increments not equal to 1\nc\n else\n\n if ( incx .lt. 0 ) then\n ix = ( - n + 1 ) * incx + 1\n else\n ix = 1\n end if\n\n if ( incy .lt. 0 ) then\n iy = ( - n + 1 ) * incy + 1\n else\n iy = 1\n end if\n\n do i = 1, n\n dtemp = dtemp + dx(ix) * dy(iy)\n ix = ix + incx\n iy = iy + incy\n end do\n\n end if\n\n ddot = dtemp\n\n return\n end\n function dnrm2 ( n, x, incx )\n\nc*********************************************************************72\nc\ncc DNRM2 returns the euclidean norm of a vector. \nc\nc Discussion:\nc\nc This routine uses double precision real arithmetic.\nc\nc DNRM2 ( X ) = sqrt ( X' * X )\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 09 February 2014\nc\nc Author:\nc\nc Sven Hammarling\nc\nc Reference:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\nc LINPACK User's Guide,\nc SIAM, 1979,\nc ISBN13: 978-0-898711-72-1,\nc LC: QA214.L56.\nc\nc Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,\nc Basic Linear Algebra Subprograms for FORTRAN usage,\nc ACM Transactions on Mathematical Software,\nc Volume 5, Number 3, pages 308-323, 1979.\nc\nc Parameters:\nc\nc Input, integer N, the number of entries in the vector.\nc\nc Input, double precision X(*), the vector whose norm is to be computed.\nc\nc Input, integer INCX, the increment between successive entries of X.\nc\nc Output, double precision DNRM2, the Euclidean norm of X.\nc\n implicit none\n\n integer incx, n\n\n double precision dnrm2 \n double precision x( * )\n\n double precision one , zero\n parameter ( one = 1.0d+0, zero = 0.0d+0 )\n\n integer ix\n double precision absxi, norm, scale, ssq\n\n intrinsic abs, sqrt\n\n if( n.lt.1 .or. incx.lt.1 )then\n norm = zero\n else if( n.eq.1 )then\n norm = abs( x( 1 ) )\n else\n scale = zero\n ssq = one\nc\nc The following loop is equivalent to this call to the LAPACK\nc auxiliary routine:\nc call dlassq( n, x, incx, scale, ssq )\nc\n do ix = 1, 1 + ( n - 1 )*incx, incx\n if( x( ix ).ne.zero )then\n absxi = abs( x( ix ) )\n if( scale.lt.absxi )then\n ssq = one + 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 norm = scale * sqrt( ssq )\n end if\n\n dnrm2 = norm\n\n return\n end\n subroutine drot ( n, dx, incx, dy, incy, c, s )\n\nc*********************************************************************72\nc\ncc DROT applies a plane rotation.\nc\nc Discussion:\nc\nc This routine uses double precision real arithmetic.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 07 July 2007\nc\nc Author:\nc\nc Jack Dongarra\nc\nc Reference:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\nc LINPACK User's Guide,\nc SIAM, 1979,\nc ISBN13: 978-0-898711-72-1,\nc LC: QA214.L56.\nc\nc Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,\nc Basic Linear Algebra Subprograms for FORTRAN usage,\nc ACM Transactions on Mathematical Software,\nc Volume 5, Number 3, pages 308-323, 1979.\nc\nc Parameters:\nc\nc Input, integer N, the number of entries in the vectors.\nc\nc Input/output, double precision X(*), one of the vectors to be rotated.\nc\nc Input, integer INCX, the increment between successive entries of X.\nc\nc Input/output, double precision Y(*), one of the vectors to be rotated.\nc\nc Input, integer INCY, the increment between successive elements of Y.\nc\nc Input, double precision C, S, parameters (presumably the cosine and\nc sine of some angle) that define a plane rotation.\nc\n implicit none\n\n double precision c\n double precision dtemp\n double precision dx(*)\n double precision dy(*)\n double precision s\n integer i,incx,incy,ix,iy,n\n\n if ( n .le. 0 ) then\n return\n end if\n\n if(incx.eq.1.and.incy.eq.1)go to 20\nc\nc code for unequal increments or equal increments not equal to 1\nc\n ix = 1\n iy = 1\n if(incx.lt.0) then\n ix = (-n+1)*incx + 1\n end if\n\n if(incy.lt.0) then\n iy = (-n+1)*incy + 1\n end if\n\n do i = 1,n\n dtemp = c*dx(ix) + s*dy(iy)\n dy(iy) = c*dy(iy) - s*dx(ix)\n dx(ix) = dtemp\n ix = ix + incx\n iy = iy + incy\n end do\n return\nc\nc code for both increments equal to 1\nc\n 20 do i = 1,n\n dtemp = c*dx(i) + s*dy(i)\n dy(i) = c*dy(i) - s*dx(i)\n dx(i) = dtemp\n end do\n\n return\n end\n subroutine drotg ( da, db, c, s )\n\nc*********************************************************************72\nc\ncc DROTG constructs a Givens plane rotation.\nc\nc Discussion:\nc\nc This routine uses double precision real arithmetic.\nc\nc Given values A and B, this routine computes\nc\nc SIGMA = sign ( A ) if abs ( A ) > abs ( B )\nc = sign ( B ) if abs ( A ) <= abs ( B );\nc\nc R = SIGMA * ( A * A + B * B );\nc\nc C = A / R if R is not 0\nc = 1 if R is 0;\nc\nc S = B / R if R is not 0,\nc 0 if R is 0.\nc\nc The computed numbers then satisfy the equation\nc\nc ( C S ) ( A ) = ( R )\nc ( -S C ) ( B ) = ( 0 )\nc\nc The routine also computes\nc\nc Z = S if abs ( A ) > abs ( B ),\nc = 1 / C if abs ( A ) <= abs ( B ) and C is not 0,\nc = 1 if C is 0.\nc\nc The single value Z encodes C and S, and hence the rotation:\nc\nc If Z = 1, set C = 0 and S = 1;\nc If abs ( Z ) < 1, set C = sqrt ( 1 - Z * Z ) and S = Z;\nc if abs ( Z ) > 1, set C = 1/ Z and S = sqrt ( 1 - C * C );\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 07 July 2007\nc\nc Author:\nc\nc Jack Dongarra\nc\nc Reference:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\nc LINPACK User's Guide,\nc SIAM, 1979,\nc ISBN13: 978-0-898711-72-1,\nc LC: QA214.L56.\nc\nc Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,\nc Basic Linear Algebra Subprograms for FORTRAN usage,\nc ACM Transactions on Mathematical Software,\nc Volume 5, Number 3, pages 308-323, 1979.\nc\nc Parameters:\nc\nc Input/output, double precision SA, SB. On input, SA and SB are the values\nc A and B. On output, SA is overwritten with R, and SB is\nc overwritten with Z.\nc\nc Output, double precision C, S, the cosine and sine of the\nc Givens rotation.\nc\n implicit none\n\n double precision c\n double precision da\n double precision db,s,roe,scale,r,z\n\n roe = db\n if( dabs(da) .gt. dabs(db) ) roe = da\n scale = dabs(da) + dabs(db)\n\n if( scale .eq. 0.0d0 ) then\n c = 1.0d0\n s = 0.0d0\n r = 0.0d0\n z = 0.0d0\n else\n r = scale*dsqrt((da/scale)**2 + (db/scale)**2)\n r = dsign(1.0d0,roe)*r\n c = da/r\n s = db/r\n z = 1.0d0\n if( dabs(da) .gt. dabs(db) ) z = s\n if( dabs(db) .ge. dabs(da) .and. c .ne. 0.0d0 ) z = 1.0d0/c\n end if\n\n da = r\n db = z\n\n return\n end\n subroutine drotm ( n, dx, incx, dy, incy, dparam )\n\nc*********************************************************************72\nc\ncc DROTM applies a modified Givens rotation matrix.\nc\nc Purpose\nc =======\nc\nc APPLY THE MODIFIED GIVENS TRANSFORMATION, H, TO THE 2 BY N MATRIX\nc\nc (DX**T) , WHERE **T INDICATES TRANSPOSE. THE ELEMENTS OF DX ARE IN\nc (DY**T)\nc\nc DX(LX+I*INCX), I = 0 TO N-1, WHERE LX = 1 IF INCX .GE. 0, ELSE\nc LX = (-INCX)*N, AND SIMILARLY FOR SY USING LY AND INCY.\nc WITH DPARAM(1)=DFLAG, H HAS ONE OF THE FOLLOWING FORMS..\nc\nc DFLAG=-1.D0 DFLAG=0.D0 DFLAG=1.D0 DFLAG=-2.D0\nc\nc (DH11 DH12) (1.D0 DH12) (DH11 1.D0) (1.D0 0.D0)\nc H=( ) ( ) ( ) ( )\nc (DH21 DH22), (DH21 1.D0), (-1.D0 DH22), (0.D0 1.D0).\nc SEE DROTMG FOR A DESCRIPTION OF DATA STORAGE IN DPARAM.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 09 February 2014\nc\nc Author:\nc\nc Original FORTRAN77 version by Jack Dongarra.\nc This version by John Burkardt\nc\nc Arguments\nc =========\nc\nc N (input) INTEGER\nc number of elements in input vector(s)\nc\nc DX (input/output) DOUBLE PRECISION array, dimension N\nc double precision vector with N elements\nc\nc INCX (input) INTEGER\nc storage spacing between elements of DX\nc\nc DY (input/output) DOUBLE PRECISION array, dimension N\nc double precision vector with N elements\nc\nc INCY (input) INTEGER\nc storage spacing between elements of DY\nc\nc DPARAM (input/output) DOUBLE PRECISION array, dimension 5 \nc DPARAM(1)=DFLAG\nc DPARAM(2)=DH11\nc DPARAM(3)=DH21\nc DPARAM(4)=DH12\nc DPARAM(5)=DH22\nc\n integer incx,incy,n\n\n double precision dparam(5),dx(*),dy(*)\n double precision dflag,dh11,dh12,dh21,dh22,two,w,z,zero\n integer i,kx,ky,nsteps\n\n data zero,two/0.d0,2.d0/\n\n dflag = dparam(1)\n if (n.le.0 .or. (dflag+two.eq.zero)) return\n if (incx.eq.incy.and.incx.gt.0) then\n\n nsteps = n*incx\n if (dflag.lt.zero) then\n dh11 = dparam(2)\n dh12 = dparam(4)\n dh21 = dparam(3)\n dh22 = dparam(5)\n do i = 1,nsteps,incx\n w = dx(i)\n z = dy(i)\n dx(i) = w*dh11 + z*dh12\n dy(i) = w*dh21 + z*dh22\n end do\n else if (dflag.eq.zero) then\n dh12 = dparam(4)\n dh21 = dparam(3)\n do i = 1,nsteps,incx\n w = dx(i)\n z = dy(i)\n dx(i) = w + z*dh12\n dy(i) = w*dh21 + z\n end do\n else\n dh11 = dparam(2)\n dh22 = dparam(5)\n do i = 1,nsteps,incx\n w = dx(i)\n z = dy(i)\n dx(i) = w*dh11 + z\n dy(i) = -w + dh22*z\n end do\n end if\n else\n kx = 1\n ky = 1\n if (incx.lt.0) kx = 1 + (1-n)*incx\n if (incy.lt.0) ky = 1 + (1-n)*incy\n*\n if (dflag.lt.zero) then\n dh11 = dparam(2)\n dh12 = dparam(4)\n dh21 = dparam(3)\n dh22 = dparam(5)\n do i = 1,n\n w = dx(kx)\n z = dy(ky)\n dx(kx) = w*dh11 + z*dh12\n dy(ky) = w*dh21 + z*dh22\n kx = kx + incx\n ky = ky + incy\n end do\n else if (dflag.eq.zero) then\n dh12 = dparam(4)\n dh21 = dparam(3)\n do i = 1,n\n w = dx(kx)\n z = dy(ky)\n dx(kx) = w + z*dh12\n dy(ky) = w*dh21 + z\n kx = kx + incx\n ky = ky + incy\n end do\n else\n dh11 = dparam(2)\n dh22 = dparam(5)\n do i = 1,n\n w = dx(kx)\n z = dy(ky)\n dx(kx) = w*dh11 + z\n dy(ky) = -w + dh22*z\n kx = kx + incx\n ky = ky + incy\n end do\n end if\n end if\n return\n end\n subroutine drotmg(dd1,dd2,dx1,dy1,dparam)\n\nc*********************************************************************72\nc\ncc DROTMG generates a modified Givens rotation matrix.\nc\n* Purpose\n* =======\n*\n* CONSTRUCT THE MODIFIED GIVENS TRANSFORMATION MATRIX H WHICH ZEROS\n* THE SECOND COMPONENT OF THE 2-VECTOR (DSQRT(DD1)*DX1,DSQRT(DD2)*\n* DY2)**T.\n* WITH DPARAM(1)=DFLAG, H HAS ONE OF THE FOLLOWING FORMS..\n*\n* DFLAG=-1.D0 DFLAG=0.D0 DFLAG=1.D0 DFLAG=-2.D0\n*\n* (DH11 DH12) (1.D0 DH12) (DH11 1.D0) (1.D0 0.D0)\n* H=( ) ( ) ( ) ( )\n* (DH21 DH22), (DH21 1.D0), (-1.D0 DH22), (0.D0 1.D0).\n* LOCATIONS 2-4 OF DPARAM CONTAIN DH11, DH21, DH12, AND DH22\n* RESPECTIVELY. (VALUES OF 1.D0, -1.D0, OR 0.D0 IMPLIED BY THE\n* VALUE OF DPARAM(1) ARE NOT STORED IN DPARAM.)\n*\n* THE VALUES OF GAMSQ AND RGAMSQ SET IN THE DATA STATEMENT MAY BE\n* INEXACT. THIS IS OK AS THEY ARE ONLY USED FOR TESTING THE SIZE\n* OF DD1 AND DD2. ALL ACTUAL SCALING OF DATA IS DONE USING GAM.\n*\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 09 February 2014\nc\n* Arguments\n* =========\n*\n* DD1 (input/output) DOUBLE PRECISION\n*\n* DD2 (input/output) DOUBLE PRECISION\n*\n* DX1 (input/output) DOUBLE PRECISION\n*\n* DY1 (input) DOUBLE PRECISION\n*\n* DPARAM (input/output) DOUBLE PRECISION array, dimension 5\n* DPARAM(1)=DFLAG\n* DPARAM(2)=DH11\n* DPARAM(3)=DH21\n* DPARAM(4)=DH12\n* DPARAM(5)=DH22\n*\n double precision dd1,dd2,dx1,dy1\n double precision dparam(5)\n double precision dflag,dh11,dh12,dh21,dh22,dp1,dp2,dq1,dq2,dtemp,\n $ du,gam,gamsq,one,rgamsq,two,zero\n* ..\n* .. intrinsic functions ..\n intrinsic dabs\n* ..\n* .. data statements ..\n*\n data zero,one,two/0.d0,1.d0,2.d0/\n data gam,gamsq,rgamsq/4096.d0,16777216.d0,5.9604645d-8/\n* ..\n\n if (dd1.lt.zero) then\n* go zero-h-d-and-dx1..\n dflag = -one\n dh11 = zero\n dh12 = zero\n dh21 = zero\n dh22 = zero\n dd1 = zero\n dd2 = zero\n dx1 = zero\n else\n* case-dd1-nonnegative\n dp2 = dd2*dy1\n if (dp2.eq.zero) then\n dflag = -two\n dparam(1) = dflag\n return\n end if \n* regular-case..\n dp1 = dd1*dx1\n dq2 = dp2*dy1\n dq1 = dp1*dx1\n*\n if (dabs(dq1).gt.dabs(dq2)) then\n dh21 = -dy1/dx1\n dh12 = dp2/dp1\n*\n du = one - dh12*dh21\n*\n if (du.gt.zero) then\n dflag = zero\n dd1 = dd1/du\n dd2 = dd2/du\n dx1 = dx1*du\n end if\n else\n\n if (dq2.lt.zero) then\n* go zero-h-d-and-dx1..\n dflag = -one\n dh11 = zero\n dh12 = zero\n dh21 = zero\n dh22 = zero\n*\n dd1 = zero\n dd2 = zero\n dx1 = zero\n else\n dflag = one\n dh11 = dp1/dp2\n dh22 = dx1/dy1\n du = one + dh11*dh22\n dtemp = dd2/du\n dd2 = dd1/du\n dd1 = dtemp\n dx1 = dy1*du\n end if\n end if\n\n* procedure..scale-check\n if (dd1.ne.zero) then\n do while ((dd1.le.rgamsq) .or. (dd1.ge.gamsq))\n if (dflag.eq.zero) then\n dh11 = one\n dh22 = one\n dflag = -one\n else\n dh21 = -one\n dh12 = one\n dflag = -one\n end if\n if (dd1.le.rgamsq) then\n dd1 = dd1*gam**2\n dx1 = dx1/gam\n dh11 = dh11/gam\n dh12 = dh12/gam\n else\n dd1 = dd1/gam**2\n dx1 = dx1*gam\n dh11 = dh11*gam\n dh12 = dh12*gam\n end if\n enddo\n end if\n \n if (dd2.ne.zero) then\n do while ( (dabs(dd2).le.rgamsq) .or. (dabs(dd2).ge.gamsq) )\n if (dflag.eq.zero) then\n dh11 = one\n dh22 = one\n dflag = -one\n else\n dh21 = -one\n dh12 = one\n dflag = -one\n end if\n if (dabs(dd2).le.rgamsq) then\n dd2 = dd2*gam**2\n dh21 = dh21/gam\n dh22 = dh22/gam\n else\n dd2 = dd2/gam**2\n dh21 = dh21*gam\n dh22 = dh22*gam\n end if \n end do\n end if\n \n end if\n\n if (dflag.lt.zero) then\n dparam(2) = dh11\n dparam(3) = dh21\n dparam(4) = dh12\n dparam(5) = dh22\n else if (dflag.eq.zero) then\n dparam(3) = dh21\n dparam(4) = dh12 \n else\n dparam(2) = dh11\n dparam(5) = dh22\n end if\n\n dparam(1) = dflag\n\n return\n end\n subroutine dscal ( n, da, dx, incx )\n\nc*********************************************************************72\nc\ncc DSCAL scales a vector by a constant.\nc\nc Discussion:\nc\nc This routine uses double precision real arithmetic.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc \nc Modified:\nc\nc 09 February 2014\nc\nc Author:\nc\nc Original FORTRAN77 version by Jack Dongarra.\nc This version by John Burkardt.\nc\nc Reference:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\nc LINPACK User's Guide,\nc SIAM, 1979,\nc ISBN13: 978-0-898711-72-1,\nc LC: QA214.L56.\nc\nc Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,\nc Basic Linear Algebra Subprograms for FORTRAN usage,\nc ACM Transactions on Mathematical Software,\nc Volume 5, Number 3, pages 308-323, 1979.\nc\nc Parameters:\nc\nc Input, integer N, the number of entries in the vector.\nc\nc Input, double precision SA, the multiplier.\nc\nc Input/output, double precision X(*), the vector to be scaled.\nc\nc Input, integer INCX, the increment between successive entries of X.\nc\n implicit none\n\n double precision da\n double precision dx(*)\n integer i\n integer incx\n integer m\n integer n\n integer nincx\n\n if ( n .le. 0 ) then\n return\n end if\n\n if ( incx .le. 0 ) then\n return\n end if\n\n if ( incx .eq. 1 ) then\n\n m = mod ( n, 5 )\n\n do i = 1, m\n dx(i) = da * dx(i)\n end do\n\n do i = m + 1, n, 5\n dx(i) = da * dx(i)\n dx(i+1) = da * dx(i+1)\n dx(i+2) = da * dx(i+2)\n dx(i+3) = da * dx(i+3)\n dx(i+4) = da * dx(i+4)\n end do\n\n else\n\n nincx = n * incx\n do i = 1, nincx, incx\n dx(i) = da * dx(i)\n end do\n end if\n\n return\n end\n function dsdot ( n, sx, incx, sy, incy )\n\nc*********************************************************************72\nc\ncc DSDOT computes the inner product of two vectors with extended precision.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\n* ..\n*\n* AUTHORS\n* =======\n* Lawson, C. L., (JPL), Hanson, R. J., (SNLA), \n* Kincaid, D. R., (U. of Texas), Krogh, F. T., (JPL)\n*\n* Purpose\n* =======\n* Compute the inner product of two vectors with extended\n* precision accumulation and result.\n*\n* Returns D.P. dot product accumulated in D.P., for S.P. SX and SY\n* DSDOT = sum for I = 0 to N-1 of SX(LX+I*INCX) * SY(LY+I*INCY),\n* where LX = 1 if INCX .GE. 0, else LX = 1+(1-N)*INCX, and LY is\n* defined in a similar way using INCY.\n*\n* Arguments\n* =========\n*\n* N (input) INTEGER\n* number of elements in input vector(s)\n*\n* SX (input) REAL array, dimension(N)\n* single precision vector with N elements\n*\n* INCX (input) INTEGER\n* storage spacing between elements of SX\n*\n* SY (input) REAL array, dimension(N)\n* single precision vector with N elements\n*\n* INCY (input) INTEGER\n* storage spacing between elements of SY\n*\n* DSDOT (output) DOUBLE PRECISION\n* DSDOT double precision dot product (zero if N.LE.0)\n*\n* Further Details\n* ===============\n*\n* REFERENCES\n* \n* C. L. Lawson, R. J. Hanson, D. R. Kincaid and F. T.\n* Krogh, Basic linear algebra subprograms for Fortran\n* usage, Algorithm No. 539, Transactions on Mathematical\n* Software 5, 3 (September 1979), pp. 308-323.\nc\n double precision dsdot\n INTEGER INCX,INCY,N\n REAL SX(*),SY(*)\n integer i,kx,ky,ns\n\n intrinsic dble\n\n dsdot = 0.0d0\n if (n.le.0) return\n if (incx.eq.incy .and. incx.gt.0) then\nc\nc code for equal, positive, non-unit increments.\nc\n ns = n*incx\n do i = 1,ns,incx\n dsdot = dsdot + dble(sx(i))*dble(sy(i))\n end do\n else\nc\nc code for unequal or nonpositive increments.\nc\n kx = 1\n ky = 1\n if (incx.lt.0) kx = 1 + (1-n)*incx\n if (incy.lt.0) ky = 1 + (1-n)*incy\n do i = 1,n\n dsdot = dsdot + dble(sx(kx))*dble(sy(ky))\n kx = kx + incx\n ky = ky + incy\n end do\n end if\n\n return\n end\n subroutine dswap ( n, dx, incx, dy, incy )\n\nc*********************************************************************72\nc\ncc DSWAP interchanges two vectors.\nc\nc Discussion:\nc\nc This routine uses double precision real arithmetic.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 07 July 2007\nc\nc Author:\nc\nc Jack Dongarra\nc\nc Reference:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\nc LINPACK User's Guide,\nc SIAM, 1979,\nc ISBN13: 978-0-898711-72-1,\nc LC: QA214.L56.\nc\nc Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,\nc Basic Linear Algebra Subprograms for FORTRAN usage,\nc ACM Transactions on Mathematical Software,\nc Volume 5, Number 3, pages 308-323, 1979.\nc\nc Parameters:\nc\nc Input, integer N, the number of entries in the vectors.\nc\nc Input/output, double precision X(*), one of the vectors to swap.\nc\nc Input, integer INCX, the increment between successive entries of X.\nc\nc Input/output, double precision Y(*), one of the vectors to swap.\nc\nc Input, integer INCY, the increment between successive elements of Y.\nc\n implicit none\n\n double precision dx(*),dy(*),dtemp\n integer i,incx,incy,ix,iy,m,n\n\n if(n.le.0)return\n if(incx.eq.1.and.incy.eq.1)go to 20\nc\nc code for unequal increments or equal increments not equal to 1\nc\n ix = 1\n iy = 1\n if(incx.lt.0)ix = (-n+1)*incx + 1\n if(incy.lt.0)iy = (-n+1)*incy + 1\n do i = 1,n\n dtemp = dx(ix)\n dx(ix) = dy(iy)\n dy(iy) = dtemp\n ix = ix + incx\n iy = iy + incy\n end do\n return\nc\nc code for both increments equal to 1\nc\nc\nc clean-up loop\nc\n 20 m = mod(n,3)\n if( m .eq. 0 ) go to 40\n do i = 1,m\n dtemp = dx(i)\n dx(i) = dy(i)\n dy(i) = dtemp\n end do\n if( n .lt. 3 ) return\n 40 continue\n\n do i = m+1, n, 3\n dtemp = dx(i)\n dx(i) = dy(i)\n dy(i) = dtemp\n dtemp = dx(i + 1)\n dx(i + 1) = dy(i + 1)\n dy(i + 1) = dtemp\n dtemp = dx(i + 2)\n dx(i + 2) = dy(i + 2)\n dy(i + 2) = dtemp\n end do\n\n return\n end\n function idamax ( n, dx, incx )\n\nc*********************************************************************72\nc\ncc IDAMAX finds the index of element having maximum absolute value.\nc\nc Discussion:\nc\nc This routine uses double precision real arithmetic.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 07 July 2007\nc\nc Author:\nc\nc Jack Dongarra\nc\nc Reference:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\nc LINPACK User's Guide,\nc SIAM, 1979,\nc ISBN13: 978-0-898711-72-1,\nc LC: QA214.L56.\nc\nc Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,\nc Basic Linear Algebra Subprograms for FORTRAN usage,\nc ACM Transactions on Mathematical Software,\nc Volume 5, Number 3, pages 308-323, 1979.\nc\nc Parameters:\nc\nc Input, integer N, the number of entries in the vector.\nc\nc Input, double precision X(*), the vector to be examined.\nc\nc Input, integer INCX, the increment between successive entries of SX.\nc\nc Output, integer IDAMAX, the index of the element of SX of maximum\nc absolute value.\nc\n implicit none\n\n double precision dmax\n double precision dx(*)\n integer i\n integer idamax\n integer incx\n integer ix\n integer n\n\n idamax = 0\n if ( n .lt. 1 .or. incx .le. 0 ) then\n return\n end if\n\n idamax = 1\n if ( n .eq. 1 ) then\n return\n end if\n\n if ( incx .eq. 1 ) then\n\n dmax = dabs ( dx(1) )\n do i = 2, n\n if( dmax .lt. dabs ( dx(i) ) ) then\n idamax = i\n dmax = dabs ( dx(i) )\n end if\n end do\n\n else\n\n ix = 1\n dmax = dabs ( dx(1) )\n ix = ix + incx\n do i = 2, n\n if ( dmax .lt. dabs ( dx(ix) ) ) then\n idamax = i\n dmax = dabs ( dx(ix) )\n end if\n ix = ix + incx\n end do\n\n end if\n\n return\n end\n", "meta": {"hexsha": "c6172168dd794b9a7e0a736d694ca66339f2e43a", "size": 33846, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "blas1_d/blas1_d.f", "max_stars_repo_name": "SourangshuGhosh/Basic-Linear-Algebra-Subprograms", "max_stars_repo_head_hexsha": "5b8b011a1acac19193203c54a97ebeed56fed6d3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-07-29T09:14:47.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-14T17:38:52.000Z", "max_issues_repo_path": "blas1_d/blas1_d.f", "max_issues_repo_name": "SourangshuGhosh/Basic-Linear-Algebra-Subprograms", "max_issues_repo_head_hexsha": "5b8b011a1acac19193203c54a97ebeed56fed6d3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "blas1_d/blas1_d.f", "max_forks_repo_name": "SourangshuGhosh/Basic-Linear-Algebra-Subprograms", "max_forks_repo_head_hexsha": "5b8b011a1acac19193203c54a97ebeed56fed6d3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.5041666667, "max_line_length": 79, "alphanum_fraction": 0.5223069196, "num_tokens": 10839, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232489352, "lm_q2_score": 0.8418256412990658, "lm_q1q2_score": 0.6862836131565813}} {"text": "c Subroutine to find dew point from vapor pressure\r\nc AJ_Kettle, Nov7/2017\r\n\r\nc from wmo_8_en-2012.pdf\r\n\r\n SUBROUTINE dewp_from_vpres_stnpres(f_ew_hpa,f_p_hpa,\r\n + f_dewp_c)\r\n\r\n IMPLICIT NONE\r\nc************************************************************************\r\n REAL :: f_dewp_c \r\n\r\n REAL :: f_ew_hpa\r\n REAL :: f_p_hpa \r\n\r\n REAL :: f_p_coef\r\nc************************************************************************\r\nc Find pressure coefficient\r\n f_p_coef=1.0016+3.15*10.0**(-6.0)*f_p_hpa-0.074/f_p_hpa\r\n\r\n f_dewp_c=(243.12*ALOG(f_ew_hpa/(6.112*f_p_coef)))/\r\n + (17.62-ALOG(f_ew_hpa/(6.112*f_p_coef)))\r\n\r\nc f_dewp_c=(243.12*ALOG(f_ew_pa/611.2))/(17.62-ALOG(f_ew_pa/611.2))\r\nc************************************************************************\r\n RETURN\r\n END", "meta": {"hexsha": "d1c5c2acf382fafa96bed9f179333ed5704dd54c", "size": 916, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "P20171014_dwdsub/Subroutine/dewp_from_vpres_stnpres.f", "max_stars_repo_name": "ajkettle/glamod-nuim", "max_stars_repo_head_hexsha": "beb37a3c2acab3f334918dda3e366c7882cc0960", "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": "P20171014_dwdsub/Subroutine/dewp_from_vpres_stnpres.f", "max_issues_repo_name": "ajkettle/glamod-nuim", "max_issues_repo_head_hexsha": "beb37a3c2acab3f334918dda3e366c7882cc0960", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 23, "max_issues_repo_issues_event_min_datetime": "2022-01-28T13:57:39.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T09:34:41.000Z", "max_forks_repo_path": "P20171014_dwdsub/Subroutine/dewp_from_vpres_stnpres.f", "max_forks_repo_name": "ajkettle/glamod-nuim", "max_forks_repo_head_hexsha": "beb37a3c2acab3f334918dda3e366c7882cc0960", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-01-24T12:06:06.000Z", "max_forks_repo_forks_event_max_datetime": "2019-01-24T12:06:06.000Z", "avg_line_length": 33.9259259259, "max_line_length": 74, "alphanum_fraction": 0.4181222707, "num_tokens": 257, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9678992951349231, "lm_q2_score": 0.7090191460821871, "lm_q1q2_score": 0.686259131730114}} {"text": "module ode\n !! Module for solving first order explicit ordinary differential equations, expressed in the form:\n !! \\[\n !! \\frac{dy}{dt}=F\\left(y,t\\right)\\\\\n !! y(0) = y_0\n !! \\]\n !! where, \\(y(t)\\) is the unknown function, \\(t\\) is the independent variable and\n !! \\(y_0\\) is the initial condition.\n implicit none\n contains\n\n function forward_euler(f,t,U0) result(U)\n !! function for integrating vector first order ODEs of the form:\n !! \\[\n !! \\frac{d\\mathbf{U}}{dt}=\\mathbf{F}\\left(\\mathbf{U},t\\right)\n !! \\]\n !! using the forward (explicit) euler method.\n interface\n function f(U,t) result(dU)\n !! function \\(\\mathbf{F}\\) of the system\n real, intent(in) :: U(:)\n !! value of the unknown function \\(\\mathbf{U}(t)\\)\n real, intent(in) :: t\n !! independent variable \\(t\\)\n real :: dU(size(U))\n !! derivative of \\(\\mathbf{y}\\)\n end function\n end interface\n real, intent(in) :: t(0:)\n !! array of times \\( t_0,t_1,\\dots,t_N \\)where the numerical solution\n !! will be evaluated.\n real, intent(in) :: U0(:)\n !! initial conditions \\(\\mathbf{U}(t_0)\\)\n real :: U(0:ubound(t,1),size(U0))\n !! solution array \\(U_j(t_i)\\) such that the\n !! the row \\(i\\) and column \\(j\\) stands for the\n !! \\(j\\)th component of the vector solution \\(\\mathbf{U}\\) at time \\(t_i\\).\n integer :: N, i\n N = ubound(t,1)\n U(0,:) = U0\n do i=1,N\n U(i,:) = U(i-1,:) + (t(i)-t(i-1))*F(U(i-1,:),t(i-1))\n end do\n end function\n\nend module\n", "meta": {"hexsha": "6f644381ed2382ac1395c331ff012f6146b927ad", "size": 1733, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "docs/src/ode.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/ode.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/ode.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": 36.8723404255, "max_line_length": 100, "alphanum_fraction": 0.5020196192, "num_tokens": 494, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096112990285, "lm_q2_score": 0.7490872243177518, "lm_q1q2_score": 0.6862460058988037}} {"text": "! *******************************************************************\r\n! * *\r\n! * Function dlspx3 *\r\n! * *\r\n! *******************************************************************\r\n! Double Precision Version 1.42\r\n! Written by Gordon A. Fenton, Mar. 25, 1994\r\n! Latest Update: Sep 21, 2001\r\n!\r\n! PURPOSE returns the covariance between two points in a 3-D random field\r\n! having an exponential (Gaussian) type covariance function\r\n! (separable and mean-square differentiable).\r\n!\r\n! This function returns the covariance between two points separated\r\n! by lag vector {X,Y,Z}. The process has a separable and mean-square\r\n! differentiable covariance function,\r\n!\r\n! B(X,Y,Z) = var * exp{ -pi*[(|X|/thx)^2 + (|Y|/thy)^2 + (|Z|/thz)^2] }\r\n!\r\n! where var is the point variance, thx, thy, and thz are the directional\r\n! scales of fluctuation and (X,Y,Z) are elements of the lag vector\r\n! separating the two points of interest.\r\n!\r\n! The parameters var, dthx, dthy, and dthz are brought into this\r\n! routine through the common block /dparam/.\r\n!\r\n! If var < 0, then this function computes the variance of a local average\r\n! of the random field, averaged over a domain having side dimensions {X,Y,Z}.\r\n! The variance function is also separable and can be written\r\n! as the product of three one-d variance functions\r\n!\r\n! V(X,Y,Z) = V(X)*V(Y)*V(Z)\r\n!\r\n! each corresponding to the 1-D Gaussian type correlation function,\r\n!\r\n! p(x) = exp{-pi*(|x|/thx)^2}\r\n!\r\n! The individual variance functions are based on the 1-D analytical model\r\n!\r\n! V(X) = (1/a*a) * [pi*(|X|/thx)*erf(a) + exp(-a*a) - 1]\r\n!\r\n! where a = (|X|*sqrt(pi))/thx and erf(.) is the error function.\r\n! See page 186 of \"Random Fields\" by E. Vanmarcke and G.A. Fenton's thesis\r\n! for more details. If var < 0, this function returns |var|*V(X,Y,Z).\r\n!\r\n! The arguments to this routine, X, Y, and Z, are the components of the\r\n! lag vector between the two points of interest (or the dimensions of the\r\n! averaging volume, if var < 0)\r\n!\r\n! The data value `eund' is designed to avoid underflow errors arising from\r\n! exp(-a) for a > eund. We quite happily accept a zero in this case. This\r\n! tends to be compiler dependent.\r\n!\r\n! Requires:\r\n! 1) from Fortran lib: d_erf\t(error function), define the following\r\n!\tr_erf(s) = d_erf(s) (on SunOS 4.1.3)\r\n!\tr_erf(s) = derf(s) (on DEC OSF/1)\r\n!\r\n! REVISION HISTORY:\r\n! 1.1\teliminated unused local variables `two' and `four' (Dec 5/96)\r\n! 1.2\tadded lvarfn flag to end of /dparam/ common block. Set it to\r\n!\ttrue if the variance function is to be returned. Otherwise this\r\n!\tfunction returns the covariance. (May 31/00)\r\n! 1.3\teliminated lvarfn -- now return covariances only if var < 0 (Apr 9/01)\r\n! 1.4\treversed default - now return covariances if var > 0. (Apr 11/01)\r\n! 1.41\trevised above documentation to reflect revision 1.4 (May 9/01)\r\n! 1.42\treplaced 'dthx' with 'thx' (etc) below (Sep 21/01)\r\n!---------------------------------------------------------------------------\r\n real*8 function dlspx3( X, Y, Z )\r\n implicit real*8 (a-h,o-z)\r\n common/dparam/ var, pb, thx, thy, thz\r\n data zero/0.d0/, one/1.d0/\r\n data rtpi/1.77245385090551588d0/, eund/300.d0/\r\n data pi/3.1415926535897932384d0/\r\n exp(s) = dexp(s)\r\n abs(s) = dabs(s)\r\n r_erf(s) = derf(s)\r\n\r\n if( var .lt. zero ) then\t\t\t! return variance of local ave\r\n rx = abs(X)/thx\r\n a = rtpi*rx\r\n aa = a*a\r\n ry = abs(Y)/thy\r\n b = rtpi*ry\r\n bb = b*b\r\n rz = abs(Z)/thz\r\n c = rtpi*rz\r\n cc = c*c\r\n!\t\t\t\t\t\t\tin the x direction\r\n if( X .eq. zero ) then\r\n dsepa = one\r\n elseif( aa .lt. eund ) then\r\n dsepa = (pi*rx*r_erf(a) + exp(-aa) - one)/aa\r\n else\r\n dsepa = (pi*rx - one)/aa\r\n endif\r\n!\t\t\t\t\t\t\tin the y direction\r\n if( Y .eq. zero ) then\r\n dsepb = one\r\n elseif( bb .lt. eund ) then\r\n dsepb = (pi*ry*r_erf(b) + exp(-bb) - one)/bb\r\n else\r\n dsepb = (pi*ry - one)/bb\r\n endif\r\n!\t\t\t\t\t\t\tand in the z direction\r\n if( Z .eq. zero ) then\r\n dsepc = one\r\n elseif( cc .lt. eund ) then\r\n dsepc = (pi*rz*r_erf(c) + exp(-cc) - one)/cc\r\n else\r\n dsepc = (pi*rz - one)/cc\r\n endif\r\n dlspx3 = -var*dsepa*dsepb*dsepc\r\n\r\n else\t\t\t\t\t! return covariance\r\n!\t\t\t\t\t\t\tin the x direction\r\n if( thx .eq. zero ) then\r\n if( X .eq. zero ) then\r\n dsepa = one\r\n else\r\n dsepa = zero\r\n endif\r\n else\r\n rx = X/thx\r\n dsepa = exp(-pi*rx*rx)\r\n endif\r\n!\t\t\t\t\t\t\tin the y direction\r\n if( thy .eq. zero ) then\r\n if( Y .eq. zero ) then\r\n dsepb = one\r\n else\r\n dsepb = zero\r\n endif\r\n else\r\n ry = Y/thy\r\n dsepb = exp(-pi*ry*ry)\r\n endif\r\n!\t\t\t\t\t\t\tin the y direction\r\n if( thz .eq. zero ) then\r\n if( Z .eq. zero ) then\r\n dsepc = one\r\n else\r\n dsepc = zero\r\n endif\r\n else\r\n rz = Z/thz\r\n dsepc = exp(-pi*rz*rz)\r\n endif\r\n dlspx3 = var*dsepa*dsepb*dsepc\r\n endif\r\n\r\n\r\n return\r\n end\r\n\r\n\r\n", "meta": {"hexsha": "53f72350eea0b5d0fd79731301b171dfb935bc28", "size": 5610, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/libs/gaf95/dlspx3.f95", "max_stars_repo_name": "leemargetts/PoreFEM", "max_stars_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/libs/gaf95/dlspx3.f95", "max_issues_repo_name": "leemargetts/PoreFEM", "max_issues_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/libs/gaf95/dlspx3.f95", "max_forks_repo_name": "leemargetts/PoreFEM", "max_forks_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.7324840764, "max_line_length": 79, "alphanum_fraction": 0.5065953654, "num_tokens": 1651, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096090086368, "lm_q2_score": 0.7490872243177518, "lm_q1q2_score": 0.6862460041831006}} {"text": " SUBROUTINE EARLIN(X,Y,N,V,MEG) \n DIMENSION C(11,11),V(11),X(N),Y(N),XX(11),E(11) \n M=IABS(MEG) \n MPL=M+1 \n DO 10 I=1,M \n DO 10 J=1,MPL \n C(I,J)=0 \n10 CONTINUE \n DO 20 I=1,N \n XXX=1 \n DO 20 J=1,M \n IF(J.NE.1)XXX=XXX*X(I) \n XX(J)=XXX \n C(J,M+1)=C(J,M+1)+XX(J)*Y(I) \n DO 20 K=1,J \n C(J,K)=C(J,K)+XX(J)*XX(K) \n20 CONTINUE \n DO 30 J=2,M \n JMI=J-1 \n DO 30 K=1,JMI \n C(K,J)=C(J,K) \n30 CONTINUE \n DET=SIMUL(M,C,V,0.,0,11)\n IF(MEG.LT.0)RETURN \n DO 40 I=1,M \n E(I)=SQRT(C(I,I)) \n DO 40 J=1,I \n C(I,J)=C(I,J)/(E(I)*E(J)) \n40 CONTINUE \nC PRINT 1000 \nC PRINT 1000,(V(I),I=1,M) \nC PRINT 1000,(E(I),I=1,M) \nC PRINT 1000 \nC DO 50 I=1,M \nC PRINT 1000,(C(I,J),J=1,I) \nC50 CONTINUE \n RETURN \nC1000 FORMAT(1H 10F12.5) \n END \n", "meta": {"hexsha": "6b5a8f66a7ecab0fcbc275a1a8fdb48fad45a99c", "size": 887, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "stsdas/pkg/contrib/redshift/earlin.f", "max_stars_repo_name": "iraf-community/stsdas", "max_stars_repo_head_hexsha": "043c173fd5497c18c2b1bfe8bcff65180bca3996", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-12-20T10:06:48.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-20T10:06:48.000Z", "max_issues_repo_path": "stsdas/pkg/contrib/redshift/earlin.f", "max_issues_repo_name": "spacetelescope/stsdas_stripped", "max_issues_repo_head_hexsha": "043c173fd5497c18c2b1bfe8bcff65180bca3996", "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": "stsdas/pkg/contrib/redshift/earlin.f", "max_forks_repo_name": "spacetelescope/stsdas_stripped", "max_forks_repo_head_hexsha": "043c173fd5497c18c2b1bfe8bcff65180bca3996", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-10-12T20:01:16.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-19T08:04:30.000Z", "avg_line_length": 22.175, "max_line_length": 54, "alphanum_fraction": 0.4464487035, "num_tokens": 402, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096181702031, "lm_q2_score": 0.7490872131147276, "lm_q1q2_score": 0.6862460007827147}} {"text": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\ncc cc\ncc mnperc : percur test program cc\ncc cc\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\n real x(27),y(27),w(27),t(37),c(37),wrk(1400),sp(27)\n integer iwrk(37)\n real al,fp,s\n integer i,ier,iopt,is,j,k,l,lwrk,l1,l2,m,m1,n,nest,nk1\nc the data absciss values\n data x(1),x(2),x(3),x(4),x(5),x(6),x(7),x(8),x(9),x(10),x(11),\n * x(12),x(13),x(14),x(15),x(16),x(17),x(18),x(19),x(20),x(21),\n * x(22),x(23),x(24),x(25),x(26)/0.0,3.922,7.843,11.765,15.686,\n * 19.608,23.509,27.451,31.373,35.294,39.216,43.137,47.059,50.980,\n * 54.902,58.824,62.745,66.667,70.588,74.510,78.431,82.353,86.275,\n * 90.196,94.118,98.039/\nc the data ordinate values\n data y(1),y(2),y(3),y(4),y(5),y(6),y(7),y(8),y(9),y(10),y(11),\n * y(12),y(13),y(14),y(15),y(16),y(17),y(18),y(19),y(20),y(21),\n * y(22),y(23),y(24),y(25),y(26)/10.099,14.835,21.453,25.022,22.427,\n * 22.315,22.070,19.673,16.754,13.983,11.973,12.286,16.129,21.560,\n * 28.041,39.205,59.489,72.559,75.960,79.137,75.925,68.809,55.758,\n * 39.915,22.006,12.076/\nc m denotes the number of data points\n m = 27\nc the period of the spline is determined by x(m)\n x(m) = 100.\n y(m) = y(1)\nc we set up the weights of the data points\n m1 = m-1\n do 10 i=1,m1\n w(i) = 1.0\n 10 continue\nc we set up the dimension information.\n nest = 37\n lwrk = 1400\nc loop for the different spline degrees.\n do 400 k=3,5,2\nc loop for the different spline approximations of degree k\n do 300 is=1,7\n go to (110,120,130,140,150,160,170),is\nc we start computing the least-squares constant (large value for s).\n 110 iopt = 0\n s = 65000.\n go to 200\nc iopt=1 from the second call on\n 120 iopt = 1\n s = 500.\n go to 200\nc a smaller value for s to get a closer approximation\n 130 s = 5.\n go to 200\nc a larger value for s to get a smoother approximation\n 140 s = 20.\n go to 200\nc if a satisfactory fit is obtained we can calculate a spline of equal\nc quality of fit ( same value for s ) but possibly with fewer knots by\nc specifying iopt=0\n 150 s = 20.\n iopt = 0\n go to 200\nc we calculate an interpolating periodic spline.\n 160 s = 0.\n go to 200\nc finally, we also calculate a least-squares periodic spline function\nc with specified knots.\n 170 iopt = -1\n n = 11+2*k\n j = k+2\n do 180 l=1,9\n al = l*10\n t(j) = al\n j = j+1\n 180 continue\nc determine the periodic spline approximation\n 200 call percur(iopt,m,x,y,w,k,s,nest,n,t,c,fp,wrk,lwrk,\n * iwrk,ier)\nc printing of the results.\n if(iopt.ge.0) go to 210\n write(6,910) k\n go to 220\n 210 write(6,915) k\n write(6,920) s\n 220 write(6,925) fp,ier\n write(6,930) n\n write(6,935)\n write(6,940) (t(i),i=1,n)\n nk1 = n-k-1\n write(6,945)\n write(6,950) (c(i),i=1,nk1)\n write(6,955)\nc evaluation of the spline approximation\n call splev(t,n,c,k,x,sp,m,ier)\n do 230 i=1,9\n l1 = (i-1)*3+1\n l2 = l1+2\n write(6,960) (x(l),y(l),sp(l),l=l1,l2)\n 230 continue\n 300 continue\n 400 continue\n stop\n 910 format(41h0least-squares periodic spline of degree ,i1)\n 915 format(37h0smoothing periodic spline of degree ,i1)\n 920 format(20h smoothing factor s=,f7.0)\n 925 format(1x,23hsum squared residuals =,e15.6,5x,11herror flag=,i2)\n 930 format(1x,24htotal number of knots n=,i3)\n 935 format(1x,22hposition of the knots )\n 940 format(5x,8f8.3)\n 945 format(23h0b-spline coefficients )\n 950 format(5x,8f8.4)\n 955 format(1h0,3(3x,2hxi,6x,2hyi,4x,5hs(xi),3x))\n 960 format(1h ,3(f7.3,1x,f7.3,1x,f7.3,2x))\n end\n", "meta": {"hexsha": "5f92a94f67bf5e432a023b553ed3bbb929d444e5", "size": 4228, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ApproxSpline/Resources/F77-Sources/ex/mnperc.f", "max_stars_repo_name": "modelica-3rdparty/ApproxSpline", "max_stars_repo_head_hexsha": "28420f5c1a88c9cd069defbd8c05e4a78a090675", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-07-13T17:24:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-18T16:16:02.000Z", "max_issues_repo_path": "ApproxSpline/Resources/F77-Sources/ex/mnperc.f", "max_issues_repo_name": "tbeu/ApproxSpline", "max_issues_repo_head_hexsha": "28420f5c1a88c9cd069defbd8c05e4a78a090675", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-03-28T09:08:23.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T07:35:48.000Z", "max_forks_repo_path": "ApproxSpline/Resources/F77-Sources/ex/mnperc.f", "max_forks_repo_name": "modelica-3rdparty/ApproxSpline", "max_forks_repo_head_hexsha": "28420f5c1a88c9cd069defbd8c05e4a78a090675", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-10-21T07:46:49.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T20:02:06.000Z", "avg_line_length": 37.0877192982, "max_line_length": 72, "alphanum_fraction": 0.5517975402, "num_tokens": 1585, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096044278532, "lm_q2_score": 0.7490872187162396, "lm_q1q2_score": 0.686245995620095}} {"text": "************************************************************************\r\n*\r\n* Function CORR Called by: AMLSTAT, OUTEQN\r\n*\r\n* compute correlation between two variables\r\n*\r\n************************************************************************\r\n DOUBLE PRECISION FUNCTION CORR(N,X,Y)\r\n*\r\n* function args\r\n*\r\n INTEGER*4 N\r\n DOUBLE PRECISION X(*),Y(*)\r\n*\r\n* local vars\r\n*\r\n INTEGER*4 I\r\n DOUBLE PRECISION C1,MX,MY,SX,SY\r\n*\r\n* \r\n*\r\n MX = 0.D0\r\n MY = 0.D0\r\n\r\n DO 10 I=1,N\r\n MX = MX+X(I)\r\n MY = MY+Y(I)\r\n 10 CONTINUE\r\n\r\n MX = MX/DBLE(N)\r\n MY = MY/DBLE(N)\r\n C1 = 0.D0\r\n SX = 0.D0\r\n SY = 0.D0\r\n\r\n DO 20 I=1,N\r\n C1 = C1+(X(I)-MX)*(Y(I)-MY)\r\n SX = SX+(X(I)-MX)**2\r\n SY = SY+(Y(I)-MY)**2\r\n 20 CONTINUE\r\n \r\n CORR = C1/SQRT(MAX(1.D-34,SX*SY))\r\n \r\n RETURN\r\n END\r\n", "meta": {"hexsha": "083633ed54372c8160d3d18071b34912cd904cc4", "size": 914, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "codeNexampls/[loadest]/loadsrc/loadest/source_USGS/corr.f", "max_stars_repo_name": "lthiamodelers/baseflow-coefficients", "max_stars_repo_head_hexsha": "183fef49548fa2e1bf0bb8cff57e96e75d629760", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "codeNexampls/[loadest]/loadsrc/loadest/source_USGS/corr.f", "max_issues_repo_name": "lthiamodelers/baseflow-coefficients", "max_issues_repo_head_hexsha": "183fef49548fa2e1bf0bb8cff57e96e75d629760", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "codeNexampls/[loadest]/loadsrc/loadest/source_USGS/corr.f", "max_forks_repo_name": "lthiamodelers/baseflow-coefficients", "max_forks_repo_head_hexsha": "183fef49548fa2e1bf0bb8cff57e96e75d629760", "max_forks_repo_licenses": ["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.8695652174, "max_line_length": 73, "alphanum_fraction": 0.3610503282, "num_tokens": 272, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.91610961358942, "lm_q2_score": 0.749087201911703, "lm_q1q2_score": 0.68624598708811}} {"text": "program test_hankel1\n use types, only: dp\n use constants, only: i_\n use utils, only: assert\n use special, only: hankel1\n implicit none\n\n ! check a few value against the ones computed with SciPy:\n integer :: i\n real(dp), parameter :: eps = 1d-14\n real(dp), parameter :: ordersReal(7) = [0.000000000000000_dp, 1.000000000000000_dp, 2.000000000000000_dp,&\n 3.300000000000000_dp, 7.000000000000000_dp,&\n -1.500000000000000_dp, -4.000000000000000_dp]\n real(dp), parameter :: xReal(7) = [1.100000000000000_dp, 3.000000000000000_dp, 10.000000000000000_dp,&\n 2.100000000000000_dp, 5.500000000000000_dp, &\n 1.100000000000000_dp, 2.000000000000000_dp]\n real(dp), parameter :: xImag(7) = [0.100000000000000_dp, -0.300000000000000_dp, 2.500000000000000_dp, &\n -1.800000000000000_dp, 2.000000000000000_dp, 0.500000000000000_dp, 1.500000000000000_dp]\n\n complex(dp), parameter :: correctResultsRealArg(7) = [(0.719622018527511_dp, 0.162163202926887_dp), &\n (0.339058958525936_dp, 0.324674424791800_dp), (0.254630313685121_dp, -0.005868082442209_dp),&\n (0.101980666751263_dp, -1.267804061151291_dp), (0.086601225791613_dp, -0.874921069456376_dp),&\n (-0.991692967169576_dp, -0.271278757000343_dp), (0.033995719807567_dp, -2.765943226330601_dp)]\n\n complex(dp), parameter :: correctResultsComplexArg(7) = [(0.651368317549290_dp, 0.118990468927329_dp),&\n (0.428137777037678_dp, 0.455161854334643_dp), (0.021205380414102_dp, -0.003435444019643_dp),&\n (0.085126712134597_dp, -0.593895774097617_dp), (-0.333857447002332_dp, -0.093364319238606_dp),&\n (-0.667664135826850_dp, 0.116458951902184_dp), (-0.750994544707426_dp, 0.404920577875372_dp)]\n\n ! test real argument with real order:\n do i = 1,7\n call assert(abs(hankel1(ordersReal(i), xReal(i)) - correctResultsRealArg(i)) < eps)\n end do\n\n ! test real argument with integer order:\n ! test those to machine precision\n call assert(abs(hankel1(0, xReal(1)) - hankel1FromDef(0, xReal(1))) <= epsilon(1.0_dp))\n call assert(abs(hankel1(1, xReal(2)) - hankel1FromDef(1, xReal(2))) <= epsilon(1.0_dp))\n call assert(abs(hankel1(2, xReal(3)) - hankel1FromDef(2, xReal(3))) <= epsilon(1.0_dp))\n call assert(abs(hankel1(3, xReal(4)) - hankel1FromDef(3, xReal(4))) <= epsilon(1.0_dp))\n call assert(abs(hankel1(4, xReal(5)) - hankel1FromDef(4, xReal(5))) <= epsilon(1.0_dp))\n\n ! test complex data with real order:\n do i = 1,7\n call assert(abs(hankel1(ordersReal(i), xReal(i)+i_*xImag(i)) - correctResultsComplexArg(i)) < eps)\n end do\n\ncontains\n\n function hankel1FromDef(order, x) result(z)\n integer, intent(in) :: order\n real(dp), intent(in) :: x\n complex(dp) :: z\n\n z = bessel_jn(order, x) + i_*bessel_yn(order, x)\n end function hankel1FromDef\n\nend program test_hankel1\n", "meta": {"hexsha": "1560edf6e8cfd7303fa392419a347645f41e3b3b", "size": 2799, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/special/test_hankel1.f90", "max_stars_repo_name": "wave-scattering/fortran-utils", "max_stars_repo_head_hexsha": "464982bfc96359c7d37d9fd0185c6722e9a70046", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 163, "max_stars_repo_stars_event_min_datetime": "2015-02-12T09:55:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T23:08:58.000Z", "max_issues_repo_path": "tests/special/test_hankel1.f90", "max_issues_repo_name": "wu2meng3/fortran-utils", "max_issues_repo_head_hexsha": "b43bd24cd421509a5bc6d3b9c3eeae8ce856ed88", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2016-10-08T21:18:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-24T15:11:50.000Z", "max_forks_repo_path": "tests/special/test_hankel1.f90", "max_forks_repo_name": "wu2meng3/fortran-utils", "max_forks_repo_head_hexsha": "b43bd24cd421509a5bc6d3b9c3eeae8ce856ed88", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 48, "max_forks_repo_forks_event_min_datetime": "2015-03-20T10:26:44.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-23T11:09:47.000Z", "avg_line_length": 47.4406779661, "max_line_length": 108, "alphanum_fraction": 0.714183637, "num_tokens": 1056, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240964782011, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.686214386371475}} {"text": "MODULE sub\nUSE param\n\nCONTAINS\n!=======================\nSUBROUTINE init\nREAL :: htot, hini(nz)\n\nhmin = 0.01 ! minimum layer thickness\ndx = 10.0 ! grid spacing\ng = 9.81 ! acceleration due to gravity\n\n! bathymetry\nDO k = 1,nx\nhtotal(k) = 100.0\nEND DO\n\n! triangle-shaped island \nDO k = 31,51\n htotal(k) = 100.-95.*real(k-30)/21.\nEND DO\n\nDO k = 52,71\n htotal(k) = 100.-95.*real(71-k+1)/20.\nEND DO\n\nhtotal(0) = -10.0\nhtotal(nx+1) = -10.0\n\n! undisturbed layer thicknesses & interface displacements\nDO i = 1,nz\nhini(i) = 10.0\nEND DO\nDO k = 0,nx+1\n htot = htotal(k)\n DO i = 1,nz\n hzero(i,k) = MAX(MIN(hini(i),htot),0.0)\n eta(i,k) = MAX(0.0,-htot)\n htot = htot - hini(1)\n END DO\nEND DO\n\n! layer densities\nrho(0) = 0.0 ! air density ignored\nrho(1) = 1025.0\nDO i = 2,nz\n rho(i) = 1026.0+REAL(i-2)/REAL(nz-2)*0.5\nEND DO\n\n! boundary values for dp and eta\nDO k = 0,nx+1\n dp(0,k) = 0.0 ! air pressure ignored\n eta(nz+1,k) = 0.0 ! sea floor is rigid\nEND DO\n\n! store initial interface displacements\nDO k = 0,nx+1\nDO i = 1,nz+1\n eta0(i,k) = eta(i,k)\nEND DO\nEND DO\n\n! layer thicknesses, wet\\dry pointers and velocities\nDO i = 1,nz\nDO k = 0,nx+1\n h(i,k) = hzero(i,k)\n wet(i,k) = 1\n if(h(i,k) < hmin) wet(i,k) = 0\n u(i,k) = 0.\n un(i,k) = 0.\nEND DO\nEND DO\n\nEND SUBROUTINE init\n\n!================\nSUBROUTINE dyn\n\n! local parameters\nREAL :: pgradx \nREAL :: hue, huw, hwp, hwn, hen, hep\nREAL :: deta\n\n! calculate dynamic pressure\n DO k = 0,nx+1\n DO i = 1,nz\n dp(i,k) = dp(i-1,k)+(rho(i)-rho(i-1))*g*eta(i,k) \n END DO\n END DO\n\nDO k = 1,nx\nDO i = 1,nz\n \n! velocity predictor for wet grid cells\n pgradx = -(dp(i,k+1)-dp(i,k))/rho(i)/dx\n un(i,k) = 0.0\n IF(wet(i,k)==1) THEN\n IF((wet(i,k+1)==1).or.(pgradx>0.0)) un(i,k) = u(i,k)+dt*pgradx\n ELSE\n IF((wet(i,k+1)==1).and.(pgradx<0.0)) un(i,k) = u(i,k)+dt*pgradx\n END IF\nEND DO\nEND DO\n\n! layer-thickness change predictor\nDO k = 1,nx\nDO i = 1,nz\n hep = 0.5*(un(i,k)+abs(un(i,k)))*h(i,k)\n hen = 0.5*(un(i,k)-abs(un(i,k)))*h(i,k+1)\n hue = hep+hen\n hwp = 0.5*(un(i,k-1)+abs(un(i,k-1)))*h(i,k-1)\n hwn = 0.5*(un(i,k-1)-abs(un(i,k-1)))*h(i,k)\n huw = hwp+hwn\n dhdt(i,k) = -(hue-huw)/dx\nEND DO\nEND DO\n\n! update interface displacements\nDO k = 1,nx\n deta = 0.0\n DO i = nz,1,-1\n deta = deta + dhdt(i,k)\n etan(i,k)= eta(i,k)+dt*deta\n END DO\nEND DO\n\n! apply Shapiro filter\nCALL shapiro\n\n! update layer thicknesses, lateral velocities and wet/dry pointers\nDO k = 1,nx\n DO i = 1,nz\n h(i,k) = hzero(i,k)+eta(i,k)-eta(i+1,k)-eta0(i,k)+eta0(i+1,k)\n u(i,k) = un(i,k)\n wet(i,k) = 1\n if(h(i,k) lmax,x,\n < fj)\n!$acc routine \n IMPLICIT NONE\n! ..\n! .. Arguments ..\n INTEGER, INTENT (IN) :: lmax\n REAL, INTENT (IN) :: x\n REAL, INTENT (OUT) :: fj(0:lmax)\n!\n! .. Parameters ..\n REAL, PARAMETER :: small = 1.0e-03 , zero = 0.0\n! ..\n! .. Locals ..\n INTEGER i,l,min,n\n REAL fac,quot,xinv,xx\n REAL :: aux(0:int(lmax+10+x))\n !REAL, ALLOCATABLE :: aux(:)\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC abs,cos,sin\n\n IF (lmax==0) THEN\n IF (x.GE.small) THEN\n fj(0) = sin(x)/x\n ELSE\n fj(0) = 1 - x*x/6.* (1.-x*x/20.* (1.-x*x/42.))\n END IF\n RETURN\n ENDIF\n!#ifdef _OPENACC\n! IF (x.LT.zero) stop \"sphbes2\"\n!#else\n! IF (x.LT.zero) CALL juDFT_error(\"sphbes2\",calledby=\"sphbes\")\n!#endif\n xx = x*x\n IF (x.GE.small) THEN\n xinv = 1./x\n fj(0) = sin(x)*xinv\n fj(1) = (fj(0)-cos(x))*xinv\n ELSE\n fj(0) = 1 - xx/6.* (1.-xx/20.* (1.-xx/42.))\n fj(1) = (x/3.)* (1.-xx/10.* (1.-xx/28.))\n fac = xx/15.\n DO l=2,lmax\n fj(l) = fac * ( 1. - xx / (4*l+6) )\n fac = x * fac / (2*l+3)\n ENDDO\n RETURN\n END IF\n IF (lmax.LT.x) THEN\n\n DO l = 2,lmax\n fj(l) = (2*l-1)*xinv*fj(l-1) - fj(l-2)\n ENDDO\n\n ELSE IF (lmax.GE.2) THEN\n n = INT( lmax + 10 + x )\n ! ALLOCATE( aux(0:n) )\n!\n! downward recursion from arbitrary starting values\n!\n aux(n) = 0.\n aux(n-1) = 1.\n DO i = n - 1,1,-1\n aux(i-1) = (2*i+1)*xinv*aux(i) - aux(i+1)\n ENDDO\n!\n! normalize with j0 or j1, whichever is larger\n!\n min = 0\n IF (abs(fj(0)).LT.abs(fj(1))) min = 1\n quot = fj(min)/aux(min)\n DO l = 2,lmax\n fj(l) = aux(l)*quot\n ENDDO\n ! DEALLOCATE( aux )\n END IF\n\n RETURN\n END SUBROUTINE sphbes\n END MODULE m_sphbes\n", "meta": {"hexsha": "d613e7656f898bb16b0c94db71cdb65b4a186343", "size": 2383, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "math/sphbes.f", "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/sphbes.f", "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/sphbes.f", "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": 26.1868131868, "max_line_length": 69, "alphanum_fraction": 0.4179605539, "num_tokens": 810, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425267730008, "lm_q2_score": 0.7461390043208003, "lm_q1q2_score": 0.6861811592574718}} {"text": " SUBROUTINE MOMENT(DATA,N,AVE,ADEV,SDEV,VAR,SKEW,CURT)\n DIMENSION DATA(N)\n IF(N.LE.1)PAUSE 'N must be at least 2'\n S=0.\n DO 11 J=1,N\n S=S+DATA(J)\n11 CONTINUE\n AVE=S/N\n ADEV=0.\n VAR=0.\n SKEW=0.\n CURT=0.\n DO 12 J=1,N\n S=DATA(J)-AVE\n ADEV=ADEV+ABS(S)\n P=S*S\n VAR=VAR+P\n P=P*S\n SKEW=SKEW+P\n P=P*S\n CURT=CURT+P\n12 CONTINUE\n ADEV=ADEV/N\n VAR=VAR/(N-1)\n SDEV=SQRT(VAR)\n IF(VAR.NE.0.)THEN\n SKEW=SKEW/(N*SDEV**3)\n CURT=CURT/(N*VAR**2)-3. \n ELSE\n PAUSE 'no skew or kurtosis when zero variance'\n ENDIF\n RETURN\n END\n", "meta": {"hexsha": "c5df46552ffe3b977e3909866c856afca30084e8", "size": 690, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "Math3/NumRec/source/moment.for", "max_stars_repo_name": "domijin/MM3", "max_stars_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Math3/NumRec/source/moment.for", "max_issues_repo_name": "domijin/MM3", "max_issues_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Math3/NumRec/source/moment.for", "max_forks_repo_name": "domijin/MM3", "max_forks_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.2941176471, "max_line_length": 59, "alphanum_fraction": 0.4753623188, "num_tokens": 267, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425311777929, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6861811573526543}} {"text": "!Tests whether an integer is happy or sad\nmodule test\n use const, only : rk, ik\n implicit none\n integer, parameter, private :: unhappy(8) = [4, 16, 37, 58, 89, 145, 42, 20]\n\n contains\n\n pure logical function O(x_in)\n implicit none\n integer(ik), intent(in) :: x_in\n integer(ik) :: x, i, sum\n\n x = x_in\n do \n sum = 0\n do i = 1, floor(log10(real(x, rk)) + 1)\n sum = sum + (x - (x / 10) * 10) ** 2\n x = x / 10\n end do\n x = sum\n\n if (x == 1) then\n O = .true.\n return\n else if (any(x == unhappy)) then\n O = .false.\n return\n end if\n end do\n end function O\nend module test", "meta": {"hexsha": "fdaf53b03c5fbbc9c7adacc834fcb71babcfadc8", "size": 794, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/test.f90", "max_stars_repo_name": "Janizai/HappyNumbers", "max_stars_repo_head_hexsha": "80ebbb1192f2230ab6a87caabe5d6e9a1f92b2c0", "max_stars_repo_licenses": ["MIT"], "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/test.f90", "max_issues_repo_name": "Janizai/HappyNumbers", "max_issues_repo_head_hexsha": "80ebbb1192f2230ab6a87caabe5d6e9a1f92b2c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/test.f90", "max_forks_repo_name": "Janizai/HappyNumbers", "max_forks_repo_head_hexsha": "80ebbb1192f2230ab6a87caabe5d6e9a1f92b2c0", "max_forks_repo_licenses": ["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.8125, "max_line_length": 80, "alphanum_fraction": 0.4319899244, "num_tokens": 230, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425223682086, "lm_q2_score": 0.7461390043208003, "lm_q1q2_score": 0.6861811559708845}} {"text": "Subroutine wida1(dmass, rhomp, wa1, iseed)\n Save\n pimass = 0.137265\n coupa = 14.8\n rhomax = dmass - pimass - 0.02\n If (rhomax<=0) Then\n rhomp = 0.\n wa1 = -10.\n End If\n icount = 0\n711 rhomp = rhomas(rhomax, iseed)\n icount = icount + 1\n If (dmass<=(pimass+rhomp)) Then\n If (icount<=100) Then\n Goto 711\n Else\n rhomp = 0.\n wa1 = -10.\n Return\n End If\n End If\n qqp2 = (dmass**2-(rhomp+pimass)**2)*(dmass**2-(rhomp-pimass)**2)\n qqp = sqrt(qqp2)/(2.0*dmass)\n epi = sqrt(pimass**2+qqp**2)\n erho = sqrt(rhomp**2+qqp**2)\n epirho = 2.0*(epi*erho+qqp**2)**2 + rhomp**2*epi**2\n wa1 = coupa**2*qqp*epirho/(24.0*3.1416*dmass**2)\n Return\nEnd Subroutine wida1\n", "meta": {"hexsha": "5333af714e2d9d99d5bfe7b7feea43ce390e3456", "size": 707, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/wida1.f90", "max_stars_repo_name": "xiaohaijin/AMPT", "max_stars_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-12-24T19:37:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-14T12:58:59.000Z", "max_issues_repo_path": "src/wida1.f90", "max_issues_repo_name": "xiaohaijin/AMPT", "max_issues_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_issues_repo_licenses": ["MIT"], "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/wida1.f90", "max_forks_repo_name": "xiaohaijin/AMPT", "max_forks_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_forks_repo_licenses": ["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.5666666667, "max_line_length": 66, "alphanum_fraction": 0.5756718529, "num_tokens": 328, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425245706047, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6861811524227734}} {"text": "subroutine banslv ( w, nroww, nrow, nbandl, nbandu, b )\n\n!*****************************************************************************80\n!\n!! BANSLV solves a banded linear system A * X = B factored by BANFAC.\n!\n! Modified:\n!\n! 14 February 2007\n!\n! Author:\n!\n! Carl DeBoor\n!\n! Reference:\n!\n! Carl DeBoor,\n! A Practical Guide to Splines,\n! Springer, 2001,\n! ISBN: 0387953663.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) W(NROWW,NROW). W contains the banded matrix,\n! after it has been factored by BANFAC.\n!\n! Input, integer NROWW, the row dimension of the work array W.\n! NROWW must be at least NBANDL+1 + NBANDU.\n!\n! Input, integer NROW, the number of rows in A.\n!\n! Input, integer NBANDL, the number of bands of A below the\n! main diagonal.\n!\n! Input, integer NBANDU, the number of bands of A above the\n! main diagonal.\n!\n! Input/output, real ( kind = 8 ) B(NROW).\n! On input, B contains the right hand side of the system to be solved.\n! On output, B contains the solution, X.\n!\n implicit none\n\n integer nrow\n integer nroww\n\n real ( kind = 8 ) b(nrow)\n integer i\n integer j\n integer jmax\n integer middle\n integer nbandl\n integer nbandu\n real ( kind = 8 ) w(nroww,nrow)\n\n middle = nbandu + 1\n\n !print*, \"ze\",size(w,1),size(w,2)\n\n if ( nrow == 1 ) then\n b(1) = b(1) / w(middle,1)\n return\n end if\n!\n! Forward pass:\n!\n! For I = 1, 2, ..., NROW-1, subtract RHS(I)*(I-th column of L)\n! from the right hand side, below the I-th row.\n!\n if ( 0 < nbandl ) then\n do i = 1, nrow-1\n jmax = min ( nbandl, nrow-i )\n do j = 1, jmax\n b(i+j) = b(i+j) - b(i) * w(middle+j,i)\n end do\n end do\n end if\n!\n! Backward pass:\n!\n! For I=NROW, NROW-1,...,1, divide RHS(I) by\n! the I-th diagonal entry of U, then subtract\n! RHS(I)*(I-th column of U) from right hand side, above the I-th row.\n!\n do i = nrow, 2, -1\n\n b(i) = b(i) / w(middle,i)\n\n do j = 1, min ( nbandu, i-1 )\n b(i-j) = b(i-j) - b(i) * w(middle-j,i)\n end do\n\n end do\n\n b(1) = b(1) / w(middle,1)\n\n !print*, 'banslv',b\n return\nend subroutine banslv\n", "meta": {"hexsha": "f138c2e7eb876aaefd126662878cb25202fb255a", "size": 2120, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "external/pppack/banslv.f90", "max_stars_repo_name": "utastudents/selalib", "max_stars_repo_head_hexsha": "84af43d0e82d4686a837c64384bbd173412df50e", "max_stars_repo_licenses": ["CECILL-B"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-03-11T15:22:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-22T16:26:18.000Z", "max_issues_repo_path": "external/pppack/banslv.f90", "max_issues_repo_name": "utastudents/selalib", "max_issues_repo_head_hexsha": "84af43d0e82d4686a837c64384bbd173412df50e", "max_issues_repo_licenses": ["CECILL-B"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2021-06-30T20:39:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-15T12:42:50.000Z", "max_forks_repo_path": "external/pppack/banslv.f90", "max_forks_repo_name": "utastudents/selalib", "max_forks_repo_head_hexsha": "84af43d0e82d4686a837c64384bbd173412df50e", "max_forks_repo_licenses": ["CECILL-B"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-03-13T17:09:10.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-22T00:30:19.000Z", "avg_line_length": 21.2, "max_line_length": 80, "alphanum_fraction": 0.570754717, "num_tokens": 755, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099167, "lm_q2_score": 0.798186787341014, "lm_q1q2_score": 0.6861722472130374}} {"text": " PROGRAM xfpoly\r\nC driver for routine fpoly\r\n INTEGER NPOLY,NVAL\r\n REAL DX\r\n PARAMETER(NVAL=15,DX=0.1,NPOLY=5)\r\n INTEGER i,j\r\n REAL x,afunc(NPOLY)\r\n write(*,'(/1x,t29,a)') 'Powers of X'\r\n write(*,'(/1x,t9,a,t17,a,t27,a,t37,a,t47,a,t57,a)') 'X','X**0',\r\n * 'X**1','X**2','X**3','X**4'\r\n do 11 i=1,NVAL\r\n x=i*DX\r\n call fpoly(x,afunc,NPOLY)\r\n write(*,'(1x,6f10.4)') x,(afunc(j),j=1,NPOLY)\r\n11 continue\r\n END\r\n", "meta": {"hexsha": "7400ac5a7915d6abbc8580442c9e5b4e50d4198c", "size": 492, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xfpoly.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xfpoly.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xfpoly.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.9411764706, "max_line_length": 70, "alphanum_fraction": 0.487804878, "num_tokens": 195, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190939, "lm_q2_score": 0.798186784940666, "lm_q1q2_score": 0.6861722394099254}} {"text": "\nsubmodule(forlab_linalg) forlab_linalg_qr\n\n implicit none\n\ncontains\n\n module procedure qr_sp\n real(sp), allocatable::v(:)\n integer::i, j, k, m, n, nn, templ\n real(sp)::alpha, t, u\n real(sp), parameter::eps = epsilon(1.0_sp), zero = 0.0_sp, one = 1.0_sp\n m = size(a, 1)\n n = size(a, 2)\n if (m < n) then\n call error_stop(\"Error:Matrix a dimension m < n \")\n end if\n if (present(l)) then\n templ = l\n else\n templ = 1\n end if\n select case (templ)\n case (1)\n r = a\n allocate (q(m, m))\n q = zero\n r = a\n forall (i=1:m)\n q(i, i) = one\n end forall\n nn = n\n if (m == n) nn = m - 1\n do k = 1, nn\n u = zero\n do i = k, m\n if (abs(r(i, k)) > u) u = abs(r(i, k))\n end do\n alpha = dot_product(r(k:m, k), r(k:m, k))/(u*u)\n if (r(k, k) > 0) u = -u\n alpha = u*sqrt(alpha)\n if (abs(alpha) < eps) then\n call error_stop(\"Error:matrix r linearly dependent\")\n end if\n u = sqrt(2*alpha*(alpha - r(k, k)))\n if (abs(u) > eps) then\n r(k, k) = (r(k, k) - alpha)/u\n r(k + 1:m, k) = r(k + 1:m, k)/u\n do j = 1, m\n t = dot_product(r(k:m, k), q(k:m, j))\n q(k:m, j) = q(k:m, j) - 2*r(k:m, k)*t\n end do\n do j = k + 1, n\n t = dot_product(r(k:m, k), r(k:m, j))\n r(k:m, j) = r(k:m, j) - 2*r(k:m, k)*t\n end do\n r(k, k) = alpha\n r(k + 1:m, k) = zero\n end if\n end do\n do i = 1, m - 1\n do j = i + 1, m\n t = q(i, j)\n q(i, j) = q(j, i)\n q(j, i) = t\n end do\n end do\n case (2)\n allocate (r(n, n))\n r = zero\n q = a\n v = q(:, 1)\n alpha = norm2(v)\n q(:, 1) = v/alpha\n r(1, 1) = alpha\n do i = 2, n\n v = q(:, i)\n do j = 1, i - 1\n alpha = dot_product(q(:, i), q(:, j))\n v = v - alpha*q(:, j)\n r(j, i) = alpha\n end do\n alpha = norm2(v)\n if (abs(alpha) < eps) then\n call error_stop(\"Error:Matrix q linearly dependent\")\n end if\n q(:, i) = v/alpha\n r(i, i) = alpha\n end do\n case default\n call Error_stop(\"Error: QR decomposition Type must be 1 or 2\")\n end select\n end procedure qr_sp\n module procedure qr_dp\n real(dp), allocatable::v(:)\n integer::i, j, k, m, n, nn, templ\n real(dp)::alpha, t, u\n real(dp), parameter::eps = epsilon(1.0_dp), zero = 0.0_dp, one = 1.0_dp\n m = size(a, 1)\n n = size(a, 2)\n if (m < n) then\n call error_stop(\"Error:Matrix a dimension m < n \")\n end if\n if (present(l)) then\n templ = l\n else\n templ = 1\n end if\n select case (templ)\n case (1)\n r = a\n allocate (q(m, m))\n q = zero\n r = a\n forall (i=1:m)\n q(i, i) = one\n end forall\n nn = n\n if (m == n) nn = m - 1\n do k = 1, nn\n u = zero\n do i = k, m\n if (abs(r(i, k)) > u) u = abs(r(i, k))\n end do\n alpha = dot_product(r(k:m, k), r(k:m, k))/(u*u)\n if (r(k, k) > 0) u = -u\n alpha = u*sqrt(alpha)\n if (abs(alpha) < eps) then\n call error_stop(\"Error:matrix r linearly dependent\")\n end if\n u = sqrt(2*alpha*(alpha - r(k, k)))\n if (abs(u) > eps) then\n r(k, k) = (r(k, k) - alpha)/u\n r(k + 1:m, k) = r(k + 1:m, k)/u\n do j = 1, m\n t = dot_product(r(k:m, k), q(k:m, j))\n q(k:m, j) = q(k:m, j) - 2*r(k:m, k)*t\n end do\n do j = k + 1, n\n t = dot_product(r(k:m, k), r(k:m, j))\n r(k:m, j) = r(k:m, j) - 2*r(k:m, k)*t\n end do\n r(k, k) = alpha\n r(k + 1:m, k) = zero\n end if\n end do\n do i = 1, m - 1\n do j = i + 1, m\n t = q(i, j)\n q(i, j) = q(j, i)\n q(j, i) = t\n end do\n end do\n case (2)\n allocate (r(n, n))\n r = zero\n q = a\n v = q(:, 1)\n alpha = norm2(v)\n q(:, 1) = v/alpha\n r(1, 1) = alpha\n do i = 2, n\n v = q(:, i)\n do j = 1, i - 1\n alpha = dot_product(q(:, i), q(:, j))\n v = v - alpha*q(:, j)\n r(j, i) = alpha\n end do\n alpha = norm2(v)\n if (abs(alpha) < eps) then\n call error_stop(\"Error:Matrix q linearly dependent\")\n end if\n q(:, i) = v/alpha\n r(i, i) = alpha\n end do\n case default\n call Error_stop(\"Error: QR decomposition Type must be 1 or 2\")\n end select\n end procedure qr_dp\n\nend submodule forlab_linalg_qr\n", "meta": {"hexsha": "d0d94910d01c773c6f1a7aa2da05e8777ccb5028", "size": 5223, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/forlab_linalg_qr.f90", "max_stars_repo_name": "zoziha/forlab_z", "max_stars_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2021-08-31T15:23:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T02:44:46.000Z", "max_issues_repo_path": "src/forlab_linalg_qr.f90", "max_issues_repo_name": "zoziha/forlab_z", "max_issues_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-08-22T11:47:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-31T00:57:16.000Z", "max_forks_repo_path": "src/forlab_linalg_qr.f90", "max_forks_repo_name": "zoziha/forlab_z", "max_forks_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-07-16T03:16:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-31T13:09:42.000Z", "avg_line_length": 28.6978021978, "max_line_length": 75, "alphanum_fraction": 0.3764120237, "num_tokens": 1672, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.91243616285804, "lm_q2_score": 0.7520125848754472, "lm_q1q2_score": 0.6861634773647092}} {"text": "subroutine elmhes(heslo,hessi,ndime,nnode,ntens,xjaci,deriv,elcod)\n!-----------------------------------------------------------------------\n!****f* Domain/elmhes\n! NAME\n! elmhes\n! DESCRIPTION\n! This routine computes the Hessian matrix in the Cartesian system\n! of coordinates according to the rule\n!\n! d^2 N / d x_i d x_j\n! = (d^2 N / d s_k d s_l) (d s_k/ d x_i)(d s_l/ d x_j)\n! + (d N / d s_k) (d^2 s_k / d x_i d x_j) \n! USES\n! vetoma\n! btdbma\n! matove\n! SOURCE\n!***\n!-----------------------------------------------------------------------\n use typre\n implicit none\n\n integer(ip), intent(in) :: ndime,nnode,ntens\n real(rp), intent(in) :: xjaci(ndime,ndime)\n real(rp), intent(in) :: deriv(ndime,nnode),elcod(ndime,nnode)\n real(rp), intent(in) :: heslo(ntens,nnode)\n real(rp), intent(out) :: hessi(ntens,nnode) \n \n real(rp) :: wmat1(ndime,ndime,nnode) !really only \n real(rp) :: wmat2(ndime,ndime,nnode) !work not even\n real(rp) :: d2sdx(ndime,ndime,ndime) !intent out\n integer(ip) :: inode,idime,jdime,kdime,ldime\n!\n! Transforms the array HESLO to a symmetric matrix WMAT1\n!\n do inode=1,nnode\n call vetoma(heslo(1,inode),wmat1(1,1,inode),ndime,ntens)\n end do\n!\n! Computes (d^2 N / d s_k d s_l) (d s_k/ d x_i)(d s_l/ d x_j) for\n! each node\n!\n do inode=1,nnode\n call btdbma(wmat2(1,1,inode),wmat1(1,1,inode),xjaci,ndime,ndime)\n end do\n!\n! Obtains (d^2 s_k / d x_i d x_j) as the solution of the system\n! (d x_l / d s_k) (d^2 s_k / d x_i d x_j) \n! = - (d^2 x_l / d s_k d s_l) (d s_k/ d x_i)(d s_l/ d x_j), \n! for l,i,j = 1,...,NDIME\n!\n do kdime=1,ndime\n do idime=1,ndime\n do jdime=1,ndime\n d2sdx(kdime,idime,jdime)=0.0_rp\n do ldime=1,ndime\n do inode=1,nnode\n d2sdx(kdime,idime,jdime)=d2sdx(kdime,idime,jdime)&\n -xjaci(kdime,ldime)*wmat2(idime,jdime,inode)&\n *elcod(ldime,inode)\n end do\n end do\n end do\n end do\n end do\n!\n! Computes the second Cartesian derivatives of the shape functions\n!\n do inode=1,nnode\n do idime=1,ndime\n do jdime=1,ndime\n do kdime=1,ndime\n wmat2(idime,jdime,inode)=wmat2(idime,jdime,inode)&\n +deriv(kdime,inode)*d2sdx(kdime,idime,jdime)\n end do\n end do\n end do\n end do\n!\n! Writes the Hessian matrix as an array\n!\n do inode=1,nnode\n call matove(wmat2(1,1,inode),hessi(1,inode),ndime,ntens)\n end do\n \nend subroutine elmhes\n", "meta": {"hexsha": "fa57fa66c8b2fdad69e95a6123c329f86ffbf290", "size": 2564, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Sources/domain/elmhes.f90", "max_stars_repo_name": "ciaid-colombia/InsFEM", "max_stars_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-24T08:19:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-24T08:19:54.000Z", "max_issues_repo_path": "Sources/domain/elmhes.f90", "max_issues_repo_name": "ciaid-colombia/InsFEM", "max_issues_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Sources/domain/elmhes.f90", "max_forks_repo_name": "ciaid-colombia/InsFEM", "max_forks_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.4712643678, "max_line_length": 72, "alphanum_fraction": 0.5585023401, "num_tokens": 928, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361676202372, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6861634657324597}} {"text": "c\nc\nc ###################################################\nc ## COPYRIGHT (C) 1997 by Jay William Ponder ##\nc ## All Rights Reserved ##\nc ###################################################\nc\nc ###############################################################\nc ## ##\nc ## function sigmoid -- general sigmoidal functional form ##\nc ## ##\nc ###############################################################\nc\nc\nc \"sigmoid\" implements a normalized sigmoidal function on the\nc interval [0,1]; the curves connect (0,0) to (1,1) and have\nc a cooperativity controlled by beta, they approach a straight\nc line as beta -> 0 and get more nonlinear as beta increases\nc\nc\n function sigmoid (beta,x)\n implicit none\n real*8 beta,x\n real*8 sigmoid\n real*8 expmax\n real*8 expmin\n real*8 expterm\nc\nc\nc compute the value of the normalized sigmoidal function\nc\n if (beta .eq. 0.0d0) then\n sigmoid = x\n else\n expmax = 1.0d0 / (exp(-beta) + 1.0d0)\n expmin = 1.0d0 / (exp(beta) + 1.0d0)\n expterm = 1.0d0 / (exp(beta*(2.0d0*x-1.0d0)) + 1.0d0)\n sigmoid = (expmax - expterm) / (expmax - expmin)\n end if\n return\n end\n", "meta": {"hexsha": "55de61a0a1a8f0bed3aa60000c2b2e5c0c7349ea", "size": 1394, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "HCsbLib/HCsbLib/HTLib2.Bioinfo/External.Tinker/src/tinker-6.2.06/sigmoid.f", "max_stars_repo_name": "htna/HCsbLib", "max_stars_repo_head_hexsha": "dae7f4e3e5e2fbc3b6e619f2ea037f661a8ae097", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-01-21T23:45:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-03T16:34:24.000Z", "max_issues_repo_path": "HCsbLib/HCsbLib/HTLib2.Bioinfo/External.Tinker/src/tinker-6.2.06/sigmoid.f", "max_issues_repo_name": "htna/HCsbLib", "max_issues_repo_head_hexsha": "dae7f4e3e5e2fbc3b6e619f2ea037f661a8ae097", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HCsbLib/HCsbLib/HTLib2.Bioinfo/External.Tinker/src/tinker-6.2.06/sigmoid.f", "max_forks_repo_name": "htna/HCsbLib", "max_forks_repo_head_hexsha": "dae7f4e3e5e2fbc3b6e619f2ea037f661a8ae097", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-03-05T00:26:38.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-08T23:25:29.000Z", "avg_line_length": 33.1904761905, "max_line_length": 69, "alphanum_fraction": 0.4196556671, "num_tokens": 358, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361580958426, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6861634636411558}} {"text": "*DECK BETAI\n REAL FUNCTION BETAI (X, PIN, QIN)\nC***BEGIN PROLOGUE BETAI\nC***PURPOSE Calculate the incomplete Beta function.\nC***LIBRARY SLATEC (FNLIB)\nC***CATEGORY C7F\nC***TYPE SINGLE PRECISION (BETAI-S, DBETAI-D)\nC***KEYWORDS FNLIB, INCOMPLETE BETA FUNCTION, SPECIAL FUNCTIONS\nC***AUTHOR Fullerton, W., (LANL)\nC***DESCRIPTION\nC\nC BETAI calculates the REAL incomplete beta function.\nC\nC The incomplete beta function ratio is the probability that a\nC random variable from a beta distribution having parameters PIN and\nC QIN will be less than or equal to X.\nC\nC -- Input Arguments -- All arguments are REAL.\nC X upper limit of integration. X must be in (0,1) inclusive.\nC PIN first beta distribution parameter. PIN must be .GT. 0.0.\nC QIN second beta distribution parameter. QIN must be .GT. 0.0.\nC\nC***REFERENCES Nancy E. Bosten and E. L. Battiste, Remark on Algorithm\nC 179, Communications of the ACM 17, 3 (March 1974),\nC pp. 156.\nC***ROUTINES CALLED ALBETA, R1MACH, XERMSG\nC***REVISION HISTORY (YYMMDD)\nC 770401 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890531 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\nC 900326 Removed duplicate information from DESCRIPTION section.\nC (WRB)\nC 920528 DESCRIPTION and REFERENCES sections revised. (WRB)\nC***END PROLOGUE BETAI\n LOGICAL FIRST\n SAVE EPS, ALNEPS, SML, ALNSML, FIRST\n DATA FIRST /.TRUE./\nC***FIRST EXECUTABLE STATEMENT BETAI\n IF (FIRST) THEN\n EPS = R1MACH(3)\n ALNEPS = LOG(EPS)\n SML = R1MACH(1)\n ALNSML = LOG(SML)\n ENDIF\n FIRST = .FALSE.\nC\n IF (X .LT. 0. .OR. X .GT. 1.0) CALL XERMSG ('SLATEC', 'BETAI',\n + 'X IS NOT IN THE RANGE (0,1)', 1, 2)\n IF (PIN .LE. 0. .OR. QIN .LE. 0.) CALL XERMSG ('SLATEC', 'BETAI',\n + 'P AND/OR Q IS LE ZERO', 2, 2)\nC\n Y = X\n P = PIN\n Q = QIN\n IF (Q.LE.P .AND. X.LT.0.8) GO TO 20\n IF (X.LT.0.2) GO TO 20\n Y = 1.0 - Y\n P = QIN\n Q = PIN\nC\n 20 IF ((P+Q)*Y/(P+1.).LT.EPS) GO TO 80\nC\nC EVALUATE THE INFINITE SUM FIRST.\nC TERM WILL EQUAL Y**P/BETA(PS,P) * (1.-PS)I * Y**I / FAC(I)\nC\n PS = Q - AINT(Q)\n IF (PS.EQ.0.) PS = 1.0\n XB = P*LOG(Y) - ALBETA(PS, P) - LOG(P)\n BETAI = 0.0\n IF (XB.LT.ALNSML) GO TO 40\nC\n BETAI = EXP (XB)\n TERM = BETAI*P\n IF (PS.EQ.1.0) GO TO 40\nC\n N = MAX (ALNEPS/LOG(Y), 4.0E0)\n DO 30 I=1,N\n TERM = TERM*(I-PS)*Y/I\n BETAI = BETAI + TERM/(P+I)\n 30 CONTINUE\nC\nC NOW EVALUATE THE FINITE SUM, MAYBE.\nC\n 40 IF (Q.LE.1.0) GO TO 70\nC\n XB = P*LOG(Y) + Q*LOG(1.0-Y) - ALBETA(P,Q) - LOG(Q)\n IB = MAX (XB/ALNSML, 0.0E0)\n TERM = EXP (XB - IB*ALNSML)\n C = 1.0/(1.0-Y)\n P1 = Q*C/(P+Q-1.)\nC\n FINSUM = 0.0\n N = Q\n IF (Q.EQ.REAL(N)) N = N - 1\n DO 50 I=1,N\n IF (P1.LE.1.0 .AND. TERM/EPS.LE.FINSUM) GO TO 60\n TERM = (Q-I+1)*C*TERM/(P+Q-I)\nC\n IF (TERM.GT.1.0) IB = IB - 1\n IF (TERM.GT.1.0) TERM = TERM*SML\nC\n IF (IB.EQ.0) FINSUM = FINSUM + TERM\n 50 CONTINUE\nC\n 60 BETAI = BETAI + FINSUM\n 70 IF (Y.NE.X .OR. P.NE.PIN) BETAI = 1.0 - BETAI\n BETAI = MAX (MIN (BETAI, 1.0), 0.0)\n RETURN\nC\n 80 BETAI = 0.0\n XB = P*LOG(MAX(Y,SML)) - LOG(P) - ALBETA(P,Q)\n IF (XB.GT.ALNSML .AND. Y.NE.0.) BETAI = EXP (XB)\n IF (Y.NE.X .OR. P.NE.PIN) BETAI = 1.0 - BETAI\n RETURN\nC\n END\n", "meta": {"hexsha": "1d281da48a8ca4fa8d955cc94fa509af663241c3", "size": 3608, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/betai.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/betai.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/betai.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.3193277311, "max_line_length": 71, "alphanum_fraction": 0.5751108647, "num_tokens": 1421, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361604769414, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6861634603606115}} {"text": " subroutine calsig(lmax,r,\n > xp,nbnd,\n > tnode,node,wgq,xgq,npts,\n > wylm,plm,sumfi)\nc ================================================================\nc\nc*********************************************************************\nc* *\nc* This is the new program to expand sigma(r) on complex spherical*\nc* harmonics. It only requires the position of boundary planes. *\nc* *\nc* the integration : *\nc* / *\nc* | _ _ * _ *\nc* | do * sigma( r ) * y ( r ) = wylm *\nc* | l,m *\nc* / *\nc* *\nc* for certain r and m => 0, is carried through this subroutine. *\nc* *\nc* m * *\nc* For m < 0, w(l,-m) = (-1) * w(l,m) *\nc* *\nc* * *\nc* = w(l,m) if m = even *\nc* *\nc* The array is stored in the following way: *\nc* *\nc* jl l m jl l m *\nc* *\nc* w( 1 ) 0 0 w( 7 ) 3 0 *\nc* w( 2 ) 1 0 w( 8 ) 3 1 *\nc* w( 3 ) 1 1 w( 9 ) 3 2 *\nc* w( 4 ) 2 0 w(10 ) 3 3 *\nc* w( 5 ) 2 1 . . . *\nc* w( 6 ) 2 2 . . . *\nc* . . . *\nc* *\nc* input: *\nc* *\nc* lmax = the maximum value of l. *\nc* xgq = the Gaussian quadrature points. *\nc* wgq = the Gaussian quadrature weight associating *\nc* each value of xgq. *\nc* npts = the number of Gaussian qurdrature points. *\nc* r = the ratial value. *\nc* xp = the vector normal to a boundary plane and *\nc* ending on the plane (from origin). *\nc* nbnd = the number of boundary planes. *\nc* tnode = the nodes along theta integration which is the*\nc* non-regular points of function: f(theta). *\nc* The integration over theta is broken into *\nc* several pieces, each of which has two nodes as*\nc* the terminal points. *\nc* node = the number of tnode. *\nc* *\nc* *\nc* output: *\nc* *\nc* wylm = step function expansion value for current *\nc* value of r. *\nc* * \nc*********************************************************************\nc\n implicit none\nc\n integer lmax\n integer nbnd\n integer node\n integer npts\n integer i\n integer l,m,jl\n integer n\nc\n real*8 wgq(npts)\n real*8 xgq(npts)\n real*8 tnode(node)\n real*8 wt\n real*8 plm((lmax+1)*(lmax+2)/2)\n real*8 xp(3,nbnd)\n real*8 cosrth,offset\n real*8 half \n real*8 one\n real*8 two\n real*8 wtol\n real*8 d,halfd\n real*8 h0,sh0\n real*8 r,u\n real*8 t(2)\nc\n complex*16 sumfi(0:lmax,3)\n complex*16 wylm((lmax+1)*(lmax+2)/2)\n complex*16 af1\n complex*16 czero\nc\n parameter (half=0.5d0)\n parameter (one=1.0d0)\n parameter (two=2.0d0)\n parameter (wtol=1.0d-14)\n parameter (czero=(0.d0,0.d0))\nc\nc ================================================================\nc start to integrate over xn=cos(theta), using gaussian method. \nc\nc 2pi -> -i*m*phi\nc sumfi = int d(phi) sigma(r )*e , for certain cos(theta)\nc 0\nc\nc ================================================================\n do i=1,node-1\n d=tnode(i+1)-tnode(i)\n h0=d*1.d-6\n\t if(h0.lt.1.d-8) h0=min(1.d-8,d*1.d-3)\n sh0=sqrt(h0)\n\n call intphi(lmax,tnode(i),r,xp,nbnd,sumfi(0,3))\n call intphi(lmax,tnode(i)+h0,r,xp,nbnd,sumfi(0,1))\n do m=0,lmax\n\t sumfi(m,1)=(sumfi(m,1)-sumfi(m,3))/sh0\n\t enddo\nc\n call intphi(lmax,tnode(i+1),r,xp,nbnd,sumfi(0,3))\n call intphi(lmax,tnode(i+1)-h0,r,xp,nbnd,sumfi(0,2))\n do m=0,lmax\n\t sumfi(m,2)=(sumfi(m,2)-sumfi(m,3))/sh0\n\t enddo\nc\n\t offset=half*(tnode(i)+tnode(i+1))\n\t halfd=half*d\n do n=1,npts\n cosrth=offset+halfd*xgq(n)\nc\nc ==========================================================\nc generate the Legendre functions up to\nc l = lmax for each cos(theta) value.\nc ==========================================================\nc ----------------------------------------------------------\n! meis: changed to normalized associated Legendre functions\n call plm_normalized(lmax,cosrth,plm)\nc ----------------------------------------------------------\n call intphi(lmax,cosrth,r,xp,nbnd,sumfi(0,3))\nc ----------------------------------------------------------\nc\n\t t(1)=sqrt(halfd+halfd*xgq(n))\n\t t(2)=sqrt(halfd-halfd*xgq(n))\n wt=wgq(n)*halfd\n\t do m=0,lmax\n af1= wt*(sumfi(m,3) -\n > sumfi(m,1)*t(1)-sumfi(m,2)*t(2))\n\t jl=m*(m+1)/2+1\n\t do l=m,lmax\n\t jl=jl+l\n wylm(jl) = wylm(jl)+af1*plm(jl)\n enddo\n enddo\nc\n\t if(xgq(n).ge.0.d0) then\n u=sqrt(d)*xgq(n)\n\t wt=two*sqrt(d)*wgq(n)*u*u\nc ----------------------------------------------------------\n! meis: changed to normalized associated Legendre functions\n call plm_normalized(lmax,u*u+tnode(i),plm)\nc ----------------------------------------------------------\n\t do m=0,lmax\n\t af1=wt*sumfi(m,1)\n\t jl=m*(m+1)/2+1\n\t do l=m,lmax\n\t jl=jl+l\n wylm(jl)=wylm(jl)+af1*plm(jl)\n enddo\n enddo\nc ----------------------------------------------------------\n! meis: changed to normalized associated Legendre functions\n call plm_normalized(lmax,tnode(i+1)-u*u,plm)\nc ----------------------------------------------------------\n\t do m=0,lmax\n\t af1=wt*sumfi(m,2)\n\t jl=m*(m+1)/2+1\n\t do l=m,lmax\n\t jl=jl+l\n wylm(jl)=wylm(jl)+af1*plm(jl)\n enddo\n enddo\n\t endif\n enddo\n enddo\nc\n do jl=1,(lmax+1)*(lmax+2)/2\n if(abs(wylm(jl)) .lt. wtol) then\n wylm(jl)=czero\n endif\n enddo\nc\n return\n end\n", "meta": {"hexsha": "f7db769103d928b7434f79ab8ac70161cc8262d2", "size": 8221, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/VORPOL/calsig.f", "max_stars_repo_name": "rdietric/lsms", "max_stars_repo_head_hexsha": "8d0d5f01186abf9a1cc54db3f97f9934b422cf92", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2020-01-05T20:05:31.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T09:08:01.000Z", "max_issues_repo_path": "src/VORPOL/calsig.f", "max_issues_repo_name": "rdietric/lsms", "max_issues_repo_head_hexsha": "8d0d5f01186abf9a1cc54db3f97f9934b422cf92", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2019-07-30T13:59:18.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T17:43:35.000Z", "max_forks_repo_path": "lsms/src/VORPOL/calsig.f", "max_forks_repo_name": "hkershaw-brown/MuST", "max_forks_repo_head_hexsha": "9db4bc5061c2f2c4d7dfd92f53b4ef952602c070", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2020-02-11T17:04:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-28T09:23:46.000Z", "avg_line_length": 41.943877551, "max_line_length": 71, "alphanum_fraction": 0.3047074565, "num_tokens": 1982, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067179697694, "lm_q2_score": 0.7279754548076478, "lm_q1q2_score": 0.6861217566733063}} {"text": "*DECK CPOFA\n SUBROUTINE CPOFA (A, LDA, N, INFO)\nC***BEGIN PROLOGUE CPOFA\nC***PURPOSE Factor a complex Hermitian positive definite matrix.\nC***LIBRARY SLATEC (LINPACK)\nC***CATEGORY D2D1B\nC***TYPE COMPLEX (SPOFA-S, DPOFA-D, CPOFA-C)\nC***KEYWORDS LINEAR ALGEBRA, LINPACK, MATRIX FACTORIZATION,\nC POSITIVE DEFINITE\nC***AUTHOR Moler, C. B., (U. of New Mexico)\nC***DESCRIPTION\nC\nC CPOFA factors a complex Hermitian positive definite matrix.\nC\nC CPOFA is usually called by CPOCO, but it can be called\nC directly with a saving in time if RCOND is not needed.\nC (Time for CPOCO) = (1 + 18/N)*(Time for CPOFA) .\nC\nC On Entry\nC\nC A COMPLEX(LDA, N)\nC the Hermitian matrix to be factored. Only the\nC diagonal and upper triangle are used.\nC\nC LDA INTEGER\nC the leading dimension of the array A .\nC\nC N INTEGER\nC the order of the matrix A .\nC\nC On Return\nC\nC A an upper triangular matrix R so that A =\nC CTRANS(R)*R where CTRANS(R) is the conjugate\nC transpose. The strict lower triangle is unaltered.\nC If INFO .NE. 0 , the factorization is not complete.\nC\nC INFO INTEGER\nC = 0 for normal return.\nC = K signals an error condition. The leading minor\nC of order K is not positive definite.\nC\nC***REFERENCES J. J. Dongarra, J. R. Bunch, C. B. Moler, and G. W.\nC Stewart, LINPACK Users' Guide, SIAM, 1979.\nC***ROUTINES CALLED CDOTC\nC***REVISION HISTORY (YYMMDD)\nC 780814 DATE WRITTEN\nC 890831 Modified array declarations. (WRB)\nC 890831 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900326 Removed duplicate information from DESCRIPTION section.\nC (WRB)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE CPOFA\n INTEGER LDA,N,INFO\n COMPLEX A(LDA,*)\nC\n COMPLEX CDOTC,T\n REAL S\n INTEGER J,JM1,K\nC***FIRST EXECUTABLE STATEMENT CPOFA\n DO 30 J = 1, N\n INFO = J\n S = 0.0E0\n JM1 = J - 1\n IF (JM1 .LT. 1) GO TO 20\n DO 10 K = 1, JM1\n T = A(K,J) - CDOTC(K-1,A(1,K),1,A(1,J),1)\n T = T/A(K,K)\n A(K,J) = T\n S = S + REAL(T*CONJG(T))\n 10 CONTINUE\n 20 CONTINUE\n S = REAL(A(J,J)) - S\n IF (S .LE. 0.0E0 .OR. AIMAG(A(J,J)) .NE. 0.0E0) GO TO 40\n A(J,J) = CMPLX(SQRT(S),0.0E0)\n 30 CONTINUE\n INFO = 0\n 40 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "51175321278d4145041928ed3fa9399b34d0dace", "size": 2703, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/cpofa.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/cpofa.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/cpofa.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.9634146341, "max_line_length": 69, "alphanum_fraction": 0.5619681835, "num_tokens": 884, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206791658465, "lm_q2_score": 0.760650658103136, "lm_q1q2_score": 0.6860465581643286}} {"text": " Program zhseqr_example\n\n! ZHSEQR Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use blas_interfaces, Only: zgemm\n Use lapack_example_aux, Only: nagf_file_print_matrix_complex_gen_comp\n Use lapack_interfaces, Only: zhseqr, zlange\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nin = 5, nout = 6\n! .. Local Scalars ..\n Complex (Kind=dp) :: alpha, beta\n Real (Kind=dp) :: norm\n Integer :: i, ifail, info, ldc, ldd, ldh, ldz, lwork, n\n! .. Local Arrays ..\n Complex (Kind=dp), Allocatable :: c(:, :), d(:, :), h(:, :), w(:), &\n work(:), z(:, :)\n Real (Kind=dp) :: rwork(1)\n Character (1) :: clabs(1), rlabs(1)\n! .. Intrinsic Procedures ..\n Intrinsic :: cmplx, epsilon\n! .. Executable Statements ..\n Write (nout, *) 'ZHSEQR Example Program Results'\n Write (nout, *)\n Flush (nout)\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n\n ldc = n\n ldd = n\n ldh = n\n ldz = n\n lwork = n\n Allocate (c(ldc,n), d(ldd,n), h(ldh,n), w(n), work(lwork), z(ldz,n))\n\n! Read H from data file\n\n Read (nin, *)(h(i,1:n), i=1, n)\n\n! Store H in D\n d(1:ldd, 1:n) = h(1:ldh, 1:n)\n\n! Print matrix H\n! ifail: behaviour on error exit\n! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft\n ifail = 0\n Call nagf_file_print_matrix_complex_gen_comp('General', ' ', n, n, h, &\n ldh, 'Bracketed', 'F7.4', 'Matrix H', 'Integer', rlabs, 'Integer', &\n clabs, 80, 0, ifail)\n\n! Calculate the eigenvalues and Schur factorization of H\n\n Call zhseqr('Schur form', 'Initialize Z', n, 1, n, h, ldh, w, z, ldz, &\n work, lwork, info)\n\n Write (nout, *)\n If (info>0) Then\n Write (nout, *) 'Failure to converge.'\n Else\n\n! Compute A - Z*T*Z^H from Schur factorization of A, and store in matrix\n! D\n alpha = cmplx(1, kind=dp)\n beta = cmplx(0, kind=dp)\n Call zgemm('N', 'N', n, n, n, alpha, z, ldz, h, ldh, beta, c, ldc)\n alpha = cmplx(-1, kind=dp)\n beta = cmplx(1, kind=dp)\n Call zgemm('N', 'C', n, n, n, alpha, c, ldc, z, ldz, beta, d, ldd)\n\n! Find norm of matrix D and print warning if it is too large\n norm = zlange('O', ldd, n, d, ldd, rwork)\n\n If (norm>epsilon(1.0E0_dp)**0.5_dp) Then\n Write (nout, *) 'Norm of A-(Z*T*Z^H) is much greater than 0.'\n Write (nout, *) 'Schur factorization has failed.'\n Else\n! Print eigenvalues\n Write (nout, *) 'Eigenvalues'\n Write (nout, 100)(w(i), i=1, n)\n End If\n\n End If\n\n100 Format ((3X,4(' (',F7.4,',',F7.4,')',:)))\n End Program\n", "meta": {"hexsha": "e8fa70f14ae30c010ac3cb78343199e400d41966", "size": 2985, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/zhseqr_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/zhseqr_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/zhseqr_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 32.0967741935, "max_line_length": 90, "alphanum_fraction": 0.5477386935, "num_tokens": 989, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569267, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6860465472547193}} {"text": "\n!===================================================================================\n!=================== SUBROUTINE RUNGE - KUTTA 4 ====================================\n!===================================================================================\n\nsubroutine rk42css(Nx,Ny,Nh,alpha,nu,time,dt,omegak,omegak_new,dt_omegak_old,dt_omegak_new)\nimplicit none\ninteger ( kind = 4 ) Nx,Ny,Nh, i, j\nreal ( kind = 8 ) time,dt,alpha,nu,lambda\ncomplex ( kind = 8 ) komega1(Nh,Ny),komega2(Nh,Ny),komega3(Nh,Ny),komega4(Nh,Ny)\ncomplex ( kind = 8 ) omegak(Nh,Ny),omegak_new(Nh,Ny),dum_omegak(Nh,Ny),dt_omegak(Nh,Ny)\ncomplex ( kind = 8 ) dt_omegak_old(Nh,Ny)\ncomplex ( kind = 8 ) dt_omegak_new(Nh,Ny)\n\ndo i = 1,Nh\n do j = 1,Ny\n komega1(i,j) = dt_omegak(i,j)\n dum_omegak(i,j) = omegak(i,j) + komega1(i,j)*dt/2.0\n end do\nend do\n\n call derive2css(Nx,Ny,Nh,alpha,nu,time+dt/2.0,dum_omegak,omegak_new,dt_omegak_old,dt_omegak_new)\n\ndo i = 1,Nh\n do j = 1,Ny\n komega2(i,j) = dt_omegak(i,j)\n dum_omegak(i,j) = omegak(i,j) + komega2(i,j)*dt/2.0\n end do\nend do\n\n call derive2css(Nx,Ny,Nh,alpha,nu,time+dt/2.0,dum_omegak,omegak_new,dt_omegak_old,dt_omegak_new)\n\ndo i = 1,Nh\n do j = 1,Ny\n komega3(i,j) = dt_omegak(i,j)\n dum_omegak(i,j) = omegak(i,j) + komega3(i,j)*dt/2.0\n end do\nend do\n\n call derive2css(Nx,Ny,Nh,alpha,nu,time+dt,dum_omegak,omegak_new,dt_omegak_old,dt_omegak_new)\n\ndo i = 1,Nh\n do j = 1,Ny\n komega4(i,j) = dt_omegak(i,j)\n omegak_new(i,j) = omegak(i,j) + dt/6.0d0*(komega1(i,j) + 2.0d0*komega2(i,j) + 2.0d0*komega3(i,j) + komega4(i,j))\n! omegak_new(i,j) = omegak(i,j) + komega1(i,j)*dt ! EULER SOLVER\n end do\nend do\n\nreturn\n\nend subroutine rk42css\n", "meta": {"hexsha": "6b3993e76b27beb859e63aee4e17bc2d05ece0de", "size": 1687, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/rk42css.f95", "max_stars_repo_name": "RupakMukherjee/Navier-Stokes", "max_stars_repo_head_hexsha": "dfcda1a7d5580759091847477cf2f69d473a88f2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-23T11:35:08.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-23T11:35:08.000Z", "max_issues_repo_path": "src/rk42css.f95", "max_issues_repo_name": "RupakMukherjee/TARA", "max_issues_repo_head_hexsha": "dfcda1a7d5580759091847477cf2f69d473a88f2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-03-25T22:19:12.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-30T23:16:56.000Z", "max_forks_repo_path": "src/rk42css.f95", "max_forks_repo_name": "RupakMukherjee/TARA", "max_forks_repo_head_hexsha": "dfcda1a7d5580759091847477cf2f69d473a88f2", "max_forks_repo_licenses": ["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.8301886792, "max_line_length": 116, "alphanum_fraction": 0.5820983995, "num_tokens": 707, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206791658465, "lm_q2_score": 0.7606506418255927, "lm_q1q2_score": 0.6860465434832757}} {"text": " subroutine halopotentialestimate\n\n include 'commonblocks'\n common /haloestimate/ hdens(0:nmax),hpot(0:nmax),hfr(0:nmax)\n\n eps = 0.0001\n \n do ir=0,nr\n r=ir*dr\n if(r.eq.0.) r = eps\n hdens(ir)=halodensity(r)\n 77 enddo\n\nc now get the potential harmonics of this new density. (BT 2-208)\nc Simpson's rule integration.\n\n s1(0)=0\n r = 2*dr\n s1(2)=(r*dr/3.)*(4*hdens(1)*(1.0-dr/r)**2+hdens(2))\n rold = r \n do ir=4,nr,2\n r=ir*dr\n s1a = (r*dr/3.)*(hdens(ir-2)*(1.0-2*dr/r)**2+\n + 4*hdens(ir-1)*(1.0-dr/r)**2+hdens(ir))\n s1(ir) = s1a + s1(ir-2)*rold/r\n rold = r\n enddo\n s2(nr)=0\n rold = nr*dr\n do ir=nr-2,2,-2\n r=ir*dr\n s2a = (r*dr/3.)*(hdens(ir+2)*(1.0+2*dr/r)+\n & 4*hdens(ir+1)*(1.0+dr/r)+hdens(ir))\n s2(ir) = s2a + s2(ir+2)\n rold = r\n enddo\n\n do ir = 2,nr,2\n r = ir*dr\n hpot(ir)=(4.*pi)*(s1(ir)+s2(ir))\n hfr(ir)=-(4.*pi)*s1(ir)/r\n enddo\n\n hpot(0)=3*(hpot(2)-hpot(4))+hpot(6)\n hfr(0)=0.0\n \nc then linearly interpolate other bins.\n \n do ir=1,nr-1,2\n hpot(ir)=(hpot(ir-1)+hpot(ir+1))/2.\n hfr(ir)=(hfr(ir-1)+hfr(ir+1))/2.\n enddo\n\n return\n end\n\n function haloforce(r)\n\n include 'commonblocks'\n common /haloestimate/ hdens(0:nmax),hpot(0:nmax),hfr(0:nmax)\n\n ihi=int(r/dr)+1\n if (ihi.lt.1) ihi=1\n if (ihi.gt.nr) ihi=nr\n r1=dr*(ihi-1)\n r2=dr*ihi\n t=(r-r1)/(r2-r1)\n tm1 = 1.0 - t\n if (r.eq.0.) then\n lmaxx=0\n costheta=0\n else\n costheta=z/r\n lmaxx=lmax\n endif\n haloforce = (t*hfr(ihi)+ tm1*hfr(ihi-1))\n\n return\n end\n\n", "meta": {"hexsha": "793d6503ecfc414c4e1b9ec0af67654a29cdc0b0", "size": 1804, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/amuse/community/galactics/src/src/halopotentialestimate.f", "max_stars_repo_name": "rknop/amuse", "max_stars_repo_head_hexsha": "85d5bdcc29cfc87dc69d91c264101fafd6658aec", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 131, "max_stars_repo_stars_event_min_datetime": "2015-06-04T09:06:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-01T12:11:29.000Z", "max_issues_repo_path": "src/amuse/community/galactics/src/src/halopotentialestimate.f", "max_issues_repo_name": "rknop/amuse", "max_issues_repo_head_hexsha": "85d5bdcc29cfc87dc69d91c264101fafd6658aec", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 690, "max_issues_repo_issues_event_min_datetime": "2015-10-17T12:18:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:15:58.000Z", "max_forks_repo_path": "src/amuse/community/galactics/src/src/halopotentialestimate.f", "max_forks_repo_name": "rieder/amuse", "max_forks_repo_head_hexsha": "3ac3b6b8f922643657279ddee5c8ab3fc0440d5e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 102, "max_forks_repo_forks_event_min_datetime": "2015-01-22T10:00:29.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-09T13:29:43.000Z", "avg_line_length": 22.2716049383, "max_line_length": 69, "alphanum_fraction": 0.4678492239, "num_tokens": 736, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569267, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.686046542361035}} {"text": "c=======================================================================\nc\nc subroutine SCHURO \nc\nc Matrix Schur Decomposition and sorts eigenvalues (decrease order)\nc cf. SCHUR subroutine \nc\nc-----------------------------------------------------------------------\n SUBROUTINE schuro ( n, X, iwork, dwork,\n & eigval, soreig, vpmat, info )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : matrix size integer\nc X : matrix (n*n) double\nc\nc WORKSPACE \nc iwork : vector (n) integer\nc dwork : vector ( n*(2*n+6) ) double\nc\nc OUTPUT \nc eigval : eigenvalues (n) double\nc soreig : sorted eigenvalues (n) double\nc vpmat : eigenvectors (n*n) double\nc info : diagnostic argument integer\nc\nc CALL \nc SCHUR : matrix Schur decomposition\nc AVODI : sorts a vector (decrease order) with index in old vector\nc ACMI : sorts the columns of a vectorized matrix as index\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\nc\nc arguments i/o\n INTEGER n, info\n DOUBLE PRECISION eigval(*), soreig(*), X(*), vpmat(*)\nc\nc workspaces\n INTEGER iwork(*)\n DOUBLE PRECISION dwork(*)\nc\nc local variables\n INTEGER piw, pvs, pdw\nc\nc external subroutines\n EXTERNAL schur, AVODI, ACMI\nc\nc-----------------------------------------------------------------------\nc\nc initialization\n info = 0\nc\nc pointers for integer work space : iwork\nc ---------------------------------------\n piw = 1\nc piw : pointer for SCHUR, AVODI and ACMI who need (n)\nc pinext = piw + ( n )\nc pinext : pointer for the next iwork array\nc\nc Total size of iwork array ( n )\nc\nc pointers for double precision work space : work(nasmax,*)\nc ----------------------------------------------------------\n pvs = 1\nc pvs : pointer eigenvectors matrix so (n*n) more\n pdw = pvs + ( n*n )\nc pdw : pointer SCHUR who needs ( n*(n+6) ), so ( n*(n+6) ) more\nc pdnext : pointer of the next dwork array\nc\nc Total size of work array = ( n*(2*n + 6) )\nc\nc-----------------------------------------------------------------------\nc\nc Schur factorization\n CALL schur ( n, X, iwork(piw), dwork(pdw),\n & eigval, dwork(pvs), info )\n IF (info .LT. 0) RETURN\nc\nc sorts the eigenvalues vector (decrease index order)\nc iwork is index of vector elements in the old vector\n CALL AVODI ( n, eigval, soreig, iwork(piw) )\nc\nc sorts the columns of a vs (eigenvectors) as index\nc iwork is index of vector elements in the old vector\n CALL ACMI ( n, n, dwork(pvs), iwork(piw), vpmat )\nc\n RETURN\n END\n\n", "meta": {"hexsha": "bdea5e23ec2eeb167e2c8c141c90608d515a9e77", "size": 3122, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/alglin/cmc/schuro.f", "max_stars_repo_name": "alpgodev/numx", "max_stars_repo_head_hexsha": "d2d3a0713020e1b83b65d3a661c3801ea256aff9", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-07-25T20:28:58.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-10T18:52:08.000Z", "max_issues_repo_path": "src/math/alglin/cmc/schuro.f", "max_issues_repo_name": "alpgodev/numx", "max_issues_repo_head_hexsha": "d2d3a0713020e1b83b65d3a661c3801ea256aff9", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/math/alglin/cmc/schuro.f", "max_forks_repo_name": "alpgodev/numx", "max_forks_repo_head_hexsha": "d2d3a0713020e1b83b65d3a661c3801ea256aff9", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.9347826087, "max_line_length": 78, "alphanum_fraction": 0.4401024984, "num_tokens": 759, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206686206199, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6860465403557267}} {"text": "!> @ingroup insertion_sort_asc\n!> \n!> @brief \n!> Run an insertion sort on a vector of double precision values. \n!>\n!> @details \n!> Run an ascending on a vector of double precision values to sort them in the specified order.\n!>\n!> @param vec\n!> The vector double precision values to be sorted.\n!>\n!> @author Arin R. Bratt\n!> @date 11/07/2014\npure subroutine insertion_sort_asc_dble(vec)\n ! Arguments\n double precision, intent(inout) :: vec(:)\n \n ! Variables\n double precision :: double_precision_value\n double precision :: swap_value\n integer :: i\n integer :: j\n \n \n ! Sort to the first element\n if (vec(size(vec,1)) > vec(1)) then\n double_precision_value = vec(1)\n else\n double_precision_value = vec(size(vec,1))\n vec(size(vec,1)) = vec(1)\n end if\n \n do i = size(vec,1) - 1,2,-1\n if (double_precision_value > vec(i)) then\n ! Swap double precision values double_precision_value and vec(i).\n swap_value = double_precision_value\n double_precision_value = vec(i)\n vec(i) = swap_value\n end if\n end do\n\n ! Run regualr insertion sort\n do j = 3,size(vec,1)\n swap_value = vec(j)\n i = j - 1\n if (vec(i) > swap_value) then\n vec(j) = vec(i)\n i = i - 1\n do\n if (.not. vec(i) > swap_value) exit\n vec(i + 1) = vec(i)\n i = i - 1\n end do\n vec(i + 1) = swap_value\n end if\n end do\nend subroutine insertion_sort_asc_dble\n\n\n", "meta": {"hexsha": "7465d0a30619ef94aed24b221cbaf6ab44de602e", "size": 1452, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/insertion_sort_asc_dble.f90", "max_stars_repo_name": "arinrb/bsort", "max_stars_repo_head_hexsha": "17cc0e2cbe52af808bae860d53dd4e4d691f4674", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-11-08T18:36:23.000Z", "max_stars_repo_stars_event_max_datetime": "2015-11-08T18:36:23.000Z", "max_issues_repo_path": "src/insertion_sort_asc_dble.f90", "max_issues_repo_name": "arinrb/bsort", "max_issues_repo_head_hexsha": "17cc0e2cbe52af808bae860d53dd4e4d691f4674", "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/insertion_sort_asc_dble.f90", "max_forks_repo_name": "arinrb/bsort", "max_forks_repo_head_hexsha": "17cc0e2cbe52af808bae860d53dd4e4d691f4674", "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.2, "max_line_length": 95, "alphanum_fraction": 0.6170798898, "num_tokens": 425, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833945721304, "lm_q2_score": 0.8856314828740729, "lm_q1q2_score": 0.685995440344549}} {"text": " SUBROUTINE slSVDS (M, N, MP, NP, B, U, W, V, WORK, X)\n*+\n* - - - - - - -\n* S V D S\n* - - - - - - -\n*\n* From a given vector and the SVD of a matrix (as obtained from\n* the SVD routine), obtain the solution vector (double precision)\n*\n* This routine solves the equation:\n*\n* A . x = b\n*\n* where:\n*\n* A is a given M (rows) x N (columns) matrix, where M.GE.N\n* x is the N-vector we wish to find\n* b is a given M-vector\n*\n* by means of the Singular Value Decomposition method (SVD). In\n* this method, the matrix A is first factorised (for example by\n* the routine slSVD) into the following components:\n*\n* A = U x W x VT\n*\n* where:\n*\n* A is the M (rows) x N (columns) matrix\n* U is an M x N column-orthogonal matrix\n* W is an N x N diagonal matrix with W(I,I).GE.0\n* VT is the transpose of an NxN orthogonal matrix\n*\n* Note that M and N, above, are the LOGICAL dimensions of the\n* matrices and vectors concerned, which can be located in\n* arrays of larger PHYSICAL dimensions MP and NP.\n*\n* The solution is found from the expression:\n*\n* x = V . [diag(1/Wj)] . (transpose(U) . b)\n*\n* Notes:\n*\n* 1) If matrix A is square, and if the diagonal matrix W is not\n* adjusted, the method is equivalent to conventional solution\n* of simultaneous equations.\n*\n* 2) If M>N, the result is a least-squares fit.\n*\n* 3) If the solution is poorly determined, this shows up in the\n* SVD factorisation as very small or zero Wj values. Where\n* a Wj value is small but non-zero it can be set to zero to\n* avoid ill effects. The present routine detects such zero\n* Wj values and produces a sensible solution, with highly\n* correlated terms kept under control rather than being allowed\n* to elope to infinity, and with meaningful values for the\n* other terms.\n*\n* Given:\n* M,N i numbers of rows and columns in matrix A\n* MP,NP i physical dimensions of array containing matrix A\n* B d(M) known vector b\n* U d(MP,NP) array containing MxN matrix U\n* W d(N) NxN diagonal matrix W (diagonal elements only)\n* V d(NP,NP) array containing NxN orthogonal matrix V\n*\n* Returned:\n* WORK d(N) workspace\n* X d(N) unknown vector x\n*\n* Reference:\n* Numerical Recipes, section 2.9.\n*\n* P.T.Wallace Starlink 29 October 1993\n*\n* Copyright (C) 1995 Rutherford Appleton Laboratory\n*\n* License:\n* This program is free software; you can redistribute it and/or modify\n* it under the terms of the GNU General Public License as published by\n* the Free Software Foundation; either version 2 of the License, or\n* (at your option) any later version.\n*\n* This program is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU General Public License for more details.\n*\n* You should have received a copy of the GNU General Public License\n* along with this program (see SLA_CONDITIONS); if not, write to the\n* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,\n* Boston, MA 02110-1301 USA\n*\n* Copyright (C) 1995 Association of Universities for Research in Astronomy Inc.\n*-\n\n IMPLICIT NONE\n\n INTEGER M,N,MP,NP\n DOUBLE PRECISION B(M),U(MP,NP),W(N),V(NP,NP),WORK(N),X(N)\n\n INTEGER J,I,JJ\n DOUBLE PRECISION S\n\n\n\n* Calculate [diag(1/Wj)] . transpose(U) . b (or zero for zero Wj)\n DO J=1,N\n S=0D0\n IF (W(J).NE.0D0) THEN\n DO I=1,M\n S=S+U(I,J)*B(I)\n END DO\n S=S/W(J)\n END IF\n WORK(J)=S\n END DO\n\n* Multiply by matrix V to get result\n DO J=1,N\n S=0D0\n DO JJ=1,N\n S=S+V(J,JJ)*WORK(JJ)\n END DO\n X(J)=S\n END DO\n\n END\n", "meta": {"hexsha": "53209f2db744163f51f57c149671f85f40d32414", "size": 3965, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iraf.v2161/math/slalib/svdsol.f", "max_stars_repo_name": "ysBach/irafdocgen", "max_stars_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:19:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T16:48:42.000Z", "max_issues_repo_path": "math/slalib/svdsol.f", "max_issues_repo_name": "kirxkirx/iraf", "max_issues_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-30T13:48:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-02T19:40:25.000Z", "max_forks_repo_path": "math/slalib/svdsol.f", "max_forks_repo_name": "kirxkirx/iraf", "max_forks_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.9765625, "max_line_length": 80, "alphanum_fraction": 0.6206809584, "num_tokens": 1153, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554444, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6859954333978944}} {"text": "submodule(euler_interface_m) euler_prob_0007_m\n implicit none\n\ncontains\n\n module character(len=20) function euler0007()\n write (euler0007, \"(i20)\") ans(10000)\n end function euler0007\n\n integer function ans(n)\n use euler_primes_m, only: is_prime\n implicit none\n integer, intent(in) :: n\n integer :: i, j\n\n i = 0; j = 0\n loop_1: do\n if (j == n + 1) exit loop_1\n i = i + 1\n if (mod(i, 2) == 2 .and. i /= 2) then\n cycle loop_1\n else if (is_prime(int(i))) then\n j = j + 1\n end if\n end do loop_1\n ans = i\n end function ans\nend submodule euler_prob_0007_m\n", "meta": {"hexsha": "46a45e64fbc588a9c87bebb92f0e62ebdab2c1e3", "size": 712, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "docs/src/prob_0007_m.f90", "max_stars_repo_name": "han190/PE-Fortran", "max_stars_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-02-09T07:07:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-31T07:45:48.000Z", "max_issues_repo_path": "docs/src/prob_0007_m.f90", "max_issues_repo_name": "han190/PE-Fortran", "max_issues_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-14T00:48:58.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-14T00:48:58.000Z", "max_forks_repo_path": "docs/src/prob_0007_m.f90", "max_forks_repo_name": "han190/PE-Fortran", "max_forks_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-04T21:29:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T21:29:45.000Z", "avg_line_length": 24.5517241379, "max_line_length": 49, "alphanum_fraction": 0.5280898876, "num_tokens": 212, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181874, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.6859954241130602}} {"text": "module simpson_mod\n use :: quad_mod\n implicit none\n\n private\n type, public, extends(quad_type) :: simpson_type\n private\n integer :: n\n contains\n procedure, public :: init\n procedure, public :: integrate\n end type simpson_type\n\ncontains\n\n subroutine init(self, n)\n implicit none\n class(simpson_type), intent(inout) :: self\n integer, intent(In) :: n\n self%n = n\n end subroutine init\n\n function integrate(self, f, a, b) result(r)\n use, intrinsic :: iso_fortran_env, only : dp => REAL64\n use :: quad_func_interface\n implicit none\n class(simpson_type), intent(in) :: self\n procedure(quad_func_type) :: f\n real(kind=dp), intent(in) :: a, b\n real(kind=dp) :: r\n real(kind=dp) :: x, delta\n integer :: i\n x = a\n r = f(x)\n delta = (b - a)/self%n\n do i = 1, self%n\n x = x + delta\n r = r + f(x)\n end do\n r = (b - a)*r/(self%n + 1)\n end function integrate\n\n\nend module simpson_mod\n", "meta": {"hexsha": "fd037c496769088c3fd23bc7847eedbead438956", "size": 1081, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran/Integrate/simpson_mod.f90", "max_stars_repo_name": "Gjacquenot/training-material", "max_stars_repo_head_hexsha": "16b29962bf5683f97a1072d961dd9f31e7468b8d", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 115, "max_stars_repo_stars_event_min_datetime": "2015-03-23T13:34:42.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T00:27:21.000Z", "max_issues_repo_path": "Fortran/Integrate/simpson_mod.f90", "max_issues_repo_name": "Gjacquenot/training-material", "max_issues_repo_head_hexsha": "16b29962bf5683f97a1072d961dd9f31e7468b8d", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 56, "max_issues_repo_issues_event_min_datetime": "2015-02-25T15:04:26.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-03T07:42:48.000Z", "max_forks_repo_path": "Fortran/Integrate/simpson_mod.f90", "max_forks_repo_name": "Gjacquenot/training-material", "max_forks_repo_head_hexsha": "16b29962bf5683f97a1072d961dd9f31e7468b8d", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 59, "max_forks_repo_forks_event_min_datetime": "2015-11-26T11:44:51.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T00:27:22.000Z", "avg_line_length": 24.0222222222, "max_line_length": 62, "alphanum_fraction": 0.540240518, "num_tokens": 293, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6859954240451763}} {"text": "MODULE ExperimentosNumericos\n\n ! Modulo que implementa os problemas com Solucao (ou benchmarks)\n \n IMPLICIT NONE\n\n CONTAINS\n !-------------------- FUNCOES DO EXPERIMENTO 5 -----------------------\n DOUBLE PRECISION FUNCTION CC_U_W_experimento5(t, j) RESULT(valor)\n USE VariaveisGerais\n INTEGER, INTENT(IN) :: t, j\n \n valor = -DCOS(Xi)*DSIN( yu(j) )*DEXP(-2.0d0*(ht*(t-1) + Ti))\n \n END FUNCTION CC_U_W_experimento5\n \n \n DOUBLE PRECISION FUNCTION CC_U_E_experimento5(t, j) RESULT(valor)\n USE VariaveisGerais\n INTEGER, INTENT(IN) :: t, j\n \n valor = -DCOS(Xf)*DSIN( yu(j) )*DEXP(-2.0d0*(ht*(t-1) + Ti))\n \n END FUNCTION CC_U_E_experimento5\n \n\n DOUBLE PRECISION FUNCTION CC_U_S_experimento5(t, i) RESULT(valor)\n USE VariaveisGerais\n INTEGER, INTENT(IN) :: t, i\n \n valor = -DCOS( xu(i) )*DSIN( Yi )*DEXP(-2.0d0*(ht*(t-1)+Ti))\n \n END FUNCTION CC_U_S_experimento5\n \n\n DOUBLE PRECISION FUNCTION CC_U_N_experimento5(t, i) RESULT(valor)\n USE VariaveisGerais\n INTEGER, INTENT(IN) :: t, i\n \n valor = -DCOS( xu(i) )*DSIN( Yf )*DEXP(-2.0d0*(ht*(t-1)+Ti))\n \n END FUNCTION CC_U_N_experimento5\n\n DOUBLE PRECISION FUNCTION CC_V_W_experimento5(t, j) RESULT(valor)\n USE VariaveisGerais\n INTEGER, INTENT(IN) :: t, j\n \n valor = DSIN(Xi)*DCOS( yv(j) )*DEXP(-2.0d0*(ht*(t-1)+Ti))\n \n END FUNCTION CC_V_W_experimento5\n\n\n DOUBLE PRECISION FUNCTION CC_V_E_experimento5(t, j) RESULT(valor)\n USE VariaveisGerais\n INTEGER, INTENT(IN) :: t, j\n \n valor = DSIN(Xf)*DCOS( yv(j) )*DEXP(-2.0d0*(ht*(t-1)+Ti))\n \n END FUNCTION CC_V_E_experimento5\n\n \n DOUBLE PRECISION FUNCTION CC_V_S_experimento5(t, i) RESULT(valor)\n USE VariaveisGerais\n INTEGER, INTENT(IN) :: t, i\n \n valor = DSIN( xv(i) )*DCOS(Yi)*DEXP(-2.0d0*(ht*(t-1)+Ti))\n \n END FUNCTION CC_V_S_experimento5\n\n\n DOUBLE PRECISION FUNCTION CC_V_N_experimento5(t, i) RESULT(valor)\n USE VariaveisGerais\n INTEGER, INTENT(IN) :: t, i\n \n valor = DSIN( xv(i) )*DCOS(Yf)*DEXP(-2.0d0*(ht*(t-1)+Ti))\n \n END FUNCTION CC_V_N_experimento5\n \n DOUBLE PRECISION FUNCTION PressaoAnaliticaExperimento5(t, volume) RESULT(valor)\n USE VariaveisGerais\n INTEGER, INTENT(IN) :: t, volume\n INTEGER :: i, j\n \n j = FLOOR ( DBLE(volume-1)/Nx ) + 1\n i = volume - (j - 1)*Nx\n valor = -(1.0d0/(4.0d0*Re))*( DCOS(2.0d0*xv(i)) + DCOS(2.0d0*yu(j)) )*DEXP(-4.0d0 * (ht*(t-1.5d0) + Ti) ) \n \n END FUNCTION PressaoAnaliticaExperimento5\n \n DOUBLE PRECISION FUNCTION PressaoInicialExperimento5(t, volume) RESULT(valor)\n USE VariaveisGerais\n INTEGER, INTENT(IN) :: t, volume\n INTEGER :: i, j\n \n j = FLOOR ( DBLE(volume-1)/Nx ) + 1\n i = volume - (j - 1)*Nx\n valor = -(1.0d0/(4.0d0*Re))*( DCOS(2.0d0*xv(i)) + DCOS(2.0d0*yu(j)) )\n \n END FUNCTION PressaoInicialExperimento5\n\n DOUBLE PRECISION FUNCTION VelocidadeU_InicialExperimento5(t, volume) RESULT(valor)\n USE VariaveisGerais\n INTEGER, INTENT(IN) :: t, volume\n INTEGER :: i, j\n \n j = FLOOR ( DBLE(volume-1)/(Nx-1) ) + 1\n i = volume - (j - 1)*(Nx-1)\n valor = -DCOS(xu(i))*DSIN(yu(j))\n \n END FUNCTION VelocidadeU_InicialExperimento5\n \n DOUBLE PRECISION FUNCTION VelocidadeV_InicialExperimento5(t, volume) RESULT(valor)\n USE VariaveisGerais\n INTEGER, INTENT(IN) :: t, volume\n INTEGER :: i, j\n \n j = FLOOR ( DBLE(volume-1)/Nx ) + 1\n i = volume - (j - 1)*Nx\n valor = DSIN(xv(i))*DCOS(yv(j)) \n \n END FUNCTION VelocidadeV_InicialExperimento5\n\n DOUBLE PRECISION FUNCTION VelocidadeU_AnaliticaExperimento5(t, volume) RESULT(valor)\n USE VariaveisGerais\n INTEGER, INTENT(IN) :: t, volume\n INTEGER :: i, j\n\n j = FLOOR ( DBLE(volume-1)/(Nx-1) ) + 1\n i = volume - (j - 1)*(Nx-1)\n valor = -DCOS(xu(i))*DSIN(yu(j))*DEXP(-2.0d0*(ht*(t-1)+Ti))\n\n END FUNCTION VelocidadeU_AnaliticaExperimento5\n\n DOUBLE PRECISION FUNCTION VelocidadeV_AnaliticaExperimento5(t, volume) RESULT(valor)\n USE VariaveisGerais\n INTEGER, INTENT(IN) :: t, volume\n INTEGER :: i, j\n\n j = FLOOR ( DBLE(volume-1)/(Nx) ) + 1\n i = volume - (j - 1)*(Nx)\n valor = DSIN(xv(i))*DCOS(yv(j))*DEXP(-2.0d0*(ht*(t-1)+Ti))\n\n END FUNCTION VelocidadeV_AnaliticaExperimento5\n \n !-------------------- FUNCOES DO EXPERIMENTO 5 -----------------------\n \nEND MODULE ExperimentosNumericos\n", "meta": {"hexsha": "a381e3eacfa2ded8f00efe8ef8f642df26ec8204", "size": 4567, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "experimentos_numericos.f90", "max_stars_repo_name": "RevertonLuis/NavierStokesSpaceTimeParallelProjectionMethod", "max_stars_repo_head_hexsha": "23fbf3b01a34c244d8928fae4ad9d12bffef8d07", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-02T16:28:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-02T16:28:12.000Z", "max_issues_repo_path": "experimentos_numericos.f90", "max_issues_repo_name": "RevertonLuis/NavierStokesSpaceTimeParallelProjectionMethod", "max_issues_repo_head_hexsha": "23fbf3b01a34c244d8928fae4ad9d12bffef8d07", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "experimentos_numericos.f90", "max_forks_repo_name": "RevertonLuis/NavierStokesSpaceTimeParallelProjectionMethod", "max_forks_repo_head_hexsha": "23fbf3b01a34c244d8928fae4ad9d12bffef8d07", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.8581081081, "max_line_length": 114, "alphanum_fraction": 0.6003941318, "num_tokens": 1510, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314647623016, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6859954217069967}} {"text": "! This module contains all constants and declarations \n! of variables read in by the function read_data. These\n! variables are used by many functions.\n\nMODULE constants\n INTEGER, PARAMETER :: dp = KIND(1.0D0)\n INTEGER, PARAMETER :: dpc = KIND((1.0D0,1.0D0))\nEND MODULE constants\n\n\n! F90 program library, adapted from Numerical Recipes\n! All functions have been translated to F90 from F77\n\nMODULE F90library\n USE constants\nCONTAINS\n\n !\n ! Routines to do mtx inversion, from Numerical\n ! Recipes, Teukolsky et al. Routines included\n ! below are MATINV, LUDCMP and LUBKSB. See chap 2\n ! of Numerical Recipes for further details\n !\n SUBROUTINE matinv(a,n,d)\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: n\n INTEGER :: i, j\n REAL(DP), DIMENSION(n,n), INTENT(INOUT) :: a\n REAL(DP), ALLOCATABLE :: y(:,:)\n REAL(DP) :: d\n INTEGER, ALLOCATABLE :: indx(:)\n\n ALLOCATE (y( n, n)) ; ALLOCATE ( indx (n))\n y=0.\n ! setup identity matrix\n DO i=1,n\n y(i,i)=1.\n ENDDO\n ! LU decompose the matrix just once\n CALL lu_decompose(a,n,indx,d)\n\n ! Find inverse by columns\n DO j=1,n\n CALL lu_linear_equation(a,n,indx,y(:,j))\n ENDDO\n ! The original matrix a was destroyed, now we equate it with the inverse y \n a=y\n\n DEALLOCATE ( y ); DEALLOCATE ( indx )\n\n END SUBROUTINE matinv\n\n ! Given an NxN matrix A(N,N), this routine replaces it by the LU \n ! decomposed one, where the matrix elements are stored in the same \n ! matrix A. The array indx is an output vector which records the row\n ! permutation effected by the partial pivoting. d is the determinant\n !\n SUBROUTINE lu_decompose(a,n,indx,d)\n IMPLICIT NONE\n INTEGER :: n, i, j, k, imax\n REAL(DP) :: sum , tiny, aamax, dum, d\n REAL(DP), DIMENSION(n,n) :: a\n INTEGER, DIMENSION(n) :: indx\n REAL(DP), ALLOCATABLE :: vv(:)\n\n tiny=1.0e-20\n ALLOCATE ( vv(n) )\n D=1.\n DO i=1,n\n aamax=0.\n DO j=1,n\n IF (ABS(a(i,j)) > aamax) aamax=ABS(a(i,j))\n ENDDO\n ! Zero is the largest element\n IF (aamax == 0.) STOP 'Singular matrix.'\n ! No nonzero largest element\n vv(i)=1./aamax\n ENDDO\n ! loop over columns\n DO j=1,n\n ! solves equation 2.3.12 except for i=j of Numerical Recipes\n IF (j > 1) THEN\n DO i=1,j-1\n sum=a(i,j)\n IF (i > 1)THEN\n DO k=1,i-1\n sum=sum-a(i,k)*a(k,j)\n ENDDO\n a(i,j)=sum\n ENDIF\n ENDDO\n ENDIF\n ! start searching for largest pivot element\n aamax=0.\n DO i=j,n\n sum=a(i,j)\n IF (j > 1)THEN\n DO k=1,j-1\n sum=sum-a(i,k)*a(k,j)\n ENDDO\n a(i,j)=sum\n ENDIF\n dum=vv(i)*ABS(sum)\n IF (dum >= aamax) THEN\n imax=i\n aamax=dum\n ENDIF\n ENDDO\n ! interchange of rows\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 ENDDO\n ! change of parity for determinant\n d=-d\n vv(imax)=vv(j)\n ENDIF\n indx(j)=imax\n IF(j /= n) THEN\n IF(a(j,j) == 0.) a(j,j)=tiny\n dum=1./a(j,j)\n DO i=j+1,n\n a(i,j)=a(i,j)*dum\n ENDDO\n ENDIF\n ! set up determinant\n d=d*a(j,j)\n ENDDO\n IF(a(n,n) == 0.) a(n,n)=tiny\n DEALLOCATE ( vv)\n\n END SUBROUTINE lu_decompose\n\n ! Solves set of linear equations Ax=b, A is input as an LU decompomsed\n ! matrix and indx keeps track of the permutations of the rows. b is input\n ! as the right-hand side vector b and returns the solution x. A, n and indx\n ! are not modified by this routine. This function takes into that b can contain\n ! many zeros and is therefore suitable for matrix inversion\n\n\n SUBROUTINE lu_linear_equation(a,n,indx,b)\n IMPLICIT NONE\n INTEGER :: n, ii, ll, i, j\n REAL(DP) :: sum \n REAL(DP), DIMENSION(n,n) :: a\n REAL(DP), DIMENSION(n) :: b\n INTEGER, DIMENSION(n) :: indx\n\n ii=0\n ! First we solve equation 2.3.6 of numerical recipes \n DO i=1,n\n ll=indx(i)\n sum=b(ll)\n b(ll)=b(i)\n IF (ii /= 0)THEN\n DO j=ii,i-1\n sum=sum-a(i,j)*b(j)\n ENDDO\n ELSEIF (sum /= 0.) THEN\n ii=i\n ENDIF\n b(i)=sum\n ENDDO\n ! then we solve equation 2.3.7\n DO i=n,1,-1\n sum=b(i)\n IF (i < n) THEN\n DO j=i+1,n\n sum=sum-a(i,j)*b(j)\n ENDDO\n ENDIF\n ! store a component of the solution x in the same place as b\n b(i)=sum/a(i,i)\n ENDDO\n\n END SUBROUTINE lu_linear_equation\n\n ! determine eigenvalues and eigenvectors of a real symmetric\n ! tri-diagonal matrix, or a real, symmetric matrix previously\n ! reduced by function tred2 to tri-diagonal form. On input,\n ! d[] contains the diagonal element and e[] the sub-diagonal\n ! of the tri-diagonal matrix. On output d[] contains the\n ! eigenvalues and e[] is destroyed. If eigenvectors are\n ! desired z[][] on input contains the identity matrix. If\n ! eigenvectors of a matrix reduced by tred2() are required,\n ! then z[][] on input is the matrix output from tred2().\n ! On output, the k'th column returns the normalized eigenvector\n ! corresponding to d[k]. \n ! The function is modified from the version in Numerical recipe.\n\n SUBROUTINE tqli(d,e,n,z)\n IMPLICIT NONE\n INTEGER :: n \n REAL(DP) :: d(n),e(n),z(n,n)\n INTEGER :: i,iter,k,l,m\n REAL(DP) :: b,c,dd,f,g,p,r,s,pythag,one\n\n DO i=2,n\n e(i-1)=e(i)\n ENDDO\n one=1.\n DO l=1,n\n iter=0\n ITERATE : DO\n DO m=l,n-1\n dd=ABS(d(m))+ABS(d(m+1))\n IF (ABS(e(m))+dd == dd) EXIT\n ENDDO\n IF(m == l) EXIT ITERATE\n IF(iter == 30) STOP 'too many iterations in tqli'\n iter=iter+1\n g=(d(l+1)-d(l))/(2.*e(l))\n! r=pythag(g,one)\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 == 0.) THEN\n d(i+1)=d(i+1)-p\n e(m)=0.\n CYCLE ITERATE\n ENDIF\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 ! Omit lines from here ...\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 ENDDO\n ! ... to here when finding only eigenvalues.\n ENDDO\n d(l)=d(l)-p\n e(l)=g\n e(m)=0.\n ENDDO ITERATE\n ENDDO\n\n END SUBROUTINE tqli\n\n\n REAL(DP) FUNCTION pythag(a,b)\n REAL(DP) :: a,b\n REAL(DP) :: absa,absb\n absa=ABS(a)\n absb=ABS(b)\n IF(absa > absb) THEN\n pythag=absa*sqrt(1.+(absb/absa)**2)\n ELSE\n IF(absb == 0.) THEN\n pythag=0.\n ELSE\n pythag=absb*sqrt(1.+(absa/absb)**2)\n ENDIF\n ENDIF\n\n END FUNCTION pythag\n\n ! perform a Housholder reduction of a real symmetric matrix\n ! a[][]. On output a[][] is replaced by the orthogonal matrix \n ! effecting the transformation. d[] returns the diagonal elements\n ! of the tri-diagonal matrix, and e[] the off-diagonal elements, \n ! with e[0] = 0.\n ! The function is modified from the version in Numerical recipes.\n\n SUBROUTINE tred2(a,n,d,e)\n IMPLICIT NONE\n INTEGER :: n\n REAL(DP) :: a(n,n),d(n),e(n)\n INTEGER :: i,j,k,l\n REAL(DP) :: f,g,h,hh,scale\n\n DO i=n,2,-1\n l=i-1\n h=0.\n scale=0.\n IF (l > 1) THEN\n scale=SUM(abs(a(i,1:l)))\n IF (scale == 0.) THEN\n e(i)=a(i,l)\n ELSE\n a(i,1:l)=a(i,1:l)/scale\n h=sum(a(i,1:l)**2)\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 ! Omit following line if finding only eigenvalues\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 ENDDO\n DO k=j+1,l\n g=g+a(k,j)*a(i,k)\n ENDDO\n e(j)=g/h\n f=f+e(j)*a(i,j)\n ENDDO\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 ENDDO\n ENDDO\n ENDIF\n ELSE\n e(i)=a(i,l)\n ENDIF\n d(i)=h\n ENDDO\n ! Omit following line if finding only eigenvalues.\n d(1)=0.\n e(1)=0.\n DO i=1,n\n ! Delete lines from here ...\n l=i-1\n IF (d(i) /= 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 ENDDO\n DO k=1,l\n a(k,j)=a(k,j)-g*a(k,i)\n ENDDO\n ENDDO\n endif\n ! ... to here when finding only eigenvalues.\n d(i)=a(i,i)\n ! Also delete lines from here ...\n a(i,i)=1.\n DO j=1,l\n a(i,j)=0.\n a(j,i)=0.\n ENDDO\n ! ... to here when finding only eigenvalues.\n ENDDO\n\n END SUBROUTINE tred2\n\n ! takes as input xa[1,..,n] and ya[1,..,n] together with \n ! a given value of x and returns a value y and an error \n ! estimate dy. If P(x) is a polynomial of degree N - 1 such \n ! that P(xa_i) = ya_i, i = 0,..,n-1, then the returned \n ! value is y = P(x). \n\n SUBROUTINE polint(xa,ya,n,x,y,dy)\n IMPLICIT NONE\n INTEGER :: i, ns, m, n\n REAL(DP), DIMENSION(n) :: xa,ya\n REAL(DP), DIMENSION(:), ALLOCATABLE :: c , d\n REAL(DP) :: den ,dif, dift, ho, hp, w, x, y, dy\n\n ALLOCATE ( c(n), d(n) )\n ns=1 \n dif=ABS(x-xa(1)) \n DO i=1,n \n dift=ABS(x-xa(i)) \n IF (dift < dif) THEN \n ns=i \n dif=dift \n ENDIF\n c(i)=ya(i) \n d(i)=ya(i) \n ENDDO\n y=ya(ns) \n ns=ns-1 \n DO m=1,n-1 \n DO i=1,n-m \n ho=xa(i)-x \n hp=xa(i+m)-x \n w=c(i+1)-d(i) \n den=ho-hp \n IF(den == 0.) WRITE(6,*) 'Error in POLINT, den =0'\n den=w/den \n d(i)=hp*den \n c(i)=ho*den \n ENDDO\n IF (2*ns < n-m)THEN \n dy=c(ns+1) \n ELSE \n dy=d(ns) \n ns=ns-1 \n ENDIF\n y=y+dy \n ENDDO\n DEALLOCATE ( c, d)\n\n END SUBROUTINE polint\n\n ! takes as input x[1,..,n] and y[1,..,n] containing a tabulation\n ! y_i = f(x_i) with x_0 < x_1 < .. < x_(n - 1) \n ! together with yp_1 and yp2 for first derivatives f(x) at x_0 \n ! and x_(n-1), respectively. Then the\n ! function returns y2[1,..,n] which contains the second \n ! derivatives of f(x_i)at each point x_i. If yp1 and/or yp2 \n ! is larger than the constant INFINITY the function will \n ! put corresponding second derivatives to zero.\n\n SUBROUTINE spline(x,y,n,yp1,ypn,y2)\n IMPLICIT NONE\n INTEGER :: i, k, n\n REAL(DP), DIMENSION(n) :: x, y, y2\n REAL(DP), DIMENSION(:), ALLOCATABLE :: u\n REAL(DP) :: p, qn, sig, un, ypn, yp1 \n\n ALLOCATE ( u (n) )\n IF (yp1 > .99E30) THEN\n y2(1)=0.\n u(1)=0.\n ELSE\n y2(1)=-0.5\n u(1)=(3./(x(2)-x(1)))*((y(2)-y(1))/(x(2)-x(1))-yp1)\n ENDIF\n DO i=2,n-1\n sig=(x(i)-x(i-1))/(x(i+1)-x(i-1))\n p=sig*y2(i-1)+2.\n y2(i)=(sig-1.)/p\n u(i)=(6.*((y(i+1)-y(i))/(x(i+1)-x(i))-(y(i)-y(i-1)) &\n /(x(i)-x(i-1)))/(x(i+1)-x(i-1))-sig*u(i-1))/p\n ENDDO\n IF (ypn > .99E30) THEN\n qn=0.\n un=0.\n ELSE\n qn=0.5\n un=(3./(x(n)-x(n-1)))*(ypn-(y(n)-y(n-1))/(x(n)-x(n-1)))\n ENDIF\n y2(n)=(un-qn*u(n-1))/(qn*y2(n-1)+1.)\n DO k=n-1,1,-1\n y2(k)=y2(k)*y2(k+1)+u(k)\n ENDDO\n DEALLOCATE ( u )\n\n END SUBROUTINE spline\n\n\n ! takes xa[1,..,n] and y[1,..,n] which tabulates a function \n ! (with the xa[i]'s in order) and given ya[0,..,n - 1], \n ! which is the output from function spline() and with \n ! given value of x returns a cubic--spline interpolation value y.\n\n SUBROUTINE splint(xa,ya,y2a,n,x,y)\n IMPLICIT NONE\n INTEGER :: k, n, klo, khi\n REAL(DP), DIMENSION(n) :: xa, ya, y2a\n REAL(DP) :: x, y, h, b, a\n\n klo=1\n khi=n\n DO WHILE (khi-klo > 1)\n k=(khi+klo)/2\n IF(xa(k) > x)THEN\n khi=k\n ELSE\n klo=k\n ENDIF\n ENDDO\n h=xa(khi)-xa(klo)\n IF (h == 0.) WRITE (6,*) 'Bad XA input in SPLINT.F.'\n a=(xa(khi)-x)/h\n b=(x-xa(klo))/h\n y=a*ya(klo)+b*ya(khi)+ &\n ((a**3-a)*y2a(klo)+(b**3-b)*y2a(khi))*(h**2)/6.\n\n END SUBROUTINE splint\n\n\n ! This routine calculates gauss-legendre mesh points and weights\n ! input: \n ! x1 : lower limit of the integration interval\n ! x2 : upper limit ---------- \"\" -------------\n ! n : the desired number of mesh points\n ! output :\n ! x : gauss-legendre mesh points on the interval (x1,x2) \n ! w : the corresponding weights\n\n SUBROUTINE gauleg(x1,x2,x,w,n)\n IMPLICIT NONE\n INTEGER :: i, j, m, n\n REAL(DP) :: eps, x1, x2, x, w \n DIMENSION :: x(n), w(n) \n PARAMETER (eps=3.D-14)\n REAL(DP) :: p1,p2,p3,pp,xl,xm,z,z1\n\n m=(n+1)/2\n xm=0.5d0*(x2+x1)\n xl=0.5d0*(x2-x1)\n DO i=1,m\n z1=0.\n z=COS(3.141592654d0*(i-.25d0)/(n+.5d0))\n DO WHILE ( ABS(z-z1) > EPS)\n p1=1.\n p2=0.\n DO j=1,n\n p3=p2\n p2=p1\n p1=((2.*j-1.)*z*p2-(j-1.)*p3)/j\n ENDDO\n pp=n*(z*p1-p2)/(z*z-1.)\n z1=z\n z=z-p1/pp\n ENDDO\n x(i)=xm-xl*z\n x(n+1-i)=xm+xl*z\n w(i)=2.*xl/((1.-z*z)*pp*pp)\n w(n+1-i)=w(i)\n ENDDO\n\n END SUBROUTINE gauleg\n\n ! Function to integrate a function func over the \n ! interval [a,b] with input a, b, and the number of steps\n ! n. It returns the sum as the variable trapez_sum\n ! The trapezoidal rule is used\n\n\n SUBROUTINE trapezoidal_rule(a,b,trapez_sum,n,func)\n INTEGER, INTENT(IN) :: n\n REAL(DP), INTENT(IN) :: a,b\n REAL(DP), INTENT(INOUT) :: trapez_sum\n REAL(DP) fa, fb, x, step\n INTEGER :: j\n INTERFACE\n DOUBLE PRECISION FUNCTION func(x)\n IMPLICIT NONE\n DOUBLE PRECISION, INTENT(IN) :: x \n\n END FUNCTION func\n END INTERFACE\n\n\n step=(b-a)/FLOAT(n)\n fa=func(a)/2. ; fb=func(b)/2. ; trapez_sum=0.\n DO j=1,n-1\n x=j*step+a\n trapez_sum=trapez_sum+func(x)\n ENDDO\n trapez_sum=(trapez_sum+fb+fa)*step\n\n END SUBROUTINE trapezoidal_rule\n\n\n ! Function to integrate a function func over the \n ! interval [a,b] with input a, b, and the number of steps\n ! n. It returns the sum as the variable simpson_sum\n ! Simpson's method is used\n\n\n SUBROUTINE simpson(a,b,simpson_sum,n,func)\n REAL(DP), INTENT(IN) :: a,b\n REAL(DP), INTENT(INOUT) :: simpson_sum\n REAL(DP) fa, fb, x, step, fac\n INTEGER, INTENT(IN) :: n \n INTEGER :: j\n\n INTERFACE\n DOUBLE PRECISION FUNCTION func(x)\n IMPLICIT NONE\n DOUBLE PRECISION, INTENT(IN) :: x \n\n END FUNCTION func\n END INTERFACE\n\n step=(b-a)/FLOAT(n)\n fa=func(a) ; fb=func(b) ; simpson_sum=fa ; fac=2.\n DO j=1,n-1\n IF ( fac == 2.) THEN\n fac = 4.\n ELSE\n fac = 2.\n ENDIF\n x=j*step+a\n simpson_sum=simpson_sum+func(x)*fac\n ENDDO\n simpson_sum=(simpson_sum+fb)*step/3.\n\n END SUBROUTINE simpson\n\n !\n ! 4th-Runge-Kutta solution of coupled equations \n !\n SUBROUTINE rk4(x,y,yout,dydx,step,n)\n IMPLICIT NONE\n INTEGER :: n\n REAL(DP), DIMENSION(n) :: yt, dyt, dym\n REAL(DP), DIMENSION(n), INTENT(IN) :: y, dydx\n REAL(DP), DIMENSION(n), INTENT(OUT) :: yout\n REAL(DP) :: hh, h6, xh, step\n REAL(DP), INTENT(IN) :: x \n\n hh=step*0.5; h6=step/6. ; xh=x+hh\n ! first rk-step\n yt=y+hh*dydx\n ! CALL derivs(xh,yt,dyt)\n ! second rk-step\n yt=y+hh*dyt\n ! CALL derivs(xh,yt,dym) \n ! third rk-step\n yt=y+step*dym; dym=dyt+dym\n ! CALL derivs(x+step,yt,dyt)\n ! fourth rk-step\n yout=y+h6*(dydx+dyt+2.*dym)\n\n END SUBROUTINE rk4\n\n\n ! This function sets up the recursive relation\n ! for the associated Legendre polynomials\n\n REAL(DP) FUNCTION legendre_polynomials(l, m, x)\n IMPLICIT NONE\n REAL(DP) :: fact,pll,pmm,pmmp1,somx2\n REAL(DP), INTENT(IN) :: x\n INTEGER :: i,ll\n INTEGER, INTENT(IN) :: l, m\n\n ! check whether m, l and x are ok\n\n IF((M < 0).OR.(M > L).OR.(ABS(X) > 1.)) THEN\n WRITE(6,*) 'bad arguments', m, l, x; RETURN\n ENDIF\n\n ! calculate now pmm as starting point for iterations\n\n pmm=1.0\n IF (m > 0) THEN\n somx2=SQRT((1.0-x)*(1.0+x))\n fact=1.0;\n DO i=1, m\n pmm = -fact*somx2*pmm\n fact = fact+2.0\n ENDDO\n ENDIF\n\n ! if l == m we do not need to use recursion relation\n\n IF (l == m) THEN\n legendre_polynomials=pmm\n\n ! recursive relation for associated Legendre polynomials\n\n ELSE\n pmmp1=x*(2*m+1)*pmm\n\n ! analytical formula for the case l == m+1\n\n IF (l == (m+1)) THEN\n legendre_polynomials=pmmp1\n ELSE \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 ENDDO\n legendre_polynomials= pll\n ENDIF\n ENDIF\n\n END FUNCTION legendre_polynomials\n\n ! \n ! This function uses Newton-Raphson's \n ! method to find the root of a function\n ! known to lie between x1 and x2. The root is returned as rtnewt\n ! and is refined till its accuracy is xacc. You need to provide\n ! this value when calling the function.\n ! You must also provide an external function called funcd which\n ! calculates both the function f and its derivative df.\n !\n REAL(DP) FUNCTION rtnewt(funcd,x1,x2,xacc)\n IMPLICIT NONE\n INTEGER :: jmax, j\n REAL(DP) :: x1,x2,xacc\n PARAMETER (jmax=20)\n REAL(DP) :: df,dx,f\n INTERFACE\n SUBROUTINE funcd(x,y,z)\n IMPLICIT NONE\n DOUBLE PRECISION :: x, y, z \n\n END SUBROUTINE funcd\n END INTERFACE\n\n\n rtnewt=.5*(x1+x2)\n DO j=1,jmax\n CALL funcd(rtnewt,f,df)\n dx=f/df\n rtnewt=rtnewt-dx\n IF ((x1-rtnewt)*(rtnewt-x2) < 0.) THEN\n WRITE(6,*) 'Error in rtnewt, jumped out of brackets'\n STOP\n ENDIF\n IF (ABS (dx) < xacc) RETURN\n ENDDO\n\n END FUNCTION rtnewt\n\n ! \n ! This function uses the bisection method to find the \n ! root of a function\n ! known to lie between x1 and x2. The root is returned as rtbis\n ! and is refined till its accuracy is xacc. \n ! You must provide an external function called func.\n !\n REAL(DP) FUNCTION rtbis(func,x1,x2,xacc)\n IMPLICIT NONE\n INTEGER :: jmax, j\n REAL(DP) :: x1,x2,xacc\n PARAMETER (jmax=40)\n REAL(DP) :: dx,f,fmid,xmid\n\n INTERFACE\n DOUBLE PRECISION FUNCTION func(x)\n IMPLICIT NONE\n DOUBLE PRECISION, INTENT(IN) :: x\n\n END FUNCTION func\n END INTERFACE\n\n fmid=func(x2)\n f=func(x1)\n IF(f*fmid >= 0.) STOP 'root must be bracketed in rtbis'\n IF (f < 0.) THEN\n rtbis=x1\n dx=x2-x1\n ELSE\n rtbis=x2\n dx=x1-x2\n ENDIF\n DO j=1,jmax\n dx=dx*.5\n xmid=rtbis+dx\n fmid=func(xmid)\n IF (fmid <= 0.) rtbis=xmid\n IF (ABS(dx) < xacc .or. fmid == 0.) RETURN\n ENDDO\n\n END FUNCTION rtbis\n ! \n ! This function uses the secant method \n ! to find the root of a function\n ! known to lie between x1 and x2. The root is returned as rtsec\n ! and is refined till its accuracy is xacc\n ! You must provide an external function called func.\n !\n REAL(DP) FUNCTION rtsec(func,x1,x2,xacc)\n IMPLICIT NONE\n INTEGER :: maxit, j\n real(DP) :: x1,x2,xacc\n PARAMETER (maxit=30)\n REAL(DP) :: dx,f,fl,swap,xl\n INTERFACE\n DOUBLE PRECISION FUNCTION func(x)\n IMPLICIT NONE\n DOUBLE PRECISION, INTENT(IN) :: x\n\n END FUNCTION func\n END INTERFACE\n\n\n fl=func(x1)\n f=func(x2)\n IF(ABS(fl) < ABS(f)) THEN\n rtsec=x1\n xl=x2\n swap=fl\n fl=f\n f=swap\n ELSE\n xl=x1\n rtsec=x2\n ENDIF\n DO j=1,maxit\n dx=(xl-rtsec)*f/(f-fl)\n xl=rtsec\n fl=f\n rtsec=rtsec+dx\n f=func(rtsec)\n IF((ABS(dx) < xacc).or.(f == 0.)) RETURN\n ENDDO\n\n END FUNCTION rtsec\n\n\n ! \n ! This function uses Brent's method to find the root of a function\n ! known to lie between x1 and x2. The root is returned as zbrent\n ! and is refined till its accuracy is tol\n ! You must provide an external function called func.\n !\n REAL(DP) FUNCTION zbrent(func,x1,x2,tol)\n IMPLICIT NONE\n REAL(DP) :: tol, x1, x2\n REAL(DP), PARAMETER :: EPS= epsilon(x1)\n INTEGER, PARAMETER :: ITMAX=100\n INTEGER :: iter\n REAL(DP) :: a,b,c,d,e,fa,fb,fc,p,q,r,s,tol1,xm\n INTERFACE\n DOUBLE PRECISION FUNCTION func(x)\n IMPLICIT NONE\n DOUBLE PRECISION, INTENT(IN) :: x\n\n END FUNCTION func\n END INTERFACE\n\n a=x1\n b=x2\n fa=func(a)\n fb=func(b)\n ! IF((fa > 0.0.AND.fb > 0.0).OR.(fa < 0.0.AND.fb < 0.0)) THEN\n ! WRITE(*,*) 'root must be bracketed for zbrent' ; STOP \n ! ENDIF\n c=b\n fc=fb\n DO iter=1,ITMAX\n IF ((fb > 0.0.AND.fc > 0.).OR.(fb < 0.0.AND.fc < 0.0))THEN\n c=a\n fc=fa\n d=b-a\n e=d\n ENDIF\n IF(ABS(fc) < ABS(fb)) THEN\n a=b\n b=c\n c=a\n fa=fb\n fb=fc\n fc=fa\n ENDIF\n tol1=2.*eps*ABS(b)+0.5*tol\n xm=.5*(c-b)\n IF((ABS(xm) <= tol1) .OR. (fb == 0.))THEN\n zbrent=b\n RETURN\n ENDIF\n IF((ABS(e) >= tol1) .AND.( ABS(fa) > ABS(fb)) ) THEN\n s=fb/fa\n IF(a == c) THEN\n p=2.*xm*s\n q=1.-s\n ELSE\n q=fa/fc\n r=fb/fc\n p=s*(2.*xm*q*(q-r)-(b-a)*(r-1.))\n q=(q-1.)*(r-1.)*(s-1.)\n ENDIF\n IF(p > 0.) q=-q\n p=ABS(p)\n IF(2.*p < MIN(3.*xm*q-ABS(tol1*q),ABS(e*q))) THEN\n e=d\n d=p/q\n ELSE\n d=xm\n e=d\n ENDIF\n ELSE\n d=xm\n e=d\n ENDIF\n a=b\n fa=fb\n b=b+MERGE(d,SIGN(tol1,xm), ABS(d) > tol1 )\n fb=func(b)\n ENDDO\n WRITE (*,*) 'zbrent exceeding maximum iterations'; STOP\n zbrent=b\n\n END FUNCTION zbrent\n\n !\n ! The function\n ! ran0()\n ! is an \"Minimal\" random number generator of Park and Miller\n ! (see Numerical recipe page 279). Set or reset the input value\n ! idum to any integer value (except the unlikely value MASK)\n ! to initialize the sequence; idum must not be altered between\n ! calls for sucessive deviates in a sequence.\n ! The function returns a uniform deviate between 0.0 and 1.0.\n !\n\n\n REAL(DP) FUNCTION ran0(idum)\n IMPLICIT NONE\n INTEGER :: idum,ia,im,iq,ir,mask,k\n REAL(DP) :: am\n PARAMETER (ia=16807,im=2147483647,am=1./im,iq=127773,ir=2836,mask=123459876)\n\n idum=ieor(idum,MASK)\n k=idum/IQ\n idum=IA*(idum-k*IQ)-IR*k\n IF (idum < 0) idum=idum+IM\n ran0=am*idum\n idum=ieor(idum,MASK)\n\n END FUNCTION ran0\n\n\n !\n ! The function\n ! ran1()\n ! is an \"Minimal\" random number generator of Park and Miller\n ! (see Numerical recipe page 280) with Bays-Durham shuffle and\n ! added safeguards. Call with idum a negative integer to initialize;\n ! thereafter, do not alter idum between sucessive deviates in a\n ! sequence. RNMX should approximate the largest floating point value\n ! that is less than 1.\n ! The function returns a uniform deviate between 0.0 and 1.0\n ! (exclusive of end-point values).\n !\n\n\n\n REAL(DP) FUNCTION ran1(idum)\n IMPLICIT NONE\n INTEGER :: idum,ia,im,iq,ir,ntab,ndiv\n REAL(DP) :: am,eps,rnmx\n PARAMETER (ia=16807,im=2147483647,am=1./im,iq=127773,ir=2836, &\n ntab=32,ndiv=1+(im-1)/ntab,eps=1.2e-7,rnmx=1.-eps)\n INTEGER :: j,k,iv(ntab),iy\n SAVE iv,iy\n DATA iv /NTAB*0/, iy /0/\n\n IF ((idum == 0).OR.(iy==0)) THEN\n idum=MAX(-idum,1)\n DO j=ntab+8,1,-1\n k=idum/iq\n idum=ia*(idum-k*iq)-ir*k\n IF (idum < 0) idum=idum+im\n IF (j <= ntab) iv(j)=idum\n ENDDO\n iy=iv(1)\n ENDIF\n k=idum/IQ\n idum=ia*(idum-k*iq)-ir*k\n if (idum < 0) idum=idum+IM\n j=1+iy/ndiv\n iy=iv(j)\n iv(j)=idum\n ran1=MIN(am*iy,rnmx)\n\n END FUNCTION ran1\n\n\n REAL(DP) FUNCTION ran(idum)\n IMPLICIT NONE\n INTEGER, PARAMETER :: K4B=selected_int_kind(9)\n INTEGER(K4B), INTENT(INOUT) :: idum \n INTEGER :: ia,im,iq,ir\n REAL(DP), SAVE :: am\n PARAMETER (ia=16807,im=2147483647,iq=127773,ir=2836)\n INTEGER(K4B), SAVE :: ix=-1, iy=-1, k \n\n IF ((idum <= 0).OR.(iy < 0)) THEN\n am=NEAREST(1.,-1.)/im\n iy=IOR(IEOR(888889999,ABS(idum)),1)\n ix=IEOR(777755555,ABS(idum))\n idum=ABS(idum)+1\n ENDIF\n ix=IEOR(ix,ISHFT(ix,13))\n ix=IEOR(ix,ISHFT(ix,-17))\n ix=IEOR(ix,ISHFT(ix,5)) \n k=iy/iq\n iy=ia*(iy-k*iq)-ir*k\n IF ( iy < 0 ) iy=iy+im\n ran=am*IOR(IAND(im,IEOR(ix,iy)),1)\n\n END FUNCTION ran\n\n !\n ! The function \n ! ran2\n ! is a long periode (> 2 x 10^18) random number generator of \n ! L'Ecuyer and Bays-Durham shuffle and added safeguards.\n ! Call with idum a negative integer to initialize; thereafter,\n ! do not alter idum between sucessive deviates in a\n ! sequence. RNMX should approximate the largest floating point value\n ! that is less than 1.\n ! The function returns a uniform deviate between 0.0 and 1.0\n ! (exclusive of end-point values).\n !\n\n REAL(DP) FUNCTION ran2(idum)\n IMPLICIT NONE\n INTEGER :: idum,im1,im2,imm1,ia1,ia2,iq1,iq2,ir1,ir2,ntab,ndiv\n REAL(DP) :: am,eps,rnmx\n PARAMETER (im1=2147483563,im2=2147483399,am=1./im1,imm1=im1-1, &\n ia1=40014,ia2=40692,iq1=53668,iq2=52774,ir1=12211,ir2=3791, &\n ntab=32,ndiv=1+imm1/ntab,eps=1.2e-7,rnmx=1.-eps)\n INTEGER :: idum2,j,k,iv(NTAB),iy\n SAVE iv,iy,idum2\n DATA idum2/123456789/, iv/NTAB*0/, iy/0/\n IF (idum <= 0) then\n idum=MAX(-idum,1)\n idum2=idum\n DO j=NTAB+8,1,-1\n k=idum/IQ1\n idum=ia1*(idum-k*iq1)-k*ir1\n IF (idum < 0) idum=idum+IM1\n IF (J <= NTAB) IV(J)=IDUM\n ENDDO\n IY=IV(1)\n ENDIF\n k=idum/iq1\n idum=ia1*(idum-k*iq1)-k*ir1\n if (idum < 0) idum=idum+im1\n k=idum2/iq2\n idum2=ia2*(idum2-k*iq2)-k*ir2\n IF (idum2 < 0) idum2=idum2+im2\n j=1+iy/ndiv\n iy=iv(j)-idum2\n iv(j)=idum\n IF (iy < 1)iy=iy+imm1\n ran2=MIN(am*iy,rnmx)\n\n END FUNCTION ran2\n\n\n !\n ! The function\n ! ran3\n ! returns a uniform random number deviate between 0.0 and 1.0. Set\n ! the idum to any negative value to initialize or reinitialize the\n ! sequence. Any large MBIG, and any small (but still large) MSEED\n ! can be substituted for the present values. \n !\n\n REAL(DP) FUNCTION ran3(idum)\n IMPLICIT NONE\n INTEGER :: idum\n INTEGER :: mbig,mseed,mz\n REAL(DP) :: fac\n PARAMETER (mbig=1000000000,mseed=161803398,mz=0,fac=1./mbig)\n INTEGER :: i,iff,ii,inext,inextp,k\n INTEGER :: mj,mk,ma(55)\n SAVE iff,inext,inextp,ma\n DATA iff /0/\n\n IF ( (idum < 0) .or. (iff == 0) ) THEN\n iff=1\n mj=mseed-IABS(idum)\n mj=MOD(mj,mbig)\n ma(55)=mj\n mk=1\n DO i=1,54\n ii=MOD(21*i,55)\n ma(ii)=mk\n mk=mj-mk\n IF(mk < mz)mk=mk+mbig\n mj=ma(ii)\n ENDDO\n DO k=1,4\n DO i=1,55\n ma(i)=ma(i)-ma(1+MOD(i+30,55))\n IF (ma(i) < mz)ma(i)=ma(i)+mbig\n ENDDO\n ENDDO\n inext=0\n inextp=31\n idum=1\n ENDIF\n inext=inext+1\n IF (inext == 56) inext=1\n inextp=inextp+1\n IF (inextp == 56) inextp=1\n mj=ma(inext)-ma(inextp)\n IF (mj < mz) mj=mj+mbig\n ma(inext)=mj\n ran3=mj*fac\n\n END FUNCTION ran3\n\nEND MODULE F90library\n\n\n\n\n\n\n", "meta": {"hexsha": "0d8e327132b169227bb84e69f00cea6b3e425361", "size": 28754, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "doc/pub/vmc/programs/F2008/f90lib.f90", "max_stars_repo_name": "GabrielSCabrera/ComputationalPhysics2", "max_stars_repo_head_hexsha": "a840b97b651085090f99bf6a11abab57100c2e85", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 87, "max_stars_repo_stars_event_min_datetime": "2015-01-21T08:29:56.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T07:11:53.000Z", "max_issues_repo_path": "doc/pub/vmc/programs/F2008/f90lib.f90", "max_issues_repo_name": "GabrielSCabrera/ComputationalPhysics2", "max_issues_repo_head_hexsha": "a840b97b651085090f99bf6a11abab57100c2e85", "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/pub/vmc/programs/F2008/f90lib.f90", "max_forks_repo_name": "GabrielSCabrera/ComputationalPhysics2", "max_forks_repo_head_hexsha": "a840b97b651085090f99bf6a11abab57100c2e85", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 54, "max_forks_repo_forks_event_min_datetime": "2015-02-09T10:02:00.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-07T10:44:14.000Z", "avg_line_length": 26.14, "max_line_length": 85, "alphanum_fraction": 0.5207275509, "num_tokens": 10024, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951104066293, "lm_q2_score": 0.8128673269042767, "lm_q1q2_score": 0.6859747625838262}} {"text": "program normalize_performance\n use, intrinsic :: iso_fortran_env, only : error_unit, DP => REAL64\n implicit none\n integer :: matrix_size\n real(kind=DP), dimension(:, :), allocatable :: matrix\n real(kind=DP) :: row_norm\n integer :: row, col, istat\n real :: start_time, end_time\n\n call get_arguments(matrix_size)\n allocate (matrix(matrix_size, matrix_size), stat=istat)\n\n ! reinitialize the matrix to avoid cache effects\n call random_number(matrix)\n call cpu_time(start_time)\n do row = 1, size(matrix, 1)\n matrix(row, :) = matrix(row, :)/sum(matrix(row, :))\n end do\n call cpu_time(end_time)\n print '(A, F10.6)', 'row-wise norm: ', end_time - start_time\n if (.not. is_normed(matrix, abs_tol=1e-4_DP)) then\n write (unit=error_unit, fmt='(A)') 'error: array is not normalized (row-wise)'\n end if\n\n ! reinitialize the matrix to avoid cache effects\n call random_number(matrix)\n call cpu_time(start_time)\n do concurrent (row = 1:size(matrix, 1))\n row_norm = 1.0_DP/sum(matrix(row, :))\n do concurrent (col = 1:size(matrix, 2))\n matrix(row, col) = matrix(row, col)*row_norm\n end do\n end do\n call cpu_time(end_time)\n print '(A, F10.6)', 'do concurrent row-wise norm: ', end_time - start_time\n if (.not. is_normed(matrix, abs_tol=1e-4_DP)) then\n write (unit=error_unit, fmt='(A)') 'error: array is not normalized (row-wise)'\n end if\n\n\n\n ! initialize the matrix\n call random_number(matrix)\n call cpu_time(start_time)\n matrix = matrix/spread(sum(matrix, dim=2), 2, size(matrix, 2))\n call cpu_time(end_time)\n print '(A, F10.6)', 'norm using spread: ', end_time - start_time\n if (.not. is_normed(matrix, abs_tol=1e-4_DP)) then\n write (unit=error_unit, fmt='(A)') 'error: array is not normalized (spread)'\n end if\n\n deallocate (matrix)\n\ncontains\n\n subroutine get_arguments(matrix_size)\n implicit none\n integer, intent(out) :: matrix_size\n character(len=1024) :: buffer, msg\n integer :: istat\n\n if (command_argument_count() /= 1) then\n write (unit=error_unit, fmt='(A)') 'error: expect matrix size as argument'\n stop 1\n end if\n call get_command_argument(1, buffer)\n read (buffer, fmt=*, iostat=istat, iomsg=msg) matrix_size\n if (istat /= 0) then\n write (unit=error_unit, fmt='(2A)') 'error: ', trim(msg)\n stop 2\n end if\n end subroutine get_arguments\n\n function is_normed(matrix, abs_tol) result(is_okay)\n implicit none\n real(kind=DP), dimension(:, :), intent(in) :: matrix\n real(kind=DP), value :: abs_tol\n logical :: is_okay\n \n is_okay = all(sum(matrix, dim=2) - 1.0_DP < abs_tol)\n end function is_normed\n\nend program normalize_performance\n", "meta": {"hexsha": "e42cbeacdaa071d14248e2d3170208c48b9020bd", "size": 2859, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source_code/arrays/normalize_performance.f90", "max_stars_repo_name": "caguerra/Fortran-MOOC", "max_stars_repo_head_hexsha": "fb8a9c24e62ce5f388deb06b21e3009aea6b78d4", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2021-05-20T12:03:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-16T19:46:26.000Z", "max_issues_repo_path": "source_code/arrays/normalize_performance.f90", "max_issues_repo_name": "caguerra/Fortran-MOOC", "max_issues_repo_head_hexsha": "fb8a9c24e62ce5f388deb06b21e3009aea6b78d4", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-09-30T04:25:50.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-06T08:21:30.000Z", "max_forks_repo_path": "source_code/arrays/normalize_performance.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": 34.0357142857, "max_line_length": 86, "alphanum_fraction": 0.6302903113, "num_tokens": 790, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951104066293, "lm_q2_score": 0.8128673246376009, "lm_q1q2_score": 0.6859747606709896}} {"text": "\nsubmodule(forlab_linalg) forlab_linalg_chol\n\n implicit none\n\ncontains\n\n module procedure chol_sp\n\n integer :: i, j, k, n\n real(sp) :: sum1, sum2\n real(sp), dimension(:), allocatable :: d\n real(sp), dimension(:, :), allocatable :: V\n real(sp), parameter::zero = 0.0_sp, one = 1.0_sp\n call eig(A, V, d)\n deallocate (V)\n if (all(d >= zero)) then\n n = size(A, 1)\n L = zeros(n, n)\n L(1, 1) = sqrt(A(1, 1))\n do i = 2, n\n L(i, 1) = A(i, 1)/L(1, 1)\n end do\n do i = 2, n\n do k = 1, i\n sum1 = zero\n sum2 = zero\n do j = 1, k - 1\n if (i == k) then\n sum1 = sum1 + (L(k, j)*L(k, j))\n L(k, k) = sqrt(A(k, k) - sum1)\n elseif (i .gt. k) then\n sum2 = sum2 + (L(i, j)*L(k, j))\n L(i, k) = (one/L(k, k))*(A(i, k) - sum2)\n else\n L(i, k) = zero\n end if\n end do\n end do\n end do\n else\n error stop \"Error: in chol(A), A should be positive definite.\"\n end if\n deallocate (d)\n end procedure chol_sp\n module procedure chol_dp\n\n integer :: i, j, k, n\n real(dp) :: sum1, sum2\n real(dp), dimension(:), allocatable :: d\n real(dp), dimension(:, :), allocatable :: V\n real(dp), parameter::zero = 0.0_dp, one = 1.0_dp\n call eig(A, V, d)\n deallocate (V)\n if (all(d >= zero)) then\n n = size(A, 1)\n L = zeros(n, n)\n L(1, 1) = sqrt(A(1, 1))\n do i = 2, n\n L(i, 1) = A(i, 1)/L(1, 1)\n end do\n do i = 2, n\n do k = 1, i\n sum1 = zero\n sum2 = zero\n do j = 1, k - 1\n if (i == k) then\n sum1 = sum1 + (L(k, j)*L(k, j))\n L(k, k) = sqrt(A(k, k) - sum1)\n elseif (i .gt. k) then\n sum2 = sum2 + (L(i, j)*L(k, j))\n L(i, k) = (one/L(k, k))*(A(i, k) - sum2)\n else\n L(i, k) = zero\n end if\n end do\n end do\n end do\n else\n error stop \"Error: in chol(A), A should be positive definite.\"\n end if\n deallocate (d)\n end procedure chol_dp\n\nend submodule forlab_linalg_chol\n\n", "meta": {"hexsha": "0b44900a499a9ace6afad46ad457368c564be391", "size": 2468, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/forlab_linalg_chol.f90", "max_stars_repo_name": "zoziha/forlab_z", "max_stars_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2021-08-31T15:23:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T02:44:46.000Z", "max_issues_repo_path": "src/forlab_linalg_chol.f90", "max_issues_repo_name": "zoziha/forlab_z", "max_issues_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-08-22T11:47:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-31T00:57:16.000Z", "max_forks_repo_path": "src/forlab_linalg_chol.f90", "max_forks_repo_name": "zoziha/forlab_z", "max_forks_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-07-16T03:16:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-31T13:09:42.000Z", "avg_line_length": 28.367816092, "max_line_length": 70, "alphanum_fraction": 0.3930307942, "num_tokens": 768, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972818382005, "lm_q2_score": 0.7879312056025699, "lm_q1q2_score": 0.6859707658730937}} {"text": "program test_gamma\n\n use gamma_module\n\n implicit none\n integer, parameter :: n_a = 5\n integer, parameter :: n_x = 9\n integer :: i, j, k\n real(dp) :: a(n_a), x(n_x), gamma_mathematica(n_a*n_x)\n\n a = (/ 1.0_dp, 2.0_dp, 3.0_dp, 4.0_dp, 5.0_dp /)\n x = (/ 0.0_dp, 1.0_dp, 2.0_dp, 3.0_dp, 4.0_dp, 5.0_dp, 6.0_dp, 7.0_dp, 8.0_dp /)\n gamma_mathematica = (/ &\n 1.00000000000000e0_dp, &\n 3.67879441171442e-1_dp, &\n 1.35335283236613e-1_dp, &\n 4.9787068367864e-2_dp, &\n 1.83156388887342e-2_dp, &\n 6.73794699908547e-3_dp, &\n 2.47875217666636e-3_dp, &\n 9.11881965554516e-4_dp, &\n 3.35462627902512e-4_dp, &\n 1.00000000000000e0_dp, &\n 7.35758882342885e-1_dp, &\n 4.06005849709838e-1_dp, &\n 1.99148273471456e-1_dp, &\n 9.15781944436709e-2_dp, &\n 4.04276819945128e-2_dp, &\n 1.73512652366645e-2_dp, &\n 7.29505572443613e-3_dp, &\n 3.01916365112261e-3_dp, &\n 2.00000000000000e0_dp, &\n 1.83939720585721e0_dp, &\n 1.35335283236613e0_dp, &\n 8.46380162253687e-1_dp, &\n 4.76206611107089e-1_dp, &\n 2.49304038966162e-1_dp, &\n 1.23937608833318e-1_dp, &\n 5.92723277610436e-2_dp, &\n 2.7507935488006e-2_dp, &\n 6.0000000000000e0_dp, &\n 5.88607105874308e0_dp, &\n 5.14274076299128e0_dp, &\n 3.88339133269339e0_dp, &\n 2.60082072220025e0_dp, &\n 1.59015549178417e0_dp, &\n 9.07223296659887e-1_dp, &\n 4.9059249746833e-1_dp, &\n 2.54280671950104e-1_dp, &\n 2.40000000000000e1_dp, &\n 2.39121636761438e1_dp, &\n 2.27363275837509e1_dp, &\n 1.95663178685705e1_dp, &\n 1.5092086444317e1_dp, &\n 1.05718388415651e1_dp, &\n 6.84135600759915e0_dp, &\n 4.15179858916971e0_dp, &\n 2.39117761168911e0_dp/)\n\n !print*,'TESTING GAMMA FUNCTION - GFORTRAN ONLY'\n !do i = 1, n_a\n ! print*, a(i), exp(ln_gamma(a(i))), gamma(a(i)), abs(exp(ln_gamma(a(i)))-gamma(a(i)))\n !enddo\n\n print*,'TESTING INCOMPLETE GAMMA FUNCTION - Mathematica results'\n print'(2a10,2a25,a14)','a','x','Gamma(a,x) Mathematica','Gamma(a,x) Current','Delta'\n k = 0\n do i = 1, n_a\n do j = 1, n_x\n k = k + 1\n print'(2f10.6,2e25.15,e14.5)',a(i),x(j),gamma_mathematica(k),gamma_incomplete_upper(a(i),x(j)), &\n abs(gamma_mathematica(k)-gamma_incomplete_upper(a(i),x(j)))\n enddo\n enddo\n\nendprogram test_gamma\n", "meta": {"hexsha": "7d8869a893dcc54dbc558362fbee443b203d750a", "size": 2266, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/libAtoms/test_gamma.f95", "max_stars_repo_name": "albapa/QUIP", "max_stars_repo_head_hexsha": "ecde1e332c6bd62c238d3cd90e31dba4fb390313", "max_stars_repo_licenses": ["NRL"], "max_stars_count": 229, "max_stars_repo_stars_event_min_datetime": "2015-01-20T16:35:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T10:44:32.000Z", "max_issues_repo_path": "src/libAtoms/test_gamma.f95", "max_issues_repo_name": "albapa/QUIP", "max_issues_repo_head_hexsha": "ecde1e332c6bd62c238d3cd90e31dba4fb390313", "max_issues_repo_licenses": ["NRL"], "max_issues_count": 356, "max_issues_repo_issues_event_min_datetime": "2015-05-29T08:28:59.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T22:55:34.000Z", "max_forks_repo_path": "src/libAtoms/test_gamma.f95", "max_forks_repo_name": "albapa/QUIP", "max_forks_repo_head_hexsha": "ecde1e332c6bd62c238d3cd90e31dba4fb390313", "max_forks_repo_licenses": ["NRL"], "max_forks_count": 106, "max_forks_repo_forks_event_min_datetime": "2015-01-21T12:56:29.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-25T08:39:24.000Z", "avg_line_length": 29.4285714286, "max_line_length": 106, "alphanum_fraction": 0.6557811121, "num_tokens": 1041, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972784807406, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.6859707502213468}} {"text": "program prl2\r\n use forSVG\r\n use GaussElimination\r\n use Utilities\r\n implicit none\r\n\r\n real(8) :: AR,b,S\r\n real(8),allocatable :: spanY(:), chordY(:), twistY(:)\r\n real(8),allocatable :: spanTh(:), chordTh(:), twistTh(:)\r\n real(8),allocatable :: Gamm(:), dGamm(:), Cl(:), yPlot(:)\r\n integer :: N, Nplot, Nsol\r\n integer :: i,j\r\n real(8) :: v\r\n real(8),allocatable :: a(:,:), r(:), An(:)\r\n\r\n real(8) :: CanvasLowerLeft(2),CanvasUpperRight(2)\r\n integer :: Resolution\r\n\r\n real(8),parameter :: Cla = 2.0d0*3.141592\r\n real(8) :: theta, yloc, chord, twist\r\n real(8) :: alfa\r\n character(len=80) :: text,filename\r\n\r\n write(*,*) \"Prandtl Lifting Line v3 11/11/16\"\r\n b = 2.0d0 ! span from -1 to 1\r\n\r\n ! SVG\r\n CanvasLowerLeft = [-2,-2]\r\n CanvasUpperRight = [2,2]\r\n Resolution = 1000\r\n call svgOpen(\"Geo\", CanvasLowerLeft,CanvasUpperRight, Resolution)\r\n call svgHeader()\r\n\r\n Nplot = 400\r\n allocate(Gamm(Nplot))\r\n allocate(dGamm(Nplot))\r\n allocate(Cl(Nplot))\r\n allocate(yPlot(Nplot))\r\n\r\n ! geometery\r\n write(*,*) \"Geometry Filename\"\r\n read*, filename\r\n open(unit=101,file=trim(filename),status=\"old\")\r\n\r\n read(101,*) ! Header Line\r\n read(101,*) ! Comment Line\r\n read(101,*) N\r\n\r\n allocate(spanY(N))\r\n allocate(chordY(N))\r\n allocate(twistY(N))\r\n\r\n read(101,*) ! Comment Line\r\n do i=1,N\r\n read(101,*) spanY(i), chordY(i), twistY(i)\r\n twistY(i) = twistY(i)*3.1415926/180.0d0\r\n enddo\r\n\r\n do i=1,N-1\r\n call svgQuadColor([spanY(i),0.25*chordY(i)],&\r\n [spanY(i+1),0.25*chordY(i+1)],&\r\n [spanY(i+1),-0.75*chordY(i+1)],&\r\n [spanY(i),-0.75*chordY(i)],[150,150,150],1.0d0)\r\n call svgLine([spanY(i),-twistY(i)],[spanY(i+1),-twistY(i+1)],[0,0,0])\r\n enddo\r\n do i=-10,10,2\r\n call svgLine([1.0d0,i/57.30d0],[1.1d0,i/57.3d0],[0,0,0])\r\n call svgText([1.2d0,i/57.3d0],0.03d0,-i*1.0d0)\r\n enddo\r\n do i=1,N\r\n call svgLine([spanY(i),0.25*chordY(i)],[spanY(i),-0.75*chordY(i)],[255,255,255])\r\n enddo\r\n\r\n ! COmpute geometry\r\n S = 0\r\n do i=1,N-1\r\n S = S + 0.5*(chordY(i)+chordY(i+1))*(spanY(i+1)-spanY(i))\r\n enddo\r\n AR = b*b/S\r\n write(*,*) \"Area = \", S, \"AR =\", AR\r\n\r\n ! Solution\r\n Nsol = 50\r\n allocate( a(Nsol,Nsol))\r\n allocate( r(Nsol))\r\n allocate( An(Nsol))\r\n\r\n ! Polar FIle\r\n open(unit=109,file=\"polar.txt\",status='unknown')\r\n write(109,*) \"Area = \", S, \"AR =\", AR\r\n write(109,*) \"CL CD\"\r\n \r\n do while(.true.)\r\n write(*,*) \"Alpha [deg]\"\r\n read*, alfa\r\n if(alfa.eq.-999) exit\r\n alfa = alfa/57.3\r\n\r\n\r\n do i=1,Nsol\r\n theta = gettheta(i,Nsol)\r\n yloc = Th2Y(b/2.0d0,theta)\r\n chord = interpolate(spanY,chordY,yloc)\r\n twist = interpolate(spanY,twistY,yloc)\r\n do j=1,Nsol\r\n a(i,j) = aic(b,theta,chord,Cla,j)\r\n enddo\r\n r(i)=raic(alfa,b,theta,chord,twist,Cla,Nsol)\r\n enddo\r\n\r\n write(*,*) \"Solving....\"\r\n call GaussElim(a,r,An,Nsol)\r\n\r\n open(unit=301,file=\"Coeffs.txt\",status='unknown')\r\n write(301,'(f15.5)') An\r\n close(301)\r\n\r\n write(*,*) \"Values....\"\r\n write(*,*) \"CL = \", getCL(AR,An)\r\n write(*,*) \"CDi = \", getCD(AR,An)\r\n write(*,*) \"Delta = \", getDelta(AR,An)\r\n write(109,*) getCL(AR,An), getCD(AR,An)\r\n\r\n write(*,*) \"Plotting....\"\r\n\r\n\r\n do i=1,Nplot\r\n yloc = -1 + b*(i-1.0d0)/(Nplot-1.0d0)\r\n chord = interpolate(spanY,chordY,yloc)\r\n yPlot(i) = yloc\r\n Gamm(i) = GammaCirc(An,b,Nsol,yloc)\r\n dGamm(i) = dGammaCirc(An,b,Nsol,yloc)\r\n Cl(i) = 2*Gamm(i)/chord\r\n enddo\r\n\r\n write(*,*) \"SVG....\"\r\n\r\n ! Gamma\r\n do i=1,Nplot-1\r\n call svgQuadColor([yPlot(i),-0.0d0],&\r\n [yPlot(i+1),0.0d0],&\r\n [yPlot(i+1),Gamm(i+1)/maxval(Gamm)],&\r\n [yPlot(i),Gamm(i)/maxval(Gamm)],[0,255,0],0.1d0)\r\n call svgLine([yPlot(i),Gamm(i)/maxval(Gamm)],[yPlot(i+1),Gamm(i+1)/maxval(Gamm)],[0,255,0])\r\n enddo\r\n\r\n ! Cl Plotting\r\n do i=1,Nplot-1\r\n call svgLine([yPlot(i),Cl(i)],[yPlot(i+1),Cl(i+1)],[0,0,255])\r\n enddo\r\n text = \"Cl\"\r\n call svgTextT([-1.3d0,0.0d0],0.05d0,text)\r\n write(text,'( \"AOA=\", f5.1, \" CL=\", f6.3, \" CD= \", f6.3)') alfa*57.3, getCL(AR,An), getCD(AR,An)\r\n call svgTextT([0.0d0,Cl(Nplot/2)+0.02],0.05d0,text)\r\n do i=-10,20\r\n call svgLine([-1.0d0,i/10.0d0],[-1.1d0,i/10.0d0],[0,0,0])\r\n call svgText([-1.2d0,i/10.0d0],0.05d0,i/10.0d0)\r\n enddo\r\n\r\n open(unit=200,file=\"output.txt\",status='unknown')\r\n write(200,*) \"#### \", filename, alfa, \"CL \", getCL(AR,An), \"CD \", getCD(AR,An)\r\n do i=1,Nplot-1\r\n write(200,*) yPlot(i), Gamm(i), Cl(i)\r\n enddo\r\n\r\n\r\n ! ! Trailing Vortex Sheet\r\n ! do i=2,Nplot-2\r\n ! call svgLine([yPlot(i),(dGamm(i))/maxval(dGamm)],&\r\n ! [yPlot(i+1),(dGamm(i+1))/maxval(dGamm)],[255,0,0])\r\n ! !call svgQuadColor([yPlot(i),-0.2d0],&\r\n ! ! [yPlot(i+1),-0.2d0],&\r\n ! ! [yPlot(i+1),-2.0d0],&\r\n ! ! [yPlot(i),-2.0d0],[255,0,0],abs(dGamm(i))/maxval(dGamm))\r\n ! enddo\r\nenddo\r\n call svgFooter()\r\ncontains\r\n\r\n function getCL(AR,An)\r\n real(8) :: getCL, AR\r\n real(8),allocatable :: An(:)\r\n getCL = 3.14159*AR*An(1)\r\n end function\r\n\r\n function getCD(AR,An)\r\n real(8) :: getCD, AR\r\n real(8),allocatable :: An(:)\r\n integer :: n\r\n n = size(An)\r\n getCD = 0.0\r\n do i=1,n\r\n getCD= getCD + 3.14159*AR*i*An(i)**2\r\n enddo\r\n end function\r\n\r\n function getDelta(AR,An)\r\n real(8) :: getDelta, AR\r\n real(8),allocatable :: An(:)\r\n integer :: n\r\n n = size(An)\r\n getDelta = 0.0\r\n do i=2,n\r\n getDelta= getDelta + i*(An(i)/An(1))**2\r\n enddo\r\n end function\r\n \r\n function GammaCirc(An,b,n,y)\r\n implicit none\r\n real(8) :: b,y\r\n real(8),allocatable :: An(:)\r\n integer :: n, i\r\n real(8) :: GammaCirc\r\n GammaCirc = 0\r\n do i=1,n\r\n GammaCirc = GammaCirc + 2*b*An(i)*sin(i*acos(2*y/b))\r\n enddo\r\n end function\r\n\r\n function dGammaCirc(An,b,n,y)\r\n implicit none\r\n real(8) :: b,y\r\n real(8),allocatable :: An(:)\r\n integer :: n, i\r\n real(8) :: dGammaCirc\r\n real(8),parameter :: deltay = 0.0001\r\n dGammaCirc = -(GammaCirc(An,b,n,y+deltay)- GammaCirc(An,b,n,y-deltay))/deltay/2.0d0\r\n\r\n end function\r\n\r\n function gettheta(m,N)\r\n real(8) :: gettheta\r\n integer :: m,N\r\n gettheta = 3.1415926*m/(N+1.0d0)\r\n end function\r\n\r\n function aic(b,theta,chord,Cla,n)\r\n real(8) :: theta,chord,CLa,b\r\n integer :: n\r\n real(8) :: aic\r\n aic = sin(n*theta)+chord/4.0/b*Cla*n*sin(n*theta)/sin(theta)\r\n end function\r\n\r\n function raic(alfa,b,theta,chord,twist,Cla,n)\r\n real(8) :: theta,chord,CLa,twist,alfa,b\r\n integer :: n\r\n real(8) :: raic\r\n raic = chord/4.0/b*Cla*(alfa+twist)\r\n end function\r\n\r\n\r\n function Th2Y(halfspan,theta)\r\n real(8) :: Th2Y,theta,halfspan\r\n Th2Y = halfspan*cos(theta)\r\n end function\r\n\r\n function interpolate(x,y,x0)\r\n real(8) :: interpolate\r\n real(8) :: x(:)\r\n real(8) :: y(:)\r\n real(8) :: x0,deltax, deltay\r\n integer :: i,n\r\n ! Sizes\r\n n = size(x)\r\n\r\n if(x0 .LT. x(1))then\r\n stop \"Interpolation Failed. Too small\"\r\n elseif(x0 .GT. x(n))then\r\n stop \"Interpolation Failed. Too LARGE\"\r\n endif\r\n do i=1,n\r\n if( x0 < x(i+1) ) exit\r\n enddo\r\n\r\n ! interpolate\r\n deltax = x(i+1)-x(i)\r\n deltay = y(i+1)-y(i)\r\n\r\n interpolate = y(i)+deltay/deltax*(x0-x(i))\r\n end function\r\n\r\nend program\r\n", "meta": {"hexsha": "bebc6fbbd1974f2e7e34b84a25cbef7d223ccc95", "size": 7337, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "prl2.f90", "max_stars_repo_name": "croneill/Prandtl-Lifting-Line", "max_stars_repo_head_hexsha": "c54b32e65edf38b77694280951a39111560bd40d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-09-30T16:39:13.000Z", "max_stars_repo_stars_event_max_datetime": "2017-09-30T16:39:13.000Z", "max_issues_repo_path": "prl2.f90", "max_issues_repo_name": "croneill/Prandtl-Lifting-Line", "max_issues_repo_head_hexsha": "c54b32e65edf38b77694280951a39111560bd40d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "prl2.f90", "max_forks_repo_name": "croneill/Prandtl-Lifting-Line", "max_forks_repo_head_hexsha": "c54b32e65edf38b77694280951a39111560bd40d", "max_forks_repo_licenses": ["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.925795053, "max_line_length": 99, "alphanum_fraction": 0.5454545455, "num_tokens": 2866, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972684083609, "lm_q2_score": 0.787931185683219, "lm_q1q2_score": 0.6859707379495714}} {"text": " program prog\n parameter(n1=2)\n parameter(n2=n1*4)\n parameter(n3=(n2+n1)*5)\n parameter(n4=(n3-n2)**3)\n parameter(n5f=n2*(n4+1)/1.99)\n write(6, *) n5f\n end\n", "meta": {"hexsha": "fd9cde0cc4eeec5151f92d228b1c1ffbd2eddd97", "size": 195, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "fable/test/valid/const_expressions_2.f", "max_stars_repo_name": "rimmartin/cctbx_project", "max_stars_repo_head_hexsha": "644090f9432d9afc22cfb542fc3ab78ca8e15e5d", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 155, "max_stars_repo_stars_event_min_datetime": "2016-11-23T12:52:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T15:35:44.000Z", "max_issues_repo_path": "fable/test/valid/const_expressions_2.f", "max_issues_repo_name": "rimmartin/cctbx_project", "max_issues_repo_head_hexsha": "644090f9432d9afc22cfb542fc3ab78ca8e15e5d", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": 590, "max_issues_repo_issues_event_min_datetime": "2016-12-10T11:31:18.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T23:10:09.000Z", "max_forks_repo_path": "fable/test/valid/const_expressions_2.f", "max_forks_repo_name": "rimmartin/cctbx_project", "max_forks_repo_head_hexsha": "644090f9432d9afc22cfb542fc3ab78ca8e15e5d", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": 115, "max_forks_repo_forks_event_min_datetime": "2016-11-15T08:17:28.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-09T15:30:14.000Z", "avg_line_length": 21.6666666667, "max_line_length": 35, "alphanum_fraction": 0.5179487179, "num_tokens": 74, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9343951698485602, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6859577454624712}} {"text": " SUBROUTINE CARTFRAC(RX11,RY11,RZ11,RA,RB,RC)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!!! converts cartesian to fractional cooridates\n!!!! K.Travis 06/05/12 Univ. of Sheffield\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n USE header_file\n IMPLICIT NONE\n\n REAL(kind = double) :: RA,RB,RC,RX11,RY11,RZ11\n\n RA = RX11*ECF(1,1) + RY11*ECF(1,2) + RZ11*ECF(1,3)\n RB = RX11*ECF(2,1) + RY11*ECF(2,2) + RZ11*ECF(2,3)\n RC = RX11*ECF(3,1) + RY11*ECF(3,2) + RZ11*ECF(3,3)\n RA = RA + 0.5D0\n RB = RB + 0.5D0\n RC = RC + 0.5D0\n\n END SUBROUTINE\n", "meta": {"hexsha": "285cfc5720eb39db838c951979cc66bae3a05c33", "size": 617, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "synthetic_NEMD/src/src_3dsllod/cartfrac.f90", "max_stars_repo_name": "niallj/ImperialNESS-Sep14", "max_stars_repo_head_hexsha": "0cd309273cdb89f8055c2aa51422584e2284ca94", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "synthetic_NEMD/src/src_3dsllod/cartfrac.f90", "max_issues_repo_name": "niallj/ImperialNESS-Sep14", "max_issues_repo_head_hexsha": "0cd309273cdb89f8055c2aa51422584e2284ca94", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "synthetic_NEMD/src/src_3dsllod/cartfrac.f90", "max_forks_repo_name": "niallj/ImperialNESS-Sep14", "max_forks_repo_head_hexsha": "0cd309273cdb89f8055c2aa51422584e2284ca94", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.85, "max_line_length": 57, "alphanum_fraction": 0.4619124797, "num_tokens": 251, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951588871157, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6859577374154607}} {"text": "module mt19937\n ! This module is the submodule of \"random_number\" module\n use,intrinsic :: iso_fortran_env\n implicit none\n private\n public:: set_seed, random_mt\n integer(int32),parameter:: N = 624\n integer(int32),parameter:: N1 = 625\n integer(int32),parameter:: M = 397\n integer(int32),parameter:: MATA = -1727483681\n integer(int32),parameter:: UMASK = -2147483648_int64\n integer(int32),parameter:: LMASK = 2147483647\n integer(int32),parameter:: TMASKB = -1658038656\n integer(int32),parameter:: TMASKC = -272236544\n real(real64),parameter:: b32 = 2.0d0 ** 32\n integer(int32) :: mti = N1, mt(0:N-1), mag01(0:1) = [0, MATA]\ncontains\n subroutine set_seed(seed)\n integer(int32),intent(in) :: seed\n mt(0) = iand(seed, -1)\n do mti = 1, N-1\n mt(mti) = iand(69069 * mt(mti-1), -1)\n end do\n end subroutine set_seed\n\n function random_mt()\n integer(int32) :: y, kk\n real(real64):: random_mt\n\n if(mti >= N) then\n if(mti == N+1) call set_seed(4357)\n do kk=0, N-M-1\n y = ior(iand(mt(kk), UMASK), iand(mt(kk+1), LMASK))\n mt(kk) = ieor(ieor(mt(kk+M), ishft(y, -1)), mag01(iand(y, 1)))\n end do\n \n do kk = N-M, N-2\n y = ior(iand(mt(kk), UMASK), iand(mt(kk+1), LMASK))\n mt(kk) = ieor(ieor(mt(kk+(M-N)), ishft(y, -1)), mag01(iand(y, 1)))\n end do\n \n y = ior(iand(mt(N-1), UMASK), iand(mt(0), LMASK))\n mt(N-1) = ieor(ieor(mt(M-1), ishft(y, -1)), mag01(iand(y, 1)))\n mti = 0\n endif\n \n y = mt(mti)\n mti = mti+1\n y = ieor(y, ishft(y, -11))\n y = ieor(y, iand(ishft(y, 7), TMASKB))\n y = ieor(y, iand(ishft(y, 15), TMASKC))\n y = ieor(y, ishft(y, -18))\n\n if(y < 0) then\n random_mt = (dble(y)+b32) / b32\n else\n random_mt = dble(y) / b32\n endif\n end function random_mt\nend module mt19937\n\n\nmodule multiple_congruential_method\n ! This module is the submodule of \"random_number\" module\n ! These are the random numbers used by Ootoriken.\n use,intrinsic :: iso_fortran_env\n implicit none\n private\n public:: random_mcm, init_mcm\n real(real64),parameter:: b0=5d0**9,tm=2d0**25\n real(real64):: dran=3d0**11\ncontains\n subroutine init_mcm()\n implicit none\n\n dran=3d0**11\n end subroutine\n\n function random_mcm() result(ret)\n real(real64):: ret\n\n dran=mod(b0*dran,tm)\n ret=dran/tm\n end function\nend module\n\n\nmodule random_number\n ! This module include\n ! random_mt random_mcm\n ! random_gaussian\n\n ! 1. random_mt\n ! This is a function that uses the \n ! Mersenne Twister to return a uniform random number.\n ! ex.) rnum = random_mt()\n\n ! 2. random_mcm\n ! This is a function that uses the \n ! multiplicative congruence method \n ! to return a uniform random number.\n ! ex.) rnum = random_mcm()\n\n ! 3. random_gaussian\n ! This is a function that uses the \n ! Box-Muller method to return \n ! a normal random number.\n ! ex.) rnum = random_gaussian(random_mt) <- use Mersenne Twister\n ! ex.) rnum = random_gaussian(random_mcm) <- use multiplicative congruence method\n use,intrinsic :: iso_fortran_env\n use multiple_congruential_method\n use mt19937\n implicit none\n abstract interface\n function random_func()\n use,intrinsic :: iso_fortran_env\n real(real64):: random_func\n end function\n end interface\n private\n public:: random_gaussian, random_mt, random_mcm\n public:: init_mcm\n real(real64),parameter:: pi2 = acos(-1d0)*2d0\ncontains\n function random_gaussian(rand) result(ret)\n procedure(random_func):: rand\n real(real64):: ret\n ret=sqrt(-2d0*log(rand()))*cos(pi2*rand())\n end function\nend module", "meta": {"hexsha": "4fc1018c22761928b1d2a8fc0c2fe97507e3c954", "size": 3926, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/random_number.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/random_number.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/random_number.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": 30.2, "max_line_length": 85, "alphanum_fraction": 0.5927152318, "num_tokens": 1228, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818865, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.685929276476954}} {"text": "c\nc-----------------------------------------------------------------------\nc main program: time-efficient radix-4 fast fourier transform\nc author: l. robert morris\nc department of systems engineering and computing science\nc carleton university, ottawa, canada k1s 5b6\nc\nc input: the array \"a\" contains the data to be transformed\nc-----------------------------------------------------------------------\nc\nc test program for autogen radix-4 fft\nc\n dimension a(2048),b(2048)\n common /aa/a\nc\n ioutd=i1mach(2)\nc\nc compute dft and idft for n = 64, 256, and 1024 complex points\nc\n do 1 mm=3,5\n n=4**mm\n do 2 j=1,n\n a(2*j-1)=uni(0)\n a(2*j )=uni(0)\n b(2*j-1)=a(2*j-1)\n2 b(2*j )=a(2*j)\nc\nc forward dft\nc\n call radix4(mm,1,-1)\nc\n if(mm.ne.3) go to 5\nc\nc list dft input, output for n = 64 only\nc\n write(ioutd,98)\n write(ioutd,100)\n do 3 j=1,n\n write(ioutd,96) b(2*j-1),b(2*j),a(2*j-1),a(2*j)\n3 continue\nc\nc inverse dft\nc\n5 call radix4(mm,0, 1)\nc\nc list dft input, idft output for n = 64 only\nc\n if(mm.ne.3) go to 7\nc\n write(ioutd,99)\n write(ioutd,100)\n do 6 j=1,n\n write(ioutd,96) b(2*j-1),b(2*j),a(2*j-1),a(2*j)\n6 continue\nc\nc calculate rms error\nc\n7 err=0.0\n do 8 j=1,n\n8 err=err+(a(2*j-1)-b(2*j-1))**2+(a(2*j)-b(2*j))**2\n err=sqrt(err/float(n))\n write(ioutd,97) mm,err\n1 continue\nc\n96 format(1x,4(f10.6,2x))\n97 format(1x,20h rms error for m =,i2,4h is ,e14.6/)\n98 format(1x,43h dft input dft output/)\n99 format(1x,43h dft input idft output/)\n100 format(1x,44h real imag real imag/)\n stop\n end\n", "meta": {"hexsha": "cf550e0150bb2043b4cacb4f673de7e5840a5886", "size": 1879, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iraf.v2161/math/ieee/chap1/test/test18.f", "max_stars_repo_name": "ysBach/irafdocgen", "max_stars_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:19:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T16:48:42.000Z", "max_issues_repo_path": "iraf.v2161/math/ieee/chap1/test/test18.f", "max_issues_repo_name": "ysBach/irafdocgen", "max_issues_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-30T13:48:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-02T19:40:25.000Z", "max_forks_repo_path": "iraf.v2161/math/ieee/chap1/test/test18.f", "max_forks_repo_name": "ysBach/irafdocgen", "max_forks_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_forks_repo_licenses": ["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.0972222222, "max_line_length": 72, "alphanum_fraction": 0.4811069718, "num_tokens": 657, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837705, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6859292690047178}} {"text": "MODULE Complex_Number\r\n!Ahora definiremos tambien las funciones de lo Complejos\r\n\r\nUSE Complex_Data\r\n\r\nIMPLICIT NONE\r\n\r\nCONTAINS ! Esta declaracion es necesaria para agregar procedimientos (funciones y subrutinas)\r\n\r\nFUNCTION C_Add(Z1, Z2)\r\n\r\nUSE Complex_Data\r\n!IMPLICIT NONE\r\n\r\n!Definici\ufffdn de Datos\r\nTYPE (C_Number) :: C_Add\r\nTYPE (C_Number), INTENT(IN):: Z1, Z2\r\n\r\n!Definici\ufffdn de la Suma\r\nC_Add%ReZ = Z1%ReZ + Z2%ReZ\r\nC_Add%ImZ = Z1%ImZ + Z2%ImZ\r\n\r\n\r\nEND FUNCTION C_Add\r\n\r\nFUNCTION C_Mul(Z1, Z2)\r\n\r\nUSE Complex_Data\r\n\r\nTYPE (C_Number) :: C_Mul\r\nTYPE (C_Number), INTENT(IN):: Z1, Z2\r\n\r\n!Definici\ufffdn de la Suma\r\nC_Mul%ReZ = (Z1%ReZ * Z2%ReZ)-(Z1%ImZ * Z2%ImZ)\r\nC_Mul%ImZ = (Z1%ReZ * Z2%ImZ)+(Z1%ImZ * Z2%ReZ)\r\n\r\n\r\nEND FUNCTION C_Mul\r\n\r\nEND MODULE Complex_Number\r\n", "meta": {"hexsha": "c1935b963370f30bbcb640bcffe5bbac5b008087", "size": 765, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Ejemplo09/Complex_Number.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": "Ejemplo09/Complex_Number.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": "Ejemplo09/Complex_Number.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.6585365854, "max_line_length": 97, "alphanum_fraction": 0.691503268, "num_tokens": 277, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178969328286, "lm_q2_score": 0.7549149868676284, "lm_q1q2_score": 0.6859292677307384}} {"text": "! Purpose :\n! Multidimensional minimization of the function funk(x) where !x(1:ndim)\n! is a vector in ndim dimensions, by the downhill simplex method of \n! Nelder and Mead. The matrix p(1:ndim+1,1:ndim) is input. Its ndim+1 rows \n! are ndim-dimensional vectors which are the vertices of the starting \n! simplex. Also input is the vector y(1:ndim+1), whose components must be \n! pre-initialized to the values of funk evaluated at the ndim+1 vertices \n! (rows) of p; and ftol the fractional convergence tolerance to be \n! achieved in the function value (n.b.!). On output, p and y will \n! have been reset to ndim+1 new points all within ftol of a minimum\n! function value, and iter gives the number of function evaluations taken.\n! Ref : \n! Nelder, J.A., and Mead, R. 1965, Computer Journal, vol. 7, pp. 308\u2013313. [1]\n! Yarbro, L.A., and Deming, S.N. 1974, Analytica Chimica Acta, vol. 73, pp.\n! 391\u2013398.\n! Jacoby, S.L.S, Kowalik, J.S., and Pizzo, J.T. 1972, Iterative Methods for\n! Nonlinear Optimization\n! Problems (Englewood Cliffs, NJ: Prentice-Hall).\n! \n! \n\n subroutine amoeba(ndim, p,y,ftol,func,iter)\n implicit none\n\n ! precision control \n integer, parameter :: dp= kind(1d0)\n integer, parameter :: i4b= 4\n\n !>> inout variables\n ! dimension of our variable space\n integer(i4b), intent(in) :: ndim\n integer(i4b), intent(out) :: iter\n\n ! the fractional convergence tolerance to be achieved in the function\n ! value\n real(dp), intent(in) :: ftol\n\n real(dp), intent(inout) :: y(ndim+1)\n real(dp), intent(inout) :: p(ndim+1, ndim)\n\n interface\n function func(n, x)\n implicit none\n integer, parameter :: dp= kind(1d0)\n integer, intent(in) :: n\n real(dp), dimension(n), intent(in) :: x\n real(dp) :: func\n end function func\n end interface\n\n !>> local variables\n integer(i4b), parameter :: itmax=5000\n real(dp), parameter :: tiny=1.0e-10\n integer(i4b) :: ihi\n real(dp), dimension(size(p,2)) :: psum\n\n call amoeba_private\n contains\n\n subroutine amoeba_private\n implicit none\n integer(i4b) :: i,ilo,inhi\n real(dp) :: rtol,ysave,ytry,ytmp\n iter=0\n\n ! Enter here when starting or have just overall contracted.\n ! Recompute psum.\n psum(:)=sum(p(:,:),dim=1)\n\n do while (.true.)\n\n ! Enter here when have just changed a single point.\n ! Determine which point is the highest (worst) ihi, next-highest inhi,\n ! and lowest (best) ilo\n ilo=iminloc(y(:))\n ihi=imaxloc(y(:))\n ytmp=y(ihi)\n y(ihi)=y(ilo)\n inhi=imaxloc(y(:))\n y(ihi)=ytmp\n\n ! Compute the fractional range from highest to lowest and return if\n ! satisfactory.\n ! If returning, put best point and value in slot 1.\n rtol=2.0_dp*abs(y(ihi)-y(ilo))/(abs(y(ihi))+abs(y(ilo))+tiny)\n if (rtol < ftol) then\n call swap1(y(1),y(ilo))\n call swap2(p(1,:),p(ilo,:))\n call printpy(p, y)\n return\n end if\n if (iter >= itmax) then\n print*, 'itmax exceeded in amoeba'\n return\n endif\n \n ! begin a new iteration. first extrapolate by a factor ?1 through the\n ! face of the simplex\n ! across from the high point, i.e., reflect the simplex from the high\n ! point.\n ytry=amotry(-1.0_dp)\n iter=iter+1\n call printpy(p, y)\n if (ytry <= y(ilo)) then\n ! gives a result better than the best point, so\n ! try an additional extrapolation by a factor of 2\n ytry=amotry(2.0_dp)\n iter=iter+1\n call printpy(p, y)\n else if (ytry >= y(inhi)) then\n ! the reflected point is worse than the second\n ! highest, so look for an intermediate lower point, i.e., do a\n ! one-dimensional contraction.\n ysave=y(ihi)\n ytry=amotry(0.5_dp)\n iter=iter+1\n call printpy(p, y)\n if (ytry >= ysave) then\n ! can't seem to get rid of that high point. better contract\n ! around the lowest (best) point.\n p(:,:)=0.5_dp*(p(:,:)+spread(p(ilo,:),1,size(p,1)))\n do i=1,ndim+1\n !if (i /= ilo) call func(ndim, p(i,:), y(i))\n if (i /= ilo) y(i)=func(ndim, p(i,:))\n end do\n !keep track of function evaluations.\n iter=iter+ndim \n psum(:)=sum(p(:,:),dim=1)\n end if\n end if\n\n end do !go back for the test of doneness and the next\n end subroutine amoeba_private\n!bl\n\n !>>> Extrapolates by a factor fac through the face of the simplex across from\n ! the high point,\n ! tries it, and replaces the high point if the new point is better.\n function amotry(fac)\n implicit none\n real(dp), intent(in) :: fac\n real(dp) :: amotry\n real(dp) :: fac1,fac2,ytry\n real(dp), dimension(size(p,2)) :: ptry\n fac1=(1.0_dp-fac)/ndim\n fac2=fac1-fac\n ptry(:)=psum(:)*fac1-p(ihi,:)*fac2\n ytry=func(ndim, ptry)\n !call func(ndim, ptry, ytry)\n if (ytry < y(ihi)) then\n y(ihi)=ytry\n psum(:)=psum(:)-p(ihi,:)+ptry(:)\n p(ihi,:)=ptry(:)\n end if\n amotry=ytry\n end function amotry\n\n !>>> function that find the location of the minimum value of y\n function iminloc(y)\n implicit none\n real(dp), intent(in) :: y(ndim+1)\n integer(i4b) :: iminloc\n\n integer(i4b) :: i\n\n iminloc=1\n do i=1, ndim+1\n if (y(i)>> function that find the location of the maximum value of y\n function imaxloc(y)\n implicit none\n real(dp), intent(in) :: y(ndim+1)\n integer(i4b) :: imaxloc\n\n integer(i4b) :: i\n\n imaxloc=1\n do i=1, ndim+1\n if (y(i)>y(imaxloc)) imaxloc=i\n enddo\n end function imaxloc\n\n ! swap two values\n subroutine swap1(x, y)\n implicit none\n real(dp), intent(inout) :: x\n real(dp), intent(inout) :: y\n real(dp) :: z\n z= x\n x= y\n y= z\n return\n end subroutine swap1\n\n ! swap two vectors\n subroutine swap2(x, y)\n implicit none\n real(dp), intent(inout) :: x(ndim)\n real(dp), intent(inout) :: y(ndim)\n real(dp) :: z(ndim)\n z= x\n x= y\n y= z\n\n return\n end subroutine swap2\n\n subroutine printpy(p, y)\n\n implicit none\n\n real(dp), intent(in) :: p(ndim+1, ndim)\n real(dp), intent(in) :: y(ndim+1 )\n\n integer :: i\n\n ! output some informations\n write(6, '(a, i8)') 'Amoeba iter= ', iter\n write(6, '(\"x\", 4f16.6)') (p(1, i), i=1, ndim)\n write(6, '(\"y\", 4f16.6)') (y( i), i=1, ndim+1)\n\n return\n end subroutine printpy\n end subroutine amoeba\n", "meta": {"hexsha": "5af6058fb00a365776f0cb9fa9ebc5d62723c864", "size": 7013, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fitsoc/amoeba.f90", "max_stars_repo_name": "dlnguyen/wannier_tools", "max_stars_repo_head_hexsha": "cc6748e3718ee2a89934a187490c37f9f520aeff", "max_stars_repo_licenses": ["OLDAP-2.3"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-14T12:07:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-14T12:07:24.000Z", "max_issues_repo_path": "fitsoc/amoeba.f90", "max_issues_repo_name": "jtsun/wannier_tools", "max_issues_repo_head_hexsha": "f3512e986c6546af6b823ee6b8a4b9118c53a9fa", "max_issues_repo_licenses": ["OLDAP-2.3"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fitsoc/amoeba.f90", "max_forks_repo_name": "jtsun/wannier_tools", "max_forks_repo_head_hexsha": "f3512e986c6546af6b823ee6b8a4b9118c53a9fa", "max_forks_repo_licenses": ["OLDAP-2.3"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.7587719298, "max_line_length": 80, "alphanum_fraction": 0.5591045202, "num_tokens": 2100, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837705, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6859292589845225}} {"text": "\nc Calculate determinant of square matrix\nc Author: Pearu Peterson, March 2002\nc\nc prefixes: d,z,s,c (double,complex double,float,complex float)\nc suffixes: _c,_r (column major order,row major order)\n\n subroutine ddet_c(det,a,n,piv,info)\n integer n,piv(n),i\n double precision det,a(n,n)\ncf2py intent(in,copy) :: a\ncf2py intent(out) :: det,info\ncf2py integer intent(hide,cache),depend(n),dimension(n) :: piv\ncf2py integer intent(hide),depend(a) :: n = shape(a,0)\ncf2py check(shape(a,0)==shape(a,1)) :: a\ncf2py callprotoargument double*,double*,int*,int*,int*\n external dgetrf\n call dgetrf(n,n,a,n,piv,info)\n det = 0d0\n if (info.ne.0) then\n return\n endif\n det = 1d0\n do 10,i=1,n\n if (piv(i).ne.i) then\n det = -det * a(i,i)\n else\n det = det * a(i,i)\n endif\n 10 continue\n end\n\n subroutine ddet_r(det,a,n,piv,info)\n integer n,piv(n)\n double precision det,a(n,n)\ncf2py intent(c,in,copy) :: a\ncf2py intent(out) :: det,info\ncf2py integer intent(hide,cache),depend(n),dimension(n) :: piv\ncf2py integer intent(hide),depend(a) :: n = shape(a,0)\ncf2py check(shape(a,0)==shape(a,1)) :: a\ncf2py callprotoargument double*,double*,int*,int*,int*\n external ddet_c\n call ddet_c(det,a,n,piv,info)\n end\n\n subroutine sdet_c(det,a,n,piv,info)\n integer n,piv(n),i\n real det,a(n,n)\ncf2py intent(in,copy) :: a\ncf2py intent(out) :: det,info\ncf2py integer intent(hide,cache),depend(n),dimension(n) :: piv\ncf2py integer intent(hide),depend(a) :: n = shape(a,0)\ncf2py check(shape(a,0)==shape(a,1)) :: a\ncf2py callprotoargument float*,float*,int*,int*,int*\n external sgetrf\n call sgetrf(n,n,a,n,piv,info)\n det = 0e0\n if (info.ne.0) then\n return\n endif\n det = 1e0\n do 10,i=1,n\n if (piv(i).ne.i) then\n det = -det * a(i,i)\n else\n det = det * a(i,i)\n endif\n 10 continue\n end\n\n subroutine sdet_r(det,a,n,piv,info)\n integer n,piv(n)\n real det,a(n,n)\ncf2py intent(c,in,copy) :: a\ncf2py intent(out) :: det,info\ncf2py integer intent(hide,cache),depend(n),dimension(n) :: piv\ncf2py integer intent(hide),depend(a) :: n = shape(a,0)\ncf2py check(shape(a,0)==shape(a,1)) :: a\ncf2py callprotoargument float*,float*,int*,int*,int*\n external sdet_c\n call sdet_c(det,a,n,piv,info)\n end\n\n subroutine zdet_c(det,a,n,piv,info)\n integer n,piv(n),i\n complex*16 det,a(n,n)\ncf2py intent(in,copy) :: a\ncf2py intent(out) :: det,info\ncf2py integer intent(hide,cache),depend(n),dimension(n) :: piv\ncf2py integer intent(hide),depend(a) :: n = shape(a,0)\ncf2py check(shape(a,0)==shape(a,1)) :: a\ncf2py callprotoargument complex_double*,complex_double*,int*,int*,int*\n external zgetrf\n call zgetrf(n,n,a,n,piv,info)\n det = (0d0,0d0)\n if (info.ne.0) then\n return\n endif\n det = (1d0,0d0)\n do 10,i=1,n\n if (piv(i).ne.i) then\n det = -det * a(i,i)\n else\n det = det * a(i,i)\n endif\n 10 continue\n end\n\n subroutine zdet_r(det,a,n,piv,info)\n integer n,piv(n)\n complex*16 det,a(n,n)\ncf2py intent(c,in,copy) :: a\ncf2py intent(out) :: det,info\ncf2py integer intent(hide,cache),depend(n),dimension(n) :: piv\ncf2py integer intent(hide),depend(a) :: n = shape(a,0)\ncf2py check(shape(a,0)==shape(a,1)) :: a\ncf2py callprotoargument complex_double*,complex_double*,int*,int*,int*\n external zdet_c\n call zdet_c(det,a,n,piv,info)\n end\n\n subroutine cdet_c(det,a,n,piv,info)\n integer n,piv(n),i\n complex det,a(n,n)\ncf2py intent(in,copy) :: a\ncf2py intent(out) :: det,info\ncf2py integer intent(hide,cache),depend(n),dimension(n) :: piv\ncf2py integer intent(hide),depend(a) :: n = shape(a,0)\ncf2py check(shape(a,0)==shape(a,1)) :: a\ncf2py callprotoargument complex_float*,complex_float*,int*,int*,int*\n external cgetrf\n call cgetrf(n,n,a,n,piv,info)\n det = (0e0,0e0)\n if (info.ne.0) then\n return\n endif\n det = (1e0,0e0)\n do 10,i=1,n\n if (piv(i).ne.i) then\n det = -det * a(i,i)\n else\n det = det * a(i,i)\n endif\n 10 continue\n end\n\n subroutine cdet_r(det,a,n,piv,info)\n integer n,piv(n)\n complex det,a(n,n)\ncf2py intent(c,in,copy) :: a\ncf2py intent(out) :: det,info\ncf2py integer intent(hide,cache),depend(n),dimension(n) :: piv\ncf2py integer intent(hide),depend(a) :: n = shape(a,0)\ncf2py check(shape(a,0)==shape(a,1)) :: a\ncf2py callprotoargument complex_float*,complex_float*,int*,int*,int*\n external cdet_c\n call cdet_c(det,a,n,piv,info)\n end\n\n\n\n", "meta": {"hexsha": "b3a25ec488182e4e9f22937e72d88f594db889ca", "size": 4747, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "scipy/linalg/src/det.f", "max_stars_repo_name": "lesserwhirls/scipy-cwt", "max_stars_repo_head_hexsha": "ee673656d879d9356892621e23ed0ced3d358621", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 6989, "max_stars_repo_stars_event_min_datetime": "2017-07-18T06:23:18.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T15:58:36.000Z", "max_issues_repo_path": "scipy/linalg/src/det.f", "max_issues_repo_name": "lesserwhirls/scipy-cwt", "max_issues_repo_head_hexsha": "ee673656d879d9356892621e23ed0ced3d358621", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1978, "max_issues_repo_issues_event_min_datetime": "2017-07-18T09:17:58.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T14:28:43.000Z", "max_forks_repo_path": "scipy/linalg/src/det.f", "max_forks_repo_name": "lesserwhirls/scipy-cwt", "max_forks_repo_head_hexsha": "ee673656d879d9356892621e23ed0ced3d358621", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1228, "max_forks_repo_forks_event_min_datetime": "2017-07-18T09:03:13.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T05:57:40.000Z", "avg_line_length": 29.3024691358, "max_line_length": 70, "alphanum_fraction": 0.606277649, "num_tokens": 1567, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544912, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.685911058091755}} {"text": "module AB_matrix_fct\n\ncontains \n\n!z=matmul(aij,s) z=multiply(AB,s(:,:)) matmul for AB matrix\n\nfunction multiply(AB,s) result (z)\n implicit none\n INTEGER, PARAMETER :: wp = KIND(0.0D0) ! working precision\n REAL (wp) :: AB(:,:),s(:,:) \n REAL(wp) :: z(size(s,1),size(s,2))\n INTEGER :: i,j,k\n INTEGER :: n, KU\n KU=(size(AB,1)-1)/2\n n=size(AB,2)\n z=0\n do j=1,n \n do i=1,2*KU+1\n z(j,:)=z(j,:)+AB(i,j)*s(1+mod(N+i+j-2-KU,N),:) \n end do\n end do\n end function\n \n! CD=ColumnConvert(AB) makes a LAPACK band matrix compatible with dgbsv and KU=KL out of periodic AB matrix\n \n function ColumnConvert(AB) result (CD)\n implicit none\n INTEGER, PARAMETER :: wp = KIND(0.0D0) ! working precision\n REAL (wp) :: AB(:,:)\n REAL(wp) :: CD((3*size(AB,1)-1)/2,size(AB,2))\n INTEGER :: i,j,m\n INTEGER :: n, KU\n m=size(AB,1)\n KU=(m-1)/2\n n=size(AB,2)\n CD=0\n do j=1,n \n do i=1,2*KU+1 \n CD(i+KU,j)=AB(m-i+1,1+mod(N+i+j+KU-m-1,n)) \n end do\n end do\n end function\n \n ! AB=RowConvert(CD) makes a periodic AB matrix out of a LAPACK band matrix compatible with dgbsv and KU=KL \n \n function RowConvert(CD) result (AB)\n implicit none\n INTEGER, PARAMETER :: wp = KIND(0.0D0) ! working precision\n REAL (wp) :: CD(:,:)\n REAL(wp) :: AB((2*size(CD,1)+1)/3,size(CD,2))\n INTEGER :: i,j,m\n INTEGER :: n, KU\n m=(2*size(CD,1)+1)/3\n KU=(m-1)/2\n n=size(CD,2)\n AB=0\n do j=1,n \n do i=1,2*KU+1 \n AB(m-i+1,1+mod(N+i+j+KU-m-1,n))=CD(i+KU,j) \n end do\n end do\n end function\n\nend module\n", "meta": {"hexsha": "4cc5f4a10cded38400bd4704ef0b596809517e7e", "size": 1570, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "AB_matrix_fct.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": "AB_matrix_fct.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": "AB_matrix_fct.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": 24.1538461538, "max_line_length": 109, "alphanum_fraction": 0.5649681529, "num_tokens": 597, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544912, "lm_q2_score": 0.7772998611746911, "lm_q1q2_score": 0.6859110580917549}} {"text": "module svd_lib \n use nan_lib\n implicit none\n interface svd\n module procedure d_svd, z_svd\n end interface\n\ncontains\n subroutine d_svd(a,u,v,s,tol,rmax,err,info)\n implicit none\n real(8),intent(in) :: a(:,:)\n real(8),pointer :: u(:,:),v(:,:),s(:)\n real(8),intent(in),optional :: tol\n integer,intent(in),optional :: rmax\n real(8),intent(out),optional :: err\n integer,intent(out),optional :: info\n character(len=*),parameter :: subnam='d_svd'\n real(8),allocatable :: b(:,:),work(:),ss(:),uu(:,:),vv(:,:)\n integer :: m,n,mn,lwork,ierr,r,i,j\n real(8),external :: dnrm2\n m=size(a,1); n=size(a,2); mn=min(m,n); lwork=256*max(m,n)\n allocate(uu(m,mn),vv(mn,n),ss(mn),b(m,n),work(lwork),stat=ierr)\n if(ierr.ne.0)then;write(*,*)subnam,': cannot allocate';stop;endif\n call dcopy(m*n,a,1,b,1)\n call dgesvd('s','s',m,n,b,m,ss,uu,m,vv,mn,work,lwork,ierr)\n if(present(info))info=ierr\n if(ierr.ne.0)then\n write(*,*)subnam,': dgesvd info: ',ierr\n if(ierr.lt.0)stop\n if(nan(a))then\n write(*,*) subnam,': NaNs detected in the input array'\n stop\n else\n write(*,*) subnam,': min/max element of input: ',minval(a),maxval(a)\n end if \n u=>null(); v=>null(); s=>null()\n else \n r=chop(ss,tol,rmax,err)\n if(present(err))err=err/dnrm2(mn,ss,1)\n allocate(u(m,r),v(n,r),s(r))\n call dcopy(m*r,uu,1,u,1)\n call dcopy(r,ss,1,s,1)\n forall(i=1:n,j=1:r)v(i,j)=vv(j,i)\n end if \n deallocate(uu,vv,ss,b,work)\n end subroutine \n subroutine z_svd(a,u,v,s,tol,rmax,err,info)\n implicit none\n double complex,intent(in) :: a(:,:)\n double complex,pointer :: u(:,:),v(:,:)\n real(8),pointer :: s(:)\n real(8),intent(in),optional :: tol\n integer,intent(in),optional :: rmax\n real(8),intent(out),optional :: err\n integer,intent(out),optional :: info\n character(len=*),parameter :: subnam='z_svd'\n double complex,allocatable :: b(:,:),work(:),uu(:,:),vv(:,:)\n real(8),allocatable :: ss(:),rwork(:)\n integer :: m,n,mn,lwork,ierr,r,i,j\n real(8),external :: dnrm2\n m=size(a,1); n=size(a,2); mn=min(m,n); lwork=256*max(m,n)\n allocate(uu(m,mn),vv(mn,n),ss(mn),b(m,n),work(lwork),rwork(lwork),stat=ierr)\n if(ierr.ne.0)then;write(*,*)subnam,': cannot allocate';stop;endif\n call zcopy(m*n,a,1,b,1)\n call zgesvd('s','s',m,n,b,m,ss,uu,m,vv,mn,work,lwork,rwork,ierr)\n if(present(info))info=ierr\n if(ierr.ne.0)then\n write(*,*)subnam,': zgesvd info: ',ierr\n if(ierr.lt.0)stop\n if (nan(a)) then\n write(*,*) subnam,': NaNs detected in the input array'\n stop\n end if \n u=>null(); v=>null(); s=>null()\n else \n r=chop(ss,tol,rmax,err)\n if(present(err))err=err/dnrm2(mn,ss,1)\n allocate(u(m,r),v(n,r),s(r))\n call zcopy(m*r,uu,1,u,1)\n call dcopy(r,ss,1,s,1)\n forall(i=1:n,j=1:r)v(i,j)=vv(j,i)\n end if\n deallocate(uu,vv,ss,b,work)\n end subroutine \n\n integer function chop(s,tol,rmax,err) result (r)\n implicit none\n real(8),intent(in) :: s(:)\n real(8),intent(in),optional :: tol\n integer,intent(in),optional :: rmax\n real(8),intent(out),optional :: err\n real(8) :: nrm,er,er2,bound\n real(8),external :: dnrm2\n r=size(s); er2=0.d0\n if(present(rmax))then\n if(rmax.lt.r)then\n er2=dot_product(s(rmax+1:r),s(rmax+1:r))\n r=rmax\n end if \n end if \n if(present(tol))then\n nrm=dnrm2(size(s),s,1)\n bound=tol*tol*nrm*nrm\n er=er2+s(r)*s(r)\n do while(er.lt.bound)\n er2=er; r=r-1; er=er+s(r)*s(r)\n end do\n end if\n if(present(err))err=dsqrt(er2)\n return\n end function\n\nend module\n", "meta": {"hexsha": "64a7ef9b4fd2ba6937d6f10cde82c7c159edf01c", "size": 3427, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "svd.f90", "max_stars_repo_name": "dimpase/tt-fort", "max_stars_repo_head_hexsha": "2feceda8df2f7c6c84a473759a9c502c3c5a3ded", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2017-12-07T12:51:46.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-02T11:27:41.000Z", "max_issues_repo_path": "svd.f90", "max_issues_repo_name": "dimpase/tt-fort", "max_issues_repo_head_hexsha": "2feceda8df2f7c6c84a473759a9c502c3c5a3ded", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-06-18T09:31:01.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-21T13:15:30.000Z", "max_forks_repo_path": "svd.f90", "max_forks_repo_name": "dimpase/tt-fort", "max_forks_repo_head_hexsha": "2feceda8df2f7c6c84a473759a9c502c3c5a3ded", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2015-03-30T10:53:25.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-21T03:58:11.000Z", "avg_line_length": 30.0614035088, "max_line_length": 78, "alphanum_fraction": 0.6200758681, "num_tokens": 1310, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278540866547, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.6859110575829949}} {"text": "program perfect_numbers\n\n use module_rational\n implicit none\n integer, parameter :: n_min = 2\n integer, parameter :: n_max = 2 ** 19 - 1\n integer :: n\n integer :: factor\n type (rational) :: sum\n\n do n = n_min, n_max\n sum = 1 // n\n factor = 2\n do\n if (factor * factor >= n) then\n exit\n end if\n if (modulo (n, factor) == 0) then\n sum = rational_simplify (sum + (1 // factor) + (factor // n))\n end if\n factor = factor + 1\n end do\n if (sum % numerator == 1 .and. sum % denominator == 1) then\n write (*, '(i0)') n\n end if\n end do\n\nend program perfect_numbers\n", "meta": {"hexsha": "a88c7830a9e3b5d601004a72bee0bec23c90b6ba", "size": 625, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Arithmetic-Rational/Fortran/arithmetic-rational-2.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Arithmetic-Rational/Fortran/arithmetic-rational-2.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Arithmetic-Rational/Fortran/arithmetic-rational-2.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 21.5517241379, "max_line_length": 69, "alphanum_fraction": 0.56, "num_tokens": 202, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582516374121, "lm_q2_score": 0.7371581741774411, "lm_q1q2_score": 0.6858949059253688}} {"text": "SUBROUTINE fmkdke(km,kp,c,ke,kd,theta)\n!\n! This subroutine builds up the 'coupled' stiffnesses ke and kd from \n! the 'elastic' stiffness km, fluid stiffness kp and coupling matrix c.\n!\n IMPLICIT NONE\n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\n REAL(iwp),INTENT(IN)::km(:,:),kp(:,:),c(:,:),theta\n REAL(iwp),INTENT(OUT)::ke(:,:),kd(:,:)\n INTEGER::ndof\n REAL::one=1.0_iwp\n ndof=SIZE(km,1)\n ke(:ndof,:ndof)=theta*km\n ke(:ndof,ndof+1:)=theta*c\n ke(ndof+1:,:ndof)=theta*TRANSPOSE(c)\n ke(ndof+1:,ndof+1:)=-theta**2*kp\n kd(:ndof,:ndof)=(theta-one)*km\n kd(:ndof,ndof+1:)=(theta-one)*c\n kd(ndof+1:,:ndof)=ke(ndof+1:,:ndof)\n kd(ndof+1:,ndof+1:)=theta*(one-theta)*kp\nRETURN\nEND SUBROUTINE fmkdke", "meta": {"hexsha": "cb5d77eeed44d0d3af2e5a7ad0f7f99d1c478c1e", "size": 687, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "main/fmkdke.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/fmkdke.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/fmkdke.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": 31.2272727273, "max_line_length": 71, "alphanum_fraction": 0.6754002911, "num_tokens": 271, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582516374122, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6858948951797319}} {"text": "C *************************** HERON *************************\nC function that computes the area of faces of each element \nC by applying Heron's formula:\nC given a,b,c the length of the edge of a triangle, \nC set s=(a+b+c)/2 the formula is:\nC area = dsqrt(s*(s-a)*(s-b)*(s-c))\nC\nC **************************************************************\n real*8 function heron(xfac,yfac,zfac)\n implicit none\n integer j\n real*8 xfac(3), yfac(3), zfac(3), length(3)\n real*8 s\n\n do j=1,3\n length(j) =dsqrt( (xfac(j)- xfac(mod(j,3)+1) )**2 +\n 1 (yfac(j) - yfac(mod(j,3)+1) )**2 +\n 2 (zfac(j) - zfac(mod(j,3)+1) )**2 )\n end do\n s= ( length(1) + length(2) +length(3) )*0.5d0\n heron = s\n do j=1,3\n heron =heron*(s-length(j))\n end do\n heron = dsqrt(heron)\n return\n end\n \n\n", "meta": {"hexsha": "d405e304c50d96fc664846e98967933a329fe51d", "size": 910, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "examples/weil_exemple_withDA/my_cathy_prj/src/heron.f", "max_stars_repo_name": "BenjMy/pycathy_wrapper", "max_stars_repo_head_hexsha": "8639713acbb5bc5c5cd293b94bdafe017d03f199", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "examples/weil_exemple_withDA/my_cathy_prj/src/heron.f", "max_issues_repo_name": "BenjMy/pycathy_wrapper", "max_issues_repo_head_hexsha": "8639713acbb5bc5c5cd293b94bdafe017d03f199", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2021-10-14T13:07:46.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-02T03:32:05.000Z", "max_forks_repo_path": "examples/weil_exemple_withDA/my_cathy_prj/src/heron.f", "max_forks_repo_name": "BenjMy/pycathy_wrapper", "max_forks_repo_head_hexsha": "8639713acbb5bc5c5cd293b94bdafe017d03f199", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.3333333333, "max_line_length": 64, "alphanum_fraction": 0.4340659341, "num_tokens": 294, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582516374121, "lm_q2_score": 0.7371581568543044, "lm_q1q2_score": 0.6858948898069133}} {"text": "module comoving_nd_module\n\n use amrex_error_module\n use amrex_fort_module, only : rt => amrex_real\n\n contains\n\n! :::\n! ::: ----------------------------------------------------------------\n! :::\n\n subroutine fort_integrate_comoving_a(old_a,new_a,dt) &\n bind(C, name=\"fort_integrate_comoving_a\")\n\n use fundamental_constants_module, only: Hubble_const\n use comoving_module , only: comoving_h, comoving_OmM, &\n comoving_OmR, comoving_type\n\n implicit none\n\n real(rt), intent(in ) :: old_a, dt\n real(rt), intent( out) :: new_a\n\n real(rt), parameter :: xacc = 1.0d-8\n real(rt) :: H_0, OmL\n real(rt) :: Delta_t, prev_soln\n real(rt) :: start_a, end_a, start_slope, end_slope\n integer :: iter, j, nsteps\n\n if (comoving_h .eq. 0.0d0) then\n new_a = old_a\n return\n endif\n\n H_0 = comoving_h * Hubble_const\n OmL = 1.d0 - comoving_OmM - comoving_OmR \n\n prev_soln = 2.0d0 ! 0 0) then\n start_slope = H_0*dsqrt(comoving_OmM/start_a + comoving_OmR/(start_a*start_a) + OmL*start_a**2)\n else\n start_slope = comoving_h\n end if\n\n ! Compute a provisional value of ln(a) at the new time \n end_a = start_a + start_slope * Delta_t\n \n ! Compute the slope at the new time\n if (comoving_type > 0) then\n end_slope = H_0*dsqrt(comoving_OmM/end_a + comoving_OmR/(end_a*end_a) + OmL*end_a**2)\n else\n end_slope = comoving_h \n end if\n \n ! Now recompute a at the new time using the average of the two slopes\n end_a = start_a + 0.5d0 * (start_slope + end_slope) * Delta_t\n enddo\n\n new_a = end_a\n if (abs(1.0d0-new_a/prev_soln) .le. xacc) return\n prev_soln = new_a\n\n enddo\n\n end subroutine fort_integrate_comoving_a\n\n! :::\n! ::: ----------------------------------------------------------------\n! :::\n\n subroutine fort_integrate_comoving_a_to_z(old_a,z_value,dt) &\n bind(C, name=\"fort_integrate_comoving_a_to_z\")\n\n use fundamental_constants_module, only: Hubble_const\n use comoving_module , only: comoving_h, comoving_OmM, &\n comoving_OmR, comoving_type\n\n implicit none\n\n real(rt), intent(in ) :: old_a, z_value\n real(rt), intent(inout) :: dt\n\n real(rt), parameter :: xacc = 1.0d-8\n real(rt) :: H_0, OmL\n real(rt) :: Delta_t\n real(rt) :: start_a, end_a, start_slope, end_slope\n real(rt) :: a_value\n integer :: j, nsteps\n\n if (comoving_h .eq. 0.0d0) &\n call amrex_error(\"fort_integrate_comoving_a_to_z: Shouldn't be setting plot_z_values if not evolving a\")\n\n H_0 = comoving_h * Hubble_const\n OmL = 1.d0 - comoving_OmM - comoving_OmR\n \n ! Translate the target \"z\" into a target \"a\"\n a_value = 1.d0 / (1.d0 + z_value)\n\n ! Use lots of steps if we want to nail the z_value\n nsteps = 1024\n\n ! We integrate a, but stop when a = a_value (or close enough)\n Delta_t = dt/nsteps\n end_a = old_a\n do j = 1, nsteps\n ! This uses RK2 to integrate the ODE:\n ! da / dt = H_0 * sqrt(OmM/a + OmR/a^2 + OmL*a^2)\n start_a = end_a\n\n ! Compute the slope at the old time\n if (comoving_type > 0) then\n start_slope = H_0*dsqrt(comoving_OmM/start_a + comoving_OmR/(start_a*start_a) + OmL*start_a**2)\n else\n start_slope = comoving_h\n end if\n\n ! Compute a provisional value of ln(a) at the new time \n end_a = start_a + start_slope * Delta_t\n\n ! Compute the slope at the new time\n if (comoving_type > 0) then\n end_slope = H_0*dsqrt(comoving_OmM/end_a + comoving_OmR/(end_a*end_a) + OmL*end_a**2)\n else\n end_slope = comoving_h \n end if\n \n ! Now recompute a at the new time using the average of the two slopes\n end_a = start_a + 0.5d0 * (start_slope + end_slope) * Delta_t\n\n ! We have crossed from a too small to a too big in this step\n if ( (end_a - a_value) * (start_a - a_value) < 0) then\n dt = ( ( end_a - a_value) * dble(j ) + &\n (a_value - start_a) * dble(j+1) ) / (end_a - start_a) * Delta_t\n exit\n end if\n end do\n\n end subroutine fort_integrate_comoving_a_to_z\n\n! ! :::\n! ! ::: ----------------------------------------------------------------\n! ! :::\n\n! subroutine fort_get_omb(frac) &\n! bind(C, name=\"fort_get_omb\")\n\n! use comoving_module, only: comoving_OmB, comoving_OmM\n\n! real(rt) :: frac\n\n! frac = comoving_OmB / comoving_OmM\n\n! end subroutine fort_get_omb\n\n\n! ! :::\n! ! ::: ----------------------------------------------------------------\n! ! :::\n\n! subroutine fort_get_omm(omm) &\n! bind(C, name=\"fort_get_omm\")\n\n! use comoving_module, only: comoving_OmM\n\n! real(rt) :: omm\n\n! omm = comoving_OmM\n\n! end subroutine fort_get_omm\n\n! ! :::\n! ! ::: ----------------------------------------------------------------\n! ! :::\n\n subroutine fort_get_hubble(hubble) &\n bind(C, name=\"fort_get_hubble\")\n\n use comoving_module, only: comoving_h\n\n real(rt) :: hubble\n\n hubble = comoving_h\n\n end subroutine fort_get_hubble\n\n\n! :::\n! ::: ----------------------------------------------------------------\n! :::\n\n subroutine fort_set_omb(omb) &\n bind(C, name=\"fort_set_omb\")\n\n use comoving_module, only: comoving_OmB\n\n real(rt), intent(in) :: omb\n\n comoving_OmB = omb\n\n end subroutine fort_set_omb\n\n\n! :::\n! ::: ----------------------------------------------------------------\n! :::\n\n subroutine fort_set_omm(omm) &\n bind(C, name=\"fort_set_omm\")\n\n use comoving_module, only: comoving_OmM\n\n real(rt), intent(in) :: omm\n\n comoving_OmM = omm\n\n end subroutine fort_set_omm\n\n\n! :::\n! ::: ----------------------------------------------------------------\n! :::\n\n subroutine fort_set_omr(omr) &\n bind(C, name=\"fort_set_omr\")\n\n use comoving_module, only: comoving_OmR\n\n real(rt), intent(in) :: omr\n\n comoving_OmR = omr\n\n end subroutine fort_set_omr\n\n! :::\n! ::: ----------------------------------------------------------------\n! :::\n\n subroutine fort_set_hubble(hubble) &\n bind(C, name=\"fort_set_hubble\")\n\n use comoving_module, only: comoving_h\n\n real(rt), intent(in) :: hubble\n\n comoving_h = hubble\n\n end subroutine fort_set_hubble\n\nend module comoving_nd_module\n", "meta": {"hexsha": "bdd8830f0eacd8415770a3be483b6615c0ddcb64", "size": 7410, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Source/comoving_nd.f90", "max_stars_repo_name": "Alpine-DAV/Nyx", "max_stars_repo_head_hexsha": "32c837dfb5ec4abc875fc57d2743d1fb46e49a41", "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": "Source/comoving_nd.f90", "max_issues_repo_name": "Alpine-DAV/Nyx", "max_issues_repo_head_hexsha": "32c837dfb5ec4abc875fc57d2743d1fb46e49a41", "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": "Source/comoving_nd.f90", "max_forks_repo_name": "Alpine-DAV/Nyx", "max_forks_repo_head_hexsha": "32c837dfb5ec4abc875fc57d2743d1fb46e49a41", "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": 28.3908045977, "max_line_length": 114, "alphanum_fraction": 0.5064777328, "num_tokens": 1980, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582477806521, "lm_q2_score": 0.7371581510799252, "lm_q1q2_score": 0.6858948815910525}} {"text": "program compute_pi\n use omp_lib\n implicit none\n integer, parameter :: num_iters = 1000\n integer :: i\n real :: x, pi_sum, dx, pi\n\n pi_sum = 0.0\n dx = 1.0/num_iters\n !$omp parallel private(x), shared(dx, pi_sum), default(none)\n !$omp do reduction(+:pi_sum) schedule(runtime)\n do i = 1, num_iters\n x = i*dx\n pi_sum = pi_sum + 1.0/(1.0 + x**2) \n end do\n !$end omp do\n !$omp end parallel\n pi = 4.0*pi_sum*dx\n print *, pi\nend program compute_pi\n", "meta": {"hexsha": "714d1d1571be335a41f4e591c470efbc9394d391", "size": 505, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "OpenMP/DataRaces/pi5.f90", "max_stars_repo_name": "stijnvanhoey/training-material", "max_stars_repo_head_hexsha": "d8e23c2aefaaafbd6a6d5e059147831c651f21ec", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "OpenMP/DataRaces/pi5.f90", "max_issues_repo_name": "stijnvanhoey/training-material", "max_issues_repo_head_hexsha": "d8e23c2aefaaafbd6a6d5e059147831c651f21ec", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "OpenMP/DataRaces/pi5.f90", "max_forks_repo_name": "stijnvanhoey/training-material", "max_forks_repo_head_hexsha": "d8e23c2aefaaafbd6a6d5e059147831c651f21ec", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-01-07T22:45:34.000Z", "max_forks_repo_forks_event_max_datetime": "2019-01-07T22:45:34.000Z", "avg_line_length": 24.0476190476, "max_line_length": 64, "alphanum_fraction": 0.5782178218, "num_tokens": 166, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.7690802476562641, "lm_q1q2_score": 0.6858742641108989}} {"text": "C++--------------------------------------------------------------------\nC Subroutine POLYFIT\nC\tFits a polynomial to real*8 arrays XX and YY\nC\tDegree : KK (less than 9)\nC YY = poly(XX)\nC\nC Contains:\nC TEST_POLYFIT, POLYFIT, PREPPW, INVMAT, INTERCH, CALPOLY\nC\nC From now on, it is better (?) to use \"polyfit.c\" (JLP, Feb. 2007)\nC\nC JLP\nC Version 07-09-90\nC--------------------------------------------------------------------\n\tSUBROUTINE TEST_POLYFIT\nC\tPROGRAM TEST_POLYFIT\n\tPARAMETER(IDIM=50,NNMAX=50)\n\tREAL*8 XX(IDIM),YY(IDIM)\n\tREAL*8 A(NNMAX,NNMAX),B(NNMAX),C(NNMAX)\n\tREAL*8 XC(20),SDEV(20),ERR\n\tINTEGER*4 NPTS\n\t\t\n\tPRINT *,' First test:'\n\tPRINT *,' x1 + x2 + x3 = 1'\n\tPRINT *,' x1 + x2 + 2x3 = 2'\n\tPRINT *,' x1 + 2x2 + 2x3 = 1'\n\tA(1,1)=1.\n\tA(2,1)=1.\n\tA(3,1)=1.\n\tA(1,2)=1.\n\tA(2,2)=1.\n\tA(3,2)=2.\n\tA(1,3)=1.\n\tA(2,3)=2.\n\tA(3,3)=2.\n\n\tC(1)=1.\n\tC(2)=2.\n\tC(3)=1.\n\n\tNN=3\n\tIFAIL=-1\n\tCALL JLP_INVMAT(A,B,C,NN,NNMAX,IFAIL)\n\n\tPRINT *,' IFAIL=',IFAIL,' Solution should be: 1 -1 1'\n\tPRINT *,' B:',B(1),B(2),B(3)\n\n\tPRINT *,' Second test:'\n\tPRINT *,' x1 + x2 + x3 = 1'\n\tPRINT *,' 0.0001x2 + x3 = 1'\n\tPRINT *,' 9999.x3 = 10000.'\n\tA(1,1)=1.\n\tA(2,1)=1.\n\tA(3,1)=1.\n\tA(1,2)=0.\n\tA(2,2)=0.0001\n\tA(3,2)=1.\n\tA(1,3)=0.\n\tA(2,3)=0.\n\tA(3,3)=9999.\n\n\tC(1)=1.\n\tC(2)=1.\n\tC(3)=10000.\n\n\tNN=3\n\tIFAIL=-1\n\tCALL JLP_INVMAT(A,B,C,NN,NNMAX,IFAIL)\n\n\tPRINT *,' IFAIL=',IFAIL,' Solution should be: 1 -1 1'\n\tPRINT *,' B:',B(1),B(2),B(3)\n\n\tPRINT *,' Test of msq: C0 + C1 X (0.5+X) '\n\tXX(1)=1.\n\tYY(1)=1.5\n\tXX(2)=3.\n\tYY(2)=3.5\n\tXX(3)=4.\n\tYY(3)=4.5\n\tXX(4)=6.\n\tYY(4)=6.5\n\tXX(5)=7.\n\tYY(5)=7.5\n\n\tNPTS=5\n\tKK=1\n\tCALL POLYFIT(XX,YY,NPTS,KK,XC,SDEV,ERR)\n\tPRINT *,' IFAIL=',IFAIL,' Solution should be: 0.5 1.00'\n\tPRINT *,' XC: ',XC(1),XC(2)\n\n\tNPTS=5\n\tKK=2\n\tCALL POLYFIT(XX,YY,NPTS,KK,XC,SDEV,ERR)\n\tPRINT *,' IFAIL=',IFAIL,' Solution should be: 0.5 1.00 0.00'\n\tPRINT *,' XC: ',XC(1),XC(2),XC(3)\n\n\tPRINT *,' Test of msq: C0 + C1 X + C2 X**2 0+X-X**2'\n\tXX(1)=0.\n\tYY(1)=0.\n\tXX(2)=1.\n\tYY(2)=0.\n\tXX(3)=2.\n\tYY(3)=-2.\n\tXX(4)=3.\n\tYY(4)=-6.\n\tXX(5)=4.\n\tYY(5)=-12.\n\n\tNPTS=5\n\tKK=2\n\tCALL POLYFIT(XX,YY,NPTS,KK,XC,SDEV,ERR)\n\tPRINT *,' IFAIL=',IFAIL,' Solution should be: 0. 1. -1.'\n\tPRINT *,' XC: ',XC(1),XC(2),XC(3)\n\n\tRETURN\n\tEND\n\nC***************************************************************************\t\nC Subroutine POLYFIT(XX,YY,NPTS,KK,XC,SDEV,ERR)\nC YY = poly(XX)\nC\nC KK: Order of the polynomial\nC M : This integer variable contains the number of residuals.\nC N : This integer variable contains the number of variables. With M >= N.\nC XX and YY : arrays to be fitted by a polynomial\nC\t\t\t\t\nC XC : Array containing the parameters which we are minimizing with respect to.\nC XC(I) is the coeff. of X**(I-1) (REAL*8)\nC SDEV : standard deviation for the coeff XC(I) (REAL*8).\nC ERR : mean deviation of the fit (REAL*8)\nC\nC FSUMSQ : sum of the squares of the final point.\nC***************************************************************************\t\n\tSUBROUTINE POLYFIT(XX,YY,NPTS,KK,XC,SDEV,ERR)\n\tPARAMETER(IDIM=500,NNMAX=50)\n\tREAL*8 XX(*),YY(*),XC(20),SDEV(20)\n\tREAL*8 XX1(IDIM,20),FSUMSQ,YVAL,ERR\n\tREAL*8 A(NNMAX,NNMAX),B(NNMAX),C(NNMAX),SCALE\n\tINTEGER*4 PNTR1\n\tCHARACTER ANS*1\n \n10\tFORMAT(A)\n \n\tIF(NPTS.LE.KK)THEN\n\t WRITE(6,32) NPTS,KK\n32 FORMAT(' Fatal error in polyfit : too few points for the fit',\n 1 /,' npoints = ',I5,' whereas polynomial order = ',I3)\n\t STOP\n\tENDIF\n\n\tIF(NPTS.GT.IDIM)THEN\n\t WRITE(6,33) NPTS,IDIM\n33 FORMAT(' Fatal error in polyfit : too many points for the fit',\n 1 /,' npoints = ',I8,' whereas idim = ',I8)\n\t STOP\n\tENDIF\n\nC Normalization of XX to avoid integer overflow:\n\tSCALE=1.\n\tDO I=1,NPTS\n\t SCALE=MAX(ABS(XX(I)),SCALE)\n\tEND DO\nC\n\tDO I=1,NPTS\n\t XX(I)=XX(I)/SCALE\n\tEND DO\n\tPRINT *,' POLYFIT/ Internal X scale:',SCALE\n\nC Preparing the array of the powers:\n\tNN=KK+1\n\tCALL JLP_PREPPW(XX,NPTS,XX1,IDIM,KK,ISTATUS)\n\tIF(ISTATUS.NE.0)THEN\n\t PRINT *,' Fatal error in polyfit : order is too big'\n\t STOP\n\tENDIF\n\nC Computing the coefficients of the normal equations:\n\tDO J=1,NN\nC C vector:\n\t C(J)=0.\n\t DO L=1,NPTS\n\t C(J)=C(J)+YY(L)*XX1(L,J)\n\t END DO\nC A matrix (symmetrical)\n\t DO I=1,J\n\t A(I,J)=0.\n\t DO L=1,NPTS\n\t A(I,J)=A(I,J)+XX1(L,J)*XX1(L,I)\n\t END DO\n\t END DO\n\tEND DO\n\nC A matrix (symmetrical)\n\tDO J=1,NN\n\t DO I=J+1,NN\n\t A(I,J)=A(J,I)\n\t END DO\n\tEND DO\n\nC Inversion of a matrix with pivotal elements:\n\tIFAIL=0\n\tCALL JLP_INVMAT(A,B,C,NN,NNMAX,IFAIL)\n\nC Transfer, taking SCALE into account:\n\tXC(1)=B(1)\n\tDO K=2,KK+1\n\t XC(K)=B(K)/(SCALE**(K-1))\n\tEND DO\t\n\nC Errors:\t\n\tFSUMSQ=0.\n\tDO L=1,NPTS\nC Going back to the initial value of XX:\n\t XX(L)=XX(L)*SCALE\n\t CALL CALPOLY(XX(L),YVAL,XC,KK)\n\t FSUMSQ=FSUMSQ+(YVAL-YY(L))*(YVAL-YY(L))\n\tEND DO\n\tFSUMSQ=FSUMSQ/FLOAT(NPTS)\n\tERR=SQRT(FSUMSQ)/FLOAT(KK+1)\n\n\tRETURN\n\tEND\nC***********************************************************************\nC Preparing the array of the powers:\nC***********************************************************************\n\tSUBROUTINE JLP_PREPPW(XX,NPTS,XX1,IDIM,KK,ISTATUS)\n\tREAL*8 XX(NPTS),XX1(IDIM,*)\n\tINTEGER*4 ISTATUS\n\nC To start the process:\n\t DO I=1,NPTS\n\t XX1(I,1)=1.\n\t END DO\n\n\tDO K=2,KK+1\n\t DO I=1,NPTS\n\t XX1(I,K)=XX1(I,K-1)*XX(I)\nC Check if there is a risk of overflow:\nC (Will be squared in A matrix):\n\t IF(ABS(XX1(I,K)).GT.1.E+18)THEN\n\t WRITE(6,*)' POLYFIT/Error: overflow'\n\t ISTATUS=1\n\t RETURN\n\t ENDIF\n\t END DO\n\tEND DO\n\n\tISTATUS=0\n\tRETURN\n\tEND\nC***********************************************************************\nC JLP_INVMAT\nC Inversion of a matrix with pivotal elements:\nC AB=C\nC\nC***********************************************************************\n\tSUBROUTINE JLP_INVMAT(A,B,C,NN,NNMAX,IFAIL)\n\tREAL*8 A(NNMAX,NNMAX),B(NNMAX),C(NNMAX),AA,APIVOT,EPSILON\n\n\tEPSILON=1.E-12\n\nC------------------\nC FIRST STEP\nC Loop on the rows, to obtain a triangular matrix:\n\tDO J=1,NN\n\nC Partial pivoting: look for the biggest coefficient:\n\t JPIVOT=J\n\t DO JJ=J+1,NN\n\t IF(ABS(A(J,JJ)).GT.ABS(A(J,JPIVOT)))THEN\n\t JPIVOT=JJ\n\t ENDIF\n\t END DO\n\nC When found, interchange rows JPIVOT and J:\n\tIF(JPIVOT.NE.J) CALL INTERCH(A,C,NN,NNMAX,JPIVOT,J)\n\nC After this, test if pivotal element is too small:\n\tIF(ABS(A(J,J)).LT.EPSILON)THEN\n\t WRITE(6,23)\n23\t FORMAT(' JLP_INVMAT/Pivotal element too small')\n\t IF(IFAIL.NE.-1)THEN\n\t WRITE(6,24)\n24\t FORMAT(' JLP_INVMAT/Fatal error')\n\t STOP\n\t ELSE\n\t IFAIL=2\n\t RETURN\n\t ENDIF\n\tENDIF\n\nC When OK, divide all the coefficients of this row by the pivot:\n\tAPIVOT=A(J,J)\n\tDO I=J,NN\n\t A(I,J)=A(I,J)/APIVOT\n\tEND DO\n\tC(J)=C(J)/APIVOT\n\nC Then subtract this row to all the following rows (to obtain a triangular\nC matrix in the end...)\n\tDO JJ=J+1,NN\n\t AA=A(J,JJ)\n\t IF(ABS(AA).GT.EPSILON)THEN\n\t DO I=J,NN\n\t A(I,JJ)=A(I,JJ)/AA-A(I,J)\n\t END DO\n\t C(JJ)=C(JJ)/AA-C(J)\n\t ENDIF\n\tEND DO\n\n\tEND DO\n\nC------------------\nC SECOND STEP\nC Inverse triangular matrix with all pivotal elements equal to 1. :\n\tDO J=NN,1,-1\n\t B(J)=C(J)\n\t DO I=NN,J+1,-1\n\t B(J)=B(J)-A(I,J)*B(I)\n\t END DO\n\tEND DO\n\n\n\tIFAIL=0\n\tRETURN\n\tEND\nC*************************************************************\n\tSUBROUTINE INTERCH(A,C,NN,NNMAX,JNEW,JOLD)\n\tREAL*8 A(NNMAX,NNMAX),AA\n\tREAL*8 C(NNMAX),CC\n\n\tDO I=1,NN\n\t AA=A(I,JNEW)\n\t A(I,JNEW)=A(I,JOLD)\n\t A(I,JOLD)=AA\n\tEND DO\n\n\tCC=C(JNEW)\n\tC(JNEW)=C(JOLD)\n\tC(JOLD)=CC\n\n\tRETURN\n\tEND\nC*************************************************************\nC Y = poly(X)\nC*************************************************************\n\tSUBROUTINE CALPOLY(X,Y,XC,KDEGREE)\nC For real*8\n\tREAL*8 X,Y\n\tREAL*8 XC(KDEGREE+1)\n\tY=XC(1)\n\tWORK=1.\n \n\tDO I=2,KDEGREE+1\n\tWORK=WORK*X\n\tY=Y+WORK*XC(I)\n\tEND DO\n \n\tRETURN\n\tEND\n", "meta": {"hexsha": "a03199279f75e156387ab2c3902b688410093731", "size": 7604, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "jlpsub/polyfit.for", "max_stars_repo_name": "jlprieur/shell_galaxies", "max_stars_repo_head_hexsha": "1dde87ef33b3c33b3a892e9ad0d642ae02ac6d9e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "jlpsub/polyfit.for", "max_issues_repo_name": "jlprieur/shell_galaxies", "max_issues_repo_head_hexsha": "1dde87ef33b3c33b3a892e9ad0d642ae02ac6d9e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "jlpsub/polyfit.for", "max_forks_repo_name": "jlprieur/shell_galaxies", "max_forks_repo_head_hexsha": "1dde87ef33b3c33b3a892e9ad0d642ae02ac6d9e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.0637119114, "max_line_length": 79, "alphanum_fraction": 0.5561546554, "num_tokens": 2976, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110540642805, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6858742568820528}} {"text": "c program DRCGEFSC\nc>> 2001-05-22 DRCGEFSC Krogh Minor change for making .f90 version.\nc>> 1992-03-18 CLL Declaring all integers.\nc>> 1988-05-11 DRCGEFSC Lawson Initial Code.\nc Demo driver for CGEFSC. Solution of square nonsingular system\nc of linear equations having complex elements.\nc S. Y. Chiu, JPL, 1987. C. L. Lawson, JPL, May 1988.\nc ------------------------------------------------------------------\n integer I, J, NMAX\n parameter (NMAX=3)\n complex A(3,3), B(3,1), Z(NMAX)\n real RCOND\n integer IPVT(NMAX)\n data (A(1,J),J=1,3) / (0.579E0,0.735E0), (0.394E0,0.537E0),\n * (0.915E0,0.143E0) /\n data (A(2,J),J=1,3) / (0.795E0,0.430E0), (0.226E0,0.384E0),\n * (0.868E0,0.494E0) /\n data (A(3,J),J=1,3) / (0.141E0,0.207E0), (0.329E0,0.635E0),\n * (0.286E0,0.971E0) /\n data (B(I,1),I=1,3) / (-2.405E0,-4.735E0), (3.87E0,-3.08E0),\n * (4.231E0,-0.213E0) /\nc ------------------------------------------------------------------\n call CGEFSC(A,NMAX,NMAX,B,NMAX,1,IPVT,RCOND,Z)\n print*,'DRCGEFSC.. Demo driver for CGEFSC.'\n print*,'True solution is (2,4), (-5,5), (3,-9)'\n print*,'Computed solution:'\n do 40 I = 1,3\n print 100, I, B(I,1)\n 40 continue\n print '(1x/1x,a,f7.4)','RCOND = ', RCOND\n 100 format(1x,'X(',I1,') =',' (',g15.8,',',g15.8,')')\n end\n", "meta": {"hexsha": "59a99a764e5ca00db4d3cdcdbca19326ed39880a", "size": 1474, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drcgefsc.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drcgefsc.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drcgefsc.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": 44.6666666667, "max_line_length": 72, "alphanum_fraction": 0.4755766621, "num_tokens": 568, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379296, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6858742502476968}} {"text": "!!----------------------------\n!!\treturns the root of the function func\n!!\ttaken from Numerical Recipes\n!!----------------------------\n\tMODULE DM_num\n\n\tcontains\n\n\n\tFUNCTION zbrent(func,x1,x2,tol)\n\tUSE nrtype; USE nrutil, ONLY : nrerror\n\tIMPLICIT NONE\n\tREAL(DP), INTENT(IN) :: x1,x2,tol\n\tREAL(DP), DIMENSION(4) :: zbrent ! = [ Tx1, emom1, Tx2, emom2 ], Tx1 is the best root\n\tINTERFACE\n\t\tFUNCTION func(x)\n\t\tUSE nrtype\n\t\tIMPLICIT NONE\n\t\tREAL(DP), INTENT(IN) :: x\n\t\tREAL(DP) :: func\n\t\tEND FUNCTION func\n\tEND INTERFACE\n\tINTEGER(I4B), PARAMETER :: ITMAX=100\n\tREAL(DP), PARAMETER :: EPS=epsilon(x1)\n\tINTEGER(I4B) :: iter\n\tREAL(DP) :: a,b,c,d,e,fa,fb,fc,p,q,r,s,tol1,xm\n\ta=x1\n\tb=x2\n\tfa=func(a)\n\tfb=func(b)\n\tif ((fa > 0.0 .and. fb > 0.0) .or. (fa < 0.0 .and. fb < 0.0)) THEN\n!\t\tcall nrerror('root must be bracketed for zbrent')\n!\t\tinstead of exiting run, increase lower limit and try again\n\t\tzbrent = [-1.0D0, 0.0D0, 0.0D0, 0.0D0]\n\t\tRETURN\n\tENDIF\n\tc=b\n\tfc=fb\n\tdo iter=1,ITMAX\n\t\tif ((fb > 0.0 .and. fc > 0.0) .or. (fb < 0.0 .and. fc < 0.0)) then\n\t\t\tc=a\n\t\t\tfc=fa\n\t\t\td=b-a\n\t\t\te=d\n\t\tend if\n\t\tif (abs(fc) < abs(fb)) then\n\t\t\ta=b\n\t\t\tb=c\n\t\t\tc=a\n\t\t\tfa=fb\n\t\t\tfb=fc\n\t\t\tfc=fa\n\t\tend if\n\t\ttol1=2.0_dp*EPS*abs(b)+0.5_dp*tol\n\t\txm=0.5_dp*(c-b)\n\t\tif (abs(xm) <= tol1 .or. fb == 0.0) then\n\t\t\t! Root (b) has been found.\n\t\t\t! Return this root plus the root from the other interval\n\t\t\t! (and both function evaluations).\n\t\t\t! This will be a or c depending on the signs of fa, fb, and fc.\n\t\t\t! The second root will be used to approximate the emoment\n\t\t\t! equation with a straight line so that a more accurate\n\t\t\t! root can be found when the extra energy is \"too high\".\n\t\t\tIF ( SIGN(1.0D0,fb) .EQ. -SIGN(1.0D0,fa) ) THEN\n\t\t\t\tzbrent = [b, fb, a, fa]\n\t\t\tELSE IF ( SIGN(1.0D0,fb) .EQ. -SIGN(1.0D0,fc) ) THEN\n\t\t\t\tzbrent = [b, fb, c, fc]\n\t\t\tELSE\n\t\t\t\tWRITE(*,*) \"---***--- ALL ZBRENT ROOTS HAVE THE SAME SIGN ---***---\"\n\t\t\t\tIF ( ABS(fa) .LT. ABS(fc) ) THEN\n\t\t\t\t\tzbrent = [b, fb, a, fa]\n\t\t\t\tELSE\n\t\t\t\t\tzbrent = [b, fb, c, fc]\n\t\t\t\tEND IF\n\t\t\tEND IF\n\t\t\t! zbrent=b\n\t\t\tRETURN\n\t\tend if\n\t\tif (abs(e) >= tol1 .and. abs(fa) > abs(fb)) then\n\t\t\ts=fb/fa\n\t\t\tif (a == c) then\n\t\t\t\tp=2.0_dp*xm*s\n\t\t\t\tq=1.0_dp-s\n\t\t\telse\n\t\t\t\tq=fa/fc\n\t\t\t\tr=fb/fc\n\t\t\t\tp=s*(2.0_dp*xm*q*(q-r)-(b-a)*(r-1.0_dp))\n\t\t\t\tq=(q-1.0_dp)*(r-1.0_dp)*(s-1.0_dp)\n\t\t\tend if\n\t\t\tif (p > 0.0) q=-q\n\t\t\tp=abs(p)\n\t\t\tif (2.0_dp*p < min(3.0_dp*xm*q-abs(tol1*q),abs(e*q))) then\n\t\t\t\te=d\n\t\t\t\td=p/q\n\t\t\telse\n\t\t\t\td=xm\n\t\t\t\te=d\n\t\t\tend if\n\t\telse\n\t\t\td=xm\n\t\t\te=d\n\t\tend if\n\t\ta=b\n\t\tfa=fb\n\t\tb=b+merge(d,sign(tol1,xm), abs(d) > tol1 )\n\t\tfb=func(b)\n\tend do\n\tcall nrerror('zbrent: exceeded maximum iterations')\n\tzbrent=[b, 0.0D0, 0.0D0, 0.0D0]\n\tEND FUNCTION zbrent\n\n\tEND MODULE DM_num\n", "meta": {"hexsha": "771767513bd0f8d5ddb0179d8d7d07b1a38e845e", "size": 2668, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/DM/DM_num.f90", "max_stars_repo_name": "troyraen/mesa_wimps", "max_stars_repo_head_hexsha": "6d1a8b3d1ce94ef1ded7214b980ca8861cb52596", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-10-12T07:59:30.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-02T06:07:22.000Z", "max_issues_repo_path": "src/DM/DM_num.f90", "max_issues_repo_name": "troyraen/mesa_wimps", "max_issues_repo_head_hexsha": "6d1a8b3d1ce94ef1ded7214b980ca8861cb52596", "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/DM/DM_num.f90", "max_forks_repo_name": "troyraen/mesa_wimps", "max_forks_repo_head_hexsha": "6d1a8b3d1ce94ef1ded7214b980ca8861cb52596", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.610619469, "max_line_length": 87, "alphanum_fraction": 0.5715892054, "num_tokens": 1147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110368115783, "lm_q2_score": 0.7690802370707283, "lm_q1q2_score": 0.6858742436133406}} {"text": "program ch1302\n ! Date Calculation\n implicit none\n\n integer :: year, month, day\n integer :: n, t\n\n print *, 'year, followed by day within year'\n read *, year, n\n if (mod(year,4)/=0) then\n t = 0\n elseif (mod(year,100)/=0) then\n t = 1\n elseif (mod(year,400)/=0) then\n t = 0\n else\n t = 1\n end if\n if (n>59+t) then\n day = n+2-t\n else\n day = n\n end if\n month = (day+91)*100/3055\n day = (day+91)-(month*3055)/100\n month = month-2\n print *, 'calendar date is ', day, month, year\nend program\n", "meta": {"hexsha": "9ef41246df0f04a7c041b7b208ad668d80d694ea", "size": 580, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ch13/ch1302.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/ch1302.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/ch1302.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.0, "max_line_length": 50, "alphanum_fraction": 0.5189655172, "num_tokens": 201, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110396870288, "lm_q2_score": 0.7690802317779601, "lm_q1q2_score": 0.6858742411046437}} {"text": "! Copyright 2015 Andrew Dawson, Peter Dueben\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 implied.\n! See the License for the specific language governing permissions and\n! limitations under the License.\n\nPROGRAM lorenz63\n! A reference double-precision Lorenz '63 model.\n!\n\n IMPLICIT NONE\n \n INTEGER, PARAMETER :: REAL_KIND = kind(1.0d0)\n\n ! Time-stepping parameters.\n REAL(KIND=REAL_KIND) :: t\n REAL(KIND=REAL_KIND) :: time_start = 0\n REAL(KIND=REAL_KIND) :: time_stop = 5\n REAL(KIND=REAL_KIND) :: dt = 0.01\n \n ! Lorenz 63 system parameters.\n REAL(KIND=REAL_KIND) :: sigma\n REAL(KIND=REAL_KIND) :: rho\n REAL(KIND=REAL_KIND) :: beta\n \n ! Array to store the 3d coordinate of the current system state.\n REAL(KIND=REAL_KIND), DIMENSION(3) :: x\n\n ! Runge-Kutta parameters.\n REAL(KIND=REAL_KIND), DIMENSION(3) :: k1, k2, k3, k4\n\n ! Set the model parameters.\n sigma = 10\n rho = 28\n beta = 8.0_REAL_KIND / 3.0_REAL_KIND\n\n ! Set the initial state.\n t = time_start\n x = (/ 1.508870_REAL_KIND, -1.531271_REAL_KIND, 25.46091_REAL_KIND /)\n \n ! Loop over time evaluating the model state (x).\n WRITE (*, '(F19.15, \" \", F19.15, \" \", F19.15)') x\n DO WHILE (t <= time_stop)\n k1 = f(x, sigma, rho, beta)\n k2 = f(x + 0.5_REAL_KIND * dt * k1, sigma, rho, beta)\n k3 = f(x + 0.5_REAL_KIND * dt * k2, sigma, rho, beta)\n k4 = f(x + dt * k3, sigma, rho, beta)\n x = x + dt * (k1 + 2 * (k2 + k3) + k4) / 6.0_REAL_KIND\n t = t + dt\n WRITE (*, '(F19.15, \" \", F19.15, \" \", F19.15)') x\n END DO\n\nCONTAINS\n\n FUNCTION f (x, sigma, rho, beta)\n ! Update the Runge-Kutta parameters.\n !\n IMPLICIT NONE\n REAL(KIND=REAL_KIND), DIMENSION(3), INTENT(IN) :: x\n REAL(KIND=REAL_KIND), INTENT(IN) :: sigma\n REAL(KIND=REAL_KIND), INTENT(IN) :: rho\n REAL(KIND=REAL_KIND), INTENT(IN) :: beta\n REAL(KIND=REAL_KIND), DIMENSION(3) :: f\n f = (/ sigma * (x(2) - x(1)), &\n x(1) * (rho - x(3)) - x(2), &\n x(1) * x(2) - beta * x(3) /)\n END FUNCTION f\n\nEND PROGRAM\n", "meta": {"hexsha": "25424239d5eb949dcbb48364c42ca365990fc2ca", "size": 2575, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/integration/lorenz63/l63_reference.f90", "max_stars_repo_name": "sparonuz/rpe", "max_stars_repo_head_hexsha": "017189986a9653691ecc1c531e53d528d3ccbbb7", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2016-01-09T23:22:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-14T23:44:37.000Z", "max_issues_repo_path": "test/integration/lorenz63/l63_reference.f90", "max_issues_repo_name": "sparonuz/rpe", "max_issues_repo_head_hexsha": "017189986a9653691ecc1c531e53d528d3ccbbb7", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 12, "max_issues_repo_issues_event_min_datetime": "2016-01-06T14:08:39.000Z", "max_issues_repo_issues_event_max_datetime": "2017-02-15T15:19:03.000Z", "max_forks_repo_path": "test/integration/lorenz63/l63_reference.f90", "max_forks_repo_name": "sparonuz/rpe", "max_forks_repo_head_hexsha": "017189986a9653691ecc1c531e53d528d3ccbbb7", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2016-01-11T16:55:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-03T13:51:29.000Z", "avg_line_length": 33.0128205128, "max_line_length": 74, "alphanum_fraction": 0.5945631068, "num_tokens": 807, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110368115781, "lm_q2_score": 0.7690802317779601, "lm_q1q2_score": 0.6858742388931914}} {"text": "subroutine getnorm(v1,v2,mn,norm)\n implicit none\n\n integer :: i,mn\n real(8) :: v1(mn),v2(mn),norm\n\n norm = 0.0\n do i=1,mn\n norm = norm + v1(i)*v2(i)\n enddo\n\n return\nend\n", "meta": {"hexsha": "d1d4d5a018b37e87633ec8dfc54fed526ae627a9", "size": 181, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "norm.f90", "max_stars_repo_name": "biofluids/IFEM-archive", "max_stars_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-15T11:40:16.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-15T11:40:16.000Z", "max_issues_repo_path": "norm.f90", "max_issues_repo_name": "biofluids/IFEM-archive", "max_issues_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "norm.f90", "max_forks_repo_name": "biofluids/IFEM-archive", "max_forks_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-02-11T16:50:21.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-08T07:24:59.000Z", "avg_line_length": 12.9285714286, "max_line_length": 33, "alphanum_fraction": 0.5856353591, "num_tokens": 81, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8539127529517043, "lm_q2_score": 0.8031738034238806, "lm_q1q2_score": 0.6858403535803769}} {"text": "subroutine phasefield_init(meqn,mbc,mx,my, & \n xlower,ylower,dx,dy,q)\n implicit none\n\n integer meqn,mbc,mx,my\n double precision xlower, ylower,dx,dy\n\n double precision q(1-mbc:mx+mbc, 1-mbc:my+mbc, meqn)\n\n integer i,j\n double precision xlow, ylow, w\n\n do j = 1-mbc,my+mbc\n do i = 1-mbc,mx+mbc\n xlow = xlower + (i-1)*dx\n ylow = ylower + (j-1)*dy\n\n call cellave(xlow,ylow,dx,dy,w)\n q(i,j,1) = w-1.d0\n q(i,j,2) = 1-w\n enddo\n enddo\n\n return\nend subroutine phasefield_init\n\n\ndouble precision function fdisc(x,y)\n implicit none\n\n double precision x,y\n\n DOUBLE PRECISION S, alpha, m, xi, k, gamma\n COMMON /comm_parms/ S, alpha, m, xi, k, gamma\n\n DOUBLE PRECISION r0, x0, y0\n COMMON /comm_init/ r0, x0, y0\n\n double precision r, rp, theta\n\n r = sqrt((x-x0)**2 + (y-y0)**2)\n theta = atan2(y - y0,x - x0)\n rp = r0*(1.d0 + gamma*cos(k*theta))\n fdisc = r - rp\n\nend function fdisc\n\n", "meta": {"hexsha": "073abe534e1a096492e0bba8a32dca8a0d0c4f42", "size": 1006, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "applications/elliptic/phasefield/fortran/phasefield_qinit.f90", "max_stars_repo_name": "ForestClaw/ForestClaw", "max_stars_repo_head_hexsha": "c81095f3e525f99cfb771c9049e9d272eb12d4cb", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "applications/elliptic/phasefield/fortran/phasefield_qinit.f90", "max_issues_repo_name": "ForestClaw/ForestClaw", "max_issues_repo_head_hexsha": "c81095f3e525f99cfb771c9049e9d272eb12d4cb", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-08-02T09:52:43.000Z", "max_issues_repo_issues_event_max_datetime": "2017-08-02T14:16:23.000Z", "max_forks_repo_path": "applications/elliptic/phasefield/fortran/phasefield_qinit.f90", "max_forks_repo_name": "ForestClaw/ForestClaw", "max_forks_repo_head_hexsha": "c81095f3e525f99cfb771c9049e9d272eb12d4cb", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.9583333333, "max_line_length": 56, "alphanum_fraction": 0.5745526839, "num_tokens": 367, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517043, "lm_q2_score": 0.8031738034238806, "lm_q1q2_score": 0.6858403535803769}} {"text": "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nmodule constant_values\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nimplicit none\n\ninteger,parameter\t\t:: n_max = 1000\ninteger,parameter\t\t:: m_max = 10\n\nreal(4),parameter\t\t:: x_min = 0.0\nreal(4),parameter\t\t:: x_max = 1.0\nreal(8),parameter \t\t:: dx = (x_max -x_min)/dble(m_max)\t!! \u7a7a\u9593\u523b\u307f\u5e45\nreal(8),parameter \t\t:: dt = 1.0/dble(n_max)\t\t\t\t\t\t!! \u6642\u9593\u523b\u307f\u5e45\n\nreal(4),parameter\t\t:: kappa = 0.5\t!! \u62e1\u6563\u4fc2\u6570\n\nend module constant_values\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nmodule set_functions\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\ncontains\n\nend module set_functions\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nprogram main\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\nuse constant_values\nuse set_functions\n\nimplicit none\n\ninteger\t\t\t\t\t\t\t\t\t\t:: i\ninteger\t\t\t\t\t\t\t\t\t\t:: j\nreal,dimension(0:m_max)\t\t:: u\nreal,dimension(0:m_max)\t\t:: x\nreal,dimension(0:n_max)\t\t\t:: t\ncharacter(len=50) :: filename\ncharacter(len=50) :: tmp\nreal lambda\n\nlambda = kappa * (dt/(dx**2))\t!! \u523b\u307f\u5e45\u5b9a\u6570\n \nu(0) = 0.0\nu(m_max) = 0.0\n\ndo i = 0, m_max\n x(i) = dx * i\nend do\n\nif (lambda <= 0.5) then\n\t\n\tfilename='diffusion_0.dat'\n\topen(9, file = filename, status=\"replace\")\n\t\n\tcall get_ICs(u)\n\t\n\tdo i = 0, m_max\n\t\twrite(9,*) x(i), u(i)\n\tend do\n\n\tclose(9)\n\t\n\tdo j = 1, n_max+1\n\t\tt = dt * j\n\t\tcall calculation_unew(u)\n\t\tif (mod(j,10)==0) then\n\t\t\twrite(tmp,'(i4)') j \n\t\t\tfilename='diffusion_'//trim(adjustl(tmp))//'.dat'\n\t\t\topen(10, file = filename, status=\"replace\")\n\t\t\t\n\t\t\tdo i = 0, m_max\n\t\t\t\twrite(10,*) x(i), u(i)\n\t\t\tend do\n\t\t\n\t\t\tclose(10)\n\t\t\n\t\tend if\n\tend do\n\nelse\n\twrite(*,*) \"\u3053\u306e\u62e1\u6563\u6570\u306f Von Neumann \u306e\u5b89\u5b9a\u6761\u4ef6\u3092\u6e80\u305f\u3057\u3066\u3044\u306a\u3044.\"\n\nend if\n\nstop\nend program main\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine get_ICs(u)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nuse constant_values\nuse set_functions\n\nimplicit none\ninteger\t\t\t\t\t\t\t\t\t:: i\nreal\t\t\t\t\t\t\t\t\t\t:: x\nreal,dimension(0:m_max)\t:: u\n\n\ndo i = 1, m_max-1\n\tx = dx * i\n\t\n\tif (x >= 0.25 .and. x < 0.75) then\n\t\tu(i) = 1.0\n\telse \n\t\tu(i) = 0.0\n\tend if\n\nend do\n\n\nend subroutine get_ICs\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine calculation_unew(u)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nuse constant_values\nuse set_functions\n\nimplicit none\ninteger\t\t\t \t\t\t\t\t\t:: i\nreal,dimension(0:m_max)\t:: u\nreal,dimension(0:m_max)\t:: u_old\nreal lambda\n\nlambda = kappa * (dt/(dx**2))\t!! \u523b\u307f\u5e45\u5b9a\u6570\n\ndo i = 0, m_max\n\tu_old(i) = u(i)\nend do\n\ndo i = 1, m_max-1\n\tu(i) = u_old(i) + lambda * (u_old(i+1) - 2*u_old(i) + u_old(i-1))\nend do\n\n\nend subroutine calculation_unew\n", "meta": {"hexsha": "842ff57412ac71b9503b70f134f663c689cc3b5a", "size": 3061, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "diffusion/PDE_diffusion.f90", "max_stars_repo_name": "Loschmidt-constant/Physics-Simulation", "max_stars_repo_head_hexsha": "604632ddae9785998ddeb4497634d62035ff11f3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "diffusion/PDE_diffusion.f90", "max_issues_repo_name": "Loschmidt-constant/Physics-Simulation", "max_issues_repo_head_hexsha": "604632ddae9785998ddeb4497634d62035ff11f3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "diffusion/PDE_diffusion.f90", "max_forks_repo_name": "Loschmidt-constant/Physics-Simulation", "max_forks_repo_head_hexsha": "604632ddae9785998ddeb4497634d62035ff11f3", "max_forks_repo_licenses": ["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.2569444444, "max_line_length": 99, "alphanum_fraction": 0.4214309049, "num_tokens": 930, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127455162773, "lm_q2_score": 0.803173801068221, "lm_q1q2_score": 0.6858403455969089}} {"text": "module types\n implicit none\n\n integer, parameter:: dp=kind(0.d0)\nend module\n\n\n\n!==============================================================================\n! interpolation function\n!==============================================================================\nmodule interp\n implicit none\n\n contains\n\n\n subroutine idxsearch(ar1, ar2, k1, k2, idx)\n ! =====================================================\n ! Called by linear_interp\n ! ar1 and ar2 assumed to be monotonically decreasing or increasing\n ! idx(k) means ar2(k) is between ar1(k) and ar1(k+1)\n ! idx(k) = 0 or size(ar1) indicates ar2(k) is outside the range of ar1\n ! =====================================================\n use types\n integer,intent(in) :: k1, k2\n real(dp), intent(in) :: ar1(k1) !sequence value to search\n real(dp), intent(in) :: ar2(k2) !set of value to serach for\n integer, intent(out) :: idx(k2) !interval locations\n\n integer :: i, j\n real(dp) :: val\n\n if (ar1(1) < ar1(k1)) then\n !monotonically increasing case\n do i = 1, k2\n val = ar2(i)\n if (val <= ar1(1)) then\n idx(i) = 0\n cycle\n else if ( val >= ar1(k1)) then\n idx(i) = k1\n cycle\n end if\n do j = 1, k1-1\n if (val <= ar1(j+1)) then\n idx(i) = j\n exit\n end if\n end do\n end do\n else\n !monotonically decreasing case\n do i = 1, k2\n val = ar2(i)\n if (val >= ar1(1)) then\n idx(i) = 0\n cycle\n else if ( val <= ar1(k1)) then\n idx(i) = k1\n cycle\n end if\n do j = 1, k1-1\n if (val >= ar1(j+1)) then\n idx(i) = j\n exit\n end if\n end do\n end do\n end if\n end subroutine idxsearch\n\n\n subroutine linear_interp(in,zin,zout,xnin,znin,znout,out)\n ! =====================================================\n ! 2D vertical linear interpolation.\n ! in : (xnin, znin) values used for interpolation.\n ! zin : vertical coordinates for in array.\n ! zout : vertical levels which interpolating applied.\n ! xnin,znin,znout : dimensions for in, zin and zout.\n ! =====================================================\n use types\n integer, intent(in) :: xnin, znin, znout\n real(dp), intent(in) :: in(xnin,znin), zin(xnin,znin), zout(znout)\n real(dp), intent(out) :: out(xnin,znout)\n\n !f2py intent(in) :: in, zin, zout\n !f2py intent(out) :: out\n\n integer idx(znout)\n real(dp) :: a, x(znin), y(znin)\n integer :: i, j, jo\n\n do i = 1, xnin\n x = zin(i,:)\n y = in(i,:)\n call idxsearch(x, zout, znin, znout, idx)\n do j = 1, znout\n jo = idx(j)\n if (jo == 0) then ! outside of bottom level is constant\n out(i,j) = y(1)\n else if (jo == znin) then !outside of top level is constant\n out(i,j) = y(znin)\n else !linear interpolation\n a = (y(jo+1) - y(jo))/(x(jo+1) - x(jo))\n out(i,j) = a*(zout(j) - x(jo)) + y(jo)\n end if\n end do\n end do\n end subroutine linear_interp\n\n\n function binarysearch(length, array, value, delta)\n ! Given an array and a value, returns the index of the element that\n ! is closest to, but less than, the given value.\n ! Uses a binary search algorithm.\n ! \"delta\" is the tolerance used to determine if two values are equal\n ! if ( abs(x1 - x2) <= delta) then\n ! assume x1 = x2\n ! endif\n ! https://github.com/cfinch/Shocksolution_Examples/blob/master/FORTRAN/BilinearInterpolation/interpolation.f90\n use types\n implicit none\n integer, intent(in) :: length\n real(dp), dimension(length), intent(in) :: array\n real(dp), intent(in) :: value\n real(dp), intent(in), optional :: delta\n\n !f2py intent(in) :: length, array, value\n !f2py intent(in), optional :: delta\n !f2py depend(length) :: array\n\n integer :: binarysearch\n integer :: left, middle, right\n real(dp) :: d\n\n if (present(delta) .eqv. .true.) then\n d = delta\n else\n d = 1e-9\n endif\n\n left = 1\n right = length\n do\n if (left > right) then\n exit\n endif\n middle = nint((left+right) / 2.0)\n if ( abs(array(middle) - value) <= d) then\n binarySearch = middle\n return\n else if (array(middle) > value) then\n right = middle - 1\n else\n left = middle + 1\n end if\n end do\n binarysearch = right\n\n end function binarysearch\n\n\n subroutine bilinear_interp(x_array, y_array, f, x, y, z, x_len, y_len, p_len, delta)\n ! This function uses bilinear interpolation to estimate the value\n ! of a function f at points (x,y)\n ! f is assumed to be sampled on a regular grid, with the grid x values specified\n ! by x_array and the grid y values specified by y_array\n ! Reference: http://en.wikipedia.org/wiki/Bilinear_interpolation\n ! https://github.com/cfinch/Shocksolution_Examples/blob/master/FORTRAN/BilinearInterpolation/interpolation.f90\n use types\n implicit none\n integer, intent(in) :: x_len, y_len, p_len\n real(dp), dimension(x_len), intent(in) :: x_array\n real(dp), dimension(y_len), intent(in) :: y_array\n real(dp), dimension(x_len, y_len), intent(in) :: f\n real(dp), dimension(p_len), intent(in) :: x, y\n real(dp), dimension(p_len), intent(out) :: z\n real(dp), intent(in), optional :: delta\n !f2py depend(x_len) :: x_array, f\n !f2py depend(y_len) :: y_array, f\n !f2py depend(p_len) :: x, y, z\n\n real(dp) :: denom, x1, x2, y1, y2\n integer :: i, j, p\n\n do p=1, p_len\n i = binarysearch(x_len, x_array, x(p))\n j = binarysearch(y_len, y_array, y(p))\n\n x1 = x_array(i)\n x2 = x_array(i+1)\n\n y1 = y_array(j)\n y2 = y_array(j+1)\n\n denom = (x2 - x1)*(y2 - y1)\n\n z(p) = (f(i,j)*(x2-x(p))*(y2-y(p)) + f(i+1,j)*(x(p)-x1)*(y2-y(p)) + &\n f(i,j+1)*(x2-x(p))*(y(p)-y1) + f(i+1, j+1)*(x(p)-x1)*(y(p)-y1))/denom\n end do\n end subroutine bilinear_interp\n\nend module interp\n\n\n!==============================================================================\n! grid manipulating function\n!==============================================================================\nmodule grid\n implicit none\n\n contains\n\n subroutine smooth_area_average(in_field, lon, lat, radius, out_field, n, nlon, nlat)\n ! =====================================================\n ! smoothing grid field with area average\n ! in_field : 3D field array used to smoothing, the 2, 3 dimension are lat and lon.\n ! lon, lat : 2D array lon and lat coorindates for the in_field.\n ! radius : smoothing radius.\n ! out_field : return smoothed field.\n ! =====================================================\n use types\n real(dp), intent(in) :: n, nlon, nlat\n real(dp), intent(in) :: in_field(n, nlat, nlon), lon(nlat, nlon), lat(nlat, nlon)\n real(dp), intent(in) :: radius\n real(dp), intent(out) :: out_field(n, nlat, nlon)\n\n !f2py intent(in) :: in_field, lon, lat, radius\n !f2py intent(out) :: out_field\n\n integer :: i, j, k, ii, jj\n real(dp) :: dlat(nlat, nlon), dlon(nlat, nlon), lat1, lat2(nlat, nlon)\n real(dp) :: a(nlat, nlon), dist(nlat, nlon), flag(nlat, nlon), numb\n real(dp), parameter :: earth_radius = 6371000.0\n real(dp), parameter :: deg_to_rad = atan(1.0)/45\n\n flag = 1.0\n do j=1, nlat\n do i=1, nlon\n ! great circle distance\n dlat = (lat-lat(j,i)) * deg_to_rad\n dlon = (lon-lon(j,i)) * deg_to_rad\n lat1 = lat(j,i) * deg_to_rad\n lat2 = lat * deg_to_rad\n a = (sin(dlat/2))**2 + cos(lat1)*cos(lat2)*(sin(dlon/2))**2\n dist = earth_radius*2.0*asin(sqrt(a))\n \n numb = sum(flag, mask=dist <= radius)\n if (numb > 0) then\n do k=1, n\n out_field(k, j, i) = sum(in_field(k, :, :), mask=dist <= radius) / numb\n end do\n else\n out_field(:, j, i) = in_field(:, j, i)\n end if\n end do\n end do\n end subroutine smooth_area_average\n\n\n subroutine smooth_gaussian(in_field, lon, lat, radius, sigma, out_field, n, nlon, nlat)\n ! =====================================================\n ! smoothing grid field with area average\n ! in_field : 3D field array used to smoothing, the 2, 3 dimension are lat and lon.\n ! lon, lat : 2D array lon and lat coorindates for the in_field.\n ! radius : smoothing radius.\n ! sigma : gaussian sigma parameter.\n ! out_field : return smoothed field.\n ! =====================================================\n use types\n real(dp), intent(in) :: n, nlon, nlat\n real(dp), intent(in) :: in_field(n, nlat, nlon), lon(nlat, nlon), lat(nlat, nlon)\n real(dp), intent(in) :: radius, sigma ! sigma is an adjustable smoothing length scale.\n real(dp), intent(out) :: out_field(n, nlat, nlon)\n !f2py intent(in) :: in_field, lon, lat, radius, sigma\n !f2py intent(out) :: out_field\n \n integer :: i, j, k, ii, jj\n real(dp) :: dlat(nlat, nlon), dlon(nlat, nlon), lat1, lat2(nlat, nlon)\n real(dp) :: a(nlat, nlon), dist(nlat, nlon), field(nlat, nlon), flag(nlat, nlon), numb\n real(dp), parameter :: earth_radius = 6371000.0\n real(dp), parameter :: deg_to_rad = atan(1.0)/45\n real(dp), parameter :: pi = 3.1415926535897932_8\n\n flag = 1.0\n do j=1, nlat\n do i=1, nlon\n ! great circle distance\n dlat = (lat-lat(j,i)) * deg_to_rad\n dlon = (lon-lon(j,i)) * deg_to_rad\n lat1 = lat(j,i) * deg_to_rad\n lat2 = lat * deg_to_rad\n a = (sin(dlat/2))**2 + cos(lat1)*cos(lat2)*(sin(dlon/2))**2\n dist = earth_radius*2.0*asin(sqrt(a))\n \n numb = sum(flag, mask=dist <= radius)\n if (numb > 0) then\n do k=1, n\n ! gaussian filter value\n field = exp(-0.5*(dist/sigma)**2)*in_field(k, :, :)/(2*pi*sigma**2)\n out_field(k, j, i) = sum(field, mask=dist <= radius) / numb\n end do\n else\n out_field(:, j, i) = in_field(:, j, i)\n end if\n end do\n end do\n end subroutine smooth_gaussian\n\nend module grid\n\n\n!==============================================================================\n! regridding function\n!==============================================================================\nmodule regrid\n implicit none\n\n contains\n\n subroutine box_average(field0, lon0, lat0, lon1, lat1, width, field1, nlon0, nlat0, nlon1, nlat1)\n ! =====================================================\n ! regridding high resolution field0 to coarse field1 with box_average.\n ! field0: 2D array (nlat1, nlon0) for input high resolution, with missing value is -9999.0\n ! lon0, lat0: 2D coordinates for field0\n ! field1: 2D array (nlat1, nlon0) for output coarse resolution.\n ! lon1, lat1: 2D coordinates for field1\n ! width: box width\n ! =====================================================\n use types\n real(dp), intent(in) :: width, nlon0, nlat0, nlon1, nlat1\n real(dp), intent(in) :: field0(nlat0, nlon0), lon0(nlat0, nlon0), lat0(nlat0, nlon0)\n real(dp), intent(in) :: lon1(nlat1, nlon1), lat1(nlat1, nlon1)\n real(dp), intent(out) :: field1(nlat1, nlon1)\n !f2py intent(in) :: field0, lon0, lat0, lon1, lat1, width\n !f2py intent(out) :: feild1\n\n integer :: i, j, k, ii, jj, numb\n logical :: mask(nlat0, nlon0)\n\n do j=1, nlat1\n do i=1, nlon1\n mask = (lon0 >= (lon1(j,i)-width)) .and. (lon0 <= (lon1(j,i)+width)) .and. &\n (lat0 >= (lat1(j,i)-width)) .and. (lat0 <= (lat1(j,i)+width)) .and. &\n (field0 /= -9999.0)\n numb = count(mask)\n if (numb > 0) then\n field1(j, i) = sum(field0, mask=mask) / numb\n else\n field1(j, i) = -9999.0\n end if\n end do\n end do\n end subroutine box_average\nend module regrid\n\n", "meta": {"hexsha": "d64b893ef8cabe585dccec136d78362378264017", "size": 12402, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/_internal.f90", "max_stars_repo_name": "guoyunqian/dk_met_base", "max_stars_repo_head_hexsha": "cf315fbb887d2ec7d8b028e24b9f161a2296543a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-01-03T10:54:30.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-08T09:26:01.000Z", "max_issues_repo_path": "fortran/_internal.f90", "max_issues_repo_name": "guoyunqian/dk_met_base", "max_issues_repo_head_hexsha": "cf315fbb887d2ec7d8b028e24b9f161a2296543a", "max_issues_repo_licenses": ["MIT"], "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/_internal.f90", "max_forks_repo_name": "guoyunqian/dk_met_base", "max_forks_repo_head_hexsha": "cf315fbb887d2ec7d8b028e24b9f161a2296543a", "max_forks_repo_licenses": ["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.6424581006, "max_line_length": 116, "alphanum_fraction": 0.507256894, "num_tokens": 3583, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517044, "lm_q2_score": 0.8031737940012417, "lm_q1q2_score": 0.6858403455342654}} {"text": "subroutine coarse_to_fine_ls(e_2h, nx, ny, xi_2h, xf_2h, xi_h, xf_h, e_h, delx, dely)\n!USE variables\nuse kind_parameters\nimplicit none\ninclude 'mpif.h'\n\ninteger:: i, j, nx, ny, io, jo, ie, je\ninteger:: xi_h, xf_h, xi_2h, xf_2h\nreal(kind=dp), intent(in), dimension(-1:nx+2,xi_2h-3:xf_2h+3):: e_2h\nreal(kind=dp), intent(out), dimension(-1:nx*2,xi_h-3:xf_h+3):: e_h\nreal(kind=dp), dimension(-2:2*nx):: delx\nreal(kind=dp), dimension(-2:2*ny):: dely\n\n!write(*,*) nx, xi_2h, xf_2h\n\n! Apply linear interpolation to get values from coarse to fine grid\n! Input\n! e_2h Variable in coarse grid\n! hx, hy grid spacing\n!\n! Output\n! e_h Variable in fine grid\n\n! Author: Pratanu Roy\n! History:\n! First Written: July 20, 2012\n! Indices Rechecked on Jan 13, 2013\n\n\n!do j = xi_2h,xf_2h\n!\n! do i = 2,nx-2\n!\n! if (j /= ny-1) then\n!\n! e_h(2*i,2*j) = (1.0/16.0)*(9.0*e_2h(i+1,j+1) + 3.0*e_2h(i,j+1) + 3.0*e_2h(i+1,j) + e_2h(i,j))\n! e_h(2*i,2*j-1) = (1.0/16.0)*(9.0*e_2h(i+1,j) + 3.0*e_2h(i,j) + 3.0*e_2h(i+1,j+1) + e_2h(i,j+1))\n! e_h(2*i-1,2*j) = (1.0/16.0)*(9.0*e_2h(i,j+1) + 3.0*e_2h(i,j) + 3.0*e_2h(i+1,j+1) + e_2h(i+1,j))\n! e_h(2*i-1,2*j-1) = (1.0/16.0)*(9.0*e_2h(i,j) + 3.0*e_2h(i+1,j) + 3.0*e_2h(i,j+1) + e_2h(i+1,j+1))\n!\n! end if\n!\n! end do\n!\n!end do\n\ndo j = xi_h,xf_h\n\n do i = 2,2*nx-3\n\n io = (i+1)/2\n jo = (j+1)/2\n\n ie = i/2\n je = j/2\n\n if (i .eq. 2) then\n\n if (j .eq. 2) then\n\n e_h(i,j) = (1.0/4.0)*(e_2h(ie,je) + e_2h(ie,je+1) + e_2h(ie+1,je) + e_2h(ie+1,je+1))\n\n else if (j .eq. 2*ny-3) then\n\n e_h(i,j) = (1.0/4.0)*(e_2h(ie,jo) + e_2h(ie,jo+1) + e_2h(ie+1,jo) + e_2h(ie+1,jo+1))\n\n else\n\n if(mod(j,2) .eq. 0) then\n\n e_h(i,j) = (1.0/8.0)*(3.0*e_2h(ie,je+1) + 3.0*e_2h(ie+1,je+1) + e_2h(ie,je) + e_2h(ie+1,je))\n\n else\n\n e_h(i,j) = (1.0/8.0)*(e_2h(ie,jo+1) + e_2h(ie+1,jo+1) + 3.0*e_2h(ie,jo) + 3.0*e_2h(ie+1,jo))\n\n end if\n\n end if\n\n else if (i .eq. 2*nx-3) then\n\n if (j .eq. 2) then\n\n e_h(i,j) = (1.0/4.0)*(e_2h(io,je) + e_2h(io,je+1) + e_2h(io+1,je) + e_2h(io+1,jo+1))\n\n else if (j .eq. 2*ny-3) then\n\n e_h(i,j) = (1.0/4.0)*(e_2h(io,jo) + e_2h(io,jo+1) + e_2h(io+1,jo) + e_2h(io+1,jo+1))\n\n else\n\n if(mod(j,2) .eq. 0) then\n\n e_h(i,j) = (1.0/8.0)*(3.0*e_2h(io,je+1) + 3.0*e_2h(io+1,je+1) + e_2h(io,je) + e_2h(io+1,je))\n\n else\n\n e_h(i,j) = (1.0/8.0)*(e_2h(io,jo+1) + e_2h(io+1,jo+1) + 3.0*e_2h(io,jo) + 3.0*e_2h(io+1,jo))\n\n end if\n\n end if\n\n else\n\n if (j .eq. 2) then\n\n if(mod(i,2) .eq. 0) then\n\n e_h(i,j) = (1.0/8.0)*(3.0*e_2h(ie+1,je) + 3.0*e_2h(ie+1,je+1) + e_2h(ie,je) + e_2h(ie,je+1))\n\n else\n\n e_h(i,j) = (1.0/8.0)*(e_2h(io+1,je) + e_2h(io+1,je+1) + 3.0*e_2h(io,je) + 3.0*e_2h(io,je+1))\n\n end if\n\n else if (j .eq. 2*ny-3) then\n\n if(mod(i,2) .eq. 0) then\n\n e_h(i,j) = (1.0/8.0)*(3.0*e_2h(ie+1,jo+1) + 3.0*e_2h(ie+1,jo) + e_2h(ie,jo) + e_2h(ie,jo+1))\n\n else\n\n e_h(i,j) = (1.0/8.0)*(3.0*e_2h(io,jo+1) + e_2h(io+1,jo+1) + 3.0*e_2h(io,jo) + e_2h(io+1,jo))\n\n end if\n\n else\n\n if (mod(i,2) .ne. 0 .and. mod(j,2) .ne. 0) e_h(i,j) = (1.0/16.0)*(9.0*e_2h(io,jo) + 3.0*e_2h(io,jo+1) + 3.0*e_2h(io+1,jo) + e_2h(io+1,jo+1))\n if (mod(i,2) .eq. 0 .and. mod(j,2) .eq. 0) e_h(i,j) = (1.0/16.0)*(e_2h(ie,je) + 3.0*e_2h(ie,je+1) + 3.0*e_2h(ie+1,je) + 9.0*e_2h(ie+1,je+1))\n if (mod(i,2) .ne. 0 .and. mod(j,2) .eq. 0) e_h(i,j) = (1.0/16.0)*(3.0*e_2h(io,je) + 3.0*e_2h(io+1,je+1) + e_2h(io+1,je) + 9.0*e_2h(io,je+1))\n if (mod(i,2) .eq. 0 .and. mod(j,2) .ne. 0) e_h(i,j) = (1.0/16.0)*(3.0*e_2h(ie,jo) + 3.0*e_2h(ie+1,jo+1) + 9.0*e_2h(ie+1,jo) + e_2h(ie,jo+1))\n\n end if\n\n end if\n\n end do\n\nend do\n\n\n! e_h(1,xi_h-3:xf_h+3) = e_h(2,xi_h-3:xf_h+3) + delx(1)*(e_h(2,xi_h-3:xf_h+3) - e_h(3,xi_h-3:xf_h+3))/delx(2)\n! e_h(0,xi_h-3:xf_h+3) = e_h(1,xi_h-3:xf_h+3) + delx(0)*(e_h(1,xi_h-3:xf_h+3) - e_h(2,xi_h-3:xf_h+3))/delx(1)\n! e_h(-1,xi_h-3:xf_h+3) = e_h(0,xi_h-3:xf_h+3)+ delx(-1)*(e_h(0,xi_h-3:xf_h+3) - e_h(1,xi_h-3:xf_h+3))/delx(0)\n!\n! e_h(nx,xi_h-3:xf_h+3) = e_h(nx-1,xi_h-3:xf_h+3) + delx(nx-1)*(e_h(nx-1,xi_h-3:xf_h+3) - e_h(nx-2,xi_h-3:xf_h+3))/delx(nx-2)\n! e_h(nx+1,xi_h-3:xf_h+3) = e_h(nx,xi_h-3:xf_h+3)+ delx(nx)*(e_h(nx,xi_h-3:xf_h+3) - e_h(nx-1,xi_h-3:xf_h+3))/delx(nx-1)\n! e_h(nx+2,xi_h-3:xf_h+3) = e_h(nx+1,xi_h-3:xf_h+3)+ delx(nx+1)*(e_h(nx+1,xi_h-3:xf_h+3) - e_h(nx,xi_h-3:xf_h+3))/delx(nx)\n!\n!if (xf_h .eq. ny-1) then\n!\n! e_h(:,ny) = e_h(:,ny-1) + dely(ny-1)*(e_h(:,ny-1) - e_h(:,ny-2))/dely(ny-2)\n! e_h(:,ny+1) = e_h(:,ny) + dely(ny)*(e_h(:,ny) - e_h(:,ny-1))/dely(ny-1)\n! e_h(:,ny+2) = e_h(:,ny+1)+ dely(ny+1)*(e_h(:,ny+1) - e_h(:,ny))/dely(ny)\n!\n!end if\n!\n!if (xi_h .eq. 2) then\n!\n! e_h(:,1) = e_h(:,2)+ dely(1)*(e_h(:,2) - e_h(:,3))/dely(2)\n! e_h(:,0) = e_h(:,1)+ dely(0)*(e_h(:,1) - e_h(:,2))/dely(1)\n! e_h(:,-1) = e_h(:,0)+ dely(-1)*(e_h(:,0) - e_h(:,1))/dely(0)\n!\n!end if\n!\ncall exchange_lsdata(e_h, nx*2+2, xi_h, xf_h)\n!if (xi_2h .eq. 2) then\n!\n!j = 1\n!\n! e_h(2,2*j) = (1.0/4.0)*(e_2h(1,j) + e_2h(1,j+1) + e_2h(2,j) + e_2h(2,j+1))\n!\n! do i = 2,nx-2\n!\n! e_h(2*i-1,2*j) = (1.0/8.0)*(3.0*e_2h(i,j) + 3.0*e_2h(i,j+1) + e_2h(i+1,j) + e_2h(i+1,j+1))\n! e_h(2*i,2*j) = (1.0/8.0)*(e_2h(i,j) + e_2h(i,j+1) + 3.0*e_2h(i+1,j) + 3.0*e_2h(i+1,j+1))\n!\n! end do\n!\n! e_h(2*nx-3,2*j) = (1.0/4.0)*(e_2h(nx-1,j) + e_2h(nx-1,j+1) + e_2h(nx,j) + e_2h(nx,j+1))\n!\n!\n!end if\n!\n!do j = xi_2h,xf_2h\n!\n!if( j /= ny-1) then\n!\n! i = 1\n!\n! e_h(2*i,2*j-1) = (1.0/8.0)*(3.0*e_2h(i,j) + 3.0*e_2h(i+1,j) + e_2h(i,j+1) + e_2h(i+1,j+1))\n! e_h(2*i,2*j) = (1.0/8.0)*(e_2h(i,j) + e_2h(i+1,j) + 3.0*e_2h(i,j+1) + 3.0*e_2h(i+1,j+1))\n!\n! i = nx-1\n!\n! e_h(2*i-1,2*j-1) = (1.0/8.0)*(3.0*e_2h(i,j) + 3.0*e_2h(i+1,j) + e_2h(i,j+1) + e_2h(i+1,j+1))\n! e_h(2*i-1,2*j) = (1.0/8.0)*(e_2h(i,j) + e_2h(i+1,j) + 3.0*e_2h(i,j+1) + 3.0*e_2h(i+1,j+1))\n!\n!end if\n!\n!end do\n!\n!\n!if (xf_2h .eq. ny-1) then\n!\n!j = ny-1\n!\n! e_h(2,2*j-1) = (1.0/4.0)*(e_2h(1,j) + e_2h(1,j+1) + e_2h(2,j) + e_2h(2,j+1))\n!\n! do i = 2,nx-2\n!\n! e_h(2*i-1,2*j-1) = (1.0/8.0)*(3.0*e_2h(i,j) + 3.0*e_2h(i,j+1) + e_2h(i+1,j) + e_2h(i+1,j+1))\n! e_h(2*i,2*j-1) = (1.0/8.0)*(e_2h(i,j) + e_2h(i,j+1) + 3.0*e_2h(i+1,j) + 3.0*e_2h(i+1,j+1))\n!\n! end do\n!\n! e_h(2*nx-3,2*j-1) = (1.0/4.0)*(e_2h(nx-1,j) + e_2h(nx-1,j+1) + e_2h(nx,j) + e_2h(nx,j+1))\n!\n!end if\n\n!string = '( (1x, e10.3))'\n!\n!write(string(2:4),'(i3)')(nx*2-2)\n!\n!if (taskid .eq. 0) then\n!\n!filename = 'e_h0_prev.txt'\n!\n!open (unit = 13, file = filename)\n!\n!do jt=xi_h-1,xf_h+1\n!\n! write(13,string) e_h(1:nx*2-2,jt)\n!\n!end do\n!\n!write(13,*) 'xi_h = ',xi_h, 'xf_h= ',xf_h\n!write(13,*) 'xi2 = ',xi_2h, 'xf2= ',xf_2h\n!\n!close(13)\n!\n!else\n!\n!filename = 'e_h1_prev.txt'\n!\n!open (unit = 13, file = filename)\n!\n!do jt=xi_h-1,xf_h+1\n!\n! write(13,string) e_h(1:nx*2-2,jt)\n!\n!end do\n!\n!write(13,*) 'xi_h = ',xi_h, 'xf_h= ',xf_h\n!write(13,*) 'xi2 = ',xi_2h, 'xf2= ',xf_2h\n!\n!close(13)\n!\n!end if\n!\n!call exchange_data(e_h, nx*2-2, xi_h, xf_h)\n!\n!string = '( (1x, e10.3))'\n!\n!write(string(2:4),'(i3)')(nx*2-2)\n!\n!if (taskid .eq. 0) then\n!\n!filename = 'e_h0.txt'\n!\n!open (unit = 13, file = filename)\n!\n!do jt=xi_h-1,xf_h+1\n!\n! write(13,string) e_h(1:nx*2-2,jt)\n!\n!end do\n!\n!close(13)\n!\n!else\n!\n!filename = 'e_h1.txt'\n!\n!open (unit = 13, file = filename)\n!\n!do jt=xi_h-1,xf_h+1\n!\n! write(13,string) e_h(1:nx*2-2,jt)\n!\n!end do\n!\n!close(13)\n!\n!end if\n\n!stop\n\nend subroutine\n", "meta": {"hexsha": "6f580462dba9ba746fc7d0b6f5202ed0f1647bf0", "size": 7663, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "coarse_to_fine_ls.f90", "max_stars_repo_name": "pratanuroy/Multigrid_Cavity", "max_stars_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-09-11T12:01:52.000Z", "max_stars_repo_stars_event_max_datetime": "2017-09-11T12:01:52.000Z", "max_issues_repo_path": "coarse_to_fine_ls.f90", "max_issues_repo_name": "pratanuroy/Multigrid_Cavity", "max_issues_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "coarse_to_fine_ls.f90", "max_forks_repo_name": "pratanuroy/Multigrid_Cavity", "max_forks_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.1245901639, "max_line_length": 152, "alphanum_fraction": 0.4983687851, "num_tokens": 4350, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240142763573, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6858236084555481}} {"text": "program problem39\n implicit none\n integer, parameter :: limit = 1000\n integer, dimension(limit) :: perimeters\n integer :: a,b,abc,best=1\n double precision :: c\n\n do a=1,limit\n perimeters(a)=0\n end do\n\n do a=1,limit\n do b=a,limit\n c = sqrt(dble(a**2 + b**2))\n if ((a + b + c) > limit) exit\n if (mod(c,1.0) == 0.0) then\n abc=a+b+int(c)\n perimeters(abc)=perimeters(abc)+1\n end if\n end do\n end do\n\n do a=1,limit\n if (perimeters(a) > perimeters(best)) best=a\n end do\n\n print *, best\n\nend program problem39\n", "meta": {"hexsha": "cbcb2640a092c97495a66e7cbcd0a0e6d584d4a9", "size": 611, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "problem39.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": "problem39.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": "problem39.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": 20.3666666667, "max_line_length": 49, "alphanum_fraction": 0.535188216, "num_tokens": 200, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467738423874, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6857282418783651}} {"text": "c program DRDRANUS\nc>> 1995-10-23 DRDRANUS Krogh Reduced N to work on PC in D.P.\nc>> 1994-10-19 DRDRANUS Krogh Changes to use M77CON\nc>> 1992-03-13 DRDRANUS CLL\nc\nc Driver to demonstrate use of DRANUS to generate random numbers\nc from the uniform distribution between A and A+B.\nc Program computes histogram for N numbers\nc ------------------------------------------------------------------\nc--D replaces \"?\": DR?RANUS, ?RANUS, ?STAT1, ?STAT2\nc ------------------------------------------------------------------\n integer N, NCELLS\n parameter(N = 8000, NCELLS = 10+2)\n double precision A, B, STATS(5), YTAB(N)\n integer IHIST(NCELLS)\n data A, B / 20.0d0, 10.0d0/\nc ------------------------------------------------------------------\n STATS(1) = 0.0d0\nc Get array of scaled random numbers.\nc\n call DRANUS(YTAB, N, A, B)\nc\nc Compute statistics and histogram.\nc\n call DSTAT1(YTAB, N, STATS, IHIST, NCELLS, A, A+B)\nc\nc Print the statistics and histogram.\nc\n write(*,'(13x,a//)') 'Uniform random numbers from DRANUS'\n call DSTAT2(STATS, IHIST, NCELLS, A, A+B)\n end\n", "meta": {"hexsha": "2de350c494fb7c06c0531de93e20d23dd9bbfdea", "size": 1219, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drdranus.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drdranus.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drdranus.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 38.09375, "max_line_length": 72, "alphanum_fraction": 0.5028712059, "num_tokens": 344, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467738423873, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6857282373822351}} {"text": "program planetmotion\nuse velocityverlet\nimplicit none\nreal(16),allocatable :: p(:,:),a(:,:),a1(:,:),m(:),x(:),y(:),z(:),vx(:),vy(:),vz(:)\nreal(16) :: t,d,ax,ay,az,G=6.67e-11\ninteger :: i,w,ios,k,l,n,j,b=0,c=0\n\nopen(unit=1,file='planets.txt',iostat=ios,status='old') !reading the input file\n if(ios/=0) then\n print '(a)','Error opening planets.txt'\n stop\n end if\n read(1,*,iostat=ios) n,t,i,w\n allocate(p(n,7),a(n,3),a1(n,3),m(n),x(n),y(n),z(n),vx(n),vy(n),vz(n))\n k=1\n do \n read(1,*,iostat=ios) m(k),x(k),y(k),z(k),vx(k),vy(k),vz(k) \n if(ios<0) exit\n p(k,1)=m(k)\n p(k,2)=x(k)\n p(k,3)=y(k)\n p(k,4)=z(k)\n p(k,5)=vx(k)\n p(k,6)=vy(k)\n p(k,7)=vz(k)\n k=k+1\n end do\nclose(1)\n\na=0\ndo k=1,i\n if(modulo(c,w)==0) then !printing and writing if the interval criterium is met\n open(unit=1,file='plot.dat',iostat=ios,position='append')\n if(ios/=0) then\n print '(a)','Error opening plot.dat'\n stop\n end if\n open(unit=2,file='plot.xyz',iostat=ios,position='append')\n if(ios/=0) then\n print '(a)','Error opening plot.xyz'\n stop\n end if\n b=b+1\n print'(a,i9,a,g15.5,a,i9)','Step: ',k,' Time: ',k*t,' Steps written to file: ', b\n write(2,'(i3)') n\n write(2,*)\n do l=1,n\n write(1,'(3g20.10)') p(l,2),p(l,3),p(l,4)\n write(2,'(i3,3g20.10)') l,p(l,2),p(l,3),p(l,4)\n print'(i3,3g20.10)',l,p(l,2),p(l,3),p(l,4) \n end do\n print*,\n close(1)\n end if\n c=c+1\n do l=1,n \n p(l,2:4)=positions(p(l,2),p(l,3),p(l,4),p(l,5),p(l,6),p(l,7),a(l,:),t) !using verlet module to calculate new postions\n end do\n do l=1,n !iterating new accelerations\n ax=0\n ay=0\n az=0\n do j=1,n\n if(j/=l) then !don't want to calculate acceleration toward itself \n d=sqrt((p(l,2)-p(j,2))**2+(p(l,3)-p(j,3))**2+(p(l,4)-p(j,4))**2)\n ax=ax+p(j,1)/d**3*(p(j,2)-p(l,2))\n ay=ay+p(j,1)/d**3*(p(j,3)-p(l,3))\n az=az+p(j,1)/d**3*(p(j,4)-p(l,4))\n end if\n end do\n a1(l,:)=[G*ax,G*ay,G*az]\n end do\n do l=1,n \n p(l,5:7)=velocities(p(l,5),p(l,6),p(l,7),a(l,:),a1(l,:),t) !verlet module to get new velocities\n end do \n a=a1\nend do\nprint'(a)','Completed' !Shows when the program is done\nend program planetmotion\n", "meta": {"hexsha": "da6155fab17e2c86bd5008408081b1a51ac8de04", "size": 2325, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/main.f90", "max_stars_repo_name": "flansec/planetary_motion_SIMULATOR", "max_stars_repo_head_hexsha": "fbff202f091a4450c609bb2b2c048f95c3869dcb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/main.f90", "max_issues_repo_name": "flansec/planetary_motion_SIMULATOR", "max_issues_repo_head_hexsha": "fbff202f091a4450c609bb2b2c048f95c3869dcb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/main.f90", "max_forks_repo_name": "flansec/planetary_motion_SIMULATOR", "max_forks_repo_head_hexsha": "fbff202f091a4450c609bb2b2c048f95c3869dcb", "max_forks_repo_licenses": ["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.0625, "max_line_length": 128, "alphanum_fraction": 0.5135483871, "num_tokens": 978, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789468908171, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.68567148670029}} {"text": " SUBROUTINE SB08ND( ACONA, DA, A, RES, E, DWORK, LDWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute a real polynomial E(z) such that\nC\nC (a) E(1/z) * E(z) = A(1/z) * A(z) and\nC (b) E(z) is stable - that is, E(z) has no zeros with modulus\nC greater than 1,\nC\nC which corresponds to computing the spectral factorization of the\nC real polynomial A(z) arising from discrete optimality problems.\nC\nC The input polynomial may be supplied either in the form\nC\nC A(z) = a(0) + a(1) * z + ... + a(DA) * z**DA\nC\nC or as\nC\nC B(z) = A(1/z) * A(z)\nC = b(0) + b(1) * (z + 1/z) + ... + b(DA) * (z**DA + 1/z**DA)\nC (1)\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC ACONA CHARACTER*1\nC Indicates whether the coefficients of A(z) or B(z) =\nC A(1/z) * A(z) are to be supplied as follows:\nC = 'A': The coefficients of A(z) are to be supplied;\nC = 'B': The coefficients of B(z) are to be supplied.\nC\nC Input/Output Parameters\nC\nC DA (input) INTEGER\nC The degree of the polynomials A(z) and E(z). DA >= 0.\nC\nC A (input/output) DOUBLE PRECISION array, dimension (DA+1)\nC On entry, if ACONA = 'A', this array must contain the\nC coefficients of the polynomial A(z) in increasing powers\nC of z, and if ACONA = 'B', this array must contain the\nC coefficients b ,b ,...,b of the polynomial B(z) in\nC 0 1 DA\nC equation (1). That is, A(i) = b for i = 1,2,...,DA+1.\nC i-1\nC On exit, this array contains the coefficients of the\nC polynomial B(z) in eqation (1). Specifically, A(i)\nC contains b , for i = 1,2,...DA+1.\nC i-1\nC\nC RES (output) DOUBLE PRECISION\nC An estimate of the accuracy with which the coefficients of\nC the polynomial E(z) have been computed (see also METHOD\nC and NUMERICAL ASPECTS).\nC\nC E (output) DOUBLE PRECISION array, dimension (DA+1)\nC The coefficients of the spectral factor E(z) in increasing\nC powers of z.\nC\nC Workspace\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC\nC LDWORK INTEGER\nC The length of the array DWORK. LDWORK >= 5*DA+5.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value;\nC = 2: if on entry, ACONA = 'B' but the supplied\nC coefficients of the polynomial B(z) are not the\nC coefficients of A(1/z) * A(z) for some real A(z);\nC in this case, RES and E are unassigned;\nC = 3: if the iterative process (see METHOD) has failed to\nC converge in 30 iterations;\nC = 4: if the last computed iterate (see METHOD) is\nC unstable. If ACONA = 'B', then the supplied\nC coefficients of the polynomial B(z) may not be the\nC coefficients of A(1/z) * A(z) for some real A(z).\nC\nC METHOD\nC _ _\nC Let A(z) be the conjugate polynomial of A(z), i.e., A(z) = A(1/z).\nC\nC The method used by the routine is based on applying the\nC Newton-Raphson iteration to the function\nC _ _\nC F(e) = A * A - e * e,\nC\nC which leads to the iteration formulae (see [1] and [2])\nC\nC _(i) (i) _(i) (i) _ )\nC q * x + x * q = 2 A * A )\nC ) for i = 0, 1, 2,...\nC (i+1) (i) (i) )\nC q = (q + x )/2 )\nC\nC The iteration starts from\nC\nC (0) DA\nC q (z) = (b(0) + b(1) * z + ... + b(DA) * z ) / SQRT( b(0))\nC\nC which is a Hurwitz polynomial that has no zeros in the closed unit\nC (i)\nC circle (see [2], Theorem 3). Then lim q = e, the convergence is\nC uniform and e is a Hurwitz polynomial.\nC\nC The iterates satisfy the following conditions:\nC (i)\nC (a) q has no zeros in the closed unit circle,\nC (i) (i-1)\nC (b) q <= q and\nC 0 0\nC DA (i) 2 DA 2\nC (c) SUM (q ) - SUM (A ) >= 0.\nC k=0 k k=0 k\nC (i)\nC The iterative process stops if q violates (a), (b) or (c),\nC or if the condition\nC _(i) (i) _\nC (d) RES = ||(q q - A A)|| < tol,\nC\nC is satisfied, where || . || denotes the largest coefficient of\nC _(i) (i) _\nC the polynomial (q q - A A) and tol is an estimate of the\nC _(i) (i)\nC rounding error in the computed coefficients of q q . If\nC (i-1)\nC condition (a) or (b) is violated then q is taken otherwise\nC (i)\nC q is used. Thus the computed reciprocal polynomial E(z) = z**DA\nC * q(1/z) is stable. If there is no convergence after 30 iterations\nC then the routine returns with the Error Indicator (INFO) set to 3,\nC and the value of RES may indicate whether or not the last computed\nC iterate is close to the solution.\nC (0)\nC If ACONA = 'B', then it is possible that q is not a Hurwitz\nC polynomial, in which case the equation e(1/z) * e(z) = B(z) has no\nC real solution (see [2], Theorem 3).\nC\nC REFERENCES\nC\nC [1] Kucera, V.\nC Discrete Linear Control, The polynomial Approach.\nC John Wiley & Sons, Chichester, 1979.\nC\nC [2] Vostry, Z.\nC New Algorithm for Polynomial Spectral Factorization with\nC Quadratic Convergence I.\nC Kybernetika, 11, pp. 415-422, 1975.\nC\nC NUMERICAL ASPECTS\nC\nC None.\nC\nC CONTRIBUTORS\nC\nC Release 3.0: V. Sima, Katholieke Univ. Leuven, Belgium, Aug. 1997.\nC Supersedes Release 2.0 routine SB08BD by F. Delebecque and\nC A.J. Geurts.\nC\nC REVISIONS\nC\nC -\nC\nC KEYWORDS\nC\nC Factorization, Laplace transform, optimal control, optimal\nC filtering, polynomial operations, spectral factorization, zeros.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, HALF, ONE, TWO\n PARAMETER ( ZERO = 0.0D0, HALF = 0.5D0, ONE = 1.0D0,\n $ TWO = 2.0D0 )\nC .. Scalar Arguments ..\n CHARACTER ACONA\n INTEGER DA, INFO, LDWORK\n DOUBLE PRECISION RES\nC .. Array Arguments ..\n DOUBLE PRECISION A(*), DWORK(*), E(*)\nC .. Local Scalars ..\n LOGICAL CONV, HURWTZ, LACONA\n INTEGER I, J, K, LALPHA, LAMBDA, LETA, LQ, LRO, NC, NCK\n DOUBLE PRECISION A0, RES0, S, SA0, TOLQ, W\nC .. External Functions ..\n LOGICAL LSAME\n INTEGER IDAMAX\n EXTERNAL IDAMAX, LSAME\nC .. External Subroutines ..\n EXTERNAL DAXPY, DCOPY, DSCAL, DSWAP, SB08NY, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC ABS, SQRT\nC .. Executable Statements ..\nC\n INFO = 0\n LACONA = LSAME( ACONA, 'A' )\nC\nC Test the input scalar arguments.\nC\n IF( .NOT.LACONA .AND. .NOT.LSAME( ACONA, 'B' ) ) THEN\n INFO = -1\n ELSE IF( DA.LT.0 ) THEN\n INFO = -2\n ELSE IF( LDWORK.LT.5*DA + 5 ) THEN\n INFO = -7\n END IF\nC\n IF ( INFO.NE.0 ) THEN\nC\nC Error return.\nC\n CALL XERBLA( 'SB08ND', -INFO )\n RETURN\n END IF\nC\n NC = DA + 1\n IF ( .NOT.LACONA ) THEN\n IF ( A(1).LE.ZERO ) THEN\n INFO = 2\n RETURN\n END IF\n CALL DCOPY( NC, A, 1, E, 1 )\n ELSE\n CALL SB08NY( DA, A, E, W )\n END IF\nC\nC Initialization.\nC\n LALPHA = 1\n LRO = LALPHA + NC\n LETA = LRO + NC\n LAMBDA = LETA + NC\n LQ = LAMBDA + NC\nC\n A0 = E(1)\n SA0 = SQRT( A0 )\n S = ZERO\nC\n DO 20 J = 1, NC\n W = E(J)\n A(J) = W\n W = W/SA0\n E(J) = W\n DWORK(LQ-1+J) = W\n S = S + W**2\n 20 CONTINUE\nC\n RES0 = S - A0\nC\nC The contents of the arrays is, cf [1], Section 7.6,\nC\nC E : the last computed Hurwitz polynomial q ;\nC i-1\nC DWORK(LALPHA,..,LALPHA+DA-K) : alpha(k,0),...alpha(k,n-k);\nC (LRO,...,LRO+DA-K) : alpha(k,n-k),...,alpha(k);\nC (LETA,...,LETA+DA) : eta(0),...,eta(n);\nC (LAMBDA,...,LAMBDA+DA-1) : lambda(0),...,lambda(n-1)\nC\nC DWORK(LQ,...,LQ+DA) : the last computed polynomial q .\nC i\n I = 0\n CONV = .FALSE.\n HURWTZ = .TRUE.\nC\nC WHILE ( I < 30 and CONV = FALSE and HURWTZ = TRUE ) DO\n 40 IF ( I.LT.30 .AND. .NOT.CONV .AND. HURWTZ ) THEN\n I = I + 1\n CALL DCOPY( NC, A, 1, DWORK(LETA), 1 )\n CALL DSCAL( NC, TWO, DWORK(LETA), 1 )\n CALL DCOPY( NC, DWORK(LQ), 1, DWORK(LALPHA), 1 )\nC\nC Computation of lambda(k) and eta(k).\nC\n K = 1\nC\nC WHILE ( K <= DA and HURWTZ = TRUE ) DO\n 60 IF ( ( K.LE.DA ) .AND. HURWTZ ) THEN\n NCK = NC - K\n CALL DCOPY( NCK+1, DWORK(LALPHA), -1, DWORK(LRO), 1 )\n W = DWORK(LALPHA+NCK)/DWORK(LRO+NCK)\n IF ( ABS( W ).GE.ONE ) HURWTZ = .FALSE.\n IF ( HURWTZ ) THEN\n DWORK(LAMBDA+K-1) = W\n CALL DAXPY( NCK, -W, DWORK(LRO), 1, DWORK(LALPHA), 1 )\n W = DWORK(LETA+NCK)/DWORK(LALPHA)\n DWORK(LETA+NCK) = W\n CALL DAXPY( NCK-1, -W, DWORK(LALPHA+1), -1,\n $ DWORK(LETA+1), 1 )\n K = K + 1\n END IF\n GO TO 60\n END IF\nC END WHILE 60\nC\nC HURWTZ = The polynomial q is a Hurwitz polynomial.\nC i-1\n IF ( HURWTZ ) THEN\n CALL DCOPY( NC, DWORK(LQ), 1, E, 1 )\nC\nC Accuracy test.\nC\n CALL SB08NY( DA, E, DWORK(LQ), TOLQ )\n CALL DAXPY( NC, -ONE, A, 1, DWORK(LQ), 1 )\n RES = ABS( DWORK( IDAMAX( NC, DWORK(LQ), 1 ) + LQ - 1 ) )\n CONV = ( RES.LT.TOLQ ) .OR. ( RES0.LT.ZERO )\nC\n IF ( .NOT.CONV ) THEN\n DWORK(LETA) = HALF*DWORK(LETA)/DWORK(LALPHA)\nC\nC Computation of x and q .\nC i i\nC DWORK(LETA,...,LETA+DA) : eta(k,0),...,eta(k,n)\nC (LRO,...,LRO+DA-K+1) : eta(k,n-k+1),...,eta(k,0)\nC\n DO 80 K = DA, 1, -1\n NCK = NC - K + 1\n CALL DCOPY( NCK, DWORK(LETA), -1, DWORK(LRO), 1 )\n W = DWORK(LAMBDA+K-1)\n CALL DAXPY( NCK, -W, DWORK(LRO), 1, DWORK(LETA), 1 )\n 80 CONTINUE\nC\n S = ZERO\nC\n DO 100 J = 0, DA\n W = HALF*( DWORK(LETA+J) + E(J+1) )\n DWORK(LQ+J) = W\n S = S + W**2\n 100 CONTINUE\nC\n RES0 = S - A0\nC\nC Test on the monotonicity of q .\nC 0\n CONV = DWORK(LQ).GT.E(1)\n GO TO 40\n END IF\n END IF\n END IF\nC END WHILE 40\nC\nC Reverse the order of the coefficients in the array E.\nC\n CALL DSWAP( NC, E, 1, DWORK, -1 )\n CALL DSWAP( NC, DWORK, 1, E, 1 )\nC\n IF ( .NOT.CONV ) THEN\n IF ( HURWTZ ) THEN\n INFO = 3\n ELSE IF ( I.EQ.1 ) THEN\n INFO = 2\n ELSE\n INFO = 4\n END IF\n END IF\nC\n RETURN\nC *** Last line of SB08ND ***\n END\n", "meta": {"hexsha": "c2427c5b11ec70351fec3911109ce503ab0765a9", "size": 12255, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/SB08ND.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/SB08ND.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/SB08ND.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 33.2113821138, "max_line_length": 72, "alphanum_fraction": 0.4717258262, "num_tokens": 3885, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9263037323284109, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.6856262794396248}} {"text": "\tSubroutine SET_NUTATE( DJD )\nC\nC\tCalculate the amount of nutation in ecliptic longitude (d_Psi)\nC\tand in the obliquity of the ecliptic (d_Eps) in degrees\nC\tfor a given DJD\nC\t\t\tBased on a BASIC routine in \"Astronomy with your\nC\t\t\tPersonal Computer\" (Duffett-Smith), CUP\nC\t\t\t\t\tFORTRAN version by KM, 23 Oct 1988\nC\n\tImplicit none\nC\n double precision deg2rad\n\tDouble Precision whole\n parameter( deg2rad = 1.74532925199433d-02 )\n* = pi / 180, converts from degrees to radians\n\tParameter( whole = 3.60D+02 )\nC\n\tDouble Precision DJD\nC\n\tDouble Precision T, T2, A, B, DIFF\n\tDouble Precision LS, LS2, LD, LD2, MS, MD, NM, NM2\nC\n\tDouble Precision did_DJD\n\tSave did_DJD\nC\n\tDouble Precision d_Psi, d_Eps, RCP, RSP, Height\n\tCommon / astro1 / d_Psi, d_Eps, RCP, RSP, Height\nC\n\tDIFF = DJD - did_DJD\n\tIf( Abs( DIFF ) .lt. 0.01D+00 ) Return\n\tT = DJD / 3.6525D+04\n\tT2 = T * T\n\tA = 1.000021358D+02 * T\n\tB = whole * ( A - Int( A ) )\n\tLS = 2.796967D+02 + 3.03D-04 * T2 + B\n\tLS = LS * deg2rad\n\tA = 1.336855231D+03 * T\n\tB = whole * ( A - Int( A ) )\n\tLD = 2.704342D+02 - 1.133D-03 * T2 + B\n\tLD = LD * deg2rad\n\tA = 9.999736056D+01 * T\n\tB = whole * ( A - Int( A ) )\n\tMS = 3.584758D+02 - 1.5D-04 * T2 + B\n\tMS = MS * deg2rad\n\tA = 1.325552359D+07 * T\n\tB = whole * ( A - Int( A ) )\n\tMD = 2.961046D+02 + 9.192D-03 * T2 * B\n\tMD = MD * deg2rad\n\tA = 5.372616667D+00 * T\n\tB = whole * ( A - Int( A ) )\n\tNM = 2.591833D+02 + 2.078D-03 * T2 - B\n\tNM = NM * deg2rad\n\tLS2 = LS * 2.0D+00\n\tLD2 = LD * 2.0D+00\n\tNM2 = NM * 2.0D+00\nC\n\td_Psi = ( -1.72327D+01 - 1.737D-02 * T ) * Sin( NM )\n &\t+ ( -1.2729D+00 - 1.3D-04 * T ) * Sin( LS2 )\n &\t+ 2.088D-01 * Sin( NM2 ) - 2.037D-01 * Sin( LD2 )\n &\t+ ( 1.261D-01 - 3.1D-04 * T ) * Sin( MS )\n &\t+ 6.75D-02 * Sin( MD )\n &\t- ( 4.97D-02 - 1.2D-04 * T ) * Sin( LS2 + MS )\n &\t- 3.42D-02 * Sin( LD2 - NM )\n & - 2.61D-02 * Sin( LD2 + MD )\n &\t+ 2.14D-02 * Sin( LS2 - MS )\n &\t- 1.49D-02 * Sin( LS2 - LD2 + MD )\n &\t+ 1.24D-02 * Sin( LS2 - NM )\n & + 1.14D-02 * Sin( LD2 - MD )\n\td_Psi = d_Psi / 3.6D+03\n\td_Eps = ( 9.21D+00 + 9.1D-04 * T ) * Cos( NM )\n &\t+ ( 5.522D-01 - 2.9D-04 * T ) * Cos( LS2 )\n &\t- 9.04D-02 * Cos( NM2 ) + 8.84D-02 * Cos( LD2 )\n &\t+ 2.16D-02 * Cos( LS2 + MS )\n & + 1.83D-02 * Cos( LD2 - NM )\n &\t+ 1.13D-02 * Cos( LD2 + MD )\n & - 9.3D-03 * Cos( LS2 - MS ) \n & \t- 6.6D-03 * Cos( LS2 - NM )\n\td_Eps = d_Eps / 3.6D+03\nC\n\tdid_DJD = DJD\nC\n\tEnd\n", "meta": {"hexsha": "9116e24965d41e6913e08d0fd8da4438ff75abc5", "size": 2455, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tvguide/nutate.f", "max_stars_repo_name": "barentsen/tvguide", "max_stars_repo_head_hexsha": "5abefada3f11885e4816f46cc78382f124372492", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tvguide/nutate.f", "max_issues_repo_name": "barentsen/tvguide", "max_issues_repo_head_hexsha": "5abefada3f11885e4816f46cc78382f124372492", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tvguide/nutate.f", "max_forks_repo_name": "barentsen/tvguide", "max_forks_repo_head_hexsha": "5abefada3f11885e4816f46cc78382f124372492", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-10-04T18:58:13.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-04T18:58:13.000Z", "avg_line_length": 29.578313253, "max_line_length": 71, "alphanum_fraction": 0.5401221996, "num_tokens": 1176, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037343628702, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6856262756363959}} {"text": " SUBROUTINE LOGLOG (A,B,C,D,E,F)\r\nC\r\nC WRITTEN BY G.CHAN/UNISYS 7/92, THE 1992 SUMMER OLYMPIC WEEK\r\nC\r\nC LOG-LOG TABLE LOOKUP 10 +------+------+------+--+\r\nC D *\r\nC INPUT : A,B, C,D, AND E 8 +------+-------/-----+--+\r\nC OUTPUT: F /\r\nC /\r\nC ALL A,B,C,D,E,F IN LOG 4 +------+----/-+------+--+\r\nC SCALE F *\r\nC /\r\nC LINEAR EVALUATION ON LOG 2 +------+-/-----+------+--+\r\nC SCALE (NO POLYNOMIAL B *\r\nC EVALUATION)\r\nC 1 +------+------+------+--+\r\nC 1 2A E 4 C 8 10\r\n AA = ALOG10(A)\r\n BB = ALOG10(B)\r\n CC = ALOG10(C) - AA\r\n DD = ALOG10(D) - BB\r\n EE = ALOG10(E) - AA\r\n F = 10.**(EE*DD/CC + BB)\r\n RETURN\r\nC\r\nC\r\n ENTRY SMILOG (A,B,C,D,E,F)\r\nC ==========================\r\nC\r\nC SEMI-LOG TABLE LOOKUP 10 +--+--+--+--+--+--+--+--+--+\r\nC D *\r\nC INPUT : A,B, C,D, AND E 8 +--+--+--+--+-/+--+--+--+--+\r\nC OUTPUT: F /\r\nC /\r\nC A,C,E IN LINEAR SCALE 4 +--+--+--+-/+--+--+--+--+--+\r\nC B,D,F IN LOG SCALE F *\r\nC /\r\nC 2 +--+--+-/+--+--+--+--+--+--+\r\nC B *\r\nC\r\nC 1 +--+--+--+--+--+--+--+--+--+\r\nC 0 1 2A 3E 4 C 6 7 8 9\r\n BB = ALOG10(B)\r\n CC = C - A\r\n DD = ALOG10(D) - BB\r\n EE = E - A\r\n F = 10.**(EE*DD/CC + BB)\r\n RETURN\r\nC\r\nC\r\n ENTRY LOGSMI (A,B,C,D,E,F)\r\nC ==========================\r\nC\r\nC LOG-SEMI TABLE LOOKUP 10 +-----+-----+-----+--+\r\nC D *\r\nC INPUT: A,B, C,D, AND E 8 +-----+-----+--/--+--+\r\nC OUTPUT: F /\r\nC 6 +-----+-----+/----+--+\r\nC A,C,E IN LOG SCALE /\r\nC B,D,F IN LINEAR SCALE 4 +-----+----/+-----+--+\r\nC F *\r\nC 2 +-----+--/--+-----+--+\r\nC B *\r\nC 0 +-----+-----+-----+--+\r\nC 1 2 A E 4 C 8 10\r\n AA = ALOG10(A)\r\n CC = ALOG10(C) - AA\r\n DD = D - B\r\n EE = ALOG10(E) - AA\r\n F = EE*DD/CC + B\r\n RETURN\r\n END\r\n", "meta": {"hexsha": "dc45d233a3d5b0459cd6143e9d888e0c8c3e0fc3", "size": 2903, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "mis/loglog.f", "max_stars_repo_name": "ldallolio/NASTRAN-95", "max_stars_repo_head_hexsha": "6d2c175f5b53ebaec4ba2b5186f7926ef9d0ed47", "max_stars_repo_licenses": ["NASA-1.3"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2016-01-09T14:33:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-18T11:51:42.000Z", "max_issues_repo_path": "mis/loglog.f", "max_issues_repo_name": "gassive/NASTRAN95", "max_issues_repo_head_hexsha": "98cb3acaa7990d639360601648498834c7782056", "max_issues_repo_licenses": ["NASA-1.3"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2016-01-17T07:30:19.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-06T19:37:44.000Z", "max_forks_repo_path": "mis/loglog.f", "max_forks_repo_name": "gassive/NASTRAN95", "max_forks_repo_head_hexsha": "98cb3acaa7990d639360601648498834c7782056", "max_forks_repo_licenses": ["NASA-1.3"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-04-07T20:51:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T14:16:01.000Z", "avg_line_length": 39.7671232877, "max_line_length": 67, "alphanum_fraction": 0.2111608681, "num_tokens": 758, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037323284109, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6856262741305412}} {"text": "!##############################################################################\n! MODULE globals\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!##############################################################################\nmodule globals\n\n implicit none\n\n ! commons\n real*8, parameter :: alpha(2) = (/0.3d0, 0.4d0/)\n real*8, parameter :: a0(2) = (/0.2d0, 0.2d0/)\n real*8, parameter :: a(2, 2) = reshape((/ 0d0, 0.3d0, 0.2d0, 0d0 /),(/2,2/))\n real*8, parameter :: G = 3d0\n real*8, parameter :: ID(2, 2) = reshape((/ 1d0, 0d0, 0d0, 1d0 /),(/2,2/))\n real*8 :: r\n\n ! country specific\n real*8, parameter :: Tbar(2) = (/30d0, 10d0/)\n real*8, parameter :: Kbar(2) = (/10d0, 30d0/)\n real*8, parameter :: beta(2, 2) = reshape((/ 0.3d0, 0.6d0, 0.3d0, 0.6d0 /),(/2,2/))\n real*8 :: tauw(2) = (/0d0, 0d0/)\n real*8 :: taur(2) = (/0d0, 0d0/)\n real*8 :: tauc(2,2) = 0d0\n real*8 :: Ybarn(2), q(2,2), p(2,2), w(2), wn(2), rn(2)\n real*8 :: Xd(2,2), Y(2,2), ky(2,2), ly(2,2), K(2,2), L(2,2), ell(2)\n\ncontains\n\n\n ! function to determine market equilibrium\n function markets(x)\n\n use toolbox\n\n implicit none\n real*8, intent(in) :: x(:)\n real*8 :: markets(size(x, 1))\n real*8 :: mat(4, 4), vec(4)\n integer :: i\n\n ! copy producer prices and taxes\n w(1) = 1d0\n w(2) = x(1)\n r = x(2)\n tauc(1,1) = x(3)\n tauc(1,2) = x(4)\n tauc(2,:) = tauc(1,:)\n\n ! 1. calculate K/Y and L/Y\n do i = 1, 2\n ky(:,i) = a0*((1d0-beta(:,i))/beta(:,i)*w(i)/r)**beta(:,i)\n ly(:,i) = a0*(beta(:,i)/(1d0-beta(:,i))*r/w(i))**(1d0-beta(:,i))\n enddo\n\n ! 2. determine producer prices\n q(:,1) = w(1)*ly(:,1)+r*ky(:,1)\n call lu_solve(ID-transpose(a), q(:,1))\n q(1,2) = (a(2,1)*q(2,1)+w(2)*ly(1,2)+r*ky(1,2))/(1d0-a(1,1))\n q(2,2) = q(2,1)\n\n ! 3. consumer prices and demands\n do i = 1, 2\n p(:,i) = q(:,i)*(1d0+tauc(:,i))\n wn(i) = w(i)*(1d0-tauw(i))\n rn(i) = r*(1d0-taur(i))\n Ybarn(i) = wn(i)*Tbar(i)+rn(i)*Kbar(i)\n Xd(:,i) = alpha/p(:,i)*Ybarn(i)\n ell(i) = (1d0-alpha(1)-alpha(2))/wn(i)*Ybarn(i)\n enddo\n\n ! 4. determine output levels\n vec(1) = Xd(1,1)+G\n vec(2) = Xd(2,1)+Xd(2,2)\n vec(3) = Xd(1,2)+G\n vec(4) = Tbar(1)-ell(1)\n\n mat(1, :) = (/1d0-a(1,1), -a(1,2), 0d0, 0d0/)\n mat(2, :) = (/-a(2,1), 1d0-a(2,2), -a(2,1), 1d0-a(2,2)/)\n mat(3, :) = (/0d0, 0d0, 1d0-a(1,1), -a(1,2)/)\n mat(4, :) = (/ly(1,1), ly(2,1), 0d0, 0d0/)\n\n call lu_solve(mat, vec)\n Y(1,1) = vec(1)\n Y(2,1) = vec(2)\n Y(1,2) = vec(3)\n Y(2,2) = vec(4)\n\n ! 5. compute K and L\n K = ky*Y\n L = ly*Y\n\n ! 6. check markets and budget\n markets(1) = L(1,2)+L(2,2)-(Tbar(2)-ell(2))\n markets(2) = sum(K)-sum(Kbar)\n markets(3) = q(1,1)*G-sum(tauc(:,1)*q(:,1)*Xd(:,1))-&\n tauw(1)*w(1)*(Tbar(1)-ell(1))-taur(1)*r*Kbar(1)\n markets(4) = q(1,2)*G-sum(tauc(:,2)*q(:,2)*Xd(:,2))-&\n tauw(2)*w(2)*(Tbar(2)-ell(2))-taur(2)*r*Kbar(2)\n\n end function\n\nend module\n\n", "meta": {"hexsha": "77eb11382eeb56a4abeacada648ef9dbbefa673a", "size": 3533, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "complete/prog03/prog03_07/prog03_07m.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/prog03/prog03_07/prog03_07m.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/prog03/prog03_07/prog03_07m.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": 31.5446428571, "max_line_length": 87, "alphanum_fraction": 0.4214548542, "num_tokens": 1458, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037363973295, "lm_q2_score": 0.7401743563075447, "lm_q1q2_score": 0.6856262718331669}} {"text": " real function shear(a,b,c,x)\r\nc\r\nc + + + PURPOSE + + +\r\nc Calculates nondimensional shear stress.\r\nc\r\nc Called from subroutine XCRIT.\r\nc Author(s): G. Foster\r\nc Reference in User Guide:\r\nc\r\nc Changes:\r\nc\r\nc Version: This module recoded from WEPP version 90.92.\r\nc Date recoded: 01/08/91.\r\nc Recoded by: Charles R. Meyer.\r\nc\r\nc + + + KEYWORDS + + +\r\nc\r\nc + + + ARGUMENT DECLARATIONS + + +\r\nc\r\n real a, b, c, x\r\nc\r\nc + + + ARGUMENT DEFINITIONS + + +\r\nc a - shear stress coefficient for current slope\r\nc section\r\nc b - shear stress coefficient for current slope\r\nc section\r\nc c - shear stress coefficient for current slope\r\nc section\r\nc x - nondimensional distance at which shear stress\r\nc is to be calculated\r\nc\r\nc + + + LOCAL VARIABLES + + +\r\nc value -\r\n real value\r\nc\r\nc + + + END SPECIFICATIONS + + +\r\nc\r\n value = a * x ** 2 + b * x + c\r\n if (value.lt.0.0) value = 0.0\r\n shear = value ** 0.66666667\r\n if (shear.le.0.0) shear = 0.0001\r\nc\r\n return\r\n end\r\n", "meta": {"hexsha": "90714552a403bd794ab2f0125f710d81dce76738", "size": 1149, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/wepp2010.1/shear.for", "max_stars_repo_name": "jarad/dep", "max_stars_repo_head_hexsha": "fe73982f4c70039e1a31b9e8e2d9aac31502f803", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-11-26T17:49:19.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-26T17:49:19.000Z", "max_issues_repo_path": "src/wepp2010.1/shear.for", "max_issues_repo_name": "jarad/dep", "max_issues_repo_head_hexsha": "fe73982f4c70039e1a31b9e8e2d9aac31502f803", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 54, "max_issues_repo_issues_event_min_datetime": "2018-12-12T18:02:31.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T19:14:25.000Z", "max_forks_repo_path": "src/wepp2010.1/shear.for", "max_forks_repo_name": "akrherz/idep", "max_forks_repo_head_hexsha": "7189a26fbcec3d8c3cc7d7015107b8fb6c5f6a45", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-03-02T22:59:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-09T15:49:00.000Z", "avg_line_length": 25.5333333333, "max_line_length": 61, "alphanum_fraction": 0.5361183638, "num_tokens": 334, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012701768144, "lm_q2_score": 0.7248702702332476, "lm_q1q2_score": 0.6855832223000162}} {"text": "!============================================================================\n MODULE math_utilities\n!--------------------------------------------------------------------------\n! \n! FUNCTION: Module containing routines necessary to compute the line-integrated\n! Faraday rotation angle and the line-integrated polarization phase shift.\n!\n!------------------------------------------------------------------------------\n USE stel_kinds\n USE stel_constants\n IMPLICIT NONE\n\n\n CONTAINS\n!=============================================================================\n REAL(KIND=rprec) FUNCTION MAGNITUDE(vec)\n!--------------------------------------------------------------------------\n! FUNCTION: calculates the magnitude of 3D input vector. \n!\n!--------------------------------------------------------------------------- \n USE stel_kinds\n IMPLICIT NONE\n\n\n REAL(rprec), DIMENSION(3), INTENT(IN) :: &\n & vec ! 3D vector\n\n MAGNITUDE = SQRT( vec(1)*vec(1) + vec(2)*vec(2) + vec(3)*vec(3) )\n\n RETURN\n END FUNCTION MAGNITUDE\n\n!=============================================================================\n SUBROUTINE UNIT_VECTOR(v1, v1_unit)\n!--------------------------------------------------------------------------\n! FUNCTION: calculates the magnitude of 3D input vector. \n!\n!--------------------------------------------------------------------------- \n USE stel_kinds\n IMPLICIT NONE\n\n REAL(rprec), DIMENSION(3), INTENT(IN) :: &\n & v1 ! 3D vector\n\n REAL(rprec), DIMENSION(3), INTENT(OUT) :: &\n & v1_unit ! 3D vector\n\n v1_unit = v1 / MAGNITUDE(v1)\n\n RETURN\n END SUBROUTINE UNIT_VECTOR\n\n\n!=============================================================================\n REAL(KIND=rprec) FUNCTION DIST(v1, v2)\n!--------------------------------------------------------------------------\n! FUNCTION: calculates the absolute distance between 2 input vectors. \n!\n!--------------------------------------------------------------------------- \n USE stel_kinds\n IMPLICIT NONE\n\n REAL(rprec), DIMENSION(3), INTENT(IN) :: &\n & v1, v2 ! 3D vectors\n\n REAL(rprec), DIMENSION(3) :: &\n & v3 ! difference vector btwn v1 & v2\n\n v3 = ABS( v2 - v1 )\n DIST = SQRT( v3(1)*v3(1) + v3(2)*v3(2) + v3(3)*v3(3) )\n\n RETURN\n END FUNCTION DIST\n\n!==================================================================================\n SUBROUTINE CROSS_PRODUCT(A, B, C)\n!----------------------------------------------------------------------------------\n! FUNCTION: computes the cross product (C) for input CARTESIAN vectors A and B.\n!\n! LOGIC: C = A .cross. B\n!\n! created by J. Shields 2/15/06\n!\n!--------------------------------------------------------------------------------------\n USE stel_kinds\n IMPLICIT NONE\n\n!........passed variables....................................................!\n REAL(rprec), DIMENSION(3), INTENT(IN) :: A ! input Cartesian vector\n\n REAL(rprec), DIMENSION(3), INTENT(IN) :: B ! input Cartesian vector\n\n REAL(rprec), DIMENSION(3), INTENT(OUT) :: C ! Cross product: A .cross. B\n\n \n!.................local variables...................................!\n INTEGER(iprec) :: i\n character(len=*), PARAMETER :: subname = 'CROSS_PRODUCT'\n\n\n!..................X component.....................................!\n C(1) = A(2) * B(3) - A(3) * B(2) \n\n!...................Y component.....................................!\n C(2) = A(3) * B(1) - A(1) * B(3) \n \n!...................Z component.....................................!\n C(3) = A(1) * B(2) - A(2) * B(1) \n\n RETURN\n END SUBROUTINE CROSS_PRODUCT\n\n\n END MODULE math_utilities\n", "meta": {"hexsha": "e19f4d3bf59d59cf1718cfeb7b48d71db7c24085", "size": 4062, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "LIBSTELL/Sources/Modules/math_utilities.f", "max_stars_repo_name": "joseluisvelasco/STELLOPT", "max_stars_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2020-05-08T01:47:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T10:35:28.000Z", "max_issues_repo_path": "LIBSTELL/Sources/Modules/math_utilities.f", "max_issues_repo_name": "joseluisvelasco/STELLOPT", "max_issues_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 77, "max_issues_repo_issues_event_min_datetime": "2020-05-08T07:18:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:20:33.000Z", "max_forks_repo_path": "Sources/Modules/math_utilities.f", "max_forks_repo_name": "ORNL-Fusion/LIBSTELL", "max_forks_repo_head_hexsha": "ba938c678d776b84d7bb260ea541a9b45deb37e2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-02-10T13:47:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T12:53:43.000Z", "avg_line_length": 35.3217391304, "max_line_length": 87, "alphanum_fraction": 0.3382570162, "num_tokens": 823, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422644, "lm_q2_score": 0.7577943658046608, "lm_q1q2_score": 0.6855390824177305}} {"text": "C$Procedure VSEPG ( Angular separation of vectors, general dimension )\n \n DOUBLE PRECISION FUNCTION VSEPG ( V1, V2, NDIM )\n \nC$ Abstract\nC\nC VSEPG finds the separation angle in radians between two double\nC precision vectors of arbitrary dimension. This angle is defined\nC as zero if either vector is zero.\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 ANGLE, VECTOR\nC\nC$ Declarations\n \n DOUBLE PRECISION V1 ( * )\n DOUBLE PRECISION V2 ( * )\n INTEGER NDIM\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC V1 I First vector.\nC V2 I Second vector.\nC NDIM I The number of elements in V1 and V2.\nC\nC$ Detailed_Input\nC\nC V1 is any double precision vector of arbitrary dimension.\nC V2 is also a double precision vector of arbitrary dimension.\nC V1 or V2 or both may be the zero vector.\nC NDIM is the dimension of the both of the input vectors\nC V1 and V2.\nC\nC$ Detailed_Output\nC\nC VSEPG is the angle between V1 and V2 expressed in radians.\nC VSEPG is strictly non-negative. For input vectors of\nC four or more dimensions, the angle is defined as the\nC generalization of the definition for three dimensions.\nC If either V1 or V2 is the zero vector, then VSEPG is\nC defined to be 0 radians.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Particulars\nC\nC In four or more dimensions this angle does not have a physically\nC realizable interpretation. However, the angle is defined as\nC the generalization of the following definition which is valid in\nC three or two dimensions:\nC\nC In the plane, it is a simple matter to calculate the angle\nC between two vectors once the two vectors have been made to be\nC unit length. Then, since the two vectors form the two equal\nC sides of an isosceles triangle, the length of the third side\nC is given by the expression\nC\nC LENGTH = 2.0 * SINE ( VSEPG/2.0 )\nC\nC The length is given by the magnitude of the difference of the\nC two unit vectors\nC\nC LENGTH = NORM ( U1 - U2 )\nC\nC Once the length is found, the value of VSEPG may be calculated\nC by inverting the first expression given above as\nC\nC VSEPG = 2.0 * ARCSINE ( LENGTH/2.0 )\nC\nC This expression becomes increasingly unstable when VSEPG gets\nC larger than PI/2 or 90 degrees. In this situation (which is\nC easily detected by determining the sign of the dot product of\nC V1 and V2) the supplementary angle is calculated first and\nC then VSEPG is given by\nC\nC VSEPG = PI - SUPPLEMENTARY_ANGLE\nC\nC$ Examples\nC\nC The following table gives sample values for V1, V2 and VSEPG\nC implied by the inputs.\nC\nC V1 V2 NDIM VSEPG\nC -----------------------------------------------------------------\nC (1, 0, 0, 0) (1, 0, 0, 0) 4 0.0D0\nC (1, 0, 0) (0, 1, 0) 3 PI/2 (=1.71...)\nC (3, 0) (-5, 0) 2 PI (=3.14...)\nC\nC$ Restrictions\nC\nC The user is required to insure that the input vectors will not\nC cause floating point overflow upon calculation of the vector\nC dot product since no error detection or correction code is\nC implemented. In practice, this is not a significant\nC restriction.\nC\nC$ Exceptions\nC\nC Error free.\nC\nC$ Files\nC\nC None\nC\nC$ Author_and_Institution\nC\nC C.A. Curzon (JPL)\nC K.R. Gehringer (JPL)\nC H.A. Neilan (JPL)\nC W.L. Taber (JPL)\nC\nC$ Literature_References\nC\nC None\nC\nC$ Version\nC\nC- SPICELIB Version 1.1.0, 29-FEB-1996 (KRG)\nC\nC The declaration for the SPICELIB function PI is now\nC preceded by an EXTERNAL statement declaring PI to be an \nC external function. This removes a conflict with any\nC compilers that have a PI intrinsic function.\nC\nC- SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)\nC\nC Comment section for permuted index source lines was added\nC following the header.\nC\nC- SPICELIB Version 1.0.0, 31-JAN-1990 (CAC)\nC\nC-&\n \nC$ Index_Entries\nC\nC angular separation of n-dimensional vectors\nC\nC-&\n \nC$ Revisions\nC\nC- SPICELIB Version 1.1.0, 29-FEB-1996 (KRG)\nC\nC The declaration for the SPICELIB function PI is now\nC preceded by an EXTERNAL statement declaring PI to be an \nC external function. This removes a conflict with any\nC compilers that have a PI intrinsic function.\nC\nC- SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)\nC\nC Comment section for permuted index source lines was added\nC following the header.\nC\nC- SPICELIB Version 1.0.0, 31-JAN-1990 (CAC)\nC\nC- Beta Version 1.1.0, 02-MAR-1989 (HAN)\nC\nC The variable MAGDIFF was changed to MAGDIF in order to\nC comply with the ANSI Fortran Standard six character\nC variable name length restriction.\nC\nC- Beta Version 1.0.1, 10-JAN-1989 (WLT)\nC\nC Error free specification added.\nC\nC-&\n \nC\nC SPICELIB functions\nC\n EXTERNAL PI\n DOUBLE PRECISION PI\n DOUBLE PRECISION VNORMG\n DOUBLE PRECISION VDOTG\nC\nC Local Variables\nC\nC The following declarations represent, respectively:\nC Magnitudes of V1, V2\nC Reciprocals of the magnitudes of V1, V2\nC Magnitude of either of the difference vectors: V1-V2 or\nC V1-(-V2)\nC\n DOUBLE PRECISION DMAG1\n DOUBLE PRECISION DMAG2\n DOUBLE PRECISION R1\n DOUBLE PRECISION R2\n DOUBLE PRECISION MAGDIF\n \n INTEGER I\nC\nC Calculate the magnitudes of V1 and V2; if either is 0, VSEPG = 0\nC\n DMAG1 = VNORMG ( V1, NDIM )\n IF ( DMAG1 .EQ. 0.D0 ) THEN\n VSEPG = 0.D0\n RETURN\n END IF\n \n DMAG2 = VNORMG ( V2, NDIM )\n IF ( DMAG2 .EQ. 0.D0 ) THEN\n VSEPG = 0.D0\n RETURN\n END IF\n \n \n IF ( VDOTG (V1, V2, NDIM) .GT. 0 ) THEN\n \n R1 = 1.0D0/DMAG1\n R2 = 1.0D0/DMAG2\n \n MAGDIF = 0.0D0\n DO I = 1, NDIM\n MAGDIF = MAGDIF + ( V1(I)*R1 - V2(I)*R2 )**2\n END DO\n MAGDIF = DSQRT(MAGDIF)\n \n VSEPG = 2.0D0 * ASIN (0.5D0 * MAGDIF)\n \n ELSE IF ( VDOTG (V1, V2, NDIM) .LT. 0 ) THEN\n \n R1 = 1.0D0/DMAG1\n R2 = 1.0D0/DMAG2\n \n MAGDIF = 0.0D0\n DO I = 1, NDIM\n MAGDIF = MAGDIF + ( V1(I)*R1 + V2(I)*R2 )**2\n END DO\n MAGDIF = DSQRT(MAGDIF)\n \n VSEPG = PI() - 2.0D0 * ASIN (0.5D0 * MAGDIF)\n \n ELSE\n VSEPG = PI() / 2.0D0\n END IF\n \n RETURN\n END\n", "meta": {"hexsha": "9714b1d8013ff4b4e39b823bda5eb8316bec5098", "size": 8216, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/vsepg.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/vsepg.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/vsepg.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": 30.0952380952, "max_line_length": 72, "alphanum_fraction": 0.6211051607, "num_tokens": 2485, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.685539079573942}} {"text": "subroutine delsph(flat1,flon1,flat2,flon2,del)\n implicit none\n real,parameter:: R=6371.0\n REAL,parameter:: pi=3.1415926535898\n real flat1,flat2\n real flon1,flon2\n real del\n\n real dlat\n real dlon\n real lat1\n real lat2\n real a\n real c\n\n\n !dlat=(flat2-flat1)*pi/180\n !dlon=(flon2-flon1)*pi/180\n !lat1=flat1*pi/180\n !lat2=flat2*pi/180\n dlat=flat2-flat1\n dlon=flon2-flon1\n lat1=pi/2-flat1\n lat2=pi/2-flat2\n a=sin(dlat/2)*sin(dlat/2)+sin(dlon/2)*sin(dlon/2)*cos(lat1)*cos(lat2)\n c=2*atan2(sqrt(a),sqrt(1-a))\n del=R*c\nend subroutine\n", "meta": {"hexsha": "d14000ce2e09985a9eb41be5f80c21e2c64e7605", "size": 549, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/delsph.f90", "max_stars_repo_name": "ChetGoerzen/DSurfTomo", "max_stars_repo_head_hexsha": "85c933d6bc49e508debac2d840bfa19b09c7d43c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 58, "max_stars_repo_stars_event_min_datetime": "2017-08-02T13:29:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-12T13:46:05.000Z", "max_issues_repo_path": "src/delsph.f90", "max_issues_repo_name": "ChetGoerzen/DSurfTomo", "max_issues_repo_head_hexsha": "85c933d6bc49e508debac2d840bfa19b09c7d43c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2017-11-16T02:14:02.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-02T01:05:49.000Z", "max_forks_repo_path": "src/delsph.f90", "max_forks_repo_name": "ChetGoerzen/DSurfTomo", "max_forks_repo_head_hexsha": "85c933d6bc49e508debac2d840bfa19b09c7d43c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 40, "max_forks_repo_forks_event_min_datetime": "2017-07-27T09:48:21.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-08T12:42:17.000Z", "avg_line_length": 18.9310344828, "max_line_length": 71, "alphanum_fraction": 0.6867030965, "num_tokens": 253, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541561135441, "lm_q2_score": 0.7279754489059775, "lm_q1q2_score": 0.6855011070109367}} {"text": "double precision function cubicfilter(x, c0, c1, c2, c3)\n ! filter 4 values using cubic splines\n double precision x, c0, c1, c2, c3\n double precision w0, w1, w2, w3\n w0 = x*(x*(-x + 3d0) - 3d0) + 1d0\n w1 = x*x*(3d0*x - 6d0) + 4d0;\n w2 = x*(x*(-3d0*x + 3d0) + 3d0) + 1d0\n w3 = x*x*x\n cubicfilter = (c0 * w0 + c1 * w1 + c2 * w2 + c3 * w3) * 0.16666666666666666d0\nend\n\ndouble precision function tex2d(ftl_map, i, j, nx, ny)\n ! nx : second dimension of array\n ! ny : first dimension of array\n double precision, intent(in) :: ftl_map(0:ny-1, 0:nx-1)\n integer, intent(in) :: nx, ny\n integer i, j\n\n if (i < 0) i = mod(ny + i, ny)\n if (j < 0) j = mod(nx + j, nx)\n if (i >= ny) i = mod(i, ny)\n if (j >= nx) j = mod(j, nx)\n tex2d = ftl_map(i, j)\nend\n\ndouble precision function eval(ftl_map, fx, fy, nx, ny)\n ! nx : second dimension of array\n ! ny : first dimension of array\n implicit none\n double precision, intent(in) :: ftl_map(0:ny-1, 0:nx-1), fx, fy\n integer, intent(in) :: nx, ny\n double precision, external :: cubicfilter, tex2d\n double precision gx, gy\n integer px, py\n\n px = floor(fx)\n py = floor(fy)\n gx = fx - px\n gy = fy - py\n eval = cubicfilter(gy, &\n cubicfilter(gx, tex2d(ftl_map, px-1, py-1,nx, ny), tex2d(ftl_map, px, py-1,nx, ny), &\n tex2d(ftl_map, px+1, py-1,nx, ny), tex2d(ftl_map, px+2,py-1,nx, ny)), &\n cubicfilter(gx, tex2D(ftl_map, px-1, py, nx, ny), tex2d(ftl_map, px, py,nx, ny), &\n tex2d(ftl_map, px+1, py, nx, ny), tex2d(ftl_map, px+2, py,nx, ny)),&\n cubicfilter(gx, tex2D(ftl_map, px-1, py+1,nx, ny), tex2d(ftl_map, px, py+1,nx, ny), &\n tex2d(ftl_map, px+1, py+1, nx, ny), tex2d(ftl_map, px+2, py+1,nx, ny)), &\n cubicfilter(gx, tex2D(ftl_map, px-1, py+2,nx, ny), tex2d(ftl_map, px, py+2,nx, ny), &\n tex2d(ftl_map, px+1, py+2,nx, ny), tex2d(ftl_map, px+2, py+2,nx, ny)) )\nend\n\ninteger function mod_test(i, npix)\n integer i, npix\n mod_test = i\n if (mod_test < 0) mod_test = mod(npix + mod_test, npix)\n if (mod_test >= npix) mod_test = mod(mod_test, npix)\nend function mod_test\n\nsubroutine deflect(output, ftl_map, fx, fy, nx, ny, npts)\n ! input ftl_map should be bicubic prefiltered map\n ! fx, fy new coordinate in grid units.\n !FIXME: misleading notation. fx is deflection in first ftl_map array dimension, fy in second dimension\n !FIXME: but nx is second dimension and ny first dimension.\n !FIXME: should rename fx <-> fy here and in eval and in tex2d\n\n implicit none\n double precision, intent(in) :: ftl_map(0:ny-1,0:nx-1)\n double precision, intent(in) :: fx(0:npts-1), fy(0:npts-1)\n double precision, intent(out) :: output(0:npts-1)\n double precision, external :: eval\n integer, intent(in) :: nx, ny, npts\n integer i\n do i = 0, npts - 1\n output(i) = eval(ftl_map, fx(i), fy(i), nx, ny)\n end do\nend subroutine deflect\n", "meta": {"hexsha": "5eed1a8cb629dfc807b82b0860111e3a4c8fd8ce", "size": 3046, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lenspyx/bicubic/bicubic.f90", "max_stars_repo_name": "antolonappan/lenspyx", "max_stars_repo_head_hexsha": "649e4b74200364e5beeb8fb8329bb899634158b7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-02-02T20:03:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-14T08:16:28.000Z", "max_issues_repo_path": "lenspyx/bicubic/bicubic.f90", "max_issues_repo_name": "antolonappan/lenspyx", "max_issues_repo_head_hexsha": "649e4b74200364e5beeb8fb8329bb899634158b7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lenspyx/bicubic/bicubic.f90", "max_forks_repo_name": "antolonappan/lenspyx", "max_forks_repo_head_hexsha": "649e4b74200364e5beeb8fb8329bb899634158b7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-09-21T10:10:50.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-29T11:31:33.000Z", "avg_line_length": 40.0789473684, "max_line_length": 106, "alphanum_fraction": 0.5879842416, "num_tokens": 1129, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.941654159388319, "lm_q2_score": 0.7279754371026367, "lm_q1q2_score": 0.6855010982802274}} {"text": "c\nc\nc ... file rgrd4.f\nc\nc this file contains documentation for subroutine rgrd4 followed by\nc fortran code for rgrd4 and additional subroutines.\nc\nc ... author\nc\nc John C. Adams (NCAR 1999)\nc\nc ... subroutine rgrd4(nx,ny,nz,nt,x,y,z,t,p,mx,my,mz,mt,xx,yy,zz,tt,q,\nc + intpol,w,lw,iw,liw,ier)\nc\nc ... purpose\nc\nc subroutine rgrd4 interpolates the values p(i,j,k,l) on the orthogonal\nc grid\nc\nc (x(i),y(j),z(k),t(l))\nc\nc for i=1,...,nx;j=1,...,ny;k=1,...,nz;l=1,...,nt\nc\nc\nc onto q(ii,jj,kk,ll) on the orthogonal grid\nc\nc\nc (xx(ii),yy(jj),zz(kk),tt(ll))\nc\nc for ii=1,...,mx;jj=1,...,my;kk=1,...,mz;ll=1,...,mt\nc\nc ... language\nc\nc coded in portable FORTRAN77 and FORTRAN90\nc\nc ... test program\nc\nc file trgrd4.f on regridpack includes a test program for subroutine rgrd4\nc\nc ... method\nc\nc linear or cubic interpolation is used (independently) in\nc each direction (see argument intpol).\nc\nc ... required files\nc\nc files rgrd3.f,rgrd2.f and rgrd1.f must be loaded with rgrd4.f. they\nc include subroutines called by the routines in rgrd4.f\nc\nc ... requirements\nc\nc each of the x,y,z,t grids must be strictly montonically increasing\nc and each of the xx,yy,zz,tt grids must be montonically increasing\nc (see ier = 4). in addition the (X,Y,Z,T) region of the q grid\nc\nc [xx(1),xx(mx)] X [yy(1),yy(my)] X [zz(1),zz(mz)] X [tt(1),tt(my)]\nc\nc must lie within the (X,Y,Z,T) region of the p grid\nc\nc [x(1),x(nx)] X [y(1),y(ny)] X [z(1),z(nz)] X [t(1),t(nt)].\nc\nc extrapolation is not allowed (see ier=3). if these (X,Y,Z,T)\nc regions are identical and the orthogonal grids are UNIFORM\nc in each direction then subroutine rgrd4u (see file rgrd4u.f)\nc should be used instead of rgrd4.\nc\nc ... efficiency\nc\nc inner most loops in regridpack software vectorize. If\nc the integer arguments mx,my,mz,mt (see below) have different values,\nc optimal vectorization will be achieved if they are arranged so that\nc mx > my > mz > mt.\nc\nc *** input arguments\nc\nc ... nx\nc\nc the integer dimension of the grid vector x and the first dimension of p.\nc nx > 1 if intpol(1) = 1 or nx > 3 if intpol(1) = 3 is required.\nc\nc ... ny\nc\nc the integer dimension of the grid vector y and the second dimension of p.\nc ny > 1 if intpol(2) = 1 or ny > 3 if intpol(2) = 3 is required.\nc\nc ... nz\nc\nc the integer dimension of the grid vector z and the third dimension of p.\nc nz > 1 if intpol(3) = 1 or nz > 3 if intpol(3) = 3 is required.\nc\nc ... nt\nc\nc the integer dimension of the grid vector t and the fourth dimension of p.\nc nt > 1 if intpol(4) = 1 or nt > 3 if intpol(4) = 3 is required.\nc\nc ... x\nc\nc a real nx vector of strictly increasing values which defines the x\nc portion of the orthogonal grid on which p is given\nc\nc ... y\nc\nc a real ny vector of strictly increasing values which defines the y\nc portion of the orthogonal grid on which p is given\nc\nc ... z\nc\nc a real nz vector of strictly increasing values which defines the z\nc portion of the orthogonal grid on which p is given\nc\nc ... t\nc\nc a real nt vector of strictly increasing values which defines the t\nc portion of the orthogonal grid on which p is given\nc\nc ... p\nc\nc a real nx by ny by nz by nt array of values given on the (x,y,z,t) grid\nc\nc ... mx\nc\nc the integer dimension of the grid vector xx and the first dimension\nc of q. mx > 0 is required.\nc\nc ... my\nc\nc the integer dimension of the grid vector yy and the second dimension\nc of q. my > 0 is required.\nc\nc ... mz\nc\nc the integer dimension of the grid vector zz and the third dimension\nc of q. mz > 0 is required.\nc\nc ... mt\nc\nc the integer dimension of the grid vector tt and the fourth dimension\nc of q. mt > 0 is required.\nc\nc ... xx\nc\nc a real mx vector of increasing values which defines the x portion of the\nc orthogonal grid on which q is defined. xx(1) < x(1) or xx(mx) > x(nx)\nc is not allowed (see ier = 3)\nc\nc ... yy\nc\nc a real my vector of increasing values which defines the y portion of the\nc orthogonal grid on which q is defined. yy(1) < y(1) or yy(my) > y(ny)\nc is not allowed (see ier = 3)\nc\nc ... zz\nc\nc a real mz vector of increasing values which defines the z portion of the\nc orthogonal grid on which q is defined. zz(1) < z(1) or zz(mz) > z(nz)\nc is not allowed (see ier = 3)\nc\nc ... tt\nc\nc a real mt vector of increasing values which defines the t portion of the\nc orthogonal grid on which q is defined. tt(1) < t(1) or tt(mt) > t(nt)\nc is not allowed (see ier = 3)\nc\nc ... intpol\nc\nc an integer vector of dimension 4 which sets linear or cubic\nc interpolation in each of the x,y,z,t directions as follows:\nc\nc intpol(1) = 1 sets linear interpolation in the x direction\nc intpol(1) = 3 sets cubic interpolation in the x direction.\nc\nc intpol(2) = 1 sets linear interpolation in the y direction\nc intpol(2) = 3 sets cubic interpolation in the y direction.\nc\nc intpol(3) = 1 sets linear interpolation in the z direction\nc intpol(3) = 3 sets cubic interpolation in the z direction.\nc\nc intpol(4) = 1 sets linear interpolation in the t direction\nc intpol(4) = 3 sets cubic interpolation in the t direction.\nc\nc values other than 1 or 3 in intpol are not allowed (ier = 6).\nc\nc ... w\nc\nc a real work space of length at least lw which must be provided in the\nc routine calling rgrd4\nc\nc ... lw\nc\nc the integer length of the real work space w. let\nc\nc lwx = mx if intpol(1) = 1\nc lwx = 4*mx if intpol(1) = 3\nc\nc lwy = my+2*mx if intpol(2) = 1\nc lwy = 4*(my+mx) if intpol(2) = 3\nc\nc lwz = 2*mx*my+mz if intpol(3) = 1\nc lwz = 4*(mx*my+mz) if intpol(3) = 3\nc\nc lwt = 2*mx*my*mz+mt if intpol(4) = 1\nc lwt = 4*(mx*my*mz+mt) if intpol(4) = 3\nc\nc then lw must be greater than or equal to lwx+lwy+lwz+lwt\nc\nc ... iw\nc\nc an integer work space of length at least liw which must be provided in the\nc routine calling rgrd4\nc\nc ... liw\nc\nc the integer length of the integer work space iw. liw must be at least mx+my+mz+mt\nc\nc\nc *** output arguments\nc\nc\nc ... q\nc\nc a real mx by my by mz by mt array of values on the (xx,yy,zz,tt) grid\nc which are interpolated from p on the (x,y,z,t) grid\nc\nc ... ier\nc\nc an integer error flag set as follows:\nc\nc ier = 0 if no errors in input arguments are detected\nc\nc ier = 1 if min0(mx,my,mz,mt) < 1\nc\nc ier = 2 if nx < 2 when intpol(1)=1 or nx < 4 when intpol(1)=3 (or)\nc ny < 2 when intpol(2)=1 or ny < 4 when intpol(2)=3 (or)\nc nz < 2 when intpol(3)=1 or nz < 4 when intpol(3)=3 (or)\nc nt < 2 when intpol(4)=1 or nt < 4 when intpol(4)=3\nc\nc ier = 3 if xx(1) < x(1) or x(nx) < xx(mx) (or)\nc yy(1) < y(1) or y(ny) < yy(my) (or)\nc zz(1) < z(1) or z(nz) < zz(mz) (or)\nc tt(1) < t(1) or t(nt) < tt(mt)\nc\nc *** to avoid this flag when end points are intended to be the\nc same but may differ slightly due to roundoff error, they\nc should be set exactly in the calling routine (e.g., if both\nc grids have the same y boundaries then yy(1)=y(1) and yy(my)=y(ny)\nc should be set before calling rgrd4)\nc\nc ier = 4 if one of the grids x,y,z,t is not strictly monotonically\nc increasing or if one of the grids xx,yy,zz,tt is not\nc montonically increasing. more precisely if:\nc\nc x(i+1) <= x(i) for some i such that 1 <= i < nx (or)\nc\nc y(j+1) <= y(j) for some j such that 1 <= j < ny (or)\nc\nc z(k+1) <= z(k) for some k such that 1 <= k < nz (or)\nc\nc t(l+1) <= t(l) for some l such that 1 <= l < nt (or)\nc\nc xx(ii+1) < xx(ii) for some ii such that 1 <= ii < mx (or)\nc\nc yy(jj+1) < yy(jj) for some jj such that 1 <= jj < my (or)\nc\nc zz(kk+1) < zz(k) for some kk such that 1 <= kk < mz (or)\nc\nc tt(ll+1) < tt(l) for some ll such that 1 <= ll < mt\nc\nc ier = 5 if lw or liw is too small (insufficient work space)\nc\nc ier = 6 if any of intpol(1),intpol(2),intpol(3),intpol(4)\nc is not equal to 1 or 3\nc\nc ************************************************************************\nc\nc end of rgrd4 documentation, fortran code follows:\nc\nc ************************************************************************\nc\n subroutine rgrd4(nx,ny,nz,nt,x,y,z,t,p,mx,my,mz,mt,xx,yy,zz,\n + tt,q,intpol,w,lw,iw,liw,ier)\n implicit none\n integer nx,ny,nz,nt,mx,my,mz,mt,lw,liw,ier\n integer iw(liw),intpol(4)\n real x(nx),y(ny),z(nz),t(nt),p(nx,ny,nz,nt),w(lw)\n real xx(mx),yy(my),zz(mz),tt(mt),q(mx,my,mz,mt)\n integer l2,l3,l4,l5,l6,l7,l8,l9\n integer k2,k3,k4,k5,k6,k7,k8,k9\n integer j2,j3,j4,j5,j6,j7,j8,j9\n integer i2,i3,i4,i5\n integer lwx,lwy,lwz,lwt,mxmy,mxmymz\n integer ii,jj,kk,ll,i,j,k,l\n integer jy,kz,lt\nc\nc check input arguments\nc\n ier = 1\nc\nc check (xx,yy,zz,tt) grid resolution\nc\n if (min0(mx,my,mz,mt) .lt. 1) return\nc\nc check intpol\nc\n ier = 6\n if (intpol(1).ne.1 .and. intpol(1).ne.3) return\n if (intpol(2).ne.1 .and. intpol(2).ne.3) return\n if (intpol(3).ne.1 .and. intpol(3).ne.3) return\n if (intpol(4).ne.1 .and. intpol(4).ne.3) return\nc\nc check (x,y,z,t) grid resolution\nc\n ier = 2\n if (intpol(1).eq.1 .and. nx.lt.2) return\n if (intpol(1).eq.3 .and. nx.lt.4) return\n if (intpol(2).eq.1 .and. ny.lt.2) return\n if (intpol(2).eq.3 .and. ny.lt.4) return\n if (intpol(3).eq.1 .and. nz.lt.2) return\n if (intpol(3).eq.3 .and. nz.lt.4) return\n if (intpol(4).eq.1 .and. nt.lt.2) return\n if (intpol(4).eq.3 .and. nt.lt.4) return\nc\nc check work space length input and set minimum\nc\n ier = 5\n mxmy = mx*my\n mxmymz = mxmy*mz\n if (intpol(1).eq.1) then\n\tlwx = mx\n else\n\tlwx = 4*mx\n end if\n if (intpol(2).eq.1) then\n\tlwy = (my+2*mx)\n else\n\tlwy = 4*(mx+my)\n end if\n if (intpol(3).eq.1) then\n\tlwz = (2*mxmy+mz)\n else\n\tlwz = 4*(mxmy+mz)\n end if\n if (intpol(4).eq.1) then\n\tlwt = (2*mxmymz+mt)\n else\n\tlwt = 4*(mxmymz+mt)\n end if\n if (lw .lt. lwx+lwy+lwz+lwt) return\n if (liw .lt. mx+my+mz+mt) return\nc\nc check (xx,yy,zz,tt) grid contained in (x,y,z,t) grid\nc\n ier = 31\n if (xx(1).lt.x(1) .or. xx(mx).gt.x(nx)) return\n ier= 32 \n if (yy(1).lt.y(1) .or. yy(my).gt.y(ny)) return\n ier= 33 \n if (zz(1).lt.z(1) .or. zz(mz).gt.z(nz)) return\n ier= 34\n if (tt(1).lt.t(1) .or. tt(mt).gt.t(nt)) return\nc\nc check montonicity of grids\nc\n ier = 4\n do i=2,nx\n\tif (x(i-1).ge.x(i)) return\n end do\n do j=2,ny\n\tif (y(j-1).ge.y(j)) return\n end do\n do k=2,nz\n\tif (z(k-1).ge.z(k)) return\n end do\n do l=2,nt\n\tif (t(l-1).ge.t(l)) return\n end do\n do ii=2,mx\n\tif (xx(ii-1).gt.xx(ii)) return\n end do\n do jj=2,my\n\tif (yy(jj-1).gt.yy(jj)) return\n end do\n do kk=2,mz\n\tif (zz(kk-1).gt.zz(kk)) return\n end do\n do ll=2,mt\n\tif (tt(ll-1).gt.tt(ll)) return\n end do\nc\nc arguments o.k.\nc\n ier = 0\nc\nc set pointers for integer work space iw\nc\n jy = mx+1\n kz = mx+my+1\n lt = mx+my+mz+1\n\n if (intpol(4).eq.1) then\nc\nc linearly interpolate in nt, set work space pointers and scales\nc\n\tl2 = 1\n\tl3 = l2\n\tl4 = l3+mt\n\tl5 = l4\n\tl6 = l5\n\tl7 = l6\n\tl8 = l7+mxmymz\n\tl9 = l8+mxmymz\n\tcall linmx(nt,t,mt,tt,iw(lt),w(l3))\n\tk2 = l9\n\n\tif (intpol(3).eq.1) then\nc linear in z\n\t k3 = k2\n\t k4 = k3+mz\n\t k5 = k4\n\t k6 = k5\n\t k7 = k6\n\t k8 = k7+mxmy\n\t k9 = k8+mxmy\n\t call linmx(nz,z,mz,zz,iw(kz),w(k3))\n\t j2 = k9\n\telse\nc cubic in z\n\t k3 = k2+mz\n\t k4 = k3+mz\n\t k5 = k4+mz\n\t k6 = k5+mz\n\t k7 = k6+mxmy\n\t k8 = k7+mxmy\n\t k9 = k8+mxmy\n\t call cubnmx(nz,z,mz,zz,iw(kz),w(k2),w(k3),w(k4),w(k5))\n\t j2 = k9+mxmy\n\tend if\n\n\tif (intpol(2) .eq. 1) then\nc linear in y\n\t j3 = j2\n\t j4 = j3+my\n\t j5 = j4\n\t j6 = j5\n\t j7 = j6\n\t j8 = j7+mx\n\t j9 = j8+mx\n\t call linmx(ny,y,my,yy,iw(jy),w(j3))\n\t i2 = j9\n\telse\nc cubic in y\n\t j3 = j2+my\n\t j4 = j3+my\n\t j5 = j4+my\n\t j6 = j5+my\n\t j7 = j6+mx\n\t j8 = j7+mx\n\t j9 = j8+mx\n\t call cubnmx(ny,y,my,yy,iw(jy),w(j2),w(j3),w(j4),w(j5))\n\t i2 = j9+mx\n\tend if\n\n\tif (intpol(1) .eq. 1) then\nc linear in x\n\t i3 = i2\n\t i4 = i3\n\t i5 = i4\n\t call linmx(nx,x,mx,xx,iw,w(i3))\n\telse\nc cubic in x\n\t i3 = i2+mx\n\t i4 = i3+mx\n\t i5 = i4+mx\n\t call cubnmx(nx,x,mx,xx,iw,w(i2),w(i3),w(i4),w(i5))\n\tend if\nc\nc linearly interpolate in t\nc\n\tcall lint4(nx,ny,nz,nt,p,mx,my,mz,mt,mxmy,mxmymz,q,intpol,\n + iw(lt),w(l3),w(l7),w(l8),\n + iw(kz),w(k2),w(k3),w(k4),w(k5),w(k6),w(k7),w(k8),w(k9),\n + iw(jy),w(j2),w(j3),w(j4),w(j5),w(j6),w(j7),w(j8),w(j9),\n + iw,w(i2),w(i3),w(i4),w(i5))\n\treturn\n\n else\nc\nc cubically interpolate in t\nc\n\tl2 = 1\n\tl3 = l2+mt\n\tl4 = l3+mt\n\tl5 = l4+mt\n\tl6 = l5+mt\n\tl7 = l6+mxmymz\n\tl8 = l7+mxmymz\n\tl9 = l8+mxmymz\n\tcall cubnmx(nt,t,mt,tt,iw(lt),w(l2),w(l3),w(l4),w(l5))\n\tk2 = l9+mxmymz\n\n\tif (intpol(3).eq.1) then\nc linear in z\n\t k3 = k2\n\t k4 = k3+mz\n\t k5 = k4\n\t k6 = k5\n\t k7 = k6\n\t k8 = k7+mxmy\n\t k9 = k8+mxmy\n\t call linmx(nz,z,mz,zz,iw(kz),w(k3))\n\t j2 = k9\n\telse\nc cubic in z\n\t k3 = k2+mz\n\t k4 = k3+mz\n\t k5 = k4+mz\n\t k6 = k5+mz\n\t k7 = k6+mxmy\n\t k8 = k7+mxmy\n\t k9 = k8+mxmy\n\t call cubnmx(nz,z,mz,zz,iw(kz),w(k2),w(k3),w(k4),w(k5))\n\t j2 = k9+mxmy\n\tend if\n\n\tif (intpol(2) .eq. 1) then\n\t j3 = j2\n\t j4 = j3+my\n\t j5 = j4\n\t j6 = j5\n\t j7 = j6\n\t j8 = j7+mx\n\t j9 = j8+mx\n\t call linmx(ny,y,my,yy,iw(jy),w(j3))\n\t i2 = j9\n\telse\n\t j3 = j2+my\n\t j4 = j3+my\n\t j5 = j4+my\n\t j6 = j5+my\n\t j7 = j6+mx\n\t j8 = j7+mx\n\t j9 = j8+mx\n\t call cubnmx(ny,y,my,yy,iw(jy),w(j2),w(j3),w(j4),w(j5))\n\t i2 = j9+mx\n\tend if\nc\nc set work space portion and indices which depend on x interpolation\nc\n\tif (intpol(1) .eq. 1) then\n\t i3 = i2\n\t i4 = i3\n\t i5 = i4\n\t call linmx(nx,x,mx,xx,iw,w(i3))\n\telse\n\t i3 = i2+mx\n\t i4 = i3+mx\n\t i5 = i4+mx\n\t call cubnmx(nx,x,mx,xx,iw,w(i2),w(i3),w(i4),w(i5))\n\tend if\nc\nc cubically interpolate in t\nc\n\tcall cubt4(nx,ny,nz,nt,p,mx,my,mz,mt,mxmy,mxmymz,q,intpol,\n + iw(lt),w(l2),w(l3),w(l4),w(l5),w(l6),w(l7),w(l8),w(l9),\n + iw(kz),w(k2),w(k3),w(k4),w(k5),w(k6),w(k7),w(k8),w(k9),\n + iw(jy),w(j2),w(j3),w(j4),w(j5),w(j6),w(j7),w(j8),w(j9),\n + iw,w(i2),w(i3),w(i4),w(i5))\n\treturn\n\n end if\n end\n\n subroutine lint4(nx,ny,nz,nt,p,mx,my,mz,mt,mxmy,mxmymz,q,intpol,\n +lt,dt,pt,ptp,kz,dzm,dz,dzp,dzpp,pkm,pk,pkp,pkpp,\n +jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,ix,dxm,dx,dxp,dxpp)\nc\nc linearly interpolate in t direction\nc\n implicit none\n integer nx,ny,nz,nt,mx,my,mz,mt,mxmy,mxmymz,lsave,ll,l,iijjkk\n integer lt(mt),kz(mz),jy(my),ix(mx),intpol(4)\n real p(nx,ny,nz,nt),q(mxmymz,mt)\n real dt(mt),pt(mxmymz),ptp(mxmymz)\n real dzm(mz),dz(mz),dzp(mz),dzpp(mz)\n real pkm(mxmy),pk(mxmy),pkp(mxmy),pkpp(mxmy)\n real dym(my),dy(my),dyp(my),dypp(my)\n real pjm(mx),pj(mx),pjp(mx),pjpp(mx)\n real dxm(mx),dx(mx),dxp(mx),dxpp(mx)\n\n if (intpol(3) .eq. 1) then\nc\nc linear in z\nc\n lsave = -1\n do ll=1,mt\n\tl = lt(ll)\n\tif (l.eq.lsave) then\nc\nc l pointer has not moved since last pass (no updates or interpolation)\nc\n\telse if (l.eq.lsave+1) then\nc\nc update l and interpolate l+1\nc\n\t do iijjkk=1,mxmymz\n\t pt(iijjkk) = ptp(iijjkk)\n\t end do\n\t call lint3(nx,ny,nz,p(1,1,1,l+1),mx,my,mxmy,mz,ptp,intpol,\n + kz,dz,pk,pkp,jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,ix,\n + dxm,dx,dxp,dxpp)\n\telse\nc\nc interpolate l,l+1 in pt,ptp on xx,yy,zz mesh\nc\n call lint3(nx,ny,nz,p(1,1,1,l),mx,my,mxmy,mz,pt,intpol,kz,\n +dz,pk,pkp,jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,ix,dxm,dx,dxp,dxpp)\n call lint3(nx,ny,nz,p(1,1,1,l+1),mx,my,mxmy,mz,ptp,intpol,kz,\n +dz,pk,pkp,jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,ix,dxm,dx,dxp,dxpp)\n\tend if\nc\nc save l pointer for next pass\nc\n lsave = l\nc\nc linearly interpolate q(ii,jj,,kk,ll) from pt,ptp in t direction\nc\n\tdo iijjkk=1,mxmymz\n\t q(iijjkk,ll) = pt(iijjkk)+dt(ll)*(ptp(iijjkk)-pt(iijjkk))\n\tend do\n end do\n return\n\n else\nc\nc cubic in z\nc\n lsave = -1\n do ll=1,mt\n\tl = lt(ll)\n\tif (l.eq.lsave) then\nc\nc l pointer has not moved since last pass (no updates or interpolation)\nc\n\telse if (l.eq.lsave+1) then\nc\nc update l and interpolate l+1\nc\n\tdo iijjkk=1,mxmymz\n\t pt(iijjkk) = ptp(iijjkk)\n\tend do\n\tcall cubt3(nx,ny,nt,p(1,1,1,l+1),mx,my,mxmy,mz,ptp,intpol,\n + kz,dzm,dz,dzp,dzpp,pkm,pk,pkp,pkpp,\n + jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,ix,dxm,dx,dxp,dxpp)\n\telse\nc\nc interpolate l,l+1 in pt,ptp on xx,yy,zz mesh\nc\n\tcall cubt3(nx,ny,nt,p(1,1,1,l),mx,my,mxmy,mz,pt,intpol,\n + kz,dzm,dz,dzp,dzpp,pkm,pk,pkp,pkpp,\n + jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,ix,dxm,dx,dxp,dxpp)\n\tcall cubt3(nx,ny,nt,p(1,1,1,l+1),mx,my,mxmy,mz,ptp,intpol,\n + kz,dzm,dz,dzp,dzpp,pkm,pk,pkp,pkpp,\n + jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,ix,dxm,dx,dxp,dxpp)\n\tend if\nc\nc save l pointer for next pass\nc\n\tlsave = l\nc\nc linearly interpolate q(ii,jj,kk,ll) from pt,ptp in t direction\nc\n\tdo iijjkk=1,mxmymz\n\t q(iijjkk,ll) = pt(iijjkk)+dt(ll)*(ptp(iijjkk)-pt(iijjkk))\n\tend do\n\n end do\n return\n\n end if\n end\n\n subroutine cubt4(nx,ny,nz,nt,p,mx,my,mz,mt,mxmy,mxmymz,q,intpol,\n +lt,dtm,dt,dtp,dtpp,ptm,pt,ptp,ptpp,\n +kz,dzm,dz,dzp,dzpp,pkm,pk,pkp,pkpp,\n +jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,\n +ix,dxm,dx,dxp,dxpp)\nc\nc cubically interpolate in t\nc\n implicit none\n integer nx,ny,nz,nt,mx,my,mz,mt,mxmy,mxmymz,lsave,ll,l,iijjkk\n integer lt(mt),kz(mz),jy(my),ix(mx),intpol(4)\n real p(nx,ny,nz,nt),q(mxmymz,mt)\n real dtm(mt),dt(mt),dtp(mt),dtpp(mt)\n real ptm(mxmymz),pt(mxmymz),ptp(mxmymz),ptpp(mxmymz)\n real dzm(mz),dz(mz),dzp(mz),dzpp(mz)\n real pkm(mxmy),pk(mxmy),pkp(mxmy),pkpp(mxmy)\n real dym(my),dy(my),dyp(my),dypp(my)\n real pjm(mx),pj(mx),pjp(mx),pjpp(mx)\n real dxm(mx),dx(mx),dxp(mx),dxpp(mx)\n if (intpol(3) .eq. 1) then\nc\nc linear in z\nc\n lsave = -3\n do ll=1,mt\n\tl = lt(ll)\n\tif (l.eq.lsave) then\nc\nc l pointer has not moved since last pass (no updates or interpolation)\nc\n\telse if (l.eq.lsave+1) then\nc\nc update l-1,l,l+1 and interpolate l+2\nc\n\tdo iijjkk=1,mxmymz\n\t ptm(iijjkk) = pt(iijjkk)\n\t pt(iijjkk) = ptp(iijjkk)\n\t ptp(iijjkk) = ptpp(iijjkk)\n\tend do\n\tcall lint3(nx,ny,nz,p(1,1,1,l+2),mx,my,mxmy,mz,ptpp,intpol,kz,dz,\n + pk,pkp,jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,ix,dxm,dx,dxp,dxpp)\n\telse if (l.eq.lsave+2) then\nc\nc update l-1,l and interpolate l+1,l+2\nc\n\tdo iijjkk=1,mxmymz\n\t ptm(iijjkk) = ptp(iijjkk)\n\t pt(iijjkk) = ptpp(iijjkk)\n\tend do\n\tcall lint3(nx,ny,nz,p(1,1,1,l+1),mx,my,mxmy,mz,ptp,intpol,kz,dz,\n + pk,pkp,jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,ix,dxm,dx,dxp,dxpp)\n\tcall lint3(nx,ny,nz,p(1,1,1,l+2),mx,my,mxmy,mz,ptpp,intpol,kz,dz,\n + pk,pkp,jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,ix,dxm,dx,dxp,dxpp)\n else if (l.eq.lsave+3) then\nc\nc update l-1 and interpolate l,l+1,l+2\nc\n\tdo iijjkk=1,mxmymz\n\t ptm(iijjkk) = ptpp(iijjkk)\n\tend do\n\tcall lint3(nx,ny,nz,p(1,1,1,l),mx,my,mxmy,mz,pt,intpol,kz,dz,\n + pk,pkp,jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,ix,dxm,dx,dxp,dxpp)\n\tcall lint3(nx,ny,nz,p(1,1,1,l+1),mx,my,mxmy,mz,ptp,intpol,kz,dz,\n + pk,pkp,jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,ix,dxm,dx,dxp,dxpp)\n\tcall lint3(nx,ny,nz,p(1,1,1,l+2),mx,my,mxmy,mz,ptpp,intpol,kz,dz,\n + pk,pkp,jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,ix,dxm,dx,dxp,dxpp)\n\telse\nc\nc interpolate all four l-1,l,l+1,l+2\nc\n\tcall lint3(nx,ny,nz,p(1,1,1,l-1),mx,my,mxmy,mz,ptm,intpol,kz,dz,\n + pk,pkp,jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,ix,dxm,dx,dxp,dxpp)\n\tcall lint3(nx,ny,nz,p(1,1,1,l),mx,my,mxmy,mz,pt,intpol,kz,dz,\n + pk,pkp,jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,ix,dxm,dx,dxp,dxpp)\n\tcall lint3(nx,ny,nz,p(1,1,1,l+1),mx,my,mxmy,mz,ptp,intpol,kz,dz,\n + pk,pkp,jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,ix,dxm,dx,dxp,dxpp)\n\tcall lint3(nx,ny,nz,p(1,1,1,l+2),mx,my,mxmy,mz,ptpp,intpol,kz,dz,\n + pk,pkp,jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,ix,dxm,dx,dxp,dxpp)\n\tend if\nc\nc save l pointer for next pass\nc\n\tlsave = l\nc\nc cubically interpolate q(ii,jj,kk,ll) from ptm,pt,ptp,ptpp in t direction\nc\n\tdo iijjkk=1,mxmymz\n\t q(iijjkk,ll) = dtm(ll)*ptm(iijjkk) + dt(ll)*pt(iijjkk) +\n + dtp(ll)*ptp(iijjkk) + dtpp(ll)*ptpp(iijjkk)\n\tend do\n end do\n return\n\n else\nc\nc cubic in z\nc\n lsave = -3\n do ll=1,mt\n\tl = lt(ll)\n\tif (l.eq.lsave) then\nc\nc l pointer has not moved since last pass (no updates or interpolation)\nc\n\telse if (l.eq.lsave+1) then\nc\nc update l-1,l,l+1 and interpolate l+2\nc\n\tdo iijjkk=1,mxmymz\n\t ptm(iijjkk) = pt(iijjkk)\n\t pt(iijjkk) = ptp(iijjkk)\n\t ptp(iijjkk) = ptpp(iijjkk)\n\tend do\n call cubt3(nx,ny,nz,p(1,1,1,l+2),mx,my,mxmy,mz,ptpp,intpol,kz,dzm,\n +dz,dzp,dzpp,pkm,pk,pkp,pkpp,jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,\n +ix,dxm,dx,dxp,dxpp)\n\telse if (l.eq.lsave+2) then\nc\nc update l-1,l and interpolate l+1,l+2\nc\n\tdo iijjkk=1,mxmymz\n\t ptm(iijjkk) = ptp(iijjkk)\n\t pt(iijjkk) = ptpp(iijjkk)\n\tend do\n call cubt3(nx,ny,nz,p(1,1,1,l+1),mx,my,mxmy,mz,ptp,intpol,kz,dzm,\n +dz,dzp,dzpp,pkm,pk,pkp,pkpp,jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,\n +ix,dxm,dx,dxp,dxpp)\n call cubt3(nx,ny,nz,p(1,1,1,l+2),mx,my,mxmy,mz,ptpp,intpol,kz,dzm,\n +dz,dzp,dzpp,pkm,pk,pkp,pkpp,jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,\n +ix,dxm,dx,dxp,dxpp)\n\telse if (l.eq.lsave+3) then\nc\nc update l-1 and interpolate l,l+1,l+2\nc\n\tdo iijjkk=1,mxmymz\n\t ptm(iijjkk) = ptpp(iijjkk)\n\tend do\n call cubt3(nx,ny,nz,p(1,1,1,l),mx,my,mxmy,mz,pt,intpol,kz,dzm,\n +dz,dzp,dzpp,pkm,pk,pkp,pkpp,jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,\n +ix,dxm,dx,dxp,dxpp)\n call cubt3(nx,ny,nz,p(1,1,1,l+1),mx,my,mxmy,mz,ptp,intpol,kz,dzm,\n +dz,dzp,dzpp,pkm,pk,pkp,pkpp,jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,\n +ix,dxm,dx,dxp,dxpp)\n call cubt3(nx,ny,nz,p(1,1,1,l+2),mx,my,mxmy,mz,ptpp,intpol,kz,dzm,\n +dz,dzp,dzpp,pkm,pk,pkp,pkpp,jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,\n +ix,dxm,dx,dxp,dxpp)\n\telse\nc\nc interpolate all four l-1,l,l+1,l+2\nc\n call cubt3(nx,ny,nz,p(1,1,1,l-1),mx,my,mxmy,mz,ptm,intpol,kz,dzm,\n +dz,dzp,dzpp,pkm,pk,pkp,pkpp,jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,\n +ix,dxm,dx,dxp,dxpp)\n call cubt3(nx,ny,nz,p(1,1,1,l),mx,my,mxmy,mz,pt,intpol,kz,dzm,\n +dz,dzp,dzpp,pkm,pk,pkp,pkpp,jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,\n +ix,dxm,dx,dxp,dxpp)\n call cubt3(nx,ny,nz,p(1,1,1,l+1),mx,my,mxmy,mz,ptp,intpol,kz,dzm,\n +dz,dzp,dzpp,pkm,pk,pkp,pkpp,jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,\n +ix,dxm,dx,dxp,dxpp)\n call cubt3(nx,ny,nz,p(1,1,1,l+2),mx,my,mxmy,mz,ptpp,intpol,kz,dzm,\n +dz,dzp,dzpp,pkm,pk,pkp,pkpp,jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,\n +ix,dxm,dx,dxp,dxpp)\n\tend if\nc\nc save l pointer for next pass\nc\n\tlsave = l\nc\nc cubically interpolate q(ii,jj,kk,ll) from ptm,pt,ptp,ptpp in t direction\nc\n\tdo iijjkk=1,mxmymz\n\t q(iijjkk,ll) = dtm(ll)*ptm(iijjkk) + dt(ll)*pt(iijjkk) +\n + dtp(ll)*ptp(iijjkk) + dtpp(ll)*ptpp(iijjkk)\n\tend do\n end do\n return\n end if\n\n end\n\n", "meta": {"hexsha": "a8e1e4350a42c2b203a1e37cd4a826748c2a3958", "size": 23578, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "grs/fortran/grs/interp/interp4d.f", "max_stars_repo_name": "Tristanovsk/grs", "max_stars_repo_head_hexsha": "ba5da28f6df0438e15404324c3488c799fb81212", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-06-14T20:43:22.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-05T09:32:41.000Z", "max_issues_repo_path": "grs/fortran/grs_a/interp/interp4d.f", "max_issues_repo_name": "Tristanovsk/grs", "max_issues_repo_head_hexsha": "ba5da28f6df0438e15404324c3488c799fb81212", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "grs/fortran/grs_a/interp/interp4d.f", "max_forks_repo_name": "Tristanovsk/grs", "max_forks_repo_head_hexsha": "ba5da28f6df0438e15404324c3488c799fb81212", "max_forks_repo_licenses": ["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.3844367015, "max_line_length": 88, "alphanum_fraction": 0.5942403936, "num_tokens": 10151, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382200964034, "lm_q2_score": 0.7956581049086031, "lm_q1q2_score": 0.6854898675082353}} {"text": "c\nc\nc =========================================================\n subroutine qinit(maxmx,meqn,mbc,mx,xlower,dx,q,maux,aux)\nc =========================================================\nc\nc # Set initial conditions for q.\nc # Pulse in pressure, zero velocity\nc\nc\n implicit double precision (a-h,o-z)\n dimension q(1-mbc:maxmx+mbc, meqn)\n dimension aux(1-mbc:maxmx+mbc, *)\n common /cqinit/ beta,ic\nc\nc\n do 150 i=1,mx\n\t xcell = xlower + (i-0.5d0)*dx\n\n\t go to (10,20,30) ic\n\n\n 10 continue\nc # half ellipse:\n\t if (xcell.gt.-4d0 .and. xcell.lt.-2d0) then\n\t q(i,1) = dsqrt(1.d0 - (xcell+3.d0)**2)\n\t else\n\t q(i,1) = 0.d0\n\t endif\n\t q(i,2) = q(i,1)\n go to 150\n\n 20 continue\nc # single discontinuity:\n if (xcell .lt. -2.d0) then\n\t q(i,1) = 1.d0\n\t else\n\t q(i,1) = 0.d0\n\t endif\n\t q(i,2) = q(i,1)\n go to 150\n\n 30 continue\nc # Gaussian and square pulse:\n\t q(i,1) = dexp(-beta*(xcell+2.0d0)**2) \n\t if (dabs(q(i,1)) .lt. 1d-30) q(i,1) = 0.d0\n\t if (xcell.gt.-4.d0 .and. xcell.lt.-3.d0) then\n\t q(i,1) = q(i,1) + 0.5d0\n\t endif\n\t q(i,2) = q(i,1)\n go to 150\n\n 150 continue\nc\n return\n end\n", "meta": {"hexsha": "658ad241b1a518df98444e30f79fbae8b6998a3f", "size": 1218, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "book/chap9/acoustics/interface/qinit.f", "max_stars_repo_name": "geoflows/geoclaw-4.x", "max_stars_repo_head_hexsha": "c8879d25405017b38392aa3b1ea422ff3e3604ea", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2016-11-13T03:11:51.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-07T18:59:48.000Z", "max_issues_repo_path": "book/chap9/acoustics/interface/qinit.f", "max_issues_repo_name": "che-wenchao/D-Claw", "max_issues_repo_head_hexsha": "8ab5d971c9a7a7130e03a447a4b8642e292f4e88", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2020-01-14T18:00:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T14:25:24.000Z", "max_forks_repo_path": "book/chap9/acoustics/interface/qinit.f", "max_forks_repo_name": "che-wenchao/D-Claw", "max_forks_repo_head_hexsha": "8ab5d971c9a7a7130e03a447a4b8642e292f4e88", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-01-14T17:15:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-03T17:28:44.000Z", "avg_line_length": 21.3684210526, "max_line_length": 63, "alphanum_fraction": 0.4704433498, "num_tokens": 471, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382129861583, "lm_q2_score": 0.7956581000631542, "lm_q1q2_score": 0.6854898576763718}} {"text": "! vim: set ft=fortran sw=4 ts=4 :\n\nmodule mod_arrays\n\n implicit none\n\n private\n public :: reverse\n public :: average\n public :: std\n public :: moving_average\n public :: moving_std\n\ncontains\n\n pure function reverse(x)\n real, intent(in) :: x(:)\n real :: reverse(size(x))\n\n reverse = x(size(x):1:-1)\n end function reverse\n\n\n pure real function average(x)\n real, intent(in) :: x(:)\n\n average = sum(x) / size(x)\n end function average\n\n\n pure real function std(x)\n real, intent(in) :: x(:)\n\n std = sqrt(average((x -average(x))**2))\n end function std\n\n\n pure function moving_average(x, window_size) result(ma)\n real, intent(in) :: x(:)\n integer, intent(in) :: window_size\n real :: ma(size(x))\n integer :: i, lower_bound\n\n do i = 1, size(x)\n lower_bound = max(i - window_size, 1)\n ma(i) = average(x(lower_bound:i))\n end do\n end function moving_average\n\n\n pure function moving_std(x, window_size) result(ms)\n real, intent(in) :: x(:)\n integer, intent(in) :: window_size\n real :: ms(size(x))\n integer :: i, lower_bound\n\n do i = 1, size(x)\n lower_bound = max(i - window_size, 1)\n ms(i) = std(x(lower_bound:i))\n end do\n end function moving_std\n\n\nend module\n", "meta": {"hexsha": "67e7f53f6ad641df209d642ff6f5deb0c9345543", "size": 1373, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran/ModernFortran/stock-prices/mod_array.f90", "max_stars_repo_name": "kkirstein/proglang-playground", "max_stars_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Fortran/ModernFortran/stock-prices/mod_array.f90", "max_issues_repo_name": "kkirstein/proglang-playground", "max_issues_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran/ModernFortran/stock-prices/mod_array.f90", "max_forks_repo_name": "kkirstein/proglang-playground", "max_forks_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.1230769231, "max_line_length": 59, "alphanum_fraction": 0.5564457393, "num_tokens": 351, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310357, "lm_q2_score": 0.795658090372256, "lm_q1q2_score": 0.6854898464986305}} {"text": " Program dorgql_example\n\n! DORGQL Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_example_aux, Only: nagf_file_print_matrix_real_gen\n Use lapack_interfaces, Only: dgeqlf, dorgql\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nb = 64, nin = 5, nout = 6\n! .. Local Scalars ..\n Integer :: i, ifail, info, lda, lwork, m, n\n Character (30) :: title\n! .. Local Arrays ..\n Real (Kind=dp), Allocatable :: a(:, :), tau(:), work(:)\n! .. Executable Statements ..\n Write (nout, *) 'DORGQL Example Program Results'\n Write (nout, *)\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) m, n\n lda = m\n lwork = nb*n\n Allocate (a(lda,n), tau(n), work(lwork))\n\n! Read A from data file\n\n Read (nin, *)(a(i,1:n), i=1, m)\n\n! Compute the QL factorization of A\n\n Call dgeqlf(m, n, a, lda, tau, work, lwork, info)\n\n! Form the leading N columns of Q explicitly\n\n Call dorgql(m, n, n, a, lda, tau, work, lwork, info)\n\n! Form the heading for NAGF_FILE_PRINT_MATRIX_REAL_GEN\n\n Write (title, 100) n\n Flush (nout)\n\n! Print the leading N columns of Q\n\n! ifail: behaviour on error exit\n! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft\n ifail = 0\n Call nagf_file_print_matrix_real_gen('General', ' ', m, n, a, lda, &\n title, ifail)\n\n100 Format ('The leading ', I4, ' columns of Q')\n End Program\n", "meta": {"hexsha": "84a341f8d83ed5034b14b32d2b1d326e62952c3d", "size": 1730, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/dorgql_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/dorgql_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/dorgql_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 29.3220338983, "max_line_length": 90, "alphanum_fraction": 0.598265896, "num_tokens": 516, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.86153820232079, "lm_q2_score": 0.7956580903722561, "lm_q1q2_score": 0.6854898408413063}} {"text": "c program DRDCHOL\nc>> 1996-06-17 DRDCHOL Krogh Minor format change for C conversion.\nc>> 1996-05-28 DRDCHOL Krogh Added external statement.\nc>> 1994-10-19 DRDCHOL Krogh Changes to use M77CON\nc>> 1994-08-09 DRDCHOL WVS remove '0' from formats\nc>> 1992-03-04 DRDCHOL Krogh Initial version.\nc Demonstration driver for DCHOL\nc ------------------------------------------------------------------\nc--D replaces \"?\": DR?CHOL, ?CHOL, ?DOT\nc ------------------------------------------------------------------\n integer LDP, M, N\n parameter (M = 3, N = 2, LDP = 2)\n integer I, IERR, J\n double precision A(M,N), B(M)\n external DDOT\n double precision P(LDP,LDP), D(LDP), U, DDOT\n data A(1,1), A(1,2), B(1) / 0.7D0, 0.6D0, 1.726D0 /\n data A(2,1), A(2,2), B(2) / -0.8D0, 0.5D0, -5.415D0 /\n data A(3,1), A(3,2), B(3) / 0.6D0, -0.7D0, 5.183D0 /\nc ------------------------------------------------------------------\n U = DDOT(M, B, 1, B, 1)\n do 20 I = 1, N\n D(I) = DDOT(M, A(1,I), 1, B, 1)\n do 10 J = 1, N\n P(I,J) = DDOT(M, A(1,I), 1, A(1, J), 1)\n 10 continue\n 20 continue\n call DCHOL(P, LDP, N, D, U, 0.0d0, IERR)\n print '('' X() = '',2f15.6)', D(1), D(2)\n print '('' RNORM = '',f15.6)', U\n if (IERR .ne. 0) print '(\n * '' Matrix failed conditioning test in DCHOL, IERR = '',I3)',IERR\n end\n", "meta": {"hexsha": "761cda13196da7d6054e940d98e262b4bde4e38e", "size": 1417, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drdchol.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drdchol.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drdchol.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 41.6764705882, "max_line_length": 72, "alphanum_fraction": 0.4565984474, "num_tokens": 552, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319863, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.685445622992732}} {"text": "cc Copyright (C) 2004-2009: Leslie Greengard and June-Yub Lee \ncc Contact: greengard@cims.nyu.edu\ncc\ncc This software is being released under a FreeBSD license\ncc (see license.txt in this directory). \nc***********************************************************************\n subroutine dirft1d1(nj,xj,cj, iflag, ms,fk)\n implicit none\n integer nj, iflag, ms\n real*8 xj(nj)\n complex*16 cj(nj), fk(-ms/2:(ms-1)/2)\nc ----------------------------------------------------------------------\nc direct computation of nonuniform FFT\nc\nc nj\nc fk(k1) = SUM cj(j) exp(+/-i k1 xj(j)) \nc j=1\nc\nc for -ms/2 <= k1 <= (ms-1)/2\nc\nc If (iflag .ge.0) the + sign is used in the exponential.\nc If (iflag .lt.0) the - sign is used in the exponential.\nc\nc***********************************************************************\n integer j, k1\n complex*16 zf, cm1\nc\n do k1 = -ms/2, (ms-1)/2\n fk(k1) = dcmplx(0d0,0d0)\n enddo\nc\n do j = 1, nj\n if (iflag .ge. 0) then\n zf = dcmplx(dcos(xj(j)),+dsin(xj(j)))\n else\n zf = dcmplx(dcos(xj(j)),-dsin(xj(j)))\n endif\nc\n cm1 = cj(j)\n do k1 = 0, (ms-1)/2\n fk(k1) = fk(k1) + cm1\n cm1 = cm1 * zf\n enddo\nc\n zf = dconjg(zf)\n cm1 = cj(j)\n do k1 = -1, -ms/2, -1\n cm1 = cm1 * zf\n fk(k1) = fk(k1) + cm1\n enddo\n enddo\n end\nc\nc\nc\nc\nc\nc***********************************************************************\n subroutine dirft1d2(nj,xj,cj, iflag, ms,fk)\n implicit none\n integer nj, iflag, ms\n real*8 xj(nj)\n complex*16 cj(nj), fk(-ms/2:(ms-1)/2)\nc ----------------------------------------------------------------------\nc direct computation of nonuniform FFT\nc\nc cj(j) = SUM fk(k1) exp(+/-i k1 xj(j)) \nc k1 \nc for j = 1,...,nj\nc\nc where -ms/2 <= k1 <= (ms-1)/2\nc\nc\nc If (iflag .ge.0) the + sign is used in the exponential.\nc If (iflag .lt.0) the - sign is used in the exponential.\nc***********************************************************************\n integer j, k1\n complex*16 zf, cm1\nc\n do j = 1, nj\n if (iflag .ge. 0) then\n zf = dcmplx(dcos(xj(j)),+dsin(xj(j)))\n else\n zf = dcmplx(dcos(xj(j)),-dsin(xj(j)))\n endif\nc\n cj(j) = fk(0)\n cm1 = zf\n do k1 = 1, (ms-1)/2\n cj(j) = cj(j) + cm1*fk(k1)+dconjg(cm1)*fk(-k1)\n cm1 = cm1 * zf\n enddo\n if (ms/2*2.eq.ms) cj(j) = cj(j) + dconjg(cm1)*fk(-ms/2)\n enddo\n end\nc\nc\nc\nc\nc\nc\nc***********************************************************************\n subroutine dirft1d3(nj,xj,cj, iflag, nk,sk,fk)\n implicit none\n integer nj, iflag, nk\n real*8 xj(nj), sk(nk)\n complex*16 cj(nj), fk(nk)\nc ----------------------------------------------------------------------\nc direct computation of nonuniform FFT\nc\nc nj\nc fk(k) = SUM cj(j) exp(+/-i s(k) xj(j)) \nc j=1 \nc\nc for k = 1, ..., nk\nc\nc If (iflag .ge.0) the + sign is used in the exponential.\nc If (iflag .lt.0) the - sign is used in the exponential.\nc\nc***********************************************************************\n integer j, k\n real*8 ssk\nc\n do k = 1, nk\n if (iflag .ge. 0) then\n ssk = sk(k)\n else\n ssk = -sk(k)\n endif\nc\n fk(k) = dcmplx(0d0, 0d0)\n do j = 1, nj\n fk(k) = fk(k) +cj(j)*dcmplx(dcos(ssk*xj(j)),dsin(ssk*xj(j)))\n enddo\n enddo\n end\n", "meta": {"hexsha": "4e36286c165229f688453abf7ae3ca664d850676", "size": 3742, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "fortran/directft/dirft1d.f", "max_stars_repo_name": "wendazhou/finufft", "max_stars_repo_head_hexsha": "ba52c1d823186aac3ae33341921136b9ed3b6422", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 134, "max_stars_repo_stars_event_min_datetime": "2018-08-23T02:05:01.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-27T05:13:20.000Z", "max_issues_repo_path": "fortran/directft/dirft1d.f", "max_issues_repo_name": "wendazhou/finufft", "max_issues_repo_head_hexsha": "ba52c1d823186aac3ae33341921136b9ed3b6422", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 157, "max_issues_repo_issues_event_min_datetime": "2018-09-14T16:36:31.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T23:42:44.000Z", "max_forks_repo_path": "fortran/directft/dirft1d.f", "max_forks_repo_name": "wendazhou/finufft", "max_forks_repo_head_hexsha": "ba52c1d823186aac3ae33341921136b9ed3b6422", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 66, "max_forks_repo_forks_event_min_datetime": "2018-09-25T15:50:59.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T00:42:28.000Z", "avg_line_length": 27.3138686131, "max_line_length": 72, "alphanum_fraction": 0.3947087119, "num_tokens": 1182, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869948899665, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.6854456160155818}} {"text": " SUBROUTINE ZLAEV2( A, B, C, RT1, RT2, CS1, SN1 )\n*\n* -- LAPACK auxiliary routine (version 3.0) --\n* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,\n* Courant Institute, Argonne National Lab, and Rice University\n* October 31, 1992\n*\n* .. Scalar Arguments ..\n DOUBLE PRECISION CS1, RT1, RT2\n COMPLEX*16 A, B, C, SN1\n* ..\n*\n* Purpose\n* =======\n*\n* ZLAEV2 computes the eigendecomposition of a 2-by-2 Hermitian matrix\n* [ A B ]\n* [ CONJG(B) C ].\n* On return, RT1 is the eigenvalue of larger absolute value, RT2 is the\n* eigenvalue of smaller absolute value, and (CS1,SN1) is the unit right\n* eigenvector for RT1, giving the decomposition\n*\n* [ CS1 CONJG(SN1) ] [ A B ] [ CS1 -CONJG(SN1) ] = [ RT1 0 ]\n* [-SN1 CS1 ] [ CONJG(B) C ] [ SN1 CS1 ] [ 0 RT2 ].\n*\n* Arguments\n* =========\n*\n* A (input) COMPLEX*16\n* The (1,1) element of the 2-by-2 matrix.\n*\n* B (input) COMPLEX*16\n* The (1,2) element and the conjugate of the (2,1) element of\n* the 2-by-2 matrix.\n*\n* C (input) COMPLEX*16\n* The (2,2) element of the 2-by-2 matrix.\n*\n* RT1 (output) DOUBLE PRECISION\n* The eigenvalue of larger absolute value.\n*\n* RT2 (output) DOUBLE PRECISION\n* The eigenvalue of smaller absolute value.\n*\n* CS1 (output) DOUBLE PRECISION\n* SN1 (output) COMPLEX*16\n* The vector (CS1, SN1) is a unit right eigenvector for RT1.\n*\n* Further Details\n* ===============\n*\n* RT1 is accurate to a few ulps barring over/underflow.\n*\n* RT2 may be inaccurate if there is massive cancellation in the\n* determinant A*C-B*B; higher precision or correctly rounded or\n* correctly truncated arithmetic would be needed to compute RT2\n* accurately in all cases.\n*\n* CS1 and SN1 are accurate to a few ulps barring over/underflow.\n*\n* Overflow is possible only if RT1 is within a factor of 5 of overflow.\n* Underflow is harmless if the input data is 0 or exceeds\n* underflow_threshold / macheps.\n*\n* =====================================================================\n*\n* .. Parameters ..\n DOUBLE PRECISION ZERO\n PARAMETER ( ZERO = 0.0D0 )\n DOUBLE PRECISION ONE\n PARAMETER ( ONE = 1.0D0 )\n* ..\n* .. Local Scalars ..\n DOUBLE PRECISION T\n COMPLEX*16 W\n* ..\n* .. External Subroutines ..\n EXTERNAL DLAEV2\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC ABS, DBLE, DCONJG\n* ..\n* .. Executable Statements ..\n*\n IF( ABS( B ).EQ.ZERO ) THEN\n W = ONE\n ELSE\n W = DCONJG( B ) / ABS( B )\n END IF\n CALL DLAEV2( DBLE( A ), ABS( B ), DBLE( C ), RT1, RT2, CS1, T )\n SN1 = W*T\n RETURN\n*\n* End of ZLAEV2\n*\n END\n", "meta": {"hexsha": "372566512b561bace361fca07b93d9a44e34dd10", "size": 2842, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "external/lapack/zlaev2.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "external/lapack/zlaev2.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "external/lapack/zlaev2.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 29.2989690722, "max_line_length": 72, "alphanum_fraction": 0.5570021112, "num_tokens": 902, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869819218865, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.6854456103056952}} {"text": "program tarefab2\n implicit real(8) (a-h,o-z)\n\n g = 9.8d0\n a_l = 9.8d0\n \n open(10, file='saida-b2-10407962.dat')\n\n do j = 1, 20\n theta_0 = rand()\n Tb2 = periodob2(g, a_l, theta_0)\n\n write(10,'(F0.8,\" \",F0.8)') theta_0, Tb2\n end do\n\n close(10)\n\ncontains\n function periodob2(g, a_l, theta_0)\n implicit real(8) (a-h,o-z)\n parameter (pi = 4d0*atan(1d0))\n periodob2 = 2*pi*sqrt(a_l/g)*(1 + theta_0**2/16d0)\n return\n end function\nend program tarefab2\n", "meta": {"hexsha": "eff97bec24d2bdd74108d9efac5a11964d33891d", "size": 523, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "projeto-5/tarefa-b/tarefa-b2-10407962.f90", "max_stars_repo_name": "ArexPrestes/introducao-fisica-computacional", "max_stars_repo_head_hexsha": "bf6e7a0134c11ddbaf9125c42eb0982250f970d9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "projeto-5/tarefa-b/tarefa-b2-10407962.f90", "max_issues_repo_name": "ArexPrestes/introducao-fisica-computacional", "max_issues_repo_head_hexsha": "bf6e7a0134c11ddbaf9125c42eb0982250f970d9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "projeto-5/tarefa-b/tarefa-b2-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": 20.1153846154, "max_line_length": 58, "alphanum_fraction": 0.552581262, "num_tokens": 206, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.7905303112671294, "lm_q1q2_score": 0.685418049076142}} {"text": " e ! Not available. Can be calculated EXP(1.0)\n pi ! Not available. Can be calculated 4.0*ATAN(1.0)\n SQRT(x) ! square root\n LOG(x) ! natural logarithm\n LOG10(x) ! logarithm to base 10\n EXP(x) ! exponential\n ABS(x) ! absolute value\n FLOOR(x) ! floor - Fortran 90 or later only\n CEILING(x) ! ceiling - Fortran 90 or later only\n x**y ! x raised to the y power\n", "meta": {"hexsha": "3fe37399760c33f1dd5d3889213ef251b4cf27d2", "size": 399, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Real-constants-and-functions/Fortran/real-constants-and-functions.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/Real-constants-and-functions/Fortran/real-constants-and-functions.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/Real-constants-and-functions/Fortran/real-constants-and-functions.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": 36.2727272727, "max_line_length": 60, "alphanum_fraction": 0.6165413534, "num_tokens": 125, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693645535724, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6854174177794577}} {"text": "use FEMSolverClass\nimplicit none\n\nreal(real64),allocatable :: K(:,:), M(:,:),eigen_vector(:),eigen_value(:),&\nx(:,:),eigen_vectors(:,:),lambda_mins(:)\nreal(real64)::lambda_min\ninteger(int32) :: i\n\nK = zeros(4,4)\nM = zeros(4,4)\n\nK(1,:) = [1.0d0, 2.0d0, 0.0d0,0.0d0]\nK(2,:) = [2.0d0, 2.0d0, 3.0d0,0.0d0]\nK(3,:) = [0.0d0, 3.0d0, 5.0d0,0.0d0]\nK(4,:) = [0.0d0, 0.0d0, 0.0d0,1.0d0]\n\nM(1,:) = [1.0d0, 0.0d0, 0.0d0,0.0d0]\nM(2,:) = [0.0d0, 1.0d0, 0.0d0,0.0d0]\nM(3,:) = [0.0d0, 0.0d0, 1.0d0,0.0d0]\nM(4,:) = [0.0d0, 0.0d0, 0.0d0,1.0d0]\n\neigen_vector = LOBPCG_dense_single(K,M,lambda_min)\n\nprint *, \"eigen_value\",lambda_min\nprint *, \"eigen_vector\",eigen_vectors\n\nend", "meta": {"hexsha": "7d3b6d1b531eb5f2cee4e6d213f4097b70eb561c", "size": 655, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/fem/LOBPCG_dense_sample.f90", "max_stars_repo_name": "kazulagi/plantFEM_binary", "max_stars_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-10T11:49:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-10T11:49:34.000Z", "max_issues_repo_path": "Tutorial/fem/LOBPCG_dense_sample.f90", "max_issues_repo_name": "kazulagi/plantFEM_binary", "max_issues_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Tutorial/fem/LOBPCG_dense_sample.f90", "max_forks_repo_name": "kazulagi/plantFEM_binary", "max_forks_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.2592592593, "max_line_length": 75, "alphanum_fraction": 0.6030534351, "num_tokens": 371, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693688269985, "lm_q2_score": 0.7217432062975979, "lm_q1q2_score": 0.6854174151798139}} {"text": "C AUTHORS: MIKE MYERS AND LUCIA SPAGNUOLO\nC DATE: MAY 8, 1989\n\nC Variables:\nC SCORE -> an array of test scores\nC SUM -> sum of the test scores\nC COUNT -> counter of scores read in\nC I -> loop counter\n\n REAL FUNCTION COMPAV(SCORE,COUNT)\n INTEGER SUM,COUNT,J,SCORE(5)\n\n DO 30 I = 1,COUNT\n SUM = SUM + SCORE(I)\n30 CONTINUE\n COMPAV = SUM/COUNT\n END\n\n\n PROGRAM AVENUM\nC\nC MAIN PROGRAM\nC\nC AUTHOR: LOIS BIGBIE\nC DATE: MAY 15, 1990\nC\nC Variables:\nC MAXNOS -> maximum number of input values\nC NUMS -> an array of numbers\nC COUNT -> exact number of input values\nC AVG -> average returned by COMPAV\nC I -> loop counter\nC\n\n PARAMETER(MAXNOS=5)\n INTEGER I, COUNT\n REAL NUMS(MAXNOS), AVG\n COUNT = 0\n DO 80 I = 1,MAXNOS\n READ (5,*,END=100) NUMS(I)\n COUNT = COUNT + 1\n80 CONTINUE\n100 AVG = COMPAV(NUMS, COUNT)\n END\n", "meta": {"hexsha": "4defec6da4d6e15452c7cebebf8d5364d2ecd9d7", "size": 1201, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "test/average.f", "max_stars_repo_name": "kurtsansom/ftnchek", "max_stars_repo_head_hexsha": "cb5b24689fec20e0dac4d158ae57a5b7387e9723", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-17T16:41:23.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-17T16:41:23.000Z", "max_issues_repo_path": "test/average.f", "max_issues_repo_name": "OS2World/DEV-FORTRAN-UTIL-ftnchek", "max_issues_repo_head_hexsha": "6a0369cb369312d7f4cfc96c6ce27a28e28acfd5", "max_issues_repo_licenses": ["MIT"], "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/average.f", "max_forks_repo_name": "OS2World/DEV-FORTRAN-UTIL-ftnchek", "max_forks_repo_head_hexsha": "6a0369cb369312d7f4cfc96c6ce27a28e28acfd5", "max_forks_repo_licenses": ["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.6888888889, "max_line_length": 56, "alphanum_fraction": 0.46877602, "num_tokens": 318, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952948443462, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6853757870637726}} {"text": "subroutine splint(xa,ya,y2a,n,x,nrow,ncol,y)\nINTEGER, INTENT(IN) :: n, nrow, ncol\nREAL, INTENT(IN) :: x(nrow,ncol)\nREAL, INTENT(IN) :: xa(n,1), ya(n,1), y2a(n,1)\nREAL, INTENT(OUT) :: y(nrow,ncol)\nINTEGER :: k, khi, klo, indr, indc\nREAL :: a, b, h\nklo = 1\nkhi = n\n!print *, 'The fifth argument in Splint.f90 is', x\ndo indr=1,nrow\n do indc=1,ncol\n klo = 1\n khi = n\n do WHILE (khi-klo>1)\n k=(khi+klo)/2\n if (xa(k,1)>x(indr,indc)) then\n khi=k\n else\n klo=k\n end if\n END do\n h = xa(khi,1)-xa(klo,1)\n a = (xa(khi,1)-x(indr,indc))/h\n b = (x(indr,indc)-xa(klo,1))/h\n y(indr,indc) = a*ya(klo,1)+b*ya(khi,1)+((a**3-a)*y2a(klo,1)+(b**3-b)*y2a(khi,1))*(h**2)/6.0\n end do\nend do\nend subroutine\n", "meta": {"hexsha": "cfe3c58a03608b0e787de2baea9b968181f7b467", "size": 776, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "CGMPortfolio/Related/SourceCode/Fortran/splint.f90", "max_stars_repo_name": "HsinYiHung/HARK_HY", "max_stars_repo_head_hexsha": "086c46af5bd037fe1ced6906c6ea917ed58b134f", "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": "CGMPortfolio/Related/SourceCode/Fortran/splint.f90", "max_issues_repo_name": "HsinYiHung/HARK_HY", "max_issues_repo_head_hexsha": "086c46af5bd037fe1ced6906c6ea917ed58b134f", "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": "CGMPortfolio/Related/SourceCode/Fortran/splint.f90", "max_forks_repo_name": "HsinYiHung/HARK_HY", "max_forks_repo_head_hexsha": "086c46af5bd037fe1ced6906c6ea917ed58b134f", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.8666666667, "max_line_length": 95, "alphanum_fraction": 0.5257731959, "num_tokens": 349, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952948443462, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6853757870637726}} {"text": " program DRDRFT\nc>> 1996-06-19 DRDRFT Krogh Minor change for C conversion.\nc>> 1994-10-19 DRDRFT Krogh Changes to use M77CON\nc>> 1994-08-09 DRDRFT WVS Remove '0' from format\nc>> 1993-02-04 DRDRFT CLL\nc>> 1989-05-07 DRDRFT FTK, CLL\nc>> 1989-05-04 DRDRFT FTK, CLL\nc Demo driver for DRFT -- Multi-dimensional real Fourier transform\nc ------------------------------------------------------------------\nc--D replaces \"?\": DR?RFT, ?RFT\nc ------------------------------------------------------------------\n integer J, J1, J2, K, L, M(2), MS, N, N2, N4, ND\n double precision A(16, 16), ONE, PI, S(3), SIG, SIGD, TEMP, ZERO\n parameter (PI = 3.1415926535897932384D0)\n parameter (ONE = 1.D0)\n parameter (ZERO = 0.D0)\n data M / 4, 4 /, ND / 2 /\nc ------------------------------------------------------------------\nc Start of code -- Construct A\n N = 2 ** M(1)\n N2 = N /2\n N4 = N2 / 2\n SIGD = PI / N2\n do 20 J1 = 1, N\n do 10 J2 = 1, N\n A(J1, J2) = ZERO\n if (abs(J1-N2-1) + abs(J2-N2-1) .le. N4) A(J1, J2) = ONE\n 10 continue\n 20 continue\nc ------------------------------------------------------------------\nc Compute Fourier transform and apply sigma factors\n MS = 0\n call DRFT (A, 'A', M, ND, MS, S)\n do 50 J1 = 1, N, 2\n A(J1, N2+1) = ZERO\n A(J1+1, N2+1) = ZERO\n do 40 J2 = 1, N2\n SIG = ONE\n if (J1 .EQ. 1) then\nc No change in SIG due to J\n if (J2 .NE. 1) then\n J = J2 - 1\n K = 1\n else\n A(2, 1) = ZERO\n go to 40\n end if\n else\n J = J1 / 2\n K = 0\n end if\nc Get nontrivial sigma factors * SIG\n 30 continue\n if (J .LT. N4) then\n TEMP = S(J)\n else if (J .EQ. N4) then\n TEMP = ONE\n else\n TEMP = S(N2-J)\n end if\n SIG = SIG * TEMP / (SIGD * dble(J))\n if (K .EQ. 0) then\n if (J2 .NE. 1) then\n J = J2 - 1\n K = 1\n go to 30\n end if\n else\nc Apply sigma factors\n if (J1 .EQ. 1) then\n A(1, N-J2+2) = ZERO\n A(2, N-J2+2) = ZERO\n else\n A(J1, N-J2+2) = SIG * A(J1, N-J2+2)\n A(J1+1, N-J2+2) = SIG * A(J1+1, N-J2+2)\n end if\n end if\n A(J1, J2) = SIG * A(J1, J2)\n A(J1+1, J2) = SIG * A(J1+1, J2)\n 40 continue\n 50 continue\n call DRFT (A, 'S', M, ND, MS, S)\n print '(/'' Smoothed A'')'\n do 60 L = 1, 9\n print'(9f8.4)', (A(L,N), N = 1, 9)\n 60 continue\n stop\n end\n", "meta": {"hexsha": "e791305aa65696ff39d630b858fffdc3016d02f6", "size": 2983, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drdrft.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drdrft.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drdrft.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": 33.5168539326, "max_line_length": 72, "alphanum_fraction": 0.3657391887, "num_tokens": 965, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333484, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.685375780794809}} {"text": "! In the 20x20 grid below, four numbers along a diagonal line have been marked in red.\n!\n! 08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08\n! 49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00\n! 81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65\n! 52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91\n! 22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80\n! 24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50\n! 32 98 81 28 64 23 67 10[26]38 40 67 59 54 70 66 18 38 64 70\n! 67 26 20 68 02 62 12 20 95[63]94 39 63 08 40 91 66 49 94 21\n! 24 55 58 05 66 73 99 26 97 17[78]78 96 83 14 88 34 89 63 72\n! 21 36 23 09 75 00 76 44 20 45 35[14]00 61 33 97 34 31 33 95\n! 78 17 53 28 22 75 31 67 15 94 03 80 04 62 16 14 09 53 56 92\n! 16 39 05 42 96 35 31 47 55 58 88 24 00 17 54 24 36 29 85 57\n! 86 56 00 48 35 71 89 07 05 44 44 37 44 60 21 58 51 54 17 58\n! 19 80 81 68 05 94 47 69 28 73 92 13 86 52 17 77 04 89 55 40\n! 04 52 08 83 97 35 99 16 07 97 57 32 16 26 26 79 33 27 98 66\n! 88 36 68 87 57 62 20 72 03 46 33 67 46 55 12 32 63 93 53 69\n! 04 42 16 73 38 25 39 11 24 94 72 18 08 46 29 32 40 62 76 36\n! 20 69 36 41 72 30 23 88 34 62 99 69 82 67 59 85 74 04 36 16\n! 20 73 35 29 78 31 90 01 74 31 49 71 48 86 81 16 23 57 05 54\n! 01 70 54 71 83 51 54 69 16 92 33 48 61 43 52 01 89 19 67 48\n!\n! The product of these numbers is 26 x 63 x 78 x 14 = 1788696.\n!\n! What is the greatest product of four adjacent numbers in the same\n! direction (up, down, left, right, or diagonally) in the 20x20 grid?\nmodule Problem11\n\n implicit none\n private\n\n public :: solve\ncontains\n subroutine solve\n write (*, '(A)') 'Problem 11. Largest product in a grid.'\n\n write (*, '(A, I)') 'Product 1: ', product1()\n end subroutine\n\n pure function product1()\n integer :: product1\n\n integer :: horizontal\n integer :: vertical\n integer :: location\n integer :: value\n\n integer, dimension(20, 20) :: matrix;\n\n ! initial values\n product1 = 0\n matrix = transpose(reshape((/08, 02, 22, 97, 38, 15, 00, 40, 00, 75, 04, 05, 07, 78, 52, 12, 50, 77, 91, 08, 49, 49, 99, 40, 17, 81, 18, 57, 60, 87, 17, 40, 98, 43, 69, 48, 04, 56, 62, 00, 81, 49, 31, 73, 55, 79, 14, 29, 93, 71, 40, 67, 53, 88, 30, 03, 49, 13, 36, 65, 52, 70, 95, 23, 04, 60, 11, 42, 69, 24, 68, 56, 01, 32, 56, 71, 37, 02, 36, 91, 22, 31, 16, 71, 51, 67, 63, 89, 41, 92, 36, 54, 22, 40, 40, 28, 66, 33, 13, 80, 24, 47, 32, 60, 99, 03, 45, 02, 44, 75, 33, 53, 78, 36, 84, 20, 35, 17, 12, 50, 32, 98, 81, 28, 64, 23, 67, 10, 26, 38, 40, 67, 59, 54, 70, 66, 18, 38, 64, 70, 67, 26, 20, 68, 02, 62, 12, 20, 95, 63, 94, 39, 63, 08, 40, 91, 66, 49, 94, 21, 24, 55, 58, 05, 66, 73, 99, 26, 97, 17, 78, 78, 96, 83, 14, 88, 34, 89, 63, 72, 21, 36, 23, 09, 75, 00, 76, 44, 20, 45, 35, 14, 00, 61, 33, 97, 34, 31, 33, 95, 78, 17, 53, 28, 22, 75, 31, 67, 15, 94, 03, 80, 04, 62, 16, 14, 09, 53, 56, 92, 16, 39, 05, 42, 96, 35, 31, 47, 55, 58, 88, 24, 00, 17, 54, 24, 36, 29, 85, 57, 86, 56, 00, 48, 35, 71, 89, 07, 05, 44, 44, 37, 44, 60, 21, 58, 51, 54, 17, 58, 19, 80, 81, 68, 05, 94, 47, 69, 28, 73, 92, 13, 86, 52, 17, 77, 04, 89, 55, 40, 04, 52, 08, 83, 97, 35, 99, 16, 07, 97, 57, 32, 16, 26, 26, 79, 33, 27, 98, 66, 88, 36, 68, 87, 57, 62, 20, 72, 03, 46, 33, 67, 46, 55, 12, 32, 63, 93, 53, 69, 04, 42, 16, 73, 38, 25, 39, 11, 24, 94, 72, 18, 08, 46, 29, 32, 40, 62, 76, 36, 20, 69, 36, 41, 72, 30, 23, 88, 34, 62, 99, 69, 82, 67, 59, 85, 74, 04, 36, 16, 20, 73, 35, 29, 78, 31, 90, 01, 74, 31, 49, 71, 48, 86, 81, 16, 23, 57, 05, 54, 01, 70, 54, 71, 83, 51, 54, 69, 16, 92, 33, 48, 61, 43, 52, 01, 89, 19, 67, 48/), shape(matrix)))\n\n do horizontal = 1, 20\n do vertical = 1, 17\n value = 1\n\n do location = vertical, vertical + 3\n value = value * matrix(location, horizontal)\n end do\n\n if (value .gt. product1) then\n product1 = value\n end if\n end do\n end do\n\n do vertical = 1, 20\n do horizontal = 1, 17\n value = 1\n\n do location = horizontal, horizontal + 3\n value = value * matrix(vertical, location)\n end do\n\n if (value .gt. product1) then\n product1 = value\n end if\n end do\n end do\n\n do horizontal = 17, 1, -1\n do vertical = 1, 17\n value = 1\n\n value = value * matrix(vertical, horizontal) &\n * matrix(vertical + 1, horizontal + 1) &\n * matrix(vertical + 2, horizontal + 2) &\n * matrix(vertical + 3, horizontal + 3)\n\n if (value .gt. product1) then\n product1 = value\n end if\n end do\n end do\n\n do horizontal = 4, 20\n do vertical = 1, 17\n value = 1\n\n value = value * matrix(vertical, horizontal) &\n * matrix(vertical + 1, horizontal - 1) &\n * matrix(vertical + 2, horizontal - 2) &\n * matrix(vertical + 3, horizontal - 3)\n\n if (value .gt. product1) then\n product1 = value\n end if\n end do\n end do\n end function\nend module\n", "meta": {"hexsha": "a9318b4888caffa4a061d6f7675f5ef7de196088", "size": 5506, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Problem11.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": "Problem11.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": "Problem11.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": 48.298245614, "max_line_length": 1656, "alphanum_fraction": 0.5159825645, "num_tokens": 2667, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952921073469, "lm_q2_score": 0.7634837635542925, "lm_q1q2_score": 0.6853757801430872}} {"text": "*> \\brief \\b SBDT01\n*\n* =========== DOCUMENTATION ===========\n*\n* Online html documentation available at\n* http://www.netlib.org/lapack/explore-html/\n*\n* Definition:\n* ===========\n*\n* SUBROUTINE SBDT01( M, N, KD, A, LDA, Q, LDQ, D, E, PT, LDPT, WORK,\n* RESID )\n*\n* .. Scalar Arguments ..\n* INTEGER KD, LDA, LDPT, LDQ, M, N\n* REAL RESID\n* ..\n* .. Array Arguments ..\n* REAL A( LDA, * ), D( * ), E( * ), PT( LDPT, * ),\n* $ Q( LDQ, * ), WORK( * )\n* ..\n*\n*\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*>\n*> SBDT01 reconstructs a general matrix A from its bidiagonal form\n*> A = Q * B * P**T\n*> where Q (m by min(m,n)) and P**T (min(m,n) by n) are orthogonal\n*> matrices and B is bidiagonal.\n*>\n*> The test ratio to test the reduction is\n*> RESID = norm(A - Q * B * P**T) / ( n * norm(A) * EPS )\n*> where EPS is the machine precision.\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in] M\n*> \\verbatim\n*> M is INTEGER\n*> The number of rows of the matrices A and Q.\n*> \\endverbatim\n*>\n*> \\param[in] N\n*> \\verbatim\n*> N is INTEGER\n*> The number of columns of the matrices A and P**T.\n*> \\endverbatim\n*>\n*> \\param[in] KD\n*> \\verbatim\n*> KD is INTEGER\n*> If KD = 0, B is diagonal and the array E is not referenced.\n*> If KD = 1, the reduction was performed by xGEBRD; B is upper\n*> bidiagonal if M >= N, and lower bidiagonal if M < N.\n*> If KD = -1, the reduction was performed by xGBBRD; B is\n*> always upper bidiagonal.\n*> \\endverbatim\n*>\n*> \\param[in] A\n*> \\verbatim\n*> A is REAL array, dimension (LDA,N)\n*> The m by n matrix A.\n*> \\endverbatim\n*>\n*> \\param[in] LDA\n*> \\verbatim\n*> LDA is INTEGER\n*> The leading dimension of the array A. LDA >= max(1,M).\n*> \\endverbatim\n*>\n*> \\param[in] Q\n*> \\verbatim\n*> Q is REAL array, dimension (LDQ,N)\n*> The m by min(m,n) orthogonal matrix Q in the reduction\n*> A = Q * B * P**T.\n*> \\endverbatim\n*>\n*> \\param[in] LDQ\n*> \\verbatim\n*> LDQ is INTEGER\n*> The leading dimension of the array Q. LDQ >= max(1,M).\n*> \\endverbatim\n*>\n*> \\param[in] D\n*> \\verbatim\n*> D is REAL array, dimension (min(M,N))\n*> The diagonal elements of the bidiagonal matrix B.\n*> \\endverbatim\n*>\n*> \\param[in] E\n*> \\verbatim\n*> E is REAL array, dimension (min(M,N)-1)\n*> The superdiagonal elements of the bidiagonal matrix B if\n*> m >= n, or the subdiagonal elements of B if m < n.\n*> \\endverbatim\n*>\n*> \\param[in] PT\n*> \\verbatim\n*> PT is REAL array, dimension (LDPT,N)\n*> The min(m,n) by n orthogonal matrix P**T in the reduction\n*> A = Q * B * P**T.\n*> \\endverbatim\n*>\n*> \\param[in] LDPT\n*> \\verbatim\n*> LDPT is INTEGER\n*> The leading dimension of the array PT.\n*> LDPT >= max(1,min(M,N)).\n*> \\endverbatim\n*>\n*> \\param[out] WORK\n*> \\verbatim\n*> WORK is REAL array, dimension (M+N)\n*> \\endverbatim\n*>\n*> \\param[out] RESID\n*> \\verbatim\n*> RESID is REAL\n*> The test ratio:\n*> norm(A - Q * B * P**T) / ( n * norm(A) * EPS )\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee\n*> \\author Univ. of California Berkeley\n*> \\author Univ. of Colorado Denver\n*> \\author NAG Ltd.\n*\n*> \\ingroup single_eig\n*\n* =====================================================================\n SUBROUTINE SBDT01( M, N, KD, A, LDA, Q, LDQ, D, E, PT, LDPT, WORK,\n $ RESID )\n*\n* -- LAPACK test routine --\n* -- LAPACK is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n*\n* .. Scalar Arguments ..\n INTEGER KD, LDA, LDPT, LDQ, M, N\n REAL RESID\n* ..\n* .. Array Arguments ..\n REAL A( LDA, * ), D( * ), E( * ), PT( LDPT, * ),\n $ Q( LDQ, * ), WORK( * )\n* ..\n*\n* =====================================================================\n*\n* .. Parameters ..\n REAL ZERO, ONE\n PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 )\n* ..\n* .. Local Scalars ..\n INTEGER I, J\n REAL ANORM, EPS\n* ..\n* .. External Functions ..\n REAL SASUM, SLAMCH, SLANGE\n EXTERNAL SASUM, SLAMCH, SLANGE\n* ..\n* .. External Subroutines ..\n EXTERNAL SCOPY, SGEMV\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC MAX, MIN, REAL\n* ..\n* .. Executable Statements ..\n*\n* Quick return if possible\n*\n IF( M.LE.0 .OR. N.LE.0 ) THEN\n RESID = ZERO\n RETURN\n END IF\n*\n* Compute A - Q * B * P**T one column at a time.\n*\n RESID = ZERO\n IF( KD.NE.0 ) THEN\n*\n* B is bidiagonal.\n*\n IF( KD.NE.0 .AND. M.GE.N ) THEN\n*\n* B is upper bidiagonal and M >= N.\n*\n DO 20 J = 1, N\n CALL SCOPY( M, A( 1, J ), 1, WORK, 1 )\n DO 10 I = 1, N - 1\n WORK( M+I ) = D( I )*PT( I, J ) + E( I )*PT( I+1, J )\n 10 CONTINUE\n WORK( M+N ) = D( N )*PT( N, J )\n CALL SGEMV( 'No transpose', M, N, -ONE, Q, LDQ,\n $ WORK( M+1 ), 1, ONE, WORK, 1 )\n RESID = MAX( RESID, SASUM( M, WORK, 1 ) )\n 20 CONTINUE\n ELSE IF( KD.LT.0 ) THEN\n*\n* B is upper bidiagonal and M < N.\n*\n DO 40 J = 1, N\n CALL SCOPY( M, A( 1, J ), 1, WORK, 1 )\n DO 30 I = 1, M - 1\n WORK( M+I ) = D( I )*PT( I, J ) + E( I )*PT( I+1, J )\n 30 CONTINUE\n WORK( M+M ) = D( M )*PT( M, J )\n CALL SGEMV( 'No transpose', M, M, -ONE, Q, LDQ,\n $ WORK( M+1 ), 1, ONE, WORK, 1 )\n RESID = MAX( RESID, SASUM( M, WORK, 1 ) )\n 40 CONTINUE\n ELSE\n*\n* B is lower bidiagonal.\n*\n DO 60 J = 1, N\n CALL SCOPY( M, A( 1, J ), 1, WORK, 1 )\n WORK( M+1 ) = D( 1 )*PT( 1, J )\n DO 50 I = 2, M\n WORK( M+I ) = E( I-1 )*PT( I-1, J ) +\n $ D( I )*PT( I, J )\n 50 CONTINUE\n CALL SGEMV( 'No transpose', M, M, -ONE, Q, LDQ,\n $ WORK( M+1 ), 1, ONE, WORK, 1 )\n RESID = MAX( RESID, SASUM( M, WORK, 1 ) )\n 60 CONTINUE\n END IF\n ELSE\n*\n* B is diagonal.\n*\n IF( M.GE.N ) THEN\n DO 80 J = 1, N\n CALL SCOPY( M, A( 1, J ), 1, WORK, 1 )\n DO 70 I = 1, N\n WORK( M+I ) = D( I )*PT( I, J )\n 70 CONTINUE\n CALL SGEMV( 'No transpose', M, N, -ONE, Q, LDQ,\n $ WORK( M+1 ), 1, ONE, WORK, 1 )\n RESID = MAX( RESID, SASUM( M, WORK, 1 ) )\n 80 CONTINUE\n ELSE\n DO 100 J = 1, N\n CALL SCOPY( M, A( 1, J ), 1, WORK, 1 )\n DO 90 I = 1, M\n WORK( M+I ) = D( I )*PT( I, J )\n 90 CONTINUE\n CALL SGEMV( 'No transpose', M, M, -ONE, Q, LDQ,\n $ WORK( M+1 ), 1, ONE, WORK, 1 )\n RESID = MAX( RESID, SASUM( M, WORK, 1 ) )\n 100 CONTINUE\n END IF\n END IF\n*\n* Compute norm(A - Q * B * P**T) / ( n * norm(A) * EPS )\n*\n ANORM = SLANGE( '1', M, N, A, LDA, WORK )\n EPS = SLAMCH( 'Precision' )\n*\n IF( ANORM.LE.ZERO ) THEN\n IF( RESID.NE.ZERO )\n $ RESID = ONE / EPS\n ELSE\n IF( ANORM.GE.RESID ) THEN\n RESID = ( RESID / ANORM ) / ( REAL( N )*EPS )\n ELSE\n IF( ANORM.LT.ONE ) THEN\n RESID = ( MIN( RESID, REAL( N )*ANORM ) / ANORM ) /\n $ ( REAL( N )*EPS )\n ELSE\n RESID = MIN( RESID / ANORM, REAL( N ) ) /\n $ ( REAL( N )*EPS )\n END IF\n END IF\n END IF\n*\n RETURN\n*\n* End of SBDT01\n*\n END\n", "meta": {"hexsha": "fdc30a51ea4dfb3c2d6b55788c7ff3d895490893", "size": 8256, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "TESTING/EIG/sbdt01.f", "max_stars_repo_name": "quellyn/lapack", "max_stars_repo_head_hexsha": "79aa0f2e0641cd48b27c7fc9a96922bf033193fa", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 998, "max_stars_repo_stars_event_min_datetime": "2016-05-04T20:50:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T17:43:13.000Z", "max_issues_repo_path": "TESTING/EIG/sbdt01.f", "max_issues_repo_name": "quellyn/lapack", "max_issues_repo_head_hexsha": "79aa0f2e0641cd48b27c7fc9a96922bf033193fa", "max_issues_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_issues_count": 603, "max_issues_repo_issues_event_min_datetime": "2016-06-04T07:28:21.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T21:16:50.000Z", "max_forks_repo_path": "TESTING/EIG/sbdt01.f", "max_forks_repo_name": "quellyn/lapack", "max_forks_repo_head_hexsha": "79aa0f2e0641cd48b27c7fc9a96922bf033193fa", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 373, "max_forks_repo_forks_event_min_datetime": "2016-06-04T06:05:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T17:25:45.000Z", "avg_line_length": 28.5674740484, "max_line_length": 76, "alphanum_fraction": 0.4332606589, "num_tokens": 2595, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.7634837527911056, "lm_q1q2_score": 0.685375770481025}} {"text": " subroutine setmb_msbar\nc--- set up the value of the running b-mass in the MS-bar scheme,\nc--- evaluated at the pole mass (mb)\nc--- expressions are taken from \nc--- J.~Fleischer, F.~Jegerlehner, O.~V.~Tarasov and O.~L.~Veretin,\nc--- %``Two-loop {QCD} corrections of the massive fermion propagator,''\nc--- Nucl.\\ Phys.\\ B {\\bf 539}, 671 (1999)\nc--- [Erratum-ibid.\\ B {\\bf 571}, 511 (2000)]\nc--- [arXiv:hep-ph/9803493].\n implicit none\n include 'constants.f'\n include 'masses.f'\n include 'msbarmasses.f'\n include 'couple.f'\n include 'part.f'\n double precision alphas,c1,c2,a,zeta3,i31 \n parameter(zeta3=1.20205690315959428539d0)\n\n if (mb_msbar .lt. 0d0) then\n c1=4d0*Cf\n c2=0d0\nc--- calculate the MS-bar mass from the pole mass\n if (part .eq. 'lord') then\n a=alphas(mb,amz,1)/(4d0*pi)\n else\n a=alphas(mb,amz,2)/(4d0*pi)\n i31=3d0/2d0*zeta3-6d0*pisqo6*dlog(2d0)\n c2=Cf*xn*(1111d0/24d0-8d0*pisqo6-4d0*i31)\n . -Cf*half*dfloat(nf-1)*(71d0/6d0+8d0*pisqo6)\n . +Cf**2*(121d0/8d0+30d0*pisqo6+8d0*i31)\n . -12d0*Cf*half*(1d0-2d0*pisqo6)\n endif\n mb_msbar=mb/(1d0+c1*a+c2*a**2)\n endif\n\nc--- For comparison, these were the choices made in previous publications:\nc--- mb(mb)=4.20 is our choice for the H+b paper\nc--- mb(mb)=4.25 is the value used in the Les Houches write-up\n \n write(6,99) mb_msbar\n\n return\n\n 99 format(/,\n . ' ************* Running b-mass at pole mass **********'/, \n . ' * *'/, \n . ' * mb_MSbar(mb) = ',f8.4,' *'/,\n . ' ****************************************************')\n\n end\n \n", "meta": {"hexsha": "ee9afbf39b2346b9faa25224a73c6a7e9b6b3f57", "size": 1780, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "MCFM-JHUGen/src/Need/setmb_msbar.f", "max_stars_repo_name": "tmartini/JHUGen", "max_stars_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-06-08T13:09:28.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-04T19:59:36.000Z", "max_issues_repo_path": "MCFM-JHUGen/src/Need/setmb_msbar.f", "max_issues_repo_name": "tmartini/JHUGen", "max_issues_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 64, "max_issues_repo_issues_event_min_datetime": "2015-06-24T15:08:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-25T04:59:32.000Z", "max_forks_repo_path": "MCFM-JHUGen/src/Need/setmb_msbar.f", "max_forks_repo_name": "tmartini/JHUGen", "max_forks_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2015-05-04T22:15:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-06T10:04:40.000Z", "avg_line_length": 34.2307692308, "max_line_length": 74, "alphanum_fraction": 0.5247191011, "num_tokens": 632, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900957313305, "lm_q2_score": 0.7490872187162397, "lm_q1q2_score": 0.6853406135146488}} {"text": "program prog3\nimplicit none\n\ndouble precision, dimension(1:2,1:2) :: matrix\ndouble precision :: a,b,det\n\nmatrix(1,1) = 1d0\nmatrix(1,2) = 4d0\nmatrix(2,1) = 3d0\nmatrix(2,2) = 2d0\n\na = matrix(1,1)*matrix(2,2)\nb = matrix(1,2)*matrix(2,1)\ndet = a-b\n\nwrite(*,*)det\n\nend program prog3\n", "meta": {"hexsha": "0841808ed4690d4448c3aea3ba9e0911c9f3d91d", "size": 278, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "aula02/prog3.f90", "max_stars_repo_name": "j-rheinheimer/Fisica-Computacional-I", "max_stars_repo_head_hexsha": "9d3d434cfb787391db5b57829e93d1461cc65f1c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "aula02/prog3.f90", "max_issues_repo_name": "j-rheinheimer/Fisica-Computacional-I", "max_issues_repo_head_hexsha": "9d3d434cfb787391db5b57829e93d1461cc65f1c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "aula02/prog3.f90", "max_forks_repo_name": "j-rheinheimer/Fisica-Computacional-I", "max_forks_repo_head_hexsha": "9d3d434cfb787391db5b57829e93d1461cc65f1c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 14.6315789474, "max_line_length": 46, "alphanum_fraction": 0.6618705036, "num_tokens": 123, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9149009596336303, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6853406101279459}} {"text": "\tsubroutine gaussj(a,n,np,b,m,mp,istat)\nc gaussj.f\nc Linear equation solution bu Gauss-jordan elimination; from\nc Numerical Recipies, p. 28.\nc A is n by n matrix; physical dimensions np by np\nc b is n by m matrix of m right-side vectors, stored np by mp\nc output replaces a by its inverse, and b by solution vectors\nc Simple case, has m = 1.\nc returns istat=-1 if singular, -2 if bad-dimensions, 0 otherwise\n\nc nmax should ge .ge. n\n\tparameter (nmax = 2048)\n\tdimension a(np,np), b(np,mp)\n\tdimension ipiv(nmax),indxr(nmax), indxc(nmax)\n\n\tistat = 0\n\tdo 11 j=1,n\n\t ipiv(j) = 0\n11\tcontinue\n\nc --- main loop over columns\n\tdo 22 i=1,n\n\t big = 0.\nc --- outer loop of search for pivot elements\n\t do 13 j=1,n\n\t if (ipiv(j).ne.1) then\n\t do 12 k=1,n\n\t\tif (ipiv(k).eq.0) then\n\t\t if (abs(a(j,k)).ge.big) then\n\t\t big = abs(a(j,k))\n\t\t irow = j\n\t\t icol = k\n\t\t end if\n\t\telse if (ipiv(k).gt.1) then\n\t\t print *,\"GAUSSJ: Singular Matrix\"\n\t\t istat = -1\n\t\t return\n\t \tend if\n12\t continue\n\t end if\n13\t continue\n\t ipiv(icol) = ipiv(icol) + 1\nc --- pivots now interchanged: indxc(i) = col. for ith piv. elem.\nc\tindxr(i) = row of original location of pivot. \n\t if (irow.ne.icol) then\n\t do 14 l=1,n\n\t dum = a(irow,l)\n\t a(irow,l) = a(icol,l)\n\t a(icol,l) = dum\n14\t continue\n\t do 15 l=1,m\n\t dum = b(irow,l)\n\t b(irow,l) = b(icol,l)\n\t b(icol,l) = dum\n15\t continue\n\t end if\n\nc--- divide pivot row by pivot elem. at irow,icol\n\t indxr(i) = irow\n\t indxc(i) = icol\n\t if (a(icol,icol).eq.0.) then\n\t print *,\"GJINV: Singular Matrix\"\n\t istat = -1\n\t return\n\t end if\n\t pivinv=1./a(icol,icol)\n\t a(icol,icol) = 1.\n\t do 16 l=1,n\n\t a(icol,l) = a(icol,l)*pivinv\n16\t continue\n\t do 17 l=1,m\n\t b(icol,l) = b(icol,l)*pivinv\n17\t continue\nc --- reduce rows now\n\t do 21 ll=1,n\n\t if (ll.ne.icol) then\n\t dum=a(ll,icol)\n\t a(ll,icol) = 0.\n\t do 18 l=1,n\n\t\ta(ll,l)=a(ll,l)-a(icol,l)*dum\n18\t continue\n\t do 19 l=1,m\n\t\tb(ll,l)=b(ll,l)-b(icol,l)*dum\n19\t continue\n\t end if\n21\t continue\n22\tcontinue\n\nc -- unscramble indexing\n\tdo 24 l=n,1,-1\n\t if(indxr(l).ne.indxc(l)) then\n\t do 23 k=1,n\n\t\tdum=a(k,indxr(l))\n\t\ta(k,indxr(l))=a(k,indxc(l))\n\t\ta(k,indxc(l))=dum\n23\t continue\n\t end if\n24\tcontinue\n\tistat = 0\n\treturn\n\tend\n\n\tsubroutine dgaussj(a,n,np,b,m,mp,istat)\nc gaussj.f\nc Linear equation solution bu Gauss-jordan elimination; from\nc Numerical Recipies, p. 28.\nc\nc *** THIS is DOUBLE PRECISION version\nC\nc A is n by n matrix; physical dimensions np by np\nc b is n by m matrix of m right-side vectors, stored np by mp\nc output replaces a by its inverse, and b by solution vectors\nc Simple case, has m = 1.\nc returns istat=-1 if singular, 0 otherwise\n\nc nmax should ge .ge. n\n\timplicit double precision (a-h,o-z)\n\tparameter (nmax = 1024)\n\tdimension a(np,np), b(np,mp)\n\tdimension ipiv(nmax),indxr(nmax), indxc(nmax)\n\n\tif (n.gt.nmax) then\n\t print *,'GAUSSJ: n>nmax; n=',n,', nmax=',nmax\n\t istat=-2\n\t return\n\tend if\n\n\tistat = 0\n\tdo 11 j=1,n\n\t ipiv(j) = 0\n11\tcontinue\n\nc --- main loop over columns\n\tdo 22 i=1,n\n\t big = 0.\nc --- outer loop of search for pivot elements\n\t do 13 j=1,n\n\t if (ipiv(j).ne.1) then\n\t do 12 k=1,n\n\t\tif (ipiv(k).eq.0) then\n\t\t if (abs(a(j,k)).ge.big) then\n\t\t big = abs(a(j,k))\n\t\t irow = j\n\t\t icol = k\n\t\t end if\n\t\telse if (ipiv(k).gt.1) then\n\t\t print *,\"GAUSSJ: Singular Matrix\"\n\t\t istat = -1\n\t\t return\n\t \tend if\n12\t continue\n\t end if\n13\t continue\n\t ipiv(icol) = ipiv(icol) + 1\nc --- pivots now interchanged: indxc(i) = col. for ith piv. elem.\nc\tindxr(i) = row of original location of pivot. \n\t if (irow.ne.icol) then\n\t do 14 l=1,n\n\t dum = a(irow,l)\n\t a(irow,l) = a(icol,l)\n\t a(icol,l) = dum\n14\t continue\n\t do 15 l=1,m\n\t dum = b(irow,l)\n\t b(irow,l) = b(icol,l)\n\t b(icol,l) = dum\n15\t continue\n\t end if\n\nc--- divide pivot row by pivot elem. at irow,icol\n\t indxr(i) = irow\n\t indxc(i) = icol\n\t if (a(icol,icol).eq.0.) then\n\t print *,\"GJINV: Singular Matrix\"\n\t istat = -1\n\t return\n\t end if\n\t pivinv=1./a(icol,icol)\n\t a(icol,icol) = 1.\n\t do 16 l=1,n\n\t a(icol,l) = a(icol,l)*pivinv\n16\t continue\n\t do 17 l=1,m\n\t b(icol,l) = b(icol,l)*pivinv\n17\t continue\nc --- reduce rows now\n\t do 21 ll=1,n\n\t if (ll.ne.icol) then\n\t dum=a(ll,icol)\n\t a(ll,icol) = 0.\n\t do 18 l=1,n\n\t\ta(ll,l)=a(ll,l)-a(icol,l)*dum\n18\t continue\n\t do 19 l=1,m\n\t\tb(ll,l)=b(ll,l)-b(icol,l)*dum\n19\t continue\n\t end if\n21\t continue\n22\tcontinue\n\nc -- unscramble indexing\n\tdo 24 l=n,1,-1\n\t if(indxr(l).ne.indxc(l)) then\n\t do 23 k=1,n\n\t\tdum=a(k,indxr(l))\n\t\ta(k,indxr(l))=a(k,indxc(l))\n\t\ta(k,indxc(l))=dum\n23\t continue\n\t end if\n24\tcontinue\n\tistat = 0\n\treturn\n\tend\n", "meta": {"hexsha": "5a6b71c46c47acfcba034261a60bf18d9025acc9", "size": 4796, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "bin/db/dbtimerf/gaussj.f", "max_stars_repo_name": "jreyes1108/antelope_contrib", "max_stars_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_stars_repo_licenses": ["BSD-2-Clause", "MIT"], "max_stars_count": 30, "max_stars_repo_stars_event_min_datetime": "2015-02-20T21:44:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-27T02:53:14.000Z", "max_issues_repo_path": "bin/db/dbtimerf/gaussj.f", "max_issues_repo_name": "jreyes1108/antelope_contrib", "max_issues_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_issues_repo_licenses": ["BSD-2-Clause", "MIT"], "max_issues_count": 14, "max_issues_repo_issues_event_min_datetime": "2015-07-07T19:17:24.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-19T19:18:53.000Z", "max_forks_repo_path": "bin/db/dbtimerf/gaussj.f", "max_forks_repo_name": "jreyes1108/antelope_contrib", "max_forks_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_forks_repo_licenses": ["BSD-2-Clause", "MIT"], "max_forks_count": 46, "max_forks_repo_forks_event_min_datetime": "2015-02-06T16:22:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T11:46:37.000Z", "avg_line_length": 22.4112149533, "max_line_length": 67, "alphanum_fraction": 0.586530442, "num_tokens": 1844, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900950352329, "lm_q2_score": 0.7490872131147276, "lm_q1q2_score": 0.6853406031754419}} {"text": "module ps_grav\n\n use amrex_fort_module, only : rt => amrex_real\n\n implicit none\n\n real(rt), private, save :: dm_const,dm_const2\n logical, private, save :: isnt_init = .true.\n public :: ps_grav_init,ps_grav_accel,ps_grav_phi\n contains\n\n subroutine ps_grav_init()\n use fundamental_constants_module, only : Gconst,Mpc,M_s\n use probdata_module, only : dcenx,dceny,dcenz,dmconc,dmmass,dmscale\n implicit none\n if(isnt_init) then\n dm_const = -(dmmass/M_s)*Gconst / (log(1.0d0+dmconc) - dmconc/(1.0d0+dmconc))\n dm_const2 = dmconc/(dmscale/Mpc)\n isnt_init = .false.\n else\n write(*,*)'ps_grav is already initialized, why are we here?'\n endif\n end subroutine ps_grav_init\n\n! This is an example of how to specify a radial profile\n! Note that r_c and rho_c must be specified in probdata_module\n pure function ps_grav_accel(r) result(g)\n implicit none\n real(rt), intent(in) :: r!,smbh_const\n real(rt) :: g\n! ! put function for g(r) in here\n g = dm_const*(dlog(1.0d0+dm_const2*r)/(r*r)-dm_const2 &\n /(r*(1.0d0+r*dm_const2)))\n end function ps_grav_accel\n\n pure function ps_grav_phi(r) result(g)\n implicit none\n real(rt), intent(in) :: r\n real(rt) :: g\n! ! put function for g(r) in here\n g = -dm_const*dlog(1.0d0+r*dm_const2)/r\n end function ps_grav_phi\nend module ps_grav\n \nsubroutine fort_prescribe_grav (lo,hi,dx, &\n grav,g_l1,g_l2,g_l3,g_h1,g_h2,g_h3,&\n problo,add)\n\n use probdata_module, only : dcenx,dceny,dcenz\n use amrex_constants_module, only : HALF\n use ps_grav, only : ps_grav_accel\n implicit none\n integer :: g_l1,g_l2,g_l3,g_h1,g_h2,g_h3,add\n integer :: lo(3),hi(3)\n real(rt) :: grav(g_l1:g_h1,g_l2:g_h2,g_l3:g_h3,3)\n real(rt) :: dx(3)\n real(rt) :: problo(3)\n\n integer :: i,j,k\n real(rt) :: fort_prescribe_grav_gravityprofile\n real(rt) :: x,y,z,y2,z2\n real(rt) :: r,maggrav\n real(rt) :: dxm,r1\n dxm = min(dx(1),dx(2),dx(3))\n!\n! This is an example of how to use the radial profile above.\n!\n if (add.eq.0) then\n do k = lo(3), hi(3)\n z = problo(3) + (dble(k)+HALF) * dx(3) - dcenz\n z2 = z*z\n do j = lo(2), hi(2)\n y = problo(2) + (dble(j)+HALF) * dx(2) - dceny\n y2 = y*y\n do i = lo(1), hi(1)\n x = problo(1) + (dble(i)+HALF) * dx(1) - dcenx\n r1 = dsqrt(x*x+y2+z2)\n r = max(dxm,r1)\n\n maggrav = ps_grav_accel(r)\n\n ! Put in angular dependence\n grav(i,j,k,1) = maggrav*x/r\n grav(i,j,k,2) = maggrav*y/r\n grav(i,j,k,3) = maggrav*z/r\n enddo\n enddo\n enddo\n else\n do k = lo(3), hi(3)\n z = problo(3) + (dble(k)+HALF) * dx(3) - dcenz\n z2 = z*z\n do j = lo(2), hi(2)\n y = problo(2) + (dble(j)+HALF) * dx(2) - dceny\n y2 = y*y\n do i = lo(1), hi(1)\n x = problo(1) + (dble(i)+HALF) * dx(1) - dcenx\n r1 = dsqrt(x*x+y2+z2)\n r = max(dxm,r1)\n\n maggrav = ps_grav_accel(r)\n\n ! Put in angular dependence\n grav(i,j,k,1) = grav(i,j,k,1) + maggrav*x/r\n grav(i,j,k,2) = grav(i,j,k,2) + maggrav*y/r\n grav(i,j,k,3) = grav(i,j,k,3) + maggrav*z/r\n enddo\n enddo\n enddo\n endif\n\nend subroutine fort_prescribe_grav\n\n", "meta": {"hexsha": "26586c76bdca7f39675694bffce97c71143f6b87", "size": 3542, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Source/Gravity/prescribe_grav_3d.f90", "max_stars_repo_name": "Alpine-DAV/Nyx", "max_stars_repo_head_hexsha": "32c837dfb5ec4abc875fc57d2743d1fb46e49a41", "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": "Source/Gravity/prescribe_grav_3d.f90", "max_issues_repo_name": "Alpine-DAV/Nyx", "max_issues_repo_head_hexsha": "32c837dfb5ec4abc875fc57d2743d1fb46e49a41", "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": "Source/Gravity/prescribe_grav_3d.f90", "max_forks_repo_name": "Alpine-DAV/Nyx", "max_forks_repo_head_hexsha": "32c837dfb5ec4abc875fc57d2743d1fb46e49a41", "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": 31.0701754386, "max_line_length": 87, "alphanum_fraction": 0.5400903444, "num_tokens": 1196, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009480320036, "lm_q2_score": 0.749087201911703, "lm_q1q2_score": 0.685340591187658}} {"text": "MODULE Grid_Interpolation\r\n\r\n! ALGORITHM 760, COLLECTED ALGORITHMS FROM ACM.\r\n! THIS WORK PUBLISHED IN TRANSACTIONS ON MATHEMATICAL SOFTWARE,\r\n! VOL. 22, NO. 3, September, 1996, P. 357--361.\r\n\r\nIMPLICIT NONE\r\nPRIVATE\r\nPUBLIC :: rgbi3p, rgsf3p\r\n\r\n\r\nCONTAINS\r\n\r\n\r\nSUBROUTINE rgbi3p(md, nxd, nyd, xd, yd, zd, nip, xi, yi, zi, ier)\r\n \r\n! Code converted using TO_F90 by Alan Miller\r\n! Date: 2003-06-11 Time: 10:11:03\r\n\r\n! Typo in definition of IDLT in SUBROUTINE RGPD3P fixed by Jason Blevins\r\n! Date: 2015-06-21 Time: 00:22:26\r\n\r\n! Rectangular-grid bivariate interpolation\r\n! (a master subroutine of the RGBI3P/RGSF3P subroutine package)\r\n\r\n! Hiroshi Akima\r\n! U.S. Department of Commerce, NTIA/ITS\r\n! Version of 1995/08\r\n\r\n! This subroutine performs interpolation of a bivariate function, z(x,y), on a\r\n! rectangular grid in the x-y plane. It is based on the revised Akima method.\r\n\r\n! In this subroutine, the interpolating function is a piecewise function\r\n! composed of a set of bicubic (bivariate third-degree) polynomials, each\r\n! applicable to a rectangle of the input grid in the x-y plane.\r\n! Each polynomial is determined locally.\r\n\r\n! This subroutine has the accuracy of a bicubic polynomial, i.e., it\r\n! interpolates accurately when all data points lie on a surface of a\r\n! bicubic polynomial.\r\n\r\n! The grid lines can be unevenly spaced.\r\n\r\n! The input arguments are\r\n! MD = mode of computation\r\n! = 1 for new XD, YD, or ZD data (default)\r\n! = 2 for old XD, YD, and ZD data,\r\n! NXD = number of the input-grid data points in the x coordinate\r\n! (must be 2 or greater),\r\n! NYD = number of the input-grid data points in the y coordinate\r\n! (must be 2 or greater),\r\n! XD = array of dimension NXD containing the x coordinates of the\r\n! input-grid data points (must be in a monotonic increasing order),\r\n! YD = array of dimension NYD containing the y coordinates of the\r\n! input-grid data points (must be in a monotonic increasing order),\r\n! ZD = two-dimensional array of dimension NXD*NYD\r\n! containing the z(x,y) values at the input-grid data points,\r\n! NIP = number of the output points at which interpolation\r\n! of the z value is desired (must be 1 or greater),\r\n! XI = array of dimension NIP containing the x coordinates\r\n! of the output points,\r\n! YI = array of dimension NIP containing the y coordinates\r\n! of the output points.\r\n\r\n! The output arguments are\r\n! ZI = array of dimension NIP where the interpolated z\r\n! values at the output points are to be stored,\r\n! IER = error flag\r\n! = 0 for no errors\r\n! = 1 for NXD = 1 or less\r\n! = 2 for NYD = 1 or less\r\n! = 3 for identical XD values or XD values out of sequence\r\n! = 4 for identical YD values or YD values out of sequence\r\n! = 5 for NIP = 0 or less.\r\n\r\n! N.B. The workspace has been removed from the argument list.\r\n! WK = three dimensional array of dimension 3*NXD*NYD used internally\r\n! as a work area.\r\n\r\n! The very fisrt call to this subroutine and the call with a new XD, YD, and\r\n! ZD array must be made with MD=1. The call with MD=2 must be preceded by\r\n! another call with the same XD, YD, and ZD arrays. Between the call with\r\n! MD=2 and its preceding call, the WK array must not be disturbed.\r\n\r\n! The constant in the PARAMETER statement below is\r\n! NIPIMX = maximum number of output points to be processed at a time.\r\n! The constant value has been selected empirically.\r\n\r\n! This subroutine calls the RGPD3P, RGLCTN, and RGPLNL subroutines.\r\n\r\n\r\n! Specification statements\r\n! .. Parameters ..\r\n\r\nINTEGER, INTENT(IN) :: md\r\nINTEGER, INTENT(IN) :: nxd\r\nINTEGER, INTENT(IN) :: nyd\r\nREAL, INTENT(IN) :: xd(nxd)\r\nREAL, INTENT(IN) :: yd(nyd)\r\nREAL, INTENT(IN OUT) :: zd(nxd,nyd)\r\nINTEGER, INTENT(IN) :: nip\r\nREAL, INTENT(IN OUT) :: xi(nip)\r\nREAL, INTENT(IN OUT) :: yi(nip)\r\nREAL, INTENT(IN OUT) :: zi(nip)\r\nINTEGER, INTENT(OUT) :: ier\r\n\r\n! ..\r\n! .. Local Scalars ..\r\nINTEGER, PARAMETER :: nipimx=51\r\n\r\nINTEGER :: iip, ix, iy, nipi\r\n! ..\r\n! .. Local Arrays ..\r\nINTEGER :: inxi(nipimx), inyi(nipimx)\r\n\r\n! Allocate workspace\r\nREAL :: wk(3,nxd,nyd)\r\n! ..\r\n! .. External Subroutines ..\r\n! EXTERNAL rglctn, rgpd3p, rgplnl\r\n! ..\r\n! .. Intrinsic Functions ..\r\n! INTRINSIC MIN\r\n! ..\r\n\r\n! Preliminary processing\r\n! Error check\r\nIF (nxd <= 1) GO TO 40\r\nIF (nyd <= 1) GO TO 50\r\nDO ix = 2,nxd\r\n IF (xd(ix) <= xd(ix-1)) GO TO 60\r\nEND DO\r\nDO iy = 2,nyd\r\n IF (yd(iy) <= yd(iy-1)) GO TO 70\r\nEND DO\r\nIF (nip <= 0) GO TO 80\r\nier = 0\r\n\r\n! Calculation\r\n! Estimates partial derivatives at all input-grid data points (for MD=1).\r\nIF (md /= 2) THEN\r\n CALL rgpd3p(nxd, nyd, xd, yd, zd, wk)\r\nEND IF\r\n\r\n! DO-loop with respect to the output point\r\n! Processes NIPIMX output points, at most, at a time.\r\nDO iip = 1,nip,nipimx\r\n nipi = MIN(nip- (iip-1),nipimx)\r\n! Locates the output points.\r\n CALL rglctn(nxd, nyd, xd, yd, nipi, xi(iip), yi(iip), inxi, inyi)\r\n\r\n! Calculates the z values at the output points.\r\n CALL rgplnl(nxd, nyd, xd, yd, zd, wk, nipi, xi(iip), yi(iip), inxi, inyi, &\r\n zi(iip))\r\nEND DO\r\nRETURN\r\n\r\n! Error exit\r\n40 WRITE (*,FMT=9000)\r\nier = 1\r\nGO TO 90\r\n50 WRITE (*,FMT=9010)\r\nier = 2\r\nGO TO 90\r\n60 WRITE (*,FMT=9020) ix,xd(ix)\r\nier = 3\r\nGO TO 90\r\n70 WRITE (*,FMT=9030) iy,yd(iy)\r\nier = 4\r\nGO TO 90\r\n80 WRITE (*,FMT=9040)\r\nier = 5\r\n90 WRITE (*,FMT=9050) nxd,nyd,nip\r\nRETURN\r\n\r\n! Format statements for error messages\r\n9000 FORMAT (/' *** RGBI3P Error 1: NXD = 1 or less')\r\n9010 FORMAT (/' *** RGBI3P Error 2: NYD = 1 or less')\r\n9020 FORMAT (/' *** RGBI3P Error 3: Identical XD values or', &\r\n ' XD values out of sequence'/ ' IX =', i6, ', XD(IX) =', e11.3)\r\n9030 FORMAT (/' *** RGBI3P Error 4: Identical YD values or', &\r\n ' YD values out of sequence',/,' IY =',i6,', YD(IY) =', e11.3)\r\n9040 FORMAT (/' *** RGBI3P Error 5: NIP = 0 or less')\r\n9050 FORMAT (' NXD =', i5,', NYD =', i5,', NIP =', i5/)\r\nEND SUBROUTINE rgbi3p\r\n\r\n\r\n\r\nSUBROUTINE rgsf3p(md, nxd, nyd, xd, yd, zd, nxi, xi, nyi, yi, zi, ier)\r\n\r\n! Rectangular-grid surface fitting\r\n! (a master subroutine of the RGBI3P/RGSF3P subroutine package)\r\n\r\n! Hiroshi Akima\r\n! U.S. Department of Commerce, NTIA/ITS\r\n! Version of 1995/08\r\n\r\n! This subroutine performs surface fitting by interpolating values of a\r\n! bivariate function, z(x,y), on a rectangular grid in the x-y plane.\r\n! It is based on the revised Akima method.\r\n\r\n! In this subroutine, the interpolating function is a piecewise function\r\n! composed of a set of bicubic (bivariate third-degree) polynomials, each\r\n! applicable to a rectangle of the input grid in the x-y plane.\r\n! Each polynomial is determined locally.\r\n\r\n! This subroutine has the accuracy of a bicubic polynomial, i.e., it fits the\r\n! surface accurately when all data points lie on a surface of a bicubic\r\n! polynomial.\r\n\r\n! The grid lines of the input and output data can be unevenly spaced.\r\n\r\n! The input arguments are\r\n! MD = mode of computation\r\n! = 1 for new XD, YD, or ZD data (default)\r\n! = 2 for old XD, YD, and ZD data,\r\n! NXD = number of the input-grid data points in the x\r\n! coordinate (must be 2 or greater),\r\n! NYD = number of the input-grid data points in the y\r\n! coordinate (must be 2 or greater),\r\n! XD = array of dimension NXD containing the x coordinates\r\n! of the input-grid data points (must be in a\r\n! monotonic increasing order),\r\n! YD = array of dimension NYD containing the y coordinates\r\n! of the input-grid data points (must be in a\r\n! monotonic increasing order),\r\n! ZD = two-dimensional array of dimension NXD*NYD\r\n! containing the z(x,y) values at the input-grid data points,\r\n! NXI = number of output grid points in the x coordinate\r\n! (must be 1 or greater),\r\n! XI = array of dimension NXI containing the x coordinates\r\n! of the output grid points,\r\n! NYI = number of output grid points in the y coordinate\r\n! (must be 1 or greater),\r\n! YI = array of dimension NYI containing the y coordinates\r\n! of the output grid points.\r\n\r\n! The output arguments are\r\n! ZI = two-dimensional array of dimension NXI*NYI, where the interpolated\r\n! z values at the output grid points are to be stored,\r\n! IER = error flag\r\n! = 0 for no error\r\n! = 1 for NXD = 1 or less\r\n! = 2 for NYD = 1 or less\r\n! = 3 for identical XD values or XD values out of sequence\r\n! = 4 for identical YD values or YD values out of sequence\r\n! = 5 for NXI = 0 or less\r\n! = 6 for NYI = 0 or less.\r\n\r\n! N.B. The workspace has been removed from the argument list.\r\n! WK = three-dimensional array of dimension 3*NXD*NYD used internally\r\n! as a work area.\r\n\r\n! The very first call to this subroutine and the call with a new XD, YD, or\r\n! ZD array must be made with MD=1. The call with MD=2 must be preceded by\r\n! another call with the same XD, YD, and ZD arrays. Between the call with\r\n! MD=2 and its preceding call, the WK array must not be disturbed.\r\n\r\n! The constant in the PARAMETER statement below is\r\n! NIPIMX = maximum number of output points to be processed at a time.\r\n! The constant value has been selected empirically.\r\n\r\n! This subroutine calls the RGPD3P, RGLCTN, and RGPLNL subroutines.\r\n\r\n\r\n! Specification statements\r\n! .. Parameters ..\r\n\r\nINTEGER, INTENT(IN) :: md\r\nINTEGER, INTENT(IN) :: nxd\r\nINTEGER, INTENT(IN) :: nyd\r\nREAL, INTENT(IN) :: xd(nxd)\r\nREAL, INTENT(IN) :: yd(nyd)\r\nREAL, INTENT(IN OUT) :: zd(nxd,nyd)\r\nINTEGER, INTENT(IN) :: nxi\r\nREAL, INTENT(IN OUT) :: xi(nxi)\r\nINTEGER, INTENT(IN) :: nyi\r\nREAL, INTENT(IN) :: yi(nyi)\r\nREAL, INTENT(IN OUT) :: zi(nxi,nyi)\r\nINTEGER, INTENT(OUT) :: ier\r\n\r\n! ..\r\n! .. Local Scalars ..\r\nINTEGER, PARAMETER :: nipimx=51\r\n\r\nINTEGER :: ix, ixi, iy, iyi, nipi\r\n! ..\r\n! .. Local Arrays ..\r\nREAL :: yii(nipimx)\r\nINTEGER :: inxi(nipimx), inyi(nipimx)\r\n\r\n! Allocate workspace\r\nREAL :: wk(3,nxd,nyd)\r\n! ..\r\n! .. External Subroutines ..\r\n! EXTERNAL rglctn,rgpd3p,rgplnl\r\n! ..\r\n! .. Intrinsic Functions ..\r\n! INTRINSIC MIN\r\n! ..\r\n\r\n! Preliminary processing\r\n! Error check\r\nIF (nxd <= 1) GO TO 60\r\nIF (nyd <= 1) GO TO 70\r\nDO ix = 2,nxd\r\n IF (xd(ix) <= xd(ix-1)) GO TO 80\r\nEND DO\r\nDO iy = 2,nyd\r\n IF (yd(iy) <= yd(iy-1)) GO TO 90\r\nEND DO\r\nIF (nxi <= 0) GO TO 100\r\nIF (nyi <= 0) GO TO 110\r\nier = 0\r\n\r\n! Calculation\r\n! Estimates partial derivatives at all input-grid data points\r\n! (for MD=1).\r\nIF (md /= 2) THEN\r\n CALL rgpd3p(nxd, nyd, xd, yd, zd, wk)\r\nEND IF\r\n\r\n! Outermost DO-loop with respect to the y coordinate of the output grid points\r\nDO iyi = 1,nyi\r\n DO ixi = 1,nipimx\r\n yii(ixi) = yi(iyi)\r\n END DO\r\n\r\n! Second DO-loop with respect to the x coordinate of the output grid points\r\n! Processes NIPIMX output-grid points, at most, at a time.\r\n DO ixi = 1,nxi,nipimx\r\n nipi = MIN(nxi- (ixi-1), nipimx)\r\n! Locates the output-grid points.\r\n CALL rglctn(nxd, nyd, xd, yd, nipi, xi(ixi), yii, inxi, inyi)\r\n\r\n! Calculates the z values at the output-grid points.\r\n CALL rgplnl(nxd, nyd, xd, yd, zd, wk, nipi, xi(ixi), yii, inxi, inyi, &\r\n zi(ixi,iyi))\r\n END DO\r\nEND DO\r\nRETURN\r\n\r\n! Error exit\r\n60 WRITE (*,FMT=9000)\r\nier = 1\r\nGO TO 120\r\n70 WRITE (*,FMT=9010)\r\nier = 2\r\nGO TO 120\r\n80 WRITE (*,FMT=9020) ix,xd(ix)\r\nier = 3\r\nGO TO 120\r\n90 WRITE (*,FMT=9030) iy,yd(iy)\r\nier = 4\r\nGO TO 120\r\n100 WRITE (*,FMT=9040)\r\nier = 5\r\nGO TO 120\r\n110 WRITE (*,FMT=9050)\r\nier = 6\r\n120 WRITE (*,FMT=9060) nxd,nyd,nxi,nyi\r\nRETURN\r\n\r\n! Format statements for error messages\r\n9000 FORMAT (/' *** RGSF3P Error 1: NXD = 1 or less')\r\n9010 FORMAT (/' *** RGSF3P Error 2: NYD = 1 or less')\r\n9020 FORMAT (/' *** RGSF3P Error 3: Identical XD values or', &\r\n ' XD values out of sequence',/,' IX =',i6,', XD(IX) =', e11.3)\r\n9030 FORMAT (/' *** RGSF3P Error 4: Identical YD values or', &\r\n ' YD values out of sequence',/,' IY =',i6,', YD(IY) =', e11.3)\r\n9040 FORMAT (/' *** RGSF3P Error 5: NXI = 0 or less')\r\n9050 FORMAT (/' *** RGSF3P Error 6: NYI = 0 or less')\r\n9060 FORMAT (' NXD =', i5, ', NYD =', i5, ', NXI =', i5,', NYI =', i5 /)\r\nEND SUBROUTINE rgsf3p\r\n\r\n\r\n\r\n! ..\r\n! Statement Function definitions\r\n! z2f(xx1,xx2,zz0,zz1) = (zz1-zz0)*xx2/xx1 + zz0\r\n! z3f(xx1,xx2,xx3,zz0,zz1,zz2) = ((zz2-zz0)* (xx3-xx1)/xx2 - &\r\n! (zz1-zz0)* (xx3-xx2)/xx1)* (xx3/ (xx2-xx1)) + zz0\r\n\r\nFUNCTION z2f(xx1, xx2, zz0, zz1) RESULT(fn_val)\r\n\r\nREAL, INTENT(IN) :: xx1, xx2, zz0, zz1\r\nREAL :: fn_val\r\n\r\nfn_val = (zz1-zz0)*xx2/xx1 + zz0\r\nRETURN\r\nEND FUNCTION z2f\r\n\r\n\r\n\r\nFUNCTION z3f(xx1, xx2, xx3, zz0, zz1, zz2) RESULT(fn_val)\r\n\r\nREAL, INTENT(IN) :: xx1, xx2, xx3, zz0, zz1, zz2\r\nREAL :: fn_val\r\n\r\nfn_val = ((zz2-zz0)*(xx3-xx1)/xx2 - (zz1-zz0)*(xx3-xx2)/xx1) * &\r\n (xx3/(xx2-xx1)) + zz0\r\nRETURN\r\nEND FUNCTION z3f\r\n\r\n\r\n\r\nSUBROUTINE rgpd3p(nxd, nyd, xd, yd, zd, pdd)\r\n\r\n! Partial derivatives of a bivariate function on a rectangular grid\r\n! (a supporting subroutine of the RGBI3P/RGSF3P subroutine package)\r\n\r\n! Hiroshi Akima\r\n! U.S. Department of Commerce, NTIA/ITS\r\n! Version of 1995/08\r\n\r\n! This subroutine estimates three partial derivatives, zx, zy, and\r\n! zxy, of a bivariate function, z(x,y), on a rectangular grid in\r\n! the x-y plane. It is based on the revised Akima method that has\r\n! the accuracy of a bicubic polynomial.\r\n\r\n! The input arguments are\r\n! NXD = number of the input-grid data points in the x\r\n! coordinate (must be 2 or greater),\r\n! NYD = number of the input-grid data points in the y\r\n! coordinate (must be 2 or greater),\r\n! XD = array of dimension NXD containing the x coordinates of the\r\n! input-grid data points (must be in a monotonic increasing order),\r\n! YD = array of dimension NYD containing the y coordinates of the\r\n! input-grid data points (must be in a monotonic increasing order),\r\n! ZD = two-dimensional array of dimension NXD*NYD\r\n! containing the z(x,y) values at the input-grid data points.\r\n\r\n! The output argument is\r\n! PDD = three-dimensional array of dimension 3*NXD*NYD,\r\n! where the estimated zx, zy, and zxy values at the\r\n! input-grid data points are to be stored.\r\n\r\n\r\n! Specification statements\r\n! .. Scalar Arguments ..\r\n\r\nINTEGER, INTENT(IN) :: nxd\r\nINTEGER, INTENT(IN) :: nyd\r\nREAL, INTENT(IN) :: xd(nxd)\r\nREAL, INTENT(IN) :: yd(nyd)\r\nREAL, INTENT(IN) :: zd(nxd,nyd)\r\nREAL, INTENT(OUT) :: pdd(3,nxd,nyd)\r\n\r\n! ..\r\n! .. Local Scalars ..\r\nREAL :: b00, b00x, b00y, b01, b10, b11, cx1, cx2, cx3, cy1, cy2, &\r\n cy3, disf, dnm, dz00, dz01, dz02, dz03, dz10, dz11, dz12, &\r\n dz13, dz20, dz21, dz22, dz23, dz30, dz31, dz32, dz33, &\r\n dzx10, dzx20, dzx30, dzxy11, dzxy12, dzxy13, dzxy21, &\r\n dzxy22, dzxy23, dzxy31, dzxy32, dzxy33, dzy01, dzy02, &\r\n dzy03, epsln, pezx, pezxy, pezy, smpef, smpei, smwtf, &\r\n smwti, sx, sxx, sxxy, sxxyy, sxy, sxyy, sxyz, sxz, sy, syy, &\r\n syz, sz, volf, wt, x0, x1, x2, x3, y0, y1, y2, &\r\n y3, z00, z01, z02, z03, z10, z11, z12, z13, z20, z21, z22, &\r\n z23, z30, z31, z32, z33, zxdi, zxydi, zydi\r\nINTEGER :: ipex, ipey, ix0, ix1, ix2, ix3, iy0, iy1, iy2, iy3, nx0, ny0\r\n! ..\r\n! .. Local Arrays ..\r\nREAL :: b00xa(4), b00ya(4), b01a(4), b10a(4), cxa(3,4), cya(3,4), &\r\n sxa(4), sxxa(4), sya(4), syya(4), xa(3,4), ya(3,4), &\r\n z0ia(3,4), zi0a(3,4)\r\n! INTEGER :: idlt(3,4)\r\n! ..\r\n! .. Intrinsic Functions ..\r\n! INTRINSIC MAX\r\n! ..\r\n! .. Statement Functions ..\r\n! REAL :: z2f,z3f\r\n! ..\r\n! Data statements\r\n! DATA ((idlt(jxy,jpexy),jpexy=1,4),jxy=1,3)/-3,-2,-1,1,-2,-1,1,2,-1,1,2,3/\r\nINTEGER, SAVE :: idlt(3,4) = RESHAPE( &\r\n (/ -3,-2,-1, -2,-1,1, -1,1,2, 1,2,3 /), (/ 3, 4 /) )\r\n! ..\r\n\r\n! Calculation\r\n! Initial setting of some local variables\r\nnx0 = MAX(4,nxd)\r\nny0 = MAX(4,nyd)\r\n\r\n! Double DO-loop with respect to the input grid points\r\nDO iy0 = 1,nyd\r\n DO ix0 = 1,nxd\r\n x0 = xd(ix0)\r\n y0 = yd(iy0)\r\n z00 = zd(ix0,iy0)\r\n\r\n! Part 1. Estimation of ZXDI\r\n! Initial setting\r\n smpef = 0.0\r\n smwtf = 0.0\r\n smpei = 0.0\r\n smwti = 0.0\r\n! DO-loop with respect to the primary estimate\r\n DO ipex = 1,4\r\n! Selects necessary grid points in the x direction.\r\n ix1 = ix0 + idlt(1,ipex)\r\n ix2 = ix0 + idlt(2,ipex)\r\n ix3 = ix0 + idlt(3,ipex)\r\n IF ((ix1 < 1) .OR. (ix2 < 1) .OR. (ix3 < 1) .OR. &\r\n (ix1 > nx0) .OR. (ix2 > nx0) .OR. (ix3 > nx0)) CYCLE\r\n! Selects and/or supplements the x and z values.\r\n x1 = xd(ix1) - x0\r\n z10 = zd(ix1,iy0)\r\n IF (nxd >= 4) THEN\r\n x2 = xd(ix2) - x0\r\n x3 = xd(ix3) - x0\r\n z20 = zd(ix2,iy0)\r\n z30 = zd(ix3,iy0)\r\n ELSE IF (nxd == 3) THEN\r\n x2 = xd(ix2) - x0\r\n z20 = zd(ix2,iy0)\r\n x3 = 2*xd(3) - xd(2) - x0\r\n z30 = z3f(x1,x2,x3,z00,z10,z20)\r\n ELSE IF (nxd == 2) THEN\r\n x2 = 2*xd(2) - xd(1) - x0\r\n z20 = z2f(x1,x2,z00,z10)\r\n x3 = 2*xd(1) - xd(2) - x0\r\n z30 = z2f(x1,x3,z00,z10)\r\n END IF\r\n dzx10 = (z10-z00)/x1\r\n dzx20 = (z20-z00)/x2\r\n dzx30 = (z30-z00)/x3\r\n! Calculates the primary estimate of partial derivative zx as\r\n! the coefficient of the bicubic polynomial.\r\n cx1 = x2*x3/ ((x1-x2)* (x1-x3))\r\n cx2 = x3*x1/ ((x2-x3)* (x2-x1))\r\n cx3 = x1*x2/ ((x3-x1)* (x3-x2))\r\n pezx = cx1*dzx10 + cx2*dzx20 + cx3*dzx30\r\n! Calculates the volatility factor and distance factor in the x\r\n! direction for the primary estimate of zx.\r\n sx = x1 + x2 + x3\r\n sz = z00 + z10 + z20 + z30\r\n sxx = x1*x1 + x2*x2 + x3*x3\r\n sxz = x1*z10 + x2*z20 + x3*z30\r\n dnm = 4.0*sxx - sx*sx\r\n b00 = (sxx*sz-sx*sxz)/dnm\r\n b10 = (4.0*sxz-sx*sz)/dnm\r\n dz00 = z00 - b00\r\n dz10 = z10 - (b00+b10*x1)\r\n dz20 = z20 - (b00+b10*x2)\r\n dz30 = z30 - (b00+b10*x3)\r\n volf = dz00**2 + dz10**2 + dz20**2 + dz30**2\r\n disf = sxx\r\n\r\n! Calculates the EPSLN value, which is used to decide whether or\r\n! not the volatility factor is essentially zero.\r\n epsln = (z00**2+z10**2+z20**2+z30**2)*1.0E-12\r\n! Accumulates the weighted primary estimates of zx and their weights.\r\n IF (volf > epsln) THEN\r\n! - For a finite weight.\r\n wt = 1.0/ (volf*disf)\r\n smpef = smpef + wt*pezx\r\n smwtf = smwtf + wt\r\n ELSE\r\n! - For an infinite weight.\r\n smpei = smpei + pezx\r\n smwti = smwti + 1.0\r\n END IF\r\n\r\n! Saves the necessary values for estimating zxy\r\n xa(1,ipex) = x1\r\n xa(2,ipex) = x2\r\n xa(3,ipex) = x3\r\n zi0a(1,ipex) = z10\r\n zi0a(2,ipex) = z20\r\n zi0a(3,ipex) = z30\r\n cxa(1,ipex) = cx1\r\n cxa(2,ipex) = cx2\r\n cxa(3,ipex) = cx3\r\n sxa(ipex) = sx\r\n sxxa(ipex) = sxx\r\n b00xa(ipex) = b00\r\n b10a(ipex) = b10\r\n END DO\r\n\r\n! Calculates the final estimate of zx.\r\n IF (smwti < 0.5) THEN\r\n! - When no infinite weights exist.\r\n zxdi = smpef/smwtf\r\n ELSE\r\n! - When infinite weights exist.\r\n zxdi = smpei/smwti\r\n END IF\r\n! End of Part 1.\r\n\r\n! Part 2. Estimation of ZYDI\r\n! Initial setting\r\n smpef = 0.0\r\n smwtf = 0.0\r\n smpei = 0.0\r\n smwti = 0.0\r\n! DO-loop with respect to the primary estimate\r\n DO ipey = 1,4\r\n! Selects necessary grid points in the y direction.\r\n iy1 = iy0 + idlt(1,ipey)\r\n iy2 = iy0 + idlt(2,ipey)\r\n iy3 = iy0 + idlt(3,ipey)\r\n IF ((iy1 < 1) .OR. (iy2 < 1) .OR. (iy3 < 1) .OR. &\r\n (iy1 > ny0) .OR. (iy2 > ny0) .OR. (iy3 > ny0)) CYCLE\r\n! Selects and/or supplements the y and z values.\r\n y1 = yd(iy1) - y0\r\n z01 = zd(ix0,iy1)\r\n IF (nyd >= 4) THEN\r\n y2 = yd(iy2) - y0\r\n y3 = yd(iy3) - y0\r\n z02 = zd(ix0,iy2)\r\n z03 = zd(ix0,iy3)\r\n ELSE IF (nyd == 3) THEN\r\n y2 = yd(iy2) - y0\r\n z02 = zd(ix0,iy2)\r\n y3 = 2*yd(3) - yd(2) - y0\r\n z03 = z3f(y1,y2,y3,z00,z01,z02)\r\n ELSE IF (nyd == 2) THEN\r\n y2 = 2*yd(2) - yd(1) - y0\r\n z02 = z2f(y1,y2,z00,z01)\r\n y3 = 2*yd(1) - yd(2) - y0\r\n z03 = z2f(y1,y3,z00,z01)\r\n END IF\r\n dzy01 = (z01-z00)/y1\r\n dzy02 = (z02-z00)/y2\r\n dzy03 = (z03-z00)/y3\r\n! Calculates the primary estimate of partial derivative zy as\r\n! the coefficient of the bicubic polynomial.\r\n cy1 = y2*y3/ ((y1-y2)* (y1-y3))\r\n cy2 = y3*y1/ ((y2-y3)* (y2-y1))\r\n cy3 = y1*y2/ ((y3-y1)* (y3-y2))\r\n pezy = cy1*dzy01 + cy2*dzy02 + cy3*dzy03\r\n! Calculates the volatility factor and distance factor in the y\r\n! direction for the primary estimate of zy.\r\n sy = y1 + y2 + y3\r\n sz = z00 + z01 + z02 + z03\r\n syy = y1*y1 + y2*y2 + y3*y3\r\n syz = y1*z01 + y2*z02 + y3*z03\r\n dnm = 4.0*syy - sy*sy\r\n b00 = (syy*sz-sy*syz)/dnm\r\n b01 = (4.0*syz-sy*sz)/dnm\r\n dz00 = z00 - b00\r\n dz01 = z01 - (b00+b01*y1)\r\n dz02 = z02 - (b00+b01*y2)\r\n dz03 = z03 - (b00+b01*y3)\r\n volf = dz00**2 + dz01**2 + dz02**2 + dz03**2\r\n disf = syy\r\n\r\n! Calculates the EPSLN value, which is used to decide whether or\r\n! not the volatility factor is essentially zero.\r\n epsln = (z00**2+z01**2+z02**2+z03**2)*1.0E-12\r\n! Accumulates the weighted primary estimates of zy and their weights.\r\n IF (volf > epsln) THEN\r\n! - For a finite weight.\r\n wt = 1.0/ (volf*disf)\r\n smpef = smpef + wt*pezy\r\n smwtf = smwtf + wt\r\n ELSE\r\n! - For an infinite weight.\r\n smpei = smpei + pezy\r\n smwti = smwti + 1.0\r\n END IF\r\n! Saves the necessary values for estimating zxy\r\n ya(1,ipey) = y1\r\n ya(2,ipey) = y2\r\n ya(3,ipey) = y3\r\n z0ia(1,ipey) = z01\r\n z0ia(2,ipey) = z02\r\n z0ia(3,ipey) = z03\r\n cya(1,ipey) = cy1\r\n cya(2,ipey) = cy2\r\n cya(3,ipey) = cy3\r\n sya(ipey) = sy\r\n syya(ipey) = syy\r\n b00ya(ipey) = b00\r\n b01a(ipey) = b01\r\n END DO\r\n\r\n! Calculates the final estimate of zy.\r\n IF (smwti < 0.5) THEN\r\n! - When no infinite weights exist.\r\n zydi = smpef/smwtf\r\n ELSE\r\n! - When infinite weights exist.\r\n zydi = smpei/smwti\r\n END IF\r\n! End of Part 2.\r\n\r\n! Part 3. Estimation of ZXYDI\r\n! Initial setting\r\n smpef = 0.0\r\n smwtf = 0.0\r\n smpei = 0.0\r\n smwti = 0.0\r\n! Outer DO-loops with respect to the primary estimates in the x direction\r\n DO ipex = 1,4\r\n ix1 = ix0 + idlt(1,ipex)\r\n ix2 = ix0 + idlt(2,ipex)\r\n ix3 = ix0 + idlt(3,ipex)\r\n IF ((ix1 < 1) .OR. (ix2 < 1) .OR. (ix3 < 1) .OR. &\r\n (ix1 > nx0) .OR. (ix2 > nx0) .OR. (ix3 > nx0)) CYCLE\r\n! Retrieves the necessary values for estimating zxy in the x direction.\r\n x1 = xa(1,ipex)\r\n x2 = xa(2,ipex)\r\n x3 = xa(3,ipex)\r\n z10 = zi0a(1,ipex)\r\n z20 = zi0a(2,ipex)\r\n z30 = zi0a(3,ipex)\r\n cx1 = cxa(1,ipex)\r\n cx2 = cxa(2,ipex)\r\n cx3 = cxa(3,ipex)\r\n sx = sxa(ipex)\r\n sxx = sxxa(ipex)\r\n b00x = b00xa(ipex)\r\n b10 = b10a(ipex)\r\n\r\n! Inner DO-loops with respect to the primary estimates in the y direction\r\n DO ipey = 1,4\r\n iy1 = iy0 + idlt(1,ipey)\r\n iy2 = iy0 + idlt(2,ipey)\r\n iy3 = iy0 + idlt(3,ipey)\r\n IF ((iy1 < 1) .OR. (iy2 < 1) .OR. (iy3 < 1) .OR. (iy1 > ny0) .OR. &\r\n (iy2 > ny0) .OR. (iy3 > ny0)) CYCLE\r\n! Retrieves the necessary values for estimating zxy in the y direction.\r\n y1 = ya(1,ipey)\r\n y2 = ya(2,ipey)\r\n y3 = ya(3,ipey)\r\n z01 = z0ia(1,ipey)\r\n z02 = z0ia(2,ipey)\r\n z03 = z0ia(3,ipey)\r\n cy1 = cya(1,ipey)\r\n cy2 = cya(2,ipey)\r\n cy3 = cya(3,ipey)\r\n sy = sya(ipey)\r\n syy = syya(ipey)\r\n b00y = b00ya(ipey)\r\n b01 = b01a(ipey)\r\n! Selects and/or supplements the z values.\r\n IF (nyd >= 4) THEN\r\n z11 = zd(ix1,iy1)\r\n z12 = zd(ix1,iy2)\r\n z13 = zd(ix1,iy3)\r\n IF (nxd >= 4) THEN\r\n z21 = zd(ix2,iy1)\r\n z22 = zd(ix2,iy2)\r\n z23 = zd(ix2,iy3)\r\n z31 = zd(ix3,iy1)\r\n z32 = zd(ix3,iy2)\r\n z33 = zd(ix3,iy3)\r\n ELSE IF (nxd == 3) THEN\r\n z21 = zd(ix2,iy1)\r\n z22 = zd(ix2,iy2)\r\n z23 = zd(ix2,iy3)\r\n z31 = z3f(x1,x2,x3,z01,z11,z21)\r\n z32 = z3f(x1,x2,x3,z02,z12,z22)\r\n z33 = z3f(x1,x2,x3,z03,z13,z23)\r\n ELSE IF (nxd == 2) THEN\r\n z21 = z2f(x1,x2,z01,z11)\r\n z22 = z2f(x1,x2,z02,z12)\r\n z23 = z2f(x1,x2,z03,z13)\r\n z31 = z2f(x1,x3,z01,z11)\r\n z32 = z2f(x1,x3,z02,z12)\r\n z33 = z2f(x1,x3,z03,z13)\r\n END IF\r\n ELSE IF (nyd == 3) THEN\r\n z11 = zd(ix1,iy1)\r\n z12 = zd(ix1,iy2)\r\n z13 = z3f(y1,y2,y3,z10,z11,z12)\r\n IF (nxd >= 4) THEN\r\n z21 = zd(ix2,iy1)\r\n z22 = zd(ix2,iy2)\r\n z31 = zd(ix3,iy1)\r\n z32 = zd(ix3,iy2)\r\n ELSE IF (nxd == 3) THEN\r\n z21 = zd(ix2,iy1)\r\n z22 = zd(ix2,iy2)\r\n z31 = z3f(x1,x2,x3,z01,z11,z21)\r\n z32 = z3f(x1,x2,x3,z02,z12,z22)\r\n ELSE IF (nxd == 2) THEN\r\n z21 = z2f(x1,x2,z01,z11)\r\n z22 = z2f(x1,x2,z02,z12)\r\n z31 = z2f(x1,x3,z01,z11)\r\n z32 = z2f(x1,x3,z02,z12)\r\n END IF\r\n z23 = z3f(y1,y2,y3,z20,z21,z22)\r\n z33 = z3f(y1,y2,y3,z30,z31,z32)\r\n ELSE IF (nyd == 2) THEN\r\n z11 = zd(ix1,iy1)\r\n z12 = z2f(y1,y2,z10,z11)\r\n z13 = z2f(y1,y3,z10,z11)\r\n IF (nxd >= 4) THEN\r\n z21 = zd(ix2,iy1)\r\n z31 = zd(ix3,iy1)\r\n ELSE IF (nxd == 3) THEN\r\n z21 = zd(ix2,iy1)\r\n z31 = z3f(x1,x2,x3,z01,z11,z21)\r\n ELSE IF (nxd == 2) THEN\r\n z21 = z2f(x1,x2,z01,z11)\r\n z31 = z2f(x1,x3,z01,z11)\r\n END IF\r\n z22 = z2f(y1,y2,z20,z21)\r\n z23 = z2f(y1,y3,z20,z21)\r\n z32 = z2f(y1,y2,z30,z31)\r\n z33 = z2f(y1,y3,z30,z31)\r\n END IF\r\n! Calculates the primary estimate of partial derivative zxy as\r\n! the coefficient of the bicubic polynomial.\r\n dzxy11 = (z11-z10-z01+z00)/ (x1*y1)\r\n dzxy12 = (z12-z10-z02+z00)/ (x1*y2)\r\n dzxy13 = (z13-z10-z03+z00)/ (x1*y3)\r\n dzxy21 = (z21-z20-z01+z00)/ (x2*y1)\r\n dzxy22 = (z22-z20-z02+z00)/ (x2*y2)\r\n dzxy23 = (z23-z20-z03+z00)/ (x2*y3)\r\n dzxy31 = (z31-z30-z01+z00)/ (x3*y1)\r\n dzxy32 = (z32-z30-z02+z00)/ (x3*y2)\r\n dzxy33 = (z33-z30-z03+z00)/ (x3*y3)\r\n pezxy = cx1* (cy1*dzxy11+cy2*dzxy12+cy3*dzxy13) + &\r\n cx2* (cy1*dzxy21+cy2*dzxy22+cy3*dzxy23) + &\r\n cx3* (cy1*dzxy31+cy2*dzxy32+cy3*dzxy33)\r\n! Calculates the volatility factor and distance factor in the x\r\n! and y directions for the primary estimate of zxy.\r\n b00 = (b00x+b00y)/2.0\r\n sxy = sx*sy\r\n sxxy = sxx*sy\r\n sxyy = sx*syy\r\n sxxyy = sxx*syy\r\n sxyz = x1* (y1*z11+y2*z12+y3*z13) + x2* (y1*z21+y2*z22+y3*z23) + &\r\n x3* (y1*z31+y2*z32+y3*z33)\r\n b11 = (sxyz-b00*sxy-b10*sxxy-b01*sxyy)/sxxyy\r\n dz00 = z00 - b00\r\n dz01 = z01 - (b00+b01*y1)\r\n dz02 = z02 - (b00+b01*y2)\r\n dz03 = z03 - (b00+b01*y3)\r\n dz10 = z10 - (b00+b10*x1)\r\n dz11 = z11 - (b00+b01*y1+x1* (b10+b11*y1))\r\n dz12 = z12 - (b00+b01*y2+x1* (b10+b11*y2))\r\n dz13 = z13 - (b00+b01*y3+x1* (b10+b11*y3))\r\n dz20 = z20 - (b00+b10*x2)\r\n dz21 = z21 - (b00+b01*y1+x2* (b10+b11*y1))\r\n dz22 = z22 - (b00+b01*y2+x2* (b10+b11*y2))\r\n dz23 = z23 - (b00+b01*y3+x2* (b10+b11*y3))\r\n dz30 = z30 - (b00+b10*x3)\r\n dz31 = z31 - (b00+b01*y1+x3* (b10+b11*y1))\r\n dz32 = z32 - (b00+b01*y2+x3* (b10+b11*y2))\r\n dz33 = z33 - (b00+b01*y3+x3* (b10+b11*y3))\r\n volf = dz00**2 + dz01**2 + dz02**2 + dz03**2 + &\r\n dz10**2 + dz11**2 + dz12**2 + dz13**2 + &\r\n dz20**2 + dz21**2 + dz22**2 + dz23**2 + &\r\n dz30**2 + dz31**2 + dz32**2 + dz33**2\r\n disf = sxx*syy\r\n! Calculates EPSLN.\r\n epsln = (z00**2 + z01**2 + z02**2 + z03**2 + z10**2 + &\r\n z11**2 + z12**2 + z13**2 + z20**2 + z21**2 + z22**2 + &\r\n z23**2 + z30**2 + z31**2 + z32**2 + z33**2)* 1.0E-12\r\n! Accumulates the weighted primary estimates of zxy and their weights.\r\n IF (volf > epsln) THEN\r\n! - For a finite weight.\r\n wt = 1.0/ (volf*disf)\r\n smpef = smpef + wt*pezxy\r\n smwtf = smwtf + wt\r\n ELSE\r\n! - For an infinite weight.\r\n smpei = smpei + pezxy\r\n smwti = smwti + 1.0\r\n END IF\r\n END DO\r\n END DO\r\n\r\n! Calculates the final estimate of zxy.\r\n IF (smwti < 0.5) THEN\r\n! - When no infinite weights exist.\r\n zxydi = smpef/smwtf\r\n ELSE\r\n! - When infinite weights exist.\r\n zxydi = smpei/smwti\r\n END IF\r\n! End of Part 3\r\n\r\n pdd(1,ix0,iy0) = zxdi\r\n pdd(2,ix0,iy0) = zydi\r\n pdd(3,ix0,iy0) = zxydi\r\n END DO\r\nEND DO\r\nRETURN\r\nEND SUBROUTINE rgpd3p\r\n\r\n\r\n\r\nSUBROUTINE rglctn(nxd, nyd, xd, yd, nip, xi, yi, inxi, inyi)\r\n\r\n! Location of the desired points in a rectangular grid\r\n! (a supporting subroutine of the RGBI3P/RGSF3P subroutine package)\r\n\r\n! Hiroshi Akima\r\n! U.S. Department of Commerce, NTIA/ITS\r\n! Version of 1995/08\r\n\r\n! This subroutine locates the desired points in a rectangular grid\r\n! in the x-y plane.\r\n\r\n! The grid lines can be unevenly spaced.\r\n\r\n! The input arguments are\r\n! NXD = number of the input-grid data points in the x\r\n! coordinate (must be 2 or greater),\r\n! NYD = number of the input-grid data points in the y\r\n! coordinate (must be 2 or greater),\r\n! XD = array of dimension NXD containing the x coordinates of the\r\n! input-grid data points (must be in a monotonic increasing order),\r\n! YD = array of dimension NYD containing the y coordinates of the\r\n! input-grid data points (must be in a monotonic increasing order),\r\n! NIP = number of the output points to be located (must be 1 or greater),\r\n! XI = array of dimension NIP containing the x coordinates\r\n! of the output points to be located,\r\n! YI = array of dimension NIP containing the y coordinates\r\n! of the output points to be located.\r\n\r\n! The output arguments are\r\n! INXI = integer array of dimension NIP where the interval\r\n! numbers of the XI array elements are to be stored,\r\n! INYI = integer array of dimension NIP where the interval\r\n! numbers of the YI array elements are to be stored.\r\n! The interval numbers are between 0 and NXD and between 0 and NYD,\r\n! respectively.\r\n\r\n\r\n! Specification statements\r\n! .. Scalar Arguments ..\r\n\r\nINTEGER, INTENT(IN) :: nxd\r\nINTEGER, INTENT(IN) :: nyd\r\nREAL, INTENT(IN) :: xd(nxd)\r\nREAL, INTENT(IN) :: yd(nyd)\r\nINTEGER, INTENT(IN) :: nip\r\nREAL, INTENT(IN) :: xi(nip)\r\nREAL, INTENT(IN) :: yi(nip)\r\nINTEGER, INTENT(OUT) :: inxi(nip)\r\nINTEGER, INTENT(OUT) :: inyi(nip)\r\n\r\n! ..\r\n! .. Local Scalars ..\r\nREAL :: xii, yii\r\nINTEGER :: iip, imd, imn, imx, ixd, iyd, nintx, ninty\r\n\r\n! ..\r\n! DO-loop with respect to IIP, which is the point number of the output point\r\nDO iip = 1,nip\r\n xii = xi(iip)\r\n yii = yi(iip)\r\n! Checks if the x coordinate of the IIPth output point, XII, is\r\n! in a new interval. (NINTX is the new-interval flag.)\r\n IF (iip == 1) THEN\r\n nintx = 1\r\n ELSE\r\n nintx = 0\r\n IF (ixd == 0) THEN\r\n IF (xii > xd(1)) nintx = 1\r\n ELSE IF (ixd < nxd) THEN\r\n IF ((xii < xd(ixd)) .OR. (xii > xd(ixd+1))) nintx = 1\r\n ELSE\r\n IF (xii < xd(nxd)) nintx = 1\r\n END IF\r\n END IF\r\n\r\n! Locates the output point by binary search if XII is in a new interval.\r\n! Determines IXD for which XII lies between XD(IXD) and XD(IXD+1).\r\n IF (nintx == 1) THEN\r\n IF (xii <= xd(1)) THEN\r\n ixd = 0\r\n ELSE IF (xii < xd(nxd)) THEN\r\n imn = 1\r\n imx = nxd\r\n imd = (imn+imx)/2\r\n 10 IF (xii >= xd(imd)) THEN\r\n imn = imd\r\n ELSE\r\n imx = imd\r\n END IF\r\n imd = (imn+imx)/2\r\n IF (imd > imn) GO TO 10\r\n ixd = imd\r\n ELSE\r\n ixd = nxd\r\n END IF\r\n END IF\r\n inxi(iip) = ixd\r\n\r\n! Checks if the y coordinate of the IIPth output point, YII, is\r\n! in a new interval. (NINTY is the new-interval flag.)\r\n IF (iip == 1) THEN\r\n ninty = 1\r\n ELSE\r\n ninty = 0\r\n IF (iyd == 0) THEN\r\n IF (yii > yd(1)) ninty = 1\r\n ELSE IF (iyd < nyd) THEN\r\n IF ((yii < yd(iyd)) .OR. (yii > yd(iyd+1))) ninty = 1\r\n ELSE\r\n IF (yii < yd(nyd)) ninty = 1\r\n END IF\r\n END IF\r\n\r\n! Locates the output point by binary search if YII is in a new interval.\r\n! Determines IYD for which YII lies between YD(IYD) and YD(IYD+1).\r\n IF (ninty == 1) THEN\r\n IF (yii <= yd(1)) THEN\r\n iyd = 0\r\n ELSE IF (yii < yd(nyd)) THEN\r\n imn = 1\r\n imx = nyd\r\n imd = (imn+imx)/2\r\n 20 IF (yii >= yd(imd)) THEN\r\n imn = imd\r\n ELSE\r\n imx = imd\r\n END IF\r\n imd = (imn+imx)/2\r\n IF (imd > imn) GO TO 20\r\n iyd = imd\r\n ELSE\r\n iyd = nyd\r\n END IF\r\n END IF\r\n inyi(iip) = iyd\r\nEND DO\r\nRETURN\r\nEND SUBROUTINE rglctn\r\n\r\n\r\n\r\nSUBROUTINE rgplnl(nxd, nyd, xd, yd, zd, pdd, nip, xi, yi, inxi, inyi, zi)\r\n\r\n! Polynomials for rectangular-grid bivariate interpolation and surface fitting\r\n! (a supporting subroutine of the RGBI3P/RGSF3P subroutine package)\r\n\r\n! Hiroshi Akima\r\n! U.S. Department of Commerce, NTIA/ITS\r\n! Version of 1995/08\r\n\r\n! This subroutine determines a polynomial in x and y for a rectangle of the\r\n! input grid in the x-y plane and calculates the z value for the desired\r\n! points by evaluating the polynomial for rectangular-grid bivariate\r\n! interpolation and surface fitting.\r\n\r\n! The input arguments are\r\n! NXD = number of the input-grid data points in the x\r\n! coordinate (must be 2 or greater),\r\n! NYD = number of the input-grid data points in the y\r\n! coordinate (must be 2 or greater),\r\n! XD = array of dimension NXD containing the x coordinates of the\r\n! input-grid data points (must be in a monotonic increasing order),\r\n! YD = array of dimension NYD containing the y coordinates of the\r\n! input-grid data points (must be in a monotonic increasing order),\r\n! ZD = two-dimensional array of dimension NXD*NYD\r\n! containing the z(x,y) values at the input-grid data points,\r\n! PDD = three-dimensional array of dimension 3*NXD*NYD\r\n! containing the estimated zx, zy, and zxy values\r\n! at the input-grid data points,\r\n! NIP = number of the output points at which interpolation\r\n! is to be performed,\r\n! XI = array of dimension NIP containing the x coordinates\r\n! of the output points,\r\n! YI = array of dimension NIP containing the y coordinates\r\n! of the output points,\r\n! INXI = integer array of dimension NIP containing the\r\n! interval numbers of the input grid intervals in the\r\n! x direction where the x coordinates of the output points lie,\r\n! INYI = integer array of dimension NIP containing the\r\n! interval numbers of the input grid intervals in the\r\n! y direction where the y coordinates of the output points lie.\r\n\r\n! The output argument is\r\n! ZI = array of dimension NIP, where the interpolated z\r\n! values at the output points are to be stored.\r\n\r\n\r\n! Specification statements\r\n! .. Scalar Arguments ..\r\n\r\nINTEGER, INTENT(IN) :: nxd\r\nINTEGER, INTENT(IN) :: nyd\r\nREAL, INTENT(IN) :: xd(nxd)\r\nREAL, INTENT(IN) :: yd(nyd)\r\nREAL, INTENT(IN) :: zd(nxd,nyd)\r\nREAL, INTENT(IN) :: pdd(3,nxd,nyd)\r\nINTEGER, INTENT(IN) :: nip\r\nREAL, INTENT(IN) :: xi(nip)\r\nREAL, INTENT(IN) :: yi(nip)\r\nINTEGER, INTENT(IN) :: inxi(nip)\r\nINTEGER, INTENT(IN) :: inyi(nip)\r\nREAL, INTENT(OUT) :: zi(nip)\r\n\r\n! ..\r\n! .. Local Scalars ..\r\nREAL :: a, b, c, d, dx, dxsq, dy, dysq, p00, p01, p02, p03, p10, p11, &\r\n p12, p13, p20, p21, p22, p23, p30, p31, p32, p33, q0, q1, q2, &\r\n q3, u, v, x0, xii, y0, yii, z00, z01, z0dx, z0dy, z10, z11, &\r\n z1dx, z1dy, zdxdy, zii, zx00, zx01, zx0dy, zx10, zx11, &\r\n zx1dy, zxy00, zxy01, zxy10, zxy11, zy00, zy01, zy0dx, zy10, zy11, zy1dx\r\nINTEGER :: iip, ixd0, ixd1, ixdi, ixdipv, iyd0, iyd1, iydi, iydipv\r\n! ..\r\n! .. Intrinsic Functions ..\r\n! INTRINSIC MAX\r\n! ..\r\n\r\n! Calculation\r\n! Outermost DO-loop with respect to the output point\r\nDO iip = 1,nip\r\n xii = xi(iip)\r\n yii = yi(iip)\r\n IF (iip == 1) THEN\r\n ixdipv = -1\r\n iydipv = -1\r\n ELSE\r\n ixdipv = ixdi\r\n iydipv = iydi\r\n END IF\r\n ixdi = inxi(iip)\r\n iydi = inyi(iip)\r\n\r\n! Retrieves the z and partial derivative values at the origin of\r\n! the coordinate for the rectangle.\r\n IF (ixdi /= ixdipv .OR. iydi /= iydipv) THEN\r\n ixd0 = MAX(1,ixdi)\r\n iyd0 = MAX(1,iydi)\r\n x0 = xd(ixd0)\r\n y0 = yd(iyd0)\r\n z00 = zd(ixd0,iyd0)\r\n zx00 = pdd(1,ixd0,iyd0)\r\n zy00 = pdd(2,ixd0,iyd0)\r\n zxy00 = pdd(3,ixd0,iyd0)\r\n END IF\r\n\r\n! Case 1. When the rectangle is inside the data area in both the\r\n! x and y directions.\r\n IF ((ixdi > 0 .AND. ixdi < nxd) .AND. (iydi > 0 .AND. iydi < nyd)) THEN\r\n! Retrieves the z and partial derivative values at the other three\r\n! vertices of the rectangle.\r\n IF (ixdi /= ixdipv .OR. iydi /= iydipv) THEN\r\n ixd1 = ixd0 + 1\r\n dx = xd(ixd1) - x0\r\n dxsq = dx*dx\r\n iyd1 = iyd0 + 1\r\n dy = yd(iyd1) - y0\r\n dysq = dy*dy\r\n z10 = zd(ixd1,iyd0)\r\n z01 = zd(ixd0,iyd1)\r\n z11 = zd(ixd1,iyd1)\r\n zx10 = pdd(1,ixd1,iyd0)\r\n zx01 = pdd(1,ixd0,iyd1)\r\n zx11 = pdd(1,ixd1,iyd1)\r\n zy10 = pdd(2,ixd1,iyd0)\r\n zy01 = pdd(2,ixd0,iyd1)\r\n zy11 = pdd(2,ixd1,iyd1)\r\n zxy10 = pdd(3,ixd1,iyd0)\r\n zxy01 = pdd(3,ixd0,iyd1)\r\n zxy11 = pdd(3,ixd1,iyd1)\r\n! Calculates the polynomial coefficients.\r\n z0dx = (z10-z00)/dx\r\n z1dx = (z11-z01)/dx\r\n z0dy = (z01-z00)/dy\r\n z1dy = (z11-z10)/dy\r\n zx0dy = (zx01-zx00)/dy\r\n zx1dy = (zx11-zx10)/dy\r\n zy0dx = (zy10-zy00)/dx\r\n zy1dx = (zy11-zy01)/dx\r\n zdxdy = (z1dy-z0dy)/dx\r\n a = zdxdy - zx0dy - zy0dx + zxy00\r\n b = zx1dy - zx0dy - zxy10 + zxy00\r\n c = zy1dx - zy0dx - zxy01 + zxy00\r\n d = zxy11 - zxy10 - zxy01 + zxy00\r\n p00 = z00\r\n p01 = zy00\r\n p02 = (2.0* (z0dy-zy00)+z0dy-zy01)/dy\r\n p03 = (-2.0*z0dy+zy01+zy00)/dysq\r\n p10 = zx00\r\n p11 = zxy00\r\n p12 = (2.0* (zx0dy-zxy00)+zx0dy-zxy01)/dy\r\n p13 = (-2.0*zx0dy+zxy01+zxy00)/dysq\r\n p20 = (2.0* (z0dx-zx00)+z0dx-zx10)/dx\r\n p21 = (2.0* (zy0dx-zxy00)+zy0dx-zxy10)/dx\r\n p22 = (3.0* (3.0*a-b-c)+d)/ (dx*dy)\r\n p23 = (-6.0*a+2.0*b+3.0*c-d)/ (dx*dysq)\r\n p30 = (-2.0*z0dx+zx10+zx00)/dxsq\r\n p31 = (-2.0*zy0dx+zxy10+zxy00)/dxsq\r\n p32 = (-6.0*a+3.0*b+2.0*c-d)/ (dxsq*dy)\r\n p33 = (2.0* (2.0*a-b-c)+d)/ (dxsq*dysq)\r\n END IF\r\n\r\n! Evaluates the polynomial.\r\n u = xii - x0\r\n v = yii - y0\r\n q0 = p00 + v* (p01+v* (p02+v*p03))\r\n q1 = p10 + v* (p11+v* (p12+v*p13))\r\n q2 = p20 + v* (p21+v* (p22+v*p23))\r\n q3 = p30 + v* (p31+v* (p32+v*p33))\r\n zii = q0 + u* (q1+u* (q2+u*q3))\r\n! End of Case 1\r\n\r\n! Case 2. When the rectangle is inside the data area in the x\r\n! direction but outside in the y direction.\r\n ELSE IF ((ixdi > 0.AND.ixdi < nxd) .AND. &\r\n (iydi <= 0.OR.iydi >= nyd)) THEN\r\n! Retrieves the z and partial derivative values at the other\r\n! vertex of the semi-infinite rectangle.\r\n IF (ixdi /= ixdipv .OR. iydi /= iydipv) THEN\r\n ixd1 = ixd0 + 1\r\n dx = xd(ixd1) - x0\r\n dxsq = dx*dx\r\n z10 = zd(ixd1,iyd0)\r\n zx10 = pdd(1,ixd1,iyd0)\r\n zy10 = pdd(2,ixd1,iyd0)\r\n zxy10 = pdd(3,ixd1,iyd0)\r\n! Calculates the polynomial coefficients.\r\n z0dx = (z10-z00)/dx\r\n zy0dx = (zy10-zy00)/dx\r\n p00 = z00\r\n p01 = zy00\r\n p10 = zx00\r\n p11 = zxy00\r\n p20 = (2.0* (z0dx-zx00)+z0dx-zx10)/dx\r\n p21 = (2.0* (zy0dx-zxy00)+zy0dx-zxy10)/dx\r\n p30 = (-2.0*z0dx+zx10+zx00)/dxsq\r\n p31 = (-2.0*zy0dx+zxy10+zxy00)/dxsq\r\n END IF\r\n! Evaluates the polynomial.\r\n u = xii - x0\r\n v = yii - y0\r\n q0 = p00 + v*p01\r\n q1 = p10 + v*p11\r\n q2 = p20 + v*p21\r\n q3 = p30 + v*p31\r\n zii = q0 + u* (q1+u* (q2+u*q3))\r\n! End of Case 2\r\n\r\n! Case 3. When the rectangle is outside the data area in the x\r\n! direction but inside in the y direction.\r\n ELSE IF ((ixdi <= 0.OR.ixdi >= nxd) .AND. &\r\n (iydi > 0 .AND. iydi < nyd)) THEN\r\n! Retrieves the z and partial derivative values at the other\r\n! vertex of the semi-infinite rectangle.\r\n IF (ixdi /= ixdipv .OR. iydi /= iydipv) THEN\r\n iyd1 = iyd0 + 1\r\n dy = yd(iyd1) - y0\r\n dysq = dy*dy\r\n z01 = zd(ixd0,iyd1)\r\n zx01 = pdd(1,ixd0,iyd1)\r\n zy01 = pdd(2,ixd0,iyd1)\r\n zxy01 = pdd(3,ixd0,iyd1)\r\n! Calculates the polynomial coefficients.\r\n z0dy = (z01-z00)/dy\r\n zx0dy = (zx01-zx00)/dy\r\n p00 = z00\r\n p01 = zy00\r\n p02 = (2.0*(z0dy-zy00)+z0dy-zy01)/dy\r\n p03 = (-2.0*z0dy+zy01+zy00)/dysq\r\n p10 = zx00\r\n p11 = zxy00\r\n p12 = (2.0*(zx0dy-zxy00) + zx0dy - zxy01)/dy\r\n p13 = (-2.0*zx0dy + zxy01 + zxy00)/dysq\r\n END IF\r\n\r\n! Evaluates the polynomial.\r\n u = xii - x0\r\n v = yii - y0\r\n q0 = p00 + v* (p01 + v*(p02+v*p03))\r\n q1 = p10 + v* (p11 + v*(p12+v*p13))\r\n zii = q0 + u*q1\r\n! End of Case 3\r\n\r\n! Case 4. When the rectangle is outside the data area in both the\r\n! x and y direction.\r\n ELSE IF ((ixdi <= 0 .OR. ixdi >= nxd) .AND. &\r\n (iydi <= 0 .OR. iydi >= nyd)) THEN\r\n! Calculates the polynomial coefficients.\r\n IF (ixdi /= ixdipv .OR. iydi /= iydipv) THEN\r\n p00 = z00\r\n p01 = zy00\r\n p10 = zx00\r\n p11 = zxy00\r\n END IF\r\n! Evaluates the polynomial.\r\n u = xii - x0\r\n v = yii - y0\r\n q0 = p00 + v*p01\r\n q1 = p10 + v*p11\r\n zii = q0 + u*q1\r\n END IF\r\n! End of Case 4\r\n zi(iip) = zii\r\nEND DO\r\n\r\nRETURN\r\nEND SUBROUTINE rgplnl\r\n\r\nEND MODULE Grid_Interpolation\r\n", "meta": {"hexsha": "24e9d80abeab01015c23932bedbe26576fd45364", "size": 42347, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/toms760.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/toms760.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/toms760.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": 32.624807396, "max_line_length": 80, "alphanum_fraction": 0.5690603821, "num_tokens": 15576, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802395624259, "lm_q2_score": 0.7461390043208003, "lm_q1q2_score": 0.6853139314354385}} {"text": "c\n subroutine cinterp(r,f,nr,rs,ps,dps,work)\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\nc\nc----- this routine interpolates functn f on grid r\nc returns value ps and its derivative dps \nc\n implicit real*8 (a-h,o-z)\n logical deriv\n real*8 r(nr),c(4),work(nr),psr,psi,dpsr,dpsi\n complex*16 f(nr),ps,dps\nc\n ip1=2\n do i=ip1,nr-1\n if (rs.gt.r(i)) ip1=i+1\n enddo\n\nc Real part\n do i=1,nr\n\twork(i)=dreal(f(i))\n enddo\n i=ip1-1\n call fit(r,work,nr,i,c)\nc\n h1=rs-r(i)\n h2=r(ip1)-rs\n c2=1.d0+c(4)*h1*h2\n psr=((c(3)-c(2))*h1+c(1))/c2\n dpsr=c(2)+(c(3)-c(2)+psr*c(4)*(h1-h2))/c2\n psr=psr+dreal(f(i))-c(1)+c(2)*h1\n\nc Imaginary part\n do i=1,nr\n\twork(i)=dimag(f(i))\n enddo\n i=ip1-1\n call fit(r,work,nr,i,c)\nc\n h1=rs-r(i)\n h2=r(ip1)-rs\n c2=1.d0+c(4)*h1*h2\n psi=((c(3)-c(2))*h1+c(1))/c2\n dpsi=c(2)+(c(3)-c(2)+psi*c(4)*(h1-h2))/c2\n psi=psi+dimag(f(i))-c(1)+c(2)*h1\n\n ps=dcmplx(psr,psi)\n dps=dcmplx(dpsr,dpsi)\n \n return\n end\n", "meta": {"hexsha": "e13c3deb5ee642b840b6646d99c797b9bac6641b", "size": 1107, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/Misc/cinterp.f", "max_stars_repo_name": "rdietric/lsms", "max_stars_repo_head_hexsha": "8d0d5f01186abf9a1cc54db3f97f9934b422cf92", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2020-01-05T20:05:31.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T09:08:01.000Z", "max_issues_repo_path": "src/Misc/cinterp.f", "max_issues_repo_name": "rdietric/lsms", "max_issues_repo_head_hexsha": "8d0d5f01186abf9a1cc54db3f97f9934b422cf92", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2019-07-30T13:59:18.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T17:43:35.000Z", "max_forks_repo_path": "lsms/src/Misc/cinterp.f", "max_forks_repo_name": "hkershaw-brown/MuST", "max_forks_repo_head_hexsha": "9db4bc5061c2f2c4d7dfd92f53b4ef952602c070", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2020-02-11T17:04:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-28T09:23:46.000Z", "avg_line_length": 21.7058823529, "max_line_length": 72, "alphanum_fraction": 0.5383920506, "num_tokens": 478, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802417938535, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6853139279155501}} {"text": "\tREAL*4 FUNCTION \r\n . TSAMPLESIZE(XITYPE,XALPHA,POWER,XDIFF,SIGMA,XM)\r\n\tUSE MSIMSL\r\nC\r\nC-Description-----------------------------------------------------------\r\n\tIMPLICIT NONE\r\nC\r\nC Function:\r\nC\tMain routine of program to compute sample size calculations\r\nC\tinvolving t tests.\r\nC\r\nC Input prompted for from user:\r\nC\tPAIRED or INDEPENDENT study type\r\nC\tALPHA\tType I error probability (two tailed)\r\nC\tPOWER\tThe desired statistical power\r\nC\tXDIFF A XDIFFerence in population means\r\nC\tSIGMA\tAn estimate of the within group standard deviation for\r\nC\t\tindependent tests. It is an estimate of the standard\r\nC\t\tdeviation of paired response XDIFFerences for paired data.\r\nC\tM\tthe number of control patients per experimental patient.\r\nC\t\tM is only defined for independent t-tests.\r\nC\r\nC Output:\r\nC\tTSAMPLESIZE\r\nC\t\tSample size needed to detect a true XDIFFerence in\r\nC\t\tpopulation means with type I error probability ALPHA and\r\nC\t\tpower POWER. N=number of pairs of patients needed for\r\nC\t\tpaired designs or number of expermental patients needed for\r\nC\t\tindependent designs. That is, independent designs will\r\nC\t\thave N case patients and M*N control patients.\r\nC\r\nC Notes:\r\nC .\tThis routine was written by Dale Plummer\r\nC .\tThis program uses sample size formulas that are given in Dupont\r\nC\tand Plummer (???). The\tresulting sample size equations are solved \r\nC\titeratively using the secant method.\r\nC\r\nC\tSpecifically, the case sample size N returned by this program\r\nC\tis the solution to the equation\r\nC\r\nC\tN=(TCRVALUE(ALPH/2.,N-1)+TCRVALUE(XBETA,N-1))**2/DELTA**2\r\nC\tfor paired designs or\r\nC\r\nC\tN=(TCRVALUE(ALPH/2.,N*(M+1)-2) + TCRVALUE(XBETA,N*(M+1)-2))**2/DELTA**2\r\nC\tfor independent designs\r\nC\r\nC\twhere TCRVALUE(P,J) returns the critical value that is exceeded\r\nC\tby a t statistic with J degrees of freedom with probability P,\r\nC\tand DELTA is a XDIFFerence in means measured in standard deviations.\r\nC\tFor paired designs DELTA=XDIFF/SIGMA. For indepedent designs\r\nC\tDELTA=XDIFF/(SIGMA*SQRT(1.+1./M)\r\nC\r\nC\tThe resulting sample size calculations produced by this program\r\nC\tare in close agreement with those obtained from Table 10 of\r\nC\tPearson and Hartley, Biometrika Tables for Statisticians, Vol I,\r\nC\t3rd Ed., Cambridge: Cambridge U. Press, 1970.\r\nC\r\nC-Declarations----------------------------------------------------------\r\nC\r\nC\r\nC Arguments\r\nC\r\n\tREAL*4 XALPHA,POWER,XDIFF,SIGMA,XM\r\n\tINTEGER*4 XITYPE\r\nC\r\nC Functions\r\nC\r\nC\tREAL TCRVALUE\r\n\tREAL TSIZE,ZCRVALUE\r\n\tEXTERNAL TSIZE\r\nC\r\nC Common used to pass needed values to passed name functions.\r\nC\r\n\tINTEGER ITYPE\r\n\tREAL ALPHA, XBETA, DELTA, M, NU\r\n\tCOMMON /TSSCOMM/ ALPHA, XBETA, DELTA, M, NU, ITYPE\r\n\r\n\tREAL EPS, ERRABS, ERRREL, ETA, XGUESS(1), XVECT(1)\r\n\tINTEGER ITMAX, NROOT, INFO(1)\r\n\r\n\tINTEGER DFRESET\r\n\tCOMMON /DFRESET/ DFRESET\r\nC\r\nC-Code------------------------------------------------------------------\r\nC\r\nC Copy data to local/common variables as appropriate.\r\nC\r\n\tALPHA=XALPHA\r\n\tITYPE=XITYPE\r\n\tM=XM\r\n\tXBETA=1.-POWER\r\nC\r\nC Set delta depending on whether the model is paired or independent.\r\nC\r\n\tIF (ITYPE.EQ.1) THEN\r\nC\r\nC Paired\r\nC ' Enter ALPHA, POWER, XDIFF and SIGMA: '\r\nC\r\n\t DELTA=XDIFF/SIGMA\r\n\tELSE IF (ITYPE.EQ.2) THEN\r\nC\r\nC Independent\r\nC ' Enter ALPHA, POWER, XDIFF, SIGMA, and M: '\r\nC\r\n\t DELTA=XDIFF/(SIGMA*SQRT(1.+1./M))\r\n\tELSE\r\n\t TSAMPLESIZE=-999\r\n\t\tRETURN\r\n\tEND IF\r\nC\r\nC Solve for sample size. Note that NU is calculated in the\r\nC TSIZE routine.\r\nC\r\nC\r\nC ERRABS - First stopping criterion. A zero X(I) is accepted if ABS(F(X(I)).LT. ERRABS.\r\nC\r\nC\tERRABS=1.0E-5\r\n\tERRABS=1.0E-4\r\n\r\nC\r\nC EPS - See ETA.\r\nC\r\nC\tEPS=1.0E-5\r\n\tEPS=1.0E-4\r\nC\r\nC ERRREL - Second stopping criterion is the relative error. A zero X(I) is\r\nC accepted if the relative change of two successive approximations\r\nC to X(I) is less than ERRREL.\r\nC\r\nC\tERRREL=1.0E-5\r\n\tERRREL=1.0E-4\r\nC\r\nC ETA - Spread criteria for multiple zeros. If the zero X(I) has been computed \r\nC and ABS(X(I) - X(J)).LT.EPS, where X(J) is a previously computed zero, \r\nC then the computation is restarted with a guess equal to X(I) + ETA.\r\nC\r\n\tETA=1.0E-2\r\nC\r\nC ITMAX - The maximum allowable number of iterations per zero.\r\nC\r\n\tITMAX=100\r\nC\r\nC NROOT - The number of zeros to be found by ZREAL.\r\nC\r\n\tNROOT=1\r\nC\r\nC XGUESS - A vector of length NROOT. XGUESS contains the initial guesses \r\nC for the zeros.\r\nC\r\n\tXGUESS(1)=(ZCRVALUE(ALPHA/2.)+ZCRVALUE(XBETA))**2./(DELTA**2)\r\nC\r\nC In TSIZE the degrees of freedom can be manipulated. DFRESET will be\r\nC set to one if that happens. Initialize it to zero here. See TSIZE\r\nC for details.\r\nC\r\n\tDFRESET=0\r\nC\r\nC Find the zero of the function TSIZE. When TSIZE is zero XVECT(1) is the \r\nC sample size needed to detect a true difference DELTA with power 1-BETA\r\nC and Type I error probability ALPHA.\r\nC\r\nC XVECT - A vector of length NROOT. XVECT contains the computed zeros.\r\nC INFO - An integer vector of length NROOT. INFO(J) contains the number of \r\nC iterations used in finding the J-th zero when convergence was achieved. \r\nC If convergence was not obtained in ITMAX iterations, INFO(J) will be \r\nC greater than ITMAX.\r\nC\r\n\tCALL ZREAL\r\n .\t(TSIZE,ERRABS,ERRREL,EPS,ETA,NROOT,ITMAX,XGUESS,XVECT,INFO)\r\nC\r\nC If convergence was not reached then INFO(1) will be greater than\r\nC ITMAX. Check for that here.\r\nC\r\n\tIF (INFO(1).GT.ITMAX) THEN\r\n\t TSAMPLESIZE=-999\r\n\t\tRETURN\r\n\tEND IF\r\nC\r\nC Otherwise convergence was reached. Record the resultant sample size.\r\nC\r\n\tTSAMPLESIZE=XVECT(1)\r\nC\r\nC If conditions warrent then output the disclaimer. Do loop through\r\nC 6 and 7 to write to both terminal and log file.\r\nC\r\nCCC\t TALPHA=TCRVALUE(ALPHA/2.,NU)\r\nCCC\t TXBETA=TCRVALUE(XBETA/2.,NU)\r\nCCC\t IF (2.*TALPHA+TXBETA .LE. 3.1) THEN\r\nCCC\t\t CALL HLPMSG(IUNIT,7)\r\nCCC\t\t WRITE(UNIT=IUNIT,FMT='(5X,A,I6,A,F12.4,A,/,5X,A,F12.4,A,/)')\r\nCCC .' associated with N=',N,' will be no less than ',1.-XBETA,' and',\r\nCCC .' no greater than ',1.-XBETA+ALPHA/2.,'.'\r\nCCC\t END IF\r\n\tRETURN\r\n\tEND\r\n", "meta": {"hexsha": "6cabba910421264537b499bee54c088da1c60141", "size": 6084, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "misc/old_ps/ps-development-version/psDll/tsamples.for", "max_stars_repo_name": "vubiostat/ps", "max_stars_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2017-12-29T14:19:14.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-06T15:08:46.000Z", "max_issues_repo_path": "misc/old_ps/ps-development-version/psDll/tsamples.for", "max_issues_repo_name": "vubiostat/ps", "max_issues_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2020-04-30T16:57:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-07T00:26:02.000Z", "max_forks_repo_path": "misc/old_ps/ps-development-version/psDll/tsamples.for", "max_forks_repo_name": "vubiostat/ps", "max_forks_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-07T20:11:54.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-11T19:18:59.000Z", "avg_line_length": 30.883248731, "max_line_length": 92, "alphanum_fraction": 0.6808021039, "num_tokens": 1875, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802484881361, "lm_q2_score": 0.7461389930307512, "lm_q1q2_score": 0.685313927725572}} {"text": "module solver_class\n \n type solver\n integer::Bodies\n real(8),dimension(10) :: mass\n real(8),dimension(10,3) :: position\n real(8),dimension(10,3) :: velocity\n contains\n procedure ::relative_position\n procedure ::forces\n procedure ::calc_position\n procedure ::calc_velocities\n procedure ::kinetic_energy\n procedure ::potential_energy\n procedure ::angular_momentum\n\n end type solver\n\ncontains\n subroutine relative_position(system,numbodies,relposition)\n implicit none\n\n class (solver),intent(in)::system\n integer :: i,j\n integer,intent(in)::NumBodies\n real(8),dimension(Numbodies,Numbodies,4):: relposition\n \n do i=1,NumBodies\n do j =1,NumBodies\n if (i.ne.j) then\n relposition(j,i,1)=system%position(j,1)-system%position(i,1)\n relposition(j,i,2)=system%position(j,2)-system%position(i,2)\n relposition(j,i,3)=system%position(j,3)-system%position(i,3)\n relposition(j,i,4)=sqrt(relposition(j,i,1)*relposition(j,i,1)+relposition(j,i,2)*relposition(j,i,2)+relposition(j,i,3)*relposition(j,i,3))\n end if\n end do\n end do\n \n return \n end subroutine relative_position\n\n subroutine forces(system,Numbodies,relposition,relforce)\n implicit none\n\n class(solver),intent(in)::system\n integer :: j,i\n integer,intent(in):: Numbodies\n real(8),dimension(Numbodies,3)::relforce\n real(8),dimension(Numbodies,Numbodies,4):: relposition\n real(8)::rrr,Fourpi2\n Fourpi2 = 4.d0*3.14*3.14\n\n \n do i=1,numbodies\n do j=1,numbodies\n relforce(i,j)=0.d0\n end do\n end do\n \n\n do i=1,numbodies\n do j=1,numbodies\n if(j.ne.i) then\n rrr=(relposition(j,i,4)**3.d0)\n relforce(i,1) =relforce(i,1) - Fourpi2*system%mass(j)*relposition(j,i,1)/rrr\n relforce(i,2) =relforce(i,2) - Fourpi2*system%mass(j)*relposition(j,i,2)/rrr\n relforce(i,3) =relforce(i,3) - Fourpi2*system%mass(j)*relposition(j,i,3)/rrr\n end if\n end do\n end do\n end subroutine forces\n\n\n subroutine calc_position(system,Numbodies,relforce,h)\n implicit none\n class(solver), intent(inout)::system\n integer,intent(in)::Numbodies\n integer::i,j\n real(8),dimension(Numbodies,3)::relforce\n real(8)::h\n\n do i=1,numbodies\n system%position(i,1)=system%position(i,1)+h*system%velocity(i,1) - (h*h/2.d0)*relforce(i,1)\n system%position(i,2)=system%position(i,2)+h*system%velocity(i,2) - (h*h/2.d0)*relforce(i,2)\n system%position(i,3)=system%position(i,3)+h*system%velocity(i,3) - (h*h/2.d0)*relforce(i,3)\n end do\n\n end subroutine calc_position\n\n subroutine calc_velocities(system,numbodies,relforce,updatedforce,h)\n implicit none\n class(solver),intent(inout)::system\n integer,intent(in)::NumBodies\n integer::i,j\n real(8)::h\n real(8),dimension(Numbodies,3)::relforce\n real(8),dimension(Numbodies,3)::updatedforce\n\n do i=1, numbodies\n system%velocity(i,1)=system%velocity(i,1)-h*0.5*updatedforce(i,1)-h*0.5*relforce(i,1)\n system%velocity(i,2)=system%velocity(i,2)-h*0.5*updatedforce(i,2)-h*0.5*relforce(i,2)\n system%velocity(i,3)=system%velocity(i,3)-h*0.5*updatedforce(i,3)-h*0.5*relforce(i,3)\n end do\n\n end subroutine calc_velocities\n \n subroutine kinetic_energy(system,numbodies,kinetic)\n implicit none\n class(solver), intent(in)::system\n integer,intent(in)::Numbodies\n integer::i\n real(8),dimension(numbodies+1)::kinetic\n real(8)::totalke\n\n totalke=0\n \n do i =1,numbodies\n kinetic(i)=(1.d0/2.d0)*system%mass(i)*(system%velocity(i,1)*system%velocity(i,1)+system%velocity(i,2)*system%velocity(i,2)+system%velocity(i,3)*system%velocity(1,3))\n totalke=totalke+kinetic(i)\n end do\n\n kinetic(numbodies+1)=totalke\n end subroutine kinetic_energy\n\n subroutine potential_energy(system, numbodies,relposition,potential)\n implicit none\n class(solver), intent(in)::system\n integer,intent(in)::Numbodies\n integer::i,j\n real(8),dimension(numbodies+1)::potential\n real(8),dimension(numbodies,numbodies,4)::relposition\n real(8)::totalpe\n\n totalpe=0\n do i=1,numbodies+1\n potential(i)=0.d0\n end do\n\n do i=1,numbodies\n do j=1,NumBodies\n if (i .ne. j ) then\n potential(i)=potential(i)+(4*3.14*3.14*system%mass(i)*system%mass(j)/relposition(j,i,4))\n end if\n end do\n totalpe=totalpe+potential(i)\n end do\n\n potential(numbodies+1)=totalpe\n end subroutine potential_energy\n\n subroutine angular_momentum(system,numbodies,relposition,angular)\n implicit none\n class(solver),intent(in)::system\n integer,intent(in)::Numbodies\n integer::i,j\n real(8),dimension(numbodies+1)::angular\n real(8),dimension(numbodies,numbodies,3)::relposition\n real(8)::totalang\n\n totalang=0\n\n do i=1,numbodies\n angular(i)=system%mass(i)*relposition(1,i,4)*(sqrt(system%velocity(i,1)**2.d0 + system%velocity(i,2)**2.d0 + system%velocity(i,3)**2.d0))\n totalang=totalang+angular(i)\n end do\n\n angular(numbodies+1)=totalang\n end subroutine angular_momentum\n \n \nend module solver_class\n", "meta": {"hexsha": "936a5215040d69791a1058b4952217f9f2c3e91b", "size": 5206, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "doc/Projects/2018/Project3/CodeExample/Fortran2008Example/solver3d.f90", "max_stars_repo_name": "kimrojas/ComputationalPhysicsMSU", "max_stars_repo_head_hexsha": "a47cfc18b3ad6adb23045b3f49fab18c0333f556", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 220, "max_stars_repo_stars_event_min_datetime": "2016-08-25T09:18:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T14:09:16.000Z", "max_issues_repo_path": "doc/Projects/2018/Project3/CodeExample/Fortran2008Example/solver3d.f90", "max_issues_repo_name": "dnhdang94/ComputationalPhysicsMSU", "max_issues_repo_head_hexsha": "16990c74cf06eb5b933982137f0536d669567259", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-12-04T12:55:10.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-04T12:55:10.000Z", "max_forks_repo_path": "doc/Projects/2018/Project3/CodeExample/Fortran2008Example/solver3d.f90", "max_forks_repo_name": "dnhdang94/ComputationalPhysicsMSU", "max_forks_repo_head_hexsha": "16990c74cf06eb5b933982137f0536d669567259", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 136, "max_forks_repo_forks_event_min_datetime": "2016-08-25T09:04:56.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-12T09:54:21.000Z", "avg_line_length": 30.2674418605, "max_line_length": 172, "alphanum_fraction": 0.658278909, "num_tokens": 1638, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802440252812, "lm_q2_score": 0.7461389817407016, "lm_q1q2_score": 0.6853139140259744}} {"text": " SUBROUTINE SB04PD( DICO, FACTA, FACTB, TRANA, TRANB, ISGN, M, N,\n $ A, LDA, U, LDU, B, LDB, V, LDV, C, LDC, SCALE,\n $ DWORK, LDWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To solve for X either the real continuous-time Sylvester equation\nC\nC op(A)*X + ISGN*X*op(B) = scale*C, (1)\nC\nC or the real discrete-time Sylvester equation\nC\nC op(A)*X*op(B) + ISGN*X = scale*C, (2)\nC\nC where op(M) = M or M**T, and ISGN = 1 or -1. A is M-by-M and\nC B is N-by-N; the right hand side C and the solution X are M-by-N;\nC and scale is an output scale factor, set less than or equal to 1\nC to avoid overflow in X. The solution matrix X is overwritten\nC onto C.\nC\nC If A and/or B are not (upper) quasi-triangular, that is, block\nC upper triangular with 1-by-1 and 2-by-2 diagonal blocks, they are\nC reduced to Schur canonical form, that is, quasi-triangular with\nC each 2-by-2 diagonal block having its diagonal elements equal and\nC its off-diagonal elements of opposite sign.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC DICO CHARACTER*1\nC Specifies the equation from which X is to be determined\nC as follows:\nC = 'C': Equation (1), continuous-time case;\nC = 'D': Equation (2), discrete-time case.\nC\nC FACTA CHARACTER*1\nC Specifies whether or not the real Schur factorization\nC of the matrix A is supplied on entry, as follows:\nC = 'F': On entry, A and U contain the factors from the\nC real Schur factorization of the matrix A;\nC = 'N': The Schur factorization of A will be computed\nC and the factors will be stored in A and U;\nC = 'S': The matrix A is quasi-triangular (or Schur).\nC\nC FACTB CHARACTER*1\nC Specifies whether or not the real Schur factorization\nC of the matrix B is supplied on entry, as follows:\nC = 'F': On entry, B and V contain the factors from the\nC real Schur factorization of the matrix B;\nC = 'N': The Schur factorization of B will be computed\nC and the factors will be stored in B and V;\nC = 'S': The matrix B is quasi-triangular (or Schur).\nC\nC TRANA CHARACTER*1\nC Specifies the form of op(A) to be used, as follows:\nC = 'N': op(A) = A (No transpose);\nC = 'T': op(A) = A**T (Transpose);\nC = 'C': op(A) = A**T (Conjugate transpose = Transpose).\nC\nC TRANB CHARACTER*1\nC Specifies the form of op(B) to be used, as follows:\nC = 'N': op(B) = B (No transpose);\nC = 'T': op(B) = B**T (Transpose);\nC = 'C': op(B) = B**T (Conjugate transpose = Transpose).\nC\nC ISGN INTEGER\nC Specifies the sign of the equation as described before.\nC ISGN may only be 1 or -1.\nC\nC Input/Output Parameters\nC\nC M (input) INTEGER\nC The order of the matrix A, and the number of rows in the\nC matrices X and C. M >= 0.\nC\nC N (input) INTEGER\nC The order of the matrix B, and the number of columns in\nC the matrices X and C. N >= 0.\nC\nC A (input or input/output) DOUBLE PRECISION array,\nC dimension (LDA,M)\nC On entry, the leading M-by-M part of this array must\nC contain the matrix A. If FACTA = 'S', then A contains\nC a quasi-triangular matrix, and if FACTA = 'F', then A\nC is in Schur canonical form; the elements below the upper\nC Hessenberg part of the array A are not referenced.\nC On exit, if FACTA = 'N', and INFO = 0 or INFO >= M+1, the\nC leading M-by-M upper Hessenberg part of this array\nC contains the upper quasi-triangular matrix in Schur\nC canonical form from the Schur factorization of A. The\nC contents of array A is not modified if FACTA = 'F' or 'S'.\nC\nC LDA INTEGER\nC The leading dimension of array A. LDA >= MAX(1,M).\nC\nC U (input or output) DOUBLE PRECISION array, dimension\nC (LDU,M)\nC If FACTA = 'F', then U is an input argument and on entry\nC the leading M-by-M part of this array must contain the\nC orthogonal matrix U of the real Schur factorization of A.\nC If FACTA = 'N', then U is an output argument and on exit,\nC if INFO = 0 or INFO >= M+1, it contains the orthogonal\nC M-by-M matrix from the real Schur factorization of A.\nC If FACTA = 'S', the array U is not referenced.\nC\nC LDU INTEGER\nC The leading dimension of array U.\nC LDU >= MAX(1,M), if FACTA = 'F' or 'N';\nC LDU >= 1, if FACTA = 'S'.\nC\nC B (input or input/output) DOUBLE PRECISION array,\nC dimension (LDB,N)\nC On entry, the leading N-by-N part of this array must\nC contain the matrix B. If FACTB = 'S', then B contains\nC a quasi-triangular matrix, and if FACTB = 'F', then B\nC is in Schur canonical form; the elements below the upper\nC Hessenberg part of the array B are not referenced.\nC On exit, if FACTB = 'N', and INFO = 0 or INFO = M+N+1,\nC the leading N-by-N upper Hessenberg part of this array\nC contains the upper quasi-triangular matrix in Schur\nC canonical form from the Schur factorization of B. The\nC contents of array B is not modified if FACTB = 'F' or 'S'.\nC\nC LDB (input) INTEGER\nC The leading dimension of the array B. LDB >= max(1,N).\nC\nC V (input or output) DOUBLE PRECISION array, dimension\nC (LDV,N)\nC If FACTB = 'F', then V is an input argument and on entry\nC the leading N-by-N part of this array must contain the\nC orthogonal matrix V of the real Schur factorization of B.\nC If FACTB = 'N', then V is an output argument and on exit,\nC if INFO = 0 or INFO = M+N+1, it contains the orthogonal\nC N-by-N matrix from the real Schur factorization of B.\nC If FACTB = 'S', the array V is not referenced.\nC\nC LDV INTEGER\nC The leading dimension of array V.\nC LDV >= MAX(1,N), if FACTB = 'F' or 'N';\nC LDV >= 1, if FACTB = 'S'.\nC\nC C (input/output) DOUBLE PRECISION array, dimension (LDC,N)\nC On entry, the leading M-by-N part of this array must\nC contain the right hand side matrix C.\nC On exit, if INFO = 0 or INFO = M+N+1, the leading M-by-N\nC part of this array contains the solution matrix X.\nC\nC LDC INTEGER\nC The leading dimension of array C. LDC >= MAX(1,M).\nC\nC SCALE (output) DOUBLE PRECISION\nC The scale factor, scale, set less than or equal to 1 to\nC prevent the solution overflowing.\nC\nC Workspace\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0 or M+N+1, then: DWORK(1) returns the\nC optimal value of LDWORK; if FACTA = 'N', DWORK(1+i) and\nC DWORK(1+M+i), i = 1,...,M, contain the real and imaginary\nC parts, respectively, of the eigenvalues of A; and, if\nC FACTB = 'N', DWORK(1+f+j) and DWORK(1+f+N+j), j = 1,...,N,\nC with f = 2*M if FACTA = 'N', and f = 0, otherwise, contain\nC the real and imaginary parts, respectively, of the\nC eigenvalues of B.\nC\nC LDWORK INTEGER\nC The length of the array DWORK.\nC LDWORK >= MAX( 1, a+MAX( c, b+d, b+e ) ),\nC where a = 1+2*M, if FACTA = 'N',\nC a = 0, if FACTA <> 'N',\nC b = 2*N, if FACTB = 'N', FACTA = 'N',\nC b = 1+2*N, if FACTB = 'N', FACTA <> 'N',\nC b = 0, if FACTB <> 'N',\nC c = 3*M, if FACTA = 'N',\nC c = M, if FACTA = 'F',\nC c = 0, if FACTA = 'S',\nC d = 3*N, if FACTB = 'N',\nC d = N, if FACTB = 'F',\nC d = 0, if FACTB = 'S',\nC e = M, if DICO = 'C', FACTA <> 'S',\nC e = 0, if DICO = 'C', FACTA = 'S',\nC e = 2*M, if DICO = 'D'.\nC An upper bound is\nC LDWORK = 1+2*M+MAX( 3*M, 5*N, 2*N+2*M ).\nC For good performance, LDWORK should be larger, e.g.,\nC LDWORK = 1+2*M+MAX( 3*M, 5*N, 2*N+2*M, 2*N+M*N ).\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value;\nC = i: if INFO = i, i = 1,...,M, the QR algorithm failed\nC to compute all the eigenvalues of the matrix A\nC (see LAPACK Library routine DGEES); the elements\nC 2+i:1+M and 2+i+M:1+2*M of DWORK contain the real\nC and imaginary parts, respectively, of the\nC eigenvalues of A which have converged, and the\nC array A contains the partially converged Schur form;\nC = M+j: if INFO = M+j, j = 1,...,N, the QR algorithm\nC failed to compute all the eigenvalues of the matrix\nC B (see LAPACK Library routine DGEES); the elements\nC 2+f+j:1+f+N and 2+f+j+N:1+f+2*N of DWORK contain the\nC real and imaginary parts, respectively, of the\nC eigenvalues of B which have converged, and the\nC array B contains the partially converged Schur form;\nC as defined for the parameter DWORK,\nC f = 2*M, if FACTA = 'N',\nC f = 0, if FACTA <> 'N';\nC = M+N+1: if DICO = 'C', and the matrices A and -ISGN*B\nC have common or very close eigenvalues, or\nC if DICO = 'D', and the matrices A and -ISGN*B have\nC almost reciprocal eigenvalues (that is, if lambda(i)\nC and mu(j) are eigenvalues of A and -ISGN*B, then\nC lambda(i) = 1/mu(j) for some i and j);\nC perturbed values were used to solve the equation\nC (but the matrices A and B are unchanged).\nC\nC METHOD\nC\nC An extension and refinement of the algorithms in [1,2] is used.\nC If the matrices A and/or B are not quasi-triangular (see PURPOSE),\nC they are reduced to Schur canonical form\nC\nC A = U*S*U', B = V*T*V',\nC\nC where U, V are orthogonal, and S, T are block upper triangular\nC with 1-by-1 and 2-by-2 blocks on their diagonal. The right hand\nC side matrix C is updated accordingly,\nC\nC C = U'*C*V;\nC\nC then, the solution matrix X of the \"reduced\" Sylvester equation\nC (with A and B in (1) or (2) replaced by S and T, respectively),\nC is computed column-wise via a back substitution scheme. A set of\nC equivalent linear algebraic systems of equations of order at most\nC four are formed and solved using Gaussian elimination with\nC complete pivoting. Finally, the solution X of the original\nC equation is obtained from the updating formula\nC\nC X = U*X*V'.\nC\nC If A and/or B are already quasi-triangular (or in Schur form), the\nC initial factorizations and the corresponding updating steps are\nC omitted.\nC\nC REFERENCES\nC\nC [1] Bartels, R.H. and Stewart, G.W. T\nC Solution of the matrix equation A X + XB = C.\nC Comm. A.C.M., 15, pp. 820-826, 1972.\nC\nC [2] Anderson, E., Bai, Z., Bischof, C., Demmel, J., Dongarra, J.,\nC Du Croz, J., Greenbaum, A., Hammarling, S., McKenney, A.,\nC Ostrouchov, S., and Sorensen, D.\nC LAPACK Users' Guide: Second Edition.\nC SIAM, Philadelphia, 1995.\nC\nC NUMERICAL ASPECTS\nC\nC The algorithm is stable and reliable, since orthogonal\nC transformations and Gaussian elimination with complete pivoting\nC are used. If INFO = M+N+1, the Sylvester equation is numerically\nC singular.\nC\nC CONTRIBUTORS\nC\nC D. Sima, University of Bucharest, April 2000.\nC V. Sima, Research Institute for Informatics, Bucharest, Apr. 2000.\nC\nC REVISIONS\nC\nC -\nC\nC KEYWORDS\nC\nC Matrix algebra, orthogonal transformation, real Schur form,\nC Sylvester equation.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, ONE\n PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )\nC ..\nC .. Scalar Arguments ..\n CHARACTER DICO, FACTA, FACTB, TRANA, TRANB\n INTEGER INFO, ISGN, LDA, LDB, LDC, LDU, LDV, LDWORK, M,\n $ N\n DOUBLE PRECISION SCALE\nC ..\nC .. Array Arguments ..\n DOUBLE PRECISION A( LDA, * ), B( LDB, * ), C( LDC, * ),\n $ DWORK( * ), U( LDU, * ), V( LDV, * )\nC ..\nC .. Local Scalars ..\n LOGICAL BLAS3A, BLAS3B, BLOCKA, BLOCKB, CONT, NOFACA,\n $ NOFACB, NOTRNA, NOTRNB, SCHURA, SCHURB\n INTEGER AVAILW, BL, CHUNKA, CHUNKB, I, IA, IB, IERR, J,\n $ JWORK, MAXWRK, MINWRK, SDIM\nC ..\nC .. Local Arrays ..\n LOGICAL BWORK( 1 )\nC ..\nC .. External Functions ..\n LOGICAL LSAME, SELECT\n EXTERNAL LSAME, SELECT\nC ..\nC .. External Subroutines ..\n EXTERNAL DCOPY, DGEES, DGEMM, DGEMV, DLACPY, DTRSYL,\n $ SB04PY, XERBLA\nC ..\nC .. Intrinsic Functions ..\n INTRINSIC DBLE, INT, MAX, MIN\nC ..\nC .. Executable Statements ..\nC\nC Decode and Test input parameters\nC\n CONT = LSAME( DICO, 'C' )\n NOFACA = LSAME( FACTA, 'N' )\n NOFACB = LSAME( FACTB, 'N' )\n SCHURA = LSAME( FACTA, 'S' )\n SCHURB = LSAME( FACTB, 'S' )\n NOTRNA = LSAME( TRANA, 'N' )\n NOTRNB = LSAME( TRANB, 'N' )\nC\n INFO = 0\n IF( .NOT.CONT .AND. .NOT.LSAME( DICO, 'D' ) ) THEN\n INFO = -1\n ELSE IF( .NOT.NOFACA .AND. .NOT.LSAME( FACTA, 'F' ) .AND.\n $ .NOT.SCHURA ) THEN\n INFO = -2\n ELSE IF( .NOT.NOFACB .AND. .NOT.LSAME( FACTB, 'F' ) .AND.\n $ .NOT.SCHURB ) THEN\n INFO = -3\n ELSE IF( .NOT.NOTRNA .AND. .NOT.LSAME( TRANA, 'T' ) .AND.\n $ .NOT.LSAME( TRANA, 'C' ) ) THEN\n INFO = -4\n ELSE IF( .NOT.NOTRNB .AND. .NOT.LSAME( TRANB, 'T' ) .AND.\n $ .NOT.LSAME( TRANB, 'C' ) ) THEN\n INFO = -5\n ELSE IF( ISGN.NE.1 .AND. ISGN.NE.-1 ) THEN\n INFO = -6\n ELSE IF( M.LT.0 ) THEN\n INFO = -7\n ELSE IF( N.LT.0 ) THEN\n INFO = -8\n ELSE IF( LDA.LT.MAX( 1, M ) ) THEN\n INFO = -10\n ELSE IF( LDU.LT.1 .OR. ( .NOT.SCHURA .AND. LDU.LT.M ) ) THEN\n INFO = -12\n ELSE IF( LDB.LT.MAX( 1, N ) ) THEN\n INFO = -14\n ELSE IF( LDV.LT.1 .OR. ( .NOT.SCHURB .AND. LDV.LT.N ) ) THEN\n INFO = -16\n ELSE IF( LDC.LT.MAX( 1, M ) ) THEN\n INFO = -18\n ELSE\n IF ( NOFACA ) THEN\n IA = 1 + 2*M\n MINWRK = 3*M\n ELSE\n IA = 0\n END IF\n IF ( SCHURA ) THEN\n MINWRK = 0\n ELSE IF ( .NOT.NOFACA ) THEN\n MINWRK = M\n END IF\n IB = 0\n IF ( NOFACB ) THEN\n IB = 2*N\n IF ( .NOT.NOFACA )\n $ IB = IB + 1\n MINWRK = MAX( MINWRK, IB + 3*N )\n ELSE IF ( .NOT.SCHURB ) THEN\n MINWRK = MAX( MINWRK, N )\n END IF\n IF ( CONT ) THEN\n IF ( .NOT.SCHURA )\n $ MINWRK = MAX( MINWRK, IB + M )\n ELSE\n MINWRK = MAX( MINWRK, IB + 2*M )\n END IF\n MINWRK = MAX( 1, IA + MINWRK )\n IF( LDWORK.LT.MINWRK )\n $ INFO = -21\n END IF\nC\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'SB04PD', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF( M.EQ.0 .OR. N.EQ.0 ) THEN\n SCALE = ONE\n DWORK( 1 ) = ONE\n RETURN\n END IF\n MAXWRK = MINWRK\nC\n IF( NOFACA ) THEN\nC\nC Compute the Schur factorization of A.\nC Workspace: need 1+5*M;\nC prefer larger.\nC (Note: Comments in the code beginning \"Workspace:\" describe the\nC minimal amount of real workspace needed at that point in the\nC code, as well as the preferred amount for good performance.\nC NB refers to the optimal block size for the immediately\nC following subroutine, as returned by ILAENV.)\nC\n JWORK = 2*M + 2\n IA = JWORK\n AVAILW = LDWORK - JWORK + 1\n CALL DGEES( 'Vectors', 'Not ordered', SELECT, M, A, LDA, SDIM,\n $ DWORK( 2 ), DWORK( M+2 ), U, LDU, DWORK( JWORK ),\n $ AVAILW, BWORK, IERR )\n IF( IERR.GT.0 ) THEN\n INFO = IERR\n RETURN\n END IF\n MAXWRK = MAX( MAXWRK, INT( DWORK( JWORK ) ) + JWORK - 1 )\n ELSE\n JWORK = 1\n IA = 2\n AVAILW = LDWORK\n END IF\nC\n IF( .NOT.SCHURA ) THEN\nC\nC Transform the right-hand side: C <-- U'*C.\nC Workspace: need a+M,\nC prefer a+M*N,\nC where a = 1+2*M, if FACTA = 'N',\nC a = 0, if FACTA <> 'N'.\nC\n CHUNKA = AVAILW / M\n BLOCKA = MIN( CHUNKA, N ).GT.1\n BLAS3A = CHUNKA.GE.N .AND. BLOCKA\nC\n IF ( BLAS3A ) THEN\nC\nC Enough workspace for a fast BLAS 3 algorithm.\nC\n CALL DLACPY( 'Full', M, N, C, LDC, DWORK( JWORK ), M )\n CALL DGEMM( 'Transpose', 'NoTranspose', M, N, M, ONE,\n $ U, LDU, DWORK( JWORK ), M, ZERO, C, LDC )\n ELSE IF ( BLOCKA ) THEN\nC\nC Use as many columns of C as possible.\nC\n DO 10 J = 1, N, CHUNKA\n BL = MIN( N-J+1, CHUNKA )\n CALL DLACPY( 'Full', M, BL, C( 1, J ), LDC,\n $ DWORK( JWORK ), M )\n CALL DGEMM( 'Transpose', 'NoTranspose', M, BL, M, ONE,\n $ U, LDU, DWORK( JWORK ), M, ZERO, C( 1, J ),\n $ LDC )\n 10 CONTINUE\nC\n ELSE\nC\nC Use a BLAS 2 algorithm.\nC\n DO 20 J = 1, N\n CALL DCOPY( M, C( 1, J ), 1, DWORK( JWORK ), 1 )\n CALL DGEMV( 'Transpose', M, M, ONE, U, LDU,\n $ DWORK( JWORK ), 1, ZERO, C( 1, J ), 1 )\n 20 CONTINUE\nC\n END IF\n MAXWRK = MAX( MAXWRK, JWORK + M*N - 1 )\n END IF\nC\n IF( NOFACB ) THEN\nC\nC Compute the Schur factorization of B.\nC Workspace: need 1+MAX(a-1,0)+5*N,\nC prefer larger.\nC\n JWORK = IA + 2*N\n AVAILW = LDWORK - JWORK + 1\n CALL DGEES( 'Vectors', 'Not ordered', SELECT, N, B, LDB, SDIM,\n $ DWORK( IA ), DWORK( N+IA ), V, LDV, DWORK( JWORK ),\n $ AVAILW, BWORK, IERR )\n IF( IERR.GT.0 ) THEN\n INFO = IERR + M\n RETURN\n END IF\n MAXWRK = MAX( MAXWRK, INT( DWORK( JWORK ) ) + JWORK - 1 )\nC\n IF( .NOT.SCHURA ) THEN\nC\nC Recompute the blocking parameters.\nC\n CHUNKA = AVAILW / M\n BLOCKA = MIN( CHUNKA, N ).GT.1\n BLAS3A = CHUNKA.GE.N .AND. BLOCKA\n END IF\n END IF\nC\n IF( .NOT.SCHURB ) THEN\nC\nC Transform the right-hand side: C <-- C*V.\nC Workspace: need a+b+N,\nC prefer a+b+M*N,\nC where b = 2*N, if FACTB = 'N', FACTA = 'N',\nC b = 1+2*N, if FACTB = 'N', FACTA <> 'N',\nC b = 0, if FACTB <> 'N'.\nC\n CHUNKB = AVAILW / N\n BLOCKB = MIN( CHUNKB, M ).GT.1\n BLAS3B = CHUNKB.GE.M .AND. BLOCKB\nC\n IF ( BLAS3B ) THEN\nC\nC Enough workspace for a fast BLAS 3 algorithm.\nC\n CALL DLACPY( 'Full', M, N, C, LDC, DWORK( JWORK ), M )\n CALL DGEMM( 'NoTranspose', 'NoTranspose', M, N, N, ONE,\n $ DWORK( JWORK ), M, V, LDV, ZERO, C, LDC )\n ELSE IF ( BLOCKB ) THEN\nC\nC Use as many rows of C as possible.\nC\n DO 30 I = 1, M, CHUNKB\n BL = MIN( M-I+1, CHUNKB )\n CALL DLACPY( 'Full', BL, N, C( I, 1 ), LDC,\n $ DWORK( JWORK ), BL )\n CALL DGEMM( 'NoTranspose', 'NoTranspose', BL, N, N, ONE,\n $ DWORK( JWORK ), BL, V, LDV, ZERO, C( I, 1 ),\n $ LDC )\n 30 CONTINUE\nC\n ELSE\nC\nC Use a BLAS 2 algorithm.\nC\n DO 40 I = 1, M\n CALL DCOPY( N, C( I, 1 ), LDC, DWORK( JWORK ), 1 )\n CALL DGEMV( 'Transpose', N, N, ONE, V, LDV,\n $ DWORK( JWORK ), 1, ZERO, C( I, 1 ), LDC )\n 40 CONTINUE\nC\n END IF\n MAXWRK = MAX( MAXWRK, JWORK + M*N - 1 )\n END IF\nC\nC Solve the (transformed) equation.\nC Workspace for DICO = 'D': a+b+2*M.\nC\n IF ( CONT ) THEN\n CALL DTRSYL( TRANA, TRANB, ISGN, M, N, A, LDA, B, LDB, C, LDC,\n $ SCALE, IERR )\n ELSE\n CALL SB04PY( TRANA, TRANB, ISGN, M, N, A, LDA, B, LDB, C, LDC,\n $ SCALE, DWORK( JWORK ), IERR )\n MAXWRK = MAX( MAXWRK, JWORK + 2*M - 1 )\n END IF\n IF( IERR.GT.0 )\n $ INFO = M + N + 1\nC\nC Transform back the solution, if needed.\nC\n IF( .NOT.SCHURA ) THEN\nC\nC Transform the right-hand side: C <-- U*C.\nC Workspace: need a+b+M;\nC prefer a+b+M*N.\nC\n IF ( BLAS3A ) THEN\nC\nC Enough workspace for a fast BLAS 3 algorithm.\nC\n CALL DLACPY( 'Full', M, N, C, LDC, DWORK( JWORK ), M )\n CALL DGEMM( 'NoTranspose', 'NoTranspose', M, N, M, ONE,\n $ U, LDU, DWORK( JWORK ), M, ZERO, C, LDC )\n ELSE IF ( BLOCKA ) THEN\nC\nC Use as many columns of C as possible.\nC\n DO 50 J = 1, N, CHUNKA\n BL = MIN( N-J+1, CHUNKA )\n CALL DLACPY( 'Full', M, BL, C( 1, J ), LDC,\n $ DWORK( JWORK ), M )\n CALL DGEMM( 'NoTranspose', 'NoTranspose', M, BL, M, ONE,\n $ U, LDU, DWORK( JWORK ), M, ZERO, C( 1, J ),\n $ LDC )\n 50 CONTINUE\nC\n ELSE\nC\nC Use a BLAS 2 algorithm.\nC\n DO 60 J = 1, N\n CALL DCOPY( M, C( 1, J ), 1, DWORK( JWORK ), 1 )\n CALL DGEMV( 'NoTranspose', M, M, ONE, U, LDU,\n $ DWORK( JWORK ), 1, ZERO, C( 1, J ), 1 )\n 60 CONTINUE\nC\n END IF\n END IF\nC\n IF( .NOT.SCHURB ) THEN\nC\nC Transform the right-hand side: C <-- C*V'.\nC Workspace: need a+b+N;\nC prefer a+b+M*N.\nC\n IF ( BLAS3B ) THEN\nC\nC Enough workspace for a fast BLAS 3 algorithm.\nC\n CALL DLACPY( 'Full', M, N, C, LDC, DWORK( JWORK ), M )\n CALL DGEMM( 'NoTranspose', 'Transpose', M, N, N, ONE,\n $ DWORK( JWORK ), M, V, LDV, ZERO, C, LDC )\n ELSE IF ( BLOCKB ) THEN\nC\nC Use as many rows of C as possible.\nC\n DO 70 I = 1, M, CHUNKB\n BL = MIN( M-I+1, CHUNKB )\n CALL DLACPY( 'Full', BL, N, C( I, 1 ), LDC,\n $ DWORK( JWORK ), BL )\n CALL DGEMM( 'NoTranspose', 'Transpose', BL, N, N, ONE,\n $ DWORK( JWORK ), BL, V, LDV, ZERO, C( I, 1 ),\n $ LDC )\n 70 CONTINUE\nC\n ELSE\nC\nC Use a BLAS 2 algorithm.\nC\n DO 80 I = 1, M\n CALL DCOPY( N, C( I, 1 ), LDC, DWORK( JWORK ), 1 )\n CALL DGEMV( 'NoTranspose', N, N, ONE, V, LDV,\n $ DWORK( JWORK ), 1, ZERO, C( I, 1 ), LDC )\n 80 CONTINUE\nC\n END IF\n END IF\nC\n DWORK( 1 ) = DBLE( MAXWRK )\nC\n RETURN\nC *** Last line of SB04PD ***\n END\n", "meta": {"hexsha": "cd950be31dfdc15dfbc7762921b957f2483e1da1", "size": 24658, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/SB04PD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/SB04PD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/SB04PD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 37.4172989378, "max_line_length": 72, "alphanum_fraction": 0.5017438559, "num_tokens": 7629, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9184802373309982, "lm_q2_score": 0.7461389817407016, "lm_q1q2_score": 0.6853139090311089}} {"text": "! { dg-do compile }\n! { dg-options \"-O2 -fpeel-loops -finline-functions -fipa-cp-clone -fdump-ipa-inline-details\" }\n\nmodule TensorProducts\n use, intrinsic :: iso_fortran_env\n\n implicit none\n\n integer, parameter :: dp = real64 ! KIND for double precision\n\n type Vect3D\n real(dp) :: x, y, z\n end type\n\ncontains\n\n type(Vect3D) pure function MySum(array)\n type(Vect3D), intent(in) :: array(:,:)\n\n mysum = Vect3D(sum(array%x), sum(array%y), sum(array%z))\n end function\n\n pure subroutine GenerateGrid(N, M, width, height, centre, P)\n integer, intent(in) :: N, M\n real(dp), intent(in) :: width, height\n type(Vect3D), intent(in) :: centre\n type(Vect3D), intent(out) :: P(N, M)\n real(dp) :: x(N), y(M)\n integer :: i, j\n\n x = ([( i, i = 0, N-1 )] * width/(N-1)) - (width / 2) + centre%x\n y = ([( j, j = 0, M-1 )] * height/(M-1)) - (height / 2) + centre%y\n do concurrent (i = 1:N)\n do concurrent (j = 1:M)\n P(i, j) = Vect3D(x(i), y(j), centre%z)\n end do\n end do\n P(2:3,2:3)%z = P(2:3,2:3)%z + 1.0_dp*reshape([2,1,1,-2], [2,2])\n end subroutine\n\n type(Vect3D) pure function TP_SUM(NU, D, NV) result(tensorproduct)\n ! (NU) D (NV)^T, row * matrix * column\n ! TODO (#6): TensorProduct: Investigate whether using DO loops triggers a temporary array.\n ! copied from Surfaces\n real(dp), intent(in) :: NU(4), NV(4)\n type(Vect3D), intent(in) :: D(4,4)\n integer :: i, j\n type(Vect3D) :: P(4,4)\n\n do concurrent (i = 1:4)\n do concurrent (j = 1:4)\n P(i,j)%x = NU(i) * D(i,j)%x * NV(j)\n P(i,j)%y = NU(i) * D(i,j)%y * NV(j)\n P(i,j)%z = NU(i) * D(i,j)%z * NV(j)\n end do\n end do\n tensorproduct = MySum(P)\n end function\n\n subroutine RandomSeed()\n integer :: seed_size, clock, i\n integer, allocatable, save :: seed(:)\n\n if (.not. allocated(seed)) then\n call random_seed(size=seed_size)\n allocate(seed(seed_size))\n call system_clock(count=clock)\n seed = clock + 37 * [( i -1, i = 1, seed_size )]\n call random_seed(put=seed)\n end if\n end subroutine\n\n subroutine RunTPTests()\n type(Vect3D) :: tp, P(4,4)\n integer, parameter :: i_max = 10000000\n real(dp) :: NU(4,i_max), NV(4,i_max)\n real(dp) :: sum\n real :: t(2)\n integer :: i\n\n! print *, 'This code variant uses explicit %x, %y and %z to represent the contents of Type(Vect3D).'\n call GenerateGrid(4, 4, 20.0_dp, 20.0_dp, Vect3D(0.0_dp,0.0_dp,20.0_dp), P)\n call RandomSeed()\n! call cpu_time(t(1))\n do i = 1, 4\n call random_number(NU(i,:))\n call random_number(NV(i,:))\n end do\n! call cpu_time(t(2))\n! print *, 'Random Numbers, time: ', t(2)-t(1)\n sum = 0.0\n call cpu_time(t(1))\n do i = 1, i_max\n tp = TP_SUM(NU(:,i), P(1:4,1:4), NV(:,i))\n sum = sum + tp%x\n end do\n call cpu_time(t(2))\n print *, 'Using SUM, time: ', t(2)-t(1)\n print *, 'sum =', sum\n end subroutine\n\n end module\n\n program Main\n use TensorProducts\n\n implicit none\n\n call RunTPTests()\n end program\n\n! { dg-final { scan-ipa-dump \"Inlined tp_sum into runtptests\" \"inline\" } }\n", "meta": {"hexsha": "eee43fb24977ff2c64e9cce3e5b207339134732f", "size": 3298, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/pr79966.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/pr79966.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/pr79966.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": 29.185840708, "max_line_length": 104, "alphanum_fraction": 0.5442692541, "num_tokens": 1115, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706734, "lm_q2_score": 0.8289388146603364, "lm_q1q2_score": 0.6852934946426641}} {"text": "!\n! Example from ORNL OpenACC tutorial\n!\n! https://www.olcf.ornl.gov/tutorials/openacc-vector-addition/#vecaddf90\n!\n\nprogram main\n\n ! Size of vectors\n integer :: n = 100000\n\n ! Input vectors\n real(8),dimension(:),allocatable :: a\n real(8),dimension(:),allocatable :: b\n ! Output vector\n real(8),dimension(:),allocatable :: c\n\n integer :: i\n real(8) :: sum\n\n ! Allocate memory for each vector\n allocate(a(n))\n allocate(b(n))\n allocate(c(n))\n\n ! Initialize content of input vectors, vector a[i] = sin(i)^2 vector b[i] = cos(i)^2\n do i=1,n\n a(i) = sin(i*1D0)*sin(i*1D0)\n b(i) = cos(i*1D0)*cos(i*1D0)\n enddo\n\n ! Sum component wise and save result into vector c\n\n !$acc kernels copyin(a(1:n),b(1:n)), copyout(c(1:n))\n do i=1,n\n c(i) = a(i) + b(i)\n enddo\n !$acc end kernels\n\n ! Sum up vector c and print result divided by n, this should equal 1 within error\n do i=1,n\n sum = sum + c(i)\n enddo\n sum = sum/n\n print *, 'final result: ', sum\n\n ! Release memory\n deallocate(a)\n deallocate(b)\n deallocate(c)\n\nend program main\n", "meta": {"hexsha": "9ed253bb72f0de15c9d8bb406aaad5821d608298", "size": 1063, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "cscs-checks/prgenv/src/vecAdd_openacc.f90", "max_stars_repo_name": "mboisson/reframe", "max_stars_repo_head_hexsha": "ebf0141596f19c7df60b59d8ad6211067f55b5e5", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 167, "max_stars_repo_stars_event_min_datetime": "2017-11-14T20:37:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T11:19:18.000Z", "max_issues_repo_path": "cscs-checks/prgenv/src/vecAdd_openacc.f90", "max_issues_repo_name": "mboisson/reframe", "max_issues_repo_head_hexsha": "ebf0141596f19c7df60b59d8ad6211067f55b5e5", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2190, "max_issues_repo_issues_event_min_datetime": "2017-06-14T12:48:13.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:09:51.000Z", "max_forks_repo_path": "cscs-checks/prgenv/src/vecAdd_openacc.f90", "max_forks_repo_name": "mboisson/reframe", "max_forks_repo_head_hexsha": "ebf0141596f19c7df60b59d8ad6211067f55b5e5", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 83, "max_forks_repo_forks_event_min_datetime": "2017-05-29T19:12:16.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T09:49:21.000Z", "avg_line_length": 20.0566037736, "max_line_length": 86, "alphanum_fraction": 0.6284101599, "num_tokens": 360, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117855317473, "lm_q2_score": 0.8289387998695209, "lm_q1q2_score": 0.6852934753366754}} {"text": "!**********************************************************************\n! twod.f90 - a solution to the Poisson problem by using Jacobi\n! interation on a 2-d decomposition\n!\n! .... the rest of this is from pi3.f to show the style ...\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!\n! This code is included (without the prints) because one version of\n! MPICH SEGV'ed (probably because of errors in handling send/recv of\n! MPI_PROC_NULL source/destination).\n!\n!****************************************************************************\n program main\n use mpi\n integer maxn\n parameter (maxn = 128)\n double precision a(maxn,maxn), b(maxn,maxn), f(maxn,maxn)\n integer nx, ny\n integer myid, numprocs, it, rc, comm2d, ierr, stride\n integer nbrleft, nbrright, nbrtop, nbrbottom\n integer sx, ex, sy, ey\n integer dims(2)\n logical periods(2)\n double precision diff2d, diffnorm, dwork\n double precision t1, t2\n external diff2d\n data periods/2*.false./\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 if (myid .eq. 0) then\n!\n! Get the size of the problem\n!\n! print *, 'Enter nx'\n! read *, nx\n nx = 10\n endif\n! print *, 'About to do bcast on ', myid\n call MPI_BCAST(nx,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)\n ny = nx\n!\n! Get a new communicator for a decomposition of the domain. Let MPI\n! find a \"good\" decomposition\n!\n dims(1) = 0\n dims(2) = 0\n call MPI_DIMS_CREATE( numprocs, 2, dims, ierr )\n call MPI_CART_CREATE( MPI_COMM_WORLD, 2, dims, periods, .true., &\n comm2d, ierr )\n!\n! Get my position in this communicator\n!\n call MPI_COMM_RANK( comm2d, myid, ierr )\n! print *, \"Process \", myid, \" of \", numprocs, \" is alive\"\n!\n! My neighbors are now +/- 1 with my rank. Handle the case of the\n! boundaries by using MPI_PROCNULL.\n call fnd2dnbrs( comm2d, nbrleft, nbrright, nbrtop, nbrbottom )\n! print *, \"Process \", myid, \":\",\n! * nbrleft, nbrright, nbrtop, nbrbottom\n!\n! Compute the decomposition\n!\n call fnd2ddecomp( comm2d, nx, sx, ex, sy, ey )\n! print *, \"Process \", myid, \":\", sx, ex, sy, ey\n!\n! Create a new, \"strided\" datatype for the exchange in the \"non-contiguous\"\n! direction\n!\n call mpi_Type_vector( ey-sy+1, 1, ex-sx+3, &\n MPI_DOUBLE_PRECISION, stride, ierr )\n call mpi_Type_commit( stride, ierr )\n!\n!\n! Initialize the right-hand-side (f) and the initial solution guess (a)\n!\n call twodinit( a, b, f, nx, sx, ex, sy, ey )\n!\n! Actually do the computation. Note the use of a collective operation to\n! check for convergence, and a do-loop to bound the number of iterations.\n!\n call MPI_BARRIER( MPI_COMM_WORLD, ierr )\n t1 = MPI_WTIME()\n do it=1, 100\n\tcall exchng2( b, sx, ex, sy, ey, comm2d, stride, &\n nbrleft, nbrright, nbrtop, nbrbottom )\n\tcall sweep2d( b, f, nx, sx, ex, sy, ey, a )\n\tcall exchng2( a, sx, ex, sy, ey, comm2d, stride, &\n nbrleft, nbrright, nbrtop, nbrbottom )\n\tcall sweep2d( a, f, nx, sx, ex, sy, ey, b )\n\tdwork = diff2d( a, b, nx, sx, ex, sy, ey )\n\tcall MPI_Allreduce( dwork, diffnorm, 1, MPI_DOUBLE_PRECISION, &\n MPI_SUM, comm2d, ierr )\n if (diffnorm .lt. 1.0e-5) exit\n if (myid .eq. 0) print *, 2*it, ' Difference is ', diffnorm\n enddo\n t2 = MPI_WTIME()\n if (myid .eq. 0 .and. it .gt. 100) print *, 'Failed to converge'\n! if (myid .eq. 0) then\n! print *, 'Converged after ', 2*it, ' Iterations in ', t2 - t1,\n! $ ' secs '\n! endif\n!\n call MPI_Type_free( stride, ierr )\n call MPI_Comm_free( comm2d, ierr )\n call MPI_FINALIZE(rc)\n end\n", "meta": {"hexsha": "ceafa67717828133abbff5dc77686c2b4f3a572c", "size": 4432, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/mpi/Using_MPI/intermediate/twod.f90", "max_stars_repo_name": "Fulayjan/ams250", "max_stars_repo_head_hexsha": "e72ab59a5f924728e69b46e2974914a2d3cab4c1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2018-05-01T20:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-06T18:43:27.000Z", "max_issues_repo_path": "examples/mpi/Using_MPI/intermediate/twod.f90", "max_issues_repo_name": "Fulayjan/ams250", "max_issues_repo_head_hexsha": "e72ab59a5f924728e69b46e2974914a2d3cab4c1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-05-01T04:06:01.000Z", "max_issues_repo_issues_event_max_datetime": "2018-05-01T04:06:01.000Z", "max_forks_repo_path": "examples/mpi/Using_MPI/intermediate/twod.f90", "max_forks_repo_name": "shawfdong/ams250", "max_forks_repo_head_hexsha": "e72ab59a5f924728e69b46e2974914a2d3cab4c1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-06-03T22:37:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-07T01:52:07.000Z", "avg_line_length": 35.1746031746, "max_line_length": 77, "alphanum_fraction": 0.5834837545, "num_tokens": 1291, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511543206819, "lm_q2_score": 0.8006920116079209, "lm_q1q2_score": 0.685273182389988}} {"text": " subroutine advance(u, u_n, u_nm1, f, Cx2, Cy2, dt2, Nx, Ny)\n integer Nx, Ny\n real*8 u(0:Nx,0:Ny), u_n(0:Nx,0:Ny), u_nm1(0:Nx,0:Ny)\n real*8 f(0:Nx,0:Ny), Cx2, Cy2, dt2\n integer i, j\n real*8 u_xx, u_yy\nCf2py intent(in, out) u\n\nC Scheme at interior points\n do j = 1, Ny-1\n do i = 1, Nx-1\n u_xx = u_n(i-1,j) - 2*u_n(i,j) + u_n(i+1,j)\n u_yy = u_n(i,j-1) - 2*u_n(i,j) + u_n(i,j+1)\n u(i,j) = 2*u_n(i,j) - u_nm1(i,j) + Cx2*u_xx + Cy2*u_yy +\n & dt2*f(i,j)\n end do\n end do\n\nC Boundary conditions\n j = 0\n do i = 0, Nx\n u(i,j) = 0\n end do\n j = Ny\n do i = 0, Nx\n u(i,j) = 0\n end do\n i = 0\n do j = 0, Ny\n u(i,j) = 0\n end do\n i = Nx\n do j = 0, Ny\n u(i,j) = 0\n end do\n return\n end\n", "meta": {"hexsha": "eca59958b78def3002f3d2fbd06dd8c6314a7a7d", "size": 883, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "fdm-devito-notebooks/C_softeng2/src-softeng2/wave2D_u0_loop_f77.f", "max_stars_repo_name": "devitocodes/devito_book", "max_stars_repo_head_hexsha": "30405c3d440a1f89df69594fd0704f69650c1ded", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-07-17T13:19:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-27T05:21:09.000Z", "max_issues_repo_path": "fdm-devito-notebooks/C_softeng2/src-softeng2/wave2D_u0_loop_f77.f", "max_issues_repo_name": "devitocodes/devito_book", "max_issues_repo_head_hexsha": "30405c3d440a1f89df69594fd0704f69650c1ded", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 73, "max_issues_repo_issues_event_min_datetime": "2020-07-14T15:38:52.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-25T11:54:59.000Z", "max_forks_repo_path": "fdm-devito-notebooks/C_softeng2/src-softeng2/wave2D_u0_loop_f77.f", "max_forks_repo_name": "devitocodes/devito_book", "max_forks_repo_head_hexsha": "30405c3d440a1f89df69594fd0704f69650c1ded", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-03-27T05:21:14.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-27T05:21:14.000Z", "avg_line_length": 23.2368421053, "max_line_length": 68, "alphanum_fraction": 0.4167610419, "num_tokens": 378, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308165850443, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6852497948952847}} {"text": "c\nc a subroutine for testing all scalar analysis and synthesis subroutines\nc\n program tsha\nc\nc set dimensions with parameter statements\nc\n parameter(nnlat= 15,nnlon= 18, nnt = 3)\nc parameter(nnlat=14,nnlon=20,nnt=3)\n parameter (lleng= 5*nnlat*nnlat*nnlon,llsav= 5*nnlat*nnlat*nnlon)\n parameter (lldwork = nnlat*(nnlat+4))\n double precision dwork(lldwork)\n dimension work(lleng),wsave(llsav)\n dimension a(nnlat,nnlat,nnt),b(nnlat,nnlat,nnt),s(nnlat,nnlon,nnt)\n dimension thetag(nnlat),dtheta(nnlat),dwts(nnlat)\n double precision dtheta, dwts\nc\nc set dimension variables\nc\n nlat = nnlat\n nlon = nnlon\n lwork = lleng\n lsave = llsav\n nt = nnt\n call iout(nlat,4hnlat)\n call iout(nlon,4hnlon)\n call iout(nt,4h nt)\n isym = 0\nc\nc set equally spaced colatitude and longitude increments\nc\n pi = 4.0*atan(1.0)\n dphi = (pi+pi)/nlon\n dlat = pi/(nlat-1)\nc\nc compute nlat gaussian points in thetag\nc\n ldwork = lldwork\n call gaqd(nlat,dtheta,dwts,dwork,ldwork,ier)\n do i=1,nlat\n\tthetag(i) = dtheta(i)\n end do\n call name(4hgaqd)\n call iout(ier,4h ier)\n call vecout(thetag,4hthtg,nlat)\nc\nc test all analysis and synthesis subroutines\nc\n do icase=1,4\nc\nc icase=1 test shaec,shsec\nc icase=2 test shaes,shses\nc icase=3 test shagc,shsgc\nc icase=4 test shags,shsgs\nc\n call name(4h****)\n call name(4h****)\n call iout(icase,4hicas)\nc\nc\nc set scalar field as (x*y*z)**k) restricted to the sphere\nc\n do k=1,nt\n\tdo j=1,nlon\n\t phi = (j-1)*dphi\n\t sinp = sin(phi)\n\t cosp = cos(phi)\n\t do i=1,nlat\n\t theta = (i-1)*dlat\n\t if (icase.gt.2) theta=thetag(i)\n\t cost = cos(theta)\n\t sint = sin(theta)\n\t xyzk = (sint*(sint*cost*sinp*cosp))**k\nc s(i,j,k) = exp(xyzk)\n\t s(i,j,k) = xyzk\n\t end do\n\tend do\nc call iout(k,4h k)\nc call aout(s(1,1,k),4h s,nlat,nlon)\n end do\n\n do l=1,lsave\n\twsave(l) = 0.0\n end do\n if (icase.eq.1) then\n\n call name(4h**ec)\n call shaeci(nlat,nlon,wsave,lsave,dwork,ldwork,ierror)\n\n call name(4hshai)\n call iout(ierror,4hierr)\n\n call shaec(nlat,nlon,isym,nt,s,nlat,nlon,a,b,nlat,nlat,wsave,\n +lsave,work,lwork,ierror)\n\n call name(4hsha )\n call iout(ierror,4hierr)\n\n call shseci(nlat,nlon,wsave,lsave,dwork,ldwork,ierror)\n\n call name(4hshsi)\n call iout(ierror,4hierr)\n\n call shsec(nlat,nlon,isym,nt,s,nlat,nlon,a,b,nlat,nlat,wsave,\n +lsave,work,lwork,ierror)\n\n call name(4hshs )\n call iout(ierror,4hierr)\n\n else if (icase.eq.2) then\n\n call name(4h**es)\n call shaesi(nlat,nlon,wsave,lsave,work,lwork,dwork,ldwork,ierror)\n\n call name(4hshai)\n call iout(ierror,4hierr)\n\n call shaes(nlat,nlon,isym,nt,s,nlat,nlon,a,b,nlat,nlat,wsave,\n +lsave,work,lwork,ierror)\n\n call name(4hsha )\n call iout(ierror,4hierr)\n\n call shsesi(nlat,nlon,wsave,lsave,work,lwork,dwork,ldwork,ierror)\n\n call name(4hshsi)\n call iout(ierror,4hierr)\n\n call shses(nlat,nlon,isym,nt,s,nlat,nlon,a,b,nlat,nlat,wsave,\n +lsave,work,lwork,ierror)\n\n call name(4hshs )\n call iout(ierror,4hierr)\n\n else if (icase.eq.3) then\n\n call name(4h**gc)\n\n call shagci(nlat,nlon,wsave,lsave,dwork,ldwork,ierror)\n\n call name(4hshai)\n call iout(ierror,4hierr)\n\n call shagc(nlat,nlon,isym,nt,s,nlat,nlon,a,b,nlat,nlat,wsave,\n +lsave,work,lwork,ierror)\n\n call name(4hsha )\n call iout(ierror,4hierr)\n\n call shsgci(nlat,nlon,wsave,lsave,dwork,ldwork,ierror)\n\n call name(4hshsi)\n call iout(ierror,4hierr)\n\n call shsgc(nlat,nlon,isym,nt,s,nlat,nlon,a,b,nlat,nlat,wsave,\n +lsave,work,lwork,ierror)\n\n call name(4hshs )\n call iout(ierror,4hierr)\n\n else if (icase.eq.4) then\n\n call name(4h**gs)\n\n call shagsi(nlat,nlon,wsave,lsave,work,lwork,dwork,ldwork,ierror)\n\n call name(4hshai)\n call iout(ierror,4hierr)\n\n call shags(nlat,nlon,isym,nt,s,nlat,nlon,a,b,nlat,nlat,wsave,\n +lsave,work,lwork,ierror)\n\n call name(4hsha )\n call iout(ierror,4hierr)\n\n call shsgsi(nlat,nlon,wsave,lsave,work,lwork,dwork,ldwork,ierror)\n call name(4hshsi)\n call iout(ierror,4hierr)\n\n call shsgs(nlat,nlon,isym,nt,s,nlat,nlon,a,b,nlat,nlat,wsave,\n +lsave,work,lwork,ierror)\n\n call name(4hshs )\n call iout(ierror,4hierr)\n end if\nc\nc compute \"error\" in s\nc\n err2 = 0.0\n do k=1,nt\n\tdo j=1,nlon\n\t phi = (j-1)*dphi\n\t sinp = sin(phi)\n\t cosp = cos(phi)\n\t do i=1,nlat\n\t theta = (i-1)*dlat\n\t if (icase.gt.2) theta = thetag(i)\n\t cost = cos(theta)\n\t sint = sin(theta)\n\t xyzk = (sint*(sint*cost*sinp*cosp))**k\nc err2 = err2+ (exp(xyzk)-s(i,j,k))**2\n\t err2 = err2 + (xyzk-s(i,j,k))**2\n\t end do\n\tend do\nc call iout(k,4h k)\nc call aout(s(1,1,k),4h s,nlat,nlon)\n end do\n err2 = sqrt(err2/(nt*nlat*nlon))\n call vout(err2,4herr2)\n end do\n end\n subroutine iout(ivar,nam)\n real nam\n write(6,10) nam , ivar\n 10 format(1h a4, 3h = ,i8)\n return\n end\nc\n subroutine vout(var,nam)\n real nam\n write(6,10) nam , var\n 10 format(1h a4,3h = ,e12.5)\n return\n end\nc\n subroutine name(nam)\n real nam\n write(6,100) nam\n 100 format(1h a8)\n return\n end\nc\n subroutine vecout(vec,nam,len)\n dimension vec(len)\n real nam\n write(6,109) nam, (vec(l),l=1,len)\n 109 format(1h a4,/(1h 8e11.4))\n return\n end\n", "meta": {"hexsha": "d9c9dfe89a496da73fe678d4dc6606baeb28a3e3", "size": 5637, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/drivers/tsha.f", "max_stars_repo_name": "jprules321/colas", "max_stars_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/drivers/tsha.f", "max_issues_repo_name": "jprules321/colas", "max_issues_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/drivers/tsha.f", "max_forks_repo_name": "jprules321/colas", "max_forks_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.4875, "max_line_length": 76, "alphanum_fraction": 0.6061734965, "num_tokens": 2097, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308147331957, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6852497935358064}} {"text": " SUBROUTINE FRR1A1 (RZ,CZ,IB,REB,CEB)\r\nC\r\n COMPLEX Z,SUM,ZK,TERM\r\nC\r\n Z = CMPLX(RZ,CZ)\r\n IF (CABS(Z) .LT. .1) GO TO 100\r\n ZK = CMPLX(1.,0.)\r\n N = IB\r\n BF = 1.\r\n BF1 = 0.\r\n SUM = CMPLX(0.,0.)\r\n DO 10 I = 1,N\r\n SUM = SUM + ZK/CMPLX(BF,0.)\r\n ZK = ZK*Z\r\n BF1 = BF1 + 1.\r\n BF = BF*BF1\r\n 10 CONTINUE\r\n ZK = CMPLX(BF,0.)/ZK*(CEXP(Z)-SUM)\r\n REB = REAL(ZK)\r\n CEB = AIMAG(ZK)\r\n RETURN\r\nC\r\n 100 CONTINUE\r\n ZK = Z\r\n DEN = FLOAT(IB) + 1.\r\n SUM = CMPLX(1.,0.)\r\n DO 20 I = 1,30\r\n TERM= ZK/DEN\r\n SUM = SUM + TERM\r\n IF (CABS(TERM) .LT. 1.E-9) GO TO 200\r\n ZK = ZK*Z\r\n DEN = DEN*(FLOAT(IB)+ FLOAT(I+1))\r\n 20 CONTINUE\r\n 200 REB = REAL(SUM)\r\n CEB = AIMAG(SUM)\r\n RETURN\r\n END\r\n", "meta": {"hexsha": "4c7b2d13cd41990177b87625e4830f210defa7e7", "size": 823, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "mis/frr1a1.f", "max_stars_repo_name": "ldallolio/NASTRAN-95", "max_stars_repo_head_hexsha": "6d2c175f5b53ebaec4ba2b5186f7926ef9d0ed47", "max_stars_repo_licenses": ["NASA-1.3"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2016-01-09T14:33:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-18T11:51:42.000Z", "max_issues_repo_path": "mis/frr1a1.f", "max_issues_repo_name": "gassive/NASTRAN95", "max_issues_repo_head_hexsha": "98cb3acaa7990d639360601648498834c7782056", "max_issues_repo_licenses": ["NASA-1.3"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2016-01-17T07:30:19.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-06T19:37:44.000Z", "max_forks_repo_path": "mis/frr1a1.f", "max_forks_repo_name": "gassive/NASTRAN95", "max_forks_repo_head_hexsha": "98cb3acaa7990d639360601648498834c7782056", "max_forks_repo_licenses": ["NASA-1.3"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-04-07T20:51:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T14:16:01.000Z", "avg_line_length": 21.6578947368, "max_line_length": 43, "alphanum_fraction": 0.4289185905, "num_tokens": 359, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308073258009, "lm_q2_score": 0.7341195152660687, "lm_q1q2_score": 0.685249771808432}} {"text": "!Calculate the Gauss integral between a pair of line segments (half the contribution to the writhe)\n!Based on methods by Klenin (2000)\n\nsubroutine gauss_pair(R1, R2, e1, e2, s1, s2, dWr)\n use params, only: dp\n implicit none\n\n real(dp), PARAMETER :: PI = 3.141592654d0 ! Value of pi\n\n real(dp), intent(in) :: R1(3), R2(3) ! PositionS\n real(dp), intent(in) :: e1(3), e2(3) ! segment orientations\n real(dp), intent(in) :: s1, s2 ! segment lenghts\n !Geometric variables\n real(dp) r12(3) ! Relative position vector\n real(dp) beta ! Angle between tangents\n real(dp) cosB\n real(dp) sin2B\n real(dp) e3(3)\n real(dp) a0\n real(dp) a1\n real(dp) a2\n real(dp) a3\n real(dp) b\n !Variables for writhe integral\n real(dp) t1\n real(dp) t2\n real(dp) F1\n real(dp) F2\n real(dp) F3\n real(dp) F4\n\n !Counter variables\n integer I, J\n real(dp), intent(out) :: dWr ! Writhe\n\n r12 = R2 - R1\n dWr = 0.\n\n cosB = doT_PRODUCT(e1, e2)\n B = ACOS(cosB)\n\n sin2B = sin(B)**2.\n e3(1) = e1(2)*e2(3) - e1(3)*e2(2)\n e3(2) = e1(3)*e2(1) - e1(1)*e2(3)\n e3(3) = e1(1)*e2(2) - e1(2)*e2(1)\n\n if (abs(sin2B) .lt. (10.**(-15.))) then\n sin2b = 0.\n endif\n\n a1 = doT_PRODUCT(r12, e2*cosB - e1)/(sin2B)\n a2 = doT_PRODUCT(r12, e2 - e1*cosB)/sin2B\n a0 = doT_PRODUCT(r12, e3)/sin2B\n\n t1 = a1 + s1\n t2 = a2 + s2\n F1 = -ATAN((t1*t2 + (a0**2.)*cosB)/(a0*SQRT((t1**2.+t2**2.-2.*t1*t2*cosB + (a0**2.)*sin2B))))/(4.*PI)\n t1 = a1 + s1\n t2 = a2\n F2 = -ATAN((t1*t2 + (a0**2.)*cosB)/(a0*SQRT((t1**2.+t2**2.-2.*t1*t2*cosB + (a0**2.)*sin2B))))/(4.*PI)\n t1 = a1\n t2 = a2 + s2\n F3 = -ATAN((t1*t2 + (a0**2.)*cosB)/(a0*SQRT((t1**2.+t2**2.-2.*t1*t2*cosB + (a0**2.)*sin2B))))/(4.*PI)\n t1 = a1\n t2 = a2\n F4 = -ATAN((t1*t2 + (a0**2.)*cosB)/(a0*SQRT((t1**2.+t2**2.-2.*t1*t2*cosB + (a0**2.)*sin2B))))/(4.*PI)\n dWr = F1 - F2 - F3 + F4\n\n !Gauss integral = 0 for segments in plane (dWr = NaN)\n if (dWr /= dWr) then\n dWr = 0.\n endif\n !Set dwr = 0 for segments nearly in-plane to avoid errors due to floating point\n if (abs(a0) < 10.**(-12.)) then\n dWr = 0.\n endif\n\n RETURN\nEND subroutine gauss_pair\n\n", "meta": {"hexsha": "ba1b0b06405d079c09bd3e8f12bdc6ea62bf105b", "size": 2200, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "src/mc/gauss_pair.f03", "max_stars_repo_name": "SpakowitzLab/BasicWLC", "max_stars_repo_head_hexsha": "13edbbc8e8cd36a3586571ff4d80880fc89d30e6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-16T01:39:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-16T01:39:18.000Z", "max_issues_repo_path": "src/mc/gauss_pair.f03", "max_issues_repo_name": "riscalab/wlcsim", "max_issues_repo_head_hexsha": "e34877ef6c5dc83c6444380dbe624b371d70faf2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 17, "max_issues_repo_issues_event_min_datetime": "2016-07-08T21:17:40.000Z", "max_issues_repo_issues_event_max_datetime": "2017-01-24T09:05:25.000Z", "max_forks_repo_path": "src/mc/gauss_pair.f03", "max_forks_repo_name": "riscalab/wlcsim", "max_forks_repo_head_hexsha": "e34877ef6c5dc83c6444380dbe624b371d70faf2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2017-02-19T06:28:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-05T22:28:08.000Z", "avg_line_length": 27.1604938272, "max_line_length": 104, "alphanum_fraction": 0.5481818182, "num_tokens": 985, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.933430805473952, "lm_q2_score": 0.7341195152660687, "lm_q1q2_score": 0.6852497704489536}} {"text": "*\n* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.\n* See https://llvm.org/LICENSE.txt for license information.\n* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception\n*\n\n! RUN: %clang -c %S/check.c -o %t1\n! RUN: %flang -c -I%S -lm %s -o %t2\n! RUN: %flang -I%S -lm %t2 %t1 -o %t3 \n! RUN: %t3 | tee %t4 && grep ' 6 tests completed. 6 tests PASSED. 0 tests failed.' %t4\n\n* Intrinsics and generics: trigonometric and hyperbolic functions.\n\n\tprogram p\n\timplicit complex (c), double precision (d), double complex(z)\n\tparameter(n=6)\n\tinteger rslts(n), expect(n), ctoi, dtoi\n\tparameter (d_dr=0.174532925199432957692D-1)\n\tparameter (r_dr=0.174532925199432957692E-1)\n\tparameter (d_rd=0.572957795130823208769D+2)\n\tparameter r_rd=0.572957795130823208769E+2\n\n\tdtoi(d) = d * 1000 + .499\n\tctoi(c) = 1000 * (real(c) + aimag(c))\n\tztoi(z) = 1000 * (real(z) + dimag(z))\n\td_dtor(d) = d_dr*d\n\td_rtod(d) = d_rd*d\n\tr_dtor(r) = r_dr*r\n\tr_rtod(r) = r_rd*r\n\n\tdata x3, xx3 / 2 * 3.0 /, d1, cx / 1.0d0, (1.0,2.0) /\n\tdata zx/(1.0d0,2.0d0)/\n\n\n\trslts(1) = nint(acos(1.0) * 100)\n\trslts(2) = 100 * dacos(.93969 * 1d0) + .2\n\trslts(3) = acos(1.0d0) + x3 + .01\n\trslts(4) = nint(r_dtor(acosd(1.0)) * 100)\n\trslts(5) = 100 * d_dtor(dacosd(.93969 * 1d0)) + .2\n\trslts(6) = d_dtor(acosd(1.0d0)) + x3 + .01\n\n\nc --- check results:\n\n\tcall check(rslts, expect, n)\n\n\tdata expect / 0, 35, 3, 0, 35, 3 /\n\tend\n", "meta": {"hexsha": "43fcbeba7e882875da01ed10c544627ce0613a96", "size": 1398, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "test/f90_correct/acos.f", "max_stars_repo_name": "StarGate01/flang", "max_stars_repo_head_hexsha": "aee79af74cf4d15f1931f123bba1a86d76792781", "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": "test/f90_correct/acos.f", "max_issues_repo_name": "StarGate01/flang", "max_issues_repo_head_hexsha": "aee79af74cf4d15f1931f123bba1a86d76792781", "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": "test/f90_correct/acos.f", "max_forks_repo_name": "StarGate01/flang", "max_forks_repo_head_hexsha": "aee79af74cf4d15f1931f123bba1a86d76792781", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.5306122449, "max_line_length": 88, "alphanum_fraction": 0.6409155937, "num_tokens": 607, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430394931456, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.685245791434997}} {"text": "\n!-------------------------------------------------------------------------------\n!\n!> \\file ArrowSolver.f90\n!> \\brief Solve a system of simultaneous linear equations with a\n!! symmetric arrow matrix.\n!> \\author M.H.A. Piro\n!> \\date September 19, 2012\n!\n!\n! Revisions:\n! ==========\n!\n! Date Programmer Description of change\n! ---- ---------- ---------------------\n! 09/19/2012 M.H.A. Piro Original code\n! 03/20/2013 M.H.A. Piro Allow for multiple rows of the arrow\n! head.\n!\n!\n! Purpose:\n! ========\n!\n!> \\details The purpose of this subroutine is to solve a real system of linear\n!! equations Ax = b where A is an n-by-n symmetric arrow matrix and x and b are\n!! N vectors. An arrow matrix is sparse everywhere except for the diagonal\n!! (i.e., A(i,i) /= 0 except A(n,n) == 0), and the bottom row/extreme right column.\n!! In other words, this matrix resembles the shape of an arrow head. The arrow head\n!! can be represented by a single row/column pair or by multiple rows/columns. This\n!! is defined by m.\n!!\n!! This subroutine effectively performs Gaussian elimination on only the bottom\n!! m rows. Computational expense is further reduced for this specific problem when\n!! performing back subsituation by exploiting the sparsity of the A matrix.\n!! This subroutine returns an error via the INFO variable if an error has been\n!! detected. The possible values for INFO are summarized below:\n!!\n!! INFO Description\n!! ---- -----------\n!! 0 Successful exit.\n!! -1 m is equal to or less than zero.\n!! -2 n is equal to or less than zero.\n!! -3 m is greater than or equal to n.\n!! -10 The system of linear equations contains an inconsistent row.\n!! i The row corresponding to i (where i > 0) in B contains a NAN.\n!!\n!\n!\n!\n! Pertinent variables:\n! ====================\n!\n!> \\param[in] m An integer scalar representing the number of rows\n!! corresponding to the arrow head.\n!> \\param[in] n An integer scalar representing the number of linear\n!! equations.\n!> \\param[in] A A double real array represending the A matrix.\n!> \\param[in,out] B A double real vector (dimension n) representing\n!! the functional vector on input and on output it\n!! represents the solution vector.\n!> \\param[out] INFO An integer scalar indicating a successful exit or\n!! an error.\n!!\n! Local variables:\n! ----------------\n! i, j, k Integer scalars used for indexing.\n! dMultiplier A double real scalar used for calculating the\n! multiplier in Gaussian elimination.\n!\n!-------------------------------------------------------------------------------\n\n\nsubroutine ArrowSolver(m, n, A, B, INFO)\n\n implicit none\n\n integer :: i, j, k\n integer, intent(out) :: INFO\n integer, intent(inout) :: m, n\n real(8) :: dMultiplier\n real(8), dimension(n,n), intent(inout) :: A\n real(8), dimension(n), intent(inout) :: B\n\n\n ! Initialize variables:\n INFO = 0\n\n ! Ensure that input parameters are within bounds:\n if (m <= 0) then\n INFO = -1\n return\n elseif (n <= 0) then\n INFO = -2\n return\n elseif (m >= n) then\n INFO = -3\n return\n end if\n\n ! Loop through number of rows representing the arrow head:\n LOOP_ArrowHead: do k = n - m + 1, n\n\n ! Loop through columns along the diagonal:\n LOOP_Column: do j = 1, k - 1\n\n ! Cycle if the coefficient is zero:\n if (A(k,j) == 0D0) cycle LOOP_Column\n\n ! Compute the multiplier:\n dMultiplier = A(j,j) / A(k,j)\n\n ! Update all columns along row:\n A(k,j) = 0D0\n do i = j + 1, n\n A(k,i) = dMultiplier * A(k,i) - A(j,i)\n end do\n\n ! Update solution vector component:\n B(k) = dMultiplier * B(k) - B(j)\n\n end do LOOP_Column\n\n end do LOOP_ArrowHead\n\n ! Check if the system of equations contains an inconsistent row:\n IF_NULL: if (A(n,n) /= 0D0) then\n\n ! Perform back-step calculation:\n B(n) = B(n) / A(n,n)\n\n ! Loop backwards:\n LOOP_Back: do i = (n - 1), (1), (-1)\n\n ! Reinitialize temporary variable:\n dMultiplier = B(i)\n\n ! Loop along column:\n LOOP_Inner: do j = n, (n - m), (-1)\n ! Exit if the diagonal has been reached:\n if (j <= i) exit LOOP_Inner\n dMultiplier = dMultiplier - A(i,j) * B(j)\n end do LOOP_Inner\n\n ! Update the solution vector component:\n B(i) = dMultiplier / A(i,i)\n\n end do LOOP_Back\n else\n\n ! The system contains an inconsistent row. Return an error:\n INFO = -10\n\n end if IF_NULL\n\n ! Check for a NAN:\n LOOP_NAN: do i = 1, n\n\n if (B(i) /= B(i)) then\n ! A NAN has been detected; report an error corresponding\n ! to the row of the first NAN and reset the solution vector.\n INFO = i\n B = 0D0\n exit LOOP_NAN\n end if\n\n end do LOOP_NAN\n\n return\n\nend subroutine ArrowSolver\n", "meta": {"hexsha": "35f163a8f7ae5867534d35ee01812b97c3b9517a", "size": 5523, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/gem/ArrowSolver.f90", "max_stars_repo_name": "elementx54/thermochimica", "max_stars_repo_head_hexsha": "ea7bb8f64b03d8583d326f737e9699083c304847", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 40, "max_stars_repo_stars_event_min_datetime": "2018-01-24T22:03:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T00:12:33.000Z", "max_issues_repo_path": "src/ArrowSolver.f90", "max_issues_repo_name": "nikolasscuro/thermochimica", "max_issues_repo_head_hexsha": "bafac98198e58b75d160d6af52e335d326b5c423", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 10, "max_issues_repo_issues_event_min_datetime": "2018-11-06T17:00:29.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-17T20:22:06.000Z", "max_forks_repo_path": "src/ArrowSolver.f90", "max_forks_repo_name": "nikolasscuro/thermochimica", "max_forks_repo_head_hexsha": "bafac98198e58b75d160d6af52e335d326b5c423", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 22, "max_forks_repo_forks_event_min_datetime": "2018-02-06T21:25:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-23T15:34:17.000Z", "avg_line_length": 32.298245614, "max_line_length": 84, "alphanum_fraction": 0.5245337679, "num_tokens": 1315, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797172476384, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6852186093892982}} {"text": "! loosely translated from python. We do not need to generate and store the entire vector at once.\n! compilation: gfortran -Wall -std=f2008 -o thisfile thisfile.f08\n\nprogram percolation_mean_run_density\n implicit none\n integer :: i, p10, n2, n, t\n real :: p, limit, sim, delta\n data n,p,t/100,0.5,500/\n write(6,'(a3,a5,4a7)')'t','p','n','p(1-p)','sim','delta%'\n do p10=1,10,2\n p = p10/10.0\n limit = p*(1-p)\n write(6,'()')\n do n2=10,15,2\n n = 2**n2\n sim = 0\n do i=1,t\n sim = sim + mean_run_density(n,p)\n end do\n sim = sim/t\n if (limit /= 0) then\n delta = abs(sim-limit)/limit\n else\n delta = sim\n end if\n delta = delta * 100\n write(6,'(i3,f5.2,i7,2f7.3,f5.1)')t,p,n,limit,sim,delta\n end do\n end do\n\ncontains\n\n integer function runs(n, p)\n integer, intent(in) :: n\n real, intent(in) :: p\n real :: harvest\n logical :: q\n integer :: count, i\n count = 0\n q = .false.\n do i=1,n\n call random_number(harvest)\n if (harvest < p) then\n q = .true.\n else\n if (q) count = count+1\n q = .false.\n end if\n end do\n runs = count\n end function runs\n\n real function mean_run_density(n, p)\n integer, intent(in) :: n\n real, intent(in) :: p\n mean_run_density = real(runs(n,p))/real(n)\n end function mean_run_density\n\nend program percolation_mean_run_density\n", "meta": {"hexsha": "b97ed6ca160b33f9919a4ab0b9d59dc0257af4cb", "size": 1453, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Percolation-Mean-run-density/Fortran/percolation-mean-run-density.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/Percolation-Mean-run-density/Fortran/percolation-mean-run-density.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/Percolation-Mean-run-density/Fortran/percolation-mean-run-density.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 24.2166666667, "max_line_length": 98, "alphanum_fraction": 0.557467309, "num_tokens": 484, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797027760039, "lm_q2_score": 0.7520125848754471, "lm_q1q2_score": 0.6852186035706243}} {"text": " subroutine surface(imsgin,xmsgin,cmsgin,msgtype,nwds,ierror)\nC\nC\nC#######################################################################\nC\nC PURPOSE -\nC\nC THIS ROUTINE DEFINES A BOUNDARY SURFACE OF THE SPECIFIED TYPE.\nC THE SURFACE TYPE IS SPECIFIED BY istype AND DESCRIBED\nC BY x1 to z4.\nC\nC\nC FORMAT: SURFACE/ISURNAME/IBTYPE/ISTYPE/X1/Y1/Z1/X2/Y2/Z2/\nC X3/Y3/Z3/X4/Y4/Z4\nC SPECIFICALLY:\nC SURFACE/ISURNAME/IBTYPE/plane/x1,y1,z1/x2,y2,z2/x3,y3,z3\nC SURFACE/isurname/IBTYPE/PLANEXYZ/x1,y1,z1/x2,y2,z2/x3,y3,z3\nC SURFACE/isurname/IBTYPE/PLANERTZ/radius1,theta1,z1,\nC radius2,theta2,z2,\nC radius3,theta3,z3,\nC xcen,ycen\nC SURFACE/isurname/IBTYPE/PLANERTP/radius1,theta1,phi1,\nC radius2,theta2,phi2,\nC radius3,theta3,phi3,\nC xcen,ycen,zcen\nC SURFACE/ISURNAME/IBTYPE/box/xmin,ymin,zmin/xmax,ymax,zmax\nC SURFACE/ISURNAME/IBTYPE/paralell/x1,y1,z1/x2,y2,z2/x3,y3,z3/\nC x4,y4,z4\nC WHERE POINTS 1, 2, 3 ARE THE FRONT LEFT, FRONT RIGHT\nC AND BACK LEFT POINTS OF THE BASE AND POINT 4 IS\nC THE UPPER LEFT POINT OF THE FRONT FACE.\nC SURFACE/ISURNAME/IBTYPE/sphere/xcen,ycen,zcen/radius\nC SURFACE/ISURNAME/IBTYPE/cylinder/x1,y1,z1/x2,y2,z2/radius\nC WHERE POINT 1 IS THE BOTTOM CENTER AND POINT 2 IS THE TOP\nC CENTER OF THE CYLINDER.\nC SURFACE/ISURNAME/IBTYPE/cone/x1,y1,z1/x2,y2,z2/radius\nC WHERE POINT 1 IS THE VERTEX AND POINT 2 IS THE TOP\nC CENTER OF THE CONE WITH RADIUS FROM THIS POINT.\nC SURFACE/ISURNAME/IBTYPE/ellipse/x1,y1,z1/x2,y2,z2/x3,y3,z3/\nC ar,br,cr\nC WHERE POINT 1 IS THE CENTER OF THE ELLIPSOID, POINT 2 IS\nC ON THE a SEMI-AXIS, POINT 3 IS ON THE b SEMI-AXIS,\nC AND ar, br, cr ARE RADII ALONG THEIR RESPECTIVE\nC SEMI-AXES.\nC SURFACE/ISURNAME/IBTYPE/tabular/x1,y1,z1/x2,y2,z2/igeom\nC r1,z1, r2,z2, r3,z3,....\nC ...., rn,zn, end\nC OR\nC r1,theta1, r2,theta2, r3,theta3,....\nC ...., rn,thetan, end\nC WHERE POINT 1 AND POINT 2 DEFINE THE AXIS OF ROTAION\nC FOR THE TABULAR PROFILE WITH POINT 1 AS THE ORIGIN.\nC THIS IS FOLLOWED BY PAIRS OF PROFILE DESCRIPTORS\nC DEPENDING ON THE VALUE OF igeom. IF igeom IS SET\nC TO rz THEN THE R VALUE IS A RADIUS NORMAL TO THE\nC AXIS OF ROTAION AND Z IS THE DISTANCE ALONG THE\nC REFLECTED BOUNDARY-POINT INFORMATION.\nC NEW AXIS OF ROTATION. IF igeom IS SET TO rt\nC THEN THETA IS THE ANGLE FROM THE AXIS OF ROTATION\nC AT POINT 1 AND R IS THE DISTANCE FROM POINT 1 ALONG\nC THETA. THE FIRST PAIR MUST START ON A NEW LINE AND\nC ALL LINES MUST CONTAIN PAIRS OF DATA. THE LAST PAIR\nC OF DATA MUST BE FOLLOWED BY end.\nC SURFACE/ISURNAME/IBTYPE/sheet/nx/ny\nC x1 y1 z1\nC x2 y2 z2\nC .\nC xn yn zn\nC This format is useful for reading a file that\nC is a set of xyz triplets with the SURFACE command\nC as the first line of the file. The file can be\nC read in with the INPUT / filename command.\nC\nC SURFACE/ISURNAME/IBTYPE/sheet/x1,y1,z1/x2,y2,z2/x3,y3,z3/igeom/\nC nx/ny\nC x1,y1,z1, x2,y2,z2, x3,y3,z3, ...\nC ...., xn,yn,zn, end\nC OR\nC theta1,z1,r1, theta2,z2,r2, theta3,z3,r3, ...\nC ...., thetan,zn,rn, end\nC OR\nC theta1,phi1,r1, theta2,phi2,r2, theta3,phi3,r3, ...\nC ...., thetan,phin,rn, end\nC OR\nC points/ipt1,ipt2,ipt3\nC SHEET SURFACES ARE OPEN SURFACES THAT ARE DEFINED BY A\nC LOGICAL GRID WITH nx*ny GRID POINTS. nx IS THE NUMBER OF\nC ROWS AND ny IS THE NUMBER OF COLUMNS IN THE GRID. ALL\nC DATA IS ENTERED IN ROW-WISE ORDER AND THE TRIPLETS DEF-\nC INING EACH POINT IS OF THE TYPE AND ORDER SET IN igeom.\nC THE ALLOWABLE igeom VALUES ARE 'xyz', 'tzr' and 'tpr'.\nC THE 3 INPUT POINTS (x1 TO z3) DEFINE A NEW COORDINATE\nC SYSTEM. POINT 1 (x1,y1,z1) IS THE NEW ORIGIN, THE LINE\nC BETWEEN POINTS 1 AND 2 IS THE NEW X-AXIS AND POINT 3\nC LIES ON THE NEW XY PLANE. THE NEW Z-AXIS IS NORMAL TO\nC THE NEW XY PLANE.\nC WHEN igeom IS xyz THEN THE Z VALUES ARE MEASURDED FROM\nC THE NEW XY PLANE. THERE CAN ONLY BE ONE Z VALUE\nC PER XY PAIR. ANYTHING BELOW THE SHEET WITHIN\nC THE GRID BOUNDS IS INSIDE THE SURFACE.\nC WHEN igeom IS tzr THEN THE r VALUE IS MEASURED FROM\nC THE NEW Z AXIS, z IS MEASURED FROM THE ORIGIN\nC AND theta IS MEASURED FROM THE NEW XZ PLANE.\nC r VALUES MUST BE POSITIVE AND THERE CAN ONLY BE\nC ONE PER tz PAIR. ANYTHING BETWEEN THE REFERENCE\nC LINE AND THE SHEET IS INSIDE THE SURFACE.\nC WHEN igeom IS tpr THEN THE r VALUE IS MEASURED FROM\nC THE REFERNCE POINT, theta IS MEASURED FROM THE NEW\nC X-AXIS AND phi IS MEASURED FROM THE NEW Z-AXIS.\nC r VALUES MUST BE POSITIVE AND THERE CAN ONLY BE\nC ONE PER tp PAIR. ANYTHING BETWEEN THE REFERENCE\nC POINT AND THE SHEET IS INSIDE THE SURFACE.\nC\nC INPUT ARGUMENTS -\nC\nC imsgin() - Integer array of command input tokens\nC xmsgin() - Real array of command input tokens\nC cmsgin() - Character array of command input tokens\nC msgtype() - Integer array of command input token types\nC nwds - Number of command input tokens\nC\nC THESE ARE CONVERTED TO THE FOLLOWING:\nC\nC isurnam - NAME FOR THIS SURFACE USED AS PATH TO STORAGE BLOCK\nC ibtype - TYPE OF BOUNDARY: FREE, INTRFACE, REFLECT,\nC VIRTUAL OR INTRCONS\nC istype - TYPE OF SURFACE: PLANE, SPHERE, CYLINDER, CONE,\nC BOX, PARALLELpiped\nC x1--z4 - PHYSICAL DESCRIPTION OF THE SURFACE, 4 POINTS\nC FOR A PLANE, CENTER POINT AND RADIUS FOR A SPHERE,\nC MIN. AND MAX. POINTS FOR A BOX, 4 POINTS FOR A\nC PARALLELPIPED, 2 END CENTER POINTS AND RADIUS FOR\nC A CYLINDER, 2 END CENTER POINTS AND 2 RADII FOR A\nC CONE.\nC\nC OUTPUT ARGUMENTS -\nC\nC ierror - Error Return Code (==0 ==> OK, <>0 ==> Error)\nC\nC CHANGE HISTORY -\nC\nC $Log: surface.f,v $\nC Revision 2.00 2007/11/09 20:04:04 spchu\nC Import to CVS\nC\nCPVCS \nCPVCS Rev 1.12 23 Mar 2001 15:02:02 dcg\nCPVCS fix error with cube type - save at correct offset\nCPVCS \nCPVCS Rev 1.11 18 Apr 2000 13:24:34 dcg\nCPVCS implement release option for surfaces, regions and mregions\nCPVCS\nCPVCS Rev 1.10 13 Apr 2000 16:50:16 dcg\nCPVCS add release surface option\nCPVCS\nCPVCS Rev 1.9 Wed Apr 05 16:34:00 2000 dcg\nCPVCS allow 'interface' as well as 'intrface' for surface type\nCPVCS\nCPVCS Rev 1.8 Wed Apr 05 13:35:08 2000 nnc\nCPVCS Minor source modifications required by the Absoft compiler.\nCPVCS\nCPVCS Rev 1.7 20 Mar 2000 13:42:04 dcg\nCPVCS check for duplicate name - if so then print warning and skip command\nCPVCS\nCPVCS Rev 1.6 24 Feb 2000 12:57:22 dcg\nCPVCS use geom_name when increasing mm surface definition block\nCPVCS\nCPVCS Rev 1.5 24 Feb 2000 11:16:36 dcg\nCPVCS use type=3 for character arrays\nCPVCS\nCPVCS Rev 1.4 Wed Feb 02 11:55:44 2000 dcg\nCPVCS\nCPVCS Rev 1.3 13 Jan 2000 14:49:28 dcg\nCPVCS\nCPVCS Rev 1.2 06 Jan 2000 12:55:16 dcg\nCPVCS\nCPVCS Rev 1.35 Wed Nov 10 09:35:08 1999 dcg\nCPVCS remove test on miscellaneous storage block\nCPVCS\nCPVCS Rev 1.34 Fri Sep 03 15:48:16 1999 dcg\nCPVCS tabular surface data read in as part of command\nCPVCS\nCPVCS Rev 1.33 Fri Apr 17 10:09:48 1998 gable\nCPVCS Add some comments about the /sheet/nx/ny option.\nCPVCS\nCPVCS Rev 1.32 Fri Oct 31 10:50:32 1997 dcg\nCPVCS declare ipcmoprm as a pointer\nCPVCS\nCPVCS Rev 1.31 Mon Apr 14 17:02:10 1997 pvcs\nCPVCS No change.\nCPVCS\nCPVCS Rev 1.30 Tue Feb 04 10:45:04 1997 dcg\nCPVCS normalize a,b,c,d representation of plane such that d=+/-1.0\nCPVCS\nCPVCS Rev 1.29 Wed May 29 08:43:24 1996 het\nCPVCS Fix an error when checking input arguments for tabular.\nCPVCS\nCPVCS Rev 1.28 Thu May 23 08:49:26 1996 dcg\nCPVCS use icscode to test for sb existence\nCPVCS\nCPVCS Rev 1.27 Thu May 16 10:28:30 1996 dcg\nCPVCS changes for new interface type 3 and for new icontab, xcontab\nCPVCS\nCPVCS Rev 1.26 11/07/95 17:26:52 dcg\nCPVCS change flag to 2 in mmgetblk calls\nCPVCS\nCPVCS Rev 1.25 10/18/95 17:11:20 het\nCPVCS Fix an error with nstbout\nCPVCS\nCPVCS Rev 1.24 10/18/95 12:17:08 het\nCPVCS Allow greater that 8 character names for sheets in the surface command.\nCPVCS\nCPVCS Rev 1.23 09/19/95 13:09:58 dcg\nCPVCS add primative syntax checking\nCPVCS\nCPVCS Rev 1.22 08/29/95 12:10:56 dcg\nCPVCS set length for names to 40 characters\nCPVCS\nCPVCS Rev 1.21 08/28/95 11:32:04 ahmed\nCPVCS Adjust the location of mmrelprt in the routine\nCPVCS\nCPVCS Rev 1.20 08/25/95 15:39:58 dcg\nCPVCS select 'active' mesh object when finished with sheet\nCPVCS\nCPVCS Rev 1.19 08/23/95 16:05:16 dcg\nCPVCS changes for sheet routines as mesh objects\nCPVCS\nCPVCS Rev 1.18 08/23/95 06:59:04 het\nCPVCS Remove the CMO prefix from SB-ids\nCPVCS\nCPVCS Rev 1.17 08/22/95 06:51:04 het\nCPVCS Split the storage block for CMO variables.\nCPVCS\nCPVCS Rev 1.16 06/13/95 12:34:20 ejl\nCPVCS Fixed error with input\nCPVCS\nCPVCS Rev 1.15 06/13/95 09:02:52 ejl\nCPVCS Cleaned up msgtty, calling arguments.\nCPVCS\nCPVCS\nCPVCS Rev 1.14 06/07/95 15:31:54 het\nCPVCS Change character*32 idsb to character*132 idsb\nCPVCS\nCPVCS Rev 1.13 05/12/95 11:40:22 ejl\nCPVCS Put error checking in SURFACE\nCPVCS\nCPVCS Rev 1.12 05/01/95 08:34:16 het\nCPVCS Modifiy all the storage block calles for long names\nCPVCS\nCPVCS Rev 1.11 03/31/95 09:10:30 het\nCPVCS Add the buildid calles before all storage block calls\nCPVCS\nCPVCS Rev 1.10 03/30/95 05:00:52 het\nCPVCS Change the storage block id packing and preidsb to buildid for long names\nCPVCS\nCPVCS Rev 1.9 03/23/95 15:08:38 dcg\nCPVCS Add mesh object name to storage block id for surface,region info.\nCPVCS\nCPVCS Rev 1.8 02/20/95 15:54:40 ahmed\nCPVCS Double the memory length for 'sheet' to handle NURBS\nCPVCS\nCPVCS Rev 1.6 02/17/95 19:14:16 het\nCPVCS Adjust memory for tri and quad cmo\nCPVCS\nCPVCS Rev 1.5 02/12/95 08:41:00 het\nCPVCS Add the quad_cmo and tri_cmo functions.\nCPVCS\nCPVCS Rev 1.4 01/25/95 16:11:36 dcg\nCPVCS Activate sheet surface type\nCPVCS\nCPVCS Rev 1.3 01/04/95 22:05:34 llt\nCPVCS unicos changes (made by het)\nCPVCS\nCPVCS Rev 1.2 12/24/94 10:52:16 het\nCPVCS Add include files for chydro.h and comdict.h.\nCPVCS\nC\nC\nC#######################################################################\nC\n implicit none\nC\nC#######################################################################\nC\n include 'geom_lg.h'\n include 'chydro.h'\n include 'consts.h'\nC\nC#######################################################################\nC\n integer nwds, imsgin(nwds), msgtype(nwds)\n REAL*8 xmsgin(nwds)\n character*(*) cmsgin(nwds)\nC\n integer ierror,lenigeom,iout,i,istrt,lengthsparam,ntab,iend,\n * ickrfl,lenibtype,lenistype,lenisurfnm,j\n integer icharlnf,length,ierrw,lout,itype,n\n pointer (ipout,out)\n real*8 out(*)\n real*8 ax,cz,bz,az,dist,xc,yc,zc,r,xdiff,ydiff,zdiff,dx,dy,dz,\n * x4,y4,z4,x2,y2,z2,x3,y3,z3,x1,y1,z1,x4in,y4in,z4in,\n * xmax1,ymax1,zmax1,xmx,ymx,zmx,xmin1,ymin1,zmin1,ai,bi,ci,\n * a,b,c,d,distx,disty,aty,bty,denom,numer,angle,\n * cty,theta,thetain,rr,zz,bx,cx,ay,by,cy,xmn,ymn,zmn,\n * absofd,phi1,phi2,phi3,xcen,ycen,zcen,theta3,radius3,theta2,\n * radius2,theta1,radius1,x1in,y1in,z1in,x2in,y2in,z2in,x3in,\n * y3in,z3in\nC\nC#######################################################################\nC\n REAL*8 x(3,6), y(3,6), z(3,6),rout\n \nC\n character*32 isurfnm,geom_name\n character*32 ibtypein, istypein, igeom, cmosheet\n character*32 isubname, cmo\nC\nC\n character*132 logmess\n integer ierr\n real*8 eps\nC\nC#######################################################################\nC\nC\nC\n isubname='surface'\nC\n ierror = 0\nC\nC Get length epsilon\nC\n call get_epsilon('epsilonl',eps)\nC\nC Get mesh object name\nC\n call cmo_get_name(cmo,ierr)\n if(ierr.ne.0) call x3d_error(isubname,'cmo_get_name')\n call cmo_get_attinfo('geom_name',cmo,iout,rout,geom_name,\n * ipout,lout,itype,ierror)\nC\nC ******************************************************************\nC GET NAME AND TYPE INFORMATION\nC\n isurfnm = cmsgin(2)\n ibtypein = cmsgin(3)\n if(ibtypein.eq.'interface') ibtypein='intrface'\n istypein = cmsgin(4)\nC\n lenisurfnm = icharlnf(isurfnm)\n lenibtype = icharlnf(ibtypein)\n lenistype = icharlnf(istypein)\nc\nc make sure we have enough space\nc\n call mmfindbk('csall',geom_name,ipcsall,length,ierror)\n if (ierror.ne.0 ) then\n length=100\n call mmgetblk('csall',geom_name,ipcsall,length,3,ierror)\n call mmgetblk('istype',geom_name,ipistype,length,3,ierror)\n call mmgetblk('ibtype',geom_name,ipibtype,length,3,ierror)\n call mmgetblk('sheetnm',geom_name,ipsheetnm,length,3,ierror)\n call mmgetblk('surfparam',geom_name,ipsurfparam,20*length,\n * 2,ierror)\n call mmgetblk('offsparam',geom_name,ipoffsparam,length,1,\n * ierror)\n elseif(length.lt.nsurf+1) then\n call mmincblk('csall',geom_name,ipcsall,100,ierror)\n call mmincblk('istype',geom_name,ipistype,100,ierror)\n call mmincblk('ibtype',geom_name,ipibtype,100,ierror)\n call mmincblk('sheetnm',geom_name,ipsheetnm,100,ierror)\n call mmincblk('offsparam',geom_name,ipoffsparam,100,ierror)\n else\n call mmfindbk('istype',geom_name,ipistype,length,ierror)\n call mmfindbk('ibtype',geom_name,ipibtype,length,ierror)\n call mmfindbk('sheetnm',geom_name,ipsheetnm,length,ierror)\n call mmfindbk('surfparam',geom_name,ipsurfparam,length,ierror)\n call mmfindbk('offsparam',geom_name,ipoffsparam,length,ierror)\n endif\nc\nc check for release or delete\nc\n if(ibtypein.eq.'release'.or.ibtypein.eq.'delete'.or.\n * ibtypein.eq.'remove') then\n do i=1,nsurf\n if(csall(i).eq.isurfnm) then\n if(ibtype(i).eq.'reflect'.or.ibtype(i).eq.'intrcons')\n * call condel(i)\n if(i.lt.nsurf) then\n length=offsparam(i+1)-offsparam(i)\n do j=offsparam(i),lastsparam-length\n surfparam(j+1)=surfparam(j+length+1)\n enddo\n do j= i+1,nsurf\n offsparam(j)=offsparam(j)-length\n enddo\n do j=i,nsurf-1\n csall(j)=csall(j+1)\n istype(j)=istype(j+1)\n ibtype(j)=ibtype(j+1)\n sheetnm(j)=sheetnm(j+1)\n offsparam(j)=offsparam(j+1)\n enddo\n lastsparam=lastsparam-length\n else\n lastsparam=0\n if(nsurf.gt.1)lastsparam=offsparam(nsurf)\n offsparam(nsurf)=0\n csall(nsurf)=' '\n endif\n nsurf=nsurf-1\n go to 9999\n endif\n enddo\n endif\nC\nC ******************************************************************\nC CHECK FOR VALID BOUNDARY TYPES.\nC\n if ((ibtypein(1:lenibtype) .ne. 'free' ) .and.\n & (ibtypein(1:lenibtype) .ne. 'intrface') .and.\n & (ibtypein(1:lenibtype) .ne. 'intrcons') .and.\n & (ibtypein(1:lenibtype) .ne. 'virtual') .and.\n & (ibtypein(1:lenibtype) .ne. 'reflect' )) then\nC\nC ***************************************************************\nC ILLEGAL BOUNDARY TYPE.\nC\n write(logmess,9000) ibtypein\n 9000 format(' ERROR - Illegal Boundary Type: ', a)\n call writloga('default',0,logmess,0,ierrw)\n go to 9999\nC\n endif\nc\nc check for illegal surface type\nc\n if ((istypein(1:lenistype) .ne. 'plane' ) .and.\n & (istypein(1:lenistype) .ne. 'planexyz') .and.\n & (istypein(1:lenistype) .ne. 'planertz') .and.\n & (istypein(1:lenistype) .ne. 'planertp') .and.\n & (istypein(1:lenistype) .ne. 'box' ) .and.\n & (istypein(1:lenistype) .ne. 'cone' ) .and.\n & (istypein(1:lenistype) .ne. 'cylinder') .and.\n & (istypein(1:lenistype) .ne. 'ellipse') .and.\n & (istypein(1:lenistype) .ne. 'parallel') .and.\n & (istypein(1:lenistype) .ne. 'sphere' ) .and.\n & (istypein(1:lenistype) .ne. 'tabular' ) .and.\n & (istypein(1:lenistype) .ne. 'sheet' )) then\n write(logmess,9120) istypein\n call writloga('default',0,logmess,0,ierrw)\n go to 9999\n endif\nc\nc increment number of surfaces\nc\n nsurf=nsurf+1\n \nc\nc check for duplicate names - if duplicate warn and ignore\nc\n n=nsurf-1\n do i=1,n\n if(csall(i).eq.isurfnm) then\n nsurf=nsurf-1\n write(logmess,'(a,a)') 'duplicate surface - ignored: '\n * ,isurfnm\n call writloga('default',0,logmess,0,ierror)\n go to 9999\n endif\n enddo\nc\nc store names and types and offset\nc\n istype(nsurf)=istypein(1:lenistype)\n ibtype(nsurf)=ibtypein(1:lenibtype)\n csall(nsurf)=isurfnm(1:lenisurfnm)\n if(nsurf.eq.1) lastsparam=0\n offsparam(nsurf)=lastsparam\nc\nc get length of surfparam for later checks\nc\n call mmfindbk('surfparam',geom_name,ipsurfparam,lengthsparam\n * ,ierror)\nC\n ickrfl=0\nC\n if ((istypein(1:lenistype) .eq. 'plane' ) .or.\n & (istypein(1:lenistype) .eq. 'planexyz') .or.\n & (istypein(1:lenistype) .eq. 'planertz') .or.\n & (istypein(1:lenistype) .eq. 'planertp')) then\nC\nC ***************************************************************\nC HANDLE PLANE TYPE SURFACE\nC\n if ((istypein(1:lenistype) .eq. 'plane' ) .or.\n * (istypein(1:lenistype) .eq. 'planexyz')) then\nC\n call test_argument_type(9,2,5,imsgin,xmsgin,cmsgin,\n * msgtype,nwds)\n x1in=xmsgin(5)\n y1in=xmsgin(6)\n z1in=xmsgin(7)\nC\n x2in=xmsgin(8)\n y2in=xmsgin(9)\n z2in=xmsgin(10)\nC\n x3in=xmsgin(11)\n y3in=xmsgin(12)\n z3in=xmsgin(13)\nC\n elseif(istypein(1:lenistype) .eq. 'planertz' ) then\nC\n call test_argument_type(12,2,5,imsgin,xmsgin,cmsgin,\n * msgtype,nwds)\n radius1=xmsgin(5)\n theta1 =xmsgin(6)*pie/180.0\n z1in =xmsgin(7)\nC\n radius2=xmsgin(8)\n theta2 =xmsgin(9)*pie/180.0\n z2in =xmsgin(10)\nC\n radius3=xmsgin(11)\n theta3 =xmsgin(12)*pie/180.0\n z3in =xmsgin(13)\nC\n xcen=xmsgin(14)\n ycen=xmsgin(15)\n zcen=xmsgin(16)\nC\n x1in=radius1*cos(theta1)+xcen\n y1in=radius1*sin(theta1)+ycen\nC\n x2in=radius2*cos(theta2)+xcen\n y2in=radius2*sin(theta2)+ycen\nC\n x3in=radius3*cos(theta3)+xcen\n y3in=radius3*sin(theta3)+ycen\nC\n elseif(istypein(1:lenistype) .eq. 'planertp' ) then\nC\n call test_argument_type(12,2,5,imsgin,xmsgin,cmsgin,\n * msgtype,nwds)\n radius1=xmsgin(5)\n theta1 =xmsgin(6)*pie/180.0\n phi1 =xmsgin(7)*pie/180.0\nC\n radius2=xmsgin(8)\n theta2 =xmsgin(9)*pie/180.0\n phi2 =xmsgin(10)*pie/180.0\nC\n radius3=xmsgin(11)\n theta3 =xmsgin(12)*pie/180.0\n phi3 =xmsgin(13)*pie/180.0\nC\n xcen=xmsgin(14)\n ycen=xmsgin(15)\n zcen=xmsgin(16)\nC\n x1in=radius1*sin(theta1)*cos(phi1)+xcen\n y1in=radius1*sin(theta1)*sin(phi1)+ycen\n z1in=radius1*cos(theta1)+zcen\nC\n x2in=radius2*sin(theta2)*cos(phi2)+xcen\n y2in=radius2*sin(theta2)*sin(phi2)+ycen\n z2in=radius2*cos(theta2)+zcen\nC\n x3in=radius3*sin(theta3)*cos(phi3)+xcen\n y3in=radius3*sin(theta3)*sin(phi3)+ycen\n z3in=radius3*cos(theta3)+zcen\nC\n endif\nC\nC ---------------------------------------------------------------\nC CONVERT INPUT POINTS FROM CURRENT COORDINATE SYSTEM TO\nC NORMAL COORDINATE SYSTEM.\nC\n call xyznorm(x1in,y1in,z1in,x(1,1),y(1,1),z(1,1))\n call xyznorm(x2in,y2in,z2in,x(2,1),y(2,1),z(2,1))\n call xyznorm(x3in,y3in,z3in,x(3,1),y(3,1),z(3,1))\nC\nC ---------------------------------------------------------------\nC SAVE TRANSPOSED INPUT DATA IN surfparam\nC\n if(lengthsparam.lt.offsparam(nsurf)+13) then\n call mmincblk('surfparam',geom_name,ipsurfparam,500,ierr)\n lengthsparam=lengthsparam+500\n endif\n surfparam(offsparam(nsurf)+1)=x(1,1)\n surfparam(offsparam(nsurf)+2)=y(1,1)\n surfparam(offsparam(nsurf)+3)=z(1,1)\nC\n surfparam(offsparam(nsurf)+4)=x(2,1)\n surfparam(offsparam(nsurf)+5)=y(2,1)\n surfparam(offsparam(nsurf)+6)=z(2,1)\nC\n surfparam(offsparam(nsurf)+7)=x(3,1)\n surfparam(offsparam(nsurf)+8)=y(3,1)\n surfparam(offsparam(nsurf)+9)=z(3,1)\nC\nC ---------------------------------------------------------------\nC SET UP THE EQUATION OF THE PLANE FROM THE 3 POINTS.\nC\n a= (y(2,1)-y(1,1))*(z(3,1)-z(1,1)) -\n & (y(3,1)-y(1,1))*(z(2,1)-z(1,1))\n b=-((x(2,1)-x(1,1))*(z(3,1)-z(1,1)) -\n & (x(3,1)-x(1,1))*(z(2,1)-z(1,1)))\n c= (x(2,1)-x(1,1))*(y(3,1)-y(1,1)) -\n & (x(3,1)-x(1,1))*(y(2,1)-y(1,1))\n d=a*x(1,1)+b*y(1,1)+c*z(1,1)\n if(abs(d).gt.eps ) then\n absofd=abs(d)\n a=a/absofd\n b=b/absofd\n c=c/absofd\n d=d/absofd\n endif\nC\nC ---------------------------------------------------------------\nC SAVE COEFFICIENTS IN stbout\nC SAVE COEFFICIENTS IN stbout\nC\n surfparam(offsparam(nsurf)+10)=a\n surfparam(offsparam(nsurf)+11)=b\n surfparam(offsparam(nsurf)+12)=c\n surfparam(offsparam(nsurf)+13)=d\n lastsparam=offsparam(nsurf)+13\nC\nC ---------------------------------------------------------------\nC PRINT UNIT VECTOR FOR THE PLANE\nC\n ai=a/sqrt(a*a + b*b + c*c)\n bi=b/sqrt(a*a + b*b + c*c)\n ci=c/sqrt(a*a + b*b + c*c)\nC\n write(logmess,9060) isurfnm,ai,bi,ci\n 9060 format(' The unit vector for ',a8,' is ',\n & f10.7,'i ',f10.7,'j ',f10.7,'k')\n call writloga('default',0,logmess,0,ierrw)\nC\nC ---------------------------------------------------------------\nC IF REFLECTIVE PLANE, SET UP BOUNDARY INFO\nC\n if (ibtypein(1:lenibtype) .eq. 'reflect') then\nC\n ickrfl=1\n nb=nb+1\n call flbound(1,nb,3,x(1,1),y(1,1),z(1,1),x(2,1),\n & y(2,1),z(2,1),x(3,1),y(3,1),z(3,1))\n call flbound(2,nb,3,zero,zero,zero,zero,zero,zero,zero,zero,\n & zero)\nC\n endif\nC\n elseif ((istypein(1:lenistype) .eq. 'box' ) .or.\n & (istypein(1:lenistype) .eq. 'parallel')) then\nC\nC ***************************************************************\nC HANDLE BOX OR PARALLELPIPED TYPE SURFACE\nC\nC ---------------------------------------------------------------\nC IF BOX, CONVERT xmin, ymin TO x1 THROUGH z4 OF PARALLELPIPED\nC\n if (istypein(1:lenistype) .eq. 'box') then\nC\n if(lengthsparam.lt.offsparam(nsurf)+36) then\n call mmincblk('surfparam',geom_name,ipsurfparam,500,ierr)\n lengthsparam=lengthsparam+500\n endif\nC\n call test_argument_type(6,2,5,imsgin,xmsgin,cmsgin,\n * msgtype,nwds)\n xmn=xmsgin(5)\n ymn=xmsgin(6)\n zmn=xmsgin(7)\nC\n xmx=xmsgin(8)\n ymx=xmsgin(9)\n zmx=xmsgin(10)\nC\nC ............................................................\nC CONVERT INPUT DATA FROM LOCAL COORD. SYSTEM TO NORMAL\nC COORD. SYSTEM AND SAVE IN stbout\nC COORD. SYSTEM AND SAVE IN stbout\nC\n call xyznorm(xmn,ymn,zmn,xmin1,ymin1,zmin1)\n call xyznorm(xmx,ymx,zmx,xmax1,ymax1,zmax1)\nC\n surfparam(offsparam(nsurf)+1)=xmin1\n surfparam(offsparam(nsurf)+2)=ymin1\n surfparam(offsparam(nsurf)+3)=zmin1\nC\n surfparam(offsparam(nsurf)+4)=xmax1\n surfparam(offsparam(nsurf)+5)=ymax1\n surfparam(offsparam(nsurf)+6)=zmax1\nC\nC ............................................................\nC NOW CONVERT FROM BOX TO PARALLELPIPED IN CURRENT COORD. SYS.\nC THEN TRANSFORM THE CORNERS TO NORMAL COORD. SYSTEM.\nC\n x1in=xmn\n y1in=ymn\n z1in=zmn\nC\n x2in=xmx\n y2in=ymn\n z2in=zmn\nC\n x3in=xmn\n y3in=ymx\n z3in=zmn\nC\n x4in=xmn\n y4in=ymn\n z4in=zmx\nC\n call xyznorm(x1in,y1in,z1in,x1,y1,z1)\n call xyznorm(x2in,y2in,z2in,x2,y2,z2)\n call xyznorm(x3in,y3in,z3in,x3,y3,z3)\n call xyznorm(x4in,y4in,z4in,x4,y4,z4)\nC\n else\nC\n call test_argument_type(14,2,5,imsgin,xmsgin,cmsgin,\n * msgtype,nwds)\n x1in=xmsgin(5)\n y1in=xmsgin(6)\n z1in=xmsgin(7)\nC\n x2in=xmsgin(8)\n y2in=xmsgin(9)\n z2in=xmsgin(10)\nC\n x3in=xmsgin(11)\n y3in=xmsgin(12)\n z3in=xmsgin(13)\nC\n x4in=xmsgin(14)\n y4in=xmsgin(15)\n z4in=xmsgin(16)\nC\nC ............................................................\nC CONVERT INPUT DATA FROM LOCAL COORD. SYSTEM TO NORMAL\nC COORD. SYSTEM AND SAVE IN stbout\nC COORD. SYSTEM AND SAVE IN stbout\nC\n call xyznorm(x1in,y1in,z1in,x1,y1,z1)\n call xyznorm(x2in,y2in,z2in,x2,y2,z2)\n call xyznorm(x3in,y3in,z3in,x3,y3,z3)\n call xyznorm(x4in,y4in,z4in,x4,y4,z4)\nC\n surfparam(offsparam(nsurf)+1)=x1\n surfparam(offsparam(nsurf)+2)=y1\n surfparam(offsparam(nsurf)+3)=z1\nC\n surfparam(offsparam(nsurf)+4)=x2\n surfparam(offsparam(nsurf)+5)=y2\n surfparam(offsparam(nsurf)+6)=z2\nC\n \n surfparam(offsparam(nsurf)+7)=x3\n surfparam(offsparam(nsurf)+8)=y3\n surfparam(offsparam(nsurf)+9)=z3\nC\n surfparam(offsparam(nsurf)+10)=x4\n surfparam(offsparam(nsurf)+11)=y4\n surfparam(offsparam(nsurf)+12)=z4\nC\n endif\nC\nC ---------------------------------------------------------------\nC CALCULATE OFFSETS, XDIFF IS THE X DISTANCE BETWEEN POINTS\nC ALONG AN UPPER OR LOWER EDGE, DX IS THE X DISTANCE BETWEEN\nC POINTS ALONG A VERTICAL EDGE, ETC.\nC\n dx=x4-x1\n dy=y4-y1\n dz=z2-z1\nC\n xdiff=x2-x1\n ydiff=y3-y1\n zdiff=z4-z1\nC\nC ---------------------------------------------------------------\nC SET UP 3 POINTS ON EACH OF THE 6 PLANES SO THAT THE RIGHT\nC HAND SYSTEM POINTS OUTWARD.\nC\n x(1,1)=x1\n y(1,1)=y1\n z(1,1)=z1\nC\n x(2,1)=x2\n y(2,1)=y2\n z(2,1)=z2\nC\n x(3,1)=x4\n y(3,1)=y4\n z(3,1)=z4\nC\n x(1,2)=x4+xdiff\n y(1,2)=y2+dy\n z(1,2)=z2+zdiff\nC\n x(2,2)=x2\n y(2,2)=y2\n z(2,2)=z2\nC\n x(3,2)=x3+xdiff\n y(3,2)=y2+ydiff\n z(3,2)=z3+dz\nC\n x(1,3)=x(3,2)\n y(1,3)=y(3,2)\n z(1,3)=z(3,2)\nC\n x(2,3)=x3\n y(2,3)=y3\n z(2,3)=z3\nC\n x(3,3)=x3+dx\n y(3,3)=y3+dy\n z(3,3)=z3+zdiff\nC\n x(1,4)=x1\n y(1,4)=y1\n z(1,4)=z1\nC\n x(2,4)=x4\n y(2,4)=y4\n z(2,4)=z4\nC\n x(3,4)=x3\n y(3,4)=y3\n z(3,4)=z3\nC\n x(1,5)=x4\n y(1,5)=y4\n z(1,5)=z4\nC\n x(2,5)=x(1,2)\n y(2,5)=y(1,2)\n z(2,5)=z(1,2)\nC\n x(3,5)=x3+dx\n y(3,5)=y3+dy\n z(3,5)=z3+zdiff\nC\n x(1,6)=x1\n y(1,6)=y1\n z(1,6)=z1\nC\n x(2,6)=x3\n y(2,6)=y3\n z(2,6)=z3\nC\n x(3,6)=x2\n y(3,6)=y2\n z(3,6)=z2\nC\nC ---------------------------------------------------------------\nC LOOP THROUGH 6 PLANES TO GET EQUATIONS AND SAVE IN stbout\nC LOOP THROUGH 6 PLANES TO GET EQUATIONS AND SAVE IN stbout\nC\n if (istypein(1:lenistype) .eq. 'box') then\n istrt=6\n lastsparam=lastsparam+6\n else\n istrt=12\n lastsparam=lastsparam+12\n endif\nC\n do i=1,6\nC\nC ............................................................\nC SET UP THE EQUATION OF THE PLANE FROM THE 3 POINTS.\nC\n a= (y(2,i)-y(1,i))*(z(3,i)-z(1,i)) -\n & (y(3,i)-y(1,i))*(z(2,i)-z(1,i))\n b=-((x(2,i)-x(1,i))*(z(3,i)-z(1,i)) -\n & (x(3,i)-x(1,i))*(z(2,i)-z(1,i)))\n c= (x(2,i)-x(1,i))*(y(3,i)-y(1,i)) -\n & (x(3,i)-x(1,i))*(y(2,i)-y(1,i))\n d=a*x(1,i)+b*y(1,i)+c*z(1,i)\n if(abs(d).gt.eps ) then\n absofd=abs(d)\n a=a/absofd\n b=b/absofd\n c=c/absofd\n d=d/absofd\n endif\nC\nC ............................................................\nC SAVE COEFFICIENTS IN stbout\nC SAVE COEFFICIENTS IN stbout\nC\n iout=istrt+(i-1)*4\n surfparam(offsparam(nsurf)+iout+1)=a\n surfparam(offsparam(nsurf)+iout+2)=b\n surfparam(offsparam(nsurf)+iout+3)=c\n surfparam(offsparam(nsurf)+iout+4)=d\nC\nC ............................................................\nC IF REFLECTIVE PLANE, SET UP BOUNDARY INFO\nC\n if (ibtypein(1:lenibtype) .eq. 'reflect') then\n ickrfl=1\n nb=nb+1\n call flbound(1,nb,3,x(1,i),y(1,i),z(1,i),x(2,i),\n & y(2,i),z(2,i),x(3,i),y(3,i),z(3,i))\n call flbound(2,nb,3,zero,zero,zero,zero,zero,zero,zero,\n & zero,zero)\n endif\nC\n enddo\nC\n lastsparam=lastsparam+24\nC\n elseif (istypein(1:lenistype) .eq. 'sphere') then\nC\nC ***************************************************************\nC HANDLE SPHERE TYPE SURFACE\nC\n call test_argument_type(4,2,5,imsgin,xmsgin,cmsgin,\n * msgtype,nwds)\n x1in=xmsgin(5)\n y1in=xmsgin(6)\n z1in=xmsgin(7)\n r=xmsgin(8)\n if(lengthsparam.lt.offsparam(nsurf)+4) then\n call mmincblk('surfparam',geom_name,ipsurfparam,500,ierr)\n lengthsparam=lengthsparam+500\n endif\nC\nC ---------------------------------------------------------------\nC CONVERT INPUT POINTS FROM CURRENT COORDINATE SYSTEM TO\nC NORMAL COORDINATE SYSTEM AND SAVE IN stbout\nC NORMAL COORDINATE SYSTEM AND SAVE IN stbout\nC\n call xyznorm(x1in,y1in,z1in,xc,yc,zc)\nC\n surfparam(offsparam(nsurf)+1)=xc\n surfparam(offsparam(nsurf)+2)=yc\n surfparam(offsparam(nsurf)+3)=zc\n surfparam(offsparam(nsurf)+4)=r\n lastsparam=lastsparam+4\nC\n elseif ((istypein(1:lenistype) .eq. 'cylinder') .or.\n & (istypein(1:lenistype) .eq. 'cone' ) .or.\n & (istypein(1:lenistype) .eq. 'tabular' )) then\nC\nC ***************************************************************\nC HANDLE CYLINDER, CONE AND ROTATED TABULAR PROFILE TYPE SURFACE\nC\n if ((istypein(1:lenistype) .eq. 'cylinder') .or.\n & (istypein(1:lenistype) .eq. 'cone' )) then\n call test_argument_type(7,2,5,imsgin,xmsgin,cmsgin,\n * msgtype,nwds)\n elseif (istypein(1:lenistype) .eq. 'tabular' ) then\n call test_argument_type(6,2,5,imsgin,xmsgin,cmsgin,\n * msgtype,nwds)\n endif\n if(lengthsparam.lt.offsparam(nsurf)+14) then\n call mmincblk('surfparam',geom_name,ipsurfparam,500,ierr)\n lengthsparam=lengthsparam+500\n endif\n x1in=xmsgin(5)\n y1in=xmsgin(6)\n z1in=xmsgin(7)\nC\n x2in=xmsgin(8)\n y2in=xmsgin(9)\n z2in=xmsgin(10)\nC\n if (istypein(1:lenistype) .ne. 'tabular') then\n r=xmsgin(11)\n else\n igeom=cmsgin(11)\n lenigeom = icharlnf(igeom)\n endif\nC\nC ---------------------------------------------------------------\nC CONVERT INPUT DATA FROM LOCAL COORD. SYSTEM TO NORMAL\nC COORD. SYSTEM AND SAVE IN stbout\nC COORD. SYSTEM AND SAVE IN stbout\nC\n call xyznorm(x1in,y1in,z1in,x1,y1,z1)\n call xyznorm(x2in,y2in,z2in,x2,y2,z2)\nC\n surfparam(offsparam(nsurf)+1)=x1\n surfparam(offsparam(nsurf)+2)=y1\n surfparam(offsparam(nsurf)+3)=z1\nC\n surfparam(offsparam(nsurf)+4)=x2\n surfparam(offsparam(nsurf)+5)=y2\n surfparam(offsparam(nsurf)+6)=z2\nC\n surfparam(offsparam(nsurf)+7)=xmsgin(11)\nC\nC ---------------------------------------------------------------\nC ROTATE THE AXES SO THAT THE LINE BETWEEN POINT 1 AND POINT 2 IS\nC THE NEW Z AXIS\nC\n dist=sqrt((x2-x1)**2 + (y2-y1)**2 + (z2-z1)**2)\nC\nC ...............................................................\nC DETERMINE THE UNIT VECTOR ALONG THE INPUT POINTS (NEW Z AXIS)\nC\n az=(x2-x1)/dist\n bz=(y2-y1)/dist\n cz=(z2-z1)/dist\nC\nC ...............................................................\nC DETERMINE THE UNIT VECTOR ALONG THE NEW X AXIS WHICH LIES ON\nC THE OLD X-Y PLANE\nC\n if ((az*az+bz*bz) .eq. 0) then\n ax=1\n bx=0\n else\n ax=sqrt(bz*bz/(az*az+bz*bz))\n bx=-sqrt(az*az/(az*az+bz*bz))\n endif\nC\n cx=0\n if (az .lt. 0 .and. bz .gt. 0) bx=-bx\n if (az .lt. 0 .and. bz .lt. 0) then\n ax=-ax\n bx=-bx\n endif\nC\n if (az .gt. 0 .and. bz .lt. 0) ax=-ax\nC\nC ...............................................................\nC DETERMINE THE UNIT VECTOR ALONG THE NEW Y AXIS WHICH LIES\nC PERPENDICULAR TO THE NEW Z AND X AXIS (Z CROSS X)\nC\n ay=bz*cx-bx*cz\n by=cz*ax-cx*az\n cy=az*bx-ax*bz\nC\nC ---------------------------------------------------------------\nC STORE THE CENTER OR VERTEX POINT, THE END POINT, AND THE\nC RADIUS IN THE STORAGE BLOCK\nC\n surfparam(offsparam(nsurf)+8)=x1\n surfparam(offsparam(nsurf)+9)=y1\n surfparam(offsparam(nsurf)+10)=z1\nC\n surfparam(offsparam(nsurf)+11)=x2\n surfparam(offsparam(nsurf)+12)=y2\n surfparam(offsparam(nsurf)+13)=z2\nC\n\nC\nC ---------------------------------------------------------------\nC FOR A CONE, STORE dist FOR C IN THE EQUATION OF A CONE\nC FOR A CONE or cylinder store radius\nc For tabular store sheet name\nC\n if (istypein(1:lenistype) .eq. 'cone') then\n surfparam(offsparam(nsurf)+14)=r\n surfparam(offsparam(nsurf)+15)=dist\n lastsparam=lastsparam+15\n elseif (istypein(1:lenistype) .eq. 'tabular') then\n sheetnm(nsurf)=igeom\n lastsparam=lastsparam+13\n else\n surfparam(offsparam(nsurf)+14)=r\n lastsparam=lastsparam+14\n endif\nC\nC ---------------------------------------------------------------\nC FOR A ROTATED TABULAR SURFACE, GET AND STORE THE PROFILE PAIRS\nC\n if (istypein(1:lenistype) .eq. 'tabular') then\nC\n iend=0\n ntab=nwds-12\n if(lengthsparam.lt.offsparam(nsurf)+24+ntab) then\n call mmincblk('surfparam',geom_name,ipsurfparam,ntab+500,\n * ierr)\n lengthsparam=lengthsparam+500+ntab\n endif\nC\nC ............................................................\nC LOOP THROUGH INPUT DATA UNTIL end FOUND\nC\n do i=12,nwds-1\n surfparam(offsparam(nsurf)+i+4)=xmsgin(i)\n enddo\nC\n surfparam(offsparam(nsurf)+15)=nwds-12\n lastsparam=lastsparam+2+ntab\nC\nC ............................................................\nC CONVERT zr TO rz OR tr TO rt GEOMETRY\nC\n if ((igeom(1:lenigeom).eq.'zr') .or.\n & (igeom(1:lenigeom).eq.'tr')) then\nC\n if (igeom(1:lenigeom) .eq. 'zr') igeom='rz'\n if (igeom(1:lenigeom) .eq. 'tr') igeom='rt'\nC\n sheetnm(nsurf)=igeom\nC\n do i=1,ntab,2\n zz=surfparam(offsparam(nsurf)+15+i)\n rr=surfparam(offsparam(nsurf)+15+i+1)\n surfparam(offsparam(nsurf)+15+i)=rr\n surfparam(offsparam(nsurf)+15+i+1)=zz\n enddo\nC\n endif\nC\nC ............................................................\nC CONVERT rt GEOMETRY TO rz GEOMETRY\nC\n if (igeom(1:lenigeom) .eq. 'rt') then\nC\n sheetnm(nsurf)='rz'\nC\n do i=1,ntab,2\n r=surfparam(offsparam(nsurf)+15+i)\n thetain=surfparam(offsparam(nsurf)+15+i+1)\n theta=thetain*pie/180.\nC\n if (thetain .eq. 0) then\n surfparam(offsparam(nsurf)+15+i)=0\n surfparam(offsparam(nsurf)+15+i+1)=r\n elseif (thetain .eq. 90) then\n surfparam(offsparam(nsurf)+15+i)=r\n surfparam(offsparam(nsurf)+15+i+1)=0\n elseif (thetain .eq. 180) then\n surfparam(offsparam(nsurf)+15+i)=0\n surfparam(offsparam(nsurf)+15+i+1)=-r\n else\n surfparam(offsparam(nsurf)+15+i)=r*sin(theta)\n surfparam(offsparam(nsurf)+15+i+1)=r*cos(theta)\n endif\n enddo\nC\n endif\nC\n endif\nC\nC ---------------------------------------------------------------\nC STORE THE ROTATION VECTORS AS A MATRIX\nC\n surfparam(lastsparam+1)=ax\n surfparam(lastsparam+2)=bx\n surfparam(lastsparam+3)=cx\nC\n surfparam(lastsparam+4)=ay\n surfparam(lastsparam+5)=by\n surfparam(lastsparam+6)=cy\nC\n surfparam(lastsparam+7)=az\n surfparam(lastsparam+8)=bz\n surfparam(lastsparam+9)=cz\nC\n lastsparam=lastsparam+9\nC\n elseif (istypein(1:lenistype) .eq. 'ellipse') then\nC\nC ***************************************************************\nC HANDLE ELLIPSOID TYPE SURFACE\nC\n call test_argument_type(12,2,5,imsgin,xmsgin,cmsgin,\n * msgtype,nwds)\n if(lengthsparam.lt.offsparam(nsurf)+27) then\n call mmincblk('surfparam',geom_name,ipsurfparam,500,ierr)\n lengthsparam=lengthsparam+500\n endif\n x1in=xmsgin(5)\n y1in=xmsgin(6)\n z1in=xmsgin(7)\nC\n x2in=xmsgin(8)\n y2in=xmsgin(9)\n z2in=xmsgin(10)\nC\n x3in=xmsgin(11)\n y3in=xmsgin(12)\n z3in=xmsgin(13)\nC\n a=xmsgin(14)\n b=xmsgin(15)\n c=xmsgin(16)\nC\nC ---------------------------------------------------------------\nC CONVERT INPUT DATA FROM LOCAL COORD. SYSTEM TO NORMAL\nC COORD. SYSTEM AND SAVE IN stbout\nC COORD. SYSTEM AND SAVE IN stbout\nC\n call xyznorm(x1in,y1in,z1in,x1,y1,z1)\n call xyznorm(x2in,y2in,z2in,x2,y2,z2)\n call xyznorm(x3in,y3in,z3in,x3,y3,z3)\nC\n surfparam(offsparam(nsurf)+1)=x1\n surfparam(offsparam(nsurf)+2)=y1\n surfparam(offsparam(nsurf)+3)=z1\nC\n surfparam(offsparam(nsurf)+4)=x2\n surfparam(offsparam(nsurf)+5)=y2\n surfparam(offsparam(nsurf)+6)=z2\nC\n surfparam(offsparam(nsurf)+7)=x3\n surfparam(offsparam(nsurf)+8)=y3\n surfparam(offsparam(nsurf)+9)=z3\nC\n surfparam(offsparam(nsurf)+10)=a\n surfparam(offsparam(nsurf)+11)=b\n surfparam(offsparam(nsurf)+12)=c\nC\nC ---------------------------------------------------------------\nC ROTATE THE AXES SO THAT THE LINE BETWEEN POINT 1 AND POINT 2 IS\nC THE NEW X AXIS AND THE LINE BETWEEN 1 AND 3 IS THE NEW Y AXIS\nC\n distx=sqrt((x2-x1)**2 + (y2-y1)**2 + (z2-z1)**2)\n disty=sqrt((x3-x1)**2 + (y3-y1)**2 + (z3-z1)**2)\nC\nC ...............................................................\nC DETERMINE THE UNIT VECTOR ALONG THE INPUT POINTS\nC\n ax=(x2-x1)/distx\n bx=(y2-y1)/distx\n cx=(z2-z1)/distx\nC\n aty=(x3-x1)/disty\n bty=(y3-y1)/disty\n cty=(z3-z1)/disty\nC\nC ...............................................................\nC DETERMINE THE UNIT VECTOR ALONG THE NEW Z AXIS WHICH LIES\nC PERPENDICULAR TO THE NEW X AND Y AXIS (X CROSS Y)\nC\n az=bx*cty-bty*cx\n bz=cx*aty-cty*ax\n cz=ax*bty-aty*bx\nC\nC ...............................................................\nC DETERMINE THE UNIT VECTOR ALONG THE NEW Y AXIS WHICH LIES\nC PERPENDICULAR TO THE NEW Z AND X AXIS (Z CROSS X)\nC\n ay=bz*cx-bx*cz\n by=cz*ax-cx*az\n cy=az*bx-ax*bz\nC\nC ...............................................................\nC CHECK THAT THE ORIGINAL SEMI-AXIS WERE PERPENDICULAR.\nC\n numer=ay*aty + by*bty + cy*cty\n denom=sqrt(ay**2+by**2+cy**2) * sqrt(aty**2+bty**2+cty**2)\n angle=acos(numer/denom)\nC\n if (angle .gt. .08725) then\n write(logmess,9080)\n 9080 format(' Warning - the semi-axis points are not ',\n & 'perpendicular.')\n call writloga('default',0,logmess,0,ierrw)\n write(logmess,9100)\n 9100 format(' The y semi-axis will be recalculated.')\n call writloga('default',0,logmess,0,ierrw)\n endif\nC\nC ---------------------------------------------------------------\nC STORE THE CENTER AND THE RADII IN THE STORAGE BLOCK.\nC\n surfparam(offsparam(nsurf)+13)=x1\n surfparam(offsparam(nsurf)+14)=y1\n surfparam(offsparam(nsurf)+15)=z1\nC\n surfparam(offsparam(nsurf)+16)=a\n surfparam(offsparam(nsurf)+17)=b\n surfparam(offsparam(nsurf)+18)=c\nC\nC ---------------------------------------------------------------\nC STORE THE ROTATION MATRIX\nC\n surfparam(offsparam(nsurf)+19)=ax\n surfparam(offsparam(nsurf)+20)=bx\n surfparam(offsparam(nsurf)+21)=cx\nC\n surfparam(offsparam(nsurf)+22)=ay\n surfparam(offsparam(nsurf)+23)=by\n surfparam(offsparam(nsurf)+24)=cy\nC\n surfparam(offsparam(nsurf)+25)=az\n surfparam(offsparam(nsurf)+26)=bz\n surfparam(offsparam(nsurf)+27)=cz\nC\n lastsparam=lastsparam+27\nC\n elseif (istypein(1:lenistype) .eq. 'sheet') then\nC\nC ***************************************************************\nC HANDLE SHEET TYPE SURFACE\nC\n call sheet(xmsgin,cmsgin,imsgin,msgtype,nwds,cmosheet)\n sheetnm(nsurf)=cmosheet\n call cmo_select(cmo,ierr)\nC\n else\nC\nC ***************************************************************\nC ILLEGAL SURFACE TYPE.\nC\n write(logmess,9120) istypein\n 9120 format(' ERROR - Illegal Surface Type: ', a)\n call writloga('default',0,logmess,0,ierrw)\n goto 9999\nC\n endif\nC\nc call conadd for constrained surface types\nc\n if(ibtypein(1:7).eq.'reflect'.or.ibtypein(1:7).eq.'virtual'\n * .or.ibtypein(1:8).eq.'intrcons') call conadd(nsurf)\n 9999 continue\nC\n return\n end\n", "meta": {"hexsha": "1498bfbd384ce382de1c690918ab0e0b4f24f8d6", "size": 46015, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/surface.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/surface.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/surface.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": 34.7283018868, "max_line_length": 82, "alphanum_fraction": 0.5110724764, "num_tokens": 14802, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998823, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6852186021340643}} {"text": "MODULE Sparse_Gaussian\r\n\r\nIMPLICIT NONE\r\nINTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(14, 60)\r\n\r\n\r\nCONTAINS\r\n\r\nSUBROUTINE dspslv (n, a, ia, ja, b, r, c, MAX, x, itemp, rtemp, ierr)\r\n \r\n! Code converted using TO_F90 by Alan Miller\r\n! Date: 2003-07-14 Time: 20:38:15\r\n \r\n!-----------------------------------------------------------------------\r\n! SOLUTION OF DOUBLE PRECISION SPARSE EQUATIONS\r\n!-----------------------------------------------------------------------\r\n! DSPSLV CALLS DNSPIV WHICH USES SPARSE GAUSSIAN ELIMINATION WITH COLUMN\r\n! INTERCHANGES TO SOLVE THE LINEAR SYSTEM A X = B. THE ELIMINATION PHASE\r\n! PERFORMS ROW OPERATIONS ON A AND B TO OBTAIN A UNIT UPPER TRIANGULAR\r\n! MATRIX U AND A VECTOR Y. THE SOLUTION PHASE SOLVES U X = Y.\r\n\r\n! INPUT ARGUMENTS---\r\n\r\n! N INTEGER NUMBER OF EQUATIONS AND UNKNOWNS\r\n\r\n! A DOUBLE PRECISION ARRAY WITH ONE ENTRY PER NONZERO IN A,\r\n! CONTAINING THE ACTUAL NONZEROS. (SEE THE MATRIX STORAGE\r\n! DESCRIPTION BELOW)\r\n\r\n! IA INTEGER ARRAY OF N+1 ENTRIES CONTAINING ROW POINTERS TO A\r\n! (SEE MATRIX STORAGE DESCRIPTION BELOW)\r\n\r\n! JA INTEGER ARRAY WITH ONE ENTRY PER NONZERO IN A, CONTAINING COLUMN\r\n! NUMBERS OF THE NONZEROS OF A. (SEE MATRIX STORAGE\r\n! DESCRIPTION BELOW)\r\n\r\n! B DOUBLE PRECISION ARRAY OF N ENTRIES CONTAINING THE RIGHT\r\n! HAND SIDE DATA\r\n\r\n! R INTEGER ARRAY OF N ENTRIES SPECIFYING THE ORDER OF THE\r\n! ROWS OF A (I.E., THE ELIMINATION ORDER FOR THE EQUATIONS)\r\n\r\n! C INTEGER ARRAY OF N ENTRIES SPECIFYING THE ORDER OF THE\r\n! COLUMNS OF A. C IS ALSO AN OUTPUT ARGUMENT\r\n\r\n! MAX INTEGER NUMBER SPECIFYING MAXIMUM NUMBER OF OFF-DIAGONAL\r\n! NONZERO ENTRIES OF U WHICH MAY BE STORED\r\n\r\n! ITEMP INTEGER ARRAY OF 3*N + MAX + 2 ENTRIES, FOR INTERNAL USE\r\n\r\n! RTEMP DOUBLE PRECISION ARRAY OF N + MAX ENTRIES FOR INTERNAL USE\r\n\r\n\r\n! OUTPUT ARGUMENTS---\r\n\r\n! C INTEGER ARRAY OF N ENTRIES SPECIFYING THE ORDER OF THE\r\n! COLUMNS OF U. C IS ALSO AN INPUT ARGUMENT\r\n\r\n! X DOUBLE PRECISION ARRAY OF N ENTRIES CONTAINING THE SOLUTION VECTOR\r\n\r\n! IERR INTEGER NUMBER WHICH INDICATES ERROR CONDITIONS OR THE ACTUAL\r\n! NUMBER OF OFF-DIAGONAL ENTRIES IN U (FOR SUCCESSFUL COMPLETION)\r\n\r\n! IERR VALUES ARE---\r\n\r\n! 0 < IERR SUCCESSFUL COMPLETION. IERR=MAX(1,M)\r\n! WHERE M IS THE NUMBER OF OFF-DIAGONAL\r\n! NONZERO ENTRIES OF U.\r\n\r\n! IERR = 0 ERROR. N IS LESS THAN OR EQUAL TO 0\r\n\r\n! -N <= IERR < 0 ERROR. ROW NUMBER IABS(IERR) OF A IS IS NULL\r\n\r\n! -2*N <= IERR < -N ERROR. ROW NUMBER IABS(IERR+N) HAS A\r\n! DUPLICATE ENTRY\r\n\r\n! -3*N <= IERR < -2*N ERROR. ROW NUMBER IABS(IERR+2*N)\r\n! HAS A ZERO PIVOT\r\n\r\n! -4*N <= IERR < -3*N ERROR. ROW NUMBER IABS(IERR+3*N)\r\n! EXCEEDS STORAGE\r\n\r\n\r\n! STORAGE OF SPARSE MATRICES---\r\n\r\n! THE SPARSE MATRIX A IS STORED USING THREE ARRAYS IA, JA, AND A.\r\n! THE ARRAY A CONTAINS THE NONZEROS OF THE MATRIX ROW-BY-ROW, NOT\r\n! NECESSARILY IN ORDER OF INCREASING COLUMN NUMBER. THE ARRAY JA CONTAINS\r\n! THE COLUMN NUMBERS CORRESPONDING TO THE NONZEROS STORED IN THE ARRAY A\r\n! (I.E., IF THE NONZERO STORED IN A(K) IS IN COLUMN J, THEN JA(K) = J).\r\n! THE ARRAY IA CONTAINS POINTERS TO THE ROWS OF NONZEROS/COLUMN INDICES IN\r\n! THE ARRAY A/JA (I.E., A(IA(I))/JA(IA(I)) IS THE FIRST ENTRY FOR ROW I IN\r\n! THE ARRAY A/JA). IA(N+1) IS SET SO THAT IA(N+1) - IA(1) = THE NUMBER OF\r\n! NONZERO ELEMENTS IN A.\r\n!------------------------\r\n\r\nINTEGER, INTENT(IN) :: n\r\nREAL (dp), INTENT(IN OUT) :: a(*)\r\nINTEGER, INTENT(IN OUT) :: ia(*)\r\nINTEGER, INTENT(IN OUT) :: ja(*)\r\nREAL (dp), INTENT(IN OUT) :: b(n)\r\nINTEGER, INTENT(IN OUT) :: r(n)\r\nINTEGER, INTENT(IN OUT) :: c(n)\r\nINTEGER, INTENT(IN OUT) :: MAX\r\nREAL (dp), INTENT(IN OUT) :: x(n)\r\nINTEGER, INTENT(OUT) :: itemp(*)\r\nREAL (dp), INTENT(IN OUT) :: rtemp(*)\r\nINTEGER, INTENT(OUT) :: ierr\r\n\r\nINTEGER :: iu, ju, k, l, u, y, p\r\n\r\nierr = 0\r\nIF (n <= 0) RETURN\r\n\r\n! SET INDICES TO DIVIDE TEMPORARY STORAGE FOR DNSPIV\r\n\r\ny = 1\r\nu = y + n\r\np = n + 1\r\niu = p + n + 1\r\nju = iu + n + 1\r\n\r\n! COMPUTE THE INVERSE PERMUTATION OF C\r\n\r\nDO k = 1,n\r\n l = c(k)\r\n itemp(l) = k\r\nEND DO\r\n\r\n! CALL DNSPIV TO PERFORM COMPUTATIONS\r\n\r\nCALL dnspiv (n, ia, ja, a, b, MAX, r, c, itemp(1), x, rtemp(y), itemp(p), &\r\n itemp(iu), itemp(ju), rtemp(u), ierr)\r\nIF (ierr == 0) ierr = 1\r\nRETURN\r\nEND SUBROUTINE dspslv\r\n\r\n\r\n\r\nSUBROUTINE dnspiv(n, ia, ja, a, b, MAX, r, c, ic, x, y, p, iu, ju, u, ierr)\r\n \r\n! DNSPIV USES SPARSE GAUSSIAN ELIMINATION WITH COLUMN INTERCHANGES TO SOLVE\r\n! THE LINEAR SYSTEM A X = B. THE ELIMINATION PHASE PERFORMS ROW OPERATIONS\r\n! ON A AND B TO OBTAIN A UNIT UPPER TRIANGULAR MATRIX U AND A VECTOR Y.\r\n! THE SOLUTION PHASE SOLVES U X = Y.\r\n\r\n\r\n! SEE DSPSLV FOR DESCRIPTIONS OF ALL INPUT AND OUTPUT ARGUMENTS\r\n! OTHER THAN THOSE DESCRIBED BELOW\r\n\r\n! IC INTEGER ARRAY OF N ENTRIES WHICH IS THE INVERSE OF C\r\n! (I.E., IC(C(I)) = I). IC IS BOTH AN INPUT AND OUTPUT ARGUMENT.\r\n\r\n! INPUT ARGUMENTS (USED INTERNALLY ONLY)---\r\n\r\n! Y DOUBLE PRECISION ARRAY OF N ENTRIES USED TO COMPUTE THE UPDATED\r\n! RIGHT HAND SIDE\r\n\r\n! P INTEGER ARRAY OF N+1 ENTRIES USED FOR A LINKED LIST.\r\n! P(N+1) IS THE LIST HEADER, AND THE ENTRY FOLLOWING P(K) IS IN P(P(K)).\r\n! THUS, P(N+1) IS THE FIRST DATA ITEM, P(P(N+1)) IS THE SECOND, ETC.\r\n! A POINTER OF N+1 MARKS THE END OF THE LIST\r\n\r\n! IU INTEGER ARRAY OF N+1 ENTRIES USED FOR ROW POINTERS TO U\r\n! (SEE MATRIX STORAGE DESCRIPTION BELOW)\r\n\r\n! JU INTEGER ARRAY OF MAX ENTRIES USED FOR COLUMN NUMBERS OF THE NONZEROS IN\r\n! THE STRICT UPPER TRIANGLE OF U. (SEE MATRIX STORAGE DESCRIPTION BELOW)\r\n\r\n! U DOUBLE PRECISION ARRAY OF MAX ENTRIES USED FOR THE ACTUAL NONZEROS IN\r\n! THE STRICT UPPER TRIANGLE OF U. (SEE MATRIX STORAGE DESCRIPTION BELOW)\r\n\r\n\r\n! STORAGE OF SPARSE MATRICES---\r\n\r\n! THE SPARSE MATRIX A IS STORED USING THREE ARRAYS IA, JA, AND A.\r\n! THE ARRAY A CONTAINS THE NONZEROS OF THE MATRIX ROW-BY-ROW, NOT\r\n! NECESSARILY IN ORDER OF INCREASING COLUMN NUMBER. THE ARRAY JA CONTAINS\r\n! THE COLUMN NUMBERS CORRESPONDING TO THE NONZEROS STORED IN THE ARRAY A\r\n! (I.E., IF THE NONZERO STORED IN A(K) IS IN COLUMN J, THEN JA(K) = J).\r\n! THE ARRAY IA CONTAINS POINTERS TO THE ROWS OF NONZEROS/COLUMN INDICES IN\r\n! THE ARRAY A/JA (I.E., A(IA(I))/JA(IA(I)) IS THE FIRST ENTRY FOR ROW I IN\r\n! THE ARRAY A/JA). IA(N+1) IS SET SO THAT IA(N+1) - IA(1) = THE NUMBER OF\r\n! NONZEROS IN A. IU, JU, AND U ARE USED IN A SIMILAR WAY TO STORE THE STRICT\r\n! UPPER TRIANGLE OF U, EXCEPT THAT JU ACTUALLY CONTAINS C(J) INSTEAD OF J\r\n\r\n\r\nINTEGER, INTENT(IN) :: n\r\nINTEGER, INTENT(IN) :: ia(*)\r\nINTEGER, INTENT(IN) :: ja(*)\r\nREAL (dp), INTENT(IN) :: a(*)\r\nREAL (dp), INTENT(IN) :: b(n)\r\nINTEGER, INTENT(IN) :: MAX\r\nINTEGER, INTENT(IN) :: r(n)\r\nINTEGER, INTENT(IN OUT) :: c(n)\r\nINTEGER, INTENT(IN OUT) :: ic(n)\r\nREAL (dp), INTENT(OUT) :: x(n)\r\nREAL (dp), INTENT(IN OUT) :: y(n)\r\nINTEGER, INTENT(OUT) :: p(*)\r\nINTEGER, INTENT(OUT) :: iu(*)\r\nINTEGER, INTENT(IN OUT) :: ju(MAX)\r\nREAL (dp), INTENT(IN OUT) :: u(MAX)\r\nINTEGER, INTENT(OUT) :: ierr\r\n\r\nREAL (dp) :: dk, lki, xpv, xpvmax, yk\r\n\r\nINTEGER :: ck, i, j, jaj, jmin, jmax, juj, juptr, k, maxc, maxcl, nzcnt, &\r\n pk, ppk, pv, v, vi, vj, vk\r\n\r\n! INITIALIZE WORK STORAGE AND POINTERS TO JU\r\n\r\nx(1:n) = 0.d0\r\niu(1) = 1\r\njuptr = 0\r\n\r\n! PERFORM SYMBOLIC AND NUMERIC FACTORIZATION ROW BY ROW\r\n! VK (VI,VJ) IS THE GRAPH VERTEX FOR ROW K (I,J) OF U\r\n\r\nDO k = 1, n\r\n \r\n! INITIALIZE LINKED LIST AND FREE STORAGE FOR THIS ROW\r\n! THE R(K)-TH ROW OF A BECOMES THE K-TH ROW OF U.\r\n \r\n p(n+1) = n + 1\r\n vk = r(k)\r\n \r\n! SET UP ADJACENCY LIST FOR VK, ORDERED IN CURRENT COLUMN ORDER OF U.\r\n! THE LOOP INDEX GOES DOWNWARD TO EXPLOIT ANY COLUMNS FROM A\r\n! IN CORRECT RELATIVE ORDER\r\n \r\n jmin = ia(vk)\r\n jmax = ia(vk+1) - 1\r\n IF (jmin > jmax) GO TO 170\r\n j = jmax\r\n 20 jaj = ja(j)\r\n vj = ic(jaj)\r\n \r\n! STORE A(K,J) IN WORK VECTOR\r\n \r\n x(vj) = a(j)\r\n! THIS CODE INSERTS VJ INTO ADJACENCY LIST OF VK\r\n ppk = n + 1\r\n 30 pk = ppk\r\n ppk = p(pk)\r\n IF (ppk-vj < 0.0) THEN\r\n GO TO 30\r\n ELSE IF (ppk-vj == 0.0) THEN\r\n GO TO 180\r\n END IF\r\n p(vj) = ppk\r\n p(pk) = vj\r\n j = j - 1\r\n IF (j >= jmin) GO TO 20\r\n \r\n! THE FOLLOWING CODE COMPUTES THE K-TH ROW OF U\r\n \r\n vi = n + 1\r\n yk = b(vk)\r\n 50 vi = p(vi)\r\n IF (vi < k) THEN\r\n \r\n! VI LT VK -- PROCESS THE L(K,I) ELEMENT AND MERGE THE\r\n! ADJACENCY OF VI WITH THE ORDERED ADJACENCY OF VK\r\n \r\n lki = -x(vi)\r\n x(vi) = 0.d0\r\n \r\n! ADJUST RIGHT HAND SIDE TO REFLECT ELIMINATION\r\n \r\n yk = yk + lki * y(vi)\r\n ppk = vi\r\n jmin = iu(vi)\r\n jmax = iu(vi+1) - 1\r\n IF (jmin > jmax) GO TO 50\r\n DO j = jmin, jmax\r\n juj = ju(j)\r\n vj = ic(juj)\r\n \r\n! IF VJ IS ALREADY IN THE ADJACENCY OF VK, SKIP THE INSERTION\r\n \r\n IF (x(vj) == 0.d0) THEN\r\n \r\n! INSERT VJ IN ADJACENCY LIST OF VK.\r\n! RESET PPK TO VI IF WE HAVE PASSED THE CORRECT INSERTION SPOT.\r\n! (THIS HAPPENS WHEN THE ADJACENCY OF\r\n! VI IS NOT IN CURRENT COLUMN ORDER DUE TO PIVOTING.)\r\n \r\n IF (vj-ppk < 0.0) THEN\r\n GO TO 60\r\n ELSE IF (vj-ppk == 0.0) THEN\r\n GO TO 90\r\n ELSE\r\n GO TO 70\r\n END IF\r\n 60 ppk = vi\r\n 70 pk = ppk\r\n ppk = p(pk)\r\n IF (ppk-vj < 0.0) THEN\r\n GO TO 70\r\n ELSE IF (ppk-vj == 0.0) THEN\r\n GO TO 90\r\n END IF\r\n p(vj) = ppk\r\n p(pk) = vj\r\n ppk = vj\r\n END IF\r\n \r\n! COMPUTE L(K,J) = L(K,J) - L(K,I)*U(I,J) FOR L(K,I) NONZERO\r\n! COMPUTE U*(K,J) = U*(K,J) - L(K,I)*U(I,J) FOR U(K,J) NONZERO\r\n! (U*(K,J) = U(K,J)*D(K,K))\r\n \r\n 90 x(vj) = x(vj) + lki * u(j)\r\n END DO\r\n GO TO 50\r\n END IF\r\n \r\n! PIVOT--INTERCHANGE LARGEST ENTRY OF K-TH ROW OF U WITH THE DIAGONAL ENTRY.\r\n \r\n! FIND LARGEST ENTRY, COUNTING OFF-DIAGONAL NONZEROS\r\n \r\n IF (vi > n) GO TO 190\r\n xpvmax = ABS(x(vi))\r\n maxc = vi\r\n nzcnt = 0\r\n pv = vi\r\n 110 v = pv\r\n pv = p(pv)\r\n IF (pv <= n) THEN\r\n nzcnt = nzcnt + 1\r\n xpv = ABS(x(pv))\r\n IF (xpv <= xpvmax) GO TO 110\r\n xpvmax = xpv\r\n maxc = pv\r\n maxcl = v\r\n GO TO 110\r\n END IF\r\n IF (xpvmax == 0.d0) GO TO 190\r\n \r\n! IF VI = K, THEN THERE IS AN ENTRY FOR DIAGONAL\r\n! WHICH MUST BE DELETED. OTHERWISE, DELETE THE\r\n! ENTRY WHICH WILL BECOME THE DIAGONAL ENTRY\r\n \r\n IF (vi /= k) THEN\r\n IF (vi /= maxc) THEN\r\n p(maxcl) = p(maxc)\r\n GO TO 120\r\n END IF\r\n END IF\r\n vi = p(vi)\r\n \r\n! COMPUTE D(K) = 1/L(K,K) AND PERFORM INTERCHANGE.\r\n \r\n 120 dk = 1.d0 / x(maxc)\r\n x(maxc) = x(k)\r\n i = c(k)\r\n c(k) = c(maxc)\r\n c(maxc) = i\r\n ck = c(k)\r\n ic(ck) = k\r\n ic(i) = maxc\r\n x(k) = 0.d0\r\n \r\n! UPDATE RIGHT HAND SIDE.\r\n \r\n y(k) = yk * dk\r\n \r\n! COMPUTE VALUE FOR IU(K+1) AND CHECK FOR STORAGE OVERFLOW\r\n \r\n iu(k+1) = iu(k) + nzcnt\r\n IF (iu(k+1) > MAX+1) GO TO 200\r\n \r\n! MOVE COLUMN INDICES FROM LINKED LIST TO JU.\r\n! COLUMNS ARE STORED IN CURRENT ORDER WITH ORIGINAL\r\n! COLUMN NUMBER (C(J)) STORED FOR CURRENT COLUMN J\r\n \r\n IF (vi <= n) THEN\r\n j = vi\r\n 130 juptr = juptr + 1\r\n ju(juptr) = c(j)\r\n u(juptr) = x(j) * dk\r\n x(j) = 0.d0\r\n j = p(j)\r\n IF (j <= n) GO TO 130\r\n END IF\r\nEND DO\r\n\r\n! BACKSOLVE U X = Y, AND REORDER X TO CORRESPOND WITH A\r\n\r\nk = n\r\nDO i = 1, n\r\n yk = y(k)\r\n jmin = iu(k)\r\n jmax = iu(k+1) - 1\r\n IF (jmin <= jmax) THEN\r\n DO j = jmin, jmax\r\n juj = ju(j)\r\n juj = ic(juj)\r\n yk = yk - u(j) * y(juj)\r\n END DO\r\n END IF\r\n y(k) = yk\r\n ck = c(k)\r\n x(ck) = yk\r\n k = k - 1\r\nEND DO\r\n\r\n! RETURN WITH IERR = NUMBER OF OFF-DIAGONAL NONZEROS IN U\r\n\r\nierr = iu(n+1) - iu(1)\r\nRETURN\r\n\r\n! ERROR RETURNS\r\n\r\n! ROW K OF A IS NULL\r\n\r\n170 ierr = -k\r\nRETURN\r\n\r\n! ROW K OF A HAS A DUPLICATE ENTRY\r\n\r\n180 ierr = -(n+k)\r\nRETURN\r\n\r\n! ZERO PIVOT IN ROW K\r\n\r\n190 ierr = -(2*n+k)\r\nRETURN\r\n\r\n! STORAGE FOR U EXCEEDED ON ROW K\r\n\r\n200 ierr = -(3*n+k)\r\nRETURN\r\nEND SUBROUTINE dnspiv\r\n\r\nEND MODULE Sparse_Gaussian\r\n", "meta": {"hexsha": "45f96d8de8691233ad58811423ff1e5d62ac81f8", "size": 12426, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/dspslv.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/dspslv.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/dspslv.f90", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 28.5, "max_line_length": 79, "alphanum_fraction": 0.5700144858, "num_tokens": 4282, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998823, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6852185920057096}} {"text": " SUBROUTINE savgol(c,np,nl,nr,ld,m)\r\n INTEGER ld,m,nl,np,nr,MMAX\r\n REAL c(np)\r\n PARAMETER (MMAX=6)\r\nCU USES lubksb,ludcmp\r\n INTEGER imj,ipj,j,k,kk,mm,indx(MMAX+1)\r\n REAL d,fac,sum,a(MMAX+1,MMAX+1),b(MMAX+1)\r\n if(np.lt.nl+nr+\r\n *1.or.nl.lt.0.or.nr.lt.0.or.ld.gt.m.or.m.gt.MMAX.or.nl+nr.lt.m) \r\n *pause 'bad args in savgol'\r\n do 14 ipj=0,2*m\r\n sum=0.\r\n if(ipj.eq.0)sum=1.\r\n do 11 k=1,nr\r\n sum=sum+float(k)**ipj\r\n11 continue\r\n do 12 k=1,nl\r\n sum=sum+float(-k)**ipj\r\n12 continue\r\n mm=min(ipj,2*m-ipj)\r\n do 13 imj=-mm,mm,2\r\n a(1+(ipj+imj)/2,1+(ipj-imj)/2)=sum\r\n13 continue\r\n14 continue\r\n call ludcmp(a,m+1,MMAX+1,indx,d)\r\n do 15 j=1,m+1\r\n b(j)=0.\r\n15 continue\r\n b(ld+1)=1.\r\n call lubksb(a,m+1,MMAX+1,indx,b)\r\n do 16 kk=1,np\r\n c(kk)=0.\r\n16 continue\r\n do 18 k=-nl,nr\r\n sum=b(1)\r\n fac=1.\r\n do 17 mm=1,m\r\n fac=fac*k\r\n sum=sum+b(mm+1)*fac\r\n17 continue\r\n kk=mod(np-k,np)+1\r\n c(kk)=sum\r\n18 continue\r\n return\r\n END\r\n", "meta": {"hexsha": "7b945bec5457164cf11702626b22487b496cc945", "size": 1162, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/savgol.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/savgol.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/savgol.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.2608695652, "max_line_length": 70, "alphanum_fraction": 0.4776247849, "num_tokens": 443, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107914029487, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6851559890397417}} {"text": "C\nC\t$Id: csgradg.f,v 1.5 2008-07-27 03:10:06 haley Exp $\nC \nC Copyright (C) 2000\nC University Corporation for Atmospheric Research\nC All Rights Reserved\nC\nC The use of this Software is governed by a License Agreement.\nC\n SUBROUTINE CSGRADG (N,X,Y,Z,F,LIST,LPTR,LEND,IFLGS,\n . SIGMA, NIT,DGMAX,GRAD, IER)\n INTEGER N, LIST(*), LPTR(*), LEND(N), IFLGS, NIT, IER\n DOUBLE PRECISION X(N), Y(N), Z(N), F(N), SIGMA(*),\n . DGMAX, GRAD(3,N)\nC\nC***********************************************************\nC\nC From SSRFPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 07/24/96\nC\nC Given a triangulation of N nodes on the unit sphere with\nC data values F at the nodes and tension factors SIGMA asso-\nC ciated with the arcs, this routine uses a global method\nC to compute estimated gradients at the nodes. The method\nC consists of minimizing a quadratic functional Q(G) over\nC the N-vector G of gradients, where Q approximates the\nC linearized curvature of the restriction to arcs of the\nC interpolatory function F defined by Function CSFVAL. The\nC restriction of F to an arc of the triangulation is the\nC Hermite interpolatory tension spline defined by the data\nC values and tangential gradient components at the endpoints\nC of the arc. Letting D1F(A) and D2F(A) denote first and\nC second derivatives of F with respect to a parameter A var-\nC ying along a triangulation arc, Q is the sum of integrals\nC over the arcs of D2F(A)**2 + ((SIGMA/L)*(D1F(A)-S))**2,\nC where L denotes arc-length, SIGMA is the appropriate ten-\nC sion factor, and S is the slope of the linear function of\nC A which interpolates the values of F at the endpoints of\nC the arc.\nC\nC Since the gradient at node K lies in the plane tangent\nC to the sphere surface at K, it is effectively defined by\nC only two components -- its X and Y components in the coor-\nC dinate system obtained by rotating K to the north pole.\nC Thus, the minimization problem corresponds to an order-2N\nC symmetric positive-definite sparse linear system which is\nC solved by a block Gauss-Seidel method with 2 by 2 blocks.\nC\nC An alternative method, Subroutine CSGRADL, computes a\nC local approximation to the gradient at a single node and,\nC although less efficient when all gradients are needed, was\nC found to be generally more accurate (in the case of uni-\nC form zero tension) when the nodal distribution is very\nC dense, varies greatly, or does not cover the sphere.\nC CSGRADG, on the other hand, was found to be slightly more\nC accurate on a uniform distribution of 514 nodes.\nC\nC On input:\nC\nC N = Number of nodes in the triangulation. N .GE. 3.\nC\nC X,Y,Z = Arrays of length N containing Cartesian\nC coordinates of the nodes. X(I)**2 + Y(I)**2\nC + Z(I)**2 = 1 for I = 1,...,N.\nC\nC F = Array of length N containing data values at the\nC nodes. F(I) is associated with (X(I),Y(I),Z(I))\nC for I = 1,...,N.\nC\nC LIST,LPTR,LEND = Data structure defining the trian-\nC gulation. Refer to STRIPACK\nC Subroutine CSTRMESH.\nC\nC IFLGS = Tension factor option:\nC IFLGS .LE. 0 if a single uniform tension\nC factor is to be used.\nC IFLGS .GE. 1 if variable tension is desired.\nC\nC SIGMA = Uniform tension factor (IFLGS .LE. 0), or\nC array containing tension factors associated\nC with arcs in one-to-one correspondence with\nC LIST entries (IFLGS .GE. 1). Refer to Sub-\nC programs CSGETSIG, CSSIG0, CSSIG1, and CSSIG2.\nC\nC The above parameters are not altered by this routine.\nC\nC NIT = Maximum number of Gauss-Seidel iterations to\nC be applied. This maximum will likely be a-\nC chieved if DGMAX is smaller than the machine\nC precision. NIT .GE. 0.\nC\nC DGMAX = Nonnegative convergence criterion. The\nC method is terminated when the maximum change\nC in a gradient between iterations is at most\nC DGMAX. The change in a gradient is taken to\nC be the Euclidean norm of the difference (in\nC the rotated coordinate system) relative to 1\nC plus the norm of the old gradient value.\nC\nC GRAD = 3 by N array whose columns contain initial\nC solution estimates (zero vectors are suffici-\nC ent). GRAD(I,J) contains component I of the\nC gradient at node J for I = 1,2,3 (X,Y,Z) and\nC J = 1,...,N. GRAD( ,J) must be orthogonal to\nC node J -- GRAD(1,J)*X(J) + GRAD(2,J)*Y(J) +\nC GRAD(3,J)*Z(J) = 0.\nC\nC On output:\nC\nC NIT = Number of Gauss-Seidel iterations employed.\nC\nC DGMAX = Maximum change in a gradient at the last\nC iteration.\nC\nC GRAD = Estimated gradients. See the description\nC under input parameters. GRAD is not changed\nC if IER = -1.\nC\nC IER = Error indicator:\nC IER = 0 if no errors were encountered and the\nC convergence criterion was achieved.\nC IER = 1 if no errors were encountered but con-\nC vergence was not achieved within NIT\nC iterations.\nC IER = -1 if N or DGMAX is outside its valid\nC range or NIT .LT. 0 on input.\nC IER = -2 if all nodes are collinear or the\nC triangulation is invalid.\nC IER = -3 if duplicate nodes were encountered.\nC\nC SSRFPACK modules required by CSGRADG: CSAPLYRT, CSCONSTR,\nC CSGRCOEF, CSSNHCSH\nC\nC Intrinsic functions called by CSGRADG: ATAN, MAX, SQRT\nC\nC***********************************************************\nC\n INTEGER IFL, ITER, J, K, LPJ, LPL, MAXIT, NN\n DOUBLE PRECISION ALFA, A11, A12, A22, CX, CY, D, DEN,\n . DET, DGK(3), DGMX, DG1, DG2, FK, G1,\n . G2, G3, R1, R2, SD, SIG, SINAL, SX,\n . SY, T, TOL, XK, YK, ZK, XJ, YJ, ZJ,\n . XS, YS\nC\nC Local parameters:\nC\nC ALFA = Arc-length between nodes K and J\nC A11,A12,A22 = Matrix components of the 2 by 2 block A*DG\nC = R where A is symmetric, (DG1,DG2,0) is\nC the change in the gradient at K, and R is\nC the residual\nC CX,CY = Components of a rotation mapping K to the\nC north pole (0,0,1)\nC D = Function of SIG computed by CSGRCOEF -- factor\nC in the order-2 system\nC DEN = ALFA*SINAL**2 -- factor in the 2 by 2 system\nC DET = Determinant of the order-2 matrix\nC DGK = Change in GRAD( ,K) from the previous esti-\nC mate in the original coordinate system\nC DGMX = Maximum change in a gradient between itera-\nC tions\nC DG1,DG2 = Solution of the 2 by 2 system -- first 2\nC components of DGK in the rotated coordi-\nC nate system\nC FK = Data value F(K)\nC G1,G2,G3 = Components of GRAD( ,K)\nC IFL = Local copy of IFLGS\nC ITER = Number of iterations used\nC J = Neighbor of K\nC K = DO-loop and node index\nC LPJ = LIST pointer of node J as a neighbor of K\nC LPL = Pointer to the last neighbor of K\nC MAXIT = Input value of NIT\nC NN = Local copy of N\nC R1,R2 = Components of the residual -- derivatives of\nC Q with respect to the components of the\nC gradient at node K\nC SD = Function of SIG computed by CSGRCOEF -- factor\nC in the order-2 system\nC SIG = Tension factor associated with ARC K-J\nC SINAL = SIN(ALFA) -- magnitude of the vector cross\nC product between nodes K and J\nC SX,SY = Components of a rotation mapping K to the\nC north pole (0,0,1)\nC T = Temporary storage for factors in the system\nC components\nC TOL = Local copy of DGMAX\nC XK,YK,ZK = Coordinates of node K -- X(K), Y(K), Z(K)\nC XJ,YJ,ZJ = Coordinates of node J in the rotated coor-\nC dinate system\nC XS,YS = XJ**2, YJ**2\nC\n NN = N\n IFL = IFLGS\n MAXIT = NIT\n TOL = DGMAX\nC\nC Test for errors in input, and initialize iteration count,\nC tension factor, and output value of DGMAX.\nC\n IF (NN .LT. 3 .OR. MAXIT .LT. 0 .OR. TOL .LT. 0.)\n . GO TO 11\n ITER = 0\n SIG = SIGMA(1)\n DGMX = 0.\nC\nC Top of iteration loop.\nC\n 1 IF (ITER .EQ. MAXIT) GO TO 4\n DGMX = 0.\nC\nC Loop on nodes.\nC\n DO 3 K = 1,NN\n XK = X(K)\n YK = Y(K)\n ZK = Z(K)\n FK = F(K)\n G1 = GRAD(1,K)\n G2 = GRAD(2,K)\n G3 = GRAD(3,K)\nC\nC Construct the rotation mapping node K to the north pole.\nC\n CALL CSCONSTR (XK,YK,ZK, CX,SX,CY,SY)\nC\nC Initialize components of the 2 by 2 system for the\nC change (DG1,DG2,0) in the K-th solution components\nC (symmetric matrix in A and residual in R).\nC\n A11 = 0.\n A12 = 0.\n A22 = 0.\n R1 = 0.\n R2 = 0.\nC\nC Loop on neighbors J of node K.\nC\n LPL = LEND(K)\n LPJ = LPL\n 2 LPJ = LPTR(LPJ)\n J = ABS(LIST(LPJ))\nC\nC Compute the coordinates of J in the rotated system.\nC\n T = SX*Y(J) + CX*Z(J)\n YJ = CX*Y(J) - SX*Z(J)\n ZJ = SY*X(J) + CY*T\n XJ = CY*X(J) - SY*T\nC\nC Compute arc-length ALFA between J and K, SINAL =\nC SIN(ALFA), and DEN = ALFA*SIN(ALFA)**2.\nC\n ALFA = 2.D0*ATAN(SQRT((1.D0-ZJ)/(1.D0+ZJ)))\n XS = XJ*XJ\n YS = YJ*YJ\n SINAL = SQRT(XS+YS)\n DEN = ALFA*(XS+YS)\nC\nC Test for coincident nodes and compute functions of SIG:\nC D = SIG*(SIG*COSHM-SINHM)/E and SD = SIG*SINHM/E for\nC E = SIG*SINH-2*COSHM.\nC\n IF (DEN .EQ. 0.) GO TO 13\n IF (IFL .GE. 1) SIG = SIGMA(LPJ)\n CALL CSGRCOEF (SIG, D,SD)\nC\nC Update the system components for node J.\nC\n T = D/DEN\n A11 = A11 + T*XS\n A12 = A12 + T*XJ*YJ\n A22 = A22 + T*YS\n T = (D+SD)*(FK-F(J))/(ALFA*ALFA*SINAL) +\n . ( D*(G1*X(J) + G2*Y(J) + G3*Z(J)) -\n . SD*(GRAD(1,J)*XK + GRAD(2,J)*YK +\n . GRAD(3,J)*ZK) )/DEN\n R1 = R1 - T*XJ\n R2 = R2 - T*YJ\nC\nC Bottom of loop on neighbors.\nC\n IF (LPJ .NE. LPL) GO TO 2\nC\nC Solve the 2 by 2 system and update DGMAX.\nC\n DET = A11*A22 - A12*A12\n IF (DET .EQ. 0. .OR. A11 .EQ. 0.) GO TO 12\n DG2 = (A11*R2 - A12*R1)/DET\n DG1 = (R1 - A12*DG2)/A11\n DGMX = MAX(DGMX,SQRT(DG1*DG1+DG2*DG2)/\n . (1.+SQRT(G1*G1+G2*G2+G3*G3)))\nC\nC Rotate (DG1,DG2,0) back to the original coordinate\nC system and update GRAD( ,K).\nC\n CALL CSAPLYRT (DG1,DG2,CX,SX,CY,SY, DGK)\n GRAD(1,K) = G1 + DGK(1)\n GRAD(2,K) = G2 + DGK(2)\n GRAD(3,K) = G3 + DGK(3)\n 3 CONTINUE\nC\nC Increment ITER and test for convergence.\nC\n ITER = ITER + 1\n IF (DGMX .GT. TOL) GO TO 1\nC\nC The method converged.\nC\n NIT = ITER\n DGMAX = DGMX\n IER = 0\n RETURN\nC\nC The method failed to converge within NIT iterations.\nC\n 4 DGMAX = DGMX\n IER = 1\n RETURN\nC\nC Invalid input parameter.\nC\n 11 NIT = 0\n DGMAX = 0.\n IER = -1\n RETURN\nC\nC Node K and its neighbors are collinear.\nC\n 12 NIT = 0\n DGMAX = DGMX\n IER = -2\n RETURN\nC\nC Nodes K and J coincide.\nC\n 13 NIT = 0\n DGMAX = DGMX\n IER = -3\n RETURN\n END\n", "meta": {"hexsha": "316e8e27ad0059f2c8f8d21843b97336b79a8c26", "size": 12145, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ngmath/src/lib/gridpack/cssgrid/csgradg.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "ngmath/src/lib/gridpack/cssgrid/csgradg.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "ngmath/src/lib/gridpack/cssgrid/csgradg.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 35.1011560694, "max_line_length": 71, "alphanum_fraction": 0.560312886, "num_tokens": 3653, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107861416414, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6851559851934179}} {"text": " \nC$Procedure ELLTOF ( Elliptic time of flight )\n \n SUBROUTINE ELLTOF ( MA, ECC, E )\n \nC$ Abstract\nC\nC Solve the time of flight equation MA = E - e sin(E) for the\nC elliptic eccentric anomaly E, given mean anomaly the MA and\nC the eccentricity ECC.\nC\nC$ Disclaimer\nC\nC THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE\nC CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.\nC GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE\nC ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE\nC PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED \"AS-IS\"\nC TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY\nC WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A\nC PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC\nC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE\nC SOFTWARE AND RELATED MATERIALS, HOWEVER USED.\nC\nC IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA\nC BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT\nC LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,\nC INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,\nC REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE\nC REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.\nC\nC RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF\nC THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY\nC CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE\nC ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.\nC\nC$ Required_Reading\nC\nC None.\nC\nC$ Keywords\nC\nC CONIC\nC\nC$ Declarations\n \n DOUBLE PRECISION MA\n DOUBLE PRECISION ECC\n DOUBLE PRECISION E\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC MA I Mean anomaly at epoch.\nC ECC I Eccentricity.\nC E O Elliptic eccentric anomaly.\nC\nC$ Detailed_Input\nC\nC MA is the elliptic mean anomaly of an orbiting body at\nC some epoch t,\nC\nC 3 1/2\nC MA = (t-T)(mu/a )\nC\nC where T is the time of periapsis passage, a is\nC the semi-major axis of the orbit, and mu is the\nC gravitational parameter of the primary body.\nC\nC ECC is the eccentricity of the orbit.\nC\nC$ Detailed_Output\nC\nC E is the corresponding eccentric anomaly. This is the\nC solution to the time of flight equation\nC\nC MA = E - e sin(E)\nC\nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC 1) If the eccentricity (ECC) is outside the range [0,1),\nC the error 'SPICE(WRONGCONIC)' is signalled.\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC Iterate to solve\nC\nC f(E,MA,e) = E - e sin(E) - MA = 0\nC\nC$ Examples\nC\nC ELLTOF, HYPTOF, and PARTOF are used by CONICS.\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Literature_References\nC\nC [1] Roger Bate, Fundamentals of Astrodynamics, Dover, 1971.\nC\nC [2] Ed Ng, \"A General Algorithm for the Solution of Kepler's\nC Equation for Elliptic Orbits\", Cel. Mech. 20, 243, 1979.\nC\nC$ Author_and_Institution\nC\nC K.R. Gehringer (JPL)\nC I.M. Underwood (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 1.1.0, 29-FEB-1996 (KRG)\nC\nC The declaration for the SPICELIB function PI is now\nC preceded by an EXTERNAL statement declaring PI to be an \nC external function. This removes a conflict with any\nC compilers that have a PI intrinsic function.\nC\nC- SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)\nC\nC Comment section for permuted index source lines was added\nC following the header.\nC\nC- SPICELIB Version 1.0.0, 31-JAN-1990 (IMU)\nC\nC-&\n \nC$ Index_Entries\nC\nC elliptic time of flight\nC\nC-&\n \nC$ Revisions\nC\nC- Beta Version 1.1.0, 8-JAN-1989 (IMU)\nC\nC The routine now verifies that the eccentricity is in the\nC proper range---[0,1)---before proceeding.\nC\nC-&\n \nC\nC SPICELIB functions\nC\n LOGICAL RETURN\n DOUBLE PRECISION DCBRT\n DOUBLE PRECISION HALFPI\n EXTERNAL PI\n DOUBLE PRECISION PI\n DOUBLE PRECISION TWOPI\n \nC\nC Local parameters\nC\n DOUBLE PRECISION TOL\n PARAMETER ( TOL = 1.D-15 )\n \nC\nC Local variables\nC\n DOUBLE PRECISION M\n DOUBLE PRECISION MPRIME\n INTEGER N\n \n DOUBLE PRECISION M0\n DOUBLE PRECISION A\n DOUBLE PRECISION B\n DOUBLE PRECISION Q\n DOUBLE PRECISION R\n DOUBLE PRECISION QR\n DOUBLE PRECISION Y\n \n DOUBLE PRECISION FN\n DOUBLE PRECISION DERIV\n DOUBLE PRECISION DERIV2\n DOUBLE PRECISION CHANGE\n \n \n \nC\nC Standard SPICE error handling.\nC\n IF ( RETURN () ) THEN\n RETURN\n ELSE\n CALL CHKIN ( 'ELLTOF' )\n END IF\n \n IF ( ECC .LT. 0.D0 .OR. ECC .GE. 1.D0 ) THEN\n CALL SIGERR ( 'SPICE(WRONGCONIC)' )\n CALL CHKOUT ( 'ELLTOF' )\n RETURN\n END IF\n \n \nC\nC For reasons of numerical stability, we would like to restrict\nC our solution to the interval [0,pi]. Because E, M, and sin E\nC are always positive or negative together, we can pretend that M\nC is positive and adjust the sign of the result. And for M, E > pi,\nC we can define\nC\nC M = 2n pi + M' and E = 2n pi + E'\nC\nC where M' and E' are in the interval [-pi,pi]. Solving for E'\nC gives us E.\nC\nC So, we begin by reducing the input mean anomaly to [0,pi].\nC\n M = ABS ( MA )\n \n IF ( M .GT. PI() ) THEN\n N = INT ( (M-PI()) / TWOPI() ) + 1\n MPRIME = M - N * TWOPI()\n ELSE\n N = 0\n MPRIME = M\n END IF\n \n M = ABS ( MPRIME )\n \nC\nC The convergence of the iterative scheme below depends on a good\nC initial estimate for E.\nC\nC For small eccentricity, the initial estimate E = M is sufficient.\nC However, as the eccentricity increases, so does the number of\nC iterations required for convergence. For sufficiently large\nC eccentricity, this estimate leads to divergence.\nC\nC Ng [2] notes that the function y(M,e)\nC\nC E - M\nC ------- = sin(e y + M)\nC e\nC\nC increases and decreases monotonically when M is in the ranges\nC [0,M0] and [m0,pi], respectively.\nC\nC When M0 < M < pi, where M0 = (pi/2) - e, the cubic\nC - -\nC\nC pi - M 2 pi - M pi - M\nC B(M,e) = 1 - (1 - -------) (1 + 2 ------- - -------)\nC pi - M0 pi - M0 1 + e\nC\nC provides a good initial estimate of y for all values of e.\nC\nC\n M0 = HALFPI() - ECC\n \n IF ( M .GE. M0 ) THEN\n \n A = PI() - M\n B = PI() - M0\n \n Y = 1.D0 - (1.D0 - A/B)**2 * (1.D0 + 2.D0*A/B - A/(1.D0+ECC))\n E = ECC * SIN(ECC*Y + M) + M\n \nC\nC The situation is a little more troublesome, however, when M < M0.\nC For small eccentricity, the cubic\nC\nC 2\nC A(M,e) = 1 - (1 - M/M0) (1 + 2M/M0 - M/(1-e) )\nC\nC gives a reasonable first estimate of y. However, as e -> 1,\nC successive approximations of the form\nC\nC k k\nC C (M,e) = 1 - (-1) (1 - M/M0)\nC k\nC\nC are used, where k = 4 for e > 0.7, and k = 8 for e > 0.85.\nC\nC For high eccentricity (e > 0.96) and low mean anomaly (M < 0.05),\nC these successive approximations eventually fail. Fortunately, in\nC just these cases, the cubic\nC\nC 3 2 1/3 3 2 1/3\nC D(M,e) = [r + (q + r )] + [r - (q + r )]\nC\nC where\nC\nC r = 3M/e, q = (2/e)(1 - e)\nC\nC provides a reasonable estimate of E directly.\nC\nC\n ELSE IF ( ECC .LE. 0.7D0 ) THEN\n \n Y = 1.D0 - (1.D0 - M/M0)**2 * (1.D0 + 2.D0*M/M0 - M/(1.D0-ECC))\n E = ECC * SIN(ECC*Y + M) + M\n \n ELSE IF ( ECC .LE. 0.85D0 ) THEN\n \n Y = 1.D0 - (1.D0 - M/M0)**4\n E = ECC * SIN(ECC*Y + M) + M\n \n ELSE IF ( ECC .LE. 0.96D0 .OR. M .GT. 0.05D0 ) THEN\n \n Y = 1.D0 - (1.D0 - M/M0)**8\n E = ECC * SIN(ECC*Y + M) + M\n \n ELSE\n \n Q = (2.D0/ECC) * (1.D0 - ECC)\n R = 3.D0 * (M/ECC)\n QR = SQRT ( Q**3 + R**2 )\n \n E = DCBRT ( R + QR ) + DCBRT ( R - QR )\n \n END IF\n \n \nC\nC Use the Newton second-order method,\nC\nC 2\nC E = E - (f/f')*(1 + f*f''/2f' )\nC i+1 i\nC\nC where\nC\nC f = E - e sin(E) - M\nC f' = 1 - e cos(E)\nC f'' = e sin(E)\nC\n CHANGE = 1.D0\n \n DO WHILE ( ABS ( CHANGE ) .GT. TOL )\n \n FN = E - ECC * SIN(E) - M\n DERIV = 1.D0 - ECC * COS(E)\n DERIV2 = ECC * SIN(E)\n \n CHANGE = (FN/DERIV) * ( 1.D0 + (FN*DERIV2) / (2.D0*DERIV**2) )\n E = E - CHANGE\n \n END DO\n \nC\nC \"Unwrap\" E' into the actual value of E.\nC\n IF ( MPRIME .LT. 0 ) THEN\n E = -E\n END IF\n \n IF ( N .GT. 0 ) THEN\n E = E + N * TWOPI()\n END IF\n \n IF ( MA .LT. 0 ) THEN\n E = -E\n END IF\n \n \n CALL CHKOUT ( 'ELLTOF' )\n RETURN\n END\n", "meta": {"hexsha": "b182ad037394ca3ced424189122e185c57801d60", "size": 9577, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/elltof.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/elltof.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/elltof.f", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 25.8140161725, "max_line_length": 72, "alphanum_fraction": 0.5436984442, "num_tokens": 3028, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9372107878954105, "lm_q2_score": 0.7310585727705127, "lm_q1q2_score": 0.6851559809839465}} {"text": "*\n* Program factable - compute the factorial table\n*\n* Written by - Charles Severance 12Mar92\n*\n INTEGER I,N,FAC\n*\n* Print heading\n*\n PRINT 100\n PRINT 200\n*\n* Loop thruogh the numbers 1-10 and print out the factorials\n*\n DO N=1,10\n FAC = 1\n DO I=2,N\n FAC = FAC * I\n ENDDO\n PRINT 300,N,FAC\n ENDDO\n*\n100 FORMAT(' NUMBER FACTORIAL') \n200 FORMAT(' ------ ---------')\n300 FORMAT(6X,I6,6X,I10)\n END\n", "meta": {"hexsha": "3b0bc90f3add0135b89abd8212f50575dc0170f8", "size": 487, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "archive/2000-eecs280/examples/examples.ftn/programs/factable.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/factable.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/factable.f", "max_forks_repo_name": "yashajoshi/cc4e", "max_forks_repo_head_hexsha": "dd166f7e70d4111945054b8cb39483eb8dfb591b", "max_forks_repo_licenses": ["Apache-2.0", "CC-BY-4.0"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2020-12-27T19:57:10.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-10T13:01:36.000Z", "avg_line_length": 18.037037037, "max_line_length": 61, "alphanum_fraction": 0.5277207392, "num_tokens": 153, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245870332531, "lm_q2_score": 0.8221891261650247, "lm_q1q2_score": 0.6851504140247004}} {"text": " SUBROUTINE linbcg(n,b,x,itol,tol,itmax,iter,err)\r\n INTEGER iter,itmax,itol,n,NMAX\r\n DOUBLE PRECISION err,tol,b(*),x(*),EPS\r\n PARAMETER (NMAX=1024,EPS=1.d-14)\r\nCU USES atimes,asolve,snrm\r\n INTEGER j\r\n DOUBLE PRECISION ak,akden,bk,bkden,bknum,bnrm,dxnrm,xnrm,zm1nrm,\r\n *znrm,p(NMAX),pp(NMAX),r(NMAX),rr(NMAX),z(NMAX),zz(NMAX),snrm\r\n iter=0\r\n call atimes(n,x,r,0)\r\n do 11 j=1,n\r\n r(j)=b(j)-r(j)\r\n rr(j)=r(j)\r\n11 continue\r\nC call atimes(n,r,rr,0)\r\n if(itol.eq.1) then\r\n bnrm=snrm(n,b,itol)\r\n call asolve(n,r,z,0)\r\n else if (itol.eq.2) then\r\n call asolve(n,b,z,0)\r\n bnrm=snrm(n,z,itol)\r\n call asolve(n,r,z,0)\r\n else if (itol.eq.3.or.itol.eq.4) then\r\n call asolve(n,b,z,0)\r\n bnrm=snrm(n,z,itol)\r\n call asolve(n,r,z,0)\r\n znrm=snrm(n,z,itol)\r\n else\r\n pause 'illegal itol in linbcg'\r\n endif\r\n100 if (iter.le.itmax) then\r\n iter=iter+1\r\n call asolve(n,rr,zz,1)\r\n bknum=0.d0\r\n do 12 j=1,n\r\n bknum=bknum+z(j)*rr(j)\r\n12 continue\r\n if(iter.eq.1) then\r\n do 13 j=1,n\r\n p(j)=z(j)\r\n pp(j)=zz(j)\r\n13 continue\r\n else\r\n bk=bknum/bkden\r\n do 14 j=1,n\r\n p(j)=bk*p(j)+z(j)\r\n pp(j)=bk*pp(j)+zz(j)\r\n14 continue\r\n endif\r\n bkden=bknum\r\n call atimes(n,p,z,0)\r\n akden=0.d0\r\n do 15 j=1,n\r\n akden=akden+z(j)*pp(j)\r\n15 continue\r\n ak=bknum/akden\r\n call atimes(n,pp,zz,1)\r\n do 16 j=1,n\r\n x(j)=x(j)+ak*p(j)\r\n r(j)=r(j)-ak*z(j)\r\n rr(j)=rr(j)-ak*zz(j)\r\n16 continue\r\n call asolve(n,r,z,0)\r\n if(itol.eq.1)then\r\n err=snrm(n,r,itol)/bnrm\r\n else if(itol.eq.2)then\r\n err=snrm(n,z,itol)/bnrm\r\n else if(itol.eq.3.or.itol.eq.4)then\r\n zm1nrm=znrm\r\n znrm=snrm(n,z,itol)\r\n if(abs(zm1nrm-znrm).gt.EPS*znrm) then\r\n dxnrm=abs(ak)*snrm(n,p,itol)\r\n err=znrm/abs(zm1nrm-znrm)*dxnrm\r\n else\r\n err=znrm/bnrm\r\n goto 100\r\n endif\r\n xnrm=snrm(n,x,itol)\r\n if(err.le.0.5d0*xnrm) then\r\n err=err/xnrm\r\n else\r\n err=znrm/bnrm\r\n goto 100\r\n endif\r\n endif\r\n write (*,*) ' iter=',iter,' err=',err\r\n if(err.gt.tol) goto 100\r\n endif\r\n return\r\n END\r\n", "meta": {"hexsha": "806ef9a9667238efe448c3f4854349c6f51761c3", "size": 2524, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/linbcg.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/linbcg.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/linbcg.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.7362637363, "max_line_length": 71, "alphanum_fraction": 0.469889065, "num_tokens": 879, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218434359675, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6851428204826555}} {"text": "c------------------------------------------------------------------\nc Calculates all first/second x/t derivative of metric functions\nc------------------------------------------------------------------\n subroutine calcall ( \n & Gxx_a , Gxx , Gxx_r,\n & Gyy_a , Gyy , Gyy_r,\n & Gzz_a , Gzz , Gzz_r,\n & alpha_a, alpha, alpha_r,\n & beta_a , beta , beta_r,\n & Gxx_x, Gxx_t, Gxx_xt, Gxx_tt, Gxx_xx,\n & Gyy_x, Gyy_t, Gyy_xt, Gyy_tt, Gyy_xx,\n & Gzz_x, Gzz_t, Gzz_xt, Gzz_tt, Gzz_xx,\n & alpha_x, alpha_t, alpha_xt, alpha_tt, alpha_xx,\n & beta_x , beta_t , beta_xt , beta_tt , beta_xx,\n & n, dx, dt\n & )\n implicit none\n integer n\n real*8 dx, dt\n real*8 Gxx_a(1:n), Gxx(1:n), Gxx_r(1:n)\n real*8 Gyy_a(1:n), Gyy(1:n), Gyy_r(1:n)\n real*8 Gzz_a(1:n), Gzz(1:n), Gzz_r(1:n)\n \n real*8 alpha_a(1:n), alpha(1:n), alpha_r(1:n)\n \n real*8 beta_a(1:n), beta(1:n), beta_r(1:n)\n \n real*8 Gxx_x (1:n), Gyy_x (1:n), Gzz_x (1:n)\n real*8 Gxx_t (1:n), Gyy_t (1:n), Gzz_t (1:n)\n real*8 Gxx_xt(1:n), Gyy_xt(1:n), Gzz_xt(1:n)\n real*8 Gxx_tt(1:n), Gyy_tt(1:n), Gzz_tt(1:n) \n real*8 Gxx_xx(1:n), Gyy_xx(1:n), Gzz_xx(1:n)\n \n real*8 alpha_x (1:n), beta_x (1:n)\n real*8 alpha_t (1:n), beta_t (1:n)\n real*8 alpha_xx(1:n), beta_xx(1:n)\n real*8 alpha_xt(1:n), beta_xt(1:n)\n real*8 alpha_tt(1:n), beta_tt(1:n) \n \n call calcallDiv(Gxx_a, Gxx , Gxx_r , \n & dx , dt, n ,\n & Gxx_x, Gxx_t, Gxx_xx, Gxx_tt , Gxx_xt)\n \n call calcallDiv(Gyy_a, Gyy , Gyy_r , \n & dx , dt, n ,\n & Gyy_x, Gyy_t, Gyy_xx, Gyy_tt , Gyy_xt)\n\n call calcallDiv(Gzz_a, Gzz , Gzz_r , \n & dx , dt, n ,\n & Gzz_x, Gzz_t, Gzz_xx, Gzz_tt , Gzz_xt)\n\n call calcallDiv(alpha_a, alpha , alpha_r , \n & dx , dt, n ,\n & alpha_x, alpha_t, alpha_xx, alpha_tt \n & , alpha_xt)\n call calcallDiv(beta_a, beta , beta_r , \n & dx , dt, n ,\n & beta_x, beta_t, beta_xx, beta_tt \n & , beta_xt)\n \n return\n end\n\nc-----------------------------------------------------------------\nc calculates all kind of derivative required in our problem for \nc a given grid function\nc all O(h^2) approximation\nc----------------------------------------------------------------\n subroutine calcallDiv(f_a, f , f_r , \n & dx , dt, n ,\n & f_x, f_t, f_xx, f_tt , f_xt)\n\n implicit none\n \n integer n\n real*8 f_a(1:n), f(1:n), f_r(1:n)\n real*8 dx, dt\n real*8 f_x(1:n), f_t(1:n), f_xx(1:n), f_tt(1:n), f_xt(1:n)\n \n call Divx(f, dx, n, f_x)\n call Divt(f_a, f_r, dt, n, f_t) \n call Divtt(f_a, f, f_r, dt, n, f_tt)\n call Divxx(f, dx, n, f_xx)\n call Divxt(f_a, f_r, dx, dt, n, f_xt)\n\n return\n\n end\nc-----------------------------------------------------------------\nc calculates x derivative of f using left and right values O(h^2)\nc assuming periodic boundry condition\nc-----------------------------------------------------------------\n\n subroutine Divx(f, dx, n, f_x)\n \n implicit none\n \n integer n, i\n real*8 f(1:n), f_x(1:n)\n real*8 dx \n\n do i=2, n-1\n f_x(i) = ( f(i+1) - f(i-1) ) / (2*dx)\n enddo \n\n i = 1\n f_x(i) = ( f(i+1) - f(n-1) ) / (2*dx)\n\n i = n\n f_x(i) = ( f(1+1) - f(i-1) ) / (2*dx)\n\n return\n \n end \nc-------------------------------------------------------------------\nc calculates time derivative of f using advanced and retarded values\nc O(h^2) approximation\nc-------------------------------------------------------------------\n\n subroutine Divt(f_a, f_r, dt, n, f_t)\n\n implicit none\n integer n, i\n real*8 dt\n real*8 f_a(1:n), f_r(1:n), f_t(1:n)\n\n do i=1, n\n f_t(i) = ( f_a(i) - f_r(i) ) / (2*dt)\n enddo\n \n return\n\n end\nc---------------------------------------------------------------------\nc calculates second time derivative of f using advanced and retarded\nc and current values. O(h^2) approximation\nc---------------------------------------------------------------------\n\n\n subroutine Divtt(f_a, f, f_r, dt, n, f_tt)\n\n implicit none\n\n real*8 dt\n integer n, i\n real*8 f_a(1:n), f(1:n), f_r(1:n), f_tt(1:n)\n \n do i=1, n\n f_tt(i) = ( f_a(i) - 2*f(i) + f_r(i) ) / (dt*dt)\n enddo\n \n return\n\n end\nc----------------------------------------------------------------\nc calculates second x derivative of f using left and right values\nc O(h^2) approximation \nc----------------------------------------------------------------\n\n subroutine Divxx(f, dx, n, f_xx)\n\n implicit none\n integer n, i\n real*8 dx\n real*8 f(1:n), f_xx(1:n)\n \n do i=2, n-1\n f_xx(i) = ( f(i+1) - 2*f(i) + f(i-1) ) / (dx*dx)\n enddo\n\n i = 1\n f_xx(i) = ( f(i+1) - 2*f(i) + f(n-1) ) / (dx*dx)\n\n i = n\n f_xx(i) = ( f(1+1) - 2*f(i) + f(i-1) ) / (dx*dx)\n\n return\n\n end\nc--------------------------------------------------------------\nc calculates mixed x-t derivative of f using a/r values\nc O(h^2) approximation\nc--------------------------------------------------------------\n\n subroutine Divxt(f_a, f_r, dx, dt, n, f_xt)\n\n implicit none\n integer n, i\n real*8 dx, dt\n real*8 f_a(1:n), f_r(1:n), f_xt(1:n)\n\n do i=2, n-1\n f_xt(i) = ( f_a(i+1) - f_a(i-1) - f_r(i+1) + f_r(i-1) )\n & / (4*dt*dx)\n enddo\n\n i = 1\n f_xt(i) = ( f_a(i+1) - f_a(n-1) - f_r(i+1) + f_r(n-1) )\n & / (4*dt*dx)\n\n i = n \n f_xt(i) = ( f_a(1+1) - f_a(i-1) - f_r(1+1) + f_r(i-1) )\n & / (4*dt*dx)\n\n return\n \n end\n", "meta": {"hexsha": "de5012b0f39f98b2cea400578afa0e4545f7b2b4", "size": 6724, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/human/Divcalc.f", "max_stars_repo_name": "rmanak/bssn_spher", "max_stars_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/human/Divcalc.f", "max_issues_repo_name": "rmanak/bssn_spher", "max_issues_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/human/Divcalc.f", "max_forks_repo_name": "rmanak/bssn_spher", "max_forks_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.3269230769, "max_line_length": 72, "alphanum_fraction": 0.3670434265, "num_tokens": 1967, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218412907381, "lm_q2_score": 0.7431680086124812, "lm_q1q2_score": 0.6851428188883898}} {"text": "c\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc . .\nc . copyright (c) 1998 by UCAR .\nc . .\nc . University Corporation for Atmospheric Research .\nc . .\nc . all rights reserved .\nc . .\nc . .\nc . SPHEREPACK .\nc . .\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc\nc\nc\nc ... file advec.f\nc\nc program advec solves the time-dependent linear advection \nc equation for geopotential phi using the SPHEREPACK software\nc\nc d(phi)/dt = -(u,v) DOT gradient(phi)\nc\nc = -(u*gdphl + v*gdpht)\nc\nc ... required files\nc\nc gradgc.f,shagc.f,shsgc.f,vhsgc.f,sphcom.f hrfft.f,gaqd.f\nc\nc\nc definitions:\nc\nc\nc nlat number of gaussian latitudes excluding poles\nc nlon number of distinct longitudes\nc omega rotation rate of earth in radians per second\nc alpha angle between axis of rotation and the coordinate\nc axis\nc beta latitude of the cosine bell\nc aa radius of earth in meters\nc ncycle cycle number\nc time model time in seconds\nc dt time step\nc lambda longitude\nc theta latitude\nc\nc the first dimension of the following two dimensional arrays\nc corresponds to the latitude index with values i=1,...,nlat\nc where i=1 is the northern most gaussian point thetag(i)\nc and i=nlat is the southern most gaussian point thetag(nlat).\nc the second dimension is longitude with values j=1,...,nlon\nc where j=1 corresponds to zero longitude and j=nlon corresponds\nc to 2pi minus 2pi/nlon.\nc\nc\nc thetag(i) vector of gaussian points on the full sphere which\nc have north to south orientation as i=1,...,nlat\nc\nc u(i,j) east longitudinal velocity component\nc v(i,j) latitudinal velocity component\nc\nc phi(i,j) the geopotential at t = time\nc\nc phnew(i,j) the geopotential at t=time+dt\nc\nc phold(i,j) the geopotential at t=time-dt\nc\nc gdphl(i,j) the longitudinal derivative component of\nc the gradient of phi\nc\nc gdphl = 1/(cos(theta))*d(phi)/dlambda\n\nc\nc gdpht(i,j) the latitudinal derivative component of\nc the gradient of phi\nc\nc gdpht = d(phi)/dtheta\n\nc\nc the following two dimensional arrays are nonzero in the triangle\nc n=1,...,nlat and m less than or equal to n.\nc\nc ar(m,n),br(m,n) spectral coefficients of phi\nc\n program advec\nc\nc set grid size with parameter statements\nc\n integer nnlat,nnlon,nn15,llwork,lldwork,llvhsgc,llshagc\n integer nlat,nlon,lwork,ldwork,lvhsgc,lshagc\n\nc parameter (nnlat=12,nnlon=23,ddt=1200.)\n parameter (nnlat=23,nnlon=45,ddt=600.)\nc parameter (nnlat=45,nnlon=90,ddt=300.)\nc\nc set saved and unsaved work space lengths in terms of nnlat,nnlon\nc (see documentation for shagc,vhsgc,vhsgci,gradgc for estimates)\nc\n parameter (nn15=nnlon+15)\n parameter(llwork=4*nnlat*nnlon+2*nnlat*(nnlat+1))\n parameter (lldwork = 2*nnlat*(nnlat+1)+1 )\n parameter (llvhsgc = 7*nnlat*nnlat+nnlon+15)\n parameter (llshagc = 5*nnlat*nnlat + nnlon+15)\nc\nc dimension arrays\nc\n real u(nnlat,nnlon),v(nnlat,nnlon)\n real phold(nnlat,nnlon),phnew(nnlat,nnlon),phi(nnlat,nnlon)\n real pexact(nnlat,nnlon)\n real dpdt(nnlat,nnlon)\n real gdphl(nnlat,nnlon),gdpht(nnlat,nnlon), work(llwork)\n double precision dwork(lldwork)\n real wshagc(llshagc),wvhsgc(llvhsgc),wshsgc(llshagc)\n real ar(nnlat,nnlat),br(nnlat,nnlat)\n real thetag(nnlat),colat(nnlat)\n double precision dtheta(nnlat),dwts(nnlat)\nc\nc set constants\nc\n pi = 4.0*atan(1.0)\n omega = (pi+pi)/(12.*24.*3600.)\n p0 = 1000.\n re = 1.0/3.0\n hzero = 1000. \n alphad = 60.\n alpha = pi*alphad/180.\n beta = pi/6.\nc\nc set one array and no equatorial symmetry\nc\n nt = 1\n isym = 0\nc\nc set time step depending on resolution\nc\n dt = ddt\n tdt = dt+dt\nc\nc set work space length arguments\nc\n lwork = llwork\n ldwork = lldwork\n lshagc = llshagc\n lvhsgc = llvhsgc\nc\nc set grid size arguments\nc\n nlat = nnlat\n nlon = nnlon\nc\nc compute nlat latitudinal gaussian points in thetag with\nc north to south orientation using gaqd from SPHEREPACK\nc\n call gaqd(nlat,dtheta,dwts,DWORK,ldwork,ier)\n do i=1,nlat\n\tthetag(i) = 0.5*pi- dtheta(i)\n\tcolat(i) = dtheta(i)\n end do\nc\nc preset saved work spaces for gradgc and shagc and shsgc\nc\n call vhsgci(nlat,nlon,wvhsgc,lvhsgc,dwork,ldwork,ierror)\n if(ierror .ne. 0) write(*,10) ierror\n 10 format(' error in vsgci = ',i5)\n call shagci(nlat,nlon,wshagc,lshagc,dwork,ldwork,ierror)\n if(ierror .ne. 0) write(*,20) ierror\n 20 format(' error in shagci = ',i5)\n call shsgci(nlat,nlon,wshsgc,lshagc,dwork,ldwork,ierror)\n if(ierror .ne. 0) write(*,21) ierror\n 21 format(' error in shsgci = ',i5)\nc\nc set vector velocities and cosine bell in geopotential\nc\n ca = cos(alpha)\n sa = sin(alpha)\n dlon = (pi+pi)/nlon\n do j=1,nlon\n xlm = (j-1)*dlon\n sl = sin(xlm)\n cl = cos(xlm)\n do i=1,nlat\n st = cos(colat(i))\n ct = sin(colat(I))\n sth = ca*st+sa*ct*cl\n cthclh = ca*ct*cl-sa*st\n cthslh = ct*sl\n xlhat = atanxy(cthclh,cthslh)\n clh = cos(xlhat)\n slh = sin(xlhat)\n cth = clh*cthclh+slh*cthslh\n uhat = omega*cth\n u(i,j) = (ca*sl*slh+cl*clh)*uhat\n v(i,j) = (ca*st*cl*slh-st*sl*clh+sa*ct*slh)*uhat\n end do\n end do\nc\nc compute geopotential at t=-dt in phold and at t=0.0 in phi\nc to start up leapfrog scheme\nc\n\tcall gpot(-dt,alpha,beta,omega,hzero,re,nlat,nlon,\n + nlat,colat,phold)\n\tcall gpot(0.,alpha,beta,omega,hzero,re,nlat,nlon,\n + nlat,colat,phi)\nc\nc smooth geopotential at t=-dt and t=0. by synthesizing after analysis\nc\n\tcall shagc(nlat,nlon,isym,nt,phold,nlat,nlon,ar,br,nlat,\n + nlat,wshagc,lshagc,work,lwork,ierror)\n\tif (ierror .ne.0) write(*,26) ierror\n\tcall shsgc(nlat,nlon,isym,nt,phold,nlat,nlon,ar,br,nlat,\n + nlat,wshsgc,lshagc,work,lwork,ierror)\n\tif (ierror .ne.0) write(*,28) ierror\n\tcall shagc(nlat,nlon,isym,nt,phi,nlat,nlon,ar,br,nlat,\n + nlat,wshagc,lshagc,work,lwork,ierror)\n\tif (ierror .ne.0) write(*,26) ierror\n\tcall shsgc(nlat,nlon,isym,nt,phi,nlat,nlon,ar,br,nlat,\n + nlat,wshsgc,lshagc,work,lwork,ierror)\n\tif (ierror .ne.0) write(*,28) ierror\n 28 format(' ierror in shsgc = ',i5)\nc\nc compute l2 and max norms of geopotential at t=0.\nc\n\tp2 = 0.0\n\tpmax = 0.0\n\tdo j=1,nlon\n\t do i=1,nlat\n\t pmax = amax1(abs(phi(i,j)),pmax)\n\t p2 = p2 + phi(i,j)**2\n\t end do\n\tend do\n\tp2 = sqrt(p2)\nc\nc set number of time steps for 12 days\nc (time to circumvent the earth)\nc\n ntime = int((12.*24.*3600.)/dt+0.5)\n mprint = ntime/12\n time = 0.0\n ncycle = 0\n do k=1,ntime+1\nc\nc compute harmonic coefficients for phi at current time\nc\n\tcall shagc(nlat,nlon,isym,nt,phi,nlat,nlon,ar,br,nlat,\n + nlat,wshagc,lshagc,work,lwork,ierror)\n\tif (ierror .ne.0) write(*,26) ierror\n 26 format(' ierror in shagc = ',i5)\nc\nc compute gradient of phi at current time\nc\n\tcall gradgc(nlat,nlon,isym,nt,gdpht,gdphl,nlat,nlon,ar,br,\n + nlat,nlat,wvhsgc,lvhsgc,work,lwork,ierror)\n\tif (ierror .ne.0) write(*,27) ierror\n 27 format(' ierror in gradgc = ',i5)\nc\nc compute the time derivative of phi, note that the sign\nc of the last term is positive because the gradient is\nC computed with respect to colatitude rather than latitude.\nc\n\tdo j=1,nlon\n\t do i=1,nlat\n\t dpdt(i,j) = -u(i,j)*gdphl(i,j) + v(i,j)*gdpht(i,j)\n\t end do\n\tend do\nc\n if (mod(ncycle,mprint) .eq. 0) then\nc\nc write variables\nc\n err2 = 0.0\n errm = 0.0\n call gpot(time,alpha,beta,omega,hzero,re,nlat,nlon,nlat,\n + colat,pexact)\n do j=1,nlon\n\tdo i=1,nlat\n\t err2 = err2 + (pexact(i,j)-phi(i,j))**2\n\t errm = amax1(abs(pexact(i,j)-phi(i,j)),errm)\n\tend do\n end do\n errm = errm/pmax\n err2 = sqrt(err2)/p2\n htime = time/3600.\n write(*,390) ncycle,htime,dt,nlat,nlon,omega,hzero,\n 1 alphad,errm,err2\n 390 format(//' advecting cosine bell, test case 2',/\n 1 ,' cycle number ',i10\n 2 ,' model time in hours ',f10.2/\n 3 ,' time step in seconds ',f10.0\n 4 ,' number of latitudes ',i10/\n 5 ,' number of longitudes ',i10\n 6 ,' rotation rate ',1pe15.6/\n 7 ,' mean height ',1pe15.6\n 8 ,' tilt angle ',0pf10.2/\n 9 ,' max geopot. error ',1pe15.6\n 1 ,' RMS geopot. error ',1pe15.6)\n\n end if\n\ttime = time + dt\n\tncycle = ncycle+1\nc\nc update phold,phi for next time step\nc\n\tdo j=1,nlon\n\t do i=1,nlat\n\t phnew(i,j) = phold(i,j) + tdt*dpdt(i,j)\n\t phold(i,j) = phi(i,j)\n\t phi(i,j) = phnew(i,j)\n\t end do\n\tend do\nc\nc end of time loop\nc\n end do\n end\n subroutine gpot(t,alpha,beta,omega,hzero,re,nlat,nlon,idim,\n + colat,h)\nc\nc computes advecting cosine bell on a tilted grid a time t.\nc \nc input parameters\nc\nc t time in seconds\nc\nc alpha tilt angle in radians\nc\nc beta colatitude of cosine bell in untilted coordinate\nc system in radians\nc\nc omega angular velocity in radians per second\nc\nc hzero maximum value of cosine bell\nc\nc re radius of support for cosine bell in radians\nc\nc nlat number of latitudes including the poles\nc\nc nlon number of distinct longitude lines\nc\nc idim first dimension of output array h\nc\nc colat vector of Gauss colatitude grid points\nc\nc output parameter\nc\nc h an nlat by nlon array containing the geopotential\nc\nc on a tilted grid\nc\n dimension h(idim,nlon),colat(nlat)\n real lambda,lambdc,lhat\n lambdc = omega*t\n call stoc(1.,beta,lambdc,xc,yc,zc)\n ca = cos(alpha)\n sa = sin(alpha)\n pi = 4.*atan(1.)\n tpi = pi+pi\n dlon = tpi/nlon\n do 10 j=1,nlon\n lambda = (j-1)*dlon\n cl = cos(lambda)\n sl = sin(lambda)\n do 10 i=1,nlat\n theta = colat(i)\n st = cos(theta)\n ct = sin(theta)\n sth = ca*st+sa*ct*cl\n cthclh = ca*ct*cl-sa*st\n cthslh = ct*sl\n lhat = atanxy(cthclh,cthslh)\n clh = cos(lhat)\n slh = sin(lhat)\n cth = clh*cthclh+slh*cthslh\n that = atanxy(sth,cth)\n call stoc(1.,that,lhat,x1,y1,z1)\n dist = sqrt((x1-xc)**2+(y1-yc)**2\n 1 +(z1-zc)**2)\n h(i,j) = 0.\n if(dist .ge. re) go to 10\n r = 2.*asin(dist/2.) \n if(r .ge. re) go to 10\n h(i,j) = hzero*.5*(cos(r*pi/re)+1.)\n 10 continue\n return\n end\n function atanxy(x,y)\n atanxy = 0.\n if(x.eq.0. .and. y.eq.0.) return\n atanxy = atan2(y,x)\n return\n end\n subroutine ctos(x,y,z,r,theta,phi)\n r1 = x*x+y*y\n if(r1 .ne. 0.) go to 10\n phi = 0.\n theta = 0.\n if(z .lt. 0.) theta = 4.*atan(1.)\n return\n 10 r = sqrt(r1+z*z)\n r1 = sqrt(r1) \n phi = atan2(y,x)\n theta = atan2(r1,z)\n return\n end\n subroutine stoc(r,theta,phi,x,y,z)\n st = sin(theta)\n x = r*st*cos(phi)\n y = r*st*sin(phi)\n z = r*cos(theta)\n return\n end\n", "meta": {"hexsha": "f09b2f7f407600383cd412bdbee331986207eba5", "size": 12180, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "install/spherepack3.2/src/advec.f", "max_stars_repo_name": "comp-physics/RBC3D", "max_stars_repo_head_hexsha": "2891a1e3b356e2cff0cfa74ba26d4aef3336641d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "install/spherepack3.2/src/advec.f", "max_issues_repo_name": "comp-physics/RBC3D", "max_issues_repo_head_hexsha": "2891a1e3b356e2cff0cfa74ba26d4aef3336641d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "install/spherepack3.2/src/advec.f", "max_forks_repo_name": "comp-physics/RBC3D", "max_forks_repo_head_hexsha": "2891a1e3b356e2cff0cfa74ba26d4aef3336641d", "max_forks_repo_licenses": ["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.6350364964, "max_line_length": 74, "alphanum_fraction": 0.5593596059, "num_tokens": 4095, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.921921841290738, "lm_q2_score": 0.743167997235783, "lm_q1q2_score": 0.6851428083999631}} {"text": "! { dg-do run }\n! PR 34566 - logical matmul used to give the wrong result.\n! We check this by running through every permutation in\n! multiplying two 3*3 matrices, and all permutations of multiplying\n! a 3-vector and a 3*3 matrices and checking against equivalence\n! with integer matrix multiply.\nprogram main\n implicit none\n integer, parameter :: ki=4\n integer, parameter :: dimen=3\n integer :: i, j, k\n real, dimension(dimen,dimen) :: r1, r2\n integer, dimension(dimen,dimen) :: m1, m2\n logical(kind=ki), dimension(dimen,dimen) :: l1, l2\n logical(kind=ki), dimension(dimen*dimen) :: laux\n logical(kind=ki), dimension(dimen) :: lv\n integer, dimension(dimen) :: iv\n\n do i=0,2**(dimen*dimen)-1\n forall (k=1:dimen*dimen)\n laux(k) = btest(i, k-1)\n end forall\n l1 = reshape(laux,shape(l1))\n m1 = ltoi(l1)\n\n ! Check matrix*matrix multiply\n do j=0,2**(dimen*dimen)-1\n forall (k=1:dimen*dimen)\n laux(k) = btest(i, k-1)\n end forall\n l2 = reshape(laux,shape(l2))\n m2 = ltoi(l2)\n if (any(matmul(l1,l2) .neqv. (matmul(m1,m2) /= 0))) then\n STOP 1\n end if\n end do\n\n ! Check vector*matrix and matrix*vector multiply.\n do j=0,2**dimen-1\n forall (k=1:dimen)\n lv(k) = btest(j, k-1)\n end forall\n iv = ltoi(lv)\n if (any(matmul(lv,l1) .neqv. (matmul(iv,m1) /=0))) then\n STOP 2\n end if\n if (any(matmul(l1,lv) .neqv. (matmul(m1,iv) /= 0))) then\n STOP 3\n end if\n end do\n end do\n\ncontains\n elemental function ltoi(v)\n implicit none\n integer :: ltoi\n real :: rtoi\n logical(kind=4), intent(in) :: v\n if (v) then\n ltoi = 1\n else\n ltoi = 0\n end if\n end function ltoi\n\nend program main\n", "meta": {"hexsha": "348cae623832160d6a15e13bdfd281ac74110d38", "size": 1788, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/matmul_6.f90", "max_stars_repo_name": "brugger1/testsuite", "max_stars_repo_head_hexsha": "9b504db668cdeaf7c561f15b76c95d05bfdd1517", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2019-02-12T18:20:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-09T19:46:19.000Z", "max_issues_repo_path": "validation_tests/llvm/f18/gfortran.dg/matmul_6.f90", "max_issues_repo_name": "brugger1/testsuite", "max_issues_repo_head_hexsha": "9b504db668cdeaf7c561f15b76c95d05bfdd1517", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 24, "max_issues_repo_issues_event_min_datetime": "2020-08-31T22:05:07.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T18:30:03.000Z", "max_forks_repo_path": "validation_tests/llvm/f18/gfortran.dg/matmul_6.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": 26.6865671642, "max_line_length": 67, "alphanum_fraction": 0.5878076063, "num_tokens": 601, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473813156295, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.6850618884453623}} {"text": "!---------------------------------------------------------------------- \n!---------------------------------------------------------------------- \n! opt : A model algebraic optimization problem\n!---------------------------------------------------------------------- \n!---------------------------------------------------------------------- \n\n SUBROUTINE FUNC(NDIM,U,ICP,PAR,IJAC,F,DFDU,DFDP) \n! ---------- ---- \n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: NDIM, ICP(*), IJAC\n DOUBLE PRECISION, INTENT(IN) :: U(NDIM), PAR(*)\n DOUBLE PRECISION, INTENT(OUT) :: F(NDIM)\n DOUBLE PRECISION, INTENT(INOUT) :: DFDU(NDIM,NDIM), DFDP(NDIM,*)\n\n DOUBLE PRECISION X1,X2,X3,X4,X5\n\n X1=U(1) \n X2=PAR(1) \n X3=PAR(2) \n X4=PAR(3) \n X5=PAR(4) \n\n F(1)=X1*X1 + X2*X2 + X3*X3 + X4*X4 + X5*X5 - 1 \n\n IF(IJAC.EQ.0)RETURN \n\n DFDU(1,1)=2*X1 \n\n IF(IJAC.EQ.1)RETURN \n\n! *Parameter derivatives\n DFDP(1,1)=2*X2 \n DFDP(1,2)=2*X3 \n DFDP(1,3)=2*X4 \n DFDP(1,4)=2*X5 \n\n END SUBROUTINE FUNC\n\n SUBROUTINE STPNT(NDIM,U,PAR,T)\n! ---------- ----- \n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: NDIM\n DOUBLE PRECISION, INTENT(INOUT) :: U(NDIM),PAR(*)\n DOUBLE PRECISION, INTENT(IN) :: T\n\n DOUBLE PRECISION X1,X2,X3,X4,X5\n\n X1=1.0 \n X2=0.0 \n X3=0.0 \n X4=0.0 \n X5=0.0 \n\n U(1)=X1 \n\n PAR(1)=X2 \n PAR(2)=X3 \n PAR(3)=X4 \n PAR(4)=X5 \n\n END SUBROUTINE STPNT\n\n SUBROUTINE FOPT(NDIM,U,ICP,PAR,IJAC,FS,DFDU,DFDP) \n! ---------- ---- \n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: NDIM, ICP(*), IJAC\n DOUBLE PRECISION, INTENT(IN) :: U(NDIM), PAR(*)\n DOUBLE PRECISION, INTENT(OUT) :: FS\n DOUBLE PRECISION, INTENT(INOUT) :: DFDU(NDIM),DFDP(*)\n\n DOUBLE PRECISION X1,X2,X3,X4,X5\n\n X1=U(1) \n X2=PAR(1) \n X3=PAR(2) \n X4=PAR(3) \n X5=PAR(4) \n\n FS=X1 + X2 + X3 + X4 + X5 \n\n IF(IJAC.EQ.0)RETURN \n\n DFDU(1)=1.0 \n\n IF(IJAC.EQ.1)RETURN \n\n! *Parameter derivatives\n DFDP(1)=1.0 \n DFDP(2)=1.0 \n DFDP(3)=1.0 \n DFDP(4)=1.0 \n\n END SUBROUTINE FOPT\n\n SUBROUTINE BCND \n END SUBROUTINE BCND\n\n SUBROUTINE ICND \n END SUBROUTINE ICND\n\n SUBROUTINE PVLS\n END SUBROUTINE PVLS\n", "meta": {"hexsha": "a21b51a34c6a4a40e27b923d8da84debf3a3399f", "size": 2358, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "07p/demos/opt/opt.f90", "max_stars_repo_name": "st970703/AUTO07P-Update-to-Python-3.0", "max_stars_repo_head_hexsha": "fb2d2aebf2127fa914064d01ed62c0acb5f6421c", "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": "07p/demos/opt/opt.f90", "max_issues_repo_name": "st970703/AUTO07P-Update-to-Python-3.0", "max_issues_repo_head_hexsha": "fb2d2aebf2127fa914064d01ed62c0acb5f6421c", "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": "07p/demos/opt/opt.f90", "max_forks_repo_name": "st970703/AUTO07P-Update-to-Python-3.0", "max_forks_repo_head_hexsha": "fb2d2aebf2127fa914064d01ed62c0acb5f6421c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.2452830189, "max_line_length": 72, "alphanum_fraction": 0.4423240034, "num_tokens": 824, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473813156294, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.6850618884453622}} {"text": "DECIMAL\r\n\r\n: FIB ( n1 -- n2 )\r\n DUP 2 < IF\r\n DROP 1\r\n ELSE\r\n DUP 1- RECURSE\r\n SWAP 2 - RECURSE\r\n +\r\n THEN\r\n;\r\n\r\nT{ 22 FIB -> 28657 }T\r\n", "meta": {"hexsha": "406a34de7e1b5eb6f66320a3c7200bd816deddf7", "size": 150, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/forth/units/fib.f", "max_stars_repo_name": "happz/ducky", "max_stars_repo_head_hexsha": "1c6a875ca5a7a9cc71836bad5b7e45cc398d42ad", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-04-25T18:25:37.000Z", "max_stars_repo_stars_event_max_datetime": "2017-08-31T20:52:29.000Z", "max_issues_repo_path": "tests/forth/units/fib.f", "max_issues_repo_name": "happz/ducky-legacy", "max_issues_repo_head_hexsha": "1c6a875ca5a7a9cc71836bad5b7e45cc398d42ad", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 27, "max_issues_repo_issues_event_min_datetime": "2015-01-06T21:59:22.000Z", "max_issues_repo_issues_event_max_datetime": "2016-11-12T07:31:39.000Z", "max_forks_repo_path": "tests/forth/units/fib.f", "max_forks_repo_name": "happz/ducky-legacy", "max_forks_repo_head_hexsha": "1c6a875ca5a7a9cc71836bad5b7e45cc398d42ad", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2017-05-14T18:52:34.000Z", "max_forks_repo_forks_event_max_datetime": "2017-05-14T18:52:34.000Z", "avg_line_length": 10.7142857143, "max_line_length": 22, "alphanum_fraction": 0.4533333333, "num_tokens": 66, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.6850618788497059}} {"text": "program test_pic_3d\n\nuse mesh_fields_m\nuse poisson_3d_m\nuse output_m\nuse particles_m\nuse compute_rho_cic_m\nuse interpolation_cic_m\n\nimplicit none\n\ntype(mesh_t) :: mesh\ntype(fields_3d_t) :: fields\ntype(poisson_3d_t) :: poisson\ntype(particles_t) :: particles\n\ninteger, parameter :: nx = 64, ny = 64, nz = 4\ninteger(8), parameter :: nbpart = nx * ny * 100 \nreal(8) :: xmin, xmax, ymin, ymax, zmin, zmax\nreal(8) :: pi\ninteger :: i, j, k, m\nreal(8) :: x, y, z\nreal(8) :: dx, dy, dz\nreal(8) :: err_x, err_y, err_z\n\n\npi = 4d0 * atan(1d0)\n\nxmin = 0d0\nxmax = 18d0\nymin = 0d0\nymax = 18d0\nzmin = 0d0\nzmax = 1d0\n\ncall init_mesh( mesh, xmin, xmax, nx, ymin, ymax, ny, zmin, zmax, nz )\n\ndx = mesh%dx\ndy = mesh%dy\ndz = mesh%dz\n\ncall init_fields( fields, mesh )\n\ncall init_poisson( poisson, mesh)\n\nprint*, \" number of particles = \", nbpart\n\ncall init_particles_3d( particles, nbpart, mesh )\n\ncall compute_rho_cic( fields, particles)\n\nprint*, sum(fields%rho) * dx * dy * dz, nbpart * particles%w\n\ncall solve_poisson( poisson, fields)\n\ncall write_data( 1, fields)\n\ndo k = 1, nz+1\n z = (k-1) * dz\n do j = 1, ny+1\n y = (j-1) * dy\n do i = 1, nx+1\n x = (i-1) * dx\n fields%e(1,i,j,k) = sin(x)\n fields%e(2,i,j,k) = sin(y)\n fields%e(3,i,j,k) = sin(z)\n end do\n end do\nend do\n\ncall interpolate_eb_cic( particles, fields)\n\nerr_x = 0d0\nerr_y = 0d0\nerr_z = 0d0\n\ndo m = 1, nbpart\n x = (i-1) * mesh%dx\n err_x = err_x + abs(particles%e(1,m) - sin(particles%x(1,m)))\n err_y = err_y + abs(particles%e(2,m) - sin(particles%x(2,m)))\n err_z = err_z + abs(particles%e(3,m) - sin(particles%x(3,m)))\nend do\n\nprint*, err_x/nbpart, err_y/nbpart, err_z/nbpart\n\nend\n", "meta": {"hexsha": "9e3a690ec860c117dfe94cf6fc3f8189f50df225", "size": 1808, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/test_pic_3d.f90", "max_stars_repo_name": "JuliaVlasov/UAPIC.jl", "max_stars_repo_head_hexsha": "c11a786cddb0b3cc5f70ea372f39cbae1b338239", "max_stars_repo_licenses": ["MIT"], "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/test_pic_3d.f90", "max_issues_repo_name": "JuliaVlasov/UAPIC.jl", "max_issues_repo_head_hexsha": "c11a786cddb0b3cc5f70ea372f39cbae1b338239", "max_issues_repo_licenses": ["MIT"], "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/test_pic_3d.f90", "max_forks_repo_name": "JuliaVlasov/UAPIC.jl", "max_forks_repo_head_hexsha": "c11a786cddb0b3cc5f70ea372f39cbae1b338239", "max_forks_repo_licenses": ["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.7816091954, "max_line_length": 70, "alphanum_fraction": 0.5896017699, "num_tokens": 671, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473647220787, "lm_q2_score": 0.7853085808877581, "lm_q1q2_score": 0.6850618710310712}} {"text": "program main\n implicit none\n \n integer :: x(1:6) = (/ 3, 4, 5, 6, 7, 8 /)\n integer :: i \n integer, dimension(size(x)) :: res\n res = [(square(x(i)), i = 1, size(x))] \n \n write(*, *) res\n \n contains\n function square(x) result(res)\n implicit none\n integer, intent(in) :: x\n integer :: res\n !integer, intent(out) :: res\n res = x * x \n end function square \n\nend program main\n\n\n", "meta": {"hexsha": "05695153f5f5ab2ed476efa3d162851077024f1d", "size": 447, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "basics/array/funcAsFCO.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/array/funcAsFCO.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/array/funcAsFCO.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.4347826087, "max_line_length": 46, "alphanum_fraction": 0.4966442953, "num_tokens": 131, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8198933183101078, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.6850073696292028}} {"text": "!___________________________________________________________________________\n! --- Module for 2D Quadratic Elements (8 nodes, 4 int) (quad2D.f90)\n! --- sets shape functions and their gradients in local sys\n! --- same for all elem of this type (=> called 1x at start) \n! --- for now ASSUMES QUADRILATERAL ELEMENTS ONLY (OR DEGEN)\n! --- distribution R1.0, Lucas Brouwer 11/15/2018\n!___________________________________________________________________________\n\nMODULE quad2D\n\nIMPLICIT NONE\n\nPRIVATE\n! element characteristics\t\t\n INTEGER nnode,edim,nq1D,etype,nq\t\n\tPARAMETER (nnode=8) \n\tPARAMETER (edim=2) ! 2D element\n\tPARAMETER (nq1D=2) ! # guassian point integration (in 1D)\n\tPARAMETER (etype=2) ! 1 = linear shape functions, 2 = quadratic shape functions (midside)\n\tPARAMETER (nq=4) ! nq1D^edim\n\t\n\t\n! quadrature and shape functions (set 1x)\t\t\n\tDOUBLE PRECISION qw(nq),dH(nnode,edim,nq)\n\tDOUBLE PRECISION qpt(edim,nq),HH(nq,nq),H(nnode,nq)\n\n! SUBROUTINEs\t\t\n\tPUBLIC set_dH,set_quad,set_HH\n\tPUBLIC qw,dH,HH,H\n\tPUBLIC nnode,edim,nq\n\tPUBLIC INVF2\n\t\nCONTAINS\n\n!___________________________________________________________________________\n! --- shape function gradients w.r.t local var (at quad points)\n!___________________________________________________________________________\n\n\tSUBROUTINE set_dH()\n\t\tDOUBLE PRECISION r,s,t\t\n\t\tINTEGER i\n\t\t\n!\tset dH based on shape function gradients w.r.t local var (at quad points)\n\n\t\tDO i = 1,nq\n\t\t\tt = qpt(1,i)\n\t\t\ts = qpt(2,i)\n\t\t\t\n! 2D 4 node element (linear)\n! \t\t\t\t\tdh(1,1,i) = +0.25d0*(1.d0+s)\n! \t\t\t\t\tdh(2,1,i) = +0.25d0*(-1.d0-s)\n! \t\t\t\t\tdh(3,1,i) = +0.25d0*(-1.d0+s)\n! \t\t\t\t\tdh(4,1,i) = +0.25d0*(1.d0-s)\n! \t\t\t\t\t\n! \t\t\t\t\tdh(1,2,i) = +0.25d0*(1.d0+r)\n! \t\t\t\t\tdh(2,2,i) = +0.25d0*(1.d0-r)\n! \t\t\t\t\tdh(3,2,i) = +0.25d0*(-1.d0+r)\n! \t\t\t\t\tdh(4,2,i) = +0.25d0*(-1.d0-r)\n\n! 2D 8 node element (quadratic)\n\t\t\tH(1,i) = +0.25d0*(+1.d0-s)*(+1.d0-t)*(-s-t-1.d0)\n\t\t\tH(2,i) = +0.25d0*(+1.d0+s)*(+1.d0-t)*(+s-t-1.d0)\t\t\t\t\t\n\t\t\tH(3,i) = +0.25d0*(+1.d0+s)*(+1.d0+t)*(+s+t-1.d0)\t\t\t\t\t\n\t\t\tH(4,i) = +0.25d0*(+1.d0-s)*(+1.d0+t)*(-s+t-1.d0)\n\t\t\tH(5,i) = +0.5d0*(+1.d0-s*s)*(+1.d0-t)\n\t\t\tH(6,i) = +0.5d0*(+1.d0+s)*(+1.d0-t*t)\n\t\t\tH(7,i) = +0.5d0*(+1.d0-s*s)*(+1.d0+t)\n\t\t\tH(8,i) = +0.5d0*(+1.d0-s)*(+1.d0-t*t)\n\t\t\t\n! 2D 8 node element (quadratic)\n\t\t\tdH(1,1,i) = -0.25d0*(-1.d0+t)*(2.d0*s+t)\n\t\t\tdH(2,1,i) = -0.25d0*(-1.d0+t)*(2.d0*s-t)\n\t\t\tdH(3,1,i) = +0.25d0*(+1.d0+t)*(2.d0*s+t)\t\n\t\t\tdH(4,1,i) = +0.25d0*(+1.d0+t)*(2.d0*s-t)\n\t\t\tdH(5,1,i) = s*(-1.d0+t)\n\t\t\tdH(6,1,i) = +0.5d0*(+1.d0-t*t)\n\t\t\tdH(7,1,i) = -s*(+1.d0+t)\n\t\t\tdH(8,1,i) = +0.5d0*(-1.d0+t*t)\n\t\t\t\n\t\t\tdH(1,2,i) = -0.25d0*(-1.d0+s)*(+2.d0*t+s)\n\t\t\tdH(2,2,i) = -0.25d0*(+1.d0+s)*(-2.d0*t+s)\n\t\t\tdH(3,2,i) = +0.25d0*(+1.d0+s)*(+2.d0*t+s)\t\n\t\t\tdH(4,2,i) = +0.25d0*(-1.d0+s)*(-2.d0*t+s)\n\t\t\tdH(5,2,i) = +0.5d0*(-1.d0+s*s)\n\t\t\tdH(6,2,i) = -t*(+1.d0+s)\n\t\t\tdH(7,2,i) = +0.5d0*(+1.d0-s*s)\n\t\t\tdH(8,2,i) = t*(-1.d0+s)\n\t\tENDDO\t\t\t\t\t\t\n\n\t\tRETURN\n\tEND SUBROUTINE set_dH\n\n!___________________________________________________________________________\n! --- set quadrature points and weights\n!___________________________________________________________________________\n\n\tSUBROUTINE set_quad()\n\t\tINTEGER i\n\t\tINTEGER permr(4),perms(4)\t\n\t\tDOUBLE PRECISION P(nq1D),W(nq1D)\t\t\t\n! set up gaussian point locations and weights (1D)\t\t\t\n\t\tW(1) = 1.0d0\n\t\tW(2) = 1.0d0\n\t\tP(1) = dsqrt(1.0d0/3.0d0)\n\t\tP(2) = -dsqrt(1.0d0/3.0d0)\n\n! permute to get\n! 4 3\n! 1 2\n\t\tpermr = (/1,2,2,1/) \t\n\t\tperms = (/1,1,2,2/) \n\t DO i=1,nq\n\t\t\t\tqpt(1,i) = P(permr(i))\n\t\t\t\tqpt(2,i) = P(perms(i))\n\t\t\t\tqw(i) = W(permr(i))*W(perms(i))\t\t\t\t\t\t\n\t ENDDO\n\t\t\n\t\tRETURN\n\tEND SUBROUTINE set_quad\n\t\n!___________________________________________________________________________\n! --- extrapolation of solution var from quad points to corner nodes\n!___________________________________________________________________________\n\n\tSUBROUTINE set_HH()\n\t\tDOUBLE PRECISION S3\n!\tset HH which extrapolates scalars from guass points to corners\t(assumes 4 quad points)\n\t\tS3 = dsqrt(3.0d0)\n\t\t\n\t\tHH(1,1) = 1.0d0+0.5d0*S3\n\t\tHH(1,2) = -0.5d0\t\t\t\n\t\tHH(1,3) = 1.0d0-0.5d0*S3\n\t\tHH(1,4) = -0.5d0\t\t\n\t\t\n\t\tHH(2,1) = -0.5d0\t\t\n\t\tHH(2,2) = 1.0d0+0.5d0*S3\t\t\t\t\n\t\tHH(2,3) = -0.5d0\t\t\t\t\t\n\t\tHH(2,4) = 1.0d0-0.5d0*S3\n\t\t\n\t\tHH(3,1) = 1.0d0-0.5d0*S3\n\t\tHH(3,2) = -0.5d0\t\t\t\n\t\tHH(3,3) = 1.0d0+0.5d0*S3\n\t\tHH(3,4) = -0.5d0\t\n\t\t\n\t\tHH(4,1) = -0.5d0\t\t\n\t\tHH(4,2) = 1.0d0-0.5d0*S3\t\t\t\t\n\t\tHH(4,3) = -0.5d0\t\t\t\t\t\n\t\tHH(4,4) = 1.0d0+0.5d0*S3\t\n\t\t\t\t\t\n\t\tRETURN\n\tEND SUBROUTINE set_HH\t\n\t\n!____________________________________________________________________\n!\t Subroutine INVF2 - from Diego\n!____________________________________________________________________\n SUBROUTINE INVF2(D,F,FINV,Jac)\n INTEGER D\n DOUBLE PRECISION F(D,D),FINV(D,D),Jac\n\t\tIF (D == 2) THEN\n\t\t\tJac = F(1,1)*F(2,2) - F(1,2)*F(2,1)\n\t\t\tFINV(1,1) = F(2,2)/Jac\n\t\t\tFINV(2,2) = F(1,1)/Jac\n\t\t\tFINV(2,1) = -F(2,1)/Jac\n\t\t\tFINV(1,2) = -F(1,2)/Jac\n\t\tELSE IF (D == 3) THEN\n\t\t\tJac = F(1,1)*(F(2,2)*F(3,3) - F(2,3)*F(3,2)) - F(1,2)*(F(2,1)*F(3,3) - F(3,1)*F(2,3)) +\tF(1,3)*(F(2,1)*F(3,2) - F(3,1)*F(2,2))\n\t\t\tFINV(1,1) = (F(2,2)*F(3,3) - F(2,3)*F(3,2))/Jac\n\t\t\tFINV(2,1) = -(F(2,1)*F(3,3) - F(3,1)*F(2,3))/Jac\n\t\t\tFINV(3,1) = (F(2,1)*F(3,2) - F(3,1)*F(2,2))/Jac \n\t\t\tFINV(1,2) = -(F(1,2)*F(3,3) - F(1,3)*F(3,2))/Jac\n\t\t\tFINV(2,2) = (F(1,1)*F(3,3) - F(1,3)*F(3,1))/Jac\n\t\t\tFINV(3,2) = -(F(1,1)*F(3,2) - F(1,2)*F(3,1))/Jac \n\t\t\tFINV(1,3) = (F(1,2)*F(2,3) - F(1,3)*F(2,2))/Jac\n\t\t\tFINV(2,3) = -(F(1,1)*F(2,3) - F(2,1)*F(1,3))/Jac\n\t\t\tFINV(3,3) = (F(1,1)*F(2,2) - F(2,1)*F(1,2))/Jac \n ENDIF\n RETURN\n END SUBROUTINE INVF2\n\t\t\t\nEND MODULE quad2D\n\n\n\n\n", "meta": {"hexsha": "df981cb99b772caba8272f3b61b6932f2c962c11", "size": 5654, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran_files/quad2D.f90", "max_stars_repo_name": "lnbrouwer/ANSYS_UEL", "max_stars_repo_head_hexsha": "e31ef0d25fb3556efe57847d01cff237efa6e503", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-07-21T20:53:27.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-19T02:36:11.000Z", "max_issues_repo_path": "fortran_files/quad2D.f90", "max_issues_repo_name": "lnbrouwer/ANSYS_UEL", "max_issues_repo_head_hexsha": "e31ef0d25fb3556efe57847d01cff237efa6e503", "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": "fortran_files/quad2D.f90", "max_forks_repo_name": "lnbrouwer/ANSYS_UEL", "max_forks_repo_head_hexsha": "e31ef0d25fb3556efe57847d01cff237efa6e503", "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": 30.5621621622, "max_line_length": 129, "alphanum_fraction": 0.5760523523, "num_tokens": 2638, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297887874625, "lm_q2_score": 0.760650658103136, "lm_q1q2_score": 0.6849885764826614}} {"text": "program elliptic\nimplicit none\ninteger::i,j,nitr,nx,ny,nom,k\nreal*8 ::dx,dy,x0,xL,y0,yL,omega,tol\nreal*8::dom,lmax,pi,optom,om1,om2\nreal*8,allocatable ::u(:,:),x(:),y(:),e(:,:)\n\n!Domain\nx0 = 0.0d0 !left\nxL = 2.0d0 !right\n\ny0 = 0.0d0 !bottom\nyL = 1.0d0 !up\n\n!number of points\nnx = 20\nny = 10\n\n!grid spacing (spatial)\ndx = (xL-x0)/dfloat(nx)\ndy = (yL-y0)/dfloat(ny)\n\n!spatial coordinates \nallocate(x(0:nx))\ndo i=0,nx\nx(i) = x0 + dfloat(i)*dx\nend do\n\nallocate(y(0:ny))\ndo j=0,ny\ny(j) = y0 + dfloat(j)*dy\nend do\n\nallocate(e(0:nx,0:ny))\npi = 4.0d0*datan(1.0d0)\n\n!Iterative schemes to solve Laplace Equation:\nallocate(u(0:nx,0:ny))\n\nopen(19,file='error.plt')\nwrite(19,*) 'variables =\"n\",\"Error\"'\n\nopen(20,file='nitr.plt')\nwrite(20,*) 'variables =\"w\",\"N-ITR\"'\n\n!Tolerance\ntol = 1.0d-10\n\n\n!Compute with various omega and plot number of iterations required by the specified omega\nom1=1.0d0\nom2=1.95d0\ndom = 0.05d0\nnom = 19\n\ndo k=0,nom\n\n \t!initial guess which satisfies boundary condtions\n\t!Homogeneous Drichlet B.C.\n\t!we are not updating boundary points, they are zero\n\tdo j=0,ny\n\tdo i=0,nx\n\tu(i,j) = 0.0d0\n\tend do\n\tend do\n\n \tomega = om1 + dfloat(k)*dom\n \n\tcall SOR(nx,ny,y,u,omega,tol,nitr) !Successive over relaxation (SOR)\n\n\t!write error\n write(*,*)'omega and total interval:'\n write(20,*) omega, nitr\n write(*,*) omega, nitr \nend do\n\n!call GS(nx,ny,y,u,tol,nitr) !Gauss-Seidel (GS)\n\nclose(20)\nclose(19)\n\nlmax=0.5d0*(dcos(pi/dfloat(nx))+dcos(pi/dfloat(ny)))\noptom=2.0d0/(1.0d0 + dsqrt(1-lmax**2))\n\n\nprint*,\"-------------------------\"\nprint*,\"optimum omega = \", optom\nprint*,\"-------------------------\"\n\nopen(200,file='field.plt')\nwrite(200,*)'variables =\"x\",\"y\",\"u\"'\nwrite(200,*)'zone f=point i=',nx+1,',j=',ny+1\ndo j=0,ny\ndo i=0,nx\nwrite(200,*) x(i),y(j),u(i,j)\nend do\nend do\nclose(200)\n\nend\n\n\n!-----------------------------------------------------------------------------!\n!Gauss-Seidel (GS)\n!-----------------------------------------------------------------------------!\nsubroutine GS(nx,ny,y,u,tol,nitr) \nimplicit none\ninteger::nx,ny,i,j,nitr\nreal*8 ::tol,err,omega\nreal*8 ::u(0:nx,0:ny),e(0:nx,0:ny),v(0:nx,0:ny),y(0:ny)\n\n\nomega = 1.0d0\n\nnitr = 0\nerr = 1.0d0\n \ndo while(err.gt.tol)\n\n\tnitr = nitr + 1\n\n !dirichlet boundary condition\n do j=0,ny\n u(0,j) = y(j)\n end do\n\n do i = 1,9\n u(i,ny) = 1.0d0\n end do\n\n do j=0,ny\n\tdo i=0,nx\n\tv(i,j) = u(i,j)\n\tend do\n\tend do\n \n\t!update\n do j=1,ny-1\n\tdo i=1,nx-1\n\tu(i,j) = v(i,j) + ((omega/4.0d0)*(v(i+1,j)+u(i-1,j)+v(i,j+1)+u(i,j-1)-(4.0d0*v(i,j))))\n\tend do\n\tend do\n \n !neumann boundary condition\n do j = 1,5\n u(nx,j) = (1.0d0/11.0d0)*(18.0d0*u(nx-1,j) - 9.0d0*u(nx-2,j) + 2.0d0*u(nx-3,j))\n end do\n\n do j = 5,ny\n do i = 10,nx\n u(i,j) = 1.0d0\n end do\n end do\n \n !compute error\n \tdo j=0,ny\n\tdo i=0,nx\n\te(i,j) = dabs(u(i,j)-v(i,j))\n\tend do\n\tend do \n !max value of the error\n err = maxval(e)\n\n\t!write error\n write(19,*) nitr, err\n write(*,*) nitr, err\n \nend do\n\nend \n\n!-----------------------------------------------------------------------------!\n!Successive over relaxation (SOR)\n!-----------------------------------------------------------------------------!\nsubroutine SOR(nx,ny,y,u,omega,tol,nitr) \nimplicit none\ninteger::nx,ny,i,j,nitr\nreal*8 ::tol,err,omega\nreal*8 ::u(0:nx,0:ny),e(0:nx,0:ny),v(0:nx,0:ny),y(0:ny)\n\nnitr = 0\nerr=1.0d0\n \ndo while(err.gt.tol)\n\n\tnitr = nitr + 1\n\n!dirichlet boundary condition\n do j=0,ny\n u(0,j) = y(j)\n end do\n\n do i = 1,9\n u(i,ny) = 1.0d0\n end do\n\n do j=0,ny\n\tdo i=0,nx\n\tv(i,j) = u(i,j)\n\tend do\n\tend do\n\n\t!update\n do j=1,ny-1\n\tdo i=1,nx-1\n\tu(i,j) = v(i,j) + (omega/4.0d0)*(v(i+1,j)+u(i-1,j)+v(i,j+1)+u(i,j-1)-(4.0d0*v(i,j)))\n\tend do\n\tend do\n\n ! Neumann boundary condition\n do j = 1,5\n u(nx,j) = (1.0d0/11.0d0)*(18.0d0*u(nx-1,j) - 9.0d0*u(nx-2,j) + 2.0d0*u(nx-3,j))\n end do\n\n do j = 5,ny\n do i = 10,nx\n u(i,j) = 1.0d0\n end do\n end do\n\n !compute error\n \tdo j=0,ny\n\tdo i=0,nx\n\te(i,j) = dabs(u(i,j)-v(i,j))\n\tend do\n\tend do \n !max value of the error\n err = maxval(e)\n\nend do\nend \n", "meta": {"hexsha": "a22aaed73d7129b1f88041ec2dcd5c69493477ed", "size": 4093, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "2Delliptic.f95", "max_stars_repo_name": "mashfiq10/2DEllipticSolvers", "max_stars_repo_head_hexsha": "e951b5f1078e873552ab5b2c3a354727fd6a585e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2Delliptic.f95", "max_issues_repo_name": "mashfiq10/2DEllipticSolvers", "max_issues_repo_head_hexsha": "e951b5f1078e873552ab5b2c3a354727fd6a585e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2Delliptic.f95", "max_forks_repo_name": "mashfiq10/2DEllipticSolvers", "max_forks_repo_head_hexsha": "e951b5f1078e873552ab5b2c3a354727fd6a585e", "max_forks_repo_licenses": ["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.6422413793, "max_line_length": 89, "alphanum_fraction": 0.5345712192, "num_tokens": 1702, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178929, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.6849885744520515}} {"text": "#include \"eiscor.h\"\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! DOHRFF (Double Orthogonal Hessenberg matrix Reduction to Factored Form)\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! This routine factors a real orthogonal upper hessenberg matrix into\n! a sequence of Givens' rotations and a diagonal matrix. \n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! INPUT VARIABLES:\n!\n! N INTEGER\n! dimension of matrix\n!\n! H REAL(8) array of dimension (N,N)\n! orthogonal hessenberg matrix to be reduced\n!\n! Q REAL(8) array of dimension (2*(N-1))\n! array of generators for Givens' rotations\n!\n! D REAL(8) array of dimension (2*N)\n! array of generators for complex diagonal matrix\n!\n! OUTPUT VARIABLES:\n!\n! INFO INTEGER\n! INFO = 0 implies successful computation\n! INFO = -1 implies COMPZ is invalid\n! INFO = -2 implies N is invalid\n! INFO = -3 implies H is invalid\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine DOHRFF(N,H,Q,D,INFO)\n\n implicit none\n \n ! input variables\n integer, intent(in) :: N\n real(8), intent(inout) :: H(N,N), Q(2*(N-1)), D(2*N)\n integer, intent(inout) :: INFO\n \n ! compute variables\n integer :: ii, ind\n real(8) :: nrm, tol \n real(8) :: c, s\n \n ! initialize info\n INFO = 0\n \n ! check N\n call IARNAN(N,INFO)\n if (INFO.NE.0) then\n ! print error in debug mode\n if (DEBUG) then\n call UARERR(__FILE__,__LINE__,\"N is invalid\",INFO,INFO)\n end if \n INFO = -1\n return\n end if\n call IARINF(N,INFO)\n if (INFO.NE.0) then\n ! print error in debug mode\n if (DEBUG) then\n call UARERR(__FILE__,__LINE__,\"N is invalid\",INFO,INFO)\n end if \n INFO = -1\n return\n end if\n if (N < 2) then\n INFO = -1\n ! print error in debug mode\n if (DEBUG) then\n call UARERR(__FILE__,__LINE__,\"N must be at least 2\",INFO,INFO)\n end if \n return\n end if\n \n ! check H\n call DARACH2(N,N,H,INFO)\n if (INFO.NE.0) then\n ! print error in debug mode\n if (DEBUG) then\n call UARERR(__FILE__,__LINE__,\"H is invalid\",INFO,INFO)\n end if \n INFO = -2\n return\n end if \n \n ! set tol\n tol = dble(max(10,N))*epsilon(1d0)\n \n ! loop for reduction\n ! ii is the column being reduced\n do ii=1,(N-1)\n \n ! reduce to block diagonal\n call DARCG22(H(ii,ii),H(ii+1,ii),c,s,nrm,INFO)\n \n ! check INFO in debug mode\n if (DEBUG) then\n call UARERR(__FILE__,__LINE__,\"DARCG22 failed\",INFO,INFO)\n if (INFO.NE.0) then \n return \n end if \n end if\n \n ! check for unitarity \n if (abs(nrm-1d0) >= tol) then\n INFO = -3\n ! print error in debug mode\n if (DEBUG) then\n call UARERR(__FILE__,__LINE__,\"H is not orthogonal\",INFO,INFO)\n end if \n return \n end if\n \n ! update H\n H(ii,ii) = c*H(ii,ii) + s*H(ii+1,ii)\n H(ii+1,(ii+1):N) = -s*H(ii,(ii+1):N) + c*H(ii+1,(ii+1):N)\n \n ! store in Q\n Q(2*(ii-1)+1) = c\n Q(2*(ii-1)+2) = s\n \n ! store in D\n D(2*(ii-1)+1) = sign(1d0,H(ii,ii))\n D(2*(ii-1)+2) = 0d0\n \n end do\n \n ! check for unitarity \n if (abs(abs(H(N,N))-1d0) >= tol) then\n INFO = -3\n ! print error in debug mode\n if (DEBUG) then\n call UARERR(__FILE__,__LINE__,\"H is not orthogonal\",INFO,INFO)\n end if \n return \n end if\n \n ! store in D\n D(2*(N-1)+1) = sign(1d0,H(N,N))\n D(2*(N-1)+2) = 0d0\n\nend subroutine DOHRFF\n", "meta": {"hexsha": "d17a623c01beaa3e5d8e6c30bf9bea203c9b40cc", "size": 3716, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "deps/eiscor-master/src/double/DOHRFF.f90", "max_stars_repo_name": "andreasnoack/EiSCor.jl", "max_stars_repo_head_hexsha": "d03d217e30e006b35263b99cb4adafd9d7e1e973", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "deps/eiscor-master/src/double/DOHRFF.f90", "max_issues_repo_name": "andreasnoack/EiSCor.jl", "max_issues_repo_head_hexsha": "d03d217e30e006b35263b99cb4adafd9d7e1e973", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "deps/eiscor-master/src/double/DOHRFF.f90", "max_forks_repo_name": "andreasnoack/EiSCor.jl", "max_forks_repo_head_hexsha": "d03d217e30e006b35263b99cb4adafd9d7e1e973", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.9395973154, "max_line_length": 73, "alphanum_fraction": 0.5078040904, "num_tokens": 1152, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297807787536, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6849885655046943}} {"text": " SUBROUTINE RK4(Y,DYDX,N,X,H,YOUT,DERIVS)\n PARAMETER (NMAX=10)\n DIMENSION Y(N),DYDX(N),YOUT(N),YT(NMAX),DYT(NMAX),DYM(NMAX)\n HH=H*0.5\n H6=H/6.\n XH=X+HH\n DO 11 I=1,N\n YT(I)=Y(I)+HH*DYDX(I)\n11 CONTINUE\n CALL DERIVS(XH,YT,DYT)\n DO 12 I=1,N\n YT(I)=Y(I)+HH*DYT(I)\n12 CONTINUE\n CALL DERIVS(XH,YT,DYM)\n DO 13 I=1,N\n YT(I)=Y(I)+H*DYM(I)\n DYM(I)=DYT(I)+DYM(I)\n13 CONTINUE\n CALL DERIVS(X+H,YT,DYT)\n DO 14 I=1,N\n YOUT(I)=Y(I)+H6*(DYDX(I)+DYT(I)+2.*DYM(I))\n14 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "d62580abb8bbda9a55580cc6ce9556c97cd93393", "size": 592, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "Math3/NumRec/source/rk4.for", "max_stars_repo_name": "domijin/MM3", "max_stars_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Math3/NumRec/source/rk4.for", "max_issues_repo_name": "domijin/MM3", "max_issues_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Math3/NumRec/source/rk4.for", "max_forks_repo_name": "domijin/MM3", "max_forks_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.68, "max_line_length": 65, "alphanum_fraction": 0.5016891892, "num_tokens": 256, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297754396142, "lm_q2_score": 0.7606506526772883, "lm_q1q2_score": 0.6849885614434744}} {"text": "module m_time\n !! Contains functions that handle time\n \nuse variableKind, only: i32, i64, r64\n\nimplicit none\n\ncontains\n\n !=====================================================================!\n function daysInMonth(month,year) result(days)\n !! Get the number of days in a month. Accounts for leap years\n !=====================================================================!\n integer(i32) :: month\n !! How many days in this month\n integer(i32),optional :: year\n !! Check if a leap year?\n integer(i32) :: days\n !! Number of days\n days=0\n select case(month)\n case(1,3,5,7,8,10,12)\n days=31\n case(2)\n days=28\n if (present(year)) then\n if (isLeapYear(year)) days=29\n endif\n case(4,6,9,11)\n days=30\n end select\n\n end function\n !=====================================================================!\n !=====================================================================!\n function daysInYear(year) result(days)\n !! Get the number of days in a year, accounts for leap years\n !=====================================================================!\n integer(i32) :: year\n !! How many days in this year\n integer(i32) :: days\n !! Number of days\n days=365\n if (isLeapYear(year)) days=366\n end function\n !=====================================================================!\n !=====================================================================!\n function isLeapYear(year) result(yes)\n !! Determine whether the year is a leap year\n !=====================================================================!\n integer(i32) :: year\n !! Year to check\n logical :: yes\n !! is a leap year\n yes=.false.\n if (iand(year,3) == 0 .and. (mod(year,25) /= 0 .or. iand(year,15) == 0)) yes=.true.\n end function\n !=====================================================================!\n !=====================================================================!\n function secondsToHMS(t) result(res)\n !! Convert a time in seconds to HH:MM:SS.MSEC\n !=====================================================================!\n real(r64) :: t\n !! Time in seconds\n character(len=22) :: res\n !! Resulting string contains the time\n integer(i32) :: days,hrs,min,sec,msec\n real(r64) :: tmp\n days=floor(t/86400.d0)\n tmp=t-(dble(days*86400))\n\n hrs=floor(tmp/3600.d0)\n tmp=tmp-(dble(hrs*3600))\n hrs=hrs+(24*days)\n\n min=floor(tmp/60.d0)\n tmp=tmp-(dble(min*60))\n\n sec=floor(tmp)\n msec=int(1000.d0*(tmp-(dble(sec))))\n\n write(res,10) hrs,min,sec,msec\n10 format(i0,':',i2,':',i2,'.',i3,' (h:m:s)')\n end function\n !=====================================================================!\n !=====================================================================!\n function timeInSeconds(values) result(res)\n !! Convert hours minutes seconds etc. to seconds\n !=====================================================================!\n integer(i32) :: values(8)\n !! values containing amounts of days hours etc.\n real(r64) :: res\n !! time in seconds\n res = dble((86400*values(3))+(3600*values(5)) + (60*values(6)) + values(7))&\n + (0.001d0 * dble(values(8)))\n end function\n !=====================================================================!\n !=====================================================================!\n function timeToInteger(values) result(res)\n !! Convert hours minutes seconds etc. to an integer. Use 64bit to prevent the 2038 problem.\n !=====================================================================!\n integer(i32) :: values(8)\n !! Values containing amounts of days hours etc.\n integer(i64) :: res\n !! Time as an integer.\n\n ! Account for leap years\n values(1) = values(1) * daysInYear(values(1))\n ! Accounts for different length months\n values(2) = values(2) * daysInMonth(values(2))\n \n res = ( values(1) * 86400000 & ! Years\n + values(2) * 86400000 & ! Months\n + values(3) * 86400000 & ! Days\n + values(5) * 3600000 & ! Hours\n + values(6) * 60000 & ! Minutes\n + values(7) * 1000 & ! Seconds\n + values(8)) ! Milliseconds\n end function\n !=====================================================================!\nend module\n", "meta": {"hexsha": "813d77ccd2ceefba1ca21c6412314ba588866f39", "size": 4170, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/time/m_time.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/time/m_time.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/time/m_time.f90", "max_forks_repo_name": "leonfoks/coretran", "max_forks_repo_head_hexsha": "bf998d4353badc91d3a12d23c78781c8377b9578", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-02-20T15:07:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-10T17:58:00.000Z", "avg_line_length": 34.1803278689, "max_line_length": 96, "alphanum_fraction": 0.4340527578, "num_tokens": 1019, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312226373181, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6849435974573485}} {"text": " subroutine SSTOP(K, N, T, BCOEF, BDIF, NPC, XI, PC)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc>> 1994-10-20 SSTOP Krogh Changes to use M77CON\nc>> 1992-10-27 SSTOP C. L. Lawson, JPL\nc>> 1988-03-16 C. L. Lawson, JPL\nc\nc Given coeffs, BCOEF(), rel to the B-spline basis, this subr\nc computes coeffs, PC(,), rel to the Power basis.\nc This code is an adaptation of lines 35-51 of\nc the subroutine, BSPLPP, given on pp. 140-141 of\nc A PRACTICAL GUIDE TO SPLINES by Carl De Boor, Springer-Verlag,\nc 1978, however BSPLPP uses the Taylor basis and this subr uses\nc the Power basis.\nc ------------------------------------------------------------------\nc K [in] Order of the spline function. Note that the\nc polynomial degree of the pieces of the spline function is\nc one less than the order.\nc N [in] Number of B-spline coefficients.\nc T() [in] Knot sequence defining the B-spline basis functions.\nc Contains N+K values, nondecreasing. The \"proper\nc interpolation interval\" is from T(K) to T(N+1).\nc BCOEF() [in] N coefficients, defining a spline function relative\nc to the B-spline basis.\nc BDIF(,) [scratch, out] Array in which differences of the\nc B-spline coeffs will be stored.\nc NPC [out] NPC+1 is the number of distinct values among T(K)\nc through T(N+1). NPC is the number of polynomial pieces\nc needed to define the spline function. The number of\nc breakpoints returned in XI() will be NPC.\nc (XI(j), j = 1, ..., NPC+1) [out] Breakpoints for the Power\nc representation of the piecewise polynomial.\nc These will be the distinct values from among the knots,\nc T(K) through T(N+1).\nc ((PC(i,j), i = 1, ..., K), j = 1, ..., NPC) [out]\nc PC(i,j) will be the (i-1)st derivative of the spline\nc function at XI(j). Thus PC(i,j)/(factorial(i-1)) is the\nc coefficient of (x-XI(j))**(i-1)\nc in the polynomial piece defined over the interval from\nc XI(j) to XI(j+1).\nc ------------------------------------------------------------------\nc--S replaces \"?\": ?STOP, ?SDIF, ?SVALA\nc ------------------------------------------------------------------\n integer I, ILEFT, NPC, K, N, NDERIV\n real BCOEF(N), BDIF(N,K), DENOM, FAC\n real ONE, PC(K,*), T(N+K), XI(*)\n parameter(ONE = 1.0e0)\nc ------------------------------------------------------------------\n NDERIV = K-1\n call SSDIF ( K, N, T, BCOEF, NDERIV, BDIF)\n NPC = 0\n XI(1) = T(K)\n do 50 ILEFT=K,N\n if (T(ILEFT+1) .ne. T(ILEFT)) then\n NPC = NPC + 1\n XI(NPC+1) = T(ILEFT+1)\nc\nc SSVALA sets PC(I,NPC) to be the (I-1)st derivative of\nc the curve at XI(NPC) for I = 1, ..., K.\nc The subsequent loop divides the Jth derivative by\nc factorial(J).\nc\n call SSVALA ( K, N, T, NDERIV, BDIF, XI(NPC), PC(1,NPC))\n DENOM = ONE\n FAC = ONE\n do 40 I = 3,K\n FAC = FAC + ONE\n DENOM = DENOM * FAC\n PC(I,NPC) = PC(I,NPC) / DENOM\n 40 continue\n endif\n 50 continue\n return\n end\n", "meta": {"hexsha": "18108906fdcf8bdaa42360225204f7fb2c395b6a", "size": 3441, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/sstop.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/sstop.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/sstop.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 45.2763157895, "max_line_length": 72, "alphanum_fraction": 0.5286253996, "num_tokens": 991, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122288794595, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6849435943464773}} {"text": "!! 1D\n\n!! setup the stencil struct matrix, A\nsubroutine stencil_ac_1d(nxyz, lamdaxyz, ng, A, soln, theta, dtk, beta_)\nimplicit none\n integer, dimension(3) :: nxyz\n real , dimension(3) :: lamdaxyz\n integer :: ng, i, ix \n real :: theta, beta_, dtk, lamda \n real, dimension( 1-ng:nxyz(1)+ng ) :: soln \n real, dimension(1:3, 1-ng:nxyz(1)+ng ) :: A \n\n ix = nxyz(1)\n lamda = lamdaxyz(1)\n do i=1, ix\n A(1, i) = -theta*lamda\n A(2, i) = -theta*lamda\n A(3, i) = 1 + 2*theta*lamda + theta*dtk * ( &\n (soln(i)-1.0) * ( soln(i) - beta_ ) &\n + (soln(i) ) * ( soln(i) - beta_ ) & \n + (soln(i) ) * ( soln(i) - 1.0 ) )\n end do\nend subroutine stencil_ac_1d \n\nsubroutine rhs_ac_1d(nxyz, lamdaxyz, ng, b, soln, soln_, g1, theta, dtk, beta_)\nimplicit none\n integer, dimension(3) :: nxyz\n real , dimension(3) :: lamdaxyz\n integer :: ng, i, ix \n real :: theta, beta_, dtk, g2, lamda\n real, dimension( 1-ng:nxyz(1)+ng ) :: soln, soln_, b, g1 \n\n ix = nxyz(1)\n lamda = lamdaxyz(1)\n do i=1, ix\n g2 = lamda * (soln(i-1) -2*soln(i) + soln(i+1)) &\n - dtk * soln(i) * ( soln(i) - 1.0 ) * ( soln(i) - beta_ ) \n b(i) = - ( soln(i) - soln_(i) - theta*g2 - (1-theta)*g1(i) )\n end do\nend subroutine rhs_ac_1d \n\nsubroutine rhs_g1_ac_1d(nxyz, lamdaxyz, ng, soln, g1, theta, dtk, beta_)\nimplicit none\n integer, dimension(3) :: nxyz\n real , dimension(3) :: lamdaxyz\n integer :: ng, i, ix \n real :: theta, beta_, dtk, lamda \n real, dimension( 1-ng:nxyz(1)+ng ) :: soln, g1 \n\n ix = nxyz(1)\n lamda = lamdaxyz(1)\n do i=1, ix\n g1(i) = lamda * (soln(i-1) -2*soln(i) + soln(i+1)) &\n - dtk * soln(i) * ( soln(i) - 1.0 ) * ( soln(i) - beta_ ) \n end do\nend subroutine rhs_g1_ac_1d \n\n\nsubroutine bc_pfm_ac_1d_l(nxyz, ng, soln)\nimplicit none\n integer, dimension(3) :: nxyz\n integer :: ng, i, nx \n real, dimension(1-ng:nxyz(1)+ng ) :: soln \n\n nx = nxyz(1)\n soln(1-ng:0) = 2.0 - soln(1) \nend subroutine bc_pfm_ac_1d_l \n\nsubroutine bc_pfm_ac_1d_r(nxyz, ng, soln)\nimplicit none\n integer, dimension(3) :: nxyz\n integer :: ng, i, nx \n real, dimension(1-ng:nxyz(1)+ng ) :: soln \n\n nx = nxyz(1)\n soln(nx+1:nx+ng) = soln(nx) \nend subroutine bc_pfm_ac_1d_r \n\n!! 2D\n\n!! setup the stencil struct matrix, A\nsubroutine stencil_ac_2d(nxyz, lamdaxyz, ng, A, soln, theta, dtk, beta_)\nimplicit none\n integer, dimension(3) :: nxyz\n real , dimension(3) :: lamdaxyz\n integer :: ng, i, j, ix, jy \n real :: theta, beta_, dtk, lamdax, lamday\n real, dimension( 1-ng:nxyz(1)+ng, 1-ng:nxyz(2)+ng ) :: soln \n real, dimension(1:5, 1-ng:nxyz(1)+ng, 1-ng:nxyz(2)+ng ) :: A \n\n ix = nxyz(1)\n jy = nxyz(2)\n lamdax = lamdaxyz(1)\n lamday = lamdaxyz(2)\n do j=1, jy\n do i=1, ix\n A(1,i,j) = -theta*lamdax\n A(2,i,j) = -theta*lamdax\n A(3,i,j) = -theta*lamday\n A(4,i,j) = -theta*lamday\n A(5,i,j) = 1 + 2*theta*(lamdax + lamday) + theta*dtk * ( &\n (soln(i,j)-1.0) * ( soln(i,j) - beta_ ) &\n + (soln(i,j) ) * ( soln(i,j) - beta_ ) & \n + (soln(i,j) ) * ( soln(i,j) - 1.0 ) )\n end do\n end do\nend subroutine stencil_ac_2d \n\nsubroutine rhs_ac_2d(nxyz, lamdaxyz, ng, b, soln, soln_, g1, theta, dtk, beta_)\nimplicit none\n integer, dimension(3) :: nxyz\n real , dimension(3) :: lamdaxyz\n integer :: ng, i, ix, j, jy \n real :: theta, beta_, dtk, g2, lamdax, lamday\n real, dimension( 1-ng:nxyz(1)+ng, 1-ng:nxyz(2)+ng ) :: soln, soln_, b, g1 \n\n ix = nxyz(1)\n jy = nxyz(2)\n lamdax = lamdaxyz(1)\n lamday = lamdaxyz(2)\n do j=1, jy\n do i=1, ix\n g2 = lamdax * ( soln(i-1,j ) -2*soln(i,j) + soln(i+1,j ) ) &\n + lamday * ( soln(i, j-1) -2*soln(i,j) + soln(i, j+1) ) &\n - dtk * soln(i,j) * ( soln(i,j) - 1.0 ) * ( soln(i,j) - beta_ ) \n b(i,j) = - ( soln(i,j) - soln_(i,j) - theta*g2 - (1-theta)*g1(i,j) ) \n end do\n end do\nend subroutine rhs_ac_2d \n\nsubroutine rhs_g1_ac_2d(nxyz, lamdaxyz, ng, soln, g1, theta, dtk, beta_)\nimplicit none\n integer, dimension(3) :: nxyz\n real , dimension(3) :: lamdaxyz\n integer :: ng, i, ix, j, jy \n real :: theta, beta_, dtk, lamdax, lamday\n real, dimension( 1-ng:nxyz(1)+ng, 1-ng:nxyz(2)+ng ) :: soln, g1 \n\n ix = nxyz(1)\n jy = nxyz(2)\n lamdax = lamdaxyz(1)\n lamday = lamdaxyz(2)\n do j=1, jy\n do i=1, ix\n g1(i,j) = lamdax * ( soln(i-1, j ) -2*soln(i,j) + soln(i+1,j ) ) &\n + lamday * ( soln(i, j-1) -2*soln(i,j) + soln(i, j+1) ) &\n - dtk * soln(i,j) * ( soln(i,j) - 1.0 ) * ( soln(i,j) - beta_ ) \n end do\n end do\nend subroutine rhs_g1_ac_2d \n\n\n\n!! the example of customized BC \nsubroutine bc_pfm_ac_2d_l(sxyz, ng, p)\nimplicit none\n integer :: ng, sy\n integer, dimension(3) :: sxyz\n real, dimension(1-ng:sxyz(1)-ng, 1:sxyz(2)) :: p\n\n sy = sxyz(2) \n p(1-ng:0, 1:sy) = 2.0 - p(1:1, 1:sy) \nend subroutine bc_pfm_ac_2d_l\n\nsubroutine bc_pfm_ac_2d_r(sxyz, ng, p)\nimplicit none\n integer :: ng, nx, sy\n integer, dimension(3) :: sxyz\n real, dimension(1-ng:sxyz(1)-ng, 1:sxyz(2)) :: p\n\n nx = sxyz(1) - 2*ng\n sy = sxyz(2) \n p(nx+1:nx+ng, 1:sy) = p(nx:nx, 1:sy)\nend subroutine bc_pfm_ac_2d_r\n\n!! 2D front\nsubroutine bc_pfm_ac_2d_f(sxyz, ng, p)\nimplicit none\n integer :: ng, sx\n integer, dimension(3) :: sxyz\n real, dimension(1:sxyz(1), 1-ng:sxyz(2)-ng) :: p\n \n sx = sxyz(1)\n p(1:sx , 1-ng:0) = p(1:sx , 1:1) \nend subroutine bc_pfm_ac_2d_f \n\n!! 2D back\nsubroutine bc_pfm_ac_2d_b(sxyz, ng, p)\nimplicit none\n integer :: ng, sx, ny\n integer, dimension(3) :: sxyz\n real, dimension(1:sxyz(1), 1-ng:sxyz(2)-ng) :: p\n\n sx = sxyz(1)\n ny = sxyz(2) - 2*ng\n p(1:sx , ny+1:ny+ng) = p(1:sx, ny:ny) \nend subroutine bc_pfm_ac_2d_b \n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!! 3D \n!!\n!! setup the stencil struct matrix, A\nsubroutine stencil_ac_3d(nxyz, lamdaxyz, ng, A, soln, theta, dtk, beta_)\nimplicit none\n integer, dimension(3) :: nxyz\n real , dimension(3) :: lamdaxyz\n integer :: ng, i, j, k, ix, jy, kz \n real :: theta, beta_, dtk, lamdax, lamday, lamdaz\n real, dimension( 1-ng:nxyz(1)+ng, 1-ng:nxyz(2)+ng, 1-ng:nxyz(3)+ng ) :: soln \n real, dimension(1:7, 1-ng:nxyz(1)+ng, 1-ng:nxyz(2)+ng, 1-ng:nxyz(3)+ng ) :: A \n\n ix = nxyz(1)\n jy = nxyz(2)\n kz = nxyz(3)\n lamdax = lamdaxyz(1)\n lamday = lamdaxyz(2)\n lamdaz = lamdaxyz(3)\n!$OMP PARALLEL &\n!$OMP FIRSTPRIVATE(ix, jy, kz, lamdax, lamday, lamdaz, theta, dtk, beta_)\n!$OMP DO SCHEDULE(static) COLLAPSE(2) \n do k=1, kz\n do j=1, jy\n do i=1, ix\n A(1,i,j,k) = -theta*lamdax\n A(2,i,j,k) = -theta*lamdax\n A(3,i,j,k) = -theta*lamday\n A(4,i,j,k) = -theta*lamday\n A(5,i,j,k) = -theta*lamdaz\n A(6,i,j,k) = -theta*lamdaz\n A(7,i,j,k) = 1 + 2*theta*(lamdax + lamday + lamdaz) + theta*dtk * ( &\n (soln(i,j,k)-1.0) * ( soln(i,j,k) - beta_ ) &\n + (soln(i,j,k) ) * ( soln(i,j,k) - beta_ ) & \n + (soln(i,j,k) ) * ( soln(i,j,k) - 1.0 ) )\n end do\n end do \n end do\n!$OMP END DO\n!$OMP END PARALLEL\n\nend subroutine stencil_ac_3d \n\nsubroutine rhs_ac_3d(nxyz, lamdaxyz, ng, b, soln, soln_, g1, theta, dtk, beta_)\nimplicit none\n integer, dimension(3) :: nxyz\n real , dimension(3) :: lamdaxyz\n integer :: ng, i, ix, j, jy, k, kz \n real :: theta, beta_, dtk, g2, lamdax, lamday, lamdaz\n real, dimension( 1-ng:nxyz(1)+ng, 1-ng:nxyz(2)+ng, 1-ng:nxyz(3)+ng ) :: soln, soln_, b, g1 \n\n ix = nxyz(1)\n jy = nxyz(2)\n kz = nxyz(3)\n lamdax = lamdaxyz(1)\n lamday = lamdaxyz(2)\n lamdaz = lamdaxyz(3)\n!$OMP PARALLEL &\n!$OMP FIRSTPRIVATE(ix, jy, kz, lamdax, lamday, lamdaz, theta, dtk, beta_)\n!$OMP DO SCHEDULE(static) COLLAPSE(2) \n do k=1, kz\n do j=1, jy\n do i=1, ix\n g2 = lamdax * ( soln(i-1, j, k ) - 2*soln(i,j,k) + soln(i+1, j, k ) ) &\n + lamday * ( soln(i, j-1, k ) - 2*soln(i,j,k) + soln(i, j+1, k ) ) &\n + lamdaz * ( soln(i, j, k-1) - 2*soln(i,j,k) + soln(i, j, k+1) ) &\n - dtk * soln(i,j,k) * ( soln(i,j,k) - 1.0 ) * ( soln(i,j,k) - beta_ ) \n b(i,j,k) = - ( soln(i,j,k) - soln_(i,j,k) - theta*g2 - (1-theta)*g1(i,j,k) ) \n end do\n end do\n end do\n!$OMP END DO\n!$OMP END PARALLEL\n\nend subroutine rhs_ac_3d \n\nsubroutine rhs_g1_ac_3d(nxyz, lamdaxyz, ng, soln, g1, theta, dtk, beta_)\nimplicit none\n integer, dimension(3) :: nxyz\n real , dimension(3) :: lamdaxyz\n integer :: ng, i, ix, j, jy, k, kz \n real :: theta, beta_, dtk, lamdax, lamday, lamdaz\n real, dimension( 1-ng:nxyz(1)+ng, 1-ng:nxyz(2)+ng, 1-ng:nxyz(3)+ng ) :: soln, g1 \n\n ix = nxyz(1)\n jy = nxyz(2)\n kz = nxyz(3)\n lamdax = lamdaxyz(1)\n lamday = lamdaxyz(2)\n lamdaz = lamdaxyz(3)\n!$OMP PARALLEL &\n!$OMP FIRSTPRIVATE(ix, jy, kz, lamdax, lamday, lamdaz, theta, dtk, beta_)\n!$OMP DO SCHEDULE(static) COLLAPSE(2) \n do k=1, kz\n do j=1, jy\n do i=1, ix\n g1(i,j,k) = lamdax * ( soln(i-1, j, k ) - 2*soln(i,j,k) + soln(i+1, j, k ) ) &\n + lamday * ( soln(i, j-1, k ) - 2*soln(i,j,k) + soln(i, j+1, k ) ) &\n + lamdaz * ( soln(i, j, k-1) - 2*soln(i,j,k) + soln(i, j, k+1) ) &\n - dtk * soln(i,j,k) * ( soln(i,j,k) - 1.0 ) * ( soln(i,j,k) - beta_ ) \n end do\n end do\n end do\n!$OMP END DO\n!$OMP END PARALLEL\n\nend subroutine rhs_g1_ac_3d \n\n\n!!\n!! Frist order forward Euler method\n!!\nsubroutine euler_rhs_ac_1d(nxyz, lamdaxyz, ng, b, soln, dtk, beta_)\nimplicit none\n integer, dimension(3) :: nxyz\n real , dimension(3) :: lamdaxyz\n integer :: ng, i, ix \n real :: dtk, beta_, ss, lamdax \n real, dimension( 1-ng:nxyz(1)+ng ) :: soln, b \n\n ix = nxyz(1)\n lamdax = lamdaxyz(1)\n do i=1, ix\n ss = lamdax * ( soln(i+1) - 2*soln(i) + soln(i-1) )\n b(i) = ss - dtk * soln(i) * ( soln(i) - 1.0 ) * ( soln(i) - beta_ ) \n end do\n\nend subroutine euler_rhs_ac_1d\n\nsubroutine euler_rhs_ac_2d(nxyz, lamdaxyz, ng, b, soln, dtk, beta_)\nimplicit none\n integer, dimension(3) :: nxyz\n real , dimension(3) :: lamdaxyz\n integer :: ng, i, ix, j, jy \n real :: dtk, beta_, ss, lamdax, lamday \n real, dimension( 1-ng:nxyz(1)+ng, 1-ng:nxyz(2)+ng) :: soln, b \n\n ix = nxyz(1)\n jy = nxyz(2)\n lamdax = lamdaxyz(1)\n lamday = lamdaxyz(2)\n\n do j=1, jy\n do i=1, ix\n\n ss = lamdax * ( soln(i-1, j ) - 2*soln(i,j) + soln(i+1, j ) ) &\n + lamday * ( soln(i, j-1 ) - 2*soln(i,j) + soln(i, j+1) ) \n b(i,j) = ss - dtk * soln(i,j) * ( soln(i,j) - 1.0 ) * ( soln(i,j) - beta_ ) \n \n end do\n end do\n\nend subroutine euler_rhs_ac_2d\n\nsubroutine euler_rhs_ac_3d(nxyz, lamdaxyz, ng, b, soln, dtk, beta_)\nimplicit none\n integer, dimension(3) :: nxyz\n real , dimension(3) :: lamdaxyz\n integer :: ng, i, ix, j, jy, k, kz \n real :: dtk, beta_, ss, lamdax, lamday, lamdaz\n real, dimension( 1-ng:nxyz(1)+ng, 1-ng:nxyz(2)+ng, 1-ng:nxyz(3)+ng ) :: soln, b \n\n ix = nxyz(1)\n jy = nxyz(2)\n kz = nxyz(3)\n lamdax = lamdaxyz(1)\n lamday = lamdaxyz(2)\n lamdaz = lamdaxyz(3)\n\n!$OMP PARALLEL &\n!$OMP FIRSTPRIVATE(ix, jy, kz, lamdax, lamday, lamdaz, dtk, beta_)\n!$OMP DO SCHEDULE(static) COLLAPSE(2) \n do k=1, kz\n do j=1, jy\n do i=1, ix\n ss = lamdax * ( soln(i-1, j, k ) - 2*soln(i,j,k) + soln(i+1, j, k ) ) &\n + lamday * ( soln(i, j-1, k ) - 2*soln(i,j,k) + soln(i, j+1, k ) ) &\n + lamdaz * ( soln(i, j, k-1) - 2*soln(i,j,k) + soln(i, j, k+1) ) \n b(i,j,k) = ss - dtk * soln(i,j,k) * ( soln(i,j,k) - 1.0 ) * ( soln(i,j,k) - beta_ ) \n \n end do\n end do\n end do\n!$OMP END DO\n!$OMP END PARALLEL\n\nend subroutine euler_rhs_ac_3d\n\n\n", "meta": {"hexsha": "e01055d003433b62980825b0522881b4e2c77094", "size": 12104, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/pfm/pfm.f90", "max_stars_repo_name": "xjtju/PinT_PFM", "max_stars_repo_head_hexsha": "26ffab52e13882005869d208db2c61ee7e00a239", "max_stars_repo_licenses": ["Linux-OpenIB"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-10-15T13:49:31.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-13T23:58:50.000Z", "max_issues_repo_path": "src/pfm/pfm.f90", "max_issues_repo_name": "xjtju/PinT_PFM", "max_issues_repo_head_hexsha": "26ffab52e13882005869d208db2c61ee7e00a239", "max_issues_repo_licenses": ["Linux-OpenIB"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-04-30T13:09:34.000Z", "max_issues_repo_issues_event_max_datetime": "2018-04-30T13:09:34.000Z", "max_forks_repo_path": "src/pfm/pfm.f90", "max_forks_repo_name": "xjtju/PinT_PFM", "max_forks_repo_head_hexsha": "26ffab52e13882005869d208db2c61ee7e00a239", "max_forks_repo_licenses": ["Linux-OpenIB"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.1958762887, "max_line_length": 101, "alphanum_fraction": 0.5285029742, "num_tokens": 5149, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.7549149868676284, "lm_q1q2_score": 0.6849435936732942}} {"text": " FUNCTION IFIB(N)\n IF (N.EQ.0) THEN\n ITEMP0=0\n ELSE IF (N.EQ.1) THEN\n ITEMP0=1\n ELSE IF (N.GT.1) THEN\n ITEMP1=0\n ITEMP0=1\n DO 1 I=2,N\n ITEMP2=ITEMP1\n ITEMP1=ITEMP0\n ITEMP0=ITEMP1+ITEMP2\n 1 CONTINUE\n ELSE\n ITEMP1=1\n ITEMP0=0\n DO 2 I=-1,N,-1\n ITEMP2=ITEMP1\n ITEMP1=ITEMP0\n ITEMP0=ITEMP2-ITEMP1\n 2 CONTINUE\n END IF\n IFIB=ITEMP0\n END\n", "meta": {"hexsha": "64e21be1aedc89df7686c2f4bb2762402dc0f110", "size": 490, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Fibonacci-sequence/Fortran/fibonacci-sequence-2.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Fibonacci-sequence/Fortran/fibonacci-sequence-2.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Fibonacci-sequence/Fortran/fibonacci-sequence-2.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 19.6, "max_line_length": 30, "alphanum_fraction": 0.4693877551, "num_tokens": 197, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.684943593673294}} {"text": " SUBROUTINE FB01QD( JOBK, MULTBQ, N, M, P, S, LDS, A, LDA, B,\n $ LDB, Q, LDQ, C, LDC, R, LDR, K, LDK, TOL,\n $ IWORK, DWORK, LDWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To calculate a combined measurement and time update of one\nC iteration of the time-varying Kalman filter. This update is given\nC for the square root covariance filter, using dense matrices.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC JOBK CHARACTER*1\nC Indicates whether the user wishes to compute the Kalman\nC filter gain matrix K as follows:\nC i\nC = 'K': K is computed and stored in array K;\nC i\nC = 'N': K is not required.\nC i\nC\nC MULTBQ CHARACTER*1 1/2\nC Indicates how matrices B and Q are to be passed to\nC i i\nC the routine as follows:\nC = 'P': Array Q is not used and the array B must contain\nC 1/2\nC the product B Q ;\nC i i\nC = 'N': Arrays B and Q must contain the matrices as\nC described below.\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The actual state dimension, i.e., the order of the\nC matrices S and A . N >= 0.\nC i-1 i\nC\nC M (input) INTEGER\nC The actual input dimension, i.e., the order of the matrix\nC 1/2\nC Q . M >= 0.\nC i\nC\nC P (input) INTEGER\nC The actual output dimension, i.e., the order of the matrix\nC 1/2\nC R . P >= 0.\nC i\nC\nC S (input/output) DOUBLE PRECISION array, dimension (LDS,N)\nC On entry, the leading N-by-N lower triangular part of this\nC array must contain S , the square root (left Cholesky\nC i-1\nC factor) of the state covariance matrix at instant (i-1).\nC On exit, the leading N-by-N lower triangular part of this\nC array contains S , the square root (left Cholesky factor)\nC i\nC of the state covariance matrix at instant i.\nC The strict upper triangular part of this array is not\nC referenced.\nC\nC LDS INTEGER\nC The leading dimension of array S. LDS >= MAX(1,N).\nC\nC A (input) DOUBLE PRECISION array, dimension (LDA,N)\nC The leading N-by-N part of this array must contain A ,\nC i\nC the state transition matrix of the discrete system at\nC instant i.\nC\nC LDA INTEGER\nC The leading dimension of array A. LDA >= MAX(1,N).\nC\nC B (input) DOUBLE PRECISION array, dimension (LDB,M)\nC The leading N-by-M part of this array must contain B ,\nC 1/2 i\nC the input weight matrix (or the product B Q if\nC i i\nC MULTBQ = 'P') of the discrete system at instant i.\nC\nC LDB INTEGER\nC The leading dimension of array B. LDB >= MAX(1,N).\nC\nC Q (input) DOUBLE PRECISION array, dimension (LDQ,*)\nC If MULTBQ = 'N', then the leading M-by-M lower triangular\nC 1/2\nC part of this array must contain Q , the square root\nC i\nC (left Cholesky factor) of the input (process) noise\nC covariance matrix at instant i.\nC The strict upper triangular part of this array is not\nC referenced.\nC If MULTBQ = 'P', Q is not referenced and can be supplied\nC as a dummy array (i.e., set parameter LDQ = 1 and declare\nC this array to be Q(1,1) in the calling program).\nC\nC LDQ INTEGER\nC The leading dimension of array Q.\nC LDQ >= MAX(1,M) if MULTBQ = 'N';\nC LDQ >= 1 if MULTBQ = 'P'.\nC\nC C (input) DOUBLE PRECISION array, dimension (LDC,N)\nC The leading P-by-N part of this array must contain C , the\nC i\nC output weight matrix of the discrete system at instant i.\nC\nC LDC INTEGER\nC The leading dimension of array C. LDC >= MAX(1,P).\nC\nC R (input/output) DOUBLE PRECISION array, dimension (LDR,P)\nC On entry, the leading P-by-P lower triangular part of this\nC 1/2\nC array must contain R , the square root (left Cholesky\nC i\nC factor) of the output (measurement) noise covariance\nC matrix at instant i.\nC On exit, the leading P-by-P lower triangular part of this\nC 1/2\nC array contains (RINOV ) , the square root (left Cholesky\nC i\nC factor) of the covariance matrix of the innovations at\nC instant i.\nC The strict upper triangular part of this array is not\nC referenced.\nC\nC LDR INTEGER\nC The leading dimension of array R. LDR >= MAX(1,P).\nC\nC K (output) DOUBLE PRECISION array, dimension (LDK,P)\nC If JOBK = 'K', and INFO = 0, then the leading N-by-P part\nC of this array contains K , the Kalman filter gain matrix\nC i\nC at instant i.\nC If JOBK = 'N', or JOBK = 'K' and INFO = 1, then the\nC leading N-by-P part of this array contains AK , a matrix\nC i\nC related to the Kalman filter gain matrix at instant i (see\nC -1/2\nC METHOD). Specifically, AK = A P C'(RINOV') .\nC i i i|i-1 i i\nC\nC LDK INTEGER\nC The leading dimension of array K. LDK >= MAX(1,N).\nC\nC Tolerances\nC\nC TOL DOUBLE PRECISION\nC If JOBK = 'K', then TOL is used to test for near\nC 1/2\nC singularity of the matrix (RINOV ) . If the user sets\nC i\nC TOL > 0, then the given value of TOL is used as a\nC lower bound for the reciprocal condition number of that\nC matrix; a matrix whose estimated condition number is less\nC than 1/TOL is considered to be nonsingular. If the user\nC sets TOL <= 0, then an implicitly computed, default\nC tolerance, defined by TOLDEF = P*P*EPS, is used instead,\nC where EPS is the machine precision (see LAPACK Library\nC routine DLAMCH).\nC Otherwise, TOL is not referenced.\nC\nC Workspace\nC\nC IWORK INTEGER array, dimension (LIWORK),\nC where LIWORK = P if JOBK = 'K',\nC and LIWORK = 1 otherwise.\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0, DWORK(1) returns the optimal value\nC of LDWORK. If INFO = 0 and JOBK = 'K', DWORK(2) returns\nC an estimate of the reciprocal of the condition number\nC 1/2\nC (in the 1-norm) of (RINOV ) .\nC i\nC\nC LDWORK The length of the array DWORK.\nC LDWORK >= MAX(1,N*(P+N)+2*P,N*(N+M+2)), if JOBK = 'N';\nC LDWORK >= MAX(2,N*(P+N)+2*P,N*(N+M+2),3*P), if JOBK = 'K'.\nC For optimum performance LDWORK should be larger.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value;\nC 1/2\nC = 1: if JOBK = 'K' and the matrix (RINOV ) is singular,\nC i 1/2\nC i.e., the condition number estimate of (RINOV )\nC i\nC (in the 1-norm) exceeds 1/TOL. The matrices S, AK ,\nC 1/2 i\nC and (RINOV ) have been computed.\nC i\nC\nC METHOD\nC\nC The routine performs one recursion of the square root covariance\nC filter algorithm, summarized as follows:\nC\nC | 1/2 | | 1/2 |\nC | R C x S 0 | | (RINOV ) 0 0 |\nC | i i i-1 | | i |\nC | 1/2 | T = | |\nC | 0 A x S B x Q | | AK S 0 |\nC | i i-1 i i | | i i |\nC\nC (Pre-array) (Post-array)\nC\nC where T is an orthogonal transformation triangularizing the\nC pre-array.\nC\nC The state covariance matrix P is factorized as\nC i|i-1\nC P = S S'\nC i|i-1 i i\nC\nC and one combined time and measurement update for the state X\nC i|i-1\nC is given by\nC\nC X = A X + K (Y - C X ),\nC i+1|i i i|i-1 i i i i|i-1\nC\nC -1/2\nC where K = AK (RINOV ) is the Kalman filter gain matrix and Y\nC i i i i\nC is the observed output of the system.\nC\nC The triangularization is done entirely via Householder\nC transformations exploiting the zero pattern of the pre-array.\nC\nC REFERENCES\nC\nC [1] Anderson, B.D.O. and Moore, J.B.\nC Optimal Filtering.\nC Prentice Hall, Englewood Cliffs, New Jersey, 1979.\nC\nC [2] Verhaegen, M.H.G. and Van Dooren, P.\nC Numerical Aspects of Different Kalman Filter Implementations.\nC IEEE Trans. Auto. Contr., AC-31, pp. 907-917, Oct. 1986.\nC\nC [3] Vanbegin, M., Van Dooren, P., and Verhaegen, M.H.G.\nC Algorithm 675: FORTRAN Subroutines for Computing the Square\nC Root Covariance Filter and Square Root Information Filter in\nC Dense or Hessenberg Forms.\nC ACM Trans. Math. Software, 15, pp. 243-256, 1989.\nC\nC NUMERICAL ASPECTS\nC\nC The algorithm requires\nC\nC 3 2 2 2\nC (7/6)N + N x (5/2 x P + M) + N x (1/2 x M + P )\nC\nC operations and is backward stable (see [2]).\nC\nC CONTRIBUTORS\nC\nC Release 3.0: V. Sima, Katholieke Univ. Leuven, Belgium, Feb. 1997.\nC Supersedes Release 2.0 routine FB01ED by M. Vanbegin,\nC P. Van Dooren, and M.H.G. Verhaegen.\nC\nC REVISIONS\nC\nC February 20, 1998, November 20, 2003.\nC\nC KEYWORDS\nC\nC Kalman filtering, optimal filtering, orthogonal transformation,\nC recursive estimation, square-root covariance filtering,\nC square-root filtering.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ONE, TWO\n PARAMETER ( ONE = 1.0D0, TWO = 2.0D0 )\nC .. Scalar Arguments ..\n CHARACTER JOBK, MULTBQ\n INTEGER INFO, LDA, LDB, LDC, LDK, LDQ, LDR, LDS, LDWORK,\n $ M, N, P\n DOUBLE PRECISION TOL\nC .. Array Arguments ..\n INTEGER IWORK(*)\n DOUBLE PRECISION A(LDA,*), B(LDB,*), C(LDC,*), DWORK(*),\n $ K(LDK,*), Q(LDQ,*), R(LDR,*), S(LDS,*)\nC .. Local Scalars ..\n LOGICAL LJOBK, LMULTB\n INTEGER I12, ITAU, JWORK, N1, PN, WRKOPT\n DOUBLE PRECISION RCOND\nC .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\nC .. External Subroutines ..\n EXTERNAL DGELQF, DLACPY, DTRMM, MB02OD, MB04LD, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC INT, MAX\nC .. Executable Statements ..\nC\n PN = P + N\n N1 = MAX( 1, N )\n INFO = 0\n LJOBK = LSAME( JOBK, 'K' )\n LMULTB = LSAME( MULTBQ, 'P' )\nC\nC Test the input scalar arguments.\nC\n IF( .NOT.LJOBK .AND. .NOT.LSAME( JOBK, 'N' ) ) THEN\n INFO = -1\n ELSE IF( .NOT.LMULTB .AND. .NOT.LSAME( MULTBQ, 'N' ) ) THEN\n INFO = -2\n ELSE IF( N.LT.0 ) THEN\n INFO = -3\n ELSE IF( M.LT.0 ) THEN\n INFO = -4\n ELSE IF( P.LT.0 ) THEN\n INFO = -5\n ELSE IF( LDS.LT.N1 ) THEN\n INFO = -7\n ELSE IF( LDA.LT.N1 ) THEN\n INFO = -9\n ELSE IF( LDB.LT.N1 ) THEN\n INFO = -11\n ELSE IF( LDQ.LT.1 .OR. ( .NOT.LMULTB .AND. LDQ.LT.M ) ) THEN\n INFO = -13\n ELSE IF( LDC.LT.MAX( 1, P ) ) THEN\n INFO = -15\n ELSE IF( LDR.LT.MAX( 1, P ) ) THEN\n INFO = -17\n ELSE IF( LDK.LT.N1 ) THEN\n INFO = -19\n ELSE IF( ( LJOBK .AND. LDWORK.LT.MAX( 2, PN*N + 2*P,\n $ N*(N + M + 2), 3*P ) ) .OR.\n $ ( .NOT.LJOBK .AND. LDWORK.LT.MAX( 1, PN*N + 2*P,\n $ N*(N + M + 2) ) ) ) THEN\n INFO = -23\n END IF\nC\n IF ( INFO.NE.0 ) THEN\nC\nC Error return.\nC\n CALL XERBLA( 'FB01QD', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF ( N.EQ.0 ) THEN\n IF ( LJOBK ) THEN\n DWORK(1) = TWO\n DWORK(2) = ONE\n ELSE\n DWORK(1) = ONE\n END IF\n RETURN\n END IF\nC\nC Construction of the needed part of the pre-array in DWORK.\nC To save workspace, only the blocks (1,2), (2,2), and (2,3) will be\nC constructed as shown below.\nC\nC Storing A x S and C x S in the (1,1) and (2,1) blocks of DWORK,\nC respectively.\nC Workspace: need (N+P)*N.\nC\nC (Note: Comments in the code beginning \"Workspace:\" describe the\nC minimal amount of real workspace needed at that point in the\nC code, as well as the preferred amount for good performance.\nC NB refers to the optimal block size for the immediately\nC following subroutine, as returned by ILAENV.)\nC\n CALL DLACPY( 'Full', N, N, A, LDA, DWORK, PN )\n CALL DLACPY( 'Full', P, N, C, LDC, DWORK(N+1), PN )\n CALL DTRMM( 'Right', 'Lower', 'No transpose', 'Non-unit', PN, N,\n $ ONE, S, LDS, DWORK, PN )\nC\nC Triangularization (2 steps).\nC\nC Step 1: annihilate the matrix C x S.\nC Workspace: need (N+P)*N + 2*P.\nC\n ITAU = PN*N + 1\n JWORK = ITAU + P\nC\n CALL MB04LD( 'Full', P, N, N, R, LDR, DWORK(N+1), PN, DWORK, PN,\n $ K, LDK, DWORK(ITAU), DWORK(JWORK) )\n WRKOPT = PN*N + 2*P\nC\nC Now, the workspace for C x S is no longer needed.\nC Adjust the leading dimension of DWORK, to save space for the\nC following computations.\nC\n CALL DLACPY( 'Full', N, N, DWORK, PN, DWORK, N )\n I12 = N*N + 1\nC\nC Storing B x Q in the (1,2) block of DWORK.\nC Workspace: need N*(N+M).\nC\n CALL DLACPY( 'Full', N, M, B, LDB, DWORK(I12), N )\n IF ( .NOT.LMULTB )\n $ CALL DTRMM( 'Right', 'Lower', 'No transpose', 'Non-unit', N, M,\n $ ONE, Q, LDQ, DWORK(I12), N )\n WRKOPT = MAX( WRKOPT, N*( N + M ) )\nC\nC Step 2: LQ triangularization of the matrix [ A x S B x Q ], where\nC A x S was modified at Step 1.\nC Workspace: need N*(N+M+2); prefer N*(N+M+1)+N*NB.\nC\n ITAU = N*( N + M ) + 1\n JWORK = ITAU + N\nC\n CALL DGELQF( N, N+M, DWORK, N, DWORK(ITAU), DWORK(JWORK),\n $ LDWORK-JWORK+1, INFO )\n WRKOPT = MAX( WRKOPT, INT( DWORK(JWORK) )+JWORK-1 )\nC\nC Output S and K (if needed) and set the optimal workspace\nC dimension (and the reciprocal of the condition number estimate).\nC\n CALL DLACPY( 'Lower', N, N, DWORK, N, S, LDS )\nC\n IF ( LJOBK ) THEN\nC\nC Compute K.\nC Workspace: need 3*P.\nC\n CALL MB02OD( 'Right', 'Lower', 'No transpose', 'Non-unit',\n $ '1-norm', N, P, ONE, R, LDR, K, LDK, RCOND, TOL,\n $ IWORK, DWORK, INFO )\n IF ( INFO.EQ.0 ) THEN\n WRKOPT = MAX( WRKOPT, 3*P )\n DWORK(2) = RCOND\n END IF\n END IF\nC\n DWORK(1) = WRKOPT\nC\n RETURN\nC *** Last line of FB01QD ***\n END\n", "meta": {"hexsha": "38f221f2c457d774e90c970855bc2e8bf8f30534", "size": 16981, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/FB01QD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/FB01QD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/FB01QD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 37.6518847007, "max_line_length": 72, "alphanum_fraction": 0.488546022, "num_tokens": 4806, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172688214137, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6848745977897853}} {"text": " double precision function rotwig (beta, jj, m1, m2, ient)\nc uses Wigner formula (Messiah eq.C.72) to calculate rotation matrix\nc for integers (ient=1) or semiintegers (ient=2)\nc other arguments (except beta) should be multiplied by ient\n \n implicit double precision (a-h,o-z)\n parameter (idim = 58)\nc dimensions modified for larger arguments by ala 12.12.94\n dimension al(idim+1),m(12)\n save ini, al\n data ini/1/\nc idim-1 is the largest argument of factorial to calculate\n\n if (((ient-1)*(ient-2)).ne.0) stop ' Illegal ient in rotwig.'\n\n if (ini.eq.1) then\nc initialisation of the log's of the factorials\n ini=0\n al(1)=0.0d 00\n do 11 i=1,idim\n b=i\n 11 al(i+1)=al(i)+ log(b)\n endif\n rotwig = 0.d0\n\n if ( m1.ge.0 .and. abs(m1).ge.abs(m2)) then\n m1p = m1 \n m2p = m2\n betap = beta\n isign = 1\n elseif (m2.ge.0 .and. abs(m2).ge.abs(m1)) then\n m1p = m2\n m2p = m1\n betap = - beta\n isign = 1\n elseif (m1.le.0 .and. abs(m1).ge.abs(m2)) then\n m1p = - m1\n m2p = - m2\n betap = beta\n isign = (-1)**( (m1-m2)/ient ) \n else\n m1p = - m2\n m2p = - m1\n betap = - beta\n isign = (-1)**( (m2-m1)/ient ) \n endif\n\n temp = 0.d0\n zeta = cos ( betap / 2.d0 )\n eta = sin ( betap / 2.d0 )\n do 100 it = m1p - m2p, jj - m2p, ient\n m(1) = 1 + (jj+m1p) / ient\n m(2) = 1 + (jj-m1p) / ient\n m(3) = 1 + (jj+m2p) / ient\n m(4) = 1 + (jj-m2p) / ient\n m(5) = 1 + (jj+m1p-it) / ient\n m(6) = 1 + (jj-m2p-it) / ient\n m(7) = 1 + it / ient\n m(8) = 1 + (m2p-m1p+it) / ient\n m(9) = (2*jj+m1p-m2p-2*it) / ient \n m(10) = (2*it-m1p+m2p) / ient \n factor = 0.d0\n do 110 i = 1,4\n 110 factor = factor + al(m(i))/2.d0 - al(m(i+4))\nc special cases to resolve 0.d0**0 problem (a.ankudinov, may 2001)\n if (m(10).eq.0 .and. m(9).eq.0) then\n temp = temp + (-1)**(it/ient)*exp(factor)\n elseif (m(10).eq.0) then\n temp = temp + (-1)**(it/ient)*zeta**m(9)*exp(factor)\n elseif (m(9).eq.0) then\n temp = temp + (-1)**(it/ient)*eta**m(10)*exp(factor)\n else\nc general expression\n temp = temp+ (-1)**(it/ient)*zeta**m(9)*eta**m(10)*exp(factor)\n endif\n 100 continue\n\n rotwig = isign * temp\n \n return\n end\n", "meta": {"hexsha": "7e9841aaafcd8a29be947d9aaa987afc0db70ced", "size": 2520, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH/rotwig.f", "max_stars_repo_name": "bruceravel/feff85exafs", "max_stars_repo_head_hexsha": "9698ce3703a73def4c1a965f276708d689ea5acb", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-01-28T15:52:14.000Z", "max_stars_repo_stars_event_max_datetime": "2019-01-28T15:52:14.000Z", "max_issues_repo_path": "src/MATH/rotwig.f", "max_issues_repo_name": "bruceravel/feff85exafs", "max_issues_repo_head_hexsha": "9698ce3703a73def4c1a965f276708d689ea5acb", "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/MATH/rotwig.f", "max_forks_repo_name": "bruceravel/feff85exafs", "max_forks_repo_head_hexsha": "9698ce3703a73def4c1a965f276708d689ea5acb", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.7317073171, "max_line_length": 72, "alphanum_fraction": 0.4869047619, "num_tokens": 964, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172673767972, "lm_q2_score": 0.7217432062975979, "lm_q1q2_score": 0.6848745910676846}} {"text": " SUBROUTINE CALP(CMN,DMN,EMN,EPSIL,LROW,LDIAG,ALP,DALP)\nC\nC CALCULATES THE ASSOCIATED LEGENDRE POLYNOMIALS USING A HIGHLY \nC STABLE FOUR TERM RECURRENCE RELATION GIVEN BY BELOUSOV (1962). \nC THE SPECTRAL TRUNCATION PARAMETERS ARE DEFINED BY 3 PARAMETERS: \nC MM, THE LARGEST FOURIER WAVENUMBER; KK, THE HIGHEST DEGREE OF THE \nC ASSOCIATED LEGENDRE POLYNOMIALS, AND NN THE HIGHEST DEGREE OF THE \nC ASSOCIATED LEGENDRE POLYNOMIALS FOR M=0. THE LENGTH OF THE \nC ASSOCIATED LEGENDRE POLYNOMIAL ARRAY ALP IS GIVEN BY THE RELATION \nC LEN = ((MM+1)*(NN+1) - (LMN**2 + LMN)/2) WHERE LMN = MM + NN - KK \nC VARIABLES ARE STORED ALONG DIAGONALS STARTING WITH DIAGONAL M=N. \nC THE LENGTH OF EACH ROW IS STORED IN THE ARRAY LROW(0:KK,2).\nC THE LENGTH OF EACH DIAGONAL IS STORED IN THE ARRAY LDIAG(0:NN,1) \nC AND IS EVALUATED IN SUBROUTINE CEPS AS (MM+1)-AMAX(MM+N-KK,0) \nC WHERE 0>N>NN. CUMULATIVE DIAGONAL LENGTHS (CUMULATIVE \nC DISPLACEMENTS) ARE ALSO STORED IN LDIAG(0:NN,2) SO THAT THE \nC ASSOCIATED LEGENDRE POLYNOMIAL OF ORDER M, DEGREE N, AND ARGUMENT \nC SNJ(NL) IS ADDRESSED AS ALP(1 + LDIAG(N-M,2)+M),NL), OR USING THE \nC STATEMENT FUNCTION IDSP AS ALP(IDSP(M,N),NL). THE SAME FORM \nC APPLIES FOR ADDRESSING THE DERIVATIVES (DALP) AND RECURRENCE \nC COEFFICIENTS DEFINED IN THE EPSIL MATRIX. \nC \nC CALLED BY: INPUT\nC CALLS: GLAT\nC\nC REVISIONS:\nC 7-10-92 CHANGE TO CCM CODING CONVENTIONS (R. JAKOB)\nC\nC---- Model Parameters -------------------------------------------------\nC\n INCLUDE 'params.i'\nC\nC------------ Arguments ------------------------------------------------\nC\nC Input\nC\nC RECURRENCE COEFFICIENTS FOR ALP\n REAL CMN(LRM+1)\nC RECURRENCE COEFFICIENTS FOR ALP\n REAL DMN(LRM+1)\nC RECURRENCE COEFFICIENTS FOR ALP\n REAL EMN(LRM+1)\nC RECURRENCE COEFFICIENTS FOR DALP\n REAL EPSIL(NALP)\nC ROW LENGTH AND INDEX\n INTEGER LROW(0:KK,2)\nC DIAGONAL LENGTH AND INDEX\n INTEGER LDIAG(0:NN,2)\nC\nC Output\nC\nC ASSOC. LEGENDRE POLYNOMIALS\n REAL ALP(NALP,NLAT/2)\nC DERIV. ASSOC. LEGENDRE POLYNOMIALS\n REAL DALP(NALP,NLAT/2)\nC\nC------ Local Parameters -----------------------------------------------\nC\n REAL PI\n PARAMETER (PI=3.141592653589793)\nC\nC------ Local Variables ------------------------------------------------\nC\n REAL CN2N1N(KK+1,3)\n REAL COL1(KK), COL2(KK), SNPSUM(KK), CSPSUM(KK), SQNP(KK), \n $ AN(KK), CSFAC(KK), SNFAC(KK), COSTBL(KK), SINTBL(KK) \nC\nC TEMPORARIES\nC\n REAL RNORM,COS2P,RLAT,SNJ,THTA\n INTEGER N,M,JK,JM,JN,MSTART,NSTART\n INTEGER MLIM,IS,ISM1,NL,LAT\nC\nC----- External Functions ----------------------------------------------\nC\nC GAUSSIAN LATITUDES\nC\n EXTERNAL GLAT\n REAL GLAT\nC\nC----- Statement Functions ---------------------------------------------\nC\nC ADDRESS COMPUTATION OF ALP, DALP, EPSIL \nC E.G., EPSIL(M,N) = EPSIL(IDSP(M,N)) \nC \n INTEGER MDUM, NDUM, IDSP, IDSPR\n IDSP(MDUM,NDUM) = 1 + LDIAG(NDUM-MDUM,2)+MDUM \nC \nC ADDRESS COMPUTATION OF BELOUSOV RECURRENCE \nC COEFFICIENT MATRICES. E.G., CMN(M,N) = CMN(IDSPR(M,N)) \nC \n IDSPR(MDUM,NDUM) = 1 + LROW(NDUM,2)+MDUM \nC\nC----- Executable Statements -------------------------------------------\nC\nC COMPUTE ASSOCIATED LEGENDRE POLYNOMIALS AND THEIR DERIVATIVES FOR \nC THE TRUNCATED WAVENUMBER SPACE DEFINED IN LDIAG(0:NN,1:2) WITH \nC ARGUMENTS GIVEN BY GRID FUNCTION GLAT USING BELOUSOV'S ALGORITHM. \nC THE PROCEDURE INVOLVES EXTRA WORK FOR ANY TRUNCATION OTHER THAN \nC TRIANGULAR BECAUSE BELOUSOV'S RECURRENCE REQUIRES POLYNOMIAL \nC INFORMATION IN PART OF THE REGION BETWEEN KK AND NN. MORE \nC ELABORATE BOOKKEEPING COULD REDUCE THIS EXTRA COMPUTATION, BUT BY \nC LESS THAN A FACTOR OF TWO (PROBABLY LESS THAN 10% OF TOTAL WORK). \nC\nC PRECOMPUTE SOME FACTORS\nC\n AN(1) = SQRT(0.75)\n DO 190 N=2,KK\n AN(N) = AN(N-1)*SQRT(1.0-(1.0/REAL(4*N*N)))\n 190 CONTINUE\nC \nC BEGIN PROCEDURE ... OUTER LOOP OVER LATITUDE (ARGUMENT) \nC \n DO 290 NL=1,NLAT/2 \nC \nC DETERMINE PROPER INDEX FOR LATITUDE DEPENDENT QUANTITIES \nC (PROVISION FOR DOING THIS COMPUTATION ON THE FLY, NOT IN USE) \nC \n LAT = NL \n RLAT = GLAT(LAT)\nC\nC LATITUDE = RLAT\nC \nC BEGIN BY COMPUTING 1ST TWO ELEMENTS IN EACH ROW (M=0:1;N=0:KK) \nC EVALUATE THE SERIES EXPANSIONS (19) AND (21) IN BELOUSOV (1962) \nC FINAL RESULTS ARE STORED IN WORK ARRAYS COL1 AND COL2 \nC \nC COS2P = SQRT(CSJ(LAT)) \n COS2P = COS(RLAT)\n SNJ = SIN(RLAT)\n THTA = PI/2.0 - RLAT\n CN2N1N(1,1) = SQRT(0.50) \n ALP(1,NL) = CN2N1N(1,1) \n DALP(1,NL) = 0.0 \nC \nC INITIALIZE WORKING SPACE \nC \n DO 205 N=1,KK \n SNPSUM(N) = 0.0 \n CSPSUM(N) = 0.0 \n SQNP(N) = 1.0/SQRT(REAL(N*N + N)) \n CSFAC(N) = 1.0 \n SNFAC(N) = REAL(N)*SQNP(N) \n COSTBL(N) = COS(REAL(N)*THTA) \n SINTBL(N) = SIN(REAL(N)*THTA) \n 205 CONTINUE \nC \nC EACH INCREMENT IN JK EVALUATES AN ADDITIONAL TERM IN EXPANSIONS \nC \n JK=1 \n DO 215 N=1,KK \n CSPSUM(N) = CSPSUM(N)+COSTBL(N-JK+1)*CSFAC(N) \n SNPSUM(N) = SNPSUM(N)+SINTBL(N-JK+1)*SNFAC(N) \n 215 CONTINUE \nC \n DO 225 JK=3,KK+1,2 \nC \n NSTART = MAX0(JK-1,1) \n N = NSTART \n CSFAC(N) = REAL(JK-2)/REAL(JK-1)*REAL(2*N-JK+3) \n $ /REAL(2*N-JK+2)*CSFAC(N) \n CSPSUM(N) = CSPSUM(N) + CSFAC(N)*0.50 \nC \n DO 220 N=NSTART+1,KK \n CSFAC(N) = REAL(JK-2)/REAL(JK-1)*REAL(2*N-JK+3) \n $ /REAL(2*N-JK+2)*CSFAC(N) \n SNFAC(N) = CSFAC(N)*REAL(N-JK+1)*SQNP(N) \n CSPSUM(N) = CSPSUM(N)+COSTBL(N-JK+1)*CSFAC(N) \n SNPSUM(N) = SNPSUM(N)+SINTBL(N-JK+1)*SNFAC(N) \n 220 CONTINUE \n 225 CONTINUE \nC \n RNORM = 1.0/ALP(1,NL) \n DO 230 N=1,KK \n COL1(N) = AN(N)*CSPSUM(N)*RNORM \n COL2(N) = AN(N)*SNPSUM(N)*RNORM \n 230 CONTINUE \nC \n DO 260 N=1,KK \nC \nC EVALUATE REMAINING POLYNOMIALS BY SWEEPING THROUGH ROWS N=1:KK \nC FIRST TWO ELEMENTS OBTAINED FROM THE ABOVE SERIES EXPANSIONS \nC \n CN2N1N(1,3) = COL1(N) \n CN2N1N(2,3) = COL2(N) \nC \nC NECESSARY DETOUR TO \"PRIME THE PIPELINE\" (FIRST PASS) \nC \n IF (N .EQ. 1) THEN \n CN2N1N(1,2) = CN2N1N(1,3) \n CN2N1N(2,2) = CN2N1N(2,3) \n ALP(MM+2,NL) = CN2N1N(1,2) \n DALP(MM+2,NL) = SQRT(3.0)*CN2N1N(1,1) \n $ - SNJ*CN2N1N(1,2) \n ALP(2,NL) = CN2N1N(2,2) \n DALP(2,NL) = -SNJ*CN2N1N(2,2) \n ELSE \nC \nC EVALUATE THE REMAINDER OF THIS ROW (M = 2, 3, 4, ...) \nC USING BELOUSOV'S RECURRENCE RELATION \nC \n MLIM = MIN0(MM,N-1) \n DO 235 M=2,MLIM \n JM = M+1 \n CN2N1N(JM,3) = CMN(IDSPR(M,N))*CN2N1N(JM-2,1) \n $ -SNJ*(DMN(IDSPR(M,N)) \n $ *CN2N1N(JM-2,2) - EMN(IDSPR(M,N)) \n $ *CN2N1N(JM,2)) \n 235 CONTINUE \nC \nC PUT VALUES OF THE POLYNOMIALS CONTAINED IN CN2N1N(0:MLIM,3) \nC INTO THE ASSOCIATED LEGENDRE POLYNOMIAL ARRAY ALP \nC \n MSTART = MAX0(N-NN,0) \n DO 240 M=MSTART,MLIM \n JM = M+1 \n ALP(IDSP(M,N),NL) = CN2N1N(JM,3) \n 240 CONTINUE \nC \nC SPECIAL EVALUATION REQUIRED FOR DIAGONAL ELEMENT M=N \nC \n IF (N .LE. MM) THEN\n CN2N1N(N+1,3) = SQRT(1.0 + (1.0/REAL(2*N)))*COS2P \n $ *CN2N1N(N,2) \n ALP(IDSP(N,N),NL) = CN2N1N(N+1,3) \n DALP(IDSP(N,N),NL) = -REAL(N)*SNJ*CN2N1N(N+1,3) \n ENDIF\nC \nC MAKE ROOM FOR NEW POLYNOMIAL EVALUATION IN CN2N1N(0:MLIM,3) \nC \n DO 250 JM=1,N+1 \n CN2N1N(JM,1) = CN2N1N(JM,2) \n CN2N1N(JM,2) = CN2N1N(JM,3) \n 250 CONTINUE \nC\n ENDIF\nC \n 260 CONTINUE \nC \nC EFFICIENTLY EVALUATE DERIVATIVES SEPARATELY (ALONG DIAGONALS) \nC \n DO 280 JN = 1,NN \n IS = LDIAG(JN,2) \n ISM1 = LDIAG(JN-1,2) \n DO 270 M=0,LDIAG(JN,1)-1 \n JM = M+1 \n N = JN+M \n DALP(IS+JM,NL) = REAL(2*N+1)*EPSIL(IS+JM)*\n $ ALP(ISM1+JM,NL)-REAL(N)*SNJ*ALP(IS+JM,NL)\n 270 CONTINUE \n 280 CONTINUE \nC \n 290 CONTINUE \nC \n RETURN \n END \n", "meta": {"hexsha": "9e4f3eaacf6ad3fb37df4b35e365dd9a1c2446e1", "size": 15754, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/calp.f", "max_stars_repo_name": "jhaoli/shallow_spectral", "max_stars_repo_head_hexsha": "a2580f9baad596a56efaaae20b80e1bd543c2502", "max_stars_repo_licenses": ["NetCDF"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-06-19T02:24:41.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-19T02:24:41.000Z", "max_issues_repo_path": "src/calp.f", "max_issues_repo_name": "jhaoli/shallow_spectral", "max_issues_repo_head_hexsha": "a2580f9baad596a56efaaae20b80e1bd543c2502", "max_issues_repo_licenses": ["NetCDF"], "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/calp.f", "max_forks_repo_name": "jhaoli/shallow_spectral", "max_forks_repo_head_hexsha": "a2580f9baad596a56efaaae20b80e1bd543c2502", "max_forks_repo_licenses": ["NetCDF"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 61.2996108949, "max_line_length": 83, "alphanum_fraction": 0.2978291228, "num_tokens": 3308, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172601537142, "lm_q2_score": 0.7217431943271999, "lm_q1q2_score": 0.6848745744955563}} {"text": " FUNCTION rc(x,y)\r\n REAL rc,x,y,ERRTOL,TINY,SQRTNY,BIG,TNBG,COMP1,COMP2,THIRD,C1,C2,\r\n *C3,C4\r\n PARAMETER (ERRTOL=.04,TINY=1.69e-38,SQRTNY=1.3e-19,BIG=3.E37,\r\n *TNBG=TINY*BIG,COMP1=2.236/SQRTNY,COMP2=TNBG*TNBG/25.,THIRD=1./3.,\r\n *C1=.3,C2=1./7.,C3=.375,C4=9./22.)\r\n REAL alamb,ave,s,w,xt,yt\r\n if(x.lt.0..or.y.eq.0..or.(x+abs(y)).lt.TINY.or.(x+\r\n *abs(y)).gt.BIG.or.(y.lt.-COMP1.and.x.gt.0..and.x.lt.COMP2))pause \r\n *'invalid arguments in rc'\r\n if(y.gt.0.)then\r\n xt=x\r\n yt=y\r\n w=1.\r\n else\r\n xt=x-y\r\n yt=-y\r\n w=sqrt(x)/sqrt(xt)\r\n endif\r\n1 continue\r\n alamb=2.*sqrt(xt)*sqrt(yt)+yt\r\n xt=.25*(xt+alamb)\r\n yt=.25*(yt+alamb)\r\n ave=THIRD*(xt+yt+yt)\r\n s=(yt-ave)/ave\r\n if(abs(s).gt.ERRTOL)goto 1\r\n rc=w*(1.+s*s*(C1+s*(C2+s*(C3+s*C4))))/sqrt(ave)\r\n return\r\n END\r\n", "meta": {"hexsha": "a33404594381015f3237af644749cb8e09322f32", "size": 914, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/rc.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/rc.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/rc.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": 30.4666666667, "max_line_length": 72, "alphanum_fraction": 0.4989059081, "num_tokens": 382, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897525789548, "lm_q2_score": 0.7279754548076477, "lm_q1q2_score": 0.6848718480120389}} {"text": " SUBROUTINE PELGEV(XMOM,PARA)\nC***********************************************************************\nC* *\nC* FORTRAN CODE WRITTEN FOR INCLUSION IN IBM RESEARCH REPORT RC20525, *\nC* 'FORTRAN ROUTINES FOR USE WITH THE METHOD OF L-MOMENTS, VERSION 3' *\nC* *\nC* J. R. M. HOSKING *\nC* IBM RESEARCH DIVISION *\nC* T. J. WATSON RESEARCH CENTER *\nC* YORKTOWN HEIGHTS *\nC* NEW YORK 10598, U.S.A. *\nC* *\nC* VERSION 3 AUGUST 1996 *\nC* *\nC***********************************************************************\nC\nC PARAMETER ESTIMATION VIA L-MOMENTS FOR THE GENERALIZED EXTREME-VALUE\nC DISTRIBUTION\nC\nC PARAMETERS OF ROUTINE:\nC XMOM * INPUT* ARRAY OF LENGTH 3. CONTAINS THE L-MOMENTS LAMBDA-1,\nC LAMBDA-2, TAU-3.\nC PARA *OUTPUT* ARRAY OF LENGTH 3. ON EXIT, CONTAINS THE PARAMETERS\nC IN THE ORDER XI, ALPHA, K (LOCATION, SCALE, SHAPE).\nC\nC OTHER ROUTINES USED: DLGAMA\nC\nC METHOD: FOR -0.8 LE TAU3 LT 1, K IS APPROXIMATED BY RATIONAL\nC FUNCTIONS AS IN DONALDSON (1996, COMMUN. STATIST. SIMUL. COMPUT.).\nC IF TAU3 IS OUTSIDE THIS RANGE, NEWTON-RAPHSON ITERATION IS USED.\nC\n IMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DOUBLE PRECISION XMOM(3),PARA(3)\n DATA ZERO/0D0/,HALF/0.5D0/,ONE/1D0/,TWO/2D0/,THREE/3D0/\n DATA P8/0.8D0/,P97/0.97D0/\nC\nC SMALL IS USED TO TEST WHETHER K IS EFFECTIVELY ZERO\nC EPS,MAXIT CONTROL THE TEST FOR CONVERGENCE OF N-R ITERATION\nC\n DATA SMALL/1D-5/,EPS/1D-6/,MAXIT/20/\nC\nC EU IS EULER'S CONSTANT\nC DL2 IS LOG(2), DL3 IS LOG(3)\nC\n DATA EU/0.57721566D0/,DL2/0.69314718D0/,DL3/1.0986123D0/\nC\nC COEFFICIENTS OF RATIONAL-FUNCTION APPROXIMATIONS FOR K\nC\n DATA A0,A1,A2/ 0.28377530D0,-1.21096399D0,-2.50728214D0/\n DATA A3,A4 /-1.13455566D0,-0.07138022D0/\n DATA B1,B2,B3/ 2.06189696D0, 1.31912239D0, 0.25077104D0/\n DATA C1,C2,C3/ 1.59921491D0,-0.48832213D0, 0.01573152D0/\n DATA D1,D2 /-0.64363929D0, 0.08985247D0/\nC\n T3=XMOM(3)\n IF(XMOM(2).LE.ZERO)GOTO 1000\n IF(DABS(T3).GE.ONE)GOTO 1000\n IF(T3.LE.ZERO)GOTO 10\nC\nC RATIONAL-FUNCTION APPROXIMATION FOR TAU3 BETWEEN 0 AND 1\nC\n Z=ONE-T3\n G=(-ONE+Z*(C1+Z*(C2+Z*C3)))/(ONE+Z*(D1+Z*D2))\n IF(DABS(G).LT.SMALL)GOTO 50\n GOTO 40\nC\nC RATIONAL-FUNCTION APPROXIMATION FOR TAU3 BETWEEN -0.8 AND 0\nC\n 10 G=(A0+T3*(A1+T3*(A2+T3*(A3+T3*A4))))/(ONE+T3*(B1+T3*(B2+T3*B3)))\n IF(T3.GE.-P8)GOTO 40\nC\nC NEWTON-RAPHSON ITERATION FOR TAU3 LESS THAN -0.8\nC\n IF(T3.LE.-P97)G=ONE-DLOG(ONE+T3)/DL2\n T0=(T3+THREE)*HALF\n DO 20 IT=1,MAXIT\n X2=TWO**(-G)\n X3=THREE**(-G)\n XX2=ONE-X2\n XX3=ONE-X3\n T=XX3/XX2\n DERIV=(XX2*X3*DL3-XX3*X2*DL2)/(XX2*XX2)\n GOLD=G\n G=G-(T-T0)/DERIV\n IF(DABS(G-GOLD).LE.EPS*G)GOTO 30\n 20 CONTINUE\n WRITE(6,7010)\n 30 CONTINUE\nC\nC ESTIMATE ALPHA,XI\nC\n 40 PARA(3)=G\n GAM=DEXP(DLGAMA(ONE+G))\n PARA(2)=XMOM(2)*G/(GAM*(ONE-TWO**(-G)))\n PARA(1)=XMOM(1)-PARA(2)*(ONE-GAM)/G\n RETURN\nC\nC ESTIMATED K EFFECTIVELY ZERO\nC\n 50 PARA(3)=ZERO\n PARA(2)=XMOM(2)/DL2\n PARA(1)=XMOM(1)-EU*PARA(2)\n RETURN\nC\n 1000 WRITE(6,7000)\n RETURN\nC\n 7000 FORMAT(' *** ERROR *** ROUTINE PELGEV : L-MOMENTS INVALID')\n 7010 FORMAT(' ** WARNING ** ROUTINE PELGEV :',\n * ' ITERATION HAS NOT CONVERGED. RESULTS MAY BE UNRELIABLE.')\n END\n", "meta": {"hexsha": "5de05cfede289bea99b2c40cdff4abb214649f1e", "size": 3947, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "contrib/lmoments/Src/pelgev.for", "max_stars_repo_name": "xylar/cdat", "max_stars_repo_head_hexsha": "8a5080cb18febfde365efc96147e25f51494a2bf", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 62, "max_stars_repo_stars_event_min_datetime": "2018-03-30T15:46:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-08T23:30:24.000Z", "max_issues_repo_path": "contrib/lmoments/Src/pelgev.for", "max_issues_repo_name": "xylar/cdat", "max_issues_repo_head_hexsha": "8a5080cb18febfde365efc96147e25f51494a2bf", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 114, "max_issues_repo_issues_event_min_datetime": "2018-03-21T01:12:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-05T12:29:54.000Z", "max_forks_repo_path": "contrib/lmoments/Src/pelgev.for", "max_forks_repo_name": "CDAT/uvcdat", "max_forks_repo_head_hexsha": "5133560c0c049b5c93ee321ba0af494253b44f91", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2018-06-06T02:42:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-26T03:27:00.000Z", "avg_line_length": 35.2410714286, "max_line_length": 72, "alphanum_fraction": 0.5140613124, "num_tokens": 1395, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299509069106, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.6848314939548422}} {"text": "program ho_wf\n use numerical_integration\n implicit none\n integer, parameter :: nmax = 10, num_pts = 101 ! Number of H.O. basis functions\n integer :: m, n, i, j\n real(kind=dp), parameter :: pi_4_root = sqrt(sqrt(pi))\n real(kind=dp) :: x_min, x_max, dx, x_pts(num_pts)\n real(kind=dp), dimension(0:nmax-1, 0:nmax-1) :: inner_prod, pot_e, kin_e, ham\n real(kind=dp), dimension(num_pts, 0:nmax-1) :: wf, wf_deriv2\n\n x_min = -10.0d0; x_max = 10.0d0\n dx = (x_max-x_min)/(num_pts-1)\n x_pts = [ (x_min+i*dx, i=0, num_pts-1) ]\n\n\n call gen_wf(x_pts, num_pts, nmax, wf, wf_deriv2)\n\n ! Calculate second derivative\n\n ! Print Wavefunctions upto order N\n open(unit=50, file='howf_data.txt')\n do i=1,num_pts\n write(50, *) x_pts(i), wf(i, :)\n end do\n close(50)\n\n ! Calculate orthogonality\n do i=0,nmax-1\n do j=0,nmax-1\n inner_prod(i,j) = simpson(x_pts, wf(:,i)*wf(:,j), num_pts)\n pot_e(i, j) = simpson(x_pts, wf(:,i)*wf(:,j)*pot_func(x_pts,num_pts), num_pts)\n kin_e(i,j) = simpson(x_pts, -wf(:,i)*wf_deriv2(:,j), num_pts)\n end do\n end do\n\n ham = kin_e + pot_e\n\n open(unit=50, file='ortho_data.txt')\n open(unit=51, file='pot_e_data.txt')\n open(unit=52, file='kin_e_data.txt')\n open(unit=53, file='ham_data.txt')\n do i=0,nmax-1\n write(50,*) inner_prod(i,:)\n write(51,*) pot_e(i,:)\n write(52,*) kin_e(i,:)\n write(53,*) ham(i,:)\n end do\n close(50)\n close(51)\n close(52)\n close(53)\ncontains\n function pot_func(x, n)\n integer, intent(in) :: n\n real(kind=dp) :: pot_func(n)\n real(kind=dp), intent(in) :: x(n)\n\n pot_func = x**2\n end function pot_func\n\n subroutine gen_wf(x_pts, num_pts, max_order, wf, wf_deriv2)\n ! Generates harmonic oscillator wavefunctions upto order max_order\n ! Wavefunction order starts from 0\n implicit none\n integer, intent(in) :: max_order, num_pts\n real(kind=dp), intent(in) :: x_pts(num_pts)\n real(kind=dp), intent(inout), dimension(num_pts, 0:max_order-1) :: wf, wf_deriv2\n integer :: i, j, k\n\n wf(:,0) = exp(-0.5d0*x_pts**2)/pi_4_root\n wf_deriv2(:,0) = (x_pts**2 - 1)*wf(:,0)\n if (nmax > 1) then\n wf(:,1) = sqrt(2.0d0)*x_pts*wf(:,0)\n wf_deriv2(:,1) = (x_pts**2 - 1)*wf(:,1) - sqrt(8.0d0)*x_pts*wf(:,0)\n do i=2, max_order-1\n wf(:,i) = sqrt(2.0d0/i)*x_pts*wf(:,i-1) - sqrt(float(i-1)/i)*wf(:,i-2)\n wf_deriv2(:,i) = 2*sqrt(float(i*(i-1)))*wf(:,i-2) - sqrt(8.0d0*i)*x_pts*wf(:,i-1) &\n + (x_pts**2 - 1)*wf(:,i)\n end do\n end if\n\n end subroutine gen_wf \n\nend program ho_wf\n", "meta": {"hexsha": "57fb0e110e04bf0ec78eee71261d6fd7f69fae55", "size": 3151, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "exercises/ho_wf.f90", "max_stars_repo_name": "deadbeatfour/phn624-comp-nuc-phy", "max_stars_repo_head_hexsha": "deaeaac5240a1f33425c4ca50539aee4fae2f370", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "exercises/ho_wf.f90", "max_issues_repo_name": "deadbeatfour/phn624-comp-nuc-phy", "max_issues_repo_head_hexsha": "deaeaac5240a1f33425c4ca50539aee4fae2f370", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "exercises/ho_wf.f90", "max_forks_repo_name": "deadbeatfour/phn624-comp-nuc-phy", "max_forks_repo_head_hexsha": "deaeaac5240a1f33425c4ca50539aee4fae2f370", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.0705882353, "max_line_length": 110, "alphanum_fraction": 0.489685814, "num_tokens": 939, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.7718434978390746, "lm_q1q2_score": 0.6847830969135068}} {"text": "!##############################################################################\n! MODULE Globals\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!##############################################################################\nmodule Globals\n\n implicit none\n\n ! time preference\n real*8 :: beta\n\n ! risk aversion\n real*8 :: eta\n\nend module\n\n\n!##############################################################################\n! MODULE UtilFunc\n!##############################################################################\nmodule UtilFunc\n\n implicit none\n\ncontains\n\n\n ! a utility function\n function utility(c1, c2)\n\n use Globals\n\n implicit none\n real*8, intent(in) :: c1, c2\n real*8 :: utility\n\n utility = 1d0/(1d0-eta)*c1**(1d0-eta) + beta/(1d0-eta)*c2**(1d0-eta)\n\n end function\n\nend module\n", "meta": {"hexsha": "23482e5279005c985487c9d6020ab7e1deccad2f", "size": 1062, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "complete/prog01/prog01_16/prog01_16m.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/prog01/prog01_16/prog01_16m.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/prog01/prog01_16/prog01_16m.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": 21.24, "max_line_length": 79, "alphanum_fraction": 0.4218455744, "num_tokens": 234, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818986, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6847830968611457}} {"text": " SUBROUTINE LPMNS(M,N,X,PM,PD)\nc**************************************************************\nC\nC ========================================================\nC Purpose: Compute associated Legendre functions Pmn(x)\nC and Pmn'(x) for a given order\nC Input : x --- Argument of Pmn(x)\nC m --- Order of Pmn(x), m = 0,1,2,...,n\nC n --- Degree of Pmn(x), n = 0,1,2,...,N\nC Output: PM(n) --- Pmn(x)\nC PD(n) --- Pmn'(x)\nC ========================================================\nC\n IMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION PM(0:N),PD(0:N)\n DO 10 K=0,N\n PM(K)=0.0D0\n10 PD(K)=0.0D0\n IF (DABS(X).EQ.1.0D0) THEN\n DO 15 K=0,N\n IF (M.EQ.0) THEN\n PM(K)=1.0D0\n PD(K)=0.5D0*K*(K+1.0)\n IF (X.LT.0.0) THEN\n PM(K)=(-1)**K*PM(K)\n PD(K)=(-1)**(K+1)*PD(K)\n ENDIF\n ELSE IF (M.EQ.1) THEN\n PD(K)=1.0D+300\n ELSE IF (M.EQ.2) THEN\n PD(K)=-0.25D0*(K+2.0)*(K+1.0)*K*(K-1.0)\n IF (X.LT.0.0) PD(K)=(-1)**(K+1)*PD(K)\n ENDIF\n15 CONTINUE\n RETURN\n ENDIF\n X0=DABS(1.0D0-X*X)\n PM0=1.0D0\n PMK=PM0\n DO 20 K=1,M\n PMK=(2.0D0*K-1.0D0)*DSQRT(X0)*PM0\n20 PM0=PMK\n PM1=(2.0D0*M+1.0D0)*X*PM0\n PM(M)=PMK\n PM(M+1)=PM1\n DO 25 K=M+2,N\n PM2=((2.0D0*K-1.0D0)*X*PM1-(K+M-1.0D0)*PMK)/(K-M)\n PM(K)=PM2\n PMK=PM1\n25 PM1=PM2\n PD(0)=((1.0D0-M)*PM(1)-X*PM(0))/(X*X-1.0) \n DO 30 K=1,N\n30 PD(K)=(K*X*PM(K)-(K+M)*PM(K-1))/(X*X-1.0D0)\n RETURN\n END\n", "meta": {"hexsha": "d4d0412a7e729baac757933547cf84d4ab0938a9", "size": 1815, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "MATLAB/f2matlab/examples/lpmns.f", "max_stars_repo_name": "vasaantk/bin", "max_stars_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MATLAB/f2matlab/examples/lpmns.f", "max_issues_repo_name": "vasaantk/bin", "max_issues_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MATLAB/f2matlab/examples/lpmns.f", "max_forks_repo_name": "vasaantk/bin", "max_forks_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.4107142857, "max_line_length": 64, "alphanum_fraction": 0.3454545455, "num_tokens": 666, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045966995027, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6847830945592028}} {"text": "c\nc-----------------------------------------------------------------------\nc main program: test program to exercise the wfta subroutine\nc the test waveform is a complex exponential a**i whose\nc transform is known analytically to be (1 - a**n)/(1 - a*w**k).\nc\nc authors:\nc james h. mcclellan and hamid nawab\nc department of electrical engineering and computer science\nc massachusetts of technology\nc cambridge, mass. 02139\nc\nc inputs:\nc n-- transform length. it must be formed as the product of\nc relatively prime integers from the set:\nc 2,3,4,5,7,8,9,16\nc invrs is the flag for forward or inverse transform.\nc invrs = 1 yields inverse transform\nc invrs .ne. 1 gives forward transform\nc rad and phi are the magnitude and angle (as a fraction of\nc 2*pi/n) of the complex exponential test signal.\nc suggestion: rad = 0.98, phi = 0.5.\nc-----------------------------------------------------------------------\nc\n double precision pi2,pin,xn,xj,xt\n dimension xr(1260),xi(1260)\n complex cone,ca,can,cnum,cden\nc\nc output will be punched\nc\n iout=i1mach(3)\n input=i1mach(1)\n cone=cmplx(1.0,0.0)\n pi2=8.0d0*datan(1.0d0)\n50 continue\n read(input,130)n\n130 format(i5)\n write(iout,150) n\n150 format(10h length = ,i5)\n if(n.le.0 .or. n.gt.1260) stop\nc\nc enter a 1 to perform the inverse\nc\nc read(input,130) invrs\n invrs = 0\nc\nc enter magnitude and angle (in fraction of 2*pi/n)\nc avoid multiples of n for the angle if the radius is\nc close to one. suggestion: rad = 0.98, phi = 0.5.\nc\nc read(input,160) rad,phi\n rad = 0.98\n phi = 0.5\n160 format(2f15.10)\n xn=float(n)\n pin=phi\n pin=pin*pi2/xn\nc\nc generate z**j\nc\n init=0\n do 200 j=1,n\n an=rad**(j-1)\n xj=j-1\n xj=xj*pin\n xt=dcos(xj)\n xr(j)=xt\n xr(j)=xr(j)*an\n xt=dsin(xj)\n xi(j)=xt\n xi(j)=xi(j)*an\n200 continue\n can=cmplx(xr(n),xi(n))\n ca=cmplx(xr(2),xi(2))\n can=can*ca\nc\nc print first 50 values of input sequence\nc\n max=50\n if(n.lt.50)max=n\n write(iout,300)(j,xr(j),xi(j),j=1,max)\nc\nc call the winograd fourier transform algorithm\nc\n call wfta(xr,xi,n,invrs,init,ierr)\nc\nc check for error return\nc\n if(ierr.lt.0) write(iout,250) ierr\n250 format(1x,5herror,i5)\n if(ierr.lt.0) go to 50\nc\nc print first 50 values of the transformed sequence\nc\n write(iout,300)(j,xr(j),xi(j),j=1,max)\n300 format(1x,3hj =,i3,6hreal =,e20.12,6himag =,e20.12)\nc\nc calculate absolute and relative deviations\nc\n devabs=0.0\n devrel=0.0\n cnum=cone-can\n pin=pi2/xn\n do 350 j=1,n\n xj=j-1\n xj=-xj*pin\n if(invrs.eq.1) xj=-xj\n tr=dcos(xj)\n ti=dsin(xj)\n can=cmplx(tr,ti)\n cden=cone-ca*can\n cden=cnum/cden\nc\nc true value of the transform (1. - a**n)/(1. - a*w**k),\nc where a = rad*exp(j*phi*(2*pi/n)), w = exp(-j*2*pi/n).\nc for the inverse transform the complex exponential w\nc is conjugated.\nc\n tr=real(cden)\n ti=aimag(cden)\n if(invrs.ne.1) go to 330\nc\nc scale inverse transform by 1/n\nc\n tr=tr/float(n)\n ti=ti/float(n)\n330 tr=xr(j)-tr\n ti=xi(j)-ti\n devabs=sqrt(tr*tr+ti*ti)\n xmag=sqrt(xr(j)*xr(j)+xi(j)*xi(j))\n devrel=100.0*devabs/xmag\n if(devabs.le.devmx1)go to 340\n devmx1=devabs\n labs=j-1\n340 if(devrel.le.devmx2)go to 350\n devmx2=devrel\n lrel=j-1\n350 continue\nc\nc print the absolute and relative deviations together\nc with their locations.\nc\n write(iout,380) devabs,labs,devrel,lrel\n380 format(1x,21habsolute deviation = ,e20.12,9h at index,i5/\n 1 1x,21hrelative deviation = ,f11.7,8h percent,1x,9h at index,i5)\n go to 50\n end\n", "meta": {"hexsha": "15a34788fde407afe7d3ef4a4500868bdd03cc86", "size": 3816, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iraf.v2161/math/ieee/chap1/test/test17.f", "max_stars_repo_name": "ysBach/irafdocgen", "max_stars_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:19:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T16:48:42.000Z", "max_issues_repo_path": "iraf.v2161/math/ieee/chap1/test/test17.f", "max_issues_repo_name": "ysBach/irafdocgen", "max_issues_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-30T13:48:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-02T19:40:25.000Z", "max_forks_repo_path": "iraf.v2161/math/ieee/chap1/test/test17.f", "max_forks_repo_name": "ysBach/irafdocgen", "max_forks_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_forks_repo_licenses": ["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.7837837838, "max_line_length": 72, "alphanum_fraction": 0.5917190776, "num_tokens": 1363, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045907347107, "lm_q2_score": 0.7718434925908524, "lm_q1q2_score": 0.6847830899553169}} {"text": "program test_program\n implicit none\n \n integer :: i, j\n integer, dimension(5,3) :: M\n integer, dimension(3,3) :: A, B\n\n do i = 1, 5\n do j = 1, 3\n M(i,j) = i+j\n end do\n end do\n write(*,*) \"nrows\", size(M,1)\n write(*,*) \"ncols\", size(M,2)\n do i = 1, size(M,1)\n write(*,*) (M(i,j), j = 1, size(M,2))\n end do\n write(*,*)\n\n A = (reshape((/ 1, 2, 3, 4, 5, 6, 7, 8, 9 /), shape(A)))\n do i = 1,size(A,1)\n write(*,*) (A(i,j), j = 1, size(A,2))\n end do\n write(*,*)\n\n B = transpose(reshape((/ 1, 2, 3, 4, 5, 6, 7, 8, 9 /), shape(B)))\n do i = 1, size(B,1)\n write(*,*) (B(i,j), j = 1, size(B,2))\n end do\nend program test_program\n", "meta": {"hexsha": "a06523fd025260260c7525e944c5510e50e85507", "size": 686, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "1_generate_initial_structures/Generate_crystal_coordinates/graphite/with_dangling_bonds/test.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/test.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/test.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": 22.1290322581, "max_line_length": 68, "alphanum_fraction": 0.4606413994, "num_tokens": 305, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711756575749, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.6847641407992696}} {"text": "c program DRSBLAS1\nc>> 1996-06-18 DRSBLAS1 Krogh Minor format change for C conversion.\nc>> 1996-05-28 DRSBLAS1 Krogh Added external statement.\nc>> 1994-10-19 DRSBLAS1 Krogh Changes to use M77CON\nc>> 1992-03-24 DRSBLAS1 CLL Removed reference to REAL() function.\nc>> 1991-12-02 DRSBLAS1 CLL\nc>> 1991-07-25 DRSBLAS1 CLL\nc>> 1987-12-09 DRBLAS1 Lawson Initial Code.\nc\nc Demonstrate usage of SAXPY, SCOPY, and SDOT from the BLAS\nc by computing\nc (1) p = A * b using SDOT\nc (2) q = A * b using SCOPY & SAXPY\nc (3) r = (A Transposed) * p using SDOT\nc (4) S = A * E using SDOT\nc ------------------------------------------------------------------\nc--S replaces \"?\": DR?BLAS1, ?AXPY, ?COPY, ?DOT\nc ------------------------------------------------------------------\n external SDOT\n real SDOT\n integer M2, M3, M4, N2, N3, N4\n parameter ( M2=5, M3=10, M4=12 )\n parameter ( N2=2, N3=3, N4=4 )\n integer I, J\n real A(M2,M3), E(M3,M4), S(M2,M4)\n real B(M3), P(M2), Q(M2), R(M3)\n real ZERO(1)\nc\n data ZERO(1) / 0.0e0 /\n data (A(1,J),J=1,N3) / 2.0e0, -4.0e0, 3.0e0 /\n data (A(2,J),J=1,N3) / -5.0e0, -2.0e0, 6.0e0 /\n data (B(J),J=1,N3) / 7.0e0, -3.0e0, 5.0e0 /\n data (E(1,J),J=1,N4) / -4.0e0, 2.0e0, 3.0e0, -6.0e0 /\n data (E(2,J),J=1,N4) / 7.0e0, 5.0e0, -6.0e0, -3.0e0 /\n data (E(3,J),J=1,N4) / 3.0e0, 4.0e0, -2.0e0, 5.0e0 /\nc ---------------------------------------------------------------\nc\nc 1. p = A * b using SDOT\nc\n do 10 I = 1, N2\n P(I) = SDOT(N3,A(I,1),M2,B,1)\n 10 continue\nc\nc 2. q = A * b using SCOPY and SAXPY\nc\n call SCOPY(N2,ZERO,0,Q,1)\n do 20 J = 1, N3\n call SAXPY(N2,B(J),A(1,J),1,Q,1)\n 20 continue\nc\nc 3. r = (A Transposed) * p using SDOT\nc\n do 30 J = 1, N3\n R(J) = SDOT(N2,A(1,J),1,P,1)\n 30 continue\nc\nc 4. S = A * E using SDOT\nc\n do 50 I = 1, N2\n do 40 J = 1, N4\n S(I,J) = SDOT(N3,A(I,1),M2,E(1,J),1)\n 40 continue\n 50 continue\nc\n print*,'DRSBLAS1.. Demo driver for SAXPY, SCOPY, and SDOT'\n print'(/'' P() = '', 7x,4f8.1)', (P(J),J=1,N2)\n print'(/'' Q() = '',7x,4f8.1)', (Q(J),J=1,N2)\n print'(/'' R() = '',7x,4f8.1)', (R(J),J=1,N3)\n print'(/'' S(,) = '')'\n do 60 I = 1,N2\n print'('' Row '',i2,5x,4f8.1)', I,(S(I,J),J=1,N4)\n 60 continue\n stop\n end\n", "meta": {"hexsha": "2354b0034ecef456a7924cd3bb9adb47c61efab4", "size": 2621, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drsblas1.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drsblas1.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drsblas1.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": 34.9466666667, "max_line_length": 72, "alphanum_fraction": 0.4357115605, "num_tokens": 1092, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563335, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6847621479226975}} {"text": "c FILE: fplfit.f\n subroutine plfit(x,nosmall,ksa,av,lx)\nc internal section of plfit\nc requires that x be sorted!\n integer lx,nosmall\n real*8 x(lx)\n real*8 ksa(lx)\n real*8 av(lx)\ncf2py intent(in) :: x, nosmall\ncf2py intent(hide) :: lx\ncf2py intent(out) :: av,ksa\n integer j,n,k,nk\n real*8 lzs,cx,cf,ks,ksp,xmin\n xmin = 0.0\nc write(*,*) \"Starting length \",lx,\" run\"\nc equivalent to python loop: i in arange(1,lx) \n do 100 i=1,lx\n if ( x(i) .lt. xmin ) write(*,*) \"WARNING X WAS NOT SORTED!\"\nc skip repeat values (only compute unique values of xmin) \n if ( x(i) .eq. xmin ) then\n ksa(i)=0\n av(i)=0\n goto 100\n endif\n xmin = x(i)\n\nc a = 1 + float(n) / sum(log(x/xmin))\nc lzs = sum(log(x/xmin)) \n lzs = 0.0\n do 200 j=i,lx\n lzs = lzs + log(x(j)/xmin)\n200 continue \n n = j - i\n av(i) = 1.0 + float(n) / (lzs)\n\n if (nosmall.gt.0) then\n if ((av(i)-1.0)/sqrt(float(n+1)) .ge. 0.1) then\nc write(*,*) \"Exiting nosmall - n=\",n\nc write(*,*) \"Debug: lx=\",lx,\"n=\",n,\"ijk=\",i,j,k,av(i),ksa(i)\n return\n endif\n endif\n\nc ks = max(abs(cf-cx))\n ksp = 0\nc if (mod(i,100).eq.0) write(*,*) \"i=\",i,\" a=\",a,\"n=\",\nc & n,\"lzs=\",lzs\n nk = lx - i\nc nk = number of points between xmin and the largest value\nc k = the index of xmin + k \n do 300 k=0,nk\n cx = float(k) / float(nk+1)\n cf = 1.0 - ( (xmin/x(k+i))**(av(i)-1) )\n ks = abs(cf-cx)\n if (ks.gt.ksp) ksp = ks \n300 continue \nc write(*,*) \"k=\",k,\"n=\",n,\"i=\",i,\"nk=\",nk,\"j=\",j,\"cx=\",cx\n ksa(i) = ksp\n100 continue\nc write(*,*) \"Debug: lx=\",lx,\"n=\",n,\"ijk=\",i,j,k,av(i),ksa(i)\n return\n END\nc END FILE fplfit.f\n", "meta": {"hexsha": "9ce409cf93ed44b4fbc2013a1986d2dfb77d720b", "size": 2119, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "plfit/fplfit.f", "max_stars_repo_name": "keflavich/plfit", "max_stars_repo_head_hexsha": "a5f2f56f4a1f1a11b8e29b5033a6ebc23d1c078e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 67, "max_stars_repo_stars_event_min_datetime": "2015-01-30T11:45:53.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-09T13:18:24.000Z", "max_issues_repo_path": "plfit/fplfit.f", "max_issues_repo_name": "keflavich/plfit", "max_issues_repo_head_hexsha": "a5f2f56f4a1f1a11b8e29b5033a6ebc23d1c078e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-05-10T18:52:31.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-30T12:47:59.000Z", "max_forks_repo_path": "plfit/fplfit.f", "max_forks_repo_name": "keflavich/plfit", "max_forks_repo_head_hexsha": "a5f2f56f4a1f1a11b8e29b5033a6ebc23d1c078e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 25, "max_forks_repo_forks_event_min_datetime": "2015-07-03T21:20:26.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-12T13:54:36.000Z", "avg_line_length": 33.109375, "max_line_length": 79, "alphanum_fraction": 0.4261444077, "num_tokens": 686, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392725805822, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.6847621268899744}} {"text": "program random_integers\n implicit none\n integer :: nr_values, lower, upper, i\n\n call get_values(nr_values, lower, upper)\n do i = 1, nr_values\n print '(I0)', random_integer(lower, upper)\n end do\n\ncontains\n\n !> @brief copmute a random number in a given range\n !>\n !> The function returns a random integer value between a given lower and\n !> upper limits, inclusively.\n !>\n !> @param[in] lower lower value for the random value\n !> @param[in] upper upper value for the random value\n !> @returns integer value\n function random_integer(lower, upper) result(rand_int)\n implicit none\n integer, value :: lower, upper\n integer :: rand_int\n real :: rand_real\n\n call random_number(rand_real)\n rand_int = lower + floor(rand_real*(upper - lower + 1))\n end function random_integer\n\n subroutine get_values(nr_values, lower, upper)\n use, intrinsic :: iso_fortran_env, only : error_unit\n implicit none\n integer, intent(out) :: nr_values, lower, upper\n\n if (command_argument_count() /= 3) then\n write (unit=error_unit, fmt='(A)') &\n 'error: argument nr_values lower upper expected'\n stop 1\n end if\n nr_values = get_integer(1)\n lower = get_integer(2)\n upper = get_integer(3)\n if (lower > upper) then\n write (unit=error_unit, fmt='(A)') &\n 'error: upper should be larger or equal to lower'\n stop 3\n end if\n end subroutine get_values\n\n function get_integer(i) result(value)\n use, intrinsic :: iso_fortran_env, only : error_unit\n implicit none\n integer, value :: i\n integer :: value\n character(len=32) :: buffer\n integer :: istat\n character(len=1024) :: msg\n \n call get_command_argument(i, buffer)\n read (buffer, fmt=*, iostat=istat, iomsg=msg) value\n if (istat /= 0) then\n write (unit=error_unit, fmt='(2A)') 'error: ', msg\n stop 2\n end if\n end function get_integer\n\nend program random_integers\n", "meta": {"hexsha": "22bf117d9600c2a6d70c090aba3b689b87fa5c24", "size": 2129, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source_code/random_numbers/random_integers.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/random_numbers/random_integers.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/random_numbers/random_integers.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": 31.3088235294, "max_line_length": 76, "alphanum_fraction": 0.6040394551, "num_tokens": 531, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391602943619, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.6847610227191578}} {"text": " PROGRAM vec2los\nC----\nC Take three-dimensional N-E-Z displacements and compute line-of-sight\nC displacements given the azimuth (from north) and inclination (from\nC horizontal) of the view\nC----\n IMPLICIT NONE\n REAL*8 pi,d2r\n PARAMETER (pi=4.0d0*atan(1.0d0),d2r=pi/180.0d0)\n REAL*8 uLOS,stlo,stla,stdp,uN,uE,uZ\n REAL*8 az,incl,cosaz,cosinc,sinaz,sininc\n CHARACTER*40 ifile,ofile\n LOGICAL ex\n\nC----\nC Parse command line\nC----\n call gcmdln(az,incl,ifile,ofile)\n if (az.lt.-1000.0d0.or.incl.lt.-1000.0d0) then\n write(*,*) '!! Error: azimuth or inclination are undefined'\n call usage('!! Use -a AZ or -i INCL')\n endif\n if (ifile.eq.'none') then\n write(*,*) '!! Error: Input displacement vector file ',\n 1 'unspecified'\n call usage('!! Use -f IFILE to specify input file')\n else\n inquire(file=ifile,EXIST=ex)\n if (.not.ex) call usage('!! Error: no input file: '//ifile)\n endif\n if (ofile.eq.'none') then\n write(*,*) '!! Error: No output file specified'\n call usage('!! Use -o OFILE to specify LOS output file')\n endif\n cosaz = dcos(az*d2r)\n sinaz = dsin(az*d2r)\n cosinc = dcos(incl*d2r)\n sininc = dsin(incl*d2r)\n !print *,'AZ',az\n !print *,'INCL',incl\n !print *,'IFILE ',ifile \n !print *,'OFILE ',ofile\n\nC----\nC Control files\nC----\n open (unit=11,file=ifile,status='old')\n open (unit=12,file=ofile,status='unknown')\n\nC----\nC Convert NEZ to LOS\nC----\n 11 read (11,*,end=12) stlo,stla,stdp,uE,uN,uZ\n uLOS = uN*cosaz*cosinc\n 1 + uE*sinaz*cosinc\n 2 - uZ*sininc\n write (12,9991) stlo,stla,stdp,uLOS\n goto 11\n 12 continue\n\n 9991 format(3F12.4,X,3E12.4)\n\n END\n\nC======================================================================C\n\n SUBROUTINE gcmdln(az,incl,ifile,ofile)\n IMPLICIT none\n REAL*8 az,incl\n CHARACTER*40 tag,ifile,ofile\n INTEGER i,narg\n az = -99999.0d0\n incl = -99999.0d0\n ifile = 'none'\n ofile = 'none'\n narg = iargc()\n if (narg.eq.0) then\n call usage('!! Error: no command line arguments specified')\n endif\n i = 0\n 11 i = i + 1\n if (i.gt.narg) goto 12\n call getarg(i,tag)\n if (tag(1:2).eq.'-a') then\n i = i + 1\n call getarg(i,tag)\n read (tag,'(BN,F12.0)') az\n elseif (tag(1:2).eq.'-i') then\n i = i + 1\n call getarg(i,tag)\n read (tag,'(BN,F12.0)') incl\n elseif (tag(1:2).eq.'-f') then\n i = i + 1\n call getarg(i,ifile)\n elseif (tag(1:2).eq.'-o') then\n i = i + 1\n call getarg(i,ofile)\n elseif (tag(1:2).eq.'-h') then\n call usage(' ')\n endif\n goto 11\n 12 continue\n RETURN\n END\n\nC----------------------------------------------------------------------C\n\n SUBROUTINE usage(str)\n IMPLICIT none\n INTEGER lstr\n CHARACTER str*(*)\n if (str.ne.' ') then\n lstr = len(str)\n write(*,*) str(1:lstr)\n write(*,*)\n endif\n write(*,*)\n 1 'Usage: vec2los -a AZ -i INC -f IFILE -o OFILE [-h]'\n write(*,*)\n write(*,*)\n 1 '-a AZ Look azimuth (CW from N)'\n write(*,*)\n 1 '-i INC Look inclination (from horizontal)'\n write(*,*)\n 1 '-f IFILE Input vector displacement file (stlo stla stdp uE ',\n 2 'uN uZ)'\n write(*,*)\n 1 '-o OFILE Output LOS displacement file (stlo stla stdp uLOS)'\n write (*,*)\n 1 '-h Online help (this message)'\n write (*,*)\n STOP\n END\n\n", "meta": {"hexsha": "dc5ea8db412e37a07e25f20d70a95e1d4b32937f", "size": 3832, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/vec2los.f", "max_stars_repo_name": "mherman09/src", "max_stars_repo_head_hexsha": "98667f7a2f2e724f2544b6aa1fe7ff278cbf4801", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/vec2los.f", "max_issues_repo_name": "mherman09/src", "max_issues_repo_head_hexsha": "98667f7a2f2e724f2544b6aa1fe7ff278cbf4801", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2017-06-27T16:35:46.000Z", "max_issues_repo_issues_event_max_datetime": "2017-07-16T14:55:39.000Z", "max_forks_repo_path": "src/vec2los.f", "max_forks_repo_name": "mherman09/src", "max_forks_repo_head_hexsha": "98667f7a2f2e724f2544b6aa1fe7ff278cbf4801", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.3851851852, "max_line_length": 72, "alphanum_fraction": 0.490605428, "num_tokens": 1182, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391602943619, "lm_q2_score": 0.793105951184112, "lm_q1q2_score": 0.6847610184969741}} {"text": " real function backtr(vrgs,nt,vr,vrg,zmin,zmax,ltail,ltpar,\n + utail,utpar)\nc-----------------------------------------------------------------------\nc\nc Back Transform Univariate Data from Normal Scores\nc *************************************************\nc\nc This subroutine backtransforms a standard normal deviate from a\nc specified back transform table and option for the tails of the\nc distribution. Call once with \"first\" set to true then set to false\nc unless one of the options for the tail changes.\nc\nc\nc\nc INPUT VARIABLES:\nc\nc vrgs normal score value to be back transformed\nc nt number of values in the back transform tbale\nc vr(nt) original data values that were transformed\nc vrg(nt) the corresponding transformed values\nc zmin,zmax limits possibly used for linear or power model\nc ltail option to handle values less than vrg(1):\nc ltpar parameter required for option ltail\nc utail option to handle values greater than vrg(nt):\nc utpar parameter required for option utail\nc\nc\nc\nc-----------------------------------------------------------------------\n\n implicit integer (i-n)\n implicit double precision (a-h,o-z)\n\n parameter(EPSLON=1.0e-20)\n dimension vr(nt),vrg(nt)\n real*8 ltpar,utpar,lambda\n integer ltail,utail\nc\nc Value in the lower tail? 1=linear, 2=power, (3 and 4 are invalid):\nc\n if(vrgs.le.vrg(1)) then\n backtr = vr(1)\n cdflo = gcum(vrg(1))\n cdfbt = gcum(vrgs)\n if(ltail.eq.1) then\n backtr = powint(0.d0,cdflo,zmin,vr(1),cdfbt,1.0)\n else if(ltail.eq.2) then\n cpow = 1.0 / ltpar\n backtr = powint(0.d0,cdflo,zmin,vr(1),cdfbt,cpow)\n endif\nc\nc Value in the upper tail? 1=linear, 2=power, 4=hyperbolic:\nc\n else if(vrgs.ge.vrg(nt)) then\n backtr = vr(nt)\n cdfhi = gcum(vrg(nt))\n cdfbt = gcum(vrgs)\n if(utail.eq.1) then\n backtr = powint(cdfhi,1.0,vr(nt),zmax,cdfbt,1.0)\n else if(utail.eq.2) then\n cpow = 1.0 / utpar\n backtr = powint(cdfhi,1.0,vr(nt),zmax,cdfbt,cpow)\n else if(utail.eq.4) then\n lambda = (vr(nt)**utpar)*(1.0-gcum(vrg(nt)))\n backtr = (lambda/(1.0-gcum(vrgs)))**(1.0/utpar)\n endif\n else\nc\nc Value within the transformation table:\nc\n call locate(vrg,nt,1,nt,vrgs,j)\n j = max(min((nt-1),j),1)\n backtr = powint(vrg(j),vrg(j+1),vr(j),vr(j+1),vrgs,1.0)\n endif\n return\n end\n", "meta": {"hexsha": "ce45cd85dc4282d01a091cf4b5cfaefd50fcc9c4", "size": 2753, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Src/Extern/gslib/backtr.f", "max_stars_repo_name": "memmett/BoxLib", "max_stars_repo_head_hexsha": "a235af87d30cbfc721d4d7eb4da9b8daadeded7d", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 79, "max_stars_repo_stars_event_min_datetime": "2015-08-03T18:29:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-15T11:42:40.000Z", "max_issues_repo_path": "Src/Extern/gslib/backtr.f", "max_issues_repo_name": "memmett/BoxLib", "max_issues_repo_head_hexsha": "a235af87d30cbfc721d4d7eb4da9b8daadeded7d", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": 22, "max_issues_repo_issues_event_min_datetime": "2016-06-15T20:46:49.000Z", "max_issues_repo_issues_event_max_datetime": "2018-09-10T21:33:10.000Z", "max_forks_repo_path": "Src/Extern/gslib/backtr.f", "max_forks_repo_name": "memmett/BoxLib", "max_forks_repo_head_hexsha": "a235af87d30cbfc721d4d7eb4da9b8daadeded7d", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": 48, "max_forks_repo_forks_event_min_datetime": "2015-08-05T02:19:33.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-18T12:33:14.000Z", "avg_line_length": 35.7532467532, "max_line_length": 72, "alphanum_fraction": 0.5263349074, "num_tokens": 790, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.6847076897765098}} {"text": "! --------------------------------------------------------------------\n!\n! Copyright (C) 2015 Rocco Meli\n!\n! This program is free software: you can redistribute it and/or modify\n! it under the terms of the GNU General Public License as published by\n! the Free Software Foundation, either version 3 of the License, or\n! (at your option) any later version.\n!\n! This program is distributed in the hope that it will be useful,\n! but WITHOUT ANY WARRANTY; without even the implied warranty of\n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n! GNU General Public License for more details.\n!\n! You should have received a copy of the GNU General Public License\n! along with this program. If not, see .\n!\n! ---------------------------------------------------------------------\n\nMODULE NUCLEAR\n\n USE FACT\n USE CONSTANTS\n USE GAUSSIAN\n\n IMPLICIT NONE\n\n !REAL*8 :: xx\n !INTEGER :: nunu\n\n CONTAINS\n FUNCTION f(j,l,m,a,b)\n !----------------------------------------\n ! Expansion coefficient.\n !----------------------------------------\n !\n ! Source:\n ! Handbook of Computational Chemistry\n ! David Cook\n ! Oxford University Press\n ! 1998\n !\n !----------------------------------------\n\n ! INPUT\n INTEGER, intent(in) :: j, l, m\n REAL*8, intent(in) :: a, b\n\n ! INTERMEDIATE VARIABLES\n INTEGER :: k ! Loop index\n REAl*8 :: tmp ! Temporary product\n\n ! OUTPUT\n REAL*8 :: f\n\n f = 0.0D0\n\n DO k = MAX(0,j-m), MIN(j,l)\n tmp = 1.0D0\n tmp = tmp * binom(l,k) * binom(m,j-k)\n tmp = tmp * a**(l-k) * b**(m+k-j)\n\n f = f + tmp\n END DO\n\n END FUNCTION f\n\n ! -------------\n ! BOYS FUNCTION\n ! -------------\n FUNCTION boys(nu,x)\n ! ------------------------------------------------------------------------\n ! Compute boys function (different strategies for different x)\n ! ------------------------------------------------------------------------\n !\n ! Source:\n ! On the evaluation of Boys functions using downward recursion relation\n ! B. A. Mamedov\n ! Journal of Mathematical Chemistry\n ! 2004\n !\n ! ------------------------------------------------------------------------\n\n IMPLICIT NONE\n\n REAL*8, EXTERNAL :: DGAMIT\n\n ! INPUT\n INTEGER, intent(in) :: nu ! Boys' index\n REAL*8, intent(in) :: x\n\n ! INTERMEDIATE VARIABLES\n !REAL*8 :: prod\n !REAL*8 :: sum\n !REAL*8 :: sumold\n !INTEGER :: idx\n\n ! OUTPUT\n REAL*8 :: boys\n\n boys = 0.0D0\n\n IF (x .LE. 1e-6) THEN ! First order Taylor expansion of the integrand\n\n boys = 1.0D0 / (2.0D0 * nu + 1.0D0) - x / (2.0D0 * nu + 3.0D0)\n\n ELSE\n\n boys = 0.5D0 * DGAMIT(nu + 0.5D0, x) * GAMMA(nu + 0.5D0)\n \n END IF\n\n END FUNCTION boys\n\n FUNCTION A(l,r,i,l1,l2,Ra,Rb,Rc,Rp,eps)\n ! -------------------------------------\n ! Factor A\n ! -------------------------------------\n !\n ! Source:\n ! Handbook of Computational Chemistry\n ! David Cook\n ! Oxford University Press\n ! 1998\n !\n !--------------------------------------\n\n ! INPUT\n INTEGER, intent(in) :: l, r, i , l1, l2\n REAL*8, intent(in) :: Ra, Rb, Rc, Rp, eps\n\n ! OUTPUT\n REAL*8 :: A\n\n A = 1.0D0\n A = A * (-1)**(l)\n A = A * f(l,l1,l2,Rp-Ra,Rp-Rb)\n A = A * (-1)**i\n A = A * factorial(l)\n A = A * (Rp-Rc)**(l - 2*r - 2*i)\n A = A * eps**(r+i)\n A = A / factorial(r)\n A = A / factorial(i)\n A = A / factorial(l - 2*r - 2*i)\n\n END FUNCTION A\n\n\n FUNCTION nuclear_coeff(ax,ay,az,bx,by,bz,aa,bb,Ra,Rb,Rn,Zn) result(Vnn)\n ! -------------------------------------------------------------------------\n ! Compute electon-nucleus integral between two Cartesian Gaussian functions\n ! -------------------------------------------------------------------------\n !\n ! Source:\n ! Handbook of Computational Chemistry\n ! David Cook\n ! Oxford University Press\n ! 1998\n !\n !--------------------------------------------------------------------------\n\n ! INPUT\n INTEGER, intent(in) :: ax, ay, az, bx, by, bz ! Angular momentum coefficients\n REAL*8, intent(in) :: aa, bb ! Exponential Gaussian coefficients\n REAL*8, dimension(3), intent(in) :: Ra, Rb ! Gaussian centers\n REAL*8, dimension(3), intent(in) :: Rn ! Nuclear position\n INTEGER, intent(in) :: Zn ! Nuclear charge\n\n ! INTERMEDIATE VARIABLES\n REAL*8 :: eps\n REAL*8 :: g ! Gaussian produc exponential coefficient\n REAL*8, dimension(3) :: Rp ! Gaussian produc center\n REAL*8 :: cp ! Gaussian product multiplicative constant\n INTEGER :: l, r, i, m, s, j, n, t, k ! Loop indices\n REAL*8 :: AAx, AAy, AAz ! Temporary calls to FUNCTION A\n INTEGER :: nu ! Boys function index\n\n ! OUTPUT\n REAL*8 :: Vnn ! Nuclear matrix element\n\n CALL gaussian_product(aa,bb,Ra,Rb,g,Rp,cp)\n\n eps = 1.0D0 / (4.0D0 * g)\n\n Vnn = 0.0D0\n\n DO l = 0, ax+bx\n DO r = 0, FLOOR(l / 2.0)\n DO i = 0, FLOOR((l - 2*r)/2.0)\n AAx = A(l,r,i,ax,bx,Ra(1),Rb(1),Rn(1),Rp(1),eps)\n\n DO m = 0, ay+by\n DO s = 0, FLOOR(m / 2.0)\n DO j = 0, FLOOR((m - 2*s)/2.0)\n AAy = A(m,s,j,ay,by,Ra(2),Rb(2),Rn(2),Rp(2),eps)\n\n DO n = 0, az+bz\n DO t = 0, FLOOR(n / 2.0)\n DO k = 0, FLOOR((n - 2*t)/2.0)\n AAz = A(n,t,k,az,bz,Ra(3),Rb(3),Rn(3),Rp(3),eps)\n\n nu = l + m + n - 2 * (r + s + t) - (i + j + k)\n\n Vnn = Vnn + AAx * AAy * AAz * boys(nu,g*DOT_PRODUCT(Rp-Rn,Rp-Rn))\n\n END DO ! k\n END DO ! t\n END DO ! n\n END DO ! j\n END DO ! s\n END DO ! m\n END DO ! i\n END DO ! r\n END DO ! l\n\n Vnn = Vnn * (-Zn) * norm(ax,ay,az,aa) * norm(bx,by,bz,bb) * cp * 2.0D0 * PI / g\n\n END FUNCTION nuclear_coeff\n\n\n ! --------------------------------\n ! NUCLEUS-ELECRON POTENTIAL MATRIX\n ! --------------------------------\n SUBROUTINE V_nuclear(Kf,c,basis_D,basis_A,basis_L,basis_R,Vn,Rnn,Znn)\n ! ------------------------------------------\n ! Compute nucleus-electrona potential matrix\n ! ------------------------------------------\n\n IMPLICIT NONE\n\n ! INPUT\n INTEGER, intent(in) :: Kf ! Number of basis functions\n INTEGER, intent(in) :: c ! Number of contractions (TODO)\n REAL*8, dimension(Kf,3), intent(in) :: basis_R ! Basis set niclear positions\n INTEGER, dimension(Kf,3), intent(in) :: basis_L ! Basis set angular momenta\n REAL*8, dimension(Kf,c), intent(in) :: basis_D ! Basis set contraction coefficients\n REAL*8, dimension(Kf,c), intent(in) :: basis_A ! Basis set exponential contraction coefficients\n REAL*8, dimension(3), intent(in) :: Rnn ! Nuclear position\n INTEGER, intent(in) :: Znn ! Nuclear charge (> 0)\n\n ! INTERMEDIATE VARIABLES\n INTEGER :: i,j,k,l\n REAL*8 :: tmp\n\n ! OUTPUT\n REAL*8, dimension(Kf,Kf), intent(out) :: Vn ! Nucleus-electron potential matrix\n\n Vn(:,:) = 0.0D0\n\n DO i = 1,Kf\n DO j = 1,Kf\n DO k = 1,c\n DO l = 1,c\n tmp = basis_D(i,k) * basis_D(j,l)\n tmp = tmp * nuclear_coeff( basis_L(i,1),& ! lx for basis function i\n basis_L(i,2),& ! ly for basis function i\n basis_L(i,3),& ! lz for basis function i\n basis_L(j,1),& ! lx for basis function j\n basis_L(j,2),& ! ly for basis function j\n basis_L(j,3),& ! lz for basis function j\n basis_A(i,k),& ! Exponential coefficient for basis function i, contraction k\n basis_A(j,l),& ! Exponential coefficient for basis function j, contraction l\n basis_R(i,:),& ! Center of basis function i\n basis_R(j,:),& ! Center of basis function j\n Rnn,Znn) ! Nuclear position and nuclear charge\n\n Vn(i,j) = Vn(i,j) + tmp\n END DO ! l\n END DO ! k\n END DO ! j\n END DO ! i\n\n END SUBROUTINE V_nuclear\n\n\nEND MODULE NUCLEAR\n", "meta": {"hexsha": "dccade032af1c7eaaccd475f1e9f770f0724bdc7", "size": 10530, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran90/nuclear.f90", "max_stars_repo_name": "RMeli/Hartree-Fock", "max_stars_repo_head_hexsha": "dda0102ab2a88f3f2f666c2479a858140505ea60", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2016-09-16T09:26:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T16:09:53.000Z", "max_issues_repo_path": "Fortran90/nuclear.f90", "max_issues_repo_name": "RMeli/Hartree-Fock", "max_issues_repo_head_hexsha": "dda0102ab2a88f3f2f666c2479a858140505ea60", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran90/nuclear.f90", "max_forks_repo_name": "RMeli/Hartree-Fock", "max_forks_repo_head_hexsha": "dda0102ab2a88f3f2f666c2479a858140505ea60", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2016-01-20T13:47:43.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-28T03:18:22.000Z", "avg_line_length": 38.0144404332, "max_line_length": 137, "alphanum_fraction": 0.3719848053, "num_tokens": 2370, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.7690802264851919, "lm_q1q2_score": 0.6847076895416744}} {"text": " PROGRAM xmrqcof\r\nC driver for routine mrqcof\r\n INTEGER NPT,MA\r\n REAL SPREAD\r\n PARAMETER(NPT=100,MA=6,SPREAD=0.1)\r\n INTEGER i,idum,j,ia(MA),mfit\r\n REAL chisq,gasdev,x(NPT),y(NPT),sig(NPT),a(MA),\r\n * alpha(MA,MA),beta(MA),gues(MA)\r\n EXTERNAL fgauss\r\n DATA a/5.0,2.0,3.0,2.0,5.0,3.0/\r\n DATA gues/4.9,2.1,2.9,2.1,4.9,3.1/\r\n idum=-911\r\nC first try sum of two gaussians\r\n do 12 i=1,NPT\r\n x(i)=0.1*i\r\n y(i)=0.0\r\n do 11 j=1,4,3\r\n y(i)=y(i)+a(j)*exp(-((x(i)-a(j+1))/a(j+2))**2)\r\n11 continue\r\n y(i)=y(i)*(1.0+SPREAD*gasdev(idum))\r\n sig(i)=SPREAD*y(i)\r\n12 continue\r\n mfit=MA\r\n do 13 i=1,mfit\r\n ia(i)=1\r\n13 continue\r\n do 14 i=1,mfit\r\n a(i)=gues(i)\r\n14 continue\r\n call mrqcof(x,y,sig,NPT,a,ia,MA,alpha,beta,MA,chisq,fgauss)\r\n write(*,'(/1x,a)') 'matrix alpha'\r\n do 15 i=1,MA\r\n write(*,'(1x,6f12.4)') (alpha(i,j),j=1,MA)\r\n15 continue\r\n write(*,'(1x,a)') 'vector beta'\r\n write(*,'(1x,6f12.4)') (beta(i),i=1,MA)\r\n write(*,'(1x,a,f12.4/)') 'Chi-squared:',chisq\r\nC next fix one line and improve the other\r\n mfit=3\r\n do 16 i=1,mfit\r\n ia(i)=0\r\n16 continue\r\n do 17 i=1,MA\r\n a(i)=gues(i)\r\n17 continue\r\n call mrqcof(x,y,sig,NPT,a,ia,MA,alpha,beta,MA,chisq,fgauss)\r\n write(*,'(1x,a)') 'matrix alpha'\r\n do 18 i=1,mfit\r\n write(*,'(1x,6f12.4)') (alpha(i,j),j=1,mfit)\r\n18 continue\r\n write(*,'(1x,a)') 'vector beta'\r\n write(*,'(1x,6f12.4)') (beta(i),i=1,mfit)\r\n write(*,'(1x,a,f12.4/)') 'Chi-squared:',chisq\r\n END\r\n", "meta": {"hexsha": "e01af56fbd13394fb58b13b74eab6c7e141cc875", "size": 1669, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xmrqcof.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xmrqcof.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xmrqcof.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": 30.3454545455, "max_line_length": 66, "alphanum_fraction": 0.5008987418, "num_tokens": 689, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.6847076852992241}} {"text": "Program testKinds\n\nUse Kinds\n\nImplicit None\n\nWrite(*,*)\nWrite(*,'(A,I2,A,F10.6,A)') 'SINGLE precision (',sp,' bytes) gives ',-Log10(2._sp*Spacing(1._sp)),' digits of precision near 1'\nWrite(*,'(A,I2,A,F10.6,A)') 'DOUBLE precision (',dp,' bytes) gives ',-Log10(2._dp*Spacing(1._dp)),' digits of precision near 1'\n# if EXTP\n Write(*,'(A,I2,A,F10.6,A)') 'QUAD precision (',qp,' bytes) gives ',-Log10(2._qp*Spacing(1._qp)),' digits of precision near 1'\n# endif\nWrite(*,*)\nWrite(*,'(A,I2,A,ES11.3E4,A,ES11.3E4)') 'SINGLE precision (',sp,' bytes) gives HUGE = ',HUGE(1._sp),' and TINY = ',TINY(1._sp)\nWrite(*,'(A,I2,A,ES11.3E4,A,ES11.3E4)') 'DOUBLE precision (',dp,' bytes) gives HUGE = ',HUGE(1._dp),' and TINY = ',TINY(1._dp)\n# if EXTP\n Write(*,'(A,I2,A,ES11.3E4,A,ES11.3E4)') 'QUAD precision (',qp,' bytes) gives HUGE = ',HUGE(1._qp),' and TINY = ',TINY(1._qp)\n# endif\nWrite(*,*)\nWrite(*,'(A,I2,A,I0)') 'SHORT integer (',is,' bytes) gives range +/- ',HUGE(1_is)\nWrite(*,'(A,I2,A,I0)') 'LONG integer (',il,' bytes) gives range +/- ',HUGE(1_il)\nWrite(*,'(A,I2,A,I0)') 'DOUBLE integer (',id,' bytes) gives range +/- ',HUGE(1_id)\n\nEnd Program testKinds", "meta": {"hexsha": "49099bf145553087289098ed3eba5459b2c7f566", "size": 1158, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "testing/Kinds/testKinds.f90", "max_stars_repo_name": "wtdailey/commonTools", "max_stars_repo_head_hexsha": "df51be16cdd64ac8062874b6b60776b30e50805b", "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": "testing/Kinds/testKinds.f90", "max_issues_repo_name": "wtdailey/commonTools", "max_issues_repo_head_hexsha": "df51be16cdd64ac8062874b6b60776b30e50805b", "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": "testing/Kinds/testKinds.f90", "max_forks_repo_name": "wtdailey/commonTools", "max_forks_repo_head_hexsha": "df51be16cdd64ac8062874b6b60776b30e50805b", "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": 48.25, "max_line_length": 131, "alphanum_fraction": 0.6174438687, "num_tokens": 463, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.7981867777396212, "lm_q1q2_score": 0.684659159769872}} {"text": "! $UWHPSC/codes/fortran/array1\n\nprogram array1\n\n ! demonstrate declaring and using arrays\n\n implicit none\n integer, parameter :: m = 5, n=6\n\n real (kind=8), dimension(m,n) :: A \n real (kind=8), dimension(m) :: b\n real (kind=8), dimension(n) :: x \n\n real (kind=8), dimension(m,n) :: At\n real (kind=8), dimension(m) :: bt \n real (kind=8), dimension(n) :: xt \n integer :: i,j\n\n ! initialize matrix A and vector x:\n do i=1,m\n do j=1,n\n A(i,j) = i+j\n At(i,j)=i+j\n enddo\n enddo\n\n xt = 1.\n x = 1.\n\n ! multiply A*x to get b:\n do i=1,m\n b(i) = 0.\n do j=1,n\n b(i) = b(i) + A(i,j)*x(j)\n enddo\n enddo\n bt=matmul(At,xt)\n print *, \"A = \"\n do i=1,m\n print *, A(i,:) ! i'th row of A\n enddo\n print \"(2d16.6)\", ((A(i,j), j=1,2), i=1,3)\n print *, \"x = \"\n print \"(d16.6)\", x\n print *, \"b and bt should be equal \"\n print *, \"b=\"\n print \"(d16.6)\", b\n print *, \"bt=\"\n print \"(d16.6)\",bt\n\n \n\nend program array1\n", "meta": {"hexsha": "1383adca81a1fe74ea882d7c5c63e64410414974", "size": 1078, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/labs/lab8/problem2/array1b.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/lab8/problem2/array1b.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/lab8/problem2/array1b.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": 19.962962963, "max_line_length": 46, "alphanum_fraction": 0.4647495362, "num_tokens": 381, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619883, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.6846591593973674}} {"text": "!!$subroutine varimax(X,Y,M,K,N)\n!!$ \n!!$ ! THIS SUBROUTINE ROTATES THE VECTORS X USING THE VARIMAX CRITERION. \n!!$ ! ON INPUT, X CONTAINS THE N EIGENVECTORS, EACH OF LENGTH M, TO BE ROTATED. \n!!$ ! ON OUTPUT, X CONTAINS THE ROTATED SYSTEM.\n!!$ \n!!$ implicit none\n!!$ \n!!$ integer, intent(IN) :: M, K, N\n!!$ real, intent(INOUT) :: X(M,N),Y(K,N)\n!!$ \n!!$ real, dimension(M) :: H,U,V\n!!$ real, dimension(K) :: T\n!!$ real :: A, B, C, D, VVOLD, VVNEW\n!!$ real :: PHI, COSPHI, SINPHI\n!!$ integer :: P, Q, L, MAXITER\n!!$ \n!!$ !f2py intent(in) :: M, K, N\n!!$ !f2py intent(in,out) :: X, Y\n!!$ !f2py intent(hide) :: M, K, N\n!!$\n!!$ ! NORMALIZE COMPONENTS\n!!$ \n!!$ do P=1,M\n!!$ H(P) =sqrt(sum(X(P,:)**2))\n!!$ enddo\n!!$ \n!!$ do Q=1,N\n!!$ where(H/=0.) X(:,Q) = X(:,Q)/H(:)\n!!$ enddo\n!!$ \n!!$ ! VARIMAX ITERATION FOR ALL PAIRS OF VECTORS\n!!$ \n!!$ maxiter = 40\n!!$ vvold = M*sum(X(:,:)**4) - sum(sum(X**2,1)**2)\n!!$ \n!!$ do L=1,MAXITER\n!!$ do P=1,N-1\n!!$ do Q=P+1,N\n!!$ U = X(:,P)**2 - X(:,Q)**2\n!!$ V = 2.*X(:,P)*X(:,Q)\n!!$ A = sum(U)\n!!$ B = sum(V)\n!!$ C = sum(U*U-V*V) - (A*A-B*B)/FLOAT(M)\n!!$ D = 2.*(sum(U*V) - A*B/FLOAT(M))\n!!$ PHI = .25*atan2(D,C)\n!!$ COSPHI = cos(PHI)\n!!$ SINPHI = sin(PHI)\n!!$ U = X(:,P)*COSPHI+X(:,Q)*SINPHI\n!!$ X(:,Q) = -X(:,P)*SINPHI+X(:,Q)*COSPHI\n!!$ X(:,P) = U\n!!$ T = Y(:,P)*COSPHI+Y(:,Q)*SINPHI\n!!$ Y(:,Q) = -Y(:,P)*SINPHI+Y(:,Q)*COSPHI\n!!$ Y(:,P) = T\n!!$ end do\n!!$ enddo\n!!$ \n!!$ VVNEW = M*sum(X(:,:)**4) - sum(sum(X**2,1)**2)\n!!$ print *, vvold, vvnew, (VVNEW-VVOLD)/VVNEW \n!!$ if((VVNEW-VVOLD)/VVNEW < .0001) exit\n!!$ \n!!$ if(L==MAXITER) then\n!!$ print *, 'eofs: VARIMAX rotation iteration did not converge'\n!!$ call exit(10)\n!!$ endif\n!!$ \n!!$ VVOLD = VVNEW\n!!$ \n!!$ enddo\n!!$ \n!!$ do Q=1,N\n!!$ X(:,Q) = X(:,Q)*H(:)\n!!$ end do\n!!$ \n!!$ return\n!!$end subroutine VARIMAX\n\n\nsubroutine varimax(X,Y,M,K,N,NM)\n\n ! THIS SUBROUTINE ROTATES THE VECTORS X USING THE VARIMAX CRITERION. \n ! ON INPUT, X CONTAINS THE N EIGENVECTORS, EACH OF LENGTH M, TO BE ROTATED. \n ! ON OUTPUT, X CONTAINS THE ROTATED SYSTEM.\n \n implicit none\n \n integer, intent(IN) :: M, K, N, NM\n real*8, intent(INOUT) :: X(M,N),Y(K,N)\n \n real*8, dimension(M) :: H,U,V\n real*8, dimension(K) :: T\n real*8 :: A, B, C, D, VVOLD, VVNEW\n real*8 :: PHI, COSPHI, SINPHI\n integer :: P, Q, L, MAXITER\n \n !f2py intent(in) :: M, K, N, NM\n !f2py intent(in,out) :: X, Y\n !f2py intent(hide) :: M, K, N\n\n ! NORMALIZE COMPONENTS\n\n do P=1,M\n H(P) =sqrt(sum(X(P,:)**2))\n enddo\n \n do Q=1,N\n where(H/=0.) X(:,Q) = X(:,Q)/H(:)\n enddo\n \n ! VARIMAX ITERATION FOR ALL PAIRS OF VECTORS\n \n maxiter = 40\n vvold = M*sum(X(:,:)**4) - sum(sum(X**2,1)**2)\n \n do L=1,MAXITER\n \n do P=1,NM-1 !N,N-NM+2,-1\n do Q=P+1,NM !P-1,N-NM+1,-1\n U = X(:,P)**2 - X(:,Q)**2\n V = 2.*X(:,P)*X(:,Q)\n A = sum(U)\n B = sum(V)\n C = sum(U*U-V*V) - (A*A-B*B)/FLOAT(M)\n D = 2.*(sum(U*V) - A*B/FLOAT(M))\n PHI = .25*atan2(D,C)\n COSPHI = cos(PHI)\n SINPHI = sin(PHI)\n U = X(:,P)*COSPHI+X(:,Q)*SINPHI\n X(:,Q) = -X(:,P)*SINPHI+X(:,Q)*COSPHI\n X(:,P) = U\n T = Y(:,P)*COSPHI+Y(:,Q)*SINPHI\n Y(:,Q) = -Y(:,P)*SINPHI+Y(:,Q)*COSPHI\n Y(:,P) = T\n end do\n enddo\n \n VVNEW = M*sum(X(:,:)**4) - sum(sum(X**2,1)**2)\n print *, vvold, vvnew, (VVNEW-VVOLD)/VVNEW \n if((VVNEW-VVOLD)/VVNEW < .0001) exit\n \n if(L==MAXITER) then\n print *, 'eofs: VARIMAX rotation iteration did not converge'\n call exit(10)\n endif\n \n VVOLD = VVNEW\n \n enddo\n \n do Q=1,N\n X(:,Q) = X(:,Q)*H(:)\n end do\n \n return\nend subroutine VARIMAX\n", "meta": {"hexsha": "3da8fb9199f9fb1bb2fcc0b109f6a868796cbd42", "size": 4023, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "GEOS_Util/coupled_diagnostics/g5lib/src/fortran/varimax.f90", "max_stars_repo_name": "GEOS-ESM/GMAO_Shared", "max_stars_repo_head_hexsha": "022af23abbc7883891006b57379be96d9a50df23", "max_stars_repo_licenses": ["NASA-1.3", "ECL-2.0", "Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-02-01T17:36:53.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-01T17:36:53.000Z", "max_issues_repo_path": "GEOS_Util/coupled_diagnostics/g5lib/src/fortran/varimax.f90", "max_issues_repo_name": "GEOS-ESM/GMAO_Shared", "max_issues_repo_head_hexsha": "022af23abbc7883891006b57379be96d9a50df23", "max_issues_repo_licenses": ["NASA-1.3", "ECL-2.0", "Apache-2.0"], "max_issues_count": 105, "max_issues_repo_issues_event_min_datetime": "2019-07-08T19:27:23.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-22T02:12:16.000Z", "max_forks_repo_path": "GEOS_Util/coupled_diagnostics/g5lib/src/fortran/varimax.f90", "max_forks_repo_name": "GEOS-ESM/GMAO_Shared", "max_forks_repo_head_hexsha": "022af23abbc7883891006b57379be96d9a50df23", "max_forks_repo_licenses": ["NASA-1.3", "ECL-2.0", "Apache-2.0"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2019-07-05T18:00:44.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-11T16:26:29.000Z", "avg_line_length": 25.7884615385, "max_line_length": 83, "alphanum_fraction": 0.4494158588, "num_tokens": 1669, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970904940927, "lm_q2_score": 0.7772998663336157, "lm_q1q2_score": 0.6846434607080959}} {"text": "!--------------------------------------------------\n!PHY1038 Assignment 2 Series Computation\n!URN: 6408056\n!February 2017\n!--------------------------------------------------\nPROGRAM Taylorseriesexpansion\nIMPLICIT NONE\n\nCHARACTER::figrunone, fig, figninput, fignoption, intchoice, figintervaltwo, figinter, figninputtwo\nINTEGER:: n, i, p\nDOUBLE PRECISION :: factorial\nREAL:: interval, taylorvalueatx, valueofderivative, yexact, x, pi\nREAL, DIMENSION(:), ALLOCATABLE::a\nfigrunone='e' !setting this so introduction to program is only printed on the first run\nfig='y'!set to y so do loop allowing users to run the program again runs first time\nfigninput='n'\nfignoption='n' \nintchoice='N' !this allows (on the intial run) for the user to be given a choice as to what the interval increases in x will be\n!this is because on further runs of the main do while loop, they are given a choice as to wether they want to use the same value\n!so the interval choice part of the program needs to be in an if loop to stop it playing after the user has chosen to use the \n!same interval value\npi=4*atan(1.0)!setting pi for later use\nDO WHILE(fig=='y' .or. fig=='Y')!This do while loop allows the user to run the program again at the end, or exit it\n figninputtwo='l' !so on reruns, the user is not told the introduction to the program again\n figintervaltwo='n'\n figninput='n'\n IF (figrunone=='e') THEN !only plays intro on first do loop\n WRITE(6,*) 'This program calculates the Taylor Expansion around zero for f(x)=sin(x)*exp(-x/2), it then'\n WRITE(6,*) 'calulates the values of both the exact function and the Taylor expansion between x=-2pi, and'\n WRITE(6,*) 'x=2pi, and writes the values to a file called taylor.dat. The Taylor function is plotted in'\n WRITE(6,*) 'columns one and two, and the exact function is plotted in columns one and three.'\n WRITE(6,*) 'Thus using: plot \"taylor.dat\" u 1:2 w l, \"taylor.dat\" u 1:3 w l'\n WRITE(6,*) 'in gnuplot will allow you to compare the Taylor expansion, of your chosen order, and' \n WRITE(6,*) 'the exact funtion.'\n END IF\n\n IF(fignoption=='n' .or. fignoption=='N') THEN!Later users are given a choice if they want to use the same order of the\n !polynomial, this if loop allows for this, if N is selected, saying they don't want to use the same order\n !they are given the following option, thus fignoption is set to N at the beginning, outside the do loop\n !so this plays on the first run\n WRITE(6,*)'Please input the order you would like the program to calculate the polynomial for?'\n DO WHILE (figninput=='n' .or. figninput=='N' ) !if they say the order they entered isn't correct, this allows them to\n !enter it again \n DO\n READ(5,*) n\n IF(n<=0)THEN!prevents negative orders being chosen\n WRITE(6,*) 'The order of a polynomial should be positive, please try again.'\n CYCLE\n ELSE \n EXIT\n END IF \n END DO\n WRITE(6,*)'You inputed',n,' Is the correct? Type N for no, or Y for yes.'\n READ(5,*) figninput\n figninputtwo='q'\n IF (figninput=='n' .or. figninput =='N') THEN\n WRITE(6,*)'Please try again.'\n END IF\n END DO \n ELSE IF(fignoption=='y' .or. fignoption=='Y') THEN\n WRITE(6,*)'Using same value for order of Taylor expansion.'!here so that if user chooses to use same value of n\n END IF!they know it has worked\n IF (figrunone=='e') THEN !if loop so intro only plays on first run\n WRITE(6,*) 'This program compares the taylor series to the nth degree between -2pi, and 2pi.'\n WRITE(6,*) 'By default the program increase the value of x in steps of 0.01, until 2pi is reached'\n END IF \n\n IF(intchoice=='y' .or. intchoice=='Y')THEN\n figinter='p' !later users are given the choice if they want to use the same interval increases in x when they run\n !the program again, if they say yes, figinter is set to p, this later lets them know that the program is using \n !the same value, if they say no, then the choice is selected that they \n \n ELSE IF(intchoice=='N'.or. intchoice=='n') THEN\n figinter='y' !if they pick no, figinter is set to Y, meaning they want to change the value of the interval\n IF(figrunone=='e') THEN !this is so they are not asked twice about changing the interval, this is only played\n !on the first run\n DO\n WRITE(6,*) 'If you would like to change the intervals that X increases in from 0.01, type Y, if not type N.'\n READ(5,*) figinter\n IF (figinter /= 'n' .and. figinter /='N' .and. figinter /='Y' .and. figinter /='y') THEN\n WRITE (6,*) 'Invalid option.' !If prevents wrong figures being picked\n CYCLE\n ELSE\n EXIT\n END IF\n END DO \n END IF\n END IF\n\n IF(figinter=='y' .or. figinter=='Y')THEN !if they don't want to keep the same interval value, this runs\n DO WHILE(figintervaltwo=='n' .or. figintervaltwo=='N')!ensures they pick the interval they want\n WRITE(6,*)'Please type in the interval you want to use.'\n READ(5,*) interval\n WRITE(6,*)'You entered',interval,' Is this correct, type Y for yes, or N for no.'\n READ(5,*) figintervaltwo\n interval=abs(interval)\n END DO\n ELSE IF (figinter=='n' .or. figinter=='N') THEN\n WRITE(6,*)'Using 0.01 as interval'\n interval=0.01\n ELSE IF (figinter=='p') THEN\n WRITE(6,*)'Using same interval value.' \n END IF \n \n ALLOCATE(a(0:n))!allocates an array to be the same length as the desired polynomial\n\n factorial=1\n x=-2.0*pi\n\n OPEN(unit=20,file='taylor.dat')\n!(main part of program)\n DO i=1,n \n factorial=factorial*i!calculating factorial\n valueofderivative = ((-SQRT(5.0)/2.0)**(i)*(sin(-(i)*Atan(2.0))))\n a(i) = valueofderivative/factorial!This calculates the taylor expansion, and storing it in to the array\n END DO\n\n DO WHILE(x<=2.0*pi)!do while loop to set the interval between -2pi and 2pi\n taylorvalueatx=0.0 !makes sure taylor value is set to 0 inbetween do loops, as otherwise the taylor values are too big\n\n DO i=1,n !multiples each part of the taylor expansion by X to the desired order, for each x\n taylorvalueatx=(x**(i))*a(i)+taylorvalueatx !calculating the actual value of the taylor expansion, by multiplying\n END DO !x to the order and summing all values\n\n yexact=sin(x)*exp(-x/2.0) !calculates what the exact value is so the user can compare\n WRITE(20,*) x, taylorvalueatx, yexact !writes the values in a file\n x=x+interval\n END DO \n \n CLOSE(20)\n\n WRITE(6,*)'Would you like to run the program again? '\n DO \n WRITE(6,*) 'Type Y for yes, or N for no.' !this correlates to main do loop\n READ(5,*)fig\n IF (fig /= 'n' .and. fig /='N' .and. fig /='Y' .and. fig/='y') THEN !ensures valid options are entered\n WRITE (6,*) 'Invalid option.'\n CYCLE\n ELSE \n EXIT\n END IF\n END DO\n IF (fig=='Y' .or. fig=='y') THEN\n WRITE(6,*) 'Would you like to use the same value for the order of the polynomial?'\n DO !allowing user to keep data for last run of program to make running the program multiple times more user friendly\n WRITE(6,*) 'Type Y for yes, or N for no.'\n READ(5,*) fignoption\n IF (fignoption /= 'n' .and. fignoption /='N' .and. fignoption /='Y' .and. fignoption /='y') THEN\n WRITE (6,*) 'Invalid option.'\n CYCLE\n ELSE\n EXIT\n END IF\n END DO\n WRITE(6,*)'Would you like to use the same value for the interval? ie the how much x increases inbetween steps.'\n DO\n WRITE(6,*) 'Type Y for yes, or N for no.'\n READ(5,*) intchoice\n IF (intchoice /= 'n' .and. intchoice /='N' .and. intchoice /='Y' .and. intchoice /='y') THEN\n WRITE (6,*) 'Invalid option.'\n CYCLE\n ELSE\n EXIT\n END IF\n END DO\n END IF\n figrunone='p'!setting this to stop introduction elements playing again\n DEALLOCATE(a) !deallocating a so that new n values can be entered \n \n END DO\nWRITE(6,*)'Thank you for using the program.'\nEND PROGRAM Taylorseriesexpansion \n \n \n \n \n \n \n \n \n", "meta": {"hexsha": "a8ed85faefdf5e97cb5610828dff303ae28f447b", "size": 7984, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Taylor Series/Taylorseries5.f90", "max_stars_repo_name": "DGrifferty/Fortran", "max_stars_repo_head_hexsha": "600b46fb553fe955c7dd574ee4f51ac1f24de62e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Taylor Series/Taylorseries5.f90", "max_issues_repo_name": "DGrifferty/Fortran", "max_issues_repo_head_hexsha": "600b46fb553fe955c7dd574ee4f51ac1f24de62e", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Taylor Series/Taylorseries5.f90", "max_forks_repo_name": "DGrifferty/Fortran", "max_forks_repo_head_hexsha": "600b46fb553fe955c7dd574ee4f51ac1f24de62e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.1104972376, "max_line_length": 128, "alphanum_fraction": 0.6647044088, "num_tokens": 2340, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746911, "lm_q2_score": 0.8807970889295664, "lm_q1q2_score": 0.684643454948024}} {"text": " \nC *********************************************************\nC * *\nC * TEST NUMBER: 06.01.01/06 *\nC * TEST TITLE : Building transformations *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n \n COMMON /GLOBNU/ CTLHND, ERRSIG, ERRFIL, IERRCT, UNERR,\n 1 TESTCT, IFLERR, PASSSW, ERRSW, MAXLIN,\n 2 CONID, MEMUN, WKID, WTYPE, GLBLUN, INDLUN,\n 3 DUMINT, DUMRL\n INTEGER CTLHND, ERRSIG, ERRFIL, IERRCT, UNERR,\n 1 TESTCT, IFLERR, PASSSW, ERRSW, MAXLIN,\n 2 CONID, MEMUN, WKID, WTYPE, GLBLUN, INDLUN,\n 3 DUMINT(20), ERRIND\n REAL DUMRL(20)\n \n COMMON /GLOBCH/ PIDENT, GLBERR, TSTMSG, FUNCID,\n 1 DUMCH\n CHARACTER PIDENT*40, GLBERR*60, TSTMSG*900, FUNCID*80,\n 1 DUMCH(20)*20\n \n REAL ACT4X4(4,4), ACT3X3(3,3), EXP4X4(4,4), EXP3X3(3,3)\n REAL X0,Y0,Z0, DX,DY,DZ, PHIX,PHIY,PHIZ, FX,FY,FZ\n LOGICAL TRNSEQ\n \n CALL INITGL ('06.01.01/06')\n \nC open PHIGS\n CALL XPOPPH (ERRFIL, MEMUN)\n \n CALL SETMSG ('1 2 15', ' ' //\n 1 'should generate a matrix to perform the ' //\n 2 'specified 3D transformation.')\n \nC Set up parameters:\nC set fixed point\n X0 = -1.12\n Y0 = 2.23\n Z0 = 3.34\nC set shift vector\n DX = 6.7\n DY = 8.9\n DZ = 10.11\nC set rotation angle\n PHIX = 7.6\n PHIY = -5.4\n PHIZ = 3.2\nC set scale factors\n FX = 0.0023\n FY = -636.34\n FZ = 2.2\n \nC returns act4x4 = actual array\n CALL PBLTM3 (X0,Y0,Z0, DX,DY,DZ, PHIX,PHIY,PHIZ, FX,FY,FZ,\n 1 ERRIND, ACT4X4)\n CALL CHKINQ ('pbltm3', ERRIND)\n \nC Compute exp4x4 = expected array\n CALL EBLTM3 (X0,Y0,Z0, DX,DY,DZ, PHIX,PHIY,PHIZ, FX,FY,FZ,\n 1 EXP4X4)\n CALL IFPF ( TRNSEQ (4, ACT4X4, EXP4X4))\n \n CALL SETMSG ('1 2 16', ' ' //\n 1 'should generate a matrix to perform the ' //\n 2 'specified 2D transformation.')\n \nC Set up parameters:\nC set fixed point\n X0 = -1.12\n Y0 = 2.23\nC set shift vector\n DX = 6.7\n DY = 10.11\nC set rotation angle\n PHIZ = -5.4\nC set scale factors\n FX = 0.0023\n FY = -636.34\n \nC returns act3x3 = actual array\n CALL PBLTM (X0,Y0, DX,DY, PHIZ, FX,FY, ERRIND, ACT3X3)\n CALL CHKINQ ('pbltm', ERRIND)\n \nC Compute exp3x3 = expected array\n CALL EBLTM (X0,Y0, DX,DY, PHIZ, FX,FY, EXP3X3)\n CALL IFPF ( TRNSEQ (3, ACT3X3, EXP3X3))\n \n CALL ENDIT\n END\n", "meta": {"hexsha": "881873c6908362bb2453a82729a541ccd42eef0a", "size": 2964, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "third_party/Phigs/PVT/PVT_fort/06/01/01/p06.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/06/01/01/p06.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/06/01/01/p06.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": 31.5319148936, "max_line_length": 66, "alphanum_fraction": 0.4888663968, "num_tokens": 1019, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970873650401, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.684643453731918}} {"text": "include 'OUCS.f90'\ninclude 'fftlib.for'\nmodule Wave\n integer, parameter :: N = 2048\n double precision,parameter :: x0=50d0, xmax = 100d0\n double precision :: t, told,x, dx = xmax / (N), dx3, k, c,amp, Cconv ,Cdisp, L2norm\n double precision,dimension(0:N) :: u, usq, uold, unew, UUx, Uxxx, Lu , uexact, error\nendmodule Wave\n\nmodule RK\n double precision :: dt=1d-5, tmax\n integer :: stage, Niter, Ncycle=5 ,writeafter\n integer :: spatial_conv = 5 ,spatial_disp = 2 ! 1-CD2, 2-UD3, 3-CD4, 4-CD4 non conserv, 5-OUCS3; 1-CD2, 2-CD4, 3-O3CS\n double precision,dimension(1:4) :: fac_dt, fac_rk\nendmodule RK\n\nsubroutine Initialize\n use Wave\n use RK\n implicit none\n integer :: i\n ! k = 1d0 \n amp = 2d0*k**2*0.999d0\n c = 4d0*k**2\n\n tmax = xmax/c*Ncycle\n Niter = tmax/dt\n writeafter = 1/dt/10\n\n Cconv=6d0\n Cdisp=1d0\n x=0d0\n dx3 = dx**3\n\n! u=0 ! Delta function\n! u(N/2)=-1d0 \n\n do i = 0,N ! Soliton wave solution\n u(i) = amp* (1d0- dtanh(k*(x-x0))**2d0)\n x=x+dx\n enddo \n\n t = 0d0\n fac_dt(1) = 0.5d0 \n fac_dt(2) = 0.5d0\n fac_dt(3) = 1d0\n fac_dt(4) = 1d0\n \n fac_rk(1) = 1d0/6d0 \n fac_rk(2) = 1d0/3d0\n fac_rk(3) = 1d0/3d0\n fac_rk(4) = 1d0/6d0\nendsubroutine Initialize\n\nsubroutine Backup\n use Wave\n implicit none\n uold = u\n unew = u\nendsubroutine Backup\n\nsubroutine Restore\n use Wave\n implicit none\n u = unew\nendsubroutine Restore\n\nsubroutine SpatialDerivative\n use Wave\n use RK\n implicit none\n integer :: i\n\n !*** Convection term****!\n select case(spatial_conv)\n case(1)\n !CD2\n do i = 1,N-1\n UUx(i) = (u(i+1)**2 - u(i-1)**2)/2d0/dx/2d0\n enddo\n UUx(N) = (u(1)**2 - u(N-1)**2)/2d0/dx/2d0\n UUx(0) = UUx(N)\n \n case(2)\n !UD3\n UUx(1) = (3d0*u(1)**2 - 4d0*u(0)**2 + u(N-1)**2)/2d0/dx/2d0\n do i = 2,N\n UUx(i) = (3d0*u(i)**2 - 4d0*u(i-1)**2 + u(i-2)**2)/2d0/dx/2d0\n enddo\n UUx(0) = UUx(N)\n \n case(3)\n !CD4\n do i = 2,N-2\n UUx(i) = -(u(i+2)**2 - 8d0*u(i+1)**2 + 8d0*u(i-1)**2 - u(i-2)**2)/12d0/dx/2d0\n enddo\n UUx(1) = -(u(3)**2 - 8d0*u(2)**2 + 8d0*u(N)**2 - u(N-1)**2)/12d0/dx/2d0\n UUx(N) = -(u(2)**2 - 8d0*u(1)**2 + 8d0*u(N-1)**2 - u(N-2)**2)/12d0/dx/2d0\n UUx(N-1) = -(u(1)**2 - 8d0*u(0)**2 + 8d0*u(N-2)**2 - u(N-3)**2)/12d0/dx/2d0\n UUx(0) = UUx(N)\n case(4)\n !CD4 - Non_conservation form\n do i = 2,N-2\n UUx(i) = -u(i)*(u(i+2) - 8d0*u(i+1) + 8d0*u(i-1) - u(i-2))/12d0/dx\n enddo\n UUx(1) = -u(1)*(u(3) - 8d0*u(2)+ 8d0*u(N) - u(N-1))/12d0/dx\n UUx(N) = -u(N)*(u(2) - 8d0*u(1)+ 8d0*u(N-1) - u(N-2))/12d0/dx\n UUx(N-1) = -u(N-1)*(u(1) - 8d0*u(0)+ 8d0*u(N-2) - u(N-3))/12d0/dx\n UUx(0) = UUx(N)\n case(5)\n ! call Dealias1d(u, usq,N)\n ! call ShiftAlign(u,usq,N)\n call Periodic_OUCS3(u*u,UUx,N,dx)\n UUx= UUx/2d0\n end select\n\n ! Dispersion term\n select case(spatial_disp)\n !CD2\n case(1)\n do i = 2,N-2\n Uxxx(i) = (u(i+2) - 2d0*u(i+1) + 2d0*u(i-1) - u(i-2))/2d0/dx3\n enddo\n Uxxx(1) = (u(3) - 2d0*u(2) + 2d0*u(N) - u(N-1))/2d0/dx3\n Uxxx(N) = (u(2) - 2d0*u(1) + 2d0*u(N-1) - u(N-2))/2d0/dx3\n Uxxx(N-1) = (u(1) - 2d0*u(N) + 2d0*u(N-2) - u(N-3))/2d0/dx3\n Uxxx(0) = Uxxx(N)\n !CD4\n case(2)\n do i = 3,N-3\n Uxxx(i) = (-u(i+3) +8d0*u(i+2) - 13d0*u(i+1) + 13d0*u(i-1) - 8d0*u(i-2) + u(i-3))/8d0/dx3\n enddo\n Uxxx(2) = (-u(5) +8d0*u(4) - 13d0*u(3) + 13d0*u(1) - 8d0*u(N) + u(N-1))/8d0/dx3\n Uxxx(1) = (-u(4) +8d0*u(3) - 13d0*u(2) + 13d0*u(N) - 8d0*u(N-1) + u(N-2))/8d0/dx3\n Uxxx(N) = (-u(3) +8d0*u(2) - 13d0*u(1) + 13d0*u(N-1) - 8d0*u(N-2) + u(N-3))/8d0/dx3\n Uxxx(N-1) = (-u(2) +8d0*u(1) - 13d0*u(0) + 13d0*u(N-2) - 8d0*u(N-3) + u(N-4))/8d0/dx3\n Uxxx(N-2) = (-u(1) +8d0*u(0) - 13d0*u(N-1) + 13d0*u(N-3) - 8d0*u(N-4) + u(N-5))/8d0/dx3\n Uxxx(0) = Uxxx(N)\n !O3CS\n case(3)\n call Periodic_O3CS(u,Uxxx,N,dx3)\n end select\nendsubroutine SpatialDerivative\n\nsubroutine RKstage\n use Wave\n use RK\n implicit none\n \n call SpatialDerivative\n Lu = -dt *(Cconv*UUx + Cdisp*Uxxx)\n\n unew = unew + fac_rk(stage)*Lu\n \n u = uold + fac_dt(stage)*Lu\nendsubroutine RKstage\n\nsubroutine CalcError\n use Wave\n use RK, only: Ncycle\n implicit none\n integer :: i, ii\n\n x = 0d0\n ii = 0\n uexact = 0d0\n\n do i=0,N*(Ncycle+1)\n uexact(ii) = uexact(ii)+amp*(1d0 - dtanh(k*(x-x0 - c*t))**2 )\n if(i/=0 .and. mod(i,N)==0) then\n ii = 0\n uexact(ii) = uexact(N)\n endif\n x = x+dx\n ii = ii+1\n enddo\n \n error = dabs(u-uexact)\n L2norm = dsqrt(dot_product(error,error)/N)\nendsubroutine CalcError\n\nsubroutine March\n use Wave\n use RK \n implicit none \n integer :: i\n\n call Initialize\n \n call CalcError\n call SolnWrite\n open(1,file='L2norm.dat',status='replace')\n write(1,*) 'Variables= t, L2norm'\n\n do i=0,Niter!while(t < tmax)\n call Backup\n do stage=1,4\n call RKstage\n enddo\n call Restore\n\n t = t + dt\n\n if(mod(i,writeafter)==0) then\n call CalcError\n call SolnWrite\n write(*,*) 't=',t, L2norm !'umax=', maxval(u), 'logerrormax=', log10(maxval(error)), 'L2norm=',L2norm\n write(1,*) t, L2norm\n endif\n enddo\n close(3)\n\nendsubroutine March\n\nsubroutine SolnWrite\n use Wave\n use RK\n implicit none\n integer :: i\n character(40) :: fname\n\n if(int(t)<10) then \n write(fname,11) 'sol_000',t,'.dat'\n 11 format(A7,F6.4,A4)\n elseif(int(t)<100) then \n write(fname,12) 'sol_00',t,'.dat'\n 12 format(A6,F7.4,A4)\n elseif(int(t)<1000) then \n write(fname,13) 'sol_0',t,'.dat'\n 13 format(A5,F8.4,A4)\n else\n write(fname,14) 'sol_',t,'.dat'\n 14 format(A4,F9.4,A4)\n endif\n\n open(101, file=trim(fname),status='replace')\n \n write(101,*) 'Variables = x, u'!, u_exact, error'\n write(101,*) 'Zone i=',N+1\n write(101,*) 'Auxdata time=\"',real(t),'\"'\n \n 111 format(4ES15.3)\n x=0d0\n do i=0,N\n write(101,111) x,u(i)!, uexact(i), error(i)!, (i), error(i)\n x=x+dx\n enddo\n\n close(101)\nendsubroutine SolnWrite\n\nprogram KdV\n use Wave\n use RK\n implicit none\n print*, \"k, (2/3) CD4/O3CS\"\n read*, k, spatial_disp\n call Initialize\n call March\n \nendprogram KdV\n", "meta": {"hexsha": "22c13669542090efe1c743dbc4cfcd7c60331452", "size": 7584, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran/kdv.f90", "max_stars_repo_name": "ashwinvis/kdv-compact", "max_stars_repo_head_hexsha": "065f6a543692f3a3c7848bf7b7bd02cb1451b253", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-09-04T07:43:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T22:46:22.000Z", "max_issues_repo_path": "Fortran/kdv.f90", "max_issues_repo_name": "ashwinvis/kdv-compact", "max_issues_repo_head_hexsha": "065f6a543692f3a3c7848bf7b7bd02cb1451b253", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran/kdv.f90", "max_forks_repo_name": "ashwinvis/kdv-compact", "max_forks_repo_head_hexsha": "065f6a543692f3a3c7848bf7b7bd02cb1451b253", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-05-02T03:02:41.000Z", "max_forks_repo_forks_event_max_datetime": "2018-05-02T03:02:41.000Z", "avg_line_length": 28.9465648855, "max_line_length": 124, "alphanum_fraction": 0.4459388186, "num_tokens": 2935, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778824, "lm_q2_score": 0.7772998663336157, "lm_q1q2_score": 0.6846434509792473}} {"text": "!##############################################################################\n!##############################################################################\n! MODULE toolbox\n!\n! ## Contains all the toolbox subroutines etc.\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! It accompanies the textbook:\n! Fehr, H. & Kindermann, F. (2018). Introduction to Computational\n! Economics using Fortran. Oxford: Oxford University Press.\n!\n! #VC# VERSION: 1.4 (06 January 2021)\n!\n!##############################################################################\n!##############################################################################\nmodule toolbox\n\n\n!##############################################################################\n!##############################################################################\n! Declaration of Variables\n!##############################################################################\n!##############################################################################\n\nimplicit none\n\n! declare everything as private by default\nprivate\n\n! starting time for cpu timer\nreal*8, private :: starttime_cpu\n\n! should the random tbox_seed be set\nlogical, private :: tbox_seed = .true.\n\n! Level of tolerance for all routines\nreal*8, private :: tbox_gftol = 1d-8\n\n! Maximum number of iterations\ninteger, private :: tbox_itermax_min = 200\n\n! Maximum number of iterations for brent_pow\ninteger, parameter, private :: tbox_tbox_itermax_pow_b = 150\n\n! Level of tolerance for all routines\nreal*8, private :: tbox_gftol_root = 1d-8\n\n! Maximum number of iterations for broydn\ninteger, private :: itermax_root = 200\n\n! control variables for gnuplot\nlogical, private :: gnu_addtoplot = .false.\nlogical, private :: gnu_dolegend = .false.\nlogical, private :: gnu_histogram = .false.\ninteger, private :: gnu_nmax, gnu_mmax\n\n! plot data for gnuplot\nreal*8, allocatable, private :: gnu_x(:, :), gnu_y(:, :)\nreal*8, allocatable, private :: gnu_x_temp(:, :), gnu_y_temp(:, :)\n\n! style data for gnuplot\ncharacter(LEN = 2000), dimension(1000), private :: gnu_definitions \n\n\n\n!##############################################################################\n!##############################################################################\n! Define public access points\n!##############################################################################\n!##############################################################################\n\n! matrix operations\npublic :: lu_solve, lu_invert, lu_dec\npublic :: cholesky\n\n! rootfinding\npublic :: settol_root\npublic :: setiter_root\npublic :: fzero\n\n! optimization\npublic :: settol_min\npublic :: setiter_min\npublic :: fminsearch\n\n! linear programming with constraints\npublic :: solve_lin\n\n! integration methods\npublic :: legendre\n\n! discretization of normal distributions\npublic :: normal_discrete\npublic :: log_normal_discrete\n\n! discretization of AR(1) process\npublic :: discretize_AR, discretize_log_AR\n\n! probabilities and distributions\npublic :: uniformPDF, uniformCDF, uniformCDF_Inv\npublic :: normalPDF, normalCDF, normalCDF_Inv\npublic :: log_normalPDF, log_normalCDF, log_normalCDF_Inv\npublic :: GammaPDF, GammaCDF\npublic :: betaPDF, betaCDF\npublic :: bernoulliPDF, bernoulliCDF\npublic :: binomialPDF, binomialCDF\npublic :: binomial_coefficient\n\n! simulation\npublic :: init_random_seed\npublic :: simulate_uniform\npublic :: simulate_normal\npublic :: simulate_log_normal\npublic :: simulate_Gamma\npublic :: simulate_beta\npublic :: simulate_bernoulli\npublic :: simulate_binomial\npublic :: simulate_AR\n\n! discretization of continuous intervals\npublic :: grid_Cons_Equi, grid_Val_Equi, grid_Inv_Equi\npublic :: grid_Cons_Cheb, grid_Val_Cheb, grid_Inv_Cheb\npublic :: grid_Cons_Grow, grid_Val_Grow, grid_Inv_Grow\n\n! interpolation\npublic :: poly_interpol\npublic :: linint_Equi, linint_Cheb, linint_Grow, linint_Gen\npublic :: spline_interp, spline_eval, spline\n\n! plotting\npublic :: plot\npublic :: plot3d\npublic :: plot_hist\npublic :: execplot\n\n! sorting\npublic :: sort\n\n! the clock\npublic :: tic, toc\n\n!##############################################################################\n!##############################################################################\n! Interface declarations\n!##############################################################################\n!##############################################################################\n\n\n!##############################################################################\n! INTERFACE assert_eq\n!\n! Interface for equality assertions by assert_eqx functions.\n!##############################################################################\ninterface assert_eq\n\n module procedure assert_eq2, assert_eq3, assert_eq4, assert_eq5, &\n assert_eqn\n\nend interface\n\n\n!##############################################################################\n! INTERFACE normal_discrete\n!\n! Discretizes normal distribution.\n!##############################################################################\ninterface normal_discrete\n\n module procedure normal_discrete_1, normal_discrete_2\n\nend interface\n\n\n!##############################################################################\n! INTERFACE log_normal_discrete\n!\n! Discretizes log-normal distribution.\n!##############################################################################\ninterface log_normal_discrete\n\n module procedure log_normal_discrete_1, log_normal_discrete_2\n\nend interface\n\n\n!##############################################################################\n! INTERFACE simulate_uniform\n!\n! Simulates uniformly distributed random variables.\n!##############################################################################\ninterface simulate_uniform\n\n module procedure simulate_uniform_1, simulate_uniform_n\n\nend interface\n\n\n!##############################################################################\n! INTERFACE simulate_normal\n!\n! Simulates normallly distributed random variables.\n!##############################################################################\ninterface simulate_normal\n\n module procedure simulate_normal_1, simulate_normal_n\n\nend interface\n\n\n!##############################################################################\n! INTERFACE simulate_log-normal\n!\n! Simulates log-normallly distributed random variables.\n!##############################################################################\ninterface simulate_log_normal\n\n module procedure simulate_log_normal_1, simulate_log_normal_n\n\nend interface\n\n\n!##############################################################################\n! INTERFACE simulate_Gamma\n!\n! Simulates Gamma distributed random variables.\n!##############################################################################\ninterface simulate_Gamma\n\n module procedure simulate_Gamma_1, simulate_Gamma_n\n\nend interface\n\n\n!##############################################################################\n! INTERFACE simulate_beta\n!\n! Simulates beta distributed random variables.\n!##############################################################################\ninterface simulate_beta\n\n module procedure simulate_beta_1, simulate_beta_n\n\nend interface\n\n\n!##############################################################################\n! INTERFACE simulate_bernoulli\n!\n! Simulates bernoulli distributed random variables.\n!##############################################################################\ninterface simulate_bernoulli\n\n module procedure simulate_bernoulli_1, simulate_bernoulli_n\n\nend interface\n\n\n!##############################################################################\n! INTERFACE simulate_binomial\n!\n! Simulates binomial distributed random variables.\n!##############################################################################\ninterface simulate_binomial\n\n module procedure simulate_binomial_1, simulate_binomial_n\n\nend interface\n\n\n!##############################################################################\n! INTERFACE poly_interpol\n!\n! Interface for onedimensional polynomial interpolation.\n!##############################################################################\ninterface poly_interpol\n\n module procedure poly_interpol_1, poly_interpol_m\n\nend interface\n\n\n!##############################################################################\n! INTERFACE fminsearch\n!\n! Finds minimum of a function.\n!##############################################################################\ninterface fminsearch\n\n module procedure brent, powell\n\nend interface\n\n\n!##############################################################################\n! INTERFACE fzero\n!\n! Finds root of a function.\n!##############################################################################\ninterface fzero\n\n module procedure newton_interpol, broydn\n\nend interface\n\n\n!##############################################################################\n! INTERFACE grid_Inv_Equi\n!\n! Interface for inverting gridpoints.\n!##############################################################################\ninterface grid_Inv_Equi\n\n module procedure grid_Inv_Equi_1, grid_Inv_Equi_m\n\nend interface\n\n\n!##############################################################################\n! INTERFACE grid_Inv_Cheb\n!\n! Interface for inverting gridpoints.\n!##############################################################################\ninterface grid_Inv_Cheb\n\n module procedure grid_Inv_Cheb_1, grid_Inv_Cheb_m\n\nend interface\n\n\n!##############################################################################\n! INTERFACE grid_Inv_Grow\n!\n! Interface for inverting gridpoints.\n!##############################################################################\ninterface grid_Inv_Grow\n\n module procedure grid_Inv_Grow_1, grid_Inv_Grow_m\n\nend interface\n\n\n!##############################################################################\n! INTERFACE linint_Equi\n!\n! Interface for inverting gridpoints.\n!##############################################################################\ninterface linint_Equi\n\n module procedure linint_Equi_1, linint_Equi_m\n\nend interface\n\n\n!##############################################################################\n! INTERFACE linint_Cheb\n!\n! Interface for inverting gridpoints.\n!##############################################################################\ninterface linint_Cheb\n\n module procedure linint_Cheb_1, linint_Cheb_m\n\nend interface\n\n \n!##############################################################################\n! INTERFACE linint_Grow\n!\n! Interface for inverting gridpoints.\n!##############################################################################\ninterface linint_Grow\n\n module procedure linint_Grow_1, linint_Grow_m\n\nend interface\n\n\n!##############################################################################\n! INTERFACE spline_interp\n!\n! Interface for one- or multidimensional spline interpolation.\n!##############################################################################\ninterface spline_interp\n\n module procedure spline_interp1, spline_interp2, spline_interp3, &\n spline_interp4, spline_interp5, spline_interp6, spline_interp7\n\nend interface\n\n\n!##############################################################################\n! INTERFACE spline_eval\n!\n! Interface for evaluation of one- or multidimensional spline.\n!##############################################################################\ninterface spline_eval\n\n module procedure &\n spline1, spline1_grid, &\n spline2, spline2_grid, &\n spline3, spline3_grid, &\n spline4, spline4_grid, &\n spline5, spline5_grid, &\n spline6, spline6_grid, &\n spline7, spline7_grid\n\nend interface\n\n\n!##############################################################################\n! INTERFACE spline\n!\n! Interface for complete interpolation and evaluation of one- or\n! multidimensional spline.\n!##############################################################################\ninterface spline\n\n module procedure &\n spline1_complete, spline1_complete_m , &\n spline2_complete, spline2_complete_m, &\n spline3_complete, spline3_complete_m , &\n spline4_complete, spline4_complete_m, &\n spline5_complete, spline5_complete_m, &\n spline6_complete, spline6_complete_m, &\n spline7_complete, spline7_complete_m\n\nend interface\n\n\n!##############################################################################\n! INTERFACE plot_hist\n!\n! Creates histogram plot\n!##############################################################################\ninterface plot_hist\n\n module procedure &\n plot_hist_old, plot_hist_new\n\nend interface\n\n\n\n!##############################################################################\n! INTERFACE plot3d\n!\n! Creates a two-dimensional plot.\n!##############################################################################\ninterface plot3d\n\n module procedure &\n plot3d_grid, plot3d_line\n\nend interface\n\n\n!##############################################################################\n! INTERFACE sort\n!\n! Interface for sorting arrays.\n!##############################################################################\ninterface sort\n\n module procedure sort_r, sort_r2, sort_i, sort_i2\n\nend interface \n\n\ncontains\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n \n!##############################################################################\n!##############################################################################\n! MODULE errwarn\n!##############################################################################\n!############################################################################## \n \n\n !##############################################################################\n ! SUBROUTINE error\n !\n ! Throws error message and stops program.\n !##############################################################################\n subroutine error(routine, message)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! routine in which error occured\n character(len=*), intent(in) :: routine\n \n ! error message\n character(len=*), intent(in) :: message\n \n \n !##### ROUTINE CODE #######################################################\n \n ! write error message\n write(*,'(/a,a,a,a/)')'ERROR ',routine,': ',message\n \n ! stop program\n stop\n \n end subroutine error\n \n \n !##############################################################################\n ! SUBROUTINE warning\n !\n ! Throws warning message\n !##############################################################################\n subroutine warning(routine, message)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! routine in which warning occured\n character(len=*), intent(in) :: routine\n \n ! warning message\n character(len=*), intent(in) :: message\n \n \n !##### ROUTINE CODE #######################################################\n \n ! write warning message\n write(*,'(/a,a,a,a/)')'WARNING ',routine,': ',message\n \n end subroutine warning\n\n \n \n \n \n \n\n\n\n\n\n\n\n\n\n!############################################################################## \n!##############################################################################\n! MODULE assertions\n!##############################################################################\n!##############################################################################\n \n \n !##############################################################################\n ! FUNCTION assert_eq2\n !\n ! Checks equality for two integers.\n !\n ! PARTS OF THIS PROCEDURE WERE COPIED AND ADAPTED FROM:\n ! Press, W.H., Teukolsky, S.A., Vetterling, W.T. & Flannery, B.P. (1992). \n ! Numerical Recipes in Fortran 90: The Art of Parallel Scientific\n ! Computing, 2nd edition. Cambridge: Cambridge University Press.\n !##############################################################################\n function assert_eq2(n1, n2, string)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! integers to compare for equality\n integer, intent(in) :: n1, n2\n \n ! routine from which error should be thrown\n character(len=*), intent(in) :: string\n \n ! return value\n integer :: assert_eq2\n \n \n !##### ROUTINE CODE #######################################################\n \n ! if equality, set return value to n1\n if (n1 == n2)then\n assert_eq2 = n1\n \n ! else throw error message\n else\n call error(string, 'an assertion failed in assert_eq2')\n end if\n \n end function assert_eq2\n \n \n !##############################################################################\n ! FUNCTION assert_eq3\n !\n ! Checks equality for three integers.\n !\n ! PARTS OF THIS PROCEDURE WERE COPIED AND ADAPTED FROM:\n ! Press, W.H., Teukolsky, S.A., Vetterling, W.T. & Flannery, B.P. (1992). \n ! Numerical Recipes in Fortran 90: The Art of Parallel Scientific\n ! Computing, 2nd edition. Cambridge: Cambridge University Press.\n !##############################################################################\n function assert_eq3(n1, n2, n3, string)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! integers to compare for equality\n integer, intent(in) :: n1, n2, n3\n \n ! routine from which error should be thrown\n character(len=*), intent(in) :: string\n \n ! return value\n integer :: assert_eq3\n \n \n !##### ROUTINE CODE #######################################################\n \n ! if equality, set return value to n1\n if (n1 == n2 .and. n2 == n3)then\n assert_eq3 = n1\n \n ! else throw error message\n else\n call error(string, 'an assertion failed in assert_eq3')\n end if\n \n end function assert_eq3\n \n \n !##############################################################################\n ! FUNCTION assert_eq4\n !\n ! Checks equality for four integers.\n !\n ! PARTS OF THIS PROCEDURE WERE COPIED AND ADAPTED FROM:\n ! Press, W.H., Teukolsky, S.A., Vetterling, W.T. & Flannery, B.P. (1992). \n ! Numerical Recipes in Fortran 90: The Art of Parallel Scientific\n ! Computing, 2nd edition. Cambridge: Cambridge University Press.\n !##############################################################################\n function assert_eq4(n1, n2, n3, n4, string)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! integers to compare for equality\n integer, intent(in) :: n1, n2, n3, n4\n \n ! routine from which error should be thrown\n character(len=*), intent(in) :: string\n \n ! return value\n integer :: assert_eq4\n \n \n !##### ROUTINE CODE #######################################################\n \n ! if equality, set return value to n1\n if (n1 == n2 .and. n2 == n3 .and. n3 == n4)then\n assert_eq4 = n1\n \n ! else throw error message\n else\n call error(string, 'an assertion failed in assert_eq4')\n end if\n \n end function assert_eq4\n \n \n !##############################################################################\n ! FUNCTION assert_eq5\n !\n ! Checks equality for five integers.\n !\n ! PARTS OF THIS PROCEDURE WERE COPIED AND ADAPTED FROM:\n ! Press, W.H., Teukolsky, S.A., Vetterling, W.T. & Flannery, B.P. (1992). \n ! Numerical Recipes in Fortran 90: The Art of Parallel Scientific\n ! Computing, 2nd edition. Cambridge: Cambridge University Press.\n !##############################################################################\n function assert_eq5(n1, n2, n3, n4, n5, string)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! integers to compare for equality\n integer, intent(in) :: n1, n2, n3, n4, n5\n \n ! routine from which error should be thrown\n character(len=*), intent(in) :: string\n \n ! return value\n integer :: assert_eq5\n \n \n !##### ROUTINE CODE #######################################################\n \n ! if equality, set return value to n1\n if (n1 == n2 .and. n2 == n3 .and. n3 == n4 .and. n4 == n5)then\n assert_eq5 = n1\n \n ! else throw error message\n else\n call error(string, 'an assertion failed in assert_eq5')\n end if\n \n end function assert_eq5\n \n \n !##############################################################################\n ! FUNCTION assert_eqn\n !\n ! Checks equality for n integers.\n !\n ! PARTS OF THIS PROCEDURE WERE COPIED AND ADAPTED FROM:\n ! Press, W.H., Teukolsky, S.A., Vetterling, W.T. & Flannery, B.P. (1992). \n ! Numerical Recipes in Fortran 90: The Art of Parallel Scientific\n ! Computing, 2nd edition. Cambridge: Cambridge University Press.\n !##############################################################################\n function assert_eqn(nn, string)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! integers to compare for equality\n integer, intent(in) :: nn(:)\n \n ! routine from which error should be thrown\n character(len=*), intent(in) :: string\n \n ! return value\n integer :: assert_eqn\n \n \n !##### ROUTINE CODE #######################################################\n \n ! if equality, set return value to n1\n if (all(nn(2:) == nn(1)))then\n assert_eqn = nn(1)\n \n ! else throw error message\n else\n call error(string, 'an assertion failed in assert_eqn')\n end if\n \n end function assert_eqn\n \n \n \n \n \n\n\n\n\n\n\n\n\n\n \n!############################################################################## \n!##############################################################################\n! MODULE clock\n!############################################################################## \n!##############################################################################\n \n\n !##############################################################################\n ! SUBROUTINE tic\n !\n ! Starts cpu timer.\n !##############################################################################\n subroutine tic()\n \n \n !##### ROUTINE CODE #######################################################\n \n ! get cpu time\n call cpu_time(starttime_cpu)\n \n end subroutine tic\n \n \n !##############################################################################\n ! SUBROUTINE toc\n !\n ! Stops cpu timer.\n !##############################################################################\n subroutine toc(file)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! optional file identifier\n integer, intent(in), optional :: file\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: time\n integer :: outfile\n real*8 :: times(4)\n \n \n !##### ROUTINE CODE #######################################################\n \n ! get output file identifier\n if(present(file))then\n outfile = file\n else\n outfile = 0\n endif\n \n ! get cpu time\n call cpu_time(time)\n \n ! calculate time difference\n time = time - starttime_cpu\n \n ! get number of days\n times(1) = floor(time/(24d0*60d0*60d0))\n time = time - times(1)*24d0*60d0*60d0\n \n ! get number of hours\n times(2) = floor(time/(60d0*60d0))\n time = time - times(2)*60d0*60d0\n \n ! get number of minutes\n times(3) = floor(time/60d0)\n time = time - times(3)*60d0\n \n ! get number of seconds\n times(4) = time\n \n call outTime(times, outfile)\n \n end subroutine toc\n \n \n !##############################################################################\n ! SUBROUTINE outTime\n !\n ! Writes time to file.\n !##############################################################################\n subroutine outTime(times, file)\n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! time as integer array\n real*8, intent(in) :: times(4)\n \n ! the output file identifier\n integer, intent(in) :: file\n \n !##### OTHER VARIABLES ####################################################\n \n character(len=200) :: output1, output2\n \n \n !##### ROUTINE CODE #######################################################\n \n ! set up output\n write(output1, '(a)')'Time elapsed: '\n output2 = output1\n \n ! write time values\n if(times(1) > 0d0)then\n write(output1, '(a,1x,i3,a)') trim(output2), int(times(1)), ' d '\n output2 = output1\n endif\n if(times(2) > 0d0)then\n write(output1, '(a,1x,i3,a)') trim(output2), int(times(2)), ' h '\n output2 = output1\n endif\n if(times(3) > 0d0) then\n write(output1, '(a,1x,i3,a)')trim(output2), int(times(3)), ' min '\n output2 = output1\n endif\n \n write(output1, '(a,1x,f7.3,a)')trim(output2), times(4), ' s '\n \n if(file > 0) then\n write(file, '(/a/)')trim(output1)\n else\n write(*, '(/a/)')trim(output1)\n endif\n \n end subroutine outTime\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n!############################################################################## \n!##############################################################################\n! MODULE linint\n!############################################################################## \n!##############################################################################\n\n \n !##############################################################################\n ! SUBROUTINE grid_Cons_Equi\n !\n ! Constructs a whole equidistant grid on [left,right].\n !##############################################################################\n subroutine grid_Cons_Equi(a, left, right)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! the array to fill\n real*8, intent(out) :: a(1:)\n \n ! left and right interval point\n real*8, intent(in) :: left, right\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: h\n integer :: j, n\n \n \n !##### ROUTINE CODE #######################################################\n \n ! get number of grid points\n n = size(a, 1)-1\n \n ! check for left <= right\n if(left >= right)call error('grid_Cons_Equi', &\n 'left interval point greater than right point')\n \n ! calculate distance between grid points\n h = (right-left)/dble(n)\n \n ! calculate grid value\n a = h*(/(dble(j), j=0,n)/)+left\n \n end subroutine grid_Cons_Equi\n \n \n !##############################################################################\n ! SUBROUTINE grid_Cons_Cheb\n !\n ! Constructs a whole grid on [left,right] using chebychev nodes.\n !##############################################################################\n subroutine grid_Cons_Cheb(a, left, right)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! the array to fill\n real*8, intent(out) :: a(1:)\n \n ! left and right interval point\n real*8, intent(in) :: left, right\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: j, n\n real*8, parameter :: pi = 3.1415926535897932d0\n \n \n !##### ROUTINE CODE #######################################################\n \n ! get number of grid points\n n = size(a, 1)-1\n \n ! check for left <= right\n if(left >= right)call error('grid_Cons_Cheb', &\n 'left interval point greater than right point')\n \n ! calculate grid value\n a = (left+right)/2d0 + (right-left)/2d0* &\n cos((dble(n)-(/(dble(j), j=0,n)/)+0.5d0)/dble(n+1)*pi)\n \n end subroutine grid_Cons_Cheb\n\n\n !##############################################################################\n ! SUBROUTINE grid_Cons_Grow\n !\n ! Constructs a growing grid on [left, right].\n !##############################################################################\n subroutine grid_Cons_Grow(a, left, right, growth)\n \n implicit none\n\n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! the array to fill\n real*8, intent(out) :: a(1:)\n \n ! left and right interval point\n real*8, intent(in) :: left, right\n \n ! the growth rate of the grid\n real*8 :: growth\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: h\n integer :: j, n\n \n \n !##### ROUTINE CODE #######################################################\n \n ! get number of grid points\n n = size(a, 1)-1\n\n ! check for left <= right\n if(left >= right)call error('grid_Cons_Grow', &\n 'left interval point greater than right point')\n\n ! check for growth\n if(growth <= 0d0)call error('grid_Cons_Grow', &\n 'growth rate must be greater than zero')\n\n ! calculate factor\n h = (right-left)/((1d0+growth)**n-1d0)\n \n ! calculate grid value\n a = h*((1d0+growth)**(/(dble(j), j=0,n)/)-1d0)+left\n\n end subroutine grid_Cons_Grow\n \n \n !##############################################################################\n ! FUNCTION grid_Val_Equi\n !\n ! Calculates single gridpoint of an equidistant grid.\n !##############################################################################\n function grid_Val_Equi(x, left, right, n)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point that shall be calculated\n real*8, intent(in) :: x\n \n ! left and right interval point\n real*8, intent(in) :: left, right\n\n ! last grid point: 0,1,...,n\n integer, intent(in) :: n\n \n ! value at the grid point x \\in [0,n]\n real*8 :: grid_Val_Equi\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: h\n \n \n !##### ROUTINE CODE #######################################################\n \n ! check for left <= right\n if(left >= right)call error('grid_Val_Equi', &\n 'left interval point greater than right point') \n \n ! calculate distance between grid points\n h = (right-left)/n\n \n ! calculate grid value\n grid_Val_Equi = h*x+left\n \n end function grid_Val_Equi\n\n\n !##############################################################################\n ! FUNCTION grid_Val_Cheb\n !\n ! Calculates single gridpoint of a Chebychev grid.\n !##############################################################################\n function grid_Val_Cheb(x, left, right, n)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point that shall be calculated\n real*8, intent(in) :: x\n \n ! left and right interval point\n real*8, intent(in) :: left, right\n\n ! last grid point: 0,1,...,n\n integer, intent(in) :: n\n \n ! value at the grid point x \\in [0,n]\n real*8 :: grid_Val_Cheb\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8, parameter :: pi = 3.1415926535897932d0 \n \n \n !##### ROUTINE CODE #######################################################\n \n ! check for left <= right\n if(left >= right)call error('grid_Val_Cheb', &\n 'left interval point greater than right point') \n \n ! calculate grid value\n grid_Val_Cheb = (left+right)/2d0 + (right-left)/2d0* &\n cos((dble(n)-x+0.5d0)/dble(n+1)*pi)\n \n end function grid_Val_Cheb\n \n\n !##############################################################################\n ! FUNCTION grid_Val_Grow\n !\n ! Calculates single gridpoint of a growing grid.\n !##############################################################################\n function grid_Val_Grow(x, left, right, growth, n)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point that shall be calculated\n real*8, intent(in) :: x\n \n ! left and right interval point\n real*8, intent(in) :: left, right \n \n ! growth rate\n real*8, intent(in) :: growth\n\n ! last grid point: 0,1,...,n\n integer, intent(in) :: n\n \n ! value at the grid point x \\in [0,n]\n real*8 :: grid_Val_Grow\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: h\n \n \n !##### ROUTINE CODE #######################################################\n \n ! check for left <= right\n if(left >= right)call error('grid_Val', &\n 'left interval point greater than right point')\n\n ! check for growth\n if(growth <= 0d0)call error('grid_Val_Grow', &\n 'growth rate must be greater than zero')\n \n ! calculate factor\n h = (right-left)/((1+growth)**n-1)\n \n ! calculate grid value\n grid_Val_Grow = h*((1+growth)**x-1)+left\n \n end function grid_Val_Grow\n\n\n !##############################################################################\n ! FUNCTION grid_Inv_Equi_1\n !\n ! Calculates inverse of gridpoints of an equidistant grid.\n !##############################################################################\n function grid_Inv_Equi_1(x, left, right, n)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point that shall be calculated\n real*8, intent(in) :: x\n \n ! left and right interval point\n real*8, intent(in) :: left, right\n \n ! last grid point: 0,1,...,n\n integer, intent(in) :: n\n \n ! value of the inverse of the gridpoint x \\in [left, right]\n real*8 :: grid_Inv_Equi_1\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: h\n \n \n !##### ROUTINE CODE #######################################################\n \n ! check for left <= right\n if(left >= right)call error('grid_Inv_Equi', &\n 'left interval point greater than right point')\n \n ! calculate distance between grid points\n h = (right-left)/n\n \n ! calculate grid value\n grid_Inv_Equi_1 = (x-left)/h\n \n end function grid_Inv_Equi_1\n\n\n !##############################################################################\n ! FUNCTION grid_Inv_Cheb_1\n !\n ! Calculates inverse of gridpoints of a Chebychev grid.\n !##############################################################################\n function grid_Inv_Cheb_1(x, left, right, n)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point that shall be calculated\n real*8, intent(in) :: x\n \n ! left and right interval point\n real*8, intent(in) :: left, right\n \n ! last grid point: 0,1,...,n\n integer, intent(in) :: n \n \n ! value of the inverse of the gridpoint x \\in [left, right]\n real*8 :: grid_Inv_Cheb_1 \n\n\n !##### OTHER VARIABLES ####################################################\n \n real*8, parameter :: pi = 3.1415926535897932d0 \n \n \n !##### ROUTINE CODE #######################################################\n \n ! check for left <= right\n if(left >= right)call error('grid_Inv_Cheb', &\n 'left interval point greater than right point')\n \n ! calculate grid value\n grid_Inv_Cheb_1 = dble(n) + 0.5d0 - acos((2d0*x-(left+right)) &\n /(right-left))*dble(n+1)/pi\n \n end function grid_Inv_Cheb_1\n \n \n !##############################################################################\n ! FUNCTION grid_Inv_Grow_1\n !\n ! Calculates inverse of gridpoints of a growing grid.\n !##############################################################################\n function grid_Inv_Grow_1(x, left, right, growth, n)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point that shall be calculated\n real*8, intent(in) :: x\n \n ! left and right interval point\n real*8, intent(in) :: left, right\n\n ! growth rate\n real*8, intent(in) :: growth\n \n ! last grid point: 0,1,...,n\n integer, intent(in) :: n \n \n ! value of the inverse of the gridpoint x \\in [left, right]\n real*8 :: grid_Inv_Grow_1\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: h\n \n \n !##### ROUTINE CODE #######################################################\n \n ! check for left <= right\n if(left >= right)call error('grid_Inv_Grow', &\n 'left interval point greater than right point')\n\n ! check for growth\n if(growth <= 0d0)call error('grid_Inv_Grow', &\n 'growth rate must be greater than zero')\n \n ! calculate factor\n h = (right-left)/((1+growth)**n-1d0)\n \n ! calculate grid value\n grid_Inv_Grow_1 = log((x-left)/h+1d0)/log(1d0+growth)\n \n end function grid_Inv_Grow_1\n \n \n !##############################################################################\n ! FUNCTION grid_Inv_Equi_m\n !\n ! Calculates inverse of gridpoints of an equidistant grid.\n !##############################################################################\n function grid_Inv_Equi_m(x, left, right, n)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point that shall be calculated\n real*8, intent(in) :: x(:)\n \n ! left and right interval point\n real*8, intent(in) :: left, right\n \n ! last grid point: 0,1,...,n\n integer, intent(in) :: n \n \n ! value of the inverse of the gridpoint x \\in [left, right]\n real*8 :: grid_Inv_Equi_m(size(x, 1))\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: h\n \n \n !##### ROUTINE CODE #######################################################\n \n ! check for left <= right\n if(left >= right)call error('grid_Inv_Equi', &\n 'left interval point greater than right point')\n \n ! calculate distance between grid points\n h = (right-left)/n\n \n ! calculate grid value\n grid_Inv_Equi_m = (x-left)/h\n \n end function grid_Inv_Equi_m\n\n\n !##############################################################################\n ! FUNCTION grid_Inv_Cheb_m\n !\n ! Calculates inverse of gridpoints of a Chebychev grid.\n !##############################################################################\n function grid_Inv_Cheb_m(x, left, right, n)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point that shall be calculated\n real*8, intent(in) :: x(:)\n \n ! left and right interval point\n real*8, intent(in) :: left, right\n \n ! last grid point: 0,1,...,n\n integer, intent(in) :: n \n \n ! value of the inverse of the gridpoint x \\in [left, right]\n real*8 :: grid_Inv_Cheb_m(size(x, 1))\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8, parameter :: pi = 3.1415926535897932d0 \n \n \n !##### ROUTINE CODE #######################################################\n \n ! check for left <= right\n if(left >= right)call error('grid_Inv_Cheb', &\n 'left interval point greater than right point')\n \n ! calculate grid value\n grid_Inv_Cheb_m = dble(n) + 0.5d0 - acos((2d0*x-(left+right)) &\n /(right-left))*dble(n+1)/pi\n \n end function grid_Inv_Cheb_m\n\n\n !##############################################################################\n ! FUNCTION grid_Inv_Grow_m\n !\n ! Calculates inverse of gridpoints of a growing grid.\n !##############################################################################\n function grid_Inv_Grow_m(x, left, right, growth, n)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point that shall be calculated\n real*8, intent(in) :: x(:)\n \n ! left and right interval point\n real*8, intent(in) :: left, right\n\n ! growth rate\n real*8, intent(in) :: growth\n \n ! last grid point: 0,1,...,n\n integer, intent(in) :: n\n \n ! value of the inverse of the gridpoint x \\in [left, right]\n real*8 :: grid_Inv_Grow_m(size(x, 1))\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: h\n \n \n !##### ROUTINE CODE #######################################################\n \n ! check for left <= right\n if(left >= right)call error('grid_Inv_Grow', &\n 'left interval point greater than right point')\n\n ! check for growth\n if(growth <= 0d0)call error('grid_Inv_Grow', &\n 'growth rate must be greater than zero')\n \n ! calculate factor\n h = (right-left)/((1d0+growth)**n-1d0)\n\n ! calculate grid value\n grid_Inv_Grow_m = log((x-left)/h+1d0)/log(1d0+growth)\n \n end function grid_Inv_Grow_m\n\n\n !##############################################################################\n ! subroutine linint_Equi_1\n !\n ! Calculates linear interpolant on an equidistant grid.\n !##############################################################################\n subroutine linint_Equi_1(x, left, right, n, il, ir, phi)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point that shall be calculated\n real*8, intent(in) :: x\n \n ! left and right interval point\n real*8, intent(in) :: left, right\n \n ! last grid point: 0,1,...,n\n integer, intent(in) :: n\n \n ! left interpolation point\n integer, intent(out) :: il\n \n ! right interpolation point\n integer, intent(out) :: ir\n\n ! interpolation fraction\n real*8, intent(out) :: phi\n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: h, xinv, xl, xr\n \n \n !##### ROUTINE CODE #######################################################\n \n ! invert the grid to get point\n xinv = grid_Inv_Equi_1(min(max(x, left), right), left, right, n)\n \n ! get left and right gridpoint\n il = min(max(floor(xinv), 0), n-1)\n ir = il+1\n\n ! determine left and right gridpoint\n h = (right-left)/n\n xl = h*dble(il)+left\n xr = h*dble(ir)+left\n\n ! get share on the left point\n phi = (xr-x)/(xr-xl)\n \n end subroutine linint_Equi_1\n\n\n !##############################################################################\n ! subroutine linint_Equi_m\n !\n ! Calculates linear interpolant on an equidistant grid.\n !##############################################################################\n subroutine linint_Equi_m(x, left, right, n, il, ir, phi)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point that shall be calculated\n real*8, intent(in) :: x(:)\n \n ! left and right interval point\n real*8, intent(in) :: left, right\n \n ! last grid point: 0,1,...,n\n integer, intent(in) :: n\n \n ! left interpolation point\n integer, intent(out) :: il(:)\n \n ! right interpolation point\n integer, intent(out) :: ir(:)\n\n ! interpolation fraction\n real*8, intent(out) :: phi(:)\n \n !##### OTHER VARIABLES ####################################################\n \n integer :: m\n real*8 :: h, xinv(size(x, 1)), xl(size(x, 1)), xr(size(x, 1))\n \n \n !##### ROUTINE CODE #######################################################\n\n ! check for sizes\n m = assert_eq(size(x, 1), size(il, 1), size(ir, 1), size(phi, 1), 'linint_Equi')\n m = m\n \n ! invert the grid to get point\n xinv = grid_Inv_Equi_m(min(max(x, left), right), left, right, n)\n \n ! get left and right gridpoint\n il = min(max(floor(xinv), 0), n-1)\n ir = il+1\n\n ! determine left and right gridpoint\n h = (right-left)/n\n xl = h*dble(il)+left\n xr = h*dble(ir)+left\n\n ! get share on the left point\n phi = (xr-x)/(xr-xl)\n \n end subroutine linint_Equi_m\n\n\n !##############################################################################\n ! subroutine linint_Cheb_1\n !\n ! Calculates linear interpolant on an equidistant grid.\n !##############################################################################\n subroutine linint_Cheb_1(x, left, right, n, il, ir, phi)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point that shall be calculated\n real*8, intent(in) :: x\n \n ! left and right interval point\n real*8, intent(in) :: left, right\n \n ! last grid point: 0,1,...,n\n integer, intent(in) :: n\n \n ! left interpolation point\n integer, intent(out) :: il\n \n ! right interpolation point\n integer, intent(out) :: ir\n\n ! interpolation fraction\n real*8, intent(out) :: phi\n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: xinv, xl, xr\n real*8, parameter :: pi = 3.1415926535897932d0 \n \n \n !##### ROUTINE CODE #######################################################\n \n ! invert the grid to get point\n xinv = grid_Inv_Cheb_1(min(max(x, left), right), left, right, n)\n \n ! get left and right gridpoint\n il = min(max(floor(xinv), 0), n-1)\n ir = il+1\n\n ! determine left and right gridpoint \n xl = (left+right)/2d0 + (right-left)/2d0* &\n cos((dble(n)-dble(il)+0.5d0)/dble(n+1)*pi)\n xr = (left+right)/2d0 + (right-left)/2d0* &\n cos((dble(n)-dble(ir)+0.5d0)/dble(n+1)*pi)\n\n ! get share on the left point\n phi = (xr-x)/(xr-xl)\n \n end subroutine linint_Cheb_1\n\n\n !##############################################################################\n ! subroutine linint_Cheb_m\n !\n ! Calculates linear interpolant on a Chebychev grid.\n !##############################################################################\n subroutine linint_Cheb_m(x, left, right, n, il, ir, phi)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point that shall be calculated\n real*8, intent(in) :: x(:)\n \n ! left and right interval point\n real*8, intent(in) :: left, right\n \n ! last grid point: 0,1,...,n\n integer, intent(in) :: n\n \n ! left interpolation point\n integer, intent(out) :: il(:)\n \n ! right interpolation point\n integer, intent(out) :: ir(:)\n\n ! interpolation fraction\n real*8, intent(out) :: phi(:)\n \n !##### OTHER VARIABLES ####################################################\n \n integer :: m\n real*8 :: xinv(size(x, 1)), xl(size(x, 1)), xr(size(x, 1))\n real*8, parameter :: pi = 3.1415926535897932d0\n \n \n !##### ROUTINE CODE #######################################################\n\n ! check for sizes\n m = assert_eq(size(x, 1), size(il, 1), size(ir, 1), size(phi, 1), 'linint_Equi')\n m = m\n \n ! invert the grid to get point\n xinv = grid_Inv_Cheb_m(min(max(x, left), right), -1d0, 1d0, n)\n \n ! get left and right gridpoint\n il = min(max(floor(xinv), 0), n-1)\n ir = il+1\n\n ! determine left and right gridpoint\n xl = (left+right)/2d0 + (right-left)/2d0* &\n cos((dble(n)-dble(il)+0.5d0)/dble(n+1)*pi)\n xr = (left+right)/2d0 + (right-left)/2d0* &\n cos((dble(n)-dble(ir)+0.5d0)/dble(n+1)*pi)\n\n ! get share on the left point\n phi = (xr-x)/(xr-xl)\n \n end subroutine linint_Cheb_m\n\n \n !##############################################################################\n ! subroutine linint_Grow_1\n !\n ! Calculates linear interpolant on a growing grid.\n !##############################################################################\n subroutine linint_Grow_1(x, left, right, growth, n, il, ir, phi)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point that shall be calculated\n real*8, intent(in) :: x\n \n ! left and right interval point\n real*8, intent(in) :: left, right\n\n ! growth rate\n real*8, intent(in) :: growth\n \n ! last grid point: 0,1,...,n\n integer, intent(in) :: n\n \n ! left interpolation point\n integer, intent(out) :: il\n \n ! right interpolation point\n integer, intent(out) :: ir\n\n ! interpolation fraction\n real*8, intent(out) :: phi\n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: h, xinv, xl, xr\n \n \n !##### ROUTINE CODE #######################################################\n \n ! check for left <= right\n if(left >= right)call error('linint_Grow', &\n 'left interval point greater than right point')\n \n ! invert the grid to get point\n xinv = grid_Inv_Grow_1(min(max(x, left), right), left, right, growth, n)\n \n ! get left and right gridpoint\n il = min(max(floor(xinv), 0), n-1)\n ir = il+1\n\n ! determine left and right gridpoint\n h = (right-left)/((1+growth)**n-1) \n xl = h*((1+growth)**dble(il)-1d0)+left\n xr = h*((1+growth)**dble(ir)-1d0)+left\n\n ! get share on the left point\n phi = (xr-x)/(xr-xl)\n \n end subroutine linint_Grow_1\n\n\n !##############################################################################\n ! subroutine linint_Grow_m\n !\n ! Calculates linear interpolant on an equidistant grid.\n !##############################################################################\n subroutine linint_Grow_m(x, left, right, growth, n, il, ir, phi)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point that shall be calculated\n real*8, intent(in) :: x(:)\n \n ! left and right interval point\n real*8, intent(in) :: left, right\n\n ! growth rate\n real*8, intent(in) :: growth\n \n ! last grid point: 0,1,...,n\n integer, intent(in) :: n\n \n ! left interpolation point\n integer, intent(out) :: il(:)\n \n ! right interpolation point\n integer, intent(out) :: ir(:)\n\n ! interpolation fraction\n real*8, intent(out) :: phi(:)\n \n !##### OTHER VARIABLES ####################################################\n \n integer :: m\n real*8 :: h, xinv(size(x, 1)), xl(size(x, 1)), xr(size(x, 1))\n \n \n !##### ROUTINE CODE #######################################################\n\n ! check for sizes\n m = assert_eq(size(x, 1), size(il, 1), size(ir, 1), size(phi, 1), 'linint_Equi')\n m = m\n \n ! check for left <= right\n if(left >= right)call error('linint_Grow', &\n 'left interval point greater than right point')\n \n ! invert the grid to get point\n xinv = grid_Inv_Grow_m(min(max(x, left), right), left, right, growth, n)\n \n ! get left and right gridpoint\n il = min(max(floor(xinv), 0), n-1)\n ir = il+1\n\n ! determine left and right gridpoint\n h = (right-left)/((1+growth)**n-1) \n xl = h*((1+growth)**dble(il)-1d0)+left\n xr = h*((1+growth)**dble(ir)-1d0)+left\n\n ! get share on the left point\n phi = (xr-x)/(xr-xl)\n \n end subroutine linint_Grow_m\n\n\n !##############################################################################\n ! function linint_Gen\n !\n ! For linear interpolation on irregular grids.\n !##############################################################################\n function linint_Gen(x, xi, yi, istart_in)\n\n \n !##### INPUT/OUTPUT VARIABLES #############################################\n\n ! point where to evaluate\n real*8, intent(in) :: x\n\n ! grid on which to evaluate\n real*8, intent(in) :: xi(0:)\n\n ! data which to evaluate\n real*8, intent(in) :: yi(0:)\n \n ! (optional) point where to start\n integer, intent(in), optional :: istart_in\n\n ! output value\n real*8 :: linint_Gen\n\n \n !##### OTHER VARIABLES ####################################################\n\n ! other variables\n integer :: ial, iar, n, istart\n real*8 :: phi\n\n\n !##### ROUTINE CODE #######################################################\n\n n = assert_eq(size(xi,1), size(yi,1), 'linint_Gen')-1\n\n if(present(istart_in))then\n istart = min(max(istart_in, 0), n)\n else\n istart = n/2\n endif\n \n ! if grid value too large, search for first smaller point\n if(xi(istart) > x)then\n ial = istart\n do \n ial = ial - 1\n if(ial <= 0)exit\n if(xi(ial) <= x)exit\n enddo\n ial = max(ial, 0)\n ial = min(ial, n-1) \n iar = ial+1\n\n ! if grid value too small, search for first larger point\n else\n iar = istart\n do \n iar = iar + 1\n if(iar >= n)exit\n if(xi(iar) >= x)exit\n enddo\n iar = max(iar, 1)\n iar = min(iar, n) \n ial = iar-1\n endif\n\n ! linearly interpolate between the two points\n phi = 1d0 - (x-xi(ial))/(xi(iar)-xi(ial)) \n linint_Gen = phi*yi(ial) + (1d0-phi)*yi(iar)\n\n end function\n\n\n\n\n \n!############################################################################## \n!##############################################################################\n! MODULE matrixtools\n!\n!##############################################################################\n!##############################################################################\n \n \n !##############################################################################\n ! SUBROUTINE lu_solve\n !\n ! Solves a linear equation system by lu-decomposition.\n !\n ! PARTS OF THIS PROCEDURE WERE COPIED AND ADAPTED FROM:\n ! Press, W.H., Teukolsky, S.A., Vetterling, W.T. & Flannery, B.P. (1992). \n ! Numerical Recipes in Fortran 90: The Art of Parallel Scientific\n ! Computing, 2nd edition. Cambridge: Cambridge University Press.\n !##############################################################################\n subroutine lu_solve(a, b)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! matrix of the system\n real*8, intent(in) :: a(:, :)\n \n ! right side of equation and solution of the system\n real*8, intent(inout) :: b(:)\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: indx(size(b))\n real*8 :: worka(size(a, 1), size(a, 2))\n real*8 :: d\n integer :: n\n \n \n !##### ROUTINE CODE #######################################################\n \n ! assert size equality\n n = assert_eq(size(a,1), size(a,2), size(b), 'lu_solve')\n n = n\n \n ! copy matrix to working matrix\n worka = a\n \n ! decompose matrix\n call lu_decomp(worka, indx, d)\n \n ! solve system\n call lu_back(worka, indx, b)\n \n end subroutine lu_solve\n \n \n !##############################################################################\n ! FUNCTION lu_invert\n !\n ! Inverts a matrix by lu-decomposition.\n !\n ! PARTS OF THIS PROCEDURE WERE COPIED AND ADAPTED FROM:\n ! Press, W.H., Teukolsky, S.A., Vetterling, W.T. & Flannery, B.P. (1992). \n ! Numerical Recipes in Fortran 90: The Art of Parallel Scientific\n ! Computing, 2nd edition. Cambridge: Cambridge University Press.\n !##############################################################################\n function lu_invert(a)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! matrix of the system\n real*8, intent(in) :: a(:, :)\n \n ! the inverse of the matrix\n real*8 :: lu_invert(size(a, 1), size(a, 2))\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: j, n\n \n \n !##### ROUTINE CODE #######################################################\n \n ! assert size equality\n n = assert_eq(size(a,1), size(a,2), 'lu_invert')\n \n ! set up unity matrix\n lu_invert = 0d0\n do j = 1, n\n lu_invert(j, j) = 1d0\n enddo\n \n ! succesively solve the system with unity matrix\n do j = 1, n\n call lu_solve(a, lu_invert(:, j))\n enddo\n \n end function lu_invert\n \n \n !##############################################################################\n ! SUBROUTINE lu_decomp\n !\n ! Calculates lu-decomposition of matrices.\n !\n ! PARTS OF THIS PROCEDURE WERE COPIED AND ADAPTED FROM:\n ! Press, W.H., Teukolsky, S.A., Vetterling, W.T. & Flannery, B.P. (1992). \n ! Numerical Recipes in Fortran 90: The Art of Parallel Scientific\n ! Computing, 2nd edition. Cambridge: Cambridge University Press.\n !##############################################################################\n subroutine lu_decomp(a, indx, d)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! matrix that shall be decomposed\n real*8, intent(inout) :: a(:, :)\n \n ! row permutation indicator due to pivoting\n integer, intent(out) :: indx(:)\n \n ! indicates whether number of row permutations was even or odd\n real*8, intent(out) :: d\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: vv(size(a,1))\n real*8, parameter :: tiny = 1.0e-20\n integer :: j, n, imax\n \n \n !##### ROUTINE CODE #######################################################\n \n ! check array sizes\n n = assert_eq(size(a,1), size(a,2), size(indx),'lu_decomp')\n \n ! initialize permutation indicator\n d = 1d0\n \n ! get maximum value in every row\n vv = maxval(abs(a), dim=2)\n \n ! if there is a zero row then matrix is singular\n if (any(abs(vv) <= 1d-100)) call error('lu_decomp', 'matrix is singular')\n \n ! invert v\n vv = 1d0/vv\n \n ! start lu-decomposition process\n do j = 1, n\n \n ! get index of pivot element\n imax = (j-1) + imaxloc(vv(j:n)*abs(a(j:n,j)))\n \n ! do pivoting if pivot element is not the first element\n if(j /= imax)then\n call swap(a(imax,:), a(j,:))\n d = -d\n vv(imax) = vv(j)\n endif\n \n ! indicate pivot element\n indx(j) = imax\n \n ! prevent division by 0\n if(abs(a(j,j)) <= 1d-100)call error('lu_decomp', 'matrix is singular')\n \n ! calculate new elements\n a(j+1:n, j) = a(j+1:n,j)/a(j,j)\n a(j+1:n, j+1:n) = a(j+1:n,j+1:n)-outerprod(a(j+1:n,j), a(j,j+1:n))\n enddo\n \n \n !##### SUBROUTINES AND FUNCTIONS ##########################################\n \n contains\n \n \n function outerprod(a, b)\n \n real*8, intent(in) :: a(:), b(:)\n real*8 :: outerprod(size(a, 1),size(b, 1))\n \n outerprod = spread(a, dim=2, ncopies=size(b, 1)) * &\n spread(b, dim=1, ncopies=size(a, 1))\n \n end function outerprod\n \n \n subroutine swap(a, b)\n \n real*8, intent(inout) :: a(:), b(:)\n real*8 :: dum(size(a))\n \n dum = a\n a = b\n b = dum\n \n end subroutine swap\n \n \n function imaxloc(arr)\n \n real*8, intent(in) :: arr(:)\n integer :: imaxloc\n integer :: imax(1)\n \n imax = maxloc(arr(:))\n imaxloc = imax(1)\n \n end function imaxloc\n \n end subroutine lu_decomp\n \n \n \n !##############################################################################\n ! SUBROUTINE lu_dec\n !\n ! Calculates lu-decomposition of matrices and returns L and U matrix.\n !\n ! PARTS OF THIS PROCEDURE WERE COPIED AND ADAPTED FROM:\n ! Press, W.H., Teukolsky, S.A., Vetterling, W.T. & Flannery, B.P. (1992). \n ! Numerical Recipes in Fortran 90: The Art of Parallel Scientific\n ! Computing, 2nd edition. Cambridge: Cambridge University Press.\n !##############################################################################\n subroutine lu_dec(a, l, u)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! matrix that shall be decomposed\n real*8, intent(in) :: a(:, :)\n \n ! lower triangular matrix\n real*8, intent(out) :: l(:, :)\n \n ! upper triangular martix\n real*8, intent(out) :: u(:, :)\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: Awork(size(a,1), size(a,2))\n integer :: indx(size(a,1))\n real*8 :: d\n integer :: n, j\n \n \n !##### ROUTINE CODE #######################################################\n \n ! check array sizes\n n = assert_eq((/size(a,1), size(a,2), size(l, 1), size(l, 2), &\n size(u, 1), size(u, 2)/), 'lu_dec')\n \n ! copy matrix\n Awork(:, :) = A(:, :)\n \n ! calculate decomposition\n call lu_decomp(Awork, indx, d)\n \n ! initialize matrices\n L(:, :) = 0d0\n U(:, :) = 0d0\n \n ! set up new matrices\n do j = 1, n\n \n ! diagonal element of L\n L(j, j) = 1d0\n \n ! other elements of L\n L(j, 1:j-1) = Awork(j, 1:j-1)\n \n ! elements of U\n U(j, j:n) = AWork(j, j:n)\n enddo\n \n end subroutine lu_dec\n \n \n !##############################################################################\n ! SUBROUTINE lu_back\n !\n ! Solves a lu decomposed linear equation system by backsubstitution.\n !\n ! PARTS OF THIS PROCEDURE WERE COPIED AND ADAPTED FROM:\n ! Press, W.H., Teukolsky, S.A., Vetterling, W.T. & Flannery, B.P. (1992). \n ! Numerical Recipes in Fortran 90: The Art of Parallel Scientific\n ! Computing, 2nd edition. Cambridge: Cambridge University Press.\n !##############################################################################\n subroutine lu_back(a, indx, b)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! lu-decomposed matrix that defines system\n real*8, intent(in) :: a(:, :)\n \n ! row permutation indicator due to pivoting\n integer, intent(in) :: indx(:)\n \n ! right side of equation and solution of the system\n real*8, intent(inout) :: b(:)\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: summ\n integer :: i, n, ii, ll\n \n \n !##### ROUTINE CODE #######################################################\n \n ! assert size equality\n n = assert_eq(size(a,1), size(a,2), size(indx), size(b), 'lu_back')\n \n ! start backward solving provess\n ii = 0\n do i = 1, n\n \n ll = indx(i)\n summ = b(ll)\n b(ll) = b(i)\n if(ii /= 0)then\n summ = summ-dot_product(a(i,ii:i-1), b(ii:i-1))\n elseif (abs(summ) >= 1d-100) then\n ii = i\n endif\n b(i)=summ\n enddo\n \n do i=n, 1, -1\n b(i) = (b(i)-dot_product(a(i,i+1:n), b(i+1:n)))/a(i,i)\n enddo\n \n end subroutine lu_back\n \n \n \n !##############################################################################\n ! SUBROUTINE cholesky\n !\n ! Calculates cholesky factorization of a symmetric matrix.\n !\n ! PARTS OF THIS PROCEDURE WERE COPIED AND ADAPTED FROM:\n ! Press, W.H., Teukolsky, S.A., Vetterling, W.T. & Flannery, B.P. (1992). \n ! Numerical Recipes in Fortran 90: The Art of Parallel Scientific\n ! Computing, 2nd edition. Cambridge: Cambridge University Press.\n !##############################################################################\n subroutine cholesky(a, l)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! the matrix that should be decomposed\n real*8, intent(in) :: a(:, :)\n \n ! the cholesky factor\n real*8, intent(out) :: l(:, :)\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: i, n\n real*8 :: summ, p(size(a,1))\n \n \n !##### ROUTINE CODE #######################################################\n \n ! assert equalities\n n = assert_eq(size(a,1), size(a,2), size(l, 1), size(l, 2), &\n size(p), 'cholesky')\n \n ! copy matrix\n l = a\n \n ! decompose matrix\n do i = 1, n\n summ = l(i,i)-dot_product(l(i,1:i-1), l(i,1:i-1))\n if(summ <= 0d0)call error('cholesky', &\n 'Cholesky decomposition failed')\n p(i) = sqrt(summ)\n l(i+1:n,i) = (l(i,i+1:n)-matmul(l(i+1:n,1:i-1),l(i,1:i-1)))/p(i)\n enddo\n \n ! copy matrix\n do i = 1, n\n l(i, i) = p(i)\n l(i, i+1:n) = 0d0\n enddo\n \n end subroutine cholesky\n \n \n \n \n \n\n\n\n\n\n\n\n\n\n \n!############################################################################## \n!##############################################################################\n! MODULE probabilities\n!##############################################################################\n!##############################################################################\n \n\n !##############################################################################\n ! FUNCTION uniformPDF\n !\n ! Calculates uniform density at point x.\n !##############################################################################\n function uniformPDF(x, a, b)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point where to calculate function\n real*8, intent(in) :: x\n \n ! left end of the distribution\n real*8, optional :: a\n \n ! right end of the distribution\n real*8, optional :: b\n \n ! value of the uniform density\n real*8 :: uniformPDF\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: a_c, b_c\n \n \n !##### ROUTINE CODE #######################################################\n \n ! initialize parameters\n a_c = 0d0\n if(present(a))a_c = a\n b_c = 1d0\n if(present(b))b_c = b\n \n if(b_c < a_c)then\n call error('uniformPDF','b is smaller than a')\n endif\n \n if(x < a_c .or. x > b_c)then\n uniformPDF = 0d0\n else\n uniformPDF = 1d0/(b_c-a_c)\n endif\n \n end function uniformPDF\n \n \n !##############################################################################\n ! FUNCTION uniformCDF\n !\n ! Calculates cumulated uniform distribution at point x.\n !##############################################################################\n function uniformCDF(x, a, b)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point where to calculate function\n real*8, intent(in) :: x\n \n ! left end of the distribution\n real*8, optional :: a\n \n ! right end of the distribution\n real*8, optional :: b\n \n ! value of the uniform distribution function\n real*8 :: uniformCDF\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: a_c, b_c\n \n \n !##### ROUTINE CODE #######################################################\n \n ! initialize parameters\n a_c = 0d0\n if(present(a))a_c = a\n b_c = 1d0\n if(present(b))b_c = b\n \n if(b_c < a_c)then\n call error('uniformCDF','b is smaller than a')\n endif\n \n if(x <= a_c)then\n uniformCDF = 0d0\n elseif(x >= b_c)then\n uniformCDF = 1d0\n else\n uniformCDF = (x-a_c)/(b_c-a_c)\n endif\n \n end function uniformCDF\n \n \n !##############################################################################\n ! FUNCTION uniformCDF_Inv\n !\n ! Calculates inverse cumulated uniform distribution at point x.\n !##############################################################################\n function uniformCDF_Inv(x, a, b)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point where to calculate function\n real*8, intent(in) :: x\n \n ! left end of the distribution\n real*8, optional :: a\n \n ! right end of the distribution\n real*8, optional :: b\n \n ! value of the uniform distribution function\n real*8 :: uniformCDF_Inv\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: a_c, b_c\n \n \n !##### ROUTINE CODE #######################################################\n \n ! initialize parameters\n a_c = 0d0\n if(present(a))a_c = a\n b_c = 1d0\n if(present(b))b_c = b\n \n if(b_c < a_c)then\n call error('uniformCDF_Inv','b is smaller than a')\n endif\n \n if(x <= 0d0)then\n uniformCDF_Inv = a_c\n elseif(x >= 1d0)then\n uniformCDF_Inv = b_c\n else\n uniformCDF_Inv = a_c + x*(b_c-a_c)\n endif\n \n end function uniformCDF_Inv\n\n\n !##############################################################################\n ! FUNCTION normalPDF\n !\n ! Calculates normal density functions at point x.\n !##############################################################################\n function normalPDF(x, mu, sigma)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point where to calculate function\n real*8, intent(in) :: x\n \n ! expectation of distribution\n real*8, optional :: mu\n \n ! variance of distribution\n real*8, optional :: sigma\n \n ! value of normal density at p\n real*8 :: normalPDF\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: mu_c, sigma_c\n real*8, parameter :: pi = 3.1415926535897d0\n \n \n !##### ROUTINE CODE #######################################################\n \n ! initialize parameters\n mu_c = 0d0\n if(present(mu))mu_c = mu\n sigma_c = 1d0\n if(present(sigma))sigma_c = sqrt(sigma)\n \n if(sigma_c <= 0d0)then\n call error('normalCDF','sigma has zero or negative value')\n endif\n \n normalPDF = 1d0/(sigma_c*sqrt(2d0*pi))*exp(-((x-mu_c)/sigma_c)**2/2d0)\n \n end function normalPDF\n \n \n !##############################################################################\n ! FUNCTION normalCDF\n !\n ! Calculates cumulated normal distribution at point x.\n !\n ! PARTS OF THIS PROCEDURE WERE COPIED AND ADAPTED FROM:\n ! Fortran Code by John Burkardt available as Algorithm ASA066 from \n ! https://people.sc.fsu.edu/~jburkardt/f_src/asa066/asa066.html\n !\n ! REFERENCE: Hill, D. (1973). Algorithm AS 66: The Normal Integral.\n ! Applied Statistics, 22(3), 424-427.\n !##############################################################################\n function normalCDF(x, mu, sigma)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point where to calculate function\n real*8, intent(in) :: x\n \n ! expectation of distribution\n real*8, optional :: mu\n \n ! variance of distribution\n real*8, optional :: sigma\n \n ! value of the normal distribution at x\n real*8 :: normalCDF\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: mu_c, sigma_c, xtrans, xabs, y\n real*8, parameter :: a0 = 0.5d0\n real*8, parameter :: a1 = 0.398942280444d0\n real*8, parameter :: a2 = 0.399903438504d0\n real*8, parameter :: a3 = 5.75885480458d0\n real*8, parameter :: a4 = 29.8213557808d0\n real*8, parameter :: a5 = 2.62433121679d0\n real*8, parameter :: a6 = 48.6959930692d0\n real*8, parameter :: a7 = 5.92885724438d0\n real*8, parameter :: b0 = 0.398942280385d0\n real*8, parameter :: b1 = 3.8052d-8\n real*8, parameter :: b2 = 1.00000615302d0\n real*8, parameter :: b3 = 3.98064794d-4\n real*8, parameter :: b4 = 1.98615381364d0\n real*8, parameter :: b5 = 0.151679116635d0\n real*8, parameter :: b6 = 5.29330324926d0\n real*8, parameter :: b7 = 4.8385912808d0\n real*8, parameter :: b8 = 15.1508972451d0\n real*8, parameter :: b9 = 0.742380924027d0\n real*8, parameter :: b10 = 30.789933034d0\n real*8, parameter :: b11 = 3.99019417011d0\n \n \n !##### ROUTINE CODE #######################################################\n \n ! initialize parameters\n mu_c = 0d0\n if(present(mu))mu_c = mu\n sigma_c = 1d0\n if(present(sigma))then\n if(sigma_c > 0d0)sigma_c = sqrt(sigma)\n endif\n \n if(sigma_c <= 0d0)then\n call error('normalCDF','sigma has zero or negative value')\n endif\n \n ! standardize evaluation point\n xtrans = (x - mu_c)/sigma_c\n \n ! calculate absolute value and quadratic\n xabs = abs(xtrans)\n y = a0*xtrans**2\n \n ! choose the right interval for calculation\n if(xabs <= 1.28d0)then\n normalCDF = a0-xabs*(a1-a2*y/(y+a3-a4/(y+a5+a6/(y+a7))))\n elseif(xabs <= 12.7d0)then\n normalCDF = b0*exp(-y)/(xabs-b1+b2/(xabs+b3+b4/(xabs-b5+b6/(xabs+b7-b8/ &\n (xabs+b9+b10/(xabs+b11))))))\n else\n normalCDF = 0d0\n endif\n \n ! transform if other side of the bell\n if(xtrans > 0d0)normalCDF = 1d0-normalCDF\n \n end function normalCDF\n \n \n !##############################################################################\n ! FUNCTION normalCDF_Inv\n !\n ! Calculates inverse cumulated normal distribution at point x.\n !\n ! PARTS OF THIS PROCEDURE WERE COPIED AND ADAPTED FROM:\n ! Fortran Code by John Burkardt available as Algorithm ASA241 from \n ! https://people.sc.fsu.edu/~jburkardt/f_src/asa241/asa241.html\n !\n ! REFERENCE: Wichura, M. (1988). Algorithm AS 241: The Percentage Points \n ! of the Normal Distribution. Applied Statistics, 37(3),\n ! 477-484.\n !##############################################################################\n function normalCDF_Inv(x, mu, sigma)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point where to calculate function\n real*8 :: x\n \n ! expectation of distribution\n real*8, optional :: mu\n \n ! variance of distribution\n real*8, optional :: sigma\n \n ! value of the inverse of the normal distribution at x \n real*8 :: normalCDF_Inv\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: mu_c, sigma_c, q, r\n real*8, parameter :: a(8) = (/ 3.3871328727963666080d0, &\n 1.3314166789178437745d2, &\n 1.9715909503065514427d3, &\n 1.3731693765509461125d4, &\n 4.5921953931549871457d4, &\n 6.7265770927008700853d4, &\n 3.3430575583588128105d4, &\n 2.5090809287301226727d3 /)\n real*8, parameter :: b(8) = (/ 1.0d0, &\n 4.2313330701600911252d1, &\n 6.8718700749205790830d2, &\n 5.3941960214247511077d3, &\n 2.1213794301586595867d4, &\n 3.9307895800092710610d4, &\n 2.8729085735721942674d4, &\n 5.2264952788528545610d3 /)\n real*8, parameter :: c(8) = (/ 1.42343711074968357734d0, &\n 4.63033784615654529590d0, &\n 5.76949722146069140550d0, &\n 3.64784832476320460504d0, &\n 1.27045825245236838258d0, &\n 2.41780725177450611770d-1, &\n 2.27238449892691845833d-2, &\n 7.74545014278341407640d-4 /)\n real*8, parameter :: const1 = 0.180625d0\n real*8, parameter :: const2 = 1.6d0\n real*8, parameter :: d(8) = (/ 1.0d0, &\n 2.05319162663775882187d0, &\n 1.67638483018380384940d0, &\n 6.89767334985100004550d-1, &\n 1.48103976427480074590d-1, &\n 1.51986665636164571966d-2, &\n 5.47593808499534494600d-4, &\n 1.05075007164441684324d-9 /)\n real*8, parameter :: e(8) = (/ 6.65790464350110377720d0, &\n 5.46378491116411436990d0, &\n 1.78482653991729133580d0, &\n 2.96560571828504891230d-1, &\n 2.65321895265761230930d-2, &\n 1.24266094738807843860d-3, &\n 2.71155556874348757815d-5, &\n 2.01033439929228813265d-7 /)\n real*8, parameter :: f(8) = (/ 1.0d0, &\n 5.99832206555887937690d-1, &\n 1.36929880922735805310d-1, &\n 1.48753612908506148525d-2, &\n 7.86869131145613259100d-4, &\n 1.84631831751005468180d-5, &\n 1.42151175831644588870d-7, &\n 2.04426310338993978564d-15 /)\n\n real*8, parameter :: split1 = 0.425D+00\n real*8, parameter :: split2 = 5.0D+00\n \n \n !##### ROUTINE CODE #######################################################\n \n ! initialize parameters\n mu_c = 0d0\n if(present(mu))mu_c = mu\n sigma_c = 1d0\n if(present(sigma))then\n if(sigma_c > 0d0)sigma_c = sqrt(sigma)\n endif\n \n if(sigma_c <= 0d0)then\n call error('normalCDF_Inv','sigma has zero or negative value')\n endif\n \n ! check for very small or large values\n if(x <= 0d0)then\n normalcdf_Inv = - huge(x)\n return\n endif\n \n if (x >= 1d0)then\n normalcdf_Inv = huge(x)\n return\n endif\n \n ! calculate for reasonable values\n q = x - 0.5d0\n \n if(abs(q) <= split1)then\n r = const1 - q*q\n normalcdf_inv = q*r8poly_value(8, a, r)/r8poly_value(8, b, r)\n else\n \n if (q < 0d0) then\n r = x\n else\n r = 1d0 - x\n endif\n \n r = sqrt(-log(r))\n \n if(r <= split2)then\n r = r - const2\n normalcdf_Inv = r8poly_value(8, c, r)/r8poly_value(8, d, r)\n else\n r = r - split2\n normalcdf_Inv = r8poly_value(8, e, r)/r8poly_value (8, f, r)\n endif\n \n if(q < 0d0)then\n normalcdf_Inv = -normalcdf_inv\n endif\n endif \n \n ! transfer to mu and sigma\n normalCDF_Inv = mu_c + sigma_c*normalCDF_Inv\n \n \n contains\n \n ! stable evaluation of a polynomial\n function r8poly_value(n, a, x)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! degree of polynomial\n integer, intent(in) :: n\n \n ! polynomial coefficients\n real*8, intent(in) :: a(n)\n \n ! point where to evaluate the polynomial\n real*8, intent(in) :: x\n \n ! the value of the polynomial\n real*8 :: r8poly_value\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: i\n \n \n !##### ROUTINE CODE #######################################################\n \n r8poly_value = 0d0\n do i = n, 1, -1\n r8poly_value = r8poly_value * x + a(i)\n enddo\n \n end function\n \n end function normalCDF_Inv\n \n \n !##############################################################################\n ! FUNCTION log_normalPDF\n !\n ! Calculates log-normal density functions at point x.\n !##############################################################################\n function log_normalPDF(x, mu, sigma)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point where to calculate function\n real*8, intent(in) :: x\n \n ! expectation of distribution\n real*8, optional :: mu\n \n ! variance of distribution\n real*8, optional :: sigma\n \n ! value of normal density at p\n real*8 :: log_normalPDF\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: mu_c, sigma_c\n \n \n !##### ROUTINE CODE #######################################################\n \n ! initialize parameters\n mu_c = exp(0.5d0)\n if(present(mu))mu_c = mu\n sigma_c = exp(1d0)*(exp(1d0)-1d0)\n if(present(sigma))sigma_c = sigma\n \n if(sigma_c <= 0d0)then\n call error('log_normalPDF','sigma has zero or negative value')\n endif\n if(mu_c <= 0d0)then\n call error('log_normalPDF','mu has zero or negative value')\n endif\n \n if(x < 0d0)then\n call error('log_normalPDF','x has negative value')\n endif\n \n ! get expectation and variance\n sigma_c = log(1d0+sigma_c/mu_c**2)\n mu_c = log(mu_c)-0.5d0*sigma_c\n \n ! simulate normal and convert to log_normal\n if(x > 0d0)then\n log_normalPDF = normalPDF(log(x), mu_c, sigma_c)/x\n else\n log_normalPDF = 0d0\n endif\n \n end function log_normalPDF\n \n \n !##############################################################################\n ! FUNCTION log_normalCDF\n !\n ! Calculates log-normal distribution at point x.\n !##############################################################################\n function log_normalCDF(x, mu, sigma)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point where to calculate function\n real*8, intent(in) :: x\n \n ! expectation of distribution\n real*8, optional :: mu\n \n ! variance of distribution\n real*8, optional :: sigma\n \n ! value of normal density at p\n real*8 :: log_normalCDF\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: mu_c, sigma_c\n \n \n !##### ROUTINE CODE #######################################################\n \n ! initialize parameters\n mu_c = exp(0.5d0)\n if(present(mu))mu_c = mu\n sigma_c = exp(1d0)*(exp(1d0)-1d0)\n if(present(sigma))sigma_c = sigma\n \n if(sigma_c <= 0d0)then\n call error('log_normalCDF','sigma has zero or negative value')\n endif\n if(mu_c <= 0d0)then\n call error('log_normalCDF','mu has zero or negative value')\n endif\n \n if(x < 0d0)then\n call error('log_normalCDF','x has negative value')\n endif\n \n ! get expectation and variance\n sigma_c = log(1d0+sigma_c/mu_c**2)\n mu_c = log(mu_c)-0.5d0*sigma_c\n \n ! simulate normal and convert to log_normal\n if(x > 0d0)then\n log_normalCDF = normalCDF(log(x), mu_c, sigma_c)\n else\n log_normalCDF = 0d0\n endif\n \n end function log_normalCDF\n \n \n !##############################################################################\n ! FUNCTION log_normalCDF_Inv\n !\n ! Calculates cumulated log-normal distribution at point x.\n !##############################################################################\n function log_normalCDF_Inv(x, mu, sigma)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point where to calculate function\n real*8, intent(in) :: x\n \n ! expectation of distribution\n real*8, optional :: mu\n \n ! variance of distribution\n real*8, optional :: sigma\n \n ! value of normal density at p\n real*8 :: log_normalCDF_Inv\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: mu_c, sigma_c\n \n \n !##### ROUTINE CODE #######################################################\n \n ! initialize parameters\n mu_c = exp(0.5d0)\n if(present(mu))mu_c = mu\n sigma_c = exp(1d0)*(exp(1d0)-1d0)\n if(present(sigma))sigma_c = sigma\n \n if(sigma_c <= 0d0)then\n call error('log_normalCDF_Inv','sigma has zero or negative value')\n endif\n if(mu_c <= 0d0)then\n call error('log_normalCDF_Inv','mu has zero or negative value')\n endif\n \n ! get expectation and variance\n sigma_c = log(1d0+sigma_c/mu_c**2)\n mu_c = log(mu_c)-0.5d0*sigma_c\n \n ! simulate normal and convert to log_normal\n log_normalCDF_Inv = normalCDF_Inv(x, mu_c, sigma_c)\n log_normalCDF_Inv = exp(log_normalCDF_Inv)\n \n end function log_normalCDF_Inv\n \n \n !##############################################################################\n ! FUNCTION GammaPDF\n !\n ! Calculates Gamma density functions at point x.\n !##############################################################################\n function GammaPDF(x, alpha, beta)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point where to calculate function\n real*8, intent(in) :: x\n \n ! shape parameter of the distribution\n real*8, optional :: alpha\n \n ! scale parameter of the distribution\n real*8, optional :: beta\n \n ! value of Gamma density at p\n real*8 :: gammaPDF\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: alpha_c, beta_c\n \n \n !##### ROUTINE CODE #######################################################\n \n ! initialize parameters\n alpha_c = 1d0\n if(present(alpha))alpha_c = alpha\n beta_c = 1d0\n if(present(beta))beta_c = beta\n \n ! check for validity of parameters\n if(alpha_c <= 0d0)then\n call error('GammaPDF','alpha has a non-positive value')\n endif\n if(beta_c <= 0d0)then\n call error('GammaPDF','beta has a non-positive value')\n endif\n \n if(x < 0d0 .or. alpha_c < 1d0 .and. x <= 0d0)then\n GammaPDF = 0d0\n else\n GammaPDF = beta_c**alpha_c/gamma_function(alpha_c)* &\n x**(alpha_c-1d0)*exp(-beta_c*x)\n endif\n \n end function GammaPDF\n \n \n !##############################################################################\n ! FUNCTION GammaCDF\n !\n ! Calculates cumulated Gamma distribution at point x.\n !##############################################################################\n function GammaCDF(x, alpha, beta)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point where to calculate function\n real*8, intent(in) :: x\n \n ! shape parameter of the distribution\n real*8, optional :: alpha\n \n ! scale parameter of the distribution\n real*8, optional :: beta\n \n ! value of cumulated Gamma distribution at p\n real*8 :: gammaCDF\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: alpha_c, beta_c\n \n \n !##### ROUTINE CODE #######################################################\n \n ! initialize parameters\n alpha_c = 1d0\n if(present(alpha))alpha_c = alpha\n beta_c = 1d0\n if(present(beta))beta_c = beta\n \n ! check for validity of parameters\n if(alpha_c <= 0d0)then\n call error('GammaCDF','alpha has a non-positive value')\n endif\n if(beta_c <= 0d0)then\n call error('GammaCDF','beta has a non-positive value')\n endif\n \n if(x <= 0d0)then\n GammaCDF = 0d0\n else\n GammaCDF = incomplete_gamma(beta_c*x, alpha_c)\n endif\n \n end function gammaCDF\n \n \n \n !##############################################################################\n ! FUNCTION betaPDF\n !\n ! Calculates beta density functions at point x.\n !##############################################################################\n function betaPDF(x, p, q)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point where to calculate function\n real*8, intent(in) :: x\n \n ! parameter of the distribution\n real*8, optional :: p\n \n ! parameter of the distribution\n real*8, optional :: q\n \n ! value of Gamma density at p\n real*8 :: betaPDF\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: p_c, q_c, betanorm\n \n \n !##### ROUTINE CODE #######################################################\n \n ! initialize parameters\n p_c = 1d0\n if(present(p))p_c = p\n q_c = 1d0\n if(present(q))q_c = q\n \n ! check for validity of parameters\n if(p_c <= 0d0)then\n call error('betaPDF','p has a non-positive value')\n endif\n if(q_c <= 0d0)then\n call error('betaPDF','q has a non-positive value')\n endif\n \n if(x < 0d0 .or. x > 1d0)then\n betaPDF = 0d0\n else\n betanorm = exp(my_log_gamma(p_c) + my_log_gamma(q_c) - my_log_gamma(p_c+q_c))\n betaPDF = x**(p_c-1d0)*(1d0-x)**(q_c-1d0)/betanorm\n endif\n \n end function betaPDF\n \n \n !##############################################################################\n ! FUNCTION betaCDF\n !\n ! Calculates cumulated beta distribution at point x.\n !\n ! PARTS OF THIS PROCEDURE WERE COPIED AND ADAPTED FROM:\n ! Fortran Code by John Burkardt available as Algorithm ASA063 from \n ! https://people.sc.fsu.edu/~jburkardt/f_src/asa063/asa063.html\n !\n ! REFERENCE: Majumder, K.L. & Bhattacharjee, G.P. (1973). Algorithm AS 63:\n ! The incomplete Beta Integral, Applied Statistics, 22(3), \n ! 409-411.\n !##############################################################################\n function betaCDF(x, p_in, q_in)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point where to calculate function\n real*8, intent(in) :: x\n \n ! parameter of the distribution\n real*8, optional :: p_in\n \n ! parameter of the distribution\n real*8, optional :: q_in\n \n ! value of Gamma density at p\n real*8 :: betaCDF\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8, parameter :: acu = 0.1d-14\n real*8 :: p, q, ai, beta_log, cx, pp, psq, qq, rx, temp, term, xx\n integer :: ns\n logical :: indx\n \n \n !##### ROUTINE CODE #######################################################\n \n ! initialize parameters\n p = 1d0\n if(present(p_in))p = p_in\n q = 1d0\n if(present(q_in))q = q_in\n \n ! check for validity of parameters\n if(p <= 0d0)then\n call error('betaPDF','p has a non-positive value')\n endif\n if(q <= 0d0)then\n call error('betaPDF','q has a non-positive value')\n endif\n \n ! check outside of range\n if(x <= 0d0)then\n betaCDF = 0d0\n return\n endif\n if(x >= 1d0)then\n betaCDF = 1d0\n return\n endif\n \n ! calculate logarithm of the complete beta function\n beta_log = my_log_gamma(p) + my_log_gamma(q) - my_log_gamma(p + q)\n\n psq = p + q\n cx = 1d0 - x\n\n if(p < psq*x)then\n xx = cx\n cx = x\n pp = q\n qq = p\n indx = .true.\n else\n xx = x\n pp = p\n qq = q\n indx = .false.\n endif\n\n term = 1d0\n ai = 1d0\n betaCDF = 1d0\n ns = int(qq + cx*psq)\n\n ! use Soper's reduction formula.\n rx = xx / cx\n temp = qq - ai\n if (ns == 0) then\n rx = xx\n endif\n\n do\n\n term = term*temp*rx / (pp + ai)\n betaCDF = betaCDF + term\n temp = abs (term)\n \n if(temp <= acu .and. temp <= acu*betaCDF) then\n \n betaCDF = betaCDF*exp (pp*log(xx) &\n + (qq-1d0)*log(cx)-beta_log)/pp\n \n ! change if other tail\n if(indx)then\n betaCDF = 1d0 - betaCDF\n endif\n exit \n endif\n \n ai = ai + 1d0\n ns = ns - 1\n \n if(0 <= ns)then\n temp = qq - ai\n if(ns == 0)then\n rx = xx\n endif\n else\n temp = psq\n psq = psq + 1d0\n endif\n enddo\n \n end function betaCDF\n \n \n !##############################################################################\n ! FUNCTION incomplete_gamma\n !\n ! Calculates the incomplete gamma integral.\n !\n ! PARTS OF THIS PROCEDURE WERE COPIED AND ADAPTED FROM:\n ! Fortran Code by John Burkardt available as Algorithm ASA239 from \n ! https://people.sc.fsu.edu/~jburkardt/f_src/asa239/asa239.html\n !\n ! REFERENCE: Shea, B. (1988). Algorithm AS 239: Chi-squared and Incomplete \n ! Gamma Integral, Applied Statistics, 37(3), 466-473.\n !##############################################################################\n function incomplete_gamma(x, p)\n\n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point where to calculate function\n real*8, intent(in) :: x\n \n ! parameter of the gamma function\n real*8, intent(in) :: p\n \n ! value of normal density at p\n real*8 :: incomplete_gamma\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: a, an, arg, b, c, pn1, pn2, pn3, pn4, pn5, pn6, rn\n real*8, parameter :: elimit = - 88d0\n real*8, parameter :: oflo = 1d37\n real*8, parameter :: plimit = 1000d0\n real*8, parameter :: tol = 1d-14\n real*8, parameter :: xbig = 1d8\n \n \n !##### ROUTINE CODE #######################################################\n\n incomplete_gamma = 0d0\n \n ! check validity of inputs solution\n if(x < 0d0)then\n call error('incomeplete_gamma','x is smaller than zero')\n endif\n \n if(p <= 0d0)then\n call error('incomeplete_gamma','p is not positive')\n endif\n \n ! set incomeplete_gamma = 0 if x is zero\n if(x <= 0d0)then\n incomplete_gamma = 0d0\n return\n endif\n\n ! normal approximation for large values of p\n if(p > plimit)then\n pn1 = 3d0*sqrt(p)*((x/p)**(1d0/3d0) + 1d0/(9d0*p) - 1d0)\n incomplete_gamma = normalCDF(pn1)\n return\n endif\n \n ! set incomeplete_gamma = 1 if x is large\n if(x > xbig)then\n incomplete_gamma = 1d0\n endif\n \n ! Pearson series expansion\n if(x <= 1d0 .or. x < p)then\n arg = p*log(x) - x - my_log_gamma(p+1d0)\n c = 1d0\n incomplete_gamma = 1.0D+00\n a = p\n \n do\n a = a + 1d0\n c = c*x/a\n incomplete_gamma = incomplete_gamma + c\n \n if(c <= tol) then\n exit\n endif\n \n enddo\n \n arg = arg + log (incomplete_gamma)\n \n if ( elimit <= arg ) then\n incomplete_gamma = exp ( arg )\n else\n incomplete_gamma = 0d0\n endif\n \n ! Use a continued fraction expansion.\n else\n \n arg = p*log (x) - x - my_log_gamma(p)\n a = 1d0 - p\n b = a + x + 1d0\n c = 0d0\n pn1 = 1d0\n pn2 = x\n pn3 = x + 1d0\n pn4 = x*b\n incomplete_gamma = pn3/pn4\n \n do\n \n a = a + 1d0\n b = b + 2d0\n c = c + 1d0\n an = a*c\n pn5 = b*pn3 - an*pn1\n pn6 = b*pn4 - an*pn2\n \n if ( abs(pn6) > 0d0 ) then\n \n rn = pn5 / pn6\n \n if ( abs(incomplete_gamma - rn) <= min(tol, tol*rn)) then\n exit\n endif\n incomplete_gamma = rn\n endif\n \n pn1 = pn3\n pn2 = pn4\n pn3 = pn5\n pn4 = pn6\n \n ! Re-scale terms in continued fraction if terms are large.\n if (oflo <= abs(pn5) ) then\n pn1 = pn1/oflo\n pn2 = pn2/oflo\n pn3 = pn3/oflo\n pn4 = pn4/oflo\n endif\n \n enddo\n \n arg = arg + log (incomplete_gamma)\n \n if (arg >= elimit) then\n incomplete_gamma = 1d0 - exp (arg)\n else\n incomplete_gamma = 1d0\n endif\n endif\n \n end function incomplete_gamma\n \n \n !##############################################################################\n ! FUNCTION gamma_function\n !\n ! Calculates the gamma fuction.\n !##############################################################################\n function gamma_function(x)\n\n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point where to calculate function\n real*8, intent(in) :: x\n \n ! value of log of the gamma function\n real*8 :: gamma_function\n \n \n !##### ROUTINE CODE #######################################################\n\n \n ! check validity of inputs solution\n if(x < 0d0)then\n call error('gamma_function','x is smaller than zero')\n endif\n \n gamma_function = my_log_gamma(x)\n gamma_function = exp(gamma_function)\n \n end function gamma_function\n \n \n !##############################################################################\n ! FUNCTION my_log_gamma\n !\n ! Calculates log of the gamma fuction.\n !\n ! PARTS OF THIS PROCEDURE WERE COPIED AND ADAPTED FROM:\n ! Fortran Code by John Burkardt available as Algorithm AS245 from \n ! https://people.sc.fsu.edu/~jburkardt/f_src/asa245/asa245.html\n !\n ! REFERENCE: Macleod, A.J. (1989). Algorithm AS 245: A Robust and Reliable \n ! Algorithm for the Logarithm of the Gamma Function. Applied \n ! Statistics, 38(2), 397-402.\n !##############################################################################\n function my_log_gamma(x_in)\n\n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point where to calculate function\n real*8, intent(in) :: x_in\n \n ! value of log of the gamma function\n real*8 :: my_log_gamma\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8, parameter :: alr2pi = 9.18938533204673d-1\n real*8, parameter :: xlge = 5.10d6 \n real*8, parameter :: r1(9) = (/ -2.66685511495d0, &\n -2.44387534237d1, &\n -2.19698958928d1, & \n 1.11667541262d1, &\n 3.13060547623d0, &\n 6.07771387771d-1, &\n 1.19400905721d1, &\n 3.14690115749d1, &\n 1.52346874070d1 /)\n real*8, parameter :: r2(9) = (/ -7.83359299449d1, &\n -1.42046296688d2, &\n 1.37519416416d2, & \n 7.86994924154d1, &\n 4.16438922228d0, &\n 4.70668766060d1, &\n 3.13399215894d2, & \n 2.63505074721d2, &\n 4.33400022514d1 /)\n real*8, parameter :: r3(9) = (/ -2.12159572323d5, & \n 2.30661510616d5, &\n 2.74647644705d4, &\n -4.02621119975d4, &\n -2.29660729780d3, &\n -1.16328495004d5, &\n -1.46025937511d5, &\n -2.42357409629d4, &\n -5.70691009324d2 /)\n real*8, parameter :: r4(5) = (/ 2.79195317918525d-1, &\n 4.917317610505968d-1, &\n 6.92910599291889d-2, &\n 3.350343815022304d0, &\n 6.012459259764103d0 /)\n real*8 :: x, x1, x2, y\n \n \n !##### ROUTINE CODE #######################################################\n\n\n my_log_gamma = 0d0\n x = x_in\n \n ! check validity of inputs solution\n if(x < 0d0)then\n call error('my_log_gamma','x is smaller than zero')\n endif\n \n ! get solution for 0 < X < 0.5 and 0.5 <= x < 1.5\n if(x < 1.5d0)then\n if(x < 0.5d0)then\n my_log_gamma = -log(x)\n y = x + 1d0\n \n ! return if x is smaller than machine epsilon\n if(y <= 1d0)return\n else\n my_log_gamma = 0d0\n y = x\n x = (x-0.5d0) - 0.5d0\n endif\n my_log_gamma = my_log_gamma + x * ((((r1(5)*y + r1(4))*y + r1(3))*y &\n + r1(2))*y + r1(1)) / ((((y + r1(9))*y + r1(8))*y + r1(7))*y + r1(6))\n \n\n ! get solution for 1.5 <= x < 4.0\n elseif(x < 4.0d0)then\n y = (x - 1d0) - 1d0\n my_log_gamma = y * ((((r2(5)*x + r2(4))*x + r2(3))*x + r2(2))*x &\n + r2(1)) / ((((x + r2(9))*x + r2(8))*x + r2(7))*x + R2(6))\n\n ! get solution for 4.0 <= x < 12\n elseif(x < 12d0)then\n my_log_gamma = ((((r3(5)*x + r3(4))*x + r3(3))*x + r3(2))*x + r3(1)) / &\n ((((x + r3(9))*x + r3(8))*x + r3(7))*x + r3(6))\n else\n y = log(x)\n my_log_gamma = x * (y -1d0) - 0.5d0*y + alr2pi\n if(x <= XLGE)then\n x1 = 1d0/x\n x2 = x1 * x1\n my_log_gamma = my_log_gamma + x1 * ((r4(3)*x2 + r4(2))*x2 + r4(1)) / &\n ((x2 + r4(5))*x2 + r4(4))\n endif\n endif\n \n end function my_log_gamma\n \n \n !##############################################################################\n ! FUNCTION bernoulliPDF\n !\n ! Calculates probabilities of the bernoulli distribution.\n !##############################################################################\n function bernoulliPDF(k, p)\n\n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! zero or 1 draw\n integer, intent(in) :: k\n \n ! the probability of the positive draw\n real*8, intent(in) :: p\n\n ! the probability of this to happen\n real*8 :: bernoulliPDF\n \n \n !##### ROUTINE CODE #######################################################\n \n ! check for validity\n if(p < 0d0 .or. p > 1d0)then\n call error('bernoulliPDF', 'Probability p is out of [0,1]')\n endif\n \n ! outside of range\n if(k < 0)then\n bernoulliPDF = 0d0\n return\n endif\n \n if(k > 1)then\n bernoulliPDF = 1d0\n return\n endif\n \n if(k == 0)then\n bernoulliPDF = 1d0 - p\n else\n bernoulliPDF = p\n endif\n\n end function\n \n \n !##############################################################################\n ! FUNCTION bernoulliCDF\n !\n ! Calculates cumulated probabilities of the bernoulli distribution.\n !##############################################################################\n function bernoulliCDF(k, p)\n\n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! zero or 1 draw\n integer, intent(in) :: k\n \n ! the probability of the positive draw\n real*8, intent(in) :: p\n\n ! the cumulated probability of this to happen\n real*8 :: bernoulliCDF\n \n \n !##### ROUTINE CODE #######################################################\n \n ! check for validity\n if(p < 0d0 .or. p > 1d0)then\n call error('bernoulliCDF', 'Probability p is out of [0,1]')\n endif\n \n ! outside of range\n if(k < 0)then\n bernoulliCDF = 0d0\n return\n endif\n \n if(k >= 1)then\n bernoulliCDF = 1d0\n return\n endif\n \n bernoulliCDF = 1d0 - p\n\n end function\n \n \n !##############################################################################\n ! FUNCTION binomialPDF\n !\n ! Calculates probabilities of the binomial distribution.\n !##############################################################################\n function binomialPDF(k, n, p)\n\n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! the number of positive draws\n integer, intent(in) :: k\n \n ! the total number of draws\n integer, intent(in) :: n\n \n ! the probability of a positive draw\n real*8, intent(in) :: p\n\n ! the probability of this to happen\n real*8 :: binomialPDF\n \n \n !##### ROUTINE CODE #######################################################\n \n\n ! check for validity\n if(p < 0d0 .or. p > 1d0)then\n call error('binomialPDF', 'Probability p is out of [0,1]')\n endif\n \n ! outside of range\n if(k < 0 .or. k > n)then\n binomialPDF = 0d0\n return\n endif\n\n binomialPDF = binomial_coefficient(n, k)*p**k*(1d0-p)**(n-k) \n\n end function\n \n \n !##############################################################################\n ! FUNCTION binomialCDF\n !\n ! Calculates cumulated probabilities of the binomial distribution.\n !##############################################################################\n function binomialCDF(k, n, p)\n\n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! the number of positive draws\n integer, intent(in) :: k\n \n ! the total number of draws\n integer, intent(in) :: n\n \n ! the probability of a positive draw\n real*8, intent(in) :: p\n\n ! the cumulated probability of this to happen\n real*8 :: binomialCDF\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: ii\n \n \n !##### ROUTINE CODE #######################################################\n \n ! check for validity\n if(p < 0d0 .or. p > 1d0)then\n call error('binomialCDF', 'Probability p is out of [0,1]')\n endif\n \n ! outside of range\n if(k < 0)then\n binomialCDF = 0d0\n return\n endif\n \n if(k > n)then\n binomialCDF = 1d0\n return\n endif\n \n binomialCDF = 0d0\n do ii = 0, k\n binomialCDF = binomialCDF + binomial_coefficient(n, ii)*p**ii*(1d0-p)**(n-ii)\n enddo\n\n end function\n \n \n !##############################################################################\n ! FUNCTION binomial_coefficient\n !\n ! Calculate binomial coefficients efficiently\n !##############################################################################\n function binomial_coefficient(n, k)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! out of number\n integer, intent(in) :: n\n \n ! number\n integer, intent(in) :: k\n \n ! the probability of this to happen\n real*8 :: binomial_coefficient\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: n0, k0, ii\n \n \n !##### ROUTINE CODE #######################################################\n \n \n if(k == 0 .or. k == n)then\n binomial_coefficient = 1d0\n endif\n \n ! copy values\n n0 = n\n k0 = k\n \n ! use symmetry of binomial coefficients\n if(k0 > n0 - k0)then\n k0 = n0 - k0\n endif\n \n ! use factorial formula for stability\n binomial_coefficient = 1d0\n do ii = 1, k\n binomial_coefficient = binomial_coefficient*dble(n+1-ii)\n binomial_coefficient = binomial_coefficient/dble(ii)\n enddo\n \n end function\n \n \n \n !##############################################################################\n ! SUBROUTINE init_random_seed\n !\n ! To ensure that each random draw is a new sequence\n !\n ! PARTS OF THIS PROCEDURE WERE COPIED AND ADAPTED FROM:\n ! The GNU GCC Fortran compiler library documentation\n ! https://gcc.gnu.org/onlinedocs/gcc-4.8.5/gfortran/RANDOM_005fSEED.html\n !##############################################################################\n subroutine init_random_seed(fixed)\n \n implicit none\n integer, allocatable :: seed(:)\n integer :: i, n, dt(8)\n integer, parameter :: int64 = selected_int_kind(16)\n integer(kind=int64) :: t\n logical, optional :: fixed\n \n call random_seed(size = n)\n allocate(seed(n))\n \n call system_clock(t)\n if (t == 0) then\n call date_and_time(values=dt)\n t = (dt(1) - 1970) * 365_int64 * 24 * 60 * 60 * 1000 &\n + dt(2) * 31_int64 * 24 * 60 * 60 * 1000 &\n + dt(3) * 24_int64 * 60 * 60 * 1000 &\n + dt(5) * 60 * 60 * 1000 &\n + dt(6) * 60 * 1000 + dt(7) * 1000 &\n + dt(8)\n endif\n \n if(present(fixed))then\n if(fixed)t = 0\n endif\n do i = 1, n\n seed(i) = lcg(t)\n enddo\n call random_seed(put=seed)\n \n contains\n \n ! This simple PRNG might not be good enough for real work, but is\n ! sufficient for seeding a better PRNG.\n function lcg(s)\n \n implicit none\n integer :: lcg\n integer(int64) :: s\n \n if (s == 0) then\n s = 104729\n else\n s = mod(s, 4294967296_int64)\n endif\n s = mod(s * 279470273_int64, 4294967291_int64)\n lcg = int(mod(s, int(huge(0), int64)), kind(0))\n \n end function lcg\n \n end subroutine init_random_seed\n \n \n !##############################################################################\n ! SUBROUTINE simulate_uniform_1\n !\n ! Simulates one draw from a uniform distribution.\n !##############################################################################\n subroutine simulate_uniform_1(x, a, b, fixed)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point into which the draw should be saved\n real*8, intent(out) :: x\n \n ! left end of the distribution\n real*8, optional :: a\n \n ! right end of the distribution\n real*8, optional :: b\n \n ! should the random seed be initialized at a fixed values\n logical, optional :: fixed\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: a_c, b_c\n \n \n !##### ROUTINE CODE #######################################################\n \n ! initialize parameters\n a_c = 0d0\n if(present(a))a_c = a\n b_c = 1d0\n if(present(b))b_c = b\n \n ! initialize the random seed\n if(tbox_seed)then\n if(present(fixed))then\n call init_random_seed(fixed)\n else\n call init_random_seed()\n endif\n tbox_seed = .false.\n endif\n \n ! draw the random number\n call random_number(x)\n \n x = a_c + (b_c-a_c)*x\n \n end subroutine simulate_uniform_1\n \n \n !##############################################################################\n ! SUBROUTINE simulate_uniform_n\n !\n ! Simulates a series draw from a uniform distribution.\n !##############################################################################\n subroutine simulate_uniform_n(x, a, b, fixed)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point into which the draw should be saved\n real*8, intent(out) :: x(:)\n \n ! left end of the distribution\n real*8, optional :: a\n \n ! right end of the distribution\n real*8, optional :: b\n \n ! should the random seed be initialized at a fixed values\n logical, optional :: fixed\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: a_c, b_c\n \n \n !##### ROUTINE CODE #######################################################\n \n ! initialize parameters\n a_c = 0d0\n if(present(a))a_c = a\n b_c = 1d0\n if(present(b))b_c = b\n \n ! initialize the random seed\n if(tbox_seed)then\n if(present(fixed))then\n call init_random_seed(fixed)\n else\n call init_random_seed()\n endif\n tbox_seed = .false.\n endif\n \n call random_number(x)\n \n x = a_c + (b_c-a_c)*x\n \n end subroutine simulate_uniform_n\n \n \n !##############################################################################\n ! Subroutine simulate_normal_1\n !\n ! Simulates one draw from a normal distribution using\n ! Box-Muller tranformation.\n !\n ! REFERENCE: Box, G.E.P., Muller, M.E. (1958). A Note on the Generation of \n ! Random Normal Deviates, The Annals of Mathematical Statistics, \n ! 29(2), 610\u2013611.\n !##############################################################################\n subroutine simulate_normal_1(x, mu, sigma, fixed)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point into which the draw should be saved\n real*8, intent(out) :: x\n \n ! expectation of distribution\n real*8, optional :: mu\n \n ! variance of distribution\n real*8, optional :: sigma\n \n ! should the random seed be initialized at a fixed values\n logical, optional :: fixed\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: uni1, uni2, mu_c, sigma_c\n real*8 :: pi = 3.141592653589793d0\n \n \n !##### ROUTINE CODE #######################################################\n \n ! initialize parameters\n mu_c = 0d0\n if(present(mu))mu_c = mu\n sigma_c = 1d0\n if(present(sigma))sigma_c = sigma\n \n if(sigma_c <= 0d0)then\n call error('simulate_normal','sigma has zero or negative value')\n endif\n \n ! simulate a uniform variable draw\n if(present(fixed))then\n call simulate_uniform_1(uni1, fixed=fixed)\n call simulate_uniform_1(uni2, fixed=fixed)\n else\n call simulate_uniform_1(uni1)\n call simulate_uniform_1(uni2)\n endif\n \n ! transform by Box-Muller transformation\n x = sqrt(-2d0*log(uni1))*cos(2d0*pi*uni2)\n \n ! transform to mean and variance\n x = mu_c + sqrt(sigma_c)*x\n \n end subroutine simulate_normal_1\n \n \n !##############################################################################\n ! SUBROUTINE simulate_normal_n\n !\n ! Simulates draws from a normal distribution using\n ! Box-Muller tranformation.\n !\n ! REFERENCE: Box, G.E.P., Muller, M.E. (1958). A Note on the Generation of \n ! Random Normal Deviates, The Annals of Mathematical Statistics, \n ! 29(2), 610\u2013611.\n !##############################################################################\n subroutine simulate_normal_n(x, mu, sigma, fixed)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point into which the draw should be saved\n real*8, intent(out) :: x(:)\n \n ! expectation of distribution\n real*8, optional :: mu\n \n ! variance of distribution\n real*8, optional :: sigma\n \n ! should the random seed be initialized at a fixed values\n logical, optional :: fixed\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: uni1(size(x, 1)/2), uni2(size(x, 1)/2), mu_c, sigma_c\n integer :: n, in, n2\n real*8 :: pi = 3.141592653589793d0\n \n \n !##### ROUTINE CODE #######################################################\n \n ! initialize parameters\n mu_c = 0d0\n if(present(mu))mu_c = mu\n sigma_c = 1d0\n if(present(sigma))sigma_c = sigma\n \n if(sigma_c <= 0d0)then\n call error('simulate_normal','sigma has zero or negative value')\n endif\n \n ! get size of x\n n = size(x, 1)\n n2 = n/2\n \n ! simulate a uniform variable draw\n if(present(fixed))then\n call simulate_uniform_n(uni1, fixed=fixed)\n call simulate_uniform_n(uni2, fixed=fixed)\n else\n call simulate_uniform_n(uni1)\n call simulate_uniform_n(uni2)\n endif\n \n ! transform by Box-Muller transformation\n do in = 1, n2\n x(2*(in-1)+1) = sqrt(-2d0*log(uni1(in)))*cos(2d0*pi*uni2(in))\n x(2*(in-1)+2) = sqrt(-2d0*log(uni1(in)))*sin(2d0*pi*uni2(in))\n enddo\n \n if(2*n2 /= n)then\n call simulate_normal_1(x(n), 0d0, 1d0)\n endif\n \n ! transform to mean and variance\n x = mu_c + sqrt(sigma_c)*x\n \n end subroutine simulate_normal_n\n \n \n !##############################################################################\n ! SUBROUTINE simulate_log_normal_1\n !\n ! Simulates one draw from a log normal distribution.\n !##############################################################################\n subroutine simulate_log_normal_1(x, mu, sigma, fixed)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point into which the draw should be saved\n real*8, intent(out) :: x\n \n ! expectation of distribution\n real*8, optional :: mu\n \n ! variance of distribution\n real*8, optional :: sigma\n \n ! should the random seed be initialized at a fixed values\n logical, optional :: fixed\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: mu_c, sigma_c\n \n \n !##### ROUTINE CODE #######################################################\n \n ! initialize parameters\n mu_c = exp(0.5d0)\n if(present(mu))mu_c = mu\n sigma_c = exp(1d0)*(exp(1d0)-1d0)\n if(present(sigma))sigma_c = sigma\n \n if(sigma_c <= 0d0)then\n call error('simulate_log_normal','sigma has zero or negative value')\n endif\n if(mu_c <= 0d0)then\n call error('simulate_log_normal','mu has zero or negative value')\n endif\n \n ! get expectation and variance\n sigma_c = log(1d0+sigma_c/mu_c**2)\n mu_c = log(mu_c)-0.5d0*sigma_c\n \n ! simulate normal and convert to log_normal\n if(present(fixed))then\n call simulate_normal_1(x, mu_c, sigma_c, fixed)\n else\n call simulate_normal_1(x, mu_c, sigma_c)\n endif\n \n ! transform to log normal\n x = exp(x)\n \n end subroutine simulate_log_normal_1\n \n \n !##############################################################################\n ! SUBROUTINE simulate_log_normal_n\n !\n ! Simulates draws from a log normal distribution.\n !##############################################################################\n subroutine simulate_log_normal_n(x, mu, sigma, fixed)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point into which the draw should be saved\n real*8, intent(out) :: x(:)\n \n ! expectation of distribution\n real*8, optional :: mu\n \n ! variance of distribution\n real*8, optional :: sigma\n \n ! should the random seed be initialized at a fixed values\n logical, optional :: fixed\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: mu_c, sigma_c\n \n \n !##### ROUTINE CODE #######################################################\n \n ! initialize parameters\n mu_c = exp(0.5d0)\n if(present(mu))mu_c = mu\n sigma_c = exp(1d0)*(exp(1d0)-1d0)\n if(present(sigma))sigma_c = sigma\n \n if(sigma_c <= 0d0)then\n call error('simulate_log_normal','sigma has zero or negative value')\n endif\n if(mu_c <= 0d0)then\n call error('simulate_log_normal','mu has zero or negative value')\n endif\n \n ! get expectation and variance\n sigma_c = log(1d0+sigma_c/mu_c**2)\n mu_c = log(mu_c)-0.5d0*sigma_c \n \n ! simulate normal and convert to log_normal\n if(present(fixed))then\n call simulate_normal_n(x, mu_c, sigma_c, fixed)\n else\n call simulate_normal_n(x, mu_c, sigma_c)\n endif\n \n ! transform to log normal\n x = exp(x)\n \n end subroutine simulate_log_normal_n\n \n \n !##############################################################################\n ! SUBROUTINE simulate_Gamma_1\n !\n ! Simulates draws from a gamma distribution using the\n ! Marsaglia/Tsang method.\n !\n ! REFERENCE: Marsaglia, G., Tsang, W.W. (2000). A simple method for generating \n ! gamma variables, ACM Transactions on Mathematical Software, 26(2),\n ! 363-372.\n !##############################################################################\n subroutine simulate_Gamma_1(x, alpha, beta, fixed)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point into which the draw should be saved\n real*8, intent(out) :: x\n \n ! shape parameter\n real*8, optional :: alpha\n \n ! rate parameter\n real*8, optional :: beta\n \n ! should the random seed be initialized at a fixed values\n logical, optional :: fixed\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: alpha_c, beta_c, d, c, uni\n \n \n !##### ROUTINE CODE #######################################################\n \n ! initialize parameters\n alpha_c = 1d0\n if(present(alpha))alpha_c = alpha\n beta_c = 1d0\n if(present(beta))beta_c = beta\n \n ! check for validity of parameters\n if(alpha_c <= 0d0)then\n call error('simulate_Gamma','alpha has a non-positive value')\n endif\n if(beta_c <= 0d0)then\n call error('simulate_Gamma','beta has a non-positive value')\n endif\n \n ! check whether alpha >= 1\n if(alpha_c >= 1d0)then\n \n ! calculate c and d\n d = alpha_c - 1d0/3d0\n c = 1d0/sqrt(9d0*d)\n \n ! simulate the gammas step by step\n if(present(fixed))then\n x = simulate_Gamma_plain(c, d, fixed)\n else\n x = simulate_Gamma_plain(c, d)\n endif\n else\n \n ! generate alpha+1 variables\n d = alpha_c + 2d0/3d0\n c = 1d0/sqrt(9d0*d)\n \n ! simulate the gammas step by step\n if(present(fixed))then\n x = simulate_Gamma_plain(c, d, fixed)\n else\n x = simulate_Gamma_plain(c, d)\n endif\n \n ! add uniform transformation\n if(present(fixed))then\n call simulate_uniform_1(uni, fixed=fixed)\n else\n call simulate_uniform_1(uni)\n endif\n x = x*uni**(1d0/alpha_c)\n \n endif\n \n ! apply scaling parameter\n x = x/beta_c\n \n \n end subroutine simulate_Gamma_1\n \n \n !##############################################################################\n ! SUBROUTINE simulate_Gamma_n\n !\n ! Simulates draws from a gamma distribution using the\n ! Marsaglia/Tsang method.\n !\n ! REFERENCE: Marsaglia, G., Tsang, W.W. (2000). A simple method for generating \n ! gamma variables, ACM Transactions on Mathematical Software, 26(2),\n ! 363-372.\n !##############################################################################\n subroutine simulate_Gamma_n(x, alpha, beta, fixed)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point into which the draw should be saved\n real*8, intent(out) :: x(:)\n \n ! shape parameter\n real*8, optional :: alpha\n \n ! rate parameter\n real*8, optional :: beta\n \n ! should the random seed be initialized at a fixed values\n logical, optional :: fixed\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: alpha_c, beta_c, d, c, uni(size(x, 1))\n integer :: n, in\n \n \n !##### ROUTINE CODE #######################################################\n \n ! initialize parameters\n alpha_c = 1d0\n if(present(alpha))alpha_c = alpha\n beta_c = 1d0\n if(present(beta))beta_c = beta\n \n ! check for validity of beta\n if(beta_c <= 0d0)then\n call error('simulate_Gamma','beta has a non-positive value')\n endif\n \n ! get size of x\n n = size(x, 1)\n \n ! check whether alpha >= 1\n if(alpha_c >= 1d0)then\n \n ! calculate c and d\n d = alpha_c - 1d0/3d0\n c = 1d0/sqrt(9d0*d)\n \n ! simulate the gammas step by step\n do in = 1, n\n if(present(fixed))then\n x(in) = simulate_Gamma_plain(c, d, fixed)\n else\n x(in) = simulate_Gamma_plain(c, d)\n endif\n enddo\n else\n \n ! generate alpha+1 variables\n d = alpha_c + 2d0/3d0\n c = 1d0/sqrt(9d0*d)\n \n ! simulate the gammas step by step\n do in = 1, n\n if(present(fixed))then\n x(in) = simulate_Gamma_plain(c, d, fixed)\n else\n x(in) = simulate_Gamma_plain(c, d)\n endif\n enddo\n \n ! add uniform transformation\n if(present(fixed))then\n call simulate_uniform_n(uni, fixed=fixed)\n else\n call simulate_uniform_n(uni)\n endif\n x = x*uni**(1d0/alpha_c)\n \n endif\n \n ! apply scaling parameter\n x = x/beta_c\n \n \n end subroutine simulate_Gamma_n\n \n \n !##############################################################################\n ! FUNCTION simulate_Gamma_plain\n !\n ! Simulates one draw from gamma distribution without any testing.\n !\n ! REFERENCE: Marsaglia, G., Tsang, W.W., A simple method for generating gamma \n ! variables, ACM Transactions on Mathematical Software, Vol. 26,\n ! No. 2, 2000, 363-372.\n !##############################################################################\n function simulate_Gamma_plain(c, d, fixed) result(res)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! c parameter\n real*8 :: c\n \n ! d parameter\n real*8 :: d\n \n ! should the random seed be initialized at a fixed values\n logical, optional :: fixed\n \n ! a gamma realization\n real*8 :: res\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: v, x, u\n \n \n !##### ROUTINE CODE #######################################################\n \n do\n ! generate v\n if(present(fixed))then\n call simulate_normal_1(x, fixed=fixed)\n else\n call simulate_normal_1(x)\n endif\n v = (1d0+c*x)\n v = v*v*v\n \n ! test v\n if(v <= 0d0)cycle\n \n ! generate u\n if(present(fixed))then\n call simulate_uniform_1(u, fixed=fixed)\n else\n call simulate_uniform_1(u)\n endif\n \n ! check squeeze\n if(u < 1d0 - 0.0331d0*(x*x)*(x*x))then\n res = d*v\n return\n endif\n \n ! check real condition\n if(log(u) < 0.5d0*x*x + d*(1d0 - v + log(v)))then\n res = d*v\n return\n endif\n enddo\n \n end function simulate_Gamma_plain\n \n \n !##############################################################################\n ! SUBROUTINE simulate_beta_1\n !\n ! Simulates one draw from a beta distribution.\n !##############################################################################\n subroutine simulate_beta_1(x, p, q, fixed)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point into which the draw should be saved\n real*8, intent(out) :: x\n \n ! shape parameter\n real*8, optional :: p\n \n ! rate parameter\n real*8, optional :: q\n \n ! should the random seed be initialized at a fixed values\n logical, optional :: fixed\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: p_c, q_c, gamma1, gamma2, bern\n \n \n !##### ROUTINE CODE #######################################################\n \n ! initialize parameters\n p_c = 1d0\n if(present(p))p_c = p\n q_c = 1d0\n if(present(q))q_c = q\n \n ! check for validity of parameters\n if(p_c <= 0d0)then\n call error('simulate_beta','p has a non-positive value')\n endif\n if(q_c <= 0d0)then\n call error('simulate_beta','q has a non-positive value')\n endif\n \n ! get bernoulli parametzer for small p and q\n bern = p_c/(p_c+q_c)\n \n if(present(fixed))then\n call simulate_Gamma_1(gamma1, p_c, fixed=fixed)\n call simulate_Gamma_1(gamma2, q_c, fixed=fixed)\n else\n call simulate_Gamma_1(gamma1, p_c)\n call simulate_Gamma_1(gamma2, q_c)\n endif\n \n ! check whether gammas both greaters 0\n if(gamma1 > 0d0 .or. gamma2 > 0d0)then\n x = gamma1/(gamma1+gamma2)\n else\n if(present(fixed))then\n call simulate_bernoulli_1(x, bern, fixed=fixed)\n else\n call simulate_bernoulli_1(x, bern)\n endif\n endif\n \n end subroutine simulate_beta_1\n \n \n !##############################################################################\n ! SUBROUTINE simulate_beta_n\n !\n ! Simulates draws from a beta distribution.\n !##############################################################################\n subroutine simulate_beta_n(x, p, q, fixed)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point into which the draw should be saved\n real*8, intent(out) :: x(:)\n \n ! shape parameter\n real*8, optional :: p\n \n ! rate parameter\n real*8, optional :: q\n \n ! should the random seed be initialized at a fixed values\n logical, optional :: fixed\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: p_c, q_c, gamma1(size(x,1)), gamma2(size(x,1)), bern\n integer :: n, in\n \n \n !##### ROUTINE CODE #######################################################\n \n ! initialize parameters\n p_c = 1d0\n if(present(p))p_c = p\n q_c = 1d0\n if(present(q))q_c = q\n \n ! check for validity of parameters\n if(p_c <= 0d0)then\n call error('simulate_beta','p has a non-positive value')\n endif\n if(q_c <= 0d0)then\n call error('simulate_beta','q has a non-positive value')\n endif\n \n ! get size of x\n n = size(x, 1)\n \n ! get bernoulli parametzer for small p and q\n bern = p_c/(p_c+q_c)\n \n if(present(fixed))then\n call simulate_Gamma_n(gamma1, p_c, fixed=fixed)\n call simulate_Gamma_n(gamma2, q_c, fixed=fixed)\n else\n call simulate_Gamma_n(gamma1, p_c)\n call simulate_Gamma_n(gamma2, q_c)\n endif\n \n do in = 1, n\n \n ! check whether gammas both greaters 0\n if(gamma1(in) > 0d0 .or. gamma2(in) > 0d0)then\n x(in) = gamma1(in)/(gamma1(in)+gamma2(in))\n else\n if(present(fixed))then\n call simulate_bernoulli_1(x(in), bern, fixed=fixed)\n else\n call simulate_bernoulli_1(x(in), bern)\n endif\n endif\n enddo\n \n end subroutine simulate_beta_n\n \n \n !##############################################################################\n ! SUBROUTINE simulate_bernoulli_1\n !\n ! Simulates one draw from bernoulli distribution\n !##############################################################################\n subroutine simulate_bernoulli_1(x, p, fixed)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point into which the draw should be saved\n real*8, intent(out) :: x\n\n ! probability to draw 1\n real*8, intent(in) :: p\n \n ! should the random seed be initialized at a fixed values\n logical, optional :: fixed\n \n \n !##### ROUTINE CODE #######################################################\n \n if(p < 0d0)then\n call error('simulate_bernoulli', 'p has a negative value')\n endif\n \n if(present(fixed))then\n call simulate_uniform_1(x, fixed=fixed)\n else\n call simulate_uniform_1(x)\n endif\n \n if(x <= p)then\n x = 1d0\n else\n x = 0d0\n endif\n \n end subroutine simulate_bernoulli_1\n \n \n !##############################################################################\n ! SUBROUTINE simulate_bernoulli_n\n !\n ! Simulates draws from bernoulli distribution\n !##############################################################################\n subroutine simulate_bernoulli_n(x, p, fixed)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point into which the draw should be saved\n real*8, intent(out) :: x(:)\n\n ! probability to draw 1\n real*8, intent(in) :: p\n \n ! should the random seed be initialized at a fixed values\n logical, optional :: fixed\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: ii\n \n \n !##### ROUTINE CODE #######################################################\n \n if(p < 0d0)then\n call error('simulate_bernoulli', 'p has a negative value')\n endif\n \n if(present(fixed))then\n call simulate_uniform_n(x, fixed=fixed)\n else\n call simulate_uniform_n(x)\n endif\n \n do ii = 1, size(x, 1)\n if(x(ii) <= p)then\n x(ii) = 1d0\n else\n x(ii) = 0d0\n endif\n enddo\n \n end subroutine simulate_bernoulli_n\n \n \n !##############################################################################\n ! SUBROUTINE simulate_binomial_1\n !\n ! Simulates one draw from binomial distribution\n !##############################################################################\n subroutine simulate_binomial_1(x, n, p, fixed)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point into which the draw should be saved\n real*8, intent(out) :: x\n \n ! total number of draws\n integer, intent(in) :: n\n\n ! probability to draw 1\n real*8, intent(in) :: p\n \n ! should the random seed be initialized at a fixed values\n logical, optional :: fixed\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: ii\n real*8 :: cumprob\n \n \n !##### ROUTINE CODE #######################################################\n \n if(p < 0d0)then\n call error('simulate_binomial', 'p has a negative value')\n endif\n \n if(n < 0)then\n call error('simulate_binomial', 'n must be positive')\n endif\n \n if(present(fixed))then\n call simulate_uniform_1(x, fixed=fixed)\n else\n call simulate_uniform_1(x)\n endif\n \n ! derive bernoulli probability schedule\n cumprob = binomialPDF(0, n, p)\n if(x <= cumprob)then\n x = 0d0\n else\n do ii = 1, n\n cumprob = cumprob + binomialPDF(ii, n, p)\n if(x <= cumprob)then\n x = dble(ii)\n exit\n endif\n enddo\n endif\n \n end subroutine simulate_binomial_1\n \n \n !##############################################################################\n ! SUBROUTINE simulate_binomial_n\n !\n ! Simulates draws from binomial distribution\n !##############################################################################\n subroutine simulate_binomial_n(x, n, p, fixed)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! point into which the draw should be saved\n real*8, intent(out) :: x(:)\n \n ! total number of draws\n integer, intent(in) :: n\n\n ! probability to draw 1\n real*8, intent(in) :: p\n \n ! should the random seed be initialized at a fixed values\n logical, optional :: fixed\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: ii, it\n real*8 :: cumprob(0:n)\n \n \n !##### ROUTINE CODE #######################################################\n \n if(p < 0d0)then\n call error('simulate_binomial', 'p has a negative value')\n endif\n \n if(n < 0)then\n call error('simulate_binomial', 'n must be positive')\n endif\n \n ! simulate\n if(present(fixed))then\n call simulate_uniform_n(x, fixed=fixed)\n else\n call simulate_uniform_n(x)\n endif\n \n ! derive bernoulli probability schedule\n cumprob(0) = binomialPDF(0, n, p)\n do ii = 1, n\n cumprob(ii) = cumprob(ii-1) + binomialPDF(ii, n, p)\n enddo\n \n ! get draws\n do it = 1, size(x, 1)\n do ii = 0, n\n if(x(it) <= cumprob(ii))then\n x(it) = dble(ii)\n exit\n endif\n enddo\n enddo\n \n end subroutine simulate_binomial_n\n \n \n !##############################################################################\n ! SUBROUTINE normal_discrete_1\n !\n ! Creates n points and probabilities for a normal distribution.\n !\n ! PARTS OF THIS PROCEDURE WERE COPIED AND ADAPTED FROM:\n ! CompEcon toolbox of Mario Miranda and Paul Fackler available under\n ! http://www4.ncsu.edu/~pfackler/compecon/toolbox.html\n !\n ! REFERENCE: Miranda, M. & Fackler, P. (2002). Applied Computational Economics \n ! and Finance. Cambridge: MIT Press.\n !##############################################################################\n subroutine normal_discrete_1(x, prob, mu, sigma)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! discrete points of normal distribution\n real*8, intent(out) :: x(:)\n \n ! probability weights\n real*8, intent(out) :: prob(:)\n \n ! expectation of distribution\n real*8, optional :: mu\n \n ! variance of distribution\n real*8, optional :: sigma\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: mu_c, sigma_c, pim4, z=0d0, z1, p1, p2, p3, pp\n integer :: n, m, i, j, its\n integer, parameter :: maxit = 200\n real*8, parameter :: pi = 3.1415926535897932d0\n \n \n !##### ROUTINE CODE #######################################################\n \n ! initialize parameters\n mu_c = 0d0\n if(present(mu))mu_c = mu\n sigma_c = 1d0\n if(present(sigma))sigma_c = sqrt(sigma)\n \n if(sigma_c < 0d0)then\n call error('normal_discrete','sigma has negative value')\n endif\n \n ! check for right array sizes\n n = assert_eq(size(x,1), size(prob,1), 'normal_discrete')\n \n ! calculate 1/pi^0.25\n pim4 = 1d0/pi**0.25d0\n \n ! get number of points\n m = (n+1)/2\n \n ! initialize x and prob\n x = 0d0\n prob = 0d0\n \n ! start iteration\n do i = 1, m\n \n ! set reasonable starting values\n if(i == 1)then\n z = sqrt(dble(2*n+1))-1.85575d0*(dble(2*n+1)**(-1d0/6d0))\n elseif(i == 2)then\n z = z - 1.14d0*(dble(n)**0.426d0)/z\n elseif(i == 3)then\n z = 1.86d0*z+0.86d0*x(1)\n elseif(i == 4)then\n z = 1.91d0*z+0.91d0*x(2);\n else\n z = 2d0*z+x(i-2);\n endif\n \n ! root finding iterations\n its = 0\n do while(its < maxit)\n its = its+1\n p1 = pim4\n p2 = 0d0\n do j = 1, n\n p3 = p2\n p2 = p1\n p1 = z*sqrt(2d0/dble(j))*p2-sqrt(dble(j-1)/dble(j))*p3\n enddo\n pp = sqrt(2d0*dble(n))*p2\n z1 = z\n z = z1-p1/pp\n if(abs(z-z1) < 1e-14)exit\n enddo\n if(its >= maxit)then\n call error('normal_discrete', &\n 'Could not discretize normal distribution')\n endif\n x(n+1-i) = z\n x(i) = -z\n prob(i) = 2d0/pp**2\n prob(n+1-i) = prob(i)\n enddo\n \n ! set output data\n prob = prob/sqrt(pi)\n x = x*sqrt(2d0)*sigma_c + mu_c\n \n end subroutine normal_discrete_1\n \n \n !##############################################################################\n ! SUBROUTINE normal_discrete_2\n !\n ! Creates n1*n2 points and probabilities for a two-dimensional normal\n ! distribution.\n !\n ! PARTS OF THIS PROCEDURE WERE COPIED AND ADAPTED FROM:\n ! CompEcon toolbox of Mario Miranda and Paul Fackler available under\n ! http://www4.ncsu.edu/~pfackler/compecon/toolbox.html\n !\n ! REFERENCE: Miranda, M. & Fackler, P. (2002). Applied Computational Economics \n ! and Finance. Cambridge: MIT Press.\n !##############################################################################\n subroutine normal_discrete_2(n, x, prob, mu, sigma, rho)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! number of points in every direction\n integer, intent(in) :: n(2)\n \n ! discrete points of normal distribution\n real*8, intent(out) :: x(:, :)\n \n ! probability weights\n real*8, intent(out) :: prob(:)\n \n ! expectation of distribution\n real*8, optional :: mu(2)\n \n ! variance of distribution\n real*8, optional :: sigma(2)\n \n ! correlation of distribution\n real*8, optional :: rho\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: mu_c(2), sig_c(2), rho_c, sigma_c(2,2), l(2,2)\n real*8 :: x1(n(1)), x2(n(2)), p1(n(1)), p2(n(2))\n integer :: m, j, k\n \n \n !##### ROUTINE CODE #######################################################\n \n ! initialize parameters\n mu_c = 0d0\n if(present(mu))mu_c = mu\n sig_c(1) = 1d0\n if(present(sigma))sig_c = sigma\n rho_c = 0d0\n if(present(rho))rho_c = rho\n \n ! set up variance covariance matrix\n sigma_c(1, 1) = sig_c(1)\n sigma_c(2, 2) = sig_c(2)\n sigma_c(1, 2) = rho_c*sqrt(sig_c(1)*sig_c(2))\n sigma_c(2, 1) = sigma_c(1, 2)\n \n ! check for right array sizes\n m = assert_eq(size(x,1), size(prob,1), n(1)*n(2), 'normal_discrete')\n m = assert_eq(size(x,2), 2, 'normal_discrete')\n \n ! check whether sigma is symmetric\n if(any(abs(transpose(sigma_c) - sigma_c) > 1d-20)) &\n call error('normal_discrete', &\n 'Variance-Covariance matrix is not symmetric')\n \n ! get standard normal distributed random variables\n call normal_discrete(x1, p1, 0d0, 1d0)\n call normal_discrete(x2, p2, 0d0, 1d0)\n \n ! get joint distribution\n m = 1\n do k = 1, n(2)\n do j = 1, n(1)\n prob(m) = p1(j)*p2(k)\n x(m, :) = (/x1(j), x2(k)/)\n m = m+1\n enddo\n enddo\n \n ! decompose var-cov matrix\n if(.not.any(abs(sig_c) <= 1d-100))then\n call cholesky(sigma_c, l)\n else\n l = 0d0\n l(1,1) = sqrt(sig_c(1))\n l(2,2) = sqrt(sig_c(2))\n endif\n \n ! calculate distribution\n x = matmul(x, transpose(l))\n x(:, 1) = x(:, 1) + mu_c(1)\n x(:, 2) = x(:, 2) + mu_c(2)\n \n end subroutine normal_discrete_2\n \n \n !##############################################################################\n ! SUBROUTINE log_normal_discrete_1\n !\n ! Creates n points and probabilities for a log-normal distribution.\n !\n ! REFERENCE: Miranda, M. & Fackler, P. (2002). Applied Computational Economics \n ! and Finance. Cambridge: MIT Press.\n !##############################################################################\n subroutine log_normal_discrete_1(x, prob, mu, sigma)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! discrete points of normal distribution\n real*8, intent(out) :: x(:)\n \n ! probability weights\n real*8, intent(out) :: prob(:)\n \n ! expectation of distribution\n real*8, optional :: mu\n \n ! variance of distribution\n real*8, optional :: sigma\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: mu_c, sigma_c\n integer :: n\n \n !##### ROUTINE CODE #######################################################\n \n ! initialize parameters\n mu_c = exp(0.5d0)\n if(present(mu))mu_c = mu\n sigma_c = exp(1d0)*(exp(1d0)-1d0)\n if(present(sigma))sigma_c = sigma\n \n if(sigma_c < 0d0)then\n call error('log_normal_discrete','sigma has negative value')\n endif\n if(mu_c <= 0d0)then\n call error('log_normal_discrete','mu has zero or negative value')\n endif\n \n ! get expectation and variance\n sigma_c = log(1d0+sigma_c/mu_c**2)\n mu_c = log(mu_c)-0.5d0*sigma_c\n \n ! check for right array sizes\n n = assert_eq(size(x,1), size(prob,1), 'normal_discrete')\n n = n\n \n call normal_discrete(x, prob, mu_c, sigma_c)\n \n x = exp(x)\n \n end subroutine log_normal_discrete_1\n \n \n !##############################################################################\n ! SUBROUTINE log_normal_discrete_2\n !\n ! Creates n1*n2 points and probabilities for a two-dimensional log-normal\n ! distribution.\n !\n ! REFERENCE: Miranda, M. & Fackler, P. (2002). Applied Computational Economics \n ! and Finance. Cambridge: MIT Press.\n !##############################################################################\n subroutine log_normal_discrete_2(n, x, prob, mu, sigma, rho)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! number of points in every direction\n integer, intent(in) :: n(2)\n \n ! discrete points of normal distribution\n real*8, intent(out) :: x(:, :)\n \n ! probability weights\n real*8, intent(out) :: prob(:)\n \n ! expectation of distribution\n real*8, optional :: mu(2)\n \n ! variance of distribution\n real*8, optional :: sigma(2)\n \n ! correlation of distribution\n real*8, optional :: rho\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: mu_c(2), sig_c(2), rho_c, sigma_c(2,2), l(2,2)\n real*8 :: x1(n(1)), x2(n(2)), p1(n(1)), p2(n(2))\n integer :: m, j, k\n \n \n !##### ROUTINE CODE #######################################################\n \n ! initialize parameters\n mu_c = exp(0.5d0)\n if(present(mu))mu_c = mu\n sig_c = exp(1d0)*(exp(1d0)-1d0)\n if(present(sigma))sig_c = sigma\n rho_c = 0d0\n if(present(rho))rho_c = rho\n \n if(any(sig_c < 0d0))then\n call error('log_normal_discrete','sigma has negative value')\n endif\n if(any(mu_c <= 0d0))then\n call error('log_normal_discrete','mu has zero or negative value')\n endif\n if(rho_c < -1d0 .or. rho_c > 1d0)then\n call error('log_normal_discrete','rho is outside -1 to 1')\n endif\n \n ! get expectation and variance\n sig_c = log(1d0+sig_c/mu_c**2)\n mu_c = log(mu_c)-0.5d0*sig_c\n \n ! set up covariance matrix\n sigma_c(1, 1) = sig_c(1)\n sigma_c(2, 2) = sig_c(2)\n sigma_c(1, 2) = log(rho_c*sqrt(exp(sig_c(1))-1d0)* &\n sqrt(exp(sig_c(2))-1d0)+1d0)\n sigma_c(2, 1) = sigma_c(1, 2)\n \n ! check for right array sizes\n m = assert_eq(size(x,1), size(prob,1), n(1)*n(2), 'normal_discrete')\n m = assert_eq(size(x,2), 2, 'normal_discrete')\n \n ! check whether sigma is symmetric\n if(any(abs(transpose(sigma_c) - sigma_c) > 1d-20)) &\n call error('normal_discrete', &\n 'Variance-Covariance matrix is not symmetric')\n \n ! get standard normal distributed random variables\n call normal_discrete(x1, p1, 0d0, 1d0)\n call normal_discrete(x2, p2, 0d0, 1d0)\n \n ! get joint distribution\n m = 1\n do k = 1, n(2)\n do j = 1, n(1)\n prob(m) = p1(j)*p2(k)\n x(m, :) = (/x1(j), x2(k)/)\n m = m+1\n enddo\n enddo\n \n ! decompose var-cov matrix\n if(.not.any(abs(sig_c) <= 1d-100))then\n call cholesky(sigma_c, l)\n else\n l = 0d0\n l(1,1) = sqrt(sig_c(1))\n l(2,2) = sqrt(sig_c(2))\n endif\n \n ! calculate distribution\n x = matmul(x, transpose(l))\n x(:, 1) = x(:, 1) + mu_c(1)\n x(:, 2) = x(:, 2) + mu_c(2)\n x = exp(x)\n \n end subroutine log_normal_discrete_2\n\n\n\n\n\n\n\n\n \n \n \n \n \n \n!############################################################################## \n!##############################################################################\n! MODULE polynomial\n!##############################################################################\n!##############################################################################\n \n \n !##############################################################################\n ! FUNCTION poly_interpol_1\n !\n ! Constructs interpolating polynomial given nodes xi and data yi.\n !##############################################################################\n function poly_interpol_1(x, xi, yi)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! value where to evaluate polynomial\n real*8, intent(in) :: x\n \n ! nodes of interpolation\n real*8, intent(in) :: xi(0:)\n \n ! data of interpolation\n real*8, intent(in) :: yi(0:)\n \n ! return value\n real*8 :: poly_interpol_1\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: j, n, i\n real*8 :: lagrange_poly(0:size(xi, 1)-1)\n \n !##### ROUTINE CODE #######################################################\n \n ! get number of interpolation nodes\n n = assert_eq(size(xi, 1), size(yi, 1), 'poly_interpol') - 1\n \n ! initialize lagrange basis polynomials\n lagrange_poly(:) = 1d0\n \n ! span polynomials\n do j = 0, n\n do i = 0, n\n if(j /= i)then\n lagrange_poly(j) = lagrange_poly(j) * (x-xi(i))/(xi(j)-xi(i))\n endif\n enddo\n enddo\n \n poly_interpol_1 = sum(yi*lagrange_poly, 1)\n \n end function poly_interpol_1\n \n \n !##############################################################################\n ! FUNCTION poly_interpol_m\n !\n ! Constructs interpolating polynomial given nodes xi and data yi and several\n ! points x.\n !##############################################################################\n function poly_interpol_m(x, xi, yi)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! value where to evaluate polynomial\n real*8, intent(in) :: x(1:)\n \n ! nodes of interpolation\n real*8, intent(in) :: xi(0:)\n \n ! data of interpolation\n real*8, intent(in) :: yi(0:)\n \n ! return value\n real*8 :: poly_interpol_m(size(x, 1))\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: j, n, i\n real*8 :: lagrange_poly(size(x, 1), 0:size(xi, 1))\n \n \n !##### ROUTINE CODE #######################################################\n \n ! get number of interpolation nodes\n n = assert_eq(size(xi, 1), size(yi, 1), 'poly_interpol') - 1\n \n ! initialize lagrange basis polynomials\n lagrange_poly(:, :) = 1d0\n \n ! span polynomials\n do j = 0, n\n do i = 0, n\n if(j /= i)then\n lagrange_poly(:, j) = lagrange_poly(:, j) * &\n (x-xi(i))/(xi(j)-xi(i))\n endif\n enddo\n enddo\n \n do j = 1, size(x, 1)\n poly_interpol_m(j) = sum(yi*lagrange_poly(j, :), 1)\n enddo\n \n end function poly_interpol_m\n\n\n\n\n\n\n\n\n\n \n \n \n \n \n \n!############################################################################## \n!##############################################################################\n! MODULE minimization\n!##############################################################################\n!##############################################################################\n \n \n !##############################################################################\n ! SUBROUTINE settol_min\n !\n ! For setting global tolerance level.\n !##############################################################################\n subroutine settol_min(tol)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! tolerance level\n real*8, intent(in) :: tol\n \n \n !##### ROUTINE CODE #######################################################\n \n ! check whether tolerance level is valid\n if(tol > 0d0)then\n tbox_gftol = tol\n else\n call warning('settol_min', 'tolerance level is not valid')\n endif\n \n end subroutine settol_min\n \n \n !##############################################################################\n ! SUBROUTINE setiter_min\n !\n ! For setting maximum number of iterations.\n !##############################################################################\n subroutine setiter_min(iter)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! tolerance level\n integer, intent(in) :: iter\n \n \n !##### ROUTINE CODE #######################################################\n \n ! check whether tolerance level is valid\n if(iter > 0)then\n tbox_itermax_min = iter\n else\n call warning('setiter_min', 'number of iterations is not valid')\n endif\n \n end subroutine setiter_min\n \n \n !##############################################################################\n ! SUBROUTINE brent\n !\n ! Minimizes a one dimensional function.\n !\n ! PARTS OF THIS PROCEDURE WERE COPIED AND ADAPTED FROM:\n ! Press, W.H., Teukolsky, S.A., Vetterling, W.T. & Flannery, B.P. (1992). \n ! Numerical Recipes in Fortran 90: The Art of Parallel Scientific\n ! Computing, 2nd edition. Cambridge: Cambridge University Press.\n !##############################################################################\n subroutine brent(xmin, fret, minimum, maximum, func)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! minimum value found\n real*8, intent(inout) :: xmin\n \n ! function value at minimum\n real*8, intent(out) :: fret\n \n ! left, middle and right interval points\n real*8, intent(in) :: minimum, maximum\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: tol\n real*8, parameter :: cgold = 0.3819660d0\n real*8, parameter :: zeps = 1.0e-3*epsilon(xmin)\n real*8 :: a=0d0, b=0d0, d=0d0, e=0d0, etemp, fu, fv, fw, fx, p, q, r, tol1, tol2, &\n u, v, w, x, xm, ax, bx, cx\n integer :: iter\n \n \n !##### INTERFACES #########################################################\n \n ! interface for the function\n interface\n function func(p)\n implicit none\n real*8, intent(in) :: p\n real*8 :: func\n end function func \n end interface\n \n \n !##### ROUTINE CODE #######################################################\n \n ! set tolerance level\n tol = tbox_gftol\n \n ! set ax, bx and cx\n ax = minimum\n cx = maximum\n\n a = min(ax, cx)\n b = max(ax, cx)\n \n if(abs(xmin-a) <= 1d-6)then\n bx = a + 1d-6\n elseif(abs(xmin-b) <= 1d-6)then\n bx = b - 1d-6\n elseif(xmin > a .and. xmin < b)then\n bx = xmin\n else\n bx = (ax+cx)/2d0\n endif\n \n v = bx\n w = v\n x = v\n e = 0d0\n fx = func(x)\n fv = fx\n fw = fx\n \n do iter = 1,tbox_itermax_min\n xm = 0.5d0*(a+b)\n tol1 = tol*abs(x)+zeps\n tol2 = 2.0d0*tol1\n \n if(abs(x-xm) <= (tol2-0.5d0*(b-a)))then\n xmin = x\n fret = fx\n return\n endif\n \n if(abs(e) > tol1)then\n r = (x-w)*(fx-fv)\n q = (x-v)*(fx-fw)\n p = (x-v)*q-(x-w)*r\n q = 2.0d0*(q-r)\n if (q > 0.0d0) p = -p\n q = abs(q)\n etemp = e\n e = d\n if(abs(p) >= abs(0.5d0*q*etemp) .or. &\n p <= q*(a-x) .or. p >= q*(b-x))then\n e = merge(a-x, b-x, x >= xm )\n d = CGOLD*e\n else\n d = p/q\n u = x+d\n if(u-a < tol2 .or. b-u < tol2) d = sign(tol1, xm-x)\n endif\n \n else\n e = merge(a-x, b-x, x >= xm )\n d = CGOLD*e\n endif\n \n u = merge(x+d, x+sign(tol1, d), abs(d) >= tol1 )\n fu = func(u)\n if(fu <= fx)then\n if(u >= x)then\n a = x\n else\n b = x\n endif\n call shft(v, w, x, u)\n call shft(fv, fw, fx, fu)\n else\n if(u < x)then\n a = u\n else\n b = u\n endif\n if(fu <= fw .or. abs(w-x) <= 1d-100)then\n v = w\n fv = fw\n w = u\n fw = fu\n elseif(fu <= fv .or. abs(v-x) <= 1d-100 .or. abs(v-w) <= 1d-100)then\n v = u\n fv = fu\n endif\n endif\n enddo\n \n call warning('fminsearch', 'maximum iterations exceeded')\n \n \n !##### SUBROUTINES AND FUNCTIONS ##########################################\n \n contains\n \n \n !##########################################################################\n ! SUBROUTINE shft\n !\n ! Shifts b to a, c to b and d to c.\n !##########################################################################\n subroutine shft(a, b, c, d)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #########################################\n \n real*8, intent(out) :: a\n real*8, intent(inout) :: b, c\n real*8, intent(in ) :: d\n \n \n !##### ROUTINE CODE ###################################################\n a = b\n b = c\n c = d\n end subroutine shft\n \n end subroutine brent\n \n \n \n !##############################################################################\n ! SUBROUTINE powell\n !\n ! Powell is a multidimensional function minimizer.\n !\n ! PARTS OF THIS PROCEDURE WERE COPIED AND ADAPTED FROM:\n ! Press, W.H., Teukolsky, S.A., Vetterling, W.T. & Flannery, B.P. (1992). \n ! Numerical Recipes in Fortran 90: The Art of Parallel Scientific\n ! Computing, 2nd edition. Cambridge: Cambridge University Press.\n !##############################################################################\n subroutine powell(p, fret, minimum, maximum, func)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! starting and ending point\n real*8, intent(inout) :: p(:)\n \n ! value of function in minimum\n real*8, intent(out) :: fret\n \n ! minimum optimization interval point\n real*8, intent(in) :: minimum(:)\n \n ! maximum optimization interval point\n real*8, intent(in) :: maximum(:)\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: xi(size(p, 1), size(p, 1))\n real*8 :: ftol\n real*8, parameter :: tiny = 1.0e-25\n integer :: i, ibig, n, iter\n real*8 :: del, fp, fptt, t\n real*8, dimension(size(p)) :: pt, ptt, xit\n real*8 :: xicom(size(p,1))\n \n \n !##### INTERFACES #########################################################\n \n ! interface for the function\n interface\n function func(p)\n implicit none\n real*8, intent(in) :: p(:)\n real*8 :: func\n end function func\n end interface\n \n \n !##### ROUTINE CODE #######################################################\n \n ! set tolerance level\n ftol = tbox_gftol\n \n ! Set number of points\n n = assert_eq(size(p), size(minimum, 1), size(maximum,1), 'fminsearch')\n \n ! initialize direction set\n xi = 0d0\n do i = 1, n\n xi(i, i) = 1d0\n enddo\n \n ! calculate function value\n fret = func(p)\n \n ! store old p\n pt(:) = p(:)\n \n ! start iteration\n iter = 0\n do\n ! step counter\n iter = iter+1\n \n ! save old function value\n fp = fret\n \n ! ibig will be direction of steepest decline\n ibig = 0\n del = 0.0d0\n \n ! iterate over all dimensions\n do i = 1, n\n \n ! copy direction i and store old function value\n xit(:) = xi(:,i)\n fptt = fret\n \n ! minimize along this direction\n call linmin(p, xit, n, fret, func)\n \n ! store i into i big if i is the direction of steepest decline\n if (fptt-fret > del) then\n del=fptt-fret\n ibig=i\n endif\n enddo\n \n ! termination criterion\n if (2d0*(fp - fret) <= ftol*(abs(fp) + abs(fret)) + tiny) return\n \n ! quit if maximum iterations reached\n if(iter == tbox_itermax_min)then\n call warning('fminsearch', 'maximum iterations exceeded')\n endif\n \n ! construct extrapolated point\n ptt(:) = 2d0*p(:) - pt(:)\n xit(:) = p(:) - pt(:)\n pt(:) = p(:)\n \n ! calculate function value at extrapolated point\n fptt = func(ptt)\n \n ! if function value greater than actual value\n ! -> no change of directions\n if (fptt >= fp) cycle\n \n ! calculate t\n t = 2d0*(fp - 2d0*fret + fptt) * (fp - fret - del)**2 &\n - del*(fp - fptt)**2\n \n ! if t > 0 -> no change of directions\n if (t >= 0d0) cycle\n \n ! else minimize along new direction and start new iteration\n call linmin(p, xit, n, fret, func)\n xi(:, ibig) = xi(:, n)\n xi(:,n) = xit(:)\n enddo\n \n \n !##### SUBROUTINES AND FUNCTIONS ##########################################\n \n contains\n \n \n !##########################################################################\n ! SUBROUTINE linmin\n !\n ! Minimizes multidimensional function along a given direction.\n !##########################################################################\n subroutine linmin(p, xi, n, fret, func)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #########################################\n \n ! point where to start and minimum if minimization is done\n real*8, intent(inout) :: p(n)\n \n ! direction in which to optimize\n real*8, intent(inout) :: xi(n)\n \n ! number of dimensions\n integer, intent(in) :: n\n \n ! value of function at minimum\n real*8, intent(out) :: fret\n \n \n !##### OTHER VARIABLES ################################################\n \n real*8 :: tol\n real*8 :: ax, bx, cx, xmin\n \n \n !##### INTERFACES #####################################################\n \n ! interface for the function\n interface\n function func(p)\n implicit none\n real*8, intent(in) :: p(:)\n real*8 :: func\n end function func\n end interface\n \n \n !##### ROUTINE CODE ###################################################\n \n ! set tolerance level\n tol = tbox_gftol\n \n xicom(:) = xi(:)\n \n ! get optimization interval\n call getintervall(ax, bx, cx)\n \n ! minimize function using one dimensional optimizer\n fret = brent_pow(ax, bx, cx, tol, xmin, func)\n \n ! calculate new direction and endpoint\n xi(:) = xmin*xi(:)\n p(:) = p(:) + xi(:)\n \n end subroutine linmin\n \n \n !##########################################################################\n ! SUBROUTINE getinterval\n !\n ! Calculates optimization interval along a given direction.\n !##########################################################################\n subroutine getintervall(ax, bx, cx)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #########################################\n \n ! left, middle and right interval point\n real*8, intent(out) :: ax, bx, cx\n \n \n !##### OTHER VARIABLES ################################################\n \n integer :: i\n real*8 :: w(0:1,n)\n \n \n !##### ROUTINE CODE ###################################################\n \n ! calculate right interval point\n cx = -1.e20\n do i = 1, n\n if(abs(xicom(i)) >= 1d-100)then\n w(0,i) = (extr(i, 0, xicom(i))-p(i))/xicom(i)\n else\n w(0,i) = -1.e20\n endif\n if(w(0,i) > cx)cx = w(0, i)\n enddo\n \n ! calculate left interval point\n ax = 1.e20\n do i=1, n\n if(abs(xicom(i)) >= 1d-100)then\n w(1,i) = (extr(i, 1, xicom(i))-p(i))/xicom(i)\n else\n w(1,i) = 1.e20\n endif\n if(w(1,i) < ax)ax = w(1,i)\n enddo\n \n ! calculate point in between [ax, cx]\n bx = 0d0\n \n end subroutine getintervall\n \n \n !##########################################################################\n ! FUNCTION extr\n !\n ! Calculates interval endpoint in a given dimension.\n !##########################################################################\n real*8 function extr(dim, maxxx, richt)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #########################################\n \n ! dimension in which to search\n integer, intent(in) :: dim\n \n ! do you want the maximum or minimum endpoint\n integer, intent(in) :: maxxx\n \n ! what is the optimization direction\n real*8 :: richt\n \n \n !##### ROUTINE CODE ###################################################\n \n if(richt > 0d0 .and. maxxx == 1 .or. richt < 0d0 .and. maxxx == 0)then\n extr = maximum(dim)\n else\n extr = minimum(dim)\n endif\n \n end function extr\n \n \n !##########################################################################\n ! FUNCTION f1dim\n !\n ! Maps multidimensional function and point/direction combo into\n ! one-dimensional function.\n !##########################################################################\n function f1dim(x, func)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #########################################\n \n ! point where to evaluate the multidimensional function\n real*8, intent(in) :: x\n \n ! function value\n real*8 :: f1dim\n \n \n !##### OTHER VARIABLES ################################################\n \n real*8 :: xt(n)\n \n \n !##### INTERFACES #####################################################\n \n ! interface for the function\n interface\n function func(p)\n implicit none\n real*8, intent(in) :: p(:)\n real*8 :: func\n end function func\n end interface\n \n \n !##### ROUTINE CODE ###################################################\n \n ! create point where to evaluate func\n xt(:) = p(:)+x*xicom(:)\n \n ! evaluate func at this point\n f1dim = func(xt)\n \n end function f1dim\n \n \n !##########################################################################\n ! FUNCTION brent_pow\n !\n ! Minimizes a one dimensional function.\n !##########################################################################\n function brent_pow(ax, bx, cx, tol, xmin, func)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #########################################\n \n ! left, middle and right interval points\n real*8, intent(in) :: ax, bx, cx\n \n ! level of tolerance\n real*8, intent(in) :: tol\n \n ! minimum value found\n real*8, intent(out) :: xmin\n \n ! function value at minimum\n real*8 :: brent_pow\n \n \n !##### OTHER VARIABLES ################################################\n \n real*8, parameter :: cgold = 0.3819660d0\n real*8, parameter :: zeps=1.0e-3*epsilon(ax)\n integer :: iter\n real*8 :: a=0d0, b=0d0, d=0d0, e=0d0, etemp=0d0\n real*8 :: fu, fv, fw, fx, p, q, r, tol1, tol2, &\n u, v, w, x, xm\n \n \n !##### INTERFACES #####################################################\n \n ! interface for the function\n interface\n function func(p)\n implicit none\n real*8, intent(in) :: p(:)\n real*8 :: func\n end function func\n end interface\n \n \n !##### ROUTINE CODE ###################################################\n \n a = min(ax, cx)\n b = max(ax, cx)\n v = bx\n w = v\n x = v\n e = 0d0\n fx = f1dim(x, func)\n fv = fx\n fw = fx\n \n do iter = 1,tbox_tbox_itermax_pow_b\n \n xm = 0.5d0*(a+b)\n tol1 = tol*abs(x)+zeps\n tol2 = 2.0d0*tol1\n\n if(abs(x-xm) <= (tol2-0.5d0*(b-a)))then\n xmin = x\n brent_pow = fx\n return\n endif\n\n if(abs(e) > tol1)then\n r = (x-w)*(fx-fv)\n q = (x-v)*(fx-fw)\n p = (x-v)*q-(x-w)*r\n q = 2.0d0*(q-r)\n if (q > 0.0d0) p = -p\n q = abs(q)\n etemp = e\n e = d\n if(abs(p) >= abs(0.5d0*q*etemp ) .or. &\n p <= q*(a-x) .or. p >= q*(b-x))then\n e = merge(a-x, b-x, x >= xm )\n d = CGOLD*e\n else\n d = p/q\n u = x+d\n if(u-a < tol2 .or. b-u < tol2) d = sign(tol1, xm-x)\n endif\n\n else\n e = merge(a-x, b-x, x >= xm )\n d = CGOLD*e\n endif\n u = merge(x+d, x+sign(tol1, d), abs(d) >= tol1 )\n fu = f1dim(u, func)\n if(fu <= fx)then\n if(u >= x)then\n a = x\n else\n b = x\n endif\n call shft(v, w, x, u)\n call shft(fv, fw, fx, fu)\n else\n if(u < x)then\n a = u\n else\n b = u\n endif\n if(fu <= fw .or. abs(w-x) <= 1d-100)then\n v = w\n fv = fw\n w = u\n fw = fu\n elseif(fu <= fv .or. abs(v-x) <= 1d-100 .or. abs(v-w) <= 1d-100)then\n v = u\n fv = fu\n endif\n endif\n enddo\n \n xmin = x\n brent_pow = fx\n call warning('fminsearch', 'maximum iterations exceeded')\n \n end function brent_pow\n \n \n !##########################################################################\n ! SUBROUTINE shft\n !\n ! Shifts b to a, c to b and d to c.\n !##########################################################################\n subroutine shft(a, b, c, d)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #########################################\n \n real*8, intent(out) :: a\n real*8, intent(inout) :: b, c\n real*8, intent(in ) :: d\n \n \n !##### ROUTINE CODE ###################################################\n a = b\n b = c\n c = d\n end subroutine shft\n \n end subroutine powell\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n!##############################################################################\n!##############################################################################\n! MODULE simplex\n!##############################################################################\n!##############################################################################\n\n\n !##############################################################################\n ! SUBROUTINE solve_lin\n !\n ! For solving a linear program in normal form by means of the simplex\n ! algorithm.\n !##############################################################################\n subroutine solve_lin(x, c, A, b, numle, numge, numeq)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! solution of the linear program\n real*8, intent(inout) :: x(:)\n \n ! coefficients in the function to minimize\n real*8, intent(in) :: c(:)\n \n ! constraint matrix \n real*8, intent(in) :: A(:, :)\n \n ! target vectors of constraint\n real*8, intent(in) :: b(:)\n \n ! number of lower equal constraints\n integer, intent(in) :: numle\n \n ! number of greater equal constraints\n integer, intent(in) :: numge\n \n ! number of equality constraints\n integer, intent(in) :: numeq\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: m, n, i1\n real*8 :: A_h(size(A, 1), size(A, 2)+numle+numge)\n real*8 :: c_h(size(c, 1)+numle+numge), b_h(size(b, 1))\n real*8 :: x_h(size(x, 1)+numle+numge)\n real*8 :: newA(size(A, 1), size(A, 2)+numle+numge)\n \n \n !##### ROUTINE CODE #######################################################\n \n ! check for sizes\n n = assert_eq(size(x, 1), size(c, 1), size(A, 2), 'solve_lin')\n m = assert_eq(size(A, 1), size(b, 1), 'solve_lin')\n \n ! check for correct inputs\n if(numle < 0)then\n call error('solve_lin', 'Number of lower equal constraints must '// &\n 'not be negative')\n elseif(numge < 0)then\n call error('solve_lin', 'Number of greater equal constraints must '// &\n 'not be negative')\n elseif(numeq < 0)then\n call error('solve_lin', 'Number of equality constraints must '// &\n 'not be negative')\n elseif(numle+numge+numeq /= size(b,1))then\n call error('solve_lin', 'Number of equations does not match size of b')\n endif\n \n ! set up optimization problem\n A_h = 0d0\n A_h(1:m, 1:n) = A(:, :)\n do i1 = 1, numle\n A_h(i1, n+i1) = 1d0\n enddo\n do i1 = 1, numge\n A_h(numle+i1, n+numle+i1) = -1d0\n enddo\n \n ! check for negative bs\n b_h = b\n do i1 = 1, m\n if(b(i1) < 0d0)then\n A_h(i1, :) = -A_h(i1, :)\n b_h(i1) = -b_h(i1)\n endif\n enddo\n \n ! initialize c\n c_h = 0d0\n c_h(1:n) = c(:)\n \n call get_starting_value(x_h, A_h, b_h, newA)\n \n call solve_simplex(x_h, c_h, newA)\n \n x = x_h(1:n)\n \n contains\n \n \n !##############################################################################\n ! SUBROUTINE get_starting_value\n !\n ! Calculates a starting value for the linear program.\n !##############################################################################\n subroutine get_starting_value(x0, A, b, newA)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! starting value of the linear program\n real*8, intent(out) :: x0(:)\n \n ! constraint matrix\n real*8, intent(in) :: A(:, :)\n \n ! target vectors of constraint\n real*8, intent(in) :: b(:)\n \n ! new matrix for simplex\n real*8, intent(out) :: newA(:, :)\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: m, n, j\n real*8 :: Astart(size(A,1), size(A,1)+size(A,2))\n real*8 :: cstart(size(A,1)+size(A,2)), xstart(size(A,1)+size(A,2))\n \n !##### ROUTINE CODE #######################################################\n \n ! get sizes\n n = size(A, 2)\n m = size(A, 1)\n \n ! set up help problem\n cstart(1:n) = 0d0\n cstart(n+1:n+m) = 1d0\n \n ! set up help matrix\n Astart(1:m, 1:n) = A\n Astart(1:m, n+1:n+m) = 0d0\n do j = 1, m\n Astart(j,n+j) = 1d0\n enddo\n \n ! get initial guess\n xstart(1:n) = 0d0\n xstart(n+1:n+m) = b\n \n ! solve linear program\n call solve_simplex(xstart, cstart, Astart, newA)\n \n ! set starting value\n x0 = xstart(1:n)\n \n end subroutine get_starting_value\n \n \n !##############################################################################\n ! SUBROUTINE solve_simplex\n !\n ! Solves a linear program in canonic form.\n !##############################################################################\n subroutine solve_simplex(x, c, A, newA)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! starting value of the linear program and result\n real*8, intent(inout) :: x(:)\n \n ! coefficients of the program\n real*8, intent(in) :: c(:)\n \n ! constraint matrix\n real*8, intent(in) :: A(:, :)\n \n ! new tableau if starting value calculation\n real*8, intent(out), optional :: newA(:, :)\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: k, m, n, j, ibas, inot, piv(2), ihelp, i1, i2, n1, bhelp\n integer :: bas(size(A, 1)), nbas(size(A, 2)-size(A, 1))\n real*8 :: alpha(size(A, 1), size(A,2)-size(A, 1))\n real*8 :: gamma(size(A, 2)-size(A,1)), x0(size(A, 1))\n real*8 :: pivcheck(size(A,1)), phelp, alpha_h(size(alpha, 2))\n \n !##### ROUTINE CODE #######################################################\n \n ! get sizes\n n = size(A, 2)\n m = size(A, 1)\n k = size(A, 2)-size(A,1)\n \n ! set up basis and non basis elements\n ibas = 1\n inot = 1\n do j = 1, n\n if(abs(x(j)) >= 1d-100)then\n bas(ibas) = j\n ibas = ibas + 1\n else\n nbas(inot) = j\n inot = inot + 1\n endif\n enddo\n \n ! set up x0 and c'x\n do ibas = 1, m\n x0(ibas) = x(bas(ibas))\n enddo\n \n ! set up alphas\n do inot = 1, k\n alpha(:, inot) = -A(:, nbas(inot))\n enddo\n \n ! set up gammas\n do inot = 1, k\n gamma(inot) = 0d0\n do ibas = 1, m\n gamma(inot) = gamma(inot) + alpha(ibas, inot)*c(bas(ibas))\n enddo\n gamma(inot) = gamma(inot) + c(nbas(inot))\n enddo\n \n ! start algorithm\n do\n \n ! choose pivot column\n piv = 0\n do inot = 1, k\n if(gamma(inot) < 0d0)then\n piv(2) = inot\n exit\n endif\n enddo\n \n ! algorithm ends of no gamma < 0\n if(piv(2) == 0)exit\n \n ! else choose pivot row\n do ibas = 1, m\n if(abs(alpha(ibas, piv(2))) >= 1d-100)then\n pivcheck(ibas) = x0(ibas)/alpha(ibas, piv(2))\n else\n pivcheck(ibas) = -1d300\n endif\n enddo\n phelp = -1d300\n do ibas = 1, m\n if(alpha(ibas, piv(2)) < 0d0 .and. pivcheck(ibas) > phelp)then\n phelp = pivcheck(ibas)\n piv(1) = ibas\n endif\n enddo\n \n ! no solution in piv(1) == 0\n if(piv(1) == 0)then\n call error('solve_lin','Problem has no solution')\n endif\n \n ! Apply basis change\n Ihelp = nbas(piv(2))\n nbas(piv(2)) = bas(piv(1))\n bas(piv(1)) = Ihelp\n \n ! change pivot element\n alpha(piv(1), piv(2)) = 1d0/alpha(piv(1), piv(2))\n \n ! change pivot column\n do ibas = 1, m\n if(ibas /= piv(1))then\n alpha(ibas, piv(2)) = alpha(ibas, piv(2))* &\n alpha(piv(1), piv(2))\n endif\n enddo\n \n ! change pivot row\n do inot = 1, k\n if(inot /= piv(2))then\n alpha(piv(1), inot) = -alpha(piv(1), inot)* &\n alpha(piv(1), piv(2))\n endif\n enddo\n \n ! change other elements of alpha\n do ibas = 1, m\n do inot = 1, k\n if(ibas /= piv(1) .and. inot /= piv(2))then\n alpha(ibas, inot) = alpha(ibas, inot) + &\n alpha(ibas, piv(2))*alpha(piv(1), inot)/ &\n alpha(piv(1), piv(2))\n endif\n enddo\n enddo\n \n ! change x0\n x0(piv(1)) = -x0(piv(1))*alpha(piv(1), piv(2))\n do ibas = 1, m\n if(ibas /= piv(1))then\n x0(ibas) = x0(ibas) + alpha(ibas, piv(2))*x0(piv(1))/ &\n alpha(piv(1), piv(2))\n endif\n enddo\n \n ! change gammas\n gamma(piv(2)) = gamma(piv(2))*alpha(piv(1), piv(2))\n do inot = 1, k\n if(inot /= piv(2))then\n gamma(inot) = gamma(inot) + alpha(piv(1), inot)* &\n gamma(piv(2))/alpha(piv(1), piv(2))\n endif\n enddo\n \n enddo\n \n ! get solution\n x = 0d0\n do ibas = 1, m\n x(bas(ibas)) = x0(ibas)\n enddo\n \n ! set up new tableau if needed\n if(present(newA))then\n \n ! check for existence of a solution\n n1 = 1\n do i1 = 1, n\n if(c(i1) > 0d0)then\n n1 = i1\n exit\n endif\n enddo\n if(any(x(n1:n) > 0d0))then\n call error('solve_lin', &\n 'Linear Program does not have a solution')\n endif\n \n ! sort tableau in ascending order\n do i1 = m-1,1,-1\n do i2 = 1, i1\n if(bas(i2) > bas(i2+1))then\n bhelp = bas(i2)\n bas(i2) = bas(i2+1)\n bas(i2+1) = bhelp\n \n alpha_h = alpha(i2, :)\n alpha(i2, :) = alpha(i2+1, :)\n alpha(i2+1, :) = alpha_h\n endif\n enddo\n enddo\n \n ! get new matrix\n newA = 0d0\n do i1 = 1, k\n if(nbas(i1) <= n1-1)then\n newA(:, nbas(i1)) = -alpha(:, i1)\n endif\n enddo\n endif\n \n end subroutine solve_simplex\n \n end subroutine solve_lin\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n!##############################################################################\n!##############################################################################\n! MODULE rootfinding\n!##############################################################################\n!##############################################################################\n\n\n !##############################################################################\n ! SUBROUTINE settol_root\n !\n ! For setting global tolerance level.\n !##############################################################################\n subroutine settol_root(tol)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! tolerance level\n real*8, intent(in) :: tol\n \n \n !##### ROUTINE CODE #######################################################\n \n ! check whether tolerance level is valid\n if(tol > 0d0)then\n tbox_gftol_root = tol\n else\n call warning('settol_root', 'tolerance level is not valid')\n endif\n \n end subroutine settol_root\n \n \n !##############################################################################\n ! SUBROUTINE setiter_root\n !\n ! For setting maximum number of iterations.\n !##############################################################################\n subroutine setiter_root(iter)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! number of iterations\n integer, intent(in) :: iter\n \n \n !##### ROUTINE CODE #######################################################\n \n ! check whether number of iterations is valid\n if(iter > 0)then\n itermax_root = iter\n else\n call warning('setiter_root', 'number of iterations is not valid')\n endif\n \n end subroutine setiter_root\n \n \n !##############################################################################\n ! SUBROUTINE newton_interpol\n !\n ! Find root of one-dimensional function by interpolatory newton method.\n !##############################################################################\n subroutine newton_interpol(x, funcv, check_return)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! initial guess and root of the function\n real*8, intent(inout) :: x\n \n ! check is true if newton_interpol converged to local minimum or can make no\n ! further progress\n logical, intent(out), optional :: check_return\n \n !##### OTHER VARIABLES ####################################################\n \n real*8, parameter :: eps = epsilon(x)\n real*8 :: tolf, tolmin\n real*8, parameter :: tolx = eps\n real*8, parameter :: stpmx = 100d0\n real*8 :: x1, x2, f1, f2, xnew, fnew, h\n integer :: its\n \n \n !##### INTERFACES #########################################################\n \n ! interface for the function\n interface\n function funcv(p)\n implicit none\n real*8, intent(in) :: p\n real*8 :: funcv\n end function funcv\n end interface\n \n \n !##### ROUTINE CODE #######################################################\n \n ! set tolerance levels\n tolf = tbox_gftol_root\n tolmin = tbox_gftol_root\n if(present(check_return))check_return = .false.\n \n ! initialize values\n x1 = x\n h = 1d-6*max(abs(x), 0.01d0)\n x2 = x + h\n \n ! calculate function values at x1, x2\n f1 = funcv(x1)\n f2 = funcv(x2)\n \n ! check if already in zero\n if(abs(f1) < 0.01d0*tolf)then\n x = x1\n if(present(check_return))check_return = .false.\n return\n endif\n \n if(abs(f2) < 0.01d0*tolf)then\n x = x2\n if(present(check_return))check_return = .false.\n return\n endif\n \n if(abs((1d0-f1/f2)/(x2-x1)) < tolmin .or. &\n abs((1d0-f1/f2)) < epsilon(1d0))then\n x = x1\n if(present(check_return))check_return = .true.\n return\n endif\n \n ! start iteration\n do its = 1, itermax_root\n \n ! calculate new point xnew\n xnew = x2 - (x2-x1)/(1d0-f1/f2)\n \n ! calculate new function value\n fnew = funcv(xnew)\n \n ! check wether function is small enough\n if(abs(fnew) < tolf)then\n x = xnew\n if(present(check_return))check_return = .false.\n return\n endif\n \n ! check whether you are in a minimum or cannot proceed further\n if(2d0*abs(xnew-x2) < tolx*abs(xnew+x2))then\n x = x2\n if(present(check_return))check_return = .true.\n return\n endif\n \n ! else set new data and repeat step\n x1 = x2\n f1 = f2\n x2 = xnew\n f2 = fnew\n\n if(abs((1d0-f1/f2)/(x2-x1)) < tolmin .or. &\n abs((1d0-f1/f2)) < epsilon(1d0))then\n x = x1\n if(present(check_return))check_return = .true.\n return\n endif\n enddo\n \n ! throw warning if newton didn't converge\n if(present(check_return))check_return = .true.\n \n x = xnew\n \n end subroutine newton_interpol\n \n \n !##############################################################################\n ! SUBROUTINE broydn\n !\n ! Find root of multidimensional function of.\n !\n ! PARTS OF THIS PROCEDURE WERE COPIED AND ADAPTED FROM:\n ! Press, W.H., Teukolsky, S.A., Vetterling, W.T. & Flannery, B.P. (1992). \n ! Numerical Recipes in Fortran 90: The Art of Parallel Scientific\n ! Computing, 2nd edition. Cambridge: Cambridge University Press. \n !##############################################################################\n subroutine broydn(x, funcv, check_return)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! initial guess and root of the function\n real*8, intent(inout) :: x(:)\n \n ! check is true if broydn converged to local minimum or can make no\n ! further progress\n logical, intent(out), optional :: check_return\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8, parameter :: eps = epsilon(x)\n real*8 :: tolf, tolmin\n real*8, parameter :: tolx = eps\n real*8, parameter :: stpmx = 100d0\n integer :: i, j, k, its, n\n real*8 :: f, fold, stpmax\n real*8, dimension(size(x)) :: c, d, fvcold, g, p, s, t, w, xold\n real*8, dimension(size(x),size(x)) :: qt, r\n logical :: restrt, sing, check\n real*8 :: fvec(size(x,1))\n \n \n !##### INTERFACES #########################################################\n \n ! interface for the function\n interface\n function funcv(p)\n implicit none\n real*8, intent(in) :: p(:)\n real*8 :: funcv(size(p, 1))\n end function funcv\n end interface\n \n \n !##### ROUTINE CODE #######################################################\n \n ! set tolerance levels\n tolf = tbox_gftol_root\n tolmin = tbox_gftol_root\n if(present(check_return))check_return = .false.\n \n ! get size of x\n n = size(x) \n \n ! calculate function euklidean norm at starting point\n f = fmin(x, funcv)\n \n ! check if root has been found\n if (maxval(abs(fvec(:))) < 0.01d0*tolf) then\n if(present(check_return))check_return = .false.\n return\n endif\n \n stpmax = stpmx*max(sqrt(dot_product(x(:),x(:))),dble(n))\n restrt = .true.\n \n ! iterate broydn steps\n do its=1,itermax_root\n \n ! If restart then calculate jacobian of function\n if (restrt) then\n \n ! calculate jacobian of func at x\n call fdjac(x, fvec, r, funcv)\n \n ! make q-r-decomposition of jacobian\n call qrdcmp(r, c, d, sing)\n \n ! throw error if jacobian is singular\n if(sing)then\n call warning('fzero', 'singular jacobian')\n if(present(check_return))check_return = .true.\n return\n endif\n \n ! create unity matrix\n qt(:,:) = 0d0\n do j = 1, n\n qt(j, j) = 1d0\n enddo\n \n ! for Q^T explicitly\n do k = 1, n-1\n if (abs(c(k)) >= 1d-100) then\n qt(k:n,:) = qt(k:n, :)-outerprod(r(k:n, k), &\n matmul(r(k:n, k), qt(k:n, :)))/c(k)\n endif\n enddo\n where(lower_triangle(n,n))r(:, :) = 0d0\n \n ! puts diagonal elements of R matrix to r\n do j = 1, n\n r(j, j) = d(j)\n enddo\n \n ! else do Broydn update step\n else\n \n ! set up s as delta x\n s(:) = x(:)-xold(:)\n \n ! t = R*delta x\n do i = 1, n\n t(i) = dot_product(r(i,i:n), s(i:n))\n enddo\n \n ! w = delta f - B*s = delta f - R*s*Q^T\n w(:) = fvec(:)-fvcold(:)-matmul(t(:), qt(:,:))\n \n ! if w entries are small enough, set them to zero\n where(abs(w(:)) < EPS*(abs(fvec(:))+abs(fvcold(:)))) w(:) = 0d0\n \n ! update for non-noisy components of w\n if(any(abs(w(:)) >= 1d-100))then\n \n ! update t and s\n t(:) = matmul(qt(:,:),w(:))\n s(:)=s(:)/dot_product(s,s)\n \n ! update R and Q^T\n call qrupdt(r,qt,t,s)\n \n ! get diagonal of matrix r\n do j = 1, size(r,1)\n d(j) = r(j,j)\n enddo\n \n ! if any diagonal value of r is 0, then jacobian is singular\n if(any(abs(d(:)) <= 1d-100))then\n call warning('fzero', 'singular jacobian')\n if(present(check_return))check_return = .true.\n return \n endif\n endif\n endif\n \n ! perform the newton step by inverting jacobian\n p(:) = -matmul(qt(:,:), fvec(:))\n do i = 1, n\n g(i) = -dot_product(r(1:i,i), p(1:i))\n enddo\n \n ! store old x, function value and function norm\n xold(:) = x(:)\n fvcold(:) = fvec(:)\n fold = f\n \n ! solve linear equation with upper triangular matrix r\n call rsolv(r, d, p)\n \n ! searches along the new gradient direction for new x and f\n call lnsrch(xold, fold, g, p, x, f, stpmax, check, funcv)\n \n ! check whether root was found\n if(maxval(abs(fvec(:))) < tolf)then\n if(present(check_return))check_return = .false.\n return\n endif\n \n ! if check is true\n if(check)then\n \n ! check if improvement can be made, if not, return\n if(restrt .or. maxval(abs(g(:))*max(abs(x(:)), &\n 1d0)/max(f, 0.5d0*n)) < tolmin)then\n if(present(check_return))check_return = check\n return\n endif\n \n ! else calculate new jacobian\n restrt=.true.\n \n ! if check is false\n else\n \n ! do broydn step\n restrt=.false.\n \n ! check for convergence\n if (maxval((abs(x(:)-xold(:)))/max(abs(x(:)), &\n 1.0d0)) < tolx)then\n if(present(check_return))check_return = check\n return\n endif\n endif\n enddo\n \n ! throw warning if broydn didn't converge\n if(present(check_return))check_return = .true.\n \n \n !##### SUBROUTINES AND FUNCTIONS ##########################################\n \n contains\n \n \n !##########################################################################\n ! FUNCTION fdjac\n !\n ! Calculates finite difference jacobian.\n !##########################################################################\n subroutine fdjac(x, fvec, df, funcv)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #########################################\n \n ! value where to calculate finite difference jacobian\n real*8, intent(inout) :: x(:)\n \n ! function value at x\n real*8, intent(in) :: fvec(:)\n \n ! resulting finite difference jacobian\n real*8, intent(out) :: df(:, :)\n \n \n !##### OTHER VARIABLES ################################################\n \n real*8, parameter :: eps = 1.0e-6\n integer :: j, n\n real*8, dimension(size(x)) :: xsav, xph, h\n \n \n !##### INTERFACES #####################################################\n \n ! interface for the function\n interface\n function funcv(p)\n implicit none\n real*8, intent(in) :: p(:)\n real*8 :: funcv(size(p, 1))\n end function funcv\n end interface\n \n \n !##### ROUTINE CODE ###################################################\n \n ! check equality of sizes\n n = assert_eq(size(x), size(fvec), size(df,1), size(df,2), 'fdjac')\n \n ! store old x\n xsav = x\n \n ! calculate difference\n h = eps*abs(xsav)\n where(abs(h) <= 1d-100)h = EPS\n \n ! calculate x + h\n xph = xsav + h\n h = xph - xsav\n \n ! itertate over dimensions and calculate difference\n do j = 1, n\n x(j) = xph(j)\n df(:,j) = (funcv(x)-fvec(:))/h(j)\n x(j) = xsav(j)\n enddo\n \n end subroutine fdjac\n \n \n !##########################################################################\n ! FUNCTION lnsrch\n !\n ! Finds point along a line, given function value and gradient, where\n ! function has decreased sufficiently (for one dimensional function).\n !##########################################################################\n subroutine lnsrch(xold, fold, g, p, x, f, stpmax, check, funcv)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #########################################\n \n ! point where to start line search\n real*8, intent(in) :: xold(:)\n \n ! the old function value\n real*8, intent(in) :: fold\n \n ! gradient at this point\n real*8, intent(in) :: g(:)\n \n ! a line search direction\n real*8, intent(inout) :: p(:)\n \n ! new value along the search line\n real*8, intent(out) :: x(:)\n \n ! function value at new x\n real*8, intent(out) :: f\n \n ! maximum size of steps such that lnsrch does not search un undefined\n ! areas\n real*8, intent(in) :: stpmax\n \n ! is true if x is too close at xold\n logical, intent(out) :: check\n \n \n !##### OTHER VARIABLES ################################################\n \n real*8, parameter :: alf = 1.0e-4\n real*8, parameter :: tolx = epsilon(x)\n integer :: ndum\n real*8 :: a, alam, alam2=0d0, alamin, b, disc, f2=0d0, pabs, rhs1, rhs2, &\n slope, tmplam\n \n \n !##### INTERFACES #####################################################\n \n ! interface for the function\n interface\n function funcv(p)\n implicit none\n real*8, intent(in) :: p(:)\n real*8 :: funcv(size(p, 1))\n end function funcv\n end interface\n \n \n !##### ROUTINE CODE ###################################################\n \n ! assert sizes or arrays\n ndum = assert_eq(size(g), size(p), size(x), size(xold), 'lnsrch')\n ndum = ndum\n \n ! set check's default value\n check=.false.\n \n ! calculate norm of p\n pabs = sqrt(dot_product(p, p))\n \n ! restrict p to maximum stepsize\n if(pabs > stpmax)p(:) = p(:)*stpmax/pabs\n \n ! calculate slope\n slope = dot_product(g, p)\n \n ! throw error if you would go uphill\n if(slope >= 0d0)then\n call warning('lnsrch', 'roundoff problem, I cannot go uphill')\n return\n endif\n \n ! calculate newton stepsize\n alamin = tolx/maxval(abs(p(:))/max(abs(xold(:)),1d0))\n alam = 1d0\n \n ! start iteration\n do\n ! calculate calculate new x\n x(:) = xold(:)+alam*p(:)\n \n ! calculate new function value at x\n f = fmin(x, funcv)\n \n ! if new x is not away enough return with check=true\n if(alam < alamin)then\n x(:) = xold(:)\n check = .true.\n return\n \n ! if optimal value found return with false\n elseif(f <= fold+alf*alam*slope)then\n return\n \n ! else do backtracking\n else\n if(abs(alam -1d0) <= 1d-100)then\n tmplam = -slope/(2d0*(f-fold-slope))\n else\n rhs1 = f-fold-alam*slope\n rhs2 = f2-fold-alam2*slope\n a = (rhs1/alam**2-rhs2/alam2**2)/(alam-alam2)\n b = (-alam2*rhs1/alam**2+alam*rhs2/alam2**2)/(alam-alam2)\n if(abs(a) <= 1d-100)then\n tmplam = -slope/(2d0*b)\n else\n disc = b*b-3d0*a*slope\n if(disc < 0d0)then\n tmplam = 0.5d0*alam\n elseif(b <= 0d0)then\n tmplam = (-b+sqrt(disc))/(3d0*a)\n else\n tmplam = -slope/(b+sqrt(disc))\n endif\n endif\n if(tmplam > 0.5d0*alam)tmplam = 0.5d0*alam\n endif\n endif\n alam2 = alam\n f2 = f\n alam = max(tmplam,0.1d0*alam)\n enddo\n \n end subroutine lnsrch\n \n \n !##########################################################################\n ! FUNCTION fmin\n !\n ! Calculates vector norm of multidimensional function.\n !##########################################################################\n function fmin(x, funcv)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #########################################\n \n ! value where to evaluate function\n real*8, intent(in) :: x(:)\n \n ! euklidean square norm of function at x\n real*8 :: fmin\n \n \n !##### INTERFACES #####################################################\n \n ! interface for the function\n interface\n function funcv(p)\n implicit none\n real*8, intent(in) :: p(:)\n real*8 :: funcv(size(p, 1))\n end function funcv\n end interface\n \n ! calculate function value\n fvec = funcv(x)\n \n ! calculate squared norm\n fmin = 0.5d0*dot_product(fvec, fvec)\n \n end function fmin\n \n \n !##########################################################################\n ! SUBROUTINE qrdcmp\n !\n ! Calculates QR decomposition of a matrix.\n !##########################################################################\n subroutine qrdcmp(a, c, d, sing)\n \n implicit none\n \n real*8, intent(inout) :: a(:, :)\n real*8, intent(out) :: c(:), d(:)\n logical, intent(out) :: sing\n integer :: k, n\n real*8 :: scale, sigma\n \n n = assert_eq(size(a,1), size(a,2), size(c), size(d), 'qrdcmp')\n sing = .false.\n do k = 1, n-1\n scale = maxval(abs(a(k:n, k)))\n if(abs(scale) <= 1d-100)then\n sing = .true.\n c(k) = 0d0\n d(k) = 0d0\n else\n a(k:n, k) = a(k:n, k)/scale\n sigma = sign(sqrt(dot_product(a(k:n, k),a(k:n, k))),a(k, k))\n a(k,k) = a(k, k)+sigma\n c(k) = sigma*a(k, k)\n d(k) = -scale*sigma\n a(k:n, k+1:n) = a(k:n, k+1:n)-outerprod(a(k:n, k),&\n matmul(a(k:n, k),a(k:n, k+1:n)))/c(k)\n endif\n enddo\n d(n) = a(n, n)\n if (abs(d(n)) <= 1d-100) sing = .true.\n \n end subroutine qrdcmp\n \n \n !##########################################################################\n ! SUBROUTINE qrupdt\n !\n ! Updates qr-matrices.\n !##########################################################################\n subroutine qrupdt(r,qt,u,v)\n \n implicit none\n \n real*8, intent(inout) :: r(:, :), qt(:, :)\n real*8, intent(inout) :: u(:)\n real*8, intent(in) :: v(:)\n integer :: i, k, n\n \n n = assert_eq((/ size(r,1), size(r,2), size(qt,1), size(qt,2), &\n size(u), size(v)/), 'qrupdt')\n k = n+1-ifirstloc(abs(u(n:1:-1)) >= 1d-100)\n if(k < 1)k=1\n do i = k-1, 1, -1\n call rotate(r,qt,i,u(i),-u(i+1))\n u(i) = pythag(u(i),u(i+1))\n enddo\n r(1,:) = r(1,:)+u(1)*v\n do i = 1,k-1\n call rotate(r,qt,i,r(i,i),-r(i+1,i))\n enddo\n end subroutine qrupdt\n \n !##########################################################################\n ! SUBROUTINE rsolv\n !\n ! Solves upper diagonal system.\n !##########################################################################\n subroutine rsolv(a, d, b)\n \n implicit none\n \n real*8, intent(in) :: a(:, :), d(:)\n real*8, intent(inout) :: b(:)\n integer :: i, n\n \n n = assert_eq(size(a,1), size(a,2), size(b), size(d), 'rsolv')\n b(n) = b(n)/d(n)\n do i = n-1, 1, -1\n b(i) =( b(i)-dot_product(a(i, i+1:n),b(i+1:n)))/d(i)\n enddo\n \n end subroutine rsolv\n \n \n subroutine rotate(r, qt, i, a, b)\n \n implicit none\n \n real*8, intent(inout) :: r(:, :), qt(:, :)\n integer, intent(in) :: i\n real*8, intent(in) :: a, b\n integer :: n\n real*8 :: c, fact, s, temp(size(r,1))\n \n n = assert_eq(size(r,1), size(r,2), size(qt,1), size(qt,2), 'rotate')\n if(abs(a) <= 1d-100)then\n c = 0d0\n s = sign(1d0, b)\n elseif(abs(a) > abs(b))then\n fact = b/a\n c = sign(1d0/sqrt(1d0+fact**2), a)\n s = fact*c\n else\n fact = a/b\n s = sign(1d0/sqrt(1d0+fact**2), b)\n c=fact*s\n endif\n temp(i:n) = r(i, i:n)\n r(i, i:n) = c*temp(i:n)-s*r(i+1, i:n)\n r(i+1, i:n) = s*temp(i:n)+c*r(i+1, i:n)\n temp = qt(i, :)\n qt(i, :) = c*temp-s*qt(i+1, :)\n qt(i+1, :) = s*temp+c*qt(i+1, :)\n \n end subroutine rotate\n \n \n function pythag(a, b)\n \n implicit none\n \n real*8, intent(in) :: a, b\n real*8 :: pythag\n real*8 :: absa, absb\n \n absa = abs(a)\n absb = abs(b)\n if(absa > absb)then\n pythag = absa*sqrt(1d0+(absb/absa)**2)\n else\n if(abs(absb) <= 1d-100)then\n pythag = 0d0\n else\n pythag = absb*sqrt(1d0+(absa/absb)**2)\n endif\n endif\n \n end function pythag\n \n \n function ifirstloc(mask)\n \n logical, intent(in) :: mask(:)\n integer :: ifirstloc, loca(1)\n \n loca = maxloc(merge(1, 0, mask))\n ifirstloc = loca(1)\n if(.not. mask(ifirstloc))ifirstloc = size(mask)+1\n \n end function ifirstloc\n \n \n function lower_triangle(j, k, extra)\n \n integer, intent(in) :: j, k\n integer, intent(in), optional :: extra\n logical :: lower_triangle(j, k)\n integer :: n\n \n n = 0\n if(present(extra))n = extra\n \n lower_triangle = (outerdiff(arth_i(1, 1, j), arth_i(1, 1, k)) > -n)\n \n end function lower_triangle\n \n \n function outerdiff(a, b)\n \n integer, intent(in) :: a(:), b(:)\n integer :: outerdiff(size(a, 1),size(b, 1))\n \n outerdiff = spread(a, dim=2, ncopies=size(b, 1)) - &\n spread(b, dim=1, ncopies=size(a, 1))\n \n end function outerdiff\n \n \n function outerprod(a, b)\n \n real*8, intent(in) :: a(:), b(:)\n real*8 :: outerprod(size(a, 1),size(b, 1))\n \n outerprod = spread(a, dim=2, ncopies=size(b, 1)) * &\n spread(b, dim=1, ncopies=size(a, 1))\n \n end function outerprod\n \n \n function arth_i(first, increment, n)\n \n integer, intent(in) :: first, increment, n\n integer, parameter :: npar_arth = 16\n integer, parameter :: npar2_arth = 8\n integer :: arth_i(n)\n integer :: k, k2, temp\n \n if(n > 0)arth_i(1) = first\n if(n <= npar_arth) then\n do k = 2, n\n arth_i(k) = arth_i(k-1) + increment\n enddo\n else\n do k = 2, npar2_arth\n arth_i(k) = arth_i(k-1) + increment\n enddo\n temp = increment*npar2_arth\n k = npar2_arth\n do\n if(k >= n)exit\n k2 = k+k\n arth_i(k+1:min(k2,n)) = temp+arth_i(1:min(k,n-k))\n temp = temp + temp\n k = k2\n enddo\n endif\n end function arth_i\n \n end subroutine broydn\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n!##############################################################################\n!##############################################################################\n! MODULE splines\n!##############################################################################\n!##############################################################################\n \n \n !##############################################################################\n ! SUBROUTINE spline_interp1\n !\n ! Subroutine for one-dimensional spline interpolation.\n !##############################################################################\n subroutine spline_interp1(yi, c)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! interpolation data\n real*8, intent(in) :: yi(0:)\n \n ! coefficients for spline interpolation\n real*8, intent(out) :: c(1:)\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: n, j\n real*8, allocatable :: r(:), d(:)\n \n \n !##### ROUTINE CODE #######################################################\n \n ! assert sizes for the two arrays do fit\n n = assert_eq(size(yi,1)+2, size(c,1), 'spline_interp')\n \n ! deallocate help arrays\n if(allocated(r))deallocate(r)\n if(allocated(d))deallocate(d)\n \n ! allocate help arrays\n allocate(r(n))\n allocate(d(n))\n \n ! calculate real n\n n = n-3\n \n ! calculate numerical derivatives at end points\n r(1) = (2d0*yi(0)-5d0*yi(1)+4d0*yi(2)-yi(3))/6d0\n r(n+3) = (2d0*yi(n)-5d0*yi(n-1)+4d0*yi(n-2)-yi(n-3))/6d0\n \n ! set rest of right side of equation system\n r(2:n+2) = yi(0:n)\n \n ! solve the spline interpolation equation system\n c(2) = (yi(0)-r(1))/6d0\n c(n+2) = (yi(n)-r(n+3))/6d0\n \n d(3) = 4d0\n r(3) = yi(1)-c(2)\n r(n+1) = yi(n-1)-c(n+2)\n \n do j = 4, n+1\n d(j) = 4d0-1d0/d(j-1)\n r(j) = r(j)-r(j-1)/d(j-1)\n enddo\n \n c(n+1) = r(n+1)/d(n+1)\n \n do j = n, 3, -1\n c(j) = (r(j)-c(j+1))/d(j)\n enddo\n \n c(1) = r(1)+2d0*c(2)-c(3)\n c(n+3) = r(n+3)+2d0*c(n+2)-c(n+1)\n \n end subroutine spline_interp1\n \n \n !##############################################################################\n ! SUBROUTINE spline_interp2\n !\n ! Subroutine for two-dimensional spline interpolation.\n !##############################################################################\n subroutine spline_interp2(yi, c)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! interpolation data\n real*8, intent(in) :: yi(0:, 0:)\n \n ! coefficients for spline interpolation\n real*8, intent(out) :: c(1:, 1:)\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: n(2), j\n real*8, allocatable :: tempc(:, :)\n \n \n !##### ROUTINE CODE #######################################################\n \n ! calculate array sizes\n do j = 1, 2\n n(j) = assert_eq(size(yi,j)+2, size(c,j), 'spline_interp')\n enddo\n \n ! calculate real n\n n = n-3\n \n ! deallocate tempc\n if(allocated(tempc))deallocate(tempc)\n \n ! allocate tempc\n allocate(tempc(n(1)+3, 0:n(2)))\n \n ! calculate temporary coefficients\n do j = 0, n(2)\n call spline_interp1(yi(:, j), tempc(:, j))\n enddo\n \n ! calculate actual coefficients\n do j = 1, n(1)+3\n call spline_interp1(tempc(j, :), c(j, :))\n enddo\n \n end subroutine spline_interp2\n \n \n !##############################################################################\n ! SUBROUTINE spline_interp3\n !\n ! Subroutine for three-dimensional spline interpolation.\n !##############################################################################\n subroutine spline_interp3(yi, c)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! interpolation data\n real*8, intent(in) :: yi(0:, 0:, 0:)\n \n ! coefficients for spline interpolation\n real*8, intent(out) :: c(1:, 1:, 1:)\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: n(3), j, j2\n real*8, allocatable :: tempc(:, :, :)\n \n \n !##### ROUTINE CODE #######################################################\n \n ! calculate array sizes\n do j = 1, 3\n n(j) = assert_eq(size(yi,j)+2, size(c,j), 'spline_interp')\n enddo\n \n ! calculate real n\n n = n-3\n \n ! deallocate tempc\n if(allocated(tempc))deallocate(tempc)\n \n ! allocate tempc\n allocate(tempc(n(1)+3, n(2)+3, 0:n(3)))\n \n ! calculate temporary coefficients\n do j = 0, n(3)\n call spline_interp2(yi(:, :, j), tempc(:, :, j))\n enddo\n \n ! calculate actual coefficients\n do j = 1, n(1)+3\n do j2 = 1, n(2)+3\n call spline_interp1(tempc(j, j2, :), c(j, j2, :))\n enddo\n enddo\n \n end subroutine spline_interp3\n \n \n !##############################################################################\n ! SUBROUTINE spline_interp4\n !\n ! Subroutine for four-dimensional spline interpolation.\n !##############################################################################\n subroutine spline_interp4(yi, c)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! interpolation data\n real*8, intent(in) :: yi(0:, 0:, 0:, 0:)\n \n ! coefficients for spline interpolation\n real*8, intent(out) :: c(1:, 1:, 1:, 1:)\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: n(4), j, j2, j3\n real*8, allocatable :: tempc(:, :, :, :)\n \n \n !##### ROUTINE CODE #######################################################\n \n ! calculate array sizes\n do j = 1, 4\n n(j) = assert_eq(size(yi,j)+2, size(c,j), 'spline_interp')\n enddo\n \n ! calculate real n\n n = n-3\n \n ! deallocate tempc\n if(allocated(tempc))deallocate(tempc)\n \n ! allocate tempc\n allocate(tempc(n(1)+3, n(2)+3, n(3)+3, 0:n(4)))\n \n ! calculate temporary coefficients\n do j = 0, n(4)\n call spline_interp3(yi(:, :, :, j), tempc(:, :, :, j))\n enddo\n \n ! calculate actual coefficients\n do j = 1, n(1)+3\n do j2 = 1, n(2)+3\n do j3 = 1, n(3)+3\n call spline_interp1(tempc(j, j2, j3, :), c(j, j2, j3, :))\n enddo\n enddo\n enddo\n \n end subroutine spline_interp4\n \n \n !##############################################################################\n ! SUBROUTINE spline_interp5\n !\n ! Subroutine for five-dimensional spline interpolation.\n !##############################################################################\n subroutine spline_interp5(yi, c)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! interpolation data\n real*8, intent(in) :: yi(0:, 0:, 0:, 0:, 0:)\n \n ! coefficients for spline interpolation\n real*8, intent(out) :: c(1:, 1:, 1:, 1:, 1:)\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: n(5), j, j2, j3, j4\n real*8, allocatable :: tempc(:, :, :, :, :)\n \n \n !##### ROUTINE CODE #######################################################\n \n ! calculate array sizes\n do j = 1, 5\n n(j) = assert_eq(size(yi,j)+2, size(c,j), 'spline_interp')\n enddo\n \n ! calculate real n\n n = n-3\n \n ! deallocate tempc\n if(allocated(tempc))deallocate(tempc)\n \n ! allocate tempc\n allocate(tempc(n(1)+3, n(2)+3, n(3)+3, n(4)+3, 0:n(5)))\n \n ! calculate temporary coefficients\n do j = 0, n(5)\n call spline_interp4(yi(:, :, :, :, j), tempc(:, :, :, :, j))\n enddo\n \n ! calculate actual coefficients\n do j = 1, n(1)+3\n do j2 = 1, n(2)+3\n do j3 = 1, n(3)+3\n do j4 = 1, n(4)+3\n call spline_interp1(tempc(j, j2, j3, j4, :), &\n c(j, j2, j3, j4, :))\n enddo\n enddo\n enddo\n enddo\n \n end subroutine spline_interp5\n \n \n !##############################################################################\n ! SUBROUTINE spline_interp6\n !\n ! Subroutine for six-dimensional spline interpolation.\n !##############################################################################\n subroutine spline_interp6(yi, c)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! interpolation data\n real*8, intent(in) :: yi(0:, 0:, 0:, 0:, 0:, 0:)\n \n ! coefficients for spline interpolation\n real*8, intent(out) :: c(1:, 1:, 1:, 1:, 1:, 1:)\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: n(6), j, j2, j3, j4, j5\n real*8, allocatable :: tempc(:, :, :, :, :, :)\n \n \n !##### ROUTINE CODE #######################################################\n \n ! calculate array sizes\n do j = 1, 6\n n(j) = assert_eq(size(yi,j)+2, size(c,j), 'spline_interp')\n enddo\n \n ! calculate real n\n n = n-3\n \n ! deallocate tempc\n if(allocated(tempc))deallocate(tempc)\n \n ! allocate tempc\n allocate(tempc(n(1)+3, n(2)+3, n(3)+3, n(4)+3, n(5)+3, 0:n(6)))\n \n ! calculate temporary coefficients\n do j = 0, n(6)\n call spline_interp5(yi(:, :, :, :, :, j), tempc(:, :, :, :, :, j))\n enddo\n \n ! calculate actual coefficients\n do j = 1, n(1)+3\n do j2 = 1, n(2)+3\n do j3 = 1, n(3)+3\n do j4 = 1, n(4)+3\n do j5 = 1, n(5)+3\n call spline_interp1(tempc(j, j2, j3, j4, j5, :), &\n c(j, j2, j3, j4, j5, :))\n enddo\n enddo\n enddo\n enddo\n enddo\n \n end subroutine spline_interp6\n \n \n !##############################################################################\n ! SUBROUTINE spline_interp7\n !\n ! Subroutine for seven-dimensional spline interpolation.\n !##############################################################################\n subroutine spline_interp7(yi, c)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! interpolation data\n real*8, intent(in) :: yi(0:, 0:, 0:, 0:, 0:, 0:, 0:)\n \n ! coefficients for spline interpolation\n real*8, intent(out) :: c(1:, 1:, 1:, 1:, 1:, 1:, 1:)\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: n(7), j, j2, j3, j4, j5, j6\n real*8, allocatable :: tempc(:, :, :, :, :, :, :)\n \n \n !##### ROUTINE CODE #######################################################\n \n ! calculate array sizes\n do j = 1, 7\n n(j) = assert_eq(size(yi,j)+2, size(c,j), 'spline_interp')\n enddo\n \n ! calculate real n\n n = n-3\n \n ! deallocate tempc\n if(allocated(tempc))deallocate(tempc)\n \n ! allocate tempc\n allocate(tempc(n(1)+3, n(2)+3, n(3)+3, n(4)+3, n(5)+3, n(6)+3, 0:n(7)))\n \n ! calculate temporary coefficients\n do j = 0, n(7)\n call spline_interp6(yi(:, :, :, :, :, :, j), tempc(:, :, :, :, :, :, j))\n enddo\n \n ! calculate actual coefficients\n do j = 1, n(1)+3\n do j2 = 1, n(2)+3\n do j3 = 1, n(3)+3\n do j4 = 1, n(4)+3\n do j5 = 1, n(5)+3\n do j6 = 1, n(6)+3\n call spline_interp1(tempc(j, j2, j3, &\n j4, j5, j6, :),c(j, j2, j3, j4, j5, j6, :))\n enddo\n enddo\n enddo\n enddo\n enddo\n enddo\n \n end subroutine spline_interp7\n \n \n !##############################################################################\n ! FUNCTION spline1\n !\n ! Function for evaluation of one-dimensional spline.\n !##############################################################################\n function spline1(x, c)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! value where to evaluate spline\n real*8, intent(in) :: x\n \n ! coefficients for spline interpolation\n real*8, intent(in) :: c(1:)\n \n ! value of spline function\n real*8 :: spline1\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: n1, j1, p1, q1\n real*8 :: phi1, xtemp1\n \n \n !##### ROUTINE CODE #######################################################\n \n ! calculate number of points used\n n1 = size(c, 1)\n \n ! calculate left and right summation end point\n p1 = max(floor(x)+1, 1)\n q1 = min(p1+3, n1)\n \n spline1 = 0d0\n \n do j1 = p1, q1\n \n ! calculate value where to evaluate basis function\n xtemp1 = abs(x-j1+2)\n \n ! calculate basis function\n if(xtemp1 <= 1d0)then\n phi1 = 4d0+xtemp1**2*(3d0*xtemp1-6d0)\n elseif(xtemp1 <= 2d0)then\n phi1 = (2d0-xtemp1)**3\n else\n phi1 = 0d0\n endif\n \n ! calculate spline value\n spline1 = spline1+c(j1)*phi1\n enddo\n \n end function spline1\n \n \n !##############################################################################\n ! FUNCTION spline1_grid\n !\n ! Function for evaluation of one-dimensional spline, includes inverting grid.\n !##############################################################################\n function spline1_grid(x, c, left, right, growth)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! value where to evaluate spline\n real*8, intent(in) :: x\n \n ! coefficients for spline interpolation\n real*8, intent(in) :: c(1:)\n \n ! left interval endpoint\n real*8, intent(in) :: left\n \n ! right interval endpoint\n real*8, intent(in) :: right\n \n ! growth rate of grid\n real*8, intent(in), optional :: growth\n \n ! value of spline function\n real*8 :: spline1_grid\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: n\n real*8 :: xtemp\n \n \n !##### ROUTINE CODE #######################################################\n \n ! calculate number of grid-points\n n = size(c, 1)-3\n \n ! invert grid\n if(present(growth))then\n xtemp = grid_Inv_Grow(x, left, right, growth, n)\n else\n xtemp = grid_Inv_Equi(x, left, right, n)\n endif\n \n ! calculate spline value\n spline1_grid = spline1(xtemp, c)\n \n end function spline1_grid\n \n \n !##############################################################################\n ! FUNCTION spline1_complete\n !\n ! Function for evaluation of one-dimensional spline, includes inverting grid\n ! and interpolation method for a single point.\n !##############################################################################\n function spline1_complete(x, yi, left, right, growth)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! value where to evaluate spline\n real*8, intent(in) :: x\n \n ! data for spline interpolation\n real*8, intent(in) :: yi(0:)\n \n ! left interval endpoint\n real*8, intent(in) :: left\n \n ! right interval endpoint\n real*8, intent(in) :: right\n \n ! growth rate of grid\n real*8, intent(in), optional :: growth\n \n ! value of spline function\n real*8 :: spline1_complete\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: spline_temp(1)\n \n \n !##### ROUTINE CODE #######################################################\n \n ! invert grid for every evaluation point\n if(present(growth))then\n spline_temp = spline1_complete_m((/x/), yi, left, right, growth)\n else\n spline_temp = spline1_complete_m((/x/), yi, left, right)\n endif\n \n ! paste data\n spline1_complete = spline_temp(1)\n \n end function spline1_complete\n \n \n !##############################################################################\n ! FUNCTION spline1_complete_m\n !\n ! Function for evaluation of one-dimensional spline, includes inverting grid\n ! and interpolation method for many points.\n !##############################################################################\n function spline1_complete_m(x, yi, left, right, growth)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! value where to evaluate spline\n real*8, intent(in) :: x(1:)\n \n ! data for spline interpolation\n real*8, intent(in) :: yi(0:)\n \n ! left interval endpoint\n real*8, intent(in) :: left\n \n ! right interval endpoint\n real*8, intent(in) :: right\n \n ! growth rate of grid\n real*8, intent(in), optional :: growth\n \n ! value of spline function\n real*8 :: spline1_complete_m(size(x, 1))\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: c(1:size(yi, 1)+2)\n real*8 :: xtemp(1:size(x, 1))\n integer :: n, m, j\n \n \n !##### ROUTINE CODE #######################################################\n \n ! calculate number of grid-points\n n = size(yi, 1)-1\n \n ! calculate number of evaluation points\n m = size(x, 1)\n \n ! invert grid for every evaluation point\n if(present(growth))then\n xtemp(:) = grid_Inv_Grow(x(:), left, right, growth, n)\n else\n xtemp(:) = grid_Inv_Equi(x(:), left, right, n)\n endif\n \n ! interpolate data\n call spline_interp1(yi, c)\n \n ! calculate spline values at point\n do j = 1, m\n spline1_complete_m(j) = spline1(xtemp(j), c)\n enddo\n \n end function spline1_complete_m\n \n \n !##############################################################################\n ! FUNCTION spline2\n !\n ! Function for evaluation of two-dimensional spline.\n !##############################################################################\n function spline2(x, c)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! value where to evaluate spline\n real*8, intent(in) :: x(2)\n \n ! coefficients for spline interpolation\n real*8, intent(in) :: c(1:, 1:)\n \n ! value of spline function\n real*8 :: spline2\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: n(2), p(2), q(2)\n integer :: j1, j2\n real*8 :: phi1, xtemp1, phi2, xtemp2\n real*8 :: s2\n \n \n !##### ROUTINE CODE #######################################################\n \n ! calculate number of points used\n n(1) = size(c, 1)\n n(2) = size(c, 2)\n \n ! calculate left and right summation end point\n p = max(floor(x)+1, 1)\n q = min(p+3, n)\n \n spline2 = 0d0\n \n do j1 = p(1), q(1)\n \n ! calculate value where to evaluate basis function\n xtemp1 = abs(x(1)-j1+2)\n \n ! calculate basis function\n if(xtemp1 <= 1d0)then\n phi1 = 4d0+xtemp1**2*(3d0*xtemp1-6d0)\n elseif(xtemp1 <= 2d0)then\n phi1 = (2d0-xtemp1)**3\n else\n phi1 = 0d0\n endif\n \n \n !#### calculate spline for second dimension ###########################\n \n s2 = 0d0\n \n do j2 = p(2), q(2)\n \n ! calculate value where to evaluate basis function\n xtemp2 = abs(x(2)-j2+2)\n \n ! calculate basis function\n if(xtemp2 <= 1d0)then\n phi2 = 4d0+xtemp2**2*(3d0*xtemp2-6d0)\n elseif(xtemp2 <= 2d0)then\n phi2 = (2d0-xtemp2)**3\n else\n phi2 = 0d0\n endif\n \n ! calculate spline value\n s2 = s2+c(j1, j2)*phi2\n enddo\n \n ! calculate spline value\n spline2 = spline2+s2*phi1\n enddo\n \n end function spline2\n \n \n !##############################################################################\n ! FUNCTION spline2_grid\n !\n ! Function for evaluation of two-dimensional spline, includ inverting grid.\n !##############################################################################\n function spline2_grid(x, c, left, right, growth)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! value where to evaluate spline\n real*8, intent(in) :: x(2)\n \n ! coefficients for spline interpolation\n real*8, intent(in) :: c(1:, 1:)\n \n ! left interval endpoint\n real*8, intent(in) :: left(2)\n \n ! right interval endpoint\n real*8, intent(in) :: right(2)\n \n ! growth rate of grid\n real*8, intent(in), optional :: growth(2)\n \n ! value of spline function\n real*8 :: spline2_grid\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: n, j\n real*8 :: xtemp(2)\n \n \n !##### ROUTINE CODE #######################################################\n \n ! calculate number of grid-points\n do j = 1, size(x, 1)\n n = size(c, j)-3\n \n ! invert grid\n if(present(growth))then\n xtemp(j) = grid_Inv_Grow(x(j), left(j), right(j), growth(j), n)\n else\n xtemp(j) = grid_Inv_Equi(x(j), left(j), right(j), n)\n endif\n enddo\n \n ! calculate spline value\n spline2_grid = spline2(xtemp, c)\n \n end function spline2_grid\n \n \n !##############################################################################\n ! FUNCTION spline2_complete\n !\n ! Function for evaluation of one-dimensional spline, includes inverting grid\n ! and interpolation method for a single point.\n !##############################################################################\n function spline2_complete(x, yi, left, right, growth)\n \n \n integer, parameter :: dim = 2\n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! value where to evaluate spline\n real*8, intent(in) :: x(dim)\n \n ! data for spline interpolation\n real*8, intent(in) :: yi(0:, 0:)\n \n ! left interval endpoint\n real*8, intent(in) :: left(dim)\n \n ! right interval endpoint\n real*8, intent(in) :: right(dim)\n \n ! growth rate of grid\n real*8, intent(in), optional :: growth(dim)\n \n ! value of spline function\n real*8 :: spline2_complete\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: xtemp(1, dim)\n real*8 :: spline_temp(1)\n \n \n !##### ROUTINE CODE #######################################################\n \n ! set xtemp\n xtemp(1, :) = x\n \n ! invert grid for every evaluation point\n if(present(growth))then\n spline_temp = spline2_complete_m(xtemp, yi, left, right, growth)\n else\n spline_temp = spline2_complete_m(xtemp, yi, left, right)\n endif\n \n ! paste data\n spline2_complete = spline_temp(1)\n \n end function spline2_complete\n \n \n !##############################################################################\n ! FUNCTION spline2_complete_m\n !\n ! Function for evaluation of one-dimensional spline, includes inverting grid\n ! and interpolation method for many points.\n !##############################################################################\n function spline2_complete_m(x, yi, left, right, growth)\n \n integer, parameter :: dim = 2\n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! value where to evaluate spline\n real*8, intent(in) :: x(1:, 1:)\n \n ! data for spline interpolation\n real*8, intent(in) :: yi(0:, 0:)\n \n ! left interval endpoint\n real*8, intent(in) :: left(dim)\n \n ! right interval endpoint\n real*8, intent(in) :: right(dim)\n \n ! growth rate of grid\n real*8, intent(in), optional :: growth(dim)\n \n ! value of spline function\n real*8 :: spline2_complete_m(size(x, 1))\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: c(1:size(yi, 1)+2, 1:size(yi, 2)+2)\n real*8 :: xtemp(1:size(x, 1), dim)\n integer :: n, m, j, k\n \n \n !##### ROUTINE CODE #######################################################\n \n ! calculate number of evaluation points\n m = size(x, 1)\n \n ! check whether x has the right dimension\n n = assert_eq(size(x, 2), dim, 'spline')\n \n ! invert grid for every evaluation point\n if(present(growth))then\n do k = 1, dim\n ! calculate number of grid-points\n n = size(yi, k)-1\n \n xtemp(:, k) = grid_Inv_Grow(x(:, k), &\n left(k), right(k), growth(k), n)\n enddo\n else\n do k = 1, dim\n ! calculate number of grid-points\n n = size(yi, k)-1\n \n xtemp(:, k) = grid_Inv_Equi(x(:, k), left(k), right(k), n)\n enddo\n endif\n \n ! interpolate data\n call spline_interp2(yi, c)\n \n ! calculate spline values at point\n do j = 1, m\n spline2_complete_m(j) = spline2(xtemp(j, :), c)\n enddo\n \n end function spline2_complete_m\n \n \n !##############################################################################\n ! FUNCTION spline3\n !\n ! Function for evaluation of three-dimensional spline.\n !##############################################################################\n function spline3(x, c)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! value where to evaluate spline\n real*8, intent(in) :: x(3)\n \n ! coefficients for spline interpolation\n real*8, intent(in) :: c(1:, 1:, 1:)\n \n ! value of spline function\n real*8 :: spline3\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: n(3), p(3), q(3)\n integer :: j1, j2, j3\n real*8 :: phi1, xtemp1, phi2, xtemp2, phi3, xtemp3\n real*8 :: s2, s3\n \n \n !##### ROUTINE CODE #######################################################\n \n ! calculate number of points used\n n(1) = size(c, 1)\n n(2) = size(c, 2)\n n(3) = size(c, 3)\n \n ! calculate left and right summation end point\n p = max(floor(x)+1, 1)\n q = min(p+3, n)\n \n spline3 = 0d0\n \n do j1 = p(1), q(1)\n \n ! calculate value where to evaluate basis function\n xtemp1 = abs(x(1)-j1+2)\n \n ! calculate basis function\n if(xtemp1 <= 1d0)then\n phi1 = 4d0+xtemp1**2*(3d0*xtemp1-6d0)\n elseif(xtemp1 <= 2d0)then\n phi1 = (2d0-xtemp1)**3\n else\n phi1 = 0d0\n endif\n \n \n !#### calculate spline for second dimension ###########################\n \n s2 = 0d0\n \n do j2 = p(2), q(2)\n \n ! calculate value where to evaluate basis function\n xtemp2 = abs(x(2)-j2+2)\n \n ! calculate basis function\n if(xtemp2 <= 1d0)then\n phi2 = 4d0+xtemp2**2*(3d0*xtemp2-6d0)\n elseif(xtemp2 <= 2d0)then\n phi2 = (2d0-xtemp2)**3\n else\n phi2 = 0d0\n endif\n \n \n !#### calculate spline for second dimension #######################\n \n s3 = 0d0\n \n do j3 = p(3), q(3)\n \n ! calculate value where to evaluate basis function\n xtemp3 = abs(x(3)-j3+2)\n \n ! calculate basis function\n if(xtemp3 <= 1d0)then\n phi3 = 4d0+xtemp3**2*(3d0*xtemp3-6d0)\n elseif(xtemp3 <= 2d0)then\n phi3 = (2d0-xtemp3)**3\n else\n phi3 = 0d0\n endif\n \n ! calculate spline value\n s3 = s3+c(j1, j2, j3)*phi3\n enddo\n \n ! calculate spline value\n s2 = s2+s3*phi2\n enddo\n \n ! calculate spline value\n spline3 = spline3+s2*phi1\n enddo\n \n end function spline3\n \n \n !##############################################################################\n ! FUNCTION spline3_grid\n !\n ! Function for evaluation of three-dimensional spline, includes inverting grid.\n !##############################################################################\n function spline3_grid(x, c, left, right, growth)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! value where to evaluate spline\n real*8, intent(in) :: x(3)\n \n ! coefficients for spline interpolation\n real*8, intent(in) :: c(1:, 1:, 1:)\n \n ! left interval endpoint\n real*8, intent(in) :: left(3)\n \n ! right interval endpoint\n real*8, intent(in) :: right(3)\n \n ! growth rate of grid\n real*8, intent(in), optional :: growth(3)\n \n ! value of spline function\n real*8 :: spline3_grid\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: n, j\n real*8 :: xtemp(3)\n \n \n !##### ROUTINE CODE #######################################################\n \n ! calculate number of grid-points\n do j = 1, size(x, 1)\n n = size(c, j)-3\n \n ! invert grid\n if(present(growth))then\n xtemp(j) = grid_Inv_Grow(x(j), left(j), right(j), growth(j), n)\n else\n xtemp(j) = grid_Inv_Equi(x(j), left(j), right(j), n)\n endif\n enddo\n \n ! calculate spline value\n spline3_grid = spline3(xtemp, c)\n \n end function spline3_grid\n \n \n !##############################################################################\n ! FUNCTION spline3_complete\n !\n ! Function for evaluation of one-dimensional spline, includes inverting grid\n ! and interpolation method for a single point.\n !##############################################################################\n function spline3_complete(x, yi, left, right, growth)\n \n \n integer, parameter :: dim = 3\n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! value where to evaluate spline\n real*8, intent(in) :: x(dim)\n \n ! data for spline interpolation\n real*8, intent(in) :: yi(0:, 0:, 0:)\n \n ! left interval endpoint\n real*8, intent(in) :: left(dim)\n \n ! right interval endpoint\n real*8, intent(in) :: right(dim)\n \n ! growth rate of grid\n real*8, intent(in), optional :: growth(dim)\n \n ! value of spline function\n real*8 :: spline3_complete\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: xtemp(1, dim)\n real*8 :: spline_temp(1)\n \n \n !##### ROUTINE CODE #######################################################\n \n ! set xtemp\n xtemp(1, :) = x\n \n ! invert grid for every evaluation point\n if(present(growth))then\n spline_temp = spline3_complete_m(xtemp, yi, left, right, growth)\n else\n spline_temp = spline3_complete_m(xtemp, yi, left, right)\n endif\n \n ! paste data\n spline3_complete = spline_temp(1)\n \n end function spline3_complete\n \n \n !##############################################################################\n ! FUNCTION spline3_complete_m\n !\n ! Function for evaluation of one-dimensional spline, includes inverting grid\n ! and interpolation method for many points.\n !##############################################################################\n function spline3_complete_m(x, yi, left, right, growth)\n \n integer, parameter :: dim = 3\n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! value where to evaluate spline\n real*8, intent(in) :: x(1:, 1:)\n \n ! data for spline interpolation\n real*8, intent(in) :: yi(0:, 0:, 0:)\n \n ! left interval endpoint\n real*8, intent(in) :: left(dim)\n \n ! right interval endpoint\n real*8, intent(in) :: right(dim)\n \n ! growth rate of grid\n real*8, intent(in), optional :: growth(dim)\n \n ! value of spline function\n real*8 :: spline3_complete_m(size(x, 1))\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: c(1:size(yi, 1)+2, 1:size(yi, 2)+2, 1:size(yi, 3)+2)\n real*8 :: xtemp(1:size(x, 1), dim)\n integer :: n, m, j, k\n \n \n !##### ROUTINE CODE #######################################################\n \n ! calculate number of evaluation points\n m = size(x, 1)\n \n ! check whether x has the right dimension\n n = assert_eq(size(x, 2), dim, 'spline')\n \n ! invert grid for every evaluation point\n if(present(growth))then\n do k = 1, dim\n ! calculate number of grid-points\n n = size(yi, k)-1\n \n xtemp(:, k) = grid_Inv_Grow(x(:, k), &\n left(k), right(k), growth(k), n)\n enddo\n else\n do k = 1, dim\n ! calculate number of grid-points\n n = size(yi, k)-1\n \n xtemp(:, k) = grid_Inv_Equi(x(:, k), left(k), right(k), n)\n enddo\n endif\n \n ! interpolate data\n call spline_interp3(yi, c)\n \n ! calculate spline values at point\n do j = 1, m\n spline3_complete_m(j) = spline3(xtemp(j, :), c)\n enddo\n \n end function spline3_complete_m\n \n \n !##############################################################################\n ! FUNCTION spline4\n !\n ! Function for evaluation of four-dimensional spline.\n !##############################################################################\n function spline4(x, c)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! value where to evaluate spline\n real*8, intent(in) :: x(4)\n \n ! coefficients for spline interpolation\n real*8, intent(in) :: c(1:, 1:, 1:, 1:)\n \n ! value of spline function\n real*8 :: spline4\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: n, j, p, q\n real*8 :: phi, xtemp\n \n \n !##### ROUTINE CODE #######################################################\n \n ! calculate number of points used\n n = size(c, 1)\n \n ! calculate left and right summation end point\n p = max(floor(x(1))+1, 1)\n q = min(p+3, n)\n \n spline4 = 0d0\n \n do j = p, q\n \n ! calculate value where to evaluate basis function\n xtemp = abs(x(1)-j+2)\n \n ! calculate basis function\n if(xtemp <= 1d0)then\n phi = 4d0+xtemp**2*(3d0*xtemp-6d0)\n elseif(xtemp <= 2d0)then\n phi = (2d0-xtemp)**3\n else\n phi = 0d0\n endif\n \n ! calculate spline value\n spline4 = spline4+spline3(x(2:4), c(j, :, :, :))*phi\n enddo\n \n end function spline4\n \n \n !##############################################################################\n ! FUNCTION spline4_grid\n !\n ! Function for evaluation of four-dimensional spline, includes inverting grid.\n !##############################################################################\n function spline4_grid(x, c, left, right, growth)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! value where to evaluate spline\n real*8, intent(in) :: x(4)\n \n ! coefficients for spline interpolation\n real*8, intent(in) :: c(1:, 1:, 1:, 1:)\n \n ! left interval endpoint\n real*8, intent(in) :: left(4)\n \n ! right interval endpoint\n real*8, intent(in) :: right(4)\n \n ! growth rate of grid\n real*8, intent(in), optional :: growth(4)\n \n ! value of spline function\n real*8 :: spline4_grid\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: n, j\n real*8 :: xtemp(4)\n \n \n !##### ROUTINE CODE #######################################################\n \n ! calculate number of grid-points\n do j = 1, size(x, 1)\n n = size(c, j)-3\n \n ! invert grid\n if(present(growth))then\n xtemp(j) = grid_Inv_Grow(x(j), left(j), right(j), growth(j), n)\n else\n xtemp(j) = grid_Inv_Equi(x(j), left(j), right(j), n)\n endif\n enddo\n \n ! calculate spline value\n spline4_grid = spline4(xtemp, c)\n \n end function spline4_grid\n \n \n !##############################################################################\n ! FUNCTION spline4_complete\n !\n ! Function for evaluation of one-dimensional spline, includes inverting grid\n ! and interpolation method for a single point.\n !##############################################################################\n function spline4_complete(x, yi, left, right, growth)\n \n \n integer, parameter :: dim = 4\n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! value where to evaluate spline\n real*8, intent(in) :: x(dim)\n \n ! data for spline interpolation\n real*8, intent(in) :: yi(0:, 0:, 0:, 0:)\n \n ! left interval endpoint\n real*8, intent(in) :: left(dim)\n \n ! right interval endpoint\n real*8, intent(in) :: right(dim)\n \n ! growth rate of grid\n real*8, intent(in), optional :: growth(dim)\n \n ! value of spline function\n real*8 :: spline4_complete\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: xtemp(1, dim)\n real*8 :: spline_temp(1)\n \n \n !##### ROUTINE CODE #######################################################\n \n ! set xtemp\n xtemp(1, :) = x\n \n ! invert grid for every evaluation point\n if(present(growth))then\n spline_temp = spline4_complete_m(xtemp, yi, left, right, growth)\n else\n spline_temp = spline4_complete_m(xtemp, yi, left, right)\n endif\n \n ! paste data\n spline4_complete = spline_temp(1)\n \n end function spline4_complete\n \n \n !##############################################################################\n ! FUNCTION spline4_complete_m\n !\n ! Function for evaluation of one-dimensional spline, includes inverting grid\n ! and interpolation method for many points.\n !##############################################################################\n function spline4_complete_m(x, yi, left, right, growth)\n \n integer, parameter :: dim = 4\n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! value where to evaluate spline\n real*8, intent(in) :: x(1:, 1:)\n \n ! data for spline interpolation\n real*8, intent(in) :: yi(0:, 0:, 0:, 0:)\n \n ! left interval endpoint\n real*8, intent(in) :: left(dim)\n \n ! right interval endpoint\n real*8, intent(in) :: right(dim)\n \n ! growth rate of grid\n real*8, intent(in), optional :: growth(dim)\n \n ! value of spline function\n real*8 :: spline4_complete_m(size(x, 1))\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: c(1:size(yi, 1)+2, 1:size(yi, 2)+2, 1:size(yi, 3)+2, &\n 1:size(yi, 4)+2)\n real*8 :: xtemp(1:size(x, 1), dim)\n integer :: n, m, j, k\n \n \n !##### ROUTINE CODE #######################################################\n \n ! calculate number of evaluation points\n m = size(x, 1)\n \n ! check whether x has the right dimension\n n = assert_eq(size(x, 2), dim, 'spline')\n \n ! invert grid for every evaluation point\n if(present(growth))then\n do k = 1, dim\n ! calculate number of grid-points\n n = size(yi, k)-1\n \n xtemp(:, k) = grid_Inv_Grow(x(:, k), &\n left(k), right(k), growth(k), n)\n enddo\n else\n do k = 1, dim\n ! calculate number of grid-points\n n = size(yi, k)-1\n \n xtemp(:, k) = grid_Inv_Equi(x(:, k), left(k), right(k), n)\n enddo\n endif\n \n ! interpolate data\n call spline_interp4(yi, c)\n \n ! calculate spline values at point\n do j = 1, m\n spline4_complete_m(j) = spline4(xtemp(j, :), c)\n enddo\n \n end function spline4_complete_m\n \n \n !##############################################################################\n ! FUNCTION spline5\n !\n ! Function for evaluation of five-dimensional spline.\n !##############################################################################\n function spline5(x, c)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! value where to evaluate spline\n real*8, intent(in) :: x(5)\n \n ! coefficients for spline interpolation\n real*8, intent(in) :: c(1:, 1:, 1:, 1:, 1:)\n \n ! value of spline function\n real*8 :: spline5\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: n, j, p, q\n real*8 :: phi, xtemp\n \n \n !##### ROUTINE CODE #######################################################\n \n ! calculate number of points used\n n = size(c, 1)\n \n ! calculate left and right summation end point\n p = max(floor(x(1))+1, 1)\n q = min(p+3, n)\n \n spline5 = 0d0\n \n do j = p, q\n \n ! calculate value where to evaluate basis function\n xtemp = abs(x(1)-j+2)\n \n ! calculate basis function\n if(xtemp <= 1d0)then\n phi = 4d0+xtemp**2*(3d0*xtemp-6d0)\n elseif(xtemp <= 2d0)then\n phi = (2d0-xtemp)**3\n else\n phi = 0d0\n endif\n \n ! calculate spline value\n spline5 = spline5+spline4(x(2:5), c(j, :, :, :, :))*phi\n enddo\n \n end function spline5\n \n \n !##############################################################################\n ! FUNCTION spline5_grid\n !\n ! Function for evaluation of five-dimensional spline, includes inverting grid.\n !##############################################################################\n function spline5_grid(x, c, left, right, growth)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! value where to evaluate spline\n real*8, intent(in) :: x(5)\n \n ! coefficients for spline interpolation\n real*8, intent(in) :: c(1:, 1:, 1:, 1:, 1:)\n \n ! left interval endpoint\n real*8, intent(in) :: left(5)\n \n ! right interval endpoint\n real*8, intent(in) :: right(5)\n \n ! growth rate of grid\n real*8, intent(in), optional :: growth(5)\n \n ! value of spline function\n real*8 :: spline5_grid\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: n, j\n real*8 :: xtemp(5)\n \n \n !##### ROUTINE CODE #######################################################\n \n ! calculate number of grid-points\n do j = 1, size(x, 1)\n n = size(c, j)-3\n \n ! invert grid\n if(present(growth))then\n xtemp(j) = grid_Inv_Grow(x(j), left(j), right(j), growth(j), n)\n else\n xtemp(j) = grid_Inv_Equi(x(j), left(j), right(j), n)\n endif\n enddo\n \n ! calculate spline value\n spline5_grid = spline5(xtemp, c)\n \n end function spline5_grid\n \n \n !##############################################################################\n ! FUNCTION spline5_complete\n !\n ! Function for evaluation of one-dimensional spline, includes inverting grid\n ! and interpolation method for a single point.\n !##############################################################################\n function spline5_complete(x, yi, left, right, growth)\n \n \n integer, parameter :: dim = 5\n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! value where to evaluate spline\n real*8, intent(in) :: x(dim)\n \n ! data for spline interpolation\n real*8, intent(in) :: yi(0:, 0:, 0:, 0:, 0:)\n \n ! left interval endpoint\n real*8, intent(in) :: left(dim)\n \n ! right interval endpoint\n real*8, intent(in) :: right(dim)\n \n ! growth rate of grid\n real*8, intent(in), optional :: growth(dim)\n \n ! value of spline function\n real*8 :: spline5_complete\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: xtemp(1, dim)\n real*8 :: spline_temp(1)\n \n \n !##### ROUTINE CODE #######################################################\n \n ! set xtemp\n xtemp(1, :) = x\n \n ! invert grid for every evaluation point\n if(present(growth))then\n spline_temp = spline5_complete_m(xtemp, yi, left, right, growth)\n else\n spline_temp = spline5_complete_m(xtemp, yi, left, right)\n endif\n \n ! paste data\n spline5_complete = spline_temp(1)\n \n end function spline5_complete\n \n \n !##############################################################################\n ! FUNCTION spline5_complete_m\n !\n ! Function for evaluation of one-dimensional spline, includes inverting grid\n ! and interpolation method for many points.\n !##############################################################################\n function spline5_complete_m(x, yi, left, right, growth)\n \n integer, parameter :: dim = 5\n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! value where to evaluate spline\n real*8, intent(in) :: x(1:, 1:)\n \n ! data for spline interpolation\n real*8, intent(in) :: yi(0:, 0:, 0:, 0:, 0:)\n \n ! left interval endpoint\n real*8, intent(in) :: left(dim)\n \n ! right interval endpoint\n real*8, intent(in) :: right(dim)\n \n ! growth rate of grid\n real*8, intent(in), optional :: growth(dim)\n \n ! value of spline function\n real*8 :: spline5_complete_m(size(x, 1))\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: c(1:size(yi, 1)+2, 1:size(yi, 2)+2, 1:size(yi, 3)+2, &\n 1:size(yi, 4)+2, 1:size(yi, 5)+2)\n real*8 :: xtemp(1:size(x, 1), dim)\n integer :: n, m, j, k\n \n \n !##### ROUTINE CODE #######################################################\n \n ! calculate number of evaluation points\n m = size(x, 1)\n \n ! check whether x has the right dimension\n n = assert_eq(size(x, 2), dim, 'spline')\n \n ! invert grid for every evaluation point\n if(present(growth))then\n do k = 1, dim\n ! calculate number of grid-points\n n = size(yi, k)-1\n \n xtemp(:, k) = grid_Inv_Grow(x(:, k), &\n left(k), right(k), growth(k), n)\n enddo\n else\n do k = 1, dim\n ! calculate number of grid-points\n n = size(yi, k)-1\n \n xtemp(:, k) = grid_Inv_Equi(x(:, k), left(k), right(k), n)\n enddo\n endif\n \n ! interpolate data\n call spline_interp5(yi, c)\n \n ! calculate spline values at point\n do j = 1, m\n spline5_complete_m(j) = spline5(xtemp(j, :), c)\n enddo\n \n end function spline5_complete_m\n \n \n !##############################################################################\n ! FUNCTION spline6\n !\n ! Function for evaluation of six-dimensional spline.\n !##############################################################################\n function spline6(x, c)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! value where to evaluate spline\n real*8, intent(in) :: x(6)\n \n ! coefficients for spline interpolation\n real*8, intent(in) :: c(1:, 1:, 1:, 1:, 1:, 1:)\n \n ! value of spline function\n real*8 :: spline6\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: n, j, p, q\n real*8 :: phi, xtemp\n \n \n !##### ROUTINE CODE #######################################################\n \n ! calculate number of points used\n n = size(c, 1)\n \n ! calculate left and right summation end point\n p = max(floor(x(1))+1, 1)\n q = min(p+3, n)\n \n spline6 = 0d0\n \n do j = p, q\n \n ! calculate value where to evaluate basis function\n xtemp = abs(x(1)-j+2)\n \n ! calculate basis function\n if(xtemp <= 1d0)then\n phi = 4d0+xtemp**2*(3d0*xtemp-6d0)\n elseif(xtemp <= 2d0)then\n phi = (2d0-xtemp)**3\n else\n phi = 0d0\n endif\n \n ! calculate spline value\n spline6 = spline6+spline5(x(2:6), c(j, :, :, :, :, :))*phi\n enddo\n \n end function spline6\n \n \n !##############################################################################\n ! FUNCTION spline6_grid\n !\n ! Function for evaluation of six-dimensional spline, includes inverting grid.\n !##############################################################################\n function spline6_grid(x, c, left, right, growth)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! value where to evaluate spline\n real*8, intent(in) :: x(6)\n \n ! coefficients for spline interpolation\n real*8, intent(in) :: c(1:, 1:, 1:, 1:, 1:, 1:)\n \n ! left interval endpoint\n real*8, intent(in) :: left(6)\n \n ! right interval endpoint\n real*8, intent(in) :: right(6)\n \n ! growth rate of grid\n real*8, intent(in), optional :: growth(6)\n \n ! value of spline function\n real*8 :: spline6_grid\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: n, j\n real*8 :: xtemp(6)\n \n \n !##### ROUTINE CODE #######################################################\n \n ! calculate number of grid-points\n do j = 1, size(x, 1)\n n = size(c, j)-3\n \n ! invert grid\n if(present(growth))then\n xtemp(j) = grid_Inv_Grow(x(j), left(j), right(j), growth(j), n)\n else\n xtemp(j) = grid_Inv_Equi(x(j), left(j), right(j), n)\n endif\n enddo\n \n ! calculate spline value\n spline6_grid = spline6(xtemp, c)\n \n end function spline6_grid\n \n \n !##############################################################################\n ! FUNCTION spline6_complete\n !\n ! Function for evaluation of one-dimensional spline, includes inverting grid\n ! and interpolation method for a single point.\n !##############################################################################\n function spline6_complete(x, yi, left, right, growth)\n \n \n integer, parameter :: dim = 6\n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! value where to evaluate spline\n real*8, intent(in) :: x(dim)\n \n ! data for spline interpolation\n real*8, intent(in) :: yi(0:, 0:, 0:, 0:, 0:, 0:)\n \n ! left interval endpoint\n real*8, intent(in) :: left(dim)\n \n ! right interval endpoint\n real*8, intent(in) :: right(dim)\n \n ! growth rate of grid\n real*8, intent(in), optional :: growth(dim)\n \n ! value of spline function\n real*8 :: spline6_complete\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: xtemp(1, dim)\n real*8 :: spline_temp(1)\n \n \n !##### ROUTINE CODE #######################################################\n \n ! set xtemp\n xtemp(1, :) = x\n \n ! invert grid for every evaluation point\n if(present(growth))then\n spline_temp = spline6_complete_m(xtemp, yi, left, right, growth)\n else\n spline_temp = spline6_complete_m(xtemp, yi, left, right)\n endif\n \n ! paste data\n spline6_complete = spline_temp(1)\n \n end function spline6_complete\n \n \n !##############################################################################\n ! FUNCTION spline6_complete_m\n !\n ! Function for evaluation of one-dimensional spline, includes inverting grid\n ! and interpolation method for many points.\n !##############################################################################\n function spline6_complete_m(x, yi, left, right, growth)\n \n integer, parameter :: dim = 6\n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! value where to evaluate spline\n real*8, intent(in) :: x(1:, 1:)\n \n ! data for spline interpolation\n real*8, intent(in) :: yi(0:, 0:, 0:, 0:, 0:, 0:)\n \n ! left interval endpoint\n real*8, intent(in) :: left(dim)\n \n ! right interval endpoint\n real*8, intent(in) :: right(dim)\n \n ! growth rate of grid\n real*8, intent(in), optional :: growth(dim)\n \n ! value of spline function\n real*8 :: spline6_complete_m(size(x, 1))\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: c(1:size(yi, 1)+2, 1:size(yi, 2)+2, 1:size(yi, 3)+2, &\n 1:size(yi, 4)+2, 1:size(yi, 5)+2, 1:size(yi, 6)+2)\n real*8 :: xtemp(1:size(x, 1), dim)\n integer :: n, m, j, k\n \n \n !##### ROUTINE CODE #######################################################\n \n ! calculate number of evaluation points\n m = size(x, 1)\n \n ! check whether x has the right dimension\n n = assert_eq(size(x, 2), dim, 'spline')\n \n ! invert grid for every evaluation point\n if(present(growth))then\n do k = 1, dim\n ! calculate number of grid-points\n n = size(yi, k)-1\n \n xtemp(:, k) = grid_Inv_Grow(x(:, k), &\n left(k), right(k), growth(k), n)\n enddo\n else\n do k = 1, dim\n ! calculate number of grid-points\n n = size(yi, k)-1\n \n xtemp(:, k) = grid_Inv_Equi(x(:, k), left(k), right(k), n)\n enddo\n endif\n \n ! interpolate data\n call spline_interp6(yi, c)\n \n ! calculate spline values at point\n do j = 1, m\n spline6_complete_m(j) = spline6(xtemp(j, :), c)\n enddo\n \n end function spline6_complete_m\n \n \n !##############################################################################\n ! FUNCTION spline7\n !\n ! Function for evaluation of seven-dimensional spline.\n !##############################################################################\n function spline7(x, c)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! value where to evaluate spline\n real*8, intent(in) :: x(7)\n \n ! coefficients for spline interpolation\n real*8, intent(in) :: c(1:, 1:, 1:, 1:, 1:, 1:, 1:)\n \n ! value of spline function\n real*8 :: spline7\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: n, j, p, q\n real*8 :: phi, xtemp\n \n \n !##### ROUTINE CODE #######################################################\n \n ! calculate number of points used\n n = size(c, 1)\n \n ! calculate left and right summation end point\n p = max(floor(x(1))+1, 1)\n q = min(p+3, n)\n \n spline7 = 0d0\n \n do j = p, q\n \n ! calculate value where to evaluate basis function\n xtemp = abs(x(1)-j+2)\n \n ! calculate basis function\n if(xtemp <= 1d0)then\n phi = 4d0+xtemp**2*(3d0*xtemp-6d0)\n elseif(xtemp <= 2d0)then\n phi = (2d0-xtemp)**3\n else\n phi = 0d0\n endif\n \n ! calculate spline value\n spline7 = spline7+spline6(x(2:7), c(j, :, :, :, :, :, :))*phi\n enddo\n \n end function spline7\n \n \n !##############################################################################\n ! FUNCTION spline7_grid\n !\n ! Function for evaluation of seven-dimensional spline, includes inverting grid.\n !##############################################################################\n function spline7_grid(x, c, left, right, growth)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! value where to evaluate spline\n real*8, intent(in) :: x(7)\n \n ! coefficients for spline interpolation\n real*8, intent(in) :: c(1:, 1:, 1:, 1:, 1:, 1:, 1:)\n \n ! left interval endpoint\n real*8, intent(in) :: left(7)\n \n ! right interval endpoint\n real*8, intent(in) :: right(7)\n \n ! growth rate of grid\n real*8, intent(in), optional :: growth(7)\n \n ! value of spline function\n real*8 :: spline7_grid\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: n, j\n real*8 :: xtemp(7)\n \n \n !##### ROUTINE CODE #######################################################\n \n ! calculate number of grid-points\n do j = 1, size(x, 1)\n n = size(c, j)-3\n \n ! invert grid\n if(present(growth))then\n xtemp(j) = grid_Inv_Grow(x(j), left(j), right(j), growth(j), n)\n else\n xtemp(j) = grid_Inv_Equi(x(j), left(j), right(j), n)\n endif\n enddo\n \n ! calculate spline value\n spline7_grid = spline7(xtemp, c)\n \n end function spline7_grid\n \n \n !##############################################################################\n ! FUNCTION spline7_complete\n !\n ! Function for evaluation of one-dimensional spline, includes inverting grid\n ! and interpolation method for a single point.\n !##############################################################################\n function spline7_complete(x, yi, left, right, growth)\n \n \n integer, parameter :: dim = 7\n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! value where to evaluate spline\n real*8, intent(in) :: x(dim)\n \n ! data for spline interpolation\n real*8, intent(in) :: yi(0:, 0:, 0:, 0:, 0:, 0:, 0:)\n \n ! left interval endpoint\n real*8, intent(in) :: left(dim)\n \n ! right interval endpoint\n real*8, intent(in) :: right(dim)\n \n ! growth rate of grid\n real*8, intent(in), optional :: growth(dim)\n \n ! value of spline function\n real*8 :: spline7_complete\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: xtemp(1, dim)\n real*8 :: spline_temp(1)\n \n \n !##### ROUTINE CODE #######################################################\n \n ! set xtemp\n xtemp(1, :) = x\n \n ! invert grid for every evaluation point\n if(present(growth))then\n spline_temp = spline7_complete_m(xtemp, yi, left, right, growth)\n else\n spline_temp = spline7_complete_m(xtemp, yi, left, right)\n endif\n \n ! paste data\n spline7_complete = spline_temp(1)\n \n end function spline7_complete\n \n \n !##############################################################################\n ! FUNCTION spline7_complete_m\n !\n ! Function for evaluation of one-dimensional spline, includes inverting grid\n ! and interpolation method for many points.\n !##############################################################################\n function spline7_complete_m(x, yi, left, right, growth)\n \n integer, parameter :: dim = 7\n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! value where to evaluate spline\n real*8, intent(in) :: x(1:, 1:)\n \n ! data for spline interpolation\n real*8, intent(in) :: yi(0:, 0:, 0:, 0:, 0:, 0:, 0:)\n \n ! left interval endpoint\n real*8, intent(in) :: left(dim)\n \n ! right interval endpoint\n real*8, intent(in) :: right(dim)\n \n ! growth rate of grid\n real*8, intent(in), optional :: growth(dim)\n \n ! value of spline function\n real*8 :: spline7_complete_m(size(x, 1))\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: c(1:size(yi, 1)+2, 1:size(yi, 2)+2, 1:size(yi, 3)+2, &\n 1:size(yi, 4)+2, 1:size(yi, 5)+2, 1:size(yi, 6)+2, 1:size(yi, 7)+2)\n real*8 :: xtemp(1:size(x, 1), dim)\n integer :: n, m, j, k\n \n \n !##### ROUTINE CODE #######################################################\n \n ! calculate number of evaluation points\n m = size(x, 1)\n \n ! check whether x has the right dimension\n n = assert_eq(size(x, 2), dim, 'spline')\n \n ! invert grid for every evaluation point\n if(present(growth))then\n do k = 1, dim\n ! calculate number of grid-points\n n = size(yi, k)-1\n \n xtemp(:, k) = grid_Inv_Grow(x(:, k), &\n left(k), right(k), growth(k), n)\n enddo\n else\n do k = 1, dim\n ! calculate number of grid-points\n n = size(yi, k)-1\n \n xtemp(:, k) = grid_Inv_Equi(x(:, k), left(k), right(k), n)\n enddo\n endif\n \n ! interpolate data\n call spline_interp7(yi, c)\n \n ! calculate spline values at point\n do j = 1, m\n spline7_complete_m(j) = spline7(xtemp(j, :), c)\n enddo\n \n end function spline7_complete_m\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n!##############################################################################\n!##############################################################################\n! MODULE gaussian_int\n!##############################################################################\n!##############################################################################\n\n\n !##############################################################################\n ! SUBROUTINE legendre\n !\n ! Calculates Gauss-Legendre abscissas and weights on [x1, x2].\n !\n ! PARTS OF THIS PROCEDURE WERE COPIED AND ADAPTED FROM:\n ! Press, W.H., Teukolsky, S.A., Vetterling, W.T. & Flannery, B.P. (1992). \n ! Numerical Recipes in Fortran 90: The Art of Parallel Scientific\n ! Computing, 2nd edition. Cambridge: Cambridge University Press.\n !##############################################################################\n subroutine legendre(x1, x2, x, w)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! left interval point on which integral should be calculated\n real*8, intent(in) :: x1\n \n ! left interval point on which integral should be calculated\n real*8, intent(in) :: x2\n \n ! abscissas of gaussian integration formula\n real*8, intent(out) :: x(:)\n \n ! weights of gaussian integration formula\n real*8, intent(out) :: w(:)\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8, parameter :: eps = 3.0e-14\n integer, parameter :: maxits = 10\n real*8, parameter :: pi = 3.14159265358979d0\n integer :: its, j, m, n\n real*8 :: xl, xm\n real*8, dimension((size(x)+1)/2) :: p1, p2, p3, pp, z, z1\n logical, dimension((size(x)+1)/2) :: unfinished\n \n \n !##### ROUTINE CODE #######################################################\n \n ! assert size equality\n n = assert_eq(size(x), size(w), 'legendre')\n \n ! calculate only up to (n+1)/2 due to symmetry\n m = (n+1)/2\n \n ! calculate interval midpoint\n xm = 0.5d0*(x2+x1)\n \n ! calculate half of interval length\n xl = 0.5d0*(x2-x1)\n \n ! set initial guess for the roots\n z = cos(pi*(arth(1,1,m)-0.25d0)/(n+0.5d0))\n \n ! initialized unfinished\n unfinished = .true.\n \n ! iterate Newton steps up to maximum iterations\n do its = 1, maxits\n \n ! calculate Legendre polynomial at z where root has not yet been found\n \n ! initialize p1 and p2\n where (unfinished)\n p1 = 1d0\n p2 = 0d0\n endwhere\n \n ! calculate polynomial value at z by recursive formula\n do j = 1, n\n \n ! only where root has not yet been found\n where (unfinished)\n \n ! the polynomial of order n - 2\n p3 = p2\n \n ! the polynomial of order n - 1\n p2 = p1\n \n ! the legendre polynomial\n p1 = ((2d0*j-1d0)*z*p2-(j-1d0)*p3)/j\n endwhere\n enddo\n \n ! calculate derivative of polynomial p1 at z\n where (unfinished)\n \n ! derivative\n pp = n*(z*p1-p2)/(z*z-1d0)\n \n ! store old z\n z1 = z\n \n ! perform the newton step\n z = z1-p1/pp\n \n ! check for difference between old and new guess being small enough\n unfinished=(abs(z-z1) > EPS)\n endwhere\n \n ! if all values have sufficiently converged, stop iteration\n if (.not. any(unfinished)) exit\n end do\n \n ! throw error message if not sufficiently convergerd\n if(its == maxits+1)call error('legendre', 'too many iterations')\n \n ! else calculate abscissas\n x(1:m) = xm-xl*z\n \n ! symmetry for abscissas\n x(n:n-m+1:-1) = xm+xl*z\n \n ! calculate weights\n w(1:m) = 2d0*xl/((1d0-z**2)*pp**2)\n \n ! symmetry for weights\n w(n:n-m+1:-1) = w(1:m)\n \n end subroutine legendre\n \n \n !##############################################################################\n ! FUNCTION arth\n !\n ! Calculates incremented array from first with n entries.\n !##############################################################################\n function arth(first, increment, n)\n \n integer, intent(in) :: first, increment, n\n integer, parameter :: npar_arth = 16\n integer, parameter :: npar2_arth = 8\n integer :: arth(n)\n integer :: k, k2, temp\n \n ! initialize first element\n if(n > 0)arth(1) = first\n \n ! calculate by hand if n <= 16\n if(n <= npar_arth) then\n do k = 2, n\n arth(k) = arth(k-1) + increment\n enddo\n \n ! else set entries stepwise by 8 steps\n else\n do k = 2, npar2_arth\n arth(k) = arth(k-1) + increment\n enddo\n temp = increment*npar2_arth\n k = npar2_arth\n do\n if(k >= n)exit\n k2 = k+k\n arth(k+1:min(k2,n)) = temp+arth(1:min(k,n-k))\n temp = temp + temp\n k = k2\n enddo\n endif\n \n end function arth\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n!##############################################################################\n!##############################################################################\n! MODULE AR_discrete\n!##############################################################################\n!##############################################################################\n\n\n !##############################################################################\n ! SUBROUTINE discretize_AR\n !\n ! Discretizes an AR(1) process of the form z_j = \\rho*z_{j-1} + eps using\n ! the Rouwenhorst method.\n !\n ! REFERENCE: Kopecky, K.A., Suen, R.M.H., Finite state Markov-chain \n ! approximations to highly persistent processes, Review of Economic\n ! Dynamics, Vol. 13, No. 3, 2010, 701-714.\n !##############################################################################\n subroutine discretize_AR(rho, mu, sigma_eps, z, pi, w)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! autoregression parameter\n real*8, intent(in) :: rho\n \n ! unconditional mean of the process\n real*8, intent(in) :: mu\n \n ! variance of the shock\n real*8, intent(in) :: sigma_eps\n \n ! discrete shock values\n real*8, intent(out) :: z(:)\n \n ! transition matrix\n real*8, intent(out) :: pi(:, :)\n \n ! the stationary distribution\n real*8, intent(out), optional :: w(:)\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: n, in\n real*8 :: psi, sigma_eta\n \n \n !##### ROUTINE CODE #######################################################\n \n ! assert size equality and get approximation points\n n = assert_eq(size(z), size(pi,1), size(pi,2), 'discretize_AR')\n \n ! calculate variance of the overall process\n sigma_eta = sigma_eps/(1d0-rho**2)\n \n ! determine the transition matrix\n call rouwenhorst_matrix(rho, pi)\n \n ! determine the nodes\n psi = sqrt(dble(n-1))*sqrt(sigma_eta)\n do in = 1, n\n z(in) = -psi + 2d0*psi*dble(in-1)/dble(n-1)\n enddo\n z = z + mu\n \n if(present(w))then\n w = 1d0/dble(n)\n do in = 1, 10000\n w = matmul(transpose(pi), w)\n enddo\n endif\n \n !##########################################################################\n ! Subroutines and functions\n !##########################################################################\n \n contains\n \n \n !##########################################################################\n ! subroutine rouwenhorst_matrix\n !\n ! Calculates value of function that should be integrated for pis.\n !##########################################################################\n recursive subroutine rouwenhorst_matrix(rho, pi_new)\n \n implicit none\n real*8, intent(in) :: rho\n real*8, intent(out) :: pi_new(:, :)\n integer :: n\n real*8 :: p, pi_old(size(pi_new,1)-1, size(pi_new,1)-1)\n \n n = size(pi_new, 1)\n p = (1d0 + rho)/2d0\n \n if(n == 2)then\n pi_new(1, :) = (/p, 1d0-p/)\n pi_new(2, :) = (/1d0-p, p/)\n else\n call rouwenhorst_matrix(rho, pi_old)\n pi_new = 0d0\n \n pi_new(1:n-1, 1:n-1) = pi_new(1:n-1, 1:n-1) + p*pi_old\n pi_new(1:n-1, 2:n ) = pi_new(1:n-1, 2:n ) + (1d0-p)*pi_old\n pi_new(2:n , 1:n-1) = pi_new(2:n , 1:n-1) + (1d0-p)*pi_old\n pi_new(2:n , 2:n ) = pi_new(2:n , 2:n ) + p*pi_old\n \n pi_new(2:n-1, :) = pi_new(2:n-1, :)/2d0\n endif\n end subroutine\n \n end subroutine discretize_AR\n\n\n !##############################################################################\n ! SUBROUTINE discretize_log_AR\n !\n ! Discretizes a log-AR(1) process using the Rouwenhorst method.\n !\n ! REFERENCE: Kopecky, K.A., Suen, R.M.H., Finite state Markov-chain \n ! approximations to highly persistent processes, Review of Economic\n ! Dynamics, Vol. 13, No. 3, 2010, 701-714.\n !##############################################################################\n subroutine discretize_log_AR(rho, mu, sigma_eps, z, pi, w)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! autoregression parameter\n real*8, intent(in) :: rho\n \n ! unconditional mean of the process\n real*8, intent(in) :: mu\n \n ! variance of the shock\n real*8, intent(in) :: sigma_eps\n \n ! discrete shock values\n real*8, intent(out) :: z(:)\n \n ! transition matrix\n real*8, intent(out) :: pi(:, :)\n \n ! the stationary distribution\n real*8, intent(out), optional :: w(:)\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: sigma_eta, mu_c, sigma_c\n \n \n !##### ROUTINE CODE #######################################################\n\n ! calculate variance of the overall process\n sigma_eta = sigma_eps/(1d0-rho**2)\n \n ! get the transformed variance and expectation\n sigma_c = log(1d0+sigma_eta/mu**2)\n mu_c = log(mu)-0.5d0*sigma_c\n sigma_c = sigma_c*(1d0-rho**2)\n\n ! discretize the log distribution\n if(present(w))then\n call discretize_AR(rho, mu_c, sigma_c, z, pi, w)\n else\n call discretize_AR(rho, mu_c, sigma_c, z, pi)\n endif\n\n ! take exponentials\n z = exp(z)\n \n end subroutine discretize_log_AR\n \n \n !##############################################################################\n ! SUBROUTINE simulate_AR\n !\n ! Simulates a discrete AR(1) process.\n !##############################################################################\n subroutine simulate_AR(pi, shocks, fixed)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! transition matrix\n real*8, intent(in) :: pi(:, :)\n \n ! simulated schocks\n integer, intent(out) :: shocks(:)\n \n ! should the random seed be initialized at a fixed values\n logical, optional :: fixed\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: T, n, j\n \n \n !##### ROUTINE CODE #######################################################\n \n ! assert size equality and get number of simulated schocks\n n = assert_eq(size(pi,1), size(pi,2), 'tauchen')\n T = size(shocks)\n \n ! initialize the random seed\n if(tbox_seed)then\n if(present(fixed))then\n call init_random_seed(fixed)\n else\n call init_random_seed()\n endif\n tbox_seed = .false.\n endif\n \n ! get first entry\n shocks(1) = n/2+1\n \n ! now calculate other shocks\n do j = 2, T\n shocks(j) = get_tomorrow(pi(shocks(j-1), :))\n enddo\n \n \n !##########################################################################\n ! Subroutines and functions\n !##########################################################################\n \n contains\n \n \n !##########################################################################\n ! FUNCTION get_tomorrow\n !\n ! Calculates value of function that should be integrated for pis.\n !##########################################################################\n function get_tomorrow(pi)\n \n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #########################################\n \n ! transition probabilities\n real*8, intent(in) :: pi(:)\n \n ! tomorrows shock\n integer :: get_tomorrow\n \n \n !##### OTHER VARIABLES ################################################\n \n real*8 :: rand\n integer :: i1\n \n \n !##### ROUTINE CODE ###################################################\n \n ! get random number\n call random_number(rand)\n \n ! get tomorrows value\n do i1 = 1, size(pi, 1)-1\n \n if(rand <= sum(pi(1:i1), 1))then\n get_tomorrow = i1\n return\n endif\n enddo\n \n ! else choose last value\n get_tomorrow = i1\n return\n \n end function\n \n end subroutine simulate_AR\n\n\n\n\n\n\n\n\n\n\n\n\n!##############################################################################\n!##############################################################################\n! MODULE gnuplot\n!##############################################################################\n!############################################################################## \n\n\n !##############################################################################\n ! SUBROUTINE execplot\n !\n ! Actually creates the plot files.\n !##############################################################################\n subroutine execplot(xlim, xticks, xlabel, ylim, yticks, ylabel, title, &\n legend, filename, filetype, output)\n\n implicit none\n\n\n !##### INPUT/OUTPUT VARIABLES #############################################\n\n ! x axis definitial\n real*8, optional :: xlim(2)\n\n ! x axis tick definitions\n real*8, optional :: xticks\n\n ! y axis definitial\n real*8, optional :: ylim(2)\n\n ! y axis tick definitions\n real*8, optional :: yticks\n\n ! output file name\n character(LEN=*), optional :: title\n\n ! output file name\n character(LEN=*), optional :: xlabel\n\n ! output file name\n character(LEN=*), optional :: ylabel\n\n ! legend position\n character(LEN=2), optional :: legend\n\n ! output file name\n character(LEN=*), optional :: filename\n\n ! file type\n character(LEN=*), optional :: filetype\n\n ! output file name\n character(LEN=*), optional :: output\n\n !##### OTHER VARIABLES ####################################################\n \n integer :: i1, i2\n character(LEN=3) :: ft\n character(LEN=150) :: cfile, dfile\n \n \n !##### ROUTINE CODE #######################################################\n\n if(present(output))then\n cfile = output//'_c.dat'\n dfile = output//'_d.dat'\n else\n cfile = 'command13545431.dat'\n dfile = 'plotdata13545431.dat'\n endif\n\n ! write the output data file\n open(213659,file=trim(dfile))\n do i1 = 1, gnu_nmax\n write(213659, '(2000e21.10e4)')(gnu_x(i1, i2), gnu_y(i1, i2), i2=1, gnu_mmax)\n enddo\n close(213659)\n\n ! write the command file\n open(213659,file=trim(cfile))\n\n ! set terminal and grid\n write(213659, '(a)')'if (strstrt(GPVAL_TERMINALS, \"wxt\") > 0) {'\n write(213659, '(a)')' set terminal wxt title \"Gnuplot\"'\n write(213659, '(a)')'} else {'\n write(213659, '(a)')' if (strstrt(GPVAL_TERMINALS, \"x11\") > 0) {'\n write(213659, '(a)')' set terminal x11'\n write(213659, '(a)')' } else {'\n write(213659, '(a)')' if (strstrt(GPVAL_TERMINALS, \"qt\") > 0) {'\n write(213659, '(a)')' set terminal qt'\n write(213659, '(a)')' } else {'\n write(213659, '(a)')' print \"\"'\n write(213659, '(a)')' print \"ATTENTION: There seems to be NO VALID TERMINAL installed in \"'\n write(213659, '(a)')' print \" your version of gnuplot. It might be a good idea to \"'\n write(213659, '(a)')' print \" completely uninstall your Fortran/gnuplot/geany installation\"'\n write(213659, '(a)')' print \" using the uninstallation files on www.ce-fortran.com. \"'\n write(213659, '(a)')' print \" Afterwards you should reinstall the Fortran system again.\"'\n write(213659, '(a)')' print \" If this does not help, please refer to the forum.\"'\n write(213659, '(a)')' print \"\"'\n write(213659, '(a)')' q'\n write(213659, '(a)')' }'\n write(213659, '(a)')' }'\n write(213659, '(a)')'}'\n write(213659, '(a)')'set grid'\n if(gnu_histogram)then\n write(213659, '(a)')'set style data histograms'\n write(213659, '(a)')'set style fill solid border -1'\n endif\n \n ! set x axis\n if(present(xlim))write(213659, '(a,e13.5,a,e13.5,a)')'set xrange [',minval(xlim),':',maxval(xlim),']'\n if(present(xticks))write(213659, '(a,e13.5)')'set xtics ',xticks \n if(present(xlabel))write(213659, '(a)')'set xlabel \"'//xlabel//'\"font \",12\"'\n \n ! set y axis\n if(present(ylim) .and. .not. gnu_histogram) &\n write(213659, '(a,e13.5,a,e13.5,a)')'set yrange [',minval(ylim),':',maxval(ylim),']'\n if(gnu_histogram)then\n if(present(ylim))then\n write(213659, '(a,e13.5,a,e13.5,a)') &\n 'set yrange [',min(minval(ylim),0d0),':',maxval(ylim),']'\n else\n write(213659, '(a)') 'set yrange [0:]'\n endif\n endif\n \n if(present(yticks))write(213659, '(a,e13.5)')'set ytics ',yticks \n if(present(ylabel))write(213659, '(a)')'set ylabel \"'//ylabel//'\"font \",12\"'\n\n ! set title\n if(present(title))write(213659, '(a)')'set title \"'//title//'\" font \",16\"'\n \n ! legend statement\n if(gnu_dolegend)then\n if(present(legend))then \n select case (legend(1:2))\n case(\"ln\")\n write(213659, '(a)')'set key inside left top'\n case(\"ls\")\n write(213659, '(a)')'set key inside left bottom'\n case(\"lo\")\n write(213659, '(a)')'set key outside vert center left'\n case(\"lb\")\n write(213659, '(a)')'set key outside left below'\n case(\"rn\")\n write(213659, '(a)')'set key inside right top'\n case(\"rs\")\n write(213659, '(a)')'set key inside right bottom'\n case(\"ro\")\n write(213659, '(a)')'set key outside vert center right'\n case(\"rb\")\n write(213659, '(a)')'set key outside right below'\n case(\"cn\")\n write(213659, '(a)')'set key inside center top'\n case(\"cs\")\n write(213659, '(a)')'set key inside center bottom'\n case(\"co\")\n write(213659, '(a)')'set key outside vert top center'\n case(\"cb\")\n write(213659, '(a)')'set key outside center below'\n case default\n write(213659, '(a)')'set key outside vert bottom center'\n end select\n else\n write(213659, '(a)')'set key center below'\n endif \n else\n write(213659, '(a)')'unset key'\n endif\n\n ! write plot lines\n if(gnu_mmax == 1)then\n write(213659, '(a)')'plot \"'//trim(dfile)//'\" using 1:2 '//trim(gnu_definitions(1))\n else\n write(213659, '(a)')'plot \"'//trim(dfile)//'\" using 1:2 '//trim(gnu_definitions(1))//',\\' \n do i1 = 2, gnu_mmax-1\n write(213659, '(a,i4,a,i4,a)')' \"'//trim(dfile)//'\" using '&\n ,2*(i1-1)+1,':',2*(i1-1)+2,' '//trim(gnu_definitions(i1))//',\\' \n enddo\n write(213659, '(a,i4,a,i4,a)')' \"'//trim(dfile)//'\" using ', &\n 2*(gnu_mmax-1)+1,':',2*(gnu_mmax-1)+2,' '//trim(gnu_definitions(i1))\n endif\n \n write(213659, '(a)')'pause -1 \"Press RETURN to continue...\"'\n\n ! write graph to file\n if(present(filename))then\n ft = \"eps\"\n if(present(filetype))then\n if(filetype(1:3) == \"png\")ft= \"png\"\n endif\n write(213659, *)\n write(213659, '(a)')'set terminal '//ft\n write(213659, '(a)')'set output \"'//filename//'.'//ft//'\"'\n write(213659, '(a)')'replot'\n endif\n \n write(213659, '(a)')'q'\n close(213659)\n \n call system('gnuplot \"'//trim(cfile)//'\"') \n if(.not.present(output))then\n open(213659,file=trim(dfile))\n close(213659, status='delete')\n open(213659,file=trim(cfile))\n close(213659, status='delete')\n endif\n\n gnu_addtoplot = .false.\n gnu_dolegend = .false.\n gnu_histogram = .false.\n\n end subroutine\n\n \n !##############################################################################\n ! SUBROUTINE plot\n !\n ! Plots a x-y-data column to the output file.\n !##############################################################################\n subroutine plot(xin, yin, color, linewidth, marker, markersize, noline, legend)\n\n implicit none\n\n\n !##### INPUT/OUTPUT VARIABLES #############################################\n \n real*8, intent(in) :: xin(:), yin(:)\n character(LEN=*), optional :: color\n real*8, optional :: linewidth\n integer, optional :: marker\n real*8, optional :: markersize\n logical, optional :: noline\n character(LEN=*), optional :: legend\n\n\n !##### OTHER VARIABLES ####################################################\n \n integer :: n, i1\n logical :: lines, points\n \n \n !##### ROUTINE CODE #######################################################\n\n n = assert_eq(size(xin, 1), size(yin, 1), 'plot')\n\n ! generate the respective plot data\n if(.not.gnu_addtoplot)then\n\n ! allocate new x array\n if(allocated(gnu_x))deallocate(gnu_x)\n allocate(gnu_x(n, 1))\n gnu_x(:, 1) = xin \n\n ! allocate new y array\n if(allocated(gnu_y))deallocate(gnu_y)\n allocate(gnu_y(n, 1))\n gnu_y(:, 1) = yin \n\n ! allocate new x_temp array\n if(allocated(gnu_x_temp))deallocate(gnu_x_temp)\n allocate(gnu_x_temp(n, 1))\n gnu_x_temp(:, 1) = xin \n\n ! allocate new y_temp array\n if(allocated(gnu_y_temp))deallocate(gnu_y_temp)\n allocate(gnu_y_temp(n, 1))\n gnu_y_temp(:, 1) = yin\n\n gnu_addtoplot = .true.\n gnu_nmax = n\n gnu_mmax = 1\n\n else\n \n ! get new number of lines\n gnu_mmax = gnu_mmax+1\n if(gnu_mmax > 1000)then\n write(*,'(/a/)')'SORRY: I CANNOT PLOT MORE THAN 1000 LINES'\n return\n endif\n\n ! deallocate arrays\n deallocate(gnu_x)\n deallocate(gnu_y)\n \n ! if the new array is the longer one\n if(n > gnu_nmax)then\n allocate(gnu_x(n, gnu_mmax))\n allocate(gnu_y(n, gnu_mmax))\n\n gnu_x(1:gnu_nmax, 1:gnu_mmax-1) = gnu_x_temp \n gnu_y(1:gnu_nmax, 1:gnu_mmax-1) = gnu_y_temp\n\n ! fill up with the same values\n do i1 = gnu_nmax+1, n\n gnu_x(i1, 1:gnu_mmax-1) = gnu_x(gnu_nmax, 1:gnu_mmax-1)\n gnu_y(i1, 1:gnu_mmax-1) = gnu_y(gnu_nmax, 1:gnu_mmax-1)\n enddo\n\n gnu_x(:, gnu_mmax) = xin\n gnu_y(:, gnu_mmax) = yin\n\n ! set new nmax\n gnu_nmax = n\n\n ! if the old array is the longer one\n else\n\n allocate(gnu_x(gnu_nmax, gnu_mmax))\n allocate(gnu_y(gnu_nmax, gnu_mmax))\n\n gnu_x(:, 1:gnu_mmax-1) = gnu_x_temp \n gnu_y(:, 1:gnu_mmax-1) = gnu_y_temp \n\n gnu_x(1:n, gnu_mmax) = xin\n gnu_y(1:n, gnu_mmax) = yin\n\n ! fill up with same values\n do i1 = n+1, gnu_nmax\n gnu_x(i1, gnu_mmax) = gnu_x(n, gnu_mmax)\n gnu_y(i1, gnu_mmax) = gnu_y(n, gnu_mmax)\n enddo \n endif\n\n deallocate(gnu_x_temp)\n allocate(gnu_x_temp(size(gnu_x,1), size(gnu_x,2)))\n gnu_x_temp = gnu_x\n\n deallocate(gnu_y_temp)\n allocate(gnu_y_temp(size(gnu_y,1), size(gnu_y,2)))\n gnu_y_temp = gnu_y\n \n endif\n\n ! check for lines and points\n lines = .true.\n if(present(noline))then\n if(noline)lines = .false.\n endif\n\n if(.not.lines)then\n points = .true.\n else\n points = .false.\n endif\n if(present(marker))points = .true.\n\n ! set up definitions\n gnu_definitions(gnu_mmax) = 'with'\n\n ! get lines and points\n if(lines .and. points)then\n gnu_definitions(gnu_mmax) = trim(gnu_definitions(gnu_mmax))//' linespoints'\n elseif(lines)then\n gnu_definitions(gnu_mmax) = trim(gnu_definitions(gnu_mmax))//' lines'\n else\n gnu_definitions(gnu_mmax) = trim(gnu_definitions(gnu_mmax))//' points'\n endif\n\n ! get the line color\n if(present(color))then\n gnu_definitions(gnu_mmax) = trim(gnu_definitions(gnu_mmax))//' lc rgb \"'//adjustl(trim(color))//'\"'\n else\n if(gnu_mmax == 1)then\n gnu_definitions(gnu_mmax) = trim(gnu_definitions(gnu_mmax))//' lc rgb \"blue\"'\n else\n write(gnu_definitions(gnu_mmax), '(a,i4)')trim(gnu_definitions(gnu_mmax))//' lc ', gnu_mmax-1\n endif\n endif \n\n ! get line width\n if(lines)then\n if(present(linewidth)) then\n write(gnu_definitions(gnu_mmax), '(a,f8.2)')trim(gnu_definitions(gnu_mmax))//' lw ', max(linewidth, 0d0)\n else\n write(gnu_definitions(gnu_mmax), '(a,f8.2)')trim(gnu_definitions(gnu_mmax))//' lw ', 2d0\n endif\n endif\n\n ! get marker definition\n if(points)then\n \n if(present(marker)) then\n write(gnu_definitions(gnu_mmax), '(a,i2)')trim(gnu_definitions(gnu_mmax))//' pt ', min(marker, 13)\n else\n write(gnu_definitions(gnu_mmax), '(a,i2)')trim(gnu_definitions(gnu_mmax))//' pt ', 1\n endif\n\n if(present(markersize))then\n write(gnu_definitions(gnu_mmax), '(a,f8.2)')trim(gnu_definitions(gnu_mmax))//' ps ', max(markersize, 0d0)\n else\n write(gnu_definitions(gnu_mmax), '(a,f8.2)')trim(gnu_definitions(gnu_mmax))//' ps ', 1d0\n endif\n endif \n\n ! set the legend\n if(present(legend))then\n gnu_dolegend = .true.\n gnu_definitions(gnu_mmax) = trim(gnu_definitions(gnu_mmax))//' title \"'//adjustl(trim(legend))//'\"'\n else\n gnu_definitions(gnu_mmax) = trim(gnu_definitions(gnu_mmax))//' notitle '\n endif\n\n end subroutine\n\n\n !##############################################################################\n ! SUBROUTINE plot_hist_old\n !\n ! Plots a histogram.\n !##############################################################################\n subroutine plot_hist_old(xin, yin, color, legend)\n\n implicit none\n\n\n !##### INPUT/OUTPUT VARIABLES #############################################\n \n real*8, intent(in) :: xin(:), yin(:)\n character(LEN=*), optional :: color\n character(LEN=*), optional :: legend\n\n\n !##### OTHER VARIABLES ####################################################\n \n integer :: n, i1\n \n \n !##### ROUTINE CODE #######################################################\n\n n = assert_eq(size(xin, 1), size(yin, 1), 'plot')\n\n ! generate the respective plot data\n if(.not.gnu_addtoplot)then\n\n ! allocate new x array\n if(allocated(gnu_x))deallocate(gnu_x)\n allocate(gnu_x(n, 1))\n gnu_x(:, 1) = xin \n\n ! allocate new y array\n if(allocated(gnu_y))deallocate(gnu_y)\n allocate(gnu_y(n, 1))\n gnu_y(:, 1) = yin \n\n ! allocate new x_temp array\n if(allocated(gnu_x_temp))deallocate(gnu_x_temp)\n allocate(gnu_x_temp(n, 1))\n gnu_x_temp(:, 1) = xin \n\n ! allocate new y_temp array\n if(allocated(gnu_y_temp))deallocate(gnu_y_temp)\n allocate(gnu_y_temp(n, 1))\n gnu_y_temp(:, 1) = yin\n\n gnu_addtoplot = .true.\n gnu_nmax = n\n gnu_mmax = 1\n\n else\n \n ! get new number of lines\n gnu_mmax = gnu_mmax+1\n if(gnu_mmax > 1000)then\n write(*,'(/a/)')'SORRY: I CANNOT PLOT MORE THAN 1000 LINES'\n return\n endif\n\n ! deallocate arrays\n deallocate(gnu_x)\n deallocate(gnu_y)\n \n ! if the new array is the longer one\n if(n > gnu_nmax)then\n allocate(gnu_x(n, gnu_mmax))\n allocate(gnu_y(n, gnu_mmax))\n\n gnu_x(1:gnu_nmax, 1:gnu_mmax-1) = gnu_x_temp \n gnu_y(1:gnu_nmax, 1:gnu_mmax-1) = gnu_y_temp\n\n ! fill up with the same values\n do i1 = gnu_nmax+1, n\n gnu_x(i1, 1:gnu_mmax-1) = gnu_x(gnu_nmax, 1:gnu_mmax-1)\n gnu_y(i1, 1:gnu_mmax-1) = gnu_y(gnu_nmax, 1:gnu_mmax-1)\n enddo\n\n gnu_x(:, gnu_mmax) = xin\n gnu_y(:, gnu_mmax) = yin\n\n ! set new nmax\n gnu_nmax = n\n\n ! if the old array is the longer one\n else\n\n allocate(gnu_x(gnu_nmax, gnu_mmax))\n allocate(gnu_y(gnu_nmax, gnu_mmax))\n\n gnu_x(:, 1:gnu_mmax-1) = gnu_x_temp \n gnu_y(:, 1:gnu_mmax-1) = gnu_y_temp \n\n gnu_x(1:n, gnu_mmax) = xin\n gnu_y(1:n, gnu_mmax) = yin\n\n ! fill up with same values\n do i1 = n+1, gnu_nmax\n gnu_x(i1, gnu_mmax) = gnu_x(n, gnu_mmax)\n gnu_y(i1, gnu_mmax) = gnu_y(n, gnu_mmax)\n enddo \n endif\n\n deallocate(gnu_x_temp)\n allocate(gnu_x_temp(size(gnu_x,1), size(gnu_x,2)))\n gnu_x_temp = gnu_x\n\n deallocate(gnu_y_temp)\n allocate(gnu_y_temp(size(gnu_y,1), size(gnu_y,2)))\n gnu_y_temp = gnu_y\n \n endif \n\n ! set up definitions\n gnu_definitions(gnu_mmax) = 'with boxes'\n\n ! get the line color\n if(present(color))then\n gnu_definitions(gnu_mmax) = trim(gnu_definitions(gnu_mmax))//' lc rgb \"'//adjustl(trim(color))//'\"'\n else\n write(gnu_definitions(gnu_mmax), '(a,i4)')trim(gnu_definitions(gnu_mmax))//' lc ', gnu_mmax\n endif \n\n ! set the legend\n if(present(legend))then\n gnu_dolegend = .true.\n gnu_definitions(gnu_mmax) = trim(gnu_definitions(gnu_mmax))//' title \"'//adjustl(trim(legend))//'\"'\n else\n gnu_definitions(gnu_mmax) = trim(gnu_definitions(gnu_mmax))//' notitle '\n endif\n\n gnu_histogram = .true.\n\n end subroutine\n \n \n !##############################################################################\n ! SUBROUTINE plot_hist_new\n !\n ! Plots a histogram.\n !##############################################################################\n subroutine plot_hist_new(xvalues, nbins, left, right, incl_outside, absolute, color, legend)\n\n implicit none\n\n\n !##### INPUT/OUTPUT VARIABLES #############################################\n \n real*8, intent(in) :: xvalues(1:)\n integer, intent(in) :: nbins\n real*8, optional :: left\n real*8, optional :: right\n logical, optional :: incl_outside\n logical, optional :: absolute\n character(LEN=*), optional :: color\n character(LEN=*), optional :: legend\n\n\n !##### OTHER VARIABLES ####################################################\n \n integer :: n, i1\n real*8 :: lower, upper, total\n real*8 :: thresholds(0:nbins), freq(0:nbins)\n real*8 :: xin(nbins), yin(nbins)\n \n \n \n !##### ROUTINE CODE #######################################################\n\n n = nbins\n \n ! get lower and upper endpoint as well as width\n lower = minval(xvalues)\n if(present(left))lower = left\n \n upper = maxval(xvalues)\n if(present(right))upper = right\n \n ! get thresholds\n call grid_Cons_Equi(thresholds, lower, upper)\n \n ! get frequency\n freq(0) = dble(count(xvalues < lower))\n do i1 = 1, nbins\n freq(i1) = dble(count(xvalues <= thresholds(i1)))\n enddo\n total = freq(nbins) - freq(0)\n \n if(present(incl_outside))then\n if(incl_outside)then\n freq(0) = 0d0\n freq(nbins) = freq(nbins) + dble(count(xvalues >= upper))\n total = freq(nbins)\n endif\n endif\n \n ! get histogram data\n do i1 = 1, nbins\n xin(i1) = (thresholds(i1-1) + thresholds(i1))/2d0\n yin(i1) = (freq(i1) - freq(i1-1))\n enddo\n \n if(present(absolute))then\n if(.not. absolute)then\n yin = yin/total\n endif\n else\n yin = yin/total\n endif\n\n ! generate the respective plot data\n if(.not.gnu_addtoplot)then\n\n ! allocate new x array\n if(allocated(gnu_x))deallocate(gnu_x)\n allocate(gnu_x(n, 1))\n gnu_x(:, 1) = xin \n\n ! allocate new y array\n if(allocated(gnu_y))deallocate(gnu_y)\n allocate(gnu_y(n, 1))\n gnu_y(:, 1) = yin \n\n ! allocate new x_temp array\n if(allocated(gnu_x_temp))deallocate(gnu_x_temp)\n allocate(gnu_x_temp(n, 1))\n gnu_x_temp(:, 1) = xin \n\n ! allocate new y_temp array\n if(allocated(gnu_y_temp))deallocate(gnu_y_temp)\n allocate(gnu_y_temp(n, 1))\n gnu_y_temp(:, 1) = yin\n\n gnu_addtoplot = .true.\n gnu_nmax = n\n gnu_mmax = 1\n\n else\n \n ! get new number of lines\n gnu_mmax = gnu_mmax+1\n if(gnu_mmax > 1000)then\n write(*,'(/a/)')'SORRY: I CANNOT PLOT MORE THAN 1000 LINES'\n return\n endif\n\n ! deallocate arrays\n deallocate(gnu_x)\n deallocate(gnu_y)\n \n ! if the new array is the longer one\n if(n > gnu_nmax)then\n allocate(gnu_x(n, gnu_mmax))\n allocate(gnu_y(n, gnu_mmax))\n\n gnu_x(1:gnu_nmax, 1:gnu_mmax-1) = gnu_x_temp \n gnu_y(1:gnu_nmax, 1:gnu_mmax-1) = gnu_y_temp\n\n ! fill up with the same values\n do i1 = gnu_nmax+1, n\n gnu_x(i1, 1:gnu_mmax-1) = gnu_x(gnu_nmax, 1:gnu_mmax-1)\n gnu_y(i1, 1:gnu_mmax-1) = gnu_y(gnu_nmax, 1:gnu_mmax-1)\n enddo\n\n gnu_x(:, gnu_mmax) = xin\n gnu_y(:, gnu_mmax) = yin\n\n ! set new nmax\n gnu_nmax = n\n\n ! if the old array is the longer one\n else\n\n allocate(gnu_x(gnu_nmax, gnu_mmax))\n allocate(gnu_y(gnu_nmax, gnu_mmax))\n\n gnu_x(:, 1:gnu_mmax-1) = gnu_x_temp \n gnu_y(:, 1:gnu_mmax-1) = gnu_y_temp \n\n gnu_x(1:n, gnu_mmax) = xin\n gnu_y(1:n, gnu_mmax) = yin\n\n ! fill up with same values\n do i1 = n+1, gnu_nmax\n gnu_x(i1, gnu_mmax) = gnu_x(n, gnu_mmax)\n gnu_y(i1, gnu_mmax) = gnu_y(n, gnu_mmax)\n enddo \n endif\n\n deallocate(gnu_x_temp)\n allocate(gnu_x_temp(size(gnu_x,1), size(gnu_x,2)))\n gnu_x_temp = gnu_x\n\n deallocate(gnu_y_temp)\n allocate(gnu_y_temp(size(gnu_y,1), size(gnu_y,2)))\n gnu_y_temp = gnu_y\n \n endif \n\n ! set up definitions\n gnu_definitions(gnu_mmax) = 'with boxes'\n\n ! get the line color\n if(present(color))then\n gnu_definitions(gnu_mmax) = trim(gnu_definitions(gnu_mmax))//' lc rgb \"'//adjustl(trim(color))//'\"'\n else\n write(gnu_definitions(gnu_mmax), '(a,i4)')trim(gnu_definitions(gnu_mmax))//' lc ', gnu_mmax\n endif \n\n ! set the legend\n if(present(legend))then\n gnu_dolegend = .true.\n gnu_definitions(gnu_mmax) = trim(gnu_definitions(gnu_mmax))//' title \"'//adjustl(trim(legend))//'\"'\n else\n gnu_definitions(gnu_mmax) = trim(gnu_definitions(gnu_mmax))//' notitle '\n endif\n\n gnu_histogram = .true.\n\n end subroutine\n\n\n !##############################################################################\n ! SUBROUTINE plot3d_grid\n !\n ! Plots a x-y-z-data column on a grid. Plot will be executed immediately.\n !\n ! Credits to Patrick Wiesmann for providing a first version of a 3d plotting \n ! subroutine during his research assistantship.\n !##############################################################################\n subroutine plot3d_grid(xin, yin, zin, color, linewidth, marker, markersize, noline, &\n xlim, xticks, xlabel, ylim, yticks, ylabel, zlim, zticks, zlevel, zlabel, & \n surf, surf_color, transparent, view, title, filename, filetype, output)\n\n implicit none\n\n\n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! input variables\n real*8, intent(in) :: xin(:), yin(:), zin(:,:)\n\n ! line and marker color\n character(LEN=*), optional :: color\n\n ! width of the plotting line\n real*8, optional :: linewidth\n\n ! marker definition\n integer, optional :: marker\n\n ! size of the marker\n real*8, optional :: markersize\n\n ! if no line should be plotted\n logical, optional :: noline\n\n ! x axis definitial\n real*8, optional :: xlim(2)\n\n ! x axis tick definitions\n real*8, optional :: xticks\n\n ! y axis definitial\n real*8, optional :: ylim(2)\n\n ! y axis tick definitions\n real*8, optional :: yticks\n\n ! z axis definitial\n real*8, optional :: zlim(2)\n\n ! z axis tick definitions\n real*8, optional :: zticks\n\n ! point where the z axis is placed\n real*8, optional :: zlevel\n\n ! rotates the graph\n real*8, optional :: view(2)\n\n ! colored surface or not\n logical, optional :: surf\n\n ! color of the surface\n integer, optional :: surf_color\n\n ! see through surface or not\n logical, optional :: transparent\n\n ! output file name\n character(LEN=*), optional :: xlabel\n\n ! output file name\n character(LEN=*), optional :: ylabel\n\n ! output file name\n character(LEN=*), optional :: zlabel\n \n ! output file name\n character(LEN=*), optional :: title\n\n ! output file name\n character(LEN=*), optional :: filename\n\n ! file type\n character(LEN=*), optional :: filetype\n\n ! output file name\n character(LEN=*), optional :: output\n\n\n !##### OTHER VARIABLES ####################################################\n \n logical :: lines, points\n character(LEN = 2000) :: definition \n integer :: i1, i2, n1, n2\n character(LEN=3) :: ft\n character(LEN=150) :: cfile, dfile\n \n \n !##### ROUTINE CODE #######################################################\n\n ! assert that the sizes are coorect\n n1 = assert_eq(size(xin, 1), size(zin, 1), 'plot3d')\n n2 = assert_eq(size(yin, 1), size(zin, 2), 'plot3d')\n\n ! check for lines and points\n lines = .true.\n if(present(noline))then\n if(noline)lines = .false.\n endif\n\n if(.not.lines)then\n points = .true.\n else\n points = .false.\n endif\n if(present(marker))points = .true.\n\n ! set up definitions\n definition = 'with'\n\n ! get lines and points\n if(lines .and. points)then\n definition = trim(definition)//' linespoints'\n elseif(lines)then\n definition = trim(definition)//' lines'\n else\n definition = trim(definition)//' points'\n endif\n\n ! get the line color\n if(present(color))then\n definition = trim(definition)//' lc rgb \"'//adjustl(trim(color))//'\"'\n else\n definition = trim(definition)//' lc rgb \"blue\"'\n endif \n\n ! get line width\n if(lines)then\n if(present(linewidth)) then\n write(definition, '(a,f8.2)')trim(definition)//' lw ', max(linewidth, 0d0)\n else\n if(present(surf))then\n write(definition, '(a,f8.2)')trim(definition)//' lw ', 0.3d0\n else\n write(definition, '(a,f8.2)')trim(definition)//' lw ', 1d0\n endif\n endif\n endif\n\n ! get marker definition\n if(points)then\n \n if(present(marker)) then\n write(definition, '(a,i2)')trim(definition)//' pt ', min(marker, 13)\n else\n write(definition, '(a,i2)')trim(definition)//' pt ', 1\n endif\n\n if(present(markersize))then\n write(definition, '(a,f8.2)')trim(definition)//' ps ', max(markersize, 0d0)\n else\n write(definition, '(a,f8.2)')trim(definition)//' ps ', 1d0\n endif\n endif \n\n ! set the legend\n definition = trim(definition)//' notitle '\n\n ! now directly create output\n if(present(output))then\n cfile = output//'_c.dat'\n dfile = output//'_d.dat'\n else\n cfile = 'command135454313d.dat'\n dfile = 'plotdata135454313d.dat'\n endif\n\n ! write the output data file\n open(213659,file=trim(dfile))\n do i1 = 1, n1\n do i2 = 1, n2\n write(213659, '(3e21.10e4)')xin(i1), yin(i2), zin(i1, i2)\n enddo\n write(213659,*) \n enddo\n close(213659)\n\n ! write the command file\n open(213659,file=trim(cfile))\n\n ! set terminal and grid\n write(213659, '(a)')'if (strstrt(GPVAL_TERMINALS, \"wxt\") > 0) {'\n write(213659, '(a)')' set terminal wxt title \"Gnuplot\"'\n write(213659, '(a)')'} else {'\n write(213659, '(a)')' if (strstrt(GPVAL_TERMINALS, \"x11\") > 0) {'\n write(213659, '(a)')' set terminal x11'\n write(213659, '(a)')' } else {'\n write(213659, '(a)')' if (strstrt(GPVAL_TERMINALS, \"qt\") > 0) {'\n write(213659, '(a)')' set terminal qt'\n write(213659, '(a)')' } else {'\n write(213659, '(a)')' print \"\"'\n write(213659, '(a)')' print \"ATTENTION: There seems to be NO VALID TERMINAL installed in \"'\n write(213659, '(a)')' print \" your version of gnuplot. It might be a good idea to \"'\n write(213659, '(a)')' print \" completely uninstall your Fortran/gnuplot/geany installation\"'\n write(213659, '(a)')' print \" using the uninstallation files on www.ce-fortran.com. \"'\n write(213659, '(a)')' print \" Afterwards you should reinstall the Fortran system again.\"'\n write(213659, '(a)')' print \" If this does not help, please refer to the forum.\"'\n write(213659, '(a)')' print \"\"'\n write(213659, '(a)')' q'\n write(213659, '(a)')' }'\n write(213659, '(a)')' }'\n write(213659, '(a)')'}'\n write(213659, '(a)')'set grid'\n \n if(present(zlevel)) then\n write(213659, '(a,e13.5)')'set ticslevel ', -min(max(zlevel, 0d0), 1d0)\n else \n write(213659, '(a,e13.5)')'set ticslevel 0'\n endif\n \n if(present(surf) .and. surf) then\n write(213659, '(a)')'set pm3d'\n if(present(surf_color)) then\n select case (surf_color)\n case(1)\n write(213659,'(a)')'set palette gray'\n case(2)\n write(213659,'(a)')'set palette rgbformulae 33,13,10'\n case(3)\n write(213659,'(a)')'set palette rgbformulae 3,11,6'\n case(4)\n write(213659,'(a)')'set palette rgbformulae 23,28,3'\n case(5)\n write(213659, '(a)')'set palette rgbformulae 21,22,23'\n case default\n write(213659, '(a)')'set palette rgbformulae 7,5,15'\n end select\n endif \n endif\n\n if(present(transparent) .and. .not. transparent) then\n write(213659, '(a)')'set hidden3d'\n endif\n \n if(present(view)) then\n write(213659, '(a,e13.5,a,e13.5)')'set view ', min(max(view(1), 0d0), 360d0), &\n ',',min(max(view(2), 0d0), 360d0)\n endif\n \n ! set x axis\n if(present(xlim))write(213659, '(a,e13.5,a,e13.5,a)')'set xrange [',minval(xlim),':',maxval(xlim),']'\n if(present(xticks))write(213659, '(a,e13.5)')'set xtics ',xticks \n if(present(xlabel))write(213659, '(a)')'set xlabel \"'//xlabel//'\"font \",12\"'\n \n ! set y axis\n if(present(ylim))write(213659, '(a,e13.5,a,e13.5,a)')'set yrange [',minval(ylim),':',maxval(ylim),']'\n if(present(yticks))write(213659, '(a,e13.5)')'set ytics ',yticks \n if(present(ylabel))write(213659, '(a)')'set ylabel \"'//ylabel//'\"font \",12\"'\n\n ! set z axis\n if(present(zlim))write(213659, '(a,e13.5,a,e13.5,a)')'set zrange [',minval(zlim),':',maxval(zlim),']'\n if(present(zticks))write(213659, '(a,e13.5)')'set ztics ',zticks \n if(present(zlabel))write(213659, '(a)')'set zlabel \"'//zlabel//'\"font \",12\"'\n\n ! set title\n if(present(title))write(213659, '(a)')'set title \"'//title//'\" font \",16\"'\n \n ! legend statement\n write(213659, '(a)')'unset key'\n\n ! write plot lines for 3D-data\n write(213659, '(a)')'splot \"'//trim(dfile)//'\" using 1:2:3 '//trim(definition)\n \n write(213659, '(a)')'pause -1 \"Press RETURN to continue...\"'\n\n ! write graph to file\n if(present(filename))then\n ft = \"eps\"\n if(present(filetype))then\n if(filetype(1:3) == \"png\")ft= \"png\"\n endif\n write(213659, *)\n write(213659, '(a)')'set terminal '//ft\n write(213659, '(a)')'set output \"'//filename//'.'//ft//'\"'\n write(213659, '(a)')'replot'\n endif\n \n write(213659, '(a)')'q'\n close(213659)\n \n call system('gnuplot \"'//trim(cfile)//'\"') \n if(.not.present(output))then\n open(213659,file=trim(dfile))\n close(213659, status='delete')\n open(213659,file=trim(cfile))\n close(213659, status='delete')\n endif\n \n end subroutine\n\n\n !##############################################################################\n ! SUBROUTINE plot3d_line\n !\n ! Plots a x-y-z-data column with random points. Plot will be executed immediately.\n !\n ! Credits to Patrick Wiesmann for providing a first version of a 3d plotting \n ! subroutine during his research assistantship.\n !##############################################################################\n subroutine plot3d_line(xin, yin, zin, color, linewidth, marker, markersize, noline, &\n xlim, xticks, xlabel, ylim, yticks, ylabel, zlim, zticks, zlevel, zlabel, & \n view, title, filename, filetype, output)\n\n implicit none\n\n\n !##### INPUT/OUTPUT VARIABLES #############################################\n \n ! input variables\n real*8, intent(in) :: xin(:), yin(:), zin(:)\n\n ! line and marker color\n character(LEN=*), optional :: color\n\n ! width of the plotting line\n real*8, optional :: linewidth\n\n ! marker definition\n integer, optional :: marker\n\n ! size of the marker\n real*8, optional :: markersize\n\n ! if no line should be plotted\n logical, optional :: noline\n\n ! x axis definitial\n real*8, optional :: xlim(2)\n\n ! x axis tick definitions\n real*8, optional :: xticks\n\n ! y axis definitial\n real*8, optional :: ylim(2)\n\n ! y axis tick definitions\n real*8, optional :: yticks\n\n ! z axis definitial\n real*8, optional :: zlim(2)\n\n ! z axis tick definitions\n real*8, optional :: zticks\n\n ! point where the z axis is placed\n real*8, optional :: zlevel\n\n ! rotates the graph\n real*8, optional :: view(2)\n\n ! output file name\n character(LEN=*), optional :: xlabel\n\n ! output file name\n character(LEN=*), optional :: ylabel\n\n ! output file name\n character(LEN=*), optional :: zlabel\n \n ! output file name\n character(LEN=*), optional :: title\n\n ! output file name\n character(LEN=*), optional :: filename\n\n ! file type\n character(LEN=*), optional :: filetype\n\n ! output file name\n character(LEN=*), optional :: output\n\n\n !##### OTHER VARIABLES ####################################################\n \n logical :: lines, points\n character(LEN = 2000) :: definition \n integer :: i1, n\n character(LEN=3) :: ft\n character(LEN=150) :: cfile, dfile\n \n \n !##### ROUTINE CODE #######################################################\n\n ! assert that the sizes are coorect\n n = assert_eq(size(xin, 1), size(yin, 1), size(zin, 1), 'plot3d')\n\n ! check for lines and points\n lines = .true.\n if(present(noline))then\n if(noline)lines = .false.\n endif\n\n if(.not.lines)then\n points = .true.\n else\n points = .false.\n endif\n if(present(marker))points = .true.\n\n ! set up definitions\n definition = 'with'\n\n ! get lines and points\n if(lines .and. points)then\n definition = trim(definition)//' linespoints'\n elseif(lines)then\n definition = trim(definition)//' lines'\n else\n definition = trim(definition)//' points'\n endif\n\n ! get the line color\n if(present(color))then\n definition = trim(definition)//' lc rgb \"'//adjustl(trim(color))//'\"'\n else\n definition = trim(definition)//' lc rgb \"blue\"'\n endif \n\n ! get line width\n if(lines)then\n if(present(linewidth)) then\n write(definition, '(a,f8.2)')trim(definition)//' lw ', max(linewidth, 0d0)\n else\n write(definition, '(a,f8.2)')trim(definition)//' lw ', 1d0\n endif\n endif\n\n ! get marker definition\n if(points)then\n \n if(present(marker)) then\n write(definition, '(a,i2)')trim(definition)//' pt ', min(marker, 13)\n else\n write(definition, '(a,i2)')trim(definition)//' pt ', 1\n endif\n\n if(present(markersize))then\n write(definition, '(a,f8.2)')trim(definition)//' ps ', max(markersize, 0d0)\n else\n write(definition, '(a,f8.2)')trim(definition)//' ps ', 1d0\n endif\n endif \n\n ! set the legend\n definition = trim(definition)//' notitle '\n\n ! now directly create output\n if(present(output))then\n cfile = output//'_c.dat'\n dfile = output//'_d.dat'\n else\n cfile = 'command135454313d.dat'\n dfile = 'plotdata135454313d.dat'\n endif\n\n ! write the output data file\n open(213659,file=trim(dfile))\n do i1 = 1, n\n write(213659, '(3e21.10e4)')xin(i1), yin(i1), zin(i1)\n enddo\n close(213659)\n\n ! write the command file\n open(213659,file=trim(cfile))\n\n ! set terminal and grid\n write(213659, '(a)')'if (strstrt(GPVAL_TERMINALS, \"wxt\") > 0) {'\n write(213659, '(a)')' set terminal wxt title \"Gnuplot\"'\n write(213659, '(a)')'} else {'\n write(213659, '(a)')' if (strstrt(GPVAL_TERMINALS, \"x11\") > 0) {'\n write(213659, '(a)')' set terminal x11'\n write(213659, '(a)')' } else {'\n write(213659, '(a)')' if (strstrt(GPVAL_TERMINALS, \"qt\") > 0) {'\n write(213659, '(a)')' set terminal qt'\n write(213659, '(a)')' } else {'\n write(213659, '(a)')' print \"\"'\n write(213659, '(a)')' print \"ATTENTION: There seems to be NO VALID TERMINAL installed in \"'\n write(213659, '(a)')' print \" your version of gnuplot. It might be a good idea to \"'\n write(213659, '(a)')' print \" completely uninstall your Fortran/gnuplot/geany installation\"'\n write(213659, '(a)')' print \" using the uninstallation files on www.ce-fortran.com. \"'\n write(213659, '(a)')' print \" Afterwards you should reinstall the Fortran system again.\"'\n write(213659, '(a)')' print \" If this does not help, please refer to the forum.\"'\n write(213659, '(a)')' print \"\"'\n write(213659, '(a)')' q'\n write(213659, '(a)')' }'\n write(213659, '(a)')' }'\n write(213659, '(a)')'}'\n write(213659, '(a)')'set grid'\n \n if(present(zlevel)) then\n write(213659, '(a,e13.5)')'set ticslevel ', -min(max(zlevel, 0d0), 1d0)\n else \n write(213659, '(a,e13.5)')'set ticslevel 0'\n endif\n \n if(present(view)) then\n write(213659, '(a,e13.5,a,e13.5)')'set view ', min(max(view(1), 0d0), 360d0), &\n ',',min(max(view(2), 0d0), 360d0)\n endif\n \n ! set x axis\n if(present(xlim))write(213659, '(a,e13.5,a,e13.5,a)')'set xrange [',minval(xlim),':',maxval(xlim),']'\n if(present(xticks))write(213659, '(a,e13.5)')'set xtics ',xticks \n if(present(xlabel))write(213659, '(a)')'set xlabel \"'//xlabel//'\"font \",12\"'\n \n ! set y axis\n if(present(ylim))write(213659, '(a,e13.5,a,e13.5,a)')'set yrange [',minval(ylim),':',maxval(ylim),']'\n if(present(yticks))write(213659, '(a,e13.5)')'set ytics ',yticks \n if(present(ylabel))write(213659, '(a)')'set ylabel \"'//ylabel//'\"font \",12\"'\n\n ! set z axis\n if(present(zlim))write(213659, '(a,e13.5,a,e13.5,a)')'set zrange [',minval(zlim),':',maxval(zlim),']'\n if(present(zticks))write(213659, '(a,e13.5)')'set ztics ',zticks \n if(present(zlabel))write(213659, '(a)')'set zlabel \"'//zlabel//'\"font \",12\"'\n\n ! set title\n if(present(title))write(213659, '(a)')'set title \"'//title//'\" font \",16\"'\n \n ! legend statement\n write(213659, '(a)')'unset key'\n\n ! write plot lines for 3D-data\n write(213659, '(a)')'splot \"'//trim(dfile)//'\" using 1:2:3 '//trim(definition)\n \n write(213659, '(a)')'pause -1 \"Press RETURN to continue...\"'\n\n ! write graph to file\n if(present(filename))then\n ft = \"eps\"\n if(present(filetype))then\n if(filetype(1:3) == \"png\")ft= \"png\"\n endif\n write(213659, *)\n write(213659, '(a)')'set terminal '//ft\n write(213659, '(a)')'set output \"'//filename//'.'//ft//'\"'\n write(213659, '(a)')'replot'\n endif\n \n write(213659, '(a)')'q'\n close(213659)\n \n call system('gnuplot \"'//trim(cfile)//'\"') \n if(.not.present(output))then\n open(213659,file=trim(dfile))\n close(213659, status='delete')\n open(213659,file=trim(cfile))\n close(213659, status='delete')\n endif\n \n end subroutine\n\n\n\n\n\n\n\n\n\n\n\n!##############################################################################\n!##############################################################################\n! MODULE sorting\n!##############################################################################\n!############################################################################## \n\n\n !##############################################################################\n ! SUBROUTINE sort_r\n !\n ! Sorts an array of type real*8 in ascending order.\n !\n ! PARTS OF THIS PROCEDURE WERE COPIED AND ADAPTED FROM:\n ! The Wikibook \"Algorithm Implementation\" available at\n ! https://en.wikibooks.org/wiki/Algorithm_Implementation/Sorting/Quicksort#FORTRAN_90.2F95\n !\n ! and follows closely the Qsort implementation found in \n ! \"A FORTRAN 90 Numerical Library\" (AFNL), which is available at\n ! https://sourceforge.net/projects/afnl/\n !\n ! REFERENCE: Ramos, A. (2006). A FORTRAN 90 numerical library.\n !##############################################################################\n subroutine sort_r(x)\n\n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n\n ! the array that should be sorted\n real*8, intent(inout) :: x(:)\n\n\n !##### OTHER VARIABLES ####################################################\n\n ! from which list size should insertion sort be used\n integer, parameter :: Isw = 10\n\n ! type for the left and right bounds\n type Limits\n integer :: Ileft, Iright\n end type Limits\n\n ! other variables \n integer :: Ipvn, Ileft, Iright, ISpos, ISmax\n type(Limits), allocatable :: Stack(:)\n \n\n !##### ROUTINE CODE #######################################################\n\n allocate(Stack(Size(X)*2)) \n \n Stack(:)%Ileft = 0\n \n ! Iniitialize the stack\n Ispos = 1\n Ismax = 1\n Stack(ISpos)%Ileft = 1\n Stack(ISpos)%Iright = size(X)\n \n do while (Stack(ISpos)%Ileft /= 0)\n \n Ileft = Stack(ISPos)%Ileft\n Iright = Stack(ISPos)%Iright\n\n ! choose between inseration and quick sort\n if (Iright-Ileft <= Isw) then\n call InsrtLC(X, Ileft, Iright)\n ISpos = ISPos + 1\n else\n Ipvn = ChoosePiv(X, Ileft, Iright)\n Ipvn = Partition(X, Ileft, Iright, Ipvn)\n \n Stack(ISmax+1)%Ileft = Ileft\n Stack(ISmax+1) %Iright = Ipvn-1\n Stack(ISmax+2)%Ileft = Ipvn + 1\n Stack(ISmax+2)%Iright = Iright\n ISpos = ISpos + 1\n ISmax = ISmax + 2\n endif\n enddo\n\n ! deallocate all arrays\n deallocate(Stack)\n \n \n !##### SUBROUTINES AND FUNCTIONS ##########################################\n\n contains\n\n \n !##########################################################################\n ! FUNCTION ChoosePiv\n !\n ! Determines the pivotal element for the quicksort algorithm.\n !##########################################################################\n function ChoosePiv(XX, IIleft, IIright) result (IIpv)\n\n\n !##### INPUT/OUTPUT VARIABLES ############################################# \n\n ! the array to work on\n real*8, intent(in) :: XX(:)\n\n ! the left and right definition of the sub-array\n integer, intent(in) :: IIleft, IIright\n \n ! the pivotal element that is returned\n integer :: IIpv\n \n\n !##### OTHER VARIABLES ####################################################\n \n real*8 :: XXcp(3)\n integer :: IIpt(3), IImd\n\n\n !##### ROUTINE CODE #######################################################\n \n IImd = Int((IIleft+IIright)/2)\n IIpv = IImd\n XXcp(1) = XX(IIleft)\n XXcp(2) = XX(IImd)\n XXcp(3) = XX(IIright)\n IIpt = (/1,2,3/)\n \n call InsrtLC(XXcp, 1, 3, IIpt)\n \n select case (IIpt(2))\n case (1)\n IIpv = IIleft\n case (2)\n IIpv = IImd\n case (3)\n IIpv = IIright\n End Select\n \n end function\n\n \n !##########################################################################\n ! SUBROUTINE InsrtLC\n !\n ! Perform an insertion sort of the list XX(:) between index \n ! values IIl and IIr.\n !##########################################################################\n subroutine InsrtLC(XX, IIl, IIr, IIpt)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n\n ! the array to work on\n real*8, intent(inout) :: XX(:)\n\n ! the left and right definition of the sub-array\n integer, intent(in) :: IIl, IIr\n\n ! the permutations\n integer, intent(inout), optional :: IIpt(:)\n\n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: RRtmp\n integer :: II, JJ\n \n\n !##### ROUTINE CODE #######################################################\n \n do II = IIl+1, IIr\n RRtmp = XX(II)\n do JJ = II-1, 1, -1\n if (RRtmp < XX(JJ)) then\n XX(JJ+1) = XX(JJ)\n if(present(IIpt))call Swap_IN(IIpt, JJ, JJ+1)\n else\n Exit\n endif\n enddo\n XX(JJ+1) = RRtmp\n enddo\n \n end subroutine InsrtLC\n\n \n !##########################################################################\n ! FUNCTION Partition\n !\n ! Arranges the array X between the index values Ileft and Iright\n ! positioning elements smallers than X(Ipv) at the left and the others \n ! at the right.\n !##########################################################################\n function Partition(X, Ileft, Iright, Ipv) result(Ipvfn)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n\n ! the array to work on\n real*8, intent(inout) :: X(:)\n\n ! the left and right definition of the sub-array and pivotal element\n integer, intent(in) :: Ileft, Iright, Ipv\n\n ! return value\n integer :: Ipvfn\n\n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: Rpv\n integer :: I\n \n\n !##### ROUTINE CODE #######################################################\n \n Rpv = X(Ipv)\n call Swap(X, Ipv, Iright)\n Ipvfn = Ileft\n \n do I = Ileft, Iright-1\n if (X(I) <= Rpv) then\n call Swap(X, I, Ipvfn)\n Ipvfn = Ipvfn + 1\n endif\n enddo\n \n call Swap(X, Ipvfn, Iright)\n \n end function Partition\n \n\n !##########################################################################\n ! SUBROUTINE Swap\n !\n ! Swaps elements i and j of array x\n !##########################################################################\n subroutine Swap(X, I, J)\n\n\n !##### INPUT/OUTPUT VARIABLES #############################################\n\n ! the array to work on\n real*8, intent(inout) :: X(:)\n\n ! the left and right definition of the sub-array and pivotal element\n integer, intent(in) :: I, J\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: Xtmp\n \n\n !##### ROUTINE CODE ####################################################### \n \n Xtmp = X(I)\n X(I) = X(J)\n X(J) = Xtmp\n \n end subroutine Swap\n\n\n !##########################################################################\n ! SUBROUTINE Swap_IN\n !\n ! Swaps elements i and j of an integer array\n !##########################################################################\n subroutine Swap_IN(X, I, J)\n\n\n !##### INPUT/OUTPUT VARIABLES #############################################\n\n ! the array to work on\n integer, intent(inout) :: X(:)\n\n ! the left and right definition of the sub-array and pivotal element\n integer, intent(in) :: I, J\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: Xtmp\n \n\n !##### ROUTINE CODE ####################################################### \n \n Xtmp = X(I)\n X(I) = X(J)\n X(J) = Xtmp\n \n end subroutine Swap_IN\n \n end subroutine sort_r\n\n\n\n !##############################################################################\n ! SUBROUTINE sort_r2\n !\n ! Sorts an array of type real*8 in ascending order and returns new ordering.\n !\n ! PARTS OF THIS PROCEDURE WERE COPIED AND ADAPTED FROM:\n ! The Wikibook \"Algorithm Implementation\" available at\n ! https://en.wikibooks.org/wiki/Algorithm_Implementation/Sorting/Quicksort#FORTRAN_90.2F95\n !\n ! and follows closely the Qsort implementation found in \n ! \"A FORTRAN 90 Numerical Library\" (AFNL), which is available at\n ! https://sourceforge.net/projects/afnl/\n !\n ! REFERENCE: Ramos, A. (2006). A FORTRAN 90 numerical library.\n !##############################################################################\n subroutine sort_r2(x, iorder)\n\n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n\n ! the array that should be sorted\n real*8, intent(inout) :: x(:)\n\n ! an array that will contain the new sorting order\n integer, intent(out) :: iorder(size(x, 1))\n\n\n !##### OTHER VARIABLES ####################################################\n\n ! from which list size should insertion sort be used\n integer, parameter :: Isw = 10\n\n ! type for the left and right bounds\n type Limits\n integer :: Ileft, Iright\n end type Limits\n\n ! other variables \n integer :: Ipvn, Ileft, Iright, ISpos, ISmax, ii\n type(Limits), allocatable :: Stack(:)\n \n\n !##### ROUTINE CODE #######################################################\n\n ! initialize the sorting order array\n iorder = (/(ii, ii = 1, size(x, 1))/)\n\n allocate(Stack(Size(X)*2)) \n \n Stack(:)%Ileft = 0\n \n ! Iniitialize the stack\n Ispos = 1\n Ismax = 1\n Stack(ISpos)%Ileft = 1\n Stack(ISpos)%Iright = size(X)\n \n do while (Stack(ISpos)%Ileft /= 0)\n \n Ileft = Stack(ISPos)%Ileft\n Iright = Stack(ISPos)%Iright\n\n ! choose between inseration and quick sort\n if (Iright-Ileft <= Isw) then\n call InsrtLC(X, iorder, Ileft, Iright)\n ISpos = ISPos + 1\n else\n Ipvn = ChoosePiv(X, Ileft, Iright)\n Ipvn = Partition(X, iorder, Ileft, Iright, Ipvn)\n \n Stack(ISmax+1)%Ileft = Ileft\n Stack(ISmax+1) %Iright = Ipvn-1\n Stack(ISmax+2)%Ileft = Ipvn + 1\n Stack(ISmax+2)%Iright = Iright\n ISpos = ISpos + 1\n ISmax = ISmax + 2\n endif\n enddo\n\n ! deallocate all arrays\n deallocate(Stack)\n \n \n !##### SUBROUTINES AND FUNCTIONS ##########################################\n\n contains\n\n \n !##########################################################################\n ! FUNCTION ChoosePiv\n !\n ! Determines the pivotal element for the quicksort algorithm.\n !##########################################################################\n function ChoosePiv(XX, IIleft, IIright) result (IIpv)\n\n\n !##### INPUT/OUTPUT VARIABLES ############################################# \n\n ! the array to work on\n real*8, intent(in) :: XX(:)\n\n ! the left and right definition of the sub-array\n integer, intent(in) :: IIleft, IIright\n \n ! the pivotal element that is returned\n integer :: IIpv\n \n\n !##### OTHER VARIABLES ####################################################\n \n real*8 :: XXcp(3)\n integer :: IIpt(3), IImd\n\n\n !##### ROUTINE CODE #######################################################\n \n IImd = Int((IIleft+IIright)/2)\n IIpv = IImd\n XXcp(1) = XX(IIleft)\n XXcp(2) = XX(IImd)\n XXcp(3) = XX(IIright)\n IIpt = (/1,2,3/)\n \n call InsrtLC_help(XXcp, 1, 3, IIpt)\n \n select case (IIpt(2))\n case (1)\n IIpv = IIleft\n case (2)\n IIpv = IImd\n case (3)\n IIpv = IIright\n End Select\n \n end function\n\n !##########################################################################\n ! SUBROUTINE InsrtLC_help\n !\n ! Just a helping routine. Same as below but without iorder.\n !##########################################################################\n subroutine InsrtLC_help(XX, IIl, IIr, IIpt)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n\n ! the array to work on\n real*8, intent(inout) :: XX(:)\n\n ! the left and right definition of the sub-array\n integer, intent(in) :: IIl, IIr\n\n ! the permutations\n integer, intent(inout) :: IIpt(:)\n\n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: RRtmp\n integer :: II, JJ\n \n\n !##### ROUTINE CODE #######################################################\n \n do II = IIl+1, IIr\n RRtmp = XX(II)\n do JJ = II-1, 1, -1\n if (RRtmp < XX(JJ)) then\n XX(JJ+1) = XX(JJ)\n call Swap_IN(IIpt, JJ, JJ+1)\n else\n Exit\n endif\n enddo\n XX(JJ+1) = RRtmp\n enddo\n \n end subroutine InsrtLC_help\n\n \n !##########################################################################\n ! SUBROUTINE InsrtLC\n !\n ! Perform an insertion sort of the list XX(:) between index \n ! values IIl and IIr.\n !##########################################################################\n subroutine InsrtLC(XX, iorder, IIl, IIr)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n\n ! the array to work on\n real*8, intent(inout) :: XX(:)\n\n ! an array that will contain the new sorting order\n integer, intent(inout) :: iorder(size(XX, 1))\n\n ! the left and right definition of the sub-array\n integer, intent(in) :: IIl, IIr\n\n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: RRtmp\n integer :: IItmp\n integer :: II, JJ\n \n\n !##### ROUTINE CODE #######################################################\n \n do II = IIl+1, IIr\n RRtmp = XX(II)\n IItmp = iorder(II)\n do JJ = II-1, 1, -1\n if (RRtmp < XX(JJ)) then\n XX(JJ+1) = XX(JJ)\n iorder(JJ+1) = iorder(JJ)\n else\n Exit\n endif\n enddo\n XX(JJ+1) = RRtmp\n iorder(JJ+1) = IItmp\n enddo\n \n end subroutine InsrtLC\n\n \n !##########################################################################\n ! FUNCTION Partition\n !\n ! Arranges the array X between the index values Ileft and Iright\n ! positioning elements smallers than X(Ipv) at the left and the others \n ! at the right.\n !##########################################################################\n function Partition(X, iorder, Ileft, Iright, Ipv) result(Ipvfn)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n\n ! the array to work on\n real*8, intent(inout) :: X(:)\n\n ! an array that will contain the new sorting order\n integer, intent(inout) :: iorder(size(X, 1))\n\n ! the left and right definition of the sub-array and pivotal element\n integer, intent(in) :: Ileft, Iright, Ipv\n\n ! return value\n integer :: Ipvfn\n\n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: Rpv\n integer :: I\n \n\n !##### ROUTINE CODE #######################################################\n \n Rpv = X(Ipv)\n call Swap(X, Ipv, Iright)\n call Swap_IN(iorder, Ipv, Iright)\n Ipvfn = Ileft\n \n do I = Ileft, Iright-1\n if (X(I) <= Rpv) then\n call Swap(X, I, Ipvfn)\n call Swap_IN(iorder, I, Ipvfn)\n Ipvfn = Ipvfn + 1\n endif\n enddo\n \n call Swap(X, Ipvfn, Iright)\n call Swap_IN(iorder, Ipvfn, Iright)\n \n end function Partition\n \n\n !##########################################################################\n ! SUBROUTINE Swap\n !\n ! Swaps elements i and j of array x\n !##########################################################################\n subroutine Swap(X, I, J)\n\n\n !##### INPUT/OUTPUT VARIABLES #############################################\n\n ! the array to work on\n real*8, intent(inout) :: X(:)\n\n ! the left and right definition of the sub-array and pivotal element\n integer, intent(in) :: I, J\n \n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: Xtmp\n \n\n !##### ROUTINE CODE ####################################################### \n \n Xtmp = X(I)\n X(I) = X(J)\n X(J) = Xtmp\n \n end subroutine Swap\n\n\n !##########################################################################\n ! SUBROUTINE Swap_IN\n !\n ! Swaps elements i and j of an integer array\n !##########################################################################\n subroutine Swap_IN(X, I, J)\n\n\n !##### INPUT/OUTPUT VARIABLES #############################################\n\n ! the array to work on\n integer, intent(inout) :: X(:)\n\n ! the left and right definition of the sub-array and pivotal element\n integer, intent(in) :: I, J\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: Xtmp\n \n\n !##### ROUTINE CODE ####################################################### \n \n Xtmp = X(I)\n X(I) = X(J)\n X(J) = Xtmp\n \n end subroutine Swap_IN\n \n end subroutine sort_r2\n\n\n\n\n !##############################################################################\n ! SUBROUTINE sort_i\n !\n ! Sorts an array of type integer in ascending order.\n !\n ! PARTS OF THIS PROCEDURE WERE COPIED AND ADAPTED FROM:\n ! The Wikibook \"Algorithm Implementation\" available at\n ! https://en.wikibooks.org/wiki/Algorithm_Implementation/Sorting/Quicksort#FORTRAN_90.2F95\n !\n ! and follows closely the Qsort implementation found in \n ! \"A FORTRAN 90 Numerical Library\" (AFNL), which is available at\n ! https://sourceforge.net/projects/afnl/\n !\n ! REFERENCE: Ramos, A. (2006). A FORTRAN 90 numerical library.\n !##############################################################################\n subroutine sort_i(x)\n\n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n\n ! the array that should be sorted\n integer, intent(inout) :: x(:)\n\n\n !##### OTHER VARIABLES ####################################################\n\n ! from which list size should insertion sort be used\n integer, parameter :: Isw = 10\n\n ! type for the left and right bounds\n type Limits\n integer :: Ileft, Iright\n end type Limits\n\n ! other variables \n integer :: Ipvn, Ileft, Iright, ISpos, ISmax\n type(Limits), allocatable :: Stack(:)\n \n\n !##### ROUTINE CODE #######################################################\n \n allocate(Stack(Size(X)*2))\n \n Stack(:)%Ileft = 0\n \n ! Iniitialize the stack\n Ispos = 1\n Ismax = 1\n Stack(ISpos)%Ileft = 1\n Stack(ISpos)%Iright = size(X)\n \n do while (Stack(ISpos)%Ileft /= 0)\n \n Ileft = Stack(ISPos)%Ileft\n Iright = Stack(ISPos)%Iright\n\n ! choose between inseration and quick sort\n if (Iright-Ileft <= Isw) then\n call InsrtLC(X, Ileft, Iright)\n ISpos = ISPos + 1\n else\n Ipvn = ChoosePiv(X, Ileft, Iright)\n Ipvn = Partition(X, Ileft, Iright, Ipvn)\n \n Stack(ISmax+1)%Ileft = Ileft\n Stack(ISmax+1) %Iright = Ipvn-1\n Stack(ISmax+2)%Ileft = Ipvn + 1\n Stack(ISmax+2)%Iright = Iright\n ISpos = ISpos + 1\n ISmax = ISmax + 2\n endif\n enddo\n\n ! deallocate all arrays\n deallocate(Stack)\n \n \n !##### SUBROUTINES AND FUNCTIONS ##########################################\n\n contains\n\n \n !##########################################################################\n ! FUNCTION ChoosePiv\n !\n ! Determines the pivotal element for the quicksort algorithm.\n !##########################################################################\n function ChoosePiv(XX, IIleft, IIright) result (IIpv)\n\n\n !##### INPUT/OUTPUT VARIABLES ############################################# \n\n ! the array to work on\n integer, intent(in) :: XX(:)\n\n ! the left and right definition of the sub-array\n integer, intent(in) :: IIleft, IIright\n \n ! the pivotal element that is returned\n integer :: IIpv\n \n\n !##### OTHER VARIABLES ####################################################\n \n integer :: XXcp(3)\n integer :: IIpt(3), IImd\n\n\n !##### ROUTINE CODE #######################################################\n \n IImd = Int((IIleft+IIright)/2)\n IIpv = IImd\n XXcp(1) = XX(IIleft)\n XXcp(2) = XX(IImd)\n XXcp(3) = XX(IIright)\n IIpt = (/1,2,3/)\n \n call InsrtLC(XXcp, 1, 3, IIpt)\n \n select case (IIpt(2))\n case (1)\n IIpv = IIleft\n case (2)\n IIpv = IImd\n case (3)\n IIpv = IIright\n End Select\n \n end function\n\n \n !##########################################################################\n ! SUBROUTINE InsrtLC\n !\n ! Perform an insertion sort of the list XX(:) between index \n ! values IIl and IIr.\n !##########################################################################\n subroutine InsrtLC(XX, IIl, IIr, IIpt)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n\n ! the array to work on\n integer, intent(inout) :: XX(:)\n\n ! the left and right definition of the sub-array\n integer, intent(in) :: IIl, IIr\n\n ! the permutations\n integer, intent(inout), optional :: IIpt(:)\n\n \n !##### OTHER VARIABLES ####################################################\n \n integer :: RRtmp\n integer :: II, JJ\n \n\n !##### ROUTINE CODE #######################################################\n \n do II = IIl+1, IIr\n RRtmp = XX(II)\n do JJ = II-1, 1, -1\n if (RRtmp < XX(JJ)) then\n XX(JJ+1) = XX(JJ)\n if(present(IIpt))call Swap_IN(IIpt, JJ, JJ+1)\n else\n Exit\n endif\n enddo\n XX(JJ+1) = RRtmp\n enddo\n \n end subroutine InsrtLC\n\n \n !##########################################################################\n ! FUNCTION Partition\n !\n ! Arranges the array X between the index values Ileft and Iright\n ! positioning elements smallers than X(Ipv) at the left and the others \n ! at the right.\n !##########################################################################\n function Partition(X, Ileft, Iright, Ipv) result(Ipvfn)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n\n ! the array to work on\n integer, intent(inout) :: X(:)\n\n ! the left and right definition of the sub-array and pivotal element\n integer, intent(in) :: Ileft, Iright, Ipv\n\n ! return value\n integer :: Ipvfn\n\n \n !##### OTHER VARIABLES ####################################################\n \n real*8 :: Rpv\n integer :: I\n \n\n !##### ROUTINE CODE #######################################################\n \n Rpv = X(Ipv)\n call Swap(X, Ipv, Iright)\n Ipvfn = Ileft\n \n do I = Ileft, Iright-1\n if (X(I) <= Rpv) then\n call Swap(X, I, Ipvfn)\n Ipvfn = Ipvfn + 1\n endif\n enddo\n \n call Swap(X, Ipvfn, Iright)\n \n end function Partition\n \n\n !##########################################################################\n ! SUBROUTINE Swap\n !\n ! Swaps elements i and j of array x\n !##########################################################################\n subroutine Swap(X, I, J)\n\n\n !##### INPUT/OUTPUT VARIABLES #############################################\n\n ! the array to work on\n integer, intent(inout) :: X(:)\n\n ! the left and right definition of the sub-array and pivotal element\n integer, intent(in) :: I, J\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: Xtmp\n \n\n !##### ROUTINE CODE ####################################################### \n \n Xtmp = X(I)\n X(I) = X(J)\n X(J) = Xtmp\n \n end subroutine Swap\n\n\n !##########################################################################\n ! SUBROUTINE Swap_IN\n !\n ! Swaps elements i and j of an integer array\n !##########################################################################\n subroutine Swap_IN(X, I, J)\n\n\n !##### INPUT/OUTPUT VARIABLES #############################################\n\n ! the array to work on\n integer, intent(inout) :: X(:)\n\n ! the left and right definition of the sub-array and pivotal element\n integer, intent(in) :: I, J\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: Xtmp\n \n\n !##### ROUTINE CODE ####################################################### \n \n Xtmp = X(I)\n X(I) = X(J)\n X(J) = Xtmp\n \n end subroutine Swap_IN\n \n end subroutine sort_i\n\n\n\n !##############################################################################\n ! SUBROUTINE sort_i2\n !\n ! Sorts an array of type integer in ascending order and returns new ordering.\n !\n ! PARTS OF THIS PROCEDURE WERE COPIED AND ADAPTED FROM:\n ! The Wikibook \"Algorithm Implementation\" available at\n ! https://en.wikibooks.org/wiki/Algorithm_Implementation/Sorting/Quicksort#FORTRAN_90.2F95\n !\n ! and follows closely the Qsort implementation found in \n ! \"A FORTRAN 90 Numerical Library\" (AFNL), which is available at\n ! https://sourceforge.net/projects/afnl/\n !\n ! REFERENCE: Ramos, A. (2006). A FORTRAN 90 numerical library.\n !##############################################################################\n subroutine sort_i2(x, iorder)\n\n implicit none\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n\n ! the array that should be sorted\n integer, intent(inout) :: x(:)\n\n ! an array that will contain the new sorting order\n integer, intent(out) :: iorder(size(x, 1))\n\n\n !##### OTHER VARIABLES ####################################################\n\n ! from which list size should insertion sort be used\n integer, parameter :: Isw = 10\n\n ! type for the left and right bounds\n type Limits\n integer :: Ileft, Iright\n end type Limits\n\n ! other variables \n integer :: Ipvn, Ileft, Iright, ISpos, ISmax, ii\n type(Limits), allocatable :: Stack(:)\n \n\n !##### ROUTINE CODE #######################################################\n\n ! initialize the sorting order array\n iorder = (/(ii, ii = 1, size(x, 1))/)\n\n allocate(Stack(Size(X)*2)) \n \n Stack(:)%Ileft = 0\n \n ! Iniitialize the stack\n Ispos = 1\n Ismax = 1\n Stack(ISpos)%Ileft = 1\n Stack(ISpos)%Iright = size(X)\n \n do while (Stack(ISpos)%Ileft /= 0)\n \n Ileft = Stack(ISPos)%Ileft\n Iright = Stack(ISPos)%Iright\n\n ! choose between inseration and quick sort\n if (Iright-Ileft <= Isw) then\n call InsrtLC(X, iorder, Ileft, Iright)\n ISpos = ISPos + 1\n else\n Ipvn = ChoosePiv(X, Ileft, Iright)\n Ipvn = Partition(X, iorder, Ileft, Iright, Ipvn)\n \n Stack(ISmax+1)%Ileft = Ileft\n Stack(ISmax+1) %Iright = Ipvn-1\n Stack(ISmax+2)%Ileft = Ipvn + 1\n Stack(ISmax+2)%Iright = Iright\n ISpos = ISpos + 1\n ISmax = ISmax + 2\n endif\n enddo\n\n ! deallocate all arrays\n deallocate(Stack)\n \n \n !##### SUBROUTINES AND FUNCTIONS ##########################################\n\n contains\n\n \n !##########################################################################\n ! FUNCTION ChoosePiv\n !\n ! Determines the pivotal element for the quicksort algorithm.\n !##########################################################################\n function ChoosePiv(XX, IIleft, IIright) result (IIpv)\n\n\n !##### INPUT/OUTPUT VARIABLES ############################################# \n\n ! the array to work on\n integer, intent(in) :: XX(:)\n\n ! the left and right definition of the sub-array\n integer, intent(in) :: IIleft, IIright\n \n ! the pivotal element that is returned\n integer :: IIpv\n \n\n !##### OTHER VARIABLES ####################################################\n \n integer :: XXcp(3)\n integer :: IIpt(3), IImd\n\n\n !##### ROUTINE CODE #######################################################\n \n IImd = Int((IIleft+IIright)/2)\n IIpv = IImd\n XXcp(1) = XX(IIleft)\n XXcp(2) = XX(IImd)\n XXcp(3) = XX(IIright)\n IIpt = (/1,2,3/)\n \n call InsrtLC_help(XXcp, 1, 3, IIpt)\n \n select case (IIpt(2))\n case (1)\n IIpv = IIleft\n case (2)\n IIpv = IImd\n case (3)\n IIpv = IIright\n End Select\n \n end function\n\n !##########################################################################\n ! SUBROUTINE InsrtLC_help\n !\n ! Just a helping routine. Same as below but without iorder.\n !##########################################################################\n subroutine InsrtLC_help(XX, IIl, IIr, IIpt)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n\n ! the array to work on\n integer, intent(inout) :: XX(:)\n\n ! the left and right definition of the sub-array\n integer, intent(in) :: IIl, IIr\n\n ! the permutations\n integer, intent(inout) :: IIpt(:)\n\n \n !##### OTHER VARIABLES ####################################################\n \n integer :: RRtmp\n integer :: II, JJ\n \n\n !##### ROUTINE CODE #######################################################\n \n do II = IIl+1, IIr\n RRtmp = XX(II)\n do JJ = II-1, 1, -1\n if (RRtmp < XX(JJ)) then\n XX(JJ+1) = XX(JJ)\n call Swap_IN(IIpt, JJ, JJ+1)\n else\n Exit\n endif\n enddo\n XX(JJ+1) = RRtmp\n enddo\n \n end subroutine InsrtLC_help\n\n \n !##########################################################################\n ! SUBROUTINE InsrtLC\n !\n ! Perform an insertion sort of the list XX(:) between index \n ! values IIl and IIr.\n !##########################################################################\n subroutine InsrtLC(XX, iorder, IIl, IIr)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n\n ! the array to work on\n integer, intent(inout) :: XX(:)\n\n ! an array that will contain the new sorting order\n integer, intent(inout) :: iorder(size(XX, 1))\n\n ! the left and right definition of the sub-array\n integer, intent(in) :: IIl, IIr\n\n \n !##### OTHER VARIABLES ####################################################\n \n integer :: RRtmp\n integer :: IItmp\n integer :: II, JJ\n \n\n !##### ROUTINE CODE #######################################################\n \n do II = IIl+1, IIr\n RRtmp = XX(II)\n IItmp = iorder(II)\n do JJ = II-1, 1, -1\n if (RRtmp < XX(JJ)) then\n XX(JJ+1) = XX(JJ)\n iorder(JJ+1) = iorder(JJ)\n else\n Exit\n endif\n enddo\n XX(JJ+1) = RRtmp\n iorder(JJ+1) = IItmp\n enddo\n \n end subroutine InsrtLC\n\n \n !##########################################################################\n ! FUNCTION Partition\n !\n ! Arranges the array X between the index values Ileft and Iright\n ! positioning elements smallers than X(Ipv) at the left and the others \n ! at the right.\n !##########################################################################\n function Partition(X, iorder, Ileft, Iright, Ipv) result(Ipvfn)\n \n \n !##### INPUT/OUTPUT VARIABLES #############################################\n\n ! the array to work on\n integer, intent(inout) :: X(:)\n\n ! an array that will contain the new sorting order\n integer, intent(inout) :: iorder(size(X, 1))\n\n ! the left and right definition of the sub-array and pivotal element\n integer, intent(in) :: Ileft, Iright, Ipv\n\n ! return value\n integer :: Ipvfn\n\n \n !##### OTHER VARIABLES ####################################################\n \n integer :: Rpv\n integer :: I\n \n\n !##### ROUTINE CODE #######################################################\n \n Rpv = X(Ipv)\n call Swap(X, Ipv, Iright)\n call Swap_IN(iorder, Ipv, Iright)\n Ipvfn = Ileft\n \n do I = Ileft, Iright-1\n if (X(I) <= Rpv) then\n call Swap(X, I, Ipvfn)\n call Swap_IN(iorder, I, Ipvfn)\n Ipvfn = Ipvfn + 1\n endif\n enddo\n \n call Swap(X, Ipvfn, Iright)\n call Swap_IN(iorder, Ipvfn, Iright)\n \n end function Partition\n \n\n !##########################################################################\n ! SUBROUTINE Swap\n !\n ! Swaps elements i and j of array x\n !##########################################################################\n subroutine Swap(X, I, J)\n\n\n !##### INPUT/OUTPUT VARIABLES #############################################\n\n ! the array to work on\n integer, intent(inout) :: X(:)\n\n ! the left and right definition of the sub-array and pivotal element\n integer, intent(in) :: I, J\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: Xtmp\n \n\n !##### ROUTINE CODE ####################################################### \n \n Xtmp = X(I)\n X(I) = X(J)\n X(J) = Xtmp\n \n end subroutine Swap\n\n\n !##########################################################################\n ! SUBROUTINE Swap_IN\n !\n ! Swaps elements i and j of an integer array\n !##########################################################################\n subroutine Swap_IN(X, I, J)\n\n\n !##### INPUT/OUTPUT VARIABLES #############################################\n\n ! the array to work on\n integer, intent(inout) :: X(:)\n\n ! the left and right definition of the sub-array and pivotal element\n integer, intent(in) :: I, J\n \n \n !##### OTHER VARIABLES ####################################################\n \n integer :: Xtmp\n \n\n !##### ROUTINE CODE ####################################################### \n \n Xtmp = X(I)\n X(I) = X(J)\n X(J) = Xtmp\n \n end subroutine Swap_IN\n \n end subroutine sort_i2\n\n\nend module\n", "meta": {"hexsha": "6daaf6ca2a4da9bad487fcaabb87c8dd0b4ab072", "size": 397769, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "install_lin/src/toolbox.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": "install_lin/src/toolbox.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": "install_lin/src/toolbox.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": 31.2514927718, "max_line_length": 121, "alphanum_fraction": 0.4008381749, "num_tokens": 88989, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339837155239, "lm_q2_score": 0.8152324848629215, "lm_q1q2_score": 0.6845784221682466}} {"text": "!--------------------------------------------------\n!PHY1038 Assignment 3 - Finite Difference Methods \n!URN 6309823 - Penguin Lab Group 1\n!March 24th 2015\n!--------------------------------------------------\n\nProgram Finite_Difference_Methods\n IMPLICIT NONE\n\n REAL :: x,h,a,b,d,z,e,k,Integral,eItrap,eIsimp\n INTEGER :: j,m,l,n\n\n WRITE(6,*) \" \"\n WRITE(6,*) \" \"\n WRITE(6,*) \"This program finds estimates of f'(x) and f''(x)\"\n WRITE(6,*) \"using the 'forward difference method' and the 'centred difference method\"\n WRITE(6,*) \"and compares them to the actual values of f'(x) and f''(x)\"\n WRITE(6,*) \" \"\n WRITE(6,*) \"This program also finds estimates of the integral of f(x) using the 'Trapesium Rule' and 'Simpson's Rule'\"\n WRITE(6,*) \"and compares them to the actual value of the integral of f(x)dx between 0 and 1\"\n WRITE(6,*) \" \"\n WRITE(6,*) \" \"\n WRITE(6,*) \"Where f(x)=1/(x^2+3x+2)\"\n WRITE(6,*) \" \"\n WRITE(6,*) \" \"\n WRITE(6,*) \"Please input a value for x\"\n READ(5,*) x\n WRITE(6,*) \" \"\n WRITE(6,*) \"Please input a value for h\"\n READ(5,*) h\n WRITE(6,*) \" \"\n WRITE(6,*) \" \"\n\n !percentage error in the forward difference approximation, dfor(x,h) = a\n a=(g(x)-dfor(x,h))/g(x)*100\n\n !percentage error in the centered difference approximation, dcen(x,h) = b\n b=-(g(x)-dcen(x,h))/g(x)*100\n\n WRITE(6,*) \"The derivative of the function f(x) is:\", g(x)\n WRITE(6,*) \" \"\n WRITE(6,*) \"This is the value given by the forward difference approximation\", dfor(x,h), \"+-\",a,\"%\"\n WRITE(6,*) \" \"\n WRITE(6,*) \"This is the value given by the centered difference approxiamtion\", dcen(x,h), \"+-\",b,\"%\"\n WRITE(6,*) \" \"\n WRITE(6,*) \" \"\n\n !Run the program with x=0.0, x=1.0 and x=2.0, and with steps h=0.1 and h=0.01, for dfor(x,h) and dcen(x,h)\n\n !When x=0.0 and h=0.1 dfor(x,h) = -0.6709957022816583+-10.5339060 %\n !When x=1.0 and h=0.1 dfor(x,h) = -0.1305684427832299+-5.9907255 %\n !When x=2.0 and h=0.1 dfor(x,h) = -4.6551226875912739E-02+-4.2374778 %\n !When x=0.0 and h=0.1 dcen(x,h) = -0.7523497827000949+-0.3133044 %\n !When x=1.0 and h=0.1 dcen(x,h) = -0.1390142718104382+-9.0270929E-02 %\n !When x=2.0 and h=0.1 dcen(x,h) = -4.8632099499820183E-02+-4.3174408E-02 %\n\n !When x=0.0 and h=0.01 dfor(x,h) = -0.7413447068932214+-1.1540390 %\n !When x=1.0 and h=0.01 dfor(x,h) = -0.1380145580622827+-0.6295229 %\n !When x=2.0 and h=0.01 dfor(x,h) = -4.8398227581342178E-02+-0.4379335 %\n !When x=0.0 and h=0.01 dcen(x,h) = -0.7500171829018857+-2.2910535E-03 %\n !When x=1.0 and h=0.01 dcen(x,h) = -0.1388892562439127+-2.5972724E-04 %\n !When x=2.0 and h=0.01 dcen(x,h) = -4.8612059249253409E-02+-1.9487526E-03 %\n\n !When h=0.01 the % errors in dfor(x,h) and dcen(x,h) are much smaller than when h=0.1\n\n !When x is larger the % errors are smaller in dfor(x,h) and dcen(x,h)\n\n !percentage error in the centered difference approximation, d2cen(x,h) = d\nd=(g(x)-d2cen(x,h))/g(x)*100\n\n WRITE(6,*) \"The second derivative of the function f(x) is:\", i(x)\n WRITE(6,*) \" \"\n WRITE(6,*) \"This is the value given by the central difference approximation, d2cen(x,h):\", d2cen(x,h), \"+-\",d,\"%\"\n WRITE(6,*) \" \"\n\n !Run the program with x=0.0, x=\u03c0/4 and x=\u03c0/2, and with steps h=0.1 and h=0.01, for the second derivative\n\n !When x=0.0 and h=0.1 d2cen(x,h) = 1.7695724436768165+-3.3594299E+02 %\n !When x=pi/4 and h=0.1 d2cen(x,h) = 1.3469159201706665E-02+-1.6572333E+02 %\n !When x=pi/2 and h=0.1 d2cen(x,h) = 1.3469159201706665E-02+-1.6572333E+02 %\n\n !When x=0.0 and h=0.01 d2cen(x,h) = 1.7499924488362257+-3.3333234E+02 %\n !When x=pi/4 and h=0.01 d2cen(x,h) = 1.3522804387933199E-02+-1.6598508E+02 %\n !When x=pi/2 and h=0.01 d2cen(x,h) = 1.3522804387933199E-02+-1.6598508E+02 %\n\n !When h=0.01 the % error is small than with h=0.1\n\n !When x=pi/2 and x=pi/4 the values of d2cen(x,h) are identicle. \n\n !This is because these values create the maximum precision possible with the program.\n\n\n !COMPARE THE ANSWERS FOR N=10,20 AND 40. USE A=0 B=1.\n WRITE(6,*) \"Please input a suitable value for the value a\"\n READ(5,*) a\n WRITE(6,*) \" \"\n WRITE(6,*) \" \"\n WRITE(6,*) \"Please input a suitable value for the value b\"\n READ(5,*) b\n WRITE(6,*) \" \"\n WRITE(6,*) \" \"\n WRITE(6,*) \"Please input a suitable value for the number of intervals N\"\n READ(5,*) m\n WRITE(6,*) \" \"\n WRITE(6,*) \" \"\n\n !When N=10 Itrap = 0.2881906059881051+-5.1060593E-04 %\n !When N=20 Itrap = 0.4102154997487863+-0.1225355 %\n !When N=40 Itrap = 0.5181063142915567+-0.2304263 %\n\n !As N increases the % error increases, as does the answer Itrap\n\n !When N=10 Isimp = 0.2504462347909079+-3.7233766E-02 %\n !When N=20 Isimp = 0.3610162977907604+-7.3336296E-02 %\n !When N=40 Isimp = 0.4618389266198301+-0.1741589 %\n\n !As N increases the % error increases, as does the answer Itrap.\n\n !The % error produced by Isimp is smaller than Isimp and therefore is a better estimate\n\n\n !Integral of f(x)dx between 0 and 1\n Integral=0.28768\n\n !Error in trapesium rule\n eItrap=-(Integral-Itrap(a,b))\n\n !Error in Simpson's Rule\n eIsimp=-(Integral-Isimp(a,b))\n\n WRITE(6,*) \"An estimate of the value of the integral of the function f(x) was found using the Trapesium Rule\"\n WRITE(6,*) \" \"\n WRITE(6,*) \"The estimate is as follows:\"\n WRITE(6,*) Itrap(a,b),\"+-\",eItrap,\"%\"\n WRITE(6,*) \" \"\n WRITE(6,*) \" \"\n WRITE(6,*) \"An estimate of the value of the integral of the function f(x) was found using Simpson's Rule\"\n WRITE(6,*) \" \"\n WRITE(6,*) \"The estimate is as follows:\"\n WRITE(6,*) Isimp(a,b),\"+-\",eIsimp,\"%\"\n WRITE(6,*) \" \"\n WRITE(6,*) \" \"\n\n\n !This is where all of the functions are contained\n CONTAINS\n\n !function defining Simpson's Rule\n DOUBLE PRECISION FUNCTION Isimp(da,db)\n IMPLICIT NONE\n REAL, INTENT(IN) :: da,db\n e=0\n DO j=1,m-1,2\n e=f(da+(j+2)*h)+e\n END DO\n l=0\n k=0\n DO l=2,m-2,2\n k=f(da+l*h)+k\n END DO\n Isimp=(h/3.0)*(f(da)+f(db)+4*e+2*k)\n END FUNCTION Isimp\n\n !function defining trapesium rulE\n DOUBLE PRECISION FUNCTION Itrap(da,db)\n IMPLICIT NONE\n REAL, INTENT(IN) :: da,db\n z=0\n DO n=1,m-1,1\n z=f(da+n*h)+z\n END DO\n Itrap=(h/2.0)*(f(da)+f(db))+h*z\n END FUNCTION Itrap\n\n !function defining f(x)\n DOUBLE PRECISION FUNCTION f(xx)\n IMPLICIT NONE\n REAL, INTENT(IN) :: xx\n f=1/(xx**2+3*xx+2)\n END FUNCTION f\n\n !function subprogram dfor(x,h)\n !It is the forward difference approximation.\n !Used to compute the first dreivative at x using a step-length parameter h.\n DOUBLE PRECISION FUNCTION dfor(da,db)\n IMPLICIT NONE\n REAL, INTENT(IN) :: da,db\n dfor=(f(da+db)-f(da))/db\n END FUNCTION dfor\n\n !function subprogram dcen(x,h)\n !It is the centred difference approximation\n !Used to compute the first dreivative at x using a step-length parameter h.\n DOUBLE PRECISION FUNCTION dcen(da,db)\n IMPLICIT NONE\n REAL, INTENT(IN) :: da,db\n dcen=(f(da+db/2)-f(da-db/2))/db\n END FUNCTION dcen\n\n !function defining f'(x)\n DOUBLE PRECISION FUNCTION g(yx)\n IMPLICIT NONE\n REAL, INTENT(IN) :: yx\n g=(-2*yx-3)/(yx**2+3*yx+2)**2\n END FUNCTION g\n\n !function defining d2cen(x,h)\n DOUBLE PRECISION FUNCTION d2cen(da,db)\n IMPLICIT NONE\n REAL, INTENT(IN) :: da,db\n d2cen=(dcen(da+db/2,db)-dcen(da-db/2,db))/db\n END FUNCTION\n\n !function defining f''(x)\n DOUBLE PRECISION FUNCTION i(yx)\n IMPLICIT NONE\n REAL, INTENT(IN) :: yx\n i=-2*(3*yx**2+9*yx+7)/(yx**2+3*yx+2)**3\n END FUNCTION\n\nEND PROGRAM Finite_Difference_Methods\n", "meta": {"hexsha": "323dc7b8121d48d86845442a8f196a5f28954066", "size": 7576, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "6309823-Finite_Difference_Methods.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-Finite_Difference_Methods.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-Finite_Difference_Methods.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": 34.1261261261, "max_line_length": 120, "alphanum_fraction": 0.6205121436, "num_tokens": 2840, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339756938818, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.6845784175135592}} {"text": "*DECK DPBCO\n SUBROUTINE DPBCO (ABD, LDA, N, M, RCOND, Z, INFO)\nC***BEGIN PROLOGUE DPBCO\nC***PURPOSE Factor a real symmetric positive definite matrix stored in\nC band form and estimate the condition number of the matrix.\nC***LIBRARY SLATEC (LINPACK)\nC***CATEGORY D2B2\nC***TYPE DOUBLE PRECISION (SPBCO-S, DPBCO-D, CPBCO-C)\nC***KEYWORDS BANDED, CONDITION NUMBER, LINEAR ALGEBRA, LINPACK,\nC MATRIX FACTORIZATION, POSITIVE DEFINITE\nC***AUTHOR Moler, C. B., (U. of New Mexico)\nC***DESCRIPTION\nC\nC DPBCO factors a double precision symmetric positive definite\nC matrix stored in band form and estimates the condition of the\nC matrix.\nC\nC If RCOND is not needed, DPBFA is slightly faster.\nC To solve A*X = B , follow DPBCO by DPBSL.\nC To compute INVERSE(A)*C , follow DPBCO by DPBSL.\nC To compute DETERMINANT(A) , follow DPBCO by DPBDI.\nC\nC On Entry\nC\nC ABD DOUBLE PRECISION(LDA, N)\nC the matrix to be factored. The columns of the upper\nC triangle are stored in the columns of ABD and the\nC diagonals of the upper triangle are stored in the\nC rows of ABD . See the comments below for details.\nC\nC LDA INTEGER\nC the leading dimension of the array ABD .\nC LDA must be .GE. M + 1 .\nC\nC N INTEGER\nC the order of the matrix A .\nC\nC M INTEGER\nC the number of diagonals above the main diagonal.\nC 0 .LE. M .LT. N .\nC\nC On Return\nC\nC ABD an upper triangular matrix R , stored in band\nC form, so that A = TRANS(R)*R .\nC If INFO .NE. 0 , the factorization is not complete.\nC\nC RCOND DOUBLE PRECISION\nC an estimate of the reciprocal condition of A .\nC For the system A*X = B , relative perturbations\nC in A and B of size EPSILON may cause\nC relative perturbations in X of size EPSILON/RCOND .\nC If RCOND is so small that the logical expression\nC 1.0 + RCOND .EQ. 1.0\nC is true, then A may be singular to working\nC precision. In particular, RCOND is zero if\nC exact singularity is detected or the estimate\nC underflows. If INFO .NE. 0 , RCOND is unchanged.\nC\nC Z DOUBLE PRECISION(N)\nC a work vector whose contents are usually unimportant.\nC If A is singular to working precision, then Z is\nC an approximate null vector in the sense that\nC NORM(A*Z) = RCOND*NORM(A)*NORM(Z) .\nC If INFO .NE. 0 , Z is unchanged.\nC\nC INFO INTEGER\nC = 0 for normal return.\nC = K signals an error condition. The leading minor\nC of order K is not positive definite.\nC\nC Band Storage\nC\nC If A is a symmetric positive definite band matrix,\nC the following program segment will set up the input.\nC\nC M = (band width above diagonal)\nC DO 20 J = 1, N\nC I1 = MAX(1, J-M)\nC DO 10 I = I1, J\nC K = I-J+M+1\nC ABD(K,J) = A(I,J)\nC 10 CONTINUE\nC 20 CONTINUE\nC\nC This uses M + 1 rows of A , except for the M by M\nC upper left triangle, which is ignored.\nC\nC Example: If the original matrix is\nC\nC 11 12 13 0 0 0\nC 12 22 23 24 0 0\nC 13 23 33 34 35 0\nC 0 24 34 44 45 46\nC 0 0 35 45 55 56\nC 0 0 0 46 56 66\nC\nC then N = 6 , M = 2 and ABD should contain\nC\nC * * 13 24 35 46\nC * 12 23 34 45 56\nC 11 22 33 44 55 66\nC\nC***REFERENCES J. J. Dongarra, J. R. Bunch, C. B. Moler, and G. W.\nC Stewart, LINPACK Users' Guide, SIAM, 1979.\nC***ROUTINES CALLED DASUM, DAXPY, DDOT, DPBFA, DSCAL\nC***REVISION HISTORY (YYMMDD)\nC 780814 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890831 Modified array declarations. (WRB)\nC 890831 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900326 Removed duplicate information from DESCRIPTION section.\nC (WRB)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE DPBCO\n INTEGER LDA,N,M,INFO\n DOUBLE PRECISION ABD(LDA,*),Z(*)\n DOUBLE PRECISION RCOND\nC\n DOUBLE PRECISION DDOT,EK,T,WK,WKM\n DOUBLE PRECISION ANORM,S,DASUM,SM,YNORM\n INTEGER I,J,J2,K,KB,KP1,L,LA,LB,LM,MU\nC\nC FIND NORM OF A\nC\nC***FIRST EXECUTABLE STATEMENT DPBCO\n DO 30 J = 1, N\n L = MIN(J,M+1)\n MU = MAX(M+2-J,1)\n Z(J) = DASUM(L,ABD(MU,J),1)\n K = J - L\n IF (M .LT. MU) GO TO 20\n DO 10 I = MU, M\n K = K + 1\n Z(K) = Z(K) + ABS(ABD(I,J))\n 10 CONTINUE\n 20 CONTINUE\n 30 CONTINUE\n ANORM = 0.0D0\n DO 40 J = 1, N\n ANORM = MAX(ANORM,Z(J))\n 40 CONTINUE\nC\nC FACTOR\nC\n CALL DPBFA(ABD,LDA,N,M,INFO)\n IF (INFO .NE. 0) GO TO 180\nC\nC RCOND = 1/(NORM(A)*(ESTIMATE OF NORM(INVERSE(A)))) .\nC ESTIMATE = NORM(Z)/NORM(Y) WHERE A*Z = Y AND A*Y = E .\nC THE COMPONENTS OF E ARE CHOSEN TO CAUSE MAXIMUM LOCAL\nC GROWTH IN THE ELEMENTS OF W WHERE TRANS(R)*W = E .\nC THE VECTORS ARE FREQUENTLY RESCALED TO AVOID OVERFLOW.\nC\nC SOLVE TRANS(R)*W = E\nC\n EK = 1.0D0\n DO 50 J = 1, N\n Z(J) = 0.0D0\n 50 CONTINUE\n DO 110 K = 1, N\n IF (Z(K) .NE. 0.0D0) EK = SIGN(EK,-Z(K))\n IF (ABS(EK-Z(K)) .LE. ABD(M+1,K)) GO TO 60\n S = ABD(M+1,K)/ABS(EK-Z(K))\n CALL DSCAL(N,S,Z,1)\n EK = S*EK\n 60 CONTINUE\n WK = EK - Z(K)\n WKM = -EK - Z(K)\n S = ABS(WK)\n SM = ABS(WKM)\n WK = WK/ABD(M+1,K)\n WKM = WKM/ABD(M+1,K)\n KP1 = K + 1\n J2 = MIN(K+M,N)\n I = M + 1\n IF (KP1 .GT. J2) GO TO 100\n DO 70 J = KP1, J2\n I = I - 1\n SM = SM + ABS(Z(J)+WKM*ABD(I,J))\n Z(J) = Z(J) + WK*ABD(I,J)\n S = S + ABS(Z(J))\n 70 CONTINUE\n IF (S .GE. SM) GO TO 90\n T = WKM - WK\n WK = WKM\n I = M + 1\n DO 80 J = KP1, J2\n I = I - 1\n Z(J) = Z(J) + T*ABD(I,J)\n 80 CONTINUE\n 90 CONTINUE\n 100 CONTINUE\n Z(K) = WK\n 110 CONTINUE\n S = 1.0D0/DASUM(N,Z,1)\n CALL DSCAL(N,S,Z,1)\nC\nC SOLVE R*Y = W\nC\n DO 130 KB = 1, N\n K = N + 1 - KB\n IF (ABS(Z(K)) .LE. ABD(M+1,K)) GO TO 120\n S = ABD(M+1,K)/ABS(Z(K))\n CALL DSCAL(N,S,Z,1)\n 120 CONTINUE\n Z(K) = Z(K)/ABD(M+1,K)\n LM = MIN(K-1,M)\n LA = M + 1 - LM\n LB = K - LM\n T = -Z(K)\n CALL DAXPY(LM,T,ABD(LA,K),1,Z(LB),1)\n 130 CONTINUE\n S = 1.0D0/DASUM(N,Z,1)\n CALL DSCAL(N,S,Z,1)\nC\n YNORM = 1.0D0\nC\nC SOLVE TRANS(R)*V = Y\nC\n DO 150 K = 1, N\n LM = MIN(K-1,M)\n LA = M + 1 - LM\n LB = K - LM\n Z(K) = Z(K) - DDOT(LM,ABD(LA,K),1,Z(LB),1)\n IF (ABS(Z(K)) .LE. ABD(M+1,K)) GO TO 140\n S = ABD(M+1,K)/ABS(Z(K))\n CALL DSCAL(N,S,Z,1)\n YNORM = S*YNORM\n 140 CONTINUE\n Z(K) = Z(K)/ABD(M+1,K)\n 150 CONTINUE\n S = 1.0D0/DASUM(N,Z,1)\n CALL DSCAL(N,S,Z,1)\n YNORM = S*YNORM\nC\nC SOLVE R*Z = W\nC\n DO 170 KB = 1, N\n K = N + 1 - KB\n IF (ABS(Z(K)) .LE. ABD(M+1,K)) GO TO 160\n S = ABD(M+1,K)/ABS(Z(K))\n CALL DSCAL(N,S,Z,1)\n YNORM = S*YNORM\n 160 CONTINUE\n Z(K) = Z(K)/ABD(M+1,K)\n LM = MIN(K-1,M)\n LA = M + 1 - LM\n LB = K - LM\n T = -Z(K)\n CALL DAXPY(LM,T,ABD(LA,K),1,Z(LB),1)\n 170 CONTINUE\nC MAKE ZNORM = 1.0\n S = 1.0D0/DASUM(N,Z,1)\n CALL DSCAL(N,S,Z,1)\n YNORM = S*YNORM\nC\n IF (ANORM .NE. 0.0D0) RCOND = YNORM/ANORM\n IF (ANORM .EQ. 0.0D0) RCOND = 0.0D0\n 180 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "4dbca32ed07b231180272ae9da0604950a47d631", "size": 8679, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/dpbco.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/dpbco.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/dpbco.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.875, "max_line_length": 71, "alphanum_fraction": 0.4851941468, "num_tokens": 2956, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.868826789824086, "lm_q2_score": 0.787931190663057, "lm_q1q2_score": 0.6845757269860536}} {"text": " program Day5\r\n character line*12\r\n integer ids(1024),count,i,decode,filled(1032),seat\r\n\r\n count = 0\r\n\r\nc read input file \r\n open(1,FILE='input.txt',STATUS='OLD')\r\n do\r\n read(1,*,IOSTAT=io) line\r\n if (io.gt.0) then\r\n write(*,*) 'Error'\r\n exit\r\n else if(io.lt.0) then\r\n exit\r\n else\r\n write(*,*) line\r\n count = count+1\r\n ids(count) = decode(line)\r\n endif\r\n enddo\r\n 200 close(1)\r\n\r\nc create filled list\r\n do 275 i=1,1032\r\n filled(i) = 0\r\n 275 continue\r\n\r\nc update filled list\r\n do 300 i=1,count\r\n write(*,*) ids(i)\r\n filled(ids(i)) = 1\r\n 300 continue\r\n\r\nc find empty seat \r\n seat =-1\r\n do 325 i=2,1031\r\n if(filled(i).eq.0) then\r\n if (filled(i-1).eq.1.and.filled(i+1).eq.1) then\r\n seat = i\r\n write(*,*) 'Seat: ',seat\r\n endif\r\n endif\r\n 325 continue\r\n\r\n end\r\n\r\n function decode(line)\r\n integer decode\r\n character line*12\r\n integer s,e,row,column,i,half\r\n\r\n write(*,*) line\r\n\r\nc compute row\r\n row = 0\r\n s = 0\r\n e = 127\r\n do 100 i=1,7\r\n half =(e-s+1)/2\r\n if(i.eq.7) then\r\n if(line(i:i).eq.'F') then\r\n row = s\r\n else if (line(i:i).eq.'B') then\r\n row = e\r\n endif\r\n else\r\n if(line(i:i).eq.'F') then\r\n e =s+half-1\r\n else if (line(i:i).eq.'B') then\r\n s = e-half+1\r\n endif\r\n endif\r\n write(*,*) i,line(i:i),s,e,row\r\n 100 continue\r\n write(*,*) s,e,row\r\n\r\nc compute column\r\n column = 0\r\n s = 0\r\n e = 7\r\n do 150 i=8,10\r\n half =(e-s+1)/2\r\n if(i.eq.10) then\r\n if(line(i:i).eq.'L') then\r\n column = s\r\n else if (line(i:i).eq.'R') then\r\n column = e\r\n endif\r\n else\r\n if(line(i:i).eq.'L') then\r\n e =s+half-1\r\n else if (line(i:i).eq.'R') then\r\n s = e-half+1\r\n endif\r\n endif\r\n write(*,*) i,line(i:i),s,e,column\r\n 150 continue\r\n write(*,*) s,e,column\r\n decode = row * 8+column\r\n write(*,*) decode\r\n return\r\n end\r\n", "meta": {"hexsha": "35b16eacf3be1f30196d906e9c3c1b5a0de448fd", "size": 3019, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Day5/main.f", "max_stars_repo_name": "SleepingBearSystems/AdventOfCode2020", "max_stars_repo_head_hexsha": "a37fcedc1178bd20c8e7b5f805cf86b9502aa7bc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Day5/main.f", "max_issues_repo_name": "SleepingBearSystems/AdventOfCode2020", "max_issues_repo_head_hexsha": "a37fcedc1178bd20c8e7b5f805cf86b9502aa7bc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Day5/main.f", "max_forks_repo_name": "SleepingBearSystems/AdventOfCode2020", "max_forks_repo_head_hexsha": "a37fcedc1178bd20c8e7b5f805cf86b9502aa7bc", "max_forks_repo_licenses": ["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.0288461538, "max_line_length": 68, "alphanum_fraction": 0.3252732693, "num_tokens": 698, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267898240861, "lm_q2_score": 0.7879311856832191, "lm_q1q2_score": 0.6845757226594371}} {"text": "! Learn_dg - A quick and dirty project to deploy a working DG solver\n! Copyright (c) 2017, Chris Coutinho\n! All rights reserved.\n!\n! Licensed under the BSD-2 clause license. See LICENSE for details.\n\nmodule mod_linalg\n use, intrinsic :: iso_fortran_env, only: wp=>real64\n implicit none\n\n private\n public :: linsolve_quick, linsolve, inv2, det2, eye\n\ncontains\n\n pure function eye(N)\n ! Generates an identity matrix of size (N,N)\n integer, intent(in) :: N\n real(wp), dimension(N,N) :: eye\n\n integer :: ii\n\n eye = 0._wp\n\n forall(ii = 1:N) eye(ii,ii) = 1._wp\n\n return\n end function eye\n\n pure function inv2(J) result(invJ)\n ! Computes the inverse of a 2x2 matrix\n real(wp), dimension(2,2), intent(in) :: J\n real(wp), dimension(2,2) :: invJ\n\n invJ = reshape( [J(2,2), -J(2,1), -J(1,2), J(1,1)], [2,2] )\n invJ = invJ / det2(J)\n\n return\n end function inv2\n\n pure function det2(A) result(det)\n ! Computes the determinant of a 2x2 matrix\n real(wp), dimension(2,2), intent(in) :: A\n real(wp) :: det\n\n det = A(1,1)*A(2,2) - A(1,2)*A(2,1)\n\n return\n end function det2\n\n subroutine linsolve_quick(n, a, nrhs, b, x)\n ! Quick wrapper around linsolve\n integer, intent(in) :: n, nrhs\n real(wp), intent(in), dimension(n, n) :: a\n real(wp), intent(in), dimension(n, nrhs) :: b\n real(wp), intent(out), dimension(n, nrhs) :: x\n\n integer, dimension(n) :: P\n real(wp), dimension(n, n) :: LU\n\n call linsolve (n, a, nrhs, b, x, LU, P, .False.)\n return\n end subroutine linsolve_quick\n\n subroutine linsolve (n, a, nrhs, b, x, LU, P, toggle)\n\n ! Linsolve is a wrapper of dgesv, the main linear solver routine for\n ! general dense matrices in LAPACK. This routine splits dgesv into\n ! its two primary components:\n !\n ! dgetrf - Decomposes A into P*L*U\n ! dgetrs - Uses P*L*U to solve for x (Ax=b => (P*L*U)x=b)\n !\n ! Splitting these two up like this allows you to save the decomposed\n ! version of 'A' so that you don't have to do it again. If 'toggle'\n ! is equal to true, then the decomposition has already occured and\n ! LU can be trusted - OK to skip dgetrf\n\n ! Dummy variables\n integer, intent(in) :: n, nrhs\n integer, intent(inout), dimension(n) :: P\n real(wp), intent(in), dimension(n, n) :: a\n real(wp), intent(in), dimension(n, nrhs) :: b\n real(wp), intent(out), dimension(n, nrhs) :: x\n real(wp), intent(inout), dimension(n, n) :: LU\n logical, intent(in) :: toggle\n\n ! Local variables\n integer :: info\n integer, dimension(n) :: my_P\n real(wp), dimension(n, n) :: my_a\n real(wp), dimension(n, nrhs) :: my_b\n\n my_a = a\n my_b = b\n\n if ( .not. toggle ) then\n call dgetrf (n, n, my_a, n, my_P, info)\n\n if ( info /= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'DGETRF'\n write ( *, '(a,i8)' ) ' Factorization failed, INFO = ', info\n stop\n endif\n\n LU = my_a\n P = my_P\n\n endif\n\n call dgetrs ('No transpose', n, nrhs, LU, n, P, my_b, n, info)\n\n if ( info /= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'DGETRS'\n write ( *, '(a,i8)' ) ' Back substitution failed, INFO = ', info\n stop\n endif\n\n x = my_b\n\n return\n end subroutine linsolve\n\nend module mod_linalg\n", "meta": {"hexsha": "75fa92038954f754863d16c03ea8472a7cf74fa9", "size": 3671, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/linalg/mod_linalg.f90", "max_stars_repo_name": "cbcoutinho/learn_dg", "max_stars_repo_head_hexsha": "b22bf91d1a0daedb6b48590c7361c3a9c3c7f371", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2017-03-08T09:26:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-25T01:25:12.000Z", "max_issues_repo_path": "src/linalg/mod_linalg.f90", "max_issues_repo_name": "cbcoutinho/learn_dg", "max_issues_repo_head_hexsha": "b22bf91d1a0daedb6b48590c7361c3a9c3c7f371", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/linalg/mod_linalg.f90", "max_forks_repo_name": "cbcoutinho/learn_dg", "max_forks_repo_head_hexsha": "b22bf91d1a0daedb6b48590c7361c3a9c3c7f371", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-01-03T05:51:10.000Z", "max_forks_repo_forks_event_max_datetime": "2018-01-03T05:51:10.000Z", "avg_line_length": 28.905511811, "max_line_length": 72, "alphanum_fraction": 0.5358213021, "num_tokens": 1122, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267626522814, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.6845757099031576}} {"text": "subroutine convergence(phi, aw, ae, as, an, ap, b_phi, f_phi, dx, dy, imax, jmax, xi, xf, residual)\nuse parallel_variables\nuse parameters\nuse kind_parameters\nimplicit none\ninclude \"mpif.h\"\n\ninteger:: imax, jmax, iu, ju, xi, xf\nreal(kind=dp), dimension(imax, xi-1:xf+1):: phi, aw, ae, as, an, ap, b_phi, f_phi\nreal(kind=dp):: dx(imax), dy(jmax)\nreal(kind=dp):: residual\nreal(kind=dp):: local_sum_num, local_sum_den, temp1, temp2, global_sum_num, global_sum_den\n\nlocal_sum_num = 0.0d0\nlocal_sum_den = 0.0d0\n\ndo ju = xi,xf\n\n do iu = 2,imax-1\n\n temp1 = aw(iu,ju)*phi(iu-1,ju) + ae(iu,ju)*phi(iu+1,ju) + as(iu,ju)*phi(iu,ju-1) + an(iu,ju)*phi(iu,ju+1)\n temp2 = ap(iu,ju)*phi(iu,ju)\n !sum_num = sum_num + dabs(temp2-temp1-b_phi(iu,ju)*dx(iu)*dy(ju)-f_phi(iu,ju)*dx(iu)*dy(ju))\n local_sum_num = local_sum_num + dabs(temp2-temp1-b_phi(iu,ju)-f_phi(iu,ju))\n local_sum_den = local_sum_den + dabs(temp2)\n\n end do\n\nend do\n\ntlocal1 = MPI_WTime()\n\ncall MPI_Allreduce(local_sum_num, global_sum_num, 1, MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD, ierr)\ncall MPI_Allreduce(local_sum_den, global_sum_den, 1, MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD, ierr)\n\ntlocal2 = MPI_WTime()\n\ncommunication_time = communication_time + (tlocal2 - tlocal1)\n\nresidual = global_sum_num/global_sum_den\n\nend subroutine\n", "meta": {"hexsha": "79e6441646497f11682758d37aa1d1334e8c09d0", "size": 1341, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "convergence.f90", "max_stars_repo_name": "pratanuroy/Multigrid_Cavity", "max_stars_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-09-11T12:01:52.000Z", "max_stars_repo_stars_event_max_datetime": "2017-09-11T12:01:52.000Z", "max_issues_repo_path": "convergence.f90", "max_issues_repo_name": "pratanuroy/Multigrid_Cavity", "max_issues_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "convergence.f90", "max_forks_repo_name": "pratanuroy/Multigrid_Cavity", "max_forks_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.1860465116, "max_line_length": 114, "alphanum_fraction": 0.7009694258, "num_tokens": 473, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.893309411735131, "lm_q2_score": 0.766293653760418, "lm_q1q2_score": 0.6845373330570832}} {"text": "c\nc cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\n subroutine intpl0(x1,x2,lmax,yl)\nc ================================================================\nc\nc ****************************************************************\nc x2 0\nc calculate the integration: inte {dx P (x)}\nc x1 l\nc\nc and store in intpl0.\nc ****************************************************************\nc\n implicit none\nc\n integer lmax\n integer l\nc\n real*8 x1\n real*8 x2\n real*8 p0x1\n real*8 p0x2\n real*8 p1x1\n real*8 p1x2\n real*8 p2x1\n real*8 p2x2\n real*8 yl(0:lmax)\n real*8 one, pi\nc\n parameter (one=1.0d0)\n parameter (pi=3.141592653589793d0)\nc\n p0x1=one\n p0x2=one\n p1x1=x1\n p1x2=x2\n yl(0)=x2-x1\nc\n do l=2,lmax+1\n p2x1=((2*l-1)*x1*p1x1-(l-1)*p0x1)/dble(l)\n p2x2=((2*l-1)*x2*p1x2-(l-1)*p0x2)/dble(l)\n yl(l-1)=(p2x2-p2x1-x2*p1x2+x1*p1x1)/dble(l-1)\n p0x1=p1x1\n p0x2=p1x2\n p1x1=p2x1\n p1x2=p2x2\n enddo\nc\n! meis: transform to normalized Legendre functions\n do l=0,lmax\n yl(l)=yl(l)*sqrt(dble(2*l+1)/(4.0d0*pi))\n end do\n\n return\n end\n", "meta": {"hexsha": "2dba9c5e4bfe987edc3f8300db290508b2e9634d", "size": 1366, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/VORPOL/intpl0.f", "max_stars_repo_name": "rdietric/lsms", "max_stars_repo_head_hexsha": "8d0d5f01186abf9a1cc54db3f97f9934b422cf92", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2020-01-05T20:05:31.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T09:08:01.000Z", "max_issues_repo_path": "src/VORPOL/intpl0.f", "max_issues_repo_name": "rdietric/lsms", "max_issues_repo_head_hexsha": "8d0d5f01186abf9a1cc54db3f97f9934b422cf92", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2019-07-30T13:59:18.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T17:43:35.000Z", "max_forks_repo_path": "lsms/src/VORPOL/intpl0.f", "max_forks_repo_name": "hkershaw-brown/MuST", "max_forks_repo_head_hexsha": "9db4bc5061c2f2c4d7dfd92f53b4ef952602c070", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2020-02-11T17:04:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-28T09:23:46.000Z", "avg_line_length": 24.3928571429, "max_line_length": 70, "alphanum_fraction": 0.4180087848, "num_tokens": 489, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094032139576, "lm_q2_score": 0.766293653760418, "lm_q1q2_score": 0.6845373265273621}} {"text": "!\n! JACOBI\n! Jacobi diagonalizer with sorted output. Same calling sequence as\n! EISPACK routine, but must specify nrot!\n!\n SUBROUTINE jacobi (a, n, np, d, v, nrot)\n IMPLICIT CHARACTER (A-Z)\n!\n INTEGER n, np, nrot\n DOUBLEPRECISION a (np, n)\n DOUBLEPRECISION d (n)\n DOUBLEPRECISION v (np, n)\n!\n DOUBLEPRECISION onorm, dnorm\n DOUBLEPRECISION b, dma, q, t, c, s\n DOUBLEPRECISION atemp, vtemp, dtemp\n INTEGER i, j, k, l\n!\n DO 10000 j = 1, n\n DO 10010 i = 1, n\n v (i, j) = 0.0D0\n10010 CONTINUE\n v (j, j) = 1.0D0\n d (j) = a (j, j)\n10000 CONTINUE\n!\n DO 20000 l = 1, nrot\n dnorm = 0.0D0\n onorm = 0.0D0\n DO 20100 j = 1, n\n dnorm = dnorm + ABS (d (j))\n DO 20110 i = 1, j - 1\n onorm = onorm + ABS (a (i, j))\n20110 CONTINUE\n20100 CONTINUE\n IF (onorm / dnorm .LE. 0.0D0) GOTO 19999\n DO 21000 j = 2, n\n DO 21010 i = 1, j - 1\n b = a (i, j)\n IF (ABS (b) .GT. 0.0D0) THEN\n dma = d (j) - d (i)\n IF (ABS (dma) + ABS (b) .LE. ABS (dma)) THEN\n t = b / dma\n ELSE\n q = 0.5D0 * dma / b\n t = SIGN (1.0D0 / (ABS (q) + SQRT (1.0D0 + q * q)), q)\n ENDIF\n c = 1.0D0 / SQRT (t * t + 1.0D0)\n s = t * c\n a (i, j) = 0.0D0\n DO 21110 k = 1, i - 1\n atemp = c * a (k, i) - s * a (k, j)\n a (k, j) = s * a (k, i) + c * a (k, j)\n a (k, i) = atemp\n21110 CONTINUE\n DO 21120 k = i + 1, j - 1\n atemp = c * a (i, k) - s * a (k, j)\n a (k, j) = s * a (i, k) + c * a (k, j)\n a (i, k) = atemp\n21120 CONTINUE\n DO 21130 k = j + 1, n\n atemp = c * a (i, k) - s * a (j, k)\n a (j, k) = s * a (i, k) + c * a (j, k)\n a (i, k) = atemp\n21130 CONTINUE\n DO 21140 k = 1, n\n vtemp = c * v (k, i) - s * v (k, j)\n v (k, j) = s * v (k, i) + c * v (k, j)\n v (k, i) = vtemp\n21140 CONTINUE\n dtemp = c * c * d (i) + s * s * d (j) -&\n 2.0D0 * c * s * b\n d (j) = s * s * d (i) + c * c * d (j) +&\n 2.0D0 * c * s * b\n d (i) = dtemp\n ENDIF\n21010 CONTINUE\n21000 CONTINUE\n20000 CONTINUE\n19999 CONTINUE\n nrot = l\n!\n DO 30000 j = 1, n - 1\n k = j\n dtemp = d (k)\n DO 30100 i = j + 1, n\n IF (d (i) .LT. dtemp) THEN\n k = i\n dtemp = d (k)\n ENDIF\n30100 CONTINUE\n IF (k .GT. j) THEN\n d (k) = d (j)\n d (j) = dtemp\n DO 30200 i = 1, n\n dtemp = v (i, k)\n v (i, k) = v (i, j)\n v (i, j) = dtemp\n30200 CONTINUE\n ENDIF\n30000 CONTINUE\n!\nRETURN\nEND subroutine jacobi \n\n \n", "meta": {"hexsha": "04ef83f3c5e991cde31c9471063ce62884243cc2", "size": 3072, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "jacobi.f90", "max_stars_repo_name": "donshen/packmol", "max_stars_repo_head_hexsha": "b62e8abaf22106d2c6287a594fa8dff6afb11326", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 47, "max_stars_repo_stars_event_min_datetime": "2020-04-12T17:47:15.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T07:37:53.000Z", "max_issues_repo_path": "jacobi.f90", "max_issues_repo_name": "donshen/packmol", "max_issues_repo_head_hexsha": "b62e8abaf22106d2c6287a594fa8dff6afb11326", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2020-05-24T16:29:44.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-10T17:24:17.000Z", "max_forks_repo_path": "jacobi.f90", "max_forks_repo_name": "donshen/packmol", "max_forks_repo_head_hexsha": "b62e8abaf22106d2c6287a594fa8dff6afb11326", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2017-09-07T19:30:15.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-27T19:16:17.000Z", "avg_line_length": 28.7102803738, "max_line_length": 70, "alphanum_fraction": 0.3753255208, "num_tokens": 1167, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543488, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6845373239361389}} {"text": "! compile this program: gfortran stochastic-logistic.f90 -o logmod\n! run the compiled program, for example: ./logmod 20 1.0 1.4 20.0 0.1\n\nprogram main\n implicit none\n\n character(len=20), dimension(5) :: args\n integer :: i, t, n\n real, allocatable :: y(:)\n real :: yinit, r, k, thetasd, theta\n\n if (command_argument_count().NE.5) then\n write(*,*) \"ERROR: five command-line arguments required\"\n stop\n end if\n\n do i=1,command_argument_count()\n call get_command_argument(i, args(i))\n end do\n\n read(args(1), *) t\n read(args(2), *) yinit\n read(args(3), *) r\n read(args(4), *) k\n read(args(5), *) thetasd\n\n allocate(y(t))\n y(1) = yinit \n do n=2,t\n call random_normal(0.0,thetasd,theta)\n y(n) = y(n-1) * (r - r * (y(n-1) / k)) * exp(theta)\n end do\n print *, y\n deallocate(y)\n \nend program main\n\n! https://masuday.github.io/fortran_tutorial/random.html\nsubroutine random_stduniform(u)\n implicit none\n real,intent(out) :: u\n real :: r\n call random_number(r)\n u = 1 - r\nend subroutine random_stduniform\n\n! modified from https://masuday.github.io/fortran_tutorial/random.html\n! based on https://www.cse.wustl.edu/~jain/books/ftp/ch5f_slides.pdf\nsubroutine random_normal(mu,sigma,x)\n implicit none\n real,intent(in) :: mu,sigma\n real,intent(out) :: x\n real,parameter :: pi=3.14159265\n real :: u1,u2\n call random_stduniform(u1)\n call random_stduniform(u2)\n x = mu + sigma * cos(2 * pi * u1) * sqrt(-2 * log(u2))\nend subroutine random_normal\n", "meta": {"hexsha": "bda6f6b7799abbd26c6be24f10203b046207a365", "size": 1482, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "stochastic-logistic.f90", "max_stars_repo_name": "hinkelman/stochastic-population-model", "max_stars_repo_head_hexsha": "1c61b259cac0d1548f9e478f3fc79b1fa09ef42f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-06T15:39:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-06T15:39:20.000Z", "max_issues_repo_path": "stochastic-logistic.f90", "max_issues_repo_name": "hinkelman/stochastic-population-model", "max_issues_repo_head_hexsha": "1c61b259cac0d1548f9e478f3fc79b1fa09ef42f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "stochastic-logistic.f90", "max_forks_repo_name": "hinkelman/stochastic-population-model", "max_forks_repo_head_hexsha": "1c61b259cac0d1548f9e478f3fc79b1fa09ef42f", "max_forks_repo_licenses": ["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.1186440678, "max_line_length": 70, "alphanum_fraction": 0.6646423752, "num_tokens": 497, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093975331752, "lm_q2_score": 0.766293653760418, "lm_q1q2_score": 0.6845373221742146}} {"text": "c program DRISRANP\nc>> 1996-07-09 DRISRANP Krogh Added external statement.\nc>> 1994-10-19 DRISRANP Krogh Changes to use M77CON\nc>> 1994-06-23 DRISRANP Changing name to DRI[D/S]RANP.\nc>> 1987-12-09 DRISRANP Lawson Initial Code.\nc\nc Driver to demonstrate use of ISRANP to generate random integers\nc from the Poisson distribution with mean, XMEAN.\nc Program computes histogram for N samples.\nc ------------------------------------------------------------------\nc--S replaces \"?\": DRI?RANP, I?RANP, I?STA1, I?STA2\nc ------------------------------------------------------------------\n integer NCELLS, NI\n parameter(NCELLS = 7+2, NI = 100)\n external ISRANP\n integer I, IHIST(NCELLS), ISRANP, ISTATS(3), ITAB(NI), ILOW, J, N\n real XMEAN, XSTATS(2)\nc\n data N / 10000 /\n data ILOW / 0 /\n data XMEAN / 1.0e0 /\nc ------------------------------------------------------------------\n ISTATS(1) = 0\n do 30 J = 1, N/NI\n do 20 I = 1, NI\nc Get random integer.\n ITAB(I) = ISRANP(XMEAN)\n 20 continue\nc Accumulate statistics and histogram.\nc\n call ISSTA1(ITAB, NI, ISTATS, XSTATS, IHIST, ILOW, NCELLS)\n 30 continue\nc Print the statistics and histogram.\nc\n print '(11x,''Poisson random integers from ISRANP'')'\n print '(11x,''with XMEAN = '',g12.4,/1x)', XMEAN\n call ISSTA2(ISTATS, XSTATS, IHIST, ILOW, NCELLS)\n end\n", "meta": {"hexsha": "42eafb55ad9051b4ffd31101cc72c161052ada6c", "size": 1534, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drisranp.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drisranp.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drisranp.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.3333333333, "max_line_length": 72, "alphanum_fraction": 0.5078226858, "num_tokens": 463, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543488, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.6845373144005447}} {"text": "SUBROUTINE beam_mm(mm,fs,ell)\r\n!\r\n! This subroutine forms the consistent mass matrix of a beam element.\r\n!\r\n IMPLICIT NONE\r\n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\r\n REAL(iwp),INTENT(IN)::fs,ell\r\n REAL(iwp),INTENT(OUT)::mm(:,:)\r\n REAL(iwp)::fac\r\n fac=(fs*ell)/420.0_iwp \r\n mm(1,1)=156.0_iwp*fac\r\n mm(3,3)=mm(1,1)\r\n mm(1,2)=22.0_iwp*ell*fac\r\n mm(2,1)=mm(1,2)\r\n mm(3,4)=-mm(1,2)\r\n mm(4,3)=mm(3,4)\r\n mm(1,3)=54.0_iwp*fac\r\n mm(3,1)=mm(1,3)\r\n mm(1,4)=-13.0_iwp*ell*fac\r\n mm(4,1)=mm(1,4)\r\n mm(2,3)=-mm(1,4)\r\n mm(3,2)=mm(2,3)\r\n mm(2,2)=4.0_iwp*(ell**2)*fac\r\n mm(4,4)=mm(2,2)\r\n mm(2,4)=-3.0_iwp*(ell**2)*fac\r\n mm(4,2)=mm(2,4)\r\nRETURN\r\nEND SUBROUTINE beam_mm \r\n", "meta": {"hexsha": "3099c415c592a0b33d607341721987e1d079b7cb", "size": 660, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "src/libs/main/beam_mm.f03", "max_stars_repo_name": "leemargetts/PoreFEM", "max_stars_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/libs/main/beam_mm.f03", "max_issues_repo_name": "leemargetts/PoreFEM", "max_issues_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/libs/main/beam_mm.f03", "max_forks_repo_name": "leemargetts/PoreFEM", "max_forks_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.7586206897, "max_line_length": 70, "alphanum_fraction": 0.603030303, "num_tokens": 317, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741295151718, "lm_q2_score": 0.7185944046238982, "lm_q1q2_score": 0.6845144394590831}} {"text": " SUBROUTINE rubber1d(pr,lb,cmd,model,bet,elas)\r\n\r\n ! calculates stiffness and stresses for rubber and elastomeric\r\n ! foam materials\r\n\r\n IMPLICIT NONE\r\n ! DUMMY arguments\r\n LOGICAL, INTENT(IN) :: cmd ! .FALSE.: compute stress at mechanical strain\r\n ! .TRUE.: compute stress and tangent modulus at mechanical strain\r\n REAL(kind=8), INTENT(IN):: pr(12), & !(12) material constants\r\n lb ! Principal stretch\r\n INTEGER(kind=4), INTENT(IN) :: model !Model\r\n !1: Arruda-Boyce\r\n !2: Mooney-Rivlin\r\n !3: Neo-Hooke\r\n !4: Ogden (N=1)\r\n !5: Ogden (N=2)\r\n !6: Ogden (N=3)\r\n !7: Polynomial (N=1)\r\n !8: Polynomial (N=2)\r\n !9: Polynomial (N=3)\r\n !10: Reduced Polynomial (N=1)\r\n !11: Reduced Polynomial (N=2)\r\n !12: Reduced Polynomial (N=3)\r\n !13: Van der Waals (not implemented yet)\r\n !14: Yeoh\r\n !15: Hyperfoam (N=1)\r\n !16: Hyperfoam (N=2)\r\n !17: Hyperfoam (N=3)\r\n REAL(kind=8), INTENT(OUT) :: &\r\n elas, & ! elasticity tangent modulus\r\n bet ! If CMD Kirchhoff stress tau Else Second Piola-Kirchhoff\r\n\r\n LOGICAL :: ci1, ci2 ! use first and second invariants\r\n\r\n INTEGER(kind=4) nterm, & ! number of terms (sum) in the model\r\n kode, & ! model\r\n i,j,k ! index and pointers\r\n INTEGER(kind=4), PARAMETER :: ii(3) = (/ 1,3,6 /)\r\n\r\n REAL(kind=8) i1,i2,a1,a2,a3,a4,a5,lt,d1,d2,dd1,dd2,lb2 ! auxiliar terms\r\n\r\n\r\n !initializes number of terms\r\n ci1 = .TRUE. !compute I1 invariant derivatives\r\n ci2 = .FALSE. !do NOT compute I2 derivatives\r\n kode = model\r\n SELECT CASE (kode)\r\n CASE (2) !Mooney-Rivlin\r\n ci2 = .TRUE. !compute I2 derivatives\r\n CASE (4:6) !Ogden\r\n nterm = kode - 3 !number of terms to be considered\r\n ci1 = .FALSE. !compute I1 invariant derivatives\r\n CASE (7:9) !Polynomial\r\n nterm = kode - 6 !number of terms to be considered\r\n ci2 = .TRUE. !compute I2 derivatives\r\n CASE (10:12)!reduced polynomial\r\n nterm = kode - 9 !number of terms to be considered\r\n CASE (14) !yeoh\r\n kode = 12 !reduced polynomial\r\n nterm = 3 !number of terms to be considered\r\n CASE (15:17) !NOTE that isochoric approach is considered\r\n CALL runen2('Hyperfoam not implemented for 1-D problems')\r\n !nterm = kode - 14 !number of terms to be considered\r\n END SELECT\r\n\r\n ! compute stresses (plane stress isochoric)\r\n lt = 1d0/SQRT(lb) !isochoric\r\n lb2 = lb*lb !lb squared\r\n\r\n IF( ci1 )THEN\r\n ! first derivatives of I1\r\n d1 = 2d0*(lb-1d0/lb2) !I1,L\r\n i1 = lb2+2d0/lb !I1\r\n IF( ci2 )THEN\r\n ! first derivatives of I2\r\n d2 = 2d0*(1d0-1d0/lb/lb2) !I2,L\r\n i2 = 2d0*lb+1d0/lb2 !I2\r\n END IF\r\n END IF\r\n\r\n\r\n SELECT CASE (kode)\r\n CASE (1) !Arruda-Boyce\r\n ! pr(5) = Mu/5/lm^2, pr(6) = Mu 11/350/lm^4, pr(7) =Mu 19/1750/lm^6, ! pr(8) =Mu 519/134750/lm^8\r\n a1 = pr(4)+i1*(pr(5)+i1*(pr(6)+i1*(pr(7)+i1*pr(8)))) !Phi,I1\r\n bet = a1*d1\r\n\r\n CASE (2) !Mooney-Rivlin\r\n\r\n bet = pr(1)*d1 + pr(2)*d2\r\n\r\n CASE (3) !Neo-Hookean\r\n bet = pr(1)*d1\r\n\r\n CASE (4:6) !ogden\r\n k = 1 !pointer to properties array\r\n bet = 0d0 !Initializes Kirchhoff stress\r\n DO j=1,nterm !for each term\r\n a1 = pr(k+1) !exponent alpha\r\n bet = bet + pr(k)*(lb**a1 - lt**a1)\r\n k = k+2\r\n END DO\r\n bet = bet/lb\r\n\r\n CASE ( 7: 9) !polynomial model\r\n i1 = i1 - 3d0 !I1 - 3\r\n i2 = i2 - 3d0 !I2 - 3\r\n a1 = pr(1) !initializes Phi,I1\r\n a2 = pr(2) !initializes Phi,I2\r\n IF( nterm > 1 )THEN\r\n a1 = a1+2d0*pr(3)*i1 + pr(4)*i2\r\n a2 = a2+ pr(4)*i1 + 2d0*pr(5)*i2\r\n END IF\r\n IF( nterm > 2 )THEN\r\n a1 = a1+3d0*pr(6)*i1*i1 +2d0*pr(7)*i1*i2+ pr(8)*i2*i2\r\n a2 = a2+ pr(7)*i1*i1 + pr(8)*i1*i2+3d0*pr(9)*i2*i2\r\n END IF\r\n\r\n bet = a1*d1 + a2*d2\r\n\r\n CASE (10:12) !Reduced polynomial\r\n i1 = i1 - 3d0 !I1 - 3\r\n a1 = 0d0 !Initializes Phi,I1\r\n DO i=1,nterm\r\n a1 = a1 + pr(ii(i))*i*i1**(i-1) !Phi,I1\r\n END DO\r\n bet = a1*d1\r\n\r\n END SELECT\r\n\r\n IF( cmd ) THEN !to compute stiffness\r\n\r\n IF( ci1 )THEN\r\n ! Second Derivatives of First Invariant\r\n dd1= (2d0+4d0/lb2/lb) !I1,L,L\r\n IF( ci2 )THEN\r\n ! Second Derivatives of Second Invariant\r\n dd2= 6d0/lb2**2 !I2,L,L\r\n END IF\r\n END IF\r\n\r\n SELECT CASE (kode)\r\n\r\n CASE (1) !Arruda-Boyce\r\n a2 = pr(5)+i1*(2d0*pr(6)+i1*(3d0*pr(7)+i1*4d0*pr(8))) !Phi,I1,i2\r\n elas = a1*dd1 + a2*d1**2\r\n\r\n CASE (2) !Mooney-Rivlin\r\n elas = pr(1)*dd1 + pr(2)*dd2\r\n\r\n CASE (3) !Neo-Hookean\r\n elas = pr(1)*dd1\r\n\r\n CASE (4:6) !ogden\r\n elas = 0d0 !initializes\r\n k = 1\r\n DO j=1,nterm !for each term\r\n a1 = pr(k+1) !exponent\r\n a2 = a1-1\r\n a3 = a1/2d0+1d0\r\n elas = elas + pr(k)*(a2*lb**a1 + a3*lt**a1 ) !DS1/L1\r\n k = k+2\r\n END DO !DS1/L1\r\n elas = elas/lb2\r\n\r\n CASE ( 7: 9) !polynomial model\r\n a3 = 0 !a1,I1\r\n a4 = 0 !a1,I2 = a2,I1\r\n a5 = 0 !a2,I2\r\n IF( nterm > 1 )THEN\r\n a3 = 2d0*pr(3) !a1,I1\r\n a4 = pr(4) !a1,I2\r\n a5 = 2d0*pr(5) !a2,I1\r\n END IF\r\n IF( nterm > 2 )THEN\r\n a3 = a3+6d0*pr(6)*i1 +2d0*pr(7)*i2 !Phi,I1,I1\r\n a4 = a4+2d0*pr(7)*i1 +2d0*pr(8)*i2 !Phi,I1,I2\r\n a5 = a5+2d0*pr(8)*i1 +6d0*pr(9)*i2 !Phi,I2,I2\r\n END IF\r\n\r\n elas = a1*dd1 +a2*dd2 +a3*d1*d1 +2d0*a4*d1*d2 +a5*d2*d2\r\n\r\n CASE (10:12) !Reduced polynomial\r\n a2 = 0d0 !initializes Phi,I1,I1\r\n IF( nterm > 1 ) a2 = pr(3)*2d0 !Phi,I1,I1\r\n IF( nterm > 3 ) a2 = a2 + pr(6)*6d0*i1 !Phi,I1,I1\r\n elas = a1*dd1 + a2*d1**2\r\n\r\n END SELECT\r\n\r\n ! Kirchhoff stress\r\n bet = bet*lb\r\n elas = elas * lb2 + bet !Dt/Ln2\r\n\r\n ELSE\r\n !second Piola Kirchhoff\r\n bet = bet/lb\r\n\r\n END IF\r\n\r\n RETURN\r\n END SUBROUTINE rubber1d\r\n", "meta": {"hexsha": "7cd443c7d117c69ebded8121e65a058ffc6a5425", "size": 6760, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/matdb/rubber1d.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/matdb/rubber1d.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/matdb/rubber1d.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": 33.137254902, "max_line_length": 102, "alphanum_fraction": 0.4667159763, "num_tokens": 2404, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741214369554, "lm_q2_score": 0.7185943805178139, "lm_q1q2_score": 0.6845144106912898}} {"text": "*DECK SCHEX\n SUBROUTINE SCHEX (R, LDR, P, K, L, Z, LDZ, NZ, C, S, JOB)\nC***BEGIN PROLOGUE SCHEX\nC***PURPOSE Update the Cholesky factorization A=TRANS(R)*R of A\nC positive definite matrix A of order P under diagonal\nC permutations of the form TRANS(E)*A*E, where E is a\nC permutation matrix.\nC***LIBRARY SLATEC (LINPACK)\nC***CATEGORY D7B\nC***TYPE SINGLE PRECISION (SCHEX-S, DCHEX-D, CCHEX-C)\nC***KEYWORDS CHOLESKY DECOMPOSITION, EXCHANGE, LINEAR ALGEBRA, LINPACK,\nC MATRIX, POSITIVE DEFINITE\nC***AUTHOR Stewart, G. W., (U. of Maryland)\nC***DESCRIPTION\nC\nC SCHEX updates the Cholesky factorization\nC\nC A = TRANS(R)*R\nC\nC of a positive definite matrix A of order P under diagonal\nC permutations of the form\nC\nC TRANS(E)*A*E\nC\nC where E is a permutation matrix. Specifically, given\nC an upper triangular matrix R and a permutation matrix\nC E (which is specified by K, L, and JOB), SCHEX determines\nC an orthogonal matrix U such that\nC\nC U*R*E = RR,\nC\nC where RR is upper triangular. At the users option, the\nC transformation U will be multiplied into the array Z.\nC If A = TRANS(X)*X, so that R is the triangular part of the\nC QR factorization of X, then RR is the triangular part of the\nC QR factorization of X*E, i.e., X with its columns permuted.\nC For a less terse description of what SCHEX does and how\nC it may be applied, see the LINPACK guide.\nC\nC The matrix Q is determined as the product U(L-K)*...*U(1)\nC of plane rotations of the form\nC\nC ( C(I) S(I) )\nC ( ) ,\nC ( -S(I) C(I) )\nC\nC where C(I) is real. The rows these rotations operate on\nC are described below.\nC\nC There are two types of permutations, which are determined\nC by the value of JOB.\nC\nC 1. Right circular shift (JOB = 1).\nC\nC The columns are rearranged in the following order.\nC\nC 1,...,K-1,L,K,K+1,...,L-1,L+1,...,P.\nC\nC U is the product of L-K rotations U(I), where U(I)\nC acts in the (L-I,L-I+1)-plane.\nC\nC 2. Left circular shift (JOB = 2).\nC The columns are rearranged in the following order\nC\nC 1,...,K-1,K+1,K+2,...,L,K,L+1,...,P.\nC\nC U is the product of L-K rotations U(I), where U(I)\nC acts in the (K+I-1,K+I)-plane.\nC\nC On Entry\nC\nC R REAL(LDR,P), where LDR .GE. P.\nC R contains the upper triangular factor\nC that is to be updated. Elements of R\nC below the diagonal are not referenced.\nC\nC LDR INTEGER.\nC LDR is the leading dimension of the array R.\nC\nC P INTEGER.\nC P is the order of the matrix R.\nC\nC K INTEGER.\nC K is the first column to be permuted.\nC\nC L INTEGER.\nC L is the last column to be permuted.\nC L must be strictly greater than K.\nC\nC Z REAL(LDZ,NZ), where LDZ.GE.P.\nC Z is an array of NZ P-vectors into which the\nC transformation U is multiplied. Z is\nC not referenced if NZ = 0.\nC\nC LDZ INTEGER.\nC LDZ is the leading dimension of the array Z.\nC\nC NZ INTEGER.\nC NZ is the number of columns of the matrix Z.\nC\nC JOB INTEGER.\nC JOB determines the type of permutation.\nC JOB = 1 right circular shift.\nC JOB = 2 left circular shift.\nC\nC On Return\nC\nC R contains the updated factor.\nC\nC Z contains the updated matrix Z.\nC\nC C REAL(P).\nC C contains the cosines of the transforming rotations.\nC\nC S REAL(P).\nC S contains the sines of the transforming rotations.\nC\nC***REFERENCES J. J. Dongarra, J. R. Bunch, C. B. Moler, and G. W.\nC Stewart, LINPACK Users' Guide, SIAM, 1979.\nC***ROUTINES CALLED SROTG\nC***REVISION HISTORY (YYMMDD)\nC 780814 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890531 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900326 Removed duplicate information from DESCRIPTION section.\nC (WRB)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE SCHEX\n INTEGER LDR,P,K,L,LDZ,NZ,JOB\n REAL R(LDR,*),Z(LDZ,*),S(*)\n REAL C(*)\nC\n INTEGER I,II,IL,IU,J,JJ,KM1,KP1,LMK,LM1\n REAL T\nC\nC INITIALIZE\nC\nC***FIRST EXECUTABLE STATEMENT SCHEX\n KM1 = K - 1\n KP1 = K + 1\n LMK = L - K\n LM1 = L - 1\nC\nC PERFORM THE APPROPRIATE TASK.\nC\n GO TO (10,130), JOB\nC\nC RIGHT CIRCULAR SHIFT.\nC\n 10 CONTINUE\nC\nC REORDER THE COLUMNS.\nC\n DO 20 I = 1, L\n II = L - I + 1\n S(I) = R(II,L)\n 20 CONTINUE\n DO 40 JJ = K, LM1\n J = LM1 - JJ + K\n DO 30 I = 1, J\n R(I,J+1) = R(I,J)\n 30 CONTINUE\n R(J+1,J+1) = 0.0E0\n 40 CONTINUE\n IF (K .EQ. 1) GO TO 60\n DO 50 I = 1, KM1\n II = L - I + 1\n R(I,K) = S(II)\n 50 CONTINUE\n 60 CONTINUE\nC\nC CALCULATE THE ROTATIONS.\nC\n T = S(1)\n DO 70 I = 1, LMK\n CALL SROTG(S(I+1),T,C(I),S(I))\n T = S(I+1)\n 70 CONTINUE\n R(K,K) = T\n DO 90 J = KP1, P\n IL = MAX(1,L-J+1)\n DO 80 II = IL, LMK\n I = L - II\n T = C(II)*R(I,J) + S(II)*R(I+1,J)\n R(I+1,J) = C(II)*R(I+1,J) - S(II)*R(I,J)\n R(I,J) = T\n 80 CONTINUE\n 90 CONTINUE\nC\nC IF REQUIRED, APPLY THE TRANSFORMATIONS TO Z.\nC\n IF (NZ .LT. 1) GO TO 120\n DO 110 J = 1, NZ\n DO 100 II = 1, LMK\n I = L - II\n T = C(II)*Z(I,J) + S(II)*Z(I+1,J)\n Z(I+1,J) = C(II)*Z(I+1,J) - S(II)*Z(I,J)\n Z(I,J) = T\n 100 CONTINUE\n 110 CONTINUE\n 120 CONTINUE\n GO TO 260\nC\nC LEFT CIRCULAR SHIFT\nC\n 130 CONTINUE\nC\nC REORDER THE COLUMNS\nC\n DO 140 I = 1, K\n II = LMK + I\n S(II) = R(I,K)\n 140 CONTINUE\n DO 160 J = K, LM1\n DO 150 I = 1, J\n R(I,J) = R(I,J+1)\n 150 CONTINUE\n JJ = J - KM1\n S(JJ) = R(J+1,J+1)\n 160 CONTINUE\n DO 170 I = 1, K\n II = LMK + I\n R(I,L) = S(II)\n 170 CONTINUE\n DO 180 I = KP1, L\n R(I,L) = 0.0E0\n 180 CONTINUE\nC\nC REDUCTION LOOP.\nC\n DO 220 J = K, P\n IF (J .EQ. K) GO TO 200\nC\nC APPLY THE ROTATIONS.\nC\n IU = MIN(J-1,L-1)\n DO 190 I = K, IU\n II = I - K + 1\n T = C(II)*R(I,J) + S(II)*R(I+1,J)\n R(I+1,J) = C(II)*R(I+1,J) - S(II)*R(I,J)\n R(I,J) = T\n 190 CONTINUE\n 200 CONTINUE\n IF (J .GE. L) GO TO 210\n JJ = J - K + 1\n T = S(JJ)\n CALL SROTG(R(J,J),T,C(JJ),S(JJ))\n 210 CONTINUE\n 220 CONTINUE\nC\nC APPLY THE ROTATIONS TO Z.\nC\n IF (NZ .LT. 1) GO TO 250\n DO 240 J = 1, NZ\n DO 230 I = K, LM1\n II = I - KM1\n T = C(II)*Z(I,J) + S(II)*Z(I+1,J)\n Z(I+1,J) = C(II)*Z(I+1,J) - S(II)*Z(I,J)\n Z(I,J) = T\n 230 CONTINUE\n 240 CONTINUE\n 250 CONTINUE\n 260 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "5ad79468da0e5a96201fd12f67a735284cb3ee9d", "size": 7775, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/schex.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/schex.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/schex.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.1198501873, "max_line_length": 72, "alphanum_fraction": 0.498778135, "num_tokens": 2532, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942067038784, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6845112703861916}} {"text": "!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 2005 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Fishpack *\n! * *\n! * A Package of Fortran *\n! * *\n! * Subroutines and Example Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams, Paul Swarztrauber and Roland Sweet *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\nprogram test_hwscsp\n\n use fishpack\n\n ! Explicit typing only\n implicit none\n\n ! Dictionary\n type(FishpackWorkspace) :: workspace\n integer(ip), parameter :: M = 36, N = 32\n integer(ip), parameter :: MP1 = M + 1, NP1 = N + 1\n integer(ip), parameter :: IDIMF = M + 12\n integer(ip) :: intl, mbdcnd, nbdcnd, i, j, ierror\n real(wp) :: f(IDIMF, NP1), theta(IDIMF)\n real(wp), dimension(NP1) :: bdtf, r\n real(wp), dimension(1) :: bdts, bdrs, bdrf\n real(wp) :: ts, tf, rs, rf, elmbda\n real(wp) :: dtheta, dr, pertrb, dphi\n real(wp) :: ZERO = 0.0_wp, ONE = 1.0_wp, TWO = 2.0_wp\n\n ! Initialization flag\n intl = 0\n\n ! Set domain\n ts = ZERO\n tf = HALF_PI\n rs = ZERO\n rf = ONE\n\n ! Set boundary conditions\n mbdcnd = 6\n nbdcnd = 5\n\n ! Set helmholtz constant\n elmbda = ZERO\n\n ! Set mesh sizes\n dtheta = tf/M\n dr = ONE /N\n\n ! Generate and store grid points for the purpose of computing the\n ! boundary data and the right side of the equation.\n do i = 1, MP1\n theta(i) = real(i - 1, kind=wp) * dtheta\n end do\n\n do j = 1, NP1\n r(j) = real(j - 1, kind=wp) * dr\n end do\n\n ! Generate normal derivative data at equator\n ! In our example, bdts, bdrs, and bdrf are 1-dimensional dummy variables\n bdtf = ZERO\n\n ! Compute boundary data on the surface of the sphere\n do i = 1, MP1\n f(i, NP1) = cos(theta(i))**4\n end do\n\n ! Compute right hand side of equation\n block\n real(wp) :: cost2\n real(wp), parameter :: TWELVE = 12.0_wp\n\n do i = 1, MP1\n cost2 = cos(theta(i))**2\n f(i, :N) = TWELVE * cost2 * (r(:N)**2)\n end do\n end block\n\n ! Solve 2D axisymmetric Helmholtz equation on centered grid\n call hwscsp(intl, ts, tf, M, mbdcnd, bdts, bdtf, rs, rf, N, &\n nbdcnd, bdrs, bdrf, elmbda, f, IDIMF, pertrb, ierror, workspace)\n\n ! Compute discretization error\n block\n real(wp), parameter :: KNOWN_ERROR = 0.799841637481730e-3_wp\n real(wp) :: discretization_error, exact_solution(MP1, N)\n\n do j = 1, N\n do i = 1, MP1\n exact_solution(i,j) = (cos(theta(i))**4) * (r(j)**4)\n end do\n end do\n\n ! Set discretization error\n discretization_error = maxval(abs(exact_solution - f(:MP1,:N)))\n\n call check_output('hwscsp example 1', ierror, KNOWN_ERROR, discretization_error)\n end block\n\n ! The following program illustrates the use of hwscsp to solve\n ! a three dimensional problem which has longitudinal dependence\n mbdcnd = 2\n nbdcnd = 1\n dphi = PI/72\n elmbda = -TWO *(ONE - cos(dphi))/dphi**2\n\n ! Compute boundary data on the surface of the sphere\n do i = 1, MP1\n f(i, NP1) = sin(theta(i))\n end do\n\n ! Compute right side of the equation\n f(:MP1, :N) = ZERO\n\n ! Solve system\n call hwscsp(intl, ts, tf, M, mbdcnd, bdts, bdtf, rs, rf, N, &\n nbdcnd, bdrs, bdrf, elmbda, f, IDIMF, pertrb, ierror, workspace)\n\n ! Compute discretization error (fourier coefficients)\n block\n real(wp), parameter :: KNOWN_ERROR = 0.586824289033339e-4_wp\n real(wp) :: exact_solution(MP1,NP1), discretization_error\n\n discretization_error = ZERO\n do j = 1, NP1\n do i = 1, MP1\n exact_solution(i,j) = r(j) * sin(theta(i))\n end do\n end do\n\n ! Set discretization error\n discretization_error = maxval(abs(exact_solution - f(:MP1,:NP1)))\n\n call check_output('hwscsp example 2', ierror, KNOWN_ERROR, discretization_error)\n end block\n\n ! Release memory\n call workspace%destroy()\n\nend program test_hwscsp\n", "meta": {"hexsha": "293d88bfc3254094c077a5c4719bf9ac02a10425", "size": 6026, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/thwscsp.f90", "max_stars_repo_name": "jlokimlin/fishpack", "max_stars_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2018-03-12T11:31:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-27T07:58:23.000Z", "max_issues_repo_path": "examples/thwscsp.f90", "max_issues_repo_name": "jlokimlin/fishpack", "max_issues_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2016-05-07T22:42:47.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-15T17:44:58.000Z", "max_forks_repo_path": "examples/thwscsp.f90", "max_forks_repo_name": "jlokimlin/fishpack", "max_forks_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-09-07T15:43:32.000Z", "max_forks_repo_forks_event_max_datetime": "2018-06-16T21:30:13.000Z", "avg_line_length": 36.3012048193, "max_line_length": 88, "alphanum_fraction": 0.4155326917, "num_tokens": 1505, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942041005328, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.684511268413391}} {"text": "! subroutine geo2metres_pixel_size\nSUBROUTINE geo2metres_pixel_size(ycent,hx,hy,spheroid, &\n hx_out,hy_out,istat)\n\n! integer subroutine to get pixel size for geographic coordinates\n! depends only on latitude ycent\n! ycent, hx and hy are in degrees\n! hx_out and hy_out are in metres\n! spheroid is wgs84 which is appropriate here\n\n! * Re-written as an indepentent subroutine by JS, Aug 2014\n! * Probable overlap with subroutine pixelsize(rlat,dres,dx,dy)???\n! * pixelsize(rlat,dres,dx,dy) & pixelsize(rlat,dres,dx,dy,pia)\n! have now been replaced by this routine which itself has\n! been renamed to geo2metres_pixel_size which describes the\n! routine a little better.\n! * The routine now takes a 4 element spheroid parameter rather\n! than hard coded WGS84 parameters.\n\n! Inputs:\n! ycent\n! hx\n! hy\n! spheroid\n! 1. Spheroid major axis\n! 2. Inverse flattening\n! 3. Eccentricity squared\n! 4. Earth rotational angular velocity rad/sec\n!\n! Outputs:\n! hx_out\n! hy_out\n! istat\n\n use sys_variables, only : pi, d2r, r2d\n\n implicit none\n\n double precision ycent\n double precision hx, hy, hx_out, hy_out\n\n double precision spheroid(4)\n double precision asph, finv\n\n double precision yc, a_e, b_e, p_e, q_e, Earth_Radius, d_phi\n\n integer istat\n\n! Spheroid parameters\n! Spheroid major axis\n! Inverse flattening\n asph = spheroid(1)\n finv = spheroid(2)\n\n yc = ycent*d2r\n a_e = asph\n b_e = a_e*(1.0d0-1.0d0/finv)\n p_e = a_e*cos(yc)\n q_e = b_e*sin(yc)\n Earth_Radius = sqrt(((a_e*p_e)**2+(b_e*q_e)**2)/(p_e**2+q_e**2))\n d_phi = (sin(yc))**2+cos(hx*d2r)*(cos(yc))**2\n d_phi = acos(d_phi)\n\n hx_out = d_phi*Earth_Radius\n hy_out = (hy*d2r)*Earth_Radius\n\n istat = 0\n\n return\n\nEND SUBROUTINE geo2metres_pixel_size\n", "meta": {"hexsha": "c88b3312413186c46ddcb2f0326fa19388167e83", "size": 1890, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "wagl/f90_sources/geo2metres_pixel_size.f90", "max_stars_repo_name": "Oceancolour-RG/wagl", "max_stars_repo_head_hexsha": "f002a1c0a373d21758d44d2a808bdfd755d90226", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2018-05-30T23:42:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-25T14:21:46.000Z", "max_issues_repo_path": "wagl/f90_sources/geo2metres_pixel_size.f90", "max_issues_repo_name": "Oceancolour-RG/wagl", "max_issues_repo_head_hexsha": "f002a1c0a373d21758d44d2a808bdfd755d90226", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 52, "max_issues_repo_issues_event_min_datetime": "2018-02-20T05:31:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-23T23:38:15.000Z", "max_forks_repo_path": "wagl/f90_sources/geo2metres_pixel_size.f90", "max_forks_repo_name": "Oceancolour-RG/wagl", "max_forks_repo_head_hexsha": "f002a1c0a373d21758d44d2a808bdfd755d90226", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2018-02-20T05:08:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-12T23:16:41.000Z", "avg_line_length": 26.25, "max_line_length": 68, "alphanum_fraction": 0.6555555556, "num_tokens": 614, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850004144266, "lm_q2_score": 0.731058584489497, "lm_q1q2_score": 0.6844791870817188}} {"text": "C$Procedure DRDGEO ( Derivative of rectangular w.r.t. geodetic )\n \n SUBROUTINE DRDGEO ( LONG, LAT, ALT, RE, F, JACOBI )\n IMPLICIT NONE\n \nC$ Abstract\nC\nC This routine computes the Jacobian of the transformation from\nC geodetic to rectangular coordinates.\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 COORDINATES\nC DERIVATIVES\nC MATRIX\nC\nC$ Declarations\n \n DOUBLE PRECISION LONG\n DOUBLE PRECISION LAT\n DOUBLE PRECISION ALT\n DOUBLE PRECISION RE\n DOUBLE PRECISION F\n DOUBLE PRECISION JACOBI ( 3, 3 )\n \nC$ Brief_I/O\nC\nC Variable I/O Description\nC -------- --- --------------------------------------------------\nC LONG I Geodetic longitude of point (radians).\nC LAT I Geodetic latitude of point (radians).\nC ALT I Altitude of point above the reference spheroid.\nC RE I Equatorial radius of the reference spheroid.\nC F I Flattening coefficient.\nC JACOBI O Matrix of partial derivatives.\nC\nC$ Detailed_Input\nC\nC LONG Geodetic longitude of point (radians).\nC\nC LAT Geodetic latitude of point (radians).\nC\nC ALT Altitude of point above the reference spheroid.\nC\nC RE Equatorial radius of the reference spheroid.\nC\nC F Flattening coefficient = (RE-RP) / RE, where RP is\nC the polar radius of the spheroid. (More importantly\nC RP = RE*(1-F).)\nC\nC$ Detailed_Output\nC\nC JACOBI is the matrix of partial derivatives of the conversion\nC between geodetic and rectangular coordinates. It\nC has the form\nC\nC .- -.\nC | DX/DLONG DX/DLAT DX/DALT |\nC | DY/DLONG DY/DLAT DY/DALT |\nC | DZ/DLONG DZ/DLAT DZ/DALT |\nC `- -'\nC\nC evaluated at the input values of LONG, LAT and ALT.\nC\nC The formulae for computing X, Y, and Z from\nC geodetic coordinates are given below.\nC\nC X = [ALT + RE/G(LAT,F)]*COS(LONG)*COS(LAT)\nC Y = [ALT + RE/G(LAT,F)]*SIN(LONG)*COS(LAT)\nC Z = [ALT + RE*(1-F)**2/G(LAT,F)]* SIN(LAT)\nC\nC where\nC\nC RE is the polar radius of the reference spheroid.\nC\nC F is the flattening factor (the polar radius is\nC obtained by multiplying the equatorial radius by\nC 1-F).\nC\nC G( LAT, F ) is given by\nC\nC sqrt ( cos(lat)**2 + (1-f)**2 * sin(lat)**2 )\nC\nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC 1) If the flattening coefficient is greater than or equal to\nC one, the error SPICE(VALUEOUTOFRANGE) is signaled.\nC\nC 2) If the equatorial radius is non-positive, the error\nC SPICE(BADRADIUS) is signaled.\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC It is often convenient to describe the motion of an object in\nC the geodetic coordinate system. However, when performing\nC vector computations its hard to beat rectangular coordinates.\nC\nC To transform states given with respect to geodetic coordinates\nC to states with respect to rectangular coordinates, one makes use\nC of the Jacobian of the transformation between the two systems.\nC\nC Given a state in geodetic coordinates\nC\nC ( long, lat, alt, dlong, dlat, dalt )\nC\nC the velocity in rectangular coordinates is given by the matrix\nC equation:\nC\nC t | t\nC (dx, dy, dz) = JACOBI| * (dlong, dlat, dalt)\nC |(long,lat,alt)\nC\nC\nC This routine computes the matrix \nC\nC |\nC JACOBI|\nC |(long,lat,alt)\nC\nC$ Examples\nC\nC Suppose that one has a model that gives radius, longitude and\nC latitude as a function of time (long(t), lat(t), alt(t) ) for\nC which the derivatives ( dlong/dt, dlat/dt, dalt/dt ) are\nC computable.\nC\nC To find the velocity of the object in bodyfixed rectangular\nC coordinates, one simply multiplies the Jacobian of the\nC transformation from geodetic to rectangular coordinates,\nC evaluated at (long(t), lat(t), alt(t) ), by the vector of \nC derivatives of the geodetic coordinates.\nC\nC In code this looks like:\nC\nC C\nC C Load the derivatives of long, lat, and alt into the\nC C geodetic velocity vector GEOV.\nC C\nC GEOV(1) = DLONG_DT ( T )\nC GEOV(2) = DLAT_DT ( T )\nC GEOV(3) = DALT_DT ( T )\nC\nC C\nC C Determine the Jacobian of the transformation from\nC C geodetic to rectangular coordinates at the geodetic \nC C coordinates of time T.\nC C\nC CALL DRDGEO ( LONG(T), LAT(T), ALT(T), RE, F, JACOBI )\nC\nC C\nC C Multiply the Jacobian on the right by the geodetic\nC C velocity to obtain the rectangular velocity RECV.\nC C\nC CALL MXV ( JACOBI, GEOV, RECV )\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC W.L. Taber (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.0, 20-JUL-2001 (WLT)\nC\nC-&\n \nC$ Index_Entries\nC\nC Jacobian of rectangular w.r.t. geodetic coordinates\nC\nC-&\n \nC$ Revisions\nC\nC None.\nC\nC-&\n \n \nC\nC SPICELIB functions\nC\n LOGICAL RETURN\n \nC\nC Local parameters\nC\n INTEGER DX\n PARAMETER ( DX = 1 )\n \n INTEGER DY\n PARAMETER ( DY = 2 )\n \n INTEGER DZ\n PARAMETER ( DZ = 3 )\n \n INTEGER DLON\n PARAMETER ( DLON = 1 )\n \n INTEGER DLAT\n PARAMETER ( DLAT = 2 )\n \n INTEGER DALT\n PARAMETER ( DALT = 3 )\n \nC\nC Local variables\nC\n DOUBLE PRECISION CLAT\n DOUBLE PRECISION CLON\n DOUBLE PRECISION DGDLAT\n DOUBLE PRECISION G\n DOUBLE PRECISION SLAT\n DOUBLE PRECISION SLON\n\n DOUBLE PRECISION FLAT\n DOUBLE PRECISION FLAT2\n DOUBLE PRECISION G2\n \nC\nC Standard SPICE error handling.\nC\n IF ( RETURN () ) THEN\n RETURN\n ELSE\n CALL CHKIN ( 'DRDGEO' )\n END IF\n \nC\nC If the flattening coefficient is greater than one, the polar\nC radius computed below is negative. If it's equal to one, the\nC polar radius is zero. Either case is a problem, so signal an\nC error and check out.\nC\n IF ( F .GE. 1.0D0 ) THEN\n\n CALL SETMSG ( 'Flattening coefficient was *.' )\n CALL ERRDP ( '*', F )\n CALL SIGERR ( 'SPICE(VALUEOUTOFRANGE)' )\n CALL CHKOUT ( 'DRDGEO' )\n RETURN\n\n END IF\n \n IF ( RE .LE. 0.0D0 ) THEN\n\n CALL SETMSG ( 'Equatorial Radius <= 0.0D0. RE = *' )\n CALL ERRDP ( '*', RE )\n CALL SIGERR ( 'SPICE(BADRADIUS)' )\n CALL CHKOUT ( 'DRDGEO' )\n RETURN\n\n END IF\n \nC\nC For the record, here is a derivation of the formulae for the\nC values of x, y and z as a function of longitude, latitude and\nC altitude.\nC\nC First, let's take the case where the longitude is 0. Moreover,\nC lets assume that the length of the equatorial axis is a and\nC that the polar axis is b:\nC\nC a = re\nC b = re * (1-f)\nC\nC For any point on the spheroid where y is zero we know that there\nC is a unique q in the range (-Pi, Pi] such that\nC\nC x = a cos(q) and z = b sin(q).\nC\nC The normal to the surface at such a point is given by\nC\nC cos(q) sin(q)\nC ( ------- , ------- )\nC a b\nC\nC The unit vector in the same direction is\nC\nC b cos(q) a sin(q)\nC ( -------------------------- , -------------------------- )\nC ______________________ ______________________\nC / 2 2 2 2 / 2 2 2 2\nC \\/ b cos (q) + a sin (q) \\/ b cos (q) + a sin (q)\nC\nC\nC The first component of this term is by definition equal to the\nC cosine of the geodetic latitude, thus\nC\nC ______________________\nC / 2 2 2 2\nC b cos(q) = cos(lat) \\/ b cos (q) + a sin (q)\nC\nC\nC This can be transformed to the equation\nC\nC ______________________________\nC / 2 2 2 2\nC b cos(q) = cos(lat) \\/ ( b - a )cos (q) + a\nC\nC\nC Squaring both sides and rearranging terms gives:\nC\nC 2 2 2 2 2 2 2 2\nC b cos (q) + cos (lat) ( a - b ) cos (q) = a cos (lat)\nC\nC Thus\nC 2 2\nC 2 a cos (lat)\nC cos (q) = --------------------------\nC 2 2 2 2\nC b sin (lat) + a cos (lat)\nC\nC\nC\nC cos (lat)\nC = ------------------------------\nC _____________________________\nC / 2 2 2\nC \\/ (b/a) sin (lat) + cos (lat)\nC\nC\nC\nC cos (lat)\nC = ---------------------------------\nC _____________________________\nC / 2 2 2\nC \\/ (1-f) sin (lat) + cos (lat)\nC\nC\nC\nC From this one can also conclude that\nC\nC\nC (1-f) sin (lat)\nC sin(q) = ----------------------------------\nC _____________________________\nC / 2 2 2\nC \\/ (1-f) sin (lat) + cos (lat)\nC\nC\nC\nC Thus the point on the surface of the spheroid is given by\nC\nC re * cos (lat)\nC x_0 = ---------------------------------\nC _____________________________\nC / 2 2 2\nC \\/ (1-f) sin (lat) + cos (lat)\nC\nC\nC\nC 2\nC re * (1-f) sin (lat)\nC z_0 = ----------------------------------\nC _____________________________\nC / 2 2 2\nC \\/ (1-f) sin (lat) + cos (lat)\nC\nC\nC Thus given a point with the same latitude but a non-zero\nC longitude, one can conclude that\nC\nC re * cos (long) *cos (lat)\nC x_0 = ---------------------------------\nC _____________________________\nC / 2 2 2\nC \\/ (1-f) sin (lat) + cos (lat)\nC\nC\nC\nC re * sin (long) cos (lat)\nC y_0 = ---------------------------------\nC _____________________________\nC / 2 2 2\nC \\/ (1-f) sin (lat) + cos (lat)\nC\nC\nC 2\nC re * (1-f) sin (lat)\nC z_0 = ----------------------------------\nC _____________________________\nC / 2 2 2\nC \\/ (1-f) sin (lat) + cos (lat)\nC\nC\nC The unit normal, n, at this point is simply\nC\nC ( cos(long)cos(lat), sin(long)cos(lat), sin(lat) )\nC\nC\nC Thus for a point at altitude alt, we simply add the vector\nC\nC alt*n\nC\nC to the vector ( x_0, y_0, z_0 ). Hence we have\nC\nC x = [ alt + re/g(lat,f) ] * cos(long) * cos(lat)\nC y = [ alt + re/g(lat,f) ] * sin(long) * cos(lat)\nC z = [ alt + re*(1-f)**2/g(lat,f) ] * sin(lat)\nC\nC\nC We're going to need the sine and cosine of LAT and LONG many \nC times. We'll just compute them once.\nC\n CLAT = DCOS ( LAT )\n CLON = DCOS ( LONG )\n SLAT = DSIN ( LAT )\n SLON = DSIN ( LONG )\n \nC\nC Referring to the G given in the header we have...\nC\n FLAT = 1.D0 - F\n FLAT2 = FLAT * FLAT\n\n G = DSQRT( CLAT*CLAT + FLAT2 * SLAT*SLAT )\n G2 = G * G\n DGDLAT = ( -1.0D0 + FLAT2 ) * SLAT * CLAT / G\n\nC\nC Now simply take the partial derivatives of the x,y,z w.r.t.\nC long,lat, alt.\nC\n JACOBI (DX,DLON) = - ( ALT + RE/G ) * SLON * CLAT\n JACOBI (DY,DLON) = ( ALT + RE/G ) * CLON * CLAT\n JACOBI (DZ,DLON) = 0.0D0\n \n \n JACOBI (DX,DLAT) = ( - RE*DGDLAT / G2 ) * CLON * CLAT\n . - ( ALT + RE / G ) * CLON * SLAT\n \n JACOBI (DY,DLAT) = ( - RE*DGDLAT / G2 ) * SLON * CLAT\n . - ( ALT + RE / G ) * SLON * SLAT\n \n JACOBI (DZ,DLAT) = ( - FLAT2*RE*DGDLAT / G2 ) * SLAT\n . + ( ALT + FLAT2*RE / G ) * CLAT\n \n \n JACOBI (DX,DALT) = CLON * CLAT\n JACOBI (DY,DALT) = SLON * CLAT\n JACOBI (DZ,DALT) = SLAT\n \n\n CALL CHKOUT ( 'DRDGEO' )\n RETURN\n END\n", "meta": {"hexsha": "02701a4a8091b7c0758c307dac6a3472a7942297", "size": 15124, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/drdgeo.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/drdgeo.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/drdgeo.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": 30.7398373984, "max_line_length": 71, "alphanum_fraction": 0.490148109, "num_tokens": 4236, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850093037731, "lm_q2_score": 0.7310585727705127, "lm_q1q2_score": 0.6844791826080425}} {"text": "! *******************************************\n!\n! Font et al. and Alexander et al. wind profiles\n!\n! *******************************************\n\n Subroutine Wind_profiles(sigdot_diff,sigdot_dir, radius, Mstar, rdir_min) \n\n real*8 sigdot_diff, sigdot_dir\n real*8 radius, rdir_min\n real*8 no, u1\n real*8 Rg, ng, cs\n real*8 mu, mH\n\n real*8 alphaB, C1, C2, A, B, D, Phi \n real*8 Mstar, Msun\n real*8 G, pi\n\n pi = ACos(-1.0d0)\n G = 6.67d-8\n Msun = 1.989d33\n AU = 1.496d13\n\n mu = 1.35 ! ionised gas\n mH = 1.67d-24 \n\n cs = 1000000.0d0 ! 10 km/s sound speed in cm/s.\n \n C1 = 0.14\n C2 = 0.235 \n A = 0.3423\n B = -0.3612\n D = 0.2457\n\n alphaB = 2.6d-13\n Phi = 7.5d42\n\n If (Mstar.gt.0.0d0) Then\n\n Rg = G*Mstar/cs**2.0d0\n\n ng = C1*(3.0d0*Phi/(4.0d0*pi*alphaB*Rg**3.0d0))**0.5d0\n\n no = ng*(2.0d0/((radius/Rg)**(15.0d0/2.0d0)+(radius/Rg)**(25.0d0/2.0d0)))**(1.0d0/5.0d0)\n \n If ((radius.gt.0.1d0*Rg).and.(Rg/AU.gt.0.01d0)) Then\n u1 = cs*A*DExp(B*(radius/Rg - 0.1d0))*(radius/Rg - 0.1d0)**D\n Else\n u1 = 0.0d0\n EndIf \n \n sigdot_diff = 2.0d0*no*u1*mu*mH\n Else\n sigdot_diff = 0.0d0\n EndIf \n\n sigdot_dir = 2.0d0*C2*mu*mH*cs\n sigdot_dir = sigdot_dir*(Phi/(4.0d0*pi*alphaB*0.05*rdir_min**3.0d0))**0.5d0\n sigdot_dir = sigdot_dir*(radius/rdir_min)**(-2.42) \n\n If (radius.lt.rdir_min) sigdot_dir = 0.0d0\n\n return\n end\n\n\n", "meta": {"hexsha": "c7df59ae5b72ec5ceea128c57d21d90aeae3deeb", "size": 1551, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/wind/wind_profiles.f90", "max_stars_repo_name": "dh4gan/visag", "max_stars_repo_head_hexsha": "bf3698459c0b41c9097807f9baf32eee3ca0bdbe", "max_stars_repo_licenses": ["MIT"], "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/wind/wind_profiles.f90", "max_issues_repo_name": "dh4gan/visag", "max_issues_repo_head_hexsha": "bf3698459c0b41c9097807f9baf32eee3ca0bdbe", "max_issues_repo_licenses": ["MIT"], "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/wind/wind_profiles.f90", "max_forks_repo_name": "dh4gan/visag", "max_forks_repo_head_hexsha": "bf3698459c0b41c9097807f9baf32eee3ca0bdbe", "max_forks_repo_licenses": ["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.1492537313, "max_line_length": 96, "alphanum_fraction": 0.4861379755, "num_tokens": 652, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850039701653, "lm_q2_score": 0.7310585727705126, "lm_q1q2_score": 0.6844791787088628}} {"text": " SUBROUTINE BPASS(FL,FH,FILT,NPTS,SI,SCR)\nC BPASS1 GENERATES A ZERO PHASE TIME DOMAIN FILTER. THE IMPULSE RESPONSE\nC WILL HAVE AN ENERGY OF 1., THUS ALLEVIATING SCALING PROBLEMS DUE TO DIFFERENT\nC BANDWIDTHS.\nC THE DESIGN IS DONE IN THE TIME DOMAIN AND IS THE SHORTEST AND SIMPLEST,\nC BUT IS NOT AS GOOD (STEEPNESS OF CUT OFF) AS SOME OPTIMIZING METHODS.\nC THE FILTER IS BETTER THE MORE POINTS IT HAS, AND IS WORSE THE LESS POINTS IT\nC HAS. 39 POINTS IS A NICE NUMBER\nC THE METHOD OF DESIGN IS:\nC 1) GENERATE A COSINE AT A FREQUENCY W1 WHICH IS HALFWAY BETWEEN THE CUTOFF\nC IN THE FREQUENCY DOMAIN THIS IS A SPIKE AT FREQUENCY W1.\nC 2) MULTIPLY 1 BY A SINC FUNCTION OF FREQUENCY WC WHICH IS HALF THE BANDWIDTH\nC IN THE FREQUENCY DOMAIN THIS IS CONVOLVING 1 WITH A BOX CAR.\nC 3) MULTIPLY THE RESULT BY A WINDOW TO PREVENT DISCONTINUITIES. IN THE\nC FREQUENCY DOMAIN THIS IS CONVOLVING THE BOX CAR WITH A SMOOTHING FUNCTION.\nC\nC ARGUMENTS:\nC FL - THE FREQUENCY OF THE LOW CORNER\nC FH - THE FREQUENCY OF THE HIGH CORNER\nC FILT - THE ARRAY TO RECEIVE THE TIME DOMAIN FILTER POINTS.\nC NPTS - THE NUMBER OF FILTER POINTS WANTED\nC SI - THE SAMPLE INTERVAL IN SECONDS\nC SCR - A SCRATCH ARRAY AT LEAST NPTS/2+1 LONG\nC\nC\nC WRITTEN AND COPYRIGHTED BY:\nC PAUL HENKART, SCRIPPS INSTITUTION OF OCEANOGRAPHY, FEBRUARY 1979\nC ALL RIGHTS ARE RESERVED BY THE AUTHOR. PERMISSION TO COPY OR REPRODUCE THIS\nC SUBROUTINE, BY COMPUTER OR OTHER MEANS, MAY BE OBTAINED ONLY FROM THE AUTHOR.\nc mod 6 Oct 09 - hange the documentation - sample interval, not sample rate.\nc\n DIMENSION FILT(*),SCR(*)\n PI2=6.283197\n N=NPTS/2+1 /* THE CENTRE POINT OF A ZERO PHASE FILTER\n W1=(FL+FH)/2. /* FIND THE CENTRE FREQUENCY\n WC=(FH-FL)/2. /* THE WIDTH OF THE BANDPASS\nC****\nC**** GENERATE A COSINE WAVE\nC****\n P=1./W1/SI\n DO 100 I=1,N\n 100 SCR(I)=COS(FLOAT(I-1)/P*PI2)\nC****\nC**** MULTIPLY BY A HALF SINC\nC****\n P=1./WC/SI\n SCR(1)=1.\n DO 200 I=2,N\n X=FLOAT(I-1)/P*PI2\n 200 SCR(I)=SCR(I)*SIN(X)/X\nC****\nC**** MULTIPLY BY A GOOD WINDOW ( HAMMING)\nC****\n CALL WINDOW(-6,FILT,N,DUM)\n DO 300 I=1,N\n 300 SCR(I)=SCR(I)*FILT(N-I+1)\nC****\nC**** NOW MAKE A SYMMETRICAL FILTER OUT OF IT\nC****\n DO 400 I=1,N\n FILT(I)=SCR(N-I+1)\n FILT(N+I-1)=SCR(I)\n 400 CONTINUE\nC****\nC**** MAKE THE FILTER HAVE AN ENERGY OF 1.\nC****\n E=0.\n DO 500 I=1,NPTS\n 500 E=E+FILT(I)*FILT(I)\n C=1./SQRT(E)\n DO 550 I=1,NPTS\n 550 FILT(I)=FILT(I)*C\n RETURN\n END\n", "meta": {"hexsha": "ee9a446b5ef7228e1c82f86be42722cb26ab6b5f", "size": 2768, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "bpass.f", "max_stars_repo_name": "apthorpe/sioseis", "max_stars_repo_head_hexsha": "28965a8b4a5b3ffaf169588dd1a385a1f9c9ccce", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-04-29T15:57:31.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-06T15:13:22.000Z", "max_issues_repo_path": "bpass.f", "max_issues_repo_name": "henkart/sioseis", "max_issues_repo_head_hexsha": "9a3d9d87eb6e9d7c8e754bc2a81eea51b30d4fa5", "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": "bpass.f", "max_forks_repo_name": "henkart/sioseis", "max_forks_repo_head_hexsha": "9a3d9d87eb6e9d7c8e754bc2a81eea51b30d4fa5", "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": 36.9066666667, "max_line_length": 115, "alphanum_fraction": 0.6159682081, "num_tokens": 907, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026663679976, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6844352929664369}} {"text": "C File: arrays-constr-05.f\nC This program has a simple 1-D array with the default lower bound of 1.\nC It shows the use of an array constructor to initialize the array.\n\n program main\n implicit none\n\nC arr is a 1-D array of integers with an implicit lower-bound = 1\nC and an upper bound of 12. \n integer, dimension(12) :: arr \n integer, dimension(7) :: idx = (/37, 43, 59, 67, 73, 79, 83/)\n integer :: i\n\nC array constructor III -- implied do loop, multiple expressions\nC computed in each loop iteration.\nC In this example, the iteration variable i takes on values 1, 3, 5, 7\nC (initial value = 1, final value = 7, stride = 2). The list of\nC values on the RHS of the assignment consists of the values of the\nC expressions given -- i.e.: 7*i, 11*i-1, idx(i) -- for each such\nC value of i:\nC\nC i = 1 ==> 7, 10, 37\nC i = 3 ==> 21, 32, 59\nC i = 5 ==> 35, 54, 73\nC i = 7 ==> 49, 76, 83\nC\nC So the sequence of values assigned to the elements of arr is:\nC\nC 7, 10, 37, 21, 32, 59, 35, 54, 73, 49, 76, 83\n\n arr = (/ (7*i, 11*i-1, idx(i), i = 1, 7, 2) /)\n\n do i = 1, 12\n write (*,10) arr(i)\n end do\n\n 10 format(I5)\n\n stop\n end program main\n", "meta": {"hexsha": "bfb6a56411ef9939e88c7b6998d72a09ae98ca0c", "size": 1283, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/data/program_analysis/arrays/arrays-constr-05.f", "max_stars_repo_name": "mikiec84/delphi", "max_stars_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2018-03-03T11:57:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-16T21:19:54.000Z", "max_issues_repo_path": "tests/data/program_analysis/arrays/arrays-constr-05.f", "max_issues_repo_name": "mikiec84/delphi", "max_issues_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 385, "max_issues_repo_issues_event_min_datetime": "2018-02-21T16:52:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-17T07:44:56.000Z", "max_forks_repo_path": "tests/data/program_analysis/arrays/arrays-constr-05.f", "max_forks_repo_name": "mikiec84/delphi", "max_forks_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2018-03-20T01:08:11.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-29T01:04:49.000Z", "avg_line_length": 31.2926829268, "max_line_length": 74, "alphanum_fraction": 0.5767731878, "num_tokens": 447, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774768002981829, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.6844256788578625}} {"text": "module support_mod\n\n implicit none\n\n private\n public :: characters_in_number\n\ncontains\n\n function characters_in_number( param ) result( length )\n\n implicit none\n\n integer, intent(in) :: param\n integer :: length\n\n length = int(floor(log10(real(param)))) + 1\n\n end function characters_in_number\n\nend module support_mod\n", "meta": {"hexsha": "a43f757f7493d503ec51a962760a7131db53f573", "size": 334, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "TestCases/CompiletimeDependency/support_mod.f90", "max_stars_repo_name": "bblay/fab", "max_stars_repo_head_hexsha": "bbdac7bae20c5b8695a2d56945c9593b4fda9c74", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-04-24T11:19:00.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-26T18:05:51.000Z", "max_issues_repo_path": "TestCases/CompiletimeDependency/support_mod.f90", "max_issues_repo_name": "bblay/fab", "max_issues_repo_head_hexsha": "bbdac7bae20c5b8695a2d56945c9593b4fda9c74", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 74, "max_issues_repo_issues_event_min_datetime": "2019-06-26T08:17:26.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-23T16:10:57.000Z", "max_forks_repo_path": "TestCases/CompiletimeDependency/support_mod.f90", "max_forks_repo_name": "bblay/fab", "max_forks_repo_head_hexsha": "bbdac7bae20c5b8695a2d56945c9593b4fda9c74", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2019-05-16T10:27:28.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-17T05:14:38.000Z", "avg_line_length": 15.1818181818, "max_line_length": 57, "alphanum_fraction": 0.7185628743, "num_tokens": 76, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8774768002981829, "lm_q2_score": 0.7799928900257126, "lm_q1q2_score": 0.6844256653950948}} {"text": "SUBROUTINE gaussj_sp(a,b)\n USE mo_kind, only: sp, i4, lgt\n USE mo_nrutil, ONLY : assert_eq,nrerror,outerand,outerprod,swap\n IMPLICIT NONE\n REAL(SP), DIMENSION(:,:), INTENT(INOUT) :: a,b\n INTEGER(I4), DIMENSION(size(a,1)) :: ipiv,indxr,indxc\n LOGICAL(LGT), DIMENSION(size(a,1)) :: lpiv\n REAL(SP) :: pivinv\n REAL(SP), DIMENSION(size(a,1)) :: dumc\n INTEGER(I4), TARGET :: irc(2)\n INTEGER(I4) :: i,l,n\n INTEGER(I4), POINTER :: irow,icol\n n=assert_eq(size(a,1),size(a,2),size(b,1),'gaussj')\n irow => irc(1)\n icol => irc(2)\n ipiv=0\n do i=1,n\n lpiv = (ipiv == 0)\n irc=maxloc(abs(a),outerand(lpiv,lpiv))\n ipiv(icol)=ipiv(icol)+1\n if (ipiv(icol) > 1) call nrerror('gaussj: singular matrix (1)')\n if (irow /= icol) then\n call swap(a(irow,:),a(icol,:))\n call swap(b(irow,:),b(icol,:))\n end if\n indxr(i)=irow\n indxc(i)=icol\n if (a(icol,icol) == 0.0) &\n call nrerror('gaussj: singular matrix (2)')\n pivinv=1.0_sp/a(icol,icol)\n a(icol,icol)=1.0\n a(icol,:)=a(icol,:)*pivinv\n b(icol,:)=b(icol,:)*pivinv\n dumc=a(:,icol)\n a(:,icol)=0.0\n a(icol,icol)=pivinv\n a(1:icol-1,:)=a(1:icol-1,:)-outerprod(dumc(1:icol-1),a(icol,:))\n b(1:icol-1,:)=b(1:icol-1,:)-outerprod(dumc(1:icol-1),b(icol,:))\n a(icol+1:,:)=a(icol+1:,:)-outerprod(dumc(icol+1:),a(icol,:))\n b(icol+1:,:)=b(icol+1:,:)-outerprod(dumc(icol+1:),b(icol,:))\n end do\n do l=n,1,-1\n call swap(a(:,indxr(l)),a(:,indxc(l)))\n end do\nEND SUBROUTINE gaussj_sp\n\n\nSUBROUTINE gaussj_dp(a,b)\n USE mo_kind, only: dp, i4, lgt\n USE mo_nrutil, ONLY : assert_eq,nrerror,outerand,outerprod,swap\n IMPLICIT NONE\n REAL(DP), DIMENSION(:,:), INTENT(INOUT) :: a,b\n INTEGER(I4), DIMENSION(size(a,1)) :: ipiv,indxr,indxc\n LOGICAL(LGT), DIMENSION(size(a,1)) :: lpiv\n REAL(DP) :: pivinv\n REAL(DP), DIMENSION(size(a,1)) :: dumc\n INTEGER(I4), TARGET :: irc(2)\n INTEGER(I4) :: i,l,n\n INTEGER(I4), POINTER :: irow,icol\n n=assert_eq(size(a,1),size(a,2),size(b,1),'gaussj')\n irow => irc(1)\n icol => irc(2)\n ipiv=0\n do i=1,n\n lpiv = (ipiv == 0)\n irc=maxloc(abs(a),outerand(lpiv,lpiv))\n ipiv(icol)=ipiv(icol)+1\n if (ipiv(icol) > 1) call nrerror('gaussj: singular matrix (1)')\n if (irow /= icol) then\n call swap(a(irow,:),a(icol,:))\n call swap(b(irow,:),b(icol,:))\n end if\n indxr(i)=irow\n indxc(i)=icol\n if (a(icol,icol) == 0.0_dp) &\n call nrerror('gaussj: singular matrix (2)')\n pivinv=1.0_dp/a(icol,icol)\n a(icol,icol)=1.0_dp\n a(icol,:)=a(icol,:)*pivinv\n b(icol,:)=b(icol,:)*pivinv\n dumc=a(:,icol)\n a(:,icol)=0.0_dp\n a(icol,icol)=pivinv\n a(1:icol-1,:)=a(1:icol-1,:)-outerprod(dumc(1:icol-1),a(icol,:))\n b(1:icol-1,:)=b(1:icol-1,:)-outerprod(dumc(1:icol-1),b(icol,:))\n a(icol+1:,:)=a(icol+1:,:)-outerprod(dumc(icol+1:),a(icol,:))\n b(icol+1:,:)=b(icol+1:,:)-outerprod(dumc(icol+1:),b(icol,:))\n end do\n do l=n,1,-1\n call swap(a(:,indxr(l)),a(:,indxc(l)))\n end do\nEND SUBROUTINE gaussj_dp\n", "meta": {"hexsha": "78077799432e3df92b0bcf66f712acfcb0198d2d", "size": 3037, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "nr_jams/gaussj.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/gaussj.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/gaussj.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": 32.6559139785, "max_line_length": 68, "alphanum_fraction": 0.5772143563, "num_tokens": 1254, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818409, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6844256643736176}} {"text": "c program DRDMLC01\nc>> 2001-05-22 DRDMLC01 Krogh Minor change for making .f90 version.\nc>> 1996-07-08 DRDMLC01 Krogh Minor format change for C conversion.\nc>> 1994-11-02 DRDMLC01 Krogh Changes to use M77CON\nc>> 1994-09-13 DRDMLC01 CLL\nc>> 1992-05-13 CLL\nc>> 1992-04-15 CLL\nc>> 1992-01-21 CLL\nc>> 1991-06-10 CLL\nc>> 1992-01-16 CLL\nc>> 1990-07-12 CLL\nc Demo driver for DMLC01. Also uses DCKDER to check gradient.\nc Minimization with linear constraints.\nc The constraints are Ax .le. b with equality required in the first\nc two rows.\nc ------------------------------------------------------------------\nc--D replaces \"?\": DR?MLC01, ?MLC01, ?XLOGX, ?CKDER\nc ------------------------------------------------------------------\n external DXLOGX\n integer MMAX, NMAX, LIW, LW\n parameter(MMAX = 3, NMAX = 4)\n parameter(LIW = 4 + MMAX + 2*NMAX)\n parameter(LW = 3 + MMAX + NMAX*(16 + NMAX))\n integer I, IMAX, IPRINT, IW(LIW), J, JMAX\n integer M, MEQ, MODE, MXEVAL, N\n logical HAVEG\n double precision A(MMAX, NMAX), ACC, B(MMAX), FVAL(1), GRAD(NMAX)\n double precision GDUMMY(NMAX), TEST(NMAX), TSTMAX, W(LW)\n double precision X(NMAX), XL(NMAX), XU(NMAX)\n data M, MEQ, N / 3, 2, 4 /\n data ACC, IPRINT, MXEVAL / 0.0D0, 3, 0 /\n data ((A(I,J),J=1,4),I=1,3) / 1.0D0, 1.0D0, 1.0D0, 1.0D0 ,\n * 1.0D0, -1.0D0, 0.0D0, 0.0D0,\n * 0.0D0, -1.0D0, 1.0D0, 0.0D0 /\n data (B(I),I=1,3) / 1.0D0, 0.25D0, -0.1D0 /\n data (XL(J),J=1,4) / 4*1.0D-6 /\n data (XU(J),J=1,4) / 4*1.0D0 /\n data (X(J),J=1,4) / 0.7d0, 0.6d0, 0.5d0, 0.4d0 /\nc ------------------------------------------------------------------\n print*,\n * 'Program DRDMLC01.. Demo driver for DMLC01. Also uses DCKDER.'\nc\nc Using DCKDER to check the gradient calculation.\nc\n MODE = 1\n call DXLOGX( N, X, FVAL(1), GRAD, HAVEG)\n 10 continue\n call DCKDER(MODE, 1, N, X, FVAL, GRAD, 1, TEST, IMAX, JMAX,TSTMAX)\n call DXLOGX( N, X, FVAL(1), GDUMMY, HAVEG)\n if(MODE .eq. 2) go to 10\n print'(/'' Using DCKDER to check the gradient calculation.'')'\n print'(/11x,''X(J) ='',5g11.3:/(17x,5g11.3))',(X(J),J=1,N)\n print'(11x,''FVAL ='',5g11.3)',FVAL(1)\n print'(7x,''Gradient ='',5g11.3:/(17x,5g11.3))',(GRAD(J),J=1,N)\n print'(9x,''TEST() ='',5g11.3/(17x,5g11.3))',(TEST(J),J=1,N)\n print'(11x,''JMAX ='',i3,'', TSTMAX ='',g11.3)',JMAX,\n * TSTMAX\nc\nc Using DMLC01 to solve the minimization problem.\nc\n print'(/'' Using DMLC01 to solve the minimization problem.'')'\n call DMLC01 (DXLOGX, N, M, MEQ, A, MMAX, B, XL, XU, X, ACC,\n * IPRINT, MXEVAL, IW, LIW, W, LW)\n stop\n end\nc ==================================================================\n subroutine DXLOGX( N, X, F, G, HAVEG)\nc ------------------------------------------------------------------\n integer I, N\n double precision F, G(N), X(N)\n logical HAVEG\nc ------------------------------------------------------------------\n HAVEG = .true.\n F = 0.0D0\n do 10 I = 1,N\n F = F + X(I) * log(X(I))\n G(I) = 1.0D0 + log(X(I))\n 10 continue\n return\n end\n", "meta": {"hexsha": "75672b846ce8fb368c216b6696c7bdf13169de2f", "size": 3331, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drdmlc01.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drdmlc01.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drdmlc01.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 41.1234567901, "max_line_length": 72, "alphanum_fraction": 0.4770339237, "num_tokens": 1238, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767906859264, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6844256623851924}} {"text": "C\nC **********************************************************************\nC ********************* SUBROUTINE EMALGO *****************************\nC **********************************************************************\nC\n SUBROUTINE EMALGO(NTOT,Y1,Y2,P,MPLONE,X,W,WCEN,LENW,\n + VCOV,WORK,LENWRK,ALPHA,TOL,MAXITS,IFAULT,ICHECK,NC)\nC\nC\nC * ALGORITHM AS 139 APPL.STATIST. (1979) VOL.28., NO2 *\nC * *\nC * COMPUTES MAXIMUM LIKELIHOOD ESTIMATES *\nC * FROM A LINEAR MODEL WITH NORMAL HETEROGENEOUS *\nC * VARIANCE. THE DESIGN MATRIX MUST BE NON-SINGULAR. *\nC * THE DEPENDENT VARIABLE MAY INCLUDE OBSERVATIONS *\nC * CENSORED IN EITHER TAIL AND/OR OBSERVATIONS CONFINED *\nC * BETWEEN FINITE LIMITS. *\nC * *\nC * SUBROUTINES *\nC * SYMINV, UNPACK, RMILLS *\nC\nC\n IMPLICIT REAL*8 (A-H,O-Z), INTEGER (I-N)\n INTEGER P\n\n DIMENSION X(NTOT,MPLONE),TOL(MPLONE),ALPHA(MPLONE)\n DIMENSION Y1(NTOT),Y2(NTOT),P(NTOT)\n DIMENSION VCOV(LENWRK),WORK(LENWRK),W(LENW),WCEN(LENW)\n DATA QLIMIT /0.00001/, RLIMIT /0.00001/\n DATA C /0.39894228/\nC\nC * INITIALIZATION *\nC * THE NEXT LINE IS LOCATED IN A DIFFERENT PLACE IN THE *\nC * ORIGINAL PROGRAM BY WOLYNETZ *\nC\n M=MPLONE-1\nC\nC * CHECK ARRAY SIZES, ETC *\nC\n IFAULT=-7\n IF(LENW.LT.(MPLONE+NTOT)) RETURN\n IF(LENWRK.LT.(M*NTOT)) RETURN\nC\nC * COMPUTE X'X IN LOWER TRIANGULAR FORM *\nC\n II=0\n DO 53 I=1,M\n DO 50 J=1,I\n TEMP=0.0\n DO 40 K=1,NTOT\n TEMP=TEMP+X(K,I)*X(K,J)\n 40 CONTINUE\n II=II+1\n VCOV(II)=TEMP\n 50 CONTINUE\n 53 CONTINUE\n\n CALL SYMINV(VCOV,M,WORK,W,NUL,LENWRK,LENWRK,LENW,IFAULT)\n\n IF((IFAULT.NE.0) .OR. (NUL.NE.0)) THEN\n VCOV(2)=REAL(IFAULT)\n VCOV(1)=REAL(NUL)\n IFAULT=-5\n RETURN\n ENDIF\n\nC\nC * THE MATRIX IS NON-SINGULAR AND WE HAVE ITS INVERSE. NOW WE *\nC * COMPUTE (X'X) INVERSE*X. *\nC * THE FOLLOWING SCHEME IS USED TO REDUCE THE NUMBER OF STORAGE *\nC * ARRAYS NEEDED, BY EXPANDING FROM THE TRIANGULAR TO A SQUARE *\nC * MATRIX. *\nC\nC * THE NEXT LINE IS NOT IN WOLYNETZ. *\nC\n IF(M.NE.1) THEN\n CALL UNPACK(WORK,M,LENWRK)\n ENDIF\nC\nC * DO MULTIPLICATION--ONE ROW AT A TIME--STARTING WITH *\nC * THE LAST ROW *\nC\n JJ=NTOT*M\n II=M*M\n DO 220 I=1,M\n II=II-M\n\n DO 200 J=1,NTOT\n TEMP=0.0\n\n DO 170 K=1,M\n IIK=II+K\n TEMP=TEMP+WORK(IIK)*X(J,K)\n 170 CONTINUE\n W(J)=TEMP\n 200 CONTINUE\n\n DO 210 J=1,NTOT\n IJ=NTOT+1-J\n WORK(JJ)=W(IJ)\n JJ=JJ-1\n 210 CONTINUE\n 220 CONTINUE\nC\n XSIG=ALPHA(MPLONE)\n IF(XSIG.LE.0.0) THEN\nC\nC * NO ACCEPTABLE INITIAL VALUE FOR SIGMA HAS BEEN INPUT, *\nC * OBTAIN INITIAL ESTIMATES FROM EXACTLY SPECIFIED *\nC * OBSERVATIONS ONLY (ALTHOUGH THE MATRIX IS BASED ON ALL *\nC * OBSERVATIONS) AND CONFINED OBSERVATIONS. *\nC\n II=-NTOT\n DO 300 I=1,M\n II=II+NTOT\n TEMP=0.0\n DO 280 J=1,NTOT\n IIJ=II+J\n IPT=P(J)\n IF(IPT.EQ.0) THEN\n TEMP=TEMP+WORK(IIJ)*Y1(J)\n ELSEIF(IPT.EQ.5) THEN \n TEMP=TEMP+WORK(IIJ)*(Y1(J)+Y2(J))*0.5\n ENDIF\n 280 CONTINUE\n ALPHA(I)=TEMP\n 300 CONTINUE\nC\nC * CALCULATE THE INITIAL ESTIMATE OF SIGMA *\nC\n SUM2=0.0\n TEMP=0.0\n DO 350 I=1,NTOT\n IPT=P(I)\n IF(IABS(IPT).NE.1) THEN\n DEMP=Y1(I)\n IF(IPT.EQ.5) DEMP=(DEMP+Y2(I))*0.5\n\n DO 320 J=1,M\n DEMP=DEMP-ALPHA(J)*X(I,J)\n 320 CONTINUE\n\n SUM2=SUM2+DEMP**2\n TEMP=TEMP+1.0\n ENDIF\n 350 CONTINUE\n\n XSIG=DSQRT(SUM2/TEMP)\n ENDIF\nC\nC * COMPUTE SOME CONSTANTS NEEDED THROUGHOUT THE SUBROUTINE *\nC\n R=0.0\n R2=0.0\n IFAULT=-2\n DO 600 I=1,NTOT\n IPT=P(I)\n IF(IPT.EQ.0) THEN\n R=R+1.0\n W(I)=Y1(I)\nC\nC * THE NEXT LINE IS LOCATED IN A DIFFERENT PLACE IN THE *\nC * ORIGINAL PROGRAM BY WOLYNETZ *\nC\n ELSEIF(IPT.EQ.5) THEN\n IF(DABS(Y1(I)-Y2(I)) .GT. QLIMIT*DABS(Y1(I))) THEN\n R2=R2+1.0\n IF(Y1(I).LT.Y2(I)) GOTO 600\n RETURN\n ENDIF\n P(I)=0\n R=R+1.0\n W(I)=Y1(I)\n ENDIF\n 600 CONTINUE\n\n I=INT(R+R2+0.01)\n IFAULT=-4\n IF(I.LT.MPLONE) RETURN\n IFAULT=0\nC\nC * START OF THE ITERATION PROCEDURE *\nC\n 620 TD=R\n SUM2=0.0\nC\nC * COMPLETE W-VECTOR *\nC\n DO 1000 I=1,NTOT\n IPT=P(I)\n YMEAN=0.0\n\n DO 650 J=1,M\n YMEAN=YMEAN+ALPHA(J)*X(I,J)\n 650 CONTINUE\nC\nC * OBSERVATION IS NOT EXACTLY SPECIFIED: START FROM LINE 990 *\nC\n IF(IPT.NE.0) THEN\n TEMP=(Y1(I)-YMEAN)/XSIG\nC\nC * OBSERVATION CENSORED FROM ABOVE: LOWER BOUND IS KNOWN *\nC\n IF((IPT-1) .EQ. 0) THEN\n 700 CALL RMILLS(TEMP,F,RLIMIT)\n W(I)=YMEAN+XSIG*F\n TD=TD+F*(F-TEMP)\nC\nC * OBSERVATON CENSORED FROM BELOW: UPPER BOUND IS KNOWN *\nC\n ELSEIF((IPT-1) .LT. 0) THEN\n 750 CALL RMILLS(-TEMP,F,RLIMIT)\n W(I)=YMEAN-XSIG*F\n TD=TD+F*(F+TEMP)\nC\nC * OBSERVATION CONFINED TO LIE BETWEEN TWO FINITE LIMITS *\nC\n ELSEIF((IPT-1) .GT. 0) THEN\n 800 YN=DEXP(-0.5*TEMP**2)*C\n CALL RMILLS(TEMP,F,RLIMIT)\n YQ=YN/F\n TMPU=(Y2(I)-YMEAN)/XSIG\n YNU=DEXP(-0.5*TMPU**2)*C\n CALL RMILLS(TMPU,FU,RLIMIT)\n YQU=YNU/FU\n TINT=YQ-YQU\n\n IF(TINT.LT.QLIMIT) THEN\n IFAULT=-3\n RETURN\n ENDIF\nC\nC * AFTER STANDARDIZING, UPPER AND LOWER LIMITS RESULT IN *\nC * THE SAME PROBABILITY INTEGRAL *\nC\n 820 A=(YN-YNU)/TINT\n W(I)=YMEAN+XSIG*A\n TD=TD+(A**2+(TMPU*YNU-TEMP*YN)/TINT)\n ENDIF\n ENDIF\nC\nC * CALCULATE RESIDUAL SUM OF SQUARES *\nC\n 990 SUM2=SUM2+(W(I)-YMEAN)**2\n 1000 CONTINUE\nC\nC * UPDATE PARAMETER ESTIMATES-STORE IN THE END OF THE W-VECTOR *\nC\n JJ=-NTOT\n DO 1200 J=1,M\n JJ=JJ+NTOT\n TEMP=0.0\n\n DO 1100 I=1,NTOT\n JJI=JJ+I\n TEMP=TEMP+WORK(JJI)*W(I)\n 1100 CONTINUE\n NJ=NTOT+J\n W(NJ)=TEMP\n 1200 CONTINUE\n\n NJ=NTOT+MPLONE\n W(NJ)=DSQRT(SUM2/TD)\nC\nC * STORE THE ESTIMATES FOR THE CENSORED POINTS *\nC\n KC=0\n DO 1250 I=1,NTOT\n IF(P(I).EQ.0) GOTO 1250\n KC=KC+1\n WCEN(KC)=W(I)\n 1250 CONTINUE\nC\nC * TEST FOR CONVERGENCE *\nC\n DO 1300 J=1,MPLONE\n NJ=NTOT+J\n IF(DABS(ALPHA(J)-W(NJ)).GE.TOL(J)) GOTO 1400\n 1300 CONTINUE\nC\nC * IF WE REACH HERE, CONVERGENCE IS OBTAINED *\nC\n IJ=IFAULT\n IFAULT=-1\nC\nC * UPDATE VALUES *\nC\n 1400 DO 1450 J=1,MPLONE\n NJ=NTOT+J\n ALPHA(J)=W(NJ)\n 1450 CONTINUE\n\n XSIG=ALPHA(MPLONE)\n IFAULT=IFAULT+1\n IF(IFAULT.NE.0) THEN\nC\nC * IF THE NUMBER OF ITERATIONS HAS NOT REACHED THE MAX., TRY *\nC * ANOTHER ITERATION. *\nC\n IF(IFAULT.LE.MAXITS) GOTO 620\n IFAULT=-1\n RETURN\n ENDIF\nC\nC * CONVERGENCE OBTAINED. COMPUTE VARIANCE--COVARIANCE *\nC * MATRIX, AND INITIALIZE THE WORK ARRAY *\nC\n 1600 II=MPLONE*(MPLONE+1)/2\n DO 1650 I=1,II\n WORK(I)=0.0\n 1650 CONTINUE\n\n DO 2500 I=1,NTOT\n IPT=P(I)\n YS=Y1(I)\n\n DO 1680 J=1,M\n YS=YS-ALPHA(J)*X(I,J)\n 1680 CONTINUE\n\n YS=YS/XSIG\n JJ=0\n IF(IPT.EQ.0) THEN\n\nC\nC * EXACTLY SPECIFIED OBSERVATION *\nC\n\n DO 1750 K=1,M\n DO 1720 J=1,K\n JJ=JJ+1\n WORK(JJ)=WORK(JJ)+X(I,K)*X(I,J)\n 1720 CONTINUE\nC\nC\nC * THE NEXT LINE IS CORRECTED ACCORDING TO REMARK AS R 32 *\nC * APPL.STAT. VOL 30, P. 105 (1981). *\nC\nC\n KK=II-MPLONE+K\n WORK(KK)=WORK(KK)+YS*X(I,K)\n 1750 CONTINUE\n WORK(II)=WORK(II)+1.0+YS**2\n\nC\nC * OBSERVATION CENSORED FROM ABOVE: LOWER BOUND IS KNOWN *\nC\n\n ELSEIF((IPT-1) .LE. 0) THEN\n IF((IPT-1) .EQ. 0) THEN\n CALL RMILLS(YS,F,RLIMIT)\n TEMP=F*(F-YS)\n\nC\nC * OBSERVATION CENSORED FROM BELOW: UPPER BOUND IS KNOWN *\nC\n\n ELSE\n CALL RMILLS(-YS,F,RLIMIT)\n TEMP=F*(F+YS)\n ENDIF\nC\nC * ROUTINE FOR CENSORED OBSERVATIONS *\nC\n DO 2190 K=1,M\n DO 2170 J=1,K\n JJ=JJ+1\n WORK(JJ)=WORK(JJ)+X(I,J)*X(I,K)*TEMP\n 2170 CONTINUE\nC\nC * THE NEXT LINE IS CORRECTED ACCORDING TO REMARK AS R 32 *\nC * APPL.STAT. VOL 30, P. 105 (1981). *\nC\n KK=II-MPLONE+K\n WORK(KK)=WORK(KK)+YS*X(I,K)*TEMP\n 2190 CONTINUE\n WORK(II)=WORK(II)+YS**2*TEMP\n\nC\nC * OBSERVATION CONFINED BETWEEN TWO FINITE LIMITS *\nC\n\n ELSEIF((IPT-1) .GT. 0) THEN\n YN=DEXP(-0.5*YS**2)*C\n CALL RMILLS(YS,F,RLIMIT)\n YQ=YN/F\n YSU=YS+(Y2(I)-Y1(I))/XSIG\n CALL RMILLS(YSU,FU,RLIMIT)\n YNU=DEXP(-0.5*YSU**2)*C\n YQU=YNU/FU\n TINT=YQ-YQU\n A=(YN-YNU)/TINT\n B=(YNU*YSU-YN*YS)/TINT\n TEMP=A**2+B\n\n DO 2350 K=1,M\n\n DO 2330 J=1,K\n JJ=JJ+1\n WORK(JJ)=WORK(JJ)+X(I,J)*X(I,K)*TEMP\n 2330 CONTINUE\n TEMP=(YS**2*YN-YSU**2*YNU)/TINT\nC\nC\nC * THE NEXT LINE IS CORRECTED ACCORDING TO REMARK AS R 32 *\nC * APPL.STAT. VOL 30, P. 105 (1981). *\nC\nC\n KK=II-MPLONE+K\n WORK(KK)=WORK(KK)-(TEMP+A*B)*X(I,K)\n 2350 CONTINUE\n\n TEMP=(YS**3*YN-YSU**3*YNU)/TINT\n WORK(II)=WORK(II)-TEMP+B**2\n ENDIF\n 2500 CONTINUE\nC\nC * INVERT THE MATRIX *\nC\n CALL SYMINV(WORK,MPLONE,VCOV,W,NUL,LENWRK,LENWRK,LENW,IFAULT)\n\n IF((IFAULT.NE.0).OR.(NUL.NE.0)) THEN\n VCOV(2)=REAL(IFAULT)\n VCOV(1)=REAL(NUL)\n IFAULT=-6\n ICHECK=IJ\n RETURN\n ENDIF\nC\nC * RESTORE THE ITERATION COUNTER *\nC\n IFAULT=IJ\nC\nC * MULTIPLY BY SIGMA-SQUARED *\nC\n TEMP=XSIG**2\n DO 2580 I=1,II\n VCOV(I)=VCOV(I)*TEMP\n 2580 CONTINUE\n\nC\nC * UNPACK THE MATRIX *\nC\n CALL UNPACK(VCOV,MPLONE,LENWRK)\n\n RETURN\n END\n", "meta": {"hexsha": "a2c1674938888fae862623da6931ed25b0af79f7", "size": 12887, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "stsdas/pkg/analysis/statistics/em/emalgo.f", "max_stars_repo_name": "iraf-community/stsdas", "max_stars_repo_head_hexsha": "043c173fd5497c18c2b1bfe8bcff65180bca3996", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-12-20T10:06:48.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-20T10:06:48.000Z", "max_issues_repo_path": "stsdas/pkg/analysis/statistics/em/emalgo.f", "max_issues_repo_name": "spacetelescope/stsdas_stripped", "max_issues_repo_head_hexsha": "043c173fd5497c18c2b1bfe8bcff65180bca3996", "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": "stsdas/pkg/analysis/statistics/em/emalgo.f", "max_forks_repo_name": "spacetelescope/stsdas_stripped", "max_forks_repo_head_hexsha": "043c173fd5497c18c2b1bfe8bcff65180bca3996", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-10-12T20:01:16.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-19T08:04:30.000Z", "avg_line_length": 28.765625, "max_line_length": 78, "alphanum_fraction": 0.4156902305, "num_tokens": 4003, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765304654121, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.684423405894669}} {"text": "!!Contains the subroutines needed to find a niggli reduced\n!!cell and to identify it.\n\nModule niggli\n use vector_matrix_utilities, only: determinant\n use numerical_utilities\n use num_types\n implicit none\n private\n public reduce_cell, id_cell\n\n\nCONTAINS\n\n !!Finds the niggli reduced cell from the users given\n !!cell.\n !!A 3 by 3 matrix with the basis\n !!vectors as columns.\n !!Optional floating point\n !!tolerance.\n !!An optional bool, true if\n !!the reduction path is to be printed at the end.\n !!The niggli reduced\n !!cell.\n !!The transformation\n !!matrix.\n SUBROUTINE reduce_cell(IN,n_cell,trans,eps_,path_)\n real(dp), intent(in) :: IN(3,3)\n real(dp), intent(in), optional :: eps_\n logical, intent(in), optional :: path_\n real(dp), intent(out) :: n_cell(3,3)\n integer, intent(out) :: trans(3,3)\n\n !!The vol of the input matrix.\n !!The floating point tolerance.\n !!The path taken by the reduction.\n !!The square of the first lattice vector.\n !!The square of the second lattice vector.\n !!The square of the third lattice vector.\n !!Twice the angle between the 2nd and 3rd lattice\n !!vectors.\n !!Twice the angle between the 3nd and 1st lattice\n !!vectors.\n !!Twice the angle between the 1st and 2nd lattice\n !!vectors.\n !!The sign of xi.\n !!The sign of eta.\n !!The sign of zeta.\n !!True if the cell is reduced.\n !!The number of passes through the steps that\n !!have been taken.\n !!A temporary lattice.\n !!Temporary transoframtion matrix.\n real(dp) :: vol, eps, temp_lat(3,3)\n character(len=2000):: path\n real(dp) :: A, B, C, xi, eta, zeta\n integer :: l, m, n, count, temp_M(3,3)\n logical :: reduced\n\n vol = determinant(IN)\n\n if (equal(vol,0._dp,0.000001_dp)) stop \"Input matrix is linearly dependent.\"\n\n if (present(eps_)) then\n eps = eps_*abs(vol)**(1.0_dp/3.0_dp)\n else\n eps = (10.0_dp**(-5.0_dp))*abs(vol)**(1.0_dp/3.0_dp)\n end if\n\n path = ''\n count = 0\n reduced = .False.\n trans = transpose(reshape((/ 1, 0, 0, 0, 1, 0, 0, 0, 1 /),(/3,3/)))\n\n call get_params(IN,eps,A,B,C,xi,eta,zeta,l,m,n)\n\n do while ((.not. reduced) .and. (count <= 1000))\n reduced = .True.\n count = count + 1\n ! step #1\n if ((A>(B+eps)) .or. ((.not. (ABS(A-B)>eps)) .and. (ABS(xi)>(ABS(eta)+eps))))then\n path = trim(path) // \"1\"\n reduced = .False.\n trans = matmul(trans,transpose(reshape((/0, -1, 0, -1, 0, 0, 0, 0, -1/),(/3,3/))))\n temp_lat = matmul(IN,trans)\n call get_params(temp_lat,eps,A,B,C,xi,eta,zeta,l,m,n)\n end if\n\n ! step #2\n if ((B>(C+eps)) .or. ((.not. (ABS(C-B)>eps) .and. (ABS(eta)>ABS(zeta)+eps)))) then\n path = trim(path) // \"2\"\n reduced = .False.\n trans = matmul(trans, transpose(reshape((/-1, 0, 0, 0, 0, -1, 0, -1, 0/),(/3,3/))))\n temp_lat = matmul(IN,trans)\n call get_params(temp_lat,eps,A,B,C,xi,eta,zeta,l,m,n)\n cycle\n end if\n\n ! step #3\n if (l*m*n==1) then\n path = trim(path) // \"3\"\n call find_C3(l,m,n,temp_M)\n if (.not. (all(abs(temp_M-transpose(reshape((/1, 0, 0, 0, 1, 0, 0, 0, 1/),(/3,3/))))==0))) then\n reduced = .False.\n end if\n trans = matmul(trans,temp_M)\n temp_lat = matmul(IN,trans)\n call get_params(temp_lat,eps,A,B,C,xi,eta,zeta,l,m,n)\n end if\n\n ! step #4\n if ((l*m*n==0) .or. (l*m*n==(-1))) then\n path = trim(path) // \"4\"\n call find_C4(l,m,n,temp_M)\n if (.not. (all(abs(temp_M-transpose(reshape((/1, 0, 0, 0, 1, 0, 0, 0, 1/),(/3,3/))))==0))) then\n reduced = .False.\n end if\n trans = matmul(trans,temp_M)\n temp_lat = matmul(IN,trans)\n call get_params(temp_lat,eps,A,B,C,xi,eta,zeta,l,m,n)\n end if\n\n ! step #5\n if ((ABS(xi)>(B+eps)) .or. ((.not. (ABS(B-xi)>eps)) .and. (2.0_dp*eta<(zeta-eps))) .or. ((.not. (ABS(B+xi)>eps)) .and. (zeta<(-eps)))) then\n path = trim(path) // \"5\"\n reduced = .False.\n trans = matmul(trans,transpose(reshape((/1, 0, 0, 0, 1, -get_sign(xi), 0, 0, 1/),(/3,3/))))\n temp_lat = matmul(IN,trans)\n call get_params(temp_lat,eps,A,B,C,xi,eta,zeta,l,m,n)\n cycle\n end if\n\n ! step #6\n if ((ABS(eta)>(A+eps)) .or. ((.not. (ABS(A-eta)>eps)) .and. (2.0_dp*xi<(zeta-eps))) .or. ((.not. (ABS(A+eta)>eps)) .and. (zeta<(-eps)))) then\n path = trim(path) // \"6\"\n reduced = .False.\n trans = matmul(trans,transpose(reshape((/1, 0, -get_sign(eta), 0, 1, 0, 0, 0, 1/),(/3,3/))))\n temp_lat = matmul(IN,trans)\n call get_params(temp_lat,eps,A,B,C,xi,eta,zeta,l,m,n)\n cycle\n end if\n\n ! step #7\n if ((ABS(zeta)>(A+eps)) .or. ((.not. (ABS(A-zeta)>eps)) .and. (2.0_dp*xi<(eta-eps))) .or. ((.not. ABS(A+zeta)>eps) .and. (eta<(-eps)))) then\n path = trim(path) // \"7\"\n reduced = .False.\n trans = matmul(trans,transpose(reshape((/1, -get_sign(zeta), 0, 0, 1, 0, 0, 0, 1/),(/3,3/))))\n temp_lat = matmul(IN,trans)\n call get_params(temp_lat,eps,A,B,C,xi,eta,zeta,l,m,n)\n cycle\n end if\n\n ! step #8\n if (((xi+eta+zeta+A+B)<(-eps)) .or. ((.not. (ABS(xi+eta+zeta+A+B)>eps)) .and. ((2.0_dp*(A+eta)+zeta)>eps))) then\n path = trim(path) // \"8\"\n reduced = .False.\n trans = matmul(trans,transpose(reshape((/1, 0, 1, 0, 1, 1, 0, 0, 1/),(/3,3/))))\n temp_lat = matmul(IN,trans)\n call get_params(temp_lat,eps,A,B,C,xi,eta,zeta,l,m,n)\n cycle\n end if\n end do\n\n if (present(path_)) then\n if (path_) then\n print *, trim(path)\n end if\n end if\n\n if (count >= 1000) stop \"Could not reduce the cell in 1000 iterations. This could be because of floating point error, try providing a smaller eps.\"\n\n if (.not. (condition_check(A,B,C,xi,eta,zeta,eps))) stop \"Cell reduction failed to satisfy niggli conditions.\"\n\n n_cell = matmul(IN,trans)\n\n end SUBROUTINE reduce_cell\n\n !!Returns .True. if the niggli cell is completely reduced,\n !!.False. if otherwise.\n !!The value of\n !!IN(:,1).IN(:,1)\n !!The value of\n !!IN(:,2).IN(:,2)\n !!The value of\n !!IN(:,3).IN(:,3)\n !!The value of\n !!2*IN(:,2).IN(:,3)\n !!The value of\n !!2*IN(:,3).IN(:,1)\n !!The value of\n !!2*IN(:,1).IN(:,2)\n !!The floating point\n !!tolerance.\n function condition_check(A,B,C,xi,eta,zeta,eps)\n logical :: condition_check\n real(dp), intent(in) :: A, B, C, xi, eta, zeta, eps\n\n condition_check = .True.\n\n if (.not. (((A-eps)>0.0_dp) .and. ((A<(B-eps)) .or. (ABS(A-B)0.0_dp) .and. ((eta-eps)>0.0_dp) .and. ((zeta-eps)>0.0_dp)) .or. (((xi<0.0_dp) .or. (ABS(xi)Finds the sign (-1,0,0) of a real number.\n !!A real number.\n function get_sign(a)\n integer :: get_sign\n real(dp), intent(in) :: a\n\n if (a>0) then\n get_sign = 1\n else if (a<0) then\n get_sign = -1\n else\n get_sign = 0\n end if\n end function get_sign\n\n !!Finds the transformation matrix for the operations of\n !!step 4.\n !!The sign of xi.\n !!The sign of eta.\n !!The sign of zeta.\n !!The transformation\n !!matrix.\n SUBROUTINE find_C4(l,m,n,trans)\n integer, intent(in) :: l,m,n\n integer, intent(out) :: trans(3,3)\n\n integer :: i, j, k, r\n\n if ((l==(-1)) .and. (m==(-1)) .and. (n==(-1))) then\n i = 1\n j = 1\n k = 1\n else\n\n i = 1\n j = 1\n k = 1\n r = -1\n\n if (l==1) then\n i = -1\n else if (l==0) then\n r = 0\n end if\n\n if (m==1) then\n j = -1\n else if (m==0) then\n r = 1\n end if\n\n if (n==1) then\n k = -1\n else if (n==0) then\n r = 2\n end if\n\n if (i*j*k == (-1)) then\n if (r==0) then\n i = -1\n else if (r==1) then\n j = -1\n else if (r==2) then\n k = -1\n end if\n end if\n end if\n\n trans = transpose(reshape((/i, 0, 0, 0, j, 0, 0, 0, k/),(/3,3/)))\n\n end SUBROUTINE find_C4\n\n !!Finds the transformation matrix for the operation of step\n !!3.\n !!The sign of xi.\n !!The sign of eta.\n !!The sign of zeta.\n !!The transformation\n !!matrix.\n SUBROUTINE find_C3(l,m,n,trans)\n integer, intent(in) :: l,m,n\n integer, intent(out) :: trans(3,3)\n\n integer :: i, j, k\n\n if (l==(-1)) then\n i = -1\n else\n i = 1\n end if\n\n if (m==(-1)) then\n j = -1\n else\n j = 1\n end if\n\n if (n==(-1)) then\n k = -1\n else\n k = 1\n end if\n\n trans = transpose(reshape((/i, 0, 0, 0, j, 0, 0, 0, k/),(/3,3/)))\n\n end SUBROUTINE find_C3\n\n !!Gets the G vector (A,B,C,xi,eta,zeta) for a given input\n !!matrix.\n !!The matrix being\n !!reduced.\n !!The floating point\n !!tolerance.\n !!The value of\n !!IN(:,1).IN(:,1)\n !!The value of\n !!IN(:,2).IN(:,2)\n !!The value of\n !!IN(:,3).IN(:,3)\n !!The value of\n !!2*IN(:,2).IN(:,3)\n !!The value of\n !!2*IN(:,3).IN(:,1)\n !!The value of\n !!2*IN(:,1).IN(:,2)\n !!1 if xi is positive, -1 if it\n !!is negatev, 0 otherwise.\n !!1 if eta is positive, -1 if it\n !!is negatev, 0 otherwise.\n !!1 if zeta is positive, -1 if it\n !!is negatev, 0 otherwise.\n SUBROUTINE get_params(IN,eps,A,B,C,xi,eta,zeta,l,m,n)\n real(dp), intent(in) :: IN(3,3), eps\n real(dp), intent(out) :: A, B, C, xi, eta, zeta\n integer, intent(out) :: l, m, n\n\n A = dot_product(IN(:,1),IN(:,1))\n B = dot_product(IN(:,2),IN(:,2))\n C = dot_product(IN(:,3),IN(:,3))\n xi = 2.0_dp*dot_product(IN(:,2),IN(:,3))\n eta = 2.0_dp*dot_product(IN(:,3),IN(:,1))\n zeta = 2.0_dp*dot_product(IN(:,1),IN(:,2))\n\n if (xi<-eps) then\n l = -1\n else if (xi>eps) then\n l = 1\n else\n l = 0\n end if\n\n if (eta<-eps) then\n m = -1\n else if (eta>eps) then\n m = 1\n else\n m = 0\n end if\n\n if (zeta<-eps) then\n n = -1\n else if (zeta>eps) then\n n = 1\n else\n n = 0\n end if\n\n end SUBROUTINE get_params\n\n !!Identifies which of the niggli cells is currently being\n !!used.\n !!The users basis.\n !!The users niggli cell\n !!basis.\n !!The niggli basis for our\n !!cell.\n !!Our basis for the\n !!cell.\n !!The transformation for the\n !!users basis.\n !!The transformaiton for our\n !!basis.\n !!The niggli cell\n !!number.\n !!The range of determinant\n !!sizes to search over.\n !!Optional floating point\n !!tolerance.\n SUBROUTINE id_cell(U, Nu, Cu, O, No, Co, id, s_range, eps_)\n real(dp), intent(in) :: U(3,3)\n real(dp), intent(in), optional :: eps_\n real(dp), intent(out) :: O(3,3), Nu(3,3), No(3,3)\n integer, intent(out) :: Cu(3,3), Co(3,3)\n integer, intent(out) :: id, s_range\n\n real(dp) :: eps\n real(dp) :: temp_a(3), temp_b(3), temp_c(3), A, B, C, D, E, F\n logical :: positive\n\n if (present(eps_)) then\n eps = eps_\n else\n eps = (10.0_dp**(-5.0_dp))\n end if\n\n call reduce_cell(U,Nu,Cu,eps_=eps)\n !! Integer transformation check TODO\n\n temp_a = Nu(:,1)\n temp_b = Nu(:,2)\n temp_c = Nu(:,3)\n\n A = dot_product(temp_a,temp_a)\n B = dot_product(temp_b,temp_b)\n C = dot_product(temp_c,temp_c)\n D = dot_product(temp_b,temp_c)\n E = dot_product(temp_a,temp_c)\n F = dot_product(temp_a,temp_b)\n\n positive = .False.\n if (((D-eps)>0) .and. ((E-eps)>0) .and. ((F-eps)>0)) then\n positive = .True.\n end if\n\n id = (-1)\n if (isclose(A,B,atol_=eps) .and. isclose(B,C,atol_=eps)) then !!lengths the same\n if (positive .eqv. .True.) then !! all angles acute?\n if (isclose(D,E,atol_=eps) .and. isclose(D,F,atol_=eps)) then !!all angles the same?\n if (isclose((A/2.0_dp),D,atol_=eps)) then\n id = 1 !! fcc\n s_range = 1\n O = reshape((/0.0_dp, 1.0_dp, 1.0_dp, 1.0_dp, 0.0_dp, 1.0_dp, 1.0_dp, &\n 1.0_dp, 0.0_dp/),(/3,3/))\n else\n id = 2 !! Acute Rhombohedral, angles not 90 or 60 but all the same\n s_range = 25\n O = reshape((/-1.11652_dp, -0.610985_dp, 0.616515_dp, 0.0_dp, &\n -1.32288_dp, -0.5_dp, 1.0_dp, 1.32288_dp, 1.5_dp/),(/3,3/))\n end if\n end if\n else !! not acute angles.\n if (isclose(D,E,atol_=eps) .and. isclose(D,F,atol_=eps)) then !! all angles the same.\n if (isclose(0.0_dp,D,atol_=eps)) then !! all angles close to 0.\n id = 3 !! simple cubic.\n s_range = 1\n O = reshape((/1.0_dp, 0.0_dp, 0.0_dp, 0.0_dp, 1.0_dp, 0.0_dp, 0.0_dp, &\n 0.0_dp, 1.0_dp/),(/3,3/))\n else if (isclose((-A/3.0_dp),D,atol_=eps)) then\n id = 5 !! bcc\n s_range = 1\n O = reshape((/-1.0_dp, 1.0_dp, 1.0_dp, 1.0_dp, -1.0_dp, 1.0_dp, &\n 1.0_dp, 1.0_dp, -1.0_dp/),(/3,3/))\n else\n id = 4 !! Obtuse Rhombohedral, angles not 90 or 60 but all the same\n s_range = 25\n O = reshape((/-0.548584_dp, 0.774292_dp, 1.04858_dp, 0.0_dp, &\n -1.32288_dp, 0.5_dp, 1.0_dp, 1.32288_dp, 0.5_dp/),(/3,3/))\n end if\n else if (isclose((2.0_dp*ABS(D+E+F)),(A+B),atol_=eps)) then !! not all angles the same.\n if (isclose(D,E,atol_=eps)) then\n id = 6 !! body-centered Tetragonal\n s_range = 25\n O = reshape((/1.80278_dp, -1.47253_dp, 0.762655_dp, 2.80278_dp, &\n 0.13535_dp, -0.791285_dp, 0.80278_dp, -0.47253_dp, 2.762655_dp/),(/3,3/))\n else if (isclose(E,F,atol_=eps)) then\n id = 7 !! body-centered Tetragonal\n s_range = 25\n O = reshape((/1.95095_dp, 1.19163_dp, 0.879663_dp, 0.0_dp, &\n 2.60788_dp, 0.44606_dp, 0.95095_dp, -0.41625_dp, 2.433603_dp/),(/3,3/))\n else\n id = 8 !! body-centered Orthorhombic\n s_range = 15\n O = reshape((/1.41144_dp, 0.0885622_dp, -2.0_dp, -0.99868_dp, 2.21232_dp,&\n 1.268178_dp, 3.41012_dp, -1.1237578_dp, -1.268178_dp/),(/3,3/))\n end if\n end if !! 2|D+E+F|==(A+B)\n end if !! are the angles acute?\n end if !! are all the lattice vector lengths the same?\n\n if (isclose(A,B,atol_=eps) .and. (id==(-1))) then !! A==B!=C\n if (positive .eqv. .True.) then !! all angles acute.\n if (isclose(D,E,atol_=eps) .and. isclose(D,F,atol_=eps) .and. &\n isclose((A/2.0_dp),D,atol_=eps)) then !! all angles the same and 60 degrees.\n id = 9 !! Hexagonal Rhombohedral\n s_range = 25\n O = reshape((/1.0_dp, 2.0_dp, 2.0_dp, 2.0_dp, 1.0_dp, 2.0_dp, 4.0_dp, &\n 3.0_dp, 3.0_dp/),(/3,3/))\n else if (isclose(D,E,atol_=eps)) then\n id = 10 !! base-centered Monoclinic\n s_range = 10\n O = reshape((/1.0_dp, -1.0_dp, 1.0_dp, -1.46391_dp, 0.0_dp, 1.96391_dp, &\n 0.0_dp, 2.0_dp, 0.0_dp/),(/3,3/))\n end if\n else !! some angles obtuse.\n if (isclose(D,E,atol_=eps) .and. isclose(D,F,atol_=eps) .and. &\n isclose(0.0_dp,D,atol_=eps)) then !! all angles close to 0.\n id = 11 !! Primitive Tetragonal\n s_range = 25\n O = reshape((/1.0_dp, 0.0_dp, 0.0_dp, 0.0_dp, 1.0_dp, 0.0_dp, 0.0_dp, &\n 0.0_dp, 2.0_dp/),(/3,3/))\n else if (isclose(D,E,atol_=eps)) then !! two angles the same\n if (isclose(0.0_dp,D,atol_=eps) .and. isclose((-A/2.0_dp),F,atol_=eps)) then !! D==E==0 and F==120\n id = 12 !! Primitive Hexagonal 120 degrees.\n s_range = 25\n O = reshape((/1.0_dp, 0.0_dp, 0.0_dp, 0.5_dp, -0.8660254037844386_dp, &\n 0.0_dp, 0.0_dp, 0.0_dp, 2.0_dp/),(/3,3/))\n else if (isclose((-A/2.0_dp),D,atol_=eps) .and. isclose(0.0_dp,F,atol_= eps)) then !! D==E==120 and F==0\n id = 15 !! body-centered Tetragonal\n s_range = 25\n O = reshape((/-1.0_dp, -1.0_dp, 2.0_dp, 0.0_dp, -2.0_dp, 0.0_dp, -2.0_dp, &\n 0.0_dp, 0.0_dp/),(/3,3/))\n else if (isclose(0.0_dp,D,atol_=eps)) then !! D==E==0 and no constraint on F.\n id = 13 !! base-centered Orthorhombic\n s_range = 15\n O = reshape((/1.0_dp, 1.0_dp, 1.0_dp, 1.0_dp, -1.0_dp, -1.0_dp, 0.0_dp, &\n -1.73205_dp, 1.73205_dp/),(/3,3/))\n else if (isclose((2.0_dp*ABS(D+E+F)),(A+B),atol_=eps)) then !! 2|D+E+F|==(A+B)\n id = 16 !! face-centered Orthorhombic\n s_range = 20\n O = reshape((/1.04442_dp, 1.43973_dp, 1.68415_dp, 0.779796_dp, -1.1789_dp, &\n 1.0_dp, 1.779796_dp, -0.1789_dp, 0.0_dp/),(/3,3/))\n else\n id = 14 !! base-centered Monoclinic\n s_range = 10\n O = reshape((/-1.0_dp, 1.0_dp, 0.0_dp, 0.5_dp, 0.0_dp, 2.0_dp, 0.0_dp, &\n -2.0_dp, 0.0_dp/),(/3,3/))\n end if\n else if (isclose((2.0_dp*ABS(D+E+F)),(A+B),atol_=eps)) then\n id = 17 !! base-centered Monoclinic\n s_range = 10\n O = reshape((/-1.05387_dp, -1.61088_dp, 1.51474_dp, -0.244302_dp, -2.77045_dp, &\n 0.51474_dp, 1.809568_dp, -0.15957_dp, 0.0_dp/),(/3,3/))\n end if\n end if !! acute or obtuse angles.\n end if !! A==B!=C\n\n if (isclose(B,C,atol_=eps) .and. (id==(-1))) then !! B==C!=A\n if (positive .eqv. .True.) then !! all angles acute\n if (isclose(E,F,atol_=eps)) then !! E==F\n if (isclose((A/4.0_dp),D,atol_=eps) .and. isclose((A/2.0_dp),E,atol_=eps)) then\n id = 18\n s_range = 25\n O = reshape((/-2.0_dp, -1.0_dp, 1.0_dp, -3.0_dp, 1.0_dp, 0.0_dp, -1.0_dp, &\n -3.0_dp, 0.0_dp/),(/3,3/))\n else if (isclose((A/2.0_dp),E,atol_=eps)) then\n id = 19\n s_range = 15\n O = reshape((/0.5_dp, 1.0_dp, 1.5_dp, 0.0_dp, 2.0_dp, 0.0_dp, 0.0_dp, &\n 0.0_dp, 3.0_dp/),(/3,3/))\n else\n id = 20\n s_range = 10\n O = reshape((/1.0_dp, 1.0_dp, 1.0_dp, 1.70119_dp, -1.45119_dp, 1.0_dp, &\n 0.69779_dp, -1.4322505_dp, 3.23446_dp/),(/3,3/))\n end if\n end if\n else\n if (isclose(E,F,atol_= eps)) then\n if (isclose(0.0_dp,D,atol_=eps) .and. isclose(0.0_dp,E,atol_=eps)) then\n id = 21\n s_range = 25\n O = reshape((/0.0_dp, 0.0_dp, 0.5_dp, 1.0_dp, 0.0_dp, 0.0_dp, 0.0_dp, &\n 1.0_dp, 0.0_dp/),(/3,3/))\n else if (isclose((-B/2.0_dp),D,atol_=eps) .and. isclose(0.0_dp,E,atol_=eps)) then\n id = 22\n s_range = 25\n O = reshape((/0.0_dp, 0.0_dp, -0.5_dp, 1.0_dp, 0.0_dp, 0.0_dp, &\n -0.5_dp, 0.8660254037844386_dp, 0.0_dp/),(/3,3/))\n else if (isclose(0.0_dp,E,atol_=eps)) then\n id = 23\n s_range = 15\n O = reshape((/-0.3333333_dp, -1.54116_dp, 1.87449_dp, 1.0_dp, 1.0_dp, &\n 1.0_dp, 2.0_dp, -1.0_dp, -1.0_dp/),(/3,3/))\n else if (isclose((2.0_dp*ABS(D+E+F)),(A+B),atol_=eps) .and. &\n isclose((-A/3.0_dp),E,atol_=eps)) then\n id = 24\n s_range = 25\n O = reshape((/-0.255922_dp, -1.44338_dp, 0.92259_dp, 1.51184_dp, &\n 0.0_dp, -0.845178_dp, 1.255922_dp, 1.44338_dp, 0.07741_dp/),(/3,3/))\n else\n id = 25\n s_range = 10\n O = reshape((/1.0_dp, 1.0_dp, 1.0_dp, 1.45119_dp, -1.70119_dp, &\n -1.0_dp, 0.28878_dp, -3.26895_dp, 0.48018_dp/),(/3,3/))\n end if\n end if\n end if\n end if\n\n if (id==(-1)) then\n if (positive .eqv. .True.) then\n if (isclose(E,F,atol_=eps)) then\n !! Why did we not use isclose()? TODO\n if ((ABS((A/4.0_dp)-D)<= ABS(eps*D)) .and. (ABS((A/2.0_dp)-E)<= ABS(eps*E))) then\n id = 26\n s_range = 20\n O = reshape((/0.0_dp, 1.0_dp, 1.5_dp, 0.5_dp, 0.0_dp, 1.5_dp, 0.0_dp, &\n 0.0_dp, 3.0_dp/),(/3,3/))\n else if (isclose((A/2.0_dp),E,atol_=eps)) then\n id = 27\n s_range = 10\n O = reshape((/-1.464824_dp,0.464824_dp,1.907413_dp,-0.153209_dp,0.153209_dp, &\n -2.907413_dp,1.0_dp,1.0_dp,0.0_dp/),(/3,3/))\n else ! Default to Triclinic (same behavior as VASP)\n id = 31\n s_range = 1\n O = U\n end if\n else !! E==F\n if (isclose((A/2.0_dp),E,atol_=eps) .and. isclose((2.0_dp*D),F,atol_=eps)) then\n id = 28\n s_range = 10\n O = reshape((/-1.44896_dp, 0.948958_dp, -1.0_dp, -1.0_dp, -1.0_dp, &\n 0.0_dp, 0.342424_dp, -1.342424_dp, -2.02006_dp/),(/3,3/))\n else if (isclose((A/2.0_dp),F,atol_=eps) .and. &\n isclose((2.0_dp*D),E,atol_=eps)) then\n id = 29\n s_range = 10\n O = reshape((/-0.666125_dp, 1.16613_dp, 2.04852_dp, 1.0_dp, 1.0_dp, &\n 0.0_dp, 1.61803_dp, -0.618034_dp, 1.0_dp/),(/3,3/))\n else if (isclose((B/2.0_dp),D,atol_=eps) .and. &\n isclose((2.0_dp*E),F,atol_=eps)) then\n id = 30\n s_range = 10\n O = reshape((/1.0_dp, 1.0_dp, 0.0_dp, 1.61803_dp, -0.618034_dp, 1.0_dp, &\n -0.0361373_dp, 0.536137_dp, 2.38982_dp/),(/3,3/))\n else\n id = 31\n s_range = 1\n O = U\n end if\n end if\n else\n if (isclose(E,F,atol_=eps) .and. isclose(0.0_dp,E,atol_=eps)) then\n if (isclose(0.0_dp,D,atol_=eps)) then\n id = 32\n s_range = 15\n O = reshape((/1.0_dp, 0.0_dp, 0.0_dp, 0.0_dp, 2.0_dp, 0.0_dp, 0.0_dp, &\n 0.0_dp, 3.0_dp/),(/3,3/))\n else if (isclose(D,(-B/2.0_dp),atol_=eps)) then\n id = 40\n s_range = 15\n O = reshape((/1.0_dp, 1.0_dp, 1.0_dp, 1.61803_dp, -0.618034_dp, &\n -1.0_dp, -1.05557_dp, 1.99895_dp, -0.943376_dp/),(/3,3/))\n else\n id = 35\n s_range = 10\n O = reshape((/-0.668912_dp, 1.96676_dp, -1.29785_dp, 1.61803_dp, &\n -0.618034_dp, -1.0_dp, 1.0_dp, 1.0_dp, 1.0_dp/),(/3,3/))\n end if\n else if (isclose(D,F,atol_=eps) .and. isclose(0.0_dp,D,atol_=eps)) then\n if (isclose((-A/2.0_dp),E,atol_=eps)) then\n id = 36\n s_range = 15\n O = reshape((/1.0_dp, 1.0_dp, 1.0_dp, 1.41421_dp, -1.41421_dp, &\n 0.0_dp, -1.43541_dp, -1.43541_dp, 1.37083_dp/),(/3,3/))\n else\n id = 33\n s_range = 10\n O = reshape((/2.0_dp, 0.0_dp, 0.0_dp, 0.0_dp, 2.0_dp, 0.0_dp, 0.5_dp, &\n 0.0_dp, 2.0_dp/),(/3,3/))\n end if\n else if (isclose(D,E,atol_=eps) .and. isclose(0.0_dp,D,atol_=eps)) then\n if (ABS((-A/2.0_dp)-F)<= ABS(eps*F)) then\n id = 38\n s_range = 15\n O = reshape((/0.5_dp, 1.0_dp, 0.0_dp, 0.5_dp, -1.0_dp, 0.0_dp, 0.0_dp, &\n 0.0_dp, 3.0_dp/),(/3,3/))\n else\n id = 34\n s_range = 10\n O = reshape((/1.0_dp, 1.0_dp, 1.0_dp, 1.22474487_dp, -1.22474487_dp, &\n -1.0_dp, -0.16598509_dp, -1.64308297_dp, 1.80906806_dp/),(/3,3/))\n end if\n else\n if (isclose((-B/2.0_dp),D,atol_=eps) .and. isclose((-A/2.0_dp),E,atol_=eps) &\n .and. isclose(0.0_dp,F,atol_=eps)) then\n id = 42\n s_range = 20\n O = reshape((/-1.53633_dp, 1.36706_dp, -1.33073_dp, 1.0_dp, 1.0_dp, &\n 1.0_dp, 1.61803_dp, -0.61803_dp, -1.0_dp/),(/3,3/))\n else if (isclose((-B/2.0_dp),D,atol_=eps) .and. isclose(0.0_dp,F,atol_=eps)) then\n id = 41\n s_range = 10\n O = reshape((/-1.85397_dp, -0.854143_dp, 1.35397_dp, 1.0_dp, 0.0_dp, &\n 1.0_dp, 1.0_dp, -1.41421_dp, -1.0_dp/),(/3,3/))\n else if (isclose((-A/2.0_dp),E,atol_=eps) .and. isclose(0.0_dp,F,atol_=eps)) then\n id = 37\n s_range = 10\n O = reshape((/-1.79092_dp, -1.47209_dp, 0.790922_dp, 1.0_dp, -1.41421_dp, &\n -1.0_dp, 1.0_dp, 0.0_dp, 1.0_dp/),(/3,3/))\n else if (isclose(0.0_dp,E,atol_=eps) .and. isclose((-A/2.0_dp),F,atol_=eps)) then\n id = 39\n s_range = 10\n O = reshape((/0.0_dp, -1.73205_dp, -1.0_dp, -1.66542_dp, -0.672857_dp, &\n 1.66542_dp, 1.0_dp, 0.0_dp, 1.0_dp/),(/3,3/))\n else if (isclose((2.0_dp*ABS(D+E+F)),(A+B),atol_=eps) .and. &\n isclose(ABS(2.0_dp*D+F),B,atol_=eps)) then\n id = 43\n s_range = 10\n O = reshape((/-0.39716_dp, -0.34718_dp, 2.49434_dp, 2.64194_dp, &\n -0.14194_dp, 0.0_dp, -1.39716_dp, -1.34718_dp, 1.49434_dp/),(/3,3/))\n else\n id = 44\n s_range = 1\n O = U\n end if\n end if\n end if\n end if\n\n\n !! see table 9.2.5.1 in the international tables (pdf in autoGR/support/documents)\n open(5,file=\"autoGR.out\")\n write(5,'(\"Niggli cell id: \",I2)') id\n\n call reduce_cell(O,No,Co,eps_=eps)\n\n end SUBROUTINE id_cell\n\n !!Matches the numpy allclose function for single floats.\n !!The first value to compare.\n !!The second value to compare.\n !!Relative tolerance.\n !!Absolute tolerance.\n Function isclose(A,B,rtol_,atol_)\n logical :: isclose\n real(dp), intent(in) :: A, B\n real(dp), optional, intent(in) :: rtol_, atol_\n\n real(dp) :: rtol, atol\n\n if (present(rtol_)) then\n rtol = rtol_\n else\n rtol = 10.0_dp**(-5.0_dp)\n end if\n\n if (present(atol_)) then\n atol = atol_\n else\n atol = 10.0_dp**(-8.0_dp)\n end if\n\n if (ABS(A-B) <= (atol+rtol*ABS(B))) then\n isclose = .True.\n else\n isclose = .False.\n end if\n\n end Function isclose\n\nend Module niggli\n", "meta": {"hexsha": "09b83ba8082d377cb7a9eec3d2903444487f64e4", "size": 31732, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/niggli.f90", "max_stars_repo_name": "glwhart/autoGR", "max_stars_repo_head_hexsha": "4c031eaa6ade736418ad9136d77004c258ef6fb4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2019-12-17T11:46:32.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T19:06:11.000Z", "max_issues_repo_path": "src/niggli.f90", "max_issues_repo_name": "glwhart/autoGR", "max_issues_repo_head_hexsha": "4c031eaa6ade736418ad9136d77004c258ef6fb4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2019-10-28T14:37:16.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-09T00:19:56.000Z", "max_forks_repo_path": "src/niggli.f90", "max_forks_repo_name": "glwhart/autoGR", "max_forks_repo_head_hexsha": "4c031eaa6ade736418ad9136d77004c258ef6fb4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2019-12-17T11:48:28.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-23T19:40:43.000Z", "avg_line_length": 39.1270036991, "max_line_length": 216, "alphanum_fraction": 0.5156939367, "num_tokens": 11432, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765163620469, "lm_q2_score": 0.7490872243177518, "lm_q1q2_score": 0.6844234055659586}} {"text": " double precision function psi(xd,yd,zd,t)\n implicit none\n\n double precision xd, yd, zd, t\n\n double precision kappa,tfinal\n common /windparms/ kappa,tfinal\n\n double precision pi, pi2\n common /compi/ pi, pi2\n\n double precision l, th, lp\n\nc call get_wind_parms(kappa,tfinal)\n\n call map2polar(xd,yd,zd,l,th)\n\n lp = l - 2*pi*t/tfinal\n\n psi = kappa*sin(lp)**2*cos(th)**2*cos(pi*t/Tfinal) -\n & 2*pi*sin(th)/Tfinal\n\nc # Sign difference from Benchmark problem\n psi = -psi\n\n\n end\n\n subroutine map2polar(x,y,z,lambda,th)\n implicit none\n\n double precision x,y,z,th,lambda\n double precision r\n\n double precision pi, pi2\n common /compi/ pi, pi2\n\n r = sqrt(x**2 + y**2 + z**2)\n th = asin(z/r)\n\n lambda = atan2(y,x)\n if (lambda .lt. 0) then\n lambda = lambda + 2*pi\n endif\n\n end\n\n\n subroutine get_psi_vel(xd1,xd2,ds,vn,t)\n implicit none\n\n double precision xd1(3),xd2(3), ds, vn, psi,t\n\n vn = (psi(xd1(1),xd1(2),xd1(3),t) -\n & psi(xd2(1),xd2(2),xd2(3),t))/ds\n\n end\n\n\n\n", "meta": {"hexsha": "54ab834e56219819f63e956b9f0e6fe0cf2017e8", "size": 1136, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "applications/clawpack/transport/2d/all/velocity_wind.f", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2017-09-26T13:39:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:56:23.000Z", "max_issues_repo_path": "applications/clawpack/transport/2d/all/velocity_wind.f", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 75, "max_issues_repo_issues_event_min_datetime": "2017-08-02T19:56:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T12:36:32.000Z", "max_forks_repo_path": "applications/clawpack/transport/2d/all/velocity_wind.f", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-02-21T00:10:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T19:08:36.000Z", "avg_line_length": 18.6229508197, "max_line_length": 58, "alphanum_fraction": 0.5580985915, "num_tokens": 370, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765257642905, "lm_q2_score": 0.749087201911703, "lm_q1q2_score": 0.6844233921371784}} {"text": " subroutine svd_solve(m, n, mp, np, a, b, v, w, nw)\n use kind_spec\n implicit none\nC-----------------------------------------------\nC D u m m y A r g u m e n t s\nC-----------------------------------------------\n integer m, n, mp, np, nw\n real(rprec), dimension(mp,np) :: a\n real(rprec), dimension(n,n) :: v\n real(rprec), dimension(n) :: w\n real(rprec), dimension(m) :: b\nC-----------------------------------------------\nC L o c a l P a r a m e t e r s\nC-----------------------------------------------\n real(rprec) :: small = 1.0e-10_dp\nC-----------------------------------------------\nC L o c a l V a r i a b l e s\nC-----------------------------------------------\n integer :: istat, i, j\n real(rprec), allocatable :: u(:,:)\nC-----------------------------------------------\n \nc Solves Matrix equation A * V = B for V using SVD method\nc Uses svd routines from numerical recipes\nc Prashant Valanju (Dec 1998) pvalanju@mail.utexas.edu\n \nc Almost same as SvdSolveB except this one finds\nc nw solutions V(:,i) by keeping i = 1 to nw vectors, where\nc nw is the number of vectors with nonzero weights > small\n\nc It also uses V internally for SVD decomposition to save space, so\n \nc Inputs:\nc A(M,N) - Matrix with physical dimensions (Mp,Np)\nc B(M) - R.H.S. of A X = B\nc M - Number of rows of A to use\nc N - Number of columns of A to use\nc Mp,NP - Storage dimensions of A(Mp,Np)\nc\nc Output:\nc nw - number of vectors with normalized weights above small\nc Eventually, this will be the number of optimum weights\nc after we decide on a criterion for optimization\nc V(N,nw) - nw Solutions of A V = B, each a vector of length N\nc V(:N,iw) = solution with top iw weights kept\nc Physical dimensions of V are (N,N)\nc w(n) - Weights in decreasing order\nc\n \nc Allocate local arrays. \nc Note u(m,n) is enough because needed part of a(mp,np) is copied to\nc u(m,n), and a(mp,np) is never used directly. This saves space.\nc It is essential to use a local u since svdcmp changes it\n\n allocate (u(m,n), stat=istat)\n if(istat.ne.0) stop 'Stop: No memory in svd_nesc' \n \nc.......................................\nc Initialize all to zero to wipe out effects of old call\n w(:n) = 0 !Zero all weights\n do j = 1, n\n u(:m,j) = a(:m,j) !Because U will be changed by svdcmp\n v(:n,j) = 0\n end do\n\nc Do the SVD decomposition of a, i.e, of u into u, v and w \n call svdcmp (u, m, n, m, n, w, v)\n \nc Sort weights and matrices with DECREASING weights so w(1) is biggest\nc Permute weight w(i) AND column vectors U(*,i), V(*,i) at the same time\n call sortsvd (m, n, m, n, w, u, v)\n \nc Find nw = number of large weights (dcreasing ordered by sortsvd)\n do nw = n, 1, -1 !Find first large weight and get out\n if ( abs(w(nw)/w(1)) .gt. small) exit\n end do\n\nc Find nw solutions by successively adding up eigenvectors V \nc with correct weight given by (U(i) dot b)/w(i) in eq 14.3.17 (NR). \nc The coeff of ith vector V(i) is the dot product of the i-th column\nc of U with the rhs vector B, divided by w(i)\nc This does the svdbksb directly, faster than the NR svdbksub routine\nc and uses less memory due to the dual role of V\nc Note: any optimization scheme to find the 'best' nw will \n\nc First set the 1st vector with largest weight w(1)\n v(:n,1) = sum(u(:m,1)*b(:m)) *v(:n,1) /w(1)\nc Next add the vectors with successive weights (in decreasing order)\n do i = 2, nw\n j = i - 1\n v(:n,i) = v(:n,j) + sum(u(:m,i)*b(:m)) *v(:n,i) / w(i)\n end do\nc................................................\n\n deallocate (u, stat=istat)\n\n! end subroutine svd_solve\n end\n\n\n subroutine svdsolveb(m, n, mp, np, wcut, file, a, b, x)\n use kind_spec\n implicit none\nC-----------------------------------------------\nC D u m m y A r g u m e n t s\nC-----------------------------------------------\n integer m, n, mp, np\n real(rprec) wcut\n real(rprec), dimension(mp,np) :: a\n real(rprec), dimension(n) :: b, x\n character file*(*)\nC-----------------------------------------------\nC L o c a l P a r a m e t e r s\nC-----------------------------------------------\n real(rprec) :: zero = 0\nC-----------------------------------------------\nC L o c a l V a r i a b l e s\nC-----------------------------------------------\n integer :: n1, nonzero, nlast, istat, i, j, iunit\n real(rprec), allocatable :: u(:,:), v(:,:), w(:)\n real(rprec) :: wmax, wmin, wcuta, udotb, err\nC-----------------------------------------------\n \nc Solves Matrix equation A X = B for X using SVD method\nc Allows supression of weights, storage and recall of answers\nc Uses svd routines from numerical recipes\nc Prashant Valanju (Sept 1998) pvalanju@mail.utexas.edu\n \nc Almost same as SvdSolveUV except this one stores basis vectors\nc rather than U, w, V. This one is a bit faster than SvdSolveUV, so\nc use this one when you want to change only weights, not B or A\n \nc Inputs:\nc A(M,N) - Matrix with physical dimensions (Mp,Np)\nc B(N) - R.H.S. of A X = B\nc M - Number of rows of A to use\nc N - Number of columns of A to use\nc Mp,NP - Storage dimensions of A(Mp,Np)\nc Wcut - Cutoff parameter\nc If Wcut = 0, writes answers into \"file\", all weights are kept\nc If Wcut < 0, reads previous answers from \"file\",\nc and uses -Wcut for weights to keep\nc If 0 < Wcut < 1 : Cuts off weights with w(i)/wmax < wcut\nc Use this to cut off small weights, does calculation\nc If Wcut = integer > 1, keeps Wcut weights, does calculation\nc Use this to cut off fixed number of weights\nc Output:\nc X(N) - Solution of A X = B\nc\n n1 = n\n \nc allocate local arrays\n allocate (u(mp,np), w(np), v(np,np), stat=istat)\n\n if (istat .eq. 0) then !have enough memory\n \n iunit = 41\n\n x(:n1) = zero !zero answer from previous call\n wcuta = abs(wcut)\nc...............................\nc If Wcut < 0 use precalculated weights to get answer fast\nc use wcuta = abs(wcut) for everything\nc If any error happens while reading \"file\", do full svd calculation\n if (wcut .lt. 0) then !Read file from previous calculation\n call safe_open(iunit, istat, file, 'old', 'formatted')\n if (istat .ne. 0) goto 98\n read (iunit, *, err=98)\n read (iunit, *, err=98)\n read (iunit, *, err=98) m, n, nonzero\nc !Read exactly the same way they were written\n do i = 1, nonzero\n read (iunit, *, err=98) w(i) !read i-th weight\n do j = 1, n !read i-th basis vector/ w(i)\nc !read j-th entry (row) of i-th column of V\n read (iunit, *, err=98) v(j,i)\n end do\n end do\n close(unit=iunit)\n \nc Decide how many weights to keep\n if (wcuta .gt. 1) nlast = wcuta !Keep Nlast weights\n if (wcuta .lt. 1) then !cutoff small weights\n wmax = w(1) !weights are already ordered\n nlast = 0\n do i = 1, nonzero\n if (w(i) .gt. wmax*wcuta) then\n nlast = nlast + 1 !accept this weight\n else\n go to 96\n endif\n end do\n endif\n \nc Just find linear sum of Nlast vectors (weights were already included)\n 96 continue\n if (nlast.le.0 .or. nlast.gt.nonzero) nlast = nonzero\n do i = 1, nlast !add ith column of V(*,i) to X(*)\n x(:n) = x(:n) + v(:n,i) !add to the j-th entry of X\n end do\n go to 999 !all done\n endif !End of precalculated branch Wcut < 0\n 98 continue\nc.......................................\nc If Wcut .ge. 0, do full svd calculation\nc Initialize all to zero to wipe out effects of old call\n do j = 1, n\n w(j) = zero !Zero all weights\n u(:m,j) = a(:m,j) !Because U will be changed by svdcmp\n v(:m,j) = zero\n end do\n \n call svdcmp (u, m, n, mp, np, w, v) !Do SVD decomposition\n \nc Sort weights and matrices with DECREASING weights\nc Permute weight w(i) AND column vectors U(*,i), V(*,i) at the same time\n call sortsvd (m, n, mp, np, w, u, v)\n \nc Find the number of nonzero weights (already dcreasing ordered)\n do nonzero = n, 1, -1\nc !Found first nonzero weight, get out\n if (w(nonzero) .ne. 0) exit \n end do\n if (nonzero .gt. 0) then\n if (wcuta .gt. 1) then\n \nc Decide how many weights to keep\n nlast = wcuta !Keep Nlast weights\n else !cutoff small weights\n wmax = w(1) !weights are already ordered\n nlast = 0\n do i = 1, nonzero\n if (w(i) .gt. wmax*wcuta) then\n nlast = nlast + 1 !accept this weight\n else\n go to 97\n endif\n end do\n endif\n \nc Find solution X and basis vectors (put into columns of V)\n 97 continue\n if (nlast.le.0 .or. nlast.gt.nonzero) nlast = nonzero\n do i = 1, nlast !Calc i-th coeff (U.b/w) for noNonzero w(i)\nc First calculate i-th coeff (U(i)*b/w(i)) in the sum in eq 14.3.17 (NR)\nc Dot product of i-th column of U with B\nc summed over all plasma points\n udotb = sum(u(:m,i)*b(:m))\nc !=(Ui.b/wi) in eq 14.3.17, saves many divisions\n udotb = udotb/w(i)\nc Now run down the i-th column of the vector V(j,i)\nc j-th entry (row) of vectors in eq 14.3.17\nc Now V is the basis vector times weight\n v(:n,i) = udotb*v(:n,i)\nc add it to the j-th entry of X\n x(:n) = x(:n) + v(:n,i)\n !This did the svdbksb, faster than NR\n end do !and also calculated the basis vectors\n \nc Write all weights and weighted basis functions into SVD file (Wcut=0)\n if (wcut .eq. 0) then\n call safe_open(iunit, istat, file, 'unknown','formatted')\n write (iunit, *) 'Max w = ', w(1), ', Min w = ', \n 1 w(nonzero)\n write (iunit, *) 'Ratio = ', w(1)/w(nonzero)\n write (iunit, *) m, n, nonzero\n do i = 1, nonzero !write in DECREASING order of weights\n write (iunit, *) w(i) !write i-th weight\n do j = 1, n !write i-th basis vector/ w(i)\n !write j-th entry (row) of i-th column of V\n write (iunit, *) v(j,i)\n end do\n end do\n close(unit=iunit)\n endif\nc................................................\n endif\n endif\n 999 continue\n\n deallocate (u, w, v, stat=istat)\n\n! end subroutine svdsolveb\n end\n\n\n subroutine svdsolveuv(m, n, mp, np, wcut, file, a, b, x)\n use kind_spec\n implicit none\nC-----------------------------------------------\nC D u m m y A r g u m e n t s\nC-----------------------------------------------\n integer m, n, mp, np\n real(rprec) wcut\n character file*(*)\n real(rprec), dimension(mp,np) :: a\n real(rprec), dimension(n) :: b, x\nC-----------------------------------------------\nC L o c a l P a r a m e t e r s\nC-----------------------------------------------\n real(rprec) :: zero = 0\nC-----------------------------------------------\nC L o c a l V a r i a b l e s\nC-----------------------------------------------\n integer :: n1, nonzero, nlast, istat, i, j, iunit\n real(rprec), allocatable :: u(:,:), w(:), v(:,:)\n real(rprec) :: wmax, wmin, wcuta, udotb, err\nC-----------------------------------------------\n \nc Solves Matrix equation A X = B for X using SVD method\nc Allows supression of weights, storage and recall of answers\nc Uses svd routines from numerical recipes\nc Prashant Valanju (Sept 1998) pvalanju@mail.utexas.edu\n \nc Almost same as SvdSolveB except this one stores U, w, V\nc rather than basis vectots.\nc Use this one when you want to change both B and weights for fixed A\n \nc Inputs:\nc A(M,N) - Matrix with physical dimensions (Mp,Np)\nc B(N) - R.H.S. of A X = B\nc M - Number of rows of A to use\nc N - Number of columns of A to use\nc Mp,NP - Storage dimensions of A(Mp,Np)\nc Wcut - Cutoff parameter\nc If Wcut = 0, writes answers into \"file\", all weights are kept\nc If Wcut < 0, reads previous answers from \"file\",\nc and uses -Wcut for weights to keep\nc If 0 < Wcut < 1 : Cuts off weights with w(i)/wmax < wcut\nc Use this to cut off small weights, does calculation\nc If Wcut = integer > 1, keeps Wcut weights, does calculation\nc Use this to cut off fixed number of weights\nc Output:\nc X(N) - Solution of A X = B\nc\n n1 = n\n \nc allocate local arrays\n allocate (u(mp,np), w(np), v(np,np), stat=istat)\n if (istat .eq. 0) then !have enough memory\n iunit = 41\n \n x(:n1) = zero !zero answer from previous call\n wcuta = abs(wcut)\nc...............................\nc If Wcut < 0 use precalculated weights to get answer fast\nc use wcuta = abs(wcut) for everything\nc If any error happens while reading \"file\", do full svd calculation\n if (wcut .lt. 0) then !Read file from previous calculation\n call safe_open(iunit, istat, file, 'old', 'formatted')\n if (istat .ne. 0) goto 98\n read (iunit, *, err=98)\n read (iunit, *, err=98)\n read (iunit, *, err=98) m, n, nonzero\n do i = 1, n !Read exactly the same way they were written\n read (iunit, *, err=98) w(i) !read i-th weight\n do j = 1, n\n read (iunit, *, err=98) v(j,i)\n end do\n do j = 1, m\n read (iunit, *, err=98) u(j,i)\n end do\n end do\n close(unit=iunit)\n \n go to 99 !Use U, w, V matrices to calculate X\n endif !End of precalculated branch Wcut < 0\n 98 continue\nc.......................................\nc If Wcut .ge. 0, do full svd calculation\nc Initialize all to zero to wipe out effects of old call\n do j = 1, n\n w(j) = zero !Zero all weights\n u(:m,j) = a(:m,j) !Because U will be changed by svdcmp\n v(:m,j) = zero\n end do\n \n call svdcmp (u, m, n, mp, np, w, v) !Do SVD decomposition\n \nc Sort weights and matrices with DECREASING weights\nc Permute weight w(i) AND column vectors U(*,i), V(*,i) at the same time\n call sortsvd (m, n, mp, np, w, u, v)\n \nc Find the number of nonzero weights (already dcreasing ordered)\n do nonzero = n, 1, -1\nc !Found first nonzero weight, get out\n if (w(nonzero) .ne. 0) exit \n end do\n if (nonzero .le. 0) go to 999\n \nc............................................\nc Decide how many weights to keep\n 99 continue\n if (wcuta .gt. 1) then\n nlast = wcuta\n else !cutoff small weights\n wmax = w(1) !weights are already ordered\n nlast = 0\n do i = 1, nonzero\n if (w(i) .gt. wmax*wcuta) then\n nlast = nlast + 1 !accept this weight\n else\n go to 96\n endif\n end do\n endif\n \nc Find solution X and basis vectors (put into columns of V)\n 96 continue\n if (nlast.le.0 .or. nlast.gt.nonzero) nlast = nonzero\n do i = 1, nlast !Calc i-th coeff (U.b/w) for noNonzero w(i)\nc First calculate i-th coeff (U(i)*b/w(i)) in the sum in eq 14.3.17 (NR)\nc !Dot product of i-th column of U with B\nc !summed over all plasma points\n udotb = sum(u(:m,i)*b(:m))\nc !=(Ui.b/wi) in eq 14.3.17, saves many divisions\n udotb = udotb/w(i)\nc Now run down the i-th column of the vector V(j,i)\nc !j-th entry (row) of vectors in eq 14.3.17\nc !add it to the j-th entry of X\n x(:n) = x(:n) + udotb*v(:n,i)\nc !This did the svdbksb, faster than NR\n end do !and also calculated the basis vectors\n \nc............................................\nc Write all weights and U, V into SVD file (if Wcut=0)\n if (wcut .eq. 0) then\n call safe_open(iunit, istat, file, 'unknown', 'formatted')\n write (iunit, *) 'Max w = ', w(1), ', Min w = ', w(nonzero)\n write (iunit, *) 'Ratio = ', w(1)/w(nonzero)\n write (iunit, *) m, n, nonzero\n do i = 1, n\n write (iunit, *) w(i) !write i-th weight\n do j = 1, n\n write (iunit, *) v(j,i)\n end do\n do j = 1, m\n write (iunit, *) u(j,i)\n end do\n end do\n close(unit=iunit)\n endif\nc................................................\n endif\n 999 continue\n\n deallocate (u, w, v, stat=istat)\n\n! end subroutine svdsolveuv\n end\n\n\n subroutine svdinv(m, a, wcut, file)\n use kind_spec\n implicit none\nC-----------------------------------------------\nC D u m m y A r g u m e n t s\nC-----------------------------------------------\n integer m\n real(rprec) wcut\n character file*(*)\n real(rprec), dimension(m,m) :: a\nC-----------------------------------------------\nC L o c a l P a r a m e t e r s\nC-----------------------------------------------\n real(rprec) :: zero = 0\nC-----------------------------------------------\nC L o c a l V a r i a b l e s\nC-----------------------------------------------\n integer :: nonzero, nlast, istat, i, j, k, iunit\n real(rprec), allocatable :: u(:,:), w(:), v(:,:)\n real(rprec) :: wmax, wmin, wcuta, udotb, err\nC-----------------------------------------------\n \nc Inverts Square Matrix A using SVD method\nc Allows supression of weights, storage and recall of answers\nc Uses svd routines from numerical recipes\nc Prashant Valanju (Sept 1998) pvalanju@mail.utexas.edu\n \nc A(M,M) - Matrix on input, Inverse on output\nc M - Size of A\nc Wcut - Cutoff parameter\nc If Wcut = 0, writes answers into \"file\", all weights are kept\nc If Wcut < 0, reads previous answers from \"file\",\nc and uses -Wcut for weights to keep\nc If 0 < Wcut < 1 : Cuts off weights with w(i)/wmax < wcut\nc Use this to cut off small weights, does calculation\nc If Wcut = integer > 1, keeps Wcut weights, does calculation\nc Use this to cut off fixed number of weights\nc\nc Note: M is same as N, Mp, and Np in this routine\n \nc allocate local arrays\n allocate (u(m,m), w(m), v(m,m), stat=istat)\n if (istat .eq. 0) then !have enough memory\n\n iunit = 41\n wcuta = abs(wcut)\nc...............................\nc If Wcut < 0 use precalculated weights to get answer fast\nc use wcuta = abs(wcut) for everything\nc If any error happens while reading \"file\", do full svd calculation\n if (wcut .lt. 0) then !Read file from previous calculation\n call safe_open(iunit, istat, file, 'old', 'formatted')\n if (istat .ne. 0) goto 98\n read (iunit, *, err=98)\n read (iunit, *, err=98)\n read (iunit, *, err=98) m, nonzero\nc !Read exactly the same way they were written\n do i = 1, nonzero\n read (iunit, *, err=98) w(i) !read i-th weight\n do j = 1, m\n read (iunit, *, err=98) v(j,i), u(j,i)\n end do\n end do\n close(unit=iunit)\n \nc Decide how many weights to keep\n nlast = wcuta !remember Wcut is < 0\n nlast = min(nonzero,nlast) !Do not use nonzero weights\n \n go to 99 !bypass svdcmp and go to matrix inversion\n endif !End of precalculated U,w,V branch Wcut < 0\n 98 continue\nc.......................................\nc If Wcut .ge. 0, do full svd calculation and save V,w,U\nc Initialize all to zero to wipe out effects of old call\n do j = 1, m\n w(j) = zero !Zero all weights\n u(:m,j) = a(:m,j) !Because U will be changed by svdcmp\n v(:m,j) = zero\n end do\n \n call svdcmp (u, m, m, m, m, w, v) !Do SVD decomposition\n \nc Sort weights and matrices with DECREASING weights\nc Permute weight w(i) AND column vectors U(*,i), V(*,i) at the same time\n call sortsvd (m, m, m, m, w, u, v)\n \nc Find the number of nonzero weights (already dcreasing ordered)\n do nonzero = m, 1, -1\nc !Found first nonzero weight, get out\n if (w(nonzero) .ne. 0) exit \n end do\n if (nonzero .le. 0) go to 999\n \nc Write all weights and U, V into SVD file (if Wcut=0)\n if (wcut .eq. 0) then !no nonzero weights, you must be kidding\n call safe_open(iunit, istat, file, 'unknown', 'formatted')\n write (iunit, *) 'Max w = ', w(1), ', Min w = ', w(nonzero)\n write (iunit, *) 'Ratio = ', w(1)/w(nonzero)\n write (iunit, *) m, nonzero\nc !write exactly the same way they were written\n do i = 1, nonzero\n write (iunit, *) w(i) !write i-th weight\n do j = 1, m\n write (iunit, *) v(j,i), u(j,i)\n end do\n end do\n close(unit=iunit)\n endif\nc.......................................\n \nc Following gets done in both cases (using saved or recalculating)\nc Decide how many weights to keep\n 99 continue\n if (wcuta .gt. 1) then\n nlast = wcuta\n else !cutoff small weights\n wmax = w(1) !weights are already ordered\n nlast = 0\n do i = 1, nonzero\n if (w(i) .gt. wmax*wcuta) then\n nlast = nlast + 1 !accept this weight\n else\n go to 96\n endif\n end do\n endif\n \nc Find Inverse of A = V [diag(1/wi)] Utranspose, return in A\nc First do [diag(1/wi)] Utranspose, store answer in U again\n 96 continue\n if (nlast.le.0 .or. nlast.gt.nonzero) nlast = nonzero\n do i = 1, nlast\nc !divide ith row of Utr by w(i)\n u(:m,i) = u(:m,i)/w(i)\n end do\nc Zero the infinite 1/weights\n do i = nlast + 1, m\n u(:m,i) = zero !multiply ith row of Utr by zero\n end do\nc Next multiply by V matrix to get A inverse, put it in A\n do i = 1, m !multiplt ith row vector of V by\n do j = 1, m !jth column vector of wU\n !vector multiply V and wU\n a(i,j) = sum(v(i,:m)*u(j,:m)) !Put inverse back in A\n end do\n end do\nc................................................\n endif\n 999 continue\n\n deallocate (u, w, v, stat=istat)\n\n! end subroutine svdinv\n end\n \n\n SUBROUTINE SVDCMP(A, M, N, MP, NP, W, V)\n use kind_spec\n IMPLICIT NONE\nC-----------------------------------------------\nC D u m m y A r g u m e n t s\nC-----------------------------------------------\n INTEGER M, N, MP, NP\n REAL(rprec), DIMENSION(MP,NP) :: A\n REAL(rprec), DIMENSION(NP) :: W\n REAL(rprec), DIMENSION(NP,NP) :: V\nC-----------------------------------------------\nC L o c a l P a r a m e t e r s\nC-----------------------------------------------\n real(rprec) :: zero = 0, one = 1, two = 2\nC-----------------------------------------------\nC L o c a l V a r i a b l e s\nC-----------------------------------------------\n INTEGER :: I, L, K, J, ITS, NM\n REAL(rprec), DIMENSION(MP*NP) :: RV1\n REAL(rprec) :: G, SCALE, ANORM, S, F, H, C, Y, Z, X\nC-----------------------------------------------\nC E x t e r n a l F u n c t i o n s\nC-----------------------------------------------\n REAL(rprec) , EXTERNAL :: PYTHAG\nC-----------------------------------------------\n IF (M .GT. MP) STOP 'M > MP IN SVDCMP'\n IF (N .GT. NP) STOP 'N > NP IN SVDCMP'\n\n G = zero\n SCALE = zero\n ANORM = zero\n DO I = 1, N\n L = I + 1\n RV1(I) = SCALE*G\n G = zero\n S = zero\n SCALE = zero\n IF (I .le. M) THEN\n SCALE = SUM(ABS(A(I:M,I)))\n IF (SCALE .ne. zero) THEN\n A(I:M,I) = A(I:M,I)/SCALE\n S = SUM(A(I:M,I)*A(I:M,I))\n F = A(I,I)\n G = -SIGN(SQRT(S),F)\n H = F*G - S\n A(I,I) = F - G\n IF (I .ne. N) THEN\n DO J = L, N\n S = SUM(A(I:M,I)*A(I:M,J))\n F = S/H\n A(I:M,J) = A(I:M,J) + F*A(I:M,I)\n END DO\n ENDIF\n A(I:M,I) = SCALE*A(I:M,I)\n ENDIF\n ENDIF\n W(I) = SCALE*G\n G = zero\n S = zero\n SCALE = zero\n IF (I.le.M .AND. I.ne.N) THEN\n SCALE = SUM(ABS(A(I,L:N)))\n IF (SCALE .ne. zero) THEN\n A(I,L:N) = A(I,L:N)/SCALE\n S = SUM(A(I,L:N)*A(I,L:N))\n F = A(I,L)\n G = -SIGN(SQRT(S),F)\n H = F*G - S\n A(I,L) = F - G\n RV1(L:N) = A(I,L:N)/H\n IF (I .ne. M) THEN\n DO J = L, M\n S = SUM(A(J,L:N)*A(I,L:N))\n A(J,L:N) = A(J,L:N) + S*RV1(L:N)\n END DO\n ENDIF\n A(I,L:N) = SCALE*A(I,L:N)\n ENDIF\n ENDIF\n ANORM = MAX(ANORM,ABS(W(I))+ABS(RV1(I)))\n END DO\n DO I = N, 1, -1\n IF (I .lt. N) THEN\n IF (G .ne. zero) THEN\n V(L:N,I) = (A(I,L:N)/A(I,L))/G\n DO J = L, N\n S = SUM(A(I,L:N)*V(L:N,J))\n V(L:N,J) = V(L:N,J) + S*V(L:N,I)\n END DO\n ENDIF\n V(I,L:N) = zero\n V(L:N,I) = zero\n ENDIF\n V(I,I) = one\n G = RV1(I)\n L = I\n END DO\n DO I = N, 1, -1\n L = I + 1\n G = W(I)\n IF (I .lt. N) THEN\n A(I,L:N) = zero\n ENDIF\n IF (G .ne. zero) THEN\n G = one/G\n IF (I .ne. N) THEN\n DO J = L, N\n S = SUM(A(L:M,I)*A(L:M,J))\n F = (S/A(I,I))*G\n A(I:M,J) = A(I:M,J) + F*A(I:M,I)\n END DO\n ENDIF\n A(I:M,I) = A(I:M,I)*G\n ELSE\n A(I:M,I) = zero\n ENDIF\n A(I,I) = A(I,I) + one\n END DO\n L49: DO K = N, 1, -1\n DO ITS = 1, 50\n DO L = K, 1, -1\n NM = L - 1\n IF (ABS(RV1(L)) + ANORM .eq. ANORM) GO TO 2\n IF (ABS(W(NM)) + ANORM .eq. ANORM) EXIT \n END DO\n C = zero\n S = one\n DO I = L, K\n F = S*RV1(I)\n IF (ABS(F) + ANORM .ne. ANORM) THEN\n G = W(I)\n H = PYTHAG(F,G)\nc H=SQRT(F*F+G*G)\n W(I) = H\n H = one/H\n C = G*H\n S = -F*H\n DO J = 1, M\n Y = A(J,NM)\n Z = A(J,I)\n A(J,NM) = Y*C + Z*S\n A(J,I) = (-Y*S) + Z*C\n END DO\n ENDIF\n END DO\n 2 CONTINUE\n Z = W(K)\n IF (L .eq. K) THEN\n IF (Z .lt. zero) THEN\n W(K) = -Z\n V(:N,K) = -V(:N,K)\n ENDIF\n CYCLE L49\n ENDIF\n IF (ITS .eq. 50) THEN\n WRITE (*, '(2A)') 'PAUSE ', \n 1 'No convergence in 150 iterations'\n READ *\n ENDIF\n X = W(L)\n NM = K - 1\n Y = W(NM)\n G = RV1(NM)\n H = RV1(K)\n F = ((Y - Z)*(Y + Z) + (G - H)*(G + H))/(TWO*H*Y)\n G = PYTHAG(F,one)\nc G=SQRT(F*F + one)\n F = ((X - Z)*(X + Z) + H*(Y/(F + SIGN(G,F)) - H))/X\n C = one\n S = one\n DO J = L, NM\n I = J + 1\n G = RV1(I)\n Y = W(I)\n H = S*G\n G = C*G\n Z = PYTHAG(F,H)\nc Z=SQRT(F*F+H*H)\n RV1(J) = Z\n C = F/Z\n S = H/Z\n F = X*C + G*S\n G = (-X*S) + G*C\n H = Y*S\n Y = Y*C\n DO NM = 1, N\n X = V(NM,J)\n Z = V(NM,I)\n V(NM,J) = X*C + Z*S\n V(NM,I) = (-X*S) + Z*C\n END DO\n Z = PYTHAG(F,H)\nc Z=SQRT(F*F+H*H)\n W(J) = Z\n IF (Z .ne. zero) THEN\n Z = one/Z\n C = F*Z\n S = H*Z\n ENDIF\n F = C*G + S*Y\n X = (-S*G) + C*Y\n DO NM = 1, M\n Y = A(NM,J)\n Z = A(NM,I)\n A(NM,J) = Y*C + Z*S\n A(NM,I) = (-Y*S) + Z*C\n END DO\n END DO\n RV1(L) = zero\n RV1(K) = F\n W(K) = X\n END DO\n END DO L49\n\n! END SUBROUTINE SVDCMP\n END\n\n\n SUBROUTINE SVBKSB(U, W, V, M, N, MP, NP, B, X)\n use kind_spec\n IMPLICIT NONE\nC-----------------------------------------------\nC D u m m y A r g u m e n t s\nC-----------------------------------------------\n INTEGER M, N, MP, NP\n REAL(rprec), DIMENSION(MP,NP) :: U\n REAL(rprec), DIMENSION(NP) :: W\n REAL(rprec), DIMENSION(NP,NP) :: V\n REAL(rprec), DIMENSION(MP) :: B\n REAL(rprec), DIMENSION(NP) :: X\nC-----------------------------------------------\nC L o c a l P a r a m e t e r s\nC-----------------------------------------------\n real(rprec) :: zero = 0\nC-----------------------------------------------\nC L o c a l V a r i a b l e s\nC-----------------------------------------------\n INTEGER :: J, I, JJ\n REAL(rprec), DIMENSION(MP*NP) :: TMP\n REAL(rprec) :: S\nC-----------------------------------------------\n IF (M .GT. MP) STOP 'M > MP IN SVBKSB'\n IF (N .GT. NP) STOP 'N > NP IN SVBKSB'\n\n DO J = 1, N\n S = zero\n IF (W(J) .ne. zero) THEN\n S = SUM(U(:M,J)*B(:M))\n S = S/W(J)\n ENDIF\n TMP(J) = S\n END DO\n DO J = 1, N\n S = SUM(V(J,:N)*TMP(:N))\n X(J) = S\n END DO\n\n! END SUBROUTINE SVBKSB\n END\n\n SUBROUTINE SORTSVD(M, N, MP, NP, W, U, V)\nc------------------------------\nc Sorts the weights and U, V matrices from SVD decomposition\nc Sorts weights in DECREASING order\nc Based on routine SORT2 from Numerical Recipes, pg 231\nc Created by Prashant Valanju, (Sept 1998)\nc------------------------------\n use kind_spec\n IMPLICIT NONE\nC-----------------------------------------------\nC D u m m y A r g u m e n t s\nC-----------------------------------------------\n INTEGER M, N, MP, NP\n REAL(rprec), DIMENSION(NP) :: W\n REAL(rprec), DIMENSION(MP,NP) :: U\n REAL(rprec), DIMENSION(NP,NP) :: V\nC-----------------------------------------------\nC L o c a l V a r i a b l e s\nC-----------------------------------------------\n INTEGER :: L, IR, II, I, J\n REAL(rprec), DIMENSION(MP) :: RU\n REAL(rprec), DIMENSION(NP) :: RV\n REAL(rprec) :: RW\nC-----------------------------------------------\n IF (M .GT. MP) STOP 'M > MP IN SORTSVD'\n IF (N .GT. NP) STOP 'N > NP IN SORTSVD'\n\n L = N/2 + 1\n IR = N\n 10 CONTINUE\n IF (L .gt. 1) THEN\n L = L - 1\n RW = W(L)\n RU(:M) = U(:M,L)\n RV(:N) = V(:N,L)\n ELSE\n RW = W(IR)\n RU(:M) = U(:M,IR)\n RV(:N) = V(:N,IR)\n W(IR) = W(1)\n U(:M,IR) = U(:M,1)\n V(:N,IR) = V(:N,1)\n IR = IR - 1\n IF (IR .eq. 1) THEN\n W(1) = RW\n U(:M,1) = RU(:M)\n V(:N,1) = RV(:N)\n RETURN \n ENDIF\n ENDIF\n I = L\n J = L + L\n 20 CONTINUE\n IF (J .le. IR) THEN\n IF (J .lt. IR) THEN\nC !Just change these 2 for increasing\n IF (W(J) .gt. W(J+1)) J = J + 1\n ENDIF\n IF (RW .gt. W(J)) THEN !Just change these 2 for increasing\n W(I) = W(J)\n U(:M,I) = U(:M,J)\n V(:N,I) = V(:N,J)\n I = J\n J = J + J\n ELSE\n J = IR + 1\n ENDIF\n GO TO 20\n ENDIF\n W(I) = RW\n U(:M,I) = RU(:M)\n V(:N,I) = RV(:N)\n GO TO 10\n\n! END SUBROUTINE SORTSVD\n END\n\n\n function pythag (a, b)\n use kind_spec\n implicit none\nC-----------------------------------------------\nC D u m m y A r g u m e n t s\nC-----------------------------------------------\n real(rprec) a, b\nC-----------------------------------------------\nC L o c a l P a r a m e t e r s\nC-----------------------------------------------\n real(rprec) :: zero = 0, one = 1\nC-----------------------------------------------\nC L o c a l V a r i a b l e s\nC-----------------------------------------------\n real(rprec) :: absa, absb, pythag\nC-----------------------------------------------\nc computes sqrt(a^2+b^2) without destructive underflow or overflow\n absa = abs(a)\n absb = abs(b)\n if (absa .gt. absb) then\n pythag = absa*sqrt(one + (absb/absa)**2)\n else\n if (absb .eq. zero) then\n pythag = zero\n else\n pythag = absb*sqrt(one + (absa/absb)**2)\n endif\n endif\n\n! end function pythag\n end\n", "meta": {"hexsha": "1efd5a3e18e8e9011645f6e163c85c35a6832bfe", "size": 36233, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/svdpack/svdpack.f", "max_stars_repo_name": "jonathanschilling/VMEC_6_90", "max_stars_repo_head_hexsha": "5a63cc2b475038560d8e81de1ddae477d6f8ddec", "max_stars_repo_licenses": ["MIT"], "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/svdpack/svdpack.f", "max_issues_repo_name": "jonathanschilling/VMEC_6_90", "max_issues_repo_head_hexsha": "5a63cc2b475038560d8e81de1ddae477d6f8ddec", "max_issues_repo_licenses": ["MIT"], "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/svdpack/svdpack.f", "max_forks_repo_name": "jonathanschilling/VMEC_6_90", "max_forks_repo_head_hexsha": "5a63cc2b475038560d8e81de1ddae477d6f8ddec", "max_forks_repo_licenses": ["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.0102145046, "max_line_length": 88, "alphanum_fraction": 0.4178787293, "num_tokens": 10109, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765163620469, "lm_q2_score": 0.7490872075132152, "lm_q1q2_score": 0.6844233902120482}} {"text": " FUNCTION bessy0(x)\r\n REAL bessy0,x\r\nCU USES bessj0\r\n REAL xx,z,bessj0\r\n DOUBLE PRECISION p1,p2,p3,p4,p5,q1,q2,q3,q4,q5,r1,r2,r3,r4,r5,r6,\r\n *s1,s2,s3,s4,s5,s6,y\r\n SAVE p1,p2,p3,p4,p5,q1,q2,q3,q4,q5,r1,r2,r3,r4,r5,r6,s1,s2,s3,s4,\r\n *s5,s6\r\n DATA p1,p2,p3,p4,p5/1.d0,-.1098628627d-2,.2734510407d-4,\r\n *-.2073370639d-5,.2093887211d-6/, q1,q2,q3,q4,q5/-.1562499995d-1,\r\n *.1430488765d-3,-.6911147651d-5,.7621095161d-6,-.934945152d-7/\r\n DATA r1,r2,r3,r4,r5,r6/-2957821389.d0,7062834065.d0,\r\n *-512359803.6d0,10879881.29d0,-86327.92757d0,228.4622733d0/,s1,s2,\r\n *s3,s4,s5,s6/40076544269.d0,745249964.8d0,7189466.438d0,\r\n *47447.26470d0,226.1030244d0,1.d0/\r\n if(x.lt.8.)then\r\n y=x**2\r\n bessy0=(r1+y*(r2+y*(r3+y*(r4+y*(r5+y*r6)))))/(s1+y*(s2+y*(s3+y*\r\n *(s4+y*(s5+y*s6)))))+.636619772*bessj0(x)*log(x)\r\n else\r\n z=8./x\r\n y=z**2\r\n xx=x-.785398164\r\n bessy0=sqrt(.636619772/x)*(sin(xx)*(p1+y*(p2+y*(p3+y*(p4+y*\r\n *p5))))+z*cos(xx)*(q1+y*(q2+y*(q3+y*(q4+y*q5)))))\r\n endif\r\n return\r\n END\r\n", "meta": {"hexsha": "21c07f4ebbb7ac040b2138f618052f1cd37ec148", "size": 1117, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/bessy0.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/bessy0.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/bessy0.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": 38.5172413793, "max_line_length": 72, "alphanum_fraction": 0.5595344673, "num_tokens": 546, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765163620469, "lm_q2_score": 0.749087201911703, "lm_q1q2_score": 0.6844233850940781}} {"text": " ! NOTE: This MODULE is virtually a copy of MODULE FFT_Module() from TurbSim.\n ! A few unused things have been eliminated (indicated by \"!remove\")\n ! and a little bit of code has been added where noted (indicated by\n ! \"NEW\").\n ! BJJ: 02/22/2008: Updated to work with NWTC_Library v1.01.09\n ! all Abort() functions changed to ProgAbort()\n!=======================================================================\nMODULE FFT_Module\n!-----------------------------------------------------------------------\n! DESCRIPTION OF THE INVERSE FOURIER TRANSFORM ROUTINE:\n!\n! Given an array, H, of N complex numbers, calculate an array, h, of N real\n! numbers:\n! h(J) = the sum from K=1,...,N of [ H(K)*exp(i*(J-1)*(K-1)*2*pi/N) ]\n! for J = 1,...,N\n!\n! where:\n! i=sqrt(-1)\n!\n! In order for h to be real, the real components of H must be an even function\n! of frequency and the imaginary components of H must be an odd function of\n! frequency. Thus, only the first N/2 + 1 values of H are unique. (The first\n! N/2 + 1 are the positive frequencies including zero; the last N/2 - 1 values\n! are the negative frequencies.)\n!\n! We accomplish this by defining a real array, R, where:\n! R(1) = REAL( H(1) ),\n! R(2) = REAL( H(2) ), R(3) = IMAG( H(2) ),\n! R(4) = REAL( H(3) ), R(5) = IMAG( H(3) ),...\n! R(N) = REAL( H(N/2 + 1) ).\n! Note that the values of IMAG( H(1) ) and IMAG( H(N/2 + 1) ) must be zero for\n! the result to be real, else the routine will abort.\n!\n! We return the array, r = h, of real numbers as calculated by:\n! h(J) = r(J) = R(1) + (-1)**(J-1)*R(N)\n! + the sum from K=2,...,N/2 of\n! [ 2*R(2*K-2)*COS((K-1)*(J-1)*2*PI/N)\n! -2*R(2*K-1)*SIN((K-1)*(J-1)*2*PI/N) ]\n! for J = 1,...,N, where N is an even number\n!\n! The routine is most effecient when N is a product of small primes.\n!\n! If the Normalization flag is set to \"TRUE\" in the initialization, we\n! normalize the result by 1/N.\n!------------------------------------------------------------------------\n! DESCRIPTION OF THE COSINE TRANSFORM ROUTINE:\n!\n! Given an array, X, of N real numbers, calculate an array, x, of N real\n! numbers:\n! x(J) = X(1) + (-1)**(J-1)*X(N)\n! + the sum from K=2,...,N-1 of [ 2*X(K)*COS((K-1)*(J-1)*PI/(N-1)) ]\n! for J = 1,...,N, where N is an odd number\n!\n! The routine is most effecient when N-1 is a product of small primes.\n!\n! If the Normalization flag is set to \"TRUE\" in the initialization, we\n! normalize the result by 1/(N-1).\n!------------------------------------------------------------------------\n! DESCRIPTION OF THE SINE TRANSFORM ROUTINE:\n!\n! Given an array, X, of N real numbers, calculate an array, x, of N real\n! numbers:\n! x(1) = X(1) = 0\n! x(J) = the sum from K=2,...,N-1 of [ 2*X(K)*SIN((K-1)*(J-1)*PI/(N-1)) ]\n! for J = 2,...,N-1, where N is an odd number\n! x(N) = X(N) = 0\n!\n! Note that the values of X(1) and X(N) must be zero, else the routine will\n! abort.\n!\n! The routine is most effecient when N-1 is a product of small primes.\n!\n! If the Normalization flag is set to \"TRUE\" in the initialization, we\n! normalize the result by 1/(N-1).\n!------------------------------------------------------------------------\n\n!remove ! This module is NEW:\n!remove USE Precision\n! We need the Precision module and the Abort() and\n! Int2LStr() functions from the NWTC_IO module.\n\n USE NWTC_Library\n\n\nIMPLICIT NONE\n\nREAL(ReKi), PRIVATE, SAVE :: InvN ! Normization constant\nREAL(ReKi), ALLOCATABLE, PRIVATE, SAVE :: wSave(:) ! Working array for performing transforms\n\nINTEGER, PRIVATE, SAVE :: N ! Number of steps\n\nLOGICAL, PRIVATE, SAVE :: Normalize ! Whether or not to normalize\n\n!------------------------------------------------------------------------\nCONTAINS\n\n SUBROUTINE ApplyCOST( TRH )\n ! Perform cosine transform.\n\n IMPLICIT NONE\n\n REAL(ReKi), INTENT(INOUT) :: TRH(:)\n\n\n\n ! Make sure the array isn't too small\n\n IF ( SIZE(TRH) < N ) &\n CALL ProgAbort( 'Error in call to cosine transform. Array size is not large enough.' )\n\n ! Perform the cosine transform with a FFTpack routine\n\n CALL COST(N, TRH, wSave) ! FFTpack routine\n\n IF (Normalize) THEN\n TRH(1:N) = InvN * TRH(1:N)\n ENDIF\n\n END SUBROUTINE ApplyCOST\n !------------------------------------------------------------------------\n SUBROUTINE ApplyFFT( TRH )\n ! Perform Backward FFT: given TRH, a REAL array representing complex numbers,\n ! return an array TRH, of real numbers.\n ! CALL FOURTH ( TRH, NumSteps, 1, WorkT, NumSteps+2 ) ! Sandia\n\n IMPLICIT NONE\n\n REAL(ReKi), INTENT(INOUT) :: TRH(:)\n\n\n\n ! Make sure the array isn't too small\n\n IF ( SIZE(TRH) < N ) &\n CALL ProgAbort( 'Error in call to FFT. Array size is not large enough.' )\n\n ! Perform the FFT with a FFTpack routine\n\n CALL RFFTB(N, TRH, wSave) ! FFTpack routine\n\n IF (Normalize) THEN\n TRH(1:N) = InvN * TRH(1:N)\n ENDIF\n\n END SUBROUTINE ApplyFFT\n !------------------------------------------------------------------------\n SUBROUTINE ApplyFFT_cx( TRH, TRH_complex )\n ! Perform Backward FFT: given TRH, a REAL array representing complex numbers,\n ! return an array TRH, of real numbers.\n\n IMPLICIT NONE\n\n REAL(ReKi), INTENT(OUT) :: TRH(:)\n COMPLEX(ReKi), INTENT(IN) :: TRH_complex(:)\n\n INTEGER :: I\n INTEGER :: Indx\n\n\n ! Make sure the arrays aren't too small\n\n IF ( ( SIZE(TRH) < N ) .OR. ( SIZE(TRH_complex) < ( N/2 + 1 ) ) ) &\n CALL ProgAbort( 'Error in call to FFT. Array size is not large enough.' )\n\n ! Make sure that the imaginary components at the zeroeth and largest\n ! positive frequency are zero, else abort.\n\n IF ( AIMAG( TRH_complex(1 ) ) /= 0.0 ) &\n CALL ProgAbort( 'Error in call to FFT. The imaginary component at the zeroeth frequency must be zero.' )\n IF ( AIMAG( TRH_complex(N/2+1) ) /= 0.0 ) &\n CALL ProgAbort( 'Error in call to FFT. The imaginary component at the largest positive frequency must be zero.' )\n\n ! Initialize the TRH array with Complex numbers\n\n TRH(1) = REAL( TRH_complex(1 ) )\n\n Indx = 1\n DO I=2,N-2, 2\n Indx = Indx + 1 ! I/2 + 1\n\n TRH(I) = REAL( TRH_complex(Indx) )\n TRH(I+1) = AIMAG( TRH_complex(Indx) )\n ENDDO\n\n TRH(N) = REAL( TRH_complex(N/2+1) )\n\n\n ! Perform the FFT with a FFTpack routine\n\n CALL RFFTB(N, TRH, wSave)\n\n IF (Normalize) THEN\n TRH(1:N) = InvN * TRH(1:N)\n ENDIF\n\n\n END SUBROUTINE ApplyFFT_cx\n !------------------------------------------------------------------------\n SUBROUTINE ApplySINT( TRH )\n ! Perform sine transform.\n\n IMPLICIT NONE\n\n REAL(ReKi), INTENT(INOUT) :: TRH(:)\n\n\n\n ! Make sure the array isn't too small\n\n IF ( SIZE(TRH) < N ) &\n CALL ProgAbort( 'Error in call to sine transform. Array size is not large enough.' )\n\n ! Make sure that the value at the zeroeth and largest positive\n ! frequency are zero, else abort.\n\n IF ( TRH(1) /= 0.0 ) &\n CALL ProgAbort( 'Error in call to FFT. The value at the zeroeth frequency must be zero.' )\n IF ( TRH(N) /= 0.0 ) &\n CALL ProgAbort( 'Error in call to FFT. The value at the largest positive frequency must be zero.' )\n\n ! Perform the sine transform with a FFTpack routine\n\n CALL SINT(N-2, TRH(2:N-1), wSave) ! FFTpack routine\n\n IF (Normalize) THEN\n TRH(1:N) = InvN * TRH(1:N)\n ENDIF\n\n END SUBROUTINE ApplySINT\n !------------------------------------------------------------------------\n SUBROUTINE ExitCOST\n\n ! This subroutine cleans up the cosine transform working space\n\n IF ( ALLOCATED (wSave) ) DEALLOCATE( wSave )\n\n END SUBROUTINE ExitCOST\n !------------------------------------------------------------------------\n SUBROUTINE ExitFFT\n\n ! This subroutine cleans up the backward FFT working space\n\n IF ( ALLOCATED (wSave) ) DEALLOCATE( wSave )\n\n END SUBROUTINE ExitFFT\n !------------------------------------------------------------------------\n SUBROUTINE ExitSINT\n\n ! This subroutine cleans up the sine transform working space\n\n IF ( ALLOCATED (wSave) ) DEALLOCATE( wSave )\n\n END SUBROUTINE ExitSINT\n !------------------------------------------------------------------------\n SUBROUTINE InitCOST( NumSteps, NormalizeIn )\n\n ! This subroutine initializes the cosine transform working space\n\n IMPLICIT NONE\n\n INTEGER, INTENT(IN) :: NumSteps ! Number of steps in the array\n INTEGER :: Sttus ! Array allocation status\n\n LOGICAL, INTENT(IN), OPTIONAL :: NormalizeIn ! Whether or not to normalize\n\n\n\n ! Number of timesteps in the time series returned from the cosine transform\n ! N should be odd:\n\n N = NumSteps\n\n IF ( MOD(N,2) /= 1 ) THEN\n CALL ProgAbort ( 'The number of steps in the cosine transform must be odd' )\n ENDIF\n\n ! Determine if we should normalize the cosine transform:\n\n IF ( PRESENT( NormalizeIn ) ) THEN\n Normalize = NormalizeIn\n InvN = 1. / ( N - 1 )\n ELSE\n Normalize = .FALSE.\n ENDIF\n\n ! According to FFTPACK documentation, the working array must be at\n ! least size 3N+15\n\n ALLOCATE ( wSave(3*N + 15) , STAT=Sttus )\n\n IF ( Sttus /= 0 ) THEN\n CALL ProgAbort ( 'Error allocating memory for the cosine transform working array.' )\n ENDIF\n\n\n ! Initialize the FFTPACK working space\n\n CALL COSTI(N, wSave)\n\n\n END SUBROUTINE InitCOST\n !------------------------------------------------------------------------\n SUBROUTINE InitFFT( NumSteps, NormalizeIn )\n\n ! This subroutine initializes the backward FFT working space\n\n IMPLICIT NONE\n\n INTEGER, INTENT(IN) :: NumSteps ! Number of steps in the array\n INTEGER :: Sttus ! Array allocation status\n\n LOGICAL, INTENT(IN), OPTIONAL :: NormalizeIn ! Whether or not to normalize the FFT\n\n\n\n ! Number of timesteps in the time series returned from the backward FFT\n ! N should be even:\n\n N = NumSteps\n\n IF ( MOD(N,2) /= 0 ) THEN\n CALL ProgAbort ( 'The number of steps in the FFT must be even' ) ! For this Real FFT\n ENDIF\n\n ! Determine if we should normalize the FFT\n\n IF ( PRESENT( NormalizeIn ) ) THEN\n Normalize = NormalizeIn\n InvN = 1. / N\n ELSE\n Normalize = .FALSE.\n ENDIF\n\n ! According to FFTPACK documentation, the working array must be at\n ! least size 2N+15\n\n ALLOCATE ( wSave(2*N + 15) , STAT=Sttus )\n\n IF ( Sttus /= 0 ) THEN\n CALL ProgAbort ( 'Error allocating memory for the FFT working array.' )\n ENDIF\n\n\n ! Initialize the FFTPACK working space\n\n CALL RFFTI(N, wSave)\n\n\n END SUBROUTINE InitFFT\n !------------------------------------------------------------------------\n SUBROUTINE InitSINT( NumSteps, NormalizeIn )\n\n ! This subroutine initializes the sine transform working space\n\n IMPLICIT NONE\n\n INTEGER, INTENT(IN) :: NumSteps ! Number of steps in the array\n INTEGER :: Sttus ! Array allocation status\n\n LOGICAL, INTENT(IN), OPTIONAL :: NormalizeIn ! Whether or not to normalize\n\n\n\n ! Number of timesteps in the time series returned from the sine transform\n ! N should be odd:\n\n N = NumSteps\n\n IF ( MOD(N,2) /= 1 ) THEN\n CALL ProgAbort ( 'The number of steps in the sine transform must be odd' )\n ENDIF\n\n ! Determine if we should normalize the sine transform:\n\n IF ( PRESENT( NormalizeIn ) ) THEN\n Normalize = NormalizeIn\n InvN = 1. / ( N - 1 )\n ELSE\n Normalize = .FALSE.\n ENDIF\n\n ! According to FFTPACK documentation, the working array must be at\n ! least size 2.5N+15; however, our N is +2 greater than their N\n\n ALLOCATE ( wSave( CEILING( 2.5*(N-2) ) + 15 ) , STAT=Sttus )\n\n IF ( Sttus /= 0 ) THEN\n CALL ProgAbort ( 'Error allocating memory for the sine transform working array.' )\n ENDIF\n\n\n ! Initialize the FFTPACK working space\n\n CALL SINTI(N-2, wSave)\n\n\n END SUBROUTINE InitSINT\n !------------------------------------------------------------------------\n FUNCTION PSF ( Npsf , NumPrimes )\n\n\n ! This routine factors the number N into its primes. If any of those\n ! prime factors is greater than the NumPrimes'th prime, a point is added to N\n ! and the new number is factored. This process is repeated until no\n ! prime factors are greater than the NumPrimes'th prime.\n\n IMPLICIT NONE\n\n !Passed variables\n INTEGER, INTENT(IN) :: Npsf ! Initial number we're trying to factor.\n INTEGER, INTENT(IN) :: NumPrimes ! Number of unique primes.\n INTEGER :: PSF ! The smallest number at least as large as Npsf, that is the product of small factors when we return.\n\n !Other variables\n INTEGER :: IPR ! A counter for the NPrime array\n INTEGER, PARAMETER :: NFact = 9 ! The number of prime numbers (the first NFact primes)\n INTEGER :: NP ! A temp variable to determine if NPr divides NTR\n INTEGER :: NPr ! A small prime number\n INTEGER :: NT ! A temp variable to determine if NPr divides NTR: INT( NTR / NPr )\n INTEGER :: NTR ! The number we're trying to factor in each iteration\n INTEGER, PARAMETER :: NPrime(NFact) = (/ 2, 3, 5, 7, 11, 13, 17, 19, 23 /) ! The first 9 prime numbers\n\n LOGICAL :: DividesN1(NFact) ! Does this factor divide NTR-1?\n\n!remove ! This variable is NEW:\n!remove CHARACTER(11), EXTERNAL :: Int2LStr ! A function to convert an interger to a left-justified string.\n\n IF ( NumPrimes > NFact ) THEN\n CALL ProgAbort ( 'In the call to PSF, NumPrimes must be less than '//TRIM( Int2LStr( NFact ) )//'.' )\n ENDIF\n\n DividesN1(:) = .FALSE. ! We need to check all of the primes the first time through\n\n PSF = Npsf\n\n DO\n ! 1.0 Factor NTR into its primes.\n\n NTR = PSF\n\n DO IPR=1,NumPrimes\n\n IF ( DividesN1(IPR) ) THEN\n\n ! If P divides N-1, then P cannot divide N.\n\n DividesN1(IPR) = .FALSE. ! We'll check it next time.\n\n ELSE\n\n NPr = NPrime(IPR) ! The small prime number we will try to find the the factorization of NTR\n\n DO\n NT = NTR/NPr ! Doing some modular arithmetic to see if\n NP = NT*NPr ! MOD( NTR, NPr ) == 0, i.e. if NPr divides NTR\n\n IF ( NP /= NTR ) EXIT ! There aren't any more of this prime number in the factorization\n\n NTR = NT ! This is the new number we need to get factors for\n DividesN1(IPR) = .TRUE. ! This prime number divides Npsf, so we won't check it next time (on Npsf+1).\n\n ENDDO\n\n IF ( NTR .EQ. 1 ) RETURN ! We've found all the prime factors, so we're finished\n\n ENDIF ! DividesN1\n\n ENDDO ! IPR\n\n ! 2.0 There is at least one prime larger than NPrime(NumPrimes). Add\n ! a point to NTR and factor again.\n\n PSF = PSF + 1\n\n ENDDO\n\n\n RETURN\n END FUNCTION PSF\n\n\nEND MODULE FFT_Module\n!=======================================================================\n", "meta": {"hexsha": "365004c4463fafdc02e019c9f8dc8c82c97dbb27", "size": 16475, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "SourceCode/HydroDyn/FFTMod.f90", "max_stars_repo_name": "RuiliangWang/F2A", "max_stars_repo_head_hexsha": "829afd159198bdea9c0adcdeff5290908fc60e55", "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": "SourceCode/HydroDyn/FFTMod.f90", "max_issues_repo_name": "RuiliangWang/F2A", "max_issues_repo_head_hexsha": "829afd159198bdea9c0adcdeff5290908fc60e55", "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": "SourceCode/HydroDyn/FFTMod.f90", "max_forks_repo_name": "RuiliangWang/F2A", "max_forks_repo_head_hexsha": "829afd159198bdea9c0adcdeff5290908fc60e55", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-05T07:53:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-05T07:53:19.000Z", "avg_line_length": 34.0392561983, "max_line_length": 153, "alphanum_fraction": 0.5271623672, "num_tokens": 4270, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087946129328, "lm_q2_score": 0.737158174177441, "lm_q1q2_score": 0.6843841319271484}} {"text": "! *******************************************************************\r\n! * *\r\n! * Real*8 Function dlsmp1 *\r\n! * *\r\n! *******************************************************************\r\n! Double Precision Version 1.31\r\n! Written by Gordon A. Fenton, May 13, 1996\r\n! Latest Update: May 9, 2001\r\n!\r\n! PURPOSE returns the covariance between two points along a 1-D simple\r\n! variance function process \r\n!\r\n! This routine returns the covariance between two points, separated by\r\n! the distance T, along a process having the simple covariance function\r\n!\r\n! var*dthx^3\r\n!\t B(T) = --------------\r\n! (dthx + |T|)^3\r\n!\r\n! where var is the point variance, and dthx is the scale of fluctuation\r\n! of the process. Both parameters, var and dthx, are brought into this\r\n! function via the common block /dparam/.\r\n!\r\n! If var < 0, then this function returns the variance of a local average\r\n! of the process, |var|*V(T), averaged over the distance T.\r\n! The random process considered has a particularly simple variance\r\n! function,\r\n!\r\n! dthx\r\n!\t V(T) = ----------\r\n! dthx + |T|\r\n!\r\n! where `dthx' is the scale of fluctuation of the process. This function\r\n! returns var*V(T), where `var' is the point variance of the process.\r\n! For more details, see page 204 of E.H. Vanmarcke's ``Random Fields:\r\n! Analysis and Synthesis.''\r\n!\r\n! REVISION HISTORY:\r\n! 1.1\tadded lvarfn flag to end of /dparam/ common block. Set it to\r\n!\ttrue if the variance function is to be returned. Otherwise this\r\n!\tfunction returns the covariance. (May 1/00)\r\n! 1.2\teliminated lvarfn -- now return covariances only if var < 0 (Mar 2/01)\r\n! 1.3\treversed default - now return covariances if var > 0. (Apr 11/01)\r\n! 1.31\trevised above documentation to reflect revision 1.3 (May 9/01)\r\n! =======================================================================\r\n real*8 function dlsmp1( T )\r\n implicit real*8 (a-h,o-z)\r\n common/dparam/ var, dpb, dthx, dthy, dthz\r\n data zero/0.d0/\r\n abs(x) = dabs(x)\r\n\r\n if( var .lt. zero ) then\t\t\t! return variance function\r\n dlsmp1 = -var*dthx/(dthx + abs(T))\r\n else\t\t\t\t\t! return covariance\r\n at = dthx + abs(T)\r\n if( at .eq. zero ) then\r\n dlsmp1 = var\r\n else\r\n bt = dthx/at\r\n dlsmp1 = var*bt*bt*bt\r\n endif\r\n endif\r\n\r\n return\r\n end\r\n", "meta": {"hexsha": "3b94fbc406602e3cb09b3f201e71d04eb7687b4f", "size": 2625, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/libs/gaf95/dlsmp1.f95", "max_stars_repo_name": "leemargetts/PoreFEM", "max_stars_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/libs/gaf95/dlsmp1.f95", "max_issues_repo_name": "leemargetts/PoreFEM", "max_issues_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/libs/gaf95/dlsmp1.f95", "max_forks_repo_name": "leemargetts/PoreFEM", "max_forks_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.7727272727, "max_line_length": 78, "alphanum_fraction": 0.5123809524, "num_tokens": 682, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087965937711, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6843841226653713}} {"text": "\tprogram matrix\n\tparameter (n=100)\n\treal a(n,n), work(4*n)\n real gamma(n,n)\n\treal w(n)\n\t\n\tlwork = 4*n\nc initialise\n\tdo i=1,n\nc diagonal element\n\t a(i,i) = float(i)\n \t do j=i+1,n\nc diagonal element\n \t a(i,j) = 1.0*float(i)/float(i+j)\n\t enddo\n\tenddo\n\n\tcall ssyev('V', 'U', n, a, n, w, work, lwork, info)\n\tprint*,'info= ', info\n\tdo i=1,10\n \t print*,w(i)\n\tenddo\n\nC check eigenvector's ortho-normal\n call sgemm('T', 'N', n, n, n, 1.0, A, n, A, n, 0.0, gamma, n)\n do i=1,5\n\t write(6,200) (gamma(j,i), j=1,10)\n\tenddo\n200 format(1x,10f10.4)\n\tstop\n\tend\n", "meta": {"hexsha": "d658798781926eebbfa144110caa76ace2af1b5e", "size": 578, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Math3/eig.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/eig.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/eig.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": 18.0625, "max_line_length": 69, "alphanum_fraction": 0.5605536332, "num_tokens": 241, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087985746092, "lm_q2_score": 0.7371581510799253, "lm_q1q2_score": 0.6843841134035937}} {"text": "#include \"rundeck_opts.h\"\n\n!@sum TRACERS_O18 water isotope specific routines and functions\n!@auth Gavin Schmidt\n\n FUNCTION FRACVL(TEMP,trname)\n!@sum FRACVL Calculate vapor-->liquid equilibrium fractionation factor\n!@auth Gavin Schmidt\n USE CONSTANT, only : tf\n IMPLICIT NONE\n!@var TEMP temperature (deg C)\n REAL*8, INTENT(IN) :: TEMP\n CHARACTER, INTENT(IN) :: trname*8\n INTEGER, PARAMETER :: NTSPM=4\nc**** quadratic fit to Majoube (1971)\nc REAL*8, PARAMETER ::\nc * A(NTSPM) = (/ 0d0, -3.75d-7, -6.375d-6, -6.875d-6 /),\nc * B(NTSPM) = (/ 0d0, 1.025d-4, 1.2475d-3, 1.7d-3 /),\nc * C(NTSPM) = (/ 1d0, 0.9884d0, 0.9001d0 , 0.86975d0 /)\nc**** exponentials \n REAL*8, PARAMETER ::\n * A(NTSPM) = (/ 0d0, 1137d0 , 24844d0 , 46480d0 /),\n * B(NTSPM) = (/ 0d0, -0.4156d0 , -76.248d0 ,-103.87d0 /),\n * C(NTSPM) = (/ 0d0, -2.0667d-3, 52.612d-3, 0d0 /)\n\n!@var ITR species number of tracer\nC**** 1: Fresh Water 2: o18 3: Deu 4: Tritium\n INTEGER ITR\n REAL*8 FRACVL,TK\nC****\n select case (trname)\n case ('Water')\n ITR=1\n case ('H2O18')\n ITR=2\n case ('HDO')\n ITR=3\n case ('HTO') ! tritium data not yet confirmed\n ITR=4\n case default\n write(6,*) \"Tracer name \",trname,\" not defined in FRACVL\"\n call stop_model('Tracer name not defined in FRACVL',255)\n end select\nC**** Quadratic fit\nc FRACVL=C(ITR) + TEMP*(B(ITR) + TEMP*A(ITR))\nC**** Exponential\n TK=TEMP+TF\n FRACVL=EXP(-A(ITR)/TK**2 - B(ITR)/TK - C(ITR))\nC****\n RETURN\n END FUNCTION FRACVL\n\n FUNCTION FRACVS(TEMP,trname)\n!@sum FRACVS Calculate vapour --> solid (ice) equil. fractionation fact.\n!@auth Gavin Schmidt\n USE CONSTANT, only : tf\n IMPLICIT NONE\n!@var TEMP temperature (deg C)\n REAL*8, INTENT(IN) :: TEMP\n CHARACTER, INTENT(IN) :: trname*8\n INTEGER, PARAMETER :: NTSPM=4\nC**** linear fit\nc REAL*8, PARAMETER ::\nc * A(NTSPM) = (/ 0d0, 1.36d-4, 1.46d-3, 0d0/),\nc * B(NTSPM) = (/ 1d0, 0.9850d0, 0.8834d0, 0.7845d0/)\nC**** exponential\n REAL*8, PARAMETER ::\n * A(NTSPM) = (/ 0d0, 0d0 , 16288d0 , 46480d0 /),\n * B(NTSPM) = (/ 0d0, 11.839d0 , 0d0 ,-103.87d0/),\n * C(NTSPM) = (/ 0d0, -0.028244d0,-0.0934d0, 0d0 /)\n\n!@var ITR species number of tracer\nC**** 1: Fresh Water 2: o18 3: Deu 4: Tritium\n INTEGER ITR\n REAL*8 FRACVS,TK\nC****\n select case (trname)\n case ('Water')\n ITR=1\n case ('H2O18')\n ITR=2\n case ('HDO')\n ITR=3\n case ('HTO') ! tritium data not yet confirmed\n ITR=4\n case default\n write(6,*) \"Tracer name \",trname,\" not defined in FRACVS\"\n call stop_model('Tracer name not defined in FRACVS',255)\n end select\nC**** linear fit\nc FRACVS=B(ITR) + A(ITR)*TEMP\nC**** Exponential\n TK=TEMP+TF\n FRACVS=EXP(-A(ITR)/TK**2 - B(ITR)/TK -C(ITR))\nC****\n RETURN\n END FUNCTION FRACVS\n\n FUNCTION FRACLS(trname)\n!@sum FRACLS Calculate liquid --> solid equilibrium fractionation factor\n!@auth Gavin Schmidt\n IMPLICIT NONE\n CHARACTER, INTENT(IN) :: trname*8\n INTEGER, PARAMETER :: NTSPM=4\n REAL*8, PARAMETER ::\n * A(NTSPM) = (/ 1d0, 1.0035d0, 1.0208d0, 1.04d0/)\n!@var ITR species number of tracer\nC**** 1: Fresh Water 2: o18 3: Deu 4: Tritium\n INTEGER ITR\n REAL*8 FRACLS\nC****\n select case (trname)\n case ('Water')\n ITR=1\n case ('H2O18')\n ITR=2\n case ('HDO')\n ITR=3\n case ('HTO')\n ITR=4\n case default\n FRACLS=1. ! no fractionation\n RETURN\n end select\n FRACLS=A(ITR)\nC****\n RETURN\n END FUNCTION FRACLS\n\n FUNCTION FRACLK(WS,trname)\n!@sum FRACLK calculates the liquid/vapor kinetic fractionation factor\n!@+ from either (Merlivat and Jouzel,1972) or as a constant\n!@auth Gavin Schmidt\n IMPLICIT NONE\n!@var WS surface wind speed (m/s)\n REAL*8, INTENT(IN) :: WS\n CHARACTER, INTENT(IN) :: trname*8\n INTEGER, PARAMETER :: NTSPM=4\n REAL*8, PARAMETER ::\n * A(NTSPM) = (/ 1d0, 0.994d0, 0.99472d0, 0.98944d0 /),\n * B(NTSPM) = (/ 0d0, 0.285d-3, 0.2508d-3, 0.5016d-3 /),\n * C(NTSPM) = (/ 0d0, 0.82d-3, 0.7216d-3, 0.14432d-2 /)\n!@var ITR species number of tracer\nC**** 1: Fresh Water 2: o18 3: Deu 4: Tritium\n INTEGER ITR\n REAL*8 FRACLK\nC****\nC**** Calculate kinetic fractionation factor:\nC****\n select case (trname)\n case ('Water')\n ITR=1\n case ('H2O18')\n ITR=2\n case ('HDO')\n ITR=3\n case ('HTO') ! tritium data not yet confirmed\n ITR=4\n case default\n write(6,*) \"Tracer name \",trname,\" not defined in FRACLK\"\n call stop_model('Tracer name not defined in FRACLK',255)\n end select\n FRACLK=A(ITR)\n IF(WS.GE.7.) FRACLK=1d0-(B(ITR)*WS+C(ITR))\nC****\n RETURN\n END FUNCTION FRACLK\n\n#ifdef TRACERS_SPECIAL_O18\n SUBROUTINE ISOEQUIL(N,TEMP,LIQU,QMV,QML,TRMV,TRML,FEQ)\n!@sum ISOEQUIL equilibrates isotopes in vapor & liquid/solid reservoirs\n!@auth Gavin Schmidt/Georg Hoffmann\n USE CONSTANT, only : tf\n USE TRACER_COM, only: trname,tr_wd_TYPE,nWATER\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: N\n LOGICAL, INTENT(IN) :: LIQU !@var LIQU true if QML is liquid\n REAL*8, INTENT(IN) :: TEMP !@var TEMP temperature (K)\n!@var QMV,QML vapour and liquid water masses (kg or kg/m^2)\n REAL*8, INTENT(IN) :: QMV,QML\n!@var TRMV,TRML vapour and liquid tracer mass (kg or kg/m^2)\n REAL*8, INTENT(INOUT) :: TRMV,TRML\n!@var FEQ fraction of condensate equilibrated (1. = all, 0. = none)\n REAL*8, INTENT(IN) :: FEQ\n REAL*8 TDEGC,ZALPH,ZDELEQU,ZXFAC,FRACVL,FRACVS\n\n SELECT CASE(tr_wd_TYPE(N))\n CASE(nWATER)\n TDEGC = TEMP - TF\n IF (QMV.GT.0.) THEN\n IF (LIQU) THEN\n ZALPH = 1./FRACVL(TDEGC,trname(N))\n ELSE\n ZALPH = 1./FRACVS(TDEGC,trname(N))\n END IF\n ZXFAC = FEQ*ZALPH*QML/QMV\n ZDELEQU = (FEQ*TRML - ZXFAC*TRMV)/(1.+ZXFAC)\n TRML = TRML - ZDELEQU\n TRMV = TRMV + ZDELEQU\n END IF\n END SELECT\n\n RETURN\nC****\n END SUBROUTINE ISOEQUIL\n\n FUNCTION KIN_COND_ICE(ALPH,SUPSAT,trname)\n!@sum calculate kinetic fractionation when condensing to ice in \n!@+ super-saturated conditions\n!@auth Gavin Schmidt/Georg Hoffmann\n USE CONSTANT, only : tf\n IMPLICIT NONE\n CHARACTER, INTENT(IN) :: trname*8\n!@var SUPSAT super_saturation factor from cloud scheme\n REAL*8, INTENT(IN) :: SUPSAT\n!@var ALPH equilibrium fractionation\n REAL*8, INTENT(IN) :: ALPH\n!@var ZDIFREL = inverse ratio of diffusion coeffs w.r.t normal water\n real*8 :: ZDIFREL(4) = (/ 1d0 ,1.0285d0, 1.0251d0, 1.0331d0/)\n integer itr\n real*8 kin_cond_ice\nC****\nC**** Calculate kinetic condensation when condensing to ice\nC****\n select case (trname)\n case ('Water')\n ITR=1\n case ('H2O18')\n ITR=2\n case ('HDO')\n ITR=3\n case ('HTO')\n ITR=4\n case default\n write(6,*) \"Tracer name \",trname,\" not defined in KIN_COND\"\n call stop_model('Tracer name not defined in KIN_COND',255)\n end select\n KIN_COND_ICE=alph*SUPSAT/(1.+(SUPSAT-1.)*alph*ZDIFREL(ITR))\n\n return\n end function kin_cond_ice\n\n FUNCTION KIN_EVAP_PREC(ALPH,HEFF,trname)\n!@sum calculate kinetic fractionation when evaporating into \n!@+ undersaturated environment\n!@auth Gavin Schmidt/Georg Hoffmann\n USE CONSTANT, only : tf\n IMPLICIT NONE\n CHARACTER, INTENT(IN) :: trname*8\n!@var HEFF effective relative humidity from cloud scheme\n REAL*8, INTENT(IN) :: HEFF\n!@var alph equilibrium fractionation \n REAL*8, INTENT(IN) :: ALPH\n!@var ZDIFRELGAM = ZDIFREL^0.58 \n real*8 :: ZDIFRELGAM(4) = (/ 1d0, 1.0164d0, 1.0145d0, 1.0191d0/)\n integer itr\n real*8 kin_evap_prec\nC****\nC**** Calculate kinetic condensation when evaporating below clouds\nC****\n select case (trname)\n case ('Water')\n ITR=1\n case ('H2O18')\n ITR=2\n case ('HDO')\n ITR=3\n case ('HTO')\n ITR=4\n case default\n write(6,*) \"Tracer name \",trname,\" not defined in KIN_EVAP\"\n call stop_model('Tracer name not defined in KIN_EVAP',255)\n end select\n KIN_EVAP_PREC=alph*HEFF/(1.+(HEFF-1.)*alph*ZDIFRELGAM(ITR))\n\n return\n end function kin_evap_prec\n\n FUNCTION delta(W,T,n)\n!@sum calculate per mil values\n use TRACER_COM, only : trw0\n implicit none\n real*8, intent(in) :: W,T\n integer, intent(in) :: n\n real*8 delta\n\n delta=0.\n if (trw0(n).gt.0 .and. W.gt.0) delta=(T/(W*trw0(n))-1.)*1d3\n\n return\n end function delta\n#endif\n", "meta": {"hexsha": "d87b20011815e6e445cb5fe6c08b1d93b59e242b", "size": 8950, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/model/TRACERS_O18.f", "max_stars_repo_name": "Climostatistics/giss_model_e", "max_stars_repo_head_hexsha": "2ec1e4fd6ef009fe894a98955ef6e1586753ff79", "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": "source/model/TRACERS_O18.f", "max_issues_repo_name": "Climostatistics/giss_model_e", "max_issues_repo_head_hexsha": "2ec1e4fd6ef009fe894a98955ef6e1586753ff79", "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": "source/model/TRACERS_O18.f", "max_forks_repo_name": "Climostatistics/giss_model_e", "max_forks_repo_head_hexsha": "2ec1e4fd6ef009fe894a98955ef6e1586753ff79", "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": 30.5460750853, "max_line_length": 72, "alphanum_fraction": 0.5823463687, "num_tokens": 3234, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436482, "lm_q2_score": 0.743168019989179, "lm_q1q2_score": 0.6843014370275795}} {"text": "\n ! The decimal number, 585 = 10010010012\n ! (binary), is palindromic in both bases.\n !\n ! Find the sum of all numbers, less than\n ! one million, which are palindromic in\n ! base 10 and base 2.\n !\n ! Project Euler: 36\n ! Answer: 872187\n\nprogram main\n\n use euler\n\nimplicit none\n\n integer (int32), parameter :: MAX_N = 1000000;\n integer (int32) :: i, sum;\n\n sum = 0\n\n do i = 1, MAX_N\n if(intrev(i) == i .and. binrev(i) == i) sum = sum + i\n end do\n\n print*, sum\n\n\ncontains\n\n ! This function works the same as the base 10 one; we start with a\n ! blank integer, and read results from one end, appending to the other\n\n function binrev(x)\n\n integer (int32) :: binrev, x, n\n binrev = 0;\n n = x\n\n do while (n > 0)\n binrev = IEOR(ISHFT(binrev, 1), IAND(n, 1));\n n = ISHFT(n, -1);\n\n end do\n\n end function binrev\n\n\nend program main\n\n", "meta": {"hexsha": "dea567d7930f192f913d437a570049f064d5d92f", "size": 1034, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "fortran/double_base_palindromes.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/double_base_palindromes.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/double_base_palindromes.f95", "max_forks_repo_name": "guynan/project_euler", "max_forks_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-11-03T01:14:28.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-26T13:52:51.000Z", "avg_line_length": 19.8846153846, "max_line_length": 78, "alphanum_fraction": 0.5154738878, "num_tokens": 288, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436483, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6843014213142606}} {"text": "C$Procedure DRDLAT ( Derivative of rectangular w.r.t. latitudinal )\n \n SUBROUTINE DRDLAT ( R, LONG, LAT, JACOBI )\n IMPLICIT NONE\n \nC$ Abstract\nC\nC Compute the Jacobian of the transformation from latitudinal to\nC rectangular coordinates.\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 COORDINATES\nC DERIVATIVES\nC MATRIX\nC\nC$ Declarations\n \n DOUBLE PRECISION R\n DOUBLE PRECISION LONG\n DOUBLE PRECISION LAT\n DOUBLE PRECISION JACOBI ( 3, 3 )\n \nC$ Brief_I/O\nC\nC Variable I/O Description\nC -------- --- --------------------------------------------------\nC RADIUS I Distance of a point from the origin.\nC LONG I Angle of the point from the XZ plane in radians.\nC LAT I Angle of the point from the XY plane in radians.\nC JACOBI O Matrix of partial derivatives.\nC\nC$ Detailed_Input\nC\nC RADIUS Distance of a point from the origin.\nC\nC LONG Angle of the point from the XZ plane in radians.\nC The angle increases in the counterclockwise sense\nC about the +Z axis.\nC\nC LAT Angle of the point from the XY plane in radians.\nC The angle increases in the direction of the +Z axis.\nC\nC$ Detailed_Output\nC\nC JACOBI is the matrix of partial derivatives of the conversion\nC between latitudinal and rectangular coordinates. It has\nC the form\nC\nC .- -.\nC | DX/DR DX/DLONG DX/DLAT |\nC | |\nC | DY/DR DY/DLONG DY/DLAT |\nC | |\nC | DZ/DR DZ/DLONG DZ/DLAT |\nC `- -'\nC\nC evaluated at the input values of R, LONG and LAT.\nC Here X, Y, and Z are given by the familiar formulae\nC\nC X = R * COS(LONG) * COS(LAT)\nC Y = R * SIN(LONG) * COS(LAT)\nC Z = R * SIN(LAT)\nC\nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC Error free.\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC It is often convenient to describe the motion of an object\nC in latitudinal coordinates. It is also convenient to manipulate\nC vectors associated with the object in rectangular coordinates.\nC\nC The transformation of a latitudinal state into an equivalent\nC rectangular state makes use of the Jacobian of the\nC transformation between the two systems.\nC\nC Given a state in latitudinal coordinates,\nC\nC ( r, long, lat, dr, dlong, dlat )\nC\nC the velocity in rectangular coordinates is given by the matrix\nC equation\nC t | t\nC (dx, dy, dz) = JACOBI| * (dr, dlong, dlat)\nC |(r,long,lat)\nC \nC This routine computes the matrix \nC\nC |\nC JACOBI|\nC |(r,long,lat)\nC\nC$ Examples\nC\nC Suppose you have a model that gives radius, longitude, and\nC latitude as functions of time (r(t), long(t), lat(t)), and\nC that the derivatives (dr/dt, dlong/dt, dlat/dt) are computable.\nC To find the velocity of the object in rectangular coordinates,\nC multiply the Jacobian of the transformation from latitudinal\nC to rectangular (evaluated at r(t), long(t), lat(t)) by the\nC vector of derivatives of the latitudinal coordinates.\nC\nC This is illustrated by the following code fragment.\nC\nC C\nC C Load the derivatives of r, long and lat into the\nC C latitudinal velocity vector LATV.\nC C\nC LATV(1) = DR_DT ( T )\nC LATV(2) = DLONG_DT ( T )\nC LATV(3) = DLAT_DT ( T )\nC\nC C\nC C Determine the Jacobian of the transformation from\nC C latitudinal to rectangular coordinates, using the \nC C latitudinal coordinates at time T.\nC C\nC CALL DRDLAT ( R(T), LONG(T), LAT(T), JACOBI )\nC\nC C\nC C Multiply the Jacobian by the latitudinal velocity to\nC C obtain the rectangular velocity RECV.\nC C\nC CALL MXV ( JACOBI, LATV, RECV )\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC W.L. Taber (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.0, 19-JUL-2001 (WLT)\nC\nC-&\n\nC$ Index_Entries\nC\nC Jacobian of rectangular w.r.t. latitudinal coordinates\nC\nC-&\n \n \nC$ Revisions\nC\nC None.\nC\nC-&\n \n \nC\nC Local variables\nC\n INTEGER DX\n PARAMETER ( DX = 1 )\n \n INTEGER DY\n PARAMETER ( DY = 2 )\n \n INTEGER DZ\n PARAMETER ( DZ = 3 )\n \n INTEGER DR\n PARAMETER ( DR = 1 )\n \n INTEGER DLON\n PARAMETER ( DLON = 2 )\n \n INTEGER DLAT\n PARAMETER ( DLAT = 3 )\n \n \n \nC\nC Construct the matrix directly.\nC\n JACOBI (DX,DR) = DCOS( LONG ) * DCOS( LAT )\n JACOBI (DY,DR) = DSIN( LONG ) * DCOS( LAT )\n JACOBI (DZ,DR) = DSIN( LAT )\n \n JACOBI (DX,DLON) = -R * DSIN( LONG ) * DCOS( LAT )\n JACOBI (DY,DLON) = R * DCOS( LONG ) * DCOS( LAT )\n JACOBI (DZ,DLON) = 0.0D0\n \n JACOBI (DX,DLAT) = -R * DCOS( LONG ) * DSIN( LAT )\n JACOBI (DY,DLAT) = -R * DSIN( LONG ) * DSIN( LAT )\n JACOBI (DZ,DLAT) = R * DCOS( LAT )\n \n RETURN\n END\n", "meta": {"hexsha": "92d5bb2d0366f9158c18d7c6ffa979e4d0de5aa7", "size": 7125, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/drdlat.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/drdlat.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/drdlat.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": 30.0632911392, "max_line_length": 72, "alphanum_fraction": 0.5674385965, "num_tokens": 1967, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896693699845, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6843014196988633}} {"text": " subroutine annulus_basis_complete(x,y, t, tinv,tderivs, flag)\n implicit none\n \n double precision x,y \n integer flag\n double precision t(3,2), tinv(3,2), tderivs(3,2,2)\n\n double precision pi, pi2\n common /compi/ pi, pi2\n\n double precision beta, theta_vec(2)\n common /annulus_comm/ beta, theta_vec\n\n double precision r1, r1x, r1xx, r1y, r1yy, r1xy\n double precision R, Rx, Rxx, Ry, Ryy, Rxy\n double precision f(3), fx(3), fy(3), fxx(3), fyy(3), fxy(3)\n double precision g(3), gx(3), gy(3), gxx(3), gyy(3), gxy(3)\n double precision t1(3), t2(3), a11, a12, a22, a21\n double precision det, a11inv, a22inv, a12inv, a21inv\n double precision pi4\n double precision annulus_dot\n\n\n integer k, kk, i\n logical compute_covariant, compute_contravariant\n logical compute_derivatives, b(32)\n\n double precision theta, thetax, thetay\n\n if (flag > 7) then\n write(6,*) 'psi.f : flag > 7'\n stop\n endif\n\nc # flag = 0 NA\nc # flag = 1 Covariant basis only\nc # flag = 2 NA\nc # flag = 3 Covariant + contravariant basis\nc # flag = 4 Derivatives only\nc # flag = 5 Derivatives + covariant basis\nc # flag = 6 NA\nc # flag = 7 Covariant + contravariant + derivatives\n\n\n do i = 1,bit_size(flag)\n b(i) = btest(flag,i-1) \n enddo\n\n compute_covariant = b(1) .or. b(2)\n compute_contravariant = b(2)\n compute_derivatives = b(3)\n\nc pi4 = pi2*pi2\n\n call map_comp2annulus_derivs(x,y,theta,r,\n & thetax, thetay, rx, ry) \n\n\nc r = beta + (1-beta)*yc\nc xp = r*cos(2*pi*xc)\nc yp = r*sin(2*pi*xc)\n\n\n\n if (compute_covariant) then\n t(1,1) = -thetax*r*sin(theta)\n t(2,1) = thetax*r*cos(theta)\n t(3,1) = 0\n\n t(1,2) = ry*cos(theta)\n t(2,2) = ry*sin(theta)\n t(3,2) = 0\n\n endif\n\n R = beta + (1-beta)*y\n Rx = 0\n Rxx = 0\n Ry = 1-beta\n Ryy = 0\n Rxy = 0\n\n f(1) = cos(theta);\n fx(1) = -thetax*sin(theta)\n fy(1) = 0\n\n f(2) = sin(theta);\n fx(2) = thetax*cos(theta)\n fy(2) = 0\n\n f(3) = 0\n fx(3) = 0\n fy(3) = 0\n\n g(1) = R\n g(2) = R\n g(3) = 0\n\n gx(1) = Rx\n gx(2) = Rx\n gx(3) = 0\n\n gy(1) = Ry\n gy(2) = Ry\n gy(3) = 0\n\n if (compute_covariant) then\n do k = 1,3\n t(k,1) = gx(k)*f(k) + g(k)*fx(k);\n t(k,2) = gy(k)*f(k) + g(k)*fy(k);\n enddo\n endif\n\n if (compute_contravariant) then\n call map_contravariant(t,tinv) \n endif\n\n if (compute_derivatives) then\n fxx(1) = -thetax**2*cos(theta)\n fyy(1) = 0\n fxy(1) = 0\n\n fxx(2) = -thetax**2*sin(theta)\n fyy(2) = 0\n fxy(2) = 0\n\n fxx(3) = 0\n fxy(3) = 0\n fyy(3) = 0\n\n gxx(1) = Rxx\n gxx(2) = Rxx\n gxx(3) = 0\n\n gyy(1) = Ryy\n gyy(2) = Ryy\n gyy(3) = 0\n\n gxy(1) = Rxy\n gxy(2) = Rxy\n gxy(3) = 0\n\n do k = 1,3\nc # d(t1)/dx = d(g*fx + gx*f)/dx\n tderivs(k,1,1) = g(k)*fxx(k) + 2*fx(k)*gx(k) + gxx(k)*f(k)\n\nc # d(t1)/dy = d(g*fx + gx*f)/dy \n tderivs(k,1,2) = g(k)*fxy(k) + gy(k)*fx(k) + \n & gx(k)*fy(k) + gxy(k)*f(k)\n\nc # d(t2)/dx = d(g*fy + gy*f)/dx \n tderivs(k,2,1) = g(k)*fxy(k) + gx(k)*fy(k) + \n & gy(k)*fx(k) + gxy(k)*f(k)\n\nc # d(t2)/dy = d(g*fy + gy*f)/dy \n tderivs(k,2,2) = g(k)*fyy(k) + 2*fy(k)*gy(k) + gyy(k)*f(k)\n enddo\n endif\n\n end\n\n\n\n subroutine map_comp2annulus(xc,yc,theta,r)\n implicit none\n\n double precision xc,yc,theta, r\n\n double precision thetax, thetay, rx, ry\n\nc # Map xc in [0,1] to theta in [-pi,pi]\nc # Map yc in [0,1] to phi in [-pi/2,pi/2] \n\n call map_comp2annulus_derivs(xc,yc,theta,r,\n & thetax, thetay, rx, ry)\n\n end\n\n subroutine map_comp2annulus_derivs(xc,yc,theta,r,\n & thetax, thetay, rx, ry)\n implicit none\n\n double precision xc,yc,theta, r\n\n double precision pi, pi2\n common /compi/ pi, pi2\n\n double precision beta, theta_range(2)\n common /annulus_comm/ beta, theta_range\n\n double precision thetax, thetay, rx, ry\n double precision tr1, tr2, pr1, pr2\n\n\nc # Map xc in [0,1] to theta in [0,2*pi]\nc # Map yc in [0,1] to phi in [-pi/2,pi/2] \n \n tr1 = pi2*theta_range(1)\n tr2 = pi2*theta_range(2)\n\n theta = tr1 + (tr2-tr1)*xc\n thetax = tr2-tr1\n thetay = 0\n\n r = beta + (1-beta)*yc\n rx = 0\n ry = 1-beta\n\n end\n\n subroutine map_annulus2comp(theta,r, xc,yc)\n implicit none\n\n double precision xc,yc,phi,theta, r\n\n double precision pi, pi2\n common /compi/ pi, pi2\n\n double precision beta, theta_range(2)\n common /annulus_comm/ beta, theta_range\n\n double precision tr1, tr2, pr1, pr2\n\nc # Map xc in [0,1] to theta in [0,2*pi]\nc # Map yc in [0,1] to phi in [-pi/2,pi/2] \n\n tr1 = pi2*theta_range(1)\n tr2 = pi2*theta_range(2)\n\n xc = (theta-tr1)/(tr2-tr1)\n yc = (r - beta)/(1-beta)\n\n end\n\n subroutine map2annulus(xp,yp,zp,theta,r)\n implicit none\n\n double precision xp,yp,zp,theta, r\n\n double precision pi, pi2\n common /compi/ pi, pi2\n\n double precision beta, theta_range(2)\n common /annulus_comm/ beta, theta_range\n\nc r1 = alpha*(1 + beta*sin(pi2*xc))\nc R = 1 + r1*cos(pi2*yc)\nc\nc xp = R*cos(pi2*xc)\nc yp = R*sin(pi2*xc)\nc zp = r1*sin(pi2*yc)\n\n \n theta = atan2(yp,xp) !! returns value in [-pi, pi]\n if (theta < 0) then\n theta = theta + pi2\n endif\n\n r = sqrt(xp**2 + yp**2)\n\n end\n\n subroutine map2comp(xp,yp,zp,xc,yc)\n implicit none\n\n double precision xp,yp,zp, xc,yc\n\n double precision pi, pi2\n common /compi/ pi, pi2\n\n double precision r, theta\n\n call map2annulus(xp,yp,zp,theta,r)\n\n call map_annulus2comp(theta,r,xc,yc)\n\n end\n\n", "meta": {"hexsha": "7bd9f7483ba7ad3d2207219dbb1a6ea21e8c66a8", "size": 6357, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "applications/paper/all/annulus_basis.f", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2017-09-26T13:39:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:56:23.000Z", "max_issues_repo_path": "applications/paper/all/annulus_basis.f", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 75, "max_issues_repo_issues_event_min_datetime": "2017-08-02T19:56:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T12:36:32.000Z", "max_forks_repo_path": "applications/paper/all/annulus_basis.f", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-02-21T00:10:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T19:08:36.000Z", "avg_line_length": 22.7849462366, "max_line_length": 72, "alphanum_fraction": 0.4936290703, "num_tokens": 2276, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436482, "lm_q2_score": 0.743167997235783, "lm_q1q2_score": 0.6843014160764874}} {"text": "! { dg-do run }\n! { dg-options \"-Warray-temporaries\" }\n! PR 71961 - no array temporary was created.\n! Original test case by Joost VandeVondele\nprogram main\n implicit none\n integer :: i\n integer, dimension(:,:), pointer :: a\n integer, dimension(:,:), allocatable :: b\n ALLOCATE(a(4,4),b(4,2))\n a=1 ; b=2\n a(:,1:2)=matmul(a(:,1:4),b(:,:)) ! { dg-warning \"Creating array temporary\" }\n if (any(a /= reshape((/8,8,8,8,8,8,8,8,1,1,1,1,1,1,1,1/),(/4,4/)))) &\n STOP 1\n a = reshape([((-1**i)*i,i=1,16)],[4,4])\n b = reshape([((-1**(i-1))*i**2,i=1,8)],[4,2])\n b(1:2,1:2) = matmul(a(1:2,:),b) ! { dg-warning \"Creating array temporary\" }\n if (any(b /= reshape([310, 340, -9, -16, 1478, 1652, -49, -64],[4,2]))) &\n STOP 2\n deallocate(a)\n deallocate(b)\nend program main\n", "meta": {"hexsha": "a4a2589796fce41b9d68f05807b2289d162ad86e", "size": 781, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/matmul_10.f90", "max_stars_repo_name": "brugger1/testsuite", "max_stars_repo_head_hexsha": "9b504db668cdeaf7c561f15b76c95d05bfdd1517", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2019-02-12T18:20:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-09T19:46:19.000Z", "max_issues_repo_path": "validation_tests/llvm/f18/gfortran.dg/matmul_10.f90", "max_issues_repo_name": "brugger1/testsuite", "max_issues_repo_head_hexsha": "9b504db668cdeaf7c561f15b76c95d05bfdd1517", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 24, "max_issues_repo_issues_event_min_datetime": "2020-08-31T22:05:07.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T18:30:03.000Z", "max_forks_repo_path": "validation_tests/llvm/f18/gfortran.dg/matmul_10.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": 33.9565217391, "max_line_length": 78, "alphanum_fraction": 0.5633802817, "num_tokens": 321, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256472515683, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.6842925540601156}} {"text": "PROGRAM test_vectors\r\n!\r\n! Purpose:\r\n! To test the definitions, operations, and assignments \r\n! associated with the vector data type.\r\n!\r\n! Record of revisions:\r\n! Date Programmer Description of change\r\n! ==== ========== =====================\r\n! 12/15/06 S. J. Chapman Original code\r\n!\r\nUSE vectors\r\nIMPLICIT NONE\r\n\r\n! Data dictionary: declare variable types & definitions\r\nREAL, DIMENSION(3) :: array_out ! Output array\r\nTYPE (vector) :: vec_1, vec_2 ! Test vectors\r\n\r\n! Test assignments by assigning an array to vec_1 and \r\n! assigning vec_1 to array_out.\r\nvec_1 = (/ 1., 2., 3. /)\r\narray_out = vec_1\r\nWRITE (*,1000) vec_1, array_out\r\n1000 FORMAT (' Test assignments: ',/, &\r\n ' vec_1 = ', 3F8.2,/, &\r\n ' array_out = ', 3F8.2)\r\n\r\n! Test addition and subtraction.\r\nvec_1 = (/ 10., 20., 30. /)\r\nvec_2 = (/ 1., 2., 3. /)\r\nWRITE (*,1010) vec_1, vec_2, vec_1 + vec_2, vec_1 - vec_2\r\n1010 FORMAT (/' Test addition and subtraction: ',/, &\r\n ' vec_1 = ', 3F8.2,/, &\r\n ' vec_2 = ', 3F8.2,/, &\r\n ' vec_1 + vec_2 = ', 3F8.2,/, &\r\n ' vec_1 - vec_2 = ', 3F8.2)\r\n\r\n! Test multiplication by a scalar.\r\nvec_1 = (/ 1., 2., 3. /)\r\nWRITE (*,1020) vec_1, 2.*vec_1, vec_1*2., 2*vec_1, vec_1*2\r\n1020 FORMAT (/' Test multiplication by a scalar: ',/, &\r\n ' vec_1 = ', 3F8.2,/, &\r\n ' 2. * vec_1 = ', 3F8.2,/, &\r\n ' vec_1 * 2. = ', 3F8.2,/, &\r\n ' 2 * vec_1 = ', 3F8.2,/, &\r\n ' vec_1 * 2 = ', 3F8.2)\r\n\r\n! Test division by a scalar.\r\nvec_1 = (/ 10., 20., 30. /)\r\nWRITE (*,1030) vec_1, vec_1/5., vec_1/5\r\n1030 FORMAT (/' Test division by a scalar: ',/, &\r\n ' vec_1 = ', 3F8.2,/, &\r\n ' vec_1 / 5. = ', 3F8.2,/, &\r\n ' vec_1 / 5 = ', 3F8.2)\r\n\r\n! Test dot product.\r\nvec_1 = (/ 1., 2., 3. /)\r\nvec_2 = (/ 1., 2., 3. /)\r\nWRITE (*,1040) vec_1, vec_2, vec_1 .DOT. vec_2\r\n1040 FORMAT (/' Test dot product: ',/, &\r\n ' vec_1 = ', 3F8.2,/, &\r\n ' vec_2 = ', 3F8.2,/, &\r\n ' vec_1 .DOT. vec_2 = ', 3F8.2)\r\n \r\n! Test cross product.\r\nvec_1 = (/ 1., -1., 1. /)\r\nvec_2 = (/ -1., 1., 1. /)\r\nWRITE (*,1050) vec_1, vec_2, vec_1*vec_2\r\n1050 FORMAT (/' Test cross product: ',/, &\r\n ' vec_1 = ', 3F8.2,/, &\r\n ' vec_2 = ', 3F8.2,/, &\r\n ' vec_1 * vec_2 = ', 3F8.2)\r\n\r\nEND PROGRAM test_vectors\r\n", "meta": {"hexsha": "cfe3c017959cbdf0735d4da5e7995902653d746b", "size": 2573, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap13/test_vectors.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/test_vectors.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/test_vectors.f90", "max_forks_repo_name": "yangyang14641/FortranLearning", "max_forks_repo_head_hexsha": "3d4a91aacd957361aff5873054edf35c586e8a55", "max_forks_repo_licenses": ["AFL-3.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-05-11T02:36:25.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-05T06:36:55.000Z", "avg_line_length": 34.3066666667, "max_line_length": 60, "alphanum_fraction": 0.4566653712, "num_tokens": 938, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256313782276, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.68429253924905}} {"text": " subroutine EBGDFFACEDIVINCR(\n & divvel\n & ,idivvello0,idivvello1\n & ,idivvelhi0,idivvelhi1\n & ,vel\n & ,ivello0,ivello1\n & ,ivelhi0,ivelhi1\n & ,nvelcomp\n & ,gradvel\n & ,igradvello0,igradvello1\n & ,igradvelhi0,igradvelhi1\n & ,ngradvelcomp\n & ,iregionlo0,iregionlo1\n & ,iregionhi0,iregionhi1\n & ,dx\n & ,facedir\n & ,divdir\n & )\n implicit none\n integer*8 ch_flops\n COMMON/ch_timer/ ch_flops\n integer CHF_ID(0:5,0:5)\n data CHF_ID/ 1,0,0,0,0,0 ,0,1,0,0,0,0 ,0,0,1,0,0,0 ,0,0,0,1,0,0 ,0\n &,0,0,0,1,0 ,0,0,0,0,0,1 /\n integer idivvello0,idivvello1\n integer idivvelhi0,idivvelhi1\n REAL*8 divvel(\n & idivvello0:idivvelhi0,\n & idivvello1:idivvelhi1)\n integer nvelcomp\n integer ivello0,ivello1\n integer ivelhi0,ivelhi1\n REAL*8 vel(\n & ivello0:ivelhi0,\n & ivello1:ivelhi1,\n & 0:nvelcomp-1)\n integer ngradvelcomp\n integer igradvello0,igradvello1\n integer igradvelhi0,igradvelhi1\n REAL*8 gradvel(\n & igradvello0:igradvelhi0,\n & igradvello1:igradvelhi1,\n & 0:ngradvelcomp-1)\n integer iregionlo0,iregionlo1\n integer iregionhi0,iregionhi1\n REAL*8 dx\n integer facedir\n integer divdir\n integer ii,i,jj,j, gradcomp, sdim\n sdim = 2\n ii = chf_id(facedir, 0)\n jj = chf_id(facedir, 1)\n if (facedir .eq. divdir) then\n do j = iregionlo1,iregionhi1\n do i = iregionlo0,iregionhi0\n divvel(i,j) = divvel(i,j) +\n $ ( vel(i ,j ,facedir)\n $ - vel(i-ii,j-jj,facedir) )/dx\n enddo\n enddo\n else\n gradcomp = divdir + sdim*divdir\n do j = iregionlo1,iregionhi1\n do i = iregionlo0,iregionhi0\n divvel(i,j) = divvel(i,j) +\n $ ( gradvel(i ,j , gradcomp)\n $ + gradvel(i-ii,j-jj, gradcomp) )/(2.0d0)\n enddo\n enddo\n endif\n return\n end\n subroutine EBGDFGRADVEL(\n & grad\n & ,igradlo0,igradlo1\n & ,igradhi0,igradhi1\n & ,vel\n & ,ivello0,ivello1\n & ,ivelhi0,ivelhi1\n & ,iloboxlo0,iloboxlo1\n & ,iloboxhi0,iloboxhi1\n & ,haslo\n & ,ihiboxlo0,ihiboxlo1\n & ,ihiboxhi0,ihiboxhi1\n & ,hashi\n & ,icenterboxlo0,icenterboxlo1\n & ,icenterboxhi0,icenterboxhi1\n & ,dx\n & ,divdir\n & ,loworderoneside\n & )\n implicit none\n integer*8 ch_flops\n COMMON/ch_timer/ ch_flops\n integer CHF_ID(0:5,0:5)\n data CHF_ID/ 1,0,0,0,0,0 ,0,1,0,0,0,0 ,0,0,1,0,0,0 ,0,0,0,1,0,0 ,0\n &,0,0,0,1,0 ,0,0,0,0,0,1 /\n integer igradlo0,igradlo1\n integer igradhi0,igradhi1\n REAL*8 grad(\n & igradlo0:igradhi0,\n & igradlo1:igradhi1)\n integer ivello0,ivello1\n integer ivelhi0,ivelhi1\n REAL*8 vel(\n & ivello0:ivelhi0,\n & ivello1:ivelhi1)\n integer iloboxlo0,iloboxlo1\n integer iloboxhi0,iloboxhi1\n integer haslo\n integer ihiboxlo0,ihiboxlo1\n integer ihiboxhi0,ihiboxhi1\n integer hashi\n integer icenterboxlo0,icenterboxlo1\n integer icenterboxhi0,icenterboxhi1\n REAL*8 dx\n integer divdir\n integer loworderoneside\n integer ii,i,jj,j\n ii = chf_id(divdir, 0)\n jj = chf_id(divdir, 1)\n do j = icenterboxlo1,icenterboxhi1\n do i = icenterboxlo0,icenterboxhi0\n grad(i,j) =\n $ ( vel(i+ii,j+jj)\n $ - vel(i-ii,j-jj) )/((2.0d0)*dx)\n enddo\n enddo\n if(haslo.eq.1) then\n if(loworderoneside.eq.1) then\n do j = iloboxlo1,iloboxhi1\n do i = iloboxlo0,iloboxhi0\n grad(i,j) =\n $ ( vel(i+ii,j+jj)\n $ - vel(i ,j ))/(dx)\n enddo\n enddo\n else\n do j = iloboxlo1,iloboxhi1\n do i = iloboxlo0,iloboxhi0\n grad(i,j) =\n $ ((4.0d0)*(vel(i+ ii,j+ jj) - vel(i,j))\n $ - (vel(i+2*ii,j+2*jj) - vel(i,j)))/((2.0d0)*dx)\n enddo\n enddo\n endif\n endif\n if(hashi.eq.1) then\n if(loworderoneside.eq.1) then\n do j = ihiboxlo1,ihiboxhi1\n do i = ihiboxlo0,ihiboxhi0\n grad(i,j) =\n $ ( vel(i-ii,j-jj)\n $ - vel(i ,j ))/(-dx)\n enddo\n enddo\n else\n do j = ihiboxlo1,ihiboxhi1\n do i = ihiboxlo0,ihiboxhi0\n grad(i,j) =\n $ ((4.0d0)*(vel(i- ii,j- jj) - vel(i,j))\n $ - (vel(i-2*ii,j-2*jj) - vel(i,j)))/(-(2.0d0)*dx)\n enddo\n enddo\n endif\n endif\n return\n end\n subroutine EBGDFCELLGRAD(\n & graddiv\n & ,igraddivlo0,igraddivlo1\n & ,igraddivhi0,igraddivhi1\n & ,div\n & ,idivlo0,idivlo1\n & ,idivhi0,idivhi1\n & ,lambda\n & ,ilambdalo0,ilambdalo1\n & ,ilambdahi0,ilambdahi1\n & ,iregionlo0,iregionlo1\n & ,iregionhi0,iregionhi1\n & ,dx\n & ,facedir\n & ,imultbylambda\n & )\n implicit none\n integer*8 ch_flops\n COMMON/ch_timer/ ch_flops\n integer CHF_ID(0:5,0:5)\n data CHF_ID/ 1,0,0,0,0,0 ,0,1,0,0,0,0 ,0,0,1,0,0,0 ,0,0,0,1,0,0 ,0\n &,0,0,0,1,0 ,0,0,0,0,0,1 /\n integer igraddivlo0,igraddivlo1\n integer igraddivhi0,igraddivhi1\n REAL*8 graddiv(\n & igraddivlo0:igraddivhi0,\n & igraddivlo1:igraddivhi1)\n integer idivlo0,idivlo1\n integer idivhi0,idivhi1\n REAL*8 div(\n & idivlo0:idivhi0,\n & idivlo1:idivhi1)\n integer ilambdalo0,ilambdalo1\n integer ilambdahi0,ilambdahi1\n REAL*8 lambda(\n & ilambdalo0:ilambdahi0,\n & ilambdalo1:ilambdahi1)\n integer iregionlo0,iregionlo1\n integer iregionhi0,iregionhi1\n REAL*8 dx\n integer facedir\n integer imultbylambda\n integer ii,i,jj,j\n ii = chf_id(facedir, 0)\n jj = chf_id(facedir, 1)\n do j = iregionlo1,iregionhi1\n do i = iregionlo0,iregionhi0\n graddiv(i,j) =\n $ ( div(i+ii,j+jj)\n $ - div(i ,j ) )/dx\n if(imultbylambda .eq. 1) then\n graddiv(i,j) = lambda(i,j)*graddiv(i,j)\n endif\n enddo\n enddo\n return\n end\n", "meta": {"hexsha": "aa1b17773b510eb0e574c5619a9d5b9e26806eed", "size": 5970, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "releasedExamples/EBAMRINS/exec/f/2d.Linux.64.mpicxx.gfortran.OPTHIGH.MPI.OPENMPCC/EBGradDivFilterF.f", "max_stars_repo_name": "rmrsk/Chombo-3.3", "max_stars_repo_head_hexsha": "f2119e396460c1bb19638effd55eb71c2b35119e", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "releasedExamples/EBAMRINS/exec/f/2d.Linux.64.mpicxx.gfortran.OPTHIGH.MPI.OPENMPCC/EBGradDivFilterF.f", "max_issues_repo_name": "rmrsk/Chombo-3.3", "max_issues_repo_head_hexsha": "f2119e396460c1bb19638effd55eb71c2b35119e", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "releasedExamples/EBAMRINS/exec/f/2d.Linux.64.mpicxx.gfortran.OPTHIGH.MPI.OPENMPCC/EBGradDivFilterF.f", "max_forks_repo_name": "rmrsk/Chombo-3.3", "max_forks_repo_head_hexsha": "f2119e396460c1bb19638effd55eb71c2b35119e", "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.4159292035, "max_line_length": 72, "alphanum_fraction": 0.5671691792, "num_tokens": 2456, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.6842733853287576}} {"text": "*> \\brief \\b SLAROR\n*\n* =========== DOCUMENTATION ===========\n*\n* Online html documentation available at\n* http://www.netlib.org/lapack/explore-html/\n*\n* Definition:\n* ===========\n*\n* SUBROUTINE SLAROR( SIDE, INIT, M, N, A, LDA, ISEED, X, INFO )\n*\n* .. Scalar Arguments ..\n* CHARACTER INIT, SIDE\n* INTEGER INFO, LDA, M, N\n* ..\n* .. Array Arguments ..\n* INTEGER ISEED( 4 )\n* REAL A( LDA, * ), X( * )\n* ..\n*\n*\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*>\n*> SLAROR pre- or post-multiplies an M by N matrix A by a random\n*> orthogonal matrix U, overwriting A. A may optionally be initialized\n*> to the identity matrix before multiplying by U. U is generated using\n*> the method of G.W. Stewart (SIAM J. Numer. Anal. 17, 1980, 403-409).\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in] SIDE\n*> \\verbatim\n*> SIDE is CHARACTER*1\n*> Specifies whether A is multiplied on the left or right by U.\n*> = 'L': Multiply A on the left (premultiply) by U\n*> = 'R': Multiply A on the right (postmultiply) by U'\n*> = 'C' or 'T': Multiply A on the left by U and the right\n*> by U' (Here, U' means U-transpose.)\n*> \\endverbatim\n*>\n*> \\param[in] INIT\n*> \\verbatim\n*> INIT is CHARACTER*1\n*> Specifies whether or not A should be initialized to the\n*> identity matrix.\n*> = 'I': Initialize A to (a section of) the identity matrix\n*> before applying U.\n*> = 'N': No initialization. Apply U to the input matrix A.\n*>\n*> INIT = 'I' may be used to generate square or rectangular\n*> orthogonal matrices:\n*>\n*> For M = N and SIDE = 'L' or 'R', the rows will be orthogonal\n*> to each other, as will the columns.\n*>\n*> If M < N, SIDE = 'R' produces a dense matrix whose rows are\n*> orthogonal and whose columns are not, while SIDE = 'L'\n*> produces a matrix whose rows are orthogonal, and whose first\n*> M columns are orthogonal, and whose remaining columns are\n*> zero.\n*>\n*> If M > N, SIDE = 'L' produces a dense matrix whose columns\n*> are orthogonal and whose rows are not, while SIDE = 'R'\n*> produces a matrix whose columns are orthogonal, and whose\n*> first M rows are orthogonal, and whose remaining rows are\n*> zero.\n*> \\endverbatim\n*>\n*> \\param[in] M\n*> \\verbatim\n*> M is INTEGER\n*> The number of rows of A.\n*> \\endverbatim\n*>\n*> \\param[in] N\n*> \\verbatim\n*> N is INTEGER\n*> The number of columns of A.\n*> \\endverbatim\n*>\n*> \\param[in,out] A\n*> \\verbatim\n*> A is REAL array, dimension (LDA, N)\n*> On entry, the array A.\n*> On exit, overwritten by U A ( if SIDE = 'L' ),\n*> or by A U ( if SIDE = 'R' ),\n*> or by U A U' ( if SIDE = 'C' or 'T').\n*> \\endverbatim\n*>\n*> \\param[in] LDA\n*> \\verbatim\n*> LDA is INTEGER\n*> The leading dimension of the array A. LDA >= max(1,M).\n*> \\endverbatim\n*>\n*> \\param[in,out] ISEED\n*> \\verbatim\n*> ISEED is INTEGER array, dimension (4)\n*> On entry ISEED specifies the seed of the random number\n*> generator. The array elements should be between 0 and 4095;\n*> if not they will be reduced mod 4096. Also, ISEED(4) must\n*> be odd. The random number generator uses a linear\n*> congruential sequence limited to small integers, and so\n*> should produce machine independent random numbers. The\n*> values of ISEED are changed on exit, and can be used in the\n*> next call to SLAROR to continue the same random number\n*> sequence.\n*> \\endverbatim\n*>\n*> \\param[out] X\n*> \\verbatim\n*> X is REAL array, dimension (3*MAX( M, N ))\n*> Workspace of length\n*> 2*M + N if SIDE = 'L',\n*> 2*N + M if SIDE = 'R',\n*> 3*N if SIDE = 'C' or 'T'.\n*> \\endverbatim\n*>\n*> \\param[out] INFO\n*> \\verbatim\n*> INFO is INTEGER\n*> An error flag. It is set to:\n*> = 0: normal return\n*> < 0: if INFO = -k, the k-th argument had an illegal value\n*> = 1: if the random numbers generated by SLARND are bad.\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee\n*> \\author Univ. of California Berkeley\n*> \\author Univ. of Colorado Denver\n*> \\author NAG Ltd.\n*\n*> \\date December 2016\n*\n*> \\ingroup real_matgen\n*\n* =====================================================================\n SUBROUTINE SLAROR( SIDE, INIT, M, N, A, LDA, ISEED, X, INFO )\n*\n* -- LAPACK auxiliary routine (version 3.7.0) --\n* -- LAPACK is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n* December 2016\n*\n* .. Scalar Arguments ..\n CHARACTER INIT, SIDE\n INTEGER INFO, LDA, M, N\n* ..\n* .. Array Arguments ..\n INTEGER ISEED( 4 )\n REAL A( LDA, * ), X( * )\n* ..\n*\n* =====================================================================\n*\n* .. Parameters ..\n REAL ZERO, ONE, TOOSML\n PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0,\n $ TOOSML = 1.0E-20 )\n* ..\n* .. Local Scalars ..\n INTEGER IROW, ITYPE, IXFRM, J, JCOL, KBEG, NXFRM\n REAL FACTOR, XNORM, XNORMS\n* ..\n* .. External Functions ..\n LOGICAL LSAME\n REAL SLARND, SNRM2\n EXTERNAL LSAME, SLARND, SNRM2\n* ..\n* .. External Subroutines ..\n EXTERNAL SGEMV, SGER, SLASET, SSCAL, XERBLA\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC ABS, SIGN\n* ..\n* .. Executable Statements ..\n*\n INFO = 0\n IF( N.EQ.0 .OR. M.EQ.0 )\n $ RETURN\n*\n ITYPE = 0\n IF( LSAME( SIDE, 'L' ) ) THEN\n ITYPE = 1\n ELSE IF( LSAME( SIDE, 'R' ) ) THEN\n ITYPE = 2\n ELSE IF( LSAME( SIDE, 'C' ) .OR. LSAME( SIDE, 'T' ) ) THEN\n ITYPE = 3\n END IF\n*\n* Check for argument errors.\n*\n IF( ITYPE.EQ.0 ) THEN\n INFO = -1\n ELSE IF( M.LT.0 ) THEN\n INFO = -3\n ELSE IF( N.LT.0 .OR. ( ITYPE.EQ.3 .AND. N.NE.M ) ) THEN\n INFO = -4\n ELSE IF( LDA.LT.M ) THEN\n INFO = -6\n END IF\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'SLAROR', -INFO )\n RETURN\n END IF\n*\n IF( ITYPE.EQ.1 ) THEN\n NXFRM = M\n ELSE\n NXFRM = N\n END IF\n*\n* Initialize A to the identity matrix if desired\n*\n IF( LSAME( INIT, 'I' ) )\n $ CALL SLASET( 'Full', M, N, ZERO, ONE, A, LDA )\n*\n* If no rotation possible, multiply by random +/-1\n*\n* Compute rotation by computing Householder transformations\n* H(2), H(3), ..., H(nhouse)\n*\n DO 10 J = 1, NXFRM\n X( J ) = ZERO\n 10 CONTINUE\n*\n DO 30 IXFRM = 2, NXFRM\n KBEG = NXFRM - IXFRM + 1\n*\n* Generate independent normal( 0, 1 ) random numbers\n*\n DO 20 J = KBEG, NXFRM\n X( J ) = SLARND( 3, ISEED )\n 20 CONTINUE\n*\n* Generate a Householder transformation from the random vector X\n*\n XNORM = SNRM2( IXFRM, X( KBEG ), 1 )\n XNORMS = SIGN( XNORM, X( KBEG ) )\n X( KBEG+NXFRM ) = SIGN( ONE, -X( KBEG ) )\n FACTOR = XNORMS*( XNORMS+X( KBEG ) )\n IF( ABS( FACTOR ).LT.TOOSML ) THEN\n INFO = 1\n CALL XERBLA( 'SLAROR', INFO )\n RETURN\n ELSE\n FACTOR = ONE / FACTOR\n END IF\n X( KBEG ) = X( KBEG ) + XNORMS\n*\n* Apply Householder transformation to A\n*\n IF( ITYPE.EQ.1 .OR. ITYPE.EQ.3 ) THEN\n*\n* Apply H(k) from the left.\n*\n CALL SGEMV( 'T', IXFRM, N, ONE, A( KBEG, 1 ), LDA,\n $ X( KBEG ), 1, ZERO, X( 2*NXFRM+1 ), 1 )\n CALL SGER( IXFRM, N, -FACTOR, X( KBEG ), 1, X( 2*NXFRM+1 ),\n $ 1, A( KBEG, 1 ), LDA )\n*\n END IF\n*\n IF( ITYPE.EQ.2 .OR. ITYPE.EQ.3 ) THEN\n*\n* Apply H(k) from the right.\n*\n CALL SGEMV( 'N', M, IXFRM, ONE, A( 1, KBEG ), LDA,\n $ X( KBEG ), 1, ZERO, X( 2*NXFRM+1 ), 1 )\n CALL SGER( M, IXFRM, -FACTOR, X( 2*NXFRM+1 ), 1, X( KBEG ),\n $ 1, A( 1, KBEG ), LDA )\n*\n END IF\n 30 CONTINUE\n*\n X( 2*NXFRM ) = SIGN( ONE, SLARND( 3, ISEED ) )\n*\n* Scale the matrix A by D.\n*\n IF( ITYPE.EQ.1 .OR. ITYPE.EQ.3 ) THEN\n DO 40 IROW = 1, M\n CALL SSCAL( N, X( NXFRM+IROW ), A( IROW, 1 ), LDA )\n 40 CONTINUE\n END IF\n*\n IF( ITYPE.EQ.2 .OR. ITYPE.EQ.3 ) THEN\n DO 50 JCOL = 1, N\n CALL SSCAL( M, X( NXFRM+JCOL ), A( 1, JCOL ), 1 )\n 50 CONTINUE\n END IF\n RETURN\n*\n* End of SLAROR\n*\n END\n", "meta": {"hexsha": "d58902110f2a5e1a9e56e6efe7d16637e75d9196", "size": 9057, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "lapack-netlib/TESTING/MATGEN/slaror.f", "max_stars_repo_name": "drhpc/OpenBLAS", "max_stars_repo_head_hexsha": "9721b57ecfd194f1a4aaa08d715735cd9e8ad8b6", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 4392, "max_stars_repo_stars_event_min_datetime": "2015-01-02T18:15:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T12:14:38.000Z", "max_issues_repo_path": "lapack-netlib/TESTING/MATGEN/slaror.f", "max_issues_repo_name": "drhpc/OpenBLAS", "max_issues_repo_head_hexsha": "9721b57ecfd194f1a4aaa08d715735cd9e8ad8b6", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2067, "max_issues_repo_issues_event_min_datetime": "2015-01-01T03:50:01.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T18:59:43.000Z", "max_forks_repo_path": "lapack-netlib/TESTING/MATGEN/slaror.f", "max_forks_repo_name": "drhpc/OpenBLAS", "max_forks_repo_head_hexsha": "9721b57ecfd194f1a4aaa08d715735cd9e8ad8b6", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1564, "max_forks_repo_forks_event_min_datetime": "2015-01-01T01:32:27.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T07:12:54.000Z", "avg_line_length": 29.6950819672, "max_line_length": 76, "alphanum_fraction": 0.497957381, "num_tokens": 2798, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513842182777, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6842733847369752}} {"text": "REAL*8 Function Romb(y,N,dx)\n IMPLICIT NONE\n REAL*8, intent(in) :: y(N)\n REAL*8, intent(in) :: dx\n INTEGER, intent(in):: N\n ! locals\n INTEGER :: Ninterv, ni, k, istart, istop, istep, i, j, nn\n REAL*8, allocatable:: R(:,:)\n REAL*8 :: h, dsum\n !maybe we should use JISHFT instead of ISHFT!\n !\n Ninterv = N-1\n h = Ninterv*dx\n ni = 1\n k = 0\n do while(ni.LT.Ninterv)\n ni = ISHFT(ni,1)\n k = k+1\n enddo\n \n allocate( R(k+1,k+1) )\n \n R(1,1) = (y(1) + y(N))/2.0*h\n \n istart = Ninterv\n istop = Ninterv\n istep = Ninterv\n do i=2,k\n istart = ISHFT(istart,-1)\n\n dsum=0.0\n do j=istart,istop-1,istep\n dsum = dsum + y(j+1)\n enddo\n \n istep = ISHFT(istep,-1)\n \n R(i,1) = 0.5*(R(i-1,1) + h*dsum)\n\n do j=2,i\n nn = ISHFT(1, (2*(j-1)))\n R(i,j) = R(i,j-1) + (R(i,j-1)-R(i-1,j-1))/(nn-1.)\n enddo\n h = h/2.0\n enddo\n Romb = R(k,k)\n deallocate( R)\n return\nEND Function Romb\n", "meta": {"hexsha": "4af87e29071698b13efc48cec5b9fb412b061d68", "size": 954, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/dmft2/romb.f90", "max_stars_repo_name": "dmft-wien2k/dmft-wien2k-v2", "max_stars_repo_head_hexsha": "83481be27e8a9ff14b9635d6cc1cd9d96f053487", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2018-04-03T06:37:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-08T11:44:06.000Z", "max_issues_repo_path": "src/dmft2/romb.f90", "max_issues_repo_name": "dmft-wien2k/dmft-wien2k-v2", "max_issues_repo_head_hexsha": "83481be27e8a9ff14b9635d6cc1cd9d96f053487", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2016-07-12T21:37:53.000Z", "max_issues_repo_issues_event_max_datetime": "2016-07-12T21:42:01.000Z", "max_forks_repo_path": "src/dmft2/romb.f90", "max_forks_repo_name": "dmft-wien2k/dmft-wien2k", "max_forks_repo_head_hexsha": "83481be27e8a9ff14b9635d6cc1cd9d96f053487", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-10-27T20:23:34.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-13T13:54:11.000Z", "avg_line_length": 19.08, "max_line_length": 59, "alphanum_fraction": 0.5115303983, "num_tokens": 430, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513842182775, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6842733799137146}} {"text": " Program dstevr_example\n\n! DSTEVR Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_example_aux, Only: nagf_file_print_matrix_real_gen\n Use lapack_interfaces, Only: dstevr\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Real (Kind=dp), Parameter :: zero = 0.0_dp\n Integer, Parameter :: nin = 5, nout = 6\n! .. Local Scalars ..\n Real (Kind=dp) :: abstol, vl, vu\n Integer :: ifail, il, info, iu, ldz, liwork, lwork, m, n\n! .. Local Arrays ..\n Real (Kind=dp), Allocatable :: d(:), e(:), w(:), work(:), z(:, :)\n Real (Kind=dp) :: rdum(1)\n Integer :: idum(1)\n Integer, Allocatable :: isuppz(:), iwork(:)\n! .. Intrinsic Procedures ..\n Intrinsic :: max, nint\n! .. Executable Statements ..\n Write (nout, *) 'DSTEVR Example Program Results'\n Write (nout, *)\n! Skip heading in data file and read N and the lower and upper\n! indices of the eigenvalues to be found\n Read (nin, *)\n Read (nin, *) n, il, iu\n ldz = n\n m = n\n Allocate (d(n), e(n-1), w(n), z(ldz,m), isuppz(2*n))\n\n! Use routine workspace query to get optimal workspace.\n lwork = -1\n liwork = -1\n Call dstevr('Vectors', 'Indices', n, d, e, vl, vu, il, iu, abstol, m, w, &\n z, ldz, isuppz, rdum, lwork, idum, liwork, info)\n\n! Make sure that there is enough workspace for block size nb.\n lwork = max(20*n, nint(rdum(1)))\n liwork = max(10*n, idum(1))\n Allocate (work(lwork), iwork(liwork))\n\n! Read the diagonal and off-diagonal elements of the matrix A\n! from data file\n\n Read (nin, *) d(1:n)\n Read (nin, *) e(1:n-1)\n\n! Set the absolute error tolerance for eigenvalues. With ABSTOL\n! set to zero, the default value is used instead\n\n abstol = zero\n\n! Solve the symmetric tridiagonal eigenvalue problem\n Call dstevr('Vectors', 'Indices', n, d, e, vl, vu, il, iu, abstol, m, w, &\n z, ldz, isuppz, work, lwork, iwork, liwork, info)\n\n If (info==0) Then\n\n! Print solution\n\n Write (nout, *) 'Selected eigenvalues'\n Write (nout, 100) w(1:m)\n Flush (nout)\n\n! ifail: behaviour on error exit\n! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft\n ifail = 0\n Call nagf_file_print_matrix_real_gen('General', ' ', n, m, z, ldz, &\n 'Selected eigenvectors', ifail)\n\n Else\n Write (nout, 110) 'Failure in DSTEVR. INFO =', info\n End If\n\n100 Format (3X, (8F8.4))\n110 Format (1X, A, I5)\n End Program\n", "meta": {"hexsha": "343e016f94051350e529263345806abd1a2ded36", "size": 2798, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/dstevr_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/dstevr_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/dstevr_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 32.5348837209, "max_line_length": 90, "alphanum_fraction": 0.5868477484, "num_tokens": 869, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336204, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6842733666274985}} {"text": "module geo3x3\n implicit none\ncontains\n character(50) function geo3x3_encode(lat, lng, level)\n real lat\n real lng\n integer level\n\n real flat\n real flng\n real unit\n integer i, x, y\n\n flat = lat\n flng = lng\n if (lng >= 0.0) then\n geo3x3_encode = \"E\"\n else\n geo3x3_encode = \"W\"\n flng = flng + 180.0\n end if\n flat = flat + 90.0\n unit = 180.0\n do i = 1, level - 1\n unit = unit / 3\n x = floor(flng / unit)\n y = floor(flat / unit)\n geo3x3_encode(i + 1: i + 1) = char(x + y * 3 + 1 + 48)\n flng = flng - x * unit\n flat = flat - y * unit\n end do\n !geo3x3_encode = \"W\"\n end\n\n function geo3x3_decode(code)\n character(len=*) code\n real geo3x3_decode(4)\n\n real lat\n real lng\n real level\n real unit\n integer flg, i, n\n\n lat = 0.0\n lng = 0.0\n level = 0\n unit = 180.0\n\n if (len(code) > 0) then\n flg = 0\n if (code(1:1) == \"W\") then\n flg = 1\n end if\n level = level + 1\n do i = 2, len(code)\n n = index(\"123456789\", code(i:i)) - 1\n if (n >= 0) then\n unit = unit / 3\n lng = lng + mod(n, 3) * unit\n lat = lat + n / 3 * unit\n level = level + 1\n end if\n end do\n\n lat = lat + unit / 2\n lng = lng + unit / 2\n lat = lat - 90\n if (flg == 1) then\n lng = lng - 180.0\n end if\n end if\n geo3x3_decode = [lat, lng, level, unit]\n end\nend\n", "meta": {"hexsha": "b84e1b77d52bdf9329bf337ca68dd1bbb1fd37c4", "size": 1470, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "geo3x3.f90", "max_stars_repo_name": "yrm006/Geo3x3", "max_stars_repo_head_hexsha": "269124682b307e0e8b100d179e3bf21d931df722", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2021-02-20T12:53:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-07T02:56:21.000Z", "max_issues_repo_path": "geo3x3.f90", "max_issues_repo_name": "yrm006/Geo3x3", "max_issues_repo_head_hexsha": "269124682b307e0e8b100d179e3bf21d931df722", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 22, "max_issues_repo_issues_event_min_datetime": "2021-02-21T03:44:34.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-27T13:32:24.000Z", "max_forks_repo_path": "geo3x3.f90", "max_forks_repo_name": "yrm006/Geo3x3", "max_forks_repo_head_hexsha": "269124682b307e0e8b100d179e3bf21d931df722", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2021-02-20T23:51:46.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T13:20:41.000Z", "avg_line_length": 19.3421052632, "max_line_length": 60, "alphanum_fraction": 0.4891156463, "num_tokens": 548, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513675912912, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6842733623960202}} {"text": "SUBROUTINE fdwvnum (hbot, omega, kinf, ulen, grav, nu)\n!\n! This subroutine takes the dimensional (SI) values of omega, infinite\n! depth wavenumber kinf, and depth hbot, and returns the non-dimensional\n! finite depth wavenumber nu*ulen.\n!\n IMPLICIT NONE\n INTEGER, PARAMETER :: long=SELECTED_REAL_KIND(12,99)\n REAL(kind=long) hbot, ulen, omega, grav, nu, r0, hi, hh, his, his2, his4, &\n his8, h, twoh, fourh, kinf, rh, r0h, fh, sh, bigh, smlh, bigexp, &\n e2h\n DATA smlh / 1.d-05 /, bigh / 1.d+05 /, bigexp / 30.0d00 /\n\n h = hbot * kinf\n\n IF (h.lt.smlh) THEN\n nu = ulen * omega / SQRT (grav * hbot)\n ELSEIF (h.gt.bigh) THEN\n nu = ulen * kinf\n ELSE\n hi = 1. / h\n twoh = h + h\n fourh = twoh + twoh\n hh = h * h\n his = hi * hi\n his2 = his + his\n his4 = his2 + his2\n his8 = his4 + his4\n!\n! Evaluation of real root R0H of R0H*TANH(R0H)=H\n!\n e2h = EXP ( - MIN (twoh, bigexp) )\n IF (h.le.2.d00) THEN\n r0h = SQRT (h) * ( (.031d00 * h + .169d00) * h + 1.d00)\n ELSE\n r0h = h + h * e2h * (2.d00 - 12.d00 * e2h)\n ENDIF\n IF (h.le.4.8d00) THEN\n rh = hh - r0h * r0h\n sh = 1.d00 / (h - rh)\n fh = sh * (.5d00 * LOG ( (r0h + h) / (r0h - h) ) - r0h)\n r0h = r0h - fh * rh * (1.d00 + fh * r0h * h * sh)\n ENDIF\n nu = r0h * hi * kinf * ulen\n ENDIF\n RETURN\nEND SUBROUTINE fdwvnum\n", "meta": {"hexsha": "f9322bcee3e4388411f324db329b9b2696aa068e", "size": 1392, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/utilities/fdwvnum.f90", "max_stars_repo_name": "apengsigkarup/OceanWave3D", "max_stars_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 46, "max_stars_repo_stars_event_min_datetime": "2016-01-08T12:36:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T06:56:45.000Z", "max_issues_repo_path": "src/utilities/fdwvnum.f90", "max_issues_repo_name": "apengsigkarup/OceanWave3D", "max_issues_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-10-10T19:45:08.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-07T07:37:11.000Z", "max_forks_repo_path": "src/utilities/fdwvnum.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.0, "max_line_length": 83, "alphanum_fraction": 0.5416666667, "num_tokens": 584, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070133672954, "lm_q2_score": 0.7520125848754472, "lm_q1q2_score": 0.6842615251186379}} {"text": "subroutine calc_dxyz(ib,jb,kb,rr,imt,jmt,km,dzt,dxdy,dxyz)\n!====================================================================\n! calculate the grid cell volume at the drifter's location\n!\n! Input:\n! ib,jb,kb : new position in grid space indices\n! rr : time interpolation constant between 0 and 1. Controls how much\n! : of earlier time step is used in interpolation.\n! imt,jmt,km : grid index sizing constants in (x,y,z), are for \n! horizontal and vertical rho grid [scalar]\n! dzt : Height of k-cells in 3 dim in meters on rho vertical grid. [imt,jmt,km]\n! dxdy : Area of horizontal cell-walls [imt,jmt]\n!\n! Output:\n! dxyz : Volume of drifter's grid cell\n!\n! Other parameters used in function:\n! rg : rg=1-rr for time interpolation between time steps. Controls how much\n! : of later time step is used in interpolation.\n! nsm=1,nsp=2 : Time index. nsm picks out the earlier bounding time step and \n! nsp picks out the later bounding time step for interpolation.\n!\n! Notes:\n! KMT: Assuming zgrid3Dt flag which includes free surface already, I think. Other \n! flags aren't set up in the allocations or in the input variables,\n! for example, hs is not currently input since it is already included in \n! the dzt.\n!====================================================================\n\nimplicit none\n\ninteger, intent(in) :: ib,jb,kb,km,jmt,imt\nreal(kind=8), intent(in), dimension(imt,jmt,km,2) :: dzt\nreal(kind=8), intent(in), dimension(imt,jmt) :: dxdy\nreal(kind=8), intent(in) :: rr\nreal(kind=8), intent(out) :: dxyz\nreal(kind=8) :: rg\ninteger :: nsm=1,nsp=2\n\n\nrg=1.d0-rr\n\n! T-box volume in m3\ndxyz=rg*dzt(ib,jb,kb,nsp)+rr*dzt(ib,jb,kb,nsm)\ndxyz=dxyz*dxdy(ib,jb)\n\nend subroutine calc_dxyz\n", "meta": {"hexsha": "477d7f121c8ff93a371b008d59363ec20aa91c0c", "size": 2145, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/calc_dxyz.f95", "max_stars_repo_name": "dcherian/tracpy", "max_stars_repo_head_hexsha": "222db3e69f792dbc2732350bc7d266441d7b7a73", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 20, "max_stars_repo_stars_event_min_datetime": "2015-06-22T17:20:14.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-14T11:36:42.000Z", "max_issues_repo_path": "src/calc_dxyz.f95", "max_issues_repo_name": "dcherian/tracpy", "max_issues_repo_head_hexsha": "222db3e69f792dbc2732350bc7d266441d7b7a73", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-06-04T22:43:02.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-03T16:33:47.000Z", "max_forks_repo_path": "src/calc_dxyz.f95", "max_forks_repo_name": "dcherian/tracpy", "max_forks_repo_head_hexsha": "222db3e69f792dbc2732350bc7d266441d7b7a73", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2015-05-09T19:10:24.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-17T13:21:42.000Z", "avg_line_length": 44.6875, "max_line_length": 93, "alphanum_fraction": 0.5202797203, "num_tokens": 525, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070133672955, "lm_q2_score": 0.7520125793176223, "lm_q1q2_score": 0.6842615200615342}} {"text": " subroutine pzcon(cnvrsn,grav,dynz,prsdb,depth)\n!http://sam.ucsd.edu/sio210/propseawater/ppsw_fortran/pzcon.f\nc\nc title:\nc *****\nc\nc pzcon -- convert pressure in decibars to depth in meters\nc (or visa versa)\nc\nc system:\nc ******\nc\nc pacodf hydrographic data library\nc\nc purpose:\nc *******\nc\nc to calculate depth in meters (mantyla,saunders)\nc from pressure in decibars (or pressure from depth).\nc\nc ref: journ. physical ocean.,vol 11 no. 4, april, 1981\nc (saunders)\nc private correspondence 1982-1983\nc (mantyla)\nc\nc method:\nc ******\nc\nc a standard ocean (salinity=35.0,t=0.0) is used plus a dynamic\nc height correction to account for deviations from the standard\nc ocean. pressure to depth conversion is effected as:\nc\nc z = p/(b*c) + dynz/b\nc\nc where:\nc\nc p = insitu pressure (decibars)\nc b = insitu gravity as a function of latitude and pressure\nc (decameters/sec/sec)\nc c = insitu mean density rho(35.0,0.0,p)\nc (grams/centimeter**3)\nc dynz = dynamic height in dynamic meters\nc z = depth in meters\nc\nc parameters:\nc **********\nc\nc cnvrsn -> conversion to be performed:\nc 0 = pressure to depth\nc 1 = depth to pressure\nc grav -> acceleration of gravity meters/sec/sec\nc at station latitude, pressure =0.0db\nc dynz -> dynamic height in dynamic meters\nc prsdb -> pressure in decibars (cnvrsn=0)\nc <- pressure in decibars (cnvrsn=1)\nc depth <- depth in meters (cnvrsn=0)\nc -> depth in meters (cnvrsn=1)\nc\n integer cnvrsn\n real grav,prsdb,dynz,depth\nc\nc variables:\nc *********\nc\n real*4 a,b,c\n real*8 dd,dg,dh,da,db,dc\nc\nc external functions:\nc ******** *********\nc\n integer isnan\nc\t /* test for Not-A-Number */\nc\nc code:\nc ****\nc\nc select\nc (convert pressure to depth):\n if(cnvrsn.ne.0) go to 10\n a = 2.2e-6*prsdb\nc /* pressure correction to gravity */\n b = 0.1*(grav+0.5*a)\nc /* insitu gravity decameters/sec/sec */\nc\n c = 1.0285+a\nc /* insitu mean density rho(35.0,0.0,p) */\nc\n depth = prsdb/(b*c)\nc /* pressure to depth conversion in standard ocean */\nc\nc select\nc (dynamic height):\n if(isnan(dynz).eq.0)\n 1 depth = depth + dynz/b\nc (otherwise):\nc end select\n go to 999\nc (convert depth to pressure):\n 10 continue\n dd = dble(depth)\n dg = dble(grav*0.1)\n dh = dble(dynz)\n da = 2.42d-13*dd\n db = dd*(1.13135d-7+2.2e-6*dg)-1.0\n dc = dg*dd\nc select\nc (dynamic height):\n if(isnan(dynz).ne.0) go to 20\n db = db - 2.2d-6*dh\n dc = dc-dh\nc (otherwise):\n 20 continue\nc end select\nc\n dc = 1.0285d0*dc\nc\n prsdb = 0.0\n if(da.ne.0.0)\n 1 prsdb = sngl((-db-dsqrt(db*db-4.0d0*da*dc))/(da+da))\nc end select\nc\nc /* return */\nc\n 999 continue\nc\n return\nc\nc end pzcon\nc\n end\n", "meta": {"hexsha": "038f98914f2dea90bb5ad6e4712dd7d0d6ac3673", "size": 3361, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/obs/HOLD/pzcon.f", "max_stars_repo_name": "GEOS-ESM/Ocean-LETKF", "max_stars_repo_head_hexsha": "a7c4bbf86cdbff078212914dcc059d0b1450accf", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-12-31T15:40:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-03T13:44:20.000Z", "max_issues_repo_path": "src/obs/HOLD/pzcon.f", "max_issues_repo_name": "GEOS-ESM/Ocean-LETKF", "max_issues_repo_head_hexsha": "a7c4bbf86cdbff078212914dcc059d0b1450accf", "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/obs/HOLD/pzcon.f", "max_forks_repo_name": "GEOS-ESM/Ocean-LETKF", "max_forks_repo_head_hexsha": "a7c4bbf86cdbff078212914dcc059d0b1450accf", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-14T18:46:56.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-14T18:46:56.000Z", "avg_line_length": 25.6564885496, "max_line_length": 71, "alphanum_fraction": 0.5177030646, "num_tokens": 1050, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6842615131672014}} {"text": "PROGRAM wave2D\n\n!*****************************************!\n!* 2d shallow-Water model *!\n!* *!\n!* including: *!\n!* - horizontal pressure-gradient force *!\n!* - Shapiro filter *!\n!* - flooding algorithm *!\n!* *!\n!* Author: J. Kaempf, 2008 *!\n!*****************************************!\n\nUSE param\nUSE sub\n\n\n\nINTEGER j,k\n\nINTEGER wet(0:ny+1,0:nx+1)\nREAL hmin, c, lambda\n\n! local parameters\nREAL hmax,time\nINTEGER n,ntot,nout\n\n!**********\nCALL INIT ! initialisation\n!**********\n! output of initial eta distribution\nOPEN(10,file ='eta0.dat',form='formatted')\n DO j = 1,ny\n WRITE(10,'(101F12.6)')(eta(j,k),k=1,nx)\n END DO\nCLOSE(10)\n\n! output of initial layer thickness distribution\nOPEN(10,file ='h0.dat',form='formatted')\n DO j = 1,ny\n WRITE(10,'(101F12.6)')(hzero(j,k),k=1,nx)\n END DO\nCLOSE(10)\n\n! set local parameters\n\n! set epsilon for Shapiro filter\neps = 0.05\n\n! runtime parameters\nntot = 1000\n\n! output parameter\nnout = 5\n\n! determine maximum water depth\nhmax = 0.\n\nDO j = 1,ny\nDO k = 1,nx\n hmax = MAX(hmax,h(j,k))\nEND DO\nEND DO\n\n! maximum phase speed\nc = SQRT(2*g*hmax)\n\n! determine stability parameter\nprint *,dt,g,hmax,dx,dy\n\nlambda = dt*SQRT(g*hmax)/MIN(dx,dy)\nprint *,\"LAMBDA:\",lambda\nIF(lambda > 1)THEN\n WRITE(6,*) \"This will not work. Do you know why?\" \n STOP\nEND IF\n\n#ifndef NO_IO\n! open files for output\nOPEN(10,file ='eta.dat',form='formatted')\nOPEN(20,file ='h.dat',form='formatted')\nOPEN(30,file ='u.dat',form='formatted')\nOPEN(40,file ='v.dat',form='formatted')\n#endif\n\nDO j = 26,26\nDO k = 26,26\neta(j,k) = 1.0 \nEND DO\nEND DO\n\n!---------------------------\n! simulation loop\n!---------------------------\nDO n = 1,ntot\n\ntime = REAL(n)*dt\n\n! call predictor\nCALL dyn\n\n! updating including Shapiro filter\n\nCALL shapiro\n\nDO j = 0,ny+1\nDO k = 0,nx+1\n h(j,k) = hzero(j,k) + eta(j,k)\n wet(j,k) = 1\n IF(h(j,k) @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief everything that has to do with rotations and conversions between rotations\n!\n!> @details This file relies a lot on the relations listed in the book \"Orientations\n!> and Rotations\" by Adam Morawiec [Springer 2004]. I've tried to implement every\n!> available representation for rotations in a way that makes it easy to convert \n!> between any pair. Needless to say, this needs extensive testing and debugging...\n!>\n!> Instead of converting all the time between representations, I've opted to \n!> \"waste\" a little more memory and time and provide the option to precompute all the representations.\n!> This way all representations are available via a single data structure.\n!>\n!> Obviously, the individual conversion routines also exist and can be called either in\n!> single or in double precision (using a function interface for each call, so that only\n!> one function name is used). The conversion routines use the following format for their\n!> call name: ab2cd, where (ab and cd are two-characters strings selected from the following\n!> possibilities: [the number in parenthesis lists the number of entries that need to be provided] \n!>\n!> eu : euler angle representation (3)\n!> om : orientation matrix representation (3x3)\n!> ax : axis angle representation (4)\n!> ro : Rodrigues vector representation (3)\n!> qu : unit quaternion representation (4)\n!> ho : homochoric representation (3)\n!> cu : cubochoric representation (3)\n!> st : 3D stereographic representation (3) [added in October 2017]\n!> rv : rotation vector representation (3) [added in Summer 2019]\n!>\n!> hence, conversion from homochoric to euler angle is called as ho2eu(); the argument of \n!> each routine must have the correct number of dimensions and entries.\n!> All 42 conversion routines exist in both single and double precision.\n!>\n!> Some routines were modified in July 2014, to simplify the paths in case the direct conversion\n!> routine does not exist. Given the complexity of the cubochoric transformations, all routines\n!> going to and from this representation will require at least one and sometimes two or three\n!> intermediate representations. cu2eu and qu2cu currently represent the longest computation \n!> paths with three intermediate steps each.\n!>\n!> In August 2014, all routines were modified to account for active vs. passive rotations,\n!> after some inconsistencies were discovered that could be traced back to that distinction.\n!> The default is for a rotation to be passive, and only those transformation rules have been\n!> implemented. For active rotations, the user needs to explicitly take action in the calling \n!> program.\n!>\n!> Testing: the program rotationtest.f90 was generated by an IDL script and contains all possible\n!> pairwise and triplet transformations, using a series of input angle combinations; for now, these\n!> are potentially problematic Euler combinations.\n!>\n!> The conventions of this module are:\n!>\n!> - all reference frames are right-handed and orthonormal (except for the Bravais frames)\n!> - a rotation angle is positive for a counterclockwise rotation when viewing along the positive rotation axis towards the origin\n!> - all rotations are interpreted in the passive way\n!> - Euler angles follow the Bunge convention, with phi1 in [0,2pi], Phi in [0,pi], and phi2 in [0,2pi]\n!> - rotation angles (in axis-angle derived representations) are limited to the range [0,pi]\n!> \n!> To make things easier for the user, this module provides a routine to create a rotation \n!> representation starting from an axis, described by a unit axis vector, and a rotation angle.\n!> This routine properly takes the sign of epsijk into account, and always produces a passive rotation.\n!> The user must explicitly take action to interpret a rotation a being active.\n!>\n!> @date 08/04/13 MDG 1.0 original\n!> @date 07/08/14 MDG 2.0 modifications to several routines (mostly simplifications)\n!> @date 08/08/14 MDG 3.0 added active/passive handling (all routines passive)\n!> @date 08/11/14 MDG 3.1 modified Rodrigues vector to 4 components (n and length) to accomodate Infinity\n!> @date 08/18/14 MDG 3.2 added RotateVector, RotateTensor2 routines with active/passive switch\n!> @date 08/20/14 MDG 3.3 completed extensive testing of epsijk<0 mode; all tests passed for the first time !\n!> @date 08/21/14 MDG 3.4 minor correction in om2ax to get things to work for epsijk>0 mode; all tests passed!\n!> @date 09/30/14 MDG 3.5 added routines to make rotation definitions easier\n!> @date 09/30/14 MDG 3.6 added strict range checking routines for all representations (tested on 10/1/14)\n!> @date 03/11/15 MDG 3.7 removed the RotVec_q routine, since it is surpassed by the new quat_Lp and quat_Lpstar routines\n!> @date 03/12/15 MDG 3.8 correction of Rodrigues representation for identity rotation -> [0,0,epsijk,0]\n!> @date 03/16/15 MDG 3.9 added quat_average routine\n!> @date 04/17/15 MDG 3.91 simplification to qu2eu routines\n!> @date 09/23/15 MDG 3.92 changes to .eq. tests on reals; replaced all by close_enough calls\n!> @date 10/05/17 MDG 4.0 added 3D stereographic representation\n!> @date 10/29/19 SS 5.0 added rotation vector representation\n!> @date 10/31/19 MDG 5.1 replaced 'ex' notation by 'rv' for rotation vector\n!--------------------------------------------------------------------------\nmodule rotations\n\nuse local\nuse typedefs\nuse quaternions\nuse math\n\n\n!--------------------------------\n! routines to check the validity range of rotation representations\npublic :: eu_check\ninterface eu_check\n module procedure eu_check\n module procedure eu_check_d\nend interface \n\npublic :: ro_check\ninterface ro_check\n module procedure ro_check\n module procedure ro_check_d\nend interface \n\npublic :: ho_check\ninterface ho_check\n module procedure ho_check\n module procedure ho_check_d\nend interface \n\npublic :: cu_check\ninterface cu_check\n module procedure cu_check\n module procedure cu_check_d\nend interface \n\npublic :: qu_check\ninterface qu_check\n module procedure qu_check\n module procedure qu_check_d\nend interface \n\npublic :: ax_check\ninterface ax_check\n module procedure ax_check\n module procedure ax_check_d\nend interface \n\npublic :: om_check\ninterface om_check\n module procedure om_check\n module procedure om_check_d\nend interface \n\npublic :: st_check\ninterface st_check\n module procedure st_check\n module procedure st_check_d\nend interface \n\npublic :: rv_check\ninterface rv_check\n module procedure rv_check\n module procedure rv_check_d\nend interface \n!--------------------------------\n! general rotation creation routine, to make sure that a rotation representation is \n! correctly initialized, takes an axis and an angle as input, returns an orientationtype structure\npublic:: genrot\ninterface genrot\n module procedure genrot\n module procedure genrot_d\nend interface\n\n! general interface routine to populate the orientation type\npublic:: init_orientation\ninterface init_orientation\n module procedure init_orientation\n module procedure init_orientation_om\n module procedure init_orientation_d\n module procedure init_orientation_om_d\nend interface\n\n!--------------------------------\n! convert Euler angles to 3x3 orientation matrix\npublic :: eu2om\ninterface eu2om\n module procedure eu2om\n module procedure eu2om_d\nend interface\n\n! convert Euler angles to axis angle\npublic :: eu2ax\ninterface eu2ax\n module procedure eu2ax\n module procedure eu2ax_d\nend interface\n\n! convert Euler angles to Rodrigues vector\npublic :: eu2ro\ninterface eu2ro\n module procedure eu2ro\n module procedure eu2ro_d\nend interface\n\n! convert Euler angles to quaternion\npublic :: eu2qu\ninterface eu2qu\n module procedure eu2qu\n module procedure eu2qu_d\nend interface\n\n! convert Euler angles to homochoric\npublic :: eu2ho\ninterface eu2ho\n module procedure eu2ho\n module procedure eu2ho_d\nend interface\n\n! convert Euler angles to cubochoric\npublic :: eu2cu\ninterface eu2cu\n module procedure eu2cu\n module procedure eu2cu_d\nend interface\n\n! convert Euler angles to stereographic\npublic :: eu2st\ninterface eu2st\n module procedure eu2st\n module procedure eu2st_d\nend interface\n\n! convert Euler angles to rotation vector map\npublic :: eu2rv\ninterface eu2rv\n module procedure eu2rv\n module procedure eu2rv_d\nend interface\n\n!--------------------------------\n! convert 3x3 orientation matrix to Euler angles\npublic :: om2eu\ninterface om2eu\n module procedure om2eu\n module procedure om2eu_d\nend interface\n\n! convert 3x3 orientation matrix to axis angle\npublic :: om2ax\ninterface om2ax\n module procedure om2ax\n module procedure om2ax_d\nend interface\n\n! convert 3x3 orientation matrix to Rodrigues\npublic :: om2ro\ninterface om2ro\n module procedure om2ro\n module procedure om2ro_d\nend interface\n\n! convert 3x3 rotation matrix to quaternion\npublic :: om2qu\ninterface om2qu\n module procedure om2qu\n module procedure om2qu_d\nend interface\n\n! convert 3x3 rotation matrix to homochoric\npublic :: om2ho\ninterface om2ho\n module procedure om2ho\n module procedure om2ho_d\nend interface\n\n! convert 3x3 rotation matrix to cubochoric\npublic :: om2cu\ninterface om2cu\n module procedure om2cu\n module procedure om2cu_d\nend interface\n\n! convert 3x3 rotation matrix to stereographic\npublic :: om2st\ninterface om2st\n module procedure om2st\n module procedure om2st_d\nend interface\n\n! convert rotation matrix to rotation vector map\npublic :: om2rv\ninterface om2rv\n module procedure om2rv\n module procedure om2rv_d\nend interface\n\n!--------------------------------\n! convert axis angle pair to euler\npublic :: ax2eu\ninterface ax2eu\n module procedure ax2eu\n module procedure ax2eu_d\nend interface\n\n! convert axis angle pair to orientation matrix\npublic :: ax2om\ninterface ax2om\n module procedure ax2om\n module procedure ax2om_d\nend interface\n\n! convert axis angle pair to Rodrigues\npublic :: ax2ro\ninterface ax2ro\n module procedure ax2ro\n module procedure ax2ro_d\nend interface\n\n! convert axis angle pair to quaternion\npublic :: ax2qu\ninterface ax2qu\n module procedure ax2qu\n module procedure ax2qu_d\nend interface\n\n! convert axis angle pair to homochoric representation\npublic :: ax2ho\ninterface ax2ho\n module procedure ax2ho\n module procedure ax2ho_d\nend interface\n\n! convert axis angle pair to cubochoric\npublic :: ax2cu\ninterface ax2cu\n module procedure ax2cu\n module procedure ax2cu_d\nend interface\n\n! convert axis angle pair to stereographic\npublic :: ax2st\ninterface ax2st\n module procedure ax2st\n module procedure ax2st_d\nend interface\n\n! convert axis angle pair to rotation vector map\npublic :: ax2rv\ninterface ax2rv\n module procedure ax2rv\n module procedure ax2rv_d\nend interface\n\n!--------------------------------\n! convert Rodrigues vector to Euler angles\npublic :: ro2eu\ninterface ro2eu\n module procedure ro2eu\n module procedure ro2eu_d\nend interface\n\n! convert Rodrigues vector to orientation matrix\npublic :: ro2om\ninterface ro2om\n module procedure ro2om\n module procedure ro2om_d\nend interface\n\n! convert Rodrigues vector to axis angle pair\npublic :: ro2ax\ninterface ro2ax\n module procedure ro2ax\n module procedure ro2ax_d\nend interface\n\n! convert Rodrigues vector to quaternion\npublic :: ro2qu\ninterface ro2qu\n module procedure ro2qu\n module procedure ro2qu_d\nend interface\n\n! convert Rodrigues vector to homochoric\npublic :: ro2ho\ninterface ro2ho\n module procedure ro2ho\n module procedure ro2ho_d\nend interface\n\n! convert Rodrigues vector to cubochoric\npublic :: ro2cu\ninterface ro2cu\n module procedure ro2cu\n module procedure ro2cu_d\nend interface\n\n! convert Rodrigues vector to stereographic\npublic :: ro2st\ninterface ro2st\n module procedure ro2st\n module procedure ro2st_d\nend interface\n\n! convert Rodrigues vector to rotation vector map\npublic :: ro2rv\ninterface ro2rv\n module procedure ro2rv\n module procedure ro2rv_d\nend interface\n\n!--------------------------------\n! convert quaternion to Euler angles\npublic :: qu2eu\ninterface qu2eu\n module procedure qu2eu\n module procedure qu2eu_d\nend interface\n\n! convert quaternion to orientation matrix \npublic :: qu2om\ninterface qu2om\n module procedure qu2om\n module procedure qu2om_d\nend interface\n\n! convert quaternion to axis angle\npublic :: qu2ax\ninterface qu2ax\n module procedure qu2ax\n module procedure qu2ax_d\nend interface\n\n! convert quaternion to Rodrigues\npublic :: qu2ro\ninterface qu2ro\n module procedure qu2ro\n module procedure qu2ro_d\nend interface\n\n! convert quaternion to homochoric\npublic :: qu2ho\ninterface qu2ho\n module procedure qu2ho\n module procedure qu2ho_d\nend interface\n\n! convert quaternion to cubochoric\npublic :: qu2cu\ninterface qu2cu\n module procedure qu2cu\n module procedure qu2cu_d\nend interface\n\n! convert quaternion to stereographic\npublic :: qu2st\ninterface qu2st\n module procedure qu2st\n module procedure qu2st_d\nend interface\n\n! convert quaternion to rotation vector map\npublic :: qu2rv\ninterface qu2rv\n module procedure qu2rv\n module procedure qu2rv_d\nend interface\n\n!--------------------------------\n! convert homochoric to euler\npublic :: ho2eu\ninterface ho2eu\n module procedure ho2eu\n module procedure ho2eu_d\nend interface\n\n! convert homochoric to orientation matrix \npublic :: ho2om\ninterface ho2om\n module procedure ho2om\n module procedure ho2om_d\nend interface\n\n! convert homochoric to axis angle pair \npublic :: ho2ax\ninterface ho2ax\n module procedure ho2ax\n module procedure ho2ax_d\nend interface\n\n! convert homochoric to Rodrigues \npublic :: ho2ro\ninterface ho2ro\n module procedure ho2ro\n module procedure ho2ro_d\nend interface\n\n! convert homochoric to quaternion\npublic :: ho2qu\ninterface ho2qu\n module procedure ho2qu\n module procedure ho2qu_d\nend interface\n\n! convert homochoric to cubochoric\npublic :: ho2cu\ninterface ho2cu\n module procedure ho2cu\n module procedure ho2cu_d\nend interface\n\n! convert homochoric to steregraphic\npublic :: ho2st\ninterface ho2st\n module procedure ho2st\n module procedure ho2st_d\nend interface\n\n! convert homochoric to rotation vector map\npublic :: ho2rv\ninterface ho2rv\n module procedure ho2rv\n module procedure ho2rv_d\nend interface\n\n!--------------------------------\n! convert cubochoric to euler\npublic :: cu2eu\ninterface cu2eu\n module procedure cu2eu\n module procedure cu2eu_d\nend interface\n\n! convert cubochoric to orientation matrix\npublic :: cu2om\ninterface cu2om\n module procedure cu2om\n module procedure cu2om_d\nend interface\n\n! convert cubochoric to axis angle\npublic :: cu2ax\ninterface cu2ax\n module procedure cu2ax\n module procedure cu2ax_d\nend interface\n\n! convert cubochoric to Rodrigues\npublic :: cu2ro\ninterface cu2ro\n module procedure cu2ro\n module procedure cu2ro_d\nend interface\n\n! convert cubochoric to quaternion\npublic :: cu2qu\ninterface cu2qu\n module procedure cu2qu\n module procedure cu2qu_d\nend interface\n\n! convert cubochoric to homochoric\npublic :: cu2ho\ninterface cu2ho\n module procedure cu2ho\n module procedure cu2ho_d\nend interface\n\n! convert cubochoric to stereographic\npublic :: cu2st\ninterface cu2st\n module procedure cu2st\n module procedure cu2st_d\nend interface\n\n! convert cubochoric to rotation vector map\npublic :: cu2rv\ninterface cu2rv\n module procedure cu2rv\n module procedure cu2rv_d\nend interface\n\n!--------------------------------\n! convert stereographic to euler\npublic :: st2eu\ninterface st2eu\n module procedure st2eu\n module procedure st2eu_d\nend interface\n\n! convert stereographic to orientation matrix\npublic :: st2om\ninterface st2om\n module procedure st2om\n module procedure st2om_d\nend interface\n\n! convert stereographic to axis angle\npublic :: st2ax\ninterface st2ax\n module procedure st2ax\n module procedure st2ax_d\nend interface\n\n! convert stereographic to Rodrigues\npublic :: st2ro\ninterface st2ro\n module procedure st2ro\n module procedure st2ro_d\nend interface\n\n! convert stereographic to quaternion\npublic :: st2qu\ninterface st2qu\n module procedure st2qu\n module procedure st2qu_d\nend interface\n\n! convert stereographic to homochoric\npublic :: st2ho\ninterface st2ho\n module procedure st2ho\n module procedure st2ho_d\nend interface\n\n! convert stereographic to homochoric\npublic :: st2cu\ninterface st2cu\n module procedure st2cu\n module procedure st2cu_d\nend interface\n\n! convert stereographic to rotation vector map\npublic :: st2rv\ninterface st2rv\n module procedure st2rv\n module procedure st2rv_d\nend interface\n\n!-----------------------------------\n! rotation vector map to axis-angle pair\npublic :: rv2ax\ninterface rv2ax\n module procedure rv2ax\n module procedure rv2ax_d\nend interface\n\n! rotation vector map to quaternion\npublic :: rv2qu\ninterface rv2qu\n module procedure rv2qu\n module procedure rv2qu_d\nend interface\n\n! rotation vector map to euler\npublic :: rv2eu\ninterface rv2eu\n module procedure rv2eu\n module procedure rv2eu_d\nend interface\n\n! rotation vector map to rodrigues vector\npublic :: rv2ro\ninterface rv2ro\n module procedure rv2ro\n module procedure rv2ro_d\nend interface\n\n! rotation vector map to orientation matrix\npublic :: rv2om\ninterface rv2om\n module procedure rv2om\n module procedure rv2om_d\nend interface\n\n! rotation vector map to cubochoric vector\npublic :: rv2cu\ninterface rv2cu\n module procedure rv2cu\n module procedure rv2cu_d\nend interface\n\n! rotation vector map to stereographic vector\npublic :: rv2st\ninterface rv2st\n module procedure rv2st\n module procedure rv2st_d\nend interface\n\n! rotation vector map to homochoric vector\npublic :: rv2ho\ninterface rv2ho\n module procedure rv2ho\n module procedure rv2ho_d\nend interface\n\n!--------------------------------\n! Rodrigues vector product\npublic :: RodriguesProduct\ninterface RodriguesProduct\n module procedure RodriguesProduct\n module procedure RodriguesProduct_d\nend interface\n\n! apply a rotation to a vector\npublic :: RotateVector\ninterface RotateVector\n module procedure RotVec_om\n module procedure RotVec_om_d\nend interface\n\n! apply a rotation to a second rank tensor\npublic :: RotateTensor2\ninterface RotateTensor2\n module procedure RotTensor2_om\n module procedure RotTensor2_om_d\nend interface\n\n! average a list of quaternions \npublic :: quat_average\ninterface quat_average\n module procedure quat_average\n module procedure quat_average_d\nend interface\n\n!--------------------------------\n! print quaternion and equivalent 3x3 rotation matrix\npublic :: print_orientation\ninterface print_orientation\n module procedure print_orientation\n module procedure print_orientation_d\nend interface\n\n! numerical comparison test of two reals\nprivate :: close_enough\ninterface close_enough\n module procedure close_enough\n module procedure close_enough_d\nend interface\n\n\ncontains\n\n!--------------------------------------------------------------------------\n!\n! Function: close_enough\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief compares two reals and returns .TRUE. is they are closer than E-8 ! machine precision\n!\n!> @param a (single precision) \n!> @param b (single precision) \n! \n!> @date 9/23/15 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function close_enough(a,b) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: close_enough\n\nuse local\nuse constants\nuse error\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: a\nreal(kind=sgl),INTENT(IN) :: b\nlogical :: res\n\nreal(kind=sgl) :: eps = 1.E-08 ! epsilon(1.0) \n\nres = .FALSE.\nif (abs(a-b).lt.eps) res = .TRUE.\n\nend function close_enough\n\n!--------------------------------------------------------------------------\n!\n! Function: close_enough_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief compares two reals and returns .TRUE. is they are closer than D-12 ! machine precision\n!\n!> @param a (double precision) \n!> @param b (double precision) \n! \n!> @date 9/23/15 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function close_enough_d(a,b) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: close_enough_d\n\nuse local\nuse constants\nuse error\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: a\nreal(kind=dbl),INTENT(IN) :: b\nlogical :: res\n\nreal(kind=sgl) :: eps = 1.D-12 ! epsilon(1.0D0) \n\nres = .FALSE.\nif (dabs(a-b).lt.eps) res = .TRUE.\n\nend function close_enough_d\n\n\n\n!--------------------------------------------------------------------------\n!\n! Function: eu_check\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief verify that the Euler angles are in the correct respective ranges\n!\n!> @param eu 3-component vector (single precision) \n!> \n! \n!> @date 9/30/14 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function eu_check(eu) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: eu_check\n\nuse local\nuse constants\nuse error\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: eu(3)\n\ninteger(kind=irg) :: res\n\nres = 1\n\nif ((eu(1).lt.0.0).or.(eu(1).gt.(2.0*sngl(cPi)))) then \n call FatalError('rotations:eu_check','phi1 Euler angle outside of valid range [0,2pi]')\nendif\nif ((eu(2).lt.0.0).or.(eu(2).gt.cPi)) then \n call FatalError('rotations:eu_check','Phi Euler angle outside of valid range [0,pi]')\nendif\nif ((eu(3).lt.0.0).or.(eu(3).gt.(2.0*sngl(cPi)))) then \n call FatalError('rotations:eu_check','phi2 Euler angle outside of valid range [0,2pi]')\nendif\n\nres = 0\n\nend function eu_check\n\n!--------------------------------------------------------------------------\n!\n! Function: eu_check_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief verify that the Euler angles are in the correct respective ranges\n!\n!> @param eu 3-component vector (double precision) \n!> \n! \n!> @date 9/30/14 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function eu_check_d(eu) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: eu_check_d\n\nuse local\nuse constants\nuse error\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: eu(3)\n\ninteger(kind=irg) :: res\n\nres = 1\n\nif ((eu(1).lt.0.0).or.(eu(1).gt.(2.0*sngl(cPi)))) then \n call FatalError('rotations:eu_check_d','phi1 Euler angle outside of valid range [0,2pi]')\nendif\nif ((eu(2).lt.0.0).or.(eu(2).gt.cPi)) then \n call FatalError('rotations:eu_check_d','Phi Euler angle outside of valid range [0,pi]')\nendif\nif ((eu(3).lt.0.0).or.(eu(3).gt.(2.0*sngl(cPi)))) then \n call FatalError('rotations:eu_check_d','phi2 Euler angle outside of valid range [0,2pi]')\nendif\n\nres = 0\n\nend function eu_check_d\n\n!--------------------------------------------------------------------------\n!\n! Function: ro_check\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief verify that the Rodrigues vector has positive length and unit axis vector\n!\n!> @param ro 4-component vector (single precision) \n!> \n! \n!> @date 9/30/14 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ro_check(ro) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ro_check\n\nuse local\nuse constants\nuse error\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: ro(4)\n\ninteger(kind=irg) :: res\nreal(kind=sgl), parameter :: eps = 1.e-7\n\nres = 1\n\nif (ro(4).lt.0.0) then \n call FatalError('rotations:ro_check','Rodrigues-Frank vector has negative length')\nendif\nif (abs(sqrt(sum(ro(1:3)*ro(1:3)))-1.0).gt.eps) then\n call FatalError('rotations:ro_check','Rodrigues-Frank axis vector not normalized')\nendif\n\nres = 0\n\nend function ro_check\n\n!--------------------------------------------------------------------------\n!\n! Function: ro_check_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief verify that the Rodrigues vector has positive length and unit axis vector\n!\n!> @param ro 4-component vector (double precision) \n!> \n! \n!> @date 9/30/14 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ro_check_d(ro) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ro_check_d\n\nuse local\nuse constants\nuse error\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: ro(4)\n\ninteger(kind=irg) :: res\nreal(kind=dbl), parameter :: eps = 1.d-15\n\nres = 1\n\nif (ro(4).lt.0.0) then \n call FatalError('rotations:ro_check_d','Rodrigues-Frank vector has negative length')\nendif\nif (abs(sqrt(sum(ro(1:3)*ro(1:3)))-1.0).gt.eps) then\n call FatalError('rotations:ro_check_d','Rodrigues-Frank axis vector not normalized')\nendif\n\nres = 0\n\nend function ro_check_d\n\n!--------------------------------------------------------------------------\n!\n! Function: ho_check\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief verify that the homochoric vector is inside or on the homochoric ball\n!\n!> @param ho 3-component vector (single precision) \n!> \n! \n!> @date 9/30/14 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ho_check(ho) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ho_check\n\nuse local\nuse constants\nuse error\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: ho(3)\n\ninteger(kind=irg) :: res\nreal(kind=sgl) :: r\n\nres = 1\n\nr = sqrt(sum(ho*ho))\nif (r.gt.sngl(LPs%R1)) then\n call FatalError('rotations:ho_check','homochoric vector outside homochoric ball')\nendif\n\nres = 0\n\nend function ho_check\n\n!--------------------------------------------------------------------------\n!\n! Function: ho_check_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief verify that the homochoric vector is inside or on the homochoric ball\n!\n!> @param ho 3-component vector (double precision) \n!> \n! \n!> @date 9/30/14 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ho_check_d(ho) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ho_check_d\n\nuse local\nuse constants\nuse error\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: ho(3)\n\ninteger(kind=irg) :: res\nreal(kind=dbl) :: r\n\nres = 1\n\nr = dsqrt(sum(ho*ho))\nif (r.gt.LPs%R1) then\n call FatalError('rotations:ho_check_d','homochoric vector outside homochoric ball')\nendif\n\nres = 0\n\nend function ho_check_d\n\n!--------------------------------------------------------------------------\n!\n! Function: cu_check\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief verify that the cubochoric vector is inside or on the cube\n!\n!> @param cu 3-component vector (single precision) \n!> \n! \n!> @date 9/30/14 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function cu_check(cu) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: cu_check\n\nuse local\nuse constants\nuse error\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: cu(3)\n\ninteger(kind=irg) :: res\nreal(kind=sgl) :: r\n\nres = 1\n\nr = maxval(abs(cu))\nif (r.gt.sngl(LPs%ap/2.D0)) then\n call FatalError('rotations:cu_check','cubochoric vector outside cube')\nendif\n\nres = 0\n\nend function cu_check\n\n!--------------------------------------------------------------------------\n!\n! Function: cu_check_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief verify that the cubochoric vector is inside or on the cube\n!\n!> @param cu 3-component vector (double precision) \n!> \n! \n!> @date 9/30/14 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function cu_check_d(cu) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: cu_check_d\n\nuse local\nuse constants\nuse error\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: cu(3)\n\ninteger(kind=irg) :: res\nreal(kind=dbl) :: r\n\nres = 1\n\nr = maxval(dabs(cu))\nif (r.gt.(LPs%ap/2.D0)) then\n call FatalError('rotations:cu_check_d','cubochoric vector outside cube')\nendif\n\nres = 0\n\nend function cu_check_d\n\n!--------------------------------------------------------------------------\n!\n! Function: qu_check\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief verify that the quaternion has unit length and positive scalar part\n!\n!> @param qu 4-component vector (single precision) \n!> \n! \n!> @date 9/30/14 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function qu_check(qu) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: qu_check\n\nuse local\nuse constants\nuse error\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: qu(4)\n\ninteger(kind=irg) :: res\nreal(kind=sgl) :: r\nreal(kind=sgl), parameter :: eps = 1.e-7\n\nres = 1\n\nr = sqrt(sum(qu*qu))\nif (qu(1).lt.0.0) then\n call FatalError('rotations:qu_check','quaternion must have positive scalar part')\nendif\nif (abs(r-1.0).gt.eps) then\n call FatalError('rotations:qu_check','quaternion must have unit norm')\nendif\n\nres = 0\n\nend function qu_check\n\n!--------------------------------------------------------------------------\n!\n! Function: qu_check_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief verify that the quaternion has unit length and positive scalar part\n!\n!> @param qu 4-component vector (double precision) \n!> \n! \n!> @date 9/30/14 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function qu_check_d(qu) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: qu_check_d\n\nuse local\nuse constants\nuse error\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: qu(4)\n\ninteger(kind=irg) :: res\nreal(kind=dbl) :: r\nreal(kind=dbl), parameter :: eps = 1.d-15\n\nres = 1\n\nr = dsqrt(sum(qu*qu))\nif (qu(1).lt.0.D0) then\n call FatalError('rotations:qu_check_d','quaternion must have positive scalar part')\nendif\nif (dabs(r-1.D0).gt.eps) then\n call FatalError('rotations:qu_check_d','quaternion must have unit norm')\nendif\n\nres = 0\n\nend function qu_check_d\n\n!--------------------------------------------------------------------------\n!\n! Function: st_check\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief verify that the stereographic vector lies inside the unit ball\n!\n!> @param st 3-component vector (single precision) \n!> \n!> @date 10/05/17 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function st_check(st) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: st_check\n\nuse local\nuse constants\nuse error\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: st(3)\n\ninteger(kind=irg) :: res\nreal(kind=sgl) :: r\nreal(kind=sgl), parameter :: eps = 1.e-7\n\nres = 1\n\nr = sqrt(sum(st*st))\nif (abs(r-1.0).gt.eps) then\n call FatalError('rotations:st_check','stereographic vector must have unit norm')\nendif\n\nres = 0\n\nend function st_check\n\n!--------------------------------------------------------------------------\n!\n! Function: st_check_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief verify that the stereographic vector lies inside the unit ball\n!\n!> @param st 3-component vector (double precision) \n!> \n!> @date 10/05/17 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function st_check_d(st) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: st_check_d\n\nuse local\nuse constants\nuse error\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: st(3)\n\ninteger(kind=irg) :: res\nreal(kind=dbl) :: r\nreal(kind=dbl), parameter :: eps = 1.d-15\n\nres = 1\n\nr = sqrt(sum(st*st))\nif (abs(r-1.0).gt.eps) then\n call FatalError('rotations:st_check_d','stereographic vector must have unit norm')\nendif\n\nres = 0\n\nend function st_check_d\n\n!--------------------------------------------------------------------------\n!\n! Function: ax_check\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief verify that the axis angle pair has a unit vector and angle in the correct range\n!\n!> @param ax 4-component vector (single precision) \n!> \n! \n!> @date 9/30/14 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ax_check(ax) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ax_check\n\nuse local\nuse constants\nuse error\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: ax(4)\n\ninteger(kind=irg) :: res\nreal(kind=sgl) :: r\nreal(kind=sgl), parameter :: eps = 1.e-7\n\nres = 1\n\nr = sqrt(sum(ax(1:3)*ax(1:3)))\nif ((ax(4).lt.0.0).or.(ax(4).gt.sngl(cPi))) then\n call FatalError('rotations:ax_check','angle must be in range [0,pi]')\nendif\nif (abs(r-1.0).gt.eps) then\n call FatalError('rotations:ax_check','axis-angle axis vector must have unit norm')\nendif\n\nres = 0\n\nend function ax_check\n\n!--------------------------------------------------------------------------\n!\n! Function: ax_check_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief verify that the axis angle pair has a unit vector and angle in the correct range\n!\n!> @param ax 4-component vector (double precision) \n!> \n! \n!> @date 9/30/14 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ax_check_d(ax) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ax_check_d\n\nuse local\nuse constants\nuse error\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: ax(4)\n\ninteger(kind=irg) :: res\nreal(kind=dbl) :: r\nreal(kind=dbl), parameter :: eps = 1.e-15\n\nres = 1\n\nr = dsqrt(sum(ax(1:3)*ax(1:3)))\nif ((ax(4).lt.0.D0).or.(ax(4).gt.cPi)) then\n call FatalError('rotations:ax_check_d','angle must be in range [0,pi]')\nendif\nif (dabs(r-1.D0).gt.eps) then\n call FatalError('rotations:ax_check_d','axis-angle axis vector must have unit norm')\nendif\n\nres = 0\n\nend function ax_check_d\n\n!--------------------------------------------------------------------------\n!\n! Function: om_check\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief verify that the rotation matrix is actually a proper rotation matrix\n!\n!> @param om 3x3-component matrix (single precision) \n!> \n! \n!> @date 9/30/14 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function om_check(om) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: om_check\n\nuse local\nuse constants\nuse error\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: om(3,3)\n\ninteger(kind=irg) :: res\nreal(kind=sgl) :: r, det\nreal(kind=sgl), parameter :: eps = 1.e-6\ninteger(kind=irg) :: i\n\nres = 1\n\n! compute the determinant (must be +1)\ndet = om(1,1)*om(2,2)*om(3,3) + om(1,2)*om(2,3)*om(3,1) + om(1,3)*om(2,1)*om(3,2) - &\n om(1,3)*om(2,2)*om(3,1) - om(1,2)*om(2,1)*om(3,3) - om(1,1)*om(2,3)*om(3,2) \nif (det.lt.0.0) then\n call FatalError('rotations:om_check','Determinant of rotation matrix must be positive')\nendif\nif (abs(det-1.0).gt.eps) then\n call FatalError('rotations:om_check','Determinant of rotation matrix must be unity')\nendif\n\n! next check the row and column sums\nr = sum(abs(matmul(om,transpose(om))))\nif (abs(r-3.0).gt.eps) then\n call FatalError('rotations:om_check','rotation matrix times transpose must be identity matrix')\nendif\n\nres = 0\n\nend function om_check\n\n!--------------------------------------------------------------------------\n!\n! Function: om_check_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief verify that the rotation matrix is actually a proper rotation matrix\n!\n!> @param om 3x3-component matrix (double precision) \n!> \n! \n!> @date 9/30/14 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function om_check_d(om) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: om_check_d\n\nuse local\nuse constants\nuse error\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: om(3,3)\n\ninteger(kind=irg) :: res\nreal(kind=dbl) :: r, det\nreal(kind=dbl), parameter :: eps = 1.e-15\ninteger(kind=irg) :: i\n\nres = 1\n\n! compute the determinant (must be +1)\ndet = om(1,1)*om(2,2)*om(3,3) + om(1,2)*om(2,3)*om(3,1) + om(1,3)*om(2,1)*om(3,2) - &\n om(1,3)*om(2,2)*om(3,1) - om(1,2)*om(2,1)*om(3,3) - om(1,1)*om(2,3)*om(3,2) \nif (det.lt.0.D0) then\n call FatalError('rotations:om_check_d','Determinant of rotation matrix must be positive')\nendif\nif (dabs(det-1.D0).gt.eps) then\n call FatalError('rotations:om_check_d','Determinant of rotation matrix must be unity')\nendif\n\n! next check the row and column sums\nr = sum(dabs(matmul(om,transpose(om))))\nif (dabs(r-3.D0).gt.eps) then\n call FatalError('rotations:om_check_d','rotation matrix times transpose must be identity matrix')\nendif\n\nres = 0\n\nend function om_check_d\n\n!--------------------------------------------------------------------------\n!\n! Function: rv_check\n!\n!> @author Saransh Singh, Lawrence Livermore National Lab\n!\n!> @brief verify that the rotation vector has magnitude in range [0, pi]\n!\n!> @param ex 3-component vector (single precision) \n!> \n! \n!> @date 10/25/19 SS 1.0 original\n!--------------------------------------------------------------------------\nrecursive function rv_check(rv) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: rv_check\n\nuse local\nuse constants\nuse error\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: rv(3)\n\ninteger(kind=irg) :: res\nreal(kind=dbl) :: r\nreal(kind=dbl), parameter :: eps = 1.e-15\n\nres = 1\n\nr = vecnorm(rv)\n\nif ((r - cPi) .ge. eps) then\n call FatalError('rotations:rv_check_d','magnitude must be in range [0,pi]')\nendif\n\nres = 0\n\nend function rv_check\n\n!--------------------------------------------------------------------------\n!\n! Function: rv_check_d\n!\n!> @author Saransh Singh, Lawrence Livermore National Lab\n!\n!> @brief verify that the rotation vector map has magnitude in range [0, pi]\n!\n!> @param ex 3-component vector (double precision) \n!> \n! \n!> @date 10/25/19 SS 1.0 original\n!--------------------------------------------------------------------------\nrecursive function rv_check_d(rv) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: rv_check_d\n\nuse local\nuse constants\nuse error\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: rv(3)\n\ninteger(kind=irg) :: res\nreal(kind=dbl) :: r\nreal(kind=dbl), parameter :: eps = 1.e-15\n\nres = 1\n\nr = vecnorm(rv)\n\nif ((r - cPi) .ge. eps) then\n call FatalError('rotations:rv_check_d','magnitude must be in range [0,pi]')\nendif\n\nres = 0\n\nend function rv_check_d\n\n!--------------------------------------------------------------------------\n!--------------------------------------------------------------------------\n! here we start with a series of input routines\n!--------------------------------------------------------------------------\n!--------------------------------------------------------------------------\n\n!--------------------------------------------------------------------------\n!\n! Function: genrot\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief generate a passive rotation representation, given the unit axis vector and the rotation angle\n!\n!> @param av 3-component vector (single precision) \n!> @param omega rotation angle (radians)\n!> \n! \n!> @date 9/30/14 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function genrot(av,omega) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: genrot\n\nuse local\nuse constants\nuse error\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: av(3)\nreal(kind=sgl),INTENT(IN) :: omega\n\ntype(orientationtype) :: res\nreal(kind=sgl) :: axang(4), s\n\n! first make sure that the rotation angle is in the interval [0,pi]\nif ((omega.lt.0.0).or.(omega.gt.sngl(cPi))) then \n call FatalError('rotations:getrot','rotation angle must be in range [0,pi]')\n STOP\nendif\n\n! define the axis-angle pair with the correct sign of epsijk\naxang(1:3) = -epsijk * av(1:3)\naxang(4) = omega\n\n! normalize the unit vector\ns = sqrt(sum(av*av))\nif (s.ne.0.0) then \n axang(1:3) = axang(1:3)/s\nelse\n call FatalError('rotations:getrot','axis unit vector can not be [0,0,0]')\n STOP\nendif\n\nres = init_orientation(axang,'ax')\n\nend function genrot\n\n!--------------------------------------------------------------------------\n!\n! Function: genrot_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief generate a passive rotation representation, given the unit axis vector and the rotation angle\n!\n!> @param av 3-component vector (double precision) \n!> @param omega rotation angle (radians)\n!> \n! \n!> @date 9/30/14 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function genrot_d(av,omega) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: genrot_d\n\nuse local\nuse constants\nuse error\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: av(3)\nreal(kind=dbl),INTENT(IN) :: omega\n\ntype(orientationtyped) :: res\nreal(kind=dbl) :: axang(4), s\n\n! first make sure that the rotation angle is in the interval [0,pi]\nif ((omega.lt.0.D0).or.(omega.gt.cPi)) then \n call FatalError('rotations:getrot_d','rotation angle must be in range [0,pi]')\n STOP\nendif\n\n! define the axis-angle pair with the correct sign of epsijk\naxang(1:3) = -epsijk * av(1:3)\naxang(4) = omega\n\n! normalize the unit vector\ns = dsqrt(sum(av*av))\nif (s.ne.0.D0) then \n axang(1:3) = axang(1:3)/s\nelse\n call FatalError('rotations:getrot','axis unit vector can not be [0,0,0]')\n STOP\nendif\n\nres = init_orientation_d(axang,'ax')\n\nend function genrot_d\n\n!--------------------------------------------------------------------------\n!\n! Function: init_orientation\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief take an orientation representation with 3 components and init all others (single precision)\n!\n!> @param orient 3-component vector (single precision) \n!> @param intype input type ['eu', 'ro', 'ho', 'cu']\n!> @param rotcheck optional parameter to enforce strict range checking\n! \n!> @date 8/04/13 MDG 1.0 original\n!> @date 9/30/14 MDG 1.1 added testing of valid ranges\n!--------------------------------------------------------------------------\nrecursive function init_orientation(orient,intype,rotcheck) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: init_orientation\n\nuse local\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: orient(*) ! 3 or 4 component orientation descriptor\ncharacter(2),INTENT(IN) :: intype ! describes input type\nlogical,INTENT(IN),OPTIONAL :: rotcheck ! check valid range if present\n\ntype(orientationtype) :: res\ninteger(kind=irg) :: i\n\nselect case (intype)\n case ('eu') ! Euler angles\n ! verify the Euler angle ranges; this will abort program if values are outside range\n if (present(rotcheck)) then \n if (rotcheck.eqv..TRUE.) i = eu_check(orient)\n endif\n res%eulang = orient(1:3)\n res%om = eu2om(orient(1:3))\n res%quat = eu2qu(orient(1:3))\n res%rodrigues = eu2ro(orient(1:3))\n res%axang = eu2ax(orient(1:3))\n res%homochoric = eu2ho(orient(1:3))\n res%cubochoric = eu2cu(orient(1:3))\n res%stereographic = eu2st(orient(1:3))\n res%rvmap = eu2rv(orient(1:3))\n case ('ro') ! Rodrigues vector\n ! verify the Rodrigues-Frank vector; this will abort program if values are outside range\n if (present(rotcheck)) then \n if (rotcheck.eqv..TRUE.) i = ro_check(orient)\n endif\n res%rodrigues = orient(1:4)\n res%eulang = ro2eu(orient(1:4))\n res%om = ro2om(orient(1:4))\n res%quat = ro2qu(orient(1:4))\n res%axang = ro2ax(orient(1:4))\n res%homochoric = ro2ho(orient(1:4))\n res%cubochoric = ro2cu(orient(1:4))\n res%stereographic = ro2st(orient(1:4))\n res%rvmap = ro2rv(orient(1:4))\n case ('ho') ! homochoric\n ! verify the homochoric vector; this will abort program if values are outside range\n if (present(rotcheck)) then \n if (rotcheck.eqv..TRUE.) i = ho_check(orient)\n endif\n res%homochoric = orient(1:3)\n res%axang = ho2ax(orient(1:3))\n res%om = ho2om(orient(1:3))\n res%eulang = ho2eu(orient(1:3))\n res%rodrigues = ho2ro(orient(1:3))\n res%quat = ho2qu(orient(1:3))\n res%cubochoric = ho2cu(orient(1:3))\n res%stereographic = ho2st(orient(1:3))\n res%rvmap = ho2rv(orient(1:3))\n case ('cu') ! cubochoric\n ! verify the cubochoric vector; this will abort program if values are outside range\n if (present(rotcheck)) then \n if (rotcheck.eqv..TRUE.) i = cu_check(orient)\n endif\n res%cubochoric = orient(1:3)\n res%homochoric = cu2ho(orient(1:3))\n res%eulang = cu2eu(orient(1:3))\n res%om = cu2om(orient(1:3))\n res%quat = cu2qu(orient(1:3))\n res%axang = cu2ax(orient(1:3))\n res%rodrigues = cu2ro(orient(1:3))\n res%stereographic = cu2st(orient(1:3))\n res%rvmap = cu2rv(orient(1:3))\n case ('st') ! stereographic\n ! verify the cstereographic vector; this will abort program if values are outside range\n if (present(rotcheck)) then \n if (rotcheck.eqv..TRUE.) i = st_check(orient)\n endif\n res%stereographic = orient(1:3)\n res%cubochoric = st2cu(orient(1:3))\n res%homochoric = st2ho(orient(1:3))\n res%eulang = st2eu(orient(1:3))\n res%om = st2om(orient(1:3))\n res%quat = st2qu(orient(1:3))\n res%axang = st2ax(orient(1:3))\n res%rodrigues = st2ro(orient(1:3))\n res%rvmap = st2rv(orient(1:3))\n case ('qu') ! quaternion\n ! verify the quaternion; this will abort program if values are outside range\n if (present(rotcheck)) then \n if (rotcheck.eqv..TRUE.) i = qu_check(orient)\n endif\n res%quat = orient(1:4)\n res%eulang = qu2eu(orient(1:4))\n res%om = qu2om(orient(1:4))\n res%rodrigues = qu2ro(orient(1:4))\n res%axang = qu2ax(orient(1:4))\n res%homochoric = qu2ho(orient(1:4))\n res%cubochoric = qu2cu(orient(1:4))\n res%stereographic = qu2st(orient(1:4))\n res%rvmap = qu2rv(orient(1:4))\n case ('ax') ! axis angle pair\n ! verify the axis angle pair; this will abort program if values are outside range\n if (present(rotcheck)) then \n if (rotcheck.eqv..TRUE.) i = ax_check(orient)\n endif\n res%axang = orient(1:4)\n res%om = ax2om(orient(1:4))\n res%eulang = ax2eu(orient(1:4))\n res%rodrigues = ax2ro(orient(1:4))\n res%quat = ax2qu(orient(1:4))\n res%homochoric = ax2ho(orient(1:4))\n res%cubochoric = ax2cu(orient(1:4))\n res%stereographic = ax2st(orient(1:4))\n res%rvmap = ax2rv(orient(1:4))\n case('rv') ! rotation vector map\n ! verify the rotation vector map; this will abort program if values are outside range\n if (present(rotcheck)) then \n if (rotcheck.eqv..TRUE.) i = qu_check(orient)\n endif\n res%rvmap = orient(1:3)\n res%stereographic = rv2st(orient(1:3))\n res%cubochoric = rv2cu(orient(1:3))\n res%homochoric = rv2ho(orient(1:3))\n res%eulang = rv2eu(orient(1:3))\n res%om = rv2om(orient(1:3))\n res%quat = rv2qu(orient(1:3))\n res%axang = rv2ax(orient(1:3))\n res%rodrigues = rv2ro(orient(1:3))\n \nend select \n\nend function init_orientation\n\n!--------------------------------------------------------------------------\n!\n! Function: init_orientation_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief take an orientation representation with 3 components and init all others (double precision)\n!\n!> @param orient 3-component vector (double precision) \n!> @param intype input type ['eu', 'ro', 'ho', 'cu']\n!> @param rotcheck optional parameter to enforce strict range checking\n!> \n! \n!> @date 8/04/13 MDG 1.0 original\n!> @date 9/30/14 MDG 1.1 added testing of valid ranges\n!--------------------------------------------------------------------------\nrecursive function init_orientation_d(orient,intype,rotcheck) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: init_orientation_d\n\nuse local\nuse error\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: orient(*) ! 3-component orientation descriptor\ncharacter(2),INTENT(IN) :: intype ! describes input type\nlogical,INTENT(IN),OPTIONAL :: rotcheck ! check valid range if present\n\ntype(orientationtyped) :: res\ninteger(kind=irg) :: i\n\nselect case (intype)\n case ('eu') ! Euler angles\n ! verify the Euler angle ranges; this will abort program if values are outside range\n if (present(rotcheck)) then \n if (rotcheck.eqv..TRUE.) i = eu_check_d(orient)\n endif\n res%eulang = orient(1:3)\n res%om = eu2om_d(orient(1:3))\n res%quat = eu2qu_d(orient(1:3))\n res%rodrigues = eu2ro_d(orient(1:3))\n res%axang = eu2ax_d(orient(1:3))\n res%homochoric = eu2ho_d(orient(1:3))\n res%cubochoric = eu2cu_d(orient(1:3))\n res%stereographic = eu2st_d(orient(1:3))\n res%rvmap = eu2rv_d(orient(1:3))\n case ('ro') ! Rodrigues vector\n ! verify the Rodrigues-Frank vector; this will abort program if values are outside range\n if (present(rotcheck)) then \n if (rotcheck.eqv..TRUE.) i = ro_check_d(orient)\n endif\n res%rodrigues = orient(1:4)\n res%eulang = ro2eu_d(orient(1:4))\n res%om = ro2om_d(orient(1:4))\n res%quat = ro2qu_d(orient(1:4))\n res%axang = ro2ax_d(orient(1:4))\n res%homochoric = ro2ho_d(orient(1:4))\n res%cubochoric = ro2cu_d(orient(1:4))\n res%stereographic = ro2st_d(orient(1:4))\n res%rvmap = ro2rv_d(orient(1:4))\n case ('ho') ! homochoric\n ! verify the homochoric vector; this will abort program if values are outside range\n if (present(rotcheck)) then \n if (rotcheck.eqv..TRUE.) i = ho_check_d(orient)\n endif\n res%homochoric = orient(1:3)\n res%axang = ho2ax_d(orient(1:3))\n res%om = ho2om_d(orient(1:3))\n res%eulang = ho2eu_d(orient(1:3))\n res%rodrigues = ho2ro_d(orient(1:3))\n res%quat = ho2qu_d(orient(1:3))\n res%cubochoric = ho2cu_d(orient(1:3))\n res%stereographic = ho2st_d(orient(1:3))\n res%rvmap = ho2rv_d(orient(1:4))\n case ('cu') ! cubochoric\n ! verify the cubochoric vector; this will abort program if values are outside range\n if (present(rotcheck)) then \n if (rotcheck.eqv..TRUE.) i = cu_check_d(orient)\n endif\n res%cubochoric = orient(1:3)\n res%homochoric = cu2ho_d(orient(1:3))\n res%eulang = cu2eu_d(orient(1:3))\n res%om = cu2om_d(orient(1:3))\n res%quat = cu2qu_d(orient(1:3))\n res%axang = cu2ax_d(orient(1:3))\n res%rodrigues = cu2ro_d(orient(1:3))\n res%stereographic = cu2st_d(orient(1:3))\n res%rvmap = cu2rv_d(orient(1:3))\n case ('st') ! stereographic\n ! verify the cstereographic vector; this will abort program if values are outside range\n if (present(rotcheck)) then \n if (rotcheck.eqv..TRUE.) i = st_check_d(orient)\n endif\n res%stereographic = orient(1:3)\n res%cubochoric = st2cu_d(orient(1:3))\n res%homochoric = st2ho_d(orient(1:3))\n res%eulang = st2eu_d(orient(1:3))\n res%om = st2om_d(orient(1:3))\n res%quat = st2qu_d(orient(1:3))\n res%axang = st2ax_d(orient(1:3))\n res%rodrigues = st2ro_d(orient(1:3))\n res%rvmap = st2rv_d(orient(1:3))\n case ('qu') ! quaternion\n ! verify the quaternion; this will abort program if values are outside range\n if (present(rotcheck)) then \n if (rotcheck.eqv..TRUE.) i = qu_check_d(orient)\n endif\n res%quat = orient(1:4)\n res%eulang = qu2eu_d(orient(1:4))\n res%om = qu2om_d(orient(1:4))\n res%rodrigues = qu2ro_d(orient(1:4))\n res%axang = qu2ax_d(orient(1:4))\n res%homochoric = qu2ho_d(orient(1:4))\n res%cubochoric = qu2cu_d(orient(1:4))\n res%stereographic = qu2st(orient(1:4))\n res%rvmap = qu2rv_d(orient(1:4))\n case ('ax') ! axis angle pair\n ! verify the axis angle pair; this will abort program if values are outside range\n if (present(rotcheck)) then \n if (rotcheck.eqv..TRUE.) i = ax_check_d(orient)\n endif\n res%axang = orient(1:4)\n res%om = ax2om_d(orient(1:4))\n res%eulang = ax2eu_d(orient(1:4))\n res%rodrigues = ax2ro_d(orient(1:4))\n res%quat = ax2qu_d(orient(1:4))\n res%homochoric = ax2ho_d(orient(1:4))\n res%cubochoric = ax2cu_d(orient(1:4))\n res%stereographic = ax2st_d(orient(1:4))\n res%rvmap = ax2rv_d(orient(1:4))\n case('rv') ! rotation vector map\n ! verify the rotation vector map; this will abort program if values are outside range\n if (present(rotcheck)) then \n if (rotcheck.eqv..TRUE.) i = qu_check(orient)\n endif\n res%rvmap = orient(1:3)\n res%stereographic = rv2st_d(orient(1:3))\n res%cubochoric = rv2cu_d(orient(1:3))\n res%homochoric = rv2ho_d(orient(1:3))\n res%eulang = rv2eu_d(orient(1:3))\n res%om = rv2om_d(orient(1:3))\n res%quat = rv2qu_d(orient(1:3))\n res%axang = rv2ax_d(orient(1:3))\n res%rodrigues = rv2ro_d(orient(1:3))\nend select \n\nend function init_orientation_d\n\n!--------------------------------------------------------------------------\n!\n! Function: init_orientation_om\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief take an orientation representation with 3x3 components and init all others (single precision)\n!\n!> @param orient r-component vector (single precision) \n!> @param intype input type ['om']\n!> @param rotcheck optional parameter to enforce strict range checking\n!> \n! \n!> @date 8/04/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function init_orientation_om(orient,intype,rotcheck) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: init_orientation_om\n\nuse local\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: orient(3,3) ! 3x3-component orientation descriptor\ncharacter(2),INTENT(IN) :: intype ! describes input type\nlogical,INTENT(IN),OPTIONAL :: rotcheck ! check valid range if present\n\ntype(orientationtype) :: res\ninteger(kind=irg) :: i\n\nselect case (intype)\n case ('om') ! orientation matrix\n ! verify the rotation matrix; this will abort program if values are outside range\n if (present(rotcheck)) then \n if (rotcheck.eqv..TRUE.) i = om_check(orient)\n endif\n res%om = orient\n res%quat = om2qu(orient)\n res%eulang = om2eu(orient)\n res%rodrigues = om2ro(orient)\n res%axang = om2ax(orient)\n res%homochoric = om2ho(orient)\n res%stereographic = om2st(orient)\n res%cubochoric = om2cu(orient)\n res%rvmap = om2rv(orient)\nend select \n\nend function init_orientation_om\n\n\n!--------------------------------------------------------------------------\n!\n! Function: init_orientation_om_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief take an orientation representation with 3x3 components and init all others (double precision)\n!\n!> @param orient r-component vector (double precision) \n!> @param intype input type ['om']\n!> @param rotcheck optional parameter to enforce strict range checking\n!> \n! \n!> @date 8/04/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function init_orientation_om_d(orient,intype,rotcheck) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: init_orientation_om_d\n\nuse local\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: orient(3,3) ! 3x3-component orientation descriptor\ncharacter(2),INTENT(IN) :: intype ! describes input type\nlogical,INTENT(IN),OPTIONAL :: rotcheck ! check valid range if present\n\ntype(orientationtyped) :: res\ninteger(kind=irg) :: i\n\nselect case (intype)\n case ('om') ! orientation matrix\n ! verify the rotation matrix; this will abort program if values are outside range\n if (present(rotcheck)) then \n if (rotcheck.eqv..TRUE.) i = om_check_d(orient)\n endif\n res%om = orient\n res%quat = om2qu_d(orient)\n res%eulang = om2eu_d(orient)\n res%rodrigues = om2ro_d(orient)\n res%axang = om2ax_d(orient)\n res%homochoric = om2ho_d(orient)\n res%stereographic = om2st_d(orient)\n res%cubochoric = om2cu_d(orient)\n res%rvmap = om2rv_d(orient)\nend select \n\nend function init_orientation_om_d\n\n\n\n!--------------------------------------------------------------------------\n!--------------------------------------------------------------------------\n! here we start with a series of conversion routines between representations\n!--------------------------------------------------------------------------\n!--------------------------------------------------------------------------\n\n!--------------------------------------------------------------------------\n!\n! Function: eu2om\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief Euler angles to orientation matrix (single precision) [Morawiec, page 28]\n!\n!> @param e 3 Euler angles in radians (single precision) \n!> \n! \n!> @date 8/04/13 MDG 1.0 original\n!> @data 7/23/14 MDG 1.1 verified\n!--------------------------------------------------------------------------\nrecursive function eu2om(e) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: eu2om\n\nuse local\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: e(3) !< Euler angles in radians\nreal(kind=sgl) :: res(3,3) !< output orientation matrix\n \nreal(kind=sgl) :: c1, c2, c3, s1, s2, s3\ninteger(kind=irg) :: i,j\nreal(kind=sgl),parameter :: thr = 1.0E-8\n\nc1 = cos(e(1))\nc2 = cos(e(2))\nc3 = cos(e(3))\ns1 = sin(e(1))\ns2 = sin(e(2))\ns3 = sin(e(3))\n\nres(1,1) = c1*c3-s1*s3*c2\nres(1,2) = s1*c3+c1*s3*c2\nres(1,3) = s3*s2\nres(2,1) = -c1*s3-s1*c3*c2\nres(2,2) = -s1*s3+c1*c3*c2\nres(2,3) = c3*s2\nres(3,1) = s1*s2\nres(3,2) = -c1*s2\nres(3,3) = c2\n\ndo i=1,3\n do j=1,3\n if (abs(res(i,j)).lt.thr) res(i,j) = 0.0\n end do\nend do\n\nend function eu2om\n\n!--------------------------------------------------------------------------\n!\n! Function: eu2om_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief Euler angles to orientation matrix (double precision) [Morawiec, page 28]\n!\n!> @param e 3 Euler angles in radians (double precision) \n!> \n! \n!> @date 8/04/13 MDG 1.0 original\n!> @data 7/23/14 MDG 1.1 verified\n!--------------------------------------------------------------------------\nrecursive function eu2om_d(e) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: eu2om_d\n\nuse local\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: e(3) !< Euler angles in radians\nreal(kind=dbl) :: res(3,3) !< output orientation matrix\n\nreal(kind=dbl) :: c1, c2, c3, s1, s2, s3\ninteger(kind=irg) :: i,j\nreal(kind=dbl),parameter :: thr = 1.0D-10\n\nc1 = dcos(e(1))\nc2 = dcos(e(2))\nc3 = dcos(e(3))\ns1 = dsin(e(1))\ns2 = dsin(e(2))\ns3 = dsin(e(3))\n\nres(1,1) = c1*c3-s1*s3*c2\nres(1,2) = s1*c3+c1*s3*c2\nres(1,3) = s3*s2\nres(2,1) = -c1*s3-s1*c3*c2\nres(2,2) = -s1*s3+c1*c3*c2\nres(2,3) = c3*s2\nres(3,1) = s1*s2\nres(3,2) = -c1*s2\nres(3,3) = c2\n\ndo i=1,3\n do j=1,3\n if (dabs(res(i,j)).lt.thr) res(i,j) = 0.D0\n end do\nend do\n\nend function eu2om_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: eu2ax\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert euler to axis angle\n!\n!> @param e 3 euler angles (single precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!> @date 7/23/14 MDG 2.0 explicit implementation\n!> @date 7/23/14 MDG 2.1 exception for zero rotation angle\n!> @date 9/23/15 MDG 2.2 moved alphe.lt.0 test inside else statement\n!--------------------------------------------------------------------------\nrecursive function eu2ax(e) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: eu2ax\n\nuse local \nuse constants\n\nreal(kind=sgl), INTENT(IN) :: e(3)\nreal(kind=sgl) :: res(4), t, del, tau, alpha, sig\nreal(kind=dbl),parameter :: thr = 1.0E-6\n\nt = tan(e(2)*0.5)\nsig = 0.5*(e(1)+e(3))\ndel = 0.5*(e(1)-e(3))\ntau = sqrt(t*t+sin(sig)**2)\n\nif (close_enough(sig,sngl(cPi)*0.5)) then ! Infinity \n alpha = sngl(cPi)\nelse\n alpha = 2.0 * atan(tau/cos(sig))\nend if \n\nif (abs(alpha).lt.thr) then\n! return a default identity axis-angle pair\n res = (/ 0.0, 0.0, 1.0, 0.0 /)\nelse\n! passive axis-angle pair so a minus sign in front\n res(1:3) = - epsijk * (/ t*cos(del), t*sin(del), sin(sig) /) / tau\n res(4) = alpha\n\n! make sure alpha is positive\n if (alpha.lt.0.0) res = -res\nend if\n\nend function eu2ax\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: eu2ax_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert euler to axis angle\n!\n!> @param e 3 euler angles (double precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!> @date 7/23/14 MDG 1.1 exception for zero rotation angle\n!> @date 9/23/15 MDG 2.2 moved alphe.lt.0 test inside else statement\n!--------------------------------------------------------------------------\nrecursive function eu2ax_d(e) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: eu2ax_d\n\nuse local \nuse constants\n\nreal(kind=dbl), INTENT(IN) :: e(3)\nreal(kind=dbl) :: res(4), del, t, tau, alpha, sig\nreal(kind=dbl),parameter :: thr = 1.0D-10\n\nt = dtan(e(2)*0.5D0)\nsig = 0.5D0*(e(1)+e(3))\ndel = 0.5D0*(e(1)-e(3))\ntau = dsqrt(t*t+dsin(sig)**2)\n\nif (close_enough(sig,cPi*0.5D0)) then ! Infinity \n alpha = cPi\nelse\n alpha = 2.D0 * datan(tau/dcos(sig))\nend if \n\nif (abs(alpha).lt.thr) then\n! return a default identity axis-angle pair\n res = (/ 0.D0, 0.D0, 1.D0, 0.D0 /)\nelse\n! passive axis-angle pair so a minus sign in front\n res(1:3) = - epsijkd *(/ t*dcos(del), t*dsin(del), dsin(sig) /) / tau\n res(4) = alpha\n\n! make sure alpha is positive\n if (alpha.lt.0.D0) res = -res\nend if\n\nend function eu2ax_d\n\n!--------------------------------------------------------------------------\n!\n! Function: eu2ro\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief Euler angles to Rodrigues vector (single precision) [Morawiec, page 40]\n!\n!> @param e 3 Euler angles in radians (single precision) \n!> \n!\n!> @date 8/04/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function eu2ro(e) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: eu2ro\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: e(3) !< input Euler angles (radians)\nreal(kind=sgl) :: res(4) !< output Rodrigues vector\n\nreal(kind=sgl) :: t\nreal(kind=sgl),parameter :: thr = 1.0E-7\n\n! first go to the axis-angle representation\nres = eu2ax(e)\n\n! then adjust the fourth component to be tan(omega/2)\nt = res(4)\nif (abs(t-sngl(cPi)).lt.thr) then\n res(4) = infty()\n return\nend if\n \nif (close_enough(t,0.0)) then \n res = (/ 0.0, 0.0, epsijk, 0.0 /)\nelse\n res(4) = tan(t*0.5)\nend if\n\nend function eu2ro\n\n!--------------------------------------------------------------------------\n!\n! Function: eu2ro_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief Euler angles to Rodrigues vector (double precision) [Morawiec, page 40]\n!\n!> @param e 3 Euler angles in radians (double precision) \n!> \n!\n!> @date 8/04/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function eu2ro_d(e) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: eu2ro_d\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: e(3) !< input Euler angles (radians)\nreal(kind=dbl) :: res(4) !< output Rodrigues vector\n\nreal(kind=dbl) :: t\nreal(kind=sgl),parameter :: thr = 1.0D-10\n\n! first go to the axis-angle representation\nres = eu2ax_d(e)\n\n! then adjust the fourth component to be tan(omega/2)\nt = res(4)\nif (abs(t-cPi).lt.thr) then\n res(4) = inftyd()\n return\nend if\n \nif (close_enough(t,0.D0)) then \n res = (/ 0.D0, 0.D0, epsijkd, 0.D0 /)\nelse\n res(4) = dtan(t*0.5D0)\nend if\n\nend function eu2ro_d\n\n!--------------------------------------------------------------------------\n!\n! Function: eu2qu\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief Euler angles to quaternion (single precision) [Morawiec, page 40]\n!\n!> @note verified 8/5/13\n!\n!> @param e 3 Euler angles in radians (single precision) \n!> \n! \n!> @date 8/04/13 MDG 1.0 original\n!> @date 8/07/14 MDG 1.1 verified\n!--------------------------------------------------------------------------\nrecursive function eu2qu(e) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: eu2qu\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: e(3) !< input Euler angles in radians\nreal(kind=sgl) :: res(4) !< output quaternion\n \nreal(kind=sgl) :: ee(3), cPhi, cp, cm, sPhi, sp, sm\n\nee = 0.5*e\n\ncPhi = cos(ee(2))\nsPhi = sin(ee(2))\ncm = cos(ee(1)-ee(3))\nsm = sin(ee(1)-ee(3))\ncp = cos(ee(1)+ee(3))\nsp = sin(ee(1)+ee(3))\n\n! passive quaternion\nres = (/ cPhi*cp, -epsijk*sPhi*cm, -epsijk*sPhi*sm, -epsijk*cPhi*sp /)\n\n! first component must be positive\nif (res(1).lt.0.0) res = -res\n\nend function eu2qu\n\n!--------------------------------------------------------------------------\n!\n! Function: eu2qu_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief Euler angles to quaternion (double precision) [Morawiec, page 40]\n!\n!> @note verified 8/5/13\n!\n!> @param e 3 Euler angles in radians (double precision) \n!> \n! \n!> @date 8/04/13 MDG 1.0 original\n!> @date 8/07/14 MDG 1.1 verified\n!--------------------------------------------------------------------------\nrecursive function eu2qu_d(e) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: eu2qu_d\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: e(3) !< input Euler angles in radians\nreal(kind=dbl) :: res(4) !< output quaternion\n\nreal(kind=dbl) :: ee(3), cPhi, cp, cm, sPhi, sp, sm\n\nee = 0.5D0*e\n\ncPhi = dcos(ee(2))\nsPhi = dsin(ee(2))\ncm = dcos(ee(1)-ee(3))\nsm = dsin(ee(1)-ee(3))\ncp = dcos(ee(1)+ee(3))\nsp = dsin(ee(1)+ee(3))\n\n! passive quaternion\nres = (/ cPhi*cp, -epsijkd*sPhi*cm, -epsijkd*sPhi*sm, -epsijkd*cPhi*sp /)\n\n! first component must be positive\nif (res(1).lt.0.D0) res = -res\n\nend function eu2qu_d\n\n!--------------------------------------------------------------------------\n!\n! Function: om2eu\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief orientation matrix to euler angles (single precision)\n!\n!> @note verified 8/19/14 using Mathematica\n!\n!> @param o orientation matrix (single precision) \n!\n!> @date 8/04/13 MDG 1.0 original\n!> @date 8/19/14 MDG 1.1 verification using Mathematica\n!--------------------------------------------------------------------------\nrecursive function om2eu(o) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: om2eu\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: o(3,3) !< orientation matrix\nreal(kind=sgl) :: res(3), zeta\nreal(kind=dbl),parameter :: thr = 1.0D-6\n\nif (.not.close_enough(abs(o(3,3)),1.0)) then\n res(2) = acos(o(3,3))\n zeta = 1.0/sqrt(1.0-o(3,3)**2)\n res(1) = atan2(o(3,1)*zeta,-o(3,2)*zeta)\n res(3) = atan2(o(1,3)*zeta, o(2,3)*zeta)\nelse\n! we arbitrarily assign the entire angle to phi_1\n if (close_enough(o(3,3),1.0)) then\n res(1) = atan2( o(1,2),o(1,1))\n res(2) = 0.0\n res(3) = 0.0\n else\n res(1) =-atan2(-o(1,2),o(1,1))\n res(2) = sngl(cPi)\n res(3) = 0.0\n end if\nend if\n\n! reduce Euler angles to definition ranges (and positive values only)\nif (res(1).lt.0.0) res(1) = mod(res(1)+100.0*sngl(cPi),2.0*sngl(cPi))\nif (res(2).lt.0.0) res(2) = mod(res(2)+100.0*sngl(cPi),sngl(cPi))\nif (res(3).lt.0.0) res(3) = mod(res(3)+100.0*sngl(cPi),2.0*sngl(cPi))\n\nend function om2eu\n\n!--------------------------------------------------------------------------\n!\n! Function: om2eu_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief orientation matrix to euler angles (double precision)\n!\n!> @note verified 8/19/14 using Mathematica\n!\n!> @param o orientation matrix (double precision) \n!\n!> @date 8/04/13 MDG 1.0 original\n!> @date 8/19/14 MDG 1.1 verification using Mathematica\n!--------------------------------------------------------------------------\nrecursive function om2eu_d(o) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: om2eu_d\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: o(3,3) !< orientation matrix\nreal(kind=dbl) :: res(3), zeta\nreal(kind=dbl),parameter :: thr = 1.0D-8\n\nif (.not.close_enough(dabs(o(3,3)),1.D0)) then\n res(2) = dacos(o(3,3))\n zeta = 1.D0/dsqrt(1.D0-o(3,3)**2)\n res(1) = datan2(o(3,1)*zeta,-o(3,2)*zeta)\n res(3) = datan2(o(1,3)*zeta, o(2,3)*zeta)\nelse\n! we arbitrarily assign the entire angle to phi_1\n if (close_enough(o(3,3),1.D0)) then\n res(1) = datan2( o(1,2),o(1,1))\n res(2) = 0.D0\n res(3) = 0.D0\n else\n res(1) =-datan2(-o(1,2),o(1,1))\n res(2) = cPi\n res(3) = 0.D0\n end if\nend if\n\n! reduce Euler angles to definition ranges (and positive values only)\nif (res(1).lt.0.D0) res(1) = dmod(res(1)+100.D0*cPi,2.D0*cPi)\nif (res(2).lt.0.D0) res(2) = dmod(res(2)+100.D0*cPi,cPi)\nif (res(3).lt.0.D0) res(3) = dmod(res(3)+100.D0*cPi,2.D0*cPi)\n\nend function om2eu_d\n\n!--------------------------------------------------------------------------\n!\n! Function: ax2om\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief Axis angle pair to orientation matrix (single precision)\n!\n!> @note verified 8/5/13.\n!\n!> @param a axis angle pair (single precision) \n!> \n!\n!> @date 8/04/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ax2om(a) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ax2om\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: a(4) !< axis angle pair\nreal(kind=sgl) :: res(3,3)\n\nreal(kind=sgl) :: q, c, s, omc\ninteger(kind=irg) :: i\n\nc = cos(a(4))\ns = sin(a(4))\nomc = 1.0-c\n\ndo i=1,3\n res(i,i) = a(i)**2*omc + c\nend do\n\nq = omc*a(1)*a(2)\nres(1,2) = q + s*a(3)\nres(2,1) = q - s*a(3)\n\nq = omc*a(2)*a(3)\nres(2,3) = q + s*a(1)\nres(3,2) = q - s*a(1)\n\nq = omc*a(3)*a(1)\nres(3,1) = q + s*a(2)\nres(1,3) = q - s*a(2)\n\nif (epsijk.eq.1.0) res = transpose(res)\n\nend function ax2om\n\n!--------------------------------------------------------------------------\n!\n! Function: ax2om_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief Axis angle pair to orientation matrix (double precision)\n!\n!> @note verified 8/5/13.\n!\n!> @param a axis angle pair (double precision) \n!> \n!\n!> @date 8/04/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ax2om_d(a) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ax2om_d\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: a(4) !< axis angle pair\nreal(kind=dbl) :: res(3,3)\n \nreal(kind=dbl) :: q, c, s, omc\ninteger(kind=irg) :: i\n\nc = dcos(a(4))\ns = dsin(a(4))\nomc = 1.D0-c\n\ndo i=1,3\n res(i,i) = a(i)**2*omc + c\nend do\n\n\nq = omc*a(1)*a(2)\nres(1,2) = q + s*a(3)\nres(2,1) = q - s*a(3)\n\nq = omc*a(2)*a(3)\nres(2,3) = q + s*a(1)\nres(3,2) = q - s*a(1)\n\nq = omc*a(3)*a(1)\nres(3,1) = q + s*a(2)\nres(1,3) = q - s*a(2)\n\nif (epsijkd.eq.1.D0) res = transpose(res)\n\nend function ax2om_d\n\n!--------------------------------------------------------------------------\n!\n! Function: qu2eu\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief Quaternion to Euler angles (single precision) [Morawiec page 40, with errata !!!! ]\n!\n!> @param q quaternion (single precision) \n!> \n!\n!> @date 8/04/13 MDG 1.0 original\n!> @date 4/17/15 MDG 1.1 simplification based on M. Jackson question\n!--------------------------------------------------------------------------\nrecursive function qu2eu(q) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: qu2eu\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: q(4) !< quaternion\nreal(kind=sgl) :: res(3)\n\nreal(kind=sgl) :: qq(4), q12, q03, chi, Phi, phi1, phi2\n\nqq = q\n\nq03 = qq(1)**2+qq(4)**2\nq12 = qq(2)**2+qq(3)**2\nchi = sqrt(q03*q12)\n\nif (close_enough(chi,0.0)) then\n if (close_enough(q12,0.0)) then \n Phi = 0.0\n phi2 = 0.0 ! arbitrarily due to degeneracy\n phi1 = atan2(-epsijk*2.0*qq(1)*qq(4),qq(1)**2-qq(4)**2)\n else\n Phi = sngl(cPi)\n phi2 = 0.0 ! arbitrarily due to degeneracy\n phi1 = atan2(2.0*qq(2)*qq(3),qq(2)**2-qq(3)**2)\n end if\nelse ! this is not a special degenerate case\n Phi = atan2( 2.0*chi, q03-q12 )\n chi = 1.0/chi\n phi1 = atan2( (-epsijk*qq(1)*qq(3)+qq(2)*qq(4))*chi, (-epsijk*qq(1)*qq(2)-qq(3)*qq(4))*chi )\n phi2 = atan2( (epsijk*qq(1)*qq(3)+qq(2)*qq(4))*chi, (-epsijk*qq(1)*qq(2)+qq(3)*qq(4))*chi )\nend if\n\nres = (/ phi1, Phi, phi2 /)\n\n! reduce Euler angles to definition ranges (and positive values only)\nif (res(1).lt.0.0) res(1) = mod(res(1)+100.0*sngl(cPi),2.0*sngl(cPi))\nif (res(2).lt.0.0) res(2) = mod(res(2)+100.0*sngl(cPi),sngl(cPi))\nif (res(3).lt.0.0) res(3) = mod(res(3)+100.0*sngl(cPi),2.0*sngl(cPi))\n\nend function qu2eu\n\n!--------------------------------------------------------------------------\n!\n! Function: qu2eu_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief Quaternion to Euler angles (double precision) [Morawiec page 40, with errata !!!! ]\n!\n!> @param q quaternion (double precision) \n!> \n!\n!> @date 8/04/13 MDG 1.0 original\n!> @date 4/17/15 MDG 1.1 simplification based on M. Jackson question\n!--------------------------------------------------------------------------\nrecursive function qu2eu_d(q) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: qu2eu_d\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: q(4) !< quaternion\nreal(kind=dbl) :: res(3)\n \nreal(kind=dbl) :: qq(4), q12, q03, chi, Phi, phi1, phi2\n\nqq = q\n\nq03 = qq(1)**2+qq(4)**2\nq12 = qq(2)**2+qq(3)**2\nchi = dsqrt(q03*q12)\n\nif (close_enough(chi,0.D0)) then\n if (close_enough(q12,0.D0)) then \n Phi = 0.D0\n phi2 = 0.D0 ! arbitrarily due to degeneracy\n phi1 = datan2(-epsijk*2.D0*qq(1)*qq(4),qq(1)**2-qq(4)**2)\n else\n Phi = cPi\n phi2 = 0.D0 ! arbitrarily due to degeneracy\n phi1 = datan2(2.D0*qq(2)*qq(3),qq(2)**2-qq(3)**2)\n end if\nelse ! this is not a special degenerate case\n Phi = datan2( 2.D0*chi, q03-q12 )\n chi = 1.D0/chi\n phi1 = datan2( (-epsijk*qq(1)*qq(3)+qq(2)*qq(4))*chi, (-epsijk*qq(1)*qq(2)-qq(3)*qq(4))*chi )\n phi2 = datan2( (epsijk*qq(1)*qq(3)+qq(2)*qq(4))*chi, (-epsijk*qq(1)*qq(2)+qq(3)*qq(4))*chi )\nend if\n\nres = (/ phi1, Phi, phi2 /)\n\n! reduce Euler angles to definition ranges (and positive values only)\nif (res(1).lt.0.D0) res(1) = dmod(res(1)+100.D0*cPi,2.D0*cPi)\nif (res(2).lt.0.D0) res(2) = dmod(res(2)+100.D0*cPi,cPi)\nif (res(3).lt.0.D0) res(3) = dmod(res(3)+100.D0*cPi,2.D0*cPi)\n\nend function qu2eu_d\n\n\n\n!--------------------------------------------------------------------------\n!\n! Function: ax2ho\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief Axis angle pair to homochoric (single precision)\n!\n!> @param a axis-angle pair (single precision) \n!> \n! !\n!> @date 8/04/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ax2ho(a) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ax2ho\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: a(4) !< axis angle pair\nreal(kind=sgl) :: res(3)\n \nreal(kind=sgl) :: f\n\n! a(4) must be in [0,pi] !\n\nf = 0.75 * ( a(4) - sin(a(4)) )\nf = f**(1.0/3.0)\n\nres = a(1:3) * f\n\nend function ax2ho\n\n!--------------------------------------------------------------------------\n!\n! Function: ax2ho_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief Axis angle pair to homochoric (double precision)\n!\n!> @param a axis-angle pair (double precision) \n!> \n! !\n!> @date 8/04/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ax2ho_d(a) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ax2ho_d\n\nuse local\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: a(4) !< axis angle pair\nreal(kind=dbl) :: res(3)\n\nreal(kind=dbl) :: f\n\n! a(4) must be in [0,pi] !\n\nf = 0.75D0 * ( a(4) - dsin(a(4)) )\nf = f**(1.D0/3.D0)\n\nres = a(1:3) * f\n\nend function ax2ho_d\n\n!--------------------------------------------------------------------------\n!\n! Function: ho2ax\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief Homochoric to axis angle pair (single precision)\n!\n!> @param h homochoric coordinates (single precision) \n!> \n! \n!\n!> @date 08/04/13 MDG 1.0 original\n!> @date 07/21/14 MDG 1.1 double precision fit coefficients\n!> @date 03/28/16 MDG 1.2 increased order of fit coefficients\n!--------------------------------------------------------------------------\nrecursive function ho2ax(h) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ho2ax\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: h(3) !< homochoric coordinates\nreal(kind=sgl) :: res(4)\n\ninteger(kind=irg) :: i\nreal(kind=sgl) :: hn(3), hmag, s, hm, sPi\nreal(kind=sgl),parameter :: thr = 1.0E-6\n\nsPi = sngl(cPi)\n\n! normalize h and store the magnitude\nhmag = sum(h*h)\nif (close_enough(hmag,0.0)) then\n res = (/ 0.0, 0.0, 1.0, 0.0 /)\nelse\n hm = hmag\n hn = h/sqrt(hmag)\n\n! convert the magnitude to the rotation angle\n s = LPs%tfit(1) + LPs%tfit(2) * hmag\n! do i=3,16\n do i=3,21\n hm = hm*hmag\n s = s + LPS%tfit(i) * hm\n end do\n\n s = 2.0*acos(s)\n if (abs(s-sngl(cPi)).lt.thr) then \n res = (/ hn(1), hn(2), hn(3), sPi /)\n else\n res = (/ hn(1), hn(2), hn(3), s /)\n end if\nend if\n\nend function ho2ax\n\n!--------------------------------------------------------------------------\n!\n! Function: ho2ax_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief Homochoric to axis angle pair (double precision)\n!\n!> @param h homochoric coordinates (double precision) \n!> \n!\n!> @date 08/04/13 MDG 1.0 original\n!> @date 07/21/14 MDG 1.1 double precision fit coefficients\n!> @date 03/28/16 MDG 1.2 increased order of fit coefficients\n!--------------------------------------------------------------------------\nrecursive function ho2ax_d(h) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ho2ax_d\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: h(3) !< homochoric coordinates\nreal(kind=dbl) :: res(4)\n\ninteger(kind=irg) :: i\nreal(kind=dbl) :: hn(3), hmag, s, hm\nreal(kind=dbl),parameter :: thr = 1.0E-8\n\n! normalize h and store the magnitude\nhmag = sum(h*h)\nif (close_enough(hmag,0.D0)) then\n res = (/ 0.D0, 0.D0, 1.D0, 0.D0 /)\nelse\n hm = hmag\n hn = h/dsqrt(hmag)\n\n! convert the magnitude to the rotation angle\n s = LPs%tfit(1) + LPs%tfit(2) * hmag\n! do i=3,16\n do i=3,21\n hm = hm*hmag\n s = s + LPS%tfit(i) * hm\n end do\n\n s = 2.D0*dacos(s)\n if (dabs(s-cPi).lt.thr) then \n res = (/ hn(1), hn(2), hn(3), cPi /)\n else\n res = (/ hn(1), hn(2), hn(3), s /)\n end if\nend if\n\nend function ho2ax_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: om2ax\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert orientation matrix to axis angle\n!\n!> @details this assumes that the matrix represents a passive rotation.\n!\n!> @param om 3x3 orientation matrix (single precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!> @date 07/08/14 MDG 2.0 replaced by direct solution\n!> @date 09/28/15 MDG 2.1 corrected dgeev -> sgeev\n!> @date 10/25/17 MDG 2.2 corrected issue in which the WORK space was too small\n!--------------------------------------------------------------------------\nrecursive function om2ax(om) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: om2ax\n\nuse local \nuse constants\nuse error\nuse io\n\nreal(kind=sgl), INTENT(IN) :: om(3,3)\nreal(kind=sgl) :: res(4)\n\nreal(kind=sgl) :: t, omega, qq(4), o(3,3)\nreal(kind=sgl) :: VL(3,3), VR(3,3), Wr(3), Wi(3), WORK(20)\ncomplex(kind=sgl) :: ev\ncomplex(kind=sgl),parameter :: cone = cmplx(1.0,0.0)\nreal(kind=sgl),parameter :: thr = 1.0E-6\ninteger(kind=irg) :: nn, LDA, LDVL, LDVR, INFO, LWORK\ncharacter(1) :: JOBVL, JOBVR\n\n o = om\n\n! first get the rotation angle\n t = 0.50*(om(1,1)+om(2,2)+om(3,3) - 1.0)\n if (t.gt.1.0) t = 1.0\n if (t.lt.-1.0) t = -1.0\n res(4) = acos(t)\n\nif (close_enough(res(4),0.0)) then\n res(1:3) = (/ 0.0, 0.0, 1.0 /)\n return\nelse\n! set some initial LAPACK variables \n nn = 3\n LDA = nn\n LDVL = nn\n LDVR = nn\n INFO = 0\n \n! first initialize the parameters for the LAPACK DGEEV routines\n JOBVL = 'N' ! do not compute the left eigenvectors\n JOBVR = 'V' ! do compute the right eigenvectors\n LWORK = 20 \n\n! SUBROUTINE SGEEV( JOBVL, JOBVR, N, A, LDA, WR, WI, VL, LDVL, VR,\n! $ LDVR, WORK, LWORK, INFO )\n\n! call the eigenvalue solver\n call sgeev(JOBVL,JOBVR,nn,o,LDA,Wr,Wi,VL,LDVL,VR,LDVR,WORK,LWORK,INFO)\n if (INFO.ne.0) call FatalError('Error in om2ax/sgeev : ','SGEEV return not zero')\n\n! next, find the eigenvalue cmplx(1,0)\n do i=1,3 \n ev = cmplx(Wr(i),Wi(i))\n if (abs(ev-cone).lt.thr) then\n res(1:3) = VR(1:3,i)\n if ((om(2,3)-om(3,2)).ne.0.D0) res(1) = sign(res(1),-epsijk*(om(2,3)-om(3,2)))\n if ((om(3,1)-om(1,3)).ne.0.D0) res(2) = sign(res(2),-epsijk*(om(3,1)-om(1,3)))\n if ((om(1,2)-om(2,1)).ne.0.D0) res(3) = sign(res(3),-epsijk*(om(1,2)-om(2,1)))\n return\n end if\n end do\nend if\n\nend function om2ax\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: om2ax_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert orientation matrix to axis angle\n!\n!> @param om 3x3 orientation matrix (double precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!> @date 07/08/14 MDG 2.0 replaced by direct solution\n!> @date 08/20/14 MDG 3.0 replaced by eigenvalue-based method\n!> @date 10/25/17 MDG 3.1 corrected issue in which the WORK space was too small\n!--------------------------------------------------------------------------\nrecursive function om2ax_d(om) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: om2ax_d\n\nuse local \nuse constants\nuse error\nuse io\n\nreal(kind=dbl), INTENT(IN) :: om(3,3)\nreal(kind=dbl) :: res(4)\n\nreal(kind=dbl) :: t, omega, qq(4), o(3,3)\nreal(kind=dbl) :: VL(3,3), VR(3,3), Wr(3), Wi(3), WORK(20)\ncomplex(kind=dbl) :: ev\ncomplex(kind=dbl),parameter :: cone = cmplx(1.D0,0.D0)\nreal(kind=dbl),parameter :: thr = 1.0D-14\ninteger(kind=irg) :: nn, LDA, LDVL, LDVR, INFO, LWORK\ncharacter(1) :: JOBVL, JOBVR\n\n o = om\n\n! first get the rotation angle\n t = 0.5D0*(om(1,1)+om(2,2)+om(3,3) - 1.D0)\n if (t.gt.1.D0) t = 1.D0\n if (t.lt.-1.D0) t = -1.D0\n res(4) = dacos(t)\n\nif (close_enough(res(4),0.D0)) then\n res(1:3) = (/ 0.D0, 0.D0, 1.D0 /)\n return\nelse\n! set some initial LAPACK variables \n nn = 3\n LDA = nn\n LDVL = nn\n LDVR = nn\n INFO = 0\n \n! first initialize the parameters for the LAPACK DGEEV routines\n JOBVL = 'N' ! do not compute the left eigenvectors\n JOBVR = 'V' ! do compute the right eigenvectors\n LWORK = 20 \n\n! SUBROUTINE DGEEV( JOBVL, JOBVR, N, A, LDA, WR, WI, VL, LDVL, VR,\n! $ LDVR, WORK, LWORK, INFO )\n\n! call the eigenvalue solver\n call dgeev(JOBVL,JOBVR,nn,o,LDA,Wr,Wi,VL,LDVL,VR,LDVR,WORK,LWORK,INFO)\n if (INFO.ne.0) call FatalError('Error in om2ax/dgeev : ','DGEEV return not zero')\n\n! next, find the eigenvalue cmplx(1,0)\n do i=1,3 \n if ((abs(Wr(i)-1.D0).lt.thr).and.(abs(Wi(i)).lt.thr)) then\n res(1:3) = VR(1:3,i)\n if ((om(2,3)-om(3,2)).ne.0.D0) res(1) = dsign(res(1),-epsijkd*(om(2,3)-om(3,2)))\n if ((om(3,1)-om(1,3)).ne.0.D0) res(2) = dsign(res(2),-epsijkd*(om(3,1)-om(1,3)))\n if ((om(1,2)-om(2,1)).ne.0.D0) res(3) = dsign(res(3),-epsijkd*(om(1,2)-om(2,1)))\n return\n end if\n end do\nend if\n\nend function om2ax_d\n\n!--------------------------------------------------------------------------\n!\n! Function: ro2ax\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief Rodrigues vector to axis angle pair (single precision)\n!\n!> @param r Rodrigues vector (single precision) \n!> \n! \n!> @date 8/04/13 MDG 1.0 original\n!> @date 8/11/14 MDG 1.1 added infty handling\n!--------------------------------------------------------------------------\nrecursive function ro2ax(r) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ro2ax\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: r(4) !< input Rodrigues vector\nreal(kind=sgl) :: res(4) !< output axis-angle pair\n\nreal(kind=sgl) :: ta, angle, sPi\n\nta = r(4)\nsPi = sngl(cPi)\n\nif (close_enough(ta,0.0)) then \n res = (/ 0.0, 0.0, 1.0, 0.0 /)\n return\nend if\n\nif (ta.eq.infty()) then\n res = (/ r(1), r(2), r(3), sPi /)\nelse\n angle = 2.0*atan(ta)\n ta = 1.0/sqrt(sum(r(1:3)*r(1:3)))\n res = (/ r(1)*ta, r(2)*ta, r(3)*ta, angle /)\nend if\n\nend function ro2ax\n\n!--------------------------------------------------------------------------\n!\n! Function: ro2ax_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief Rodrigues vector to axis angle pair (double precision)\n!\n!> @param r Rodrigues vector (double precision) \n!> \n! \n!> @date 8/04/13 MDG 1.0 original\n!> @date 8/11/14 MDG 1.1 added infty handling\n!--------------------------------------------------------------------------\nrecursive function ro2ax_d(r) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ro2ax_d\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: r(4) !< input Rodrigues vector\nreal(kind=dbl) :: res(4) !< output axis-angle pair\n\nreal(kind=dbl) :: ta, angle\n\nta = r(4)\n\nif (close_enough(ta,0.D0)) then \n res = (/ 0.D0, 0.D0, 1.D0, 0.D0 /)\n return\nend if\n\nif (ta.eq.inftyd()) then\n res = (/ r(1), r(2), r(3), cPi /)\nelse\n angle = 2.D0*datan(ta)\n ta = 1.D0/dsqrt(sum(r(1:3)*r(1:3)))\n res = (/ r(1)*ta, r(2)*ta, r(3)*ta, angle /)\nend if\n\nend function ro2ax_d\n\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: ax2ro\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert axis angle to Rodrigues\n!\n!> @param a axis angle pair (single precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!> @date 7/6/14 MDG 2.0 simplified\n!> @date 8/11/14 MDG 2.1 added infty handling\n!--------------------------------------------------------------------------\nrecursive function ax2ro(a) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ax2ro\n\nuse local \nuse constants\n\nreal(kind=sgl), INTENT(IN) :: a(4)\nreal(kind=sgl) :: res(4)\n\nreal(kind=sgl) :: t\nreal(kind=sgl),parameter :: thr = 1.0E-7\n\nif (close_enough(a(4),0.0)) then\n res = (/ 0.0, 0.0, epsijk, 0.0 /)\n return\nend if\n\nres(1:3) = a(1:3)\n\n! we need to deal with the 180 degree case\nif (abs(a(4)-sngl(cPi)).lt.thr) then\n!if (close_enough(abs(a(4)-sngl(cPi)),0.0)) then\n res(4) = infty()\nelse\n res(4) = tan( a(4) * 0.5 )\nend if\n\nend function ax2ro\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: ax2ro_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert axis angle to Rodrigues\n!\n!> @param a axis angle pair (double precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!> @date 7/6/14 MDG 2.0 simplified\n!> @date 8/11/14 MDG 2.1 added infty handling\n!--------------------------------------------------------------------------\nrecursive function ax2ro_d(a) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ax2ro_d\n\nuse local \nuse constants\n\nreal(kind=dbl), INTENT(IN) :: a(4)\nreal(kind=dbl) :: res(4)\n\nreal(kind=sgl) :: t\nreal(kind=sgl),parameter :: thr = 1.0E-7\n\nif (a(4).eq.0.D0) then\n res = (/ 0.D0, 0.D0, epsijkd, 0.D0 /)\n return\nend if\n\nres(1:3) = a(1:3)\n\n! we need to deal with the 180 degree case\nif (dabs(a(4)-cPi).lt.thr) then\n!if (close_enough(dabs(a(4)-cPi),0.D0)) then\n res(4) = inftyd()\nelse\n res(4) = dtan( a(4) * 0.5D0 )\nend if\n\nend function ax2ro_d\n\n\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: ax2qu\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert axis angle to quaternion\n!\n!> @param a axis angle pair (single precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!> @date 7/23/14 MDG 1.1 explicit transformation\n!--------------------------------------------------------------------------\nrecursive function ax2qu(a) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ax2qu\n\nuse local \n\nreal(kind=sgl), INTENT(IN) :: a(4)\nreal(kind=sgl) :: res(4), c, s\n\n\nif (close_enough(a(4),0.0)) then\n res = (/ 1.0, 0.0, 0.0, 0.0 /)\nelse\n c = cos(a(4)*0.5)\n s = sin(a(4)*0.5)\n res = (/ c, a(1)*s, a(2)*s, a(3)*s /)\nend if\n\nend function ax2qu\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: ax2qu_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert axis angle to quaternion\n!\n!> @param a axis angle pair (double precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!> @date 7/23/14 MDG 1.1 explicit transformation\n!--------------------------------------------------------------------------\nrecursive function ax2qu_d(a) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ax2qu_d\n\nuse local \n\nreal(kind=dbl), INTENT(IN) :: a(4)\nreal(kind=dbl) :: res(4), c, s\n\n\nif (close_enough(a(4),0.D0)) then\n res = (/ 1.D0, 0.D0, 0.D0, 0.D0 /)\nelse\n c = dcos(a(4)*0.5D0)\n s = dsin(a(4)*0.5D0)\n res = (/ c, a(1)*s, a(2)*s, a(3)*s /)\nend if\n\nend function ax2qu_d\n\n\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: ro2ho\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert rodrigues to homochoric\n!\n!> @param r Rodrigues vector (single precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!> @date 7/24/14 MDG 2.0 explicit transformation\n!> @date 8/11/14 MDG 3.0 added infty handling\n!--------------------------------------------------------------------------\nrecursive function ro2ho(r) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ro2ho\n\nuse local \nuse constants\n\nreal(kind=sgl), INTENT(IN) :: r(4)\nreal(kind=sgl) :: res(3), rv, f, t\n\nrv = sum(r(1:3)*r(1:3))\nif (close_enough(rv,0.0)) then\n res = (/ 0.0, 0.0, 0.0 /)\n return\nend if\n\nif (r(4).eq.infty()) then\n f = 0.750 * sngl(cPi)\nelse\n t = 2.0*atan(r(4))\n f = 0.750*(t- sin(t))\nend if\n\nres(1:3) = r(1:3) * f**0.333333333\n\nend function ro2ho\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: ro2ho_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert rodrigues to homochoric\n!\n!> @param r Rodrigues vector (double precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!> @date 7/24/14 MDG 2.0 explicit transformation\n!--------------------------------------------------------------------------\nrecursive function ro2ho_d(r) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ro2ho_d\n\nuse local \nuse constants\n\nreal(kind=dbl), INTENT(IN) :: r(4)\nreal(kind=dbl) :: res(3), rv, f, t\n\nrv = sum(r(1:3)*r(1:3))\nif (close_enough(rv,0.D0)) then\n res = (/ 0.D0, 0.D0, 0.D0 /)\n return\nend if\n\nif (r(4).eq.inftyd()) then\n f = 0.75D0 * cPi\nelse\n t = 2.D0*datan(r(4))\n f = 0.75D0*(t- dsin(t))\nend if\n\nres(1:3) = r(1:3) * f**0.333333333D0\n\nend function ro2ho_d\n\n\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: qu2om\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert a quaternion to a 3x3 matrix\n!\n!> @param q quaternion (single precision) \n!> \n! \n!> @note verified 8/5/13\n!\n!> @date 6/03/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function qu2om(q) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: qu2om\n\nuse local\nuse constants\n\nreal(kind=sgl),INTENT(IN) :: q(4)\nreal(kind=sgl) :: res(3,3)\n\nreal(kind=sgl) :: qq, qc(4)\n\nqq=q(1)*q(1)-(q(2)*q(2)+q(3)*q(3)+q(4)*q(4))\n\nqc = q\n\nres(1,1) = qq+2.0*qc(2)*qc(2)\nres(2,2) = qq+2.0*qc(3)*qc(3)\nres(3,3) = qq+2.0*qc(4)*qc(4)\n\nres(1,2) = 2.0*(qc(2)*qc(3)-qc(1)*qc(4))\nres(2,3) = 2.0*(qc(3)*qc(4)-qc(1)*qc(2))\nres(3,1) = 2.0*(qc(4)*qc(2)-qc(1)*qc(3))\nres(2,1) = 2.0*(qc(3)*qc(2)+qc(1)*qc(4))\nres(3,2) = 2.0*(qc(4)*qc(3)+qc(1)*qc(2))\nres(1,3) = 2.0*(qc(2)*qc(4)+qc(1)*qc(3))\n\nif (epsijk.ne.1.0) res = transpose(res)\n\nend function qu2om\n\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: qu2om_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert a quaternion to a 3x3 matrix (double precision)\n!\n!> @param q quaternion (double precision) \n!> \n! \n!> @note verified 8/5/13\n!\n!> @date 6/03/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function qu2om_d(q) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: qu2om_d\n\nuse local\nuse constants\n\nreal(kind=dbl),INTENT(IN) :: q(4)\nreal(kind=dbl) :: res(3,3)\n\nreal(kind=dbl) :: qq, qc(4)\n\nqq=q(1)*q(1)-(q(2)*q(2)+q(3)*q(3)+q(4)*q(4))\n\nqc = q\n\nres(1,1) = qq+2.D0*qc(2)*qc(2)\nres(2,2) = qq+2.D0*qc(3)*qc(3)\nres(3,3) = qq+2.D0*qc(4)*qc(4)\n\nres(1,2) = 2.D0*(qc(2)*qc(3)-qc(1)*qc(4))\nres(2,3) = 2.D0*(qc(3)*qc(4)-qc(1)*qc(2))\nres(3,1) = 2.D0*(qc(4)*qc(2)-qc(1)*qc(3))\nres(2,1) = 2.D0*(qc(3)*qc(2)+qc(1)*qc(4))\nres(3,2) = 2.D0*(qc(4)*qc(3)+qc(1)*qc(2))\nres(1,3) = 2.D0*(qc(2)*qc(4)+qc(1)*qc(3))\n\nif (epsijkd.ne.1.D0) res = transpose(res)\n\nend function qu2om_d\n\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: om2qu\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert a 3x3 rotation matrix to a unit quaternion (see Morawiec, page 37)\n!\n!> @param x 3x3 matrix to be converted (single precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!> @date 8/18/14 MDG 2.0 new version\n!--------------------------------------------------------------------------\nrecursive function om2qu(x) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: om2qu\n\nuse local \nuse constants\n\nreal(kind=sgl), INTENT(IN) :: x(3,3) !< input matrix\nreal(kind=sgl) :: res(4)\n\nreal(kind=sgl) :: s, s1, s2, s3, oax(4)\n\ns = x(1,1) + x(2,2) + x(3,3) + 1.0\nif (abs(s).lt.thr) s = 0.0\ns = sqrt(s)\n\ns1 = x(1,1) - x(2,2) - x(3,3) + 1.0\nif (abs(s1).lt.thr) s1 = 0.0\ns1 = sqrt(s1)\n\ns2 = -x(1,1) + x(2,2) - x(3,3) + 1.0\nif (abs(s2).lt.thr) s2 = 0.0\ns2 = sqrt(s2)\n\ns3 = -x(1,1) - x(2,2) + x(3,3) + 1.0\nif (abs(s3).lt.thr) s3 = 0.0\ns3 = sqrt(s3)\n\nres = (/ s, s1, s2, s3 /) * 0.5\n\n! verify the signs (q0 always positive)\nif (x(3,2).lt.x(2,3)) res(2) = -epsijk * res(2)\nif (x(1,3).lt.x(3,1)) res(3) = -epsijk * res(3)\nif (x(2,1).lt.x(1,2)) res(4) = -epsijk * res(4)\n\n! normalize\ns = sqrt(sum(res*res))\nif (s.ne.0.0) res = res/s\n\n! we need to do a quick test here to make sure that the \n! sign of the vector part is the same as that of the \n! corresponding vector in the axis-angle representation;\n! these two can end up being different, presumably due to rounding \n! issues, but this needs to be further analyzed...\n! This adds a little bit of computation overhead but for now it\n! is the easiest way to make sure the signs are correct.\noax = om2ax(x)\nif (oax(1)*res(2).lt.0.0) res(2) = -res(2)\nif (oax(2)*res(3).lt.0.0) res(3) = -res(3)\nif (oax(3)*res(4).lt.0.0) res(4) = -res(4)\n\nend function om2qu\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: om2qu_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert a 3x3 rotation matrix to a unit quaternion (see Morawiec, page 37)\n!\n!> @param x 3x3 matrix to be converted (double precision)\n! \n!> @date 8/12/13 MDG 1.0 original\n!> @date 8/18/14 MDG 2.0 new version\n!--------------------------------------------------------------------------\nrecursive function om2qu_d(x) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: om2qu_d\n\nuse local \nuse constants\n\nreal(kind=dbl), INTENT(IN) :: x(3,3) !< input matrix\nreal(kind=dbl) :: res(4)\n\nreal(kind=dbl) :: s, s1, s2, s3, oax(4)\nreal(kind=dbl),parameter :: thr = 1.0D-10\n\ns = x(1,1) + x(2,2) + x(3,3) + 1.D0\nif (abs(s).lt.thr) s = 0.D0\ns = dsqrt(s)\n\ns1 = x(1,1) - x(2,2) - x(3,3) + 1.D0\nif (abs(s1).lt.thr) s1 = 0.D0\ns1 = dsqrt(s1)\n\ns2 = -x(1,1) + x(2,2) - x(3,3) + 1.D0\nif (abs(s2).lt.thr) s2 = 0.D0\ns2 = dsqrt(s2)\n\ns3 = -x(1,1) - x(2,2) + x(3,3) + 1.D0\nif (abs(s3).lt.thr) s3 = 0.D0\ns3 = dsqrt(s3)\n\nres = (/ s, s1, s2, s3 /) * 0.5\n\n! verify the signs (q0 always positive)\nif (epsijkd.eq.1.D0) then\n if (x(3,2).lt.x(2,3)) res(2) = -epsijkd * res(2)\n if (x(1,3).lt.x(3,1)) res(3) = -epsijkd * res(3)\n if (x(2,1).lt.x(1,2)) res(4) = -epsijkd * res(4)\nend if\n\n! normalize\ns = dsqrt(sum(res*res))\nif (s.ne.0.D0) res = res/s\n\n! we need to do a quick test here to make sure that the \n! sign of the vector part is the same as that of the \n! corresponding vector in the axis-angle representation;\n! these two can end up being different, presumably due to rounding \n! issues, but this needs to be further analyzed...\n! This adds a little bit of computation overhead but for now it\n! is the easiest way to make sure the signs are correct.\noax = om2ax(x)\nif (oax(1)*res(2).lt.0.D0) res(2) = -res(2)\nif (oax(2)*res(3).lt.0.D0) res(3) = -res(3)\nif (oax(3)*res(4).lt.0.D0) res(4) = -res(4)\n\nend function om2qu_d\n\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: qu2ax\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert quaternion to axis angle\n!\n!> @param q quaternion (single precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!> @date 7/23/14 MDG 2.0 explicit transformation\n!--------------------------------------------------------------------------\nrecursive function qu2ax(q) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: qu2ax\n\nuse local \nuse constants\n\nreal(kind=sgl), INTENT(IN) :: q(4)\nreal(kind=sgl) :: res(4), omega, s, sPi\n\nomega = 2.0 * acos(q(1))\nsPi = sngl(cPi)\n\n! if the angle equals zero, then we return the rotation axis as [001]\nif (close_enough(omega,0.0)) then\n res = (/ 0.0, 0.0, 1.0, 0.0 /)\nelse\n if (q(1).ne.0.0) then\n s = (q(1)/abs(q(1)))/sqrt(q(2)**2+q(3)**2+q(4)**2)\n res = (/ q(2)*s, q(3)*s, q(4)*s, omega /)\n else\n res = (/ q(2), q(3), q(4), sPi /)\n end if\nend if\n\nend function qu2ax\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: qu2ax_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert quaternion to axis angle\n!\n!> @param q quaternion (double precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!> @date 7/23/14 MDG 2.0 explicit transformation\n!--------------------------------------------------------------------------\nrecursive function qu2ax_d(q) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: qu2ax_d\n\nuse local \nuse constants\n\nreal(kind=dbl), INTENT(IN) :: q(4)\nreal(kind=dbl) :: res(4), omega, s\n\nomega = 2.D0 * dacos(q(1))\n! if the angle equals zero, then we return the rotation axis as [001]\nif (close_enough(omega,0.D0)) then\n res = (/ 0.D0, 0.D0, 1.D0, 0.D0 /)\nelse\n if (q(1).ne.0.D0) then\n s = (q(1)/abs(q(1)))/dsqrt(q(2)**2+q(3)**2+q(4)**2)\n res = (/ q(2)*s, q(3)*s, q(4)*s, omega /)\n else\n res = (/ q(2), q(3), q(4), cPi /)\n end if\nend if\n\nend function qu2ax_d\n\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: qu2ro\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert quaternion to Rodrigues\n!\n!> @param q quaternion (single precision)\n! \n!> @date 8/12/13 MDG 1.0 original\n!> @date 7/23/14 MDG 2.0 direct transformation\n!> @date 8/11/14 MDG 2.1 added infty handling\n!--------------------------------------------------------------------------\nrecursive function qu2ro(q) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: qu2ro\n\nuse local \nuse constants\n\nreal(kind=sgl), INTENT(IN) :: q(4)\nreal(kind=sgl) :: res(4), omega, t, s\nreal(kind=sgl),parameter :: thr = 1.0E-8\n\nres(1:3) = q(2:4)\nres(4) = 0.0\n\nif (q(1).lt.thr) then\n res(4)=infty()\n return\nend if\n\ns = sqrt(sum(res(1:3)*res(1:3)))\nif (s.lt.thr) then\n res = (/ 0.0, 0.0, epsijk, 0.0 /)\n return\nelse\n t = tan(acos(q(1)))\n res = (/ res(1)/s, res(2)/s, res(3)/s, t /)\nend if\n\nend function qu2ro\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: qu2ro_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert quaternion to Rodrigues\n!\n!> @param q quaternion (double precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!> @date 7/23/14 MDG 2.0 direct transformation\n!> @date 8/11/14 MDG 2.1 added infty handling\n!--------------------------------------------------------------------------\nrecursive function qu2ro_d(q) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: qu2ro_d\n\nuse local \nuse constants\n\nreal(kind=dbl), INTENT(IN) :: q(4)\nreal(kind=dbl) :: res(4), omega, s, t\nreal(kind=dbl),parameter :: thr = 1.0D-10\n\nres(1:3) = q(2:4)\nres(4) = 0.D0\n\nif (q(1).lt.thr) then\n res(4)=inftyd()\n return\nend if\n\ns = dsqrt(sum(res(1:3)*res(1:3)))\nif (s.lt.thr) then\n res = (/ 0.D0, 0.D0, epsijkd, 0.D0 /)\n return\nelse\n t = dtan(dacos(q(1)))\n res = (/ res(1)/s, res(2)/s, res(3)/s, t /)\nend if\n\nend function qu2ro_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: qu2ho\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert quaternion to homochoric\n!\n!> @param q quaternion (single precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!> @date 7/23/14 MDG 2.0 explicit transformation\n!--------------------------------------------------------------------------\nrecursive function qu2ho(q) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: qu2ho\n\nuse local \n\nreal(kind=sgl), INTENT(IN) :: q(4)\nreal(kind=sgl) :: res(3), omega, s, f\n\nomega = 2.0 * acos(q(1))\nif (close_enough(omega,0.0)) then\n res = (/ 0.0, 0.0, 0.0 /)\nelse\n res = q(2:4)\n s = 1.0/sqrt(sum(res**2))\n res = res * s\n f = 0.75 * ( omega - sin(omega) )\n res = res * f**0.333333333\nend if\n\nend function qu2ho\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: qu2ho_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert quaternion to homochoric\n!\n!> @param q quaternion (double precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!> @date 7/23/14 MDG 2.0 explicit transformation\n!--------------------------------------------------------------------------\nrecursive function qu2ho_d(q) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: qu2ho_d\n\nuse local \n\nreal(kind=dbl), INTENT(IN) :: q(4)\nreal(kind=dbl) :: res(3), omega, s, f\n\nomega = 2.D0 * dacos(q(1))\nif (close_enough(omega,0.D0)) then\n res = (/ 0.D0, 0.D0, 0.D0 /)\nelse\n res = q(2:4)\n s = 1.D0/dsqrt(sum(res**2))\n res = res * s\n f = 0.75D0 * ( omega - dsin(omega) )\n res = res * f**0.333333333D0\nend if\n\nend function qu2ho_d\n!--------------------------------------------------------------------------\n!\n! FUNCTION: ho2cu\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert homochoric to cubochoric\n!\n!> @param h homochoric coordinates (single precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ho2cu(h) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ho2cu\n\nuse local\nuse Lambert, only: LambertBallToCube\n\nreal(kind=sgl), INTENT(IN) :: h(3) !< input coordinates\nreal(kind=sgl) :: res(3)\n\ninteger(kind=irg) :: ierr\n\n! calling program must have initialized the Lambert parameters!!!!\n!> \nres = LambertBallToCube(h,ierr)\n\nend function ho2cu\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: ho2cu_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert homochoric to cubochoric\n!\n!> @param h homochoric coordinates (double precision)\n!> \n!\n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ho2cu_d(h) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ho2cu_d\n\nuse local \nuse Lambert, only: LambertBallToCube\n\nreal(kind=dbl), INTENT(IN) :: h(3) !< input coordinates\nreal(kind=dbl) :: res(3)\n\ninteger(kind=irg) :: ierr\n\n! calling program must have initialized the Lambert parameters!!!!\n!> \nres = LambertBallToCube(h,ierr)\n\nend function ho2cu_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: cu2ho\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert cubochoric to homochoric\n!\n!> @param c cubochoric coordinates (single precision)\n!> \n! \n!\n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function cu2ho(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: cu2ho\n\nuse local \nuse Lambert, only: LambertCubeToBall\n\nreal(kind=sgl), INTENT(IN) :: c(3) !< input coordinates\nreal(kind=sgl) :: res(3)\n\ninteger(kind=irg) :: ierr\n\n! calling program must have initialized the Lambert parameters!!!!\n!> \nres = LambertCubeToBall(c,ierr)\n\nend function cu2ho\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: cu2ho_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert cubochoric to homochoric\n!\n!> @param c cubochoric coordinates (double precision)\n!> \n! \n!\n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function cu2ho_d(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: cu2ho_d\n\nuse local \nuse Lambert, only: LambertCubeToBall\n\nreal(kind=dbl), INTENT(IN) :: c(3) !< input coordinates\nreal(kind=dbl) :: res(3)\n\ninteger(kind=irg) :: ierr\n\n! calling program must have initialized the Lambert parameters!!!!\n!> \nres = LambertCubeToBall(c,ierr)\n\nend function cu2ho_d\n\n\n!--------------------------------------------------------------------------\n!--------------------------------------------------------------------------\n!--------------------------------------------------------------------------\n!--------------------------------------------------------------------------\n!--------------------------------------------------------------------------\n!--------------------------------------------------------------------------\n! and here are a bunch of transformation routines that are derived from the others\n!--------------------------------------------------------------------------\n!--------------------------------------------------------------------------\n!--------------------------------------------------------------------------\n!--------------------------------------------------------------------------\n!--------------------------------------------------------------------------\n!--------------------------------------------------------------------------\n\n!--------------------------------------------------------------------------\n!\n! Function: ro2eu\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief Rodrigues vector to Euler angles (single precision)\n!\n!> @param r Rodrigues vector (single precision) \n!> \n!\n!> @date 8/04/13 MDG 1.0 original\n!> @date 8/11/14 MDG 1.1 added infty handling\n!> @date 10/20/17 MDG 1.2 check for small values that could cause rounding issues in other routines\n!--------------------------------------------------------------------------\nrecursive function ro2eu(r) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ro2eu\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: r(4) !< Rodrigues vector\nreal(kind=sgl) :: res(3)\n \nreal(kind=sgl) :: rr(3), s, d, eps = 1.0e-8\ninteger(kind=irg) :: i, j\nreal(kind=sgl), parameter :: pivals(4) = (/ 1.570796326794, 3.141592653589, 4.712388980384, 6.283185307179 /)\n\nres = om2eu(ro2om(r))\n\ndo i=1,3\n if (abs(res(i)).lt.eps) res(i) = 0.0\n do j=1,4\n if (abs(res(i)-pivals(j)).lt.eps) res(i) = pivals(j)\n end do \nend do\n\nend function ro2eu\n\n!--------------------------------------------------------------------------\n!\n! Function: ro2eu_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief Rodrigues vector to Euler angles (double precision)\n!\n!> @param r Rodrigues vector (double precision) \n!> \n! \n!> @date 8/04/13 MDG 1.0 original\n!> @date 8/11/14 MDG 1.1 added infty handling\n!> @date 10/20/17 MDG 1.2 check for small values that could cause rounding issues in other routines\n!--------------------------------------------------------------------------\nrecursive function ro2eu_d(r) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ro2eu_d\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: r(4) !< Rodrigues vector\nreal(kind=dbl) :: res(3)\n\nreal(kind=dbl) :: rr(3), s, d, eps = 1.0D-12\ninteger(kind=irg) :: i, j\nreal(kind=dbl), parameter :: pivals(4) = (/ cPi*0.5D0, cPi, 3.D0*cPi*0.5D0, 2.D0*cPi /)\n\nres = om2eu_d(ro2om_d(r))\n\ndo i=1,3\n if (abs(res(i)).lt.eps) res(i) = 0.D0\n do j=1,4\n if (abs(res(i)-pivals(j)).lt.eps) res(i) = pivals(j)\n end do \nend do\n\nend function ro2eu_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: eu2ho\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert euler to homochoric\n!\n!> @param e 3 euler angles (single precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function eu2ho(e) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: eu2ho\n\nuse local \n\nreal(kind=sgl), INTENT(IN) :: e(3)\nreal(kind=sgl) :: res(3)\n\nres = ax2ho(eu2ax(e))\n\nend function eu2ho\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: eu2ho_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert euler to homochoric\n!\n!> @param e 3 euler angles (double precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function eu2ho_d(e) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: eu2ho_d\n\nuse local \n\nreal(kind=dbl), INTENT(IN) :: e(3)\nreal(kind=dbl) :: res(3)\n\nres = ax2ho_d(eu2ax_d(e))\n\nend function eu2ho_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: om2ro\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert orientation matrix to Rodrigues\n!\n!> @param om 3x3 orientation matrix (single precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function om2ro(om) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: om2ro\n\nuse local \n\nreal(kind=sgl), INTENT(IN) :: om(3,3)\nreal(kind=sgl) :: res(4)\n\nres = eu2ro(om2eu(om))\n\nend function om2ro\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: om2ro_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert orientation matrix to Rodrigues\n!\n!> @param om 3x3 orientation matrix (double precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function om2ro_d(om) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: om2ro_d\n\nuse local \n\nreal(kind=dbl), INTENT(IN) :: om(3,3)\nreal(kind=dbl) :: res(4)\n\nres = eu2ro_d(om2eu_d(om))\n\nend function om2ro_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: om2ho\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert orientation matrix to homochoric\n!\n!> @param om 3x3 orientation matrix (single precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!> @date 07/08/14 MDG 2.0 simplification via ax (shorter path)\n!--------------------------------------------------------------------------\nrecursive function om2ho(om) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: om2ho\n\nuse local \n\nreal(kind=sgl), INTENT(IN) :: om(3,3)\nreal(kind=sgl) :: res(3)\n\nres = ax2ho(om2ax(om))\n\nend function om2ho \n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: om2ho_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert orientation matrix to homochoric\n!\n!> @param om 3x3 orientation matrix (double precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!> @date 07/08/14 MDG 2.0 simplification via ax (shorter path)\n!--------------------------------------------------------------------------\nrecursive function om2ho_d(om) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: om2ho_d\n\nuse local \n\nreal(kind=dbl), INTENT(IN) :: om(3,3)\nreal(kind=dbl) :: res(3)\n\nres = ax2ho(om2ax(om))\n\nend function om2ho_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: ax2eu\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert axis angle to euler\n!\n!> @param a axis angle pair (single precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!> @date 07/08/14 MDG 2.0 simplification via ro (shorter path)\n!--------------------------------------------------------------------------\nrecursive function ax2eu(a) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ax2eu\n\nuse local \n\nreal(kind=sgl), INTENT(IN) :: a(4)\nreal(kind=sgl) :: res(3)\n\nres = om2eu(ax2om(a))\n\nend function ax2eu\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: ax2eu_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert axis angle to euler\n!\n!> @param a axis angle pair (double precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!> @date 07/08/14 MDG 2.0 simplification via ro (shorter path)\n!--------------------------------------------------------------------------\nrecursive function ax2eu_d(a) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ax2eu_d\n\nuse local \n\nreal(kind=dbl), INTENT(IN) :: a(4)\nreal(kind=dbl) :: res(3)\n\nres = om2eu(ax2om(a))\n\nend function ax2eu_d\n\n\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: ro2om\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert rodrigues to orientation matrix\n!\n!> @param r Rodrigues vector (single precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ro2om(r) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ro2om\n\nuse local \n\nreal(kind=sgl), INTENT(IN) :: r(4)\nreal(kind=sgl) :: res(3,3)\n\nres = ax2om(ro2ax(r))\n\nend function ro2om\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: ro2om_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert rodrigues to orientation matrix\n!\n!> @param r Rodrigues vector (double precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ro2om_d(r) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ro2om_d\n\nuse local \n\nreal(kind=dbl), INTENT(IN) :: r(4)\nreal(kind=dbl) :: res(3,3)\n\nres = ax2om_d(ro2ax_d(r))\n\nend function ro2om_d\n\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: ro2qu\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert rodrigues to quaternion\n!\n!> @param r Rodrigues vector (single precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ro2qu(r) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ro2qu\n\nuse local \n\nreal(kind=sgl), INTENT(IN) :: r(4)\nreal(kind=sgl) :: res(4)\n\nres = ax2qu(ro2ax(r))\n\nend function ro2qu\n\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: ro2qu_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert rodrigues to quaternion\n!\n!> @param r Rodrigues vector (double precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ro2qu_d(r) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ro2qu_d\n\nuse local \n\nreal(kind=dbl), INTENT(IN) :: r(4)\nreal(kind=dbl) :: res(4)\n\nres = ax2qu_d(ro2ax_d(r))\n\nend function ro2qu_d\n\n\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: ho2eu\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert homochoric to euler\n!\n!> @param h homochoric coordinates (single precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ho2eu(h) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ho2eu\n\nuse local \n\nreal(kind=sgl), INTENT(IN) :: h(3)\nreal(kind=sgl) :: res(3)\n\nres = ax2eu(ho2ax(h))\n\nend function ho2eu\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: ho2eu_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert homochoric to euler\n!\n!> @param h homochoric coordinates (double precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ho2eu_d(h) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ho2eu_d\n\nuse local \n\nreal(kind=dbl), INTENT(IN) :: h(3)\nreal(kind=dbl) :: res(3)\n\nres = ax2eu_d(ho2ax_d(h))\n\nend function ho2eu_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: ho2om\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert homochoric to orientation matrix\n!\n!> @param h homochoric coordinates (single precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ho2om(h) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ho2om\n\nuse local \n\nreal(kind=sgl), INTENT(IN) :: h(3)\nreal(kind=sgl) :: res(3,3)\n\nres = ax2om(ho2ax(h))\n\nend function ho2om\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: ho2om_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert homochoric to orientation matrix\n!\n!> @param h homochoric coordinates (double precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ho2om_d(h) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ho2om_d\n\nuse local \n\nreal(kind=dbl), INTENT(IN) :: h(3)\nreal(kind=dbl) :: res(3,3)\n\nres = ax2om_d(ho2ax_d(h))\n\nend function ho2om_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: ho2ro\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert homochoric to Rodrigues\n!\n!> @param h homochoric coordinates (single precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ho2ro(h) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ho2ro\n\nuse local \n\nreal(kind=sgl), INTENT(IN) :: h(3)\nreal(kind=sgl) :: res(4)\n\nres = ax2ro(ho2ax(h))\n\nend function ho2ro\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: ho2ro_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert homochoric to Rodrigues\n!\n!> @param h homochoric coordinates (double precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ho2ro_d(h) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ho2ro_d\n\nuse local \n\nreal(kind=dbl), INTENT(IN) :: h(3)\nreal(kind=dbl) :: res(4)\n\nres = ax2ro_d(ho2ax_d(h))\n\nend function ho2ro_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: ho2qu\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert homochoric to quaternion\n!\n!> @param h homochoric coordinates (single precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ho2qu(h) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ho2qu\n\nuse local \n\nreal(kind=sgl), INTENT(IN) :: h(3)\nreal(kind=sgl) :: res(4)\n\nres = ax2qu(ho2ax(h))\n\nend function ho2qu\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: ho2qu_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert homochoric to quaternion\n!\n!> @param h homochoric coordinates (double precision)\n!> \n! \n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ho2qu_d(h) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ho2qu_d\n\nuse local \n\nreal(kind=dbl), INTENT(IN) :: h(3)\nreal(kind=dbl) :: res(4)\n\nres = ax2qu_d(ho2ax_d(h))\n\nend function ho2qu_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: eu2cu\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert euler angles to cubochoric\n!\n!> @param e euler angles (single precision)\n!> \n! \n!\n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function eu2cu(e) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: eu2cu\n\nuse local \n\nreal(kind=sgl), INTENT(IN) :: e(3) !< input coordinates\nreal(kind=sgl) :: res(3)\n\nres = ho2cu(eu2ho(e))\n\nend function eu2cu\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: eu2cu_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert euler angles to cubochoric\n!\n!> @param e euler angles (double precision)\n!> \n! \n!\n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function eu2cu_d(e) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: eu2cu_d\n\nuse local \n\nreal(kind=dbl), INTENT(IN) :: e(3) !< input coordinates\nreal(kind=dbl) :: res(3)\n\nres = ho2cu_d(eu2ho_d(e))\n\nend function eu2cu_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: om2cu\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert orientation matrix to cubochoric\n!\n!> @param o orientation matrix (single precision)\n!> \n! \n!\n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function om2cu(o) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: om2cu\n\nuse local \n\nreal(kind=sgl), INTENT(IN) :: o(3,3) !< input coordinates\nreal(kind=sgl) :: res(3)\n\nres = ho2cu(om2ho(o))\n\nend function om2cu\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: om2cu_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert orientation matrix to cubochoric\n!\n!> @param o orientation matrix (double precision)\n!> \n! \n!\n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function om2cu_d(o) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: om2cu_d\n\nuse local \n\nreal(kind=dbl), INTENT(IN) :: o(3,3) !< input coordinates\nreal(kind=dbl) :: res(3)\n\nres = ho2cu_d(om2ho_d(o))\n\nend function om2cu_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: ax2cu\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert axis angle to cubochoric\n!\n!> @param a axis angle (single precision)\n!> \n! \n!\n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ax2cu(a) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ax2cu\n\nuse local \n\nreal(kind=sgl), INTENT(IN) :: a(4) !< input coordinates\nreal(kind=sgl) :: res(3)\n\nres = ho2cu(ax2ho(a))\n\nend function ax2cu\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: ax2cu_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert axis angle to cubochoric\n!\n!> @param a axis angle (double precision)\n!> \n! \n!\n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ax2cu_d(a) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ax2cu_d\n\nuse local \n\nreal(kind=dbl), INTENT(IN) :: a(4) !< input coordinates\nreal(kind=dbl) :: res(3)\n\nres = ho2cu_d(ax2ho_d(a))\n\nend function ax2cu_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: ro2cu\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert Rodrigues to cubochoric\n!\n!> @param r Rodrigues (single precision)\n!> \n! \n!\n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ro2cu(r) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ro2cu\n\nuse local \n\nreal(kind=sgl), INTENT(IN) :: r(4) !< input coordinates\nreal(kind=sgl) :: res(3)\n\nres = ho2cu(ro2ho(r))\n\nend function ro2cu\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: ro2cu_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert Rodrigues to cubochoric\n!\n!> @param r Rodrigues (double precision)\n!> \n! \n!\n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ro2cu_d(r) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ro2cu_d\n\nuse local \n\nreal(kind=dbl), INTENT(IN) :: r(4) !< input coordinates\nreal(kind=dbl) :: res(3)\n\nres = ho2cu_d(ro2ho_d(r))\n\nend function ro2cu_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: qu2cu\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert quaternion to cubochoric\n!\n!> @param q quaternion (single precision)\n!> \n! \n!\n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function qu2cu(q) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: qu2cu\n\nuse local \n\nreal(kind=sgl), INTENT(IN) :: q(4) !< input coordinates\nreal(kind=sgl) :: res(3)\n\nres = ho2cu(qu2ho(q))\n\nend function qu2cu\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: qu2cu_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert quaternion to cubochoric\n!\n!> @param q quaternion (double precision)\n!> \n! \n!\n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function qu2cu_d(q) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: qu2cu_d\n\nuse local \n\nreal(kind=dbl), INTENT(IN) :: q(4) !< input coordinates\nreal(kind=dbl) :: res(3)\n\nres = ho2cu_d(qu2ho_d(q))\n\nend function qu2cu_d\n\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: cu2eu\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert cubochoric to euler angles\n!\n!> @param c cubochoric coordinates (single precision)\n!> \n! \n!\n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function cu2eu(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: cu2eu\n\nuse local \n\nreal(kind=sgl), INTENT(IN) :: c(3) !< input coordinates\nreal(kind=sgl) :: res(3)\n\nres = ho2eu(cu2ho(c))\n\nend function cu2eu\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: cu2eu_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert cubochoric to euler angles\n!\n!> @param c cubochoric coordinates (double precision)\n!> \n! \n!\n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function cu2eu_d(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: cu2eu_d\n\nuse local \n\nreal(kind=dbl), INTENT(IN) :: c(3) !< input coordinates\nreal(kind=dbl) :: res(3)\n\nres = ho2eu_d(cu2ho_d(c))\n\nend function cu2eu_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: cu2om\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert cubochoric to orientation matrix\n!\n!> @param c cubochoric coordinates (single precision)\n!> \n! \n!\n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function cu2om(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: cu2om\n\nuse local \n\nreal(kind=sgl), INTENT(IN) :: c(3) !< input coordinates\nreal(kind=sgl) :: res(3,3)\n\nres = ho2om(cu2ho(c))\n\nend function cu2om\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: cu2om_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert cubochoric to orientation matrix\n!\n!> @param c cubochoric coordinates (double precision)\n!> \n! \n!\n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function cu2om_d(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: cu2om_d\n\nuse local \n\nreal(kind=dbl), INTENT(IN) :: c(3) !< input coordinates\nreal(kind=dbl) :: res(3,3)\n\nres = ho2om_d(cu2ho_d(c))\n\nend function cu2om_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: cu2ax\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert cubochoric to axis angle\n!\n!> @param c cubochoric coordinates (single precision)\n!> \n! \n!\n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function cu2ax(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: cu2ax\n\nuse local \n\nreal(kind=sgl), INTENT(IN) :: c(3) !< input coordinates\nreal(kind=sgl) :: res(4)\n\nres = ho2ax(cu2ho(c))\n\nend function cu2ax\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: cu2ax_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert cubochoric to axis angle\n!\n!> @param c cubochoric coordinates (double precision)\n!> \n! \n!\n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function cu2ax_d(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: cu2ax_d\n\nuse local \n\nreal(kind=dbl), INTENT(IN) :: c(3) !< input coordinates\nreal(kind=dbl) :: res(4)\n\nres = ho2ax_d(cu2ho_d(c))\n\nend function cu2ax_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: cu2ro\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert cubochoric to Rodrigues\n!\n!> @param c cubochoric coordinates (single precision)\n!> \n! \n!\n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function cu2ro(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: cu2ro\n\nuse local \n\nreal(kind=sgl), INTENT(IN) :: c(3) !< input coordinates\nreal(kind=sgl) :: res(4)\n\nif (maxval(abs(c)).eq.0.0) then\n res = (/ 0.0, 0.0, 1.0, 0.0 /)\nelse\n res = ho2ro(cu2ho(c))\nend if\n\nend function cu2ro\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: cu2ro_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert cubochoric to Rodrigues\n!\n!> @param c cubochoric coordinates (double precision)\n!> \n! \n!\n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function cu2ro_d(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: cu2ro_d\n\nuse local \n\nreal(kind=dbl), INTENT(IN) :: c(3) !< input coordinates\nreal(kind=dbl) :: res(4)\n\nif (maxval(dabs(c)).eq.0.0D0) then\n res = (/ 0.D0, 0.D0, 1.D0, 0.D0 /)\nelse\n res = ho2ro_d(cu2ho_d(c))\nend if\n\nend function cu2ro_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: cu2qu\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert cubochoric to quaternion\n!\n!> @param c cubochoric coordinates (single precision)\n!> \n! \n!\n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function cu2qu(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: cu2qu\n\nuse local \n\nreal(kind=sgl), INTENT(IN) :: c(3) !< input coordinates\nreal(kind=sgl) :: res(4)\n\nres = ho2qu(cu2ho(c))\n\nend function cu2qu\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: cu2qu_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert cubochoric to quaternion\n!\n!> @param c cubochoric coordinates (double precision)\n!> \n!\n!> @date 8/12/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function cu2qu_d(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: cu2qu_d\n\nuse local \n\nreal(kind=dbl), INTENT(IN) :: c(3) !< input coordinates\nreal(kind=dbl) :: res(4)\n\nres = ho2qu_d(cu2ho_d(c))\n\nend function cu2qu_d\n\n\n!--------------------------------------------------------------------------\n!--------------------------------------------------------------------------\n! new routines for 3D stereographic representation [added October 2017] \n!--------------------------------------------------------------------------\n!--------------------------------------------------------------------------\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: om2st\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert orientation matrix to stereographic\n!\n!> @param c rotation matrix (single precision)\n!> \n!\n!> @date 10/07/17 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function om2st(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: om2st\n\nuse local \n\nreal(kind=sgl), INTENT(IN) :: c(3,3) !< input \nreal(kind=sgl) :: res(3)\n\nres = qu2st(om2qu(c))\n\nend function om2st\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: om2st_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert orientation matrix to stereographic\n!\n!> @param c rotation matrix (double precision)\n!> \n!\n!> @date 10/07/17 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function om2st_d(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: om2st_d\n\nuse local \n\nreal(kind=dbl), INTENT(IN) :: c(3,3) !< input \nreal(kind=dbl) :: res(3)\n\nres = qu2st_d(om2qu_d(c))\n\nend function om2st_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: ax2st\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert axis-angle pair to stereographic\n!\n!> @param c axis-angle pair (single precision)\n!> \n!\n!> @date 10/07/17 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ax2st(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ax2st\n\nuse local \n\nreal(kind=sgl), INTENT(IN) :: c(4) !< input \nreal(kind=sgl) :: res(3)\n\nres = qu2st(ax2qu(c))\n\nend function ax2st\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: ax2st_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert axis-angle pair to stereographic\n!\n!> @param c axis-angle pair (double precision)\n!> \n!\n!> @date 10/07/17 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ax2st_d(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ax2st_d\n\nuse local \n\nreal(kind=dbl), INTENT(IN) :: c(4) !< input \nreal(kind=dbl) :: res(3)\n\nres = qu2st_d(ax2qu_d(c))\n\nend function ax2st_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: ro2st\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert Rodrigues vector to stereographic\n!\n!> @param c Rodrigues vector (single precision)\n!> \n!\n!> @date 10/07/17 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ro2st(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ro2st\n\nuse local \n\nreal(kind=sgl), INTENT(IN) :: c(4) !< input \nreal(kind=sgl) :: res(3)\n\nres = qu2st(ro2qu(c))\n\nend function ro2st\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: ro2st_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert Rodrigues vector to stereographic\n!\n!> @param c Rodrigues vector (double precision)\n!> \n!\n!> @date 10/07/17 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ro2st_d(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ro2st_d\n\nuse local \n\nreal(kind=dbl), INTENT(IN) :: c(4) !< input \nreal(kind=dbl) :: res(3)\n\nres = qu2st_d(ro2qu_d(c))\n\nend function ro2st_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: ho2st\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert homochoric vector to stereographic\n!\n!> @param c homochoric vector (single precision)\n!> \n!\n!> @date 10/07/17 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ho2st(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ho2st\n\nuse local \n\nreal(kind=sgl), INTENT(IN) :: c(3) !< input \nreal(kind=sgl) :: res(3)\n\nres = qu2st(ho2qu(c))\n\nend function ho2st\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: ho2st_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert homochoric vector to stereographic\n!\n!> @param c homochoric vector (double precision)\n!> \n!\n!> @date 10/07/17 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ho2st_d(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ho2st_d\n\nuse local \n\nreal(kind=dbl), INTENT(IN) :: c(3) !< input \nreal(kind=dbl) :: res(3)\n\nres = qu2st_d(ho2qu_d(c))\n\nend function ho2st_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: cu2st\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert homochoric vector to stereographic\n!\n!> @param c homochoric vector (single precision)\n!> \n!\n!> @date 10/07/17 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function cu2st(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: cu2st\n\nuse local \n\nreal(kind=sgl), INTENT(IN) :: c(3) !< input \nreal(kind=sgl) :: res(3)\n\nres = qu2st(cu2qu(c))\n\nend function cu2st\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: cu2st_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert homochoric vector to stereographic\n!\n!> @param c homochoric vector (double precision)\n!> \n!\n!> @date 10/07/17 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function cu2st_d(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: cu2st_d\n\nuse local \n\nreal(kind=dbl), INTENT(IN) :: c(3) !< input \nreal(kind=dbl) :: res(3)\n\nres = qu2st_d(cu2qu_d(c))\n\nend function cu2st_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: eu2st\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert Euler angles to stereographic\n!\n!> @param c Euler angles (single precision)\n!> \n!\n!> @date 10/07/17 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function eu2st(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: eu2st\n\nuse local \n\nreal(kind=sgl), INTENT(IN) :: c(3) !< input \nreal(kind=sgl) :: res(3)\n\nres = qu2st(eu2qu(c))\n\nend function eu2st\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: eu2st_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert Euler angles to stereographic\n!\n!> @param c Euler angles (double precision)\n!> \n!\n!> @date 10/07/17 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function eu2st_d(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: eu2st_d\n\nuse local \n\nreal(kind=dbl), INTENT(IN) :: c(3) !< input \nreal(kind=dbl) :: res(3)\n\nres = qu2st_d(eu2qu_d(c))\n\nend function eu2st_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: qu2st\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert quaternion to stereographic\n!\n!> @param c quaternion (single precision)\n!> \n!\n!> @date 10/07/17 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function qu2st(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: qu2st\n\nuse local \n\nreal(kind=sgl), INTENT(IN) :: c(4) !< input \nreal(kind=sgl) :: res(3)\n\nres(1:3) = c(2:4)\nif (c(1).ne.0.0) then\n res = res / (1.0 + c(1))\nend if\n\nend function qu2st\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: qu2st_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert quaternion to stereographic\n!\n!> @param c quaternion (double precision)\n!> \n!\n!> @date 10/07/17 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function qu2st_d(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: qu2st_d\n\nuse local \n\nreal(kind=dbl), INTENT(IN) :: c(4) !< input \nreal(kind=dbl) :: res(3)\n\nres(1:3) = c(2:4)\nif (c(1).ne.0.D0) then\n res = res / (1.D0 + c(1))\nend if\n\nend function qu2st_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: st2om\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert stereographic to orientation matrix \n!\n!> @param c stereographic vector (single precision)\n!> \n!\n!> @date 10/07/17 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function st2om(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: st2om\n\nuse local \nuse constants\n\nreal(kind=sgl), INTENT(IN) :: c(3) !< input \nreal(kind=sgl) :: res(3,3)\n\nreal(kind=sgl) :: l, tmp(3), ax(4), sPi\n\nl = sqrt(sum(c*c))\nsPi = sngl(cPi)\n\nif (l.gt.0.0) then ! not the identity rotation\n tmp = c/l\n if ( close_enough(l,1.0) ) then\n ax = (/ tmp(1), tmp(2), tmp(3), sPi /)\n else\n ax = (/ tmp(1), tmp(2), tmp(3), 4.0*atan(l) /)\n end if\n res = ax2om(ax)\nelse ! return the identity matrix\n res = 0.0\n res(1,1) = 1.0\n res(2,2) = 1.0\n res(3,3) = 1.0\nend if\n\nend function st2om\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: st2om_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert stereographic to orientation matrix \n!\n!> @param c stereographic vector (double precision)\n!> \n!\n!> @date 10/07/17 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function st2om_d(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: st2om_d\n\nuse local \nuse constants\n\nreal(kind=dbl), INTENT(IN) :: c(3) !< input \nreal(kind=dbl) :: res(3,3)\n\nreal(kind=dbl) :: l, tmp(3), ax(4)\n\nl = sqrt(sum(c*c))\n\nif (l.gt.0.D0) then ! not the identity rotation\n tmp = c/l\n if ( close_enough_d(l,1.D0) ) then\n ax = (/ tmp(1), tmp(2), tmp(3), cPi /)\n else\n ax = (/ tmp(1), tmp(2), tmp(3), 4.D0*datan(l) /)\n end if\n res = ax2om_d(ax)\nelse ! return the identity matrix\n res = 0.D0\n res(1,1) = 1.D0\n res(2,2) = 1.D0\n res(3,3) = 1.D0\nend if\n\nend function st2om_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: st2eu\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert stereographic to Euler angles \n!\n!> @param c stereographic vector (single precision)\n!> \n!\n!> @date 10/07/17 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function st2eu(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: st2eu\n\nuse local \nuse constants\n\nreal(kind=sgl), INTENT(IN) :: c(3) !< input \nreal(kind=sgl) :: res(3)\n\nreal(kind=sgl) :: l, tmp(3), ax(4), sPi\n\nl = sqrt(sum(c*c))\nsPi = sngl(cPi)\n\nif (l.gt.0.0) then ! not the identity rotation\n tmp = c/l\n if ( close_enough(l,1.0) ) then\n ax = (/ tmp(1), tmp(2), tmp(3), sPi /)\n else\n ax = (/ tmp(1), tmp(2), tmp(3), 4.0*atan(l) /)\n end if\n res = ax2eu(ax)\nelse ! return the identity orientation\n res = 0.0\nend if\n\nend function st2eu\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: st2eu_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert stereographic to Euler angles \n!\n!> @param c stereographic vector (double precision)\n!> \n!\n!> @date 10/07/17 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function st2eu_d(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: st2eu_d\n\nuse local \nuse constants\n\nreal(kind=dbl), INTENT(IN) :: c(3) !< input \nreal(kind=dbl) :: res(3)\n\nreal(kind=dbl) :: l, tmp(3), ax(4)\n\nl = sqrt(sum(c*c))\n\nif (l.gt.0.D0) then ! not the identity rotation\n tmp = c/l\n if ( close_enough_d(l,1.D0) ) then\n ax = (/ tmp(1), tmp(2), tmp(3), cPi /)\n else\n ax = (/ tmp(1), tmp(2), tmp(3), 4.D0*datan(l) /)\n end if\n res = ax2eu_d(ax)\nelse ! return the identity orientation\n res = 0.D0\nend if\n\nend function st2eu_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: st2qu\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert stereographic to quaternion\n!\n!> @param c stereographic vector (single precision)\n!> \n!\n!> @date 10/07/17 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function st2qu(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: st2qu\n\nuse local \nuse constants\n\nreal(kind=sgl), INTENT(IN) :: c(3) !< input \nreal(kind=sgl) :: res(4)\n\nreal(kind=sgl) :: l, tmp(3), ax(4), sPi\n\nl = sqrt(sum(c*c))\nsPi = sngl(cPi)\n\nif (l.gt.0.0) then ! not the identity rotation\n tmp = c/l\n if ( close_enough(l,1.0) ) then\n ax = (/ tmp(1), tmp(2), tmp(3), sPi /)\n else\n ax = (/ tmp(1), tmp(2), tmp(3), 4.0*atan(l) /)\n end if\n res = ax2qu(ax)\nelse ! return the identity orientation\n res = (/ 1.0, 0.0, 0.0, 0.0 /)\nend if\n\nend function st2qu\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: st2qu_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert stereographic to quaternion\n!\n!> @param c stereographic vector (double precision)\n!> \n!\n!> @date 10/07/17 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function st2qu_d(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: st2qu_d\n\nuse local \nuse constants\n\nreal(kind=dbl), INTENT(IN) :: c(3) !< input \nreal(kind=dbl) :: res(4)\n\nreal(kind=dbl) :: l, tmp(3), ax(4)\n\nl = sqrt(sum(c*c))\n\nif (l.gt.0.D0) then ! not the identity rotation\n tmp = c/l\n if ( close_enough_d(l,1.D0) ) then\n ax = (/ tmp(1), tmp(2), tmp(3), cPi /)\n else\n ax = (/ tmp(1), tmp(2), tmp(3), 4.D0*datan(l) /)\n end if\n res = ax2qu_d(ax)\nelse ! return the identity orientation\n res = (/ 1.D0, 0.D0, 0.D0, 0.D0 /)\nend if\n\nend function st2qu_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: st2ax\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert stereographic to axis-angle pair\n!\n!> @param c stereographic vector (single precision)\n!> \n!\n!> @date 10/07/17 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function st2ax(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: st2ax\n\nuse local \nuse constants\n\nreal(kind=sgl), INTENT(IN) :: c(3) !< input \nreal(kind=sgl) :: res(4)\n\nreal(kind=sgl) :: l, tmp(3), sPi\n\nl = sqrt(sum(c*c))\nsPi = sngl(cPi)\n\nif (l.gt.0.0) then ! not the identity rotation\n tmp = c/l\n if ( close_enough(l,1.0) ) then\n res = (/ tmp(1), tmp(2), tmp(3), sPi /)\n else\n res = (/ tmp(1), tmp(2), tmp(3), 4.0*atan(l) /)\n end if\nelse ! return the identity orientation\n res = (/ 0.0, 0.0, 1.0, 0.0 /)\nend if\n\nend function st2ax\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: st2ax_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert stereographic to axis-angle pair\n!\n!> @param c stereographic vector (double precision)\n!> \n!\n!> @date 10/07/17 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function st2ax_d(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: st2ax_d\n\nuse local \nuse constants\n\nreal(kind=dbl), INTENT(IN) :: c(3) !< input \nreal(kind=dbl) :: res(4)\n\nreal(kind=dbl) :: l, tmp(3)\n\nl = sqrt(sum(c*c))\n\nif (l.gt.0.D0) then ! not the identity rotation\n tmp = c/l\n if ( close_enough_d(l,1.D0) ) then\n res = (/ tmp(1), tmp(2), tmp(3), cPi /)\n else\n res = (/ tmp(1), tmp(2), tmp(3), 4.D0*datan(l) /)\n end if\nelse ! return the identity orientation\n res = (/ 0.D0, 0.D0, 1.D0, 0.D0 /)\nend if\n\nend function st2ax_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: st2ro\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert stereographic to Rodrigues vector\n!\n!> @param c stereographic vector (single precision)\n!> \n!\n!> @date 10/07/17 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function st2ro(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: st2ro\n\nuse local \nuse constants\n\nreal(kind=sgl), INTENT(IN) :: c(3) !< input \nreal(kind=sgl) :: res(4)\n\nreal(kind=sgl) :: l, tmp(3)\n\nl = sqrt(sum(c*c))\n\nif (l.gt.0.0) then ! not the identity rotation\n tmp = c/l\n if ( close_enough(l,1.0) ) then\n res = (/ tmp(1), tmp(2), tmp(3), 0.0 /)\n res(4) = infty()\n else\n res = (/ tmp(1), tmp(2), tmp(3), tan(2.0*atan(l)) /)\n end if\nelse ! return the identity orientation\n res = (/ 0.0, 0.0, 1.0, 0.0 /)\nend if\n\nend function st2ro\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: st2ro_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert stereographic to Rodrigues vector\n!\n!> @param c stereographic vector (double precision)\n!> \n!\n!> @date 10/07/17 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function st2ro_d(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: st2ro_d\n\nuse local \nuse constants\n\nreal(kind=dbl), INTENT(IN) :: c(3) !< input \nreal(kind=dbl) :: res(4)\n\nreal(kind=dbl) :: l, tmp(3)\n\nl = sqrt(sum(c*c))\n\nif (l.gt.0.D0) then ! not the identity rotation\n tmp = c/l\n if ( close_enough_d(l,1.D0) ) then\n res = (/ tmp(1), tmp(2), tmp(3), 0.D0 /)\n res(4) = inftyd()\n else\n res = (/ tmp(1), tmp(2), tmp(3), tan(2.D0*datan(l)) /)\n end if\nelse ! return the identity orientation\n res = (/ 0.D0, 0.D0, 1.D0, 0.D0 /)\nend if\n\nend function st2ro_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: st2ho\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert stereographic to homochoric vector\n!\n!> @param c stereographic vector (single precision)\n!> \n!\n!> @date 10/07/17 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function st2ho(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: st2ho\n\nuse local \n\nreal(kind=sgl), INTENT(IN) :: c(3) !< input \nreal(kind=sgl) :: res(3)\n\nreal(kind=sgl) :: l, tmp(3), angle\n\nl = sqrt(sum(c*c))\n\nif (l.gt.0.0) then ! not the identity rotation\n tmp = c/l\n angle = 4.0*atan(l)\n res = tmp * (3.0 * ( angle - sin(angle) ) / 4.0) ** (1.0/3.0)\nelse ! return the identity orientation\n res = (/ 0.0, 0.0, 0.0 /)\nend if\n\nend function st2ho\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: st2ho_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert stereographic to homochoric vector\n!\n!> @param c stereographic vector (double precision)\n!> \n!\n!> @date 10/07/17 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function st2ho_d(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: st2ho_d\n\nuse local \n\nreal(kind=dbl), INTENT(IN) :: c(3) !< input \nreal(kind=dbl) :: res(3)\n\nreal(kind=dbl) :: l, tmp(3), angle\n\nl = sqrt(sum(c*c))\n\nif (l.gt.0.0) then ! not the identity rotation\n tmp = c/l\n angle = 4.D0*datan(l)\n res = tmp * (3.D0 * ( angle - dsin(angle) ) / 4.D0) ** (1.D0/3.D0)\nelse ! return the identity orientation\n res = (/ 0.D0, 0.D0, 0.D0 /)\nend if\n\nend function st2ho_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: st2cu\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert stereographic to cubochoric vector\n!\n!> @param c stereographic vector (single precision)\n!> \n!\n!> @date 10/07/17 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function st2cu(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: st2cu\n\nuse local \n\nreal(kind=sgl), INTENT(IN) :: c(3) !< input \nreal(kind=sgl) :: res(3)\n\nreal(kind=sgl) :: l, tmp(3), angle\n\nl = sqrt(sum(c*c))\n\nif (l.gt.0.0) then ! not the identity rotation\n tmp = c/l\n angle = 4.0*atan(l)\n res = ho2cu(tmp * (3.0 * ( angle - sin(angle) ) / 4.0) ** (1.0/3.0))\nelse ! return the identity orientation\n res = (/ 0.0, 0.0, 0.0 /)\nend if\n\nend function st2cu\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: st2cu_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief convert stereographic to cubochoric vector\n!\n!> @param c stereographic vector (double precision)\n!> \n!\n!> @date 10/07/17 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function st2cu_d(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: st2cu_d\n\nuse local \n\nreal(kind=dbl), INTENT(IN) :: c(3) !< input \nreal(kind=dbl) :: res(3)\n\nreal(kind=dbl) :: l, tmp(3), angle\n\nl = sqrt(sum(c*c))\n\nif (l.gt.0.0) then ! not the identity rotation\n tmp = c/l\n angle = 4.D0*datan(l)\n res = ho2cu_d(tmp * (3.D0 * ( angle - dsin(angle) ) / 4.D0) ** (1.D0/3.D0))\nelse ! return the identity orientation\n res = (/ 0.D0, 0.D0, 0.D0 /)\nend if\n\nend function st2cu_d\n\n!--------------------------------------------------------------------------\n!\n! Function: eu2rv\n!\n!> @author Saransh Singh, Lawrence Livermore National Lab\n!\n!> @brief Euler angles to rotation vector map \n!\n!> @param e 3 Euler angles in radians (single precision) \n!> \n!> @date 10/25/19 SS 1.0 original\n!--------------------------------------------------------------------------\nrecursive function eu2rv(e) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: eu2rv\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: e(3) !< input Euler angles in radians\nreal(kind=dbl) :: res(3) !< output rotation vector map\n\nreal(kind=dbl) :: ax(4)\n\nax = eu2ax(e)\n\nres = ax(1:3) * ax(4)\n\nend function eu2rv\n\n!--------------------------------------------------------------------------\n!\n! Function: eu2rv_d\n!\n!> @author Saransh Singh, Lawrence Livermore National Lab\n!\n!> @brief Euler angles to rotation vector map \n!\n!> @param e 3 Euler angles in radians (double precision) \n!> \n!> @date 10/25/19 SS 1.0 original\n!--------------------------------------------------------------------------\nrecursive function eu2rv_d(e) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: eu2rv_d\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: e(3) !< input Euler angles in radians\nreal(kind=dbl) :: res(3) !< output rotation vector map\n\nreal(kind=dbl) :: ax(4)\n\nax = eu2ax(e)\n\nres = ax(1:3) * ax(4)\n\nend function eu2rv_d\n\n!--------------------------------------------------------------------------\n!\n! Function: om2rv\n!\n!> @author Saransh Singh, Lawrence Livermore National Lab\n!\n!> @brief rotation matrix to rotation vector map \n!\n!> @param o 3x3 rotation matrix (single precision) \n!> \n!> @date 10/25/19 SS 1.0 original\n!--------------------------------------------------------------------------\nrecursive function om2rv(o) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: om2rv\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: o(3,3) \nreal(kind=dbl) :: res(3) !< output rotation vector map\n\nreal(kind=dbl) :: ax(4)\n\nres = qu2rv(om2qu(o))\n\nend function om2rv\n\n!--------------------------------------------------------------------------\n!\n! Function: om2rv_d\n!\n!> @author Saransh Singh, Lawrence Livermore National Lab\n!\n!> @brief rotation matrix to rotation vector map \n!\n!> @param o 3x3 rotation matrix (double precision) \n!> \n!> @date 10/25/19 SS 1.0 original\n!--------------------------------------------------------------------------\nrecursive function om2rv_d(o) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: om2rv_d\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: o(3,3) \nreal(kind=dbl) :: res(3) !< output rotation vector map\n\nreal(kind=dbl) :: ax(4)\n\nres = qu2rv(om2qu(o))\n\nend function om2rv_d\n\n!--------------------------------------------------------------------------\n!\n! Function: ro2rv\n!\n!> @author Saransh Singh, Lawrence Livermore National Lab\n!\n!> @brief rodrigues vector to rotation vector map \n!\n!> @param r rodrigues vector (single precision) \n!> \n!> @date 10/25/19 SS 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ro2rv(r) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ro2rv\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: r(4) \nreal(kind=dbl) :: res(3) !< output rotation vector map\n\nreal(kind=dbl) :: ax(4)\n\nres = eu2rv(ro2eu(r))\n\nend function ro2rv\n\n!--------------------------------------------------------------------------\n!\n! Function: ro2rv_d\n!\n!> @author Saransh Singh, Lawrence Livermore National Lab\n!\n!> @brief rodrigues vector to rotation vector map \n!\n!> @param r rodrigues vector (double precision) \n!> \n!> @date 10/25/19 SS 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ro2rv_d(r) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ro2rv_d\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: r(4) \nreal(kind=dbl) :: res(3) !< output rotation vector map\n\nreal(kind=dbl) :: ax(4)\n\nres = eu2rv(ro2eu(r))\n\nend function ro2rv_d\n\n!--------------------------------------------------------------------------\n!\n! Function: qu2rv\n!\n!> @author Saransh Singh, Lawrence Livermore National Lab\n!\n!> @brief quaternion to rotation vector map \n!\n!> @param q quaternion (single precision) \n!> \n!> @date 10/25/19 SS 1.0 original\n!--------------------------------------------------------------------------\nrecursive function qu2rv(q) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: qu2rv\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: q(4) \nreal(kind=dbl) :: res(3) !< output rotation vector map\n\nreal(kind=dbl) :: ax(4)\n\nres = eu2rv(qu2eu(q))\n\nend function qu2rv\n\n!--------------------------------------------------------------------------\n!\n! Function: qu2rv_d\n!\n!> @author Saransh Singh, Lawrence Livermore National Lab\n!\n!> @brief quaternion to rotation vector map \n!\n!> @param q quaternion (double precision) \n!> \n!> @date 10/25/19 SS 1.0 original\n!--------------------------------------------------------------------------\nrecursive function qu2rv_d(q) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: qu2rv_d\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: q(4) \nreal(kind=dbl) :: res(3) !< output rotation vector map\n\nreal(kind=dbl) :: ax(4)\n\nres = eu2rv(qu2eu(q))\n\nend function qu2rv_d\n\n!--------------------------------------------------------------------------\n!\n! Function: cu2rv\n!\n!> @author Saransh Singh, Lawrence Livermore National Lab\n!\n!> @brief cubochoric vector to rotation vector map \n!\n!> @param c cubochoric vector (single precision) \n!> \n!> @date 10/25/19 SS 1.0 original\n!--------------------------------------------------------------------------\nrecursive function cu2rv(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: cu2rv\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: c(3) \nreal(kind=dbl) :: res(3) !< output rotation vector map\n\nreal(kind=dbl) :: ax(4)\n\nres = eu2rv(cu2eu(c))\n\nend function cu2rv\n\n!--------------------------------------------------------------------------\n!\n! Function: cu2rv_d\n!\n!> @author Saransh Singh, Lawrence Livermore National Lab\n!\n!> @brief cubochoric vector to rotation vector map \n!\n!> @param c cubochoric vector (double precision) \n!> \n!> @date 10/25/19 SS 1.0 original\n!--------------------------------------------------------------------------\nrecursive function cu2rv_d(c) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: cu2rv_d\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: c(3) \nreal(kind=dbl) :: res(3) !< output rotation vector map\n\nreal(kind=dbl) :: ax(4)\n\nres = eu2rv(cu2eu(c))\n\nend function cu2rv_d\n\n!--------------------------------------------------------------------------\n!\n! Function: ax2rv\n!\n!> @author Saransh Singh, Lawrence Livermore National Lab\n!\n!> @brief axis angle pair to rotation vector map \n!\n!> @param a axis angle pair (single precision)\n!> \n!> @date 10/25/19 SS 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ax2rv(a) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ax2rv\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: a(4) \nreal(kind=dbl) :: res(3) !< output rotation vector map\ninteger(kind=irg) :: ii, ctr\nreal(kind=sgl),parameter :: thr = 1.0E-6\n\nres = a(1:3) * a(4)\n\nend function ax2rv\n\n!--------------------------------------------------------------------------\n!\n! Function: ax2rv_d\n!\n!> @author Saransh Singh, Lawrence Livermore National Lab\n!\n!> @brief axis angle to rotation vector map \n!\n!> @param a axis angle pair (double precision) \n!> \n!> @date 10/25/19 SS 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ax2rv_d(a) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ax2rv_d\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: a(4) \nreal(kind=dbl) :: res(3) !< output rotation vector map\ninteger(kind=irg) :: ii, ctr\nreal(kind=sgl),parameter :: thr = 1.0D-8\n\nres = a(1:3) * a(4)\n\nend function ax2rv_d\n\n!--------------------------------------------------------------------------\n!\n! Function: ho2rv\n!\n!> @author Saransh Singh, Lawrence Livermore National Lab\n!\n!> @brief homochoric vector to rotation vector map \n!\n!> @param h homochoric vector (single precision) \n!> \n!> @date 10/25/19 SS 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ho2rv(h) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ho2rv\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: h(3) \nreal(kind=dbl) :: res(3) !< output rotation vector map\n\nreal(kind=dbl) :: ax(4)\n\nres = eu2rv(ho2eu(h))\n\nend function ho2rv\n\n!--------------------------------------------------------------------------\n!\n! Function: ho2rv_d\n!\n!> @author Saransh Singh, Lawrence Livermore National Lab\n!\n!> @brief homochoric vector to rotation vector map \n!\n!> @param h homochoric vector (double precision) \n!> \n!> @date 10/25/19 SS 1.0 original\n!--------------------------------------------------------------------------\nrecursive function ho2rv_d(h) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: ho2rv_d\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: h(3) \nreal(kind=dbl) :: res(3) !< output rotation vector map\n\nreal(kind=dbl) :: ax(4)\n\nres = eu2rv(ho2eu(h))\n\nend function ho2rv_d\n\n!--------------------------------------------------------------------------\n!\n! Function: st2rv\n!\n!> @author Saransh Singh, Lawrence Livermore National Lab\n!\n!> @brief stereographic vector to rotation vector map \n!\n!> @param s stereographic vector (single precision) \n!> \n!> @date 10/25/19 SS 1.0 original\n!--------------------------------------------------------------------------\nrecursive function st2rv(s) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: st2rv\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: s(3) \nreal(kind=dbl) :: res(3) !< output rotation vector map\n\nreal(kind=dbl) :: ax(4)\n\nres = eu2rv(st2eu(s))\n\nend function st2rv\n\n!--------------------------------------------------------------------------\n!\n! Function: st2rv_d\n!\n!> @author Saransh Singh, Lawrence Livermore National Lab\n!\n!> @brief stereographic vector to rotation vector map \n!\n!> @param s stereographic vector (double precision) \n!> \n!> @date 10/25/19 SS 1.0 original\n!--------------------------------------------------------------------------\nrecursive function st2rv_d(s) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: st2rv_d\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: s(3) \nreal(kind=dbl) :: res(3) !< output rotation vector map\n\nreal(kind=dbl) :: ax(4)\n\nres = eu2rv(st2eu(s))\n\nend function st2rv_d\n\n!--------------------------------------------------------------------------\n!\n! Function: rv2ax\n!\n!> @author Saransh Singh, Lawrence Livermore National Lab\n!\n!> @brief rotation vector map to axis angle pair \n!\n!> @param e rotation vector map (single precision) \n!> \n!> @date 10/25/19 SS 1.0 original\n!--------------------------------------------------------------------------\nrecursive function rv2ax(e) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: rv2ax\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: e(3) !< input rotation vector map \nreal(kind=dbl) :: res(4) !< output axis angle pair\n\nreal(kind=dbl) :: an, n(3)\nreal(kind=dbl), parameter :: tol = 1.0D-10\n\nan = sqrt(sum(e**2))\n\nif(an .gt. tol) then\n n = e / an\nelse\n n = (/0.0, 0.0, 1.0/)\nend if\n\nres = (/n, an/)\n\nend function rv2ax\n\n!--------------------------------------------------------------------------\n!\n! Function: rv2ax_d\n!\n!> @author Saransh Singh, Lawrence Livermore National Lab\n!\n!> @brief rotation vector map to axis angle pair \n!\n!> @param e rotation vector map (double precision) \n!> \n!> @date 10/25/19 SS 1.0 original\n!--------------------------------------------------------------------------\nrecursive function rv2ax_d(e) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: rv2ax_d\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: e(3) !< input rotation vector map\nreal(kind=dbl) :: res(4) !< output rotation vector map\n\nreal(kind=dbl) :: an, n(3)\nreal(kind=dbl), parameter :: tol = 1.0D-10\n\nan = sqrt(sum(e**2))\n\nif(an .gt. tol) then\n n = e / an\nelse\n n = (/0.0, 0.0, 1.0/)\nend if\n\nres = (/n, an/)\n\nend function rv2ax_d\n\n!--------------------------------------------------------------------------\n!\n! Function: rv2om\n!\n!> @author Saransh Singh, Lawrence Livermore National Lab\n!\n!> @brief rotation vector map to rotation matrix\n!\n!> @param e rotation vector map (single precision) \n!> \n!> @date 10/25/19 SS 1.0 original\n!--------------------------------------------------------------------------\nrecursive function rv2om(e) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: rv2om\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: e(3) !< input rotation vector map \nreal(kind=dbl) :: res(3,3) !< output rotation matrix\n\nres = ax2om(rv2ax(e))\n\nend function rv2om\n\n!--------------------------------------------------------------------------\n!\n! Function: rv2om_d\n!\n!> @author Saransh Singh, Lawrence Livermore National Lab\n!\n!> @brief rotation vector map to rotation matrix\n!\n!> @param e rotation vector map (double precision) \n!> \n!> @date 10/25/19 SS 1.0 original\n!--------------------------------------------------------------------------\nrecursive function rv2om_d(e) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: rv2om_d\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: e(3) !< input rotation vector map\nreal(kind=dbl) :: res(3,3) !< output rotation matrix\n\nres = ax2om(rv2ax(e))\n\nend function rv2om_d\n\n!--------------------------------------------------------------------------\n!\n! Function: rv2eu\n!\n!> @author Saransh Singh, Lawrence Livermore National Lab\n!\n!> @brief rotation vector map to euler angles in radians\n!\n!> @param e rotation vector map (single precision) \n!> \n!> @date 10/25/19 SS 1.0 original\n!--------------------------------------------------------------------------\nrecursive function rv2eu(e) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: rv2eu\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: e(3) !< input rotation vector map \nreal(kind=dbl) :: res(3) !< output euler angles in radians\n\nres = ax2eu(rv2ax(e))\n\nend function rv2eu\n\n!--------------------------------------------------------------------------\n!\n! Function: rv2eu_d\n!\n!> @author Saransh Singh, Lawrence Livermore National Lab\n!\n!> @brief rotation vector map to euler angles in radians\n!\n!> @param e rotation vector map (double precision) \n!> \n!> @date 10/25/19 SS 1.0 original\n!--------------------------------------------------------------------------\nrecursive function rv2eu_d(e) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: rv2eu_d\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: e(3) !< input rotation vector map\nreal(kind=dbl) :: res(3) !< output euler angles in radians\n\nres = ax2eu(rv2ax(e))\n\nend function rv2eu_d\n\n!--------------------------------------------------------------------------\n!\n! Function: rv2qu\n!\n!> @author Saransh Singh, Lawrence Livermore National Lab\n!\n!> @brief rotation vector map to quaternion\n!\n!> @param e rotation vector map (single precision) \n!> \n!> @date 10/25/19 SS 1.0 original\n!--------------------------------------------------------------------------\nrecursive function rv2qu(e) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: rv2qu\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: e(3) !< input rotation vector map \nreal(kind=dbl) :: res(4) !< output quaternion\n\nres = ax2qu(rv2ax(e))\n\nend function rv2qu\n\n!--------------------------------------------------------------------------\n!\n! Function: rv2qu_d\n!\n!> @author Saransh Singh, Lawrence Livermore National Lab\n!\n!> @brief rotation vector map to quaternion\n!\n!> @param e rotation vector map (double precision) \n!> \n!> @date 10/25/19 SS 1.0 original\n!--------------------------------------------------------------------------\nrecursive function rv2qu_d(e) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: rv2qu_d\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: e(3) !< input rotation vector map\nreal(kind=dbl) :: res(4) !< output quaternion\n\nres = ax2qu(rv2ax(e))\n\nend function rv2qu_d\n\n!--------------------------------------------------------------------------\n!\n! Function: rv2ro\n!\n!> @author Saransh Singh, Lawrence Livermore National Lab\n!\n!> @brief rotation vector map to rodrigues vector\n!\n!> @param e rotation vector map (single precision) \n!> \n!> @date 10/25/19 SS 1.0 original\n!--------------------------------------------------------------------------\nrecursive function rv2ro(e) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: rv2ro\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: e(3) !< input rotation vector map \nreal(kind=dbl) :: res(4) !< output rodrigues vector\n\nres = ax2ro(rv2ax(e))\n\nend function rv2ro\n\n!--------------------------------------------------------------------------\n!\n! Function: rv2ro_d\n!\n!> @author Saransh Singh, Lawrence Livermore National Lab\n!\n!> @brief rotation vector map to rodrigues vector\n!\n!> @param e rotation vector map (double precision) \n!> \n!> @date 10/25/19 SS 1.0 original\n!--------------------------------------------------------------------------\nrecursive function rv2ro_d(e) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: rv2ro_d\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: e(3) !< input rotation vector map\nreal(kind=dbl) :: res(4) !< output rodrigues vector\n\nres = ax2ro(rv2ax(e))\n\nend function rv2ro_d\n\n!--------------------------------------------------------------------------\n!\n! Function: rv2cu\n!\n!> @author Saransh Singh, Lawrence Livermore National Lab\n!\n!> @brief rotation vector map to cubochoric vector\n!\n!> @param e rotation vector map (single precision) \n!> \n!> @date 10/25/19 SS 1.0 original\n!--------------------------------------------------------------------------\nrecursive function rv2cu(e) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: rv2cu\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: e(3) !< input rotation vector map \nreal(kind=dbl) :: res(3) !< output cubochoric vector\n\nres = ax2cu(rv2ax(e))\n\nend function rv2cu\n\n!--------------------------------------------------------------------------\n!\n! Function: rv2cu_d\n!\n!> @author Saransh Singh, Lawrence Livermore National Lab\n!\n!> @brief rotation vector map to cubochoric vector\n!\n!> @param e rotation vector map (double precision) \n!> \n!> @date 10/25/19 SS 1.0 original\n!--------------------------------------------------------------------------\nrecursive function rv2cu_d(e) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: rv2cu_d\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: e(3) !< input rotation vector map\nreal(kind=dbl) :: res(3) !< output cubochoric vector\n\nres = ax2cu(rv2ax(e))\n\nend function rv2cu_d\n\n!--------------------------------------------------------------------------\n!\n! Function: rv2ho\n!\n!> @author Saransh Singh, Lawrence Livermore National Lab\n!\n!> @brief rotation vector map to homochoric vector\n!\n!> @param e rotation vector map (single precision) \n!> \n!> @date 10/25/19 SS 1.0 original\n!--------------------------------------------------------------------------\nrecursive function rv2ho(e) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: rv2ho\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: e(3) !< input rotation vector map \nreal(kind=dbl) :: res(3) !< output homochoric vector\n\nres = ax2ho(rv2ax(e))\n\nend function rv2ho\n\n!--------------------------------------------------------------------------\n!\n! Function: rv2ho_d\n!\n!> @author Saransh Singh, Lawrence Livermore National Lab\n!\n!> @brief rotation vector map to homochoric vector\n!\n!> @param e rotation vector map (double precision) \n!> \n!> @date 10/25/19 SS 1.0 original\n!--------------------------------------------------------------------------\nrecursive function rv2ho_d(e) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: rv2ho_d\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: e(3) !< input rotation vector map\nreal(kind=dbl) :: res(3) !< output homochoric vector\n\nres = ax2ho(rv2ax(e))\n\nend function rv2ho_d\n\n!--------------------------------------------------------------------------\n!\n! Function: rv2st\n!\n!> @author Saransh Singh, Lawrence Livermore National Lab\n!\n!> @brief rotation vector map to stereographic vector\n!\n!> @param e rotation vector map (single precision) \n!> \n!> @date 10/25/19 SS 1.0 original\n!--------------------------------------------------------------------------\nrecursive function rv2st(e) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: rv2st\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=sgl),INTENT(IN) :: e(3) !< input rotation vector map \nreal(kind=dbl) :: res(3) !< output stereographic vector\n\nres = ax2st(rv2ax(e))\n\nend function rv2st\n\n!--------------------------------------------------------------------------\n!\n! Function: rv2st_d\n!\n!> @author Saransh Singh, Lawrence Livermore National Lab\n!\n!> @brief rotation vector map to stereographic vector\n!\n!> @param e rotation vector map (double precision) \n!> \n!> @date 10/25/19 SS 1.0 original\n!--------------------------------------------------------------------------\nrecursive function rv2st_d(e) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: rv2st_d\n\nuse local\nuse constants\n\nIMPLICIT NONE\n\nreal(kind=dbl),INTENT(IN) :: e(3) !< input rotation vector map\nreal(kind=dbl) :: res(3) !< output stereographic vector\n\nres = ax2st(rv2ax(e))\n\nend function rv2st_d\n\n!--------------------------------------------------------------------------\n!--------------------------------------------------------------------------\n! routines for rotating a vector, tensor, ...\n!--------------------------------------------------------------------------\n!--------------------------------------------------------------------------\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: RodriguesProduct\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief multiply two Rodrigues vectors\n!\n!> @param roA first input Rodrigues vector components (single precision)\n!> @param roB second input Rodrigues vector components (single precision)\n!\n!> @date 12/01/16 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function RodriguesProduct(roA,roB) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: RodriguesProduct\n\nuse local\nuse math\n\nreal(kind=sgl),INTENT(IN) :: roA(3)\nreal(kind=sgl),INTENT(IN) :: roB(3)\n\nreal(kind=sgl) :: res(3)\n\nres = (roA + roB - cross3(roA,roB))/(1.0 - DOT_PRODUCT(roA,roB))\n\nend function RodriguesProduct\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: RodriguesProduct_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief multiply two Rodrigues vectors\n!\n!> @param roA first input Rodrigues vector components (single precision)\n!> @param roB second input Rodrigues vector components (single precision)\n!\n!> @date 12/01/16 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function RodriguesProduct_d(roA,roB) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: RodriguesProduct_d\n\nuse local\nuse math\n\nreal(kind=dbl),INTENT(IN) :: roA(3)\nreal(kind=dbl),INTENT(IN) :: roB(3)\n\nreal(kind=dbl) :: res(3)\n\nres = (roA + roB - cross3(roA,roB))/(1.D0 - DOT_PRODUCT(roA,roB))\n\nend function RodriguesProduct_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: RotVec_om\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief rotate a vector using a rotation matrix, active or passive (single precision)\n!\n!> @details This routine provides a way for the user to transform a vector\n!> and it returns the new vector components. The user can use either a \n!> rotation matrix or a quaternion to define the transformation, and must\n!> also specifiy whether an active or passive result is needed. The quaternion\n!> rotation is part of the quaternion.f90 file, in the routine quat_Lp or quat_Lpstar.\n!\n!> @param vec input vector components (single precision)\n!> @param om orientation matrix (single precision)\n!> @param ap active/passive switch\n!> \n!\n!> @date 8/18/14 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function RotVec_om(vec,om,ap) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: RotVec_om\n\nuse local\n\nreal(kind=sgl),INTENT(IN) :: vec(3)\nreal(kind=sgl),INTENT(IN) :: om(3,3)\ncharacter(1),INTENT(IN) :: ap\n\nreal(kind=sgl) :: res(3)\n\nif (ap.eq.'p') then\n res = matmul(om,vec)\nelse\n res = matmul(transpose(om),vec)\nend if\n\nend function RotVec_om\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: RotVec_om_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief rotate a vector using a rotation matrix, active or passive (double precision)\n!\n!> @details This routine provides a way for the user to transform a vector\n!> and it returns the new vector components. The user can use either a \n!> rotation matrix or a quaternion to define the transformation, and must\n!> also specifiy whether an active or passive result is needed. The quaternion\n!> rotation is part of the quaternion.f90 file, in the routine quat_Lp or quat_Lpstar.\n!\n!> @param vec input vector components (double precision)\n!> @param om orientation matrix (double precision)\n!> @param ap active/passive switch\n!> \n!\n!> @date 8/18/14 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function RotVec_om_d(vec,om,ap) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: RotVec_om_d\n\nuse local\n\nreal(kind=dbl),INTENT(IN) :: vec(3)\nreal(kind=dbl),INTENT(IN) :: om(3,3)\ncharacter(1),INTENT(IN) :: ap\n\nreal(kind=dbl) :: res(3)\n\nif (ap.eq.'p') then\n res = matmul(om,vec)\nelse\n res = matmul(transpose(om),vec)\nend if\n\nend function RotVec_om_d\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: RotTensor2_om\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief rotate a second rank tensor using a rotation matrix, active or passive (single precision)\n!\n!> @param tensor input tensor components (single precision)\n!> @param om orientation matrix (single precision)\n!> @param ap active/passive switch\n!> \n!\n!> @date 8/18/14 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function RotTensor2_om(tensor,om,ap) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: RotTensor2_om\n\nuse local\n\nreal(kind=sgl),INTENT(IN) :: tensor(3,3)\nreal(kind=sgl),INTENT(IN) :: om(3,3)\ncharacter(1),INTENT(IN) :: ap\n\nreal(kind=sgl) :: res(3,3)\n\nif (ap.eq.'p') then\n res = matmul(matmul(om,tensor),transpose(om))\nelse\n res = matmul(matmul(transpose(om),tensor),om)\nend if\n\nend function RotTensor2_om\n\n\n!--------------------------------------------------------------------------\n!\n! FUNCTION: RotTensor2_om_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief rotate a second rank tensor using a rotation matrix, active or passive (double precision)\n!\n!> @param tensor input tensor components (double precision)\n!> @param om orientation matrix (double precision)\n!> @param ap active/passive switch\n!> \n!\n!> @date 8/18/14 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive function RotTensor2_om_d(tensor,om,ap) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: RotTensor2_om_d\n\nuse local\n\nreal(kind=dbl),INTENT(IN) :: tensor(3,3)\nreal(kind=dbl),INTENT(IN) :: om(3,3)\ncharacter(1),INTENT(IN) :: ap\n\nreal(kind=dbl) :: res(3,3)\n\nif (ap.eq.'p') then\n res = matmul(matmul(om,tensor),transpose(om))\nelse\n res = matmul(matmul(transpose(om),tensor),om)\nend if\n\nend function RotTensor2_om_d\n\n\n!--------------------------------------------------------------------------\n!--------------------------------------------------------------------------\n! some basic averaging routines for quaternions\n!--------------------------------------------------------------------------\n!--------------------------------------------------------------------------\n\n!--------------------------------------------------------------------------\n!\n! function: quat_average\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief computes the average of a list of quaternions using the quaternion logarithm\n! \n!> @param qlist quaternion list\n!> @param numq number of quaternions in list\n!> @param qstdev standard deviation quaternion/eigenvalues\n! \n!> @date 03/16/15 MDG 1.0 original\n!> @date 10/16/20 MDG 1.1 corrects sign of axis angle pairs when dot product with first entry is negative\n!> @date 10/16/20 MDG 1.2 add optional Tmatrix approach (largest eigenvalue determines mean)\n!--------------------------------------------------------------------------\nrecursive function quat_average(qlist,numq,qstdev,Tmatrix) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: quat_average\n\nuse local\n\nreal(kind=sgl),INTENT(IN) :: qlist(4,numq)\ninteger(kind=irg) :: numq\nreal(kind=sgl),INTENT(OUT) :: qstdev(4)\nreal(kind=sgl) :: res(4)\nlogical,INTENT(IN),OPTIONAL :: Tmatrix\n\ninteger(kind=irg) :: i, pos(1)\nreal(kind=sgl) :: lsum(3), ax(4), qv, sqv, dfm(3), first(4), dp, qin(4), Tmat(4,4)\nreal(kind=sgl) :: axanglist(3,numq)\nlogical :: doTmatrix\n\n!LAPACK parameters \nreal(kind=sgl) :: VL(4,4), VR(4,4), Wr(4), Wi(4), WORK(40)\ninteger(kind=irg) :: nn, LDA, LDVL, LDVR, INFO, LWORK\ncharacter(1) :: JOBVL, JOBVR\n\ndoTmatrix=.FALSE.\nif (present(Tmatrix)) then \n if (Tmatrix.eqv..TRUE.) doTmatrix=.TRUE. ! use the Tmatrix approach to find the quaternion average\nend if \n\nif (doTmatrix.eqv..TRUE.) then \n Tmat = matmul(qlist,transpose(qlist))/real(numq)\n\n! set some initial LAPACK variables \n nn = 4\n LDA = nn\n LDVL = nn\n LDVR = nn\n INFO = 0\n \n! first initialize the parameters for the LAPACK DGEEV routines\n JOBVL = 'N' ! do not compute the left eigenvectors\n JOBVR = 'V' ! do compute the right eigenvectors\n LWORK = 40 \n\n! call the eigenvalue solver\n call sgeev(JOBVL,JOBVR,nn,Tmat,LDA,Wr,Wi,VL,LDVL,VR,LDVR,WORK,LWORK,INFO)\n pos = maxloc(Wr)\n res(1:4) = VR(1:4,pos(1))\n qstdev = Wr\n! check the sign of the scalar part\n if (res(1).lt.0.D0) res = -res \n\n else ! use the quaternion logarithm to determine the average \n\n! convert each one to a logarithm, which is really the unit rotation vector multiplied by half the rotation angle\n first = qlist(1:4,1)\n do i=1,numq\n qin = qlist(1:4,i)\n! convert the quaternion to an axis angle pair\n ax = qu2ax(qin)\n! make sure that the dot product with first is positive \n dp = sum(first*qin)\n if (dp.lt.0.0) then \n axanglist(1:3,i) = -ax(1:3)*0.50*ax(4)\n else \n axanglist(1:3,i) = ax(1:3)*0.50*ax(4)\n end if\n end do\n\n! compute the geometric mean\n lsum = sum(axanglist,2)/float(numq)\n\n! then get the standard deviation from the mean\n dfm = 0.0\n do i=1,numq\n dfm(1:3) = dfm(1:3) + (lsum - axanglist(1:3,i))**2\n end do\n dfm = sqrt(dfm/float(numq))\n\n! then convert this average back to a quaternion via the exponentiation operation\n qv = sqrt(sum(lsum*lsum))\n sqv = sin(qv)/qv\n res = (/ cos(qv), lsum(1)*sqv, lsum(2)*sqv, lsum(3)*sqv /)\n\n! and do the same with the standard deviation quaternion\n qv = sqrt(sum(dfm*dfm))\n sqv = sin(qv)/qv\n qstdev = (/ cos(qv), dfm(1)*sqv, dfm(2)*sqv, dfm(3)*sqv /)\nend if\n\nend function quat_average\n\n!--------------------------------------------------------------------------\n!\n! function: quat_average_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief computes the average of a list of quaternions using the quaternion logarithm\n! \n!> @param qlist quaternion list\n!> @param numq number of quaternions in list\n!> @param qstdev standard deviation quaternion/eigenvalues\n! \n!> @date 03/16/15 MDG 1.0 original\n!> @date 10/16/20 MDG 1.1 corrects sign of axis angle pairs when dot product with first entry is negative\n!> @date 10/16/20 MDG 1.2 add optional Tmatrix approach (largest eigenvalue determines mean)\n!--------------------------------------------------------------------------\nrecursive function quat_average_d(qlist,numq,qstdev, Tmatrix) result(res)\n!DEC$ ATTRIBUTES DLLEXPORT :: quat_average_d\n\nuse local\n\nreal(kind=dbl),INTENT(IN) :: qlist(4,numq)\ninteger(kind=irg) :: numq\nreal(kind=dbl),INTENT(OUT) :: qstdev(4)\nreal(kind=dbl) :: res(4)\nlogical,INTENT(IN),OPTIONAL :: Tmatrix\n\ninteger(kind=irg) :: i, pos(1)\nreal(kind=dbl) :: lsum(3), ax(4), qv, sqv, dfm(3), first(4), dp, qin(4), Tmat(4,4) \nreal(kind=dbl) :: axanglist(3,numq)\nlogical :: doTmatrix\n\n!LAPACK parameters \nreal(kind=dbl) :: VL(4,4), VR(4,4), Wr(4), Wi(4), WORK(20)\ninteger(kind=irg) :: nn, LDA, LDVL, LDVR, INFO, LWORK\ncharacter(1) :: JOBVL, JOBVR\n\ndoTmatrix=.FALSE.\nif (present(Tmatrix)) then \n if (Tmatrix.eqv..TRUE.) doTmatrix=.TRUE. ! use the Tmatrix approach to find the quaternion average\nend if \n\nif (doTmatrix.eqv..TRUE.) then \n Tmat = matmul(qlist,transpose(qlist))/dble(numq)\n\n! set some initial LAPACK variables \n nn = 4\n LDA = nn\n LDVL = nn\n LDVR = nn\n INFO = 0\n \n! first initialize the parameters for the LAPACK DGEEV routines\n JOBVL = 'N' ! do not compute the left eigenvectors\n JOBVR = 'V' ! do compute the right eigenvectors\n LWORK = 40 \n\n! call the eigenvalue solver\n call dgeev(JOBVL,JOBVR,nn,Tmat,LDA,Wr,Wi,VL,LDVL,VR,LDVR,WORK,LWORK,INFO)\n pos = maxloc(Wr)\n res(1:4) = VR(1:4,pos(1))\n qstdev = Wr\n! check the sign of the scalar part\n if (res(1).lt.0.D0) res = -res \n\n else ! use the quaternion logarithm to determine the average \n\n! convert each one to a logarithm, which is really the unit rotation vector multiplied by half the rotation angle\n first = qlist(1:4,1)\n do i=1,numq\n qin = qlist(1:4,i)\n! convert the quaternion to an axis angle pair\n ax = qu2ax_d(qin)\n! make sure that the dot product with first is positive \n dp = sum(first*qin)\n if (dp.lt.0.D0) then \n axanglist(1:3,i) = -ax(1:3)*0.5D0*ax(4)\n else \n axanglist(1:3,i) = ax(1:3)*0.5D0*ax(4)\n end if\n end do\n\n! compute the geometric mean\n lsum = sum(axanglist,2)/dble(numq)\n\n! then get the standard deviation from the mean\n dfm = 0.D0\n do i=1,numq\n dfm(1:3) = dfm(1:3) + (lsum - axanglist(1:3,i))**2\n end do\n dfm = dsqrt(dfm/dble(numq))\n\n! then convert this average back to a quaternion via the exponentiation operation; check interval first ?\n qv = dsqrt(sum(lsum*lsum))\n sqv = dsin(qv)/qv\n res = (/ dcos(qv), lsum(1)*sqv, lsum(2)*sqv, lsum(3)*sqv /)\n\n! and do the same with the standard deviation quaternion\n qv = dsqrt(sum(dfm*dfm))\n sqv = dsin(qv)/qv\n qstdev = (/ dcos(qv), dfm(1)*sqv, dfm(2)*sqv, dfm(3)*sqv /)\nend if \n\nend function quat_average_d\n\n\n!--------------------------------------------------------------------------\n!--------------------------------------------------------------------------\n! and finally some printing routines, mostly used for debugging\n!--------------------------------------------------------------------------\n!--------------------------------------------------------------------------\n\n!--------------------------------------------------------------------------\n!\n! SUBROUTINE: print_orientation\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief prints a complete orientationtype record or a single entry\n! \n!> @param o orientationtype record\n!> @param outtype (optional) indicates which representation to print\n!> @param pretext (optional) up to 10 characters that will precede each line\n! \n!> @date 8/4/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive subroutine print_orientation(o,outtype,pretext)\n!DEC$ ATTRIBUTES DLLEXPORT :: print_orientation\n\nuse local\nuse io\nuse constants\n\nIMPLICIT NONE\n\ntype(orientationtype),INTENT(IN) :: o\ncharacter(2),INTENT(IN),OPTIONAL :: outtype\ncharacter(10),INTENT(IN),OPTIONAL :: pretext\n\nreal(kind=sgl) :: ioreal(4)\ncharacter(10) :: pret\n\npret = ''\nif (present(pretext)) pret=trim(pretext)\n\nif (present(outtype)) then\n select case (outtype)\n case ('eu')\n ioreal(1:3) = o%eulang(1:3)*180.0/sngl(cPi)\n call WriteValue(trim(pret)//'Euler angles : ', ioreal, 3, \"(3(F8.4,' '))\")\n\n case ('ax')\n ioreal(1:4) = o%axang(1:4)\n ioreal(4) = ioreal(4)*180.0/sngl(cPi)\n call WriteValue(trim(pret)//'Axis angle pair [n; angle] : ', ioreal, 4, \"(3(F8.4,' '),'; ',F8.4)\")\n\n case ('ro')\n if (o%rodrigues(4).lt.infty()) then\n ioreal(1:3) = o%rodrigues(1:3)*o%rodrigues(4)\n call WriteValue(trim(pret)//'Rodrigues vector : ', ioreal, 3, \"(3(F12.4,' '))\")\n else\n ioreal(1:4) = o%rodrigues(1:4)\n call WriteValue(trim(pret)//'Rodrigues vector : ', ioreal, 4, \"(4(F12.4,' '))\")\n end if\n\n case ('ho')\n ioreal(1:3) = o%homochoric(1:3)\n call WriteValue(trim(pret)//'Homochoric representation : ', ioreal, 3, \"(3(F8.4,' '))\")\n\n case ('cu')\n ioreal(1:3) = o%cubochoric(1:3)\n call WriteValue(trim(pret)//'Cubochoric representation : ', ioreal, 3, \"(3(F8.4,' '))\")\n\n case ('qu')\n ioreal(1:4) = o%quat\n call WriteValue(trim(pret)//'Quaternion : ', ioreal, 4, \"(4(F8.4,' '))\")\n\n case ('st')\n ioreal(1:3) = o%stereographic\n call WriteValue(trim(pret)//'Stereographic : ', ioreal, 3, \"(3(F8.4,' '))\")\n\n case ('rv')\n ioreal(1:3) = o%rvmap\n call WriteValue(trim(pret)//'Rotation vector map : ', ioreal, 3, \"(3(F8.4,' '))\")\n\n case ('om')\n ioreal(1:3) = o%om(1,1:3)\n call WriteValue(' / ', ioreal, 3, \"(2(F8.4,' '),F8.4,' \\')\")\n ioreal(1:3) = o%om(2,1:3)\n call WriteValue(trim(pret)//'Orientation Matrix : |', ioreal, 3, \"(2(F8.4,' '),F8.4,' |')\")\n ioreal(1:3) = o%om(3,1:3)\n call WriteValue(' \\ ', ioreal, 3, \"(2(F8.4,' '),F8.4,' /')\")\n \n end select\nelse\n! print the entire record with all representations\n ioreal(1:3) = o%eulang(1:3)*180.0/sngl(cPi)\n call WriteValue(trim(pret)//'Euler angles : ', ioreal, 3, \"(3(F8.4,' '))\")\n ioreal(1:4) = o%axang(1:4)\n ioreal(4) = ioreal(4)*180.0/sngl(cPi)\n call WriteValue(trim(pret)//'Axis angle pair [n; angle] : ', ioreal, 4, \"(3(F8.4,' '),'; ',F8.4)\")\n if (o%rodrigues(4).lt.infty()) then\n ioreal(1:3) = o%rodrigues(1:3)*o%rodrigues(4)\n call WriteValue(trim(pret)//'Rodrigues vector : ', ioreal, 3, \"(3(F12.4,' '))\")\n else\n ioreal(1:4) = o%rodrigues(1:4)\n call WriteValue(trim(pret)//'Rodrigues vector : ', ioreal, 4, \"(4(F12.4,' '))\")\n end if\n ioreal(1:3) = o%homochoric(1:3)\n call WriteValue(trim(pret)//'Homochoric representation : ', ioreal, 3, \"(3(F8.4,' '))\")\n ioreal(1:3) = o%cubochoric(1:3)\n call WriteValue(trim(pret)//'Cubochoric representation : ', ioreal, 3, \"(3(F8.4,' '))\")\n ioreal(1:4) = o%quat\n call WriteValue(trim(pret)//'Quaternion : ', ioreal, 4, \"(4(F8.4,' '))\")\n ioreal(1:3) = o%stereographic\n call WriteValue(trim(pret)//'Stereographic : ', ioreal, 3, \"(3(F8.4,' '))\")\n ioreal(1:3) = o%rvmap\n call WriteValue(trim(pret)//'Rotation vector map : ', ioreal, 3, \"(3(F8.4,' '))\")\n ioreal(1:3) = o%om(1,1:3)\n call WriteValue(' / ', ioreal, 3, \"(2(F8.4,' '),F8.4,' \\')\")\n ioreal(1:3) = o%om(2,1:3)\n call WriteValue(trim(pret)//'Orientation Matrix : |', ioreal, 3, \"(2(F8.4,' '),F8.4,' |')\")\n ioreal(1:3) = o%om(3,1:3)\n call WriteValue(' \\ ', ioreal, 3, \"(2(F8.4,' '),F8.4,' /')\")\nend if\n\ncall Message(' ', frm = \"(A/)\")\n\nend subroutine print_orientation\n\n!--------------------------------------------------------------------------\n!\n! SUBROUTINE: print_orientation_d\n!\n!> @author Marc De Graef, Carnegie Mellon University\n!\n!> @brief prints a complete orientationtype record or a single entry (double precision)\n! \n!> @param o orientationtype record\n!> @param outtype (optional) indicates which representation to print\n!> @param pretext (optional) up to 10 characters that will precede each line\n!\n!> @date 8/4/13 MDG 1.0 original\n!--------------------------------------------------------------------------\nrecursive subroutine print_orientation_d(o,outtype,pretext)\n!DEC$ ATTRIBUTES DLLEXPORT :: print_orientation_d\n\nuse local\nuse io\nuse constants\n\nIMPLICIT NONE\n\ntype(orientationtyped),INTENT(IN) :: o\ncharacter(2),INTENT(IN),OPTIONAL :: outtype\ncharacter(10),INTENT(IN),OPTIONAL :: pretext\n\nreal(kind=dbl) :: ioreal(4)\ncharacter(10) :: pret\n\npret = ''\nif (present(pretext)) pret=trim(pretext)\n\nif (present(outtype)) then\n select case (outtype)\n case ('eu')\n ioreal(1:3) = o%eulang(1:3)*180.D0/cPi\n call WriteValue(trim(pret)//'Euler angles : ', ioreal, 3, \"(3(F12.7,' '))\")\n\n case ('ax')\n ioreal(1:4) = o%axang(1:4)\n ioreal(4) = ioreal(4)*180.D0/cPi\n call WriteValue(trim(pret)//'Axis angle pair [n; angle] : ', ioreal, 4, \"(3(F12.7,' '),'; ',F12.7)\")\n\n case ('ro')\n if (o%rodrigues(4).lt.inftyd()) then \n ioreal(1:3) = o%rodrigues(1:3)*o%rodrigues(4)\n call WriteValue(trim(pret)//'Rodrigues vector : ', ioreal, 3, \"(3(F16.7,' '))\")\n else\n ioreal(1:4) = o%rodrigues(1:4)\n call WriteValue(trim(pret)//'Rodrigues vector : ', ioreal, 4, \"(4(F16.7,' '))\")\n end if\n\n case ('ho')\n ioreal(1:3) = o%homochoric(1:3)\n call WriteValue(trim(pret)//'Homochoric representation : ', ioreal, 3, \"(3(F12.7,' '))\")\n\n case ('cu')\n ioreal(1:3) = o%cubochoric(1:3)\n call WriteValue(trim(pret)//'Cubochoric representation : ', ioreal, 3, \"(3(F12.7,' '))\")\n\n case ('qu')\n ioreal(1:4) = o%quat\n call WriteValue(trim(pret)//'Quaternion : ', ioreal, 4, \"(4(F12.7,' '))\")\n\n case ('st')\n ioreal(1:3) = o%stereographic\n call WriteValue(trim(pret)//'Stereographic : ', ioreal, 3, \"(3(F8.4,' '))\")\n\n case ('rv')\n ioreal(1:3) = o%rvmap\n call WriteValue(trim(pret)//'Rotation vector map : ', ioreal, 3, \"(3(F8.4,' '))\")\n\n case ('om')\n ioreal(1:3) = o%om(1,1:3)\n call WriteValue(' / ', ioreal, 3, \"(2(F8.4,' '),F8.4,' \\')\")\n ioreal(1:3) = o%om(2,1:3)\n call WriteValue(trim(pret)//'Orientation Matrix : |', ioreal, 3, \"(2(F8.4,' '),F8.4,' |')\")\n ioreal(1:3) = o%om(3,1:3)\n call WriteValue(' \\ ', ioreal, 3, \"(2(F8.4,' '),F8.4,' /')\")\n \n end select\nelse\n! print the entire record with all representations\n ioreal(1:3) = o%eulang(1:3)*180.D0/cPi\n call WriteValue(trim(pret)//'Euler angles : ', ioreal, 3, \"(3(F12.7,' '))\")\n ioreal(1:4) = o%axang(1:4)\n ioreal(4) = ioreal(4)*180.D0/cPi\n call WriteValue(trim(pret)//'Axis angle pair [n; angle] : ', ioreal, 4, \"(3(F12.7,' '),'; ',F12.7)\")\n if (o%rodrigues(4).lt.inftyd()) then \n ioreal(1:3) = o%rodrigues(1:3)*o%rodrigues(4)\n call WriteValue(trim(pret)//'Rodrigues vector : ', ioreal, 3, \"(3(F16.7,' '))\")\n else\n ioreal(1:4) = o%rodrigues(1:4)\n call WriteValue(trim(pret)//'Rodrigues vector : ', ioreal, 4, \"(4(F16.7,' '))\")\n end if\n ioreal(1:3) = o%homochoric(1:3)\n call WriteValue(trim(pret)//'Homochoric representation : ', ioreal, 3, \"(3(F12.7,' '))\")\n ioreal(1:3) = o%cubochoric(1:3)\n call WriteValue(trim(pret)//'Cubochoric representation : ', ioreal, 3, \"(3(F12.7,' '))\")\n ioreal(1:4) = o%quat\n call WriteValue(trim(pret)//'Quaternion : ', ioreal, 4, \"(4(F12.7,' '))\")\n ioreal(1:3) = o%stereographic\n call WriteValue(trim(pret)//'Stereographic : ', ioreal, 3, \"(3(F8.4,' '))\")\n ioreal(1:3) = o%rvmap\n call WriteValue(trim(pret)//'Rotation vector map : ', ioreal, 3, \"(3(F8.4,' '))\")\n ioreal(1:3) = o%om(1,1:3)\n call WriteValue(' / ', ioreal, 3, \"(2(F8.4,' '),F8.4,' \\')\")\n ioreal(1:3) = o%om(2,1:3)\n call WriteValue(trim(pret)//'Orientation Matrix : | ', ioreal, 3, \"(2(F8.4,' '),F8.4,' |')\")\n ioreal(1:3) = o%om(3,1:3)\n call WriteValue(' \\ ', ioreal, 3, \"(2(F8.4,' '),F8.4,' /')\")\nend if\n\ncall Message(' ', frm = \"(A/)\")\n\nend subroutine print_orientation_d\n\n\n\nend module rotations\n", "meta": {"hexsha": "07596dc6d02d696810e8212d79a67f21bc827fa5", "size": 213395, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Source/EMsoftLib/rotations.f90", "max_stars_repo_name": "josephtessmer/EMsoft", "max_stars_repo_head_hexsha": "b6f73c76c52ff7bfa432119b91d3981c8e97fd11", "max_stars_repo_licenses": ["Intel", "Unlicense", "MIT-CMU", "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": "Source/EMsoftLib/rotations.f90", "max_issues_repo_name": "josephtessmer/EMsoft", "max_issues_repo_head_hexsha": "b6f73c76c52ff7bfa432119b91d3981c8e97fd11", "max_issues_repo_licenses": ["Intel", "Unlicense", "MIT-CMU", "BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Source/EMsoftLib/rotations.f90", "max_forks_repo_name": "josephtessmer/EMsoft", "max_forks_repo_head_hexsha": "b6f73c76c52ff7bfa432119b91d3981c8e97fd11", "max_forks_repo_licenses": ["Intel", "Unlicense", "MIT-CMU", "BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.7100376574, "max_line_length": 130, "alphanum_fraction": 0.5330162375, "num_tokens": 59844, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648677, "lm_q2_score": 0.7826624688140726, "lm_q1q2_score": 0.6841074468083141}} {"text": "!==============================================================================\n! Module WELL_MODULE (28-Jun-2017)\n!\n! Written by:\n! \t Dr. Randal J. Barnes\n! Department of Civil, Environmental, and Geo- Engineering\n! University of Minnesota\n! \n!==============================================================================\n\n!==============================================================================\nMODULE WELL_MODULE\n!==============================================================================\n USE CONSTANTS_MODULE\n IMPLICIT NONE\n\n !===========================================================================\n ! Type T_WELL\n !===========================================================================\n TYPE T_WELL\n REAL(8) :: X = 0 ! X coordinate\n REAL(8) :: Y = 0 ! Y coordinate\n REAL(8) :: R = 0 ! radius\n REAL(8) :: Q = 0 ! discharge\n END TYPE T_WELL\n\n !===========================================================================\n ! INTERFACES\n !===========================================================================\n INTERFACE Potential\n MODULE PROCEDURE Potential_Well\n END INTERFACE\n\n INTERFACE Discharge\n MODULE PROCEDURE Discharge_Well\n END INTERFACE\n\n\nCONTAINS\n !---------------------------------------------------------------------------\n ! Potential_Well\n !---------------------------------------------------------------------------\n FUNCTION Potential_Well( Well, X, Y ) Result( Phi )\n\n ! Declare the arguments.\n TYPE(T_WELL), INTENT(IN) :: Well ! well of interest\n REAL(8), INTENT(IN) :: X ! X coordinate of interest\n REAL(8), INTENT(IN) :: Y ! Y coordinate of interest\n\n REAL(8) :: Phi ! resulting discharge potential\n\n ! Declare the local variables.\n REAL(8) :: R\n\n ! Compute the discharge potential for the well.\n R = HYPOT(X - Well%X, Y - Well%Y)\n\n IF( R .LT. Well%R ) THEN\n Phi = Well%Q/TWO_PI * LOG(Well%R)\n ELSE\n Phi = Well%Q/TWO_PI * LOG(R)\n END IF\n\n END FUNCTION Potential_Well\n\n\n !---------------------------------------------------------------------------\n ! Discharge_Well\n !---------------------------------------------------------------------------\n FUNCTION Discharge_Well( Well, X, Y ) RESULT( Q )\n\n ! Declare the arguments.\n TYPE(T_WELL), INTENT(IN) :: Well ! well of interest\n REAL(8), INTENT(IN) :: X ! X coordinate of interest\n REAL(8), INTENT(IN) :: Y ! Y coordinate of interest\n\n REAL(8), DIMENSION(2) :: Q ! resulting discharge vector\n\n ! Declare the local variables.\n REAL(8) :: DX, DY, R2\n\n ! Compute the discharge for the well.\n DX = X - Well%X\n DY = Y - Well%Y\n R2 = DX*DX + DY*DY\n\n IF( R2 .LT. Well%R*Well%R ) THEN\n Q = 0\n ELSE\n Q(1) = -Well%Q/TWO_PI * DX/R2\n Q(2) = -Well%Q/TWO_PI * DY/R2\n END IF\n\n END FUNCTION Discharge_Well\n\n\n!==============================================================================\nEND MODULE WELL_MODULE\n!==============================================================================\n", "meta": {"hexsha": "f9dee61e20256f1740fa4bf8cc7806474fc33fd8", "size": 3187, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/Well.f95", "max_stars_repo_name": "RandalJBarnes/Oneka", "max_stars_repo_head_hexsha": "89fe33315047faeadc4ea02481e8d923b04c4feb", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/Well.f95", "max_issues_repo_name": "RandalJBarnes/Oneka", "max_issues_repo_head_hexsha": "89fe33315047faeadc4ea02481e8d923b04c4feb", "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/Well.f95", "max_forks_repo_name": "RandalJBarnes/Oneka", "max_forks_repo_head_hexsha": "89fe33315047faeadc4ea02481e8d923b04c4feb", "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.87, "max_line_length": 79, "alphanum_fraction": 0.3806087229, "num_tokens": 682, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772220439509, "lm_q2_score": 0.7826624789529376, "lm_q1q2_score": 0.6841074454012159}} {"text": "\r\nMODULE Cone\r\n USE bellhopMod\r\n USE MathConstants\r\n IMPLICIT NONE\r\n\r\nCONTAINS\r\n\r\n SUBROUTINE ConeFormulas2D( z_xx, z_xy, z_yy, nBdry, xs, tradial, xray, BotTop )\r\n\r\n ! analytic formula for the conical seamount\r\n REAL (KIND=8), INTENT( IN ) :: xs( 3 ), tradial( 2 ), xray( 2 )\r\n CHARACTER (LEN=3), INTENT( IN ) :: BotTop ! Flag indicating bottom or top reflection\r\n REAL (KIND=8), INTENT( OUT ) :: z_xx, z_xy, z_yy, nBdry( 2 )\r\n REAL (KIND=8) :: nBdry3dCone( 3 ), theta, phi, Rray, Radius, x, y ! for cone reflection\r\n\r\n IF ( BotTop == 'BOT' ) THEN\r\n phi = 15 * DegRad ! 15 degree angle of seamount\r\n Rray = xray( 1 ) ! cylindrical range of ray from source\r\n\r\n ! get bearing from cone to ray using (x,y) coordinate of the ray\r\n x = xs( 1 ) + Rray * tradial( 1 )\r\n y = xs( 2 ) + Rray * tradial( 2 )\r\n theta = atan2( y, x )\r\n\r\n nBdry3dCone = [ -cos( theta ) * sin( phi ), -sin( theta ) * sin( phi ), cos( phi ) ]\r\n\r\n ! nBdry3dCone = -[ -cos( theta ) * tan( phi ), -sin( theta ) * tan( phi ), 1.0D0 ]\r\n ! nBdry3dCone = -[ ray2D( is )%x( 1 ), ray2D( is )%x( 2 ), -1.0D0 ]\r\n ! nBdry3dCone = NBdry3dCone / NORM2( NBdry3dCone )\r\n\r\n nBdry( 1 ) = DOT_PRODUCT( nBdry3dCone( 1 : 2 ), tradial )\r\n nBdry( 2 ) = nBdry3dCone( 3 )\r\n\r\n ! curvatures\r\n Radius = SQRT( x ** 2 + y ** 2 ) ! radius of seamount at the bounce point\r\n\r\n ! z = z_xx / 2 * x^2 + z_xy * xy + z_yy / 2 * y^2; coefs are the kappa matrix\r\n\r\n z_xx = y * y / Radius**3 * tan( phi )\r\n z_xy = - x * y / Radius**3 * tan( phi )\r\n z_yy = x * x / Radius**3 * tan( phi )\r\n END IF\r\nEND SUBROUTINE ConeFormulas2D\r\n\r\n SUBROUTINE ConeFormulas3D( z_xx, z_xy, z_yy, nBdry, xs, xray, BotTop )\r\n\r\n ! analytic formula for the conical seamount\r\n\r\n REAL (KIND=8), INTENT( IN ) :: xs( 3 ), xray( 3 )\r\n CHARACTER (LEN=3), INTENT( IN ) :: BotTop ! Flag indicating bottom or top reflection\r\n REAL (KIND=8), INTENT( OUT ) :: z_xx, z_xy, z_yy, nBdry( 3 )\r\n REAL (KIND=8) :: theta, phi, Radius, x, y, RLen\r\n\r\n IF ( BotTop == 'BOT' ) THEN\r\n phi = 15 * DegRad ! 15 degree angle of seamount\r\n\r\n x = xray( 1 )\r\n y = xray( 2 )\r\n\r\n theta = atan2( y, x ) ! bearing from origin (center of cone) to ray\r\n ! could write the folowing in terms of x, y, and z ...\r\n nBdry = [ -cos( theta ) * sin( phi ), -sin( theta ) * sin( phi ), cos( phi ) ] ! unit normal to bdry\r\n\r\n ! curvatures\r\n\r\n Radius = SQRT( x ** 2 + y ** 2 ) ! radius of seamount at the bounce point\r\n ! z = z_xx / 2 * x^2 + z_xy * xy + z_yy * y^2 ! coefs are the kappa matrix\r\n\r\n RLen = SQRT( 1 + TAN( phi ) ** 2 ) ! 1 + fx^2 + fy^2\r\n z_xx = y * y / Radius**3 * tan( phi ) / RLen\r\n z_xy = - x * y / Radius**3 * tan( phi ) / RLen\r\n z_yy = x * x / Radius**3 * tan( phi ) / RLen\r\n END IF\r\n END SUBROUTINE ConeFormulas3D\r\n\r\nEND MODULE CONE\r\n\r\n", "meta": {"hexsha": "70c53abd8a75d22e232e838ffb8ad2106d9bf897", "size": 2995, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "at_2020_11_4/Bellhop/Cone.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/Bellhop/Cone.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": "bellhop/Cone.f90", "max_forks_repo_name": "IvanaEscobar/sandbox", "max_forks_repo_head_hexsha": "71d62af2c112686c5ce26def35593247cf6a0ccc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.9113924051, "max_line_length": 110, "alphanum_fraction": 0.534557596, "num_tokens": 1104, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418199787564, "lm_q2_score": 0.7401743677704878, "lm_q1q2_score": 0.684026087333044}} {"text": " SUBROUTINE spear(data1,data2,n,wksp1,wksp2,d,zd,probd,rs,probrs)\r\n INTEGER n\r\n REAL d,probd,probrs,rs,zd,data1(n),data2(n),wksp1(n),wksp2(n)\r\nCU USES betai,crank,erfcc,sort2\r\n INTEGER j\r\n REAL aved,df,en,en3n,fac,sf,sg,t,vard,betai,erfcc\r\n do 11 j=1,n\r\n wksp1(j)=data1(j)\r\n wksp2(j)=data2(j)\r\n11 continue\r\n call sort2(n,wksp1,wksp2)\r\n call crank(n,wksp1,sf)\r\n call sort2(n,wksp2,wksp1)\r\n call crank(n,wksp2,sg)\r\n d=0.\r\n do 12 j=1,n\r\n d=d+(wksp1(j)-wksp2(j))**2\r\n12 continue\r\n en=n\r\n en3n=en**3-en\r\n aved=en3n/6.-(sf+sg)/12.\r\n fac=(1.-sf/en3n)*(1.-sg/en3n)\r\n vard=((en-1.)*en**2*(en+1.)**2/36.)*fac\r\n zd=(d-aved)/sqrt(vard)\r\n probd=erfcc(abs(zd)/1.4142136)\r\n rs=(1.-(6./en3n)*(d+(sf+sg)/12.))/sqrt(fac)\r\n fac=(1.+rs)*(1.-rs)\r\n if(fac.gt.0.)then\r\n t=rs*sqrt((en-2.)/fac)\r\n df=en-2.\r\n probrs=betai(0.5*df,0.5,df/(df+t**2))\r\n else\r\n probrs=0.\r\n endif\r\n return\r\n END\r\n", "meta": {"hexsha": "257ca752ab9ed7bfa0d2845ce7794ddf643f03fa", "size": 1052, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/spear.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/spear.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/spear.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.4324324324, "max_line_length": 71, "alphanum_fraction": 0.5085551331, "num_tokens": 439, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418116217418, "lm_q2_score": 0.7401743677704878, "lm_q1q2_score": 0.684026081147396}} {"text": "FUNCTION gamma_s(xx)\n USE mo_kind, only: sp\n USE mo_nrutil, ONLY : arth,assert\n IMPLICIT NONE\n REAL(SP), INTENT(IN) :: xx\n REAL(SP) :: gamma_s\n REAL(sp) :: tmp,x\n REAL(sp) :: stp = 2.5066282746310005_sp\n REAL(sp), DIMENSION(6) :: coef = (/76.18009172947146_sp,&\n -86.50532032941677_sp,24.01409824083091_sp,&\n -1.231739572450155_sp,0.1208650973866179e-2_sp,&\n -0.5395239384953e-5_sp/)\n call assert(xx > 0.0, 'gamma_s arg')\n x=xx\n tmp=x+5.5_sp\n tmp=(x+0.5_sp)*log(tmp)-tmp\n gamma_s=tmp+log(stp*(1.000000000190015_sp+&\n sum(coef(:)/arth(x+1.0_sp,1.0_sp,size(coef))))/x)\n gamma_s=exp(gamma_s)\nEND FUNCTION gamma_s\n\n\nFUNCTION gamma_v(xx)\n USE mo_kind, only: sp, i4\n USE mo_nrutil, ONLY: assert\n IMPLICIT NONE\n INTEGER(I4) :: i\n REAL(SP), DIMENSION(:), INTENT(IN) :: xx\n REAL(SP), DIMENSION(size(xx)) :: gamma_v\n REAL(sp), DIMENSION(size(xx)) :: ser,tmp,x,y\n REAL(sp) :: stp = 2.5066282746310005_sp\n REAL(sp), DIMENSION(6) :: coef = (/76.18009172947146_sp,&\n -86.50532032941677_sp,24.01409824083091_sp,&\n -1.231739572450155_sp,0.1208650973866179e-2_sp,&\n -0.5395239384953e-5_sp/)\n if (size(xx) == 0) RETURN\n call assert(all(xx > 0.0), 'gamma_v arg')\n x=xx\n tmp=x+5.5_sp\n tmp=(x+0.5_sp)*log(tmp)-tmp\n ser=1.000000000190015_sp\n y=x\n do i=1,size(coef)\n y=y+1.0_sp\n ser=ser+coef(i)/y\n end do\n gamma_v=tmp+log(stp*ser/x)\n gamma_v=exp(gamma_v)\nEND FUNCTION gamma_v\n\n\nFUNCTION dgamma_s(z)\n ! Uses Lanczos-type approximation to ln(gamma) for z > 0.\n ! Reference:\n ! Lanczos, C. ''A precision approximation of the gamma\n ! function'', J. SIAM Numer. Anal., B, 1, 86-96, 1964.\n ! Accuracy: About 14 significant digits except for small regions\n ! in the vicinity of 1 and 2.\n ! Programmer: Alan Miller\n ! 1 Creswick Street, Brighton, Vic. 3187, Australia\n ! e-mail: amiller @ bigpond.net.au\n ! Latest revision - 14 October 1996\n USE mo_kind, only: dp\n USE mo_nrutil, ONLY : assert\n IMPLICIT NONE\n REAL(DP), INTENT(IN) :: z\n REAL(DP) :: dgamma_s\n ! Local variables\n REAL(DP) :: a(9) = (/ 0.9999999999995183_dp, 676.5203681218835_dp, &\n -1259.139216722289_dp, 771.3234287757674_dp, &\n -176.6150291498386_dp, 12.50734324009056_dp, &\n -0.1385710331296526_dp, 0.9934937113930748D-05, &\n 0.1659470187408462D-06 /)\n REAL(DP) :: zero = 0.0_dp, &\n one = 1.0_dp, &\n lnsqrt2pi = 0.9189385332046727_dp, &\n half = 0.5_dp, &\n sixpt5 = 6.5_dp, &\n seven = 7.0_dp\n REAL(DP) :: tmp\n INTEGER :: j\n call assert(z > zero, 'dgamma_s arg')\n dgamma_s = zero\n tmp = z + seven\n DO j = 9, 2, -1\n dgamma_s = dgamma_s + a(j)/tmp\n tmp = tmp - one\n END DO\n dgamma_s = dgamma_s + a(1)\n dgamma_s = LOG(dgamma_s) + lnsqrt2pi - (z + sixpt5) + (z - half)*LOG(z + sixpt5)\n dgamma_s = exp(dgamma_s)\nEND FUNCTION dgamma_s\n\n\nFUNCTION dgamma_v(z)\n ! Uses Lanczos-type approximation to ln(gamma) for z > 0.\n ! Reference:\n ! Lanczos, C. ''A precision approximation of the gamma\n ! function'', J. SIAM Numer. Anal., B, 1, 86-96, 1964.\n ! Accuracy: About 14 significant digits except for small regions\n ! in the vicinity of 1 and 2.\n ! Programmer: Alan Miller\n ! 1 Creswick Street, Brighton, Vic. 3187, Australia\n ! e-mail: amiller @ bigpond.net.au\n ! Latest revision - 14 October 1996\n USE mo_kind, only: dp\n USE mo_nrutil, ONLY : assert\n IMPLICIT NONE\n REAL(DP), DIMENSION(:), INTENT(IN) :: z\n REAL(DP), DIMENSION(size(z)) :: dgamma_v\n ! Local variables\n REAL(DP) :: a(9) = (/ 0.9999999999995183_dp, 676.5203681218835_dp, &\n -1259.139216722289_dp, 771.3234287757674_dp, &\n -176.6150291498386_dp, 12.50734324009056_dp, &\n -0.1385710331296526_dp, 0.9934937113930748D-05, &\n 0.1659470187408462D-06 /)\n REAL(DP) :: zero = 0.0_dp, &\n one = 1.0_dp, &\n lnsqrt2pi = 0.9189385332046727_dp, &\n half = 0.5_dp, &\n sixpt5 = 6.5_dp, &\n seven = 7.0_dp\n REAL(DP), DIMENSION(size(z)) :: tmp\n INTEGER :: j\n if (size(z) == 0) RETURN\n call assert(all(z > 0.0_dp), 'dgamma_v arg')\n dgamma_v = zero\n tmp = z + seven\n DO j = 9, 2, -1\n dgamma_v = dgamma_v + a(j)/tmp\n tmp = tmp - one\n END DO\n dgamma_v = dgamma_v + a(1)\n dgamma_v = LOG(dgamma_v) + lnsqrt2pi - (z + sixpt5) + (z - half)*LOG(z + sixpt5)\n dgamma_v = exp(dgamma_v)\nEND FUNCTION dgamma_v\n", "meta": {"hexsha": "e2b319557e3e1bdcbbbe9add071eecb19a701d37", "size": 4449, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "nr_jams/gamma.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/gamma.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/gamma.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": 32.4744525547, "max_line_length": 82, "alphanum_fraction": 0.6262081367, "num_tokens": 1712, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190939, "lm_q2_score": 0.7956580952177053, "lm_q1q2_score": 0.6839984165369926}} {"text": "!*******************************************************************************\n!> author: Jacob Williams\n!\n! Test for the [[slsqp_module]].\n\n program slsqp_test_3\n\n use slsqp_module\n use slsqp_kinds\n\n implicit none\n\n integer,parameter :: n = 2 !! number of optimization variables\n integer,parameter :: m = 1 !! total number of constraints\n integer,parameter :: meq = 0 !! number of equality constraints\n integer,parameter :: max_iter = 100 !! maximum number of allowed iterations\n real(wp),dimension(n),parameter :: xl = [-1.0_wp, -1.0_wp] !! lower bounds\n real(wp),dimension(n),parameter :: xu = [ 1.0_wp, 1.0_wp] !! upper bounds\n real(wp),parameter :: acc = 1.0e-8_wp !! tolerance\n integer,parameter :: linesearch_mode = 1 !! use inexact linesearch.\n real(wp),parameter :: gradient_delta = 1.0e-5_wp !! step to approximate gradient\n\n type(slsqp_solver) :: solver !! instantiate an slsqp solver\n real(wp),dimension(n) :: x !! optimization variable vector\n integer :: istat !! for solver status check\n logical :: status_ok !! for initialization status check\n integer :: iterations !! number of iterations by the solver\n integer :: gradient_mode !! gradient computation mode\n\n ! test each of the gradient modes (backward, forward, and central diffs)\n do gradient_mode = 1, 3\n\n write(*,*) ''\n write(*,*) '---------------------------'\n write(*,*) 'gradient mode:', gradient_mode\n write(*,*) '---------------------------'\n\n x = [0.1_wp, 0.1_wp] !initial guess\n\n call solver%initialize(n,m,meq,max_iter,acc,rosenbrock_func,dummy_grad,&\n xl,xu,linesearch_mode=linesearch_mode,status_ok=status_ok,&\n report=report_iteration,&\n gradient_mode=gradient_mode,gradient_delta=gradient_delta)\n\n if (status_ok) then\n call solver%optimize(x,istat,iterations)\n write(*,*) ''\n write(*,*) 'solution :', x\n write(*,*) 'istat :', istat\n write(*,*) 'iterations :', iterations\n write(*,*) ''\n else\n error stop 'error calling slsqp.'\n end if\n\n end do\n\n !solution: x1 = 0.7864151509699762\n ! x2 = 0.6176983165977831\n ! f = 0.0456748087191604\n ! c = -0.0000000000028654\n\n contains\n\n subroutine rosenbrock_func(me,x,f,c)\n !! Rosenbrock function\n !!\n !! Minimize the Rosenbrock function: \\( f(x) = 100 (x_2 - x_1)^2 + (1 - x_1)^2 \\),\n !! subject to the inequality constraint: \\( x_1^2 + x_2^2 \\le 1 \\).\n !!\n !! see: http://www.mathworks.com/help/optim/ug/example-nonlinear-constrained-minimization.html\n implicit none\n class(slsqp_solver),intent(inout) :: me\n real(wp),dimension(:),intent(in) :: x !! optimization variable vector\n real(wp),intent(out) :: f !! value of the objective function\n real(wp),dimension(:),intent(out) :: c !! the constraint vector `dimension(m)`,\n !! equality constraints (if any) first.\n\n f = 100.0_wp*(x(2) - x(1)**2)**2 + (1.0_wp - x(1))**2 !objective function\n c(1) = 1.0_wp - x(1)**2 - x(2)**2 !equality constraint (>=0)\n\n end subroutine rosenbrock_func\n\n subroutine dummy_grad(me,x,g,a)\n\n !! not used in this case\n\n implicit none\n\n class(slsqp_solver),intent(inout) :: me\n real(wp),dimension(:),intent(in) :: x !! optimization variable vector\n real(wp),dimension(:),intent(out) :: g !! objective function partials w.r.t x `dimension(n)`\n real(wp),dimension(:,:),intent(out) :: a !! gradient matrix of constraints w.r.t. x `dimension(m,n)`\n\n error stop 'this routine is not meant to be called'\n\n end subroutine dummy_grad\n\n subroutine report_iteration(me,iter,x,f,c)\n use, intrinsic :: iso_fortran_env, only: output_unit\n !! report an iteration (print to the console).\n implicit none\n class(slsqp_solver),intent(inout) :: me\n integer,intent(in) :: iter\n real(wp),dimension(:),intent(in) :: x\n real(wp),intent(in) :: f\n real(wp),dimension(:),intent(in) :: c\n\n !write a header:\n if (iter==0) then\n write(output_unit,'(*(A20,1X))') 'iteration', 'x(1)', 'x(2)', 'f(1)', 'c(1)'\n end if\n\n !write the iteration data:\n write(output_unit,'(I20,1X,(*(F20.16,1X)))') iter,x,f,c\n\n end subroutine report_iteration\n\n end program slsqp_test_3\n!*******************************************************************************\n", "meta": {"hexsha": "538c639f04bc50c22643eb0f21a235733c880e75", "size": 5060, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/slsqp_test_3.f90", "max_stars_repo_name": "LKedward/slsqp", "max_stars_repo_head_hexsha": "163628e77d5de6d8647c6f44d2bf9cdf9dbb04f2", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 52, "max_stars_repo_stars_event_min_datetime": "2016-01-12T17:41:53.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-30T09:38:15.000Z", "max_issues_repo_path": "src/tests/slsqp_test_3.f90", "max_issues_repo_name": "LKedward/slsqp", "max_issues_repo_head_hexsha": "163628e77d5de6d8647c6f44d2bf9cdf9dbb04f2", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 20, "max_issues_repo_issues_event_min_datetime": "2018-03-14T21:58:16.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-26T15:19:49.000Z", "max_forks_repo_path": "src/tests/slsqp_test_3.f90", "max_forks_repo_name": "LKedward/slsqp", "max_forks_repo_head_hexsha": "163628e77d5de6d8647c6f44d2bf9cdf9dbb04f2", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2016-03-28T10:37:10.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-05T06:33:41.000Z", "avg_line_length": 41.8181818182, "max_line_length": 111, "alphanum_fraction": 0.5201581028, "num_tokens": 1258, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240930029118, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.6839858822321792}} {"text": " PROGRAM xbanmul\r\nC driver for routine banmul\r\n INTEGER NP,M1,M2,MP\r\n PARAMETER (NP=7,M1=2,M2=1,MP=M1+1+M2)\r\n INTEGER i,j,k\r\n REAL a(NP,MP),aa(NP,NP),ax(NP),b(NP),x(NP)\r\n do 12 i=1,M1\r\n do 11 j=1,NP\r\n a(j,i)=10*j+i\r\n11 continue\r\n12 continue\r\nC lower band\r\n do 13 i=1,NP\r\n a(i,M1+1)=i\r\n13 continue\r\nC diagonal\r\n do 15 i=1,M2\r\n do 14 j=1,NP\r\n a(j,M1+1+i)=0.1*j+i\r\n14 continue\r\n15 continue\r\nC upper band\r\n do 17 i=1,NP\r\n do 16 j=1,NP\r\n k=i-M1-1\r\n if (j.ge.max(1,1+k).and.j.le.min(M1+M2+1+k,NP)) then\r\n aa(i,j)=a(i,j-k)\r\n else\r\n aa(i,j)=0.0\r\n endif\r\n16 continue\r\n17 continue\r\n do 18 i=1,NP\r\n x(i)=i/10.0\r\n18 continue\r\n call banmul(a,NP,M1,M2,NP,MP,x,b)\r\n do 21 i=1,NP\r\n ax(i)=0.0\r\n do 19 j=1,NP\r\n ax(i)=ax(i)+aa(i,j)*x(j)\r\n19 continue\r\n21 continue\r\n write(*,'(t8,a,t32,a)') 'Reference vector','banmul vector'\r\n do 22 i=1,NP\r\n write(*,'(t8,f12.4,t32,f12.4)') ax(i),b(i)\r\n22 continue\r\n END\r\n", "meta": {"hexsha": "43025033cc453b3cfd0e48c0f38e74455f72688d", "size": 1158, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xbanmul.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xbanmul.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xbanmul.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.125, "max_line_length": 65, "alphanum_fraction": 0.4602763385, "num_tokens": 444, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240964782011, "lm_q2_score": 0.7905303137346446, "lm_q1q2_score": 0.6839858764396867}} {"text": "!*****************************************************************************************\n!\n!> Units test for 2d-6d linear interpolation.\n\n program linear_interpolation_test\n\n use linear_interpolation_module\n use,intrinsic :: iso_fortran_env, only: wp => real64\n\n implicit none\n\n integer,parameter :: nx = 6 !! number of points in x\n integer,parameter :: ny = 6 !! number of points in y\n integer,parameter :: nz = 6 !! number of points in z\n integer,parameter :: nq = 6 !! number of points in q\n integer,parameter :: nr = 6 !! number of points in r\n integer,parameter :: ns = 6 !! number of points in s\n\n real(wp) :: x(nx),y(ny),z(nz),q(nq),r(nr),s(ns)\n real(wp) :: fcn_1d(nx)\n real(wp) :: fcn_2d(nx,ny)\n real(wp) :: fcn_3d(nx,ny,nz)\n real(wp) :: fcn_4d(nx,ny,nz,nq)\n real(wp) :: fcn_5d(nx,ny,nz,nq,nr)\n real(wp) :: fcn_6d(nx,ny,nz,nq,nr,ns)\n\n type(linear_interp_1d) :: s1\n type(linear_interp_2d) :: s2\n type(linear_interp_3d) :: s3\n type(linear_interp_4d) :: s4\n type(linear_interp_5d) :: s5\n type(linear_interp_6d) :: s6\n\n real(wp) :: tol,rnd\n real(wp),dimension(6) :: val,tru,err,errmax\n logical :: fail\n integer :: i,j,k,l,m,n,idx,idy,idz,idq,idr,ids\n integer,dimension(6) :: iflag\n\n fail = .false.\n tol = 1.0e-14_wp\n do i=1,nx\n x(i) = dble(i-1)/dble(nx-1)\n end do\n do j=1,ny\n y(j) = dble(j-1)/dble(ny-1)\n end do\n do k=1,nz\n z(k) = dble(k-1)/dble(nz-1)\n end do\n do l=1,nq\n q(l) = dble(l-1)/dble(nq-1)\n end do\n do m=1,nr\n r(m) = dble(m-1)/dble(nr-1)\n end do\n do n=1,ns\n s(n) = dble(n-1)/dble(ns-1)\n end do\n do i=1,nx\n fcn_1d(i) = f1(x(i))\n do j=1,ny\n fcn_2d(i,j) = f2(x(i),y(j))\n do k=1,nz\n fcn_3d(i,j,k) = f3(x(i),y(j),z(k))\n do l=1,nq\n fcn_4d(i,j,k,l) = f4(x(i),y(j),z(k),q(l))\n do m=1,nr\n fcn_5d(i,j,k,l,m) = f5(x(i),y(j),z(k),q(l),r(m))\n do n=1,ns\n fcn_6d(i,j,k,l,m,n) = f6(x(i),y(j),z(k),q(l),r(m),s(n))\n end do\n end do\n end do\n end do\n end do\n end do\n\n ! initialize\n call s1%initialize(x,fcn_1d, iflag(1))\n call s2%initialize(x,y,fcn_2d, iflag(2))\n call s3%initialize(x,y,z,fcn_3d, iflag(3))\n call s4%initialize(x,y,z,q,fcn_4d, iflag(4))\n call s5%initialize(x,y,z,q,r,fcn_5d, iflag(5))\n call s6%initialize(x,y,z,q,r,s,fcn_6d, iflag(6))\n\n if (any(iflag/=0)) then\n do i=1,6\n if (iflag(i)/=0) then\n write(*,*) 'Error initializing ',i,'D interpolator. iflag=',iflag(i)\n end if\n end do\n stop 1\n end if\n\n ! compute max error at interpolation points\n\n errmax = 0.0_wp\n do i=1,nx\n call RANDOM_NUMBER(rnd); rnd = (rnd - 0.5_wp) / 100.0_wp\n call s1%evaluate(x(i)+rnd,val(1))\n tru(1) = f1(x(i)+rnd)\n err(1) = abs(tru(1)-val(1))\n errmax(1) = max(err(1),errmax(1))\n do j=1,ny\n call RANDOM_NUMBER(rnd); rnd = rnd / 100.0_wp\n call s2%evaluate(x(i)+rnd,y(j)+rnd,val(2))\n tru(2) = f2(x(i)+rnd,y(j)+rnd)\n err(2) = abs(tru(2)-val(2))\n errmax(2) = max(err(2),errmax(2))\n do k=1,nz\n call RANDOM_NUMBER(rnd); rnd = rnd / 100.0_wp\n call s3%evaluate(x(i)+rnd,y(j)+rnd,z(k)+rnd,val(3))\n tru(3) = f3(x(i)+rnd,y(j)+rnd,z(k)+rnd)\n err(3) = abs(tru(3)-val(3))\n errmax(3) = max(err(3),errmax(3))\n do l=1,nq\n call RANDOM_NUMBER(rnd); rnd = rnd / 100.0_wp\n call s4%evaluate(x(i)+rnd,y(j)+rnd,z(k)+rnd,q(l)+rnd,val(4))\n tru(4) = f4(x(i)+rnd,y(j)+rnd,z(k)+rnd,q(l)+rnd)\n err(4) = abs(tru(4)-val(4))\n errmax(4) = max(err(4),errmax(4))\n do m=1,nr\n call RANDOM_NUMBER(rnd); rnd = rnd / 100.0_wp\n call s5%evaluate(x(i)+rnd,y(j)+rnd,z(k)+rnd,q(l)+rnd,r(m)+rnd,val(5))\n tru(5) = f5(x(i)+rnd,y(j)+rnd,z(k)+rnd,q(l)+rnd,r(m)+rnd)\n err(5) = abs(tru(5)-val(5))\n errmax(5) = max(err(5),errmax(5))\n do n=1,ns\n call RANDOM_NUMBER(rnd); rnd = rnd / 100.0_wp\n call s6%evaluate(x(i)+rnd,y(j)+rnd,z(k)+rnd,q(l)+rnd,r(m)+rnd,s(n)+rnd,val(6))\n tru(6) = f6(x(i)+rnd,y(j)+rnd,z(k)+rnd,q(l)+rnd,r(m)+rnd,s(n)+rnd)\n err(6) = abs(tru(6)-val(6))\n errmax(6) = max(err(6),errmax(6))\n end do\n end do\n end do\n end do\n end do\n end do\n\n ! check max error against tolerance\n do i=1,6\n write(*,*) i,'D: max error:', errmax(i)\n if (errmax(i) >= tol) then\n write(*,*) ' ** test failed ** '\n else\n write(*,*) ' ** test passed ** '\n end if\n write(*,*) ''\n end do\n\n contains\n\n real(wp) function f1(x) !! 1d test function\n implicit none\n real(wp),intent(in) :: x\n f1 = x + x + x + x + x + x\n end function f1\n\n real(wp) function f2(x,y) !! 2d test function\n implicit none\n real(wp),intent(in) :: x,y\n f2 = x + y + x + y + x + y\n end function f2\n\n real(wp) function f3 (x,y,z) !! 3d test function\n implicit none\n real(wp),intent(in) :: x,y,z\n f3 = x + y + z + x + y + z\n end function f3\n\n real(wp) function f4 (x,y,z,q) !! 4d test function\n implicit none\n real(wp),intent(in) :: x,y,z,q\n f4 = x + y + z + q + x + y\n end function f4\n\n real(wp) function f5 (x,y,z,q,r) !! 5d test function\n implicit none\n real(wp),intent(in) :: x,y,z,q,r\n f5 = x + y + z + q + r + x\n end function f5\n\n real(wp) function f6 (x,y,z,q,r,s) !! 6d test function\n implicit none\n real(wp),intent(in) :: x,y,z,q,r,s\n f6 = x + y + z + q + r + s\n end function f6\n\n end program linear_interpolation_test\n", "meta": {"hexsha": "83b57673d911df84667df2e2e5bcd18ab196d6e2", "size": 6654, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/test.f90", "max_stars_repo_name": "jacobwilliams/finterp", "max_stars_repo_head_hexsha": "cccb3c9c5547d951983bf8471f7abb0191f712fa", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2016-03-02T03:08:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T21:02:34.000Z", "max_issues_repo_path": "test/test.f90", "max_issues_repo_name": "jacobwilliams/finterp", "max_issues_repo_head_hexsha": "cccb3c9c5547d951983bf8471f7abb0191f712fa", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-10-10T04:31:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T23:57:05.000Z", "max_forks_repo_path": "test/test.f90", "max_forks_repo_name": "jacobwilliams/finterp", "max_forks_repo_head_hexsha": "cccb3c9c5547d951983bf8471f7abb0191f712fa", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2016-03-13T13:36:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-26T03:21:47.000Z", "avg_line_length": 34.65625, "max_line_length": 102, "alphanum_fraction": 0.4428914938, "num_tokens": 2184, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240686758841, "lm_q2_score": 0.7905303137346446, "lm_q1q2_score": 0.6839858544611123}} {"text": "subroutine asm_enum ( n, asm_num )\n!\n!*******************************************************************************\n!\n!! ASM_ENUM returns the number of alternating sign matrices of a given order.\n!\n!\n! Discussion:\n!\n! N ASM_NUM\n!\n! 0 1\n! 1 1\n! 2 2\n! 3 7\n! 4 42\n! 5 429\n! 6 7436\n! 7 218348\n!\n! A direct formula is\n!\n! ASM_NUM ( N ) = product ( 0 <= I <= N-1 ) ( 3 * I + 1 )! / ( N + I )!\n!\n! Modified:\n!\n! 01 January 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the order of the matrices.\n!\n! Output, integer ASM_NUM, the number of alternating sign matrices of\n! order N.\n!\n implicit none\n!\n integer n\n!\n integer a(n+1)\n integer asm_num\n integer b(n+1)\n integer c(n+1)\n integer i\n integer nn\n!\n asm_num = 0\n\n nn = n + 1\n\n if ( n+1 <= 0 ) then\n return\n end if\n!\n! Row 1\n!\n a(1) = 1\n\n if ( n+1 == 1 ) then\n asm_num = a(1)\n return\n end if\n!\n! Row 2\n!\n a(1) = 1\n\n if ( n+1 == 2 ) then\n asm_num = a(1)\n return\n end if\n\n b(1) = 2\n c(1) = 2\n a(2) = 1\n!\n! Row 3 and on.\n!\n do nn = 3, n\n\n b(nn-1) = nn\n do i = nn-2, 2, -1\n b(i) = b(i) + b(i-1)\n end do\n b(1) = 2\n\n c(nn-1) = 2\n do i = nn-2, 2, -1\n c(i) = c(i) + c(i-1)\n end do\n c(1) = nn\n\n a(1) = sum ( a(1:nn-1) )\n do i = 2, nn\n a(i) = a(i-1) * c(i-1) / b(i-1)\n end do\n\n end do\n\n asm_num = sum ( a(1:n) )\n\n return\nend\nsubroutine asm_triangle ( n, a )\n!\n!*******************************************************************************\n!\n!! ASM_TRIANGLE returns a row of the alternating sign matrix triangle.\n!\n!\n! Discussion:\n!\n! The first seven rows of the triangle are as follows:\n!\n! 1 2 3 4 5 6 7\n!\n! 1 1\n! 2 1 1\n! 3 2 3 2\n! 4 7 14 14 7\n! 5 42 105 135 105 42\n! 6 429 1287 2002 2002 1287 429\n! 7 7436 26026 47320 56784 47320 26026 7436\n!\n! For a given N, the value of A(J) represents entry A(I,J) of\n! the triangular matrix, and gives the number of alternating sign matrices\n! of order N in which the (unique) 1 in row 1 occurs in column J.\n!\n! Thus, of alternating sign matrices of order 3, there are\n! 2 with a leading 1 in column 1:\n!\n! 1 0 0 1 0 0\n! 0 1 0 0 0 1\n! 0 0 1 0 1 0\n!\n! 3 with a leading 1 in column 2, and\n!\n! 0 1 0 0 1 0 0 1 0\n! 1 0 0 0 0 1 1-1 1\n! 0 0 1 1 0 0 0 1 0\n!\n! 2 with a leading 1 in column 3:\n!\n! 0 0 1 0 0 1\n! 1 0 0 0 1 0\n! 0 1 0 1 0 0\n!\n! Modified:\n!\n! 01 January 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the desired row.\n!\n! Output, integer A(N), the entries of the row.\n!\n implicit none\n!\n integer n\n!\n integer a(n)\n integer b(n)\n integer c(n)\n integer i\n integer nn\n!\n if ( n <= 0 ) then\n return\n end if\n!\n! Row 1\n!\n a(1) = 1\n\n if ( n == 1 ) then\n return\n end if\n!\n! Row 2\n!\n nn = 2\n b(1) = 2\n c(1) = nn\n\n a(1) = sum ( a(1:nn-1) )\n do i = 2, nn\n a(i) = a(i-1) * c(i-1) / b(i-1)\n end do\n\n if ( n == 2 ) then\n return\n end if\n!\n! Row 3 and on.\n!\n do nn = 3, n\n\n b(nn-1) = nn\n do i = nn-2, 2, -1\n b(i) = b(i) + b(i-1)\n end do\n b(1) = 2\n\n c(nn-1) = 2\n do i = nn-2, 2, -1\n c(i) = c(i) + c(i-1)\n end do\n c(1) = nn\n\n a(1) = sum ( a(1:nn-1) )\n do i = 2, nn\n a(i) = a(i-1) * c(i-1) / b(i-1)\n end do\n\n end do\n\n return\nend\nsubroutine bell ( b, n )\n!\n!*******************************************************************************\n!\n!! BELL returns the Bell numbers from 0 to N.\n!\n!\n! Discussion:\n!\n! The Bell number B(N) is the number of restricted growth functions\n! on N.\n!\n! Note that the Stirling numbers of the second kind, S^m_n, count the\n! number of partitions of N objects into M classes, and so it is\n! true that\n!\n! B(N) = S^1_N + S^2_N + ... + S^N_N.\n!\n! Definition:\n!\n! The Bell number B(N) is defined as the number of partitions (of\n! any size) of a set of N distinguishable objects.\n!\n! A partition of a set is a division of the objects of the set into\n! subsets.\n!\n! Examples:\n!\n! There are 15 partitions of a set of 4 objects:\n!\n! (1234), (123)(4), (124)(3), (12)(34), (12)(3)(4),\n! (134)(2), (13)(24), (13)(2)(4), (14)(23), (1)(234),\n! (1)(23)(4), (14)(2)(3), (1)(24)(3), (1)(2)(34), (1)(2)(3)(4)\n!\n! and so B(4) = 15.\n!\n! First values:\n!\n! N B(N)\n! 0 1\n! 1 1\n! 2 2\n! 3 5\n! 4 15\n! 5 52\n! 6 203\n! 7 877\n! 8 4140\n! 9 21147\n! 10 115975\n!\n! Recursion:\n!\n! B(I) = sum ( 1 <= J <= I ) Binomial ( I-1, J-1 ) * B(I-J)\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Output, integer B(0:N), the Bell numbers from 0 to N.\n!\n! Input, integer N, the number of Bell numbers desired.\n!\n implicit none\n!\n integer n\n!\n integer b(0:n)\n integer combo\n integer i\n integer j\n!\n b(0) = 1\n\n do i = 1, n\n b(i) = 0\n do j = 1, i\n call combin2 ( i-1, j-1, combo )\n b(i) = b(i) + combo * b(i-j)\n end do\n end do\n\n return\nend\nsubroutine catalan ( n, c )\n!\n!*******************************************************************************\n!\n!! CATALAN computes the Catalan numbers, from C(0) to C(N).\n!\n!\n! First values:\n!\n! C(0) 1\n! C(1) 1\n! C(2) 2\n! C(3) 5\n! C(4) 14\n! C(5) 42\n! C(6) 132\n! C(7) 429\n! C(8) 1430\n! C(9) 4862\n! C(10) 16796\n!\n! Formula:\n!\n! C(N) = (2*N)! / ( (N+1) * (N!) * (N!) )\n! = 1 / (N+1) * COMB ( 2N, N )\n! = 1 / (2N+1) * COMB ( 2N+1, N+1).\n!\n! Recursion:\n!\n! C(N) = 2 * (2*N-1) * C(N-1) / (N+1)\n! C(N) = sum ( 1 <= I <= N-1 ) C(I) * C(N-I)\n!\n! Comments:\n!\n! The Catalan number C(N) counts:\n!\n! 1) the number of binary trees on N vertices;\n! 2) the number of ordered trees on N+1 vertices;\n! 3) the number of full binary trees on 2N+1 vertices;\n! 4) the number of well formed sequences of 2N parentheses;\n! 5) number of ways 2N ballots can be counted, in order,\n! with N positive and N negative, so that the running sum\n! is never negative;\n! 6) the number of standard tableaus in a 2 by N rectangular Ferrers diagram;\n! 7) the number of monotone functions from [1..N} to [1..N} which\n! satisfy f(i) <= i for all i;\n! 8) the number of ways to triangulate a polygon with N+2 vertices.\n!\n! Example:\n!\n! N = 3\n!\n! ()()()\n! ()(())\n! (()())\n! (())()\n! ((()))\n!\n! Reference:\n!\n! Dennis Stanton and Dennis White,\n! Constructive Combinatorics,\n! Springer Verlag, New York, 1986.\n!\n! Modified:\n!\n! 14 August 1998\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of Catalan numbers desired.\n!\n! Output, integer C(0:N), the Catalan numbers from C(0) to C(N).\n!\n implicit none\n!\n integer n\n!\n integer c(0:n)\n integer i\n!\n c(0) = 1\n!\n! The extra parentheses ensure that the integer division is\n! done AFTER the integer multiplication.\n!\n do i = 1, n\n c(i) = ( c(i-1) * 2 * ( 2 * i - 1 ) ) / ( i + 1 )\n end do\n\n return\nend\nsubroutine cfrac_to_rat ( a, n, p, q )\n!\n!*******************************************************************************\n!\n!! CFRAC_TO_RAT converts a monic continued fraction to an ordinary fraction.\n!\n!\n! Discussion:\n!\n! The routine is given the monic or \"simple\" continued fraction with\n! integer coefficients:\n!\n! A(1) + 1 / ( A(2) + 1 / ( A(3) ... + 1 / A(N) ) )\n!\n! and returns the N successive approximants P(I)/Q(I)\n! to the value of the rational number represented by the continued\n! fraction, with the value exactly equal to the final ratio P(N)/Q(N).\n!\n! Reference:\n!\n! Hart, Cheney, Lawson, Maehly, Mesztenyi, Rice, Thacher, Witzgall,\n! Computer Approximations,\n! Wiley, 1968.\n!\n! Modified:\n!\n! 01 October 2000\n!\n! Parameters:\n!\n! Input, integer A(N), the continued fraction coefficients.\n!\n! Input, integer N, the number of continued fraction coefficients.\n!\n! Output, integer P(N), Q(N), the N successive approximations\n! to the value of the continued fraction.\n!\n implicit none\n!\n integer n\n!\n integer a(n)\n integer i\n integer p(n)\n integer q(n)\n!\n do i = 1, n\n\n if ( i == 1 ) then\n p(i) = a(i) * 1 + 0\n q(i) = a(i) * 0 + 1\n else if ( i == 2 ) then\n p(i) = a(i) * p(i-1) + 1\n q(i) = a(i) * q(i-1) + 0\n else\n p(i) = a(i) * p(i-1) + p(i-2)\n q(i) = a(i) * q(i-1) + q(i-2)\n end if\n\n end do\n\n return\nend\nsubroutine cfrac_to_rfrac ( g, h, m, p, q )\n!\n!*******************************************************************************\n!\n!! CFRAC_TO_RFRAC converts a polynomial fraction from continued to rational form.\n!\n!\n! Discussion:\n!\n! The routine accepts a continued polynomial fraction:\n!\n! G(1) / ( H(1) +\n! G(2) * X / ( H(2) +\n! G(3) * X / ( H(3) + ...\n! G(M) * X / ( H(M) )...) ) )\n!\n! and returns the equivalent rational polynomial fraction:\n!\n! P(1) + P(2) * X + ... + P(L1) * X**(L1)\n! -------------------------------------------------------\n! Q(1) + Q(2) * X + ... + Q(L2) * X**(L2-1)\n!\n! where\n!\n! L1 = (M+1)/2\n! L2 = (M+2)/2.\n!\n! Reference:\n!\n! Hart, Cheney, Lawson, Maehly, Mesztenyi, Rice, Thacher, Witzgall,\n! Computer Approximations,\n! Wiley, 1968.\n!\n! Modified:\n!\n! 17 April 2000\n!\n! Parameters:\n!\n! Input, real G(M), H(M), the continued polynomial fraction coefficients.\n!\n! Input, integer M, the number of continued fraction polynomial coefficients.\n!\n! Output, real P((M+1)/2), Q((M+2)/2), the rational polynomial fraction\n! coefficients.\n!\n implicit none\n!\n integer m\n!\n real a(m,(m+2)/2)\n real g(m)\n real h(m)\n integer i\n integer j\n real p((m+1)/2)\n real q((m+2)/2)\n!\n if ( m == 1 ) then\n p(1) = g(1)\n q(1) = h(1)\n return\n end if\n\n do i = 1, m\n do j = 1, (m+2)/2\n a(i,j) = 0.0E+00\n end do\n end do\n!\n! Solve for P's\n!\n a(1,1) = g(1)\n a(2,1) = g(1) * h(2)\n\n do i = 3, m\n a(i,1) = h(i) * a(i-1,1)\n do j = 2, (i+1)/2\n a(i,j) = h(i) * a(i-1,j) + g(i) * a(i-2,j-1)\n end do\n end do\n\n do i = 1, (m+1)/2\n p(i) = a(m,i)\n end do\n\n a(1,1) = h(1)\n a(2,1) = h(1) * h(2)\n a(2,2) = g(2)\n\n do i = 3, m\n a(i,1) = h(i) * a(i-1,1)\n do j = 2, (i+2) / 2\n a(i,j) = h(i) * a(i-1,j) + g(i) * a(i-2,j-1)\n end do\n end do\n\n do i = 1, (m+2)/2\n q(i) = a(m,i)\n end do\n\n return\nend\nsubroutine ch_cap ( c )\n!\n!*******************************************************************************\n!\n!! CH_CAP capitalizes a single character.\n!\n!\n! Modified:\n!\n! 19 July 1998\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input/output, character C, the character to capitalize.\n!\n implicit none\n!\n character c\n integer itemp\n!\n itemp = ichar ( c )\n\n if ( 97 <= itemp .and. itemp <= 122 ) then\n c = char ( itemp - 32 )\n end if\n\n return\nend\nsubroutine chinese_check ( n, m, ierror )\n!\n!*******************************************************************************\n!\n!! CHINESE_CHECK checks the Chinese remainder moduluses.\n!\n!\n! Discussion:\n!\n! For a Chinese remainder representation, the moduluses M(I) must\n! be positive and pairwise prime. Also, in case this is not obvious,\n! no more than one of the moduluses may be 1.\n!\n! Modified:\n!\n! 05 July 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of moduluses.\n!\n! Input, integer M(N), the moduluses. These should be positive\n! and pairwise prime.\n!\n! Output, integer IERROR, an error flag.\n! 0, no error was detected.\n! nonzero, an error was detected.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer ierror\n logical ivec_pairwise_prime\n integer j\n integer m(n)\n!\n ierror = 0\n!\n! Do not allow nonpositive entries.\n!\n if ( any ( m(1:n) <= 0 ) ) then\n ierror = 1\n return\n end if\n!\n! Allow one entry to be 1, but not two entries.\n!\n do i = 1, n\n do j = i+1, n\n if ( m(i) == 1 .and. m(j) == 1 ) then\n ierror = 2\n return\n end if\n end do\n end do\n!\n! Now check pairwise primeness.\n!\n if ( .not. ivec_pairwise_prime ( n, m ) ) then\n ierror = 3\n return\n end if\n\n return\nend\nsubroutine chinese_to_i ( n, m, r, j )\n!\n!*******************************************************************************\n!\n!! CHINESE_TO_I converts a set of Chinese remainders to an equivalent integer.\n!\n!\n! Discussion:\n!\n! Given a set of N pairwise prime, positive moduluses M(I), and\n! a corresponding set of remainders M(I), this routine finds an\n! integer J such that, for all I,\n!\n! J = R(I) mod M(I)\n!\n! Modified:\n!\n! 10 July 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of moduluses.\n!\n! Input, integer M(N), the moduluses. These should be positive\n! and pairwise prime.\n!\n! Input, integer R(N), the Chinese remainder representation of the integer.\n!\n! Output, integer J, the corresponding integer.\n!\n implicit none\n!\n integer n\n!\n integer a\n integer b(n)\n integer big_m\n integer c\n integer i\n integer ierror\n integer j\n integer m(n)\n integer r(n)\n!\n call chinese_check ( n, m, ierror )\n\n if ( ierror /= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'CHINESE_TO_I - Fatal error!'\n write ( *, '(a)' ) ' The moduluses are not legal.'\n stop\n end if\n!\n! Set BIG_M.\n!\n big_m = product ( m )\n!\n! Solve BIG_M / M(I) * B(I) = 1, mod M(I)\n!\n do i = 1, n\n a = big_m / m(i)\n c = 1\n call congruence ( a, m(i), c, ierror, b(i) )\n end do\n!\n! Set J = sum ( 1 <= I <= N ) ( R(I) * B(I) * BIG_M / M(I) ) mod M\n!\n j = 0\n do i = 1, n\n j = mod ( j + r(i) * b(i) * ( big_m / m(i) ), big_m )\n end do\n\n return\nend\nsubroutine comb ( m, n, l, iarray )\n!\n!*******************************************************************************\n!\n!! COMB returns the L-th combination of N things out of M.\n!\n!\n! Discussion:\n!\n! The combinations are ordered lexically.\n!\n! Lexical order can be illustrated for the general case of N and M as\n! follows:\n!\n! 1: 1, 2, 3, ..., N-2, N-1, N\n! 2: 1, 2, 3, ..., N-2, N-1, N+1\n! 3: 1, 2, 3, ..., N-2, N-1, N+2\n! ...\n! M-N+1: 1, 2, 3, ..., N-2, N-1, M\n! M-N+2: 1, 2, 3, ..., N-2, N, N+1\n! M-N+3: 1, 2, 3, ..., N-2, N, N+2\n! ...\n! LAST-2: M-N, M-N+1, M-N+3, ..., M-2, M-1, M\n! LAST-1: M-N, M-N+2, M-N+3, ..., M-2, M-1, M\n! LAST: M-N+1, M-N+2, M-N+3, ..., M-2, M-1, M\n!\n! There are a total of M!/(N!*(M-N)!) combinations of M\n! things taken N at a time.\n!\n! Reference:\n!\n! B P Buckles and M Lybanon,\n! Algorithm 515,\n! Generation of a Vector from the Lexicographical Index,\n! ACM Transactions on Mathematical Software,\n! Volume 3, Number 2, pages 180-182, June 1977.\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Input, integer M, the size of the set.\n!\n! Input, integer N, the number of things in the combination.\n! N must be greater than 0, and no greater than M.\n!\n! Input, integer L, the lexicographical index of combination\n! sought. L must be at least 1, and no greater than M!/(N!*(M-N)!).\n!\n! Output, integer IARRAY(N), array containing the combination set.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer iarray(n)\n integer j\n integer k\n integer l\n integer m\n!\n! Initialize lower bound index at zero.\n!\n k = 0\n!\n! Loop to select elements in ascending order.\n!\n do i = 1, n - 1\n!\n! Set lower bound element number for next element value.\n!\n iarray(i) = 0\n\n if ( i /= 1 ) then\n iarray(i) = iarray(i-1)\n end if\n!\n! Check each element value.\n!\n do\n\n iarray(i) = iarray(i) + 1\n call combin2 ( m-iarray(i), n-i, j )\n k = k + j\n\n if ( k >= l ) then\n exit\n end if\n\n end do\n\n k = k - j\n\n end do\n\n iarray(n) = iarray(n-1) + l - k\n\n return\nend\nsubroutine comb_next ( done, n, k, iarray )\n!\n!*******************************************************************************\n!\n!! COMB_NEXT computes combinations of K things out of N.\n!\n!\n! Discussion:\n!\n! The combinations are computed one at a time, in lexicographical order.\n!\n! Reference:\n!\n! Charles Mifsud,\n! Combination in Lexicographic Order,\n! ACM algorithm 154,\n! March 1963.\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Input/output, logical DONE, indicator.\n! On input, if this is the first call, the user should set\n! DONE to FALSE. On each subsequent call, the value of\n! DONE should be left at its output value from the previous\n! call.\n!\n! On output, if DONE is TRUE, then a new combination was\n! computed and returned. If DONE is FALSE, then the list\n! of combinations was finished on the previous call.\n!\n! Input, integer N, the total number of things.\n!\n! Input, integer K, the number of things in each combination.\n!\n! Output, integer IARRAY(K), contains the list of elements in\n! the current combination.\n!\n implicit none\n!\n integer k\n!\n logical done\n integer i\n integer iarray(k)\n integer j\n integer n\n!\n if ( done ) then\n\n call ivec_identity ( k, iarray )\n\n if ( k > 1 ) then\n done = .false.\n else\n done = .true.\n end if\n\n else\n\n if ( iarray(k) < n ) then\n iarray(k) = iarray(k) + 1\n return\n end if\n\n do i = k, 2, -1\n\n if ( iarray(i-1) < n-k+i-1 ) then\n\n iarray(i-1) = iarray(i-1) + 1\n\n do j = i, k\n iarray(j) = iarray(i-1) + j - ( i-1 )\n end do\n\n return\n\n end if\n\n end do\n\n done = .true.\n\n end if\n\n return\nend\nsubroutine comb_row ( ido, n, irow )\n!\n!*******************************************************************************\n!\n!! COMB_ROW computes a row of the combinatorial coefficients.\n!\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer IDO, startup information.\n!\n! 0, build up the table from scratch.\n! 1, N = 0, or IROW contains the previous row of combinatorial coefficients.\n!\n! Input, integer N, the desired row. N must be 0 or greater.\n!\n! Output, integer IROW(N+1), the combinatorial coefficients.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer ido\n integer irow(n+1)\n integer k\n!\n if ( n < 0 ) then\n return\n end if\n\n if ( ido == 1 ) then\n\n do i = n, 2, -1\n irow(i) = irow(i) + irow(i-1)\n end do\n\n irow(n+1) = 1\n\n else\n\n irow(1) = 1\n irow(2:n+1) = 0\n\n do k = 1, n\n do i = k+1, 2, -1\n irow(i) = irow(i) + irow(i-1)\n end do\n end do\n\n end if\n\n return\nend\nsubroutine combin ( n, k, cnk )\n!\n!*******************************************************************************\n!\n!! COMBIN computes the combinatorial coefficient C(N,K).\n!\n!\n! Method:\n!\n! Real arithmetic is used, and C(N,K) is computed directly, via\n! Gamma functions, rather than recursively.\n!\n! Definition:\n!\n! C(N,K) is the number of distinct combinations of K objects\n! chosen from a set of N distinct objects. A combination is\n! like a set, in that order does not matter.\n!\n! Examples:\n!\n! The number of combinations of 2 things chosen from 5 is 10.\n!\n! C(5,2) = ( 5 * 4 * 3 * 2 * 1 ) / ( ( 3 * 2 * 1 ) * ( 2 * 1 ) ) = 10.\n!\n! The actual combinations may be represented as:\n!\n! (1,2), (1,3), (1,4), (1,5), (2,3),\n! (2,4), (2,5), (3,4), (3,5), (4,5).\n!\n! Formula:\n!\n! C(N,K) = N! / ( (N-K)! * K! )\n!\n! Modified:\n!\n! 16 June 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the value of N.\n!\n! Input, integer K, the value of K.\n!\n! Output, real CNK, the value of C(N,K)\n!\n implicit none\n!\n real arg\n real cnk\n real fack\n real facn\n real facnmk\n real gamma_log\n integer k\n integer n\n!\n if ( n < 0 ) then\n\n cnk = 0.0E+00\n\n else if ( k == 0 ) then\n\n cnk = 1.0E+00\n\n else if ( k == 1 ) then\n\n cnk = real ( n )\n\n else if ( k > 1 .and. k < n-1 ) then\n\n arg = real ( n + 1 )\n facn = gamma_log ( arg )\n\n arg = real ( k + 1 )\n fack = gamma_log ( arg )\n\n arg = real ( n - k + 1 )\n facnmk = gamma_log ( arg )\n\n cnk = anint ( exp ( facn - fack - facnmk ) )\n\n else if ( k == n-1 ) then\n\n cnk = real ( n )\n\n else if ( k == n ) then\n\n cnk = 1.0E+00\n\n else\n\n cnk = 0.0E+00\n\n end if\n\n return\nend\nsubroutine combin2 ( n, k, icnk )\n!\n!*******************************************************************************\n!\n!! COMBIN2 computes the binomial coefficient C(N,K).\n!\n!\n! Discussion:\n!\n! The value is calculated in such a way as to avoid overflow and\n! roundoff. The calculation is done in integer arithmetic.\n!\n! Formula:\n!\n! ICNK = C(N,K) = N! / ( K! * (N-K)! )\n!\n! Reference:\n!\n! M L Wolfson and H V Wright,\n! Combinatorial of M Things Taken N at a Time,\n! ACM algorithm 160,\n! Communications of the ACM,\n! April, 1963.\n!\n! Modified:\n!\n! 17 January 1999\n!\n! Parameters:\n!\n! Input, integer N, K, are the values of N and K.\n!\n! Output, integer ICNK, the number of combinations of N\n! things taken K at a time.\n!\n implicit none\n!\n integer i\n integer icnk\n integer k\n integer mn\n integer mx\n integer n\n!\n mn = min ( k, n-k )\n\n if ( mn < 0 ) then\n\n icnk = 0\n\n else if ( mn == 0 ) then\n\n icnk = 1\n\n else\n\n mx = max ( k, n-k )\n icnk = mx + 1\n\n do i = 2, mn\n icnk = ( icnk * ( mx + i ) ) / i\n end do\n\n end if\n\n return\nend\nsubroutine comp_next ( n, k, iarray, more )\n!\n!*******************************************************************************\n!\n!! COMP_NEXT computes the compositions of the integer N into K parts.\n!\n!\n! Discussion:\n!\n! The routine computes one composition on each call until there are no more.\n! For instance, one composition of 6 into 3 parts is\n! 3+2+1, another would be 6+0+0.\n!\n! Example:\n!\n! The 28 compositions of 6 into three parts are:\n!\n! 6 0 0, 5 1 0, 5 0 1, 4 2 0, 4 1 1, 4 0 2,\n! 3 3 0, 3 2 1, 3 1 2, 3 0 3, 2 4 0, 2 3 1,\n! 2 2 2, 2 1 3, 2 0 4, 1 5 0, 1 4 1, 1 3 2,\n! 1 2 3, 1 1 4, 1 0 5, 0 6 0, 0 5 1, 0 4 2,\n! 0 3 3, 0 2 4, 0 1 5, 0 0 6.\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Input, integer N, the integer whose compositions are desired.\n!\n! Input, integer K, the number of parts in the composition.\n!\n! Output, integer IARRAY(K). IARRAY(I) is the I-th part of\n! the composition.\n!\n! Input/output, logical MORE.\n! Set MORE = .FALSE. on first call. It will be reset to .TRUE. on return\n! with a new composition. Each new call returns another composition until\n! MORE is set to .FALSE. when the last composition has been computed\n! and returned.\n!\n implicit none\n!\n integer k\n!\n integer i\n integer iarray(k)\n integer, save :: ih = 0\n integer, save :: it = 0\n logical more\n integer n\n!\n if ( .not. more ) then\n\n it = n\n ih = 0\n iarray(1) = n\n iarray(2:k) = 0\n\n else\n\n if ( it > 1 ) then\n ih = 0\n end if\n\n ih = ih + 1\n it = iarray(ih)\n iarray(ih) = 0\n iarray(1) = it - 1\n iarray(ih+1) = iarray(ih+1) + 1\n\n end if\n\n more = iarray(k) /= n\n\n return\nend\nsubroutine comp_random ( n, k, iarray )\n!\n!*******************************************************************************\n!\n!! COMP_RANDOM selects a random composition of the integer N into K parts.\n!\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Input, integer N, the integer to be decomposed.\n!\n! Input, integer K, the number of parts in the composition.\n!\n! Output, integer IARRAY(K). IARRAY(I) is the I-th part of the\n! composition.\n!\n implicit none\n!\n integer k\n!\n integer i\n integer iarray(k)\n integer l\n integer m\n integer n\n!\n call ksub_random ( n+k-1, k-1, iarray )\n\n iarray(k) = n + k\n l = 0\n\n do i = 1, k\n m = iarray(i)\n iarray(i) = iarray(i) - l - 1\n l = m\n end do\n\n return\nend\nsubroutine congruence ( a, b, c, ierror, x )\n!\n!*******************************************************************************\n!\n!! CONGRUENCE solves a congruence of the form A * X = C mod ( B ).\n!\n!\n! Discussion:\n!\n! A, B and C are given integers. The equation is solvable if and only\n! if the greatest common divisor of A and B also divides C.\n!\n! Reference:\n!\n! Eric Weisstein, editor,\n! CRC Concise Encylopedia of Mathematics,\n! CRC Press, 1998, page 446.\n!\n! Modified:\n!\n! 09 July 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer A, B, C, the coefficients of the Diophantine equation.\n!\n! Output, integer IERROR, error flag.\n! 0, no error, X was computed.\n! 1, A = B = 0, C is nonzero.\n! 2, A = 0, B and C nonzero, but C is not a multiple of B.\n! 3, A nonzero, B zero, C nonzero, but C is not a multiple of A.\n! 4, A, B, C nonzero, but GCD of A and B does not divide C.\n! 5, algorithm ran out of internal space.\n!\n! Output, integer X, the solution of the Diophantine equation.\n! X will be between 0 and B-1.\n!\n implicit none\n!\n integer, parameter :: nmax = 100\n!\n integer a\n integer a_copy\n integer a_mag\n integer a_sign\n integer b\n integer b_copy\n integer b_mag\n integer b_sign\n integer c\n integer c_copy\n integer g\n integer i_gcd\n integer ierror\n integer k\n integer n\n real norm_new\n real norm_old\n integer q(nmax)\n logical swap\n integer temp\n integer x\n integer xnew\n integer y\n integer ynew\n!\n! Defaults for output parameters.\n!\n ierror = 0\n x = 0\n y = 0\n!\n! Special cases.\n!\n if ( a == 0 .and. b == 0 .and. c == 0 ) then\n x = 0\n return\n else if ( a == 0 .and. b == 0 .and. c /= 0 ) then\n ierror = 1\n x = 0\n return\n else if ( a == 0 .and. b /= 0 .and. c == 0 ) then\n x = 0\n return\n else if ( a == 0 .and. b /= 0 .and. c /= 0 ) then\n x = 0\n if ( mod ( c, b ) /= 0 ) then\n ierror = 2\n end if\n return\n else if ( a /= 0 .and. b == 0 .and. c == 0 ) then\n x = 0\n return\n else if ( a /= 0 .and. b == 0 .and. c /= 0 ) then\n x = c / a\n if ( mod ( c, a ) /= 0 ) then\n ierror = 3\n end if\n return\n else if ( a /= 0 .and. b /= 0 .and. c == 0 ) then\n g = i_gcd ( a, b )\n x = b / g\n return\n end if\n!\n! Now handle the \"general\" case: A, B and C are nonzero.\n!\n! Step 1: Compute the GCD of A and B, which must also divide C.\n!\n g = i_gcd ( a, b )\n\n if ( mod ( c, g ) /= 0 ) then\n ierror = 4\n return\n end if\n\n a_copy = a / g\n b_copy = b / g\n c_copy = c / g\n!\n! Step 2: Split A and B into sign and magnitude.\n!\n a_mag = abs ( a_copy )\n a_sign = sign ( 1, a_copy )\n b_mag = abs ( b_copy )\n b_sign = sign ( 1, b_copy )\n!\n! Another special case, A_MAG = 1 or B_MAG = 1.\n!\n if ( a_mag == 1 ) then\n x = a_sign * c_copy\n return\n else if ( b_mag == 1 ) then\n x = 0\n return\n end if\n!\n! Step 3: Produce the Euclidean remainder sequence.\n!\n if ( a_mag >= b_mag ) then\n\n swap = .false.\n q(1) = a_mag\n q(2) = b_mag\n\n else\n\n swap = .true.\n q(1) = b_mag\n q(2) = a_mag\n\n end if\n\n n = 3\n\n do\n\n q(n) = mod ( q(n-2), q(n-1) )\n\n if ( q(n) == 1 ) then\n exit\n end if\n\n n = n + 1\n\n if ( n > nmax ) then\n ierror = 5\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'CONGRUENCE - Fatal error!'\n write ( *, '(a)' ) ' Exceeded number of iterations.'\n stop\n end if\n\n end do\n!\n! Step 4: Now go backwards to solve X * A_MAG + Y * B_MAG = 1.\n!\n y = 0\n do k = n, 2, -1\n x = y\n y = ( 1 - x * q(k-1) ) / q(k)\n end do\n!\n! Step 5: Undo the swapping.\n!\n if ( swap ) then\n call i_swap ( x, y )\n end if\n!\n! Step 6: Now apply signs to X and Y so that X * A + Y * B = 1.\n!\n x = x * a_sign\n!\n! Step 7: Multiply by C, so that X * A + Y * B = C.\n!\n x = x * c_copy\n!\n! Step 8: Now force 0 <= X < B.\n!\n x = mod ( x, b )\n\n return\nend\nsubroutine count_pose ( blocks, goal )\n!\n!*******************************************************************************\n!\n!! COUNT_POSE poses a problem for the game \"The Count is Good\"\n!\n!\n! Discussion:\n!\n! The French television show \"The Count is Good\" has a game that goes\n! as follows:\n!\n! A number is chosen at random between 100 and 999. This is the GOAL.\n!\n! Six numbers are randomly chosen from the set 1, 2, 3, 4, 5, 6, 7, 8,\n! 9, 10, 25, 50, 75, 100. These numbers are the BLOCKS.\n!\n! The player must construct a formula, using some or all of the blocks,\n! (but not more than once), and the operations of addition, subtraction,\n! multiplication and division. Parentheses should be used to remove\n! all ambiguity. However, it is forbidden to use subtraction in a\n! way that produces a negative result, and all division must come out\n! exactly, with no remainder.\n!\n! This routine poses a sample problem from the show. The point is,\n! to determine how to write a program that can solve such a problem.\n!\n! Reference:\n!\n! Raymond Seroul,\n! Programming for Mathematicians,\n! Springer Verlag, 2000, page 355-357.\n!\n! Modified:\n!\n! 24 July 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Output, integer BLOCKS(6), the six numbers available for the formula.\n!\n! Output, integer GOAL, the goal number.\n!\n implicit none\n!\n integer blocks(6)\n integer goal\n integer ind(6)\n integer, dimension ( 14 ) :: stuff = &\n (/ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 25, 50, 75, 100 /)\n!\n call i_random ( 100, 999, goal )\n\n call ksub_random ( 14, 6, ind )\n\n blocks(1:6) = stuff(ind(1:6))\n\n return\nend\nfunction d_pi ( )\n!\n!*******************************************************************************\n!\n!! D_PI returns the value of pi as a double precision quantity.\n!\n!\n! Modified:\n!\n! 19 December 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Output, double precision D_PI, the value of pi.\n!\n implicit none\n!\n double precision d_pi\n!\n d_pi = 3.14159265358979323846264338327950288419716939937510D+00\n\n return\nend\nsubroutine d_to_cfrac ( r, n, a, p, q )\n!\n!*******************************************************************************\n!\n!! D_TO_CFRAC converts a double precision value to a continued fraction.\n!\n!\n! Discussion:\n!\n! The routine is given a real number R. It computes a sequence of\n! continued fraction approximations to R, returning the results as\n! simple fractions of the form P(I) / Q(I).\n!\n! Example:\n!\n! X = 2 * PI\n! N = 7\n!\n! A = [ *, 6, 3, 1, 1, 7, 2, 146, 3 ]\n! P = [ 1, 6, 19, 25, 44, 333, 710, 103993, 312689 ]\n! Q = [ 0, 1, 3, 4, 7, 53, 113, 16551, 49766 ]\n!\n! (This ignores roundoff error, which will cause later terms to differ).\n!\n! Reference:\n!\n! Norman Richert,\n! Strang's Strange Figures,\n! American Mathematical Monthly,\n! Volume 99, Number 2, February 1992, pages 101-107.\n!\n! Modified:\n!\n! 10 June 2002\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, double precision R, the real value.\n!\n! Input, integer N, the number of convergents to compute.\n!\n! Output, integer A(0:N), the partial quotients.\n!\n! Output, integer P(-1:N), Q(-1:N), the numerators and denominators\n! of the continued fraction approximations.\n!\n implicit none\n!\n integer n\n!\n integer a(0:n)\n integer i\n integer p(-1:n)\n integer q(-1:n)\n double precision r\n double precision r_copy\n double precision x(0:n)\n!\n if ( r == 0.0D+00 ) then\n a(0:n) = 0\n p(-1:n) = 0\n q(-1:n) = 1\n return\n end if\n\n r_copy = abs ( r )\n\n p(-1) = 1\n q(-1) = 0\n\n p(0) = int ( r_copy )\n q(0) = 1\n x(0) = r_copy\n a(0) = int ( x(0) )\n\n do i = 1, n\n x(i) = 1.0E+00 / ( x(i-1) - dble ( a(i-1) ) )\n a(i) = int ( x(i) )\n p(i) = a(i) * p(i-1) + p(i-2)\n q(i) = a(i) * q(i-1) + q(i-2)\n end do\n\n if ( r < 0.0D+00 ) then\n p(-1:n) = - p(-1:n)\n end if\n\n return\nend\nsubroutine d_to_dec ( dval, itop, ibot )\n!\n!*******************************************************************************\n!\n!! D_TO_DEC converts a double precision quantity to a decimal representation.\n!\n!\n! Discussion:\n!\n! Given the double precision value DVAL, the routine computes integers\n! ITOP and IBOT so that it is approximately true that:\n!\n! DVAL = ITOP * 10 ** IBOT\n!\n! In particular, only DEC_DIGIT digits of DVAL are used in constructing the\n! representation.\n!\n! Modified:\n!\n! 25 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, double precision DVAL, the value whose decimal representation\n! is desired.\n!\n! Output, integer ITOP, IBOT, the approximate decimal representation of DVAL.\n! ITOP is an integer, strictly between -10**DEC_DIGIT and 10**DEC_DIGIT.\n! IBOT is an integer exponent of 10.\n!\n implicit none\n!\n integer dec_digit\n double precision dtop\n double precision dval\n integer ibot\n integer itop\n real ten1\n real ten2\n!\n! Special cases.\n!\n if ( dval == 0.0D+00 ) then\n itop = 0\n ibot = 0\n return\n end if\n!\n! Factor DVAL = DTOP * 10**IBOT\n!\n dtop = dval\n ibot = 0\n!\n! Get the number of decimal digits.\n!\n dec_digit = 0\n call i_data ( 'GET', 'DEC_DIGIT', dec_digit )\n!\n! Now normalize so that 10**(DEC_DIGIT-1) <= ABS(DTOP) < 10**(DEC_DIGIT)\n!\n ten1 = 10.0E+00**( dec_digit - 1 )\n ten2 = 10.0E+00**dec_digit\n\n do while ( abs ( dtop ) < ten1 )\n dtop = dtop * 10.0D+00\n ibot = ibot - 1\n end do\n\n do while ( abs ( dtop ) >= ten2 )\n dtop = dtop / 10.0D+00\n ibot = ibot + 1\n end do\n!\n! ITOP is the integer part of DTOP, rounded.\n!\n itop = nint ( dtop )\n!\n! Now divide out any factors of ten from ITOP.\n!\n if ( itop /= 0 ) then\n do while ( 10 * ( itop / 10 ) == itop )\n itop = itop / 10\n ibot = ibot + 1\n end do\n end if\n\n return\nend\nsubroutine debruijn ( m, n, string )\n!\n!*******************************************************************************\n!\n!! DEBRUIJN constructs a de Bruijn sequence.\n!\n!\n! Description:\n!\n! Suppose we have an alphabet of M letters, and we are interested in\n! all possible strings of length N. If M = 2 and N = 3, then we are\n! interested in the M**N strings:\n!\n! 000\n! 001\n! 010\n! 011\n! 100\n! 101\n! 110\n! 111\n!\n! Now, instead of making a list like this, we prefer, if possible, to\n! write a string of letters, such that every consecutive sequence of\n! N letters is one of the strings, and every string occurs once, if\n! we allow wraparound.\n!\n! For the above example, a suitable sequence would be the 8 characters:\n!\n! 00011101(00...\n!\n! where we have suggested the wraparound feature by repeating the first\n! two characters at the end.\n!\n! Such a sequence is called a de Bruijn sequence. It can easily be\n! constructed by considering a directed graph, whose nodes are all\n! M**(N-1) strings of length N-1. A node I has a directed edge to\n! node J (labeled with character K) if the string at node J can\n! be constructed by beheading the string at node I and adding character K.\n!\n! In this setting, a de Bruijn sequence is simply an Eulerian circuit\n! of the directed graph, with the edge labels being the entries of the\n! sequence. In general, there are many distinct de Bruijn sequences\n! for the same parameter M and N. This program will only find one\n! of them.\n!\n! Modified:\n!\n! 06 July 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer M, the number of letters in the alphabet.\n!\n! Input, integer N, the number of letters in a codeword.\n!\n! Output, integer STRING(M**N), a deBruijn string.\n!\n implicit none\n!\n integer m\n integer n\n!\n integer i\n integer iedge\n integer inode(m**n)\n integer ivec(n-1)\n integer j\n integer jnode(m**n)\n integer jvec(n-1)\n integer k\n integer knode(m**n)\n integer nedge\n integer nnode\n logical success\n integer string(m**n)\n integer trail(m**n)\n!\n! Construct the adjacency information.\n!\n nnode = m**(n-1)\n nedge = m**n\n\n iedge = 0\n\n do i = 1, nnode\n\n call index_unrank0 ( n-1, m, i, ivec )\n\n do k = 1, m\n jvec(1:n-2) = ivec(2:n-1)\n jvec(n-1) = k\n call index_rank0 ( n-1, m, jvec, j )\n iedge = iedge + 1\n inode(iedge) = i\n jnode(iedge) = j\n knode(iedge) = k\n end do\n\n end do\n!\n! Determine a circuit.\n!\n call digraph_arc_euler ( nnode, nedge, inode, jnode, success, trail )\n!\n! The string is constructed from the labels of the edges in the circuit.\n!\n string(1:nedge) = knode(trail(1:nedge))\n\n return\nend\nsubroutine dec_add ( itop1, ibot1, itop2, ibot2, itop, ibot )\n!\n!*******************************************************************************\n!\n!! DEC_ADD adds two decimal quantities.\n!\n!\n! Discussion:\n!\n! The routine computes\n!\n! ITOP * 10**IBOT = ITOP1 * 10**IBOT1 + ITOP2 * 10**IBOT2\n!\n! while trying to avoid integer overflow.\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ITOP1, IBOT1, the first number to be added.\n!\n! Input, integer ITOP2, IBOT2, the second number to be added.\n!\n! Output, integer ITOP, IBOT, the sum.\n!\n implicit none\n!\n integer ibot\n integer ibot1\n integer ibot2\n integer itop\n integer itop1\n integer itop2\n integer jtop1\n integer jtop2\n!\n if ( itop1 == 0 ) then\n itop = itop2\n ibot = ibot2\n return\n else if ( itop2 == 0 ) then\n itop = itop1\n ibot = ibot1\n return\n else if ( ibot1 == ibot2 ) then\n itop = itop1 + itop2\n ibot = ibot1\n call dec_round ( itop, ibot )\n return\n end if\n!\n! Line up the exponents.\n!\n jtop1 = itop1\n jtop2 = itop2\n\n if ( ibot1 < ibot2 ) then\n jtop2 = jtop2 * 10**( ibot2 - ibot1 )\n else\n jtop1 = jtop1 * 10**( ibot1 - ibot2 )\n end if\n!\n! Add the coefficients.\n!\n itop = jtop1 + jtop2\n ibot = min ( ibot1, ibot2 )\n!\n! Clean up the result.\n!\n call dec_round ( itop, ibot )\n\n return\nend\nsubroutine dec_div ( itop1, ibot1, itop2, ibot2, itop, ibot, ierror )\n!\n!*******************************************************************************\n!\n!! DEC_DIV divides two decimal values.\n!\n!\n! Discussion:\n!\n! A decimal quantity is stored as\n!\n! (ITOP,IBOT)\n!\n! representing the value\n!\n! ITOP * 10 ** IBOT.\n!\n! The routine computes\n!\n! ITOP * 10**IBOT = (ITOP1 * 10**IBOT1) / (ITOP2 * 10**IBOT2)\n!\n! = (ITOP1/ITOP2) * 10**(IBOT1-IBOT2)\n!\n! while avoiding integer overflow.\n!\n! Modified:\n!\n! 23 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ITOP1, IBOT1, the numerator.\n!\n! Input, integer ITOP2, IBOT2, the denominator.\n!\n! Output, integer ITOP, IBOT, the result.\n!\n! Output, integer IERROR.\n! 0, no error occurred.\n! 1, an error occurred.\n!\n implicit none\n!\n double precision dval\n integer ibot\n integer ibot1\n integer ibot2\n integer ibot3\n integer ierror\n integer itop\n integer itop1\n integer itop2\n integer itop3\n!\n! First special case, top fraction is 0.\n!\n if ( itop1 == 0 ) then\n itop = 0\n ibot = 0\n return\n end if\n!\n! First error, bottom of fraction is 0.\n!\n if ( itop2 == 0 ) then\n ierror = 1\n itop = 0\n ibot = 0\n return\n end if\n!\n! Second special case, result is 1.\n!\n if ( itop1 == itop2 .and. ibot1 == ibot2 ) then\n itop = 1\n ibot = 0\n return\n end if\n!\n! Third special case, result is power of 10.\n!\n if ( itop1 == itop2 ) then\n itop = 1\n ibot = ibot1 - ibot2\n return\n end if\n!\n! Fourth special case: ITOP1/ITOP2 is exact.\n!\n if ( ( itop1 / itop2 ) * itop2 == itop1 ) then\n itop = itop1 / itop2\n ibot = ibot1 - ibot2\n return\n end if\n!\n! General case.\n!\n dval = dble ( itop1 ) / dble ( itop2 )\n\n call d_to_dec ( dval, itop3, ibot3 )\n\n itop = itop3\n ibot = ibot3 + ibot1 - ibot2\n\n return\nend\nsubroutine dec_mul ( itop1, ibot1, itop2, ibot2, itop, ibot )\n!\n!*******************************************************************************\n!\n!! DEC_MUL multiplies two decimals.\n!\n!\n! Discussion:\n!\n! The routine computes\n!\n! ITOP * 10**IBOT = (ITOP1 * 10**IBOT1) * (ITOP2 * 10**IBOT2)\n! = (ITOP1*ITOP2) * 10**(IBOT1+IBOT2)\n!\n! while avoiding integer overflow.\n!\n! Modified:\n!\n! 25 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ITOP1, IBOT1, the first multiplier.\n!\n! Input, integer ITOP2, IBOT2, the second multiplier.\n!\n! Output, integer ITOP, IBOT, the product.\n!\n implicit none\n!\n double precision dval\n integer i_max\n integer ibot\n integer ibot1\n integer ibot2\n integer ibot3\n integer itop\n integer itop1\n integer itop2\n integer itop3\n real temp\n!\n i_max = huge ( i_max )\n!\n! The result is zero if either ITOP1 or ITOP2 is zero.\n!\n if ( itop1 == 0 .or. itop2 == 0 ) then\n itop = 0\n ibot = 0\n return\n end if\n!\n! The result is simple if either ITOP1 or ITOP2 is one.\n!\n if ( abs ( itop1 ) == 1 .or. abs ( itop2 ) == 1 ) then\n itop = itop1 * itop2\n ibot = ibot1 + ibot2\n return\n end if\n\n temp = log ( real ( abs ( itop1 ) ) ) + log ( real ( abs ( itop2 ) ) )\n\n if ( temp < log ( real ( i_max ) ) ) then\n\n itop = itop1 * itop2\n ibot = ibot1 + ibot2\n\n else\n\n dval = dble ( itop1 ) * dble ( itop2 )\n\n call d_to_dec ( dval, itop3, ibot3 )\n\n itop = itop3\n ibot = ibot3 + ( ibot1 + ibot2 )\n\n end if\n\n call dec_round ( itop, ibot )\n\n return\nend\nsubroutine dec_round ( itop, ibot )\n!\n!*******************************************************************************\n!\n!! DEC_ROUND rounds a decimal fraction to a given number of digits.\n!\n!\n! Discussion:\n!\n! The routine takes an arbitrary decimal fraction represented by\n!\n! ITOP * 10**IBOT\n!\n! and makes sure that ITOP has no more than DEC_DIGIT digits.\n! DEC_DIGIT can be set or reported by calling I_DATA.\n!\n! Modified:\n!\n! 25 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input/output, integer ITOP, IBOT, the coefficient and exponent\n! of a decimal fraction. On return, ITOP has no more than\n! DEC_DIGIT decimal digits.\n!\n implicit none\n!\n integer dec_digit\n integer ibot\n integer itop\n!\n if ( itop == 0 ) then\n ibot = 0\n return\n end if\n\n dec_digit = 0\n call i_data ( 'GET', 'DEC_DIGIT', dec_digit )\n\n do while ( abs ( itop ) >= 10**dec_digit )\n itop = nint ( real ( itop ) / 10.0E+00 )\n ibot = ibot + 1\n end do\n!\n! Absorb trailing 0's into the exponent.\n!\n do while ( ( itop / 10 ) * 10 == itop )\n itop = itop / 10\n ibot = ibot + 1\n end do\n\n return\nend\nsubroutine dec_to_r ( a, itop, ibot )\n!\n!*****************************************************************************\n!\n!! DEC_TO_R converts a decimal ITOP * 10**IBOT to a real value.\n!\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Output, real A, the equivalent real value.\n!\n! Input, integer ITOP, IBOT, the coefficient and exponent\n! of the decimal value.\n!\n implicit none\n!\n real a\n integer ibot\n integer itop\n!\n a = itop * 10.0E+00**ibot\n\n return\nend\nsubroutine dec_to_rat ( iatop, iabot )\n!\n!*******************************************************************************\n!\n!! DEC_TO_RAT converts a decimal to a rational representation.\n!\n!\n! Discussion:\n!\n! On input, a value is represented as IATOP * 10**IABOT.\n!\n! On output, approximately the same value is represented as IATOP / IABOT.\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input/output, integer IATOP, IABOT.\n! On input, these quantities represent the value IATOP * 10 ** IABOT.\n! On output, these quantities represent the value IATOP / IABOT.\n!\n integer iabot\n integer iatop\n integer i_gcd\n integer itmp\n!\n if ( iabot >= 0 ) then\n iatop = iatop * 10**iabot\n iabot = 1\n else\n iabot = 10**( - iabot )\n itmp = i_gcd ( iatop, iabot )\n iatop = iatop / itmp\n iabot = iabot / itmp\n end if\n\n return\nend\nsubroutine dec_to_s_left ( ival, jval, s )\n!\n!*******************************************************************************\n!\n!! DEC_TO_S_LEFT returns a left-justified representation of IVAL * 10**JVAL.\n!\n!\n! Examples:\n!\n! IVAL JVAL S\n! ---- ---- ------\n! 0 0 0\n! 21 3 21000\n! -3 0 -3\n! 147 -2 14.7\n! 16 -5 0.00016\n! 34 30 Inf\n! 123 -21 0.0000000000000000012\n! 34 -30 0.0\n!\n! Modified:\n!\n! 13 September 1998\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer IVAL, JVAL, integers which represent the decimal.\n!\n! Output, character ( len = * ) S, the representation of the value.\n! The string is 'Inf' or '0.0' if the value was too large\n! or small to represent with a fixed point format.\n!\n implicit none\n!\n character ( len = 22 ) chrrep\n integer i\n integer iget1\n integer iget2\n integer iput1\n integer iput2\n integer ival\n integer jval\n integer maxdigit\n integer ndigit\n integer nleft\n character ( len = * ) s\n!\n s = ' '\n\n if ( ival == 0 ) then\n s = '0'\n return\n end if\n\n maxdigit = len ( s )\n!\n! Store a representation of IVAL in CHRREP.\n!\n write ( chrrep, '(i22)' ) ival\n call s_blank_delete ( chrrep )\n ndigit = len_trim ( chrrep )\n!\n! Overflow if JVAL is positive, and NDIGIT + JVAL > MAXDIGIT.\n!\n if ( jval > 0 ) then\n if ( ndigit + jval > maxdigit ) then\n s = 'Inf'\n return\n end if\n end if\n!\n! Underflow if JVAL is negative, and 3 + NDIGIT - JVAL > MAXDIGIT.\n!\n if ( jval < 0 ) then\n if ( ival > 0 ) then\n if ( 3 - ndigit - jval > maxdigit ) then\n s = '0.0'\n return\n end if\n else\n if ( 5 - ndigit - jval > maxdigit ) then\n s = '0.0'\n return\n end if\n end if\n end if\n!\n! If JVAL is nonnegative, insert trailing zeros.\n!\n if ( jval >= 0 ) then\n\n s(1:ndigit) = chrrep(1:ndigit)\n\n do i = ndigit+1, ndigit+jval\n s(i:i) = '0'\n end do\n\n else if ( jval < 0 ) then\n\n iput2 = 0\n iget2 = 0\n!\n! Sign.\n!\n if ( ival < 0 ) then\n iput1 = 1\n iput2 = 1\n iget2 = 1\n s(iput1:iput2) = '-'\n ndigit = ndigit - 1\n end if\n!\n! Digits of the integral part.\n!\n if ( ndigit + jval > 0 ) then\n iput1 = iput2 + 1\n iput2 = iput1 + ndigit + jval -1\n iget1 = iget2 + 1\n iget2 = iget1 + ndigit+jval - 1\n s(iput1:iput2) = chrrep(iget1:iget2)\n else\n iput1 = iput2 + 1\n iput2 = iput1\n s(iput1:iput2) = '0'\n end if\n!\n! Decimal point.\n!\n iput1 = iput2 + 1\n iput2 = iput1\n s(iput1:iput2) = '.'\n!\n! Leading zeroes.\n!\n do i = 1, - jval - ndigit\n iput1 = iput2 + 1\n iput2 = iput1\n s(iput1:iput2) = '0'\n end do\n\n nleft = min ( -jval, ndigit )\n nleft = min ( nleft, maxdigit - iput2 )\n iput1 = iput2 + 1\n iput2 = iput1 + nleft - 1\n iget1 = iget2 + 1\n iget2 = iget1 + nleft - 1\n s(iput1:iput2) = chrrep(iget1:iget2)\n\n end if\n\n return\nend\nsubroutine decmat_det ( n, iatop, iabot, idtop, idbot, ierror )\n!\n!*******************************************************************************\n!\n!! DECMAT_DET finds the determinant of an N by N matrix of decimal entries.\n!\n!\n! Warning:\n!\n! The brute force method is used. The routine should only be used for\n! small matrices, since this calculation requires the summation of N!\n! products of N numbers.\n!\n! Modified:\n!\n! 17 April 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of rows and columns of A.\n!\n! Input, integer IATOP(N,N), IABOT(N,N), the decimal\n! representation of the matrix.\n!\n! Output, integer IDTOP, IDBOT, the decimal determinant of the matrix.\n!\n! Output, integer IERROR.\n! 0, no error occurred.\n! 1, an error occurred (probably overflow).\n!\n implicit none\n!\n integer n\n!\n logical even\n integer i\n integer iabot(n,n)\n integer iatop(n,n)\n integer iarray(n)\n integer ibot\n integer ibot1\n integer ibot2\n integer idbot\n integer idtop\n integer ierror\n integer itop\n integer itop1\n integer itop2\n logical more\n!\n ierror = 0\n more = .false.\n idtop = 0\n idbot = 1\n!\n! Compute the next permutation.\n!\n do\n\n call perm_next ( n, iarray, more, even )\n!\n! The sign of this term depends on the sign of the permutation.\n!\n if ( even ) then\n itop = 1\n else\n itop = - 1\n end if\n!\n! Choose one item from each row, as specified by the permutation,\n! and multiply them\n!\n ibot = 0\n\n do i = 1, n\n\n itop1 = itop\n ibot1 = ibot\n itop2 = iatop(i,iarray(i))\n ibot2 = iabot(i,iarray(i))\n\n call dec_mul ( itop1, ibot1, itop2, ibot2, itop, ibot )\n\n end do\n!\n! Add this term to the total.\n!\n itop1 = itop\n ibot1 = ibot\n\n itop2 = idtop\n ibot2 = idbot\n\n call dec_add ( itop1, ibot1, itop2, ibot2, itop, ibot )\n\n idtop = itop\n idbot = ibot\n\n if ( .not. more ) then\n exit\n end if\n\n end do\n\n return\nend\nsubroutine decmat_print ( m, n, a, b, title )\n!\n!*******************************************************************************\n!\n!! DECMAT_PRINT prints out decimal vectors and matrices.\n!\n!\n! Modified:\n!\n! 12 July 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer M, N, the number of rows and columns in the matrix.\n!\n! Input, integer A(M,N), B(M,N), the decimal matrix.\n!\n! Input, character ( len = * ) TITLE, a label for the object being printed.\n!\n implicit none\n!\n integer m\n integer n\n!\n integer a(m,n)\n integer b(m,n)\n character ( len = 22 ) chrtmp\n character ( len = 10 ) chrtmp1\n character ( len = 10 ) chrtmp2\n character ( len = 10 ) chrtmp3\n character ( len = 40 ) format2\n integer i\n integer ichi\n integer iclo\n integer imax\n integer imin\n integer izhi\n integer izlo\n integer j\n integer jmax\n integer jmin\n integer khi\n integer klo\n integer kmax\n integer lenc\n integer, parameter :: ncolum = 80\n integer npline\n character ( len = 100 ) output\n character ( len = * ) title\n!\n! Figure out how wide we must make each column.\n!\n imax = 0\n jmax = 0\n\n do i = 1, m\n do j = 1, n\n\n call dec_to_s_left ( a(i,j), b(i,j), chrtmp )\n lenc = len_trim ( chrtmp )\n jmax = max ( jmax, lenc )\n\n end do\n end do\n\n kmax = 2 + imax + 1 + jmax\n npline = ncolum / kmax\n!\n! Set up the format for the heading.\n!\n call i_to_s_left ( npline, chrtmp2 )\n call i_to_s_left ( kmax, chrtmp3 )\n format2 = '(' // chrtmp2 // 'i' // chrtmp3 // ')'\n\n call s_blank_delete ( format2 )\n\n do jmin = 1, n, npline\n\n jmax = min ( jmin+npline-1, n )\n\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) trim ( title )\n write ( *, '(a)' ) ' '\n\n if ( jmin > 1 .or. jmax < n ) then\n write ( output, * ) 'Columns ', jmin, ' to ', jmax\n call s_blanks_delete ( output )\n write ( *, '(a)' ) trim ( output )\n write ( *, '(a)' ) ' '\n end if\n\n do i = 1, m\n\n output = ' '\n\n do j = jmin, jmax\n klo = 4 + (j-jmin) * kmax + 1\n khi = 4 + (j-jmin) * kmax + kmax\n call dec_to_s_left ( a(i,j), b(i,j), chrtmp )\n output(klo:khi) = adjustr ( chrtmp(1:kmax) )\n end do\n\n write ( *, '(a)' ) trim ( output )\n\n end do\n\n end do\n\n return\nend\nsubroutine derange_back_candidate ( n, iarray, k, nstack, stack, ncan )\n!\n!*******************************************************************************\n!\n!! DERANGE_BACK_CANDIDATE finds possible values for the K-th entry of a derangement.\n!\n!\n! Modified:\n!\n! 10 August 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the order of the derangement.\n!\n! Input, integer IARRAY(N). The first K-1 entries of IARRAY\n! record the currently set values of the derangement.\n!\n! Input, integer K, the entry of the derangement for which candidates\n! are to be found.\n!\n! Input/output, integer NSTACK, the length of the stack.\n!\n! Input/output, integer STACK((N*(N+1))/2). On output, we have added\n! the candidates for entry K to the end of the stack.\n!\n! Input/output, integer NCAN(N), the number of candidates for each level.\n!\n implicit none\n!\n integer n\n!\n integer iarray(n)\n integer ican\n integer ifree(n)\n integer k\n integer ncan(n)\n integer nfree\n integer nstack\n integer stack((n*(n+1)/2))\n!\n! Consider all the integers from 1 through N that have not been used yet.\n!\n nfree = n - k + 1\n\n call perm_free ( iarray, k-1, ifree, nfree )\n!\n! Everything but K is a legitimate candidate for the K-th entry.\n!\n ncan(k) = 0\n\n do ican = 1, nfree\n\n if ( ifree(ican) /= k ) then\n ncan(k) = ncan(k) + 1\n nstack = nstack + 1\n stack(nstack) = ifree(ican)\n end if\n\n end do\n\n return\nend\nsubroutine derange_back_next ( n, iarray, more )\n!\n!*******************************************************************************\n!\n!! DERANGE_BACK_NEXT returns the next derangement of N items.\n!\n!\n! Discussion:\n!\n! This routine uses backtracking.\n!\n! Modified:\n!\n! 26 November 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of items to be deranged.\n!\n! Input/output, integer IARRAY(N).\n! On the first call, the input value of IARRAY is not important.\n! On return with MORE = .TRUE., IARRAY contains the next derangement.\n! On subsequent input, IARRAY should not be changed.\n!\n! Input/output, logical MORE.\n! On first call, set MORE to .FALSE, and do not alter it after.\n! On return, MORE is TRUE if another derangement was found, and FALSE\n! if there are no more.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer iarray(n)\n integer, save :: indx = 0\n integer, save :: k = 0\n integer, save :: maxstack = 0\n logical more\n integer, save, allocatable, dimension (:) :: ncan\n integer, save :: nstack = 0\n integer, save, allocatable, dimension (:) :: stack\n!\n if ( .not. more ) then\n\n indx = 0\n k = 0\n maxstack = ( n * ( n + 1 ) ) / 2\n nstack = 0\n\n if ( allocated ( stack ) ) then\n deallocate ( stack )\n end if\n\n allocate ( stack(1:(n*(n+1))/2) )\n stack(1:maxstack) = 0\n\n if ( allocated ( ncan ) ) then\n deallocate ( ncan )\n end if\n\n allocate ( ncan(1:n) )\n ncan(1:n) = 0\n\n more = .true.\n\n end if\n\n do\n\n call ivec_backtrack ( n, iarray, indx, k, nstack, stack, maxstack, ncan )\n\n if ( indx == 1 ) then\n\n exit\n\n else if ( indx == 2 ) then\n\n call derange_back_candidate ( n, iarray, k, nstack, stack, ncan )\n\n else\n\n more = .false.\n exit\n\n end if\n\n end do\n\n return\nend\nsubroutine derange_check ( n, iarray, deranged )\n!\n!*******************************************************************************\n!\n!! DERANGE_CHECK determines whether a permutation is a derangement.\n!\n!\n! Definition:\n!\n! A derangement of the integers 1 through N is a permutation of the\n! integers such that the first value is not 1, the second is not 2,\n! and so on.\n!\n! Modified:\n!\n! 22 September 1998\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of objects permuted.\n!\n! Input, integer IARRAY(N), a permutation of the integers 1 through N.\n!\n! Output, logical DERANGED, is TRUE if IARRAY is a derangement, and\n! FALSE otherwise.\n!\n implicit none\n!\n integer n\n!\n logical deranged\n integer i\n integer iarray(n)\n!\n do i = 1, n\n if ( iarray(i) == i ) then\n deranged = .false.\n return\n end if\n end do\n\n deranged = .true.\n\n return\nend\nfunction derange_enum ( n )\n!\n!*******************************************************************************\n!\n!! DERANGE_ENUM returns the number of derangements of N objects.\n!\n!\n! Definition:\n!\n! A derangement of N objects is a permutation with no fixed\n! points. If we symbolize the permutation operation by \"P\",\n! then for a derangment, P(I) is never equal to I.\n!\n! Recursion:\n!\n! D(0) = 1\n! D(1) = 0\n! D(2) = 1\n! D(N) = (N-1) * ( D(N-1) + D(N-2) )\n!\n! or\n!\n! D(0) = 1\n! D(1) = 0\n! D(N) = N * D(N-1) + (-1)**N\n!\n! Formula:\n!\n! D(N) = N! * ( 1 - 1/1! + 1/2! - 1/3! ... 1/N! )\n!\n! Based on the inclusion/exclusion law.\n!\n! Comments:\n!\n! D(N) is the number of ways of placing N non-attacking rooks on\n! an N by N chessboard with one diagonal deleted.\n!\n! Limit ( N -> Infinity ) D(N)/N! = 1 / e.\n!\n! The number of permutations with exactly K items in the right\n! place is COMB(N,K) * D(N-K).\n!\n! First values:\n!\n! N D(N)\n! 0 1\n! 1 0\n! 2 1\n! 3 2\n! 4 9\n! 5 44\n! 6 265\n! 7 1854\n! 8 14833\n! 9 133496\n! 10 1334961\n!\n! Modified:\n!\n! 01 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of objects to be permuted.\n!\n! Output, integer DERANGE_ENUM, the number of derangements of N objects.\n!\n implicit none\n!\n integer derange_enum\n integer dn\n integer dnm1\n integer dnm2\n integer i\n integer n\n!\n if ( n < 0 ) then\n\n dn = 0\n\n else if ( n == 0 ) then\n\n dn = 1\n\n else if ( n == 1 ) then\n\n dn = 0\n\n else if ( n == 2 ) then\n\n dn = 1\n\n else\n\n dnm1 = 0\n dn = 1\n\n do i = 3, n\n dnm2 = dnm1\n dnm1 = dn\n dn = ( i - 1 ) * ( dnm1 + dnm2 )\n end do\n\n end if\n\n derange_enum = dn\n\n return\nend\nsubroutine derange_enum2 ( n, d )\n!\n!*******************************************************************************\n!\n!! DERANGE_ENUM2 returns the number of derangements of 0 through N objects.\n!\n!\n! Definition:\n!\n! A derangement of N objects is a permutation with no fixed\n! points. If we symbolize the permutation operation by \"P\",\n! then for a derangment, P(I) is never equal to I.\n!\n! Recursion:\n!\n! D(0) = 1\n! D(1) = 0\n! D(2) = 1\n! D(N) = (N-1) * ( D(N-1) + D(N-2) )\n!\n! or\n!\n! D(0) = 1\n! D(1) = 0\n! D(N) = N * D(N-1) + (-1)**N\n!\n! Formula:\n!\n! D(N) = N! * ( 1 - 1/1! + 1/2! - 1/3! ... 1/N! )\n!\n! Based on the inclusion/exclusion law.\n!\n! Comments:\n!\n! D(N) is the number of ways of placing N non-attacking rooks on\n! an N by N chessboard with one diagonal deleted.\n!\n! Limit ( N -> Infinity ) D(N)/N! = 1 / e.\n!\n! The number of permutations with exactly K items in the right\n! place is COMB(N,K) * D(N-K).\n!\n! First values:\n!\n! N D(N)\n! 0 1\n! 1 0\n! 2 1\n! 3 2\n! 4 9\n! 5 44\n! 6 265\n! 7 1854\n! 8 14833\n! 9 133496\n! 10 1334961\n!\n! Modified:\n!\n! 28 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the maximum number of objects to be permuted.\n!\n! Output, integer D(0:N); D(I) is the number of derangements of\n! I objects.\n!\n implicit none\n!\n integer n\n!\n integer d(0:n)\n integer i\n!\n d(0) = 1\n d(1) = 0\n\n do i = 2, n\n d(i) = ( i - 1 ) * ( d(i-1) + d(i-2) )\n end do\n\n return\nend\nsubroutine derange_weed_next ( n, iarray, more )\n!\n!*******************************************************************************\n!\n!! DERANGE_WEED_NEXT computes all of the derangements of N objects, one at a time.\n!\n!\n! Definition:\n!\n! A derangement of the integers 1 through N is a permutation of the\n! integers such that the first value is not 1, the second is not 2,\n! and so on.\n!\n! Discussion:\n!\n! This routine simply generates all permutations, one at a time,\n! and weeds out those that are not derangements.\n!\n! Examples:\n!\n! Here are the derangements when N = 4:\n!\n! 2143 3142 4123\n! 2341 3412 4312\n! 2413 3421 4321\n!\n! Modified:\n!\n! 18 July 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of objects being permuted.\n!\n! Input/output, integer IARRAY(N).\n!\n! On first call, the input contents of IARRAY are unimportant. But\n! on the second and later calls, the input value of IARRAY should be\n! the output value returned on the previous call.\n!\n! On output, IARRAY contains the next derangement.\n!\n! Input/output, logical MORE.\n!\n! Set MORE = .FALSE. before the first call.\n!\n! MORE will be reset to .TRUE. and a derangement will be returned.\n!\n! Each new call produces a new derangement until MORE is returned .FALSE.\n!\n implicit none\n!\n integer n\n!\n logical deranged\n integer derange_enum\n integer iarray(n)\n integer, save :: maxder = 0\n logical more\n integer, save :: numder = 0\n!\n! Initialization on call with MORE = .FALSE.\n!\n if ( .not. more ) then\n\n maxder = derange_enum ( n )\n numder = 0\n\n end if\n!\n! Watch out for cases where there are no derangements.\n!\n if ( maxder == 0 ) then\n more = .false.\n return\n end if\n!\n! Get the next permutation.\n!\n do\n\n call perm_lex ( n, iarray, more )\n!\n! See if it is a derangment.\n!\n call derange_check ( n, iarray, deranged )\n\n if ( deranged ) then\n exit\n end if\n\n end do\n\n numder = numder + 1\n\n if ( numder >= maxder ) then\n more = .false.\n end if\n\n return\nend\nsubroutine digit_to_ch ( digit, c )\n!\n!*******************************************************************************\n!\n!! DIGIT_TO_CH returns the character representation of a decimal digit.\n!\n!\n! Example:\n!\n! DIGIT C\n! ----- ---\n! 0 '0'\n! 1 '1'\n! ... ...\n! 9 '9'\n! 17 '*'\n!\n! Modified:\n!\n! 04 August 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer DIGIT, the digit value between 0 and 9.\n!\n! Output, character C, the corresponding character, or '*' if DIGIT\n! was illegal.\n!\n implicit none\n!\n character c\n integer digit\n!\n if ( 0 <= digit .and. digit <= 9 ) then\n\n c = char ( digit + 48 )\n\n else\n\n c = '*'\n\n end if\n\n return\nend\nsubroutine digraph_arc_euler ( nnode, nedge, inode, jnode, success, trail )\n!\n!*******************************************************************************\n!\n!! DIGRAPH_ARC_EULER returns an Euler circuit in a digraph.\n!\n!\n! Description:\n!\n! An Euler circuit of a digraph is a path which starts and ends at\n! the same node and uses each directed edge exactly once. A digraph is\n! eulerian if it has an Euler circuit. The problem is to decide whether\n! a given digraph is eulerian and to find an Euler circuit if the\n! answer is affirmative.\n!\n! Method:\n!\n! A digraph has an Euler circuit if and only if the number of incoming\n! edges is equal to the number of outgoing edges at each node.\n!\n! This characterization gives a straightforward procedure to decide whether\n! a digraph is eulerian. Furthermore, an Euler circuit in an eulerian digraph\n! G of NEDGE edges can be determined by the following method:\n!\n! STEP 1: Choose any node U as the starting node, and traverse any edge\n! ( U, V ) incident to node U, and than traverse any unused edge incident\n! to node U. Repeat this process of traversing unused edges until the\n! starting node U is reached. Let P be the resulting walk consisting of\n! all used edges. If all edges of G are in P, than stop.\n!\n! STEP 2: Choose any unused edge ( X, Y) in G such that X is\n! in P and Y is not in P. Use node X as the starting node and\n! find another walk Q using all unused edges as in step 1.\n!\n! STEP 3: Walk P and walk Q share a common node X, they can be merged\n! to form a walk R by starting at any node S of P and to traverse P\n! until node X is reached; than, detour and traverse all edges of Q\n! until node X is reached and continue to traverse the edges of P until\n! the starting node S is reached. Set P = R.\n!\n! STEP 4: Repeat steps 2 and 3 until all edges are used.\n!\n! The running time of the algorithm is O ( NEDGE ).\n!\n! Note:\n!\n! The digraph is assumed to be connected.\n!\n! Reference:\n!\n! Hang Tong Lau,\n! Algorithms on Graphs,\n! Tab Books, 1989.\n!\n! Modified:\n!\n! 25 July 2000\n!\n! Parameters:\n!\n! Input, integer NNODE, the number of nodes.\n!\n! Input, integer NEDGE, the number of edges.\n!\n! Input, integer INODE(NEDGE), JNODE(NEDGE); the I-th edge starts at node\n! INODE(I) and ends at node JNODE(I).\n!\n! Output, logical SUCCESS, is TRUE if an Euler circuit was found,\n! and FALSE otherwise.\n!\n! Output, integer TRAIL(NEDGE). TRAIL(I) is the edge number of the I-th\n! edge in the Euler circuit.\n!\n implicit none\n!\n integer nedge\n!\n logical candid(nedge)\n integer endnod(nedge)\n integer i\n integer inode(nedge)\n integer istak\n integer j\n integer jnode(nedge)\n integer k\n integer l\n integer len\n integer lensol\n integer lenstk\n integer nnode\n integer stack(2*nedge)\n logical success\n integer trail(nedge)\n!\n! Check if the digraph is eulerian.\n!\n trail(1:nedge) = 0\n endnod(1:nedge) = 0\n\n do i = 1, nedge\n j = inode(i)\n trail(j) = trail(j) + 1\n j = jnode(i)\n endnod(j) = endnod(j) + 1\n end do\n\n do i = 1, nnode\n if ( trail(i) /= endnod(i) ) then\n success = .false.\n return\n end if\n end do\n!\n! The digraph is eulerian; find an Euler circuit.\n!\n success = .true.\n lensol = 1\n lenstk = 0\n!\n! Find the next edge.\n!\n do\n\n if ( lensol == 1 ) then\n\n endnod(1) = inode(1)\n stack(1) = 1\n stack(2) = 1\n lenstk = 2\n\n else\n\n l = lensol - 1\n\n if ( lensol /= 2 ) then\n endnod(l) = inode(trail(l)) + jnode(trail(l)) - endnod(l-1)\n end if\n\n k = endnod(l)\n\n do i = 1, nedge\n candid(i) = ( k == jnode(i) )\n end do\n\n do i = 1, l\n candid(trail(i)) = .false.\n end do\n\n len = lenstk\n\n do i = 1, nedge\n\n if ( candid(i) ) then\n len = len + 1\n stack(len) = i\n end if\n\n end do\n\n stack(len+1) = len - lenstk\n lenstk = len + 1\n\n end if\n\n do\n\n istak = stack(lenstk)\n lenstk = lenstk - 1\n\n if ( istak /= 0 ) then\n exit\n end if\n\n lensol = lensol - 1\n\n if ( lensol == 0 ) then\n call ivec_reverse ( nedge, trail )\n return\n end if\n\n end do\n\n trail(lensol) = stack(lenstk)\n stack(lenstk) = istak - 1\n\n if ( lensol == nedge ) then\n exit\n end if\n\n lensol = lensol + 1\n\n end do\n\n call ivec_reverse ( nedge, trail )\n\n return\nend\nsubroutine digraph_arc_print ( nedge, inode, jnode, title )\n!\n!*******************************************************************************\n!\n!! DIGRAPH_ARC_PRINT prints out a digraph from an edge list.\n!\n!\n! Modified:\n!\n! 04 July 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer NEDGE, the number of edges.\n!\n! Input, integer INODE(NEDGE), JNODE(NEDGE), the beginning and end\n! nodes of the edges.\n!\n! Input, character ( len = * ) TITLE, a title.\n!\n implicit none\n!\n integer nedge\n!\n integer i\n integer inode(nedge)\n integer jnode(nedge)\n character ( len = * ) title\n!\n if ( len_trim ( title ) /= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) trim ( title )\n end if\n\n write ( *, '(a)' ) ' '\n\n do i = 1, nedge\n write ( *, '(i6,4x,2i6)' ) i, inode(i), jnode(i)\n end do\n\n return\nend\nsubroutine diophantine ( a, b, c, ierror, x, y )\n!\n!*******************************************************************************\n!\n!! DIOPHANTINE solves a Diophantine equation A * X + B * Y = C.\n!\n!\n! Discussion:\n!\n! Given integers A, B and C, produce X and Y so that\n!\n! A * X + B * Y = C.\n!\n! In general, the equation is solvable if and only if the\n! greatest common divisor of A and B also divides C.\n!\n! A solution (X,Y) of the Diophantine equation also gives the solution\n! X to the congruence equation:\n!\n! A * X = C mod ( B ).\n!\n! Generally, if there is one nontrivial solution, there are an infinite\n! number of solutions to a Diophantine problem.\n! If (X0,Y0) is a solution, then so is ( X0+T*B/D, Y0-T*A/D ) where\n! T is any integer, and D is the greatest common divisor of A and B.\n!\n! Reference:\n!\n! Eric Weisstein, editor,\n! CRC Concise Encylopedia of Mathematics,\n! CRC Press, 1998, page 446.\n!\n! Modified:\n!\n! 02 October 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer A, B, C, the coefficients of the Diophantine equation.\n!\n! Output, integer IERROR, error flag.\n! 0, no error, X and Y were computed.\n! 1, A = B = 0, C is nonzero.\n! 2, A = 0, B and C nonzero, but C is not a multiple of B.\n! 3, A nonzero, B zero, C nonzero, but C is not a multiple of A.\n! 4, A, B, C nonzero, but GCD of A and B does not divide C.\n! 5, the algorithm ran out of internal space.\n!\n! Output, integer X, Y, the solution of the Diophantine equation.\n! Note that the algorithm will attempt to return a solution with\n! smallest Euclidean norm.\n!\n implicit none\n!\n integer, parameter :: nmax = 100\n!\n integer a\n integer a_copy\n integer a_mag\n integer a_sign\n integer b\n integer b_copy\n integer b_mag\n integer b_sign\n integer c\n integer c_copy\n integer g\n integer i_gcd\n integer ierror\n integer k\n integer n\n real norm_new\n real norm_old\n integer q(nmax)\n logical swap\n integer temp\n integer x\n integer xnew\n integer y\n integer ynew\n!\n! Defaults for output parameters.\n!\n ierror = 0\n x = 0\n y = 0\n!\n! Special cases.\n!\n if ( a == 0 .and. b == 0 .and. c == 0 ) then\n x = 0\n y = 0\n return\n else if ( a == 0 .and. b == 0 .and. c /= 0 ) then\n ierror = 1\n x = 0\n y = 0\n return\n else if ( a == 0 .and. b /= 0 .and. c == 0 ) then\n x = 0\n y = 0\n return\n else if ( a == 0 .and. b /= 0 .and. c /= 0 ) then\n x = 0\n y = c / b\n if ( mod ( c, b ) /= 0 ) then\n ierror = 2\n end if\n return\n else if ( a /= 0 .and. b == 0 .and. c == 0 ) then\n x = 0\n y = 0\n return\n else if ( a /= 0 .and. b == 0 .and. c /= 0 ) then\n x = c / a\n y = 0\n if ( mod ( c, a ) /= 0 ) then\n ierror = 3\n end if\n return\n else if ( a /= 0 .and. b /= 0 .and. c == 0 ) then\n g = i_gcd ( a, b )\n x = b / g\n y = - a / g\n return\n end if\n!\n! Now handle the \"general\" case: A, B and C are nonzero.\n!\n! Step 1: Compute the GCD of A and B, which must also divide C.\n!\n g = i_gcd ( a, b )\n\n if ( mod ( c, g ) /= 0 ) then\n ierror = 4\n return\n end if\n\n a_copy = a / g\n b_copy = b / g\n c_copy = c / g\n!\n! Step 2: Split A and B into sign and magnitude.\n!\n a_mag = abs ( a_copy )\n a_sign = sign ( 1, a_copy )\n b_mag = abs ( b_copy )\n b_sign = sign ( 1, b_copy )\n!\n! Another special case, A_MAG = 1 or B_MAG = 1.\n!\n if ( a_mag == 1 ) then\n x = a_sign * c_copy\n y = 0\n return\n else if ( b_mag == 1 ) then\n x = 0\n y = b_sign * c_copy\n return\n end if\n!\n! Step 3: Produce the Euclidean remainder sequence.\n!\n if ( a_mag >= b_mag ) then\n\n swap = .false.\n q(1) = a_mag\n q(2) = b_mag\n\n else\n\n swap = .true.\n q(1) = b_mag\n q(2) = a_mag\n\n end if\n\n n = 3\n\n do\n\n q(n) = mod ( q(n-2), q(n-1) )\n\n if ( q(n) == 1 ) then\n exit\n end if\n\n n = n + 1\n\n if ( n > nmax ) then\n ierror = 5\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'DIOPHANTINE - Fatal error!'\n write ( *, '(a)' ) ' Exceeded number of iterations.'\n stop\n end if\n\n end do\n!\n! Step 4: Now go backwards to solve X * A_MAG + Y * B_MAG = 1.\n!\n y = 0\n do k = n, 2, -1\n x = y\n y = ( 1 - x * q(k-1) ) / q(k)\n end do\n!\n! Step 5: Undo the swapping.\n!\n if ( swap ) then\n call i_swap ( x, y )\n end if\n!\n! Step 6: Now apply signs to X and Y so that X * A + Y * B = 1.\n!\n x = x * a_sign\n y = y * b_sign\n!\n! Step 7: Multiply by C, so that X * A + Y * B = C.\n!\n x = x * c_copy\n y = y * c_copy\n!\n! Step 8: Given a solution (X,Y), try to find the solution of\n! minimal magnitude.\n!\n call diophantine_solution_minimize ( a_copy, b_copy, x, y )\n\n return\nend\nsubroutine diophantine_solution_minimize ( a, b, x, y )\n!\n!*******************************************************************************\n!\n!! DIOPHANTINE_SOLUTION_MINIMIZE seeks a minimal solution of a Diophantine equation.\n!\n!\n! Discussion:\n!\n! Given a solution (X,Y) of a Diophantine equation:\n!\n! A * X + B * Y = C.\n!\n! then there are an infinite family of solutions of the form\n!\n! ( X(i), Y(i) ) = ( X + i * B, Y - i * A )\n!\n! An integral solution of minimal Euclidean norm can be found by\n! tentatively moving along the vectors (B,-A) and (-B,A) one step\n! at a time.\n!\n! Reference:\n!\n! Eric Weisstein, editor,\n! CRC Concise Encylopedia of Mathematics,\n! CRC Press, 1998, page 446.\n!\n! Modified:\n!\n! 03 October 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer A, B, the coefficients of the Diophantine equation.\n! A and B are assumed to be relatively prime.\n!\n! Input/output, integer X, Y, on input, a solution of the Diophantine\n! equation. On output, a solution of minimal Euclidean norm.\n!\n implicit none\n!\n integer a\n integer b\n real norm\n real norm_new\n real t\n integer x\n integer xnew\n integer y\n integer ynew\n!\n! Compute the minimum for T real, and then look nearby.\n!\n t = ( - real ( b ) * real ( x ) + real ( a ) * real ( y ) ) &\n / ( real ( a )**2 + real ( b )**2 )\n\n x = x + nint ( t ) * b\n y = y - nint ( t ) * a\n!\n! Now look nearby.\n!\n norm = ( real ( x ) )**2 + ( real ( y ) )**2\n\n do\n\n xnew = x + b\n ynew = y - a\n\n norm_new = ( real ( xnew ) )**2 + ( real ( ynew ) )**2\n\n if ( norm_new >= norm ) then\n exit\n end if\n\n x = xnew\n y = ynew\n norm = norm_new\n\n end do\n\n do\n\n xnew = x - b\n ynew = y + a\n\n norm_new = ( real ( xnew ) )**2 + ( real ( ynew ) )**2\n\n if ( norm_new >= norm ) then\n exit\n end if\n\n x = xnew\n y = ynew\n norm = norm_new\n\n end do\n\n return\nend\nsubroutine equiv_next ( n, npart, jarray, iarray, more )\n!\n!*******************************************************************************\n!\n!! EQUIV_NEXT computes the partitions of a set one at a time.\n!\n!\n! Definition:\n!\n! A partition of a set assigns each element to exactly one subset.\n!\n! Comments:\n!\n! The number of partitions of a set of size N is the Bell number B(N).\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 18 July 2000\n!\n! Parameters:\n!\n! Input, integer N, number of elements in the set to be partitioned.\n!\n! Output, integer NPART, number of subsets in the partition.\n!\n! Output, integer JARRAY(N). JARRAY(I) is the number of elements\n! in the I-th subset of the partition.\n!\n! Output, integer IARRAY(N). IARRAY(I) is the class to which\n! element I belongs.\n!\n! Input/output, logical MORE. Set MORE = .FALSE. before first call.\n! It is reset and held at .TRUE. as long as\n! the partition returned is not the last one.\n! When MORE is returned .FALSE., all the partitions\n! have been computed and returned.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer iarray(n)\n integer jarray(n)\n integer l\n integer m\n logical more\n integer npart\n!\n if ( .not. more ) then\n\n npart = 1\n iarray(1:n) = 1\n jarray(1) = n\n\n else\n\n m = n\n\n do while ( jarray(iarray(m)) == 1 )\n iarray(m) = 1\n m = m - 1\n end do\n\n l = iarray(m)\n npart = npart + m - n\n jarray(1) = jarray(1) + n - m\n\n if ( l == npart ) then\n npart = npart + 1\n jarray(npart) = 0\n end if\n\n iarray(m) = l + 1\n jarray(l) = jarray(l) - 1\n jarray(l+1) = jarray(l+1) + 1\n\n end if\n\n more = npart /= n\n\n return\nend\nsubroutine equiv_next2 ( done, iarray, n )\n!\n!*******************************************************************************\n!\n!! EQUIV_NEXT2 computes, one at a time, the partitions of a set.\n!\n!\n! Definition:\n!\n! A partition of a set assigns each element to exactly one subset.\n!\n! Comments:\n!\n! The number of partitions of a set of size N is the Bell number B(N).\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Input/output, logical DONE. Before the very first call, the\n! user should set DONE to .TRUE., which prompts the program\n! to initialize its data, and return the first partition.\n!\n! Thereafter, the user should call again, for the next\n! partition, and so on, until the routine returns with DONE\n! equal to .TRUE., at which point there are no more partitions\n! to compute.\n!\n! Input/output, integer IARRAY(N), contains the information\n! defining the current partition. The user should not alter\n! IARRAY between calls. Except for the very first\n! call, the routine uses the previous output value of IARRAY to compute\n! the next value.\n!\n! The entries of IARRAY are the partition subset to which each\n! element of the original set belongs. If there are NPART distinct\n! parts of the partition, then each entry of IARRAY will be a\n! number between 1 and NPART. Every number from 1 to NPART will\n! occur somewhere in the list. If the entries of IARRAY are\n! examined in order, then each time a new partition subset occurs,\n! it will be the next unused integer.\n!\n! For instance, for N = 4, the program will describe the set\n! where each element is in a separate subset as 1, 2, 3, 4,\n! even though such a partition might also be described as\n! 4, 3, 2, 1 or even 1, 5, 8, 19.\n!\n! Input, integer N, the number of elements in the set.\n!\n implicit none\n!\n integer n\n!\n logical done\n integer i\n integer iarray(n)\n integer imax\n integer j\n integer jmax\n!\n if ( done ) then\n\n done = .false.\n\n iarray(1:n) = 1\n\n else\n!\n! Find the last element J that can be increased by 1.\n! This is the element that is not equal to its maximum possible value,\n! which is the maximum value of all preceding elements +1.\n!\n jmax = iarray(1)\n imax = 1\n\n do j = 2, n\n\n if ( iarray(j) > jmax ) then\n jmax = iarray(j)\n else\n imax = j\n end if\n\n end do\n!\n! If no element can be increased by 1, we are done.\n!\n if ( imax == 1 ) then\n done = .true.\n return\n end if\n!\n! Increase the value of the IMAX-th element by 1, set its successors to 1.\n!\n done = .false.\n iarray(imax) = iarray(imax) + 1\n iarray(imax+1:n) = 1\n\n end if\n\n return\nend\nsubroutine equiv_print ( n, iarray )\n!\n!*******************************************************************************\n!\n!! EQUIV_PRINT prints a partition of a set.\n!\n!\n! Modified:\n!\n! 11 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, number of elements in set to be partitioned.\n!\n! Input, integer IARRAY(N), defines the partition or set of equivalence\n! classes. Element I belongs to subset IARRAY(I).\n!\n implicit none\n!\n integer n\n!\n integer iarray(n)\n integer karray(n)\n integer j\n integer k\n integer s\n integer s_max\n integer s_min\n!\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'Set partition:'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' Set Size'\n\n s_min = minval ( iarray(1:n) )\n s_max = maxval ( iarray(1:n) )\n\n do s = s_min, s_max\n\n k = 0\n\n do j = 1, n\n\n if ( iarray(j) == s ) then\n k = k + 1\n karray(k) = j\n end if\n\n end do\n\n if ( k > 0 ) then\n write ( *, '(2i6,4x,(10i4))' ) s, k, karray(1:k)\n end if\n\n end do\n\n return\nend\nsubroutine equiv_random ( n, npart, iarray, b )\n!\n!*******************************************************************************\n!\n!! EQUIV_RANDOM selects a random partition of a set.\n!\n!\n! Discussion:\n!\n! The user does not control the number of parts in the partition.\n!\n! The equivalence classes are numbered in no particular order.\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 12 May 2002\n!\n! Parameters:\n!\n! Input, integer N, the number of elements in the set to be partitioned.\n!\n! Output, integer NPART, the number of classes or parts in the \n! partition. NPART will be between 1 and N.\n!\n! Output, integer IARRAY(N), indicates the class to which each element\n! is assigned.\n!\n! Output, real B(N). B(K) = A(K)/(K!), where\n! A(K) = number of partitions of a set of K objects.\n!\n implicit none\n!\n integer n\n!\n real b(n)\n integer iarray(n)\n integer k\n integer l\n integer m\n integer npart\n real sum1\n real z\n real, parameter :: zhi = 1.0E+00\n real, parameter :: zlo = 0.0E+00\n!\n b(1) = 1.0E+00\n\n do l = 1, n-1\n\n sum1 = 1.0E+00 / real ( l )\n do k = 1, l-1\n sum1 = ( sum1 + b(k) ) / real ( l - k )\n end do\n\n b(l+1) = ( sum1 + b(l) ) / real ( l + 1 )\n\n end do\n\n m = n\n npart = 0\n\n do\n\n call r_random ( zlo, zhi, z )\n z = real ( m ) * b(m) * z\n k = 0\n npart = npart + 1\n\n do while ( z >= 0.0E+00 )\n\n iarray(m) = npart\n m = m - 1\n\n if ( m == 0 ) then\n exit\n end if\n\n z = z - b(m)\n k = k + 1\n z = z * k\n\n end do\n\n if ( m == 0 ) then\n exit\n end if\n\n end do\n!\n! Randomly permute the assignments.\n!\n call perm_random2 ( n, iarray )\n\n return\nend\nsubroutine euler ( ieuler, n )\n!\n!*******************************************************************************\n!\n!! EULER returns the N-th row of Euler's triangle.\n!\n!\n! Definition:\n!\n! E(N,K) counts the number of permutations of the N digits that have\n! exactly K \"ascents\", that is, K places where the Ith digit is\n! less than the (I+1)th digit.\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Output, integer IEULER(0:N), the N-th row of Euler's\n! triangle, IEULER(K) contains the value of E(N,K). Note\n! that IEULER(0) should be 1 and IEULER(N) should be 0.\n!\n! Input, integer N, the row of Euler's triangle desired.\n!\n implicit none\n!\n integer n\n!\n integer ieuler(0:n)\n integer irow\n integer k\n!\n ieuler(0) = 1\n\n if ( n > 0 ) then\n\n ieuler(1) = 0\n\n do irow = 2, n\n\n ieuler(irow) = 0\n\n do k = irow-1, 1, -1\n\n ieuler(k) = ( k + 1 ) * ieuler(k) + ( irow - k ) * ieuler(k-1)\n\n end do\n\n ieuler(0) = 1\n\n end do\n\n end if\n\n return\nend\nfunction fall ( x, n )\n!\n!*******************************************************************************\n!\n!! FALL computes the falling factorial function [X]_N.\n!\n!\n! Discussion:\n!\n! Note that the number of \"injections\" or 1-to-1 mappings from\n! a set of N elements to a set of M elements is [M]_N.\n!\n! The number of permutations of N objects out of M is [M}_N.\n!\n! Moreover, the Stirling numbers of the first kind can be used\n! to convert a falling factorial into a polynomial, as follows:\n!\n! [X]_N = S^0_N + S^1_N * X + S^2_N * X^2 + ... + S^N_N X^N.\n!\n! Formula:\n!\n! [X]_N = X * ( X - 1 ) * ( X - 2 ) * ... * ( X - N + 1 ).\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real X, the argument of the falling factorial function.\n!\n! Input, integer N, the order of the falling factorial function.\n! If N = 0, FALL = 1, if N = 1, FALL = X. Note that if N is\n! negative, a \"rising\" factorial will be computed.\n!\n! Output, real FALL, the value of the falling factorial function.\n!\n implicit none\n!\n real arg\n real fall\n integer i\n integer n\n real x\n!\n fall = 1.0E+00\n\n arg = x\n\n if ( n > 0 ) then\n\n do i = 1, n\n fall = fall * arg\n arg = arg - 1.0E+00\n end do\n\n else if ( n < 0 ) then\n\n do i = -1, n\n fall = fall * arg\n arg = arg + 1.0E+00\n end do\n\n end if\n\n return\nend\nfunction gamma_log ( x )\n!\n!*******************************************************************************\n!\n!! GAMMA_LOG calculates the natural logarithm of GAMMA ( X ) for positive X.\n!\n!\n! Discussion:\n!\n! Computation is based on an algorithm outlined in references 1 and 2.\n! The program uses rational functions that theoretically approximate\n! LOG(GAMMA(X)) to at least 18 significant decimal digits. The\n! approximation for X > 12 is from reference 3, while approximations\n! for X < 12.0 are similar to those in reference 1, but are unpublished.\n! The accuracy achieved depends on the arithmetic system, the compiler,\n! intrinsic functions, and proper selection of the machine-dependent\n! constants.\n!\n! Modified:\n!\n! 16 June 1999\n!\n! Authors:\n!\n! W. J. Cody and L. Stoltz\n! Argonne National Laboratory\n!\n! References:\n!\n! # 1)\n! W. J. Cody and K. E. Hillstrom,\n! Chebyshev Approximations for the Natural Logarithm of the Gamma Function,\n! Math. Comp.\n! Volume 21, 1967, pages 198-203.\n!\n! # 2)\n! K. E. Hillstrom,\n! ANL/AMD Program ANLC366S, DGAMMA/DLGAMA,\n! May 1969.\n!\n! # 3)\n! Hart, Et. Al.,\n! Computer Approximations,\n! Wiley and sons, New York, 1968.\n!\n! Parameters:\n!\n! Input, real X, the argument of the Gamma function. X must be positive.\n!\n! Output, real GAMMA_LOG, the logarithm of the Gamma function of X.\n! If X <= 0.0, or if overflow would occur, the program returns the\n! value XINF, the largest representable floating point number.\n!\n!*******************************************************************************\n!\n! Explanation of machine-dependent constants\n!\n! BETA - radix for the floating-point representation.\n!\n! MAXEXP - the smallest positive power of BETA that overflows.\n!\n! XBIG - largest argument for which LN(GAMMA(X)) is representable\n! in the machine, i.e., the solution to the equation\n! LN(GAMMA(XBIG)) = BETA**MAXEXP.\n!\n! FRTBIG - Rough estimate of the fourth root of XBIG\n!\n!\n! Approximate values for some important machines are:\n!\n! BETA MAXEXP XBIG\n!\n! CRAY-1 (S.P.) 2 8191 9.62E+2461\n! Cyber 180/855\n! under NOS (S.P.) 2 1070 1.72E+319\n! IEEE (IBM/XT,\n! SUN, etc.) (S.P.) 2 128 4.08E+36\n! IEEE (IBM/XT,\n! SUN, etc.) (D.P.) 2 1024 2.55D+305\n! IBM 3033 (D.P.) 16 63 4.29D+73\n! VAX D-Format (D.P.) 2 127 2.05D+36\n! VAX G-Format (D.P.) 2 1023 1.28D+305\n!\n!\n! FRTBIG\n!\n! CRAY-1 (S.P.) 3.13E+615\n! Cyber 180/855\n! under NOS (S.P.) 6.44E+79\n! IEEE (IBM/XT,\n! SUN, etc.) (S.P.) 1.42E+9\n! IEEE (IBM/XT,\n! SUN, etc.) (D.P.) 2.25D+76\n! IBM 3033 (D.P.) 2.56D+18\n! VAX D-Format (D.P.) 1.20D+9\n! VAX G-Format (D.P.) 1.89D+76\n!\n implicit none\n!\n real, parameter, dimension ( 7 ) :: c = (/ &\n -1.910444077728E-03, &\n 8.4171387781295E-04, &\n -5.952379913043012E-04, &\n 7.93650793500350248E-04, &\n -2.777777777777681622553E-03, &\n 8.333333333333333331554247E-02, &\n 5.7083835261E-03 /)\n real corr\n real, parameter :: d1 = - 5.772156649015328605195174E-01\n real, parameter :: d2 = 4.227843350984671393993777E-01\n real, parameter :: d4 = 1.791759469228055000094023E+00\n real, parameter :: frtbig = 1.42E+09\n integer i\n real gamma_log\n real, parameter, dimension ( 8 ) :: p1 = (/ &\n 4.945235359296727046734888E+00, &\n 2.018112620856775083915565E+02, &\n 2.290838373831346393026739E+03, &\n 1.131967205903380828685045E+04, &\n 2.855724635671635335736389E+04, &\n 3.848496228443793359990269E+04, &\n 2.637748787624195437963534E+04, &\n 7.225813979700288197698961E+03 /)\n real, parameter, dimension ( 8 ) :: p2 = (/ &\n 4.974607845568932035012064E+00, &\n 5.424138599891070494101986E+02, &\n 1.550693864978364947665077E+04, &\n 1.847932904445632425417223E+05, &\n 1.088204769468828767498470E+06, &\n 3.338152967987029735917223E+06, &\n 5.106661678927352456275255E+06, &\n 3.074109054850539556250927E+06 /)\n real, parameter, dimension ( 8 ) :: p4 = (/ &\n 1.474502166059939948905062E+04, &\n 2.426813369486704502836312E+06, &\n 1.214755574045093227939592E+08, &\n 2.663432449630976949898078E+09, &\n 2.940378956634553899906876E+010, &\n 1.702665737765398868392998E+011, &\n 4.926125793377430887588120E+011, &\n 5.606251856223951465078242E+011 /)\n real, parameter :: pnt68 = 0.6796875E+00\n real, parameter, dimension ( 8 ) :: q1 = (/ &\n 6.748212550303777196073036E+01, &\n 1.113332393857199323513008E+03, &\n 7.738757056935398733233834E+03, &\n 2.763987074403340708898585E+04, &\n 5.499310206226157329794414E+04, &\n 6.161122180066002127833352E+04, &\n 3.635127591501940507276287E+04, &\n 8.785536302431013170870835E+03 /)\n real, parameter, dimension ( 8 ) :: q2 = (/ &\n 1.830328399370592604055942E+02, &\n 7.765049321445005871323047E+03, &\n 1.331903827966074194402448E+05, &\n 1.136705821321969608938755E+06, &\n 5.267964117437946917577538E+06, &\n 1.346701454311101692290052E+07, &\n 1.782736530353274213975932E+07, &\n 9.533095591844353613395747E+06 /)\n real, parameter, dimension ( 8 ) :: q4 = (/ &\n 2.690530175870899333379843E+03, &\n 6.393885654300092398984238E+05, &\n 4.135599930241388052042842E+07, &\n 1.120872109616147941376570E+09, &\n 1.488613728678813811542398E+010, &\n 1.016803586272438228077304E+011, &\n 3.417476345507377132798597E+011, &\n 4.463158187419713286462081E+011 /)\n real res\n real, parameter :: sqrtpi = 0.9189385332046727417803297E+00\n real x\n real, parameter :: xbig = 4.08E+36\n real xden\n real xm1\n real xm2\n real xm4\n real xnum\n real xsq\n!\n! Return immediately if the argument is out of range.\n!\n if ( x <= 0.0E+00 .or. x > xbig ) then\n gamma_log = huge ( gamma_log )\n return\n end if\n\n if ( x <= epsilon ( x ) ) then\n\n res = - log ( x )\n\n else if ( x <= 1.5E+00 ) then\n\n if ( x < pnt68 ) then\n corr = - log ( x )\n xm1 = x\n else\n corr = 0.0E+00\n xm1 = ( x - 0.5E+00 ) - 0.5E+00\n end if\n\n if ( x <= 0.5E+00 .or. x >= pnt68 ) then\n\n xden = 1.0E+00\n xnum = 0.0E+00\n\n do i = 1, 8\n xnum = xnum * xm1 + p1(i)\n xden = xden * xm1 + q1(i)\n end do\n\n res = corr + ( xm1 * ( d1 + xm1 * ( xnum / xden ) ) )\n\n else\n\n xm2 = ( x - 0.5E+00 ) - 0.5E+00\n xden = 1.0E+00\n xnum = 0.0E+00\n do i = 1, 8\n xnum = xnum * xm2 + p2(i)\n xden = xden * xm2 + q2(i)\n end do\n\n res = corr + xm2 * ( d2 + xm2 * ( xnum / xden ) )\n\n end if\n\n else if ( x <= 4.0E+00 ) then\n\n xm2 = x - 2.0E+00\n xden = 1.0E+00\n xnum = 0.0E+00\n do i = 1, 8\n xnum = xnum * xm2 + p2(i)\n xden = xden * xm2 + q2(i)\n end do\n\n res = xm2 * ( d2 + xm2 * ( xnum / xden ) )\n\n else if ( x <= 12.0E+00 ) then\n\n xm4 = x - 4.0E+00\n xden = - 1.0E+00\n xnum = 0.0E+00\n do i = 1, 8\n xnum = xnum * xm4 + p4(i)\n xden = xden * xm4 + q4(i)\n end do\n\n res = d4 + xm4 * ( xnum / xden )\n\n else\n\n res = 0.0E+00\n\n if ( x <= frtbig ) then\n\n res = c(7)\n xsq = x * x\n\n do i = 1, 6\n res = res / xsq + c(i)\n end do\n\n end if\n\n res = res / x\n corr = log ( x )\n res = res + sqrtpi - 0.5E+00 * corr\n res = res + x * ( corr - 1.0E+00 )\n\n end if\n\n gamma_log = res\n\n return\nend\nsubroutine gray_rank ( gray, rank )\n!\n!*******************************************************************************\n!\n!! GRAY_RANK ranks a Gray code.\n!\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Input, integer GRAY, the Gray code to be ranked.\n!\n! Output, integer RANK, the rank of GRAY, and the integer whose Gray\n! code is GRAY.\n!\n implicit none\n!\n integer gray\n integer i\n integer ii\n integer j\n integer, parameter :: nbits = 32\n integer rank\n!\n j = 0\n\n if ( btest ( gray, nbits-1 ) ) then\n j = ibset ( j, nbits-1 )\n end if\n\n do i = 2, nbits\n\n ii = nbits - i\n\n if ( btest ( j, ii+1 ) .and. ( .not. btest ( gray, ii ) ) ) then\n j = ibset ( j, ii )\n end if\n\n if ( ( .not. btest ( j, ii+1 ) ) .and. btest ( gray, ii ) ) then\n j = ibset ( j, ii )\n end if\n\n end do\n\n rank = j\n\n return\nend\nsubroutine gray_unrank ( rank, gray )\n!\n!*******************************************************************************\n!\n!! GRAY_UNRANK unranks a Gray code.\n!\n!\n! Comments:\n!\n! The binary values of the Gray codes of successive integers differ in\n! just one bit.\n!\n! The sequence of Gray codes for 0 to (2**N)-1 can be interpreted as a\n! Hamiltonian cycle on a graph of the cube in N dimensions.\n!\n! Examples:\n!\n! RANK IGRAY BINARY\n! 0 0 0\n! 1 1 1\n! 2 3 11\n! 3 2 10\n! 4 6 110\n! 5 7 111\n! 6 5 101\n! 7 4 100\n! 8 12 1100\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Input, integer RANK, the integer whose Gray code is desired.\n!\n! Output, integer GRAY, the Gray code of the given rank.\n!\n implicit none\n!\n integer gray\n integer i\n integer ii\n integer j\n integer, parameter :: nbits = 32\n integer rank\n!\n j = 0\n\n if ( btest ( rank, nbits-1 ) ) then\n j = ibset ( j, nbits-1 )\n end if\n\n do i = 2, nbits\n\n ii = nbits - i\n\n if ( btest ( rank, ii+1 ) .neqv. btest ( rank, ii ) ) then\n j = ibset ( j, ii )\n end if\n\n end do\n\n gray = j\n\n return\nend\nsubroutine i_data ( op, var, ival )\n!\n!*******************************************************************************\n!\n!! I_DATA stores and retrieves common data items.\n!\n!\n! Discussion:\n!\n! This routine works like a sort of COMMON block. It stores or returns\n! the values of certain variables. Thus, it allows routines\n! to \"communicate\" without having to have data passed up and\n! down the calling tree in argument lists.\n!\n! The variables stored by this version of the routine are:\n!\n! 'DEC_DIGIT', the number of digits stored for decimals;\n! 'DEC_DIGIT_MAX', the maximum number of digits stored for decimals;\n! 'I_BIG', the biggest integer to use in calculations.\n!\n! Modified:\n!\n! 20 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, character ( len = * ) OP, describes the operation to be done.\n! 'SET' means set a value.\n! 'INC' means increment a value (and return its new value)\n! 'GET' means get a value.\n!\n! Input, character ( len = * ) VAR, the name of the variable.\n!\n! Input/output, integer IVAL.\n! If OP is 'SET', then the variable named in VAR is set to the\n! value IVAL.\n! If OP is 'GET', then the value of IVAL is set to the value of\n! the variable named in VAR.\n! If OP is 'INC', then the value of IVAL is incremented by 1,\n! and its new value is returned in VAR.\n!\n implicit none\n!\n integer, save :: dec_digit = 7\n integer, save :: dec_digit_max = 7\n integer, save :: i_big = huge ( i_big )\n integer ival\n character ( len = * ) op\n logical s_eqi\n character ( len = * ) var\n!\n if ( s_eqi ( op, 'SET' ) ) then\n\n if ( s_eqi ( var, 'DEC_DIGIT' ) ) then\n dec_digit = ival\n else if ( s_eqi ( var, 'DEC_DIGIT_MAX' ) ) then\n dec_digit_max = ival\n else if ( s_eqi ( var, 'I_BIG' ) ) then\n i_big = ival\n end if\n\n else if ( s_eqi ( op, 'GET' ) ) then\n\n if ( s_eqi ( var, 'DEC_DIGIT' ) ) then\n ival = dec_digit\n else if ( s_eqi ( var, 'DEC_DIGIT_MAX' ) ) then\n ival = dec_digit_max\n else if ( s_eqi ( var, 'I_BIG' ) ) then\n ival = i_big\n end if\n\n else if ( s_eqi ( op, 'INC' ) ) then\n\n if ( s_eqi ( var, 'DEC_DIGIT' ) ) then\n dec_digit = dec_digit + 1\n ival = dec_digit\n else if ( s_eqi ( var, 'DEC_DIGIT_MAX' ) ) then\n dec_digit_max = dec_digit_max + 1\n ival = dec_digit_max\n else if ( s_eqi ( var, 'I_BIG' ) ) then\n i_big = i_big + 1\n ival = i_big\n end if\n\n end if\n\n return\nend\nsubroutine i_factor ( n, maxfactor, nfactor, factor, power, nleft )\n!\n!*******************************************************************************\n!\n!! I_FACTOR factors an integer into prime factors.\n!\n!\n! Formula:\n!\n! N = NLEFT * Product ( I = 1 to NFACTOR ) FACTOR(I)**POWER(I).\n!\n! Modified:\n!\n! 20 July 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the integer to be factored. N may be positive,\n! negative, or 0.\n!\n! Input, integer MAXFACTOR, the maximum number of prime factors for\n! which storage has been allocated.\n!\n! Output, integer NFACTOR, the number of prime factors of N discovered\n! by the routine.\n!\n! Output, integer FACTOR(MAXFACTOR), the prime factors of N.\n!\n! Output, integer POWER(MAXFACTOR). POWER(I) is the power of\n! the FACTOR(I) in the representation of N.\n!\n! Output, integer NLEFT, the factor of N that the routine could not\n! divide out. If NLEFT is 1, then N has been completely factored.\n! Otherwise, NLEFT represents factors of N involving large primes.\n!\n implicit none\n!\n integer maxfactor\n!\n integer factor(maxfactor)\n integer i\n integer maxprime\n integer n\n integer nleft\n integer nfactor\n integer p\n integer power(maxfactor)\n integer prime\n!\n nfactor = 0\n\n factor(1:maxfactor) = 0\n power(1:maxfactor) = 0\n\n nleft = n\n\n if ( n == 0 ) then\n return\n end if\n\n if ( abs ( n ) == 1 ) then\n nfactor = 1\n factor(1) = 1\n power(1) = 1\n return\n end if\n!\n! Find out how many primes we stored.\n!\n maxprime = prime ( -1 )\n!\n! Try dividing the remainder by each prime.\n!\n do i = 1, maxprime\n\n p = prime ( i )\n\n if ( mod ( abs ( nleft ), p ) == 0 ) then\n\n if ( nfactor < maxfactor ) then\n\n nfactor = nfactor + 1\n factor(nfactor) = p\n\n do\n\n power(nfactor) = power(nfactor) + 1\n nleft = nleft / p\n\n if ( mod ( abs ( nleft ), p ) /= 0 ) then\n exit\n end if\n\n end do\n\n if ( abs ( nleft ) == 1 ) then\n exit\n end if\n\n end if\n\n end if\n\n end do\n\n return\nend\nfunction i_gcd ( i, j )\n!\n!*******************************************************************************\n!\n!! I_GCD finds the greatest common divisor of I and J.\n!\n!\n! Modified:\n!\n! 03 March 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer I, J, two numbers whose greatest common divisor\n! is desired.\n!\n! Output, integer I_GCD, the greatest common divisor of I and J.\n!\n! Note that only the absolute values of I and J are\n! considered, so that the result is always nonnegative.\n!\n! If I or J is 0, I_GCD is returned as max ( 1, abs ( I ), abs ( J ) ).\n!\n! If I and J have no common factor, I_GCD is returned as 1.\n!\n! Otherwise, using the Euclidean algorithm, I_GCD is the\n! largest common factor of I and J.\n!\n implicit none\n!\n integer i\n integer i_gcd\n integer ip\n integer iq\n integer ir\n integer j\n!\n i_gcd = 1\n!\n! Return immediately if either I or J is zero.\n!\n if ( i == 0 ) then\n i_gcd = max ( 1, abs ( j ) )\n return\n else if ( j == 0 ) then\n i_gcd = max ( 1, abs ( i ) )\n return\n end if\n!\n! Set IP to the larger of I and J, IQ to the smaller.\n! This way, we can alter IP and IQ as we go.\n!\n ip = max ( abs ( i ), abs ( j ) )\n iq = min ( abs ( i ), abs ( j ) )\n!\n! Carry out the Euclidean algorithm.\n!\n do\n\n ir = mod ( ip, iq )\n\n if ( ir == 0 ) then\n exit\n end if\n\n ip = iq\n iq = ir\n\n end do\n\n i_gcd = iq\n\n return\nend\nfunction i_modp ( i, j )\n!\n!*******************************************************************************\n!\n!! I_MODP returns the nonnegative remainder of integer division.\n!\n!\n! Formula:\n!\n! If\n! NREM = I_MODP ( I, J )\n! NMULT = ( I - NREM ) / J\n! then\n! I = J * NMULT + NREM\n! where NREM is always nonnegative.\n!\n! Comments:\n!\n! The MOD function computes a result with the same sign as the\n! quantity being divided. Thus, suppose you had an angle A,\n! and you wanted to ensure that it was between 0 and 360.\n! Then mod(A,360) would do, if A was positive, but if A\n! was negative, your result would be between -360 and 0.\n!\n! On the other hand, I_MODP(A,360) is between 0 and 360, always.\n!\n! Examples:\n!\n! I J MOD I_MODP I_MODP Factorization\n!\n! 107 50 7 7 107 = 2 * 50 + 7\n! 107 -50 7 7 107 = -2 * -50 + 7\n! -107 50 -7 43 -107 = -3 * 50 + 43\n! -107 -50 -7 43 -107 = 3 * -50 + 43\n!\n! Modified:\n!\n! 02 March 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer I, the number to be divided.\n!\n! Input, integer J, the number that divides I.\n!\n! Output, integer I_MODP, the nonnegative remainder when I is divided by J.\n!\n implicit none\n!\n integer i\n integer i_modp\n integer j\n!\n if ( j == 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'I_MODP - Fatal error!'\n write ( *, '(a,i6)' ) ' I_MODP ( I, J ) called with J = ', j\n stop\n end if\n\n i_modp = mod ( i, j )\n\n if ( i_modp < 0 ) then\n i_modp = i_modp + abs ( j )\n end if\n\n return\nend\nsubroutine i_moebius ( n, mu )\n!\n!*******************************************************************************\n!\n!! I_MOEBIUS returns the value of MU(N), the Moebius function of N.\n!\n!\n! Definition:\n!\n! MU(N) is defined as follows:\n!\n! MU(N) = 1 if N = 1;\n! 0 if N is divisible by the square of a prime;\n! (-1)**K, if N is the product of K distinct primes.\n!\n! First values:\n!\n! N MU(N)\n!\n! 1 1\n! 2 -1\n! 3 -1\n! 4 0\n! 5 -1\n! 6 1\n! 7 -1\n! 8 0\n! 9 0\n! 10 1\n! 11 -1\n! 12 0\n! 13 -1\n! 14 1\n! 15 1\n! 16 0\n! 17 -1\n! 18 0\n! 19 -1\n! 20 0\n!\n! Note:\n!\n! As special cases, MU(N) is -1 if N is a prime, and MU(N) is 0\n! if N is a square, cube, etc.\n!\n! Formula:\n!\n! The Moebius function is related to Euler's totient function:\n!\n! PHI(N) = sum ( D divides N ) MU(D) * ( N / D ).\n!\n! Modified:\n!\n! 01 March 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the value to be analyzed.\n!\n! Output, integer MU, the value of MU(N).\n! If N is less than or equal to 0, MU will be returned as -2.\n! If there was not enough internal space for factoring, MU\n! is returned as -3.\n!\n implicit none\n!\n integer, parameter :: maxfactor = 20\n!\n integer factor(maxfactor)\n integer i\n integer mu\n integer n\n integer nfactor\n integer nleft\n integer power(maxfactor)\n!\n if ( n <= 0 ) then\n mu = - 2\n return\n end if\n\n if ( n == 1 ) then\n mu = 1\n return\n end if\n!\n! Factor N.\n!\n call i_factor ( n, maxfactor, nfactor, factor, power, nleft )\n\n if ( nleft /= 1 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'I_MOEBIUS - Fatal error!'\n write ( *, '(a)' ) ' Not enough factorization space.'\n mu = - 3\n return\n end if\n\n mu = 1\n\n do i = 1, nfactor\n\n mu = - mu\n\n if ( power(i) > 1 ) then\n mu = 0\n return\n end if\n\n end do\n\n return\nend\nsubroutine i_random ( ilo, ihi, i )\n!\n!*******************************************************************************\n!\n!! I_RANDOM returns a random integer in a given range.\n!\n!\n! Modified:\n!\n! 27 June 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ILO, IHI, the minimum and maximum acceptable values.\n!\n! Output, integer I, the randomly chosen integer.\n!\n implicit none\n!\n integer i\n integer ihi\n integer ilo\n real r\n real rhi\n real rlo\n!\n! Pick a random number in (0,1).\n!\n call random_number ( harvest = r )\n!\n! Set a real interval [RLO,RHI] which contains the integers [ILO,IHI],\n! each with a \"neighborhood\" of width 1.\n!\n rlo = real ( ilo ) - 0.5E+00\n rhi = real ( ihi ) + 0.5E+00\n!\n! Set I to the integer that is nearest the scaled value of R.\n!\n i = nint ( ( 1.0E+00 - r ) * rlo + r * rhi )\n!\n! In case of oddball events at the boundary, enforce the limits.\n!\n i = max ( i, ilo )\n i = min ( i, ihi )\n\n return\nend\nsubroutine i_sqrt ( n, q, r )\n!\n!*******************************************************************************\n!\n!! I_SQRT finds the integer square root of N by solving N = Q**2 + R.\n!\n!\n! Discussion:\n!\n! The integer square root of N is an integer Q such that\n! Q**2 <= N but (Q+1)**2 > N.\n!\n! A simpler calculation would be something like\n!\n! Q = INT ( SQRT ( REAL ( N ) ) )\n!\n! but this calculation has the virtue of using only integer arithmetic.\n!\n! To avoid the tedium of worrying about negative arguments, the routine\n! automatically considers the absolute value of the argument.\n!\n! Reference:\n!\n! Mark Herkommer,\n! Number Theory, A Programmer's Guide,\n! McGraw Hill, 1999, pages 294-307.\n!\n! Modified:\n!\n! 18 July 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number whose integer square root is desired.\n! Actually, only the absolute value of N is considered.\n!\n! Output, integer Q, R, the integer square root, and positive remainder,\n! of N.\n!\n implicit none\n!\n integer n\n integer n_abs\n integer q\n integer r\n!\n n_abs = abs ( n )\n\n q = n_abs\n\n if ( n_abs > 0 ) then\n\n do while ( q > n_abs / q )\n q = ( q + ( n_abs / q ) ) / 2\n end do\n\n end if\n\n r = n_abs - q**2\n\n return\nend\nsubroutine i_sqrt_cf ( n, max_term, n_term, b )\n!\n!*******************************************************************************\n!\n!! I_SQRT_CF finds the continued fraction representation of a square root of an integer.\n!\n!\n! Discussion:\n!\n! The continued fraction representation of the square root of an integer\n! has the form\n!\n! [ B0, (B1, B2, B3, ..., BM), ... ]\n!\n! where\n!\n! B0 = int ( sqrt ( real ( N ) ) )\n! BM = 2 * B0\n! the sequence ( B1, B2, B3, ..., BM ) repeats in the representation.\n! the value M is termed the period of the representation.\n!\n! Examples:\n!\n! N Period Continued Fraction\n!\n! 2 1 [ 1, 2, 2, 2, ... ]\n! 3 2 [ 1, 1, 2, 1, 2, 1, 2... ]\n! 4 0 [ 2 ]\n! 5 1 [ 2, 4, 4, 4, ... ]\n! 6 2 [ 2, 2, 4, 2, 4, 2, 4, ... ]\n! 7 4 [ 2, 1, 1, 1, 4, 1, 1, 4, 1, 1, 4... ]\n! 8 2 [ 2, 1, 4, 1, 4, 1, 4, 1, 4, ... ]\n! 9 0 [ 3 ]\n! 10 1 [ 3, 6, 6, 6, ... ]\n!\n! Reference:\n!\n! Mark Herkommer,\n! Number Theory, A Programmer's Guide,\n! McGraw Hill, 1999, pages 294-307.\n!\n! Modified:\n!\n! 18 July 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number whose continued fraction square root\n! is desired.\n!\n! Input, integer MAX_TERM, the maximum number of terms that may\n! be computed.\n!\n! Output, integer N_TERM, the number of terms computed beyond the\n! 0 term. The routine should stop if it detects that the period\n! has been reached.\n!\n! Output, integer B(0:MAX_TERM), contains the continued fraction\n! coefficients in entries B(0:N_TERM).\n!\n implicit none\n!\n integer max_term\n!\n integer b(0:max_term)\n integer k\n integer n\n integer n_term\n integer p\n integer q\n integer r\n integer s\n!\n n_term = 0\n\n call i_sqrt ( n, s, r )\n b(0) = s\n\n if ( r > 0 ) then\n\n p = 0\n q = 1\n\n do\n\n p = b(n_term) * q - p\n q = ( n - p**2 ) / q\n\n if ( n_term >= max_term ) then\n return\n end if\n\n n_term = n_term + 1\n b(n_term) = ( p + s ) / q\n\n if ( q == 1 ) then\n exit\n end if\n\n end do\n\n end if\n\n return\nend\nsubroutine i_swap ( i, j )\n!\n!*******************************************************************************\n!\n!! I_SWAP switches two integer values.\n!\n!\n! Modified:\n!\n! 30 November 1998\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input/output, integer I, J. On output, the values of I and\n! J have been interchanged.\n!\n implicit none\n!\n integer i\n integer j\n integer k\n!\n k = i\n i = j\n j = k\n\n return\nend\nsubroutine i_to_chinese ( j, n, m, r )\n!\n!*******************************************************************************\n!\n!! I_TO_CHINESE converts an integer to its Chinese remainder form.\n!\n!\n! Discussion:\n!\n! Modified:\n!\n! 05 July 2000\n!\n! Parameters:\n!\n! Input, integer J, the integer to be converted.\n!\n! Input, integer N, the number of moduluses.\n!\n! Input, integer M(N), the moduluses. These should be positive\n! and pairwise prime.\n!\n! Output, integer R(N), the Chinese remainder representation of the integer.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer ierror\n integer i_modp\n integer j\n integer m(n)\n integer r(n)\n!\n call chinese_check ( n, m, ierror )\n\n if ( ierror /= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'I_TO_CHINESE - Fatal error!'\n write ( *, '(a)' ) ' The moduluses are not legal.'\n stop\n end if\n\n do i = 1, n\n r(i) = i_modp ( j, m(i) )\n end do\n\n return\nend\nsubroutine i_to_halton ( n, p, r )\n!\n!*******************************************************************************\n!\n!! I_TO_HALTON computes an element of a Halton sequence.\n!\n!\n! Discussion:\n!\n! The Halton sequence is often used to generate a \"subrandom\"\n! sequence of points which have a better covering property\n! than pseudorandom points.\n!\n! The Halton sequence generates a sequence of points in [0,1]\n! which (theoretically) never repeats.\n!\n! To generate a sequence of points in a 2 dimensional space,\n! it is typical practice to generate a pair of Halton sequences,\n! the first with prime base 2, the second with prime base 3.\n! Similarly, by using the first K primes, a suitable sequence\n! in K-dimensional space can be generated.\n!\n! The generation is quite simple. Given an integer N, the expansion\n! of N in base P is generated. Then, essentially, the result R\n! is generated by writing a decimal point followed by the digits of\n! the expansion of N, in reverse order. This decimal value is actually\n! still in base P, so it must be properly interpreted to generate\n! a usable value.\n!\n! Example:\n!\n! P = 2\n!\n! N N Halton Halton\n! decimal binary binary decimal\n! ------- ------ ------ -------\n! 1 = 1 => .1 = 0.5\n! 2 = 10 => .01 = 0.25\n! 3 = 11 => .11 = 0.75\n! 4 = 100 => .001 = 0.125\n! 5 = 101 => .101 = 0.625\n! 6 = 110 => .011 = 0.375\n! 7 = 111 => .111 = 0.875\n! 8 = 1000 => .0001 = 0.0625\n!\n! Reference:\n!\n! J H Halton,\n! Numerische Mathematik,\n! Volume 2, pages 84-90.\n!\n! Modified:\n!\n! 17 December 2000\n!\n! Author:\n!\n! Lili Ju\n!\n! Parameters:\n!\n! Input, integer N, the index of the desired element.\n!\n! Input, integer P, the Halton base, which should be a prime number.\n!\n! Output, real R, the N-th element of the Halton sequence\n! for base P.\n!\n implicit none\n!\n integer digit\n integer n\n integer n2\n integer p\n real pp\n real r\n!\n n2 = abs ( n )\n r = 0.0E+00\n pp = 1.0E+00 / real ( p )\n\n do while ( n2 /= 0 )\n digit = mod ( n2, p )\n r = r + digit * pp\n pp = pp / real ( p )\n n2 = n2 / p\n end do\n\n if ( n < 0 ) then\n r = - r\n end if\n\n return\nend\nsubroutine i_to_ivec_binary ( i, n, ivec )\n!\n!*******************************************************************************\n!\n!! I_TO_IVEC_BINARY makes a vector binary representation of an integer.\n!\n!\n! Example:\n!\n! I IVEC\n! -- --------------\n! 1 0,0,...0,0,0,1\n! 2 0,0,...0,0,1,0\n! 3 0,0,...0,0,1,1\n! 4 0,0,...0,1,0,0\n! 9 0,0,...1,0,0,1\n! -9 1,1,...0,1,1,1\n!\n! Discussion:\n!\n! The vector is assumed to have dimension 32. Negative values have\n! a two's complement operation applied.\n!\n! Modified:\n!\n! 08 May 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer I, an integer to be represented.\n!\n! Input, integer N, the dimension of the vector, which should be 32.\n!\n! Output, integer IVEC(N), the binary representation.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer i_copy\n integer ivec(n)\n integer j\n!\n i_copy = abs ( i )\n\n do j = n, 2, -1\n\n ivec(j) = mod ( i_copy, 2 )\n\n i_copy = i_copy / 2\n\n end do\n\n ivec(1) = 0\n\n if ( i < 0 ) then\n call ivec_binary_complement2 ( n, ivec )\n end if\n\n return\nend\nsubroutine i_to_s_left ( intval, s )\n!\n!*******************************************************************************\n!\n!! I_TO_S_LEFT converts an integer to a left-justified string.\n!\n!\n! Examples:\n!\n! Assume that S is 6 characters long:\n!\n! INTVAL S\n!\n! 1 1\n! -1 -1\n! 0 0\n! 1952 1952\n! 123456 123456\n! 1234567 ****** <-- Not enough room!\n!\n! Modified:\n!\n! 28 July 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer INTVAL, an integer to be converted.\n!\n! Output, character ( len = * ) S, the representation of the integer.\n! The integer will be left-justified. If there is not enough space,\n! the string will be filled with stars.\n!\n implicit none\n!\n character c\n integer i\n integer idig\n integer ihi\n integer ilo\n integer intval\n integer ipos\n integer ival\n character ( len = * ) s\n!\n s = ' '\n\n ilo = 1\n ihi = len ( s )\n\n if ( ihi <= 0 ) then\n return\n end if\n!\n! Make a copy of the integer.\n!\n ival = intval\n!\n! Handle the negative sign.\n!\n if ( ival < 0 ) then\n\n if ( ihi <= 1 ) then\n s(1:1) = '*'\n return\n end if\n\n ival = - ival\n s(1:1) = '-'\n ilo = 2\n\n end if\n!\n! The absolute value of the integer goes into S(ILO:IHI).\n!\n ipos = ihi\n!\n! Find the last digit of IVAL, strip it off, and stick it into the string.\n!\n do\n\n idig = mod ( ival, 10 )\n ival = ival / 10\n\n if ( ipos < ilo ) then\n do i = 1, ihi\n s(i:i) = '*'\n end do\n return\n end if\n\n call digit_to_ch ( idig, c )\n\n s(ipos:ipos) = c\n ipos = ipos - 1\n\n if ( ival == 0 ) then\n exit\n end if\n\n end do\n!\n! Shift the string to the left.\n!\n s(ilo:ilo+ihi-ipos-1) = s(ipos+1:ihi)\n s(ilo+ihi-ipos:ihi) = ' '\n\n return\nend\nsubroutine imat_01_rowcolsum ( m, n, r, c, a, ierror )\n!\n!*******************************************************************************\n!\n!! IMAT_01_ROWCOLSUM creates a 0/1 matrix with given row and column sums.\n!\n!\n! Discussion:\n!\n! Given an M vector R and N vector C, there may exist one or more\n! M by N matrices with entries that are 0 or 1, whose row sums are R\n! and column sums are C.\n!\n! For convenience, this routine requires that the entries of R and C\n! be given in nonincreasing order.\n!\n! There are several requirements on R and C. The simple requirements\n! are that the entries of R and C must be nonnegative, that the entries\n! of R must each be no greater than N, and those of C no greater than M,\n! and that the sum of the entries of R must equal the sum of the entries \n! of C.\n!\n! The final technical requirement is that if we form R*, the conjugate\n! partition of R, then C is majorized by R*, that is, that every partial\n! sum from 1 to K of the entries of C is no bigger than the sum of the same\n! entries of R*, for every K from 1 to N.\n!\n! Given these conditions on R and C, there is at least one 0/1 matrix\n! with the given row and column sums.\n!\n! The conjugate partition of R is constructed as follows:\n! R*(1) is the number of entries of R that are 1 or greater.\n! R*(2) is the number of entries of R that are 2 or greater.\n! ...\n! R*(N) is the number of entries of R that are N (can't be greater).\n!\n! Example:\n!\n! M = N = 5\n! R = ( 3, 2, 2, 1, 1 )\n! C = ( 2, 2, 2, 2, 1 )\n!\n! A =\n! 1 0 1 0 1\n! 1 0 0 1 0\n! 0 1 0 1 0\n! 0 1 0 0 0\n! 0 0 1 0 0\n!\n! Reference:\n!\n! J H van Lint and R M Wilson,\n! A Course in Combinatorics,\n! Oxford, 1992, pages 148-156.\n!\n! James Sandeson,\n! Testing Ecological Patterns,\n! American Scientist,\n! Volume 88, July-August 2000, pages 332-339.\n!\n! Ian Saunders,\n! Algorithm AS 205,\n! Enumeration of R x C Tables with Repeated Row Totals,\n! Applied Statistics,\n! Volume 33, Number 3, pages 340-352, 1984.\n!\n! Modified:\n!\n! 26 July 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer M, N, the number of rows and columns in the array.\n!\n! Input, integer R(M), C(N), the row and column sums desired for the array.\n! Both vectors must be arranged in descending order.\n! The elements of R must be between 0 and N.\n! The elements of C must be between 0 and M.\n!\n! Output, integer A(M,N), the M by N matrix with the given row and\n! column sums.\n! Each entry of A is 0 or 1.\n!\n! Output, integer IERROR, an error flag.\n! 0, no error was encountered, and the array was computed.\n! 1, R and C do not have the same total.\n! 2, R is not monotone decreasing, or has illegal entries.\n! 3, C is not monotone decreasing, or has illegal entries.\n! 4, R and C are not a possible set of row and column sums.\n!\n implicit none\n!\n integer m\n integer n\n!\n integer a(m,n)\n integer c(n)\n integer c_sum\n integer i\n integer ierror\n logical ivec_descends\n integer ivec_imax_last\n integer j\n integer k\n integer r(m)\n integer r_conj(n)\n integer r_sum\n integer r2(m)\n!\n a(1:m,1:n) = 0\n!\n! Check conditions.\n!\n ierror = 0\n\n if ( sum ( r(1:m) ) /= sum ( c(1:n) ) ) then\n ierror = 1\n return\n end if\n\n if ( .not. ivec_descends ( m, r ) ) then\n ierror = 2\n return\n end if\n\n if ( r(1) > n .or. r(m) < 0 ) then\n ierror = 2\n return\n end if\n\n if ( .not. ivec_descends ( n, c ) ) then\n ierror = 3\n return\n end if\n\n if ( c(1) > m .or. c(n) < 0 ) then\n ierror = 3\n return\n end if\n!\n! Compute the conjugate of R.\n!\n r_conj(1:n) = 0\n\n do i = 1, m\n do j = 1, r(i)\n r_conj(j) = r_conj(j) + 1\n end do\n end do\n!\n! C must be majorized by R_CONJ.\n!\n r_sum = 0\n c_sum = 0\n do i = 1, n\n r_sum = r_sum + r_conj(i)\n c_sum = c_sum + c(i)\n if ( c_sum > r_sum ) then\n ierror = 4\n return\n end if\n end do\n!\n! We need a temporary copy of R that we can decrement.\n!\n r2(1:m) = r(1:m)\n\n do j = n, 1, -1\n\n i = ivec_imax_last ( m, r2 )\n\n do k = 1, c(j)\n!\n! By adding 1 rather than setting A(I,J) to 1, we were able to spot\n! an error where the index was \"sticking\".\n!\n a(i,j) = a(i,j) + 1\n\n r2(i) = r2(i) - 1\n!\n! There's a special case you have to watch out for.\n! If I was 1, and when you decrement R2(1), I is going to be 1 again,\n! and you're staying in the same column, that's not good.\n!\n if ( i > 1 ) then\n i = i - 1\n else\n i = ivec_imax_last ( m, r2 )\n if ( i == 1 .and. k < c(j) ) then\n i = 1 + ivec_imax_last ( m-1, r2(2:m) )\n end if\n end if\n\n end do\n\n end do\n\n return\nend\nsubroutine imat_01_rowcolsum2 ( m, n, r, c, a, ierror )\n!\n!*******************************************************************************\n!\n!! IMAT_01_ROWCOLSUM2 creates a 0/1 matrix with given row and column sums.\n!\n!\n! Discussion:\n!\n! This routine uses network flow optimization to compute the results.\n!\n! Given an M vector R and N vector C, there may exist one or more\n! M by N matrices with entries that are 0 or 1, whose row sums are R\n! and column sums are C.\n!\n! For convenience, this routine requires that the entries of R and C\n! be given in nonincreasing order.\n!\n! There are several requirements on R and C. The simple requirements\n! are that the entries of R and C must be nonnegative, that the entries\n! of R must each no greater than N, and those of C no greater than M,\n! and that the sum of the entries of R must equal the sum of the \n! entries of C.\n!\n! The final technical requirement is that if we form R*, the conjugate\n! partition of R, then C is majorized by R*, that is, that every partial\n! sum from 1 to K of the entries of C is no bigger than the sum of the same\n! entries of R*, for every K from 1 to N.\n!\n! Given these conditions on R and C, there is at least one 0/1 matrix\n! with the given row and column sums.\n!\n! The conjugate partition of R is constructed as follows:\n! R*(1) is the number of entries of R that are 1 or greater.\n! R*(2) is the number of entries of R that are 2 or greater.\n! ...\n! R*(N) is the number of entries of R that are N (can't be greater).\n!\n! Example:\n!\n! M = N = 5\n! R = ( 3, 2, 2, 1, 1 )\n! C = ( 2, 2, 2, 2, 1 )\n!\n! A =\n! 1 0 1 0 1\n! 1 0 0 1 0\n! 0 1 0 1 0\n! 0 1 0 0 0\n! 0 0 1 0 0\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! J H van Lint and R M Wilson,\n! A Course in Combinatorics,\n! Oxford, 1992, pages 148-156.\n!\n! James Sandeson,\n! Testing Ecological Patterns,\n! American Scientist,\n! Volume 88, July-August 2000, pages 332-339.\n!\n! Modified:\n!\n! 27 July 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer M, N, the number of rows and columns in the array.\n! These values do not have to be equal.\n!\n! Input, integer R(M), C(N), the row and column sums desired for the array.\n! Both vectors must be arranged in descending order.\n! The elements of R must be between 0 and N.\n! The elements of C must be between 0 and M.\n! One of the conditions for a solution to exist is that the sum of the\n! elements in R equal the sum of the elements in C.\n!\n! Output, integer A(M,N), the matrix with the given row and column sums.\n! Each entry of A is 0 or 1.\n!\n! Output, integer IERROR, an error flag.\n! 0, no error was encountered, and the array was computed.\n! 1, R and C are not consistent. A partial solution may be constructed.\n!\n implicit none\n!\n integer m\n integer n\n!\n integer a(m,n)\n integer c(n)\n integer capflo(2,2*(m+m*n+n))\n integer flow(2*(m+m*n+n))\n integer i\n integer icut(m+n+2)\n integer iendpt(2,2*(m+m*n+n))\n integer ierror\n integer isink\n integer isorce\n integer j\n integer k\n integer nedge\n integer nnode\n integer node_flow(m+n+2)\n integer r(m)\n!\n ierror = 0\n!\n! There are M + N + 2 nodes. The last two are the special source and sink.\n!\n isorce = m + n + 1\n isink = m + n + 2\n nnode = m + n + 2\n!\n! The source is connected to each of the R nodes.\n!\n k = 0\n\n do i = 1, m\n\n k = k + 1\n iendpt(1,k) = isorce\n iendpt(2,k) = i\n capflo(1,k) = r(i)\n capflo(2,k) = 0\n\n k = k + 1\n iendpt(1,k) = i\n iendpt(2,k) = isorce\n capflo(1,k) = r(i)\n capflo(2,k) = 0\n\n end do\n!\n! Every R node is connected to every C node, with capacity 1.\n!\n do i = 1, m\n do j = 1, n\n\n k = k + 1\n iendpt(1,k) = i\n iendpt(2,k) = j+m\n capflo(1,k) = 1\n capflo(2,k) = 0\n\n k = k + 1\n iendpt(1,k) = j+m\n iendpt(2,k) = i\n capflo(1,k) = 1\n capflo(2,k) = 0\n\n end do\n end do\n!\n! Every C node is connected to the sink.\n!\n do j = 1, n\n\n k = k + 1\n iendpt(1,k) = j+m\n iendpt(2,k) = isink\n capflo(1,k) = c(j)\n capflo(2,k) = 0\n\n k = k + 1\n iendpt(1,k) = isink\n iendpt(2,k) = j+m\n capflo(1,k) = c(j)\n capflo(2,k) = 0\n\n end do\n!\n! Determine the maximum flow on the network.\n!\n nedge = k\n\n call network_flow_max ( nnode, nedge, iendpt, capflo, isorce, isink, &\n icut, node_flow )\n!\n! We have a perfect solution if, and only if, the edges leading from the\n! source, and the edges leading to the sink, are all saturated.\n!\n do k = 1, nedge\n\n i = iendpt(1,k)\n j = iendpt(2,k) - m\n\n if ( i <= m .and. 1 <= j .and. j <= n ) then\n if ( capflo(2,k) /= 0 .and. capflo(2,k) /= 1 ) then\n ierror = 1\n end if\n end if\n\n if ( iendpt(1,k) == isorce ) then\n if ( capflo(1,k) /= capflo(2,k) ) then\n ierror = 1\n end if\n end if\n\n if ( iendpt(2,k) == isink ) then\n if ( capflo(1,k) /= capflo(2,k) ) then\n ierror = 1\n end if\n end if\n\n end do\n!\n! If we have a solution, then A(I,J) = the flow on the edge from\n! R node I to C node J.\n!\n a(1:m,1:n) = 0\n\n do k = 1, nedge\n\n i = iendpt(1,k)\n j = iendpt(2,k) - m\n\n if ( i <= m .and. 1 <= j .and. j <= n ) then\n a(i,j) = capflo(2,k)\n end if\n\n end do\n\n return\nend\nsubroutine imat_inverse ( n, a, b )\n!\n!*******************************************************************************\n!\n!! IMAT_INVERSE inverts a unit upper triangular matrix.\n!\n!\n! Discussion:\n!\n! A unit upper triangular matrix is a matrix with only 1's on the main\n! diagonal, and only 0's below the main diagonal. Above the main\n! diagonal, the entries may be assigned any value.\n!\n! It may be surprising to note that the inverse of an integer unit upper\n! triangular matrix is also an integer unit upper triangular matrix.\n!\n! Note that this routine can invert a matrix in place, that is, with no\n! extra storage. If the matrix is stored in A, then the call\n!\n! call imat_inverse ( n, a, a )\n!\n! will result in A being overwritten by its inverse, which can\n! save storage if the original value of A is not needed later.\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 05 March 1999\n!\n! Parameters:\n!\n! Input, integer N, number of rows and columns in matrix.\n!\n! Input, integer A(N,N). Unit upper triangular matrix\n! to be inverted.\n!\n! Output, integer B(N,N), the inverse matrix.\n!\n implicit none\n!\n integer n\n!\n integer a(n,n)\n integer b(n,n)\n integer i\n integer isum\n integer j\n integer k\n!\n do j = n, 1, -1\n\n do i = n, 1, -1\n\n if ( i == j ) then\n isum = 1\n else\n isum = 0\n end if\n\n do k = i + 1, j\n isum = isum - a(i,k) * b(k,j)\n end do\n\n b(i,j) = isum\n\n end do\n end do\n\n return\nend\nsubroutine imat_perm ( n, a, p )\n!\n!*******************************************************************************\n!\n!! IMAT_PERM permutes the rows and columns of a square integer matrix.\n!\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 27 July 2000\n!\n! Parameters:\n!\n! Input, integer N, the order of the matrix.\n!\n! Input/output, integer A(N,N).\n! On input, the matrix to be permuted.\n! On output, the permuted matrix.\n!\n! Input, integer P(N), the permutation. P(I) is the new number of row\n! and column I.\n!\n implicit none\n!\n integer n\n!\n integer a(n,n)\n integer i\n integer i1\n integer is\n integer it\n integer j\n integer j1\n integer j2\n integer k\n integer lc\n integer nc\n integer p(n)\n!\n call perm_cycle ( n, p, is, nc, 1 )\n\n do i = 1, n\n\n i1 = - p(i)\n\n if ( i1 > 0 ) then\n\n lc = 0\n\n do\n\n i1 = p(i1)\n lc = lc + 1\n\n if ( i1 <= 0 ) then\n exit\n end if\n\n end do\n\n i1 = i\n\n do j = 1, n\n\n if ( p(j) <= 0 ) then\n\n j2 = j\n k = lc\n\n do\n\n j1 = j2\n it = a(i1,j1)\n\n do\n\n i1 = abs ( p(i1) )\n j1 = abs ( p(j1) )\n\n call i_swap ( a(i1,j1), it )\n\n if ( j1 /= j2 ) then\n cycle\n end if\n\n k = k - 1\n\n if ( i1 == i ) then\n exit\n end if\n\n end do\n\n j2 = abs ( p(j2) )\n\n if ( k == 0 ) then\n exit\n end if\n\n end do\n\n end if\n\n end do\n\n end if\n\n end do\n!\n! Restore the positive signs of the data.\n!\n p(1:n) = abs ( p(1:n) )\n\n return\nend\nsubroutine imat_perm2 ( m, n, a, p, q )\n!\n!*******************************************************************************\n!\n!! IMAT_PERM2 permutes the rows and columns of a rectangular integer matrix.\n!\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 28 October 1999\n!\n! Parameters:\n!\n! Input, integer M, number of rows in the matrix.\n!\n! Input, integer N, number of columns in the matrix.\n!\n! Input/output, integer A(M,N).\n! On input, the matrix to be permuted.\n! On output, the permuted matrix.\n!\n! Input, integer P(M), the row permutation. P(I) is the new number of row I.\n!\n! Input, integer Q(N). The column permutation. Q(I) is the new number\n! of column I. Note that this routine allows you to pass a single array\n! as both P and Q.\n!\n implicit none\n!\n integer m\n integer n\n!\n integer a(m,n)\n integer i\n integer i1\n integer is\n integer it\n integer j\n integer j1\n integer j2\n integer k\n integer lc\n integer nc\n integer p(m)\n integer q(n)\n!\n call perm_cycle ( m, p, is, nc, 1 )\n\n if ( q(1) > 0 ) then\n call perm_cycle ( n, q, is, nc, 1 )\n end if\n\n do i = 1, m\n\n i1 = - p(i)\n\n if ( i1 > 0 ) then\n\n lc = 0\n\n do\n\n i1 = p(i1)\n lc = lc + 1\n\n if ( i1 <= 0 ) then\n exit\n end if\n\n end do\n\n i1 = i\n\n do j = 1, n\n\n if ( q(j) <= 0 ) then\n\n j2 = j\n k = lc\n\n do\n\n j1 = j2\n it = a(i1,j1)\n\n do\n\n i1 = abs ( p(i1) )\n j1 = abs ( q(j1) )\n\n call i_swap ( a(i1,j1), it )\n\n if ( j1 /= j2 ) then\n cycle\n end if\n\n k = k - 1\n\n if ( i1 == i ) then\n exit\n end if\n\n end do\n\n j2 = abs ( q(j2) )\n\n if ( k == 0 ) then\n exit\n end if\n\n end do\n\n end if\n\n end do\n\n end if\n\n end do\n!\n! Restore the positive signs of the data.\n!\n p(1:m) = abs ( p(1:m) )\n\n if ( q(1) <= 0 ) then\n q(1:n) = abs ( q(1:n) )\n end if\n\n return\nend\nsubroutine imat_print ( m, n, a, title )\n!\n!*******************************************************************************\n!\n!! IMAT_PRINT prints an integer matrix.\n!\n!\n! Modified:\n!\n! 08 May 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer M, the number of rows in A.\n!\n! Input, integer N, the number of columns in A.\n!\n! Input, integer A(M,N), the matrix to be printed.\n!\n! Input, character ( len = * ) TITLE, a title to be printed first.\n! TITLE may be blank.\n!\n implicit none\n!\n integer m\n integer n\n!\n integer a(m,n)\n integer i\n integer j\n integer jhi\n integer jlo\n character ( len = * ) title\n!\n if ( title /= ' ' ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) title\n end if\n\n do jlo = 1, n, 10\n jhi = min ( jlo + 9, n )\n write ( *, '(a)' ) ' '\n write ( *, '(6x,10(i7))' ) ( j, j = jlo, jhi )\n write ( *, '(a)' ) ' '\n do i = 1, m\n write ( *, '(i6,10i7)' ) i, a(i,jlo:jhi)\n end do\n end do\n\n return\nend\nsubroutine index_box2_next_2d ( n1, n2, ic, jc, i, j, more )\n!\n!*******************************************************************************\n!\n!! INDEX_BOX2_NEXT_2D produces indices on the surface of a box in 2D.\n!\n!\n! Discussion:\n!\n! The box is has center at (IC,JC), and has half-widths N1 and N2.\n! The indices are exactly those which are between (IC-N1,JC-N1) and\n! (IC+N1,JC+N2) with the property that at least one of I and J\n! is an \"extreme\" value.\n!\n! Modified:\n!\n! 14 February 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N1, N2, the half-widths of the box, that is, the\n! maximum distance allowed between (IC,JC) and (I,J).\n!\n! Input, integer IC, JC, the central cell of the box.\n!\n! Input/output, integer I, J. On input, the previous index set.\n! On output, the next index set. On the first call, MORE should\n! be set to FALSE, and the input values of I and J are ignored.\n!\n! Input/output, logical MORE.\n! On the first call for a given box, the user should set MORE to FALSE.\n! On return, the routine sets MORE to TRUE.\n! When there are no more indices, the routine sets MORE to FALSE.\n!\n implicit none\n!\n integer i\n integer ic\n integer j\n integer jc\n logical more\n integer n1\n integer n2\n!\n if ( .not. more ) then\n more = .true.\n i = ic - n1\n j = jc - n2\n return\n end if\n\n if ( i == ic + n1 .and. j == jc + n2 ) then\n more = .false.\n return\n end if\n!\n! Increment J.\n!\n j = j + 1\n!\n! Check J.\n!\n if ( j > jc + n2 ) then\n j = jc - n2\n i = i + 1\n else if ( j < jc + n2 .and. ( i == ic - n1 .or. i == ic + n1 ) ) then\n return\n else\n j = jc + n2\n return\n end if\n\n return\nend\nsubroutine index_box2_next_3d ( n1, n2, n3, ic, jc, kc, i, j, k, more )\n!\n!*******************************************************************************\n!\n!! INDEX_BOX2_NEXT_3D produces indices on the surface of a box in 3D.\n!\n!\n! Discussion:\n!\n! The box has a central cell of (IC,JC,KC), with a half widths of\n! (N1,N2,N3). The indices are exactly those between (IC-N1,JC-N2,KC-N3) and\n! (IC+N1,JC+N2,KC+N3) with the property that at least one of I, J, and K\n! is an \"extreme\" value.\n!\n! Modified:\n!\n! 14 February 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N1, N2, N3, the \"half widths\" of the box, that is, the\n! maximum distances from the central cell allowed for I, J and K.\n!\n! Input, integer IC, JC, KC, the central cell of the box.\n!\n! Input/output, integer I, J, K. On input, the previous index set.\n! On output, the next index set. On the first call, MORE should\n! be set to FALSE, and the input values of I, J, and K are ignored.\n!\n! Input/output, logical MORE.\n! On the first call for a given box, the user should set MORE to FALSE.\n! On return, the routine sets MORE to TRUE.\n! When there are no more indices, the routine sets MORE to FALSE.\n!\n implicit none\n!\n integer i\n integer ic\n integer j\n integer jc\n integer k\n integer kc\n logical more\n integer n1\n integer n2\n integer n3\n!\n if ( .not. more ) then\n more = .true.\n i = ic - n1\n j = jc - n2\n k = kc - n3\n return\n end if\n\n if ( i == ic + n1 .and. j == jc + n2 .and. k == kc + n3 ) then\n more = .false.\n return\n end if\n!\n! Increment K.\n!\n k = k + 1\n!\n! Check K.\n!\n if ( k > kc + n3 ) then\n k = kc - n3\n j = j + 1\n else if ( k < kc + n3 .and. &\n ( i == ic - n1 .or. i == ic + n1 .or. &\n j == jc - n2 .or. j == jc + n2 ) ) then\n return\n else\n k = kc + n3\n return\n end if\n!\n! Check J.\n!\n if ( j > jc + n2 ) then\n j = jc - n2\n i = i + 1\n else if ( j < jc + n2 .and. &\n ( i == ic - n1 .or. i == ic + n1 .or. &\n k == kc - n3 .or. k == kc + n3 ) ) then\n return\n else\n j = jc + n2\n return\n end if\n\n return\nend\nsubroutine index_box_next_2d ( n1, n2, i, j, more )\n!\n!*******************************************************************************\n!\n!! INDEX_BOX_NEXT_2D produces indices on the surface of a box in 2D.\n!\n!\n! Discussion:\n!\n! The indices are exactly those which are between (1,1) and\n! (N1,N2) with the property that at least one of I and J\n! is an \"extreme\" value.\n!\n! Modified:\n!\n! 13 February 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N1, N2, the \"dimensions\" of the box, that is, the\n! maximum values allowed for I and J. The minimum values are\n! assumed to be 1.\n!\n! Input/output, integer I, J. On input, the previous index set.\n! On output, the next index set. On the first call, MORE should\n! be set to FALSE, and the input values of I and J are ignored.\n!\n! Input/output, logical MORE.\n! On the first call for a given box, the user should set MORE to FALSE.\n! On return, the routine sets MORE to TRUE.\n! When there are no more indices, the routine sets MORE to FALSE.\n!\n implicit none\n!\n integer i\n integer j\n logical more\n integer n1\n integer n2\n!\n if ( .not. more ) then\n more = .true.\n i = 1\n j = 1\n return\n end if\n\n if ( i == n1 .and. j == n2 ) then\n more = .false.\n return\n end if\n!\n! Increment J.\n!\n j = j + 1\n!\n! Check J.\n!\n if ( j > n2 ) then\n j = 1\n i = i + 1\n else if ( j < n2 .and. ( i == 1 .or. i == n1 ) ) then\n return\n else\n j = n2\n return\n end if\n\n return\nend\nsubroutine index_box_next_3d ( n1, n2, n3, i, j, k, more )\n!\n!*******************************************************************************\n!\n!! INDEX_BOX_NEXT_3D produces indices on the surface of a box in 3D.\n!\n!\n! Discussion:\n!\n! The indices are exactly those which are between (1,1,1) and\n! (N1,N2,N3) with the property that at least one of I, J, and K\n! is an \"extreme\" value.\n!\n! Modified:\n!\n! 13 February 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N1, N2, N3, the \"dimensions\" of the box, that is, the\n! maximum values allowed for I, J and K. The minimum values are\n! assumed to be 1.\n!\n! Input/output, integer I, J, K. On input, the previous index set.\n! On output, the next index set. On the first call, MORE should\n! be set to FALSE, and the input values of I, J, and K are ignored.\n!\n! Input/output, logical MORE.\n! On the first call for a given box, the user should set MORE to FALSE.\n! On return, the routine sets MORE to TRUE.\n! When there are no more indices, the routine sets MORE to FALSE.\n!\n implicit none\n!\n integer i\n integer j\n integer k\n logical more\n integer n1\n integer n2\n integer n3\n!\n if ( .not. more ) then\n more = .true.\n i = 1\n j = 1\n k = 1\n return\n end if\n\n if ( i == n1 .and. j == n2 .and. k == n3 ) then\n more = .false.\n return\n end if\n!\n! Increment K.\n!\n k = k + 1\n!\n! Check K.\n!\n if ( k > n3 ) then\n k = 1\n j = j + 1\n else if ( k < n3 .and. &\n ( i == 1 .or. i == n1 .or. j == 1 .or. j == n2 ) ) then\n return\n else\n k = n3\n return\n end if\n!\n! Check J.\n!\n if ( j > n2 ) then\n j = 1\n i = i + 1\n else if ( j < n2 .and. &\n ( i == 1 .or. i == n1 .or. k == 1 .or. k == n3 ) ) then\n return\n else\n j = n2\n return\n end if\n\n return\nend\nsubroutine index_next0 ( n, hi, iarray, more )\n!\n!*******************************************************************************\n!\n!! INDEX_NEXT0 generates all indices within given upper limits.\n!\n!\n! Discussion:\n!\n! The indices are generated in such a way that the reversed\n! sequences are produced in lexicographic order.\n!\n! Example:\n!\n! N = 3,\n! HI = 3\n!\n! 1 2 3\n! ---------\n! 1 1 1\n! 2 1 1\n! 3 1 1\n! 1 2 1\n! 2 2 1\n! 3 2 1\n! 1 3 1\n! 2 3 1\n! 3 3 1\n! 1 1 2\n! 2 1 2\n! 3 1 2\n! 1 2 2\n! 2 2 2\n! 3 2 2\n! 1 3 2\n! 2 3 2\n! 3 3 2\n! 1 1 3\n! 2 1 3\n! 3 1 3\n! 1 2 3\n! 2 2 3\n! 3 2 3\n! 1 3 3\n! 2 3 3\n! 3 3 3\n!\n! Modified:\n!\n! 05 July 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of entries in IARRAY.\n!\n! Input, integer HI, the upper limit for the array indices.\n! The lower limit is implicitly 1 and HI must be at least 1.\n!\n! Input/output, integer IARRAY(N).\n! On startup calls, with MORE = .FALSE., the input value of IARRAY\n! doesn't matter, because the routine initializes it.\n! On calls with MORE = .TRUE., the input value of IARRAY must be\n! the output value of IARRAY from the previous call. (In other words,\n! just leave it alone!).\n! On output, IARRAY contains the successor set of indices to the input\n! value.\n!\n! Input/output, logical MORE. Set this variable .FALSE. before\n! the first call. Normally, MORE will be returned .TRUE. but\n! once all the vectors have been generated, MORE will be\n! reset .FALSE. and you should stop calling the program.\n!\n implicit none\n!\n integer n\n!\n integer hi\n integer i\n integer iarray(n)\n integer inc\n logical more\n!\n if ( .not. more ) then\n\n iarray(1:n) = 1\n\n if ( hi < 1 ) then\n more = .false.\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'INDEX_NEXT0 - Fatal error!'\n write ( *, '(a,i6)' ) ' HI is ', hi\n write ( *, '(a)' ) ' but HI must be at least 1.'\n return\n end if\n\n else\n\n inc = 1\n\n do while ( iarray(inc) >= hi )\n iarray(inc) = 1\n inc = inc + 1\n end do\n\n iarray(inc) = iarray(inc) + 1\n\n end if\n!\n! See if there are more entries to compute.\n!\n more = .false.\n\n do i = 1, n\n if ( iarray(i) < hi ) then\n more = .true.\n end if\n end do\n\n return\nend\nsubroutine index_next1 ( n, hi, iarray, more )\n!\n!*******************************************************************************\n!\n!! INDEX_NEXT1 generates all indices within given upper limits.\n!\n!\n! Discussion:\n!\n! The indices are generated in such a way that the reversed\n! sequences are produced in lexicographic order.\n!\n! Example:\n!\n! N = 3,\n! HI(1) = 4, HI(2) = 2, HI(3) = 3\n!\n! 1 2 3\n! ---------\n! 1 1 1\n! 2 1 1\n! 3 1 1\n! 4 1 1\n! 1 2 1\n! 2 2 1\n! 3 2 1\n! 4 2 1\n! 1 1 2\n! 2 1 2\n! 3 1 2\n! 4 1 2\n! 1 2 2\n! 2 2 2\n! 3 2 2\n! 4 2 2\n! 1 1 3\n! 2 1 3\n! 3 1 3\n! 4 1 3\n! 1 2 3\n! 2 2 3\n! 3 2 3\n! 4 2 3\n!\n! Modified:\n!\n! 27 June 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of entries in IARRAY.\n!\n! Input, integer HI(N), the upper limits for the array indices.\n! The lower limit is implicitly 1, and each HI(I) should be at least 1.\n!\n! Input/output, integer IARRAY(N).\n! On startup calls, with MORE = .FALSE., the input value of IARRAY\n! doesn't matter, because the routine initializes it.\n! On calls with MORE = .TRUE., the input value of IARRAY must be\n! the output value of IARRAY from the previous call. (In other words,\n! just leave it alone!).\n! On output, IARRAY contains the successor set of indices to the input\n! value.\n!\n! Input/output, logical MORE. Set this variable .FALSE. before\n! the first call. Normally, MORE will be returned .TRUE. but\n! once all the vectors have been generated, MORE will be\n! reset .FALSE. and you should stop calling the program.\n!\n implicit none\n!\n integer n\n!\n integer hi(n)\n integer i\n integer iarray(n)\n integer inc\n logical more\n!\n if ( .not. more ) then\n\n iarray(1:n) = 1\n\n do i = 1, n\n if ( hi(i) < 1 ) then\n more = .false.\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'INDEX_NEXT1 - Fatal error!'\n write ( *, '(a,i6,a,i6)' ) ' Entry ', i, ' of HI is ', hi(i)\n write ( *, '(a)' ) ' but all entries must be at least 1.'\n return\n end if\n end do\n\n else\n\n inc = 1\n\n do while ( iarray(inc) >= hi(inc) )\n iarray(inc) = 1\n inc = inc + 1\n end do\n\n iarray(inc) = iarray(inc) + 1\n\n end if\n!\n! See if there are more entries to compute.\n!\n more = .false.\n\n do i = 1, n\n if ( iarray(i) < hi(i) ) then\n more = .true.\n end if\n end do\n\n return\nend\nsubroutine index_next2 ( n, lo, hi, iarray, more )\n!\n!*******************************************************************************\n!\n!! INDEX_NEXT2 generates all indices within given lower and upper limits.\n!\n!\n! Example:\n!\n! N = 3,\n! LO(1) = 1, LO(2) = 10, LO(3) = 4\n! HI(1) = 2, HI(2) = 11, HI(3) = 6\n!\n! 1 2 3\n! ---------\n! 1 10 4\n! 2 10 4\n! 1 11 4\n! 2 11 4\n! 1 10 5\n! 2 10 5\n! 1 11 5\n! 2 11 5\n! 1 10 6\n! 2 10 6\n! 1 11 6\n! 2 11 6\n!\n! Modified:\n!\n! 21 July 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of entries in IARRAY. The rank of\n! the object being indexed.\n!\n! Input, integer LO(N), HI(N), the lower and upper limits for the array\n! indices. LO(I) should be less than or equal to HI(I), for each I.\n!\n! Input/output, integer IARRAY(N).\n! On startup calls, with MORE = .FALSE., the input value of IARRAY\n! doesn't matter, because the routine initializes it.\n! On calls with MORE = .TRUE., the input value of IARRAY must be\n! the output value of IARRAY from the previous call. (In other words,\n! just leave it alone!).\n! On output, IARRAY contains the successor set of indices to the input\n! value.\n!\n! Input/output, logical MORE. Set this variable .FALSE. before\n! the first call. Normally, MORE will be returned .TRUE. but\n! once all the vectors have been generated, MORE will be\n! reset .FALSE. and you should stop calling the program.\n!\n implicit none\n!\n integer n\n!\n integer hi(n)\n integer i\n integer iarray(n)\n integer inc\n integer lo(n)\n logical more\n!\n if ( .not. more ) then\n\n iarray(1:n) = lo(1:n)\n\n do i = 1, n\n if ( hi(i) < lo(i) ) then\n more = .false.\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'INDEX_NEXT2 - Fatal error!'\n write ( *, '(a,i6,a,i6)' ) ' Entry ', i, ' of HI is ', hi(i)\n write ( *, '(a,i6,a,i6)' ) ' Entry ', i, ' of LO is ', lo(i)\n write ( *, '(a)' ) ' but LO(I) <= HI(I) is required.'\n return\n end if\n end do\n\n else\n\n inc = 1\n\n do while ( iarray(inc) >= hi(inc) )\n iarray(inc) = lo(inc)\n inc = inc + 1\n end do\n\n iarray(inc) = iarray(inc) + 1\n\n end if\n!\n! See if there are more entries to compute.\n!\n more = .false.\n\n do i = 1, n\n if ( iarray(i) < hi(i) ) then\n more = .true.\n end if\n end do\n\n return\nend\nsubroutine index_rank0 ( n, hi, iarray, rank )\n!\n!*******************************************************************************\n!\n!! INDEX_RANK0 ranks an index within given upper limits.\n!\n!\n! Example:\n!\n! N = 3,\n! HI = 3\n! IARRAY = ( 3, 1, 2 )\n!\n! RANK = 12\n!\n! Modified:\n!\n! 05 July 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of entries in IARRAY.\n!\n! Input, integer HI, the upper limit for the array indices.\n! The lower limit is implicitly 1, and HI should be at least 1.\n!\n! Input, integer IARRAY(N), the index to be ranked.\n!\n! Output, integer RANK, the rank of the index, or -1 if IARRAY\n! is not a legal index.\n!\n implicit none\n!\n integer n\n!\n integer hi\n integer i\n integer iarray(n)\n integer range\n integer rank\n!\n rank = - 1\n do i = 1, n\n if ( iarray(i) < 1 .or. iarray(i) > hi ) then\n return\n end if\n end do\n\n rank = 0\n do i = n, 1, -1\n rank = hi * rank + iarray(i)\n end do\n\n rank = 1\n range = 1\n do i = 1, n\n rank = rank + ( iarray(i) - 1 ) * range\n range = range * hi\n end do\n\n return\nend\nsubroutine index_rank1 ( n, hi, iarray, rank )\n!\n!*******************************************************************************\n!\n!! INDEX_RANK1 ranks an index within given upper limits.\n!\n!\n! Example:\n!\n! N = 3,\n! HI(1) = 4, HI(2) = 2, HI(3) = 3\n! IARRAY = ( 4, 1, 2 )\n!\n! RANK = 12\n!\n! Modified:\n!\n! 22 July 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of entries in IARRAY.\n!\n! Input, integer HI(N), the upper limits for the array indices.\n! The lower limit is implicitly 1, and each HI(I) should be at least 1.\n!\n! Input, integer IARRAY(N), the index to be ranked.\n!\n! Output, integer RANK, the rank of the index, or -1 if IARRAY\n! is not a legal index.\n!\n implicit none\n!\n integer n\n!\n integer hi(n)\n integer i\n integer iarray(n)\n integer range\n integer rank\n!\n rank = - 1\n do i = 1, n\n if ( iarray(i) < 1 .or. iarray(i) > hi(i) ) then\n return\n end if\n end do\n\n rank = 0\n do i = n, 1, -1\n rank = hi(i) * rank + iarray(i)\n end do\n\n rank = 1\n range = 1\n do i = 1, n\n rank = rank + ( iarray(i) - 1 ) * range\n range = range * hi(i)\n end do\n\n return\nend\nsubroutine index_rank2 ( n, lo, hi, iarray, rank )\n!\n!*******************************************************************************\n!\n!! INDEX_RANK2 ranks an index within given lower and upper limits.\n!\n!\n! Example:\n!\n! N = 3,\n! LO(1) = 1, LO(2) = 10, LO(3) = 4\n! HI(1) = 2, HI(2) = 11, HI(3) = 6\n! IARRAY = ( 1, 11, 5 )\n!\n! RANK = 7\n!\n! Modified:\n!\n! 22 July 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of entries in IARRAY.\n!\n! Input, integer LO(N), HI(N), the lower and upper limits for the array\n! indices. LO(I) should be less than or equal to HI(I), for each I.\n!\n! Input, integer IARRAY(N), the index to be ranked.\n!\n! Output, integer RANK, the rank of the index, or -1 if IARRAY\n! is not a legal index.\n!\n implicit none\n!\n integer n\n!\n integer hi(n)\n integer i\n integer iarray(n)\n integer lo(n)\n integer range\n integer rank\n!\n rank = - 1\n do i = 1, n\n if ( iarray(i) < lo(i) .or. iarray(i) > hi(i) ) then\n return\n end if\n end do\n\n rank = 1\n range = 1\n do i = 1, n\n rank = rank + ( iarray(i) - lo(i) ) * range\n range = range * ( hi(i) + 1 - lo(i) )\n end do\n\n return\nend\nsubroutine index_unrank0 ( n, hi, rank, iarray )\n!\n!*******************************************************************************\n!\n!! INDEX_UNRANK0 unranks an index within given upper limits.\n!\n!\n! Example:\n!\n! N = 3,\n! HI = 3\n! RANK = 12\n!\n! IARRAY = ( 3, 1, 2 )\n!\n! Modified:\n!\n! 05 July 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of entries in IARRAY.\n!\n! Input, integer HI, the upper limit for the array indices.\n! The lower limit is implicitly 1, and HI should be at least 1.\n!\n! Input, integer RANK, the rank of the desired index.\n!\n! Output, integer IARRAY(N), the index of the given rank.\n!\n implicit none\n!\n integer n\n!\n integer hi\n integer i\n integer iarray(n)\n integer j\n integer k\n integer range\n integer rank\n!\n iarray(1:n) = 0\n!\n! The rank might be too small.\n!\n if ( rank < 1 ) then\n return\n end if\n\n range = hi**n\n!\n! The rank might be too large.\n!\n if ( rank > range ) then\n return\n end if\n\n k = rank - 1\n do i = n, 1, -1\n range = range / hi\n j = k / range\n iarray(i) = j + 1\n k = k - j * range\n end do\n\n return\nend\nsubroutine index_unrank1 ( n, hi, rank, iarray )\n!\n!*******************************************************************************\n!\n!! INDEX_UNRANK1 unranks an index within given upper limits.\n!\n!\n! Example:\n!\n! N = 3,\n! HI(1) = 4, HI(2) = 2, HI(3) = 3\n! RANK = 11\n!\n! IARRAY = ( 3, 1, 2 )\n!\n! Modified:\n!\n! 24 July 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of entries in IARRAY.\n!\n! Input, integer HI(N), the upper limits for the array indices.\n! The lower limit is implicitly 1, and each HI(I) should be at least 1.\n!\n! Input, integer RANK, the rank of the desired index.\n!\n! Output, integer IARRAY(N), the index of the given rank.\n!\n implicit none\n!\n integer n\n!\n integer hi(n)\n integer i\n integer iarray(n)\n integer j\n integer k\n integer range\n integer rank\n!\n iarray(1:n) = 0\n!\n! The rank might be too small.\n!\n if ( rank < 1 ) then\n return\n end if\n\n range = product ( hi )\n!\n! The rank might be too large.\n!\n if ( rank > range ) then\n return\n end if\n\n k = rank - 1\n do i = n, 1, -1\n range = range / hi(i)\n j = k / range\n iarray(i) = j + 1\n k = k - j * range\n end do\n\n return\nend\nsubroutine index_unrank2 ( n, lo, hi, rank, iarray )\n!\n!*******************************************************************************\n!\n!! INDEX_UNRANK2 unranks an index within given lower and upper limits.\n!\n!\n! Example:\n!\n! N = 3,\n! LO(1) = 1, LO(2) = 10, LO(3) = 4\n! HI(1) = 2, HI(2) = 11, HI(3) = 6\n! RANK = 7\n!\n! IARRAY = ( 1, 11, 5 )\n!\n! Modified:\n!\n! 24 July 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of entries in IARRAY.\n!\n! Input, integer LO(N), HI(N), the lower and upper limits for the array\n! indices. It should be the case that LO(I) <= HI(I) for each I.\n!\n! Input, integer RANK, the rank of the desired index.\n!\n! Output, integer IARRAY(N), the index of the given rank.\n!\n implicit none\n!\n integer n\n!\n integer hi(n)\n integer i\n integer iarray(n)\n integer j\n integer k\n integer lo(n)\n integer range\n integer rank\n!\n iarray(1:n) = 0\n!\n! The rank might be too small.\n!\n if ( rank < 1 ) then\n return\n end if\n\n range = 1\n do i = 1, n\n range = range * ( hi(i) + 1 - lo(i) )\n end do\n!\n! The rank might be too large.\n!\n if ( rank > range ) then\n return\n end if\n\n k = rank - 1\n do i = n, 1, -1\n range = range / ( hi(i) + 1 - lo(i) )\n j = k / range\n iarray(i) = j + lo(i)\n k = k - j * range\n end do\n\n return\nend\nsubroutine ins_perm ( n, ins, p )\n!\n!*******************************************************************************\n!\n!! INS_PERM computes a permutation from its inversion sequence.\n!\n!\n! Definition:\n!\n! For a given permutation P acting on objects 1 through N, the\n! inversion sequence INS is defined as:\n!\n! INS(1) = 0\n! INS(I) = number of values J < I for which P(J) > P(I).\n!\n! Example:\n!\n! Input:\n!\n! ( 0, 0, 2, 1, 3 )\n!\n! Output:\n!\n! ( 3, 5, 1, 4, 2 )\n!\n! Reference:\n!\n! Dennis Stanton and Dennis White,\n! Constructive Combinatorics,\n! Springer Verlag, New York, 1986.\n!\n! Modified:\n!\n! 17 July 1998\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of objects being permuted.\n!\n! Input, integer INS(N), the inversion sequence of a permutation.\n! It must be the case that 0 <= INS(I) < I for I = 1 to N.\n!\n! Output, integer P(N), the permutation.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer ins(n)\n integer itemp\n integer j\n integer p(n)\n!\n call ivec_identity ( n, p )\n\n do i = n, 2, -1\n\n itemp = p(i-ins(i))\n\n do j = i-ins(i), i-1\n p(j) = p(j+1)\n end do\n\n p(i) = itemp\n\n end do\n\n return\nend\nsubroutine intp_conj ( iarray1, mult1, npart1, iarray2, mult2, npart2, n )\n!\n!*******************************************************************************\n!\n!! INTP_CONJ computes the conjugate of a partition.\n!\n!\n! Definition:\n!\n! A partition of an integer N is a set of positive integers which\n! add up to N. The conjugate of a partition P1 of N is another partition\n! P2 of N obtained in the following way:\n!\n! The first element of P2 is the number of parts of P1 greater than\n! or equal to 1.\n!\n! The K-th element of P2 is the number of parts of P1 greater than\n! or equal to K.\n!\n! Clearly, P2 will have no more than N elements; it may be surprising\n! to find that P2 is guaranteed to be a partition of N. However, if\n! we symbolize the initial partition P1 by rows of X's, then we can\n! see that P2 is simply produced by grouping by columns:\n!\n! 6 3 2 2 1\n! 5 X X X X X\n! 4 X X X X\n! 2 X X\n! 1 X\n! 1 X\n! 1 X\n!\n! Example:\n!\n! 14 = 5 + 4 + 2 + 1 + 1 + 1\n!\n! The conjugate partition is:\n!\n! 14 = 6 + 3 + 2 + 2 + 1\n!\n! Modified:\n!\n! 20 May 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters\n!\n! Input, integer IARRAY1(NPART1). IARRAY1 contains the parts of\n! the partition. The value of N is represented by\n!\n! sum ( 1 <= I <= NPART1 ) MULT1(I) * IARRAY1(I).\n!\n! Intput, integer MULT1(NPART1). MULT1 counts the multiplicity of\n! the parts of the partition. MULT1(I) is the multiplicity\n! of the part IARRAY1(I), for I = 1 to NPART1.\n!\n! Input, integer N, the integer to be partitioned.\n!\n! Input, integer NPART1, the number of \"parts\" in the partition.\n!\n! Output, integer IARRAY2(N). IARRAY contains the parts of\n! the conjugate partition in entries 1 through NPART2.\n!\n! Output, integer MULT2(N). MULT2 counts the multiplicity of\n! the parts of the conjugate partition in entries 1 through NPART2.\n!\n! Output, integer NPART2, the number of \"parts\" in the conjugate partition.\n!\n! Input, integer N, the integer to be partitioned.\n!\n implicit none\n!\n integer n\n integer npart1\n!\n integer i\n integer iarray1(npart1)\n integer iarray2(n)\n integer itemp\n integer itest\n integer mult1(npart1)\n integer mult2(n)\n integer npart2\n!\n iarray2(1:n) = 0\n mult2(1:n) = 0\n npart2 = 0\n\n itest = 0\n\n do\n\n itest = itest + 1\n\n itemp = 0\n\n do i = 1, npart1\n if ( iarray1(i) >= itest ) then\n itemp = itemp + mult1(i)\n end if\n end do\n\n if ( itemp <= 0 ) then\n exit\n end if\n\n if ( npart2 > 0 ) then\n if ( itemp == iarray2(npart2) ) then\n mult2(npart2) = mult2(npart2) + 1\n else\n npart2 = npart2 + 1\n iarray2(npart2) = itemp\n mult2(npart2) = 1\n end if\n else\n npart2 = npart2 + 1\n iarray2(npart2) = itemp\n mult2(npart2) = 1\n end if\n\n end do\n\n return\nend\nsubroutine intp_enum ( n, p )\n!\n!*******************************************************************************\n!\n!! INTP_ENUM computes the number of partitions of an integer.\n!\n!\n! Method:\n!\n! Partition numbers are difficult to compute. This routine uses\n! Euler's method, which observes that:\n!\n! P(0) = 1\n! P(N) = P(N-1) + P(N-2)\n! - P(N-5) - P(N-7)\n! + P(N-12) + P(N-15)\n! - ...\n! where the numbers subtracted from N are the pentagonal numbers,\n! (with both positive and negative indices) with the computation\n! stopping when a negative index is reached.\n!\n! First values:\n!\n! N P\n!\n! 0 1\n! 1 1\n! 2 2\n! 3 3\n! 4 5\n! 5 7\n! 6 11\n! 7 15\n! 8 22\n! 9 30\n! 10 42\n!\n! Reference:\n!\n! John Conway and Richard Guy,\n! The Book of Numbers,\n! Springer Verlag, 1996, page 95.\n!\n! Modified:\n!\n! 18 July 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the index of the highest partition number desired.\n!\n! Output, integer P(0:N), the partition numbers.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer j\n integer p(0:n)\n integer pj\n integer sgn\n!\n p(0) = 1\n\n do i = 1, n\n\n p(i) = 0\n\n j = 0\n sgn = 1\n\n do\n\n j = j + 1\n call pent_enum ( j, pj )\n\n if ( pj > i ) then\n exit\n end if\n\n p(i) = p(i) + sgn * p(i-pj)\n sgn = - sgn\n\n end do\n\n j = 0\n sgn = 1\n\n do\n\n j = j - 1\n call pent_enum ( j, pj )\n\n if ( pj > i ) then\n exit\n end if\n\n p(i) = p(i) + sgn * p(i-pj)\n sgn = - sgn\n\n end do\n\n end do\n\n return\nend\nsubroutine intp_next ( done, iarray, mult, n, npart )\n!\n!*******************************************************************************\n!\n!! INTP_NEXT generates the partitions of an integer, one at a time.\n!\n!\n! Comments:\n!\n! The number of partitions of N is:\n!\n! 1 1\n! 2 2\n! 3 3\n! 4 5\n! 5 7\n! 6 11\n! 7 15\n! 8 22\n! 9 30\n! 10 42\n! 11 56\n! 12 77\n! 13 101\n! 14 135\n! 15 176\n! 16 231\n! 17 297\n! 18 385\n! 19 490\n! 20 627\n! 21 792\n! 22 1002\n! 23 1255\n! 24 1575\n! 25 1958\n! 26 2436\n! 27 3010\n! 28 3718\n! 29 4565\n! 30 5604\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Input/output, logical DONE.\n!\n! On first call, the user should set DONE to .TRUE. to signal\n! that the program should initialize data.\n!\n! On each return, the programs sets DONE to .FALSE. if it\n! has another partition to return. If the program returns\n! with DONE .TRUE., then there are no more partitions.\n!\n! Output, integer IARRAY(N). IARRAY contains the parts of\n! the partition. The value of N is represented by\n!\n! sum ( 1 <= I <= NPART ) MULT(I) * IARRAY(I).\n!\n! Output, integer MULT(N). MULT counts the multiplicity of\n! the parts of the partition. MULT(I) is the multiplicity\n! of the part IARRAY(I), for I = 1 to NPART.\n!\n! Input, integer N, the integer to be partitioned.\n!\n! Output, integer NPART, the number of \"parts\" in the partition.\n!\n implicit none\n!\n integer n\n!\n logical done\n integer i\n integer iarray(n)\n integer is\n integer iu\n integer iv\n integer iw\n integer k\n integer k1\n integer mult(n)\n integer npart\n!\n if ( n <= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'INTP_NEXT - Fatal error!'\n write ( *, '(a)' ) ' N must be positive.'\n write ( *, '(a,i6)' ) ' The input value of N was ', n\n stop\n end if\n\n if ( done ) then\n\n iarray(1) = n\n iarray(2:n) = 0\n\n mult(1) = 1\n mult(2:n) = 0\n\n npart = 1\n done = .false.\n\n else\n\n if ( iarray(npart) > 1 .or. npart > 1 ) then\n\n done = .false.\n\n if ( iarray(npart) == 1 ) then\n is = iarray(npart-1) + mult(npart)\n k = npart - 1\n else\n is = iarray(npart)\n k = npart\n end if\n\n iw = iarray(k) - 1\n iu = is / iw\n iv = mod ( is, iw )\n mult(k) = mult(k) - 1\n\n if ( mult(k) == 0 ) then\n k1 = k\n else\n k1 = k + 1\n end if\n\n mult(k1) = iu\n iarray(k1) = iw\n\n if ( iv == 0 ) then\n npart = k1\n else\n mult(k1+1) = 1\n iarray(k1+1) = iv\n npart = k1 + 1\n end if\n\n else\n done = .true.\n end if\n\n end if\n\n return\nend\nsubroutine intp_next2 ( n, iarray, mult, npart, more )\n!\n!*******************************************************************************\n!\n!! INTP_NEXT2 computes the partitions of the integer N one at a time.\n!\n!\n! Discussion:\n!\n! Unlike compositions, order is not important in a partition. Thus\n! the sequences 3+2+1 and 1+2+3 represent distinct compositions, but\n! not distinct partitions. Also 0 is never returned as one of the\n! elements of the partition.\n!\n! Examples:\n!\n! Sample partitions of 6 include:\n!\n! 6 = 4+1+1 = 3+2+1 = 2+2+2\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Input, integer N, the integer whose partitions are desired.\n!\n! Output, integer IARRAY(N). IARRAY(I) is the I-th distinct part\n! of the partition, for I = 1, NPART. Note that if a certain number\n! shows up several times in the partition, it is listed only\n! once in IARRAY, and its multiplicity is counted in MULT.\n!\n! Output, integer MULT(N). MULT(I) is the multiplicity of IARRAY(I)\n! in the partition, for I = 1, NPART; that is, the number of repeated\n! times that IARRAY(I) is used in the partition.\n!\n! Output, integer NPART, the number of distinct, nonzero parts in the\n! output partition.\n!\n! Input/output, logical MORE. Set MORE = .FALSE. on first call. It\n! will be reset .TRUE. on return with the first partition.\n! Keep calling for more partitions until MORE\n! is returned .FALSE.\n!\n implicit none\n!\n integer n\n!\n integer iarray(n)\n integer iff\n integer is\n integer isum\n logical more\n integer mult(n)\n integer, save :: nlast = 0\n integer npart\n!\n! On the first call, set NLAST to 0.\n!\n if ( .not. more ) then\n nlast = 0\n end if\n\n if ( n /= nlast .or. ( .not. more ) ) then\n nlast = n\n npart = 1\n iarray(npart) = n\n mult(npart) = 1\n more = mult(npart) /= n\n return\n end if\n\n isum = 1\n\n if ( iarray(npart) <= 1 ) then\n isum = mult(npart) + 1\n npart = npart - 1\n end if\n\n iff = iarray(npart) - 1\n\n if ( mult(npart) /= 1 ) then\n mult(npart) = mult(npart) - 1\n npart = npart + 1\n end if\n\n iarray(npart) = iff\n mult(npart) = 1 + ( isum / iff )\n is = mod ( isum, iff )\n\n if ( is > 0 ) then\n npart = npart + 1\n iarray(npart) = is\n mult(npart) = 1\n end if\n!\n! There are more partitions, as long as we haven't just computed\n! the last one, which is N copies of 1.\n!\n more = mult(npart) /= n\n\n return\nend\nsubroutine intp_random ( n, iarray, mult, npart )\n!\n!*******************************************************************************\n!\n!! INTP_RANDOM selects a random partition of the integer N.\n!\n!\n! Discussion:\n!\n! Note that some elements of the partition may be 0. The partition is\n! returned as (MULT(I),I), with NPART nonzero entries in MULT, and\n!\n! N = sum ( 1 <= I <= N ) MULT(I) * I.\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 29 March 2001\n!\n! Parameters:\n!\n! Input, integer N, the integer to be partitioned.\n!\n! Output, integer IARRAY(N), returns the number of partitions of each\n! integer from 1 to N.\n!\n! Output, integer MULT(N). MULT(I) is the multiplicity of I\n! in the chosen partition.\n!\n! Output, integer NPART, the number of parts in the partition chosen,\n! that is, the number of integers I with nonzero multiplicity MULT(I).\n!\n implicit none\n!\n integer n\n!\n integer i\n integer i1\n integer iarray(n)\n integer id\n integer is\n integer isum\n integer j\n integer m\n integer mult(n)\n integer, save :: nlast = 0\n integer npart\n real z\n real, parameter :: zhi = 1.0E+00\n real, parameter :: zlo = 0.0E+00\n!\n if ( n > nlast ) then\n\n iarray(1) = 1\n m = nlast + 1\n nlast = n\n\n if ( n > 1 ) then\n\n do i = m, n\n\n isum = 0\n\n do id = 1, i\n\n is = 0\n i1 = i\n\n do\n\n i1 = i1 - id\n\n if ( i1 > 0 ) then\n is = is + iarray(i1)\n else\n if ( i1 == 0 ) then\n is = is + 1\n end if\n exit\n end if\n\n end do\n\n isum = isum + is * id\n\n end do\n\n iarray(i) = isum / i\n\n end do\n\n end if\n\n end if\n\n m = n\n npart = 0\n mult(1:n) = 0\n\n do while ( m > 0 )\n\n call r_random ( zlo, zhi, z )\n z = m * iarray(m) * z\n id = 0\n\n30 continue\n\n id = id + 1\n i1 = m\n j = 0\n\n do\n\n j = j + 1\n i1 = i1 - id\n\n if ( i1 < 0 ) then\n go to 30\n end if\n\n if ( i1 == 0 ) then\n z = z - id\n if ( z > 0.0E+00 ) then\n go to 30\n else\n exit\n end if\n end if\n\n if ( i1 > 0 ) then\n z = z - id * iarray(i1)\n if ( z <= 0.0E+00 ) then\n exit\n end if\n end if\n\n end do\n\n mult(id) = mult(id) + j\n npart = npart + j\n m = i1\n\n end do\n\n return\nend\nsubroutine involute_enum ( n, s )\n!\n!*******************************************************************************\n!\n!! INVOLUTE_ENUM enumerates the involutions of N objects.\n!\n!\n! Definition:\n!\n! An involution is a permutation consisting only of fixed points and\n! pairwise transpositions.\n!\n! Comments:\n!\n! An involution is its own inverse permutation.\n!\n! Recursion:\n!\n! S(0) = 1\n! S(1) = 1\n! S(N) = S(N-1) + (N-1) * S(N-2)\n!\n! First values:\n!\n! N S(N)\n! 0 1\n! 1 1\n! 2 2\n! 3 4\n! 4 10\n! 5 26\n! 6 76\n! 7 232\n! 8 764\n! 9 2620\n! 10 9496\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of objects to be permuted.\n!\n! Output, integer S(0:N), the number of involutions of 0, 1, 2, ... N\n! objects.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer s(0:n)\n!\n if ( n < 0 ) then\n return\n end if\n\n s(0) = 1\n\n if ( n <= 0 ) then\n return\n end if\n\n s(1) = 1\n\n do i = 2, n\n s(i) = s(i-1) + real ( i - 1 ) * s(i-2)\n end do\n\n return\nend\nsubroutine ipoly ( n, a, x0, iopt, val )\n!\n!*******************************************************************************\n!\n!! IPOLY performs operations on integer polynomials in power or factorial form.\n!\n!\n! Discussion:\n!\n! The power sum form of a polynomial is\n!\n! P(X) = A1 + A2*X + A3*X**2 + ... + (AN+1)*X**N\n!\n! The Taylor expansion at C has the form\n!\n! P(X) = A1 + A2*(X-C) + A3*(X-C)**2 + ... + (AN+1)*(X-C)**N\n!\n! The factorial form of a polynomial is\n!\n! P(X) = A1 + A2*X + A3*(X)*(X-1) + A4*(X)*(X-1)*(X-2)+...\n! + (AN+1)*(X)*(X-1)*...*(X-N+1)\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Input, integer N, the number of coefficients in the polynomial\n! (in other words, the polynomial degree + 1)\n!\n! Input/output, integer A(N), the coefficients of the polynomial. Depending\n! on the option chosen, these coefficients may be overwritten by those\n! of a different form of the polynomial.\n!\n! Input, integer X0, for IOPT = -1, 0, or positive, the value of the\n! argument at which the polynomial is to be evaluated, or the\n! Taylor expansion is to be carried out.\n!\n! Input, integer IOPT, a flag describing which algorithm is to\n! be carried out:\n!\n! -3: Reverse Stirling. Input the coefficients of the polynomial in\n! factorial form, output them in power sum form.\n!\n! -2: Stirling. Input the coefficients in power sum form, output them\n! in factorial form.\n!\n! -1: Evaluate a polynomial which has been input in factorial form.\n!\n! 0: Evaluate a polynomial input in power sum form.\n!\n! 1 or more: Given the coefficients of a polynomial in\n! power sum form, compute the first IOPT coefficients of\n! the polynomial in Taylor expansion form.\n!\n! Output, integer VAL, for IOPT = -1 or 0, the value of the\n! polynomial at the point X0.\n!\n implicit none\n!\n integer n\n!\n integer a(n)\n integer eps\n integer i\n integer iopt\n integer m\n integer n1\n integer val\n integer w\n integer x0\n integer z\n!\n n1 = min ( n, iopt )\n n1 = max ( 1, n1 )\n\n if ( iopt < -1 ) then\n n1 = n\n end if\n\n eps = mod ( max ( -iopt, 0 ), 2 )\n\n w = - n * eps\n\n if ( iopt > -2 ) then\n w = w + x0\n end if\n\n do m = 1, n1\n\n val = 0\n z = w\n\n do i = m, n\n z = z + eps\n val = a(n+m-i) + z * val\n if ( iopt /= 0 .and. iopt /= -1 ) then\n a(n+m-i) = val\n end if\n end do\n\n if ( iopt < 0 ) then\n w = w + 1\n end if\n\n end do\n\n return\nend\nsubroutine ipoly_cyclo ( n, phi )\n!\n!*******************************************************************************\n!\n!! IPOLY_CYCLO computes a cyclotomic polynomial.\n!\n!\n! Discussion:\n!\n! For N >= 1, let\n!\n! I = SQRT ( - 1 )\n! L = EXP ( 2 * PI * I / N )\n!\n! Then the N-th cyclotomic polynomial is defined by\n!\n! PHI(N;X) = Product ( 1 <= K <= N and GCD(K,N) = 1 ) ( X - L**K )\n!\n! We can use the Moebius MU function to write\n!\n! PHI(N;X) = Product ( mod ( D, N ) = 0 ) ( X**D - 1 )**MU(N/D)\n!\n! There is a sort of inversion formula:\n!\n! X**N - 1 = Product ( mod ( D, N ) = 0 ) PHI(D;X)\n!\n! Example:\n!\n! N PHI\n!\n! 0 1\n! 1 X - 1\n! 2 X + 1\n! 3 X**2 + X + 1\n! 4 X**2 + 1\n! 5 X**4 + X**3 + X**2 + X + 1\n! 6 X**2 - X + 1\n! 7 X**6 + X**5 + X**4 + X**3 + X**2 + X + 1\n! 8 X**4 + 1\n! 9 X**6 + X**3 + 1\n! 10 X**4 - X**3 + X**2 - X + 1\n!\n! Reference:\n!\n! Raymond Seroul,\n! Programming for Mathematicians,\n! Springer Verlag, 2000, page 269.\n!\n! Modified:\n!\n! 08 August 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the index of the cyclotomic polynomial desired.\n!\n! Output, integer PHI(0:N), the N-th cyclotomic polynomial.\n!\n implicit none\n!\n integer n\n integer, parameter :: max_poly = 100\n!\n integer d\n integer den(0:max_poly)\n integer den_n\n integer factor(0:n)\n integer mu\n integer nq\n integer nr\n integer num(0:max_poly)\n integer num_n\n integer phi(0:n)\n integer rem(0:n)\n!\n num(0) = 1\n num(1:max_poly) = 0\n num_n = 0\n\n den(0) = 1\n den(1:max_poly) = 0\n den_n = 0\n\n phi(0:n) = 0\n\n do d = 1, n\n!\n! For each divisor D of N, ...\n!\n if ( mod ( n, d ) == 0 ) then\n\n call i_moebius ( n / d, mu )\n!\n! ...multiply the numerator or denominator by (X^D-1).\n!\n factor(0) = -1\n factor(1:d-1) = 0\n factor(d) = 1\n\n if ( mu == + 1 ) then\n\n if ( num_n + d > max_poly ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'IPOLY_CYCLO - Fatal error!'\n write ( *, '(a)' ) ' Numerator polynomial degree too high.'\n return\n end if\n\n call ipoly_mul ( num_n, num, d, factor, num )\n\n num_n = num_n + d\n\n else if ( mu == -1 ) then\n\n if ( num_n + d > max_poly ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'IPOLY_CYCLO - Fatal error!'\n write ( *, '(a)' ) ' Denominator polynomial degree too high.'\n return\n end if\n\n call ipoly_mul ( den_n, den, d, factor, den )\n\n den_n = den_n + d\n\n end if\n\n end if\n\n end do\n!\n! PHI = NUM / DEN\n!\n call ipoly_div ( num_n, num, den_n, den, nq, phi, nr, rem )\n\n return\nend\nsubroutine ipoly_degree ( na, a, degree )\n!\n!*******************************************************************************\n!\n!! IPOLY_DEGREE returns the degree of a polynomial.\n!\n!\n! Discussion:\n!\n! The degree of a polynomial is the index of the highest power\n! of X with a nonzero coefficient.\n!\n! The degree of a constant polynomial is 0. The degree of the\n! zero polynomial is debatable, but this routine returns the\n! degree as 0.\n!\n! Modified:\n!\n! 20 March 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer NA, the dimension of A.\n!\n! Input, integer A(0:NA), the coefficients of the polynomials.\n!\n! Output, integer DEGREE, the degree of A.\n!\n implicit none\n!\n integer na\n!\n integer a(0:na)\n integer degree\n!\n degree = na\n\n do while ( degree > 0 )\n\n if ( a(degree) /= 0 ) then\n return\n end if\n\n degree = degree - 1\n\n end do\n\n return\nend\nsubroutine ipoly_div ( na, a, nb, b, nq, q, nr, r )\n!\n!*******************************************************************************\n!\n!! IPOLY_DIV computes the quotient and remainder of two polynomials.\n!\n!\n! Discussion:\n!\n! Normally, the quotient and remainder would have rational coefficients.\n! This routine assumes that the special case applies that the quotient\n! and remainder are known beforehand to be integral.\n!\n! The polynomials are assumed to be stored in power sum form.\n!\n! The power sum form is:\n!\n! p(x) = a(0) + a(1)*x + ... + a(n-1)*x**(n-1) + a(n)*x**(n)\n!\n! Modified:\n!\n! 23 March 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer NA, the dimension of A.\n!\n! Input, integer A(0:NA), the coefficients of the polynomial to be divided.\n!\n! Input, integer NB, the dimension of B.\n!\n! Input, integer B(0:NB), the coefficients of the divisor polynomial.\n!\n! Output, integer NQ, the degree of Q.\n! If the divisor polynomial is zero, NQ is returned as -1.\n!\n! Output, integer Q(0:NA-NB), contains the quotient of A/B.\n! If A and B have full degree, Q should be dimensioned Q(0:NA-NB).\n! In any case, Q(0:NA) should be enough.\n!\n! Output, integer NR, the degree of R.\n! If the divisor polynomial is zero, NR is returned as -1.\n!\n! Output, integer R(0:NB-1), contains the remainder of A/B.\n! If B has full degree, R should be dimensioned R(0:NB-1).\n! Otherwise, R will actually require less space.\n!\n implicit none\n!\n integer na\n integer nb\n!\n integer a(0:na)\n integer a2(0:na)\n integer b(0:nb)\n integer i\n integer na2\n integer nb2\n integer nq\n integer nr\n integer q(0:*)\n integer r(0:*)\n!\n call ipoly_degree ( na, a, na2 )\n\n call ipoly_degree ( nb, b, nb2 )\n\n if ( b(nb2) == 0 ) then\n nq = -1\n nr = -1\n return\n end if\n\n a2(0:na2) = a(0:na2)\n\n nq = na2 - nb2\n nr = nb2 - 1\n\n do i = nq, 0, -1\n q(i) = a2(i+nb2) / b(nb2)\n a2(i+nb2) = 0\n a2(i:i+nb2-1) = a2(i:i+nb2-1) - q(i) * b(0:nb2-1)\n end do\n\n r(0:nr) = a2(0:nr)\n\n return\nend\nsubroutine ipoly_mul ( na, a, nb, b, c )\n!\n!*******************************************************************************\n!\n!! IPOLY_MUL computes the product of two integer polynomials A and B.\n!\n!\n! Discussion:\n!\n! The polynomials are in power sum form.\n!\n! The power sum form is:\n!\n! p(x) = a(0) + a(1)*x + ... + a(n-1)*x**(n-1) + a(n)*x**(n)\n!\n! Modified:\n!\n! 29 March 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer NA, the dimension of A.\n!\n! Input, integer A(0:NA), the coefficients of the first polynomial factor.\n!\n! Input, integer NB, the dimension of B.\n!\n! Input, integer B(0:NB), the coefficients of the second polynomial factor.\n!\n! Output, integer C(0:NA+NB), the coefficients of A * B.\n!\n implicit none\n!\n integer na\n integer nb\n!\n integer a(0:na)\n integer b(0:nb)\n integer c(0:na+nb)\n integer d(0:na+nb)\n integer i\n integer j\n!\n d(0:na+nb) = 0\n\n do i = 0, na\n d(i:i+nb) = d(i:i+nb) + a(i) * b(0:nb)\n end do\n\n c(0:na+nb) = d(0:na+nb)\n\n return\nend\nsubroutine ipoly_print ( n, a, title )\n!\n!*******************************************************************************\n!\n!! IPOLY_PRINT prints out a polynomial.\n!\n!\n! Discussion:\n!\n! The power sum form is:\n!\n! p(x) = a(0) + a(1)*x + ... + a(n-1)*x**(n-1) + a(n)*x**(n)\n!\n! Modified:\n!\n! 06 August 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the dimension of A.\n!\n! Input, integer A(0:N), the polynomial coefficients.\n! A(0) is the constant term and\n! A(N) is the coefficient of X**N.\n!\n! Input, character ( len = * ) TITLE, an optional title.\n!\n implicit none\n!\n integer n\n!\n integer a(0:n)\n integer i\n integer mag\n integer n2\n character plus_minus\n character ( len = * ) title\n!\n if ( len_trim ( title ) > 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) trim ( title )\n end if\n\n write ( *, '(a)' ) ' '\n\n call ipoly_degree ( n, a, n2 )\n\n if ( a(n2) < 0 ) then\n plus_minus = '-'\n else\n plus_minus = ' '\n end if\n\n mag = abs ( a(n2) )\n\n if ( n2 >= 2 ) then\n write ( *, '( '' p(x) = '', a1, i6, '' * x ^ '', i3 )' ) &\n plus_minus, mag, n2\n else if ( n2 == 1 ) then\n write ( *, '( '' p(x) = '', a1, i6, '' * x'' )' ) plus_minus, mag\n else if ( n2 == 0 ) then\n write ( *, '( '' p(x) = '', a1, i6 )' ) plus_minus, mag\n end if\n\n do i = n2-1, 0, -1\n\n if ( a(i) < 0.0E+00 ) then\n plus_minus = '-'\n else\n plus_minus = '+'\n end if\n\n mag = abs ( a(i) )\n\n if ( mag /= 0 ) then\n\n if ( i >= 2 ) then\n write ( *, ' ( '' '', a1, i6, '' * x ^ '', i3 )' ) &\n plus_minus, mag, i\n else if ( i == 1 ) then\n write ( *, ' ( '' '', a1, i6, '' * x'' )' ) plus_minus, mag\n else if ( i == 0 ) then\n write ( *, ' ( '' '', a1, i6 )' ) plus_minus, mag\n end if\n end if\n\n end do\n\n return\nend\nsubroutine ivec_backtrack ( n, x, indx, k, nstack, stack, maxstack, ncan )\n!\n!*******************************************************************************\n!\n!! IVEC_BACKTRACK supervises a backtrack search for an integer vector.\n!\n!\n! Discussion:\n!\n! The routine tries to construct an integer vector one index at a time,\n! using possible candidates as supplied by the user.\n!\n! At any time, the partially constructed vector may be discovered to be\n! unsatisfactory, but the routine records information about where the\n! last arbitrary choice was made, so that the search can be\n! carried out efficiently, rather than starting out all over again.\n!\n! First, call the routine with INDX = 0 so it can initialize itself.\n!\n! Now, on each return from the routine, if INDX is:\n! 1, you've just been handed a complete candidate vector;\n! Admire it, analyze it, do what you like.\n! 2, please determine suitable candidates for position X(K).\n! Return the number of candidates in NCAN(K), adding each\n! candidate to the end of STACK, and increasing NSTACK.\n! 3, you're done. Stop calling the routine;\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 24 July 2000\n!\n! Parameters:\n!\n! Input, integer N, the number of positions to be filled in the vector.\n!\n! Input/output, integer X(N), the partial or complete candidate vector.\n!\n! Input/output, integer INDX, a communication flag.\n! On input,\n! 0 to start a search.\n! On output:\n! 1, a complete output vector has been determined and returned in X(1:N);\n! 2, candidates are needed for position X(K);\n! 3, no more possible vectors exist.\n!\n! Output, integer K, if INDX=2, the current vector index being considered.\n!\n! Input/output, integer NSTACK, the current length of the stack.\n!\n! Input, integer STACK(MAXSTACK), a list of all current candidates for\n! all positions 1 through K.\n!\n! Input, integer MAXSTACK, the maximum length of the stack.\n!\n! Input/output, integer NCAN(N), lists the current number of candidates for\n! positions 1 through K.\n!\n implicit none\n!\n integer n\n integer maxstack\n!\n integer indx\n integer k\n integer ncan(n)\n integer nstack\n integer stack(maxstack)\n integer x(n)\n!\n! If this is the first call, request a candidate for position 1.\n!\n if ( indx == 0 ) then\n k = 1\n nstack = 0\n indx = 2\n return\n end if\n!\n! Examine the stack.\n!\n do\n!\n! If there are candidates for position K, take the first available\n! one off the stack, and increment K.\n!\n! This may cause K to reach the desired value of N, in which case\n! we need to signal the user that a complete set of candidates\n! is being returned.\n!\n if ( ncan(k) > 0 ) then\n\n x(k) = stack(nstack)\n nstack = nstack - 1\n\n ncan(k) = ncan(k) - 1\n\n if ( k /= n ) then\n k = k + 1\n indx = 2\n else\n indx = 1\n end if\n\n exit\n!\n! If there are no candidates for position K, then decrement K.\n! If K is still positive, repeat the examination of the stack.\n!\n else\n\n k = k - 1\n\n if ( k <= 0 ) then\n indx = 3\n exit\n end if\n\n end if\n\n end do\n\n return\nend\nsubroutine ivec_binary_add ( n, ivec, jvec, kvec )\n!\n!*******************************************************************************\n!\n!! IVEC_BINARY_ADD adds two binary vectors.\n!\n!\n! Modified:\n!\n! 08 May 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the length of the vectors.\n!\n! Input, integer IVEC(N), JVEC(N), the vectors to be added.\n!\n! Output, integer KVEC(N), the sum of the two input vectors.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer ivec(n)\n integer jvec(n)\n integer kvec(n)\n logical overflow\n!\n overflow = .false.\n!\n kvec(1:n) = ivec(1:n) + jvec(1:n)\n\n do i = n, 1, -1\n if ( kvec(i) == 2 ) then\n kvec(i) = 0\n if ( i > 1 ) then\n kvec(i-1) = kvec(i-1) + 1\n else\n overflow = .true.\n end if\n end if\n end do\n\n return\nend\nsubroutine ivec_binary_complement2 ( n, ivec )\n!\n!*******************************************************************************\n!\n!! IVEC_BINARY_COMPLEMENT2 computes the two's complement of a binary vector.\n!\n!\n! Modified:\n!\n! 08 May 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the length of the vectors.\n!\n! Input/output, integer IVEC(N), the vector to be two's complemented.\n!\n implicit none\n!\n integer n\n!\n integer ivec(n)\n integer jvec(n)\n integer kvec(n)\n!\n ivec(1:n) = 1 - ivec(1:n)\n\n jvec(1:n-1) = 0\n jvec(n) = 1\n\n call ivec_binary_add ( n, ivec, jvec, ivec )\n\n ivec(1:n) = kvec(1:n)\n\n return\nend\nsubroutine ivec_binary_print ( n, a, title )\n!\n!*******************************************************************************\n!\n!! IVEC_BINARY_PRINT prints a binary integer vector, with an optional title.\n!\n!\n! Modified:\n!\n! 08 May 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of components of the vector.\n!\n! Input, integer A(N), the vector to be printed.\n!\n! Input, character ( len = * ) TITLE, a title to be printed first.\n! TITLE may be blank.\n!\n implicit none\n!\n integer n\n!\n integer a(n)\n integer i\n integer ihi\n integer ilo\n character ( len = * ) title\n!\n if ( title /= ' ' ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) trim ( title )\n write ( *, '(a)' ) ' '\n end if\n\n do ilo = 1, n, 80\n ihi = min ( ilo + 79, n )\n write ( *, '(80i1)' ) a(ilo:ihi)\n end do\n\n return\nend\nsubroutine ivec_binary_to_i ( n, ivec, i )\n!\n!*******************************************************************************\n!\n!! IVEC_BINARY_TO_I makes an integer from a vector binary representation.\n!\n!\n! Example:\n!\n! IVEC I\n! -------------- --\n! 0,0,...0,0,0,1 1\n! 0,0,...0,0,1,0 2\n! 0,0,...0,0,1,1 3\n! 0,0,...0,1,0,0 4\n! 0,0,...1,0,0,1 9\n! 1,1,...0,1,1,1 -9\n!\n! Modified:\n!\n! 08 May 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer I, an integer to be represented.\n!\n! Input, integer N, the dimension of the vector, which should be 32.\n!\n! Output, integer IVEC(N), the binary representation.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer i_sign\n integer ivec(n)\n integer j\n integer jvec(n)\n!\n jvec(1:n) = ivec(1:n)\n\n i_sign = 1\n\n if ( jvec(1) == 1 ) then\n i_sign = -1\n call ivec_binary_complement2 ( n, jvec )\n end if\n\n i = 0\n do j = 2, n\n i = 2 * i + jvec(j)\n end do\n\n i = i_sign * i\n\n return\nend\nsubroutine ivec_binary_xor ( n, ivec, jvec, kvec )\n!\n!*******************************************************************************\n!\n!! IVEC_BINARY_XOR computes the exclusive OR of two binary vectors.\n!\n!\n! Modified:\n!\n! 08 May 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the length of the vectors.\n!\n! Input, integer IVEC(N), JVEC(N), the binary vectors to be XOR'ed.\n!\n! Input, integer KVEC(N), the exclusive OR of the two vectors.\n!\n implicit none\n!\n integer n\n!\n integer ivec(n)\n integer jvec(n)\n integer kvec(n)\n!\n kvec(1:n) = mod ( ivec(1:n) + jvec(1:n), 2 )\n\n return\nend\nfunction ivec_descends ( n, x )\n!\n!*******************************************************************************\n!\n!! IVEC_DESCENDS determines if an integer vector is decreasing.\n!\n!\n! Example:\n!\n! X = ( 9, 7, 7, 3, 2, 1, -8 )\n!\n! IVEC_DESCEND = TRUE\n!\n! Modified:\n!\n! 17 July 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the size of the array.\n!\n! Input, integer X(N), the array to be examined.\n!\n! Output, logical IVEC_DESCEND, is TRUE if the entries of X descend.\n!\n implicit none\n!\n integer n\n!\n integer i\n logical ivec_descends\n integer x(n)\n!\n ivec_descends = .false.\n\n do i = 1, n-1\n if ( x(i) < x(i+1) ) then\n return\n end if\n end do\n\n ivec_descends = .true.\n\n return\nend\nsubroutine ivec_frac ( n, a, k, iafrac )\n!\n!*******************************************************************************\n!\n!! IVEC_FRAC searches for the K-th smallest element in an N-vector.\n!\n!\n! Discussion:\n!\n! Hoare's algorithm is used.\n!\n! Modified:\n!\n! 17 July 2000\n!\n! Parameters:\n!\n! Input, integer N, the number of elements of A.\n!\n! Input/output, integer A(N), array to search. On output,\n! the elements of A have been somewhat rearranged.\n!\n! Input, integer K, the fractile to be sought. If K = 1, the\n! minimum entry is sought. If K = N, the maximum is sought.\n! Other values of K search for the entry which is K-th in size.\n! K must be at least 1, and no greater than N.\n!\n! Output, integer IAFRAC, the value of the K-th fractile of A.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer a(n)\n integer iafrac\n integer iryt\n integer iw\n integer ix\n integer j\n integer k\n integer left\n!\n if ( n <= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'IVEC_FRAC - Fatal error!'\n write ( *, '(a,i6)' ) ' Illegal nonpositive value of N = ', n\n stop\n end if\n\n if ( k <= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'IVEC_FRAC - Fatal error!'\n write ( *, '(a,i6)' ) ' Illegal nonpositive value of K = ', k\n stop\n end if\n\n if ( k > n ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'IVEC_FRAC - Fatal error!'\n write ( *, '(a,i6)' ) ' Illegal K > N, K = ', k\n stop\n end if\n\n left = 1\n iryt = n\n\n do\n\n if ( left >= iryt ) then\n iafrac = a(k)\n exit\n end if\n\n ix = a(k)\n i = left\n j = iryt\n\n do\n\n if ( i > j ) then\n\n if ( j < k ) then\n left = i\n end if\n\n if ( k < i ) then\n iryt = j\n end if\n\n exit\n\n end if\n!\n! Find I so that IX <= A(I).\n!\n do while ( a(i) < ix )\n i = i + 1\n end do\n!\n! Find J so that A(J) <= IX.\n!\n do while ( ix < a(j) )\n j = j - 1\n end do\n\n if ( i <= j ) then\n call i_swap ( a(i), a(j) )\n i = i + 1\n j = j - 1\n end if\n\n end do\n\n end do\n\n return\nend\nsubroutine ivec_identity ( n, a )\n!\n!*******************************************************************************\n!\n!! IVEC_IDENTITY sets an integer vector to the identity vector A(I)=I.\n!\n!\n! Modified:\n!\n! 09 November 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of elements of A.\n!\n! Output, integer A(N), the array to be initialized.\n!\n implicit none\n!\n integer n\n!\n integer a(n)\n integer i\n!\n do i = 1, n\n a(i) = i\n end do\n\n return\nend\nfunction ivec_imax_last ( n, x )\n!\n!*******************************************************************************\n!\n!! IVEC_MAX_LAST returns the index of the last maximal integer vector element.\n!\n!\n! Example:\n!\n! X = ( 5, 1, 2, 5, 0, 5, 3 )\n!\n! IVEC_IMAX_LAST = 6\n!\n! Modified:\n!\n! 17 July 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the size of the array.\n!\n! Input, integer X(N), the array to be examined.\n!\n! Output, integer IVEC_IMAX_LAST, the index of the last element of\n! X of maximal value.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer ivec_imax_last\n integer max_last\n integer x(n)\n!\n ivec_imax_last = 0\n\n do i = 1, n\n if ( i == 1 ) then\n ivec_imax_last = 1\n max_last = x(1)\n else if ( x(i) >= max_last ) then\n ivec_imax_last = i\n max_last = x(i)\n end if\n end do\n\n return\nend\nfunction ivec_index ( n, a, aval )\n!\n!*******************************************************************************\n!\n!! IVEC_INDEX returns the location of the first occurrence of a given value.\n!\n!\n! Modified:\n!\n! 01 February 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of entries in the vector.\n!\n! Input, integer A(N), the vector to be searched.\n!\n! Input, integer AVAL, the value to be indexed.\n!\n! Output, integer IVEC_INDEX, the first location in A which has the\n! value AVAL, or 0 if no such index exists.\n!\n implicit none\n!\n integer n\n!\n integer a(n)\n integer aval\n integer i\n integer ivec_index\n!\n do i = 1, n\n if ( a(i) == aval ) then\n ivec_index = i\n return\n end if\n end do\n\n ivec_index = 0\n\n return\nend\nfunction ivec_pairwise_prime ( n, a )\n!\n!*******************************************************************************\n!\n!! IVEC_PAIRWISE_PRIME checks whether a vector of integers is pairwise prime.\n!\n!\n! Discussion:\n!\n! Two positive integers I and J are pairwise prime if they have no common\n! factor greater than 1.\n!\n! Modified:\n!\n! 05 July 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of values to check.\n!\n! Input, integer A(N), the vector of integers.\n!\n! Output, logical IVEC_PAIRWISE_PRIME, is TRUE if the vector of integers\n! is pairwise prime.\n!\n implicit none\n!\n integer n\n!\n integer a(n)\n integer i\n integer i_gcd\n logical ivec_pairwise_prime\n integer j\n!\n ivec_pairwise_prime = .false.\n\n do i = 1, n\n do j = i+1, n\n if ( i_gcd ( a(i), a(j) ) /= 1 ) then\n return\n end if\n end do\n end do\n\n ivec_pairwise_prime = .true.\n\n return\nend\nsubroutine ivec_print ( n, a, title )\n!\n!*******************************************************************************\n!\n!! IVEC_PRINT prints an integer vector, with an optional title.\n!\n!\n! Modified:\n!\n! 16 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of components of the vector.\n!\n! Input, integer A(N), the vector to be printed.\n!\n! Input, character ( len = * ) TITLE, a title to be printed first.\n! TITLE may be blank.\n!\n implicit none\n!\n integer n\n!\n integer a(n)\n integer i\n character ( len = * ) title\n!\n if ( title /= ' ' ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) trim ( title )\n end if\n\n write ( *, '(a)' ) ' '\n do i = 1, n\n write ( *, '(i6,i10)' ) i, a(i)\n end do\n\n return\nend\nsubroutine ivec_random ( n, a, alo, ahi )\n!\n!*******************************************************************************\n!\n!! IVEC_RANDOM returns a random integer vector in a given range.\n!\n!\n! Modified:\n!\n! 01 December 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of entries in the vector.\n!\n! Output, integer A(N), the vector of randomly chosen integers.\n!\n! Input, integer ALO, AHI, the range allowed for the entries.\n!\n implicit none\n!\n integer n\n!\n integer a(n)\n integer ahi\n integer alo\n integer i\n!\n do i = 1, n\n\n call i_random ( alo, ahi, a(i) )\n\n end do\n\n return\nend\nsubroutine ivec_reverse ( n, a )\n!\n!*******************************************************************************\n!\n!! IVEC_REVERSE reverses the elements of an integer vector.\n!\n!\n! Example:\n!\n! Input:\n!\n! N = 5,\n! A = ( 11, 12, 13, 14, 15 ).\n!\n! Output:\n!\n! A = ( 15, 14, 13, 12, 11 ).\n!\n! Modified:\n!\n! 26 July 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of entries in the array.\n!\n! Input/output, integer A(N), the array to be reversed.\n!\n implicit none\n!\n integer n\n!\n integer a(n)\n integer i\n!\n do i = 1, n/2\n call i_swap ( a(i), a(n+1-i) )\n end do\n\n return\nend\nsubroutine ivec_sort_heap_index_d ( n, a, indx )\n!\n!*******************************************************************************\n!\n!! IVEC_SORT_HEAP_INDEX_D does an indexed heap descending sort of an integer vector.\n!\n!\n! Discussion:\n!\n! The sorting is not actually carried out. Rather an index array is\n! created which defines the sorting. This array may be used to sort\n! or index the array, or to sort or index related arrays keyed on the\n! original array.\n!\n! Once the index array is computed, the sorting can be carried out\n! \"implicitly:\n!\n! A(INDX(I)), I = 1 to N is sorted,\n!\n! after which A(I), I = 1 to N is sorted.\n!\n! Modified:\n!\n! 07 November 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of entries in the array.\n!\n! Input, integer A(N), an array to be index-sorted.\n!\n! Output, integer INDX(N), contains the sort index. The\n! I-th element of the sorted array is A(INDX(I)).\n!\n implicit none\n!\n integer n\n!\n integer a(n)\n integer aval\n integer i\n integer indx(n)\n integer indxt\n integer ir\n integer j\n integer l\n!\n call ivec_identity ( n, indx )\n\n l = n / 2 + 1\n ir = n\n\n do\n\n if ( l > 1 ) then\n\n l = l - 1\n indxt = indx(l)\n aval = a(indxt)\n\n else\n\n indxt = indx(ir)\n aval = a(indxt)\n indx(ir) = indx(1)\n ir = ir - 1\n\n if ( ir == 1 ) then\n indx(1) = indxt\n return\n end if\n\n end if\n\n i = l\n j = l + l\n\n do while ( j <= ir )\n\n if ( j < ir ) then\n if ( a(indx(j)) > a(indx(j+1)) ) then\n j = j + 1\n end if\n end if\n\n if ( aval > a(indx(j)) ) then\n indx(i) = indx(j)\n i = j\n j = j + j\n else\n j = ir + 1\n end if\n\n end do\n\n indx(i) = indxt\n\n end do\n\n return\nend\nsubroutine jfrac_to_rfrac ( m, r, s, p, q )\n!\n!*******************************************************************************\n!\n!! JFRAC_TO_RFRAC converts a J-fraction into a rational polynomial fraction.\n!\n!\n! Discussion:\n!\n! The routine accepts a J-fraction:\n!\n! R(1) / ( X + S(1)\n! + R(2) / ( X + S(2)\n! + R(3) / ...\n! + R(M) / ( X + S(M) )... ))\n!\n! and returns the equivalent rational polynomial fraction:\n!\n! P(1) + P(2) * X + ... + P(M) * X**(M-1)\n! -------------------------------------------------------\n! Q(1) + Q(2) * X + ... + Q(M) * X**(M-1) + Q(M+1) * X**M\n!\n! Reference:\n!\n! Hart, Cheney, Lawson, Maehly, Mesztenyi, Rice, Thacher, Witzgall,\n! Computer Approximations,\n! Wiley, 1968.\n!\n! Modified:\n!\n! 17 April 2000\n!\n! Parameters:\n!\n! Input, integer M, defines the number of P, R, and S\n! coefficients, and is one less than the number of Q\n! coefficients.\n!\n! Input, real R(M), S(M), the coefficients defining the J-fraction.\n!\n! Output, real P(M), Q(M+1), the coefficients defining the rational\n! polynomial fraction. The algorithm used normalizes the coefficients\n! so that Q(M+1) = 1.0.\n!\n implicit none\n!\n integer m\n!\n real a(m,m)\n real b(m,m)\n integer i\n integer k\n real p(m)\n real q(m+1)\n real r(m)\n real s(m)\n!\n a(1,1) = r(1)\n b(1,1) = s(1)\n\n if ( m > 1 ) then\n\n do k = 2, m\n a(k,k) = r(1)\n b(k,k) = b(k-1,k-1) + s(k)\n end do\n\n a(1,2) = r(1) * s(2)\n b(1,2) = r(2) + s(1) * s(2)\n\n do k = 3, m\n a(1,k) = s(k) * a(1,k-1) + r(k) * a(1,k-2)\n a(k-1,k) = a(k-2,k-1) + s(k) * r(1)\n b(1,k) = s(k) * b(1,k-1) + r(k) * b(1,k-2)\n b(k-1,k) = b(k-2,k-1) + s(k) * b(k-1,k-1) + r(k)\n end do\n\n do k = 4, m\n do i = 2, k-2\n a(i,k) = a(i-1,k-1) + s(k)*a(i,k-1) + r(k) * a(i,k-2)\n b(i,k) = b(i-1,k-1) + s(k)*b(i,k-1) + r(k) * b(i,k-2)\n end do\n end do\n\n end if\n\n p(1:m) = a(1:m,m)\n\n q(1:m) = b(1:m,m)\n q(m+1) = 1.0E+00\n\n return\nend\nsubroutine josephus ( n, m, k, x )\n!\n!*******************************************************************************\n!\n!! JOSEPHUS returns the position X of the K-th man to be executed.\n!\n!\n! Discussion:\n!\n! The classic Josephus problem concerns a circle of 41 men.\n! Every third man is killed and removed from the circle. Counting\n! and executing continues until all are dead. Where was the last\n! survivor sitting?\n!\n! Note that the first person killed was sitting in the third position.\n! Moreover, when we get down to 2 people, and we need to count the\n! \"third\" one, we just do the obvious thing, which is to keep counting\n! around the circle until our count is completed.\n!\n! The process may be regarded as generating a permutation of\n! the integers from 1 to N. The permutation would be the execution\n! list, that is, the list of the executed men, by position number.\n!\n! Reference:\n!\n! W W Rouse Ball,\n! Mathematical Recreations and Essays,\n! Macmillan, 1962, pages 32-36.\n!\n! Donald Knuth,\n! The Art of Computer Programming,\n! Volume 1, Fundamental Algorithms,\n! Addison Wesley, 1968, pages 158-159.\n!\n! Donald Knuth,\n! The Art of Computer Programming,\n! Volume 3, Sorting and Searching,\n! Addison Wesley, 1968, pages 18-19.\n!\n! Modified:\n!\n! 03 April 2000\n!\n! Parameters:\n!\n! Input, integer N, the number of men.\n! N must be positive.\n!\n! Input, integer M, the counting index.\n! M must not be zero. Ordinarily, M is positive, and no greater than N.\n!\n! Input, integer K, the index of the executed man of interest.\n! K must be between 1 and N.\n!\n! Output, integer X, the position of the K-th man.\n! X will be between 1 and N.\n!\n implicit none\n!\n integer i_modp\n integer k\n integer m\n integer m2\n integer n\n integer x\n!\n if ( n <= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'JOSEPHUS - Fatal error!'\n write ( *, '(a)' ) ' N <= 0.'\n stop\n end if\n\n if ( m == 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'JOSEPHUS - Fatal error!'\n write ( *, '(a)' ) ' M = 0.'\n stop\n end if\n\n if ( k <= 0 .or. k > n ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'JOSEPHUS - Fatal error!'\n write ( *, '(a)' ) ' J <= 0 or K > N.'\n stop\n end if\n!\n! In case M is bigger than N, or negative, get the\n! equivalent positive value between 1 and N.\n! You can skip this operation if 1 <= M <= N.\n!\n m2 = i_modp ( m, n )\n\n x = k * m2\n\n do while ( x > n )\n x = ( m2 * ( x - n ) - 1 ) / ( m2 - 1 )\n end do\n\n return\nend\nsubroutine ksub_next ( n, k, iarray, more )\n!\n!*******************************************************************************\n!\n!! KSUB_NEXT generates the K subsets of an N set, one at a time.\n!\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Input, integer N, the size of the set from which subsets are drawn.\n!\n! Input, integer K, the desired size of the subsets. K must\n! be between 0 and N.\n!\n! Output, integer IARRAY(K). IARRAY(I) is the I-th element of the\n! subset. Thus IARRAY(I) will be an integer between 1 and N.\n! Note that the routine will return the values in IARRAY\n! in sorted order: 1 <= IARRAY(1) < IARRAY(2) < ... < IARRAY(K) <= N\n!\n! Input/output, logical MORE. Set MORE = .FALSE. before first call\n! for a new sequence of subsets. It then is set and remains\n! .TRUE. as long as the subset computed on this call is not the\n! final one. When the final subset is computed, MORE is set to\n! .FALSE. as a signal that the computation is done.\n!\n implicit none\n!\n integer k\n!\n integer iarray(k)\n integer j\n integer, save :: m = 0\n integer, save :: m2 = 0\n logical more\n integer n\n!\n if ( k < 0 .or. k > n ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'KSUB_NEXT - Fatal error!'\n write ( *, '(a,i6)' ) 'N = ', n\n write ( *, '(a,i6)' ) 'K = ', k\n write ( *, '(a)' ) 'but 0 <= K <= N is required!'\n stop\n end if\n\n if ( .not. more ) then\n m2 = 0\n m = k\n else\n if ( m2 < n-m ) then\n m = 0\n end if\n m = m + 1\n m2 = iarray(k+1-m)\n end if\n\n do j = 1, m\n iarray(k+j-m) = m2 + j\n end do\n\n more = iarray(1) /= (n-k+1)\n\n return\nend\nsubroutine ksub_next2 ( n, k, iarray, in, iout )\n!\n!*******************************************************************************\n!\n!! KSUB_NEXT2 computes the next K subset of an N set.\n!\n!\n! Discussion:\n!\n! This routine uses the revolving door method. It has no \"memory\".\n! It simply calculates the successor of the input set,\n! and will start from the beginning after the last set.\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 29 March 2001\n!\n! Parameters:\n!\n! Input, integer N, the size of the set from which subsets are drawn.\n! N must be positive.\n!\n! Input, integer K, the size of the desired subset. K must be\n! between 0 and N.\n!\n! Input/output, integer IARRAY(K). On input, the user must\n! supply a subset of size K in IARRAY. That is, IARRAY must\n! contain K unique numbers, in order, between 1 and N. On\n! output, IARRAY(I) is the I-th element of the output subset.\n! The output array is also in sorted order.\n!\n! Output, integer IN, the element of the output subset which\n! was not in the input set. Each new subset differs from the\n! last one by adding one element and deleting another.\n!\n! Output, integer IOUT, the element of the input subset which\n! is not in the output subset.\n!\n implicit none\n!\n integer k\n!\n integer iarray(k)\n integer in\n integer iout\n integer j\n integer m\n integer n\n!\n if ( n <= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'KSUB_NEXT2 - Fatal error!'\n write ( *, '(a,i6)' ) ' N = ', n\n write ( *, '(a)' ) ' but 0 < N is required!'\n stop\n end if\n\n if ( k < 0 .or. k > n ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'KSUB_NEXT2 - Fatal error!'\n write ( *, '(a,i6)' ) ' N = ', n\n write ( *, '(a,i6)' ) ' K = ', k\n write ( *, '(a)' ) ' but 0 <= K <= N is required!'\n stop\n end if\n\n j = 0\n\n do\n\n if ( j > 0 .or. mod ( k, 2 ) == 0 ) then\n\n j = j + 1\n\n if ( j > k ) then\n iarray(k) = k\n in = k\n iout = n\n return\n end if\n\n if ( iarray(j) /= j ) then\n\n iout = iarray(j)\n in = iout - 1\n iarray(j) = in\n\n if ( j /= 1 ) then\n in = j - 1\n iarray(j-1) = in\n end if\n\n return\n\n end if\n\n end if\n\n j = j + 1\n m = n\n\n if ( j < k ) then\n m = iarray(j+1) - 1\n end if\n\n if ( m /= iarray(j) ) then\n exit\n end if\n\n end do\n\n in = iarray(j) + 1\n iarray(j) = in\n iout = in - 1\n\n if ( j /= 1 ) then\n iarray(j-1) = iout\n iout = j - 1\n end if\n\n return\nend\nsubroutine ksub_next3 ( n, k, iarray, more, in, iout )\n!\n!*******************************************************************************\n!\n!! KSUB_NEXT3 computes the K subsets of an N set.\n!\n!\n! Discussion:\n!\n! The routine uses the revolving door method.\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 30 March 2001\n!\n! Parameters:\n!\n! Input, integer N, the size of the set from which subsets are drawn.\n! N must be positive.\n!\n! Input, integer K, the size of the desired subsets. K must be\n! between 0 and N.\n!\n! Output, integer IARRAY(K). IARRAY(I) is the I-th element of the\n! output subset. The elements of IARRAY are sorted.\n!\n! Input/output, logical MORE. On first call, set MORE = .FALSE.\n! to signal the beginning. MORE will be set to .TRUE., and on\n! each call, the routine will return another K-subset.\n! Finally, when the last subset has been returned,\n! MORE will be set .FALSE. and you may stop calling.\n!\n! Output, integer IN, the element of the output subset which\n! was not in the input set. Each new subset differs from the\n! last one by adding one element and deleting another. IN is not\n! defined the first time that the routine returns, and is\n! set to zero.\n!\n! Output, integer IOUT, the element of the input subset which is\n! not in the output subset. IOUT is not defined the first time\n! the routine returns, and is set to zero.\n!\n implicit none\n!\n integer k\n!\n integer i\n integer iarray(k)\n integer in\n integer iout\n integer j\n integer m\n logical more\n integer n\n!\n if ( n <= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'KSUB_NEXT3 - Fatal error!'\n write ( *, '(a,i6)' ) ' N = ', n\n write ( *, '(a)' ) ' but 0 < N is required!'\n stop\n end if\n\n if ( k < 0 .or. k > n ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'KSUB_NEXT3 - Fatal error!'\n write ( *, '(a,i6)' ) ' N = ', n\n write ( *, '(a,i6)' ) ' K = ', k\n write ( *, '(a)' ) ' but 0 <= K <= N is required!'\n stop\n end if\n\n if ( .not. more ) then\n in = 0\n iout = 0\n call ivec_identity ( k, iarray )\n more = ( k /= n )\n return\n end if\n\n j = 0\n\n do\n\n if ( j > 0 .or. mod ( k, 2 ) == 0 ) then\n\n j = j + 1\n\n if ( iarray(j) /= j ) then\n\n iout = iarray(j)\n in = iout - 1\n iarray(j) = in\n\n if ( j /= 1 ) then\n in = j - 1\n iarray(j-1) = in\n end if\n\n if ( k /= 1 ) then\n more = ( iarray(k-1) == k-1 )\n end if\n\n more = ( .not. more ) .or. ( iarray(k) /= n )\n\n return\n\n end if\n\n end if\n\n j = j + 1\n m = n\n\n if ( j < k ) then\n m = iarray(j+1) - 1\n end if\n\n if ( m /= iarray(j) ) then\n exit\n end if\n\n end do\n\n in = iarray(j) + 1\n iarray(j) = in\n iout = in - 1\n\n if ( j /= 1 ) then\n iarray(j-1) = iout\n iout = j - 1\n end if\n\n if ( k /= 1 ) then\n more = ( iarray(k-1) == k-1 )\n end if\n\n more = ( .not. more ) .or. ( iarray(k) /= n )\n\n return\nend\nsubroutine ksub_next4 ( done, iarray, k, n )\n!\n!*******************************************************************************\n!\n!! KSUB_NEXT4 generates the subsets of size K of a set of N elements.\n!\n!\n! Discussion:\n!\n! The subsets are generated one at a time.\n!\n! The routine should be used by setting DONE to .TRUE., and then calling\n! repeatedly. Each call returns with DONE equal to .FALSE., the array\n! IARRAY contains information defining a new subset. When DONE returns\n! equal to .TRUE., there are no more subsets.\n!\n! There are ( N*(N-1)*...*(N+K-1)) / ( K*(K-1)*...*2*1) such subsets.\n!\n! Modified:\n!\n! 31 July 2000\n!\n! Parameters:\n!\n! Input/output, logical DONE.\n!\n! On the first call, DONE is an input quantity with a value\n! of .TRUE. which tells the program to initialize data and\n! return the first subset.\n!\n! On return, DONE is an output quantity that is .TRUE. as long as\n! the routine is returning another subset, and .FALSE. when\n! there are no more.\n!\n! Input/output, integer IARRAY(K), contains information about\n! the subsets. On the first call with DONE = .TRUE., the input contents\n! of IARRAY don't matter. Thereafter, the input value of IARRAY\n! should be the same as the output value of the previous call.\n! In other words, leave the array alone!\n!\n! On output, as long as DONE is returned .FALSE., IARRAY contains\n! information defining a subset of K elements of a set of N elements.\n! In other words, IARRAY will contain K distinct numbers (in order)\n! between 1 and N.\n!\n! Input, integer K, the size of the desired subset. K must be\n! between 0 and N.\n!\n! Input, integer N, the size of the entire set.\n!\n implicit none\n!\n integer k\n!\n logical done\n integer i\n integer iarray(k)\n integer j\n integer jsave\n integer n\n!\n if ( k < 0 .or. k > n ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'KSUB_NEXT4 - Fatal error!'\n write ( *, '(a,i6)' ) ' N = ', n\n write ( *, '(a,i6)' ) ' K = ', k\n write ( *, '(a)' ) ' but 0 <= K <= N is required!'\n stop\n end if\n!\n! First call:\n!\n if ( done ) then\n call ivec_identity ( k, iarray )\n\n if ( n > 0 ) then\n done = .false.\n else\n done = .true.\n end if\n!\n! Next call.\n!\n else\n\n if ( iarray(1) < n-k+1 ) then\n\n done = .false.\n\n jsave = k\n\n do j = 1, k-1\n\n if ( iarray(j+1) > iarray(j)+1 ) then\n jsave = j\n exit\n end if\n\n end do\n\n call ivec_identity ( jsave-1, iarray )\n iarray(jsave) = iarray(jsave) + 1\n\n else\n\n done = .true.\n\n end if\n\n end if\n\n return\nend\nsubroutine ksub_random ( n, k, iarray )\n!\n!*******************************************************************************\n!\n!! KSUB_RANDOM selects a random subset of size K from a set of size N.\n!\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 01 December 2000\n!\n! Parameters:\n!\n! Input, integer N, the size of the set from which subsets are drawn.\n!\n! Input, integer K, number of elements in desired subsets. K must\n! be between 0 and N.\n!\n! Output, integer IARRAY(K). IARRAY(I) is the I-th element of the\n! output set. The elements of IARRAY are in order.\n!\n implicit none\n!\n integer k\n!\n integer i\n integer iarray(k)\n integer ids\n integer ihi\n integer ip\n integer ir\n integer is\n integer ix\n integer l\n integer ll\n integer m\n integer m0\n integer n\n real r\n!\n if ( k < 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'KSUB_RANDOM - Fatal error!'\n write ( *, '(a,i6)' ) ' K = ', k\n write ( *, '(a)' ) ' but 0 <= K is required!'\n stop\n else if ( k > n ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'KSUB_RANDOM - Fatal error!'\n write ( *, '(a,i6)' ) ' N = ', n\n write ( *, '(a,i6)' ) ' K = ', k\n write ( *, '(a)' ) ' K <= N is required!'\n stop\n end if\n\n if ( k == 0 ) then\n return\n end if\n\n do i = 1, k\n iarray(i) = ( ( i - 1 ) * n ) / k\n end do\n\n do i = 1, k\n\n do\n\n call i_random ( 1, n, ix )\n\n l = 1 + ( ix * k - 1 ) / n\n\n if ( ix > iarray(l) ) then\n exit\n end if\n\n end do\n\n iarray(l) = iarray(l) + 1\n\n end do\n\n ip = 0\n is = k\n\n do i = 1, k\n\n m = iarray(i)\n iarray(i) = 0\n\n if ( m /= ( ( i - 1 ) * n ) / k ) then\n ip = ip + 1\n iarray(ip) = m\n end if\n\n end do\n\n ihi = ip\n\n do i = 1, ihi\n ip = ihi + 1 - i\n l = 1 + ( iarray(ip) * k - 1 ) / n\n ids = iarray(ip) - ( ( l - 1 ) * n ) / k\n iarray(ip) = 0\n iarray(is) = l\n is = is - ids\n end do\n\n do ll = 1, k\n\n l = k + 1 - ll\n\n if ( iarray(l) /= 0 ) then\n ir = l\n m0 = 1 + ( ( iarray(l) - 1 ) * n ) / k\n m = ( iarray(l) * n ) / k - m0 + 1\n end if\n\n call i_random ( m0, m0 + m - 1, ix )\n\n i = l + 1\n\n do while ( i <= ir )\n\n if ( ix < iarray(i) ) then\n exit\n end if\n\n ix = ix + 1\n iarray(i-1) = iarray(i)\n i = i + 1\n\n end do\n\n iarray(i-1) = ix\n m = m - 1\n\n end do\n\n return\nend\nsubroutine ksub_random2 ( n, k, iarray )\n!\n!*******************************************************************************\n!\n!! KSUB_RANDOM2 selects a random subset of size K from a set of size N.\n!\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 25 July 2000\n!\n! Parameters:\n!\n! Input, integer N, the size of the set from which subsets are drawn.\n!\n! Input, integer K, number of elements in desired subsets. K must\n! be between 0 and N.\n!\n! Output, integer IARRAY(K). IARRAY(I) is the I-th element of the\n! output set. The elements of IARRAY are in order.\n!\n implicit none\n!\n integer k\n!\n integer i\n integer iarray(k)\n integer ic1\n integer ic2\n integer k0\n integer n\n real r\n real, parameter :: rhi = 1.0E+00\n real, parameter :: rlo = 0.0E+00\n!\n if ( k < 0 .or. k > n ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'KSUB_RANDOM2 - Fatal error!'\n write ( *, '(a,i6)' ) ' N = ', n\n write ( *, '(a,i6)' ) ' K = ', k\n write ( *, '(a)' ) ' but 0 <= K <= N is required!'\n stop\n end if\n\n if ( k == 0 ) then\n return\n end if\n\n ic1 = k\n ic2 = n\n k0 = 0\n i = 0\n\n do\n\n i = i + 1\n\n call r_random ( rlo, rhi, r )\n\n if ( real ( ic2 ) * r <= real ( ic1 ) ) then\n\n ic1 = ic1 - 1\n k0 = k0 + 1\n iarray(k0) = i\n\n if ( ic1 <= 0 ) then\n exit\n end if\n\n end if\n\n ic2 = ic2 - 1\n\n end do\n\n return\nend\nsubroutine ksub_random3 ( n, k, iarray )\n!\n!*******************************************************************************\n!\n!! KSUB_RANDOM3 selects a random subset of size K from a set of size N.\n!\n!\n! Discussion:\n!\n! This routine uses Floyd's algorithm.\n!\n! Modified:\n!\n! 01 December 2000\n!\n! Parameters:\n!\n! Input, integer N, the size of the set from which subsets are drawn.\n!\n! Input, integer K, number of elements in desired subsets. K must\n! be between 0 and N.\n!\n! Output, integer IARRAY(N). I is an element of the subset\n! if IARRAY(I) = 1, and I is not an element if IARRAY(I)=0.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer iarray(n)\n integer j\n integer k\n real r\n!\n if ( k < 0 .or. k > n ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'KSUB_RANDOM3 - Fatal error!'\n write ( *, '(a,i6)' ) ' N = ', n\n write ( *, '(a,i6)' ) ' K = ', k\n write ( *, '(a)' ) ' but 0 <= K <= N is required!'\n stop\n end if\n\n iarray(1:n) = 0\n\n if ( k == 0 ) then\n return\n end if\n\n do i = n-k+1, n\n\n call i_random ( 1, i, j )\n\n if ( iarray(j) == 0 ) then\n iarray(j) = 1\n else\n iarray(i) = 1\n end if\n\n end do\n\n return\nend\nsubroutine matrix_product_opt ( n, rank, cost, order )\n!\n!*******************************************************************************\n!\n!! MATRIX_PRODUCT_OPT determines the optimal cost of a matrix product.\n!\n!\n! Discussion:\n!\n! The cost of multiplying an LxM matrix by an M by N matrix is\n! assessed as L*M*N.\n!\n! Any particular order of multiplying a set of N matrices is equivalent\n! to parenthesizing an expression of N objects.\n!\n! The actual number of ways of parenthesizing an expression\n! of N objects is C(N), the N-th Catalan number.\n!\n! Reference:\n!\n! Robert Sedgewick,\n! Algorithms,\n! Addison-Wesley, 1984, pages 486-489.\n!\n! Modified:\n!\n! 17 April 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of matrices to be multiplied.\n!\n! Input, integer RANK(N+1), the rank information for the matrices.\n! Matrix I has RANK(I) rows and RANK(I+1) columns.\n!\n! Output, integer COST, the cost of the multiplication if the optimal\n! order is used.\n!\n! Output, integer ORDER(N-1), indicates the order in which the N-1\n! multiplications are to be carried out. ORDER(1) is the first\n! multiplication to do, and so on.\n!\n implicit none\n!\n integer, parameter :: stack_max = 100\n integer n\n!\n integer best(n,n)\n integer cost\n integer cost2(n,n)\n integer cost3\n integer i\n integer i_inf\n integer i1\n integer i2\n integer i3\n integer j\n integer k\n integer order(n-1)\n integer rank(n+1)\n integer stack(stack_max)\n integer stack_num\n integer step\n!\n! Initialize the cost matrix.\n!\n do i = 1, n\n\n cost2(i,1:i) = 0\n cost2(i,i+1:n) = huge ( 1 )\n\n end do\n!\n! Initialize the BEST matrix.\n!\n best(1:n,1:n) = 0\n!\n! Compute the cost and best matrices.\n!\n do j = 1, n-1\n do i = 1, n-j\n do k = i+1, i+j\n cost3 = cost2(i,k-1) + cost2(k,i+j) + rank(i) * rank(k) * rank(i+j+1)\n if ( cost3 < cost2(i,i+j) ) then\n cost2(i,i+j) = cost3\n best(i,i+j) = k\n end if\n end do\n end do\n end do\n!\n! Pick off the optimal cost.\n!\n cost = cost2(1,n)\n!\n! Backtrack to determine the optimal order.\n!\n stack_num = 0\n\n i1 = 1\n i2 = n\n\n if ( i1+1 < i2 ) then\n stack_num = stack_num + 1\n stack(stack_num) = i1\n stack_num = stack_num + 1\n stack(stack_num) = i2\n end if\n\n step = n - 1\n!\n! Take an item off the stack.\n!\n do while ( stack_num > 0 )\n\n i3 = stack(stack_num)\n stack_num = stack_num - 1\n i1 = stack(stack_num)\n stack_num = stack_num - 1\n\n i2 = best(i1,i3)\n\n order(step) = i2 - 1\n step = step - 1\n!\n! The left chunk is matrices (I1...I2-1)\n!\n if ( i1 == i2-1 ) then\n\n else if ( i1+1 == i2-1 ) then\n order(step) = i2 - 2\n step = step - 1\n else\n stack_num = stack_num + 1\n stack(stack_num) = i1\n stack_num = stack_num + 1\n stack(stack_num) = i2 - 1\n end if\n!\n! The right chunk is matrices (I2...I3)\n!\n if ( i2 == i3 ) then\n\n else if ( i2+1 == i3 ) then\n order(step) = i2\n step = step - 1\n else\n stack_num = stack_num + 1\n stack(stack_num) = i2\n stack_num = stack_num + 1\n stack(stack_num) = i3\n end if\n\n end do\n\n return\nend\nsubroutine moebius_matrix ( n, a, mu )\n!\n!*******************************************************************************\n!\n!! MOEBIUS_MATRIX finds the Moebius matrix from a covering relation.\n!\n!\n! Discussion:\n!\n! This routine can be called with MATRIX and MU being the same matrix.\n! The routine will correctly compute the Moebius matrix, which\n! will, in this case, overwrite the input matrix.\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Input, integer N, number of elements in the partially ordered set.\n!\n! Input, integer A(N,N). A(I,J) = 1 if I is covered by J,\n! 0 otherwise.\n!\n! Output, integer MU(N,N), the Moebius matrix as computed by the routine.\n!\n implicit none\n!\n integer n\n!\n integer a(n,n)\n integer i\n integer iwork(n,2)\n integer j\n integer mu(n,n)\n!\n! Compute a reordering of the elements of the partially ordered matrix.\n!\n call triang ( n, a, iwork(1,1) )\n!\n! Copy the matrix.\n!\n mu(1:n,1:n) = a(1:n,1:n)\n!\n! Apply the reordering to MU.\n!\n call imat_perm2 ( n, n, mu, iwork(1,1), iwork(1,1) )\n!\n! Negate the (strict) upper triangular elements of MU.\n!\n do i = 1, n-1\n mu(i,i+1:n) = - mu(i,i+1:n)\n end do\n!\n! Compute the inverse of MU.\n!\n call imat_inverse ( n, mu, mu )\n!\n! All nonzero elements are reset to 1.\n!\n do i = 1, n\n do j = i, n\n if ( mu(i,j) /= 0 ) then\n mu(i,j) = 1\n end if\n end do\n end do\n!\n! Invert the matrix again.\n!\n call imat_inverse ( n, mu, mu )\n!\n! Compute the inverse permutation.\n!\n do i = 1, n\n iwork(iwork(i,1),2) = i\n end do\n!\n! Unpermute the rows and columns of MU.\n!\n call imat_perm2 ( n, n, mu, iwork(1,2), iwork(1,2) )\n\n return\nend\nsubroutine morse_thue ( i, s )\n!\n!*******************************************************************************\n!\n!! MORSE_THUE generates a Morse_Thue number.\n!\n!\n! Definition:\n!\n! The Morse_Thue sequence can be defined in a number of ways.\n!\n! A) Start with the string containing the single letter '0'; then\n! repeatedly apply the replacement rules '0' -> '01' and\n! '1' -> '10' to the letters of the string. The Morse_Thue sequence\n! is the resulting letter sequence.\n!\n! B) Starting with the string containing the single letter '0',\n! repeatedly append the binary complement of the string to itself.\n! Thus, '0' becomes '0' + '1' or '01', then '01' becomes\n! '01' + '10', which becomes '0110' + '1001', and so on.\n!\n! C) Starting with I = 0, the I-th Morse-Thue number is determined\n! by taking the binary representation of I, adding the digits,\n! and computing the remainder modulo 2.\n!\n! Example:\n!\n! I binary S\n! -- ------ --\n! 0 0 0\n! 1 1 1\n! 2 10 1\n! 3 11 0\n! 4 100 1\n! 5 101 0\n! 6 110 0\n! 7 111 1\n! 8 1000 1\n!\n! Modified:\n!\n! 17 December 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer I, the index of the Morse-Thue number.\n! Normally, I is 0 or greater, but any value is allowed.\n!\n! Output, integer S, the Morse-Thue number of index I.\n!\n implicit none\n!\n integer, parameter :: nbits = 32\n!\n integer b(nbits)\n integer i\n integer i_copy\n integer s\n!\n i_copy = abs ( i )\n!\n! Expand I into binary form.\n!\n call i_to_ivec_binary ( i_copy, nbits, b )\n!\n! Sum the 1's in the binary representation.\n!\n s = sum ( b(1:nbits) )\n!\n! Take the value modulo 2.\n!\n s = mod ( s, 2 )\n\n return\nend\nsubroutine multinomial_coef1 ( nfactor, factor, ncomb )\n!\n!*******************************************************************************\n!\n!! MULTINOMIAL_COEF1 computes a multinomial coefficient.\n!\n!\n! Definition:\n!\n! The multinomial coefficient is a generalization of the binomial\n! coefficient. It may be interpreted as the number of combinations of\n! N objects, where FACTOR(1) objects are indistinguishable of type 1,\n! ... and FACTOR(NFACTOR) are indistinguishable of type NFACTOR,\n! and N is the sum of FACTOR(1) through FACTOR(NFACTOR).\n!\n! Formula:\n!\n! NCOMB = N! / ( FACTOR(1)! FACTOR(2)! ... FACTOR(NFACTOR)! )\n!\n! Method:\n!\n! The log of the gamma function is used, to avoid overflow.\n!\n! Modified:\n!\n! 16 June 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer NFACTOR, the number of factors.\n!\n! Input, integer FACTOR(NFACTOR), contains the factors.\n! 0 <= FACTOR(I)\n!\n! Output, integer NCOMB, the value of the multinomial coefficient.\n!\n implicit none\n!\n integer nfactor\n!\n real arg\n real fack\n real facn\n integer factor(nfactor)\n real gamma_log\n integer i\n integer n\n integer ncomb\n!\n! Each factor must be nonnegative.\n!\n do i = 1, nfactor\n\n if ( factor(i) < 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'MULTINOMIAL_COEF1 - Fatal error'\n write ( *, '(a,i6,a,i6)' ) ' Factor ', I, ' = ', factor(i)\n write ( *, '(a)' ) ' But this value must be nonnegative.'\n stop\n end if\n\n end do\n!\n! The factors sum to N.\n!\n n = sum ( factor(1:nfactor) )\n\n arg = real ( n + 1 )\n facn = gamma_log ( arg )\n\n do i = 1, nfactor\n\n arg = real ( factor(i) + 1 )\n fack = gamma_log ( arg )\n facn = facn - fack\n\n end do\n\n ncomb = nint ( exp ( facn ) )\n\n return\nend\nsubroutine multinomial_coef2 ( nfactor, factor, ncomb )\n!\n!*******************************************************************************\n!\n!! MULTINOMIAL_COEF2 computes a multinomial coefficient.\n!\n!\n! Definition:\n!\n! The multinomial coefficient is a generalization of the binomial\n! coefficient. It may be interpreted as the number of combinations of\n! N objects, where FACTOR(1) objects are indistinguishable of type 1,\n! ... and FACTOR(NFACTOR) are indistinguishable of type NFACTOR,\n! and N is the sum of FACTOR(1) through FACTOR(NFACTOR).\n!\n! Formula:\n!\n! NCOMB = N! / ( FACTOR(1)! FACTOR(2)! ... FACTOR(NFACTOR)! )\n!\n! Method:\n!\n! A direct method is used, which should be exact. However, there\n! is a possibility of intermediate overflow of the result.\n!\n! Modified:\n!\n! 01 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer NFACTOR, the number of factors.\n!\n! Input, integer FACTOR(NFACTOR), contains the factors.\n! 0 <= FACTOR(I)\n!\n! Output, integer NCOMB, the value of the multinomial coefficient.\n!\n implicit none\n!\n integer nfactor\n!\n integer factor(nfactor)\n integer i\n integer j\n integer k\n integer ncomb\n!\n! Each factor must be nonnegative.\n!\n do i = 1, nfactor\n\n if ( factor(i) < 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'MULTINOMIAL_COEF2 - Fatal error'\n write ( *, '(a,i6,a,i6)' ) ' Factor ', I, ' = ', factor(i)\n write ( *, '(a)' ) ' But this value must be nonnegative.'\n stop\n end if\n\n end do\n\n ncomb = 1\n k = 0\n\n do i = 1, nfactor\n\n do j = 1, factor(i)\n k = k + 1\n ncomb = ( ncomb * k ) / j\n end do\n\n end do\n\n return\nend\nsubroutine network_flow_max ( nnode, nedge, iendpt, icpflo, isorce, isink, &\n icut, node_flow )\n!\n!*******************************************************************************\n!\n!! NETWORK_FLOW_MAX finds the maximal flow and a minimal cut in a network.\n!\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 31 July 2000\n!\n! Parameters:\n!\n! Input, integer NNODE, the number of nodes.\n!\n! Input, integer NEDGE, the number of edges.\n!\n! Input/output, integer IENDPT(2,NEDGE), the edges of the network,\n! defined as pairs of nodes. Each edge should be listed TWICE,\n! the second time in reverse order. On output, the edges have\n! been reordered, and so the columns of IENDPT have been rearranged.\n!\n! Input/output, integer ICPFLO(2,NEDGE). Capacities and flows.\n! On input, ICPFLO(1,I) is the capacity of edge I. On output,\n! ICPFLO(2,I) is the flow on edge I and ICPFLO(1,I) has\n! been rearranged to match the reordering of IENDPT.\n!\n! Input, integer ISORCE, the designated source node.\n!\n! Input, integer ISINK, the designated sink node.\n!\n! Output, integer ICUT(NNODE). ICUT(I) = 1 if node I is in the\n! minimal cut set, otherwise 0.\n!\n! Output, integer NODE_FLOW(NNODE). NODE_FLOW(I) is the value of the flow\n! through node I.\n!\n implicit none\n!\n integer nedge\n integer nnode\n!\n integer i\n integer iarray(nnode)\n integer icpflo(2,nedge)\n integer icut(nnode)\n integer idel\n integer ien1\n integer ien2\n integer iendpt(2,nedge)\n integer indx\n integer ip\n integer iparm\n integer iq\n integer ir\n integer iread\n integer irite\n integer is\n integer isink\n integer isorce\n integer isort\n integer it\n integer iwork(nnode,2)\n integer j\n integer kz\n integer lst\n integer m\n integer node_flow(nnode)\n!\n iarray(1:nnode) = 0\n idel = 0\n\n do i = 1, nedge\n\n icpflo(2,i) = 0\n ip = iendpt(1,i)\n\n if ( ip == isorce ) then\n idel = idel + icpflo(1,i)\n end if\n\n iarray(ip) = iarray(ip) + 1\n\n end do\n\n node_flow(isorce) = idel\n is = 1\n\n do i = 1, nnode\n it = iarray(i)\n iarray(i) = is\n iwork(i,1) = is\n is = is + it\n end do\n\n isort = 0\n ien1 = 0\n ien2 = 0\n\n10 continue\n\n indx = 0\n\n50 continue\n\n do\n\n call sort_heap_external ( nedge, indx, ien1, ien2, is )\n\n if ( indx < 0 ) then\n\n is = iendpt(1,ien1) - iendpt(1,ien2)\n\n if ( is == 0 ) then\n is = iendpt(2,ien1) - iendpt(2,ien2)\n end if\n\n else if ( indx > 0 ) then\n\n do ir = 1, 2\n call i_swap ( iendpt(ir,ien1), iendpt(ir,ien2) )\n call i_swap ( icpflo(ir,ien1), icpflo(ir,ien2) )\n end do\n\n else\n\n if ( isort > 0 ) then\n return\n end if\n\n do i = 1, nedge\n iq = iendpt(2,i)\n iendpt(1,i) = iwork(iq,1)\n iwork(iq,1) = iwork(iq,1) + 1\n end do\n\n go to 100\n\n end if\n\n end do\n\n80 continue\n\n iendpt(1,iendpt(1,ien1)) = ien2\n iendpt(1,iendpt(1,ien2)) = ien1\n\n do ir = 1, 2\n call i_swap ( iendpt(ir,ien1), iendpt(ir,ien2) )\n call i_swap ( icpflo(ir,ien1), icpflo(ir,ien2) )\n end do\n\n if ( indx < 0 ) then\n go to 270\n end if\n\n if ( indx == 0 ) then\n go to 170\n end if\n\n go to 50\n\n100 continue\n\n indx = 0\n\n do i = 1, nnode\n\n if ( i /= isorce ) then\n node_flow(i) = 0\n end if\n\n iwork(i,2) = nedge + 1\n\n if ( i < nnode ) then\n iwork(i,2) = iarray(i+1)\n end if\n\n icut(i) = 0\n\n end do\n\n iread = 0\n irite = 1\n iwork(1,1) = isorce\n icut(isorce) = - 1\n\n120 continue\n\n iread = iread + 1\n\n if ( iread <= irite ) then\n\n ip = iwork(iread,1)\n lst = iwork(ip,2) - 1\n i = iarray(ip) - 1\n\n do\n\n i = i + 1\n\n if ( i > lst ) then\n go to 120\n end if\n\n iq = iendpt(2,i)\n idel = icpflo(1,i) - icpflo(2,i)\n\n if ( icut(iq) == 0 .and. idel /= 0 ) then\n\n if ( iq /= isink ) then\n irite = irite + 1\n iwork(irite,1) = iq\n end if\n\n icut(iq) = - 1\n\n end if\n\n end do\n\n end if\n\n if ( icut(isink) == 0 ) then\n\n icut(1:nnode) = - icut(1:nnode)\n\n do i = 1, nedge\n ip = iendpt(2,iendpt(1,i))\n if ( icpflo(2,i) < 0 ) then\n node_flow(ip) = node_flow(ip) - icpflo(2,i)\n end if\n iendpt(1,i) = ip\n end do\n\n node_flow(isorce) = node_flow(isink)\n isort = 1\n go to 10\n\n end if\n\n icut(isink) = 1\n\n160 continue\n\n iread = iread - 1\n\n if ( iread == 0 ) then\n go to 180\n end if\n\n ip = iwork(iread,1)\n ien1 = iarray(ip) - 1\n ien2 = iwork(ip,2) - 1\n\n170 continue\n\n if ( ien1 /= ien2 ) then\n\n iq = iendpt(2,ien2)\n\n if ( icut(iq) <= 0 .or. icpflo(1,ien2) == icpflo(2,ien2) ) then\n ien2 = ien2 - 1\n go to 170\n end if\n\n iendpt(2,ien2) = - iq\n icpflo(1,ien2) = icpflo(1,ien2) - icpflo(2,ien2)\n icpflo(2,ien2) = 0\n ien1 = ien1 + 1\n\n if ( ien1 < ien2 ) then\n go to 80\n end if\n\n end if\n\n if ( ien1 >= iarray(ip) ) then\n icut(ip) = ien1\n end if\n\n go to 160\n\n180 continue\n\n kz = 0\n\n do ir = 1, irite\n if ( icut(iwork(ir,1)) > 0 ) then\n kz = kz + 1\n iwork(kz,1) = iwork(ir,1)\n end if\n end do\n\n indx = - 1\n m = 1\n\n200 continue\n\n ip = iwork(m,1)\n\n if ( node_flow(ip) > 0 ) then\n go to 250\n end if\n\n210 continue\n\n m = m + 1\n\n if ( m <= kz ) then\n go to 200\n end if\n\n iparm = 0\n\n220 continue\n\n m = m - 1\n\n if ( m == 1 ) then\n\n do i = 1, nedge\n\n iq = - iendpt(2,i)\n\n if ( iq >= 0 ) then\n\n iendpt(2,i) = iq\n j = iendpt(1,i)\n icpflo(1,i) = icpflo(1,i) - icpflo(2,j)\n\n idel = icpflo(2,i) - icpflo(2,j)\n icpflo(2,i) = idel\n icpflo(2,j) = - idel\n\n end if\n\n end do\n\n go to 100\n\n end if\n\n ip = iwork(m,1)\n\n if ( node_flow(ip) < 0 ) then\n go to 220\n end if\n\n if ( node_flow(ip) == 0 ) then\n\n lst = nedge + 1\n\n if ( ip < nnode ) then\n lst = iarray(ip+1)\n end if\n\n i = iwork(ip,2)\n iwork(ip,2) = lst\n\n do\n\n if ( i == lst ) then\n go to 220\n end if\n\n j = iendpt(1,i)\n idel = icpflo(2,j)\n icpflo(2,j) = 0\n icpflo(1,j) = icpflo(1,j) - idel\n icpflo(2,i) = icpflo(2,i) - idel\n i = i + 1\n\n end do\n\n end if\n\n if ( iarray(ip) > icut(ip) ) then\n go to 300\n end if\n\n250 continue\n\n i = icut(ip) + 1\n\n260 continue\n\n do\n\n i = i - 1\n\n if ( i < iarray(ip) ) then\n go to 290\n end if\n\n iq = - iendpt(2,i)\n\n if ( node_flow(iq) >= 0 ) then\n exit\n end if\n\n end do\n\n idel = icpflo(1,i) - icpflo(2,i)\n\n if ( node_flow(ip) < idel ) then\n idel = node_flow(ip)\n end if\n\n icpflo(2,i) = icpflo(2,i) + idel\n node_flow(ip) = node_flow(ip) - idel\n node_flow(iq) = node_flow(iq) + idel\n iparm = 1\n ien1 = iendpt(1,i)\n ien2 = iwork(iq,2) - 1\n\n if ( ien1 < ien2 ) then\n go to 80\n end if\n\n if ( ien1 /= ien2 ) then\n go to 280\n end if\n\n270 continue\n\n iwork(iq,2) = ien2\n\n280 continue\n\n if ( node_flow(ip) > 0 ) then\n go to 260\n end if\n\n if ( icpflo(1,i) == icpflo(2,i) ) then\n i = i - 1\n end if\n\n290 continue\n\n icut(ip) = i\n\n if ( iparm /= 0 ) then\n go to 210\n end if\n\n300 continue\n\n i = iwork(ip,2)\n\n310 continue\n\n j = iendpt(1,i)\n idel = icpflo(2,j)\n\n if ( node_flow(ip) < idel ) then\n idel = node_flow(ip)\n end if\n\n icpflo(2,j) = icpflo(2,j) - idel\n node_flow(ip) = node_flow(ip) - idel\n iq = iendpt(2,i)\n node_flow(iq) = node_flow(iq) + idel\n i = i + 1\n\n if ( node_flow(ip) > 0 ) then\n go to 310\n end if\n\n node_flow(ip) = - 1\n go to 220\n\nend\nsubroutine nim_sum ( i, j, k )\n!\n!*******************************************************************************\n!\n!! NIM_SUM computes the Nim sum of two integers.\n!\n!\n! Discussion:\n!\n! If K is the Nim sum of I and J, then each bit of K is the exclusive\n! OR of the corresponding bits of I and J.\n!\n! Example:\n!\n! I J K I_2 J_2 K_2\n! ---- ---- ---- ---------- ---------- ----------\n! 0 0 0 0 0 0\n! 1 0 1 1 0 1\n! 1 1 0 1 1 0\n! 2 7 5 10 111 101\n! 11 28 23 1011 11100 10111\n!\n! Modified:\n!\n! 08 May 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer I, J, the integers to be Nim-summed.\n!\n! Input, integer K, the Nim sum of I and J.\n!\n implicit none\n!\n integer, parameter :: nbits = 32\n!\n integer i\n integer ivec(nbits)\n integer j\n integer jvec(nbits)\n integer k\n integer kvec(nbits)\n!\n call i_to_ivec_binary ( i, nbits, ivec )\n call i_to_ivec_binary ( j, nbits, jvec )\n call ivec_binary_xor ( nbits, ivec, jvec, kvec )\n call ivec_binary_to_i ( nbits, kvec, k )\n\n return\nend\nsubroutine pell_basic ( d, x0, y0 )\n!\n!*******************************************************************************\n!\n!! PELL_BASIC returns the fundamental solution for Pell's basic equation.\n!\n!\n! Discussion:\n!\n! Pell's equation has the form:\n!\n! X**2 - D * Y**2 = 1\n!\n! where D is a given non-square integer, and X and Y may be assumed\n! to be positive integers.\n!\n! Example:\n!\n! D X0 Y0\n!\n! 2 3 2\n! 3 2 1\n! 5 9 4\n! 6 5 2\n! 7 8 3\n! 8 3 1\n! 10 19 6\n! 11 10 3\n! 12 7 2\n! 13 649 180\n! 14 15 4\n! 15 4 1\n! 17 33 8\n! 18 17 4\n! 19 170 39\n! 20 9 2\n!\n! Reference:\n!\n! Mark Herkommer,\n! Number Theory, A Programmer's Guide,\n! McGraw Hill, 1999, pages 294-307\n!\n! Modified:\n!\n! 19 May 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer D, the coefficient in Pell's equation. D should be\n! positive, and not a perfect square.\n!\n! Output, integer X0, Y0, the fundamental or 0'th solution.\n! If X0 = Y0 = 0, then the calculation was canceled because of an error.\n! Both X0 and Y0 will be nonnegative.\n!\n implicit none\n!\n integer, parameter :: max_term = 100\n!\n integer b(0:max_term)\n integer d\n integer i\n integer n_term\n integer p\n integer pm1\n integer pm2\n integer q\n integer qm1\n integer qm2\n integer r\n integer x0\n integer y0\n!\n! If these values are returned, an error has occurred.\n!\n x0 = 0\n y0 = 0\n!\n! Check D.\n!\n if ( d <= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PELL_BASIC - Fatal error!'\n write ( *, '(a)' ) ' Pell coefficient D <= 0.'\n return\n end if\n\n call i_sqrt ( d, q, r )\n\n if ( r == 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PELL_BASIC - Fatal error!'\n write ( *, '(a)' ) ' Pell coefficient is a perfect square.'\n return\n end if\n!\n! Find the continued fraction representation of sqrt ( D ).\n!\n call i_sqrt_cf ( d, max_term, n_term, b )\n!\n! If necessary, go for two periods.\n!\n if ( mod ( n_term, 2 ) == 1 ) then\n\n do i = n_term + 1, 2*n_term\n b(i) = b(i-n_term)\n end do\n\n n_term = 2 * n_term\n\n end if\n!\n! Evaluate the continued fraction using the forward recursion algorithm.\n!\n pm2 = 0\n pm1 = 1\n qm2 = 1\n qm1 = 0\n\n do i = 0, n_term-1\n p = b(i) * pm1 + pm2\n q = b(i) * qm1 + qm2\n pm2 = pm1\n pm1 = p\n qm2 = qm1\n qm1 = q\n end do\n!\n! Get the fundamental solution.\n!\n x0 = p\n y0 = q\n\n return\nend\nsubroutine pell_next ( d, x0, y0, xn, yn, xnp1, ynp1 )\n!\n!*******************************************************************************\n!\n!! PELL_NEXT returns the next solution of Pell's equation.\n!\n!\n! Discussion:\n!\n! Pell's equation has the form:\n!\n! X**2 - D * Y**2 = 1\n!\n! where D is a given non-square integer, and X and Y may be assumed\n! to be positive integers.\n!\n! To compute X0, Y0, call PELL_BASIC.\n! To compute X1, Y1, call this routine, with XN and YN set to X0 and Y0.\n! To compute further solutions, call again with X0, Y0 and the previous\n! solution.\n!\n! Example:\n!\n! ------INPUT-------- --OUTPUT--\n!\n! D X0 Y0 XN YN XNP1 YNP1\n!\n! 2 3 2 3 2 17 12\n! 2 3 2 17 12 99 70\n! 2 3 2 99 70 577 408\n! 2 3 2 577 408 3363 2378\n!\n! Reference:\n!\n! Mark Herkommer,\n! Number Theory, A Programmer's Guide,\n! McGraw Hill, 1999, pages 294-307\n!\n! Modified:\n!\n! 16 May 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer D, the coefficient in Pell's equation.\n!\n! Input, integer X0, Y0, the fundamental or 0'th solution.\n!\n! Input, integer XN, YN, the N-th solution.\n!\n! Output, integer XNP1, YNP1, the N+1-th solution.\n!\n implicit none\n!\n integer d\n integer x0\n integer xn\n integer xnp1\n integer y0\n integer yn\n integer ynp1\n!\n xnp1 = x0 * xn + d * y0 * yn\n ynp1 = x0 * yn + y0 * xn\n\n return\nend\nsubroutine pent_enum ( n, p )\n!\n!*******************************************************************************\n!\n!! PENT_ENUM computes the N-th pentagonal number.\n!\n!\n! Definition:\n!\n! The pentagonal number P(N) counts the number of dots in a figure of\n! N nested pentagons. The pentagonal numbers are defined for both\n! positive and negative N.\n!\n! First values:\n!\n! N P\n!\n! -5 40\n! -4 26\n! -3 15\n! -2 7\n! -1 2\n! 0 0\n! 1 1\n! 2 5\n! 3 12\n! 4 22\n! 5 35\n!\n! Formula:\n!\n! P(N) = ( N * ( 3 * N - 1 ) ) / 2\n!\n! Modified:\n!\n! 22 September 1998\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the index of the pentagonal number desired.\n!\n! Output, integer P, the value of the N-th pentagonal number.\n!\n implicit none\n!\n integer n\n integer p\n!\n p = ( n * ( 3 * n - 1 ) ) / 2\n\n return\nend\nsubroutine perm_ascend ( n, a, length, sub )\n!\n!*******************************************************************************\n!\n!! PERM_ASCEND computes the longest ascending subsequence of permutation.\n!\n!\n! Discussion:\n!\n! Although this routine is intended to be applied to a permutation,\n! it will work just as well for an arbitrary vector.\n!\n! Modified:\n!\n! 07 May 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the order of the permutation.\n!\n! Input, integer A(N), the permutation to be examined.\n!\n! Output, integer LENGTH, the length of the longest increasing subsequence.\n!\n! Output, integer SUB(N), contains in entries 1 through LENGTH\n! a longest increasing subsequence of A.\n!\n implicit none\n!\n integer n\n!\n integer a(n)\n integer a1\n integer a2\n integer i\n integer j\n integer k\n integer length\n integer sub(n)\n integer top(n)\n integer top_prev(n)\n!\n top(1:n) = 0\n top_prev(1:n) = 0\n sub(1:n) = 0\n\n if ( n <= 0 ) then\n length = 0\n return\n end if\n\n length = 0\n\n do i = 1, n\n\n k = 0\n\n do j = 1, length\n if ( a(i) <= a(top(j)) ) then\n k = j\n exit\n end if\n end do\n\n if ( k == 0 ) then\n length = length + 1\n k = length\n end if\n\n top(k) = i\n\n if ( k > 1 ) then\n top_prev(i) = top(k-1)\n else\n top_prev(i) = 0\n end if\n\n end do\n\n j = top(length)\n sub(length) = a(j)\n\n do i = length-1, 1, -1\n j = top_prev(j)\n sub(i) = a(j)\n end do\n\n return\nend\nsubroutine perm_break_count ( n, p, break_count )\n!\n!*******************************************************************************\n!\n!! PERM_BREAK_COUNT counts the number of \"breaks\" in a permutation.\n!\n!\n! Discussion:\n!\n! We begin with a permutation of order N. We prepend an element\n! labeled \"0\" and append an element labeled \"N+1\". There are now\n! N+1 pairs of neighbors. A \"break\" is a pair of neighbors whose\n! value differs by more than 1. \n!\n! The identity permutation has a break count of 0. The maximum\n! break count is N+1.\n!\n! Modified:\n!\n! 25 October 2001\n!\n! Parameters:\n!\n! Input, integer N, the order of the permutation.\n!\n! Input, integer P(N), a permutation, in standard index form.\n!\n! Output, integer BREAK_COUNT, the number of breaks in the permutation.\n!\n implicit none\n!\n integer n\n!\n integer break_count\n integer i\n integer ierror\n integer p(n)\n!\n break_count = 0\n!\n! Make sure the permutation is a legal one.\n! (This is not an efficient way to do so!)\n!\n call perm_check ( n, p, ierror )\n\n if ( ierror /= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PERM_BREAK_COUNT - Fatal error!'\n write ( *, '(a)' ) ' The input array does not represent'\n write ( *, '(a)' ) ' a proper permutation. In particular, the'\n write ( *, '(a,i6)' ) ' array is missing the value ', ierror\n stop\n end if\n\n if ( p(1) /= 1 ) then\n break_count = break_count + 1\n end if\n\n do i = 1, n-1\n if ( abs ( p(i+1) - p(i) ) /= 1 ) then\n break_count = break_count + 1\n end if\n end do\n\n if ( p(n) /= n ) then\n break_count = break_count + 1\n end if\n\n return\nend\nsubroutine perm_canon_to_cycle ( n, p1, p2 )\n!\n!*******************************************************************************\n!\n!! PERM_CANON_TO_CYCLE converts a permutation from canonical to cycle form.\n!\n!\n! Example:\n!\n! Input:\n!\n! 4 5 2 1 6 3\n!\n! Output:\n!\n! -4 5 -2 -1 6 3,\n! indicating the cycle structure\n! ( 4, 5 ) ( 2 ) ( 1, 6, 3 )\n!\n! Reference:\n!\n! Donald Knuth,\n! The Art of Computer Programming,\n! Volume 1, Fundamental Algorithms,\n! Addison Wesley, 1968, page 176.\n!\n! Modified:\n!\n! 30 July 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of objects permuted.\n!\n! Input, integer P1(N), the permutation, in canonical form.\n!\n! Output, integer P2(N), the permutation, in cycle form.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer p1(n)\n integer p2(n)\n integer pmin\n!\n p2(1:n) = p1(1:n)\n\n pmin = p2(1) + 1\n\n do i = 1, n\n\n if ( p2(i) < pmin ) then\n pmin = p2(i)\n p2(i) = - p2(i)\n end if\n\n end do\n\n return\nend\nsubroutine perm_check ( n, p, ierror )\n!\n!*******************************************************************************\n!\n!! PERM_CHECK checks that a vector represents a permutation.\n!\n!\n! Discussion:\n!\n! The routine verifies that each of the integers from 1\n! to N occurs among the N entries of the permutation.\n!\n! Modified:\n!\n! 06 August 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of entries.\n!\n! Input, integer P(N), the permutation, in standard index form.\n!\n! Output, integer IERROR, error flag.\n! 0, the array does represent a permutation.\n! nonzero, the array does not represent a permutation. The smallest\n! missing value is equal to IERROR.\n!\n implicit none\n!\n integer n\n!\n integer ierror\n integer ifind\n integer iseek\n integer p(n)\n!\n ierror = 0\n\n do iseek = 1, n\n\n ierror = iseek\n\n do ifind = 1, n\n if ( p(ifind) == iseek ) then\n ierror = 0\n exit\n end if\n end do\n\n if ( ierror /= 0 ) then\n return\n end if\n\n end do\n\n return\nend\nsubroutine perm_cycle ( n, p, isgn, ncycle, iopt )\n!\n!*******************************************************************************\n!\n!! PERM_CYCLE analyzes a permutation.\n!\n!\n! Discussion:\n!\n! The routine will count cycles, find the sign of a permutation,\n! and tag a permutation.\n!\n! Example:\n!\n! Input:\n!\n! N = 9\n! IOPT = 1\n! P = 2, 3, 9, 6, 7, 8, 5, 4, 1\n!\n! Output:\n!\n! NCYCLE = 3\n! ISGN = +1\n! P = -2, 3, 9, -6, -7, 8, 5, 4, 1\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Input, integer N, the number of objects being permuted.\n!\n! Input/output, integer P(N). On input, P describes a\n! permutation, in the sense that entry I is to be moved to P(I).\n! If IOPT = 0, then P will not be changed by this routine.\n! If IOPT = 1, then on output, P will be \"tagged\". That is,\n! one element of every cycle in P will be negated. In this way,\n! a user can traverse a cycle by starting at any entry I1 of P\n! which is negative, moving to I2 = ABS(P(I1)), then to\n! P(I2), and so on, until returning to I1.\n!\n! Output, integer ISGN, the \"sign\" of the permutation, which is\n! +1 if the permutation is even, -1 if odd. Every permutation\n! may be produced by a certain number of pairwise switches.\n! If the number of switches is even, the permutation itself is\n! called even.\n!\n! Output, integer NCYCLE, the number of cycles in the permutation.\n!\n! Input, integer IOPT, requests tagging.\n! 0, the permutation will not be tagged.\n! 1, the permutation will be tagged.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer i1\n integer i2\n integer ierror\n integer iopt\n integer is\n integer isgn\n integer ncycle\n integer p(n)\n!\n call perm_check ( n, p, ierror )\n\n if ( ierror /= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PERM_CYCLE - Fatal error!'\n write ( *, '(a)' ) ' The input array does not represent'\n write ( *, '(a)' ) ' a proper permutation. In particular, the'\n write ( *, '(a,i6)' ) ' array is missing the value ', ierror\n stop\n end if\n\n is = 1\n ncycle = n\n\n do i = 1, n\n\n i1 = p(i)\n\n do while ( i1 > i )\n ncycle = ncycle - 1\n i2 = p(i1)\n p(i1) = - i2\n i1 = i2\n end do\n\n if ( iopt /= 0 ) then\n is = - sign ( 1, p(i) )\n end if\n\n p(i) = sign ( p(i), is )\n\n end do\n\n isgn = 1 - 2 * mod ( n - ncycle, 2 )\n\n return\nend\nsubroutine perm_cycle_to_canon ( n, p1, p2 )\n!\n!*******************************************************************************\n!\n!! PERM_CYCLE_TO_CANON converts a permutation from cycle to canonical form.\n!\n!\n! Example:\n!\n! Input:\n!\n! -6 3 1 -5, 4 -2,\n! indicating the cycle structure\n! ( 6, 3, 1 ) ( 5, 4 ) ( 2 )\n!\n! Output:\n!\n! 4 5 2 1 6 3\n!\n! Discussion:\n!\n! The procedure is to \"rotate\" the elements of each cycle so that\n! the smallest element is first:\n!\n! ( 1, 6, 3 ) ( 4, 5 ) ( 2 )\n!\n! and then to sort the cycles in decreasing order of their first\n! (and lowest) element:\n!\n! ( 4, 5 ) ( 2 ) ( 1, 6, 3 )\n!\n! and then to drop the parentheses:\n!\n! 4 5 2 1 6 3\n!\n! Reference:\n!\n! Donald Knuth,\n! The Art of Computer Programming,\n! Volume 1, Fundamental Algorithms,\n! Addison Wesley, 1968, pages 176.\n!\n! Modified:\n!\n! 31 July 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of objects permuted.\n!\n! Input, integer P1(N), the permutation, in cycle form.\n!\n! Output, integer P2(N), the permutation, in canonical form.\n!\n implicit none\n!\n integer n\n!\n integer hi(n)\n integer i\n integer indx(n)\n integer j\n integer k\n integer lo(n)\n integer ncycle\n integer next\n integer nhi\n integer nlo\n integer nmin\n integer p1(n)\n integer p2(n)\n integer pmin(n)\n integer ptemp(n)\n!\n p2(1:n) = p1(1:n)\n!\n! Work on the next cycle.\n!\n nlo = 1\n ncycle = 0\n\n do while ( nlo <= n )\n!\n! Identify NHI, the last index in this cycle.\n!\n ncycle = ncycle + 1\n\n nhi = nlo\n\n do while ( nhi < n )\n if ( p2(nhi+1) < 0 ) then\n exit\n end if\n nhi = nhi + 1\n end do\n!\n! Identify the smallest value in this cycle.\n!\n p2(nlo) = - p2(nlo)\n pmin(ncycle) = p2(nlo)\n nmin = nlo\n\n do i = nlo+1, nhi\n if ( p2(i) < pmin(ncycle) ) then\n pmin(ncycle) = p2(i)\n nmin = i\n end if\n end do\n!\n! Rotate the cycle so A_MIN occurs first.\n!\n ptemp(nlo+nhi+1-nmin:nhi) = p2(nlo:nmin-1)\n ptemp(nlo:nlo+nhi-nmin) = p2(nmin:nhi)\n\n lo(ncycle) = nlo\n hi(ncycle) = nhi\n!\n! Prepare to operate on the next cycle.\n!\n nlo = nhi + 1\n\n end do\n!\n! Compute a sorting index for the cycle minima.\n!\n call ivec_sort_heap_index_d ( ncycle, pmin, indx )\n!\n! Copy the cycles out of the temporary array in sorted order.\n!\n j = 0\n do i = 1, ncycle\n next = indx(i)\n nlo = lo(next)\n nhi = hi(next)\n do k = nlo, nhi\n j = j + 1\n p2(j) = ptemp(k)\n end do\n end do\n\n return\nend\nsubroutine perm_cycle_to_index ( n, p1, p2 )\n!\n!*******************************************************************************\n!\n!! PERM_CYCLE_TO_INDEX converts a permutation from cycle to standard index form.\n!\n!\n! Example:\n!\n! Input:\n!\n! N = 9\n! P1 = -1, 2, 3, 9, -4, 6, 8, -5, 7\n!\n! Output:\n!\n! P2 = 2, 3, 9, 6, 7, 8, 5, 4, 1\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 31 July 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of objects being permuted.\n!\n! Input, integer P1(N), the permutation, in cycle form.\n!\n! Output, integer P2(N), the permutation, in standard index form.\n!\n implicit none\n!\n integer n\n!\n integer j\n integer k1\n integer k2\n integer k3\n integer p1(n)\n integer p2(n)\n!\n do j = 1, n\n\n k1 = p1(j)\n\n if ( k1 < 0 ) then\n k1 = - k1\n k3 = k1\n end if\n\n if ( j + 1 <= n ) then\n k2 = p1(j+1)\n if ( k2 < 0 ) then\n k2 = k3\n end if\n else\n k2 = k3\n end if\n\n p2(k1) = k2\n\n end do\n\n return\nend\nsubroutine perm_distance ( n, a, b, k )\n!\n!*******************************************************************************\n!\n!! PERM_DISTANCE computes the Ulam metric distance of two permutations.\n!\n!\n! Discussion:\n!\n! If we let N be the order of the permutations A and B, and L(P) be\n! the length of the longest ascending subsequence of a permutation P,\n! then the Ulam metric distance between A and B is\n!\n! N - L ( A * inverse ( B ) ).\n!\n! Modified:\n!\n! 08 May 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the order of the permutation.\n!\n! Input, integer A(N), B(N), the permutations to be examined.\n!\n! Output, integer K, the Ulam metric distance between A and B.\n!\n implicit none\n!\n integer n\n!\n integer a(n)\n integer b(n)\n integer binv(n)\n integer c(n)\n integer k\n integer length\n integer sub(n)\n!\n binv(1:n) = b(1:n)\n\n call perm_inv ( n, binv )\n\n call perm_mul ( n, a, binv, c )\n\n call perm_ascend ( n, c, length, sub )\n\n k = n - length\n\n return\nend\nsubroutine perm_fixed_enum ( n, m, fnm )\n!\n!*******************************************************************************\n!\n!! PERM_FIXED_ENUM enumerates the permutations of N objects with M fixed.\n!\n!\n! Definition:\n!\n! A permutation of N objects with M fixed is a permutation in which\n! exactly M of the objects retain their original positions. If\n! M = 0, the permutation is a \"derangement\". If M = N, the\n! permutation is the identity.\n!\n! Formula:\n!\n! F(N,M) = ( N! / M! ) * ( 1 - 1/1! + 1/2! - 1/3! ... 1/(N-M)! )\n! = COMB(N,M) * D(N-M)\n! where D(N-M) is the number of derangements of N-M objects.\n!\n! Modified:\n!\n! 31 January 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of objects to be permuted.\n! N should be at least 1.\n!\n! Input, integer M, the number of objects that retain their\n! position. M should be between 0 and N.\n!\n! Output, integer FNM, the number of derangements of N objects\n! in which M objects retain their positions.\n!\n implicit none\n!\n integer derange_enum\n integer fnm\n integer icnm\n integer m\n integer n\n!\n if ( n <= 0 ) then\n\n fnm = 1\n\n else if ( m < 0 ) then\n\n fnm = 0\n\n else if ( m > n ) then\n\n fnm = 0\n\n else if ( m == n ) then\n\n fnm = 1\n\n else if ( n == 1 ) then\n\n if ( m == 1 ) then\n fnm = 1\n else\n fnm = 0\n end if\n\n else\n\n call combin2 ( n, m, icnm )\n\n fnm = icnm * derange_enum ( n - m )\n\n end if\n\n return\nend\nsubroutine perm_free ( ipart, npart, ifree, nfree )\n!\n!*******************************************************************************\n!\n!! PERM_FREE reports the number of unused items in a partial permutation.\n!\n!\n! Discussion:\n!\n! It is assumed that the N objects being permuted are the integers\n! from 1 to N, and that IPART contains a \"partial\" permutation, that\n! is, the NPART entries of IPART represent the beginning of a\n! permutation of all N items.\n!\n! The routine returns in IFREE the items that have not been used yet.\n!\n! Modified:\n!\n! 12 March 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer IPART(NPART), the partial permutation, which should\n! contain, at most once, some of the integers between 1 and\n! NPART+NFREE.\n!\n! Input, integer NPART, the number of entries in IPART. NPART may be 0.\n!\n! Output, integer IFREE(NFREE), the integers between 1 and NPART+NFREE\n! that were not used in IPART.\n!\n! Input, integer NFREE, the number of integers that have not been\n! used in IPART. This is simply N - NPART. NFREE may be zero.\n!\n implicit none\n!\n integer nfree\n integer npart\n!\n integer i\n integer ifree(nfree)\n integer ipart(npart)\n integer j\n integer k\n integer match\n integer n\n!\n n = npart + nfree\n\n if ( npart < 0 ) then\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PERM_FREE - Fatal error!'\n write ( *, '(a)' ) ' NPART < 0.'\n stop\n\n else if ( npart == 0 ) then\n\n call ivec_identity ( n, ifree )\n\n else if ( nfree < 0 ) then\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PERM_FREE - Fatal error!'\n write ( *, '(a)' ) ' NFREE < 0.'\n stop\n\n else if ( nfree == 0 ) then\n\n return\n\n else\n\n k = 0\n\n do i = 1, n\n\n match = 0\n\n do j = 1, npart\n if ( ipart(j) == i ) then\n match = j\n exit\n end if\n end do\n\n if ( match == 0 ) then\n\n k = k + 1\n\n if ( k > nfree ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PERM_FREE - Fatal error!'\n write ( *, '(a)' ) ' The partial permutation is illegal.'\n write ( *, '(a)' ) ' It should contain, at most once, some of'\n write ( *, '(a,i6)' ) ' the integers between 1 and ', n\n stop\n end if\n\n ifree(k) = i\n\n end if\n\n end do\n\n end if\n\n return\nend\nsubroutine perm_index_to_cycle ( n, p1, p2 )\n!\n!*******************************************************************************\n!\n!! PERM_INDEX_TO_CYCLE converts a permutation from standard index to cycle form.\n!\n!\n! Example:\n!\n! Input:\n!\n! N = 9\n! P1 = 2, 3, 9, 6, 7, 8, 5, 4, 1\n!\n! Output:\n!\n! P2 = -1, 2, 3, 9, -4, 6, 8, -5, 7\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 31 July 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of objects being permuted.\n!\n! Input, integer P1(N), the permutation, in standard index form.\n!\n! Output, integer P2(N), the permutation, in cycle form.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer j\n integer k\n integer p1(n)\n integer p2(n)\n!\n i = 0\n j = 1\n\n do while ( j <= n )\n\n if ( p1(j) < 0 ) then\n\n j = j + 1\n\n else\n\n k = j\n\n i = i + 1\n p2(i) = - k\n\n do while ( p1(k) /= j )\n i = i + 1\n p2(i) = p1(k)\n p1(k) = - p1(k)\n k = abs ( p1(k) )\n end do\n\n p1(k) = - p1(k)\n\n end if\n\n end do\n\n p1(1:n) = abs ( p1(1:n) )\n\n return\nend\nsubroutine perm_ins ( n, p, ins )\n!\n!*******************************************************************************\n!\n!! PERM_INS computes the inversion sequence of a permutation.\n!\n!\n! Definition:\n!\n! For a given permutation P acting on objects 1 through N, the inversion\n! sequence INS is defined as:\n!\n! INS(1) = 0\n! INS(I) = number of values J < I for which P(J) > P(I).\n!\n! Example:\n!\n! Input:\n!\n! ( 3, 5, 1, 4, 2 )\n!\n! Output:\n!\n! ( 0, 0, 2, 1, 3 )\n!\n! Note:\n!\n! The original permutation can be recovered from the inversion sequence.\n!\n! Reference:\n!\n! Dennis Stanton and Dennis White,\n! Constructive Combinatorics,\n! Springer Verlag, New York, 1986.\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of objects being permuted.\n!\n! Input, integer P(N), the permutation, in standard index form.\n! The I-th item has been mapped to P(I).\n!\n! Output, integer INS(N), the inversion sequence of the permutation.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer ierror\n integer ins(n)\n integer j\n integer p(n)\n!\n call perm_check ( n, p, ierror )\n\n if ( ierror /= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PERM_INS - Fatal error!'\n write ( *, '(a)' ) ' The input array does not represent'\n write ( *, '(a)' ) ' a proper permutation. In particular, the'\n write ( *, '(a,i6)' ) ' array is missing the value ', ierror\n stop\n end if\n\n ins(1:n) = 0\n\n do i = 1, n\n do j = 1, i-1\n if ( p(j) > p(i) ) then\n ins(i) = ins(i) + 1\n end if\n end do\n end do\n\n return\nend\nsubroutine perm_inv ( n, p )\n!\n!*******************************************************************************\n!\n!! PERM_INV inverts a permutation \"in place\".\n!\n!\n! Modified:\n!\n! 25 July 2000\n!\n! Parameters:\n!\n! Input, integer N, the number of objects being permuted.\n!\n! Input/output, integer P(N), the permutation, in standard index form.\n! On output, P describes the inverse permutation\n!\n implicit none\n!\n integer n\n!\n integer i\n integer i0\n integer i1\n integer i2\n integer ierror\n integer is\n integer p(n)\n!\n if ( n <= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PERM_INV - Fatal error!'\n write ( *, '(a,i6)' ) ' Input value of N = ', n\n stop\n end if\n\n call perm_check ( n, p, ierror )\n\n if ( ierror /= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PERM_INV - Fatal error!'\n write ( *, '(a)' ) ' The input array does not represent'\n write ( *, '(a)' ) ' a proper permutation. In particular, the'\n write ( *, '(a,i6)' ) ' array is missing the value ', ierror\n stop\n end if\n\n is = 1\n\n do i = 1, n\n\n i1 = p(i)\n\n do while ( i1 > i )\n i2 = p(i1)\n p(i1) = - i2\n i1 = i2\n end do\n\n is = - sign ( 1, p(i) )\n p(i) = sign ( p(i), is )\n\n end do\n\n do i = 1, n\n\n i1 = - p(i)\n\n if ( i1 >= 0 ) then\n\n i0 = i\n\n do\n\n i2 = p(i1)\n p(i1) = i0\n\n if ( i2 < 0 ) then\n exit\n end if\n\n i0 = i1\n i1 = i2\n\n end do\n\n end if\n\n end do\n\n return\nend\nsubroutine perm_inv2 ( n, p )\n!\n!*****************************************************************************\n!\n!! PERM_INV2 inverts a permutation \"in place\".\n!\n!\n! Discussion:\n!\n! The routine needs no extra vector storage in order to compute the\n! inverse of a permutation.\n!\n! This feature might be useful if the permutation is large.\n!\n! Modified:\n!\n! 25 July 2000\n!\n! Parameters:\n!\n! Input, integer N, the number of objects in the permutation.\n!\n! Input/output, integer P(N), the permutation, in standard index form.\n! On output, the inverse permutation.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer ierror\n integer ii\n integer j\n integer k\n integer m\n integer p(n)\n!\n call perm_check ( n, p, ierror )\n\n if ( ierror /= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PERM_INV2 - Fatal error!'\n write ( *, '(a)' ) ' The input array does not represent'\n write ( *, '(a)' ) ' a proper permutation. In particular, the'\n write ( *, '(a,i6)' ) ' array is missing the value ', ierror\n stop\n end if\n!\n do ii = 1, n\n\n m = n + 1 - ii\n i = p(m)\n\n if ( i < 0 ) then\n\n p(m) = - i\n\n else if ( i /= m ) then\n\n k = m\n\n do\n\n j = p(i)\n p(i) = - k\n\n if ( j == m ) then\n p(m) = i\n exit\n end if\n\n k = i\n i = j\n\n end do\n\n end if\n\n end do\n\n return\nend\nsubroutine perm_lex ( n, p, more )\n!\n!*******************************************************************************\n!\n!! PERM_LEX generates permutations in lexical order, one at a time.\n!\n!\n! Example:\n!\n! N = 3\n!\n! 1 1 2 3\n! 2 1 3 2\n! 3 2 1 3\n! 4 2 3 1\n! 5 3 1 2\n! 6 3 2 1\n!\n! Reference:\n!\n! Mok-Kong Shen,\n! Algorithm 202: Generation of Permutations in Lexicographical Order,\n! Communications of the ACM,\n! Volume 6, September 1963, page 517.\n!\n! Modified:\n!\n! 24 September 1998\n!\n! Parameters:\n!\n! Input, integer N, the number of elements being permuted.\n!\n! Input/output, integer P(N), the permutation, in standard index form.\n!\n! The user should not alter the elements of Pbetween successive\n! calls. The routine uses the input value of P to determine\n! the output value.\n!\n! Input/output, logical MORE.\n!\n! On the first call, the user should set MORE = FALSE, which signals\n! the routine to do initialization.\n!\n! On return, if MORE is TRUE, then another permutation has been\n! computed and returned, while if MORE is FALSE, there are no more\n! permutations.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer j\n integer k\n logical more\n integer p(n)\n integer u\n integer w\n!\n! Initialization.\n!\n if ( .not. more ) then\n\n call ivec_identity ( n, p )\n more = .true.\n\n else\n\n if ( n <= 1 ) then\n more = .false.\n return\n end if\n\n w = n\n\n do while ( p(w) < p(w-1) )\n\n if ( w == 2 ) then\n more = .false.\n return\n end if\n\n w = w - 1\n end do\n\n u = p(w-1)\n\n do j = n, w, -1\n\n if ( p(j) > u ) then\n\n p(w-1) = p(j)\n p(j) = u\n\n do k = 0, ( n - w - 1 ) / 2\n call i_swap ( p(n-k), p(w+k) )\n end do\n\n return\n\n end if\n\n end do\n\n end if\n\n return\nend\nsubroutine perm_mul ( n, p1, p2, p3 )\n!\n!*******************************************************************************\n!\n!! PERM_MUL \"multiplies\" two permutations.\n!\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the order of the permutations.\n!\n! Input, integer P1(N), P2(N), the permutations, in standard index form.\n!\n! Output, integer P3(N), the product permutation.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer ierror\n integer p1(n)\n integer p2(n)\n integer p3(n)\n!\n call perm_check ( n, p1, ierror )\n\n if ( ierror /= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PERM_MUL - Fatal error!'\n write ( *, '(a)' ) ' The input array does not represent'\n write ( *, '(a)' ) ' a proper permutation. In particular, the'\n write ( *, '(a,i6)' ) ' array is missing the value ', ierror\n stop\n end if\n\n call perm_check ( n, p2, ierror )\n\n if ( ierror /= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PERM_MUL - Fatal error!'\n write ( *, '(a)' ) ' The input array does not represent'\n write ( *, '(a)' ) ' a proper permutation. In particular, the'\n write ( *, '(a,i6)' ) ' array is missing the value ', ierror\n stop\n end if\n\n p3(1:n) = p2(p1(1:n))\n\n return\nend\nsubroutine perm_next ( n, p, more, even )\n!\n!*******************************************************************************\n!\n!! PERM_NEXT computes all of the permutations of N objects, one at a time.\n!\n!\n! Discussion:\n!\n! The routine is initialized by calling with MORE = TRUE, in which case\n! it returns the identity permutation.\n!\n! If the routine is called with MORE = FALSE, then the successor of the\n! input permutation is computed.\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 30 March 2001\n!\n! Parameters:\n!\n! Input, integer N, the number of objects being permuted.\n!\n! Input/output, integer P(N), the permutation, in standard index form.\n!\n! On the first call, the input value is unimportant.\n! On subsequent calls, the input value should be the same\n! as the output value from the previous call. In other words, the\n! user should just leave P alone.\n!\n! On output, contains the \"next\" permutation.\n!\n! Input/output, logical MORE.\n!\n! Set MORE = .FALSE. before the first call.\n!\n! MORE will be reset to .TRUE. and a permutation will be returned.\n!\n! Each new call produces a new permutation until\n! MORE is returned .FALSE.\n!\n! Input/output, logical EVEN.\n!\n! The input value of EVEN should simply be its output value from the\n! previous call; (the input value on the first call doesn't matter.)\n!\n! On output, EVEN is .TRUE. if the output permutation is even, that is,\n! involves an even number of transpositions.\n!\n implicit none\n!\n integer n\n!\n logical even\n integer i\n integer i1\n integer ia\n integer id\n integer is\n integer j\n integer l\n integer m\n logical more\n integer p(n)\n!\n if ( .not. more ) then\n\n call ivec_identity ( n, p )\n more = .true.\n even = .true.\n\n if ( n == 1 ) then\n more = .false.\n return\n end if\n\n if ( p(n) /= 1 .or. p(1) /= 2 + mod ( n, 2 ) ) then\n return\n end if\n\n do i = 1, n-3\n if ( p(i+1) /= p(i)+1 ) then\n return\n end if\n end do\n\n more = .false.\n\n else\n\n if ( n == 1 ) then\n p(1) = 0\n more = .false.\n return\n end if\n\n if ( even ) then\n\n ia = p(1)\n p(1) = p(2)\n p(2) = ia\n even = .false.\n\n if ( p(n) /= 1 .or. p(1) /= 2 + mod ( n, 2 ) ) then\n return\n end if\n\n do i = 1, n-3\n if ( p(i+1) /= p(i)+1 ) then\n return\n end if\n end do\n\n more = .false.\n return\n\n else\n\n more = .false.\n\n is = 0\n\n do i1 = 2, n\n\n ia = p(i1)\n i = i1 - 1\n id = 0\n\n do j = 1, i\n if ( p(j) > ia ) then\n id = id + 1\n end if\n end do\n\n is = id + is\n if ( id /= i * mod ( is, 2 ) ) then\n more = .true.\n exit\n end if\n\n end do\n\n if ( .not. more ) then\n p(1) = 0\n return\n end if\n\n end if\n\n m = mod ( is+1, 2 ) * ( n + 1 )\n\n do j = 1, i\n\n if ( sign ( 1, p(j)-ia ) /= sign ( 1, p(j)-m ) ) then\n m = p(j)\n l = j\n end if\n\n end do\n\n p(l) = ia\n p(i1) = m\n even = .true.\n\n end if\n\n return\nend\nsubroutine perm_next2 ( n, p, done, iactiv, idir, invers )\n!\n!*******************************************************************************\n!\n!! PERM_NEXT2 generates all the permutations of N objects.\n!\n!\n! Discussion:\n!\n! The routine generates the permutations one at a time. It uses a\n! particular ordering of permutations, generating them from the first\n! (which is the identity permutation) to the N!-th. The same ordering\n! is used by the routines PERM_RANK and PERM_UNRANK.\n!\n! Reference:\n!\n! Dennis Stanton and Dennis White,\n! Constructive Combinatorics,\n! Springer Verlag, New York, 1986.\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Input, integer N, the number of elements in the set to be permuted.\n!\n! Input/output, integer P(N), the permutation, in standard index form.\n!\n! Input/output, logical DONE. The user should set the input value of\n! DONE only once, before the first call to compute the permutations.\n! The user should set DONE to .TRUE., which signals the routine\n! that it is to initialize itself.\n!\n! Thereafter, the routine will set DONE to .FALSE. and will\n! compute a new permutation on each call.\n!\n! However, when there are no more permutations to compute, the\n! routine will not return a new permutation, but instead will\n! return DONE with the value .TRUE.. At this point, all the\n! permutations have been computed.\n!\n! Workspace, integer IACTIV(N).\n!\n! On each call, as long as DONE is not returned as\n! .TRUE., P will contain a new permutation. Since this\n! permutation is computed in part from the previous one, the user\n! should not overwrite or alter the contents of P during\n! the computation.\n!\n! Workspace, integer IDIR(N).\n!\n! Output, integer INVERS(N). This array, which is computed as a\n! byproduct of the main computation, contains the inverse permutation\n! to that contained in P. In particular, INVERS(P(I)) = I.\n!\n implicit none\n!\n integer n\n!\n logical done\n integer i\n integer iactiv(n)\n integer idir(n)\n integer invers(n)\n integer j\n integer nactiv\n integer p(n)\n!\n! An input value of .FALSE. for DONE is assumed to mean a new\n! computation is beginning.\n!\n if ( done ) then\n\n call ivec_identity ( n, p )\n invers(1:n) = p(1:n)\n idir(1:n) = -1\n\n iactiv(1) = 0\n iactiv(2:n) = 1\n!\n! Set the DONE flag to .FALSE., signifying there are more permutations\n! to come. Except, of course, that we must take care of the trivial case!\n!\n if ( n > 1 ) then\n done = .false.\n else\n done = .true.\n end if\n!\n! Otherwise, assume we are in a continuing computation\n!\n else\n\n nactiv = 0\n\n do i = 1, n\n if ( iactiv(i) /= 0 ) then\n nactiv = i\n end if\n end do\n\n if ( nactiv <= 0 ) then\n\n done = .true.\n\n else\n\n j = invers(nactiv)\n\n p(j) = p(j+idir(nactiv))\n p(j+idir(nactiv)) = nactiv\n\n invers(nactiv) = invers(nactiv) + idir(nactiv)\n invers(p(j)) = j\n\n if ( j+2*idir(nactiv) < 1.or.j+2*idir(nactiv) > n ) then\n idir(nactiv) = - idir(nactiv)\n iactiv(nactiv) = 0\n else if ( nactiv < p(j+2*idir(nactiv)) ) then\n idir(nactiv) = - idir(nactiv)\n iactiv(nactiv) = 0\n end if\n\n iactiv(nactiv+1:n) = 1\n\n end if\n\n end if\n\n return\nend\nsubroutine perm_next3 ( n, p, more )\n!\n!*******************************************************************************\n!\n!! PERM_NEXT3 computes all of the permutations of N objects, one at a time.\n!\n!\n! Discussion:\n!\n! The routine is initialized by calling with MORE = TRUE, in which case\n! it returns the identity permutation.\n!\n! If the routine is called with MORE = FALSE, then the successor of the\n! input permutation is computed.\n!\n! Trotter's algorithm is used.\n!\n! Reference:\n!\n! H Trotter,\n! PERM, Algorithm 115,\n! Communications of the Association for Computing Machinery,\n! Volume 5, 1962, pages 434-435.\n!\n! Modified:\n!\n! 25 July 2000\n!\n! Parameters:\n!\n! Input, integer N, the number of objects being permuted.\n!\n! Input/output, integer P(N), the permutation, in standard index form.\n! If MORE is .TRUE., then P is assumed to contain the\n! \"previous\" permutation, and on P(I) is the value\n! of the I-th object under the next permutation.\n! Otherwise, P will be set to the \"first\" permutation.\n!\n! Input/output, logical MORE.\n! Set MORE = .FALSE. before first calling this routine.\n! MORE will be reset to .TRUE. and a permutation will be returned.\n! Each new call produces a new permutation until MORE is returned .FALSE.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer, save :: irank = 0\n integer m2\n logical more\n integer n2\n integer, save :: nfact = 0\n integer p(n)\n integer q\n integer s\n integer t\n!\n if ( .not. more ) then\n\n call ivec_identity ( n, p )\n more = .true.\n irank = 1\n\n nfact = 1\n do i = 1, n\n nfact = nfact * i\n end do\n\n else\n\n n2 = n\n m2 = irank\n s = n\n\n do\n\n q = mod ( m2, n2 )\n t = mod ( m2, 2 * n2 )\n\n if ( q /= 0 ) then\n exit\n end if\n\n if ( t == 0 ) then\n s = s - 1\n end if\n\n m2 = m2 / n2\n n2 = n2 - 1\n\n end do\n\n if ( q == t ) then\n s = s - q\n else\n s = s + q - n2\n end if\n\n call i_swap ( p(s), p(s+1) )\n\n irank = irank + 1\n\n if ( irank == nfact ) then\n more = .false.\n end if\n\n end if\n\n return\nend\nsubroutine perm_print ( n, p, title )\n!\n!*******************************************************************************\n!\n!! PERM_PRINT prints a permutation.\n!\n!\n! Example:\n!\n! Input:\n!\n! P = 7 2 4 1 5 3 6\n!\n! Printed output:\n!\n! \"This is the permutation:\"\n!\n! 1 2 3 4 5 6 7\n! 7 2 4 1 5 3 6\n!\n! Modified:\n!\n! 25 July 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of objects permuted.\n!\n! Input, integer P(N), the permutation, in standard index form.\n!\n! Input, character ( len = * ) TITLE, an optional title.\n! If no title is supplied, then only the permutation is printed.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer ihi\n integer ilo\n integer, parameter :: inc = 20\n integer p(n)\n character ( len = * ) title\n!\n if ( len_trim ( title ) /= 0 ) then\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) trim ( title )\n\n do ilo = 1, n, inc\n ihi = min ( n, ilo + inc - 1 )\n write ( *, '(a)' ) ' '\n write ( *, '(20i4)' ) ( i, i = ilo, ihi )\n write ( *, '(20i4)' ) p(ilo:ihi)\n end do\n\n else\n\n do ilo = 1, n, inc\n ihi = min ( n, ilo + inc - 1 )\n write ( *, '(20i4)' ) p(ilo:ihi)\n end do\n\n end if\n\n return\nend\nsubroutine perm_random ( n, p )\n!\n!*******************************************************************************\n!\n!! PERM_RANDOM selects a random permutation of N objects.\n!\n!\n! Discussion:\n!\n! The routine assumes the objects are labeled 1, 2, ... N.\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 12 May 2002\n!\n! Parameters:\n!\n! Input, integer N, the number of objects to be permuted.\n!\n! Output, integer P(N), a permutation of ( 1, 2, ..., N ), in standard \n! index form.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer j\n integer p(n)\n!\n call ivec_identity ( n, p )\n\n do i = 1, n\n call i_random ( i, n, j )\n call i_swap ( p(i), p(j) )\n end do\n\n return\nend\nsubroutine perm_random2 ( n, p )\n!\n!*******************************************************************************\n!\n!! PERM_RANDOM2 selects a random permutation of N objects.\n!\n!\n! Discussion:\n!\n! The input values of P are used as labels; that is, the I-th object \n! is labeled P(I).\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 12 May 2002\n!\n! Parameters:\n!\n! Input, integer N, the number of objects to be permuted.\n!\n! Input/output, integer P(N), on input, a list of labels. On output,\n! the list has been permuted randomly.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer j\n integer p(n)\n!\n do i = 1, n\n call i_random ( i, n, j )\n call i_swap ( p(i), p(j) )\n end do\n\n return\nend\nsubroutine perm_random3 ( n, p )\n!\n!*******************************************************************************\n!\n!! PERM_RANDOM3 selects a random permutation of N elements.\n!\n!\n! Reference:\n!\n! K L Hoffman and D R Shier,\n! Algorithm 564,\n! A Test Problem Generator for Discrete Linear L1 Approximation Problems,\n! ACM Transactions on Mathematical Software,\n! Volume 6, Number 4, December 1980, pages 615-617.\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Author:\n!\n! James Filliben\n! National Bureau of Standards.\n!\n! Parameters:\n!\n! Input, integer N, the number of elements of the array.\n!\n! Output, integer P(N), a permutation, in standard index form.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer iadd\n integer j\n integer p(n)\n!\n if ( n < 1 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PERM_RANDOM3 - Fatal error!'\n write ( *, '(a,i6)' ) ' Illegal input value of N = ', n\n write ( *, '(a)' ) ' N must be at least 1!'\n stop\n end if\n\n if ( n == 1 ) then\n p(1) = 1\n return\n end if\n\n call ivec_identity ( n, p )\n\n do i = 1, n\n\n call i_random ( 1, n, iadd )\n\n j = i + iadd\n\n if ( j > n ) then\n j = j - n\n end if\n\n if ( i /= j ) then\n call i_swap ( p(j), p(i) )\n end if\n\n end do\n\n return\nend\nsubroutine perm_rank ( n, p, ierror, invers, irank )\n!\n!*******************************************************************************\n!\n!! PERM_RANK computes the rank of a given permutation.\n!\n!\n! Discussion:\n!\n! This is the same as asking for the step at which PERM_NEXT2\n! would compute the permutation. The value of the rank will be\n! between 1 and N!.\n!\n! Reference:\n!\n! Dennis Stanton and Dennis White,\n! Constructive Combinatorics,\n! Springer Verlag, New York, 1986.\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Input, integer N, the number of elements in the set that\n! is permuted by P.\n!\n! Input, integer P(N), a permutation, in standard index form.\n!\n! Output, integer IERROR, error flag.\n! 0, no error.\n! nonzero, IARRAY does not represent a permutation of the integers\n! from 1 to N. In particular, the value IERROR is missing.\n!\n! Output, integer INVERS(N), the inverse permutation of P.\n! It is computed as part of the algorithm, and may be of use\n! to the user. INVERS(P(I)) = I for each entry I.\n!\n! Output, integer IRANK, the rank of the permutation. This\n! gives the order of the given permutation in the set of all\n! the permutations on N elements.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer icount\n integer ierror\n integer invers(n)\n integer irank\n integer irem\n integer j\n integer p(n)\n!\n! Make sure the permutation is a legal one.\n! (This is not an efficient way to do so!)\n!\n call perm_check ( n, p, ierror )\n\n if ( ierror /= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PERM_RANK - Fatal error!'\n write ( *, '(a)' ) ' The input array does not represent'\n write ( *, '(a)' ) ' a proper permutation. In particular, the'\n write ( *, '(a,i6)' ) ' array is missing the value ', ierror\n stop\n end if\n!\n! Compute the inverse permutation\n!\n invers(1:n) = p(1:n)\n\n call perm_inv2 ( n, invers )\n\n irank = 0\n\n do i = 1, n\n\n icount = 0\n\n do j = 1, invers(i)\n if ( p(j) < i ) then\n icount = icount + 1\n end if\n end do\n\n if ( mod ( irank, 2 ) == 1 ) then\n irem = icount\n else\n irem = i - 1 - icount\n end if\n\n irank = i * irank + irem\n\n end do\n\n irank = irank + 1\n\n return\nend\nsubroutine perm_sign ( n, p, p_sign )\n!\n!*******************************************************************************\n!\n!! PERM_SIGN returns the sign of a permutation.\n!\n!\n! Discussion:\n!\n! A permutation can always be replaced by a sequence of pairwise\n! transpositions. A given permutation can be represented by\n! many different such transposition sequences, but the number of\n! such transpositions will always be odd or always be even.\n! If the number of transpositions is even or odd, the permutation is\n! said to be even or odd.\n!\n! Example:\n!\n! Input:\n!\n! N = 9\n! P = 2, 3, 9, 6, 7, 8, 5, 4, 1\n!\n! Output:\n!\n! P_SIGN = +1\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 01 February 2000\n!\n! Parameters:\n!\n! Input, integer N, the number of objects permuted.\n!\n! Input, integer P(N), a permutation, in standard index form.\n!\n! Output, integer P_SIGN, the \"sign\" of the permutation.\n! +1, the permutation is even,\n! -1, the permutation is odd.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer ierror\n integer ivec_index\n integer j\n integer p(n)\n integer p_sign\n integer q(n)\n!\n call perm_check ( n, p, ierror )\n\n if ( ierror /= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PERM_SIGN - Fatal error!'\n write ( *, '(a)' ) ' The input array does not represent'\n write ( *, '(a)' ) ' a proper permutation. In particular, the'\n write ( *, '(a,i6)' ) ' array is missing the value ', ierror\n stop\n end if\n!\n! Make a temporary copy of the permutation.\n!\n q(1:n) = p(1:n)\n!\n! Start with P_SIGN indicating an even permutation.\n! Restore each element of the permutation to its correct position,\n! updating P_SIGN as you go.\n!\n p_sign = 1\n\n do i = 1, n-1\n\n j = ivec_index ( n, q, i )\n\n if ( j /= i ) then\n call i_swap ( q(i), q(j) )\n p_sign = - p_sign\n end if\n\n end do\n\n return\nend\nsubroutine perm_to_equiv ( n, p, npart, jarray, iarray )\n!\n!*******************************************************************************\n!\n!! PERM_TO_EQUIV computes the partition induced by a permutation.\n!\n!\n! Example:\n!\n! Input:\n!\n! N = 9\n! P = 2, 3, 9, 6, 7, 8, 5, 4, 1\n!\n! Output:\n!\n! NPART = 3\n! JARRAY = 4, 3, 2\n! IARRAY = 1, 1, 1, 2 3 2 3 2, 1\n!\n! Modified:\n!\n! 26 July 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of objects being permuted.\n!\n! Input, integer P(N), a permutation, in standard index form.\n!\n! Output, integer NPART, number of subsets in the partition.\n!\n! Output, integer JARRAY(N). JARRAY(I) is the number of elements\n! in the I-th subset of the partition.\n!\n! Output, integer IARRAY(N). IARRAY(I) is the class to which\n! element I belongs.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer iarray(n)\n integer ierror\n integer j\n integer jarray(n)\n integer k\n integer npart\n integer p(n)\n!\n call perm_check ( n, p, ierror )\n\n if ( ierror /= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PERM__TO_EQUIV - Fatal error!'\n write ( *, '(a)' ) ' The input array does not represent'\n write ( *, '(a)' ) ' a proper permutation. In particular, the'\n write ( *, '(a,i6)' ) ' array is missing the value ', ierror\n stop\n end if\n!\n! Initialize.\n!\n iarray(1:n) = 0\n jarray(1:n) = 0\n\n npart = 0\n!\n! Search for the next item J which has not been assigned a subset/orbit.\n!\n do j = 1, n\n\n if ( iarray(j) /= 0 ) then\n cycle\n end if\n!\n! Begin a new subset/orbit.\n!\n npart = npart + 1\n k = j\n!\n! Add the item to the subset/orbit.\n!\n do\n\n jarray(npart) = jarray(npart) + 1\n iarray(k) = npart\n!\n! Apply the permutation. If the permuted object isn't already in the\n! subset/orbit, add it.\n!\n k = p(k)\n\n if ( iarray(k) /= 0 ) then\n exit\n end if\n\n end do\n\n end do\n\n return\nend\nsubroutine perm_to_ytb ( n, p, lambda, iarray )\n!\n!*******************************************************************************\n!\n!! PERM_TO_YTB converts a permutation to a Young tableau.\n!\n!\n! Discussion:\n!\n! The mapping is not invertible. In most cases, several permutations\n! correspond to the same tableau.\n!\n! Example:\n!\n! N = 7\n! P = 7 2 4 1 5 3 6\n!\n! YTB =\n! 1 2 3 6\n! 4 5\n! 7\n!\n! LAMBDA = 4 2 1 0 0 0 0\n!\n! IARRAY = 1 1 1 2 2 1 3\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 11 April 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the integer to be partitioned.\n!\n! Input, integer P(N), a permutation, in standard index form.\n!\n! Output, integer LAMBDA(N). LAMBDA(I) is the length of the I-th row.\n!\n! Output, integer IARRAY(N). IARRAY(I) is the row containing I.\n!\n implicit none\n!\n integer n\n!\n logical another\n integer compare\n integer i\n integer iarray(n)\n integer lambda(n)\n integer p(n)\n integer put_index\n integer put_row\n integer put_value\n!\n! Initialize.\n!\n lambda(1:n) = 0\n iarray(1:n) = 0\n!\n! Now insert each item of the permutation.\n!\n do put_index = 1, n\n\n put_value = p(put_index)\n put_row = 1\n\n do\n\n another = .false.\n\n do compare = put_value+1, n\n\n if ( iarray(compare) == put_row ) then\n another = .true.\n iarray(put_value) = put_row\n iarray(compare) = 0\n put_value = compare\n put_row = put_row + 1\n exit\n end if\n\n end do\n\n if ( .not. another ) then\n exit\n end if\n\n end do\n\n iarray(put_value) = put_row\n lambda(put_row) = lambda(put_row) + 1\n\n end do\n\n return\nend\nsubroutine perm_unrank ( n, p, irank )\n!\n!*******************************************************************************\n!\n!! PERM_UNRANK \"unranks\" a permutation.\n!\n!\n! Discussion:\n!\n! That is, given a rank, it computes the corresponding permutation.\n! This is the same as asking for the permutation which PERM_NEXT2\n! would compute at the IRANK-th step.\n!\n! The value of the rank should be between 1 and N!.\n!\n! Reference:\n!\n! Dennis Stanton and Dennis White,\n! Constructive Combinatorics,\n! Springer Verlag, New York, 1986.\n!\n! Modified:\n!\n! 25 July 2000\n!\n! Parameters:\n!\n! Input, integer N, the number of elements in the set.\n!\n! Output, integer P(N), the permutation, in standard index form.\n!\n! Input, integer IRANK, the desired rank of the permutation. This\n! gives the order of the given permutation in the set of all\n! the permutations on N elements, using the order of PERM_NEXT2.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer icount\n integer iprev\n integer irank\n integer irem\n integer j\n integer jdir\n integer jrank\n integer nfact\n integer p(n)\n!\n p(1:n) = 0\n\n nfact = 1\n\n do i = 1, n\n nfact = nfact * i\n end do\n\n if ( irank < 1 .or. irank > nfact ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PERM_UNRANK - Fatal error!'\n write ( *, '(a)' ) ' Illegal input value for IRANK.'\n write ( *, '(a,i6)' ) ' IRANK must be between 1 and ', nfact\n write ( *, '(a,i6)' ) ' but the input value is ', irank\n stop\n end if\n\n jrank = irank - 1\n\n do i = 1, n\n\n iprev = n + 1 - i\n irem = mod ( jrank, iprev )\n jrank = jrank / iprev\n\n if ( mod ( jrank, 2 ) == 1 ) then\n j = 0\n jdir = 1\n else\n j = n + 1\n jdir = -1\n end if\n\n icount = 0\n\n do\n\n j = j + jdir\n\n if ( p(j) == 0 ) then\n icount = icount + 1\n end if\n\n if ( icount > irem ) then\n exit\n end if\n\n end do\n\n p(j) = iprev\n\n end do\n\n return\nend\nsubroutine pord_check ( n, a, ierror )\n!\n!*******************************************************************************\n!\n!! PORD_CHECK checks a matrix representing a partial ordering.\n!\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of elements in the set. The number\n! of rows and columns used in IZETA.\n!\n! Input, integer A(N,N). Contains the description of the\n! partial ordering. A(I,J) = 1 if I is less than J\n! in the partial ordering, 0 otherwise.\n!\n! Output, integer IERROR, error flag.\n! 0, no errors detected.\n! 1, N <= 0.\n! 2, A(I,J) > 0 and A(J,I) > 0 for some I and J.\n!\n implicit none\n!\n integer n\n!\n integer a(n,n)\n integer i\n integer ierror\n integer j\n!\n ierror = 0\n\n if ( n <= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PORD_CHECK - Fatal error!'\n write ( *, '(a,i6)' ) ' N must be positive, but N = ', n\n ierror = 1\n return\n end if\n\n do i = 1, n\n do j = i+1, n\n\n if ( a(i,j) > 0 ) then\n if ( a(j,i) > 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PORD_CHECK - Fatal error!'\n write ( *, '(a,i6)' ) ' For indices I = ', i\n write ( *, '(a,i6)' ) ' and J = ', j\n write ( *, '(a,i6)' ) ' A(I,J) = ', a(i,j)\n write ( *, '(a,i6)' ) ' A(J,I) = ', a(j,i)\n ierror = 2\n return\n end if\n end if\n\n end do\n end do\n\n return\nend\nsubroutine power_mod ( a, n, m, x )\n!\n!*******************************************************************************\n!\n!! POWER_MOD computes mod ( A**N, M ).\n!\n!\n! Discussion:\n!\n! Some programming tricks are used to speed up the computation, and to\n! allow computations in which A**N is much too large to store in a\n! real word.\n!\n! First, for efficiency, the power A**N is computed by determining\n! the binary expansion of N, then computing A, A**2, A**4, and so on\n! by repeated squaring, and multiplying only those factors that\n! contribute to A**N.\n!\n! Secondly, the intermediate products are immediately \"mod'ed\", which\n! keeps them small.\n!\n! For instance, to compute mod ( A**13, 11 ), we essentially compute\n!\n! 13 = 1 + 4 + 8\n!\n! A**13 = A * A**4 * A**8\n!\n! mod ( A**13, 11 ) = mod ( A, 11 ) * mod ( A**4, 11 ) * mod ( A**8, 11 ).\n!\n! Fermat's little theorem says that if P is prime, and A is not divisible\n! by P, then ( A**(P-1) - 1 ) is divisible by P.\n!\n! Modified:\n!\n! 29 July 1999\n!\n! Parameters:\n!\n! Input, integer A, the base of the expression to be tested.\n! A should be nonnegative.\n!\n! Input, integer N, the power to which the base is raised.\n! N should be nonnegative.\n!\n! Input, integer M, the divisor against which the expression is tested.\n! M should be positive.\n!\n! Output, integer X, the remainder when A**N is divided by M.\n!\n implicit none\n!\n integer a\n integer a_square\n integer d\n integer m\n integer n\n integer ncopy\n integer x\n!\n x = - 1\n\n if ( a < 0 ) then\n return\n end if\n\n if ( m < 0 ) then\n return\n end if\n\n if ( n < 0 ) then\n return\n end if\n!\n! A_SQUARE contains the successive squares of A.\n!\n a_square = a\n ncopy = n\n x = 1\n\n do while ( ncopy > 0 )\n\n d = mod ( ncopy, 2 )\n\n if ( d == 1 ) then\n x = mod ( x * a_square, m )\n end if\n\n a_square = mod ( a_square * a_square, m )\n ncopy = ( ncopy - d ) / 2\n\n end do\n\n return\nend\nsubroutine power_series1 ( a, c, n, alpha )\n!\n!*******************************************************************************\n!\n!! POWER_SERIES1 computes a power series for a function F(Z) = (1+H(Z))**ALPHA.\n!\n!\n! Discussion:\n!\n! The power series for H(Z) is given.\n!\n! The form of the power series are:\n!\n! F(Z) = A1*Z + A2*Z**2 + A3*Z**3 + ... + AN*Z**N\n!\n! H(Z) = C1*Z + C2*Z**2 + C3*Z**3 + ... + CN*Z**N\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Output, real A(N), the power series coefficients for F(Z).\n!\n! Input, real C(N), the power series coefficients for H(Z).\n!\n! Input, integer N, the number of terms in the power series.\n!\n! Input, real ALPHA, the exponent of 1+H(Z) in the definition of F(Z).\n!\n implicit none\n!\n integer n\n!\n real a(n)\n real alpha\n real c(n)\n integer i\n integer j\n real v\n!\n do j = 1, n\n\n v = 0.0E+00\n\n do i = 1, j-1\n v = v + a(i) * c(j-i) * ( alpha * ( j - i ) - i )\n end do\n\n a(j) = ( alpha * c(j) + v / real(j) )\n\n end do\n\n return\nend\nsubroutine power_series2 ( a, c, n )\n!\n!*******************************************************************************\n!\n!! POWER_SERIES2 computes the power series for a function F(Z) = EXP(H(Z)) - 1.\n!\n!\n! Discussion:\n!\n! The power series for H(Z) is given.\n!\n! The power series have the form:\n!\n! F(Z) = A1*Z + A2*Z**2 + A3*Z**3 + ... + AN*Z**N\n!\n! H(Z) = C1*Z + C2*Z**2 + C3*Z**3 + ... + CN*Z**N\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Output, real A(N), the power series coefficients for F(Z).\n!\n! Input, real C(N), the power series coefficients for H(Z).\n!\n! Input, integer N, the number of terms in the power series.\n!\n implicit none\n!\n integer n\n!\n real a(n)\n real c(n)\n integer i\n integer j\n real v\n!\n do j = 1, n\n\n v = 0.0E+00\n\n do i = 1, j-1\n v = v + a(i) * c(j-i) * real ( j - i )\n end do\n\n a(j) = c(j) + v / real ( j )\n\n end do\n\n return\nend\nsubroutine power_series3 ( a, b, c, n )\n!\n!*******************************************************************************\n!\n!! POWER_SERIES3 computes the power series for a function F(Z) = G(H(Z)).\n!\n!\n! Discussion:\n!\n! The power series for G and H are given.\n!\n! We assume that\n!\n! F(Z) = A1*Z + A2*Z**2 + A3*Z**3 + ... + AN*Z**N\n! G(Z) = B1*Z + B2*Z**2 + B3*Z**3 + ... + BN*Z**N\n! H(Z) = C1*Z + C2*Z**2 + C3*Z**3 + ... + CN*Z**N\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 02 November 2001\n!\n! Parameters:\n!\n! Output, real A(N), the power series for F.\n!\n! Input, real B(N), the power series for G.\n!\n! Input, real C(N), the power series for H.\n!\n! Input, integer N, the number of terms in the power series.\n!\n implicit none\n!\n integer n\n!\n real a(n)\n real b(n)\n real c(n)\n integer i\n integer iq\n integer j\n integer m\n real r\n real v\n real work(n)\n!\n work(1:n) = b(1) * c(1:n)\n!\n! Search for IQ, the index of the first nonzero entry in C.\n!\n iq = 0\n\n do i = 1, n\n\n if ( c(i) /= 0.0E+00 ) then\n iq = i\n exit\n end if\n\n end do\n\n if ( iq /= 0 ) then\n\n m = 1\n\n do\n\n m = m + 1\n\n if ( m * iq > n ) then\n exit\n end if\n\n if ( b(m) == 0.0E+00 ) then\n cycle\n end if\n\n r = b(m) * c(iq)**m\n work(m*iq) = work(m*iq) + r\n\n do j = 1, n-m*iq\n\n v = 0.0E+00\n do i = 1, j-1\n v = v + a(i) * c(j-i+iq) * real ( m * ( j - i ) - i )\n end do\n\n a(j) = ( real ( m ) * c(j) + v / real ( j ) ) / c(iq)\n\n end do\n\n do i = 1, n-m*iq\n work(i+m*iq) = work(i+m*iq) + a(i) * r\n end do\n\n end do\n\n end if\n\n a(1:n) = work(1:n)\n\n return\nend\nsubroutine power_series4 ( a, b, c, n )\n!\n!*******************************************************************************\n!\n!! POWER_SERIES4 computes the power series for a function G(Z) = F ( 1/H(Z) ).\n!\n!\n! Discussion:\n!\n! POWER_SERIES4 is given the power series for the functions F and H.\n!\n! We assume that\n!\n! F(Z) = A1*Z + A2*Z**2 + A3*Z**3 + ... + AN*Z**N\n! G(Z) = B1*Z + B2*Z**2 + B3*Z**3 + ... + BN*Z**N\n! H(Z) = C1*Z + C2*Z**2 + C3*Z**3 + ... + CN*Z**N\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Input, real A(N). Power series for F.\n!\n! Output, real B(N). Power series for G.\n!\n! Input, real C(N). Power series for H. For this problem, C(1)\n! may not be 0.0.\n!\n! Input, integer N, the number of terms in the power series.\n!\n implicit none\n!\n integer n\n!\n real a(n)\n real b(n)\n real c(n)\n integer i\n integer l\n integer m\n real s\n real t\n real work(n)\n!\n if ( c(1) == 0.0E+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'POWER_SERIES4 - Fatal error!'\n write ( *, '(a)' ) ' C(1) is zero.'\n stop\n end if\n\n t = 1.0E+00\n\n do i = 1, n\n t = t / c(1)\n b(i) = a(i) * t\n work(i) = c(i) * t\n end do\n\n do m = 2, n\n s = - work(m)\n do i = m, n\n do l = i, n\n b(l) = b(l) + s * b(l+1-m)\n work(l) = work(l) + s * work(l+1-m)\n end do\n end do\n end do\n\n return\nend\nfunction prime ( n )\n!\n!*******************************************************************************\n!\n!! PRIME returns any of the first MAXPRIME prime numbers.\n!\n!\n! Note:\n!\n! MAXPRIME is 1500, and the largest prime stored is 12553.\n!\n! Modified:\n!\n! 21 October 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Milton Abramowitz and Irene Stegun,\n! Handbook of Mathematical Functions,\n! US Department of Commerce, 1964, pages 870-873.\n!\n! Daniel Zwillinger,\n! CRC Standard Mathematical Tables and Formulae,\n! 30th Edition,\n! CRC Press, 1996, pages 95-98.\n!\n! Parameters:\n!\n! Input, integer N, the index of the desired prime number.\n! N = -1 returns MAXPRIME, the index of the largest prime available.\n! N = 0 is legal, returning PRIME = 1.\n! It should generally be true that 0 <= N <= MAXPRIME.\n!\n! Output, integer PRIME, the N-th prime. If N is out of range, PRIME\n! is returned as 0.\n!\n implicit none\n!\n integer, parameter :: maxprime = 1500\n!\n integer i\n integer n\n integer, save, dimension ( maxprime ) :: npvec\n integer prime\n!\n data ( npvec(i), i = 1, 100 ) / &\n 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, &\n 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, &\n 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, &\n 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, &\n 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, &\n 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, &\n 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, &\n 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, &\n 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, &\n 467, 479, 487, 491, 499, 503, 509, 521, 523, 541 /\n\n data ( npvec(i), i = 101, 200 ) / &\n 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, &\n 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, &\n 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, &\n 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, &\n 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, &\n 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, &\n 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, &\n 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, &\n 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, &\n 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223 /\n\n data ( npvec(i), i = 201, 300 ) / &\n 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, &\n 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, &\n 1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, &\n 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, &\n 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, &\n 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, &\n 1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, &\n 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, &\n 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, &\n 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987 /\n\n data ( npvec(i), i = 301, 400 ) / &\n 1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053, &\n 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2129, &\n 2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, &\n 2221, 2237, 2239, 2243, 2251, 2267, 2269, 2273, 2281, 2287, &\n 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, &\n 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423, &\n 2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521, 2531, &\n 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617, &\n 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687, &\n 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741 /\n\n data ( npvec(i), i = 401, 500 ) / &\n 2749, 2753, 2767, 2777, 2789, 2791, 2797, 2801, 2803, 2819, &\n 2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897, 2903, &\n 2909, 2917, 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999, &\n 3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061, 3067, 3079, &\n 3083, 3089, 3109, 3119, 3121, 3137, 3163, 3167, 3169, 3181, &\n 3187, 3191, 3203, 3209, 3217, 3221, 3229, 3251, 3253, 3257, &\n 3259, 3271, 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331, &\n 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391, 3407, 3413, &\n 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, &\n 3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571 /\n\n data ( npvec(i), i = 501, 600 ) / &\n 3581, 3583, 3593, 3607, 3613, 3617, 3623, 3631, 3637, 3643, &\n 3659, 3671, 3673, 3677, 3691, 3697, 3701, 3709, 3719, 3727, &\n 3733, 3739, 3761, 3767, 3769, 3779, 3793, 3797, 3803, 3821, &\n 3823, 3833, 3847, 3851, 3853, 3863, 3877, 3881, 3889, 3907, &\n 3911, 3917, 3919, 3923, 3929, 3931, 3943, 3947, 3967, 3989, &\n 4001, 4003, 4007, 4013, 4019, 4021, 4027, 4049, 4051, 4057, &\n 4073, 4079, 4091, 4093, 4099, 4111, 4127, 4129, 4133, 4139, &\n 4153, 4157, 4159, 4177, 4201, 4211, 4217, 4219, 4229, 4231, &\n 4241, 4243, 4253, 4259, 4261, 4271, 4273, 4283, 4289, 4297, &\n 4327, 4337, 4339, 4349, 4357, 4363, 4373, 4391, 4397, 4409 /\n\n data ( npvec(i), i = 601, 700 ) / &\n 4421, 4423, 4441, 4447, 4451, 4457, 4463, 4481, 4483, 4493, &\n 4507, 4513, 4517, 4519, 4523, 4547, 4549, 4561, 4567, 4583, &\n 4591, 4597, 4603, 4621, 4637, 4639, 4643, 4649, 4651, 4657, &\n 4663, 4673, 4679, 4691, 4703, 4721, 4723, 4729, 4733, 4751, &\n 4759, 4783, 4787, 4789, 4793, 4799, 4801, 4813, 4817, 4831, &\n 4861, 4871, 4877, 4889, 4903, 4909, 4919, 4931, 4933, 4937, &\n 4943, 4951, 4957, 4967, 4969, 4973, 4987, 4993, 4999, 5003, &\n 5009, 5011, 5021, 5023, 5039, 5051, 5059, 5077, 5081, 5087, &\n 5099, 5101, 5107, 5113, 5119, 5147, 5153, 5167, 5171, 5179, &\n 5189, 5197, 5209, 5227, 5231, 5233, 5237, 5261, 5273, 5279 /\n\n data ( npvec(i), i = 701, 800 ) / &\n 5281, 5297, 5303, 5309, 5323, 5333, 5347, 5351, 5381, 5387, &\n 5393, 5399, 5407, 5413, 5417, 5419, 5431, 5437, 5441, 5443, &\n 5449, 5471, 5477, 5479, 5483, 5501, 5503, 5507, 5519, 5521, &\n 5527, 5531, 5557, 5563, 5569, 5573, 5581, 5591, 5623, 5639, &\n 5641, 5647, 5651, 5653, 5657, 5659, 5669, 5683, 5689, 5693, &\n 5701, 5711, 5717, 5737, 5741, 5743, 5749, 5779, 5783, 5791, &\n 5801, 5807, 5813, 5821, 5827, 5839, 5843, 5849, 5851, 5857, &\n 5861, 5867, 5869, 5879, 5881, 5897, 5903, 5923, 5927, 5939, &\n 5953, 5981, 5987, 6007, 6011, 6029, 6037, 6043, 6047, 6053, &\n 6067, 6073, 6079, 6089, 6091, 6101, 6113, 6121, 6131, 6133 /\n\n data ( npvec(i), i = 801, 900 ) / &\n 6143, 6151, 6163, 6173, 6197, 6199, 6203, 6211, 6217, 6221, &\n 6229, 6247, 6257, 6263, 6269, 6271, 6277, 6287, 6299, 6301, &\n 6311, 6317, 6323, 6329, 6337, 6343, 6353, 6359, 6361, 6367, &\n 6373, 6379, 6389, 6397, 6421, 6427, 6449, 6451, 6469, 6473, &\n 6481, 6491, 6521, 6529, 6547, 6551, 6553, 6563, 6569, 6571, &\n 6577, 6581, 6599, 6607, 6619, 6637, 6653, 6659, 6661, 6673, &\n 6679, 6689, 6691, 6701, 6703, 6709, 6719, 6733, 6737, 6761, &\n 6763, 6779, 6781, 6791, 6793, 6803, 6823, 6827, 6829, 6833, &\n 6841, 6857, 6863, 6869, 6871, 6883, 6899, 6907, 6911, 6917, &\n 6947, 6949, 6959, 6961, 6967, 6971, 6977, 6983, 6991, 6997 /\n\n data ( npvec(i), i = 901, 1000 ) / &\n 7001, 7013, 7019, 7027, 7039, 7043, 7057, 7069, 7079, 7103, &\n 7109, 7121, 7127, 7129, 7151, 7159, 7177, 7187, 7193, 7207, &\n 7211, 7213, 7219, 7229, 7237, 7243, 7247, 7253, 7283, 7297, &\n 7307, 7309, 7321, 7331, 7333, 7349, 7351, 7369, 7393, 7411, &\n 7417, 7433, 7451, 7457, 7459, 7477, 7481, 7487, 7489, 7499, &\n 7507, 7517, 7523, 7529, 7537, 7541, 7547, 7549, 7559, 7561, &\n 7573, 7577, 7583, 7589, 7591, 7603, 7607, 7621, 7639, 7643, &\n 7649, 7669, 7673, 7681, 7687, 7691, 7699, 7703, 7717, 7723, &\n 7727, 7741, 7753, 7757, 7759, 7789, 7793, 7817, 7823, 7829, &\n 7841, 7853, 7867, 7873, 7877, 7879, 7883, 7901, 7907, 7919 /\n\n data ( npvec(i), i = 1001, 1100 ) / &\n 7927, 7933, 7937, 7949, 7951, 7963, 7993, 8009, 8011, 8017, &\n 8039, 8053, 8059, 8069, 8081, 8087, 8089, 8093, 8101, 8111, &\n 8117, 8123, 8147, 8161, 8167, 8171, 8179, 8191, 8209, 8219, &\n 8221, 8231, 8233, 8237, 8243, 8263, 8269, 8273, 8287, 8291, &\n 8293, 8297, 8311, 8317, 8329, 8353, 8363, 8369, 8377, 8387, &\n 8389, 8419, 8423, 8429, 8431, 8443, 8447, 8461, 8467, 8501, &\n 8513, 8521, 8527, 8537, 8539, 8543, 8563, 8573, 8581, 8597, &\n 8599, 8609, 8623, 8627, 8629, 8641, 8647, 8663, 8669, 8677, &\n 8681, 8689, 8693, 8699, 8707, 8713, 8719, 8731, 8737, 8741, &\n 8747, 8753, 8761, 8779, 8783, 8803, 8807, 8819, 8821, 8831 /\n\n data ( npvec(i), i = 1101, 1200 ) / &\n 8837, 8839, 8849, 8861, 8863, 8867, 8887, 8893, 8923, 8929, &\n 8933, 8941, 8951, 8963, 8969, 8971, 8999, 9001, 9007, 9011, &\n 9013, 9029, 9041, 9043, 9049, 9059, 9067, 9091, 9103, 9109, &\n 9127, 9133, 9137, 9151, 9157, 9161, 9173, 9181, 9187, 9199, &\n 9203, 9209, 9221, 9227, 9239, 9241, 9257, 9277, 9281, 9283, &\n 9293, 9311, 9319, 9323, 9337, 9341, 9343, 9349, 9371, 9377, &\n 9391, 9397, 9403, 9413, 9419, 9421, 9431, 9433, 9437, 9439, &\n 9461, 9463, 9467, 9473, 9479, 9491, 9497, 9511, 9521, 9533, &\n 9539, 9547, 9551, 9587, 9601, 9613, 9619, 9623, 9629, 9631, &\n 9643, 9649, 9661, 9677, 9679, 9689, 9697, 9719, 9721, 9733 /\n\n data ( npvec(i), i = 1201, 1300 ) / &\n 9739, 9743, 9749, 9767, 9769, 9781, 9787, 9791, 9803, 9811, &\n 9817, 9829, 9833, 9839, 9851, 9857, 9859, 9871, 9883, 9887, &\n 9901, 9907, 9923, 9929, 9931, 9941, 9949, 9967, 9973,10007, &\n 10009,10037,10039,10061,10067,10069,10079,10091,10093,10099, &\n 10103,10111,10133,10139,10141,10151,10159,10163,10169,10177, &\n 10181,10193,10211,10223,10243,10247,10253,10259,10267,10271, &\n 10273,10289,10301,10303,10313,10321,10331,10333,10337,10343, &\n 10357,10369,10391,10399,10427,10429,10433,10453,10457,10459, &\n 10463,10477,10487,10499,10501,10513,10529,10531,10559,10567, &\n 10589,10597,10601,10607,10613,10627,10631,10639,10651,10657 /\n\n data ( npvec(i), i = 1301, 1400 ) / &\n 10663,10667,10687,10691,10709,10711,10723,10729,10733,10739, &\n 10753,10771,10781,10789,10799,10831,10837,10847,10853,10859, &\n 10861,10867,10883,10889,10891,10903,10909,19037,10939,10949, &\n 10957,10973,10979,10987,10993,11003,11027,11047,11057,11059, &\n 11069,11071,11083,11087,11093,11113,11117,11119,11131,11149, &\n 11159,11161,11171,11173,11177,11197,11213,11239,11243,11251, &\n 11257,11261,11273,11279,11287,11299,11311,11317,11321,11329, &\n 11351,11353,11369,11383,11393,11399,11411,11423,11437,11443, &\n 11447,11467,11471,11483,11489,11491,11497,11503,11519,11527, &\n 11549,11551,11579,11587,11593,11597,11617,11621,11633,11657 /\n\n data ( npvec(i),i = 1401, 1500 ) / &\n 11677,11681,11689,11699,11701,11717,11719,11731,11743,11777, &\n 11779,11783,11789,11801,11807,11813,11821,11827,11831,11833, &\n 11839,11863,11867,11887,11897,11903,11909,11923,11927,11933, &\n 11939,11941,11953,11959,11969,11971,11981,11987,12007,12011, &\n 12037,12041,12043,12049,12071,12073,12097,12101,12107,12109, &\n 12113,12119,12143,12149,12157,12161,12163,12197,12203,12211, &\n 12227,12239,12241,12251,12253,12263,12269,12277,12281,12289, &\n 12301,12323,12329,12343,12347,12373,12377,12379,12391,12401, &\n 12409,12413,12421,12433,12437,12451,12457,12473,12479,12487, &\n 12491,12497,12503,12511,12517,12527,12539,12541,12547,12553 /\n!\n if ( n == -1 ) then\n prime = maxprime\n else if ( n == 0 ) then\n prime = 1\n else if ( n <= maxprime ) then\n prime = npvec(n)\n else\n prime = 0\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PRIMES - Fatal error!'\n write ( *, '(a)' ) ' Illegal prime index N = ', n\n write ( *, '(a,i6)' ) ' but N must be between 0 and MAXPRIME =', maxprime\n stop\n end if\n\n return\nend\nsubroutine pythag_triple_next ( i, j, a, b, c )\n!\n!*******************************************************************************\n!\n!! PYTHAG_TRIPLE_NEXT computes the next Pythagorean triple.\n!\n!\n! Modified:\n!\n! 08 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input/output, integer I, J, the generators.\n! On first call, set I = J = 0. On repeated calls, leave I and J\n! at their output values from the previous call.\n!\n! Output, integer A, B, C, the next Pythagorean triple.\n! A, B, and C are positive integers which have no common factors,\n! and A**2 + B**2 = C**2.\n!\n implicit none\n!\n integer a\n integer b\n integer c\n integer i\n integer j\n!\n! I starts at 2 and increases;\n!\n! J starts out at 2 if I is odd, or 1 if I is even, increases by 2,\n! but is always less than I.\n!\n if ( i == 0 .and. j == 0 ) then\n i = 2\n j = 1\n else if ( j + 2 < i ) then\n j = j + 2\n else\n i = i + 1\n j = mod ( i, 2 ) + 1\n end if\n\n a = i**2 - j**2\n b = 2 * i * j\n c = i**2 + j**2\n\n return\nend\nfunction r_agm ( a, b )\n!\n!*******************************************************************************\n!\n!! R_AGM finds the arithmetic-geometric mean of two numbers.\n!\n!\n! Discussion:\n!\n! The AGM of (A,B) is produced by the following iteration:\n!\n! (A,B) -> ( (A+B)/2, SQRT(A*B) ).\n!\n! The sequence of successive values of (A,B) quickly converge to the AGM.\n!\n! Modified:\n!\n! 02 June 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real A, B, the numbers whose AGM is desired. A and B should\n! both be non-negative.\n!\n! Output, real R_AGM, the AGM of the two numbers.\n!\n implicit none\n!\n real a\n real a1\n real a2\n real b\n real b1\n real b2\n real tol\n real r_agm\n!\n if ( a < 0.0E+00 ) then\n r_agm = -1.0E+00\n return\n end if\n\n if ( b < 0.0E+00 ) then\n r_agm = -1.0E+00\n return\n end if\n\n if ( a == 0.0E+00 .or. b == 0.0E+00 ) then\n r_agm = 0.0E+00\n return\n end if\n\n if ( a == b ) then\n r_agm = a\n return\n end if\n\n tol = epsilon ( tol ) * ( a + b + 1.0E+00 )\n\n a1 = a\n b1 = b\n\n do\n\n a2 = ( a1 + b1 ) / 2.0E+00\n b2 = sqrt ( a1 * b1 )\n\n if ( abs ( a2 - b2 ) < tol ) then\n r_agm = ( a2 + b2 ) / 2.0E+00\n exit\n end if\n\n a1 = a2\n b1 = b2\n\n end do\n\n return\nend\nfunction r_pi ( )\n!\n!*******************************************************************************\n!\n!! R_PI returns the value of pi.\n!\n!\n! Modified:\n!\n! 04 December 1998\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Output, real R_PI, the value of pi.\n!\n implicit none\n!\n real r_pi\n!\n r_pi = 3.14159265358979323846264338327950288419716939937510E+00\n\n return\nend\nsubroutine r_random ( rlo, rhi, r )\n!\n!*******************************************************************************\n!\n!! R_RANDOM returns a random real in a given range.\n!\n!\n! Modified:\n!\n! 26 October 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real RLO, RHI, the minimum and maximum values.\n!\n! Output, real R, the randomly chosen value.\n!\n implicit none\n!\n real r\n real rhi\n real rlo\n real t\n!\n! Pick a random number in (0,1).\n!\n call random_number ( harvest = t )\n!\n! Set R.\n!\n r = ( 1.0E+00 - t ) * rlo + t * rhi\n\n return\nend\nsubroutine r_swap ( x, y )\n!\n!*******************************************************************************\n!\n!! R_SWAP switches two real values.\n!\n!\n! Modified:\n!\n! 30 November 1998\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input/output, real X, Y. On output, the values of X and\n! Y have been interchanged.\n!\n implicit none\n!\n real x\n real y\n real z\n!\n z = x\n x = y\n y = z\n\n return\nend\nsubroutine r_to_cfrac ( r, n, a, p, q )\n!\n!*******************************************************************************\n!\n!! R_TO_CFRAC converts a real value to a continued fraction.\n!\n!\n! Discussion:\n!\n! The routine is given a real number R. It computes a sequence of\n! continued fraction approximations to R, returning the results as\n! simple fractions of the form P(I) / Q(I).\n!\n! Example:\n!\n! X = 2 * PI\n! N = 7\n!\n! A = [ *, 6, 3, 1, 1, 7, 2, 146, 3 ]\n! P = [ 1, 6, 19, 25, 44, 333, 710, 103993, 312689 ]\n! Q = [ 0, 1, 3, 4, 7, 53, 113, 16551, 49766 ]\n!\n! (This ignores roundoff error, which will cause later terms to differ).\n!\n! Reference:\n!\n! Norman Richert,\n! Strang's Strange Figures,\n! American Mathematical Monthly,\n! Volume 99, Number 2, February 1992, pages 101-107.\n!\n! Modified:\n!\n! 10 June 2002\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real R, the real value.\n!\n! Input, integer N, the number of convergents to compute.\n!\n! Output, integer A(0:N), the partial quotients.\n!\n! Output, integer P(-1:N), Q(-1:N), the numerators and denominators\n! of the continued fraction approximations.\n!\n implicit none\n!\n integer n\n!\n integer a(0:n)\n integer i\n integer p(-1:n)\n integer q(-1:n)\n real r\n real r_copy\n real x(0:n)\n!\n if ( r == 0.0E+00 ) then\n a(0:n) = 0\n p(-1:n) = 0\n q(-1:n) = 1\n return\n end if\n\n r_copy = abs ( r )\n\n p(-1) = 1\n q(-1) = 0\n\n p(0) = int ( r_copy )\n q(0) = 1\n x(0) = r_copy\n a(0) = int ( x(0) )\n\n do i = 1, n\n x(i) = 1.0E+00 / ( x(i-1) - real ( a(i-1) ) )\n a(i) = int ( x(i) )\n p(i) = a(i) * p(i-1) + p(i-2)\n q(i) = a(i) * q(i-1) + q(i-2)\n end do\n\n if ( r < 0.0E+00 ) then\n p(-1:n) = - p(-1:n)\n end if\n\n return\nend\nsubroutine r_to_dec ( rval, itop, ibot )\n!\n!*******************************************************************************\n!\n!! R_TO_DEC converts a real value to a decimal fraction form.\n!\n!\n! Discussion:\n!\n! The routine computes ITOP and IBOT, so that approximately:\n!\n! RVAL = ITOP * 10 ** IBOT\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real RVAL, the real number whose decimal\n! representation is desired.\n!\n! Output, integer ITOP, IBOT, form the decimal\n! representation of RVAL, approximately.\n!\n! ITOP is an integer, strictly between -10**NDIG and 10**NDIG.\n! IBOT is an integer exponent of 10.\n!\n implicit none\n!\n integer dec_digit\n integer ibot\n integer itop\n real rtop\n real rval\n real ten1\n real ten2\n!\n dec_digit = 0\n call i_data ( 'GET', 'DEC_DIGIT', dec_digit )\n!\n! Special cases.\n!\n if ( rval == 0.0E+00 ) then\n itop = 0\n ibot = 0\n return\n end if\n!\n! Factor RVAL = RTOP * 10**IBOT\n!\n rtop = rval\n ibot = 0\n!\n! Now normalize so that 10**(DEC_DIGIT-1) <= ABS(RTOP) < 10**(DEC_DIGIT)\n!\n ten1 = 10.0E+00**( dec_digit - 1 )\n ten2 = 10.0E+00**dec_digit\n\n do while ( abs ( rtop ) < ten1 )\n rtop = rtop * 10.0E+00\n ibot = ibot - 1\n end do\n\n do while ( abs ( rtop ) >= ten2 )\n rtop = rtop / 10.0E+00\n ibot = ibot + 1\n end do\n!\n! ITOP is the integer part of RTOP, rounded.\n!\n itop = nint ( rtop )\n!\n! Now divide out any factors of ten from ITOP.\n!\n if ( itop /= 0 ) then\n do while ( 10 * ( itop / 10 ) == itop )\n itop = itop / 10\n ibot = ibot + 1\n end do\n end if\n\n return\nend\nsubroutine r_to_rat ( a, iatop, iabot, ndig )\n!\n!*******************************************************************************\n!\n!! R_TO_RAT converts a real value to a rational value.\n!\n!\n! Discussion:\n!\n! The rational value (IATOP/IABOT) is essentially computed by truncating\n! the decimal representation of the real value after a given number of\n! decimal digits.\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real A, the real value to be converted.\n!\n! Output, integer IATOP, IABOT, the numerator and denominator\n! of the rational value that approximates A.\n!\n! Input, integer NDIG, the number of decimal digits used.\n!\n implicit none\n!\n real a\n real factor\n integer i_gcd\n integer iabot\n integer iatop\n integer ibot\n integer ifac\n integer itemp\n integer itop\n integer jfac\n integer ndig\n!\n factor = 10.0E+00**ndig\n\n if ( ndig > 0 ) then\n ifac = 10**ndig\n jfac = 1\n else\n ifac = 1\n jfac = 10**(-ndig)\n end if\n\n itop = nint ( a * factor ) * jfac\n ibot = ifac\n!\n! Factor out the greatest common factor.\n!\n itemp = i_gcd ( itop, ibot )\n\n iatop = itop / itemp\n iabot = ibot / itemp\n\n return\nend\nsubroutine r_to_s_left ( rval, s )\n!\n!*******************************************************************************\n!\n!! R_TO_S_LEFT represents a real using 14 left_justified characters.\n!\n!\n! Modified:\n!\n! 22 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real RVAL, a real number.\n!\n! Output, character ( len = * ) S, a left-justified character variable\n! containing the representation of RVAL.\n!\n implicit none\n!\n character ( len = 14 ) chrtmp\n integer i\n real rval\n character ( len = * ) s\n!\n! We can't seem to write directly into the string because of compiler\n! quibbles.\n!\n if ( real ( int ( rval ) ) == rval .and. abs ( rval ) < 1.0E+13 ) then\n\n write ( chrtmp, '(i14)' ) int ( rval )\n\n else\n\n write ( chrtmp, '(g14.6)' ) rval\n\n end if\n\n do i = 1, len ( chrtmp )\n if ( chrtmp(i:i) /= ' ' ) then\n s = chrtmp(i:)\n return\n end if\n end do\n\n s = ' '\n\n return\nend\nsubroutine random_initialize ( seed )\n!\n!*******************************************************************************\n!\n!! RANDOM_INITIALIZE initializes the FORTRAN 90 random number seed.\n!\n!\n! Discussion:\n!\n! If you don't initialize the random number generator, its behavior\n! is not specified. If you initialize it simply by:\n!\n! call random_seed\n!\n! its behavior is not specified. On the DEC ALPHA, if that's all you\n! do, the same random number sequence is returned. In order to actually\n! try to scramble up the random number generator a bit, this routine\n! goes through the tedious process of getting the size of the random\n! number seed, making up values based on the current time, and setting\n! the random number seed.\n!\n! Modified:\n!\n! 03 April 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input/output, integer SEED.\n! If SEED is zero on input, then you're asking this routine to come up\n! with a seed value, which is returned as output.\n! If SEED is nonzero on input, then you're asking this routine to\n! use the input value of SEED to initialize the random number generator.\n!\n implicit none\n!\n integer count\n integer count_max\n integer count_rate\n integer i\n integer seed\n integer, allocatable :: seed_vector(:)\n integer seed_size\n real t\n!\n! Initialize the random number seed.\n!\n call random_seed ( )\n!\n! Determine the size of the random number seed.\n!\n call random_seed ( size = seed_size )\n!\n! Allocate a seed of the right size.\n!\n allocate ( seed_vector(seed_size) )\n\n if ( seed /= 0 ) then\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'RANDOM_INITIALIZE'\n write ( *, '(a,i12)' ) ' Initialize RANDOM_NUMBER with user SEED = ', seed\n\n else\n\n call system_clock ( count, count_rate, count_max )\n\n seed = count\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'RANDOM_INITIALIZE'\n write ( *, '(a,i12)' ) &\n ' Initialize RANDOM_NUMBER with arbitrary SEED = ', seed\n\n end if\n!\n! Now set the seed.\n!\n seed_vector(1:seed_size) = seed\n\n call random_seed ( put = seed_vector(1:seed_size) )\n!\n! Free up the seed space.\n!\n deallocate ( seed_vector )\n!\n! Call the random number routine a bunch of times.\n!\n do i = 1, 100\n call random_number ( harvest = t )\n end do\n\n return\nend\nsubroutine rat_add ( itop1, ibot1, itop2, ibot2, itop, ibot, ierror )\n!\n!*******************************************************************************\n!\n!! RAT_ADD adds two rational values.\n!\n!\n! Discussion:\n!\n! The routine computes\n!\n! ITOP/IBOT = ITOP1/IBOT1 + ITOP2/IBOT2\n!\n! while trying to avoid integer overflow.\n!\n! Modified:\n!\n! 01 February 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ITOP1, IBOT1, the first value to add.\n!\n! Input, integer ITOP2, IBOT2, the second value to add.\n!\n! Output, integer ITOP, IBOT, the sum.\n!\n! Output, integer IERROR.\n! 0, no error occurred.\n! 1, an error occurred. The addition of the two values\n! requires a numerator or denominator larger than the\n! maximum legal integer.\n!\n! Output, integer ITOP, the numerator of the result.\n!\n! Input, integer ITOP1, ITOP2, the numerators of the\n! two rational values to be added.\n!\n implicit none\n!\n integer i_gcd\n integer ibot\n integer ibot1\n integer ibot2\n integer ierror\n integer i_max\n integer itemp\n integer itop\n integer itop1\n integer itop2\n integer jbot1\n integer jbot2\n integer jbot3\n integer jtop1\n integer jtop2\n!\n i_max = huge ( i_max )\n\n ierror = 0\n\n if ( itop1 == 0 ) then\n itop = itop2\n ibot = ibot2\n return\n else if ( itop2 == 0 ) then\n itop = itop1\n ibot = ibot1\n return\n end if\n!\n! Make copies of the input arguments, since we will change them.\n!\n jbot1 = ibot1\n jbot2 = ibot2\n jtop1 = itop1\n jtop2 = itop2\n!\n! Compute the greatest common factor of the two denominators,\n! and factor it out.\n!\n jbot3 = i_gcd ( jbot1, jbot2 )\n jbot1 = jbot1 / jbot3\n jbot2 = jbot2 / jbot3\n!\n! The fraction may now be formally written as:\n!\n! (jtop1*jbot2 + jtop2*jbot1) / (jbot1*jbot2*jbot3)\n!\n! Check the tops for overflow.\n!\n if ( abs ( real ( jtop1 ) * real ( jbot2 ) ) > real ( i_max ) ) then\n ierror = 1\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'RAT_ADD - Fatal error!'\n write ( *, '(a)' ) ' Overflow of top of rational sum.'\n itop = 0\n stop\n end if\n\n jtop1 = jtop1 * jbot2\n\n if ( abs ( real ( jtop2 ) * real ( jbot1 ) ) > real ( i_max ) ) then\n ierror = 1\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'RAT_ADD - Fatal error!'\n write ( *, '(a)' ) ' Overflow of top of rational sum.'\n itop = 0\n stop\n end if\n\n jtop2 = jtop2 * jbot1\n\n if ( abs ( real ( jtop1 ) + real ( jtop2 ) ) > real ( i_max ) ) then\n ierror = 1\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'RAT_ADD - Fatal error!'\n write ( *, '(a)' ) ' Overflow of top of rational sum.'\n itop = 0\n stop\n end if\n\n itop = jtop1 + jtop2\n!\n! Check the bottom for overflow.\n!\n if ( abs ( real ( jbot1 ) * real ( jbot2 ) * real ( jbot3 ) ) > &\n real ( i_max ) ) then\n ierror = 1\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'RAT_ADD - Fatal error!'\n write ( *, '(a)' ) ' Overflow of bottom of rational sum.'\n ibot = 1\n stop\n end if\n\n ibot = jbot1 * jbot2 * jbot3\n!\n! Put the fraction in lowest terms.\n!\n itemp = i_gcd ( itop, ibot )\n itop = itop / itemp\n ibot = ibot / itemp\n!\n! The bottom should be positive.\n!\n if ( ibot < 0 ) then\n ibot = - ibot\n itop = - itop\n end if\n\n return\nend\nsubroutine rat_div ( itop1, ibot1, itop2, ibot2, itop, ibot, ierror )\n!\n!*******************************************************************************\n!\n!! RAT_DIV divides one rational value by another.\n!\n!\n! Discussion:\n!\n! The routine computes\n!\n! ITOP / IBOT = ( ITOP1 / IBOT1 ) / ( ITOP2 / IBOT2 ).\n!\n! while avoiding integer overflow.\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ITOP1, IBOT1, the numerator.\n!\n! Input, integer ITOP2, IBOT2, the denominator.\n!\n! Output, integer ITOP, IBOT, the result.\n!\n! Output, integer IERROR.\n! 0, no error occurred.\n! 1, an error occurred. One of the quantities IBOT1, IBOT2,\n! or ITOP2 is zero, or the result of the division\n! requires a numerator or denominator larger than the\n! maximum legal integer.\n!\n implicit none\n!\n integer i_gcd\n integer i_max\n integer ibot\n integer ibot1\n integer ibot2\n integer ierror\n integer itemp\n integer itop\n integer itop1\n integer itop2\n integer jbot1\n integer jbot2\n integer jtop1\n integer jtop2\n!\n ierror = 0\n\n i_max = huge ( i_max )\n\n if ( ibot1 == 0 .or. itop2 == 0 .or. ibot2 == 0 ) then\n ierror = 1\n return\n end if\n\n if ( itop1 == 0 ) then\n itop = 0\n ibot = 1\n return\n end if\n!\n! Make copies of the input arguments, since we will change them.\n! Implicitly invert the divisor fraction here. The rest of\n! the code will be a multiply operation.\n!\n jbot1 = ibot1\n jbot2 = itop2\n jtop1 = itop1\n jtop2 = ibot2\n!\n! Get rid of all common factors in top and bottom.\n!\n itemp = i_gcd ( jtop1, jbot1 )\n jtop1 = jtop1 / itemp\n jbot1 = jbot1 / itemp\n itemp = i_gcd ( jtop1, jbot2 )\n jtop1 = jtop1 / itemp\n jbot2 = jbot2 / itemp\n itemp = i_gcd ( jtop2, jbot1 )\n jtop2 = jtop2 / itemp\n jbot1 = jbot1 / itemp\n itemp = i_gcd ( jtop2, jbot2 )\n jtop2 = jtop2 / itemp\n jbot2 = jbot2 / itemp\n!\n! The fraction (ITOP1*IBOT2)/(IBOT1*ITOP2) is in lowest terms.\n!\n! Check the top for overflow.\n!\n if ( abs ( real ( jtop1 ) * abs ( jtop2 ) ) > real ( i_max ) ) then\n ierror = 1\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'RAT_DIV - Fatal error!'\n write ( *, '(a)' ) ' Overflow of top of rational fraction.'\n itop = 0\n return\n end if\n\n itop = jtop1 * jtop2\n!\n! Check the bottom IBOT1*ITOP2 for overflow.\n!\n if ( abs ( real ( jbot1 ) * real ( jbot2 ) ) > real ( i_max ) ) then\n ierror = 1\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'RAT_DIV - Fatal error!'\n write ( *, '(a)' ) ' Overflow of bottom of rational fraction.'\n ibot = 1\n return\n end if\n\n ibot = jbot1 * jbot2\n!\n! The bottom should be positive.\n!\n if ( ibot < 0 ) then\n ibot = - ibot\n itop = - itop\n end if\n!\n! The fraction is ITOP/IBOT with no loss of accuracy.\n!\n return\nend\nsubroutine rat_farey ( n, max_frac, num_frac, a, b )\n!\n!*******************************************************************************\n!\n!! RAT_FAREY computes the N-th row of the Farey fraction table.\n!\n!\n! Example:\n!\n! N = 5\n!\n! NUM_FRAC = 11\n! A = 0 1 1 1 2 1 3 2 3 4 1\n! B = 1 5 4 3 5 2 5 3 4 5 1\n!\n! Discussion:\n!\n! In this form of the Farey fraction table, fractions in row N lie between\n! 0 and 1, are in lowest terms, and have a denominator that is no greater\n! than N. Row N is computed directly, and does not require the computation\n! of previous rows.\n!\n! The data satisfy the relationship:\n!\n! A(K+1) * B(K) - A(K) * B(K+1) = 1\n!\n! The number of items in the N-th row is roughly N**2 / PI**2.\n!\n! Reference:\n!\n! Donald Knuth,\n! The Art of Computer Programming,\n! Volume 1, Fundamental Algorithms,\n! Addison Wesley, 1968, page 157.\n!\n! Modified:\n!\n! 31 July 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the desired row number. N must be positive.\n!\n! Input, integer MAX_FRAC, the maximum number of fractions to compute.\n!\n! Output, integer NUM_FRAC, the number of fractions computed.\n!\n! Output, integer A(MAX_FRAC), B(MAX_FRAC), contains the NUM_FRAC\n! numerators and denominators of the N-th row of the Farey fraction table.\n!\n implicit none\n!\n integer max_frac\n!\n integer a(max_frac)\n integer b(max_frac)\n integer c\n integer k\n integer n\n integer num_frac\n!\n if ( n <= 0 ) then\n num_frac = 0\n return\n end if\n\n if ( max_frac <= 0 ) then\n num_frac = k\n return\n end if\n\n k = 1\n a(k) = 0\n b(k) = 1\n\n if ( max_frac <= 1 ) then\n num_frac = k\n return\n end if\n\n k = 2\n a(k) = 1\n b(k) = n\n\n do while ( k < max_frac )\n\n if ( a(k) == 1 .and. b(k) == 1 ) then\n exit\n end if\n\n k = k + 1\n c = int ( ( b(k-2) + n ) / b(k-1) )\n a(k) = c * a(k-1) - a(k-2)\n b(k) = c * b(k-1) - b(k-2)\n\n end do\n\n num_frac = k\n\n return\nend\nsubroutine rat_farey2 ( n, a, b )\n!\n!*******************************************************************************\n!\n!! RAT_FAREY2 computes the next row of the Farey fraction table.\n!\n!\n! Example:\n!\n! Input:\n!\n! N = 3\n! A = 0 1 1 2 1\n! B = 1 3 2 3 1\n!\n! Output:\n!\n! A = 0 1 1 2 1 3 2 3 1\n! B = 1 4 3 5 2 5 3 4 1\n!\n! Discussion:\n!\n! In this form of the Farey fraction table, fractions in row N lie between\n! 0 and 1, and are in lowest terms. For every adjacent pair of input\n! fractions, A1/B1 and A2/B2, the mediant (A1+A2)/(B1+B2) is computed\n! and inserted between them.\n!\n! The number of items in the N-th row is 1+2**(N-1).\n!\n! Modified:\n!\n! 31 July 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the input row number. N must be nonnegative.\n! If N is zero, then the input is ignored, and the entries of\n! row 1 are computed directly.\n!\n! Input/output, integer A(1+2**N), B(1+2**N).\n! On input, entries 1 through 1+2**(N-1) contain the entries of row N.\n! On output, entries 1 through 1+2**N contain the entries of row N+1.\n!\n implicit none\n!\n integer n\n!\n integer a(1+2**n)\n integer b(1+2**n)\n integer i\n\n if ( n == 0 ) then\n a(1) = 0\n b(1) = 1\n a(2) = 1\n b(2) = 1\n return\n end if\n!\n! Shift the current data.\n!\n do i = 1+2**(n-1), 1, -1\n a(2*i-1) = a(i)\n b(2*i-1) = b(i)\n end do\n!\n! Compute the mediants.\n!\n do i = 2, 2**n, 2\n a(i) = a(i-1) + a(i+1)\n b(i) = b(i-1) + b(i+1)\n end do\n\n return\nend\nsubroutine rat_mul ( itop1, ibot1, itop2, ibot2, itop, ibot, ierror )\n!\n!*******************************************************************************\n!\n!! RAT_MUL multiplies two fractions.\n!\n!\n! Discussion:\n!\n! The routine computes\n!\n! ITOP / IBOT = ( ITOP1 / IBOT1 ) * ( ITOP2 / IBOT2 ).\n!\n! while avoiding integer overflow.\n!\n! Modified:\n!\n! 01 February 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ITOP1, IBOT1, the first factor.\n!\n! Input, integer ITOP2, IBOT2, the second factor.\n!\n! Output, integer ITOP, IBOT, the product.\n!\n! Output, integer IERROR.\n! 0, no error occurred.\n! 1, an error occurred. The multiplication of the two values\n! requires a numerator or denominator larger than the\n! maximum legal integer.\n!\n implicit none\n!\n integer i_gcd\n integer i_max\n integer ibot\n integer ibot1\n integer ibot2\n integer ierror\n integer itemp\n integer itop\n integer itop1\n integer itop2\n integer jbot1\n integer jbot2\n integer jtop1\n integer jtop2\n!\n ierror = 0\n\n i_max = huge ( i_max )\n\n if ( itop1 == 0 .or. itop2 == 0 ) then\n itop = 0\n ibot = 1\n return\n end if\n!\n! Make copies of the input arguments, since we will change them.\n!\n jbot1 = ibot1\n jbot2 = ibot2\n jtop1 = itop1\n jtop2 = itop2\n!\n! Get rid of all common factors in top and bottom.\n!\n itemp = i_gcd ( jtop1, jbot1 )\n jtop1 = jtop1 / itemp\n jbot1 = jbot1 / itemp\n itemp = i_gcd ( jtop1, jbot2 )\n jtop1 = jtop1 / itemp\n jbot2 = jbot2 / itemp\n itemp = i_gcd ( jtop2, jbot1 )\n jtop2 = jtop2 / itemp\n jbot1 = jbot1 / itemp\n itemp = i_gcd ( jtop2, jbot2 )\n jtop2 = jtop2 / itemp\n jbot2 = jbot2 / itemp\n!\n! The fraction (ITOP1*ITOP2)/(IBOT1*IBOT2) is in lowest terms.\n!\n! Check the top ITOP1*ITOP2 for overflow.\n!\n if ( abs ( real ( jtop1 ) * real ( jtop2 ) ) > real ( i_max ) ) then\n ierror = 1\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'RAT_MUL - Fatal error!'\n write ( *, '(a)' ) ' Overflow of top of rational product.'\n itop = 0\n return\n end if\n\n itop = jtop1 * jtop2\n!\n! Check the bottom IBOT1*IBOT2 for overflow.\n!\n if ( abs ( real ( jbot1 ) * real ( jbot2 ) ) > real ( i_max ) ) then\n ierror = 1\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'RAT_MUL - Fatal error!'\n write ( *, '(a)' ) ' Overflow of bottom of rational product.'\n ibot = 1\n return\n end if\n\n ibot = jbot1 * jbot2\n!\n! The bottom should be positive.\n!\n if ( ibot < 0 ) then\n ibot = - ibot\n itop = - itop\n end if\n!\n! The fraction is ITOP/IBOT with no loss of accuracy.\n!\n return\nend\nsubroutine rat_sum_formula ( n, a, b )\n!\n!*******************************************************************************\n!\n!! RAT_SUM_FORMULA computes the formulas for sums of powers of integers.\n!\n!\n! Example:\n!\n! N = 6\n!\n! 1 2 3 4 5 6 7\n! -----------------------------------\n! 0 | 1 0 0 0 0 0 0\n! |\n! 1 | 1 1 0 0 0 0 0\n! | 2 2\n! |\n! 2 | 1 1 1 0 0 0 0\n! | 3 2 6\n! |\n! 3 | 1 1 1 0 0 0 0\n! | 4 2 4\n! | \n! 4 | 1 1 1 0 -1 0 0\n! | 5 2 3 30\n! |\n! 5 | 1 1 5 0 -1 0 0\n! | 6 2 12 12\n! |\n! 6 | 1 1 1 0 -1 0 1\n! | 7 2 2 6 42\n!\n! The interpretation of row 2, for instance, is:\n!\n! sum ( 1 <= I <= N ) I**2 = 1/3 N**3 + 1/2 N**2 + 1/6 N\n!\n! This suggests that a more sensible way to display the table\n! is to reverse the order of the entries in the row, so that\n! the entry in column J is the coeeficient of N**J, which is\n! not the case now.\n!\n! Reference:\n!\n! Robert Owens,\n! Sums of Powers of Integers,\n! Mathematics Magazine,\n! Volume 65, Number 1, February 1992, pages 38-40.\n!\n! Modified:\n!\n! 11 June 2002\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of rows of coefficients to compute.\n!\n! Output, integer A(0:N,N+1), B(0:N,N+1), the numerator and denominator\n! of the coefficients.\n!\n implicit none\n!\n integer n\n!\n integer a(0:n,1:n+1)\n integer asum\n integer b(0:n,1:n+1)\n integer bsum\n integer i\n integer ierror\n integer j\n!\n a(0,1) = 1\n b(0,1) = 1\n a(0,2:n+1) = 0\n b(0,2:n+1) = 1\n\n do i = 1, n\n\n asum = 0\n bsum = 0\n!\n! Subdiagonal entries are multiples of entries above them.\n!\n do j = 1, i\n\n call rat_mul ( a(i-1,j), b(i-1,j), i, i+2-j, a(i,j), b(i,j), ierror )\n\n call rat_add ( asum, bsum, a(i,j), b(i,j), asum, bsum, ierror )\n\n end do\n!\n! Diagonal entry is 1 - sum of previous entries in row.\n!\n asum = - asum\n call rat_add ( 1, 1, asum, bsum, a(i,i+1), b(i,i+1), ierror )\n!\n! Superdiagonal entries are zero.\n!\n a(i,i+2:n+1) = 0\n b(i,i+2:n+1) = 1\n\n end do\n\n return\nend\nsubroutine rat_to_cfrac ( a, ierror, m, n, ip, iq )\n!\n!*******************************************************************************\n!\n!! RAT_TO_CFRAC converts a rational value to a continued fraction.\n!\n!\n! Discussion:\n!\n! The routine is given a rational number represented by IP/IQ, and\n! computes the monic or \"simple\" continued fraction representation\n! with integer coefficients of the number:\n!\n! A(1) + 1/ (A(2) + 1/ (A(3) + ... + 1/A(N) ...))\n!\n! The user must dimension A to a value M which is \"large enough\".\n! The actual number of terms needed in the continued fraction\n! representation cannot be known beforehand.\n!\n! Reference:\n!\n! Hart, Cheney, Lawson, Maehly, Mesztenyi, Rice, Thacher, Witzgall,\n! Computer Approximations,\n! Wiley, 1968.\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Output, integer A(M), contains the continued fraction\n! representation of the number.\n!\n! Output, integer IERROR, error indicator. 0 if no error,\n! 1 if there was an error, namely, M is not large enough.\n!\n! Input, integer M, the dimension of A. If M is not great\n! enough, the algorithm may run out of space.\n!\n! Output, integer N, the actual number of entries used in A.\n!\n! Input, integer IP, IQ, the numerator and denominator of the\n! rational value whose continued fraction representation is\n! desired.\n!\n implicit none\n!\n integer m\n!\n integer a(m)\n integer ierror\n integer ip\n integer iq\n integer jp\n integer jq\n integer n\n!\n jp = ip\n jq = iq\n\n n = 0\n\n do\n\n n = n + 1\n\n if ( n > m ) then\n ierror = 1\n return\n end if\n\n a(n) = jp / jq\n jp = mod ( jp, jq )\n\n if ( jp == 0 ) then\n return\n end if\n\n n = n + 1\n\n if ( n > m ) then\n ierror = 1\n return\n end if\n\n a(n) = jq / jp\n jq = mod ( jq, jp )\n\n if ( jq == 0 ) then\n exit\n end if\n\n end do\n\n return\nend\nsubroutine rat_to_r ( a, iatop, iabot )\n!\n!*******************************************************************************\n!\n!! RAT_TO_R converts rational values to real values.\n!\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Output, real A, the value of the rational quantity.\n!\n! Input, integer IATOP, IABOT, the rational quantity\n! (IATOP/IABOT) that is to be converted.\n!\n implicit none\n!\n real a\n integer iabot\n integer iatop\n!\n if ( iabot == 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'RAT_TO_R - Warning!'\n write ( *, '(a)' ) ' The input fraction to be converted had a'\n write ( *, '(a)' ) ' zero denominator.'\n a = 0.0E+00\n else\n a = real ( iatop ) / real ( iabot )\n end if\n\n return\nend\nsubroutine rat_to_s_left ( ival, jval, s )\n!\n!*******************************************************************************\n!\n!! RAT_TO_S_LEFT returns a left-justified representation of IVAL/JVAL.\n!\n!\n! Discussion:\n!\n! If the ratio is negative, a minus sign precedes IVAL.\n! A slash separates IVAL and JVAL.\n!\n! Modified:\n!\n! 13 September 1998\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer IVAL, JVAL, the two integers whose\n! ratio IVAL/JVAL is to be represented.\n!\n! Note that if IVAL is nonzero and JVAL is 0, STRING will\n! be returned as \"Inf\" or \"-Inf\" (Infinity), and if both\n! IVAL and JVAL are zero, STRING will be returned as \"NaN\"\n! (Not-a-Number).\n!\n! Output, character ( len = * ) S, a left-justified string\n! containing the representation of IVAL/JVAL.\n!\n implicit none\n!\n integer ival\n integer ival2\n integer jval\n integer jval2\n character ( len = * ) s\n character ( len = 22 ) s2\n!\n! Take care of simple cases right away.\n!\n if ( ival == 0 ) then\n\n if ( jval /= 0 ) then\n s2 = '0'\n else\n s2= 'NaN'\n end if\n\n else if ( jval == 0 ) then\n\n if ( ival > 0 ) then\n s2 = 'Inf'\n else\n s2 = '-Inf'\n end if\n!\n! Make copies of IVAL and JVAL.\n!\n else\n\n ival2 = ival\n jval2 = jval\n\n if ( jval2 == 1 ) then\n write ( s2, '(i11)' ) ival2\n else\n write ( s2, '(i11, ''/'', i10)' ) ival2, jval2\n end if\n\n call s_blank_delete ( s2 )\n\n end if\n\n s = s2\n\n return\nend\nsubroutine ratmat_det ( n, iatop, iabot, idtop, idbot, ierror )\n!\n!*******************************************************************************\n!\n!! RATMAT_DET finds the determinant of an N by N matrix of rational entries.\n!\n!\n! Discussion:\n!\n! The brute force method is used.\n!\n! This routine should only be used for small matrices, since this\n! calculation requires the summation of N! products of N numbers.\n!\n! Modified:\n!\n! 17 April 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of rows and columns of A.\n!\n! Input, integer IATOP(N,N), IABOT(N,N), the numerators\n! and denominators of the entries of the matrix.\n!\n! Output, integer IDTOP, IDBOT, the determinant of the matrix,\n! expressed as IDTOP/IDBOT.\n!\n! Output, integer IERROR.\n! 0, the determinant was computed.\n! 1, an overflow error occurred, and the determinant was not\n! computed.\n!\n implicit none\n!\n integer n\n!\n logical even\n integer i\n integer iabot(n,n)\n integer iatop(n,n)\n integer iarray(n)\n integer ibot\n integer ibot1\n integer ibot2\n integer idbot\n integer idtop\n integer ierror\n integer itop\n integer itop1\n integer itop2\n logical more\n!\n ierror = 0\n\n more = .false.\n idtop = 0\n idbot = 1\n\n do\n\n call perm_next ( n, iarray, more, even )\n\n if ( even ) then\n itop = 1\n else\n itop = -1\n end if\n\n ibot = 1\n\n do i = 1, n\n\n itop1 = itop\n ibot1 = ibot\n itop2 = iatop(i,iarray(i))\n ibot2 = iabot(i,iarray(i))\n\n call rat_mul ( itop1, ibot1, itop2, ibot2, itop, ibot, ierror )\n\n if ( ierror /= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'RATMAT_DET - Fatal error!'\n write ( *, '(a)' ) ' An overflow occurred.'\n write ( *, '(a)' ) ' The determinant calculation cannot be done'\n write ( *, '(a)' ) ' for this matrix.'\n idtop = 0\n idbot = 1\n return\n end if\n\n end do\n\n itop1 = itop\n ibot1 = ibot\n\n itop2 = idtop\n ibot2 = idbot\n\n call rat_add ( itop1, ibot1, itop2, ibot2, itop, ibot, ierror )\n\n if ( ierror == 0 ) then\n idtop = itop\n idbot = ibot\n else\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'RATMAT_DET - Fatal error!'\n write ( *, '(a)' ) ' An overflow occurred.'\n write ( *, '(a)' ) ' The determinant calculation cannot be done'\n write ( *, '(a)' ) ' for this matrix.'\n idtop = 0\n idbot = 1\n return\n end if\n\n if ( .not. more ) then\n exit\n end if\n\n end do\n!\n! The bottom should be positive.\n!\n if ( idbot < 0 ) then\n idbot = - idbot\n idtop = - idtop\n end if\n\n return\nend\nsubroutine ratmat_print ( m, n, a, b, title )\n!\n!*******************************************************************************\n!\n!! RATMAT_PRINT prints out rational vectors or matrices.\n!\n!\n! Modified:\n!\n! 12 July 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer M, N, the number of rows and columns in the matrix.\n!\n! Input, integer A(M,N), B(M,N), the current rational or decimal\n! matrix.\n!\n! Input, character ( len = * ) TITLE, a label for the object being printed.\n!\n implicit none\n!\n integer m\n integer n\n!\n integer a(m,n)\n integer b(m,n)\n character ( len = 10 ) chrtmp1\n character ( len = 10 ) chrtmp2\n character ( len = 10 ) chrtmp3\n character ( len = 40 ) format1\n character ( len = 40 ) format2\n integer i\n integer ichi\n integer iclo\n integer imax\n integer imin\n integer ione\n integer itemp\n integer izhi\n integer izlo\n integer j\n integer jmax\n integer jmin\n integer kmax\n integer, parameter :: ncolum = 80\n integer none\n integer npline\n character ( len = 100 ) output\n character ( len = * ) title\n!\n! Figure out how many rationals we can get in NCOLUM columns.\n!\n kmax = 3\n\n do i = 1, m\n do j = 1, n\n\n itemp = abs ( a(i,j) )\n\n do while ( itemp >= 10**(kmax-2) )\n kmax = kmax + 1\n end do\n\n itemp = abs ( b(i,j) )\n\n do while ( itemp > 10**(kmax-2) )\n kmax = kmax + 1\n end do\n\n end do\n end do\n\n kmax = kmax + 1\n npline = ncolum / kmax\n!\n! Create the formats.\n!\n call i_to_s_left ( npline, chrtmp2 )\n call i_to_s_left ( kmax, chrtmp3 )\n\n format1 = '(' // chrtmp2 // 'i' // chrtmp3 // ')'\n\n call s_blank_delete ( format1 )\n\n format2 = '(' // chrtmp2 // 'i' // chrtmp3 // ')'\n\n call s_blank_delete ( format2 )\n\n do jmin = 1, n, npline\n\n jmax = min ( jmin+npline-1, n )\n\n write ( *, '(a)' ) ' '\n\n if ( jmin == 1 ) then\n write ( *, '(a)' ) trim ( title )\n write ( *, '(a)' ) ' '\n end if\n\n if ( jmin > 1 .or. jmax < n ) then\n write ( output, * ) 'Columns ', jmin, ' to ', jmax\n call s_blanks_delete ( output )\n write ( *, '(a)' ) trim ( output )\n write ( *, '(a)' ) ' '\n end if\n\n do i = 1, m\n\n write ( *, format1 ) a(i,jmin:jmax)\n write ( output, format1 ) b(i,jmin:jmax)\n!\n! Delete each denominator that is 1. If all are 1, don't\n! even print out the line.\n!\n none = 0\n\n do j = jmin, jmax\n\n if ( b(i,j) == 1 ) then\n ione = (j-jmin+1) * kmax\n output(ione:ione) = ' '\n else\n none = 1\n end if\n\n end do\n\n write ( *, '(a)' ) trim ( output )\n\n if ( jmax == n .and. i == m ) then\n else\n write ( *, '(a)' ) ' '\n end if\n\n end do\n\n end do\n\n return\nend\nsubroutine regro_next ( done, n, v, vmax )\n!\n!*******************************************************************************\n!\n!! REGRO_NEXT computes restricted growth functions one at a time.\n!\n!\n! Definition:\n!\n! A restricted growth function on N is a vector (V(1), ..., V(N) )\n! of values V(I) between 1 and N, satisfying the requirements:\n! V(1) = 1;\n! V(I) <= 1 + max ( V(1), V(2), ..., V(I-1) ).\n!\n! Comments:\n!\n! The number of restricted growth functions on N is equal to\n! the Bell number B(N).\n!\n! There is a bijection between restricted growth functions on N\n! and set partitions of N.\n!\n! Examples:\n!\n! The 15 restricted growth functions for N = 4 are:\n!\n! (1111), (1112), (1121), (1122), (1123),\n! (1211), (1212), (1213), (1221), (1222),\n! (1223), (1231), (1232), (1233), (1234).\n!\n! Reference:\n!\n! Dennis Stanton and Dennis White,\n! Constructive Combinatorics,\n! Springer Verlag, New York, 1986, page 19.\n!\n! Modified:\n!\n! 15 July 1998\n!\n! Parameters:\n!\n! Input/output, logical DONE.\n! On first call, set DONE to .TRUE., and then do not alter it.\n!\n! On output, DONE will be .FALSE. if the routine has computed another\n! restricted growth function, or .TRUE. if all the restricted\n! growth functions have been returned.\n!\n! Input, integer N, the number of components in the restricted growth\n! function.\n!\n! Input/output, integer V(N). The user need not set this quantity\n! before the initial call, and should not alter it between successive\n! calls. On each return from the routine, with DONE = .FALSE.,\n! V will contain the componentwise values of the next restricted\n! growth function.\n!\n! Input/output, integer VMAX(N). The user need not set this quantity\n! before the initial call, and should not alter it between calls.\n! VMAX(I) records the largest value that component V(I) could take,\n! given the values of components 1 through I-1.\n!\n implicit none\n!\n integer n\n!\n logical done\n integer i\n integer j\n integer v(n)\n integer vmax(n)\n!\n! First call:\n!\n if ( done ) then\n\n v(1:n) = 1\n\n vmax(1) = 1\n vmax(2:n) = 2\n\n done = .false.\n!\n! Later calls.\n!\n else\n\n j = n\n\n do\n\n if ( j == 1 ) then\n done = .true.\n return\n end if\n\n if ( v(j) /= vmax(j) ) then\n exit\n end if\n\n j = j - 1\n\n end do\n\n v(j) = v(j) + 1\n\n do i = j+1, n\n\n v(i) = 1\n\n if ( v(j) == vmax(j) ) then\n vmax(i) = vmax(j) + 1\n else\n vmax(i) = vmax(j)\n end if\n\n end do\n\n end if\n\n return\nend\nsubroutine rfrac_to_cfrac ( m, p, q, t, ierror )\n!\n!*******************************************************************************\n!\n!! RFRAC_TO_CFRAC converts a rational polynomial fraction to a continued fraction.\n!\n!\n! Discussion:\n!\n! That is, it accepts\n!\n! P(1) + P(2) * X + ... + P(M) * X**(M-1)\n! -------------------------------------------------------\n! Q(1) + Q(2) * X + ... + Q(M) * X**(M-1) + Q(M+1) * X**M\n!\n! and returns the equivalent continued fraction:\n!\n! 1 / (T(1) + X/(T(2) + X/(...T(2*M-1)+X/(T(2*M) ... )))\n!\n! Reference:\n!\n! Hart, Cheney, Lawson, Maehly, Mesztenyi, Rice, Thacher, Witzgall,\n! Computer Approximations,\n! Wiley, 1968.\n!\n! Modified:\n!\n! 17 April 2000\n!\n! Parameters:\n!\n! Input, integer M, defines the number of P coefficients,\n! and is one less than the number of Q coefficients, and one\n! half the number of T coefficients.\n!\n! Input, real P(M), Q(M+1), the coefficients defining the rational\n! polynomial fraction.\n!\n! Output, real T(2*M), the coefficients defining the continued fraction.\n!\n! Output, integer IERROR, error flag.\n! 0, no error;\n! nonzero, the algorithm broke down at some point with a zero divisor.\n!\n implicit none\n!\n integer m\n!\n real a(m+1,2*m+1)\n integer i\n integer ierror\n integer k\n real p(m)\n real q(m+1)\n real t(2*m)\n real ta\n!\n ierror = 0\n\n a(1:m+1,1) = q(1:m+1)\n a(1:m, 2) = p(1:m)\n\n t(1) = a(1,1) / a(1,2)\n ta = a(m+1,1)\n\n do i = 1, m\n a(m-i+1,2*i+1) = ta\n end do\n\n do k = 1, 2*m-2\n\n do i = 1, (2*m-k)/2\n a(i,k+2) = a(i+1,k) - t(k) * a(i+1,k+1)\n end do\n\n if ( a(1,k+2) == 0.0E+00 ) then\n ierror = 1\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'RFRAC_TO_CFRAC - Fatal error!'\n write ( *, '(a,i6)' ) ' A(1,K+2) is zero for K = ', k\n stop\n end if\n\n t(k+1) = a(1,k+1) / a(1,k+2)\n\n end do\n\n t(2*m) = a(1,2*m) / a(1,2*m+1)\n\n return\nend\nsubroutine rfrac_to_jfrac ( m, p, q, r, s, ierror )\n!\n!*******************************************************************************\n!\n!! RFRAC_TO_JFRAC converts a rational polynomial fraction to a J fraction.\n!\n!\n! Discussion:\n!\n! The routine accepts\n!\n! P(1) + P(2) * X + ... + P(M) * X**(M-1)\n! -------------------------------------------------------\n! Q(1) + Q(2) * X + ... + Q(M) * X**(M-1) + Q(M+1) * X**M\n!\n! and returns the equivalent J-fraction:\n!\n! R(1)/ (X + S(1) + R(2)/(X + S(2) + R(3)/ ... + R(M)/(X+S(M))... ))\n!\n! Reference:\n!\n! Hart, Cheney, Lawson, Maehly, Mesztenyi, Rice, Thacher, Witzgall,\n! Computer Approximations,\n! Wiley, 1968.\n!\n! Modified:\n!\n! 17 April 2000\n!\n! Parameters:\n!\n! Input, integer M, defines the number of P, R, and S coefficients,\n! and is one less than the number of Q coefficients.\n!\n! Input, real P(M), Q(M+1), the coefficients defining the rational\n! polynomial fraction.\n!\n! Output, real R(M), S(M), the coefficients defining the\n! J-fraction.\n!\n! Output, integer IERROR, error flag.\n! IERROR is zero on return, unless the algorithm broke down at\n! some point with a zero divisor, in which case IERROR = 1.\n!\n implicit none\n!\n integer m\n!\n real a(m+1,m+1)\n integer i\n integer ierror\n integer k\n real p(m)\n real q(m+1)\n real r(m)\n real s(m)\n!\n ierror = 0\n\n a(1:m+1,1) = q(1:m+1)\n a(1:m, 2) = p(1:m)\n\n if ( m > 1 ) then\n\n r(1) = a(m,2) / a(m+1,1)\n s(1) = ( r(1) * a(m,1) - a(m-1,2) ) / a(m,2)\n\n do k = 1, m-2\n\n a(1,k+2) = r(k) * a(1,k) - s(k) * a(1,k+1)\n\n do i = 2, m-k\n\n a(i,k+2) = r(k) * a(i,k) - a(i-1,k+1) - s(k) * a(i,k+1)\n\n if ( a(m-k,k+2) == 0.0E+00 ) then\n ierror = 1\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'RFRAC_TO_JFRAC - Fatal error!'\n write ( *, '(a,i6)' ) ' A(M-K,K+2) = 0 for K=', k\n stop\n end if\n\n r(k+1) = a(m-k,k+2) / a(m-k+1,k+1)\n s(k+1) = ( r(k+1) * a(m-k,k+1) - a(m-k-1,k+2) ) / a(m-k,k+2)\n\n end do\n\n end do\n\n a(1,m+1) = r(m-1) * a(1,m-1) - s(m-1) * a(1,m)\n\n end if\n\n r(m) = a(1,m+1) / a(2,m)\n s(m) = a(1,m) / a(2,m)\n\n return\nend\nfunction rise ( x, n )\n!\n!*******************************************************************************\n!\n!! RISE computes the rising factorial function [X]^N.\n!\n!\n! Discussion:\n!\n! [X}^N = X * ( X + 1 ) * ( X + 2 ) * ... * ( X + N - 1 ).\n!\n! Note that the number of ways of arranging N objects in M ordered\n! boxes is [M}^N. (Here, the ordering in each box matters). Thus,\n! 2 objects in 2 boxes have the following 6 possible arrangements:\n!\n! -/12, 1/2, 12/-, -/21, 2/1, 21/-.\n!\n! Moreover, the number of non-decreasing maps from a set of\n! N to a set of M ordered elements is [M]^N / N!. Thus the set of\n! nondecreasing maps from (1,2,3) to (a,b,c,d) is the 20 elements:\n!\n! aaa, abb, acc, add, aab, abc, acd, aac, abd, aad\n! bbb, bcc, bdd, bbc, bcd, bbd, ccc, cdd, ccd, ddd.\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real X, the argument of the rising factorial function.\n!\n! Input, integer N, the order of the rising factorial function.\n! If N = 0, RISE = 1, if N = 1, RISE = X. Note that if N is\n! negative, a \"falling\" factorial will be computed.\n!\n! Output, real RISE, the value of the rising factorial function.\n!\n implicit none\n!\n real arg\n integer i\n integer n\n real rise\n real x\n!\n rise = 1.0E+00\n\n arg = x\n\n if ( n > 0 ) then\n\n do i = 1, n\n rise = rise * arg\n arg = arg + 1.0E+00\n end do\n\n else if ( n < 0 ) then\n\n do i = -1, n\n rise = rise * arg\n arg = arg - 1.0E+00\n end do\n\n end if\n\n return\nend\nsubroutine rmat_det ( n, a, det )\n!\n!*******************************************************************************\n!\n!! RMAT_DET finds the determinant of a real N by N matrix.\n!\n!\n! Discussion:\n!\n! A brute force calculation is made.\n!\n! This routine should only be used for small matrices, since this\n! calculation requires the summation of N! products of N numbers.\n!\n! Modified:\n!\n! 10 June 2002\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of rows and columns of A.\n!\n! Input, real A(N,N), the matrix whose determinant is desired.\n!\n! Output, real DET, the determinant of the matrix.\n!\n implicit none\n!\n integer n\n!\n real a(n,n)\n real det\n logical even\n integer i\n integer iarray(n)\n logical more\n real term\n!\n more = .false.\n det = 0.0E+00\n\n do\n\n call perm_next ( n, iarray, more, even )\n\n if ( even ) then\n term = 1.0E+00\n else\n term = -1.0E+00\n end if\n\n do i = 1, n\n term = term * a(i,iarray(i))\n end do\n\n det = det + term\n\n if ( .not. more ) then\n exit\n end if\n\n end do\n\n return\nend\nsubroutine rmat_perm ( n, a, p )\n!\n!*******************************************************************************\n!\n!! RMAT_PERM permutes the rows and columns of a square real matrix.\n!\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 10 June 2002\n!\n! Parameters:\n!\n! Input, integer N, the order of the matrix.\n!\n! Input/output, real A(N,N).\n! On input, the matrix to be permuted.\n! On output, the permuted matrix.\n!\n! Input, integer P(N), a permutation to be applied to the rows\n! and columns. P(I) is the new number of row and column I.\n!\n implicit none\n!\n integer n\n!\n real a(n,n)\n integer i\n integer i1\n integer is\n real it\n integer j\n integer j1\n integer j2\n integer k\n integer lc\n integer nc\n integer p(n)\n!\n call perm_cycle ( n, p, is, nc, 1 )\n\n do i = 1, n\n\n i1 = - p(i)\n\n if ( i1 > 0 ) then\n\n lc = 0\n\n do\n\n i1 = p(i1)\n lc = lc + 1\n\n if ( i1 <= 0 ) then\n exit\n end if\n\n end do\n\n i1 = i\n\n do j = 1, n\n\n if ( p(j) <= 0 ) then\n\n j2 = j\n k = lc\n\n do\n\n j1 = j2\n it = a(i1,j1)\n\n do\n\n i1 = abs ( p(i1) )\n j1 = abs ( p(j1) )\n\n call r_swap ( a(i1,j1), it )\n\n if ( j1 /= j2 ) then\n cycle\n end if\n\n k = k - 1\n\n if ( i1 == i ) then\n exit\n end if\n\n end do\n\n j2 = abs ( p(j2) )\n\n if ( k == 0 ) then\n exit\n end if\n\n end do\n\n end if\n\n end do\n\n end if\n\n end do\n!\n! Restore the positive signs of the data.\n!\n p(1:n) = abs ( p(1:n) )\n\n return\nend\nsubroutine rmat_perm2 ( m, n, a, p, q )\n!\n!*******************************************************************************\n!\n!! RMAT_PERM2 permutes rows and columns of a real rectangular matrix, in place.\n!\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 28 October 1999\n!\n! Parameters:\n!\n! Input, integer M, number of rows in the matrix.\n!\n! Input, integer N, number of columns in the matrix.\n!\n! Input/output, real A(M,N).\n! On input, the matrix to be permuted.\n! On output, the permuted matrix.\n!\n! Input, integer P(M), the row permutation. P(I) is the new number of row I.\n!\n! Input, integer Q(N), the column permutation. Q(I) is the new number of\n! column I. Note that the routine allows you to pass a single array as both\n! P and Q.\n!\n implicit none\n!\n integer m\n integer n\n!\n real a(m,n)\n integer i\n integer i1\n integer is\n integer j\n integer j1\n integer j2\n integer k\n integer lc\n integer nc\n integer p(m)\n integer q(n)\n real t\n!\n call perm_cycle ( m, p, is, nc, 1 )\n\n if ( q(1) > 0 ) then\n call perm_cycle ( n, q, is, nc, 1 )\n end if\n\n do i = 1, m\n\n i1 = - p(i)\n\n if ( i1 > 0 ) then\n\n lc = 0\n\n do\n\n i1 = p(i1)\n lc = lc + 1\n\n if ( i1 <= 0 ) then\n exit\n end if\n\n end do\n\n i1 = i\n\n do j = 1, n\n\n if ( q(j) <= 0 ) then\n\n j2 = j\n k = lc\n\n do\n\n j1 = j2\n t = a(i1,j1)\n\n do\n\n i1 = abs ( p(i1) )\n j1 = abs ( q(j1) )\n\n call r_swap ( a(i1,j1), t )\n\n if ( j1 /= j2 ) then\n cycle\n end if\n\n k = k - 1\n\n if ( i1 == i ) then\n exit\n end if\n\n end do\n\n j2 = abs ( q(j2) )\n\n if ( k == 0 ) then\n exit\n end if\n\n end do\n\n end if\n\n end do\n\n end if\n\n end do\n\n p(1:m) = abs ( p(1:m) )\n\n if ( q(1) <= 0 ) then\n\n q(1:n) = abs ( q(1:n) )\n\n end if\n\n return\nend\nsubroutine rmat_permanent ( n, a, perm )\n!\n!*******************************************************************************\n!\n!! RMAT_PERMANENT computes the permanent of a real matrix.\n!\n!\n! Discussion:\n!\n! The permanent function is similar to the determinant. Recall that\n! the determinant of a matrix may be defined as the sum of all the\n! products:\n!\n! S * A(1,I(1)) * A(2,I(2)) * ... * A(N,I(N))\n!\n! where I is any permutation of the columns of the matrix, and S is the\n! sign of the permutation. By contrast, the permanent function is\n! the (unsigned) sum of all the products\n!\n! A(1,I(1)) * A(2,I(2)) * ... * A(N,I(N))\n!\n! where I is any permutation of the columns of the matrix. The only\n! difference is that there is no permutation sign multiplying each summand.\n!\n! Symbolically, then, the determinant of a 2 by 2 matrix\n!\n! a b\n! c d\n!\n! is a*d-b*c, whereas the permanent of the same matrix is a*d+b*c.\n!\n!\n! The permanent is invariant under row and column permutations.\n! If a row or column of the matrix is multiplied by S, then the\n! permanent is likewise multiplied by S.\n! If the matrix is square, then the permanent is unaffected by\n! transposing the matrix.\n! Unlike the determinant, however, the permanent does change if\n! one row is added to another, and it is not true that the\n! permanent of the product is the product of the permanents.\n!\n!\n! Note that if A is a matrix of all 1's and 0's, then the permanent\n! of A counts exactly which permutations hit exactly 1's in the matrix.\n! This fact can be exploited for various combinatorial purposes.\n!\n! For instance, setting the diagonal of A to 0, and the offdiagonals\n! to 1, the permanent of A counts the number of derangements of N\n! objects.\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Input, integer N, number of rows and columns in matrix.\n!\n! Input, real A(N,N). The matrix whose permanent is desired.\n!\n! Output, real PERM, the value of the permanent function of A.\n!\n implicit none\n!\n integer n\n!\n real a(n,n)\n integer i\n integer iadd\n integer iwork(n)\n integer j\n logical more\n integer ncard\n real p\n real perm\n real prod\n real sgn\n real work(n)\n real z\n!\n more = .false.\n\n do i = 1, n\n work(i) = a(i,n)\n do j = 1, n\n work(i) = work(i) - 0.5E+00 * a(i,j)\n end do\n end do\n\n p = 0.0E+00\n sgn = - 1.0E+00\n\n do\n\n sgn = - sgn\n call sub_next ( n-1, iwork, more, ncard, iadd )\n\n if ( ncard /= 0 ) then\n z = real ( 2 * iwork(iadd) - 1 )\n work(1:n) = work(1:n) + z * a(1:n,iadd)\n end if\n\n p = p + sgn * product ( work )\n\n if ( .not. more ) then\n exit\n end if\n\n end do\n\n perm = p * real ( 4 * mod ( n, 2 ) - 2 )\n\n return\nend\nsubroutine rmat_print ( m, n, a, title )\n!\n!*******************************************************************************\n!\n!! RMAT_PRINT prints a real matrix.\n!\n!\n! Modified:\n!\n! 24 March 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer M, the number of rows in A.\n!\n! Input, integer N, the number of columns in A.\n!\n! Input, real A(M,N), the matrix to be printed.\n!\n! Input, character ( len = * ) TITLE, a title to be printed first.\n! TITLE may be blank.\n!\n implicit none\n!\n integer m\n integer n\n!\n real a(m,n)\n integer i\n integer j\n integer jhi\n integer jlo\n character ( len = * ) title\n!\n if ( title /= ' ' ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) title\n end if\n\n do jlo = 1, n, 5\n jhi = min ( jlo + 4, n )\n write ( *, '(a)' ) ' '\n write ( *, '(6x,5(i7,7x))' ) ( j, j = jlo, jhi )\n write ( *, '(a)' ) ' '\n do i = 1, m\n write ( *, '(i6,5g14.6)' ) i, a(i,jlo:jhi)\n end do\n end do\n\n return\nend\nsubroutine rpoly ( n, a, x0, iopt, val )\n!\n!*******************************************************************************\n!\n!! RPOLY performs operations on real polynomials in power or factorial form.\n!\n!\n! Discussion:\n!\n! The power sum form of a polynomial is\n!\n! P(X) = A1 + A2*X + A3*X**2 + ... + (AN+1)*X**N\n!\n! The Taylor expansion at C has the form\n!\n! P(X) = A1 + A2*(X-C) + A3*(X-C)**2+... + (AN+1)*(X-C)**N\n!\n! The factorial form of a polynomial is\n!\n! P(X) = A1 + A2*X + A3*(X)*(X-1) + A4*(X)*(X-1)*(X-2) + ...\n! + (AN+1)*(X)*(X-1)*...*(X-N+1)\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Input, integer N, the number of coefficients in the polynomial\n! (in other words, the polynomial degree + 1)\n!\n! Input/output, real A(N), the coefficients of the polynomial. Depending\n! on the option chosen, these coefficients may be overwritten by those\n! of a different form of the polynomial.\n!\n! Input, real X0, for IOPT = -1, 0, or positive, the value of the\n! argument at which the polynomial is to be evaluated, or the\n! Taylor expansion is to be carried out.\n!\n! Input, integer IOPT, a flag describing which algorithm is to\n! be carried out:\n!\n! -3: Reverse Stirling. Input the coefficients of the polynomial in\n! factorial form, output them in power sum form.\n!\n! -2: Stirling. Input the coefficients in power sum\n! form, output them in factorial form.\n!\n! -1: Evaluate a polynomial which has been input\n! in factorial form.\n!\n! 0: Evaluate a polynomial input in power sum form.\n!\n! 1 or more: Given the coefficients of a polynomial in\n! power sum form, compute the first IOPT coefficients of\n! the polynomial in Taylor expansion form.\n!\n! Output, real VAL, for IOPT = -1 or 0, the value of the\n! polynomial at the point X0.\n!\n implicit none\n!\n integer n\n!\n real a(n)\n real eps\n integer i\n integer iopt\n integer m\n integer n1\n real val\n real w\n real x0\n real z\n!\n n1 = min ( n, iopt )\n n1 = max ( 1, n1 )\n\n if ( iopt < -1 ) then\n n1 = n\n end if\n\n eps = real ( mod ( max ( -iopt, 0 ), 2 ) )\n\n w = - real ( n ) * eps\n\n if ( iopt > -2 ) then\n w = w + x0\n end if\n\n do m = 1, n1\n\n val = 0.0E+00\n z = w\n\n do i = m, n\n z = z + eps\n val = a(n+m-i) + z * val\n if ( iopt /= 0 .and. iopt /= -1 ) then\n a(n+m-i) = val\n end if\n end do\n\n if ( iopt < 0 ) then\n w = w + 1.0E+00\n end if\n\n end do\n\n return\nend\nsubroutine rpoly_degree ( na, a, degree )\n!\n!*******************************************************************************\n!\n!! RPOLY_DEGREE returns the degree of a polynomial.\n!\n!\n! Discussion:\n!\n! The degree of a polynomial is the index of the highest power\n! of X with a nonzero coefficient.\n!\n! The degree of a constant polynomial is 0. The degree of the\n! zero polynomial is debatable, but this routine returns the\n! degree as 0.\n!\n! Modified:\n!\n! 20 March 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer NA, the dimension of A.\n!\n! Input, real A(0:NA), the coefficients of the polynomials.\n!\n! Output, integer DEGREE, the degree of A.\n!\n implicit none\n!\n integer na\n!\n real a(0:na)\n integer degree\n!\n degree = na\n\n do while ( degree > 0 )\n\n if ( a(degree) /= 0.0E+00 ) then\n return\n end if\n\n degree = degree - 1\n\n end do\n\n return\nend\nsubroutine rpoly_div ( na, a, nb, b, nq, q, nr, r )\n!\n!*******************************************************************************\n!\n!! RPOLY_DIV computes the quotient and remainder of two polynomials.\n!\n!\n! Discussion:\n!\n! The polynomials are assumed to be stored in power sum form.\n!\n! The power sum form is:\n!\n! p(x) = a(0) + a(1)*x + ... + a(n-1)*x**(n-1) + a(n)*x**(n)\n!\n! Modified:\n!\n! 23 March 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer NA, the dimension of A.\n!\n! Input, real A(0:NA), the coefficients of the polynomial to be divided.\n!\n! Input, integer NB, the dimension of B.\n!\n! Input, real B(0:NB), the coefficients of the divisor polynomial.\n!\n! Output, integer NQ, the degree of Q.\n! If the divisor polynomial is zero, NQ is returned as -1.\n!\n! Output, real Q(0:NA-NB), contains the quotient of A/B.\n! If A and B have full degree, Q should be dimensioned Q(0:NA-NB).\n! In any case, Q(0:NA) should be enough.\n!\n! Output, integer NR, the degree of R.\n! If the divisor polynomial is zero, NR is returned as -1.\n!\n! Output, real R(0:NB-1), contains the remainder of A/B.\n! If B has full degree, R should be dimensioned R(0:NB-1).\n! Otherwise, R will actually require less space.\n!\n implicit none\n!\n integer na\n integer nb\n!\n real a(0:na)\n real a2(0:na)\n real b(0:nb)\n integer i\n integer na2\n integer nb2\n integer nq\n integer nr\n real q(0:*)\n real r(0:*)\n!\n call rpoly_degree ( na, a, na2 )\n call rpoly_degree ( nb, b, nb2 )\n\n if ( b(nb2) == 0.0E+00 ) then\n nq = -1\n nr = -1\n return\n end if\n\n a2(0:na) = a(0:na)\n\n nq = na2 - nb2\n nr = nb2 - 1\n\n do i = nq, 0, -1\n q(i) = a2(i+nb2) / b(nb2)\n a2(i+nb2) = 0.0E+00\n a2(i:i+nb2-1) = a2(i:i+nb2-1) - q(i) * b(0:nb2-1)\n end do\n\n r(0:nr) = a2(0:nr)\n\n return\nend\nsubroutine rpoly_f2p ( n, a )\n!\n!*******************************************************************************\n!\n!! RPOLY_F2P converts a real polynomial from factorial form to power sum form.\n!\n!\n! Discussion:\n!\n! The factorial form is\n!\n! p(x) = a(1)\n! + a(2) * x\n! + a(3) * x*(x-1)\n! ...\n! + a(n) * x*(x-1)*...*(x-(n-2))\n!\n! The power sum form is\n!\n! p(x) = a(1) + a(2)*x + a(3)*x**2 + ... + a(n)*x**(n-1)\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Input, real N, the dimension of A.\n!\n! Input/output, real A(N), on input, the polynomial\n! coefficients in factorial form. On output, the polynomial\n! coefficients in power sum form.\n!\n implicit none\n!\n integer n\n!\n real a(n)\n integer i\n integer m\n real val\n real w\n real z\n!\n w = - n\n\n do m = 1, n\n\n val = 0.0E+00\n z = w\n\n do i = m, n\n z = z + 1.0E+00\n val = a(n+m-i) + z * val\n a(n+m-i) = val\n end do\n\n w = w + 1.0E+00\n\n end do\n\n return\nend\nsubroutine rpoly_fval ( n, a, x, val )\n!\n!*******************************************************************************\n!\n!! RPOLY_FVAL evaluates a real polynomial in factorial form.\n!\n!\n! Discussion:\n!\n! The factorial form of a polynomial is:\n!\n! p(x) = a(1)\n! + a(2) *x\n! + a(3) *x*(x-1)\n! +...\n! + a(n-1)*x*(x-1)*(x-2)...*(x-(n-3))\n! + a(n) *x*(x-1)*(x-2)...*(x-(n-3))*(x-(n-2))\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Input, integer N, the dimension of A.\n!\n! Input, real A(N), the coefficients of the polynomial.\n! A(1) is the constant term.\n!\n! Input, real X, the point at which the polynomial is to be evaluated.\n!\n! Output, real VAL, the value of the polynomial at X.\n!\n implicit none\n!\n integer n\n!\n real a(n)\n integer i\n real val\n real x\n!\n val = 0.0E+00\n do i = 1, n\n val = a(n+1-i) + ( x - n + i ) * val\n end do\n\n return\nend\nsubroutine rpoly_mul ( na, a, nb, b, c )\n!\n!*******************************************************************************\n!\n!! RPOLY_MUL computes the product of two real polynomials A and B.\n!\n!\n! Discussion:\n!\n! The polynomials are in power sum form.\n!\n! The power sum form is:\n!\n! p(x) = a(0) + a(1)*x + ... + a(n-1)*x**(n-1) + a(n)*x**(n)\n!\n! Modified:\n!\n! 20 March 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer NA, the dimension of A.\n!\n! Input, real A(0:NA), the coefficients of the first polynomial factor.\n!\n! Input, integer NB, the dimension of B.\n!\n! Input, real B(0:NB), the coefficients of the second polynomial factor.\n!\n! Output, real C(0:NA+NB), the coefficients of A * B.\n!\n implicit none\n!\n integer na\n integer nb\n!\n real a(0:na)\n real b(0:nb)\n real c(0:na+nb)\n real d(0:na+nb)\n integer i\n integer j\n!\n d(0:na+nb) = 0.0E+00\n\n do i = 0, na\n d(i:i+nb) = d(i:i+nb) + a(i) * b(0:nb)\n end do\n\n c(0:na+nb) = d(0:na+nb)\n\n return\nend\nsubroutine rpoly_n2p ( n, a, xarray )\n!\n!*******************************************************************************\n!\n!! RPOLY_N2P converts a real polynomial from Newton form to power sum form.\n!\n!\n! Discussion:\n!\n! This is done by shifting all the Newton abscissas to zero.\n!\n! Actually, what happens is that the abscissas of the Newton form\n! are all shifted to zero, which means that A is the power sum\n! polynomial description and A, XARRAY is the Newton polynomial\n! description. It is only because all the abscissas are shifted to\n! zero that A can be used as both a power sum and Newton polynomial\n! coefficient array.\n!\n! The Newton form of a polynomial is described by an array of N coefficients\n! A and N abscissas X:\n!\n! p(x) = a(1)\n! + a(2) * (x-x(1))\n! + a(3) * (x-x(1)) * (x-x(2))\n! ...\n! + a(n) * (x-x(1)) * (x-x(2)) * ... * (x-x(n-1))\n!\n! X(N) does not occur explicitly in the formula for the evaluation of p(x),\n! although it is used in deriving the coefficients A.\n!\n! The power sum form of a polynomial is:\n!\n! p(x) = a(1) + a(2)*x + ... + a(n-1)*x**(n-2) + a(n)*x**(n-1)\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Input, integer N, the dimension of A.\n!\n! Input/output, real A(N). On input, the coefficients\n! of the polynomial in Newton form, and on output, the coefficients\n! in power sum form.\n!\n! Input/output, real XARRAY(N). On input, the abscissas of\n! the Newton form of the polynomial. On output, these values\n! have all been set to zero.\n!\n implicit none\n!\n integer n\n!\n real a(n)\n integer i\n real xarray(n)\n real, parameter :: zero = 0.0E+00\n!\n do i = 1, n\n call rpoly_nx ( n, a, xarray, zero )\n end do\n\n return\nend\nsubroutine rpoly_nval ( n, a, xarray, x, val )\n!\n!*******************************************************************************\n!\n!! RPOLY_NVAL evaluates a real polynomial in Newton form.\n!\n!\n! Definition:\n!\n! The Newton form of a polynomial is;\n!\n! p(x) = a(1)\n! + a(2) *(x-x1)\n! + a(3) *(x-x1)*(x-x2)\n! +...\n! + a(n-1)*(x-x1)*(x-x2)*(x-x3)...*(x-x(n-2))\n! + a(n) *(x-x1)*(x-x2)*(x-x3)...*(x-x(n-2))*(x-x(n-1))\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Input, integer N, the dimension of A.\n!\n! Input, real A(N), the coefficients of the polynomial.\n! A(1) is the constant term.\n!\n! Input, real XARRAY(N-1), the N-1 points X which are part\n! of the definition of the polynomial.\n!\n! Input, real X, the point at which the polynomial is to be evaluated.\n!\n! Output, real VAL, the value of the polynomial at X.\n!\n implicit none\n!\n integer n\n!\n real a(n)\n integer i\n real val\n real x\n real xarray(n-1)\n!\n val = a(n)\n do i = n-1, 1, -1\n val = a(i) + ( x - xarray(i) ) * val\n end do\n\n return\nend\nsubroutine rpoly_nx ( n, a, xarray, x )\n!\n!*******************************************************************************\n!\n!! RPOLY_NX replaces one of the base points in a polynomial in Newton form.\n!\n!\n! Discussion:\n!\n! The Newton form of a polynomial is described by an array of N coefficients\n! A and N abscissas X:\n!\n! p(x) = a(1)\n! + a(2) * (x-x(1))\n! + a(3) * (x-x(1)) * (x-x(2))\n! ...\n! + a(n) * (x-x(1)) * (x-x(2)) * ... * (x-x(n-1))\n!\n! X(N) does not occur explicitly in the formula for the evaluation of p(x),\n! although it is used in deriving the coefficients A.\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Input, integer N, the dimension of A.\n!\n! Input/output, real A(N), the polynomial coefficients of the Newton form.\n!\n! Input/output, real XARRAY(N), the set of abscissas that\n! are part of the Newton form of the polynomial. On output,\n! the abscissas have been shifted up one index, so that\n! the first location now holds X, and the original contents\n! of XARRAY(N) have been discarded.\n!\n! Input, real X, the new point to be shifted into XARRAY.\n!\n implicit none\n!\n integer n\n!\n real a(n)\n integer i\n real x\n real xarray(n)\n!\n do i = n-1, 1, -1\n a(i) = a(i) + ( x - xarray(i) ) * a(i+1)\n end do\n\n do i = n, 2, -1\n xarray(i) = xarray(i-1)\n end do\n\n xarray(1) = x\n\n return\nend\nsubroutine rpoly_p2f ( n, a )\n!\n!*******************************************************************************\n!\n!! RPOLY_P2F converts a real polynomial from power sum form to factorial form.\n!\n!\n! Discussion:\n!\n! The power sum form is\n!\n! p(x) = a(1) + a(2)*x + a(3)*x**2 + ... + a(n)*x**(n-1)\n!\n! The factorial form is\n!\n! p(x) = a(1)\n! + a(2) * x\n! + a(3) * x*(x-1)\n! ...\n! + a(n) * x*(x-1)*...*(x-(n-2))\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Input, real N, the dimension of A.\n!\n! Input/output, real A(N), on input, the polynomial\n! coefficients in the power sum form, on output, the polynomial\n! coefficients in factorial form.\n!\n implicit none\n!\n integer n\n!\n real a(n)\n integer i\n integer m\n real val\n!\n do m = 1, n\n val = 0.0E+00\n do i = m, n\n val = a(n+m-i) + real ( m - 1 ) * val\n a(n+m-i) = val\n end do\n end do\n\n return\nend\nsubroutine rpoly_p2n ( n, a, xarray )\n!\n!*******************************************************************************\n!\n!! RPOLY_P2N converts a real polynomial from power sum form to Newton form.\n!\n!\n! Discussion:\n!\n! This is done by shifting all the Newton abscissas from zero.\n!\n! The power sum form of a polynomial is:\n!\n! p(x) = a(1) + a(2)*x + ... + a(n-1)*x**(n-2) + a(n)*x**(n-1)\n!\n! The Newton form of a polynomial is described by an array of N coefficients\n! A and N abscissas X:\n!\n! p(x) = a(1)\n! + a(2) * (x-x(1))\n! + a(3) * (x-x(1)) * (x-x(2))\n! ...\n! + a(n) * (x-x(1)) * (x-x(2)) * ... * (x-x(n-1))\n!\n! X(N) does not occur explicitly in the formula for the evaluation of p(x),\n! although it is used in deriving the coefficients A.\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Input, integer N, the dimension of A.\n!\n! Input/output, real A(N). On input, the coefficients\n! of the polynomial in power sum form, and on output, the\n! coefficients in Newton form.\n!\n! Input/output, real XARRAY(N). On input, the desired abscissas of\n! the Newton form of the polynomial.\n!\n implicit none\n!\n integer n\n!\n real a(n)\n integer i\n real xarray(n)\n real work(n)\n!\n work(1:n) = 0.0E+00\n\n do i = n, 1, -1\n call rpoly_nx ( n, a, work, xarray(i) )\n end do\n\n return\nend\nsubroutine rpoly_p2t ( n, a, x )\n!\n!*******************************************************************************\n!\n!! RPOLY_P2T converts a real polynomial from power sum form to Taylor form.\n!\n!\n! Discussion:\n!\n! The power sum form is\n!\n! p(x) = a(1) + a(2)*x + a(3)*x**2 + ... + a(n)*x**(n-1)\n!\n! The Taylor form is\n!\n! p(x) = a(1)\n! + a(2) * (x-x0)\n! + a(3) * (x-x0)**2\n! ...\n! + a(n) * (x-x0)**(n-1)\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Input, real N, the dimension of A.\n!\n! Input/output, real A(N), on input, the coefficients in\n! power sum form, and on output, the coefficients in Taylor form.\n!\n! Input, real X, the point at which the Taylor form of the\n! polynomial is to be based.\n!\n implicit none\n!\n integer n\n!\n real a(n)\n integer i\n integer m\n real val\n real x\n!\n do m = 1, n\n val = 0.0E+00\n do i = m, n\n val = a(n+m-i) + x * val\n a(n+m-i) = val\n end do\n end do\n\n return\nend\nsubroutine rpoly_power ( na, a, p, b )\n!\n!*******************************************************************************\n!\n!! RPOLY_POWER computes a positive integer power of a polynomial.\n!\n!\n! Discussion:\n!\n! The power sum form is:\n!\n! p(x) = a(0) + a(1)*x + ... + a(n-1)*x**(n-1) + a(n)*x**(n)\n!\n! Modified:\n!\n! 20 March 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer NA, the dimension of A.\n!\n! Input, real A(0:NA), the polynomial to be raised to the power.\n!\n! Input, integer P, the nonnegative power to which A is raised.\n!\n! Output, real B(0:P*NA), the power of the polynomial.\n!\n implicit none\n!\n integer na\n integer p\n!\n real a(0:na)\n real b(0:p*na)\n integer i\n integer j\n integer nonzer\n!\n! Zero out B.\n!\n b(0:p*na) = 0.0E+00\n!\n! Search for the first nonzero element in A.\n!\n nonzer = 0\n\n do i = 0, na\n if ( a(i) /= 0.0E+00 ) then\n nonzer = i\n exit\n end if\n end do\n\n if ( nonzer == 0 ) then\n return\n end if\n\n b(0) = a(nonzer)**p\n\n do i = 1, p*(na-nonzer)\n\n if ( i + nonzer <= na ) then\n b(i) = real ( i * p ) * b(0) * a(i+nonzer)\n else\n b(i) = 0.0E+00\n end if\n\n do j = 1, i-1\n\n if ( j+nonzer <= na ) then\n b(i) = b(i) - real ( i - j ) * a(j+nonzer) * b(i-j)\n end if\n\n if ( i-j+nonzer <= na ) then\n b(i) = b(i) + real ( i - j ) * real ( p ) * b(j) * a(i-j+nonzer)\n end if\n\n end do\n\n b(i) = b(i) / ( real ( i ) * a(nonzer) )\n\n end do\n!\n! Shift B up.\n!\n do i = p*nonzer, p*na\n b(i) = b(i-p*nonzer)\n end do\n\n do i = 0, p * nonzer-1\n b(i) = 0.0E+00\n end do\n\n return\nend\nsubroutine rpoly_print ( n, a, title )\n!\n!*******************************************************************************\n!\n!! RPOLY_PRINT prints out a polynomial.\n!\n!\n! Discussion:\n!\n! The power sum form is:\n!\n! p(x) = a(0) + a(1)*x + ... + a(n-1)*x**(n-1) + a(n)*x**(n)\n!\n! Modified:\n!\n! 06 August 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the dimension of A.\n!\n! Input, real A(0:N), the polynomial coefficients.\n! A(0) is the constant term and\n! A(N) is the coefficient of X**N.\n!\n! Input, character ( len = * ) TITLE, an optional title.\n!\n implicit none\n!\n integer n\n!\n real a(0:n)\n integer i\n real mag\n integer n2\n character plus_minus\n character ( len = * ) title\n!\n if ( len_trim ( title ) > 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) trim ( title )\n end if\n\n write ( *, '(a)' ) ' '\n\n call rpoly_degree ( n, a, n2 )\n\n if ( a(n2) < 0.0E+00 ) then\n plus_minus = '-'\n else\n plus_minus = ' '\n end if\n\n mag = abs ( a(n2) )\n\n if ( n2 >= 2 ) then\n write ( *, '( '' p(x) = '', a1, g14.6, '' * x ^ '', i3 )' ) &\n plus_minus, mag, n2\n else if ( n2 == 1 ) then\n write ( *, '( '' p(x) = '', a1, g14.6, '' * x'' )' ) plus_minus, mag\n else if ( n2 == 0 ) then\n write ( *, '( '' p(x) = '', a1, g14.6 )' ) plus_minus, mag\n end if\n\n do i = n2-1, 0, -1\n\n if ( a(i) < 0.0E+00 ) then\n plus_minus = '-'\n else\n plus_minus = '+'\n end if\n\n mag = abs ( a(i) )\n\n if ( mag /= 0.0E+00 ) then\n\n if ( i >= 2 ) then\n write ( *, ' ( '' '', a1, g14.6, '' * x ^ '', i3 )' ) &\n plus_minus, mag, i\n else if ( i == 1 ) then\n write ( *, ' ( '' '', a1, g14.6, '' * x'' )' ) plus_minus, mag\n else if ( i == 0 ) then\n write ( *, ' ( '' '', a1, g14.6 )' ) plus_minus, mag\n end if\n end if\n\n end do\n\n return\nend\nsubroutine rpoly_pval ( n, a, x, val )\n!\n!*******************************************************************************\n!\n!! RPOLY_PVAL evaluates a real polynomial in power sum form.\n!\n!\n! Discussion:\n!\n! The power sum form is:\n!\n! p(x) = a(0) + a(1)*x + ... + a(n-1)*x**(n-1) + a(n)*x**(n)\n!\n! Modified:\n!\n! 08 December 1999\n!\n! Parameters:\n!\n! Input, integer N, the dimension of A.\n!\n! Input, real A(0:N), the coefficients of the polynomial.\n! A(0) is the constant term.\n!\n! Input, real X, the point at which the polynomial is to be evaluated.\n!\n! Output, real VAL, the value of the polynomial at X.\n!\n implicit none\n!\n integer n\n!\n real a(0:n)\n integer i\n real val\n real x\n!\n val = 0.0E+00\n do i = n, 0, -1\n val = val * x + a(i)\n end do\n\n return\nend\nsubroutine rpoly_t2p ( n, a, x )\n!\n!*******************************************************************************\n!\n!! RPOLY_T2P converts a real polynomial from Taylor form to power sum form.\n!\n!\n! Discussion:\n!\n! The Taylor form is\n!\n! p(x) = a(1)\n! + a(2) * (x-x0)\n! + a(3) * (x-x0)**2\n! ...\n! + a(n) * (x-x0)**(n-1)\n!\n! The power sum form is\n!\n! p(x) = a(1) + a(2)*x + a(3)*x**2 + ... + a(n)*x**(n-1)\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Input, real N, the dimension of A.\n!\n! Input/output, real A(N). On input, the coefficients in Taylor form,\n! and on output, the coefficients in power sum form.\n!\n! Input, real X, the point at which the Taylor form polynomial is based.\n!\n implicit none\n!\n integer n\n!\n real a(n)\n integer i\n integer j\n real x\n!\n do i = n, 1, -1\n do j = i, n-1\n a(j) = a(j) - a(j+1) * x\n end do\n end do\n\n return\nend\nsubroutine rvec_backtrack ( n, x, indx, k, nstack, stack, maxstack, ncan )\n!\n!*******************************************************************************\n!\n!! RVEC_BACKTRACK supervises a backtrack search for a real vector.\n!\n!\n! Discussion:\n!\n! The routine tries to construct a real vector one index at a time,\n! using possible candidates as supplied by the user.\n!\n! At any time, the partially constructed vector may be discovered to be\n! unsatisfactory, but the routine records information about where the\n! last arbitrary choice was made, so that the search can be\n! carried out efficiently, rather than starting out all over again.\n!\n! First, call the routine with INDX = 0 so it can initialize itself.\n!\n! Now, on each return from the routine, if INDX is:\n! 1, you've just been handed a complete candidate vector;\n! Admire it, analyze it, do what you like.\n! 2, please determine suitable candidates for position X(K).\n! Return the number of candidates in NCAN(K), adding each\n! candidate to the end of STACK, and increasing NSTACK.\n! 3, you're done. Stop calling the routine;\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 24 July 2000\n!\n! Parameters:\n!\n! Input, integer N, the number of positions to be filled in the vector.\n!\n! Input/output, real X(N), the partial or complete candidate vector.\n!\n! Input/output, integer INDX, a communication flag.\n! On input,\n! 0 to start a search.\n! On output:\n! 1, a complete output vector has been determined and returned in X(1:N);\n! 2, candidates are needed for position X(K);\n! 3, no more possible vectors exist.\n!\n! Output, integer K, if INDX=2, the current vector index being considered.\n!\n! Input/output, integer NSTACK, the current length of the stack.\n!\n! Input, real STACK(MAXSTACK), a list of all current candidates for\n! all positions 1 through K.\n!\n! Input, integer MAXSTACK, the maximum length of the stack.\n!\n! Input/output, integer NCAN(N), lists the current number of candidates for\n! positions 1 through K.\n!\n implicit none\n!\n integer n\n integer maxstack\n!\n integer indx\n integer k\n integer ncan(n)\n integer nstack\n real stack(maxstack)\n real x(n)\n!\n! If this is the first call, request a candidate for position 1.\n!\n if ( indx == 0 ) then\n k = 1\n nstack = 0\n indx = 2\n return\n end if\n!\n! Examine the stack.\n!\n do\n!\n! If there are candidates for position K, take the first available\n! one off the stack, and increment K.\n!\n! This may cause K to reach the desired value of N, in which case\n! we need to signal the user that a complete set of candidates\n! is being returned.\n!\n if ( ncan(k) > 0 ) then\n\n x(k) = stack(nstack)\n nstack = nstack - 1\n\n ncan(k) = ncan(k) - 1\n\n if ( k /= n ) then\n k = k + 1\n indx = 2\n else\n indx = 1\n end if\n\n exit\n!\n! If there are no candidates for position K, then decrement K.\n! If K is still positive, repeat the examination of the stack.\n!\n else\n\n k = k - 1\n\n if ( k <= 0 ) then\n indx = 3\n exit\n end if\n\n end if\n\n end do\n\n return\nend\nsubroutine rvec_frac ( n, a, k, afrac )\n!\n!*******************************************************************************\n!\n!! RVEC_FRAC searches for the K-th smallest entry in an N-vector.\n!\n!\n! Discussion:\n!\n! Hoare's algorithm is used.\n!\n! Modified:\n!\n! 17 July 2000\n!\n! Parameters:\n!\n! Input, integer N, the number of elements of A.\n!\n! Input/output, real A(N).\n!\n! On input, A is the array to search.\n!\n! On output, the elements of A have been somewhat rearranged.\n!\n! Input, integer K, the fractile to be sought. If K = 1, the minimum\n! entry is sought. If K = N, the maximum is sought. Other values\n! of K search for the entry which is K-th in size. K must be at\n! least 1, and no greater than N.\n!\n! Output, real AFRAC, the value of the K-th fractile of A.\n!\n implicit none\n!\n integer n\n!\n real a(n)\n real afrac\n integer i\n integer iryt\n integer j\n integer k\n integer left\n real w\n real x\n!\n if ( n <= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'RVEC_FRAC - Fatal error!'\n write ( *, '(a,i6)' ) ' Illegal nonpositive value of N = ', n\n stop\n end if\n\n if ( k <= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'RVEC_FRAC - Fatal error!'\n write ( *, '(a,i6)' ) ' Illegal nonpositive value of K = ', k\n stop\n end if\n\n if ( k > n ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'RVEC_FRAC - Fatal error!'\n write ( *, '(a,i6)' ) ' Illegal K > N, K = ', k\n stop\n end if\n\n left = 1\n iryt = n\n\n do\n\n if ( left >= iryt ) then\n afrac = a(k)\n exit\n end if\n\n x = a(k)\n i = left\n j = iryt\n\n do\n\n if ( i > j ) then\n if ( j < k ) then\n left = i\n end if\n if ( k < i ) then\n iryt = j\n end if\n exit\n end if\n!\n! Find I so that X< = A(I)\n!\n do while ( a(i) < x )\n i = i + 1\n end do\n!\n! Find J so that A(J) < = X\n!\n do while ( x < a(j) )\n j = j - 1\n end do\n\n if ( i <= j ) then\n call r_swap ( a(i), a(j) )\n i = i + 1\n j = j - 1\n end if\n\n end do\n\n end do\n\n return\nend\nsubroutine rvec_identity ( n, a )\n!\n!*******************************************************************************\n!\n!! RVEC_IDENTITY sets a real vector to the identity vector A(I)=I.\n!\n!\n! Modified:\n!\n! 09 February 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of elements of A.\n!\n! Output, real A(N), the array to be initialized.\n!\n implicit none\n!\n integer n\n!\n real a(n)\n integer i\n!\n do i = 1, n\n a(i) = real ( i )\n end do\n\n return\nend\nsubroutine rvec_print ( n, a, title )\n!\n!*******************************************************************************\n!\n!! RVEC_PRINT prints a real vector.\n!\n!\n! Modified:\n!\n! 16 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of components of the vector.\n!\n! Input, real A(N), the vector to be printed.\n!\n! Input, character ( len = * ) TITLE, a title to be printed first.\n! TITLE may be blank.\n!\n implicit none\n!\n integer n\n!\n real a(n)\n integer i\n character ( len = * ) title\n!\n if ( title /= ' ' ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) trim ( title )\n end if\n\n write ( *, '(a)' ) ' '\n do i = 1, n\n write ( *, '(i6,g14.6)' ) i, a(i)\n end do\n\n return\nend\nsubroutine rvec_random ( n, a, alo, ahi )\n!\n!*******************************************************************************\n!\n!! RVEC_RANDOM returns a random real vector in a given range.\n!\n!\n! Modified:\n!\n! 01 December 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of entries in the vector.\n!\n! Output, real A(N), the vector of randomly chosen values.\n!\n! Input, real ALO, AHI, the range allowed for the entries.\n!\n implicit none\n!\n integer n\n!\n real a(n)\n real ahi\n real alo\n integer i\n!\n do i = 1, n\n\n call r_random ( alo, ahi, a(i) )\n\n end do\n\n return\nend\nsubroutine s_blank_delete ( s )\n!\n!*******************************************************************************\n!\n!! S_BLANK_DELETE removes blanks from a string, left justifying the remainder.\n!\n!\n! Comment:\n!\n! All TAB characters are also removed.\n!\n! Modified:\n!\n! 26 July 1998\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input/output, character ( len = * ) S, the string to be transformed.\n!\n implicit none\n!\n character c\n integer iget\n integer iput\n character ( len = * ) s\n character, parameter :: TAB = char ( 9 )\n!\n iput = 0\n\n do iget = 1, len ( s )\n\n c = s(iget:iget)\n\n if ( c /= ' ' .and. c /= TAB ) then\n iput = iput + 1\n s(iput:iput) = c\n end if\n\n end do\n\n s(iput+1:) = ' '\n\n return\nend\nsubroutine s_blanks_delete ( s )\n!\n!*******************************************************************************\n!\n!! S_BLANKS_DELETE replaces consecutive blanks by one blank.\n!\n!\n! Discussion:\n!\n! The remaining characters are left justified and right padded with blanks.\n! TAB characters are converted to spaces.\n!\n! Modified:\n!\n! 26 July 1998\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input/output, character ( len = * ) S, the string to be transformed.\n!\n implicit none\n!\n integer i\n integer j\n character newchr\n character oldchr\n character ( len = * ) s\n character, parameter :: TAB = char ( 9 )\n!\n j = 0\n newchr = ' '\n\n do i = 1, len ( s )\n\n oldchr = newchr\n newchr = s(i:i)\n\n if ( newchr == TAB ) then\n newchr = ' '\n end if\n\n s(i:i) = ' '\n\n if ( oldchr /= ' ' .or. newchr /= ' ' ) then\n j = j + 1\n s(j:j) = newchr\n end if\n\n end do\n\n return\nend\nfunction s_eqi ( s1, s2 )\n!\n!*******************************************************************************\n!\n!! S_EQI is a case insensitive comparison of two strings for equality.\n!\n!\n! Examples:\n!\n! S_EQI ( 'Anjana', 'ANJANA' ) is .TRUE.\n!\n! Modified:\n!\n! 14 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, character ( len = * ) S1, S2, the strings to compare.\n!\n! Output, logical S_EQI, the result of the comparison.\n!\n implicit none\n!\n character c1\n character c2\n integer i\n integer len1\n integer len2\n integer lenc\n logical s_eqi\n character ( len = * ) s1\n character ( len = * ) s2\n!\n len1 = len ( s1 )\n len2 = len ( s2 )\n lenc = min ( len1, len2 )\n\n s_eqi = .false.\n\n do i = 1, lenc\n\n c1 = s1(i:i)\n c2 = s2(i:i)\n call ch_cap ( c1 )\n call ch_cap ( c2 )\n\n if ( c1 /= c2 ) then\n return\n end if\n\n end do\n\n do i = lenc + 1, len1\n if ( s1(i:i) /= ' ' ) then\n return\n end if\n end do\n\n do i = lenc + 1, len2\n if ( s2(i:i) /= ' ' ) then\n return\n end if\n end do\n\n s_eqi = .true.\n\n return\nend\nsubroutine schroeder ( n, s )\n!\n!*******************************************************************************\n!\n!! SCHROEDER generates the Schroeder numbers.\n!\n!\n! Definition:\n!\n! The Schroeder number S(N) counts the number of ways to insert\n! parentheses into an expression of N items, with two or more items within\n! a parenthesis.\n!\n! Note that the Catalan number C(N) counts the number of ways\n! to legally arrange a set of N left and N right parentheses.\n!\n! Example:\n!\n! N = 4\n!\n! 1234\n! 12(34)\n! 1(234)\n! 1(2(34))\n! 1(23)4\n! 1((23)4)\n! (123)4\n! (12)34\n! (12)(34)\n! (1(23))4\n! ((12)3)4\n!\n! First Values:\n!\n! 1\n! 1\n! 3\n! 11\n! 45\n! 197\n! 903\n! 4279\n! 20793\n! 103049\n! 518859\n! 2646723\n! 13648869\n! 71039373\n!\n! Formula:\n!\n! S(N) = ( P(N)(3.0) - 3 P(N-1)(3.0) ) / ( 4 * ( N - 1 ) )\n! where P(N)(X) is the N-th Legendre polynomial.\n!\n! Recursion:\n!\n! S(1) = 1\n! S(2) = 1\n! S(N) = ( ( 6 * N - 9 ) * S(N-1) - ( N - 3 ) * S(N-2) ) / N\n!\n! Reference:\n!\n! R P Stanley,\n! Hipparchus, Plutarch, Schroeder, and Hough,\n! American Mathematical Monthly,\n! Volume 104, Number 4, 1997, pages 344-350.\n!\n! Laurent Habsieger, Maxim Kazarian, Sergei Lando,\n! On the Second Number of Plutarch,\n! American Mathematical Monthly, May 1998, page 446.\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of Schroeder numbers desired.\n!\n! Output, integer S(N), the Schroeder numbers.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer s(n)\n!\n if ( n <= 0 ) then\n return\n end if\n\n s(1) = 1\n\n if ( n <= 1 ) then\n return\n end if\n\n s(2) = 1\n\n if ( n <= 2 ) then\n return\n end if\n\n do i = 3, n\n s(i) = ( ( 6 * i - 9 ) * s(i-1) - ( i - 3 ) * s(i-2) ) / i\n end do\n\n return\nend\nsubroutine sort_heap_external ( n, indx, i, j, isgn )\n!\n!*******************************************************************************\n!\n!! SORT_HEAP_EXTERNAL externally sorts a list of items into linear order.\n!\n!\n! Discussion:\n!\n! The actual list of data is not passed to the routine. Hence this\n! routine may be used to sort integers, reals, numbers, names,\n! dates, shoe sizes, and so on. After each call, the routine asks\n! the user to compare or interchange two items, until a special\n! return value signals that the sorting is completed.\n!\n! Modified:\n!\n! 19 May 1999\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Parameters:\n!\n! Input, integer N, the number of items to be sorted.\n!\n! Input/output, integer INDX, the main communication signal.\n!\n! The user must set INDX to 0 before the first call.\n! Thereafter, the user should not change the value of INDX until\n! the sorting is done.\n!\n! On return, if INDX is\n!\n! greater than 0,\n! * interchange items I and J;\n! * call again.\n!\n! less than 0,\n! * compare items I and J;\n! * set ISGN = -1 if I < J, ISGN = +1 if I > J;\n! * call again.\n!\n! equal to 0, the sorting is done.\n!\n! Output, integer I, J, the indices of two items.\n! On return with INDX positive, elements I and J should be interchanged.\n! On return with INDX negative, elements I and J should be compared, and\n! the result reported in ISGN on the next call.\n!\n! Input, integer ISGN, results of comparison of elements I and J.\n! (Used only when the previous call returned INDX less than 0).\n! ISGN <= 0 means I is less than or equal to J;\n! ISGN => 0 means I is greater than or equal to J.\n!\n implicit none\n!\n integer i\n integer indx\n integer isgn\n integer j\n integer, save :: k = 0\n integer, save :: k1 = 0\n integer n\n integer, save :: n1 = 0\n!\n! INDX = 0: This is the first call.\n!\n if ( indx == 0 ) then\n\n n1 = n\n k = n / 2\n k1 = k\n!\n! INDX < 0: The user is returning the results of a comparison.\n!\n else if ( indx < 0 ) then\n\n if ( indx == -2 ) then\n\n if ( isgn < 0 ) then\n i = i + 1\n end if\n\n j = k1\n k1 = i\n indx = - 1\n return\n\n end if\n\n if ( isgn > 0 ) then\n indx = 2\n return\n end if\n\n if ( k <= 1 ) then\n\n if ( n1 == 1 ) then\n indx = 0\n else\n i = n1\n n1 = n1 - 1\n j = 1\n indx = 1\n end if\n\n return\n\n end if\n\n k = k - 1\n k1 = k\n!\n! INDX > 0, the user was asked to make an interchange.\n!\n else if ( indx == 1 ) then\n\n k1 = k\n\n end if\n\n do\n\n i = 2 * k1\n\n if ( i == n1 ) then\n j = k1\n k1 = i\n indx = - 1\n return\n else if ( i <= n1 ) then\n j = i + 1\n indx = - 2\n return\n end if\n\n if ( k <= 1 ) then\n exit\n end if\n\n k = k - 1\n k1 = k\n\n end do\n\n if ( n1 == 1 ) then\n indx = 0\n else\n i = n1\n n1 = n1 - 1\n j = 1\n indx = 1\n end if\n\n return\nend\nsubroutine sub_by_size_next ( n, iarray, size, more )\n!\n!*******************************************************************************\n!\n!! SUB_BY_SIZE_NEXT returns all subsets of an N set, in order of size.\n!\n!\n! Example:\n!\n! N = 4:\n!\n! 1 2 3 4\n! 1 2 3\n! 1 2 4\n! 1 3 4\n! 1 3\n! 1 4\n! 2 3\n! 1\n! 2\n! 3\n! (the empty set)\n!\n! Discussion:\n!\n! The subsets are returned in decreasing order of size, with the\n! empty set last.\n!\n! For a given size K, the K subsets are returned in lexicographic order.\n!\n! Modified:\n!\n! 02 December 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the size of the set.\n!\n! Output, integer IARRAY(N). The entries IARRAY(1:SIZE) contain\n! the elements of the subset. The elements are given in ascending\n! order.\n!\n! Output, integer SIZE, the number of elements in the subset.\n!\n! Input/output, logical MORE. Set MORE = .FALSE. before first call\n! for a new sequence of subsets. It then is set and remains\n! .TRUE. as long as the subset computed on this call is not the\n! final one. When the final subset is computed, MORE is set to\n! .FALSE. as a signal that the computation is done.\n!\n implicit none\n!\n integer n\n!\n integer iarray(n)\n logical more\n logical, save :: more2 = .false.\n integer size\n!\n if ( .not. more ) then\n more = .true.\n more2 = .false.\n size = n\n else if ( .not. more2 ) then\n size = size - 1\n end if\n!\n! Compute the next subset of size SIZE.\n!\n if ( size > 0 ) then\n call ksub_next ( n, size, iarray, more2 )\n else if ( size == 0 ) then\n more = .false.\n end if\n\n return\nend\nsubroutine sub_lex ( n, k, a, jmp, ndim )\n!\n!*******************************************************************************\n!\n!! SUB_LEX generates the subsets of a set of N elements, one at a time.\n!\n!\n! Discussion:\n!\n! The subsets are generated in lexical order. The routine can also be\n! forced to generate only those subsets whose size is no greater than\n! some user-specified maximum.\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Input, integer N, the order of the main set from which subsets\n! are chosen.\n!\n! Input/output, integer K. On first call, the user must set K = 0 as\n! a startup signal to the program. Thereafter, the routine returns\n! the size of the computed subset in K. On the last return,\n! the empty set is returned and K is 0, which is a signal to\n! the user that the computation is complete.\n!\n! Output, integer A(NDIM). A(I) is the I-th element of the\n! subset, listed in increasing order, with 0's in entries\n! beyond entry K.\n!\n! Input, logical JMP. In the simplest case, set JMP = .FALSE. for\n! a normal computation. But to jump over supersets of the input set,\n! set JMP = .TRUE.. Setting JMP=K.EQ.3 before every new call\n! will, for example, force all the subsets returned\n! to have cardinality 3 or less.\n!\n! Input, integer NDIM, the allowed storage for A. If NDIM < N,\n! JMP must be used to avoid creation of a subset too large to store in A.\n!\n implicit none\n!\n integer ndim\n!\n integer a(ndim)\n integer is\n logical jmp\n integer k\n integer n\n!\n if ( k == 0 ) then\n\n if ( jmp ) then\n return\n end if\n\n is = 0\n k = k + 1\n a(1) = 1\n\n else if ( a(k) /= n ) then\n\n is = a(k)\n\n if ( .not. jmp ) then\n k = k + 1\n end if\n\n a(k) = is + 1\n\n else\n\n k = k - 1\n\n if ( k /= 0 ) then\n a(k) = a(k) + 1\n end if\n\n end if\n\n return\nend\nsubroutine sub_next ( n, a, more, ncard, iadd )\n!\n!*******************************************************************************\n!\n!! SUB_NEXT generates all subsets of a set of order N, one at a time.\n!\n!\n! Discussion:\n!\n! It generates the subsets one at a time, by adding or subtracting\n! exactly one element on each step.\n!\n! The user should set MORE = .FALSE. and the value of N before\n! the first call. On return, the user may examine A which contains\n! the definition of the new subset, and must check .MORE., because\n! as soon as it is .FALSE. on return, all the subsets have been\n! generated and the user probably should cease calling.\n!\n! The first set returned is the empty set.\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Input, integer N, the order of the total set from which\n! subsets will be drawn.\n!\n! Output, integer A(N). On each return, the Gray code for the newly\n! generated subset. A(I) = 0 if element I is in the subset, 1 otherwise.\n!\n! Input/output, logical MORE. Set this variable .FALSE. before\n! the first call. Normally, MORE will be returned .TRUE. but once\n! all the subsets have been generated, MORE will be\n! reset .FALSE. on return and you should stop calling the program.\n!\n! Output, integer NCARD, the cardinality of the set returned,\n! which may be any value between 0 (the empty set) and N (the\n! whole set).\n!\n! Output, integer IADD, the element which was added or removed to the\n! previous subset to generate the current one. Exception:\n! the empty set is returned on the first call, and IADD is set to 0.\n!\n implicit none\n!\n integer n\n!\n integer a(n)\n integer i\n integer iadd\n logical more\n integer ncard\n!\n! First set returned is the empty set.\n!\n if ( .not. more ) then\n\n a(1:n) = 0\n\n iadd = 0\n ncard = 0\n more = .true.\n\n else\n\n iadd = 1\n\n if ( mod ( ncard, 2 ) /= 0 ) then\n\n do\n\n iadd = iadd + 1\n if ( a(iadd-1) /= 0 ) then\n exit\n end if\n\n end do\n\n end if\n\n a(iadd) = 1 - a(iadd)\n ncard = ncard + 2 * a(iadd) - 1\n!\n! Last set returned is the singleton A(N).\n!\n if ( ncard == a(n) ) then\n more = .false.\n end if\n\n end if\n\n return\nend\nsubroutine sub_random ( n, a )\n!\n!*******************************************************************************\n!\n!! SUB_RANDOM selects a random subset of an N-set.\n!\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 01 December 2000\n!\n! Parameters:\n!\n! Input, integer N, the size of the full set.\n!\n! Output, integer A(N). A vector to hold the information about\n! the set chosen. On return, if A(I) = 1, then\n! I is in the random subset, otherwise, A(I) = 0\n! and I is not in the random subset.\n!\n implicit none\n!\n integer n\n!\n integer a(n)\n integer i\n real r\n!\n do i = 1, n\n call i_random ( 0, 1, a(i) )\n end do\n\n return\nend\nsubroutine sub_rank ( a, irank, k )\n!\n!*******************************************************************************\n!\n!! SUB_RANK computes the rank of a subset of an N set.\n!\n!\n! Discussion:\n!\n! The routine accepts an array representing a subset of size K from a set\n! of size N, and returns the rank (or order) of that subset. This\n! is the same order in which routine SUB_NEXT2 would produce that subset.\n! Note the value of N is not input, and is not, in fact,\n! needed.\n!\n! Parameters:\n!\n! Input, integer A(K), contains K distinct numbers between\n! 1 and N, in order.\n!\n! Output, integer IRANK, the rank of this subset.\n!\n! Input, integer K, the number of elements in the subset.\n!\n implicit none\n!\n integer k\n!\n integer a(k)\n integer i\n integer iprod\n integer irank\n integer j\n!\n irank = 0\n\n do i = 1, k\n\n iprod = 1\n\n do j = i+1, a(i)-1\n iprod = iprod * j\n end do\n\n do j = 1, a(i)-i-1\n iprod = iprod / j\n end do\n\n if ( a(i) == 1 ) then\n iprod = 0\n end if\n\n irank = irank + iprod\n\n end do\n\n irank = irank + 1\n\n return\nend\nsubroutine sub_unrank ( a, irank, k )\n!\n!*******************************************************************************\n!\n!! SUB_UNRANK returns the subset of a given rank.\n!\n!\n! Discussion:\n!\n! SUB_UNRANK is given a rank and returns the corresponding subset of K\n! elements of a set of N elements. It uses the same ranking that\n! SUB_NEXT2 uses to generate all the subsets one at a time. Note that\n! the value of N itself is not input, nor is it needed.\n!\n! Modified:\n!\n! 24 July 2000\n!\n! Parameters:\n!\n! Output, integer A(K), K distinct integers in order between\n! 1 and N, which define the subset.\n!\n! Input, integer IRANK, the rank of the desired subset.\n! There are ( N*(N-1)*...*(N+K-1)) / ( K*(K-1)*...*2*1) such\n! subsets, so IRANK must be between 1 and that value.\n!\n! Input, integer K, the number of elements in the subset.\n!\n implicit none\n!\n integer k\n!\n integer a(k)\n integer i\n integer ii\n integer ip\n integer iprod\n integer irank\n integer jrank\n!\n jrank = irank - 1\n\n do ii = 1, k\n\n i = k + 1 - ii\n ip = i - 1\n iprod = 1\n\n do\n\n ip = ip + 1\n\n if ( ip /= i ) then\n iprod = ( ip * iprod ) / ( ip - i )\n end if\n\n if ( iprod > jrank ) then\n exit\n end if\n\n end do\n\n if ( ip /= i ) then\n iprod = ( ( ip - i ) * iprod ) / ip\n end if\n\n jrank = jrank - iprod\n a(i) = ip\n\n end do\n\n return\nend\nsubroutine thue_binary_next ( n, thue )\n!\n!*******************************************************************************\n!\n!! THUE_BINARY_NEXT returns the next element in a binary Thue sequence.\n!\n!\n! Discussion:\n!\n! Thue demonstrated that arbitrarily long sequences of 0's and\n! 1's could be generated which had the \"cubefree\" property. In\n! other words, for a given string S, there was no substring W\n! such that S contained \"WWW\". In fact, a stronger result holds:\n! if \"a\" is the first letter of W, it is never the case that S\n! contains the substring \"WWa\". \n!\n! In this example, the digits allowed are binary, that is, just\n! \"0\" and \"1\". The replacement rules are:\n!\n! \"0\" -> \"01\"\n! \"1\" -> \"10\"\n!\n! This routine produces the next binary Thue sequence in a given series.\n! However, the input sequence must be a Thue sequence in order for\n! us to guarantee that the output sequence will also have the\n! cubic nonrepetition property.\n!\n! Also, enough space must be set aside in THUE to hold the\n! output sequence. This will always be twice the input\n! value of N.\n!\n! Modified:\n!\n! 05 November 2001\n!\n! Parameters:\n!\n! Input/output, integer N. On input, the length of the input sequence.\n! On output, the length of the output sequence.\n!\n! Input, integer THUE(N). On input, the initial Thue sequence, and on\n! output, the result of applying the substitution rules once.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer n_out\n integer thue(*)\n integer thue_out(2*n)\n!\n n_out = 0\n\n do i = 1, n\n\n if ( thue(i) == 0 ) then\n n_out = n_out + 1\n thue_out(n_out) = 0\n n_out = n_out + 1\n thue_out(n_out) = 1\n else if ( thue(i) == 1 ) then\n n_out = n_out + 1\n thue_out(n_out) = 1\n n_out = n_out + 1\n thue_out(n_out) = 0\n else\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'THUE_BINARY_NEXT - Fatal error!'\n write ( *, '(a)' ) ' The input sequence contains a non-binary digit'\n write ( *, '(a,i6,a,i6)' ) ' THUE(', i, ') = ', thue(i)\n stop\n end if\n\n end do\n\n n = n_out\n thue(1:n) = thue_out(1:n)\n\n return\nend\nsubroutine thue_ternary_next ( n, thue )\n!\n!*******************************************************************************\n!\n!! THUE_TERNARY_NEXT returns the next element in a ternary Thue sequence.\n!\n!\n! Discussion:\n!\n! Thue was interested in showing that there were arbitrarily long\n! sequences of digits which never displayed a pair of contiguous\n! repetitions of any length. That is, there was no occurrence of \n! \"00\" or \"1010\" or \"121121\", anywhere in the string. This makes\n! the string \"squarefree\".\n!\n! To do this, he demonstrated a way to start with a single digit,\n! and to repeatedly apply a series of transformation rules to each \n! digit of the sequence, deriving nonrepeating sequences of ever \n! greater length.\n!\n! In this example, the digits allowed are ternary, that is, just\n! \"0\", \"1\" and \"2\". The replacement rules are:\n!\n! \"0\" -> \"12\"\n! \"1\" -> \"102\"\n! \"2\" -> \"0\"\n!\n! This routine produces the next Thue sequence in a given series.\n! However, the input sequence must be a Thue sequence in order for\n! us to guarantee that the output sequence will also have the \n! nonrepetition property.\n!\n! Also, enough space must be set aside in THUE to hold the\n! output sequence. This will never be more than 3 times the input\n! value of N.\n!\n! Reference:\n!\n! Brian Hayes,\n! Third Base,\n! American Scientist, \n! Volume 89, Number 6, pages 490-494, November-December 2001.\n!\n! Modified:\n!\n! 28 October 2001\n!\n! Parameters:\n!\n! Input/output, integer N. On input, the length of the input sequence.\n! On output, the length of the output sequence.\n!\n! Input, integer THUE(N). On input, the initial Thue sequence, and on\n! output, the result of applying the substitution rules once.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer n_out\n integer thue(*)\n integer thue_out(3*n)\n!\n n_out = 0\n\n do i = 1, n\n\n if ( thue(i) == 0 ) then\n n_out = n_out + 1\n thue_out(n_out) = 1\n n_out = n_out + 1\n thue_out(n_out) = 2\n else if ( thue(i) == 1 ) then\n n_out = n_out + 1\n thue_out(n_out) = 1\n n_out = n_out + 1\n thue_out(n_out) = 0\n n_out = n_out + 1\n thue_out(n_out) = 2\n else if ( thue(i) == 2 ) then\n n_out = n_out + 1\n thue_out(n_out) = 0\n else\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'THUE_TERNARY_NEXT - Fatal error!'\n write ( *, '(a)' ) ' The input sequence contains a non-ternary digit'\n write ( *, '(a,i6,a,i6)' ) ' THUE(', i, ') = ', thue(i)\n stop\n end if\n\n end do\n\n n = n_out\n thue(1:n) = thue_out(1:n)\n\n return\nend\n!!$subroutine timestamp ( )\n!!$!\n!!$!*******************************************************************************\n!!$!\n!!$!! TIMESTAMP prints the current YMDHMS date as a time stamp.\n!!$!\n!!$!\n!!$! Example:\n!!$!\n!!$! May 31 2001 9:45:54.872 AM\n!!$!\n!!$! Modified:\n!!$!\n!!$! 31 May 2001\n!!$!\n!!$! Author:\n!!$!\n!!$! John Burkardt\n!!$!\n!!$! Parameters:\n!!$!\n!!$! None\n!!$!\n!!$ implicit none\n!!$!\n!!$ character ( len = 8 ) ampm\n!!$ integer d\n!!$ character ( len = 8 ) date\n!!$ integer h\n!!$ integer m\n!!$ integer mm\n!!$ character ( len = 9 ), parameter, dimension(12) :: month = (/ &\n!!$ 'January ', 'February ', 'March ', 'April ', &\n!!$ 'May ', 'June ', 'July ', 'August ', &\n!!$ 'September', 'October ', 'November ', 'December ' /)\n!!$ integer n\n!!$ integer s\n!!$ character ( len = 10 ) time\n!!$ integer values(8)\n!!$ integer y\n!!$ character ( len = 5 ) zone\n!!$!\n!!$ call date_and_time ( date, time, zone, values )\n!!$\n!!$ y = values(1)\n!!$ m = values(2)\n!!$ d = values(3)\n!!$ h = values(5)\n!!$ n = values(6)\n!!$ s = values(7)\n!!$ mm = values(8)\n!!$\n!!$ if ( h < 12 ) then\n!!$ ampm = 'AM'\n!!$ else if ( h == 12 ) then\n!!$ if ( n == 0 .and. s == 0 ) then\n!!$ ampm = 'Noon'\n!!$ else\n!!$ ampm = 'PM'\n!!$ end if\n!!$ else\n!!$ h = h - 12\n!!$ if ( h < 12 ) then\n!!$ ampm = 'PM'\n!!$ else if ( h == 12 ) then\n!!$ if ( n == 0 .and. s == 0 ) then\n!!$ ampm = 'Midnight'\n!!$ else\n!!$ ampm = 'AM'\n!!$ end if\n!!$ end if\n!!$ end if\n!!$\n!!$ write ( *, '(a,1x,i2,1x,i4,2x,i2,a1,i2.2,a1,i2.2,a1,i3.3,1x,a)' ) &\n!!$ trim ( month(m) ), d, y, h, ':', n, ':', s, '.', mm, trim ( ampm )\n!!$\n!!$ return\n!!$end\nsubroutine triang ( n, izeta, p )\n!\n!*******************************************************************************\n!\n!! TRIANG renumbers elements in accordance with a partial ordering.\n!\n!\n! Discussion:\n!\n! TRIANG is given a partially ordered set, where the partial ordering\n! is defined by a matrix IZETA, where element I is partially less than\n! or equal to element J if and only if IZETA(I,J) = 1.\n!\n! TRIANG renumbers the elements with a permutation P so that if\n! element I is partially less than element J in the partial ordering,\n! then P(I) < P(J) in the usual, numerical ordering.\n!\n! In other words, the elements are relabeled so that their labels\n! reflect their ordering. This is equivalent to relabeling the\n! matrix so that, on unscrambling it, the matrix would be upper\n! triangular.\n!\n! Calling IMAT_PERM or RMAT_PERM with P used for both the row\n! and column permutations applied to matrix IZETA will result in\n! an upper triangular matrix.\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Input, integer N, the number of elements in the set. The number\n! of rows and columns used in IZETA.\n!\n! Input, integer IZETA(N,N), contains the description of the\n! partial ordering. To avoid confusion with the true \"less than\"\n! relationship, symbolized by \"<\" or \".LT.\", let us use\n! \"I .PLT. J\" to mean that I is less than J in the partial ordering.\n!\n! The diagonal entries of IZETA are meaningless.\n!\n! Consider any two distinct elements, I and J. There are three\n! possibilities:\n!\n! * I and J are not related in the partial ordering. That is, neither\n! I .PLT. J nor J .PLT. I are true. In that case,\n! set IZETA(I,J) = IZETA(J,I) = 0.\n!\n! * I and J are related, and I .PLT. J. In that case, set\n! IZETA(I,J) = 1, IZETA(J,I) = 0.\n!\n! * I and J are related, and J .PLT. I. In that case, set\n! IZETA(I,J) = 0, IZETA(J,I) = 1\n!\n! Note that it should never happen that IZETA(I,J) and IZETA(J,I)\n! are both nonzero. This would represent incorrect data.\n!\n! Thus, the values of IZETA(I,J) are:\n! 0, for diagonal elements, or for unrelated elements, or if J .PLT. I.\n! 1, (or any nonzero value) if I .PLT. J.\n!\n! Output, integer P(N), a permutation of the elements that reflects\n! their partial ordering. P(I) is the new label of element I, with\n! the property that if IZETA(I,J) = 1, that is, I .PLT. J,\n! then P(I) < P(J) (in the usual ordering).\n!\n implicit none\n!\n integer n\n!\n integer i\n integer ierror\n integer iq\n integer ir\n\n integer it\n integer izeta(n,n)\n integer l\n integer m\n integer p(n)\n!\n! Make sure IZETA represents a partially ordered set. In other words,\n! if IZETA(I,J) = 1, then IZETA(J,I) must NOT be 1.\n!\n call pord_check ( n, izeta, ierror )\n\n if ( ierror /= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TRIANG - Fatal error!'\n write ( *, '(a)' ) ' The matrix IZETA does not represent a'\n write ( *, '(a)' ) ' partial ordering.'\n stop\n end if\n\n m = 0\n l = 0\n p(1:n) = 0\n!\n! Find the next value of M for which P(M) is 0.\n!\n10 continue\n\n do\n\n m = m + 1\n\n if ( p(m) == 0 ) then\n exit\n end if\n\n if ( m == n ) then\n return\n end if\n\n end do\n\n it = m + 1\n ir = m + 1\n\n do\n\n if ( ir <= n ) then\n\n if ( p(ir) == 0 .and. izeta(ir,m) /= 0 ) then\n p(ir) = m\n m = ir\n ir = it\n else\n ir = ir + 1\n end if\n\n else\n\n l = l + 1\n iq = p(m)\n p(m) = l\n\n if ( iq == 0 ) then\n if ( m == n ) then\n exit\n end if\n go to 10\n end if\n\n ir = m + 1\n m = iq\n\n end if\n\n end do\n\n return\nend\nsubroutine tuple_next ( m, n, k, x )\n!\n!*******************************************************************************\n!\n!! TUPLE_NEXT computes the next element of a tuple space.\n!\n!\n! Discussion:\n!\n! The elements are N vectors. Each entry is constrained to lie\n! between 1 and M. The elements are produced one at a time.\n! The first element is\n! (1,1,...,1)\n! and the last element is\n! (M,M,...,M)\n! Intermediate elements are produced in lexicographic order.\n!\n! Examples:\n!\n! N = 2, M = 3\n!\n! K X\n! 1 1 1\n! 2 1 2\n! 3 1 3\n! 4 2 1\n! 5 2 2\n! 6 2 3\n! 7 3 1\n! 8 3 2\n! 9 3 3\n!\n! Modified:\n!\n! 30 October 2000\n!\n! Parameters:\n!\n! Input, integer M, the maximum entry.\n!\n! Input, integer N, the number of components.\n!\n! Input/output, integer K, counts the elements.\n! On first call, set K to 0. Thereafter, K will indicate the\n! order of the element returned. When there are no more elements,\n! K will be returned as 0.\n!\n! Input/output, integer X(N), on input the previous tuple.\n! On output, the next tuple.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer k\n integer m\n integer x(n)\n!\n if ( m < 1 ) then\n return\n end if\n\n if ( k <= 0 ) then\n\n x(1:n) = 1\n k = 1\n\n else\n\n k = k + 1\n i = n\n\n do\n\n if ( x(i) < m ) then\n x(i) = x(i) + 1\n exit\n end if\n\n x(i) = 1\n\n if ( i == 1 ) then\n k = 0\n exit\n end if\n\n i = i - 1\n\n end do\n\n end if\n\n return\nend\nsubroutine tuple_next_ge ( m, n, k, x )\n!\n!*******************************************************************************\n!\n!! TUPLE_NEXT_GE computes the next \"nondecreasing\" element of a tuple space.\n!\n!\n! Discussion:\n!\n! The elements are N vectors. Each element is constrained to lie\n! between 1 and M, and to have components that are nondecreasing.\n! That is, for an element X, and any positive K,\n! X(I) <= X(I+K)\n!\n! The elements are produced one at a time.\n! The first element is\n! (1,1,...,1)\n! and the last element is\n! (M,M,...,M)\n! Intermediate elements are produced in lexicographic order.\n!\n! Examples:\n!\n! N = 3, M = 3\n!\n! K X\n! 1 1 1 1\n! 2 1 1 2\n! 3 1 1 3\n! 4 1 2 2\n! 5 1 2 3\n! 6 1 3 3\n! 7 2 2 2\n! 8 2 2 3\n! 9 2 3 3\n! 10 3 3 3\n!\n! Modified:\n!\n! 14 August 2001\n!\n! Parameters:\n!\n! Input, integer M, the maximum entry.\n!\n! Input, integer N, the number of components.\n!\n! Input/output, integer K, counts the elements.\n! On first call, set K to 0. Thereafter, K will indicate the\n! order of the element returned. When there are no more elements,\n! K will be returned as 0.\n!\n! Input/output, integer X(N), on input the previous tuple.\n! On output, the next tuple.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer k\n integer m\n integer x(n)\n!\n if ( m < 1 ) then\n return\n end if\n\n if ( k <= 0 ) then\n x(1:n) = 1\n k = 1\n return\n end if\n\n do i = n, 1, -1\n\n if ( x(i) < m ) then\n x(i) = x(i) + 1\n x(i+1:n) = x(i)\n k = k + 1\n return\n end if\n\n end do\n\n k = 0\n x(1:n) = 0\n\n return\nend\nsubroutine tuple_next2 ( n, xmin, xmax, x, rank )\n!\n!*******************************************************************************\n!\n!! TUPLE_NEXT2 computes the next element of an integer tuple space.\n!\n!\n! Discussion:\n!\n! The elements X are N vectors.\n!\n! Each entry X(I) is constrained to lie between XMIN(I) and XMAX(I).\n!\n! The elements are produced one at a time.\n!\n! The first element is\n! (XMIN(1), XMIN(2), ..., XMIN(N)),\n! the second is (probably)\n! (XMIN(1), XMIN(2), ..., XMIN(N)+1),\n! and the last element is\n! (XMAX(1), XMAX(2), ..., XMAX(N))\n!\n! Intermediate elements are produced in a lexicographic order, with\n! the first index more important than the last, and the ordering of\n! values at a fixed index implicitly defined by the sign of\n! XMAX(I) - XMIN(I).\n!\n! Examples:\n!\n! N = 2,\n! XMIN = (/ 1, 10 /)\n! XMAX = (/ 3, 8 /)\n!\n! RANK X\n! ---- -----\n! 1 1 10\n! 2 1 9\n! 3 1 8\n! 4 2 10\n! 5 2 9\n! 6 2 8\n! 7 3 10\n! 8 3 9\n! 9 3 8\n!\n! Modified:\n!\n! 21 March 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the number of components.\n!\n! Input, integer XMIN(N), XMAX(N), the \"minimum\" and \"maximum\" entry values.\n! These values are minimum and maximum only in the sense of the lexicographic\n! ordering. In fact, XMIN(I) may be less than, equal to, or greater\n! than XMAX(I).\n!\n! Input/output, integer X(N), on input the previous tuple.\n! On output, the next tuple.\n!\n! Input/output, integer RANK, the rank of the item. On first call,\n! set RANK to 0 to start up the sequence. On return, if RANK is zero,\n! there are no more items in the sequence.\n!\n implicit none\n!\n integer n\n!\n integer i\n integer rank\n integer x(n)\n integer xmin(n)\n integer xmax(n)\n!\n if ( rank < 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TUPLE_NEXT2 - Fatal error!'\n write ( *, '(a,i6)' ) ' Illegal value of RANK = ', rank\n stop\n end if\n\n if ( rank > product ( 1 + abs ( xmax(1:n) - xmin(1:n) ) ) ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TUPLE_NEXT2 - Fatal error!'\n write ( *, '(a,i6)' ) ' Illegal value of RANK = ', rank\n stop\n end if\n\n if ( rank == 0 ) then\n x(1:n) = xmin(1:n)\n rank = 1\n return\n end if\n\n rank = rank + 1\n i = n\n\n do\n\n if ( x(i) /= xmax(i) ) then\n x(i) = x(i) + sign ( 1, xmax(i) - xmin(i) )\n exit\n end if\n\n x(i) = xmin(i)\n\n if ( i == 1 ) then\n rank = 0\n exit\n end if\n\n i = i - 1\n\n end do\n\n return\nend\nsubroutine vec_next ( n, iarray, more, base )\n!\n!*******************************************************************************\n!\n!! VEC_NEXT generates all N-vectors of integers modulo a given base.\n!\n!\n! Examples:\n!\n! N = 2, BASE = 3\n!\n! 0 0\n! 0 1\n! 0 2\n! 1 0\n! 1 1\n! 1 2\n! 2 0\n! 2 1\n! 2 2\n!\n! Comment:\n!\n! The vectors are produced in lexical order, starting with\n! (0,0,...,0), (0,0,...,1), ... through (BASE-1,BASE-1,...,BASE-1).\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Input, integer N, the size of the vectors to be used.\n!\n! Output, integer IARRAY(N). On each return, IARRAY\n! will contain entries in the range 0 to BASE-1.\n!\n! Input/output, logical MORE. Set this variable .FALSE. before\n! the first call. Normally, MORE will be returned .TRUE. but\n! once all the vectors have been generated, MORE will be\n! reset .FALSE. and you should stop calling the program.\n!\n! Input, integer BASE, the base to be used. BASE = 2 will\n! give vectors of 0's and 1's, for instance.\n!\n implicit none\n!\n integer n\n!\n integer base\n integer i\n integer iarray(n)\n integer, save :: kount = 0\n integer, save :: last = 0\n logical more\n integer nn\n!\n if ( .not. more ) then\n\n kount = 1\n last = base**n\n more = .true.\n iarray(1:n) = 0\n\n else\n\n kount = kount + 1\n\n if ( kount == last ) then\n more = .false.\n end if\n\n iarray(n) = iarray(n) + 1\n\n do i = 1, n\n\n nn = n - i\n\n if ( iarray(nn+1) < base ) then\n return\n end if\n\n iarray(nn+1) = 0\n\n if ( nn /= 0 ) then\n iarray(nn) = iarray(nn) + 1\n end if\n\n end do\n\n end if\n\n return\nend\nsubroutine vec_next2 ( done, iactiv, iarray, idir, imax, n )\n!\n!*******************************************************************************\n!\n!! VEC_NEXT2 computes the elements of a product space.\n!\n!\n! Discussion:\n!\n! The elements are produced one at a time.\n!\n! This routine handles the case where the number of degrees of freedom may\n! differ from one component to the next.\n!\n! Examples:\n!\n! N = 2, IMAX = ( 2, 3 )\n!\n! 0 0\n! 0 1\n! 0 2\n! 1 2\n! 1 1\n! 1 0\n!\n! Comments:\n!\n! A method similar to the Gray code is used, so that successive\n! elements returned by this routine differ by only a single element.\n!\n! Reference:\n!\n! Dennis Stanton and Dennis White,\n! Constructive Combinatorics,\n! Springer Verlag, New York, 1986.\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Parameters:\n!\n! Input/output, logical DONE. On the first call, the user must\n! set DONE to .TRUE. This signals the program to initialize data.\n! On every return, if DONE is .FALSE., the program has computed\n! another entry, which is contained in IARRAY. If DONE is .TRUE.,\n! then there are no more entries, and the program should not be\n! called for any more.\n!\n! Workspace, integer IACTIV(N).\n!\n! Input/output, integer IARRAY(N). On the first call, the input value\n! of IARRAY doesn't matter. Thereafter, it should be the same as\n! its output value from the previous call. On output, if DONE\n! is .FALSE., then IARRAY contains the next element of the space.\n!\n! Workspace, integer IDIR(N).\n!\n! Input, integer IMAX(N), contains the number of degrees of\n! freedom of each component. The output values of IARRAY will\n! satisfy 0 <= IARRAY(I) < IMAX(I).\n!\n! Input, integer N, the number of components.\n!\n implicit none\n!\n integer n\n!\n logical done\n integer i\n integer iactiv(n)\n integer iarray(n)\n integer idir(n)\n integer imax(n)\n integer ip\n integer maxact\n!\n! The user is calling for the first time.\n!\n if ( done ) then\n\n done = .false.\n\n do i = 1, n\n\n iarray(i) = 0\n idir(i) = 1\n\n if ( imax(i) < 1 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'VEC_NEXT2 - Warning!'\n write ( *, '(a,i6)' ) ' For index I = ',i\n write ( *, '(a,i6)' ) ' the nonpositive value of IMAX(I) = ', imax(i)\n write ( *, '(a)' ) ' which was reset to 1!'\n imax(i) = 1\n iactiv(i) = 0\n else if ( imax(i) == 1 ) then\n iactiv(i) = 0\n else\n iactiv(i) = 1\n end if\n\n end do\n!\n! The user is asking for the next vector.\n!\n else\n!\n! Find the maximum active index.\n!\n maxact = 0\n\n do i = 1, n\n if ( iactiv(i) /= 0 ) then\n maxact = i\n end if\n end do\n\n if ( maxact /= 0 ) then\n\n done = .false.\n ip = maxact\n iarray(ip) = iarray(ip) + idir(ip)\n\n if ( iarray(ip) == imax(ip)-1 .or. iarray(ip) == 0 ) then\n\n idir(ip) = - idir(ip)\n iactiv(ip) = 0\n\n end if\n\n do i = ip+1, n\n if ( imax(i) > 1 ) then\n iactiv(i) = i\n end if\n end do\n\n else\n done = .true.\n end if\n\n end if\n\n return\nend\nsubroutine vec_random ( n, iarray, base )\n!\n!*****************************************************************************\n!\n!! VEC_RANDOM selects a random N-vector of integers modulo a given base.\n!\n!\n! Modified:\n!\n! 15 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the size of the vector to be generated.\n!\n! Output, integer IARRAY(N), a list of N random values between\n! 0 and BASE-1.\n!\n! Input, integer BASE, the base to be used.\n!\n implicit none\n!\n integer n\n!\n integer base\n integer i\n integer iarray(n)\n integer ival\n!\n do i = 1, n\n call i_random ( 0, base-1, ival )\n iarray(i) = ival\n end do\n\n return\nend\nsubroutine vec_rank ( iarray, imax, n, rank )\n!\n!*******************************************************************************\n!\n!! VEC_RANK computes the rank of a product space element.\n!\n!\n! Discussion:\n!\n! The rank applies only to the elements as produced by the routine\n! VEC_NEXT2.\n!\n! Examples:\n!\n! N = 2, IMAX = ( 2, 3 ), IARRAY = ( 1, 2 ),\n!\n! RANK = 4.\n!\n! Reference:\n!\n! Dennis Stanton and Dennis White,\n! Constructive Combinatorics,\n! Springer Verlag, New York, 1986.\n!\n! Modified:\n!\n! 27 July 1998\n!\n! Parameters:\n!\n! Input, integer IARRAY(N), the product space element, with the\n! property that 0 <= IARRAY(I) < IMAX(I) for each entry I.\n!\n! Input, integer IMAX(N), contains the number of degrees of\n! freedom of each component. The output values of IARRAY will\n! satisfy 0 <= IARRAY(I) < IMAX(I).\n!\n! Input, integer N, the number of components.\n!\n! Output, integer RANK, the rank, or order, of the element in\n! the list of all elements. The rank count begins at 1.\n!\n implicit none\n!\n integer n\n!\n integer c\n integer i\n integer iarray(n)\n integer imax(n)\n integer rank\n!\n rank = 0\n\n do i = 1, n\n\n if ( mod ( rank, 2 ) == 1 ) then\n c = imax(i) - iarray(i) - 1\n else\n c = iarray(i)\n end if\n\n rank = imax(i) * rank + c\n\n end do\n\n rank = rank + 1\n\n return\nend\nsubroutine vec_unrank ( iarray, imax, n, rank )\n!\n!*******************************************************************************\n!\n!! VEC_UNRANK computes the product space element of a given rank.\n!\n!\n! Discussion:\n!\n! The rank applies only to the elements as produced by the routine\n! VEC_NEXT2.\n!\n! Examples:\n!\n! N = 2, IMAX = ( 2, 3 ), RANK = 4.\n!\n! IARRAY = ( 1, 2 ).\n!\n! Reference:\n!\n! Dennis Stanton and Dennis White,\n! Constructive Combinatorics,\n! Springer Verlag, New York, 1986.\n!\n! Modified:\n!\n! 27 July 1998\n!\n! Parameters:\n!\n! Output, integer IARRAY(N), the product space element of the given rank.\n!\n! Input, integer IMAX(N), contains the number of degrees of\n! freedom of each component. The output values of IARRAY will\n! satisfy 0 <= IARRAY(I) < IMAX(I).\n!\n! Input, integer N, the number of components.\n!\n! Input, integer RANK, the desired rank, or order, of the element in\n! the list of all elements. The rank count begins at 1 and extends\n! to MAXRANK = Product ( I = 1 to N ) IMAX(I).\n!\n implicit none\n!\n integer n\n!\n integer i\n integer iarray(n)\n integer imax(n)\n integer rank\n integer s\n!\n s = rank - 1\n\n do i = n, 1, -1\n\n iarray(i) = mod ( s, imax(i) )\n s = s / imax(i)\n\n if ( mod ( s, 2 ) == 1 ) then\n iarray(i) = imax(i) - iarray(i) - 1\n end if\n\n end do\n\n return\nend\nsubroutine ytb_enum ( n, ytb_num )\n!\n!*******************************************************************************\n!\n!! YTB_ENUM enumerates the Young tableau of size N.\n!\n!\n! Discussion:\n!\n! If A(N) is the number of Young tableau of size N, then A(1) = 1,\n! A(2) = 2, and\n!\n! A(N) = A(N-1) + (N-1) * A(N-2).\n!\n! Modified:\n!\n! 05 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the integer which is to be partitioned.\n!\n! Output, integer YTB_NUM, the number of Young tableau of N.\n!\n implicit none\n!\n integer a1\n integer a2\n integer a3\n integer i\n integer n\n integer ytb_num\n!\n if ( n <= 0 ) then\n ytb_num = 0\n else if ( n == 1 ) then\n ytb_num = 1\n else if ( n == 2 ) then\n ytb_num = 2\n else\n a2 = 1\n a3 = 2\n do i = 3, n\n a1 = a2\n a2 = a3\n a3 = a2 + ( i - 1 ) * a1\n end do\n ytb_num = a3\n end if\n\n return\nend\nsubroutine ytb_next ( n, lambda, iarray, more )\n!\n!*******************************************************************************\n!\n!! YTB_NEXT computes the next Young tableau for a given shape.\n!\n!\n! Discussion:\n!\n! When the routine is called with MORE = .FALSE. (the first time), and\n! if LAMBDA on this call has M parts, with M n ) then\n exit\n end if\n\n if ( lambda(ir) /= 0 ) then\n iarray(l) = ir\n lambda(ir) = lambda(ir) - 1\n l = l + 1\n ir = ir + 1\n cycle\n end if\n\n if ( l > it ) then\n exit\n end if\n\n ir = 1\n\n end do\n\n if ( n == 1 ) then\n more = .false.\n return\n end if\n\n do j = 2, n\n if ( iarray(j) < iarray(j-1) ) then\n more = .true.\n return\n end if\n end do\n\n more = .false.\n\n return\nend\nsubroutine ytb_print ( n, iarray )\n!\n!*******************************************************************************\n!\n!! YTB_PRINT prints a Young tableau.\n!\n!\n! Modified:\n!\n! 24 July 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer N, the integer that is partitioned.\n!\n! Input, integer IARRAY(N), describes the Young tableau.\n! IARRAY(I) is the row of the tableau on which I occurs.\n!\n implicit none\n!\n integer n\n!\n integer iarray(n)\n integer j\n integer jarray(n)\n integer row_i\n integer row_length\n!\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'Young tableau:'\n write ( *, '(a)' ) ' '\n\n row_i = 0\n\n do\n\n row_i = row_i + 1\n\n row_length = 0\n\n do j = 1, n\n\n if ( iarray(j) == row_i ) then\n row_length = row_length + 1\n jarray(row_length) = j\n end if\n\n end do\n\n if ( row_length <= 0 ) then\n exit\n end if\n\n write ( *, '(20i4)' ) jarray(1:row_length)\n\n end do\n\n return\nend\nsubroutine ytb_random ( n, lambda, iarray )\n!\n!*******************************************************************************\n!\n!! YTB_RANDOM selects a random Young tableau of a given shape.\n!\n!\n! Reference:\n!\n! A Nijenhuis and H Wilf,\n! Combinatorial Algorithms,\n! Academic Press, 1978, second edition,\n! ISBN 0-12-519260-6.\n!\n! Modified:\n!\n! 01 December 2000\n!\n! Parameters:\n!\n! Input, integer N, the integer which has been partitioned.\n!\n! Input, integer LAMBDA(N). N = LAMBDA(1)+LAMBDA(2)+...is the\n! partition of N.\n!\n! Output, integer IARRAY(N). The vector describing the Young tableau.\n!\n implicit none\n!\n integer n\n real r\n!\n integer i\n integer iarray(n)\n integer ih\n integer j\n integer l\n integer lambda(n)\n integer m\n!\n iarray(1:n) = 0\n\n i = 0\n l = 0\n\n do\n\n i = i + 1\n do j = 1, lambda(i)\n iarray(j) = iarray(j) + 1\n l = l + 1\n end do\n\n if ( l >= n ) then\n exit\n end if\n\n end do\n\n do m = 1, n\n\n do\n\n call i_random ( 1, iarray(1), i )\n call i_random ( 1, lambda(1), j )\n\n if ( i <= iarray(j) .and. j <= lambda(i) ) then\n exit\n end if\n\n end do\n\n do\n\n ih = iarray(j) + lambda(i) - i - j\n\n if ( ih == 0 ) then\n exit\n end if\n\n call i_random ( 1, ih, l )\n\n if ( l <= lambda(i)-j ) then\n j = j + l\n else\n i = l - lambda(i) + i + j\n end if\n\n end do\n\n lambda(i) = lambda(i) - 1\n iarray(j) = iarray(j) - 1\n iarray(n+1-m) = i\n\n end do\n\n do i = 1, n\n lambda(iarray(i)) = lambda(iarray(i)) + 1\n end do\n\n return\nend\n", "meta": {"hexsha": "50081d9fc89bc51d0cd5e11124df6341b62e38ce", "size": 440101, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/FORTRAN/Manybody/subset.f90", "max_stars_repo_name": "gsinuco/OPENMMF", "max_stars_repo_head_hexsha": "2cc0d0f2a4ded895c189050c38dbf2e8985e2d55", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-05-12T19:28:12.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T05:37:17.000Z", "max_issues_repo_path": "examples/FORTRAN/Manybody/subset.f90", "max_issues_repo_name": "gsinuco/OPENMMF", "max_issues_repo_head_hexsha": "2cc0d0f2a4ded895c189050c38dbf2e8985e2d55", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "examples/FORTRAN/Manybody/subset.f90", "max_forks_repo_name": "gsinuco/OPENMMF", "max_forks_repo_head_hexsha": "2cc0d0f2a4ded895c189050c38dbf2e8985e2d55", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-05-12T19:28:13.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-16T21:09:32.000Z", "avg_line_length": 19.9194804019, "max_line_length": 88, "alphanum_fraction": 0.5442159868, "num_tokens": 149777, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303087996143, "lm_q2_score": 0.8652240721511739, "lm_q1q2_score": 0.6839858529385273}} {"text": "! Fortran program to open, clost, read and write data from a file\n! This is basic file input/output in fortran\n\nprogram outputdata\n implicit none\n\n real, DIMENSION(100) :: x, y, p, q\n integer :: i\n\n do i = 1,100\n x(i) = i * 0.1\n y(i) = sin(x(i)) * (1 - cos(x(i)/3.0))\n end do\n\n ! Output the data to a dat file\n open(1, file = 'data.dat', status = 'new')\n do i = 1,100\n write(1,*) x(i), y(i)\n end do\n close(1)\n\n ! opening a file for reading\n\n open(2, file = 'data.dat', status = 'old')\n do i = 1,100\n read(2,*) p(i), q(i)\n end do\n close(2)\n\n do i = 1,100\n write(*,*) p(i), q(i)\n end do\n\nend program outputdata\n", "meta": {"hexsha": "bea2adb5011b5959b5e19c84675b881bc3cced5a", "size": 695, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "FPL/class9_file_input_output/outputdata.f90", "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": "FPL/class9_file_input_output/outputdata.f90", "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": "FPL/class9_file_input_output/outputdata.f90", "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.8571428571, "max_line_length": 65, "alphanum_fraction": 0.5251798561, "num_tokens": 244, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951025545427, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.6839591759559602}} {"text": "! OndedimensionUnsteadyHeatConduct.f90\r\n!\r\n! Program:\r\n! OndedimensionUnsteadyHeatConduct - Compute Onedimension Heat Transfer Problem\r\n! Author: Yang Yang \r\n! October. 2013. \r\n\r\n!****************************************************************************\r\n!\r\n! PROGRAM: OndedimensionUnsteadyHeatConduct\r\n!\r\n! PURPOSE: Compute Onedimension Heat Conduct Problem in the Wall with Convection Boundary Condition\r\n!\r\n!****************************************************************************\r\n\r\nPROGRAM OndedimensionUnsteadyHeatConduct\r\nIMPLICIT NONE\r\n\r\n! Basic Physics Parameters: data for metal iron \r\nREAL*8:: k=80.2,rho=7870,cp=447,L=10,h=300,Tf=300,Ti=900 \r\n! Basic Mesh Parameters:\r\nINTEGER Nx,Nt\r\nPARAMETER(Nx=100,Nt=100)\r\nREAL*8:: dx,dt,x(Nx),t(Nt)\r\n! Temperature Field Variables:\r\nREAL*8,DIMENSION(Nt,Nx)::Temperature \r\n! Process Varibles:\r\nREAL*8:: e(2:Nx),b(1:Nx),c(1:Nx-1),f(1:Nx),Temp(Nx),Fo,Bi\r\n! Control Varibles:\r\nINTEGER:: i,j\r\n\r\n \r\n! out put file directory\r\nOPEN(2,file='space_time.txt')\r\nOPEN(3,file='result.txt')\r\n\r\n! Mesh step length\r\ndx=L/(Nx-1)\r\ndt=2000\r\nx(1) = 0\r\nDO j=2,Nx\r\n x(j) = x(j-1) + dx\r\nEND DO\r\nt(1) = 0\r\nDO j=2,Nt\r\n t(j) = t(j-1) + dt\r\nEND DO\r\n\r\n! Compute Fo and Bi (dimensionless)\r\nFo = (k/(rho*cp)) *dt / (dx**2)\r\nBi = h*dx / (k)\r\n\r\n! Initial Temperature Field\r\nDO i=1,Nt\r\n DO j=1,Nx\r\n Temperature(i,j) = 0\r\n END DO\r\nEND DO\r\n\r\nDO j=1,Nx\r\n Temperature(1,j) = Ti\r\nEND DO\r\n\r\n\r\n! main time loop\r\n! |b1 c1 |\r\n! |e2 b2 c2 |\r\n! | e3 b3 c3 |\r\n! | e4 b4 c4 |\r\n! | . . . |\r\n! | . . cn-1|\r\n! | en bn|\r\nDO i=2,Nt\r\n ! Assemble Sparse matrix A\r\n DO j = 2,Nx-1\r\n c(j) = -Fo\r\n e(j) = -Fo\r\n END DO\r\n c(1) = -2*Fo\r\n e(Nx) = -2*Fo\r\n \r\n DO j=2,Nx-1\r\n b(j) = (1+2*Fo)\r\n END DO\r\n b(1) = 1+2*Bi*Fo+2*Fo \r\n b(Nx) = 1+2*Bi*Fo+2*Fo\r\n \r\n DO j=2,Nx-1\r\n f(j)= Temperature(i-1,j)\r\n END DO\r\n f(1) = 2*Bi*Fo*Tf + Temperature(i-1,1) \r\n f(Nx) = 2*Bi*Fo*Tf + Temperature(i-1,Nx)\r\n DO\r\n j=1,Nx\r\n Temp(j) = Temperature(i-1,j)\r\n END DO\r\n ! Inner loop to update temperature field:\r\n CALL chase(c,e,b,f,Nx,Temp)\r\n ! Save Result\r\n DO j=1,Nx\r\n Temperature(i,j) = Temp(j)\r\n END DO\r\n ! Print current time step\r\n PRINT*, \"Current Time Step:\",i\r\nEND DO\r\n \r\n! save result to file\r\nWRITE(2,200)t(:),x(:)\r\nDO i=1,Nt\r\n WRITE(3,100)Temperature(i,:)\r\nEND DO\r\n100 FORMAT(100(f15.8)) \r\n200 FORMAT(100(f12.5))\r\n\r\n! Body of OndedimensionUnsteadyHeatConduct\r\nPRINT *, 'Computing Job Compelete!'\r\nPAUSE\r\nEND PROGRAM OndedimensionUnsteadyHeatConduct\r\n\r\n", "meta": {"hexsha": "981818848cf787e42bba51b0a5e096b883a2ebc5", "size": 2665, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "OneDimensionUnsteadyHeatConduct/OndedimensionUnsteadHeatConduct.f90", "max_stars_repo_name": "shihe000/matlabcfd", "max_stars_repo_head_hexsha": "1134a2385efaa4c9824a309fbb79fd33afff17c1", "max_stars_repo_licenses": ["AFL-3.0"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2018-03-12T02:18:35.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-09T01:53:49.000Z", "max_issues_repo_path": "OneDimensionUnsteadyHeatConduct/OndedimensionUnsteadHeatConduct.f90", "max_issues_repo_name": "shihe000/matlabcfd", "max_issues_repo_head_hexsha": "1134a2385efaa4c9824a309fbb79fd33afff17c1", "max_issues_repo_licenses": ["AFL-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "OneDimensionUnsteadyHeatConduct/OndedimensionUnsteadHeatConduct.f90", "max_forks_repo_name": "shihe000/matlabcfd", "max_forks_repo_head_hexsha": "1134a2385efaa4c9824a309fbb79fd33afff17c1", "max_forks_repo_licenses": ["AFL-3.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-06-02T11:35:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-05T21:28:17.000Z", "avg_line_length": 22.2083333333, "max_line_length": 101, "alphanum_fraction": 0.5324577861, "num_tokens": 920, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898254600903, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6839453021850155}} {"text": "!===============================================================================\n!> Compute time derivative from a sequence of time slices, using Lagrange\n!> interpolation\n!===============================================================================\n MODULE time_slices_mod\n USE io_mod\n USE io_unit_mod\n USE trace_mod\n USE patch_mod\n USE kinds_mod\n USE lagrange_mod\n implicit none\n private\n type, public:: time_slices_t\n integer:: order=3\n contains\n procedure:: init\n procedure, nopass:: interpolate\n procedure, nopass:: derivative1\n procedure, nopass:: derivative2\n end type\n integer, save:: verbose=0\n integer, save:: order=3\n integer, save:: id_debug=0\n type(time_slices_t), public:: time_slices\nCONTAINS\n\n!===============================================================================\n!===============================================================================\nSUBROUTINE init (self, nt)\n class(time_slices_t):: self\n integer:: nt\n !.............................................................................\n integer:: iostat\n namelist /time_slices_params/ verbose, order, id_debug\n logical, save:: first_time=.true.\n !-----------------------------------------------------------------------------\n call trace%begin ('time_slices_t%init')\n !$omp critical (input_cr)\n if (first_time) then\n first_time = .false.\n rewind (io_unit%input)\n read (io_unit%input, time_slices_params, iostat=iostat)\n order = min(order,nt-2)\n write (io%output, time_slices_params)\n write (io_unit%nml, time_slices_params)\n flush (io_unit%nml)\n call lagrange%test\n end if\n !$omp end critical (input_cr)\n self%order = order\n call trace%end()\nEND SUBROUTINE init\n\n!===============================================================================\n!> Time interpolation. mem() is assumed to contain nt time slices of a 3-D\n!> variable, with times consistent with the times produced by patch%timeslots()\n!===============================================================================\nSUBROUTINE interpolate (patch, mem, buffer)\n class(patch_t):: patch\n integer:: iv\n real(kind=KindScalarVar), dimension(:,:,:,:):: mem\n real(kind=4), dimension(:,:,:):: buffer\n !.............................................................................\n real(8):: times(patch%nt-1)\n integer:: iit(patch%nt-1)\n real(8), dimension(order+1):: w\n integer:: i1, i2\n !-----------------------------------------------------------------------------\n if (verbose > 0) write(io_unit%log,*) patch%id, 'time_slices_t%interpolate'\n call patch%timeslots (iit, times)\n call lagrange%sequence_weights (patch%out_next, times, i1, i2, w, order)\n call weighted_sum (patch, times, w, i1, i2, mem, buffer)\nEND SUBROUTINE interpolate\n\n!===============================================================================\n!> First time derivate\n!===============================================================================\nSUBROUTINE derivative1 (patch, mem, buffer)\n class(patch_t):: patch\n integer:: iv\n real(kind=KindScalarVar), dimension(:,:,:,:):: mem\n real(kind=4), dimension(:,:,:):: buffer\n !.............................................................................\n real(8):: times(patch%nt-1)\n real(8), dimension(order+1):: w\n integer:: i1, i2\n !-----------------------------------------------------------------------------\n if (verbose > 0) write(io_unit%log,*) patch%id, 'time_slices_t%derivative1'\n times = patch%t(patch%iit(1:patch%nt-1))\n call lagrange%deriv_sequence_weights (patch%out_next, times, i1, i2, w, order)\n call weighted_sum (patch, times, w, i1, i2, mem, buffer)\nEND SUBROUTINE derivative1\n\n!===============================================================================\n!> Second time derivate\n!===============================================================================\nSUBROUTINE derivative2 (patch, mem, buffer)\n class(patch_t):: patch\n integer:: iv\n real(kind=KindScalarVar), dimension(:,:,:,:):: mem\n real(kind=4), dimension(:,:,:):: buffer\n !.............................................................................\n real(8):: times(patch%nt-1)\n real(8), dimension(order+1):: w\n integer:: i1, i2\n !-----------------------------------------------------------------------------\n if (verbose > 0) write(io_unit%log,*) patch%id, 'time_slices_t%derivative2'\n times = patch%t(patch%iit(1:patch%nt-1))\n call lagrange%deriv2_sequence_weights (patch%out_next, times, i1, i2, w, order)\n call weighted_sum (patch, times, w, i1, i2, mem, buffer)\nEND SUBROUTINE derivative2\n\n!===============================================================================\n!> Weighted sum of time slice values\n!===============================================================================\nSUBROUTINE weighted_sum (patch, times, w, i1, i2, mem, buffer)\n class(patch_t):: patch\n real(8), dimension(:):: times, w\n integer:: i1, i2\n real(kind=KindScalarVar), dimension(:,:,:,:):: mem\n real(kind=4), dimension(:,:,:):: buffer\n !.............................................................................\n integer:: i\n !-----------------------------------------------------------------------------\n if (verbose>0 .or. patch%id==id_debug) then\n write (io_unit%output,'(a,2i4,2x,10i4)') 'indices:', i1, i2, patch%iit(i1:i2)\n write (io_unit%output,'(a,f12.6,2x,10f14.6)') ' times:', patch%out_next, times(i1:i2)\n write (io_unit%output,'(a,f12.6,2x,10f14.3)') 'weights:', sum(w), w\n end if\n buffer = 0.0\n do i=i1,i2\n buffer = buffer + w(1+i-i1)*mem(:,:,:,i)\n end do\nEND SUBROUTINE weighted_sum\n\nEND MODULE time_slices_mod\n", "meta": {"hexsha": "e3cc6d25ffc126130a7fc0f191777a8c3c15b2cd", "size": 5618, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "interpolation/time_slices_mod.f90", "max_stars_repo_name": "applejwjcat/dispatch", "max_stars_repo_head_hexsha": "4fad06ee952de181f6c51b91f179d6396bdfb333", "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/time_slices_mod.f90", "max_issues_repo_name": "applejwjcat/dispatch", "max_issues_repo_head_hexsha": "4fad06ee952de181f6c51b91f179d6396bdfb333", "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/time_slices_mod.f90", "max_forks_repo_name": "applejwjcat/dispatch", "max_forks_repo_head_hexsha": "4fad06ee952de181f6c51b91f179d6396bdfb333", "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": 40.7101449275, "max_line_length": 90, "alphanum_fraction": 0.4716981132, "num_tokens": 1332, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.6839172714472617}} {"text": "!##############################################################################\n! MODULE Volume\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!##############################################################################\nmodule Volume\n\n implicit none\n\n ! module parameter\n real*8, parameter :: pi = 3.14159265358d0\n\n! separates variable declarations from subroutine and functions\ncontains\n\n\n ! for calculating volume of a sphere\n function vol(r)\n\n implicit none\n\n ! input and output variables\n real*8, intent(in) :: r\n real*8 :: vol\n\n ! calculation\n vol = 4d0/3d0*r**3*pi\n\n end function\n\nend module\n", "meta": {"hexsha": "112dc63544665ddd196746254da0109d2d5e1d37", "size": 876, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "complete/prog01/prog01_15/prog01_15m.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/prog01/prog01_15/prog01_15m.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/prog01/prog01_15/prog01_15m.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": 22.4615384615, "max_line_length": 79, "alphanum_fraction": 0.5114155251, "num_tokens": 197, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213799730775, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6839172645126256}} {"text": "! Print out the analytic solution for the homologous dust collapse problem,\n! from Colgate and White 1966, ApJ, 143, 626.\n! \n! This will yield r(t) as a function of t\n\nmodule constants_module\n\n implicit none\n\n ! fundamental constants\n double precision, parameter :: Gconst = 6.67428d-8 ! cm^3/g/s^2\n double precision, parameter :: pi = 3.14159265358979323846d0\n double precision, parameter :: SMALL = 1.d-20\n\n ! user-defined problem parameters\n double precision, parameter :: rho_0 = 1.d9\n double precision, parameter :: r_0 = 6.5d8\n\n ! we try to do equal timesteps, but eventually, the radius of the\n ! sphere is changing so quickly that we need to adjust the size of\n ! the timestep. The code will take nstep timesteps, with the \n ! initial timestep to be (t_f - t_i)/(nstep - 1). Once the radius\n ! begins to change significantly, we will begin halving the timestep\n ! as needed.\n\n integer :: nstep = 100 ! number of points to output\n double precision, parameter :: t_i = 1.d-3 ! initial output time\n double precision, parameter :: t_f = 0.1 ! final output time\n\nend module constants_module\n\n\nprogram analytic\n\n use constants_module\n\n implicit none\n\n ! local variables\n double precision :: r, r_guess, r_old, t\n integer :: i, n\n double precision :: dt\n double precision :: dr, f, dfdr\n\n logical :: converged\n double precision, parameter :: TOL = 1.d-6\n integer, parameter :: max_iter = 25\n\n ! compute the initial timestep\n dt = (t_f - t_i)/(nstep - 1)\n\n r_old = r_0\n\n t = t_i\n\n ! main timestepping loop\n do i = 1, nstep\n\n ! find the analytic solution via Newton iteration\n converged = .false.\n r_guess = 0.95*r_old\n\n do n = 1, max_iter\n dr = -f(r_guess,t)/dfdr(r_guess,t)\n\n ! we have lots of sqrt(1 - r/r_0), so r(t) has to be less than r_0\n if (r_guess + dr > r_0) then\n r_guess = 0.5d0*(r_guess + r_0)\n else\n r_guess = r_guess + dr\n endif\n\n if (abs(dr/r_guess) < TOL) then\n converged = .true.\n exit\n endif\n\n enddo\n\n if (.not. converged) then\n print *, \"ERROR: Newton iterations failed to converge\"\n stop\n endif\n\n ! we converged, set the new radius of the sphere\n r = r_guess\n\n print *, t, r\n\n ! toward the end, we need smaller timesteps, if the radius is\n ! changing significantly, halve the timestep\n if (abs(r - r_old)/r_old > 0.2) then\n dt = 0.5*dt\n endif\n\n ! store the old radius for the timestep check next cycle\n r_old = r\n\n ! update the desired output time\n t = t + dt\n\n enddo\n\nend program analytic\n\n\n\n\nfunction f(r,t) result (func)\n\n use constants_module\n\n implicit none\n \n double precision, intent(in) :: r, t\n double precision :: func\n\n ! the analytic solution from Colgate and White, Eq. 5 (with everything moved\n ! onto the LHS). We use SMALL to prevent against zeros in some places.\n func = sqrt(8.d0*pi*Gconst*rho_0/3.d0)*t - &\n sqrt(1.d0 - r/r_0)*sqrt(r/r_0) - asin(sqrt(1.0 - r/r_0 + SMALL))\n\n return\nend function f\n\n\n\nfunction dfdr(r,t) result (dfuncdr)\n\n use constants_module\n\n implicit none\n \n double precision, intent(in) :: r, t\n double precision :: dfuncdr\n\n ! the derivative (wrt x) of the analytic function f, defined above.\n ! We use SMALL to prevent against zeros in some places.\n dfuncdr = (0.5d0/r_0)*(-sqrt(1.d0 - r/r_0 + SMALL)/sqrt(r/r_0) + &\n sqrt(r/r_0)/sqrt(1 - r/r_0 + SMALL) + &\n 1.d0/(sqrt(r/r_0)*sqrt(1.d0 - r/r_0 + SMALL)))\n\n\n return\nend function dfdr\n\n\n \n", "meta": {"hexsha": "d1a4093b26b16de3a20b8ad277118aaa1a0e03c7", "size": 3629, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Diagnostics/DustCollapse/analytic.f90", "max_stars_repo_name": "MargotF/Castro", "max_stars_repo_head_hexsha": "5cdb549af422ef44c9b1822d0fefe043b3533c57", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 178, "max_stars_repo_stars_event_min_datetime": "2017-05-03T18:07:03.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T22:34:53.000Z", "max_issues_repo_path": "Diagnostics/DustCollapse/analytic.f90", "max_issues_repo_name": "MargotF/Castro", "max_issues_repo_head_hexsha": "5cdb549af422ef44c9b1822d0fefe043b3533c57", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": 1334, "max_issues_repo_issues_event_min_datetime": "2017-05-04T14:23:24.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T00:12:06.000Z", "max_forks_repo_path": "Diagnostics/DustCollapse/analytic.f90", "max_forks_repo_name": "MargotF/Castro", "max_forks_repo_head_hexsha": "5cdb549af422ef44c9b1822d0fefe043b3533c57", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": 86, "max_forks_repo_forks_event_min_datetime": "2017-06-12T15:27:51.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-09T22:21:44.000Z", "avg_line_length": 24.355704698, "max_line_length": 78, "alphanum_fraction": 0.6324056214, "num_tokens": 1075, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636754, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6839172534657079}} {"text": " SUBROUTINE ALG29 (Y,X,FXY,N)\r\nC\r\n DIMENSION Y(3),X(3),FXY(3)\r\nC\r\n X1=(X(3)+X(2))*(Y(3)-Y(2))/(X(3)-X(2))\r\n FXY(2)=X1/(X(3)-X(1))\r\n N2=N-2\r\n DO 100 J=3,N2\r\n X2=(X(J+1)+X(J))*(Y(J+1)-Y(J))/(X(J+1)-X(J))\r\n FXY(J)=(X2-X1)/(X(J+1)-X(J-1))\r\n100 X1=X2\r\n FXY(N-1)=-X1/(X(N)-X(N-2))\r\n FXY(1)=FXY(2)-(FXY(3)-FXY(2))/(X(3)-X(2))*(X(2)-X(1))\r\n FXY(N)=FXY(N-1)+(FXY(N-1)-FXY(N-2))/(X(N-1)-X(N-2))*(X(N)-X(N-1))\r\n RETURN\r\n END\r\n", "meta": {"hexsha": "d87283533fc2c7e221e0c7da8ceb1d47a90c5898", "size": 482, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "mis/alg29.f", "max_stars_repo_name": "ldallolio/NASTRAN-95", "max_stars_repo_head_hexsha": "6d2c175f5b53ebaec4ba2b5186f7926ef9d0ed47", "max_stars_repo_licenses": ["NASA-1.3"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2016-01-09T14:33:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-18T11:51:42.000Z", "max_issues_repo_path": "mis/alg29.f", "max_issues_repo_name": "gassive/NASTRAN95", "max_issues_repo_head_hexsha": "98cb3acaa7990d639360601648498834c7782056", "max_issues_repo_licenses": ["NASA-1.3"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2016-01-17T07:30:19.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-06T19:37:44.000Z", "max_forks_repo_path": "mis/alg29.f", "max_forks_repo_name": "gassive/NASTRAN95", "max_forks_repo_head_hexsha": "98cb3acaa7990d639360601648498834c7782056", "max_forks_repo_licenses": ["NASA-1.3"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-04-07T20:51:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T14:16:01.000Z", "avg_line_length": 28.3529411765, "max_line_length": 72, "alphanum_fraction": 0.3941908714, "num_tokens": 254, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636754, "lm_q2_score": 0.7606506418255927, "lm_q1q2_score": 0.683917248587212}} {"text": "\r\nsubroutine CalcEnergy(Pos, M, L, rc, PEnergy, Dim, NAtom)\r\n implicit none\r\n integer, intent(in) :: M, Dim, NAtom\r\n real(8), intent(in), dimension(0:NAtom-1, 0:Dim-1) :: Pos\r\n real(8), intent(in) :: L, rc\r\n real(8), intent(out) :: PEnergy\r\n real(8), parameter :: k = 3000., r0 = 1.\r\n integer:: i, j\r\n real(8) :: kfac, d2, sep, disp, shiftval, rc2, id6, id2, id12\r\n real(8), dimension(Dim) :: rij, Posi\r\n \r\n\r\n !Assign initially zeros to the force array and potential energy\r\n PEnergy = 0.\r\n rc2 = rc**2\r\n\r\n !Precompute constants such as LJ shift value up here\r\n kfac = k/2.\r\n id6 = 1./rc**6\r\n shiftval = 4*(id6**2 - id6)\r\n\r\n\r\n do i=0, NAtom - 1\r\n !store Pos(i,:) in a temporary array for faster access in j looop\r\n Posi = Pos(i,:)\r\n do j = i+1, NAtom - 1\r\n !compute initial rij\r\n rij = Pos(j,:) - Posi\r\n !Apply minimum image convention\r\n rij = rij - L*dnint(rij / L)\r\n\r\n !Do bonded calculation\r\n if ( j == i+1 .and. mod(j, M)> 0) then\r\n !Compute scalar separation\r\n sep = sqrt( sum( rij * rij ) )\r\n !Compute displacement relative to preferred separation\r\n disp = sep - r0\r\n !Calculate energy\r\n PEnergy = PEnergy + kfac * disp*disp\r\n else !Do nonbonded calculation\r\n !compute scalar distance\r\n d2 = sum(rij*rij)\r\n !Check against cutoff\r\n if ( d2 > rc2) then \r\n cycle\r\n end if\r\n id2 = 1./d2 !inverse squared distance\r\n id6 = id2 * id2 * id2 !inverse sixth distance\r\n id12 = id6 * id6 !inverse twelfth distance\r\n PEnergy = Penergy + 4. * (id12 - id6) + shiftval\r\n\r\n !end nonbonded calculation\r\n endif\r\n enddo\r\n enddo\r\nend subroutine\r\n\r\n\r\n!I AM WRITING THIS PART\r\n!added atomnum argument for atom for which to calculate interaction energy\r\nsubroutine CalcInteractionEnergy(Pos, atomnum, M, L, rc, PEnergy, Dim, NAtom)\r\n implicit none\r\n integer, intent(in) :: M, Dim, NAtom, atomnum\r\n real(8), intent(in), dimension(0:NAtom-1, 0:Dim-1) :: Pos\r\n real(8), intent(in) :: L, rc\r\n real(8), intent(out) :: PEnergy\r\n real(8), parameter :: k = 3000., r0 = 1.\r\n integer:: j\r\n real(8) :: kfac, d2, sep, disp, shiftval, rc2, id6, id2, id12\r\n real(8), dimension(Dim) :: rij, Posi\r\n \r\n\r\n !Assign initially zeros to the force array and potential energy\r\n PEnergy = 0.\r\n rc2 = rc**2\r\n\r\n !Precompute constants such as LJ shift value up here\r\n kfac = k/2.\r\n id6 = 1./rc**6\r\n shiftval = 4*(id6**2 - id6)\r\n \r\n !store Pos(i,:) in a temporary array for faster access in j looop\r\n Posi = Pos(atomnum,:)\r\n do j = 0, NAtom - 1\r\n if (j==atomnum) cycle \r\n !compute initial rij\r\n rij = Pos(j,:) - Posi\r\n !Apply minimum image convention\r\n rij = rij - L*dnint(rij / L)\r\n !Do bonded calculation\r\n !Note that each trial movement may involves 2 bond length changes.\r\n if ( j == atomnum+1 .and. mod(j, M)> 0) then\r\n !Compute scalar separation\r\n sep = sqrt( sum( rij * rij ) )\r\n !Compute displacement relative to preferred separation\r\n disp = sep - r0\r\n !Calculate energy\r\n PEnergy = PEnergy + kfac * disp*disp\r\n else if (j == atomnum-1 .and. mod(j,M) < M-1) then\r\n !Compute scalar separation\r\n sep = sqrt( sum( rij * rij ) )\r\n !Compute displacement relative to preferred separation\r\n disp = sep - r0\r\n !Calculate energy\r\n PEnergy = PEnergy + kfac * disp*disp\r\n else !Do nonbonded calculation\r\n !compute scalar distance\r\n d2 = sum(rij*rij)\r\n !Check against cutoff\r\n if ( d2 > rc2) cycle\r\n id2 = 1./d2 !inverse squared distance\r\n id6 = id2 * id2 * id2 !inverse sixth distance\r\n id12 = id6 * id6 !inverse twelfth distance\r\n PEnergy = Penergy + 4. * (id12 - id6) + shiftval\r\n\r\n !end nonbonded calculation\r\n endif\r\n enddo\r\nend subroutine\r\n\r\n! a mutant version of CalcInteractionEnergy \r\n! the atom \"atomnum\" has an extra virtual displacement parameter.\r\nsubroutine CalcVirtualEnergy(Pos, atomnum, virtualDisp, M, L, rc, PEnergy, Dim, NAtom)\r\n implicit none\r\n integer, intent(in) :: M, Dim, NAtom, atomnum\r\n real(8), intent(in), dimension(0:NAtom-1, 0:Dim-1) :: Pos\r\n real(8), intent(in), dimension(0:Dim-1) :: virtualDisp\r\n real(8), intent(in) :: L, rc\r\n real(8), intent(out) :: PEnergy\r\n real(8), parameter :: k = 3000., r0 = 1.\r\n integer:: j\r\n real(8) :: kfac, d2, sep, disp, shiftval, rc2, id6, id2, id12\r\n real(8), dimension(Dim) :: rij, Posi\r\n \r\n\r\n !Assign initially zeros to the force array and potential energy\r\n PEnergy = 0.\r\n rc2 = rc**2\r\n\r\n !Precompute constants such as LJ shift value up here\r\n kfac = k/2.\r\n id6 = 1./rc**6\r\n shiftval = 4*(id6**2 - id6)\r\n \r\n !store Pos(i,:) in a temporary array for faster access in j looop\r\n Posi = Pos(atomnum,:) + virtualDisp\r\n do j = 0, NAtom - 1\r\n if (j==atomnum) cycle \r\n !compute initial rij\r\n rij = Pos(j,:) - Posi\r\n !Apply minimum image convention\r\n rij = rij - L*dnint(rij / L)\r\n !Do bonded calculation\r\n if ( j == atomnum+1 .and. mod(j, M)> 0) then\r\n !Compute scalar separation\r\n sep = sqrt( sum( rij * rij ) )\r\n !Compute displacement relative to preferred separation\r\n disp = sep - r0\r\n !Calculate energy\r\n PEnergy = PEnergy + kfac * disp*disp\r\n else if (j == atomnum-1 .and. mod(j,M) < M-1) then\r\n !Compute scalar separation\r\n sep = sqrt( sum( rij * rij ) )\r\n !Compute displacement relative to preferred separation\r\n disp = sep - r0\r\n !Calculate energy\r\n PEnergy = PEnergy + kfac * disp*disp\r\n else !Do nonbonded calculation\r\n !compute scalar distance\r\n d2 = sum(rij*rij)\r\n !Check against cutoff\r\n if ( d2 > rc2) cycle\r\n id2 = 1./d2 !inverse squared distance\r\n id6 = id2 * id2 * id2 !inverse sixth distance\r\n id12 = id6 * id6 !inverse twelfth distance\r\n PEnergy = Penergy + 4. * (id12 - id6) + shiftval\r\n\r\n !end nonbonded calculation\r\n endif\r\n enddo\r\nend subroutine\r\n\r\n\r\nsubroutine CalcEnergyForces(Pos, M, L, rc, PEnergy, Forces, Dim, NAtom)\r\n implicit none\r\n integer, intent(in) :: M, Dim, NAtom\r\n real(8), intent(in), dimension(0:NAtom-1, 0:Dim-1) :: Pos\r\n real(8), intent(in) :: L, rc\r\n real(8), intent(out) :: PEnergy\r\n real(8), intent(inout), dimension(0:NAtom-1, 0:Dim-1) :: Forces\r\n!f2py intent(in, out, inplace) :: Forces\r\n real(8), parameter :: k = 3000., r0 = 1.\r\n integer :: i, j\r\n real(8) :: kfac, d2, sep, disp, shiftval, rc2, id6, id2, id12\r\n real(8), dimension(Dim) :: rij, Fij, Posi\r\n \r\n\r\n !Assign initially zeros to the force array and potential energy\r\n Forces = 0.\r\n PEnergy = 0.\r\n rc2 = rc**2\r\n\r\n !Precompute constants such as LJ shift value up here\r\n kfac = k/2.\r\n id6 = 1./rc**6\r\n shiftval = 4.*(id6**2 - id6)\r\n\r\n\r\n do i=0, NAtom - 1\r\n !store Pos(i,:) in a temporary array for faster access in j looop\r\n Posi = Pos(i,:)\r\n do j = i+1, NAtom - 1\r\n !compute initial rij\r\n rij = Pos(j,:) - Posi\r\n !Apply minimum image convention\r\n rij = rij - L*dnint(rij / L)\r\n\r\n !Do bonded calculation\r\n if ( j == i+1 .and. mod(j, M)> 0) then\r\n !Compute scalar separation\r\n sep = sqrt( sum( rij * rij ) )\r\n !Compute displacement relative to preferred separation\r\n disp = sep - r0\r\n !Calculate energy\r\n PEnergy = PEnergy + kfac * disp*disp\r\n !Calculate force: - k*displacement in direction of rij\r\n Fij = k * ( disp ) * rij/sep\r\n Forces(i,:) = Forces(i,:) + Fij\r\n Forces(j,:) = Forces(j,:) - Fij\r\n else !Do nonbonded calculation\r\n !compute scalar distance\r\n d2 = sum(rij*rij)\r\n !Check against cutoff\r\n if ( d2 > rc2) then \r\n cycle\r\n end if\r\n id2 = 1./d2 !inverse squared distance\r\n id6 = id2 * id2 * id2 !inverse sixth distance\r\n id12 = id6 * id6 !inverse twelfth distance\r\n PEnergy = Penergy + 4. * (id12 - id6) + shiftval\r\n Fij = rij * (-48. * id12 + 24. * id6) * id2\r\n Forces(i,:) = Forces(i,:) + Fij\r\n Forces(j,:) = Forces(j,:) - Fij\r\n\r\n !end nonbonded calculation\r\n endif\r\n enddo\r\n enddo\r\nend subroutine\r\n", "meta": {"hexsha": "cd992732b26defbc748ed9d5b4002a37d688324b", "size": 9289, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uci-pharmsci/assignments/MC/mclib.f90", "max_stars_repo_name": "inferential/drug-computing", "max_stars_repo_head_hexsha": "25ff2f04b2a1f7cb71c552f62e722edb26cc297f", "max_stars_repo_licenses": ["CC-BY-4.0", "MIT"], "max_stars_count": 103, "max_stars_repo_stars_event_min_datetime": "2017-10-21T18:49:01.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T22:05:21.000Z", "max_issues_repo_path": "uci-pharmsci/assignments/MC/mclib.f90", "max_issues_repo_name": "inferential/drug-computing", "max_issues_repo_head_hexsha": "25ff2f04b2a1f7cb71c552f62e722edb26cc297f", "max_issues_repo_licenses": ["CC-BY-4.0", "MIT"], "max_issues_count": 29, "max_issues_repo_issues_event_min_datetime": "2017-10-23T20:57:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-15T21:57:09.000Z", "max_forks_repo_path": "uci-pharmsci/assignments/MC/mclib.f90", "max_forks_repo_name": "inferential/drug-computing", "max_forks_repo_head_hexsha": "25ff2f04b2a1f7cb71c552f62e722edb26cc297f", "max_forks_repo_licenses": ["CC-BY-4.0", "MIT"], "max_forks_count": 36, "max_forks_repo_forks_event_min_datetime": "2018-01-18T20:22:29.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-16T13:08:09.000Z", "avg_line_length": 37.0079681275, "max_line_length": 87, "alphanum_fraction": 0.5182473894, "num_tokens": 2588, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625050654263, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6838048189622606}} {"text": " SUBROUTINE SOLVSMBE(SMV1,SMV2,SMA11,SMA22,SMA1,SMA2,SMB11,SMB22) \n REAL::SMA12,SMA2,SMA21,SMA1,SMDET,SMA11,SMA22,SMB11,SMB22\n REAL::SMV1,SMV2\nC SOLVE 2X2 MATRIX \nC CHANGE RECORD \nC \n SMA12 = -SMA2 \n SMA21 = -SMA1 \n SMDET = SMA11*SMA22 - SMA12*SMA21 \n IF(SMDET.EQ.0.0)THEN \n PRINT*, 'SINGULAR MATRIX: A11, A12, A21, A22, B11, B22' \n PRINT*, SMA11,SMA12,SMA21,SMA22,SMB11,SMB22 \n STOP \n ENDIF \n SMDET = 1.0 / SMDET \n SMV1 = (SMB11*SMA22 - SMB22*SMA12) * SMDET \n SMV2 = (SMB22*SMA11 - SMB11*SMA21) * SMDET \n RETURN \n END \n\n", "meta": {"hexsha": "bfa834688c65636f3e6c684dc883da7fcf24d449", "size": 624, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "EFDC_src/SOLVSMBE.f", "max_stars_repo_name": "T-Carlotto/SW2D-EFDC", "max_stars_repo_head_hexsha": "7b01a41a308cb79db569a0e6291fe40797f3ef28", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 32, "max_stars_repo_stars_event_min_datetime": "2018-03-31T22:19:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-14T01:35:23.000Z", "max_issues_repo_path": "EFDC_src/SOLVSMBE.f", "max_issues_repo_name": "T-Carlotto/SW2D-EFDC", "max_issues_repo_head_hexsha": "7b01a41a308cb79db569a0e6291fe40797f3ef28", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-04-02T06:13:13.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-10T07:15:07.000Z", "max_forks_repo_path": "EFDC_src/SOLVSMBE.f", "max_forks_repo_name": "T-Carlotto/SW2D-EFDC", "max_forks_repo_head_hexsha": "7b01a41a308cb79db569a0e6291fe40797f3ef28", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2018-06-27T02:55:23.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-09T07:51:23.000Z", "avg_line_length": 29.7142857143, "max_line_length": 72, "alphanum_fraction": 0.5769230769, "num_tokens": 260, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475778774728, "lm_q2_score": 0.724870282120402, "lm_q1q2_score": 0.6838046249136417}} {"text": "!C++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n!C Projet MICO - Newton Raphson (ver. FORTRAN 21.03.95)\n!C++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\nsubroutine newtonr(x, y, P)\n\n implicit none\n\n integer :: i, nite, compt\n logical :: converged\n double precision :: h, a, b, Vh, Vv, E, Lh, Lv\n double precision :: TOL, u, v\n double precision :: lambda\n double precision, intent(inout) :: P(101), x(101), y(101)\n double precision :: R(2), uu(2)\n double precision :: norm, F(2), Kt(2, 2), Du(2), MAT(2)\n double precision :: invKt(2, 2), dtmKt\n\n h = 40.\n a = 24.\n b = 40.\n Vh = 160.\n Vv = 200.\n E = 70000.\n Lh = 2*a\n Lv = sqrt(h**2 + (b + a)**2)\n TOL = 1e-5\n i = 0\n lambda = 0.\n uu(1) = 0.\n uu(2) = 0.\n R(1) = 9000. ! maximum force\n R(2) = 0.\n\n !C ----converged principale----\n\n do compt = 0, 100\n lambda = compt/100.\n\n ! Newton-Raphson\n converged = .false.\n nite = 0\n do while (.not. converged)\n u = uu(1)\n v = uu(2)\n nite = nite + 1\n if (nite > 200) then\n converged = .true.\n print *, \"WARNING: max nb of iterations reached!\"\n end if\n\n F(1) = (E*Vv/Lv**4)*(v*v + u*u - 2*h*v + 2*u*(a + b))*(v - h)\n F(2) = (Vv/Lv**4)*(v**2 + u**2 - 2*h*v + 2*u*(a + b))*(u + a + b) &\n + (8*Vh/Lh**4)*(u**2 + 2*a*u)*(u + a)\n\n if (lambda /= 0) then\n norm = dsqrt((lambda*R(1) - F(1))**2 + (lambda*R(2) - F(2))**2) &\n /abs(lambda)/dsqrt(R(1)**2 + R(2)**2)\n ! write(*,*)norm\n else\n norm = 0\n end if\n\n if (norm > TOL) then\n Kt(1, 1) = E*Vv/(Lv**4)*(2*u + 2*(a + b))*(v - h)\n Kt(1, 2) = E*Vv/(Lv**4)*((v**2 + u**2 - 2*v*h + 2*u*(a + b)) &\n + (v - h)*(2*v - 2*h))\n Kt(2, 1) = Vv/(Lv**4)*((v**2 + u**2 - 2*h*v + 2*u*(a + b)) &\n + (u + a + b)*(2*u + 2*(a + b))) &\n + 8*Vh/(Lh**4)*((2*u + 2*a)*(u + a) + (u**2 + 2*a*u))\n Kt(2, 2) = Vv/(Lv**4)*(u + a + b)*(2*v - 2*h)\n\n MAT(1) = lambda*R(1) - F(1)\n MAT(2) = lambda*R(2) - F(2)\n \n dtmKt = Kt(1, 1)*Kt(2, 2) - Kt(1, 2)*Kt(2, 1)\n \n invKt(1, 1) = Kt(2, 2)/dtmKt\n invKt(2, 2) = Kt(1, 1)/dtmKt\n invKt(1, 2) = -1*Kt(1, 2)/dtmKt\n invKt(2, 1) = -1*Kt(2, 1)/dtmKt\n\n Du(1) = invKt(1, 1)*MAT(1) + invKt(1, 2)*MAT(2)\n Du(2) = invKt(2, 1)*MAT(1) + invKt(2, 2)*MAT(2)\n\n uu(1) = uu(1) + Du(1)\n uu(2) = uu(2) + Du(2)\n else\n converged = .true.\n end if\n end do\n\n i = i + 1\n x(i) = uu(2)\n y(i) = uu(1)\n P(i) = lambda*R(1)\n end do\n\nend subroutine newtonr\n", "meta": {"hexsha": "fc70c3188112408e9c249bedb6bb28389d51327c", "size": 3083, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "student/mico/newtonr.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/mico/newtonr.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/mico/newtonr.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": 30.83, "max_line_length": 81, "alphanum_fraction": 0.3483619851, "num_tokens": 1169, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465062370313, "lm_q2_score": 0.731058584489497, "lm_q1q2_score": 0.6837930928568406}} {"text": "\n! Version 1.4\n\n! This file collects all the various FM routines from the \"More sample programs\" page on the\n! FM web site. See that page for the programs that call these routines and illustrate their\n! use. Here is a list of the user-callable routines in this file (see the documentation at\n! the top of each routine for explanation of each of the arguments to the routines).\n\n! 1. Find a minimum or maximum function value of a real function of one variable.\n\n! SUBROUTINE FM_FIND_MIN(MIN_OR_MAX,AX,BX,TOL,XVAL,FVAL,F,NF,KPRT,KW)\n\n! 2. Nth derivative of a real function of one variable.\n\n! FUNCTION FM_FPRIME(N,A,F,NF)\n\n! 3. Nth derivative of a complex function of one variable.\n\n! FUNCTION ZM_FPRIME(N,A,F,NF)\n\n! 4. Definite integral for a real function of one variable.\n\n! SUBROUTINE FM_INTEGRATE(F,N,A,B,TOL,RESULT,KPRT,NW)\n\n! 5. Inverse matrix for a real NxN matrix.\n\n! SUBROUTINE FM_INVERSE(A,N,B,DET)\n\n! 6. Inverse matrix for a complex NxN matrix.\n\n! SUBROUTINE ZM_INVERSE(A,N,B,DET)\n\n! 7. Generate the real linear system of normal equations for a least square fit.\n\n! SUBROUTINE FM_GENEQ(F,A,B,K,X,Y,N)\n\n! 8. Solve a real NxN linear system of equations.\n\n! SUBROUTINE FM_LIN_SOLVE(A,X,B,N,DET)\n\n! 9. Solve a complex NxN linear system of equations.\n\n! SUBROUTINE ZM_LIN_SOLVE(A,X,B,N,DET)\n\n! 10. Solve a real differential equation (initial value problem).\n\n! SUBROUTINE FM_RK14(A,B,N_ORDER,N_FUNCTION,S,TOL,S1)\n\n! 11. Find a root of a real function of one variable.\n\n! SUBROUTINE FM_SECANT(AX,BX,F,NF,ROOT,KPRT,KU)\n\n! 12. Find a root of a complex function of one variable.\n\n! SUBROUTINE ZM_SECANT(AX,BX,F,NF,ROOT,KPRT,KU)\n\n! 13. Find NR roots of a complex function of one variable.\n\n! SUBROUTINE ZM_ROOTS(NR,F,NF,N_FOUND,LIST_OF_ROOTS,KPRT,KU)\n\n\n\n SUBROUTINE FM_FIND_MIN(MIN_OR_MAX,AX,BX,TOL,XVAL,FVAL,F,NF,KPRT,KW)\n USE FMZM\n\n! MIN_OR_MAX having value 1 means minimize the function, otherwise maximize.\n! AX, BX define the endpoints of an interval in which the search takes place.\n! TOL is the tolerance for the minimum. Usually TOL should be no less than\n! sqrt(epsilon(ax)), meaning the x-coordinate XVAL of the extreme point will\n! be accurate to only about half the digits carried. The y-coordinate FVAL\n! should be accurate to nearly full precision.\n! This happens because the typical graph is nearly parabolic near the minimum,\n! and within sqrt(epsilon(ax)) of the minimum all the function values are\n! essentially identical at the current precision.\n! XVAL is returned as the value of X that minimizes (or maximizes) function F(X,NF).\n! It is a relative extreme point, and may not be the global extreme point if the\n! function has more than one extremum on the interval.\n! FVAL is returned as the function value at XVAL.\n! F(X,NF) is the function to be minimized. X is the argument and NF is the function\n! number, in case several functions are defined within F.\n! KPRT controls printing within the routine:\n! KPRT = 0 for no output\n! KPRT = 1 for the approximation to the root and the function\n! value to be printed once at the end of the routine.\n! KPRT = 2 for the approximation to the root and the function\n! value to be printed each iteration.\n! KW is the unit number for output.\n\n! The method used is a combination of golden section search and successive parabolic interpolation.\n! Convergence is never much slower than that for a fibonacci search. If f has a continuous second\n! derivative which is positive at the minimum (which is not at ax or bx), then convergence is\n! superlinear, and usually of the order of about 1.324....\n\n! The function f is never evaluated at two points closer together than eps*abs(FVAL)+(tol/3),\n! where eps is approximately the square root of the relative machine precision. If f is a\n! unimodal function and the computed values of f are always unimodal when separated by at least\n! eps*abs(x)+(tol/3), then FVAL approximates the abscissa of the global minimum of f on the\n! interval ax,bx with an error less than 3*eps*abs(FVAL)+tol. If f is not unimodal, then FVAL\n! may approximate a local, but perhaps non-global, minimum to the same accuracy.\n\n! This routine is a slightly modified translation of function FVAL from netlib, which was adapted\n! from the algol 60 procedure localmin given by Richard Brent in Algorithms For Minimization\n! Without Derivatives, Prentice-Hall (1973).\n\n IMPLICIT NONE\n CHARACTER(80) :: ST1,ST2\n INTEGER :: J,MINV,MIN_OR_MAX,NF,KPRT,KW\n TYPE (FM) :: AX,BX,TOL,XVAL,FVAL\n TYPE (FM), EXTERNAL :: F\n\n TYPE (FM), SAVE :: A, B, C, D, E, EPS, XM, P, Q, R, T2, U, V, W, FU, FV, FW, FX, X, TOL1, TOL3\n\n MINV = 1\n IF (MIN_OR_MAX /= 1) MINV = -1\n\n! C is the squared inverse of the golden ratio.\n\n C = (3-SQRT(TO_FM('5.0D0')))/2\n\n! EPS is approximately the square root of the relative machine precision.\n\n EPS = EPSILON(AX)\n TOL1 = EPS + 1\n EPS = SQRT(EPS)\n\n A = MIN(AX,BX)\n B = MAX(AX,BX)\n V = A + C*(B-A)\n W = V\n X = V\n E = 0\n FX = F(X,NF)*MINV\n FV = FX\n FW = FX\n TOL3 = TOL/3\n J = 1\n\n IF (KPRT == 2) THEN\n WRITE (KW,*) ' '\n IF (MIN_OR_MAX == 1) THEN\n WRITE (KW,*) ' FM_FIND_MIN. Begin trace of all iterations.'\n WRITE (KW,*) ' Search for a relative minimum on the interval'\n WRITE (KW,\"(13X,ES20.10,' to ',ES20.10/)\") TO_DP(AX),TO_DP(BX)\n ELSE\n WRITE (KW,*) ' FM_FIND_MIN. Begin trace of all iterations.'\n WRITE (KW,*) ' Search for a relative maximum on the interval'\n WRITE (KW,\"(13X,ES20.10,' to ',ES20.10/)\") TO_DP(AX),TO_DP(BX)\n ENDIF\n ST1 = FM_FORMAT('ES35.25',X)\n ST2 = FM_FORMAT('ES35.25',FX*MINV)\n WRITE (KW,\"(' J =',I3,4X,' x = ',A)\") J,TRIM(ST1)\n WRITE (KW,\"(' ',3X,4X,'f(x) = ',A/)\") TRIM(ST2)\n ENDIF\n\n! The main loop starts here.\n\n 110 XM = (A+B)/2\n TOL1 = EPS*ABS(X) + TOL3\n T2 = 2*TOL1\n\n! Check the stopping criterion.\n\n IF (ABS(X-XM) <= (T2-(B-A)/2)) GO TO 160\n P = 0\n Q = 0\n R = 0\n IF (ABS(E) > TOL1) THEN\n R = (X-W)*(FX-FV) ! Fit a parabola.\n Q = (X-V)*(FX-FW)\n P = (X-V)*Q-(X-W)*R\n Q = 2*(Q-R)\n IF (Q > 0) THEN\n P = -P\n ELSE\n Q = -Q\n ENDIF\n R = E\n E = D\n ENDIF\n\n IF ((ABS(P) >= ABS(Q*R/2)) .OR. (P <= Q*(A-X)) .OR. (P >= Q*(B-X))) GO TO 120\n\n! Make a parabolic-interpolation step.\n\n D = P/Q\n U = X + D\n\n! f must not be evaluated too close to ax or bx.\n\n IF (((U-A) >= T2) .AND. ((B-U) >= T2)) GO TO 130\n D = TOL1\n IF (X >= XM) D = -D\n GO TO 130\n\n! Make a golden-section step.\n\n 120 IF (X < XM) THEN\n E = B - X\n ELSE\n E = A - X\n ENDIF\n D = C*E\n\n! f must not be evaluated too close to x.\n\n 130 IF (ABS(D) >= TOL1) THEN\n U = X + D\n ELSE\n IF (D > 0) THEN\n U = X + TOL1\n ELSE\n U = X - TOL1\n ENDIF\n ENDIF\n FU = F(U,NF)*MINV\n\n J = J + 1\n IF (KPRT == 2) THEN\n ST1 = FM_FORMAT('ES35.25',U)\n ST2 = FM_FORMAT('ES35.25',FU*MINV)\n WRITE (KW,\"(' J =',I3,4X,' x = ',A)\") J,TRIM(ST1)\n WRITE (KW,\"(' ',3X,4X,'f(x) = ',A/)\") TRIM(ST2)\n ENDIF\n\n! update a, b, v, w, and x.\n\n IF (FX <= FU) THEN\n IF (U < X) THEN\n A = U\n ELSE\n B = U\n ENDIF\n ENDIF\n IF (FU > FX) GO TO 140\n IF (U < X) THEN\n B = X\n ELSE\n A = X\n ENDIF\n V = W\n FV = FW\n W = X\n FW = FX\n X = U\n FX = FU\n GO TO 110\n\n 140 IF ((FU > FW) .AND. (W /= X)) GO TO 150\n V = W\n FV = FW\n W = U\n FW = FU\n GO TO 110\n\n 150 IF ((FU > FV) .AND. (V /= X) .AND. (V /= W)) GO TO 110\n V = U\n FV = FU\n GO TO 110\n\n! end of main loop\n\n 160 XVAL = X\n FVAL = FX*MINV\n\n IF (KPRT >= 1) THEN\n IF (KPRT == 1) WRITE (KW,*) ' '\n IF (MIN_OR_MAX == 1) THEN\n WRITE (KW,\"(' FM_FIND_MIN. Function ',I3,I6,' iterations. A relative minimum\"// &\n \" on interval'/13X,ES20.10,' to ',ES20.10,' is')\") &\n NF,J,TO_DP(AX),TO_DP(BX)\n ST1 = FM_FORMAT('ES35.25',XVAL)\n ST2 = FM_FORMAT('ES35.25',FVAL)\n WRITE (KW,\"(15X,' x = ',A)\") TRIM(ST1)\n WRITE (KW,\"(15X,' f(x) = ',A)\") TRIM(ST2)\n ELSE\n WRITE (KW,\"(' FM_FIND_MIN. Function ',I3,I6,' iterations. A relative maximum\"// &\n \" on interval'/13X,ES20.10,' to ',ES20.10,' is')\") &\n NF,J,TO_DP(AX),TO_DP(BX)\n ST1 = FM_FORMAT('ES35.25',XVAL)\n ST2 = FM_FORMAT('ES35.25',FVAL)\n WRITE (KW,\"(15X,' x = ',A)\") TRIM(ST1)\n WRITE (KW,\"(15X,' f(x) = ',A)\") TRIM(ST2)\n ENDIF\n WRITE (KW,*) ' '\n ENDIF\n\n END SUBROUTINE FM_FIND_MIN\n\n FUNCTION FM_FPRIME(N,A,F,NF) RESULT (RETURN_VALUE)\n USE FMVALS\n USE FMZM\n IMPLICIT NONE\n\n! This routine finds the Nth derivative of F(X,NF), evaluated at A.\n! NF is passed on to function F to indicate which function to use in cases where several\n! different functions may be defined there.\n\n! F must be defined in an interval containing A, so that F can be sampled on both sides of A.\n\n! N may be zero, so that in cases where F suffers cancellation error at A, an accurate\n! function value is returned.\n\n! FM_FPRIME tries to return full accuracy for the derivative, by raising precision above\n! the user's level and using difference formulas.\n\n TYPE (FM) :: RETURN_VALUE, A\n TYPE (FM), EXTERNAL :: F\n INTEGER :: J, K, KWARN_SAVE, NDSAVE, N, NF\n TYPE (FM), SAVE :: D1, D2, F1, F2, H, TOL, TOL2, X1\n\n! Raise precision slightly.\n\n NDSAVE = NDIG\n NDIG = NDIG + NGRD52\n CALL FM_EQU(A,X1,NDSAVE,NDIG)\n KWARN_SAVE = KWARN\n KWARN = 0\n\n D2 = 0\n F1 = F(X1,NF)\n IF (F1 /= 0) THEN\n CALL FM_ULP(F1,TOL)\n ELSE\n TOL = EPSILON(TO_FM(1))\n ENDIF\n TOL = ABS(TOL)\n\n! Check for a legal function value.\n\n IF (IS_UNKNOWN(F1) .OR. IS_OVERFLOW(F1) .OR. IS_UNDERFLOW(F1) .OR. N < 0) THEN\n D2 = TO_FM(' UNKNOWN ')\n GO TO 110\n ENDIF\n F2 = F1\n\n! Loop at increasing precision until the difference formula is accurate.\n\n DO J = 1, 100\n\n NDIG = 2*NDIG\n\n! Define the variables used below at the new higher precision.\n\n CALL FM_EQU(D2,D1,NDIG/2,NDIG)\n CALL FM_EQU(F2,F1,NDIG/2,NDIG)\n CALL FM_EQU(TOL,TOL2,NDSAVE,NDIG)\n CALL FM_EQU(A,X1,NDSAVE,NDIG)\n\n! Special case for N = 0.\n\n IF (N == 0) THEN\n F2 = F(X1,NF)\n D2 = F2\n IF (ABS(F2-F1) < TOL2) GO TO 110\n CYCLE\n ENDIF\n F2 = F1\n\n! Special case for N = 1.\n\n IF (N == 1) THEN\n IF (X1 /= 0) THEN\n CALL FM_ULP(X1,H)\n ELSE\n H = EPSILON(TO_FM(1))\n ENDIF\n H = SQRT(ABS(H))\n D2 = ( F(X1+H,NF) - F(X1-H,NF) ) / (2*H)\n IF (ABS(D2-D1) < TOL2 .AND. J > 1) GO TO 110\n CYCLE\n ENDIF\n\n! General case for even N > 1.\n\n IF (MOD(N,2) == 0) THEN\n IF (X1 /= 0) THEN\n CALL FM_ULP(X1,H)\n ELSE\n H = EPSILON(TO_FM(1))\n ENDIF\n H = ABS(H)**(TO_FM(1)/(N+2))\n D2 = (-1)**(N/2) * BINOMIAL(TO_FM(N),TO_FM(N/2)) * F(X1,NF)\n DO K = 0, N/2-1\n D2 = D2 + (-1)**K * BINOMIAL(TO_FM(N),TO_FM(K)) * &\n ( F(X1+(N/2-K)*H,NF) + F(X1-(N/2-K)*H,NF) )\n ENDDO\n D2 = D2 / H**N\n IF (ABS(D2-D1) < TOL2 .AND. J > 1) GO TO 110\n CYCLE\n ENDIF\n\n! General case for odd N > 1.\n\n IF (MOD(N,2) == 1) THEN\n IF (X1 /= 0) THEN\n CALL FM_ULP(X1,H)\n ELSE\n H = EPSILON(TO_FM(1))\n ENDIF\n H = ABS(H)**(TO_FM(1)/(N+2))\n D2 = 0\n DO K = 0, N/2\n D2 = D2 + (-1)**K * BINOMIAL(TO_FM(N-1),TO_FM(K)) * &\n ( F(X1+(N/2-K+1)*H,NF) - F(X1-(N/2-K+1)*H,NF) ) * &\n TO_FM(N*(N+1-2*K)) / ((N-K)*(N+1-K))\n ENDDO\n D2 = D2 / (2*H**N)\n IF (ABS(D2-D1) < TOL2 .AND. J > 1) GO TO 110\n CYCLE\n ENDIF\n\n ENDDO\n\n! Round and return.\n\n 110 CALL FM_EQU(D2,RETURN_VALUE,NDIG,NDSAVE)\n NDIG = NDSAVE\n KWARN = KWARN_SAVE\n END FUNCTION FM_FPRIME\n\n SUBROUTINE FM_GENEQ(F,A,B,K,X,Y,N)\n USE FMZM\n IMPLICIT NONE\n\n! Generate the KxK matrix A and Kx1 vector B of normal equations for the least square\n! fit of the K-parameter model\n\n! Y = C(1)*F(1,X) + ... + C(K)*F(K,X)\n\n! to the data points (X(J),Y(J)), J = 1, 2, ..., N.\n\n! A and B are returned, and then the coefficients C can be found by solving the\n! linear system A * C = B.\n\n! Function L in the model evaluated at X is referenced by F(L,X) in this routine,\n! and F should be supplied as an external function subprogram by the user.\n\n INTEGER :: K, N\n TYPE (FM), EXTERNAL :: F\n TYPE (FM) :: A(K,K), B(K), X(N), Y(N)\n TYPE (FM), ALLOCATABLE :: FXI(:)\n INTEGER :: I, J, L\n TYPE (FM) :: XI, YI, FXIL\n\n IF (N <= 0 .OR. K <= 0) THEN\n WRITE (*,\"(/' Error in FM_GENEQ. K,N=',2I8/)\") K,N\n STOP\n ENDIF\n\n ALLOCATE(FXI(K),STAT=J)\n IF (J /= 0) THEN\n WRITE (*,\"(/' Error in FM_GENEQ. Unable to allocate FXI with size ',I8/)\") K\n STOP\n ENDIF\n\n! Initialize the upper triangle of A.\n\n DO I = 1, K\n DO J = I, K\n A(I,J) = 0\n ENDDO\n B(I) = 0\n ENDDO\n\n! Loop over the data points.\n\n DO I = 1, N\n XI = X(I)\n YI = Y(I)\n\n! Compute the K function values at X(I).\n\n DO J = 1, K\n FXI(J) = F(J,XI)\n ENDDO\n\n! Multiply the function values and add the products to the matrix.\n\n DO L = 1, K\n FXIL = FXI(L)\n DO J = L, K\n A(L,J) = A(L,J) + FXIL*FXI(J)\n ENDDO\n\n! Sum the right-hand-side term.\n\n B(L) = B(L) + YI*FXIL\n ENDDO\n ENDDO\n\n! Fill the lower triangle of the A matrix using symmetry.\n\n IF (K >= 2) THEN\n DO L = 2, K\n DO J = 1, L-1\n A(L,J) = A(J,L)\n ENDDO\n ENDDO\n ENDIF\n\n DEALLOCATE(FXI)\n END SUBROUTINE FM_GENEQ\n\n RECURSIVE SUBROUTINE FM_INTEGRATE(F,N,A,B,TOL,RESULT,KPRT,NW)\n USE FMVALS\n USE FMZM\n IMPLICIT NONE\n\n! High-precision numerical integration.\n\n! Integrate F(X,N) from A to B. N is passed on to function F to indicate which function to use in\n! cases where several different functions may be defined there.\n\n\n! WARNING: If the function F being integrated or one of its derivatives does not exist at one or\n! both of the endpoints (A,B), the endpoints should be exactly representable in FM's\n! number system. For non-exact numbers like 1/3, sqrt(2), or pi/2, when FM_INTEGRATE\n! raises precision to evaluate the integration formula the endpoints are not accurate\n! enough at the higher precision.\n\n! Example: Integrate sqrt( tan( x ) ) from 0 to pi/2.\n! First, pi/2 is not exact as an FM number. At some precisions it may have rounded up,\n! making tan(x) negative and causing an error in sqrt. Using sqrt( abs( tan( x ) ) )\n! is safer.\n! Second, b = pi/2 has been computed at the user's precision, so when FM_INTEGRATE\n! raises precision, the value of b is just zero-padded on the end, which does not give\n! enough information about how f(x) behaves near the singularity at pi/2.\n!\n! Make the endpoints exact by changing variables. Change the interval to [ 0 , 1 ]:\n!\n! u = ( 2/pi ) * x => du = ( 2/pi ) * dx\n! so\n! x = ( pi/2 ) * u => dx = ( pi/2 ) * du\n! new limits\n! x = 0 => u = 0 and x = pi/2 => u = 1\n!\n! New integral: Integrate (pi/2) * sqrt( abs( tan( pi*u/2 ) ) ) from 0 to 1.\n!\n! Now the function F should declare a local saved type(fm) variable PI, and then use\n! CALL FM_PI(PI) each time F is called to make sure the value of PI is correct at the\n! higher precision being used by FM_INTEGRATE when F is called.\n\n TYPE (FM) :: A,B,RESULT,TOL\n TYPE (FM), EXTERNAL :: F\n INTEGER :: N,KPRT,NW\n INTENT (IN) :: N,A,B,TOL,KPRT,NW\n INTENT (INOUT) :: RESULT\n\n! A,B,TOL, and RESULT are all type (FM) variables, and function F returns a type (FM) result.\n\n! RESULT is returned as the value of the integral, with ABS((RESULT-true)/true) less than TOL\n! (i.e., TOL is a relative error tolerance).\n! For example, to get 30 significant digits correct for the integral, set TOL = 1.0E-30.\n\n! FM precision must be set high enough in the calling program (using FM_SET) so that 1+TOL > 1\n! at that precision. Using TOL = EPSILON(TO_FM(1)) will usually get a full precision result,\n! but for some functions this might fail. A better strategy is to set precision higher than\n! the accuracy required for the integral. For example, to get the integral to 50 significant\n! digits, CALL FMSET(60) and then set TOL = TO_FM(' 1.0E-50 ') before the call to FM_INTEGRATE.\n\n! KPRT can be used to show intermediate results on unit NW.\n! KPRT = 0 for no output\n! = 1 prints a summary for each call to FM_INTEGRATE\n! = 2 prints a trace of all iterations.\n\n! NW is the unit number used for KPRT output and any error or warning messages.\n\n! No method for numerical integration is foolproof. Since it samples only a finite number of\n! function values, any numerical integration algorithm can be made to fail by choosing a\n! sufficiently badly-behaved function. Such functions often vary by many orders of magnitude\n! over relatively small fractions of the interval (A,B).\n\n! F should be well-behaved in the interior of the interval (A,B).\n! The routine tries to handle any singularities of F or F' at A and/or B, so cases with interior\n! singularities should be done as separate calls having the singularities as endpoints.\n! The routine will try to handle cases where F or F' has singularities inside (A,B), but then\n! the time will be much slower and the routine might fail.\n\n! For a function with a removable singularity in the interior of the interval, such as\n! f(x) = 1/ln(x) - 1/(x-1), define F(X,N) to check for X = 1 and return the correct limiting\n! value, 0.5 in this case, when X is 1.\n\n! Among functions with no singularities, examples of badly behaved functions are those with one\n! or more extremely narrow tall spikes in their graphs. If possible, identify the peaks of any\n! such spikes first, then make separate calls with the peaks as endpoints of the intervals of\n! integration.\n\n! If the value of the integral is zero or very close to zero, relative error may be undefined, so\n! this routine may fail to converge and then return unknown. For these cases, try breaking the\n! integral into two pieces and calling twice to get two non-zero results. These two results can\n! then be added, often giving the original integral with sufficiently small absolute error even\n! though small relative error could not be attained.\n\n! If the function values are too extreme, it can cause problems. For example, if an exponential\n! in F underflows and then is multiplied by something bigger than one, then F will return unknown.\n! If the result of the integral is much larger than the underflow threshold (TINY(TO_FM(1))), then\n! it is safe to set the underflowed results in F to zero to avoid getting unknown.\n\n! If the function is nearly divergent FM_INTEGRATE may fail. 1/x from 0 to b is divergent.\n! 1/x**0.99 converges, but so slowly that FM_INTEGRATE may run a long time and then might fail.\n! 1/x**0.9999 converges even more slowly and FM_INTEGRATE may fail by declaring that the integral\n! seems divergent.\n\n! When the integrand is highly (or infinitely) oscillatory, FM_INTEGRATE may fail.\n! If F has more than about 100 oscillations on the interval (A,B), it may be necessary to break\n! the interval into smaller intervals and call FM_INTEGRATE several times.\n! For infinitely many oscillations, like sin(1/x) from 0 to 1, first turn the integral into an\n! infinite series by calling FM_INTEGRATE to integrate each separate loop between roots of\n! sin(1/x). The function is well-behaved for each call, so FM_INTEGRATE can get high precision\n! quickly for each. Next form a sequence of k partial sums for this series. The series converges\n! slowly, with 50 or 100 terms giving only 3 or 4 significant digits of the sum, so an\n! extrapolation method can be used to get a more accurate value of the sum of this series from\n! its first k terms. For an alternating series like this, the extrapolation method of Cohen,\n! Villegas, and Zagier often works very well.\n! Repeated Aitken extrapolation could be used instead -- it is a more widely known method.\n! Sample program Oscillate.f95 computes this integral.\n\n\n! M is the maximum level for the integration algorithm. The number of function\n! evaluations roughly doubles for each successive level until the tolerance is met.\n! Using M = 12 allows up to about 5,000 digits for most integrals, but the upper\n! limit for a given M depends on the function.\n! Raising M further will approximately double the maximum precision for each\n! extra level, but will also double the memory usage for each extra level.\n\n INTEGER, PARAMETER :: M = 12\n INTEGER, PARAMETER :: NT = 20*2**M\n TYPE (FM), SAVE :: ST_SAVE(0:NT)\n INTEGER, SAVE :: PRECISION_OF(0:NT) = 0\n INTEGER :: ABSIGN,I,ISTEP,K,KWSAVE,NDS,NDSAVE,NRETRY\n INTEGER, SAVE :: R_LEVEL = 0, NUM_F = 0\n\n TYPE (FM) :: A1,AB2,B1,C1,C2,CI,CT,D,EPS,ERR1,ERR2,FMAX,FMAX2,H,HF,LAST_H,PI,PRIOR_HS, &\n S,S1,S2,SI,ST,T,TOL1,TOL2,X,XF,XMAX,V,W\n\n CHARACTER(80) :: ST1,ST2\n REAL :: TIME1,TIME2\n LOGICAL :: SPIKE_FOUND,ST_IS_SAVED\n\n! Iterative tanh-sinh integration is used, increasing the order until convergence\n! is obtained, or M levels have been done.\n\n RESULT = 0\n\n NCALL = NCALL + 1\n NAMEST(NCALL) = 'INTEGRATE'\n KWSAVE = KW\n KW = NW\n R_LEVEL = R_LEVEL + 1\n NRETRY = 0\n IF (KPRT >= 2) THEN\n WRITE (NW,\"(A)\") ' '\n WRITE (NW,\"(A,I9,A)\") ' Input to FM_INTEGRATE. Function N = ',N,'. A, B ='\n CALL FM_PRINT(A)\n CALL FM_PRINT(B)\n CALL FM_FORM('ES20.8',TOL,ST1)\n WRITE (NW,\"(A,A)\") ' TOL =',TRIM(ST1)\n ENDIF\n CALL CPU_TIME(TIME1)\n\n! Check for special cases.\n\n IF (A == B) THEN\n A1 = F(A,N)\n IF (R_LEVEL <= 1) THEN\n NUM_F = 1\n ELSE\n NUM_F = NUM_F + 1\n ENDIF\n IF (A1%MFM%MP(2) == MUNKNO) THEN\n CALL FM_F_FAIL(A,N,NW)\n PRIOR_HS = A1\n GO TO 120\n ELSE\n PRIOR_HS = 0\n GO TO 120\n ENDIF\n ENDIF\n\n! Check to make sure the user has set precision high enough for the value of TOL chosen.\n\n TOL1 = TOL\n IF (TOL < ABS(EPSILON(A))) THEN\n WRITE (NW,\"(A)\") ' '\n WRITE (NW,\"(A)\") ' Error in FM_INTEGRATE. TOL is '\n CALL FM_PRINT(TOL)\n WRITE (NW,\"(A)\") ' This is too small for the current precision level. Current epsilon ='\n TOL1 = ABS(EPSILON(A))\n CALL FM_PRINT(TOL1)\n WRITE (NW,\"(A)\") ' This larger value will be used. TOL ='\n CALL FM_PRINT(TOL1)\n WRITE (NW,\"(A)\") ' Use FM_SET to set a higher precision before the call to'\n WRITE (NW,\"(A)\") ' FM_INTEGRATE if the smaller TOL is needed.'\n ENDIF\n\n! Raise the precision.\n! Check for an integrable singularity at either endpoint, and increase precision\n! if it seems that a retry would be needed at the first precision.\n\n NDSAVE = NDIG\n A1 = LOG10(F(A+(B-A)*TO_FM(' 1.0E-10 '),N)/F(A+(B-A)*TO_FM(' 1.0E-20 '),N))/10\n B1 = LOG10(F(B-(B-A)*TO_FM(' 1.0E-10 '),N)/F(B-(B-A)*TO_FM(' 1.0E-20 '),N))/10\n IF (R_LEVEL <= 1) THEN\n NUM_F = 4\n ELSE\n NUM_F = NUM_F + 4\n ENDIF\n IF (A1 < -0.999 .OR. B1 < -0.999) THEN\n PRIOR_HS = TO_FM(' UNKNOWN ')\n WRITE (NW,\"(A)\") ' '\n WRITE (NW,\"(A,I9,A)\") ' FM_INTEGRATE failed -- F(X,N) for N = ',N, &\n ' seems to have a non-integrable singularity'\n WRITE (NW,\"(A)\") ' at an endpoint. A,B ='\n CALL FM_PRINT(A)\n CALL FM_PRINT(B)\n WRITE (NW,\"(A)\") ' Check the limits of integration, function number (N), and' // &\n ' function definition.'\n WRITE (NW,\"(A)\") ' '\n GO TO 120\n ENDIF\n NDIG = NDIG+INT(30/ALOGMT)\n CALL FM_EQU_R1(A1,NDSAVE,NDIG)\n CALL FM_EQU_R1(B1,NDSAVE,NDIG)\n IF (A1 < -0.2 .OR. B1 < -0.2) NDIG = 2*NDIG\n\n CALL CPU_TIME(TIME1)\n\n! Start here when doing a retry.\n\n 110 NRETRY = NRETRY + 1\n CALL FM_EQU(A,A1,NDSAVE,NDIG)\n CALL FM_EQU(B,B1,NDSAVE,NDIG)\n ABSIGN = 1\n IF (A1 > B1) THEN\n CALL FM_EQU(B,A1,NDSAVE,NDIG)\n CALL FM_EQU(A,B1,NDSAVE,NDIG)\n ABSIGN = -1\n ELSE IF (A1 == B1) THEN\n PRIOR_HS = 0\n GO TO 120\n ENDIF\n CALL FM_EQU(TOL1,TOL2,NDSAVE,NDIG)\n\n IF (KPRT >= 2) THEN\n WRITE (NW,\"(A)\") ' '\n WRITE (NW,\"(A,I9,A,I5)\") ' Begin FM_INTEGRATE. NDIG = ',NDIG,' Recursion level = ', &\n R_LEVEL\n ENDIF\n\n S = 0\n PRIOR_HS = 0\n ERR2 = 1\n EPS = EPSILON(TOL2)\n D = ABS(B1-A1)/100\n FMAX = 0\n FMAX2 = 0\n XMAX = A1\n H = 1\n LAST_H = H/2**M\n CALL FM_PI(PI)\n\n HF = (B1-A1)/2\n AB2 = A1 + HF\n DO K = 1, M\n H = H/2\n ISTEP = 2**(M-K)\n IF (K > 1) THEN\n T = ISTEP*LAST_H\n CALL FM_CHSH(T,C1,S1)\n T = 2*S1*C1\n C2 = C1**2 + S1**2\n S2 = T\n ENDIF\n DO I = 0, NT, ISTEP\n IF (MOD(I,2*ISTEP) /= 0 .OR. K == 1) THEN\n\n! The + or -X values are the abscissas for interval (-1,1).\n! XF translates these to the interval (A,B).\n\n IF (I == 0) THEN\n X = 0\n W = PI/2\n XF = HF*X + AB2\n T = F(XF,N)\n NUM_F = NUM_F + 1\n IF (T%MFM%MP(2) == MUNKNO) THEN\n CALL FM_F_FAIL(XF,N,NW)\n PRIOR_HS = T\n GO TO 120\n ENDIF\n FMAX2 = MAX(FMAX2,ABS(T))\n IF (ABS(T) > FMAX .AND. XF > A1+D .AND. XF < B1-D) THEN\n FMAX = ABS(T)\n XMAX = XF\n ENDIF\n S = S + W*HF*T\n ELSE\n IF (K == 1) THEN\n T = I*LAST_H\n CALL FM_CHSH(T,CI,SI)\n ELSE\n\n! Use the hyperbolic addition formulas to get the next cosh and sinh\n! quickly when evaluated at I*LAST_H.\n\n IF (I == ISTEP) THEN\n CI = C1\n SI = S1\n ELSE\n T = SI*C2 + CI*S2\n CI = CI*C2 + SI*S2\n SI = T\n C1 = CI\n S1 = SI\n ENDIF\n ENDIF\n ST_IS_SAVED = .FALSE.\n IF (ALLOCATED(ST_SAVE(I)%MFM%MP)) THEN\n IF (PRECISION_OF(I) >= NDIG) ST_IS_SAVED = .TRUE.\n ENDIF\n IF (ST_IS_SAVED) THEN\n ST = ST_SAVE(I)\n CT = SQRT(1+ST**2)\n ELSE\n T = PI*SI/2\n CALL FM_CHSH(T,CT,ST)\n ST_SAVE(I) = ST\n PRECISION_OF(I) = NDIG\n ENDIF\n W = (PI/2)*CI/CT**2\n IF (W < EPS) EXIT\n X = ST/CT\n XF = HF*(-X) + AB2\n IF (XF > A1) THEN\n T = F(XF,N)\n NUM_F = NUM_F + 1\n IF (T%MFM%MP(2) == MUNKNO) THEN\n CALL FM_F_FAIL(XF,N,NW)\n PRIOR_HS = T\n GO TO 120\n ENDIF\n FMAX2 = MAX(FMAX2,ABS(T))\n IF (ABS(T) > FMAX .AND. XF > A1+D .AND. XF < B1-D) THEN\n FMAX = ABS(T)\n XMAX = XF\n ENDIF\n S = S + W*HF*T\n ENDIF\n XF = HF*(X) + AB2\n IF (XF < B1) THEN\n T = F(XF,N)\n NUM_F = NUM_F + 1\n IF (T%MFM%MP(2) == MUNKNO) THEN\n CALL FM_F_FAIL(XF,N,NW)\n PRIOR_HS = T\n GO TO 120\n ENDIF\n FMAX2 = MAX(FMAX2,ABS(T))\n IF (ABS(T) > FMAX .AND. XF > A1+D .AND. XF < B1-D) THEN\n FMAX = ABS(T)\n XMAX = XF\n ENDIF\n S = S + W*HF*T\n ENDIF\n ENDIF\n ENDIF\n ENDDO\n IF (KPRT >= 2) THEN\n WRITE (NW,\"(A)\") ' '\n WRITE (NW,\"(A,I9,A,I9,A)\") ' K = ',K,' ',NUM_F, &\n ' function calls so far. Integral approximation ='\n V = H*S\n CALL FM_PRINT(V)\n ENDIF\n IF (K > 1) THEN\n ERR1 = ERR2\n IF (S /= 0) THEN\n ERR2 = ABS( (PRIOR_HS - H*S)/(H*S) )\n ELSE\n ERR2 = ABS( (PRIOR_HS - H*S) )\n ENDIF\n IF (KPRT >= 2) THEN\n CALL FM_FORM('ES15.3',ERR2,ST1)\n WRITE (NW,\"(A,A)\") ' relative error of the last two approximations = ', &\n TRIM(ST1)\n ENDIF\n\n! Check for convergence.\n\n IF (K > 3 .AND. ERR2 > 0 .AND. ERR2 < TOL2/10.0) EXIT\n IF (K > 5 .AND. ERR2 == 0) EXIT\n\n! If the errors do not decrease fast enough, raise precision and try again.\n\n IF (K > 3*NRETRY .AND. ERR1 > 0 .AND. ERR2 > 0) THEN\n IF (LOG(ERR2)/LOG(ERR1) < 1.2 .AND. ERR1 < 1.0D-6) THEN\n NDIG = 2*NDIG\n IF (KPRT >= 2) THEN\n WRITE (NW,\"(A,I9,A,I9)\") ' FM_INTEGRATE Retry. So far, NUM_F = ',NUM_F, &\n ' New NDIG = ',NDIG\n ENDIF\n IF (NRETRY <= 3) GO TO 110\n NDIG = NDIG/2\n ENDIF\n ENDIF\n ENDIF\n PRIOR_HS = H*S\n\n! No convergence in M iterations.\n! Before giving up, look for an interior singularity or tall spike. If one is found,\n! split (A,B) into two intervals with the interior singularity as an endpoint, and try\n! again as two integrals.\n\n IF (K == M .OR. (K >= 9 .AND. ERR2 > 1.0D-7 .AND. ABS(TOL2) < 1.0D-16)) THEN\n IF (KPRT >= 2) THEN\n WRITE (NW,\"(A)\") ' '\n WRITE (NW,\"(A,I6,A)\") ' No convergence in ',M, &\n ' iterations. Look for an interior singularity.'\n CALL FM_FORM('ES25.6',XMAX,ST1)\n CALL FM_FORM('ES25.6',FMAX,ST2)\n WRITE (NW,\"(I9,A,A,A)\") NUM_F,' function calls so far. XMAX, FMAX =', &\n TRIM(ST1),TRIM(ST2)\n ENDIF\n CALL FM_SPIKE(F,N,A1,B1,XMAX,FMAX,NUM_F,SPIKE_FOUND,KPRT,NW)\n CALL FMEQU_R1(A1%MFM,NDIG,NDSAVE)\n CALL FMEQU_R1(B1%MFM,NDIG,NDSAVE)\n CALL FMEQU_R1(XMAX%MFM,NDIG,NDSAVE)\n NDS = NDIG\n NDIG = NDSAVE\n IF (SPIKE_FOUND) THEN\n IF (MIN(ABS(A-XMAX),ABS(B-XMAX)) < 1.01*D) THEN\n NDIG = 2*NDS\n IF (NRETRY <= 5) GO TO 110\n NDIG = NDSAVE\n ENDIF\n IF (KPRT >= 2) THEN\n WRITE (NW,\"(A)\") ' '\n WRITE (NW,\"(A)\") ' Split the integral. First half: A,B = '\n CALL FM_PRINT(A1)\n CALL FM_PRINT(XMAX)\n ENDIF\n CALL FM_INTEGRATE(F,N,A1,XMAX,TOL,C1,KPRT,NW)\n IF (C1%MFM%MP(2) == MUNKNO) THEN\n PRIOR_HS = C1\n GO TO 120\n ENDIF\n IF (KPRT >= 2) THEN\n WRITE (NW,\"(A)\") ' '\n WRITE (NW,\"(A)\") ' Split the integral. Second half: A,B = '\n CALL FM_PRINT(XMAX)\n CALL FM_PRINT(B1)\n ENDIF\n CALL FM_INTEGRATE(F,N,XMAX,B1,TOL,C2,KPRT,NW)\n PRIOR_HS = C1 + C2\n GO TO 120\n ENDIF\n CALL FM_INT_FAIL(N,A,B,TOL,M,ERR2,PRIOR_HS,NW)\n PRIOR_HS = TO_FM(' UNKNOWN ')\n GO TO 120\n ENDIF\n ENDDO\n\n PRIOR_HS = ABSIGN*H*S\n\n! Round the result and return.\n\n 120 CALL FM_EQU(PRIOR_HS,RESULT,NDIG,NDSAVE)\n\n NDIG = NDSAVE\n NCALL = NCALL - 1\n CALL CPU_TIME(TIME2)\n\n IF (KPRT >= 2 .OR. ( R_LEVEL <= 1 .AND. KPRT == 1 ) ) THEN\n WRITE (NW,\"(A)\") ' '\n WRITE (NW,\"(A,I9,A)\") ' Return from FM_INTEGRATE. Function N = ',N,'. A, B ='\n CALL FM_PRINT(A)\n CALL FM_PRINT(B)\n CALL FM_FORM('ES20.8',TOL,ST1)\n WRITE (NW,\"(A,A)\") ' TOL =',TRIM(ST1)\n IF (ABS(TIME2-TIME1) > 0.0001 .AND. ABS(TIME2-TIME1) < 1000.0) THEN\n WRITE (NW,\"(1X,I9,A,F9.5,A)\") NUM_F,' function calls were made in ',TIME2-TIME1, &\n ' seconds.'\n WRITE (NW,\"(A)\") ' RESULT ='\n ELSE\n WRITE (NW,\"(1X,I9,A,ES14.5,A)\") NUM_F,' function calls were made in ',TIME2-TIME1, &\n ' seconds.'\n WRITE (NW,\"(A)\") ' RESULT ='\n ENDIF\n CALL FM_PRINT(RESULT)\n ENDIF\n KW = KWSAVE\n R_LEVEL = R_LEVEL - 1\n\n END SUBROUTINE FM_INTEGRATE\n\n SUBROUTINE FM_INT_FAIL(N,A,B,TOL,M,ERR,VAL,NW)\n USE FMZM\n IMPLICIT NONE\n INTEGER :: N,M,NW\n TYPE (FM) :: A,B,TOL,ERR,VAL\n\n WRITE (NW,*) ' '\n WRITE (NW,*) ' FM_INTEGRATE failed -- no convergence in ',M,' iterations.'\n WRITE (NW,*) ' UNKNOWN has been returned in RESULT.'\n WRITE (NW,*) ' Possible causes: (1) highly oscillatory integrand'\n WRITE (NW,*) ' (2) non-convergent integral'\n WRITE (NW,*) ' (3) integrable singularity in the interior of interval (A,B)'\n WRITE (NW,*) ' (4) narrow spike in the interior of interval (A,B)'\n WRITE (NW,*) ' (5) integral too close to zero'\n WRITE (NW,*) ' A possible remedy for the last 3 is to split the integral into two pieces,'\n WRITE (NW,*) ' making two calls to FM_INTEGRATE and then adding the two results.'\n WRITE (NW,*) ' Put singularities or spikes at the endpoints of the intervals of integration.'\n WRITE (NW,*) ' '\n WRITE (NW,*) ' Function N = ',N,'. A, B ='\n CALL FM_PRINT(A)\n CALL FM_PRINT(B)\n WRITE (NW,*) ' TOL ='\n CALL FM_PRINT(TOL)\n WRITE (NW,*) ' The last integral approximation ='\n CALL FM_PRINT(VAL)\n WRITE (NW,*) ' The estimated relative error in the last integral approximation ='\n CALL FM_PRINT(ERR)\n WRITE (NW,*) ' '\n\n END SUBROUTINE FM_INT_FAIL\n\n SUBROUTINE FM_F_FAIL(X,N,NW)\n USE FMZM\n IMPLICIT NONE\n INTEGER :: N,NW\n TYPE (FM) :: X\n\n WRITE (NW,*) ' '\n WRITE (NW,*) ' FM_INTEGRATE failed -- F(X,N) gave UNKNOWN for N = ',N,' and X ='\n CALL FM_PRINT(X)\n WRITE (NW,*) ' Check the limits of integration, function number (N), and' // &\n ' function definition.'\n WRITE (NW,*) ' Be careful of rounding at an irrational endpoint producing an' // &\n ' illegal function argument.'\n WRITE (NW,*) ' Example: Integrate log( cos( t ) ) from 0 to pi/2'\n WRITE (NW,*) ' At some precisions the computed value of pi/2 rounds up, giving' // &\n ' a small negative cos(t),'\n WRITE (NW,*) ' which then causes the log function to return UNKNOWN.'\n WRITE (NW,*) ' Possible fixes:'\n WRITE (NW,*) ' Change variables to get an integral from 0 to 1'\n WRITE (NW,*) ' Change the function to log( abs( cos( t ) ) )'\n WRITE (NW,*) ' Compute pi/2 with rounding toward -infinity'\n WRITE (NW,*) ' '\n\n END SUBROUTINE FM_F_FAIL\n\n SUBROUTINE FM_SPIKE(F,N,A,B,XMAX,FMAX,NUM_F,SPIKE_FOUND,KPRT,NW)\n USE FMVALS\n USE FMZM\n IMPLICIT NONE\n\n! look for an interior singularity or tall spike in F(X,N).\n! After getting no convergence in M iterations in FM_INTEGRATE, FMAX = ABS(F(XMAX,N)) was\n! the largest magnitude found for F on the interval (A+D,B-D), where D = ABS(B-A)/100.\n\n TYPE (FM) :: A,B,XMAX,FMAX\n TYPE (FM), EXTERNAL :: F\n INTEGER :: N,NUM_F,KPRT,NW\n LOGICAL :: SPIKE_FOUND\n TYPE (FM), SAVE :: AB,AVERAGE,D,DX,FPMAX,EPS,F1,F2,H,T,X1,XPMAX\n INTEGER :: J\n\n SPIKE_FOUND = .FALSE.\n IF (KPRT >= 2) THEN\n WRITE (NW,\"(A)\") ' Enter FM_SPIKE'\n ENDIF\n\n DX = ABS(B-A)/100\n H = MIN(XMAX-A,B-XMAX)/2\n\n AVERAGE = 0\n DO J = 1, 99\n X1 = A + (J*(B-A))/100\n F1 = F(X1,N)\n NUM_F = NUM_F + 1\n IF (F1%MFM%MP(2) == MUNKNO) THEN\n XMAX = X1\n FMAX = ABS(F1)\n SPIKE_FOUND = .TRUE.\n RETURN\n ELSE\n AVERAGE = AVERAGE + ABS(F1)\n ENDIF\n ENDDO\n AVERAGE = AVERAGE/99\n\n! Search for a singularity in F.\n\n DO\n X1 = XMAX + H\n IF (X1 > A + DX .AND. X1 < B - DX) THEN\n F1 = F(X1,N)\n NUM_F = NUM_F + 1\n IF (F1%MFM%MP(2) == MUNKNO) THEN\n XMAX = X1\n FMAX = ABS(F1)\n SPIKE_FOUND = .TRUE.\n RETURN\n ENDIF\n IF (ABS(F1) > FMAX) THEN\n XMAX = X1\n FMAX = ABS(F1)\n H = -(H*14)/10\n ENDIF\n ENDIF\n H = -(H*10)/14\n AB = MAX(ABS(A),ABS(B))\n CALL FM_ULP(AB,EPS)\n IF (ABS(H) < ABS(EPS)) THEN\n IF (FMAX > 50*AVERAGE) THEN\n SPIKE_FOUND = .TRUE.\n RETURN\n ELSE\n EXIT\n ENDIF\n ENDIF\n ENDDO\n\n! Search for a singularity in F'.\n\n FPMAX = -1\n AVERAGE = 0\n AB = MAX(ABS(A),ABS(B))\n CALL FM_ULP(AB,EPS)\n EPS = SQRT(EPS)\n DO J = 1, 99\n X1 = A + (J*(B-A))/100\n IF (X1-EPS <= A) CYCLE\n F1 = F(X1-EPS,N)\n IF (X1+EPS >= B) CYCLE\n F2 = F(X1+EPS,N)\n NUM_F = NUM_F + 2\n IF (F1%MFM%MP(2) == MUNKNO .OR. F2%MFM%MP(2) == MUNKNO) THEN\n IF (F1%MFM%MP(2) == MUNKNO) THEN\n XMAX = X1 - EPS\n FMAX = ABS(F1)\n ELSE\n XMAX = X1 + EPS\n FMAX = ABS(F2)\n ENDIF\n SPIKE_FOUND = .TRUE.\n RETURN\n ELSE\n D = ABS((F2-F1)/(2*EPS))\n AVERAGE = AVERAGE + D\n IF (D > FPMAX) THEN\n XPMAX = X1\n FPMAX = D\n ENDIF\n ENDIF\n ENDDO\n AVERAGE = AVERAGE/99\n\n H = MIN(XPMAX-A,B-XPMAX)/2\n DO\n X1 = XPMAX + H\n IF (X1 > A + DX .AND. X1 < B - DX) THEN\n F1 = F(X1-EPS,N)\n NUM_F = NUM_F + 1\n IF (F1%MFM%MP(2) == MUNKNO) THEN\n XPMAX = X1\n FPMAX = ABS(F1)\n SPIKE_FOUND = .TRUE.\n RETURN\n ENDIF\n F2 = F(X1+EPS,N)\n NUM_F = NUM_F + 1\n IF (F2%MFM%MP(2) == MUNKNO) THEN\n XPMAX = X1+EPS\n FPMAX = ABS(F2)\n SPIKE_FOUND = .TRUE.\n RETURN\n ENDIF\n D = ABS((F2-F1)/(2*EPS))\n IF (D > FPMAX) THEN\n XPMAX = X1\n FPMAX = D\n H = -(H*14)/10\n ENDIF\n ENDIF\n H = -(H*10)/14\n AB = MAX(ABS(A),ABS(B))\n CALL FM_ULP(AB,T)\n IF (ABS(H) < ABS(T)) THEN\n IF (FPMAX > 50*AVERAGE) THEN\n SPIKE_FOUND = .TRUE.\n XMAX = XPMAX\n FMAX = FPMAX\n RETURN\n ELSE\n EXIT\n ENDIF\n ENDIF\n ENDDO\n\n END SUBROUTINE FM_SPIKE\n\n SUBROUTINE FM_INVERSE(A,N,B,DET)\n USE FMVALS\n USE FMZM\n IMPLICIT NONE\n\n! Return B as the inverse of the N x N matrix A, and DET as the determinant of A.\n\n! A and B are type (fm) (real) multiprecision arrays.\n\n INTEGER :: N\n TYPE (FM) :: A(N,N), B(N,N), DET\n TYPE (FM), SAVE :: TOL\n TYPE (FM), ALLOCATABLE :: A1(:,:), A2(:,:), B1(:), R1(:), X1(:)\n INTEGER, ALLOCATABLE :: KSWAP(:)\n INTEGER :: I, J, K, KWARN_SAVE, NDSAVE\n\n TOL = EPSILON(TO_FM(1))/MBASE/TO_FM(10)**10\n\n ALLOCATE(A1(N,N),A2(N,N),B1(N),R1(N),X1(N),KSWAP(N),STAT=J)\n IF (J /= 0) THEN\n WRITE (*,\"(/' Error in FM_INVERSE. Unable to allocate arrays with N = ',I8/)\") N\n STOP\n ENDIF\n\n! Raise precision.\n\n NDSAVE = NDIG\n NDIG = 2*NDIG\n KWARN_SAVE = KWARN\n KWARN = 0\n\n! Copy A to A1 with higher precision.\n\n 110 CALL FM_EQU_R1(TOL,NDSAVE,NDIG)\n DO I = 1, N\n DO J = 1, N\n CALL FM_EQU(A(I,J),A1(I,J),NDSAVE,NDIG)\n ENDDO\n ENDDO\n A2 = A1\n\n! Factor A into L*U form.\n\n CALL FM_FACTOR_LU(A1,N,DET,KSWAP)\n IF (DET == 0 .OR. IS_UNKNOWN(DET)) THEN\n IF (KWARN > 0) THEN\n WRITE (KW,\"(/' Error in FM_INVERSE. The matrix is singular.'/)\")\n ENDIF\n IF (KWARN >= 2) STOP\n B = TO_FM(' UNKNOWN ')\n GO TO 120\n ENDIF\n\n! Solve for the inverse matrix one column at a time.\n\n DO K = 1, N\n B1 = 0\n B1(K) = 1\n CALL FM_SOLVE_LU(A1,N,B1,X1,KSWAP)\n\n! Do an iterative refinement.\n\n R1 = MATMUL(A2,X1) - B1\n\n CALL FM_SOLVE_LU(A1,N,R1,B1,KSWAP)\n X1 = X1 - B1\n\n! Check for accuracy at the user's precision.\n\n IF (SQRT( DOT_PRODUCT( B1 , B1 ) ) > TOL) THEN\n NDIG = 2*NDIG\n GO TO 110\n ENDIF\n\n! Round the results and store column K in the B matrix.\n\n DO I = 1, N\n CALL FM_EQU(X1(I),B(I,K),NDIG,NDSAVE)\n ENDDO\n ENDDO\n 120 CALL FM_EQU_R1(DET,NDIG,NDSAVE)\n DEALLOCATE(A1,A2,B1,R1,X1,KSWAP)\n\n NDIG = NDSAVE\n KWARN = KWARN_SAVE\n END SUBROUTINE FM_INVERSE\n\n SUBROUTINE FM_LIN_SOLVE(A,X,B,N,DET)\n USE FMVALS\n USE FMZM\n IMPLICIT NONE\n\n! Gauss elimination to solve the linear system A X = B, where:\n\n! A is the matrix of the system, containing the N x N coefficient matrix.\n\n! B is the N x 1 right-hand-side vector.\n\n! X is the returned N x 1 solution vector.\n\n! DET is returned as the determinant of A.\n! Nonzero DET means a solution was found.\n! DET = 0 is returned if the system is singular.\n\n! A,X,B,DET are all type (fm) multiprecision variables.\n\n INTEGER :: N\n TYPE (FM) :: A(N,N), B(N), X(N), DET\n TYPE (FM), SAVE :: TOL\n TYPE (FM), ALLOCATABLE :: A1(:,:), A2(:,:), B1(:), R1(:), X1(:)\n INTEGER, ALLOCATABLE :: KSWAP(:)\n INTEGER :: I, J, NDSAVE\n\n ALLOCATE(A1(N,N),A2(N,N),B1(N),R1(N),X1(N),KSWAP(N),STAT=J)\n IF (J /= 0) THEN\n WRITE (*,\"(/' Error in FM_LIN_SOLVE. Unable to allocate arrays with N = ',I8/)\") N\n STOP\n ENDIF\n\n TOL = EPSILON(B(1))/MBASE/TO_FM(10)**10\n\n NDSAVE = NDIG\n NDIG = 2*NDIG\n\n! Copy A and B to A1 and B1 with higher precision.\n\n 110 CALL FM_EQU_R1(TOL,NDSAVE,NDIG)\n DO I = 1, N\n DO J = 1, N\n CALL FM_EQU(A(I,J),A1(I,J),NDSAVE,NDIG)\n CALL FM_EQ(A1(I,J),A2(I,J))\n ENDDO\n CALL FM_EQU(B(I),B1(I),NDSAVE,NDIG)\n ENDDO\n\n! Solve the system.\n\n CALL FM_FACTOR_LU(A1,N,DET,KSWAP)\n IF (DET == 0 .OR. IS_UNKNOWN(DET)) THEN\n IF (KWARN > 0) THEN\n WRITE (KW,\"(/' Error in FM_LIN_SOLVE. The matrix is singular.'/)\")\n ENDIF\n IF (KWARN >= 2) STOP\n X1 = TO_FM(' UNKNOWN ')\n GO TO 120\n ENDIF\n CALL FM_SOLVE_LU(A1,N,B1,X1,KSWAP)\n\n! Do an iterative refinement.\n\n R1 = MATMUL(A2,X1) - B1\n\n CALL FM_SOLVE_LU(A1,N,R1,B1,KSWAP)\n X1 = X1 - B1\n\n! Check for accuracy at the user's precision.\n\n IF (SQRT( DOT_PRODUCT( B1 , B1 ) ) > TOL) THEN\n NDIG = 2*NDIG\n GO TO 110\n ENDIF\n\n! Round and return X and DET.\n\n 120 DO I = 1, N\n CALL FM_EQU(X1(I),X(I),NDIG,NDSAVE)\n ENDDO\n CALL FM_EQU_R1(DET,NDIG,NDSAVE)\n\n NDIG = NDSAVE\n\n DEALLOCATE(A1,A2,B1,R1,X1,KSWAP)\n\n END SUBROUTINE FM_LIN_SOLVE\n\n SUBROUTINE FM_FACTOR_LU(A,N,DET,KSWAP)\n USE FMZM\n IMPLICIT NONE\n\n! Gauss elimination to factor the NxN matrix A (LU decomposition).\n\n! The time is proportional to N**3.\n\n! Once this factorization has been done, a linear system A x = b\n! with the same coefficient matrix A and Nx1 vector b can be solved\n! for x using routine FM_SOLVE_LU in time proportional to N**2.\n\n! DET is returned as the determinant of A.\n! Nonzero DET means there is a unique solution.\n! DET = 0 is returned if the system is singular.\n\n! KSWAP is a list of row interchanges made by the partial pivoting strategy during the\n! elimination phase.\n\n! After returning, the values in matrix A have been replaced by the multipliers\n! used during elimination. This is equivalent to factoring the A matrix into\n! a lower triangular matrix L times an upper triangular matrix U.\n\n\n INTEGER :: N\n INTEGER :: JCOL, JDIAG, JMAX, JROW, KSWAP(N)\n TYPE (FM) :: A(N,N), DET\n TYPE (FM), SAVE :: AMAX, AMULT, TEMP\n\n DET = 1\n KSWAP(1:N) = 1\n IF (N <= 0) THEN\n DET = 0\n RETURN\n ENDIF\n IF (N == 1) THEN\n KSWAP(1) = 1\n DET = A(1,1)\n RETURN\n ENDIF\n\n! Do the elimination phase.\n! JDIAG is the current diagonal element below which the elimination proceeds.\n\n DO JDIAG = 1, N-1\n\n! Pivot to put the element with the largest absolute value on the diagonal.\n\n AMAX = ABS(A(JDIAG,JDIAG))\n JMAX = JDIAG\n DO JROW = JDIAG+1, N\n IF (ABS(A(JROW,JDIAG)) > AMAX) THEN\n AMAX = ABS(A(JROW,JDIAG))\n JMAX = JROW\n ENDIF\n ENDDO\n\n! If AMAX is zero here then the system is singular.\n\n IF (AMAX == 0.0) THEN\n DET = 0\n RETURN\n ENDIF\n\n! Swap rows JDIAG and JMAX unless they are the same row.\n\n KSWAP(JDIAG) = JMAX\n IF (JMAX /= JDIAG) THEN\n DET = -DET\n DO JCOL = JDIAG, N\n TEMP = A(JDIAG,JCOL)\n A(JDIAG,JCOL) = A(JMAX,JCOL)\n A(JMAX,JCOL) = TEMP\n ENDDO\n ENDIF\n DET = DET * A(JDIAG,JDIAG)\n\n! For JROW = JDIAG+1, ..., N, eliminate A(JROW,JDIAG) by replacing row JROW by\n! row JROW - A(JROW,JDIAG) * row JDIAG / A(JDIAG,JDIAG)\n\n DO JROW = JDIAG+1, N\n IF (A(JROW,JDIAG) == 0) CYCLE\n AMULT = A(JROW,JDIAG)/A(JDIAG,JDIAG)\n\n! Save the multiplier for use later by FM_SOLVE_LU.\n\n A(JROW,JDIAG) = AMULT\n DO JCOL = JDIAG+1, N\n CALL FMMPY_SUB(A(JROW,JCOL)%MFM,AMULT%MFM,A(JDIAG,JCOL)%MFM)\n ENDDO\n ENDDO\n ENDDO\n DET = DET * A(N,N)\n\n END SUBROUTINE FM_FACTOR_LU\n\n SUBROUTINE FM_SOLVE_LU(A,N,B,X,KSWAP)\n USE FMZM\n IMPLICIT NONE\n\n! Solve a linear system A x = b.\n! A is the NxN coefficient matrix, after having been factored by FM_FACTOR_LU.\n! B is the Nx1 right-hand-side vector.\n! X is returned with the solution of the linear system.\n! KSWAP is a list of row interchanges made by the partial pivoting strategy during the\n! elimination phase in FM_FACTOR_LU.\n! Time for this call is proportional to N**2.\n\n INTEGER :: N, KSWAP(N)\n TYPE (FM) :: A(N,N), B(N), X(N)\n INTEGER :: J, JDIAG, JMAX\n TYPE (FM), SAVE :: TEMP\n\n IF (N <= 0) THEN\n RETURN\n ENDIF\n IF (N == 1) THEN\n X(1) = B(1) / A(1,1)\n RETURN\n ENDIF\n DO J = 1, N\n X(J) = B(J)\n ENDDO\n\n! Do the elimination phase operations only on X.\n! JDIAG is the current diagonal element below which the elimination proceeds.\n\n DO JDIAG = 1, N-1\n\n! Pivot to put the element with the largest absolute value on the diagonal.\n\n JMAX = KSWAP(JDIAG)\n\n! Swap rows JDIAG and JMAX unless they are the same row.\n\n IF (JMAX /= JDIAG) THEN\n TEMP = X(JDIAG)\n X(JDIAG) = X(JMAX)\n X(JMAX) = TEMP\n ENDIF\n\n! For JROW = JDIAG+1, ..., N, eliminate A(JROW,JDIAG) by replacing row JROW by\n! row JROW - A(JROW,JDIAG) * row JDIAG / A(JDIAG,JDIAG)\n! After factoring, A(JROW,JDIAG) is the original A(JROW,JDIAG) / A(JDIAG,JDIAG).\n\n DO J = JDIAG+1, N\n X(J) = X(J) - A(J,JDIAG) * X(JDIAG)\n ENDDO\n ENDDO\n\n! Do the back substitution.\n\n DO JDIAG = N, 1, -1\n\n! Divide row JDIAG by the diagonal element.\n\n X(JDIAG) = X(JDIAG) / A(JDIAG,JDIAG)\n\n! Zero above the diagonal in column JDIAG by replacing row JROW by\n! row JROW - A(JROW,JDIAG) * row JDIAG\n! For JROW = 1, ..., JDIAG-1.\n\n IF (JDIAG == 1) EXIT\n DO J = 1, JDIAG-1\n X(J) = X(J) - A(J,JDIAG) * X(JDIAG)\n ENDDO\n ENDDO\n\n END SUBROUTINE FM_SOLVE_LU\n\n SUBROUTINE FMMPY_SUB(MA,MB,MC)\n USE FMVALS\n IMPLICIT NONE\n\n! Fused multiply-subtract operation. Return MA = MA - MB*MC\n! This is an internal FM routine used by FM_FACTOR_LU. It doesn't always return correctly\n! rounded results, since precision will have already been raised by FM_LIN_SOLVE before\n! calling FM_FACTOR_LU.\n\n TYPE(MULTI) :: MA,MB,MC\n TYPE(MULTI) :: MXY\n INTEGER :: J,K,K1,KPTA,KPTC,MA_VS_MBMC\n DOUBLE PRECISION :: A1,A2,B,B1,B2,C1,C2,DPA,DPBC\n REAL (KIND(1.0D0)) :: MBJ, MGD\n\n! Special cases.\n\n IF (MB%MP(3) == 0 .OR. MC%MP(3) == 0 .OR. &\n MA%MP(2) - 1 > MB%MP(2) + MC%MP(2) + NDIG) THEN\n RETURN\n ENDIF\n IF (MA%MP(3) == 0 .OR. &\n MB%MP(2) + MC%MP(2) - 1 > MA%MP(2) + NDIG) THEN\n CALL FMMPY(MB,MC,MA)\n IF (MA%MP(2) /= MUNKNO) MA%MP(1) = -MA%MP(1)\n RETURN\n ENDIF\n\n IF (ABS(MA%MP(2)) > MEXPAB .OR. ABS(MB%MP(2)) > MEXPAB .OR. &\n ABS(MC%MP(2)) > MEXPAB .OR. MBASE < 1000 .OR. MBASE**2 > MAXINT .OR. &\n NDIG > 900 .OR. NDIG > MAXINT/MBASE**2) THEN\n GO TO 110\n ENDIF\n\n! Determine which of abs(MA) and abs(MB*MC) is larger.\n\n MA_VS_MBMC = 0\n B = MBASE\n IF (MA%MP(2) <= MB%MP(2) + MC%MP(2) - 2) THEN\n MA_VS_MBMC = -1\n GO TO 120\n ENDIF\n IF (MA%MP(2) >= MB%MP(2) + MC%MP(2) + 1) THEN\n MA_VS_MBMC = 1\n GO TO 120\n ENDIF\n A1 = MA%MP(3)\n A2 = MA%MP(4)\n B1 = MB%MP(3)\n B2 = MB%MP(4)\n C1 = MC%MP(3)\n C2 = MC%MP(4)\n IF (MA%MP(2) == MB%MP(2) + MC%MP(2) - 1) THEN\n DPA = A1 * B + A2 + 1\n DPBC = B1 * C1 * B + B1 * C2 + B2 * C1 + C2 * B2 / B\n IF (DPA < DPBC) THEN\n MA_VS_MBMC = -1\n GO TO 120\n ENDIF\n\n DPA = A1 * B + A2\n DPBC = B1 * C1 * B + B1 * (C2+1) + (B2+1) * C1 + (C2+1) * (B2+1) / B\n IF (DPA > DPBC) THEN\n MA_VS_MBMC = 1\n GO TO 120\n ENDIF\n ELSE IF (MA%MP(2) == MB%MP(2) + MC%MP(2)) THEN\n DPA = A1 * B + A2 + 1\n DPBC = B1 * C1 + ( B1 * C2 + B2 * C1 ) / B + C2 * B2 / B**2\n IF (DPA < DPBC) THEN\n MA_VS_MBMC = -1\n GO TO 120\n ENDIF\n\n DPA = A1 * B + A2\n DPBC = B1 * C1 + ( B1 * (C2+1) + (B2+1) * C1 ) / B + (C2+1) * (B2+1) / B**2\n IF (DPA > DPBC) THEN\n MA_VS_MBMC = 1\n GO TO 120\n ENDIF\n ENDIF\n\n! If it is not easy to determine which term is larger, make separate calls to\n! multiply and subtract.\n\n 110 CALL FMMPY(MB,MC,MXY)\n CALL FMSUB_R1(MA,MXY)\n RETURN\n\n! Handle the operation using 4 cases, depending on which term is larger and whether\n! MA and MB*MC have opposite signs or not.\n\n 120 IF (MA%MP(1) * MB%MP(1) * MC%MP(1) < 0) THEN\n IF (MA_VS_MBMC == 1) THEN\n MGD = 0\n K1 = 2 + MA%MP(2) - MB%MP(2) - MC%MP(2)\n DO J = K1, NDIG\n MBJ = MB%MP(3+J-K1)\n KPTA = 2+J\n KPTC = 3\n DO K = J, NDIG\n MA%MP(KPTA) = MA%MP(KPTA) + MBJ * MC%MP(KPTC)\n KPTA = KPTA + 1\n KPTC = KPTC + 1\n ENDDO\n IF (KPTC <= 2+NDIG) MGD = MGD + MBJ * MC%MP(KPTC)\n ENDDO\n K1 = MA%MP(2)\n MA%MP(2) = 0\n KPTA = 3+NDIG\n MA%MP(KPTA-1) = MA%MP(KPTA-1) + NINT( MGD / MBASE )\n DO J = NDIG, 1, -1\n KPTA = KPTA - 1\n IF (MA%MP(KPTA) >= MBASE) THEN\n K = MA%MP(KPTA) / MBASE\n MA%MP(KPTA) = MA%MP(KPTA) - K * MBASE\n MA%MP(KPTA-1) = MA%MP(KPTA-1) + K\n ENDIF\n ENDDO\n IF (MA%MP(2) > 0) THEN\n DO J = NDIG, 1, -1\n MA%MP(2+J) = MA%MP(2+J-1)\n ENDDO\n K1 = K1 + 1\n ENDIF\n MA%MP(2) = K1\n IF (MA%MP(3) >= MBASE) THEN\n DO J = NDIG, 3, -1\n MA%MP(2+J) = MA%MP(2+J-1)\n ENDDO\n K = MA%MP(3) / MBASE\n MA%MP(4) = MA%MP(3) - K * MBASE\n MA%MP(3) = K\n MA%MP(2) = MA%MP(2) + 1\n ENDIF\n ENDIF\n\n IF (MA_VS_MBMC == -1) THEN\n MGD = 0\n K1 = MB%MP(2) + MC%MP(2) - 1\n K = MB%MP(2) + MC%MP(2) - MA%MP(2) - 1\n MA%MP(2) = 0\n IF (K > 0) THEN\n IF (K <= NDIG) MGD = MA%MP(2+NDIG+1-K)\n DO J = NDIG, K+1, -1\n MA%MP(2+J) = MA%MP(2+J-K)\n ENDDO\n DO J = 1, MIN(K,NDIG)\n MA%MP(2+J) = 0\n ENDDO\n ELSE IF (K == -1) THEN\n DO J = 1, NDIG\n MA%MP(1+J) = MA%MP(1+J+1)\n ENDDO\n MA%MP(2+NDIG) = 0\n ENDIF\n\n DO J = 1, NDIG\n MBJ = MB%MP(2+J)\n KPTA = 2+J\n KPTC = 3\n DO K = J, NDIG\n MA%MP(KPTA) = MA%MP(KPTA) + MBJ * MC%MP(KPTC)\n KPTA = KPTA + 1\n KPTC = KPTC + 1\n ENDDO\n IF (KPTC <= 2+NDIG) MGD = MGD + MBJ * MC%MP(KPTC)\n ENDDO\n KPTA = 3+NDIG\n MA%MP(KPTA-1) = MA%MP(KPTA-1) + NINT( MGD / MBASE )\n DO J = NDIG, 1, -1\n KPTA = KPTA - 1\n IF (MA%MP(KPTA) >= MBASE) THEN\n K = MA%MP(KPTA) / MBASE\n MA%MP(KPTA) = MA%MP(KPTA) - K * MBASE\n MA%MP(KPTA-1) = MA%MP(KPTA-1) + K\n ENDIF\n ENDDO\n IF (MA%MP(2) > 0) THEN\n DO J = NDIG, 1, -1\n MA%MP(2+J) = MA%MP(2+J-1)\n ENDDO\n K1 = K1 + 1\n ENDIF\n MA%MP(2) = K1\n IF (MA%MP(3) >= MBASE) THEN\n DO J = NDIG, 3, -1\n MA%MP(2+J) = MA%MP(2+J-1)\n ENDDO\n K = MA%MP(3) / MBASE\n MA%MP(4) = MA%MP(3) - K * MBASE\n MA%MP(3) = K\n MA%MP(2) = MA%MP(2) + 1\n ENDIF\n ENDIF\n\n ELSE\n CALL FMEQ(MA,MXY)\n\n IF (MA_VS_MBMC == 1) THEN\n MGD = 0\n K1 = 2 + MA%MP(2) - MB%MP(2) - MC%MP(2)\n DO J = K1, NDIG\n MBJ = MB%MP(3+J-K1)\n KPTA = 2+J\n KPTC = 3\n DO K = J, NDIG\n MA%MP(KPTA) = MA%MP(KPTA) - MBJ * MC%MP(KPTC)\n KPTA = KPTA + 1\n KPTC = KPTC + 1\n ENDDO\n IF (KPTC <= 2+NDIG) MGD = MGD - MBJ * MC%MP(KPTC)\n ENDDO\n K1 = MA%MP(2)\n MA%MP(2) = 0\n KPTA = 3+NDIG\n MA%MP(KPTA-1) = MA%MP(KPTA-1) + NINT( MGD / MBASE )\n DO J = NDIG, 1, -1\n KPTA = KPTA - 1\n IF (MA%MP(KPTA) < 0) THEN\n K = (-MA%MP(KPTA)-1) / MBASE + 1\n MA%MP(KPTA) = MA%MP(KPTA) + K * MBASE\n MA%MP(KPTA-1) = MA%MP(KPTA-1) - K\n ELSE IF (MA%MP(KPTA) >= MBASE) THEN\n K = MA%MP(KPTA) / MBASE\n MA%MP(KPTA) = MA%MP(KPTA) - K * MBASE\n MA%MP(KPTA-1) = MA%MP(KPTA-1) + K\n ENDIF\n ENDDO\n IF (MA%MP(2) > 0) THEN\n DO J = NDIG, 1, -1\n MA%MP(2+J) = MA%MP(2+J-1)\n ENDDO\n K1 = K1 + 1\n ENDIF\n MA%MP(2) = K1\n IF (MA%MP(3) == 0) THEN\n CALL FMMPY(MB,MC,MA)\n CALL FMSUB_R2(MXY,MA)\n RETURN\n ENDIF\n ENDIF\n\n IF (MA_VS_MBMC == -1) THEN\n MGD = 0\n K1 = MB%MP(2) + MC%MP(2) - 1\n K = MB%MP(2) + MC%MP(2) - MA%MP(2) - 1\n MA%MP(2) = 0\n IF (K > 0) THEN\n IF (K <= NDIG) MGD = -MA%MP(2+NDIG+1-K)\n DO J = NDIG, K+1, -1\n MA%MP(2+J) = -MA%MP(2+J-K)\n ENDDO\n DO J = 1, MIN(K,NDIG)\n MA%MP(2+J) = 0\n ENDDO\n ELSE IF (K == -1) THEN\n DO J = 1, NDIG\n MA%MP(1+J) = -MA%MP(1+J+1)\n ENDDO\n MA%MP(2+NDIG) = 0\n ELSE IF (K == 0) THEN\n DO J = 1, NDIG\n MA%MP(2+J) = -MA%MP(2+J)\n ENDDO\n ENDIF\n\n DO J = 1, NDIG\n MBJ = MB%MP(2+J)\n KPTA = 2+J\n KPTC = 3\n DO K = J, NDIG\n MA%MP(KPTA) = MA%MP(KPTA) + MBJ * MC%MP(KPTC)\n KPTA = KPTA + 1\n KPTC = KPTC + 1\n ENDDO\n IF (KPTC <= 2+NDIG) MGD = MGD + MBJ * MC%MP(KPTC)\n ENDDO\n KPTA = 3+NDIG\n MA%MP(KPTA-1) = MA%MP(KPTA-1) + NINT( MGD / MBASE )\n DO J = NDIG, 1, -1\n KPTA = KPTA - 1\n IF (MA%MP(KPTA) >= MBASE) THEN\n K = MA%MP(KPTA) / MBASE\n MA%MP(KPTA) = MA%MP(KPTA) - K * MBASE\n MA%MP(KPTA-1) = MA%MP(KPTA-1) + K\n ELSE IF (MA%MP(KPTA) < 0) THEN\n K = (-MA%MP(KPTA)-1) / MBASE + 1\n MA%MP(KPTA) = MA%MP(KPTA) + K * MBASE\n MA%MP(KPTA-1) = MA%MP(KPTA-1) - K\n ENDIF\n ENDDO\n IF (MA%MP(2) > 0) THEN\n DO J = NDIG, 1, -1\n MA%MP(2+J) = MA%MP(2+J-1)\n ENDDO\n K1 = K1 + 1\n ENDIF\n MA%MP(2) = K1\n MA%MP(1) = -MA%MP(1)\n IF (MA%MP(3) == 0) THEN\n CALL FMMPY(MB,MC,MA)\n CALL FMSUB_R2(MXY,MA)\n RETURN\n ENDIF\n ENDIF\n\n RETURN\n ENDIF\n END SUBROUTINE FMMPY_SUB\n\n SUBROUTINE FM_RK14( A, B, N_ORDER, FM_RK14_F, N_FUNCTION, S, TOL, S1 )\n\n! Solve the vector first-order differential equation s' = f(x,s).\n\n! This routine uses 14th order Runge-Kutta with adjustable step size, starting at x = A\n! with state vector S (initial conditions), and returns state vector S1 as the solution\n! at x = B.\n\n! N_ORDER is the order of the differential equation (length of vectors S and S1).\n\n! N_FUNCTION is the function number (used in FM_RK14_F) identifying which function f(x,s)\n! defines the right-hand-side of the differential equation to be solved.\n\n! TOL is the absolute error tolerance. Because the coefficients are defined with no more than\n! about 85-digit precision, TOL should not be less than 1.0e-75.\n\n! The FM precision level should be set to at least 10 digits more than TOL.\n! For example, set precision with CALL FM_SET(30) if FM_RK14 will be called with TOL = 1.0e-20.\n\n! The error estimate that is used to control step size will fail if f(x,s) is a function of\n! x only, not depending on s. In this case, the differential equation is really just an\n! integration problem and should be done as a numerical integration.\n\n USE FMZM\n IMPLICIT NONE\n\n INTEGER, PARAMETER :: MAXIMUM_ORDER = 3\n INTEGER :: J, N_ORDER, N_FUNCTION\n TYPE (FM) :: A, B, TOL, S(MAXIMUM_ORDER), S1(MAXIMUM_ORDER)\n TYPE (FM), SAVE :: ERROR_EST, H, TOL2, X\n EXTERNAL :: FM_RK14_F\n LOGICAL, SAVE :: LAST_STEP\n\n\n IF (TOL < TO_FM(' 1.0e-75 ')) THEN\n WRITE (*,*) ' '\n WRITE (*,*) ' Error in input to FM_RK14. TOL should not be less than 1.0e-75. It was'\n CALL FM_PRINT(TOL)\n WRITE (*,*) ' '\n STOP\n ENDIF\n\n! Pick an initial step size.\n\n TOL2 = ABS(TOL) / 1000\n H = ABS(TOL2)**(1.0D0/14)\n\n X = A\n LAST_STEP = .FALSE.\n\n DO J = 1, 10**7\n IF (X+H >= B) THEN\n H = B - X\n LAST_STEP = .TRUE.\n ENDIF\n CALL FM_RK14_STEP( N_ORDER, FM_RK14_F, N_FUNCTION, X, S, H, ERROR_EST, S1 )\n\n! If the error is too big, try again with halved step size.\n\n IF (ERROR_EST > TOL2) THEN\n H = H / 2\n CYCLE\n ENDIF\n\n! Make the step.\n\n IF (LAST_STEP) THEN\n EXIT\n ENDIF\n S(1:N_ORDER) = S1(1:N_ORDER)\n X = X + H\n\n! If the error is much smaller than TOL2, try doubling the step size.\n! Otherwise, if the error is less than TOL2/10, try to fine-tune the\n! step size by increasing H slightly.\n\n IF (ERROR_EST < TOL2/1.0D+5) THEN\n H = 2*H\n ELSE IF (ERROR_EST < TOL2/10) THEN\n H = 1.05*H\n ENDIF\n ENDDO\n\n END SUBROUTINE FM_RK14\n\n SUBROUTINE FM_RK14_STEP( N_ORDER, FM_RK14_F, N_FUNCTION, X, S, H, ERROR_EST, S1 )\n\n! Do one step of 14th order Runge-Kutta, starting with state vector S(X) and returning\n! state vector S1(X+H) after a step of H.\n! N_ORDER is the order of the differential equation (length of vector S).\n! N_FUNCTION is the function number (used in FM_RK14_F) identifying which function is to be solved.\n\n USE FMVALS\n USE FMZM\n IMPLICIT NONE\n\n INTEGER, PARAMETER :: MAXIMUM_ORDER = 3\n INTEGER :: J, K, N_STAGES, N_ORDER, N_FUNCTION\n TYPE (FM) :: H, ERROR_EST, S(MAXIMUM_ORDER), S1(MAXIMUM_ORDER), X\n TYPE (FM), SAVE :: A(0:34), B(0:34,0:34), C(0:34), FI_J(MAXIMUM_ORDER,0:34), &\n FI(MAXIMUM_ORDER), YK(0:34,MAXIMUM_ORDER), Y(MAXIMUM_ORDER)\n EXTERNAL :: FM_RK14_F\n INTEGER, SAVE :: COEFF_BASE = 0, COEFF_PRECISION = 0\n\n N_STAGES = 35\n\n IF (COEFF_BASE /= MBASE .OR. COEFF_PRECISION < NDIG) THEN\n COEFF_BASE = MBASE\n COEFF_PRECISION = NDIG\n CALL FM_RK14_COEFFS(A, B, C)\n ENDIF\n\n! Do the step.\n\n YK(0,1:N_ORDER) = S(1:N_ORDER)\n DO K = 1, N_STAGES - 1\n YK(K,1:N_ORDER) = 0\n DO J = 0, K-1\n IF (J == K-1) THEN\n Y(1:N_ORDER) = YK(J,1:N_ORDER)\n CALL FM_RK14_F(N_ORDER, N_FUNCTION, X+A(J)*H, Y, FI)\n FI_J(1:N_ORDER,J) = FI(1:N_ORDER)\n ENDIF\n IF (B(K,J) /= 0) THEN\n YK(K,1:N_ORDER) = YK(K,1:N_ORDER) + B(K,J) * FI_J(1:N_ORDER,J)\n ENDIF\n ENDDO\n YK(K,1:N_ORDER) = YK(0,1:N_ORDER) + H * YK(K,1:N_ORDER)\n ENDDO\n\n S1(1:N_ORDER) = 0\n DO K = 0, N_STAGES - 1\n IF (K == N_STAGES-1) THEN\n Y(1:N_ORDER) = YK(K,1:N_ORDER)\n CALL FM_RK14_F(N_ORDER, N_FUNCTION, X+A(K)*H, Y, FI)\n S1(1:N_ORDER) = S1(1:N_ORDER) + C(K) * FI(1:N_ORDER)\n ELSE\n S1(1:N_ORDER) = S1(1:N_ORDER) + C(K) * FI_J(1:N_ORDER,K)\n ENDIF\n ENDDO\n\n S1(1:N_ORDER) = S(1:N_ORDER) + H * S1(1:N_ORDER)\n\n ERROR_EST = H * ( NORM2( FI_J(1:N_ORDER,33) - FI_J(1:N_ORDER,1) ) ) / 1000\n\n END SUBROUTINE FM_RK14_STEP\n\n SUBROUTINE FM_RK14_COEFFS(A, B, C)\n\n! Define the coefficients used in the RK14 formula (85 digits).\n\n! These came from:\n! http://www.peterstone.name/Maplepgs/Maple/nmthds/RKcoeff/Runge_Kutta_schemes/RK14/RKcoeff14a_1.pdf\n\n USE FMZM\n IMPLICIT NONE\n\n TYPE (FM) :: A(0:34), B(0:34,0:34), C(0:34)\n\n! Many of the coefficients are zero. Initialize A, B, and C here, then\n! skip those definitions below.\n\n A = 0\n B = 0\n C = 0\n\n A( 1) = TO_FM(' 1 ') / 9\n A( 2) = TO_FM(' 5 ') / 9\n A( 3) = TO_FM(' 5 ') / 6\n A( 4) = TO_FM(' 1 ') / 3\n A( 5) = TO_FM(' 1 ')\n A( 6) = TO_FM(' .6699869792727729217646837855059985139388452296384603532851421391683474428303956826239 ')\n A( 7) = TO_FM(' .2970683842138183573895847168082194132233320946989156873791682903324708698499266217383 ')\n A( 8) = TO_FM(' 8 ') / 11\n A( 9) = TO_FM(' .1401527990421887652761874879669467176298064630825329362873230163439023340348096838456 ')\n A(10) = TO_FM(' .7007010397701507371510998548307493379414070492655464089692218490447945746638665522966 ')\n A(11) = TO_FM(' 4 ') / 11\n A(12) = TO_FM(' 5 ') / 19\n A(13) = TO_FM(' .392172246650270859125196642501208648863714315266128052078483e-1 ')\n A(14) = TO_FM(' .8129175029283767629833931592780365061896123726172385507744269795906758195776958783707 ')\n A(15) = TO_FM(' 1 ') / 6\n A(16) = TO_FM(' 9 ') / 10\n A(17) = TO_FM(' .6412992574519669233127711938966828094810966516150832254029235721305050295351572963693e-1 ')\n A(18) = TO_FM(' .2041499092834288489277446343010234050271495052413337516288702042649259099754335560687 ')\n A(19) = TO_FM(' .3953503910487605656156713698273243723522272974566594505545766538389345381768585023057 ')\n A(20) = TO_FM(' .6046496089512394343843286301726756276477727025433405494454233461610654618231414976943 ')\n A(21) = TO_FM(' .7958500907165711510722553656989765949728504947586662483711297957350740900245664439313 ')\n A(22) = TO_FM(' .9358700742548033076687228806103317190518903348384916774597076427869494970464842703631 ')\n A(23) = TO_FM(' 1 ') / 6\n A(24) = TO_FM(' .8129175029283767629833931592780365061896123726172385507744269795906758195776958783707 ')\n A(25) = TO_FM(' .392172246650270859125196642501208648863714315266128052078483e-1 ')\n A(26) = TO_FM(' 4 ') / 11\n A(27) = TO_FM(' .7007010397701507371510998548307493379414070492655464089692218490447945746638665522966 ')\n A(28) = TO_FM(' .1401527990421887652761874879669467176298064630825329362873230163439023340348096838456 ')\n A(29) = TO_FM(' .2970683842138183573895847168082194132233320946989156873791682903324708698499266217383 ')\n A(30) = TO_FM(' .6699869792727729217646837855059985139388452296384603532851421391683474428303956826239 ')\n A(31) = TO_FM(' 1 ') / 3\n A(32) = TO_FM(' 5 ') / 9\n A(33) = TO_FM(' 1 ') / 9\n A(34) = TO_FM(' 1 ')\n\n C( 0) = TO_FM(' 1 ') / 56\n C( 1) = TO_FM(' 3 ') / 512\n C( 2) = TO_FM(' 3 ') / 256\n C( 4) = TO_FM(' 9 ') / 512\n C( 6) = TO_FM(' 3 ') / 128\n C( 7) = TO_FM(' 15 ') / 512\n C( 9) = TO_FM(' 9 ') / 256\n C(10) = TO_FM(' 21 ') / 512\n C(11) = TO_FM(' 3 ') / 64\n C(13) = TO_FM(' 27 ') / 512\n C(14) = TO_FM(' 15 ') / 256\n C(15) = TO_FM(' 33 ') / 512\n C(17) = TO_FM(' .1053521135717530196914960328878781622276730830805238840416702908213176249782427570033 ')\n C(18) = TO_FM(' .1705613462417521823821203385538740858875554878027908047375010369442754416180982144816 ')\n C(19) = TO_FM(' .2062293973293519407835264857011048947419142862595424540779715293772640762608018856579 ')\n C(20) = TO_FM(' .2062293973293519407835264857011048947419142862595424540779715293772640762608018856579 ')\n C(21) = TO_FM(' .1705613462417521823821203385538740858875554878027908047375010369442754416180982144816 ')\n C(22) = TO_FM(' .1053521135717530196914960328878781622276730830805238840416702908213176249782427570033 ')\n C(23) = TO_FM(' -33 ') / 512\n C(24) = TO_FM(' -15 ') / 256\n C(25) = TO_FM(' -27 ') / 512\n C(26) = TO_FM(' -3 ') / 64\n C(27) = TO_FM(' -21 ') / 512\n C(28) = TO_FM(' -9 ') / 256\n C(29) = TO_FM(' -15 ') / 512\n C(30) = TO_FM(' -3 ') / 128\n C(31) = TO_FM(' -9 ') / 512\n C(32) = TO_FM(' -3 ') / 256\n C(33) = TO_FM(' -3 ') / 512\n C(34) = TO_FM(' 1 ') / 56\n\n B( 1, 0) = TO_FM(' 1 ') / 9\n B( 2, 0) = TO_FM(' -5 ') / 6\n B( 2, 1) = TO_FM(' 25 ') / 18\n B( 3, 0) = TO_FM(' 5 ') / 24\n B( 3, 2) = TO_FM(' 5 ') / 8\n B( 4, 0) = TO_FM(' 29 ') / 150\n B( 4, 2) = TO_FM(' 11 ') / 50\n B( 4, 3) = TO_FM(' -2 ') / 25\n B( 5, 0) = TO_FM(' 1 ') / 10\n B( 5, 3) = TO_FM(' 2 ') / 5\n B( 5, 4) = TO_FM(' 1 ') / 2\n B( 6, 0) = TO_FM(' .1034845616366797766729935465119103444997447982019713166066629728281981965079290745983 ')\n B( 6, 3) = TO_FM(' .1220688873064072225896440828689620771395927148341621347412746563709055937325311521675 ')\n B( 6, 4) = TO_FM(' .4825744903312466224751347801256881128659190238501680496794015023696413273862321544150 ')\n B( 6, 5) = TO_FM(' -.3814096000156069997308862400056202056641130724784114774219699240039767479629669855696e-1 ')\n B( 7, 0) = TO_FM(' .1243805266540944128815164208687993162684914663596714231632892354628068537117612942798 ')\n B( 7, 4) = TO_FM(' .2261202821975843014222386629792029011967523207426331439651447460281196206643404356021 ')\n B( 7, 5) = TO_FM(' .1378858876180808806076958370164778145309694174914933853635428709475288586061552782365e-1 ')\n B( 7, 6) = TO_FM(' -.6722101339966844497493995074143058569500863415253821828561997825320849038679063596730e-1 ')\n B( 8, 0) = TO_FM(' .9369190656596738155308854560830059338663496952177500856556033862893464429241815101000e-1 ')\n B( 8, 5) = TO_FM(' -.6134068434505109872294989956416647356209145071288588710070986068372475355320835997035e-2 ')\n B( 8, 6) = TO_FM(' .2160198256255030637088600976598665734909794332781173201886676706066128640340557614360 ')\n B( 8, 7) = TO_FM(' .4236950635157619373376190739609767532058674695441235326831157041055522397561196508237 ')\n B( 9, 0) = TO_FM(' .8384798124090526646169687913728140859805331392249111310693346670107922625197375034871e-1 ')\n B( 9, 5) = TO_FM(' -.1179493671009738143197550560312957753679619605907361507776128268875265788248790903515e-1 ')\n B( 9, 6) = TO_FM(' -.2472990205688126523394738387431945983259928403533401326974984247503501083158412965835 ')\n B( 9, 7) = TO_FM(' .9780808583677290122593130140812916655037406554767339407565991037499621093437371932341e-1 ')\n B( 9, 8) = TO_FM(' .2175906892434206313600086517678603183441681200247821768799893467069296630467914197921 ')\n B(10, 0) = TO_FM(' .6152553597694282279545623896143147143334239690648211074539397569215087099333654844097e-1 ')\n B(10, 5) = TO_FM(' .5922327803245033080429900057980465247383895604442571368349896773084347972825775455007e-2 ')\n B(10, 6) = TO_FM(' .4703261599638411122172243032058941134553625307461088250108483236601604516650193568134 ')\n B(10, 7) = TO_FM(' .2996888638486790008539818370961923991368311216717812791841936858888827504094204242461 ')\n B(10, 8) = TO_FM(' -.2476568775939949146899922763298108258539580692639470955481886317480090967647905771626 ')\n B(10, 9) = TO_FM(' .1108950297714376828939998518390617145224451736006787182086245987785252503880550245038 ')\n B(11, 0) = TO_FM(' .4197000733627825798617928647872777872134836565431046112459945389674655429048057710370e-1 ')\n B(11, 5) = TO_FM(' -.317987696266205093901912847692712407988609169703103952205634e-2 ')\n B(11, 6) = TO_FM(' .8063977149061920772608217115203795063935431115674197501197468839656405367779525213500 ')\n B(11, 7) = TO_FM(' .9759831264123889790935228506842888513146720480030545503571875185550549213299958241991e-1 ')\n B(11, 8) = TO_FM(' .7785755781583989090275124464529272389997634605941819649588520345133050850477185489203 ')\n B(11, 9) = TO_FM(' .2048904238315994281894992020981056033120292350814206535748293420400885242747823516625 ')\n B(11,10) = TO_FM(' -1.562615796274681883070709439505278252114628922364243608928053762634922556160297217820 ')\n B(12, 0) = TO_FM(' .4377267822337301635744652424953398116882149670716141232569729223172939742940416733395e-1 ')\n B(12, 8) = TO_FM(' .6243650275201952087943586285809336252816312169030959172012504609444028241438248581173e-2 ')\n B(12, 9) = TO_FM(' .2000430971095773149944351654696478568290662322182649696087680691197048872391143823078 ')\n B(12,10) = TO_FM(' -.8053283678049830368238571620489029119233928873370293148442058928084075077460302544840e-2 ')\n B(12,11) = TO_FM(' .2115175280673965219157119035233996013168778251575505730512208770404786743066139905871e-1 ')\n B(13, 0) = TO_FM(' .2834992503635145630950235919207173122471376548964770977684956012393009143065795513785e-1 ')\n B(13, 8) = TO_FM(' .2491632048558174075389491488059951494598846535854176800982219995075912885766744587193e-2 ')\n B(13, 9) = TO_FM(' .2301387878545931496383998463737427687720871226381422342236583655735620108657836993957e-1 ')\n B(13,10) = TO_FM(' -.3221559566929770987244760924671208781894636047606204610433085107190031098987004938258e-2 ')\n B(13,11) = TO_FM(' .9884425494476646689463354144878852560408199827860146481292993078049373245839618405001e-2 ')\n B(13,12) = TO_FM(' -.2130107713288873513843076428759273848866345654295724666320922464722154754985568313136e-1 ')\n B(14, 0) = TO_FM(' .3435118942902430010494322347351479430833531749807014262686507474123120416010457867571 ')\n B(14, 8) = TO_FM(' .2104519120236273856090970119990106557888074052256267000419050051487632641518018732685 ')\n B(14, 9) = TO_FM(' 1.034274520572304119364829268288257099386679996983247401666929134177931632176349026735 ')\n B(14,10) = TO_FM(' .6003036458644224870512404482066405749390780924061569454673075686417142117164254262878e-2 ')\n B(14,11) = TO_FM(' .8559381250996195375780121060024077289150626526164160058172684354881277648341960563008 ')\n B(14,12) = TO_FM(' -.9772350050367668108722648523725256330131076568928396776974412446349105799705851506077 ')\n B(14,13) = TO_FM(' -.6600269804792946946162250138563276937205739812199748747775581736879654453322759683463 ')\n B(15, 0) = TO_FM(' -.1435740016721680695382063999350763666577559543783998809757153672896315044426183882232e-1 ')\n B(15, 8) = TO_FM(' -.3662532700490399702936857968489747917331190817335522078657913621382824038988807796287e-1 ')\n B(15, 9) = TO_FM(' .3502549756362136819768494069798465243467890824711035742020654749717518291597210559354e-1 ')\n B(15,10) = TO_FM(' .3609460163621135089317866587583352398236899298642376718895880083960486970547825683491e-1 ')\n B(15,11) = TO_FM(' -.2652199675536811063515959468346019236496270124574642848667252606942739787160130682669e-1 ')\n B(15,12) = TO_FM(' .4456990113056981196389115375088399081043363230822267716707629092315111479614958673268e-1 ')\n B(15,13) = TO_FM(' .1243430933313582432862255957417864480389734088951067419167759990001419776217292554191 ')\n B(15,14) = TO_FM(' .4138296932394806944035124962043359604261929086744760344472227418812310333088685698274e-2 ')\n B(16, 0) = TO_FM(' .3560324044251202909756091163980891762641062223797488026536968101501275805051289760823 ')\n B(16, 8) = TO_FM(' -.450192758947562595966821779075956175110645100214763601190349 ')\n B(16, 9) = TO_FM(' .430527907083710898626656292808782917793030154094709462877146 ')\n B(16,10) = TO_FM(' .5119730290110222376685569603940716920771257870306513863906805244405042813755411512463 ')\n B(16,11) = TO_FM(' .9083036388864042603901591246381102139974962148199046305445452541870528153933236088278 ')\n B(16,12) = TO_FM(' -1.239210933719339317573724691515340288544138892486057261860887966510000755220957594942 ')\n B(16,13) = TO_FM(' -.6490486616717614651416723488790625539054028319671910976544025456235491510559878435372 ')\n B(16,14) = TO_FM(' .2517089045868192922104805299489705414048878529314474912189256354259853776829630937658 ')\n B(16,15) = TO_FM(' .7799064703455863988107567952823344760235405934115501870206452879298798513199886085571 ')\n B(17, 0) = TO_FM(' .1309356874065130664068812064188349801274704382131924878449566575565302965696195341197e-1 ')\n B(17,12) = TO_FM(' -.9320530679851139459084619627671082378586315096846671421247697017556505173897578610165e-4 ')\n B(17,13) = TO_FM(' .5053743342622993596400904431385907267709423447161223817027456630856526555478831396014e-1 ')\n B(17,14) = TO_FM(' .8044703419444879791095791096101977976413118689308653610493721999399129417586629251430e-6 ')\n B(17,15) = TO_FM(' .5917260294941711905287557427777172598443409719243215281782302034071342229921661278343e-3 ')\n B(17,16) = TO_FM(' -.4016147221545573370646916849063755877322642479500938046774565993013424294867398455789e-6 ')\n B(18, 0) = TO_FM(' .2079264844660530125419445440007656521672552061443734079797586969853055549175505457737e-1 ')\n B(18,12) = TO_FM(' .5826959188000859151019026978372841089514061030298715701031065480360641416298102920851e-3 ')\n B(18,13) = TO_FM(' -.8017007323588159390833421865258527466405584659196335246554992680506588169863285718822e-2 ')\n B(18,14) = TO_FM(' .4038476438471369403751708217435605704841172903308955066191655368223862388605213690921e-5 ')\n B(18,15) = TO_FM(' .8546099980555061442250561145675356025101146220336224918025961310211940592009621595606e-1 ')\n B(18,16) = TO_FM(' -.2044864809358042427067075696910043079044428375526774562331430989116458814609927891477e-5 ')\n B(18,17) = TO_FM(' .1053285788244318933997994029790939973542409042351728431465827473723673651882417656762 ')\n B(19, 0) = TO_FM(' 1.401534497957360214154462473557713067184864529175977331289881318884096354294079099114 ')\n B(19,12) = TO_FM(' -.2302520009842212616162724103674156212611302982744556219175010157057031125814669239016 ')\n B(19,13) = TO_FM(' -7.211068404669129056595822371068742471658564935099615697324849532576890894506619405031 ')\n B(19,14) = TO_FM(' .3729015606948363352369953278521323402177595666786623882373057096229137360164435411243e-2 ')\n B(19,15) = TO_FM(' -4.714154957271250206787781793922247570113233732218200980194845522013711035054762664884 ')\n B(19,16) = TO_FM(' -.1763676575453492420538419950327976735749038866956001340593194717236122233799126229446e-2 ')\n B(19,17) = TO_FM(' 7.641305480386987655630293108802376511851733678139370059818519661401442202665741111270 ')\n B(19,18) = TO_FM(' 3.506020436597518349898960829497447109682129498933753736341591881470708008233521976557 ')\n B(20, 0) = TO_FM(' 11.95146506941206867993723858307164016744736108265535168242754934626543968357331742096 ')\n B(20,12) = TO_FM(' 7.794809321081759687835167002317643882202842795989809549197917776161588225206322580459 ')\n B(20,13) = TO_FM(' -56.45013938673257925235609911209042814404681000613405538635967763011214022629172907669 ')\n B(20,14) = TO_FM(' .9123763069306449013445304492902766457096074504036737047499704936582270274950128398912e-1 ')\n B(20,15) = TO_FM(' -12.73362799254348862019455243091992750381627175299189605168457824373779389828110581300 ')\n B(20,16) = TO_FM(' -.3968959219047197123135428109397366747123830704331478729319411886202118671113516172493e-1 ')\n B(20,17) = TO_FM(' 54.43921418835708869962257651553077918614383784233053341001985423053366890118247056463 ')\n B(20,18) = TO_FM(' -3.644116379215692368464069903613506458067214784092667356589342345057374050114156075061 ')\n B(20,19) = TO_FM(' -.8045032499105099108990307879585794993156949132107878807481027183961246894903442258757 ')\n B(21, 0) = TO_FM(' -148.8094265071004884278388682686476255619306120821485965777899951377767737092911763254 ')\n B(21,12) = TO_FM(' -91.72952782912564843579356624023216234952287290363542836291360346578688265538801398361 ')\n B(21,13) = TO_FM(' 707.6561449715983598345757192863357161548211289666495623584804744987957677893379157809 ')\n B(21,14) = TO_FM(' -1.10563611857482440905296961311590930801338308942637769555540 ')\n B(21,15) = TO_FM(' 176.1345918838113725878598980760556604069995167623016865882869129962911416096097878945 ')\n B(21,16) = TO_FM(' .4913848242148806622688983451644545574168846314027647925019604519368994965045299923826 ')\n B(21,17) = TO_FM(' -684.2780004498149443582375356108950819560771678936002751371799726829821841834791232605 ')\n B(21,18) = TO_FM(' 27.99106049983982589842243321243804074460025184006686868209688958109916979926727384229 ')\n B(21,19) = TO_FM(' 13.19397100302823334436709643711532384350641596237449753683872220663989495376087330358 ')\n B(21,20) = TO_FM(' 1.251287812839804454501149741480560063172688300773964063605141347518040989702499199856 ')\n B(22, 0) = TO_FM(' -9.673079469481967636441261184332193958399514085718772596349277868068021458303626779169 ')\n B(22,12) = TO_FM(' -4.469901508585055314438462277019603604978306814087514357488023393670679083633020106516 ')\n B(22,13) = TO_FM(' 45.51271286909526819682419504000527511789059078173984816890412459840121969200961260987 ')\n B(22,14) = TO_FM(' -.713085086183826912791492024438246129930559805352394367050813e-1 ')\n B(22,15) = TO_FM(' 11.22736140684127415825906244799393842078268007767944830815221105133516977144595052189 ')\n B(22,16) = TO_FM(' .1262443767176227245162379129091388093617868898191054263714925416869147773104813482457 ')\n B(22,17) = TO_FM(' -43.54393395494833136058106249072421076238143044676214056937881652359375369765457150165 ')\n B(22,18) = TO_FM(' .7871743075430589783987929949965509020645460914432340378113766124779028133099797867162 ')\n B(22,19) = TO_FM(' .5322646967446842156693007086038866907853957768215038536520118921656033723449302296244 ')\n B(22,20) = TO_FM(' .4224227339963253260102251274713887725750865388096033468497941673910509540050957057177 ')\n B(22,21) = TO_FM(' .8591312495030671073084380314998594434411150562941549563989586466154235621165245563192e-1 ')\n B(23, 0) = TO_FM(' -10.06640324470547024033966069004268914722028247579687652710623604380152449409080444899 ')\n B(23, 8) = TO_FM(' -.3662532700490399702936857968489747917331190817335522078657913621382824038988807796287e-1 ')\n B(23, 9) = TO_FM(' .3502549756362136819768494069798465243467890824711035742020654749717518291597210559354e-1 ')\n B(23,10) = TO_FM(' .3609460163621135089317866587583352398236899298642376718895880083960486970547825683491e-1 ')\n B(23,11) = TO_FM(' -.2652199675536811063515959468346019236496270124574642848667252606942739787160130682669e-1 ')\n B(23,12) = TO_FM(' -6.270889721814641435905531494788716038393561229573960230194057818533161624674313994502 ')\n B(23,13) = TO_FM(' 48.20792374425629890907021030081950639234925931416361161278899187780407980462426656808 ')\n B(23,14) = TO_FM(' -.694471689136165640882395180583732834557754169149088630301342e-1 ')\n B(23,15) = TO_FM(' 12.68106902048502956983413709136098070661084838114121251454273060707937017246509534894 ')\n B(23,16) = TO_FM(' .119671168968323754838161435501011294100927813964199613229864e-1 ')\n B(23,17) = TO_FM(' -46.72497649924824080033582682426626955932013216597956070401309263301039263373634230581 ')\n B(23,18) = TO_FM(' 1.330296133266267113147100392982165913990335111912271192356479099067512051132965697343 ')\n B(23,19) = TO_FM(' 1.007667875033982983534389036199266577711627177936617199056121787956529680139072027935 ')\n B(23,20) = TO_FM(' .2095120519336650916641223884754807028927707538644872411247284065032940106679251005781e-1 ')\n B(23,21) = TO_FM(' .2101347063312641773177354243313964074244121884437574908902263894855162847478911411134e-1 ')\n B(23,22) = TO_FM(' .9521960144171217941751015424545759073763602336583562405468424451848266905185171865534e-2 ')\n B(24, 0) = TO_FM(' -409.4780816777437087725890974093703576244243416067520683455326035855162023776088699896 ')\n B(24, 8) = TO_FM(' .2104519120236273856090970119990106557888074052256267000419050051487632641518018732685 ')\n B(24, 9) = TO_FM(' 1.034274520572304119364829268288257099386679996983247401666929134177931632176349026735 ')\n B(24,10) = TO_FM(' .6003036458644224870512404482066405749390780924061569454673075686417142117164254262878e-2 ')\n B(24,11) = TO_FM(' .8559381250996195375780121060024077289150626526164160058172684354881277648341960563008 ')\n B(24,12) = TO_FM(' -250.5169985474478604927776577293161303865840504207820779326393997812026874735614210230 ')\n B(24,13) = TO_FM(' 1946.424666523884277660537503282647585958298508957614274560610260899186136259514015246 ')\n B(24,14) = TO_FM(' -3.045038821023103655061058090868608827869505440976021016842196622317831446605499698935 ')\n B(24,15) = TO_FM(' 490.6263795282817135212082652991680838415985422740616633051003594128766152337185220086 ')\n B(24,16) = TO_FM(' 1.566475895312709071154840670135974457395956152459667753199388690841173424714434871921 ')\n B(24,17) = TO_FM(' -1881.974289940111733622172673770358706192159066384530557689275696031792911993357071098 ')\n B(24,18) = TO_FM(' 75.25922247248471752788377136433031498216206189142459440229301807516615379972994062700 ')\n B(24,19) = TO_FM(' 34.57343569803310676224343447365546896967286447935510158001529990937243976348724448442 ')\n B(24,20) = TO_FM(' 3.211476794409689614354173618470737551690229667488916278855754113243135684398993410117 ')\n B(24,21) = TO_FM(' -.4604080417384143913072014042370588488672450952653828208427296561415079214017074427602 ')\n B(24,22) = TO_FM(' -.8707183398418105224318841379579862457242520473889365722145748143125162133630944128398e-1 ')\n B(24,23) = TO_FM(' -7.393518141583030675670169521955210639991857732491329543926346613193825315394087286297 ')\n B(25, 0) = TO_FM(' 3.433474758535508789210934962575967811206238910720084588712755786644583035514752699598 ')\n B(25, 8) = TO_FM(' .2491632048558174075389491488059951494598846535854176800982219995075912885766744587193e-2 ')\n B(25, 9) = TO_FM(' .2301387878545931496383998463737427687720871226381422342236583655735620108657836993957e-1 ')\n B(25,10) = TO_FM(' -.3221559566929770987244760924671208781894636047606204610433085107190031098987004938258e-2 ')\n B(25,11) = TO_FM(' .9884425494476646689463354144878852560408199827860146481292993078049373245839618405001e-2 ')\n B(25,12) = TO_FM(' 2.162527993779225077883078419047573540457592253357327094851479956564246957314476133478 ')\n B(25,13) = TO_FM(' -16.26998645464574213280656406601394890069875520402288517985775075363232756881970486667 ')\n B(25,14) = TO_FM(' -.1285345021205245528435834174709350105380290375426545062302651848844352856037884822181 ')\n B(25,15) = TO_FM(' -8.98915042666504253089307820833379330486511746063552853023189 ')\n B(25,16) = TO_FM(' -.3485953632320253333870802018510136501924017672505137649688730136175086767654181319387e-2 ')\n B(25,17) = TO_FM(' 15.79361941133398075362351873886955741358533870251397376656158275266140525531011608606 ')\n B(25,18) = TO_FM(' -.5744033309140950656281654820173358201483836631956754708231458398423255984252281047127 ')\n B(25,19) = TO_FM(' -.3456020390213932966927224966081249825352372288276553067081833889419898565070467534157 ')\n B(25,20) = TO_FM(' -.6622414902065850917316199913837577811330679927074186873906450413385445874036001388495e-2 ')\n B(25,21) = TO_FM(' -.7777881292422041640325464586073643097593472096267591120155367761150273183248441708392e-2 ')\n B(25,22) = TO_FM(' -.3560841924022749133388272326974373646752408187917065879526063406092336300493607300593e-2 ')\n B(25,23) = TO_FM(' 4.792825064499307996497977496298401894572969341393590555417712618624354747222657791607 ')\n B(25,24) = TO_FM(' .153725464873068577844576387402512082757034273069877432944621 ')\n B(26, 0) = TO_FM(' 32.30385208719854423269947344400315350913649750477846297617061421719281146058139852238 ')\n B(26, 5) = TO_FM(' -.317987696266205093901912847692712407988609169703103952205634e-2 ')\n B(26, 6) = TO_FM(' .8063977149061920772608217115203795063935431115674197501197468839656405367779525213500 ')\n B(26, 7) = TO_FM(' .9759831264123889790935228506842888513146720480030545503571875185550549213299958241991e-1 ')\n B(26, 8) = TO_FM(' .7785755781583989090275124464529272389997634605941819649588520345133050850477185489203 ')\n B(26, 9) = TO_FM(' .2048904238315994281894992020981056033120292350814206535748293420400885242747823516625 ')\n B(26,10) = TO_FM(' -1.562615796274681883070709439505278252114628922364243608928053762634922556160297217820 ')\n B(26,12) = TO_FM(' 16.34298918823105706485042439739271747087533535041545512917666902744198799725970841669 ')\n B(26,13) = TO_FM(' -154.5445552935436212307301896314710363993166836696091165017078152549564923882084122674 ')\n B(26,14) = TO_FM(' 1.569710887033348726920342834176217614662635935824970859658624964687079589089479471888 ')\n B(26,15) = TO_FM(' 3.276855450872481313214298172699007311655224049747336000450385269517693130775985884604 ')\n B(26,16) = TO_FM(' -.5034892451936531763480407271997836265340810956916323972462042700071863164675818955838e-1 ')\n B(26,17) = TO_FM(' 153.3211518580416650705937678859146940112243631025945564907021486707139114294996134941 ')\n B(26,18) = TO_FM(' 7.175681863277204958467664848147841435678263080348653386540185145833155908488128910568 ')\n B(26,19) = TO_FM(' -2.940367486753004819459176598969309892153205943807775979427615740476908865098135595635 ')\n B(26,20) = TO_FM(' -.6658459460768031444707496760226288702819204931972568878708744783028558369468497032253e-1 ')\n B(26,21) = TO_FM(' -.4623460549908436612292486685622172611769665140168592842374268449140643068786760618896e-1 ')\n B(26,22) = TO_FM(' -.2041987335856794015393882286172697788485797748215817776751235910664984352284968100100e-1 ')\n B(26,23) = TO_FM(' -53.35231064387358505159534411659981079740450904957915977996876390672711239156977103431 ')\n B(26,24) = TO_FM(' -1.355487147150786549787321867059964040175545016141913251148206738329360142936656282958 ')\n B(26,25) = TO_FM(' -1.571962758012327518829017351714592491776872191144425834618663282570958684038698495739 ')\n B(27, 0) = TO_FM(' -16.64514674863415128720312944039317587645603711308189782044257016154825923946758475845 ')\n B(27, 5) = TO_FM(' .5922327803245033080429900057980465247383895604442571368349896773084347972825775455007e-2 ')\n B(27, 6) = TO_FM(' .4703261599638411122172243032058941134553625307461088250108483236601604516650193568134 ')\n B(27, 7) = TO_FM(' .2996888638486790008539818370961923991368311216717812791841936858888827504094204242461 ')\n B(27, 8) = TO_FM(' -.2476568775939949146899922763298108258539580692639470955481886317480090967647905771626 ')\n B(27, 9) = TO_FM(' .1108950297714376828939998518390617145224451736006787182086245987785252503880550245038 ')\n B(27,11) = TO_FM(' -.4917190438462291470706666287041940976780819072106730449888664749836403474888832394921 ')\n B(27,12) = TO_FM(' -11.47431544272894969683894925643525363508424541308531757856483965863898534849416840511 ')\n B(27,13) = TO_FM(' 80.25931665762302725417024858864844001527933666235899875893849400507278534931158408231 ')\n B(27,14) = TO_FM(' -.3841323039800428476253125267590291037469268413420882192068133107492120348263618466046 ')\n B(27,15) = TO_FM(' 7.281476674681075834713269509261361157676125818628777243483988994104498714011047355205 ')\n B(27,16) = TO_FM(' -.1326993846122483795105717081760352748368273416167518843018178653526280269065470590467 ')\n B(27,17) = TO_FM(' -81.07998325257307266746792897522552400060707166336329885641562357237166810196760593013 ')\n B(27,18) = TO_FM(' -1.250374928356206395217681856561791199622537474924031863192434629401819729868852090550 ')\n B(27,19) = TO_FM(' 2.592635949695436810237763795043773249942264473592968880837586883560068434349818491911 ')\n B(27,20) = TO_FM(' -.3014402983464045398301639972605268752644315372756414953420797074457552586137488110716 ')\n B(27,21) = TO_FM(' .2213844607898323374517064515727737916952468390573184143179573617704323166985265217363 ')\n B(27,22) = TO_FM(' .8275772747718929319559898709746931529962764354298098905497078729734353980896315305691e-1 ')\n B(27,23) = TO_FM(' 18.99606620406115204646724500372432639981751614122371589366718674999943569769696943522 ')\n B(27,24) = TO_FM(' .2692319464096396856234680151283341674600519103489128451211866688910668614577677735665 ')\n B(27,25) = TO_FM(' 1.626748274470665374629893649296289339881250292841836802790201430504847697803528636395 ')\n B(27,26) = TO_FM(' .4917190438462291470706666287041940976780819072106730449888664749836403474888832394921 ')\n B(28, 0) = TO_FM(' .8384798124090526646169687913728140859805331392249111310693346670107922625197375034871e-1 ')\n B(28, 5) = TO_FM(' -.1179493671009738143197550560312957753679619605907361507776128268875265788248790903515e-1 ')\n B(28, 6) = TO_FM(' -.2472990205688126523394738387431945983259928403533401326974984247503501083158412965835 ')\n B(28, 7) = TO_FM(' .9780808583677290122593130140812916655037406554767339407565991037499621093437371932341e-1 ')\n B(28, 8) = TO_FM(' .2175906892434206313600086517678603183441681200247821768799893467069296630467914197921 ')\n B(28,10) = TO_FM(' .1375856067633252248656596321967877466474472229750848659754400903987833771639575727867 ')\n B(28,11) = TO_FM(' .4398702297150466850587900923415450260461038902942613590425808839943205635447284745074e-1 ')\n B(28,13) = TO_FM(' -.5137008137681933419570044566186303037387573636419640300869712169933398305905931343468 ')\n B(28,14) = TO_FM(' .8263556911513155086442113083991534587014231586161685769224194977471882335420141183213 ')\n B(28,15) = TO_FM(' 25.70181397198118326258738829725199395111365563419600781824702737091645129169813134401 ')\n B(28,23) = TO_FM(' -25.70181397198118326258738829725199395111365563419600781824702737091645129169813134401 ')\n B(28,24) = TO_FM(' -.8263556911513155086442113083991534587014231586161685769224194977471882335420141183213 ')\n B(28,25) = TO_FM(' .5137008137681933419570044566186303037387573636419640300869712169933398305905931343468 ')\n B(28,26) = TO_FM(' -.4398702297150466850587900923415450260461038902942613590425808839943205635447284745074e-1 ')\n B(28,27) = TO_FM(' -.1375856067633252248656596321967877466474472229750848659754400903987833771639575727867 ')\n B(29, 0) = TO_FM(' .1243805266540944128815164208687993162684914663596714231632892354628068537117612942798 ')\n B(29, 4) = TO_FM(' .2261202821975843014222386629792029011967523207426331439651447460281196206643404356021 ')\n B(29, 5) = TO_FM(' .1378858876180808806076958370164778145309694174914933853635428709475288586061552782365e-1 ')\n B(29, 6) = TO_FM(' -.6722101339966844497493995074143058569500863415253821828561997825320849038679063596730e-1 ')\n B(29, 9) = TO_FM(' -.8562389750854283547553497698795017721121215974115638028550665385850612741040225222977 ')\n B(29,10) = TO_FM(' -1.963375228668589089282628500280938139881804405182674045535756631526916950083353845169 ')\n B(29,11) = TO_FM(' -.2323328227241194012372462573089218472501081992304199949782180319905262045718872259601 ')\n B(29,13) = TO_FM(' 4.306607190864533494616689368765629477724325620534780926267640393608500758570100495873 ')\n B(29,14) = TO_FM(' -2.927229632494654826597879112023904466876873949506336126307786635262992367484998786517 ')\n B(29,15) = TO_FM(' -82.31316663978589444544923341054587077357619664281386893950601309356417181948645997040 ')\n B(29,23) = TO_FM(' 82.31316663978589444544923341054587077357619664281386893950601309356417181948645997040 ')\n B(29,24) = TO_FM(' 2.927229632494654826597879112023904466876873949506336126307786635262992367484998786517 ')\n B(29,25) = TO_FM(' -4.306607190864533494616689368765629477724325620534780926267640393608500758570100495873 ')\n B(29,26) = TO_FM(' .2323328227241194012372462573089218472501081992304199949782180319905262045718872259601 ')\n B(29,27) = TO_FM(' 1.963375228668589089282628500280938139881804405182674045535756631526916950083353845169 ')\n B(29,28) = TO_FM(' .8562389750854283547553497698795017721121215974115638028550665385850612741040225222977 ')\n B(30, 0) = TO_FM(' .1034845616366797766729935465119103444997447982019713166066629728281981965079290745983 ')\n B(30, 3) = TO_FM(' .1220688873064072225896440828689620771395927148341621347412746563709055937325311521675 ')\n B(30, 4) = TO_FM(' .4825744903312466224751347801256881128659190238501680496794015023696413273862321544150 ')\n B(30, 5) = TO_FM(' -.3814096000156069997308862400056202056641130724784114774219699240039767479629669855696e-1 ')\n B(30, 7) = TO_FM(' -.5504995253108023241383885070205081774114143110000375617128363206424473498745141065969 ')\n B(30, 9) = TO_FM(' -.7119158115851892278876482620437943875782918824067455704957652139710574799878630163853 ')\n B(30,10) = TO_FM(' -.5841296056715513404329887301584808720953353296452275957070524410065417676683463009109 ')\n B(30,13) = TO_FM(' 2.110463081258649321287173000466227503003750542789369878507182287710881470618943318741 ')\n B(30,14) = TO_FM(' -.8374947367395721355257420230010379926952601753351235177405529298334532793741463162845e-1 ')\n B(30,15) = TO_FM(' 5.100214990723209140752959690433441131075450608628042491597346388445135412965217165555 ')\n B(30,23) = TO_FM(' -5.100214990723209140752959690433441131075450608628042491597346388445135412965217165555 ')\n B(30,24) = TO_FM(' .8374947367395721355257420230010379926952601753351235177405529298334532793741463162845e-1 ')\n B(30,25) = TO_FM(' -2.110463081258649321287173000466227503003750542789369878507182287710881470618943318741 ')\n B(30,27) = TO_FM(' .5841296056715513404329887301584808720953353296452275957070524410065417676683463009109 ')\n B(30,28) = TO_FM(' .7119158115851892278876482620437943875782918824067455704957652139710574799878630163853 ')\n B(30,29) = TO_FM(' .5504995253108023241383885070205081774114143110000375617128363206424473498745141065969 ')\n B(31, 0) = TO_FM(' 29 ') / 150\n B(31, 2) = TO_FM(' 11 ') / 50\n B(31, 3) = TO_FM(' -2 ') / 25\n B(31, 6) = TO_FM(' .1099934255807247039194624048650683408451190582958464264636524271459687549994002654752 ')\n B(31, 7) = TO_FM(' -.2542970480762701613840685069971531221418356269767039208462421656164179875269042982442 ')\n B(31, 9) = TO_FM(' .8655707771166942543437703438210982818328474012330118593467368132762510892051242759318 ')\n B(31,10) = TO_FM(' 3.324164491140930831067995527865720183368600929369864071601998386039920635781409865040 ')\n B(31,13) = TO_FM(' -12.01022233159779338823523851486618412603019426339968151272769528462035002110216728101 ')\n B(31,14) = TO_FM(' .4766014662424932394304427768620618996029637820035802094825720242694315551196576125507 ')\n B(31,15) = TO_FM(' -29.02430112210363905258026232136540995962512213324709106915239870601916450708546744075 ')\n B(31,23) = TO_FM(' 29.02430112210363905258026232136540995962512213324709106915239870601916450708546744075 ')\n B(31,24) = TO_FM(' -.4766014662424932394304427768620618996029637820035802094825720242694315551196576125507 ')\n B(31,25) = TO_FM(' 12.01022233159779338823523851486618412603019426339968151272769528462035002110216728101 ')\n B(31,27) = TO_FM(' -3.324164491140930831067995527865720183368600929369864071601998386039920635781409865040 ')\n B(31,28) = TO_FM(' -.8655707771166942543437703438210982818328474012330118593467368132762510892051242759318 ')\n B(31,29) = TO_FM(' .2542970480762701613840685069971531221418356269767039208462421656164179875269042982442 ')\n B(31,30) = TO_FM(' -.1099934255807247039194624048650683408451190582958464264636524271459687549994002654752 ')\n B(32, 0) = TO_FM(' -5 ') / 6\n B(32, 1) = TO_FM(' 25 ') / 18\n B(32, 4) = TO_FM(' -3 ') / 4\n B(32, 6) = TO_FM(' -.4925295437180263044226820491140213202002146815806577847190740839644346370048749342561 ')\n B(32,30) = TO_FM(' .4925295437180263044226820491140213202002146815806577847190740839644346370048749342561 ')\n B(32,31) = TO_FM(' 3 ') / 4\n B(33, 0) = TO_FM(' 1 ') / 9\n B(33, 2) = TO_FM(' -2 ') / 9\n B(33,32) = TO_FM(' 2 ') / 9\n B(34, 0) = TO_FM(' .2858351403889715587960888421638364148529275378945964668924322897553490152559792262023 ')\n B(34, 1) = TO_FM(' 7 ') / 24\n B(34, 2) = TO_FM(' 7 ') / 32\n B(34, 4) = TO_FM(' 21 ') / 128\n B(34, 6) = TO_FM(' .2181943549455566583271882415813521070932888243221879411415164327116967439531911272777 ')\n B(34, 7) = TO_FM(' .1803928984786977668636352219467754377196200536418492285624347210514163759703679527180 ')\n B(34, 9) = TO_FM(' .2057138394048450188591207551229295422775700949828089053939914789386228504942804843989 ')\n B(34,10) = TO_FM(' .2427157915817702399702829279594465157627459713866705419485763522859549196625913978401 ')\n B(34,11) = TO_FM(' .2464657808136293058336092911818914077992281038693057051370210135284213379790417930740 ')\n B(34,12) = TO_FM(' -3.449919407908908249798341546016226620603704606149316442883265523381128452524989278943 ')\n B(34,13) = TO_FM(' .2288755621600360817607290607384585842942203725527402184592948392511281334278617959957 ')\n B(34,14) = TO_FM(' .2832905997021514153215274190567333359784365954938557898314048426595070708424182066065 ')\n B(34,15) = TO_FM(' 3.210851258377666409601314905442367870055573203322387098512984999880577120008173123283 ')\n B(34,16) = TO_FM(' -.2235387773648456999202337562141625079641252300836740320899016275445898395177373582441 ')\n B(34,17) = TO_FM(' -.7071211572044190735187272862074872121300912319552061607910521928571247612111795934106 ')\n B(34,18) = TO_FM(' 3.211233451502870804081747292028565008932600344430223743249588034157195885590228893622 ')\n B(34,19) = TO_FM(' 1.409543483096697660304144743011231757690459455735489863573218752821178310978199657967 ')\n B(34,20) = TO_FM(' -.1513620534437426131216022767425181110909630262036760559494590353712667648924754181285 ')\n B(34,21) = TO_FM(' .3723505745270142764547240802146199843971210282021482987373568243836683323798121465643 ')\n B(34,22) = TO_FM(' .2529787464063613367221999077621412859157757281294143192610824780367182739421617243696 ')\n B(34,23) = TO_FM(' -3.210851258377666409601314905442367870055573203322387098512984999880577120008173123283 ')\n B(34,24) = TO_FM(' -.2832905997021514153215274190567333359784365954938557898314048426595070708424182066065 ')\n B(34,25) = TO_FM(' -.2288755621600360817607290607384585842942203725527402184592948392511281334278617959957 ')\n B(34,26) = TO_FM(' -.2464657808136293058336092911818914077992281038693057051370210135284213379790417930740 ')\n B(34,27) = TO_FM(' -.2427157915817702399702829279594465157627459713866705419485763522859549196625913978401 ')\n B(34,28) = TO_FM(' -.2057138394048450188591207551229295422775700949828089053939914789386228504942804843989 ')\n B(34,29) = TO_FM(' -.1803928984786977668636352219467754377196200536418492285624347210514163759703679527180 ')\n B(34,30) = TO_FM(' -.2181943549455566583271882415813521070932888243221879411415164327116967439531911272777 ')\n B(34,31) = TO_FM(' -21 ') / 128\n B(34,32) = TO_FM(' -7 ') / 32\n B(34,33) = TO_FM(' -7 ') / 24\n\n END SUBROUTINE FM_RK14_COEFFS\n\n SUBROUTINE FM_SECANT(AX,BX,F,NF,ROOT,KPRT,KU)\n USE FMVALS\n USE FMZM\n IMPLICIT NONE\n\n! This routine finds a root of F(X,NF) = 0 using AX and BX as starting points.\n! AX and BX do not have to bracket a root in the sense that F(AX,NF) and F(BX,NF) have opposite\n! signs on input. This means the search can fail if AX and BX are not close enough to any roots\n! or if the function has no real roots or is badly behaved.\n\n! When a root is found, FM_SECANT tries to return full accuracy even in the case of multiple\n! or closely-spaced roots, by raising precision above the user's level.\n\n! ROOT is the value returned as the approximate root of the equation.\n\n! KPRT controls printing within the routine:\n! KPRT = 0 for no output\n! KPRT = 1 for the approximation to the root and the function\n! value to be printed once at the end of the routine.\n! KPRT = 2 for the approximation to the root and the function\n! value to be printed each iteration.\n\n! KU is the unit number for output.\n\n TYPE (FM) :: AX, BX, ROOT\n TYPE (FM), EXTERNAL :: F, FM_FPRIME\n CHARACTER (80) :: STR\n INTEGER :: J, KU, KPRT, KWARN_SAVE, MAXIT, NDSAVE, NF\n LOGICAL :: USE_F_OVER_FP\n TYPE (FM), SAVE :: ERR, ERR1, F1, F2, TOL, X1, X1OLD, X2, X3\n\n IF (KPRT == 2) THEN\n WRITE (KU,*) ' '\n WRITE (KU,*) ' FM_SECANT. Begin trace of all iterations.'\n ENDIF\n\n! Raise precision slightly.\n\n NDSAVE = NDIG\n NDIG = NDIG + NGRD52\n CALL FM_EQU(AX,X1,NDSAVE,NDIG)\n CALL FM_EQU(BX,X2,NDSAVE,NDIG)\n KWARN_SAVE = KWARN\n KWARN = 0\n\n MAXIT = 1000\n ERR = 1\n TOL = 100*EPSILON(ERR)\n USE_F_OVER_FP = .FALSE.\n F1 = F(X1,NF)\n F2 = F(X2,NF)\n\n! Check for legal function values.\n\n IF (IS_UNKNOWN(F1) .OR. IS_OVERFLOW(F1)) THEN\n DO J = 1, 3\n X3 = ((TO_FM(4) - J)/4)*X1 + (1-(TO_FM(4) - J)/4)*X2\n F1 = F(X3,NF)\n IF (.NOT. (IS_UNKNOWN(F1) .OR. IS_OVERFLOW(F1))) THEN\n X1 = X3\n EXIT\n ENDIF\n ENDDO\n IF (IS_UNKNOWN(F1) .OR. IS_OVERFLOW(F1)) THEN\n DO J = 1, 3\n X3 = ((TO_FM(4) + J)/4)*X1 + (1-(TO_FM(4) + J)/4)*X2\n F1 = F(X3,NF)\n IF (.NOT. (IS_UNKNOWN(F1) .OR. IS_OVERFLOW(F1))) THEN\n X1 = X3\n EXIT\n ENDIF\n X3 = (1-(TO_FM(4) + J)/4)*X1 + ((TO_FM(4) + J)/4)*X2\n F1 = F(X3,NF)\n IF (.NOT. (IS_UNKNOWN(F1) .OR. IS_OVERFLOW(F1))) THEN\n X1 = X3\n EXIT\n ENDIF\n ENDDO\n ENDIF\n ENDIF\n IF (IS_UNKNOWN(F1) .OR. IS_OVERFLOW(F1)) THEN\n WRITE (KU,*) ' '\n WRITE (KU,*) ' Invalid input for FM_SECANT. ', &\n 'Unknown or overflowed function value for AX ='\n CALL FM_PRINT(X1)\n WRITE (KU,*) ' '\n J = 0\n X2 = TO_FM(' UNKNOWN ')\n ERR = TO_FM(' UNKNOWN ')\n GO TO 110\n ENDIF\n\n IF (IS_UNKNOWN(F2) .OR. IS_OVERFLOW(F2)) THEN\n DO J = 1, 3\n X3 = ((TO_FM(4) - J)/4)*X1 + (1-(TO_FM(4) - J)/4)*X2\n F2 = F(X3,NF)\n IF (.NOT. (IS_UNKNOWN(F2) .OR. IS_OVERFLOW(F2))) THEN\n X2 = X3\n EXIT\n ENDIF\n ENDDO\n IF (IS_UNKNOWN(F2) .OR. IS_OVERFLOW(F2)) THEN\n DO J = 1, 3\n X3 = ((TO_FM(4) + J)/4)*X1 + (1-(TO_FM(4) + J)/4)*X2\n F2 = F(X3,NF)\n IF (.NOT. (IS_UNKNOWN(F2) .OR. IS_OVERFLOW(F2))) THEN\n X2 = X3\n EXIT\n ENDIF\n X3 = (1-(TO_FM(4) + J)/4)*X1 + ((TO_FM(4) + J)/4)*X2\n F2 = F(X3,NF)\n IF (.NOT. (IS_UNKNOWN(F2) .OR. IS_OVERFLOW(F2))) THEN\n X2 = X3\n EXIT\n ENDIF\n ENDDO\n ENDIF\n ENDIF\n IF (IS_UNKNOWN(F2) .OR. IS_OVERFLOW(F2)) THEN\n WRITE (KU,*) ' '\n WRITE (KU,*) ' Invalid input for FM_SECANT. ', &\n 'Unknown or overflowed function value for BX ='\n CALL FM_PRINT(X2)\n WRITE (KU,*) ' '\n J = 0\n X2 = TO_FM(' UNKNOWN ')\n ERR = TO_FM(' UNKNOWN ')\n GO TO 110\n ENDIF\n\n IF (KPRT == 2) THEN\n STR = FM_FORMAT('ES20.10',F1)\n WRITE (KU,\"(' J =',I3,3X,'f(AX) = ',A,' x:')\") 0,STR(1:25)\n CALL FM_PRINT(X1)\n STR = FM_FORMAT('ES20.10',F2)\n WRITE (KU,\"(' J =',I3,3X,'f(BX) = ',A,' x:')\") 0,STR(1:25)\n CALL FM_PRINT(X2)\n ENDIF\n\n! This loop does the iteration.\n\n DO J = 1, MAXIT\n\n IF (F2-F1 /= 0.0) THEN\n X3 = X2 - F2*(X2-X1)/(F2-F1)\n ELSE\n X3 = X2 + 1\n ENDIF\n\n! Multiple roots cause very slow convergence and loss of accuracy.\n! If the slope is very small, try to improve convergence and accuracy by using\n! the (slower) function f(x)/f'(x) which has no multiple roots.\n\n X1OLD = X1\n IF ( (ABS((F2-F1)/(X2-X1)) < 1.0D-2 .AND. ABS(F2) < 1.0D-4) .OR. USE_F_OVER_FP) THEN\n USE_F_OVER_FP = .TRUE.\n X1 = X2\n X2 = X3\n F1 = F2\n F2 = FM_FPRIME(0,X3,F,NF) / FM_FPRIME(1,X3,F,NF)\n ELSE\n X1 = X2\n X2 = X3\n F1 = F2\n F2 = F(X3,NF)\n ENDIF\n\n! If F2 is one of the FM non-numbers, +-underflow, +-overflow, unknown,\n! then replace it by something representable, so that the next x3 will be\n! closer to x1. Also swap x1 and x2, making the bad x go away first.\n\n IF (IS_UNKNOWN(F2) .OR. IS_OVERFLOW(F2)) THEN\n F2 = -2*F1\n X3 = X1\n X1 = X2\n X2 = X3\n X3 = F1\n F1 = F2\n F2 = X3\n ENDIF\n\n IF (KPRT == 2) THEN\n STR = FM_FORMAT('ES20.10',F2)\n WRITE (KU,\"(' J =',I3,4X,'f(x) = ' ,A,' x:')\") J,STR(1:25)\n CALL FM_PRINT(X2)\n ENDIF\n\n ERR1 = ERR\n IF (X2 /= 0.0) THEN\n ERR = ABS((X2-X1)/X2)\n ELSE\n ERR = ABS(X2-X1)\n ENDIF\n\n! If the error is less than the tolerance, double check to make sure the previous\n! error was small along with the current function value. Some divergent iterations\n! can get err < tol without being close to a root.\n\n IF (ERR < TOL .OR. F2 == 0) THEN\n IF (ERR1 > SQRT(SQRT(TOL)) .AND. ABS(F2) > SQRT(EPSILON(TO_FM(1)))) THEN\n WRITE (KU,\"(/' Possible false convergence in FM_SECANT after',I5,\"// &\n \"' iterations. ','Last two approximations =')\") J\n CALL FM_PRINT(X1)\n CALL FM_PRINT(X2)\n WRITE (KU,\"(/' These agree to the convergence tolerance, but the previous\"// &\n \" iteration was suspiciously far away:')\")\n CALL FM_PRINT(X1OLD)\n WRITE (KU,\"(/' and the function value of the last iteration was\"// &\n \" suspiciously far from zero:')\")\n CALL FM_PRINT(F2)\n ENDIF\n GO TO 110\n ENDIF\n\n ENDDO\n\n! No convergence after maxit iterations.\n\n WRITE (KU,\"(/' No convergence in FM_SECANT after',I5,' iterations. ',\"// &\n \"'Last two approximations =')\") MAXIT\n CALL FM_PRINT(X1)\n CALL FM_PRINT(X2)\n X2 = TO_FM(' UNKNOWN ')\n WRITE (KU,\"(/' Unknown has been returned.')\")\n\n! The root was found.\n\n 110 CALL FM_EQU(X2,ROOT,NDIG,NDSAVE)\n NDIG = NDSAVE\n IF (KPRT >= 1) THEN\n CALL FM_ULP(X2,ERR1)\n IF (.NOT.( IS_UNKNOWN(ERR1) .OR. IS_UNDERFLOW(ERR1) )) THEN\n ERR1 = ABS(ERR1/X2)/2\n IF (ERR < ERR1) ERR = ERR1\n ENDIF\n STR = FM_FORMAT('ES16.6',ERR)\n WRITE (KU,*) ' '\n WRITE (KU,\"(' FM_SECANT. Function ',I3,I7,' iterations.'/17X\"// &\n \"'Estimated relative error =',A,', Root:')\") NF,J,TRIM(STR)\n CALL FM_PRINT(ROOT)\n WRITE (KU,*) ' '\n ENDIF\n\n KWARN = KWARN_SAVE\n END SUBROUTINE FM_SECANT\n\n FUNCTION ZM_FPRIME(N,A,F,NF) RESULT (RETURN_VALUE)\n USE FMVALS\n USE FMZM\n IMPLICIT NONE\n\n! This routine finds the Nth derivative of F(X,NF), evaluated at A.\n! NF is passed on to function F to indicate which function to use in cases where several\n! different functions may be defined there.\n\n! F must be defined in an interval containing A, so that F can be sampled on both sides of A.\n\n! N may be zero, so that in cases where F suffers cancellation error at A, an accurate\n! function value is returned.\n\n! ZM_FPRIME tries to return full accuracy for the derivative, by raising precision above\n! the user's level and using difference formulas.\n\n TYPE (ZM) :: A, RETURN_VALUE\n TYPE (ZM), EXTERNAL :: F\n INTEGER :: J, K, KWARN_SAVE, NDSAVE, N, NF\n TYPE (ZM), SAVE :: D1, D2, F1, F2, X1\n TYPE (FM), SAVE :: H, TOL, TOL2\n\n! Raise precision slightly.\n\n NDSAVE = NDIG\n NDIG = NDIG + NGRD52\n CALL ZM_EQU(A,X1,NDSAVE,NDIG)\n KWARN_SAVE = KWARN\n KWARN = 0\n\n D2 = 0\n F1 = F(X1,NF)\n IF (F1 /= 0) THEN\n CALL FM_ULP(ABS(F1),TOL)\n ELSE\n TOL = EPSILON(TO_FM(1))\n ENDIF\n TOL = ABS(TOL)\n\n! Check for a legal function value.\n\n IF (IS_UNKNOWN(ABS(F1)) .OR. IS_OVERFLOW(ABS(F1)) .OR. IS_UNDERFLOW(ABS(F1)) .OR. N < 0) THEN\n D2 = TO_ZM(' UNKNOWN + UNKNOWN i ')\n GO TO 110\n ENDIF\n F2 = F1\n\n! Loop at increasing precision until the difference formula is accurate.\n\n DO J = 1, 100\n\n NDIG = 2*NDIG\n\n! Define the variables used below at the new higher precision.\n\n CALL ZM_EQU(D2,D1,NDIG/2,NDIG)\n CALL ZM_EQU(F2,F1,NDIG/2,NDIG)\n CALL FM_EQU(TOL,TOL2,NDSAVE,NDIG)\n CALL ZM_EQU(A,X1,NDSAVE,NDIG)\n\n! Special case for N = 0.\n\n IF (N == 0) THEN\n F2 = F(X1,NF)\n D2 = F2\n IF (ABS(F2-F1) < TOL2) GO TO 110\n CYCLE\n ENDIF\n F2 = F1\n\n! Special case for N = 1.\n\n IF (N == 1) THEN\n IF (X1 /= 0) THEN\n CALL FM_ULP(ABS(X1),H)\n ELSE\n H = EPSILON(TO_FM(1))\n ENDIF\n H = SQRT(ABS(H))\n D2 = ( F(X1+H,NF) - F(X1-H,NF) ) / (2*H)\n IF (ABS(D2-D1) < TOL2 .AND. J > 1) GO TO 110\n CYCLE\n ENDIF\n\n! General case for even N > 1.\n\n IF (MOD(N,2) == 0) THEN\n IF (X1 /= 0) THEN\n CALL FM_ULP(ABS(X1),H)\n ELSE\n H = EPSILON(TO_FM(1))\n ENDIF\n H = ABS(H)**(TO_FM(1)/(N+2))\n D2 = (-1)**(N/2) * BINOMIAL(TO_FM(N),TO_FM(N/2)) * F(X1,NF)\n DO K = 0, N/2-1\n D2 = D2 + (-1)**K * BINOMIAL(TO_FM(N),TO_FM(K)) * &\n ( F(X1+(N/2-K)*H,NF) + F(X1-(N/2-K)*H,NF) )\n ENDDO\n D2 = D2 / H**N\n IF (ABS(D2-D1) < TOL2 .AND. J > 1) GO TO 110\n CYCLE\n ENDIF\n\n! General case for odd N > 1.\n\n IF (MOD(N,2) == 1) THEN\n IF (X1 /= 0) THEN\n CALL FM_ULP(ABS(X1),H)\n ELSE\n H = EPSILON(TO_FM(1))\n ENDIF\n H = ABS(H)**(TO_FM(1)/(N+2))\n D2 = 0\n DO K = 0, N/2\n D2 = D2 + (-1)**K * BINOMIAL(TO_FM(N-1),TO_FM(K)) * &\n ( F(X1+(N/2-K+1)*H,NF) - F(X1-(N/2-K+1)*H,NF) ) * &\n TO_FM(N*(N+1-2*K)) / ((N-K)*(N+1-K))\n ENDDO\n D2 = D2 / (2*H**N)\n IF (ABS(D2-D1) < TOL2 .AND. J > 1) GO TO 110\n CYCLE\n ENDIF\n\n ENDDO\n\n! Round and return.\n\n 110 CALL ZM_EQU(D2,RETURN_VALUE,NDIG,NDSAVE)\n NDIG = NDSAVE\n KWARN = KWARN_SAVE\n END FUNCTION ZM_FPRIME\n\n SUBROUTINE ZM_INVERSE(A,N,B,DET)\n USE FMVALS\n USE FMZM\n IMPLICIT NONE\n\n! Return B as the inverse of the N x N matrix A, and DET as the determinant of A.\n\n! A and B are type (zm) (complex) multiprecision arrays.\n\n INTEGER :: N\n TYPE (ZM) :: A(N,N), B(N,N), DET\n TYPE (FM), SAVE :: TOL\n TYPE (ZM), ALLOCATABLE :: A1(:,:), A2(:,:), B1(:), R1(:), X1(:)\n INTEGER, ALLOCATABLE :: KSWAP(:)\n INTEGER :: I, J, K, KWARN_SAVE, NDSAVE\n\n TOL = EPSILON(TO_FM(1))/MBASE/TO_FM(10)**10\n\n ALLOCATE(A1(N,N),A2(N,N),B1(N),R1(N),X1(N),KSWAP(N),STAT=J)\n IF (J /= 0) THEN\n WRITE (*,\"(/' Error in ZM_INVERSE. Unable to allocate arrays with N = ',I8/)\") N\n STOP\n ENDIF\n\n! Raise precision.\n\n NDSAVE = NDIG\n NDIG = 2*NDIG\n KWARN_SAVE = KWARN\n KWARN = 0\n\n! Copy A to A1 with higher precision.\n\n 110 CALL FM_EQU_R1(TOL,NDSAVE,NDIG)\n DO I = 1, N\n DO J = 1, N\n CALL ZM_EQU(A(I,J),A1(I,J),NDSAVE,NDIG)\n ENDDO\n ENDDO\n A2 = A1\n\n! Factor A into L*U form.\n\n CALL ZM_FACTOR_LU(A1,N,DET,KSWAP)\n IF (DET == 0 .OR. IS_UNKNOWN(DET)) THEN\n IF (KWARN > 0) THEN\n WRITE (*,\"(/' Error in ZM_INVERSE. The matrix is singular.'/)\")\n ENDIF\n IF (KWARN >= 2) STOP\n B = TO_ZM(' UNKNOWN ')\n GO TO 120\n ENDIF\n\n! Solve for the inverse matrix one column at a time.\n\n DO K = 1, N\n B1 = 0\n B1(K) = 1\n CALL ZM_SOLVE_LU(A1,N,B1,X1,KSWAP)\n\n! Do an iterative refinement.\n\n R1 = MATMUL(A2,X1) - B1\n\n CALL ZM_SOLVE_LU(A1,N,R1,B1,KSWAP)\n X1 = X1 - B1\n\n! Check for accuracy at the user's precision.\n\n IF (SQRT( ABS(DOT_PRODUCT( B1 , B1 )) ) > TOL) THEN\n NDIG = 2*NDIG\n GO TO 110\n ENDIF\n\n! Round the result and store column K in the B matrix.\n\n DO I = 1, N\n CALL ZM_EQU(X1(I),B(I,K),NDIG,NDSAVE)\n ENDDO\n ENDDO\n 120 CALL ZMEQU_R1(DET%MZM,NDIG,NDSAVE)\n\n DEALLOCATE(A1,A2,B1,R1,X1,KSWAP)\n\n NDIG = NDSAVE\n KWARN = KWARN_SAVE\n END SUBROUTINE ZM_INVERSE\n\n SUBROUTINE ZM_LIN_SOLVE(A,X,B,N,DET)\n USE FMVALS\n USE FMZM\n IMPLICIT NONE\n\n! Gauss elimination to solve the linear system A X = B, where:\n\n! A is the matrix of the system, containing the N x N coefficient matrix.\n\n! B is the N x 1 right-hand-side vector.\n\n! X is the returned N x 1 solution vector.\n\n! DET is returned as the determinant of A.\n! Nonzero DET means a solution was found.\n! DET = 0 is returned if the system is singular.\n\n! A,X,B,DET are all type (zm) complex multiprecision variables.\n\n INTEGER :: N\n TYPE (ZM) :: A(N,N), B(N), X(N), DET\n TYPE (FM), SAVE :: TOL\n TYPE (ZM), ALLOCATABLE :: A1(:,:), A2(:,:), B1(:), R1(:), X1(:)\n INTEGER, ALLOCATABLE :: KSWAP(:)\n INTEGER :: I, J, NDSAVE\n\n ALLOCATE(A1(N,N),A2(N,N),B1(N),R1(N),X1(N),KSWAP(N),STAT=J)\n IF (J /= 0) THEN\n WRITE (*,\"(/' Error in ZM_LIN_SOLVE. Unable to allocate arrays with N = ',I8/)\") N\n STOP\n ENDIF\n\n TOL = EPSILON(TO_FM(1))/MBASE/TO_FM(10)**10\n\n NDSAVE = NDIG\n NDIG = 2*NDIG\n\n! Copy A and B to A1 and B1 with higher precision.\n\n 110 CALL FM_EQU_R1(TOL,NDSAVE,NDIG)\n DO I = 1, N\n DO J = 1, N\n CALL ZM_EQU(A(I,J),A1(I,J),NDSAVE,NDIG)\n CALL ZM_EQ(A1(I,J),A2(I,J))\n ENDDO\n CALL ZM_EQU(B(I),B1(I),NDSAVE,NDIG)\n ENDDO\n\n! Solve the system.\n\n CALL ZM_FACTOR_LU(A1,N,DET,KSWAP)\n IF (DET == 0 .OR. IS_UNKNOWN(DET)) THEN\n IF (KWARN > 0) THEN\n WRITE (KW,\"(/' Error in ZM_LIN_SOLVE. The matrix is singular.'/)\")\n ENDIF\n IF (KWARN >= 2) STOP\n X1 = TO_ZM(' UNKNOWN ')\n GO TO 120\n ENDIF\n CALL ZM_SOLVE_LU(A1,N,B1,X1,KSWAP)\n\n! Do an iterative refinement.\n\n R1 = MATMUL(A2,X1) - B1\n\n CALL ZM_SOLVE_LU(A1,N,R1,B1,KSWAP)\n X1 = X1 - B1\n\n! Check for accuracy at the user's precision.\n\n IF (SQRT( ABS(DOT_PRODUCT( B1 , B1 )) ) > TOL) THEN\n NDIG = 2*NDIG\n GO TO 110\n ENDIF\n\n! Round and return X and DET.\n\n 120 DO I = 1, N\n CALL ZM_EQU(X1(I),X(I),NDIG,NDSAVE)\n ENDDO\n CALL ZMEQU_R1(DET%MZM,NDIG,NDSAVE)\n\n NDIG = NDSAVE\n\n DEALLOCATE(A1,A2,B1,R1,X1,KSWAP)\n\n END SUBROUTINE ZM_LIN_SOLVE\n\n SUBROUTINE ZM_FACTOR_LU(A,N,DET,KSWAP)\n USE FMZM\n IMPLICIT NONE\n\n! Gauss elimination to factor the NxN matrix A (LU decomposition).\n\n! The time is proportional to N**3.\n\n! Once this factorization has been done, a linear system A x = b\n! with the same coefficient matrix A and Nx1 vector b can be solved\n! for x using routine ZM_SOLVE_LU in time proportional to N**2.\n\n! DET is returned as the determinant of A.\n! Nonzero DET means there is a unique solution.\n! DET = 0 is returned if the system is singular.\n\n! KSWAP is a list of row interchanges made by the partial pivoting strategy during the\n! elimination phase.\n\n! After returning, the values in matrix A have been replaced by the multipliers\n! used during elimination. This is equivalent to factoring the A matrix into\n! a lower triangular matrix L times an upper triangular matrix U.\n\n INTEGER :: N\n INTEGER :: JCOL, JDIAG, JMAX, JROW, KSWAP(N)\n TYPE (ZM) :: A(N,N), DET\n TYPE (ZM), SAVE :: AMAX, AMULT, TEMP\n\n DET = 1\n KSWAP(1:N) = 1\n IF (N <= 0) THEN\n DET = 0\n RETURN\n ENDIF\n IF (N == 1) THEN\n KSWAP(1) = 1\n DET = A(1,1)\n RETURN\n ENDIF\n\n! Do the elimination phase.\n! JDIAG is the current diagonal element below which the elimination proceeds.\n\n DO JDIAG = 1, N-1\n\n! Pivot to put the element with the largest absolute value on the diagonal.\n\n AMAX = ABS(A(JDIAG,JDIAG))\n JMAX = JDIAG\n DO JROW = JDIAG+1, N\n IF (ABS(A(JROW,JDIAG)) > ABS(AMAX)) THEN\n AMAX = ABS(A(JROW,JDIAG))\n JMAX = JROW\n ENDIF\n ENDDO\n\n! If AMAX is zero here then the system is singular.\n\n IF (AMAX == 0.0) THEN\n DET = 0\n RETURN\n ENDIF\n\n! Swap rows JDIAG and JMAX unless they are the same row.\n\n KSWAP(JDIAG) = JMAX\n IF (JMAX /= JDIAG) THEN\n DET = -DET\n DO JCOL = JDIAG, N\n TEMP = A(JDIAG,JCOL)\n A(JDIAG,JCOL) = A(JMAX,JCOL)\n A(JMAX,JCOL) = TEMP\n ENDDO\n ENDIF\n DET = DET * A(JDIAG,JDIAG)\n\n! For JROW = JDIAG+1, ..., N, eliminate A(JROW,JDIAG) by replacing row JROW by\n! row JROW - A(JROW,JDIAG) * row JDIAG / A(JDIAG,JDIAG)\n\n DO JROW = JDIAG+1, N\n IF (A(JROW,JDIAG) == 0) CYCLE\n AMULT = A(JROW,JDIAG)/A(JDIAG,JDIAG)\n\n! Save the multiplier for use later by ZM_SOLVE_LU.\n\n A(JROW,JDIAG) = AMULT\n DO JCOL = JDIAG+1, N\n A(JROW,JCOL) = A(JROW,JCOL) - AMULT*A(JDIAG,JCOL)\n ENDDO\n ENDDO\n ENDDO\n DET = DET * A(N,N)\n\n END SUBROUTINE ZM_FACTOR_LU\n\n SUBROUTINE ZM_SOLVE_LU(A,N,B,X,KSWAP)\n USE FMZM\n IMPLICIT NONE\n\n! Solve a linear system A x = b.\n! A is the NxN coefficient matrix, after having been factored by ZM_FACTOR_LU.\n! B is the Nx1 right-hand-side vector.\n! X is returned with the solution of the linear system.\n! KSWAP is a list of row interchanges made by the partial pivoting strategy during the\n! elimination phase in ZM_FACTOR_LU.\n! Time for this call is proportional to N**2.\n\n INTEGER :: N, KSWAP(N)\n TYPE (ZM) :: A(N,N), B(N), X(N)\n INTEGER :: J, JDIAG, JMAX\n TYPE (ZM), SAVE :: TEMP\n\n IF (N <= 0) THEN\n RETURN\n ENDIF\n IF (N == 1) THEN\n X(1) = B(1) / A(1,1)\n RETURN\n ENDIF\n DO J = 1, N\n X(J) = B(J)\n ENDDO\n\n! Do the elimination phase operations only on X.\n! JDIAG is the current diagonal element below which the elimination proceeds.\n\n DO JDIAG = 1, N-1\n\n! Pivot to put the element with the largest absolute value on the diagonal.\n\n JMAX = KSWAP(JDIAG)\n\n! Swap rows JDIAG and JMAX unless they are the same row.\n\n IF (JMAX /= JDIAG) THEN\n TEMP = X(JDIAG)\n X(JDIAG) = X(JMAX)\n X(JMAX) = TEMP\n ENDIF\n\n! For JROW = JDIAG+1, ..., N, eliminate A(JROW,JDIAG) by replacing row JROW by\n! row JROW - A(JROW,JDIAG) * row JDIAG / A(JDIAG,JDIAG)\n! After factoring, A(JROW,JDIAG) is the original A(JROW,JDIAG) / A(JDIAG,JDIAG).\n\n DO J = JDIAG+1, N\n X(J) = X(J) - A(J,JDIAG) * X(JDIAG)\n ENDDO\n ENDDO\n\n! Do the back substitution.\n\n DO JDIAG = N, 1, -1\n\n! Divide row JDIAG by the diagonal element.\n\n X(JDIAG) = X(JDIAG) / A(JDIAG,JDIAG)\n\n! Zero above the diagonal in column JDIAG by replacing row JROW by\n! row JROW - A(JROW,JDIAG) * row JDIAG\n! For JROW = 1, ..., JDIAG-1.\n\n IF (JDIAG == 1) EXIT\n DO J = 1, JDIAG-1\n X(J) = X(J) - A(J,JDIAG) * X(JDIAG)\n ENDDO\n ENDDO\n\n END SUBROUTINE ZM_SOLVE_LU\n\n SUBROUTINE ZM_ROOTS(NR,F,NF,N_FOUND,LIST_OF_ROOTS,KPRT,KU)\n USE FMVALS\n USE FMZM\n IMPLICIT NONE\n\n! This routine searches for NR roots of F(X,NF) = 0.\n! NF is the function number in case roots to several functions are needed.\n\n! N_FOUND is returned as the number of roots found.\n! LIST_OF_ROOTS is an array returned with the roots found. They are complex type (zm) numbers,\n! even when the actual root is real.\n\n! KPRT controls printing within the routine:\n! KPRT = 0 for no output\n! KPRT = 1 for the approximation to each root to be printed as they are found.\n\n! KU is the unit number for output.\n\n! The search for roots begins with fairly small magnitude complex values, so small roots are\n! often found before larger roots, but there is no guarantee of this, and the order in which\n! the roots are found is fairly random. The user can sort LIST_OF_ROOTS and print them after\n! all have been found.\n\n! The secant method often fails to converge to any root for a given pair of starting points.\n! This routine may call ZM_ROOT1 many more than NR times before NR roots are found. It can\n! also happen that ZM_ROOTS eventually gives up and returns N_FOUND < NR roots.\n\n! The user's function F is divided by the product of (X - LIST_OF_ROOTS(j)) over the roots that\n! have been found so far. This tries keep the ZM_ROOT1 routine from returning to a root that is\n! already on the list (unless it is a root of multiplicity M > 1).\n\n TYPE (ZM), EXTERNAL :: F\n INTEGER :: J, KU, KPRT, KWARN_SAVE, NDIG_OF_ROOTS, NDSAVE, NF, NR, N_FOUND\n DOUBLE PRECISION :: VALUE\n LOGICAL :: REMOVE_PREVIOUS_ROOTS, RETRY\n TYPE (ZM) :: LIST_OF_ROOTS(NR)\n TYPE (ZM), SAVE :: AX, BX, X1\n\n\n! Raise precision slightly.\n\n NDSAVE = NDIG\n NDIG = NDIG + NGRD52\n KWARN_SAVE = KWARN\n KWARN = 0\n RETRY = .FALSE.\n\n N_FOUND = 0\n LIST_OF_ROOTS = TO_ZM(' UNKNOWN + UNKNOWN i ')\n NDIG_OF_ROOTS = NDIG\n\n DO J = 1, 10*NR\n IF (RETRY) THEN\n CALL FM_RANDOM_NUMBER(VALUE)\n IF (MOD(J,4) == 0) THEN\n AX = TO_ZM(' 1.1 + 1.2 i ')*((2+J)*VALUE+1)\n ELSE IF (MOD(J,4) == 1) THEN\n AX = TO_ZM(' 1.1 - 0.8 i ')*((2+J)*VALUE+1)\n ELSE IF (MOD(J,4) == 2) THEN\n AX = TO_ZM(' -0.8 - 1.2 i ')*((2+J)*VALUE+1)\n ELSE IF (MOD(J,4) == 3) THEN\n AX = TO_ZM(' -1.1 + 0.8 i ')*((2+J)*VALUE+1)\n ENDIF\n BX = TO_ZM(' 0.87 + 0.5 i ')*AX\n ELSE\n AX = TO_ZM(' 1.1 + 1.2 i ')\n BX = TO_ZM(' 3.4 + 4.5 i ')\n ENDIF\n REMOVE_PREVIOUS_ROOTS = .TRUE.\n CALL ZM_ROOT1(AX,BX,NR,F,NF,REMOVE_PREVIOUS_ROOTS,N_FOUND,LIST_OF_ROOTS,NDIG_OF_ROOTS, &\n X1,-1,KU)\n IF (.NOT. (IS_UNKNOWN(ABS(X1)) .OR. IS_OVERFLOW(ABS(X1))) ) THEN\n N_FOUND = N_FOUND + 1\n LIST_OF_ROOTS(N_FOUND) = X1\n\n! Some roots, primarily multiple roots, may have lost some accuracy due to the\n! divisions by previously found roots. Refine them using F without dividing.\n\n AX = LIST_OF_ROOTS(N_FOUND)*(1+1.0D-10)\n BX = LIST_OF_ROOTS(N_FOUND)*(1+1.0D-15)\n REMOVE_PREVIOUS_ROOTS = .FALSE.\n CALL ZM_ROOT1(AX,BX,NR,F,NF,REMOVE_PREVIOUS_ROOTS,N_FOUND,LIST_OF_ROOTS, &\n NDIG_OF_ROOTS,X1,-1,KU)\n IF (ABS(REAL(X1)) < EPSILON(TO_FM(1))*ABS(X1)) X1 = CMPLX( TO_FM(0) , AIMAG(X1) )\n IF (ABS(AIMAG(X1)) < EPSILON(TO_FM(1))*ABS(X1)) X1 = CMPLX( REAL(X1) , TO_FM(0) )\n LIST_OF_ROOTS(N_FOUND) = X1\n\n IF (KPRT > 0) THEN\n WRITE (*,\"(A,I9,A,I6,A)\") ' ZM_ROOTS. Function ',NF,' Root ',N_FOUND,' ='\n CALL ZM_PRINT(X1)\n ENDIF\n IF (N_FOUND == NR) EXIT\n\n! Check to see if the conjugate of this root is also a root.\n\n IF (ABS(AIMAG(X1)) < 100*EPSILON(TO_FM(1))) CYCLE\n AX = CONJG(AX)\n BX = CONJG(BX)\n REMOVE_PREVIOUS_ROOTS = .TRUE.\n CALL ZM_ROOT1(AX,BX,NR,F,NF,REMOVE_PREVIOUS_ROOTS,N_FOUND,LIST_OF_ROOTS, &\n NDIG_OF_ROOTS,X1,-1,KU)\n IF (.NOT. (IS_UNKNOWN(ABS(X1)) .OR. IS_OVERFLOW(ABS(X1))) ) THEN\n N_FOUND = N_FOUND + 1\n LIST_OF_ROOTS(N_FOUND) = X1\n AX = LIST_OF_ROOTS(N_FOUND)*(1+1.0D-10)\n BX = LIST_OF_ROOTS(N_FOUND)*(1+1.0D-15)\n REMOVE_PREVIOUS_ROOTS = .FALSE.\n CALL ZM_ROOT1(AX,BX,NR,F,NF,REMOVE_PREVIOUS_ROOTS,N_FOUND,LIST_OF_ROOTS, &\n NDIG_OF_ROOTS,X1,-1,KU)\n IF (ABS(REAL(X1)) < EPSILON(TO_FM(1))*ABS(X1)) X1 = CMPLX( TO_FM(0) , AIMAG(X1) )\n IF (ABS(AIMAG(X1)) < EPSILON(TO_FM(1))*ABS(X1)) X1 = CMPLX( REAL(X1) , TO_FM(0) )\n LIST_OF_ROOTS(N_FOUND) = X1\n IF (KPRT > 0) THEN\n WRITE (*,\"(A,I9,A,I6,A)\") ' ZM_ROOTS. Function ',NF,' Root ',N_FOUND,' ='\n CALL ZM_PRINT(X1)\n ENDIF\n IF (N_FOUND == NR) EXIT\n ENDIF\n RETRY = .FALSE.\n ELSE\n RETRY = .TRUE.\n ENDIF\n ENDDO\n\n! Round the roots to the user's precision.\n\n DO J = 1, N_FOUND\n X1 = LIST_OF_ROOTS(J)\n CALL ZM_EQU(X1,LIST_OF_ROOTS(J),NDIG,NDSAVE)\n ENDDO\n\n NDIG = NDSAVE\n KWARN = KWARN_SAVE\n END SUBROUTINE ZM_ROOTS\n\n SUBROUTINE ZM_ROOT1(AX,BX,NR,F,NF,REMOVE_PREVIOUS_ROOTS,N_FOUND,LIST_OF_ROOTS, &\n NDIG_OF_ROOTS,ROOT,KPRT,KU)\n USE FMVALS\n USE FMZM\n IMPLICIT NONE\n\n! This is a special version of ZM_SECANT, modified to work with ZM_ROOTS so that some calls\n! will use F and others will use F divided by all the (x - r) terms of the roots found so far.\n\n! REMOVE_PREVIOUS_ROOTS is a logical input variable telling this routine whether or not to\n! divide F by the product of (X - LIST_OF_ROOTS(j)) over the roots that have been found so far.\n! This tries keep the ZM_ROOT1 routine from returning to a root that is already on the list\n! (unless it is a root of multiplicity M > 1).\n\n! This routine searches for a root of F(X,NF) = 0 using AX and BX as starting points.\n! AX and BX are complex, and the search can fail if AX and BX are not close enough to any roots\n! or if the function is badly behaved.\n\n! When a root is found, ZM_ROOT1 tries to return full accuracy even in the case of multiple\n! or closely-spaced roots, by raising precision above the user's level.\n\n! ROOT is the value returned as the approximate root of the equation.\n\n! KPRT controls printing within the routine:\n! KPRT = -1 for no output\n! KPRT = 0 for no output except warning and error messages.\n! KPRT = 1 for the approximation to the root and the function\n! value to be printed once at the end of the routine.\n! KPRT = 2 for the approximation to the root and the function\n! value to be printed each iteration.\n\n! KU is the unit number for output.\n\n TYPE (ZM) :: AX, BX, ROOT\n TYPE (ZM), EXTERNAL :: F, ZM_FPRIME, ZM_ROOT_F\n CHARACTER (80) :: STR\n DOUBLE PRECISION :: VALUE\n INTEGER :: J, JSET, K, KU, KPRT, KWARN_SAVE, MAXIT, N_FOUND, NDIG_OF_ROOTS, NDSAVE, NF, NR\n LOGICAL :: REMOVE_PREVIOUS_ROOTS, USE_F_OVER_FP\n TYPE (ZM) :: LIST_OF_ROOTS(NR)\n TYPE (ZM), SAVE :: F1, F1OLD, F2, FP0, FP1, FS, S, X1, X1OLD, X2, X3\n TYPE (FM), SAVE :: ERR, ERR1, TOL\n\n IF (KPRT == 2) THEN\n WRITE (KU,\"(A)\") ' '\n WRITE (KU,\"(A)\") ' ZM_ROOT1. Begin trace of all iterations.'\n ENDIF\n\n! Raise precision slightly.\n\n NDSAVE = NDIG\n NDIG = NDIG + NGRD52\n CALL ZM_EQU(AX,X1,NDSAVE,NDIG)\n CALL ZM_EQU(BX,X2,NDSAVE,NDIG)\n KWARN_SAVE = KWARN\n KWARN = 0\n\n MAXIT = 1000\n JSET = 50\n ERR = 1\n TOL = 100*EPSILON(ERR)\n USE_F_OVER_FP = .FALSE.\n F1 = ZM_ROOT_F(X1,F,NF,REMOVE_PREVIOUS_ROOTS,N_FOUND,LIST_OF_ROOTS,NDIG_OF_ROOTS)\n F2 = ZM_ROOT_F(X2,F,NF,REMOVE_PREVIOUS_ROOTS,N_FOUND,LIST_OF_ROOTS,NDIG_OF_ROOTS)\n\n! Check for legal function values.\n\n IF (IS_UNKNOWN(ABS(F1)) .OR. IS_OVERFLOW(ABS(F1))) THEN\n DO J = 1, 3\n X3 = ((TO_FM(4) - J)/4)*X1 + (1-(TO_FM(4) - J)/4)*X2\n F1 = ZM_ROOT_F(X3,F,NF,REMOVE_PREVIOUS_ROOTS,N_FOUND,LIST_OF_ROOTS,NDIG_OF_ROOTS)\n IF (.NOT. (IS_UNKNOWN(ABS(F1)) .OR. IS_OVERFLOW(ABS(F1)))) THEN\n X1 = X3\n EXIT\n ENDIF\n ENDDO\n IF (IS_UNKNOWN(ABS(F1)) .OR. IS_OVERFLOW(ABS(F1))) THEN\n DO J = 1, 3\n X3 = ((TO_FM(4) + J)/4)*X1 + (1-(TO_FM(4) + J)/4)*X2\n F1 = ZM_ROOT_F(X3,F,NF,REMOVE_PREVIOUS_ROOTS,N_FOUND,LIST_OF_ROOTS,NDIG_OF_ROOTS)\n IF (.NOT. (IS_UNKNOWN(ABS(F1)) .OR. IS_OVERFLOW(ABS(F1)))) THEN\n X1 = X3\n EXIT\n ENDIF\n X3 = (1-(TO_FM(4) + J)/4)*X1 + ((TO_FM(4) + J)/4)*X2\n F1 = ZM_ROOT_F(X3,F,NF,REMOVE_PREVIOUS_ROOTS,N_FOUND,LIST_OF_ROOTS,NDIG_OF_ROOTS)\n IF (.NOT. (IS_UNKNOWN(ABS(F1)) .OR. IS_OVERFLOW(ABS(F1)))) THEN\n X1 = X3\n EXIT\n ENDIF\n ENDDO\n ENDIF\n ENDIF\n IF (IS_UNKNOWN(ABS(F1)) .OR. IS_OVERFLOW(ABS(F1))) THEN\n IF (KPRT >= 0) THEN\n WRITE (KU,\"(A)\") ' '\n WRITE (KU,\"(A,A)\") ' Invalid input for ZM_ROOT1. ', &\n ' Unknown or overflowed function value for AX ='\n CALL ZM_PRINT(X1)\n WRITE (KU,\"(A)\") ' '\n ENDIF\n J = 0\n X2 = TO_ZM(' UNKNOWN + UNKNOWN i ')\n ERR = TO_ZM(' UNKNOWN + UNKNOWN i ')\n GO TO 110\n ENDIF\n\n IF (IS_UNKNOWN(ABS(F2)) .OR. IS_OVERFLOW(ABS(F2))) THEN\n DO J = 1, 3\n X3 = ((TO_FM(4) - J)/4)*X1 + (1-(TO_FM(4) - J)/4)*X2\n F2 = ZM_ROOT_F(X3,F,NF,REMOVE_PREVIOUS_ROOTS,N_FOUND,LIST_OF_ROOTS,NDIG_OF_ROOTS)\n IF (.NOT. (IS_UNKNOWN(ABS(F2)) .OR. IS_OVERFLOW(ABS(F2)))) THEN\n X2 = X3\n EXIT\n ENDIF\n ENDDO\n IF (IS_UNKNOWN(ABS(F2)) .OR. IS_OVERFLOW(ABS(F2))) THEN\n DO J = 1, 3\n X3 = ((TO_FM(4) + J)/4)*X1 + (1-(TO_FM(4) + J)/4)*X2\n F2 = ZM_ROOT_F(X3,F,NF,REMOVE_PREVIOUS_ROOTS,N_FOUND,LIST_OF_ROOTS,NDIG_OF_ROOTS)\n IF (.NOT. (IS_UNKNOWN(ABS(F2)) .OR. IS_OVERFLOW(ABS(F2)))) THEN\n X2 = X3\n EXIT\n ENDIF\n X3 = (1-(TO_FM(4) + J)/4)*X1 + ((TO_FM(4) + J)/4)*X2\n F2 = ZM_ROOT_F(X3,F,NF,REMOVE_PREVIOUS_ROOTS,N_FOUND,LIST_OF_ROOTS,NDIG_OF_ROOTS)\n IF (.NOT. (IS_UNKNOWN(ABS(F2)) .OR. IS_OVERFLOW(ABS(F2)))) THEN\n X2 = X3\n EXIT\n ENDIF\n ENDDO\n ENDIF\n ENDIF\n IF (IS_UNKNOWN(ABS(F2)) .OR. IS_OVERFLOW(ABS(F2))) THEN\n IF (KPRT >= 0) THEN\n WRITE (KU,\"(A)\") ' '\n WRITE (KU,\"(A,A)\") ' Invalid input for ZM_ROOT1. ', &\n ' Unknown or overflowed function value for BX ='\n CALL ZM_PRINT(X2)\n WRITE (KU,\"(A)\") ' '\n ENDIF\n J = 0\n X2 = TO_ZM(' UNKNOWN + UNKNOWN i ')\n ERR = TO_ZM(' UNKNOWN + UNKNOWN i ')\n GO TO 110\n ENDIF\n\n! Secant does not do well if the magnitudes of the two starting function values differ\n! by too much. Adjust if necessary.\n\n DO J = 1, 10\n IF (ABS(F2/F1) > 10) THEN\n X2 = (X1 + X2)/2\n F2 = ZM_ROOT_F(X2,F,NF,REMOVE_PREVIOUS_ROOTS,N_FOUND,LIST_OF_ROOTS,NDIG_OF_ROOTS)\n ELSE IF (ABS(F1/F2) > 10) THEN\n X1 = (X1 + X2)/2\n F1 = ZM_ROOT_F(X1,F,NF,REMOVE_PREVIOUS_ROOTS,N_FOUND,LIST_OF_ROOTS,NDIG_OF_ROOTS)\n ELSE\n EXIT\n ENDIF\n ENDDO\n\n IF (KPRT == 2) THEN\n STR = ZM_FORMAT('ES20.10','ES20.10',F1)\n WRITE (KU,\"(' J =',I3,3X,'f(AX) = ',A,' x:')\") 0,TRIM(STR)\n CALL ZM_PRINT(X1)\n STR = ZM_FORMAT('ES20.10','ES20.10',F2)\n WRITE (KU,\"(' J =',I3,3X,'f(BX) = ',A,' x:')\") 0,TRIM(STR)\n CALL ZM_PRINT(X2)\n ENDIF\n\n! This loop does the iteration.\n\n DO J = 1, MAXIT\n\n IF (F2-F1 /= 0.0) THEN\n X3 = X2 - F2*(X2-X1)/(F2-F1)\n ELSE\n X3 = X2 + 1\n ENDIF\n\n! Multiple roots cause very slow convergence and loss of accuracy.\n! If the slope is very small, try to improve convergence and accuracy by using\n! the (slower) function f(x)/f'(x) which has no multiple roots.\n\n X1OLD = X1\n F1OLD = F1\n IF ( (ABS((F2-F1)/(X2-X1)) < 1.0D-2 .AND. ABS(F2) < 1.0D-4 .AND. &\n ABS(F2*(X2-X1)/(F2-F1)) < 1.0D-4*ABS(X2)) .OR. USE_F_OVER_FP) THEN\n USE_F_OVER_FP = .TRUE.\n X1 = X2\n X2 = X3\n F1 = F2\n IF (REMOVE_PREVIOUS_ROOTS) THEN\n FP0 = ZM_FPRIME(0,X3,F,NF)\n FP1 = ZM_FPRIME(1,X3,F,NF)\n S = 0\n DO K = 1, N_FOUND\n S = S + 1/(X3-LIST_OF_ROOTS(K))\n ENDDO\n F2 = FP0 / ( FP1 - FP0*S )\n ELSE\n F2 = ZM_FPRIME(0,X3,F,NF) / ZM_FPRIME(1,X3,F,NF)\n ENDIF\n ELSE\n X1 = X2\n X2 = X3\n F1 = F2\n F2 = ZM_ROOT_F(X3,F,NF,REMOVE_PREVIOUS_ROOTS,N_FOUND,LIST_OF_ROOTS,NDIG_OF_ROOTS)\n\n! If the function has a large number of roots, like a high-degree polynomial, then\n! from a distance the function looks like it has multiple roots even though once we\n! get closer the roots appear distinct. This can slow the rate of convergence in\n! the early iterations. Try an Aitken extrapolation once every few steps to try to\n! speed up this initial phase of convergence.\n\n IF (MOD(J,5) == 0 .AND. X2-2*X1+X1OLD /= 0) THEN\n S = X2 - (X2-X1)/(X2-2*X1+X1OLD)\n FS = ZM_ROOT_F(S,F,NF,REMOVE_PREVIOUS_ROOTS,N_FOUND,LIST_OF_ROOTS,NDIG_OF_ROOTS)\n IF (ABS(FS) < MAX(ABS(F1),ABS(F2))) THEN\n X1 = X2\n F1 = F2\n X2 = S\n F2 = FS\n ENDIF\n ENDIF\n ENDIF\n\n! If F2 is one of the FM non-numbers, +-underflow, +-overflow, unknown,\n! then replace it by something representable, so that the next x3 will be\n! closer to x1. Also swap x1 and x2, making the bad x go away first.\n\n IF (IS_UNKNOWN(ABS(F2)) .OR. IS_OVERFLOW(ABS(F2))) THEN\n F2 = -2*F1\n X3 = X1\n X1 = X2\n X2 = X3\n X3 = F1\n F1 = F2\n F2 = X3\n ENDIF\n\n! A common failure mode for secant is to get into a pattern that repeats x1 and x2\n! close together with nearly equal function values and x3 farther away with much\n! larger function value. Check for this, and re-start the iteration by choosing\n! a different x3.\n\n IF (ABS(F2) > 100*MAX(ABS(F1OLD),ABS(F1)) .AND. J >= JSET) THEN\n IF (JSET >= 200) THEN\n MAXIT = J\n EXIT\n ENDIF\n JSET = JSET + 50\n CALL FM_RANDOM_NUMBER(VALUE)\n VALUE = 9*VALUE - 4\n X2 = VALUE*X1 + (1-VALUE)*X2\n F2 = ZM_ROOT_F(X2,F,NF,REMOVE_PREVIOUS_ROOTS,N_FOUND,LIST_OF_ROOTS,NDIG_OF_ROOTS)\n ENDIF\n\n IF (KPRT == 2) THEN\n STR = ZM_FORMAT('ES20.10','ES20.10',F2)\n WRITE (KU,\"(' J =',I3,4X,'f(x) = ' ,A,' x:')\") J,TRIM(STR)\n CALL ZM_PRINT(X2)\n ENDIF\n\n ERR1 = ERR\n IF (X2 /= 0.0) THEN\n ERR = ABS((X2-X1)/X2)\n ELSE\n ERR = ABS(X2-X1)\n ENDIF\n\n! If the error is less than the tolerance, double check to make sure the previous\n! error was small along with the current function value. Some divergent iterations\n! can get err < tol without being close to a root.\n\n IF (ERR < TOL .OR. F2 == 0) THEN\n IF (ERR1 > SQRT(SQRT(TOL)) .AND. ABS(F2) > SQRT(EPSILON(TO_FM(1)))) THEN\n IF (KPRT >= 0) THEN\n WRITE (KU,\"(/' Possible false convergence in ZM_ROOT1 after',I5,\"// &\n \"' iterations. ','Last two approximations =')\") J\n CALL ZM_PRINT(X1)\n CALL ZM_PRINT(X2)\n WRITE (KU,\"(/' These agree to the convergence tolerance, but the previous\"// &\n \" iteration was suspiciously far away:')\")\n CALL ZM_PRINT(X1OLD)\n WRITE (KU,\"(/' and the function value of the last iteration was\"// &\n \" suspiciously far from zero:')\")\n CALL ZM_PRINT(F2)\n WRITE (KU,\"(/' Unknown has been returned.')\")\n ENDIF\n X2 = TO_ZM(' UNKNOWN + UNKNOWN i ')\n ENDIF\n GO TO 110\n ENDIF\n\n ENDDO\n\n! No convergence after maxit iterations.\n\n IF (KPRT >= 0) THEN\n WRITE (KU,\"(/' No convergence in ZM_ROOT1 after',I5,' iterations. ',\"// &\n \"'Last two approximations =')\") MAXIT\n CALL ZM_PRINT(X1)\n CALL ZM_PRINT(X2)\n WRITE (KU,\"(/' Unknown has been returned.')\")\n ENDIF\n X2 = TO_ZM(' UNKNOWN + UNKNOWN i ')\n\n! The root was found.\n\n 110 CALL ZM_EQU(X2,ROOT,NDIG,NDSAVE)\n NDIG = NDSAVE\n IF (KPRT >= 1) THEN\n CALL FM_ULP(ABS(X2),ERR1)\n IF (.NOT.( IS_UNKNOWN(ERR1) .OR. IS_UNDERFLOW(ERR1) )) THEN\n ERR1 = ABS(ERR1/X2)/2\n IF (ERR < ERR1) ERR = ERR1\n ENDIF\n STR = FM_FORMAT('ES16.6',ERR)\n WRITE (KU,\"(A)\") ' '\n WRITE (KU,\"(' ZM_ROOT1. Function ',I3,I7,' iterations.'/17X\"// &\n \"'Estimated relative error =',A,', Root:')\") NF,J,TRIM(STR)\n CALL ZM_PRINT(ROOT)\n WRITE (KU,\"(A)\") ' '\n ENDIF\n\n KWARN = KWARN_SAVE\n END SUBROUTINE ZM_ROOT1\n\n FUNCTION ZM_ROOT_F(X,F,NF,REMOVE_PREVIOUS_ROOTS,N_FOUND,LIST_OF_ROOTS,NDIG_OF_ROOTS) &\n RESULT (RETURN_VALUE)\n USE FMVALS\n USE FMZM\n IMPLICIT NONE\n\n! ZM_ROOT_F is used here to evaluate the user's function F and divide F by the product of\n! (X - LIST_OF_ROOTS(j)) over the roots that have been found so far. This should keep the\n! ZM_ROOT1 routine from returning to a root that is already on the list (unless it is a\n! root of multiplicity M > 1).\n\n! When REMOVE_PREVIOUS_ROOTS is false, just evaluate F without doing the division.\n\n! X is the argument to the function.\n! NF is the function number.\n\n INTEGER :: J, NDIG_OF_ROOTS, NF, N_FOUND\n LOGICAL :: REMOVE_PREVIOUS_ROOTS\n TYPE (ZM) :: LIST_OF_ROOTS(N_FOUND)\n TYPE (ZM) :: RETURN_VALUE, X\n TYPE (ZM), EXTERNAL :: F\n TYPE (ZM), SAVE :: D\n\n IF (REMOVE_PREVIOUS_ROOTS) THEN\n RETURN_VALUE = F(X,NF)\n DO J = 1, N_FOUND\n CALL ZM_EQU(LIST_OF_ROOTS(J),D,NDIG_OF_ROOTS,NDIG)\n IF (X /= D) RETURN_VALUE = RETURN_VALUE / (X - D)\n ENDDO\n ELSE\n RETURN_VALUE = F(X,NF)\n ENDIF\n\n END FUNCTION ZM_ROOT_F\n\n SUBROUTINE ZM_SECANT(AX,BX,F,NF,ROOT,KPRT,KU)\n USE FMVALS\n USE FMZM\n IMPLICIT NONE\n\n! This routine searches for a root of F(X,NF) = 0 using AX and BX as starting points.\n! AX and BX are complex, and the search can fail if AX and BX are not close enough to any roots\n! or if the function is badly behaved.\n\n! When a root is found, ZM_SECANT tries to return full accuracy even in the case of multiple\n! or closely-spaced roots, by raising precision above the user's level.\n\n! ROOT is the value returned as the approximate root of the equation.\n\n! KPRT controls printing within the routine:\n! KPRT = -1 for no output\n! KPRT = 0 for no output except warning and error messages.\n! KPRT = 1 for the approximation to the root and the function\n! value to be printed once at the end of the routine.\n! KPRT = 2 for the approximation to the root and the function\n! value to be printed each iteration.\n\n! KU is the unit number for output.\n\n TYPE (ZM) :: AX, BX, ROOT\n TYPE (ZM), EXTERNAL :: F, ZM_FPRIME\n CHARACTER (80) :: STR\n DOUBLE PRECISION :: VALUE\n INTEGER :: J, JSET, KPRT, KU, KWARN_SAVE, MAXIT, NDSAVE, NF\n LOGICAL :: USE_F_OVER_FP\n TYPE (ZM), SAVE :: F1, F1OLD, F2, X1, X1OLD, X2, X3\n TYPE (FM), SAVE :: ERR, ERR1, TOL\n\n IF (KPRT == 2) THEN\n WRITE (KU,*) ' '\n WRITE (KU,*) ' ZM_SECANT. Begin trace of all iterations.'\n ENDIF\n\n! Raise precision slightly.\n\n NDSAVE = NDIG\n NDIG = NDIG + NGRD52\n CALL ZM_EQU(AX,X1,NDSAVE,NDIG)\n CALL ZM_EQU(BX,X2,NDSAVE,NDIG)\n KWARN_SAVE = KWARN\n KWARN = 0\n\n MAXIT = 1000\n JSET = 50\n ERR = 1\n TOL = 100*EPSILON(ERR)\n USE_F_OVER_FP = .FALSE.\n F1 = F(X1,NF)\n F2 = F(X2,NF)\n\n! Check for legal function values.\n\n IF (IS_UNKNOWN(ABS(F1)) .OR. IS_OVERFLOW(ABS(F1))) THEN\n DO J = 1, 3\n X3 = ((TO_FM(4) - J)/4)*X1 + (1-(TO_FM(4) - J)/4)*X2\n F1 = F(X3,NF)\n IF (.NOT. (IS_UNKNOWN(ABS(F1)) .OR. IS_OVERFLOW(ABS(F1)))) THEN\n X1 = X3\n EXIT\n ENDIF\n ENDDO\n IF (IS_UNKNOWN(ABS(F1)) .OR. IS_OVERFLOW(ABS(F1))) THEN\n DO J = 1, 3\n X3 = ((TO_FM(4) + J)/4)*X1 + (1-(TO_FM(4) + J)/4)*X2\n F1 = F(X3,NF)\n IF (.NOT. (IS_UNKNOWN(ABS(F1)) .OR. IS_OVERFLOW(ABS(F1)))) THEN\n X1 = X3\n EXIT\n ENDIF\n X3 = (1-(TO_FM(4) + J)/4)*X1 + ((TO_FM(4) + J)/4)*X2\n F1 = F(X3,NF)\n IF (.NOT. (IS_UNKNOWN(ABS(F1)) .OR. IS_OVERFLOW(ABS(F1)))) THEN\n X1 = X3\n EXIT\n ENDIF\n ENDDO\n ENDIF\n ENDIF\n IF (IS_UNKNOWN(ABS(F1)) .OR. IS_OVERFLOW(ABS(F1))) THEN\n IF (KPRT >= 0) THEN\n WRITE (KU,*) ' '\n WRITE (KU,*) ' Invalid input for ZM_SECANT. ', &\n ' Unknown or overflowed function value for AX ='\n CALL ZM_PRINT(X1)\n WRITE (KU,*) ' '\n ENDIF\n J = 0\n X2 = TO_ZM(' UNKNOWN + UNKNOWN i ')\n ERR = TO_ZM(' UNKNOWN + UNKNOWN i ')\n GO TO 110\n ENDIF\n\n IF (IS_UNKNOWN(ABS(F2)) .OR. IS_OVERFLOW(ABS(F2))) THEN\n DO J = 1, 3\n X3 = ((TO_FM(4) - J)/4)*X1 + (1-(TO_FM(4) - J)/4)*X2\n F2 = F(X3,NF)\n IF (.NOT. (IS_UNKNOWN(ABS(F2)) .OR. IS_OVERFLOW(ABS(F2)))) THEN\n X2 = X3\n EXIT\n ENDIF\n ENDDO\n IF (IS_UNKNOWN(ABS(F2)) .OR. IS_OVERFLOW(ABS(F2))) THEN\n DO J = 1, 3\n X3 = ((TO_FM(4) + J)/4)*X1 + (1-(TO_FM(4) + J)/4)*X2\n F2 = F(X3,NF)\n IF (.NOT. (IS_UNKNOWN(ABS(F2)) .OR. IS_OVERFLOW(ABS(F2)))) THEN\n X2 = X3\n EXIT\n ENDIF\n X3 = (1-(TO_FM(4) + J)/4)*X1 + ((TO_FM(4) + J)/4)*X2\n F2 = F(X3,NF)\n IF (.NOT. (IS_UNKNOWN(ABS(F2)) .OR. IS_OVERFLOW(ABS(F2)))) THEN\n X2 = X3\n EXIT\n ENDIF\n ENDDO\n ENDIF\n ENDIF\n IF (IS_UNKNOWN(ABS(F2)) .OR. IS_OVERFLOW(ABS(F2))) THEN\n IF (KPRT >= 0) THEN\n WRITE (KU,*) ' '\n WRITE (KU,*) ' Invalid input for ZM_SECANT. ', &\n ' Unknown or overflowed function value for BX ='\n CALL ZM_PRINT(X2)\n WRITE (KU,*) ' '\n ENDIF\n J = 0\n X2 = TO_ZM(' UNKNOWN + UNKNOWN i ')\n ERR = TO_ZM(' UNKNOWN + UNKNOWN i ')\n GO TO 110\n ENDIF\n\n! Secant does not do well if the magnitude of the two starting function values differ\n! by too much. Adjust if necessary.\n\n DO J = 1, 10\n IF (ABS(F2/F1) > 10) THEN\n X2 = (X1 + X2)/2\n F2 = F(X2,NF)\n ELSE IF (ABS(F1/F2) > 10) THEN\n X1 = (X1 + X2)/2\n F1 = F(X1,NF)\n ELSE\n EXIT\n ENDIF\n ENDDO\n\n IF (KPRT == 2) THEN\n STR = ZM_FORMAT('ES20.10','ES20.10',F1)\n WRITE (KU,\"(' J =',I3,3X,'f(AX) = ',A,' x:')\") 0,TRIM(STR)\n CALL ZM_PRINT(X1)\n STR = ZM_FORMAT('ES20.10','ES20.10',F2)\n WRITE (KU,\"(' J =',I3,3X,'f(BX) = ',A,' x:')\") 0,TRIM(STR)\n CALL ZM_PRINT(X2)\n ENDIF\n\n! This loop does the iteration.\n\n DO J = 1, MAXIT\n\n IF (F2-F1 /= 0.0) THEN\n X3 = X2 - F2*(X2-X1)/(F2-F1)\n ELSE\n X3 = X2 + 1\n ENDIF\n\n! Multiple roots cause very slow convergence and loss of accuracy.\n! If the slope is very small, try to improve convergence and accuracy by using\n! the (slower) function f(x)/f'(x) which has no multiple roots.\n\n X1OLD = X1\n F1OLD = F1\n IF ( (ABS((F2-F1)/(X2-X1)) < 1.0D-2 .AND. ABS(F2) < 1.0D-4 .AND. &\n ABS(F2*(X2-X1)/(F2-F1)) < 1.0D-4*ABS(X2)) .OR. USE_F_OVER_FP) THEN\n USE_F_OVER_FP = .TRUE.\n X1 = X2\n X2 = X3\n F1 = F2\n F2 = ZM_FPRIME(0,X3,F,NF) / ZM_FPRIME(1,X3,F,NF)\n ELSE\n X1 = X2\n X2 = X3\n F1 = F2\n F2 = F(X3,NF)\n ENDIF\n\n! If F2 is one of the FM non-numbers, +-underflow, +-overflow, unknown,\n! then replace it by something representable, so that the next x3 will be\n! closer to x1. Also swap x1 and x2, making the bad x go away first.\n\n IF (IS_UNKNOWN(ABS(F2)) .OR. IS_OVERFLOW(ABS(F2))) THEN\n F2 = -2*F1\n X3 = X1\n X1 = X2\n X2 = X3\n X3 = F1\n F1 = F2\n F2 = X3\n ENDIF\n\n! A common failure mode for secant is to get into a pattern that repeats x1 and x2\n! close together with nearly equal function values and x3 farther away with much\n! larger function value. Check for this, and re-start the iteration by choosing\n! a different x3.\n\n IF (ABS(F2) > 100*MAX(ABS(F1OLD),ABS(F1)) .AND. J >= JSET) THEN\n IF (JSET >= 200) THEN\n MAXIT = J\n EXIT\n ENDIF\n JSET = JSET + 50\n CALL FM_RANDOM_NUMBER(VALUE)\n VALUE = 9*VALUE - 4\n X2 = VALUE*X1 + (1-VALUE)*X2\n F2 = F(X2,NF)\n ENDIF\n\n IF (KPRT == 2) THEN\n STR = ZM_FORMAT('ES20.10','ES20.10',F2)\n WRITE (KU,\"(' J =',I3,4X,'f(x) = ' ,A,' x:')\") J,TRIM(STR)\n CALL ZM_PRINT(X2)\n ENDIF\n\n ERR1 = ERR\n IF (X2 /= 0.0) THEN\n ERR = ABS((X2-X1)/X2)\n ELSE\n ERR = ABS(X2-X1)\n ENDIF\n\n! If the error is less than the tolerance, double check to make sure the previous\n! error was small along with the current function value. Some divergent iterations\n! can get err < tol without being close to a root.\n\n IF (ERR < TOL .OR. F2 == 0) THEN\n IF (ERR1 > SQRT(SQRT(TOL)) .AND. ABS(F2) > SQRT(EPSILON(TO_FM(1)))) THEN\n IF (KPRT >= 0) THEN\n WRITE (KU,\"(/' Possible false convergence in ZM_SECANT after',I5,\"// &\n \"' iterations. ','Last two approximations =')\") J\n CALL ZM_PRINT(X1)\n CALL ZM_PRINT(X2)\n WRITE (KU,\"(/' These agree to the convergence tolerance, but the previous\"// &\n \" iteration was suspiciously far away:')\")\n CALL ZM_PRINT(X1OLD)\n WRITE (KU,\"(/' and the function value of the last iteration was\"// &\n \" suspiciously far from zero:')\")\n CALL ZM_PRINT(F2)\n WRITE (KU,\"(/' Unknown has been returned.')\")\n ENDIF\n X2 = TO_ZM(' UNKNOWN + UNKNOWN i ')\n ENDIF\n GO TO 110\n ENDIF\n\n ENDDO\n\n! No convergence after maxit iterations.\n\n IF (KPRT >= 0) THEN\n WRITE (KU,\"(/' No convergence in ZM_SECANT after',I5,' iterations. ',\"// &\n \"'Last two approximations =')\") MAXIT\n CALL ZM_PRINT(X1)\n CALL ZM_PRINT(X2)\n WRITE (KU,\"(/' Unknown has been returned.')\")\n ENDIF\n X2 = TO_ZM(' UNKNOWN + UNKNOWN i ')\n\n! The root was found.\n\n 110 CALL ZM_EQU(X2,ROOT,NDIG,NDSAVE)\n NDIG = NDSAVE\n IF (KPRT >= 1) THEN\n CALL FM_ULP(ABS(X2),ERR1)\n IF (.NOT.( IS_UNKNOWN(ERR1) .OR. IS_UNDERFLOW(ERR1) )) THEN\n ERR1 = ABS(ERR1/X2)/2\n IF (ERR < ERR1) ERR = ERR1\n ENDIF\n STR = FM_FORMAT('ES16.6',ERR)\n WRITE (KU,*) ' '\n WRITE (KU,\"(' ZM_SECANT. Function ',I3,I7,' iterations.'/17X\"// &\n \"'Estimated relative error =',A,', Root:')\") NF,J,TRIM(STR)\n CALL ZM_PRINT(ROOT)\n WRITE (KU,*) ' '\n ENDIF\n\n KWARN = KWARN_SAVE\n END SUBROUTINE ZM_SECANT\n", "meta": {"hexsha": "48f8ba09e312b4f5e724ed1464152bc301ee6e15", "size": 160913, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Libraries/FM/FMsamples/FM_Sample_Routines.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/FM_Sample_Routines.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/FM_Sample_Routines.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": 40.8927573062, "max_line_length": 118, "alphanum_fraction": 0.5685183919, "num_tokens": 53010, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232809, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.6836875194006922}} {"text": "module test_var\n use testdrive, only : new_unittest, unittest_type, error_type, check\n use stdlib_kinds, only: sp, dp, int32, int64\n use stdlib_stats, only: var\n use,intrinsic :: ieee_arithmetic, only : ieee_is_nan\n implicit none\n\n\n real(sp), parameter :: sptol = 1000 * epsilon(1._sp)\n real(dp), parameter :: dptol = 1000 * epsilon(1._dp)\n\n integer(int32), parameter :: i321(5) = [1, 2, 3, 4, 5]\n integer(int64), parameter :: i641(5) = [1, 2, 3, 4, 5]\n\n real(sp), parameter :: s1(5) = [1.0_sp, 2.0_sp, 3.0_sp, 4.0_sp, 5.0_sp]\n real(dp), parameter :: d1(5) = [1.0_dp, 2.0_dp, 3.0_dp, 4.0_dp, 5.0_dp]\n\n real(dp), parameter :: d(4, 3) = reshape([1._dp, 3._dp, 5._dp, 7._dp,&\n 2._dp, 4._dp, 6._dp, 8._dp,&\n 9._dp, 10._dp, 11._dp, 12._dp], [4, 3])\n real(dp), parameter :: d3(4, 3, 3) = reshape([d, d*2, d*4], shape(d3))\n real(sp), parameter :: s(4, 3) = d\n real(sp), parameter :: s3(4, 3, 3) = reshape([s, s*2, s*4], shape(s3))\n\n integer(int32), parameter :: i32(4, 3) = d\n integer(int32), parameter :: i323(4, 3, 3) = d3\n integer(int64), parameter :: i64(4, 3) = d\n integer(int64), parameter :: i643(4, 3, 3) = d3\n\n complex(sp), parameter :: cs1(5) = [ cmplx(0.57706_sp, 0.00000_sp, sp),&\n cmplx(0.00000_sp, 1.44065_sp, sp),&\n cmplx(1.26401_sp, 0.00000_sp, sp),&\n cmplx(0.00000_sp, 0.88833_sp, sp),&\n cmplx(1.14352_sp, 0.00000_sp, sp)]\n complex(dp), parameter :: cd1(5) = [ cmplx(0.57706_dp, 0.00000_dp,kind=dp),&\n cmplx(0.00000_dp, 1.44065_dp,kind=dp),&\n cmplx(1.26401_dp, 0.00000_dp,kind=dp),&\n cmplx(0.00000_dp, 0.88833_dp,kind=dp),&\n cmplx(1.14352_dp, 0.00000_dp,kind=dp)]\n complex(sp), parameter :: cs(5,3) = reshape([cs1, cs1*3.0_sp, cs1*1.5_sp], shape(cs))\n complex(dp), parameter :: cd(5,3) = reshape([cd1, cd1*3.0_dp, cd1*1.5_dp], shape(cd))\n\ncontains\n\n\n !> Collect all exported unit tests\n subroutine collect_var(testsuite)\n !> Collection of tests\n type(unittest_type), allocatable, intent(out) :: testsuite(:)\n\n testsuite = [ &\n new_unittest(\"sp_1dim\", test_sp_1dim), &\n new_unittest(\"sp_1dim_mask\", test_sp_1dim_mask), &\n new_unittest(\"sp_2dim\", test_sp_2dim), &\n new_unittest(\"sp_2dim_mask\", test_sp_2dim_mask), &\n new_unittest(\"sp_2dim_mask_array\", test_sp_2dim_mask_array), &\n new_unittest(\"sp_3dim\", test_sp_3dim), &\n new_unittest(\"sp_3dim_mask\", test_sp_3dim_mask), &\n new_unittest(\"sp_3dim_mask_array\", test_sp_3dim_mask_array), &\n new_unittest(\"dp_1dim\", test_dp_1dim), &\n new_unittest(\"dp_1dim_mask\", test_dp_1dim_mask), &\n new_unittest(\"dp_1dim_mask_array\", test_dp_1dim_mask_array), &\n new_unittest(\"dp_2dim\", test_dp_2dim), &\n new_unittest(\"dp_2dim_mask\", test_dp_2dim_mask), &\n new_unittest(\"dp_2dim_mask_array\", test_dp_2dim_mask_array), &\n new_unittest(\"dp_3dim\", test_dp_3dim), &\n new_unittest(\"dp_3dim_mask\", test_dp_3dim_mask), &\n new_unittest(\"dp_3dim_mask_array\", test_dp_3dim_mask_array), &\n new_unittest(\"int32_1dim\", test_int32_1dim), &\n new_unittest(\"int32_1dim_mask\", test_int32_1dim_mask), &\n new_unittest(\"int32_1dim_mask_array\", test_int32_1dim_mask_array), &\n new_unittest(\"int32_2dim\", test_int32_2dim), &\n new_unittest(\"int32_2dim_mask\", test_int32_2dim_mask), &\n new_unittest(\"int32_2dim_mask_array\", test_int32_2dim_mask_array), &\n new_unittest(\"int32_3dim\", test_int32_3dim), &\n new_unittest(\"int32_3dim_mask\", test_int32_3dim_mask), &\n new_unittest(\"int32_3dim_mask_array\", test_int32_3dim_mask_array), &\n new_unittest(\"int64_1dim\", test_int64_1dim), &\n new_unittest(\"int64_1dim_mask\", test_int64_1dim_mask), &\n new_unittest(\"int641_1dim_mask_array\", test_int641_1dim_mask_array), &\n new_unittest(\"int64_2dim\", test_int64_2dim), &\n new_unittest(\"int64_2dim_mask\", test_int64_2dim_mask), &\n new_unittest(\"int64_2dim_mask_array\", test_int64_2dim_mask_array), &\n new_unittest(\"int64_3dim\", test_int64_3dim), &\n new_unittest(\"int64_3dim_mask\", test_int64_3dim_mask), &\n new_unittest(\"int64_3dim_mask_array\", test_int64_3dim_mask_array), &\n new_unittest(\"csp_1dim\", test_csp_1dim), &\n new_unittest(\"csp_1dim_mask\", test_csp_1dim_mask), &\n new_unittest(\"csp_1dim_mask_array\", test_csp_1dim_mask_array), &\n new_unittest(\"csp_2dim\", test_csp_2dim), &\n new_unittest(\"csp_2dim_mask\", test_csp_2dim_mask), &\n new_unittest(\"csp_2dim_mask_array\", test_csp_2dim_mask_array), &\n new_unittest(\"cdp_1dim\", test_cdp_1dim), &\n new_unittest(\"cdp_1dim_mask\", test_cdp_1dim_mask), &\n new_unittest(\"cdp_1dim_mask_array\", test_cdp_1dim_mask_array), &\n new_unittest(\"cdp_2dim\", test_cdp_2dim), &\n new_unittest(\"cdp_2dim_mask\", test_cdp_2dim_mask), &\n new_unittest(\"cdp_2dim_mask_array\", test_cdp_2dim_mask_array) &\n ]\n end subroutine collect_var\n\n subroutine test_sp_1dim(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, abs(var(s1) - 2.5) < sptol)\n call check(error, abs(var(s1, dim=1) - 2.5) < sptol)\n\n end subroutine test_sp_1dim\n\n subroutine test_sp_1dim_mask(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, ieee_is_nan(var(s1, .false.)))\n call check(error, ieee_is_nan(var(s1, 1, .false.)))\n\n end subroutine test_sp_1dim_mask\n\n subroutine test_sp_1dim_mask_array(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, abs(var(s1, s1 < 5) - 5./3.) < sptol)\n call check(error, ieee_is_nan((var(s1, s1 < 0.))))\n call check(error, ieee_is_nan((var(s1, s1 == 1.))))\n call check(error, abs(var(s1, 1, s1 < 5) - 5./3.) < sptol)\n\n end subroutine test_sp_1dim_mask_array\n\n subroutine test_sp_2dim(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, abs(var(s) - 13) < sptol)\n call check(error, all( abs( var(s, 1) - [20. / 3., 20. / 3., 5. / 3.]) < sptol))\n call check(error, all( abs( var(s, 2) - [19.0, 43. / 3., 31. / 3. , 7.0]) < sptol))\n\n end subroutine test_sp_2dim\n\n subroutine test_sp_2dim_mask(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, ieee_is_nan(var(s, .false.)))\n call check(error, any(ieee_is_nan(var(s, 1, .false.))))\n call check(error, any(ieee_is_nan(var(s, 2, .false.))))\n\n end subroutine test_sp_2dim_mask\n\n subroutine test_sp_2dim_mask_array(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, abs(var(s, s < 11) - 27.5 / 3.) < sptol)\n call check(error, all( abs( var(s, 1, s < 11) - [20. / 3., 20. / 3., 0.5]) < sptol))\n call check(error, all( abs( var(s, 2, s < 11) - [19.0, 43. / 3., 0.5 , 0.5]) < sptol))\n\n end subroutine test_sp_2dim_mask_array\n\n subroutine test_sp_3dim(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, abs(var(s3) - 153.4) < sptol)\n call check(error, all( abs( var(s3, 1) -&\n reshape([20. / 3., 20. / 3., 5. / 3.,&\n 4* 20. / 3., 4* 20. / 3., 4* 5. / 3.,&\n 16* 20. / 3., 16* 20. / 3., 16* 5. / 3.],&\n [size(s3,2), size(s3,3)]))&\n < sptol))\n call check(error, all( abs( var(s3, 2) -&\n reshape([19.0, 43. / 3., 31. / 3. , 7.0,&\n 4* 19.0, 4* 43. / 3., 4* 31. / 3. , 4* 7.0,&\n 16* 19.0, 16* 43. / 3., 16* 31. / 3. , 16* 7.0],&\n [size(s3,1), size(s3,3)] ))&\n < sptol))\n call check(error, all(abs( var(s3, 3) -&\n reshape([ 7./3., 21., 175./3.,&\n 343./3., 28./3., 112./3.,&\n 84., 448./3., 189.,&\n 700./3., 847./3., 336.], [size(s3,1), size(s3,2)] ))&\n < sptol))\n\n end subroutine test_sp_3dim\n\n subroutine test_sp_3dim_mask(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, ieee_is_nan(var(s3, .false.)))\n call check(error, any(ieee_is_nan(var(s3, 1, .false.))))\n call check(error, any(ieee_is_nan(var(s3, 2, .false.))))\n call check(error, any(ieee_is_nan(var(s3, 3, .false.))))\n\n end subroutine test_sp_3dim_mask\n\n subroutine test_sp_3dim_mask_array(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, abs(var(s3, s3 < 11) - 8.2205877_sp) < sptol)\n call check(error, all( abs( var(s3, 1, s3 < 45) -&\n reshape([20./3., 20./3., 5./3., 80./3., 80./3., 20./3.,&\n 320./3., 320./3., 16.],&\n [size(s3, 2), size(s3, 3)])) < sptol ))\n call check(error, any( ieee_is_nan( var(s3, 2, s3 < 25))))\n call check(error, all( abs( var(s3, 3, s3 < 25) -&\n reshape([ 7./3., 21., 175./3.,&\n 24.5, 28./3., 112./3.,&\n 84., 32., 40.5,&\n 50., 60.5, 72.], [size(s3,1), size(s3,2)] ))&\n < sptol ))\n\n end subroutine test_sp_3dim_mask_array\n\n subroutine test_dp_1dim(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, abs(var(d1) - 2.5) < dptol)\n call check(error, abs(var(d1, 1) - 2.5) < dptol)\n\n end subroutine test_dp_1dim\n\n subroutine test_dp_1dim_mask(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, ieee_is_nan(var(d1, .false.)))\n call check(error, ieee_is_nan(var(d1, 1, .false.)))\n\n end subroutine test_dp_1dim_mask\n\n subroutine test_dp_1dim_mask_array(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, abs(var(d1, d1 < 5) - 5._dp/3._dp) < dptol)\n call check(error, ieee_is_nan((var(d1, d1 < 0.))))\n call check(error, ieee_is_nan((var(d1, d1 == 1.))))\n call check(error, abs(var(d1, 1, d1 < 5) - 5._dp/3._dp) < dptol)\n\n end subroutine test_dp_1dim_mask_array\n\n subroutine test_dp_2dim(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, abs(var(d) - 13) < dptol)\n call check(error, all( abs( var(d,1) -&\n [20._dp/3._dp, 20._dp/3._dp, 5._dp/3._dp]) < dptol))\n call check(error, all( abs( var(d,2) -&\n [19.0_dp, 43._dp/3._dp, 31._dp/3._dp, 7.0_dp]) < dptol))\n\n end subroutine test_dp_2dim\n\n subroutine test_dp_2dim_mask(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, ieee_is_nan(var(d, .false.)))\n call check(error, any(ieee_is_nan(var(d, 1, .false.))))\n call check(error, any(ieee_is_nan(var(d, 2, .false.))))\n\n end subroutine test_dp_2dim_mask\n\n subroutine test_dp_2dim_mask_array(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, abs(var(d, d < 11) - 27.5_dp / 3._dp) < dptol)\n call check(error, all( abs( var(d, 1, d < 11) -&\n [20._dp / 3._dp, 20._dp / 3._dp, 0.5_dp]) < dptol))\n call check(error, all( abs( var(d, 2, d < 11) -&\n [19.0_dp, 43._dp / 3._dp, 0.5_dp, 0.5_dp]) < dptol))\n\n end subroutine test_dp_2dim_mask_array\n\n subroutine test_dp_3dim(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, abs(var(d3) - 153.4_dp) < dptol)\n call check(error, all( abs( var(d3, 1) -&\n reshape([20._dp / 3._dp, 20._dp / 3._dp, 5._dp / 3._dp,&\n 4* 20._dp / 3._dp, 4* 20._dp / 3._dp, 4* 5._dp / 3._dp,&\n 16* 20._dp / 3._dp, 16* 20._dp / 3._dp, 16* 5._dp / 3._dp],&\n [size(d3,2), size(d3,3)]))&\n < dptol))\n call check(error, all( abs( var(d3, 2) -&\n reshape([19.0_dp, 43._dp / 3._dp, 31._dp / 3._dp , 7.0_dp,&\n 4* 19.0_dp, 4* 43._dp / 3._dp, 4* 31._dp / 3._dp , 4* 7.0_dp,&\n 16* 19.0_dp, 16* 43._dp / 3._dp, 16* 31._dp / 3._dp ,&\n 16* 7.0_dp],&\n [size(d3,1), size(d3,3)] ))&\n < dptol))\n call check(error, all(abs( var(d3, 3) -&\n reshape([ 7._dp/3._dp, 21._dp, 175._dp/3._dp,&\n 343._dp/3._dp, 28._dp/3._dp, 112._dp/3._dp,&\n 84._dp, 448._dp/3._dp, 189._dp,&\n 700._dp/3._dp, 847._dp/3._dp, 336._dp],&\n [size(d3,1), size(d3,2)] ))&\n < dptol))\n\n end subroutine test_dp_3dim\n\n subroutine test_dp_3dim_mask(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, ieee_is_nan(var(d3, .false.)))\n call check(error, any(ieee_is_nan(var(d3, 1, .false.))))\n call check(error, any(ieee_is_nan(var(d3, 2, .false.))))\n call check(error, any(ieee_is_nan(var(d3, 3, .false.))))\n\n end subroutine test_dp_3dim_mask\n\n subroutine test_dp_3dim_mask_array(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, abs(var(d3, d3 < 25) - 46.041379310344823_dp) < dptol)\n call check(error, all( abs( var(d3, 1, d3 < 45) -&\n reshape([20._dp/3._dp, 20._dp/3._dp, 5._dp/3._dp,&\n 80._dp/3._dp, 80._dp/3._dp, 20._dp/3._dp,&\n 320._dp/3._dp, 320._dp/3._dp, 16._dp],&\n [size(d3, 2), size(d3, 3)]))&\n < dptol ))\n call check(error, any( ieee_is_nan( var(d3, 2, d3 < 25))))\n call check(error, all( abs( var(d3, 3, d3 < 25) -&\n reshape([ 7._dp/3._dp, 21._dp, 175._dp/3._dp,&\n 24.5_dp, 28._dp/3._dp, 112._dp/3._dp,&\n 84._dp, 32._dp, 40.5_dp,&\n 50._dp, 60.5_dp, 72._dp],&\n [size(d3,1), size(d3,2)] ))&\n < dptol ))\n\n end subroutine test_dp_3dim_mask_array\n\n subroutine test_int32_1dim(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, abs(var(i321) - 2.5) < dptol)\n call check(error, abs(var(i321, 1) - 2.5) < dptol)\n\n end subroutine test_int32_1dim\n\n subroutine test_int32_1dim_mask(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, ieee_is_nan(var(i321, .false.)))\n call check(error, ieee_is_nan(var(i321, 1, .false.)))\n\n end subroutine test_int32_1dim_mask\n\n subroutine test_int32_1dim_mask_array(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, abs(var(i321, i321 < 5) - 5._dp/3._dp) < dptol)\n call check(error, ieee_is_nan((var(i321, i321 < 0))))\n call check(error, ieee_is_nan((var(i321, i321 == 1))))\n call check(error, abs(var(i321, 1, i321 < 5) - 5._dp/3._dp) < dptol)\n\n end subroutine test_int32_1dim_mask_array\n\n subroutine test_int32_2dim(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, abs(var(i32) - 13) < dptol)\n call check(error, all( abs( var(i32,1) -&\n [20._dp/3._dp, 20._dp/3._dp, 5._dp/3._dp]) < dptol))\n call check(error, all( abs( var(i32,2) -&\n [19.0_dp, 43._dp/3._dp, 31._dp/3._dp, 7.0_dp]) < dptol))\n\n end subroutine test_int32_2dim\n\n subroutine test_int32_2dim_mask(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, ieee_is_nan(var(i32, .false.)))\n call check(error, any(ieee_is_nan(var(i32, 1, .false.))))\n call check(error, any(ieee_is_nan(var(i32, 2, .false.))))\n\n end subroutine test_int32_2dim_mask\n\n subroutine test_int32_2dim_mask_array(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, abs(var(i32, i32 < 11) - 27.5_dp / 3._dp) < dptol)\n call check(error, all( abs( var(i32, 1, i32 < 11) -&\n [20._dp / 3._dp, 20._dp / 3._dp, 0.5_dp]) < dptol))\n call check(error, all( abs( var(i32, 2, i32 < 11) -&\n [19.0_dp, 43._dp / 3._dp, 0.5_dp, 0.5_dp]) < dptol))\n\n end subroutine test_int32_2dim_mask_array\n\n subroutine test_int32_3dim(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, abs(var(i323) - 153.4_dp) < dptol)\n call check(error, all( abs( var(i323, 1) -&\n reshape([20._dp / 3._dp, 20._dp / 3._dp, 5._dp / 3._dp,&\n 4* 20._dp / 3._dp, 4* 20._dp / 3._dp, 4* 5._dp / 3._dp,&\n 16* 20._dp / 3._dp, 16* 20._dp / 3._dp, 16* 5._dp / 3._dp],&\n [size(i323,2), size(i323,3)]))&\n < dptol))\n call check(error, all( abs( var(i323, 2) -&\n reshape([19.0_dp, 43._dp / 3._dp, 31._dp / 3._dp , 7.0_dp,&\n 4* 19.0_dp, 4* 43._dp / 3._dp, 4* 31._dp / 3._dp , 4* 7.0_dp,&\n 16* 19.0_dp, 16* 43._dp / 3._dp, 16* 31._dp / 3._dp ,&\n 16* 7.0_dp],&\n [size(i323,1), size(i323,3)] ))&\n < dptol))\n call check(error, all(abs( var(i323, 3) -&\n reshape([ 7._dp/3._dp, 21._dp, 175._dp/3._dp,&\n 343._dp/3._dp, 28._dp/3._dp, 112._dp/3._dp,&\n 84._dp, 448._dp/3._dp, 189._dp,&\n 700._dp/3._dp, 847._dp/3._dp, 336._dp],&\n [size(i323,1), size(i323,2)] ))&\n < dptol))\n\n end subroutine test_int32_3dim\n\n subroutine test_int32_3dim_mask(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, ieee_is_nan(var(i323, .false.)))\n call check(error, any(ieee_is_nan(var(i323, 1, .false.))))\n call check(error, any(ieee_is_nan(var(i323, 2, .false.))))\n call check(error, any(ieee_is_nan(var(i323, 3, .false.))))\n\n end subroutine test_int32_3dim_mask\n\n subroutine test_int32_3dim_mask_array(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, abs(var(i323, i323 < 25) - 46.041379310344823_dp) < dptol)\n call check(error, all( abs( var(i323, 1, i323 < 45) -&\n reshape([20._dp/3._dp, 20._dp/3._dp, 5._dp/3._dp,&\n 80._dp/3._dp, 80._dp/3._dp, 20._dp/3._dp,&\n 320._dp/3._dp, 320._dp/3._dp, 16._dp],&\n [size(i323, 2), size(i323, 3)]))&\n < dptol ))\n call check(error, any( ieee_is_nan( var(i323, 2, i323 < 25))))\n call check(error, all( abs( var(i323, 3, i323 < 25) -&\n reshape([ 7._dp/3._dp, 21._dp, 175._dp/3._dp,&\n 24.5_dp, 28._dp/3._dp, 112._dp/3._dp,&\n 84._dp, 32._dp, 40.5_dp,&\n 50._dp, 60.5_dp, 72._dp],&\n [size(i323,1), size(i323,2)] ))&\n < dptol ))\n\n end subroutine test_int32_3dim_mask_array\n\n subroutine test_int64_1dim(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, abs(var(i641) - 2.5) < dptol)\n call check(error, abs(var(i641, 1) - 2.5) < dptol)\n\n end subroutine test_int64_1dim\n\n subroutine test_int64_1dim_mask(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, ieee_is_nan(var(i641, .false.)))\n call check(error, ieee_is_nan(var(i641, 1, .false.)))\n\n end subroutine test_int64_1dim_mask\n\n subroutine test_int641_1dim_mask_array(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, abs(var(i641, i641 < 5) - 5._dp/3._dp) < dptol)\n call check(error, ieee_is_nan((var(i641, i641 < 0))))\n call check(error, ieee_is_nan((var(i641, i641 == 1))))\n call check(error, abs(var(i641, 1, i641 < 5) - 5._dp/3._dp) < dptol)\n\n end subroutine test_int641_1dim_mask_array\n\n subroutine test_int64_2dim(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, abs(var(i64) - 13) < dptol)\n call check(error, all( abs( var(i64,1) -&\n [20._dp/3._dp, 20._dp/3._dp, 5._dp/3._dp]) < dptol))\n call check(error, all( abs( var(i64,2) -&\n [19.0_dp, 43._dp/3._dp, 31._dp/3._dp, 7.0_dp]) < dptol))\n\n end subroutine test_int64_2dim\n\n subroutine test_int64_2dim_mask(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, ieee_is_nan(var(i64, .false.)))\n call check(error, any(ieee_is_nan(var(i64, 1, .false.))))\n call check(error, any(ieee_is_nan(var(i64, 2, .false.))))\n\n end subroutine test_int64_2dim_mask\n\n subroutine test_int64_2dim_mask_array(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, abs(var(i64, i64 < 11) - 27.5_dp / 3._dp) < dptol)\n call check(error, all( abs( var(i64, 1, i64 < 11) -&\n [20._dp / 3._dp, 20._dp / 3._dp, 0.5_dp]) < dptol))\n call check(error, all( abs( var(i64, 2, i64 < 11) -&\n [19.0_dp, 43._dp / 3._dp, 0.5_dp, 0.5_dp]) < dptol))\n\n end subroutine test_int64_2dim_mask_array\n\n subroutine test_int64_3dim(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, abs(var(i643) - 153.4_dp) < dptol)\n call check(error, all( abs( var(i643, 1) -&\n reshape([20._dp / 3._dp, 20._dp / 3._dp, 5._dp / 3._dp,&\n 4* 20._dp / 3._dp, 4* 20._dp / 3._dp, 4* 5._dp / 3._dp,&\n 16* 20._dp / 3._dp, 16* 20._dp / 3._dp, 16* 5._dp / 3._dp],&\n [size(i643,2), size(i643,3)]))&\n < dptol))\n call check(error, all( abs( var(i643, 2) -&\n reshape([19.0_dp, 43._dp / 3._dp, 31._dp / 3._dp , 7.0_dp,&\n 4* 19.0_dp, 4* 43._dp / 3._dp, 4* 31._dp / 3._dp , 4* 7.0_dp,&\n 16* 19.0_dp, 16* 43._dp / 3._dp, 16* 31._dp / 3._dp ,&\n 16* 7.0_dp],&\n [size(i643,1), size(i643,3)] ))&\n < dptol))\n call check(error, all(abs( var(i643, 3) -&\n reshape([ 7._dp/3._dp, 21._dp, 175._dp/3._dp,&\n 343._dp/3._dp, 28._dp/3._dp, 112._dp/3._dp,&\n 84._dp, 448._dp/3._dp, 189._dp,&\n 700._dp/3._dp, 847._dp/3._dp, 336._dp],&\n [size(i643,1), size(i643,2)] ))&\n < dptol))\n\n end subroutine test_int64_3dim\n\n subroutine test_int64_3dim_mask(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, ieee_is_nan(var(i643, .false.)))\n call check(error, any(ieee_is_nan(var(i643, 1, .false.))))\n call check(error, any(ieee_is_nan(var(i643, 2, .false.))))\n call check(error, any(ieee_is_nan(var(i643, 3, .false.))))\n\n end subroutine test_int64_3dim_mask\n\n subroutine test_int64_3dim_mask_array(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, abs(var(i643, i643 < 25) - 46.041379310344823_dp) < dptol)\n call check(error, all( abs( var(i643, 1, i643 < 45) -&\n reshape([20._dp/3._dp, 20._dp/3._dp, 5._dp/3._dp,&\n 80._dp/3._dp, 80._dp/3._dp, 20._dp/3._dp,&\n 320._dp/3._dp, 320._dp/3._dp, 16._dp],&\n [size(i643, 2), size(i643, 3)]))&\n < dptol ))\n call check(error, any( ieee_is_nan( var(i643, 2, i643 < 25))))\n call check(error, all( abs( var(i643, 3, i643 < 25) -&\n reshape([ 7._dp/3._dp, 21._dp, 175._dp/3._dp,&\n 24.5_dp, 28._dp/3._dp, 112._dp/3._dp,&\n 84._dp, 32._dp, 40.5_dp,&\n 50._dp, 60.5_dp, 72._dp],&\n [size(i643,1), size(i643,2)] ))&\n < dptol ))\n\n end subroutine test_int64_3dim_mask_array\n\n subroutine test_csp_1dim(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, abs(var(cs1) - (var(real(cs1)) + var(aimag(cs1)))) < sptol)\n call check(error, abs(var(cs1, dim=1) - (var(real(cs1),1) + var(aimag(cs1), 1)) ) < sptol)\n\n end subroutine test_csp_1dim\n\n subroutine test_csp_1dim_mask(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, ieee_is_nan(var(cs1, .false.)))\n call check(error, ieee_is_nan(var(cs1, 1, .false.)))\n\n end subroutine test_csp_1dim_mask\n\n subroutine test_csp_1dim_mask_array(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, abs(var(cs1, aimag(cs1) == 0) - var(real(cs1), aimag(cs1) == 0)) < sptol)\n call check(error, abs(var(cs1, 1, aimag(cs1) == 0) - var(real(cs1), 1, aimag(cs1) == 0)) < sptol)\n\n end subroutine test_csp_1dim_mask_array\n\n subroutine test_csp_2dim(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, abs(var(cs) - (var(real(cs)) + var(aimag(cs)))) < sptol)\n call check(error, all( abs( var(cs, 1) - (var(real(cs), 1) + var(aimag(cs), 1))) < sptol))\n call check(error, all( abs( var(cs, 2) - (var(real(cs), 2) + var(aimag(cs), 2))) < sptol))\n\n end subroutine test_csp_2dim\n\n subroutine test_csp_2dim_mask(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, ieee_is_nan(var(cs, .false.)))\n call check(error, any(ieee_is_nan(var(cs, 1, .false.))))\n call check(error, any(ieee_is_nan(var(cs, 2, .false.))))\n\n end subroutine test_csp_2dim_mask\n\n\n subroutine test_csp_2dim_mask_array(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, abs(var(cs, aimag(cs) == 0) - var(real(cs), aimag(cs) == 0)) < sptol)\n call check(error, all( abs( var(cs, 1, aimag(cs) == 0) - var(real(cs), 1, aimag(cs) == 0)) < sptol))\n call check(error, any( ieee_is_nan( var(cs, 2, aimag(cs) == 0))))\n\n end subroutine test_csp_2dim_mask_array\n\n subroutine test_cdp_1dim(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, abs(var(cd1) - (var(real(cd1)) + var(aimag(cd1)))) < dptol)\n call check(error, abs(var(cd1, dim=1) - (var(real(cd1),1) + var(aimag(cd1), 1)) ) < dptol)\n\n end subroutine test_cdp_1dim\n\n subroutine test_cdp_1dim_mask(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, ieee_is_nan(var(cd1, .false.)))\n call check(error, ieee_is_nan(var(cd1, 1, .false.)))\n\n end subroutine test_cdp_1dim_mask\n\n subroutine test_cdp_1dim_mask_array(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, abs(var(cd1, aimag(cd1) == 0) - var(real(cd1), aimag(cd1) == 0)) < dptol)\n call check(error, abs(var(cd1, 1, aimag(cd1) == 0) - var(real(cd1), 1, aimag(cd1) == 0)) < dptol)\n\n end subroutine test_cdp_1dim_mask_array\n\n subroutine test_cdp_2dim(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, abs(var(cd) - (var(real(cd)) + var(aimag(cd)))) < dptol)\n call check(error, all( abs( var(cd, 1) - (var(real(cd), 1) + var(aimag(cd), 1))) < dptol))\n call check(error, all( abs( var(cd, 2) - (var(real(cd), 2) + var(aimag(cd), 2))) < dptol))\n\n end subroutine test_cdp_2dim\n\n subroutine test_cdp_2dim_mask(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, ieee_is_nan(var(cd, .false.)))\n call check(error, any(ieee_is_nan(var(cd, 1, .false.))))\n call check(error, any(ieee_is_nan(var(cd, 2, .false.))))\n\n end subroutine test_cdp_2dim_mask\n\n subroutine test_cdp_2dim_mask_array(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n call check(error, abs(var(cd, aimag(cd) == 0) - var(real(cd), aimag(cd) == 0)) < dptol)\n call check(error, all( abs( var(cd, 1, aimag(cd) == 0) - var(real(cd), 1, aimag(cd) == 0)) < dptol))\n call check(error, any( ieee_is_nan( var(cd, 2, aimag(cd) == 0))))\n\n end subroutine test_cdp_2dim_mask_array\n\nend module\n\n\nprogram tester\n use, intrinsic :: iso_fortran_env, only : error_unit\n use testdrive, only : run_testsuite, new_testsuite, testsuite_type\n use test_var, only : collect_var\n implicit none\n integer :: stat, is\n type(testsuite_type), allocatable :: testsuites(:)\n character(len=*), parameter :: fmt = '(\"#\", *(1x, a))'\n\n stat = 0\n\n testsuites = [ &\n new_testsuite(\"var\", collect_var) &\n ]\n\n do is = 1, size(testsuites)\n write(error_unit, fmt) \"Testing:\", testsuites(is)%name\n call run_testsuite(testsuites(is)%collect, error_unit, stat)\n end do\n\n if (stat > 0) then\n write(error_unit, '(i0, 1x, a)') stat, \"test(s) failed!\"\n error stop\n end if\nend program\n", "meta": {"hexsha": "657ce6cb0f7fde238facf6fef9ee13259b0648f0", "size": 31126, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/stats/test_var.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/tests/stats/test_var.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/tests/stats/test_var.f90", "max_forks_repo_name": "seanwallawalla-forks/stdlib", "max_forks_repo_head_hexsha": "f58da3b1141a0bb0ce741aa6b74f636a1376706d", "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": 42.5218579235, "max_line_length": 108, "alphanum_fraction": 0.5578294673, "num_tokens": 10292, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972717658209, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.6836875036407308}} {"text": " PROGRAM xlocate\r\nC driver for routine locate\r\n INTEGER N\r\n PARAMETER(N=100)\r\n INTEGER i,j\r\n REAL x,xx(N)\r\nC create array to be searched\r\n do 11 i=1,N\r\n xx(i)=exp(i/20.0)-74.0\r\n11 continue\r\n write(*,*) 'Result of: j=0 indicates x too small'\r\n write(*,*) ' j=100 indicates x too large'\r\n write(*,'(t5,a7,t17,a1,t24,a5,t34,a7)') 'locate ','j',\r\n * 'xx(j)','xx(j+1)'\r\nC perform test\r\n do 12 i=1,19\r\n x=-100.0+200.0*i/20.0\r\n call locate(xx,N,x,j)\r\n if (j.eq.0) then\r\n write(*,'(1x,f10.4,i6,a12,f12.6)') x,j,'lower lim',xx(j+1)\r\n else if (j.eq.N) then\r\n write(*,'(1x,f10.4,i6,f12.6,a12)') x,j,xx(j),'upper lim'\r\n else\r\n write(*,'(1x,f10.4,i6,2f12.6)') x,j,xx(j),xx(j+1)\r\n endif\r\n12 continue\r\n END\r\n", "meta": {"hexsha": "8448d983e2de3395f8815bca737237743b6cde41", "size": 862, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xlocate.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xlocate.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xlocate.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": 30.7857142857, "max_line_length": 69, "alphanum_fraction": 0.4814385151, "num_tokens": 311, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934406, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.6836875001052439}} {"text": "subroutine bis(a,b,ET,x)\n \n implicit none\n\n!!!!!!!!!!!!!!!!!\n ! AUTOR: BYRON J. ENCINAS\n !\n ! PROP\u00d3SITO:\n ! APROXIMAR RA\u00cdCES REALES PARA FUNCIONES\n ! MEDIANTE M\u00c9TODOS DE BISECCI\u00d3N \n !\n!!!!!!!!!!!!!!!!!!\n\n integer,parameter::q=selected_real_kind(32,600)\n real,external::F\n real,intent(INOUT)::a,b,ET,x\n real(kind=q)::G,j\n integer::i,k\n\t\n!======================================================\n\nG = F(b)*F(a)\t\t!!! Variable G nos comunica si hay cambio de signo en el primer intervalo\n\t\nIF(G==0 .OR. G>0)THEN\t\t!!!verificaci\u00f3n\nWRITE(*,*)'No hay cambio de signo'\nSTOP\n\nELSE !!!cambio de signo, LISTOS PARA CONTINUAR CON APROXIMACION\n\t\n!!!!!===============CALCULO DE ERRORES: !!!BISECCION============================\n\t\n \n!=====================================================================\t\n\tIF(ET==0)then\n\tk=200\t\t\t!!! condicionamos el numero de iteraciones, si es otorgado por el usuario\n\tELSE \t\t\t!!! si no, se realizan 200 iteraciones\n\tj= log((b-a)/ET)/0.69314718056 -1\n\tk=NINT(j)+1\n\tEND IF\n!=======================================================================\n\t\nWRITE(*,*)'X_n F(x_n) a_n b_n'\n\t!=============================================================\n\tDo i=1,k\nx = (a + b)/2\n\t!====================\n\tWRITE(*,*) x,F(x),a,b\n\n\tIF(F(x) /= 0)THEN\n\t\n\t\n\t\n\tIF(F(x)*F(a)<0)then\n\t!Si F(x)*F(a_n) <0 entonces hay cambio de signo\n\t!h 0, south < 0)\n! riseangle - angle of earths rotation where sunrise occurs.\n! This varies depending on whether you are calculating\n! direct beam, civil twilight, nautical twilight or\n! astronomical twilight daylength\n \n! + + + local variables + + +\n \n! + + + local variable definitions + + +\n! dec - declination of earth with respect to the sun (degrees)\n! declination - \n! h - hour angle (degrees)\n! hourangle - a function. This variable holds the value returned by \n! the Hourangle function. Debe assumed this definition\n \n! + + + common blocks + + +\n! include 'p1unconv.inc'\n \n! + + + function declarations + + +\n \n! + + + end specifications + + +\n \n! declination angle (dec)\n!\ndec = declination(idoy)\n \n! sunrise or sunset hour angle\nh = hourangle(dlat,dec,riseangle)\n \n! calculate the length of the day\ndaylen = 2.0*h/15.0\n! \nEND FUNCTION daylen\n", "meta": {"hexsha": "35e85dc3109435d4837a2b01efe63f986519a0e2", "size": 1710, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Project Documents/Source Code Original/Daylen.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/Daylen.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/Daylen.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": 27.1428571429, "max_line_length": 74, "alphanum_fraction": 0.6198830409, "num_tokens": 448, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.927363293639213, "lm_q2_score": 0.7371581741774411, "lm_q1q2_score": 0.6836134323382604}} {"text": "\t!------------------------------------------------------------------------\n\t!\n\t!\n\t! PURPOSE\n\t!\n\t! This program solves nonlinear Klein-Gordon equation in 1 dimension\n\t! u_{tt}-u_{xx}+u=Es*|u|^2u\n\t! using a second order implicit-explicit time stepping scheme.\n\t!\n\t! The boundary conditions are u(x=0)=u(2*Lx*\\pi), \n\t! The initial condition is u=sqrt(2)*sech((x-c*t)/sqrt(1-c^2));\n\t!\n\t! .. Parameters ..\n\t! Nx = number of modes in x - power of 2 for FFT\n\t! Nt\t\t\t= number of timesteps to take\n\t! Tmax\t\t\t= maximum simulation time\n\t! plotgap\t\t= number of timesteps between plots\n\t! FFTW_IN_PLACE \t= value for FFTW input \n\t! FFTW_MEASURE \t= value for FFTW input\n\t! FFTW_EXHAUSTIVE \t= value for FFTW input\n\t! FFTW_PATIENT \t= value for FFTW input \n\t! FFTW_ESTIMATE \t= value for FFTW input\n\t! FFTW_FORWARD = value for FFTW input\n\t! FFTW_BACKWARD\t= value for FFTW input\t\n\t! pi = 3.14159265358979323846264338327950288419716939937510d0\n\t! Lx\t\t\t= width of box in x direction\n\t! ES\t\t\t= +1 for focusing and -1 for defocusing\n\t! .. Scalars ..\n\t! i\t\t\t= loop counter in x direction\n\t! n\t\t\t= loop counter for timesteps direction\t\n\t! allocatestatus\t= error indicator during allocation\n\t! start\t\t= variable to record start time of program\n\t! finish\t\t= variable to record end time of program\n\t! count_rate\t\t= variable for clock count rate\n\t! planfx\t\t= Forward 2d fft plan \n\t! planbx\t\t= Backward 2d fft plan\n\t! dt\t\t\t= timestep\n\t! ierr\t\t\t= error code\n\t! plotnum\t\t= number of plot\n\t! .. Arrays ..\n\t! unew \t\t= approximate solution\n\t! vnew \t\t= Fourier transform of approximate solution\n\t! u \t\t\t= approximate solution\n\t! v \t\t\t= Fourier transform of approximate solution\n\t! uold \t\t= approximate solution\n\t! vold \t\t= Fourier transform of approximate solution\n\t! nonlin \t\t= nonlinear term, u^3\n\t! nonlinhat \t\t= Fourier transform of nonlinear term, u^3\n\t! .. Vectors ..\n\t! kx\t\t\t= fourier frequencies in x direction\n\t! x\t\t\t= x locations\n\t! time\t\t\t= times at which save data\n\t! en\t\t\t= total energy\t\n\t! enstr\t\t= strain energy\n\t! enpot\t\t= potential energy\n\t! enkin\t\t= kinetic energy\n\t! name_config\t\t= array to store filename for data to be saved \t\t\n\t! fftfx\t\t= array to setup 1D Fourier transform\n\t! fftbx\t\t= array to setup 1D Fourier transform\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!\tgetgrid.f90\t-- Get initial grid of points\n\t! \tinitialdata.f90 -- Get initial data\n\t!\tenercalc.f90 -- Subroutine to calculate the energy\n\t!\tsavedata.f90 -- Save initial data\n\t!\tstoreold.f90 -- Store old data\n\t! External libraries required\n\t! \tFFTW3\t -- Fast Fourier Transform in the West Library\n\t!\t\t\t(http://www.fftw.org/)\n\t! \tMPI library\n\t\t\n\tPROGRAM Kg\n\tUSE mpi\t \t \n\t! Declare variables\n\tIMPLICIT NONE\t\t\t\t\t \n\tINTEGER(kind=4), PARAMETER\t\t:: Nx=512\n\tINTEGER(kind=4), PARAMETER\t\t:: Nt=128\n\tINTEGER(kind=4), PARAMETER\t\t:: plotgap=32\t\n\tREAL(kind=8), PARAMETER\t\t\t:: &\n\t\tpi=3.14159265358979323846264338327950288419716939937510d0\n\tREAL(kind=8), PARAMETER\t\t\t:: Lx=9.0d0\n\tREAL(kind=8), PARAMETER\t\t\t:: Es=1.0d0\t\n REAL(kind=8), PARAMETER \t:: c=0.5\n\tREAL(kind=8)\t\t\t\t:: dt=0.50d0/REAL(Nt,kind(0d0)) \n\tCOMPLEX(kind=8), DIMENSION(1:1+Nx/2)\t:: kx \n\tREAL(kind=8), \t DIMENSION(1:Nx)\t:: x\n\tREAL(kind=8), DIMENSION(1:Nx) :: u,nonlin\n\tCOMPLEX(kind=8), DIMENSION(1:1+Nx/2) :: v,nonlinhat\n\tREAL(kind=8), DIMENSION(1:Nx) :: uold\n\tCOMPLEX(kind=8), DIMENSION(1:1+Nx/2) :: vold\n\tREAL(kind=8), DIMENSION(1:Nx) :: unew\n\tCOMPLEX(kind=8), DIMENSION(1:1+Nx/2) :: vnew\n\tREAL(kind=8), DIMENSION(1:Nt+1) :: time,enkin,enstr,enpot,en\n REAL(kind=8) :: runtime,start,finish,err\n\tINTEGER(kind=4)\t\t\t\t:: ierr,i,n,nn\n\tINTEGER(kind=4)\t\t\t\t:: plotnum\n\tINTEGER(kind=4), PARAMETER\t\t:: ntable=2*Nx+64, nwork=4*Nx\n\tINTEGER(kind=4), PARAMETER\t\t:: isign=0, isignf=-1, isignb=1\n\tREAL(kind=8),PARAMETER :: scale=1.0d0,scalef=1.0d0,scaleb=1.0d0/DBLE(Nx)\n REAL(kind=8), DIMENSION(1:ntable), SAVE :: tabledz,tablezd\n REAL(kind=8), DIMENSION(1:nwork) :: work\n INTEGER(kind=4), SAVE :: isys\n CHARACTER*100\t\t\t\t:: name_config\n\t\n CALL MPI_INIT(ierr)\n\t! set up fft\n CALL DZFFT(isign,Nx,scale,u,v,tabledz,work,isys)\n CALL ZDFFT(isign,Nx,scale,v,u,tablezd,work,isys)\n\n\tPRINT *,'Setup FFTs'\n\t! setup fourier frequencies\n\tCALL getgrid(Nx,Lx,pi,name_config,x,kx)\n\tPRINT *,'Setup grid and fourier frequencies'\n\tCALL initialdata(Nx,dt,c,x,u,uold)\n\tplotnum=1\t\n\tname_config = 'data/u' \n\t!CALL savedata(Nx,plotnum,name_config,u)\n CALL DZFFT(isignf,Nx,scalef,u, v, tabledz,work,isys)\n CALL DZFFT(isignf,Nx,scalef,uold,vold,tabledz,work,isys)\n PRINT *,'Transformed initialdata'\n\tCALL enercalc(Nx,isignf,isignb,isys,ntable,nwork,dt,Es,&\n\t\t\tenkin(plotnum),enstr(plotnum),&\n\t\t\tenpot(plotnum),en(plotnum),&\n\t\t\tkx,nonlin,nonlinhat,&\n\t\t\tv,vold,u,uold,tabledz,tablezd,work)\n\n\t\t\t\n\tPRINT *,'Got initial data, starting timestepping'\n\ttime(plotnum)=0.0d0\n start = MPI_WTIME()\n nn=1\n\tDO n=1,(Nt/3)\t\t\t\t\t\n ! Iteration 1\n\t\tDO i=1,Nx\n\t\t\tnonlin(i)=u(i)**3\n\t\tEND DO\n CALL DZFFT(isignf,Nx,scalef,nonlin,nonlinhat,tabledz,work,isys)\n\t\tDO i=1,Nx/2 + 1\n\t\t\tvnew(i)=( 0.25d0*(kx(i)*kx(i) - 1.0d0) &\n\t\t\t\t*(2.0d0*v(i)+vold(i)) &\n\t\t\t\t+(2.0d0*v(i)-vold(i))/(dt*dt) &\n\t\t\t\t+Es*nonlinhat(i) ) &\n\t\t\t\t/(1.0d0/(dt*dt) - 0.25d0*(kx(i)*kx(i) - 1.0d0))\n\t\tEND DO\n CALL ZDFFT(isignb,Nx,scaleb,vnew,unew,tablezd,work,isys)\n nn=nn+1\n\t\tIF (mod(nn,plotgap)==0) then\n\t\t\tplotnum=plotnum+1\n\t\t\ttime(plotnum)=n*dt\n\t\t\tPRINT *,'time',n*dt\n\t\t\tCALL enercalc(Nx,isignf,isignb,isys,ntable,nwork,dt,Es,&\n\t\t\t\tenkin(plotnum),enstr(plotnum),&\n\t\t\t\tenpot(plotnum),en(plotnum),kx,&\n\t\t\t\tnonlin,nonlinhat,vnew,v,unew,u,&\n tabledz,tablezd,work)\n\t\tEND IF\n \n ! Iteration 2\n DO i=1,Nx\n nonlin(i)=unew(i)**3\n END DO\n CALL DZFFT(isignf,Nx,scalef,nonlin,nonlinhat,tabledz,work,isys)\n DO i=1,Nx/2 + 1\n vold(i)=( 0.25d0*(kx(i)*kx(i) - 1.0d0) &\n *(2.0d0*vnew(i)+v(i)) &\n +(2.0d0*vnew(i)-v(i))/(dt*dt) &\n +Es*nonlinhat(i) ) &\n /(1.0d0/(dt*dt) - 0.25d0*(kx(i)*kx(i)-1.0d0))\n END DO\n call ZDFFT(isignb,Nx,scaleb,vold,uold,tablezd,work,isys)\n nn=nn+1\n IF (mod(nn,plotgap)==0) then\n plotnum=plotnum+1\n time(plotnum)=n*dt\n PRINT *,'time',n*dt\n CALL enercalc(Nx,isignf,isignb,isys,ntable,nwork,dt,Es,&\n enkin(plotnum),enstr(plotnum),&\n enpot(plotnum),en(plotnum),kx,&\n nonlin,nonlinhat,vold,vnew,uold,unew,&\n tabledz,tablezd,work)\n END IF\n \n ! Iteration 3\n DO i=1,Nx\n nonlin(i)=uold(i)**3\n END DO\n CALL DZFFT(isignf,Nx,scalef,nonlin,nonlinhat,tabledz,work,isys)\n DO i=1,Nx/2 + 1\n v(i)=( 0.25d0*(kx(i)*kx(i) - 1.0d0) &\n *(2.0d0*vold(i)+vnew(i)) &\n +(2.0d0*vold(i)-vnew(i))/(dt*dt) &\n +Es*nonlinhat(i) ) &\n /(1.0d0/(dt*dt) - 0.25d0*(kx(i)*kx(i)-1.0d0))\n END DO\n CALL ZDFFT(isignb,Nx,scaleb,v,u,tablezd,work,isys)\n nn=nn+1\n IF (mod(nn,plotgap)==0) then\n plotnum=plotnum+1\n time(plotnum)=n*dt\n PRINT *,'time',n*dt\n CALL enercalc(Nx,isignf,isignb,isys,ntable,nwork,dt,Es,&\n enkin(plotnum),enstr(plotnum),&\n enpot(plotnum),en(plotnum),kx,&\n nonlin,nonlinhat,v,vold,u,uold,&\n tabledz,tablezd,work)\n END IF\n\tEND DO\t\n ! clean up steps\n IF (mod(Nt,3).GT.0) THEN\n DO i=1,Nx\n nonlin(i)=u(i)**3\n END DO\n CALL DZFFT(isignf,Nx,scalef,nonlin,nonlinhat,tabledz,work,isys)\n DO i=1,Nx/2 + 1\n vnew(i)=( 0.25d0*(kx(i)*kx(i) - 1.0d0) &\n *(2.0d0*v(i)+vold(i)) &\n +(2.0d0*v(i)-vold(i))/(dt*dt) &\n +Es*nonlinhat(i) ) &\n /(1.0d0/(dt*dt) - 0.25d0*(kx(i)*kx(i)-1.0d0))\n END DO\n CALL ZDFFT(isignb,Nx,scaleb,vnew,unew,tablezd,work,isys)\n nn=nn+1\n IF (mod(nn,plotgap)==0) then\n plotnum=plotnum+1\n time(plotnum)=n*dt\n PRINT *,'time',n*dt\n CALL enercalc(Nx,isignf,isignb,isys,ntable,nwork,dt,Es,&\n enkin(plotnum),enstr(plotnum),&\n enpot(plotnum),en(plotnum),kx,&\n nonlin,nonlinhat,vnew,v,unew,u,&\n tabledz,tablezd,work)\n END IF\n \n END IF\n IF (mod(Nt,3).GT.1) THEN\n DO i=1,Nx\n nonlin(i)=unew(i)**3\n END DO\n CALL DZFFT(isignf,Nx,scalef,nonlin,nonlinhat,tabledz,work,isys)\n DO i=1,Nx/2 +1\n vold(i)=( 0.25d0*(kx(i)*kx(i) - 1.0d0) &\n *(2.0d0*vnew(i)+v(i)) &\n +(2.0d0*vnew(i)-v(i))/(dt*dt) &\n +Es*nonlinhat(i) ) &\n /(1.0d0/(dt*dt) -0.25d0*(kx(i)*kx(i)-1.0d0))\n END DO\n CALL ZDFFT(isignb,Nx,scaleb,vold,uold,tablezd,work,isys)\n nn=nn+1\n IF (mod(nn,plotgap)==0) then\n plotnum=plotnum+1\n time(plotnum)=n*dt\n PRINT *,'time',n*dt\n CALL enercalc(Nx,isignf,isignb,isys,ntable,nwork,dt,Es,&\n enkin(plotnum),enstr(plotnum),&\n enpot(plotnum),en(plotnum),kx,&\n nonlin,nonlinhat,vold,vnew,uold,unew,&\n tabledz,tablezd,work)\n END IF\n END IF\t\n\tPRINT *,'Finished time stepping'\n finish = MPI_WTIME()\n runtime=REAL(finish-start,kind(0d0))\n\tPRINT*,'Program took ',runtime,'for Time stepping'\n\tCALL saveresults(Nt,plotgap,time(1:1+n/plotgap),en(1:1+n/plotgap),&\n\t\t\tenstr(1:1+n/plotgap),enkin(1:1+n/plotgap),&\n enpot(1:1+n/plotgap))\t\n\t\t\t\n\t! Save times at which output was made in text format\n\tPRINT *,'Saved data'\n IF(mod(Nt,3)==0) CALL errorcalc(Nt,Nx,dt,c,x,unew,err) \n IF(mod(Nt,3)==1) CALL errorcalc(Nt,Nx,dt,c,x,uold,err)\n IF(mod(Nt,3)==2) CALL errorcalc(Nt,Nx,dt,c,x,u,err)\n name_config = 'data/errortime'\n CALL savetimeanderror(Nx,Nt,err,runtime,name_config)\n\n\tPRINT *,'Program execution complete'\n CALL MPI_FINALIZE(ierr)\n\tEND PROGRAM Kg\n", "meta": {"hexsha": "79ae2fa7b68d77d602e35d6545051f88d041571a", "size": 11887, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Codes/Fortran1DFourierR2C/KgSemiImp1d.f90", "max_stars_repo_name": "bkmgit/KleinGordon1D", "max_stars_repo_head_hexsha": "ce6ba332e542d74b72069ae253cca5e0a2ade425", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-01-21T03:57:51.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-21T03:57:51.000Z", "max_issues_repo_path": "Codes/Fortran1DFourierR2C/KgSemiImp1d.f90", "max_issues_repo_name": "bkmgit/KleinGordon1D", "max_issues_repo_head_hexsha": "ce6ba332e542d74b72069ae253cca5e0a2ade425", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Codes/Fortran1DFourierR2C/KgSemiImp1d.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": 40.8487972509, "max_line_length": 91, "alphanum_fraction": 0.5115672583, "num_tokens": 3833, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632876167045, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6836134225437721}} {"text": "!-----------------------------------------------------------------------\n! Saturation specific humidity\n!-----------------------------------------------------------------------\nsubroutine QSAT(water,P,T,Qs)\n\nuse Constants, only : &\n eps, &! Ratio of molecular weights of water and dry air\n e0, &! Saturation vapour pressure at Tm (Pa)\n Tm ! Melting point (K)\n\nimplicit none\n\nlogical, intent(in) :: &\n water ! Saturation wrt water if TRUE\n\nreal*8, intent(in) :: &\n P, &! Air pressure (Pa)\n T ! Temperature (K)\n\nreal*8, intent(out) :: &\n Qs ! Saturation specific humidity\n\nreal*8 :: &\n Tc, &! Temperature (C)\n es ! Saturation vapour pressure (Pa)\n\nTc = T - Tm\nif (Tc > 0 .or. water) then\n es = e0*exp(17.5043*Tc / (241.3 + Tc))\nelse\n es = e0*exp(22.4422*Tc / (272.186 + Tc))\nend if\nQs = eps*es / P\n\nend subroutine QSAT\n", "meta": {"hexsha": "083f4b2c5d0205f6aad6d7f760200157cb387915", "size": 971, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "deps/QSAT.f90", "max_stars_repo_name": "jmgnve/JFSM.jl", "max_stars_repo_head_hexsha": "5cbe139f2e7eb7d8e5844d8a7feffa93f69e8596", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "deps/QSAT.f90", "max_issues_repo_name": "jmgnve/JFSM.jl", "max_issues_repo_head_hexsha": "5cbe139f2e7eb7d8e5844d8a7feffa93f69e8596", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "deps/QSAT.f90", "max_forks_repo_name": "jmgnve/JFSM.jl", "max_forks_repo_head_hexsha": "5cbe139f2e7eb7d8e5844d8a7feffa93f69e8596", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-02-08T11:09:51.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-08T11:09:51.000Z", "avg_line_length": 26.9722222222, "max_line_length": 72, "alphanum_fraction": 0.4510813594, "num_tokens": 258, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632876167044, "lm_q2_score": 0.7371581626286833, "lm_q1q2_score": 0.683613417188825}} {"text": "program test_fft\n use adjac\n use adjac_fft\n implicit none\n\n integer, parameter :: n = 127\n type(adjac_double), dimension(2,2*n,3) :: x\n double precision, dimension(2,2*n,3) :: x_value\n double precision, dimension(2*n,2*n) :: jac\n complex(kind=kind(0d0)) :: v1, v2\n integer :: i, j\n\n do i = 1, n\n x_value(1,2*i-1,2) = 1 + i + i**2\n x_value(1,2*i,2) = 0\n call adjac_set_independent(x(1,2*i-1,2), x_value(1,2*i-1,2), 2*i-1)\n call adjac_set_independent(x(1,2*i,2), x_value(1,2*i,2), 2*i)\n end do\n\n write(*,*) 'forward transform'\n call fft(x_value(1,:,2))\n call fft(x(1,:,2))\n call adjac_get_dense_jacobian(x(1,:,2), jac)\n\n do i = 1, n\n v1 = x(1,i,2)%value\n v2 = x_value(1,i,2)\n if (abs(v1 - v2) > 1d-10) then\n write(*,*) 'FAIL', i, v1, v2\n stop\n end if\n do j = 1, n\n v1 = jac(2*i-1,2*j-1) + (0,1)*jac(2*i,2*j-1)\n v2 = exp(-2*(0,3.141592653589793d0)*(i-1)*(j-1)/n)\n if (abs(v1 - v2) > 1d-10) then\n write(*,*) 'FAIL', i, j, v1, v2\n stop\n end if\n end do\n end do\n write(*,*) 'OK'\n\n write(*,*) 'inverse transform'\n call ifft(x_value(1,:,2))\n call ifft(x(1,:,2))\n call adjac_get_dense_jacobian(x(1,:,2), jac)\n\n do i = 1, n\n if (mod(i,2) == 1) then\n v2 = 1 + (1 + i/2) + (1 + i/2)**2\n else\n v2 = 0\n end if\n\n v1 = x(1,i,2)%value\n if (abs(v1 - v2) > 1d-10) then\n write(*,*) 'FAIL', 'avalue', i, v1, v2\n stop\n end if\n\n v2 = x_value(1,i,2)\n if (abs(v1 - v2) > 1d-10) then\n write(*,*) 'FAIL', 'value', i, v1, v2\n stop\n end if\n\n do j = 1, n\n v1 = jac(2*i-1,2*j-1) + (0,1)*jac(2*i,2*j-1)\n if (i == j) then\n v2 = 1\n else\n v2 = 0\n end if\n if (abs(v1 - v2) > 1d-10) then\n write(*,*) 'FAIL', i, j, v1, v2\n stop\n end if\n end do\n end do\n write(*,*) 'OK'\nend program test_fft\n", "meta": {"hexsha": "0a0ee9c18eebddf5b4eba13ff12c77074779da53", "size": 1946, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "tests/test_fft.f95", "max_stars_repo_name": "gyzhangqm/adjac", "max_stars_repo_head_hexsha": "49e19123b7abee390ecfc29ae8c6327bc957690a", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2017-07-18T18:55:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-12T19:01:59.000Z", "max_issues_repo_path": "tests/test_fft.f95", "max_issues_repo_name": "pv/adjac", "max_issues_repo_head_hexsha": "49e19123b7abee390ecfc29ae8c6327bc957690a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/test_fft.f95", "max_forks_repo_name": "pv/adjac", "max_forks_repo_head_hexsha": "49e19123b7abee390ecfc29ae8c6327bc957690a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-07-30T21:02:25.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-23T19:12:17.000Z", "avg_line_length": 23.7317073171, "max_line_length": 72, "alphanum_fraction": 0.4856115108, "num_tokens": 830, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632876167045, "lm_q2_score": 0.7371581568543044, "lm_q1q2_score": 0.683613411833878}} {"text": "program test_funcs\n\nuse funcs\nuse assert, only: assert_isclose, wp\n\nimplicit none (type, external)\n\nreal(wp), parameter :: pi = 4._wp * atan(1._wp), pi3 = pi/3\ncomplex(wp), parameter :: cpi = (pi, pi)\ninteger :: N,D\n\n\ncall assert_isclose(csc(acsc(pi3)), pi3)\n\nif (.not.isdigit('3')) stop 1\nif (isdigit('x')) stop 1\n\nN=6; D=10\ncall ratnorm(N,D)\nif (.not. N==3 .and. D==5) stop 1\n\ncall assert_isclose(frac(pi), pi-3)\ncall assert_isclose(frac(-pi), -pi+3)\n\nprint *,'OK RPN test'\nend program\n", "meta": {"hexsha": "ebf79569d2dc29a65e9413177af248d482318941", "size": 488, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/test.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/tests/test.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/tests/test.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": 18.0740740741, "max_line_length": 59, "alphanum_fraction": 0.6639344262, "num_tokens": 176, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8459424528443252, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.6835783587408549}} {"text": "module ex_stdlib_function\n use, intrinsic :: iso_fortran_env\n use :: stdlib_optval\n use :: stdlib_math\n use :: stdlib_linalg\n use :: stdlib_specialfunctions\n use :: stdlib_quadrature\n use :: stdlib_random\n use :: stdlib_stats\n use :: stdlib_stats_distribution_uniform\n use :: stdlib_sorting\n implicit none\n private\n public :: ex_stdlib_optval\n public :: ex_stdlib_math\n public :: ex_stdlib_linalg\n public :: ex_stdlib_specialfunctions\n public :: ex_stdlib_quadrature\n public :: ex_stdlib_random\n public :: ex_stdlib_stats\n public :: ex_stdlib_stats_distribution_uniform\n public :: ex_stdlib_sorting\n\ncontains\n !| optional\u5f15\u6570\u304c\u306a\u3044\u3068\u304d\u306b\u6a19\u6e96\u5024\u3092\u8fd4\u3059\u95a2\u6570optval\u306e\u4f7f\u7528\u4f8b\uff0e\n subroutine ex_stdlib_optval()\n implicit none\n\n ! 1 0\n print *, optval(1, default=0), optval(default=0)\n\n ! 1.00000000 0.00000000\n print *, optval(1., default=0.), optval(default=0.)\n\n ! 1.0000000000000000 0.0000000000000000\n print *, optval(1d0, default=0d0), optval(default=0d0)\n\n ! T F\n print *, optval(.true., default=.false.), optval(default=.false.)\n\n ! (1.00000000,2.00000000) (0.00000000,0.00000000)\n print *, optval((1., 2.), default=(0., 0.)), optval(default=(0., 0.))\n\n block\n real(real64) :: x = 64.\n\n ! 8.0000000000000000 3.9999999999999996\n print *, root(x), root(x, 3)\n end block\n contains\n !| x\u306en\u4e57\u6839\u3092\u8a08\u7b97\u3059\u308b\uff0e\n real(real64) function root(x, n)\n implicit none\n real(real64), intent(in) :: x\n !! \u88ab\u958b\u5e73\u6570\n integer(int32), intent(in), optional :: n\n !! \u6307\u6570\n\n root = x**(1d0/optval(n, 2)) ! n\u304c\u7121\u3044\u3068\u304d\u306f2\u304c\u4f7f\u308f\u308c\u308b\n end function root\n end subroutine ex_stdlib_optval\n\n !| stdlib_math\u3067\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u624b\u7d9a\u306e\u4f7f\u7528\u4f8b\uff0e\n subroutine ex_stdlib_math()\n implicit none\n\n block\n ! [start, end]\u3092\u7b49\u9593\u9694\u306b\u5206\u5272\u3057\u305f\u6570\u3092\u914d\u5217\u3067\u8fd4\u3059\uff0e\n ! \u623b\u308a\u5024\u306e\u578b\u306f\uff0c[start,end]\u306e\u578b\u3068\u540c\u3058\uff0e\n\n ! 0.00000000 0.200000003 0.400000006 0.600000024 0.800000012 1.00000000\n print *, linspace(start=0., end=1., n=6)\n\n ! 0.0000000000000000 0.20000000000000001 0.40000000000000002 0.60000000000000009 0.80000000000000004 1.0000000000000000\n print *, linspace(0d0, 1d0, 6)\n\n ! \u6574\u6570\u578b\u3067\u7bc4\u56f2\u3092\u6307\u5b9a\u3059\u308b\u3068\uff0c\u623b\u308a\u5024\u306f\u500d\u7cbe\u5ea6\u5b9f\u6570\n ! 0.0000000000000000 0.20000000000000001 0.40000000000000002 0.60000000000000009 0.80000000000000004 1.0000000000000000\n print *, linspace(0, 1, 6)\n end block\n\n block\n complex(real64) :: start, end\n complex(real64), allocatable :: z(:)\n start = cmplx(1d0, 0d0)\n end = cmplx(0d0, 1d0)\n\n ! (1.0000000000000000,0.0000000000000000) (0.80000000000000004,0.20000000000000001) (0.59999999999999998,0.40000000000000002)\n ! (0.39999999999999991,0.60000000000000009) (0.19999999999999996,0.80000000000000004) (0.0000000000000000,1.0000000000000000)\n z = linspace(start, end, 6)\n print *, z\n end block\n\n block\n\n ! [base**start, base**end]\u306e\u7bc4\u56f2\u3092\u5bfe\u6570\u3067\u5206\u5272\u3059\u308b\u6570\u3092\u914d\u5217\u3067\u8fd4\u3059\uff0e\n ! \u623b\u308a\u5024\u306e\u578b\u306f\uff0c\u57fa\u672c\u7684\u306b[start,end]\u3042\u308b\u3044\u306fbase\u306e\u578b\u3068\u540c\u3058\uff0e\n\n ! base\u304c\u500d\u7cbe\u5ea6\u5b9f\u6570\u306a\u306e\u3067\u500d\u7cbe\u5ea6\u5b9f\u6570\u3067\u8fd4\u3059\uff0e\n ! 1.0000000000000000E-003 1.0000000000000000E-002 0.10000000000000001 1.0000000000000000 10.000000000000000\n print *, logspace(-3, 1, n=5, base=10d0)\n\n ! start, end\u304c\u5358\u7cbe\u5ea6\u5b9f\u6570\u306a\u306e\u3067\u5358\u7cbe\u5ea6\u5b9f\u6570\u3067\u8fd4\u3059\uff0e\n ! 1.00000005E-03 9.99999978E-03 0.100000001 1.00000000 10.0000000\n print *, logspace(-3., 1., n=5, base=10)\n\n ! start, end, base\u304c\u5168\u3066\u6574\u6570\u306a\u3089\uff0c\u6574\u6570\u3067\u5024\u3092\u8fd4\u3059\uff0e\n ! 0 0 0 1 10\n print *, logspace(start=-3, end=1, n=5, base=10)\n end block\n\n block\n ! \u6307\u5b9a\u3055\u308c\u305f\u533a\u9593\u3092\u7b49\u9593\u9694\u306b\u5206\u5272\u3057\u305f\u5024\u3092\u3082\u3064\u914d\u5217\u3067\u8fd4\u3059\uff0e\n\n ! \u5f15\u6570\u3092\u6574\u6570\u3067\u6307\u5b9a\u3059\u308b\uff0e\n ! \u5f15\u6570\u304c\u4e00\u3064\u306e\u5834\u5408\u306f\u7d42\u7aef\u3068\u3057\u3066\u6271\u3044\uff0c\u59cb\u70b9\u30921\uff0c\u9593\u9694\u30921\u3068\u3057\u3066\u6271\u3046\uff0e\n ! 1 2 3\n print *, arange(3) ! = arange(1,3,1)\n\n ! \u7d42\u7aef\u304c\u8ca0\u306e\u5834\u5408\uff0c\u59cb\u70b9\u306f1\uff0c\u9593\u9694\u3092-1\u3068\u3057\u3066\u6271\u3046\uff0e\n ! 1 0 -1\n print *, arange(-1) ! = arange(1,-1,-1)\n\n ! \u59cb\u70b9\u3068\u7d42\u70b9\u3092\u6307\u5b9a\uff0e\u9593\u9694\u30921\u3068\u3057\u3066\u6271\u3046\uff0e\n ! 0 1 2\n print *, arange(0, 2) ! = arange(0, 2, 1)\n\n ! \u59cb\u70b9\uff0c\u7d42\u70b9\uff0c\u9593\u9694\u3092\u6307\u5b9a\uff0e\n ! 0 2\n print *, arange(0, 2, 2)\n\n ! \u5f15\u6570\u3092\u5b9f\u6570\u3067\u6307\u5b9a\u3059\u308b\uff0e\n ! \u5f15\u6570\u304c\u4e00\u3064\u306e\u5834\u5408\u306f\u7d42\u7aef\u3068\u3057\u3066\u6271\u3044\uff0c\u59cb\u70b9\u30921\uff0c\u9593\u9694\u30921\u3068\u3057\u3066\u6271\u3046\uff0e\n ! 1.00000000 2.00000000 3.00000000\n print *, arange(3.0) ! = arange(1.0,3.0,1.0)\n\n ! \u7d42\u7aef\u304c\u8ca0\u306e\u5834\u5408\uff0c\u59cb\u70b9\u306f1\uff0c\u9593\u9694\u3092-1\u3068\u3057\u3066\u6271\u3046\uff0e\n ! 1.00000000 0.00000000 -1.00000000\n print *, arange(-1.0) ! = arange(1.0,-1.0,-1.0)\n\n ! \u59cb\u70b9\u3068\u7d42\u70b9\u3092\u6307\u5b9a\uff0e\u9593\u9694\u30921\u3068\u3057\u3066\u6271\u3046\uff0e\n ! 0.00000000 1.00000000 2.00000000\n print *, arange(0.0, 2.0) ! = arange(0.0, 2.0, 1.0)\n\n ! \u59cb\u70b9\uff0c\u7d42\u70b9\uff0c\u9593\u9694\u3092\u6307\u5b9a\uff0e\n ! 0.00000000 0.200000003\n print *, arange(0.0, 0.2, 0.2)\n end block\n\n block\n ! \u6307\u5b9a\u3055\u308c\u305f\u6570\u5024\u306e\u7bc4\u56f2[xmin, xmax]\u304b\u3089\u5916\u308c\u305f\u5165\u529b\u5024x\u306b\u5bfe\u3057\u3066\uff0c\u6700\u3082\u8fd1\u3044\u7bc4\u56f2\u5185\u306e\u5024\u3092\u8fd4\u3059\uff0e\n\n ! [-5, 5]\u306e\u7bc4\u56f2\u304b\u3089\u5916\u308c\u305f\u502410\u306b\u5bfe\u3057\u30665\u3092\u8fd4\u3059\uff0e\n ! 5\n print *, clip(10, -5, 5)\n\n ! [0.0, 0.1]\u306e\u7bc4\u56f2\u304b\u3089\u5916\u308c\u305f\u5024-1.0\u306b\u5bfe\u3057\u30660.0\u3092\u8fd4\u3059\uff0e\n ! 0.00000000\n print *, clip(-1.0, 0.0, 0.1)\n end block\n\n block\n ! \u4e8c\u3064\u306e\u6570\u306e\u6700\u5927\u516c\u7d04\u6570\u3092\u8a08\u7b97\u3059\u308b\uff0e\n ! 6\n print *, gcd(48, 18)\n end block\n end subroutine ex_stdlib_math\n\n !| stdlib_linalg\u3067\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u624b\u7d9a\u306e\u4f7f\u7528\u4f8b\uff0e\n subroutine ex_stdlib_linalg()\n implicit none\n\n block\n real(real32), allocatable :: v(:)\n real(real32), allocatable :: A(:, :)\n\n ! \u30d9\u30af\u30c8\u30eb\uff081\u6b21\u5143\u914d\u5217\uff09\u3092\u5165\u529b\u3068\u3057\u3066\uff0c\u305d\u306e\u5024\u3092\u5bfe\u89d2\u6210\u5206\u306b\u3082\u3064\u884c\u5217\u3092\u8fd4\u3059\uff0e\n ! [1, 1]\u3092\u5bfe\u89d2\u6210\u5206\u3068\u3057\u3066\u884c\u5217\u3092\u4f5c\u308b\uff0e\n ! i\\j 1 2\n ! +-----\n ! 1| 1 0\n ! 2| 0 1\n v = [1, 1]\n A = diag(v)\n print *, A\n\n ! [1,2,3,4]\u3092\u5bfe\u89d2\u6210\u5206\u306b\u3082\u3064\u884c\u5217\u3092\u8fd4\u3059\uff0e\n ! i\\j 1 2 3 4\n ! +-----------\n ! 1| 1 0 0 0\n ! 2| 0 2 0 0\n ! 3| 0 0 3 0\n ! 4| 0 0 0 4\n A = diag(arange(1, 4))\n print *, A\n\n block\n real(real32), allocatable :: u(:)\n real(real32), allocatable :: l(:)\n real(real32), allocatable :: d(:)\n\n allocate (l(3), source=-1.)\n allocate (u(3), source=1.)\n allocate (d(4), source=-2.)\n\n ! \u5bfe\u89d2\u7dda\u30921\u4e0b\u306b\u305a\u3089\u3057\uff0c[-1, -1, -1]\u3092\u6210\u5206\u306b\u3082\u3064\u884c\u5217\u3092\u8fd4\u3059\uff0e\n ! i\\j 1 2 3 4\n ! +-----------\n ! 1| 0 0 0 0\n ! 2|-1 0 0 0\n ! 3| 0 -1 0 0\n ! 4| 0 0 -1 0\n A = diag(l, -1)\n print *, A\n\n ! \u5bfe\u89d2\u7dda\u30921\u4e0a\u306b\u305a\u3089\u3057\uff0c[1, 1, 1]\u3092\u6210\u5206\u306b\u3082\u3064\u884c\u5217\u3092\u8fd4\u3059\uff0e\n ! i\\j 1 2 3 4\n ! +-----------\n ! 1| 0 1 0 0\n ! 2| 0 0 1 0\n ! 3| 0 0 0 1\n ! 4| 0 0 0 0\n A = diag(u, 1)\n print *, A\n\n ! i\\j 1 2 3 4\n ! +-----------\n ! 1| 2 1 0 0\n ! 2|-1 2 1 0\n ! 3| 0 -1 2 1\n ! 4| 0 0 -1 2\n A = diag(l, -1) + diag(d) + diag(u, 1)\n print *, A\n end block\n end block\n\n block\n ! \u5358\u4f4d\u884c\u5217\u3092\u8fd4\u3059\uff0e\n\n ! 2\u884c2\u5217\u306e\u5358\u4f4d\u884c\u5217\u3092\u8fd4\u3059\uff0e\n ! i\\j 1 2\n ! +-----\n ! 1| 1 0\n ! 2| 0 1\n print *, eye(2)\n\n ! 3\u884c3\u5217\u306e\u5358\u4f4d\u884c\u5217\u3092\u8fd4\u3059\uff0e\n ! i\\j 1 2 3\n ! +--------\n ! 1| 1 0 0\n ! 2| 0 1 0\n ! 3| 0 0 1\n print *, eye(3)\n\n ! 2\u884c1\u5217\u306e\u5358\u4f4d\u884c\u5217\u3092\u8fd4\u3059\n ! i\\j 1\n ! +--\n ! 1| 1\n ! 2| 0\n print *, eye(2, 1)\n\n ! 3\u884c3\u5217\u306e\u5358\u4f4d\u884c\u5217\u3092\u8fd4\u3059\uff0e\n ! i\\j 1 2 3\n ! +--------\n ! 1| 1 0 0\n ! 2| 0 1 0\n ! 3| 0 0 1\n print *, eye(3, 3)\n\n ! 3\u884c2\u5217\u306e\u5358\u4f4d\u884c\u5217\u3092\u8fd4\u3059\uff0e\n ! i\\j 1 2\n ! +-----\n ! 1| 1 0\n ! 2| 0 1\n ! 3| 0 0\n print *, eye(3, 2)\n end block\n\n block\n real(real32) :: A(3, 3)\n\n ! \u884c\u5217\u306etrace\u3092\u8a08\u7b97\u3059\u308b\uff0e\n ! i\\j 1 2 3\n ! +--------\n ! 1| 1 0 0\n ! 2| 0 1 0\n ! 3| 0 0 1\n ! 3\n A = eye(3, 3)\n print *, trace(A)\n\n ! i\\j 1 2 3\n ! +--------\n ! 1| 1 4 7\n ! 2| 2 5 8\n ! 3| 3 6 9\n ! 15\n A = reshape([1, 2, 3, 4, 5, 6, 7, 8, 9], [3, 3])\n print *, trace(A)\n end block\n\n block\n real(real32), allocatable :: A(:, :), u(:), v(:)\n\n ! \u76f4\u7a4du\u00d7v^T\u3092\u8a08\u7b97\u3059\u308b\uff0e\n ! i\\j 1 2 3\n ! +---------\n ! 1| 4 5 6\n ! 2| 8 10 12\n ! 3| 12 15 18\n u = [real :: 1, 2, 3]\n v = [real :: 4, 5, 6]\n A = outer_product(u, v)\n print *, A\n end block\n end subroutine ex_stdlib_linalg\n\n !| stdlib_specialfunctions\u3067\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u624b\u7d9a\u306e\u4f7f\u7528\u4f8b\uff0e\n subroutine ex_stdlib_specialfunctions()\n implicit none\n\n block\n real(real64) :: x\n x = 1d-1\n\n ! \u30eb\u30b8\u30e3\u30f3\u30c9\u30eb\u591a\u9805\u5f0f\n ! P_0(x) = 1\n ! 1.0000000000000000 1.0000000000000000\n print *, legendre(0, x), 1d0\n\n ! P_1(x) = x\n ! 0.10000000000000001 0.10000000000000001\n print *, legendre(1, x), x ! x\n\n ! P_2(x) = (3d0*x**2 - 1d0)/2d0\n ! -0.48499999999999999 -0.48499999999999999\n print *, legendre(2, x), (3d0*x**2 - 1d0)/2d0\n\n ! P_3(x) = (5d0*x**3 - 3d0*x)/2d0\n ! -0.14749999999999999 -0.14750000000000002\n print *, legendre(3, x), (5d0*x**3 - 3d0*x)/2d0\n\n ! P_10(x) = (46189d0*x**10 - 109395d0*x**8 + 90090d0*x**6 - 30030d0*x**4 + 3465d0*x**2 - 63d0)/256d0\n ! -0.12212499738710939 -0.12212499738710936\n print *, legendre(10, x), (46189d0*x**10 - 109395d0*x**8 + 90090d0*x**6 - 30030d0*x**4 + 3465d0*x**2 - 63d0)/256d0\n end block\n end subroutine ex_stdlib_specialfunctions\n\n !| stdlib_quadrature\u3067\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u624b\u7d9a\u306e\u4f7f\u7528\u4f8b\uff0e\n subroutine ex_stdlib_quadrature()\n implicit none\n\n real(real32) :: x(6), f(6)\n real(real32) :: w(6)\n\n x = linspace(-1., 1., 6)\n f = 5.*x**4\n ! x = [-1.0 -0.6 -0.2 0.2 0.6 1.0 ]\n ! f = [5.0 0.648 8E-03 8E-03 0.648 5.0 ]\n\n block\n ! \u53f0\u5f62\u5247\u3067\u95a2\u6570\u5024f\u3092\u7a4d\u5206\u3059\u308b\uff0e\n ! \u95a2\u6570\u5024\u3068\u5ea7\u6a19\u5024\u3092\u6307\u5b9a\u3059\u308b\uff0e\n ! 2.52479982\n print *, trapz(f, x)\n\n ! \u95a2\u6570\u5024\u3068\u305d\u306e\u30b5\u30f3\u30d7\u30ea\u30f3\u30b0\u70b9\u306e\u9593\u9694\u3092\u6307\u5b9a\u3059\u308b\uff0e\n ! 2.52480006\n print *, trapz(f, dx=0.4)\n\n ! \u30b5\u30f3\u30d7\u30ea\u30f3\u30b0\u70b9\u306e\u9593\u9694\u306e\u6307\u5b9a\u8aa4\u308a\uff0e\n ! 3.15600014\n print *, trapz(f, dx=0.5)\n end block\n\n block\n ! \u4e0e\u3048\u3089\u308c\u305fx\u5ea7\u6a19\u5024\u306b\u5bfe\u3057\u3066\uff0c\u91cd\u307f\u4fc2\u6570\u3092\u8fd4\u3059\uff0e\n ! 0.199999988 0.400000006 0.400000036 0.400000006 0.399999976 0.199999988\n w = trapz_weights(x)\n print *, w\n\n ! \u91cd\u307f\u4fc2\u6570w\u3068\u95a2\u6570\u5024f\u3092\u7528\u3044\u3066\u7a4d\u5206\u3059\u308b\uff0e\n ! 0.999999940 0.259200007 3.19999922E-03 3.20000271E-03 0.259199977 0.999999940\n ! 2.52480006\n print *, f*w\n print *, sum(f*w)\n end block\n\n block\n ! \u30b7\u30f3\u30d7\u30bd\u30f3\u5247\u3067\u95a2\u6570\u5024f\u3092\u7a4d\u5206\u3059\u308b\uff0e\n ! \u95a2\u6570\u5024\u3068\u5ea7\u6a19\u5024\u3092\u6307\u5b9a\u3059\u308b\uff0e\n ! 2.05973339\n print *, simps(f, x)\n\n ! \u95a2\u6570\u5024\u3068\u305d\u306e\u30b5\u30f3\u30d7\u30ea\u30f3\u30b0\u70b9\u306e\u9593\u9694\u3092\u6307\u5b9a\u3059\u308b\uff0e\n ! 2.05973339\n print *, simps(f, dx=0.4)\n\n ! \u30b5\u30f3\u30d7\u30ea\u30f3\u30b0\u70b9\u306e\u9593\u9694\u306e\u6307\u5b9a\u8aa4\u308a\uff0e\n ! 2.57466650\n print *, simps(f, dx=0.5)\n end block\n\n block\n ! \u4e0e\u3048\u3089\u308c\u305fx\u5ea7\u6a19\u5024\u306b\u5bfe\u3057\u3066\uff0c\u91cd\u307f\u4fc2\u6570\u3092\u8fd4\u3059\uff0e\n ! 0.141666651 0.491666645 0.366666734 0.366666734 0.491666645 0.141666681\n w = simps_weights(x)\n print *, w\n\n ! \u91cd\u307f\u4fc2\u6570w\u3068\u95a2\u6570\u5024f\u3092\u7528\u3044\u3066\u7a4d\u5206\u3059\u308b\uff0e\n ! 0.708333254 0.318599999 2.93333293E-03 2.93333642E-03 0.318599999 0.708333373\n ! 2.05973339\n print *, f*w\n print *, sum(f*w)\n end block\n\n block\n real(real64) :: x(6), w(6)\n\n ! Gauss-Legendre\u6c42\u7a4d\u6cd5\u306e\u30ce\u30fc\u30c9\u3068\u91cd\u307f\u3092\u8a08\u7b97\u3059\u308b\uff0e\n ! -0.93246951420315205 -0.66120938646626448 -0.23861918608319693 0.23861918608319693 0.66120938646626448 0.93246951420315205\n ! 0.17132449237917019 0.36076157304813866 0.46791393457269126 0.46791393457269126 0.36076157304813866 0.17132449237917019\n call gauss_legendre(x, w)\n print *, x\n print *, w\n\n ! \u30ce\u30fc\u30c9\u3068\u91cd\u307f\u3092\u4f7f\u3063\u3066\uff0cx\u304c[-1, 1]\u306e\u7bc4\u56f2\u30675x^4\u3092\u7a4d\u5206\u3059\u308b\uff0e\n ! 1.9999999999999987\n print *, sum(5.*x**4*w)\n end block\n\n block\n real(real64) :: x(6), w(6)\n\n ! Gauss-Legendre-Lobatto\u6c42\u7a4d\u6cd5\u306e\u30ce\u30fc\u30c9\u3068\u91cd\u307f\u3092\u8a08\u7b97\u3059\u308b\uff0e\n ! -1.0000000000000000 -0.76505532392946474 -0.28523151648064510 0.28523151648064510 0.76505532392946474 1.0000000000000000\n ! 6.6666666666666666E-002 0.37847495629784678 0.55485837703548646 0.55485837703548646 0.37847495629784678 6.6666666666666666E-002\n call gauss_legendre_lobatto(x, w)\n print *, x\n print *, w\n\n ! \u30ce\u30fc\u30c9\u3068\u91cd\u307f\u3092\u4f7f\u3063\u3066\uff0cx\u304c[-1, 1]\u306e\u7bc4\u56f2\u30675x^4\u3092\u7a4d\u5206\u3059\u308b\uff0e\n ! 1.9999999999999993\n print *, sum(5.*x**4*w)\n end block\n end subroutine ex_stdlib_quadrature\n\n !| stdlib_random\u3067\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u624b\u7d9a\u306e\u4f7f\u7528\u4f8b\uff0e\n subroutine ex_stdlib_random()\n implicit none\n\n integer(int32) :: seed_put, seed_get\n\n ! \u4e71\u6570\u306e\u7a2e\u3092\u8a2d\u5b9a\u30fb\u53d6\u5f97\u3059\u308b\uff0e\n seed_put = 135792468\n call random_seed(seed_put, seed_get)\n\n ! \u5165\u529b\u3055\u308c\u305f\u6574\u6570\u306ekind\u306b\u57fa\u3065\u3044\u3066\uff0c\u305d\u306e\u6574\u6570\u306e\u7bc4\u56f2\u3067\u64ec\u4f3c\u4e71\u6570\u3092\u751f\u6210\u3059\u308b\uff0e\n ! 1\u30d0\u30a4\u30c8\u6574\u6570\u306e\u7bc4\u56f2 [-2^7, 2^7 -1]\u5185\u3067\u4e71\u6570\u3092\u751f\u6210\u3059\u308b\uff0e\n ! -90\n print *, dist_rand(0_int8)\n\n ! 2\u30d0\u30a4\u30c8\u6574\u6570\u306e\u7bc4\u56f2 [-2^15, 2^15 -1]\u5185\u3067\u4e71\u6570\u3092\u751f\u6210\u3059\u308b\uff0e\n ! -32725\n print *, dist_rand(0_int16)\n\n ! 4\u30d0\u30a4\u30c8\u6574\u6570\u306e\u7bc4\u56f2 [-2^31, 2^31 -1]\u5185\u3067\u4e71\u6570\u3092\u751f\u6210\u3059\u308b\uff0e\n ! -1601563881\n print *, dist_rand(0_int32)\n\n ! 8\u30d0\u30a4\u30c8\u6574\u6570\u306e\u7bc4\u56f2 [-2^63, 2^63 -1]\u5185\u3067\u4e71\u6570\u3092\u751f\u6210\u3059\u308b\uff0e\n ! 180977695517992208\n print *, dist_rand(0_int64)\n end subroutine ex_stdlib_random\n\n !| stdlib_stats\u3067\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u624b\u7d9a\u306e\u4f7f\u7528\u4f8b\uff0e\n subroutine ex_stdlib_stats()\n implicit none\n real(real32) :: x(1:6) = [1., 2., 3., 4., 5., 6.]\n real(real32) :: y(1:2, 1:3) = reshape([1., 2., 3., 4., 5., 6.], [2, 3])\n\n ! x = [1,2,3,4,5,6]^T\n ! y =\n ! i\\j 1 2 3\n ! +--------\n ! 1| 1 3 5\n ! 2| 2 4 6\n\n block\n ! \u5e73\u5747\u5024\u3092\u8a08\u7b97\u3059\u308b\uff0e\n ! \u914d\u5217\u306e\u5168\u8981\u7d20\u306e\u5e73\u5747\u3092\u8a08\u7b97\u3059\u308b\uff0e=(1+2+3+4+5+6)/6\n ! 3.50000000\n print *, mean(x)\n\n ! \u914d\u5217\u306e\u5168\u8981\u7d20\u306e\u3046\u3061\uff0c3\u3088\u308a\u5927\u304d\u3044\u5024\u306e\u5e73\u5747\u3092\u8a08\u7b97\u3059\u308b\uff0e=(4_5+6)/3\n ! 5.00000000\n print *, mean(x, mask=(x > 3.))\n\n ! \u914d\u5217\u306e\u5168\u8981\u7d20\u306e\u5e73\u5747\u3092\u8a08\u7b97\u3059\u308b\uff0e=(1+2+3+4+5+6)/6\n ! 3.50000000\n print *, mean(y)\n\n ! \u914d\u5217\u306e\u7b2c1\u6b21\u5143\u65b9\u5411\u6210\u5206\u306e\u5e73\u5747\u3092\u8a08\u7b97\u3059\u308b\uff0e=[(1+2)/2, (3+4)/2, (5+6)/2]\n ! 1.50000000 3.50000000 5.50000000\n print *, mean(y, dim=1)\n\n ! \u914d\u5217\u306e\u7b2c1\u6b21\u5143\u65b9\u5411\u6210\u5206\u306e\u3046\u3061\uff0c3\u3088\u308a\u5927\u304d\u3044\u5024\u306e\u5e73\u5747\u3092\u8a08\u7b97\u3059\u308b\uff0e=[\u5b58\u5728\u3057\u306a\u3044, 4/1, (5+6)/2]\n ! \u6210\u5206\u304c0\u500b\u306e\u5834\u5408\uff0c0/0\u306e\u305f\u3081NaN\u306b\u306a\u308b\uff0e\n ! NaN 4.00000000 5.50000000\n print *, mean(y, dim=1, mask=(y > 3.))\n end block\n\n block\n real(real32) :: x(1:6) = [1., 1., 6., 7., 8., 9.]\n real(real32) :: y(1:3, 1:2) = reshape([0., 1., 6., 7., 8., 9.], [3, 2])\n ! x = [1,1,6,7,8,9]^T\n ! y =\n ! i\\j 1 2\n ! +-----\n ! 1| 0 7\n ! 2| 1 8\n ! 3| 6 9\n\n ! \u4e2d\u592e\u5024\u3092\u8a08\u7b97\u3059\u308b\uff0e\n ! \u914d\u5217\u306e\u5168\u8981\u7d20\u306e\u6210\u5206\u304b\u3089\u4e2d\u592e\u5024\u3092\u8a08\u7b97\u3059\u308b\uff0e=(6+7)/2\n ! 6.50000000\n print *, median(x)\n\n ! \u914d\u5217\u306e\u5168\u8981\u7d20\u306e\u6210\u5206\u306e\u3046\u30616\u3088\u308a\u5927\u304d\u3044\u5024[7,8,9]\u306e\u4e2d\u592e\u5024\u3092\u8a08\u7b97\u3059\u308b\uff0e\n ! 8.00000000\n print *, median(x, mask=(x > 6.))\n\n ! \u914d\u5217\u306e\u5168\u8981\u7d20\u306e\u6210\u5206\u304b\u3089\u4e2d\u592e\u5024\u3092\u8a08\u7b97\u3059\u308b\uff0e=(6+7)/2\n ! 6.50000000\n print *, median(y)\n\n ! \u914d\u5217\u306e\u7b2c1\u6b21\u5143\u65b9\u5411\u6210\u5206\u306e\u4e2d\u592e\u5024\u3092\u8a08\u7b97\u3059\u308b\uff0e= [median([0,1,6]), median(7,8,9)]\n ! 1.00000000 8.00000000\n print *, median(y, dim=1)\n\n ! \u914d\u5217\u306e\u7b2c1\u6b21\u5143\u65b9\u5411\u6210\u5206\u306e\u3046\u3061\uff0c3\u3088\u308a\u5927\u304d\u3044\u5024\u306e\u4e2d\u592e\u5024\u3092\u8a08\u7b97\u3059\u308b\uff0e=[median([6]), median(7,8,9)]\n ! 6.00000000 8.00000000\n print *, median(y, dim=1, mask=(y > 3.))\n end block\n\n block\n ! \u914d\u5217\u306e\u5206\u6563variance\u3092\u8a08\u7b97\u3059\u308b\uff0e\n ! \u8a08\u7b97\u5f0f\u306fvar(array) = 1/(n-1) sum_i (array(i) - mean(array))^2, n\u306f\u8981\u7d20\u6570\uff0e\n\n ! x = [1,2,3,4,5,6]^T\n ! y =\n ! i\\j 1 2 3\n ! +--------\n ! 1| 1 3 5\n ! 2| 2 4 6\n\n ! \u5168\u8981\u7d20\u306e\u5206\u6563\u3092\u8a08\u7b97\u3059\u308b\uff0e\n ! 3.50000000\n print *, var(x)\n\n ! corrected=.false.\u306e\u5834\u5408(n-1)\u3067\u306f\u306a\u304fn\u3067\u30b9\u30b1\u30fc\u30ea\u30f3\u30b0\u3059\u308b\uff0e\n ! 2.91666675\n print *, var(x, corrected=.false.)\n\n ! \u5168\u8981\u7d20\u306e\u5206\u6563\u3092\u8a08\u7b97\u3059\u308b\uff0e\n ! 3.50000000\n print *, var(y)\n\n ! \u914d\u5217\u306e\u7b2c1\u6b21\u5143\u65b9\u5411\u6210\u5206\u306e\u5206\u6563\u3092\u8a08\u7b97\u3059\u308b\uff0e=[var([1,2]), var([3,4]), var([5,6])]\n ! 0.500000000 0.500000000 0.500000000\n print *, var(y, dim=1)\n\n ! \u914d\u5217\u306e\u7b2c1\u6b21\u5143\u65b9\u5411\u6210\u5206\u306e\u3046\u3061\uff0c3\u3088\u308a\u5927\u304d\u3044\u5024\u306e\u5206\u6563\u3092\u8a08\u7b97\u3059\u308b\uff0e=[var([]), var([4]), var([5,6])]\n ! NaN NaN 0.500000000\n print *, var(y, dim=1, mask=y > 3.)\n\n ! \u914d\u5217\u306e\u7b2c1\u6b21\u5143\u65b9\u5411\u6210\u5206\u306e\u3046\u3061\uff0c3\u3088\u308a\u5927\u304d\u3044\u5024\u306e\u5206\u6563\u3092\u8a08\u7b97\u3059\u308b\uff0e=[var([]), var([4]), var([5,6])]\n ! n-1\u3067\u306f\u306a\u304fn\u3067\u30b9\u30b1\u30fc\u30ea\u30f3\u30b0\u3059\u308b\uff0e\n ! NaN 0.00000000 0.250000000\n print *, var(y, dim=1, mask=y > 3., corrected=.false.)\n end block\n\n block\n ! \u6307\u5b9a\u3055\u308c\u305f\u914d\u5217\u306e\u6b21\u5143\u306b\u304a\u3051\u308b\u5171\u5206\u6563covariance\u3092\u8a08\u7b97\u3059\u308b\uff0e\n ! \u8a08\u7b97\u5f0f\u306fcov(array) = 1/(n-1) sum_i (array(i) - mean(array) * (array(i) - mean(array))), n\u306f\u8981\u7d20\u6570\uff0e\n\n ! x = [1,2,3,4,5,6]^T\n ! y =\n ! i\\j 1 2 3\n ! +--------\n ! 1| 1 3 5\n ! 2| 2 4 6\n\n ! \u5168\u8981\u7d20\u306e\u5171\u5206\u6563\u3092\u8a08\u7b97\u3059\u308b\uff0e\n ! 3.50000000\n print *, cov(x, dim=1)\n\n ! n-1\u3067\u306f\u306a\u304fn\u3067\u30b9\u30b1\u30fc\u30ea\u30f3\u30b0\u3059\u308b\uff0e\n ! 2.91666675\n print *, cov(x, dim=1, corrected=.false.)\n\n ! \u914d\u5217\u306e\u7b2c1\u6b21\u5143\u65b9\u5411\u6210\u5206\u306e\u5206\u6563\u3092\u8a08\u7b97\u3059\u308b\uff0e\n ! y\u306e\u5834\u5408\uff0c\u8a08\u7b97\u4e2d\u306b\u7528\u3044\u3066\u3044\u308bmean\u304c3\u6210\u5206\u306e\u914d\u5217\u3092\u8fd4\u3059\u306e\u3067\uff0c\u5404\u6b21\u5143\u30673\u500b\u306e\u5171\u5206\u6563\u304c\u5f97\u3089\u308c\uff0c\u5408\u8a08\u30673x3=9\u500b\u306e\u5024\u304c\u8fd4\u3055\u308c\u308b\uff0e\n ! 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000\n print *, cov(y, dim=1)\n end block\n\n block\n real(real32) :: y(1:2, 1:3) = reshape([-1., 40., -3., 4., 10., 6.], [2, 3])\n\n ! x = [1,2,3,4,5,6]^T\n ! y =\n ! i\\j 1 2 3\n ! +----------\n ! 1| -1 -3 10\n ! 2| 40 4 6\n\n ! Pearson\u306e\u76f8\u95a2\u4fc2\u6570\u3092\u8a08\u7b97\u3059\u308b\uff0e\n ! \u8a08\u7b97\u5f0f\u306fcorr(x, y) = cov(x, y) / sqrt( var(x) * var(y))\n\n ! \u5168\u8981\u7d20\u3092\u7528\u3044\u3066\u76f8\u95a2\u4fc2\u6570\u3092\u8a08\u7b97\u3059\u308b\uff0e\n ! 1.00000000\n print *, corr(x, dim=1)\n\n ! \u914d\u5217\u306e\u7b2c1\u6b21\u5143\u65b9\u5411\u6210\u5206\u306e\u5206\u6563\u3092\u8a08\u7b97\u3059\u308b\uff0e\n ! y\u306e\u5834\u5408\uff0c\u8a08\u7b97\u4e2d\u306b\u7528\u3044\u3066\u3044\u308bcov\u304c9\u6210\u5206\u306e\u914d\u5217\u3092\u8fd4\u3059\u306e\u3067\uff0ccorr\u306e\u623b\u308a\u5024\u30829\u500b\u306b\u306a\u308b\uff0e\n ! 1.00000000 1.00000000 -0.999999940 1.00000000 1.00000000 -0.999999940 -1.00000000 -1.00000000 0.999999940\n print *, corr(y, dim=1)\n\n ! \u914d\u5217\u306e\u7b2c2\u6b21\u5143\u65b9\u5411\u6210\u5206\u306e\u5206\u6563\u3092\u8a08\u7b97\u3059\u308b\uff0e\n ! \u8a08\u7b97\u4e2d\u306b\u7528\u3044\u3066\u3044\u308bcov\u304c4\u6210\u5206\u306e\u914d\u5217\u3092\u8fd4\u3059\u306e\u3067\uff0ccorr\u306e\u623b\u308a\u5024\u30824\u500b\u306b\u306a\u308b\uff0e\n ! 1.00000000 -0.324803889 -0.324803889 0.999999940\n print *, corr(y, dim=2)\n end block\n\n block\n\n ! x = [1,2,3,4,5,6]^T\n\n ! k\u6b21\u306e\u30e2\u30fc\u30e1\u30f3\u30c8\u3092\u8a08\u7b97\u3059\u308b\uff0e\n ! \u8a08\u7b97\u5f0f\u306f moment(array) = 1/n sum_i (array(i) - mean(array))^k\n ! \u4e2d\u5fc3\u304c\u4e0e\u3048\u3089\u308c\u3066\u3044\u308b\u6642\u306e\u8a08\u7b97\u5f0f\u306fmoment(array) = 1/n sum_i (array(i) - center)^k\n\n ! \u914d\u5217\u306e\u5168\u8981\u7d20\u3092\u7528\u3044\u30662\u6b21\u306e\u30e2\u30fc\u30e1\u30f3\u30c8\u3092\u8a08\u7b97\u3059\u308b\uff0e\n ! 2.91666675\n print *, moment(x, order=2)\n\n ! \u914d\u5217\u306e\u5168\u8981\u7d20\u3092\u7528\u3044\u30662\u6b21\u306e\u30e2\u30fc\u30e1\u30f3\u30c8\u3092\u8a08\u7b97\u3059\u308b\uff0e\n ! 2.91666675\n print *, moment(y, order=2)\n\n ! \u914d\u5217\u306e\u7b2c1\u6b21\u5143\u65b9\u5411\u6210\u5206\u3092\u7528\u3044\u30662\u6b21\u306e\u30e2\u30fc\u30e1\u30f3\u30c8\u3092\u8a08\u7b97\u3059\u308b\uff0e=[moment([1,2], 2), moment([3,4], 2), moment([5,6], 2)]\n ! 0.250000000 0.250000000 0.250000000\n print *, moment(y, order=2, dim=1)\n\n ! \u914d\u5217\u306e\u7b2c1\u6b21\u5143\u65b9\u5411\u6210\u5206\u306e\u3046\u3061\uff0c3\u3088\u308a\u5927\u304d\u3044\u5024\u3092\u7528\u3044\u30662\u6b21\u306e\u30e2\u30fc\u30e1\u30f3\u30c8\u3092\u8a08\u7b97\u3059\u308b\uff0e=[moment([], 2), moment([4], 2), moment([5,6], 2)]\n ! NaN 0.00000000 0.250000000\n print *, moment(y, 2, 1, mask=(y > 3.))\n\n ! \u4e2d\u5fc3\u3092\u4e0e\u3048\u30662\u6b21\u306e\u30e2\u30fc\u30e1\u30f3\u30c8\u3092\u8a08\u7b97\u3059\u308b\uff0e\n ! 15.1666670\n print *, moment(x, 2, center=0.)\n\n ! \u4e2d\u5fc3\u3092\u4e0e\u3048\u3066\uff0c\u914d\u5217\u306e\u7b2c1\u6b21\u5143\u65b9\u5411\u6210\u5206\u3092\u7528\u3044\u30662\u6b21\u306e\u30e2\u30fc\u30e1\u30f3\u30c8\u3092\u8a08\u7b97\u3059\u308b\uff0e=[moment([1,2], 2, 0), moment([3,4], 2, 0), moment([5,6], 2, 0)]\n ! 1.50000000 3.50000000 5.50000000\n print *, moment(y, 1, 1, center=0.)\n end block\n end subroutine ex_stdlib_stats\n\n !| stdlib_stats_distribution_uniform\u3067\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u624b\u7d9a\u306e\u4f7f\u7528\u4f8b\uff0e\n subroutine ex_stdlib_stats_distribution_uniform()\n use :: stdlib_math\n implicit none\n real(real32) :: x(10)\n integer(int32) :: n(10)\n complex(real32) :: z(10)\n integer :: seed_put, seed_get\n\n n = arange(10)\n x = arange(10.)\n z = linspace(cmplx(1., 1.), cmplx(10., 10.), 10)\n ! n = [1 2 3 4 5 6 7 8 9 10]\n ! x = [1. 2. 3. 4. 5. 6. 7. 8. 9. 10.]\n ! z = [(1.,1.) (2.,2.) (3.,3.) (4.,4.) (5.,5.) (6.,6.) (7.,7.) (8.,8.) (9..9.) (10.,10.)]\n\n block\n seed_put = 32165498\n call random_seed(seed_put, seed_get)\n\n ! Fisher-Yates\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u306b\u57fa\u3065\u3044\u3066\u30e9\u30f3\u30c0\u30e0\u306b\u4e26\u3073\u66ff\u3048\u308b\uff0e\n\n ! \u6574\u6570\u3092\u4e26\u3073\u66ff\u3048\u308b\uff0e\n ! 10 6 9 2 8 1 3 5 7 4\n print *, shuffle(n)\n\n ! \u5b9f\u6570\u3092\u4e26\u3073\u66ff\u3048\u308b\uff0e\n ! 5. 10. 9. 4. 3. 8. 2. 1. 7. 6.\n print *, shuffle(x)\n\n ! \u8907\u7d20\u6570\u3092\u4e26\u3073\u66ff\u3048\u308b\uff0e\n ! (8.,8.) (7.,7.) (4.,4.) (1.,1.) (5.,5.) (9.,9.) (6.,6.) (3.,3.) (2.,2.) (10.,10.)\n print *, shuffle(z)\n end block\n\n block\n\n seed_put = 1234567\n call random_seed(seed_put, seed_get)\n\n ! [0,1]\u306e\u7bc4\u56f2\u3067\u4e00\u69d8\u5206\u5e03\u3092\u8fd4\u3059\uff0e\n\n ! \u5f15\u6570\u3092\u4f55\u3082\u6307\u5b9a\u3057\u306a\u3051\u308c\u3070\uff0c[0,1]\u306e\u7bc4\u56f2\u3067\uff0c\u5358\u7cbe\u5ea6\u5b9f\u6570\u3068\u3057\u3066\u5024\u3092\u8fd4\u3059\uff0e\n ! 0.161520019\n print *, rvs_uniform()\n\n ! scale\u304c\u6307\u5b9a\u3055\u308c\u308b\u3068\uff0c[0,scale]\u306e\u7bc4\u56f2\u3067\u4e00\u69d8\u5206\u5e03\u3092\u8fd4\u3059\uff0e\n ! scale\u306e\u578b\u306b\u3088\u3063\u3066\u623b\u308a\u5024\u306e\u578b\u304c\u6c7a\u5b9a\u3055\u308c\u308b\uff0e\n ! [0,3.]\u306e\u7bc4\u56f2\u3067\u5358\u7cbe\u5ea6\u5b9f\u6570\u5024\u3092\u8fd4\u3059\uff0e\n ! 1.65974522\n print *, rvs_uniform(scale=3.0)\n\n ! [0,20]\u306e\u7bc4\u56f2\u3067\u6574\u6570\u5024\u3092\u8fd4\u3059\uff0e\n ! 14\n print *, rvs_uniform(scale=20)\n\n ! loc\u3068scale\u304c\u6307\u5b9a\u3055\u308c\u308b\u3068\uff0c[loc,loc+scale]\u306e\u7bc4\u56f2\u3067\u4e00\u69d8\u5206\u5e03\u3092\u8fd4\u3059\uff0e\n ! loc\u304a\u3088\u3073scale\u306e\u578b\u306b\u3088\u3063\u3066\u623b\u308a\u5024\u306e\u578b\u304c\u6c7a\u5b9a\u3055\u308c\u308b\uff0e\n ! [-0.5,0.5]\u306e\u7bc4\u56f2\u3067\u5024\u3092\u8fd4\u3059\uff0e\n ! 0.486900032\n print *, rvs_uniform(loc=-0.5, scale=1.0)\n\n ! array\u3092\u6307\u5b9a\u3059\u308b\u3068\uff0carray_size\u306e\u6570\u3060\u3051\u5024\u3092\u8fd4\u3059\uff0e\n ! -0.885760069 -0.219811499 -0.145343125 -0.535613418 -0.715533257 -0.251231968 -0.698165953 -0.662991643 -0.431156635 -0.403834939\n print *, rvs_uniform(loc=-1.0, scale=1.0, array_size=10) ![-1.,1.]\n\n block\n real :: a(3, 4, 5), b(3, 4, 5)\n\n ! [-0.5, 0.5]\u306e\u7bc4\u56f2\u3067\uff0c60\u500b\u306e\u5024\u3092\u8fd4\u3059\uff0e\n a = -0.5\n b = 1.0\n print *, rvs_uniform(loc=a, scale=b)\n end block\n end block\n\n block\n\n seed_put = 1234567\n call random_seed(seed_put, seed_get)\n\n ! \u4e00\u69d8\u5206\u5e03\u306e\u78ba\u7387\u5bc6\u5ea6\u95a2\u6570\u3092\u8a08\u7b97\u3059\u308b\uff0e\n\n ! [2, 12]\u306e\u7bc4\u56f2\u3067\uff0cx=3\u306b\u304a\u3051\u308b\u78ba\u7387\u5bc6\u5ea6\u95a2\u6570\u3092\u8a08\u7b97\u3059\u308b\uff0e\n ! 9.09090936E-02\n print *, pdf_uniform(x=3, loc=2, scale=10)\n\n ! [0, 1]\u306e\u7bc4\u56f2\u3067\uff0cx=0.5\u306b\u304a\u3051\u308b\u78ba\u7387\u5bc6\u5ea6\u95a2\u6570\u3092\u8a08\u7b97\u3059\u308b\uff0e\n ! 1.00000000\n print *, pdf_uniform(0.5, 0.0, 1.0)\n\n ! [-1, 1]\u306e\u7bc4\u56f2\u3067\uff0cx=0.7\u306b\u304a\u3051\u308b\u78ba\u7387\u5bc6\u5ea6\u95a2\u6570\u3092\u8a08\u7b97\u3059\u308b\uff0e\n ! 0.500000000\n print *, pdf_uniform(0.7, -1.0, 2.0)\n\n block\n real(real32) :: a(3, 4, 5), b(3, 4, 5), x(3, 4, 5)\n\n a(:, :, :) = 0.\n b(:, :, :) = 2.\n ! [0,2]\u306e\u7bc4\u56f2\u3067\u9023\u7d9a\u5206\u5e03\u306e\u5024\u309260\u500b\u53d6\u5f97\u3059\u308b\uff0e\n x = reshape(rvs_uniform(0., 2., size(a)), shape(a))\n ! [0,2]\u306e\u7bc4\u56f2\u3067\uff0cx\u306b\u304a\u3051\u308b\u78ba\u7387\u5bc6\u5ea6\u95a2\u6570\u309260\u500b\u8a08\u7b97\u3059\u308b\uff0e\n print *, pdf_uniform(x, a, b)\n end block\n end block\n\n block\n\n seed_put = 1234567\n call random_seed(seed_put, seed_get)\n\n ! \u7d2f\u7a4d\u5206\u5e03\u95a2\u6570\u3092\u8a08\u7b97\u3059\u308b\uff0e\n ! [0, 1]\u306e\u7bc4\u56f2\u3067\uff0cx=0.5\u306b\u304a\u3051\u308b\u7d2f\u7a4d\u5206\u5e03\u95a2\u6570\u3092\u8a08\u7b97\u3059\u308b\uff0e\n ! 0.500000000\n print *, cdf_uniform(x=0.5, loc=0., scale=1.)\n\n ! [-1.0, 1.0]\u306e\u7bc4\u56f2\u3067\uff0cx=0.7\u306b\u304a\u3051\u308b\u7d2f\u7a4d\u5206\u5e03\u95a2\u6570\u3092\u8a08\u7b97\u3059\u308b\n ! 0.850000024\n print *, cdf_uniform(0.7, -1.0, 2.0)\n\n ! [2, 12]\u306e\u7bc4\u56f2\u3067\uff0cx=6\u306b\u304a\u3051\u308b\u7d2f\u7a4d\u5206\u5e03\u95a2\u6570\u3092\u8a08\u7b97\u3059\u308b\n ! 0.454545468\n print *, cdf_uniform(x=6, loc=2, scale=10) ! a cumulative at 6 in [2, 10]\n\n block\n real(real32) :: a(3, 4, 5), b(3, 4, 5), x(3, 4, 5)\n\n a(:, :, :) = -1.\n b(:, :, :) = 2.\n ! [0,2]\u306e\u7bc4\u56f2\u3067\u9023\u7d9a\u5206\u5e03\u306e\u5024\u309260\u500b\u53d6\u5f97\u3059\u308b\uff0e\n x = reshape(rvs_uniform(-1.0, 2.0, size(a)), shape(a))\n ! [0,2]\u306e\u7bc4\u56f2\u3067\uff0cx\u306b\u304a\u3051\u308b\u7d2f\u7a4d\u5206\u5e03\u95a2\u6570\u309260\u500b\u8a08\u7b97\u3059\u308b\uff0e\n print *, cdf_uniform(x, a, b)\n end block\n end block\n end subroutine ex_stdlib_stats_distribution_uniform\n\n !| stdlib_sorting\u3067\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u624b\u7d9a\u306e\u4f7f\u7528\u4f8b\uff0e\n subroutine ex_stdlib_sorting()\n implicit none\n\n integer(int32), allocatable :: array(:)\n array = [5, 4, 3, 1, 10, 4, 9]\n\n block\n ! \u30a4\u30f3\u30c8\u30ed\u30bd\u30fc\u30c8\u3092\u5229\u7528\u3057\u3066\u4e26\u3073\u66ff\u3048\u308b\uff0e\n ! 1 3 4 4 5 9 10\n call sort(array)\n print *, array\n\n ! \u30a4\u30f3\u30c8\u30ed\u30bd\u30fc\u30c8\u3092\u5229\u7528\u3057\u3066\u9006\u9806\u306b\u4e26\u3073\u66ff\u3048\u308b\uff0e\n ! 10 9 5 4 4 3 1\n call sort(array, reverse=.true.)\n print *, array\n end block\n\n block\n integer(int32), allocatable :: work(:)\n\n array = [5, 4, 3, 1, 10, 4, 9]\n allocate (work, mold=array)\n\n ! Rust\u306e\u30bd\u30fc\u30c8\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3092\u5229\u7528\u3057\u3066\u4e26\u3073\u66ff\u3048\u308b\uff0e\n ! 1 3 4 4 5 9 10\n call ord_sort(array, work)\n print *, array\n\n ! Rust\u306e\u30bd\u30fc\u30c8\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3092\u5229\u7528\u3057\u3066\u9006\u9806\u306b\u4e26\u3073\u66ff\u3048\u308b\uff0e\n ! 10 9 5 4 4 3 1\n call ord_sort(array, work, reverse=.true.)\n print *, array\n end block\n\n block\n integer(int32), allocatable :: work(:)\n integer(int_size), allocatable :: index(:), iwork(:)\n\n array = [5, 4, 3, 1, 10, 4, 9]\n allocate (index(1:size(array)))\n allocate (work(1:size(array)/2))\n allocate (iwork(1:size(array)/2))\n\n ! ord_sort\u3092\u5229\u7528\u3057\u3066\u4e26\u3073\u66ff\u3048\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u8fd4\u3059\uff0e\n call sort_index(array, index, work, iwork)\n ! 1 3 4 4 5 9 10\n ! 4 3 2 6 1 7 5\n print *, array\n print *, index\n\n ! index\u3092\u7528\u3044\u3066\u4e26\u3073\u66ff\u3048\u308b\uff0e\n array = [5, 4, 3, 1, 10, 4, 9]\n array = array(index)\n ! array(1) = array(index(1)) = array(4) = 1\n ! array(2) = array(index(2)) = array(3) = 3\n ! array(3) = array(index(3)) = array(2) = 4\n ! array(4) = array(index(4)) = array(6) = 4\n ! array(5) = array(index(5)) = array(1) = 5\n ! array(6) = array(index(6)) = array(7) = 9\n ! array(7) = array(index(7)) = array(5) = 10\n ! 1 3 4 4 5 9 10\n print *, array\n end block\n end subroutine ex_stdlib_sorting\nend module ex_stdlib_function\n", "meta": {"hexsha": "42d962073d65321badb4d61edd038a6d0c08af94", "size": 27337, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/ex_stdlib_function.f90", "max_stars_repo_name": "degawa/ex_stdlib", "max_stars_repo_head_hexsha": "ff196e1e3a1ad698b9133bf01e68430aa06698fc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-26T13:59:39.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-26T13:59:39.000Z", "max_issues_repo_path": "src/ex_stdlib_function.f90", "max_issues_repo_name": "degawa/ex_stdlib", "max_issues_repo_head_hexsha": "ff196e1e3a1ad698b9133bf01e68430aa06698fc", "max_issues_repo_licenses": ["MIT"], "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/ex_stdlib_function.f90", "max_forks_repo_name": "degawa/ex_stdlib", "max_forks_repo_head_hexsha": "ff196e1e3a1ad698b9133bf01e68430aa06698fc", "max_forks_repo_licenses": ["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.2422857143, "max_line_length": 179, "alphanum_fraction": 0.4518418261, "num_tokens": 11654, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424411924673, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.6835783512804193}} {"text": "program notas\nimplicit none\n\nreal, dimension(1:36) :: p1, p2, m\nreal :: conta, contr, pa, pr\ninteger :: c\n\nopen(1, FILE = \"NOTAS.csv\")\n\nread(1,*)\n\ndo c = 1,36\n read(1,*) p1(c), p2(c)\nend do\n\nclose(1)\n\ndo c = 1,36\n m(c) = (p1(c)+p2(c))/2d0\nend do\n\nconta = 0\ncontr = 0\n\ndo c = 1,36\n\n if (m(c) .ge. 5.0) then\n\twrite(*,*) p1(c), p2(c), m(c), \"A\"\n\tconta = conta + 1\n\tpa = (conta/36d0)*100\n\n else if (m(c) .lt. 5.0) then\n\twrite(*,*) p1(c), p2(c), m(c), \"R\"\n\tcontr = contr + 1\n\tpr = (contr/36d0)*100\n\n end if\n\nend do\n\nwrite(*,*) \"O n\u00famero de aprovados \u00e9\",conta,\"e a porcentagem \u00e9\",pa\nwrite(*,*) \"O n\u00famero de reprovados \u00e9\",contr,\"e sua porcentagem \u00e9\",pr\n\nopen(3,file = \"notasfinais.txt\")\n\n1 format(3(F5.2, 1X),A1)\n\n do c = 1,36\n\n\tif (m(c) .ge. 5.0) then\n \t write(3,1) p1(c), p2(c), m(c), \"A\"\n\telse if (m(c) .lt. 5.0) then\n\t write(3,1) p1(c), p2(c), m(c), \"R\"\n\n\tend if\n\n end do\n\nclose (3)\n\nend program notas\n", "meta": {"hexsha": "f6c8048fbef96d69098cbf56575f238dda813069", "size": 929, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "aula04/prog1.f90", "max_stars_repo_name": "j-rheinheimer/Fisica-Computacional-I", "max_stars_repo_head_hexsha": "9d3d434cfb787391db5b57829e93d1461cc65f1c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "aula04/prog1.f90", "max_issues_repo_name": "j-rheinheimer/Fisica-Computacional-I", "max_issues_repo_head_hexsha": "9d3d434cfb787391db5b57829e93d1461cc65f1c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "aula04/prog1.f90", "max_forks_repo_name": "j-rheinheimer/Fisica-Computacional-I", "max_forks_repo_head_hexsha": "9d3d434cfb787391db5b57829e93d1461cc65f1c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 14.9838709677, "max_line_length": 68, "alphanum_fraction": 0.5435952637, "num_tokens": 421, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314858927012, "lm_q2_score": 0.7718435083355187, "lm_q1q2_score": 0.683568913163821}} {"text": "module const\n\n implicit none\n\n\t! geo-physical constants\n\n real,parameter :: Radius_of_Earth\t\t= 6.371*1.e6\t! m\n real,parameter :: Acc_dueto_Gravity\t\t= 9.8100\t! m/s/s\n real,parameter :: Earths_angular_velocity\t= 7.292e-5\t! /s\n\n real,parameter :: R_EARTH\t= Radius_of_Earth\n real,parameter :: G_EARTH\t= Acc_dueto_Gravity\n real,parameter :: OMEGA\t= Earths_angular_velocity\n\n\t\t\t\t! = 2*sin(ONEPI/4) = sqrt(2.)*OMEGA\n real,parameter :: Coriolis_45\t\t\t= 1.4142136 * OMEGA\n real,parameter :: Rate_of_Coriolis_45\t\t= Coriolis_45 / R_EARTH\n\n real,parameter :: BETA\t= Rate_of_Coriolis_45\n\n\t\t\t\t! = 4*atan(1.)\n real,parameter :: ONEPI=3.1415927\n\n real,parameter :: T_ref\t= 273.15\t! Kelvin\n real,parameter :: P_ref\t= 1000.\t\t! mbar\n real,parameter :: R_dry\t= 287.00 ! Gas constant of dry air\n\n real,parameter :: RHOBAR = 1.24 ! mean sea-level density, kg/m^3\nend module const\n!.\n", "meta": {"hexsha": "4f7a69c531d26b995b7e76bdb690dfc81f7af8f2", "size": 878, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/Shared/GMAO_Shared/GMAO_psas/const.f90", "max_stars_repo_name": "GEOS-ESM/AeroApps", "max_stars_repo_head_hexsha": "874dad6f34420c014d98eccbe81a061bdc0110cf", "max_stars_repo_licenses": ["NASA-1.3", "ECL-2.0", "Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-12-02T14:23:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-31T15:39:30.000Z", "max_issues_repo_path": "GMAO_psas/const.f90", "max_issues_repo_name": "GEOS-ESM/GMAO_Shared", "max_issues_repo_head_hexsha": "022af23abbc7883891006b57379be96d9a50df23", "max_issues_repo_licenses": ["NASA-1.3", "ECL-2.0", "Apache-2.0"], "max_issues_count": 105, "max_issues_repo_issues_event_min_datetime": "2019-07-08T19:27:23.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-22T02:12:16.000Z", "max_forks_repo_path": "src/Shared/GMAO_Shared/GMAO_psas/const.f90", "max_forks_repo_name": "GEOS-ESM/AeroApps", "max_forks_repo_head_hexsha": "874dad6f34420c014d98eccbe81a061bdc0110cf", "max_forks_repo_licenses": ["NASA-1.3", "ECL-2.0", "Apache-2.0"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2019-07-05T18:00:44.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-11T16:26:29.000Z", "avg_line_length": 28.3225806452, "max_line_length": 66, "alphanum_fraction": 0.6879271071, "num_tokens": 338, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.885631476836816, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6835688968781135}} {"text": "\n! $UWHPSC/codes/f2py/jacobi1\n\n! For use with f2py:\n! $ f2py -m jacobi1 -c jacobi1.f90\n! Then in Python you can import jacobi1 and use it to take a fixed number of\n! iterations using Jacobi in one space dimension to solve\n! u(i-1) - 2*u(i) + u(i+1) = -dx**2 * f(i).\n! Python call:\n! >>> u = jacobi1.iterate(u0, iters, f)\n! where \n! iters is the number of iterations to take,\n! u0(0:n+1) is the initial guess (with desired boundary values \n! in u0(0) and u0(n+1), these are not changed.\n! f(0:n+1) contains values of f(x) at each grid point.\n! \n\nsubroutine iterate(u0,iters,f,u,n)\n implicit none\n integer, intent(in) :: n, iters\n real(kind=8), dimension(0:n+1), intent(in) :: u0, f\n real(kind=8), dimension(0:n+1), intent(out) :: u\n\n ! local variables:\n real(kind=8), dimension(:), allocatable :: uold\n real(kind=8) :: dx\n integer :: i, iter\n\n ! allocate storage for boundary points too:\n allocate(uold(0:n+1))\n\n ! grid spacing:\n dx = 1.d0 / (n+1.d0)\n\n uold = u0\n\n ! initialize boundary values of u:\n u(0) = u0(0)\n u(n+1) = u0(n+1)\n\n ! take the iterations requested:\n do iter=1,iters\n do i=1,n\n u(i) = 0.5d0*(uold(i-1) + uold(i+1) + dx**2*f(i))\n enddo\n uold = u\n enddo\n\nend subroutine iterate\n", "meta": {"hexsha": "c6bfe904750eb22602bab087274a8869fe8eb53d", "size": 1316, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/codes/f2py/jacobi1.f90", "max_stars_repo_name": "philipwangdk/HPC", "max_stars_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "uwhpsc/codes/f2py/jacobi1.f90", "max_issues_repo_name": "philipwangdk/HPC", "max_issues_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "uwhpsc/codes/f2py/jacobi1.f90", "max_forks_repo_name": "philipwangdk/HPC", "max_forks_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.32, "max_line_length": 76, "alphanum_fraction": 0.5881458967, "num_tokens": 457, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554444, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6835688945600314}} {"text": "!\n!\nFUNCTION J_INDEX(L,M) \nIMPLICIT NONE\nINTEGER J_INDEX, L, M \n!\n! given l (degree) and m(order), this function computes \n! the j-index \"J\", with J=l(l+1)/2+m+1 - GS 14-09-2007\n!\n If(l<0.or.m<0.or.m>l) then \n\t Write(88,*) \"J_INDEX: The degree and order are out of bounds\" \n \t Write(88,*) \"The program will STOP -------------------------\"\n \t Write(*, *) \"J_INDEX: The degree and order are out of bounds\" \n \t Write(*, *) \"The program will STOP -------------------------\"\t \n call stop_config \n\t Stop\n endif\n!\n J_INDEX = l*(l+1)/2+m+1\n!\nEND FUNCTION J_INDEX \n!\n!\n!\n", "meta": {"hexsha": "8601779191da57485a768c13be6ae29b95341d62", "size": 580, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/j_index.f90", "max_stars_repo_name": "gassmoeller/selen", "max_stars_repo_head_hexsha": "796ed0c3b994e0a8d447934f3ec2863a2d2804ab", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2016-01-15T16:22:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-11T03:05:48.000Z", "max_issues_repo_path": "src/j_index.f90", "max_issues_repo_name": "gassmoeller/selen", "max_issues_repo_head_hexsha": "796ed0c3b994e0a8d447934f3ec2863a2d2804ab", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2015-10-14T21:07:01.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T20:08:24.000Z", "max_forks_repo_path": "src/j_index.f90", "max_forks_repo_name": "gassmoeller/selen", "max_forks_repo_head_hexsha": "796ed0c3b994e0a8d447934f3ec2863a2d2804ab", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2015-08-26T10:55:15.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-01T16:31:11.000Z", "avg_line_length": 23.2, "max_line_length": 69, "alphanum_fraction": 0.5586206897, "num_tokens": 182, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8856314798554444, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6835688945600314}} {"text": "C * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC * *\nC * copyright (c) 1999 by UCAR *\nC * *\nC * UNIVERSITY CORPORATION for ATMOSPHERIC RESEARCH *\nC * *\nC * all rights reserved *\nC * *\nC * FISHPACK version 4.1 *\nC * *\nC * A PACKAGE OF FORTRAN SUBPROGRAMS FOR THE SOLUTION OF *\nC * *\nC * SEPARABLE ELLIPTIC PARTIAL DIFFERENTIAL EQUATIONS *\nC * *\nC * BY *\nC * *\nC * JOHN ADAMS, PAUL SWARZTRAUBER AND ROLAND SWEET *\nC * *\nC * OF *\nC * *\nC * THE NATIONAL CENTER FOR ATMOSPHERIC RESEARCH *\nC * *\nC * BOULDER, COLORADO (80307) U.S.A. *\nC * *\nC * WHICH IS SPONSORED BY *\nC * *\nC * THE NATIONAL SCIENCE FOUNDATION *\nC * *\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC\nC\nC PROGRAM TO ILLUSTRATE THE USE OF SUBROUTINE HWSCRT TO SOLVE\nC THE EQUATION\nC\nC (D/DX)(DU/DX) + (D/DY)(DU/DY) - 4*U\nC\nC = (2 - (4 + PI**2/4)*X**2)*COS((Y+1)*PI/2)\nC\nC WITH THE BOUNDARY CONDITIONS\nC ON THE RECTANGLE 0 .LT. X .LT. 2, -1 .LT. Y .LT. 3 WITH THE\nC\nC U(0,Y) = 0\nC -1 .LE. Y .LE. 3\nC (DU/DX)(2,Y) = 4*COS((Y+1)*PI/2)\nC\nC AND WITH U PERIODIC IN Y.\nC THE X-INTERVAL WILL BE DIVIDED INTO 40 PANELS AND THE\nC Y-INTERVAL WILL BE DIVIDED INTO 80 PANELS.\nC\n DIMENSION F(45,82) ,BDB(81) ,W(1103) ,X(41) ,\n 1 Y(81)\nC\nC FROM DIMENSION STATEMENT WE GET VALUE OF IDIMF. ALSO NOTE THAT W\nC IS DIMENSIONED 4*(N+1) + (13 + INT(LOG2(N+1)))*(M+1) .\nC\n IDIMF = 45\n A = 0.\n B = 2.\n M = 40\n MBDCND = 2\n C = -1.\n D = 3.\n N = 80\n NBDCND = 0\n ELMBDA = -4.\nC\nC AUXILIARY QUANTITIES.\nC\n PI = PIMACH(DUM)\n PIBY2 = PI/2.\n PISQ = PI**2\n MP1 = M+1\n NP1 = N+1\nC\nC GENERATE AND STORE GRID POINTS FOR THE PURPOSE OF COMPUTING\nC BOUNDARY DATA AND THE RIGHT SIDE OF THE HELMHOLTZ EQUATION.\nC\n DO 101 I=1,MP1\n X(I) = FLOAT(I-1)/20.\n 101 CONTINUE\n DO 102 J=1,NP1\n Y(J) = -1.+FLOAT(J-1)/20.\n 102 CONTINUE\nC\nC GENERATE BOUNDARY DATA.\nC\n DO 103 J=1,NP1\n BDB(J) = 4.*COS((Y(J)+1.)*PIBY2)\n 103 CONTINUE\nC\nC BDA, BDC, AND BDD ARE DUMMY VARIABLES.\nC\n DO 104 J=1,NP1\n F(1,J) = 0.\n 104 CONTINUE\nC\nC GENERATE RIGHT SIDE OF EQUATION.\nC\n DO 106 I=2,MP1\n DO 105 J=1,NP1\n F(I,J) = (2.-(4.+PISQ/4.)*X(I)**2)*COS((Y(J)+1.)*PIBY2)\n 105 CONTINUE\n 106 CONTINUE\n CALL HWSCRT (A,B,M,MBDCND,BDA,BDB,C,D,N,NBDCND,BDC,BDD,ELMBDA,F,\n 1 IDIMF,PERTRB,IERROR,W)\nC\nC COMPUTE DISCRETIZATION ERROR. THE EXACT SOLUTION IS\nC U(X,Y) = X**2*COS((Y+1)*PIBY2)\nC\n ERR = 0.\n DO 108 I=1,MP1\n DO 107 J=1,NP1\n Z = ABS(F(I,J)-X(I)**2*COS((Y(J)+1.)*PIBY2))\n IF (Z .GT. ERR) ERR = Z\n 107 CONTINUE\n 108 CONTINUE\n PRINT 1001 , IERROR,ERR,W(1)\n STOP\nC\n 1001 FORMAT (1H1,20X,25HSUBROUTINE HWSCRT EXAMPLE///\n 1 10X,46HTHE OUTPUT FROM THE NCAR CONTROL DATA 7600 WAS//\n 2 32X,10HIERROR = 0/\n 3 18X,34HDISCRETIZATION ERROR = 5.36508E-04/\n 4 12X,32HREQUIRED LENGTH OF W ARRAY = 880//\n 5 10X,32HTHE OUTPUT FROM YOUR COMPUTER IS//\n 6 32X,8HIERROR =,I2/18X,22HDISCRETIZATION ERROR =,E12.5/\n 7 12X,28HREQUIRED LENGTH OF W ARRAY =,F4.0)\nC\n END\n", "meta": {"hexsha": "bf4d6c5d21a339983455df0d255495854d2205fc", "size": 4761, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/test/thwscrt.f", "max_stars_repo_name": "ipelupessy/omuse", "max_stars_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2020-03-25T10:02:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-18T00:28:35.000Z", "max_issues_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/test/thwscrt.f", "max_issues_repo_name": "ipelupessy/omuse", "max_issues_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 45, "max_issues_repo_issues_event_min_datetime": "2020-03-03T16:07:16.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-14T09:01:07.000Z", "max_forks_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/test/thwscrt.f", "max_forks_repo_name": "ipelupessy/omuse", "max_forks_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-03-03T13:28:50.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-26T09:20:02.000Z", "avg_line_length": 36.6230769231, "max_line_length": 71, "alphanum_fraction": 0.3721907162, "num_tokens": 1449, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314647623016, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6835688875584781}} {"text": "!***************************************************************************************************\n!> Subroutine factorial\n!Factorial function returns n!\n!This is limited to numbers n<17 for computer feasibility.\n!***************************************************************************************************\ninteger function factorial(n)\n\timplicit none\n\n\tinteger, intent(in) :: n\n\tinteger :: i, temp\n\n\tif(n >= 17) then\n\t\twrite(*,*) 'error factorial too large'\n\tendif\n\n\ttemp=1\n\tdo i=1,n\n\t\ttemp=temp*i\n\tend do\n\tfactorial=temp\nend function\n\n!***************************************************************************************************\n!> Subroutine binomial\n!Binomial function returns n choose k\n!***************************************************************************************************\ninteger function binomial(n,k)\n\timplicit none\n\n\tinteger, intent(in) :: n, k\n\tinteger, external :: factorial\n\n\tbinomial=factorial(n)/(factorial(k)*factorial(n-k))\n\nend function\n\n!***************************************************************************************************\n!> function TotalRateCheck() - checks if our total rate still matches the actual total rate\n!This function is used as a diagnostic tool, it calcuates the total rate of all reactions in the\n!system and compares it to totalRate, in order to test whether totalRate is being properly updated.\n!***************************************************************************************************\ndouble precision function TotalRateCheck()\n\tuse mod_constants\n\tuse mod_globalVariables\n\tuse mod_structures\n\timplicit none\n\n\tinteger :: i\n\tdouble precision :: rate, rateCell, rateCascade\n\ttype(reaction), pointer :: reactionCurrent\n\ttype(cascade), pointer :: cascadeCurrent\n\n\tCascadeCurrent=>ActiveCascades\n\trate=0d0\n\n\t!Compute total rate of all reactions in the coarse mesh\n\tdo i=1,numCells\n\t\trateCell=0d0\n\t\treactionCurrent=>reactionList(i)\n\n\t\tdo while(associated(reactionCurrent))\n\t\t\trate=rate+reactionCurrent%reactionRate\n\t\t\trateCell=rateCell+reactionCurrent%reactionRate\n\t\t\treactionCurrent=>reactionCurrent%next\n\t\tend do\n\n\t\tif(dabs(totalRateVol(i)-rateCell) > 1d0) then\n\t\t\twrite(*,*) 'Error: total rate differs significantly from expected in cell', i\n\t\t\twrite(*,*) 'TotalRateVol', totalRateVol(i), 'expected value', rateCell\n\t\t\tcall MPI_ABORT(comm,ierr)\n\t\tend if\n\t\ttotalRateVol(i)=rateCell\t\t\t!Also updating the total rate within each volume element\n\tend do\n\n\t!Compute total rate of all reactions in the fine meshes by going through active cascades\n\tdo while(associated(CascadeCurrent))\n\n\t\tdo i=1,numCellsCascade\n\t\t\trateCascade=0d0\n\t\t\treactionCurrent=>CascadeCurrent%reactionList(i)\n\t\t\tdo while(associated(reactionCurrent))\n\t\t\t\trate=rate+reactionCurrent%reactionRate\n\t\t\t\trateCascade=rateCascade+reactionCurrent%reactionRate\n\t\t\t\treactionCurrent=>reactionCurrent%next\n\t\t\tend do\n\n\t\t\tif(dabs(CascadeCurrent%totalRate(i)-rateCascade) > 1d0) then\n\t\t\t\twrite(*,*) 'Error: total rate differs significantly from expected in cascade', &\n\t\t\t\t\t\tCascadeCurrent%cascadeID\n\t\t\t\twrite(*,*) 'TotalRateCascade', CascadeCurrent%totalRate(i), 'Expected Value', rateCascade\n\t\t\tend if\n\t\t\tCascadeCurrent%totalRate(i)=rateCascade\n\t\tend do\n\t\tCascadeCurrent=>CascadeCurrent%next\n\tend do\n\n\t!Compare rate to totalRate and return error if different\n\t!if(myProc%taskid==MASTER) then\n\t!\tif (rate==totalRate) then\n\t!\t\twrite(*,*) 'TotalRate correct', totalRate\n\t!\telse\n\t!\t\twrite(*,*) 'TotalRate incorrect ', 'totalRate=', totalRate, 'actual total rate=', rate\n\t!\tend if\n\t!end if\n\n\tTotalRateCheck=rate\nend function\n\n!***************************************************************************************************\n!> Function total rate cascade - finds total reaction rate within cascade\n!***************************************************************************************************\ndouble precision function totalRateCascade(CascadeCurrent)\n\tuse mod_structures\n\tuse mod_globalVariables\n\timplicit none\n\n\ttype(cascade), pointer, intent(in) :: CascadeCurrent\n\tinteger :: i\n\tdouble precision :: rateSum\n\n\trateSum=0d0\n\tdo i=1,numCellsCascade\n\t\trateSum=rateSum+CascadeCurrent%totalRate(i)\n\tend do\n\ttotalRateCascade=rateSum\n\nend function\n\n\n", "meta": {"hexsha": "ebae46ed56372b09f93d3279ac340c24e47963ab", "size": 4185, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/src_mathFunctions.f90", "max_stars_repo_name": "MISA-SCD/misa-scd-v1.0", "max_stars_repo_head_hexsha": "ac71a050a20d7890f999585f07dca8e4d3bf360d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-12-17T02:18:58.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-25T12:39:19.000Z", "max_issues_repo_path": "src/src_mathFunctions.f90", "max_issues_repo_name": "MISA-SCD/misa-scd-v1.0", "max_issues_repo_head_hexsha": "ac71a050a20d7890f999585f07dca8e4d3bf360d", "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/src_mathFunctions.f90", "max_forks_repo_name": "MISA-SCD/misa-scd-v1.0", "max_forks_repo_head_hexsha": "ac71a050a20d7890f999585f07dca8e4d3bf360d", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-06T03:40:28.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-06T03:40:28.000Z", "avg_line_length": 32.1923076923, "max_line_length": 100, "alphanum_fraction": 0.6136200717, "num_tokens": 937, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181875, "lm_q2_score": 0.7718434873426302, "lm_q1q2_score": 0.6835688852522231}} {"text": "!! ==================================================================\nsubroutine clawpack46_setaux(mbc,mx,my,mz,xlower,ylower,zlower, & \n dx,dy,dz,maux,aux)\n!! ==================================================================\n\n !!\n !! # set auxiliary arrays\n !!\n !! # advection\n !! # aux(i,j,k,1) is u velocity on left face of cell\n !! # aux(i,j,k,2) is v velocity on bottom face of cell\n !! # aux(i,j,k,3) is w velocity on back face of cell\n !!\n\n implicit none\n\n integer :: mx, my, mz, mbc, maux\n double precision :: xlower, ylower, zlower, dx, dy, dz\n double precision :: aux(1-mbc:mx+mbc,1-mbc:my+mbc,1-mbc:mz+mbc,maux)\n\n double precision :: xc(1-mbc:mx+mbc)\n double precision :: yc(1-mbc:my+mbc)\n double precision :: zc(1-mbc:mz+mbc)\n\n integer :: i,j,k\n double precision :: dx2, dy2, dz2, compute_u, compute_v, compute_w\n\n do i = 1-mbc,mx+mbc\n xc(i) = xlower + (i-0.5d0)*dx\n enddo\n\n do j = 1-mbc,my+mbc\n yc(j) = ylower + (j-0.5d0)*dy\n end do\n\n do k = 1-mbc,mz+mbc\n zc(k) = zlower + (k-0.5d0)*dz\n end do\n\n dx2 = 0.5d0*dx\n dy2 = 0.5d0*dy\n dz2 = 0.5d0*dz\n\n do k = 1-mbc,mz+mbc\n do j = 1-mbc,my+mbc\n do i = 1-mbc,mx+mbc\n aux(i,j,k,1) = compute_u(xc(i)-dx2, yc(j),zc(k))\n aux(i,j,k,2) = compute_v(xc(i),yc(j)-dy2, zc(k))\n aux(i,j,k,3) = compute_w(xc(i),yc(j), zc(k)-dz2)\n enddo\n enddo\n enddo\n\n return\nend subroutine clawpack46_setaux\n\ndouble precision function compute_u(x,y,z)\n implicit none\n double precision :: x,y,z,pi, pi2\n\n common /compi/ pi, pi2\n\n compute_u = 2.d0 * dsin(pi*x)**2 * dsin(pi2*y) * dsin(pi2*z)\nend function compute_u\n\ndouble precision function compute_v(x,y,z)\n implicit none\n double precision :: x,y,z,pi, pi2\n\n common /compi/ pi, pi2\n\n compute_v = -dsin(pi2*x) * dsin(pi*y)**2 * dsin(pi2*z)\nend function compute_v\n\ndouble precision function compute_w(x,y,z)\n implicit none\n double precision :: x,y,z,pi, pi2\n\n common /compi/ pi, pi2\n\n compute_w = -dsin(pi2*x) * dsin(pi2*y) * dsin(pi*z)**2\nend function compute_w\n", "meta": {"hexsha": "5cefdc7fc83590370e77585fc6073b8177dded12", "size": 2208, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "applications/clawpack/advection/3d/swirl/user_4.6/setaux.f90", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "applications/clawpack/advection/3d/swirl/user_4.6/setaux.f90", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-08-02T09:52:43.000Z", "max_issues_repo_issues_event_max_datetime": "2017-08-02T14:16:23.000Z", "max_forks_repo_path": "applications/clawpack/advection/3d/swirl/user_4.6/setaux.f90", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "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.6024096386, "max_line_length": 73, "alphanum_fraction": 0.5317028986, "num_tokens": 780, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181875, "lm_q2_score": 0.7718434873426302, "lm_q1q2_score": 0.6835688852522231}} {"text": "!*****************************************************************************************\r\n!> author: Jacob Williams\r\n! license: BSD\r\n!\r\n!### Description\r\n!\r\n! Multidimensional (1D-6D) B-spline interpolation of data on a regular grid.\r\n! Basic pure subroutine interface.\r\n!\r\n!### Notes\r\n!\r\n! This module is based on the B-spline and spline routines from [1].\r\n! The original Fortran 77 routines were converted to free-form source.\r\n! Some of them are relatively unchanged from the originals, but some have\r\n! been extensively refactored. In addition, new routines for\r\n! 1d, 4d, 5d, and 6d interpolation were also created (these are simply\r\n! extensions of the same algorithm into higher dimensions).\r\n!\r\n!### See also\r\n! * An object-oriented interface can be found in [[bspline_oo_module]].\r\n!\r\n!### References\r\n!\r\n! 1. DBSPLIN and DTENSBS from the\r\n! [NIST Core Math Library](http://www.nist.gov/itl/math/mcsd-software.cfm).\r\n! Original code is public domain.\r\n! 2. Carl de Boor, \"A Practical Guide to Splines\",\r\n! Springer-Verlag, New York, 1978.\r\n! 3. Carl de Boor, [Efficient Computer Manipulation of Tensor\r\n! Products](http://dl.acm.org/citation.cfm?id=355831),\r\n! ACM Transactions on Mathematical Software,\r\n! Vol. 5 (1979), p. 173-182.\r\n! 4. D.E. Amos, \"Computation with Splines and B-Splines\",\r\n! SAND78-1968, Sandia Laboratories, March, 1979.\r\n! 5. Carl de Boor,\r\n! [Package for calculating with B-splines](http://epubs.siam.org/doi/abs/10.1137/0714026),\r\n! SIAM Journal on Numerical Analysis 14, 3 (June 1977), p. 441-472.\r\n! 6. D.E. Amos, \"Quadrature subroutines for splines and B-splines\",\r\n! Report SAND79-1825, Sandia Laboratories, December 1979.\r\n\r\n module bspline_sub_module\r\n\r\n use,intrinsic :: iso_fortran_env\r\n\r\n implicit none\r\n \r\n integer,parameter,public :: wp = real64\r\n\r\n private\r\n\r\n abstract interface\r\n function b1fqad_func(x) result(f)\r\n !! interface for the input function in [[dbfqad]]\r\n import :: wp\r\n implicit none\r\n real(wp),intent(in) :: x\r\n real(wp) :: f !! f(x)\r\n end function b1fqad_func\r\n end interface\r\n public :: b1fqad_func\r\n\r\n !Spline function order (order = polynomial degree + 1)\r\n integer,parameter,public :: bspline_order_quadratic = 3\r\n integer,parameter,public :: bspline_order_cubic = 4\r\n integer,parameter,public :: bspline_order_quartic = 5\r\n integer,parameter,public :: bspline_order_quintic = 6\r\n\r\n !main routines:\r\n public :: db1ink, db1val, db1sqad, db1fqad\r\n public :: db2ink, db2val\r\n public :: db3ink, db3val\r\n public :: db4ink, db4val\r\n public :: db5ink, db5val\r\n public :: db6ink, db6val\r\n\r\n public :: get_status_message\r\n\r\n contains\r\n!*****************************************************************************************\r\n\r\n!*****************************************************************************************\r\n!>\r\n! Determines the parameters of a function that interpolates\r\n! the one-dimensional gridded data\r\n! $$ [x(i),\\mathrm{fcn}(i)] ~\\mathrm{for}~ i=1,..,n_x $$\r\n! The interpolating function and its derivatives may\r\n! subsequently be evaluated by the function [[db1val]].\r\n!\r\n!### History\r\n! * Jacob Williams, 10/30/2015 : Created 1D routine.\r\n\r\n pure subroutine db1ink(x,nx,fcn,kx,iknot,tx,bcoef,iflag)\r\n\r\n implicit none\r\n\r\n integer,intent(in) :: nx !! Number of \\(x\\) abcissae\r\n integer,intent(in) :: kx !! The order of spline pieces in \\(x\\)\r\n !! ( \\( 2 \\le k_x < n_x \\) )\r\n !! (order = polynomial degree + 1)\r\n real(wp),dimension(:),intent(in) :: x !! `(nx)` array of \\(x\\) abcissae. Must be strictly increasing.\r\n real(wp),dimension(:),intent(in) :: fcn !! `(nx)` array of function values to interpolate. `fcn(i)` should\r\n !! contain the function value at the point `x(i)`\r\n integer,intent(in) :: iknot !! knot sequence flag:\r\n !!\r\n !! * 0 = knot sequence chosen by [[db1ink]].\r\n !! * 1 = knot sequence chosen by user.\r\n real(wp),dimension(:),intent(inout) :: tx !! The `(nx+kx)` knots in the \\(x\\) direction\r\n !! for the spline interpolant:\r\n !!\r\n !! * If `iknot=0` these are chosen by [[db1ink]].\r\n !! * If `iknot=1` these are specified by the user.\r\n !!\r\n !! Must be non-decreasing.\r\n real(wp),dimension(:),intent(out) :: bcoef !! `(nx)` array of coefficients of the b-spline interpolant.\r\n integer,intent(out) :: iflag !! status flag:\r\n !!\r\n !! * 0 = successful execution.\r\n !! * 2 = `iknot` out of range.\r\n !! * 3 = `nx` out of range.\r\n !! * 4 = `kx` out of range.\r\n !! * 5 = `x` not strictly increasing.\r\n !! * 6 = `tx` not non-decreasing.\r\n !! * 700 = `size(x)` \\( \\ne \\) `size(fcn,1)`.\r\n !! * 706 = `size(x)` \\( \\ne \\) `nx`.\r\n !! * 712 = `size(tx)` \\( \\ne \\) `nx+kx`.\r\n !! * 800 = `size(x)` \\( \\ne \\) `size(bcoef,1)`.\r\n\r\n real(wp),dimension(2*kx*(nx+1)) :: work\r\n logical :: status_ok\r\n\r\n !check validity of inputs\r\n\r\n call check_inputs( iknot,&\r\n iflag,&\r\n nx=nx,&\r\n kx=kx,&\r\n x=x,&\r\n f1=fcn,&\r\n bcoef1=bcoef,&\r\n tx=tx,&\r\n status_ok=status_ok)\r\n\r\n if (status_ok) then\r\n\r\n !choose knots\r\n\r\n if (iknot == 0) then\r\n call dbknot(x,nx,kx,tx)\r\n end if\r\n\r\n !construct b-spline coefficients\r\n\r\n call dbtpcf(x,nx,fcn,nx,1,tx,kx,bcoef,work,iflag)\r\n\r\n end if\r\n\r\n end subroutine db1ink\r\n!*****************************************************************************************\r\n\r\n!*****************************************************************************************\r\n!>\r\n! Evaluates the tensor product piecewise polynomial\r\n! interpolant constructed by the routine [[db1ink]] or one of its\r\n! derivatives at the point `xval`.\r\n!\r\n! To evaluate the interpolant itself, set `idx=0`,\r\n! to evaluate the first partial with respect to `x`, set `idx=1`, and so on.\r\n!\r\n! [[db1val]] returns 0.0 if (`xval`,`yval`) is out of range. that is, if\r\n!```fortran\r\n! xval < tx(1) .or. xval > tx(nx+kx)\r\n!```\r\n! if the knots `tx` were chosen by [[db1ink]], then this is equivalent to:\r\n!```fortran\r\n! xval < x(1) .or. xval > x(nx)+epsx\r\n!```\r\n! where\r\n!```fortran\r\n! epsx = 0.1*(x(nx)-x(nx-1))\r\n!```\r\n!\r\n! The input quantities `tx`, `nx`, `kx`, and `bcoef` should be\r\n! unchanged since the last call of [[db1ink]].\r\n!\r\n!### History\r\n! * Jacob Williams, 10/30/2015 : Created 1D routine.\r\n\r\n pure subroutine db1val(xval,idx,tx,nx,kx,bcoef,f,iflag,inbvx,extrap)\r\n\r\n implicit none\r\n\r\n integer,intent(in) :: idx !! \\(x\\) derivative of piecewise polynomial to evaluate.\r\n integer,intent(in) :: nx !! the number of interpolation points in \\(x\\).\r\n !! (same as in last call to [[db1ink]])\r\n integer,intent(in) :: kx !! order of polynomial pieces in \\(x\\).\r\n !! (same as in last call to [[db1ink]])\r\n real(wp),intent(in) :: xval !! \\(x\\) coordinate of evaluation point.\r\n real(wp),dimension(nx+kx),intent(in) :: tx !! sequence of knots defining the piecewise polynomial\r\n !! in the \\(x\\) direction. (same as in last call to [[db1ink]])\r\n real(wp),dimension(nx),intent(in) :: bcoef !! the b-spline coefficients computed by [[db1ink]].\r\n real(wp),intent(out) :: f !! interpolated value\r\n integer,intent(out) :: iflag !! status flag:\r\n !!\r\n !! * \\( = 0 \\) : no errors\r\n !! * \\( \\ne 0 \\) : error\r\n integer,intent(inout) :: inbvx !! initialization parameter which must be set\r\n !! to 1 the first time this routine is called,\r\n !! and must not be changed by the user.\r\n logical,intent(in),optional :: extrap !! if extrapolation is allowed\r\n !! (if not present, default is False)\r\n\r\n real(wp),dimension(3*kx) :: work\r\n\r\n f = 0.0_wp\r\n\r\n iflag = check_value(xval,tx,1,extrap); if (iflag/=0) return\r\n\r\n call dbvalu(tx,bcoef,nx,kx,idx,xval,inbvx,work,iflag,f,extrap)\r\n\r\n end subroutine db1val\r\n!*****************************************************************************************\r\n\r\n!*****************************************************************************************\r\n!>\r\n! Computes the integral on `(x1,x2)` of a `kx`-th order b-spline.\r\n! Orders `kx` as high as 20 are permitted by applying a 2, 6, or 10\r\n! point gauss formula on subintervals of `(x1,x2)` which are\r\n! formed by included (distinct) knots.\r\n!\r\n!### See also\r\n! * [[dbsqad]] -- the core routine.\r\n\r\n pure subroutine db1sqad(tx,bcoef,nx,kx,x1,x2,f,iflag)\r\n\r\n implicit none\r\n\r\n integer,intent(in) :: nx !! length of coefficient array\r\n integer,intent(in) :: kx !! order of b-spline, `1 <= k <= 20`\r\n real(wp),dimension(nx+kx),intent(in) :: tx !! knot array\r\n real(wp),dimension(nx),intent(in) :: bcoef !! b-spline coefficient array\r\n real(wp),intent(in) :: x1 !! left point of quadrature interval in `t(kx) <= x <= t(nx+1)`\r\n real(wp),intent(in) :: x2 !! right point of quadrature interval in `t(kx) <= x <= t(nx+1)`\r\n real(wp),intent(out) :: f !! integral of the b-spline over (`x1`,`x2`)\r\n integer,intent(out) :: iflag !! status flag:\r\n !!\r\n !! * \\( = 0 \\) : no errors\r\n !! * \\( \\ne 0 \\) : error\r\n\r\n real(wp),dimension(3*kx) :: work !! work array for [[dbsqad]]\r\n\r\n call dbsqad(tx,bcoef,nx,kx,x1,x2,f,work,iflag)\r\n\r\n end subroutine db1sqad\r\n!*****************************************************************************************\r\n\r\n!*****************************************************************************************\r\n!>\r\n! Computes the integral on `(x1,x2)` of a product of a\r\n! function `fun` and the `idx`-th derivative of a `kx`-th order b-spline,\r\n! using the b-representation `(tx,bcoef,nx,kx)`, with an adaptive\r\n! 8-point Legendre-Gauss algorithm.\r\n! `(x1,x2)` must be a subinterval of `t(kx) <= x <= t(nx+1)`.\r\n!\r\n!### See also\r\n! * [[dbfqad]] -- the core routine.\r\n!\r\n!@note This one is not pure, because we are not enforcing\r\n! that the user function `fun` be pure.\r\n\r\n subroutine db1fqad(fun,tx,bcoef,nx,kx,idx,x1,x2,tol,f,iflag)\r\n\r\n implicit none\r\n\r\n procedure(b1fqad_func) :: fun !! external function of one argument for the\r\n !! integrand `bf(x)=fun(x)*dbvalu(tx,bcoef,nx,kx,id,x,inbv,work)`\r\n integer,intent(in) :: nx !! length of coefficient array\r\n integer,intent(in) :: kx !! order of b-spline, `kx >= 1`\r\n real(wp),dimension(nx+kx),intent(in):: tx !! knot array\r\n real(wp),dimension(nx),intent(in) :: bcoef !! b-spline coefficient array\r\n integer,intent(in) :: idx !! order of the spline derivative, `0 <= idx <= k-1`\r\n !! `idx=0` gives the spline function\r\n real(wp),intent(in) :: x1 !! left point of quadrature interval in `t(k) <= x <= t(n+1)`\r\n real(wp),intent(in) :: x2 !! right point of quadrature interval in `t(k) <= x <= t(n+1)`\r\n real(wp),intent(in) :: tol !! desired accuracy for the quadrature, suggest\r\n !! `10*dtol < tol <= 0.1` where `dtol` is the maximum\r\n !! of `1.0e-300` and real(wp) unit roundoff for\r\n !! the machine\r\n real(wp),intent(out) :: f !! integral of `bf(x)` on `(x1,x2)`\r\n integer,intent(out) :: iflag !! status flag:\r\n !!\r\n !! * \\( = 0 \\) : no errors\r\n !! * \\( \\ne 0 \\) : error\r\n\r\n real(wp),dimension(3*kx) :: work !! work array for [[dbfqad]]\r\n\r\n call dbfqad(fun,tx,bcoef,nx,kx,idx,x1,x2,tol,f,iflag,work)\r\n\r\n end subroutine db1fqad\r\n!*****************************************************************************************\r\n\r\n!*****************************************************************************************\r\n!>\r\n! Determines the parameters of a function that interpolates\r\n! the two-dimensional gridded data\r\n! $$ [x(i),y(j),\\mathrm{fcn}(i,j)] ~\\mathrm{for}~ i=1,..,n_x ~\\mathrm{and}~ j=1,..,n_y $$\r\n! The interpolating function and its derivatives may\r\n! subsequently be evaluated by the function [[db2val]].\r\n!\r\n! The interpolating function is a piecewise polynomial function\r\n! represented as a tensor product of one-dimensional b-splines. the\r\n! form of this function is\r\n!\r\n! $$ s(x,y) = \\sum_{i=1}^{n_x} \\sum_{j=1}^{n_y} a_{ij} u_i(x) v_j(y) $$\r\n!\r\n! where the functions \\(u_i\\) and \\(v_j\\) are one-dimensional b-spline\r\n! basis functions. the coefficients \\( a_{ij} \\) are chosen so that\r\n!\r\n! $$ s(x(i),y(j)) = \\mathrm{fcn}(i,j) ~\\mathrm{for}~ i=1,..,n_x ~\\mathrm{and}~ j=1,..,n_y $$\r\n!\r\n! Note that for each fixed value of \\(y\\), \\( s(x,y) \\) is a piecewise\r\n! polynomial function of \\(x\\) alone, and for each fixed value of \\(x\\), \\( s(x,y) \\)\r\n! is a piecewise polynomial function of \\(y\\) alone. in one dimension\r\n! a piecewise polynomial may be created by partitioning a given\r\n! interval into subintervals and defining a distinct polynomial piece\r\n! on each one. the points where adjacent subintervals meet are called\r\n! knots. each of the functions \\(u_i\\) and \\(v_j\\) above is a piecewise\r\n! polynomial.\r\n!\r\n! Users of [[db2ink]] choose the order (degree+1) of the polynomial\r\n! pieces used to define the piecewise polynomial in each of the \\(x\\) and\r\n! \\(y\\) directions (`kx` and `ky`). users also may define their own knot\r\n! sequence in \\(x\\) and \\(y\\) separately (`tx` and `ty`). if `iflag=0`, however,\r\n! [[db2ink]] will choose sequences of knots that result in a piecewise\r\n! polynomial interpolant with `kx-2` continuous partial derivatives in\r\n! \\(x\\) and `ky-2` continuous partial derivatives in \\(y\\). (`kx` knots are taken\r\n! near each endpoint in the \\(x\\) direction, not-a-knot end conditions\r\n! are used, and the remaining knots are placed at data points if `kx`\r\n! is even or at midpoints between data points if `kx` is odd. the \\(y\\)\r\n! direction is treated similarly.)\r\n!\r\n! After a call to [[db2ink]], all information necessary to define the\r\n! interpolating function are contained in the parameters `nx`, `ny`, `kx`,\r\n! `ky`, `tx`, `ty`, and `bcoef`. These quantities should not be altered until\r\n! after the last call of the evaluation routine [[db2val]].\r\n!\r\n!### History\r\n! * Boisvert, Ronald, NBS : 25 may 1982 : Author of original routine.\r\n! * JEC : 000330 modified array declarations.\r\n! * Jacob Williams, 2/24/2015 : extensive refactoring of CMLIB routine.\r\n\r\n pure subroutine db2ink(x,nx,y,ny,fcn,kx,ky,iknot,tx,ty,bcoef,iflag)\r\n\r\n implicit none\r\n\r\n integer,intent(in) :: nx !! Number of \\(x\\) abcissae\r\n integer,intent(in) :: ny !! Number of \\(y\\) abcissae\r\n integer,intent(in) :: kx !! The order of spline pieces in \\(x\\)\r\n !! ( \\( 2 \\le k_x < n_x \\) )\r\n !! (order = polynomial degree + 1)\r\n integer,intent(in) :: ky !! The order of spline pieces in \\(y\\)\r\n !! ( \\( 2 \\le k_y < n_y \\) )\r\n !! (order = polynomial degree + 1)\r\n real(wp),dimension(:),intent(in) :: x !! `(nx)` array of \\(x\\) abcissae. Must be strictly increasing.\r\n real(wp),dimension(:),intent(in) :: y !! `(ny)` array of \\(y\\) abcissae. Must be strictly increasing.\r\n real(wp),dimension(:,:),intent(in) :: fcn !! `(nx,ny)` matrix of function values to interpolate.\r\n !! `fcn(i,j)` should contain the function value at the\r\n !! point (`x(i)`,`y(j)`)\r\n integer,intent(in) :: iknot !! knot sequence flag:\r\n !!\r\n !! * 0 = knot sequence chosen by [[db1ink]].\r\n !! * 1 = knot sequence chosen by user.\r\n real(wp),dimension(:),intent(inout) :: tx !! The `(nx+kx)` knots in the \\(x\\) direction for the spline\r\n !! interpolant.\r\n !!\r\n !! * If `iknot=0` these are chosen by [[db2ink]].\r\n !! * If `iknot=1` these are specified by the user.\r\n !!\r\n !! Must be non-decreasing.\r\n real(wp),dimension(:),intent(inout) :: ty !! The `(ny+ky)` knots in the \\(y\\) direction for the spline\r\n !! interpolant.\r\n !!\r\n !! * If `iknot=0` these are chosen by [[db2ink]].\r\n !! * If `iknot=1` these are specified by the user.\r\n !!\r\n !! Must be non-decreasing.\r\n real(wp),dimension(:,:),intent(out) :: bcoef !! `(nx,ny)` matrix of coefficients of the b-spline interpolant.\r\n integer,intent(out) :: iflag !! * 0 = successful execution.\r\n !! * 2 = `iknot` out of range.\r\n !! * 3 = `nx` out of range.\r\n !! * 4 = `kx` out of range.\r\n !! * 5 = `x` not strictly increasing.\r\n !! * 6 = `tx` not non-decreasing.\r\n !! * 7 = `ny` out of range.\r\n !! * 8 = `ky` out of range.\r\n !! * 9 = `y` not strictly increasing.\r\n !! * 10 = `ty` not non-decreasing.\r\n !! * 700 = `size(x)` \\( \\ne \\) `size(fcn,1)`\r\n !! * 701 = `size(y)` \\( \\ne \\) `size(fcn,2)`\r\n !! * 706 = `size(x)` \\( \\ne \\) `nx`\r\n !! * 707 = `size(y)` \\( \\ne \\) `ny`\r\n !! * 712 = `size(tx)` \\( \\ne \\) `nx+kx`\r\n !! * 713 = `size(ty)` \\( \\ne \\) `ny+ky`\r\n !! * 800 = `size(x)` \\( \\ne \\) `size(bcoef,1)`\r\n !! * 801 = `size(y)` \\( \\ne \\) `size(bcoef,2)`\r\n\r\n real(wp),dimension(nx*ny) :: temp\r\n real(wp),dimension(max(2*kx*(nx+1),2*ky*(ny+1))) :: work\r\n logical :: status_ok\r\n\r\n !check validity of inputs\r\n\r\n call check_inputs( iknot,&\r\n iflag,&\r\n nx=nx,ny=ny,&\r\n kx=kx,ky=ky,&\r\n x=x,y=y,&\r\n tx=tx,ty=ty,&\r\n f2=fcn,&\r\n bcoef2=bcoef,&\r\n status_ok=status_ok)\r\n\r\n if (status_ok) then\r\n\r\n !choose knots\r\n\r\n if (iknot == 0) then\r\n call dbknot(x,nx,kx,tx)\r\n call dbknot(y,ny,ky,ty)\r\n end if\r\n\r\n !construct b-spline coefficients\r\n\r\n call dbtpcf(x,nx,fcn, nx,ny,tx,kx,temp, work,iflag)\r\n if (iflag==0) call dbtpcf(y,ny,temp,ny,nx,ty,ky,bcoef,work,iflag)\r\n\r\n end if\r\n\r\n end subroutine db2ink\r\n!*****************************************************************************************\r\n\r\n!*****************************************************************************************\r\n!>\r\n! Evaluates the tensor product piecewise polynomial\r\n! interpolant constructed by the routine [[db2ink]] or one of its\r\n! derivatives at the point (`xval`,`yval`).\r\n!\r\n! To evaluate the interpolant\r\n! itself, set `idx=idy=0`, to evaluate the first partial with respect\r\n! to `x`, set `idx=1,idy=0`, and so on.\r\n!\r\n! [[db2val]] returns 0.0 if `(xval,yval)` is out of range. that is, if\r\n!```fortran\r\n! xval < tx(1) .or. xval > tx(nx+kx) .or.\r\n! yval < ty(1) .or. yval > ty(ny+ky)\r\n!```\r\n! if the knots tx and ty were chosen by [[db2ink]], then this is equivalent to:\r\n!```fortran\r\n! xval < x(1) .or. xval > x(nx)+epsx .or.\r\n! yval < y(1) .or. yval > y(ny)+epsy\r\n!```\r\n! where\r\n!```fortran\r\n! epsx = 0.1*(x(nx)-x(nx-1))\r\n! epsy = 0.1*(y(ny)-y(ny-1))\r\n!```\r\n!\r\n! The input quantities `tx`, `ty`, `nx`, `ny`, `kx`, `ky`, and `bcoef` should be\r\n! unchanged since the last call of [[db2ink]].\r\n!\r\n!### History\r\n! * Boisvert, Ronald, NBS : 25 may 1982 : Author of original routine.\r\n! * JEC : 000330 modified array declarations.\r\n! * Jacob Williams, 2/24/2015 : extensive refactoring of CMLIB routine.\r\n\r\n pure subroutine db2val(xval,yval,idx,idy,tx,ty,nx,ny,kx,ky,bcoef,f,iflag,inbvx,inbvy,iloy,extrap)\r\n\r\n implicit none\r\n\r\n integer,intent(in) :: idx !! \\(x\\) derivative of piecewise polynomial to evaluate.\r\n integer,intent(in) :: idy !! \\(y\\) derivative of piecewise polynomial to evaluate.\r\n integer,intent(in) :: nx !! the number of interpolation points in \\(x\\).\r\n !! (same as in last call to [[db2ink]])\r\n integer,intent(in) :: ny !! the number of interpolation points in \\(y\\).\r\n !! (same as in last call to [[db2ink]])\r\n integer,intent(in) :: kx !! order of polynomial pieces in \\(x\\).\r\n !! (same as in last call to [[db2ink]])\r\n integer,intent(in) :: ky !! order of polynomial pieces in \\(y\\).\r\n !! (same as in last call to [[db2ink]])\r\n real(wp),intent(in) :: xval !! \\(x\\) coordinate of evaluation point.\r\n real(wp),intent(in) :: yval !! \\(y\\) coordinate of evaluation point.\r\n real(wp),dimension(nx+kx),intent(in) :: tx !! sequence of knots defining the piecewise polynomial\r\n !! in the \\(x\\) direction.\r\n !! (same as in last call to [[db2ink]])\r\n real(wp),dimension(ny+ky),intent(in) :: ty !! sequence of knots defining the piecewise\r\n !! polynomial in the \\(y\\) direction.\r\n !! (same as in last call to [[db2ink]])\r\n real(wp),dimension(nx,ny),intent(in) :: bcoef !! the b-spline coefficients computed by [[db2ink]].\r\n real(wp),intent(out) :: f !! interpolated value\r\n integer,intent(out) :: iflag !! status flag:\r\n !!\r\n !! * \\( = 0 \\) : no errors\r\n !! * \\( \\ne 0 \\) : error\r\n integer,intent(inout) :: inbvx !! initialization parameter which must be set to 1\r\n !! the first time this routine is called,\r\n !! and must not be changed by the user.\r\n integer,intent(inout) :: inbvy !! initialization parameter which must be set to 1\r\n !! the first time this routine is called,\r\n !! and must not be changed by the user.\r\n integer,intent(inout) :: iloy !! initialization parameter which must be set to 1\r\n !! the first time this routine is called,\r\n !! and must not be changed by the user.\r\n logical,intent(in),optional :: extrap !! if extrapolation is allowed\r\n !! (if not present, default is False)\r\n\r\n integer :: k, lefty, kcol\r\n real(wp),dimension(ky) :: temp\r\n real(wp),dimension(3*max(kx,ky)) :: work\r\n\r\n f = 0.0_wp\r\n\r\n iflag = check_value(xval,tx,1,extrap); if (iflag/=0) return\r\n iflag = check_value(yval,ty,2,extrap); if (iflag/=0) return\r\n\r\n call dintrv(ty,ny+ky,yval,iloy,lefty,iflag,extrap); if (iflag/=0) return\r\n\r\n kcol = lefty - ky\r\n do k=1,ky\r\n kcol = kcol + 1\r\n call dbvalu(tx,bcoef(:,kcol),nx,kx,idx,xval,inbvx,work,iflag,temp(k),extrap)\r\n if (iflag/=0) return !error\r\n end do\r\n\r\n kcol = lefty - ky + 1\r\n call dbvalu(ty(kcol:),temp,ky,ky,idy,yval,inbvy,work,iflag,f,extrap)\r\n\r\n end subroutine db2val\r\n!*****************************************************************************************\r\n\r\n!*****************************************************************************************\r\n!>\r\n! Determines the parameters of a function that interpolates\r\n! the three-dimensional gridded data\r\n! $$ [x(i),y(j),z(k),\\mathrm{fcn}(i,j,k)] ~\\mathrm{for}~\r\n! i=1,..,n_x ~\\mathrm{and}~ j=1,..,n_y, ~\\mathrm{and}~ k=1,..,n_z $$\r\n! The interpolating function and\r\n! its derivatives may subsequently be evaluated by the function\r\n! [[db3val]].\r\n!\r\n! The interpolating function is a piecewise polynomial function\r\n! represented as a tensor product of one-dimensional b-splines. the\r\n! form of this function is\r\n! $$ s(x,y,z) = \\sum_{i=1}^{n_x} \\sum_{j=1}^{n_y} \\sum_{k=1}^{n_z}\r\n! a_{ijk} u_i(x) v_j(y) w_k(z) $$\r\n!\r\n! where the functions \\(u_i\\), \\(v_j\\), and \\(w_k\\) are one-dimensional b-\r\n! spline basis functions. the coefficients \\(a_{ijk}\\) are chosen so that:\r\n!\r\n! $$ s(x(i),y(j),z(k)) = \\mathrm{fcn}(i,j,k)\r\n! ~\\mathrm{for}~ i=1,..,n_x , j=1,..,n_y , k=1,..,n_z $$\r\n!\r\n! Note that for fixed values of \\(y\\) and \\(z\\) \\(s(x,y,z)\\) is a piecewise\r\n! polynomial function of \\(x\\) alone, for fixed values of \\(x\\) and \\(z\\) \\(s(x,y,z)\\)\r\n! is a piecewise polynomial function of \\(y\\) alone, and for fixed\r\n! values of \\(x\\) and \\(y\\) \\(s(x,y,z)\\) is a function of \\(z\\) alone. in one\r\n! dimension a piecewise polynomial may be created by partitioning a\r\n! given interval into subintervals and defining a distinct polynomial\r\n! piece on each one. the points where adjacent subintervals meet are\r\n! called knots. each of the functions \\(u_i\\), \\(v_j\\), and \\(w_k\\) above is a\r\n! piecewise polynomial.\r\n!\r\n! Users of [[db3ink]] choose the order (degree+1) of the polynomial\r\n! pieces used to define the piecewise polynomial in each of the \\(x\\), \\(y\\),\r\n! and \\(z\\) directions (`kx`, `ky`, and `kz`). users also may define their own\r\n! knot sequence in \\(x\\), \\(y\\), \\(z\\) separately (`tx`, `ty`, and `tz`). if `iflag=0`,\r\n! however, [[db3ink]] will choose sequences of knots that result in a\r\n! piecewise polynomial interpolant with `kx-2` continuous partial\r\n! derivatives in \\(x\\), `ky-2` continuous partial derivatives in \\(y\\), and `kz-2`\r\n! continuous partial derivatives in \\(z\\). (`kx` knots are taken near\r\n! each endpoint in \\(x\\), not-a-knot end conditions are used, and the\r\n! remaining knots are placed at data points if `kx` is even or at\r\n! midpoints between data points if `kx` is odd. the \\(y\\) and \\(z\\) directions\r\n! are treated similarly.)\r\n!\r\n! After a call to [[db3ink]], all information necessary to define the\r\n! interpolating function are contained in the parameters `nx`, `ny`, `nz`,\r\n! `kx`, `ky`, `kz`, `tx`, `ty`, `tz`, and `bcoef`. these quantities should not be\r\n! altered until after the last call of the evaluation routine [[db3val]].\r\n!\r\n!### History\r\n! * Boisvert, Ronald, NBS : 25 may 1982 : Author of original routine.\r\n! * JEC : 000330 modified array declarations.\r\n! * Jacob Williams, 2/24/2015 : extensive refactoring of CMLIB routine.\r\n\r\n pure subroutine db3ink(x,nx,y,ny,z,nz,fcn,kx,ky,kz,iknot,tx,ty,tz,bcoef,iflag)\r\n\r\n implicit none\r\n\r\n integer,intent(in) :: nx !! number of \\(x\\) abcissae ( \\( \\ge 3 \\) )\r\n integer,intent(in) :: ny !! number of \\(y\\) abcissae ( \\( \\ge 3 \\) )\r\n integer,intent(in) :: nz !! number of \\(z\\) abcissae ( \\( \\ge 3 \\) )\r\n integer,intent(in) :: kx !! The order of spline pieces in \\(x\\)\r\n !! ( \\( 2 \\le k_x < n_x \\) )\r\n !! (order = polynomial degree + 1)\r\n integer,intent(in) :: ky !! The order of spline pieces in \\(y\\)\r\n !! ( \\( 2 \\le k_y < n_y \\) )\r\n !! (order = polynomial degree + 1)\r\n integer,intent(in) :: kz !! the order of spline pieces in \\(z\\)\r\n !! ( \\( 2 \\le k_z < n_z \\) )\r\n !! (order = polynomial degree + 1)\r\n real(wp),dimension(:),intent(in) :: x !! `(nx)` array of \\(x\\) abcissae. must be strictly increasing.\r\n real(wp),dimension(:),intent(in) :: y !! `(ny)` array of \\(y\\) abcissae. must be strictly increasing.\r\n real(wp),dimension(:),intent(in) :: z !! `(nz)` array of \\(z\\) abcissae. must be strictly increasing.\r\n real(wp),dimension(:,:,:),intent(in) :: fcn !! `(nx,ny,nz)` matrix of function values to interpolate. `fcn(i,j,k)` should\r\n !! contain the function value at the point (`x(i)`,`y(j)`,`z(k)`)\r\n integer,intent(in) :: iknot !! knot sequence flag:\r\n !!\r\n !! * 0 = knot sequence chosen by [[db3ink]].\r\n !! * 1 = knot sequence chosen by user.\r\n real(wp),dimension(:),intent(inout) :: tx !! The `(nx+kx)` knots in the \\(x\\) direction for the spline\r\n !! interpolant.\r\n !!\r\n !! * If `iknot=0` these are chosen by [[db3ink]].\r\n !! * If `iknot=1` these are specified by the user.\r\n !!\r\n !! Must be non-decreasing.\r\n real(wp),dimension(:),intent(inout) :: ty !! The `(ny+ky)` knots in the \\(y\\) direction for the spline\r\n !! interpolant.\r\n !!\r\n !! * If `iknot=0` these are chosen by [[db3ink]].\r\n !! * If `iknot=1` these are specified by the user.\r\n !!\r\n !! Must be non-decreasing.\r\n real(wp),dimension(:),intent(inout) :: tz !! The `(nz+kz)` knots in the \\(z\\) direction for the spline\r\n !! interpolant.\r\n !!\r\n !! * If `iknot=0` these are chosen by [[db3ink]].\r\n !! * If `iknot=1` these are specified by the user.\r\n !!\r\n !! Must be non-decreasing.\r\n real(wp),dimension(:,:,:),intent(out) :: bcoef !! `(nx,ny,nz)` matrix of coefficients of the b-spline interpolant.\r\n integer,intent(out) :: iflag !! * 0 = successful execution.\r\n !! * 2 = `iknot` out of range.\r\n !! * 3 = `nx` out of range.\r\n !! * 4 = `kx` out of range.\r\n !! * 5 = `x` not strictly increasing.\r\n !! * 6 = `tx` not non-decreasing.\r\n !! * 7 = `ny` out of range.\r\n !! * 8 = `ky` out of range.\r\n !! * 9 = `y` not strictly increasing.\r\n !! * 10 = `ty` not non-decreasing.\r\n !! * 11 = `nz` out of range.\r\n !! * 12 = `kz` out of range.\r\n !! * 13 = `z` not strictly increasing.\r\n !! * 14 = `ty` not non-decreasing.\r\n !! * 700 = `size(x) ` \\(\\ne\\) `size(fcn,1)`\r\n !! * 701 = `size(y) ` \\(\\ne\\) `size(fcn,2)`\r\n !! * 702 = `size(z) ` \\(\\ne\\) `size(fcn,3)`\r\n !! * 706 = `size(x) ` \\(\\ne\\) `nx`\r\n !! * 707 = `size(y) ` \\(\\ne\\) `ny`\r\n !! * 708 = `size(z) ` \\(\\ne\\) `nz`\r\n !! * 712 = `size(tx)` \\(\\ne\\) `nx+kx`\r\n !! * 713 = `size(ty)` \\(\\ne\\) `ny+ky`\r\n !! * 714 = `size(tz)` \\(\\ne\\) `nz+kz`\r\n !! * 800 = `size(x) ` \\(\\ne\\) `size(bcoef,1)`\r\n !! * 801 = `size(y) ` \\(\\ne\\) `size(bcoef,2)`\r\n !! * 802 = `size(z) ` \\(\\ne\\) `size(bcoef,3)`\r\n\r\n real(wp),dimension(nx*ny*nz) :: temp\r\n real(wp),dimension(max(2*kx*(nx+1),2*ky*(ny+1),2*kz*(nz+1))) :: work\r\n logical :: status_ok\r\n\r\n ! check validity of input\r\n\r\n call check_inputs( iknot,&\r\n iflag,&\r\n nx=nx,ny=ny,nz=nz,&\r\n kx=kx,ky=ky,kz=kz,&\r\n x=x,y=y,z=z,&\r\n tx=tx,ty=ty,tz=tz,&\r\n f3=fcn,&\r\n bcoef3=bcoef,&\r\n status_ok=status_ok)\r\n\r\n if (status_ok) then\r\n\r\n ! choose knots\r\n\r\n if (iknot == 0) then\r\n call dbknot(x,nx,kx,tx)\r\n call dbknot(y,ny,ky,ty)\r\n call dbknot(z,nz,kz,tz)\r\n end if\r\n\r\n ! copy fcn to work in packed for dbtpcf\r\n temp(1:nx*ny*nz) = reshape( fcn, [nx*ny*nz] )\r\n\r\n ! construct b-spline coefficients\r\n\r\n call dbtpcf(x,nx,temp, nx,ny*nz,tx,kx,bcoef,work,iflag)\r\n if (iflag==0) call dbtpcf(y,ny,bcoef,ny,nx*nz,ty,ky,temp, work,iflag)\r\n if (iflag==0) call dbtpcf(z,nz,temp, nz,nx*ny,tz,kz,bcoef,work,iflag)\r\n\r\n end if\r\n\r\n end subroutine db3ink\r\n!*****************************************************************************************\r\n\r\n!*****************************************************************************************\r\n!>\r\n! Evaluates the tensor product piecewise polynomial\r\n! interpolant constructed by the routine [[db3ink]] or one of its\r\n! derivatives at the point (`xval`,`yval`,`zval`).\r\n!\r\n! To evaluate the\r\n! interpolant itself, set `idx=idy=idz=0`, to evaluate the first\r\n! partial with respect to `x`, set `idx=1`,`idy=idz=0`, and so on.\r\n!\r\n! [[db3val]] returns 0.0 if (`xval`,`yval`,`zval`) is out of range. that is,\r\n!```fortran\r\n! xvaltx(nx+kx) .or.\r\n! yvalty(ny+ky) .or.\r\n! zvaltz(nz+kz)\r\n!```\r\n! if the knots `tx`, `ty`, and `tz` were chosen by [[db3ink]], then this is\r\n! equivalent to\r\n!```fortran\r\n! xvalx(nx)+epsx .or.\r\n! yvaly(ny)+epsy .or.\r\n! zvalz(nz)+epsz\r\n!```\r\n! where\r\n!```fortran\r\n! epsx = 0.1*(x(nx)-x(nx-1))\r\n! epsy = 0.1*(y(ny)-y(ny-1))\r\n! epsz = 0.1*(z(nz)-z(nz-1))\r\n!```\r\n!\r\n! The input quantities `tx`, `ty`, `tz`, `nx`, `ny`, `nz`, `kx`, `ky`, `kz`, and `bcoef`\r\n! should remain unchanged since the last call of [[db3ink]].\r\n!\r\n!### History\r\n! * Boisvert, Ronald, NBS : 25 may 1982 : Author of original routine.\r\n! * JEC : 000330 modified array declarations.\r\n! * Jacob Williams, 2/24/2015 : extensive refactoring of CMLIB routine.\r\n\r\n pure subroutine db3val(xval,yval,zval,idx,idy,idz,&\r\n tx,ty,tz,&\r\n nx,ny,nz,kx,ky,kz,bcoef,f,iflag,&\r\n inbvx,inbvy,inbvz,iloy,iloz,extrap)\r\n\r\n implicit none\r\n\r\n integer,intent(in) :: idx !! \\(x\\) derivative of piecewise polynomial to evaluate.\r\n integer,intent(in) :: idy !! \\(y\\) derivative of piecewise polynomial to evaluate.\r\n integer,intent(in) :: idz !! \\(z\\) derivative of piecewise polynomial to evaluate.\r\n integer,intent(in) :: nx !! the number of interpolation points in \\(x\\).\r\n !! (same as in last call to [[db3ink]])\r\n integer,intent(in) :: ny !! the number of interpolation points in \\(y\\).\r\n !! (same as in last call to [[db3ink]])\r\n integer,intent(in) :: nz !! the number of interpolation points in \\(z\\).\r\n !! (same as in last call to [[db3ink]])\r\n integer,intent(in) :: kx !! order of polynomial pieces in \\(z\\).\r\n !! (same as in last call to [[db3ink]])\r\n integer,intent(in) :: ky !! order of polynomial pieces in \\(y\\).\r\n !! (same as in last call to [[db3ink]])\r\n integer,intent(in) :: kz !! order of polynomial pieces in \\(z\\).\r\n !! (same as in last call to [[db3ink]])\r\n real(wp),intent(in) :: xval !! \\(x\\) coordinate of evaluation point.\r\n real(wp),intent(in) :: yval !! \\(y\\) coordinate of evaluation point.\r\n real(wp),intent(in) :: zval !! \\(z\\) coordinate of evaluation point.\r\n real(wp),dimension(nx+kx),intent(in) :: tx !! sequence of knots defining the piecewise polynomial\r\n !! in the \\(x\\) direction. (same as in last call to [[db3ink]])\r\n real(wp),dimension(ny+ky),intent(in) :: ty !! sequence of knots defining the piecewise polynomial\r\n !! in the \\(y\\) direction. (same as in last call to [[db3ink]])\r\n real(wp),dimension(nz+kz),intent(in) :: tz !! sequence of knots defining the piecewise polynomial\r\n !! in the \\(z\\) direction. (same as in last call to [[db3ink]])\r\n real(wp),dimension(nx,ny,nz),intent(in) :: bcoef !! the b-spline coefficients computed by [[db3ink]].\r\n real(wp),intent(out) :: f !! interpolated value\r\n integer,intent(out) :: iflag !! status flag:\r\n !!\r\n !! * \\( = 0 \\) : no errors\r\n !! * \\( \\ne 0 \\) : error\r\n integer,intent(inout) :: inbvx !! initialization parameter which must be\r\n !! set to 1 the first time this routine is called,\r\n !! and must not be changed by the user.\r\n integer,intent(inout) :: inbvy !! initialization parameter which must be\r\n !! set to 1 the first time this routine is called,\r\n !! and must not be changed by the user.\r\n integer,intent(inout) :: inbvz !! initialization parameter which must be\r\n !! set to 1 the first time this routine is called,\r\n !! and must not be changed by the user.\r\n integer,intent(inout) :: iloy !! initialization parameter which must be\r\n !! set to 1 the first time this routine is called,\r\n !! and must not be changed by the user.\r\n integer,intent(inout) :: iloz !! initialization parameter which must be\r\n !! set to 1 the first time this routine is called,\r\n !! and must not be changed by the user.\r\n logical,intent(in),optional :: extrap !! if extrapolation is allowed\r\n !! (if not present, default is False)\r\n\r\n real(wp),dimension(ky,kz) :: temp1\r\n real(wp),dimension(kz) :: temp2\r\n real(wp),dimension(3*max(kx,ky,kz)) :: work\r\n\r\n integer :: lefty, leftz, &\r\n kcoly, kcolz, j, k\r\n\r\n f = 0.0_wp\r\n\r\n iflag = check_value(xval,tx,1,extrap); if (iflag/=0) return\r\n iflag = check_value(yval,ty,2,extrap); if (iflag/=0) return\r\n iflag = check_value(zval,tz,3,extrap); if (iflag/=0) return\r\n\r\n call dintrv(ty,ny+ky,yval,iloy,lefty,iflag,extrap); if (iflag/=0) return\r\n call dintrv(tz,nz+kz,zval,iloz,leftz,iflag,extrap); if (iflag/=0) return\r\n\r\n iflag = 0\r\n\r\n kcolz = leftz - kz\r\n do k=1,kz\r\n kcolz = kcolz + 1\r\n kcoly = lefty - ky\r\n do j=1,ky\r\n kcoly = kcoly + 1\r\n call dbvalu(tx,bcoef(:,kcoly,kcolz),nx,kx,idx,xval,inbvx,work,iflag,temp1(j,k),extrap)\r\n if (iflag/=0) return\r\n end do\r\n end do\r\n\r\n kcoly = lefty - ky + 1\r\n do k=1,kz\r\n call dbvalu(ty(kcoly:),temp1(:,k),ky,ky,idy,yval,inbvy,work,iflag,temp2(k),extrap)\r\n if (iflag/=0) return\r\n end do\r\n\r\n kcolz = leftz - kz + 1\r\n call dbvalu(tz(kcolz:),temp2,kz,kz,idz,zval,inbvz,work,iflag,f,extrap)\r\n\r\n end subroutine db3val\r\n!*****************************************************************************************\r\n\r\n!*****************************************************************************************\r\n!>\r\n! Determines the parameters of a function that interpolates\r\n! the four-dimensional gridded data\r\n! $$ [x(i),y(j),z(k),q(l),\\mathrm{fcn}(i,j,k,l)] ~\\mathrm{for}~\r\n! i=1,..,n_x ~\\mathrm{and}~ j=1,..,n_y, ~\\mathrm{and}~ k=1,..,n_z,\r\n! ~\\mathrm{and}~ l=1,..,n_q $$\r\n! The interpolating function and its derivatives may\r\n! subsequently be evaluated by the function [[db4val]].\r\n!\r\n! See [[db3ink]] header for more details.\r\n!\r\n!### History\r\n! * Jacob Williams, 2/24/2015 : Created this routine.\r\n\r\n pure subroutine db4ink(x,nx,y,ny,z,nz,q,nq,&\r\n fcn,&\r\n kx,ky,kz,kq,&\r\n iknot,&\r\n tx,ty,tz,tq,&\r\n bcoef,iflag)\r\n\r\n implicit none\r\n\r\n integer,intent(in) :: nx !! number of \\(x\\) abcissae ( \\( \\ge 3 \\) )\r\n integer,intent(in) :: ny !! number of \\(y\\) abcissae ( \\( \\ge 3 \\) )\r\n integer,intent(in) :: nz !! number of \\(z\\) abcissae ( \\( \\ge 3 \\) )\r\n integer,intent(in) :: nq !! number of \\(q\\) abcissae ( \\( \\ge 3 \\) )\r\n integer,intent(in) :: kx !! the order of spline pieces in \\(x\\)\r\n !! ( \\( 2 \\le k_x < n_x \\) ).\r\n !! (order = polynomial degree + 1)\r\n integer,intent(in) :: ky !! the order of spline pieces in \\(y\\)\r\n !! ( \\( 2 \\le k_y < n_y \\) ).\r\n !! (order = polynomial degree + 1)\r\n integer,intent(in) :: kz !! the order of spline pieces in \\(z\\)\r\n !! ( \\( 2 \\le k_z < n_z \\) ).\r\n !! (order = polynomial degree + 1)\r\n integer,intent(in) :: kq !! the order of spline pieces in \\(q\\)\r\n !! ( \\( 2 \\le k_q < n_q \\) ).\r\n !! (order = polynomial degree + 1)\r\n real(wp),dimension(:),intent(in) :: x !! `(nx)` array of \\(x\\) abcissae. must be strictly increasing.\r\n real(wp),dimension(:),intent(in) :: y !! `(ny)` array of \\(y\\) abcissae. must be strictly increasing.\r\n real(wp),dimension(:),intent(in) :: z !! `(nz)` array of \\(z\\) abcissae. must be strictly increasing.\r\n real(wp),dimension(:),intent(in) :: q !! `(nq)` array of \\(q\\) abcissae. must be strictly increasing.\r\n real(wp),dimension(:,:,:,:),intent(in) :: fcn !! `(nx,ny,nz,nq)` matrix of function values to interpolate.\r\n !! `fcn(i,j,k,q)` should contain the function value at the\r\n !! point (`x(i)`,`y(j)`,`z(k)`,`q(l)`)\r\n integer,intent(in) :: iknot !! knot sequence flag:\r\n !!\r\n !! * 0 = knot sequence chosen by [[db4ink]].\r\n !! * 1 = knot sequence chosen by user.\r\n real(wp),dimension(:),intent(inout) :: tx !! The `(nx+kx)` knots in the x direction for the spline\r\n !! interpolant.\r\n !!\r\n !! * If `iknot=0` these are chosen by [[db4ink]].\r\n !! * If `iknot=1` these are specified by the user.\r\n !!\r\n !! Must be non-decreasing.\r\n real(wp),dimension(:),intent(inout) :: ty !! The `(ny+ky)` knots in the y direction for the spline\r\n !! interpolant.\r\n !!\r\n !! * If `iknot=0` these are chosen by [[db4ink]].\r\n !! * If `iknot=1` these are specified by the user.\r\n !!\r\n !! Must be non-decreasing.\r\n real(wp),dimension(:),intent(inout) :: tz !! The `(nz+kz)` knots in the z direction for the spline\r\n !! interpolant.\r\n !!\r\n !! * If `iknot=0` these are chosen by [[db4ink]].\r\n !! * If `iknot=1` these are specified by the user.\r\n !!\r\n !! Must be non-decreasing.\r\n real(wp),dimension(:),intent(inout) :: tq !! The `(nq+kq)` knots in the q direction for the spline\r\n !! interpolant.\r\n !!\r\n !! * If `iknot=0` these are chosen by [[db4ink]].\r\n !! * If `iknot=1` these are specified by the user.\r\n !!\r\n !! Must be non-decreasing.\r\n real(wp),dimension(:,:,:,:),intent(out) :: bcoef !! `(nx,ny,nz,nq)` matrix of coefficients of the b-spline\r\n !! interpolant.\r\n integer,intent(out) :: iflag !! * 0 = successful execution.\r\n !! * 2 = `iknot` out of range.\r\n !! * 3 = `nx` out of range.\r\n !! * 4 = `kx` out of range.\r\n !! * 5 = `x` not strictly increasing.\r\n !! * 6 = `tx` not non-decreasing.\r\n !! * 7 = `ny` out of range.\r\n !! * 8 = `ky` out of range.\r\n !! * 9 = `y` not strictly increasing.\r\n !! * 10 = `ty` not non-decreasing.\r\n !! * 11 = `nz` out of range.\r\n !! * 12 = `kz` out of range.\r\n !! * 13 = `z` not strictly increasing.\r\n !! * 14 = `tz` not non-decreasing.\r\n !! * 15 = `nq` out of range.\r\n !! * 16 = `kq` out of range.\r\n !! * 17 = `q` not strictly increasing.\r\n !! * 18 = `tq` not non-decreasing.\r\n !! * 700 = `size(x)` \\( \\ne \\) `size(fcn,1)`\r\n !! * 701 = `size(y)` \\( \\ne \\) `size(fcn,2)`\r\n !! * 702 = `size(z)` \\( \\ne \\) `size(fcn,3)`\r\n !! * 703 = `size(q)` \\( \\ne \\) `size(fcn,4)`\r\n !! * 706 = `size(x)` \\( \\ne \\) `nx`\r\n !! * 707 = `size(y)` \\( \\ne \\) `ny`\r\n !! * 708 = `size(z)` \\( \\ne \\) `nz`\r\n !! * 709 = `size(q)` \\( \\ne \\) `nq`\r\n !! * 712 = `size(tx`) \\( \\ne \\) `nx+kx`\r\n !! * 713 = `size(ty`) \\( \\ne \\) `ny+ky`\r\n !! * 714 = `size(tz`) \\( \\ne \\) `nz+kz`\r\n !! * 715 = `size(tq`) \\( \\ne \\) `nq+kq`\r\n !! * 800 = `size(x)` \\( \\ne \\) `size(bcoef,1)`\r\n !! * 801 = `size(y)` \\( \\ne \\) `size(bcoef,2)`\r\n !! * 802 = `size(z)` \\( \\ne \\) `size(bcoef,3)`\r\n !! * 803 = `size(q)` \\( \\ne \\) `size(bcoef,4)`\r\n\r\n real(wp),dimension(nx*ny*nz*nq) :: temp\r\n real(wp),dimension(max(2*kx*(nx+1),2*ky*(ny+1),2*kz*(nz+1),2*kq*(nq+1))) :: work\r\n logical :: status_ok\r\n\r\n ! check validity of input\r\n\r\n call check_inputs( iknot,&\r\n iflag,&\r\n nx=nx,ny=ny,nz=nz,nq=nq,&\r\n kx=kx,ky=ky,kz=kz,kq=kq,&\r\n x=x,y=y,z=z,q=q,&\r\n tx=tx,ty=ty,tz=tz,tq=tq,&\r\n f4=fcn,&\r\n bcoef4=bcoef,&\r\n status_ok=status_ok)\r\n\r\n if (status_ok) then\r\n\r\n ! choose knots\r\n\r\n if (iknot == 0) then\r\n call dbknot(x,nx,kx,tx)\r\n call dbknot(y,ny,ky,ty)\r\n call dbknot(z,nz,kz,tz)\r\n call dbknot(q,nq,kq,tq)\r\n end if\r\n\r\n ! construct b-spline coefficients\r\n\r\n call dbtpcf(x,nx,fcn, nx,ny*nz*nq,tx,kx,temp, work,iflag)\r\n if (iflag==0) call dbtpcf(y,ny,temp, ny,nx*nz*nq,ty,ky,bcoef,work,iflag)\r\n if (iflag==0) call dbtpcf(z,nz,bcoef,nz,nx*ny*nq,tz,kz,temp, work,iflag)\r\n if (iflag==0) call dbtpcf(q,nq,temp, nq,nx*ny*nz,tq,kq,bcoef,work,iflag)\r\n\r\n end if\r\n\r\n end subroutine db4ink\r\n!*****************************************************************************************\r\n\r\n!*****************************************************************************************\r\n!>\r\n! Evaluates the tensor product piecewise polynomial\r\n! interpolant constructed by the routine [[db4ink]] or one of its\r\n! derivatives at the point (`xval`,`yval`,`zval`,`qval`).\r\n!\r\n! To evaluate the\r\n! interpolant itself, set `idx=idy=idz=idq=0`, to evaluate the first\r\n! partial with respect to `x`, set `idx=1,idy=idz=idq=0`, and so on.\r\n!\r\n! See [[db3val]] header for more information.\r\n!\r\n!### History\r\n! * Jacob Williams, 2/24/2015 : Created this routine.\r\n\r\n pure subroutine db4val(xval,yval,zval,qval,&\r\n idx,idy,idz,idq,&\r\n tx,ty,tz,tq,&\r\n nx,ny,nz,nq,&\r\n kx,ky,kz,kq,&\r\n bcoef,f,iflag,&\r\n inbvx,inbvy,inbvz,inbvq,&\r\n iloy,iloz,iloq,extrap)\r\n\r\n implicit none\r\n\r\n integer,intent(in) :: idx !! \\(x\\) derivative of piecewise polynomial to evaluate.\r\n integer,intent(in) :: idy !! \\(y\\) derivative of piecewise polynomial to evaluate.\r\n integer,intent(in) :: idz !! \\(z\\) derivative of piecewise polynomial to evaluate.\r\n integer,intent(in) :: idq !! \\(q\\) derivative of piecewise polynomial to evaluate.\r\n integer,intent(in) :: nx !! the number of interpolation points in \\(x\\).\r\n !! (same as in last call to [[db4ink]])\r\n integer,intent(in) :: ny !! the number of interpolation points in \\(y\\).\r\n !! (same as in last call to [[db4ink]])\r\n integer,intent(in) :: nz !! the number of interpolation points in \\(z\\).\r\n !! (same as in last call to [[db4ink]])\r\n integer,intent(in) :: nq !! the number of interpolation points in \\(q\\).\r\n !! (same as in last call to [[db4ink]])\r\n integer,intent(in) :: kx !! order of polynomial pieces in \\(x\\).\r\n !! (same as in last call to [[db4ink]])\r\n integer,intent(in) :: ky !! order of polynomial pieces in \\(y\\).\r\n !! (same as in last call to [[db4ink]])\r\n integer,intent(in) :: kz !! order of polynomial pieces in \\(z\\).\r\n !! (same as in last call to [[db4ink]])\r\n integer,intent(in) :: kq !! order of polynomial pieces in \\(q\\).\r\n !! (same as in last call to [[db4ink]])\r\n real(wp),intent(in) :: xval !! \\(x\\) coordinate of evaluation point.\r\n real(wp),intent(in) :: yval !! \\(y\\) coordinate of evaluation point.\r\n real(wp),intent(in) :: zval !! \\(z\\) coordinate of evaluation point.\r\n real(wp),intent(in) :: qval !! \\(q\\) coordinate of evaluation point.\r\n real(wp),dimension(nx+kx),intent(in) :: tx !! sequence of knots defining the piecewise polynomial\r\n !! in the \\(x\\) direction. (same as in last call to\r\n !! [[db4ink]])\r\n real(wp),dimension(ny+ky),intent(in) :: ty !! sequence of knots defining the piecewise polynomial\r\n !! in the \\(y\\) direction. (same as in last call to\r\n !! [[db4ink]])\r\n real(wp),dimension(nz+kz),intent(in) :: tz !! sequence of knots defining the piecewise polynomial\r\n !! in the \\(z\\) direction. (same as in last call to\r\n !! [[db4ink]])\r\n real(wp),dimension(nq+kq),intent(in) :: tq !! sequence of knots defining the piecewise polynomial\r\n !! in the \\(q\\) direction. (same as in last call to\r\n !! [[db4ink]])\r\n real(wp),dimension(nx,ny,nz,nq),intent(in) :: bcoef !! the b-spline coefficients computed by [[db4ink]].\r\n real(wp),intent(out) :: f !! interpolated value\r\n integer,intent(out) :: iflag !! status flag:\r\n !!\r\n !! * \\( = 0 \\) : no errors\r\n !! * \\( \\ne 0 \\) : error\r\n integer,intent(inout) :: inbvx !! initialization parameter which must be set\r\n !! to 1 the first time this routine is called,\r\n !! and must not be changed by the user.\r\n integer,intent(inout) :: inbvy !! initialization parameter which must be set\r\n !! to 1 the first time this routine is called,\r\n !! and must not be changed by the user.\r\n integer,intent(inout) :: inbvz !! initialization parameter which must be set\r\n !! to 1 the first time this routine is called,\r\n !! and must not be changed by the user.\r\n integer,intent(inout) :: inbvq !! initialization parameter which must be set\r\n !! to 1 the first time this routine is called,\r\n !! and must not be changed by the user.\r\n integer,intent(inout) :: iloy !! initialization parameter which must be set\r\n !! to 1 the first time this routine is called,\r\n !! and must not be changed by the user.\r\n integer,intent(inout) :: iloz !! initialization parameter which must be set\r\n !! to 1 the first time this routine is called,\r\n !! and must not be changed by the user.\r\n integer,intent(inout) :: iloq !! initialization parameter which must be set\r\n !! to 1 the first time this routine is called,\r\n !! and must not be changed by the user.\r\n logical,intent(in),optional :: extrap !! if extrapolation is allowed\r\n !! (if not present, default is False)\r\n\r\n real(wp),dimension(ky,kz,kq) :: temp1\r\n real(wp),dimension(kz,kq) :: temp2\r\n real(wp),dimension(kq) :: temp3\r\n real(wp),dimension(3*max(kx,ky,kz,kq)) :: work\r\n integer :: lefty, leftz, leftq, &\r\n kcoly, kcolz, kcolq, j, k, q\r\n\r\n f = 0.0_wp\r\n\r\n iflag = check_value(xval,tx,1,extrap); if (iflag/=0) return\r\n iflag = check_value(yval,ty,2,extrap); if (iflag/=0) return\r\n iflag = check_value(zval,tz,3,extrap); if (iflag/=0) return\r\n iflag = check_value(qval,tq,4,extrap); if (iflag/=0) return\r\n\r\n call dintrv(ty,ny+ky,yval,iloy,lefty,iflag,extrap); if (iflag/=0) return\r\n call dintrv(tz,nz+kz,zval,iloz,leftz,iflag,extrap); if (iflag/=0) return\r\n call dintrv(tq,nq+kq,qval,iloq,leftq,iflag,extrap); if (iflag/=0) return\r\n\r\n iflag = 0\r\n\r\n ! x -> y, z, q\r\n kcolq = leftq - kq\r\n do q=1,kq\r\n kcolq = kcolq + 1\r\n kcolz = leftz - kz\r\n do k=1,kz\r\n kcolz = kcolz + 1\r\n kcoly = lefty - ky\r\n do j=1,ky\r\n kcoly = kcoly + 1\r\n call dbvalu(tx,bcoef(:,kcoly,kcolz,kcolq),&\r\n nx,kx,idx,xval,inbvx,work,iflag,&\r\n temp1(j,k,q),extrap)\r\n if (iflag/=0) return\r\n end do\r\n end do\r\n end do\r\n\r\n ! y -> z, q\r\n kcoly = lefty - ky + 1\r\n do q=1,kq\r\n do k=1,kz\r\n call dbvalu(ty(kcoly:),temp1(:,k,q),&\r\n ky,ky,idy,yval,inbvy,work,iflag,&\r\n temp2(k,q),extrap)\r\n if (iflag/=0) return\r\n end do\r\n end do\r\n\r\n ! z -> q\r\n kcolz = leftz - kz + 1\r\n do q=1,kq\r\n call dbvalu(tz(kcolz:),temp2(:,q),&\r\n kz,kz,idz,zval,inbvz,work,iflag,&\r\n temp3(q),extrap)\r\n if (iflag/=0) return\r\n end do\r\n\r\n ! q\r\n kcolq = leftq - kq + 1\r\n call dbvalu(tq(kcolq:),temp3,kq,kq,idq,qval,inbvq,work,iflag,f,extrap)\r\n\r\n end subroutine db4val\r\n!*****************************************************************************************\r\n\r\n!*****************************************************************************************\r\n!>\r\n! Determines the parameters of a function that interpolates\r\n! the five-dimensional gridded data:\r\n!\r\n! $$ [x(i),y(j),z(k),q(l),r(m),\\mathrm{fcn}(i,j,k,l,m)] $$\r\n!\r\n! for:\r\n!\r\n! $$ i=1,..,n_x ~\\mathrm{and}~ j=1,..,n_y, ~\\mathrm{and}~ k=1,..,n_z,\r\n! ~\\mathrm{and}~ l=1,..,n_q, ~\\mathrm{and}~ m=1,..,n_r $$\r\n!\r\n! The interpolating function and its derivatives may subsequently be evaluated\r\n! by the function [[db5val]].\r\n!\r\n! See [[db3ink]] header for more details.\r\n!\r\n!### History\r\n! * Jacob Williams, 2/24/2015 : Created this routine.\r\n\r\n pure subroutine db5ink(x,nx,y,ny,z,nz,q,nq,r,nr,&\r\n fcn,&\r\n kx,ky,kz,kq,kr,&\r\n iknot,&\r\n tx,ty,tz,tq,tr,&\r\n bcoef,iflag)\r\n\r\n implicit none\r\n\r\n integer,intent(in) :: nx !! number of \\(x\\) abcissae ( \\( \\ge 3 \\) )\r\n integer,intent(in) :: ny !! number of \\(y\\) abcissae ( \\( \\ge 3 \\) )\r\n integer,intent(in) :: nz !! number of \\(z\\) abcissae ( \\( \\ge 3 \\) )\r\n integer,intent(in) :: nq !! number of \\(q\\) abcissae ( \\( \\ge 3 \\) )\r\n integer,intent(in) :: nr !! number of \\(r\\) abcissae ( \\( \\ge 3 \\) )\r\n integer,intent(in) :: kx !! the order of spline pieces in \\(x\\)\r\n !! ( \\( 2 \\le k_x < n_x \\) ).\r\n !! (order = polynomial degree + 1)\r\n integer,intent(in) :: ky !! the order of spline pieces in \\(y\\)\r\n !! ( \\( 2 \\le k_y < n_y \\) ).\r\n !! (order = polynomial degree + 1)\r\n integer,intent(in) :: kz !! the order of spline pieces in \\(z\\)\r\n !! ( \\( 2 \\le k_z < n_z \\) ).\r\n !! (order = polynomial degree + 1)\r\n integer,intent(in) :: kq !! the order of spline pieces in \\(q\\)\r\n !! ( \\( 2 \\le k_q < n_q \\) ).\r\n !! (order = polynomial degree + 1)\r\n integer,intent(in) :: kr !! the order of spline pieces in \\(r\\)\r\n !! ( \\( 2 \\le k_r < n_r \\) ).\r\n !! (order = polynomial degree + 1)\r\n real(wp),dimension(:),intent(in) :: x !! `(nx)` array of \\(x\\) abcissae. must be strictly increasing.\r\n real(wp),dimension(:),intent(in) :: y !! `(ny)` array of \\(y\\) abcissae. must be strictly increasing.\r\n real(wp),dimension(:),intent(in) :: z !! `(nz)` array of \\(z\\) abcissae. must be strictly increasing.\r\n real(wp),dimension(:),intent(in) :: q !! `(nq)` array of \\(q\\) abcissae. must be strictly increasing.\r\n real(wp),dimension(:),intent(in) :: r !! `(nr)` array of \\(r\\) abcissae. must be strictly increasing.\r\n real(wp),dimension(:,:,:,:,:),intent(in) :: fcn !! `(nx,ny,nz,nq,nr)` matrix of function values to interpolate.\r\n !! `fcn(i,j,k,q,r)` should contain the function value at the\r\n !! point (`x(i)`,`y(j)`,`z(k)`,`q(l)`,`r(m)`)\r\n integer,intent(in) :: iknot !! knot sequence flag:\r\n !!\r\n !! * 0 = knot sequence chosen by [[db5ink]].\r\n !! * 1 = knot sequence chosen by user.\r\n real(wp),dimension(:),intent(inout) :: tx !! The `(nx+kx)` knots in the \\(x\\) direction for the spline\r\n !! interpolant.\r\n !!\r\n !! * If `iknot=0` these are chosen by [[db5ink]].\r\n !! * If `iknot=1` these are specified by the user.\r\n !!\r\n !! Must be non-decreasing.\r\n real(wp),dimension(:),intent(inout) :: ty !! The `(ny+ky)` knots in the \\(y\\) direction for the spline\r\n !! interpolant.\r\n !!\r\n !! * If `iknot=0` these are chosen by [[db5ink]].\r\n !! * If `iknot=1` these are specified by the user.\r\n !!\r\n !! Must be non-decreasing.\r\n real(wp),dimension(:),intent(inout) :: tz !! The `(nz+kz)` knots in the \\(z\\) direction for the spline\r\n !! interpolant.\r\n !!\r\n !! * If `iknot=0` these are chosen by [[db5ink]].\r\n !! * If `iknot=1` these are specified by the user.\r\n !!\r\n !! Must be non-decreasing.\r\n real(wp),dimension(:),intent(inout) :: tq !! The `(nq+kq)` knots in the \\(q\\) direction for the spline\r\n !! interpolant.\r\n !!\r\n !! * If `iknot=0` these are chosen by [[db5ink]].\r\n !! * If `iknot=1` these are specified by the user.\r\n !!\r\n !! Must be non-decreasing.\r\n real(wp),dimension(:),intent(inout) :: tr !! The `(nr+kr)` knots in the \\(r\\) direction for the spline\r\n !! interpolant.\r\n !!\r\n !! * If `iknot=0` these are chosen by [[db5ink]].\r\n !! * If `iknot=1` these are specified by the user.\r\n !!\r\n !! Must be non-decreasing.\r\n real(wp),dimension(:,:,:,:,:),intent(out) :: bcoef !! `(nx,ny,nz,nq,nr)` matrix of coefficients of the b-spline\r\n !! interpolant.\r\n integer,intent(out) :: iflag !! * 0 = successful execution.\r\n !! * 2 = `iknot` out of range.\r\n !! * 3 = `nx` out of range.\r\n !! * 4 = `kx` out of range.\r\n !! * 5 = `x` not strictly increasing.\r\n !! * 6 = `tx` not non-decreasing.\r\n !! * 7 = `ny` out of range.\r\n !! * 8 = `ky` out of range.\r\n !! * 9 = `y` not strictly increasing.\r\n !! * 10 = `ty` not non-decreasing.\r\n !! * 11 = `nz` out of range.\r\n !! * 12 = `kz` out of range.\r\n !! * 13 = `z` not strictly increasing.\r\n !! * 14 = `tz` not non-decreasing.\r\n !! * 15 = `nq` out of range.\r\n !! * 16 = `kq` out of range.\r\n !! * 17 = `q` not strictly increasing.\r\n !! * 18 = `tq` not non-decreasing.\r\n !! * 19 = `nr` out of range.\r\n !! * 20 = `kr` out of range.\r\n !! * 21 = `r` not strictly increasing.\r\n !! * 22 = `tr` not non-decreasing.\r\n !! * 700 = `size(x)` \\( \\ne \\) `size(fcn,1)`\r\n !! * 701 = `size(y)` \\( \\ne \\) `size(fcn,2)`\r\n !! * 702 = `size(z)` \\( \\ne \\) `size(fcn,3)`\r\n !! * 703 = `size(q)` \\( \\ne \\) `size(fcn,4)`\r\n !! * 704 = `size(r)` \\( \\ne \\) `size(fcn,5)`\r\n !! * 706 = `size(x)` \\( \\ne \\) `nx`\r\n !! * 707 = `size(y)` \\( \\ne \\) `ny`\r\n !! * 708 = `size(z)` \\( \\ne \\) `nz`\r\n !! * 709 = `size(q)` \\( \\ne \\) `nq`\r\n !! * 710 = `size(r)` \\( \\ne \\) `nr`\r\n !! * 712 = `size(tx)` \\( \\ne \\) `nx+kx`\r\n !! * 713 = `size(ty)` \\( \\ne \\) `ny+ky`\r\n !! * 714 = `size(tz)` \\( \\ne \\) `nz+kz`\r\n !! * 715 = `size(tq)` \\( \\ne \\) `nq+kq`\r\n !! * 716 = `size(tr)` \\( \\ne \\) `nr+kr`\r\n !! * 800 = `size(x)` \\( \\ne \\) `size(bcoef,1)`\r\n !! * 801 = `size(y)` \\( \\ne \\) `size(bcoef,2)`\r\n !! * 802 = `size(z)` \\( \\ne \\) `size(bcoef,3)`\r\n !! * 803 = `size(q)` \\( \\ne \\) `size(bcoef,4)`\r\n !! * 804 = `size(r)` \\( \\ne \\) `size(bcoef,5)`\r\n\r\n real(wp),dimension(nx*ny*nz*nq*nr) :: temp\r\n real(wp),dimension(max( 2*kx*(nx+1),&\r\n 2*ky*(ny+1),&\r\n 2*kz*(nz+1),&\r\n 2*kq*(nq+1),&\r\n 2*kr*(nr+1) )) :: work\r\n logical :: status_ok\r\n\r\n ! check validity of input\r\n\r\n call check_inputs( iknot,&\r\n iflag,&\r\n nx=nx,ny=ny,nz=nz,nq=nq,nr=nr,&\r\n kx=kx,ky=ky,kz=kz,kq=kq,kr=kr,&\r\n x=x,y=y,z=z,q=q,r=r,&\r\n tx=tx,ty=ty,tz=tz,tq=tq,tr=tr,&\r\n f5=fcn,&\r\n bcoef5=bcoef,&\r\n status_ok=status_ok)\r\n\r\n if (status_ok) then\r\n\r\n ! choose knots\r\n\r\n if (iknot == 0) then\r\n call dbknot(x,nx,kx,tx)\r\n call dbknot(y,ny,ky,ty)\r\n call dbknot(z,nz,kz,tz)\r\n call dbknot(q,nq,kq,tq)\r\n call dbknot(r,nr,kr,tr)\r\n end if\r\n\r\n ! copy fcn to work in packed for dbtpcf\r\n\r\n temp(1:nx*ny*nz*nq*nr) = reshape( fcn, [nx*ny*nz*nq*nr] )\r\n\r\n ! construct b-spline coefficients\r\n\r\n call dbtpcf(x,nx,temp, nx,ny*nz*nq*nr,tx,kx,bcoef,work,iflag)\r\n if (iflag==0) call dbtpcf(y,ny,bcoef, ny,nx*nz*nq*nr,ty,ky,temp, work,iflag)\r\n if (iflag==0) call dbtpcf(z,nz,temp, nz,nx*ny*nq*nr,tz,kz,bcoef,work,iflag)\r\n if (iflag==0) call dbtpcf(q,nq,bcoef, nq,nx*ny*nz*nr,tq,kq,temp, work,iflag)\r\n if (iflag==0) call dbtpcf(r,nr,temp, nr,nx*ny*nz*nq,tr,kr,bcoef,work,iflag)\r\n\r\n end if\r\n\r\n end subroutine db5ink\r\n!*****************************************************************************************\r\n\r\n!*****************************************************************************************\r\n!>\r\n! Evaluates the tensor product piecewise polynomial\r\n! interpolant constructed by the routine [[db5ink]] or one of its\r\n! derivatives at the point (`xval`,`yval`,`zval`,`qval`,`rval`).\r\n!\r\n! To evaluate the\r\n! interpolant itself, set `idx=idy=idz=idq=idr=0`, to evaluate the first\r\n! partial with respect to `x`, set `idx=1,idy=idz=idq=idr=0,` and so on.\r\n!\r\n! See [[db3val]] header for more information.\r\n!\r\n!### History\r\n! * Jacob Williams, 2/24/2015 : Created this routine.\r\n\r\n pure subroutine db5val(xval,yval,zval,qval,rval,&\r\n idx,idy,idz,idq,idr,&\r\n tx,ty,tz,tq,tr,&\r\n nx,ny,nz,nq,nr,&\r\n kx,ky,kz,kq,kr,&\r\n bcoef,f,iflag,&\r\n inbvx,inbvy,inbvz,inbvq,inbvr,&\r\n iloy,iloz,iloq,ilor,extrap)\r\n\r\n implicit none\r\n\r\n integer,intent(in) :: idx !! \\(x\\) derivative of piecewise polynomial to evaluate.\r\n integer,intent(in) :: idy !! \\(y\\) derivative of piecewise polynomial to evaluate.\r\n integer,intent(in) :: idz !! \\(z\\) derivative of piecewise polynomial to evaluate.\r\n integer,intent(in) :: idq !! \\(q\\) derivative of piecewise polynomial to evaluate.\r\n integer,intent(in) :: idr !! \\(r\\) derivative of piecewise polynomial to evaluate.\r\n integer,intent(in) :: nx !! the number of interpolation points in \\(x\\).\r\n !! (same as in last call to [[db5ink]])\r\n integer,intent(in) :: ny !! the number of interpolation points in \\(y\\).\r\n !! (same as in last call to [[db5ink]])\r\n integer,intent(in) :: nz !! the number of interpolation points in \\(z\\).\r\n !! (same as in last call to [[db5ink]])\r\n integer,intent(in) :: nq !! the number of interpolation points in \\(q\\).\r\n !! (same as in last call to [[db5ink]])\r\n integer,intent(in) :: nr !! the number of interpolation points in \\(r\\).\r\n !! (same as in last call to [[db5ink]])\r\n integer,intent(in) :: kx !! order of polynomial pieces in \\(x\\).\r\n !! (same as in last call to [[db5ink]])\r\n integer,intent(in) :: ky !! order of polynomial pieces in \\(y\\).\r\n !! (same as in last call to [[db5ink]])\r\n integer,intent(in) :: kz !! order of polynomial pieces in \\(z\\).\r\n !! (same as in last call to [[db5ink]])\r\n integer,intent(in) :: kq !! order of polynomial pieces in \\(q\\).\r\n !! (same as in last call to [[db5ink]])\r\n integer,intent(in) :: kr !! order of polynomial pieces in \\(r\\).\r\n !! (same as in last call to [[db5ink]])\r\n real(wp),intent(in) :: xval !! \\(x\\) coordinate of evaluation point.\r\n real(wp),intent(in) :: yval !! \\(y\\) coordinate of evaluation point.\r\n real(wp),intent(in) :: zval !! \\(z\\) coordinate of evaluation point.\r\n real(wp),intent(in) :: qval !! \\(q\\) coordinate of evaluation point.\r\n real(wp),intent(in) :: rval !! \\(r\\) coordinate of evaluation point.\r\n real(wp),dimension(nx+kx),intent(in) :: tx !! sequence of knots defining the piecewise polynomial\r\n !! in the \\(x\\) direction.\r\n !! (same as in last call to [[db5ink]])\r\n real(wp),dimension(ny+ky),intent(in) :: ty !! sequence of knots defining the piecewise polynomial\r\n !! in the \\(y\\) direction.\r\n !! (same as in last call to [[db5ink]])\r\n real(wp),dimension(nz+kz),intent(in) :: tz !! sequence of knots defining the piecewise polynomial\r\n !! in the \\(z\\) direction.\r\n !! (same as in last call to [[db5ink]])\r\n real(wp),dimension(nq+kq),intent(in) :: tq !! sequence of knots defining the piecewise polynomial\r\n !! in the \\(q\\) direction.\r\n !! (same as in last call to [[db5ink]])\r\n real(wp),dimension(nr+kr),intent(in) :: tr !! sequence of knots defining the piecewise polynomial\r\n !! in the \\(r\\) direction.\r\n !! (same as in last call to [[db5ink]])\r\n real(wp),dimension(nx,ny,nz,nq,nr),intent(in) :: bcoef !! the b-spline coefficients computed by [[db5ink]].\r\n real(wp),intent(out) :: f !! interpolated value\r\n integer,intent(out) :: iflag !! status flag:\r\n !!\r\n !! * \\( = 0 \\) : no errors\r\n !! * \\( \\ne 0 \\) : error\r\n integer,intent(inout) :: inbvx !! initialization parameter which must be set\r\n !! to 1 the first time this routine is called,\r\n !! and must not be changed by the user.\r\n integer,intent(inout) :: inbvy !! initialization parameter which must be set\r\n !! to 1 the first time this routine is called,\r\n !! and must not be changed by the user.\r\n integer,intent(inout) :: inbvz !! initialization parameter which must be set\r\n !! to 1 the first time this routine is called,\r\n !! and must not be changed by the user.\r\n integer,intent(inout) :: inbvq !! initialization parameter which must be set\r\n !! to 1 the first time this routine is called,\r\n !! and must not be changed by the user.\r\n integer,intent(inout) :: inbvr !! initialization parameter which must be set\r\n !! to 1 the first time this routine is called,\r\n !! and must not be changed by the user.\r\n integer,intent(inout) :: iloy !! initialization parameter which must be set\r\n !! to 1 the first time this routine is called,\r\n !! and must not be changed by the user.\r\n integer,intent(inout) :: iloz !! initialization parameter which must be set\r\n !! to 1 the first time this routine is called,\r\n !! and must not be changed by the user.\r\n integer,intent(inout) :: iloq !! initialization parameter which must be set\r\n !! to 1 the first time this routine is called,\r\n !! and must not be changed by the user.\r\n integer,intent(inout) :: ilor !! initialization parameter which must be set\r\n !! to 1 the first time this routine is called,\r\n !! and must not be changed by the user.\r\n logical,intent(in),optional :: extrap !! if extrapolation is allowed\r\n !! (if not present, default is False)\r\n\r\n real(wp),dimension(ky,kz,kq,kr) :: temp1\r\n real(wp),dimension(kz,kq,kr) :: temp2\r\n real(wp),dimension(kq,kr) :: temp3\r\n real(wp),dimension(kr) :: temp4\r\n real(wp),dimension(3*max(kx,ky,kz,kq,kr)) :: work\r\n integer :: lefty, leftz, leftq, leftr, &\r\n kcoly, kcolz, kcolq, kcolr, j, k, q, r\r\n\r\n f = 0.0_wp\r\n\r\n iflag = check_value(xval,tx,1,extrap); if (iflag/=0) return\r\n iflag = check_value(yval,ty,2,extrap); if (iflag/=0) return\r\n iflag = check_value(zval,tz,3,extrap); if (iflag/=0) return\r\n iflag = check_value(qval,tq,4,extrap); if (iflag/=0) return\r\n iflag = check_value(rval,tr,5,extrap); if (iflag/=0) return\r\n\r\n call dintrv(ty,ny+ky,yval,iloy,lefty,iflag,extrap); if (iflag/=0) return\r\n call dintrv(tz,nz+kz,zval,iloz,leftz,iflag,extrap); if (iflag/=0) return\r\n call dintrv(tq,nq+kq,qval,iloq,leftq,iflag,extrap); if (iflag/=0) return\r\n call dintrv(tr,nr+kr,rval,ilor,leftr,iflag,extrap); if (iflag/=0) return\r\n\r\n iflag = 0\r\n\r\n ! x -> y, z, q, r\r\n kcolr = leftr - kr\r\n do r=1,kr\r\n kcolr = kcolr + 1\r\n kcolq = leftq - kq\r\n do q=1,kq\r\n kcolq = kcolq + 1\r\n kcolz = leftz - kz\r\n do k=1,kz\r\n kcolz = kcolz + 1\r\n kcoly = lefty - ky\r\n do j=1,ky\r\n kcoly = kcoly + 1\r\n call dbvalu(tx,bcoef(:,kcoly,kcolz,kcolq,kcolr),&\r\n nx,kx,idx,xval,inbvx,work,iflag,temp1(j,k,q,r),&\r\n extrap)\r\n if (iflag/=0) return\r\n end do\r\n end do\r\n end do\r\n end do\r\n\r\n ! y -> z, q, r\r\n kcoly = lefty - ky + 1\r\n do r=1,kr\r\n do q=1,kq\r\n do k=1,kz\r\n call dbvalu(ty(kcoly:),temp1(:,k,q,r),ky,ky,idy,yval,inbvy,&\r\n work,iflag,temp2(k,q,r),extrap)\r\n if (iflag/=0) return\r\n end do\r\n end do\r\n end do\r\n\r\n ! z -> q, r\r\n kcolz = leftz - kz + 1\r\n do r=1,kr\r\n do q=1,kq\r\n call dbvalu(tz(kcolz:),temp2(:,q,r),kz,kz,idz,zval,inbvz,&\r\n work,iflag,temp3(q,r),extrap)\r\n if (iflag/=0) return\r\n end do\r\n end do\r\n\r\n ! q -> r\r\n kcolq = leftq - kq + 1\r\n do r=1,kr\r\n call dbvalu(tq(kcolq:),temp3(:,r),kq,kq,idq,qval,inbvq,&\r\n work,iflag,temp4(r),extrap)\r\n if (iflag/=0) return\r\n end do\r\n\r\n ! r\r\n kcolr = leftr - kr + 1\r\n call dbvalu(tr(kcolr:),temp4,kr,kr,idr,rval,inbvr,work,iflag,f,extrap)\r\n\r\n end subroutine db5val\r\n!*****************************************************************************************\r\n\r\n!*****************************************************************************************\r\n!>\r\n! Determines the parameters of a function that interpolates\r\n! the six-dimensional gridded data:\r\n!\r\n! $$ [x(i),y(j),z(k),q(l),r(m),s(n),\\mathrm{fcn}(i,j,k,l,m,n)] $$\r\n!\r\n! for:\r\n!\r\n! $$ i=1,..,n_x, j=1,..,n_y, k=1,..,n_z, l=1,..,n_q, m=1,..,n_r, n=1,..,n_s $$\r\n!\r\n! the interpolating function and its derivatives may subsequently be evaluated\r\n! by the function [[db6val]].\r\n!\r\n! See [[db3ink]] header for more details.\r\n!\r\n!### History\r\n! * Jacob Williams, 2/24/2015 : Created this routine.\r\n\r\n pure subroutine db6ink(x,nx,y,ny,z,nz,q,nq,r,nr,s,ns,&\r\n fcn,&\r\n kx,ky,kz,kq,kr,ks,&\r\n iknot,&\r\n tx,ty,tz,tq,tr,ts,&\r\n bcoef,iflag)\r\n\r\n implicit none\r\n\r\n integer,intent(in) :: nx !! number of \\(x\\) abcissae ( \\( \\ge 3 \\) )\r\n integer,intent(in) :: ny !! number of \\(y\\) abcissae ( \\( \\ge 3 \\) )\r\n integer,intent(in) :: nz !! number of \\(z\\) abcissae ( \\( \\ge 3 \\) )\r\n integer,intent(in) :: nq !! number of \\(q\\) abcissae ( \\( \\ge 3 \\) )\r\n integer,intent(in) :: nr !! number of \\(r\\) abcissae ( \\( \\ge 3 \\) )\r\n integer,intent(in) :: ns !! number of \\(s\\) abcissae ( \\( \\ge 3 \\) )\r\n integer,intent(in) :: kx !! the order of spline pieces in \\(x\\)\r\n !! ( \\( 2 \\le k_x < n_x \\) )\r\n !! (order = polynomial degree + 1)\r\n integer,intent(in) :: ky !! the order of spline pieces in \\(y\\)\r\n !! ( \\( 2 \\le k_y < n_y \\) )\r\n !! (order = polynomial degree + 1)\r\n integer,intent(in) :: kz !! the order of spline pieces in \\(z\\)\r\n !! ( \\( 2 \\le k_z < n_z \\) )\r\n !! (order = polynomial degree + 1)\r\n integer,intent(in) :: kq !! the order of spline pieces in \\(q\\)\r\n !! ( \\( 2 \\le k_q < n_q \\) )\r\n !! (order = polynomial degree + 1)\r\n integer,intent(in) :: kr !! the order of spline pieces in \\(r\\)\r\n !! ( \\( 2 \\le k_r < n_r \\) )\r\n !! (order = polynomial degree + 1)\r\n integer,intent(in) :: ks !! the order of spline pieces in \\(s\\)\r\n !! ( \\( 2 \\le k_s < n_s \\) )\r\n !! (order = polynomial degree + 1)\r\n real(wp),dimension(:),intent(in) :: x !! `(nx)` array of \\(x\\) abcissae.\r\n !! must be strictly increasing.\r\n real(wp),dimension(:),intent(in) :: y !! `(ny)` array of \\(y\\) abcissae.\r\n !! must be strictly increasing.\r\n real(wp),dimension(:),intent(in) :: z !! `(nz)` array of \\(z\\) abcissae.\r\n !! must be strictly increasing.\r\n real(wp),dimension(:),intent(in) :: q !! `(nq)` array of \\(q\\) abcissae.\r\n !! must be strictly increasing.\r\n real(wp),dimension(:),intent(in) :: r !! `(nr)` array of \\(r\\) abcissae.\r\n !! must be strictly increasing.\r\n real(wp),dimension(:),intent(in) :: s !! `(ns)` array of \\(s\\) abcissae.\r\n !! must be strictly increasing.\r\n real(wp),dimension(:,:,:,:,:,:),intent(in) :: fcn !! `(nx,ny,nz,nq,nr,ns)` matrix of function values to\r\n !! interpolate. `fcn(i,j,k,q,r,s)` should contain the\r\n !! function value at the point\r\n !! (`x(i)`,`y(j)`,`z(k)`,`q(l)`,`r(m)`,`s(n)`)\r\n integer,intent(in) :: iknot !! knot sequence flag:\r\n !!\r\n !! * 0 = knot sequence chosen by [[db6ink]].\r\n !! * 1 = knot sequence chosen by user.\r\n real(wp),dimension(:),intent(inout) :: tx !! The `(nx+kx)` knots in the \\(x\\) direction for the\r\n !! spline interpolant.\r\n !!\r\n !! * f `iknot=0` these are chosen by [[db6ink]].\r\n !! * f `iknot=1` these are specified by the user.\r\n !!\r\n !! Must be non-decreasing.\r\n real(wp),dimension(:),intent(inout) :: ty !! The `(ny+ky)` knots in the \\(y\\) direction for the\r\n !! spline interpolant.\r\n !!\r\n !! * If `iknot=0` these are chosen by [[db6ink]].\r\n !! * If `iknot=1` these are specified by the user.\r\n !!\r\n !! Must be non-decreasing.\r\n real(wp),dimension(:),intent(inout) :: tz !! The `(nz+kz)` knots in the \\(z\\) direction for the\r\n !! spline interpolant.\r\n !!\r\n !! * If `iknot=0` these are chosen by [[db6ink]].\r\n !! * If `iknot=1` these are specified by the user.\r\n !!\r\n !! Must be non-decreasing.\r\n real(wp),dimension(:),intent(inout) :: tq !! The `(nq+kq)` knots in the \\(q\\) direction for the\r\n !! spline interpolant.\r\n !!\r\n !! * If `iknot=0` these are chosen by [[db6ink]].\r\n !! * If `iknot=1` these are specified by the user.\r\n !!\r\n !! Must be non-decreasing.\r\n real(wp),dimension(:),intent(inout) :: tr !! The `(nr+kr)` knots in the \\(r\\) direction for the\r\n !! spline interpolant.\r\n !!\r\n !! * If `iknot=0` these are chosen by [[db6ink]].\r\n !! * If `iknot=1` these are specified by the user.\r\n !!\r\n !! Must be non-decreasing.\r\n real(wp),dimension(:),intent(inout) :: ts !! The `(ns+ks)` knots in the \\(s\\) direction for the\r\n !! spline interpolant.\r\n !!\r\n !! * If `iknot=0` these are chosen by [[db6ink]].\r\n !! * If `iknot=1` these are specified by the user.\r\n !!\r\n !! Must be non-decreasing.\r\n real(wp),dimension(:,:,:,:,:,:),intent(out) :: bcoef !! `(nx,ny,nz,nq,nr,ns)` matrix of coefficients of the\r\n !! b-spline interpolant.\r\n integer,intent(out) :: iflag !! * 0 = successful execution.\r\n !! * 2 = `iknot` out of range.\r\n !! * 3 = `nx` out of range.\r\n !! * 4 = `kx` out of range.\r\n !! * 5 = `x` not strictly increasing.\r\n !! * 6 = `tx` not non-decreasing.\r\n !! * 7 = `ny` out of range.\r\n !! * 8 = `ky` out of range.\r\n !! * 9 = `y` not strictly increasing.\r\n !! * 10 = `ty` not non-decreasing.\r\n !! * 11 = `nz` out of range.\r\n !! * 12 = `kz` out of range.\r\n !! * 13 = `z` not strictly increasing.\r\n !! * 14 = `tz` not non-decreasing.\r\n !! * 15 = `nq` out of range.\r\n !! * 16 = `kq` out of range.\r\n !! * 17 = `q` not strictly increasing.\r\n !! * 18 = `tq` not non-decreasing.\r\n !! * 19 = `nr` out of range.\r\n !! * 20 = `kr` out of range.\r\n !! * 21 = `r` not strictly increasing.\r\n !! * 22 = `tr` not non-decreasing.\r\n !! * 23 = `ns` out of range.\r\n !! * 24 = `ks` out of range.\r\n !! * 25 = `s` not strictly increasing.\r\n !! * 26 = `ts` not non-decreasing.\r\n !! * 700 = `size(x) ` \\( \\ne \\) `size(fcn,1)`\r\n !! * 701 = `size(y) ` \\( \\ne \\) `size(fcn,2)`\r\n !! * 702 = `size(z) ` \\( \\ne \\) `size(fcn,3)`\r\n !! * 703 = `size(q) ` \\( \\ne \\) `size(fcn,4)`\r\n !! * 704 = `size(r) ` \\( \\ne \\) `size(fcn,5)`\r\n !! * 705 = `size(s) ` \\( \\ne \\) `size(fcn,6)`\r\n !! * 706 = `size(x) ` \\( \\ne \\) `nx`\r\n !! * 707 = `size(y) ` \\( \\ne \\) `ny`\r\n !! * 708 = `size(z) ` \\( \\ne \\) `nz`\r\n !! * 709 = `size(q) ` \\( \\ne \\) `nq`\r\n !! * 710 = `size(r) ` \\( \\ne \\) `nr`\r\n !! * 711 = `size(s) ` \\( \\ne \\) `ns`\r\n !! * 712 = `size(tx)` \\( \\ne \\) `nx+kx`\r\n !! * 713 = `size(ty)` \\( \\ne \\) `ny+ky`\r\n !! * 714 = `size(tz)` \\( \\ne \\) `nz+kz`\r\n !! * 715 = `size(tq)` \\( \\ne \\) `nq+kq`\r\n !! * 716 = `size(tr)` \\( \\ne \\) `nr+kr`\r\n !! * 717 = `size(ts)` \\( \\ne \\) `ns+ks`\r\n !! * 800 = `size(x) ` \\( \\ne \\) `size(bcoef,1)`\r\n !! * 801 = `size(y) ` \\( \\ne \\) `size(bcoef,2)`\r\n !! * 802 = `size(z) ` \\( \\ne \\) `size(bcoef,3)`\r\n !! * 803 = `size(q) ` \\( \\ne \\) `size(bcoef,4)`\r\n !! * 804 = `size(r) ` \\( \\ne \\) `size(bcoef,5)`\r\n !! * 805 = `size(s) ` \\( \\ne \\) `size(bcoef,6)`\r\n\r\n real(wp),dimension(nx*ny*nz*nq*nr*ns) :: temp\r\n real(wp),dimension(max( 2*kx*(nx+1),&\r\n 2*ky*(ny+1),&\r\n 2*kz*(nz+1),&\r\n 2*kq*(nq+1),&\r\n 2*kr*(nr+1),&\r\n 2*ks*(ns+1))) :: work\r\n logical :: status_ok\r\n\r\n ! check validity of input\r\n\r\n call check_inputs( iknot,&\r\n iflag,&\r\n nx=nx,ny=ny,nz=nz,nq=nq,nr=nr,ns=ns,&\r\n kx=kx,ky=ky,kz=kz,kq=kq,kr=kr,ks=ks,&\r\n x=x,y=y,z=z,q=q,r=r,s=s,&\r\n tx=tx,ty=ty,tz=tz,tq=tq,tr=tr,ts=ts,&\r\n f6=fcn,&\r\n bcoef6=bcoef,&\r\n status_ok=status_ok)\r\n\r\n if (status_ok) then\r\n\r\n ! choose knots\r\n\r\n if (iknot == 0) then\r\n call dbknot(x,nx,kx,tx)\r\n call dbknot(y,ny,ky,ty)\r\n call dbknot(z,nz,kz,tz)\r\n call dbknot(q,nq,kq,tq)\r\n call dbknot(r,nr,kr,tr)\r\n call dbknot(s,ns,ks,ts)\r\n end if\r\n\r\n ! construct b-spline coefficients\r\n\r\n call dbtpcf(x,nx,fcn, nx,ny*nz*nq*nr*ns,tx,kx,temp, work,iflag)\r\n if (iflag==0) call dbtpcf(y,ny,temp, ny,nx*nz*nq*nr*ns,ty,ky,bcoef,work,iflag)\r\n if (iflag==0) call dbtpcf(z,nz,bcoef,nz,nx*ny*nq*nr*ns,tz,kz,temp, work,iflag)\r\n if (iflag==0) call dbtpcf(q,nq,temp, nq,nx*ny*nz*nr*ns,tq,kq,bcoef,work,iflag)\r\n if (iflag==0) call dbtpcf(r,nr,bcoef,nr,nx*ny*nz*nq*ns,tr,kr,temp, work,iflag)\r\n if (iflag==0) call dbtpcf(s,ns,temp, ns,nx*ny*nz*nq*nr,ts,ks,bcoef,work,iflag)\r\n\r\n end if\r\n\r\n end subroutine db6ink\r\n!*****************************************************************************************\r\n\r\n!*****************************************************************************************\r\n!>\r\n! Evaluates the tensor product piecewise polynomial\r\n! interpolant constructed by the routine [[db6ink]] or one of its\r\n! derivatives at the point (`xval`,`yval`,`zval`,`qval`,`rval`,`sval`).\r\n!\r\n! To evaluate the\r\n! interpolant itself, set `idx=idy=idz=idq=idr=ids=0`, to evaluate the first\r\n! partial with respect to `x`, set `idx=1,idy=idz=idq=idr=ids=0`, and so on.\r\n!\r\n! See [[db3val]] header for more information.\r\n!\r\n!### History\r\n! * Jacob Williams, 2/24/2015 : Created this routine.\r\n\r\n pure subroutine db6val(xval,yval,zval,qval,rval,sval,&\r\n idx,idy,idz,idq,idr,ids,&\r\n tx,ty,tz,tq,tr,ts,&\r\n nx,ny,nz,nq,nr,ns,&\r\n kx,ky,kz,kq,kr,ks,&\r\n bcoef,f,iflag,&\r\n inbvx,inbvy,inbvz,inbvq,inbvr,inbvs,&\r\n iloy,iloz,iloq,ilor,ilos,extrap)\r\n\r\n implicit none\r\n\r\n integer,intent(in) :: idx !! \\(x\\) derivative of piecewise polynomial to evaluate.\r\n integer,intent(in) :: idy !! \\(y\\) derivative of piecewise polynomial to evaluate.\r\n integer,intent(in) :: idz !! \\(z\\) derivative of piecewise polynomial to evaluate.\r\n integer,intent(in) :: idq !! \\(q\\) derivative of piecewise polynomial to evaluate.\r\n integer,intent(in) :: idr !! \\(r\\) derivative of piecewise polynomial to evaluate.\r\n integer,intent(in) :: ids !! \\(s\\) derivative of piecewise polynomial to evaluate.\r\n integer,intent(in) :: nx !! the number of interpolation points in \\(x\\).\r\n !! (same as in last call to [[db6ink]])\r\n integer,intent(in) :: ny !! the number of interpolation points in \\(y\\).\r\n !! (same as in last call to [[db6ink]])\r\n integer,intent(in) :: nz !! the number of interpolation points in \\(z\\).\r\n !! (same as in last call to [[db6ink]])\r\n integer,intent(in) :: nq !! the number of interpolation points in \\(q\\).\r\n !! (same as in last call to [[db6ink]])\r\n integer,intent(in) :: nr !! the number of interpolation points in \\(r\\).\r\n !! (same as in last call to [[db6ink]])\r\n integer,intent(in) :: ns !! the number of interpolation points in \\(s\\).\r\n !! (same as in last call to [[db6ink]])\r\n integer,intent(in) :: kx !! order of polynomial pieces in \\(x\\).\r\n !! (same as in last call to [[db6ink]])\r\n integer,intent(in) :: ky !! order of polynomial pieces in \\(y\\).\r\n !! (same as in last call to [[db6ink]])\r\n integer,intent(in) :: kz !! order of polynomial pieces in \\(z\\).\r\n !! (same as in last call to [[db6ink]])\r\n integer,intent(in) :: kq !! order of polynomial pieces in \\(q\\).\r\n !! (same as in last call to [[db6ink]])\r\n integer,intent(in) :: kr !! order of polynomial pieces in \\(r\\).\r\n !! (same as in last call to [[db6ink]])\r\n integer,intent(in) :: ks !! order of polynomial pieces in \\(s\\).\r\n !! (same as in last call to [[db6ink]])\r\n real(wp),intent(in) :: xval !! \\(x\\) coordinate of evaluation point.\r\n real(wp),intent(in) :: yval !! \\(y\\) coordinate of evaluation point.\r\n real(wp),intent(in) :: zval !! \\(z\\) coordinate of evaluation point.\r\n real(wp),intent(in) :: qval !! \\(q\\) coordinate of evaluation point.\r\n real(wp),intent(in) :: rval !! \\(r\\) coordinate of evaluation point.\r\n real(wp),intent(in) :: sval !! \\(s\\) coordinate of evaluation point.\r\n real(wp),dimension(nx+kx),intent(in) :: tx !! sequence of knots defining the piecewise polynomial\r\n !! in the \\(x\\) direction.\r\n !! (same as in last call to [[db6ink]])\r\n real(wp),dimension(ny+ky),intent(in) :: ty !! sequence of knots defining the piecewise polynomial\r\n !! in the \\(y\\) direction.\r\n !! (same as in last call to [[db6ink]])\r\n real(wp),dimension(nz+kz),intent(in) :: tz !! sequence of knots defining the piecewise polynomial\r\n !! in the \\(z\\) direction.\r\n !! (same as in last call to [[db6ink]])\r\n real(wp),dimension(nq+kq),intent(in) :: tq !! sequence of knots defining the piecewise polynomial\r\n !! in the \\(q\\) direction.\r\n !! (same as in last call to [[db6ink]])\r\n real(wp),dimension(nr+kr),intent(in) :: tr !! sequence of knots defining the piecewise polynomial\r\n !! in the \\(r\\) direction.\r\n !! (same as in last call to [[db6ink]])\r\n real(wp),dimension(ns+ks),intent(in) :: ts !! sequence of knots defining the piecewise polynomial\r\n !! in the \\(s\\) direction.\r\n !! (same as in last call to [[db6ink]])\r\n real(wp),dimension(nx,ny,nz,nq,nr,ns),intent(in) :: bcoef !! the b-spline coefficients computed by [[db6ink]].\r\n real(wp),intent(out) :: f !! interpolated value\r\n integer,intent(out) :: iflag !! status flag:\r\n !!\r\n !! * \\( = 0 \\) : no errors\r\n !! * \\( \\ne 0 \\) : error\r\n integer,intent(inout) :: inbvx !! initialization parameter which must be set\r\n !! to 1 the first time this routine is called,\r\n !! and must not be changed by the user.\r\n integer,intent(inout) :: inbvy !! initialization parameter which must be set\r\n !! to 1 the first time this routine is called,\r\n !! and must not be changed by the user.\r\n integer,intent(inout) :: inbvz !! initialization parameter which must be set\r\n !! to 1 the first time this routine is called,\r\n !! and must not be changed by the user.\r\n integer,intent(inout) :: inbvq !! initialization parameter which must be set\r\n !! to 1 the first time this routine is called,\r\n !! and must not be changed by the user.\r\n integer,intent(inout) :: inbvr !! initialization parameter which must be set\r\n !! to 1 the first time this routine is called,\r\n !! and must not be changed by the user.\r\n integer,intent(inout) :: inbvs !! initialization parameter which must be set\r\n !! to 1 the first time this routine is called,\r\n !! and must not be changed by the user.\r\n integer,intent(inout) :: iloy !! initialization parameter which must be set\r\n !! to 1 the first time this routine is called,\r\n !! and must not be changed by the user.\r\n integer,intent(inout) :: iloz !! initialization parameter which must be set\r\n !! to 1 the first time this routine is called,\r\n !! and must not be changed by the user.\r\n integer,intent(inout) :: iloq !! initialization parameter which must be set\r\n !! to 1 the first time this routine is called,\r\n !! and must not be changed by the user.\r\n integer,intent(inout) :: ilor !! initialization parameter which must be set\r\n !! to 1 the first time this routine is called,\r\n !! and must not be changed by the user.\r\n integer,intent(inout) :: ilos !! initialization parameter which must be set\r\n !! to 1 the first time this routine is called,\r\n !! and must not be changed by the user.\r\n logical,intent(in),optional :: extrap !! if extrapolation is allowed\r\n !! (if not present, default is False)\r\n\r\n real(wp),dimension(ky,kz,kq,kr,ks) :: temp1\r\n real(wp),dimension(kz,kq,kr,ks) :: temp2\r\n real(wp),dimension(kq,kr,ks) :: temp3\r\n real(wp),dimension(kr,ks) :: temp4\r\n real(wp),dimension(ks) :: temp5\r\n real(wp),dimension(3*max(kx,ky,kz,kq,kr,ks)) :: work\r\n\r\n integer :: lefty,leftz,leftq,leftr,lefts,&\r\n kcoly,kcolz,kcolq,kcolr,kcols,&\r\n j,k,q,r,s\r\n\r\n f = 0.0_wp\r\n\r\n iflag = check_value(xval,tx,1,extrap); if (iflag/=0) return\r\n iflag = check_value(yval,ty,2,extrap); if (iflag/=0) return\r\n iflag = check_value(zval,tz,3,extrap); if (iflag/=0) return\r\n iflag = check_value(qval,tq,4,extrap); if (iflag/=0) return\r\n iflag = check_value(rval,tr,5,extrap); if (iflag/=0) return\r\n iflag = check_value(sval,ts,6,extrap); if (iflag/=0) return\r\n\r\n call dintrv(ty,ny+ky,yval,iloy,lefty,iflag,extrap); if (iflag/=0) return\r\n call dintrv(tz,nz+kz,zval,iloz,leftz,iflag,extrap); if (iflag/=0) return\r\n call dintrv(tq,nq+kq,qval,iloq,leftq,iflag,extrap); if (iflag/=0) return\r\n call dintrv(tr,nr+kr,rval,ilor,leftr,iflag,extrap); if (iflag/=0) return\r\n call dintrv(ts,ns+ks,sval,ilos,lefts,iflag,extrap); if (iflag/=0) return\r\n\r\n iflag = 0\r\n\r\n ! x -> y, z, q, r, s\r\n kcols = lefts - ks\r\n do s=1,ks\r\n kcols = kcols + 1\r\n kcolr = leftr - kr\r\n do r=1,kr\r\n kcolr = kcolr + 1\r\n kcolq = leftq - kq\r\n do q=1,kq\r\n kcolq = kcolq + 1\r\n kcolz = leftz - kz\r\n do k=1,kz\r\n kcolz = kcolz + 1\r\n kcoly = lefty - ky\r\n do j=1,ky\r\n kcoly = kcoly + 1\r\n call dbvalu(tx,bcoef(:,kcoly,kcolz,kcolq,kcolr,kcols),&\r\n nx,kx,idx,xval,inbvx,work,iflag,&\r\n temp1(j,k,q,r,s),extrap)\r\n if (iflag/=0) return\r\n end do\r\n end do\r\n end do\r\n end do\r\n end do\r\n\r\n ! y -> z, q, r, s\r\n kcoly = lefty - ky + 1\r\n do s=1,ks\r\n do r=1,kr\r\n do q=1,kq\r\n do k=1,kz\r\n call dbvalu(ty(kcoly:),temp1(:,k,q,r,s),&\r\n ky,ky,idy,yval,inbvy,work,iflag,&\r\n temp2(k,q,r,s),extrap)\r\n if (iflag/=0) return\r\n end do\r\n end do\r\n end do\r\n end do\r\n\r\n ! z -> q, r, s\r\n kcolz = leftz - kz + 1\r\n do s=1,ks\r\n do r=1,kr\r\n do q=1,kq\r\n call dbvalu(tz(kcolz:),temp2(:,q,r,s),&\r\n kz,kz,idz,zval,inbvz,work,iflag,&\r\n temp3(q,r,s),extrap)\r\n if (iflag/=0) return\r\n end do\r\n end do\r\n end do\r\n\r\n ! q -> r, s\r\n kcolq = leftq - kq + 1\r\n do s=1,ks\r\n do r=1,kr\r\n call dbvalu(tq(kcolq:),temp3(:,r,s),&\r\n kq,kq,idq,qval,inbvq,work,iflag,&\r\n temp4(r,s),extrap)\r\n if (iflag/=0) return\r\n end do\r\n end do\r\n\r\n ! r -> s\r\n kcolr = leftr - kr + 1\r\n do s=1,ks\r\n call dbvalu(tr(kcolr:),temp4(:,s),&\r\n kr,kr,idr,rval,inbvr,work,iflag,&\r\n temp5(s),extrap)\r\n if (iflag/=0) return\r\n end do\r\n\r\n ! s\r\n kcols = lefts - ks + 1\r\n call dbvalu(ts(kcols:),temp5,ks,ks,ids,sval,inbvs,work,iflag,f,extrap)\r\n\r\n end subroutine db6val\r\n!*****************************************************************************************\r\n\r\n!*****************************************************************************************\r\n!>\r\n! Checks if the value is withing the range of the knot vectors.\r\n! This is called by the various `db*val` routines.\r\n\r\n pure function check_value(x,t,i,extrap) result(iflag)\r\n\r\n implicit none\r\n\r\n integer :: iflag !! returns 0 if value is OK, otherwise returns `600+i`\r\n real(wp),intent(in) :: x !! the value to check\r\n integer,intent(in) :: i !! 1=x, 2=y, 3=z, 4=q, 5=r, 6=s\r\n real(wp),dimension(:),intent(in) :: t !! the knot vector\r\n logical,intent(in),optional :: extrap !! if extrapolation is allowed\r\n !! (if not present, default is False)\r\n\r\n logical :: allow_extrapolation !! if extrapolation is allowed\r\n\r\n if (present(extrap)) then\r\n allow_extrapolation = extrap\r\n else\r\n allow_extrapolation = .false.\r\n end if\r\n\r\n if (allow_extrapolation) then\r\n ! in this case all values are OK\r\n iflag = 0\r\n else\r\n if (xt(size(t))) then\r\n iflag = 600 + i ! value out of bounds (601, 602, etc.)\r\n else\r\n iflag = 0\r\n end if\r\n end if\r\n\r\n end function check_value\r\n!*****************************************************************************************\r\n\r\n!*****************************************************************************************\r\n!>\r\n! Check the validity of the inputs to the `db*ink` routines.\r\n! Prints warning message if there is an error,\r\n! and also sets iflag and status_ok.\r\n!\r\n! Supports up to 6D: `x`,`y`,`z`,`q`,`r`,`s`\r\n!\r\n!### Notes\r\n!\r\n! The code is new, but the logic is based on the original\r\n! logic in the CMLIB routines `db2ink` and `db3ink`.\r\n!\r\n!### History\r\n! * Jacob Williams, 2/24/2015 : Created this routine.\r\n\r\n pure subroutine check_inputs(iknot,&\r\n iflag,&\r\n nx,ny,nz,nq,nr,ns,&\r\n kx,ky,kz,kq,kr,ks,&\r\n x,y,z,q,r,s,&\r\n tx,ty,tz,tq,tr,ts,&\r\n f1,f2,f3,f4,f5,f6,&\r\n bcoef1,bcoef2,bcoef3,bcoef4,bcoef5,bcoef6,&\r\n status_ok)\r\n\r\n implicit none\r\n\r\n integer,intent(in) :: iknot !! = 0 if the `INK` routine is computing the knots.\r\n integer,intent(out) :: iflag\r\n integer,intent(in),optional :: nx,ny,nz,nq,nr,ns\r\n integer,intent(in),optional :: kx,ky,kz,kq,kr,ks\r\n real(wp),dimension(:),intent(in),optional :: x,y,z,q,r,s\r\n real(wp),dimension(:),intent(in),optional :: tx,ty,tz,tq,tr,ts\r\n real(wp),dimension(:),intent(in),optional :: f1,bcoef1\r\n real(wp),dimension(:,:),intent(in),optional :: f2,bcoef2\r\n real(wp),dimension(:,:,:),intent(in),optional :: f3,bcoef3\r\n real(wp),dimension(:,:,:,:),intent(in),optional :: f4,bcoef4\r\n real(wp),dimension(:,:,:,:,:),intent(in),optional :: f5,bcoef5\r\n real(wp),dimension(:,:,:,:,:,:),intent(in),optional :: f6,bcoef6\r\n logical,intent(out) :: status_ok\r\n\r\n logical :: error\r\n\r\n status_ok = .false.\r\n\r\n if ((iknot < 0) .or. (iknot > 1)) then\r\n\r\n iflag = 2 ! iknot is out of range\r\n\r\n else\r\n\r\n call check('x',nx,kx,x,tx,[3, 4, 5, 6,706,712],iflag,error); if (error) return\r\n call check('y',ny,ky,y,ty,[7, 8, 9,10,707,713],iflag,error); if (error) return\r\n call check('z',nz,kz,z,tz,[11,12,13,14,708,714],iflag,error); if (error) return\r\n call check('q',nq,kq,q,tq,[15,16,17,18,709,715],iflag,error); if (error) return\r\n call check('r',nr,kr,r,tr,[19,20,21,22,710,716],iflag,error); if (error) return\r\n call check('s',ns,ks,s,ts,[23,24,25,26,711,717],iflag,error); if (error) return\r\n\r\n if (present(x) .and. present(f1) .and. present(bcoef1)) then\r\n if (size(x)/=size(f1,1)) then; iflag = 700; return; end if\r\n if (size(x)/=size(bcoef1,1)) then; iflag = 800; return; end if\r\n end if\r\n if (present(x) .and. present(y) .and. present(f2) .and. present(bcoef2)) then\r\n if (size(x)/=size(f2,1)) then; iflag = 700; return; end if\r\n if (size(y)/=size(f2,2)) then; iflag = 701; return; end if\r\n if (size(x)/=size(bcoef2,1)) then; iflag = 800; return; end if\r\n if (size(y)/=size(bcoef2,2)) then; iflag = 801; return; end if\r\n end if\r\n if (present(x) .and. present(y) .and. present(z) .and. present(f3) .and. &\r\n present(bcoef3)) then\r\n if (size(x)/=size(f3,1)) then; iflag = 700; return; end if\r\n if (size(y)/=size(f3,2)) then; iflag = 701; return; end if\r\n if (size(z)/=size(f3,3)) then; iflag = 702; return; end if\r\n if (size(x)/=size(bcoef3,1)) then; iflag = 800; return; end if\r\n if (size(y)/=size(bcoef3,2)) then; iflag = 801; return; end if\r\n if (size(z)/=size(bcoef3,3)) then; iflag = 802; return; end if\r\n end if\r\n if (present(x) .and. present(y) .and. present(z) .and. present(q) .and. &\r\n present(f4) .and. present(bcoef4)) then\r\n if (size(x)/=size(f4,1)) then; iflag = 700; return; end if\r\n if (size(y)/=size(f4,2)) then; iflag = 701; return; end if\r\n if (size(z)/=size(f4,3)) then; iflag = 702; return; end if\r\n if (size(q)/=size(f4,4)) then; iflag = 703; return; end if\r\n if (size(x)/=size(bcoef4,1)) then; iflag = 800; return; end if\r\n if (size(y)/=size(bcoef4,2)) then; iflag = 801; return; end if\r\n if (size(z)/=size(bcoef4,3)) then; iflag = 802; return; end if\r\n if (size(q)/=size(bcoef4,4)) then; iflag = 803; return; end if\r\n end if\r\n if (present(x) .and. present(y) .and. present(z) .and. present(q) .and. &\r\n present(r) .and. present(f5) .and. present(bcoef5)) then\r\n if (size(x)/=size(f5,1)) then; iflag = 700; return; end if\r\n if (size(y)/=size(f5,2)) then; iflag = 701; return; end if\r\n if (size(z)/=size(f5,3)) then; iflag = 702; return; end if\r\n if (size(q)/=size(f5,4)) then; iflag = 703; return; end if\r\n if (size(r)/=size(f5,5)) then; iflag = 704; return; end if\r\n if (size(x)/=size(bcoef5,1)) then; iflag = 800; return; end if\r\n if (size(y)/=size(bcoef5,2)) then; iflag = 801; return; end if\r\n if (size(z)/=size(bcoef5,3)) then; iflag = 802; return; end if\r\n if (size(q)/=size(bcoef5,4)) then; iflag = 803; return; end if\r\n if (size(r)/=size(bcoef5,5)) then; iflag = 804; return; end if\r\n end if\r\n if (present(x) .and. present(y) .and. present(z) .and. present(q) .and. &\r\n present(r) .and. present(s) .and. present(f6) .and. present(bcoef6)) then\r\n if (size(x)/=size(f6,1)) then; iflag = 700; return; end if\r\n if (size(y)/=size(f6,2)) then; iflag = 701; return; end if\r\n if (size(z)/=size(f6,3)) then; iflag = 702; return; end if\r\n if (size(q)/=size(f6,4)) then; iflag = 703; return; end if\r\n if (size(r)/=size(f6,5)) then; iflag = 704; return; end if\r\n if (size(s)/=size(f6,6)) then; iflag = 705; return; end if\r\n if (size(x)/=size(bcoef6,1)) then; iflag = 800; return; end if\r\n if (size(y)/=size(bcoef6,2)) then; iflag = 801; return; end if\r\n if (size(z)/=size(bcoef6,3)) then; iflag = 802; return; end if\r\n if (size(q)/=size(bcoef6,4)) then; iflag = 803; return; end if\r\n if (size(r)/=size(bcoef6,5)) then; iflag = 804; return; end if\r\n if (size(s)/=size(bcoef6,6)) then; iflag = 805; return; end if\r\n end if\r\n\r\n status_ok = .true.\r\n iflag = 0\r\n\r\n end if\r\n\r\n contains\r\n\r\n pure subroutine check(s,n,k,x,t,ierrs,iflag,error) !! check `t`,`x`,`n`,`k` for validity\r\n\r\n implicit none\r\n\r\n character(len=1),intent(in) :: s !! coordinate string: 'x','y','z','q','r','s'\r\n integer,intent(in) ,optional :: n !! size of `x`\r\n integer,intent(in) ,optional :: k !! order\r\n real(wp),dimension(:),intent(in),optional :: x !! abcissae vector\r\n real(wp),dimension(:),intent(in),optional :: t !! knot vector `size(n+k)`\r\n integer,dimension(:),intent(in) :: ierrs !! int error codes for `n`,`k`,`x`,`t`,\r\n !! `size(x)`,`size(t)` checks\r\n integer,intent(out) :: iflag !! status return code\r\n logical,intent(out) :: error !! true if there was an error\r\n\r\n if (present(n) .and. present(k) .and. present(x) .and. present(t)) then\r\n call check_n('n'//s,n,x,[ierrs(1),ierrs(5)],iflag,error); if (error) return\r\n call check_k('k'//s,k,n,ierrs(2),iflag,error); if (error) return\r\n call check_x(s,n,x,ierrs(3),iflag,error); if (error) return\r\n if (iknot /= 0) then\r\n call check_t('t'//s,n,k,t,[ierrs(4),ierrs(6)],iflag,error); if (error) return\r\n end if\r\n end if\r\n\r\n end subroutine check\r\n\r\n pure subroutine check_n(s,n,x,ierr,iflag,error)\r\n\r\n implicit none\r\n\r\n character(len=*),intent(in) :: s\r\n integer,intent(in) :: n\r\n real(wp),dimension(:),intent(in):: x !! abcissae vector\r\n integer,dimension(2),intent(in) :: ierr !! [n<3 check, size(x)==n check]\r\n integer,intent(out) :: iflag !! status return code\r\n logical,intent(out) :: error\r\n\r\n if (n < 3) then\r\n iflag = ierr(1)\r\n error = .true.\r\n else\r\n if (size(x)/=n) then\r\n iflag = ierr(2)\r\n error = .true.\r\n else\r\n error = .false.\r\n end if\r\n end if\r\n\r\n end subroutine check_n\r\n\r\n pure subroutine check_k(s,k,n,ierr,iflag,error)\r\n\r\n implicit none\r\n\r\n character(len=*),intent(in) :: s\r\n integer,intent(in) :: k\r\n integer,intent(in) :: n\r\n integer,intent(in) :: ierr\r\n integer,intent(out) :: iflag !! status return code\r\n logical,intent(out) :: error\r\n\r\n if ((k < 2) .or. (k >= n)) then\r\n iflag = ierr\r\n error = .true.\r\n else\r\n error = .false.\r\n end if\r\n\r\n end subroutine check_k\r\n\r\n pure subroutine check_x(s,n,x,ierr,iflag,error)\r\n\r\n implicit none\r\n\r\n character(len=*),intent(in) :: s\r\n integer,intent(in) :: n\r\n real(wp),dimension(:),intent(in) :: x\r\n integer,intent(in) :: ierr\r\n integer,intent(out) :: iflag !! status return code\r\n logical,intent(out) :: error\r\n\r\n integer :: i\r\n\r\n error = .true.\r\n do i=2,n\r\n if (x(i) <= x(i-1)) then\r\n iflag = ierr\r\n return\r\n end if\r\n end do\r\n error = .false.\r\n\r\n end subroutine check_x\r\n\r\n pure subroutine check_t(s,n,k,t,ierr,iflag,error)\r\n\r\n implicit none\r\n\r\n character(len=*),intent(in) :: s\r\n integer,intent(in) :: n\r\n integer,intent(in) :: k\r\n real(wp),dimension(:),intent(in) :: t\r\n integer,dimension(2),intent(in) :: ierr !! [non-decreasing check, size check]\r\n integer,intent(out) :: iflag !! status return code\r\n logical,intent(out) :: error\r\n\r\n integer :: i\r\n\r\n error = .true.\r\n\r\n if (size(t)/=(n+k)) then\r\n iflag = ierr(2)\r\n return\r\n end if\r\n\r\n do i=2,n + k\r\n if (t(i) < t(i-1)) then\r\n iflag = ierr(1)\r\n return\r\n end if\r\n end do\r\n error = .false.\r\n\r\n end subroutine check_t\r\n\r\n end subroutine check_inputs\r\n!*****************************************************************************************\r\n\r\n!*****************************************************************************************\r\n!>\r\n! dbknot chooses a knot sequence for interpolation of order k at the\r\n! data points x(i), i=1,..,n. the n+k knots are placed in the array\r\n! t. k knots are placed at each endpoint and not-a-knot end\r\n! conditions are used. the remaining knots are placed at data points\r\n! if n is even and between data points if n is odd. the rightmost\r\n! knot is shifted slightly to the right to insure proper interpolation\r\n! at x(n) (see page 350 of the reference).\r\n!\r\n!### History\r\n! * Jacob Williams, 2/24/2015 : Refactored this routine.\r\n\r\n pure subroutine dbknot(x,n,k,t)\r\n\r\n implicit none\r\n\r\n integer,intent(in) :: n\r\n integer,intent(in) :: k\r\n real(wp),dimension(n),intent(in) :: x\r\n real(wp),dimension(:),intent(out) :: t\r\n\r\n integer :: i, j, ipj, npj, ip1, jstrt\r\n real(wp) :: rnot\r\n\r\n !put k knots at each endpoint\r\n !(shift right endpoints slightly -- see pg 350 of reference)\r\n rnot = x(n) + 0.1_wp*( x(n)-x(n-1) )\r\n do j=1,k\r\n t(j) = x(1)\r\n npj = n + j\r\n t(npj) = rnot\r\n end do\r\n\r\n !distribute remaining knots\r\n\r\n if (mod(k,2) == 1) then\r\n\r\n !case of odd k -- knots between data points\r\n\r\n i = (k-1)/2 - k\r\n ip1 = i + 1\r\n jstrt = k + 1\r\n do j=jstrt,n\r\n ipj = i + j\r\n t(j) = 0.5_wp*( x(ipj) + x(ipj+1) )\r\n end do\r\n\r\n else\r\n\r\n !case of even k -- knots at data points\r\n\r\n i = (k/2) - k\r\n jstrt = k+1\r\n do j=jstrt,n\r\n ipj = i + j\r\n t(j) = x(ipj)\r\n end do\r\n\r\n end if\r\n\r\n end subroutine dbknot\r\n!*****************************************************************************************\r\n\r\n!*****************************************************************************************\r\n!>\r\n! dbtpcf computes b-spline interpolation coefficients for nf sets\r\n! of data stored in the columns of the array fcn. the b-spline\r\n! coefficients are stored in the rows of bcoef however.\r\n! each interpolation is based on the n abcissa stored in the\r\n! array x, and the n+k knots stored in the array t. the order\r\n! of each interpolation is k.\r\n!\r\n!### History\r\n! * Jacob Williams, 2/24/2015 : Refactored this routine.\r\n\r\n pure subroutine dbtpcf(x,n,fcn,ldf,nf,t,k,bcoef,work,iflag)\r\n\r\n integer,intent(in) :: n\r\n integer,intent(in) :: nf\r\n integer,intent(in) :: ldf\r\n integer,intent(in) :: k\r\n real(wp),dimension(n),intent(in) :: x\r\n real(wp),dimension(ldf,nf),intent(in) :: fcn\r\n real(wp),dimension(*),intent(in) :: t\r\n real(wp),dimension(nf,n),intent(out) :: bcoef\r\n real(wp),dimension(*),intent(out) :: work !! work array of size >= `2*k*(n+1)`\r\n integer,intent(out) :: iflag !! 0: no errors\r\n !! 301: n should be >0\r\n\r\n integer :: i, j, m1, m2, iq, iw\r\n\r\n ! check for null input\r\n\r\n if (nf > 0) then\r\n\r\n ! partition work array\r\n m1 = k - 1\r\n m2 = m1 + k\r\n iq = 1 + n\r\n iw = iq + m2*n+1\r\n\r\n ! compute b-spline coefficients\r\n\r\n ! first data set\r\n\r\n call dbintk(x,fcn,t,n,k,work,work(iq),work(iw),iflag)\r\n if (iflag == 0) then\r\n do i=1,n\r\n bcoef(1,i) = work(i)\r\n end do\r\n\r\n ! all remaining data sets by back-substitution\r\n\r\n if (nf == 1) return\r\n do j=2,nf\r\n do i=1,n\r\n work(i) = fcn(i,j)\r\n end do\r\n call dbnslv(work(iq),m2,n,m1,m1,work)\r\n do i=1,n\r\n bcoef(j,i) = work(i)\r\n end do\r\n end do\r\n end if\r\n\r\n else\r\n !write(error_unit,'(A)') 'dbtpcf - n should be >0'\r\n iflag = 301\r\n end if\r\n\r\n end subroutine dbtpcf\r\n!*****************************************************************************************\r\n\r\n!*****************************************************************************************\r\n!>\r\n! dbintk produces the b-spline coefficients, bcoef, of the\r\n! b-spline of order k with knots t(i), i=1,...,n+k, which\r\n! takes on the value y(i) at x(i), i=1,...,n. the spline or\r\n! any of its derivatives can be evaluated by calls to [[dbvalu]].\r\n!\r\n! the i-th equation of the linear system a*bcoef = b for the\r\n! coefficients of the interpolant enforces interpolation at\r\n! x(i), i=1,...,n. hence, b(i) = y(i), for all i, and a is\r\n! a band matrix with 2k-1 bands if a is invertible. the matrix\r\n! a is generated row by row and stored, diagonal by diagonal,\r\n! in the rows of q, with the main diagonal going into row k.\r\n! the banded system is then solved by a call to dbnfac (which\r\n! constructs the triangular factorization for a and stores it\r\n! again in q), followed by a call to dbnslv (which then\r\n! obtains the solution bcoef by substitution). dbnfac does no\r\n! pivoting, since the total positivity of the matrix a makes\r\n! this unnecessary. the linear system to be solved is\r\n! (theoretically) invertible if and only if\r\n! t(i) < x(i) < t(i+k), for all i.\r\n! equality is permitted on the left for i=1 and on the right\r\n! for i=n when k knots are used at x(1) or x(n). otherwise,\r\n! violation of this condition is certain to lead to an error.\r\n!\r\n!# Error conditions\r\n!\r\n! * improper input\r\n! * singular system of equations\r\n!\r\n!### History\r\n! * splint written by carl de boor [5]\r\n! * dbintk author: amos, d. e., (snla) : date written 800901\r\n! * revision date 820801\r\n! * 000330 modified array declarations. (jec)\r\n! * Jacob Williams, 5/10/2015 : converted to free-form Fortran.\r\n\r\n pure subroutine dbintk(x,y,t,n,k,bcoef,q,work,iflag)\r\n\r\n implicit none\r\n\r\n integer,intent(in) :: n !! number of data points, n >= k\r\n real(wp),dimension(n),intent(in) :: x !! vector of length n containing data point abscissa\r\n !! in strictly increasing order.\r\n real(wp),dimension(n),intent(in) :: y !! corresponding vector of length n containing data\r\n !! point ordinates.\r\n real(wp),dimension(*),intent(in) :: t !! knot vector of length n+k\r\n !! since t(1),..,t(k) <= x(1) and t(n+1),..,t(n+k)\r\n !! >= x(n), this leaves only n-k knots (not\r\n !! necessarily x(i) values) interior to (x(1),x(n))\r\n integer,intent(in) :: k !! order of the spline, k >= 1\r\n real(wp),dimension(n),intent(out) :: bcoef !! a vector of length n containing the b-spline coefficients\r\n real(wp),dimension(*),intent(out) :: q !! a work vector of length (2*k-1)*n, containing\r\n !! the triangular factorization of the coefficient\r\n !! matrix of the linear system being solved. the\r\n !! coefficients for the interpolant of an\r\n !! additional data set (x(i),yy(i)), i=1,...,n\r\n !! with the same abscissa can be obtained by loading\r\n !! yy into bcoef and then executing\r\n !! call dbnslv(q,2k-1,n,k-1,k-1,bcoef)\r\n real(wp),dimension(*),intent(out) :: work !! work vector of length 2*k\r\n integer,intent(out) :: iflag !! * 0: no errors.\r\n !! * 100: k does not satisfy k>=1.\r\n !! * 101: n does not satisfy n>=k.\r\n !! * 102: x(i) does not satisfy x(i)=1'\r\n iflag = 100\r\n return\r\n end if\r\n\r\n if (n=k'\r\n iflag = 101\r\n return\r\n end if\r\n\r\n jj = n - 1\r\n if (jj/=0) then\r\n do i=1,jj\r\n if (x(i)>=x(i+1)) then\r\n !write(error_unit,'(A)') 'dbintk - x(i) does not satisfy x(i)=ilp1mx) exit\r\n end do\r\n if (.not. found) then\r\n left = left - 1\r\n if (xi>t(left+1)) then\r\n !write(error_unit,'(A)') 'dbintk - some abscissa was not in the support of the'//&\r\n ! ' corresponding basis function and the system is singular'\r\n iflag = 103\r\n return\r\n end if\r\n end if\r\n ! the i-th equation enforces interpolation at xi, hence\r\n ! a(i,j) = b(j,k,t)(xi), all j. only the k entries with j =\r\n ! left-k+1,...,left actually might be nonzero. these k numbers\r\n ! are returned, in bcoef (used for temp.storage here), by the\r\n ! following\r\n call dbspvn(t, k, k, 1, xi, left, bcoef, work, iwork, iflag)\r\n if (iflag/=0) return\r\n\r\n ! we therefore want bcoef(j) = b(left-k+j)(xi) to go into\r\n ! a(i,left-k+j), i.e., into q(i-(left+j)+2*k,(left+j)-k) since\r\n ! a(i+j,j) is to go into q(i+k,j), all i,j, if we consider q\r\n ! as a two-dim. array , with 2*k-1 rows (see comments in\r\n ! dbnfac). in the present program, we treat q as an equivalent\r\n ! one-dimensional array (because of fortran restrictions on\r\n ! dimension statements) . we therefore want bcoef(j) to go into\r\n ! entry\r\n ! i -(left+j) + 2*k + ((left+j) - k-1)*(2*k-1)\r\n ! = i-left+1 + (left -k)*(2*k-1) + (2*k-2)*j\r\n ! of q.\r\n jj = i - left + 1 + (left-k)*(k+km1)\r\n do j=1,k\r\n jj = jj + kpkm2\r\n q(jj) = bcoef(j)\r\n end do\r\n\r\n end do\r\n\r\n ! obtain factorization of a, stored again in q.\r\n call dbnfac(q, k+km1, n, km1, km1, iflag)\r\n\r\n if (iflag==1) then !success\r\n ! solve a*bcoef = y by backsubstitution\r\n do i=1,n\r\n bcoef(i) = y(i)\r\n end do\r\n call dbnslv(q, k+km1, n, km1, km1, bcoef)\r\n iflag = 0\r\n else !failure\r\n !write(error_unit,'(A)') 'dbintk - the system of solver detects a singular system'//&\r\n ! ' although the theoretical conditions for a solution were satisfied'\r\n iflag = 104\r\n end if\r\n\r\n end subroutine dbintk\r\n!*****************************************************************************************\r\n\r\n!*****************************************************************************************\r\n!>\r\n! Returns in w the LU-factorization (without pivoting) of the banded\r\n! matrix a of order nrow with (nbandl + 1 + nbandu) bands or diagonals\r\n! in the work array w .\r\n!\r\n! gauss elimination without pivoting is used. the routine is\r\n! intended for use with matrices a which do not require row inter-\r\n! changes during factorization, especially for the totally\r\n! positive matrices which occur in spline calculations.\r\n! the routine should not be used for an arbitrary banded matrix.\r\n!\r\n!### Work array\r\n!\r\n! **Input**\r\n!\r\n! w array of size (nroww,nrow) contains the interesting\r\n! part of a banded matrix a , with the diagonals or bands of a\r\n! stored in the rows of w , while columns of a correspond to\r\n! columns of w . this is the storage mode used in linpack and\r\n! results in efficient innermost loops.\r\n! explicitly, a has nbandl bands below the diagonal\r\n! + 1 (main) diagonal\r\n! + nbandu bands above the diagonal\r\n! and thus, with middle = nbandu + 1,\r\n! a(i+j,j) is in w(i+middle,j) for i=-nbandu,...,nbandl\r\n! j=1,...,nrow .\r\n! for example, the interesting entries of a (1,2)-banded matrix\r\n! of order 9 would appear in the first 1+1+2 = 4 rows of w\r\n! as follows.\r\n! 13 24 35 46 57 68 79\r\n! 12 23 34 45 56 67 78 89\r\n! 11 22 33 44 55 66 77 88 99\r\n! 21 32 43 54 65 76 87 98\r\n!\r\n! all other entries of w not identified in this way with an en-\r\n! try of a are never referenced .\r\n!\r\n! **Output**\r\n!\r\n! * if iflag = 1, then\r\n! w contains the lu-factorization of a into a unit lower triangu-\r\n! lar matrix l and an upper triangular matrix u (both banded)\r\n! and stored in customary fashion over the corresponding entries\r\n! of a . this makes it possible to solve any particular linear\r\n! system a*x = b for x by a\r\n! call dbnslv ( w, nroww, nrow, nbandl, nbandu, b )\r\n! with the solution x contained in b on return .\r\n! * if iflag = 2, then\r\n! one of nrow-1, nbandl,nbandu failed to be nonnegative, or else\r\n! one of the potential pivots was found to be zero indicating\r\n! that a does not have an lu-factorization. this implies that\r\n! a is singular in case it is totally positive .\r\n!\r\n!### History\r\n! * banfac written by carl de boor [5]\r\n! * dbnfac from CMLIB [1]\r\n! * Jacob Williams, 5/10/2015 : converted to free-form Fortran.\r\n\r\n pure subroutine dbnfac(w,nroww,nrow,nbandl,nbandu,iflag)\r\n\r\n integer,intent(in) :: nroww !! row dimension of the work array w. must be >= nbandl + 1 + nbandu.\r\n integer,intent(in) :: nrow !! matrix order\r\n integer,intent(in) :: nbandl !! number of bands of a below the main diagonal\r\n integer,intent(in) :: nbandu !! number of bands of a above the main diagonal\r\n integer,intent(out) :: iflag !! indicating success(=1) or failure (=2)\r\n real(wp),dimension(nroww,nrow),intent(inout) :: w !! work array. See header for details.\r\n\r\n integer :: i, ipk, j, jmax, k, kmax, middle, midmk, nrowm1\r\n real(wp) :: factor, pivot\r\n\r\n iflag = 1\r\n middle = nbandu + 1 ! w(middle,.) contains the main diagonal of a.\r\n nrowm1 = nrow - 1\r\n\r\n if (nrowm1 < 0) then\r\n iflag = 2\r\n return\r\n else if (nrowm1 == 0) then\r\n if (w(middle,nrow)==0.0_wp) iflag = 2\r\n return\r\n end if\r\n\r\n if (nbandl<=0) then\r\n ! a is upper triangular. check that diagonal is nonzero .\r\n do i=1,nrowm1\r\n if (w(middle,i)==0.0_wp) then\r\n iflag = 2\r\n return\r\n end if\r\n end do\r\n if (w(middle,nrow)==0.0_wp) iflag = 2\r\n return\r\n end if\r\n\r\n if (nbandu<=0) then\r\n ! a is lower triangular. check that diagonal is nonzero and\r\n ! divide each column by its diagonal.\r\n do i=1,nrowm1\r\n pivot = w(middle,i)\r\n if (pivot==0.0_wp) then\r\n iflag = 2\r\n return\r\n end if\r\n jmax = min(nbandl,nrow-i)\r\n do j=1,jmax\r\n w(middle+j,i) = w(middle+j,i)/pivot\r\n end do\r\n end do\r\n return\r\n end if\r\n\r\n ! a is not just a triangular matrix. construct lu factorization\r\n do i=1,nrowm1\r\n ! w(middle,i) is pivot for i-th step .\r\n pivot = w(middle,i)\r\n if (pivot==0.0_wp) then\r\n iflag = 2\r\n return\r\n end if\r\n ! jmax is the number of (nonzero) entries in column i\r\n ! below the diagonal.\r\n jmax = min(nbandl,nrow-i)\r\n ! divide each entry in column i below diagonal by pivot.\r\n do j=1,jmax\r\n w(middle+j,i) = w(middle+j,i)/pivot\r\n end do\r\n ! kmax is the number of (nonzero) entries in row i to\r\n ! the right of the diagonal.\r\n kmax = min(nbandu,nrow-i)\r\n ! subtract a(i,i+k)*(i-th column) from (i+k)-th column\r\n ! (below row i).\r\n do k=1,kmax\r\n ipk = i + k\r\n midmk = middle - k\r\n factor = w(midmk,ipk)\r\n do j=1,jmax\r\n w(midmk+j,ipk) = w(midmk+j,ipk) - w(middle+j,i)*factor\r\n end do\r\n end do\r\n end do\r\n\r\n ! check the last diagonal entry.\r\n if (w(middle,nrow)==0.0_wp) iflag = 2\r\n\r\n end subroutine dbnfac\r\n!*****************************************************************************************\r\n\r\n!*****************************************************************************************\r\n!>\r\n! Companion routine to [[dbnfac]]. it returns the solution x of the\r\n! linear system a*x = b in place of b, given the lu-factorization\r\n! for a in the work array w from dbnfac.\r\n!\r\n! (with \\( a = l*u \\), as stored in w), the unit lower triangular system\r\n! \\( l(u*x) = b \\) is solved for \\( y = u*x \\), and y stored in b. then the\r\n! upper triangular system \\(u*x = y \\) is solved for x. the calculations\r\n! are so arranged that the innermost loops stay within columns.\r\n!\r\n!### History\r\n! * banslv written by carl de boor [5]\r\n! * dbnslv from SLATEC library [1]\r\n! * Jacob Williams, 5/10/2015 : converted to free-form Fortran.\r\n\r\n pure subroutine dbnslv(w,nroww,nrow,nbandl,nbandu,b)\r\n\r\n integer,intent(in) :: nroww !! describes the lu-factorization of a banded matrix a of order `nrow`\r\n !! as constructed in [[dbnfac]].\r\n integer,intent(in) :: nrow !! describes the lu-factorization of a banded matrix a of order `nrow`\r\n !! as constructed in [[dbnfac]].\r\n integer,intent(in) :: nbandl !! describes the lu-factorization of a banded matrix a of order `nrow`\r\n !! as constructed in [[dbnfac]].\r\n integer,intent(in) :: nbandu !! describes the lu-factorization of a banded matrix a of order `nrow`\r\n !! as constructed in [[dbnfac]].\r\n real(wp),dimension(nroww,nrow),intent(in) :: w !! describes the lu-factorization of a banded matrix a of\r\n !! order `nrow` as constructed in [[dbnfac]].\r\n real(wp),dimension(nrow),intent(inout) :: b !! * **in**: right side of the system to be solved\r\n !! * **out**: the solution x, of order nrow\r\n\r\n integer :: i, j, jmax, middle, nrowm1\r\n\r\n middle = nbandu + 1\r\n if (nrow/=1) then\r\n\r\n nrowm1 = nrow - 1\r\n if (nbandl/=0) then\r\n\r\n ! forward pass\r\n ! for i=1,2,...,nrow-1, subtract right side(i)*(i-th column of l)\r\n ! from right side (below i-th row).\r\n do i=1,nrowm1\r\n jmax = min(nbandl,nrow-i)\r\n do j=1,jmax\r\n b(i+j) = b(i+j) - b(i)*w(middle+j,i)\r\n end do\r\n end do\r\n\r\n end if\r\n\r\n ! backward pass\r\n ! for i=nrow,nrow-1,...,1, divide right side(i) by i-th diagonal\r\n ! entry of u, then subtract right side(i)*(i-th column\r\n ! of u) from right side (above i-th row).\r\n if (nbandu<=0) then\r\n ! a is lower triangular.\r\n do i=1,nrow\r\n b(i) = b(i)/w(1,i)\r\n end do\r\n return\r\n end if\r\n\r\n i = nrow\r\n do\r\n b(i) = b(i)/w(middle,i)\r\n jmax = min(nbandu,i-1)\r\n do j=1,jmax\r\n b(i-j) = b(i-j) - b(i)*w(middle-j,i)\r\n end do\r\n i = i - 1\r\n if (i<=1) exit\r\n end do\r\n\r\n end if\r\n\r\n b(1) = b(1)/w(middle,1)\r\n\r\n end subroutine dbnslv\r\n!*****************************************************************************************\r\n\r\n!*****************************************************************************************\r\n!>\r\n! Calculates the value of all (possibly) nonzero basis\r\n! functions at x of order max(jhigh,(j+1)*(index-1)), where t(k)\r\n! <= x <= t(n+1) and j=iwork is set inside the routine on\r\n! the first call when index=1. ileft is such that t(ileft) <=\r\n! x < t(ileft+1). a call to dintrv(t,n+1,x,ilo,ileft,mflag)\r\n! produces the proper ileft. dbspvn calculates using the basic\r\n! algorithm needed in dbspvd. if only basis functions are\r\n! desired, setting jhigh=k and index=1 can be faster than\r\n! calling dbspvd, but extra coding is required for derivatives\r\n! (index=2) and dbspvd is set up for this purpose.\r\n!\r\n! left limiting values are set up as described in dbspvd.\r\n!\r\n!### Error Conditions\r\n!\r\n! * improper input\r\n!\r\n!### History\r\n! * bsplvn written by carl de boor [5]\r\n! * dbspvn author: amos, d. e., (snla) : date written 800901\r\n! * revision date 820801\r\n! * 000330 modified array declarations. (jec)\r\n! * Jacob Williams, 2/24/2015 : extensive refactoring of CMLIB routine.\r\n\r\n pure subroutine dbspvn(t,jhigh,k,index,x,ileft,vnikx,work,iwork,iflag)\r\n\r\n implicit none\r\n\r\n real(wp),dimension(*),intent(in) :: t !! knot vector of length n+k, where\r\n !! n = number of b-spline basis functions\r\n !! n = sum of knot multiplicities-k\r\n !! dimension t(ileft+jhigh)\r\n integer,intent(in) :: jhigh !! order of b-spline, 1 <= jhigh <= k\r\n integer,intent(in) :: k !! highest possible order\r\n integer,intent(in) :: index !! index = 1 gives basis functions of order jhigh\r\n !! = 2 denotes previous entry with work, iwork\r\n !! values saved for subsequent calls to\r\n !! dbspvn.\r\n real(wp),intent(in) :: x !! argument of basis functions, t(k) <= x <= t(n+1)\r\n integer,intent(in) :: ileft !! largest integer such that t(ileft) <= x < t(ileft+1)\r\n real(wp),dimension(k),intent(out) :: vnikx !! vector of length k for spline values.\r\n real(wp),dimension(*),intent(out) :: work !! a work vector of length 2*k\r\n integer,intent(out) :: iwork !! a work parameter. both work and iwork contain\r\n !! information necessary to continue for index = 2.\r\n !! when index = 1 exclusively, these are scratch\r\n !! variables and can be used for other purposes.\r\n integer,intent(out) :: iflag !! 0: no errors\r\n !! 201: k does not satisfy k>=1\r\n !! 202: jhigh does not satisfy 1<=jhigh<=k\r\n !! 203: index is not 1 or 2\r\n !! 204: x does not satisfy t(ileft)<=x<=t(ileft+1)\r\n\r\n integer :: imjp1, ipj, jp1, jp1ml, l\r\n real(wp) :: vm, vmprev\r\n\r\n ! content of j, deltam, deltap is expected unchanged between calls.\r\n ! work(i) = deltap(i),\r\n ! work(k+i) = deltam(i), i = 1,k\r\n\r\n if (k<1) then\r\n !write(error_unit,'(A)') 'dbspvn - k does not satisfy k>=1'\r\n iflag = 201\r\n return\r\n end if\r\n if (jhigh>k .or. jhigh<1) then\r\n !write(error_unit,'(A)') 'dbspvn - jhigh does not satisfy 1<=jhigh<=k'\r\n iflag = 202\r\n return\r\n end if\r\n if (index<1 .or. index>2) then\r\n !write(error_unit,'(A)') 'dbspvn - index is not 1 or 2'\r\n iflag = 203\r\n return\r\n end if\r\n if (xt(ileft+1)) then\r\n !write(error_unit,'(A)') 'dbspvn - x does not satisfy t(ileft)<=x<=t(ileft+1)'\r\n iflag = 204\r\n return\r\n end if\r\n\r\n iflag = 0\r\n\r\n if (index==1) then\r\n iwork = 1\r\n vnikx(1) = 1.0_wp\r\n if (iwork>=jhigh) return\r\n end if\r\n\r\n do\r\n ipj = ileft + iwork\r\n work(iwork) = t(ipj) - x\r\n imjp1 = ileft - iwork + 1\r\n work(k+iwork) = x - t(imjp1)\r\n vmprev = 0.0_wp\r\n jp1 = iwork + 1\r\n do l=1,iwork\r\n jp1ml = jp1 - l\r\n vm = vnikx(l)/(work(l)+work(k+jp1ml))\r\n vnikx(l) = vm*work(l) + vmprev\r\n vmprev = vm*work(k+jp1ml)\r\n end do\r\n vnikx(jp1) = vmprev\r\n iwork = jp1\r\n if (iwork>=jhigh) exit\r\n end do\r\n\r\n end subroutine dbspvn\r\n!*****************************************************************************************\r\n\r\n!*****************************************************************************************\r\n!>\r\n! Evaluates the b-representation (`t`,`a`,`n`,`k`) of a b-spline\r\n! at `x` for the function value on `ideriv=0` or any of its\r\n! derivatives on `ideriv=1,2,...,k-1`. right limiting values\r\n! (right derivatives) are returned except at the right end\r\n! point `x=t(n+1)` where left limiting values are computed. the\r\n! spline is defined on `t(k)` \\( \\le \\) `x` \\( \\le \\) `t(n+1)`.\r\n! dbvalu returns a fatal error message when `x` is outside of this\r\n! interval.\r\n!\r\n! To compute left derivatives or left limiting values at a\r\n! knot `t(i)`, replace `n` by `i-1` and set `x=t(i), i=k+1,n+1`.\r\n!\r\n!### Error Conditions\r\n!\r\n! * improper input\r\n!\r\n!### History\r\n! * bvalue written by carl de boor [5]\r\n! * dbvalu author: amos, d. e., (snla) : date written 800901\r\n! * revision date 820801\r\n! * 000330 modified array declarations. (jec)\r\n! * Jacob Williams, 2/24/2015 : extensive refactoring of CMLIB routine.\r\n\r\n pure subroutine dbvalu(t,a,n,k,ideriv,x,inbv,work,iflag,val,extrap)\r\n\r\n implicit none\r\n\r\n real(wp),intent(out) :: val !! the interpolated value\r\n integer,intent(in) :: n !! number of b-spline coefficients.\r\n !! (sum of knot multiplicities-`k`)\r\n real(wp),dimension(:),intent(in) :: t !! knot vector of length `n+k`\r\n real(wp),dimension(n),intent(in) :: a !! b-spline coefficient vector of length `n`\r\n integer,intent(in) :: k !! order of the b-spline, `k >= 1`\r\n integer,intent(in) :: ideriv !! order of the derivative, `0 <= ideriv <= k-1`.\r\n !! `ideriv = 0` returns the b-spline value\r\n real(wp),intent(in) :: x !! argument, `t(k) <= x <= t(n+1)`\r\n integer,intent(inout) :: inbv !! an initialization parameter which must be set\r\n !! to 1 the first time [[dbvalu]] is called.\r\n !! `inbv` contains information for efficient processing\r\n !! after the initial call and `inbv` must not\r\n !! be changed by the user. distinct splines require\r\n !! distinct `inbv` parameters.\r\n real(wp),dimension(:),intent(inout) :: work !! work vector of length at least `3*k`\r\n integer,intent(out) :: iflag !! status flag:\r\n !!\r\n !! * 0: no errors\r\n !! * 401: `k` does not satisfy `k` \\( \\ge \\) 1\r\n !! * 402: `n` does not satisfy `n` \\( \\ge \\) `k`\r\n !! * 403: `ideriv` does not satisfy 0 \\( \\le \\) `ideriv` \\(<\\) `k`\r\n !! * 404: `x` is not greater than or equal to `t(k)`\r\n !! * 405: `x` is not less than or equal to `t(n+1)`\r\n !! * 406: a left limiting value cannot be obtained at `t(k)`\r\n logical,intent(in),optional :: extrap !! if extrapolation is allowed\r\n !! (if not present, default is False)\r\n\r\n integer :: i,iderp1,ihi,ihmkmj,ilo,imk,imkpj,ipj,&\r\n ip1,ip1mj,j,jj,j1,j2,kmider,kmj,km1,kpk,mflag\r\n real(wp) :: fkmj\r\n real(wp) :: xt\r\n logical :: extrapolation_allowed !! if extrapolation is allowed\r\n\r\n val = 0.0_wp\r\n\r\n if (k<1) then\r\n iflag = 401 ! dbvalu - k does not satisfy k>=1\r\n return\r\n end if\r\n\r\n if (n=k\r\n return\r\n end if\r\n\r\n if (ideriv<0 .or. ideriv>=k) then\r\n iflag = 403 ! dbvalu - ideriv does not satisfy 0<=iderivt(n+k)) then\r\n xt = t(n+k)\r\n else\r\n xt = x\r\n end if\r\n else\r\n xt = x\r\n end if\r\n\r\n kmider = k - ideriv\r\n\r\n ! find *i* in (k,n) such that t(i) <= x < t(i+1)\r\n ! (or, <= t(i+1) if t(i) < t(i+1) = t(n+1)).\r\n\r\n km1 = k - 1\r\n call dintrv(t, n+1, xt, inbv, i, mflag)\r\n if (xtt(i)) then\r\n iflag = 405 ! dbvalu - x is not less than or equal to t(n+1)\r\n return\r\n end if\r\n\r\n do\r\n if (i==k) then\r\n iflag = 406 ! dbvalu - a left limiting value cannot be obtained at t(k)\r\n return\r\n end if\r\n i = i - 1\r\n if (xt/=t(i)) exit\r\n end do\r\n\r\n end if\r\n\r\n ! difference the coefficients *ideriv* times\r\n ! work(i) = aj(i), work(k+i) = dp(i), work(k+k+i) = dm(i), i=1.k\r\n\r\n imk = i - k\r\n do j=1,k\r\n imkpj = imk + j\r\n work(j) = a(imkpj)\r\n end do\r\n\r\n if (ideriv/=0) then\r\n do j=1,ideriv\r\n kmj = k - j\r\n fkmj = real(kmj,wp)\r\n do jj=1,kmj\r\n ihi = i + jj\r\n ihmkmj = ihi - kmj\r\n work(jj) = (work(jj+1)-work(jj))/(t(ihi)-t(ihmkmj))*fkmj\r\n end do\r\n end do\r\n end if\r\n\r\n ! compute value at *x* in (t(i),(t(i+1)) of ideriv-th derivative,\r\n ! given its relevant b-spline coeff. in aj(1),...,aj(k-ideriv).\r\n\r\n if (ideriv/=km1) then\r\n ip1 = i + 1\r\n kpk = k + k\r\n j1 = k + 1\r\n j2 = kpk + 1\r\n do j=1,kmider\r\n ipj = i + j\r\n work(j1) = t(ipj) - x\r\n ip1mj = ip1 - j\r\n work(j2) = x - t(ip1mj)\r\n j1 = j1 + 1\r\n j2 = j2 + 1\r\n end do\r\n iderp1 = ideriv + 1\r\n do j=iderp1,km1\r\n kmj = k - j\r\n ilo = kmj\r\n do jj=1,kmj\r\n work(jj) = (work(jj+1)*work(kpk+ilo)+work(jj)*&\r\n work(k+jj))/(work(kpk+ilo)+work(k+jj))\r\n ilo = ilo - 1\r\n end do\r\n end do\r\n end if\r\n\r\n iflag = 0\r\n val = work(1)\r\n\r\n end subroutine dbvalu\r\n!*****************************************************************************************\r\n\r\n!*****************************************************************************************\r\n!>\r\n! Computes the largest integer `ileft` in 1 \\( \\le \\) `ileft` \\( \\le \\) `lxt`\r\n! such that `xt(ileft)` \\( \\le \\) `x` where `xt(*)` is a subdivision of\r\n! the `x` interval.\r\n! precisely,\r\n!\r\n!```fortran\r\n! if x < xt(1) then ileft=1, mflag=-1\r\n! if xt(i) <= x < xt(i+1) then ileft=i, mflag=0\r\n! if xt(lxt) <= x then ileft=lxt, mflag=-2\r\n!```\r\n!\r\n! that is, when multiplicities are present in the break point\r\n! to the left of `x`, the largest index is taken for `ileft`.\r\n!\r\n!### History\r\n! * interv written by carl de boor [5]\r\n! * dintrv author: amos, d. e., (snla) : date written 800901\r\n! * revision date 820801\r\n! * Jacob Williams, 2/24/2015 : updated to free-form Fortran.\r\n! * Jacob Williams, 2/17/2016 : additional refactoring (eliminated GOTOs).\r\n! * Jacob Williams, 3/4/2017 : added extrapolation option.\r\n\r\n pure subroutine dintrv(xt,lxt,xx,ilo,ileft,mflag,extrap)\r\n\r\n implicit none\r\n\r\n integer,intent(in) :: lxt !! length of the `xt` vector\r\n real(wp),dimension(lxt),intent(in) :: xt !! a knot or break point vector of length `lxt`\r\n real(wp),intent(in) :: xx !! argument\r\n integer,intent(inout) :: ilo !! an initialization parameter which must be set\r\n !! to 1 the first time the spline array `xt` is\r\n !! processed by dintrv. `ilo` contains information for\r\n !! efficient processing after the initial call and `ilo`\r\n !! must not be changed by the user. distinct splines\r\n !! require distinct `ilo` parameters.\r\n integer,intent(out) :: ileft !! largest integer satisfying `xt(ileft)` \\( \\le \\) `x`\r\n integer,intent(out) :: mflag !! signals when `x` lies out of bounds\r\n logical,intent(in),optional :: extrap !! if extrapolation is allowed\r\n !! (if not present, default is False)\r\n\r\n integer :: ihi, istep, middle\r\n real(wp) :: x\r\n\r\n x = get_temp_x_for_extrap(xx,xt(1),xt(lxt),extrap)\r\n\r\n ihi = ilo + 1\r\n if ( ihi>=lxt ) then\r\n if ( x>=xt(lxt) ) then\r\n mflag = -2\r\n ileft = lxt\r\n return\r\n end if\r\n if ( lxt<=1 ) then\r\n mflag = -1\r\n ileft = 1\r\n return\r\n end if\r\n ilo = lxt - 1\r\n ihi = lxt\r\n end if\r\n\r\n if ( x>=xt(ihi) ) then\r\n\r\n ! now x >= xt(ilo). find upper bound\r\n istep = 1\r\n do\r\n ilo = ihi\r\n ihi = ilo + istep\r\n if ( ihi>=lxt ) then\r\n if ( x>=xt(lxt) ) then\r\n mflag = -2\r\n ileft = lxt\r\n return\r\n end if\r\n ihi = lxt\r\n else if ( x>=xt(ihi) ) then\r\n istep = istep*2\r\n cycle\r\n end if\r\n exit\r\n end do\r\n\r\n else\r\n\r\n if ( x>=xt(ilo) ) then\r\n mflag = 0\r\n ileft = ilo\r\n return\r\n end if\r\n ! now x <= xt(ihi). find lower bound\r\n istep = 1\r\n do\r\n ihi = ilo\r\n ilo = ihi - istep\r\n if ( ilo<=1 ) then\r\n ilo = 1\r\n if ( x\r\n! DBSQAD computes the integral on `(x1,x2)` of a `k`-th order\r\n! b-spline using the b-representation `(t,bcoef,n,k)`. orders\r\n! `k` as high as 20 are permitted by applying a 2, 6, or 10\r\n! point gauss formula on subintervals of `(x1,x2)` which are\r\n! formed by included (distinct) knots.\r\n!\r\n! If orders `k` greater than 20 are needed, use [[dbfqad]] with\r\n! `f(x) = 1`.\r\n!\r\n!### Note\r\n! * The maximum number of significant digits obtainable in\r\n! DBSQAD is the smaller of ~300 and the number of digits\r\n! carried in `real(wp)` arithmetic.\r\n!\r\n!### References\r\n! * D. E. Amos, \"Quadrature subroutines for splines and\r\n! B-splines\", Report SAND79-1825, Sandia Laboratories,\r\n! December 1979.\r\n!\r\n!### History\r\n! * Author: Amos, D. E., (SNLA)\r\n! * 800901 DATE WRITTEN\r\n! * 890531 Changed all specific intrinsics to generic. (WRB)\r\n! * 890531 REVISION DATE from Version 3.2\r\n! * 891214 Prologue converted to Version 4.0 format. (BAB)\r\n! * 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\r\n! * 900326 Removed duplicate information from DESCRIPTION section. (WRB)\r\n! * 920501 Reformatted the REFERENCES section. (WRB)\r\n! * Jacob Williams, 9/6/2017 : refactored to modern Fortran.\r\n! Added higher precision coefficients.\r\n!\r\n!@note Extrapolation is not enabled for this routine.\r\n\r\n pure subroutine dbsqad(t,bcoef,n,k,x1,x2,bquad,work,iflag)\r\n\r\n implicit none\r\n\r\n real(wp),dimension(:),intent(in) :: t !! knot array of length `n+k`\r\n real(wp),dimension(:),intent(in) :: bcoef !! b-spline coefficient array of length `n`\r\n integer,intent(in) :: n !! length of coefficient array\r\n integer,intent(in) :: k !! order of b-spline, `1 <= k <= 20`\r\n real(wp),intent(in) :: x1 !! end point of quadrature interval\r\n !! in `t(k) <= x <= t(n+1)`\r\n real(wp),intent(in) :: x2 !! end point of quadrature interval\r\n !! in `t(k) <= x <= t(n+1)`\r\n real(wp),intent(out) :: bquad !! integral of the b-spline over (`x1`,`x2`)\r\n real(wp),dimension(:),intent(inout) :: work !! work vector of length `3*k`\r\n integer,intent(out) :: iflag !! status flag:\r\n !!\r\n !! * 0: no errors\r\n !! * 901: `k` does not satisfy `1<=k<=20`\r\n !! * 902: `n` does not satisfy `n>=k`\r\n !! * 903: `x1` or `x2` or both do\r\n !! not satisfy `t(k)<=x<=t(n+1)`\r\n\r\n integer :: i,il1,il2,ilo,inbv,jf,left,m,mf,mflag,npk,np1\r\n real(wp) :: a,aa,b,bb,bma,bpa,c1,gx,q,ta,tb,y1,y2\r\n real(wp),dimension(5) :: s !! sum\r\n\r\n real(wp),dimension(9),parameter :: gpts = [ &\r\n &0.577350269189625764509148780501957455647601751270126876018602326483977&\r\n &67230293334569371539558574952522520871380513556767665664836499965082627&\r\n &05518373647912161760310773007685273559916067003615583077550051041144223&\r\n &01107628883557418222973945990409015710553455953862673016662179126619796&\r\n &4892168_wp,&\r\n &0.238619186083196908630501721680711935418610630140021350181395164574274&\r\n &93427563984224922442725734913160907222309701068720295545303507720513526&\r\n &28872175189982985139866216812636229030578298770859440976999298617585739&\r\n &46921613621659222233462641640013936777894532787145324672151888999339900&\r\n &0945406150514997832_wp,&\r\n &0.661209386466264513661399595019905347006448564395170070814526705852183&\r\n &49660714310094428640374646145642988837163927514667955734677222538043817&\r\n &23198010093367423918538864300079016299442625145884902455718821970386303&\r\n &22362011735232135702218793618906974301231555871064213101639896769013566&\r\n &1651261150514997832_wp,&\r\n &0.932469514203152027812301554493994609134765737712289824872549616526613&\r\n &50084420019627628873992192598504786367972657283410658797137951163840419&\r\n &21786180750210169211578452038930846310372961174632524612619760497437974&\r\n &07422632089671621172178385230505104744277222209386367655366917903888025&\r\n &2326771150514997832_wp,&\r\n &0.148874338981631210884826001129719984617564859420691695707989253515903&\r\n &61735566852137117762979946369123003116080525533882610289018186437654023&\r\n &16761969968090913050737827720371059070942475859422743249837177174247346&\r\n &21691485290294292900319346665908243383809435507599683357023000500383728&\r\n &0634351_wp,&\r\n &0.433395394129247190799265943165784162200071837656246496502701513143766&\r\n &98907770350122510275795011772122368293504099893794727422475772324920512&\r\n &67741032822086200952319270933462032011328320387691584063411149801129823&\r\n &14148878744320432476641442157678880770848387945248811854979703928792696&\r\n &4254222_wp,&\r\n &0.679409568299024406234327365114873575769294711834809467664817188952558&\r\n &57539507492461507857357048037949983390204739931506083674084257663009076&\r\n &82741718202923543197852846977409718369143712013552962837733153108679126&\r\n &93254495485472934132472721168027426848661712101171203022718105101071880&\r\n &4444161_wp,&\r\n &0.865063366688984510732096688423493048527543014965330452521959731845374&\r\n &75513805556135679072894604577069440463108641176516867830016149345356373&\r\n &92729396890950011571349689893051612072435760480900979725923317923795535&\r\n &73929059587977695683242770223694276591148364371481692378170157259728913&\r\n &9322313_wp,&\r\n &0.973906528517171720077964012084452053428269946692382119231212066696595&\r\n &20323463615962572356495626855625823304251877421121502216860143447777992&\r\n &05409587259942436704413695764881258799146633143510758737119877875210567&\r\n &06745243536871368303386090938831164665358170712568697066873725922944928&\r\n &4383797_wp]\r\n\r\n real(wp),dimension(9),parameter :: gwts = [ &\r\n &1.0_wp,&\r\n &0.467913934572691047389870343989550994811655605769210535311625319963914&\r\n &20162039812703111009258479198230476626878975479710092836255417350295459&\r\n &35635592733866593364825926382559018030281273563502536241704619318259000&\r\n &99756987095900533474080074634376824431808173206369174103416261765346292&\r\n &7888917150514997832_wp,&\r\n &0.360761573048138607569833513837716111661521892746745482289739240237140&\r\n &03783726171832096220198881934794311720914037079858987989027836432107077&\r\n &67872114085818922114502722525757771126000732368828591631602895111800517&\r\n &40813685547074482472486101183259931449817216402425586777526768199930950&\r\n &3106873150514997832_wp,&\r\n &0.171324492379170345040296142172732893526822501484043982398635439798945&\r\n &76054234015464792770542638866975211652206987440430919174716746217597462&\r\n &96492293180314484520671351091683210843717994067668872126692485569940481&\r\n &59429327357024984053433824182363244118374610391205239119044219703570297&\r\n &7497812150514997832_wp,&\r\n &0.295524224714752870173892994651338329421046717026853601354308029755995&\r\n &93821715232927035659579375421672271716440125255838681849078955200582600&\r\n &19363424941869666095627186488841680432313050615358674090830512706638652&\r\n &87483901746874726597515954450775158914556548308329986393605934912382356&\r\n &670244_wp,&\r\n &0.269266719309996355091226921569469352859759938460883795800563276242153&\r\n &43231917927676422663670925276075559581145036869830869292346938114524155&\r\n &64658846634423711656014432259960141729044528030344411297902977067142537&\r\n &53480628460839927657500691168674984281408628886853320804215041950888191&\r\n &6391898_wp,&\r\n &0.219086362515982043995534934228163192458771870522677089880956543635199&\r\n &91065295128124268399317720219278659121687281288763476662690806694756883&\r\n &09211843316656677105269915322077536772652826671027878246851010208832173&\r\n &32006427348325475625066841588534942071161341022729156547776892831330068&\r\n &8702802_wp,&\r\n &0.149451349150580593145776339657697332402556639669427367835477268753238&\r\n &65472663001094594726463473195191400575256104543633823445170674549760147&\r\n &13716011937109528798134828865118770953566439639333773939909201690204649&\r\n &08381561877915752257830034342778536175692764212879241228297015017259084&\r\n &2897331_wp,&\r\n &0.066671344308688137593568809893331792857864834320158145128694881613412&\r\n &06408408710177678550968505887782109005471452041933148750712625440376213&\r\n &93049873169940416344953637064001870112423155043935262424506298327181987&\r\n &18647480566044117862086478449236378557180717569208295026105115288152794&\r\n &421677_wp]\r\n\r\n iflag = 0\r\n bquad = 0.0_wp\r\n\r\n if ( k<1 .or. k>20 ) then\r\n\r\n iflag = 901 ! error return\r\n\r\n else if ( n=t(k) ) then\r\n np1 = n + 1\r\n if ( bb<=t(np1) ) then\r\n if ( aa==bb ) return\r\n npk = n + k\r\n ! selection of 2, 6, or 10 point gauss formula\r\n jf = 0\r\n mf = 1\r\n if ( k>4 ) then\r\n jf = 1\r\n mf = 3\r\n if ( k>12 ) then\r\n jf = 4\r\n mf = 5\r\n end if\r\n end if\r\n do i = 1 , mf\r\n s(i) = 0.0_wp\r\n end do\r\n ilo = 1\r\n inbv = 1\r\n call dintrv(t,npk,aa,ilo,il1,mflag)\r\n call dintrv(t,npk,bb,ilo,il2,mflag)\r\n if ( il2>=np1 ) il2 = n\r\n do left = il1 , il2\r\n ta = t(left)\r\n tb = t(left+1)\r\n if ( ta/=tb ) then\r\n a = max(aa,ta)\r\n b = min(bb,tb)\r\n bma = 0.5_wp*(b-a)\r\n bpa = 0.5_wp*(b+a)\r\n do m = 1 , mf\r\n c1 = bma*gpts(jf+m)\r\n gx = -c1 + bpa\r\n call dbvalu(t,bcoef,n,k,0,gx,inbv,work,iflag,y2)\r\n if (iflag/=0) return\r\n gx = c1 + bpa\r\n call dbvalu(t,bcoef,n,k,0,gx,inbv,work,iflag,y1)\r\n if (iflag/=0) return\r\n s(m) = s(m) + (y1+y2)*bma\r\n end do\r\n end if\r\n end do\r\n q = 0.0_wp\r\n do m = 1 , mf\r\n q = q + gwts(jf+m)*s(m)\r\n end do\r\n if ( x1>x2 ) q = -q\r\n bquad = q\r\n return\r\n end if\r\n end if\r\n\r\n iflag = 903 ! error return\r\n\r\n end if\r\n\r\n end subroutine dbsqad\r\n!*****************************************************************************************\r\n\r\n!*****************************************************************************************\r\n!>\r\n! dbfqad computes the integral on `(x1,x2)` of a product of a\r\n! function `f` and the `id`-th derivative of a `k`-th order b-spline,\r\n! using the b-representation `(t,bcoef,n,k)`. `(x1,x2)` must be a\r\n! subinterval of `t(k) <= x <= t(n+1)`. an integration routine,\r\n! [[dbsgq8]] (a modification of `gaus8`), integrates the product\r\n! on subintervals of `(x1,x2)` formed by included (distinct) knots\r\n!\r\n!### Reference\r\n! * D. E. Amos, \"Quadrature subroutines for splines and\r\n! B-splines\", Report SAND79-1825, Sandia Laboratories,\r\n! December 1979.\r\n!\r\n!### History\r\n! * 800901 Amos, D. E., (SNLA)\r\n! * 890531 Changed all specific intrinsics to generic. (WRB)\r\n! * 890531 REVISION DATE from Version 3.2\r\n! * 891214 Prologue converted to Version 4.0 format. (BAB)\r\n! * 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\r\n! * 900326 Removed duplicate information from DESCRIPTION section. (WRB)\r\n! * 920501 Reformatted the REFERENCES section. (WRB)\r\n! * Jacob Williams, 9/6/2017 : refactored to modern Fortran. Some changes.\r\n!\r\n!@note the maximum number of significant digits obtainable in\r\n! [[dbsqad]] is the smaller of ~300 and the number of digits\r\n! carried in `real(wp)` arithmetic.\r\n!\r\n!@note Extrapolation is not enabled for this routine.\r\n\r\n subroutine dbfqad(f,t,bcoef,n,k,id,x1,x2,tol,quad,iflag,work)\r\n\r\n implicit none\r\n\r\n procedure(b1fqad_func) :: f !! external function of one argument for the\r\n !! integrand `bf(x)=f(x)*dbvalu(t,bcoef,n,k,id,x,inbv,work)`\r\n integer,intent(in) :: n !! length of coefficient array\r\n integer,intent(in) :: k !! order of b-spline, `k >= 1`\r\n real(wp),dimension(n+k),intent(in) :: t !! knot array\r\n real(wp),dimension(n),intent(in) :: bcoef !! coefficient array\r\n integer,intent(in) :: id !! order of the spline derivative, `0 <= id <= k-1`\r\n !! `id=0` gives the spline function\r\n real(wp),intent(in) :: x1 !! left point of quadrature interval in `t(k) <= x <= t(n+1)`\r\n real(wp),intent(in) :: x2 !! right point of quadrature interval in `t(k) <= x <= t(n+1)`\r\n real(wp),intent(in) :: tol !! desired accuracy for the quadrature, suggest\r\n !! `10*dtol < tol <= 0.1` where `dtol` is the maximum\r\n !! of `1.0e-300` and real(wp) unit roundoff for\r\n !! the machine\r\n real(wp),intent(out) :: quad !! integral of `bf(x)` on `(x1,x2)`\r\n real(wp),dimension(:),intent(inout) :: work !! work vector of length `3*k`\r\n integer,intent(out) :: iflag !! status flag:\r\n !!\r\n !! * 0: no errors\r\n !! * 1001: `k` does not satisfy `k>=1`\r\n !! * 1002: `n` does not satisfy `n>=k`\r\n !! * 1003: `d` does not satisfy `0<=id=k ) then\r\n iflag = 1003 ! error\r\n else\r\n if ( tol>=min_tol .and. tol<=0.1_wp ) then\r\n aa = min(x1,x2)\r\n bb = max(x1,x2)\r\n if ( aa>=t(k) ) then\r\n np1 = n + 1\r\n if ( bb<=t(np1) ) then\r\n if ( aa==bb ) return\r\n npk = n + k\r\n ilo = 1\r\n call dintrv(t,npk,aa,ilo,il1,mflag)\r\n call dintrv(t,npk,bb,ilo,il2,mflag)\r\n if ( il2>=np1 ) il2 = n\r\n inbv = 1\r\n q = 0.0_wp\r\n do left = il1 , il2\r\n ta = t(left)\r\n tb = t(left+1)\r\n if ( ta/=tb ) then\r\n a = max(aa,ta)\r\n b = min(bb,tb)\r\n call dbsgq8(f,t,bcoef,n,k,id,a,b,inbv,err,ans,iflag,work)\r\n if ( iflag/=0 .and. iflag/=1101 ) return\r\n q = q + ans\r\n end if\r\n end do\r\n if ( x1>x2 ) q = -q\r\n quad = q\r\n end if\r\n else\r\n iflag = 1004 ! error\r\n end if\r\n else\r\n iflag = 1005 ! error\r\n end if\r\n end if\r\n\r\n end subroutine dbfqad\r\n!*****************************************************************************************\r\n\r\n!*****************************************************************************************\r\n!>\r\n! DBSGQ8, a modification of [gaus8](http://netlib.sandia.gov/slatec/src/gaus8.f),\r\n! integrates the product of `fun(x)` by the `id`-th derivative of a spline\r\n! [[dbvalu]] between limits `a` and `b` using an adaptive 8-point Legendre-Gauss\r\n! algorithm.\r\n!\r\n!### See also\r\n! * [[dbfqad]]\r\n!\r\n!### History\r\n! * 800901 Jones, R. E., (SNLA)\r\n! * 890531 Changed all specific intrinsics to generic. (WRB)\r\n! * 890911 Removed unnecessary intrinsics. (WRB)\r\n! * 891214 Prologue converted to Version 4.0 format. (BAB)\r\n! * 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\r\n! * 900326 Removed duplicate information from DESCRIPTION section. (WRB)\r\n! * 900328 Added TYPE section. (WRB)\r\n! * 910408 Updated the AUTHOR section. (WRB)\r\n! * Jacob Williams, 9/6/2017 : refactored to modern Fortran. Some changes.\r\n! Added higher precision coefficients.\r\n\r\n subroutine dbsgq8(fun,xt,bc,n,kk,id,a,b,inbv,err,ans,iflag,work)\r\n\r\n implicit none\r\n\r\n procedure(b1fqad_func) :: fun !! name of external function of one\r\n !! argument which multiplies [[dbvalu]].\r\n integer,intent(in) :: n !! number of b-coefficients for [[dbvalu]]\r\n integer,intent(in) :: kk !! order of the spline, `kk>=1`\r\n real(wp),dimension(:),intent(in) :: xt !! knot array for [[dbvalu]]\r\n real(wp),dimension(n),intent(in) :: bc !! b-coefficient array for [[dbvalu]]\r\n integer,intent(in) :: id !! Order of the spline derivative, `0<=id<=kk-1`\r\n real(wp),intent(in) :: a !! lower limit of integral\r\n real(wp),intent(in) :: b !! upper limit of integral (may be less than `a`)\r\n integer,intent(inout) :: inbv !! initialization parameter for [[dbvalu]]\r\n real(wp),intent(inout) :: err !! **IN:** is a requested pseudorelative error\r\n !! tolerance. normally pick a value of\r\n !! `abs(err)<1e-3`. `ans` will normally\r\n !! have no more error than `abs(err)` times\r\n !! the integral of the absolute value of\r\n !! `fun(x)*[[dbvalu]]()`.\r\n !!\r\n !! **OUT:** will be an estimate of the absolute\r\n !! error in ans if the input value of `err`\r\n !! was negative. (`err` is unchanged if\r\n !! the input value of `err` was nonnegative.)\r\n !! the estimated error is solely for information\r\n !! to the user and should not be used as a\r\n !! correction to the computed integral.\r\n real(wp),intent(out) :: ans !! computed value of integral\r\n integer,intent(out) :: iflag !! a status code:\r\n !!\r\n !! * 0: `ans` most likely meets requested\r\n !! error tolerance, or `a=b`.\r\n !! * 1101: `a` and `b` are too nearly equal\r\n !! to allow normal integration.\r\n !! `ans` is set to zero.\r\n !! * 1102: `ans` probably does not meet\r\n !! requested error tolerance.\r\n real(wp),dimension(:),intent(inout) :: work !! work vector of length `3*k` for [[dbvalu]]\r\n\r\n integer :: k,l,lmn,lmx,mxl,nbits,nib,nlmx\r\n real(wp) :: ae,anib,area,c,ce,ee,ef,eps,est,gl,glr,tol,vr,x\r\n integer,dimension(60) :: lr\r\n real(wp),dimension(60) :: aa,hh,vl,gr\r\n\r\n integer,parameter :: i1mach14 = digits(1.0_wp) !! i1mach(14)\r\n real(wp),parameter :: d1mach5 = log10(real(radix(x),wp)) !! d1mach(5)\r\n real(wp),parameter :: ln2 = log(2.0_wp) !! 0.69314718d0\r\n real(wp),parameter :: sq2 = sqrt(2.0_wp)\r\n integer,parameter :: nlmn = 1\r\n integer,parameter :: kmx = 5000\r\n integer,parameter :: kml = 6\r\n\r\n ! initialize\r\n inbv = 1\r\n iflag = 0\r\n k = i1mach14\r\n anib = d1mach5*k/0.30102000_wp\r\n nbits = int(anib)\r\n nlmx = min((nbits*5)/8,60)\r\n ans = 0.0_wp\r\n ce = 0.0_wp\r\n\r\n if ( a==b ) then\r\n if ( err<0.0_wp ) err = ce\r\n else\r\n lmx = nlmx\r\n lmn = nlmn\r\n if ( b/=0.0_wp ) then\r\n if ( sign(1.0_wp,b)*a>0.0_wp ) then\r\n c = abs(1.0_wp-a/b)\r\n if ( c<=0.1_wp ) then\r\n if ( c<=0.0_wp ) then\r\n if ( err<0.0_wp ) err = ce\r\n return\r\n else\r\n anib = 0.5_wp - log(c)/ln2\r\n nib = int(anib)\r\n lmx = min(nlmx,nbits-nib-7)\r\n if ( lmx<1 ) then\r\n ! a and b are too nearly equal\r\n ! to allow normal integration\r\n iflag = 1101\r\n if ( err<0.0_wp ) err = ce\r\n return\r\n else\r\n lmn = min(lmn,lmx)\r\n end if\r\n end if\r\n end if\r\n end if\r\n end if\r\n tol = max(abs(err),2.0_wp**(5-nbits))/2.0_wp\r\n if ( err==0.0_wp ) tol = sqrt(epsilon(1.0_wp))\r\n eps = tol\r\n hh(1) = (b-a)/4.0_wp\r\n aa(1) = a\r\n lr(1) = 1\r\n l = 1\r\n call g8(aa(l)+2.0_wp*hh(l),2.0_wp*hh(l),est,iflag)\r\n if (iflag/=0) return\r\n k = 8\r\n area = abs(est)\r\n ef = 0.5_wp\r\n mxl = 0\r\n end if\r\n\r\n do\r\n ! compute refined estimates, estimate the error, etc.\r\n call g8(aa(l)+hh(l),hh(l),gl,iflag)\r\n if (iflag/=0) return\r\n call g8(aa(l)+3.0_wp*hh(l),hh(l),gr(l),iflag)\r\n if (iflag/=0) return\r\n k = k + 16\r\n area = area + (abs(gl)+abs(gr(l))-abs(est))\r\n glr = gl + gr(l)\r\n ee = abs(est-glr)*ef\r\n ae = max(eps*area,tol*abs(glr))\r\n if ( ee>ae ) then\r\n ! consider the left half of this level\r\n if ( k>kmx ) lmx = kml\r\n if ( l>=lmx ) then\r\n mxl = 1\r\n else\r\n l = l + 1\r\n eps = eps*0.5_wp\r\n ef = ef/sq2\r\n hh(l) = hh(l-1)*0.5_wp\r\n lr(l) = -1\r\n aa(l) = aa(l-1)\r\n est = gl\r\n cycle\r\n end if\r\n end if\r\n ce = ce + (est-glr)\r\n if ( lr(l)<=0 ) then\r\n ! proceed to right half at this level\r\n vl(l) = glr\r\n else\r\n ! return one level\r\n vr = glr\r\n do\r\n if ( l<=1 ) then\r\n ! exit\r\n ans = vr\r\n if ( (mxl/=0) .and. (abs(ce)>2.0_wp*tol*area) ) then\r\n iflag = 1102\r\n end if\r\n if ( err<0.0_wp ) err = ce\r\n return\r\n else\r\n l = l - 1\r\n eps = eps*2.0_wp\r\n ef = ef*sq2\r\n if ( lr(l)<=0 ) then\r\n vl(l) = vl(l+1) + vr\r\n exit\r\n else\r\n vr = vl(l+1) + vr\r\n end if\r\n end if\r\n end do\r\n end if\r\n est = gr(l-1)\r\n lr(l) = 1\r\n aa(l) = aa(l) + 4.0_wp*hh(l)\r\n end do\r\n\r\n contains\r\n\r\n subroutine g8(x,h,res,iflag)\r\n\r\n !! 8-point formula.\r\n !!\r\n !!@note Replaced the original double precision abscissa and weight\r\n !! coefficients with the higher precision versions from here:\r\n !! http://pomax.github.io/bezierinfo/legendre-gauss.html\r\n !! So, if `wp` is changed to say, `real128`, more precision\r\n !! can be obtained. These coefficients have about 300 digits.\r\n\r\n implicit none\r\n\r\n real(wp),intent(in) :: x\r\n real(wp),intent(in) :: h\r\n real(wp),intent(out) :: res\r\n integer,intent(out) :: iflag\r\n\r\n real(wp),dimension(8) :: f\r\n real(wp),dimension(8) :: v\r\n\r\n ! abscissa and weight coefficients:\r\n real(wp),parameter :: x1 = &\r\n &0.1834346424956498049394761423601839806667578129129737823171884736992044&\r\n &742215421141160682237111233537452676587642867666089196012523876865683788&\r\n &569995160663568104475551617138501966385810764205532370882654749492812314&\r\n &961247764619363562770645716456613159405134052985058171969174306064445289&\r\n &638150514997832_wp\r\n real(wp),parameter :: x2 = &\r\n &0.5255324099163289858177390491892463490419642431203928577508570992724548&\r\n &207685612725239614001936319820619096829248252608507108793766638779939805&\r\n &395303668253631119018273032402360060717470006127901479587576756241288895&\r\n &336619643528330825624263470540184224603688817537938539658502113876953598&\r\n &879150514997832_wp\r\n real(wp),parameter :: x3 = &\r\n &0.7966664774136267395915539364758304368371717316159648320701702950392173&\r\n &056764730921471519272957259390191974534530973092653656494917010859602772&\r\n &562074621689676153935016290342325645582634205301545856060095727342603557&\r\n &415761265140428851957341933710803722783136113628137267630651413319993338&\r\n &002150514997832_wp\r\n real(wp),parameter :: x4 = &\r\n &0.9602898564975362316835608685694729904282352343014520382716397773724248&\r\n &977434192844394389592633122683104243928172941762102389581552171285479373&\r\n &642204909699700433982618326637346808781263553346927867359663480870597542&\r\n &547603929318533866568132868842613474896289232087639988952409772489387324&\r\n &25615051499783203_wp\r\n real(wp),parameter :: w1 = &\r\n &0.3626837833783619829651504492771956121941460398943305405248230675666867&\r\n &347239066773243660420848285095502587699262967065529258215569895173844995&\r\n &576007862076842778350382862546305771007553373269714714894268328780431822&\r\n &779077846722965535548199601402487767505928976560993309027632737537826127&\r\n &502150514997832_wp\r\n real(wp),parameter :: w2 = &\r\n &0.3137066458778872873379622019866013132603289990027349376902639450749562&\r\n &719421734969616980762339285560494275746410778086162472468322655616056890&\r\n &624276469758994622503118776562559463287222021520431626467794721603822601&\r\n &295276898652509723185157998353156062419751736972560423953923732838789657&\r\n &919150514997832_wp\r\n real(wp),parameter :: w3 = &\r\n &0.2223810344533744705443559944262408844301308700512495647259092892936168&\r\n &145704490408536531423771979278421592661012122181231114375798525722419381&\r\n &826674532090577908613289536840402789398648876004385697202157482063253247&\r\n &195590228631570651319965589733545440605952819880671616779621183704306688&\r\n &233150514997832_wp\r\n real(wp),parameter :: w4 = &\r\n &0.1012285362903762591525313543099621901153940910516849570590036980647401&\r\n &787634707848602827393040450065581543893314132667077154940308923487678731&\r\n &973041136073584690533208824050731976306575729205467961435779467552492328&\r\n &730055025992954089946676810510810729468366466585774650346143712142008566&\r\n &866150514997832_wp\r\n\r\n res = 0.0_wp\r\n\r\n v(1) = x-x1*h\r\n v(2) = x+x1*h\r\n v(3) = x-x2*h\r\n v(4) = x+x2*h\r\n v(5) = x-x3*h\r\n v(6) = x+x3*h\r\n v(7) = x-x4*h\r\n v(8) = x+x4*h\r\n\r\n call dbvalu(xt,bc,n,kk,id,v(1),inbv,work,iflag,f(1)); if (iflag/=0) return\r\n call dbvalu(xt,bc,n,kk,id,v(2),inbv,work,iflag,f(2)); if (iflag/=0) return\r\n call dbvalu(xt,bc,n,kk,id,v(3),inbv,work,iflag,f(3)); if (iflag/=0) return\r\n call dbvalu(xt,bc,n,kk,id,v(4),inbv,work,iflag,f(4)); if (iflag/=0) return\r\n call dbvalu(xt,bc,n,kk,id,v(5),inbv,work,iflag,f(5)); if (iflag/=0) return\r\n call dbvalu(xt,bc,n,kk,id,v(6),inbv,work,iflag,f(6)); if (iflag/=0) return\r\n call dbvalu(xt,bc,n,kk,id,v(7),inbv,work,iflag,f(7)); if (iflag/=0) return\r\n call dbvalu(xt,bc,n,kk,id,v(8),inbv,work,iflag,f(8)); if (iflag/=0) return\r\n\r\n res = h*((w1*(fun(v(1))*f(1) + fun(v(2))*f(2)) + &\r\n w2*(fun(v(3))*f(3) + fun(v(4))*f(4))) + &\r\n (w3*(fun(v(5))*f(5) + fun(v(6))*f(6)) + &\r\n w4*(fun(v(7))*f(7) + fun(v(8))*f(8))))\r\n\r\n end subroutine g8\r\n\r\n end subroutine dbsgq8\r\n!*****************************************************************************************\r\n\r\n!*****************************************************************************************\r\n!>\r\n! Returns the value of `x` to use for computing the interval\r\n! in `t`, depending on if extrapolation is allowed or not.\r\n!\r\n! If extrapolation is allowed and x is < tmin or > tmax, then either\r\n! `tmin` or `tmax - 2.0_wp*spacing(tmax)` is returned.\r\n! Otherwise, `x` is returned.\r\n\r\n pure function get_temp_x_for_extrap(x,tmin,tmax,extrap) result(xt)\r\n\r\n implicit none\r\n\r\n real(wp),intent(in) :: x !! variable value\r\n real(wp),intent(in) :: tmin !! first knot vector element for b-splines\r\n real(wp),intent(in) :: tmax !! last knot vector element for b-splines\r\n real(wp) :: xt !! The value returned (it will either\r\n !! be `tmin`, `x`, or `tmax`)\r\n logical,intent(in),optional :: extrap !! if extrapolation is allowed\r\n !! (if not present, default is False)\r\n\r\n logical :: extrapolation_allowed !! if extrapolation is allowed\r\n\r\n if (present(extrap)) then\r\n extrapolation_allowed = extrap\r\n else\r\n extrapolation_allowed = .false.\r\n end if\r\n\r\n if (extrapolation_allowed) then\r\n if (xtmax) then\r\n ! Put it just inside the upper bound.\r\n ! This is sort of a hack to get\r\n ! extrapolation to work.\r\n xt = tmax - 2.0_wp*spacing(tmax)\r\n else\r\n xt = x\r\n end if\r\n else\r\n xt = x\r\n end if\r\n\r\n end function get_temp_x_for_extrap\r\n!*****************************************************************************************\r\n\r\n!*****************************************************************************************\r\n!>\r\n! Returns a message string associated with the status code.\r\n\r\n pure function get_status_message(iflag) result(msg)\r\n\r\n implicit none\r\n\r\n integer,intent(in) :: iflag !! return code from one of the routines\r\n character(len=:),allocatable :: msg !! status message associated with the flag\r\n\r\n character(len=10) :: istr !! for integer to string conversion\r\n integer :: istat !! for write statement\r\n\r\n select case (iflag)\r\n\r\n case( 0); msg='Successful execution'\r\n\r\n case( -1); msg='Error in dintrv: x < xt(1)'\r\n case( -2); msg='Error in dintrv: x >= xt(lxt)'\r\n\r\n case( 1); msg='Error in evaluate_*d: class is not initialized'\r\n\r\n case( 2); msg='Error in db*ink: iknot out of range'\r\n case( 3); msg='Error in db*ink: nx out of range'\r\n case( 4); msg='Error in db*ink: kx out of range'\r\n case( 5); msg='Error in db*ink: x not strictly increasing'\r\n case( 6); msg='Error in db*ink: tx not non-decreasing'\r\n case( 7); msg='Error in db*ink: ny out of range'\r\n case( 8); msg='Error in db*ink: ky out of range'\r\n case( 9); msg='Error in db*ink: y not strictly increasing'\r\n case( 10); msg='Error in db*ink: ty not non-decreasing'\r\n case( 11); msg='Error in db*ink: nz out of range'\r\n case( 12); msg='Error in db*ink: kz out of range'\r\n case( 13); msg='Error in db*ink: z not strictly increasing'\r\n case( 14); msg='Error in db*ink: tz not non-decreasing'\r\n case( 15); msg='Error in db*ink: nq out of range'\r\n case( 16); msg='Error in db*ink: kq out of range'\r\n case( 17); msg='Error in db*ink: q not strictly increasing'\r\n case( 18); msg='Error in db*ink: tq not non-decreasing'\r\n case( 19); msg='Error in db*ink: nr out of range'\r\n case( 20); msg='Error in db*ink: kr out of range'\r\n case( 21); msg='Error in db*ink: r not strictly increasing'\r\n case( 22); msg='Error in db*ink: tr not non-decreasing'\r\n case( 23); msg='Error in db*ink: ns out of range'\r\n case( 24); msg='Error in db*ink: ks out of range'\r\n case( 25); msg='Error in db*ink: s not strictly increasing'\r\n case( 26); msg='Error in db*ink: ts not non-decreasing'\r\n case(700); msg='Error in db*ink: size(x) /= size(fcn,1)'\r\n case(701); msg='Error in db*ink: size(y) /= size(fcn,2)'\r\n case(702); msg='Error in db*ink: size(z) /= size(fcn,3)'\r\n case(703); msg='Error in db*ink: size(q) /= size(fcn,4)'\r\n case(704); msg='Error in db*ink: size(r) /= size(fcn,5)'\r\n case(705); msg='Error in db*ink: size(s) /= size(fcn,6)'\r\n case(706); msg='Error in db*ink: size(x) /= nx'\r\n case(707); msg='Error in db*ink: size(y) /= ny'\r\n case(708); msg='Error in db*ink: size(z) /= nz'\r\n case(709); msg='Error in db*ink: size(q) /= nq'\r\n case(710); msg='Error in db*ink: size(r) /= nr'\r\n case(711); msg='Error in db*ink: size(s) /= ns'\r\n case(712); msg='Error in db*ink: size(tx) /= nx+kx'\r\n case(713); msg='Error in db*ink: size(ty) /= ny+ky'\r\n case(714); msg='Error in db*ink: size(tz) /= nz+kz'\r\n case(715); msg='Error in db*ink: size(tq) /= nq+kq'\r\n case(716); msg='Error in db*ink: size(tr) /= nr+kr'\r\n case(717); msg='Error in db*ink: size(ts) /= ns+ks'\r\n case(800); msg='Error in db*ink: size(x) /= size(bcoef,1)'\r\n case(801); msg='Error in db*ink: size(y) /= size(bcoef,2)'\r\n case(802); msg='Error in db*ink: size(z) /= size(bcoef,3)'\r\n case(803); msg='Error in db*ink: size(q) /= size(bcoef,4)'\r\n case(804); msg='Error in db*ink: size(r) /= size(bcoef,5)'\r\n case(805); msg='Error in db*ink: size(s) /= size(bcoef,6)'\r\n\r\n case(100); msg='Error in dbintk: k does not satisfy k>=1'\r\n case(101); msg='Error in dbintk: n does not satisfy n>=k'\r\n case(102); msg='Error in dbintk: x(i) does not satisfy x(i) decomp%xen(2)) .and. (nz_global == decomp%xen(3))) then\n !coprocessing: case 2: pencil furthest in z, send just upper y halo\n allocate(xpass2c(decomp%xsz(1)*(decomp%xsz(2)+1)*decomp%xsz(3)))\n allocate(ypass2c(decomp%xsz(1)*(decomp%xsz(2)+1)*decomp%xsz(3)))\n allocate(zpass2c(decomp%xsz(1)*(decomp%xsz(2)+1)*decomp%xsz(3)))\n xpass2c = reshape(tempxhalo(:,1:decomp%xsz(2)+1,1:decomp%xsz(3)),(/size(xpass2c)/))\n ypass2c = reshape(tempyhalo(:,1:decomp%xsz(2)+1,1:decomp%xsz(3)),(/size(ypass2c)/))\n zpass2c = reshape(tempzhalo(:,1:decomp%xsz(2)+1,1:decomp%xsz(3)),(/size(zpass2c)/))\n call NSadaptor(Nx,Ny,Nz,decomp%xst(1),decomp%xen(1), &\n decomp%xst(2),decomp%xen(2)+1,decomp%xst(3),decomp%xen(3), n, n*dt, &\n xpass2c, ypass2c, zpass2c)\n deallocate(xpass2c, ypass2c, zpass2c)\n else if ((ny_global == decomp%xen(2)) .and. (nz_global > decomp%xen(3))) then\n !coprocessing: case 3: pencil furthest in y, send just upper z halo\n allocate(xpass2c(decomp%xsz(1)*decomp%xsz(2)*(decomp%xsz(3)+1)))\n allocate(ypass2c(decomp%xsz(1)*decomp%xsz(2)*(decomp%xsz(3)+1)))\n allocate(zpass2c(decomp%xsz(1)*decomp%xsz(2)*(decomp%xsz(3)+1)))\n xpass2c = reshape(tempxhalo(:,1:decomp%xsz(2),1:decomp%xsz(3)+1),(/size(xpass2c)/))\n ypass2c = reshape(tempyhalo(:,1:decomp%xsz(2),1:decomp%xsz(3)+1),(/size(ypass2c)/))\n zpass2c = reshape(tempzhalo(:,1:decomp%xsz(2),1:decomp%xsz(3)+1),(/size(zpass2c)/))\n call NSadaptor(Nx,Ny,Nz,decomp%xst(1),decomp%xen(1), &\n decomp%xst(2),decomp%xen(2),decomp%xst(3),decomp%xen(3)+1, n, n*dt, &\n xpass2c, ypass2c, zpass2c)\n deallocate(xpass2c, ypass2c, zpass2c)\n else\n !coprocessing: case 4: send both upper y and upper z halo\n allocate(xpass2c(decomp%xsz(1)*(decomp%xsz(2)+1)*(decomp%xsz(3)+1)))\n allocate(ypass2c(decomp%xsz(1)*(decomp%xsz(2)+1)*(decomp%xsz(3)+1)))\n allocate(zpass2c(decomp%xsz(1)*(decomp%xsz(2)+1)*(decomp%xsz(3)+1)))\n xpass2c = reshape(tempxhalo(:,1:decomp%xsz(2)+1,1:decomp%xsz(3)+1),(/size(xpass2c)/))\n ypass2c = reshape(tempyhalo(:,1:decomp%xsz(2)+1,1:decomp%xsz(3)+1),(/size(ypass2c)/))\n zpass2c = reshape(tempzhalo(:,1:decomp%xsz(2)+1,1:decomp%xsz(3)+1),(/size(zpass2c)/))\n call NSadaptor(Nx,Ny,Nz,decomp%xst(1),decomp%xen(1), &\n decomp%xst(2),decomp%xen(2)+1,decomp%xst(3),decomp%xen(3)+1,n,n*dt, &\n xpass2c, ypass2c, zpass2c)\n deallocate(xpass2c,ypass2c,zpass2c)\n end if\n\n !start timer\n CALL system_clock(start,count_rate)\n ! coprocessing: Simulation loop starts here\n DO n=1,Nt\n !fixed point\n DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\n uold(i,j,k)=u(i,j,k)\n uxold(i,j,k)=ux(i,j,k)\n uyold(i,j,k)=uy(i,j,k)\n uzold(i,j,k)=uz(i,j,k)\n END DO; END DO ; END DO\n DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\n vold(i,j,k)=v(i,j,k)\n vxold(i,j,k)=vx(i,j,k)\n vyold(i,j,k)=vy(i,j,k)\n vzold(i,j,k)=vz(i,j,k)\n END DO; END DO ; END DO\n DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\n wold(i,j,k)=w(i,j,k)\n wxold(i,j,k)=wx(i,j,k)\n wyold(i,j,k)=wy(i,j,k)\n wzold(i,j,k)=wz(i,j,k)\n END DO; END DO ; END DO\n DO k=decomp%zst(3),decomp%zen(3) ; DO j=decomp%zst(2),decomp%zen(2) ; DO i=decomp%zst(1),decomp%zen(1)\n rhsuhatfix(i,j,k) = (dtInv+(0.5*ReInv)*(kx(i)*kx(i)+ky(j)*ky(j)+kz(k)*kz(k)))*uhat(i,j,k) \n END DO; END DO ; END DO\n DO k=decomp%zst(3),decomp%zen(3) ; DO j=decomp%zst(2),decomp%zen(2) ; DO i=decomp%zst(1),decomp%zen(1)\n rhsvhatfix(i,j,k) = (dtInv+(0.5*ReInv)*(kx(i)*kx(i)+ky(j)*ky(j)+kz(k)*kz(k)))*vhat(i,j,k) \n END DO; END DO ; END DO\n DO k=decomp%zst(3),decomp%zen(3) ; DO j=decomp%zst(2),decomp%zen(2) ; DO i=decomp%zst(1),decomp%zen(1)\n rhswhatfix(i,j,k) = (dtInv+(0.5*ReInv)*(kx(i)*kx(i)+ky(j)*ky(j)+kz(k)*kz(k)))*what(i,j,k) \n END DO; END DO ; END DO\n\n chg=1\n DO WHILE (chg .gt. tol)\n DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\n temp_r(i,j,k)=0.25d0*((u(i,j,k)+uold(i,j,k))*(ux(i,j,k)+uxold(i,j,k))&\n +(v(i,j,k)+vold(i,j,k))*(uy(i,j,k)+uyold(i,j,k))&\n +(w(i,j,k)+wold(i,j,k))*(uz(i,j,k)+uzold(i,j,k)))\n END DO; END DO ; END DO\n CALL decomp_2d_fft_3d(temp_r,nonlinuhat,DECOMP_2D_FFT_FORWARD)\n DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\n temp_r(i,j,k)=0.25d0*((u(i,j,k)+uold(i,j,k))*(vx(i,j,k)+vxold(i,j,k))&\n +(v(i,j,k)+vold(i,j,k))*(vy(i,j,k)+vyold(i,j,k))&\n +(w(i,j,k)+wold(i,j,k))*(vz(i,j,k)+vzold(i,j,k)))\n END DO; END DO ; END DO\n CALL decomp_2d_fft_3d(temp_r,nonlinvhat,DECOMP_2D_FFT_FORWARD)\n DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\n temp_r(i,j,k)=0.25d0*((u(i,j,k)+uold(i,j,k))*(wx(i,j,k)+wxold(i,j,k))&\n +(v(i,j,k)+vold(i,j,k))*(wy(i,j,k)+wyold(i,j,k))&\n +(w(i,j,k)+wold(i,j,k))*(wz(i,j,k)+wzold(i,j,k)))\n END DO; END DO ; END DO\n CALL decomp_2d_fft_3d(temp_r,nonlinwhat,DECOMP_2D_FFT_FORWARD)\n DO k=decomp%zst(3),decomp%zen(3) ; DO j=decomp%zst(2),decomp%zen(2) ; DO i=decomp%zst(1),decomp%zen(1)\n phat(i,j,k)=-1.0d0*( kx(i)*nonlinuhat(i,j,k)&\n +ky(j)*nonlinvhat(i,j,k)&\n +kz(k)*nonlinwhat(i,j,k))&\n /(kx(i)*kx(i)+ky(j)*ky(j)+kz(k)*kz(k)+0.1d0**13)\n END DO; END DO ; END DO\n\n DO k=decomp%zst(3),decomp%zen(3) ; DO j=decomp%zst(2),decomp%zen(2) ; DO i=decomp%zst(1),decomp%zen(1)\n uhat(i,j,k)=(rhsuhatfix(i,j,k)-nonlinuhat(i,j,k)-kx(i)*phat(i,j,k))/&\n (dtInv-(0.5d0*ReInv)*(kx(i)*kx(i)+ky(j)*ky(j)+kz(k)*kz(k))) !*scalemodes\n END DO; END DO ; END DO\n DO k=decomp%zst(3),decomp%zen(3) ; DO j=decomp%zst(2),decomp%zen(2) ; DO i=decomp%zst(1),decomp%zen(1)\n vhat(i,j,k)=(rhsvhatfix(i,j,k)-nonlinvhat(i,j,k)-ky(j)*phat(i,j,k))/&\n (dtInv-(0.5d0*ReInv)*(kx(i)*kx(i)+ky(j)*ky(j)+kz(k)*kz(k))) !*scalemodes\n END DO; END DO ; END DO\n DO k=decomp%zst(3),decomp%zen(3) ; DO j=decomp%zst(2),decomp%zen(2) ; DO i=decomp%zst(1),decomp%zen(1)\n what(i,j,k)=(rhswhatfix(i,j,k)-nonlinwhat(i,j,k)-kz(k)*phat(i,j,k))/&\n (dtInv-(0.5d0*ReInv)*(kx(i)*kx(i)+ky(j)*ky(j)+kz(k)*kz(k))) !*scalemodes\n END DO; END DO ; END DO\n\n ! derivative of u with respect to x, y, and z \n DO k=decomp%zst(3),decomp%zen(3) ; DO j=decomp%zst(2),decomp%zen(2) ; DO i=decomp%zst(1),decomp%zen(1)\n temp_c(i,j,k)=uhat(i,j,k)*kx(i)*scalemodes\n END DO; END DO ; END DO\n CALL decomp_2d_fft_3d(temp_c,ux,DECOMP_2D_FFT_BACKWARD) \n DO k=decomp%zst(3),decomp%zen(3); DO j=decomp%zst(2),decomp%zen(2) ; DO i=decomp%zst(1),decomp%zen(1)\n temp_c(i,j,k)=uhat(i,j,k)*ky(j)*scalemodes\n END DO; END DO ; END DO\n CALL decomp_2d_fft_3d(temp_c,uy,DECOMP_2D_FFT_BACKWARD) \n DO k=decomp%zst(3),decomp%zen(3); DO j=decomp%zst(2),decomp%zen(2) ; DO i=decomp%zst(1),decomp%zen(1)\n temp_c(i,j,k)=uhat(i,j,k)*kz(k)*scalemodes\n END DO; END DO ; END DO\n CALL decomp_2d_fft_3d(temp_c,uz,DECOMP_2D_FFT_BACKWARD) \n\n ! derivative of v with respect to x, y, and z \n DO k=decomp%zst(3),decomp%zen(3) ; DO j=decomp%zst(2),decomp%zen(2) ; DO i=decomp%zst(1),decomp%zen(1)\n temp_c(i,j,k)=vhat(i,j,k)*kx(i)*scalemodes\n END DO; END DO ; END DO\n CALL decomp_2d_fft_3d(temp_c,vx,DECOMP_2D_FFT_BACKWARD) \n DO k=decomp%zst(3),decomp%zen(3); DO j=decomp%zst(2),decomp%zen(2) ; DO i=decomp%zst(1),decomp%zen(1)\n temp_c(i,j,k)=vhat(i,j,k)*ky(j)*scalemodes\n END DO; END DO ; END DO\n CALL decomp_2d_fft_3d(temp_c,vy,DECOMP_2D_FFT_BACKWARD) \n DO k=decomp%zst(3),decomp%zen(3) ; DO j=decomp%zst(2),decomp%zen(2) ; DO i=decomp%zst(1),decomp%zen(1)\n temp_c(i,j,k)=vhat(i,j,k)*kz(k)*scalemodes\n END DO; END DO ; END DO\n CALL decomp_2d_fft_3d(temp_c,vz,DECOMP_2D_FFT_BACKWARD) \n\n ! derivative of w with respect to x, y, and z \n DO k=decomp%zst(3),decomp%zen(3) ; DO j=decomp%zst(2),decomp%zen(2) ; DO i=decomp%zst(1),decomp%zen(1)\n temp_c(i,j,k)=what(i,j,k)*kx(i)*scalemodes\n END DO; END DO ; END DO\n CALL decomp_2d_fft_3d(temp_c,wx,DECOMP_2D_FFT_BACKWARD) \n DO k=decomp%zst(3),decomp%zen(3) ; DO j=decomp%zst(2),decomp%zen(2) ; DO i=decomp%zst(1),decomp%zen(1)\n temp_c(i,j,k)=what(i,j,k)*ky(j)*scalemodes\n END DO; END DO ; END DO\n CALL decomp_2d_fft_3d(temp_c,wy,DECOMP_2D_FFT_BACKWARD) \n DO k=decomp%zst(3),decomp%zen(3) ; DO j=decomp%zst(2),decomp%zen(2) ; DO i=decomp%zst(1),decomp%zen(1)\n temp_c(i,j,k)=what(i,j,k)*kz(k)*scalemodes\n END DO; END DO ; END DO\n CALL decomp_2d_fft_3d(temp_c,wz,DECOMP_2D_FFT_BACKWARD) \n\n DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\n utemp(i,j,k)=u(i,j,k)\n END DO; END DO ; END DO\n DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\n vtemp(i,j,k)=v(i,j,k)\n END DO; END DO ; END DO\n DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\n wtemp(i,j,k)=w(i,j,k)\n END DO; END DO ; END DO\n\n CALL decomp_2d_fft_3d(uhat,u,DECOMP_2D_FFT_BACKWARD) \n CALL decomp_2d_fft_3d(vhat,v,DECOMP_2D_FFT_BACKWARD) \n CALL decomp_2d_fft_3d(what,w,DECOMP_2D_FFT_BACKWARD) \n\n DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\n u(i,j,k)=u(i,j,k)*scalemodes\n END DO; END DO ; END DO\n DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\n v(i,j,k)=v(i,j,k)*scalemodes\n END DO; END DO ; END DO\n DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\n w(i,j,k)=w(i,j,k)*scalemodes\n END DO; END DO ; END DO\n\n mychg(1) =maxval(abs(utemp-u))\n mychg(2) =maxval(abs(vtemp-v))\n mychg(3) =maxval(abs(wtemp-w))\n CALL MPI_ALLREDUCE(mychg,allchg,3,MPI_DOUBLE_PRECISION,MPI_MAX,MPI_COMM_WORLD,ierr)\n chg=allchg(1)+allchg(2)+allchg(3)\n IF (myid.eq.0) THEN\n PRINT *,'chg:',chg\n END IF\n END DO\n time(n+1)=n*dt\n\n !goto 5100\n IF (myid.eq.0) THEN \n PRINT *,'time',n*dt\n END IF\n\n !coprocessing: populating the arrays sent to the coprocessor\n DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\n realtempx(i,j,k)=REAL(wy(i,j,k)-vz(i,j,k),KIND=8)\n END DO; END DO ; END DO\n call update_halo(realtempx, tempxhalo, level=1)\n\n DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\n realtempy(i,j,k)=REAL(uz(i,j,k)-wx(i,j,k),KIND=8)\n END DO; END DO ; END DO\n call update_halo(realtempy, tempyhalo, level=1)\n\n DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\n realtempz(i,j,k)=REAL(vx(i,j,k)-uy(i,j,k),KIND=8)\n END DO; END DO ; END DO\n call update_halo(realtempz, tempzhalo, level=1)\n\n !coprocessing: same cases as for initial conditions. \n if ((ny_global == decomp%xen(2)) .and. (nz_global == decomp%xen(3))) then\n ! case 1: send just the pencil\n allocate(xpass2c(decomp%xsz(1)*decomp%xsz(2)*decomp%xsz(3)))\n allocate(ypass2c(decomp%xsz(1)*decomp%xsz(2)*decomp%xsz(3)))\n allocate(zpass2c(decomp%xsz(1)*decomp%xsz(2)*decomp%xsz(3)))\n xpass2c = reshape(tempxhalo(:,1:decomp%xsz(2),1:decomp%xsz(3)),(/size(xpass2c)/))\n ypass2c = reshape(tempyhalo(:,1:decomp%xsz(2),1:decomp%xsz(3)),(/size(ypass2c)/)) \n zpass2c = reshape(tempzhalo(:,1:decomp%xsz(2),1:decomp%xsz(3)),(/size(zpass2c)/))\n call NSadaptor(Nx,Ny,Nz,decomp%xst(1),decomp%xen(1), &\n decomp%xst(2),decomp%xen(2),decomp%xst(3),decomp%xen(3), n, n*dt, &\n xpass2c, ypass2c, zpass2c)\n deallocate(xpass2c, ypass2c, zpass2c)\n else if ((ny_global > decomp%xen(2)) .and. (nz_global == decomp%xen(3))) then\n ! case 2: send just upper y halo\n allocate(xpass2c(decomp%xsz(1)*(decomp%xsz(2)+1)*decomp%xsz(3)))\n allocate(ypass2c(decomp%xsz(1)*(decomp%xsz(2)+1)*decomp%xsz(3)))\n allocate(zpass2c(decomp%xsz(1)*(decomp%xsz(2)+1)*decomp%xsz(3)))\n xpass2c = reshape(tempxhalo(:,1:decomp%xsz(2)+1,1:decomp%xsz(3)),(/size(xpass2c)/))\n ypass2c = reshape(tempyhalo(:,1:decomp%xsz(2)+1,1:decomp%xsz(3)),(/size(ypass2c)/))\n zpass2c = reshape(tempzhalo(:,1:decomp%xsz(2)+1,1:decomp%xsz(3)),(/size(zpass2c)/))\n call NSadaptor(Nx,Ny,Nz,decomp%xst(1),decomp%xen(1), &\n decomp%xst(2),decomp%xen(2)+1,decomp%xst(3),decomp%xen(3), n, n*dt, &\n xpass2c, ypass2c, zpass2c)\n deallocate(xpass2c, ypass2c, zpass2c)\n else if ((ny_global == decomp%xen(2)) .and. (nz_global > decomp%xen(3))) then\n ! case 3: send just upper z halo\n allocate(xpass2c(decomp%xsz(1)*decomp%xsz(2)*(decomp%xsz(3)+1)))\n allocate(ypass2c(decomp%xsz(1)*decomp%xsz(2)*(decomp%xsz(3)+1)))\n allocate(zpass2c(decomp%xsz(1)*decomp%xsz(2)*(decomp%xsz(3)+1)))\n xpass2c = reshape(tempxhalo(:,1:decomp%xsz(2),1:decomp%xsz(3)+1),(/size(xpass2c)/))\n ypass2c = reshape(tempyhalo(:,1:decomp%xsz(2),1:decomp%xsz(3)+1),(/size(ypass2c)/))\n zpass2c = reshape(tempzhalo(:,1:decomp%xsz(2),1:decomp%xsz(3)+1),(/size(zpass2c)/))\n call NSadaptor(Nx,Ny,Nz,decomp%xst(1),decomp%xen(1), &\n decomp%xst(2),decomp%xen(2),decomp%xst(3),decomp%xen(3)+1, n, n*dt, &\n xpass2c, ypass2c, zpass2c)\n deallocate(xpass2c, ypass2c, zpass2c)\n else\n ! send both upper y and upper z halo\n allocate(xpass2c(decomp%xsz(1)*(decomp%xsz(2)+1)*(decomp%xsz(3)+1)))\n allocate(ypass2c(decomp%xsz(1)*(decomp%xsz(2)+1)*(decomp%xsz(3)+1)))\n allocate(zpass2c(decomp%xsz(1)*(decomp%xsz(2)+1)*(decomp%xsz(3)+1)))\n xpass2c = reshape(tempxhalo(:,1:decomp%xsz(2)+1,1:decomp%xsz(3)+1),(/size(xpass2c)/))\n ypass2c = reshape(tempyhalo(:,1:decomp%xsz(2)+1,1:decomp%xsz(3)+1),(/size(ypass2c)/))\n zpass2c = reshape(tempzhalo(:,1:decomp%xsz(2)+1,1:decomp%xsz(3)+1),(/size(zpass2c)/))\n call NSadaptor(Nx,Ny,Nz,decomp%xst(1),decomp%xen(1), &\n decomp%xst(2),decomp%xen(2)+1,decomp%xst(3),decomp%xen(3)+1,n,n*dt, &\n xpass2c, ypass2c, zpass2c)\n deallocate(xpass2c,ypass2c,zpass2c)\n end if\n\n END DO\n !coprocessing:\n call coprocessorfinalize()\n\n CALL system_clock(finish,count_rate)\n\n IF (myid.eq.0) then\n PRINT *, 'Program took', REAL(finish-start)/REAL(count_rate), 'for main timestepping loop'\n END IF\n\n IF (myid.eq.0) THEN\n name_config = './data/tdata.dat' \n OPEN(unit=11,FILE=name_config,status=\"UNKNOWN\") \n REWIND(11)\n DO n=1,1+Nt\n WRITE(11,*) time(n)\n END DO \n CLOSE(11)\n\n name_config = './data/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 = './data/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 name_config = './data/zcoord.dat' \n OPEN(unit=11,FILE=name_config,status=\"UNKNOWN\") \n REWIND(11)\n DO k=1,Nz\n WRITE(11,*) z(k)\n END DO\n CLOSE(11)\n PRINT *,'Saved data'\n END IF\n\n ! Calculate error in final numerical solution\n DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\n utemp(i,j,k)=u(i,j,k) -&\n (-0.5*( factor*cos(x(i))*sin(y(j))*sin(z(k))&\n +sin(x(i))*cos(y(j))*cos(z(k)) )*exp(-(factor**2)*time(Nt+1)/Re))\n END DO; END DO; END DO\n DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\n vtemp(i,j,k)=v(i,j,k) -&\n (0.5*( factor*sin(x(i))*cos(y(j))*sin(z(k))&\n -cos(x(i))*sin(y(j))*cos(z(k)) )*exp(-(factor**2)*time(Nt+1)/Re))\n END DO; END DO ; END DO\n DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\n wtemp(i,j,k)=w(i,j,k)-&\n (cos(x(i))*cos(y(j))*sin(z(k))*exp(-(factor**2)*time(Nt+1)/Re))\n END DO; END DO ; END DO\n mychg(1) = maxval(abs(utemp))\n mychg(2) = maxval(abs(vtemp))\n mychg(3) = maxval(abs(wtemp))\n CALL MPI_ALLREDUCE(mychg,allchg,3,MPI_DOUBLE_PRECISION,MPI_MAX,MPI_COMM_WORLD,ierr)\n chg=allchg(1)+allchg(2)+allchg(3)\n IF (myid.eq.0) THEN\n PRINT*,'The error at the final timestep is',chg\n END IF\n\n ! clean up \n CALL decomp_2d_fft_finalize\n CALL decomp_2d_finalize\n\n DEALLOCATE(x,y,z,time,mychg,allchg,u,v,w,ux,uy,uz,vx,vy,vz,wx,wy,wz,uold,uxold,uyold,uzold,&\n vold,vxold,vyold,vzold,wold,wxold,wyold,wzold,utemp,vtemp,wtemp,&\n temp_r,kx,ky,kz,uhat,vhat,what,rhsuhatfix,rhsvhatfix,&\n rhswhatfix,phat,nonlinuhat,nonlinvhat,nonlinwhat,temp_c,&\n realtemp,stat=AllocateStatus) \n !coprocessing: deallocate Coprocessing specific arrays\n deallocate(realtempx, realtempy, realtempz, tempxhalo, tempyhalo, tempzhalo)\n IF (AllocateStatus .ne. 0) STOP\n IF (myid.eq.0) THEN\n PRINT *,'Program execution complete'\n END IF\n CALL MPI_FINALIZE(ierr) \n\nEND PROGRAM main\n\n", "meta": {"hexsha": "0359bebc41509c95dffa62c1c05e7d4cf5181db8", "size": 40514, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "NavierStokes/Programs/NavierStokes3dFortranMPIParaView/node-based/NavierStokes3DfftIMR.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/NavierStokes3dFortranMPIParaView/node-based/NavierStokes3DfftIMR.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/NavierStokes3dFortranMPIParaView/node-based/NavierStokes3DfftIMR.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": 48.403823178, "max_line_length": 114, "alphanum_fraction": 0.5779730464, "num_tokens": 15366, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096044278533, "lm_q2_score": 0.7461389817407017, "lm_q1q2_score": 0.6835450874106754}} {"text": "program Hofstadter\n\timplicit none !all variables needed to be defined\n\n\n\t!variable decleration\n\treal :: nu=0,alpha=0,e=0.0,res=0.0,p2,q2,e_step = 0.01\n\tinteger :: qmax=50,countAlpha=0,p,q,i,countE=0,m=1,j\n\treal, dimension(2,2) :: a,b,mult !2d matrix for array multiplication\n\treal, dimension(100000) :: alpha_mat !matrix dimension unknown so taking a long one\n\tlogical :: br\n\tREAL, PARAMETER :: M_PI = 3.1415927 !Approximate value of pi\n\n\n print *, \"Please enter maximum value of qmax\"!Querying for maximum q value\n read (*,*) qmax!maximum q value input from user\n call system('rm gnuOut.txt')!removing gnuOut.txt file if present already\n open(1, file=\"gnuOut.txt\",status=\"new\")!opening gnuOut.txt for storing all the alpha value in gnuplot format\n\n\n !****** Main Itteration starting here **********\n\n do q = 1,qmax !denominator q values\n \tdo p = 0,q !numerator p values\n \t\tbr =.TRUE. !for checking the overlapping condition\n \t\tp2 = p*1.0000 !converting p and q to real variables\n \t\tq2 = q*1.0000\n \t\talpha = p2/q2 !alpha value calculated here\n \t\tdo i = 1, countAlpha!to prevent repetation\n \t\t\tif(alpha == alpha_mat(i)) then\n \t\t\t\tbr= .FALSE.!if repeated then next if condition will not proceed\n \t\t\t\tEXIT !Exiting when found\n \t\t\tend if\n \t\tend do\n \t\tif(br) then!continue if alpha value not repeated\n \t\t\tcountAlpha = countAlpha +1 !Alpha count used for indexing the container of all the alpha values required to check overcounting\n \t\t\talpha_mat(countAlpha)=alpha!Storing all the alpha values \n \t\t\tnu = M_PI/(2.0*q)!nu value\n \t\t\te=-4.0!starting e value\n \t\t\tdo while(e<=4.0)!itterating over all the e values with increament 0.01\n \t\t\t\tm = 1! m value starting form 1 with 1 incrementation\n\n \t\t\t\t!matrix Initialization\n \t\t\t\ta(1,1) = e -2*cos(2*M_PI*m*alpha-nu)\n \t\t\t\ta(1,2) = -1.0\n \t\t\t\ta(2,1) = 1.0\n \t\t\t\ta(2,2) = 0.0\n\n \t\t\t\tb(1,1) = e -2*cos(2*M_PI*(m+1)*alpha - nu)\n \t\t\t\tb(1,2) = -1.0\n \t\t\t\tb(2,1) = 1.0\n \t\t\t\tb(2,2) = 0.0\n\n \t\t\t\tdo j=1,q-1 !The loop has to only run q-1 times as we have already have A(m=1) and only have to multiply A(m=q)...A(m=2) with it.\n \t\t\t\t\t!setting m = 0\n \t\t\t\t\tmult(1,1) = 0.0\n \t\t\t\t\tmult(1,2) = 0.0\n \t\t\t\t\tmult(2,1) = 0.0\n \t\t\t\t\tmult(2,2) = 0.0\n\n \t\t\t\t\tcall matrixMultiplication(a,b,mult)!a*b =mult matrix operation\n \t\t\t\t\tcall equateMatrix(a,mult)! a= mult matrix operation\n \t\t\t\t\tm = m+1\n \t\t\t\t\tb(1,1)= e -2*cos(2*M_PI*(m+1)*alpha - nu)\n\n \t\t\t\tend do\n \t\t\t\tcall trace(a,res) !finding trace of a and storing it to res\n \t\t\t\tif(ABS(res)<=4.0) then!if trace <=4 then e and alpha are written down\n \t\t\t\t\twrite(1,*) e, alpha\n \t\t\t\tend if\n \t\t\t\te = e+e_step!Incrementation in e\n \t\t\tend do\n\n \t\tend if\n \tend do\n end do\n\n print*, \"Total number of alpha components are:\", countAlpha!Total alpha count displayed\n \n !**** Plotting it using gnuplot *****\n call system('rm gnuCommands.txt')\n open(2, file=\"gnuCommands.txt\",status=\"new\")\n write(2,*) \"set terminal qt enhanced\"\n write(2,*) \"set key off\"\n write(2,*) \"set xlabel '{/Symbol e}'\"\n write(2,*) \"set ylabel '{/Symbol a}'\"\n write(2,*) \"plot 'gnuOut.txt' w p pt 7 ps 0.05\"\n call system(\"gnuplot gnuCommands.txt --persist\")\n\n close(2)!closing open files\n close(1)\nend program Hofstadter\n\n\n! For finding trace of a 2-d matrix\nSUBROUTINE trace(a,res)\n\nimplicit none\n\nreal, dimension(2,2) :: a\nreal :: res\ninteger :: i\nres =0\ndo i=1,2\n\tres = res + a(i,i)\nend do\n\nend SUBROUTINE trace\n\n\n!a*b=mult operation\nSUBROUTINE matrixMultiplication(a,b,mult)\n\nimplicit none\n\nreal, dimension(2,2) :: a,b,mult\ninteger :: i,j,k\n\ndo i=1,2\n\tdo j=1,2\n\t\tdo k=1,2\n\t\t\tmult(i,j) = mult(i,j) + a(i,k)*b(k,j)\n\t\tend do\n\tend do\nend do\n\nEND SUBROUTINE matrixMultiplication\n\n\n!a=mult Matrix Operation\nSUBROUTINE equateMatrix(a,mult)\nimplicit none\n\nreal, dimension(2,2) :: a,mult\ninteger :: i,j\n\ndo i =1,2\n\tdo j=1,2\n\t\ta(i,j) = mult(i,j)\n\tend do\nend do\n\nend SUBROUTINE equateMatrix\n", "meta": {"hexsha": "0bb9a1b3b2e0960b637f5f1718793bc79a9ae8dd", "size": 4022, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Hofstadter-Hamiltonian/Hofstadter-Hamiltonian.f90", "max_stars_repo_name": "Subhajit-Roy-Partho/Solid-State-Numerical-Method", "max_stars_repo_head_hexsha": "3c907913b707e0cd20bab96c30be5b220dbde1a5", "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": "Hofstadter-Hamiltonian/Hofstadter-Hamiltonian.f90", "max_issues_repo_name": "Subhajit-Roy-Partho/Solid-State-Numerical-Method", "max_issues_repo_head_hexsha": "3c907913b707e0cd20bab96c30be5b220dbde1a5", "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": "Hofstadter-Hamiltonian/Hofstadter-Hamiltonian.f90", "max_forks_repo_name": "Subhajit-Roy-Partho/Solid-State-Numerical-Method", "max_forks_repo_head_hexsha": "3c907913b707e0cd20bab96c30be5b220dbde1a5", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.1258741259, "max_line_length": 137, "alphanum_fraction": 0.6198408752, "num_tokens": 1345, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588052782736, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.683526837366106}} {"text": "! Mikayla Webber\r\n! 4670 Numerical Analysis\r\n! Homework G Due 12.1.17\r\n\r\n! use at least three numerical methods to solve:\r\n! dy/dt = te^(3t) - 2y\r\n! y(0) = 0\r\n! for 0 <= t <= 2\r\n! for each method obtain at least 100 data points on your approximation and produce a graph for each method.\r\n\r\nprogram extrapall\r\n implicit none\r\n\r\n integer :: i, neq, nsteps\r\n double precision :: a, b, dt, tin, tout\r\n double precision, allocatable, dimension(:, :) :: archive\r\n double precision, allocatable, dimension(:) :: t, f1, yin, yout\r\n\r\n neq = 1\r\n a = 0.0d0\r\n b = 2.0d0\r\n nsteps = 1000\r\n\r\n allocate(yin(neq), yout(neq), t(0:nsteps), f1(neq), archive(neq,0:nsteps))\r\n\r\n dt = ((b - a) / dble(nsteps))\r\n\r\n do i = 0, nsteps\r\n t(i) = (a + dble(i) * dt)\r\n end do\r\n\r\n archive (:,0) = (/ 1.0d0, 0.0d0, 0.0d0, 1.0d0 /) ! initial state vector\r\n yin = archive(:,0)\r\n\r\n do i = 0, (nsteps - 1)\r\n tin = t(i)\r\n tout = t(i + 1)\r\n yin = archive(:,i)\r\n call extrapolate(neq, tin, tout, yin, yout)\r\n archive(:,i+1) = yout\r\n end do\r\n\r\n print*, 'Creating \"out5.2.2\"'\r\n open(unit=8, file='out5.2.2', status='replace')\r\n\r\n do i = 0, nsteps\r\n write(8,*) t(i), archive(1,i)\r\n end do\r\n\r\n close(8)\r\n deallocate(yin, yout, t, f1, archive)\r\n\r\n stop\r\nend program extrapall\r\n\r\n!-----------------------------------------------------------------------\r\n\r\nsubroutine extrapolate(neq, tin, tout, yin, yout)\r\n implicit none\r\n\r\n integer, intent(in) :: neq\r\n integer :: i, k, nrich, nsteps\r\n double precision :: yout(neq), bot\r\n double precision, intent(in) :: tin, tout, yin(neq)\r\n double precision, allocatable, dimension(:, :, :) :: table\r\n\r\n nrich = 10\r\n nsteps = 1\r\n allocate(table(0:nrich, 0:nrich, neq))\r\n\r\n do i = 0, nrich\r\n call euler(neq, tin, tout, nsteps, yin, yout)\r\n table(i,0,:) = yout\r\n nsteps = (nsteps * 2)\r\n end do\r\n\r\n do k = 1, nrich\r\n bot = (2.0d0**k - 1.0d0)\r\n do i = k, nrich\r\n table(i,k,:) = (table(i,k-1,:) + (table(i,k-1,:) - table(i-1,k-1,:)) / bot)\r\n end do\r\n end do\r\n\r\n yout = table(nrich, nrich, :)\r\n return\r\nend\r\n\r\n!-----------------------------------------------------------------------\r\n\r\nsubroutine euler(neq, tin, tout, nsteps, yin, yout)\r\n implicit none\r\n\r\n integer :: i\r\n integer, intent(in) :: neq, nsteps\r\n double precision :: yout(neq), f(neq), dt\r\n double precision, intent(in) :: tin, tout, yin(neq)\r\n\r\n yout = yin\r\n dt = ((tout - tin)/dble(nsteps))\r\n\r\n do i = 0, (nsteps - 1)\r\n call computef(neq, (tin + dble(i) * dt), yout, f)\r\n yout = (yout + dt * f)\r\n end do\r\n\r\n return\r\nend\r\n\r\n!-----------------------------------------------------------------------\r\n\r\nsubroutine computef(neq, t, y, f)\r\n implicit none\r\n integer :: neq\r\n double precision :: f(neq)\r\n double precision, intent(in) :: t, y(neq)\r\n ! This subroutine computes the RHS of the differential equation:\r\n ! dy\r\n ! -- = f(t, y)\r\n ! dt\r\n ! where y is the array of unknowns, indexed from one to neq and f is the array of right sides.\r\n\r\n f(1) = (t * dexp(3.0d0 * t) - 2.0d0 * y(1))\r\n\r\n return\r\nend\r\n", "meta": {"hexsha": "d788eebbc5e88415041aef3d2a75c499005c3a4d", "size": 3063, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "4670 Numerical Analysis/HomeworkG/Question2Method2.f90", "max_stars_repo_name": "mwebber3/UnderGraduateCourses", "max_stars_repo_head_hexsha": "0040791609ad4dd4336077f072106f8f31fdf8df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "4670 Numerical Analysis/HomeworkG/Question2Method2.f90", "max_issues_repo_name": "mwebber3/UnderGraduateCourses", "max_issues_repo_head_hexsha": "0040791609ad4dd4336077f072106f8f31fdf8df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "4670 Numerical Analysis/HomeworkG/Question2Method2.f90", "max_forks_repo_name": "mwebber3/UnderGraduateCourses", "max_forks_repo_head_hexsha": "0040791609ad4dd4336077f072106f8f31fdf8df", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.3095238095, "max_line_length": 109, "alphanum_fraction": 0.5341168789, "num_tokens": 1050, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853655, "lm_q2_score": 0.7690802370707283, "lm_q1q2_score": 0.6835268281299928}} {"text": "module v_cycle_mod\n\ncontains\n\n recursive subroutine v_cycle(ct,lvl,nlvl)\n\n use constants\n use multifab_module\n use traverse_mod\n use cycle_tower_mod\n\n implicit none\n\n ! Note: nlvl is different than ct%nlvl when in the FMG-cycle, because nlvl\n ! is the number of multigrid levels in whichever \"mini\" V-cycle is being called by\n ! the FMG-cycle, but ct%nlvl will always be the number of multigrid levels\n ! of the FMG-cycle.\n integer , intent(in) :: lvl ! Current multigrid level of this V-cycle\n integer , intent(in) :: nlvl ! Total multigrid levels of this V-cycle\n type(cycle_tower), intent(inout) :: ct\n\n integer :: i\n\n ! If not at the top, set solution guess to zero; use existing solution guess otherwise\n if (lvl /= nlvl) then\n call setval(ct%uu(lvl),0.d0,all=.true.)\n end if\n\n if (lvl == 1) then\n\n if (parallel_IOProcessor()) then\n call print_cycle_tower(ct,lvl,'Before relaxation: ')\n if (ct%verbose >= 2) then\n write(*,'(a,i3,a)') ' V Cycle BOTTOM -- Applying ',ct%v_bot,' relaxations.'\n end if\n end if\n\n ! Just smooth a bunch of times at the bottom; can choose different solver here\n do i = 1,ct%v_bot\n call gsrb(ct%uu(lvl),ct%ff(lvl),ct%bb(lvl,:),ct%dx(lvl))\n end do\n\n if (parallel_IOProcessor()) then\n call print_cycle_tower(ct,lvl,' After relaxation: ')\n end if\n\n else\n\n if (parallel_IOProcessor()) then\n call print_cycle_tower(ct,lvl,'Before relaxation: ')\n end if\n\n ! Smooth on the way down\n do i = 1,ct%s1\n call gsrb(ct%uu(lvl),ct%ff(lvl),ct%bb(lvl,:),ct%dx(lvl))\n end do\n\n if (parallel_IOProcessor()) then\n call print_cycle_tower(ct,lvl,' After relaxation: ')\n end if\n\n ! Coarsen and continue downwards\n call residual(ct%res(lvl),ct%uu(lvl),ct%ff(lvl),ct%bb(lvl,:),ct%dx(lvl))\n call restriction(ct%ff(lvl-1),ct%res(lvl))\n call v_cycle(ct,lvl-1,nlvl)\n\n if (parallel_IOProcessor()) then\n call print_cycle_tower(ct,lvl,'Before relaxation: ')\n end if\n\n ! Smooth on the way up\n do i = 1,ct%s2\n call gsrb(ct%uu(lvl),ct%ff(lvl),ct%bb(lvl,:),ct%dx(lvl))\n end do\n\n if (parallel_IOProcessor()) then\n call print_cycle_tower(ct,lvl,' After relaxation: ')\n end if\n\n end if\n\n ! If not at the top of this V-cycle, interpolate up and apply correction (i.e. prolongation)\n if (lvl /= nlvl) then\n call prolongation(ct%uu(lvl+1),ct%uu(lvl),ct%interp_type)\n end if\n\n ! If at the top of this V-cycle, and if this V-cycle is NOT part of an FMG-cycle,\n ! then save solution and fill ghost cells.\n if (lvl == nlvl .and. ct%cycle_type /= FMG_CYCLE_TYPE) then\n call copy(ct%sol,ct%uu(lvl))\n call multifab_fill_boundary(ct%sol)\n end if\n\n end subroutine v_cycle\n\nend module v_cycle_mod\n\n\n", "meta": {"hexsha": "7eb905aac8be69783d4d77437b2067f8e342b26a", "size": 3294, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorials/MultiGrid_F/v_cycle.f90", "max_stars_repo_name": "memmett/BoxLib", "max_stars_repo_head_hexsha": "a235af87d30cbfc721d4d7eb4da9b8daadeded7d", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 79, "max_stars_repo_stars_event_min_datetime": "2015-08-03T18:29:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-15T11:42:40.000Z", "max_issues_repo_path": "Tutorials/MultiGrid_F/v_cycle.f90", "max_issues_repo_name": "memmett/BoxLib", "max_issues_repo_head_hexsha": "a235af87d30cbfc721d4d7eb4da9b8daadeded7d", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": 22, "max_issues_repo_issues_event_min_datetime": "2016-06-15T20:46:49.000Z", "max_issues_repo_issues_event_max_datetime": "2018-09-10T21:33:10.000Z", "max_forks_repo_path": "Tutorials/MultiGrid_F/v_cycle.f90", "max_forks_repo_name": "memmett/BoxLib", "max_forks_repo_head_hexsha": "a235af87d30cbfc721d4d7eb4da9b8daadeded7d", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": 48, "max_forks_repo_forks_event_min_datetime": "2015-08-05T02:19:33.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-18T12:33:14.000Z", "avg_line_length": 33.2727272727, "max_line_length": 100, "alphanum_fraction": 0.5567698846, "num_tokens": 849, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853654, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6835268281299925}} {"text": "!----------------------------------------------------------------\n! (c) Copyright, 2016 by the Regents of the University of California.\n! PhysConstclass: physical constants class in CONSTANTS module of \n! DATA STRUCTURE layer.\n!\n! MODULE : ... PhysConstclass\n! VERSION : ... 1.0\n!> @author\n!> Ji Qiang, LBNL\n!\n! DESCRIPTION:\n!> This class defines the physical constant parameters used\n!> in the simulation.\n! Comments:\n!----------------------------------------------------------------\n module PhysConstclass\n use mpistub\n implicit none\n \n !physical parameters and constants ---------------------\n double precision :: Pi\n double precision :: Clight !< speed of light in vaccum\n double precision :: Scxl !< length scale\n double precision :: Rad2deg !< conversion factor from radian to degree\n double precision :: Epsilon0 !< permittivity of vacuum\n double precision :: Scfreq !< time scale\n contains\n subroutine construct_PhysConst(freq)\n double precision, intent(in) :: freq\n\n Clight = 299792458.0d0 \n Pi = 2*asin(1.0d0)\n Scxl = Clight/(2*pi*freq)\n Rad2deg = 180.0d0/Pi\n Epsilon0 = 8.854187817d-12\n Scfreq = freq\n\n end subroutine construct_PhysConst\n \n end module PhysConstclass\n", "meta": {"hexsha": "436b51a3bcea1dc9cbf37ada1b8ca10de5893c4a", "size": 1341, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/DataStruct/PhysConst.f90", "max_stars_repo_name": "elainejut/IMPACT-Z", "max_stars_repo_head_hexsha": "5e38c9d30b55d4fe3ed0c37811b52055300e6f13", "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": "src/DataStruct/PhysConst.f90", "max_issues_repo_name": "elainejut/IMPACT-Z", "max_issues_repo_head_hexsha": "5e38c9d30b55d4fe3ed0c37811b52055300e6f13", "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": "src/DataStruct/PhysConst.f90", "max_forks_repo_name": "elainejut/IMPACT-Z", "max_forks_repo_head_hexsha": "5e38c9d30b55d4fe3ed0c37811b52055300e6f13", "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": 32.7073170732, "max_line_length": 78, "alphanum_fraction": 0.5659955257, "num_tokens": 311, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318195, "lm_q2_score": 0.7690802264851919, "lm_q1q2_score": 0.6835268209880636}} {"text": "!*******************************************************************************\n! Solve a series of large (~1 million variable) symmetric positive-definite \n! finite difference matrix equations using the conjugate gradient method\n! preconditioned by the nested factorization algorithm described by \n! \"J. APPLEYARD AND I. CHESHIRE, Nested factorization, in Reservoir \n! Simulation Symposium of the SPE, 1983. Paper 12264.\" The method works \n! well with very stiff equations which defeat other iterative methods, and \n! is similar to that implemented in the widely used Eclipse oil reservoir\n! simulator.\n!\n! For a matrix \n!\n! A = D + L1 + U1 + L2 + U2 + L3 + U3\n!\n! where D is the matrix diagonal, \n! L1 and U1 are the bands connecting adjacent cells within a line, \n! L2 and U2 are the bands connecting adjacent lines within a plane, \n! and L3 and U3 are the bands connecting adjacent planes of the FD grid,\n!\n! D U1 U1 U3 Finite Difference Matrix for\n! L1 D U1 U2 U3 nx=3, ny=2, nz=2\n! L1 D U2 U3\n! L2 D U1 U3\n! L2 L1 D U1 U3\n! L2 L1 D U3\n! L3 D U1 U2\n! L3 L1 D U1 U2\n! L3 L1 D U2\n! L3 L2 D U1\n! L3 L2 L1 D U1\n! L3 L2 L1 D\n! \n! the preconditioning matrix, B^-1, is defined by the recursive equations\n! \n! B = (P+L3)(I+P^-1.U3) - B is block tridiagonal - block elements are planes\n! P = (T+L2)(I+T^-1.U2) - P is block tridiagonal - block elements are lines\n! T = (G+L1)(I+G^-1.U1) - T is tridiagonal\n! G = D - L1.G^-1.U1\n! - ColSum(E) - G is diagonal\n! E = L2.T^-1.U2 - L3.P^-1.*U3\n!\n! ColSum(E) is the diagonal matrix formed by summing the elements of E in \n! columns. Although, the definition of G is recursive, close examination \n! shows that each element depends only on the previous cell, line or plane.\n!\n! After expansion, we obtain\n!\n! B = A + E - Colsum(E)\n!\n! The fact that the column sum of the error matrix is zero is useful in \n! some cases - for example it ensures zero material balance error for every\n! plane in some CFD problems. It can also be used as a check on the\n! correctness of the implementation.\n!\n! This preconditioning is usually most effective when the L1, and U1 bands are \n! numerically largest, followed by L2, U2 and, finally, L3, U3. This happens\n! naturally in some problem domains - for example if the vertical extent of \n! finite difference grid blocks is smaller than the horizontal extent. \n!*******************************************************************************\nprogram NF\nimplicit none\n\n! Theses tests require about 120MBytes\n! nx ny nz bd1 bd2 bd3 stiff it rms method\ncall mattest(97,105,99,1D2,1D1,1D0,1000D0, 50,1D-7,'NFCG') ! NFCG best case - band1>band2>band3\ncall mattest(97,105,99,1D2,1D2,1D0,1000D0, 50,1D-7,'NFCG') ! NFCG band1=band2>band3\ncall mattest(97,105,99,1D1,1D2,1D0,100D0 , 50,1D-7,'NFCG') ! NFCG bad ordering - band1band2>band3\n!call mattest(97,105,99,1D2,1D1,1D0,1000D0, 50,1D-7,'VNFCG6')! invwstigate effect of approximation\n!call mattest(97,105,99,1D2,1D1,1D0,1000D0, 50,1D-7,'VNFCG5')! in tridiag solver\n!call mattest(97,105,99,1D2,1D1,1D0,1000D0, 50,1D-7,'VNFCG4')! \nend program NF\n\n!*******************************************************************************\n! Set up and solve matrix representing nx * ny * nz finite difference grid\n! Elements on 1st band (1 above and below diagonal) are set to band1\n! Elements on 2nd band (nx above and below diagonal) are set to band2\n! Elements on 3rd band (nx*ny above and below diagonal) are set to band3\n! All bands have gaps appropriate for nx * ny * nz geometry\n! Elements on diagonal = -sum(band elements in same column) - 1.0/stiffness\n! Up to maxiter iterations are allowed to reduce the rms residual to targrms\n! method='NFCG', 'ICCG', 'SIP3D0.nn' (alpha = 0.nn), 'VNFCGn'\n!*******************************************************************************\n\nsubroutine mattest(nx,ny,nz,band1,band2,band3,stiffness,maxiter,targrms,method)\nimplicit none\ninteger,parameter :: dpkind=kind(1.0D0)\ninteger :: nx , ny , nz , maxiter\ncharacter(*) :: method\nreal(dpkind) :: band1 , band2 , band3 , stiffness , targrms , alfa\nreal(dpkind),allocatable,dimension(:) :: ad,au1,au2,au3,x,b\ninteger :: nxyz , nxy , i , cycles\n\nwrite(*,'(/A,I4,A,I4,A,I4,A,A)') &\n ' Solve ',nx,' by',ny,' by',nz,' FD problem - method=',method\nwrite(*,'(A,F8.2,A,F8.2,A,F8.2,A,F10.2)') &\n ' Band elements are ',band1,', ',band2, &\n ', and ',band3,'. stiffness=',stiffness\nwrite(*,'(A,G13.4,A,I4/)') ' Target RMS residual =',targrms,' Maximum Iterations =',maxiter\n \n ! Set up matrix\nnxy = nx*ny ; nxyz = nxy*nz\nallocate(ad(nxyz),au1(nxyz),au2(nxyz),au3(nxyz),x(nxyz),b(nxyz))\nau1 = band1 ; au2 = band2 ; au3 = band3\nau1(nx:nxyz:nx) = 0.0\ndo i = nxy , nxyz , nxy \n au2(i-nx+1:i) = 0.0d0 \nenddo \nau3(nxyz-nxy+1:) = 0.0d0\nad = -1.0/stiffness - au1 - au2 - au3\nad(2:nxyz) = ad(2:nxyz) - au1(1:nxyz-1)\nad(nx+1:nxyz) = ad(nx+1:nxyz) - au2(1:nxyz-nx)\nad(nxy+1:nxyz) = ad(nxy+1:nxyz) - au3(1:nxyz-nxy)\n\nb=0.0 ; b(1) = 100.0 ! set up rhs\nx=0.0 ! set up initial solution vector\n\n ! solve using requested method \nif ( method=='NFCG' ) then \n call nfcg(nx,nxy,nxyz,ad,au1,au2,au3,x,b,maxiter,targrms)\n!elseif ( method(1:5)=='VNFCG' ) then\n! read(method(6:6),'(I1)') cycles\n! call vnfcg(nx,nxy,nxyz,ad,au1,au2,au3,x,b,maxiter,targrms,cycles)\n!elseif ( method=='ICCG' ) then \n! call iccg(nx,nxy,nxyz,ad,au1,au2,au3,x,b,maxiter,targrms)\n!elseif ( method(1:5)=='SIP3D' ) then \n! read(method(6:),*) alfa\n! call sip3d(nx,nxy,nxyz,ad,au1,au2,au3,x,b,maxiter,targrms,alfa)\n!elseif ( method=='CGSTAB' ) then \n! call cgstab(nx,nxy,nxyz,ad,au1,au2,au3,x,b,maxiter,targrms)\nendif\n\ndeallocate(ad,au1,au2,au3,x,b)\nend subroutine mattest\n!*******************************************************************************\n\n!*******************************************************************************\n! Solve using conjugate gradients pre-conditioned by nested factorization\n!*******************************************************************************\nsubroutine nfcg(nx,nxy,nxyz,ad,au1,au2,au3,x,b,maxiter,targrms) \nimplicit none ; integer,parameter :: dpkind=kind(1.0D0)\ninteger :: nx , nxy , nxyz , maxiter\nreal(dpkind),dimension(nxyz):: ad,au1,au2,au3,x,b\nreal(dpkind)::targrms\n\nreal(dpkind),allocatable,dimension(:) :: r,q,p,z,g,gi\nreal(dpkind):: alpha,beta,qr,qrp,rmserr\ninteger :: iter , tbase , tgi , tcg , tickspersec , maxticks\n\nallocate (gi(nxyz),g(nxyz))\ncall system_clock(tbase,tickspersec,maxticks)\ncall GetGI3D(1,nxyz) ! compute gi for preconditioning matrix \ncall system_clock(tgi,tickspersec,maxticks)\ndeallocate(g)\n\nallocate (r(nxyz),q(nxyz),p(nxyz),z(nxyz))\nCALL SPMMULT(x,r) ; r = b - r ! compute initial residual vector\n\nwrite(*,'(A)') ' Iter Alpha Beta RMS Residual Sum of Residuals'\nwrite(*,'(I4,24X,2G18.7)') 0,sqrt(DOT_PRODUCT(r,r)/nxyz),sum(r)\n\n ! Do a single iteration with alpha =1 \n ! to reduce sum of residuals to 0\np = r ; CALL NF3DPrecon(p,1,nxyz) ; CALL SPMMULT(p,z)\nx = x + p ; r = r - z\nwrite(*,'(I4,F12.5,12X,2G18.7)') 0,1.0,sqrt(DOT_PRODUCT(r,r)/nxyz),sum(r)\n\ndo iter = 1 , maxiter\n q = r ; CALL NF3DPrecon(q,1,nxyz)\n qr = DOT_PRODUCT(q,r)\n if ( iter==1 ) then\n beta = 0.0\n p = q\n else\n beta = qr/qrp\n p = q + beta*p\n endif\n qrp = qr\n CALL SPMMULT(p,z)\n alpha = qr/DOT_PRODUCT(p,z)\n x = x + alpha*p ; r = r - alpha*z\n rmserr = sqrt(DOT_PRODUCT(r,r)/nxyz)\n write(*,'(I4,2F12.5,3G18.7)') iter , alpha , beta , rmserr , sum(r)! , maxval(abs(r))\n if ( rmserri1 ) then ! get contribution from previous line\n g(i-nx:i-1) = au2(i-nx:i-1)\n call trisolve(g,i-nx,i-1)\n g(i:i+nx-1) = g(i:i+nx-1) - au2(i-nx:i-1)*g(i-nx:i-1)\n endif\n call GetGI1D(i,i+nx-1) ! get contribution from this line\nenddo\nend subroutine GetGI2D !=========================================\n\n !=========================================\n ! solve for a plane of cells using ======\nsubroutine NF2DPrecon(x,i1,i2) ! 2D NF Preconditioning matrix\ninteger :: i1 , i2\nreal(dpkind),dimension(i2)::x,t\ninteger :: i\ndo i = i1 , i2 , nx\n if ( i>i1 ) x(i:i+nx-1) = x(i:i+nx-1) - au2(i-nx:i-1)*x(i-nx:i-1)\n call trisolve(x,i,i+nx-1)\nenddo \ndo i = i2-2*nx+1 , i1 , -nx\n t(i:i+nx-1) = au2(i:i+nx-1)*x(i+nx:i+2*nx-1)\n call trisolve(t,i,i+nx-1)\n x(i:i+nx-1) = x(i:i+nx-1) - t(i:i+nx-1)\nenddo\nend subroutine NF2DPrecon !=========================================\n\n !=========================================\nsubroutine GetGI3D(i1,i2) ! compute gi for a 3D block of cells =====\ninteger :: i1 , i2\ninteger :: i\ng = ad\ndo i = i1 , i2 , nxy ! advance one plane at a time\n if ( i>i1 ) then ! get contribution from previous plane \n g(i-nxy:i-1) = au3(i-nxy:i-1)\n call NF2DPrecon(g,i-nxy,i-1)\n g(i:i+nxy-1) = g(i:i+nxy-1) - au3(i-nxy:i-1)*g(i-nxy:i-1)\n endif\n call GetGI2D(i,i+nxy-1) ! get contribution from this plane\nenddo\nend subroutine GetGI3D !=========================================\n\n !=========================================\n ! solve for a 3D block of cells using \nsubroutine NF3DPrecon(x,i1,i2) ! 3D Preconditioning matrix\ninteger :: i1 , i2\nreal(dpkind),dimension(i2)::x,t\ninteger :: i\ndo i = i1 , i2 , nxy\n if ( i>i1 ) x(i:i+nxy-1) = x(i:i+nxy-1) - au3(i-nxy:i-1)*x(i-nxy:i-1)\n call NF2DPrecon(x,i,i+nxy-1)\nenddo \ndo i = i2-2*nxy+1 , i1 , -nxy\n t(i:i+nxy-1) = au3(i:i+nxy-1)*x(i+nxy:i+2*nxy-1)\n call NF2DPrecon(t,i,i+nxy-1)\n x(i:i+nxy-1) = x(i:i+nxy-1) - t(i:i+nxy-1)\nenddo\nend subroutine NF3DPrecon !=========================================\n\nend subroutine nfcg \n!******************************************************************************\n\n!include '\\nf\\vnfcg.f90'\n!include '\\nf\\cgstab.f90'\n!include '\\nf\\iccg.f90'\n!include '\\nf\\sip3d.f90'\n", "meta": {"hexsha": "05e90f1cd361fc7142d620aa05698f9006d0a50a", "size": 13822, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "benchmarks/polyhedron-1.1/win/source/nf.f90", "max_stars_repo_name": "andrastantos/kcomp", "max_stars_repo_head_hexsha": "9c80f62310a617b2a0c147ab776ab7f36a6a7ec9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "benchmarks/polyhedron-1.1/win/source/nf.f90", "max_issues_repo_name": "andrastantos/kcomp", "max_issues_repo_head_hexsha": "9c80f62310a617b2a0c147ab776ab7f36a6a7ec9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2022-02-20T16:39:58.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-22T05:19:52.000Z", "max_forks_repo_path": "benchmarks/polyhedron-1.1/win/source/nf.f90", "max_forks_repo_name": "andrastantos/kcomp", "max_forks_repo_head_hexsha": "9c80f62310a617b2a0c147ab776ab7f36a6a7ec9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.5870967742, "max_line_length": 116, "alphanum_fraction": 0.522210968, "num_tokens": 4521, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587846530938, "lm_q2_score": 0.7690802370707283, "lm_q1q2_score": 0.6835268167996936}} {"text": "module extrapolation_limiting_mod\n !!\n !! Some useful routines for extrapolation and slope-limiting. These do not rely on the domain_type.\n !!\n\n use global_mod, only: dp, ip, charlen\n implicit none\n\n real(dp), parameter :: HALF_dp = 0.5_dp, ZERO_dp = 0.0_dp, ONE_dp=1.0_dp\n\n contains\n\n elemental function minmod(a,b) result(minmod_ab)\n !!\n !! minmod function, which is used in some gradient limiters\n !!\n !! @param a,b real numbers\n !!\n real(dp), intent(in):: a, b\n real(dp):: minmod_ab\n \n minmod_ab = merge(min(abs(a), abs(b))*sign(ONE_dp,a), ZERO_dp, sign(ONE_dp,a) == sign(ONE_dp,b))\n !minmod_ab = sign(one_dp, a) * max(zero_dp, min(abs(a), sign(one_dp, a)*b))\n\n end function\n\n elemental subroutine minmod_sub(a,b, minmod_ab)\n !!\n !! minmod subroutine, which is used in some gradient limiters\n !!\n !! @param a,b real numbers\n !!\n real(dp), intent(in):: a, b\n real(dp), intent(out):: minmod_ab\n\n if((a>ZERO_dp .and. b>ZERO_dp).or.(a ZERO_dp)\n end do\n\n else if(limiter_type == \"Superbee_variant\") then\n\n !$OMP SIMD\n do i = 1, n\n\n a = U_upper(i) - U_local(i)\n b = U_local(i) - U_lower(i)\n ! Divide by 1.6 which is the default 'max theta' in the rk2 algorithms\n th = theta(i) * 2.0_dp/1.6_dp\n !d = minmod(a, th*b)\n d = merge(min(abs(a), abs(th*b))*sign(ONE_dp,a), ZERO_dp, sign(ONE_dp,a) == sign(ONE_dp,b))\n !e = minmod(th*a, b)\n e = merge(min(abs(th*a), abs(b))*sign(ONE_dp,a), ZERO_dp, sign(ONE_dp,a) == sign(ONE_dp,b))\n if(abs(e) > abs(d)) then\n b = e\n else\n b = d\n endif\n gradient_dx(i) = b \n end do\n\n else if(limiter_type == \"Minmod2\") then\n ! Same as 'MC' (!!!)\n\n !$OMP SIMD\n do i = 1, n\n\n a = U_upper(i) - U_local(i)\n b = U_local(i) - U_lower(i)\n th = theta(i)\n e = HALF_dp * (a + b)\n a = a * th\n b = b * th\n if(b > ZERO_dp .and. a > ZERO_dp) then\n ! Positive slopes\n if(b < a) a = b\n d = min(e, a)\n else if(b < ZERO_dp .and. a < ZERO_dp) then\n ! Negative slopes\n if(b > a) a = b\n d = max(e, a)\n else\n d = ZERO_dp\n endif\n gradient_dx(i) = d\n end do\n\n else if(limiter_type == 'nolimit') then\n\n gradient_dx = HALF_dp * (U_upper - U_lower)\n\n else \n gradient_dx = ZERO_dp\n end if\n \n\n end subroutine\n\n !\n ! This is the same as the above routine, but elemental so not necessarily vectorized.\n ! It allows trying a different loop structure elsewhere in the code.\n !\n pure elemental subroutine limited_gradient_dx(U_local, U_lower, U_upper, theta, gradient_dx)\n !!\n !! Slope limiter -- get the \"gradient times dx\" around U_local, given the upper and lower values of U.\n !!\n real(dp), intent(in):: U_local !! U_{i}\n real(dp), intent(in):: U_lower !! U_{i-1}\n real(dp), intent(in):: U_upper !! U_{i+1}\n real(dp), intent(in):: theta !! Limiter parameter, often in [1-2].\n real(dp), intent(out) :: gradient_dx !! Output\n\n real(dp):: a, b, c, d, e, th, sa, sb, half_sasb\n\n a = U_upper - U_local\n b = U_local - U_lower\n th = theta\n sa = sign(ONE_dp,a)\n sb = sign(ONE_dp,b)\n half_sasb = HALF_dp * (sa + sb)\n d = min(abs(a), abs(b)) * half_sasb * th ! Limit on local gradient\n e = HALF_dp * (a + b)\n c = merge(ZERO_dp, e, d == ZERO_dp) \n ! NOTE: IF d /= 0, then clearly d, c have the same sign\n ! We exploit this to avoid a further minmod call (which seems\n ! expensive)\n gradient_dx = merge(min(c, d), max(c, d), d > ZERO_dp)\n\n end subroutine\n\n subroutine test_extrapolation_limiting_mod\n !! Unit tests\n \n integer(ip), parameter :: N = 10\n real(dp) :: U(N), U_lower(N), U_upper(N)\n real(dp) :: theta(N), extrapolation_sign(N)\n real(dp) :: desired_answer(N), answer(N)\n integer(ip) :: i, version\n\n ! Test both versions of the limited gradient extrapolation routine\n do version = 1, 2\n\n theta = 1.0_dp\n U = (/(i*1.0_dp - 5.5_dp, i = 1, N)/)\n U_lower = U - 1.0_dp\n U_upper = U + 1.0_dp\n\n ! Basic extrapolation tests, positive side\n extrapolation_sign=1.0_dp\n call test_both_limited_gradient_dx_vectorized(version, U, U_lower, U_upper, theta, answer, N)\n desired_answer = 0.5_dp * (U + U_upper)\n call assert_equal_within_tol(desired_answer, U + HALF_dp*extrapolation_sign*answer, __LINE__)\n\n ! As above, negative side\n extrapolation_sign = -1.0_dp\n call test_both_limited_gradient_dx_vectorized(version, U, U_lower, U_upper, theta, answer, N)\n desired_answer = 0.5_dp * (U + U_lower)\n call assert_equal_within_tol(desired_answer, U + HALF_dp*extrapolation_sign*answer, __LINE__)\n\n ! As above, negative side, reduced theta\n theta = 0.5_dp\n extrapolation_sign = -1.0_dp\n call test_both_limited_gradient_dx_vectorized(version, U, U_lower, U_upper, theta, answer, N)\n desired_answer = 0.5_dp * U + 0.5_dp*0.5_dp * (U + U_lower)\n call assert_equal_within_tol(desired_answer, U+HALF_dp*extrapolation_sign*answer, __LINE__)\n\n ! As above, negative side, zero theta\n theta = 0.0_dp\n extrapolation_sign = 1.0_dp\n call test_both_limited_gradient_dx_vectorized(version, U, U_lower, U_upper, theta, answer, N)\n desired_answer = 1.0_dp * U + 0.0_dp*0.5_dp * (U + U_lower)\n call assert_equal_within_tol(desired_answer, U+HALF_dp*extrapolation_sign*answer, __LINE__)\n\n ! Local min.\n theta = 4.0_dp\n extrapolation_sign = 1.0_dp\n U_lower = U + 2.0_dp\n U_upper = U + 3.0_dp\n call test_both_limited_gradient_dx_vectorized(version, U, U_lower, U_upper, theta, answer, N)\n desired_answer = U \n call assert_equal_within_tol(desired_answer, U+HALF_dp*extrapolation_sign*answer, __LINE__)\n\n ! Local max.\n theta = 4.0_dp\n U_lower = U - 2.0_dp\n U_upper = U - 3.0_dp\n extrapolation_sign = -1.0_dp\n call test_both_limited_gradient_dx_vectorized(version, U, U_lower, U_upper, theta, answer, N)\n desired_answer = U \n call assert_equal_within_tol(desired_answer, U+HALF_dp*extrapolation_sign*answer, __LINE__)\n\n ! Limited gradients\n ! \n ! Central gradient = 2, lower-gradient=1, upper-gradient=3\n U_lower = U - 1.0_dp\n U_upper = U + 3.0_dp\n extrapolation_sign = 1.0_dp\n theta = 1.0_dp ! Limited-gradient = 1\n call test_both_limited_gradient_dx_vectorized(version, U, U_lower, U_upper, theta, answer, N)\n desired_answer = U + 0.5_dp * 1.0_dp\n call assert_equal_within_tol(desired_answer, U+HALF_dp*extrapolation_sign*answer, __LINE__)\n\n theta = 1.5_dp ! Limited-gradient = 1.5\n call test_both_limited_gradient_dx_vectorized(version, U, U_lower, U_upper, theta, answer, N)\n desired_answer = U + 0.5_dp * 1.5_dp\n call assert_equal_within_tol(desired_answer, U+HALF_dp*extrapolation_sign*answer, __LINE__)\n\n \n extrapolation_sign = -1.0_dp ! As above, negative side\n call test_both_limited_gradient_dx_vectorized(version, U, U_lower, U_upper, theta, answer, N)\n desired_answer = U - 0.5_dp * 1.5_dp\n call assert_equal_within_tol(desired_answer, U+HALF_dp*extrapolation_sign*answer, __LINE__)\n end do\n\n contains\n\n subroutine assert_equal_within_tol(desired_answer, answer, line)\n real(dp) :: desired_answer(N), answer(N)\n integer :: line\n\n real(dp) :: tol\n\n tol = spacing(1.0_dp) * 100\n\n if(all(abs(desired_answer - answer) < tol)) then\n print*, 'PASS'\n else\n print*, 'FAIL', line, desired_answer - answer\n end if\n\n end subroutine\n\n ! Use this to test one or the other variant of the extrapolation routine\n subroutine test_both_limited_gradient_dx_vectorized(version, U, U_lower, U_upper, theta, answer, N)\n integer(ip), intent(in) :: N, version\n real(dp), intent(in) :: U(N), U_lower(N), U_upper(N)\n real(dp), intent(in) :: theta(N)\n real(dp), intent(inout) :: answer(N)\n\n if(version == 1) then\n call limited_gradient_dx_vectorized(U, U_lower, U_upper, theta, answer, N)\n else if (version == 2) then\n call limited_gradient_dx(U, U_lower, U_upper, theta, answer)\n else\n print*, 'unknown version of limited_gradient_dx in test suite'\n stop\n end if\n\n end subroutine\n\n end subroutine\n\nend module\n", "meta": {"hexsha": "0e7370b9753d57076f91625a854f062f17975e5d", "size": 11419, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "propagation/SWALS/src/shallow_water/extrapolation_limiting_mod.f90", "max_stars_repo_name": "GeoscienceAustralia/ptha", "max_stars_repo_head_hexsha": "65a9c7936c1f61a5681833f7a0462ac9b3d514c4", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2017-03-28T02:33:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-10T01:11:24.000Z", "max_issues_repo_path": "propagation/SWALS/src/shallow_water/extrapolation_limiting_mod.f90", "max_issues_repo_name": "GeoscienceAustralia/ptha", "max_issues_repo_head_hexsha": "65a9c7936c1f61a5681833f7a0462ac9b3d514c4", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2021-11-15T22:44:38.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-02T06:04:18.000Z", "max_forks_repo_path": "propagation/SWALS/src/shallow_water/extrapolation_limiting_mod.f90", "max_forks_repo_name": "GeoscienceAustralia/ptha", "max_forks_repo_head_hexsha": "65a9c7936c1f61a5681833f7a0462ac9b3d514c4", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-11-08T21:22:37.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-07T11:36:39.000Z", "avg_line_length": 38.8401360544, "max_line_length": 115, "alphanum_fraction": 0.544093178, "num_tokens": 3013, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278726384089, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6835139724615176}} {"text": "!! module for hilbert transform\nmodule m_hilbert_transform\n use constants, only : CUSTOM_REAL\n implicit none \n\n complex :: CI=(0.0,1.0)\n\ncontains\n\n subroutine hilbert(trace,nt)\n !! return hilbert transform of real signal trace(nt)\n !! i.e. imaginary part of analytic signal \n !! a = cmplx(trace, hilbert(trace))\n\n integer, intent(in) :: nt\n real(kind=CUSTOM_REAL), intent(inout) :: trace(nt)\n\n complex, allocatable, dimension(:) :: C\n integer :: NPT,IMID \n\n ! extend nt to a power of 2\n IF ( nt <= 0 ) STOP 'FATAL ERROR in HILBERT: nt must be positive'\n\n NPT = 2**( INT( LOG10( REAL( nt ) ) / 0.30104 ) + 1 )\n ! IF ( NPT /= nt) print*,'pad trace from length ', nt, ' to ',NPT\n IF (NPT > 16784) STOP 'FATAL ERROR in HILBERT: nt(NPT) exceeds 16784 '\n\n allocate(C(NPT))\n C=cmplx(0.,0.)\n C(1:nt)=cmplx(trace(1:nt),0.0)\n\n ! Fourier transform \n call CFFT(C,NPT,1)\n ! scaling \n C=C/NPT\n\n ! Multiply by i * sgn( f )\n IMID = NPT / 2\n C( 1:IMID-1 ) = -CI * C( 1:IMID-1 ) ! pos. spectrum (-i)\n C( IMID ) = 0.0 ! d.c. component\n C(IMID+1:NPT) = CI * C( IMID+1:NPT ) ! neg. spectrum (i)\n\n ! inverse Fourier transform\n call CFFT(C,NPT,-1) \n\n ! output\n trace(1:nt)=real(C(1:nt))\n\n deallocate(C)\n\n end subroutine hilbert\n\n SUBROUTINE CFFT(trace,N,iforw)\n !!! complex FFT\n IMPLICIT NONE \n integer, intent(in) :: N, iforw\n complex, intent(inout) :: trace(N)\n INTEGER :: I1, I2A, I2B, I3, I3Rev, IP1, IP2, ISign\n REAL :: theta, sinth\n COMPLEX :: TEMP, W, WSTP\n\n ISIGN = -IFORW\n I3REV = 1\n\n DO I3 = 1, N\n IF ( I3 < I3REV ) THEN ! switch values\n TEMP = trace( I3 )\n trace( I3 ) = trace( I3REV )\n trace( I3REV ) = TEMP\n ENDIF\n ! following loop is just to compute I3REV\n IP1 = N / 2\n DO WHILE ( I3REV > IP1 )\n IF ( IP1 <= 1 ) EXIT\n I3REV = I3REV - IP1\n IP1 = IP1 / 2\n END DO\n I3REV = I3REV + IP1\n END DO\n\n IP1 = 1\n\n DO WHILE ( IP1 < N )\n IP2 = IP1 * 2\n THETA = 6.283185307 / FLOAT( ISIGN * IP2 )\n SINTH = SIN( THETA / 2.)\n WSTP = CMPLX( -2. * SINTH * SINTH, SIN( THETA ) )\n W = 1.\n\n DO I1 = 1, IP1\n DO I3 = I1, N, IP2\n I2A = I3\n I2B = I2A + IP1\n TEMP = W * trace( I2B )\n trace( I2B ) = trace( I2A ) - TEMP\n trace( I2A ) = trace( I2A ) + TEMP\n END DO\n\n W = W * WSTP + W\n END DO\n\n IP1 = IP2\n END DO\n\n RETURN\n END SUBROUTINE CFFT\n\nend module m_hilbert_transform\n", "meta": {"hexsha": "298798426c8fb8208ada7b256bb309e59d7b79b0", "size": 2892, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "SeisElastic2D/lib/src/m_hilbert_transform.f90", "max_stars_repo_name": "PanIGGCAS/SeisElastic2D_1.1", "max_stars_repo_head_hexsha": "2872dc514b638237771f4071195f7b8f90e0ce3d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2020-10-04T01:55:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-14T05:20:50.000Z", "max_issues_repo_path": "SeisElastic2D/lib/src/m_hilbert_transform.f90", "max_issues_repo_name": "PanIGGCAS/SeisElastic2D_1.1", "max_issues_repo_head_hexsha": "2872dc514b638237771f4071195f7b8f90e0ce3d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-10-31T03:36:34.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-27T09:36:13.000Z", "max_forks_repo_path": "SeisElastic2D/lib/src/m_hilbert_transform.f90", "max_forks_repo_name": "PanIGGCAS/SeisElastic2D_1.1", "max_forks_repo_head_hexsha": "2872dc514b638237771f4071195f7b8f90e0ce3d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-12-15T02:04:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-15T21:48:35.000Z", "avg_line_length": 26.5321100917, "max_line_length": 78, "alphanum_fraction": 0.4782157676, "num_tokens": 962, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544912, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6835139676715576}} {"text": "subroutine apply_linearized_pde_operator(t, q, p, output)\n\n! For the PDE q_t = g(q), calculates g'[q](p), i.e. the linearization\n! of g, about q, applied to perturbation p\n!\n! Args:\n! t: Time at which the operator is evaluated.\n! q: Base function of the linearization.\n! p: Perturbation to which the linearized operator is applied.\n! output: g'[q](p), calculated here.\n\n implicit none\n\n integer :: mx, mbc, meqn\n double precision :: dx, x_lower\n common /claw_config/ mx, mbc, x_lower, dx, meqn\n\n double precision, intent(in) :: t\n double precision, dimension(1-mbc:mx+mbc, meqn), intent(in) :: q, p\n double precision, dimension(1-mbc:mx+mbc, meqn), intent(out) :: output\n\n integer :: ix\n double precision, dimension(1:mx+1) :: fprime ! Linearized flux\n double precision :: q1_face, p1_face, q1_xxx, p1_xxx\n\n ! Compute linearized flux at interfaces.\n !$omp parallel do\n do ix = 1, mx+1\n q1_face = (q(ix-1, 1) + q(ix, 1)) / 2.d0\n p1_face = (p(ix-1, 1) + p(ix, 1)) / 2.d0\n q1_xxx = &\n (-q(ix-2, 1) + 3 * q(ix-1, 1) - 3 * q(ix, 1) + q(ix+1, 1)) &\n / dx**3\n p1_xxx = &\n (-p(ix-2, 1) + 3 * p(ix-1, 1) - 3 * p(ix, 1) + p(ix+1, 1)) &\n / dx**3\n fprime(ix) = q1_xxx * p1_face + q1_face * p1_xxx \n end do\n\n !$omp parallel do\n do ix = 1, mx\n output(ix, 1) = -(fprime(ix+1) - fprime(ix)) / dx\n end do\n\nend subroutine apply_linearized_pde_operator\n", "meta": {"hexsha": "7833f6ce15e5a83ae0eb50a531e92312dc882c3c", "size": 1499, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "applications/1d/Order4Nonlinear/apply_linearized_pde_operator.f90", "max_stars_repo_name": "claridge/implicit_solvers", "max_stars_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-04-29T00:16:18.000Z", "max_stars_repo_stars_event_max_datetime": "2017-04-29T00:16:18.000Z", "max_issues_repo_path": "applications/1d/Order4Nonlinear/apply_linearized_pde_operator.f90", "max_issues_repo_name": "claridge/implicit_solvers", "max_issues_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "applications/1d/Order4Nonlinear/apply_linearized_pde_operator.f90", "max_forks_repo_name": "claridge/implicit_solvers", "max_forks_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.5869565217, "max_line_length": 74, "alphanum_fraction": 0.5737158105, "num_tokens": 534, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278633625322, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6835139652765775}} {"text": "!\n! (c) 2019 Guide Star Engineering, LLC\n! This Software was developed for the US Nuclear Regulatory Commission (US NRC)\n! under contract \"Multi-Dimensional Physics Implementation into Fuel Analysis under\n! Steady-state and Transients (FAST)\", contract # NRC-HQ-60-17-C-0007\n!\nprogram test_class_vector\n !! label: Morfeus-FV\n !!\n !! Test vector class behavior\n\n use assertions_interface, only : assert\n use class_vector, only : vector, operator(.dot.), vector_\n use class_psblas, only : psb_dpk_\n\n implicit none\n\n type(vector) :: a(3), b, c\n real(psb_dpk_), parameter :: tolerance=1.0E-06, one=1.0_psb_dpk_, zero=0.0_psb_dpk_\n\n a = [vector_(zero, zero, zero), vector_(one, zero, zero), vector_(zero, one, zero)]\n b = vector_(zero, zero, one) ! perpendicular to all vectors in a\n c = a .dot. b ! = [a(1) .dot. b, a(2) .dot. b, a(3) .dot. b] = [zero, zero, zero]\n\n test_operators: &\n block\n call assert( c%mag() <= tolerance, \"fv-test-class_vector: mag()\" )\n end block test_operators\n\n print *, \"Test passed.\"\n\nend program test_class_vector\n", "meta": {"hexsha": "a71eda50f56785bb215771634787b7cd2810b207", "size": 1104, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/FV/src/unit-tests/fv-test-class_vector.f90", "max_stars_repo_name": "sourceryinstitute/MORFEUS-Source", "max_stars_repo_head_hexsha": "38659b1097e89e3dea8f5e7e83acf98bfe6623bd", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 19, "max_stars_repo_stars_event_min_datetime": "2019-09-19T03:00:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T02:07:07.000Z", "max_issues_repo_path": "src/FV/src/unit-tests/fv-test-class_vector.f90", "max_issues_repo_name": "sourceryinstitute/MORFEUS-Source", "max_issues_repo_head_hexsha": "38659b1097e89e3dea8f5e7e83acf98bfe6623bd", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 43, "max_issues_repo_issues_event_min_datetime": "2019-09-10T04:59:39.000Z", "max_issues_repo_issues_event_max_datetime": "2020-02-28T22:02:45.000Z", "max_forks_repo_path": "src/FV/src/unit-tests/fv-test-class_vector.f90", "max_forks_repo_name": "sourceryinstitute/MORFEUS-Source", "max_forks_repo_head_hexsha": "38659b1097e89e3dea8f5e7e83acf98bfe6623bd", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-01-28T03:13:26.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-06T04:13:20.000Z", "avg_line_length": 33.4545454545, "max_line_length": 87, "alphanum_fraction": 0.6639492754, "num_tokens": 335, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705731, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6835139628815974}} {"text": "module art\n\nuse iso_fortran_env, only: wp=>real64\n\nimplicit none\n\ncontains\n\npure subroutine logmart(A,b,relax,x0,sigma,max_iter, x)\n! delta Chisquare.\n! stopped if Chisquare increases.\n!\n! Inputs\n! ------\n! A: NxM array\n! b: N vector\n! relax: user specified relaxation constant\t(default is 20.)\n! x0: user specified initial guess (Nx1 vector) (default is backproject y, i.e., y#A)\n! max_iter: user specified max number of iterations (default is 20)\n!\n!\n! Outputs\n! -------\n! x: N vector\n!\n!\n! AUTHOR:\tJoshua Semeter\n! LAST MODIFIED:\t5-2015\n!\n! Simple test problem\n! A = diag([5, 5, 5])\n! x = [1,2,3]\n! b = A*x\n\n! --- parameter check\nreal(wp), intent(in) :: A(:,:), b(:)\nreal(wp), optional, value :: relax, sigma\nreal(wp), intent(in),optional :: x0(:)\ninteger, optional, value :: max_iter\nreal(wp), intent(out) :: x(:)\n\nreal(wp), dimension(size(b)) :: W(size(b)), x_prev,c, op_b\ninteger :: i\nreal(wp) :: t,chi2,chiold\n\n\nif (.not.size(A,1) == size(b)) error stop 'A and b row numbers must match'\nif (any(A<0)) error stop 'A must be non-negative'\nif (any(b<0)) error stop 'b must be non-negative'\nop_b = b\n! --- make sure there are no 0's in b\nwhere(op_b <= 1e-8) op_b = 1e-8_wp\n\n! --- set defaults\nif (.not.present(relax)) relax = 1\nif (.not.present(max_iter)) max_iter = 200\nif (.not.present(sigma)) sigma = 1\n\nif (.not.present(x0)) then\n x = matmul(transpose(A), op_b) / sum(A)\n x = x * maxval(op_b) / maxval(matmul(A, x))\nelse\n x = x0\nendif\n\n\n\n! W=sigma;\n! W=linspace(1,0,size(A,1))';\n! W=rand(size(A,1),1);\nW = 1\nW = W / sum(W)\n\n! --- iterate solution\nchi2 = chi_squared(A, op_b, x, sigma)\n\ndo i = 1, max_iter\n x_prev = x\n t = minval(1/matmul(A,x))\n C = relax*t*(1-(matmul(A,x)/op_b))\n x = x / (1-x*matmul(transpose(A),W*C))\n! monitor solution\n chiold = chi2\n chi2 = chi_squared(A, op_b, x, sigma)\n if (chi2 > chiold .and. i > 2) exit\nenddo\n\nx = x_prev\n\nend subroutine logmart\n\n\npure real(wp) function chi_squared(A, b, x, sigma)\nreal(wp), intent(in) :: A(:,:), b(:), x(:), sigma\nchi_squared = sqrt(sum(((matmul(A,x) - b) / sigma)**2))\n\nend function chi_squared\n\nend module art\n", "meta": {"hexsha": "2e6f7130255056fa21ca3e249edd3d4c2d1b6725", "size": 2114, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/logmart.f90", "max_stars_repo_name": "scienceopen/pyAIRtools", "max_stars_repo_head_hexsha": "655fb228cbe8e226c41d9c75d884ef25c27cc611", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2017-05-06T15:09:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T22:13:34.000Z", "max_issues_repo_path": "fortran/logmart.f90", "max_issues_repo_name": "scienceopen/pyAIRtools", "max_issues_repo_head_hexsha": "655fb228cbe8e226c41d9c75d884ef25c27cc611", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-10-04T16:52:34.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-04T16:52:34.000Z", "max_forks_repo_path": "fortran/logmart.f90", "max_forks_repo_name": "scienceopen/pyAIRtools", "max_forks_repo_head_hexsha": "655fb228cbe8e226c41d9c75d884ef25c27cc611", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-06-06T19:21:09.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-24T13:06:13.000Z", "avg_line_length": 21.14, "max_line_length": 86, "alphanum_fraction": 0.6277199622, "num_tokens": 732, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.88242786954645, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.6835139608829278}} {"text": "! =============================================================================\n! Test ellipse orientation\n!\n! This unit test checks the ellipse orientation computed using the\n! B matrix values, i.e., B11 and B12. The angle computed via the\n! B matrix is within [-pi/2, pi/2].\n! =============================================================================\nprogram test_ellipse_orientation\n use unit_test\n use constants, only : pi, zero, two, three, f14\n use parcel_container, only : parcels, n_parcels, parcel_alloc, parcel_dealloc\n use parcel_ellipse\n implicit none\n\n double precision :: extent(2) = (/0.2d0, 0.2d0/)\n integer :: iter\n integer :: grid(2) = (/2, 2/)\n double precision :: angle, B11, B12, V, a2, b2\n double precision, parameter :: lam = three\n logical :: passed = .true.\n\n n_parcels = 1\n call parcel_alloc(1)\n\n parcels%position = zero\n parcels%volume = f14 * product(extent / (grid - 1))\n\n V = parcels%volume(1)\n\n a2 = (lam * V) / pi\n b2 = V / (pi * lam)\n\n do iter = 0, 360\n\n angle = dble(iter) * pi / 180.0d0\n\n B11 = a2 * dcos(angle) ** 2 + b2 * dsin(angle) ** 2\n\n B12 = (a2 - b2) * dsin(angle) * dcos(angle)\n\n parcels%B(1, 1) = B11\n\n parcels%B(2, 1) = B12\n\n ! get_angle computes the angle in the first and fourth quadrant, i.e.,\n ! -pi/2 <= get_angle <= pi/2\n if (angle > pi / two .and. angle <= three * pi / two) then\n angle = angle - pi\n else if (angle > three * pi / two) then\n angle = angle - two * pi\n endif\n\n passed = (passed .and. abs(angle - get_angle(B11, B12, V)) < dble(1.0e-13))\n\n enddo\n\n call parcel_dealloc()\n\n call print_result_logical('Test ellipse orientation', passed)\n\nend program test_ellipse_orientation\n", "meta": {"hexsha": "4fd3f123d74ce35111d4098cbd66ad6436d0dea6", "size": 1849, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "unit-tests/2d/test_ellipse_orientation.f90", "max_stars_repo_name": "matt-frey/epic", "max_stars_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2021-11-11T10:50:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T00:11:41.000Z", "max_issues_repo_path": "unit-tests/2d/test_ellipse_orientation.f90", "max_issues_repo_name": "matt-frey/epic", "max_issues_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 47, "max_issues_repo_issues_event_min_datetime": "2021-11-12T17:09:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-24T16:50:58.000Z", "max_forks_repo_path": "unit-tests/2d/test_ellipse_orientation.f90", "max_forks_repo_name": "matt-frey/epic", "max_forks_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.8225806452, "max_line_length": 83, "alphanum_fraction": 0.5332612223, "num_tokens": 519, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278540866548, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.683513958091637}} {"text": " SUBROUTINE GAUSSJ(A,N,NP,B,M,MP)\nc\tnote added from 2nd edition, which is not the same as the first, \nc\tbelow\nc\tlinear equations solution by Gauss Jordan elimination, equation \nc\t(2.1.1) above. a(1;n,1:n) is an input matrix stored in an array\nc\tof physical dimensions np by np. b(1:n,1:m) is an input matrix \nc\tcontaining the m right-hand side vectors, stored in an array of\nc\tphysical dimensions np by mp. On output, a(1:n,1:n) is replaced\nc\tby its matrix inverse and b(1:n,1:m) is replace by the corresponding\nc\tset of solution vectors.\nc\tParameter: NMAX is the largest anticpated value of n\nc\n PARAMETER (NMAX=50)\n DIMENSION A(NP,NP),B(NP,MP),IPIV(NMAX),INDXR(NMAX),INDXC(NMAX)\n DO 11 J=1,N\n IPIV(J)=0\n11 CONTINUE\n DO 22 I=1,N\n BIG=0.\n DO 13 J=1,N\n IF(IPIV(J).NE.1)THEN\n DO 12 K=1,N\n IF (IPIV(K).EQ.0) THEN\n IF (ABS(A(J,K)).GE.BIG)THEN\n BIG=ABS(A(J,K))\n IROW=J\n ICOL=K\n ENDIF\n ELSE IF (IPIV(K).GT.1) THEN\nC PAUSE 'Singular matrix'\n PRINT*, 'Singular matrix'\n\t\tRETURN\n ENDIF\n12 CONTINUE\n ENDIF\n13 CONTINUE\n IPIV(ICOL)=IPIV(ICOL)+1\n IF (IROW.NE.ICOL) THEN\n DO 14 L=1,N\n DUM=A(IROW,L)\n A(IROW,L)=A(ICOL,L)\n A(ICOL,L)=DUM\n14 CONTINUE\n DO 15 L=1,M\n DUM=B(IROW,L)\n B(IROW,L)=B(ICOL,L)\n B(ICOL,L)=DUM\n15 CONTINUE\n ENDIF\n INDXR(I)=IROW\n INDXC(I)=ICOL\nC IF (A(ICOL,ICOL).EQ.0.) PAUSE 'Singular matrix.'\n IF (A(ICOL,ICOL).EQ.0.) THEN\n\t\tPRINT*, 'Singular matrix.'\n\t\tRETURN\n\tENDIF\n PIVINV=1./A(ICOL,ICOL)\n A(ICOL,ICOL)=1.\n DO 16 L=1,N\n A(ICOL,L)=A(ICOL,L)*PIVINV\n16 CONTINUE\n DO 17 L=1,M\n B(ICOL,L)=B(ICOL,L)*PIVINV\n17 CONTINUE\n DO 21 LL=1,N\n IF(LL.NE.ICOL)THEN\n DUM=A(LL,ICOL)\n A(LL,ICOL)=0.\n DO 18 L=1,N\n A(LL,L)=A(LL,L)-A(ICOL,L)*DUM\n18 CONTINUE\n DO 19 L=1,M\n B(LL,L)=B(LL,L)-B(ICOL,L)*DUM\n19 CONTINUE\n ENDIF\n21 CONTINUE\n22 CONTINUE\n DO 24 L=N,1,-1\n IF(INDXR(L).NE.INDXC(L))THEN\n DO 23 K=1,N\n DUM=A(K,INDXR(L))\n A(K,INDXR(L))=A(K,INDXC(L))\n A(K,INDXC(L))=DUM\n23 CONTINUE\n ENDIF\n24 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "8b0596e7476ffd226f49c0e959d2f4b9b4bbd6d1", "size": 2547, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "WAVES_VMS_Fortran/TDS_src_VAX/gaussj.for", "max_stars_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_stars_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "WAVES_VMS_Fortran/TDS_src_VAX/gaussj.for", "max_issues_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_issues_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "WAVES_VMS_Fortran/TDS_src_VAX/gaussj.for", "max_forks_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_forks_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.6179775281, "max_line_length": 70, "alphanum_fraction": 0.5056929721, "num_tokens": 874, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278571786139, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.6835139558948125}} {"text": "program test\n\n use precision\n use globals\n use fft\n use misc\n\n\n integer(idp) :: i, j, k\n integer(idp), dimension(2) :: n\n real(fdp), dimension(2) :: t\n complex(cdp), dimension(:,:), allocatable :: a, dely, delx, xdelydel, array_t, x, y, t1, t2\n\n\n read(*,*) n\n\n parameters%n = n\n parameters%pspacing = 1.0d0/dble(n)\n parameters%gridspacing = 1.0\n\n allocate(xdelydel(n(1), n(2)), dely(n(1), n(2)), delx(n(1), n(2)), array_t(n(1), n(2)), a(n(1), n(2)), x(n(1), n(2)), y(n(1), n(2)), t1(n(1), n(2)), t2(n(1), n(2)))\n \n do j=1, n(2)\n do i=1, n(1)\n\n a(i, j) = exp(-dble(i-n(1)/3)**2/50.0d0-dble(j-n(2)/3)**2/50)\n\n end do\n end do\n\n call s_momentumfac(xdelydel, (/ 1.0d0, 1.0d0 /), (/ 1, 1 /()\n \n call s_momentumfac(array_t, (/ 1.0d0, 1.0d0 /), (/ 1, 1 /))\n \n call s_momentumfac(dely, (/ 1.0d0, 1.0d0 /), (/ 1, 1 /))\n \n call s_momentumfac(delx, (/ 1.0d0, 1.0d0 /), (/ 1, 1 /))\n \n write(*,*) \"a \",sum(abs(a))\n write(*,*) \"array_t \",sum(abs(array_t))\n write(*,*) \"xdelydel \",sum(abs(xdelydel))\n write(*,*) \"delx \",sum(abs(delx))\n write(*,*) \"dely \",sum(abs(dely))\n\n do i=1, n(1)\n \n xdelydel(i, :) = f_positionx(i)*xdelydel(i, :)\n x(i, :) = f_positionx(i)\n \n end do\n \n do i=1, n(2)\n \n xdelydel(:, i) = xdelydel(:, i)-f_positiony(i)*array_t(:, i)\n y(:, i) = f_positiony(i)\n \n end do\n \n xdelydel = xdelydel / dble(n(1)*n(2))\n delx = delx / dble(n(1)*n(2))\n dely = dely / dble(n(1)*n(2))\n \n call s_c2dfft(a, n, fftfor)\n\n array_t = a*xdelydel\n call s_c2dfft(array_t, n, fftbac)\n\n t1 = dely*a\n call s_c2dfft(t1, n, fftbac)\n\n t2 = delx*a\n call s_c2dfft(t2, n, fftbac)\n\n t2 = x*dely*a-y*delx*a\n call s_c2dfft(t2, n, fftbac)\n\n t1 = x*t1-y*t2\n\n write(*,*) \"t1-t2 \",sum(abs(t2-t1))\n\n call s_c2dfft(a, n, fftbac)\n a = a / dble(n(1)*n(2))\n\n write(*,*) \"a \",sum(abs(a))\n write(*,*) \"array_t \",sum(abs(array_t))\n write(*,*) \"t1 \",sum(abs(t1))\n write(*,*) \"array_t-t1\",sum(abs(array_t-t1))\n \nend program test\n\n", "meta": {"hexsha": "f9074224620e2f785b37e9a29ffe42bd30fdd52d", "size": 1994, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test.f90", "max_stars_repo_name": "sdm900/chebyshev_propagation_scheme", "max_stars_repo_head_hexsha": "24b4633e2bcb71d6966f27b9466b42d11c6b5f80", "max_stars_repo_licenses": ["MIT"], "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.f90", "max_issues_repo_name": "sdm900/chebyshev_propagation_scheme", "max_issues_repo_head_hexsha": "24b4633e2bcb71d6966f27b9466b42d11c6b5f80", "max_issues_repo_licenses": ["MIT"], "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.f90", "max_forks_repo_name": "sdm900/chebyshev_propagation_scheme", "max_forks_repo_head_hexsha": "24b4633e2bcb71d6966f27b9466b42d11c6b5f80", "max_forks_repo_licenses": ["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.9120879121, "max_line_length": 166, "alphanum_fraction": 0.5346038114, "num_tokens": 887, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361509525462, "lm_q2_score": 0.7490872075132153, "lm_q1q2_score": 0.6834942483511495}} {"text": "! RUN: %python %S/test_folding.py %s %flang_fc1\n! Tests folding of DIM()\nmodule m\n logical, parameter :: test_i1 = dim(0, 0) == 0\n logical, parameter :: test_i2 = dim(1, 2) == 0\n logical, parameter :: test_i3 = dim(2, 1) == 1\n logical, parameter :: test_i4 = dim(2, -1) == 3\n logical, parameter :: test_i5 = dim(-1, 2) == 0\n logical, parameter :: test_a1 = dim(0., 0.) == 0.\n logical, parameter :: test_a2 = dim(1., 2.) == 0.\n logical, parameter :: test_a3 = dim(2., 1.) == 1.\n logical, parameter :: test_a4 = dim(2., -1.) == 3.\n logical, parameter :: test_a5 = dim(-1., 2.) == 0.\n !WARN: warning: invalid argument on division\n real, parameter :: nan = 0./0.\n logical, parameter :: test_a6 = dim(nan, 1.) /= dim(nan, 1.)\nend module\n", "meta": {"hexsha": "40163c3f5a5ee47db5805c3c477c6bfed6e6e741", "size": 745, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "flang/test/Evaluate/fold-dim.f90", "max_stars_repo_name": "ornata/llvm-project", "max_stars_repo_head_hexsha": "494913b8b4e4bce0b3525e5569d8e486e82b9a52", "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": "flang/test/Evaluate/fold-dim.f90", "max_issues_repo_name": "ornata/llvm-project", "max_issues_repo_head_hexsha": "494913b8b4e4bce0b3525e5569d8e486e82b9a52", "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": "flang/test/Evaluate/fold-dim.f90", "max_forks_repo_name": "ornata/llvm-project", "max_forks_repo_head_hexsha": "494913b8b4e4bce0b3525e5569d8e486e82b9a52", "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": 41.3888888889, "max_line_length": 62, "alphanum_fraction": 0.6013422819, "num_tokens": 278, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206818021531, "lm_q2_score": 0.757794360334681, "lm_q1q2_score": 0.683470406138882}} {"text": "c\nc e1 and e2 values in fortran application differ\nc slighly from the values in the wrapped function in R,\nc since the the later use 16 decimal places\nc\n\n subroutine cao97sub(x,ndp,maxd,tau,e1,e2)\n\n integer ndp, d, maxd, tau, maxtau\n double precision x(1:ndp),e1(1:maxd),e2(1:maxd),v(50),a(50),ya(50),v0,vij\n\n do d=1,maxd\n a(d)=0.\n ya(d)=0.\n ng=ndp-d*tau\n do i=1,ng\n v0=1.e+30\n do j=1,ng\n if(j.eq.i) go to 20\n do k=1,d\n v(k)=abs(x(i+(k-1)*tau)-x(j+(k-1)*tau))\n enddo\n if (d.eq.1) go to 50\n do k=1,d-1\n v(k+1)=max(v(k),v(k+1))\n enddo\n 50 vij=v(d)\n if (vij.lt.v0.and.vij.ne.0.) then\n n0=j\n v0=vij\n endif\n 20 continue\n enddo\n a(d)=a(d)+max(v0,abs(x(i+d*tau)-x(n0+d*tau)))/v0\n ya(d)=ya(d)+abs(x(i+d*tau)-x(n0+d*tau))\n enddo\n a(d)=a(d)/float(ng)\n ya(d)=ya(d)/float(ng)\n !write (*,*) a(d), ya(d)\n if (d.ge.2) then\n !write(*,*) d-1,' E1=', a(d)/a(d-1), ' E2=', ya(d)/ya(d-1)\n e1(d-1) = a(d) / a(d-1)\n e2(d-1) = ya(d) / ya(d-1)\n endif\n enddo\n end\n", "meta": {"hexsha": "865877c0aa75b41c3de6cd089f70273079293344", "size": 1264, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "code/rfunctions/embedding_parameters/withCao1997/cao97sub.f", "max_stars_repo_name": "mxochicale/phd-thesis-code-data", "max_stars_repo_head_hexsha": "6da4eea7643ff747ac84d5b2ed542fd7cb19db31", "max_stars_repo_licenses": ["MIT"], "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/rfunctions/embedding_parameters/withCao1997/cao97sub.f", "max_issues_repo_name": "mxochicale/phd-thesis-code-data", "max_issues_repo_head_hexsha": "6da4eea7643ff747ac84d5b2ed542fd7cb19db31", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-01-06T10:40:35.000Z", "max_issues_repo_issues_event_max_datetime": "2019-01-06T10:40:35.000Z", "max_forks_repo_path": "code/rfunctions/embedding_parameters/withCao1997/cao97sub.f", "max_forks_repo_name": "mxochicale/phd-thesis-code-data", "max_forks_repo_head_hexsha": "6da4eea7643ff747ac84d5b2ed542fd7cb19db31", "max_forks_repo_licenses": ["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.8936170213, "max_line_length": 79, "alphanum_fraction": 0.4390822785, "num_tokens": 480, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.901920681802153, "lm_q2_score": 0.757794360334681, "lm_q1q2_score": 0.6834704061388819}} {"text": " subroutine fd_solar_elevation(lyear,idayjl,isecdy,xlat,xlon, sun_theta)\r\n implicit none\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) sun_theta ! sun elevation \r\n\treal(4) sunlat,sunlon,sundis,hh,xlon,local_time,cosZ\r\n\r\n\tcall sunloc1(lyear,idayjl,isecdy, sunlat,sunlon,sundis)\t !sundis is radius/(mean radius)\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\tcosZ=sind(xlat)*sind(sunlat) + cosd(xlat)*cosd(sunlat)*cos((hh+12)/24.*2*pi)\r\n\tsun_theta=asin(cosZ)*180./pi\r\n\tif(sun_theta<-90)sun_theta=-90\r\n\tif(sun_theta>90)sun_theta=90\r\n return\r\n end\r\n", "meta": {"hexsha": "2d3965e9176dc07dc9d6387af73a76842801434c", "size": 874, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "subroutines/fd_solar_elevation.f", "max_stars_repo_name": "cgentemann/posh_diurnal_model_fortran", "max_stars_repo_head_hexsha": "227fbea81016da29c3925a65fc2b3dcb5958e822", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-10-05T12:34:07.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-05T12:34:07.000Z", "max_issues_repo_path": "subroutines/fd_solar_elevation.f", "max_issues_repo_name": "cgentemann/posh_diurnal_model_fortran", "max_issues_repo_head_hexsha": "227fbea81016da29c3925a65fc2b3dcb5958e822", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "subroutines/fd_solar_elevation.f", "max_forks_repo_name": "cgentemann/posh_diurnal_model_fortran", "max_forks_repo_head_hexsha": "227fbea81016da29c3925a65fc2b3dcb5958e822", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.7272727273, "max_line_length": 91, "alphanum_fraction": 0.671624714, "num_tokens": 296, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191348157373, "lm_q2_score": 0.7154239836484143, "lm_q1q2_score": 0.6834582210854313}} {"text": "program oned_mc_impsampling\n\n !Author : Anantha Rao\n ! Reg no : 20181044\n integer:: n,i\n real*8:: p, crude_mc, x, func, sigma, var, length, actual\n\n length=3.0d0\n actual=exp(3.0d0) -1\n\n n = 1\n open(unit=1, file=\"20181044_p2_MC_sampling.dat\")\n\n 7 crude_mc = 0.0d0\n sigma=0.0d0\n\n do i=1,n\n call random_number(p)\n x = 3.0d0*p**(1.0/3.0)\n crude_mc = crude_mc+func(x)\n sigma=sigma+func(x)*func(x)\n end do\n\n crude_mc=crude_mc/real(n)\n sigma=sigma/real(n)\n var = sigma - crude_mc*crude_mc\n\n crude_mc = length*crude_mc\n var=length*sqrt(var/real(n))\n write(*,*) n,\"\",crude_mc,\" \", var\n write(1,*) n,\"\",crude_mc,\"\",abs(crude_mc-actual)\n\n !automation\n n=n*10\n if (n .le. 100000000) goto 7\n print*, \"Output written to 20181044_p2_MC_impsampling.dat\"\n ! end automation\n\n end program oned_mc_impsampling\n\nreal*8 function func(x)\n implicit none\n real*8 ::x\n func=3.0d0*x**(-2.0)*exp(x)\nend function\n\n\n\n", "meta": {"hexsha": "4ba7095f83a6960e73013c0894d14f8231f094a9", "size": 1049, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Solutions/assgn02_solns/Assgn02_p2_impsampling.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_impsampling.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_impsampling.f90", "max_forks_repo_name": "Anantha-Rao12/ComPhys", "max_forks_repo_head_hexsha": "235bbebcff0a0ba8b20380d4749a039bca060771", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.4081632653, "max_line_length": 64, "alphanum_fraction": 0.5786463298, "num_tokens": 365, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118111485244, "lm_q2_score": 0.8267118004748678, "lm_q1q2_score": 0.6834524098684355}} {"text": " program demo_max\n implicit none\n real :: arr1(4)= [10.0,11.0,30.0,-100.0]\n real :: arr2(5)= [20.0,21.0,32.0,-200.0,2200.0]\n\n !! this is simple enough because it is not being called elementally\n !! because all arguments are scalar\n !!\n\n write(*,*)'scalars:',max(10.0,11.0,30.0,-100.0)\n\n !!\n !! this is all max(3) could do before it became an elemental\n !! function and is the most intuitive\n !! except that it can take an arbitrary number of options,\n !! which is not common in Fortran without\n !! declaring a lot of optional parameters.\n !!\n !! That is it unless you want to use the elemental features of max(3)!\n\n !! Error: Intrinsic max at (1) must have at least two arguments\n !!write(*,*)max(arr1)\n !! This does not work because it is like trying to return\n !! [(max(arr1(i)),i=1,size(arr1))]\n !! so it is trying to take the max of a single value.\n !! To find the largest element of an array\n !! call maxloc(3) or maxval(3).\n\n !! Error: Different shape for arguments 'a1' and 'a2' for intrinsic\n !! 'max' at (1) on dimension 1 (4 and 5)\n !!write(*,*)max(arr1,arr2)\n !! but this will return an array of\n !! [(max(arr1(N),arr2(N),N=1,size(arr1))]\n\n write(*,*)max(arr1,arr2(1:4))\n\n !! so this works only if all the arrays are the same size and\n !! you want an array of the largest Nth elements\n !! from the input arrays.\n !! maybe you wanted to do maxval([arr1,arr2]) or\n !! equivalently max(maxval(arr1),maxval(arr2))\n !! to find the single largest element in both arrays?\n\n !! compares all scalars to each member of array and\n !! returns array of size arr2\n\n write(*,*)'scalars and array:',max(10.0,11.0,30.0,-100.0,arr2)\n\n !! Error: Different shape for arguments 'a5' and 'a6'\n !! for intrinsic 'max' at (1) on dimension 1 (5 and 4)\n !! write(*,*)'scalars and array:',max(10.0,11.0,30.0,-100.0,arr2,arr1)\n !! as the same reason above when arrays are used\n !! (without scalar values) all the arrays must be the same size\n\n write(*,*)'scalars and array:',&\n & max(40.0,11.0,30.0,-100.0,arr2(:4),arr1)\n end program demo_max\n", "meta": {"hexsha": "5750aa8e2fc5d4751549ec507e855add5d14d2e4", "size": 2252, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/max.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/max.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/max.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": 38.8275862069, "max_line_length": 76, "alphanum_fraction": 0.6070159858, "num_tokens": 674, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706734, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.6834523939851669}} {"text": " subroutine r8mktricub(x,nx,y,ny,z,nz,f,nf2,nf3,\n > ibcxmin,bcxmin,ibcxmax,bcxmax,inb1x,\n > ibcymin,bcymin,ibcymax,bcymax,inb1y,\n > ibczmin,bczmin,ibczmax,bczmax,inb1z,\n > ilinx,iliny,ilinz,ier)\nc\nc setup a tricubic spline; store coefficients in compact form\nc (as per suggestion of L. Zakharov, PPPL, Feb. 1999)\nC 8 coeffs per (x,y,z) grid point:\nC f,fxx,fyy,fzz,fxxyy,fxxzz,fyyzz,fxxyyzz\nC\nC dmc -- modified Feb 2004 -- rewritten to compute coefficients\nC directly rather than by conversion from the non-compact representation\nC (to reduce cpu and memory cost)\nC\nC\nC input:\n IMPLICIT NONE\n INTEGER, PARAMETER :: R8=SELECTED_REAL_KIND(12,100)\n integer nx ! length of x vector\n integer ny ! length of y vector\n integer nz ! length of z vector\n REAL*8 x(nx) ! x vector, strict ascending\n REAL*8 y(ny) ! y vector, strict ascending\n REAL*8 z(nz) ! z vector, strict ascending\nc\n integer nf2 ! 2nd dim. of f array, nf2.ge.nx\n integer nf3 ! 3rd dim. of f array, nf3.ge.ny\nc\nc input/output:\nc\n REAL*8 f(8,nf2,nf3,nz) ! data and spline coefficients\nc\nC on input: f(1,i,j,k) = f(x(i),y(j),z(k))\nC on output: f(1,i,j,k) unchanged\nC f(2,i,j,k) = d2f/dx2(x(i),y(j),z(k))\nC f(3,i,j,k) = d2f/dy2(x(i),y(j),z(k))\nC f(4,i,j,k) = d2f/dz2(x(i),y(j),z(k))\nC f(5,i,j,k) = d4f/dx2dy2(x(i),y(j),z(k))\nC f(6,i,j,k) = d4f/dx2dz2(x(i),y(j),z(k))\nC f(7,i,j,k) = d4f/dy2dz2(x(i),y(j),z(k))\nC f(8,i,j,k) = d6f/dx2dy2dz2(x(i),y(j),z(k))\nC\nC there is a rather Hermite like interpolation formula to go with\nC this-- see evtricub.for. Also the bicubic formula is given in\nC mkbicubw.for; the tricubic formula is precisely analogous.\nC\nC boundary condition data\nC inputs:\n integer inb1x ! 1st dim of xmin & xmax bc arrays\n integer inb1y ! 1st dim of ymin & ymax bc arrays\n integer inb1z ! 1st dim of zmin & zmax bc arrays\nC\n integer ibcxmin,ibcxmax ! BC type flag @xmin, xmax\n integer ibcymin,ibcymax ! BC type flag @ymin, ymax\n integer ibczmin,ibczmax ! BC type flag @zmin, zmax\nC\n REAL*8 bcxmin(inb1x,nz),bcxmax(inb1x,nz) ! xmin & xmax BC data, ny x nz\n REAL*8 bcymin(inb1y,nz),bcymax(inb1y,nz) ! ymin & ymax BC data, nx x nz\n REAL*8 bczmin(inb1z,ny),bczmax(inb1z,ny) ! zmin & zmax BC data, nx x ny\nc\nc where BC data is not required, dummy scalars may be passed.\nC the ibc* flags determine whether BC data isneeded.\nc\nc BC data: bcxmin & bcxmax: BC vs. y,z @xmin,xmax\nC bcymin & bcymax: BC vs. x,z @ymin,ymax\nC bczmin & bczmax: BC vs. x,y @zmin,zmax\nC\nc ibcxmin -- indicator for boundary condition at xmin=x(1):\nc bcxmin(...) -- boundary condition data\nc =-1 -- use periodic boundary condition\nc =0 -- use \"not a knot\"\nc =1 -- match slope, specified at x(1),y(iy),z(iz) by bcxmin(iy,iz)\nc =2 -- match 2nd derivative, specified at x(1),y(iy),z(iz)\nc by bcxmin(iy,iz\nc =3 -- boundary condition is slope=0 (df/dx=0) at x(1), all y(j)\nc =4 -- boundary condition is d2f/dx2=0 at x(1), all y(j)\nc =5 -- df/dx BC from 1st divided difference\nc =6 -- d2f/dx2 BC from 2nd divided difference (parabolic fit)\nc =7 -- d3f/dx3 BC from 3rd divided difference (cubic fit)\nc ***NOTE bcxmin(...) referenced ONLY if ibcxmin=1 or ibcxmin=2\nc\nc ibcxmax -- indicator for boundary condition at x(nx):\nc bcxmax(...) -- boundary condition data\nc (interpretation as with ibcxmin, bcxmin)\nc NOTE: if ibcxmin=-1 then the periodic BC applies on both sides\nc and ibcxmax, bcxmax are ignored.\nc inb1x -- 1st dimension of bcxmin, bcxmax: if ibcxmin or ibcxmax .gt. 0\nc this must be .ge. ny.\nc\nc interpretation of ibcymin,bcymin,ibcymax,bcymax,inb1y\nc is same as with ibcxmin,...\nc\nc interpretation of ibczmin,bczmin,ibczmax,bczmax,inb1z\nc is same as with ibcxmin,...\nc\nc the explicit bdy condition arrays are referenced only if the\nc corresponding \"ibc\" flag values are set to 1 or 2.\nc\nc output:\n integer ilinx ! x vector equal spacing flag\n integer iliny ! y vector equal spacing flag\n integer ilinz ! z vector equal spacing flag\nc\nc ilinx -- =1 on output if x(nx) pts are nearly evenly spaced (tol=1e-3)\nc iliny -- =1 on output if y(ny) evenly spaced (tol=1e-3)\nc ilinz -- =1 on output if z(nz) evenly spaced (tol=1e-3)\nc\n integer ier ! exit code\nc ier -- completion code, 0 for normal\nc\nC-----------------------------------------------------\nc workspace **dynamic allocation**\nC f90 dynamic array\nC\n REAL*8, dimension(:,:,:), allocatable :: fbicub ! bicubic subsection\n REAL*8, dimension(:,:), allocatable :: fwk ! work array\n REAL*8, dimension(:), allocatable :: bcx1,bcx2,bcy1,bcy2 ! BCs for mkbicub\nc\n REAL*8, dimension(:,:,:,:), allocatable :: fcorr ! correction spline\n REAL*8, dimension(:,:), allocatable :: bcc1,bcc2 ! correction BCs\nc\n integer iflg,ierx,iery,ierz\n integer ix,iy,iz\nc\n REAL*8 ztol\n REAL*8 zbc1,zbc2,hz\n integer ibc1,ibc2\nc\n data ztol/1.0E-3_r8/\nc-----------------------------------------------------\nc\n ier=0\nc\n iflg=0\nc\nc check z bdy condition \"linearity\"\nc\n if(ibczmin.ne.-1) then\n if((ibczmin.eq.1).or.(ibczmin.eq.2)) then\n do iy=1,ny\n do ix=1,nx\n if(bczmin(ix,iy).ne.0.0_r8) iflg=1\n enddo\n enddo\n endif\n if((ibczmax.eq.1).or.(ibczmax.eq.2)) then\n do iy=1,ny\n do ix=1,nx\n if(bczmax(ix,iy).ne.0.0_r8) iflg=1\n enddo\n enddo\n endif\n endif\nc\n if(nx.lt.2) then\n write(6,'('' ?mktricub: at least 2 x points required.'')')\n ier=1\n endif\n if(ny.lt.2) then\n write(6,'('' ?mktricub: need at least 2 y points.'')')\n ier=1\n endif\n if(nz.lt.2) then\n write(6,'('' ?mktricub: need at least 2 z points.'')')\n ier=1\n endif\nc\n if((ibcxmin.eq.1).or.(ibcxmax.eq.1).or.(ibcxmin.eq.2).or.\n > (ibcxmax.eq.2)) then\n if(inb1x.lt.ny) then\n ier=1\n write(6,\n >'('' ?mktricub: 1st dim of bcxmin/max arrays .lt. ny'')')\n endif\n endif\nc\n if((ibcymin.eq.1).or.(ibcymax.eq.1).or.(ibcymin.eq.2).or.\n > (ibcymax.eq.2)) then\n if(inb1y.lt.nx) then\n ier=1\n write(6,\n >'('' ?mktricub: 1st dim of bcymin/max arrays .lt. nx'')')\n endif\n endif\nc\n if((ibczmin.eq.1).or.(ibczmax.eq.1).or.(ibczmin.eq.2).or.\n > (ibczmax.eq.2)) then\n if(inb1z.lt.nx) then\n ier=1\n write(6,\n >'('' ?mktricub: 1st dim of bczmin/max arrays .lt. nx'')')\n endif\n endif\nc\n call ibc_ck(ibcxmin,'mktricub','xmin',-1,7,ier)\n if(ibcxmin.ge.0) call ibc_ck(ibcxmax,'mktricub','xmax',0,7,ier)\nc\n call ibc_ck(ibcymin,'mktricub','ymin',-1,7,ier)\n if(ibcymin.ge.0) call ibc_ck(ibcymax,'mktricub','ymax',0,7,ier)\nc\n call ibc_ck(ibczmin,'mktricub','zmin',-1,7,ier)\n if(ibczmax.ge.0) call ibc_ck(ibczmax,'mktricub','zmax',0,7,ier)\nc\nc check ilinx & x vector\nc\n call r8splinck(x,nx,ilinx,ztol,ierx)\n if(ierx.ne.0) ier=2\nc\n if(ier.eq.2) then\n write(6,'('' ?mktricub: x axis not strict ascending'')')\n endif\nc\nc check iliny & y vector\nc\n call r8splinck(y,ny,iliny,ztol,iery)\n if(iery.ne.0) ier=3\nc\n if(ier.eq.3) then\n write(6,'('' ?mktricub: y axis not strict ascending'')')\n endif\nc\nc check ilinz & z vector\nc\n call r8splinck(z,nz,ilinz,ztol,ierz)\n if(ierz.ne.0) ier=4\nc\n if(ier.eq.4) then\n write(6,'('' ?mktricub: z axis not strict ascending'')')\n endif\nc\n if(ier.ne.0) return\nc\nc------------------------------------\nc 1. compute (x,y) bicubic splines using mkbicub\nc\n allocate(fbicub(4,nx,ny))\n allocate(bcx1(ny),bcx2(ny),bcy1(nx),bcy2(nx))\n bcx1=0.0; bcx2=0.0; bcy1=0.0; bcy2=0.0_r8\nc\n do iz=1,nz\n if(ibcxmin.ne.-1) then\n if((ibcxmin.eq.1).or.(ibcxmin.eq.2)) then\n bcx1(1:ny)=bcxmin(1:ny,iz)\n endif\n if((ibcxmax.eq.1).or.(ibcxmax.eq.2)) then\n bcx2(1:ny)=bcxmax(1:ny,iz)\n endif\n endif\n if(ibcymin.ne.-1) then\n if((ibcymin.eq.1).or.(ibcymin.eq.2)) then\n bcy1(1:nx)=bcymin(1:nx,iz)\n endif\n if((ibcymax.eq.1).or.(ibcymax.eq.2)) then\n bcy2(1:nx)=bcymax(1:nx,iz)\n endif\n endif\nc\n fbicub(1,1:nx,1:ny) = f(1,1:nx,1:ny,iz)\nc\n call r8mkbicub(x,nx,y,ny,fbicub,nx,\n > ibcxmin,bcx1,ibcxmax,bcx2,\n > ibcymin,bcy1,ibcymax,bcy2,\n > ilinx,iliny,ier)\n if(ier.ne.0) return\nc\n f(2:3,1:nx,1:ny,iz) = fbicub(2:3,1:nx,1:ny) ! fxx, fyy\n f(5,1:nx,1:ny,iz) = fbicub(4,1:nx,1:ny) ! fxxyy\nc\n enddo\nc\n deallocate(fbicub,bcx1,bcx2,bcy1,bcy2)\nc\nc 2. homogeneous spline in z direction; inhomogeneous BC imposed later\nc if necessary\nc\n zbc1=0.0_r8\n zbc2=0.0_r8\n ibc1=ibczmin\n ibc2=ibczmax\n if(iflg.eq.1) then\n if((ibczmin.eq.1).or.(ibczmin.eq.2)) ibc1=0\n if((ibczmax.eq.1).or.(ibczmax.eq.2)) ibc2=0\n endif\nc\n allocate(fwk(2,nz))\nc\n do iy=1,ny\n do ix=1,nx\n \n fwk(1,1:nz) = f(1,ix,iy,1:nz)\n call r8mkspline(z,nz,fwk,\n > ibc1,zbc1,ibc2,zbc2,ilinz,ier)\n if(ier.ne.0) return\n f(4,ix,iy,1:nz) = fwk(2,1:nz) ! fzz\n \n fwk(1,1:nz) = f(2,ix,iy,1:nz)\n call r8mkspline(z,nz,fwk,\n > ibc1,zbc1,ibc2,zbc2,ilinz,ier)\n if(ier.ne.0) return\n f(6,ix,iy,1:nz) = fwk(2,1:nz) ! fxxzz\n \n fwk(1,1:nz) = f(3,ix,iy,1:nz)\n call r8mkspline(z,nz,fwk,\n > ibc1,zbc1,ibc2,zbc2,ilinz,ier)\n if(ier.ne.0) return\n f(7,ix,iy,1:nz) = fwk(2,1:nz) ! fyyzz\n \n fwk(1,1:nz) = f(5,ix,iy,1:nz)\n call r8mkspline(z,nz,fwk,\n > ibc1,zbc1,ibc2,zbc2,ilinz,ier)\n if(ier.ne.0) return\n f(8,ix,iy,1:nz) = fwk(2,1:nz) ! fxxyyzz\n \n enddo\n enddo\nc\n deallocate(fwk)\nc\n if(iflg.eq.1) then\nc\nc 3. inhomogeneous BC correction\nc\n allocate(fwk(2,max(nx,ny,nz)))\n allocate(bcc1(nx,ny),bcc2(nx,ny))\n allocate(fcorr(4,nx,ny,nz))\nc\nc correction BCs\nc\n do iy=1,ny\n do ix=1,nx\n bcc1(ix,iy)=0.0_r8\n if(ibczmin.eq.1) then\n hz=z(2)-z(1)\n bcc1(ix,iy)=(f(1,ix,iy,2)-f(1,ix,iy,1))/hz +\n > hz*(-2*f(4,ix,iy,1)-f(4,ix,iy,2))/6\n bcc1(ix,iy)=bczmin(ix,iy)-bcc1(ix,iy)\n else if(ibczmin.eq.2) then\n bcc1(ix,iy)=bczmin(ix,iy)-f(4,ix,iy,1)\n endif\n enddo\n enddo\nc\n do iy=1,ny\n do ix=1,nx\n bcc2(ix,iy)=0.0_r8\n if(ibczmax.eq.1) then\n hz=z(2)-z(1)\n bcc2(ix,iy)=(f(1,ix,iy,2)-f(1,ix,iy,1))/hz +\n > hz*(-2*f(4,ix,iy,1)-f(4,ix,iy,2))/6\n bcc2(ix,iy)=bczmax(ix,iy)-bcc2(ix,iy)\n else if(ibczmax.eq.2) then\n bcc2(ix,iy)=bczmax(ix,iy)-f(4,ix,iy,1)\n endif\n enddo\n enddo\nc\n fwk(1,1:nz)=0.0_r8 ! values are all zero, only BC is set...\n do iy=1,ny\n do ix=1,nx\n call r8mkspline(z,nz,fwk,\n > ibczmin,bcc1(ix,iy),ibczmax,bcc2(ix,iy),ilinz,ier)\n if(ier.ne.0) return\n fcorr(1,ix,iy,1:nz)=fwk(2,1:nz) ! fzz-correction\n enddo\n enddo\nc\nc higher order corrections\nc\n zbc1=0.0_r8\n zbc2=0.0_r8\nc\n do iz=1,nz\n do iy=1,ny\n fwk(1,1:nx)=fcorr(1,1:nx,iy,iz)\n call r8mkspline(x,nx,fwk,\n > ibcxmin,zbc1,ibcxmax,zbc2,ilinx,ier)\n if(ier.ne.0) return\n fcorr(2,1:nx,iy,iz)=fwk(2,1:nx) ! fxxzz-correction\n enddo\n enddo\nc\n do iz=1,nz\n do ix=1,nx\n fwk(1,1:ny)=fcorr(1,ix,1:ny,iz)\n call r8mkspline(y,ny,fwk,\n > ibcymin,zbc1,ibcymax,zbc2,iliny,ier)\n if(ier.ne.0) return\n fcorr(3,ix,1:ny,iz)=fwk(2,1:ny) ! fyyzz-correction\n \n fwk(1,1:ny)=fcorr(2,ix,1:ny,iz)\n call r8mkspline(y,ny,fwk,\n > ibcymin,zbc1,ibcymax,zbc2,iliny,ier)\n if(ier.ne.0) return\n fcorr(4,ix,1:ny,iz)=fwk(2,1:ny) ! fxxyyzz-correction\n enddo\n enddo\nc\nc apply correction\nc\n do iz=1,nz\n do iy=1,ny\n do ix=1,nx\n f(4,ix,iy,iz)=f(4,ix,iy,iz)+fcorr(1,ix,iy,iz)\n f(6,ix,iy,iz)=f(6,ix,iy,iz)+fcorr(2,ix,iy,iz)\n f(7,ix,iy,iz)=f(7,ix,iy,iz)+fcorr(3,ix,iy,iz)\n f(8,ix,iy,iz)=f(8,ix,iy,iz)+fcorr(4,ix,iy,iz)\n enddo\n enddo\n enddo\nc\n deallocate(fwk,fcorr,bcc1,bcc2)\nc\n endif\nc\nc that's all\nc\n return\n end\n \n", "meta": {"hexsha": "a60026c7ef48d7c401b794ac16b37aa6a30c62eb", "size": 13815, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gfile_Bfield/PSPLINE/Pspline/r8mktricub.f", "max_stars_repo_name": "ORNL-Fusion/RFSciDAC-testing", "max_stars_repo_head_hexsha": "c2fa44e00ce8e0af4be6fa662a9e8c94d6c6f60e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2020-05-08T01:47:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T10:35:28.000Z", "max_issues_repo_path": "gfile_Bfield/PSPLINE/Pspline/r8mktricub.f", "max_issues_repo_name": "ORNL-Fusion/RFSciDAC-testing", "max_issues_repo_head_hexsha": "c2fa44e00ce8e0af4be6fa662a9e8c94d6c6f60e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 77, "max_issues_repo_issues_event_min_datetime": "2020-05-08T07:18:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:20:33.000Z", "max_forks_repo_path": "gfile_Bfield/PSPLINE/Pspline/r8mktricub.f", "max_forks_repo_name": "ORNL-Fusion/RFSciDAC-testing", "max_forks_repo_head_hexsha": "c2fa44e00ce8e0af4be6fa662a9e8c94d6c6f60e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-02-10T13:47:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T12:53:43.000Z", "avg_line_length": 32.8147268409, "max_line_length": 80, "alphanum_fraction": 0.5204487875, "num_tokens": 5137, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425223682086, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6834489072149884}} {"text": "module alimento\n\ncontains\n\nsubroutine evolui_tempo(tf, T_inicial, Raio, H, ka, rho, Cp, h_convec, eps, T_esteira, T_paredes, T_ar, T_ambiente,T)\n\n implicit none\n integer, parameter :: nr = 60\n integer, parameter :: nh = 30\n real, dimension(nh,nr), intent(in) :: T_inicial\n real, intent(in) :: tf, Raio, H, ka, rho, Cp, h_convec, eps\n real, intent(in) :: T_esteira, T_paredes, T_ar, T_ambiente\n real, dimension(nh,nr), intent(out) :: T\n real:: sigma, alpha, dr, dh, dt\n integer :: nt, i, j, k, l, m\n REAL, PARAMETER :: pi = 3.1415927\n\n real, dimension(nr) :: r\n real, dimension(nh,nr) :: Tc\n\n dt = 0.05\n sigma = 5.67032e-8\n alpha = ka/(rho*Cp)\n dr = Raio/(nr + 1)\n dh = H/(nh + 1)\n nt = int(tf/dt)\n\n do i = 1, int(nh)\n do j = 1, int(nr)\n T(i,j) = T_inicial(i,j)\n Tc(i,j) = T_inicial(i,j)\n enddo\n enddo\n\n do i = 1, nr\n T(1,i) = T_esteira\n r(i) = i*Raio/nr\n enddo\n\n do k = 1, nt\n\n do i = 1, int(nh)\n do j = 1, int(nr)\n Tc(i,j) = T(i,j)\n enddo\n enddo\n\n do i = 2, int(nh) -1\n do j = 2, int(nr) -1\n T(i,j) = Tc(i,j) + dt*alpha*( &\n ( Tc(i,j+1) - 2*Tc(i,j) + T(i,j-1) )/dr**2 + &\n ( Tc(i+1,j) - 2*Tc(i,j) + T(i-1,j) )/dh**2 + &\n ( Tc(i,j+1) - Tc(i,j-1) )/(dr* r(j)) )\n enddo\n enddo\n\n do i = 1, int(nr)\n T(nh,i) = T(nh-1,i) + dr*eps*sigma*(T_paredes**4 - T(nh,i)**4)&\n + dr*h_convec*( T_ar - T(nh,i))\n enddo\n\n do i = 1, int(nh)\n T(i,nr) = T(i,nr-1) + dr*eps*sigma*(T_paredes**4 - T(i,nr)**4)&\n + dr*h_convec*( T_ar - T(i,nr))\n enddo\n\n do i = 1, int(nh)\n T(i,1) = T(i,2)\n enddo\n enddo\n\nend subroutine evolui_tempo\n\nend module alimento\n", "meta": {"hexsha": "9649cb3f99bb046c938cadffa2ca04fbd691d330", "size": 1915, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/simulacao/alimento.f90", "max_stars_repo_name": "Atzingen/controleForno-interface", "max_stars_repo_head_hexsha": "6a8968527f8b76c7d0c7ea26f8c8aca728fe4d2d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source/simulacao/alimento.f90", "max_issues_repo_name": "Atzingen/controleForno-interface", "max_issues_repo_head_hexsha": "6a8968527f8b76c7d0c7ea26f8c8aca728fe4d2d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2016-09-06T15:54:00.000Z", "max_issues_repo_issues_event_max_datetime": "2016-09-15T15:05:41.000Z", "max_forks_repo_path": "source/simulacao/alimento.f90", "max_forks_repo_name": "Atzingen/controleForno-interface", "max_forks_repo_head_hexsha": "6a8968527f8b76c7d0c7ea26f8c8aca728fe4d2d", "max_forks_repo_licenses": ["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.5333333333, "max_line_length": 117, "alphanum_fraction": 0.4553524804, "num_tokens": 742, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425355825848, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6834489065729946}} {"text": "c Do the shuffling using as little memory as possible.\n program day22\n integer*8 p(2), modulo, inverse, mult\n character*4 command\n integer*8 val, x(2), v(2), i, j, r, n, d\n data x/2*0/, v/2*1/\n\n p(1) = 10007\n p(2) = 1193157*10**8 + 17514047\n r = 1017415*10**8 + 82076661\n\n 1 read(*,*,end=2) command, val\n do 3 j = 1,2\n if (command .eq. 'cut') then\n x(j) = modulo(x(j) + v(j) * val, p(j))\n\n else if (command .eq. 'new') then\n v(j) = p(j) - v(j)\n x(j) = modulo(x(j) + v(j), p(j))\n else if (command .eq. 'incr') then\n v(j) = mult(v(j), inverse(val, p(j)), p(j))\n end if\n 3 continue\n go to 1\n\nc Part one - find the index of 2019\n 2 v(1) = inverse(v(1), p(1))\n x(1) = mult(-x(1), v(1), p(1))\n n = modulo(2019 * v(1) + x(1), p(1))\n write(*,*) n\n\nc Part two - find the 2020th value after many iterations\n n = 2020\n call geom(x(2), v(2), r, p(2))\n d = mult(v(2), n, p(2))\n d = modulo(x(2) + d, p(2))\n write(*,*) d\n end\n\n subroutine geom(x, v, r, p)\n integer*8 x, v, r, p, a, b, mult, inverse, modexp\n\n a = modexp(v, r, p)\n b = modulo(a-1, p)\n b = mult(b, x, p)\n b = mult(b, inverse(v-1, p), p)\n\n x = b\n v = a\n return\n end\n\nc a*b mod p by repeated addition\n integer*8 function mult(a, b, p)\n integer*8 a, b, p, x, y, m\n m = 0\n x = a\n y = b\n do 1 while(y.ne.0)\n if (mod(y, 2).eq.1) then\n m = mod(m + x, p)\n end if\n y = y / 2\n if (x.lt.p-x) then\n x = x * 2\n else\n x = x - (p - x)\n end if\n 1 continue\n mult = m\n return\n end\n\nc A version of mod that handles negatives correctly\n integer*8 function modulo(a, b)\n integer*8 a, b\n modulo = mod(a, b)\n if (modulo.lt.0) then\n modulo = modulo + b\n end if\n return\n end\n\nc b^e mod m by repeated squaring\n integer*8 function modexp(b, e, m)\n integer*8 b, e, m\n integer*8 c, x, mult, g\n c = mod(b, m)\n x = e\n g = 1\n do 1 while(x.gt.0)\n if (mod(x, 2).eq.1) then\n g = mult(g, c, m)\n end if\n c = mult(c, c, m)\n x = x / 2\n 1 continue\n modexp = g\n return\n end\n\nc Get the modular inverse (1 / a mod m)\n integer*8 function inverse(a, m)\n integer*8 a, m, q, p\n integer*8 t0, t1, r0, r1\n\n t0 = 0\n t1 = 1\n r0 = m\n r1 = a\n\n do 1 while (r1 .ne. 0)\n q = r0 / r1\n\n p = t1\n t1 = t0 - q * t1\n t0 = p\n\n p = r1\n r1 = r0 - q * r1\n r0 = p\n 1 continue\n\n if (t0 .lt. 0) then\n inverse = t0 + m\n else\n inverse = t0\n end if\n return\n end\n", "meta": {"hexsha": "7735e736282f43d1decc1fad610edd1902f9685e", "size": 3069, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "day22.f", "max_stars_repo_name": "anthony-arnold/advent-2019", "max_stars_repo_head_hexsha": "583938ce1ee0c0ce719deb5c0492d00f8397062b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-16T04:28:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-16T04:28:15.000Z", "max_issues_repo_path": "day22.f", "max_issues_repo_name": "anthony-arnold/advent-2019", "max_issues_repo_head_hexsha": "583938ce1ee0c0ce719deb5c0492d00f8397062b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "day22.f", "max_forks_repo_name": "anthony-arnold/advent-2019", "max_forks_repo_head_hexsha": "583938ce1ee0c0ce719deb5c0492d00f8397062b", "max_forks_repo_licenses": ["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.427480916, "max_line_length": 60, "alphanum_fraction": 0.4115347019, "num_tokens": 1069, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425223682086, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6834489019837408}} {"text": "program problem85\n implicit none\n integer :: besti,bestj,best,temp,i,j\n\n best=huge(best)\n besti=0\n bestj=0\n\n do i=1,100\n do j=1,100\n temp=score(i,j)\n if (abs(temp-2000000)= T_s(k)).and.((T-dT) < T_s(k)) ) then\n \n w_s(k) = sum(w)\n k = k + 1\n\n end if\n \n end do\n\nend subroutine solve\n", "meta": {"hexsha": "24c325186c04b574b02c35758f535bbaf68b4596", "size": 1866, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "tga-bayes/Scripts/odefort.f95", "max_stars_repo_name": "koverholt/fire-platform", "max_stars_repo_head_hexsha": "480f90d0929856106f1ee0f1adf612c053c18bd0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2016-06-19T12:44:22.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-21T07:01:38.000Z", "max_issues_repo_path": "tga-bayes/Scripts/odefort.f95", "max_issues_repo_name": "koverholt/fire-platform", "max_issues_repo_head_hexsha": "480f90d0929856106f1ee0f1adf612c053c18bd0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tga-bayes/Scripts/odefort.f95", "max_forks_repo_name": "koverholt/fire-platform", "max_forks_repo_head_hexsha": "480f90d0929856106f1ee0f1adf612c053c18bd0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-10-15T02:37:25.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T16:22:44.000Z", "avg_line_length": 27.8507462687, "max_line_length": 79, "alphanum_fraction": 0.4587352626, "num_tokens": 628, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.683389144119608}} {"text": " SUBROUTINE DG01MD( INDI, N, XR, XI, INFO )\r\nC\r\nC SLICOT RELEASE 5.5.\r\nC\r\nC Copyright (c) 2002-2012 NICONET e.V.\r\nC\r\nC PURPOSE\r\nC\r\nC To compute the discrete Fourier transform, or inverse transform,\r\nC of a complex signal.\r\nC\r\nC ARGUMENTS\r\nC\r\nC Mode Parameters\r\nC\r\nC INDI CHARACTER*1\r\nC Indicates whether a Fourier transform or inverse Fourier\r\nC transform is to be performed as follows:\r\nC = 'D': (Direct) Fourier transform;\r\nC = 'I': Inverse Fourier transform.\r\nC\r\nC Input/Output Parameters\r\nC\r\nC N (input) INTEGER\r\nC The number of complex samples. N must be a power of 2.\r\nC N >= 2.\r\nC\r\nC XR (input/output) DOUBLE PRECISION array, dimension (N)\r\nC On entry, this array must contain the real part of either\r\nC the complex signal z if INDI = 'D', or f(z) if INDI = 'I'.\r\nC On exit, this array contains either the real part of the\r\nC computed Fourier transform f(z) if INDI = 'D', or the\r\nC inverse Fourier transform z of f(z) if INDI = 'I'.\r\nC\r\nC XI (input/output) DOUBLE PRECISION array, dimension (N)\r\nC On entry, this array must contain the imaginary part of\r\nC either z if INDI = 'D', or f(z) if INDI = 'I'.\r\nC On exit, this array contains either the imaginary part of\r\nC f(z) if INDI = 'D', or z if INDI = 'I'.\r\nC\r\nC Error Indicator\r\nC\r\nC INFO INTEGER\r\nC = 0: successful exit;\r\nC < 0: if INFO = -i, the i-th argument had an illegal\r\nC value.\r\nC\r\nC METHOD\r\nC\r\nC If INDI = 'D', then the routine performs a discrete Fourier\r\nC transform on the complex signal Z(i), i = 1,2,...,N. If the result\r\nC is denoted by FZ(k), k = 1,2,...,N, then the relationship between\r\nC Z and FZ is given by the formula:\r\nC\r\nC N ((k-1)*(i-1))\r\nC FZ(k) = SUM ( Z(i) * V ),\r\nC i=1\r\nC 2\r\nC where V = exp( -2*pi*j/N ) and j = -1.\r\nC\r\nC If INDI = 'I', then the routine performs an inverse discrete\r\nC Fourier transform on the complex signal FZ(k), k = 1,2,...,N. If\r\nC the result is denoted by Z(i), i = 1,2,...,N, then the\r\nC relationship between Z and FZ is given by the formula:\r\nC\r\nC N ((k-1)*(i-1))\r\nC Z(i) = SUM ( FZ(k) * W ),\r\nC k=1\r\nC\r\nC where W = exp( 2*pi*j/N ).\r\nC\r\nC Note that a discrete Fourier transform, followed by an inverse\r\nC discrete Fourier transform, will result in a signal which is a\r\nC factor N larger than the original input signal.\r\nC\r\nC REFERENCES\r\nC\r\nC [1] Rabiner, L.R. and Rader, C.M.\r\nC Digital Signal Processing.\r\nC IEEE Press, 1972.\r\nC\r\nC NUMERICAL ASPECTS\r\nC\r\nC The algorithm requires 0( N*log(N) ) operations.\r\nC\r\nC CONTRIBUTOR\r\nC\r\nC Release 3.0: V. Sima, Katholieke Univ. Leuven, Belgium, Feb. 1997.\r\nC Supersedes Release 2.0 routine DG01AD by R. Dekeyser, State\r\nC University of Gent, Belgium.\r\nC\r\nC REVISIONS\r\nC\r\nC -\r\nC\r\nC KEYWORDS\r\nC\r\nC Complex signals, digital signal processing, fast Fourier\r\nC transform.\r\nC\r\nC ******************************************************************\r\nC\r\nC .. Parameters ..\r\n DOUBLE PRECISION ZERO, HALF, ONE, TWO, EIGHT\r\n PARAMETER ( ZERO = 0.0D0, HALF = 0.5D0, ONE = 1.0D0,\r\n $ TWO = 2.0D0, EIGHT = 8.0D0 )\r\nC .. Scalar Arguments ..\r\n CHARACTER INDI\r\n INTEGER INFO, N\r\nC .. Array Arguments ..\r\n DOUBLE PRECISION XI(*), XR(*)\r\nC .. Local Scalars ..\r\n LOGICAL LINDI\r\n INTEGER I, J, K, L, M\r\n DOUBLE PRECISION PI2, TI, TR, WHELP, WI, WR, WSTPI, WSTPR\r\nC .. External Functions ..\r\n LOGICAL LSAME\r\n EXTERNAL LSAME\r\nC .. External Subroutines ..\r\n EXTERNAL XERBLA\r\nC .. Intrinsic Functions ..\r\n INTRINSIC ATAN, DBLE, MOD, SIN\r\nC .. Executable Statements ..\r\nC\r\n INFO = 0\r\n LINDI = LSAME( INDI, 'D' )\r\nC\r\nC Test the input scalar arguments.\r\nC\r\n IF( .NOT.LINDI .AND. .NOT.LSAME( INDI, 'I' ) ) THEN\r\n INFO = -1\r\n ELSE\r\n J = 0\r\n IF( N.GE.2 ) THEN\r\n J = N\r\nC WHILE ( MOD( J, 2 ).EQ.0 ) DO\r\n 10 CONTINUE\r\n IF ( MOD( J, 2 ).EQ.0 ) THEN\r\n J = J/2\r\n GO TO 10\r\n END IF\r\nC END WHILE 10\r\n END IF\r\n IF ( J.NE.1 ) INFO = -2\r\n END IF\r\nC\r\n IF ( INFO.NE.0 ) THEN\r\nC\r\nC Error return.\r\nC\r\n CALL XERBLA( 'DG01MD', -INFO )\r\n RETURN\r\n END IF\r\nC\r\nC Inplace shuffling of data.\r\nC\r\n J = 1\r\nC\r\n DO 30 I = 1, N\r\n IF ( J.GT.I ) THEN\r\n TR = XR(I)\r\n TI = XI(I)\r\n XR(I) = XR(J)\r\n XI(I) = XI(J)\r\n XR(J) = TR\r\n XI(J) = TI\r\n END IF\r\n K = N/2\r\nC REPEAT\r\n 20 IF ( J.GT.K ) THEN\r\n J = J - K\r\n K = K/2\r\n IF ( K.GE.2 ) GO TO 20\r\n END IF\r\nC UNTIL ( K.LT.2 )\r\n J = J + K\r\n 30 CONTINUE\r\nC\r\nC Transform by decimation in time.\r\nC\r\n PI2 = EIGHT*ATAN( ONE )\r\n IF ( LINDI ) PI2 = -PI2\r\nC\r\n I = 1\r\nC\r\nC WHILE ( I.LT.N ) DO\r\nC\r\n 40 IF ( I.LT.N ) THEN\r\n L = 2*I\r\n WHELP = PI2/DBLE( L )\r\n WSTPI = SIN( WHELP )\r\n WHELP = SIN( HALF*WHELP )\r\n WSTPR = -TWO*WHELP*WHELP\r\n WR = ONE\r\n WI = ZERO\r\nC\r\n DO 60 J = 1, I\r\nC\r\n DO 50 K = J, N, L\r\n M = K + I\r\n TR = WR*XR(M) - WI*XI(M)\r\n TI = WR*XI(M) + WI*XR(M)\r\n XR(M) = XR(K) - TR\r\n XI(M) = XI(K) - TI\r\n XR(K) = XR(K) + TR\r\n XI(K) = XI(K) + TI\r\n 50 CONTINUE\r\nC\r\n WHELP = WR\r\n WR = WR + WR*WSTPR - WI*WSTPI\r\n WI = WI + WHELP*WSTPI + WI*WSTPR\r\n 60 CONTINUE\r\nC\r\n I = L\r\n GO TO 40\r\nC END WHILE 40\r\n END IF\r\nC\r\n RETURN\r\nC *** Last line of DG01MD ***\r\n END\r\n", "meta": {"hexsha": "c0ec3ecbde40886bdc60ed573327662aeb28d017", "size": 6348, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "External/SLICOT/DG01MD.f", "max_stars_repo_name": "bgin/MissileSimulation", "max_stars_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2016-08-28T23:20:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-15T14:43:58.000Z", "max_issues_repo_path": "External/SLICOT/DG01MD.f", "max_issues_repo_name": "bgin/MissileSimulation", "max_issues_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-06-02T21:29:51.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-05T05:59:31.000Z", "max_forks_repo_path": "External/SLICOT/DG01MD.f", "max_forks_repo_name": "bgin/MissileSimulation", "max_forks_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-07-04T22:38:22.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-04T22:38:22.000Z", "avg_line_length": 28.5945945946, "max_line_length": 73, "alphanum_fraction": 0.4716446125, "num_tokens": 1936, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110396870288, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6833891210264507}} {"text": " program demo_lglin\n use M_calcomp\n implicit none\n ! based on concepts of CALIFORNIA COMPUTER PRODUCTS, 1968\n character(len=50) :: ibcd\n integer :: i, k\n integer :: inteq\n real :: a\n real :: angl\n real :: angle(19)\n real :: bang\n real :: beta\n real :: r(19)\n real :: theta\n real :: x\n real :: xx\n real :: xa,ya, xb,yb, xc,yc, xd,yd\n real :: xar(8)= [ 1.00, 2.00, 3.00, 4.00, 5.00, 6.00 , 0.0, 0.0 ]\n real :: yar(8)= [ 250.0, 110.0, 500.0, 900.0, 200.0, 140.0 , 0.0, 1.0 ]\n call plots(0.0,10.0,0.0,10.0)\n ! DRAW FRAME\n call plot(7.0,0.0,2)\n call plot(7.0,9.0,2)\n call plot(0.0,9.0,2)\n call plot(0.0,0.0,2)\n ! DRAW COMMENTS\n ibcd='USING SCALG, LGAXS, AND LGLIN SUBROUTINES'\n call symbol(0.7,8.25,0.14,ibcd,inteq,0.0,42)\n ibcd='USING POLAR SUBROUTINE'\n call symbol(0.7,3.80,0.14,ibcd,inteq,0.0,22)\n ! AXIS IS DRAWN\n ibcd='ALTITUDE'\n call axis(1.0,4.75,ibcd,-8,5.0,0.0,0.0,25.0)\n call scalg(yar,3.0,6,1)\n ibcd='TEMPERATURE'\n call lgaxs(1.0,4.75,ibcd,11,3.0,90.0,yar(7),yar(8))\n call scale(xar,5.0,6,1)\n call plot(1.0,4.75,-3)\n call lglin(xar,yar,6,1,0,1,1)\n call plot(-1.0,-4.75,-3)\n ! POLAR SUBROUTINE IS USED\n x=0.0\n do k=1,19\n theta=x*0.0174533\n r(k)=2.0*(1.0-cos(theta))\n angle(k)=theta\n x=x+10.0\n enddo\n call plot(5.0,0.75,-3)\n call polar(r,angle,19,1,0,1,0.0,1.0)\n angl =30.0\n a=1.0\n do i=1,5\n theta=angl *0.0174533\n xa=cos(theta)\n ya=sin(theta)\n call plot(xa,ya,3)\n xb=1.1*xa\n yb=1.1*ya\n call plot(xb,yb,2)\n xc=xb+0.05*xa\n yc=yb+0.05*ya\n if((i-3).gt.0)then\n a=1.5\n endif\n beta=1.570797-theta\n xd=xc-0.105*a*cos(beta)\n yd=yc+0.105*a*sin(beta)\n bang=270.0+angl\n call number(xd,yd,0.105,angl, bang,-1)\n angl =angl +30.0\n enddo\n xx=0.0\n do i=1,19\n angle(i) = xx*0.0174533\n r(i) = 1.0\n xx=xx+10.0\n enddo\n call polar(r,angle,19,1,0,1,0.0,1.0)\n call plot(-5.0,-0.75,-3)\n ! AXIS IS DRAWN\n ibcd=''\n call axis(1.0,0.75,ibcd,-1,4.0,0.0,4.0,-1.0)\n call axis(5.0,0.75,ibcd,-1,1.0,0.0,0.0,1.0)\n ibcd='RADIUS=2*(1-COS(ANGLE))'\n call symbol(3.75,3.5,0.09,ibcd,inteq,0.0,23)\n call plot(11.0,0.0,999)\n end program demo_lglin\n", "meta": {"hexsha": "ff9ce609481171fe7893dc0f9b089f48ed273da8", "size": 2812, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/demo_lglin.f90", "max_stars_repo_name": "urbanjost/M_calcomp", "max_stars_repo_head_hexsha": "72eb83b3cb6f6498c39097fcb379130beb27eedb", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-15T10:22:11.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-15T10:22:11.000Z", "max_issues_repo_path": "example/demo_lglin.f90", "max_issues_repo_name": "urbanjost/M_calcomp", "max_issues_repo_head_hexsha": "72eb83b3cb6f6498c39097fcb379130beb27eedb", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "example/demo_lglin.f90", "max_forks_repo_name": "urbanjost/M_calcomp", "max_forks_repo_head_hexsha": "72eb83b3cb6f6498c39097fcb379130beb27eedb", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.595505618, "max_line_length": 89, "alphanum_fraction": 0.4463015647, "num_tokens": 1122, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110396870287, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6833891210264506}} {"text": ": prime? HERE + C@ 0= ;\n: composite! HERE + 1 SWAP C! ;\n\n: sieve\n HERE OVER ERASE\n 2\n BEGIN\n 2DUP DUP * >\n WHILE\n DUP prime? IF\n 2DUP DUP * DO\n I composite!\n DUP +LOOP\n THEN\n 1+\n REPEAT\n DROP\n 1 SWAP 2 DO I prime? IF DROP I THEN LOOP .\n;\n\n: main 10000 sieve ;\n", "meta": {"hexsha": "6d71faea9cccb79fac2da13127ddef7a4498a3d0", "size": 296, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "experiments/waforth2c/examples/sieve.f", "max_stars_repo_name": "remko/waforth", "max_stars_repo_head_hexsha": "e50fbe7e1c34a30f458e0979b63e2af7a348ec45", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 205, "max_stars_repo_stars_event_min_datetime": "2018-05-25T14:01:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-19T18:17:51.000Z", "max_issues_repo_path": "experiments/waforth2c/examples/sieve.f", "max_issues_repo_name": "rigidus/waforth", "max_issues_repo_head_hexsha": "ba62bc39eca3fe313002cf31378d828f020437a6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 18, "max_issues_repo_issues_event_min_datetime": "2018-05-16T08:44:28.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-12T07:11:39.000Z", "max_forks_repo_path": "experiments/waforth2c/examples/sieve.f", "max_forks_repo_name": "rigidus/waforth", "max_forks_repo_head_hexsha": "ba62bc39eca3fe313002cf31378d828f020437a6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2018-06-07T04:34:15.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-26T09:19:59.000Z", "avg_line_length": 13.4545454545, "max_line_length": 44, "alphanum_fraction": 0.5405405405, "num_tokens": 113, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110368115781, "lm_q2_score": 0.7662936324115012, "lm_q1q2_score": 0.6833891188230112}} {"text": "\tsubroutine tuiep3 (xa, ya, x, y, dy)\nC\nC Evaluate a cubic polynomial interpolation function at X.\nC xa(klo) <= x <= xa(klo+1)\nC This routine was copied with slight modifications from the POLINT\nC subroutine in Numerical Recipes by Press, Flannery, Teukolsky and\nC Vetterling.\nC\nC XA\t\ti: array of four independent-variable values\nC YA\t\ti: array of four dependent-variable values\nC X\t\ti: the independent variable\nC Y\t\to: the result of interpolations\nC DY\t\to: an estimate of the error of interpolation\nC\nCH Phil Hodge, 18-Apr-1988 Subroutine copied from Numerical Recipes POLINT.\nC\n\tdouble precision xa(4), ya(4), x, y, dy\nC--\n\tinteger n\nC\t\t\t\t\tfour-point interpolation\n\tparameter (n = 4)\n\n\tdouble precision c(n), d(n), dif, dift, den\n\tdouble precision ho, hp, w\n\tinteger i, m, ns\n\n\tdo 10 i = 1, n\n\t if (x .eq. xa(i)) then\n\t\ty = ya(i)\n\t\treturn\n\t endif\n 10\tcontinue\n\n\tns = 1\n\tdif = abs (x - xa(1))\n\n\tdo 20 i = 1, n \n\t dift = abs (x - xa(i))\n\t if (dift .lt. dif) then\n\t\tns = i\n\t\tdif = dift\n\t endif\n\t c(i) = ya(i)\n\t d(i) = ya(i)\n 20\tcontinue\n\n\ty = ya(ns)\n\tns = ns - 1\n\n\tdo 40 m = 1, n-1\n\n\t do 30 i = 1, n-m\n\t\tho = xa(i) - x\n\t\thp = xa(i+m) - x\n\t\tw = c(i+1) - d(i)\n\t\tden = w / (ho - hp)\n\t\td(i) = hp * den\n\t\tc(i) = ho * den\n 30\t continue\n\n\t if (2*ns .lt. n-m) then\n\t\tdy = c(ns+1)\n\t else\n\t\tdy = d(ns)\n\t\tns = ns - 1\n\t endif\n\t y = y + dy\n 40\tcontinue\n\n\treturn\n\tend\n", "meta": {"hexsha": "58f81a99e7bd2cb72bf6f2ae5dbccedebcb52f47", "size": 1409, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iraf.v2161/pkg/utilities/nttools/trebin/tuiep3.f", "max_stars_repo_name": "ysBach/irafdocgen", "max_stars_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:19:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T16:48:42.000Z", "max_issues_repo_path": "iraf.v2161/pkg/utilities/nttools/trebin/tuiep3.f", "max_issues_repo_name": "ysBach/irafdocgen", "max_issues_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-30T13:48:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-02T19:40:25.000Z", "max_forks_repo_path": "iraf.v2161/pkg/utilities/nttools/trebin/tuiep3.f", "max_forks_repo_name": "ysBach/irafdocgen", "max_forks_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_forks_repo_licenses": ["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.5694444444, "max_line_length": 77, "alphanum_fraction": 0.5940383251, "num_tokens": 529, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467738423874, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.6833606743307691}} {"text": "program weather_average\n\n use mod_arrays, only: denan, normalize, &\n operator(.denan.), operator(.normalize.)\n use mod_average, only: average, operator(.average.)\n use mod_weather_data, only: weather_data\n\n implicit none\n\n type(weather_data) :: dataset\n character(len=4), parameter :: cities(*) = &\n ['EGLL', 'LAX ', 'LYBE', 'MIA ', 'MMMX', &\n 'NYC ', 'OIII', 'SEA ', 'SKBO', 'ZGSZ']\n integer :: n\n integer, parameter :: nm = size(cities)\n real :: temperature(nm), humidity(nm), wind_speed(nm), clear_sky(nm)\n real :: temperature_score(nm), humidity_score(nm),&\n wind_score(nm), clear_score(nm), total_score(nm)\n\n ! Read data and compute the averages\n do n = 1, nm\n dataset = weather_data('data/processed/' // trim(cities(n)) // '.csv')\n temperature(n) = .average. (.denan. dataset % temperature)\n humidity(n) = .average. (.denan. dataset % humidity)\n wind_speed(n) = .average. (.denan. dataset % wind_speed)\n clear_sky(n) = .average. dataset % clear_sky\n end do\n\n ! Compute scores\n temperature_score = .normalize. temperature ! the higher the better\n humidity_score = 1 - .normalize. humidity ! the lower the better\n wind_score = .normalize. wind_speed ! the higher the better\n clear_score = .normalize. clear_sky ! the higher the better\n total_score = (temperature_score + humidity_score &\n + wind_score + clear_score) / 4\n\n ! Generate the score table\n print *, 'City | Temp. | Humidity | Wind | Clear | Total'\n print *, 'Code | Score | Score | Score | Score | Score'\n print *, '-----+-------+----------+-------+-------+------'\n do n = 1, nm\n write(*,'(1x, a4, 3x, 5(f4.2, 5x))') cities(n), temperature_score(n),&\n humidity_score(n), wind_score(n), clear_score(n), total_score(n)\n end do\n\nend program weather_average\n", "meta": {"hexsha": "97b7de873140797bb99fc703630b8479b279fd1f", "size": 1793, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fortify/mf/generic-procedures/src/weather_average.f90", "max_stars_repo_name": "wilsonify/c-consumer", "max_stars_repo_head_hexsha": "e19a1baf4efb68436bbec50395f2a3a2c6e3c078", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 20, "max_stars_repo_stars_event_min_datetime": "2019-01-05T21:15:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T07:30:25.000Z", "max_issues_repo_path": "src/fortify/mf/generic-procedures/src/weather_average.f90", "max_issues_repo_name": "wilsonify/c-consumer", "max_issues_repo_head_hexsha": "e19a1baf4efb68436bbec50395f2a3a2c6e3c078", "max_issues_repo_licenses": ["MIT"], "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/fortify/mf/generic-procedures/src/weather_average.f90", "max_forks_repo_name": "wilsonify/c-consumer", "max_forks_repo_head_hexsha": "e19a1baf4efb68436bbec50395f2a3a2c6e3c078", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-10-10T08:50:54.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-13T21:36:14.000Z", "avg_line_length": 38.1489361702, "max_line_length": 74, "alphanum_fraction": 0.6441717791, "num_tokens": 514, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095294, "lm_q2_score": 0.7772998663336157, "lm_q1q2_score": 0.6833606648727875}} {"text": "PROGRAM time_random_normal\r\nIMPLICIT NONE\r\n\r\nINTERFACE\r\n FUNCTION random_normal() RESULT (ran_norm)\r\n IMPLICIT NONE\r\n REAL :: ran_norm\r\n END FUNCTION random_normal\r\n\r\n SUBROUTINE gasdev_s(harvest)\r\n IMPLICIT NONE\r\n REAL, INTENT(OUT) :: harvest\r\n END SUBROUTINE gasdev_s\r\nEND INTERFACE\r\n\r\nINTEGER :: i, k, start(8), finish(8)\r\nREAL :: x, time_taken\r\nINTEGER, ALLOCATABLE :: seed(:)\r\n\r\n! Set the random number seed.\r\n\r\nCALL RANDOM_SEED(size=k)\r\nALLOCATE (seed(k))\r\nCALL RANDOM_SEED(get=seed)\r\nWRITE(*, *)'Old random number seeds: ', seed\r\n\r\nWRITE(*, '(1x, a, i4, a)') 'Enter ', k, ' integers as random number seeds: '\r\nREAD(*, *) seed\r\nCALL RANDOM_SEED(put=seed)\r\n\r\n! Generate 10 million random normals using TOMS 712\r\n\r\nCALL DATE_AND_TIME( VALUES=start )\r\nDO i = 1, 10000000\r\n x = random_normal()\r\nEND DO\r\nCALL DATE_AND_TIME( VALUES=finish )\r\ntime_taken = 3600.*(finish(5) - start(5)) + 60.*(finish(6) - start(6)) + &\r\n (finish(7) - start(7)) + 0.001*(finish(8) - start(8))\r\nWRITE(*, '(a, f8.2, a)') ' Time taken using TOMS 712 = ', time_taken, ' sec.'\r\n\r\n! Generate 10 million random normals using NR\r\n\r\nCALL DATE_AND_TIME( VALUES=start )\r\nDO i = 1, 10000000\r\n CALL gasdev_s(x)\r\nEND DO\r\nCALL DATE_AND_TIME( VALUES=finish )\r\ntime_taken = 3600.*(finish(5) - start(5)) + 60.*(finish(6) - start(6)) + &\r\n (finish(7) - start(7)) + 0.001*(finish(8) - start(8))\r\nWRITE(*, '(a, f8.2, a)') ' Time taken using Num. Rec.= ', time_taken, ' sec.'\r\n\r\nSTOP\r\nEND PROGRAM time_random_normal\r\n\r\n\r\n\r\nFUNCTION random_normal() RESULT (ran_norm)\r\n\r\n! Adapted from the following Fortran 77 code\r\n! ALGORITHM 712, COLLECTED ALGORITHMS FROM ACM.\r\n! THIS WORK PUBLISHED IN TRANSACTIONS ON MATHEMATICAL SOFTWARE,\r\n! VOL. 18, NO. 4, DECEMBER, 1992, PP. 434-435.\r\n\r\n! The function random_normal() returns a normally distributed pseudo-random\r\n! number with zero mean and unit variance. This version uses the default\r\n! uniform random number generator which is in your fortran library.\r\n\r\n! The algorithm uses the ratio of uniforms method of A.J. Kinderman\r\n! and J.F. Monahan augmented with quadratic bounding curves.\r\n\r\n! Fortran 90 version by Alan Miller (alan @ mel.dms.csiro.au)\r\n\r\nIMPLICIT NONE\r\nREAL :: ran_norm\r\n\r\n! Local variables\r\nREAL, PARAMETER :: s = 0.449871, t = -0.386595, a = 0.19600, b = 0.25472, &\r\n half = 0.5, r1 = 0.27597, r2 = 0.27846\r\nREAL :: u, v, x, y, q\r\n\r\n! Generate P = (u,v) uniform in rectangle enclosing acceptance region\r\n\r\nDO\r\n CALL RANDOM_NUMBER(u)\r\n CALL RANDOM_NUMBER(v)\r\n v = 1.7156 * (v - half)\r\n\r\n! Evaluate the quadratic form\r\n x = u - s\r\n y = ABS(v) - t\r\n q = x**2 + y*(a*y - b*x)\r\n\r\n! Accept P if inside inner ellipse\r\n IF (q < r1) EXIT\r\n! Reject P if outside outer ellipse\r\n IF (q > r2) CYCLE\r\n! Reject P if outside acceptance region\r\n IF (v**2 < -4.0*LOG(u)*u**2) EXIT\r\nEND DO\r\n\r\n! Return ratio of P's coordinates as the normal deviate\r\nran_norm = v/u\r\nRETURN\r\n\r\nEND FUNCTION random_normal\r\n\r\n\r\n\r\nSUBROUTINE gasdev_s(harvest)\r\n! Numerical Recipes routine for generating a single normal random deviate,\r\n! adapted to use the compiler's random number generator.\r\n\r\nIMPLICIT NONE\r\nREAL, INTENT(OUT) :: harvest\r\n\r\n! Local variables\r\nREAL :: rsq, v1, v2\r\nREAL, SAVE :: g\r\nLOGICAL, SAVE :: gaus_stored = .false.\r\n\r\nIF (gaus_stored) THEN\r\n harvest = g\r\n gaus_stored = .false.\r\nELSE\r\n DO\r\n CALL RANDOM_NUMBER(v1)\r\n CALL RANDOM_NUMBER(v2)\r\n v1 = 2.0*v1 - 1.0\r\n v2 = 2.0*v2 - 1.0\r\n rsq = v1**2 + v2**2\r\n if (rsq > 0.0 .and. rsq < 1.0) EXIT\r\n END DO\r\n rsq = SQRT(-2.0*LOG(rsq)/rsq)\r\n harvest = v1*rsq\r\n g = v2*rsq\r\n gaus_stored = .true.\r\nEND IF\r\n\r\nRETURN\r\nEND SUBROUTINE gasdev_s\r\n", "meta": {"hexsha": "499b7d6bc2f5503089298f4737c31144b429942d", "size": 3819, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/ran_norm.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/ran_norm.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/ran_norm.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.8943661972, "max_line_length": 78, "alphanum_fraction": 0.6273893689, "num_tokens": 1193, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467611766711, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.6833606644857095}} {"text": "PROGRAM A6Q2\r\n!--\r\n! Determines the next permutation of the array A.\r\n!--\r\nIMPLICIT NONE\r\nINTEGER, DIMENSION(:), ALLOCATABLE :: An\r\nINTEGER :: n, check, invokenum, idx\r\nLOGICAL :: permcheck\r\n\r\nPRINT *, \"Determines the next possible permutation of A, if there is one\"\r\nDO\r\n\tPRINT *, \"Please enter the length of the array A (0 to stop)\"\r\n READ *, n\r\n IF (n .eq. 0) STOP\r\n ALLOCATE(An(n), STAT=check)\r\n IF (check .ne. 0) THEN\r\n \tPRINT *, \"Allocation for array A was unseccessfull\"\r\n ELSE\r\n \tPRINT *, \"Please enter the data for array A\"\r\n READ *, An\r\n\t\tPRINT *, \"How many permutations would you like to cycle through?\"\r\n READ *, invokenum\r\n DO idx = 1, invokenum\r\n\t\t\tpermcheck = NextPerm(An, n)\r\n PRINT *, \"Permutation\", idx\r\n IF (permcheck) THEN\r\n \tPRINT \"(1X, I2, 15I3)\", An\r\n ELSE\r\n \tPRINT *, \"No further permutations are available\"\r\n END IF\r\n END DO\r\n DEALLOCATE(An)\r\n END IF\r\nEND DO\r\n\r\nCONTAINS\r\n!- Do the next array shift \r\nLOGICAL FUNCTION NextPerm(A,n)\r\nINTEGER, DIMENSION(n), INTENT(INOUT) :: A\r\nINTEGER :: n\r\nINTEGER :: x, idxX, n0, n1, tmp\r\nLOGICAL :: possibleperm\r\n\r\nx = A(n)\r\nidxX = n\r\nn1 = n\r\nn0 = n - 1\r\npossibleperm = .false.\r\nDO WHILE (n0 .gt. 0)\r\n\tIF (A(n1) .gt. A(n0) .and. A(n0) .gt. x) idxX = n1\r\n IF (A(n0) .lt. A(n1)) THEN\r\n \tx = A(idxX)\r\n tmp = A(n0)\r\n A(n0) = x\r\n A(idxX) = tmp\r\n possibleperm = .true.\r\n n0 = 0\r\n ELSE\r\n \tn1 = n0\r\n n0 = n0 - 1\r\n END IF\r\nEND DO\r\nIF (possibleperm) CALL SelectionSort(A, n1, n)\r\nNextPerm = possibleperm\r\n\r\nEND FUNCTION NextPerm\r\n!- Sort the required set of A\r\nSUBROUTINE SelectionSort(A, i, j)\r\nINTEGER, DIMENSION(j), INTENT(INOUT) :: A\r\nINTEGER, INTENT(IN) :: i, j\r\nINTEGER :: min_idx, h, k, tmp\r\n\r\nh = i\r\nDO WHILE (h .lt. j)\r\n \tmin_idx = h\r\n \tDO k = h,j\r\n \tIF (A(min_idx) .gt. A(k)) min_idx = k\r\n END DO\r\n\ttmp = A(h)\r\n A(h) = A(min_idx)\r\n A(min_idx) = tmp\r\n\th = h + 1\r\nEND DO\r\n\r\nEND SUBROUTINE SelectionSort\r\nEND PROGRAM ", "meta": {"hexsha": "514d286f7fc4e9693efcd50cf09d991d0f0045b6", "size": 2092, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Assignment 6/A6Q2.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 6/A6Q2.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 6/A6Q2.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.3255813953, "max_line_length": 74, "alphanum_fraction": 0.5592734226, "num_tokens": 676, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746911, "lm_q2_score": 0.8791467706759584, "lm_q1q2_score": 0.6833606627986004}} {"text": "#include \"eiscor.h\"\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! ZARCG43 (Zomplex Auxiliary Routine Compute Givens generators 4->3)\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! This routine computes the generator for a Givens rotation represented\n! by 3 real numbers: the real and imaginary parts of a complex cosine\n! and a scrictly real sine. The first column is constructed to be \n! parallel with the complex vector [A,B]^T. The (4->3) refers to the \n! 4 double inputs and 3 double outputs (excluding the norm).\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! INPUT VARIABLES:\n!\n! AR, AI REAL(8) \n! real and imaginary part of the first component \n! of the complex vector [A,B]^T\n!\n! BR, BI REAL(8) \n! real and imaginary part of the second component \n! of the complex vector [A,B]^T\n!\n! OUTPUT VARIABLES:\n!\n! CR, CI REAL(8)\n! on exit contains the generators for the cosine\n! component of the Givens rotation\n!\n! S REAL(8)\n! on exit contains the generators for the sine\n! component of the Givens rotation\n!\n! NRM REAL(8)\n! on exit contains the norm of the vector [A,B]^T\n!\n! INFO INTEGER\n! INFO = 0 implies successful computation\n! INFO = -1 implies AR is invalid\n! INFO = -2 implies AI is invalid\n! INFO = -3 implies BR is invalid\n! INFO = -4 implies BI is invalid\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine ZARCG43(AR,AI,BR,BI,CR,CI,S,NRM,INFO)\n\n implicit none\n \n ! input variables\n integer, intent(inout) :: INFO\n real(8), intent(in) :: AR, AI, BR, BI\n real(8), intent(inout) :: CR, CI, S, NRM\n \n ! compute variables\n real(8) :: sr, si, temp\n \n ! initialize INFO\n INFO = 0\n \n ! print error in debug mode\n if (DEBUG) then\n \n ! check AR\n call DARNAN(AR,INFO)\n if (INFO.NE.0) then\n call UARERR(__FILE__,__LINE__,\"AR is invalid\",INFO,-1)\n return\n end if\n call DARINF(AR,INFO)\n if (INFO.NE.0) then\n call UARERR(__FILE__,__LINE__,\"AR is invalid\",INFO,-1)\n return\n end if \n\n ! check AI\n call DARNAN(AI,INFO)\n if (INFO.NE.0) then\n call UARERR(__FILE__,__LINE__,\"AI is invalid\",INFO,-2)\n return\n end if\n call DARINF(AI,INFO)\n if (INFO.NE.0) then\n call UARERR(__FILE__,__LINE__,\"AI is invalid\",INFO,-2)\n return\n end if \n\n ! check BR\n call DARNAN(BR,INFO)\n if (INFO.NE.0) then\n call UARERR(__FILE__,__LINE__,\"BR is invalid\",INFO,-3)\n return\n end if\n call DARINF(BR,INFO)\n if (INFO.NE.0) then\n call UARERR(__FILE__,__LINE__,\"BR is invalid\",INFO,-3)\n return\n end if\n \n ! check BI\n call DARNAN(BI,INFO)\n if (INFO.NE.0) then\n call UARERR(__FILE__,__LINE__,\"BI is invalid\",INFO,-4)\n return\n end if\n call DARINF(BI,INFO)\n if (INFO.NE.0) then\n call UARERR(__FILE__,__LINE__,\"BI is invalid\",INFO,-4)\n return\n end if\n\n end if \n \n ! compute NRM\n CR = abs(AR)\n CI = abs(AI)\n sr = abs(BR)\n si = abs(BI)\n \n ! exit if nrm is zero\n if ((CR.EQ.0).AND.(CI.EQ.0).AND.(sr.EQ.0).AND.(si.EQ.0)) then\n nrm = 0d0\n CR = 1d0\n CI = 0d0\n S = 0d0\n return\n end if\n \n ! find maximum value\n NRM = CR\n if (CI > NRM) then\n NRM = CI\n end if\n if (sr > NRM) then\n NRM = sr\n end if\n if (si > NRM) then\n NRM = si\n end if\n \n ! scale\n CR = CR/NRM\n CI = CI/NRM\n sr = sr/NRM\n si = si/NRM\n \n ! NRM\n NRM = NRM*sqrt(CR*CR + CI*CI + sr*sr + si*si)\n \n ! update Generators\n CR = AR/NRM\n CI = AI/NRM\n sr = BR/NRM\n si = BI/NRM\n \n ! check si\n if (abs(si) .EQ. 0d0) then\n S = sr\n return\n end if\n \n ! compute phase\n if (abs(sr) > abs(si)) then\n S = abs(sr)*sqrt(1d0+abs(si/sr)**2)\n else\n S = abs(si)*sqrt(1d0+abs(sr/si)**2)\n end if\n sr = sr/S\n si = si/S\n \n ! update CR and CI\n temp = CR*sr + CI*si\n CI = -CR*si + CI*sr\n CR = temp \n\nend subroutine ZARCG43\n", "meta": {"hexsha": "bc3ca83ce264a27687a1f9e4b6629b7a0f745d46", "size": 4237, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "deps/eiscor-master/src/complex_double/ZARCG43.f90", "max_stars_repo_name": "andreasnoack/EiSCor.jl", "max_stars_repo_head_hexsha": "d03d217e30e006b35263b99cb4adafd9d7e1e973", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "deps/eiscor-master/src/complex_double/ZARCG43.f90", "max_issues_repo_name": "andreasnoack/EiSCor.jl", "max_issues_repo_head_hexsha": "d03d217e30e006b35263b99cb4adafd9d7e1e973", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "deps/eiscor-master/src/complex_double/ZARCG43.f90", "max_forks_repo_name": "andreasnoack/EiSCor.jl", "max_forks_repo_head_hexsha": "d03d217e30e006b35263b99cb4adafd9d7e1e973", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.8033707865, "max_line_length": 71, "alphanum_fraction": 0.5230115648, "num_tokens": 1342, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146761176671, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.6833606554148057}} {"text": "!*********************************************************************\n!\n! This benchmark test program is measuring a cpu performance\n! of floating point operation by a Poisson equation solver.\n!!\n! If you have any question, please ask me via email.\n! written by Ryutaro HIMENO, November 26, 2001.\n! Version 3.0\n! ----------------------------------------------\n! Ryutaro Himeno, Dr. of Eng.\n! Head of Computer Information Division,\n! RIKEN (The Institute of Pysical and Chemical Research)\n! Email : himeno@postman.riken.go.jp\n! ---------------------------------------------------------------\n! You can adjust the size of this benchmark code to fit your target\n! computer. In that case, please chose following sets of\n! (mimax,mjmax,mkmax):\n! small : 65,33,33\n! small : 129,65,65\n! midium: 257,129,129\n! large : 513,257,257\n! ext.large: 1025,513,513\n! This program is to measure a computer performance in MFLOPS\n! by using a kernel which appears in a linear solver of pressure\n! Poisson eq. which appears in an incompressible Navier-Stokes solver.\n! A point-Jacobi method is employed in this solver as this method can \n! be easyly vectrized and be parallelized.\n! ------------------\n! Finite-difference method, curvilinear coodinate system\n! Vectorizable and parallelizable on each grid point\n! No. of grid points : imax x jmax x kmax including boundaries\n! ------------------\n! A,B,C:coefficient matrix, wrk1: source term of Poisson equation\n! wrk2 : working area, OMEGA : relaxation parameter\n! BND:control variable for boundaries and objects ( = 0 or 1)\n! P: pressure\n! -------------------\n! -------------------\n! \"use portlib\" statement on the next line is for Visual fortran\n! to use UNIX libraries. Please remove it if your system is UNIX.\n! -------------------\n! use portlib\n!\nMODULE pres\nREAL(kind=4), DIMENSION(:,:,:), ALLOCATABLE :: p\nEND MODULE pres\n\n!\nMODULE mtrx\nREAL(kind=4), ALLOCATABLE :: a(:,:,:,:), b(:,:,:,:), c(:,:,:,:)\nEND MODULE mtrx\n\n!\nMODULE bound\nREAL(kind=4), DIMENSION(:,:,:), ALLOCATABLE :: bnd\nEND MODULE bound\n\n!\nMODULE work\nREAL(kind=4), ALLOCATABLE :: wrk1(:,:,:), wrk2(:,:,:)\nEND MODULE work\n\n!\nMODULE others\nINTEGER :: mimax, mjmax, mkmax\nINTEGER :: imax, jmax, kmax\nREAL(kind=4), PARAMETER :: omega = 0.8\nEND MODULE others\n\n!\n!\nPROGRAM HimenoBMTxp_F90\nUSE others\n!\nIMPLICIT NONE\n!\nINTEGER :: nn\nINTEGER :: ic, icr, icm\nREAL(kind=4) :: flop, xmflops2, score, gosa\nREAL(kind=8) :: cpu0, cpu1, cpu, dt\n ! ttarget specifys the measuring period in sec\nREAL(kind=4), PARAMETER :: ttarget = 60.0\nREAL(kind=8), EXTERNAL :: second\n!\nCALL readparam()\n!\n!! Initializing matrixes\nCALL initmem()\nCALL initmt()\nPRINT *, ' mimax=',mimax,' mjmax=',mjmax,' mkmax=',mkmax\nPRINT *, ' imax=',imax,' jmax=',jmax,' kmax=',kmax\n!\nCALL system_clock(ic,icr,icm)\ndt = 1.0 / real(icr,8)\nPRINT '(2x,a,e10.5)', 'Time measurement accuracy : ',dt\n!! Start measuring\n!\nnn = 3\nPRINT *, ' Start rehearsal measurement process.'\nPRINT *, ' Measure the performance in 3 times.'\n!\ncpu0 = second()\n!! Jacobi iteration\nCALL jacobi(nn,gosa)\n!\ncpu1 = second()\ncpu = (cpu1 - cpu0) * dt\nflop = real(kmax - 2,4) * real(jmax - 2,4) * real(imax - 2,4) * 34.0\nIF (cpu .NE. 0.0) xmflops2 = flop / real(cpu,4) * 1.0e-6 * real(nn,4)\nPRINT *, ' MFLOPS:',xmflops2,' time(s):',cpu,gosa\n!\n!! end the test loop\nnn = int(ttarget / (cpu / 3.0))\nPRINT *, 'Now, start the actual measurement process.'\nPRINT *, 'The loop will be excuted in',nn,' times.'\nPRINT *, 'This will take about one minute.'\nPRINT *, 'Wait for a while.'\n!\n!! Jacobi iteration\ncpu0 = second()\n!! Jacobi iteration\nCALL jacobi(nn,gosa)\n!\ncpu1 = second()\ncpu = (cpu1 - cpu0) * dt\nIF (cpu .NE. 0.0) xmflops2 = flop * 1.0e-6 / real(cpu,4) * real(nn,4)\n!\n!!! xmflops2=nflop/cpu*1.0e-6*float(nn)\n!\nPRINT *, ' Loop executed for ',nn,' times'\nPRINT *, ' Gosa :',gosa\nPRINT *, ' MFLOPS:',xmflops2,' time(s):',cpu\nscore = xmflops2 / 82.84\nPRINT *, ' Score based on Pentium III 600MHz :',score\n!\n! pause\n! stop\nEND PROGRAM HimenoBMTxp_F90\n\n!\n!\nSUBROUTINE readparam()\n!\nUSE others\n!\nIMPLICIT NONE\n!\nCHARACTER(len=10) :: size\n!\nPRINT *, 'Select Grid-size:'\n! print *,'For example:'\nPRINT *, 'Grid-size= '\nPRINT *, ' XS (64x32x32)'\nPRINT *, ' S (128x64x64)'\nPRINT *, ' M (256x128x128)'\nPRINT *, ' L (512x256x256)'\nPRINT *, ' XL (1024x512x512)'\n! print *,' Grid-size = '\n! read(*,*) size\nsize = \"M\"\nCALL grid_set(size)\n!\nimax = mimax - 1\njmax = mjmax - 1\nkmax = mkmax - 1\n!\nRETURN\nEND SUBROUTINE readparam\n\n!\n!\nSUBROUTINE grid_set(size)\nUSE others\nIMPLICIT NONE\nCHARACTER(len=10), INTENT(IN) :: size\n!\nSELECT CASE(size)\nCASE (\"xs\")\nmimax = 65\nmjmax = 33\nmkmax = 33\nCASE (\"XS\")\nmimax = 65\nmjmax = 33\nmkmax = 33\nCASE (\"s\")\nmimax = 129\nmjmax = 65\nmkmax = 65\nCASE (\"S\")\nmimax = 129\nmjmax = 65\nmkmax = 65\nCASE (\"m\")\nmimax = 257\nmjmax = 129\nmkmax = 129\nCASE (\"M\")\nmimax = 257\nmjmax = 129\nmkmax = 129\nCASE (\"l\")\nmimax = 513\nmjmax = 257\nmkmax = 257\nCASE (\"L\")\nmimax = 513\nmjmax = 257\nmkmax = 257\nCASE (\"xl\")\nmimax = 1025\nmjmax = 513\nmkmax = 513\nCASE (\"XL\")\nmimax = 1025\nmjmax = 513\nmkmax = 513\nCASE DEFAULT\nPRINT *, 'Invalid input character !!'\nSTOP \nEND SELECT\n!\nRETURN\nEND SUBROUTINE grid_set\n\n!\n!\n!**************************************************************\nSUBROUTINE initmt()\n!**************************************************************\nUSE pres\nUSE mtrx\nUSE bound\nUSE work\nUSE others\n!\nIMPLICIT NONE\n!\nINTEGER :: i, j, k\n!\n! a=0.0\n! b=0.0\n! c=0.0\n! p=0.0\n! wrk1=0.0 \n! wrk2=0.0 \n! bnd=0.0 \n!_KZ start\n!$omp parallel\n!$omp do\n!_KZ end\nDO k = 1, mkmax\nDO j = 1, mjmax\nDO i = 1, mimax\na(i,j,k,1) = 0.0\na(i,j,k,2) = 0.0\na(i,j,k,3) = 0.0\na(i,j,k,4) = 0.0\nb(i,j,k,1) = 0.0\nb(i,j,k,2) = 0.0\nb(i,j,k,3) = 0.0\nc(i,j,k,1) = 0.0\nc(i,j,k,2) = 0.0\nc(i,j,k,3) = 0.0\np(i,j,k) = 0.0\nwrk1(i,j,k) = 0.0\nwrk2(i,j,k) = 0.0\nbnd(i,j,k) = 0.0\nEND DO\nEND DO\nEND DO\n!_KZ start\n!$omp end do\n!$omp end parallel\n!_KZ end\n!\n! a(1:imax,1:jmax,1:kmax,1:3)=1.0\n! a(1:imax,1:jmax,1:kmax,4)=1.0/6.0\n! c(1:imax,1:jmax,1:kmax,:)=1.0\n! bnd(1:imax,1:jmax,1:kmax)=1.0 \n! do k=1,kmax\n! p(:,:,k)=real((k-1)*(k-1),4)/real((kmax-1)*(kmax-1),4)\n! enddo\n!_KZ start\n!$omp parallel\n!$omp do\n!_KZ end\nDO k = 1, kmax\nDO j = 1, jmax\nDO i = 1, imax\na(i,j,k,1) = 1.0\na(i,j,k,2) = 1.0\na(i,j,k,3) = 1.0\na(i,j,k,4) = 1.0 / 6.0\nb(i,j,k,1) = 0.0\nb(i,j,k,2) = 0.0\nb(i,j,k,3) = 0.0\nc(i,j,k,1) = 1.0\nc(i,j,k,2) = 1.0\nc(i,j,k,3) = 1.0\np(i,j,k) = real((k - 1) * (k - 1),4) / real((kmax - 1) * (kmax - 1),4)\nwrk1(i,j,k) = 0.0\nwrk2(i,j,k) = 0.0\nbnd(i,j,k) = 1.0\nEND DO\nEND DO\nEND DO\n!_KZ start\n!$omp end do\n!$omp end parallel\n!_KZ end\n!\nRETURN\nEND SUBROUTINE initmt\n\n!\n!*************************************************************\nSUBROUTINE initmem()\n!*************************************************************\nUSE pres\nUSE mtrx\nUSE bound\nUSE work\nUSE others\n!\nIMPLICIT NONE\n!\nallocate( p(mimax,mjmax,mkmax) )\nallocate( a(mimax,mjmax,mkmax,4),b(mimax,mjmax,mkmax,3),c(mimax,mjmax,mkmax,3) )\nallocate( bnd(mimax,mjmax,mkmax) )\nallocate( wrk1(mimax,mjmax,mkmax),wrk2(mimax,mjmax,mkmax) )\n!\nRETURN\nEND SUBROUTINE initmem\n\n!\n!*************************************************************\nSUBROUTINE jacobi(nn,gosa)\nUSE pres\nUSE mtrx\nUSE bound\nUSE work\nUSE others\nIMPLICIT NONE\nINTEGER, INTENT(IN) :: nn\nREAL(kind=4), INTENT(INOUT) :: gosa\nINTEGER :: i, j, k, loop\nREAL(kind=4) :: s0, ss\n!\n!\nDO loop = 1, nn\ngosa = 0.0\n!_KZ start\n!$omp parallel\n!$omp do\n!_KZ end\nDO k = 2, kmax - 1\nDO j = 2, jmax - 1\nDO i = 2, imax - 1\ns0 = a(i,j,k,1) * p(i + 1,j,k) + a(i,j,k,2) * p(i,j + 1,k) + a(i,j,k,3) * p(i,j,k + 1) + b(i,j,k,1) * (p(i + 1,j + 1,k) - p(i + 1,j - 1,k) - p(i - 1,j + 1,k) + p(i - 1,j - 1,k)) + b(i,j,k,2) * (p(i,j + 1,k + 1) - p(i,j - 1,k + 1) - p(i,j + 1,k - 1) + p(i,j - 1,k - 1)) + b(i,j,k,3) * (p(i + 1,j,k + 1) - p(i - 1,j,k + 1) - p(i + 1,j,k - 1) + p(i - 1,j,k - 1)) + c(i,j,k,1) * p(i - 1,j,k) + c(i,j,k,2) * p(i,j - 1,k) + c(i,j,k,3) * p(i,j,k - 1) + wrk1(i,j,k)\nss = (s0 * a(i,j,k,4) - p(i,j,k)) * bnd(i,j,k)\ngosa = gosa + ss * ss\nwrk2(i,j,k) = p(i,j,k) + omega * ss\nEND DO\nEND DO\nEND DO\n!_KZ start\n!$omp end do\n!$omp end parallel\n!_KZ end\n! \n! p(2:imax-1,2:jmax-1,2:kmax-1)= &\n! wrk2(2:imax-1,2:jmax-1,2:kmax-1)\n!_KZ start\n!$omp parallel\n!$omp do\n!_KZ end\nDO k = 2, kmax - 1\nDO j = 2, jmax - 1\nDO i = 2, imax - 1\np(i,j,k) = wrk2(i,j,k)\nEND DO\nEND DO\nEND DO\n!_KZ start\n!$omp end do\n!$omp end parallel\n!_KZ end\n!\nEND DO\n!! End of iteration\nRETURN\nEND SUBROUTINE jacobi\n\n!\n!\n!\n FUNCTION second() result(rtime)\n!\nIMPLICIT NONE\n!\nINTEGER :: ic, ir, im\nREAL(kind=8) :: rtime\n!\nCALL system_clock(ic,ir,im)\n!\nrtime = real(ic,8)\n!\nEND FUNCTION second\n\n", "meta": {"hexsha": "ff830a98d622d6c7b45afd8645103b126c7e0971", "size": 8636, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "sample/rose_himenoBMTxp.f90", "max_stars_repo_name": "kazukomatsu/autoOMP_f", "max_stars_repo_head_hexsha": "519641e349c12369041da0645bcd3f2444ff46aa", "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": "sample/rose_himenoBMTxp.f90", "max_issues_repo_name": "kazukomatsu/autoOMP_f", "max_issues_repo_head_hexsha": "519641e349c12369041da0645bcd3f2444ff46aa", "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": "sample/rose_himenoBMTxp.f90", "max_forks_repo_name": "kazukomatsu/autoOMP_f", "max_forks_repo_head_hexsha": "519641e349c12369041da0645bcd3f2444ff46aa", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.0121654501, "max_line_length": 457, "alphanum_fraction": 0.5792033349, "num_tokens": 3389, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.822189134878876, "lm_q1q2_score": 0.6833567834792218}} {"text": "MODULE spline1_mod\n!-------------------------------------------------------------------------------\n!SPLINE1-SPLINE interpolation in 1d\n!\n!SPLINE1_MOD is an F90 module of cubic interpolating spline routines in 1d\n!\n!References:\n!\n! Forsythe, Malcolm, Moler, Computer Methods for Mathematical\n! Computations, Prentice-Hall, 1977, p.76\n! Engeln-Muellges, Uhlig, Numerical Algorithms with Fortran, Springer,\n! 1996, p.251\n! W.A.Houlberg, P.I.Strand, D.McCune 8/2001\n! W.A.Houlberg, F90 free form 8/2004\n!\n!Contains PUBLIC routines:\n!\n! SPLINE1_FIT -get the coefficients\n! SPLINE1_EVAL -evaluate the spline\n! SPLINE1_INTERP -interpolate from one grid to another\n! SPLINE1_INTEG -integrate the spline fit\n!\n!Comments:\n!\n! Spline interpolation routines are C2 (f, f', and f'' are continuous)\n!\n! The modernization of the code structure into an F90 module takes advantage of\n! some of the more attractive features of F90:\n! -use of KIND for precision declarations\n! -optional arguments for I/O\n! -generic names for all intrinsic functions\n! -compilation using either free or fixed form\n! -no common blocks or other deprecated Fortran features\n! -dynamic and automatic alocation of variables\n! -array syntax for vector operations\n!-------------------------------------------------------------------------------\nUSE spec_kind_mod\nIMPLICIT NONE\n\n!-------------------------------------------------------------------------------\n! Private procedures\n!-------------------------------------------------------------------------------\nPRIVATE :: &\n SPLINE1_SEARCH !find the indices that bracket an abscissa value\n ! called from SPLINE1_EVAL\n\n!-------------------------------------------------------------------------------\n! Public procedures\n!-------------------------------------------------------------------------------\nCONTAINS\n\nSUBROUTINE SPLINE1_FIT(n,x,f, &\n K_BC1,K_BCN)\n!-------------------------------------------------------------------------------\n!SPLINE1_FIT gets the coefficients for a 1d cubic interpolating spline\n!\n!References:\n! Forsythe, Malcolm, Moler, Computer Methods for Mathematical\n! Computations, Prentice-Hall, 1977, p.76\n! Engeln-Muellges, Uhlig, Numerical Algorithms with Fortran, Springer,\n! 1996, p.251\n! W.A.Houlberg, P.I.Strand, D.McCune 8/2001\n! D.McCune, W.A.Houlberg 3/2004\n! W.A.Houlberg, F90 free form 8/2004\n!\n!Comments:\n! For x(i).le.x.le.x(i+1)\n! s(x) = f(1,i) + f(2,i)*(x-x(i)) + f(3,i)*(x-x(i))**2/2!\n! +f(4,i)*(x-x(i))**3/3!\n! The cubic spline is twice differentiable (C2)\n! The BCs default to not-a-knot conditions, K_BC1=0 and K_BCN=0\n! Two errors fixed in 3/2004 version:\n! Logic for not-a-knot on f(3,1) and f(3,n) after back substitution\n! Treatment of asymmetrix coefficient matrix for s''=0 BC\n! For s''=0 the off-diagonal elements nearest the corners are not symmetric,\n! i.e., el(1,2) /= el(2,1) and el(n-1,n) /= el(n,n-1). The correct values:\n! el(1,2)=0, el(2,1)=x(2)-x(1), el(n,n-1)=0, el(n-1,n)=x(n)-x(n-1) are fixed\n! by adding variables to hold the el21 and elnn1 values.\n!-------------------------------------------------------------------------------\n\n!Declaration of input variables\nINTEGER, INTENT(IN) :: &\n n !number of data points or knots [>=2]\n\nREAL(KIND=rspec), INTENT(IN) :: &\n x(:) !abscissas of the knots in increasing order [arb]\n\n!Declaration of input/output variables\nREAL(KIND=rspec), INTENT(INOUT) :: &\n f(:,:) !ordinates of the knots [arb]\n !f(2,1)=input value of s'(x1) for K_BC1=1 [arb]\n !f(2,n)=input value of s'(xn) for K_BCN=1 [arb]\n !f(3,1)=input value of s''(x1) for K_BC1=2 [arb]\n !f(3,n)=input value of s''(xn) for K_BCN=2 [arb]\n !f(2,i)=output s'(x(i)) [arb]\n !f(3,i)=output s''(x(i)) [arb]\n !f(4,i)=output s'''(x(i)) [arb]\n\n!Declaration of optional input variables\nINTEGER, INTENT(IN), OPTIONAL :: &\n K_BC1, & !option for BC at x(1) [-]\n !=-1 periodic, ignore K_BCN\n !=0 not-a-knot (default)\n !=1 s'(x1) = input value of f(2,1)\n !=2 s''(x1) = input value of f(3,1)\n !=3 s'(x1) = 0.0\n !=4 s''(x1) = 0.0\n !=5 match first derivative to first 2 points\n !=6 match second derivative to first 3 points\n !=7 match third derivative to first 4 points\n !=else use not-a-knot\n K_BCN !option for boundary condition at x(n) [-]\n !=0 not-a-knot (default)\n !=1 s'(x1) = input value of f(2,1)\n !=2 s''(x1) = input value of f(3,1)\n !=3 s'(x1) = 0.0\n !=4 s''(x1) = 0.0\n !=5 match first derivative to first 2 points\n !=6 match second derivative to first 3 points\n !=7 match third derivative to first 4 points\n !=else use knot-a-knot\n\n!-------------------------------------------------------------------------------\n!Declaration of local variables\nINTEGER :: &\n i,ib,imax,imin,kbc1,kbcn\n\nREAL(KIND=rspec) :: &\n a1,an,b1,bn,el21,elnn1,hn,q,t,wk(1:n)\n\n!-------------------------------------------------------------------------------\n!Initialization\n!-------------------------------------------------------------------------------\n!Set left BC option, and leftmost node\n!Default to not-a-knot\nkbc1=0\n\n!Otherwise use requested value\nIF(PRESENT(K_BC1)) THEN\n\n IF(K_BC1 >= -1 .AND. & \n K_BC1 <= 7) kbc1=K_BC1\n\nENDIF\n\n!Include first node for all but not-a-knot\nimin=1\n\n!Not-a-knot condition removes first node\nIF(kbc1 == 0) imin=2\n\n!Set left BC values\n!Default for not-a-knot\na1=0\nb1=0\n\nIF(kbc1 == 1) THEN\n\n !First derivative specified\n a1=f(2,1)\n\nELSEIF(kbc1 == 2) THEN\n\n !Second derivative specified\n b1=f(3,1)\n\nELSEIF(kbc1 == 5) THEN\n\n !Match first derivative to first two points\n a1=(f(1,2)-f(1,1))/(x(2)-x(1))\n\nELSEIF(kbc1 == 6) THEN\n\n !Match second derivative to first three points\n b1=2*((f(1,3)-f(1,2))/(x(3)-x(2))-(f(1,2)-f(1,1))/(x(2)-x(1)))/(x(3)-x(1))\n\nENDIF\n\n!Set right BC option, and rightmost node\n!Default to not-a-knot\nkbcn=0\n\n!Otherwise use requested value\nIF(PRESENT(K_BCN)) THEN\n\n IF(K_BCN >= -1 .AND. &\n K_BCN <= 7) kbcn=K_BCN\n\nENDIF\n\n!Include last node for all but not-a-knot\nimax=n\n\n!Not-a-knot condition removes last node\nIF(kbcn == 0) imax=n-1\n\n!Set right BC values\n!Default for not-a-knot\nan=0\nbn=0\n\nIF(kbcn == 1) THEN\n\n !First derivative specified\n an=f(2,n)\n\nELSEIF(kbcn == 2) THEN\n\n !Second derivative specified\n bn=f(3,n)\n\nELSEIF(kbcn == 5) THEN\n\n !Match first derivative to last two points\n an=(f(1,n)-f(1,n-1))/(x(n)-x(n-1))\n\nELSEIF(kbcn == 6) THEN\n\n !Match second derivative to first three points\n bn=2*((f(1,n)-f(1,n-1))/(x(n)-x(n-1)) & \n -(f(1,n-1)-f(1,n-2))/(x(n-1)-x(n-2)))/(x(n)-x(n-2))\n\nENDIF\n\n!Clear derivatives, f(2:4,1:n), and work array\nf(2:4,1:n)=0\nwk(1:n)=0\n\n!-------------------------------------------------------------------------------\n!Evaluate coefficients\n!-------------------------------------------------------------------------------\n!Two and three nodes are special cases\nIF(n == 2) THEN\n\n !Coefficients for n=2\n f(2,1)=(f(1,2)-f(1,1))/(x(2)-x(1))\n f(3,1)=0\n f(4,1)=0\n f(2,2)=f(2,1)\n f(3,2)=0\n f(4,2)=0\n\n!Set up tridiagonal system for A*y=B where y(i) are the second\n! derivatives at the knots\n! f(2,i) are the diagonal elements of A\n! f(4,i) are the off-diagonal elements of A\n! f(3,i) are the B elements/3, and will become c/3 upon solution\n\nELSEIF(n > 2) THEN\n\n f(4,1)=x(2)-x(1)\n f(3,2)=(f(1,2)-f(1,1))/f(4,1)\n\n DO i=2,n-1 !Over nodes\n\n f(4,i)=x(i+1)-x(i)\n f(2,i)=2*(f(4,i-1)+f(4,i))\n f(3,i+1)=(f(1,i+1)-f(1,i))/f(4,i)\n f(3,i)=f(3,i+1)-f(3,i)\n\n ENDDO !Over nodes\n\n !Save elements for non-symmetric matrix cases\n el21=f(4,1)\n elnn1=f(4,n-1)\n\n!Apply left BC\n IF(kbc1 == -1) THEN\n\n !Periodic\n f(2,1)=2*(f(4,1)+f(4,n-1))\n f(3,1)=(f(1,2)-f(1,1))/f(4,1)-(f(1,n)-f(1,n-1))/f(4,n-1)\n wk(1)=f(4,n-1)\n wk(2:n-3)=0\n wk(n-2)=f(4,n-2)\n wk(n-1)=f(4,n-1)\n\n ELSEIF((kbc1 == 1) .OR. &\n (kbc1 == 3) .OR. & \n (kbc1 == 5)) THEN\n\n !First derivative conditions\n f(2,1)=2*f(4,1)\n f(3,1)=(f(1,2)-f(1,1))/f(4,1)-a1\n\n ELSEIF((kbc1 == 2) .OR. (kbc1 == 4) .OR. (kbc1 == 6)) THEN\n\n !Second derivative conditions\n f(2,1)=2*f(4,1)\n f(3,1)=f(4,1)*b1/3\n f(4,1)=0\n\n ELSEIF(kbc1 == 7) THEN\n\n !Third derivative condition\n f(2,1)=-f(4,1)\n f(3,1)=f(3,3)/(x(4)-x(2))-f(3,2)/(x(3)-x(1))\n f(3,1)=f(3,1)*f(4,1)**2/(x(4)-x(1))\n\n ELSE\n\n !Not-a-knot condition\n f(2,2)=f(4,1)+2*f(4,2)\n f(3,2)=f(3,2)*f(4,2)/(f(4,1)+f(4,2))\n\n ENDIF\n\n !Apply right BC\n IF((kbcn == 1) .OR. &\n (kbcn == 3) .OR. & \n (kbcn == 5)) THEN\n\n !First derivative conditions\n f(2,n)=2*f(4,n-1)\n f(3,n)=-(f(1,n)-f(1,n-1))/f(4,n-1)+an\n\n ELSEIF((kbcn == 2) .OR. &\n (kbcn == 4) .OR. &\n (kbcn == 6)) THEN\n\n !Second derivative conditions\n f(2,n)=2*f(4,n-1)\n f(3,n)=f(4,n-1)*bn/3\n elnn1=0\n\n ELSEIF(kbcn == 7) THEN\n\n !Third derivative condition\n f(2,n)=-f(4,n-1)\n f(3,n)=f(3,n-1)/(x(n)-x(n-2))-f(3,n-2)/(x(n-1)-x(n-3))\n f(3,n)=-f(3,n)*f(4,n-1)**2/(x(n)-x(n-3))\n\n ELSEIF(kbc1 /= -1) THEN\n\n !Not-a-knot condition\n f(2,n-1)=2*f(4,n-2)+f(4,n-1)\n f(3,n-1)=f(3,n-1)*f(4,n-2)/(f(4,n-1)+f(4,n-2))\n\n ENDIF\n\n !Limit solution for only three points in domain\n IF(n == 3) THEN\n\n f(3,1)=0\n f(3,n)=0\n\n ENDIF\n\n !Solve system of equations for second derivatives at the knots\n IF(kbc1 == -1) THEN\n\n !Periodic BC - requires special treatment at ends\n !Forward elimination\n DO i=2,n-2 !Over nodes in forward elimination\n\n t=f(4,i-1)/f(2,i-1)\n f(2,i)=f(2,i)-t*f(4,i-1)\n f(3,i)=f(3,i)-t*f(3,i-1)\n wk(i)=wk(i)-t*wk(i-1)\n q=wk(n-1)/f(2,i-1)\n wk(n-1)=-q*f(4,i-1)\n f(2,n-1)=f(2,n-1)-q*wk(i-1)\n f(3,n-1)=f(3,n-1)-q*f(3,i-1)\n\n ENDDO !Over nodes in forward elimination\n\n !Correct the n-1 element\n wk(n-1)=wk(n-1)+f(4,n-2)\n\n !Complete the forward elimination\n !wk(n-1) and wk(n-2) are the off-diag elements of the lower corner\n t=wk(n-1)/f(2,n-2)\n f(2,n-1)=f(2,n-1)-t*wk(n-2)\n f(3,n-1)=f(3,n-1)-t*f(3,n-2)\n\n !Back substitution\n f(3,n-1)=f(3,n-1)/f(2,n-1)\n f(3,n-2)=(f(3,n-2)-wk(n-2)*f(3,n-1))/f(2,n-2)\n\n DO ib=3,n-1 !Over nodes in back substitution\n\n i=n-ib\n f(3,i)=(f(3,i)-f(4,i)*f(3,i+1)-wk(i)*f(3,n-1))/f(2,i)\n\n ENDDO !Over nodes in back substitution\n\n f(3,n)=f(3,1)\n\n ELSE\n\n !Non-periodic BC\n !Forward elimination\n !For not-a-knot and s''=0 BCs the off-diagonal end elements are not equal\n DO i=imin+1,imax !Over nodes in forward elimination\n\n IF((i == n-1) .AND. &\n (imax == n-1)) THEN\n\n t=(f(4,i-1)-f(4,i))/f(2,i-1)\n\n ELSE\n\n IF(i == 2) THEN\n\n t=el21/f(2,i-1)\n\n ELSEIF(i == n) THEN\n\n t=elnn1/f(2,i-1)\n\n ELSE\n\n t=f(4,i-1)/f(2,i-1)\n\n ENDIF\n\n ENDIF\n\n IF((i == imin+1) .AND. &\n (imin == 2)) THEN\n\n f(2,i)=f(2,i)-t*(f(4,i-1)-f(4,i-2))\n\n ELSE\n\n f(2,i)=f(2,i)-t*f(4,i-1)\n\n ENDIF\n\n f(3,i)=f(3,i)-t*f(3,i-1)\n\n ENDDO !Over nodes in forward elimination\n\n !Back substitution\n f(3,imax)=f(3,imax)/f(2,imax)\n\n DO ib=1,imax-imin !Over nodes in back substitution\n\n i=imax-ib\n\n IF((i == 2) .AND. &\n (imin == 2)) THEN\n\n f(3,i)=(f(3,i)-(f(4,i)-f(4,i-1))*f(3,i+1))/f(2,i)\n\n ELSE\n\n f(3,i)=(f(3,i)-f(4,i)*f(3,i+1))/f(2,i)\n\n ENDIF\n\n ENDDO !Over nodes in back substitution\n\n !Reset d array to step size\n f(4,1)=x(2)-x(1)\n f(4,n-1)=x(n)-x(n-1)\n\n !Set f(3,1) for not-a-knot; 5 changed to 7 in 3/2004\n IF((kbc1 <= 0) .OR. &\n (kbc1 > 7)) THEN\n\n f(3,1)=(f(3,2)*(f(4,1)+f(4,2))-f(3,3)*f(4,1))/f(4,2)\n\n ENDIF\n\n !Set f(3,n) for not-a-knot; 5 changed to 7 in 3/2004\n IF((kbcn <= 0) .OR. &\n (kbcn > 7)) THEN\n\n f(3,n)=f(3,n-1)+(f(3,n-1)-f(3,n-2))*f(4,n-1)/f(4,n-2)\n\n ENDIF\n\n ENDIF\n\n !f(3,i) is now the sigma(i) of the text and f(4,i) is the step size\n !Compute polynomial coefficients\n DO i=1,n-1 !Over nodes\n\n f(2,i)=(f(1,i+1)-f(1,i))/f(4,i)-f(4,i)*(f(3,i+1)+2*f(3,i))\n f(4,i)=(f(3,i+1)-f(3,i))/f(4,i)\n f(3,i)=6*f(3,i)\n f(4,i)=6*f(4,i)\n\n ENDDO !Over nodes\n\n IF(kbc1 == -1) THEN\n\n !Periodic BC\n f(2,n)=f(2,1)\n f(3,n)=f(3,1)\n f(4,n)=f(4,1)\n\n ELSE\n\n !All other BCs\n hn=x(n)-x(n-1)\n f(2,n)=f(2,n-1)+hn*(f(3,n-1)+hn*f(4,n-1)/2)\n f(3,n)=f(3,n-1)+hn*f(4,n-1)\n f(4,n)=f(4,n-1)\n\n IF((kbcn == 1) .OR. &\n (kbcn == 3) .OR. &\n (kbcn == 5)) THEN\n\n !First derivative BC\n f(2,n)=an\n\n ELSEIF((kbcn == 2) .OR. &\n (kbcn == 4) .OR. &\n (kbcn == 6)) THEN\n\n !Second derivative BC\n f(3,n)=bn\n\n ENDIF\n\n ENDIF\n\nENDIF\n\nEND SUBROUTINE SPLINE1_FIT\n\nSUBROUTINE SPLINE1_EVAL(k_vopt,n,u,x,f, &\n i, &\n value)\n!-------------------------------------------------------------------------------\n!SPLINE1_EVAL evaluates the cubic spline function and its derivatives\n!\n!References:\n! W.A.Houlberg, P.I. Strand, D.McCune 8/2001\n! W.A.Houlberg, F90 free form 8/2004\n!\n!Comments:\n! s=f(1,i)+f(2,i)*dx+f(3,i)*dx**2/2!+f(4,i)*dx**3/3!\n! s'=f(2,i)+f(3,i)*dx+f(4,i)*dx**2/2!\n! s''=f(3,i)+f(4,i)*dx\n! where dx=u-x(i) and x(i).lt.u.lt.x(i+1)\n! If u <= x(1) then i=1 is used\n! If u >= x(n) then i=n is used\n!-------------------------------------------------------------------------------\n\n!Declaration of input variables\nINTEGER, INTENT(IN) :: &\n k_vopt(:), & !k_vopt(1)=calculate the function [0=off]\n !k_vopt(2)=calculate the first derivative [0=off]\n !k_vopt(3)=calculate the second derivative [0=off]\n n !number of data points [-]\n\nREAL(KIND=rspec), INTENT(IN) :: &\n u, & !abscissa at which the spline is to be evaluated [arb]\n f(:,:), & !array containing the data ordinates [arb]\n x(:) !array containing the data abcissas [arb]\n\n!Declaration of input/output variables\nINTEGER, INTENT(INOUT) :: &\n i !in=guess for target lower bound if 1= n) THEN\n\n i=n\n dx=0\n\nELSE\n\n dx=u-x(i)\n\nENDIF\n\n!-------------------------------------------------------------------------------\n!Evaluate spline\n!-------------------------------------------------------------------------------\nj=0\n\n!Value\nIF(k_vopt(1) /= 0) THEN\n\n j=j+1\n value(j)=f(1,i)+dx*(f(2,i)+dx/2*(f(3,i)+f(4,i)*dx/3))\n\nENDIF\n\n!First derivative\nIF(k_vopt(2) /= 0) THEN\n\n j=j+1\n value(j)=f(2,i)+dx*(f(3,i)+f(4,i)*dx/2)\n\nENDIF\n\n!Second derivative\nIF(k_vopt(3) /= 0) THEN\n\n j=j+1\n value(j)=f(3,i)+dx*f(4,i)\n\nENDIF\n\nEND SUBROUTINE SPLINE1_EVAL\n\nSUBROUTINE SPLINE1_INTERP(k_vopt,n0,x0,f,n1,x1,value, & \n iflag,message, &\n K_BC1,K_BCN)\n!-------------------------------------------------------------------------------\n!SPLINE1_INTERP performs a spline interpolation from the x0 mesh to the x1 mesh\n!\n!References:\n! W.A.Houlberg, P.I.Strand, D.McCune 8/2001\n! W.A.Houlberg, F90 free form 8/2004\n!-------------------------------------------------------------------------------\n\n!Declaration of input variables\nINTEGER, INTENT(IN) :: &\n k_vopt(:), & !option for output values\n !k_vopt(1)=calculate the function [0=off]\n !k_vopt(2)=calculate the first derivative [0=off]\n !k_vopt(3)=calculate the second derivative [0=off]\n n0, & !number of source abscissas [-]\n n1 !number of target abscissas [-]\n\nREAL(KIND=rspec), INTENT(IN) :: &\n x0(:), & !source abscissas (in increasing order) [arb]\n x1(:) !target abscissas (in increasing order) [arb]\n\n!Declaration of input/output variables\nREAL(KIND=rspec), INTENT(INOUT) :: &\n f(:,:) !f(1,n0)=input source values [arb]\n !f(2,1)=input value of s'(x1) for K_BC1=1 [arb]\n !f(2,n0)=input value of s'(xn) for K_BCN=1 [arb]\n !f(3,1)=input value of s''(x1) for K_BC1=2 [arb]\n !f(3,n0)=input value of s''(xn) for K_BCN=2 [arb]\n !f(4,n)=output arrays of n0 spline coefficients\n !f(2,i)=output s'(x0(i))/1!\n !f(3,i)=output s''(x0(i))/2!\n !f(4,i)=output s'''(x0(i))/3!\n\n!Declaration of output variables\nCHARACTER(len=*), INTENT(OUT) :: &\n message !warning or error message [character]\n \nINTEGER, INTENT(OUT) :: &\n iflag !error and warning flag [-]\n !=-1 warning\n !=0 none\n !=1 error\n\nREAL(KIND=rspec), INTENT(OUT) :: &\n value(:,:) !ordering is a subset of the sequence under k_vopt [arb]\n !value(1,j)=function or lowest order derivative requested [arb]\n !value(2,j)=next order derivative requested [arb]\n !value(3,j)=second derivative if all k_vopt are non-zero [arb]\n\n\n!Declaration of optional input variables\nINTEGER, INTENT(IN), OPTIONAL :: &\n K_BC1, & !option for BC at x0(1) [-]\n !=-1 periodic, ignore K_BCN\n !=0 not-a-knot (default)\n !=1 s'(x1) = input value of f(2,1)\n !=2 s''(x1) = input value of f(3,1)\n !=3 s'(x1) = 0.0\n !=4 s''(x1) = 0.0\n !=5 match first derivative to first 2 points\n !=6 match second derivative to first 3 points\n !=7 match third derivative to first 4 points\n !=else use not-a-knot\n K_BCN !option for boundary condition at x0(n0) [-]\n !=0 not-a-knot (default)\n !=1 s'(x1) = input value of f(2,1)\n !=2 s''(x1) = input value of f(3,1)\n !=3 s'(x1) = 0.0\n !=4 s''(x1) = 0.0\n !=5 match first derivative to first 2 points\n !=6 match second derivative to first 3 points\n !=7 match third derivative to first 4 points\n !=else use knot-a-knot\n\n!-------------------------------------------------------------------------------\n!Declaration of local variables\nINTEGER :: &\n i,j\n\n!-------------------------------------------------------------------------------\n!Initialization\n!-------------------------------------------------------------------------------\n!If no target values are requested, return\nIF(n1 <= 0) THEN\n\n iflag=-1\n message='SPLINE1_INTERP/WARNING(1):no points in output array'\n GOTO 9999\n\nENDIF\n\n!Make sure there are at least two nodes in the input grid\nIF(n0 < 2) THEN\n\n iflag=1\n message='SPLINE1_INTERP/ERROR(2):<2 points in source array'\n GOTO 9999\n\nENDIF\n\n!-------------------------------------------------------------------------------\n!Get spline coefficients\n!-------------------------------------------------------------------------------\nIF(PRESENT(K_BC1) .AND. &\n PRESENT(K_BCN)) THEN\n\n CALL SPLINE1_FIT(n0,x0,f, &\n K_BC1=K_BC1, &\n K_BCN=K_BCN)\n\n ELSEIF(PRESENT(K_BC1)) THEN\n\n CALL SPLINE1_FIT(n0,x0,f, &\n K_BC1=K_BC1)\n\n ELSEIF(PRESENT(K_BCN)) THEN\n\n CALL SPLINE1_FIT(n0,x0,f, &\n K_BCN=K_BCN)\n\n ELSE\n\n CALL SPLINE1_FIT(n0,x0,f)\n\nENDIF\n\n!-------------------------------------------------------------------------------\n!Interpolate onto x1 mesh\n!-------------------------------------------------------------------------------\ni=1\n\nDO j=1,n1 !Over nodes\n\n CALL SPLINE1_EVAL(k_vopt,n0,x1(j),x0,f,i,value(1:3,j))\n\nENDDO !Over nodes\n\n!-------------------------------------------------------------------------------\n!Cleanup and exit\n!-------------------------------------------------------------------------------\n 9999 CONTINUE\n\nEND SUBROUTINE SPLINE1_INTERP\n\nSUBROUTINE SPLINE1_INTEG(k_order,n0,x0,f,n1,x1, &\n value,iflag,message)\n!-------------------------------------------------------------------------------\n!SPLINE1_INTEG evaluates the integral f(x)*x**k_order, where f(x) is a cubic\n! spline function and k_order is 0 or 1\n!\n!References:\n! Forsythe, Malcolm, Moler, Computer Methods for Mathematical\n! Computations, Prentice-Hall (1977) 76\n! W.A.Houlberg, P.I.Strand, D.McCune 8/2001\n! W.A.Houlberg, F90 free form 8/2004\n!-------------------------------------------------------------------------------\n\n!Declaration of input variables\nINTEGER, INTENT(IN) :: &\n k_order, & !exponent in integral (s(x)*x**k_order) [-]\n !=0 or 1 only\n n0, & !number of source nodes [-]\n n1 !number of output nodes (may be 1) [-]\n\nREAL(KIND=rspec), INTENT(IN) :: &\n x0(:), & !source abcissas [arb]\n x1(:), & !output abcissas at which the integral is wanted [arb]\n f(:,:) !f(1,n0)=source ordinates [arb]\n !f(2-4,n0)=spline coefficients computed by SPLINE1_FIT [arb]\n\n\n!Declaration of output variables\nCHARACTER(len=*), INTENT(OUT) :: &\n message !warning or error message [character]\n\nINTEGER, INTENT(OUT) :: &\n iflag !error and warning flag [-]\n !=-1 warning\n !=0 none\n !=1 error\n\nREAL(KIND=rspec), INTENT(OUT) :: &\n value(:) !integral of f(x)*x**k_order from x0(1) to x1(i) [arb]\n\n!-------------------------------------------------------------------------------\n!Declaration of local variables\nINTEGER :: &\n i,j,ido,jdo\n\nREAL(KIND=rspec) :: &\n add,dx,sum,xnew,xold\n\n!-------------------------------------------------------------------------------\n!Initialization\n!-------------------------------------------------------------------------------\n!If no target values are requested, return\nIF(n1 <= 0) GOTO 9999\n\nvalue(1:n1)=0\n\n!Integral value\nsum=0\n\n!Source index and abscissa\nj=1\nxold=x0(j)\n\n!-------------------------------------------------------------------------------\n!Integrate over target abscissas\n!-------------------------------------------------------------------------------\nDO i=1,n1 !Over target abscissas\n\n !Find dx to next source or target abscissa\n ido=0\n\n DO WHILE(ido == 0) !Over source abscissas\n\n IF(x1(i) < x0(j+1)) THEN\n\n !Hit target abscissa\n xnew=x1(i)\n ido=1\n jdo=0\n\n ELSEIF(x1(i) == x0(j+1)) THEN\n\n !Hit both source and target abscissas\n xnew=x1(i)\n ido=1\n jdo=1\n\n ELSEIF(x1(i) > x0(j+1)) THEN\n\n !Hit source abscissa\n xnew=x0(j+1)\n ido=0\n jdo=1\n\n ENDIF\n\n !Integrate over dx\n dx=xnew-xold\n\n IF(k_order == 1) THEN\n\n !Integral x s(x)dx\n add= dx*(xold*f(1,j) &\n +dx*((xold*f(2,j)+f(1,j))/2 &\n +dx*((xold*f(3,j)/2+f(2,j))/3 &\n +dx*((xold*f(4,j)/3+f(3,j))/8 &\n +dx*f(4,j)/30))))\n\n ELSE\n\n !Integral s(x)dx\n add=dx*(f(1,j)+dx*(f(2,j)+dx*(f(3,j)+dx*f(4,j)/4)/3)/2)\n\n ENDIF\n\n !Add increment and update endpoint\n sum=sum+add\n xold=xnew\n\n !Check whether to increment source index\n IF(jdo == 1) j=j+1\n\n !Check whether target index is in range\n IF(j > n0) THEN\n\n iflag=1\n message='LINEAR1_INTEG/ERROR:target node out of range'\n GOTO 9999\n\n ENDIF\n\n !Set integral value\n value(i)=sum\n\n ENDDO !Over source abscissas\n\nENDDO !Over target abscissas\n \n!-------------------------------------------------------------------------------\n!Cleanup and exit\n!-------------------------------------------------------------------------------\n9999 CONTINUE\n\nEND SUBROUTINE SPLINE1_INTEG\n\nSUBROUTINE SPLINE1_SEARCH(x,n,xl, &\n jlo)\n!-------------------------------------------------------------------------------\n!SPLINE1_SEARCH is a correlated table search routine to find the indices of the\n! array x that bound xl\n!\n!References:\n! W.A.Houlberg, P.I.Strand, D.McCune 8/2001\n!\n!Comments:\n! This is similar to the Numerical Recipes routine HUNT\n!-------------------------------------------------------------------------------\n\n!Declaration of input variables\nINTEGER, INTENT(IN) :: &\n n !number of abscissas [-]\n\nREAL(KIND=rspec), INTENT(IN) :: &\n xl, & !target value [arb]\n x(:) !monotonically increasing array of abscissas [arb]\n\n!Declaration of input/output variables\nINTEGER, INTENT(INOUT) :: &\n jlo !input starting lower index [-]\n !<1 binary search\n !=1,n-1 use value\n !>n-1 binary search\n !output starting lower index [-]\n !=0 xl < x(1) \n !=1 x(1) <= xl <= x(2)\n !=2,n-1 x(jlo) < xl <= x(jlo+1)\n !=n x(jlo) > x(n)\n\n!-------------------------------------------------------------------------------\n!Declaration of local variables\nINTEGER :: &\n inc,jhi,jmid\n\n!-------------------------------------------------------------------------------\n!Check lower end of array, first two points\n!-------------------------------------------------------------------------------\nIF(xl < x(1)) THEN\n\n !Target is below node 1\n jlo=0\n\nELSEIF(xl <= x(2)) THEN\n\n !Target is between nodes 1 and 2 inclusive\n jlo=1\n \n!-------------------------------------------------------------------------------\n!Check middle range\n!-------------------------------------------------------------------------------\nELSEIF(xl <= x(n)) THEN\n\n !Target is between nodes 2 and n\n IF(jlo < 1 .OR. &\n jlo > (n-1)) THEN\n\n !jlo from previous call is unusable\n jlo=2\n jhi=n\n\n !Bracket target value\n ELSE\n\n !Start with jlo from previous call\n inc=1\n\n IF(xl > x(jlo)) THEN\n\n !Search up\n jhi=jlo+1\n\n DO WHILE(xl > x(jhi))\n\n inc=2*inc\n jlo=jhi\n jhi=MIN(jlo+inc,n)\n\n ENDDO\n\n ELSE\n\n !Search down\n jhi=jlo\n jlo=jlo-1\n\n DO WHILE(xl <= x(jlo))\n\n inc=inc+inc\n jhi=jlo\n jlo=MAX(jlo-inc,1)\n\n ENDDO\n\n ENDIF\n\n ENDIF\n\n !Bisection\n DO WHILE(jhi-jlo > 1)\n\n jmid=(jhi+jlo)/2\n\n IF(xl > x(jmid)) THEN\n\n jlo=jmid\n\n ELSE\n\n jhi=jmid\n\n ENDIF\n\n ENDDO\n\n!-------------------------------------------------------------------------------\n!Target is above node n\n!-------------------------------------------------------------------------------\nELSE\n\n jlo=n\n\nENDIF\n\nEND SUBROUTINE SPLINE1_SEARCH\n\nEND MODULE spline1_mod\n", "meta": {"hexsha": "ea28726179197f37de3c05b4b7b28a9000be7174", "size": 28590, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Sources/Track/spline1_mod.f90", "max_stars_repo_name": "ORNL-Fusion/libstell", "max_stars_repo_head_hexsha": "92ac5c339b31e29d9d734c20eae3e7571de8f490", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-10-19T06:24:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-08T21:10:12.000Z", "max_issues_repo_path": "Sources/Track/spline1_mod.f90", "max_issues_repo_name": "ORNL-Fusion/libstell", "max_issues_repo_head_hexsha": "92ac5c339b31e29d9d734c20eae3e7571de8f490", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-09-21T14:00:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-03T00:48:39.000Z", "max_forks_repo_path": "Sources/Track/spline1_mod.f90", "max_forks_repo_name": "ORNL-Fusion/LIBSTELL", "max_forks_repo_head_hexsha": "ba938c678d776b84d7bb260ea541a9b45deb37e2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.150997151, "max_line_length": 88, "alphanum_fraction": 0.4598111228, "num_tokens": 8782, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818864, "lm_q2_score": 0.7520125848754472, "lm_q1q2_score": 0.6832920970583028}} {"text": "MODULE korc_velocity_distribution\n !! @note Module containing subroutines to initialize the velocity \n !! distribution of the simulated particles. @endnote\n USE korc_types\n USE korc_constants\n USE korc_HDF5\n USE korc_hpc\n use korc_fields\n use korc_rnd_numbers\n use korc_hammersley_generator\n\n use korc_avalanche\n use korc_experimental_pdf\n use korc_energy_pdfs\n use korc_simple_equilibrium_pdf\n\n IMPLICIT NONE\n\n PUBLIC :: initial_gyro_distribution,&\n thermal_distribution,&\n initial_energy_pitch_dist\n PRIVATE :: fth_3V,&\n random_norm,&\n gyro_distribution\n\nCONTAINS\n\n\n FUNCTION fth_3V(Vth,V)\n !! @note Function used to sample the probability density function of a \n !! thermal plasma in the 3-dimensional velocity space. @endnote\n !! This function returns \\(f_{T_e}(v) = \\exp{\\left( v^2/2v_{T_e}^2 \\right)}\\), \n !! where \\(v_{T_e} = \\sqrt{T_e/m_e}\\) is\n !! the temperature of the thermal electrons, and \\(v = |\\mathbf{v}|\\) \n !! is the speed of the sampled electron.\n REAL(rp), DIMENSION(3), INTENT(IN) \t:: V\n !! Velocity of the sampled electron \\(\\mathbf{v}\\).\n REAL(rp), INTENT(IN) \t\t\t:: Vth\n !! Thermal velocity of the background electrons \\(v_{T_e}\\).\n REAL(rp) \t\t\t\t:: fth_3V\n !! Value of \\(f_{T_e}(v)\\).\n\n fth_3V = EXP(-0.5_rp*DOT_PRODUCT(V,V)/Vth**2.0_rp)\n END FUNCTION fth_3V\n\n\n FUNCTION random_norm(mu,sigma)\n !! @note Gaussian random number generator. @endnote\n !! This function returns a deviate of a Gaussian distribution\n !! $$f_G(x;\\mu,\\sigma) = \n !! \\frac{1}{\\sigma\\sqrt{2\\pi}} \\exp{\\left( -(x-\\mu)^2/2\\sigma^2 \\right)},$$\n !!\n !! with mean \\(\\mu\\), and standard deviation \\(\\sigma\\).\n !!\n !! We use the Inverse Transform Sampling Method for sampling \\(x\\). \n !! With this method we get \\(x = \\sqrt{-2\\log{(1-y)}}\\cos(2\\pi z)\\),\n !! where \\(y\\) and \\(z\\) are uniform random numbers in the interval \\([0,1]\\).\n REAL(rp), INTENT(IN) \t:: mu\n !! Mean value \\(\\mu\\) of the Gaussian distribution.\n REAL(rp), INTENT(IN) \t:: sigma\n !! Standard deviation \\(\\sigma\\) of the Gaussian distribution.\n REAL(rp) \t\t\t\t:: random_norm\n !! Sampled number \\(x\\) from the Gaussian distribution \\(f_G(x;\\mu,\\sigma)\\).\n REAL(rp) \t\t\t\t:: rand1\n !! Uniform random number in the interval \\([0,1]\\).\n REAL(rp) \t\t\t\t:: rand2\n !! Uniform random number in the interval \\([0,1]\\).\n\n call RANDOM_NUMBER(rand1)\n call RANDOM_NUMBER(rand2)\n\n random_norm = SQRT(-2.0_rp*LOG(1.0_rp-rand1))*COS(2.0_rp*C_PI*rand2);\n END FUNCTION random_norm\n\n\n subroutine thermal_distribution(params,spp)\n !! @note Subroutine that samples a thermal distribution function\n !! of electrons for generating the initial condition of a set of\n !! simulated particles. @endnote\n !! This subroutine uses the Inverse Transform Sampling Method along\n !! with the Metropolis-Hastings algorithm to generate an\n !! initial condition of the velocity distribution that follows a\n !! 3-dimensional (in velocity space) thermal distribution.\n !! @todo Check that the gyro-distribution is initialized right in\n !! this function.\n TYPE(KORC_PARAMS), INTENT(IN) \t:: params\n !! Core KORC simulation parameters.\n TYPE(SPECIES), INTENT(INOUT) \t:: spp\n !! An instance of the derived type SPECIES containing all the\n !! parameters and simulation variables of the different species\n !! in the simulation.\n REAL(rp) \t\t\t\t:: Vmax\n !! Velocity cutoff where we stop sampling the tail of the thermal\n !! distribution.\n REAL(rp) \t\t\t\t:: vsq\n !! \n REAL(rp) \t\t\t\t:: Vth\n !! Thermal velocity of the sampled distribution \\(v_{T_e} =\n !! \\sqrt{T_e/m_e}\\).\n REAL(rp) \t\t\t\t:: sv\n !! Step to sample the velocity space using the Metropolis-Hastings\n !! algorithm.\n REAL(rp) \t\t\t\t:: ratio\n !! Ratio used to accept or reject a sampling in the Metropolis-Hastings\n !! algorithm.\n REAL(rp) \t\t\t\t:: rand_unif\n !! Uniform random deviate in the interval \\([0,1]\\).\n REAL(rp), DIMENSION(3) \t\t:: V\n !! Sampled velocity.\n REAL(rp), DIMENSION(3) \t\t:: U\n !! Sampled velocity.\n REAL(rp), DIMENSION(3) \t\t:: b = (/1.0_rp,0.0_rp,0.0_rp/)\n !! Temporary variable representing a unit vector along the \\(x\\)-axis.\n INTEGER \t\t\t\t:: ii\n !! Iterator.\n INTEGER \t\t\t\t:: ppp\n !! Number of particles per species.\n \n Vmax = 0.9_rp\n Vth = SQRT(spp%Eo*ABS(spp%q)/spp%m)\n ppp = spp%ppp\n\n V = (/0.0_rp,0.0_rp,0.0_rp/)\n sv = Vth/10.0_rp\n\n ii=2_idef\n do while (ii .LE. 1000_idef)\n U(1) = V(1) + random_norm(0.0_rp,sv)\n do while (ABS(U(1)) .GT. Vmax)\n U(1) = V(1) + random_norm(0.0_rp,sv)\n end do\n\n U(2) = V(2) + random_norm(0.0_rp,sv)\n do while (ABS(U(2)) .GT. Vmax)\n U(2) = V(2) + random_norm(0.0_rp,sv)\n end do\n\n U(3) = V(3) + random_norm(0.0_rp,sv)\n do while (ABS(U(3)) .GT. Vmax)\n U(3) = V(3) + random_norm(0.0_rp,sv)\n end do\n\n ratio = fth_3V(Vth,U)/fth_3V(Vth,V)\n\n if (ratio .GE. 1.0_rp) then\n V = U\n ii = ii + 1_idef\n else\n call RANDOM_NUMBER(rand_unif)\n if (ratio .GT. rand_unif) then\n V = U\n ii = ii + 1_idef\n end if\n end if\n end do\n\n spp%vars%V(1,1) = V(1)\n spp%vars%V(1,2) = V(2)\n spp%vars%V(1,3) = V(3)\n ii=2_idef\n do while (ii .LE. ppp)\n U(1) = spp%vars%V(ii-1,1) + random_norm(0.0_rp,sv)\n do while (ABS(U(1)) .GT. Vmax)\n U(1) = spp%vars%V(ii-1,1) + random_norm(0.0_rp,sv)\n end do\n U(2) = spp%vars%V(ii-1,2) + random_norm(0.0_rp,sv)\n do while (ABS(U(2)) .GT. Vmax)\n U(2) = spp%vars%V(ii-1,2) + random_norm(0.0_rp,sv)\n end do\n U(3) = spp%vars%V(ii-1,3) + random_norm(0.0_rp,sv)\n do while (ABS(U(3)) .GT. Vmax)\n U(3) = spp%vars%V(ii-1,3) + random_norm(0.0_rp,sv)\n end do\n\n ratio = fth_3V(Vth,U)/fth_3V(Vth,spp%vars%V(ii-1,:))\n\n if (ratio .GE. 1.0_rp) then\n spp%vars%V(ii,1) = U(1)\n spp%vars%V(ii,2) = U(2)\n spp%vars%V(ii,3) = U(3)\n ii = ii + 1_idef\n else\n call RANDOM_NUMBER(rand_unif)\n if (ratio .GT. rand_unif) then\n spp%vars%V(ii,1) = U(1)\n spp%vars%V(ii,2) = U(2)\n spp%vars%V(ii,3) = U(3)\n ii = ii + 1_idef\n end if\n end if\n end do\n\n do ii=1_idef,ppp\n vsq = spp%vars%V(ii,1)*spp%vars%V(ii,1) &\n + spp%vars%V(ii,2)*spp%vars%V(ii,2) &\n + spp%vars%V(ii,3)*spp%vars%V(ii,3)\n spp%vars%g(ii) = 1.0_rp/SQRT(1.0_rp - vsq)\n spp%vars%eta(ii) = ACOS(spp%vars%V(ii,1)/SQRT(vsq))\n end do\n\n spp%go = spp%Eo/(spp%m*C_C**2)\n spp%etao = 90.0_rp\n end subroutine thermal_distribution\n\n\n subroutine initial_energy_pitch_dist(params,spp)\n !! @note Subroutine that calls subroutines of different modules to \n !! initialize the energy and pitch-angle distribution in various ways. @endnote\n TYPE(KORC_PARAMS), INTENT(IN) \t\t\t\t:: params\n !! Core KORC simulation parameters.\n TYPE(SPECIES), DIMENSION(:), ALLOCATABLE, INTENT(INOUT) :: spp\n !! An instance of the derived type SPECIES containing all the parameters and \n !! simulation variables of the different species in the simulation.\n INTEGER \t\t\t\t\t\t\t:: ii\n !! Species iterator.\n INTEGER \t\t\t\t\t\t\t:: mpierr\n !! MPI error status.\n\n do ii=1_idef,params%num_species\n\n if (params%mpi_params%rank .EQ. 0) then\n write(output_unit_write,'(/,\"* * * * * SPECIES: \",I2,\" * * * * * * * * * * *\")') ii\n write(output_unit_write,'(\"Particles per MPI process: \",I16)') spp(ii)%ppp\n write(output_unit_write,'(\"Energy distribution is: \",A20)') &\n TRIM(spp(ii)%energy_distribution)\n write(output_unit_write,'(\"Pitch-angle distribution is: \",A20)') &\n TRIM(spp(ii)%pitch_distribution)\n write(output_unit_write,'(\"Spatial distribution is: \",A20)') &\n TRIM(spp(ii)%spatial_distribution)\n write(output_unit_write,'(\"* * * * * * * * * * * * * * * * * * * * * *\",/)')\n end if\n \n SELECT CASE (TRIM(spp(ii)%energy_distribution))\n CASE ('MONOENERGETIC')\n spp(ii)%go = (spp(ii)%Eo + spp(ii)%m*C_C**2)/(spp(ii)%m*C_C**2)\n\n spp(ii)%vars%g = spp(ii)%go ! Monoenergetic\n spp(ii)%Eo_lims = (/spp(ii)%Eo, spp(ii)%Eo /)\n \n CASE ('THERMAL')\n call thermal_distribution(params,spp(ii))\n\n spp(ii)%Eo_lims = (/spp(ii)%m*C_C**2*MINVAL(spp(ii)%vars%g) - &\n spp(ii)%m*C_C**2, &\n spp(ii)%m*C_C**2*MAXVAL(spp(ii)%vars%g) - spp(ii)%m*C_C**2 /)\n CASE ('AVALANCHE')\n call get_avalanche_distribution(params,spp(ii)%vars%g, &\n spp(ii)%vars%eta,spp(ii)%go,spp(ii)%etao)\n spp(ii)%Eo = spp(ii)%m*C_C**2*spp(ii)%go - spp(ii)%m*C_C**2\n spp(ii)%Eo_lims = (/spp(ii)%m*C_C**2*MINVAL(spp(ii)%vars%g) &\n - spp(ii)%m*C_C**2, &\n spp(ii)%m*C_C**2*MAXVAL(spp(ii)%vars%g) - spp(ii)%m*C_C**2 /)\n CASE ('HOLLMANN')\n call get_Hollmann_distribution(params,spp(ii)) \n! spp(ii)%Eo = spp(ii)%m*C_C**2*spp(ii)%go - spp(ii)%m*C_C**2\n spp(ii)%go = (spp(ii)%Eo + spp(ii)%m*C_C**2)/(spp(ii)%m*C_C**2)\n spp(ii)%Eo_lims = (/spp(ii)%m*C_C**2*MINVAL(spp(ii)%vars%g) &\n - spp(ii)%m*C_C**2, &\n spp(ii)%m*C_C**2*MAXVAL(spp(ii)%vars%g) - spp(ii)%m*C_C**2 /)\n CASE ('EXPERIMENTAL-GAMMA')\n call get_experimentalG_distribution(params,spp(ii)%vars%g, &\n spp(ii)%vars%eta, &\n spp(ii)%go,spp(ii)%etao)\n spp(ii)%Eo = spp(ii)%m*C_C**2*spp(ii)%go - spp(ii)%m*C_C**2\n spp(ii)%Eo_lims = (/spp(ii)%m*C_C**2*MINVAL(spp(ii)%vars%g) &\n - spp(ii)%m*C_C**2, &\n spp(ii)%m*C_C**2*MAXVAL(spp(ii)%vars%g) - spp(ii)%m*C_C**2 /)\n CASE ('GAMMA')\n call get_gamma_distribution(params,spp(ii)%vars%g,spp(ii)%go)\n\n spp(ii)%Eo = spp(ii)%m*C_C**2*spp(ii)%go - spp(ii)%m*C_C**2\n spp(ii)%Eo_lims = (/spp(ii)%m*C_C**2*MINVAL(spp(ii)%vars%g) &\n - spp(ii)%m*C_C**2, &\n spp(ii)%m*C_C**2*MAXVAL(spp(ii)%vars%g) - spp(ii)%m*C_C**2 /)\n CASE ('UNIFORM')\n spp(ii)%Eo = spp(ii)%Eo_lims(1)\n spp(ii)%go = (spp(ii)%Eo + spp(ii)%m*C_C**2)/(spp(ii)%m*C_C**2)\n\n call generate_2D_hammersley_sequence(params%mpi_params%rank, &\n params%mpi_params%nmpi,spp(ii)%vars%g,spp(ii)%vars%eta)\n\n spp(ii)%vars%g = (spp(ii)%Eo_lims(2) - & \n spp(ii)%Eo_lims(1))*spp(ii)%vars%g/(spp(ii)%m*C_C**2) + &\n (spp(ii)%Eo_lims(1) + spp(ii)%m*C_C**2)/(spp(ii)%m*C_C**2)\n CASE ('AVALANCHE-4D')\n spp(ii)%go = (spp(ii)%Eo + spp(ii)%m*C_C**2)/(spp(ii)%m*C_C**2)\n spp(ii)%vars%g = spp(ii)%go\n ! Monoenergy from input file until sampled in Avalanche_4D\n CASE ('HOLLMANN-3D')\n spp(ii)%go = (spp(ii)%Eo + spp(ii)%m*C_C**2)/(spp(ii)%m*C_C**2)\n spp(ii)%vars%g = spp(ii)%go\n ! Monoenergy from input file until sampled in Hollmann_3D\n CASE ('HOLLMANN-3D-PSI')\n spp(ii)%go = (spp(ii)%Eo + spp(ii)%m*C_C**2)/(spp(ii)%m*C_C**2)\n spp(ii)%vars%g = spp(ii)%go\n ! Monoenergy from input file until sampled in Hollmann_3D\n CASE DEFAULT\n ! Something to be done\n END SELECT\n\n call MPI_BARRIER(MPI_COMM_WORLD,mpierr)\n\n SELECT CASE (TRIM(spp(ii)%pitch_distribution))\n CASE ('MONOPITCH')\n spp(ii)%vars%eta = spp(ii)%etao ! Mono-pitch-angle\n\n if(spp(ii)%spatial_distribution.ne.'SPONG-3D') then\n spp(ii)%etao_lims = (/spp(ii)%etao , spp(ii)%etao/)\n end if\n \n CASE ('THERMAL')\n spp(ii)%etao_lims = (/MINVAL(spp(ii)%vars%eta), &\n MAXVAL(spp(ii)%vars%eta)/)\n CASE ('AVALANCHE')\n spp(ii)%etao_lims = (/MINVAL(spp(ii)%vars%eta), &\n MAXVAL(spp(ii)%vars%eta)/)\n CASE ('HOLLMANN')\n! spp(ii)%vars%eta = spp(ii)%etao\n! spp(ii)%etao_lims = (/MINVAL(spp(ii)%vars%eta), &\n! MAXVAL(spp(ii)%vars%eta)/)\n CASE ('EXPERIMENTAL-GAMMA')\n spp(ii)%etao_lims = (/MINVAL(spp(ii)%vars%eta), &\n MAXVAL(spp(ii)%vars%eta)/)\n CASE ('UNIFORM')\n spp(ii)%etao = spp(ii)%etao_lims(1)\n\n spp(ii)%vars%eta = (spp(ii)%etao_lims(2) - &\n spp(ii)%etao_lims(1))*spp(ii)%vars%eta + spp(ii)%etao_lims(1)\n CASE ('SIMPLE-EQUILIBRIUM')\n call get_equilibrium_distribution(params,spp(ii)%vars%eta, &\n spp(ii)%go,spp(ii)%etao)\n\n spp(ii)%etao_lims = (/MINVAL(spp(ii)%vars%eta),&\n MAXVAL(spp(ii)%vars%eta)/)\n CASE ('AVALANCHE-4D')\n spp(ii)%vars%eta = spp(ii)%etao\n !Monopitch from input file until sampled in Avalanche_4D\n CASE ('HOLLMANN-3D')\n spp(ii)%vars%eta = spp(ii)%etao\n !Monopitch from input file until sampled in Hollmann_3D\n CASE ('HOLLMANN-3D-PSI')\n spp(ii)%vars%eta = spp(ii)%etao\n !Monopitch from input file until sampled in Hollmann_3D\n CASE ('SPONG-3D')\n spp(ii)%vars%eta = spp(ii)%etao\n !Monopitch from input file until sampled in Spong_3D\n CASE DEFAULT\n ! Something to be done\n END SELECT\n\n\n\n call MPI_BARRIER(MPI_COMM_WORLD,mpierr)\n end do\n end subroutine initial_energy_pitch_dist\n\n\n subroutine gyro_distribution(params,F,spp)\n !! @Note Subroutine that initializes the gyro-angle distribution \n !! of the particles. @endnote\n !! When evolving the particles in the 6-D phase space, in addition to \n !! the position (3 degrees of freedom), energy (one degree of freedom), \n !! pitch angle (one degree of freedom), we need to define the gyro-angle \n !! of the particle (one degree of freedom), which is given by the pitch \n !! angle and the direction of the local magnetic field. By default, this \n !! subroutine generates a uniform gyro-angle distribution.\n !! @note Notice that all the simulation variables are normalized\n !! here. @endnote\n TYPE(KORC_PARAMS), INTENT(IN) \t:: params\n !! Core KORC simulation parameters.\n TYPE(FIELDS), INTENT(IN) \t\t:: F\n !! An instance of the KORC derived type FIELDS. This structure \n !! has the information of the magnetic field.\n TYPE(SPECIES), INTENT(INOUT) \t\t:: spp\n !! An instance of the derived type SPECIES containing all the\n !! parameters and \n !! simulation variables of the different species in the simulation.\n REAL(rp), DIMENSION(:,:), ALLOCATABLE\t:: b1\n !! Basis vector pointing along the local magnetic field, that is,\n !! along \\(\\mathbf{b} = \\mathbf{B}/B\\).\n REAL(rp), DIMENSION(:,:), ALLOCATABLE\t:: b2\n !! Basis vector perpendicular to b1\n REAL(rp), DIMENSION(:,:), ALLOCATABLE\t:: b3\n !! Basis vector perpendicular to b1 and b2.\n REAL(rp), DIMENSION(:), ALLOCATABLE \t:: Vo\n !! Initial particle speed.\n REAL(rp), DIMENSION(:), ALLOCATABLE \t:: V1\n !! Velocity component along b1.\n REAL(rp), DIMENSION(:), ALLOCATABLE \t:: V2\n !! Velocity component along b2.\n REAL(rp), DIMENSION(:), ALLOCATABLE \t:: V3\n !! Velocity component along b3.\n REAL(rp), DIMENSION(:), ALLOCATABLE \t:: theta\n !! Uniform random number in the interval \\([0,2\\pi]\\) \n !! representing the gyro-angle.\n INTEGER \t\t\t\t:: jj\n !! Particle iterator.\n\n ALLOCATE(Vo(spp%ppp))\n ALLOCATE(V1(spp%ppp))\n ALLOCATE(V2(spp%ppp))\n ALLOCATE(V3(spp%ppp))\n ALLOCATE(b1(spp%ppp,3))\n ALLOCATE(b2(spp%ppp,3))\n ALLOCATE(b3(spp%ppp,3))\n\n ALLOCATE( theta(spp%ppp) )\n\n ! * * * * INITIALIZE VELOCITY * * * *\n\n call init_random_seed()\n call RANDOM_NUMBER(theta)\n theta = 2.0_rp*C_PI*theta\n \n if (spp%spatial_distribution.eq.'TRACER') theta=2.0*C_PI\n\n\n Vo = SQRT( 1.0_rp - 1.0_rp/(spp%vars%g(:)**2) )\n V1 = Vo*COS(C_PI*spp%vars%eta/180.0_rp)\n V2 = Vo*SIN(C_PI*spp%vars%eta/180.0_rp)*COS(theta)\n V3 = Vo*SIN(C_PI*spp%vars%eta/180.0_rp)*SIN(theta)\n \n call unitVectors(params,spp%vars%X,F,b1,b2,b3,spp%vars%flagCon, &\n spp%vars%cart,spp%vars%hint)\n !! Call to subroutine [[unitVectors]] in [[korc_fields]].\n\n !write(output_unit_write,*) 'X',spp%vars%X\n !write(output_unit_write,*) 'b-hat',b1\n\n \n do jj=1_idef,spp%ppp\n if ( spp%vars%flagCon(jj) .EQ. 1_idef ) then \n spp%vars%V(jj,1) = V1(jj)*b1(jj,1) + V2(jj)*b2(jj,1) + V3(jj)*b3(jj,1)\n spp%vars%V(jj,2) = V1(jj)*b1(jj,2) + V2(jj)*b2(jj,2) + V3(jj)*b3(jj,2)\n spp%vars%V(jj,3) = V1(jj)*b1(jj,3) + V2(jj)*b2(jj,3) + V3(jj)*b3(jj,3)\n end if\n end do\n \n! write(output_unit_write,'(\"Vx: \",E17.10)') spp%vars%V(:,1)\n! write(output_unit_write,'(\"Vy: \",E17.10)') spp%vars%V(:,2)\n! write(output_unit_write,'(\"Vz: \",E17.10)') spp%vars%V(:,3)\n \n DEALLOCATE(theta)\n DEALLOCATE(Vo)\n DEALLOCATE(V1)\n DEALLOCATE(V2)\n DEALLOCATE(V3)\n DEALLOCATE(b1)\n DEALLOCATE(b2)\n DEALLOCATE(b3)\n end subroutine gyro_distribution\n\n\n subroutine initial_gyro_distribution(params,F,spp)\n !! @note Subroutine that works as an interface for initializing various \n !! gyro-angle distributions for the different simulated particle\n !! species. @endnote\n !! @todo At this moment this subroutine only calls the subroutine\n !! to generate \n !! a uniform gyro-angle distribution. This will be modified later. @endtodo\n TYPE(KORC_PARAMS), INTENT(IN) \t\t\t\t:: params\n !! Core KORC simulation parameters.\n TYPE(FIELDS), INTENT(IN) \t\t\t\t\t:: F\n !! An instance of the KORC derived type FIELDS. This structure has \n !! the information of the magnetic field.\n TYPE(SPECIES), DIMENSION(:), ALLOCATABLE, INTENT(INOUT) :: spp\n !! An instance of the derived type SPECIES containing all the parameters \n !! and simulation variables of the different species in the simulation.\n INTEGER \t\t\t\t\t\t\t:: ss\n !! Species iterator.\n\n do ss=1_idef,params%num_species\n SELECT CASE (TRIM(spp(ss)%energy_distribution))\n CASE ('THERMAL')\n !Nothing, all was done in initialize_particles through\n !thermal_distribution\n CASE DEFAULT \n call gyro_distribution(params,F,spp(ss))\n END SELECT\n end do\n end subroutine initial_gyro_distribution\n\nEND MODULE korc_velocity_distribution\n", "meta": {"hexsha": "60e76bdf94d6cbb71ad2dcf434bae46f7aff1928", "size": 18599, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "docs/src/korc_velocity_distribution.f90", "max_stars_repo_name": "ORNL-Fusion/KORC", "max_stars_repo_head_hexsha": "975fc01cdac1e922fe537e739a6b67f01c6a6431", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-10-30T13:01:12.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-13T19:20:48.000Z", "max_issues_repo_path": "docs/src/korc_velocity_distribution.f90", "max_issues_repo_name": "ORNL-Fusion/KORC", "max_issues_repo_head_hexsha": "975fc01cdac1e922fe537e739a6b67f01c6a6431", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-05-21T17:20:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-23T16:58:40.000Z", "max_forks_repo_path": "docs/src/korc_velocity_distribution.f90", "max_forks_repo_name": "ORNL-Fusion/KORC", "max_forks_repo_head_hexsha": "975fc01cdac1e922fe537e739a6b67f01c6a6431", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-08-03T04:14:17.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-03T04:14:17.000Z", "avg_line_length": 38.4276859504, "max_line_length": 93, "alphanum_fraction": 0.5872896392, "num_tokens": 5965, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837705, "lm_q2_score": 0.7520125848754472, "lm_q1q2_score": 0.6832920896147952}} {"text": " REAL FUNCTION SSI (X)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nC>> 1998-10-29 SSI Krogh Moved external statement up for mangle.\nC>> 1995-11-03 SSI Krogh Removed blanks in numbers for C conversion.\nC>> 1994-11-11 SSI Krogh Declared all vars.\nc>> 1994-10-20 SSI Krogh Changes to use M77CON\nc>> 1989-03-14 SSI Original W. V. Snyder at JPL\nC\nC COMPUTE THE SINE INTEGRAL OF X =\nC INTEGRAL FROM 0 TO X OF (SIN(T)/T DT).\nC\nC FOR ABS(X)<16, USE A CHEBYSHEV SERIES WITH ARGUMENT 2*Z*Z-1 WHERE\nC Z=X/16 TO EVALUATE SI(X)/Z, THEN MULTIPLY THE RESULT BY Z. THIS\nC AVOIDS STORING ZERO COEFFICIENTS FOR EVEN ORDERS, AND PRESERVES\nC ACCURACY FOR SMALL Z.\nC\nC FOR 16.LE.ABS(X).LE.100, USE CHEBYCHEV SERIES WITH ARGUMENT\nC 2*Z*Z-1, WHERE Z=16/X ARE USED TO COMPUTE F(X)/X AND G(X)/(X*X).\nC THEN SI(X)=0.5*PI*SIGN(X)-F(X)/X*COS(X)-G(X)/(X*X)*SIN(X).\nC\nC WHEN X.GT.100, USE ASYMPTOTIC APPROXIMATIONS FOR F(X)/X AND\nC G(X)/(X*X) AND COMPUTE SI(X) AS ABOVE.\nC\nC THIS ALGORITHM YIELDS AT MOST 15 DIGITS OF PRECISION.\nC\nC--S replaces \"?\": ?SI, ?CPVAL\nC\n INTEGER N\n REAL X\n EXTERNAL SCPVAL\n REAL PI2,Z,ZW,FZ,GZ,SCPVAL\n REAL FT,GT\n REAL S(23),F(13),G(13)\n DATA PI2/1.57079632679489662E0/\n DATA S/\n * + 0.5E0, + 0.5E0,\n 1 + 4.052926477680623E0, - 4.063980844911986E0,\n 2 + 2.778756381742663E0, - 1.926565091150656E0,\n 3 + 1.389308771171888E0, - 0.968322236987086E0,\n 4 + 0.530148847916522E0, - 0.211263780976555E0,\n 5 + 0.062033679432003E0, - 0.013867445589417E0,\n 6 + 0.002436221404749E0, - 0.000345469155569E0,\n 7 + 0.000040420271419E0, - 0.000003972908746E0,\n 8 + 0.000000332988589E0, - 0.000000024100076E0,\n 9 + 0.000000001522370E0, - 0.000000000084710E0,\n A + 0.000000000004185E0, - 0.000000000000185E0,\n B + 0.000000000000007E0/\n DATA F/\n * + 0.5E0, + 0.5E0,\n 1 + 0.062263729028927E0, - 0.000233756041393E0,\n 2 + 0.000002453755677E0, - 0.000000058670317E0,\n 3 + 0.000000002356196E0, - 0.000000000136096E0,\n 4 + 0.000000000010308E0, - 0.000000000000964E0,\n 5 + 0.000000000000107E0, - 0.000000000000014E0,\n 6 + 0.000000000000002E0/\n DATA G/\n * + 0.5E0, + 0.5E0,\n 1 + 0.003862856096703E0, - 0.000042644182622E0,\n 2 + 0.000000724995950E0, - 0.000000023468225E0,\n 3 + 0.000000001169202E0, - 0.000000000079604E0,\n 4 + 0.000000000006875E0, - 0.000000000000717E0,\n 5 + 0.000000000000087E0, - 0.000000000000012E0,\n 6 + 0.000000000000002E0/\nC\n IF (ABS(X).LT.16.0) THEN\n Z = X/16.0\n ZW = Z*Z\n Z = Z*SCPVAL(S,20,ZW)\n ELSE\n IF (ABS(X).LE.100.0) THEN\nC 16.LE.ABS(X).LE.100\n Z = 16.0/X\n ZW = Z*Z\n FZ = Z*SCPVAL(F,10,ZW)\n GZ = ZW*SCPVAL(G,10,ZW)\n ELSE\nC ABS(X).GT.100\n FZ = 1.0/X\n FT = FZ\n GZ = FZ/X\n GT = GZ\n Z = GZ\n DO 25 N = 2, 16, 2\n FT = -REAL(N*(N-1))*Z*FT\n GT = -REAL(N*(N+1))*Z*GT\n FZ = FZ + FT\n GZ = GZ + GT\n25 CONTINUE\n END IF\n Z = SIGN(PI2,X) - FZ*COS(X) - GZ*SIN(X)\n END IF\nC\n SSI = Z\n RETURN\n END\n", "meta": {"hexsha": "24f3c41332c2bd1f6593e35ff18d1d65e44491e5", "size": 3480, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/ssi.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/ssi.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/ssi.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 35.5102040816, "max_line_length": 71, "alphanum_fraction": 0.5732758621, "num_tokens": 1447, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178944582997, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6832920813757938}} {"text": " SUBROUTINE iau_HD2AE ( HA, DEC, PHI, AZ, EL )\n*+\n* - - - - - - - - - -\n* i a u _ H D 2 A E\n* - - - - - - - - - -\n*\n* Equatorial to horizon coordinates: transform hour angle and\n* declination to azimuth and altitude.\n*\n* This routine is part of the International Astronomical Union's\n* SOFA (Standards of Fundamental Astronomy) software collection.\n*\n* Status: support routine.\n*\n* Given:\n* HA d hour angle (local)\n* DEC d declination\n* PHI d site latitude\n*\n* Returned:\n* AZ d azimuth\n* EL d altitude (informally, elevation)\n*\n* Notes:\n*\n* 1) All the arguments are angles in radians.\n*\n* 2) Azimuth is returned in the range 0-2pi; north is zero, and east\n* is +pi/2. Altitude is returned in the range +/- pi/2.\n*\n* 3) The latitude PHI is pi/2 minus the angle between the Earth's\n* rotation axis and the adopted zenith. In many applications it\n* will be sufficient to use the published geodetic latitude of the\n* site. In very precise (sub-arcsecond) applications, PHI can be\n* corrected for polar motion.\n*\n* 4) The returned azimuth AZ is with respect to the rotational north\n* pole, as opposed to the ITRS pole, and for sub-arcsecond accuracy\n* will need to be adjusted for polar motion if it is to be with\n* respect to north on a map of the Earth's surface.\n*\n* 5) Should the user wish to work with respect to the astronomical\n* zenith rather than the geodetic zenith, PHI will need to be\n* adjusted for deflection of the vertical (often tens of\n* arcseconds), and the zero point of HA will also be affected.\n*\n* 6) The transformation is the same as Vh = Rz(pi)*Ry(pi/2-phi)*Ve,\n* where Vh and Ve are lefthanded unit vectors in the (az,el) and\n* (ha,dec) systems respectively and Ry and Rz are rotations about\n* first the y-axis and then the z-axis. (n.b. Rz(pi) simply\n* reverses the signs of the x and y components.) For efficiency,\n* the algorithm is written out rather than calling other utility\n* functions. For applications that require even greater\n* efficiency, additional savings are possible if constant terms\n* such as functions of latitude are computed once and for all.\n*\n* 7) Again for efficiency, no range checking of arguments is carried\n* out.\n*\n* Last revision: 2018 January 2\n*\n* SOFA release 2020-07-21\n*\n* Copyright (C) 2020 IAU SOFA Board. See notes at end.\n*\n*-----------------------------------------------------------------------\n\n IMPLICIT NONE\n\n DOUBLE PRECISION HA, DEC, PHI, AZ, EL\n\n DOUBLE PRECISION D2PI\n PARAMETER ( D2PI = 6.283185307179586476925287D0 )\n\n DOUBLE PRECISION SH, CH, SD, CD, SP, CP, X, Y, Z, R, A\n\n\n* Useful trig functions.\n SH = SIN(HA)\n CH = COS(HA)\n SD = SIN(DEC)\n CD = COS(DEC)\n SP = SIN(PHI)\n CP = COS(PHI)\n\n* Az,Alt unit vector.\n X = - CH*CD*SP + SD*CP\n Y = - SH*CD\n Z = CH*CD*CP + SD*SP\n\n* To spherical.\n R = SQRT(X*X + Y*Y)\n IF ( R.EQ.0D0 ) THEN\n A = 0D0\n ELSE\n A = ATAN2(Y,X)\n END IF\n IF ( A.LT.0D0 ) A = A+D2PI\n AZ = A\n EL = ATAN2(Z,R)\n\n* Finished.\n\n*+----------------------------------------------------------------------\n*\n* Copyright (C) 2020\n* Standards Of Fundamental Astronomy Board\n* of the International Astronomical Union.\n*\n* =====================\n* SOFA Software License\n* =====================\n*\n* NOTICE TO USER:\n*\n* BY USING THIS SOFTWARE YOU ACCEPT THE FOLLOWING SIX TERMS AND\n* CONDITIONS WHICH APPLY TO ITS USE.\n*\n* 1. The Software is owned by the IAU SOFA Board (\"SOFA\").\n*\n* 2. Permission is granted to anyone to use the SOFA software for any\n* purpose, including commercial applications, free of charge and\n* without payment of royalties, subject to the conditions and\n* restrictions listed below.\n*\n* 3. You (the user) may copy and distribute SOFA source code to others,\n* and use and adapt its code and algorithms in your own software,\n* on a world-wide, royalty-free basis. That portion of your\n* distribution that does not consist of intact and unchanged copies\n* of SOFA source code files is a \"derived work\" that must comply\n* with the following requirements:\n*\n* a) Your work shall be marked or carry a statement that it\n* (i) uses routines and computations derived by you from\n* software provided by SOFA under license to you; and\n* (ii) does not itself constitute software provided by and/or\n* endorsed by SOFA.\n*\n* b) The source code of your derived work must contain descriptions\n* of how the derived work is based upon, contains and/or differs\n* from the original SOFA software.\n*\n* c) The names of all routines in your derived work shall not\n* include the prefix \"iau\" or \"sofa\" or trivial modifications\n* thereof such as changes of case.\n*\n* d) The origin of the SOFA components of your derived work must\n* not be misrepresented; you must not claim that you wrote the\n* original software, nor file a patent application for SOFA\n* software or algorithms embedded in the SOFA software.\n*\n* e) These requirements must be reproduced intact in any source\n* distribution and shall apply to anyone to whom you have\n* granted a further right to modify the source code of your\n* derived work.\n*\n* Note that, as originally distributed, the SOFA software is\n* intended to be a definitive implementation of the IAU standards,\n* and consequently third-party modifications are discouraged. All\n* variations, no matter how minor, must be explicitly marked as\n* such, as explained above.\n*\n* 4. You shall not cause the SOFA software to be brought into\n* disrepute, either by misuse, or use for inappropriate tasks, or\n* by inappropriate modification.\n*\n* 5. The SOFA software is provided \"as is\" and SOFA makes no warranty\n* as to its use or performance. SOFA does not and cannot warrant\n* the performance or results which the user may obtain by using the\n* SOFA software. SOFA makes no warranties, express or implied, as\n* to non-infringement of third party rights, merchantability, or\n* fitness for any particular purpose. In no event will SOFA be\n* liable to the user for any consequential, incidental, or special\n* damages, including any lost profits or lost savings, even if a\n* SOFA representative has been advised of such damages, or for any\n* claim by any third party.\n*\n* 6. The provision of any version of the SOFA software under the terms\n* and conditions specified herein does not imply that future\n* versions will also be made available under the same terms and\n* conditions.\n*\n* In any published work or commercial product which uses the SOFA\n* software directly, acknowledgement (see www.iausofa.org) is\n* appreciated.\n*\n* Correspondence concerning SOFA software should be addressed as\n* follows:\n*\n* By email: sofa@ukho.gov.uk\n* By post: IAU SOFA Center\n* HM Nautical Almanac Office\n* UK Hydrographic Office\n* Admiralty Way, Taunton\n* Somerset, TA1 2DN\n* United Kingdom\n*\n*-----------------------------------------------------------------------\n\n END\n", "meta": {"hexsha": "f3dc45c7519e6d8c6d30b5f57220391172108854", "size": 7434, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "source/sofa_c/hd2ae.for", "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/sofa_c/hd2ae.for", "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/sofa_c/hd2ae.for", "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": 36.9850746269, "max_line_length": 72, "alphanum_fraction": 0.6425881087, "num_tokens": 1923, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9086178944582997, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6832920763258544}} {"text": "! ======================================================================\n! PROGRAM FTPSD\n! ----------------------------------------------------------------------\n PROGRAM FTPSD\n IMPLICIT NONE\n\n! Parameter Declarations:\n! -----------------------\n REAL, PARAMETER :: PI = 3.1415926535897932384626433832795028841971E0\n\n! Input Variable and Array Declarations:\n! --------------------------------------\n INTEGER :: NUMBER_OF_GRID_POINTS\n INTEGER :: NUMBER_OF_TIME_STEPS_BEFORE_WRITE\n INTEGER :: START_FILE\n INTEGER :: END_FILE\n\n REAL :: RADIUS\n REAL :: GAMMA_FACTOR\n REAL :: CARRIER_FREQUENCY\n\n! Internal Variable and Array Declarations:\n! -----------------------------------------\n CHARACTER(80) :: BUFFER\n\n INTEGER :: CURRENT_GRID_POINT\n INTEGER :: CURRENT_FILE\n INTEGER :: LENGTH\n INTEGER :: INFO\n\n REAL :: ANGULAR_GRID_SPACING_SIZE\n REAL :: TIME_STEP_SIZE\n\n COMPLEX :: FOURIER_TRANSFORM\n\n REAL, ALLOCATABLE, DIMENSION(:) :: ARCLENGTH\n REAL, ALLOCATABLE, DIMENSION(:) :: DENSITY\n\n COMPLEX, ALLOCATABLE, DIMENSION(:) :: WAVEFUNCTION\n\n! Input Variable Assignment Read from Command-line Arguments:\n! -----------------------------------------------------------\n CALL GET_COMMAND_ARGUMENT(1,BUFFER,LENGTH,INFO)\n READ(BUFFER,*) NUMBER_OF_GRID_POINTS\n\n CALL GET_COMMAND_ARGUMENT(2,BUFFER,LENGTH,INFO)\n READ(BUFFER,*) START_FILE\n\n CALL GET_COMMAND_ARGUMENT(3,BUFFER,LENGTH,INFO)\n READ(BUFFER,*) END_FILE\n\n CALL GET_COMMAND_ARGUMENT(4,BUFFER,LENGTH,INFO)\n READ(BUFFER,*) RADIUS\n\n CALL GET_COMMAND_ARGUMENT(5,BUFFER,LENGTH,INFO)\n READ(BUFFER,*) TIME_STEP_SIZE\n\n CALL GET_COMMAND_ARGUMENT(6,BUFFER,LENGTH,INFO)\n READ(BUFFER,*) CARRIER_FREQUENCY\n\n! Internal Variable Assignment:\n! -----------------------------\n ANGULAR_GRID_SPACING_SIZE = 2.0E0*PI/FLOAT(NUMBER_OF_GRID_POINTS)\n\n! Allocate Arrays:\n! ----------------\n ALLOCATE(WAVEFUNCTION(NUMBER_OF_GRID_POINTS))\n ALLOCATE(ARCLENGTH(NUMBER_OF_GRID_POINTS))\n ALLOCATE(DENSITY(NUMBER_OF_GRID_POINTS))\n\n! Main Program:\n! -------------\n DO CURRENT_FILE = START_FILE, END_FILE\n OPEN(UNIT=CURRENT_FILE,ACTION='READ',FORM='FORMATTED',STATUS='OLD')\n DO CURRENT_GRID_POINT = 1, NUMBER_OF_GRID_POINTS\n READ(CURRENT_FILE,*) ARCLENGTH(CURRENT_GRID_POINT), DENSITY(CURRENT_GRID_POINT)\n ENDDO\n CLOSE(UNIT=CURRENT_FILE,STATUS='SAVE')\n FOURIER_TRANSFORM = CMPLX(0.0E0,0.0E0)\n DO CURRENT_GRID_POINT = 1, NUMBER_OF_GRID_POINTS\n FOURIER_TRANSFORM = FOURIER_TRANSFORM+CMPLX(DENSITY(CURRENT_GRID_POINT)*ANGULAR_GRID_SPACING_SIZE,0.0E0)*EXP(CMPLX(0.0E0,CARRIER_FREQUENCY*FLOAT(CURRENT_GRID_POINT-1)*ANGULAR_GRID_SPACING_SIZE))\n ENDDO\n WRITE(500,*) FLOAT(CURRENT_FILE-START_FILE)*TIME_STEP_SIZE, ATAN2(AIMAG(FOURIER_TRANSFORM),REAL(FOURIER_TRANSFORM))\n ENDDO\n\n! Deallocate Arrays:\n! ------------------\n DEALLOCATE(WAVEFUNCTION)\n DEALLOCATE(ARCLENGTH)\n DEALLOCATE(DENSITY)\n\n STOP\n ENDPROGRAM FTPSD\n! ======================================================================\n", "meta": {"hexsha": "4d535bc2272de7bbf7a3a1b5196669d61b1dc282", "size": 3245, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/ftpsd2D.f", "max_stars_repo_name": "mkandes/gpecn1Dtdpbc", "max_stars_repo_head_hexsha": "51646d6804fcd6abfbac154c58d9e5739d795c6b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source/ftpsd2D.f", "max_issues_repo_name": "mkandes/gpecn1Dtdpbc", "max_issues_repo_head_hexsha": "51646d6804fcd6abfbac154c58d9e5739d795c6b", "max_issues_repo_licenses": ["MIT"], "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/ftpsd2D.f", "max_forks_repo_name": "mkandes/gpecn1Dtdpbc", "max_forks_repo_head_hexsha": "51646d6804fcd6abfbac154c58d9e5739d795c6b", "max_forks_repo_licenses": ["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.1578947368, "max_line_length": 206, "alphanum_fraction": 0.5913713405, "num_tokens": 765, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837706, "lm_q2_score": 0.752012562644147, "lm_q1q2_score": 0.6832920694150381}} {"text": "! $ brew install gcc\n! $ gfortran -O3 -o envelopes_f08 envelopes.f08\n! $ ./envelopes_f08\n\nfunction single_trial(cutoff) result(value)\n ! Runs a single trial where an envelope is chosen. If the chosen envelope has\n ! a value < cutoff, the function will switch envelopes, otherwise it will keep\n ! the envelope it has chosen. Returns the value of the envelope it ultimately \n ! selects.\n implicit none\n double precision :: cutoff, higher_value, lower_value, value\n logical :: picked_lower\n \n lower_value = rand() * 100.0d+0\n higher_value = 2 * lower_value\n picked_lower = (rand() < 0.5)\n if ((picked_lower .and. lower_value >= cutoff) .or. &\n (.not. picked_lower .and. higher_value < cutoff)) then\n value = lower_value\n else\n value = higher_value\n end if\nend function single_trial\n\n\nfunction multi_trial(cutoff) result(expected_value)\n ! Runs many trials at a given cutoff to approximate the expected value.\n implicit none\n integer :: cutoff, i, num_trials\n double precision :: cutoff64, expected_value, single_trial, total\n\n num_trials = 10000\n cutoff64 = dble(cutoff)\n total = 0.0d+0\n do i = 1, num_trials\n total = total + single_trial(cutoff64)\n end do\n expected_value = total / dble(num_trials)\nend function multi_trial\n\n\nsubroutine print_result(cutoff, expected_value)\n ! Formats the results nicely and outputs them.\n implicit none\n integer :: cutoff\n double precision :: expected_value\n character(len=100) :: fmt\n\n if (cutoff < 10) then\n fmt = \"(A, I1, A, F9.6)\"\n else if (cutoff < 100) then\n fmt = \"(A, I2, A, F9.6)\"\n else\n fmt = \"(A, I3, A, F9.6)\"\n end if\n write (*, fmt) \"cutoff=\", cutoff, \", expected_value=\", expected_value\nend subroutine print_result\n\n\nprogram envelopes\n ! Approximates the expected value for each integral cutoff value.\n implicit none\n integer :: cutoff\n double precision :: multi_trial\n\n call random_seed()\n do cutoff = 0, 200\n call print_result(cutoff, multi_trial(cutoff))\n end do\nend program envelopes", "meta": {"hexsha": "9fdd7ab1a74612748d889fa8833a2a33fc3ed1d2", "size": 2039, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "envelopes.f08", "max_stars_repo_name": "dfings/two-envelopes-problem", "max_stars_repo_head_hexsha": "00ffb43e2e88bceda995ddb909f1b183e198add4", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2015-03-30T22:33:26.000Z", "max_stars_repo_stars_event_max_datetime": "2018-03-11T09:42:31.000Z", "max_issues_repo_path": "envelopes.f08", "max_issues_repo_name": "dfings/two-envelopes-problem", "max_issues_repo_head_hexsha": "00ffb43e2e88bceda995ddb909f1b183e198add4", "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": "envelopes.f08", "max_forks_repo_name": "dfings/two-envelopes-problem", "max_forks_repo_head_hexsha": "00ffb43e2e88bceda995ddb909f1b183e198add4", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-04-21T17:52:18.000Z", "max_forks_repo_forks_event_max_datetime": "2020-04-21T17:52:18.000Z", "avg_line_length": 29.1285714286, "max_line_length": 80, "alphanum_fraction": 0.6964198136, "num_tokens": 558, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382200964035, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.6832910958507052}} {"text": " subroutine nscore(nd,vr,tmin,tmax,iwt,wt,tmp,lout,vrg,ierror)\n!-----------------------------------------------------------------------\n\n! Transform Univariate Data to Normal Scores\n! ******************************************\n\n! This subroutibe takes \"nd\" data \"vr(i),i=1,...,nd\" possibly weighted\n! by \"wt(i),i=,...,nd\" and returns the normal scores transform N(0,1)\n! as \"vrg(i),i=1,...,nd\". The extra storage array \"tmp\" is required\n! so that the data can be returned in the same order (just in case\n! there are associated arrays like the coordinate location).\n\n\n\n! INPUT VARIABLES:\n\n! nd Number of data (no missing values)\n! vr(nd) Data values to be transformed\n! tmin,tmax data trimming limits\n! iwt =0, equal weighted; =1, then apply weight\n! wt(nd) Weight for each data (don't have to sum to 1.0)\n! tmp(nd) Temporary storage space for sorting\n! lout if > 0 then transformation table will be written\n\n\n\n! OUTPUT VARIABLES:\n\n! vrg(nd) normal scores\n! ierror error flag (0=error free,1=problem)\n\n\n\n! EXTERNAL REFERENCES:\n\n! gauinv Calculates the inverse of a Gaussian cdf\n! sortem sorts a number of arrays according to a key array\n\n\n\n!-----------------------------------------------------------------------\n parameter(EPSLON=1.0e-20)\n real :: vr(nd),wt(nd),vrg(nd),tmp(nd)\n real*8 :: pd\n\n! Sort the data in ascending order and calculate total weight:\n\n ierror = 0\n twt = 0.0\n do i=1,nd\n tmp(i) = real(i)\n if(vr(i) >= tmin .AND. vr(i) < tmax) then\n if(iwt == 0) then\n twt = twt + 1.\n else\n twt = twt + wt(i)\n end if\n end if\n end do\n if(nd < 1 .OR. twt < EPSLON) then\n ierror = 1\n return\n end if\n call sortem(1,nd,vr,2,wt,tmp,d,e,f,g,h)\n\n! Compute the cumulative probabilities:\n\n oldcp = 0.0\n cp = 0.0\n do i=1,nd\n cp = cp + wt(i) / twt\n wt(i) = (cp + oldcp)/ 2.0\n oldcp = cp\n call gauinv(dble(wt(i)),vrg(i),ierr)\n if(lout > 0) write(lout,'(f12.5,1x,f12.5)') vr(i),vrg(i)\n end do\n\n! Get the arrays back in original order:\n\n call sortem(1,nd,tmp,3,wt,vr,vrg,e,f,g,h)\n\n! Finished:\n\n return\n end subroutine nscore\n", "meta": {"hexsha": "6f27b31fe2b6c6aac24510d99ebf51f88745490e", "size": 2385, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gslib/gslib/nscore.f90", "max_stars_repo_name": "opengeostat/gslib_new_code", "max_stars_repo_head_hexsha": "ecd00cfcb9654ef8d0fe28c649405fb71595e42e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "gslib/gslib/nscore.f90", "max_issues_repo_name": "opengeostat/gslib_new_code", "max_issues_repo_head_hexsha": "ecd00cfcb9654ef8d0fe28c649405fb71595e42e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gslib/gslib/nscore.f90", "max_forks_repo_name": "opengeostat/gslib_new_code", "max_forks_repo_head_hexsha": "ecd00cfcb9654ef8d0fe28c649405fb71595e42e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-01-03T12:19:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-03T12:19:42.000Z", "avg_line_length": 27.7325581395, "max_line_length": 72, "alphanum_fraction": 0.5157232704, "num_tokens": 690, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412809, "lm_q2_score": 0.793105941403651, "lm_q1q2_score": 0.6832910782851951}} {"text": "!-------------------------------------------------------------------------------\n! Copyright (c) 2016 The University of Tokyo\n! This software is released under the MIT License, see LICENSE.txt\n!-------------------------------------------------------------------------------\n!> \\brief This module contains functions for interpolation in 2 node\n!! line element (Langrange interpolation)\nmodule shape_line2n\n integer, parameter, private :: kreal = kind(0.0d0)\n\ncontains\n subroutine ShapeFunc_line2n(lcoord,func)\n real(kind=kreal), intent(in) :: lcoord(1)\n real(kind=kreal) :: func(2)\n func(1) = 0.5d0*(1.d0-lcoord(1))\n func(2) = 0.5d0*(1.d0+lcoord(1))\n end subroutine\n\n subroutine ShapeDeriv_line2n(func)\n real(kind=kreal) :: func(2,1)\n func(1,1) = -0.5d0\n func(2,1) = 0.5d0\n end subroutine\n\n subroutine Shape2ndDeriv_line2n(func)\n real(kind=kreal) :: func(2,1,1)\n func(:,:,:) = 0.d0\n end subroutine\n\nend module\n", "meta": {"hexsha": "94b1259e8fb116b316e95708382fe3954016f9d1", "size": 951, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fistr1/src/lib/element/line2n.f90", "max_stars_repo_name": "tkoyama010/FrontISTR", "max_stars_repo_head_hexsha": "2ce1f0425b87df76261c86ddb93bb4b588f72718", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fistr1/src/lib/element/line2n.f90", "max_issues_repo_name": "tkoyama010/FrontISTR", "max_issues_repo_head_hexsha": "2ce1f0425b87df76261c86ddb93bb4b588f72718", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fistr1/src/lib/element/line2n.f90", "max_forks_repo_name": "tkoyama010/FrontISTR", "max_forks_repo_head_hexsha": "2ce1f0425b87df76261c86ddb93bb4b588f72718", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.7, "max_line_length": 80, "alphanum_fraction": 0.563617245, "num_tokens": 272, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381952105442, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.6832910740070219}} {"text": "\\ .( LOADING BUBBLE SORT BENCHMARK...) CR\r\n\r\n\\ A CLASSICAL BENCHMARK OF AN O(N**2) ALGORITHM; BUBBLE SORT\r\n\\\r\n\\ PART OF THE PROGRAMS GATHERED BY JOHN HENNESSY FOR THE MIPS\r\n\\ RISC PROJECT AT STANFORD. TRANSLATED TO FORTH BY MARTY FRAEMAN\r\n\\ JOHNS HOPKINS UNIVERSITY/APPLIED PHYSICS LABORATORY.\r\n\r\n\\ MM FORTH2C DOESN'T HAVE IT !\r\n\r\n4 CONSTANT CELL\r\n\r\n: MYBOUNDS OVER + SWAP ;\r\n\r\nVARIABLE SEED ( -- ADDR)\r\n\r\n: INITIATE-SEED ( -- ) 74755 SEED ! ;\r\n: RANDOM ( -- N ) SEED @ 1309 * 13849 + 65535 AND DUP SEED ! ;\r\n\r\n800 CONSTANT ELEMENTS ( -- INT)\r\n\r\nCREATE LIST ELEMENTS CELLS ALLOT\r\n\r\n: INITIATE-LIST ( -- )\r\n LIST ELEMENTS CELLS + LIST DO RANDOM I ! CELL +LOOP\r\n;\r\n\r\n: DUMP-LIST ( -- )\r\n LIST ELEMENTS CELLS + LIST DO I @ . CELL +LOOP CR\r\n;\r\n\r\n: VERIFY-LIST ( -- )\r\n LIST ELEMENTS 1- CELLS MYBOUNDS DO\r\n I 2@ > ABORT\" BUBBLE-SORT: NOT SORTED\"\r\n CELL +LOOP\r\n;\r\n\r\n: BUBBLE ( -- )\r\n\\ .\" BUBBLING...\" CR\r\n ELEMENTS 1 DO\r\n LIST ELEMENTS I - CELLS MYBOUNDS DO\r\n I 2@ > IF I 2@ SWAP I 2! THEN\r\n CELL +LOOP \r\n LOOP\r\n;\r\n\r\n: BUBBLE-SORT ( -- )\r\n INITIATE-SEED \r\n INITIATE-LIST \r\n BUBBLE \r\n VERIFY-LIST \r\n;\r\n\r\n: BUBBLE-WITH-FLAG ( -- )\r\n 1 ELEMENTS 1 DO\r\n -1 LIST ELEMENTS I - CELLS MYBOUNDS DO\r\n I 2@ > IF I 2@ SWAP I 2! DROP 0 THEN\r\n CELL +LOOP \r\n IF LEAVE THEN\r\n LOOP\r\n;\r\n \r\n: BUBBLE-SORT-WITH-FLAG ( -- )\r\n INITIATE-SEED\r\n INITIATE-LIST\r\n BUBBLE-WITH-FLAG\r\n VERIFY-LIST\r\n;\r\n\r\n: MAIN ( -- )\r\n BUBBLE-SORT\r\n BUBBLE-SORT-WITH-FLAG DROP\r\n;\r\n", "meta": {"hexsha": "05d8c2ea495afa152d39b10c62cf4f89f783e999", "size": 1501, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "bubble.f", "max_stars_repo_name": "ForthWin/ForthWinUsersGroup", "max_stars_repo_head_hexsha": "e5f9c73db0f2f202cd91d6effb9595371dd92140", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2019-06-04T15:24:11.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-11T16:31:17.000Z", "max_issues_repo_path": "bubble.f", "max_issues_repo_name": "ForthWin/ForthWinUsersGroup", "max_issues_repo_head_hexsha": "e5f9c73db0f2f202cd91d6effb9595371dd92140", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "bubble.f", "max_forks_repo_name": "ForthWin/ForthWinUsersGroup", "max_forks_repo_head_hexsha": "e5f9c73db0f2f202cd91d6effb9595371dd92140", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-14T19:58:07.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-14T19:58:07.000Z", "avg_line_length": 20.2837837838, "max_line_length": 65, "alphanum_fraction": 0.5929380413, "num_tokens": 537, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933447152498, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.6832372879869296}} {"text": "!> @ingroup quick_sort_recursive_dec\n!> \n!> @brief \n!> Run a recursive three way quick sort on a vector of double precision values. \n!>\n!> @details \n!> Run a decending on a vector of double precision values to sort them in the specified order.\n!>\n!> @param vec\n!> The vector double precision values to be sorted.\n!>\n!> @author Arin R. Bratt\n!> @date 11/07/2014\npure subroutine quick_sort_recursive_dec_dble(vec)\n ! Arguments\n double precision, intent(inout) :: vec(:)\n\n ! Variables\n integer :: low\n integer :: high\n integer :: low_eq\n integer :: high_eq\n double precision :: pivot\n double precision :: temp\n\n ! Go to interchange sort if list is small\n if (size(vec,1) <= max_interchange_sort_size) then\n call interchange_sort_dec_dble(vec)\n else\n ! Initilize values\n low = 1\n high = size(vec,1)\n low_eq = 1\n high_eq = size(vec,1)\n\n ! Build pivot\n pivot = (vec(low) + vec(high)) / 2\n if ( vec(low) < vec(high)) then\n call swap(vec(low),vec(high))\n end if\n \n ! Main loop with three way partition\n do \n ! Find pivot points\n do\n low = low + 1\n if (.not. pivot < vec(low)) exit\n end do\n do \n high = high - 1\n if (.not. vec(high) < pivot .or. high == 1) exit\n end do\n\n ! Exit if they are on the wrong side of the pivot\n if (low >= high) exit\n\n ! Run main quick sort swap\n call swap(vec(low),vec(high))\n\n ! Check for if values are equal to pivot, if so swap\n if (.not. vec(high) < pivot) then\n call swap(vec(high),vec(high_eq))\n high_eq = high_eq - 1\n end if\n\n if (.not. pivot < vec(low)) then\n call swap(vec(low),vec(low_eq))\n low_eq = low_eq + 1\n end if\n end do\n high = low - 1\n\n ! Move equals to the middle\n do while(1 < low_eq)\n low_eq = low_eq - 1\n call swap(vec(low_eq),vec(high))\n high = high - 1\n end do\n \n do while(high_eq < size(vec,1))\n high_eq = high_eq + 1\n call swap(vec(high_eq),vec(low))\n low = low + 1\n end do\n \n ! Recursive calls \n if (size(vec,1) - low > high - 1) then\n if (high > 1) call quick_sort_recursive_dec_dble(vec(:high))\n if (low < size(vec,1)) call quick_sort_recursive_dec_dble(vec(low:))\n else\n if (low < size(vec,1)) call quick_sort_recursive_dec_dble(vec(low:))\n if (high > 1) call quick_sort_recursive_dec_dble(vec(:high))\n end if\n end if\nend subroutine quick_sort_recursive_dec_dble\n\n", "meta": {"hexsha": "388294c223c9772f3cfe4d92aeb34682f8247318", "size": 2586, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/quick_sort_recursive_dec_dble.f90", "max_stars_repo_name": "arinrb/bsort", "max_stars_repo_head_hexsha": "17cc0e2cbe52af808bae860d53dd4e4d691f4674", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-11-08T18:36:23.000Z", "max_stars_repo_stars_event_max_datetime": "2015-11-08T18:36:23.000Z", "max_issues_repo_path": "src/quick_sort_recursive_dec_dble.f90", "max_issues_repo_name": "arinrb/bsort", "max_issues_repo_head_hexsha": "17cc0e2cbe52af808bae860d53dd4e4d691f4674", "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/quick_sort_recursive_dec_dble.f90", "max_forks_repo_name": "arinrb/bsort", "max_forks_repo_head_hexsha": "17cc0e2cbe52af808bae860d53dd4e4d691f4674", "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.6597938144, "max_line_length": 94, "alphanum_fraction": 0.5846867749, "num_tokens": 728, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245953120233, "lm_q2_score": 0.8198933293122506, "lm_q1q2_score": 0.6832372768481586}} {"text": "subroutine init_phi(phi, lo, hi, ng, dx, prob_lo, prob_hi) bind(C, name=\"init_phi\")\n\n implicit none\n\n integer :: lo(3), hi(3), ng\n double precision :: phi(lo(1)-ng:hi(1)+ng,lo(2)-ng:hi(2)+ng,lo(3)-ng:hi(3)+ng)\n double precision :: dx(3) \n double precision :: prob_lo(3) \n double precision :: prob_hi(3) \n\n integer :: i,j,k\n double precision :: x,y,z,r2\n\n do k = lo(3), hi(3)\n z = prob_lo(3) + (dble(k)+0.5d0) * dx(3)\n do j = lo(2), hi(2)\n y = prob_lo(2) + (dble(j)+0.5d0) * dx(2)\n do i = lo(1), hi(1)\n x = prob_lo(1) + (dble(i)+0.5d0) * dx(1)\n\n r2 = ((x-0.25d0)**2 + (y-0.25d0)**2 + (z-0.25d0)**2) / 0.01d0\n phi(i,j,k) = 1.d0 + exp(-r2)\n\n end do\n end do\n end do\n\nend subroutine init_phi\n", "meta": {"hexsha": "7d54fd573e84208ddb04f3f5c6a86fd4cccff079", "size": 778, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorials/HeatEquation_EX1_C/init_phi_3d.f90", "max_stars_repo_name": "BoxLib-Codes/BoxLib", "max_stars_repo_head_hexsha": "330b14363148ebb0b85d1ffd59d07874ddc79e6d", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 79, "max_stars_repo_stars_event_min_datetime": "2015-08-03T18:29:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-15T11:42:40.000Z", "max_issues_repo_path": "Tutorials/HeatEquation_EX1_C/init_phi_3d.f90", "max_issues_repo_name": "BoxLib-Codes/BoxLib", "max_issues_repo_head_hexsha": "330b14363148ebb0b85d1ffd59d07874ddc79e6d", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": 22, "max_issues_repo_issues_event_min_datetime": "2016-06-15T20:46:49.000Z", "max_issues_repo_issues_event_max_datetime": "2018-09-10T21:33:10.000Z", "max_forks_repo_path": "Tutorials/HeatEquation_EX2_C/init_phi_3d.f90", "max_forks_repo_name": "BoxLib-Codes/BoxLib", "max_forks_repo_head_hexsha": "330b14363148ebb0b85d1ffd59d07874ddc79e6d", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": 48, "max_forks_repo_forks_event_min_datetime": "2015-08-05T02:19:33.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-18T12:33:14.000Z", "avg_line_length": 26.8275862069, "max_line_length": 83, "alphanum_fraction": 0.5102827763, "num_tokens": 324, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381605, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.683209927709757}} {"text": "\n\nmodule fiducial\n use settings, only: mcp ! real precision\n use constants, only: const_pi ! pi\n use numrec\n implicit none\n !values of dm and H used to take into account the fiducial cosmology. \n !Assumes that the fiducial cosmology corresponds to a simple flat LCDM model \n !as the one used for all BOSS measurements.\n real(mcp) :: save_om_m !used to pass Omega_m to the integrand of D_M(z)\n contains\n\n subroutine compute_scaling(om_m_fid, h0_fid, z, d_m, hub)!Ariel: added this subroutine\n use camb\n implicit none\n real(kind=mcp), intent(in) :: om_m_fid, h0_fid, z\n real(kind=mcp), intent(out) :: d_m, hub\n hub = e(om_m_fid, z)!*h0_fid !H(z)/100.\n d_m = dm(om_m_fid, z)!/h0_fid !D_M(z)\n end subroutine compute_scaling\n \n function e(om_m, z) !E(z)=H(z)/H_0\n implicit none\n real(kind=mcp) :: om_m, z\n real(kind=mcp) :: e2, e, zplus, a\n zplus = 1._mcp + z\n a = 1._mcp / zplus\n e2 = om_m/a**3 + (1._mcp- om_m)\n e = sqrt(e2)\n end function e\n\n function einv(z)\n implicit none\n real(kind=mcp) :: einv, z\n einv = 1._mcp/e(save_om_m, z)\n end function einv\n \n function dm(om_m, z) !for a flat cosmology dm = r(z)\n implicit none\n real(kind=mcp) :: dm, om_m, z, ans\n save_om_m = om_m\n call qromb(einv, 0._mcp, z, ans)\n dm = ans*2997.92458_mcp\n end function dm\n\nend module fiducial\n\n\n", "meta": {"hexsha": "983dce62345a3742a521588ff5f526249eaea73f", "size": 1447, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "CosmoMC_BOSS/source/fiducial.f90", "max_stars_repo_name": "KiDS-WL/kcap_boss_module", "max_stars_repo_head_hexsha": "0e894a7e58b257f50f9348f35309b3171688f004", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "CosmoMC_BOSS/source/fiducial.f90", "max_issues_repo_name": "KiDS-WL/kcap_boss_module", "max_issues_repo_head_hexsha": "0e894a7e58b257f50f9348f35309b3171688f004", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "CosmoMC_BOSS/source/fiducial.f90", "max_forks_repo_name": "KiDS-WL/kcap_boss_module", "max_forks_repo_head_hexsha": "0e894a7e58b257f50f9348f35309b3171688f004", "max_forks_repo_licenses": ["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.94, "max_line_length": 90, "alphanum_fraction": 0.6123013131, "num_tokens": 494, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391579526934, "lm_q2_score": 0.7401743677704878, "lm_q1q2_score": 0.6832099251650383}} {"text": "Module Trait_functions\n!This module provides several functions calculating phytoplankton physiological rates as a function of environmental conditions (e.g., temperature) and traits\nimplicit none\n\nprivate\n\npublic :: TEMPBOL, temp_Topt, palatability, PHY_C2Vol, PHY_ESD2C\n\nreal, parameter :: pi= 3.1415926535\n\nCONTAINS\n\n!Function converting phytoplankton ESD (micron) to Carbon (unit: pmol C per cell) with the parameters obtained from Maranon et al. (2013)\nreal function PHY_ESD2C(ESD) result(y)\nimplicit none\nreal, intent(in) :: ESD !Phytoplankton ESD (micron)\n\nreal, parameter :: a = -0.69\nreal, parameter :: b = 0.88\n\nreal :: Vol = 0d0\n\n!Calculate volume from ESD\nVol = pi/6d0 * ESD**3\n\n!the parameters of a and b are derived from pg C cell-1 to volume; so we need to\n!convert the carbon unit from pmol C cell-1 to pg C cell-1\n\n!Calculate carbon (pmol C per cell) from volume\ny = 10.d0**a * Vol**b / 12.d0\n\nreturn\nend function PHY_ESD2C\n\n!Function converting phytoplankton carbon to volume (unit: micron^3) with the parameters obtained from Maranon et al. (2013)\npure real function PHY_C2Vol(p_C) result(y)\nimplicit none\nreal, intent(in) :: p_C !Phytoplankton carbon (pmol C/cell)\n\nreal, parameter :: a = -0.69\nreal, parameter :: b = 0.88\n\n!the parameters of a and b are derived from pg C cell-1 to volume; so we need to\n!convert the carbon unit from pmol C cell-1 to pg C cell-1\n\ny = (12d0 * p_C/10.d0**a)**(1d0/b)\nreturn\nend function \n\n!Function calculating the prey palatability based on Ward et al. L&O 2012 (Eq. A21) and Banas Ecol. Mod. (2011) Table 2\nreal function palatability(Vpred, Vprey) result(y)\nimplicit none\n\n!Predator Volume\nreal, intent(in) :: Vpred\n\n!Prey Volume\nreal, intent(in) :: Vprey\n\n!The actual predator:prey volume ratio\nreal :: R_real = 0d0\n\n! Standard deviation of log zooplankton feeding preference\nreal, parameter :: SDpref_Z = 0.5\n\n!Optimal prey Volume of the predator\nreal :: Vprey_opt = 1d3 \n\nreal :: Xpred, Xprey !ESD of predator and prey\nreal :: Xprey_opt = 0. !Optimal prey ESD\n\n!Optimal predator:prey volume ratio\nreal :: R_opt = 1d3 \n\nreal :: cff = 0d0\n\n!First calculate prey and predator ESD (micron) from volume\nXpred = (6d0*Vpred/pi)**(.33333333333333)\nXprey = (6d0*Vprey/pi)**(.33333333333333)\n\n!Then calculate optimal prey ESD (micron)\nXprey_opt = 0.65 * Xpred**0.56\n\n!Convert prey ESD to volume\nVprey_opt = pi/6d0 * Xprey_opt**3\n\nR_opt = Vpred/Vprey_opt\nR_real = Vpred/Vprey\n\ncff = log(R_real/R_opt)\ncff = cff**2/(2.d0 * SDpref_Z**2)\n\n!To avoid underflow\nif (cff > 5d2) then\n y = 0d0\nelse\n y = exp(-cff)\nendif\nreturn\nend function palatability\n\npure real function TEMPBOL(Ea,tC)\nimplicit none\n!DESCRIPTION:\n!The temperature dependence of plankton rates are fomulated according to the Arrhenuis equation. \n! tC: in situ temperature\n! Tr: reference temperature\n!\n!INPUT PARAMETERS:\nreal, intent (in) :: Ea, tC\n\n! boltzman constant constant [ eV /K ]\nreal, parameter :: kb = 8.62d-5, Tr = 15D0\n\nTEMPBOL = exp(-(Ea/kb)*(1D0/(273.15 + tC)-1D0/(273.15 + Tr)))\nreturn \nend function TEMPBOL\n\nREAL function temp_Topt(tC, mumax0, Topt_) result(y)\n!Function of a rate depending on Temperature and optimal temperature (Topt_) modified from Chen Ecol. Mod. (2022)\nIMPLICIT NONE\nreal, intent(in) :: mumax0 !Maximal rate normalized to an optimal temperature of 15 \u00baC\nreal, intent(in) :: tC !Environmental temperature in \u00baC\nreal, intent(in) :: Topt_ !Optimal temperature in \u00baC\n\nreal, parameter :: Ea0 = 0.98 \nreal, parameter :: Ed0 = 2.3\nreal, parameter :: Ei = 0.22 \nreal, parameter :: beta =-0.2 !Exponent for Ea0\nreal, parameter :: phi = 0.27 !Exponent for Ed\n!real, parameter :: mumax0 = 0.59 !Normalized growth rate for mumax (d-1)\n\nreal :: Ed, Ea, mumax\n\nmumax = alloscale(Topt_, mumax0, Ei) \nEa = alloscale(Topt_, Ea0, beta) \nEd = alloscale(Topt_, Ed0, phi) \ny = JOHNSON(tC, mumax, Ea, Ed, Topt_)\n\nEND function temp_Topt\n\nREAL FUNCTION JOHNSON(tC, mumax, Ea, Ed, Topt_) RESULT(y)\n!Temperature function following Dell et al. PNAS (2011) and Chen & Laws L&O (2017)\nIMPLICIT NONE\n!Both tC and Topt_ are in \u00baC\nreal, intent(in) :: tC, mumax, Ea, Ed, Topt_\nreal, parameter :: kb = 8.62D-5\nreal, parameter :: T0 = 273.15D0\nreal, parameter :: Tref = 15D0\nreal :: Eh, x, theta, b\n\nif (Ed .le. 0d0) stop \"Ed must be greater than zero!\"\nEh = Ed+Ea\nx = TK(TC)\ntheta = TK(Topt_)\nb = x - theta\ny = mumax*(Ea/Ed + 1.d0) * exp(Ea*b)/(1.D0+Ea/ED*exp(Eh*b)) \nreturn\nEND FUNCTION JOHNSON\n\nPURE REAL FUNCTION TK(TC)\nIMPLICIT NONE\n!DESCRIPTION:\n!The temperature dependence of plankton rates are fomulated according to the Arrhenuis equation. \n! tC: in situ temperature\n! Tr: reference temperature\n!\n!INPUT PARAMETERS:\nREAL, INTENT (IN) :: TC\n! boltzman constant constant [ eV /K ]\nREAL, PARAMETER :: kb = 8.62d-5, Tr = 15.0\n\nTK = -(1./kb)*(1./(273.15 + tC) - 1./(273.15 + Tr))\nreturn \nEND FUNCTION TK\n\nPURE REAL FUNCTION alloscale(Topt_, mu0p, alpha)\nIMPLICIT NONE\nreal, intent(in) :: Topt_ !Topt in \u00baC\nreal, intent(in) :: mu0p !Normalized growth rate\nreal, intent(in) :: alpha !Exponent of thermal traits normalized to z\nalloscale = mu0p * exp(TK(Topt_) * alpha) \nEND FUNCTION alloscale\n\nEND MODULE\n", "meta": {"hexsha": "12f5acd2da791015886ea6cf0131b161e124dd1d", "size": 5249, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/Trait_functions.f90", "max_stars_repo_name": "BingzhangChen/IBM", "max_stars_repo_head_hexsha": "16a443e159a088f2aecb0aefc1d1a4865462d62c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/Trait_functions.f90", "max_issues_repo_name": "BingzhangChen/IBM", "max_issues_repo_head_hexsha": "16a443e159a088f2aecb0aefc1d1a4865462d62c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Trait_functions.f90", "max_forks_repo_name": "BingzhangChen/IBM", "max_forks_repo_head_hexsha": "16a443e159a088f2aecb0aefc1d1a4865462d62c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.2204301075, "max_line_length": 158, "alphanum_fraction": 0.7007048962, "num_tokens": 1790, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391600697869, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.683209921441684}} {"text": "c\nc\nc double precision function myatan(y,x)\nc double precision function dmyatandx(y,x)\nc double precision function dmyatandy(y,x)\nc\nc double precision function polyarea(x,n)\nc subroutine polyprop(xs,x,n)\nc\nc integer function round(x)\nc integer function trunc(x)\nc\nc integer function Hs(x)\nc\nc double precision function LP(i,m,s)\nc double precision function dLP(i,m,s)\nc double precision function ddLP(i,m,s)\nc\nc double precision function dot(a,b,n)\nc\nc logical function NaN(x)\nc\nc double precision function value(ad,al,au,jpl,jpu,i,j)\nc\nc subroutine eliminate_column(A,l,m,n)\nc subroutine eliminate_row(A,l,m,n)\nc\nc\nc\nc\nc\nc\nc\nc\nc\nc=======================================================\nc (A.9) myatan(y,x) takes into account the signs of x and y \nc-------------------------------------------------------\n double precision function myatan(y,x)\n implicit none\n double precision x, y, r0, pi, phi\n r0 = 0.d0\n pi = acos(-1.d0)\n phi = atan(y/x)\n if (x.lt.r0) then\n myatan = pi + phi\n elseif ((x.gt.r0).and.(y.lt.r0)) then\n myatan = 2.d0 * pi + phi\n else\n myatan = phi\n endif\n return\n end\nc\nc=======================================================\nc (A.10) dmyatandx(y,x) takes into account the signs of x and y \nc-------------------------------------------------------\n double precision function dmyatandx(y,x)\n implicit none\n double precision x, y\n dmyatandx = - y / (x*x + y*y)\n return\n end\nc\nc=======================================================\nc (A.11) dmyatandy(y,x) takes into account the signs of x and y \nc-------------------------------------------------------\n double precision function dmyatandy(y,x)\n implicit none\n double precision x, y\n dmyatandy = x / (x*x + y*y)\n return\n end\nc\nc=======================================================\nc polyarea(x,n)\nc-------------------------------------------------------\n double precision function polyarea(x,n)\n implicit none\n integer n, i\n double precision x(2,*), A, x0(2)\n x0(1) = 0.d0\n x0(2) = 0.d0\n A = 0.d0\n do i=1, n-1\n A = A + ((x(1,i )-x0(1))*(x(2,i+1)-x0(2)) \n * - (x(1,i+1)-x0(1))*(x(2,i )-x0(2))) * 0.5d0\n enddo\n polyarea = A + ((x(1,n)-x0(1))*(x(2,1)-x0(2)) \n * - (x(1,1)-x0(1))*(x(2,n)-x0(2))) * 0.5d0\n return\n end\nc\nc=======================================================\nc polyprop(prop,x,n)\nc-------------------------------------------------------\n subroutine polyprop(prop,x,n)\n implicit none\n integer n, i\n double precision prop(*), x(2,*), x0(2), Dx(2), Ax(2), DA, A\n x0(1) = 0.d0\n x0(2) = 0.d0\n A = 0.d0\n Ax(1) = 0.d0\n Ax(2) = 0.d0\n do i=1, n-1\n Dx(1) = ((x(1,i) + x(1,i+1)) - 2.d0*x0(1)) / 3.d0\n Dx(2) = ((x(2,i) + x(2,i+1)) - 2.d0*x0(2)) / 3.d0\n DA = ((x(1,i )-x0(1))*(x(2,i+1)-x0(2)) \n * - (x(1,i+1)-x0(1))*(x(2,i )-x0(2))) * 0.5d0\n A = A + DA\n Ax(1) = Ax(1) + DA * Dx(1)\n Ax(2) = Ax(2) + DA * Dx(2)\n enddo\n Dx(1) = ((x(1,n) + x(1,1)) - 2.d0*x0(1)) / 3.d0\n Dx(2) = ((x(2,n) + x(2,1)) - 2.d0*x0(2)) / 3.d0\n DA = ((x(1,n)-x0(1))*(x(2,1)-x0(2)) \n * - (x(1,1)-x0(1))*(x(2,n)-x0(2))) * 0.5d0\n A = A + DA\n Ax(1) = Ax(1) + DA * Dx(1)\n Ax(2) = Ax(2) + DA * Dx(2)\n prop(1) = Ax(1) / A ! centre of gravity, x-coordinate \n prop(2) = Ax(2) / A ! centre of gravity, y-coordinate \n prop(3) = A ! area\n\n Ax(1) = 0.d0\n Ax(2) = 0.d0\n do i=1, n-1\n Dx(1) = ((x(1,i) + x(1,i+1)) - 2.d0*prop(1)) / 3.d0\n Dx(2) = ((x(2,i) + x(2,i+1)) - 2.d0*prop(2)) / 3.d0\n DA = ((x(1,i )-prop(1))*(x(2,i+1)-prop(2)) \n * - (x(1,i+1)-prop(1))*(x(2,i )-prop(2))) * 0.5d0\n Ax(1) = Ax(1) + DA * Dx(1) * Dx(1)\n Ax(2) = Ax(2) + DA * Dx(2) * Dx(2)\n enddo\n Dx(1) = ((x(1,n) + x(1,1)) - 2.d0*prop(1)) / 3.d0\n Dx(2) = ((x(2,n) + x(2,1)) - 2.d0*prop(2)) / 3.d0\n DA = ((x(1,n)-prop(1))*(x(2,1)-prop(2)) \n * - (x(1,1)-prop(1))*(x(2,n)-prop(2))) * 0.5d0\n A = A + DA\n Ax(1) = Ax(1) + DA * Dx(1) * Dx(1)\n Ax(2) = Ax(2) + DA * Dx(2) * Dx(2)\n prop(4) = Ax(1) ! I_x \n prop(5) = Ax(2) ! I_y \n prop(6) = Ax(1) + Ax(2) ! I_p\n return\n end\nc\nc=======================================================\nc (A.12) round(x) \nc-------------------------------------------------------\n integer function round(x)\n implicit none\n double precision x\n integer h\n h = int(2*abs(x))\n h = h + mod(h,2)\n round = sign(.5d0,x) * h \n return\n end\nc=======================================================\nc (A.12) trunc(x) \nc-------------------------------------------------------\n integer function trunc(x)\n implicit none\n double precision x\n integer h\n h = int(x)\n if (x.lt.h) then\n trunc = h - 1\n else\n trunc = h\n endif \n return\n end\ncc=======================================================\nc (A.13) Hs(x) \nc-------------------------------------------------------\n integer function Hs(x)\n implicit none\n double precision x\n if (x.gt.1.d-15) then\n Hs = 1\n elseif (x.lt.-1.d-15) then\n Hs = -1\n else\n Hs = 0\n endif \n return\n end\nc\nc=======================================================\nc (A.15) LP(i,m,s) \nc\nc evaluate Lagrangian Polynomial i\nc \nc 0 <= x <= 1, \nc m equally distributed interpolation points\nc\nc example: m = 3 -> x1=0.0, x2=0.5, x3=1.0\nc-------------------------------------------------------\n double precision function LP(i,m,s)\n implicit none\n integer i, m, j\n double precision ds, s, si, sj, N \n ds = 1.d0 / real(m-1)\n N = 1.d0\n si = (i-1) * ds\n do j=1, m\n sj = (j-1) * ds\n if (j.ne.i) N = N * (s-sj) / (si-sj)\n enddo\n LP = N\n return\n end\nc\nc=======================================================\nc (A.16) dLP(i,m,s) \nc\nc evaluate first derivative of Lagrangian Polynomial i\nc \nc 0 <= x <= 1, \nc m equally distributed interpolation points\nc\nc example: m = 3 -> x1=0.0, x2=0.5, x3=1.0\nc-------------------------------------------------------\n double precision function dLP(i,m,s)\n implicit none\n integer i, m, j, k\n double precision ds, s, si, sj, sk, dN, h\n save\n ds = 1.d0 / real(m-1)\n dN = 0.d0\n si = (i-1) * ds\n do k=1, m\n if (k.ne.i) then\n sk = (k-1) * ds\n h = 1.d0 / (si-sk)\n do j=1, m\n sj = (j-1) * ds\n if (j.ne.i.and.j.ne.k) h = h * (s-sj) / (si-sj) \n enddo\n dN = dN + h\n endif\n enddo\n dLP = dN\n return\n end\nc\nc=======================================================\nc (A.17) ddLP(i,m,s) \nc\nc evaluate second derivative of Lagrangian Polynomial i\nc \nc 0 <= x <= 1, \nc m equally distributed interpolation points\nc\nc example: m = 3 -> x1=0.0, x2=0.5, x3=1.0\nc-------------------------------------------------------\n double precision function ddLP(i,m,s)\n implicit none\n integer i, m, j, k, l\n double precision ds, s, si, sj, sk, sl, ddN, h\n save\n ds = 1.d0 / real(m-1)\n ddN = 0.d0\n si = (i-1) * ds\n do l=1, m\n if (l.ne.i) then\n sl = (l-1) * ds\n do k=1, m\n if (k.ne.i.and.k.ne.l) then\n sk = (k-1) * ds\n h = 1.d0 / ((si-sk) * (si-sl))\n do j=1, m\n sj = (j-1) * ds\n if (j.ne.i.and.j.ne.k.and.j.ne.l) h = h * (s-sj)/(si-sj)\n enddo\n ddN = ddN + h\n endif\n enddo\n endif\n enddo\n ddLP = ddN\n return\n end\nc\nc=======================================================\nc (A.18) dot(a,b,n) \nc\nc dot product of two vectors of dimension n \nc\nc-------------------------------------------------------\n double precision function dot(a,b,n)\n implicit none\n integer n, i\n double precision a(*), b(*), d\n save\n d = 0.d0\n do i=1, n\n d = d + a(i) * b(i)\n enddo\n dot = d\n return\n end\nc\nc=======================================================\nc (A.18) nan(x) \nc\nc check whether x is a well defined number or not\nc\nc-------------------------------------------------------\n logical function NaN(x)\n implicit none\n double precision x\n character strg*3\n write(strg,'(f3.1)') x\nc write(*,*) strg\n NaN = .false.\n if (strg(1:1).eq.'N'.or.strg(1:1).eq.'n'.or.strg(1:1).eq.'?'.or.\n * strg(1:1).eq.' ') \n * NaN = .true.\n return\n end\nc\nc========================================================================\nc\nc (D.19) return value of coefficient A[i,j] in profile matrix\nc\nc------------------------------------------------------------------------\n double precision function value(ad,al,au,jpl,jpu,i,j)\n implicit none\n integer i, j, jpl(*), jpu(*), n\n double precision ad(*), al(*), au(*)\n if (i.gt.j) then\n if (jpl(i)-jpl(i-1).ge.i-j) then\n value = al(jpl(i)-i+j+1)\n else\n value = 0.d0\n endif\n elseif (i.eq.j) then\n value = ad(i)\n else\n if (jpu(j)-jpu(j-1).ge.j-i) then\n value = au(jpu(j)-j+i+1)\n else\n value = 0.d0\n endif\n endif\n return\n end\nc\nc=======================================================\nc (D.20) Eliminiere die l-te Spalte aus einer Matrix\nc Matrixdimension: m x n -> m x n-1\nc-------------------------------------------------------\n subroutine eliminate_column(A,l,m,n)\n implicit none\n integer i, l, m, n\n double precision A(m*n)\n do i=(l-1)*m+1, l*m\n A(i) = A(i+m)\n enddo\n return\n end\nc\nc=======================================================\nc (D.12) Eliminiere die l-te Zeile aus einer Matrix\nc Matrixdimension: m x n -> m-1 x n\nc-------------------------------------------------------\n subroutine eliminate_row(A,l,m,n)\n implicit none\n integer i, j, l, m, n\n double precision A(m*n)\n do i=1, n\n do j=1, m-1\n A((i-1)*(m-1)+l + j-1) = A((i-1)*(m-1)+l + j-1+i)\n enddo\n enddo\n return\n end\nc\nc=======================================================\n\n", "meta": {"hexsha": "66d174c5df8a37e053c83258e8555e616f2a21b9", "size": 10775, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/support/math_other.for", "max_stars_repo_name": "chennachaos/stabfem", "max_stars_repo_head_hexsha": "b3d1f44c45e354dc930203bda22efc800c377c6f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-12-30T16:45:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-29T23:27:29.000Z", "max_issues_repo_path": "src/support/math_other.for", "max_issues_repo_name": "chennachaos/stabfem", "max_issues_repo_head_hexsha": "b3d1f44c45e354dc930203bda22efc800c377c6f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2019-11-22T12:57:55.000Z", "max_issues_repo_issues_event_max_datetime": "2020-11-04T22:01:42.000Z", "max_forks_repo_path": "src/support/math_other.for", "max_forks_repo_name": "chennachaos/mpap", "max_forks_repo_head_hexsha": "99d02bc9075b72b899a167d1bbc2bf73584b85bc", "max_forks_repo_licenses": ["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.987012987, "max_line_length": 73, "alphanum_fraction": 0.3858932715, "num_tokens": 3536, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391621868804, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6832099177183295}} {"text": "C\nC file hstcrt.f\nC\n SUBROUTINE HSTCRT (A,B,M,MBDCND,BDA,BDB,C,D,N,NBDCND,BDC,BDD,\n 1 ELMBDA,F,IDIMF,PERTRB,IERROR,W)\nC\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC * *\nC * copyright (c) 1999 by UCAR *\nC * *\nC * UNIVERSITY CORPORATION for ATMOSPHERIC RESEARCH *\nC * *\nC * all rights reserved *\nC * *\nC * FISHPACK version 4.1 *\nC * *\nC * A PACKAGE OF FORTRAN SUBPROGRAMS FOR THE SOLUTION OF *\nC * *\nC * SEPARABLE ELLIPTIC PARTIAL DIFFERENTIAL EQUATIONS *\nC * *\nC * BY *\nC * *\nC * JOHN ADAMS, PAUL SWARZTRAUBER AND ROLAND SWEET *\nC * *\nC * OF *\nC * *\nC * THE NATIONAL CENTER FOR ATMOSPHERIC RESEARCH *\nC * *\nC * BOULDER, COLORADO (80307) U.S.A. *\nC * *\nC * WHICH IS SPONSORED BY *\nC * *\nC * THE NATIONAL SCIENCE FOUNDATION *\nC * *\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC\nC\nC\nC DIMENSION OF BDA(N),BDB(N),BDC(M),BDD(M),F(IDIMF,N),\nC ARGUMENTS W(SEE ARGUMENT LIST)\nC\nC LATEST REVISION NOVEMBER 1988\nC\nC PURPOSE SOLVES THE STANDARD FIVE-POINT FINITE\nC DIFFERENCE APPROXIMATION TO THE HELMHOLTZ\nC EQUATION\nC (D/DX)(DU/DX) + (D/DY)(DU/DY) + LAMBDA*U\nC = F(X,Y)\nC ON A STAGGERED GRID IN CARTESIAN COORDINATES.\nC\nC USAGE CALL HSTCRT (A,B,M,MBDCND,BDA,BDB,C,D\nC N,NBDCND,BDC,BDD,ELMBDA,\nC F,IDIMF,PERTRB,IERROR,W)\nC\nC ARGUMENTS\nC ON INPUT\nC\nC A,B\nC THE RANGE OF X, I.E. A .LE. X .LE. B.\nC A MUST BE LESS THAN B.\nC\nC M\nC THE NUMBER OF GRID POINTS IN THE\nC INTERVAL (A,B). THE GRID POINTS\nC IN THE X-DIRECTION ARE GIVEN BY\nC X(I) = A + (I-0.5)DX FOR I=1,2,...,M\nC WHERE DX =(B-A)/M. M MUST BE GREATER\nC THAN 2.\nC\nC MBDCND\nC INDICATES THE TYPE OF BOUNDARY CONDITIONS\nC AT X = A AND X = B.\nC\nC = 0 IF THE SOLUTION IS PERIODIC IN X,\nC U(M+I,J) = U(I,J).\nC\nC = 1 IF THE SOLUTION IS SPECIFIED AT\nC X = A AND X = B.\nC\nC = 2 IF THE SOLUTION IS SPECIFIED AT\nC X = A AND THE DERIVATIVE\nC OF THE SOLUTION WITH RESPECT TO X\nC IS SPECIFIED AT X = B.\nC\nC = 3 IF THE DERIVATIVE OF THE SOLUTION\nC WITH RESPECT TO X IS SPECIFIED\nC AT X = A AND X = B.\nC\nC = 4 IF THE DERIVATIVE OF THE SOLUTION\nC WITH RESPECT TO X IS SPECIFIED\nC AT X = A AND THE SOLUTION IS\nC SPECIFIED AT X = B.\nC\nC BDA\nC A ONE-DIMENSIONAL ARRAY OF LENGTH N\nC THAT SPECIFIES THE BOUNDARY VALUES\nC (IF ANY) OF THE SOLUTION AT X = A.\nC\nC WHEN MBDCND = 1 OR 2,\nC BDA(J) = U(A,Y(J)) , J=1,2,...,N.\nC\nC WHEN MBDCND = 3 OR 4,\nC BDA(J) = (D/DX)U(A,Y(J)) , J=1,2,...,N.\nC\nC BDB\nC A ONE-DIMENSIONAL ARRAY OF LENGTH N\nC THAT SPECIFIES THE BOUNDARY VALUES\nC OF THE SOLUTION AT X = B.\nC\nC WHEN MBDCND = 1 OR 4\nC BDB(J) = U(B,Y(J)) , J=1,2,...,N.\nC\nC WHEN MBDCND = 2 OR 3\nC BDB(J) = (D/DX)U(B,Y(J)) , J=1,2,...,N.\nC\nC C,D\nC THE RANGE OF Y, I.E. C .LE. Y .LE. D.\nC C MUST BE LESS THAN D.\nC\nC\nC N\nC THE NUMBER OF UNKNOWNS IN THE INTERVAL\nC (C,D). THE UNKNOWNS IN THE Y-DIRECTION\nC ARE GIVEN BY Y(J) = C + (J-0.5)DY,\nC J=1,2,...,N, WHERE DY = (D-C)/N.\nC N MUST BE GREATER THAN 2.\nC\nC NBDCND\nC INDICATES THE TYPE OF BOUNDARY CONDITIONS\nC AT Y = C AND Y = D.\nC\nC\nC = 0 IF THE SOLUTION IS PERIODIC IN Y, I.E.\nC U(I,J) = U(I,N+J).\nC\nC = 1 IF THE SOLUTION IS SPECIFIED AT Y = C\nC AND Y = D.\nC\nC = 2 IF THE SOLUTION IS SPECIFIED AT Y = C\nC AND THE DERIVATIVE OF THE SOLUTION\nC WITH RESPECT TO Y IS SPECIFIED AT\nC Y = D.\nC\nC = 3 IF THE DERIVATIVE OF THE SOLUTION\nC WITH RESPECT TO Y IS SPECIFIED AT\nC Y = C AND Y = D.\nC\nC = 4 IF THE DERIVATIVE OF THE SOLUTION\nC WITH RESPECT TO Y IS SPECIFIED AT\nC Y = C AND THE SOLUTION IS SPECIFIED\nC AT Y = D.\nC\nC BDC\nC A ONE DIMENSIONAL ARRAY OF LENGTH M THAT\nC SPECIFIES THE BOUNDARY VALUES OF THE\nC SOLUTION AT Y = C.\nC\nC WHEN NBDCND = 1 OR 2,\nC BDC(I) = U(X(I),C) , I=1,2,...,M.\nC\nC WHEN NBDCND = 3 OR 4,\nC BDC(I) = (D/DY)U(X(I),C), I=1,2,...,M.\nC\nC WHEN NBDCND = 0, BDC IS A DUMMY VARIABLE.\nC\nC BDD\nC A ONE-DIMENSIONAL ARRAY OF LENGTH M THAT\nC SPECIFIES THE BOUNDARY VALUES OF THE\nC SOLUTION AT Y = D.\nC\nC WHEN NBDCND = 1 OR 4,\nC BDD(I) = U(X(I),D) , I=1,2,...,M.\nC\nC WHEN NBDCND = 2 OR 3,\nC BDD(I) = (D/DY)U(X(I),D) , I=1,2,...,M.\nC\nC WHEN NBDCND = 0, BDD IS A DUMMY VARIABLE.\nC\nC ELMBDA\nC THE CONSTANT LAMBDA IN THE HELMHOLTZ\nC EQUATION. IF LAMBDA IS GREATER THAN 0,\nC A SOLUTION MAY NOT EXIST. HOWEVER,\nC HSTCRT WILL ATTEMPT TO FIND A SOLUTION.\nC\nC F\nC A TWO-DIMENSIONAL ARRAY THAT SPECIFIES\nC THE VALUES OF THE RIGHT SIDE OF THE\nC HELMHOLTZ EQUATION. FOR I=1,2,...,M\nC AND J=1,2,...,N\nC\nC F(I,J) = F(X(I),Y(J)) .\nC\nC F MUST BE DIMENSIONED AT LEAST M X N.\nC\nC IDIMF\nC THE ROW (OR FIRST) DIMENSION OF THE ARRAY\nC F AS IT APPEARS IN THE PROGRAM CALLING\nC HSTCRT. THIS PARAMETER IS USED TO SPECIFY\nC THE VARIABLE DIMENSION OF F.\nC IDIMF MUST BE AT LEAST M.\nC\nC W\nC A ONE-DIMENSIONAL ARRAY THAT MUST BE\nC PROVIDED BY THE USER FOR WORK SPACE.\nC W MAY REQUIRE UP TO 13M + 4N +\nC M*INT(LOG2(N)) LOCATIONS. THE ACTUAL NUMBER\nC OF LOCATIONS USED IS COMPUTED BY HSTCRT\nC AND IS RETURNED IN THE LOCATION W(1).\nC\nC ON OUTPUT F\nC CONTAINS THE SOLUTION U(I,J) OF THE FINITE\nC DIFFERENCE APPROXIMATION FOR THE GRID POINT\nC (X(I),Y(J)) FOR I=1,2,...,M, J=1,2,...,N.\nC\nC PERTRB\nC IF A COMBINATION OF PERIODIC OR DERIVATIVE\nC BOUNDARY CONDITIONS IS SPECIFIED FOR A\nC POISSON EQUATION (LAMBDA = 0), A SOLUTION\nC MAY NOT EXIST. PERTRB IS A CONSTANT,\nC CALCULATED AND SUBTRACTED FROM F, WHICH\nC ENSURES THAT A SOLUTION EXISTS. HSTCRT\nC THEN COMPUTES THIS SOLUTION, WHICH IS A\nC LEAST SQUARES SOLUTION TO THE ORIGINAL\nC APPROXIMATION. THIS SOLUTION PLUS ANY\nC CONSTANT IS ALSO A SOLUTION; HENCE, THE\nC SOLUTION IS NOT UNIQUE. THE VALUE OF\nC PERTRB SHOULD BE SMALL COMPARED TO THE\nC RIGHT SIDE F. OTHERWISE, A SOLUTION IS\nC OBTAINED TO AN ESSENTIALLY DIFFERENT PROBLEM.\nC THIS COMPARISON SHOULD ALWAYS BE MADE TO\nC INSURE THAT A MEANINGFUL SOLUTION HAS BEEN\nC OBTAINED.\nC\nC IERROR\nC AN ERROR FLAG THAT INDICATES INVALID INPUT\nC PARAMETERS. EXCEPT TO NUMBERS 0 AND 6,\nC A SOLUTION IS NOT ATTEMPTED.\nC\nC = 0 NO ERROR\nC\nC = 1 A .GE. B\nC\nC = 2 MBDCND .LT. 0 OR MBDCND .GT. 4\nC\nC = 3 C .GE. D\nC\nC = 4 N .LE. 2\nC\nC = 5 NBDCND .LT. 0 OR NBDCND .GT. 4\nC\nC = 6 LAMBDA .GT. 0\nC\nC = 7 IDIMF .LT. M\nC\nC = 8 M .LE. 2\nC\nC SINCE THIS IS THE ONLY MEANS OF INDICATING\nC A POSSIBLY INCORRECT CALL TO HSTCRT, THE\nC USER SHOULD TEST IERROR AFTER THE CALL.\nC\nC W\nC W(1) CONTAINS THE REQUIRED LENGTH OF W.\nC\nC I/O NONE\nC\nC PRECISION SINGLE\nC\nC REQUIRED LIBRARY COMF, GENBUN, GNBNAUX, AND POISTG\nC FILES FROM FISHPACK\nC\nC LANGUAGE FORTRAN\nC\nC HISTORY WRITTEN BY ROLAND SWEET AT NCAR IN 1977.\nC RELEASED ON NCAR'S PUBLIC SOFTWARE LIBRARIES\nC IN JANUARY 1980.\nC\nC PORTABILITY FORTRAN 77\nC\nC ALGORITHM THIS SUBROUTINE DEFINES THE FINITE-DIFFERENCE\nC EQUATIONS, INCORPORATES BOUNDARY DATA, ADJUSTS\nC THE RIGHT SIDE WHEN THE SYSTEM IS SINGULAR\nC AND CALLS EITHER POISTG OR GENBUN WHICH SOLVES\nC THE LINEAR SYSTEM OF EQUATIONS.\nC\nC TIMING FOR LARGE M AND N, THE OPERATION COUNT\nC IS ROUGHLY PROPORTIONAL TO M*N*LOG2(N).\nC\nC ACCURACY THE SOLUTION PROCESS EMPLOYED RESULTS IN A\nC LOSS OF NO MORE THAN FOUR SIGNIFICANT DIGITS\nC FOR N AND M AS LARGE AS 64. MORE DETAILED\nC INFORMATION ABOUT ACCURACY CAN BE FOUND IN\nC THE DOCUMENTATION FOR PACKAGE POISTG WHICH\nC SOLVES THE FINITE DIFFERENCE EQUATIONS.\nC\nC REFERENCES U. SCHUMANN AND R. SWEET,\"A DIRECT METHOD\nC FOR THE SOLUTION OF POISSON'S EQUATION WITH\nC BOUNDARY CONDITIONS ON A STAGGERED GRID OF\nC ARBITRARY SIZE,\" J. COMP. PHYS. 20(1976),\nC PP. 171-182.\nC***********************************************************************\n DIMENSION F(IDIMF,1) ,BDA(*) ,BDB(*) ,BDC(*) ,\n 1 BDD(*) ,W(*)\nC\nC CHECK FOR INVALID PARAMETERS.\nC\n IERROR = 0\n IF (A .GE. B) IERROR = 1\n IF (MBDCND.LT.0 .OR. MBDCND.GT.4) IERROR = 2\n IF (C .GE. D) IERROR = 3\n IF (N .LE. 2) IERROR = 4\n IF (NBDCND.LT.0 .OR. NBDCND.GT.4) IERROR = 5\n IF (IDIMF .LT. M) IERROR = 7\n IF (M .LE. 2) IERROR = 8\n IF (IERROR .NE. 0) RETURN\n NPEROD = NBDCND\n MPEROD = 0\n IF (MBDCND .GT. 0) MPEROD = 1\n DELTAX = (B-A)/FLOAT(M)\n TWDELX = 1./DELTAX\n DELXSQ = 2./DELTAX**2\n DELTAY = (D-C)/FLOAT(N)\n TWDELY = 1./DELTAY\n DELYSQ = DELTAY**2\n TWDYSQ = 2./DELYSQ\n NP = NBDCND+1\n MP = MBDCND+1\nC\nC DEFINE THE A,B,C COEFFICIENTS IN W-ARRAY.\nC\n ID2 = M\n ID3 = ID2+M\n ID4 = ID3+M\n S = (DELTAY/DELTAX)**2\n ST2 = 2.*S\n DO 101 I=1,M\n W(I) = S\n J = ID2+I\n W(J) = -ST2+ELMBDA*DELYSQ\n J = ID3+I\n W(J) = S\n 101 CONTINUE\nC\nC ENTER BOUNDARY DATA FOR X-BOUNDARIES.\nC\n GO TO (111,102,102,104,104),MP\n 102 DO 103 J=1,N\n F(1,J) = F(1,J)-BDA(J)*DELXSQ\n 103 CONTINUE\n W(ID2+1) = W(ID2+1)-W(1)\n GO TO 106\n 104 DO 105 J=1,N\n F(1,J) = F(1,J)+BDA(J)*TWDELX\n 105 CONTINUE\n W(ID2+1) = W(ID2+1)+W(1)\n 106 GO TO (111,107,109,109,107),MP\n 107 DO 108 J=1,N\n F(M,J) = F(M,J)-BDB(J)*DELXSQ\n 108 CONTINUE\n W(ID3) = W(ID3)-W(1)\n GO TO 111\n 109 DO 110 J=1,N\n F(M,J) = F(M,J)-BDB(J)*TWDELX\n 110 CONTINUE\n W(ID3) = W(ID3)+W(1)\n 111 CONTINUE\nC\nC ENTER BOUNDARY DATA FOR Y-BOUNDARIES.\nC\n GO TO (121,112,112,114,114),NP\n 112 DO 113 I=1,M\n F(I,1) = F(I,1)-BDC(I)*TWDYSQ\n 113 CONTINUE\n GO TO 116\n 114 DO 115 I=1,M\n F(I,1) = F(I,1)+BDC(I)*TWDELY\n 115 CONTINUE\n 116 GO TO (121,117,119,119,117),NP\n 117 DO 118 I=1,M\n F(I,N) = F(I,N)-BDD(I)*TWDYSQ\n 118 CONTINUE\n GO TO 121\n 119 DO 120 I=1,M\n F(I,N) = F(I,N)-BDD(I)*TWDELY\n 120 CONTINUE\n 121 CONTINUE\n DO 123 I=1,M\n DO 122 J=1,N\n F(I,J) = F(I,J)*DELYSQ\n 122 CONTINUE\n 123 CONTINUE\n IF (MPEROD .EQ. 0) GO TO 124\n W(1) = 0.\n W(ID4) = 0.\n 124 CONTINUE\n PERTRB = 0.\n IF (ELMBDA) 133,126,125\n 125 IERROR = 6\n GO TO 133\n 126 GO TO (127,133,133,127,133),MP\n 127 GO TO (128,133,133,128,133),NP\nC\nC FOR SINGULAR PROBLEMS MUST ADJUST DATA TO INSURE THAT A SOLUTION\nC WILL EXIST.\nC\n 128 CONTINUE\n S = 0.\n DO 130 J=1,N\n DO 129 I=1,M\n S = S+F(I,J)\n 129 CONTINUE\n 130 CONTINUE\n PERTRB = S/FLOAT(M*N)\n DO 132 J=1,N\n DO 131 I=1,M\n F(I,J) = F(I,J)-PERTRB\n 131 CONTINUE\n 132 CONTINUE\n PERTRB = PERTRB/DELYSQ\nC\nC SOLVE THE EQUATION.\nC\n 133 CONTINUE\n IF (NPEROD .EQ. 0) GO TO 134\n CALL POISTG (NPEROD,N,MPEROD,M,W(1),W(ID2+1),W(ID3+1),IDIMF,F,\n 1 IERR1,W(ID4+1))\n GO TO 135\n 134 CONTINUE\n CALL GENBUN (NPEROD,N,MPEROD,M,W(1),W(ID2+1),W(ID3+1),IDIMF,F,\n 1 IERR1,W(ID4+1))\n 135 CONTINUE\n W(1) = W(ID4+1)+3.*FLOAT(M)\n RETURN\nC\nC REVISION HISTORY---\nC\nC SEPTEMBER 1973 VERSION 1\nC APRIL 1976 VERSION 2\nC JANUARY 1978 VERSION 3\nC DECEMBER 1979 VERSION 3.1\nC FEBRUARY 1985 DOCUMENTATION UPGRADE\nC NOVEMBER 1988 VERSION 3.2, FORTRAN 77 CHANGES\nC-----------------------------------------------------------------------\n END\n", "meta": {"hexsha": "0cd1841ac80d9baa0e1712dcfc1c73423a3e34aa", "size": 17069, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/src/hstcrt.f", "max_stars_repo_name": "ipelupessy/omuse", "max_stars_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2020-03-25T10:02:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-18T00:28:35.000Z", "max_issues_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/src/hstcrt.f", "max_issues_repo_name": "ipelupessy/omuse", "max_issues_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 45, "max_issues_repo_issues_event_min_datetime": "2020-03-03T16:07:16.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-14T09:01:07.000Z", "max_forks_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/src/hstcrt.f", "max_forks_repo_name": "ipelupessy/omuse", "max_forks_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-03-03T13:28:50.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-26T09:20:02.000Z", "avg_line_length": 38.4436936937, "max_line_length": 72, "alphanum_fraction": 0.3983244478, "num_tokens": 4708, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966717067253, "lm_q2_score": 0.721743200312399, "lm_q1q2_score": 0.6831997112426773}} {"text": "!\n! Copyright 2016 ARTED developers\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 implied.\n! See the License for the specific language governing permissions and\n! limitations under the License.\n!\n\n!===============================================================\nreal(8) function bessel_j1(x)\n implicit none\n real(8), intent(in) :: x\n integer, parameter :: order = 30\n real(8) :: c, s\n integer :: m\n\n c = 0.5 * x\n s = c\n do m = 1, 30\n c = -0.25d0 * x * x / (m * (m + 1)) * c\n s = s + c\n end do\n bessel_j1 = s\n return\nend function bessel_j1\n!===============================================================\nreal(8) function sin2cos(t, tw, omega, cep)\n use Global_Variables, only: pi\n implicit none\n real(8), intent(in) :: t, tw, omega, cep\n real(8) :: theta1, theta2\n\n if ((0 <= t) .and. (t <= tw)) then\n theta1 = pi / tw * t\n theta2 = omega * t + 2 * pi * cep\n sin2cos = sin(theta1) ** 2 * cos(theta2)\n else\n sin2cos = 0.0d0\n endif\n return\nend function sin2cos\n!===============================================================\nsubroutine incident_bessel_beam()\n use Global_Variables, only: IWcm2_1, omegaeV_1, tpulsefs_1, Epdir_1, phi_CEP_1, &\n & NXvacL_m, NXvacR_m, NYvacB_m, NYvacT_m, &\n & HX_m, HY_m, Ac_m, Ac_new_m, dt, &\n & pi, c_light\n implicit none\n real(8) :: f0_1, omega_1, tpulse_1, wpulse_1\n integer :: ix_m, iy_m\n real(8) :: lx, ly, x, y, kx, ky, k, vx\n real(8) :: f(3), j, tau\n \n real(8) bessel_j1, sin2cos\n \n ! First pulse\n f0_1 = 5.338d-9*sqrt(IWcm2_1) ! electric field in a.u.\n omega_1 = omegaeV_1 / (2d0*13.6058d0) ! frequency in a.u.\n tpulse_1 = tpulsefs_1 / 0.02418d0 ! pulse_duration in a.u.\n wpulse_1 = 2*pi/tpulse_1\n\n lx = (NXvacR_m-NXvacL_m) * HX_m\n ly = (NYvacT_m+1) * HY_m\n\n ky = 3.8317d0 / ly\n k = omega_1 / c_light\n \n if (ky > k) then\n call err_finalize('Error: NY,HY is not enough')\n endif\n \n kx = SQRT(k*k-ky*ky)\n vx = omega_1 / kx\n\n Ac_m = 0.0\n Ac_new_m = 0.0\n do iy_m = NYvacB_m, NYvacT_m\n y = HY_m * iy_m\n j = bessel_j1(ky * y)\n f = j * f0_1 / 0.58186d0 * Epdir_1\n do ix_m = NXvacL_m-1, 0\n x = ix_m * HX_m\n ! Ac_new_m\n tau = - x / vx\n Ac_new_m(:,ix_m,iy_m) = f * sin2cos(tau, tpulse_1, omega_1, phi_CEP_1)\n ! Ac_m (previous time-step)\n tau = - x / vx - dt\n Ac_m(:,ix_m,iy_m) = f * sin2cos(tau, tpulse_1, omega_1, phi_CEP_1)\n end do\n end do\n \n ! impose boundary condition\n Ac_new_m(:,:,NYvacT_m+1) = 0.0d0\n Ac_new_m(2:3,:,NYvacB_m-1) = 0.0d0\n Ac_new_m(1,:,NYvacB_m-1) = Ac_new_m(1,:,NYvacB_m)\n Ac_m(:,:,NYvacT_m+1) = 0.0d0\n Ac_m(2:3,:,NYvacB_m-1) = 0.0d0\n Ac_m(1,:,NYvacB_m-1) = Ac_m(1,:,NYvacB_m)\n return\nend subroutine incident_bessel_beam\n\n\nsubroutine read_initial_ac_from_file()\n use Global_Variables, only: SYSName, directory,file_ac_init, &\n & Ac_m, Ac_new_m\n use communication, only: comm_is_root, comm_bcast, proc_group\n implicit none\n integer :: ix_m, iy_m\n integer :: nx1_m, nx2_m, ny1_m, ny2_m\n \n write(file_ac_init, \"(A,A,'_Ac_init.dat')\") trim(directory), trim(SYSname)\n if (comm_is_root(1)) then\n Ac_m = 0.0\n Ac_new_m = 0.0\n open(944, file=trim(file_ac_init))\n read(944, *) nx1_m, nx2_m\n read(944, *) ny1_m, ny2_m\n do iy_m = ny1_m, ny2_m\n do ix_m = nx1_m, nx2_m\n read(944, *) Ac_m(:, ix_m, iy_m), Ac_new_m(:, ix_m, iy_m)\n end do\n end do\n close(944)\n end if\n call comm_bcast(Ac_m, proc_group(1))\n call comm_bcast(Ac_new_m, proc_group(1))\n return\nend subroutine \n", "meta": {"hexsha": "167d9551e5a5b55f9a16c08b0f86bb92a963a620", "size": 4004, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "FDTD/beam.f90", "max_stars_repo_name": "shunsuke-sato/ARTED", "max_stars_repo_head_hexsha": "608e503c75076ac912a8a997910faf72e81f63f0", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2016-11-20T12:56:04.000Z", "max_stars_repo_stars_event_max_datetime": "2018-03-02T02:00:18.000Z", "max_issues_repo_path": "FDTD/beam.f90", "max_issues_repo_name": "shunsuke-sato/ARTED", "max_issues_repo_head_hexsha": "608e503c75076ac912a8a997910faf72e81f63f0", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 20, "max_issues_repo_issues_event_min_datetime": "2016-07-10T05:34:15.000Z", "max_issues_repo_issues_event_max_datetime": "2017-04-09T02:51:54.000Z", "max_forks_repo_path": "FDTD/beam.f90", "max_forks_repo_name": "shunsuke-sato/ARTED", "max_forks_repo_head_hexsha": "608e503c75076ac912a8a997910faf72e81f63f0", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2016-06-29T20:52:16.000Z", "max_forks_repo_forks_event_max_datetime": "2018-05-25T07:03:49.000Z", "avg_line_length": 29.2262773723, "max_line_length": 83, "alphanum_fraction": 0.5894105894, "num_tokens": 1467, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067195846919, "lm_q2_score": 0.7248702880639791, "lm_q1q2_score": 0.6831951173275916}} {"text": "! mpiexec -np 4 bin/Debug/WGFM_test2.exe\nprogram mainWGF\n use meshread_mod\n use spherePEC_mod\n implicit none\n\n real(8), parameter :: pi = 4d0 * atan(1d0)\n complex(8), parameter :: IU = (0d0, 1d0)\n\n ! Variables\n type(Mesh) :: msh_evl\n complex(8), allocatable :: Esrc(:, :) ! Source electric field\n complex(8), allocatable :: Eexact(:, :) ! Exact electric field solution\n\n real(8) :: ExNormSrc, ExNormTot\n integer :: nEvl\n\n ! Parameters\n real(8), parameter :: ep0 = 1d0 / (35950207149.4727056d0 * PI) ! vacuum permittivity [F/m]\n real(8), parameter :: mu0 = PI * 4d-7 ! vacuum permeability [H/m]\n real(8), parameter :: k0 = 2*PI ! free-space wavenumber [1/m]\n\n real(8), parameter :: ep1_r = 1d0 ! upper half-space relative permittivity\n real(8), parameter :: ep1 = ep0*ep1_r ! upper half-space permittivity [F/m]\n real(8), parameter :: mu1 = mu0 ! upper half-space permeability [H/m]\n\n real(8), parameter :: w = k0 / sqrt(ep0 * mu0) ! angular frequency [rad/s]\n real(8), parameter :: k1 = w * sqrt(ep1 * mu1) ! upper half-space wavenumber [1/m]\n\n character(len=100), parameter :: file_evl_msh = 'meshes/eval_msh/dome.msh'\n real(8), parameter :: sph_radius = 1d0 ! hemisphere radius\n\n ! Planewave parameters\n integer, parameter :: n_terms = 100 ! number of terms in Mie series\n real(8), parameter :: alpha = PI/32d0 ! planewave angle of incidence in (0, pi)\n logical, parameter :: TE_mode = .false. ! planewave mode: TEmode = .true.\n ! TMmode = .false.\n\n !************************************************************************************\n\n ! Load eval mesh\n call load_gmsh(file_evl_msh, msh_evl)\n nEvl = size(msh_evl%POS, 1)\n\n ! Compute source field Esrc\n call halfsphere_on_plane_source_field(alpha, k1, msh_evl, Esrc, TE_mode)\n\n ! Compute exact solution Es\n print *, \"Exact solution\"\n call halfsphere_on_plane_scattered_field(msh_evl%POS, k1, sph_radius, &\n alpha, n_terms, Eexact, TE_mode)\n print *, \"done\"\n\n ! ExNormSrc\n ExNormSrc = maxval(sqrt(abs(Eexact(:,1))**2+abs(Eexact(:,2))**2+abs(Eexact(:,3))**2))\n \n ! ExNormTot\n Eexact = Eexact + Esrc\n ExNormTot = maxval(sqrt(abs(Eexact(:,1))**2+abs(Eexact(:,2))**2+abs(Eexact(:,3))**2))\n\n ! ExNorm\n print *, \"ExNormSrc\", ExNormSrc\n print *, \"ExNormTot\", ExNormTot\nend program \n", "meta": {"hexsha": "3fecd75d6547da42b1bb44543797d311d003c463", "size": 2544, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "script/WGFMethod/mainMieField.f90", "max_stars_repo_name": "Riarrieta/WindowedGreenFunctionMethod", "max_stars_repo_head_hexsha": "e6f965cac1acd8d9922e2bf94c33e3577ceb0dc9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "script/WGFMethod/mainMieField.f90", "max_issues_repo_name": "Riarrieta/WindowedGreenFunctionMethod", "max_issues_repo_head_hexsha": "e6f965cac1acd8d9922e2bf94c33e3577ceb0dc9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "script/WGFMethod/mainMieField.f90", "max_forks_repo_name": "Riarrieta/WindowedGreenFunctionMethod", "max_forks_repo_head_hexsha": "e6f965cac1acd8d9922e2bf94c33e3577ceb0dc9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.1384615385, "max_line_length": 95, "alphanum_fraction": 0.5770440252, "num_tokens": 769, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357701094304, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.6831645310074815}} {"text": "\nmodule quadrature_mc\n\ncontains\n\nfunction quad_mc(g, a, b, ndim, npoints)\n\n implicit none\n real(kind=8),external :: g\n integer, intent(in) :: ndim, npoints\n real(kind=8), intent(in) :: a(ndim), b(ndim)\n real(kind=8) :: quad_mc\n\n integer :: i\n\n real(kind=4), allocatable :: r(:), rr(:)\n real(kind=8) :: gsum, volume\n real(kind=8), allocatable :: x(:)\n\n allocate(r(ndim*npoints))\n allocate(x(ndim), rr(ndim))\n\n gsum = 0.d0\n\n volume = product(b-a)\n\n call random_number(r)\n do i=1,npoints\n rr = r((i-1)*ndim + 1 : i*ndim) ! next ndim elements of r\n x = a + rr*(b-a) ! sets ndim elements of x elementwise\n gsum = gsum + g(x,ndim)\n enddo\n quad_mc = volume * gsum / npoints\n\n deallocate(x,r,rr)\n\nend function quad_mc\n\nend module quadrature_mc\n", "meta": {"hexsha": "8ac80db166f41a5509a9b38fbcf2ba9df810255b", "size": 819, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/2013/solutions/project/part2/quadrature_mc.f90", "max_stars_repo_name": "philipwangdk/HPC", "max_stars_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "uwhpsc/2013/solutions/project/part2/quadrature_mc.f90", "max_issues_repo_name": "philipwangdk/HPC", "max_issues_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "uwhpsc/2013/solutions/project/part2/quadrature_mc.f90", "max_forks_repo_name": "philipwangdk/HPC", "max_forks_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.475, "max_line_length": 66, "alphanum_fraction": 0.5897435897, "num_tokens": 269, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021708, "lm_q2_score": 0.7879312031126512, "lm_q1q2_score": 0.6831645293626162}} {"text": "module Mbinning\n\n use, intrinsic :: iso_c_binding, only: dp=>C_DOUBLE\n\n contains\n\n integer function test(a,b)\n implicit none\n integer, intent(in) :: a,b\n test = a+b\n return\n end function test\n\n ! the matrix, vector sizes go to the end of the call list\n ! since we do not have to provide them in python\n ! automatic detection\n subroutine binMatrix_r(inMatrix, vec1, vec2, outMatrix, inX, inY, vec1length, vec2length)\n implicit none\n integer, intent(in) :: inX, inY, vec1length, vec2length\n\n real(dp), dimension(inX, inY), intent(in) :: inMatrix\n real(dp), dimension(vec1length, vec2length), intent(inout) :: outMatrix\n\n integer, dimension(vec1length), intent(in) :: vec1\n integer, dimension(vec2length), intent(in) :: vec2\n\n integer :: i,j\n integer :: ii,jj\n real(dp) :: tempsum\n integer :: vecsum\n\n integer :: xbegin, xend\n integer :: ybegin, yend\n\n ! check vector lengths\n\n vecsum = 0\n do i=1,vec1length\n vecsum = vecsum + vec1(i)\n enddo\n\n if (vecsum /= inX) then\n write(*,*) 'WARNING: inMatrix x-size inconsistent with x vector'\n endif\n\n\n vecsum = 0\n do i=1,vec2length\n vecsum = vecsum + vec2(i)\n enddo\n\n if (vecsum /= inY) then\n write(*,*) 'WARNING: inMatrix y-size inconsistent with y vector'\n endif\n\n\n ! we scan through the coarse grid\n do j=1,vec2length\n do i=1,vec1length\n\n ! determine index ranges\n xbegin = 1\n do ii=1,i-1\n xbegin = xbegin + vec1(ii)\n enddo\n xend = xbegin + vec1(i) - 1\n\n ybegin = 1\n do jj=1,j-1\n ybegin = ybegin + vec2(jj)\n enddo\n yend = ybegin + vec2(j) - 1\n\n\n ! index through the coarse grid and sum all elements\n tempsum = 0\n do jj=ybegin,yend\n do ii=xbegin,xend\n tempsum = tempsum + inMatrix(ii,jj)\n enddo\n enddo\n\n outMatrix(i,j) = tempsum\n\n enddo\n enddo\n\n end subroutine\n\n subroutine binMatrix_c(inMatrix, vec1, vec2, outMatrix, inX, inY, vec1length, vec2length)\n implicit none\n integer, intent(in) :: inX, inY, vec1length, vec2length\n\n complex(dp), dimension(inX, inY), intent(in) :: inMatrix\n complex(dp), dimension(vec1length, vec2length), intent(inout) :: outMatrix\n\n integer, dimension(vec1length), intent(in) :: vec1\n integer, dimension(vec2length), intent(in) :: vec2\n\n integer :: i,j\n integer :: ii,jj\n complex(dp) :: tempsum\n integer :: vecsum\n\n integer :: xbegin, xend\n integer :: ybegin, yend\n\n ! check vector lengths\n\n vecsum = 0\n do i=1,vec1length\n vecsum = vecsum + vec1(i)\n enddo\n\n if (vecsum /= inX) then\n write(*,*) 'WARNING: inMatrix x-size inconsistent with x vector'\n endif\n\n\n vecsum = 0\n do i=1,vec2length\n vecsum = vecsum + vec2(i)\n enddo\n\n if (vecsum /= inY) then\n write(*,*) 'WARNING: inMatrix y-size inconsistent with y vector'\n endif\n\n\n ! we scan through the coarse grid\n do j=1,vec2length\n do i=1,vec1length\n\n ! determine index ranges\n xbegin = 1\n do ii=1,i-1\n xbegin = xbegin + vec1(ii)\n enddo\n xend = xbegin + vec1(i) - 1\n\n ybegin = 1\n do jj=1,j-1\n ybegin = ybegin + vec2(jj)\n enddo\n yend = ybegin + vec2(j) - 1\n\n\n ! index through the coarse grid and sum all elements\n tempsum = 0\n do jj=ybegin,yend\n do ii=xbegin,xend\n tempsum = tempsum + inMatrix(ii,jj)\n enddo\n enddo\n\n outMatrix(i,j) = tempsum\n\n enddo\n enddo\n\n end subroutine\n\n\n\nend module Mbinning\n", "meta": {"hexsha": "b38c3f4b7b9e101cca68a6b63c1e128c04bcc8df", "size": 3687, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran_source/binning.f90", "max_stars_repo_name": "mpickem/binning_f2py", "max_stars_repo_head_hexsha": "ba7372fa61e15a1f89e54a75865f71a6b12d7428", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fortran_source/binning.f90", "max_issues_repo_name": "mpickem/binning_f2py", "max_issues_repo_head_hexsha": "ba7372fa61e15a1f89e54a75865f71a6b12d7428", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran_source/binning.f90", "max_forks_repo_name": "mpickem/binning_f2py", "max_forks_repo_head_hexsha": "ba7372fa61e15a1f89e54a75865f71a6b12d7428", "max_forks_repo_licenses": ["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.2108433735, "max_line_length": 91, "alphanum_fraction": 0.5852997017, "num_tokens": 1113, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021708, "lm_q2_score": 0.7879312006227323, "lm_q1q2_score": 0.6831645272037674}} {"text": "module ExampleOperators\n use Precision\n use AbstractOperators\n use DVectors\n\n private\n\n !! Derived type describing the 1d-Laplacian\n !! with periodic boundary conditions\n type, public, extends(abstract_operator) :: Laplacian\n contains\n procedure, public, pass :: init => init_LP\n !! procedure overrided \n procedure, public, pass :: apply => apply_LP\n end type Laplacian\n\n !! Derived type describing the 1d-Laplacian\n !! with periodic boundary conditions\n type, public, extends(abstract_operator) :: DiagonalMatrix\n double precision, allocatable :: coefficients(:)\n contains\n procedure, public, pass :: init => init_DM\n procedure, public, pass :: kill => kill_DM\n !! procedure overrided \n procedure, public, pass :: apply => apply_DM\n end type DiagonalMatrix\n \ncontains\n\n !! constructor\n subroutine init_LP(this, nnode)\n implicit none\n class(Laplacian), intent(inout) :: this\n integer, intent(in ) :: nnode\n \n !! the set domain/codomain operator dimension\n this%nrow = nnode\n this%ncol = nnode\n this%is_symmetric=.True.\n\n end subroutine init_LP\n\n !! apply tridiagonal operator\n subroutine apply_LP(this,vec_in,vec_out,ierr)\n implicit none\n class(Laplacian), intent(inout) :: this\n class(dvector), intent(in ) :: vec_in\n class(dvector), intent(inout) :: vec_out\n integer, intent(inout) :: ierr\n !local\n double precision :: sign=1.0d0, val\n integer :: i_row\n\n !! first row\n i_row=1\n val = 2*vec_in%get(i_row) + sign* vec_in%get(i_row+1)\n call vec_out%set(i_row,val)\n\n !! middle rowsuse DVectors\n do i_row=2,this%nrow-1\n val = sign * vec_in%get(i_row-1) + 2*vec_in%get(i_row) + sign* vec_in%get(i_row+1)\n call vec_out%set(i_row,val)\n end do\n \n !! last row\n i_row=this%nrow\n val = sign* vec_in%get(i_row-1) + 2*vec_in%get(i_row)\n call vec_out%set(i_row,val)\n\n \n ierr=0\n end subroutine apply_LP\n \n !! constructor\n subroutine init_DM(this, size)\n class(DiagonalMatrix), intent(inout) :: this\n integer, intent(in ) :: size\n \n this%nrow = size\n this%ncol = size\n this%is_symmetric=.True.\n\n\n allocate(this%coefficients(size))\n \n end subroutine init_DM\n\n !! destructor\n subroutine kill_DM(this)\n class(DiagonalMatrix), intent(inout) :: this\n \n this%nrow = 0\n this%ncol = 0\n this%is_symmetric=.False.\n\n deallocate(this%coefficients)\n \n end subroutine kill_DM\n\n !! apply diagonal matrix\n subroutine apply_DM(this,vec_in,vec_out,ierr)\n implicit none\n class(DiagonalMatrix), intent(inout) :: this\n class(dvector), intent(in ) :: vec_in\n class(dvector), intent(inout) :: vec_out\n integer, intent(inout) :: ierr\n !local\n integer :: i_row\n double precision :: val\n\n do i_row=1,this%nrow\n val=vec_in%get(i_row)*this%coefficients(i_row)\n call vec_out%set(i_row,val)\n end do\n ierr=0\n\n end subroutine apply_DM\n \nend module ExampleOperators\n", "meta": {"hexsha": "e02688208f396c863aec7c2b49bfa5370f4e62a0", "size": 3087, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src_abs_vect/ExampleOperators.f90", "max_stars_repo_name": "enricofacca/KrylovAPI", "max_stars_repo_head_hexsha": "33ced13dcad32b83aae867bebac894e7b82aab8f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src_abs_vect/ExampleOperators.f90", "max_issues_repo_name": "enricofacca/KrylovAPI", "max_issues_repo_head_hexsha": "33ced13dcad32b83aae867bebac894e7b82aab8f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src_abs_vect/ExampleOperators.f90", "max_forks_repo_name": "enricofacca/KrylovAPI", "max_forks_repo_head_hexsha": "33ced13dcad32b83aae867bebac894e7b82aab8f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.725, "max_line_length": 89, "alphanum_fraction": 0.6436669906, "num_tokens": 861, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357460591569, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.683164516375218}} {"text": " COMPLEX FUNCTION CDOTC(N,CX,INCX,CY,INCY)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nC>> 1994-11-11 CDOTC Krogh Declared all vars.\nC>> 1985-08-02 CDOTC Lawson Initial code.\nC\nC RETURNS THE DOT PRODUCT FOR COMPLEX CX AND CY, USES CONJUGATE(CX)\nC CDOTC = SUM FOR I = 0 TO N-1 OF CONJ(CX(LX+I*INCX))*CY(LY+I*INCY),\nC WHERE LX = 1 IF INCX .GE. 0, ELSE LX = (-INCX)*N, AND LY IS\nC DEFINED IN A SIMILAR WAY USING INCY.\nC\n INTEGER N, INCX, INCY, KX, KY, I, NS\n COMPLEX CX(*),CY(*)\nC\n CDOTC = (0.,0.)\n IF(N .LE. 0)RETURN\n IF(INCX.EQ.INCY.AND.INCX.GT.0) GO TO 20\n KX = 1\n KY = 1\n IF(INCX.LT.0) KX = 1+(1-N)*INCX\n IF(INCY.LT.0) KY = 1+(1-N)*INCY\n DO 10 I = 1,N\n CDOTC = CDOTC + CONJG(CX(KX))*CY(KY)\n KX = KX + INCX\n KY = KY + INCY\n 10 CONTINUE\n RETURN\n 20 CONTINUE\n NS = N*INCX\n DO 30 I=1,NS,INCX\n CDOTC = CONJG(CX(I))*CY(I) + CDOTC\n 30 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "1fb001feeb7cd7a1bac387eaccbd065cf6f07bcc", "size": 1113, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/cdotc.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/cdotc.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/cdotc.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": 30.9166666667, "max_line_length": 72, "alphanum_fraction": 0.5696316262, "num_tokens": 445, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357460591568, "lm_q2_score": 0.7879311881731379, "lm_q1q2_score": 0.6831645055809745}} {"text": "! This code is part of Radiative Transfer for Energetics (RTE)\n!\n! Contacts: Robert Pincus and Eli Mlawer\n! email: rrtmgp@aer.com\n!\n! Copyright 2015-2018, Atmospheric and Environmental Research and\n! Regents of the University of Colorado. All right reserved.\n!\n! Use and duplication is permitted under the terms of the\n! BSD 3-clause license, see http://opensource.org/licenses/BSD-3-Clause\n! -------------------------------------------------------------------------------------------------\n!\n! test for mo_rte_spherical_correction module\n! Igor Polonsky\n! ipolonsk@aer.com\n! \n! reads test data file ref_data.dat\n! \n\nprogram test_bending\n use mo_rte_spherical_correction \n use mo_rte_kind, only: wp, wl\n\timplicit none\n\n\ninteger, parameter :: nlev = 97 ! number of vertical levels\nreal(wp),parameter :: RE = 6371.23 ! in [km]\n\nreal(wp), dimension(nlev) :: temp, hum, RefIndex\n! no refraction\nreal(wp), dimension(nlev) :: mu ! solar zenith angle cosine\nreal(wp), dimension(nlev) :: SZ ! solar zenith angle\nreal(wp), dimension(nlev) :: refSZ ! reference solar zenith angle\n! with refraction\nreal(wp), dimension(nlev) :: muRef ! solar zenith angle cosine\nreal(wp), dimension(nlev) :: SZref ! solar zenith angle\nreal(wp), dimension(nlev) :: refSZref ! reference solar zenith angle\nreal(wp), dimension(nlev) :: alt, p\n\nreal(wp), dimension(nlev) :: refMu, refMuRef\n\nlogical(wl) :: top_at_1 ! TOA atnosphere at index 1\nlogical(wl) :: isError\n\ninteger :: jj\nreal(wp) :: g0, zsurf, mu0, wavenumber, refRefIndex\n!\n! read meterological profile \nopen(100, file='ref_data.dat', action='read', status='old')\n! skip comments\ndo jj=1,5\n\tread(100,*)\nenddo\n\ndo jj=1,nlev\n\tread(100,*) alt(jj), p(jj), temp(jj), hum(jj), szRef(jj), refSZref(jj)\nenddo\n! convert to [g/g]\nhum=hum*1e-3\nclose(100)\n\n! initial condition\n! solar zenith anle is 90 at surface\n! wavelength is 500 nm\n\nmu0 = cos(acos(-1d0)/180_wp*90_wp)\nwavenumber = 1e4/0.5\n\ntop_at_1 = p(1) < p(2)\n! compute index of refraction\n\ncall indexRefraction(nlev, temp, p, hum, wavenumber, RefIndex)\n\nif (top_at_1) then\n refRefIndex = RefIndex(nlev)\n zsurf = alt(nlev)\nelse\n refRefIndex = RefIndex(1)\n zsurf = alt(1)\nendif\n\n! compute solar zenith cosine without effect of refraction\ncall spherical_angles(nlev, zsurf, RE, alt, mu0, mu) \n\n\n! compute solar zenith cosine including the effect of refraction\ncall spherical_angles(nlev, zsurf, RE, alt, mu0, muRef, refRefIndex, RefIndex) \n\n! print out results\nprint *, ' altitude SZA cosine SZA cosine SZA SZA Refractivity'\nprint *, ' no refrac. with refrac. no ref. with ref. (n-1)*1e6'\nprint *, ' [km] [deg] [deg] [ppm]'\n \ndo jj=1, nlev\n\tprint '(4x, f6.3, 2(2x,E12.4), 3(4x, F7.2))', alt(jj), mu(jj), muRef(jj), 180_wp/acos(-1.)*acos(mu(jj)), &\n\t & 180_wp/acos(-1.)*acos(muRef(jj)), (RefIndex(jj) - 1.)*1e6\nenddo\nprint *,''\nprint *, 'Compare with reference:'\n\n! compare with reference vaules\nSZ = 180_wp/acos(-1.)*acos(mu) \nisError = any(abs(SZ-szRef) > 1e-6)\n\nif (isError) then\n\tprint *, 'bias in solar zenith angle (no refration)'\n print *, \"level angle ref.angle bias\"\n\tdo jj =1, nlev\n if (abs(SZ(jj)-szRef(jj)) > 1e-6) &\n print \"(I6, 3(F12.6, 2x) )\", jj, SZ(jj), szRef(jj), SZ(jj) - szRef(jj)\n\tenddo\nelse\n\tprint *, ' solar zenith angle (no refration) : PASSED'\nendif\n\nSZref = 180_wp/acos(-1.)*acos(muRef)\n\nif (any(abs(SZref-refSZref) > 1e-6)) then\n\tprint *, 'bias in solar zenith angle (with refration)'\n print *, \"level angle ref.angle bias\"\n\tdo jj =1, nlev\n\t\tif (abs(SZref(jj)-refSZref(jj)) > 1e-6) print \"(I6, 3(F12.6, 2x) )\", jj, SZref(jj), &\n refSZref(jj), SZref(jj) - refSZref(jj)\n\tenddo\nelse\n\tprint *, ' solar zenith angle (with refration): PASSED'\nendif\nend program test_bending", "meta": {"hexsha": "65fc1d82a77e47cc83e4b38c8fa938a70cfafd17", "size": 3983, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test_spherical_correction.f90", "max_stars_repo_name": "inpolonsky/bending_angle", "max_stars_repo_head_hexsha": "a41df2c836ecc0822db847088528a9a69377a56a", "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": "test_spherical_correction.f90", "max_issues_repo_name": "inpolonsky/bending_angle", "max_issues_repo_head_hexsha": "a41df2c836ecc0822db847088528a9a69377a56a", "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": "test_spherical_correction.f90", "max_forks_repo_name": "inpolonsky/bending_angle", "max_forks_repo_head_hexsha": "a41df2c836ecc0822db847088528a9a69377a56a", "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.1171875, "max_line_length": 107, "alphanum_fraction": 0.6249058499, "num_tokens": 1264, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969137, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.6831572366574389}} {"text": "MODULE common_mtx\n!=======================================================================\n!\n! [PURPOSE:] Matrix Functions\n!\n! [CREATED:] 07/20/2004 Takemasa Miyoshi\n! [UPDATED:] 10/16/2004 Takemasa Miyoshi\n!\n! [PUBLIC:]\n! mtx_eigen : eigenvalue decomposition\n! mtx_inv : real symmetric matrix inverse\n! mtx_sqrt : real symmetric matrix square root\n!\n! [REFERENCES:]\n! Core subroutines are adapted from netlib.org\n!\n! [HISTORY:]\n! 07/20/2003 Takemasa Miyoshi Created at University of Maryland, College Park\n!\n!=======================================================================\n USE common\n\n IMPLICIT NONE\n\n PRIVATE\n PUBLIC :: mtx_eigen, mtx_inv, mtx_sqrt, mtx_inv_rg\n\nCONTAINS\n!=======================================================================\n! Eigenvalue decomposition using subroutine rs\n! INPUT\n! INTEGER :: imode : mode switch (0: only eiven values)\n! INTEGER :: n : dimension of matrix\n! REAL(r_size) :: a(n,n) : input matrix\n! OUTPUT\n! REAL(r_size) :: eival(n) : eiven values in decending order\n! i.e. eival(1) is the largest\n! REAL(r_size) :: eivec(n,n) : eiven vectors\n! INTEGER :: nrank_eff : number of positive eivenvalues\n!=======================================================================\nSUBROUTINE mtx_eigen(imode,n,a,eival,eivec,nrank_eff)\n IMPLICIT NONE\n\n INTEGER,INTENT(IN) :: imode ! 0: calculate only eigen values\n INTEGER,INTENT(IN) :: n\n REAL(r_size),INTENT(IN) :: a(1:n,1:n)\n REAL(r_size),INTENT(OUT) :: eival(1:n)\n REAL(r_size),INTENT(OUT) :: eivec(1:n,1:n)\n INTEGER,INTENT(OUT) :: nrank_eff\n\n REAL(r_dble) :: a8(n,n)\n REAL(r_dble) :: eival8(n)\n REAL(r_dble) :: eivec8(n,n)\n REAL(r_dble) :: wrk1(n)\n REAL(r_dble) :: wrk2(n)\n INTEGER :: ierr,i,j\n\n a8 = a\n eivec8 = 0.0d0\n CALL rs(n,n,a8,eival8,imode,eivec8,wrk1,wrk2,ierr)\n IF( ierr/=0 ) THEN\n WRITE(6,'(A,I)') '!!! ERROR (mtx_eigen): rs error code is ',ierr\n STOP 2\n END IF\n\n nrank_eff = n\n IF( eival8(n) > 0 ) THEN\n DO i=1,n\n IF( eival8(i) < ABS(eival8(n))*SQRT(EPSILON(eival8)) ) THEN\n nrank_eff = nrank_eff - 1\n eival8(i) = 0.0d0\n eivec8(:,i) = 0.0d0\n END IF\n END DO\n ELSE\n WRITE(6,'(A)') '!!! ERROR (mtx_eigen): All Eigenvalues are below 0'\n !STEVE:\n print *, \"a = \", a\n print *, \"eival8 = \", eival8\n print *, \"imode = \", imode\n print *, \"eivec8 = \", eivec8\n print *, \"wrk1 = \", wrk1\n print *, \"wrk2 = \", wrk2\n print *, \"ierr = \", ierr\n !STEVE: end\n STOP 2\n END IF\n\n IF( nrank_eff 0 else False \nfunction is_positive(a) result(value)\n !DEC$ ATTRIBUTES DLLEXPORT, ALIAS:'is_positive' :: is_positive\n implicit none\n logical :: value\n real(8) :: a\n value = a > 0.d0\nend function is_positive\n\n \n! if do_addition is True return a+b otherwise return a-b\nfunction add_or_subtract(a, b, do_addition) result(value)\n !DEC$ ATTRIBUTES DLLEXPORT, ALIAS:'add_or_subtract' :: add_or_subtract\n implicit none\n logical :: do_addition\n integer(4) :: a, b, value\n if (do_addition) then\n value = a + b\n else\n value = a - b\n endif\nend function add_or_subtract\n\n \n! compute the n'th factorial of a 8-bit signed integer, return a double-precision number\nfunction factorial(n) result(value)\n !DEC$ ATTRIBUTES DLLEXPORT, ALIAS:'factorial' :: factorial\n implicit none\n integer(1) :: n\n integer(4) :: i\n double precision value\n if (n < 0) then\n value = 0.d0\n print *, \"Cannot compute the factorial of a negative number\", n\n else\n value = 1.d0\n do i = 2, n\n value = value * i\n enddo\n endif\nend function factorial\n\n\n! calculate the standard deviation of an array.\nfunction standard_deviation(a, n) result(var)\n !DEC$ ATTRIBUTES DLLEXPORT, ALIAS:'standard_deviation' :: standard_deviation\n integer :: n ! the length of the array\n double precision :: var, a(n)\n var = SUM(a)/SIZE(a) ! SUM is a built-in fortran function\n var = SQRT(SUM((a-var)**2)/(SIZE(a)-1.0))\nend function standard_deviation\n\n\n! compute the Bessel function of the first kind of order 0 of x\nfunction besselj0(x) result(val)\n !DEC$ ATTRIBUTES DLLEXPORT, ALIAS:'besselj0' :: besselj0\n double precision :: x, val\n val = BESSEL_J0(x)\nend function besselJ0\n\n\n! reverse a string, 'n' is the length of the original string\nsubroutine reverse_string(original, n, reversed)\n !DEC$ ATTRIBUTES DLLEXPORT, ALIAS:'reverse_string' :: reverse_string\n !DEC$ ATTRIBUTES REFERENCE :: original, reversed\n implicit none\n integer :: i, n\n character(len=n) :: original, reversed\n do i = 1, n\n reversed(i:i) = original(n-i+1:n-i+1)\n end do\nend subroutine reverse_string\n\n\n! element-wise addition of two 1D double-precision arrays\nsubroutine add_1d_arrays(a, in1, in2, n)\n !DEC$ ATTRIBUTES DLLEXPORT, ALIAS:'add_1d_arrays' :: add_1d_arrays\n implicit none\n integer(4) :: n ! the length of the input arrays\n double precision :: in1(n), in2(n) ! the arrays to add (element-wise)\n double precision :: a(n) ! the array that will contain the element-wise sum\n a(:) = in1(:) + in2(:)\n end subroutine add_1D_arrays\n\n\n! multiply two 2D, double-precision arrays. \n! NOTE: multi-dimensional arrays are column-major order in FORTRAN, \n! whereas C (Python) is row-major order.\nsubroutine matrix_multiply(a, a1, r1, c1, a2, r2, c2)\n !DEC$ ATTRIBUTES DLLEXPORT, ALIAS:'matrix_multiply' :: matrix_multiply\n implicit none\n integer(4) :: r1, c1, r2, c2 ! the dimensions of the input arrays\n double precision :: a1(r1,c1), a2(r2,c2) ! the arrays to multiply\n double precision :: a(r1,c2) ! resultant array\n a = MATMUL(a1, a2)\nend subroutine matrix_multiply\n ", "meta": {"hexsha": "3fe89c1edd5972609b14d6c72b5374f5741e96d9", "size": 4961, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "msl/examples/loadlib/fortran_lib.f90", "max_stars_repo_name": "MSLNZ/msl-loadlib", "max_stars_repo_head_hexsha": "60f100221774e7c8bac067b50f427fd1d99d2552", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 51, "max_stars_repo_stars_event_min_datetime": "2017-02-20T18:13:18.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T21:46:36.000Z", "max_issues_repo_path": "msl/examples/loadlib/fortran_lib.f90", "max_issues_repo_name": "MSLNZ/msl-loadlib", "max_issues_repo_head_hexsha": "60f100221774e7c8bac067b50f427fd1d99d2552", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 31, "max_issues_repo_issues_event_min_datetime": "2017-02-20T18:09:43.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-02T15:21:37.000Z", "max_forks_repo_path": "msl/examples/loadlib/fortran_lib.f90", "max_forks_repo_name": "MSLNZ/msl-loadlib", "max_forks_repo_head_hexsha": "60f100221774e7c8bac067b50f427fd1d99d2552", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2017-02-20T18:13:25.000Z", "max_forks_repo_forks_event_max_datetime": "2020-04-06T12:27:43.000Z", "avg_line_length": 31.2012578616, "max_line_length": 88, "alphanum_fraction": 0.6871598468, "num_tokens": 1461, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936437, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.6830700152157549}} {"text": "program main\n implicit none\n integer, parameter :: dp = selected_real_kind(8)\n real(dp), parameter :: kB = 1.380649d-23, hbar = 1.05457266d-34, omegac = 1.d13, omegar = 1.d14\n real(dp) :: T, beta, x, y\n\n open(unit = 1,file = '3-C-T.txt',status = 'unknown')\n T = 0.0d0\n do while (T <= 600)\n beta = 1 / (kB * T)\n x = T\n y = 3 * kB *&\n ((beta * hbar * omegac)**2 * exp(beta * hbar * omegac) / (exp(beta * hbar * omegac) - 1)**2&\n + (beta * hbar * omegar)**2 * exp(beta * hbar * omegar) / (exp(beta * hbar * omegar) - 1)**2) / kB\n write(1,\"(2f20.8)\") x, y\n T = T + .1d0\n end do\n close(1)\nend program main\n", "meta": {"hexsha": "cade755e36511139daa487a2f67f78a431802516", "size": 685, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Assignment-1/3-C-T.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-1/3-C-T.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-1/3-C-T.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": 34.25, "max_line_length": 110, "alphanum_fraction": 0.503649635, "num_tokens": 269, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582593509314, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6830675825676025}} {"text": "C***************************************************************************\nC************************ SUBROUTINE SCHMIT *******************************\nC***************************************************************************\nC\nC\n SUBROUTINE SCHMIT(X, Y, NP, NC, DELX, DELY, XORG, YORG, TOL, \n + MAX, NTOT, MX, MY, MXY, NM, NU, NL, FC, F, A, \n + ALPHA, BETA)\nC\nC\nC * *\nC * THIS SUBROUTINE COMPUTES LINEAR REGRESSION COEFFICIENTS *\nC * ALPHA AND BETA (INTERCEPT AND SLOPE) BY SCHMITT'S BINNED *\nC * METHOD. BECAUSE OF THE BINNING METHOD, FINER BINNING GIVES *\nC * BETTER RESULTS, THOUGH THE CPU TIME MAY INCREASE VERY *\nC * MUCH. ALSO IF THE BINS ARE TOO FINE, THE CENSORED POINTS *\nC * MAY NOT FALL ON THE DETECTIONS. *\nC * *\nC * *\nC * INPUT *\nC * X(I): INDEPENDENT VARIABLE *\nC * Y(I): DEPENDENT VARIABLE *\nC * NP(I): INDICATOR OF CENSORED STATUS *\nC * IF NP(I)=0 : DETECTION *\nC * =1 : Y(I) IS LOWER LIMIT *\nC * =2 : X(I) IS LOWER LIMIT *\nC * =3 : BOTH ARE LOWER LIMITS *\nC * =4 : Y(I) IS LOWER AND X(I) IS UPPER *\nC * FOR THE UPPER LIMITS, CHANGE THE SIGNS *\nC * NC(K): NUMBER OF CENSORED POINTS OF EACH TYPE *\nC * DELX : BIN SIZE OF X AXIS *\nC * DELY : BIN SIZE OF Y AXIS *\nC * XORG : ORIGIN OF X *\nC * YORG : ORIGIN OF Y *\nC * TOL : TOLERANCE FOR COMPUTAION F(I,J) *\nC * MAX : MAXIMUM ITERATION *\nC * NTOT : NUMBER OF DATA POINTS *\nC * MX : NUMBER OF BINS IN THE INDEPENDENT VARIABLE *\nC * MY : NUMBER OF BINS IN THE DEPENDENT VARIABLE *\nC * MXY : TOTAL NUMBER OF BINS *\nC * *\nC * OUTPUT *\nC * NM(K) : NUMBER OF LIMITS CHANGED TO DETECTIONS *\nC * NU(I,J) : NUMBER OF UNCENSORED IN THE BIN(I,J) *\nC * NL(I,J,K): NUMBER OF Y LOWER LIMITS IN THE BIN(I,J) *\nC * FC(I,J) : COPY OF F(I,J) (TO CHECK THE CONVERGENCE) *\nC * F(I,J) : NUMBER OF DATA POINTS IN BIN(I,J) *\nC * A(I,J) : MATRIX WHICH CONTAINS INFORMATION OF BIN *\nC * POSITION I=1,4 AND J=1,MX*MY *\nC * ALPHA : INTERCEPT COEFFICIENT *\nC * BETA : SLOPE COEFFICIENT *\nC * *\nC * WORK *\nC * TH(I) : VECTOR \" A(I,J)*F(I,J), I=1,4 *\nC * SUM : TOTAL NUMBER OF POINTS. THIS IS APPROXIMATELY *\nC * EQUAL TO NTOT. THE DIFFERENCE BETWEEN THE TWO *\nC * VALUES DEPENDS ON THE TOLERANCE LEVEL. *\nC * *\nC * SUBROUTINES: *\nC * GRDPRB : THE SUBROUTINE WHICH COMPUTES THE TWO-DIMENSIONAL * \nC * KAPLAN-MEIER PROBABILITY OF THE BINS *\nC * *\n\n IMPLICIT REAL*8 (A-H,O-Z), INTEGER (I-N)\n\n DIMENSION X(NTOT),Y(NTOT),NP(NTOT),NC(8),NM(8),NU(MX,MY)\n DIMENSION NL(MX,MY,8),FC(MX,MY),F(MX,MY),A(5,MXY),TH(5) \nC\nC * CALL SUBROUTINE GRDPRB *\nC\n CALL GRDPRB (X, Y, NP, NC, DELX, DELY, XORG, YORG, TOL, MAX,\n + NTOT, MX, MY, NM, NU, NL, FC, F)\nC\nC\nC * MAKE MATRIX A(I,J) *\nC\n IJ = 0\n DO 1120 J = 1,MY\n DO 1110 I = 1,MX\n IJ = IJ + 1\n XB = XORG + DELX / 2.0 + DELX * (I - 1)\n YB = YORG + DELY / 2.0 + DELY * (J - 1)\nC\n A(1,IJ) = XB\n A(2,IJ) = XB ** 2\n A(3,IJ) = XB * YB\n A(4,IJ) = YB\n A(5,IJ) = YB ** 2\n 1110 CONTINUE\n 1120 CONTINUE\nC\nC * COMPUTE THE VECTOR THETA : TH(I) *\nC\n DO 1400 I = 1,5\n TH(I) = 0.0\n 1400 CONTINUE\n\n IJ = 0\n DO 1430 J = 1,MY\n DO 1420 I = 1,MX\n IJ = IJ + 1\n DO 1410 K = 1,5\n TH(K) = TH(K) + A(K,IJ) * F(I,J) * NTOT\n 1410 CONTINUE\n 1420 CONTINUE\n 1430 CONTINUE\n\n SUM = 0.0\n DO 1460 I = 1, MX\n DO 1450 J = 1, MY\n SUM = SUM + F(I,J) * NTOT\n 1450 CONTINUE\n 1460 CONTINUE\n \nC\nC * COMPUTE THE SLOPE COEFFICIENT : BETA, AND THE INTERCEPT *\nC * COEFFICIENT : ALPHA. *\nC\n DEN = SUM * TH(2) - TH(1) ** 2\n BETA = (SUM * TH(3) - TH(1) * TH(4)) / DEN\n ALPHA = (TH(2) * TH(4) - TH(1) * TH(3)) / DEN\nC\n RETURN\n END\n", "meta": {"hexsha": "fe97a6819811e00d240bb306ac5548b1d264587b", "size": 6169, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "stsdas/pkg/analysis/statistics/twokm/schmit.f", "max_stars_repo_name": "iraf-community/stsdas", "max_stars_repo_head_hexsha": "043c173fd5497c18c2b1bfe8bcff65180bca3996", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-12-20T10:06:48.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-20T10:06:48.000Z", "max_issues_repo_path": "stsdas/pkg/analysis/statistics/twokm/schmit.f", "max_issues_repo_name": "spacetelescope/stsdas_stripped", "max_issues_repo_head_hexsha": "043c173fd5497c18c2b1bfe8bcff65180bca3996", "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": "stsdas/pkg/analysis/statistics/twokm/schmit.f", "max_forks_repo_name": "spacetelescope/stsdas_stripped", "max_forks_repo_head_hexsha": "043c173fd5497c18c2b1bfe8bcff65180bca3996", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-10-12T20:01:16.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-19T08:04:30.000Z", "avg_line_length": 49.352, "max_line_length": 78, "alphanum_fraction": 0.3242016534, "num_tokens": 1565, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582497090321, "lm_q2_score": 0.7341195385342971, "lm_q1q2_score": 0.6830675809018245}} {"text": " REAL*8 FUNCTION GHANGL(TSEC50,KPRECES)\n IMPLICIT REAL*8(A-H,O-Z)\nC\nC THIS ROUTINE COMPUTES THE GREENWICH HOUR ANGLE AT A GIVEN TIME FOR\nC EITHER A FIXED OR PRECESSING EQUINOX.\nC\nC VARIABLE DIM TYPE I/O DESCRIPTION\nC -------- --- ---- --- -----------\nC\nC TSEC50 1 R*8 I THE TIME FOR WHICH THE GREENWICH HOUR ANGLE \nC IS WANTED. UNITS ARE MEAN SOLAR SECONDS \nC SINCE 1/1/50, 0.0 HRS UT.\nC TSEC50 MAY BE ANY VALUE, + OR -.\nC\nC TSEC50 SHOULD BE COMPUTED USING THE JULIAN\nC DATE(UT) OF INTEREST MINUS THE JULIAN DATE\nC OF 1/1/50 0.0 (=2433282.5) MULTIPLIED BY\nC 86400. THAT IS, DO NOT ADD IN LEAP SECONDS.\nC\nC KPRECES 1 I*4 I A FLAG INDICATING THE COORDINATE SYSTEM \nC TO WHICH THE HOUR ANGLE IS REFERENCED.\nC = 0, MEAN EQUATOR AND EQUINOX OF 1950.0\nC = OTHERWISE, MEAN OF DATE.\nC\nC GHANGL 1 R*8 O THE GREENWICH HOUR ANGLE MEASURED IN A \nC POSITIVE SENSE(EASTWARD) IN THE EQUATORIAL \nC PLANE FROM THE EQUINOX(X-AXIS) TO THE \nC GREENWICH MERIDIAN. IN RADIANS.\nC\nC**********************************************************************\nC\nC CODED BY C PETRUZZO, 11/82.\nC MODIFIED.... 7/83. CJP. COMMENT CLARIFICATION. CODE CLEANUP, AND\nC CORRECTION TO METHOD OF HANDLING THE\nC NON-PRECESSING EQUINOX.\nC\nC**********************************************************************\nC\nC\nC METHOD: AS IN THE ASTRONOMICAL ALMANAC, 1983, PAGE B-6. THOSE \nC FORMULAE ARE FOR MEAN OF DATE.\nC\n REAL*8 SECDAY/86400.D0/,SECHR/3600.D0/,MINHR/60.D0/\n REAL*8 TWOPI/ 6.283185307179586D0 /\n REAL*8 DEGRAD/ 57.29577951308232D0 /\n INTEGER INIT/1/\nC\nC\n IF(INIT.NE.0) THEN ! INITIALIZATION ON FIRST CALL.\n INIT=0\n CENT50=0.5D0 ! CENTURIES 1/0/1900, 12 HR, TO 1/1/50, 0 HR (UT).\n RADHR = 15.D0/DEGRAD ! 15 (DEG/HR) / (DEG/RAD)= RAD/HR.\nC SET COEFFICIENTS FOR RU FORMULA, MEAN OF DATE CASE.\n C1=18.D0 + 38.D0/MINHR + 45.836D0/SECHR\n C2=8640184.542D0/SECHR\n C3=0.0929D0/SECHR\n END IF\nC\nC CENT = FRAC OF A JULIAN CENTURY(MEAN SOLAR DAYS) FROM 1/0/00, 12 HR\n CENT = (TSEC50/SECDAY)/36525.D0 + CENT50 \nC UT = UNIVERSAL TIME. HOURS.\n UT = DMOD(TSEC50/SECHR,24.D0) \nC RU = RACN OF FICTITIOUS MEAN SUN. HOURS.\n RU = C1 + C2*CENT + C3*CENT*CENT\nC GMST = GREENWICH MEAN SIDEREAL TIME(GHA OF MEAN EQNX OF DATE). HRS.\n GMST = UT + 12.D0 + RU\nC GHA = GREENWICH HOUR ANGLE. RADIANS.\n GHA = GMST * RADHR\nC\nC GHA IS NOW IN MEAN OF DATE. CONVERT TO MEAN OF 1950.0 IF NEEDED.\n IF(KPRECES.EQ.0) THEN\n SHIFT=PRECES50(TSEC50,1)\n ELSE\n SHIFT=0.D0\n END IF\n GHA = GHA - SHIFT\nC\nC WRAP IT UP.\n GHANGL = DMOD(GHA,TWOPI)\nC\n RETURN\n END\n", "meta": {"hexsha": "5d9bc4a385bc4c6970ea6f0e9947d9f3c89c9789", "size": 3094, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "gsc-13083/ghangl.for", "max_stars_repo_name": "SteveDoyle2/nasa-cosmic", "max_stars_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_stars_repo_licenses": ["BSD-Source-Code"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2015-03-14T07:26:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-16T12:23:17.000Z", "max_issues_repo_path": "gsc-13083/ghangl.for", "max_issues_repo_name": "SteveDoyle2/nasa-cosmic", "max_issues_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_issues_repo_licenses": ["BSD-Source-Code"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gsc-13083/ghangl.for", "max_forks_repo_name": "SteveDoyle2/nasa-cosmic", "max_forks_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_forks_repo_licenses": ["BSD-Source-Code"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2016-02-12T22:18:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-08T17:46:54.000Z", "avg_line_length": 37.2771084337, "max_line_length": 72, "alphanum_fraction": 0.5355526826, "num_tokens": 1051, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582497090322, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.683067575489296}} {"text": "************************************************************************\n* Author: R.K. Ellis & GZ *\n************************************************************************\n\n double complex function qlL0(x,y)\n implicit none\n include 'qlconstants.f'\n double complex qllnrat\n double precision x,y,denom\n denom=one-x/y\n if (abs(denom) .lt. 1d-7) then\n qlL0=-cone-dcmplx(denom*(half+denom/3d0))\n else\n qlL0=qllnrat(x,y)/dcmplx(denom)\n endif\n return\n end\n\n double complex function qlL1(x,y)\n implicit none\n include 'qlconstants.f'\n double precision x,y,denom\n double complex qlL0\n denom=one-x/y\n if (abs(denom) .lt. 1d-7) then\n qlL1=-half*cone-dcmplx(denom/3d0*(one+0.75d0*denom))\n else\n qlL1=(qlL0(x,y)+cone)/dcmplx(denom)\n endif\n return\n end\n\n double complex function qlL2(x,y)\n implicit none\n include 'qlconstants.f'\n double complex qllnrat\n double precision x,y,r,denom\n r=x/y\n denom=one-r\n if (abs(denom) .lt. 1d-7) then\n qlL2=(dcmplx(10d0)+denom*(dcmplx(15d0)+dcmplx(18d0)*denom))\n . /dcmplx(60d0)\n else\n qlL2=(qllnrat(x,y)-dcmplx(0.5d0*(r-1d0/r)))/dcmplx(denom)**3\n endif \n return\n end\n\n double complex function qlLsm1(x1,y1,x2,y2)\n implicit none\n include 'qlconstants.f'\n double precision x1,x2,y1,y2\n double complex qlLnrat,qlLi2omrat\n\n qlLsm1=qlLi2omrat(x1,y1)+qlLi2omrat(x2,y2)\n . +qllnrat(x1,y1)*qllnrat(x2,y2)-dcmplx(pisqo6)\n return\n end\n\n\n double complex function qlLsm1_2mht(s,t,p1sq,p2sq)\n implicit none\n include 'qlconstants.f'\n double precision s,t,p1sq,p2sq\n double complex qlLnrat,qlLi2omrat\n\n qlLsm1_2mht=\n & -qlLi2omrat(-p1sq,-t)\n & -qlLi2omrat(-p2sq,-t)\n & +half*(qllnrat(-s,-p1sq)*qllnrat(-s,-p2sq)-qllnrat(-s,-t)**2)\n return\n end\n\n\n double complex function qlLsm1_2me(s,t,p1sq,p3sq)\n implicit none\n include 'qlconstants.f'\n double precision s,t,p1sq,p3sq\n double complex qlLnrat,Li2(5),qlLi2omrat,qlLi2omx2\n\n Li2(1)=qlLi2omrat(-p1sq,-s)\n Li2(2)=qlLi2omrat(-p1sq,-t)\n Li2(3)=qlLi2omrat(-p3sq,-s)\n Li2(4)=qlLi2omrat(-p3sq,-t)\n Li2(5)=qlLi2omx2(-p1sq,-p3sq,-s,-t)\n qlLsm1_2me=Li2(5)-Li2(1)-Li2(2)-Li2(3)-Li2(4)\n . -half*qlLnrat(-s,-t)**2\n return\n end\n\n", "meta": {"hexsha": "502d39667f4d52f71b68bc52ff106dcf982a6ab5", "size": 2490, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "vendor/IREGI/src/qcdloop/ql/qlfunctions.f", "max_stars_repo_name": "valassi/mg5amc_test", "max_stars_repo_head_hexsha": "2e04f23353051f64e1604b23105fe3faabd32869", "max_stars_repo_licenses": ["NCSA"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-10-23T14:37:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-22T20:59:02.000Z", "max_issues_repo_path": "vendor/IREGI/src/qcdloop/ql/qlfunctions.f", "max_issues_repo_name": "valassi/mg5amc_test", "max_issues_repo_head_hexsha": "2e04f23353051f64e1604b23105fe3faabd32869", "max_issues_repo_licenses": ["NCSA"], "max_issues_count": 64, "max_issues_repo_issues_event_min_datetime": "2015-06-24T15:08:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-25T04:59:32.000Z", "max_forks_repo_path": "vendor/IREGI/src/qcdloop/ql/qlfunctions.f", "max_forks_repo_name": "valassi/mg5amc_test", "max_forks_repo_head_hexsha": "2e04f23353051f64e1604b23105fe3faabd32869", "max_forks_repo_licenses": ["NCSA"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2015-05-04T22:15:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-06T10:04:40.000Z", "avg_line_length": 27.3626373626, "max_line_length": 77, "alphanum_fraction": 0.5514056225, "num_tokens": 900, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582477806521, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6830675632485769}} {"text": "program Newtonxiu\n\treal*8 x(2),t,g(2),A(2,2),Gni(2,2),b(2),f,p(2),ans,aro(2)\n\tdata x /0,0/\n\tdata A /8,0,0,4/\n\tdata Gni /0.125,0.0,0.0,0.25/\n\tdata b /9,-3/\n\topen(13,file=\"Newtonxiu\")\n\twrite(13,\"(5A13)\")\"f\",\"x1\",\"x2\",\"g1\",\"g2\"\n\tdo\n\tg=matmul(A,x)+b\n\tf=10+x(1)+x(2)+4*(x(1)+1)**2+2*(x(2)-1)**2\n\twrite(13,\"(5f13.6)\")f,x,g\n\tcall onedimenmul(g,g,2,ans)\n\tif(ans<0.01) exit\n\tp=matmul(-Gni,g)\n\taro=matmul(p,A)\n\tt=ans\n\tcall onedimenmul(aro,g,2,ans)\n\tt=t/ans\n\tx=x-t*p\n\tend do\n\tclose(13)\nend program Newtonxiu\n\n\tsubroutine onedimenmul(m1,m2,n,ans)\n\tinteger n\n\treal*8 m1(n),m2(n),ans\n\tans=0\n\tdo i=1,n\n\t\tans=m1(i)*m2(i)+ans\n\tend do\n\tend subroutine onedimenmul\n", "meta": {"hexsha": "da110c68751dddf3a2373219fabdf2a93e4e70e4", "size": 645, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Newtonxiu.f90", "max_stars_repo_name": "DearDon/Optimization", "max_stars_repo_head_hexsha": "f22a95bc1317aff69664516c495d94831dabce51", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Newtonxiu.f90", "max_issues_repo_name": "DearDon/Optimization", "max_issues_repo_head_hexsha": "f22a95bc1317aff69664516c495d94831dabce51", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Newtonxiu.f90", "max_forks_repo_name": "DearDon/Optimization", "max_forks_repo_head_hexsha": "f22a95bc1317aff69664516c495d94831dabce51", "max_forks_repo_licenses": ["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.5454545455, "max_line_length": 58, "alphanum_fraction": 0.6093023256, "num_tokens": 321, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505428129514, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6829342576356539}} {"text": "! --------------------- BEGIN YINTRF ------------------------------------\r\n function yintrf( x, xin, yin, n)\r\n!\r\n! returns an interpolated value (yintrf) based on straight line\r\n! interpolation of the data in xin and yin.\r\n\r\n! Needs Numerical recipe routine locate\r\n\r\n!\r\n! dates: 3/14/85 - written\r\n! 11/30/95 - substituted LOCATE instead of starting from beginning\r\n! each time\r\n! 03/13/96 - added code to deal with xin increasing or decreasing\r\n! 12/12/00 - Stripped off \"locate.for\"\r\n! 04/28/15 - Replaced comment characters * or C with ! (The Fortran 95 standard)\r\n\r\n dimension xin(1), yin(1)\r\n logical incrs\r\n\r\n! Is xin increasing or decreasing?\r\n incrs = .true.\r\n if (xin(n) .lt. xin(1)) incrs = .false.\r\n\r\n! Set value if x is outside the range of xin:\r\n if (incrs) then\r\n if ( x .le. xin(1) ) then\r\n yintrf = yin(1)\r\n return\r\n end if\r\n if ( x .ge. xin(n) ) then\r\n yintrf = yin(n)\r\n return\r\n end if \r\n else\r\n if ( x .ge. xin(1) ) then\r\n yintrf = yin(1)\r\n return\r\n end if\r\n if ( x .le. xin(n) ) then\r\n yintrf = yin(n)\r\n return\r\n end if \r\n end if\r\n\r\n! Locate the proper cell and interpolate:\r\n call locate(xin, n, x, j)\r\n yintrf = yin(j) + (x-xin(j))*(yin(j+1) - yin(j))/\r\n * (xin(j+1)-xin(j))\r\n\r\n return\r\n end\r\n! --------------------- END YINTRF ------------------------------------\r\n\r\n", "meta": {"hexsha": "2ddce6f3135c3a92b0d2427eedff1b8f92fd35dc", "size": 1548, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "bbp/src/usgs/fas/yintrf.for", "max_stars_repo_name": "kevinmilner/bbp", "max_stars_repo_head_hexsha": "d9ba291b123be4e85f76317ef23600a339b2354d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2017-10-31T09:16:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T23:44:29.000Z", "max_issues_repo_path": "bbp/src/usgs/fas/yintrf.for", "max_issues_repo_name": "kevinmilner/bbp", "max_issues_repo_head_hexsha": "d9ba291b123be4e85f76317ef23600a339b2354d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 37, "max_issues_repo_issues_event_min_datetime": "2017-05-23T15:15:35.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-05T09:13:18.000Z", "max_forks_repo_path": "bbp/src/usgs/fas/yintrf.for", "max_forks_repo_name": "kevinmilner/bbp", "max_forks_repo_head_hexsha": "d9ba291b123be4e85f76317ef23600a339b2354d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2017-09-21T17:43:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-29T06:34:30.000Z", "avg_line_length": 28.6666666667, "max_line_length": 88, "alphanum_fraction": 0.476744186, "num_tokens": 440, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422644, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6829342556950037}} {"text": " \nc****************************************************************\n\n\tsubroutine matvec(r_t,r_v,r_w)\n\nc****************************************************************\nc**\nc**\tFILE NAME: matvec.f\nc**\nc** DATE WRITTEN: 7/20/90\nc**\nc** PROGRAMMER:Scott Hensley\nc**\nc** \tFUNCTIONAL DESCRIPTION: The subroutine takes a 3x3 matrix \nc** and a 3x1 vector a multiplies them to return another 3x1\nc**\tvector.\nc**\nc** ROUTINES CALLED:none\nc** \nc** NOTES: none\nc**\nc** UPDATE LOG:\nc**\nc*****************************************************************\n\n \timplicit none\n\nc\tINPUT VARIABLES:\n \treal*8 r_t(3,3) !3x3 matrix\n real*8 r_v(3) !3x1 vector\n \nc \tOUTPUT VARIABLES:\n real*8 r_w(3) !3x1 vector\n\nc\tLOCAL VARIABLES:none\n\nc \tPROCESSING STEPS:\n\nc compute matrix product\n\n\tr_w(1) = r_t(1,1)*r_v(1) + r_t(1,2)*r_v(2) + r_t(1,3)*r_v(3)\n\tr_w(2) = r_t(2,1)*r_v(1) + r_t(2,2)*r_v(2) + r_t(2,3)*r_v(3)\n\tr_w(3) = r_t(3,1)*r_v(1) + r_t(3,2)*r_v(2) + r_t(3,3)*r_v(3)\n \n end \n \n\n", "meta": {"hexsha": "de9a24f5c072069beb02afa859c1f99af8de4b09", "size": 1113, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "contrib/alos2proc_f/src/matvec.f", "max_stars_repo_name": "vincentschut/isce2", "max_stars_repo_head_hexsha": "1557a05b7b6a3e65abcfc32f89c982ccc9b65e3c", "max_stars_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_stars_count": 1133, "max_stars_repo_stars_event_min_datetime": "2022-01-07T21:24:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-07T21:33:08.000Z", "max_issues_repo_path": "contrib/alos2proc_f/src/matvec.f", "max_issues_repo_name": "vincentschut/isce2", "max_issues_repo_head_hexsha": "1557a05b7b6a3e65abcfc32f89c982ccc9b65e3c", "max_issues_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_issues_count": 276, "max_issues_repo_issues_event_min_datetime": "2019-02-10T07:18:28.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:45:55.000Z", "max_forks_repo_path": "contrib/alos2proc_f/src/matvec.f", "max_forks_repo_name": "vincentschut/isce2", "max_forks_repo_head_hexsha": "1557a05b7b6a3e65abcfc32f89c982ccc9b65e3c", "max_forks_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_forks_count": 235, "max_forks_repo_forks_event_min_datetime": "2019-02-10T05:00:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T07:37:24.000Z", "avg_line_length": 23.1875, "max_line_length": 66, "alphanum_fraction": 0.4357592093, "num_tokens": 362, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505453836382, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.682934254588082}} {"text": "SUBROUTINE twofft(data1,data2,fft1,fft2)\r\n USE nrtype\n USE nrutil, ONLY : assert,assert_eq\r\n USE nr, ONLY : four1\r\n IMPLICIT NONE\r\n REAL(SP), DIMENSION(:), INTENT(IN) :: data1,data2\r\n COMPLEX(SPC), DIMENSION(:), INTENT(OUT) :: fft1,fft2\r\n INTEGER(I4B) :: n,n2\r\n COMPLEX(SPC), PARAMETER :: C1=(0.5_sp,0.0_sp), C2=(0.0_sp,-0.5_sp)\r\n COMPLEX, DIMENSION(size(data1)/2+1) :: h1,h2\r\n n=assert_eq(size(data1),size(data2),size(fft1),size(fft2),'twofft')\r\n call assert(iand(n,n-1)==0, 'n must be a power of 2 in twofft')\r\n fft1=cmplx(data1,data2,kind=spc)\r\n call four1(fft1,1)\r\n fft2(1)=cmplx(aimag(fft1(1)),0.0_sp,kind=spc)\r\n fft1(1)=cmplx(real(fft1(1)),0.0_sp,kind=spc)\r\n n2=n/2+1\r\n h1(2:n2)=C1*(fft1(2:n2)+conjg(fft1(n:n2:-1)))\r\n h2(2:n2)=C2*(fft1(2:n2)-conjg(fft1(n:n2:-1)))\r\n fft1(2:n2)=h1(2:n2)\r\n fft1(n:n2:-1)=conjg(h1(2:n2))\r\n fft2(2:n2)=h2(2:n2)\r\n fft2(n:n2:-1)=conjg(h2(2:n2))\r\nEND SUBROUTINE twofft\r\n", "meta": {"hexsha": "ce18e71af48c53aacf54c7197ccf68ddd9643fd1", "size": 924, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "inversor/database/NICOLE/numerical_recipes/twofft.f90", "max_stars_repo_name": "aasensio/DeepLearning", "max_stars_repo_head_hexsha": "71838115ce93e0ca96c8314cff3f07de1d64c235", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "inversor/database/NICOLE/numerical_recipes/twofft.f90", "max_issues_repo_name": "aasensio/DeepLearning", "max_issues_repo_head_hexsha": "71838115ce93e0ca96c8314cff3f07de1d64c235", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "inversor/database/NICOLE/numerical_recipes/twofft.f90", "max_forks_repo_name": "aasensio/DeepLearning", "max_forks_repo_head_hexsha": "71838115ce93e0ca96c8314cff3f07de1d64c235", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.96, "max_line_length": 70, "alphanum_fraction": 0.6341991342, "num_tokens": 422, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422644, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6829342457185601}} {"text": "program entropy\n USE yepLibrary, ONLY: yepLibrary_Init, yepLibrary_Release, yepLibrary_GetTimerFrequency, yepLibrary_GetTimerTicks\n USE yepCore, ONLY: yepCore_DotProduct_V64fV64f_S64f\n USE yepMath, ONLY: yepMath_Log_V64f_V64f\n USE ISO_C_BINDING, ONLY : C_SIZE_T, C_INT64_T, C_INT, C_DOUBLE\n implicit none\n INTEGER(C_SIZE_T), PARAMETER :: n = 1024*1024*16\n INTEGER(C_INT64_T) :: ticksStart, ticksEnd, frequency\n real(C_DOUBLE) :: p(n), logP(n), H\n integer(C_INT) :: s\n s = yepLibrary_Init()\n s = yepLibrary_GetTimerFrequency(frequency)\n call RANDOM_NUMBER(p)\n\n s = yepLibrary_GetTimerTicks(ticksStart)\n s = yepMath_Log_V64f_V64f(p, logP, n)\n s = yepCore_DotProduct_V64fV64f_S64f(p, logP, H, n)\n H = -H\n s = yepLibrary_GetTimerTicks(ticksEnd)\n print*, \"Yeppp!\"\n print*, \" Entropy =\", H\n print*, \" Time =\", REAL(ticksEnd - ticksStart) / REAL(frequency)\n\n s = yepLibrary_GetTimerTicks(ticksStart)\n H = -DOT_PRODUCT(p, LOG(p))\n s = yepLibrary_GetTimerTicks(ticksEnd)\n print*, \"Naive\"\n print*, \" Entropy =\", H\n print*, \" Time =\", REAL(ticksEnd - ticksStart) / REAL(frequency)\n s = yepLibrary_Release()\nend\n", "meta": {"hexsha": "a434bf315f543b2065994963185b2aa27d14830a", "size": 1193, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/fortran/sources/Entropy.f90", "max_stars_repo_name": "wdv4758h/Yeppp-", "max_stars_repo_head_hexsha": "deeca59a88bc2b014be802fd575757f7c26c180e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 30, "max_stars_repo_stars_event_min_datetime": "2015-09-18T00:52:22.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-03T17:44:30.000Z", "max_issues_repo_path": "examples/fortran/sources/Entropy.f90", "max_issues_repo_name": "rguthrie3/Yeppp-Mirror", "max_issues_repo_head_hexsha": "23cc725a7489d376558bef3e92e31fda014b6c47", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-02-09T04:53:29.000Z", "max_issues_repo_issues_event_max_datetime": "2017-02-09T04:53:29.000Z", "max_forks_repo_path": "examples/fortran/sources/Entropy.f90", "max_forks_repo_name": "rguthrie3/Yeppp-Mirror", "max_forks_repo_head_hexsha": "23cc725a7489d376558bef3e92e31fda014b6c47", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2017-02-09T03:05:32.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-17T06:50:19.000Z", "avg_line_length": 37.28125, "max_line_length": 117, "alphanum_fraction": 0.6881810562, "num_tokens": 391, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008904, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6829342418372598}} {"text": "\nsubroutine fort_set_rhs(rhs, lo, hi, nc, dx, a, b, sigma, w) bind(c)\n integer, intent(in) :: lo(2), hi(2)\n integer, intent(in), value :: nc\n double precision, intent(in), value :: a, b, sigma, w\n double precision, intent(inout) :: rhs(lo(1):hi(1),lo(2):hi(2),nc)\n double precision, intent(in) :: dx(2)\n\n integer :: i, j, n\n double precision :: x, y, r, pi, tpi, fpi, fac, theta, beta, dbdrfac\n\n pi = 4.d0 * datan(1.d0)\n tpi = 2.0d0 * pi\n fpi = 4.0d0 * pi\n fac = 2.0d0 * tpi**2\n \n theta = 0.5d0*log(3.0) / w\n\n do n = 1, nc\n do j = lo(2), hi(2)\n y = (dble(j)+0.5d0)*dx(2)\n do i = lo(1), hi(1)\n x = (dble(i)+0.5d0)*dx(1)\n \n r = sqrt((x-0.5d0)**2+(y-0.5d0)**2)\n\n beta = (sigma-1.d0)/2.d0*tanh(theta*(r-0.25d0)) + (sigma+1.d0)/2.d0\n beta = beta * b\n dbdrfac = (sigma-1.d0)/2.d0/(cosh(theta*(r-0.25d0)))**2 * theta/r\n dbdrfac = dbdrfac * b\n \n rhs(i,j,n) = beta*fac*(sin(tpi*x) * sin(tpi*y) &\n & + sin(fpi*x) * sin(fpi*y)) &\n & + dbdrfac*((x-0.5d0)*(-tpi*cos(tpi*x) * sin(tpi*y) &\n & - pi*cos(fpi*x) * sin(fpi*y)) &\n & + (y-0.5d0)*(-tpi*sin(tpi*x) * cos(tpi*y) &\n & - pi*sin(fpi*x) * cos(fpi*y))) &\n & + a * ( sin(tpi*x) * sin(tpi*y) &\n & + 0.25d0 * sin(fpi*x) * sin(fpi*y))\n end do\n end do\n end do\nend subroutine fort_set_rhs\n\nsubroutine fort_set_coef(xcoef, xlo, xhi, ycoef, ylo, yhi, nc, dx, sigma, w) bind(c)\n integer, intent(in) :: xlo(2), xhi(2), ylo(2), yhi(2)\n integer, intent(in), value :: nc\n double precision, intent(in), value :: sigma, w\n double precision, intent(inout) :: xcoef(xlo(1):xhi(1),xlo(2):xhi(2),nc)\n double precision, intent(inout) :: ycoef(ylo(1):yhi(1),ylo(2):yhi(2),nc)\n double precision, intent(in) :: dx(2)\n\n integer :: i, j, n\n double precision :: theta, x, y, r\n\n theta = 0.5d0*log(3.0) / w\n\n do n = 1, nc\n do j = xlo(2), xhi(2)\n y = (dble(j)+0.5d0)*dx(2)\n do i = xlo(1), xhi(1)\n x = (dble(i))*dx(1)\n \n r = sqrt((x-0.5d0)**2 + (y-0.5d0)**2)\n\n xcoef(i,j,n) = (sigma-1.d0)/2.d0*tanh(theta*(r-0.25d0)) &\n + (sigma+1.d0)/2.d0\n end do\n end do\n\n do j = ylo(2), yhi(2)\n y = (dble(j))*dx(2)\n do i = ylo(1), yhi(1)\n x = (dble(i)+0.5d0)*dx(1)\n \n r = sqrt((x-0.5d0)**2 + (y-0.5d0)**2)\n\n ycoef(i,j,n) = (sigma-1.d0)/2.d0*tanh(theta*(r-0.25d0)) &\n + (sigma+1.d0)/2.d0\n end do\n end do\n end do\nend subroutine fort_set_coef\n", "meta": {"hexsha": "191700db7bf38ace3f6e2e21defade9a90f2992c", "size": 2778, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorials/ForkJoin/MLMG/ff.f90", "max_stars_repo_name": "ylunalin/amrex", "max_stars_repo_head_hexsha": "5715b2fc8a77e0db17bfe7907982e29ec44811ca", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 79, "max_stars_repo_stars_event_min_datetime": "2015-08-03T18:29:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-15T11:42:40.000Z", "max_issues_repo_path": "Tutorials/ForkJoin/MLMG/ff.f90", "max_issues_repo_name": "ylunalin/amrex", "max_issues_repo_head_hexsha": "5715b2fc8a77e0db17bfe7907982e29ec44811ca", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": 22, "max_issues_repo_issues_event_min_datetime": "2016-06-15T20:46:49.000Z", "max_issues_repo_issues_event_max_datetime": "2018-09-10T21:33:10.000Z", "max_forks_repo_path": "Tutorials/ForkJoin/MLMG/ff.f90", "max_forks_repo_name": "ylunalin/amrex", "max_forks_repo_head_hexsha": "5715b2fc8a77e0db17bfe7907982e29ec44811ca", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": 48, "max_forks_repo_forks_event_min_datetime": "2015-08-05T02:19:33.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-18T12:33:14.000Z", "avg_line_length": 33.0714285714, "max_line_length": 84, "alphanum_fraction": 0.4550035997, "num_tokens": 1095, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240194661944, "lm_q2_score": 0.7279754371026368, "lm_q1q2_score": 0.6829312431273854}} {"text": "!\r\n! The Laboratory of Algorithms\r\n!\r\n! The MIT License\r\n!\r\n! Copyright 2011-2015 Andrey Pudov.\r\n!\r\n! Permission is hereby granted, free of charge, to any person obtaining a copy\r\n! of this software and associated documentation files (the 'Software'), to deal\r\n! in the Software without restriction, including without limitation the rights\r\n! to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n! copies of the Software, and to permit persons to whom the Software is\r\n! furnished to do so, subject to the following conditions:\r\n!\r\n! The above copyright notice and this permission notice shall be included in\r\n! all copies or substantial portions of the Software.\r\n!\r\n! THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r\n! THE SOFTWARE.\r\n!\r\n\r\n! Largest palindrome product\r\n!\r\n! A palindromic number reads the same both ways. The largest palindrome made\r\n! from the product of two 2-digit numbers is 9009 = 91x99.?\r\n! Find the largest palindrome made from the product of two 3-digit numbers.\r\nmodule MPEProblem4\r\n\r\n implicit none\r\n private\r\n\r\n type, public :: TPEProblem4\r\n contains\r\n procedure, nopass :: present\r\n end type\r\ncontains\r\n subroutine present\r\n write (*, '(A)') 'Problem 4. Largest palindrome product.'\r\n\r\n write (*, '(A, I)') 'Palindrome 1: ', palindrome()\r\n end subroutine\r\n\r\n function palindrome()\r\n integer palindrome\r\n integer current\r\n integer number1\r\n integer number2\r\n\r\n integer number\r\n integer digit\r\n integer remaining\r\n\r\n palindrome = 0\r\n\r\n do number1 = 999, 100, -1\r\n do number2 = 999, 100, -1\r\n current = number1 * number2\r\n\r\n number = current\r\n remaining = 0\r\n do while (number .gt. 0)\r\n digit = mod(number, 10)\r\n remaining = remaining * 10 + digit\r\n number = number / 10\r\n end do\r\n\r\n if (remaining .eq. current) then\r\n if (current .gt. palindrome) then\r\n palindrome = current\r\n end if\r\n end if\r\n end do\r\n end do\r\n end function\r\nend module\r\n", "meta": {"hexsha": "4204604be7c68dcf659ddb775c4899d1b5ceb08f", "size": 2676, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Problems/ProjectEuler/Problem4.f", "max_stars_repo_name": "andreypudov/Algorithms", "max_stars_repo_head_hexsha": "9693efa0abed30a38fcb9c3f7eebbd5b92b734f5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2016-02-15T14:45:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-01T22:42:32.000Z", "max_issues_repo_path": "Problems/ProjectEuler/Problem4.f", "max_issues_repo_name": "jlokimlin/Algorithms", "max_issues_repo_head_hexsha": "d981990394d940fd999334b0b65b118567670d1a", "max_issues_repo_licenses": ["MIT"], "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/ProjectEuler/Problem4.f", "max_forks_repo_name": "jlokimlin/Algorithms", "max_forks_repo_head_hexsha": "d981990394d940fd999334b0b65b118567670d1a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2016-02-24T15:47:02.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-01T10:45:03.000Z", "avg_line_length": 33.037037037, "max_line_length": 80, "alphanum_fraction": 0.6225710015, "num_tokens": 578, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324983301568, "lm_q2_score": 0.8376199552262967, "lm_q1q2_score": 0.6828550087503279}} {"text": "!--------------------------------------------------\n!PHY1038 Assignment 4 - Matrix Geometry \n!URN 6309823 - Penguin Lab Group 1\n!May 5th 2015\n!--------------------------------------------------\n\nPROGRAM Matrix_Geometry\n IMPLICIT NONE\n\n REAL :: theta,j,k,l,h,m,n,xcom,ycom,alpha\n REAL, DIMENSION(1:3) :: a,b,c,e,i,p,newa,newb,newc\n \n\n !Step 1\n\n OPEN(unit=20,file='rotate.dat')\n \n WRITE(6,*) \"The x value of the initial point to be rotated is:\"\n READ(5,*) m\n\n WRITE(6,*) \"The y value of the initial point to be rotated is:\"\n READ(5,*) n\n\n !p=initial point to be rotated\n p=(/m,n,0.0/)\n\n WRITE(6,*) \"Please input a value for the angle of rotation theta in radians:\"\n READ(5,*) theta\n WRITE(6,*) \" \"\n WRITE(6,*) \" \"\n \n !a = [ 1 1 1 ]\n !b = [ 2 1 1 ]\n !c = [ 2 2 1 ]\n\n a=(/1.0,1.0,1.0/)\n b=(/2.0,1.0,1.0/)\n c=(/2.0,2.0,1.0/)\n e=(/1.0,1.0,1.0/)\n\n WRITE(6,*) \"The angle through which the vectors are rotated is theta.\"\n WRITE(6,*) \" \"\n WRITE(6,*) \"theta=\", theta, \"radians\"\n WRITE(6,*) \" \"\n\n !This inputs the translated points and the original points to the file rotate.dat\n WRITE(20,*) f(a,theta), a, f(p,theta), p\n WRITE(20,*) f(b,theta), b\n WRITE(20,*) f(c,theta), c\n WRITE(20,*) f(e,theta), e\n\n WRITE(6,*) \"Plot using GNU PLOT.\"\n\n !Write in Terminal 'gnuplot' then press ENTER\"\n\n !In order to plot the vector inputed by the user, write in the terminal:\n !plot \"rotate.dat\" using 7:8, \"rotate.dat\" using 10:11\n !then press ENTER\n\n !In order to plot the triangle as a test, write in the terminal:\n !plot \"rotate.dat\" using 1:2 with lines, \"rotate.dat\" using 4:5 with lines \n !then press ENTER\n \n\n !Step 2\n\n OPEN(unit=19,file='translate.dat')\n\n WRITE(6,*) \"Please input the x value of the initial point to be translated:\"\n READ(5,*) l\n WRITE(6,*) \" \"\n WRITE(6,*) \"Please input the y value of the initial point to be translated:\"\n READ(5,*) h\n WRITE(6,*) \" \"\n\n !i=initial point to be translated\n i=(/l,h,1.0/)\n \n WRITE(6,*) \" \"\n WRITE(6,*) \"The shape is translated in the x axis by:\"\n READ(5,*) j\n WRITE(6,*) \" \"\n WRITE(6,*) \"The shape is translated in the y axis by:\"\n READ(5,*) k\n WRITE(6,*) \" \"\n WRITE(6,*) \" \"\n\n !This inputs the translated points and the original points to the file translate.dat\n WRITE(19,*) g(a,k,j), a, i, g(i,k,j)\n WRITE(19,*) g(b,k,j), b\n WRITE(19,*) g(c,k,j), c\n WRITE(19,*) g(e,k,j), e\n \n WRITE(6,*) \"Plot using GNU PLOT.\"\n \n !Write in Terminal 'gnuplot' then press ENTER\"\n\n !In order to plot the vector inputed by the user, write in the terminal:\n !plot \"translate.dat\" using 7:8, \"translate.dat\" using 10:11\n !then press ENTER\n\n !In order to plot the triangle as a test, write in the terminal:\n !plot \"translate.dat\" using 1:2 with lines, \"translate.dat\" using 4:5 with lines \n !then press ENTER\n\n\n !Step 3\n \n OPEN(unit=18,file='step3.dat')\n \n !The current centre of mass of the triangle is: (\",xcom,\",\",ycom,\")\"\n xcom=(a(1)+b(1)+c(1))/3\n ycom=(a(2)+b(2)+c(2))/3\n\n WRITE(6,*) \"Please input a value for the angle of rotation 'alpha' in radians:\"\n READ(5,*) alpha\n WRITE(6,*) \" \"\n WRITE(6,*) \" \"\n\n newa=o(a,xcom,ycom,alpha)\n newb=o(b,xcom,ycom,alpha)\n newc=o(c,xcom,ycom,alpha)\n\n !This inputs the points rotated about the triangle's centre of mass and the original points to the file step3.dat\n WRITE(18,*) a,newa\n WRITE(18,*) b,newb\n WRITE(18,*) c,newc\n WRITE(18,*) a,newa\n\n WRITE(6,*) \"The triangle has now been rotated about its centre of mass.\"\n WRITE(6,*) \" \" \n WRITE(6,*) \" \"\n WRITE(6,*) \"Write 'gnuplot 6309823.gnu' in the terminal to create a .png file displaying the original triangle and the rotate triangle.\"\n\n \n CONTAINS\n\n !Rotation Function\n FUNCTION f(a,theta)\n IMPLICIT NONE\n REAL, INTENT(IN) :: theta\n REAL, DIMENSION(1:3) :: a,f\n REAL, DIMENSION(1:3,1:3) :: d\n\n !d = [cos(theta) -sin(theta) 0]\n ! [sin(theta) cos(theta 0]\n ! [ 0 0 1]\n\n d= RESHAPE( (/cos(theta),sin(theta),0.0,-sin(theta),cos(theta),0.0,0.0,0.0,1.0/), (/3,3/) )\n f=matmul(a,d)\n END FUNCTION f\n \n\n !Translation Function\n FUNCTION g(i,j,k)\n IMPLICIT NONE\n REAL, INTENT(IN) :: k,j\n REAL, DIMENSION(1:3) :: g,i\n REAL, DIMENSION(1:3,1:3) :: h\n\n !h = [ 1 0 j ]\n ! [ 0 1 k ]\n ! [ 0 0 1 ]\n\n h= RESHAPE( (/1.0,0.0,j,0.0,1.0,k,0.0,0.0,1.0/), (/3,3/) )\n g=MATMUL(i,h)\n END FUNCTION g\n\n\n !Function which rotates a triangle about its centre of mass\n FUNCTION o(a,xcom,ycom,alpha)\n IMPLICIT NONE\n REAL, INTENT(IN) :: xcom,ycom,alpha,a(3)\n REAL, DIMENSION(1:3) :: z,y,o\n\n z=g(a,-xcom,-ycom)\n y=f(z,alpha)\n o=g(y,xcom,ycom)\n END FUNCTION o\n\nEND PROGRAM Matrix_Geometry\n", "meta": {"hexsha": "e07ac4d0f78be8499ccd8c87ee0c66cee627719e", "size": 5241, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "6309823-Matrix_Geometry.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-Matrix_Geometry.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-Matrix_Geometry.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.7967032967, "max_line_length": 142, "alphanum_fraction": 0.5306239267, "num_tokens": 1683, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.7606506635289836, "lm_q1q2_score": 0.6828325195882983}} {"text": "program lineclip\n\n use, intrinsic:: ieee_arithmetic\n use lineclip,only: Ccohensutherland, cohensutherland\n use assert, only: wp, assert_isclose\n\n implicit none\n\n real(wp) :: L(8)[*]\n\n call coarray_lineclip(L)\n! if(this_image()==1) print *,L\n\ncontains\n\nsubroutine coarray_lineclip(length)\n\n integer, parameter :: Np=8\n real(wp), dimension(Np) :: x1,x2,y1,y2\n real(wp),parameter :: xmin=1., ymax=5.,xmax=4., ymin=3.\n real(wp) :: truelength(Np) =[2.40370083, 3.,0.,0.,0.,0.,2.,2.5]\n real(wp) :: nan\n integer :: Ni, im, s0,s1\n real(wp),intent(out) :: length(Np)[*]\n\n Ni = num_images()\n im=this_image()\n\n nan = ieee_value(1.,ieee_quiet_nan)\n truelength(3:6) = nan\n\n x1=[0.,0.,0.,0.,0.,0.,0.,0.]\n y1=[0.,4.,1.,1.5,2.,2.5,3.0,3.5]\n x2=[4.,5.,1.,1.5,2.,2.5,3.0,3.5]\n y2=[6.,4.,1.,1.5,2.,2.5,3.0,3.5]\n\n!------ slice problem\n s0 = (im-1)*Np/Ni+1\n s1 = im*Np/Ni\n print '(A,I3,A,I3,A,I3)','Image',im,' solved over indices ',s0,':',s1\n!------- solve problem\n call cohensutherland(xmin,ymax,xmax,ymin, &\n x1(s0:s1), y1(s0:s1), x2(s0:s1), y2(s0:s1))\n\n length(s0:s1)[1] = hypot(x2(s0:s1) - x1(s0:s1), y2(s0:s1) - y1(s0:s1))\n!-------- finish up\n sync all\n\n if (im==1) then\n call assert_isclose(length, truelength, equal_nan=.true.)\n print *, 'OK coarray_lineclip'\n endif\n\n\nend subroutine coarray_lineclip\n\nend program\n", "meta": {"hexsha": "142165ece4e5840035f795f51b9b90515b79d968", "size": 1421, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "DemoCoarrayLineclip.f90", "max_stars_repo_name": "scivision/lineclipping-python-fortran", "max_stars_repo_head_hexsha": "55889ce97b14f69f475ec6e3c516f53529536d4f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2018-02-22T03:25:46.000Z", "max_stars_repo_stars_event_max_datetime": "2019-08-02T08:30:23.000Z", "max_issues_repo_path": "DemoCoarrayLineclip.f90", "max_issues_repo_name": "scivision/lineclipping-python-fortran", "max_issues_repo_head_hexsha": "55889ce97b14f69f475ec6e3c516f53529536d4f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-19T18:37:37.000Z", "max_issues_repo_issues_event_max_datetime": "2019-11-19T18:37:37.000Z", "max_forks_repo_path": "DemoCoarrayLineclip.f90", "max_forks_repo_name": "scivision/lineclipping-python-fortran", "max_forks_repo_head_hexsha": "55889ce97b14f69f475ec6e3c516f53529536d4f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-19T15:57:20.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-19T15:57:20.000Z", "avg_line_length": 24.5, "max_line_length": 74, "alphanum_fraction": 0.57565095, "num_tokens": 556, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813454, "lm_q2_score": 0.760650658103136, "lm_q1q2_score": 0.6828325188813409}} {"text": "PROGRAM PE2D_HF_FD\r\n USE PE2D_TYPE\n USE PE2D_VAR\n USE PE2D_AUX\n USE PE2D_GROUND\r\n IMPLICIT NONE\r\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\r\n WRITE(*,*) \"\"\r\n WRITE(*,*) \"================================================\"\r\n WRITE(*,*) \"========== Parabolic Equation Package ==========\"\r\n WRITE(*,*) \"================================================\"\r\n WRITE(*,*) \"\"\r\n WRITE(*,*) \"University of Bristol\"\r\n WRITE(*,*) \"Aerodynamics and Aeroacoustics Research Group\"\r\n WRITE(*,*) \"\"\r\n WRITE(*,*) \"Codor Khodr, July 2016\"\r\n WRITE(*,*) \"\"\r\n WRITE(*,*) \"================================================\"\r\n WRITE(*,*) \"\"\r\n WRITE(*,*) \"PE2D_HFR\"\r\n WRITE(*,*) \"Dimension : 2D\"\r\n WRITE(*,*) \"Atmosphere : Homogeneous\"\r\n WRITE(*,*) \"Boundary : Flat\"\r\n WRITE(*,*) \"Impedance : Rigid\"\r\n WRITE(*,*) \"\"\r\n WRITE(*,*) \"================================================\"\r\n WRITE(*,*) \"\"\r\n WRITE(*,*) \"Enter inputs L, f, zs, As\"\r\n WRITE(*,*) \"\"\r\n READ *, L, F, ZS, ABL\r\n WRITE(*,*) \"\"\r\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\n C0 = 343.0_DP\r\n LMBDA0 = C0/F\r\n K0 = 2*PI*F/C0\r\n DZ = LMBDA0/10\r\n DR = LMBDA0/10\n H = 100*LMBDA0\r\n HABL = 30*LMBDA0\r\n N = FLOOR(H/DZ)\r\n M = FLOOR(L/DR)\n WRITE(*,*) \"================================================\"\n WRITE(*,*) \"\"\n WRITE(*,*) \"Size of the system : \", N\n WRITE(*,*) \"Number of steps : \", M\n WRITE(*,*) \"\"\n WRITE(*,*) \"================================================\"\r\n NS = MAX(1,FLOOR(ZS/DZ))\r\n NABL = FLOOR(HABL/DZ)\n A = IM/(2.0_DP*K0*DZ**2)\n KU = 1\n KL = 1\n NDIAG = KU+KL+1\r\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\r\n !Memory allocation\r\n ALLOCATE(K(N), DK2(N), ALT(N), PHI(N,M+1), T(N,N), D(N,N), M1(N,N), &\n M2(N,N), I(N,N), P(N,M), LP(N,M), LP2(N,M), LPG(M), LPG2(M), E(N,N), &\n MB2(NDIAG,N), MB1(NDIAG,N), TEMP(N,1), M1T(N,N), M2T(N,N), IPIV(N), &\n GHX(3), MCOND(M,2), MB1T(NDIAG,N), MB2T(KL+NDIAG,N))\r\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\r\n DO NZ = 1,N\r\n IF (NZ.GE.N-NABL) THEN\r\n K(NZ) = K0+ABL*IM*(NZ-N+NABL)**2/NABL**2\r\n ELSE\r\n K(NZ) = K0\r\n ENDIF\r\n DK2(NZ) = IM*(K(NZ)**2-K0**2)/(2*K0)\n ALT(NZ) = NZ*DZ\r\n END DO\r\n TAU1 = 4./(3.-2.*IM*K0*DZ)\r\n TAU2 = -1./(3.-2.*IM*K0*DZ)\r\n SIGMA1 = 4./3.\r\n SIGMA2 = -1./3.\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\r\n A0 = 1.3717\r\n A2 = -0.3701\r\n B = 3.\r\n DO NZ = 1,N\r\n PHI(NZ,1) = SQRT(IM*K0)* &\r\n ((A0+A2*K0**2*(NZ*DZ-ZS)**2)*EXP(-K0**2*(NZ*DZ-ZS)**2/B) + &\r\n (A0+A2*K0**2*(NZ*DZ+ZS)**2)*EXP(-K0**2*(NZ*DZ+ZS)**2/B))\r\n END DO\r\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\r\n !Initialization (Dense Matrices)\n !---------\r\n T(:,:) = 0._DP\r\n DO NZ = 2,N-1 \r\n T(NZ,NZ-1) = T(NZ,NZ-1)+1.\r\n T(NZ,NZ) = T(NZ,NZ)-2.\r\n T(NZ,NZ+1) = T(NZ,NZ+1)+1.\r\n END DO\n T(1,1) = T(1,1)-2.+SIGMA1\r\n T(1,2) = T(1,2)+1.+SIGMA2\r\n T(N,N-1) = T(N,N-1)+1.+TAU2\r\n T(N,N) = T(N,N)-2.+TAU1\n E = DIAG(ALT,N)\n D = DIAG(DK2,N)\n I = EYE(N)\n !-----------------------------------------------------------\n !System - M1 and M2\n !---------\n ALPHA = CMPLX(1.0_DP,0.0_DP,KIND=DP)\n BETA = CMPLX(0.0_DP,0.0_DP,KIND=DP)\n BETA1 = 1.0_DP/(2.0_DP*IM*K0)+DR/2.0_DP\n BETA2 = 1.0_DP/(2.0_DP*IM*K0)-DR/2.0_DP\n M1 = I+A*BETA1*T+BETA1*D\r\n M2 = I+A*BETA2*T+BETA2*D \n MB1 = DENSE2BAND(M1,N,KL,KU)\n MB2 = DENSE2BAND(M2,N,KL,KU)\n MB1T = MB1\n MB2T(KL+1:KL+NDIAG,:) = MB2\r\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\r\n !Forward-marching procedure\n CALL CPU_TIME(TI)\n !-----------------------------------------------------------\n DO MX = 2,M+1\n WRITE(*,*) \"Step :\", MX-1, \"out of\", M\n !-------------------------------\n !Right hand side multiplication\n !-------------------------------\n CALL ZGBMV('N',N,N,KL,KU,ALPHA,MB1,KL+KU+1,PHI(1:N,MX-1),1,BETA,TEMP(:,1),1)\n WRITE(*,*) \".... Right-hand side multiplied\"\n WRITE(*,*)\n !-------------------------------\n !System solving\n !-------------------------------\n !MTEMP2 = M2\n !CALL ZGESV(N,1,M2T,N,IPIV,TEMP,N,INFO) !General matrix form \n CALL ZGBSV(N,KL,KU,1,MB2T,2*KL+KU+1,IPIV,TEMP,N,INFO) !Band matrix form\n !CALL ZGTSV(N,1,MT2T(3,1:N-1),MT2T(2,1:N),MT2T(1,2:N),TEMP(:,1),N,INFO) !Tridiagonal matrix form\n IF (INFO.NE.0) THEN\n STOP \"ERROR : Matrix is singular\"\n END IF\n WRITE(*,*) \".... System solved\"\n WRITE(*,*)\n PHI(1:N,MX) = TEMP(:,1)\r\n P(1:N,MX-1) = EXP(IM*K0*(MX-1)*DR)*PHI(1:N,MX)*(1/SQRT((MX-1)*DR))\r\n END DO\n !-----------------------------------------------------------\r\n CALL CPU_TIME(TF)\r\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\r\n !Transmission loss conversion\r\n P0 = ABS(P(NS,1))\r\n DO MX = 1,M\r\n DO NZ = 1,N\r\n LP(NZ,MX) = 20.*LOG10(ABS(P(NZ,MX))/P0)\r\n END DO\r\n END DO\r\n LPG = LP(1,1:M)\r\n LP2 = LP/SQRT(2.)\r\n LPG2 = LP2(1,1:M)\r\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\r\n IF (OUTPUT.EQ.\"Y\") THEN\r\n !Output\r\n OPEN(UNIT=10,FILE=\"../results/Flat_LPg.dat\")\r\n OPEN(UNIT=20,FILE=\"../results/Flat_LP.dat\")\r\n OPEN(UNIT=30,FILE=\"../results/Flat_P.dat\")\r\n DO MX = 1,M\r\n WRITE(10,100) MX*DR, LPG(MX), LPG2(MX)\n DO NZ = 1,N\n WRITE(20,100) MX*DR, NZ*DZ+TERR(MX), LP(NZ,MX)\n WRITE(30,101) MX*DR, NZ*DZ+TERR(MX), ABS(P(NZ,MX))\n END DO\n WRITE(20,*)\n WRITE(30,*) \r\n END DO\r\n 100 FORMAT(3(3X,F12.3))\r\n 101 FORMAT(2(3X,F12.3),3X,F12.3,SP,F12.3,SS,\"i\")\n !Plotting of results\n CALL SYSTEM('gnuplot -p plot_flat.plt')\n END IF\n PRINT *, \"Main CPU time (s) :\", TF-TI\r\n PRINT *, \"Source pressure P0 (dB) :\", 20*LOG10(ABS(P0))\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\r\nEND PROGRAM PE2D_HF_FD\r\n!-----------------------------------------------------------\r\n!------------- EXTERNAL PROCEDURES ---------------\r\n!-----------------------------------------------------------\r\n", "meta": {"hexsha": "b896ffb4124ed96176e472870b1be400edf1bb3d", "size": 6465, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "Parabolic_Equation/2DPE/SRC/PE2D_HF_FD.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/SRC/PE2D_HF_FD.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/SRC/PE2D_HF_FD.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": 34.2063492063, "max_line_length": 123, "alphanum_fraction": 0.3653518948, "num_tokens": 2053, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.7606506418255928, "lm_q1q2_score": 0.6828325001052665}} {"text": "!-------------------------------------------------------------------------------!\r\n! !\r\n\r\nsubroutine fungauss(n,f,J,x,y,w)\r\n \r\n! !\r\n! Authors: !\r\n! Per J\\\"onsson, Malm\\\"o University, Sweden !\r\n! e-mail per.jonsson@ts.mah.se !\r\n! !\r\n! Lars Eklundh, Lund University, Sweden !\r\n! e-mail lars.eklundh@nateko.lu.se !\r\n! !\r\n! Updated 1/11-2005 !\r\n! !\r\n! Local variables !\r\n! x(n) vector with parameter values ! \r\n! f(m) vector with function values !\r\n! J(m,n) Jacobian matrix !\r\n! !\r\n! !\r\n!-------------------------------------------------------------------------------!\r\n\r\nimplicit none\r\n\r\ninteger :: i,n,nmid\r\ndouble precision :: zeros(n),t(n),arg(n),exparg(n),x(5),y(n),ytilde(n),w(n),f(n)\r\ndouble precision :: J(n,5),J1(n),J2(n),J3(n),J4(n),J5(n),Jb(n,5),A(2,2)\r\ndouble precision :: Btilde(n,2),Btildeprim(n,2),c(2),cprim(2)\r\n\r\nnmid = floor(x(1)) \r\nzeros = 0.d0\r\nt = dble((/ (i, i = 1,n) /)) \r\narg = (/ ((x(1)-t(1:nmid))/x(2))**x(3),((t(nmid+1:n)-x(1))/x(4))**x(5) /)\r\nexparg = exp(-arg)\r\n\r\n!---- Compute the Jacobian for asymmetric Gaussian ------------------------------\r\n\r\nJ1 = (/ -(x(3)/(x(1)-t(1:nmid)))*arg(1:nmid)*exparg(1:nmid), & \r\n (x(5)/(t(nmid+1:n)-x(1)))*arg(nmid+1:n)*exparg(nmid+1:n) /)\r\nJ2 = (/ (x(3)/x(2))*arg(1:nmid)*exparg(1:nmid), zeros(nmid+1:n) /)\r\nJ3 = (/ -log((x(1)-t(1:nmid))/x(2))*arg(1:nmid)*exparg(1:nmid), zeros(nmid+1:n) /)\r\nJ4 = (/ zeros(1:nmid) , (x(5)/x(4))*arg(nmid+1:n)*exparg(nmid+1:n) /)\r\nJ5 = (/ zeros(1:nmid) , -log((t(nmid+1:n)-x(1))/x(4))*arg(nmid+1:n)*exparg(nmid+1:n) /)\r\nJb = reshape(source = (/ J1,J2,J3,J4,J5 /), shape = (/ n,5 /))\r\n\r\nytilde = w*y\r\nBtilde = reshape(source = (/ w, w*exparg /), shape = (/ n,2 /)) \r\nA(1:2,1:2) = matmul(transpose(Btilde),Btilde) \r\ncall gauss(2,A,matmul(ytilde,Btilde),c) \r\nf = ytilde - matmul(c,transpose(Btilde)) \r\n\r\ndo i = 1,5\r\n Btildeprim = reshape(source = (/ zeros, w*Jb(1:n,i) /), shape = (/ n,2 /))\r\n call gauss(2,matmul(transpose(Btilde),Btilde),matmul(f,Btildeprim) &\r\n - matmul(c,matmul(transpose(Btildeprim),Btilde)),cprim) \r\n J(1:n,i) = -matmul(c,transpose(Btildeprim)) - matmul(cprim,transpose(Btilde)) \r\nend do\r\n\r\nend subroutine fungauss", "meta": {"hexsha": "b5f4c05850afe9d55ea368e69c97f5c8611acafb", "size": 3270, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/Smooth_Gapfill_LAI/fungauss.f90", "max_stars_repo_name": "bucricket/projectMASpreprocess", "max_stars_repo_head_hexsha": "608495d7cd6890ecca6ad2a8be0d15b5ea80f7c1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-28T20:26:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T20:26:59.000Z", "max_issues_repo_path": "source/Smooth_Gapfill_LAI/fungauss.f90", "max_issues_repo_name": "bucricket/projectMASpreprocess", "max_issues_repo_head_hexsha": "608495d7cd6890ecca6ad2a8be0d15b5ea80f7c1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/Smooth_Gapfill_LAI/fungauss.f90", "max_forks_repo_name": "bucricket/projectMASpreprocess", "max_forks_repo_head_hexsha": "608495d7cd6890ecca6ad2a8be0d15b5ea80f7c1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-04-20T21:04:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-16T08:05:44.000Z", "avg_line_length": 54.5, "max_line_length": 88, "alphanum_fraction": 0.3428134557, "num_tokens": 872, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037363973295, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6828323603587397}} {"text": "!\n! Newman-Penrose fields of definite spin and boost weight \n! for the background Kerr spacetime.\n! The fields have been rescaled by the highest power of R that allows\n! them to remain regular and nonzero from the black hole horizon to\n! future null infinity.\n!\n! rh_0: rescaled by R\n! mu_0: rescaled by R\n! ta_0: rescaled by R^2\n! pi_0: rescaled by R^2\n! ep_0: rescaled by R^2\n! psi2_0: rescaled by R^3\n!\n!=============================================================================\nmodule mod_bkgrd_np\n!=============================================================================\n use mod_prec\n use mod_params, only: &\n ZI, nx, ny, & \n cl=>compactification_length, &\n bhm=>black_hole_mass, &\n bhs=>black_hole_spin\n\n use mod_cheb, only: R=>Rarr\n use mod_swal, only: cy=>cyarr, sy=>syarr\n!=============================================================================\n implicit none\n private\n\n public :: bkgrd_np_init\n\n complex(rp), allocatable, public, protected :: &\n mu_0(:,:), ta_0(:,:), pi_0(:,:), rh_0(:,:), ep_0(:,:), psi2_0(:,:) \n!=============================================================================\ncontains\n!=============================================================================\n subroutine bkgrd_np_init()\n allocate(mu_0(nx,ny))\n allocate(ta_0(nx,ny))\n allocate(pi_0(nx,ny))\n allocate(rh_0(nx,ny))\n allocate(ep_0(nx,ny))\n allocate(psi2_0(nx,ny))\n !----------------------------\n mu_0 = &\n 1.0_rp / (-(cl**2) + ZI*bhs*R*cy)\n !----------------------------\n ta_0 = &\n (ZI*bhs*sy/sqrt(2.0_rp)) / ((cl**2 - ZI*bhs*R*cy)**2)\n !----------------------------\n pi_0 = &\n - (ZI*bhs*sy/sqrt(2.0_rp)) / (cl**4 + (bhs*cy*R)**2)\n !----------------------------\n rh_0 = &\n - 0.5_rp*( &\n cl**4 - 2.0_rp*(cl**2)*bhm*R + (bhs*R)**2 &\n )/( &\n ((cl**2 - ZI*bhs*R*cy)**2)*(cl**2 + ZI*bhs*R*cy) &\n )\n !----------------------------\n ep_0 = &\n 0.5_rp*( &\n (cl**2)*bhm - (bhs**2)*R - ZI*bhs*(cl**2-bhm*R)*cy &\n )/( &\n ((cl**2 - ZI*bhs*R*cy)**2)*(cl**2 + ZI*bhs*R*cy) &\n )\n !----------------------------\n psi2_0 = &\n - bhm / ((cl**2 - ZI*bhs*R*cy)**3)\n !----------------------------\n end subroutine bkgrd_np_init\n!=============================================================================\nend module mod_bkgrd_np\n", "meta": {"hexsha": "ed8519a4d8bc083713feacb99a72cf0ee5fb6391", "size": 2484, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/mod_bkgrd.f90", "max_stars_repo_name": "JLRipley314/teuk-fortran", "max_stars_repo_head_hexsha": "18e04c9ad70db4e0d26f96dc27349f79323f44c8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-11-02T18:31:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-24T21:22:39.000Z", "max_issues_repo_path": "src/mod_bkgrd.f90", "max_issues_repo_name": "JLRipley314/teuk-fortran", "max_issues_repo_head_hexsha": "18e04c9ad70db4e0d26f96dc27349f79323f44c8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/mod_bkgrd.f90", "max_forks_repo_name": "JLRipley314/teuk-fortran", "max_forks_repo_head_hexsha": "18e04c9ad70db4e0d26f96dc27349f79323f44c8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-07-06T01:42:52.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-24T21:22:42.000Z", "avg_line_length": 33.12, "max_line_length": 78, "alphanum_fraction": 0.3816425121, "num_tokens": 705, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.926303724190573, "lm_q2_score": 0.7371581684030624, "lm_q1q2_score": 0.6828323567092582}} {"text": " SUBROUTINE convlv(data,n,respns,m,isign,ans)\r\n INTEGER isign,m,n,NMAX\r\n REAL data(n),respns(n)\r\n COMPLEX ans(n)\r\n PARAMETER (NMAX=4096)\r\nCU USES realft,twofft\r\n INTEGER i,no2\r\n COMPLEX fft(NMAX)\r\n do 11 i=1,(m-1)/2\r\n respns(n+1-i)=respns(m+1-i)\r\n11 continue\r\n do 12 i=(m+3)/2,n-(m-1)/2\r\n respns(i)=0.0\r\n12 continue\r\n call twofft(data,respns,fft,ans,n)\r\n no2=n/2\r\n do 13 i=1,no2+1\r\n if (isign.eq.1) then\r\n ans(i)=fft(i)*ans(i)/no2\r\n else if (isign.eq.-1) then\r\n if (abs(ans(i)).eq.0.0) pause\r\n *'deconvolving at response zero in convlv'\r\n ans(i)=fft(i)/ans(i)/no2\r\n else\r\n pause 'no meaning for isign in convlv'\r\n endif\r\n13 continue\r\n ans(1)=cmplx(real(ans(1)),real(ans(no2+1)))\r\n call realft(ans,n,-1)\r\n return\r\n END\r\n", "meta": {"hexsha": "e15c7ebf03282a7980a2e10e4e52dfedeadbb3f5", "size": 893, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/convlv.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/convlv.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/convlv.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.90625, "max_line_length": 51, "alphanum_fraction": 0.5218365062, "num_tokens": 305, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037302939515, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6828323558595848}} {"text": "PROGRAM select_kinds\r\n!\r\n! Purpose: \r\n! To illustrate the use of SELECTED_REAL_KIND to select\r\n! desired kinds of real variables in a processor-independent\r\n! manner.\r\n! \r\n! Record of revisions:\r\n! Date Programmer Description of change\r\n! ==== ========== =====================\r\n! 11/27/06 S. J. Chapman Original code\r\n!\r\nIMPLICIT NONE\r\n\r\n! Declare parameters:\r\nINTEGER, PARAMETER :: SGL = SELECTED_REAL_KIND(p=6,r=37)\r\nINTEGER, PARAMETER :: DBL = SELECTED_REAL_KIND(p=13,r=200)\r\n\r\n! Declare variables of each type:\r\nREAL(kind=SGL) :: var1 = 0.\r\nREAL(kind=DBL) :: var2 = 0._DBL\r\n\r\n! Write characteristics of selected variables.\r\nWRITE (*,100) 'var1', KIND(var1), PRECISION(var1), RANGE(var1)\r\nWRITE (*,100) 'var2', KIND(var2), PRECISION(var2), RANGE(var2)\r\n100 FORMAT(1X,A,': kind = ',I2,', Precision = ',I2,', Range = ',I3)\r\n\r\nEND PROGRAM\r\n", "meta": {"hexsha": "3a8bf1d4bdaa02d05bd03cbdb649b779edad27c7", "size": 907, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap11/select_kinds.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/select_kinds.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/select_kinds.f90", "max_forks_repo_name": "yangyang14641/FortranLearning", "max_forks_repo_head_hexsha": "3d4a91aacd957361aff5873054edf35c586e8a55", "max_forks_repo_licenses": ["AFL-3.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-05-11T02:36:25.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-05T06:36:55.000Z", "avg_line_length": 31.275862069, "max_line_length": 68, "alphanum_fraction": 0.6074972437, "num_tokens": 247, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. Yes\n2. Yes", "lm_q1_score": 0.7371581626286834, "lm_q2_score": 0.926303724699188, "lm_q1q2_score": 0.6828323517353592}} {"text": "program lu1\n implicit none\n call check( reshape([real(8)::1,2,1,3,4,1,5,7,0 ],[3,3]) )\n call check( reshape([real(8)::11,1,3,2,9,5,17,5,24,2,18,7,2,6,1,1],[4,4]) )\n\ncontains\n\n subroutine check(a)\n real(8), intent(in) :: a(:,:)\n integer :: i,j,n\n real(8), allocatable :: aa(:,:),l(:,:),u(:,:)\n integer, allocatable :: p(:,:)\n integer, allocatable :: ipiv(:)\n n = size(a,1)\n allocate(aa(n,n),l(n,n),u(n,n),p(n,n),ipiv(n))\n forall (j=1:n,i=1:n)\n aa(i,j) = a(i,j)\n u (i,j) = 0d0\n p (i,j) = merge(1 ,0 ,i.eq.j)\n l (i,j) = merge(1d0,0d0,i.eq.j)\n end forall\n call lu(aa, ipiv)\n do i = 1,n\n l(i, :i-1) = aa(ipiv(i), :i-1)\n u(i,i: ) = aa(ipiv(i),i: )\n end do\n p(ipiv,:) = p\n call mat_print('a',a)\n call mat_print('p',p)\n call mat_print('l',l)\n call mat_print('u',u)\n print *, \"residual\"\n print *, \"|| P.A - L.U || = \", maxval(abs(matmul(p,a)-matmul(l,u)))\n end subroutine\n\n subroutine lu(a,p)\n! in situ decomposition, corresponds to LAPACK's dgebtrf\n real(8), intent(inout) :: a(:,:)\n integer, intent(out ) :: p(:)\n integer :: n, i,j,k,kmax\n n = size(a,1)\n p = [ ( i, i=1,n ) ]\n do k = 1,n-1\n kmax = maxloc(abs(a(p(k:),k)),1) + k-1\n if (kmax /= k ) p([k, kmax]) = p([kmax, k])\n a(p(k+1:),k) = a(p(k+1:),k) / a(p(k),k)\n forall (j=k+1:n) a(p(k+1:),j) = a(p(k+1:),j) - a(p(k+1:),k) * a(p(k),j)\n end do\n end subroutine\n\n subroutine mat_print(amsg,a)\n character(*), intent(in) :: amsg\n class (*), intent(in) :: a(:,:)\n integer :: i\n print*,' '\n print*,amsg\n do i=1,size(a,1)\n select type (a)\n type is (real(8)) ; print'(100f8.2)',a(i,:)\n type is (integer) ; print'(100i8 )',a(i,:)\n end select\n end do\n print*,' '\n end subroutine\n\nend program\n", "meta": {"hexsha": "1b5e187d1cc8cbb4946d74bd53d12145ab4e2098", "size": 1905, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/LU-decomposition/Fortran/lu-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/LU-decomposition/Fortran/lu-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/LU-decomposition/Fortran/lu-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": 28.4328358209, "max_line_length": 79, "alphanum_fraction": 0.4708661417, "num_tokens": 745, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473879530492, "lm_q2_score": 0.782662489091802, "lm_q1q2_score": 0.6827535780080654}} {"text": "module PCAClass\n use IOClass\n use MathClass\n use ArrayClass\n implicit none\n\n type :: PCA_\n logical :: columns_are_feature_names=.true.\n real(real64),allocatable :: DataFrame(:,:)\n real(real64),allocatable :: CovMatrix(:,:)\n real(real64),allocatable :: EigenVector(:,:)\n real(real64),allocatable :: EigenValue(:)\n contains\n procedure :: load => loadPCA\n procedure :: standarize => standarizePCA\n procedure :: run => runPCA\n procedure :: principalComponent =>principalComponentPCA\n end type\ncontains\n\n! #############################################################\nsubroutine loadPCA(obj,filename,DataFrame,columns_are_feature_names,num_feature) \n class(PCA_),intent(inout) :: obj\n real(real64),optional,intent(in) :: DataFrame(:,:)\n character(*),optional,intent(in) :: filename\n logical,optional,intent(in) :: columns_are_feature_names\n integer(int32),optional,intent(in) :: num_feature\n type(IO_) ::f \n character(:),allocatable :: line\n integer(int32) :: n\n\n if(present(filename) )then\n if(.not.present(num_feature) )then\n print *, \"ERROR :: LoadPCA >> Argument: num_feature should be set.\"\n stop\n endif\n n = f%numLine(filename)\n obj%DataFrame = zeros(n,num_feature)\n call f%open(filename,\"r\")\n n=1\n do while(n<=10)\n line = f%readline()\n print *, line\n read(line,*) obj%DataFrame(n,1:num_feature)\n n=n+1\n enddo\n call f%close()\n call print(obj%DataFrame)\n else\n if(present(columns_are_feature_names) )then\n obj%columns_are_feature_names = columns_are_feature_names\n endif\n obj%DataFrame = DataFrame \n endif\n\nend subroutine\n! #############################################################\n\n\n! #############################################################\nsubroutine standarizePCA(obj)\n class(PCA_),intent(inout) :: obj\n real(real64) :: sdval, aveval\n integer(int32) :: n\n\n ! get covarianceMatrix\n if(.not.obj%columns_are_feature_names)then\n n=size(obj%DataFrame,1)\n obj%DataFrame = transpose(obj%DataFrame)\n endif\n\n do n=1,size(obj%DataFrame,2)\n sdval = standardDeviation(obj%DataFrame(:,n) )\n aveval = average( obj%DataFrame(:,n) )\n obj%DataFrame(:,n) =obj%DataFrame(:,n)-aveval\n obj%DataFrame(:,n) =obj%DataFrame(:,n)/sdval\n enddo\n\nend subroutine\n! #############################################################\n\n! #############################################################\nsubroutine runPCA(obj)\n class(PCA_),intent(inout) :: obj\n integer(int32) :: i,j,n\n\n\n ! get covarianceMatrix\n if(obj%columns_are_feature_names)then\n n=size(obj%DataFrame,2)\n obj%CovMatrix = covarianceMatrix(obj%DataFrame,obj%DataFrame,n)\n else\n n=size(obj%DataFrame,1)\n obj%DataFrame = transpose(obj%DataFrame)\n obj%columns_are_feature_names = .true.\n obj%CovMatrix = covarianceMatrix(obj%DataFrame,&\n obj%DataFrame,n)\n endif\n\n\n call eigenValueAndVector(obj%CovMatrix,lambda=obj%EigenValue,x=obj%eigenVector)\n\n print *, \"Eigen value::\"\n call print(obj%EigenValue)\n do i=1,size(obj%EigenValue)\n print *, \"Eigen Vector #\"//str(i)\n print *, obj%eigenVector(:,i)\n enddo\n\nend subroutine\n! #############################################################\n\n! #############################################################\nfunction principalComponentPCA(obj) result(ret)\n class(PCA_),intent(in) :: obj\n real(real64),allocatable :: ret(:,:),Wmat(:,:)\n integer(int32) :: numdata, numfeature\n\n numdata =size(obj%DataFrame,1)\n numfeature=size(obj%DataFrame,2)\n ret = zeros(numdata,2)\n Wmat = zeros(numfeature,2)\n Wmat(:,1) = obj%eigenVector(1,:)\n Wmat(:,2) = obj%eigenVector(2,:)\n\n ! First Principal Component\n ret(:,1:2) = matmul(obj%DataFrame,Wmat)\n\n\nend function\n! #############################################################\n\nend module PCAClass", "meta": {"hexsha": "06e4d4b8594b272b56e5bbca6bb76c016371c083", "size": 4097, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/PCAClass/PCAClass.f90", "max_stars_repo_name": "kazulagi/plantFEM", "max_stars_repo_head_hexsha": "20bf2df8202d41aa5dc25d1cc820385dabbc604f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2020-06-21T08:21:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-13T04:28:30.000Z", "max_issues_repo_path": "src/PCAClass/PCAClass.f90", "max_issues_repo_name": "kazulagi/faba", "max_issues_repo_head_hexsha": "7ef140f1ebea0e0ca496d14fdb94a3c024393cfa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-05-08T05:20:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T05:39:29.000Z", "max_forks_repo_path": "src/PCAClass/PCAClass.f90", "max_forks_repo_name": "kazulagi/faba", "max_forks_repo_head_hexsha": "7ef140f1ebea0e0ca496d14fdb94a3c024393cfa", "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": 30.8045112782, "max_line_length": 83, "alphanum_fraction": 0.5540639492, "num_tokens": 970, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473879530492, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.6827535691634534}} {"text": " PROGRAM xbrent\r\nC driver for routine brent\r\n REAL EQL,TOL\r\n PARAMETER(TOL=1.0E-6,EQL=1.E-4)\r\n INTEGER i,iflag,j,nmin\r\n REAL amin(20),ax,b,bx,cx,fa,fb,fc,xmin\r\n REAL bessj0,bessj1,brent,func\r\n EXTERNAL func\r\n nmin=0\r\n write(*,'(/1x,a)') 'Minima of the function BESSJ0'\r\n write(*,'(/1x,t6,a,t19,a,t28,a,t40,a/)') 'Min. #','X',\r\n * 'BESSJ0(X)','BESSJ1(X)'\r\n do 12 i=1,100\r\n ax=i\r\n bx=i+1.0\r\n call mnbrak(ax,bx,cx,fa,fb,fc,func)\r\n b=brent(ax,bx,cx,func,TOL,xmin)\r\n if (nmin.eq.0) then\r\n amin(1)=xmin\r\n nmin=1\r\n write(*,'(1x,5x,i2,3x,3f12.6)') nmin,xmin,\r\n * bessj0(xmin),bessj1(xmin)\r\n else\r\n iflag=0\r\n do 11 j=1,nmin\r\n if (abs(xmin-amin(j)).le.EQL*xmin)\r\n * iflag=1\r\n11 continue\r\n if (iflag.eq.0) then\r\n nmin=nmin+1\r\n amin(nmin)=xmin\r\n write(*,'(1x,5x,i2,3x,3f12.6)') nmin,\r\n * xmin,bessj0(xmin),bessj1(xmin)\r\n endif\r\n endif\r\n12 continue\r\n END\r\n REAL FUNCTION func(x)\r\n REAL bessj0,x\r\n func=bessj0(x)\r\n return\r\n END\r\n", "meta": {"hexsha": "63b7f15ed146ca8a4e1be284d0258c0bfa08181a", "size": 1218, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xbrent.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xbrent.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xbrent.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.3255813953, "max_line_length": 61, "alphanum_fraction": 0.473727422, "num_tokens": 450, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473813156294, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.6827535595462879}} {"text": " SUBROUTINE BB02AD(DEF, NR, DPAR, IPAR, BPAR, CHPAR, VEC, N, M, P,\r\n 1 A, LDA, B, LDB, C, LDC, Q, LDQ, R, LDR, S, LDS,\r\n 2 X, LDX, DWORK, LDWORK, INFO)\r\nC\r\nC SLICOT RELEASE 5.5.\r\nC\r\nC Copyright (c) 2002-2012 NICONET e.V.\r\nC\r\nC PURPOSE\r\nC\r\nC To generate the benchmark examples for the numerical solution of\r\nC discrete-time algebraic Riccati equations (DAREs) of the form\r\nC\r\nC T T T -1 T T\r\nC 0 = A X A - X - (A X B + S) (R + B X B) (B X A + S ) + Q\r\nC\r\nC as presented in [1]. Here, A,Q,X are real N-by-N matrices, B,S are\r\nC N-by-M, and R is M-by-M. The matrices Q and R are symmetric and Q\r\nC may be given in factored form\r\nC\r\nC T\r\nC (I) Q = C Q0 C .\r\nC\r\nC Here, C is P-by-N and Q0 is P-by-P. If R is nonsingular and S = 0,\r\nC the DARE can be rewritten equivalently as\r\nC\r\nC T -1\r\nC 0 = X - A X (I_n + G X) A - Q,\r\nC\r\nC where I_n is the N-by-N identity matrix and\r\nC\r\nC -1 T\r\nC (II) G = B R B .\r\nC\r\nC ARGUMENTS\r\nC\r\nC Mode Parameters\r\nC\r\nC DEF CHARACTER\r\nC This parameter specifies if the default parameters are\r\nC to be used or not.\r\nC = 'N' or 'n' : The parameters given in the input vectors\r\nC xPAR (x = 'D', 'I', 'B', 'CH') are used.\r\nC = 'D' or 'd' : The default parameters for the example\r\nC are used.\r\nC This parameter is not meaningful if NR(1) = 1.\r\nC\r\nC Input/Output Parameters\r\nC\r\nC NR (input) INTEGER array, dimension (2)\r\nC This array determines the example for which DAREX returns\r\nC data. NR(1) is the group of examples.\r\nC NR(1) = 1 : parameter-free problems of fixed size.\r\nC NR(1) = 2 : parameter-dependent problems of fixed size.\r\nC NR(1) = 3 : parameter-free problems of scalable size.\r\nC NR(1) = 4 : parameter-dependent problems of scalable size.\r\nC NR(2) is the number of the example in group NR(1).\r\nC Let NEXi be the number of examples in group i. Currently,\r\nC NEX1 = 13, NEX2 = 5, NEX3 = 0, NEX4 = 1.\r\nC 1 <= NR(1) <= 4;\r\nC 0 <= NR(2) <= NEXi, where i = NR(1).\r\nC\r\nC DPAR (input/output) DOUBLE PRECISION array, dimension (4)\r\nC Double precision parameter vector. For explanation of the\r\nC parameters see [1].\r\nC DPAR(1) defines the parameter 'epsilon' for\r\nC examples NR = 2.2,2.3,2.4, the parameter 'tau'\r\nC for NR = 2.5, and the 1-by-1 matrix R for NR = 2.1,4.1.\r\nC For Example 2.5, DPAR(2) - DPAR(4) define in\r\nC consecutive order 'D', 'K', and 'r'.\r\nC NOTE that DPAR is overwritten with default values\r\nC if DEF = 'D' or 'd'.\r\nC\r\nC IPAR (input/output) INTEGER array, dimension (3)\r\nC On input, IPAR(1) determines the actual state dimension,\r\nC i.e., the order of the matrix A as follows:\r\nC NR(1) = 1, NR(1) = 2 : IPAR(1) is ignored.\r\nC NR = NR(1).NR(2) = 4.1 : IPAR(1) determines the order of\r\nC the output matrix A.\r\nC NOTE that IPAR(1) is overwritten for Examples 1.1-2.3. For\r\nC the other examples, IPAR(1) is overwritten if the default\r\nC parameters are to be used.\r\nC On output, IPAR(1) contains the order of the matrix A.\r\nC\r\nC On input, IPAR(2) is the number of colums in the matrix B\r\nC and the order of the matrix R (in control problems, the\r\nC number of inputs of the system). Currently, IPAR(2) is\r\nC fixed for all examples and thus is not referenced on\r\nC input.\r\nC On output, IPAR(2) is the number of columns of the\r\nC matrix B from (I).\r\nC\r\nC On input, IPAR(3) is the number of rows in the matrix C\r\nC (in control problems, the number of outputs of the\r\nC system). Currently, IPAR(3) is fixed for all examples\r\nC and thus is not referenced on input.\r\nC On output, IPAR(3) is the number of rows of the matrix C\r\nC from (I).\r\nC\r\nC NOTE that IPAR(2) and IPAR(3) are overwritten and\r\nC IPAR(2) <= IPAR(1) and IPAR(3) <= IPAR(1) for all\r\nC examples.\r\nC\r\nC BPAR (input) LOGICAL array, dimension (7)\r\nC This array defines the form of the output of the examples\r\nC and the storage mode of the matrices Q, G or R.\r\nC BPAR(1) = .TRUE. : Q is returned.\r\nC BPAR(1) = .FALSE. : Q is returned in factored form, i.e.,\r\nC Q0 and C from (I) are returned.\r\nC BPAR(2) = .TRUE. : The matrix returned in array Q (i.e.,\r\nC Q if BPAR(1) = .TRUE. and Q0 if\r\nC BPAR(1) = .FALSE.) is stored as full\r\nC matrix.\r\nC BPAR(2) = .FALSE. : The matrix returned in array Q is\r\nC provided in packed storage mode.\r\nC BPAR(3) = .TRUE. : If BPAR(2) = .FALSE., the matrix\r\nC returned in array Q is stored in upper\r\nC packed mode, i.e., the upper triangle\r\nC of a symmetric n-by-n matrix is stored\r\nC by columns, e.g., the matrix entry\r\nC Q(i,j) is stored in the array entry\r\nC Q(i+j*(j-1)/2) for i <= j.\r\nC Otherwise, this entry is ignored.\r\nC BPAR(3) = .FALSE. : If BPAR(2) = .FALSE., the matrix\r\nC returned in array Q is stored in lower\r\nC packed mode, i.e., the lower triangle\r\nC of a symmetric n-by-n matrix is stored\r\nC by columns, e.g., the matrix entry\r\nC Q(i,j) is stored in the array entry\r\nC Q(i+(2*n-j)*(j-1)/2) for j <= i.\r\nC Otherwise, this entry is ignored.\r\nC BPAR(4) = .TRUE. : The product G in (II) is returned.\r\nC BPAR(4) = .FALSE. : G is returned in factored form, i.e.,\r\nC B and R from (II) are returned.\r\nC BPAR(5) = .TRUE. : The matrix returned in array R (i.e.,\r\nC G if BPAR(4) = .TRUE. and R if\r\nC BPAR(4) = .FALSE.) is stored as full\r\nC matrix.\r\nC BPAR(5) = .FALSE. : The matrix returned in array R is\r\nC provided in packed storage mode.\r\nC BPAR(6) = .TRUE. : If BPAR(5) = .FALSE., the matrix\r\nC returned in array R is stored in upper\r\nC packed mode (see above).\r\nC Otherwise, this entry is ignored.\r\nC BPAR(6) = .FALSE. : If BPAR(5) = .FALSE., the matrix\r\nC returned in array R is stored in lower\r\nC packed mode (see above).\r\nC Otherwise, this entry is ignored.\r\nC BPAR(7) = .TRUE. : The coefficient matrix S of the DARE\r\nC is returned in array S.\r\nC BPAR(7) = .FALSE. : The coefficient matrix S of the DARE\r\nC is not returned.\r\nC NOTE that there are no default values for BPAR. If all\r\nC entries are declared to be .TRUE., then matrices Q, G or R\r\nC are returned in conventional storage mode, i.e., as\r\nC N-by-N or M-by-M arrays where the array element Z(I,J)\r\nC contains the matrix entry Z_{i,j}.\r\nC\r\nC CHPAR (output) CHARACTER*255\r\nC On output, this string contains short information about\r\nC the chosen example.\r\nC\r\nC VEC (output) LOGICAL array, dimension (10)\r\nC Flag vector which displays the availability of the output\r\nC data:\r\nC VEC(j), j=1,2,3, refer to N, M, and P, respectively, and\r\nC are always .TRUE.\r\nC VEC(4) refers to A and is always .TRUE.\r\nC VEC(5) is .TRUE. if BPAR(4) = .FALSE., i.e., the factors B\r\nC and R from (II) are returned.\r\nC VEC(6) is .TRUE. if BPAR(1) = .FALSE., i.e., the factors C\r\nC and Q0 from (I) are returned.\r\nC VEC(7) refers to Q and is always .TRUE.\r\nC VEC(8) refers to R and is always .TRUE.\r\nC VEC(9) is .TRUE. if BPAR(7) = .TRUE., i.e., the matrix S\r\nC is returned.\r\nC VEC(10) refers to X and is .TRUE. if the exact solution\r\nC matrix is available.\r\nC NOTE that VEC(i) = .FALSE. for i = 1 to 10 if on exit\r\nC INFO .NE. 0.\r\nC\r\nC N (output) INTEGER\r\nC The order of the matrices A, X, G if BPAR(4) = .TRUE., and\r\nC Q if BPAR(1) = .TRUE.\r\nC\r\nC M (output) INTEGER\r\nC The number of columns in the matrix B (or the dimension of\r\nC the control input space of the underlying dynamical\r\nC system).\r\nC\r\nC P (output) INTEGER\r\nC The number of rows in the matrix C (or the dimension of\r\nC the output space of the underlying dynamical system).\r\nC\r\nC A (output) DOUBLE PRECISION array, dimension (LDA,N)\r\nC The leading N-by-N part of this array contains the\r\nC coefficient matrix A of the DARE.\r\nC\r\nC LDA INTEGER\r\nC The leading dimension of array A. LDA >= N.\r\nC\r\nC B (output) DOUBLE PRECISION array, dimension (LDB,M)\r\nC If (BPAR(4) = .FALSE.), then the leading N-by-M part\r\nC of this array contains the coefficient matrix B of\r\nC the DARE. Otherwise, B is used as workspace.\r\nC\r\nC LDB INTEGER\r\nC The leading dimension of array B. LDB >= N.\r\nC\r\nC C (output) DOUBLE PRECISION array, dimension (LDC,N)\r\nC If (BPAR(1) = .FALSE.), then the leading P-by-N part\r\nC of this array contains the matrix C of the factored\r\nC form (I) of Q. Otherwise, C is used as workspace.\r\nC\r\nC LDC INTEGER\r\nC The leading dimension of array C. LDC >= P.\r\nC\r\nC Q (output) DOUBLE PRECISION array, dimension (NQ)\r\nC If (BPAR(1) = .TRUE.) and (BPAR(2) = .TRUE.), then\r\nC NQ = LDQ*N.\r\nC IF (BPAR(1) = .TRUE.) and (BPAR(2) = .FALSE.), then\r\nC NQ = N*(N+1)/2.\r\nC If (BPAR(1) = .FALSE.) and (BPAR(2) = .TRUE.), then\r\nC NQ = LDQ*P.\r\nC IF (BPAR(1) = .FALSE.) and (BPAR(2) = .FALSE.), then\r\nC NQ = P*(P+1)/2.\r\nC The symmetric matrix contained in array Q is stored\r\nC according to BPAR(2) and BPAR(3).\r\nC\r\nC LDQ INTEGER\r\nC If conventional storage mode is used for Q, i.e.,\r\nC BPAR(2) = .TRUE., then Q is stored like a 2-dimensional\r\nC array with leading dimension LDQ. If packed symmetric\r\nC storage mode is used, then LDQ is irrelevant.\r\nC LDQ >= N if BPAR(1) = .TRUE.;\r\nC LDQ >= P if BPAR(1) = .FALSE..\r\nC\r\nC R (output) DOUBLE PRECISION array, dimension (MR)\r\nC If (BPAR(4) = .TRUE.) and (BPAR(5) = .TRUE.), then\r\nC MR = LDR*N.\r\nC IF (BPAR(4) = .TRUE.) and (BPAR(5) = .FALSE.), then\r\nC MR = N*(N+1)/2.\r\nC If (BPAR(4) = .FALSE.) and (BPAR(5) = .TRUE.), then\r\nC MR = LDR*M.\r\nC IF (BPAR(4) = .FALSE.) and (BPAR(5) = .FALSE.), then\r\nC MR = M*(M+1)/2.\r\nC The symmetric matrix contained in array R is stored\r\nC according to BPAR(5) and BPAR(6).\r\nC\r\nC LDR INTEGER\r\nC If conventional storage mode is used for R, i.e.,\r\nC BPAR(5) = .TRUE., then R is stored like a 2-dimensional\r\nC array with leading dimension LDR. If packed symmetric\r\nC storage mode is used, then LDR is irrelevant.\r\nC LDR >= N if BPAR(4) = .TRUE.;\r\nC LDR >= M if BPAR(4) = .FALSE..\r\nC\r\nC S (output) DOUBLE PRECISION array, dimension (LDS,M)\r\nC If (BPAR(7) = .TRUE.), then the leading N-by-M part of\r\nC this array contains the coefficient matrix S of the DARE.\r\nC\r\nC LDS INTEGER\r\nC The leading dimension of array S. LDS >= 1, and\r\nC LDS >= N if BPAR(7) = .TRUE..\r\nC\r\nC X (output) DOUBLE PRECISION array, dimension (LDX,NX)\r\nC If an exact solution is available (NR = 1.1,1.3,1.4,2.1,\r\nC 2.3,2.4,2.5,4.1), then NX = N and the leading N-by-N part\r\nC of this array contains the solution matrix X.\r\nC Otherwise, X is not referenced.\r\nC\r\nC LDX INTEGER\r\nC The leading dimension of array X. LDX >= 1, and\r\nC LDX >= N if an exact solution is available.\r\nC\r\nC Workspace\r\nC\r\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\r\nC\r\nC LDWORK INTEGER\r\nC The length of the array DWORK. LDWORK >= N*N.\r\nC\r\nC Error Indicator\r\nC\r\nC INFO INTEGER\r\nC = 0 : successful exit;\r\nC < 0 : if INFO = -i, the i-th argument had an illegal\r\nC value;\r\nC = 1 : data file could not be opened or had wrong format;\r\nC = 2 : division by zero;\r\nC = 3 : G can not be computed as in (II) due to a singular R\r\nC matrix. This error can only occur if\r\nC BPAR(4) = .TRUE..\r\nC\r\nC REFERENCES\r\nC\r\nC [1] Abels, J. and Benner, P.\r\nC DAREX - A Collection of Benchmark Examples for Discrete-Time\r\nC Algebraic Riccati Equations (Version 2.0).\r\nC SLICOT Working Note 1999-16, November 1999. Available from\r\nC http://www.win.tue.nl/niconet/NIC2/reports.html.\r\nC\r\nC This is an updated and extended version of\r\nC\r\nC [2] Benner, P., Laub, A.J., and Mehrmann, V.\r\nC A Collection of Benchmark Examples for the Numerical Solution\r\nC of Algebraic Riccati Equations II: Discrete-Time Case.\r\nC Technical Report SPC 95_23, Fak. f. Mathematik,\r\nC TU Chemnitz-Zwickau (Germany), December 1995.\r\nC\r\nC FURTHER COMMENTS\r\nC\r\nC Some benchmark examples read data from the data files provided\r\nC with the collection.\r\nC\r\nC CONTRIBUTOR\r\nC\r\nC Peter Benner (Universitaet Bremen), November 25, 1999.\r\nC\r\nC For questions concerning the collection or for the submission of\r\nC test examples, please send e-mail to benner@math.uni-bremen.de.\r\nC\r\nC REVISIONS\r\nC\r\nC 1999, December 23 (V. Sima).\r\nC\r\nC KEYWORDS\r\nC\r\nC Discrete-time algebraic Riccati equation.\r\nC\r\nC ******************************************************************\r\nC\r\nC .. Parameters ..\r\nC . # of examples available , # of examples with fixed size. .\r\n INTEGER NEX1, NEX2, NEX3, NEX4, NMAX\r\n PARAMETER ( NEX1 = 13, NEX2 = 5, NEX3 = 0, NEX4 = 1 )\r\n PARAMETER ( NMAX = 13 )\r\n DOUBLE PRECISION ZERO, ONE, TWO, THREE, FOUR, FIVE\r\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0, TWO = 2.0D0,\r\n 1 THREE = 3.0D0, FOUR = 4.0D0, FIVE = 5.0D0 )\r\nC\r\nC .. Scalar Arguments ..\r\n INTEGER INFO, LDA, LDB, LDC, LDQ, LDR, LDS, LDWORK, LDX,\r\n $ M, N, P\r\n CHARACTER DEF\r\nC\r\nC .. Array Arguments ..\r\n DOUBLE PRECISION A(LDA,*), B(LDB,*), C(LDC,*), DPAR(*), DWORK(*),\r\n 1 Q(*), R(*), S(LDS,*), X(LDX,*)\r\n INTEGER IPAR(3), NR(2)\r\n CHARACTER CHPAR*255\r\n LOGICAL BPAR(7), VEC(10)\r\nC\r\nC .. Local Scalars ..\r\n INTEGER I, IOS, ISYMM, J, MSYMM, NSYMM, PSYMM, QDIMM,\r\n 1 RDIMM\r\n DOUBLE PRECISION ALPHA, BETA, TEMP\r\nC\r\nC ..Local Arrays ..\r\n INTEGER MDEF(2,NMAX), NDEF(4,NMAX), NEX(4), PDEF(2,NMAX)\r\n CHARACTER IDENT*4\r\n CHARACTER*255 NOTES(4,NMAX)\r\nC\r\nC .. External Functions ..\r\nC . LAPACK .\r\n LOGICAL LSAME\r\n EXTERNAL LSAME\r\nC\r\nC .. External Subroutines ..\r\nC . BLAS .\r\n EXTERNAL DCOPY, DGEMV, DSPMV, DSPR, DSYMM, DSYRK\r\nC . LAPACK .\r\n EXTERNAL DLASET, DPPTRF, DPPTRI, DRSCL, XERBLA\r\nC . SLICOT .\r\n EXTERNAL MA02DD, MA02ED\r\nC\r\nC .. Intrinsic Functions ..\r\n INTRINSIC SQRT\r\nC\r\nC .. Data Statements ..\r\nC . default values for dimensions .\r\n DATA NEX /NEX1, NEX2, NEX3, NEX4/\r\n DATA (NDEF(1,I), I = 1, NEX1) /2, 2, 2, 3, 4, 4, 4, 5, 6, 9,\r\n 1 11, 13, 26/\r\n DATA (NDEF(2,I), I = 1, NEX2) /2, 2, 2, 3, 4/\r\n DATA (NDEF(4,I), I = 1, NEX4) /100/\r\n DATA (MDEF(1,I), I = 1, NEX1) /1, 2, 1, 2, 2, 2, 4, 2, 2, 3,\r\n 1 2, 2, 6/\r\n DATA (MDEF(2,I), I = 1, NEX2) /1, 2, 1, 3, 1/\r\n DATA (PDEF(1,I), I = 1, NEX1) /1, 2, 2, 3, 4, 4, 4, 5, 2, 2,\r\n 1 4, 4, 12/\r\n DATA (PDEF(2,I), I = 1, NEX2) /2, 2, 2, 3, 1/\r\nC . comments on examples .\r\n DATA (NOTES(1,I), I = 1, 10) /\r\n 1'Van Dooren 1981, Ex. II: singular R matrix', 'Ionescu/Weiss 1992\r\n 2: singular R matrix, nonzero S matrix', 'Jonckheere 1981: (A,B) co\r\n 3ntrollable, no solution X <= 0', 'Sun 1998: R singular, Q non-defi\r\n 4nite', 'Ackerson/Fu 1970 : satellite control problem', 'Litkouhi 1\r\n 5983 : system with slow and fast modes', 'Lu/Lin 1993, Ex. 4.3', 'G\r\n 6ajic/Shen 1993, Section 2.7.4: chemical plant', 'Davison/Wang 1974\r\n 7: nonzero S matrix', 'Patnaik et al. 1980: tubular ammonia reactor\r\n 8'/\r\n DATA (NOTES(1,I), I = 11, NEX1) /\r\n 1'Sima 1996, Sec. 1.2.2: paper machine model error integrators', 'S\r\n 2ima 1996, Ex. 2.6: paper machine model with with disturbances', 'P\r\n 3ower plant model, Katayama et al., 1985'/\r\n DATA (NOTES(2,I), I = 1, NEX2) /\r\n 1'Laub 1979, Ex. 2: uncontrollable-unobservable data', 'Laub 1979,\r\n 2Ex. 3: increasingly ill-conditioned R-matrix', 'increasingly bad s\r\n 3caled system as eps -> oo','Petkov et. al. 1989 : increasingly bad\r\n 4 scaling as eps -> oo', 'Pappas et al. 1980: process control of pa\r\n 5per machine'/\r\n DATA (NOTES(4,I), I = 1, NEX4) /'Pappas et al. 1980, Ex. 3'/\r\nC\r\nC .. Executable Statements ..\r\nC\r\n INFO = 0\r\n DO 1 I = 1, 10\r\n VEC(I) = .FALSE.\r\n 1 CONTINUE\r\nC\r\n IF (NR(1) .GE. 3) THEN\r\n IF (LSAME(DEF, 'D')) IPAR(1) = NDEF(NR(1),NR(2))\r\n IPAR(2) = 1\r\n IPAR(3) = IPAR(1)\r\n ELSE\r\n IPAR(1) = NDEF(NR(1),NR(2))\r\n IPAR(2) = MDEF(NR(1),NR(2))\r\n IPAR(3) = PDEF(NR(1),NR(2))\r\n END IF\r\nC\r\n IF ((NR(1) .GE. 2) .AND. .NOT. ((LSAME(DEF,'D')) .OR.\r\n $ (LSAME(DEF,'N')))) THEN\r\n INFO = -1\r\n ELSE IF ((NR(1) .LT. 1) .OR. (NR(1) .GT. 4) .OR. (NR(2) .LT. 0)\r\n 1 .OR. (NR(2) .GT. NEX(NR(1)))) THEN\r\n INFO = -2\r\n ELSE IF (IPAR(1) .LT. 1) THEN\r\n INFO = -4\r\n ELSE IF (IPAR(1) .GT. LDA) THEN\r\n INFO = -12\r\n ELSE IF (IPAR(1) .GT. LDB) THEN\r\n INFO = -14\r\n ELSE IF (IPAR(3) .GT. LDC) THEN\r\n INFO = -16\r\n ELSE IF (BPAR(2) .AND. (((.NOT. BPAR(1)) .AND.\r\n 1 (IPAR(3) .GT. LDQ)) .OR. (BPAR(1) .AND.\r\n 2 (IPAR(1) .GT. LDQ)))) THEN\r\n INFO = -18\r\n ELSE IF (BPAR(5) .AND. ((BPAR(4) .AND. (IPAR(1) .GT. LDR)) .OR.\r\n 1 ((.NOT. BPAR(4)) .AND. (IPAR(2) .GT. LDR)))) THEN\r\n INFO = -20\r\n ELSE IF (LDS .LT. 1 .OR. (BPAR(7) .AND. (IPAR(1) .GT. LDS))) THEN\r\n INFO = -22\r\n ELSE IF (LDX .LT. 1) THEN\r\n INFO = -24\r\n ELSE IF (((NR(1) .EQ. 1) .AND. ((NR(2) .EQ. 1) .OR.\r\n 1 (NR(2) .EQ. 3) .OR. (NR(2) .EQ. 4))) .OR.\r\n 2 ((NR(1) .EQ. 2) .AND. ((NR(2). EQ. 1) .OR.\r\n 3 (NR(2) .GE. 3))) .OR. (NR(1) .EQ. 4)) THEN\r\nC .. solution X available ..\r\n IF (IPAR(1) .GT. LDX) THEN\r\n INFO = -24\r\n ELSE\r\n CALL DLASET('A', IPAR(1), IPAR(1), ZERO, ZERO, X, LDX)\r\n END IF\r\n ELSE IF (LDWORK .LT. N*N) THEN\r\n INFO = -26\r\n END IF\r\n IF (INFO .NE. 0) THEN\r\n CALL XERBLA( 'BB02AD', -INFO )\r\n RETURN\r\n END IF\r\nC\r\n NSYMM = (IPAR(1)*(IPAR(1)+1))/2\r\n MSYMM = (IPAR(2)*(IPAR(2)+1))/2\r\n PSYMM = (IPAR(3)*(IPAR(3)+1))/2\r\nC\r\n CALL DLASET('A', IPAR(1), IPAR(1), ZERO, ZERO, A, LDA)\r\n CALL DLASET('A', IPAR(1), IPAR(2), ZERO, ZERO, B, LDB)\r\n CALL DLASET('A', IPAR(3), IPAR(1), ZERO, ZERO, C, LDC)\r\n CALL DLASET('L', PSYMM, 1, ZERO, ZERO, Q, 1)\r\n CALL DLASET('L', MSYMM, 1, ZERO, ZERO, R, 1)\r\n IF (BPAR(7)) CALL DLASET('A', IPAR(1), IPAR(2), ZERO, ZERO,\r\n 1 S, LDS)\r\nC\r\n IF(NR(1) .EQ. 1) THEN\r\nC\r\n IF (NR(2) .EQ. 1) THEN\r\n A(1,1) = TWO\r\n A(2,1) = ONE\r\n A(1,2) = -ONE\r\n B(1,1) = ONE\r\n Q(1) = ONE\r\n C(1,2) = ONE\r\n R(1) = ZERO\r\n CALL DLASET('A', IPAR(1), IPAR(1), ZERO, ONE, X, LDX)\r\n IDENT = '0000'\r\nC\r\n ELSE IF (NR(2) .EQ. 2) THEN\r\n A(1,2) = ONE\r\n A(2,2) = -ONE\r\n B(1,1) = ONE\r\n B(2,1) = TWO\r\n B(2,2) = ONE\r\n R(1) = 9.0D0\r\n R(2) = THREE\r\n R(3) = ONE\r\n CALL DLASET('A', PSYMM, 1, -FOUR, -FOUR, Q, PSYMM)\r\n Q(3) = 7.0D0\r\n CALL DRSCL(MSYMM, 11.0D0, Q, 1)\r\n IF (BPAR(7)) THEN\r\n S(1,1) = THREE\r\n S(2,1) = -ONE\r\n S(1,2) = ONE\r\n S(2,2) = 7.0D0\r\n END IF\r\n IDENT = '0100'\r\nC\r\n ELSE IF (NR(2) .EQ. 3) THEN\r\n A(1,2) = ONE\r\n B(2,1) = ONE\r\n Q(1) = ONE\r\n Q(2) = TWO\r\n Q(3) = FOUR\r\n X(1,1) = ONE\r\n X(2,1) = TWO\r\n X(1,2) = TWO\r\n X(2,2) = TWO + SQRT(FIVE)\r\n IDENT = '0101'\r\nC\r\n ELSE IF (NR(2) .EQ. 4) THEN\r\n A(1,2) = .1000D+00\r\n A(2,3) = .0100D+00\r\n B(1,1) = ONE\r\n B(3,2) = ONE\r\n R(3) = ONE\r\n Q(1) = .1D+06\r\n Q(4) = .1D+04\r\n Q(6) = -.1D+02\r\n X(1,1) = .1D+06\r\n X(2,2) = .1D+04\r\n IDENT = '0100'\r\nC\r\n ELSE IF (((NR(2) .GE. 5) .AND. (NR(2) .LE. 8)) .OR.\r\n 1 (NR(2) .EQ. 10) .OR. (NR(2) .EQ. 11) .OR.\r\n 2 (NR(2) .EQ. 13)) THEN\r\n IF (NR(2) .LT. 10) THEN\r\n WRITE (CHPAR(1:11), '(A,I1,A,I1,A)')\r\n 1 'BB02', NR(1), '0', NR(2), '.dat'\r\n OPEN(1, IOSTAT = IOS, STATUS = 'OLD', FILE = CHPAR(1:11))\r\n ELSE\r\n WRITE (CHPAR(1:11), '(A,I1,I2,A)')\r\n 1 'BB02', NR(1), NR(2), '.dat'\r\n OPEN(1, IOSTAT = IOS, STATUS = 'OLD', FILE = CHPAR(1:11))\r\n END IF\r\n IF (IOS .NE. 0) THEN\r\n INFO = 1\r\n ELSE\r\n IF (.NOT. (NR(2) .EQ. 13)) THEN\r\n DO 10 I = 1, IPAR(1)\r\n READ (1, FMT = *, IOSTAT = IOS) (A(I,J), J = 1, IPAR(1))\r\n IF (IOS .NE. 0) INFO = 1\r\n 10 CONTINUE\r\n DO 20 I = 1, IPAR(1)\r\n READ (1, FMT = *, IOSTAT = IOS) (B(I,J), J = 1, IPAR(2))\r\n IF (IOS .NE. 0) INFO = 1\r\n 20 CONTINUE\r\n END IF\r\n IF (NR(2) .EQ. 5) THEN\r\n Q(1) = .187D1\r\n Q(4) = -.244D0\r\n Q(5) = .744D0\r\n Q(6) = .205D0\r\n Q(8) = .589D0\r\n Q(10) = .1048D1\r\n ELSE IF (NR(2) .EQ. 6) THEN\r\n Q(1) = .1D-1\r\n Q(5) = .1D-1\r\n Q(8) = .1D-1\r\n Q(10) = .1D-1\r\n ELSE IF (NR(2) .EQ. 7) THEN\r\n CALL DLASET('U', IPAR(3), IPAR(1), ONE, ONE, C, LDC)\r\n C(1,3) = TWO\r\n C(1,4) = FOUR\r\n C(2,4) = TWO\r\n Q(1) = TWO\r\n Q(2) = -ONE\r\n Q(5) = TWO\r\n Q(6) = -ONE\r\n Q(8) = TWO\r\n ELSE IF (NR(2) .EQ. 10) THEN\r\n C(1,1) = ONE\r\n C(2,5) = ONE\r\n Q(1) = 50.0D0\r\n Q(3) = 50.0D0\r\n ELSE IF (NR(2) .EQ. 11) THEN\r\n A(10,10) = ONE\r\n A(11,11) = ONE\r\n C(1,6) = 15.0D0\r\n C(2,7) = 7.0D0\r\n C(2,8) = -.5357D+01\r\n C(2,9) = -.3943D+01\r\n C(3,10) = ONE\r\n C(4,11) = ONE\r\n Q(1) = 0.5D0\r\n Q(5) = 5.0D0\r\n Q(8) = 0.5D0\r\n Q(10) = 5.0D0\r\n R(1) = 400.0D0\r\n R(3) = 700.0D0\r\n IDENT = '0000'\r\nC\r\n ELSE IF (NR(2) .EQ. 13) THEN\r\n DO 24 I = 1, IPAR(1)-6\r\n READ (1, FMT = *, IOSTAT = IOS)\r\n 1 (A(I,J), J = 1, IPAR(1)-6)\r\n IF (IOS .NE. 0) INFO = 1\r\n 24 CONTINUE\r\n DO 25 I = 1, IPAR(1)-6\r\n READ (1, FMT = *, IOSTAT = IOS)\r\n 1 (B(I,J), J = 1, IPAR(2))\r\n IF (IOS .NE. 0) INFO = 1\r\n 25 CONTINUE\r\n DO 26 I = 1, IPAR(2)\r\n READ (1, FMT = *, IOSTAT = IOS)\r\n 1 (C(I,J), J = 1, IPAR(1)-6)\r\n IF (IOS .NE. 0) INFO = 1\r\n 26 CONTINUE\r\n DO 27 I = 1, 6\r\n A(20+I,20+I) = ONE\r\n C(6+I,20+I) = ONE\r\n 27 CONTINUE\r\n J = 58\r\n DO 28 I = 7, 12\r\n READ (1, FMT = *, IOSTAT = IOS) Q(J)\r\n IF (IOS .NE. 0) INFO = 1\r\n J = J + (13 - I)\r\n 28 CONTINUE\r\n J = 1\r\n DO 29 I = 1, 6\r\n READ (1, FMT = *, IOSTAT = IOS) R(J)\r\n IF (IOS .NE. 0) INFO = 1\r\n J = J + (7 - I)\r\n 29 CONTINUE\r\n DO 31 I = 1, 6\r\n DO 30 J = 1, 20\r\n A(I+20,J) = -C(I,J)\r\n 30 CONTINUE\r\n 31 CONTINUE\r\n IDENT = '0000'\r\n END IF\r\n END IF\r\n CLOSE(1)\r\n IF ((NR(2) .EQ. 5) .OR. (NR(2) .EQ. 6)) THEN\r\n IDENT = '0101'\r\n ELSE IF ((NR(2) .EQ. 7) .OR. (NR(2) .EQ. 10)) THEN\r\n IDENT = '0001'\r\n ELSE IF (NR(2) .EQ. 8) THEN\r\n IDENT = '0111'\r\n END IF\r\nC\r\n ELSE IF (NR(2). EQ. 9) THEN\r\n A(1,2) = ONE\r\n A(2,3) = ONE\r\n A(4,5) = ONE\r\n A(5,6) = ONE\r\n B(3,1) = ONE\r\n B(6,2) = ONE\r\n C(1,1) = ONE\r\n C(1,2) = ONE\r\n C(2,4) = ONE\r\n C(2,5) = -ONE\r\n R(1) = THREE\r\n R(3) = ONE\r\n IF (BPAR(7)) THEN\r\n S(1,1) = ONE\r\n S(2,1) = ONE\r\n S(4,1) = ONE\r\n S(5,1) = -ONE\r\n END IF\r\n IDENT = '0010'\r\n ELSE IF (NR(2) .EQ. 12) THEN\r\n DO 32 I = 1, 10\r\n A(I,I+1) = ONE\r\n 32 CONTINUE\r\n A(6,7) = ZERO\r\n A(8,9) = ZERO\r\n A(12,12) = ONE\r\n A(13,13) = ONE\r\n A(12,1) = -.3318D+01\r\n A(13,1) = -.15484D+01\r\n A(6,6) = .7788D+00\r\n A(8,7) = -.4724D+00\r\n A(13,7) = .3981D+00\r\n A(8,8) = .13746D+01\r\n A(13,8) = .5113D+00\r\n A(13,9) = .57865D+01\r\n A(11,11) = .8071D+00\r\n B(6,1) = ONE\r\n B(8,2) = ONE\r\n C(1,1) = .3318D+01\r\n C(2,1) = .15484D+01\r\n C(2,7) = -.3981D+00\r\n C(2,8) = -.5113D+00\r\n C(2,9) = -.57865D+01\r\n C(3,12) = ONE\r\n C(4,13) = ONE\r\n Q(1) = 0.5D0\r\n Q(5) = 5.0D0\r\n Q(8) = 0.5D0\r\n Q(10) = 5.0D0\r\n R(1) = 400.0D0\r\n R(3) = 700.0D0\r\n IDENT = '0000'\r\n END IF\r\nC\r\n ELSE IF (NR(1) .EQ. 2) THEN\r\n IF (NR(2) .EQ. 1) THEN\r\n IF (LSAME(DEF, 'D')) DPAR(1) = .1D+07\r\n A(1,1) = FOUR\r\n A(2,1) = -.45D1\r\n A(1,2) = THREE\r\n A(2,2) = -.35D1\r\n CALL DLASET('A', IPAR(1), IPAR(2), -ONE, ONE, B, LDB)\r\n R(1) = DPAR(1)\r\n Q(1) = 9.0D0\r\n Q(2) = 6.0D0\r\n Q(3) = FOUR\r\n TEMP = (ONE + SQRT(ONE+FOUR*DPAR(1))) / TWO\r\n X(1,1) = TEMP*Q(1)\r\n X(2,1) = TEMP*Q(2)\r\n X(1,2) = X(2,1)\r\n X(2,2) = TEMP*Q(3)\r\n IDENT = '0100'\r\nC\r\n ELSE IF (NR(2) .EQ. 2) THEN\r\n IF (LSAME(DEF, 'D')) DPAR(1) = .1D+07\r\n IF (DPAR(1) .EQ. ZERO) THEN\r\n INFO = 2\r\n ELSE\r\n A(1,1) = .9512D0\r\n A(2,2) = .9048D0\r\n CALL DLASET('A', 1, IPAR(2), .4877D1, .4877D1, B, LDB)\r\n B(2,1) = -.11895D1\r\n B(2,2) = .3569D1\r\n R(1) = ONE / (THREE*DPAR(1))\r\n R(3) = THREE*DPAR(1)\r\n Q(1) = .5D-2\r\n Q(3) = .2D-1\r\n IDENT = '0100'\r\n END IF\r\nC\r\n ELSE IF (NR(2) .EQ. 3) THEN\r\n IF (LSAME(DEF,'D')) DPAR(1) = .1D7\r\n A(1,2) = DPAR(1)\r\n B(2,1) = ONE\r\n X(1,1) = ONE\r\n X(2,2) = ONE + DPAR(1)*DPAR(1)\r\n IDENT = '0111'\r\nC\r\n ELSE IF (NR(2) .EQ. 4) THEN\r\n IF (LSAME(DEF,'D')) DPAR(1) = .1D7\r\n A(2,2) = ONE\r\n A(3,3) = THREE\r\n R(1) = DPAR(1)\r\n R(4) = DPAR(1)\r\n R(6) = DPAR(1)\r\nC .. set C = V ..\r\n TEMP = TWO/THREE\r\n CALL DLASET('A', IPAR(3), IPAR(1), -TEMP, ONE - TEMP, C, LDC)\r\nC .. and compute A <- C' A C\r\n CALL DSYMM('L', 'L', IPAR(1), IPAR(1), ONE, C, LDC, A, LDA,\r\n 1 ZERO, DWORK, IPAR(1))\r\n CALL DSYMM('R', 'L', IPAR(1), IPAR(1), ONE, C, LDC, DWORK,\r\n 1 IPAR(1), ZERO, A, LDA)\r\n Q(1) = DPAR(1)\r\n Q(4) = DPAR(1)\r\n Q(6) = DPAR(1)\r\n X(1,1) = DPAR(1)\r\n X(2,2) = DPAR(1) * (ONE + SQRT(FIVE)) / TWO\r\n X(3,3) = DPAR(1) * (9.0D0 + SQRT(85.0D0)) / TWO\r\n CALL DSYMM('L', 'L', IPAR(1), IPAR(1), ONE, C, LDC, X, LDX,\r\n 1 ZERO, DWORK, IPAR(1))\r\n CALL DSYMM('R', 'L', IPAR(1), IPAR(1), ONE, C, LDC, DWORK,\r\n 1 IPAR(1), ZERO, X, LDX)\r\n IDENT = '1000'\r\nC\r\n ELSE IF (NR(2) .EQ. 5) THEN\r\n IF (LSAME(DEF, 'D')) THEN\r\n DPAR(4) = .25D0\r\n DPAR(3) = ONE\r\n DPAR(2) = ONE\r\n DPAR(1) = .1D9\r\n END IF\r\n IF (DPAR(1) .EQ. ZERO) THEN\r\n INFO = 2\r\n ELSE\r\n TEMP = DPAR(2) / DPAR(1)\r\n BETA = DPAR(3) * TEMP\r\n ALPHA = ONE - TEMP\r\n A(1,1) = ALPHA\r\n CALL DLASET('A', IPAR(1)-1, IPAR(1)-1, ZERO, ONE, A(2,1),\r\n 1 LDA)\r\n B(1,1) = BETA\r\n C(1,4) = ONE\r\n R(1) = DPAR(4)\r\n IF (BETA .EQ. ZERO) THEN\r\n INFO = 2\r\n ELSE\r\n CALL DLASET('A', IPAR(1), IPAR(1), ZERO, ONE, X, LDX)\r\n BETA = BETA * BETA\r\n TEMP = DPAR(4) * (ALPHA + ONE) * (ALPHA - ONE) + BETA\r\n X(1,1) = (TEMP + SQRT(TEMP*TEMP + FOUR*BETA*DPAR(4)))\r\n X(1,1) = X(1,1) / TWO / BETA\r\n END IF\r\n IDENT = '0010'\r\n END IF\r\n END IF\r\nC\r\n ELSE IF (NR(1) .EQ. 4) THEN\r\n IF (NR(2) .EQ. 1) THEN\r\n IF (LSAME(DEF,'D')) DPAR(1) = ONE\r\n CALL DLASET('A', IPAR(1)-1, IPAR(1)-1, ZERO, ONE, A(1,2), LDA)\r\n B(IPAR(1),1) = ONE\r\n R(1) = DPAR(1)\r\n DO 40 I = 1, IPAR(1)\r\n X(I,I) = DBLE(I)\r\n 40 CONTINUE\r\n IDENT = '0110'\r\n END IF\r\n END IF\r\nC\r\n IF (INFO .NE. 0) GOTO 2001\r\nC .. set up data in required format ..\r\nC\r\n IF (BPAR(4)) THEN\r\nC .. G is to be returned in product form ..\r\n RDIMM = IPAR(1)\r\n IF (IDENT(4:4) .EQ. '0') THEN\r\nC .. invert R using Cholesky factorization, ..\r\n CALL DPPTRF('L', IPAR(2), R, INFO)\r\n IF (INFO .EQ. 0) THEN\r\n CALL DPPTRI('L', IPAR(2), R, INFO)\r\n IF (IDENT(1:1) .EQ. '0') THEN\r\nC .. B is not identity matrix ..\r\n DO 100 I = 1, IPAR(1)\r\n CALL DSPMV('L', IPAR(2), ONE, R, B(I,1), LDB, ZERO,\r\n 1 DWORK((I-1)*IPAR(1)+1), 1)\r\n 100 CONTINUE\r\n CALL DGEMV('T', IPAR(2), IPAR(1), ONE, DWORK, IPAR(1),\r\n 1 B(1,1), LDB, ZERO, R, 1)\r\n ISYMM = IPAR(1) + 1\r\n DO 110 I = 2, IPAR(1)\r\n CALL DGEMV('T', IPAR(2), IPAR(1), ONE, DWORK, IPAR(1),\r\n 1 B(I,1), LDB, ZERO, B(1,1), LDB)\r\n CALL DCOPY(IPAR(1) - I + 1, B(1,I), LDB, R(ISYMM), 1)\r\n ISYMM = ISYMM + (IPAR(1) - I + 1)\r\n 110 CONTINUE\r\n END IF\r\n ELSE\r\n IF (INFO .GT. 0) THEN\r\n INFO = 3\r\n GOTO 2001\r\n END IF\r\n END IF\r\n ELSE\r\nC .. R = identity ..\r\n IF (IDENT(1:1) .EQ. '0') THEN\r\nC .. B not identity matrix ..\r\n IF (IPAR(2) .EQ. 1) THEN\r\n CALL DLASET('L', NSYMM, 1, ZERO, ZERO, R, 1)\r\n CALL DSPR('L', IPAR(1), ONE, B, 1, R)\r\n ELSE\r\n CALL DSYRK('L', 'N', IPAR(1), IPAR(2), ONE, B, LDB, ZERO,\r\n 1 DWORK, IPAR(1))\r\n CALL MA02DD('Pack', 'Lower', IPAR(1), DWORK, IPAR(1), R)\r\n END IF\r\n ELSE\r\nC .. B = R = identity ..\r\n ISYMM = 1\r\n DO 120 I = IPAR(1), 1, -1\r\n R(ISYMM) = ONE\r\n ISYMM = ISYMM + I\r\n 120 CONTINUE\r\n END IF\r\n END IF\r\n ELSE\r\n RDIMM = IPAR(2)\r\n IF (IDENT(1:1) .EQ. '1')\r\n 1 CALL DLASET('A', IPAR(1), IPAR(2), ZERO, ONE, B, LDB)\r\n IF (IDENT(4:4) .EQ. '1') THEN\r\n ISYMM = 1\r\n DO 130 I = IPAR(2), 1, -1\r\n R(ISYMM) = ONE\r\n ISYMM = ISYMM + I\r\n 130 CONTINUE\r\n END IF\r\n END IF\r\nC\r\n IF (BPAR(1)) THEN\r\nC .. Q is to be returned in product form ..\r\n QDIMM = IPAR(1)\r\n IF (IDENT(3:3) .EQ. '0') THEN\r\n IF (IDENT(2:2) .EQ. '0') THEN\r\nC .. C is not identity matrix ..\r\n DO 140 I = 1, IPAR(1)\r\n CALL DSPMV('L', IPAR(3), ONE, Q, C(1,I), 1, ZERO,\r\n 1 DWORK((I-1)*IPAR(1)+1), 1)\r\n 140 CONTINUE\r\nC .. use Q(1:IPAR(1)) as workspace and compute the first column\r\nC of Q at the end ..\r\n ISYMM = IPAR(1) + 1\r\n DO 150 I = 2, IPAR(1)\r\n CALL DGEMV('T', IPAR(3), IPAR(1), ONE, DWORK, IPAR(1),\r\n 1 C(1,I), 1, ZERO, Q(1), 1)\r\n CALL DCOPY(IPAR(1) - I + 1, Q(I), 1, Q(ISYMM), 1)\r\n ISYMM = ISYMM + (IPAR(1) - I + 1)\r\n 150 CONTINUE\r\n CALL DGEMV('T', IPAR(3), IPAR(1), ONE, DWORK, IPAR(1),\r\n 1 C(1,1), 1, ZERO, Q, 1)\r\n END IF\r\n ELSE\r\nC .. Q = identity ..\r\n IF (IDENT(2:2) .EQ. '0') THEN\r\nC .. C is not identity matrix ..\r\n IF (IPAR(3) .EQ. 1) THEN\r\n CALL DLASET('L', NSYMM, 1, ZERO, ZERO, Q, 1)\r\n CALL DSPR('L', IPAR(1), ONE, C, LDC, Q)\r\n ELSE\r\n CALL DSYRK('L', 'T', IPAR(1), IPAR(3), ONE, C, LDC, ZERO,\r\n 1 DWORK, IPAR(1))\r\n CALL MA02DD('Pack', 'Lower', IPAR(1), DWORK, IPAR(1), Q)\r\n END IF\r\n ELSE\r\nC .. C = Q = identity ..\r\n ISYMM = 1\r\n DO 160 I = IPAR(1), 1, -1\r\n Q(ISYMM) = ONE\r\n ISYMM = ISYMM + I\r\n 160 CONTINUE\r\n END IF\r\n END IF\r\n ELSE\r\n QDIMM = IPAR(3)\r\n IF (IDENT(2:2) .EQ. '1')\r\n 1 CALL DLASET('A', IPAR(3), IPAR(1), ZERO, ONE, C, LDC)\r\n IF (IDENT(3:3) .EQ. '1') THEN\r\n ISYMM = 1\r\n DO 170 I = IPAR(3), 1, -1\r\n Q(ISYMM) = ONE\r\n ISYMM = ISYMM + I\r\n 170 CONTINUE\r\n END IF\r\n END IF\r\nC\r\nC .. unpack symmetric matrices if required ..\r\n IF (BPAR(2)) THEN\r\n ISYMM = (QDIMM * (QDIMM + 1)) / 2\r\n CALL DCOPY(ISYMM, Q, 1, DWORK, 1)\r\n CALL MA02DD('Unpack', 'Lower', QDIMM, Q, LDQ, DWORK)\r\n CALL MA02ED('Lower', QDIMM, Q, LDQ)\r\n ELSE IF (BPAR(3)) THEN\r\n CALL MA02DD('Unpack', 'Lower', QDIMM, DWORK, QDIMM, Q)\r\n CALL MA02ED('Lower', QDIMM, DWORK, QDIMM)\r\n CALL MA02DD('Pack', 'Upper', QDIMM, DWORK, QDIMM, Q)\r\n END IF\r\n IF (BPAR(5)) THEN\r\n ISYMM = (RDIMM * (RDIMM + 1)) / 2\r\n CALL DCOPY(ISYMM, R, 1, DWORK, 1)\r\n CALL MA02DD('Unpack', 'Lower', RDIMM, R, LDR, DWORK)\r\n CALL MA02ED('Lower', RDIMM, R, LDR)\r\n ELSE IF (BPAR(6)) THEN\r\n CALL MA02DD('Unpack', 'Lower', RDIMM, DWORK, RDIMM, R)\r\n CALL MA02ED('Lower', RDIMM, DWORK, RDIMM)\r\n CALL MA02DD('Pack', 'Upper', RDIMM, DWORK, RDIMM, R)\r\n END IF\r\nC\r\nC ...set VEC...\r\n VEC(1) = .TRUE.\r\n VEC(2) = .TRUE.\r\n VEC(3) = .TRUE.\r\n VEC(4) = .TRUE.\r\n VEC(5) = .NOT. BPAR(4)\r\n VEC(6) = .NOT. BPAR(1)\r\n VEC(7) = .TRUE.\r\n VEC(8) = .TRUE.\r\n VEC(9) = BPAR(7)\r\n IF (((NR(1) .EQ. 1) .AND. ((NR(2) .EQ. 1) .OR.\r\n 1 (NR(2) .EQ. 3) .OR. (NR(2) .EQ. 4))) .OR.\r\n 2 ((NR(1) .EQ. 2) .AND. ((NR(2). EQ. 1) .OR.\r\n 3 (NR(2) .GE. 3))) .OR. (NR(1) .EQ. 4)) THEN\r\n VEC(10) = .TRUE.\r\n END IF\r\n CHPAR = NOTES(NR(1),NR(2))\r\n N = IPAR(1)\r\n M = IPAR(2)\r\n P = IPAR(3)\r\nC\r\n 2001 CONTINUE\r\n RETURN\r\nC *** Last line of BB02AD ***\r\n END\r\n", "meta": {"hexsha": "9f61ef06c7313c427f92fbd67e90b1214a57f838", "size": 38607, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "External/SLICOT/BB02AD.f", "max_stars_repo_name": "bgin/MissileSimulation", "max_stars_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2016-08-28T23:20:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-15T14:43:58.000Z", "max_issues_repo_path": "External/SLICOT/BB02AD.f", "max_issues_repo_name": "bgin/MissileSimulation", "max_issues_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-06-02T21:29:51.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-05T05:59:31.000Z", "max_forks_repo_path": "External/SLICOT/BB02AD.f", "max_forks_repo_name": "bgin/MissileSimulation", "max_forks_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-07-04T22:38:22.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-04T22:38:22.000Z", "avg_line_length": 38.453187251, "max_line_length": 73, "alphanum_fraction": 0.4346103038, "num_tokens": 13346, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8723473813156295, "lm_q2_score": 0.7826624688140728, "lm_q1q2_score": 0.682753555123982}} {"text": "program ns\n use, intrinsic :: iso_fortran_env, only : wp => real64\n use pyplot_module, only : pyplot\n \n implicit none\n \n type(pyplot) :: plt\n \n integer, parameter :: nx = 101 ! Number of grid points\n integer, parameter :: nt = 100 ! Number of timesteps\n real(kind=8) :: dx, dt, c, nu\n real(kind=8) :: pi, t, x1, x2, x3, sigma\n real(kind=8) :: burger\n real(kind=8), dimension(nx) :: u, un, x, u_analytical\n integer :: istat, finish = nx\n integer :: n, i, j\n character :: input\n character(len=3) :: index_str\n pi = 4 * atan(1.0)\n \n !nx is declared and assigned above \n dx = 2 * pi / (nx-1) ! Distance between points \n nu = 0.07 ! Viscosity\n sigma = 0.2\n dt = dx * nu\n t = 0\n \n ! Populate \"x\" with evenly spaced numbers -> numpy.linspace\n ! Initialize \"x\"\n ! Done\n call spaceevenly(1, finish, 2 * pi, x)\n \n ! Print x \n do i = 1, nx\n print*, x(i)\n end do\n \n ! Initialize u \n ! Done\n do i = 1, nx\n u(i) = burger(t, x(i), nu)\n end do\n \n ! Initialize un\n ! Done\n do i = 1, nx\n un(i) = 1\n end do\n \n !main loop \n do n=1, nt\n un = u\n do i=2, (nx - 1)\n u(i) = un(i) - un(i) * dt / dx * (un(i) - un(i-1)) + nu * dt / dx**2 * &\n (un(i+1) - 2 * un(i) + un(i-1))\n \n u(1) = un(1) - un(1) * dt / dx * (un(1) - un(nx-2)) + nu * dt / dx**2 * &\n (un(2) - 2 * un(1) + un(nx-2))\n \n u(nx) = u(1)\n end do\n write(index_str, '(I0)') n\n !call plt%initialize(grid=.true.,xlabel='timestep',&\n !title='Plot of u over time',legend=.true.)\n !call plt%add_plot(x,u,label='value of u',linestyle='b-o',markersize=3,linewidth=1,istat=istat)\n\n !call plt%savefig('plot'//index_str//'.png', pyfile='plot'//index_str//'.py', dpi='220', istat=istat)\n print*, \"fig \", n, \" saved ot of \", nt\n end do\n \n !initialize Analitical\n do i = 1, nx\n u_analytical(i) = burger(nt*dt, x(i), nu)\n end do\n \n print*, \"un\"\n do i=1, nx\n print*, un(i)\n end do\n \n print*, \"u\"\n do i=1, nx\n print*, u(i)\n end do\n \n print*, \"u_analytical\"\n do i=1, nx\n print*, u_analytical(i)\n end do\n \n print*, \"x\"\n do i=1, nx\n print*, x(i)\n end do\n \n\n! print*, \"plotting\"\n! call plt%initialize(grid=.true.,xlabel='timestep',&\n! title='Plot of u over time',legend=.true.)\n! call plt%add_plot(x,u,label='value of u',linestyle='b-o',markersize=3,linewidth=1,istat=istat)\n! call plt%add_plot(x,un,label='value of un',linestyle='b-o',markersize=3,linewidth=1,istat=istat)\n! call plt%add_plot(x,u_analytical,label='value of u_analytical',linestyle='b-o',markersize=3,linewidth=1,istat=istat)\n! call plt%savefig('plot.png', pyfile='plot.py', dpi='320', istat=istat)\n\n read*, INPUT\n \nend program ns", "meta": {"hexsha": "f0db199c9f34b0e81ca7e45e314781983f1021fb", "size": 3007, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "l3/l4.f90", "max_stars_repo_name": "dominique120/12-steps-navier-stokes", "max_stars_repo_head_hexsha": "3e195bf7f7895f83f5f2248ef48dc13b76e8b5de", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "l3/l4.f90", "max_issues_repo_name": "dominique120/12-steps-navier-stokes", "max_issues_repo_head_hexsha": "3e195bf7f7895f83f5f2248ef48dc13b76e8b5de", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "l3/l4.f90", "max_forks_repo_name": "dominique120/12-steps-navier-stokes", "max_forks_repo_head_hexsha": "3e195bf7f7895f83f5f2248ef48dc13b76e8b5de", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.1028037383, "max_line_length": 121, "alphanum_fraction": 0.5114732291, "num_tokens": 1004, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473614033683, "lm_q2_score": 0.7826624840223699, "lm_q1q2_score": 0.6827535528063203}} {"text": "!> \\file mo_combinatorics.f90\n\n!> \\brief Package for combinatorial calculations.\n\n!> \\details This package provides routines and functions for combinatorial calculations.\n\n!> \\authors Matthias Cuntz, Giovanni Dalmasso, Juliane Mai, Stephan Thober, Sebastian Mueller\n!> \\date Feb 2013\n\nMODULE mo_combinatorics\n\n ! Written Matthias Cuntz, Giovanni Dalmasso, Juliane Mai, Stephan Thober Feb 2013\n ! Modified Matthias Cuntz, May 2014 - removed numerical recipes, use mo_functions\n\n ! License\n ! -------\n ! This file is part of the JAMS Fortran package, distributed under the MIT License.\n !\n ! Copyright (c) 2011-2014 Matthias Cuntz, Giovanni Dalmasso, Juliane Mai, Stephan Thober, Sebastian Mueller\n ! mc (at) macu (dot) de\n !\n ! Permission is hereby granted, free of charge, to any person obtaining a copy\n ! of this software and associated documentation files (the \"Software\"), to deal\n ! in the Software without restriction, including without limitation the rights\n ! to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n ! copies of the Software, and to permit persons to whom the Software is\n ! furnished to do so, subject to the following conditions:\n !\n ! The above copyright notice and this permission notice shall be included in all\n ! copies or substantial portions of the Software.\n !\n ! THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n ! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n ! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n ! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n ! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n ! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n ! SOFTWARE.\n\n USE mo_kind, ONLY: i4, i8, sp, dp\n USE mo_functions, only: factln, factorial\n\n IMPLICIT NONE\n\n PUBLIC :: binomcoeffi ! Binomial coefficient (n choose k)\n PUBLIC :: random_kofn ! Random selection of k of n\n PUBLIC :: next_kofn ! Next selection of k of n to a given one\n PUBLIC :: all_kofn ! All selections of k of n\n PUBLIC :: random_permut ! Random permutation of a vector\n PUBLIC :: random_index_permut ! Random permutation of (1..n)\n PUBLIC :: next_index_permut ! Next permutation of (1..n) to a given one\n PUBLIC :: all_index_permut ! All permutations of (1..n)\n PUBLIC :: nextpart ! Next partition of n to a given one\n PUBLIC :: prevpart ! Previous partition of n to a given one\n PUBLIC :: isgoodpart ! checks if a given array is a partition of n\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! binomcoeffi\n\n ! PURPOSE\n !\n !> \\brief The binomial coefficient.\n !\n !> \\details Calculates the binomial coefficient (n choose k):\n !> \\f[ C(n,k) = \\frac{n!}{k! (n-k)!} \\f], \n !> i.e. the number of possibilities to select from n numbers k\n !> for real input it also calculates the generalized binomial coefficient which is used for the binomial series\n !> \\f[ C(x,k) = \\prod_{i=1}^k \\frac{x+1-i}{i} \\f],\n ! INTENT(IN)\n !> \\param[in] \"integer(i4/i8)/real(sp,dp) :: n/n(:)/x/x(:)\" from n numbers ...\n !> \\param[in] \"integer(i4/i8) :: k/k(:)\" ... k will be selected\n !\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n ! None\n !\n ! INTENT(IN), OPTIONAL\n ! None\n !\n ! INTENT(INOUT), OPTIONAL\n ! None\n !\n ! INTENT(OUT), OPTIONAL\n ! None\n !\n ! RETURN\n !> \\return integer(i4/i8)/real(sp,dp) :: binomcoeffi/binomcoeffi(:) — Binomial coefficient (n choose k)\n !\n ! RESTRICTIONS\n ! None\n !\n ! EXAMPLE\n ! bico = binomcoeffi(5,2)\n ! bico --> 10\n ! bico = binomcoeffi(1.5,2)\n ! bico --> 0.375\n ! -> see also example in test directory\n\n ! LITERATURE\n ! \n\n ! HISTORY\n !> \\author Matthias Cuntz, Juliane Mai\n !> \\date Feb 2013\n ! Modified, Sebastian Mueller June 2014\n\n INTERFACE binomcoeffi\n MODULE PROCEDURE binomcoeffi_i4_d0, binomcoeffi_i8_d0, binomcoeffi_i4_d1, binomcoeffi_i8_d1,&\n binomcoeffi_sp_d0, binomcoeffi_dp_d0, binomcoeffi_sp_d1, binomcoeffi_dp_d1,&\n binomcoeffi_dpi4_d0, binomcoeffi_dpi4_d1\n END INTERFACE binomcoeffi\n \n ! ------------------------------------------------------------------\n\n ! NAME\n ! all_kofn\n\n ! PURPOSE\n !\n !> \\brief All possible selections of k numbers from n.\n !\n !> \\details Returns all possible selections of a k-subset from n numbers.\n !\n ! INTENT(IN)\n !> \\param[in] \"integer(i4/i8) :: n\" select from n numbers ...\n !> \\param[in] \"integer(i4/i8) :: k\" ... k numbers\n !\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n ! None\n !\n ! INTENT(IN), OPTIONAL\n ! None\n !\n ! INTENT(INOUT), OPTIONAL\n ! None\n !\n ! INTENT(OUT), OPTIONAL\n ! None\n !\n ! RETURN\n !> \\return integer(i4/i8), allocatable, dimension(:,:) :: alle — All selections. Dim_2=k.\n !\n ! RESTRICTIONS\n ! None\n !\n ! EXAMPLE\n ! alle = all_kofn(3, 2)\n ! alle --> (/ (/ 1,2 /), (/ 1,3 /), (/ 2,3 /) /) \n ! -> see also example in test directory\n\n ! LITERATURE\n ! Nijenhuis, A., & Wilf, H. S. (1978). \n ! Combinatorial algorithms for computers and calculators (2nd ed.). \n ! Academic Pr.\n\n ! HISTORY\n !> \\author Juliane Mai\n !> \\date Feb 2013\n ! Modified, \n\n INTERFACE all_kofn\n MODULE PROCEDURE all_kofn_i4, all_kofn_i8\n END INTERFACE all_kofn\n \n ! ------------------------------------------------------------------\n\n ! NAME\n ! next_kofn\n\n ! PURPOSE\n !\n !> \\brief The next selection of k numbers from n to a given one.\n !\n !> \\details Determines the next selection of k numbers from k to a given one.\\n\n !> If one has n=5 numbers and want to pick k=3, the first possible selection is (1,2,3).\n !> The next selection will be (1,2,4). The subsequent selection to (1,3,4) will be (1,3,5).\\n\n !> The given subset (previous) has to be sorted.\n !\n ! INTENT(IN)\n !> \\param[in] \"integer(i4/i8) :: n\" select from n numbers ...\n !> \\param[in] \"integer(i4/i8) :: k\" ... k numbers\n !> \\param[in] \"integer(i4/i8) :: previous(:)\" previous selection (dim_1 = k)\n !\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n ! None\n !\n ! INTENT(IN), OPTIONAL\n ! None\n !\n ! INTENT(INOUT), OPTIONAL\n ! None\n !\n ! INTENT(OUT), OPTIONAL\n ! None\n !\n ! RETURN\n !> \\return integer(i4/i8) :: next(size(previous)) — Next selection of k from n numbers\n !\n ! RESTRICTIONS\n !> \\note The given subset (previous) has to be sorted.\n !\n ! EXAMPLE\n ! next = next_kofn(5, 3, (/1,3,4/))\n ! next --> (/ 1,3,5 /)\n ! -> see also example in test directory\n\n ! LITERATURE\n ! Nijenhuis, A., & Wilf, H. S. (1978). \n ! Combinatorial algorithms for computers and calculators (2nd ed.). \n ! Academic Pr.\n\n ! HISTORY\n !> \\author Giovanni Dalmasso, Juliane Mai\n !> \\date Feb 2013\n ! Modified, \n\n INTERFACE next_kofn\n MODULE PROCEDURE next_kofn_i4, next_kofn_i8\n END INTERFACE next_kofn\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! random_kofn\n\n ! PURPOSE\n !\n !> \\brief A random selection of a k-subset of n numbers (1..n).\n !\n !> \\details Returns a random k-subset of n numbers (1..n).\\n\n !> The returned subset will be sorted.\\n\n !> The code is adapted from Nijenhuis (1978) - routine RANKSB.\n !\n ! INTENT(IN)\n !> \\param[in] \"integer(i4/i8) :: n\" select from n numbers ...\n !> \\param[in] \"integer(i4/i8) :: k\" ... k numbers\n !\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n ! None\n !\n ! INTENT(IN), OPTIONAL\n ! None\n !\n ! INTENT(INOUT), OPTIONAL\n !> \\param[in,out] \"integer(i4/i8), optional :: save_state(n_save_state)\" an array for saving the state \n !> of an uniform random number stream\n !\n ! INTENT(OUT), OPTIONAL\n ! None\n !\n ! RETURN\n !> \\return integer(i4/i8) :: set(k) — Random selection of k from n numbers\n !\n ! RESTRICTIONS\n !> \\note A random number stream for generating uniform random numbers has to be initialized before running this function. \n !\n ! EXAMPLE\n ! set = random_kofn(5, 3)\n ! set --> (/ 2,3,5 /)\n ! -> see also example in test directory\n\n ! LITERATURE\n ! Nijenhuis, A., & Wilf, H. S. (1978). \n ! Combinatorial algorithms for computers and calculators (2nd ed.). \n ! Academic Pr.\n\n ! HISTORY\n !> \\author Juliane Mai\n !> \\date Feb 2013\n ! Modified, \n\n INTERFACE random_kofn\n MODULE PROCEDURE random_kofn_i4 , random_kofn_i8\n END INTERFACE random_kofn\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! all_index_permut\n\n ! PURPOSE\n !\n !> \\brief All possible permutations of n integers 1..n.\n !\n !> \\details Determines all possible permutations of n integers 1..n. \\n\n !> The number of possibilities is the factorial of n (n!).\n !> The code is adapted from Nijenhuis (1978) - routine NEXPER.\n !\n ! INTENT(IN)\n !> \\param[in] \"integer(i4/i8) :: n\" permutation of n integers 1..n\n !\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n ! None\n !\n ! INTENT(IN), OPTIONAL\n ! None\n !\n ! INTENT(INOUT), OPTIONAL\n ! None\n !\n ! INTENT(OUT), OPTIONAL\n ! None\n !\n ! RETURN\n !> \\return integer(i4/i8), allocatable :: permut(:,:) — All permutations of n integers \\n\n !> size(permut,1) = n! \\n\n !> size(permut,2) = n\n !\n ! RESTRICTIONS\n ! None\n !\n ! EXAMPLE\n ! permut = all_index_permut(3)\n ! permut --> (/ (/ 1,2,3 /), (/2,1,3/), (/3,1,2/), (/ 1,3,2 /), (/2,3,1/), (/3,2,1/) /)\n ! -> see also example in test directory\n\n ! LITERATURE\n ! Nijenhuis, A., & Wilf, H. S. (1978). \n ! Combinatorial algorithms for computers and calculators (2nd ed.). \n ! Academic Pr.\n\n ! HISTORY\n !> \\author Juliane Mai\n !> \\date Feb 2013\n ! Modified, \n\n INTERFACE all_index_permut\n MODULE PROCEDURE all_index_permut_i4, all_index_permut_i8\n END INTERFACE all_index_permut\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! next_index_permut\n\n ! PURPOSE\n !\n !> \\brief The next permutation of n integers 1..n to a given one.\n !\n !> \\details Determines the next permutation of n integers 1..n to a given one.\\n\n !> If one has n=5 numbers, the first possible permutation is (1,2,3,4,5).\n !> The next selection will be (2,1,3,4,5). \\n\n !> The code is adapted from Nijenhuis (1978) - routine NEXPER.\n !\n ! INTENT(IN)\n !> \\param[in] \"integer(i4/i8) :: n\" permutation of n integers 1..n\n !> \\param[in] \"integer(i4/i8) :: previous(:)\" previous permutation (dim_1 = n)\n !\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n ! None\n !\n ! INTENT(IN), OPTIONAL\n ! None\n !\n ! INTENT(INOUT), OPTIONAL\n ! None\n !\n ! INTENT(OUT), OPTIONAL\n ! None\n !\n ! RETURN\n !> \\return integer(i4/i8) :: next(n) — Next permutation of n integers\n !\n ! RESTRICTIONS\n ! None\n !\n ! EXAMPLE\n ! next = next_index_permut(5, (/1,2,3,4,5/))\n ! next --> (/ 2,1,3,4,5 /)\n ! -> see also example in test directory\n\n ! LITERATURE\n ! Nijenhuis, A., & Wilf, H. S. (1978). \n ! Combinatorial algorithms for computers and calculators (2nd ed.). \n ! Academic Pr.\n\n ! HISTORY\n !> \\author Juliane Mai\n !> \\date Feb 2013\n ! Modified, \n\n INTERFACE next_index_permut\n MODULE PROCEDURE next_index_permut_i4, next_index_permut_i8\n END INTERFACE next_index_permut\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! random_index_permut\n\n ! PURPOSE\n !\n !> \\brief A random permutation of the integers 1..n.\n !\n !> \\details Returns a random permutation of n numbers (1..n)\\n\n !> The code adapted from the Fortran library of A. Miller.\n !\n ! INTENT(IN)\n !> \\param[in] \"integer(i4/i8) :: n\" permutation of integers 1..n\n !\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n ! None\n !\n ! INTENT(IN), OPTIONAL\n ! None\n !\n ! INTENT(INOUT), OPTIONAL\n !> \\param[in,out] \"integer(i4/i8), optional :: save_state(n_save_state)\" an array for saving the state \n !> of an uniform random number stream\n !\n ! INTENT(OUT), OPTIONAL\n ! None\n !\n ! RETURN\n !> \\return integer(i4/i8) :: set(n) — Random permutation of n integers 1..n\n !\n ! RESTRICTIONS\n !> \\note A random number stream for generating uniform random numbers has to be \n !> initialized before running this function. \n !\n ! EXAMPLE\n ! set = random_index_permut(5, 3)\n ! set --> (/ 2,1,3,5,4 /)\n ! -> see also example in test directory\n\n ! LITERATURE\n ! A. Miller, CSIRO Mathematical & Information Sciences, \n ! Clayton 3169, Victoria, Australia, Version 1.13, 2 October 2000.\n ! http://jblevins.org/mirror/amiller/\n\n ! HISTORY\n !> \\author Matthias Cuntz\n !> \\date Feb 2013\n ! Modified, \n\n INTERFACE random_index_permut\n MODULE PROCEDURE random_index_permut_i4, random_index_permut_i8\n END INTERFACE random_index_permut\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! random_permut\n\n ! PURPOSE\n ! Calculates a random permutation of n numbers\n !\n !> \\brief Random permutation.\n !\n !> \\details Randomly permutes the elements of a given vector.\n !\n ! INTENT(IN)\n ! None\n !\n ! INTENT(INOUT)\n !> \\param[inout] \"integer(i4/i8)/real(sp/dp) :: vec(:)\" 1D-array to be shuffled\n\n ! INTENT(OUT)\n ! None\n !\n ! INTENT(IN), OPTIONAL\n ! None\n !\n ! INTENT(INOUT), OPTIONAL\n !> \\param[in,out] \"integer(i4/i8), optional :: save_state(n_save_state)\" an array for saving the state \n !> of a uniform random number stream\n !\n ! INTENT(OUT), OPTIONAL\n ! None\n !\n ! RETURN\n ! None\n !\n ! RESTRICTIONS\n !> \\note A random number stream for generating uniform random numbers has to be \n !> initialized before running this function. \n !\n ! EXAMPLE\n ! a = (/5,3,2/)\n ! call random_permut(a)\n ! a --> (/ 2,5,3 /)\n ! -> see also example in test directory\n\n ! LITERATURE\n ! Nijenhuis, A., & Wilf, H. S. (1978).\\n\n ! Combinatorial algorithms for computers and calculators (2nd ed.). Academic Pr., p. 63\n ! Algorithm RANPER\n\n ! HISTORY\n !> \\author Stephan Thober, Juliane Mai, Matthias Cuntz\n !> \\date Feb 2013\n\n INTERFACE random_permut\n MODULE PROCEDURE random_permut_i4, random_permut_i8, random_permut_sp, random_permut_dp\n END INTERFACE random_permut\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! nextpart\n\n ! PURPOSE\n ! Calculates the next partition of n to a given one\n !\n !> \\brief next partition of n to a given one\n !\n !> \\details next greater partition of n to a given one where the partitions are sorted by inverse lexicographical ordering\n !> for example: (2,0) > (0,1)\n !\n ! INTENT(IN)\n !> \\param[in] \"integer(i4/i8), dimension(:), intent(in) :: part\" a given partition not equal to (n,0,..,0) [not last]\n !\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n ! None\n !\n ! INTENT(IN), OPTIONAL\n ! None\n !\n ! INTENT(INOUT), OPTIONAL\n ! None\n !\n ! INTENT(OUT), OPTIONAL\n ! None\n !\n ! RETURN\n !> \\return \"integer(i4/i8), dimension(:) :: nextpart\" next partition of n\n !\n ! RESTRICTIONS\n !> \\note the given partiton should not be the greatest one i.e. not (n,0,..,0) \n !\n ! EXAMPLE\n ! nextpart((0,2,0,0)) = (2,1,0,0)\n\n ! LITERATURE\n ! none\n\n\n ! HISTORY\n !> \\author Sebastian Mueller\n !> \\date June 2014\n\n INTERFACE nextpart\n MODULE PROCEDURE nextpart_i4, nextpart_i8\n END INTERFACE nextpart\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! prevpart\n\n ! PURPOSE\n ! Calculates the previous partition of n to a given one\n !\n !> \\brief previous partition of n to a given one\n !\n !> \\details next smaller partition of n to a given one where the partitions are sorted by inverse lexicographical ordering\n !> for example: (2,0) > (0,1)\n !\n ! INTENT(IN)\n !> \\param[in] \"integer(i4/i8), dimension(:), intent(in) :: part\" a given partition not equal to (0,..,0,1) [not first]\n !\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n ! None\n !\n ! INTENT(IN), OPTIONAL\n ! None\n !\n ! INTENT(INOUT), OPTIONAL\n ! None\n !\n ! INTENT(OUT), OPTIONAL\n ! None\n !\n ! RETURN\n !> \\return \"integer(i4/i8), dimension(:) :: prevpart\" previous partition of n\n !\n ! RESTRICTIONS\n !> \\note the given partiton should not be the smallest one i.e. not (0,..,0,1) \n !\n ! EXAMPLE\n ! prevpart((2,1,0,0)) = (0,2,0,0)\n\n ! LITERATURE\n ! none\n\n\n ! HISTORY\n !> \\author Sebastian Mueller\n !> \\date July 2014\n\n INTERFACE prevpart\n MODULE PROCEDURE prevpart_i4, prevpart_i8\n END INTERFACE prevpart\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! isgoodpart\n\n ! PURPOSE\n ! Checks if a given array is a partition of n\n !\n !> \\brief Checks if a given array is a partition of n\n !\n !> \\details Checks if a given array is a partition of n, where p=(p_1,..,p_n) is a partition of n iff\n !> \\f[ \\sum_{i=1}^n p_i*i = p_1 + 2*p_2 + 3*p_3 + .. =n \\f]\n !\n ! INTENT(IN)\n !> \\param[in] \"integer(i4/i8), dimension(:), intent(in) :: part\" a given partition not equal to (n,0,..,0)\n !\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n ! None\n !\n ! INTENT(IN), OPTIONAL\n ! None\n !\n ! INTENT(INOUT), OPTIONAL\n ! None\n !\n ! INTENT(OUT), OPTIONAL\n ! None\n !\n ! RETURN\n !> \\return \"logical :: isgoodpart\"\n !\n ! RESTRICTIONS\n !> \\note the given array should be of dimension greater than one\n !\n ! EXAMPLE\n ! isgoodpart((2,1,0)) = true\n ! isgoodpart((0,2)) = false\n\n ! LITERATURE\n ! none\n\n\n ! HISTORY\n !> \\author Sebastian Mueller\n !> \\date June 2014\n\n INTERFACE isgoodpart\n MODULE PROCEDURE isgoodpart_i4, isgoodpart_i8\n END INTERFACE isgoodpart\n\n ! ------------------------------------------------------------------\n\n PRIVATE\n\n ! ------------------------------------------------------------------\n\nCONTAINS\n\n FUNCTION binomcoeffi_i4_d0(n,k)\n ! Returns the binomial coefficient as an integer number.\n IMPLICIT NONE\n\n INTEGER(i4), INTENT(IN) :: n, k\n INTEGER(i4) :: binomcoeffi_i4_d0\n\n binomcoeffi_i4_d0 = nint(exp(factln(n)-factln(k)-factln(n-k)))\n\n END FUNCTION binomcoeffi_i4_d0\n\n FUNCTION binomcoeffi_i8_d0(n,k)\n ! Returns the binomial coefficient as an integer number.\n IMPLICIT NONE\n\n INTEGER(i8), INTENT(IN) :: n, k\n INTEGER(i8) :: binomcoeffi_i8_d0\n\n binomcoeffi_i8_d0 = nint(exp(factln(n)-factln(k)-factln(n-k)))\n\n END FUNCTION binomcoeffi_i8_d0\n\n FUNCTION binomcoeffi_i4_d1(n,k)\n\n IMPLICIT NONE\n\n INTEGER(i4), DIMENSION(:), INTENT(IN) :: n, k\n INTEGER(i4), DIMENSION(size(n)) :: binomcoeffi_i4_d1\n\n if (size(n) /= size(k)) stop 'Error binomcoeffi: size(n) /= size(k)'\n\n binomcoeffi_i4_d1 = nint(exp(factln(n)-factln(k)-factln(n-k)))\n\n END FUNCTION binomcoeffi_i4_d1\n\n FUNCTION binomcoeffi_i8_d1(n,k)\n\n IMPLICIT NONE\n\n INTEGER(i8), DIMENSION(:), INTENT(IN) :: n, k\n INTEGER(i8), DIMENSION(size(n)) :: binomcoeffi_i8_d1\n\n if (size(n) /= size(k)) stop 'Error binomcoeffi: size(n) /= size(k)'\n\n binomcoeffi_i8_d1 = nint(exp(factln(n)-factln(k)-factln(n-k)))\n\n END FUNCTION binomcoeffi_i8_d1\n\n!generalized binomial coefficient\n FUNCTION binomcoeffi_sp_d0(x,k)\n ! Returns the generalized binomial coefficient as a real number.\n IMPLICIT NONE\n\n real(sp), INTENT(IN) :: x\n INTEGER(i4), INTENT(IN) :: k\n real(sp) :: binomcoeffi_sp_d0\n\n integer(i4) :: i\n \n if (k>0_i4) then \n binomcoeffi_sp_d0 = 1.0_sp \n do i=1_i4,k\n binomcoeffi_sp_d0 = binomcoeffi_sp_d0*(x+1.0_sp-real(i,sp))/real(i,sp)\n end do\n else if (k<0_i4) then\n binomcoeffi_sp_d0 = 0.0_sp\n else\n binomcoeffi_sp_d0 = 1.0_sp\n endif\n \n END FUNCTION binomcoeffi_sp_d0\n\n FUNCTION binomcoeffi_dp_d0(x,k)\n ! Returns the generalized binomial coefficient as a real number.\n IMPLICIT NONE\n\n real(dp), INTENT(IN) :: x\n INTEGER(i8), INTENT(IN) :: k\n real(dp) :: binomcoeffi_dp_d0\n\n integer(i8) :: i\n \n if (k>0_i8) then \n binomcoeffi_dp_d0 = 1.0_sp \n do i=1_i8,k\n binomcoeffi_dp_d0 = binomcoeffi_dp_d0*(x+1.0_dp-real(i,dp))/real(i,dp)\n end do\n else if (k<0_i8) then\n binomcoeffi_dp_d0 = 0.0_dp\n else\n binomcoeffi_dp_d0 = 1.0_dp\n endif\n\n END FUNCTION binomcoeffi_dp_d0\n\n FUNCTION binomcoeffi_sp_d1(x,k)\n\n IMPLICIT NONE\n\n real(sp), DIMENSION(:), INTENT(IN) :: x\n INTEGER(i4), DIMENSION(:), INTENT(IN) :: k\n real(sp), DIMENSION(size(x)) :: binomcoeffi_sp_d1\n\n integer(i4) :: i\n\n if (size(x) /= size(k)) stop 'Error binomcoeffi: size(n) /= size(k)'\n\n do i=1_i4, size(x)\n binomcoeffi_sp_d1(i) = binomcoeffi_sp_d0(x(i),k(i))\n end do\n\n END FUNCTION binomcoeffi_sp_d1\n\n FUNCTION binomcoeffi_dp_d1(x,k)\n\n IMPLICIT NONE\n\n real(dp), DIMENSION(:), INTENT(IN) :: x\n INTEGER(i8), DIMENSION(:), INTENT(IN) :: k\n real(dp), DIMENSION(size(x)) :: binomcoeffi_dp_d1\n\n integer(i8) :: i\n\n if (size(x) /= size(k)) stop 'Error binomcoeffi: size(n) /= size(k)'\n\n do i=1_i8, size(x)\n binomcoeffi_dp_d1(i) = binomcoeffi_dp_d0(x(i),k(i))\n end do\n\n END FUNCTION binomcoeffi_dp_d1\n\n FUNCTION binomcoeffi_dpi4_d0(x,k)\n ! Returns the generalized binomial coefficient as a real number.\n IMPLICIT NONE\n\n real(dp), INTENT(IN) :: x\n INTEGER(i4), INTENT(IN) :: k\n real(dp) :: binomcoeffi_dpi4_d0\n\n integer(i4) :: i\n \n if (k>0_i4) then \n binomcoeffi_dpi4_d0 = 1.0_sp \n do i=1_i4,k\n binomcoeffi_dpi4_d0 = binomcoeffi_dpi4_d0*(x+1.0_dp-real(i,dp))/real(i,dp)\n end do\n else if (k<0_i4) then\n binomcoeffi_dpi4_d0 = 0.0_dp\n else\n binomcoeffi_dpi4_d0 = 1.0_dp\n endif\n\n END FUNCTION binomcoeffi_dpi4_d0\n\n FUNCTION binomcoeffi_dpi4_d1(x,k)\n\n IMPLICIT NONE\n\n real(dp), DIMENSION(:), INTENT(IN) :: x\n INTEGER(i4), DIMENSION(:), INTENT(IN) :: k\n real(dp), DIMENSION(size(x)) :: binomcoeffi_dpi4_d1\n\n integer(i4) :: i\n\n if (size(x) /= size(k)) stop 'Error binomcoeffi: size(n) /= size(k)'\n\n do i=1_i4, size(x)\n binomcoeffi_dpi4_d1(i) = binomcoeffi_dpi4_d0(x(i),k(i))\n end do\n\n END FUNCTION binomcoeffi_dpi4_d1\n\n ! ------------------------------------------------------------------\n\n FUNCTION all_kofn_i4(n, k) result(alle)\n\n IMPLICIT NONE\n\n INTEGER(I4), INTENT(IN) :: n ! from n numbers will be selected\n INTEGER(I4), INTENT(IN) :: k ! k numbers will be selected\n INTEGER(I4), DIMENSION(:,:), allocatable :: alle ! all subsets\n\n ! local variables\n integer(i4) :: bico\n integer(i4) :: i\n\n bico = binomcoeffi(n,k)\n allocate(alle(bico,k))\n\n forall(i=1:k) alle(1,i) = i\n\n do i=2,bico\n alle(i,:) = next_kofn(n, k, alle(i-1,:))\n end do\n\n END FUNCTION all_kofn_i4\n\n FUNCTION all_kofn_i8(n, k) result(alle)\n\n IMPLICIT NONE\n\n INTEGER(I8), INTENT(IN) :: k ! k numbers will be selected\n INTEGER(I8), INTENT(IN) :: n ! from n numbers will be selected\n INTEGER(I8), DIMENSION(:,:), allocatable :: alle ! all subsets\n\n ! local variables\n integer(i8) :: bico\n integer(i8) :: i\n\n bico = binomcoeffi(n,k)\n allocate(alle(bico,k))\n\n forall(i=1:k) alle(1,i) = i\n\n do i=2,bico\n alle(i,:) = next_kofn(n, k, alle(i-1,:))\n end do\n\n END FUNCTION all_kofn_i8\n\n ! ------------------------------------------------------------------\n\n FUNCTION next_kofn_i4(n, k, previous) result(next)\n\n IMPLICIT NONE\n\n INTEGER(I4), INTENT(IN) :: k ! k numbers will be selected\n INTEGER(I4), INTENT(IN) :: n ! from n numbers will be selected\n INTEGER(I4), DIMENSION(k), INTENT(IN) :: previous ! previous subset\n INTEGER(I4), DIMENSION(k) :: next ! next subset\n\n ! local variables\n integer(i4) :: indx\n logical :: found\n integer(i4) :: i\n\n ! find index from the back to start changing the values\n indx = k\n found = .false.\n do while ( (.not. found) .and. (indx .gt. 1) ) \n if ( previous(indx) .eq. n-k+indx ) then\n indx = indx-1\n else\n found = .true.\n end if\n end do\n if( (indx .gt. 1) .or. ( previous(1) .ne. (n-k+1)) ) then\n ! it is a subset in between\n next = previous\n next(indx) = previous(indx) + 1\n forall(i=indx+1:k) next(i) = next(indx) + i-indx\n else\n ! there do not exist a next subset and first one (/1, ..., k/) is returned\n forall(i=1:k) next(i) = i\n end if \n\n END FUNCTION next_kofn_i4\n\n FUNCTION next_kofn_i8(n, k, previous) result(next)\n\n IMPLICIT NONE\n\n INTEGER(I8), INTENT(IN) :: k ! k numbers will be selected\n INTEGER(I8), INTENT(IN) :: n ! from n numbers will be selected\n INTEGER(I8), DIMENSION(k), INTENT(IN) :: previous ! previous subset\n INTEGER(I8), DIMENSION(k) :: next ! next subset\n\n ! local variables\n integer(i8) :: indx\n logical :: found\n integer(i8) :: i\n\n ! find index from the back to start changing the values\n indx = k\n found = .false.\n do while ( (.not. found) .and. (indx .gt. 1) ) \n if ( previous(indx) .eq. n-k+indx ) then\n indx = indx-1\n else\n found = .true.\n end if\n end do\n\n if( (indx .gt. 1) .or. ( previous(1) .ne. (n-k+1)) ) then\n ! it is a subset in between\n next = previous\n next(indx) = previous(indx) + 1\n forall(i=indx+1:k) next(i) = next(indx) + i-indx\n else\n ! there do not exist a next subset and first one (/1, ..., k/) is returned\n forall(i=1:k) next(i) = i\n end if \n\n END FUNCTION next_kofn_i8\n\n ! ------------------------------------------------------------------\n\n FUNCTION random_kofn_i4(n, k, save_state) result(set)\n \n use mo_xor4096, only: xor4096, n_save_state\n\n implicit none\n\n INTEGER(I4), INTENT(IN) :: k ! k numbers will be selected\n INTEGER(I4), INTENT(IN) :: n ! from n numbers will be selected\n INTEGER(I4), DIMENSION(n_save_state), OPTIONAL, INTENT(INOUT) :: save_state ! for saving state of a uniform, sp \n ! ! random number stream\n INTEGER(I4), DIMENSION(k) :: set ! random subset\n\n ! local variables\n logical :: gout\n integer(i4) :: x, r, ds, p, s, c, i, l, m,m0, iseed\n real(sp) :: rn\n\n iseed = 0_i4\n\n ! (A)\n c=k\n forall(i=1:k) set(i) = ((i-1)*n)/k\n \n ! (B)\n do while (c .gt. 0)\n if (present(save_state)) then\n call xor4096(iSeed, rn, save_state=save_state)\n else\n call xor4096(iSeed, rn)\n end if\n x = 1 + int( real(n,sp)*rn, i4 )\n l = 1 + int( real(x*k-1,sp)/real(n,sp), i4 )\n if(x.le.set(l)) cycle\n set(l) = set(l) + 1\n c = c - 1\n end do\n i = 0\n p = 0\n s = k\n m = 0\n\n ! (C)\n gout = .false.\n do while (.not. gout)\n i = i+1\n if (i .gt. k) then\n gout = .true.\n else\n if (set(i) .eq. int(real((i-1)*n,sp)/real(k),i4)) then\n set(i) = 0\n else\n p=p+1\n m=set(i)\n set(i) = 0\n set(p) = m\n end if\n end if\n end do\n\n ! (D)\n gout = .false.\n do while (.not. gout)\n l = 1+int(real(set(p)*k-1,sp)/real(n,sp),i4)\n ds = set(p) - int( real((l-1)*n,sp)/real(k,sp) ,i4)\n set(p) = 0\n set(s) = l\n s=s-ds\n p=p-1\n if (p .le. 0) gout = .true.\n end do\n l = k\n m0 = 1+int(real((set(k)-1)*n,sp)/real(k,sp),i4)\n r = 0\n\n do while( l .ne. 0)\n \n ! (E)\n if (set(l) .ne. 0) then\n r = l\n m0 = 1+int(real((set(l)-1)*n,sp)/real(k,sp),i4)\n m = int(real(set(l)* n, sp) / real(k,sp),i4) - m0 + 1\n end if\n \n ! (F)\n if (present(save_state)) then\n call xor4096(iSeed, rn, save_state=save_state)\n else\n call xor4096(iSeed, rn)\n end if\n x = m0 + int(real(m,sp) * rn,i4)\n i = l\n \n ! (G)\n gout = .false.\n do while (.not. gout)\n i = i + 1\n if (i .le. r) then\n if( x .ge. set(i)) then\n set(i-1) = set(i)\n x = x+1\n else \n gout = .true.\n end if\n else\n gout = .true.\n end if\n end do\n \n ! (H)\n set(i-1) = x\n m = m-1\n l=l-1\n\n end do\n\n END FUNCTION random_kofn_i4\n\n FUNCTION random_kofn_i8(n, k, save_state) result(set)\n \n use mo_xor4096, only: xor4096, n_save_state\n\n implicit none\n\n INTEGER(I8), INTENT(IN) :: k ! k numbers will be selected\n INTEGER(I8), INTENT(IN) :: n ! from n numbers will be selected\n INTEGER(I8), DIMENSION(n_save_state), OPTIONAL, INTENT(INOUT) :: save_state ! for saving state of a uniform, dp \n ! ! random number stream\n INTEGER(I8), DIMENSION(k) :: set ! random subset\n\n ! local variables\n logical :: gout\n integer(i8) :: x, r, ds, p, s, c, i, l, m,m0, iseed\n real(dp) :: rn\n\n iseed = 0_i8\n\n ! (A)\n c=k\n forall(i=1:k) set(i) = ((i-1)*n)/k\n \n ! (B)\n do while (c .gt. 0)\n if (present(save_state)) then\n call xor4096(iSeed, rn, save_state=save_state)\n else\n call xor4096(iSeed, rn)\n end if\n x = 1 + int( real(n,dp)*rn, i8 )\n l = 1 + int( real(x*k-1,dp)/real(n,dp), i8 )\n if(x.le.set(l)) cycle\n set(l) = set(l) + 1\n c = c - 1\n end do\n i = 0_i8\n p = 0_i8\n s = k\n m = 0_i8\n\n ! (C)\n gout = .false.\n do while (.not. gout)\n i = i+1\n if (i .gt. k) then\n gout = .true.\n else\n if (set(i) .eq. int(real((i-1)*n,dp)/real(k),i8)) then\n set(i) = 0\n else\n p=p+1\n m=set(i)\n set(i) = 0\n set(p) = m\n end if\n end if\n end do\n\n ! (D)\n gout = .false.\n do while (.not. gout)\n l = 1+int(real(set(p)*k-1,dp)/real(n,dp),i8)\n ds = set(p) - int( real((l-1)*n,dp)/real(k,dp) ,i8)\n set(p) = 0\n set(s) = l\n s=s-ds\n p=p-1\n if (p .le. 0) gout = .true.\n end do\n l = k\n m0 = 1_i8+int(real((set(k)-1)*n,dp)/real(k,dp),i8)\n r = 0_i8\n\n do while( l .ne. 0)\n \n ! (E)\n if (set(l) .ne. 0) then\n r = l\n m0 = 1+int(real((set(l)-1)*n,dp)/real(k,dp),i8)\n m = int(real(set(l)* n, dp) / real(k,dp),i8) - m0 + 1\n end if\n \n ! (F)\n if (present(save_state)) then\n call xor4096(iSeed, rn, save_state=save_state)\n else\n call xor4096(iSeed, rn)\n end if\n x = m0 + int(real(m,dp) * rn,i8)\n i = l\n \n ! (G)\n gout = .false.\n do while (.not. gout)\n i = i + 1\n if (i .le. r) then\n if( x .ge. set(i)) then\n set(i-1) = set(i)\n x = x+1\n else \n gout = .true.\n end if\n else\n gout = .true.\n end if\n end do\n \n ! (H)\n set(i-1) = x\n m = m-1\n l=l-1\n\n end do\n\n END FUNCTION random_kofn_i8\n\n ! ------------------------------------------------------------------\n\n FUNCTION all_index_permut_i4(n) result(alle)\n\n IMPLICIT NONE\n\n INTEGER(I4), INTENT(IN) :: n ! n numbers will be permuted\n INTEGER(I4), DIMENSION(:,:), allocatable :: alle ! all permutations\n\n ! local variables\n integer(i4) :: fact\n integer(i4) :: i\n\n fact = factorial(n)\n allocate(alle(fact,n))\n\n forall(i=1:n) alle(1,i) = i\n\n do i=2,fact\n alle(i,:) = next_index_permut(n, alle(i-1,:))\n end do\n\n END FUNCTION all_index_permut_i4\n\n FUNCTION all_index_permut_i8(n) result(alle)\n\n IMPLICIT NONE\n\n INTEGER(I8), INTENT(IN) :: n ! n numbers will be permuted\n INTEGER(I8), DIMENSION(:,:), allocatable :: alle ! all permutations\n\n ! local variables\n integer(i8) :: fact\n integer(i8) :: i\n\n fact = factorial(n)\n allocate(alle(fact,n))\n\n forall(i=1:n) alle(1,i) = i\n\n do i=2,fact\n alle(i,:) = next_index_permut(n, alle(i-1,:))\n end do\n\n END FUNCTION all_index_permut_i8\n\n ! ------------------------------------------------------------------\n\n FUNCTION next_index_permut_i4(n, previous) result(next)\n\n implicit none\n\n integer(i4), intent(in) :: n\n integer(i4), dimension(n), intent(in) :: previous\n integer(i4), dimension(n) :: next\n\n ! local variables\n integer(i4) :: i, j\n integer(i4), dimension(n-1) :: s, d\n integer(i4) :: indx, indx2, found_case\n integer(i4) :: largest, smallest\n logical :: last\n\n ! calculate d\n do i=1,n-1\n d(i) = 0\n s(i) = 0\n do j=1,i\n if (previous(j) .gt. previous(i+1)) then\n d(i) = d(i)+1\n end if\n end do\n do j=1, i\n s(i) = s(i) + d(j)\n end do\n end do\n\n ! check if last one\n last = .true.\n if( mod(n,2_i4) .eq. 0_i4 ) then\n ! (a) n odd: last sequence is (2, 3, 4 ... n, 1)\n do i=1,n-1\n last = last .and. (previous(i) .eq. (i+1))\n end do\n last = last .and. (previous(n) .eq. 1)\n else\n ! (b) n even: last sequence is (3, 4, 5, ..., n, 2, 1)\n do i=1,n-2\n last = last .and. (previous(i) .eq. (i+2))\n end do\n last = last .and. (previous(n-1) .eq. 2)\n last = last .and. (previous(n) .eq. 1)\n end if\n if (last) then\n do i=1,n\n next(i) = i\n end do\n ! stop already here\n return\n end if\n \n if ( mod(s(n-1),2_i4) .eq. 0_i4) then\n ! if s(n-1) is even interchange previous(1) and previous(2)\n next = previous\n next(2) = previous(1)\n next(1) = previous(2)\n else\n ! if s(n-1) is odd do some more work...\n ! (1) find index and case: \n ! case 1 : d(indx) < indx && s(indx) odd\n ! case 2 : d(indx) > 0 && s(indx) even\n ! indx where case 1 or 2 fulfilled first time\n found_case = 0_i4\n indx = 0_i4\n do while (found_case .eq. 0_i4)\n indx = indx + 1_i4\n ! case 1 ?\n if ( (mod(s(indx),2_i4) .eq. 1_i4) .and. (d(indx) .lt. indx) ) then\n found_case = 1_i4\n else \n ! case 2 ?\n if( (mod(s(indx),2_i4) .eq. 0_i4) .and. (d(indx) .gt. 0_i4) ) then\n found_case = 2_i4\n end if\n end if\n end do\n ! (2a) case 1 fulfilled: search largest number previous(i),(i=1,indx) \n ! less than previous(indx+1)\n ! (2b) case 2 fulfilled: search smallest number previous(i),(i=1,indx) \n ! greater than previous(indx+1)\n select case(found_case)\n case(1)\n indx2 = indx+1\n largest = 1\n do i=1,indx\n if( (previous(i) .lt. previous(indx+1)) .and. (largest .le. previous(i)) ) then\n indx2 = i\n largest = previous(i)\n end if\n end do\n case(2)\n indx2 = indx+1\n smallest = n\n do i=1,indx\n if( (previous(i) .gt. previous(indx+1)) .and. (smallest .ge. previous(i)) ) then\n indx2 = i\n smallest = previous(i)\n end if\n end do\n case default\n stop 'next_index_permut_i4: something went wrong here'\n end select\n ! (3) swap previous(indx2) and previous(indx+1)\n next = previous\n next(indx2) = previous(indx+1)\n next(indx+1) = previous(indx2)\n end if\n\n END FUNCTION next_index_permut_i4\n\n FUNCTION next_index_permut_i8(n, previous) result(next)\n\n implicit none\n\n integer(i8), intent(in) :: n\n integer(i8), dimension(n), intent(in) :: previous\n integer(i8), dimension(n) :: next\n\n ! local variables\n integer(i8) :: i, j\n integer(i8), dimension(n-1) :: s, d\n integer(i8) :: indx, indx2, found_case\n integer(i8) :: largest, smallest\n logical :: last\n\n ! calculate d\n do i=1,n-1\n d(i) = 0\n s(i) = 0\n do j=1,i\n if (previous(j) .gt. previous(i+1)) then\n d(i) = d(i)+1\n end if\n end do\n do j=1, i\n s(i) = s(i) + d(j)\n end do\n end do\n\n ! check if last one\n last = .true.\n if( mod(n,2_i8) .eq. 0_i8 ) then\n ! (a) n odd: last sequence is (2, 3, 4 ... n, 1)\n do i=1,n-1\n last = last .and. (previous(i) .eq. (i+1))\n end do\n last = last .and. (previous(n) .eq. 1)\n else\n ! (b) n even: last sequence is (3, 4, 5, ..., n, 2, 1)\n do i=1,n-2\n last = last .and. (previous(i) .eq. (i+2))\n end do\n last = last .and. (previous(n-1) .eq. 2)\n last = last .and. (previous(n) .eq. 1)\n end if\n if (last) then\n do i=1,n\n next(i) = i\n end do\n ! stop already here\n return\n end if\n \n if ( mod(s(n-1),2_i8) .eq. 0_i8) then\n ! if s(n-1) is even interchange previous(1) and previous(2)\n next = previous\n next(2) = previous(1)\n next(1) = previous(2)\n else\n ! if s(n-1) is odd do some more work...\n ! (1) find index and case: \n ! case 1 : d(indx) < indx && s(indx) odd\n ! case 2 : d(indx) > 0 && s(indx) even\n ! indx where case 1 or 2 fulfilled first time\n found_case = 0_i8\n indx = 0_i8\n do while (found_case .eq. 0_i8)\n indx = indx + 1_i8\n ! case 1 ?\n if ( (mod(s(indx),2_i8) .eq. 1_i8) .and. (d(indx) .lt. indx) ) then\n found_case = 1_i8\n else \n ! case 2 ?\n if( (mod(s(indx),2_i8) .eq. 0_i8) .and. (d(indx) .gt. 0_i8) ) then\n found_case = 2_i8\n end if\n end if\n end do\n ! (2a) case 1 fulfilled: search largest number previous(i),(i=1,indx) \n ! less than previous(indx+1)\n ! (2b) case 2 fulfilled: search smallest number previous(i),(i=1,indx) \n ! greater than previous(indx+1)\n select case(found_case)\n case(1)\n indx2 = indx+1\n largest = 1\n do i=1,indx\n if( (previous(i) .lt. previous(indx+1)) .and. (largest .le. previous(i)) ) then\n indx2 = i\n largest = previous(i)\n end if\n end do\n case(2)\n indx2 = indx+1\n smallest = n\n do i=1,indx\n if( (previous(i) .gt. previous(indx+1)) .and. (smallest .ge. previous(i)) ) then\n indx2 = i\n smallest = previous(i)\n end if\n end do\n case default\n stop 'next_index_permut_i8: something went wrong here'\n end select\n ! (3) swap previous(indx2) and previous(indx+1)\n next = previous\n next(indx2) = previous(indx+1)\n next(indx+1) = previous(indx2)\n end if\n\n END FUNCTION next_index_permut_i8\n\n ! ------------------------------------------------------------------\n\n SUBROUTINE random_permut_i4(vec, save_state)\n !\n ! Generate a random permuation of the inout vector vec\n !\n use mo_xor4096, only: xor4096, n_save_state\n\n implicit none\n\n INTEGER(i4), DIMENSION(:), INTENT(INOUT) :: vec\n INTEGER(i4), DIMENSION(n_save_state), OPTIONAL, INTENT(INOUT) :: save_state\n\n ! Local variables\n INTEGER(i4) :: l, m, nvec\n INTEGER(i4) :: iSeed\n INTEGER(i4) :: L1\n REAL(sp) :: rn\n\n iSeed = 0_i4\n\n nvec = size(vec)\n do m = 1, nvec\n if (present(save_state)) then\n call xor4096(iSeed, rn, save_state=save_state)\n else\n call xor4096(iSeed, rn)\n end if\n l = m + int(rn * real(nvec + 1 - m, sp), i4)\n L1 = vec(l)\n vec(l) = vec(m)\n vec(m) = L1\n end do\n\n END SUBROUTINE random_permut_i4\n\n SUBROUTINE random_permut_i8(vec, save_state)\n !\n ! Generate a random permuation of the inout vector vec\n !\n use mo_xor4096, only: xor4096, n_save_state\n\n implicit none\n\n INTEGER(i8), DIMENSION(:), INTENT(INOUT) :: vec\n INTEGER(i8), DIMENSION(n_save_state), OPTIONAL, INTENT(INOUT) :: save_state\n\n ! Local variables\n INTEGER(i4) :: l, m, nvec\n INTEGER(i8) :: iSeed\n INTEGER(i8) :: L1\n REAL(dp) :: rn\n\n iSeed = 0_i8\n\n nvec = size(vec)\n do m = 1, nvec\n if (present(save_state)) then\n call xor4096(iSeed, rn, save_state=save_state)\n else\n call xor4096(iSeed, rn)\n end if\n l = m + int(rn * real(nvec + 1 - m, dp), i4)\n L1 = vec(l)\n vec(l) = vec(m)\n vec(m) = L1\n end do\n\n END SUBROUTINE random_permut_i8\n\n SUBROUTINE random_permut_sp(vec, save_state)\n !\n ! Generate a random permuation of the inout vector vec\n !\n use mo_xor4096, only: xor4096, n_save_state\n\n implicit none\n\n REAL(sp), DIMENSION(:), INTENT(INOUT) :: vec\n INTEGER(i4), DIMENSION(n_save_state), OPTIONAL, INTENT(INOUT) :: save_state\n\n ! Local variables\n INTEGER(i4) :: l, m, nvec\n INTEGER(i4) :: iSeed\n REAL(sp) :: L1\n REAL(sp) :: rn\n\n iSeed = 0_i4\n\n nvec = size(vec)\n do m = 1, nvec\n if (present(save_state)) then\n call xor4096(iSeed, rn, save_state=save_state)\n else\n call xor4096(iSeed, rn)\n end if\n l = m + int(rn * real(nvec + 1 - m, sp), i4)\n L1 = vec(l)\n vec(l) = vec(m)\n vec(m) = L1\n end do\n\n END SUBROUTINE random_permut_sp\n\n SUBROUTINE random_permut_dp(vec, save_state)\n !\n ! Generate a random permuation of the inout vector vec\n !\n use mo_xor4096, only: xor4096, n_save_state\n\n implicit none\n\n REAL(dp), DIMENSION(:), INTENT(INOUT) :: vec\n INTEGER(i8), DIMENSION(n_save_state), OPTIONAL, INTENT(INOUT) :: save_state\n\n ! Local variables\n INTEGER(i4) :: l, m, nvec\n INTEGER(i8) :: iSeed\n REAL(dp) :: L1\n REAL(dp) :: rn\n\n iSeed = 0_i8\n\n nvec = size(vec)\n do m = 1, nvec\n if (present(save_state)) then\n call xor4096(iSeed, rn, save_state=save_state)\n else\n call xor4096(iSeed, rn)\n end if\n l = m + int(rn * real(nvec + 1 - m, dp), i4)\n L1 = vec(l)\n vec(l) = vec(m)\n vec(m) = L1\n end do\n\n END SUBROUTINE random_permut_dp\n\n ! ------------------------------------------------------------------\n\n FUNCTION random_index_permut_i4(n, save_state)\n !\n ! Generate a random ordering of the integers 1 ... n.\n !\n use mo_xor4096, only: n_save_state\n\n implicit none\n\n INTEGER(i4), INTENT(IN) :: n\n INTEGER(i4), DIMENSION(n_save_state), OPTIONAL, INTENT(INOUT) :: save_state\n INTEGER(i4), DIMENSION(n) :: random_index_permut_i4\n\n INTEGER(i4) :: i\n\n forall(i=1:n) random_index_permut_i4(i) = i\n if (present(save_state)) then\n call random_permut(random_index_permut_i4, save_state=save_state)\n else\n call random_permut(random_index_permut_i4)\n endif\n\n END FUNCTION random_index_permut_i4\n\n FUNCTION random_index_permut_i8(n, save_state)\n !\n ! Generate a random ordering of the integers 1 ... n.\n !\n use mo_xor4096, only: n_save_state\n\n implicit none\n\n INTEGER(i8), INTENT(IN) :: n\n INTEGER(i8), DIMENSION(n_save_state), OPTIONAL, INTENT(INOUT) :: save_state\n INTEGER(i8), DIMENSION(n) :: random_index_permut_i8\n\n INTEGER(i8) :: i\n\n forall(i=1_i8:n) random_index_permut_i8(i) = i\n if (present(save_state)) then\n call random_permut(random_index_permut_i8, save_state=save_state)\n else\n call random_permut(random_index_permut_i8)\n endif\n\n END FUNCTION random_index_permut_i8\n\n ! ------------------------------------------------------------------\n\n function nextpart_i4(part)\n\n implicit none\n\n integer(i4), dimension(:), intent(in) :: part \n integer(i4), dimension(size(part)) :: nextpart_i4\n \n integer(i4) :: n, firstindex, summ, temp\n\n\n !Check if input is valid\n if (.not. isgoodpart(part)) stop 'Not a valid input partition.'\n if (part(1) .eq. size(part)) stop 'Input was the last possible partition.'\n\n nextpart_i4 = part \n\n !set the first entry to zero and remember it\n temp = nextpart_i4(1)\n nextpart_i4(1) = 0_i4 \n\n !search for the first index that is not equal to zero\n firstindex = 1_i4\n do n = 2_i4, size(nextpart_i4)\n if (nextpart_i4(n) .ne. 0_i4) then\n firstindex = n\n exit\n endif\n end do\n\n !decrease the first entry that is not equal to zero by one\n nextpart_i4(firstindex) = nextpart_i4(firstindex)-1_i4\n\n !calculate the actual sum of the partition\n summ = size(nextpart_i4)-firstindex-temp\n\n !fill up the partition below the index from above, until the sum equals n again \n do n=firstindex-1_i4,1_i4,-1_i4\n temp = nextpart_i4(n)\n !set the next entry as big as possible\n nextpart_i4(n) = FLOOR(real(size(nextpart_i4)-summ,sp)/real(n,sp))\n !calculate the actual sum of the partition\n summ = summ + n*(nextpart_i4(n) - temp) \n !if the sum is n we are done\n if (summ == size(nextpart_i4)) exit\n end do\n\n end function nextpart_i4\n\n function nextpart_i8(part)\n\n implicit none\n\n integer(i8), dimension(:), intent(in) :: part \n integer(i8), dimension(size(part)) :: nextpart_i8\n \n integer(i8) :: n, firstindex, summ, temp\n\n\n !Check if input is valid\n if (.not. isgoodpart(part)) stop 'Not a valid input partition.'\n if (part(1) .eq. size(part)) stop 'Input was the last possible partition.'\n\n nextpart_i8 = part \n\n !set the first entry to zero and remember it\n temp = nextpart_i8(1)\n nextpart_i8(1) = 0_i8 \n\n !search for the first index that is not equal to zero\n firstindex = 1_i8\n do n = 2_i8, size(nextpart_i8)\n if (nextpart_i8(n) .ne. 0_i8) then\n firstindex = n\n exit\n endif\n end do\n\n !decrease the first entry that is not equal to zero by one\n nextpart_i8(firstindex) = nextpart_i8(firstindex)-1_i8\n\n !calculate the actual sum of the partition\n summ = size(nextpart_i8)-firstindex-temp\n\n !fill up the partition below the index from above, until the sum equals n again \n do n=firstindex-1_i8,1_i8,-1_i8\n temp = nextpart_i8(n)\n !set the next entry as big as possible\n nextpart_i8(n) = FLOOR(real(size(nextpart_i8)-summ,dp)/real(n,dp))\n !calculate the actual sum of the partition\n summ = summ + n*(nextpart_i8(n) - temp) \n !if the sum is n we are done\n if (summ == size(nextpart_i8)) exit\n end do\n\n end function nextpart_i8\n\n ! ------------------------------------------------------------------\n\n function prevpart_i4(part)\n\n implicit none\n\n integer(i4), dimension(:), intent(in) :: part \n integer(i4), dimension(size(part)) :: prevpart_i4\n \n integer(i4) :: n, summ\n\n\n !Check if input is valid\n if (.not. isgoodpart(part)) stop 'Not a valid input partition.'\n if (part(size(part)) .eq. 1_i4) stop 'Input was the first possible partition.'\n\n prevpart_i4 = part \n\n summ = size(prevpart_i4)\n\n do n = 1_i4, size(prevpart_i4)\n if (summ + n .gt. size(prevpart_i4)) then\n if (prevpart_i4(n) .ne. 0_i4) then\n summ = summ - prevpart_i4(n)*n\n prevpart_i4(n) = 0_i4\n endif\n else\n !increase the first entry that is increasable\n prevpart_i4(n) = prevpart_i4(n)+1_i4\n !correct the remainder by filling up 1's\n prevpart_i4(1) = size(prevpart_i4) - summ - n\n return\n endif\n end do\n\n end function prevpart_i4\n\n function prevpart_i8(part)\n\n implicit none\n\n integer(i8), dimension(:), intent(in) :: part \n integer(i8), dimension(size(part)) :: prevpart_i8\n \n integer(i8) :: n, summ\n\n\n !Check if input is valid\n if (.not. isgoodpart(part)) stop 'Not a valid input partition.'\n if (part(size(part)) .eq. 1_i8) stop 'Input was the first possible partition.'\n\n prevpart_i8 = part \n\n summ = size(prevpart_i8)\n\n do n = 1_i8, size(prevpart_i8)\n if (summ + n .gt. size(prevpart_i8)) then\n if (prevpart_i8(n) .ne. 0_i8) then\n summ = summ - prevpart_i8(n)*n\n prevpart_i8(n) = 0_i8\n endif\n else\n !increase the first entry that is increasable\n prevpart_i8(n) = prevpart_i8(n)+1_i8\n !correct the remainder by filling up 1's\n prevpart_i8(1) = size(prevpart_i8) - summ - n\n return\n endif\n end do\n\n end function prevpart_i8\n\n ! ------------------------------------------------------------------\n\n function isgoodpart_i4(part)\n\n implicit none\n\n integer(i4), dimension(:), intent(in) :: part \n logical :: isgoodpart_i4\n \n integer(i4) :: n, testn\n \n isgoodpart_i4 = .false.\n testn = 0_i4\n\n if (size(part) .le. 1_i4) stop 'n must be at least 2'\n\n !check if p_i >= 0\n if (any(part<0_i4)) return\n\n !Check if it is a partition: sum(i*p_i)=n\n do n=size(part),1_i4,-1_i4\n testn = testn+n*part(n)\n if (testn > size(part)) return\n end do\n \n if (testn==size(part)) isgoodpart_i4 = .true.\n \n end function isgoodpart_i4\n \n function isgoodpart_i8(part)\n\n implicit none\n\n integer(i8), dimension(:), intent(in) :: part \n logical :: isgoodpart_i8\n \n integer(i8) :: n, testn\n \n isgoodpart_i8 = .false.\n testn = 0_i8\n\n if (size(part) .le. 1_i8) stop 'n must be at least 2'\n\n !check if p_i >= 0\n if (any(part<0_i8)) return\n\n !Check if it is a partition: sum(i*p_i)=n\n do n=size(part),1_i8,-1_i8\n testn = testn+n*part(n)\n if (testn > size(part)) return\n end do\n \n if (testn==size(part)) isgoodpart_i8 = .true.\n \n end function isgoodpart_i8\n \nEND MODULE mo_combinatorics\n", "meta": {"hexsha": "8362a327b24c2f3ad8e627f8a006183a8dc7ddd0", "size": 55448, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/test_mo_sampling/mo_combinatorics.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_sampling/mo_combinatorics.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_laplace_inversion/mo_combinatorics.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": 29.1831578947, "max_line_length": 131, "alphanum_fraction": 0.5058613476, "num_tokens": 16485, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711832583695, "lm_q2_score": 0.8031738057795403, "lm_q1q2_score": 0.6826745900605637}} {"text": " module m_select\n !! Perform a quickselect on an array. Quick select finds the kth smallest number in an array. It also puts values lower than the kth on the left, and those higher on the right\n !! This makes it perfect for finding the median.\n use variableKind\n\n implicit none\n\n private\n\n public :: select\n\n interface select\n !!Use an in-place quick select on an array of numbers\n !!\n !!Example usage\n !!```fortran\n !!program selectTest\n !!use variableKind\n !!use m_strings, only: str\n !!use m_allocate, only: allocate\n !!use m_random, only: rngInteger,rngNormal\n !!use m_select, only: select\n !!real(r64),allocatable :: d1D(:)\n !!integer(i32),allocatable :: i1D(:)\n !!integer(i32) :: k\n !!real(r64) :: dv\n !!integer(i32) :: iv\n !!\n !!write(*,'(a)') 'Select the kth smallest element from a 10000 length array of random double precision numbers'\n !!call allocate(d1D, 10000)\n !!call rngNormal(d1D)\n !!k = (1+size(d1D))/2\n !!dv = select(d1D,k)\n !!write(*,'(a)') 'kth element? '//str(dv)\n !!write(*,'(a)') 'Select the kth smallest element from a 10000 length array of random integers''\n !!call allocate(i1D, 10000)\n !!call rngInteger(i1D)\n !!iv = select(i1D, k)\n !!write(*,'(a)') 'kth element? '//str(iv)\n !!end program\n !!```\n module subroutine quickSelect_i1D(this, k, res)\n !! Interfaced with select()\n integer(i32), intent(inout) :: this(:) !! Array to choose kth smallest from\n integer(i32), intent(in) :: k !! kth smallest element\n integer(i32) :: res\n end subroutine\n module subroutine quickSelect_id1D(this, k, res)\n !! Interfaced with select()\n integer(i64), intent(inout) :: this(:) !! Array to choose kth smallest from\n integer(i32), intent(in) :: k !! kth smallest element\n integer(i64) :: res\n end subroutine\n module subroutine quickSelect_r1D(this, k, res)\n !! Interfaced with select()\n real(r32), intent(inout) :: this(:) !! Array to choose kth smallest from\n integer(i32), intent(in) :: k !! kth smallest element\n real(r32) :: res\n end subroutine\n module subroutine quickSelect_d1D(this, k, res)\n !! Interfaced with select()\n real(r64), intent(inout) :: this(:) !! Array to choose kth smallest from\n integer(i32), intent(in) :: k !! kth smallest element\n real(r64) :: res\n end subroutine\n end interface\n\n public :: argSelect\n\n interface argSelect\n !!Use an indirect introspection sort on an array of numbers\n !!\n !!Example usage\n !!```fortran\n !!program argSortTest\n !!use variableKind\n !!use m_strings, only: str\n !!use m_random, only: rngInteger,rngNormal\n !!use m_arrays, only: isSorted\n !!use m_Sort, only: argSort\n !!real(r64),allocatable :: d1D(:)\n !!integer(i32),allocatable :: i1D(:)\n !!integer(i32),allocatable :: indx(:)\n !!integer(i32) :: i, k, N\n !!N = 10000\n !!call allocate(indx,N)\n !!call arange(indx, 1, N)\n !!call allocate(d1D,N)\n !!call rngNormal(d1D)\n !!k = (size(d1D)+1)/2\n !!call argSelect(d1D, indx, k)\n !!write(*,'(a)') 'Double array is indirectly sorted? '//str(isSorted(d1D(indx)))\n !!\n !!call arange(indx, 1, N)\n !!call allocate(i1D,N)\n !!call rngInteger(i1D)\n !!call argSelectt(i1D, indx, k)\n !!write(*,'(a)') 'Integer array is indirectly sorted? '//str(isSorted(i1D(indx)))\n !!end program\n !!```\n module subroutine argQuickSelect_i1D(this, indx, k, res, left, right)\n !! Interfaced with argSelect()\n integer(i32), intent(in) :: this(:) !! 1D array\n integer(i32), intent(inout) :: indx(:) !! Index to choose kth smallest from\n integer(i32), intent(in) :: k !! kth smallest element\n integer(i32) :: res !! Index of the kth smallest element\n integer(i32), intent(in), optional :: left !! Select over the region left:right\n integer(i32), intent(in), optional :: right !! Select over the region left:right\n end subroutine\n module subroutine argQuickSelect_id1D(this, indx, k, res, left, right)\n !! Interfaced with argSelect()\n integer(i64), intent(in) :: this(:) !! 1D array\n integer(i32), intent(inout) :: indx(:) !! Index to choose kth smallest from\n integer(i32), intent(in) :: k !! kth smallest element\n integer(i32) :: res !! Index of the kth smallest element\n integer(i32), intent(in), optional :: left !! Select over the region left:right\n integer(i32), intent(in), optional :: right !! Select over the region left:right\n end subroutine\n module subroutine argQuickSelect_r1D(this, indx, k, res, left, right)\n !! Interfaced with argSelect()\n real(r32), intent(in) :: this(:) !! 1D array\n integer(i32), intent(inout) :: indx(:) !! Index to choose kth smallest from\n integer(i32), intent(in) :: k !! kth smallest element\n integer(i32) :: res !! Index of the kth smallest element\n integer(i32), intent(in), optional :: left !! Select over the region left:right\n integer(i32), intent(in), optional :: right !! Select over the region left:right\n end subroutine\n module subroutine argQuickSelect_d1D(this, indx, k, res, left, right)\n !! Interfaced with argSelect()\n real(r64), intent(in) :: this(:) !! 1D array\n integer(i32), intent(inout) :: indx(:) !! Index to choose kth smallest from\n integer(i32), intent(in) :: k!! kth smallest element\n integer(i32) :: res !! Index of the kth smallest element\n integer(i32), intent(in), optional :: left !! Select over the region left:right\n integer(i32), intent(in), optional :: right !! Select over the region left:right\n end subroutine\n end interface\n\n end module\n", "meta": {"hexsha": "89c15b76d0392467f7fab29aa1149e784fb151c4", "size": 5708, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "docs/src/m_select.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": "docs/src/m_select.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": "docs/src/m_select.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": 40.7714285714, "max_line_length": 179, "alphanum_fraction": 0.6343728101, "num_tokens": 1613, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.849971190859164, "lm_q2_score": 0.8031737892899222, "lm_q1q2_score": 0.6826745821496224}} {"text": "PROGRAM EXAMPLE\n\n! -- LAPACK95 EXAMPLE DRIVER ROUTINE (VERSION 1.0) --\n! UNI-C, DENMARK\n! DECEMBER, 1999\n!\n! .. \"Use Statements\" ..\nUSE LA_PRECISION, ONLY: WP => dp\nUSE F95_LAPACK, ONLY: LA_GESVX\n! .. \"Implicit Statement\" ..\nIMPLICIT NONE\n! .. \"Local Scalars\" ..\nINTEGER :: I, J, N, NRHS, u, info\n! .. \"Local Arrays\" ..\nINTEGER, ALLOCATABLE :: IPIV(:)\nREAL(WP) :: RCOND, RPVGRW\nREAL(WP), ALLOCATABLE :: A(:,:), AA(:,:), B(:,:), X(:,:),BB(:,:), FERR(:), BERR(:)\nREAL(WP), ALLOCATABLE :: RR(:,:)\ncharacter(1024) :: argv\n\n! .. \"Executable Statements\" ..\nprint *, 'SGESVX Example Program Results.'\n\nN = 4\nNRHS = 3\n\nALLOCATE( A(N,N), AA(N,N), B(N,NRHS), X(N,NRHS),BB(N,NRHS), IPIV(N), RR(N,N), FERR(NRHS), BERR(NRHS) )\n\ncall get_command_argument(1,argv)\n\nOPEN(newunit=u,FILE=trim(argv)//'/gesv.ma',STATUS='old')\nDO J=1,N\nDO I=1,N \n READ(u,'(F2.0)') AA(I,J)\nENDDO \nENDDO\nCLOSE(u)\n\n! DO I = 1, N; READ (*, *) (RR(I, J), J = 1, N); ENDDO\n! AA=RR\n\nDO J = 1, NRHS; BB(:,J) = SUM( AA, DIM=2)*J; ENDDO\n\nprint *, 'The matrix A:'\nDO I=1,N; WRITE(*,\"(4(I3,1X),I3,1X)\") INT(AA(I,:)); ENDDO\n\nprint *, 'The RHS matrix B:'\nDO I=1,N; WRITE(*,\"(2(I3,1X),I3,1X)\") INT(BB(I,:)); ENDDO\n \nA=AA; B=BB\nCALL LA_GESVX( A, B, X, FERR=FERR, BERR=BERR, RCOND=RCOND, RPVGRW=RPVGRW, info=info )\n\nprint *, 'FERR = ', FERR\nprint *, 'BERR = ', BERR\nprint *, 'RCOND = ', RCOND\nprint *, 'RPVGRW = ', RPVGRW\n\nprint *, '\\noindent'\nprint *, 'The solution of the system $ A\\,X = B $ is:'\nprint *, '$$ X = \\left( \\begin{array}{rrr}'\nDO I=1,N; WRITE(*,\"(2(F9.5,' & '),F9.5,' \\\\')\") X(I,:); ENDDO\nprint *, '\\end{array} \\right). $$'\n\nstop info\n\nEND PROGRAM\n", "meta": {"hexsha": "b45ee83aeee6be75b538f7a4fb5d486a07c4610b", "size": 1638, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "EXAMPLES1/la_gesvx_example.f90", "max_stars_repo_name": "MattBurn/LAPACK95", "max_stars_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "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": "EXAMPLES1/la_gesvx_example.f90", "max_issues_repo_name": "MattBurn/LAPACK95", "max_issues_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "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": "EXAMPLES1/la_gesvx_example.f90", "max_forks_repo_name": "MattBurn/LAPACK95", "max_forks_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "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.447761194, "max_line_length": 102, "alphanum_fraction": 0.5702075702, "num_tokens": 676, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711604559848, "lm_q2_score": 0.8031737963569016, "lm_q1q2_score": 0.6826745637373144}} {"text": "module math_vars\nimplicit none\n\tinteger, parameter :: nfac = 301\n\treal(kind=8) :: fact(0:nfac)\n\treal(kind=8) :: identity(4,4)\n\t\n\treal(kind=8), parameter :: L_weideman = 2.2248028d0\n\treal(kind=8), parameter :: a_weideman(7) = (/1.0547115,0.60504614,0.20181603,0.0080914418,-0.021688188,-0.0038423489,0.0030903311/) \nend module math_vars\n\n\nmodule math_functions\nuse math_vars\nuse vars\nimplicit none\ncontains\n\t\t\n!----------------------------------------------------------------\n! Calculates the factorial of the integers up to 301 and save it into the fact array\n!----------------------------------------------------------------\n subroutine factrl\n\tinteger :: i\n fact(0) = 1.d0\n do i=1,301\n\t\t\tfact(I) = fact(I-1) * dble(I)\n\t\tenddo\n END subroutine factrl\n\n!----------------------------------------------------------------\n! This function calculates the 3-j symbol\n! J_i and M_i have to be twice the actual value of J and M\n!----------------------------------------------------------------\n function w3js(j1,j2,j3,m1,m2,m3)\n integer :: m1, m2, m3, j1, j2, j3\n\tinteger :: ia, ib, ic, id, ie, im, ig, ih, z, zmin, zmax, jsum\n\treal(kind=8) :: w3js, cc, denom, cc1, cc2\n\n!\t\tw3js = w3js_regge(j1/2,j2/2,j3/2,m1/2,m2/2,m3/2)\n!\t\treturn\n w3js = 0.d0\n if (m1+m2+m3 /= 0) return\n ia = j1 + j2\n if (j3 > ia) return\n ib = j1 - j2\n if (j3 < abs(ib)) return\n\t\tif (abs(m1) > j1) return\n\t\tif (abs(m2) > j2) return\n\t\tif (abs(m3) > j3) return\n\t\t\n jsum = j3 + ia\n ic = j1 - m1\n id = j2 - m2\n \n\t\tie = j3 - j2 + m1\n\t\tim = j3 - j1 - m2\n\t\tzmin = max0(0,-ie,-im)\n\t\tig = ia - j3\n\t\tih = j2 + m2\n\t\tzmax = min0(ig,ih,ic)\n\t\tcc = 0.d0\n\n\t\tdo z = zmin, zmax, 2\n\t\t\tdenom = fact(z/2)*fact((ig-z)/2)*fact((ic-z)/2)*fact((ih-z)/2)*&\n\t\t\t\tfact((ie+z)/2)*fact((im+z)/2)\n \tif (mod(z,4) /= 0) denom = -denom\n\t\t\tcc = cc + 1.d0/denom\n\t\tenddo\n\n\t\tcc1 = fact(ig/2)*fact((j3+ib)/2)*fact((j3-ib)/2)/fact((jsum+2)/2)\n cc2 = fact((j1+m1)/2)*fact(ic/2)*fact(ih/2)*fact(id/2)*fact((j3-m3)/2)*fact((j3+m3)/2)\n cc = cc * sqrt(1.d0*cc1*cc2)\n\t\tif (mod(ib-m3,4) /= 0) cc = -cc\n\t\tw3js = cc\n\t\tif (abs(w3js) < 1.d-8) w3js = 0.d0\t\t\n1000 \t\treturn\n end function w3js\n\t\t\t\n!--------------------------------------------------------------\n! Generates Voigt and anomalous dispersion profiles\n! See Humlicek (1982) JQSRT 27, 437\n!--------------------------------------------------------------\n\tfunction fvoigt(da, dv)\n\treal*8 :: da\n\treal*8 :: dv(:), fvoigt(size(dv))\n\tcomplex :: w4, z, t, u, v4\n\treal*8 :: s\n\tinteger :: i, n\n\t\t\n\t\tn = size(dv)\n\t\tdo i = 1, n\n\t\t\tz = cmplx(dv(i), da)\n\t\t\tt = cmplx(da, -dv(i))\n\t\t\ts = dabs(dv(i)) + da\n\t\t\tu = t*t\n\n\n\t\t\tif (s >= 15.d0) then\n\t\t\t\tw4 = t * 0.5641896d0 / (0.5d0+u)\n\t\t\telseif (s >= 5.5) then\n\t\t\t\tw4 = t*(1.410474d0+u*0.5641896d0)/(0.75d0+u*(3.d0+u))\n\t\t\telseif (da >= 0.195d0*dabs(dv(i))-0.176d0) then\n\t\t\t\tw4 = (16.4955d0+t*(20.20933d0+t*(11.96482d0+t*(3.778987d0+t*0.5642236d0)))) / &\n\t\t\t\t\t(16.4955d0+t*(38.82363d0+t*(39.27121d0+t*(21.69274d0+t*(6.699398d0+t)))))\n\t\t\telse \n\t\t\t\tw4 = t*(36183.31d0-u*(3321.9905d0-u*(1540.787d0-u*(219.0313d0-u*(35.76683d0-&\n\t\t\t\t\tu*(1.320522d0-u*0.56419d0))))))\n\t\t\t\tv4 = (32066.6d0-u*(24322.84d0-u*(9022.228d0-u*(2186.181d0-u*(364.2191d0-&\n\t\t\t\t\tu*(61.57037d0-u*(1.841439d0-u)))))))\n\t\t\t\tw4 = cexp(u) - w4/v4\n\t\t\tendif\n\t\t\tfvoigt(i) = dble(w4)\n\t\tenddo \n\nend function fvoigt\n\n!--------------------------------------------------------------\n! Generates Voigt and anomalous dispersion profiles\n! See Humlicek (1982) JQSRT 27, 437\n!--------------------------------------------------------------\n\tfunction fvoigt_zeeman(da, dv)\n\treal*8 :: da\n\treal*8 :: dv(:), fvoigt_zeeman(2,size(dv))\n\tcomplex :: w4, z, t, u, v4\n\treal*8 :: s\n\tinteger :: i, n\n\t\t\n\t\tn = size(dv)\n\t\tdo i = 1, n\n\t\t\tz = cmplx(dv(i), da)\n\t\t\tt = cmplx(da, -dv(i))\n\t\t\ts = dabs(dv(i)) + da\n\t\t\tu = t*t\n\n\n\t\t\tif (s >= 15.d0) then\n\t\t\t\tw4 = t * 0.5641896d0 / (0.5d0+u)\n\t\t\telseif (s >= 5.5) then\n\t\t\t\tw4 = t*(1.410474d0+u*0.5641896d0)/(0.75d0+u*(3.d0+u))\n\t\t\telseif (da >= 0.195d0*dabs(dv(i))-0.176d0) then\n\t\t\t\tw4 = (16.4955d0+t*(20.20933d0+t*(11.96482d0+t*(3.778987d0+t*0.5642236d0)))) / &\n\t\t\t\t\t(16.4955d0+t*(38.82363d0+t*(39.27121d0+t*(21.69274d0+t*(6.699398d0+t)))))\n\t\t\telse \n\t\t\t\tw4 = t*(36183.31d0-u*(3321.9905d0-u*(1540.787d0-u*(219.0313d0-u*(35.76683d0-&\n\t\t\t\t\tu*(1.320522d0-u*0.56419d0))))))\n\t\t\t\tv4 = (32066.6d0-u*(24322.84d0-u*(9022.228d0-u*(2186.181d0-u*(364.2191d0-&\n\t\t\t\t\tu*(61.57037d0-u*(1.841439d0-u)))))))\n\t\t\t\tw4 = cexp(u) - w4/v4\n\t\t\tendif\n\t\t\tfvoigt_zeeman(1,i) = dble(w4)\n\t\t\tfvoigt_zeeman(2,i) = aimag(w4)\n\t\tenddo \n\n\tend function fvoigt_zeeman\t\t\n\t\n!--------------------------------------------------------------\n! Generates Voigt and anomalous dispersion profiles using a different damping for each frequency\n! point\n! See Humlicek (1982) JQSRT 27, 437\n!--------------------------------------------------------------\n\tfunction vecfvoigt(da, dv)\n\treal*8 :: da(:)\n\treal*8 :: dv(:), vecfvoigt(size(dv))\n\tcomplex :: w4, z, t, u, v4\n\treal*8 :: s\n\tinteger :: i, n\n \n\t\tn = size(dv)\n\t\tdo i = 1, n\n! There is a problem for very small dampings. We force it to be 0 using a threshold \n\t\t\tif (da(i) < 1.d-3) da(i) = 0.d0\n\t\t\tz = cmplx(dv(i), da(i))\n\t\t\tt = cmplx(da(i), -dv(i))\n\t\t\ts = dabs(dv(i)) + da(i)\n\t\t\tu = t*t\n\n\n\t\t\tif (s >= 15.d0) then\n\t\t\t\tw4 = t * 0.5641896d0 / (0.5d0+u)\n\t\t\telseif (s >= 5.5) then\n\t\t\t\tw4 = t*(1.410474d0+u*0.5641896d0)/(0.75d0+u*(3.d0+u))\n\t\t\telseif (da(i) >= 0.195d0*dabs(dv(i))-0.176d0) then\n\t\t\t\tw4 = (16.4955d0+t*(20.20933d0+t*(11.96482d0+t*(3.778987d0+t*0.5642236d0)))) / &\n\t\t\t\t\t(16.4955d0+t*(38.82363d0+t*(39.27121d0+t*(21.69274d0+t*(6.699398d0+t)))))\n\t\t\telse \n\t\t\t\tw4 = t*(36183.31d0-u*(3321.9905d0-u*(1540.787d0-u*(219.0313d0-u*(35.76683d0-&\n\t\t\t\t\tu*(1.320522d0-u*0.56419d0))))))\n\t\t\t\tv4 = (32066.6d0-u*(24322.84d0-u*(9022.228d0-u*(2186.181d0-u*(364.2191d0-&\n\t\t\t\t\tu*(61.57037d0-u*(1.841439d0-u)))))))\n\t\t\t\tw4 = cexp(u) - w4/v4\n\t\t\tendif\n\t\t\tvecfvoigt(i) = dble(w4)\n\t\tenddo \n\n\tend function vecfvoigt\n\n!--------------------------------------------------------------\n! Generates Voigt and anomalous dispersion profiles using a different damping for each frequency\n! point\n! See Humlicek (1982) JQSRT 27, 437\n!--------------------------------------------------------------\n\tfunction vecfvoigt_zeeman(da, dv)\n\treal*8 :: da(:)\n\treal*8 :: dv(:), vecfvoigt_zeeman(2,size(dv))\n\tcomplex :: w4, z, t, u, v4\n\treal*8 :: s\n\tinteger :: i, n\n \n\t\tn = size(dv)\n\t\tdo i = 1, n\n! There is a problem for very small dampings. We force it to be 0 using a threshold \n\t\t\tif (da(i) < 1.d-3) da(i) = 0.d0\n\t\t\tz = cmplx(dv(i), da(i))\n\t\t\tt = cmplx(da(i), -dv(i))\n\t\t\ts = dabs(dv(i)) + da(i)\n\t\t\tu = t*t\n\n\n\t\t\tif (s >= 15.d0) then\n\t\t\t\tw4 = t * 0.5641896d0 / (0.5d0+u)\n\t\t\telseif (s >= 5.5) then\n\t\t\t\tw4 = t*(1.410474d0+u*0.5641896d0)/(0.75d0+u*(3.d0+u))\n\t\t\telseif (da(i) >= 0.195d0*dabs(dv(i))-0.176d0) then\n\t\t\t\tw4 = (16.4955d0+t*(20.20933d0+t*(11.96482d0+t*(3.778987d0+t*0.5642236d0)))) / &\n\t\t\t\t\t(16.4955d0+t*(38.82363d0+t*(39.27121d0+t*(21.69274d0+t*(6.699398d0+t)))))\n\t\t\telse \n\t\t\t\tw4 = t*(36183.31d0-u*(3321.9905d0-u*(1540.787d0-u*(219.0313d0-u*(35.76683d0-&\n\t\t\t\t\tu*(1.320522d0-u*0.56419d0))))))\n\t\t\t\tv4 = (32066.6d0-u*(24322.84d0-u*(9022.228d0-u*(2186.181d0-u*(364.2191d0-&\n\t\t\t\t\tu*(61.57037d0-u*(1.841439d0-u)))))))\n\t\t\t\tw4 = cexp(u) - w4/v4\n\t\t\tendif\n\t\t\tvecfvoigt_zeeman(1,i) = dble(w4)\n\t\t\tvecfvoigt_zeeman(2,i) = aimag(w4)\n\t\tenddo \t\t\t\t\t\t\t\n\n\tend function vecfvoigt_zeeman\n\n!--------------------------------------------------------------\n! Generates Voigt and anomalous dispersion profiles using a different damping for each frequency\n! point\n! See Humlicek (1982) JQSRT 27, 437\n!--------------------------------------------------------------\n\tfunction vecfvoigt_zeeman2(da, dv)\n\treal*8 :: da(:)\n\treal*8 :: dv(:), vecfvoigt_zeeman2(2,size(dv))\n\tcomplex :: w4(size(dv)), z(size(dv)), t(size(dv)), u(size(dv)), v4(size(dv))\n\treal*8 :: s(size(dv))\n\tinteger :: i, n\n \n\t\tn = size(dv)\n\t\t\n!\t\tallocate(w4(n))\n!\t\tallocate(z(n))\n!\t\tallocate(t(n))\n!\t\tallocate(u(n))\n!\t\tallocate(v4(n))\n!\t\tallocate(s(n))\n\t\t\n\t\twhere(da < 1.d-3) \n\t\t\tda = 0.d0\n\t\tendwhere\n\t\t\n\t\tz = cmplx(dv,da)\n\t\tt = cmplx(da, -dv)\n\t\ts = dabs(dv) + da\n\t\tu = t*t\n\t\t\n\t\twhere(s >= 15.d0)\n\t\t\tw4 = t * 0.5641896d0 / (0.5d0+u)\n\t\tendwhere\n\t\twhere(s < 15.d0 .and. s >= 5.5d0)\n\t\t\tw4 = t*(1.410474d0+u*0.5641896d0)/(0.75d0+u*(3.d0+u))\n\t\tendwhere\n\t\twhere(s < 15.d0 .and. s < 5.5d0 .and. da >= 0.195d0*dabs(dv)-0.176d0)\n\t\t\tw4 = (16.4955d0+t*(20.20933d0+t*(11.96482d0+t*(3.778987d0+t*0.5642236d0)))) / &\n\t\t\t\t\t(16.4955d0+t*(38.82363d0+t*(39.27121d0+t*(21.69274d0+t*(6.699398d0+t)))))\n\t\tendwhere\n\t\twhere(s < 15.d0 .and. s < 5.5d0 .and. da < 0.195d0*dabs(dv)-0.176d0)\n\t\t\tw4 = t*(36183.31d0-u*(3321.9905d0-u*(1540.787d0-u*(219.0313d0-u*(35.76683d0-&\n\t\t\t\t\tu*(1.320522d0-u*0.56419d0))))))\n\t\t\tv4 = (32066.6d0-u*(24322.84d0-u*(9022.228d0-u*(2186.181d0-u*(364.2191d0-&\n\t\t\t\t\tu*(61.57037d0-u*(1.841439d0-u)))))))\n\t\t\tw4 = cexp(u) - w4/v4\n\t\tendwhere\n\t\t\n\t\tvecfvoigt_zeeman2(1,:) = dble(w4)\n\t\tvecfvoigt_zeeman2(2,:) = aimag(w4)\n\t\t\n!\t\tdeallocate(w4)\n!\t\tdeallocate(z)\n!\t\tdeallocate(t)\n!\t\tdeallocate(u)\n!\t\tdeallocate(v4)\n!\t\tdeallocate(s)\n\n\tend function vecfvoigt_zeeman2\n\n!----------------------------------------------------------------\n! This function returns the strength of the Zeeman components\n!----------------------------------------------------------------\t\t\t\t\n\tfunction strength_zeeman(J_up,J_low,M_up,M_low)\n\treal(kind=8) :: J_up, J_low, M_up, M_low, strength_zeeman\n\n\t\tstrength_zeeman = 3.d0 * w3js(int(2.d0*J_up),int(2.d0*J_low),2,-int(2.d0*M_up),&\n\t\t\t\t\tint(2.d0*M_low),-int(2.d0*(M_low-M_up)))**2\n\tend function strength_zeeman\n\n!----------------------------------------------------------------\n! This function initializes some things\n!----------------------------------------------------------------\t\t\n\t\tsubroutine init_maths\n\t\tinteger :: i\n\t\t\tcall factrl\n end subroutine init_maths\n\nend module math_functions\n", "meta": {"hexsha": "49221dc7cabf77105ac71a8a1b9b9a6e845a7787", "size": 10034, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "pyiacsun/radtran/sourceMilne/maths.f90", "max_stars_repo_name": "aasensio/pyiacsun", "max_stars_repo_head_hexsha": "56bdaca98461be7b927f8d5fbbc9e64517c889fb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2015-10-30T17:38:13.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-04T19:11:34.000Z", "max_issues_repo_path": "pyiacsun/radtran/sourceMilne/maths.f90", "max_issues_repo_name": "aasensio/pyiacsun", "max_issues_repo_head_hexsha": "56bdaca98461be7b927f8d5fbbc9e64517c889fb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2015-10-15T21:55:46.000Z", "max_issues_repo_issues_event_max_datetime": "2015-10-16T19:04:54.000Z", "max_forks_repo_path": "pyiacsun/radtran/sourceMilne/maths.f90", "max_forks_repo_name": "aasensio/pyiacsun", "max_forks_repo_head_hexsha": "56bdaca98461be7b927f8d5fbbc9e64517c889fb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-10-18T17:20:31.000Z", "max_forks_repo_forks_event_max_datetime": "2019-10-10T00:47:36.000Z", "avg_line_length": 31.6529968454, "max_line_length": 133, "alphanum_fraction": 0.5173410405, "num_tokens": 4060, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009642742806, "lm_q2_score": 0.7461390043208003, "lm_q1q2_score": 0.6826432945357518}} {"text": "!-------------------------------------------------------------------------------\n! Copyright (c) 2019 FrontISTR Commons\n! This software is released under the MIT License, see LICENSE.txt\n!-------------------------------------------------------------------------------\n!> \\brief This module contains functions for interpolation in 15 node\n!! prism element (Langrange interpolation)\nmodule shape_prism15n\n implicit none\n integer, parameter, private :: kreal = kind(0.0d0)\n\ncontains\n subroutine ShapeFunc_prism15n(ncoord,shp)\n real(kind=kreal), intent(in) :: ncoord(3)\n real(kind=kreal) :: shp(15)\n real(kind=kreal) :: xi,et,a,ze\n xi = ncoord(1); et = ncoord(2)\n a=1.d0-xi-et\n ze = ncoord(3)\n shp(1)=0.5* a*(1.0-ze)*(2.0*a -2.0-ze)\n shp(2)=0.5*xi*(1.0-ze)*(2.0*xi-2.0-ze)\n shp(3)=0.5*et*(1.0-ze)*(2.0*et-2.0-ze)\n shp(4)=0.5* a*(1.0+ze)*(2.0*a -2.0+ze)\n shp(5)=0.5*xi*(1.0+ze)*(2.0*xi-2.0+ze)\n shp(6)=0.5*et*(1.0+ze)*(2.0*et-2.0+ze)\n shp(7)=2.0*xi*a*(1.0-ze)\n shp(8)=2.0*xi*et*(1.0-ze)\n shp(9)=2.0*et*a*(1.0-ze)\n shp(10)=2.0*xi*a*(1.0+ze)\n shp(11)=2.0*xi*et*(1.0+ze)\n shp(12)=2.0*et*a*(1.0+ze)\n shp(13)= a*(1.0-ze*ze)\n shp(14)=xi*(1.0-ze*ze)\n shp(15)=et*(1.0-ze*ze)\n end subroutine\n\n subroutine ShapeDeriv_prism15n(ncoord,func)\n real(kind=kreal), intent(in) :: ncoord(3)\n real(kind=kreal) :: func(15,3)\n real(kind=kreal) :: xi,et,a,ze\n xi = ncoord(1); et = ncoord(2)\n a=1.d0-xi-et\n ze = ncoord(3)\n !\n ! local derivatives of the shape functions: xi-derivative\n !\n func(1,1)= -0.5*(1.0-ze)*(4.0*a -ze-2.0)\n func(2,1)= 0.5*(1.0-ze)*(4.0*xi-ze-2.0)\n func(3,1)= 0.d0\n func(4,1)= -0.5*(1.0+ze)*(4.0*a +ze-2.0)\n func(5,1)= 0.5*(1.0+ze)*(4.0*xi+ze-2.0)\n func(6,1)= 0.d0\n func(7,1)= 2.0*(1.0-ze)*(1.0-2.0*xi-et)\n func(8,1)= 2.0*et*(1.0-ze)\n func(9,1)= -2.0*et*(1.0-ze)\n func(10,1)= 2.0*(1.0+ze)*(1.0-2.0*xi-et)\n func(11,1)= 2.0*et*(1.0+ze)\n func(12,1)= -2.0*et*(1.0+ze)\n func(13,1)= -(1.0-ze*ze)\n func(14,1)= (1.0-ze*ze)\n func(15,1)= 0.d0\n !\n ! local derivatives of the shape functions: eta-derivative\n !\n func(1,2)=-0.5*(1.0-ze)*(4.0*a -ze-2.0)\n func(2,2)= 0.d0\n func(3,2)= 0.5*(1.0-ze)*(4.0*et-ze-2.0)\n func(4,2)=-0.5*(1.0+ze)*(4.0*a +ze-2.0)\n func(5,2)= 0.d0\n func(6,2)= 0.5*(1.0+ze)*(4.0*et+ze-2.0)\n func(7,2)=-2.0*xi*(1.0-ze)\n func(8,2)= 2.0*xi*(1.0-ze)\n func(9,2)= 2.0*(1.0-ze)*(1.0-xi-2.0*et)\n func(10,2)=-2.0*xi*(1.0+ze)\n func(11,2)= 2.0*xi*(1.0+ze)\n func(12,2)= 2.0*(1.0+ze)*(1.0-xi-2.0*et)\n func(13,2)=-(1.0-ze*ze)\n func(14,2)= 0.0d0\n func(15,2)= (1.0-ze*ze)\n !\n ! local derivatives of the shape functions: zeta-derivative\n !\n func(1,3)= a*(xi+et+ze-0.5)\n func(2,3)= xi*(-xi+ze+0.5)\n func(3,3)= et*(-et+ze+0.5)\n func(4,3)= a*(-xi-et+ze+0.5)\n func(5,3)= xi*(xi+ze-0.5)\n func(6,3)= et*(et+ze-0.5)\n func(7,3)= -2*xi*a\n func(8,3)= -2*xi*et\n func(9,3)= -2*et*a\n func(10,3)= 2*xi*a\n func(11,3)= 2*xi*et\n func(12,3)= 2*et*a\n func(13,3)=-2*a*ze\n func(14,3)=-2*xi*ze\n func(15,3)=-2*et*ze\n end subroutine\n\nend module\n", "meta": {"hexsha": "5cff285f09906bbac5a0fab57ed81bf8f684b778", "size": 3185, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fistr1/src/lib/element/prism15n.f90", "max_stars_repo_name": "masae-hayashi/FrontISTR", "max_stars_repo_head_hexsha": "a488de9eb45b3238ba0cd11454c71a03450666a6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 64, "max_stars_repo_stars_event_min_datetime": "2016-09-08T05:26:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T03:36:57.000Z", "max_issues_repo_path": "fistr1/src/lib/element/prism15n.f90", "max_issues_repo_name": "masae-hayashi/FrontISTR", "max_issues_repo_head_hexsha": "a488de9eb45b3238ba0cd11454c71a03450666a6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2016-04-12T09:46:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-17T09:51:51.000Z", "max_forks_repo_path": "fistr1/src/lib/element/prism15n.f90", "max_forks_repo_name": "masae-hayashi/FrontISTR", "max_forks_repo_head_hexsha": "a488de9eb45b3238ba0cd11454c71a03450666a6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 38, "max_forks_repo_forks_event_min_datetime": "2016-10-05T01:47:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-16T07:05:26.000Z", "avg_line_length": 31.85, "max_line_length": 80, "alphanum_fraction": 0.5004709576, "num_tokens": 1570, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009503523291, "lm_q2_score": 0.7461389873857264, "lm_q1q2_score": 0.6826432686541255}} {"text": " subroutine mapc2m_annulus2(xc,yc,xp,yp,zp)\n implicit none\n\n double precision xc,yc,xp,yp,zp\n\n double precision theta, r\n\n call map_comp2annulus(xc,yc,theta,r)\n\n xp = r*cos(theta)\n yp = r*sin(theta)\n zp = 0\n\n end\n", "meta": {"hexsha": "f794f280ef7c6071d4fbec2b32bbc9aed3359f30", "size": 258, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "applications/paper/all/mapc2m_annulus.f", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2017-09-26T13:39:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:56:23.000Z", "max_issues_repo_path": "applications/paper/all/mapc2m_annulus.f", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 75, "max_issues_repo_issues_event_min_datetime": "2017-08-02T19:56:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T12:36:32.000Z", "max_forks_repo_path": "applications/paper/all/mapc2m_annulus.f", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-02-21T00:10:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T19:08:36.000Z", "avg_line_length": 17.2, "max_line_length": 48, "alphanum_fraction": 0.5852713178, "num_tokens": 83, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.914900945711678, "lm_q2_score": 0.7461389873857264, "lm_q1q2_score": 0.6826432651915548}} {"text": "rho1 = 2.30485d-6*1d0/mbh*r**1.5d0/(alpha*cgs_kapes**3*mdot**2*f(r)**2)\nT1 = 4.61893d+7*alpha**(-0.25d0)*cgs_kapes**(-0.25d0)*mbh**(-0.25d0)*r** &\n (-0.375d0)\nH1 = 982981.0d0*cgs_kapes*mbh**1.0d0*mdot*f(r)\nrho2 = 21.9208d0*alpha**(-0.7d0)*cgs_kapes**(-0.3d0)*mbh**(-0.7d0)*mdot &\n **0.4d0*r**(-1.65d0)*f(r)**0.4d0\nT2 = 6.72321d+8*alpha**(-0.2d0)*cgs_kapes**0.2d0*mbh**(-0.2d0)*mdot** &\n 0.4d0*r**(-0.9d0)*f(r)**0.4d0\nH2 = 4639.53d0*alpha**(-0.1d0)*cgs_kapes**0.1d0*mbh**0.9d0*mdot**0.2d0*r &\n **1.05d0*f(r)**0.2d0\nrho3 = 594575.0d0*alpha**(-0.7d0)*kappa_abs_0**(-0.15d0)*mbh**(-0.7d0)* &\n mdot**0.55d0*r**(-1.875d0)*f(r)**0.55d0\nT3 = 744750.0d0*alpha**(-0.2d0)*kappa_abs_0**0.1d0*mbh**(-0.2d0)*mdot** &\n 0.3d0*r**(-0.75d0)*f(r)**0.3d0\nH3 = 154.415d0*alpha**(-0.1d0)*kappa_abs_0**0.05d0*mbh**0.9d0*mdot** &\n 0.15d0*r**1.125d0*f(r)**0.15d0\nr12 = 164.175d0*alpha**0.0952381d0*cgs_kapes**0.857143d0*mbh** &\n 0.0952381d0*mdot**0.761905d0*f(r12)**0.761905d0\nr23 = 5.05562d+19*cgs_kapes**1.33333d0*kappa_abs_0**(-0.666667d0)*mdot** &\n 0.666667d0*f(r23)**0.666667d0\n", "meta": {"hexsha": "c2eec190924c9645a8b4f57c8e41d62c71d4eaee", "size": 1103, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "sympy/ss73/3zones.f90", "max_stars_repo_name": "gronki/diskvert", "max_stars_repo_head_hexsha": "459238a46fc173c9fec3ff609cd42595bbc0c858", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "sympy/ss73/3zones.f90", "max_issues_repo_name": "gronki/diskvert", "max_issues_repo_head_hexsha": "459238a46fc173c9fec3ff609cd42595bbc0c858", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sympy/ss73/3zones.f90", "max_forks_repo_name": "gronki/diskvert", "max_forks_repo_head_hexsha": "459238a46fc173c9fec3ff609cd42595bbc0c858", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.5238095238, "max_line_length": 74, "alphanum_fraction": 0.5974614687, "num_tokens": 666, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012732322216, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6826256491237829}} {"text": " program demo_dim\n use, intrinsic :: iso_fortran_env, only : real64\n implicit none\n integer :: i\n real(kind=real64) :: x\n i = dim(4, 15)\n x = dim(4.321_real64, 1.111_real64)\n print *, i\n print *, x\n ! elemental\n print *, dim([1,2,3],2)\n print *, dim([1,2,3],[3,2,1])\n print *, dim(-10,[0,-10,-20])\n end program demo_dim\n", "meta": {"hexsha": "361a3fef017b768cae3c7a6d9bb7334fdb7ea13a", "size": 404, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/dim.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/dim.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/dim.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": 26.9333333333, "max_line_length": 52, "alphanum_fraction": 0.495049505, "num_tokens": 132, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339596505966, "lm_q2_score": 0.8128673223709252, "lm_q1q2_score": 0.682592295285115}} {"text": "\n function v_to_b(v)\n\n! Convert visual magnitude per square second (v) to brightness in \n! nanolamberts (b)\n\n v_to_b = 34.08 * exp(20.7233 - 0.92104 * v)\n\n return\n end\n\n\n function b_to_v(b)\n\n! Convert brightness in nanolamberts (b) to visual magnitude per square \n! second (v) \n\n b_to_v = (log(b/34.08) - 20.7233) / (- 0.92104) \n\n return\n end \n\n function b_to_maglim(b)\n\n! Convert brightness in nanolamberts (b) to visual magnitude limit.\n! This starts with Weavers formula (1947). Also Eq. 20 of Garstang (1986).\n! Then, a Schaaf - Albers correction of +0.23 magnitude is applied.\n\n if(b .le. 1479.)then\n b_to_maglim = 7.930 - 2.171 * log(1. + .1122 * sqrt(b)) \n else ! b > 1479.\n b_to_maglim = 4.305 - 2.171 * log(1. + .001122 * sqrt(b))\n endif\n\n! b_to_maglim = b_to_maglim + 0.23\n\n! write(13,1)b,b_to_maglim \n! format(' b/b_to_maglim',2f9.2)\n\n return\n end \n\n\n function b_to_maglim_hecht(b)\n\n! Convert brightness in nanolamberts (b) to visual magnitude limit.\n! This starts with Hecht's formula (1947) as quoted in Schaefer using\n! Schaefer's Equations. \n\n\n real*4 k\n\n blog = log10(b)\n\n if(blog .ge. 3.17)then\n c = 10. ** (-8.35)\n k = 10. ** (-5.90)\n else ! blog < 3.17\n c = 10. ** (-9.80)\n k = 10. ** (-1.90)\n endif\n\n rith = c * (1. + sqrt(k * b)) ** 2 ! Eq 34\n rmag_v = -16.57 - 2.5 * alog10(rith) ! Eq 10\n b_to_maglim_hecht = rmag_v - 0.3 ! Eq 9,48\n\n! write(22,*)b,c,k,rith,rmag_v,b_to_maglim_hecht\n\n return\n end \n\n function rmaglim_to_b(rmaglim)\n\n bestval = 0.\n resid_min = 999.\n! do i = 1000,10000,2 \n do i = 1000,10000,5 \n testb = 10. ** (float(i) / 1000.)\n testmag = b_to_maglim(testb)\n resid = testmag - rmaglim\n if(abs(resid) .lt. resid_min)then\n resid_min = resid\n rmaglim_to_b = testb\n ibest = i\n endif\n! write(6,1)rmaglim,ibest,resid_min,rmaglim_to_b \n enddo ! i\n\n! write(13,1)rmaglim,ibest,resid_min,rmaglim_to_b \n1 format(' rmaglim/ibest/resid_min/rmaglim_to_b ',f9.2,i6,2f9.2)\n \n return\n end\n\n\n subroutine addmaglims(rmaglim1,rmaglim2,rmaglim_out)\n\n b1 = rmaglim_to_b(rmaglim1)\n b2 = rmaglim_to_b(rmaglim2)\n\n bsum = b1 + b2\n\n rmaglim_out = b_to_maglim(bsum)\n\n return\n end\n", "meta": {"hexsha": "043b324bfb0490ceb43d967e463101c0f24f250c", "size": 2611, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/lib/cloud/places_routines.f", "max_stars_repo_name": "maxinye/laps-mirror", "max_stars_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_stars_repo_licenses": ["Intel", "Unlicense", "OLDAP-2.2.1", "NetCDF"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-04-05T12:28:22.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-29T06:37:29.000Z", "max_issues_repo_path": "src/lib/cloud/places_routines.f", "max_issues_repo_name": "longwosion/laps-mirror", "max_issues_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_issues_repo_licenses": ["Intel", "NetCDF", "OLDAP-2.2.1", "Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/lib/cloud/places_routines.f", "max_forks_repo_name": "longwosion/laps-mirror", "max_forks_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_forks_repo_licenses": ["Intel", "NetCDF", "OLDAP-2.2.1", "Unlicense"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-04-27T12:51:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-19T13:57:44.000Z", "avg_line_length": 24.4018691589, "max_line_length": 78, "alphanum_fraction": 0.5350440444, "num_tokens": 886, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802507195636, "lm_q2_score": 0.743168019989179, "lm_q1q2_score": 0.6825851493264228}} {"text": "PROGRAM power\r\n!\r\n! Purpose: \r\n! To calculate the current, real, reactive, and apparent power,\r\n! and the power factor supplied to a load. \r\n!\r\n! Record of revisions:\r\n! Date Programmer Description of change\r\n! ==== ========== =====================\r\n! 11/03/06 S. J. Chapman Original code \r\n!\r\n \r\nIMPLICIT NONE\r\n \r\n! Data dictionary: declare constants \r\nREAL,PARAMETER :: DEG_2_RAD = 0.01745329 ! Deg to radians factor\r\n\r\n! Data dictionary: declare variable types, definitions, & units \r\nREAL :: amps ! Current in the load (A)\r\nREAL :: p ! Real power of load (W)\r\nREAL :: pf ! Power factor of load (no units)\r\nREAL :: q ! Reactive power of the load (VAR)\r\nREAL :: s ! Apparent power of the load (VA)\r\nREAL :: theta ! Impedance angle of the load (deg)\r\nREAL :: volts ! Rms voltage of the power source (V)\r\nREAL :: z ! Magnitude of the load impedance (ohms)\r\n\r\n! Prompt the user for the rms voltage.\r\nWRITE (*,*) 'Enter the rms voltage of the source: '\r\nREAD (*,*) volts \r\n\r\n! Prompt the user for the magnitude and angle of the impedance.\r\nWRITE (*,*) 'Enter the magnitude and angle of the impedance '\r\nWRITE (*,*) 'in ohms and degrees: '\r\nREAD (*,*) z, theta \r\n\r\n! Perform calculations\r\namps = volts / z ! Rms current\r\np = volts * amps * cos (theta * DEG_2_RAD) ! Real power\r\nq = volts * amps * sin (theta * DEG_2_RAD) ! Reactive power\r\ns = volts * amps ! Apparent power\r\npf = cos ( theta * DEG_2_RAD) ! Power factor\r\n \r\n! Write out the results.\r\nWRITE (*,*) 'Voltage = ', volts, ' volts'\r\nWRITE (*,*) 'Impedance = ', z, ' ohms at ', theta,' degrees'\r\nWRITE (*,*) 'Current = ', amps, ' amps'\r\nWRITE (*,*) 'Real Power = ', p, ' watts'\r\nWRITE (*,*) 'Reactive Power = ', q, ' VAR'\r\nWRITE (*,*) 'Apparent Power = ', s, ' VA'\r\nWRITE (*,*) 'Power Factor = ', pf\r\n \r\n! Finish up.\r\nEND PROGRAM power\r\n", "meta": {"hexsha": "3c4109d6706def8b50967bf5a61ee709c5b9afde", "size": 2053, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap2/power.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/power.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/power.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": 37.3272727273, "max_line_length": 67, "alphanum_fraction": 0.5465172918, "num_tokens": 524, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802440252812, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6825851286775377}} {"text": "module tensor\n\nimplicit none\n\npublic :: t0, t1, t2\n\ncontains\n\nfunction t0(r_a, r_b) result(var)\n double precision, intent(in), dimension(3) :: r_a\n double precision, intent(in), dimension(3) :: r_b\n double precision :: var\n\n double precision :: R2\n double precision, dimension(3) :: dr\n\n dr = r_b - r_a\n R2 = dot_product(dr, dr)\n var = 1.0d0 / sqrt(R2)\n\nend function t0\n\nfunction t1(r_a, r_b) result(var)\n double precision, intent(in), dimension(3) :: r_a\n double precision, intent(in), dimension(3) :: r_b\n double precision, dimension(3) :: var\n\n double precision :: R, R2\n double precision, dimension(3) :: dr\n\n dr = r_b - r_a\n R2 = dot_product(dr, dr)\n R = sqrt(R2)\n var = dr / (R*R2)\n\nend function t1\n\nfunction t2(r_a, r_b) result(var)\n double precision, intent(in), dimension(3) :: r_a\n double precision, intent(in), dimension(3) :: r_b\n double precision, dimension(6) :: var\n\n double precision :: R, R2\n double precision, dimension(3) :: dr\n\n dr = r_b - r_a\n R2 = dot_product(dr, dr)\n R = sqrt(R2)\n\n var(1) = 3 * dr(1) * dr(1) - R2 ! xx\n var(2) = 3 * dr(1) * dr(2) ! xy\n var(3) = 3 * dr(1) * dr(3) ! xz\n var(4) = 3 * dr(2) * dr(2) - R2 ! yy\n var(5) = 3 * dr(2) * dr(3) ! yz\n var(6) = 3 * dr(3) * dr(3) - R2 ! zz\n\n var = var / (R*R2*R2)\n\nend function t2\n\n\nend module tensor\n", "meta": {"hexsha": "92edcb1e14c73ef747cc6f9d9aac8975fd7745ad", "size": 1338, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tensor.f90", "max_stars_repo_name": "cstein/qfitlib", "max_stars_repo_head_hexsha": "1acdc9863fdeae2cdbc7f5a599413257a095b8ad", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2016-03-16T14:28:03.000Z", "max_stars_repo_stars_event_max_datetime": "2019-08-29T05:56:58.000Z", "max_issues_repo_path": "src/tensor.f90", "max_issues_repo_name": "cstein/qfitlib", "max_issues_repo_head_hexsha": "1acdc9863fdeae2cdbc7f5a599413257a095b8ad", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-01-17T09:06:52.000Z", "max_issues_repo_issues_event_max_datetime": "2017-01-17T09:06:52.000Z", "max_forks_repo_path": "src/tensor.f90", "max_forks_repo_name": "cstein/qfitlib", "max_forks_repo_head_hexsha": "1acdc9863fdeae2cdbc7f5a599413257a095b8ad", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-06-18T16:27:31.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-30T08:23:48.000Z", "avg_line_length": 21.2380952381, "max_line_length": 51, "alphanum_fraction": 0.5994020927, "num_tokens": 500, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802462567087, "lm_q2_score": 0.743167997235783, "lm_q1q2_score": 0.6825851251112269}} {"text": "c ============================================\n subroutine setaux(maxmx,mbc,mx,xlower,dx,maux,aux)\nc ============================================\nc\nc # set auxiliary arrays \nc # aux(i,1) = b in cell i, bottom topography \"hillinbasin\"\nc\nc \n implicit double precision (a-h,o-z)\n dimension aux(1-mbc:maxmx+mbc, *)\n\n ! set user-defined topography as aux(i,1)\n do 50 i=1,mx \n xcell = xlower + (i-0.5d0)*dx\n aux(i,1)=1.8d0*dexp(-1000.d0*xcell**2)\n & + .5d0*1.0d0*dexp(-50.d0*(xcell-0.5d0)**2)\n & + 1.8d0*dexp(-1000.d0*(xcell-1.d0)**2)\n\n\n write(17,701) aux(i,1)\n 701 format(e22.12)\n\n\n 50 continue\n \n\n\n return\n end\n", "meta": {"hexsha": "cd9490b008d11168599c427872ae0236f0182c0f", "size": 722, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "geoclaw/1d/lib_geo/setaux_geo.f", "max_stars_repo_name": "kbarnhart/D-Claw", "max_stars_repo_head_hexsha": "20599fac079e120b6129de073a6bec3a49d689fa", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2016-11-13T03:11:51.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-07T18:59:48.000Z", "max_issues_repo_path": "geoclaw/1d/lib_geo/setaux_geo.f", "max_issues_repo_name": "che-wenchao/D-Claw", "max_issues_repo_head_hexsha": "8ab5d971c9a7a7130e03a447a4b8642e292f4e88", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2020-01-14T18:00:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T14:25:24.000Z", "max_forks_repo_path": "geoclaw/1d/lib_geo/setaux_geo.f", "max_forks_repo_name": "che-wenchao/D-Claw", "max_forks_repo_head_hexsha": "8ab5d971c9a7a7130e03a447a4b8642e292f4e88", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-01-14T17:15:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-03T17:28:44.000Z", "avg_line_length": 24.0666666667, "max_line_length": 63, "alphanum_fraction": 0.4639889197, "num_tokens": 246, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797172476384, "lm_q2_score": 0.7490872075132152, "lm_q1q2_score": 0.6825530699357144}} {"text": "program spherical_harmonics\n use special_functions\n integer, parameter :: num_theta_pts = 100, num_phi_pts = 100, lmax=4\n real(kind=dp) :: alp(num_theta_pts, 0:lmax,-lmax:lmax), theta_pts(num_theta_pts), dtheta, dphi\n real(kind=dp) :: fac, phi\n integer :: i, j, k, l, m, fact(2*lmax)\n complex(kind=dp) :: spha_ylm(num_theta_pts, num_phi_pts)\n\n\n dtheta = pi/(num_theta_pts-1)\n dphi = 2*pi/(num_phi_pts-1)\n theta_pts = [ (-pi/2+i*dtheta, i=0, num_theta_pts-1) ]\n l=2\n m=0\n\n\n call calc_factorials(2*lmax, fact)\n call gen_assoc_legendre_pol(cos(theta_pts), num_theta_pts, lmax, alp)\n\n do i=0,num_phi_pts-1\n phi = i*dphi\n fac=dsqrt((2*l+1)*fact(l-m)/(4.0d0*pi*fact(l+m)))\n spha_ylm(:,i)=fac*alp(:,l,m)*cmplx(cos(m*phi),sin(m*phi))\n end do\n\n\n\n do i=1,num_theta_pts\n do j=1,num_phi_pts\n print '(5f10.4)', theta_pts(i), (j-1)*dphi, spha_ylm(i,j)%re, spha_ylm(i,j)%im, abs(spha_ylm(i, j))\n end do\n end do\nend program spherical_harmonics\n", "meta": {"hexsha": "2ba9a8674d25c9f633092d76e5133d75695a59b7", "size": 966, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "exercises/spherical_harmonics.f90", "max_stars_repo_name": "deadbeatfour/phn624-comp-nuc-phy", "max_stars_repo_head_hexsha": "deaeaac5240a1f33425c4ca50539aee4fae2f370", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "exercises/spherical_harmonics.f90", "max_issues_repo_name": "deadbeatfour/phn624-comp-nuc-phy", "max_issues_repo_head_hexsha": "deaeaac5240a1f33425c4ca50539aee4fae2f370", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "exercises/spherical_harmonics.f90", "max_forks_repo_name": "deadbeatfour/phn624-comp-nuc-phy", "max_forks_repo_head_hexsha": "deaeaac5240a1f33425c4ca50539aee4fae2f370", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.4117647059, "max_line_length": 104, "alphanum_fraction": 0.6666666667, "num_tokens": 377, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797027760038, "lm_q2_score": 0.7490872187162396, "lm_q1q2_score": 0.6825530693031666}} {"text": " SUBROUTINE posin1 (a,nmax,ndd)\r\n\r\n! Inverse of matrix perhaps ??????????\r\n\r\n IMPLICIT NONE\r\n INTEGER (kind=4),INTENT(IN) :: nmax,ndd\r\n REAL (kind=8),INTENT(IN OUT) :: a(ndd,ndd)\r\n\r\n INTEGER (kind=4) i,j,n\r\n REAL (kind=8) d\r\n\r\n DO n=1,nmax\r\n\r\n d = a(n,n)\r\n DO j=1,nmax\r\n a(n,j) = -a(n,j)/d\r\n END DO\r\n\r\n DO i=1,nmax\r\n IF(n /= i)THEN\r\n DO j=1,nmax\r\n IF(n /= j) a(i,j) = a(i,j) + a(i,n)*a(n,j)\r\n END DO\r\n END IF\r\n a(i,n) = a(i,n)/d\r\n END DO\r\n\r\n a(n,n) = 1.0/d\r\n\r\n END DO\r\n\r\n RETURN\r\n END SUBROUTINE posin1\r\n", "meta": {"hexsha": "0a44462cf69b5cf4fa1237c2f9f426bd609be9fc", "size": 672, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/matdb/posin1.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/matdb/posin1.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/matdb/posin1.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": 19.7647058824, "max_line_length": 57, "alphanum_fraction": 0.3973214286, "num_tokens": 230, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797027760038, "lm_q2_score": 0.7490872187162397, "lm_q1q2_score": 0.6825530693031666}} {"text": "\tSUBROUTINE VC_PFTH ( theta, tmp, nxy, p, iret )\nC************************************************************************\nC* VC_PFTH\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This subroutine computes pressure on an isentropic surface given\t*\nC* temperature.\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* VC_PFTH ( THETA, TMP, NXY, P, IRET )\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tTHETA\t\tREAL\t\tPotential temperature\t\t*\nC*\tTMP (NXY)\tREAL\t\tTemperature\t\t\t*\nC*\tNXY\t\tINTEGER\t\tNumber of points\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tP (NXY)\tREAL\t\tOutput pressure values\t\t*\nC*\tIRET\t\tINTEGER\t\tReturn code\t\t\t*\nC*\t\t\t\t\t 0 = normal return\t\t*\nC*\t\t\t\t\t +1 = all missing\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* K. Brill/NMC 06/92\t\t\t\t\t\t*\nC************************************************************************\n\tINCLUDE\t\t'GEMPRM.PRM'\nC*\n\tREAL\t\ttmp (*), p (*)\nC*\n\tINCLUDE\t\t'ERMISS.FNC'\nC-----------------------------------------------------------------------\n\tiret = 0\nC\nC*\tCompute the theta coordinate values.\nC\n\ticnt = 0\n\tDO i = 1, nxy\n\t IF ( ERMISS ( tmp (i) ) .or. ERMISS ( theta ) ) THEN\n\t\tp (i) = RMISSD\n\t\ticnt = icnt + 1\n\t ELSE\n\t\tp (i) = 1000. * ( tmp (i) / theta ) ** 3.5\n\t END IF\n\tEND DO\nC*\n\tIF ( icnt .eq. nxy ) iret = +1\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "42082de0435f0ff7836d98cdf14467dd93510b60", "size": 1233, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/programs/gd/gdvint/vcpfth.f", "max_stars_repo_name": "oxelson/gempak", "max_stars_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2015-06-03T15:26:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T22:36:03.000Z", "max_issues_repo_path": "gempak/source/programs/gd/gdvint/vcpfth.f", "max_issues_repo_name": "oxelson/gempak", "max_issues_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 60, "max_issues_repo_issues_event_min_datetime": "2015-05-11T21:36:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T16:22:42.000Z", "max_forks_repo_path": "gempak/source/programs/gd/gdvint/vcpfth.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": 25.6875, "max_line_length": 73, "alphanum_fraction": 0.4412003244, "num_tokens": 423, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797124237605, "lm_q2_score": 0.7490872075132152, "lm_q1q2_score": 0.6825530663222092}} {"text": "!-----------------------------------------------------------------------------------\r\n!\r\n!\r\n! PURPOSE\r\n!\r\n! This program numerically solves the 3D incompressible Navier-Stokes\r\n! on a Cubic Domain [0,2pi]x[0,2pi]x[0,2pi] using pseudo-spectral methods and\r\n! Implicit Midpoint rule timestepping. The numerical solution is compared to\r\n! an exact solution reported by Shapiro\r\n!\r\n! Analytical Solution:\r\n! u(x,y,z,t)=-0.25*(cos(x)sin(y)sin(z)+sin(x)cos(y)cos(z))exp(-t/Re)\r\n! v(x,y,z,t)= 0.25*(sin(x)cos(y)sin(z)-cos(x)sin(y)cos(z))exp(-t/Re)\r\n! w(x,y,z,t)= 0.5*cos(x)cos(y)sin(z)exp(-t/Re)\r\n!\r\n! .. Parameters ..\r\n! Nx = number of modes in x - power of 2 for FFT\r\n! Ny = number of modes in y - power of 2 for FFT\r\n! Nz = number of modes in z - power of 2 for FFT\r\n! Nt = number of timesteps to take\r\n! Tmax = maximum simulation time\r\n! pi = 3.14159265358979323846264338327950288419716939937510d0\r\n! Re = Reynolds number\r\n! .. Scalars ..\r\n! i = loop counter in x direction\r\n! j = loop counter in y direction\r\n! k = loop counter in z direction\r\n! n = loop counter for timesteps direction\r\n! nn = loop conuter for timesteps between plots\r\n! allocatestatus = error indicator during allocation\r\n! count = keep track of information written to disk\r\n! iol = size of array to write to disk\r\n! start = variable to record start time of program\r\n! finish = variable to record end time of program\r\n! count_rate = variable for clock count rate\r\n! theta = variable to modify exact solution used\r\n! dt = timestep\r\n! filesize = MPI variable to indicate file size to be written to disk\r\n! disp = MPI variable to indicate where in file local portion to be written\r\n! p_row = variable used by 2decomp to store number of rows \r\n! p_col= variable used by 2decomp to store number of columns\r\n! numprocs = number of processros \r\n! myid = number of local process\r\n! ierr = error codes returned in this variable\r\n! t = time\r\n! plotInt= plot number\r\n! ind = index for file number\r\n! start = timing variable\r\n! finish = fiming variable \r\n! count_rate = clock rate to convert to seconds\r\n\r\n! .. Arrays ..\r\n! u = velocity in x direction\r\n! v = velocity in y direction\r\n! w = velocity in z direction\r\n! uexact = array for exact solution\r\n! vexact = array for exact solution\r\n! wexact = array for exact solution\r\n! uold = velocity in x direction at previous timestep\r\n! vold = velocity in y direction at previous timestep\r\n! wold = velocity in z direction at previous timestep\r\n! ux = x derivative of velocity in x direction\r\n! uy = y derivative of velocity in x direction\r\n! uz = z derivative of velocity in x direction\r\n! vx = x derivative of velocity in y direction\r\n! vy = y derivative of velocity in y direction\r\n! vz = z derivative of velocity in y direction\r\n! wx = x derivative of velocity in z direction\r\n! wy = y derivative of velocity in z direction\r\n! wz = z derivative of velocity in z direction\r\n! uxold = x derivative of velocity in x direction\r\n! uyold = y derivative of velocity in x direction\r\n! uzold = z derivative of velocity in x direction\r\n! vxold = x derivative of velocity in y direction\r\n! vyold = y derivative of velocity in y direction\r\n! vzold = z derivative of velocity in y direction\r\n! wxold = x derivative of velocity in z direction\r\n! wyold = y derivative of velocity in z direction\r\n! wzold = z derivative of velocity in z direction\r\n! utemp = temporary storage of u to check convergence\r\n! vtemp = temporary storage of u to check convergence\r\n! wtemp = temporary storage of u to check convergence\r\n! temp_r = temporary storage for untransformed variables\r\n! uhat = Fourier transform of u\r\n! vhat = Fourier transform of v\r\n! what = Fourier transform of w\r\n! rhsuhatfix = Fourier transform of righthand side for u for timestepping\r\n! rhsvhatfix = Fourier transform of righthand side for v for timestepping\r\n! rhswhatfix = Fourier transform of righthand side for w for timestepping\r\n! nonlinuhat = Fourier transform of nonlinear term for u\r\n! nonlinvhat = Fourier transform of nonlinear term for u\r\n! nonlinwhat = Fourier transform of nonlinear term for u\r\n! phat = Fourier transform of nonlinear term for pressure, p\r\n! temp_c = temporary storage for Fourier transforms\r\n!\r\n! .. Vectors ..\r\n! kx = fourier frequencies in x direction\r\n! ky = fourier frequencies in y direction\r\n! kz = fourier frequencies in z direction\r\n! x = x locations\r\n! y = y locations\r\n! z = y locations\r\n! time = times at which save data\r\n! name_config = array to store filename for data to be saved\r\n! number_file = array to store number of filename being saved\r\n! temp1 = array to collect local sums for MPI reductions\r\n! temp2 = array to perform MPI reductions in\r\n! mychg = array to collect local differences between fixed point iterates\r\n! allchg = array to collect global differences between fixed point iterates\r\n! KE = array to record kinetic energy\r\n! Enstrophy = array to record enstrophy\r\n! KEdissipationRate = array to record kinetic energy dissipation rate\r\n!\r\n! .. Special types ..\r\n!\r\n! decomp = structure from 2decomp with information on complex array sizes\r\n! sp = structure from 2decomp with information on real array sizes\r\n!\r\n! REFERENCES\r\n!\r\n! A. Shapiro \" The use of an exact solution of the Navier-Stokes equations\r\n! in a validation test of a three-dimensional nonhydrostatic numerical model\"\r\n! Monthly Weather Review vol. 121, 2420-2425, (1993).\r\n!\r\n! ACKNOWLEDGEMENTS\r\n!\r\n! ACCURACY\r\n!\r\n! ERROR INDICATORS AND WARNINGS\r\n!\r\n! FURTHER COMMENTS\r\n!\r\n! This program has not been optimized to use the least amount of memory\r\n! or be as efficeint as possible, but is intended to be portable and produc\r\n! correcte results\r\n!\r\n!--------------------------------------------------------------------------------\r\n! External routines required\r\n!\r\n! External libraries required\r\n! 2DECOMP&FFT -- Fast Fourier Transform in the West Library\r\n! (http://2decomp.org/)\r\n\r\nPROGRAM main\r\n\tUSE decomp_2d\r\n\tUSE decomp_2d_fft\r\n\tUSE decomp_2d_io\r\n\t\r\n\tIMPLICIT NONE\t\r\n\tinclude \"mpif.h\"\r\n\t!Grid & Timing\r\n \tINTEGER(kind=4), PARAMETER \t\t:: Nx=512, Ny=512, Nz=512\t\t\r\n \tINTEGER(kind=4), PARAMETER \t\t:: Lx=1, Ly=1, Lz=1\r\n\tINTEGER(kind=4), PARAMETER\t\t:: Nt=1000, plotgap=100\r\n\tINTEGER(kind=4)\t\t\t\t:: numplots=Nt/plotgap\r\n\t!choose initial conditions\r\n\tlogical ::readinput=.false.,&\r\n TGvortex=.true.,&\r\n exactsoln=.false.\r\n\t!option to save output\r\n\tINTEGER(kind=4), PARAMETER \t \t:: savedata1=1\r\n\t!runtime parameters\r\n\tREAL(kind=8), PARAMETER\t\t\t:: dt=0.005d0\r\n\tREAL(kind=8), PARAMETER\t\t\t:: Re=1600.0d0\t\r\n\tREAL(kind=8), PARAMETER\t\t\t:: tol=0.1d0**10\r\n\tREAL(kind=8), PARAMETER\t\t\t:: theta=0.0d0\r\n\t!additional parameters & constants\r\n\tREAL(kind=8), PARAMETER\t&\r\n\t\t:: pi=3.14159265358979323846264338327950288419716939937510d0\r\n\tREAL(kind=8), PARAMETER :: dx=2.0d0*pi*Lx/REAL(Nx,kind(0d0))\r\n\tREAL(kind=8), PARAMETER :: dy=2.0d0*pi*Ly/REAL(Ny,kind(0d0))\r\n\tREAL(kind=8), PARAMETER :: dz=2.0d0*pi*Lz/REAL(Nz,kind(0d0))\r\n\tREAL(kind=8), PARAMETER :: ReInv=1.0d0/REAL(Re,kind(0d0))\r\n\tREAL(kind=8), PARAMETER :: dtInv=1.0d0/REAL(dt,kind(0d0)) \r\n\t!computational arrays/scalars\r\n\tREAL(kind=8) :: scalemodes,chg,factor,temp3\r\n\tREAL(kind=8), DIMENSION(:), ALLOCATABLE\t\t\t:: x, y, z, time,mychg,allchg\r\n\tREAL(kind=8), DIMENSION(:), ALLOCATABLE\t\t\t:: KE,Enstrophy,&\r\n KEdissipationRate\r\n \tREAL(kind=8), DIMENSION(:), ALLOCATABLE\t\t\t:: temp1,temp2\r\n \tREAL(kind=8), DIMENSION(:,:,:), ALLOCATABLE\t\t:: temp,omega\r\n\tREAL(kind=8), DIMENSION(:,:,:), ALLOCATABLE\t\t:: u, v, w,&\r\n ux, uy, uz,&\r\n vx, vy, vz,&\r\n wx, wy, wz,&\r\n uold, uxold, uyold, uzold,&\r\n vold, vxold, vyold, vzold,&\r\n wold, wxold, wyold, wzold,&\r\n utemp, vtemp, wtemp, temp_r\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\tCOMPLEX(kind=8), DIMENSION(:), ALLOCATABLE\t\t:: kx, ky, kz\t\t\t\t\t\t\r\n\tCOMPLEX(kind=8), DIMENSION(:,:,:), ALLOCATABLE\t:: uhat, vhat, what,&\r\n rhsuhatfix, rhsvhatfix,&\r\n rhswhatfix, nonlinuhat,&\r\n nonlinvhat, nonlinwhat,&\r\n phat,temp_c\r\n\t! MPI and 2DECOMP variables\r\n\tTYPE(DECOMP_INFO) :: decomp,sp\r\n\tINTEGER(kind=MPI_OFFSET_KIND) :: filesize, disp\r\n\tINTEGER(kind=4) :: p_row=0, p_col=0, numprocs, myid, ierr\t\r\n\t\r\n\t! variables used for saving data and timing\r\n\tINTEGER(kind=4) :: count, iol, convDiag=0\r\n\tINTEGER(kind=4) :: i,j,k,n,nn,t,allocatestatus,plotInt=0\r\n\tINTEGER(kind=4) :: ind\r\n\tCHARACTER*100 :: name_config,number_file\r\n\tINTEGER(kind=4) :: start, finish, count_rate\r\n\t\r\n\t! initialisation of 2DECOMP&FFT and MPI\r\n\tCALL MPI_INIT(ierr)\r\n\tCALL MPI_COMM_SIZE(MPI_COMM_WORLD, numprocs, ierr)\r\n\tCALL MPI_COMM_RANK(MPI_COMM_WORLD, myid, ierr) \r\n\tCALL decomp_2d_init(Nx,Ny,Nz,p_row,p_col)\r\n\tCALL decomp_info_init(Nx,Ny,Nz,decomp)\r\n \tCALL decomp_info_init(Nx/2+1,Ny,Nz,sp)\r\n\tCALL decomp_2d_fft_init\r\n\r\n\tIF (myid.eq.0) THEN\r\n\t\tPRINT *,'Solve 3D incompressible NS equations with Fourier pseudospectral methods'\r\n\t\tPRINT *,'and Implicit-Midpoint rule timestepping.'\r\n\t\tPRINT *,'Grid:',Nx,'X',Ny,'X',Nz\r\n\t\tPRINT *,'dt:',dt\r\n\t\tPRINT *,'Re:',Re\r\n\t\tPRINT *,'Nt:',Nt\r\n \t\tPRINT *,'plotgap:',plotgap\r\n\tEND IF\t\r\n\tALLOCATE(x(1:Nx),y(1:Ny),z(1:Nz),time(1:numplots+1),mychg(1:3),allchg(1:3),temp1(1:9),temp2(1:9),&\r\n KE(1:numplots+1),Enstrophy(1:numplots+1),KEdissipationRate(1:numplots+1),&\r\n\t\t\t\tu(decomp%xst(1):decomp%xen(1),&\r\n \t\t\t\t\tdecomp%xst(2):decomp%xen(2),&\r\n \t\t\t\t\tdecomp%xst(3):decomp%xen(3)),& \r\n \t\t\t\tv(decomp%xst(1):decomp%xen(1),&\r\n \t\t\t\t\tdecomp%xst(2):decomp%xen(2),&\r\n \t\t\t\t\tdecomp%xst(3):decomp%xen(3)),&\r\n \t\t\t\tw(decomp%xst(1):decomp%xen(1),&\r\n \t\t\t\t\tdecomp%xst(2):decomp%xen(2),&\r\n \t\t\t\t\tdecomp%xst(3):decomp%xen(3)),&\r\n \t\t\t\tux(decomp%xst(1):decomp%xen(1),&\r\n \t\t\t\t\tdecomp%xst(2):decomp%xen(2),&\r\n \t\t\t\t\tdecomp%xst(3):decomp%xen(3)),&\r\n\t\t\t\tuy(decomp%xst(1):decomp%xen(1),&\r\n \t\t\t\t\tdecomp%xst(2):decomp%xen(2),&\r\n \t\t\t\t\tdecomp%xst(3):decomp%xen(3)),&\r\n\t\t\t\tuz(decomp%xst(1):decomp%xen(1),&\r\n \t\t\t\t\tdecomp%xst(2):decomp%xen(2),&\r\n \t\t\t\t\tdecomp%xst(3):decomp%xen(3)),&\r\n\t\t\t\tvx(decomp%xst(1):decomp%xen(1),&\r\n \t\t\t\t\tdecomp%xst(2):decomp%xen(2),&\r\n \t\t\t\t\tdecomp%xst(3):decomp%xen(3)),&\r\n\t\t\t\tvy(decomp%xst(1):decomp%xen(1),&\r\n \t\t\t\t\tdecomp%xst(2):decomp%xen(2),&\r\n \t\t\t\t\tdecomp%xst(3):decomp%xen(3)),&\r\n\t\t\t\tvz(decomp%xst(1):decomp%xen(1),&\r\n \t\t\t\t\tdecomp%xst(2):decomp%xen(2),&\r\n \t\t\t\t\tdecomp%xst(3):decomp%xen(3)),&\r\n\t\t\t\twx(decomp%xst(1):decomp%xen(1),&\r\n \t\t\t\t\tdecomp%xst(2):decomp%xen(2),&\r\n \t\t\t\t\tdecomp%xst(3):decomp%xen(3)),&\r\n\t\t\t\twy(decomp%xst(1):decomp%xen(1),&\r\n \t\t\t\t\tdecomp%xst(2):decomp%xen(2),&\r\n \t\t\t\t\tdecomp%xst(3):decomp%xen(3)),&\r\n\t\t\t\twz(decomp%xst(1):decomp%xen(1),&\r\n \t\t\t\t\tdecomp%xst(2):decomp%xen(2),&\r\n \t\t\t\t\tdecomp%xst(3):decomp%xen(3)),&\r\n\t\t\t\tuold(decomp%xst(1):decomp%xen(1),&\r\n \t\t\t\t\tdecomp%xst(2):decomp%xen(2),&\r\n \t\t\t\t\tdecomp%xst(3):decomp%xen(3)),&\r\n\t\t\t\tuxold(decomp%xst(1):decomp%xen(1),&\r\n \t\t\t\t\tdecomp%xst(2):decomp%xen(2),&\r\n \t\t\t\t\tdecomp%xst(3):decomp%xen(3)),&\r\n\t\t\t\tuyold(decomp%xst(1):decomp%xen(1),&\r\n \t\t\t\t\tdecomp%xst(2):decomp%xen(2),&\r\n \t\t\t\t\tdecomp%xst(3):decomp%xen(3)),&\r\n\t\t\t\tuzold(decomp%xst(1):decomp%xen(1),&\r\n \t\t\t\t\tdecomp%xst(2):decomp%xen(2),&\r\n \t\t\t\t\tdecomp%xst(3):decomp%xen(3)),&\r\n\t\t\t\tvold(decomp%xst(1):decomp%xen(1),&\r\n \t\t\t\t\tdecomp%xst(2):decomp%xen(2),&\r\n \t\t\t\t\tdecomp%xst(3):decomp%xen(3)),&\r\n\t\t\t\tvxold(decomp%xst(1):decomp%xen(1),&\r\n \t\t\t\t\tdecomp%xst(2):decomp%xen(2),&\r\n \t\t\t\t\tdecomp%xst(3):decomp%xen(3)),&\r\n\t\t\t\tvyold(decomp%xst(1):decomp%xen(1),&\r\n \t\t\t\t\tdecomp%xst(2):decomp%xen(2),&\r\n \t\t\t\t\tdecomp%xst(3):decomp%xen(3)),&\r\n\t\t\t\tvzold(decomp%xst(1):decomp%xen(1),&\r\n \t\t\t\t\tdecomp%xst(2):decomp%xen(2),&\r\n \t\t\t\t\tdecomp%xst(3):decomp%xen(3)),&\r\n\t\t\t\twold(decomp%xst(1):decomp%xen(1),&\r\n \t\t\t\t\tdecomp%xst(2):decomp%xen(2),&\r\n \t\t\t\t\tdecomp%xst(3):decomp%xen(3)),&\r\n\t\t\t\twxold(decomp%xst(1):decomp%xen(1),&\r\n \t\t\t\t\tdecomp%xst(2):decomp%xen(2),&\r\n \t\t\t\t\tdecomp%xst(3):decomp%xen(3)),&\r\n\t\t\t\twyold(decomp%xst(1):decomp%xen(1),&\r\n \t\t\t\t\tdecomp%xst(2):decomp%xen(2),&\r\n \t\t\t\t\tdecomp%xst(3):decomp%xen(3)),&\r\n\t\t\t\twzold(decomp%xst(1):decomp%xen(1),&\r\n \t\t\t\t\tdecomp%xst(2):decomp%xen(2),&\r\n \t\t\t\t\tdecomp%xst(3):decomp%xen(3)),&\r\n\t\t\t\tutemp(decomp%xst(1):decomp%xen(1),&\r\n \t\t\t\t\tdecomp%xst(2):decomp%xen(2),&\r\n \t\t\t\t\tdecomp%xst(3):decomp%xen(3)),&\r\n \t\t\t\tvtemp(decomp%xst(1):decomp%xen(1),&\r\n \t\t\t\t\tdecomp%xst(2):decomp%xen(2),&\r\n \t\t\t\t\tdecomp%xst(3):decomp%xen(3)),&\r\n \t\t\t\twtemp(decomp%xst(1):decomp%xen(1),&\r\n \t\t\t\t\tdecomp%xst(2):decomp%xen(2),&\r\n \t\t\t\t\tdecomp%xst(3):decomp%xen(3)),&\r\n \t\t\t\ttemp_r(decomp%xst(1):decomp%xen(1),&\r\n \t\t\t\t\tdecomp%xst(2):decomp%xen(2),&\r\n \t\t\t\t\tdecomp%xst(3):decomp%xen(3)),&\r\n omega(decomp%xst(1):decomp%xen(1),&\r\n decomp%xst(2):decomp%xen(2),&\r\n decomp%xst(3):decomp%xen(3)),&\r\n\t temp(decomp%xst(1):decomp%xen(1),&\r\n decomp%xst(2):decomp%xen(2),&\r\n decomp%xst(3):decomp%xen(3)),&\r\n\t\t\t\tkx(1:Nx),ky(1:Ny),kz(1:Nz),&\r\n\t\t\t\tuhat(sp%zst(1):sp%zen(1),&\r\n \t\t\t\t\tsp%zst(2):sp%zen(2),&\r\n \t\t\t\t\tsp%zst(3):sp%zen(3)),&\r\n\t\t\t\tvhat(sp%zst(1):sp%zen(1),&\r\n \t\t\t\t\tsp%zst(2):sp%zen(2),&\r\n \t\t\t\t\tsp%zst(3):sp%zen(3)),&\r\n\t \t\t\twhat(sp%zst(1):sp%zen(1),&\r\n \t\t\t\t\tsp%zst(2):sp%zen(2),&\r\n \t\t\t\t\tsp%zst(3):sp%zen(3)),&\r\n\t \t\t\trhsuhatfix(sp%zst(1):sp%zen(1),&\r\n \t\t\t\t\tsp%zst(2):sp%zen(2),&\r\n \t\t\t\t\tsp%zst(3):sp%zen(3)),&\r\n \t\t\t\trhsvhatfix(sp%zst(1):sp%zen(1),&\r\n \t\t\t\t\tsp%zst(2):sp%zen(2),&\r\n \t\t\t\t\tsp%zst(3):sp%zen(3)),&\r\n \t\t\t\trhswhatfix(sp%zst(1):sp%zen(1),&\r\n \t\t\t\t\tsp%zst(2):sp%zen(2),&\r\n \t\t\t\t\tsp%zst(3):sp%zen(3)),&\r\n \t\t\t\tnonlinuhat(sp%zst(1):sp%zen(1),&\r\n \t\t\t\t\tsp%zst(2):sp%zen(2),&\r\n \t\t\t\t\tsp%zst(3):sp%zen(3)),&\r\n \t\t\t\tnonlinvhat(sp%zst(1):sp%zen(1),&\r\n \t\t\t\t\tsp%zst(2):sp%zen(2),&\r\n \t\t\t\t\tsp%zst(3):sp%zen(3)),&\r\n \t\t\t\tnonlinwhat(sp%zst(1):sp%zen(1),&\r\n \t\t\t\t\tsp%zst(2):sp%zen(2),&\r\n \t\t\t\t\tsp%zst(3):sp%zen(3)),&\r\n \t\t\t\tphat(sp%zst(1):sp%zen(1),&\r\n \t\t\t\t\tsp%zst(2):sp%zen(2),&\r\n \t\t\t\t\tsp%zst(3):sp%zen(3)),&\r\n \t\t\t\ttemp_c(sp%zst(1):sp%zen(1),&\r\n \t\t\t\t\tsp%zst(2):sp%zen(2),&\r\n \t\t\t\t\tsp%zst(3):sp%zen(3)),&\r\n\t\t\t\tstat=AllocateStatus)\t\r\n\tIF (AllocateStatus .ne. 0) STOP\r\n\tIF (myid.eq.0) THEN\r\n\t \tPRINT *,'allocated space'\r\n\tEND IF\r\n\r\n\t! setup fourier frequencies in x-direction\r\n\tDO i=1,Nx/2+1\r\n\t\tkx(i)= cmplx(0.0d0,1.0d0)*REAL(i-1,kind(0d0))/Lx \t\t\t\r\n\tEND DO\r\n\tkx(1+Nx/2)=0.0d0\r\n\tDO i = 1,Nx/2 -1\r\n\t\tkx(i+1+Nx/2)=-kx(1-i+Nx/2)\r\n\tEND DO\t\r\n\tind=1\r\n\tDO i=-Nx/2,Nx/2-1\r\n\t\tx(ind)=2.0d0*pi*REAL(i,kind(0d0))*Lx/REAL(Nx,kind(0d0))\r\n\t\tind=ind+1\r\n\tEND DO\r\n\t! setup fourier frequencies in y-direction\r\n\tDO j=1,Ny/2+1\r\n\t\tky(j)= cmplx(0.0d0,1.0d0)*REAL(j-1,kind(0d0))/Ly \t\t\t\r\n\tEND DO\r\n\tky(1+Ny/2)=0.0d0\r\n\tDO j = 1,Ny/2 -1\r\n\t\tky(j+1+Ny/2)=-ky(1-j+Ny/2)\r\n\tEND DO\t\r\n\tind=1\r\n\tDO j=-Ny/2,Ny/2-1\r\n\t\ty(ind)=2.0d0*pi*REAL(j,kind(0d0))*Ly/REAL(Ny,kind(0d0))\r\n\t\tind=ind+1\r\n\tEND DO\r\n\t! setup fourier frequencies in z-direction\r\n\tDO k=1,Nz/2+1\r\n\t\tkz(k)= cmplx(0.0d0,1.0d0)*REAL(k-1,kind(0d0))/Lz \t\t\t\r\n\tEND DO\r\n\tkz(1+Nz/2)=0.0d0\r\n\tDO k = 1,Nz/2 -1\r\n\t\tkz(k+1+Nz/2)=-kz(1-k+Nz/2)\r\n\tEND DO\t\r\n\tind=1\r\n\tDO k=-Nz/2,Nz/2-1\r\n\t\tz(ind)=2.0d0*pi*REAL(k,kind(0d0))*Lz/REAL(Nz,kind(0d0))\r\n\t\tind=ind+1\r\n\tEND DO\r\n\tIF (myid.eq.0) THEN\r\n\t\tPRINT *,'Setup grid and fourier frequencies'\r\n\tEND IF\t\r\n\tscalemodes=1.0d0/REAL(Nx*Ny*Nz,kind(0d0)); time(1)=0.0d0; \r\n\r\n IF(readInput.eqv..true.) THEN\r\n\t\tname_config='./data/restartData'\r\n\t\tOPEN(unit=11,file=name_config,status='old')\r\n\t\tREWIND(11)\r\n\t\tREAD(11,*) time(1),plotInt\r\n\t\tCLOSE(11)\r\n name_config='./data/u'\r\n CALL getName(name_config,plotInt)\r\n CALL decomp_2d_read_one(1,u,name_config)\r\n name_config='./data/v'\r\n CALL getName(name_config,plotInt)\r\n CALL decomp_2d_read_one(1,v,name_config)\r\n name_config='./data/w'\r\n CALL getName(name_config,plotInt)\r\n CALL decomp_2d_read_one(1,w,name_config)\r\n IF(myid.eq.0) THEN\r\n PRINT*,'Read in values'\r\n END IF\r\n ELSE If(TGvortex.eqv..true.) THEN\r\n\t !initial conditions for Taylor-Green vortex\r\n\t factor=2.0d0/sqrt(3.0d0)\r\n DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\r\n\t u(i,j,k)=factor*sin(theta+2.0d0*pi/3.0d0)*sin(x(i))*cos(y(j))*cos(z(k))\r\n END DO; END DO; END DO\r\n DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\r\n\t v(i,j,k)=factor*sin(theta-2.0d0*pi/3.0d0)*cos(x(i))*sin(y(j))*cos(z(k))\r\n END DO ; END DO ; END DO\r\n DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\r\n\t w(i,j,k)=factor*sin(theta)*cos(x(i))*cos(y(j))*sin(z(k))\r\n END DO ; END DO ; END DO\r\n IF(myid.eq.0) THEN\r\n PRINT*,'Taylor-Green Vortex initial conditions'\r\n END IF\r\n ELSE IF(exactsoln.eqv..true.) THEN\r\n\t\t!special exact sol'n usted for testing\r\n\t\tfactor=sqrt(3.0d0)\r\n\t\tDO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\r\n\t\t\tu(i,j,k)=-0.5*( factor*cos(x(i))*sin(y(j))*sin(z(k))&\r\n\t\t\t\t\t\t\t+sin(x(i))*cos(y(j))*cos(z(k)) )*exp(-(factor**2)*time(1)/Re)\r\n\t\tEND DO; END DO; END DO\r\n\t\tDO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\r\n\t\t\tv(i,j,k)=0.5*( factor*sin(x(i))*cos(y(j))*sin(z(k))&\r\n\t\t\t\t\t\t\t-cos(x(i))*sin(y(j))*cos(z(k)) )*exp(-(factor**2)*time(1)/Re)\r\n\t\tEND DO ; END DO ; END DO\r\n\t\tDO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\r\n\t\t\tw(i,j,k)=cos(x(i))*cos(y(j))*sin(z(k))*exp(-(factor**2)*time(1)/Re)\r\n\t\tEND DO ; END DO ; END DO\r\n IF(myid.eq.0) THEN\r\n PRINT*,'Exact Solution initial conditions'\r\n END IF\r\n\tELSE\r\n IF(myid.eq.0) THEN\r\n PRINT*,'--------------------------------------------------------------------'\r\n\t\t PRINT*,'Set initial conditions to either readinput, TGvortex, or exactsoln.'\r\n PRINT*,'--------------------------------------------------------------------'\r\n goto 111\r\n END IF\r\n\tEND IF\r\n \r\n\tCALL decomp_2d_fft_3d(u,uhat)\r\n CALL decomp_2d_fft_3d(v,vhat)\r\n\tCALL decomp_2d_fft_3d(w,what)\r\n\t\r\n\t! derivative of u with respect to x, y, and z \r\n\tDO k=sp%zst(3),sp%zen(3) ; DO j=sp%zst(2),sp%zen(2) ; DO i=sp%zst(1),sp%zen(1)\r\n\t\ttemp_c(i,j,k)=uhat(i,j,k)*kx(i)*scalemodes\r\n\tEND DO ; END DO ; END DO\r\n\tCALL decomp_2d_fft_3d(temp_c,ux)\t\r\n\tDO k=sp%zst(3),sp%zen(3) ; DO j=sp%zst(2),sp%zen(2) ; DO i=sp%zst(1),sp%zen(1)\r\n\t\ttemp_c(i,j,k)=uhat(i,j,k)*ky(j)*scalemodes\r\n\tEND DO ; END DO ; END DO\r\n\tCALL decomp_2d_fft_3d(temp_c,uy)\t\r\n\tDO k=sp%zst(3),sp%zen(3) ; DO j=sp%zst(2),sp%zen(2) ; DO i=sp%zst(1),sp%zen(1)\r\n\t\ttemp_c(i,j,k)=uhat(i,j,k)*kz(k)*scalemodes\r\n\tEND DO ; END DO ; END DO\r\n\tCALL decomp_2d_fft_3d(temp_c,uz)\t\r\n\r\n\t! derivative of v with respect to x, y, and z \r\n\tDO k=sp%zst(3),sp%zen(3) ; DO j=sp%zst(2),sp%zen(2) ; DO i=sp%zst(1),sp%zen(1)\r\n\t\ttemp_c(i,j,k)=vhat(i,j,k)*kx(i)*scalemodes\r\n\tEND DO ; END DO ; END DO\r\n\tCALL decomp_2d_fft_3d(temp_c,vx)\t\t\r\n\tDO k=sp%zst(3),sp%zen(3) ; DO j=sp%zst(2),sp%zen(2) ; DO i=sp%zst(1),sp%zen(1)\r\n\t\ttemp_c(i,j,k)=vhat(i,j,k)*ky(j)*scalemodes\r\n\tEND DO ; END DO ; END DO\r\n\tCALL decomp_2d_fft_3d(temp_c,vy)\t\r\n\tDO k=sp%zst(3),sp%zen(3) ; DO j=sp%zst(2),sp%zen(2) ; DO i=sp%zst(1),sp%zen(1)\r\n\t\ttemp_c(i,j,k)=vhat(i,j,k)*kz(k)*scalemodes\r\n\tEND DO ; END DO ; END DO\r\n\tCALL decomp_2d_fft_3d(temp_c,vz)\t\t\r\n\r\n\t! derivative of w with respect to x, y, and z \r\n\tDO k=sp%zst(3),sp%zen(3) ; DO j=sp%zst(2),sp%zen(2) ; DO i=sp%zst(1),sp%zen(1)\r\n\t\ttemp_c(i,j,k)=what(i,j,k)*kx(i)*scalemodes\r\n\tEND DO ; END DO ; END DO\r\n\tCALL decomp_2d_fft_3d(temp_c,wx)\t\t\r\n\tDO k=sp%zst(3),sp%zen(3) ; DO j=sp%zst(2),sp%zen(2) ; DO i=sp%zst(1),sp%zen(1)\r\n\t\ttemp_c(i,j,k)=what(i,j,k)*ky(j)*scalemodes\r\n\tEND DO ; END DO ; END DO\r\n\tCALL decomp_2d_fft_3d(temp_c,wy)\t\t\r\n\tDO k=sp%zst(3),sp%zen(3) ; DO j=sp%zst(2),sp%zen(2) ; DO i=sp%zst(1),sp%zen(1)\r\n\t\ttemp_c(i,j,k)=what(i,j,k)*kz(k)*scalemodes\r\n\tEND DO ; END DO ; END DO\r\n\tCALL decomp_2d_fft_3d(temp_c,wz)\r\n \r\n\t!calculate vorticity\r\n\tDO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\r\n\t\ttemp(i,j,k)=wy(i,j,k)-vz(i,j,k)\r\n\tEND DO ; END DO ; END DO\r\n\r\n\tDO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\r\n\t\tomega(i,j,k)=temp(i,j,k)*temp(i,j,k)\r\n\tEND DO ; END DO ; END DO\r\n\r\n\tDO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\r\n\t\ttemp(i,j,k)=uz(i,j,k)-wx(i,j,k)\r\n\tEND DO ; END DO ; END DO\r\n\r\n\tDO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\r\n\t\tomega(i,j,k)=temp(i,j,k)*temp(i,j,k)+omega(i,j,k)\r\n\tEND DO ; END DO ; END DO\r\n\r\n\tDO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\r\n\t\ttemp(i,j,k)=vx(i,j,k)-uy(i,j,k)\r\n\tEND DO ; END DO ; END DO\r\n\tDO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\r\n\t\tomega(i,j,k)=temp(i,j,k)*temp(i,j,k)+omega(i,j,k)\r\n\tEND DO ; END DO ; END DO\r\n\r\n\t!Calculate Kinetic Energy\r\n\ttemp1(1) = sum(u*u)\r\n\ttemp1(2) = sum(v*v)\r\n\ttemp1(3) = sum(w*w)\r\n\tCALL MPI_ALLREDUCE(temp1(1:3),temp2(1:3),3,MPI_DOUBLE_PRECISION,MPI_SUM,MPI_COMM_WORLD,ierr)\r\n\ttemp3=temp2(1)+temp2(2)+temp2(3)\r\n\tKE(1)=dx*dy*dz*temp3/(8.0d0*2.0d0*pi*pi*pi)\r\n\r\n\t!Calculate Enstrophy\r\n temp1(1)=sum(omega)\r\n\tCALL MPI_ALLREDUCE(temp1(1),temp3,1,MPI_DOUBLE_PRECISION,MPI_SUM,MPI_COMM_WORLD,ierr)\r\n Enstrophy(1)=dx*dy*dz*temp3/(8.0d0*2.0d0*pi*pi*pi)\r\n\r\n\ttemp1=0.0;temp2=0.0\r\n\t!Calculate Kinetic Energy Dissipation Rate\r\n\ttemp1(1)=sum(ux*ux)\r\n\ttemp1(2)=sum(uy*uy)\r\n\ttemp1(3)=sum(uz*uz)\r\n\ttemp1(4)=sum(vx*vx)\r\n\ttemp1(5)=sum(vy*vy)\r\n\ttemp1(6)=sum(vz*vz)\r\n\ttemp1(7)=sum(wx*wx)\r\n\ttemp1(8)=sum(wy*wy)\r\n\ttemp1(9)=sum(wz*wz)\r\n\tCALL MPI_ALLREDUCE(temp1,temp2,9,MPI_DOUBLE_PRECISION,MPI_SUM,MPI_COMM_WORLD,ierr)\r\n\ttemp3=temp2(1)+temp2(2)+temp2(3)+temp2(4)+temp2(5)+temp2(6)+temp2(7)+temp2(8)+temp2(9)\r\n\tKEdissipationRate(1)=dx*dy*dz*temp3/(8.0d0*Re*pi*pi*pi)\r\n \r\n IF(myid.eq.0) THEN\r\n PRINT *,'time=',time(1)\r\n\t PRINT*,'KE=',KE(1)\r\n\t PRINT*,'Enstrophy=',Enstrophy(1)\r\n\t PRINT*,'KEdissipationRate=',KEdissipationRate(1)\r\n PRINT*,'---------------------------------'\r\n\t\tPRINT*,'starting timestepping and timer'\r\n \tPRINT*,'---------------------------------'\r\n END IF \r\n CALL system_clock(start,count_rate)\r\n DO n=1,numplots\r\n DO nn=1,plotgap\r\n\t\t !fixed point\r\n\t\t DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\r\n\t\t\t uold(i,j,k)=u(i,j,k)\r\n\t\t\t uxold(i,j,k)=ux(i,j,k)\r\n\t\t\t uyold(i,j,k)=uy(i,j,k)\r\n\t\t\t uzold(i,j,k)=uz(i,j,k)\r\n\t\t END DO ; END DO ; END DO\r\n\t\t DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\r\n\t\t\t vold(i,j,k)=v(i,j,k)\r\n\t\t\t vxold(i,j,k)=vx(i,j,k)\r\n\t\t\t vyold(i,j,k)=vy(i,j,k)\r\n\t\t\t vzold(i,j,k)=vz(i,j,k)\r\n\t\t END DO ; END DO ; END DO\r\n\t\t DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\r\n\t\t\t wold(i,j,k)=w(i,j,k)\r\n\t\t\t wxold(i,j,k)=wx(i,j,k)\r\n\t\t\t wyold(i,j,k)=wy(i,j,k)\r\n\t\t\t wzold(i,j,k)=wz(i,j,k)\r\n\t\t END DO ; END DO ; END DO\r\n \r\n\t\t DO k=sp%zst(3),sp%zen(3) ; DO j=sp%zst(2),sp%zen(2) ; DO i=sp%zst(1),sp%zen(1)\r\n \t\trhsuhatfix(i,j,k) = (dtInv+(0.5d0*ReInv)*(kx(i)*kx(i)+ky(j)*ky(j)+kz(k)*kz(k)))*uhat(i,j,k) \r\n\t\t END DO ; END DO ; END DO\r\n\t\t DO k=sp%zst(3),sp%zen(3) ; DO j=sp%zst(2),sp%zen(2) ; DO i=sp%zst(1),sp%zen(1)\r\n\t\t\t rhsvhatfix(i,j,k) = (dtInv+(0.5d0*ReInv)*(kx(i)*kx(i)+ky(j)*ky(j)+kz(k)*kz(k)))*vhat(i,j,k) \r\n\t\t END DO ; END DO ; END DO\r\n\t\t DO k=sp%zst(3),sp%zen(3) ; DO j=sp%zst(2),sp%zen(2) ; DO i=sp%zst(1),sp%zen(1)\r\n\t\t\t rhswhatfix(i,j,k) = (dtInv+(0.5d0*ReInv)*(kx(i)*kx(i)+ky(j)*ky(j)+kz(k)*kz(k)))*what(i,j,k) \r\n\t\t END DO ; END DO ; END DO\r\n\t\t\r\n\t\t chg=1\r\n convDiag=0\r\n\t\t DO WHILE (chg .gt. tol)\r\n\t\t\t DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\r\n\t\t\t\t temp_r(i,j,k)=0.25d0*((u(i,j,k)+uold(i,j,k))*(ux(i,j,k)+uxold(i,j,k))&\r\n\t\t\t\t\t\t\t\t\t\t +(v(i,j,k)+vold(i,j,k))*(uy(i,j,k)+uyold(i,j,k))&\r\n\t\t\t\t\t\t\t\t\t\t +(w(i,j,k)+wold(i,j,k))*(uz(i,j,k)+uzold(i,j,k)))\r\n\t\t\t END DO ; END DO ; END DO\r\n\t\t\t CALL decomp_2d_fft_3d(temp_r,nonlinuhat)\r\n\t\t\t DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\r\n\t\t\t\t temp_r(i,j,k)=0.25d0*((u(i,j,k)+uold(i,j,k))*(vx(i,j,k)+vxold(i,j,k))&\r\n\t\t\t\t\t\t\t\t\t\t +(v(i,j,k)+vold(i,j,k))*(vy(i,j,k)+vyold(i,j,k))&\r\n\t\t\t\t\t\t\t\t\t\t +(w(i,j,k)+wold(i,j,k))*(vz(i,j,k)+vzold(i,j,k)))\r\n\t\t\t END DO ; END DO ; END DO\r\n\t\t\t CALL decomp_2d_fft_3d(temp_r,nonlinvhat)\r\n\t\t\t DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\r\n\t\t\t\t temp_r(i,j,k)=0.25d0*((u(i,j,k)+uold(i,j,k))*(wx(i,j,k)+wxold(i,j,k))&\r\n\t\t\t\t\t\t\t\t\t\t +(v(i,j,k)+vold(i,j,k))*(wy(i,j,k)+wyold(i,j,k))&\r\n\t\t\t\t\t\t\t\t\t\t +(w(i,j,k)+wold(i,j,k))*(wz(i,j,k)+wzold(i,j,k)))\r\n\t\t\t END DO ; END DO ; END DO\r\n\t\t\t CALL decomp_2d_fft_3d(temp_r,nonlinwhat)\r\n\t\t\t DO k=sp%zst(3),sp%zen(3) ; DO j=sp%zst(2),sp%zen(2) ; DO i=sp%zst(1),sp%zen(1)\r\n\t\t\t\t phat(i,j,k)=-1.0d0*( kx(i)*nonlinuhat(i,j,k)&\r\n\t\t\t\t\t\t\t+ky(j)*nonlinvhat(i,j,k)&\r\n\t\t\t\t\t\t\t+kz(k)*nonlinwhat(i,j,k))&\r\n\t\t\t\t\t\t/(kx(i)*kx(i)+ky(j)*ky(j)+kz(k)*kz(k)+0.1d0**13)\r\n\t\t\t END DO ; END DO ; END DO\r\n\r\n\t\t\t DO k=sp%zst(3),sp%zen(3) ; DO j=sp%zst(2),sp%zen(2) ; DO i=sp%zst(1),sp%zen(1)\r\n\t\t\t\t uhat(i,j,k)=(rhsuhatfix(i,j,k)-nonlinuhat(i,j,k)-kx(i)*phat(i,j,k))/&\r\n\t\t\t\t\t\t\t (dtInv-(0.5d0*ReInv)*(kx(i)*kx(i)+ky(j)*ky(j)+kz(k)*kz(k))) !*scalemodes\r\n\t\t\t END DO ; END DO ; END DO\r\n\t\t\t DO k=sp%zst(3),sp%zen(3) ; DO j=sp%zst(2),sp%zen(2) ; DO i=sp%zst(1),sp%zen(1)\r\n\t\t\t\t vhat(i,j,k)=(rhsvhatfix(i,j,k)-nonlinvhat(i,j,k)-ky(j)*phat(i,j,k))/&\r\n\t\t\t\t\t\t\t (dtInv-(0.5d0*ReInv)*(kx(i)*kx(i)+ky(j)*ky(j)+kz(k)*kz(k))) !*scalemodes\r\n\t\t\t END DO ; END DO ; END DO\r\n\t\t\t DO k=sp%zst(3),sp%zen(3) ; DO j=sp%zst(2),sp%zen(2) ; DO i=sp%zst(1),sp%zen(1)\r\n\t\t\t\t what(i,j,k)=(rhswhatfix(i,j,k)-nonlinwhat(i,j,k)-kz(k)*phat(i,j,k))/&\r\n\t\t\t\t\t\t\t (dtInv-(0.5d0*ReInv)*(kx(i)*kx(i)+ky(j)*ky(j)+kz(k)*kz(k))) !*scalemodes\r\n\t\t\t END DO ; END DO ; END DO\r\n\r\n\t ! derivative of u with respect to x, y, and z \r\n\t DO k=sp%zst(3),sp%zen(3) ; DO j=sp%zst(2),sp%zen(2) ; DO i=sp%zst(1),sp%zen(1)\r\n\t\t temp_c(i,j,k)=uhat(i,j,k)*kx(i)*scalemodes\r\n\t END DO ; END DO ; END DO\r\n\t CALL decomp_2d_fft_3d(temp_c,ux)\t\r\n\t DO k=sp%zst(3),sp%zen(3) ; DO j=sp%zst(2),sp%zen(2) ; DO i=sp%zst(1),sp%zen(1)\r\n\t\t temp_c(i,j,k)=uhat(i,j,k)*ky(j)*scalemodes\r\n\t END DO ; END DO ; END DO\r\n\t CALL decomp_2d_fft_3d(temp_c,uy)\t\r\n\t DO k=sp%zst(3),sp%zen(3) ; DO j=sp%zst(2),sp%zen(2) ; DO i=sp%zst(1),sp%zen(1)\r\n\t\t temp_c(i,j,k)=uhat(i,j,k)*kz(k)*scalemodes\r\n\t END DO ; END DO ; END DO\r\n\t CALL decomp_2d_fft_3d(temp_c,uz)\t\r\n\r\n\t ! derivative of v with respect to x, y, and z \r\n\t DO k=sp%zst(3),sp%zen(3) ; DO j=sp%zst(2),sp%zen(2) ; DO i=sp%zst(1),sp%zen(1)\r\n\t\t temp_c(i,j,k)=vhat(i,j,k)*kx(i)*scalemodes\r\n\t END DO ; END DO ; END DO\r\n\t CALL decomp_2d_fft_3d(temp_c,vx)\t\t\r\n\t DO k=sp%zst(3),sp%zen(3) ; DO j=sp%zst(2),sp%zen(2) ; DO i=sp%zst(1),sp%zen(1)\r\n\t\t temp_c(i,j,k)=vhat(i,j,k)*ky(j)*scalemodes\r\n\t END DO ; END DO ; END DO\r\n\t CALL decomp_2d_fft_3d(temp_c,vy)\t\r\n\t DO k=sp%zst(3),sp%zen(3) ; DO j=sp%zst(2),sp%zen(2) ; DO i=sp%zst(1),sp%zen(1)\r\n\t\t temp_c(i,j,k)=vhat(i,j,k)*kz(k)*scalemodes\r\n\t END DO ; END DO ; END DO\r\n\t CALL decomp_2d_fft_3d(temp_c,vz)\t\t\r\n\r\n\t ! derivative of w with respect to x, y, and z \r\n\t DO k=sp%zst(3),sp%zen(3) ; DO j=sp%zst(2),sp%zen(2) ; DO i=sp%zst(1),sp%zen(1)\r\n\t\t temp_c(i,j,k)=what(i,j,k)*kx(i)*scalemodes\r\n\t END DO ; END DO ; END DO\r\n\t CALL decomp_2d_fft_3d(temp_c,wx)\t\t\r\n\t DO k=sp%zst(3),sp%zen(3) ; DO j=sp%zst(2),sp%zen(2) ; DO i=sp%zst(1),sp%zen(1)\r\n\t\t temp_c(i,j,k)=what(i,j,k)*ky(j)*scalemodes\r\n\t END DO ; END DO ; END DO\r\n\t CALL decomp_2d_fft_3d(temp_c,wy)\t\t\r\n\t DO k=sp%zst(3),sp%zen(3) ; DO j=sp%zst(2),sp%zen(2) ; DO i=sp%zst(1),sp%zen(1)\r\n\t\t temp_c(i,j,k)=what(i,j,k)*kz(k)*scalemodes\r\n\t END DO ; END DO ; END DO\r\n\t CALL decomp_2d_fft_3d(temp_c,wz)\t\r\n\r\n\t\tDO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\r\n\t\t\tutemp(i,j,k)=u(i,j,k)\r\n\t\tEND DO ; END DO ; END DO\r\n\t\tDO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\r\n\t\t\tvtemp(i,j,k)=v(i,j,k)\r\n\t\tEND DO ; END DO ; END DO\r\n\t\tDO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\r\n\t\t\twtemp(i,j,k)=w(i,j,k)\r\n\t\tEND DO ; END DO ; END DO\r\n\r\n\t\tCALL decomp_2d_fft_3d(uhat,u)\t\r\n\t\tCALL decomp_2d_fft_3d(vhat,v)\t\r\n\t\tCALL decomp_2d_fft_3d(what,w)\t\r\n\r\n\t DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\r\n\t\t u(i,j,k)=u(i,j,k)*scalemodes\r\n\t END DO ; END DO ; END DO\r\n\t DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\r\n\t\t v(i,j,k)=v(i,j,k)*scalemodes\r\n\t END DO ; END DO ; END DO\r\n\t DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\r\n\t\t w(i,j,k)=w(i,j,k)*scalemodes\r\n\t END DO ; END DO ; END DO\r\n\t\t\t\t\t\t\r\n\t\tmychg(1) =maxval(abs(utemp-u))\r\n\t\tmychg(2) =maxval(abs(vtemp-v))\r\n\t\tmychg(3) =maxval(abs(wtemp-w))\r\n\t\tCALL MPI_ALLREDUCE(mychg,allchg,3,MPI_DOUBLE_PRECISION,MPI_MAX,MPI_COMM_WORLD,ierr)\r\n\t\tchg=allchg(1)+allchg(2)+allchg(3)\r\n convDiag=convDiag+1\r\n\tEND DO\r\n END DO\r\n \r\n\t !calculate vorticity\r\n\t DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\r\n\t\t temp(i,j,k)=REAL(wy(i,j,k)-vz(i,j,k),KIND=8)\r\n\t END DO ; END DO ; END DO\r\n\r\n\t DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\r\n\t\t omega(i,j,k)=REAL(temp(i,j,k)*temp(i,j,k),KIND=8)\r\n\t END DO ; END DO ; END DO\r\n\r\n\t DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\r\n\t\t temp(i,j,k)=REAL(uz(i,j,k)-wx(i,j,k),KIND=8)\r\n\t END DO ; END DO ; END DO\r\n\r\n\t DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\r\n\t\t omega(i,j,k)=REAL(temp(i,j,k)*temp(i,j,k)+omega(i,j,k),KIND=8)\r\n\t END DO ; END DO ; END DO\r\n\r\n\t DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\r\n\t\t temp(i,j,k)=REAL(vx(i,j,k)-uy(i,j,k),KIND=8)\r\n\t END DO ; END DO ; END DO\r\n\t DO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\r\n\t\t omega(i,j,k)=REAL(temp(i,j,k)*temp(i,j,k)+omega(i,j,k),KIND=8)\r\n\t END DO ; END DO ; END DO\r\n\r\n\t !Calculate Kinetic Energy\r\n\t temp1(1) = sum(u*u)\r\n\t temp1(2) = sum(v*v)\r\n\t temp1(3) = sum(w*w)\r\n\t CALL MPI_ALLREDUCE(temp1(1:3),temp2(1:3),3,MPI_DOUBLE_PRECISION,MPI_SUM,MPI_COMM_WORLD,ierr)\r\n\t temp3=temp2(1)+temp2(2)+temp2(3)\r\n\t KE(n+1)=dx*dy*dz*temp3/(8.0d0*2.0d0*pi*pi*pi)\r\n\r\n\t !Calculate Enstrophy\r\n \t temp1(1)=sum(omega)\r\n\t CALL MPI_ALLREDUCE(temp1(1),temp3,1,MPI_DOUBLE_PRECISION,MPI_SUM,MPI_COMM_WORLD,ierr)\r\n \t Enstrophy(n+1)=dx*dy*dz*temp3/(8.0d0*2.0d0*pi*pi*pi)\r\n\r\n\t temp1=0.0;temp2=0.0\r\n\t !Calculate Kinetic Energy Dissipation Rate\r\n\t temp1(1)=sum(ux*ux)\r\n\t temp1(2)=sum(uy*uy)\r\n\t temp1(3)=sum(uz*uz)\r\n\t temp1(4)=sum(vx*vx)\r\n\t temp1(5)=sum(vy*vy)\r\n\t temp1(6)=sum(vz*vz)\r\n\t temp1(7)=sum(wx*wx)\r\n\t temp1(8)=sum(wy*wy)\r\n\t temp1(9)=sum(wz*wz)\r\n\t CALL MPI_ALLREDUCE(temp1,temp2,9,MPI_DOUBLE_PRECISION,MPI_SUM,MPI_COMM_WORLD,ierr)\r\n\t temp3=temp2(1)+temp2(2)+temp2(3)+temp2(4)+temp2(5)+temp2(6)+temp2(7)+temp2(8)+temp2(9)\r\n KEdissipationRate(n+1)=dx*dy*dz*temp3/(8.0d0*Re*pi*pi*pi)\r\n\t\t\r\n time(n+1)=time(1)+plotgap*dt*n \r\n IF(myid.eq.0) THEN\r\n PRINT*,'time=',time(n+1)\r\n\t PRINT*,'KE=',KE(n+1)\r\n\t PRINT*,'Enstrophy=',Enstrophy(n+1)\r\n\t PRINT*,'KEdissipationRate=',KEdissipationRate(n+1)\r\n PRINT*,'Number of Steps for Convergence=',convDiag\r\n PRINT*,'---------------------------------'\r\n END IF\r\n IF(savedata1==1) THEN\r\n\t plotInt=plotInt+1\r\n name_config='./data/u'\r\n CALL savedata(Nx,Ny,Nz,plotInt,name_config,u,decomp)\r\n name_config='./data/v'\r\n CALL savedata(Nx,Ny,Nz,plotInt,name_config,v,decomp)\r\n name_config='./data/w'\r\n CALL savedata(Nx,Ny,Nz,plotInt,name_config,w,decomp)\r\n\t name_config='./data/omega'\r\n CALL savedata(Nx,Ny,Nz,plotInt,name_config,omega,decomp)\r\n END IF\r\n IF (savedata1==1) THEN\r\n IF (myid.eq.0) THEN\r\n name_config='./data/KineticEnergy' \r\n\t OPEN(UNIT=13, FILE=name_config,position='append') \r\n\t write(13,*) KE(n+1)\r\n CLOSE(13)\r\n\r\n name_config='./data/Enstrophy' \r\n\t OPEN(UNIT=13, FILE=name_config,position='append') \r\n\t write(13,*) Enstrophy(n)\r\n CLOSE(13)\r\n\r\n name_config='./data/KEdissipationRate' \r\n\t OPEN(UNIT=13, FILE=name_config,position='append') \r\n\t write(13,*) KEdissipationRate(n)\r\n CLOSE(13)\r\n\r\n name_config='./data/tdata' \r\n\t OPEN(UNIT=13, FILE=name_config,position='append') \r\n\t write(13,*) time(n)\r\n CLOSE(13)\r\n\r\n\t\t\t!time and plot number needed for restart\r\n name_config='./data/restartData'\r\n\t OPEN(UNIT=13, FILE=name_config, status='unknown') \r\n\t REWIND(13)\r\n\t write(13,*) time(n),plotInt\r\n CLOSE(13)\r\n END IF\r\n END IF\r\n\r\n\tEND DO\r\n \r\n CALL system_clock(finish,count_rate)\r\n IF (myid.eq.0) then\r\n PRINT *, 'Program took', REAL(finish-start)/REAL(count_rate), 'for main timestepping loop'\r\n END IF\r\n\t \r\n\tIF(exactsoln.eqv..true.) THEN\r\n\t\t!Calculate error in final numerical solution\r\n\t\tDO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\r\n\t\t\tutemp(i,j,k)=u(i,j,k) -&\r\n\t\t\t\t\t(-0.5*( factor*cos(x(i))*sin(y(j))*sin(z(k))&\r\n\t\t\t\t\t+sin(x(i))*cos(y(j))*cos(z(k)) )*exp(-(factor**2)*time(numplots+1)/Re))\r\n\t\tEND DO; END DO; END DO\r\n\t\tDO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\r\n\t\t\tvtemp(i,j,k)=v(i,j,k) -&\r\n\t\t\t\t\t(0.5*( factor*sin(x(i))*cos(y(j))*sin(z(k))&\r\n\t\t\t\t\t\t-cos(x(i))*sin(y(j))*cos(z(k)) )*exp(-(factor**2)*time(numplots+1)/Re))\r\n\t\tEND DO ; END DO ; END DO\r\n\t\tDO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\r\n\t\t\twtemp(i,j,k)=w(i,j,k)-&\r\n\t\t\t\t\t(cos(x(i))*cos(y(j))*sin(z(k))*exp(-(factor**2)*time(numplots+1)/Re))\r\n\t\tEND DO ; END DO ; END DO\r\n\t\tmychg(1) = maxval(abs(utemp)); mychg(2) = maxval(abs(vtemp)); mychg(3) = maxval(abs(wtemp))\r\n\t\tCALL MPI_ALLREDUCE(mychg,allchg,3,MPI_DOUBLE_PRECISION,MPI_MAX,MPI_COMM_WORLD,ierr)\r\n\t\tchg=allchg(1)+allchg(2)+allchg(3)\r\n\t\tIF (myid.eq.0) THEN\r\n\t\t\tPRINT*,'The error at time',time(numplots+1),'is=',chg\r\n\t\tEND IF\r\n\tEND IF\r\n\t\t\r\n\r\n\r\n 111 continue\r\n !clean up \r\n \tCALL decomp_2d_fft_finalize\r\n \tCALL decomp_2d_finalize\r\n\r\n\tDEALLOCATE(x,y,z,time,mychg,allchg,temp,temp1,temp2,&\r\n \tu,v,w,ux,uy,uz,vx,vy,vz,wx,wy,wz,uold,uxold,uyold,uzold,&\r\n\t\tvold,vxold,vyold,vzold,wold,wxold,wyold,wzold,utemp,vtemp,wtemp,&\r\n\t\ttemp_r,kx,ky,kz,uhat,vhat,what,rhsuhatfix,rhsvhatfix,&\r\n \t\trhswhatfix,phat,nonlinuhat,nonlinvhat,nonlinwhat,temp_c,&\r\n\t\tstat=AllocateStatus)\t\t\r\n\tIF (AllocateStatus .ne. 0) STOP\r\n\tIF (myid.eq.0) THEN\r\n\t\tPRINT *,'Program execution complete'\r\n\tEND IF\r\n\tCALL MPI_FINALIZE(ierr)\t\t\r\nEND PROGRAM main\r\n\r\n SUBROUTINE getName(name_config,plotInt)\r\n implicit none\r\n CHARACTER*100,intent(inout) :: name_config\r\n INTEGER(kind=4) :: plotInt\r\n CHARACTER*100 :: number_file\r\n INTEGER(kind=4) :: ind\r\n\r\n ind = index(name_config,' ') - 1\r\n WRITE(number_file,'(i0)') 10000000+plotInt\r\n number_file = name_config(1:ind)//number_file\r\n ind = index(number_file,' ') - 1\r\n name_config = number_file(1:ind)//'.datbin'\r\n END SUBROUTINE getname\r\n\r\n", "meta": {"hexsha": "9cddf1a4bb3e9b81cc24dfb327190c30c20d59d3", "size": 37207, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "NavierStokes/Programs/NavierStokes3dFortranMPI/navierstokes_IMR.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/NavierStokes3dFortranMPI/navierstokes_IMR.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/NavierStokes3dFortranMPI/navierstokes_IMR.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.9943566591, "max_line_length": 109, "alphanum_fraction": 0.5805359207, "num_tokens": 14339, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111796979521253, "lm_q2_score": 0.7490872075132152, "lm_q1q2_score": 0.6825530554816924}} {"text": "!\n! fingas1996_module.f90\n! Contributors: Pi-Yueh Chuang \n!\n! Distributed under terms of the BSD 3-Clause license.\n!\n\n!> @brief Implementation of Fingas 1996 models for non-volatile fluids.\nmodule fingas1996_module\n use:: evap_base_module\n implicit none\n private\n public:: EvapFingas1996Log, EvapFingas1996SQRT\n\n !> @brief A model from Fingas 1996 based on natural log law.\n type, extends(EvapBase):: EvapFingas1996Log\n private\n !> @brief Final and combined coefficients used in Fingas 1996 model.\n real(kind=8):: final_coeffs\n !> @brief Time point at which evaporation percentage is 100%.\n real(kind=8):: t100\n\n contains\n !> @brief Initialization with an opened file unit.\n procedure:: init_with_funit => init_with_funit_fingas1996log\n !> @brief The kernel calculating remained percentage from t to t+dt.\n procedure:: remained_kernel => remained_kernel_fingas1996log\n !> @brief Destructor.\n final:: destructor_fingas1996log\n end type EvapFingas1996Log\n\n !> @brief A model from Fingas 1996 based on square-root law.\n type, extends(EvapFingas1996Log):: EvapFingas1996SQRT\n private\n contains\n !> @brief Initialization with an opened file unit.\n procedure:: init_with_funit => init_with_funit_fingas1996sqrt\n !> @brief The kernel calculating remained percentage from t to t+dt.\n procedure:: remained_kernel => remained_kernel_fingas1996sqrt\n !> @brief Destructor.\n final:: destructor_fingas1996sqrt\n end type EvapFingas1996SQRT\n\ncontains\n\n ! init the common part of Fingas models\n subroutine init_with_funit_common(this, funit, T)\n class(EvapFingas1996Log), intent(inout):: this\n integer(kind=4), intent(in):: funit\n real(kind=8), intent(in):: T\n integer(kind=4):: n_coeffs\n real(kind=8):: C1, C2\n\n this%ambient_temperature = T\n this%evap_volume_tracker = 0D0\n\n read(funit, *) n_coeffs\n\n if (n_coeffs /= 2) then\n print *, \"The number of coefficients in Fingas' model should be 2.\"\n stop\n end if\n\n read(funit, *) C1\n read(funit, *) C2\n\n this%final_coeffs = C1 + C2 * this%ambient_temperature\n end subroutine init_with_funit_common\n\n ! init_with_funit_fingas1996log\n subroutine init_with_funit_fingas1996log(this, funit, T)\n class(EvapFingas1996Log), intent(inout):: this\n integer(kind=4), intent(in):: funit\n real(kind=8), intent(in):: T\n\n this%model_name = \"Fingas1996 Log\"\n call init_with_funit_common(this, funit, T)\n\n this%t100 = 6D1 * dexp(1D2/this%final_coeffs)\n end subroutine init_with_funit_fingas1996log\n\n ! remained_kernel_fingas1996log\n function remained_kernel_fingas1996log(this, t, dt) result(remained_percent)\n class(EvapFingas1996Log), intent(in):: this\n real(kind=8), intent(in):: t\n real(kind=8), intent(in):: dt\n real(kind=8):: remained_percent\n\n ! before 1 minute, no evaporation\n if (t <= 6D1) then\n remained_percent = 1D0\n return\n end if\n\n if ((t + dt) >= this%t100) then\n remained_percent = 0D0\n return\n end if\n\n remained_percent = &\n (1D2 - this%final_coeffs * dlog((t+dt)/6D1)) / &\n (1D2 - this%final_coeffs * dlog(t/6D1))\n end function remained_kernel_fingas1996log\n\n ! destructor_fingas1996log\n subroutine destructor_fingas1996log(this)\n type(EvapFingas1996Log), intent(inout):: this\n this%model_name = \"none\"\n this%ambient_temperature = 0D0\n this%evap_volume_tracker = 0D0\n this%final_coeffs = 0D0\n end subroutine destructor_fingas1996log\n\n ! init_with_funit_fingas1996sqrt\n subroutine init_with_funit_fingas1996sqrt(this, funit, T)\n class(EvapFingas1996SQRT), intent(inout):: this\n integer(kind=4), intent(in):: funit\n real(kind=8), intent(in):: T\n\n this%model_name = \"Fingas1996 Square-Root\"\n call init_with_funit_common(this, funit, T)\n\n this%t100 = 6D1 * 1D4 / (this%final_coeffs**2)\n end subroutine init_with_funit_fingas1996sqrt\n\n ! remained_kernel_fingas1996sqrt\n function remained_kernel_fingas1996sqrt(this, t, dt) result(remained_percent)\n class(EvapFingas1996SQRT), intent(in):: this\n real(kind=8), intent(in):: t\n real(kind=8), intent(in):: dt\n real(kind=8):: remained_percent\n\n if ((t + dt) >= this%t100) then\n remained_percent = 0D0\n return\n end if\n\n remained_percent = &\n (1D2 - this%final_coeffs * dsqrt((t+dt)/6D1)) / &\n (1D2 - this%final_coeffs * dsqrt(t/6D1))\n end function remained_kernel_fingas1996sqrt\n\n ! destructor_fingas1996sqrt\n subroutine destructor_fingas1996sqrt(this)\n type(EvapFingas1996SQRT), intent(inout):: this\n this%model_name = \"none\"\n this%ambient_temperature = 0D0\n this%evap_volume_tracker = 0D0\n this%final_coeffs = 0D0\n end subroutine destructor_fingas1996sqrt\n\nend module fingas1996_module\n", "meta": {"hexsha": "4d4d55468069ecda55a4ed8e016de066ea0b6040", "size": 5205, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gclandspill/src/evaporation/fingas1996_module.f90", "max_stars_repo_name": "kbarnhart/geoclaw-landspill", "max_stars_repo_head_hexsha": "76deb0f585c99a2712bdffd7761fca23ac99c6a8", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-03-06T11:11:36.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-08T20:30:32.000Z", "max_issues_repo_path": "gclandspill/src/evaporation/fingas1996_module.f90", "max_issues_repo_name": "kbarnhart/geoclaw-landspill", "max_issues_repo_head_hexsha": "76deb0f585c99a2712bdffd7761fca23ac99c6a8", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 19, "max_issues_repo_issues_event_min_datetime": "2018-09-06T17:30:42.000Z", "max_issues_repo_issues_event_max_datetime": "2019-04-12T00:24:22.000Z", "max_forks_repo_path": "gclandspill/src/evaporation/fingas1996_module.f90", "max_forks_repo_name": "kbarnhart/geoclaw-landspill", "max_forks_repo_head_hexsha": "76deb0f585c99a2712bdffd7761fca23ac99c6a8", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-06-14T20:48:31.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-01T03:21:26.000Z", "avg_line_length": 34.0196078431, "max_line_length": 81, "alphanum_fraction": 0.6570605187, "num_tokens": 1501, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391602943619, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.6825372390117405}} {"text": "PROGRAM celsius2fahrenheit\n IMPLICIT NONE\n\n REAL(8) celsius, fahrenheit\n\n WRITE(*, *) \"Valor da temperatura em Celsius:\"\n READ(*, *) celsius\n\n IF (celsius >= -273.15d0) THEN ! zero absoluto\n fahrenheit = 1.8d0 * celsius + 32.0d0\n\n WRITE(*, *) \"Valor da temperatura em Fahrenheit\"\n WRITE(*, *) fahrenheit\n ELSE\n WRITE(*, *) \"Temperatura inv\u00e1lida\"\n END IF\nEND PROGRAM celsius2fahrenheit\n", "meta": {"hexsha": "930684f591cb27621a52cf262c538c068b5f6869", "size": 434, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "atividades/celsius2fahrenheit.f95", "max_stars_repo_name": "ViniciusGiroto/intro-fiscomp", "max_stars_repo_head_hexsha": "a0e58222b28545f6950865f32a20eb60e934273d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "atividades/celsius2fahrenheit.f95", "max_issues_repo_name": "ViniciusGiroto/intro-fiscomp", "max_issues_repo_head_hexsha": "a0e58222b28545f6950865f32a20eb60e934273d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "atividades/celsius2fahrenheit.f95", "max_forks_repo_name": "ViniciusGiroto/intro-fiscomp", "max_forks_repo_head_hexsha": "a0e58222b28545f6950865f32a20eb60e934273d", "max_forks_repo_licenses": ["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.1111111111, "max_line_length": 56, "alphanum_fraction": 0.6244239631, "num_tokens": 131, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916029436189, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.6825372368813085}} {"text": "\nPROGRAM MAIN\n\n IMPLICIT NONE\n\n ! Loop counter and maximum value\n INTEGER :: i, max_val\n ! Variables for current value\n ! If I use an INTEGER, I get exactly the right answer UNTIL I overflow\n ! I have to catch the overflow and do something\n INTEGER(KIND=SELECTED_INT_KIND(15)) :: factorial\n\n ! TRY the first 20 terms\n max_val = 30\n\n ! Optional last but to add- sanity check on max_val\n IF(max_val < 1 .OR. max_val > 30) THEN\n PRINT*, \"Sequence is too short or long. max_val should be between 1 and 30\"\n END IF\n\n\n factorial = 1\n\n ! Loop from first value to max_value, calculating and printing the term\n DO i = 1, max_val\n\n ! this iterattion will exceed HUGE()\n ! If I continue regardless I wil get a plausible but WRONG answer\n IF(factorial .GT. HUGE(factorial)/i) THEN\n PRINT*, \"Value Overflowing!\"\n STOP\n END IF\n factorial = factorial * i\n ! Print the calculated value\n PRINT*, \"n= \", i, \" n!=\", factorial\n\n END DO\n\nEND PROGRAM\n", "meta": {"hexsha": "c3a1e407e522016906cdceb9c2a66866ed46368b", "size": 979, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ModelSolutions/Factorial_int.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/Factorial_int.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/Factorial_int.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.475, "max_line_length": 79, "alphanum_fraction": 0.6802860061, "num_tokens": 276, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619885, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.6824901485752679}} {"text": "!\tconvert an n by n symmetric matrix from compact to regular form.\r\nfunction expandmat(n,compmat)\r\nimplicit none\r\ninteger,intent(in)::n\r\nreal(kind=8),intent(in)::compmat(:)\r\nreal(kind=8)::expandmat(n,n)\r\ninteger::row,position\r\nposition=1\r\ndo row=1,n\r\n\texpandmat(row,1:row)=compmat(position:position+row-1)\r\n\tif(row>1)then\r\n\t\texpandmat(row,1:row-1)=expandmat(row,1:row-1)/2.0_8\r\n\t\texpandmat(1:row-1,row)=expandmat(row,1:row-1)\r\n\tend if\r\n\tposition=position+row\r\nend do\r\nreturn\r\nend function expandmat", "meta": {"hexsha": "766c6fc988ed63df0398df9b35ce67c9c7091bb3", "size": 498, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Source/expandmat.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/expandmat.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/expandmat.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": 27.6666666667, "max_line_length": 67, "alphanum_fraction": 0.7289156627, "num_tokens": 165, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182186, "lm_q2_score": 0.7956581097540519, "lm_q1q2_score": 0.6824901432378068}} {"text": "! { dg-do run }\n! { dg-options \"-ffrontend-optimize\" }\nprogram main\n\n real, dimension(2,2) :: a,b,c\n\n data a /2., 4., 8., 16. /\n data b /3., 9., 27., 81./\n\n c = matmul(a,b)\n a = matmul(a,b)\n if (any(a /= c)) call abort\nend program main\n", "meta": {"hexsha": "bed1cb6a0afc946cb78e0ab3e7f86293fdaaf2e7", "size": 243, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.dg/inline_matmul_5.f90", "max_stars_repo_name": "best08618/asylo", "max_stars_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-05-02T17:34:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-17T10:15:18.000Z", "max_issues_repo_path": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.dg/inline_matmul_5.f90", "max_issues_repo_name": "best08618/asylo", "max_issues_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "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": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.dg/inline_matmul_5.f90", "max_forks_repo_name": "best08618/asylo", "max_forks_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-27T00:22:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-01T09:41:02.000Z", "avg_line_length": 17.3571428571, "max_line_length": 38, "alphanum_fraction": 0.5390946502, "num_tokens": 99, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8577680904463334, "lm_q2_score": 0.7956581000631542, "lm_q1q2_score": 0.6824901291393294}} {"text": "program test_spectral_interpolation_ipol_0\n \nuse kind_values, only: wp => kind_swd_internal\nuse spectral_interpolation_def, only: spectral_interpolation\n\nimplicit none\n\n! This program tests the ipol=0 temporal scheme\n\n! Dummy polynomials: f(t) = a0 + a1*t + a2*t**2 + a3*t**3 + a4*t**4 + a5*t**5\ncomplex(wp), parameter :: a0 = cmplx(0.156_wp, 0.17_wp, wp)\ncomplex(wp), parameter :: a1 = cmplx(1.234_wp, -0.54_wp, wp)\ncomplex(wp), parameter :: a2 = cmplx(-2.34_wp, 0.154_wp, wp)\ncomplex(wp), parameter :: a3 = cmplx(-0.18_wp, -0.25_wp, wp)\ncomplex(wp), parameter :: a4 = cmplx(0.58_wp, -0.74_wp, wp)\ncomplex(wp), parameter :: a5 = cmplx(0.23_wp, 0.09_wp, wp)\n\nreal(wp), parameter :: delta_t = 0.34_wp\nreal(wp), parameter :: t_im1 = 0.15_wp\nreal(wp), parameter :: t_i = t_im1 + delta_t\nreal(wp), parameter :: t_ip1 = t_i + delta_t\nreal(wp), parameter :: t_ip2 = t_ip1 + delta_t\n\ntype(spectral_interpolation) :: si\nreal(wp) :: t, delta\ncomplex(wp) :: c1, dc1, ddc1, c2, dc2, ddc2\ncomplex(wp) :: f_im1, f_i, f_ip1, f_ip2\ncomplex(wp) :: df_im1, df_i, df_ip1, df_ip2\ncomplex(wp) :: ddf_i, ddf_ip1\n\ninteger :: ipol, i, ierr, n_error = 0\nreal(wp), parameter :: deltas(5) = [0.0_wp, 0.29_wp, 0.64_wp, 0.84_wp, 1.0_wp]\n\nprint*, \" Test of ipol=0...\"\nipol = 0\ncall si % construct(ipol, delta_t, ierr)\nif (ierr /= 0) then\n print *, \"Unknown interpolation scheme: \", ipol\n stop\nend if\n\nf_im1 = f5(t_im1)\nf_i = f5(t_i)\nf_ip1 = f5(t_ip1)\nf_ip2 = f5(t_ip2)\ndf_im1 = df5(t_im1)\ndf_i = df5(t_i)\ndf_ip1 = df5(t_ip1)\ndf_ip2 = df5(t_ip2)\n! Adjust f_im1 make ddf_i based on finite-difference match polynomial at t_i\nddf_i = ddf5(t_i)\nf_im1 = 0.5_wp * ddf_i * delta_t**2 + 2 * f_i - f_ip1 + (df_ip1 - df_im1) * delta_t / 4\n! Adjust f_ip2 to make ddf_ip1 based on finite-difference match polynomial at t_ip1\nddf_ip1 = ddf5(t_ip1)\nf_ip2 = 0.5_wp * ddf_ip1 * delta_t**2 + 2 * f_ip1 - f_i + (df_ip2 - df_i) * delta_t / 4\n\ndo i = 1, size(deltas)\n delta = deltas(i)\n t = t_i + delta * delta_t\n c1 = f5(t)\n dc1 = df5(t)\n ddc1 = ddf5(t)\n call si % scheme(delta, &\n f_im1, f_i, f_ip1, f_ip2, &\n df_im1, df_i, df_ip1, df_ip2, &\n c2, dc2)\n print*, \"Delta = \", delta\n print*, \"Compare function values: \", c1, c2, compare(c1, c2)\n print*, \"Compare function derivatives: \", dc1, dc2, compare(dc1, dc2)\n if (i==1) then\n print*, \"f_i, df_i: \", f_i, df_i\n print*, \"compare(c2, f_i)\", compare(c2, f_i)\n print*, \"compare(dc2, df_i)\", compare(dc2, df_i)\n print*, \"compare(ddc1, ddf_i)\", compare(ddc1, ddf_i)\n else if (i==size(deltas)) then\n print*, \"f_ip1, df_ip1: \", f_ip1, df_ip1\n print*, \"compare(c2, f_ip1)\", compare(c2, f_ip1)\n print*, \"compare(dc2, df_ip1)\", compare(dc2, df_ip1)\n print*, \"compare(ddc1, ddf_ip1)\", compare(ddc1, ddf_ip1)\n end if\nend do\n\nprint*, \"Number of detected ERRORs = \", n_error\n \ncontains\n\nfunction f5(t) result(res)\nreal(wp), intent(in) :: t\ncomplex(wp) res\nres = a0 + a1*t + a2*t**2 + a3*t**3 + a4*t**4 + a5*t**5\nend function f5\n\nfunction df5(t) result(res)\nreal(wp), intent(in) :: t\ncomplex(wp) res\nres = a1 + 2.0_wp * a2*t + 3.0_wp * a3*t**2 + 4.0_wp * a4*t**3 + 5.0_wp * a5*t**4\nend function df5\n\nfunction ddf5(t) result(res)\nreal(wp), intent(in) :: t\ncomplex(wp) res\nres = 2.0_wp * a2 + 6.0_wp * a3*t + 12.0_wp * a4*t**2 + 20.0_wp * a5*t**3\nend function ddf5\n\nfunction compare(c1, c2) result(res)\ncomplex(wp), intent(in) :: c1, c2\ncharacter(len=10) res\nreal(wp), parameter :: eps = 100*epsilon(eps)\nif (abs(c1 % re - c2 % re) > eps * max(abs(c1 % re), abs(c2 % re)) .or. &\n abs(c1 % im - c2 % im) > eps * max(abs(c1 % im), abs(c2 % im))) then\n res = \"ERROR!\"\n n_error = n_error + 1\nelse\n res = \"OK\"\nend if\nend function compare\n\nend program test_spectral_interpolation_ipol_0\n", "meta": {"hexsha": "39f80bd7fbf770609a73f9d10760d5f222069117", "size": 3842, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/fortran/temporal_interpolation/test_spectral_interpolation_ipol_0.f90", "max_stars_repo_name": "TormodLandet/spectral_wave_data", "max_stars_repo_head_hexsha": "c43710e769c3d7d3c4f832ab74e456706b361493", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-03-01T19:49:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T10:21:56.000Z", "max_issues_repo_path": "tests/fortran/temporal_interpolation/test_spectral_interpolation_ipol_0.f90", "max_issues_repo_name": "TormodLandet/spectral_wave_data", "max_issues_repo_head_hexsha": "c43710e769c3d7d3c4f832ab74e456706b361493", "max_issues_repo_licenses": ["MIT"], "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/fortran/temporal_interpolation/test_spectral_interpolation_ipol_0.f90", "max_forks_repo_name": "TormodLandet/spectral_wave_data", "max_forks_repo_head_hexsha": "c43710e769c3d7d3c4f832ab74e456706b361493", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2020-09-01T12:23:30.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-24T17:50:40.000Z", "avg_line_length": 32.2857142857, "max_line_length": 87, "alphanum_fraction": 0.628058303, "num_tokens": 1464, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182187, "lm_q2_score": 0.7956580903722561, "lm_q1q2_score": 0.6824901266127207}} {"text": " SUBROUTINE ROOTS (A ,NA ,CROOTS,IRL )\n IMPLICIT COMPLEX*16 (C), REAL*8 (A-B,D-H,O-Z)\n DIMENSION A(NA) ,CROOTS(NA) ,Z(2) ,ZS(2)\n EQUIVALENCE (Z(1),CZ) ,(ZS(1),CZS)\nC\nC.......................................................................\nC\nC VERSION OF APRIL 5, 1976\nC\nC PURPOSE:\nC THIS SUBROUTINE COMPUTES ANY DESIRED COMPLEX ROOTS (ZEROES) OF A\nC GIVEN POLYNOMIAL, IF APPROXIMATIONS TO THE DESIRED ROOTS ARE KNOWN.\nC\nC METHOD:\nC NEWTON'S METHOD, AS DESCRIBED IN THE REFERENCE.\nC\nC REFERENCE:\nC HENRICI, P., 'ELEMENTS OF NUMERICAL ANALYSIS', NEW YORK, WILEY,\nC 1965, PAGE 84.\nC\nC CALLING SEQUENCE EXPLANATION :\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC A I IS AN INPUT DIMENSION NA ARRAY OF REAL\nC (NON-IMAGINARY) POLYNOMIAL COEFFICIENTS, STARTING\nC WITH THE LOWEST POWER.\nC NA I IS THE NUMBER OF IMPUT COEFFICIENTS (ONE MORE\nC THAN THE DEGREE OF THE POLYNOMIAL).\nC CROOTS I/O IS A COMPLEX*16 ARRAY OF DIMENSION NA\nC CONTAINING THE STARTING APPROXIMATIONS TO THE\nC DESIRED ROOTS ON INPUT AND THE SOLUTIONS ON\nC OUTPUT.\nC IRL I IS THE NUMBER OF ROOTS (ZEROES) DESIRED TO BE\nC SOLVED FOR\nC\nC COMMON BLOCK PARAMETERS;\nC NONE\nC\nC SUBROUTINES AND FUNCTIONS REQUIRED:\nC NONE\nC\nC CALLED BY:\nC LOWALT\nC\nC.......................................................................\nC\nC\nC IR COUNTS ROOTS SOLVED SO FAR\nC\n IR = 0\n N1 = NA - 1\nC\n 100 IR = IR + 1\n IF (IR .GT. IRL) RETURN\nC\nC IT COUNTS ITERATIONS ON THIS ROOT SO FAR\nC\n IT = 0\nC\nC CZ IS THE CURRENTLY ITERATED VALUE OF THE ROOT.\nC\n CZ = CROOTS(IR)\nC\n 150 CB = A(NA)\n CC = A(NA)\nC\n DO 200 I=1,N1\n J = NA - I\nC\nC CB & CC ARE THE VALUES OF THE POLYNOMIAL(P(Z)) AND ITS DERIVATIVE\nC (P'(Z)).\nC\n CB = CZ*CB + A(J)\n IF (J .EQ. 1) GO TO 200\nC\n CC = CZ*CC + CB\n 200 CONTINUE\nC\n IT = IT + 1\nC\nC THE RESULT OF THE LAST ITERATION IS SAVED IN CZS.\nC\n CZS = CZ\nC\nC NEWTONS METHOD SAYS THAT\nC Z(I) = Z(I-1) - P(Z(I-1))/P'(Z(I-1))\nC TENDS TOWARD A ROOT OF THE POLYNOMIAL P(Z).\nC\n CZ = CZ - CB/CC\nC\nC THE CONVERGENCE CRITERION (DIF) IS THE SUM OF THE RELATIVE CHANGES\nC IN THE REAL AND IMMAGINARY PARTS OF THE ROOT (CZ).\nC\n DIF =DABS((ZS(1) - Z(1))/ZS(1))\n IF (ZS(2) .NE. 0.D0) DIF = DIF + DABS((ZS(2) - Z(2))/ZS(2))\nC\nC IF THE CONVERGENCE CRITERION IS TOO LARGE, ITERATE AGAIN.\nC\n IF (DIF .GT.1.D-14) GO TO 150\nC\nC OTHERWISE, THE CONVERGENCE IS COMPLETE. STORE THE ANSWER FOR OUTPUT\nC AND START ON THE NEXT ROOT.\nC\n CROOTS(IR) = CZ\n GO TO 100\nC\n END\n", "meta": {"hexsha": "b5a8358532e9060feeaf411c85a43c94df403cee", "size": 2962, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "gsc-13006/fsd/source/roots.for", "max_stars_repo_name": "SteveDoyle2/nasa-cosmic", "max_stars_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_stars_repo_licenses": ["BSD-Source-Code"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2015-03-14T07:26:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-16T12:23:17.000Z", "max_issues_repo_path": "gsc-13006/fsd/source/roots.for", "max_issues_repo_name": "SteveDoyle2/nasa-cosmic", "max_issues_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_issues_repo_licenses": ["BSD-Source-Code"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gsc-13006/fsd/source/roots.for", "max_forks_repo_name": "SteveDoyle2/nasa-cosmic", "max_forks_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_forks_repo_licenses": ["BSD-Source-Code"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2016-02-12T22:18:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-08T17:46:54.000Z", "avg_line_length": 27.1743119266, "max_line_length": 72, "alphanum_fraction": 0.5249831195, "num_tokens": 1005, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297941266014, "lm_q2_score": 0.7577943658046608, "lm_q1q2_score": 0.6824164042283696}} {"text": "program test\r\n use quadratures, only: clencurt, polytest\r\n implicit none\r\n integer, parameter :: dp = kind(1.d0)\r\n integer, parameter :: sp = kind(1.0)\r\n real(dp), parameter :: PI = 3.141592653589793_dp\r\n integer(8) :: N\r\n real(dp), dimension(:), allocatable :: mu, wt\r\n character(len=12) :: arg\r\n\r\n if (command_argument_count() .ne. 1) then\r\n write (*, '(A)') &\r\n '> Runtime error: must supply the number of gridpoints as input.'\r\n write (*, '(A)') 'Example: ./test 16'\r\n stop\r\n else\r\n call get_command_argument(1, arg)\r\n read(arg, *) N\r\n endif\r\n allocate(mu(N), wt(N))\r\n\r\n\r\n call clencurt(N, mu, wt)\r\n call polytest(N, 0, -1.0_dp, 1.0_dp, mu, wt)\r\n call polytest(N, 1, -1.0_dp, 1.0_dp, mu, wt)\r\n call polytest(N, 2, -1.0_dp, 1.0_dp, mu, wt)\r\n call polytest(N, 3, -1.0_dp, 1.0_dp, mu, wt)\r\n call polytest(N, 4, -1.0_dp, 1.0_dp, mu, wt)\r\n call polytest(N, 16, -1.0_dp, 1.0_dp, mu, wt)\r\n call polytest(N, 32, -1.0_dp, 1.0_dp, mu, wt)\r\n call polytest(N, 50, -1.0_dp, 1.0_dp, mu, wt)\r\n call polytest(N, 0, -1.0_dp, 1.0_dp, mu, wt)\r\n\r\n deallocate(mu, wt)\r\n\r\nend program test\r\n", "meta": {"hexsha": "0d661cdb0a3dda9335fce397db158a7909e0b604", "size": 1124, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "test.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": "test.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": "test.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": 30.3783783784, "max_line_length": 76, "alphanum_fraction": 0.5934163701, "num_tokens": 435, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297807787536, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6824163990393255}} {"text": "program main\n use LinearSolverClass\n implicit none\n\n real(8),allocatable :: a(:,:),b(:),x(:)\n integer :: i,n,itrmax\n real(8) :: er\n\n open(10,file=\"gpbicg.txt\")\n read(10,*) n\n\n allocate(a(n,n),b(n),x(n) )\n do i=1,n\n read(10,* ) a(i,:)\n enddo\n do i=1,n\n read(10,* ) b(i)\n enddo\n close(10)\n \n x(:)=1.0d0\n call GPBiCG(a,b,x,n)\n\n do i=1,n\n print *, i,\"|value \",x(i),\"|residual \",b(i)-dot_product(a(i,:),x(:) )\n enddo\n \n call gauss_jordan_pv(a,x,b,n)\n \n do i=1,n\n print *, i,\"|value \",x(i),\"|residual \",b(i)-dot_product(a(i,:),x(:) )\n enddo\n\n\n itrmax=1000\n er=1.0e-20\n x(:)=0.0d0\n call bicgstab1d(a,b,x,n,itrmax, er)\n \n \n do i=1,n\n print *, i,\"|value \",x(i),\"|residual \",b(i)-dot_product(a(i,:),x(:) )\n enddo\n\nend program main", "meta": {"hexsha": "5729afc372f9cefa96b2d578c29a83b3195d5111", "size": 851, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/app/Preprocess_samples/gpbicg.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/Preprocess_samples/gpbicg.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/Preprocess_samples/gpbicg.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": 18.9111111111, "max_line_length": 78, "alphanum_fraction": 0.4853113984, "num_tokens": 324, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297754396142, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6824163949933557}} {"text": "subroutine tara1dHydSer(arg)\r\n\r\nuse cfgio_mod, only: cfg_t, parse_cfg\r\n\r\nimplicit none\r\n\r\ntype(cfg_t):: cfg\r\n\r\nreal (kind=8), parameter :: pi = 3.14159265358979323846d0\r\n\r\ninclude \"fftw3.f\"\r\n\r\ninteger (kind=4) N,Nh\r\n\r\nreal (kind = 8), dimension (:), allocatable :: x, ux, dux, ddux\r\n\r\ncomplex (kind=8), dimension(:), allocatable :: uk,duk,dduk\r\n\r\ninteger*8 :: plan\r\nreal*8 :: L\r\n\r\ninteger :: i,t\r\nreal*8 dx,k,time,time_min,time_max,dt,nu\r\nreal (kind = 8), dimension (:), allocatable :: force_u_n, force_u_o\r\n\r\ncharacter (len=90) :: filename\r\ncharacter (len=32) :: arg\r\n\r\ncfg = parse_cfg(arg)\r\n\r\ncall cfg%get(\"grid\",\"Nx\",N)\r\n\r\nNh = (N/2) + 1\r\n\r\nallocate(x(N))\r\nallocate(ux(N))\r\nallocate(dux(N))\r\nallocate(ddux(N))\r\n\r\nallocate(force_u_n(N))\r\nallocate(force_u_o(N))\r\n\r\nallocate(uk(Nh))\r\nallocate(duk(Nh))\r\nallocate(dduk(Nh))\r\n\r\ncall cfg%get(\"length\",\"Lx\",L)\r\n\r\ncall cfg%get(\"resistivity\",\"nu\",nu)\r\n\r\ncall cfg%get(\"time\",\"time_min\",time_min)\r\ncall cfg%get(\"time\",\"time_max\",time_max)\r\ncall cfg%get(\"time\",\"dt\",dt)\r\n\r\nL = L*pi\r\ndx = L/dfloat(N)\r\n\r\ndo i = 1,N\r\n x(i) = dfloat(i-1)*dx\r\n ux(i) = dsin(x(i))\r\nenddo\r\n\r\ndo time = time_min, time_max, dt\r\n\r\nt = nint(time/dt) - int(time_min/dt)\r\n\r\ncall dfftw_plan_dft_r2c_1d(plan, N, ux, uk, FFTW_ESTIMATE)\r\ncall dfftw_execute_dft_r2c(plan, ux, uk)\r\ncall dfftw_destroy_plan(plan)\r\n\r\ndo i = 1,Nh\r\n k = 2.0d0*pi*dfloat(i-1)/L\r\n duk(i) = (0.0d0,1.0d0) * k * uk(i)\r\n dduk(i) = - k * k * uk(i)\r\nenddo\r\n\r\ncall dfftw_plan_dft_c2r_1d(plan, N, duk, dux, FFTW_ESTIMATE)\r\ncall dfftw_execute_dft_c2r(plan, duk, dux)\r\ncall dfftw_destroy_plan(plan)\r\n\r\ncall dfftw_plan_dft_c2r_1d(plan, N, dduk, ddux, FFTW_ESTIMATE)\r\ncall dfftw_execute_dft_c2r(plan, dduk, ddux)\r\ncall dfftw_destroy_plan(plan)\r\n\r\ndo i = 1,N\r\ndux(i) = dux(i)/dfloat(N)\r\nddux(i) = ddux(i)/dfloat(N)\r\n if (t .ge. 1000 .and. mod(t,500) == 0) then\r\n write(filename, '(\"output/fort.\",I8.8)') t\r\n open(unit=t,file=filename,status='unknown')\r\n write(t,*) t, x(i), ux(i)\r\n endif\r\nenddo\r\n\r\ndo i = 1,N\r\n force_u_n(i) = -ux(i)*dux(i) + nu*ddux(i)\r\n if (t==0) then\r\n ux(i) = ux(i) + dt * force_u_n(i)\r\n else\r\n ux(i) = ux(i) + dt* ( (3.0/2.0) * force_u_n(i) - (1.0/2.0) * force_u_o(i))\r\n endif\r\n force_u_o(i) = force_u_n(i)\r\nenddo\r\n\r\nenddo\r\n\r\nend subroutine tara1dHydSer\r\n", "meta": {"hexsha": "7b7a331a6501060b4b90f3192e02211cfc3421c0", "size": 2279, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/main1csh.f95", "max_stars_repo_name": "RupakMukherjee/Navier-Stokes", "max_stars_repo_head_hexsha": "dfcda1a7d5580759091847477cf2f69d473a88f2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-23T11:35:08.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-23T11:35:08.000Z", "max_issues_repo_path": "src/main1csh.f95", "max_issues_repo_name": "RupakMukherjee/TARA", "max_issues_repo_head_hexsha": "dfcda1a7d5580759091847477cf2f69d473a88f2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-03-25T22:19:12.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-30T23:16:56.000Z", "max_forks_repo_path": "src/main1csh.f95", "max_forks_repo_name": "RupakMukherjee/TARA", "max_forks_repo_head_hexsha": "dfcda1a7d5580759091847477cf2f69d473a88f2", "max_forks_repo_licenses": ["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.1018518519, "max_line_length": 79, "alphanum_fraction": 0.6274681878, "num_tokens": 855, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308036221031, "lm_q2_score": 0.731058584489497, "lm_q1q2_score": 0.6823926020148683}} {"text": "module maths\nuse vars\n! use Fast_Fourier\nuse singleton\n!use nrutil, ONLY : assert_eq, imaxloc, outerprod, swap\nimplicit none\ncontains\n\n!----------------------------------------------------------------\n! This function calculates the 3-j symbol\n! J_i and M_i have to be twice the actual value of J and M\n!----------------------------------------------------------------\n function w3js(j1,j2,j3,m1,m2,m3)\n integer :: m1, m2, m3, j1, j2, j3\n integer :: ia, ib, ic, id, ie, im, ig, ih, z, zmin, zmax, jsum\n real(kind=8) :: w3js, cc, denom, cc1, cc2\n\n! w3js = w3js_regge(j1/2,j2/2,j3/2,m1/2,m2/2,m3/2)\n! return\n w3js = 0.d0\n if (m1+m2+m3 /= 0) return\n ia = j1 + j2\n if (j3 > ia) return\n ib = j1 - j2\n if (j3 < abs(ib)) return\n if (abs(m1) > j1) return\n if (abs(m2) > j2) return\n if (abs(m3) > j3) return\n \n jsum = j3 + ia\n ic = j1 - m1\n id = j2 - m2\n \n ie = j3 - j2 + m1\n im = j3 - j1 - m2\n zmin = max0(0,-ie,-im)\n ig = ia - j3\n ih = j2 + m2\n zmax = min0(ig,ih,ic)\n cc = 0.d0\n\n do z = zmin, zmax, 2\n denom = fact(z/2)*fact((ig-z)/2)*fact((ic-z)/2)*fact((ih-z)/2)*&\n fact((ie+z)/2)*fact((im+z)/2)\n if (mod(z,4) /= 0) denom = -denom\n cc = cc + 1.d0/denom\n enddo\n\n cc1 = fact(ig/2)*fact((j3+ib)/2)*fact((j3-ib)/2)/fact((jsum+2)/2)\n cc2 = fact((j1+m1)/2)*fact(ic/2)*fact(ih/2)*fact(id/2)*fact((j3-m3)/2)*fact((j3+m3)/2)\n cc = cc * sqrt(1.d0*cc1*cc2)\n if (mod(ib-m3,4) /= 0) cc = -cc\n w3js = cc\n if (abs(w3js) < 1.d-8) w3js = 0.d0 \n1000 return\n end function w3js\n \n \n!----------------------------------------------------------------\n! This function calculates the 6-j symbol\n! J_i and M_i have to be twice the actual value of J and M\n!----------------------------------------------------------------\n function w6js(j1,j2,j3,l1,l2,l3)\n integer :: j1,j2,j3,l1,l2,l3\n integer :: ia, ib, ic, id, ie, iif, ig, ih, sum1, sum2, sum3, sum4\n integer :: w, wmin, wmax, ii, ij, ik\n real(kind=8) :: w6js, omega, theta1, theta2, theta3, theta4, theta, denom\n\n w6js = 0.d0\n ia = j1 + j2\n if (ia < j3) return\n ib = j1 - j2\n if (abs(ib) > j3) return\n ic = j1 + l2\n if (ic < l3) return\n id = j1 - l2\n if (abs(id) > l3) return\n ie = l1 + j2\n if (ie < l3) return\n iif = l1 - j2\n if (abs(iif) > l3) return\n ig = l1 + l2\n if (ig < j3) return\n ih = l1 - l2\n if (abs(ih) > j3) return\n sum1=ia + j3\n sum2=ic + l3\n sum3=ie + l3\n sum4=ig + j3\n wmin = max0(sum1, sum2, sum3, sum4)\n ii = ia + ig\n ij = j2 + j3 + l2 + l3\n ik = j3 + j1 + l3 + l1\n wmax = min0(ii,ij,ik)\n omega = 0.d0\n do w = wmin, wmax, 2\n denom = fact((w-sum1)/2)*fact((w-sum2)/2)*fact((w-sum3)/2)&\n *fact((w-sum4)/2)*fact((ii-w)/2)*fact((ij-w)/2)&\n *fact((ik-w)/2)\n if (mod(w,4) /= 0) denom = -denom\n omega = omega + fact(w/2+1) / denom\n enddo \n theta1 = fact((ia-j3)/2)*fact((j3+ib)/2)*fact((j3-ib)/2)/fact(sum1/2+1)\n theta2 = fact((ic-l3)/2)*fact((l3+id)/2)*fact((l3-id)/2)/fact(sum2/2+1)\n theta3 = fact((ie-l3)/2)*fact((l3+iif)/2)*fact((l3-iiF)/2)/fact(sum3/2+1)\n theta4 = fact((ig-j3)/2)*fact((j3+ih)/2)*fact((j3-ih)/2)/fact(sum4/2+1)\n theta = theta1 * theta2 * theta3 * theta4\n w6js = omega * sqrt(theta)\n if (abs(w6js) < 1.d-8) w6js = 0.d0\n1000 return\n end function w6js\n\n!----------------------------------------------------------------\n! This function calculates the 9-j symbol\n! J_i and M_i have to be twice the actual value of J and M\n!----------------------------------------------------------------\n function w9js(j1,j2,j3,j4,j5,j6,j7,j8,j9)\n integer :: j1,j2,j3,j4,j5,j6,j7,j8,j9\n integer :: i, kmin, kmax, k\n real(kind=8) :: x, s, x1, x2, x3, w9js\n\n kmin = abs(j1-j9)\n kmax = j1 + j9\n i = abs(j4-j8)\n if (i > kmin) kmin = i\n i = j4 + j8\n if (i < kmax) kmax = i\n i = abs(j2-j6)\n if (i > kmin) kmin = i\n i = j2 + j6\n if (i < kmax) kmax = i\n x = 0.d0\n do k = kmin, kmax, 2\n s = 1.d0\n if (mod(k,2) /= 0) s = -1.d0\n x1 = w6js(j1,j9,k,j8,j4,j7)\n x2 = w6js(j2,j6,k,j4,j8,j5)\n x3 = w6js(j1,j9,k,j6,j2,j3)\n x = x + s*x1*x2*x3*dfloat(k+1)\n enddo\n w9js = x\n return\n end function w9js\n\n!----------------------------------------------------------------\n! Reorder the Regge square to make it similar to eq. (2.11) in Rasch & Yu (SIAM J. Sci. Comput. Vol 25, n 4, 1416)\n!----------------------------------------------------------------\n function reorder_regge(regge, factor)\n integer :: reorder_regge(3,3), regge(3,3), temp(3,3), loc_max(2), col_max, row_max, loc_min(2), col_min, row_min, t\n integer :: i, j, tot, minus1, factor\n\n tot = sum(regge(1,:))\n minus1 = (-1)**tot\n factor = 1\n \n temp = regge\n \n loc_max = maxloc(temp)\n row_max = loc_max(2)\n col_max = loc_max(1)\n \n loc_min = minloc(temp)\n row_min = loc_min(2)\n col_min = loc_min(1)\n \n! Put the maximum and minimum in the same row\n if (col_min == col_max) then\n temp = transpose(regge)\n \n row_max = loc_max(1)\n col_max = loc_max(2)\n\n row_min = loc_min(1)\n col_min = loc_min(2)\n\n endif\n \n reorder_regge = temp\n if (row_min /= 1) then\n reorder_regge(:,1) = temp(:,row_min)\n reorder_regge(:,row_min) = temp(:,1)\n factor = factor * minus1\n endif\n temp = reorder_regge\n \n loc_min = minloc(temp)\n row_min = loc_min(2)\n col_min = loc_min(1)\n \n! Put smallest one into R_11\n reorder_regge = temp\n if (col_min /= 1) then\n reorder_regge(1,:) = temp(col_min,:)\n reorder_regge(col_min,:) = temp(1,:)\n factor = factor * minus1 \n temp = reorder_regge\n endif\n \n! Put largest one into R_21\n loc_max = maxloc(temp)\n row_max = loc_max(2)\n col_max = loc_max(1)\n \n if (col_max /= 2) then\n reorder_regge = temp\n reorder_regge(2,:) = temp(col_max,:)\n reorder_regge(col_max,:) = temp(2,:)\n factor = factor * minus1\n endif\n \n \n end function reorder_regge\n\n!----------------------------------------------------------------\n! Calculate the 3j symbol by indexing a 1D array with all the 3j symbols Rasch & Yu (SIAM J. Sci. Comput. Vol 25, n 4, 1416)\n!---------------------------------------------------------------- \n function w3js_regge(j1,j2,j3,m1,m2,m3)\n integer :: j1, j2, j3, m1, m2, m3, regge(3,3), regge_order(3,3), L, X, T, B, S, c1, c2, c3, c4, c5, c, factor\n real(kind=8) :: w3js_regge\n \n w3js_regge = 0.d0\n if (abs(m1) > j1 .or. abs(m2) > j2 .or. abs(m3) > j3 .or. (m1+m2+m3) /= 0) return\n \n regge(1,1) = -j1+j2+j3\n regge(2,1) = j1-j2+j3\n regge(3,1) = j1+j2-j3\n \n regge(1,2) = j1-m1\n regge(2,2) = j2-m2\n regge(3,2) = j3-m3\n \n regge(1,3) = j1+m1\n regge(2,3) = j2+m2\n regge(3,3) = j3+m3\n \n regge_order = reorder_regge(regge,factor)\n \n L = regge_order(2,1)\n X = regge_order(1,2)\n T = regge_order(3,3)\n B = regge_order(2,2)\n S = regge_order(1,1)\n \n c1 = L*(24+L*(50+L*(35+L*(10+L))))/120\n c2 = X*(6+X*(11+X*(6+X)))/24\n c3 = T*(2+T*(3+T))/6\n c4 = B*(B+1)/2\n c5 = S\n c = c1+c2+c3+c4+c5+1\n\n w3js_regge = factor*threej(c)\n end function w3js_regge \n \n!----------------------------------------------------------------\n! Calculate the list of 3j symbols and store them in a 1D array\n!---------------------------------------------------------------- \n subroutine init_regge(Lmax)\n integer :: S, B, T, X, L, Lmax, cmax, c1, c2, c3, c4, c5, c, k, j1, j2, j3, m1, m2, m3\n \n cmax = Lmax*(274+Lmax*(225+Lmax*(85+Lmax*(15+Lmax))))/120+1\n\n allocate(threej(0:cmax))\n\n k = 0\n do L = 0, Lmax\n do X = 0, L\n do T = 0, X\n do B = 0, T\n do S = 0, B\n j1 = (B+L-T+X)\n j2 = (B+S-T+X)\n j3 = (L+S)\n m1 = (B+L-T-X)\n m2 = (-B+S-T+X)\n m3 = (T+T-L-S)\n\n c1 = L*(24+L*(50+L*(35+L*(10+L))))/120\n c2 = X*(6+X*(11+X*(6+X)))/24\n c3 = T*(2+T*(3+T))/6\n c4 = B*(B+1)/2\n c5 = S\n c = c1+c2+c3+c4+c5+1\n\n threej(c) = w3js(j1,j2,j3,m1,m2,m3)\n\n k = k + 1\n enddo\n enddo\n enddo\n enddo\n enddo\n\n open(unit=12,file='regge_3j.dat',action='write',form='unformatted')\n write(12) threej\n close(12)\n \n end subroutine init_regge\n\n!----------------------------------------------------------------\n! This function calculates the rotation matrix of order k\n! The results are returned in dr(iq,iqp) and di(iq,iqp) representing\n! the real and imaginary part of the rotation matrix respectevely.\n! The angles alpha, beta and gamma are given in radians\n!----------------------------------------------------------------\n subroutine rotmatk(k,alpha,beta,gamma,dr,di)\n integer :: k\n real(kind=8) :: alpha, beta, gamma\n real(kind=8) :: dr(-1:1,-1:1), di(-1:1,-1:1)\n integer :: iq, iqp, it, it1, it2, it3, itmax, itmin, ie1, ie2\n real(kind=8) :: a1, a2, ca, sa, cg, sg, bo2, cb2, sb2, redm, s, den\n\n dr = 0.d0\n di = 0.d0\n do iq = -k, k\n do iqp = -k, k\n a1 = alpha * dfloat(iq)\n a2 = gamma * dfloat(iqp)\n ca = dcos(a1)\n sa = dsin(a1)\n cg = dcos(a2)\n sg = dsin(a2)\n bo2 = beta / 2.d0\n cb2 = dcos(bo2)\n sb2 = dsin(bo2)\n it1 = k + iq\n it2 = k - iqp\n itmax = it1\n if (it2 < itmax) itmax = it2\n itmin = 0\n it3 = iq - iqp\n if (it3 > 0) itmin = it3\n redm = 0.d0\n if (beta /= 0.d0) then\n do it = itmin, itmax\n s = 1.d0\n if (mod(it,2) /= 0) s = -1.d0\n ie1 = 2*(k-it)+iq-iqp\n ie2 = 2*it+iqp-iq\n den = fact(it1-it) * fact(it2-it) * fact(it) * fact(it-it3)\n redm = redm + s*(cb2**ie1)*(sb2**ie2) / den\n enddo\n redm = redm*sqrt(fact(k+iq)*fact(k-iq)*fact(k+iqp)*fact(k-iqp))\n else\n if (iq == iqp) redm = 1.d0\n endif\n dr(iq,iqp) = redm*(ca*cg-sa*sg)\n di(iq,iqp) = -redm*(ca*sg+sa*cg)\n enddo \n enddo\n\n end subroutine rotmatk\n\n\n!----------------------------------------------------------------\n! This function calculates the reduced rotation matrix of order 0,1,2,...kmax\n! The results are returned in complex format dr(K,iq,iqp) \n! The angle beta is given in radians\n! The maximum value of kmax is 6\n!---------------------------------------------------------------- \n subroutine reduced_matrix(kmax,beta,reduced)\n integer :: kmax, K, M, N, t, min_t, max_t\n real(kind=8) :: beta, cos_beta, sin_beta, suma, f1, f2\n real(kind=8) :: reduced(0:kmax,-kmax:kmax,-kmax:kmax)\n\n cos_beta = cos(beta/2.d0)\n sin_beta = sin(beta/2.d0)\n\n do K = 0, kmax\n do M = -K, K\n do N = -K, K\n max_t = min(K+M,K-N)\n min_t = max(0,M-N)\n suma = 0.d0\n f1 = sqrt(fact(K+M)*fact(K-M)*fact(K+N)*fact(K-N))\n do t = min_t, max_t \n f2 = fact(K+M-t)*fact(K-N-t)*fact(t)*fact(t+N-M)\n suma = suma + (-1.d0)**t*cos_beta**(2*K+M-N-2*t)*sin_beta**(2*t-M+N) / f2\n enddo \n reduced(k,M,N) = f1 * suma\n enddo\n enddo \n enddo\n\n\n end subroutine reduced_matrix\n\n!----------------------------------------------------------------\n! This function calculates the rotation matrix of order 0,1,2,...kmax\n! The results are returned in complex format dr(K,iq,iqp) \n! The angles alpha, beta and gamma are given in radians\n! The maximum value of kmax is 6\n!---------------------------------------------------------------- \n subroutine rotmatsu(kmax,alpha,beta,gamma,dr)\n integer :: kmax, K, M, N\n real(kind=8) :: alpha, beta, gamma, ca, sa, cg, sg\n complex(kind=8) :: dr(0:kmax,-kmax:kmax,-kmax:kmax), ii\n real(kind=8) :: reduced(0:kmax,-kmax:kmax,-kmax:kmax)\n\n ii = cmplx(0.d0,1.d0)\n call reduced_matrix(kmax,beta,reduced)\n \n do K = 0, kmax\n do M = -K, K\n do N = -K, K\n dr(K,M,N) = reduced(K,M,N) * exp(-ii*(alpha*M+gamma*N))\n enddo\n enddo\n enddo\n\n end subroutine \n\n!----------------------------------------------------------------\n! This function returns the Kronecker delta\n!---------------------------------------------------------------- \n function delta(A,B)\n integer :: A, B, delta\n delta = 0.d0\n if (A == B) delta = 1.d0\n end function delta \n\n!----------------------------------------------------------------\n! This function calculates the t^K_P(i) symbol\n!---------------------------------------------------------------- \n function tkp(K,P)\n integer :: K, P\n complex(kind=8) :: tkp(0:3), ii\n\n tkp = 0.d0\n ii = cmplx(0.d0,1.d0)\n if (K == 0) then\n tkp(0) = delta(P,0)\n return\n endif\n\n if (K == 1) then\n tkp(3) = sqrt(3.d0/2.d0) * delta(P,0)\n return\n endif\n\n if (K == 2) then\n tkp(0) = sqrt(1.d0/2.d0) * delta(P,0)\n tkp(1) = -sqrt(3.d0)/2.d0 * (delta(P,-2) + delta(P,2))\n tkp(2) = ii * sqrt(3.d0)/2.d0 * (delta(P,-2) - delta(P,2))\n return\n endif \n end function tkp\n\n!----------------------------------------------------------------\n! This function calculates the tensor T^K_P(i,Omega) taking into account a double rotation\n!---------------------------------------------------------------- \n subroutine tkq2(alpha,beta,gamma,alphap,betap,gammap,tr)\n real(kind=8) :: alpha, beta, gamma, alphap, betap, gammap\n complex(kind=8) :: tr(0:2,-2:2,0:3), tkpi(0:3), dr1(0:2,-2:2,-2:2), dr2(0:2,-2:2,-2:2), suma\n integer :: i, K, Q, P, Qp\n\n call rotmatsu(2,alpha,beta,gamma,dr1)\n call rotmatsu(2,alphap,betap,gammap,dr2)\n \n tr = 0.d0\n\n do i = 0, 3\n do K = 0, 2\n do Q = -K, K\n suma = 0.d0\n do P = -K, K\n tkpi = tkp(K,P)\n do Qp = -K, K\n suma = suma + tkpi(i) * dr1(K,P,Qp) * dr2(K,Qp,Q)\n enddo\n enddo\n tr(K,Q,i) = suma\n enddo\n enddo\n enddo \n\n end subroutine tkq2\n\n!----------------------------------------------------------------\n! Calculates part of eq. 7.41 from Landi Degl'Innocenti & Landolfi (2004)\n!---------------------------------------------------------------- \n subroutine bigpar(l2,is2,k2,kp2,j2,jp2,js2,jt2,x)\n integer :: l2, is2, k2, kp2, j2, jp2, js2, jt2\n real(kind=8) :: x, x1, x2, x3, g\n\n x = 0.d0\n if (jp2 /= jt2 .and. j2 /= js2) return\n if (jp2 == jt2) then\n if (iabs(j2-js2) > 2 .or. j2+js2 == 0) then\n else\n call gamma(l2,is2,j2,js2,g)\n x1 = g\n x2 = w6js(k2,kp2,2,js2,j2,jp2)\n x = x1*x2\n endif\n endif\n\n if (j2 /= js2) return\n if (iabs(jt2-jp2) > 2 .or. jt2+jp2 == 0) return\n call gamma(l2,is2,jt2,jp2,g)\n x1 = g\n x2 = 1.d0\n if (mod(k2-kp2,4) /= 0) x2 = -1.d0\n x3 = w6js(k2,kp2,2,jt2,jp2,j2)\n x = x + x1*x2*x3\n end subroutine bigpar\n \n!----------------------------------------------------------------\n! Calculates eq. 7.42 from Landi Degl'Innocenti & Landolfi (2004)\n!---------------------------------------------------------------- \n subroutine gamma(l2,is2,j2,jp2,g)\n integer :: l2, is2, j2, jp2\n real(kind=8) :: g\n real(kind=8) :: x1, x2, x3\n\n g = 0.d0\n if (j2 == jp2) then\n g = g + dsqrt(dfloat(j2*(j2+2)*(j2+1))/4.d0)\n endif\n x1 = 1.d0\n if (mod(2+l2+is2+j2,4) /= 0) x1 = -1.d0\n x2 = dsqrt(dfloat((j2+1)*(jp2+1)*is2*(is2+2)*(is2+1))/4.d0)\n x3 = w6js(j2,jp2,2,is2,is2,l2)\n g = g + x1*x2*x3\n end subroutine gamma\n\n!----------------------------------------------------------------\n! Calculates the factorial of the integers up to 301 and save it into the fact array\n!----------------------------------------------------------------\n subroutine factrl\n integer :: i\n fact(0) = 1.d0\n do i=1,101\n fact(I) = fact(I-1) * dble(I)\n enddo\n END subroutine factrl\n \n! ---------------------------------------------------------\n! LU decomposition of a matrix\n! INPUT:\n! - a is the matrix to decompose\n! \n! OUTPUT:\n! - a is the LU decomposition of a\n! - indx is a vector that records the row permutation effected by the partial pivoting\n! - d takes values +1/-1 depending on whether the number of row interchanges was odd or even\n! ---------------------------------------------------------\n subroutine ludcmp(a,indx,d,error)\n integer, INTENT(INOUT) :: indx(:)\n real*8, INTENT(INOUT) :: a(:,:), d\n real*8, parameter :: TINY = 1.d-20\n integer :: i, imax, j, k, n\n real*8 :: aamax, dum, sum, vv(size(a,1))\n integer :: values_start(8), values_end(8), error\n real(kind=8) :: start_time, end_time\n \n! call date_and_time(values=values_start)\n \n d = 1.d0\n n = size(a,1)\n error = 0\n \n do i = 1, n\n aamax = 0.d0 \n aamax = maxval(dabs(a(i,:)))\n if (aamax == 0.d0) then\n print *, 'Singular matrix in LU decomposition'\n error = 1\n return\n endif\n vv(i) = 1.d0 / aamax\n enddo\n \n!$OMP PARALLEL DO PRIVATE(I,J,K,sum,aamax,imax,d,dum) SHARED (A,indx)\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 enddo\n a(i,j) = sum\n enddo\n aamax = 0.d0\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 enddo\n a(i,j) = sum\n dum = vv(i) * dabs(sum)\n if (dum >= aamax) then\n imax = i\n aamax = dum\n endif \n enddo\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 enddo\n d = -d\n vv(imax) = vv(j)\n endif\n indx(j) = imax\n if (a(j,j) == 0.d0) a(j,j) = TINY\n if (j /= n) then\n dum = 1.d0 / a(j,j)\n do i = j+1, n\n a(i,j) = a(i,j) * dum\n enddo\n endif\n enddo\n!$OMP END PARALLEL DO\n\n! call date_and_time(values=values_end)\n! start_time = values_start(5) * 3600 + values_start(6) * 60 + values_start(7) + 0.001 * values_start(8)\n! end_time = values_end(5) * 3600 + values_end(6) * 60 + values_end(7) + 0.001 * values_end(8)\n! print *, 'Time : ', end_time-start_time\n \n end subroutine ludcmp\n \n! ---------------------------------------------------------\n! Solves the set of equations AX=b where A is the LU decomposition of a matrix\n! INPUT:\n! - a is the LU decomposition of the system matrix\n! - b is the right hand side vector of the system\n! - indx is the vector returned by ludcmp\n! OUTPUT:\n! - b is the solution of the system\n! ---------------------------------------------------------\n subroutine lubksb(a,indx,b)\n real*8, INTENT(IN) :: a(:,:)\n real*8, INTENT(INOUT) :: b(:)\n integer, INTENT(IN) :: indx(:)\n integer :: i, ii, n, j, ll\n real*8 :: sum\n n = size(a,1)\n ii = 0\n do i = 1, n\n ll = indx(i)\n sum = b(ll)\n b(ll) = b(i)\n if (ii /= 0) then\n do j = ii, i-1\n sum = sum - a(i,j) * b(j)\n enddo\n else if (sum /= 0.d0) then\n ii = i\n endif\n b(i) = sum\n enddo\n do i = n, 1, -1\n sum = b(i)\n do j = i+1, n\n sum = sum - a(i,j) * b(j)\n enddo\n b(i) = sum / a(i,i)\n enddo\n end subroutine lubksb \n \n! ---------------------------------------------------------\n! This subroutine solves a linear system of equations using the SLAP routines\n! It uses an Incomplete LU BiConjugate Gradient Sparse Ax=b solver\n! --------------------------------------------------------- \n! subroutine slapsolver(a,b)\n! real(kind=8), INTENT(INOUT) :: a(:,:), b(:)\n! integer :: i, j, k, j2\n! real(kind=8), allocatable :: a_sparse(:), x(:), rwork(:)\n! integer, allocatable :: ia(:), ja(:), iwork(:)\n! integer :: n, nelt, isym, itol, itmax, iter, ierr, iunit, lenw, leniw, nsave\n! real(kind=8) :: tol, err\n! integer, allocatable :: indx(:)\n! \n! n = size(b)\n! allocate(x(n))\n! k = 0\n! do i = 1, n\n! do j = 1, n\n! if (a(j,i) /= 0.d0) k = k + 1\n! enddo\n! enddo\n! nelt = k\n! if (verbose_mode == 1) then\n! print *, 'Number of non-zero elements : ', nelt\n! endif\n! allocate(a_sparse(nelt))\n! allocate(ia(nelt))\n! allocate(ja(nelt)) \n! \n! k = 1\n! do i = 1, n\n! do j = 1, n\n! if (a(j,i) /= 0.d0) then\n! a_sparse(k) = a(j,i)\n! ia(k) = j\n! ja(k) = i\n! k = k + 1\n! endif\n! enddo\n! enddo\n! \n! x = 0.d0\n! \n! isym = 0\n! itol = 1\n! tol = 1.d-10\n! itmax = 10000\n! iunit = 0\n! lenw = n*n\n! leniw = n*n\n! nsave = 10\n! allocate(iwork(leniw))\n! allocate(rwork(lenw))\n! \n! if (verbose_mode == 1) then \n! print *, 'Solving the system...'\n! endif\n! call ds2y( n, nelt, ia, ja, a_sparse, isym )\n! call dslubc(n, b, x, nelt, ia, ja, a_sparse, isym, itol, tol, &\n! itmax, iter, err, ierr, iunit, rwork, lenw, iwork, leniw )\n! if (verbose_mode == 1) then \n! print *, 'Number of iterations : ', iter, 'of ', itmax\n! print *, 'Error : ', err, ierr\n! endif\n! if (iter >= itmax+1 .or. ierr /= 0) then\n! if (verbose_mode == 1) then \n! print *, 'Couldn''t reach convergence. Trying other initialization...'\n! endif\n! write(17,*) 'Couldn''t reach convergence. Trying other initialization...'\n! x = 1.d0\n! isym = 0\n! itol = 0\n! tol = 1.d-10\n! itmax = 10000\n! iunit = 0\n! lenw = n*n\n! leniw = n*n\n! nsave = 10\n! call dslucs(n, b, x, nelt, ia, ja, a_sparse, isym, itol, tol, &\n! itmax, iter, err, ierr, iunit, rwork, lenw, iwork, leniw )\n! if (verbose_mode == 1) then \n! print *, 'Number of iterations : ', iter, 'of ', itmax\n! print *, 'Error : ', err, ierr\n! endif\n! endif\n! \n! if (iter >= itmax+1 .or. ierr /= 0) then\n! if (verbose_mode == 1) then \n! print *, 'Couldn''t reach convergence. Trying GMRES...'\n! endif\n! write(17,*) 'Couldn''t reach convergence. Trying GMRES...'\n! x = 0.d0\n! isym = 0\n! itol = 0\n! tol = 1.d-10\n! itmax = 10000\n! iunit = 0\n! lenw = n*n\n! leniw = n*n\n! nsave = 10\n! call dsdgmr(n, b, x, nelt, ia, ja, a_sparse, isym, nsave, itol, tol, &\n! itmax, iter, err, ierr, iunit, rwork, lenw, iwork, leniw )\n! if (verbose_mode == 1) then \n! print *, 'Number of iterations : ', iter, 'of ', itmax\n! print *, 'Error : ', err, ierr\n! endif\n! endif\n! \n! if (iter >= itmax+1 .or. ierr /= 0) then\n! if (verbose_mode == 1) then \n! print *, 'Couldn''t reach convergence. Trying other initialization...'\n! endif\n! write(17,*) 'Couldn''t reach convergence. Trying other initialization...'\n! x = 1.d0\n! isym = 0\n! itol = 0\n! tol = 1.d-10\n! itmax = 10000\n! iunit = 0\n! lenw = n*n\n! leniw = n*n\n! nsave = 10\n! call dsdgmr(n, b, x, nelt, ia, ja, a_sparse, isym, nsave, itol, tol, &\n! itmax, iter, err, ierr, iunit, rwork, lenw, iwork, leniw )\n! if (verbose_mode == 1) then \n! print *, 'Number of iterations : ', iter, 'of ', itmax\n! print *, 'Error : ', err, ierr\n! endif\n! endif\n! \n! b = x\n! \n! deallocate(x)\n! deallocate(a_sparse)\n! deallocate(ia)\n! deallocate(ja)\n! deallocate(iwork)\n! deallocate(rwork)\n! \n! if (iter >= itmax+1 .or. ierr /= 0) then\n! if (verbose_mode == 1) then \n! print *, 'Couldn''t reach convergence. Trying LU decomposition...'\n! endif\n! write(17,*) 'Couldn''t reach convergence. Trying LU decomposition...'\n! allocate(indx(n))\n! call ludcmp(a,indx,tol)\n! call lubksb(a,indx,b)\n! deallocate(indx)\n! endif \n! \n! end subroutine slapsolver\n\n! ---------------------------------------------------------\n! Read lines that don't mind in a file\n! INPUT:\n! - unit : unit to whom the file is associated\n! - n : number of lines to read\n! ---------------------------------------------------------\n subroutine lb(unit, n)\n integer, INTENT(IN) :: unit, n\n integer :: i\n do i = 1, n\n read(unit,*)\n enddo\n end subroutine lb\n \n! ---------------------------------------------------------\n! Returns the sizes of the eigenvectors of the Paschen Back effect\n! ---------------------------------------------------------\n subroutine paschen_size(l2,is2,j2max,njlargest)\n integer :: l2, is2\n integer :: m2, j2max, j2min, j2a, j2b, nj, njlargest\n \n j2min = abs(l2-is2)\n j2max = l2 + is2\n \n! First find the largest value of nj\n njlargest = 0\n do m2 = -j2max, j2max, 2\n j2a = abs(m2)\n if (j2a < j2min) j2a = j2min\n j2b = j2max\n nj = 1 + (j2b-j2a) / 2\n if (nj > njlargest) njlargest = nj\n enddo\n end subroutine paschen_size\n \n! ---------------------------------------------------------\n! Calculates the eigenvalues and eigenvectors of the Paschen-Back matrix\n! INPUT:\n! l2 = 2*L\n! is2 = 2*S\n! e0 = a vector containing the energy in cm^-1 of the level J (Jmin <= J <= Jmax) organized in terms of the J2 value\n! ex. e0(3) is the energy of the J=3/2 level. (Some elements remain undefined)\n! b = magnetic field in gauss\n! OUTPUT:\n! njlev = number of levels for each m2\n! e = a vector containing the eigenvalues of the matrix. It is organized as e(m2,jsmall), where m2 is 2*M and\n! jsmall is a quantum number which takes values between 1 and the number of J compatible with M\n! c = eigenvectors, organized as c(m2,jsmall,J2)\n! --------------------------------------------------------- \n subroutine paschen(l2,is2,e0,B,njlev,e,c,j2m,njl)\n integer :: l2, is2, j2m, njl\n integer :: njlev(-j2m:j2m)\n real(kind=8) :: e(-j2m:j2m,njl), c(-j2m:j2m,njl,0:j2m)\n real(kind=8) :: b, e0(0:jlimit2), bb\n real(kind=8), allocatable :: d(:), ud(:), z(:,:)\n integer :: m2, j2max, j2min, j2a, j2b, nj, j2vero, j, jp, jp2vero, njlargest, i, jsmall, jaux, j2\n real(kind=8) :: x1, x2, x3, x4\n \n bb = PE / (4.d0*PI*PME*PC**2) * B\n j2min = abs(l2-is2)\n j2max = l2 + is2\n \n do m2 = -j2max, j2max, 2\n\n! Build the matrix which corresponds to the value of M\n j2a = abs(m2)\n if (j2a < j2min) j2a = j2min\n j2b = j2max\n nj = 1 + (j2b-j2a) / 2\n njlev(m2) = nj\n \n allocate(d(nj))\n d = 0.d0\n allocate(ud(nj))\n ud = 0.d0\n allocate(z(nj,nj))\n \n! First the diagonal part\n do j = 1, nj\n j2vero = j2a+2*(j-1)\n d(j) = e0(j2vero) \n x1 = 1.d0\n if (mod(2*j2vero+l2+is2+m2,4) /= 0) x1 = -1.d0\n x2 = dfloat(j2vero+1)*dsqrt(dfloat(is2*(is2+2)*(is2+1))/4.d0)\n x3 = w3js(j2vero,j2vero,2,-m2,m2,0)\n x4 = w6js(j2vero,j2vero,2,is2,is2,l2)\n d(j) = d(j) + bb * (dfloat(m2)/2.d0+x1*x2*x3*x4)\n enddo\n \n! If we use the Pashen-Back regime\n if (use_paschen_back == 1) then\n! Then the upper diagonal (only if the matrix is at least 2x2)\n if (nj /= 1) then\n do jp = 2, nj\n jp2vero = j2a+2*(jp-1)\n j2vero = jp2vero-2\n x1 = 1.d0\n if (mod(j2vero+jp2vero+l2+is2+m2,4) /= 0) x1 = -1.d0\n x2 = dsqrt(dfloat((j2vero+1)*(jp2vero+1)*is2*(is2+2)*(is2+1))/4.d0)\n x3 = w3js(j2vero,jp2vero,2,-m2,m2,0)\n x4 = w6js(j2vero,jp2vero,2,is2,is2,l2)\n ud(jp) = bb*x1*x2*x3*x4\n enddo\n endif\n endif\n \n! Initializes the matrix z with the eigenvectors\n z = 0.d0\n do i = 1, nj\n z(i,i) = 1.d0\n enddo\n \n! Diagonalize the matrix\n call tqli(d,ud,nj,nj,z)\n \n do jsmall = 1, nj\n e(m2,jsmall) = d(jsmall)\n do jaux = 1, nj\n j2 = j2a + 2*(jaux-1)\n c(m2,jsmall,j2) = z(jaux,jsmall)\n enddo\n enddo\n \n deallocate(d)\n deallocate(ud)\n deallocate(z)\n \n enddo\n \n end subroutine paschen\n \n! ---------------------------------------------------------\n! Diagonalizes a tridiagonal matrix\n! ---------------------------------------------------------\n subroutine tqli(d,e,n,np,z)\n integer :: n, np, i, l, m, iter, k\n real(kind=8) :: d(np),e(np),z(np,np), g, r, s, c, p, f, b, dd\n \n if (n.gt.1) then\n do 11 i=2,n\n e(i-1)=e(i)\n 11 continue\n e(n)=0.d0\n do 15 l=1,n\n iter=0\n 1 do 12 m=l,n-1\n dd=dabs(d(m))+dabs(d(m+1))\n if(dabs(e(m))+dd.eq.dd) go to 2\n 12 continue\n m=n\n 2 if(m.ne.l) then\n if(iter.eq.30) then\n print *, 'too many iterations'\n stop\n endif\n iter=iter+1\n g=(d(l+1)-d(l))/(2.d0*e(l))\n r=dsqrt(g**2+1.d0)\n g=d(m)-d(l)+e(l)/(g+dsign(r,g))\n s=1.d0\n c=1.d0\n p=0.d0\n do 14 i=m-1,l,-1\n f=s*e(i)\n b=c*e(i)\n if(dabs(f).ge.dabs(g)) then\n c=g/f\n r=dsqrt(c**2+1.d0)\n e(i+1)=f*r\n s=1.d0/r\n c=c*s\n else\n s=f/g\n r=dsqrt(s**2+1.d0)\n e(i+1)=g*r\n c=1.d0/r\n s=s*c\n endif\n g=d(i+1)-p\n r=(d(i)-g)*s+2.d0*c*b\n p=s*r\n d(i+1)=g+p\n g=c*r-b\n do 13 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 13 continue\n 14 continue\n d(l)=d(l)-p\n e(l)=g\n e(m)=0.d0\n go to 1\n endif\n 15 continue\n endif\n return\n end subroutine tqli\n \n! ---------------------------------------------------------\n! Sets the imaginary part of a complex to a given number\n! ---------------------------------------------------------\n subroutine set_imaginary(A,b)\n complex(kind=8) :: A\n real(kind=8) :: b\n A = cmplx(real(A),b)\n end subroutine set_imaginary\n \n! ---------------------------------------------------------\n! Sets the imaginary part of a complex to a given number\n! ---------------------------------------------------------\n subroutine set_real(A,b)\n complex(kind=8) :: A\n real(kind=8) :: b\n A = cmplx(b,aimag(A))\n end subroutine set_real\n \n\n\n!--------------------------------------------------------------\n! Dawson's integral\n!--------------------------------------------------------------\n function dawson(dv)\n real(kind=8) :: dv(:)\n real(kind=8) :: dawson(size(dv)), c(6), x\n real(kind=8), parameter :: H=0.4, A1=2./3., A2=0.4, A3=2./7.\n integer :: i, n, j, n0\n real(kind=8) :: xx, xp, e1, e2, d1, d2, sum, x2\n \n n = size(dv)\n do i = 1, 6\n c(i)=exp(-((2.*float(i)-1.)*H)**2)\n enddo\n\n do i = 1, n\n if (abs(dv(i)) < 0.2) then\n x = dv(i)\n x2 = dv(i)**2\n dawson(i) = x*(1.-A1*x2*(1.-A2*x2*(1.-A3*x2)))\n else\n x = dv(i)\n xx = abs(dv(i))\n n0 = 2*nint(0.5*xx/H)\n xp = xx-float(n0)*H\n e1 = exp(2.*xp*H)\n e2 = e1**2\n d1 = float(n0+1)\n d2 = d1-2.\n sum = 0.\n do j = 1,6\n sum = sum + c(j)*(e1/d1+1./(d2*e1))\n d1 = d1+2.\n d2 = d2-2.\n e1 = e2*e1\n enddo\n dawson(i) = 0.5641895835*sign(exp(-xp**2),x)*sum\n endif\n enddo\n\n end function dawson\n\n!--------------------------------------------------------------\n! Generates Voigt and anomalous dispersion profiles using a different damping for each frequency\n! point\n! See Humlicek (1982) JQSRT 27, 437\n!--------------------------------------------------------------\n function profile(da, dv)\n real(kind=8) :: da\n real(kind=8) :: dv(:)\n complex(kind=8) :: profile(size(dv))\n complex(kind=8) :: w4, z, t, u, v4\n real(kind=8) :: s\n integer :: i, n\n\n \n n = size(dv)\n\n! For small a, evaluate the power expansion up to second order (Landi degl'Innocenti & Landolfi 2004, p. 168)\n if (da < 1.d-3) then\n profile = cmplx(exp(-dv**2) + 2.d0*da/sqrt(PI)*(2*dv*dawson(dv)-1.d0), 2.d0*dawson(dv) / sqrt(PI) - 2.d0*da*dv*exp(-dv**2))\n return\n endif\n do i = 1, n\n! There is a problem for very small dampings. We force it to be 0 using a threshold\n z = cmplx(dv(i), da)\n t = cmplx(da, -dv(i))\n s = dabs(dv(i)) + da\n u = t*t\n\n\n if (s >= 15.d0) then\n w4 = t * 0.5641896d0 / (0.5d0+u)\n elseif (s >= 5.5) then\n w4 = t*(1.410474d0+u*0.5641896d0)/(0.75d0+u*(3.d0+u))\n elseif (da >= 0.195d0*dabs(dv(i))-0.176d0) then\n w4 = (16.4955d0+t*(20.20933d0+t*(11.96482d0+t*(3.778987d0+t*0.5642236d0)))) / &\n (16.4955d0+t*(38.82363d0+t*(39.27121d0+t*(21.69274d0+t*(6.699398d0+t)))))\n else \n w4 = t*(36183.31d0-u*(3321.9905d0-u*(1540.787d0-u*(219.0313d0-u*(35.76683d0-&\n u*(1.320522d0-u*0.56419d0))))))\n v4 = (32066.6d0-u*(24322.84d0-u*(9022.228d0-u*(2186.181d0-u*(364.2191d0-&\n u*(61.57037d0-u*(1.841439d0-u)))))))\n w4 = exp(u) - w4/v4\n endif\n profile(i) = w4\n enddo\n\n end function profile\n \n! ---------------------------------------------------------\n! Given xa(:) and ya(:) which tabulate a function, returns the interpolation using\n! linear interpolation of vector x(:) in y(:)\n! --------------------------------------------------------- \n subroutine lin_interpol(xa,ya,x,y)\n real*8, INTENT(IN) :: xa(:), ya(:), x(:)\n real*8, INTENT(INOUT) :: y(:)\n integer :: i, n\n integer :: locat(1), loc\n\n n = size(x)\n\n do i = 1, n\n locat = minloc(dabs(xa-x(i)))\n loc = locat(1)\n if (loc == 1) then\n y(i) = ya(loc)\n else \n y(i) = (ya(loc)-ya(loc-1))/(xa(loc)-xa(loc-1)) * (x(i)-xa(loc-1)) + ya(loc-1)\n endif\n enddo\n\n end subroutine lin_interpol \n\n! ---------------------------------------------------------\n! Given etaI, etaQ, etaU, etaV, rhoQ, rhoU and rhoV, fill the absorption matrix\n! --------------------------------------------------------- \n subroutine fill_absorption_matrix(matrix,etaI,etaQ,etaU,etaV,rhoQ,rhoU,rhoV)\n real(kind=8) :: matrix(4,4), etaI, etaQ, etaU, etaV, rhoQ, rhoU, rhoV\n\n matrix(1,1) = etaI\n matrix(2,2) = etaI\n matrix(3,3) = etaI\n matrix(4,4) = etaI\n matrix(1,2) = etaQ\n matrix(2,1) = etaQ \n matrix(1,3) = etaU\n matrix(3,1) = etaU\n matrix(1,4) = etaV\n matrix(4,1) = etaV \n matrix(2,3) = rhoV\n matrix(3,2) = -rhoV\n matrix(2,4) = -rhoU\n matrix(4,2) = rhoU \n matrix(3,4) = rhoQ \n matrix(4,3) = -rhoQ \n \n end subroutine fill_absorption_matrix\n\n!--------------------------------------------------------------\n! Inversion of a 4x4 matrix\n!--------------------------------------------------------------\n subroutine invert(a)\n real*8 :: a(4,4)\n real*8 :: b(4,4), det, maxim, fabsmax\n ! First some tests of singularity\n b = dabs(a)\n maxim = maxval(b)\n fabsmax = 1.d0 / maxim\n if (maxim == 0.d0) then\n print *, 'Singularity in the inversion'\n! stop\n endif\n\n a = a * fabsmax\n\n b(1,1) = a(2,2) * a(3,3) * a(4,4) + a(2,3) * a(3,4) * a(4,2)&\n + a(2,4) * a(3,2) * a(4,3) - a(2,2) * a(3,4) * a(4,3)&\n - a(2,3) * a(3,2) * a(4,4) - a(2,4) * a(3,3) * a(4,2)\n b(2,1) = a(2,3) * a(3,1) * a(4,4) + a(2,4) * a(3,3) * a(4,1)&\n + a(2,1) * a(3,4) * a(4,3) - a(2,3) * a(3,4) * a(4,1)&\n - a(2,4) * a(3,1) * a(4,3) - a(2,1) * a(3,3) * a(4,4)\n b(3,1) = a(2,4) * a(3,1) * a(4,2) + a(2,1) * a(3,2) * a(4,4)&\n + a(2,2) * a(3,4) * a(4,1) - a(2,4) * a(3,2) * a(4,1)&\n - a(2,1) * a(3,4) * a(4,2) - a(2,2) * a(3,1) * a(4,4)\n b(4,1) = a(2,1) * a(3,3) * a(4,2) + a(2,2) * a(3,1) * a(4,3)&\n + a(2,3) * a(3,2) * a(4,1) - a(2,1) * a(3,2) * a(4,3)&\n - a(2,2) * a(3,3) * a(4,1) - a(2,3) * a(3,1) * a(4,2)\n b(1,2) = a(3,2) * a(4,4) * a(1,3) + a(3,3) * a(4,2) * a(1,4)&\n + a(3,4) * a(4,3) * a(1,2) - a(3,2) * a(4,3) * a(1,4)&\n - a(3,3) * a(4,4) * a(1,2) - a(3,4) * a(4,2) * a(1,3)\n b(2,2) = a(3,3) * a(4,4) * a(1,1) + a(3,4) * a(4,1) * a(1,3)&\n + a(3,1) * a(4,3) * a(1,4) - a(3,3) * a(4,1) * a(1,4)&\n - a(3,4) * a(4,3) * a(1,1) - a(3,1) * a(4,4) * a(1,3)\n b(3,2) = a(3,4) * a(4,2) * a(1,1) + a(3,1) * a(4,4) * a(1,2)&\n + a(3,2) * a(4,1) * a(1,4) - a(3,4) * a(4,1) * a(1,2)&\n - a(3,1) * a(4,2) * a(1,4) - a(3,2) * a(4,4) * a(1,1)\n b(4,2) = a(3,1) * a(4,2) * a(1,3) + a(3,2) * a(4,3) * a(1,1)&\n + a(3,3) * a(4,1) * a(1,2) - a(3,1) * a(4,3) * a(1,2)&\n - a(3,2) * a(4,1) * a(1,3) - a(3,3) * a(4,2) * a(1,1)\n b(1,3) = a(4,2) * a(1,3) * a(2,4) + a(4,3) * a(1,4) * a(2,2)&\n + a(4,4) * a(1,2) * a(2,3) - a(4,2) * a(1,4) * a(2,3)&\n - a(4,3) * a(1,2) * a(2,4) - a(4,4) * a(1,3) * a(2,2)\n b(2,3) = a(4,3) * a(1,1) * a(2,4) + a(4,4) * a(1,3) * a(2,1)&\n + a(4,1) * a(1,4) * a(2,3) - a(4,3) * a(1,4) * a(2,1)&\n - a(4,4) * a(1,1) * a(2,3) - a(4,1) * a(1,3) * a(2,4)\n b(3,3) = a(4,4) * a(1,1) * a(2,2) + a(4,1) * a(1,2) * a(2,4)&\n + a(4,2) * a(1,4) * a(2,1) - a(4,4) * a(1,2) * a(2,1)&\n - a(4,1) * a(1,4) * a(2,2) - a(4,2) * a(1,1) * a(2,4)\n b(4,3) = a(4,1) * a(1,3) * a(2,2) + a(4,2) * a(1,1) * a(2,3)&\n + a(4,3) * a(1,2) * a(2,1) - a(4,1) * a(1,2) * a(2,3)&\n - a(4,2) * a(1,3) * a(2,1) - a(4,3) * a(1,1) * a(2,2)\n b(1,4) = a(1,2) * a(2,4) * a(3,3) + a(1,3) * a(2,2) * a(3,4)&\n + a(1,4) * a(2,3) * a(3,2) - a(1,2) * a(2,3) * a(3,4)&\n - a(1,3) * a(2,4) * a(3,2) - a(1,4) * a(2,2) * a(3,3)\n b(2,4) = a(1,3) * a(2,4) * a(3,1) + a(1,4) * a(2,1) * a(3,3)&\n + a(1,1) * a(2,3) * a(3,4) - a(1,3) * a(2,1) * a(3,4)&\n - a(1,4) * a(2,3) * a(3,1) - a(1,1) * a(2,4) * a(3,3)\n b(3,4) = a(1,4) * a(2,2) * a(3,1) + a(1,1) * a(2,4) * a(3,2)&\n + a(1,2) * a(2,1) * a(3,4) - a(1,4) * a(2,1) * a(3,2)&\n - a(1,1) * a(2,2) * a(3,4) - a(1,2) * a(2,4) * a(3,1)\n b(4,4) = a(1,1) * a(2,2) * a(3,3) + a(1,2) * a(2,3) * a(3,1)&\n + a(1,3) * a(2,1) * a(3,2) - a(1,1) * a(2,3) * a(3,2)&\n - a(1,2) * a(2,1) * a(3,3) - a(1,3) * a(2,2) * a(3,1)\n\n det = a(1,1) * b(1,1) + a(1,2) * b(2,1) + a(1,3) * b(3,1) + a(1,4) * b(4,1)\n\n a = b * (fabsmax / det)\n\n end subroutine invert\n\n!--------------------------------------------------------------\n! Returns in b the evolution operator if the propagation matrix is constant\n! given by exp(-A*t). It uses Eqs. A5.20 of Landi Degl'Innocenti & Landolfi 2004\n!--------------------------------------------------------------\n subroutine evol_operator(a,t,b)\n real(kind=8) :: a(4,4), t\n real(kind=8) :: b(4,4), det, maxim, fabsmax, w(3), y(3), w_y_scalar, sigma\n real(kind=8) :: Lambda_plus, Lambda_minus, tt, Theta, w_mod_sq, y_mod_sq, factor1, factor2, factor3, factor4, w0, temp1, temp2\n real(kind=8), dimension(4,4) :: M1, M2, M3, M4\n integer :: i\n\n w0 = a(1,1)\n\n w(1) = a(1,2)\n w(2) = a(1,3)\n w(3) = a(1,4)\n w_mod_sq = sum(w*w)\n\n y(1) = a(3,4)\n y(2) = a(4,2)\n y(3) = a(2,3)\n y_mod_sq = sum(y*y)\n\n w_y_scalar = sum(w*y)\n sigma = 1.d0\n if (w_y_scalar < 0.d0) sigma = -1.d0\n\n! Eigenvalues\n temp1 = sqrt((w_mod_sq - y_mod_sq)**2 / 4.d0 + w_y_scalar**2)\n temp2 = (w_mod_sq - y_mod_sq) / 2.d0\n if (temp1+temp2 < 0.d0) then\n Lambda_plus = 0.d0\n else\n Lambda_plus = sqrt(temp1 + temp2)\n endif\n if (temp1-temp2 < 0.d0) then\n Lambda_minus = 0.d0\n else\n Lambda_minus = sqrt(temp1 - temp2)\n endif\n \n Theta = 2.d0 * temp1\n tt = (w_mod_sq + y_mod_sq) / 2.d0\n\n M1 = 0.d0\n M2 = 0.d0\n M3 = 0.d0\n M4 = 0.d0\n\n! M1\n do i = 1, 4\n M1(i,i) = 1.d0\n enddo\n\n! M2\n M2(1,2) = Lambda_minus * w(1) - sigma * Lambda_plus * y(1)\n M2(1,3) = Lambda_minus * w(2) - sigma * Lambda_plus * y(2)\n M2(1,4) = Lambda_minus * w(3) - sigma * Lambda_plus * y(3)\n M2(2,1) = M2(1,2)\n M2(2,3) = sigma * Lambda_plus * w(3) + Lambda_minus * y(3)\n M2(2,4) = -sigma * Lambda_plus * w(2) - Lambda_minus * y(2)\n M2(3,1) = M2(1,3)\n M2(3,2) = -M2(2,3)\n M2(3,4) = sigma * Lambda_plus * w(1) + Lambda_minus * y(1)\n M2(4,1) = M2(1,4)\n M2(4,2) = -M2(2,4)\n M2(4,3) = -M2(3,4)\n\n! M3\n M3(1,2) = Lambda_plus * w(1) + sigma * Lambda_minus * y(1)\n M3(1,3) = Lambda_plus * w(2) + sigma * Lambda_minus * y(2)\n M3(1,4) = Lambda_plus * w(3) + sigma * Lambda_minus * y(3)\n M3(2,1) = M3(1,2)\n M3(2,3) = -sigma * Lambda_minus * w(3) + Lambda_plus * y(3)\n M3(2,4) = sigma * Lambda_minus * w(2) - Lambda_plus * y(2)\n M3(3,1) = M3(1,3)\n M3(3,2) = -M3(2,3)\n M3(3,4) = -sigma * Lambda_minus * w(1) + Lambda_plus * y(1)\n M3(4,1) = M3(1,4)\n M3(4,2) = -M3(2,4)\n M3(4,3) = -M3(3,4)\n\n! M4\n M4(1,1) = tt\n M4(1,2) = w(3)*y(2) - w(2)*y(3)\n M4(1,3) = w(1)*y(3) - w(3)*y(1)\n M4(1,4) = w(2)*y(1) - w(1)*y(2)\n M4(2,1) = -M4(1,2)\n M4(2,2) = w(1)**2 + y(1)**2 - tt\n M4(2,3) = w(1)*w(2) + y(1)*y(2)\n M4(2,4) = w(3)*w(1) + y(3)*y(1)\n M4(3,1) = -M4(1,3)\n M4(3,2) = M4(2,3)\n M4(3,3) = w(2)**2 + y(2)**2 - tt\n M4(3,4) = w(2)*w(3) + y(2)*y(3)\n M4(4,1) = -M4(1,4)\n M4(4,2) = M4(2,4)\n M4(4,3) = M4(3,4)\n M4(4,4) = w(3)**2 + y(3)**2 - tt\n\n M2 = M2 / Theta\n M3 = M3 / Theta\n M4 = 2.d0 * M4 / Theta\n\n factor1 = 0.5d0*(cosh(t*Lambda_plus) + cos(t*Lambda_minus))\n factor2 = sin(t*Lambda_minus)\n factor3 = sinh(t*Lambda_plus)\n factor4 = 0.5d0*(cosh(t*Lambda_plus) - cos(t*Lambda_minus))\n\n b = factor1*M1 - factor2*M2 - factor3*M3 + factor4*M4\n b = exp(-t*w0) * b\n \n end subroutine evol_operator\n\n! ---------------------------------------------------------\n! Return the input array but shifted by a sub-pixel amount\n! Note that it works only for any length of series which has no prime factor greater than 23\n! ---------------------------------------------------------\n function fft_shift(x, sh)\n real(kind=8) :: x(:), fft_shift(size(x)), sh\n complex(kind=8) :: k(size(x)), ff(size(x))\n integer :: nx, i, n21\n \n nx = size(x)\n\n do i = 1, nx\n k(i) = i-1\n enddo\n n21 = nx/2+1\n do i = n21+1, nx\n k(i) = n21-nx+(i-1-n21)\n enddo\n\n k = 2.d0*PI*k/(1.d0*nx)\n k = k * cmplx(0.d0,1.d0)\n\n ff = x\n\n ff = fft(ff)\n\n fft_shift = real(fft(ff * exp(k*sh), inv=.TRUE.))\n \n end function fft_shift\n\n function erf(x)\n real(kind=8) :: erf, x, dumerfc, t, z\n\n z = abs(x)\n t = 1.0 / ( 1.0 + 0.5 * z )\n\n dumerfc = t * exp(-z * z - 1.26551223 + t * &\n ( 1.00002368 + t * ( 0.37409196 + t * &\n ( 0.09678418 + t * (-0.18628806 + t * &\n ( 0.27886807 + t * (-1.13520398 + t * &\n ( 1.48851587 + t * (-0.82215223 + t * 0.17087277 )))))))))\n\n if ( x.lt.0.0 ) dumerfc = 2.0 - dumerfc\n \n erf = 1.0 - dumerfc\n\n end function erf\n \n! ---------------------------------------------------------\n! Solve a one-dimensional equality using the secant method\n! ---------------------------------------------------------\n function confidenceLevel(x, nu, P)\n real(kind=8) :: confidenceLevel, x, nu, P\n confidenceLevel = gammq(0.5*nu,0.5*x) + P - 1.d0\n return \n end function confidenceLevel\n\n! ---------------------------------------------------------\n! Solve a one-dimensional equality using the secant method\n! ---------------------------------------------------------\n function secantConfidenceLevel(nu,P)\n real(kind=8) :: func, x1, x2, xacc, fl, f, secantConfidenceLevel, xl, swap, dx, nu,P\n integer :: j\n integer, parameter :: maxit=30\n xacc = 1e-3\n x1 = nu-0.1\n x2 = nu+14.d0\n fl=confidenceLevel(x1,nu,P)\n f=confidenceLevel(x2,nu,P) \n if(abs(fl).lt.abs(f))then\n secantConfidenceLevel=x1\n xl=x2\n swap=fl\n fl=f\n f=swap\n else\n xl=x1\n secantConfidenceLevel=x2\n endif\n do j=1,maxit\n dx=(xl-secantConfidenceLevel)*f/(f-fl)\n xl=secantConfidenceLevel\n fl=f\n secantConfidenceLevel=secantConfidenceLevel+dx\n f=confidenceLevel(secantConfidenceLevel,nu,P)\n if(abs(dx).lt.xacc.or.f.eq.0.)return\n enddo\n print *, 'rtsec exceed maximum iterations'\n end function secantConfidenceLevel\n\n! ---------------------------------------------------------\n! Return the log of the gamma function\n! ---------------------------------------------------------\n function gammln(xx)\n real(kind=8) :: cof(6),stp,half,one,fpf,x,tmp,ser,gammln, dx, xx\n data cof,stp/76.18009173d0,-86.50532033d0,24.01409822d0,-1.231739516d0,.120858003d-2,-.536382d-5,2.50662827465d0/\n data half,one,fpf/0.5d0,1.0d0,5.5d0/\n integer :: j\n x=xx-one\n tmp=x+fpf\n tmp=(x+half)*log(tmp)-tmp\n ser=one\n do j=1,6\n x=x+one\n ser=ser+cof(j)/x\n enddo\n gammln=tmp+log(stp*ser)\n return\n end function gammln\n\n! ---------------------------------------------------------\n! \n! ---------------------------------------------------------\n subroutine gcf(gammcf,a,x,gln)\n real(kind=8) :: gammcf, a, x, gln, gold, a0, a1, b0, b1, fac, an, ana, anf, g\n real(kind=8), parameter :: eps=3e-7\n integer, parameter :: itmax=200\n integer :: n\n \n gln=gammln(a)\n gold=0.\n a0=1.\n a1=x\n b0=0.\n b1=1.\n fac=1.\n do n=1,itmax\n an=float(n)\n ana=an-a\n a0=(a1+a0*ana)*fac\n b0=(b1+b0*ana)*fac\n anf=an*fac\n a1=x*a0+anf*a1\n b1=x*b0+anf*b1\n if(a1.ne.0.)then\n fac=1./a1\n g=b1*fac\n if(abs((g-gold)/g).lt.eps) then\n gammcf=exp(-x+a*log(x)-gln)*g\n return\n endif\n gold=g\n endif\n enddo\n print *, 'a too large, itmax too small'\n end subroutine gcf\n \n subroutine gser(gamser,a,x,gln)\n real(kind=8) :: gamser, a, x, gln, ap, sum, del\n real(kind=8), parameter :: eps=3e-7\n integer, parameter :: itmax=200\n integer :: n\n \n gln=gammln(a)\n if(x.le.0.)then \n gamser=0.\n return\n endif\n ap=a\n sum=1./a\n del=sum\n do n=1,itmax\n ap=ap+1.\n del=del*x/ap\n sum=sum+del\n if(abs(del).lt.abs(sum)*eps) then\n gamser=sum*exp(-x+a*log(x)-gln)\n return\n endif\n enddo\n print *, 'a too large, itmax too small'\n end subroutine gser\n \n function gammq(a,x)\n real(kind=8) :: gammq, a, x, gln, gamser, gammcf\n if(x.lt.0..or.a.le.0.) then\n print *, x, a\n stop\n endif\n if(x.lt.a+1.)then\n call gser(gamser,a,x,gln)\n gammq=1.-gamser\n else\n call gcf(gammcf,a,x,gln)\n gammq=gammcf\n endif\n return\n end function gammq\n\n\n \nend module maths\n", "meta": {"hexsha": "059d7758d9d96d02015df4adbb56f633a372967b", "size": 51921, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/maths.f90", "max_stars_repo_name": "aasensio/hazel", "max_stars_repo_head_hexsha": "899c8461324061bacc14da7165b9ac7eed35c96b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2016-01-11T05:03:00.000Z", "max_stars_repo_stars_event_max_datetime": "2018-08-31T11:13:24.000Z", "max_issues_repo_path": "src/maths.f90", "max_issues_repo_name": "aasensio/hazel", "max_issues_repo_head_hexsha": "899c8461324061bacc14da7165b9ac7eed35c96b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 12, "max_issues_repo_issues_event_min_datetime": "2017-04-22T16:10:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-11T14:03:59.000Z", "max_forks_repo_path": "src/maths.f90", "max_forks_repo_name": "aasensio/hazel", "max_forks_repo_head_hexsha": "899c8461324061bacc14da7165b9ac7eed35c96b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2016-02-25T19:35:07.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-01T17:12:52.000Z", "avg_line_length": 33.5190445449, "max_line_length": 135, "alphanum_fraction": 0.4150343792, "num_tokens": 17923, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.933430805473952, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6823925978992479}} {"text": " subroutine root(a,b,c,x1,x2)\r\nc\r\nc + + + PURPOSE + + +\r\nc Finds roots for the equation y=a*x**2+b*x+c\r\nc\r\nc Called from subroutine XCRIT.\r\nc Author(s): G. Foster, M. Nearing\r\nc Reference in User Guide:\r\nc\r\nc Changes:\r\nc\r\nc Version: This module recoded from WEPP version 90.92.\r\nc Date recoded: 01/08/91.\r\nc Recoded by: Charles R. Meyer.\r\nc\r\nc + + + KEYWORDS + + +\r\nc\r\nc + + + ARGUMENT DECLARATIONS + + +\r\n real a, b\r\n double precision c, x1, x2\r\nc\r\nc a -\r\nc b -\r\nc c -\r\nc x1 -\r\nc x2 -\r\nc\r\nc + + + ARGUMENT DEFINITIONS + + +\r\nc\r\nc + + + LOCAL VARIABLES + + +\r\n double precision cc, part\r\n real b1, tmpvr1\r\nc cc -\r\nc part -\r\nc\r\nc + + + END SPECIFICATIONS + + +\r\nc\r\n b1 = -b\r\n tmpvr1 = 2.0 * a\r\n cc = -c\r\n part = sqrt(b**2-4.0*a*cc)\r\n x1 = (b1-part) / tmpvr1\r\n x2 = (b1+part) / tmpvr1\r\nc\r\n if (x1.gt.x2) then\r\n part = x2\r\n x2 = x1\r\n x1 = part\r\n end if\r\nc\r\n return\r\n end\r\n", "meta": {"hexsha": "969eda7c0510bf61e3a3d590d38cfe990db606ea", "size": 1068, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/wepp2010.1/root.for", "max_stars_repo_name": "jarad/dep", "max_stars_repo_head_hexsha": "fe73982f4c70039e1a31b9e8e2d9aac31502f803", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-11-26T17:49:19.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-26T17:49:19.000Z", "max_issues_repo_path": "src/wepp2010.1/root.for", "max_issues_repo_name": "jarad/dep", "max_issues_repo_head_hexsha": "fe73982f4c70039e1a31b9e8e2d9aac31502f803", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 54, "max_issues_repo_issues_event_min_datetime": "2018-12-12T18:02:31.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T19:14:25.000Z", "max_forks_repo_path": "src/wepp2010.1/root.for", "max_forks_repo_name": "akrherz/idep", "max_forks_repo_head_hexsha": "7189a26fbcec3d8c3cc7d7015107b8fb6c5f6a45", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-03-02T22:59:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-09T15:49:00.000Z", "avg_line_length": 20.1509433962, "max_line_length": 60, "alphanum_fraction": 0.4672284644, "num_tokens": 379, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294983, "lm_q2_score": 0.7310585727705127, "lm_q1q2_score": 0.6823925964912472}} {"text": "\tSUBROUTINE SSIZE\r\n .\t(SALPHA,SBETA,SR,SP0,M,XSPSI,XN,ERR)\r\n\tIMPLICIT NONE\r\nC\r\nC-Description-----------------------------------------------------------\r\nC\r\nC Function:\r\nC\tDetermine case patient sample size N\r\nC Arguments:\r\nC\r\nC INPUT:\r\nC\r\nC i\tSALPHA\t(REAL)\r\nC\tType I error probability\r\nC i\tSBETA\t(REAL)\r\nC\tType II error probability\r\nC i\tSR\t(REAL)\r\nC\tCorrelation coefficient\r\nC i\tSP0\t(REAL)\r\nC\tProbability of exposure in control group\r\nC i\tM\t(Integer)\r\nC\tNumber of matched controls per case patient\r\nC i\tXSPSI\t(REAL)\r\nC\tOdds ratio\r\nC\r\nC OUTPUT:\r\nC\r\nC o\tXN\t(Real)\r\nC\tNumber of case patients\r\nC o\tERR\t(Integer)\r\nC Notes:\r\nC .\tThis routine was written by Dale Plummer.\r\nC .\tDesigned by Dr. William Dupont.\r\nC . The LaTeX notation given in the comments is from:\r\nC Dupont, Biometrics 1988;44:1157-68.\r\nC\r\nC-Declarations----------------------------------------------------------\r\nC\r\n\tINTEGER M,ERR\r\n\tREAL XN\r\n\tREAL SALPHA,SBETA,SR,SP0,XSPSI\r\n DOUBLE PRECISION ALPHA,BETA,R,P0,PSI\r\n\tDOUBLE PRECISION ZALPHA,ZBETA\r\n\tREAL ZCRVALUE\r\n\tDOUBLE PRECISION RM,RN\r\n\tDOUBLE PRECISION SQV1,SQVPSI\r\n\tDOUBLE PRECISION NM\r\n\t\r\n\tDOUBLE PRECISION MEAN,VAR,PSI_VALUE\r\n\tDOUBLE PRECISION E1, V1, EPSI, VPSI\r\nC\r\nC Code:\r\nC\r\nC Assume a successful run.\r\nC\r\n\tERR=0\r\nC\r\nC Copy arguments M and N to floating point local storage.\r\nC\r\n\tRM=DBLE(M)\r\n\tRN=DBLE(XN)\r\nC\r\nC Copy single precision arguments to double precision internal\r\nC representation.\r\nC\r\nC ALPHA = \\alpha\r\nC BETA = \\beta\r\nC P0 = p_0\r\nC PSI = \\psi\r\nC ZALPHA = z_{\\alpha/2}\r\nC ZBETA = z_{\\beta}\r\nC\r\n\tALPHA=DBLE(SALPHA)\r\n\tBETA=DBLE(SBETA)\r\n\tR=DBLE(SR)\r\n\tP0=DBLE(SP0)\r\n\tPSI=DBLE(XSPSI)\r\n\tZALPHA=DBLE(ZCRVALUE(SALPHA/2.))\r\n\tZBETA=DBLE(ZCRVALUE(SBETA))\r\n\r\n\tPSI_VALUE=1\r\n\tCALL MEANANDVAR(P0,R,M,RM,PSI_VALUE,MEAN,VAR)\r\nC\r\nC E1 = e_1 in equation (7)\r\nC V1 = v_1 in equation (7)\r\nC\r\n\tE1 = MEAN\r\n\tV1 = VAR\r\n\t\r\n\tPSI_VALUE=PSI\r\n\tCALL MEANANDVAR(P0,R,M,RM,PSI_VALUE,MEAN,VAR)\r\nC\r\nC EPSI = e_{\\PSI} in equation (7)\r\nC VPSI = v_{\\PSI} in equation (7)\r\nC\r\n\tEPSI = MEAN\r\n\tVPSI = VAR\r\n\t\r\nC ----------------------------------------------------\r\n\t\r\n\tSQV1=SQRT(V1)\r\n\tSQVPSI=SQRT(VPSI)\r\nC\r\nC NM is equation (7) in Dupont (Biometrics 1988).\r\nC\r\n\tNM=(ZBETA*SQVPSI+ZALPHA*SQV1)**2/(EPSI-E1)**2\r\n\tXN=NM\r\n\r\n\tRETURN\r\n\tEND\r\n\t\r\nC ======================================================\r\n\r\n\tSUBROUTINE MEANANDVAR(P0,R,M,RM,PSI,MEAN,VAR)\r\n\tIMPLICIT NONE\r\nC\r\nC When the alternaitve hypothesis is true this\r\nC routine calculates e_{\\psi} and v_{\\psi}\r\nC\r\nC When the null hypothesis is true (\\psi=1)\r\nC then it calculates e_1 and v_1\r\nC\r\n\tDOUBLE PRECISION P0,R,RM,PSI\r\n\tINTEGER M\r\n\tDOUBLE PRECISION MEAN,VAR\r\n\t\r\n\tINTEGER IMPOSS,I,IM\r\n\tDOUBLE PRECISION P1,Q1,Q0,P01,P00,Q01,Q00,C1,C2,T(1000)\r\n\t\t\r\n\tINTEGER ERR\r\n\tREAL FM, XN\r\nC\r\nC Code:\r\nC\r\nC Calculate P1 = p_1.\r\nC\r\n\tCALL PONE(P0,PSI,R,P1,IMPOSS)\r\n\tIF (IMPOSS.EQ.1) THEN\r\n\t ERR=1\r\n\t FM=0.\r\n\t XN=0.\r\n\t RETURN\r\n\tEND IF\r\nC\r\nC Q1=q_1 Probability that a case patient is not exposed.\r\nC\r\n\tQ1=1.-P1\r\nC\r\nC Q0=q_0 Probability that a control is not exposed.\r\nC\r\n\tQ0=1.-P0\r\nC\r\nC P01 = p_{o+}\r\nC Probability that a control is exposed given that his matched case\r\nC is exposed.\r\nC\r\n\tP01=P0+R*SQRT(Q1*P0*Q0/P1)\r\nC\r\nC P00 = p_{o-}\r\nC Probability that a control is exposed given that his matched case\r\nC is NOT exposed.\r\nC\r\n\tP00=P0-R*SQRT(P1*P0*Q0/Q1)\r\n\tQ01=1.-P01\r\n\tQ00=1.-P00\r\n\tIM=M\r\n1\tCONTINUE\r\n\tC1=1.\r\n\tC2=RM\r\nC\r\nC The index I is denoted \"m\" in Dupont 1988.\r\nC T(I) = T(m) = t_m is the probability of\r\nC observing m exposed subjects among a case\r\nC and his M matched controls.\r\nC\r\n\tDO 10 I=1,IM\r\n\t T(I)=P1*C1*P01**(I-1)*Q01**(IM-I+1) + Q1*C2*P00**I*Q00**(IM-I)\r\n\t C1=C2\r\n\t C2=C2*(RM-DBLE(I))/(DBLE(I)+1.)\r\n10\tCONTINUE\r\n\r\n\tMEAN=0D0\r\n\tDO 40 I=1,IM\r\n\t MEAN=MEAN+(DBLE(I)*T(I)*PSI/(DBLE(I)*PSI+RM-DBLE(I)+1.))\r\n40\tCONTINUE\r\n\r\n\tVAR=0D0\r\n\tDO 50 I=1,IM\r\n\t VAR=VAR+\r\n .\t(DBLE(I)*T(I)*PSI*(RM-DBLE(I)+1.)/(DBLE(I)*PSI+RM-DBLE(I)+1)**2)\r\n50\tCONTINUE\r\n\r\n\tRETURN\r\n\tEND", "meta": {"hexsha": "3633b26969993b27a8b095c860124a7dde549783", "size": 4043, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "misc/old_ps/ps-development-version/psDll/ssize.for", "max_stars_repo_name": "vubiostat/ps", "max_stars_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2017-12-29T14:19:14.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-06T15:08:46.000Z", "max_issues_repo_path": "misc/old_ps/ps-development-version/psDll/ssize.for", "max_issues_repo_name": "vubiostat/ps", "max_issues_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2020-04-30T16:57:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-07T00:26:02.000Z", "max_forks_repo_path": "misc/old_ps/ps-development-version/psDll/ssize.for", "max_forks_repo_name": "vubiostat/ps", "max_forks_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-07T20:11:54.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-11T19:18:59.000Z", "avg_line_length": 20.8402061856, "max_line_length": 73, "alphanum_fraction": 0.6045016077, "num_tokens": 1509, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218305645895, "lm_q2_score": 0.7401743505760728, "lm_q1q2_score": 0.6823828922200493}} {"text": "*> \\brief \\b DROTG\n*\n* =========== DOCUMENTATION ===========\n*\n* Online html documentation available at\n* http://www.netlib.org/lapack/explore-html/\n*\n* Definition:\n* ===========\n*\n* SUBROUTINE DROTG(DA,DB,C,S)\n*\n* .. Scalar Arguments ..\n* DOUBLE PRECISION C,DA,DB,S\n* ..\n*\n*\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*>\n*> DROTG construct givens plane rotation.\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in] DA\n*> \\verbatim\n*> DA is DOUBLE PRECISION\n*> \\endverbatim\n*>\n*> \\param[in] DB\n*> \\verbatim\n*> DB is DOUBLE PRECISION\n*> \\endverbatim\n*>\n*> \\param[out] C\n*> \\verbatim\n*> C is DOUBLE PRECISION\n*> \\endverbatim\n*>\n*> \\param[out] S\n*> \\verbatim\n*> S is DOUBLE PRECISION\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee\n*> \\author Univ. of California Berkeley\n*> \\author Univ. of Colorado Denver\n*> \\author NAG Ltd.\n*\n*> \\date November 2017\n*\n*> \\ingroup double_blas_level1\n*\n*> \\par Further Details:\n* =====================\n*>\n*> \\verbatim\n*>\n*> jack dongarra, linpack, 3/11/78.\n*> \\endverbatim\n*>\n* =====================================================================\n SUBROUTINE DROTG(DA,DB,C,S)\n*\n* -- Reference BLAS level1 routine (version 3.8.0) --\n* -- Reference BLAS is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n* November 2017\n*\n* .. Scalar Arguments ..\n DOUBLE PRECISION C,DA,DB,S\n* ..\n*\n* =====================================================================\n*\n* .. Local Scalars ..\n DOUBLE PRECISION R,ROE,SCALE,Z\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC DABS,DSIGN,DSQRT\n* ..\n ROE = DB\n IF (DABS(DA).GT.DABS(DB)) ROE = DA\n SCALE = DABS(DA) + DABS(DB)\n IF (SCALE.EQ.0.0d0) THEN\n C = 1.0d0\n S = 0.0d0\n R = 0.0d0\n Z = 0.0d0\n ELSE\n R = SCALE*DSQRT((DA/SCALE)**2+ (DB/SCALE)**2)\n R = DSIGN(1.0d0,ROE)*R\n C = DA/R\n S = DB/R\n Z = 1.0d0\n IF (DABS(DA).GT.DABS(DB)) Z = S\n IF (DABS(DB).GE.DABS(DA) .AND. C.NE.0.0d0) Z = 1.0d0/C\n END IF\n DA = R\n DB = Z\n RETURN\n END\n", "meta": {"hexsha": "c030d3c6442bacfcda3d82987cb8cb75f1de8124", "size": 2288, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "lapack-netlib/BLAS/SRC/drotg.f", "max_stars_repo_name": "drhpc/OpenBLAS", "max_stars_repo_head_hexsha": "9721b57ecfd194f1a4aaa08d715735cd9e8ad8b6", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 4392, "max_stars_repo_stars_event_min_datetime": "2015-01-02T18:15:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T12:14:38.000Z", "max_issues_repo_path": "lapack-netlib/BLAS/SRC/drotg.f", "max_issues_repo_name": "drhpc/OpenBLAS", "max_issues_repo_head_hexsha": "9721b57ecfd194f1a4aaa08d715735cd9e8ad8b6", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2067, "max_issues_repo_issues_event_min_datetime": "2015-01-01T03:50:01.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T18:59:43.000Z", "max_forks_repo_path": "lapack-netlib/BLAS/SRC/drotg.f", "max_forks_repo_name": "drhpc/OpenBLAS", "max_forks_repo_head_hexsha": "9721b57ecfd194f1a4aaa08d715735cd9e8ad8b6", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1564, "max_forks_repo_forks_event_min_datetime": "2015-01-01T01:32:27.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T07:12:54.000Z", "avg_line_length": 20.8, "max_line_length": 80, "alphanum_fraction": 0.486013986, "num_tokens": 722, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392848011834, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6823399784477339}} {"text": "!***********************************************************************\n! This file is part of project ISFRC. *\n! ISFRC is an Integrated Simulation code for Field-Reversed *\n! Configuration. *\n! *\n! Developers: *\n! Shuying SUN, Yang LI, Huasheng XIE, ... *\n! *\n! ENN Sci. & Tech. Development Coorporation, 2008-2019. *\n! (c) All rights reserved. *\n!***********************************************************************\n\nsubroutine comelp ( hk2, ck, ce )\n\n!*****************************************************************************80\n!\n!! COMELP computes complete elliptic integrals K(k) and E(k).\n!\n! Licensing:\n!\n! This routine is copyrighted by Shanjie Zhang and Jianming Jin. However, \n! they give permission to incorporate this routine into a user program \n! provided that the copyright is acknowledged.\n!\n! Modified:\n!\n! 07 July 2012\n!\n! Author:\n!\n! Shanjie Zhang, Jianming Jin\n!\n! Reference:\n!\n! Shanjie Zhang, Jianming Jin,\n! Computation of Special Functions,\n! Wiley, 1996,\n! ISBN: 0-471-11963-6,\n! LC: QA351.C45.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) HK, the modulus. 0 <= HK <= 1.\n!\n! Output, real ( kind = 8 ) CK, CE, the values of K(HK) and E(HK).\n!\n implicit none\n\n real ( kind = 8 ) ae\n real ( kind = 8 ) ak\n real ( kind = 8 ) be\n real ( kind = 8 ) bk\n real ( kind = 8 ) ce\n real ( kind = 8 ) ck\n real ( kind = 8 ) hk2 ! hk2=hk*hk\n real ( kind = 8 ) pk\n\n !pk = 1.0D+00 - hk * hk\n pk = 1.0D+00 - hk2\n\n if ( hk2 == 1.0D+00 ) then\n\n ck = 1.0D+300\n ce = 1.0D+00\n\n else\n\n ak = ((( &\n 0.01451196212D+00 * pk &\n + 0.03742563713D+00 ) * pk &\n + 0.03590092383D+00 ) * pk &\n + 0.09666344259D+00 ) * pk &\n + 1.38629436112D+00\n\n bk = ((( &\n 0.00441787012D+00 * pk &\n + 0.03328355346D+00 ) * pk &\n + 0.06880248576D+00 ) * pk &\n + 0.12498593597D+00 ) * pk &\n + 0.5D+00\n\n ck = ak - bk * log ( pk )\n\n ae = ((( &\n 0.01736506451D+00 * pk &\n + 0.04757383546D+00 ) * pk &\n + 0.0626060122D+00 ) * pk &\n + 0.44325141463D+00 ) * pk &\n + 1.0D+00\n\n be = ((( &\n 0.00526449639D+00 * pk &\n + 0.04069697526D+00 ) * pk &\n + 0.09200180037D+00 ) * pk &\n + 0.2499836831D+00 ) * pk\n\n ce = ae - be * log ( pk )\n\n end if\n\n return\nend\n\n", "meta": {"hexsha": "e2a2056221d68e03026c1145c2c872ace385b9c5", "size": 2702, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/elliptic.f90", "max_stars_repo_name": "bangrsun/ISFRC", "max_stars_repo_head_hexsha": "f7a5598c28451212d6751f2b5819129df9d5a084", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-06-17T14:26:33.000Z", "max_stars_repo_stars_event_max_datetime": "2019-08-15T09:23:08.000Z", "max_issues_repo_path": "src/elliptic.f90", "max_issues_repo_name": "bangrsun/ISFRC", "max_issues_repo_head_hexsha": "f7a5598c28451212d6751f2b5819129df9d5a084", "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/elliptic.f90", "max_forks_repo_name": "bangrsun/ISFRC", "max_forks_repo_head_hexsha": "f7a5598c28451212d6751f2b5819129df9d5a084", "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.9807692308, "max_line_length": 80, "alphanum_fraction": 0.422649889, "num_tokens": 834, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563336, "lm_q2_score": 0.7718434978390746, "lm_q1q2_score": 0.682339976166197}} {"text": "*DECK COMLR2\n SUBROUTINE COMLR2 (NM, N, LOW, IGH, INT, HR, HI, WR, WI, ZR, ZI,\n + IERR)\nC***BEGIN PROLOGUE COMLR2\nC***PURPOSE Compute the eigenvalues and eigenvectors of a complex upper\nC Hessenberg matrix using the modified LR method.\nC***LIBRARY SLATEC (EISPACK)\nC***CATEGORY D4C2B\nC***TYPE COMPLEX (COMLR2-C)\nC***KEYWORDS EIGENVALUES, EIGENVECTORS, EISPACK, LR METHOD\nC***AUTHOR Smith, B. T., et al.\nC***DESCRIPTION\nC\nC This subroutine is a translation of the ALGOL procedure COMLR2,\nC NUM. MATH. 16, 181-204(1970) by Peters and Wilkinson.\nC HANDBOOK FOR AUTO. COMP., VOL.II-LINEAR ALGEBRA, 372-395(1971).\nC\nC This subroutine finds the eigenvalues and eigenvectors\nC of a COMPLEX UPPER Hessenberg matrix by the modified LR\nC method. The eigenvectors of a COMPLEX GENERAL matrix\nC can also be found if COMHES has been used to reduce\nC this general matrix to Hessenberg form.\nC\nC On INPUT\nC\nC NM must be set to the row dimension of the two-dimensional\nC array parameters, HR, HI, ZR and ZI, as declared in the\nC calling program dimension statement. NM is an INTEGER\nC variable.\nC\nC N is the order of the matrix H=(HR,HI). N is an INTEGER\nC variable. N must be less than or equal to NM.\nC\nC LOW and IGH are two INTEGER variables determined by the\nC balancing subroutine CBAL. If CBAL has not been used,\nC set LOW=1 and IGH equal to the order of the matrix, N.\nC\nC INT contains information on the rows and columns\nC interchanged in the reduction by COMHES, if performed.\nC Only elements LOW through IGH are used. If you want the\nC eigenvectors of a complex general matrix, leave INT as it\nC came from COMHES. If the eigenvectors of the Hessenberg\nC matrix are desired, set INT(J)=J for these elements. INT\nC is a one-dimensional INTEGER array, dimensioned INT(IGH).\nC\nC HR and HI contain the real and imaginary parts, respectively,\nC of the complex upper Hessenberg matrix. Their lower\nC triangles below the subdiagonal contain the multipliers\nC which were used in the reduction by COMHES, if performed.\nC If the eigenvectors of a complex general matrix are\nC desired, leave these multipliers in the lower triangles.\nC If the eigenvectors of the Hessenberg matrix are desired,\nC these elements must be set to zero. HR and HI are\nC two-dimensional REAL arrays, dimensioned HR(NM,N) and\nC HI(NM,N).\nC\nC On OUTPUT\nC\nC The upper Hessenberg portions of HR and HI have been\nC destroyed, but the location HR(1,1) contains the norm\nC of the triangularized matrix.\nC\nC WR and WI contain the real and imaginary parts, respectively,\nC of the eigenvalues of the upper Hessenberg matrix. If an\nC error exit is made, the eigenvalues should be correct for\nC indices IERR+1, IERR+2, ..., N. WR and WI are one-\nC dimensional REAL arrays, dimensioned WR(N) and WI(N).\nC\nC ZR and ZI contain the real and imaginary parts, respectively,\nC of the eigenvectors. The eigenvectors are unnormalized.\nC If an error exit is made, none of the eigenvectors has been\nC found. ZR and ZI are two-dimensional REAL arrays,\nC dimensioned ZR(NM,N) and ZI(NM,N).\nC\nC IERR is an INTEGER flag set to\nC Zero for normal return,\nC J if the J-th eigenvalue has not been\nC determined after a total of 30*N iterations.\nC The eigenvalues should be correct for indices\nC IERR+1, IERR+2, ..., N, but no eigenvectors are\nC computed.\nC\nC Calls CSROOT for complex square root.\nC Calls CDIV for complex division.\nC\nC Questions and comments should be directed to B. S. Garbow,\nC APPLIED MATHEMATICS DIVISION, ARGONNE NATIONAL LABORATORY\nC ------------------------------------------------------------------\nC\nC***REFERENCES B. T. Smith, J. M. Boyle, J. J. Dongarra, B. S. Garbow,\nC Y. Ikebe, V. C. Klema and C. B. Moler, Matrix Eigen-\nC system Routines - EISPACK Guide, Springer-Verlag,\nC 1976.\nC***ROUTINES CALLED CDIV, CSROOT\nC***REVISION HISTORY (YYMMDD)\nC 760101 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890831 Modified array declarations. (WRB)\nC 890831 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE COMLR2\nC\n INTEGER I,J,K,L,M,N,EN,II,JJ,LL,MM,NM,NN,IGH,IM1,IP1\n INTEGER ITN,ITS,LOW,MP1,ENM1,IEND,IERR\n REAL HR(NM,*),HI(NM,*),WR(*),WI(*),ZR(NM,*),ZI(NM,*)\n REAL SI,SR,TI,TR,XI,XR,YI,YR,ZZI,ZZR,NORM,S1,S2\n INTEGER INT(*)\nC\nC***FIRST EXECUTABLE STATEMENT COMLR2\n IERR = 0\nC .......... INITIALIZE EIGENVECTOR MATRIX ..........\n DO 100 I = 1, N\nC\n DO 100 J = 1, N\n ZR(I,J) = 0.0E0\n ZI(I,J) = 0.0E0\n IF (I .EQ. J) ZR(I,J) = 1.0E0\n 100 CONTINUE\nC .......... FORM THE MATRIX OF ACCUMULATED TRANSFORMATIONS\nC FROM THE INFORMATION LEFT BY COMHES ..........\n IEND = IGH - LOW - 1\n IF (IEND .LE. 0) GO TO 180\nC .......... FOR I=IGH-1 STEP -1 UNTIL LOW+1 DO -- ..........\n DO 160 II = 1, IEND\n I = IGH - II\n IP1 = I + 1\nC\n DO 120 K = IP1, IGH\n ZR(K,I) = HR(K,I-1)\n ZI(K,I) = HI(K,I-1)\n 120 CONTINUE\nC\n J = INT(I)\n IF (I .EQ. J) GO TO 160\nC\n DO 140 K = I, IGH\n ZR(I,K) = ZR(J,K)\n ZI(I,K) = ZI(J,K)\n ZR(J,K) = 0.0E0\n ZI(J,K) = 0.0E0\n 140 CONTINUE\nC\n ZR(J,I) = 1.0E0\n 160 CONTINUE\nC .......... STORE ROOTS ISOLATED BY CBAL ..........\n 180 DO 200 I = 1, N\n IF (I .GE. LOW .AND. I .LE. IGH) GO TO 200\n WR(I) = HR(I,I)\n WI(I) = HI(I,I)\n 200 CONTINUE\nC\n EN = IGH\n TR = 0.0E0\n TI = 0.0E0\n ITN = 30*N\nC .......... SEARCH FOR NEXT EIGENVALUE ..........\n 220 IF (EN .LT. LOW) GO TO 680\n ITS = 0\n ENM1 = EN - 1\nC .......... LOOK FOR SINGLE SMALL SUB-DIAGONAL ELEMENT\nC FOR L=EN STEP -1 UNTIL LOW DO -- ..........\n 240 DO 260 LL = LOW, EN\n L = EN + LOW - LL\n IF (L .EQ. LOW) GO TO 300\n S1 = ABS(HR(L-1,L-1)) + ABS(HI(L-1,L-1))\n 1 + ABS(HR(L,L)) + ABS(HI(L,L))\n S2 = S1 + ABS(HR(L,L-1)) + ABS(HI(L,L-1))\n IF (S2 .EQ. S1) GO TO 300\n 260 CONTINUE\nC .......... FORM SHIFT ..........\n 300 IF (L .EQ. EN) GO TO 660\n IF (ITN .EQ. 0) GO TO 1000\n IF (ITS .EQ. 10 .OR. ITS .EQ. 20) GO TO 320\n SR = HR(EN,EN)\n SI = HI(EN,EN)\n XR = HR(ENM1,EN) * HR(EN,ENM1) - HI(ENM1,EN) * HI(EN,ENM1)\n XI = HR(ENM1,EN) * HI(EN,ENM1) + HI(ENM1,EN) * HR(EN,ENM1)\n IF (XR .EQ. 0.0E0 .AND. XI .EQ. 0.0E0) GO TO 340\n YR = (HR(ENM1,ENM1) - SR) / 2.0E0\n YI = (HI(ENM1,ENM1) - SI) / 2.0E0\n CALL CSROOT(YR**2-YI**2+XR,2.0E0*YR*YI+XI,ZZR,ZZI)\n IF (YR * ZZR + YI * ZZI .GE. 0.0E0) GO TO 310\n ZZR = -ZZR\n ZZI = -ZZI\n 310 CALL CDIV(XR,XI,YR+ZZR,YI+ZZI,XR,XI)\n SR = SR - XR\n SI = SI - XI\n GO TO 340\nC .......... FORM EXCEPTIONAL SHIFT ..........\n 320 SR = ABS(HR(EN,ENM1)) + ABS(HR(ENM1,EN-2))\n SI = ABS(HI(EN,ENM1)) + ABS(HI(ENM1,EN-2))\nC\n 340 DO 360 I = LOW, EN\n HR(I,I) = HR(I,I) - SR\n HI(I,I) = HI(I,I) - SI\n 360 CONTINUE\nC\n TR = TR + SR\n TI = TI + SI\n ITS = ITS + 1\n ITN = ITN - 1\nC .......... LOOK FOR TWO CONSECUTIVE SMALL\nC SUB-DIAGONAL ELEMENTS ..........\n XR = ABS(HR(ENM1,ENM1)) + ABS(HI(ENM1,ENM1))\n YR = ABS(HR(EN,ENM1)) + ABS(HI(EN,ENM1))\n ZZR = ABS(HR(EN,EN)) + ABS(HI(EN,EN))\nC .......... FOR M=EN-1 STEP -1 UNTIL L DO -- ..........\n DO 380 MM = L, ENM1\n M = ENM1 + L - MM\n IF (M .EQ. L) GO TO 420\n YI = YR\n YR = ABS(HR(M,M-1)) + ABS(HI(M,M-1))\n XI = ZZR\n ZZR = XR\n XR = ABS(HR(M-1,M-1)) + ABS(HI(M-1,M-1))\n S1 = ZZR / YI * (ZZR + XR + XI)\n S2 = S1 + YR\n IF (S2 .EQ. S1) GO TO 420\n 380 CONTINUE\nC .......... TRIANGULAR DECOMPOSITION H=L*R ..........\n 420 MP1 = M + 1\nC\n DO 520 I = MP1, EN\n IM1 = I - 1\n XR = HR(IM1,IM1)\n XI = HI(IM1,IM1)\n YR = HR(I,IM1)\n YI = HI(I,IM1)\n IF (ABS(XR) + ABS(XI) .GE. ABS(YR) + ABS(YI)) GO TO 460\nC .......... INTERCHANGE ROWS OF HR AND HI ..........\n DO 440 J = IM1, N\n ZZR = HR(IM1,J)\n HR(IM1,J) = HR(I,J)\n HR(I,J) = ZZR\n ZZI = HI(IM1,J)\n HI(IM1,J) = HI(I,J)\n HI(I,J) = ZZI\n 440 CONTINUE\nC\n CALL CDIV(XR,XI,YR,YI,ZZR,ZZI)\n WR(I) = 1.0E0\n GO TO 480\n 460 CALL CDIV(YR,YI,XR,XI,ZZR,ZZI)\n WR(I) = -1.0E0\n 480 HR(I,IM1) = ZZR\n HI(I,IM1) = ZZI\nC\n DO 500 J = I, N\n HR(I,J) = HR(I,J) - ZZR * HR(IM1,J) + ZZI * HI(IM1,J)\n HI(I,J) = HI(I,J) - ZZR * HI(IM1,J) - ZZI * HR(IM1,J)\n 500 CONTINUE\nC\n 520 CONTINUE\nC .......... COMPOSITION R*L=H ..........\n DO 640 J = MP1, EN\n XR = HR(J,J-1)\n XI = HI(J,J-1)\n HR(J,J-1) = 0.0E0\n HI(J,J-1) = 0.0E0\nC .......... INTERCHANGE COLUMNS OF HR, HI, ZR, AND ZI,\nC IF NECESSARY ..........\n IF (WR(J) .LE. 0.0E0) GO TO 580\nC\n DO 540 I = 1, J\n ZZR = HR(I,J-1)\n HR(I,J-1) = HR(I,J)\n HR(I,J) = ZZR\n ZZI = HI(I,J-1)\n HI(I,J-1) = HI(I,J)\n HI(I,J) = ZZI\n 540 CONTINUE\nC\n DO 560 I = LOW, IGH\n ZZR = ZR(I,J-1)\n ZR(I,J-1) = ZR(I,J)\n ZR(I,J) = ZZR\n ZZI = ZI(I,J-1)\n ZI(I,J-1) = ZI(I,J)\n ZI(I,J) = ZZI\n 560 CONTINUE\nC\n 580 DO 600 I = 1, J\n HR(I,J-1) = HR(I,J-1) + XR * HR(I,J) - XI * HI(I,J)\n HI(I,J-1) = HI(I,J-1) + XR * HI(I,J) + XI * HR(I,J)\n 600 CONTINUE\nC .......... ACCUMULATE TRANSFORMATIONS ..........\n DO 620 I = LOW, IGH\n ZR(I,J-1) = ZR(I,J-1) + XR * ZR(I,J) - XI * ZI(I,J)\n ZI(I,J-1) = ZI(I,J-1) + XR * ZI(I,J) + XI * ZR(I,J)\n 620 CONTINUE\nC\n 640 CONTINUE\nC\n GO TO 240\nC .......... A ROOT FOUND ..........\n 660 HR(EN,EN) = HR(EN,EN) + TR\n WR(EN) = HR(EN,EN)\n HI(EN,EN) = HI(EN,EN) + TI\n WI(EN) = HI(EN,EN)\n EN = ENM1\n GO TO 220\nC .......... ALL ROOTS FOUND. BACKSUBSTITUTE TO FIND\nC VECTORS OF UPPER TRIANGULAR FORM ..........\n 680 NORM = 0.0E0\nC\n DO 720 I = 1, N\nC\n DO 720 J = I, N\n NORM = NORM + ABS(HR(I,J)) + ABS(HI(I,J))\n 720 CONTINUE\nC\n HR(1,1) = NORM\n IF (N .EQ. 1 .OR. NORM .EQ. 0.0E0) GO TO 1001\nC .......... FOR EN=N STEP -1 UNTIL 2 DO -- ..........\n DO 800 NN = 2, N\n EN = N + 2 - NN\n XR = WR(EN)\n XI = WI(EN)\n ENM1 = EN - 1\nC .......... FOR I=EN-1 STEP -1 UNTIL 1 DO -- ..........\n DO 780 II = 1, ENM1\n I = EN - II\n ZZR = HR(I,EN)\n ZZI = HI(I,EN)\n IF (I .EQ. ENM1) GO TO 760\n IP1 = I + 1\nC\n DO 740 J = IP1, ENM1\n ZZR = ZZR + HR(I,J) * HR(J,EN) - HI(I,J) * HI(J,EN)\n ZZI = ZZI + HR(I,J) * HI(J,EN) + HI(I,J) * HR(J,EN)\n 740 CONTINUE\nC\n 760 YR = XR - WR(I)\n YI = XI - WI(I)\n IF (YR .NE. 0.0E0 .OR. YI .NE. 0.0E0) GO TO 775\n YR = NORM\n 770 YR = 0.5E0*YR\n IF (NORM + YR .GT. NORM) GO TO 770\n YR = 2.0E0*YR\n 775 CALL CDIV(ZZR,ZZI,YR,YI,HR(I,EN),HI(I,EN))\n 780 CONTINUE\nC\n 800 CONTINUE\nC .......... END BACKSUBSTITUTION ..........\n ENM1 = N - 1\nC .......... VECTORS OF ISOLATED ROOTS ..........\n DO 840 I = 1, ENM1\n IF (I .GE. LOW .AND. I .LE. IGH) GO TO 840\n IP1 = I + 1\nC\n DO 820 J = IP1, N\n ZR(I,J) = HR(I,J)\n ZI(I,J) = HI(I,J)\n 820 CONTINUE\nC\n 840 CONTINUE\nC .......... MULTIPLY BY TRANSFORMATION MATRIX TO GIVE\nC VECTORS OF ORIGINAL FULL MATRIX.\nC FOR J=N STEP -1 UNTIL LOW+1 DO -- ..........\n DO 880 JJ = LOW, ENM1\n J = N + LOW - JJ\n M = MIN(J-1,IGH)\nC\n DO 880 I = LOW, IGH\n ZZR = ZR(I,J)\n ZZI = ZI(I,J)\nC\n DO 860 K = LOW, M\n ZZR = ZZR + ZR(I,K) * HR(K,J) - ZI(I,K) * HI(K,J)\n ZZI = ZZI + ZR(I,K) * HI(K,J) + ZI(I,K) * HR(K,J)\n 860 CONTINUE\nC\n ZR(I,J) = ZZR\n ZI(I,J) = ZZI\n 880 CONTINUE\nC\n GO TO 1001\nC .......... SET ERROR -- NO CONVERGENCE TO AN\nC EIGENVALUE AFTER 30*N ITERATIONS ..........\n 1000 IERR = EN\n 1001 RETURN\n END\n", "meta": {"hexsha": "d775358d87a161f032c2fd5e51074a4c5c8b2c90", "size": 13127, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/comlr2.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/comlr2.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/comlr2.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.1848958333, "max_line_length": 72, "alphanum_fraction": 0.5032376019, "num_tokens": 4740, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563335, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6823399715265624}} {"text": "! Converts the binary string in BIN to its real value\r\n! Igor Lopes, February 2015\r\nDOUBLE PRECISION FUNCTION BIN2REAL(BIN,NBIT)\r\n IMPLICIT NONE\r\n REAL(8) R0 /0.0D0/\r\n REAL(8) R2 /2.0D0/\r\n ! Arguments\r\n INTEGER NBIT\r\n INTEGER,DIMENSION(NBIT) :: BIN\r\n ! Locals\r\n INTEGER :: IBIT\r\n ! Begin algorithm\r\n BIN2REAL=R0\r\n DO IBIT=1,NBIT\r\n BIN2REAL=BIN2REAL+BIN(IBIT)*R2**(NBIT-IBIT)\r\n ENDDO\r\n RETURN\r\nEND FUNCTION", "meta": {"hexsha": "e1a1bb4d2b32a6b6e5da8cb8754479fe5fea2104", "size": 451, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/genetic/bin2real.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/genetic/bin2real.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/genetic/bin2real.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.0555555556, "max_line_length": 54, "alphanum_fraction": 0.6319290466, "num_tokens": 151, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8840392756357327, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6823399620941712}} {"text": " PROGRAM xpredic\r\nC driver for routine predic\r\n INTEGER NPTS,NPOLES,NFUT\r\n REAL PI\r\n PARAMETER(NPTS=500,NPOLES=10,NFUT=20,PI=3.1415926)\r\n INTEGER i,n\r\n REAL f,dum,data(NPTS),d(NPOLES),future(NFUT)\r\n f(n)=exp(-1.0*n/NPTS)*sin(2.0*PI*n/50.0)\r\n * +exp(-2.0*n/NPTS)*sin(2.2*PI*n/50.0)\r\n do 11 i=1,NPTS\r\n data(i)=f(i)\r\n11 continue\r\n call memcof(data,NPTS,NPOLES,dum,d)\r\n call fixrts(d,NPOLES)\r\n call predic(data,NPTS,d,NPOLES,future,NFUT)\r\n write(*,'(6x,a,t13,a,t25,a)') 'I','Actual','PREDIC'\r\n do 12 i=1,NFUT\r\n write(*,'(1x,i6,2f12.6)') i,f(i+NPTS),future(i)\r\n12 continue\r\n END\r\n", "meta": {"hexsha": "1d615edff4dfe95598fc7e20f70ff71b58726bf1", "size": 677, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xpredic.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xpredic.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xpredic.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.2380952381, "max_line_length": 58, "alphanum_fraction": 0.5568685377, "num_tokens": 260, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.6823315239619597}} {"text": "MODULE Snowaccumulationmod\n IMPLICIT NONE\nCONTAINS\n\n SUBROUTINE model_snowaccumulation(tsmax, &\n tmax, &\n trmax, &\n precip, &\n Snowaccu)\n IMPLICIT NONE\n REAL, INTENT(IN) :: tsmax\n REAL, INTENT(IN) :: tmax\n REAL, INTENT(IN) :: trmax\n REAL, INTENT(IN) :: precip\n REAL, INTENT(OUT) :: Snowaccu\n REAL:: fs\n fs = 0.0\n !- Name: SnowAccumulation -Version: 1.0, -Time step: 1\n !- Description:\n ! * Title: snowfall accumulation calculation\n ! * Author: STICS\n ! * Reference: doi:http://dx.doi.org/10.1016/j.agrformet.2014.05.002\n ! * Institution: INRA\n ! * Abstract: It simulates the depth of snow cover and recalculate weather data\n !- inputs:\n ! * name: tsmax\n ! ** description : maximum daily air temperature (tmax) below which all precipitation is assumed to be snow\n ! ** inputtype : parameter\n ! ** parametercategory : constant\n ! ** datatype : DOUBLE\n ! ** default : 0.0\n ! ** min : 0.0\n ! ** max : 1000\n ! ** unit : degC\n ! ** uri : \n ! * name: tmax\n ! ** description : current maximum air temperature\n ! ** inputtype : variable\n ! ** variablecategory : auxiliary\n ! ** datatype : DOUBLE\n ! ** default : 0.0\n ! ** min : 0.0\n ! ** max : 5000.0\n ! ** unit : degC\n ! ** uri : \n ! * name: trmax\n ! ** description : tmax above which all precipitation is assumed to be rain\n ! ** inputtype : parameter\n ! ** parametercategory : constant\n ! ** datatype : DOUBLE\n ! ** default : 0.0\n ! ** min : 0.0\n ! ** max : 5000.0\n ! ** unit : degC\n ! ** uri : \n ! * name: precip\n ! ** description : current precipitation\n ! ** inputtype : variable\n ! ** variablecategory : auxiliary\n ! ** datatype : DOUBLE\n ! ** default : 0.0\n ! ** min : 0.0\n ! ** max : 5000.0\n ! ** unit : mmW\n ! ** uri : \n !- outputs:\n ! * name: Snowaccu\n ! ** description : snowfall accumulation\n ! ** variablecategory : rate\n ! ** datatype : DOUBLE\n ! ** min : 0.0\n ! ** max : 500.0\n ! ** unit : mmW/d\n ! ** uri : \n IF(tmax .LT. tsmax) THEN\n fs = 1.0\n END IF\n IF(tmax .GE. tsmax .AND. tmax .LE. trmax) THEN\n fs = (trmax - tmax) / (trmax - tsmax)\n END IF\n Snowaccu = fs * precip\n END SUBROUTINE model_snowaccumulation\n\nEND MODULE\n", "meta": {"hexsha": "d884d557aa7fc9b0aa686dc09a6c45847cde056f", "size": 3603, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/stics/STICS_SNOW/Snowaccumulation.f90", "max_stars_repo_name": "Crop2ML-Catalog/STICS_SNOW", "max_stars_repo_head_hexsha": "26ed2a9a30e068d72d5589b1dc64916c1b07fa09", "max_stars_repo_licenses": ["MIT"], "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/stics/STICS_SNOW/Snowaccumulation.f90", "max_issues_repo_name": "Crop2ML-Catalog/STICS_SNOW", "max_issues_repo_head_hexsha": "26ed2a9a30e068d72d5589b1dc64916c1b07fa09", "max_issues_repo_licenses": ["MIT"], "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/stics/STICS_SNOW/Snowaccumulation.f90", "max_forks_repo_name": "Crop2ML-Catalog/STICS_SNOW", "max_forks_repo_head_hexsha": "26ed2a9a30e068d72d5589b1dc64916c1b07fa09", "max_forks_repo_licenses": ["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.3882352941, "max_line_length": 136, "alphanum_fraction": 0.3605328893, "num_tokens": 806, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.6823315239619596}} {"text": "C DATANA.F - Gateway function for data analysis calculations using\nC SLICOT routines DE01OD, DE01PD, DF01MD, DG01MD, DG01ND,\nC DG01OD, and DK01MD.\nC\nC RELEASE 2.0 of SLICOT Basic Systems and Control Toolbox.\nC Based on SLICOT RELEASE 5.7. Copyright (c) 2002-2020 NICONET e.V.\nC\nC Matlab call:\nC [C(,D)] = datana(job,A(,B)(,T)(,window)(,pad0))\nC\nC [C] = datana(job,A(,pad0)) |job| = 0, 6;\nC [C] = datana(job,A,B(,pad0)) |job| = 1, 2;\nC [C] = datana(job,A(,T)(,pad0)) |job| = 3;\nC [YR,YI] = datana(job,XR,XI(,pad0)) |job| = 4, 5;\nC [C] = datana(job,A(,window)) job = 7.\nC\nC Purpose:\nC To perform various transforms of real or complex vectors, used in\nC data analysis calculations.\nC\nC Input parameters:\nC job - option parameter indicating the task to be performed.\nC =-6 : scrambled discrete Hartley transform of a real\nC signal A (the input signal is bit-reversed);\nC =-5 : inverse discrete Fourier transform of a real signal;\nC =-4 : inverse discrete Fourier transform of a complex\nC signal XR+i*XI;\nC =-3 : sine transform of a real signal A;\nC =-2 : deconvolution of two real signals A and B using\nC Hartley transform;\nC =-1 : deconvolution of two real signals A and B using FFT;\nC = 0 : discrete Hartley transform of a real signal A\nC (the signal is not scrambled);\nC = 1 : convolution of two real signals A and B using FFT,\nC defined in MATLAB by real(ifft(fft(A).*fft(B)));\nC = 2 : convolution of two real signals A and B using\nC Hartley transform;\nC = 3 : cosine transform of a real signal A;\nC = 4 : discrete Fourier transform of a complex signal\nC XR+i*XI;\nC = 5 : discrete Fourier transform of a real signal X;\nC = 6 : scrambled discrete Hartley transform of a real\nC signal A (the output transform is bit-reversed);\nC = 7 : anti-aliasing window applied to a real signal A.\nC A - the n-vector A.\nC B - (optional) if |job| = 1 or 2, the n-vector B.\nC T - (optional) if |job| = 3, the sampling time of the\nC signal; otherwise, it is not used.\nC Default: T = 1.\nC XR - if job = 4, the n-vector containing the real part of the\nC complex signal X.\nC if job = -4, the n-vector containing the real part of the\nC discrete Fourier transform.\nC if job = 5, the n-vector containing the odd part of the\nC real signal X.\nC if job = -5, the n+1-vector containing the real part of\nC the discrete Fourier transform.\nC XI - if job = 4, the n-vector containing the imaginary part of\nC the complex signal X.\nC if job = -4, the n-vector containing the imaginary part of\nC the discrete Fourier transform.\nC if job = 5, the n-vector containing the even part of the\nC real signal X.\nC if job = -5, the n+1-vector containing the imaginary\nC part of the discrete Fourier transform.\nC window - (optional) if job = 7, integer specifying the type of\nC window to use:\nC = 1: Hamming window;\nC = 2: Hann window;\nC = 3: Quadratic window.\nC Default: window = 1.\nC pad0 - (optional) if job <> 7, integer specifying how sequences\nC whose length is not a power of 2 should be dealt with:\nC = 0: truncate the trailing part and use a number of data\nC points corresponding to the largest power of 2, i.e.,\nC 2^m, if |job| <> 3, or 2^m+1, if |job| = 3;\nC = 1: pad the trailing part with 0 till the next power\nC of 2 (plus 1, if |job| = 3).\nC Default: pad0 = 0.\nC\nC Output parameters:\nC C - the n-vector of results computed according to job.\nC YR - if job = 4, the n-vector containing the real part of\nC the computed discrete Fourier transform.\nC if job = -4, the n-vector containing the real part of\nC inverse discrete Fourier transform.\nC if job = 5, the n+1-vector containing the real part of\nC the discrete Fourier transform.\nC if job = -5, the odd part of the inverse discrete\nC Fourier transform.\nC YI - if job = 4, the n-vector containing the imaginary part\nC of the computed discrete Fourier transform.\nC if job = -4, the n-vector containing the imaginary part\nC of the inverse discrete Fourier transform.\nC if job = 5, the n+1-vector containing the imaginary part\nC of the discrete Fourier transform.\nC if job = -5, the even part of the inverse discrete\nC Fourier transform.\nC\nC Further Comments:\nC 1) Except for job = 7, this function essentially works on signals\nC whose length is a power of 2, 2^m (or 2^m+1, if |job| = 3).\nC For |job| = 3, m >= 2.\nC 2) For job = 5, this function computes the first n+1 elements\nC of the discrete Fourier transform. The remaining n-1 elements\nC can be obtained using the MATLAB command conj( Y(n:-1:2) ),\nC where Y = YR + i*YI.\nC 3) For job = -5, this function uses as input the first\nC n+1 elements of the discrete Fourier transform.\nC\nC Contributor:\nC V. Sima, Research Institute for Informatics, Bucharest, Dec. 2002.\nC\nC Revisions:\nC V. Sima, Research Institute for Informatics, Bucharest, Apr. 2009,\nC Dec. 2012.\nC\nC **********************************************************************\nC\n SUBROUTINE MEXFUNCTION( NLHS, PLHS, NRHS, PRHS )\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, ONE\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )\nC\nC .. Mex-file interface parameters ..\n INTEGER PLHS(*), PRHS(*)\n INTEGER*4 NLHS, NRHS\nC\nC .. Mex-file integer functions ..\n INTEGER mxCreateDoubleMatrix, mxGetPr\n INTEGER*4 mxGetM, mxGetN, mxIsNumeric, mxIsComplex\nC\nC .. Scalar parameters used by SLICOT subroutines ..\n CHARACTER CONV, INDI, SCR, SICO, WGHT, WIND\n INTEGER INFO, N\n DOUBLE PRECISION DT\nC\nC .. Allocatable arrays ..\nC !Fortran 90/95 (Fixed dimensions should be used with Fortran 77.)\n DOUBLE PRECISION, ALLOCATABLE :: A(:), B(:), DWORK(:), W(:),\n $ XI(:), XR(:)\nC\nC .. Local variables and constant dimension arrays ..\n CHARACTER*120 TEXT\n INTEGER I, IJOB, IP, IPAD, IWIN, JOB, LA, M, NZ\n DOUBLE PRECISION DUM(1), TEMP\nC\nC .. External subroutines ..\n EXTERNAL DCOPY, DE01OD, DE01PD, DF01MD, DG01MD, DG01ND,\n $ DG01OD, DK01MD, DSCAL\nC\nC .. Intrinsic functions ..\n INTRINSIC ABS, DBLE, MAX, MIN\nC\nC Check for proper number of arguments.\nC\n IF ( NRHS.LT.2 ) THEN\n CALL mexErrMsgTxt\n $ ( 'DATANA requires at least 2 input arguments' )\n ELSE IF ( NLHS.LT.1 ) THEN\n CALL mexErrMsgTxt\n $ ( 'DATANA requires at least 1 output argument' )\n END IF\nC\nC job, A(n), (B(n)) (,T) (,window) (,pad0).\nC\n M = mxGetM( PRHS(2) )\n N = mxGetN( PRHS(2) )\n I = MIN( M, N )\n N = MAX( M, N )\n M = I\nC\n IF ( mxGetM( PRHS(1) ).NE.1 .OR.\n $ mxGetN( PRHS(1) ).NE.1 ) THEN\n CALL mexErrMsgTxt( 'JOB must be a scalar' )\n END IF\n IF ( mxIsNumeric( PRHS(1) ).EQ.0 .OR.\n $ mxIsComplex( PRHS(1) ).EQ.1 ) THEN\n CALL mexErrMsgTxt( 'JOB must be an integer scalar' )\n END IF\n CALL mxCopyPtrToReal8( mxGetPr( PRHS(1) ), TEMP, 1 )\n JOB = TEMP\n IJOB = ABS( JOB )\n IF ( JOB.LT.-6 ) THEN\n CALL mexErrMsgTxt\n $ ( 'JOB must be larger than or equal to -6' )\n ELSE IF ( JOB.GT.7 ) THEN\n CALL mexErrMsgTxt\n $ ( 'JOB must be less than or equal to 7' )\n END IF\nC\nC Recheck for proper number of arguments.\nC\n IF ( ( IJOB.EQ.1 .OR. IJOB.EQ.2 .OR. IJOB.EQ.4 .OR. IJOB.EQ.5 )\n $ .AND. NRHS.LT.3 ) THEN\n CALL mexErrMsgTxt\n $ ( 'DATANA requires at least 3 input arguments' )\n END IF\n IF ( ( IJOB.EQ.4 .OR. IJOB.EQ.5 ) .AND. NLHS.LT.2 ) THEN\n CALL mexErrMsgTxt\n $ ( 'DATANA requires 2 output arguments' )\n END IF\nC\n IF ( ( mxIsNumeric( PRHS(2) ).EQ.0 .OR.\n $ mxIsComplex( PRHS(2) ).EQ.1 ) .OR. M.NE.1 ) THEN\n IF ( IJOB.EQ.4 .OR. IJOB.EQ.5 ) THEN\n CALL mexErrMsgTxt( 'XR must be a real vector' )\n ELSE\n CALL mexErrMsgTxt( 'A must be a real vector' )\n END IF\n END IF\nC\n IP = 3\n IF ( IJOB.EQ.1 .OR. IJOB.EQ.2 ) THEN\n IF ( mxIsNumeric( PRHS(3) ).EQ.0 .OR.\n $ mxIsComplex( PRHS(3) ).EQ.1 ) THEN\n CALL mexErrMsgTxt( 'B must be a real vector' )\n END IF\n IF ( MAX( mxGetM( PRHS(3) ), mxGetN( PRHS(3) ) ).NE.N .AND.\n $ MIN( mxGetM( PRHS(3) ), mxGetN( PRHS(3) ) ).NE.1 ) THEN\n CALL mexErrMsgTxt( 'B must have the same size as A' )\n END IF\n IP = 4\nC\n ELSE IF ( IJOB.EQ.4 .OR. IJOB.EQ.5 ) THEN\n IF ( mxIsNumeric( PRHS(3) ).EQ.0 .OR.\n $ mxIsComplex( PRHS(3) ).EQ.1 ) THEN\n CALL mexErrMsgTxt( 'XI must be a real vector' )\n END IF\n IF ( MAX( mxGetM( PRHS(3) ), mxGetN( PRHS(3) ) ).NE.N .AND.\n $ MIN( mxGetM( PRHS(3) ), mxGetN( PRHS(3) ) ).NE.1 ) THEN\n CALL mexErrMsgTxt( 'XI must have the same size as XR' )\n END IF\n IP = 4\nC\n ELSE IF ( IJOB.EQ.3 ) THEN\n IF ( NRHS.GE.3 ) THEN\nC\nC T\nC\n IF ( mxGetM( PRHS(3) ).NE.1 .OR.\n $ mxGetN( PRHS(3) ).NE.1 ) THEN\n CALL mexErrMsgTxt( 'T must be a scalar' )\n END IF\n IF ( mxIsNumeric( PRHS(3) ).EQ.0 .OR.\n $ mxIsComplex( PRHS(3) ).EQ.1 ) THEN\n CALL mexErrMsgTxt( 'T must be a real scalar' )\n END IF\n CALL mxCopyPtrToReal8( mxGetPr( PRHS(3) ), DT, 1 )\n IP = IP + 1\n ELSE\n DT = ONE\n END IF\nC\n ELSE IF ( JOB.EQ.7 ) THEN\n IF ( NRHS.EQ.3 ) THEN\nC\nC window\nC\n IF ( mxGetM( PRHS(3) ).NE.1 .OR.\n $ mxGetN( PRHS(3) ).NE.1 ) THEN\n CALL mexErrMsgTxt( 'WINDOW must be a scalar' )\n END IF\n IF ( mxIsNumeric( PRHS(3) ).EQ.0 .OR.\n $ mxIsComplex( PRHS(3) ).EQ.1 ) THEN\n CALL mexErrMsgTxt( 'WINDOW must be an integer scalar' )\n END IF\n CALL mxCopyPtrToReal8( mxGetPr( PRHS(3) ), TEMP, 1 )\n IWIN = TEMP\n IF ( IWIN.LT.0 .OR. IWIN.GT.3 ) THEN\n CALL mexErrMsgTxt\n $ ( 'WINDOW has 1, 2, or 3 the only admissible values' )\n END IF\n ELSE\n IWIN = 1\n END IF\n END IF\nC\n IF ( JOB.NE.7 .AND. NRHS.GE.IP ) THEN\nC\nC pad0\nC\n IF ( mxGetM( PRHS(IP) ).NE.1 .OR.\n $ mxGetN( PRHS(IP) ).NE.1 ) THEN\n CALL mexErrMsgTxt( 'PAD0 must be a scalar' )\n END IF\n IF ( mxIsNumeric( PRHS(IP) ).EQ.0 .OR.\n $ mxIsComplex( PRHS(IP) ).EQ.1 ) THEN\n CALL mexErrMsgTxt( 'PAD0 must be an integer scalar' )\n END IF\n CALL mxCopyPtrToReal8( mxGetPr( PRHS(IP) ), TEMP, 1 )\n IPAD = TEMP\n IF ( IPAD.LT.0 .OR. IPAD.GT.1 ) THEN\n CALL mexErrMsgTxt\n $ ( 'PAD0 has 0 or 1 the only admissible values' )\n END IF\n ELSE\n IPAD = 0\n END IF\nC\n IF ( IJOB.EQ.1 .OR. IJOB.EQ.2 ) THEN\n IF ( JOB.LT.0 ) THEN\n CONV = 'D'\n ELSE\n CONV = 'C'\n END IF\n IF ( IJOB.EQ.2 )\n $ WGHT = 'N'\n ELSE IF ( IJOB.EQ.3 ) THEN\n IF ( JOB.LT.0 ) THEN\n SICO = 'S'\n ELSE\n SICO = 'C'\n END IF\n ELSE IF ( IJOB.EQ.4 .OR. IJOB.EQ.5 ) THEN\n IF ( JOB.LT.0 ) THEN\n INDI = 'I'\n ELSE\n INDI = 'D'\n END IF\n IF ( JOB.EQ.-5 )\n $ N = N - 1\nC\n ELSE IF ( IJOB.EQ.6 ) THEN\n IF ( JOB.LT.0 ) THEN\n SCR = 'I'\n ELSE\n SCR = 'O'\n END IF\n WGHT = 'N'\n ELSE IF ( IJOB.EQ.0 ) THEN\n SCR = 'N'\n WGHT = 'N'\nC\n ELSE IF ( JOB.EQ.7 ) THEN\n IF ( IWIN.EQ.1 ) THEN\n WIND = 'M'\n ELSE IF ( IWIN.EQ.2 ) THEN\n WIND = 'N'\n ELSE\n WIND = 'Q'\n END IF\n END IF\nC\nC Determine the lenghts of working arrays.\nC First check if for job <> 7, n is power of 2, n = 2^m\nC (or 2^m+1, for |job| = 3).\nC\n IF ( IJOB.LT.7 ) THEN\n I = 1\n M = 0\n IF ( N.GT.1 ) THEN\nC WHILE 2**M < N DO\n 10 CONTINUE\n I = I*2\n M = M + 1\n IF ( I.LT.N )\n $ GO TO 10\nC END WHILE 10\n END IF\n IF ( I.GT.N ) THEN\n IF ( IPAD.EQ.1 ) THEN\n IF ( IJOB.EQ.3 ) THEN\n IF ( I/2 + 1.NE.N ) THEN\n LA = I + 1\n ELSE\n LA = N\n END IF\n ELSE\n LA = I\n END IF\n ELSE\n IF ( IJOB.EQ.3 ) THEN\n N = I/2 + 1\n ELSE\n N = I/2\n END IF\n LA = N\n END IF\n ELSE\n IF ( IJOB.EQ.3 ) THEN\n IF ( IPAD.EQ.1 ) THEN\n LA = I + 1\n ELSE\n N = I/2 + 1\n LA = N\n END IF\n ELSE\n LA = N\n END IF\n END IF\n NZ = LA - N\n IF ( JOB.EQ.-5 .AND. NZ.GT.0 )\n $ NZ = NZ - 1\n ELSE\n NZ = 0\n END IF\nC\nC Allocate variable dimension local arrays.\nC !Fortran 90/95\nC\n IF ( IJOB.EQ.3 .AND. LA.LT.5 ) THEN\n CALL mexErrMsgTxt( 'N must be at least 5' )\n ELSE IF ( ( IJOB.EQ.1 .OR. IJOB.EQ.4 .OR. IJOB.EQ.5 ) .AND.\n $ LA.LT.2 ) THEN\n CALL mexErrMsgTxt( 'N must be at least 2' )\n ELSE IF ( JOB.EQ.7 .AND. N.LT.1 ) THEN\n CALL mexErrMsgTxt( 'N must be at least 1' )\n END IF\nC\n IF ( IJOB.EQ.1 ) THEN\n ALLOCATE ( A( LA ), B( LA ) )\n ELSE IF ( IJOB.EQ.2 ) THEN\n ALLOCATE ( A( LA ), B( LA ), W( LA-M ) )\n ELSE IF ( IJOB.EQ.3 ) THEN\n ALLOCATE ( A( LA ), DWORK( LA+1 ) )\n ELSE IF ( IJOB.EQ.4 ) THEN\n ALLOCATE ( XI( LA ), XR( LA ) )\n ELSE IF ( IJOB.EQ.5 ) THEN\n ALLOCATE ( XI( LA+1 ), XR( LA+1 ) )\n ELSE IF ( IJOB.EQ.6 .OR. IJOB.EQ.0 ) THEN\n ALLOCATE ( A( LA ), W( LA-M ) )\n ELSE\n ALLOCATE ( A( N ) )\n END IF\nC\nC Copy inputs from MATLAB workspace to locally allocated arrays.\nC\n M = N\n IF ( JOB.EQ.-5 )\n $ M = N + 1\n IF ( IJOB.LE.3 .OR. IJOB.GE.6 ) THEN\n CALL mxCopyPtrToReal8( mxGetPr( PRHS(2) ), A, N )\n ELSE\n CALL mxCopyPtrToReal8( mxGetPr( PRHS(2) ), XR, M )\n CALL mxCopyPtrToReal8( mxGetPr( PRHS(3) ), XI, M )\n END IF\n IF ( IJOB.EQ.1 .OR. IJOB.EQ.2 ) THEN\n CALL mxCopyPtrToReal8( mxGetPr( PRHS(3) ), B, N )\n END IF\nC\n IF ( NZ.GT.0 ) THEN\nC\nC Pad the trailing part with zero and reset N.\nC\n DUM(1) = ZERO\n IF ( IJOB.LE.3 .OR. IJOB.GE.6 ) THEN\n CALL DCOPY( NZ, DUM(1), 0, A(N+1), 1 )\n ELSE\n CALL DCOPY( NZ, DUM(1), 0, XR(M+1), 1 )\n CALL DCOPY( NZ, DUM(1), 0, XI(M+1), 1 )\n END IF\n IF ( IJOB.LE.2 ) THEN\n CALL DCOPY( NZ, DUM(1), 0, B(N+1), 1 )\n END IF\n N = LA\n END IF\n M = N\n IF ( JOB.EQ.5 )\n $ M = N + 1\nC\nC Do the actual computations.\nC\n IF ( IJOB.EQ.1 ) THEN\n CALL DE01OD( CONV, N, A, B, INFO )\n ELSE IF ( IJOB.EQ.2 ) THEN\n CALL DE01PD( CONV, WGHT, N, A, B, W, INFO )\n ELSE IF ( IJOB.EQ.3 ) THEN\n CALL DF01MD( SICO, N, DT, A, DWORK, INFO )\n ELSE IF ( IJOB.EQ.4 ) THEN\n CALL DG01MD( INDI, N, XR, XI, INFO )\n IF ( JOB.LT.0 ) THEN\n TEMP = ONE/DBLE( N )\n CALL DSCAL( N, TEMP, XR, 1 )\n CALL DSCAL( N, TEMP, XI, 1 )\n END IF\n ELSE IF ( IJOB.EQ.5 ) THEN\n CALL DG01ND( INDI, N, XR, XI, INFO )\n IF ( JOB.LT.0 ) THEN\n TEMP = ONE/DBLE( 2*N )\n CALL DSCAL( N, TEMP, XR, 1 )\n CALL DSCAL( N, TEMP, XI, 1 )\n END IF\n ELSE IF ( IJOB.EQ.6 .OR. IJOB.EQ.0 ) THEN\n CALL DG01OD( SCR, WGHT, N, A, W, INFO )\n ELSE\n CALL DK01MD( WIND, N, A, INFO )\n END IF\nC\nC Copy output to MATLAB workspace.\nC\n IF ( IJOB.LE.3 .OR. IJOB.GE.6 ) THEN\n PLHS(1) = mxCreateDoubleMatrix( N, 1, 0 )\n CALL mxCopyReal8ToPtr( A, mxGetPr( PLHS(1) ), N )\n ELSE\n PLHS(1) = mxCreateDoubleMatrix( M, 1, 0 )\n CALL mxCopyReal8ToPtr( XR, mxGetPr( PLHS(1) ), M )\n PLHS(2) = mxCreateDoubleMatrix( M, 1, 0 )\n CALL mxCopyReal8ToPtr( XI, mxGetPr( PLHS(2) ), M )\n END IF\nC\nC Deallocate local arrays.\nC !Fortran 90/95\nC\n IF ( IJOB.EQ.1 ) THEN\n DEALLOCATE ( A, B )\n ELSE IF ( IJOB.EQ.2 ) THEN\n DEALLOCATE ( A, B, W )\n ELSE IF ( IJOB.EQ.3 ) THEN\n DEALLOCATE ( A, DWORK )\n ELSE IF ( IJOB.EQ.4 .OR. IJOB.EQ.5 ) THEN\n DEALLOCATE ( XI, XR )\n ELSE IF ( IJOB.EQ.6 .OR. IJOB.EQ.0 ) THEN\n DEALLOCATE ( A, W )\n ELSE\n DEALLOCATE ( A )\n END IF\nC\nC Error and warning handling.\nC\n IF ( INFO.NE.0 ) THEN\n IF ( IJOB.EQ.1 ) THEN\n WRITE( TEXT, '('' INFO = '',I4,'' ON EXIT FROM DE01OD'')'\n $ ) INFO\n ELSE IF ( IJOB.EQ.2 ) THEN\n WRITE( TEXT, '('' INFO = '',I4,'' ON EXIT FROM DE01PD'')'\n $ ) INFO\n ELSE IF ( IJOB.EQ.3 ) THEN\n WRITE( TEXT, '('' INFO = '',I4,'' ON EXIT FROM DF01MD'')'\n $ ) INFO\n ELSE IF ( IJOB.EQ.4 ) THEN\n WRITE( TEXT, '('' INFO = '',I4,'' ON EXIT FROM DG01MD'')'\n $ ) INFO\n ELSE IF ( IJOB.EQ.5 ) THEN\n WRITE( TEXT, '('' INFO = '',I4,'' ON EXIT FROM DG01ND'')'\n $ ) INFO\n ELSE IF ( IJOB.EQ.6 .OR. IJOB.EQ.0 ) THEN\n WRITE( TEXT, '('' INFO = '',I4,'' ON EXIT FROM DG01OD'')'\n $ ) INFO\n ELSE\n WRITE( TEXT, '('' INFO = '',I4,'' ON EXIT FROM DK01MD'')'\n $ ) INFO\n END IF\n CALL mexErrMsgTxt( TEXT )\n END IF\nC\n RETURN\nC *** Last line of DATANA ***\n END\n", "meta": {"hexsha": "9049be6ff9200238cb27408d36aa21ba93cee617", "size": 19173, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "mex_src/datana.f", "max_stars_repo_name": "SLICOT/SLICOT-BasicControl", "max_stars_repo_head_hexsha": "f8a1715a56fe5503347da61e57c2d97e9dd08cee", "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": "mex_src/datana.f", "max_issues_repo_name": "SLICOT/SLICOT-BasicControl", "max_issues_repo_head_hexsha": "f8a1715a56fe5503347da61e57c2d97e9dd08cee", "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": "mex_src/datana.f", "max_forks_repo_name": "SLICOT/SLICOT-BasicControl", "max_forks_repo_head_hexsha": "f8a1715a56fe5503347da61e57c2d97e9dd08cee", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-27T09:49:32.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-27T09:49:32.000Z", "avg_line_length": 34.7967332123, "max_line_length": 72, "alphanum_fraction": 0.4935064935, "num_tokens": 6123, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9294404096760998, "lm_q2_score": 0.7341195385342971, "lm_q1q2_score": 0.6823203646465464}} {"text": " real function SERFI (X)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nC--S replaces \"?\": ?ERFI, ?ERFCI, ?ERFIX, ?ERM1\nc>> 1998-11-01 SERFI Krogh Removed some equivalence for \"mangle\".\nc>> 1996-06-18 SERFI Krogh Changes to use .C. and C%%. J not changed.\nc>> 1996-03-30 SERFI Krogh Added external statements.\nC>> 1995-11-28 SERFI Krogh Removed multiple entries.\nC>> 1995-11-03 SERFI Krogh Removed blanks in numbers for C conversion.\nC>> 1994-10-20 SERFI Krogh Changes to use M77CON\nC>> 1994-04-20 SERFI CLL Edited type stmts to make DP & SP files similar\nC>> 1987-10-29 SERFI Snyder Initial code.\nc\nc For -1.0 .LT. X .LT. 1.0 calculate the inverse of the error\nc function. That is, X = ERF(ERFI).\nc\nc For 0.0 .LT. X .LT. 2.0 calculate the inverse of the\nc complementary error function. that is, X = ERFC(ERFCI). This\nc calculation is carried out by invoking the alternate entry *ERFCI.\nc\nc If X is out of range, program execution is terminated by calling\nc the error message processor.\nc\nc This subprogram uses approximations due to A. Strecok from\nc Mathematics of Computation 22, (1968) pp 144-158.\nc\n external SERFIX\n real SERFIX\n real X\n real ARG, D(6), FSIGN, S\n integer J\nc\nc ***** Parameters *****************************************\nc\nc MAX... is the position in C of the last coefficient of a Chebyshev\nc polynomial expansion.\nc MIN... is the position in C of the first coefficient of a Chebyshev\nc polynomial expansion.\nc NC is the upper dimension of the array of coefficients.\nc NDELTA is the number of coefficients of the Chebyshev polynomial\nc expansion used to approximate R(X) in the range\nc 0.9975 .LT. X .LE. 1-5.0E-16\nc NLAMDA is the number of coefficients of the Chebyshev polynomial\nc expansion used to approximate R(X) in the range\nc 0.8 .LT. X .LE. 0.9975.\nc NMU is the number of coefficients of the Chebyshev polynomial\nc expansion used to approximate R(X) in the range\nc 5.0E-16 .GT. 1-X .GE. 1.E-300.\nc NXI is the number of coefficients of the Chebyshev polynomial\nc expansion used to approximate SERFCI(X)/X in the\nc range 0.0 .LE. X .LE. 0.8.\nc\nc\nc ***** External References ********************************\nc\nc R1MACH Provides the round-off level. Used to calculate the number\nc of coefficients to retain in each Chebyshev expansion.\nc SERM1 Prints an error message and stops if X .LE. -1.0 or\nc X .GE. 1.0 (ERFI) or X .LE. 0.0 or X .GE. 2.0 (ERFCI).\nc LOG Calculates the natural logarithm.\nc SQRT Calculates the square root.\nc\nc\nc ***** Local Variables ***********************************\nc\nc ARG If ERFI or ERFCI is being approximated by a Chebyshev\nc expansion then ARG is the argument of ERFI or the argument\nc that would be used if ERFCI(X) were computed as ERFC(1-X),\nc that is, ARG = X if ERFI is being computed, or ARG = 1-X if\nc ERFCI is being computed. If ERFI or ERFCI is being computed\nc using the initial approximation ERFI=SQRT(-LOG((1-X)*(1+X))),\nc then ARG is that initial approximation.\nc C contains the coefficients of polynomial expansions. They are\nc stored in C in the order DELTA(0..37), LAMDA(0..26),\nc MU(0..25), XI(0..38).\nc D are used to scale the argument of the Chebyshev polynomial\nc expansion in the range 1.E-300 .LT. 1-X .LT. 0.2.\nc DELTA are coefficients of the Chebyshev polynomial expansion of R(X)\nc for 0.9975 .LT. X .LE. 1-5.0E-16.\nc FIRST is a logical SAVE variable indicating whether it is necessary\nc to calculate the number of coefficients to use for each\nc Chebyshev expansion.\nc FSIGN is X or 1.0 - X. It is used to remember the sign to be\nc assigned to the function value.\nc I, J are used as indices.\nc IMIN is the minimum index of a coefficient in the Chebyshev\nc polynomial expansion to be used.\nc JIX is an array containing MINXI, MAXXI, MINLAM, MAXLAM, MINDEL,\nc MAXDEL, MINMU, MAXMU in locations -1..6\nc LAMDA are coefficients of the Chebyshev polynomial expansion of R(X)\nc for 0.8 .LT. X .LE. 0.9975.\nc MU are coefficients of the Chebyshev polynomial expansion of R(X)\nc for 5.0E-16 .GT. 1-X .GE. 1.E-300.\nc S2 is 2.0 * S.\nc S is the argument of the Chebyshev polynomial expansion.\nc W1..W3 are adjacent elements of the recurrence used to evaluate the\nc Chebyshev polynomial expansion.\nc XI are coefficients of the Chebyshev polynomial expansion of\nc ERFC(X)/X for 0.0 .LE. X .LE. 0.8.\nc\n data D /-1.548813042373261659512742E0\n 2, 2.565490123147816151928163E0\n 3, -.5594576313298323225436913E0\n 4, 2.287915716263357638965891E0\n 5, -9.199992358830151031278420E0\n 6, 2.794990820124599493768426E0/\nc\n fsign = x\n arg = abs(x)\n if (arg.lt.0.0e0 .or. arg.ge.1.0e0)then\n call serm1 ('SERFI',1,2,'Argument out of range','X',x,'.')\nc In case the error level is shifted to zero by the caller:\n serfi = 0.0e0\n return\n end if\n if (arg.eq.0.0e0) then\n serfi = 0.0e0\n return\n end if\n if (arg.le.0.8e0) then\n s = 3.125e0*arg*arg - 1.0e0\n j = -1\n else\n if (arg.le.0.9975e0) then\n j = 1\n else\n j = 3\n end if\n arg = sqrt(-log((1.0e0-arg)*(1.0e0+arg)))\n s = d(j)*arg + d(j+1)\n end if\n SERFI = sign(arg*SERFIX(s, j), fsign)\n return\n end\nc\nc ***** entry ERFCI ****************************************\nc\n real function SERFCI(X)\nc Calculate the inverse of the complementary error function.\nc\n external SERFIX\n real SERFIX\n real X\n real ARG, D(6), FSIGN, S\n integer J\n data D /-1.548813042373261659512742E0\n 2, 2.565490123147816151928163E0\n 3, -.5594576313298323225436913E0\n 4, 2.287915716263357638965891E0\n 5, -9.199992358830151031278420E0\n 6, 2.794990820124599493768426E0/\nc\nc Decide which approximation to use, and calculate the argument of\nc the Chebyshev polynomial expansion.\nc\n if (x.le.0.0e0 .or. x.ge.2.0e0) then\n call serm1('SERFCI',1,2,'Argument out of range','X',x,'.')\nc In case the error level is shifted to zero by the caller:\n serfci = 0.0e0\n end if\n if (x.eq.1.0e0) then\n serfci = 0.0e0\n return\n end if\n fsign = 1.0e0 - x\n arg = abs(fsign)\n if (arg.le.0.8e0) then\n s = 3.125e0*arg*arg - 1.0e0\n j = -1\n else\n arg = 2.0e0 - x\n if (x.lt.1.0e0) then\n s = x\n else\n s = arg\n end if\n arg = sqrt(-log(x*arg))\n if (s.lt.5.0e-16) then\n j = 5\n s = d(5)/sqrt(arg) + d(6)\n else\n if (s.ge.0.0025e0) then\n j = 1\n else if (s.ge.5.0e-16) then\n j = 3\n end if\n s = d(j)*arg + d(j+1)\n end if\n end if\n SERFCI = sign(arg*SERFIX(s, j), fsign)\n return\n end\nc\n real function SERFIX(S, J)\nc Subroutine where most of calculations are done.\n external R1MACH\n integer MAXDEL, MAXLAM, MAXMU, MAXXI, MINDEL, MINLAM\n integer MINMU, MINXI, NC, NDELTA, NLAMDA, NMU, NXI\n parameter (MINDEL = 0)\n parameter (NDELTA = 37)\n parameter (MAXDEL = MINDEL + NDELTA)\n parameter (MINLAM = MAXDEL + 1)\n parameter (NLAMDA = 26)\n parameter (MAXLAM = MINLAM + NLAMDA)\n parameter (MINMU = MAXLAM + 1)\n parameter (NMU = 25)\n parameter (MAXMU = MINMU + NMU)\n parameter (MINXI = MAXMU + 1)\n parameter (NXI = 38)\n parameter (MAXXI = MINXI + NXI)\n parameter (NC = MAXXI)\n real R1MACH\n real C(0:NC)\n logical FIRST\n save FIRST\n integer I, J, JIX(-1:6)\n save JIX\n integer IMIN\n real S, S2\n real W1, W2, W3\nc\nc ***** Equivalence Statements *****************************\nc\nc Equivalence statements connecting arrays DELTA, LAMDA, MU, XI removed\nc by FTK to make \"mangle\" work. All references to these arrays have\nc been replaced by references to C.\nc\nc ***** Data Statements ************************************\nc\nc DELTA(J), J = 0..NDELTA, then\nc LAMDA(J), J = 0..NLAMDA, then\nc MU(J), J = 0..NMU, then\nc XI(J), J = 0..NXI\nc\nc++ With first index 0, save data by elements if ~.C.\n data C(0) / .9566797090204925274526373E0 /\n data C(1) / -.0231070043090649036999908E0 /\n data C(2) / -.0043742360975084077333218E0 /\n data C(3) / -.0005765034226511854809364E0 /\n data C(4) / -.0000109610223070923931242E0 /\n data C(5) / .0000251085470246442787982E0 /\n data C(6) / .0000105623360679477511955E0 /\n data C(7) / .0000027544123300306391503E0 /\n data C(8) / .0000004324844983283380689E0 /\n data C(9) / -.0000000205303366552086916E0 /\n data C(10) / -.0000000438915366654316784E0 /\n data C(11) / -.0000000176840095080881795E0 /\n data C(12) / -.0000000039912890280463420E0 /\n data C(13) / -.0000000001869324124559212E0 /\n data C(14) / .0000000002729227396746077E0 /\n data C(15) / .0000000001328172131565497E0 /\n data C(16) / .0000000000318342484482286E0 /\n data C(17) / .0000000000016700607751926E0 /\n data C(18) / -.0000000000020364649611537E0 /\n data C(19) / -.0000000000009648468127965E0 /\n data C(20) / -.0000000000002195672778128E0 /\n data C(21) / -.0000000000000095689813014E0 /\n data C(22) / .0000000000000137032572230E0 /\n data C(23) / .0000000000000062538505417E0 /\n data C(24) / .0000000000000014584615266E0 /\n data C(25) / .0000000000000001078123993E0 /\n data C(26) / -.0000000000000000709229988E0 /\n data C(27) / -.0000000000000000391411775E0 /\n data C(28) / -.0000000000000000111659209E0 /\n data C(29) / -.0000000000000000015770366E0 /\n data C(30) / .0000000000000000002853149E0 /\n data C(31) / .0000000000000000002716662E0 /\n data C(32) / .0000000000000000000957770E0 /\n data C(33) / .0000000000000000000176835E0 /\n data C(34) / -.0000000000000000000009828E0 /\n data C(35) / -.0000000000000000000020464E0 /\n data C(36) / -.0000000000000000000008020E0 /\n data C(37) / -.0000000000000000000001650E0 /\n data C(38) / .9121588034175537733059200E0 /\n data C(39) / -.0162662818676636958546661E0 /\n data C(40) / .0004335564729494453650589E0 /\n data C(41) / .0002144385700744592065205E0 /\n data C(42) / .0000026257510757648130176E0 /\n data C(43) / -.0000030210910501037969912E0 /\n data C(44) / -.0000000124060618367572157E0 /\n data C(45) / .0000000624066092999917380E0 /\n data C(46) / -.0000000005401247900957858E0 /\n data C(47) / -.0000000014232078975315910E0 /\n data C(48) / .0000000000343840281955305E0 /\n data C(49) / .0000000000335848703900138E0 /\n data C(50) / -.0000000000014584288516512E0 /\n data C(51) / -.0000000000008102174258833E0 /\n data C(52) / .0000000000000525324085874E0 /\n data C(53) / .0000000000000197115408612E0 /\n data C(54) / -.0000000000000017494333828E0 /\n data C(55) / -.0000000000000004800596619E0 /\n data C(56) / .0000000000000000557302987E0 /\n data C(57) / .0000000000000000116326054E0 /\n data C(58) / -.0000000000000000017262489E0 /\n data C(59) / -.0000000000000000002784973E0 /\n data C(60) / .0000000000000000000524481E0 /\n data C(61) / .0000000000000000000065270E0 /\n data C(62) / -.0000000000000000000015707E0 /\n data C(63) / -.0000000000000000000001475E0 /\n data C(64) / .0000000000000000000000450E0 /\n data C(65) / .9885750640661893136460358E0 /\n data C(66) / .0108577051845994776160281E0 /\n data C(67) / -.0017511651027627952494825E0 /\n data C(68) / .0000211969932065633437984E0 /\n data C(69) / .0000156648714042435087911E0 /\n data C(70) / -.0000005190416869103124261E0 /\n data C(71) / -.0000000371357897426717780E0 /\n data C(72) / .0000000012174308662357429E0 /\n data C(73) / -.0000000001768115526613442E0 /\n data C(74) / -.0000000000119372182556161E0 /\n data C(75) / .0000000000003802505358299E0 /\n data C(76) / -.0000000000000660188322362E0 /\n data C(77) / -.0000000000000087917055170E0 /\n data C(78) / -.0000000000000003506869329E0 /\n data C(79) / -.0000000000000000697221497E0 /\n data C(80) / -.0000000000000000109567941E0 /\n data C(81) / -.0000000000000000011536390E0 /\n data C(82) / -.0000000000000000001326235E0 /\n data C(83) / -.0000000000000000000263938E0 /\n data C(84) / .0000000000000000000005341E0 /\n data C(85) / -.0000000000000000000022610E0 /\n data C(86) / .0000000000000000000009552E0 /\n data C(87) / -.0000000000000000000005250E0 /\n data C(88) / .0000000000000000000002487E0 /\n data C(89) / -.0000000000000000000001134E0 /\n data C(90) / .0000000000000000000000420E0 /\n data C(91) / .9928853766189408231495800E0 /\n data C(92) / .1204675161431044864647846E0 /\n data C(93) / .0160781993420999447257039E0 /\n data C(94) / .0026867044371623158279591E0 /\n data C(95) / .0004996347302357262947170E0 /\n data C(96) / .0000988982185991204409911E0 /\n data C(97) / .0000203918127639944337340E0 /\n data C(98) / .0000043272716177354218758E0 /\n data C(99) / .0000009380814128593406758E0 /\n data C(100) / .0000002067347208683427411E0 /\n data C(101) / .0000000461596991054300078E0 /\n data C(102) / .0000000104166797027146217E0 /\n data C(103) / .0000000023715009995921222E0 /\n data C(104) / .0000000005439284068471390E0 /\n data C(105) / .0000000001255489864097987E0 /\n data C(106) / .0000000000291381803663201E0 /\n data C(107) / .0000000000067949421808797E0 /\n data C(108) / .0000000000015912343331469E0 /\n data C(109) / .0000000000003740250585245E0 /\n data C(110) / .0000000000000882087762421E0 /\n data C(111) / .0000000000000208650897725E0 /\n data C(112) / .0000000000000049488041039E0 /\n data C(113) / .0000000000000011766394740E0 /\n data C(114) / .0000000000000002803855725E0 /\n data C(115) / .0000000000000000669506638E0 /\n data C(116) / .0000000000000000160165495E0 /\n data C(117) / .0000000000000000038382583E0 /\n data C(118) / .0000000000000000009212851E0 /\n data C(119) / .0000000000000000002214615E0 /\n data C(120) / .0000000000000000000533091E0 /\n data C(121) / .0000000000000000000128488E0 /\n data C(122) / .0000000000000000000031006E0 /\n data C(123) / .0000000000000000000007491E0 /\n data C(124) / .0000000000000000000001812E0 /\n data C(125) / .0000000000000000000000439E0 /\n data C(126) / .0000000000000000000000106E0 /\n data C(127) / .0000000000000000000000026E0 /\n data C(128) / .0000000000000000000000006E0 /\n data C(129) / .0000000000000000000000002E0 /\nc\n data FIRST /.TRUE./\nc\n data JIX /MINXI, MAXXI, MINLAM, MAXLAM, MINDEL, MAXDEL\n 1, MINMU, MAXMU/\nc\nc ***** Procedures *****************************************\nc\nc Decide which approximation to use, and calculate the argument of\nc the Chebyshev polynomial expansion.\nc\nc\nc If this is the first call, calculate the degree of each expansion.\nc\n if (first) then\n first = .false.\n s2 = 0.5e0*r1mach(3)\n do 120 imin = -1, 5, 2\n do 110 i = jix(imin), jix(imin+1)\n if (abs(c(i)).lt.s2) then\n jix(imin+1) = i\n go to 120\n end if\n110 continue\n120 continue\n end if\nc\nc Evaluate the Chebyshev polynomial expansion.\nc\n s2 = s + s\n w1 = 0.0e0\n w2 = 0.0e0\n imin = jix(j)\n i = jix(j+1)\n200 w3 = w2\n w2 = w1\n w1 = (s2*w2 - w3) + c(i)\n i = i - 1\n if (i.gt.imin) go to 200\n serfix = (s*w1 - w2) + c(imin)\n return\n end\n", "meta": {"hexsha": "9f172b70d4b3cb6ff09eea6b9e70c26385523ec7", "size": 16636, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/serfi.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/serfi.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/serfi.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": 40.6748166259, "max_line_length": 72, "alphanum_fraction": 0.6106035105, "num_tokens": 5890, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404116305638, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6823203498615329}} {"text": "*> \\brief \\b SSTECT\n*\n* =========== DOCUMENTATION ===========\n*\n* Online html documentation available at\n* http://www.netlib.org/lapack/explore-html/\n*\n* Definition:\n* ===========\n*\n* SUBROUTINE SSTECT( N, A, B, SHIFT, NUM )\n*\n* .. Scalar Arguments ..\n* INTEGER N, NUM\n* REAL SHIFT\n* ..\n* .. Array Arguments ..\n* REAL A( * ), B( * )\n* ..\n*\n*\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*>\n*> SSTECT counts the number NUM of eigenvalues of a tridiagonal\n*> matrix T which are less than or equal to SHIFT. T has\n*> diagonal entries A(1), ... , A(N), and offdiagonal entries\n*> B(1), ..., B(N-1).\n*> See W. Kahan \"Accurate Eigenvalues of a Symmetric Tridiagonal\n*> Matrix\", Report CS41, Computer Science Dept., Stanford\n*> University, July 21, 1966\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in] N\n*> \\verbatim\n*> N is INTEGER\n*> The dimension of the tridiagonal matrix T.\n*> \\endverbatim\n*>\n*> \\param[in] A\n*> \\verbatim\n*> A is REAL array, dimension (N)\n*> The diagonal entries of the tridiagonal matrix T.\n*> \\endverbatim\n*>\n*> \\param[in] B\n*> \\verbatim\n*> B is REAL array, dimension (N-1)\n*> The offdiagonal entries of the tridiagonal matrix T.\n*> \\endverbatim\n*>\n*> \\param[in] SHIFT\n*> \\verbatim\n*> SHIFT is REAL\n*> The shift, used as described under Purpose.\n*> \\endverbatim\n*>\n*> \\param[out] NUM\n*> \\verbatim\n*> NUM is INTEGER\n*> The number of eigenvalues of T less than or equal\n*> to SHIFT.\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee\n*> \\author Univ. of California Berkeley\n*> \\author Univ. of Colorado Denver\n*> \\author NAG Ltd.\n*\n*> \\ingroup single_eig\n*\n* =====================================================================\n SUBROUTINE SSTECT( N, A, B, SHIFT, NUM )\n*\n* -- LAPACK test routine --\n* -- LAPACK is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n*\n* .. Scalar Arguments ..\n INTEGER N, NUM\n REAL SHIFT\n* ..\n* .. Array Arguments ..\n REAL A( * ), B( * )\n* ..\n*\n* =====================================================================\n*\n* .. Parameters ..\n REAL ZERO, ONE, THREE\n PARAMETER ( ZERO = 0.0E0, ONE = 1.0E0, THREE = 3.0E0 )\n* ..\n* .. Local Scalars ..\n INTEGER I\n REAL M1, M2, MX, OVFL, SOV, SSHIFT, SSUN, SUN, TMP,\n $ TOM, U, UNFL\n* ..\n* .. External Functions ..\n REAL SLAMCH\n EXTERNAL SLAMCH\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC ABS, MAX, SQRT\n* ..\n* .. Executable Statements ..\n*\n* Get machine constants\n*\n UNFL = SLAMCH( 'Safe minimum' )\n OVFL = SLAMCH( 'Overflow' )\n*\n* Find largest entry\n*\n MX = ABS( A( 1 ) )\n DO 10 I = 1, N - 1\n MX = MAX( MX, ABS( A( I+1 ) ), ABS( B( I ) ) )\n 10 CONTINUE\n*\n* Handle easy cases, including zero matrix\n*\n IF( SHIFT.GE.THREE*MX ) THEN\n NUM = N\n RETURN\n END IF\n IF( SHIFT.LT.-THREE*MX ) THEN\n NUM = 0\n RETURN\n END IF\n*\n* Compute scale factors as in Kahan's report\n* At this point, MX .NE. 0 so we can divide by it\n*\n SUN = SQRT( UNFL )\n SSUN = SQRT( SUN )\n SOV = SQRT( OVFL )\n TOM = SSUN*SOV\n IF( MX.LE.ONE ) THEN\n M1 = ONE / MX\n M2 = TOM\n ELSE\n M1 = ONE\n M2 = TOM / MX\n END IF\n*\n* Begin counting\n*\n NUM = 0\n SSHIFT = ( SHIFT*M1 )*M2\n U = ( A( 1 )*M1 )*M2 - SSHIFT\n IF( U.LE.SUN ) THEN\n IF( U.LE.ZERO ) THEN\n NUM = NUM + 1\n IF( U.GT.-SUN )\n $ U = -SUN\n ELSE\n U = SUN\n END IF\n END IF\n DO 20 I = 2, N\n TMP = ( B( I-1 )*M1 )*M2\n U = ( ( A( I )*M1 )*M2-TMP*( TMP / U ) ) - SSHIFT\n IF( U.LE.SUN ) THEN\n IF( U.LE.ZERO ) THEN\n NUM = NUM + 1\n IF( U.GT.-SUN )\n $ U = -SUN\n ELSE\n U = SUN\n END IF\n END IF\n 20 CONTINUE\n RETURN\n*\n* End of SSTECT\n*\n END\n", "meta": {"hexsha": "94a26536900c02a79f186872854b5abe35d716f2", "size": 4435, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "TESTING/EIG/sstect.f", "max_stars_repo_name": "sergey-v-kuznetsov/lapack", "max_stars_repo_head_hexsha": "799ef93faa5878aa8702f7cf9980cfc649cc39cc", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 998, "max_stars_repo_stars_event_min_datetime": "2016-05-04T20:50:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T17:43:13.000Z", "max_issues_repo_path": "TESTING/EIG/sstect.f", "max_issues_repo_name": "sergey-v-kuznetsov/lapack", "max_issues_repo_head_hexsha": "799ef93faa5878aa8702f7cf9980cfc649cc39cc", "max_issues_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_issues_count": 603, "max_issues_repo_issues_event_min_datetime": "2016-06-04T07:28:21.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T21:16:50.000Z", "max_forks_repo_path": "TESTING/EIG/sstect.f", "max_forks_repo_name": "sergey-v-kuznetsov/lapack", "max_forks_repo_head_hexsha": "799ef93faa5878aa8702f7cf9980cfc649cc39cc", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 373, "max_forks_repo_forks_event_min_datetime": "2016-06-04T06:05:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T17:25:45.000Z", "avg_line_length": 23.972972973, "max_line_length": 76, "alphanum_fraction": 0.4602029312, "num_tokens": 1294, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122263731811, "lm_q2_score": 0.752012562644147, "lm_q1q2_score": 0.6823101924732623}} {"text": "!*************************************************************************\r\n!* Hyperdual Number Module (HDMod_cplx) of Fortran Codes \r\n!*----------------------------------------------------------------\r\n\r\nModule HDMod_cplx\r\n\r\n use HDMod\r\n implicit none\r\n \r\n public\r\n \r\n integer, parameter :: SP_cplx = KIND(1.0) ! Single Precision\r\n integer, parameter :: DP_cplx = KIND(1.d0) ! Double Precision\r\n integer, parameter :: PRhyd_cplx = DP_cplx ! Set the precision\r\n real(PRhyd_cplx), parameter, private :: pi = ACOS(-1.0_PRhyd) \r\n complex(PRhyd_cplx), parameter, private :: pi_c = (pi, 0.0_PRhyd)\r\n \r\n !--- DEFINITION OF HYPERDUAL TYPE\r\n TYPE hyperdual_cplx\r\n complex(PRhyd) :: x\r\n complex(PRhyd) :: dx1\r\n complex(PRhyd) :: dx2\r\n complex(PRhyd) :: dx1x2\r\n END TYPE\r\n \r\n !================================================================!\r\n ! Overloading hdual functions !\r\n !================================================================!\r\n \r\n !----- Constructor\r\n interface hdual_cplx\r\n module procedure hdual_cplx_from_dble\r\n end interface\r\n \r\n interface assignment(=) \r\n module procedure hdual_cplx_assign_hdual_cplx, hdual_cplx_assign_cplx\r\n end interface\r\n \r\n interface operator(+)\r\n module procedure hdual_cplx_plus_hdual_cplx, hdual_cplx_plus_dble, dble_plus_hdual_cplx, &\r\n hdual_cplx_plus_hdual\r\n end interface\r\n \r\n interface operator(-)\r\n module procedure hdual_cplx_minus_hdual_cplx, hdual_cplx_minus_dble, dble_minus_hdual_cplx, &\r\n minus_hdual_cplx, hdual_cplx_minus_hdual\r\n end interface\r\n \r\n interface operator(*)\r\n module procedure hdual_cplx_mul_hdual_cplx, hdual_cplx_mul_dble, dble_mul_hdual_cplx, &\r\n hdual_mul_hdual_cplx, hdual_cplx_mul_hdual\r\n end interface \r\n \r\n interface operator(/) \r\n module procedure hdual_cplx_div_hdual_cplx, hdual_cplx_div_dble, dble_div_hdual_cplx\r\n end interface \r\n\r\n interface operator(**)\r\n module procedure hdual_cplx_pow_dble\r\n end interface\r\n \r\n interface ABS\r\n module procedure hdual_cplx_abs\r\n end interface\r\n\r\n interface COS\r\n module procedure hdual_cplx_cos\r\n end interface\r\n\r\n interface SIN\r\n module procedure hdual_cplx_sin\r\n end interface\r\n \r\n interface CMPLX\r\n module procedure hdual_cplx_from_hdual, hdual_cplx_tens_from_hdual_tens\r\n end interface\r\n \r\n interface REAL\r\n module procedure real_from_hdual_cplx\r\n end interface \r\n \r\n interface AIMAG\r\n module procedure aimag_from_hdual_cplx\r\n end interface AIMAG\r\n \r\n interface IMAG \r\n module procedure imag_from_hdual_cplx\r\n end interface IMAG\r\n \r\n interface CONJG\r\n module procedure conjg_from_hdual_cplx\r\n end interface\r\n \r\n \r\n CONTAINS\r\n \r\n \r\n function hdual_cplx_from_dble(x11,x12,x21,x22) result(q)\r\n \r\n implicit none\r\n complex(PRhyd_cplx), intent(in) :: x11, x12, x21, x22\r\n TYPE(hyperdual_cplx) :: q\r\n \r\n q%x = x11\r\n q%dx1 = x12\r\n q%dx2 = x21\r\n q%dx1x2 = x22\r\n \r\n end function hdual_cplx_from_dble\r\n \r\n \r\n subroutine hdual_cplx_assign_hdual_cplx(qcplx_left, qcplx_right)\r\n \r\n implicit none\r\n TYPE(hyperdual_cplx), intent(out) :: qcplx_left\r\n TYPE(hyperdual_cplx), intent(in) :: qcplx_right\r\n \r\n qcplx_left%x = qcplx_right%x\r\n qcplx_left%dx1 = qcplx_right%dx1\r\n qcplx_left%dx2 = qcplx_right%dx2\r\n qcplx_left%dx1x2 = qcplx_right%dx1x2\r\n \r\n end subroutine hdual_cplx_assign_hdual_cplx\r\n\r\n\r\n subroutine hdual_cplx_assign_cplx(qcplx_left, cplx_right)\r\n\r\n implicit none\r\n complex(PRhyd_cplx), intent(in) :: cplx_right\r\n TYPE(hyperdual_cplx), intent(out) :: qcplx_left\r\n\r\n qcplx_left%x = cplx_right\r\n qcplx_left%dx1 = 0.0d0\r\n qcplx_left%dx2 = 0.0d0\r\n qcplx_left%dx1x2 = 0.0d0\r\n\r\n end subroutine hdual_cplx_assign_cplx\r\n \r\n \r\n function hdual_cplx_plus_hdual_cplx(qleft, qright) result(res)\r\n \r\n implicit none\r\n TYPE(hyperdual_cplx), intent(in) :: qleft, qright\r\n TYPE(hyperdual_cplx) :: res\r\n \r\n res%x = qleft%x + qright%x\r\n res%dx1 = qleft%dx1 + qright%dx1\r\n res%dx2 = qleft%dx2 + qright%dx2\r\n res%dx1x2 = qleft%dx1x2 + qright%dx1x2\r\n \r\n end function hdual_cplx_plus_hdual_cplx\r\n \r\n \r\n function hdual_cplx_plus_dble(qleft, iright) result(res)\r\n \r\n implicit none \r\n TYPE(hyperdual_cplx), intent(in) :: qleft\r\n real(PRhyd_cplx), intent(in) :: iright\r\n TYPE(hyperdual_cplx) :: res\r\n \r\n res%x = qleft%x + iright\r\n res%dx1 = qleft%dx1 \r\n res%dx2 = qleft%dx2 \r\n res%dx1x2 = qleft%dx1x2 \r\n \r\n end function hdual_cplx_plus_dble\t\r\n \r\n \r\n function dble_plus_hdual_cplx(ileft, qright) result(res)\r\n \r\n implicit none \r\n TYPE(hyperdual_cplx), intent(in) :: qright\r\n real(PRhyd_cplx), intent(in) :: ileft\r\n TYPE(hyperdual_cplx) :: res\r\n \r\n res%x = qright%x + ileft\r\n res%dx1 = qright%dx1 \r\n res%dx2 = qright%dx2 \r\n res%dx1x2 = qright%dx1x2 \r\n \r\n end function dble_plus_hdual_cplx\r\n\r\n\r\n function hdual_cplx_plus_hdual(qcplx, qright) result(res)\r\n\r\n implicit none\r\n TYPE(hyperdual_cplx), intent(in) :: qcplx\r\n TYPE(hyperdual), intent(in) :: qright\r\n TYPE(hyperdual_cplx) :: res\r\n\r\n res%x = qcplx%x + qright%x \r\n res%dx1 = qcplx%dx1 + qright%dx1\r\n res%dx2 = qcplx%dx2 + qright%dx2\r\n res%dx1x2 = qcplx%dx1x2 + qright%dx1x2\r\n\r\n end function hdual_cplx_plus_hdual\r\n \r\n\r\n \r\n function hdual_cplx_minus_hdual_cplx(qleft, qright) result(res)\r\n \r\n implicit none\r\n TYPE(hyperdual_cplx), intent(in) :: qleft, qright\r\n TYPE(hyperdual_cplx) :: res\r\n \r\n res%x = qleft%x - qright%x\r\n res%dx1 = qleft%dx1 - qright%dx1\r\n res%dx2 = qleft%dx2 - qright%dx2\r\n res%dx1x2 = qleft%dx1x2 - qright%dx1x2\r\n \r\n end function hdual_cplx_minus_hdual_cplx\r\n \r\n \r\n function hdual_cplx_minus_dble(qleft, iright) result(res)\r\n \r\n implicit none \r\n TYPE(hyperdual_cplx), intent(in) :: qleft\r\n real(PRhyd_cplx), intent(in) :: iright\r\n TYPE(hyperdual_cplx) :: res\r\n \r\n res%x = qleft%x - iright\r\n res%dx1 = qleft%dx1 \r\n res%dx2 = qleft%dx2 \r\n res%dx1x2 = qleft%dx1x2 \r\n \r\n end function hdual_cplx_minus_dble\t\r\n \r\n \r\n function dble_minus_hdual_cplx(ileft, qright) result(res)\r\n \r\n implicit none\r\n TYPE(hyperdual_cplx), intent(in) :: qright\r\n real(PRhyd_cplx), intent(in) :: ileft\r\n TYPE(hyperdual_cplx) :: res\r\n \r\n res%x = ileft - qright%x\r\n res%dx1 = - qright%dx1\r\n res%dx2 = - qright%dx2\r\n res%dx1x2 = - qright%dx1x2\r\n \r\n end function dble_minus_hdual_cplx\r\n \r\n \r\n function minus_hdual_cplx(qright) result(res)\r\n \r\n implicit none\r\n TYPE(hyperdual_cplx), intent(in) :: qright\r\n TYPE(hyperdual_cplx) :: res\r\n \r\n res%x = - qright%x \r\n res%dx1 = - qright%dx1\r\n res%dx2 = - qright%dx2\r\n res%dx1x2 = - qright%dx1x2\r\n \r\n end function minus_hdual_cplx\r\n \r\n\r\n function hdual_cplx_minus_hdual(qcplx, qright) result(res)\r\n\r\n implicit none\r\n TYPE(hyperdual_cplx), intent(in) :: qcplx\r\n TYPE(hyperdual), intent(in) :: qright\r\n TYPE(hyperdual_cplx) :: res\r\n\r\n res%x = qcplx%x - qright%x \r\n res%dx1 = qcplx%dx1 - qright%dx1\r\n res%dx2 = qcplx%dx2 - qright%dx2\r\n res%dx1x2 = qcplx%dx1x2 - qright%dx1x2\r\n\r\n end function hdual_cplx_minus_hdual\r\n\r\n \r\n function hdual_cplx_mul_hdual_cplx(qleft, qright) result(res)\r\n \r\n implicit none\r\n TYPE(hyperdual_cplx), intent(in) :: qleft, qright\r\n TYPE(hyperdual_cplx) :: res\r\n \r\n res%x = qleft%x * qright%x\r\n res%dx1 = qleft%x * qright%dx1 + qleft%dx1 * qright%x\r\n res%dx2 = qleft%x * qright%dx2 + qleft%dx2 * qright%x\r\n res%dx1x2 = qleft%x * qright%dx1x2 + qleft%dx1 * qright%dx2 + qleft%dx2 * qright%dx1 + qleft%dx1x2 * qright%x\r\n \r\n end function hdual_cplx_mul_hdual_cplx\r\n \r\n \r\n function hdual_cplx_mul_dble(qleft, iright) result(res)\r\n \r\n implicit none\r\n TYPE(hyperdual_cplx), intent(in) :: qleft\r\n real(PRhyd_cplx), intent(in) :: iright\r\n TYPE(hyperdual_cplx) :: res\r\n \r\n res%x = qleft%x * iright\r\n res%dx1 = qleft%dx1 * iright\r\n res%dx2 = qleft%dx2 * iright\r\n res%dx1x2 = qleft%dx1x2 * iright\r\n \r\n end function hdual_cplx_mul_dble\r\n \r\n \r\n function dble_mul_hdual_cplx(ileft, qright) result(res)\r\n \r\n implicit none\r\n TYPE(hyperdual_cplx), intent(in) :: qright\r\n real(PRhyd_cplx), intent(in) :: ileft\r\n TYPE(hyperdual_cplx) :: res\r\n \r\n res%x = qright%x * ileft\r\n res%dx1 = qright%dx1 * ileft\r\n res%dx2 = qright%dx2 * ileft\r\n res%dx1x2 = qright%dx1x2 * ileft\r\n \r\n end function dble_mul_hdual_cplx\r\n\r\n\r\n function hdual_mul_hdual_cplx(qleft, qcplx) result(res)\r\n\r\n ! Hyperdual multiplied by hyperdual complex\r\n ! FOR subroutine BHCOAT in twoway_rrtmg_aero_optical.F\r\n\r\n implicit none\r\n TYPE(hyperdual), intent(in) :: qleft\r\n TYPE(hyperdual_cplx), intent(in) :: qcplx\r\n TYPE(hyperdual_cplx) :: res\r\n\r\n res%x = qleft%x * qcplx%x\r\n res%dx1 = qleft%x * qcplx%dx1 + qleft%dx1 * qcplx%x\r\n res%dx2 = qleft%x * qcplx%dx2 + qleft%dx2 * qcplx%x\r\n res%dx1x2 = qleft%x * qcplx%dx1x2 + qleft%dx1 * qcplx%dx2 + qleft%dx2 * qcplx%dx1 + qleft%dx1x2 * qcplx%x\r\n\r\n\r\n end function hdual_mul_hdual_cplx\r\n\r\n\r\n function hdual_cplx_mul_hdual(qcplx, qright) result(res)\r\n\r\n ! Hyperdual multiplied by hyperdual complex\r\n ! FOR subroutine BHCOAT in twoway_rrtmg_aero_optical.F\r\n\r\n implicit none\r\n TYPE(hyperdual), intent(in) :: qright\r\n TYPE(hyperdual_cplx), intent(in) :: qcplx\r\n TYPE(hyperdual_cplx) :: res\r\n\r\n res%x = qright%x * qcplx%x\r\n res%dx1 = qright%x * qcplx%dx1 + qright%dx1 * qcplx%x\r\n res%dx2 = qright%x * qcplx%dx2 + qright%dx2 * qcplx%x\r\n res%dx1x2 = qright%x * qcplx%dx1x2 + qright%dx1 * qcplx%dx2 + qright%dx2 * qcplx%dx1 + qright%dx1x2 * qcplx%x\r\n\r\n\r\n end function hdual_cplx_mul_hdual\r\n ! DIVISION !\r\n \r\n \r\n function hdual_cplx_div_hdual_cplx(qleft, qright) result(res)\r\n \r\n implicit none\r\n TYPE(hyperdual_cplx), intent(in) :: qleft, qright\r\n \r\n TYPE(hyperdual_cplx) :: inv\r\n TYPE(hyperdual_cplx) :: res\r\n \r\n inv = hdual_cplx_pow_dble(qright, -1.0d0)\r\n res = qleft * inv\r\n \r\n end function hdual_cplx_div_hdual_cplx\r\n \r\n \r\n function hdual_cplx_div_dble(qleft, iright) result(res)\r\n \r\n implicit none\r\n TYPE(hyperdual_cplx), intent(in) :: qleft\r\n real(PRhyd_cplx), intent(in) :: iright\r\n TYPE(hyperdual_cplx) :: res\r\n \r\n res%x = qleft%x / iright\r\n res%dx1 = qleft%dx1 / iright\r\n res%dx2 = qleft%dx2 / iright\r\n res%dx1x2 = qleft%dx1x2 / iright\r\n \r\n end function hdual_cplx_div_dble\r\n \r\n \r\n function dble_div_hdual_cplx(ileft, qright) result(res)\r\n implicit none\r\n TYPE(hyperdual_cplx), intent(in) :: qright\r\n real(PRhyd_cplx), intent(in) :: ileft\r\n TYPE(hyperdual_cplx) :: inv\r\n TYPE(hyperdual_cplx) :: res\r\n \r\n inv = hdual_cplx_pow_dble(qright, -1.0d0)\r\n res = ileft * inv\r\n \r\n end function dble_div_hdual_cplx\r\n \r\n \r\n function hdual_cplx_pow_dble(qleft, iright) result(res)\r\n \r\n implicit none\r\n TYPE(hyperdual_cplx), intent(in) :: qleft\r\n real(PRhyd_cplx), intent(in) :: iright\r\n complex(PRhyd_cplx) :: xval\r\n complex(PRhyd_cplx) :: tol\r\n complex(PRhyd_cplx) :: deriv\r\n TYPE(hyperdual_cplx) :: res\r\n \r\n xval = qleft%x \r\n tol = 1.0e-15\r\n if (abs(real(xval)) < real(tol)) then\r\n \r\n if (real(xval) >= 0) then \r\n xval = tol\r\n endif \r\n \r\n if (real(xval) < 0) then\r\n xval = -tol\r\n endif\r\n \r\n endif \r\n deriv = iright * xval**(iright - 1.0d0)\r\n \r\n res%x = qleft%x**iright\r\n res%dx1 = qleft%dx1 * deriv\r\n res%dx2 = qleft%dx2 * deriv\r\n res%dx1x2 = qleft%dx1x2 * deriv + iright * (iright - 1.0d0) * qleft%dx1 * qleft%dx2 * xval**(iright - 2.0d0)\r\n \r\n end function hdual_cplx_pow_dble\r\n \r\n \r\n function hdual_cplx_abs(qcplx) result(res)\r\n\r\n ! using abs on hyperdual complex\r\n implicit none\r\n TYPE(hyperdual_cplx), intent(in) :: qcplx\r\n TYPE(hyperdual) :: res\r\n\r\n ! Like applying abs on complex(8), the result \r\n ! should be a hyperdual number\r\n res%x = abs(qcplx%x)\r\n res%dx1 = abs(qcplx%dx1)\r\n res%dx2 = abs(qcplx%dx2)\r\n res%dx1x2 = abs(qcplx%dx1x2)\r\n \r\n end function hdual_cplx_abs\r\n\r\n\r\n function hdual_cplx_cos(qcplx) result(res)\r\n \r\n implicit none\r\n TYPE(hyperdual_cplx), intent(in) :: qcplx\r\n complex(PRhyd_cplx) :: funval, deriv\r\n TYPE(hyperdual_cplx) :: res\r\n\r\n funval = cos(qcplx%x)\r\n deriv = -sin(qcplx%x)\r\n\r\n res%x = funval\r\n res%dx1 = deriv * qcplx%dx1\r\n res%dx2 = deriv * qcplx%dx2\r\n res%dx1x2 = -funval * qcplx%dx1 * qcplx%dx2 + deriv * qcplx%dx1x2\r\n\r\n end function hdual_cplx_cos\r\n\r\n\r\n function hdual_cplx_sin(qcplx) result(res)\r\n \r\n implicit none\r\n TYPE(hyperdual_cplx), intent(in) :: qcplx\r\n complex(PRhyd_cplx) :: funval, deriv\r\n TYPE(hyperdual_cplx) :: res\r\n\r\n funval = sin(qcplx%x)\r\n deriv = cos(qcplx%x)\r\n\r\n res%x = funval\r\n res%dx1 = deriv * qcplx%dx1\r\n res%dx2 = deriv * qcplx%dx2\r\n res%dx1x2 = -funval * qcplx%dx1 * qcplx%dx2 + deriv * qcplx%dx1x2\r\n\r\n end function hdual_cplx_sin\r\n \r\n\r\n function hdual_cplx_from_hdual(qreal, qimag) result(qcplx)\r\n \r\n ! Complexify hyperdual numbers using CMPLX\r\n \r\n implicit none\r\n TYPE(hyperdual), intent(in) :: qreal\r\n TYPE(hyperdual), intent(in) :: qimag\r\n TYPE(hyperdual_cplx) :: qcplx\r\n \r\n qcplx%x = CMPLX(qreal%x, qimag%x, KIND=PRhyd_cplx) \r\n qcplx%dx1 = CMPLX(qreal%dx1, qimag%dx1, KIND=PRhyd_cplx)\r\n qcplx%dx2 = CMPLX(qreal%dx2, qimag%dx2, KIND=PRhyd_cplx)\r\n qcplx%dx1x2 = CMPLX(qreal%dx1x2, qimag%dx1x2, KIND=PRhyd_cplx)\r\n \r\n end function hdual_cplx_from_hdual\r\n \r\n \r\n function hdual_cplx_tens_from_hdual_tens(qreal, qimag) result(qcplx)\r\n \r\n ! Complexify hyperdual numbers using CMPLX\r\n \r\n implicit none\r\n TYPE(hyperdual), dimension(:,:,:), intent(in) :: qreal\r\n TYPE(hyperdual), dimension(:,:,:), intent(in) :: qimag\r\n TYPE(hyperdual_cplx), dimension(size(qreal, 1), size(qreal, 2), size(qreal, 3)) :: qcplx\r\n \r\n qcplx%x = CMPLX(qreal%x, qimag%x, KIND=PRhyd_cplx) \r\n qcplx%dx1 = CMPLX(qreal%dx1, qimag%dx1, KIND=PRhyd_cplx)\r\n qcplx%dx2 = CMPLX(qreal%dx2, qimag%dx2, KIND=PRhyd_cplx)\r\n qcplx%dx1x2 = CMPLX(qreal%dx1x2, qimag%dx1x2, KIND=PRhyd_cplx)\r\n \r\n end function hdual_cplx_tens_from_hdual_tens\r\n \r\n \r\n function real_from_hdual_cplx(qcplx) result(qreal)\r\n \r\n ! Extract the real component from hyperdual_cplx\r\n \r\n implicit none\r\n TYPE(hyperdual_cplx), intent(in) :: qcplx\r\n TYPE(hyperdual) :: qreal\r\n \r\n qreal%x = real(qcplx%x)\r\n qreal%dx1 = real(qcplx%dx1)\r\n qreal%dx2 = real(qcplx%dx2)\r\n qreal%dx1x2 = real(qcplx%dx1x2)\r\n \r\n end function real_from_hdual_cplx\r\n \r\n \r\n function aimag_from_hdual_cplx(qcplx) result(qimag)\r\n \r\n ! Extract the real component from hyperdual_cplx\r\n \r\n implicit none\r\n TYPE(hyperdual_cplx), intent(in) :: qcplx\r\n TYPE(hyperdual) :: qimag\r\n \r\n qimag%x = aimag(qcplx%x)\r\n qimag%dx1 = aimag(qcplx%dx1)\r\n qimag%dx2 = aimag(qcplx%dx2)\r\n qimag%dx1x2 = aimag(qcplx%dx1x2)\r\n \r\n end function aimag_From_hdual_cplx\r\n \r\n \r\n function imag_from_hdual_cplx(qcplx) result(qimag)\r\n \r\n ! Extract the real component from hyperdual_cplx\r\n \r\n implicit none\r\n TYPE(hyperdual_cplx), intent(in) :: qcplx\r\n TYPE(hyperdual) :: qimag\r\n \r\n qimag%x = imag(qcplx%x)\r\n qimag%dx1 = imag(qcplx%dx1)\r\n qimag%dx2 = imag(qcplx%dx2)\r\n qimag%dx1x2 = imag(qcplx%dx1x2)\r\n \r\n end function imag_From_hdual_cplx\r\n \r\n \r\n function conjg_from_hdual_cplx(qcplx) result(qconjg)\r\n TYPE(hyperdual_cplx), intent(in) :: qcplx\r\n TYPE(hyperdual_cplx) :: qconjg\r\n \r\n qconjg%x = conjg(qcplx%x)\r\n qconjg%dx1 = conjg(qcplx%dx1)\r\n qconjg%dx2 = conjg(qcplx%dx2)\r\n qconjg%dx1x2 = conjg(qcplx%dx1x2)\r\n \r\n end function conjg_from_hdual_cplx\r\n\r\n\r\n \r\n \r\n end module HDMod_cplx", "meta": {"hexsha": "a4c3507c93b8612739b4520b42d21c086968c055", "size": 18564, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "CCTM/src/util/util/HDMod_cplx.f90", "max_stars_repo_name": "echen-git/echenhydCMAQ", "max_stars_repo_head_hexsha": "0148280d6da841bf208db7840888ca35dd2e34a8", "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": "CCTM/src/util/util/HDMod_cplx.f90", "max_issues_repo_name": "echen-git/echenhydCMAQ", "max_issues_repo_head_hexsha": "0148280d6da841bf208db7840888ca35dd2e34a8", "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": "CCTM/src/util/util/HDMod_cplx.f90", "max_forks_repo_name": "echen-git/echenhydCMAQ", "max_forks_repo_head_hexsha": "0148280d6da841bf208db7840888ca35dd2e34a8", "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.0068965517, "max_line_length": 119, "alphanum_fraction": 0.5457875458, "num_tokens": 5473, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122188543453, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6823101918616861}} {"text": "program main\n use LTISystemClass\n implicit none\n\n type(LTISystem_) :: system\n type(Random_) :: random\n type(IO_) :: file,SpectreFile\n real(real64) :: F(2,2),G(2,1),H(1,2),x(2)\n complex(complex64) :: y(4096)\n complex(complex64),allocatable :: spectre(:),in_spectre(:)\n integer(int32) :: i,j\n\n ! Yule (1927), autoreguressive model\n F(1,:) = [ 0.0d0, -0.65504d0 ]\n F(2,:) = [ 1.0d0, 1.34254d0 ]\n\n G(1:2,1) = [-0.65504d0, 1.34254d0]\n\n H(1,1:2) = [1.0d0, 0.0d0]\n\n x(1) = random%gauss(mu=0.0d0,sigma=1.0d0) \n x(2) = random%gauss(mu=0.0d0,sigma=1.0d0)\n\n call system%init(&\n State=x,&\n StateTransition=F,&\n Driving=G,&\n ObservMat=H)\n system%sigma = 15.41d0\n\n call file%open(\"Observation.txt\")\n\n do i=1,size(y)\n call file%write(i, system%update()+44.333d0 )\n y(i) = system%ObservVec(1) \n if(i>=256)then\n spectre = fft(y(i-255:i) )\n call Spectrefile%open(\"FFT_Result\"//str(i)//\".txt\")\n do j=1,256/2\n call Spectrefile%write(j, dble(sqrt(spectre(j)*spectre(j))) )\n enddo\n \n call Spectrefile%close()\n endif\n enddo\n call file%close()\n \n\n \n \n\n\nend program main", "meta": {"hexsha": "ab08d8c176d42216fb623c4f31bd1ce488980113", "size": 1263, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/std/STIsample.f90", "max_stars_repo_name": "kazulagi/plantFEM", "max_stars_repo_head_hexsha": "20bf2df8202d41aa5dc25d1cc820385dabbc604f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2020-06-21T08:21:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-13T04:28:30.000Z", "max_issues_repo_path": "Tutorial/std/STIsample.f90", "max_issues_repo_name": "kazulagi/plantFEM_binary", "max_issues_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-05-08T05:20:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T05:39:29.000Z", "max_forks_repo_path": "Tutorial/std/STIsample.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": 23.8301886792, "max_line_length": 77, "alphanum_fraction": 0.5360253365, "num_tokens": 462, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122113355092, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6823101912501094}} {"text": " subroutine appft (niter, total_time, verified)\n include 'global.h'\n integer niter\n\t double precision total_time\n\t logical verified\n!\n! Local variables\n!\n integer i, j, k, kt, n12, n22, n32, ii, jj, kk, ii2, ik2\n double precision ap\n double precision twiddle(nx+1,ny,nz)\n \n double complex xnt(nx+1,ny,nz),y(nx+1,ny,nz),\n & pad1(128),pad2(128)\n common /mainarrays/ xnt,pad1,y,pad2,twiddle\n\n double complex exp1(nx), exp2(ny), exp3(nz)\n\n do i=1,15\n call timer_clear(i)\n\t end do \n\n call timer_start(2) \n call compute_initial_conditions(xnt,nx,ny,nz)\n \n call CompExp( nx, exp1 )\n call CompExp( ny, exp2 )\n call CompExp( nz, exp3 ) \n call fftXYZ(1,xnt,y,exp1,exp2,exp3,nx,ny,nz)\n call timer_stop(2) \n\n call timer_start(1)\n if (timers_enabled) call timer_start(13)\n\t \n n12 = nx/2\n n22 = ny/2\n n32 = nz/2\n ap = - 4.d0 * alpha * pi ** 2\n do i = 1, nz\n\t ii = i-1-((i-1)/n32)*nz\n\t ii2 = ii*ii\n do k = 1, ny\n\t kk = k-1-((k-1)/n22)*ny\n\t ik2 = ii2 + kk*kk\n do j = 1, nx\n\t jj = j-1-((j-1)/n12)*nx\n twiddle(j,k,i) = exp(ap*dble(jj*jj + ik2))\n end do\n end do\n end do\n if (timers_enabled) call timer_stop(13) \n \n if (timers_enabled) call timer_start(12)\n call compute_initial_conditions(xnt,nx,ny,nz) \n if (timers_enabled) call timer_stop(12) \n if (timers_enabled) call timer_start(15) \n call fftXYZ(1,xnt,y,exp1,exp2,exp3,nx,ny,nz)\n if (timers_enabled) call timer_stop(15) \n\n do kt = 1, niter\n\t if (timers_enabled) call timer_start(11) \n\t call evolve(xnt,y,twiddle,nx,ny,nz)\n if (timers_enabled) call timer_stop(11) \n if (timers_enabled) call timer_start(15) \n call fftXYZ(-1,xnt,xnt,exp1,exp2,exp3,nx,ny,nz)\n if (timers_enabled) call timer_stop(15) \n if (timers_enabled) call timer_start(10) \n call CalculateChecksum(sums(kt),kt,xnt,nx,ny,nz) \n if (timers_enabled) call timer_stop(10) \n end do\n!\n! Verification test.\n!\n if (timers_enabled) call timer_start(14) \n call verify(nx, ny, nz, niter, sums, verified)\n if (timers_enabled) call timer_stop(14) \n call timer_stop(1)\n\n\t total_time = timer_read(1)\n\t if (.not.timers_enabled) return\n\n\t print*,'FT subroutine timers ' \n write(*,40) 'FT total ', timer_read(1)\n write(*,40) 'WarmUp time ', timer_read(2)\n write(*,40) 'fftXYZ body ', timer_read(3)\n write(*,40) 'Swarztrauber ', timer_read(4)\n write(*,40) 'X time ', timer_read(7)\n write(*,40) 'Y time ', timer_read(8)\n write(*,40) 'Z time ', timer_read(9)\n write(*,40) 'CalculateChecksum ', timer_read(10)\n write(*,40) 'evolve ', timer_read(11)\n write(*,40) 'compute_initial_conditions', timer_read(12)\n write(*,40) 'twiddle ', timer_read(13)\n write(*,40) 'verify ', timer_read(14)\n write(*,40) 'fftXYZ ', timer_read(15)\n write(*,40) 'Benchmark time ', total_time\n 40 format(' ',A26,' =',F9.4)\n\n return\n end\n", "meta": {"hexsha": "a46cf64fe0e7317cb30d4d990479667a24d3dc05", "size": 3663, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "NPB3.0-SER/FT/appft.f", "max_stars_repo_name": "josevnz/NPB3.0-JAV-FORK", "max_stars_repo_head_hexsha": "4d917796d534fab7df30a08c74a756b9a44f38b7", "max_stars_repo_licenses": ["NASA-1.3"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NPB3.0-SER/FT/appft.f", "max_issues_repo_name": "josevnz/NPB3.0-JAV-FORK", "max_issues_repo_head_hexsha": "4d917796d534fab7df30a08c74a756b9a44f38b7", "max_issues_repo_licenses": ["NASA-1.3"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NPB3.0-SER/FT/appft.f", "max_forks_repo_name": "josevnz/NPB3.0-JAV-FORK", "max_forks_repo_head_hexsha": "4d917796d534fab7df30a08c74a756b9a44f38b7", "max_forks_repo_licenses": ["NASA-1.3"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.2673267327, "max_line_length": 70, "alphanum_fraction": 0.500955501, "num_tokens": 1060, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122213606241, "lm_q2_score": 0.752012562644147, "lm_q1q2_score": 0.6823101887037565}} {"text": " FUNCTION rtsec(func,x1,x2,xacc)\r\n INTEGER MAXIT\r\n REAL rtsec,x1,x2,xacc,func\r\n EXTERNAL func\r\n PARAMETER (MAXIT=30)\r\n INTEGER j\r\n REAL dx,f,fl,swap,xl\r\n fl=func(x1)\r\n f=func(x2)\r\n if(abs(fl).lt.abs(f))then\r\n rtsec=x1\r\n xl=x2\r\n swap=fl\r\n fl=f\r\n f=swap\r\n else\r\n xl=x1\r\n rtsec=x2\r\n endif\r\n do 11 j=1,MAXIT\r\n dx=(xl-rtsec)*f/(f-fl)\r\n xl=rtsec\r\n fl=f\r\n rtsec=rtsec+dx\r\n f=func(rtsec)\r\n if(abs(dx).lt.xacc.or.f.eq.0.)return\r\n11 continue\r\n pause 'rtsec exceed maximum iterations'\r\n END\r\n", "meta": {"hexsha": "12da32cf2cfb7c87bd61976048a04ca526b05b71", "size": 650, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/rtsec.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/rtsec.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/rtsec.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": 21.6666666667, "max_line_length": 46, "alphanum_fraction": 0.4815384615, "num_tokens": 208, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8688267830311354, "lm_q2_score": 0.7853085808877581, "lm_q1q2_score": 0.6822971280194571}} {"text": "program main\n use device\n implicit none \n class(device_t), allocatable :: fig\n real, allocatable :: x(:), y(:)\n integer :: n = 10**3\n allocate(x(n), y(n))\n call random_seed()\n call random_number(x)\n call random_number(y) \n\nuplot: block\n use uniplot\n allocate(fig_t::fig)\n call fig%init(100, 100, 'MonteCarlo')\n call monte_carlo(fig, x, y) \n deallocate(fig)\n end block uplot\n\nxplot: block\n use xplot\n allocate(fig_t::fig)\n call fig%init(450, 450, 'MonteCarlo')\n call monte_carlo(fig, x, y) \n deallocate(fig)\n end block xplot\n\ncontains\n subroutine monte_carlo(fig, x, y)\n class(device_t), intent(in out) :: fig\n real, intent(in) :: x(:), y(:)\n integer :: i, ix0, iy0, ix1, iy1, k\n k = fig%nx\n print *\n print *, 'Monte Carlo: estimated pi =', 4.0 * count(x**2 + y**2 < 1.0) / size(x) \n !draw box\n call fig%line0(0, 0, k-1, 0)\n call fig%line0(0, 0, 0, k-1)\n call fig%line0(0, k-1, k-1, k-1)\n call fig%line0(k-1, 0, k-1, k-1)\n ! draw 1/4 circle\n ix0 = 0\n iy0 = 0\n do ix1 = 0, k - 1\n iy1 = k - 1 - int(sqrt(real((k-1)**2 - ix1**2)))\n call fig%line0(ix0, iy0, ix1, iy1)\n ix0 = ix1\n iy0 = iy1\n end do \n \n do i = 1, n \n call fig%point(int(k * x(i)), int(k * y(i)))\n end do \n call fig%show()\n end subroutine monte_carlo\n\nend program main\n", "meta": {"hexsha": "30c061aea7a221fc5e2215fb959b61780c578e95", "size": 1539, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "app/main.f90", "max_stars_repo_name": "f66blog/xplot", "max_stars_repo_head_hexsha": "0443de378fbf308f7feb7b10d55fe6a2a1f5ac33", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app/main.f90", "max_issues_repo_name": "f66blog/xplot", "max_issues_repo_head_hexsha": "0443de378fbf308f7feb7b10d55fe6a2a1f5ac33", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "app/main.f90", "max_forks_repo_name": "f66blog/xplot", "max_forks_repo_head_hexsha": "0443de378fbf308f7feb7b10d55fe6a2a1f5ac33", "max_forks_repo_licenses": ["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.5344827586, "max_line_length": 89, "alphanum_fraction": 0.5009746589, "num_tokens": 520, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256472515683, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.6822819357287823}} {"text": "program expr_03\nimplicit none\ninteger :: x\nx = -2\nif (x /= -2) error stop\n\nx = -2*3\nif (x /= -6) error stop\n\nx = -2*(-3)\nif (x /= 6) error stop\n\nx = 3 - 1\nif (x /= 2) error stop\n\nx = 1 - 3\nif (x /= -2) error stop\nif (x /= (-2)) error stop\n\nx = 1 - (-3)\nif (x /= 4) error stop\nif (x /= +4) error stop\nif (x /= (+4)) error stop\nend program\n", "meta": {"hexsha": "bab1628677d10007252d126d6b6553e401d5c650", "size": 338, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "integration_tests/expr_03.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/expr_03.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/expr_03.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": 13.52, "max_line_length": 25, "alphanum_fraction": 0.5266272189, "num_tokens": 148, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703224, "lm_q2_score": 0.8418256393148981, "lm_q1q2_score": 0.682281925442635}} {"text": " PROGRAM FOO\n INTEGER I, J\n INTEGER A(5:10, 5:10)\n DO J = 5 ,10\n DO I = 5 ,10\n A(I,J) = I * J\n enddo\n enddo\n PRINT *,A\n END\n", "meta": {"hexsha": "a1038a3936378efea0d349adb1b1f3e8bd4b3345", "size": 186, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "packages/PIPS/validation/Transformations/Linearize_array.sub/linearize_array04.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/Transformations/Linearize_array.sub/linearize_array04.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/Transformations/Linearize_array.sub/linearize_array04.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": 16.9090909091, "max_line_length": 27, "alphanum_fraction": 0.3709677419, "num_tokens": 68, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8104788995148791, "lm_q2_score": 0.8418256412990657, "lm_q1q2_score": 0.682281919343474}} {"text": "\nc****************************************************************\n\n\tsubroutine cross(r_u,r_v,r_w)\n\nc****************************************************************\nc**\nc**\tFILE NAME: cross.f\nc**\nc** DATE WRITTEN: 8/3/90\nc**\nc** PROGRAMMER:Scott Hensley\nc**\nc** \tFUNCTIONAL DESCRIPTION: The subroutine takes two vectors and returns \nc** their cross product.\nc**\nc** ROUTINES CALLED:none\nc** \nc** NOTES: none\nc**\nc** UPDATE LOG:\nc**\nc*****************************************************************\n\n \timplicit none\n\nc\tINPUT VARIABLES:\n real*8 r_v(3),r_u(3) !3x1 vectors\n \nc \tOUTPUT VARIABLES:\n real*8 r_w(3)\n\nc\tLOCAL VARIABLES:\n\t\nc \tPROCESSING STEPS:\n\nc compute vector norm\n\n r_w(1) = r_u(2)*r_v(3) - r_u(3)*r_v(2) \n r_w(2) = r_u(3)*r_v(1) - r_u(1)*r_v(3) \n r_w(3) = r_u(1)*r_v(2) - r_u(2)*r_v(1) \n\n end \n", "meta": {"hexsha": "800032ed9ae0c77f0b60fe5c4881d3647f884ccc", "size": 906, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "contrib/alos2proc_f/src/cross.f", "max_stars_repo_name": "vincentschut/isce2", "max_stars_repo_head_hexsha": "1557a05b7b6a3e65abcfc32f89c982ccc9b65e3c", "max_stars_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_stars_count": 1133, "max_stars_repo_stars_event_min_datetime": "2022-01-07T21:24:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-07T21:33:08.000Z", "max_issues_repo_path": "contrib/alos2proc_f/src/cross.f", "max_issues_repo_name": "vincentschut/isce2", "max_issues_repo_head_hexsha": "1557a05b7b6a3e65abcfc32f89c982ccc9b65e3c", "max_issues_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_issues_count": 276, "max_issues_repo_issues_event_min_datetime": "2019-02-10T07:18:28.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:45:55.000Z", "max_forks_repo_path": "contrib/alos2proc_f/src/cross.f", "max_forks_repo_name": "vincentschut/isce2", "max_forks_repo_head_hexsha": "1557a05b7b6a3e65abcfc32f89c982ccc9b65e3c", "max_forks_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_forks_count": 235, "max_forks_repo_forks_event_min_datetime": "2019-02-10T05:00:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T07:37:24.000Z", "avg_line_length": 20.5909090909, "max_line_length": 74, "alphanum_fraction": 0.4337748344, "num_tokens": 272, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970904940927, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6822507957008515}} {"text": "!----------------------------------------------------------------------\n!----------------------------------------------------------------------\n! couple.f90 - coupled cavity equation normal form\n!----------------------------------------------------------------------\n!----------------------------------------------------------------------\n\nSUBROUTINE FUNC(NDIM,U,ICP,PAR,IJAC,F,DFDU,DFDP)\n!--------- ----\n\n! Evaluates the algebraic equations or ODE right hand side\n\n! Input arguments :\n! NDIM : Dimension of the algebraic or ODE system \n! U : State variables\n! ICP : Array indicating the free parameter(s)\n! PAR : Equation parameters\n\n! Values to be returned :\n! F : Equation or ODE right hand side values\n\n! Normally unused Jacobian arguments : IJAC, DFDU, DFDP (see manual)\n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: NDIM, IJAC, ICP(*)\n DOUBLE PRECISION, INTENT(IN) :: U(NDIM), PAR(*)\n DOUBLE PRECISION, INTENT(OUT) :: F(NDIM)\n DOUBLE PRECISION, INTENT(INOUT) :: DFDU(NDIM,NDIM),DFDP(NDIM,*)\n\n DOUBLE PRECISION x, delta,dff,phi,kappa,gamma\n COMPLEX(KIND(1.0d0)) I, AA, BB,FF\n\n delta=PAR(1)\n! kappa = (0.d0,1.d0)*PAR(2)\n kappa = PAR(2)\n phi = PAR(3)\n\n dff = PAR(4)\n gamma = PAR(5)\n\n I=COMPLEX(0.d0,1.d0)\n AA=U(1)+I*U(2)\n BB=U(3)+I*U(4)\n\t\n! FF=I*(delta+AA*CONJG(AA))*AA-AA+(kappa-1/2)*BB+CDEXP(I*phi)*dff \n! F(1)=REALPART(FF)\n! F(2)=IMAGPART(FF)\n! F(1)= dff*dcos(phi) - U(1) - delta*U(2) - U(2)*U(1)**2 -U(2)**3 - U(3)/2 -kappa*U(4)\n! F(2)= dff*dsin(phi) + delta*U(1)+ U(1)**3 - U(2) +U(1)*U(2)*U(2)+kappa*U(3)-U(4)/2\n\n F(1)= dff*dcos(phi) - U(1) - delta*U(2) - U(2)*U(1)**2 -U(2)**3 + gamma*U(3) -kappa*U(4)\n F(2)= dff*dsin(phi) + delta*U(1)+ U(1)**3 - U(2) +U(1)*U(2)*U(2)+kappa*U(3)+gamma*U(4)\n\n! FF=I*(delta+BB*CONJG(BB))*BB-BB+(kappa-1/2)*AA+CDEXP(I*phi)*dff \n! F(3)=REALPART(FF)\n! F(4)=IMAGPART(FF)\n\n! F(3)=dff*dcos(phi) - U(1)/2 - kappa*U(2) - U(3) - delta*U(4) - U(4)*U(3)**2 - U(4)**3\n! F(4)=dff*dsin(phi) + kappa*U(1) - U(2)/2 + delta*U(3) + U(3)**3 - U(4) + U(3)*U(4)**2\n\n F(3)=dff*dcos(phi) + gamma*U(1) - kappa*U(2) - U(3) - delta*U(4) - U(4)*U(3)**2 - U(4)**3\n F(4)=dff*dsin(phi) + kappa*U(1) + gamma*U(2) + delta*U(3) + U(3)**3 - U(4) + U(3)*U(4)**2\n\n\n\nEND SUBROUTINE FUNC\n\n!-----------------------------------------------------------------------\n!-----------------------------------------------------------------------\n\nSUBROUTINE STPNT(NDIM,U,PAR,T)\n!--------- -----\n\n! Input arguments :\n! NDIM : Dimension of the algebraic or ODE system \n\n! Values to be returned :\n! U : A starting solution vector\n! PAR : The corresponding equation-parameter values\n\n! Note : For time- or space-dependent solutions this subroutine has\n! the scalar input parameter T contains the varying time or space\n! variable value.\n \n IMPLICIT NONE\n INTEGER, INTENT(IN) :: NDIM\n DOUBLE PRECISION, INTENT(INOUT) :: U(NDIM),PAR(*)\n DOUBLE PRECISION, INTENT(IN) :: T\n\n! Initialize the equation parameters\n! PAR(1:2) = (/ 0.0d0, 0.0d0 /)\n! PAR(1)=-1.20;\n! PAR(2)=0.8; \n PAR(1)=-8.00;\n PAR(2)=2.8; \n PAR(3)=0.0; \n PAR(4)=0.00; \n PAR(5)=0.00; \n\n! Initialize the solution\n! U(1) = 0.5783549543956;\n! U(2) = 0.1279674119301;\n! U(3) = 0.5435124237934;\n! U(4) = 0.7882331404511;\n U(1) = 0.0;\n U(2) = 0.0;\n U(3) = 0.0;\n U(4) = 0.0;\n \nEND SUBROUTINE STPNT\n\n!----------------------------------------------------------------------\n!----------------------------------------------------------------------\n\nSUBROUTINE BCND(NDIM,PAR,ICP,NBC,U0,U1,FB,IJAC,DBC)\n!--------- ----\n\n! Boundary Conditions\n\n! Input arguments :\n! NDIM : Dimension of the ODE system \n! PAR : Equation parameters\n! ICP : Array indicating the free parameter(s)\n! NBC : Number of boundary conditions\n! U0 : State variable values at the left boundary\n! U1 : State variable values at the right boundary\n\n! Values to be returned :\n! FB : The values of the boundary condition functions \n\n! Normally unused Jacobian arguments : IJAC, DBC (see manual)\n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: NDIM, ICP(*), NBC, IJAC\n DOUBLE PRECISION, INTENT(IN) :: PAR(*), U0(NDIM), U1(NDIM)\n DOUBLE PRECISION, INTENT(OUT) :: FB(NBC)\n DOUBLE PRECISION, INTENT(INOUT) :: DBC(NBC,*)\n\n! FB(1)= U0(1) \n! FB(2)= U0(2) \n\nEND SUBROUTINE BCND\n\n!----------------------------------------------------------------------\n!----------------------------------------------------------------------\n\nSUBROUTINE ICND(NDIM,PAR,ICP,NINT,U,UOLD,UDOT,UPOLD,FI,IJAC,DINT)\n!--------- ----\n\n! Integral Conditions\n\n! Input arguments :\n! NDIM : Dimension of the ODE system \n! PAR : Equation parameters\n! ICP : Array indicating the free parameter(s)\n! NINT : Number of integral conditions\n! U : Value of the vector function U at `time' t\n\n! The following input arguments, which are normally not needed,\n! correspond to the preceding point on the solution branch\n! UOLD : The state vector at 'time' t\n! UDOT : Derivative of UOLD with respect to arclength\n! UPOLD : Derivative of UOLD with respect to `time'\n\n! Normally unused Jacobian arguments : IJAC, DINT\n\n! Values to be returned :\n! FI : The value of the vector integrand \n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: NDIM, ICP(*), NINT, IJAC\n DOUBLE PRECISION, INTENT(IN) :: PAR(*)\n DOUBLE PRECISION, INTENT(IN) :: U(NDIM), UOLD(NDIM), UDOT(NDIM), UPOLD(NDIM)\n DOUBLE PRECISION, INTENT(OUT) :: FI(NINT)\n DOUBLE PRECISION, INTENT(INOUT) :: DINT(NINT,*)\n\n!X FI(1)=\n\nEND SUBROUTINE ICND\n\n!----------------------------------------------------------------------\n!----------------------------------------------------------------------\n\nSUBROUTINE FOPT(NDIM,U,ICP,PAR,IJAC,FS,DFDU,DFDP)\n!--------- ----\n!\n! Defines the objective function for algebraic optimization problems\n!\n! Supplied variables :\n! NDIM : Dimension of the state equation\n! U : The state vector\n! ICP : Indices of the control parameters\n! PAR : The vector of control parameters\n!\n! Values to be returned :\n! FS : The value of the objective function\n!\n! Normally unused Jacobian argument : IJAC, DFDP\n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: NDIM, ICP(*), IJAC\n DOUBLE PRECISION, INTENT(IN) :: U(NDIM), PAR(*)\n DOUBLE PRECISION, INTENT(OUT) :: FS\n DOUBLE PRECISION, INTENT(INOUT) :: DFDU(NDIM),DFDP(*)\n\n!X FS=\n\nEND SUBROUTINE FOPT\n\n!----------------------------------------------------------------------\n!----------------------------------------------------------------------\n\nSUBROUTINE PVLS(NDIM,U,PAR)\n!--------- ----\n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: NDIM\n DOUBLE PRECISION, INTENT(IN) :: U(NDIM)\n DOUBLE PRECISION, INTENT(INOUT) :: PAR(*)\n DOUBLE PRECISION, EXTERNAL :: GETP\n\n!---------------------------------------------------------------------- \n! NOTE : \n! Parameters set in this subroutine should be considered as ``solution \n! measures'' and be used for output purposes only.\n! \n! They should never be used as `true'' continuation parameters. \n!\n! They may, however, be added as ``over-specified parameters'' in the \n! parameter list associated with the AUTO-Constant NICP, in order to \n! print their values on the screen and in the ``p.xxx file.\n!\n! They may also appear in the list associated with AUTO-Constant NUZR.\n!\n!---------------------------------------------------------------------- \n! For algebraic problems the argument U is, as usual, the state vector.\n! For differential equations the argument U represents the approximate \n! solution on the entire interval [0,1]. In this case its values must \n! be accessed indirectly by calls to GETP, as illustrated below.\n!---------------------------------------------------------------------- \n!\n! Set PAR(2) equal to the L2-norm of U(1)\n!\n! Set PAR(3) equal to the minimum of U(2)\n!X PAR(3)=GETP('MIN',2,U)\n!\n! Set PAR(4) equal to the value of U(2) at the left boundary.\n!X PAR(4)=GETP('BV0',2,U)\n!\n! Set PAR(5) equal to the pseudo-arclength step size used.\n!X PAR(5)=GETP('STP',1,U)\n!\n\n Par(6)=GETP('MAX',1,U)*GETP('MAX',1,U)+GETP('MAX',2,U)*GETP('MAX',2,U)\n Par(7)=GETP('MAX',3,U)*GETP('MAX',3,U)+GETP('MAX',4,U)*GETP('MAX',4,U)\n\n\n!---------------------------------------------------------------------- \n! The first argument of GETP may be one of the following:\n! 'NRM' (L2-norm), 'MAX' (maximum),\n! 'INT' (integral), 'BV0 (left boundary value),\n! 'MIN' (minimum), 'BV1' (right boundary value).\n!\n! Also available are\n! 'STP' (Pseudo-arclength step size used).\n! 'FLD' (`Fold function', which vanishes at folds).\n! 'BIF' (`Bifurcation function', which vanishes at singular points).\n! 'HBF' (`Hopf function'; which vanishes at Hopf points).\n! 'SPB' ( Function which vanishes at secondary periodic bifurcations).\n!---------------------------------------------------------------------- \n\n\nEND SUBROUTINE PVLS\n\n!----------------------------------------------------------------------\n!----------------------------------------------------------------------\n", "meta": {"hexsha": "db86c3b6689103fc69d844c3cfbd334f5c6e6dbf", "size": 9140, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Files_From_Neil/couple.f90", "max_stars_repo_name": "st970703/AUTO07P-Update-to-Python-3.0", "max_stars_repo_head_hexsha": "fb2d2aebf2127fa914064d01ed62c0acb5f6421c", "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": "Files_From_Neil/couple.f90", "max_issues_repo_name": "st970703/AUTO07P-Update-to-Python-3.0", "max_issues_repo_head_hexsha": "fb2d2aebf2127fa914064d01ed62c0acb5f6421c", "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": "Files_From_Neil/couple.f90", "max_forks_repo_name": "st970703/AUTO07P-Update-to-Python-3.0", "max_forks_repo_head_hexsha": "fb2d2aebf2127fa914064d01ed62c0acb5f6421c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.115942029, "max_line_length": 92, "alphanum_fraction": 0.5213347921, "num_tokens": 2774, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970811069351, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.6822507930130339}} {"text": "! This file is part of fortran_quaternion\n! Author: Pierre de Buyl http://pdebuyl.be/\n! License: BSD 3-clause\n\nmodule quaternion\n implicit none\n\n private\n\n public :: qnorm, qnormalize, qconj, qinv, qmul\n public :: qvector, qscalar, qnew\n public :: qrot\n\n interface qnew\n module procedure qnew_s\n module procedure qnew_v\n module procedure qnew_sv\n module procedure qnew_void\n end interface qnew\n\ncontains\n\n !! Construct a new quaternion from the scalar part s and the vector part v\n pure function qnew_s(s) result(q)\n double precision, intent(in) :: s\n double precision :: q(4)\n\n q(1:3) = 0\n q(4) = s\n\n end function qnew_s\n\n !! Construct a new quaternion from the scalar part s and the vector part v\n pure function qnew_v(v) result(q)\n double precision, intent(in) :: v(3)\n double precision :: q(4)\n\n q(1:3) = v\n q(4) = 0\n\n end function qnew_v\n\n !! Construct a new quaternion from the scalar part s and the vector part v\n pure function qnew_sv(s, v) result(q)\n double precision, intent(in) :: s\n double precision, intent(in) :: v(3)\n double precision :: q(4)\n\n q(1:3) = v\n q(4) = s\n\n end function qnew_sv\n\n !! Construct a new quaternion from the scalar part s and the vector part v\n pure function qnew_void() result(q)\n double precision :: q(4)\n\n q = 0\n\n end function qnew_void\n\n !! Return the vector part of a quaternion\n pure function qvector(q) result(v)\n double precision, intent(in) :: q(4)\n double precision :: v(3)\n\n v = q(1:3)\n\n end function qvector\n\n !! Return the scalar part of a quaternion\n pure function qscalar(q) result(s)\n double precision, intent(in) :: q(4)\n double precision :: s\n\n s = q(4)\n\n end function qscalar\n\n !! Return the norm of quaternion\n pure function qnorm(q) result(n)\n double precision, intent(in) :: q(4)\n double precision :: n\n\n n = norm2(q)\n\n end function qnorm\n\n !! Return normalized quaternion\n pure function qnormalize(q) result(r)\n double precision, intent(in) :: q(4)\n double precision :: r(4)\n\n double precision :: n\n\n n = qnorm(q)\n r = q/n\n end function qnormalize\n\n !! Return conjugate quaternion\n pure function qconj(q) result(n)\n double precision, intent(in) :: q(4)\n double precision :: n(4)\n\n n(1) = -q(1)\n n(2) = -q(2)\n n(3) = -q(3)\n n(4) = q(4)\n\n end function qconj\n\n !! Return cross product between two 3d vectors\n pure function cross(x1, x2) result(r)\n double precision, intent(in) :: x1(3), x2(3)\n double precision :: r(3)\n\n r(1) = x1(2)*x2(3) - x1(3)*x2(2)\n r(2) = x1(3)*x2(1) - x1(1)*x2(3)\n r(3) = x1(1)*x2(2) - x1(2)*x2(1)\n\n end function cross\n\n !! Return inverse quaterion\n pure function qinv(q) result(n)\n double precision, intent(in) :: q(4)\n double precision :: n(4)\n\n n(1) = -q(1)\n n(2) = -q(2)\n n(3) = -q(3)\n n(4) = q(4)\n\n n = n / dot_product(n, n)\n\n end function qinv\n\n !! Return the product of two quaternions\n pure function qmul(q1, q2) result(r)\n double precision, intent(in) :: q1(4)\n double precision, intent(in) :: q2(4)\n double precision :: r(4)\n\n r(1:3) = q1(4)*q2(1:3) + q2(4)*q1(1:3) + cross(q1(1:3), q2(1:3))\n r(4) = q1(4)*q2(4) - dot_product(q1(1:3), q2(1:3))\n\n end function qmul\n\n !! Return the vector v rotated by the quaternion q\n pure function qrot(q, v) result(r)\n double precision, intent(in) :: q(4)\n double precision, intent(in) :: v(3)\n double precision :: r(3)\n\n r = qvector(qmul(q, qmul(qnew(v=v), qconj(q))))\n\n end function qrot\n\nend module quaternion\n", "meta": {"hexsha": "f34b371c2d842695979fa292355a9b0be069d446", "size": 3569, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/quaternion.f90", "max_stars_repo_name": "pdebuyl/fortran_quaternion", "max_stars_repo_head_hexsha": "7a7e26530e040bcddd36eadad73044a0ae07893c", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2017-02-23T02:16:43.000Z", "max_stars_repo_stars_event_max_datetime": "2018-04-04T10:15:35.000Z", "max_issues_repo_path": "src/quaternion.f90", "max_issues_repo_name": "pdebuyl/fortran_quaternion", "max_issues_repo_head_hexsha": "7a7e26530e040bcddd36eadad73044a0ae07893c", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-05-23T11:39:28.000Z", "max_issues_repo_issues_event_max_datetime": "2019-05-23T11:44:35.000Z", "max_forks_repo_path": "src/quaternion.f90", "max_forks_repo_name": "pdebuyl/fortran_quaternion", "max_forks_repo_head_hexsha": "7a7e26530e040bcddd36eadad73044a0ae07893c", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.4465408805, "max_line_length": 76, "alphanum_fraction": 0.6262258336, "num_tokens": 1171, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970717197771, "lm_q2_score": 0.774583389368527, "lm_q1q2_score": 0.6822507811585785}} {"text": " module modulo_formas\n implicit none \n private\n public tipo_cuadrado\n\n \n type :: tipo_cuadrado\n real :: lado\n contains \n procedure :: area !Declaraci\u00f3n de procedimiento\n end type\n\n\n contains\n !Definici\u00f3n del procedimiento\n real function area(el_mismo) result(resultado)\n class(tipo_cuadrado), intent(in) :: el_mismo\n resultado=el_mismo%lado**2\n end function\n end module modulo_formas\n\n\n program principal ! \"principal\" .eq. \"main\"\n use modulo_formas\n implicit none\n \n !Declaraci\u00f3n de variables\n type(tipo_cuadrado) :: cuadradito\n real :: x, lado\n\n !Inicializando variables\n lado = 0.5\n cuadradito%lado = lado\n x =cuadradito%area()\n ! el \"el_mismo\" no aparece aqu\u00ed, esto sucede ya que es \n ! pasado de forma impl\u00edcita \n print *, \"x=\" , x\n end program principal\n\n !x= 0.250000000 \n", "meta": {"hexsha": "b7f11ae9e80c767c6614e83528db8feaa17cdcf3", "size": 1025, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Programas/procedimientos_ligados_al_tipo.f90", "max_stars_repo_name": "Marc-xyz/InicioRapidoEnFortran", "max_stars_repo_head_hexsha": "8cfe017877061bbfbb2bef66e16c2afc9375243d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-25T22:00:53.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-25T22:00:53.000Z", "max_issues_repo_path": "Programas/procedimientos_ligados_al_tipo.f90", "max_issues_repo_name": "Marc-xyz/InicioRapidoEnFortran", "max_issues_repo_head_hexsha": "8cfe017877061bbfbb2bef66e16c2afc9375243d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Programas/procedimientos_ligados_al_tipo.f90", "max_forks_repo_name": "Marc-xyz/InicioRapidoEnFortran", "max_forks_repo_head_hexsha": "8cfe017877061bbfbb2bef66e16c2afc9375243d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.0, "max_line_length": 63, "alphanum_fraction": 0.5609756098, "num_tokens": 257, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.6822507765752596}} {"text": "module block_mod \r\n! Demonstrate BLOCK construct, which has nothing to do with COMMON BLOCK.\r\nimplicit none\r\ncontains\r\npure function correlation_matrix(x) result(corr)\r\nreal, intent(in) :: x(:,:)\r\nreal :: corr(size(x,2),size(x,2))\r\nreal :: xstd(size(x,1),size(x,2))\r\ninteger :: i2,j2,n1,n2\r\nn1 = size(x,1)\r\nn2 = size(x,2)\r\ncalc_xstd: block ! naming the block allows early exit\r\n real :: mean,sqrt_sumsq,vec(n1) ! do not exist outside block\r\n if (n1 < 1) exit calc_xstd ! leave block early to avoid division by 0\r\n do i2=1,n2\r\n ! variables x and xstd declared outside block are accessible\r\n mean = sum(x(:,i2))/n1\r\n vec = x(:,i2) - mean\r\n sqrt_sumsq = sqrt(sum(vec**2))\r\n xstd(:,i2) = vec/sqrt_sumsq ! standardized columns of x\r\n end do\r\nend block calc_xstd\r\ndo i2=1,n2\r\n do j2=1,i2-1\r\n corr(i2,j2) = sum(xstd(:,i2)*xstd(:,j2)) ! lower diagonal \r\n end do\r\n corr(i2,i2) = 1.0\r\nend do\r\n! FORALL can be masked. Line below copies lower diagonal to upper.\r\nforall (i2=1:n2,j2=1:n2,j2>i2) corr(i2,j2) = corr(j2,i2)\r\nend function correlation_matrix\r\nend module block_mod\r\n!\r\nprogram main\r\nuse block_mod, only: correlation_matrix\r\nimplicit none\r\ninteger, parameter :: n1 = 1000, n2 = 3\r\nreal :: x(n1,n2),v(n1),corr(n2,n2)\r\ninteger :: i2\r\ncall random_seed()\r\ncall random_number(v)\r\ncall random_number(x)\r\nforall (i2=1:n2) x(:,i2) = x(:,i2) + 2*v\r\ncorr = correlation_matrix(x)\r\nprint \"('correlation matrix')\"\r\ndo i2=1,n2\r\n write (*,\"(*(f6.3))\") corr(i2,:)\r\nend do\r\nend program main\r\n! sample output:\r\n! correlation matrix\r\n! 1.000 0.787 0.791\r\n! 0.787 1.000 0.803\r\n! 0.791 0.803 1.000", "meta": {"hexsha": "8d857dc791bf2f669958dcaca49e39faa3262d1d", "size": 1660, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "block.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": "block.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": "block.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": 30.7407407407, "max_line_length": 74, "alphanum_fraction": 0.6373493976, "num_tokens": 559, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970654616711, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.6822507717278348}} {"text": "\n! $UWHPSC/codes/fortran/rank2.f90\n\nprogram rank2\n\n implicit none\n real(kind=8) :: A(3,4), B(12)\n equivalence (A,B)\n integer :: i,j\n\n A = reshape((/(10*i, i=1,12)/), (/3,4/))\n\n do i=1,3\n print 20, i, (A(i,j), j=1,4)\n 20 format(\"Row \",i1,\" of A contains: \", 11x, 4f6.1)\n print 21, i, (3*(j-1)+i, j=1,4)\n 21 format(\"Row \",i1,\" is in locations\",4i3)\n print 22, (B(3*(j-1)+i), j=1,4)\n 22 format(\"These elements of B contain:\", 4x, 4f6.1, /)\n enddo\n\nend program rank2\n\n", "meta": {"hexsha": "d59a0dcaddaa88e068ece8894d74618b7eaf55eb", "size": 522, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/codes/fortran/rank2.f90", "max_stars_repo_name": "philipwangdk/HPC", "max_stars_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "uwhpsc/codes/fortran/rank2.f90", "max_issues_repo_name": "philipwangdk/HPC", "max_issues_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "uwhpsc/codes/fortran/rank2.f90", "max_forks_repo_name": "philipwangdk/HPC", "max_forks_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.75, "max_line_length": 60, "alphanum_fraction": 0.5172413793, "num_tokens": 224, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.7745833737577158, "lm_q1q2_score": 0.6822507674086216}} {"text": "! =====================================================================\n! subroutine USHO \n!\n! This subroutine constructs a simple harmonic oscillator ground state\n! wavefunction.\n! --------------------------------------------------------------------- \n subroutine USHO(nRP,nR,nP,x0,y0,kX,kY,R,P,U)\n implicit none\n\n integer :: nRP\n integer :: nR\n integer :: nP\n double precision :: x0\n double precision :: y0\n double precision :: kX\n double precision :: kY\n double precision :: R(nR)\n double precision :: P(nP)\n double complex :: U(nRP)\n\n integer :: i\n integer :: j\n integer :: k\n double precision :: pi \n double complex :: a \n double complex :: b \n double complex :: bX \n double complex :: bY\n\n pi = 3.14159265358979323846d0\n a = dcmplx((kX*kY/pi**2)**(0.25d0),0.0d0)\n\n k = 0\n do j = 1, nP\n do i = 1, nR\n k = k + 1\n bX = dcmplx(-0.5d0*kX*(R(i)*dcos(P(j))-x0)**2,0.0d0) \n bY = dcmplx(-0.5d0*kY*(R(i)*dsin(P(j))-y0)**2,0.0d0) \n b = bX + bY\n U(k) = a*cdexp(b)\n enddo\n enddo\n\n return\n end\n! =====================================================================\n", "meta": {"hexsha": "8c8adf42332d8837cba90ddd3f08878b2bbfcc3e", "size": 1264, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/usho.f", "max_stars_repo_name": "mkandes/itpprp", "max_stars_repo_head_hexsha": "d30f4fc0b05822a34fef187688ab12245cbbf93a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source/usho.f", "max_issues_repo_name": "mkandes/itpprp", "max_issues_repo_head_hexsha": "d30f4fc0b05822a34fef187688ab12245cbbf93a", "max_issues_repo_licenses": ["MIT"], "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/usho.f", "max_forks_repo_name": "mkandes/itpprp", "max_forks_repo_head_hexsha": "d30f4fc0b05822a34fef187688ab12245cbbf93a", "max_forks_repo_licenses": ["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.8936170213, "max_line_length": 72, "alphanum_fraction": 0.4224683544, "num_tokens": 358, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942290328345, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6822268129356809}} {"text": "SUBROUTINE BottomVincent(FineGrid,GX,GY)\n!\n! Define bottom profile for Vincent and Briggs experiment (3D), waves are assumed to \n! be in the x-direction and the shoal center is placed at x=10.61m, y=13.72. \n!\n! By Maite Gouin. Modified by H.B. Bingham.\nUSE Precision\nUSE Constants\nUSE DataTypes\nIMPLICIT NONE\nTYPE (Level_def) :: FineGrid\nREAL(KIND=long) :: y, x, xr, yr, k, angle, dy\nINTEGER :: Nx, Ny, i, j, GX, GY\n\n\nNx = FineGrid%Nx+2*GX\nNy = FineGrid%Ny+2*GY\ndy = FineGrid%y(1,Ny)-FineGrid%y(1,Ny-1)\nangle = 0 ! We assume waves in the x-direction.\nk = angle/180.0_long*pi\nDO j = 1, Ny\n DO i = 1 , Nx\n x = FineGrid%x(i,1) - 6.1_long -4.51_long ! shoal is centered at 6.1 + 2 lambda in x.\n y = FineGrid%y(1,j) - 13.72_long+GY*dy ! shoal at 13.72m in y.\n yr = cos(k)*y - sin(k)*x\n xr = sin(k)*y + cos(k)*x\n !\n FineGrid%h(i,j) = 0.4572_long\n !\n IF ((yr/3.96_long)**2 + (xr/3.05_long)**2<1) THEN\n FineGrid%h(i,j) = FineGrid%h(i,j) + 0.4572_long - 0.7620_long*sqrt(one-(yr/4.95_long)**2-(xr/3.81_long)**2)\n END IF\n END DO\nEND DO\nWRITE(*,*) ' WARNING: The bottom slopes for the Vincent and Briggs experiment are not defined analytically.,'\nWRITE(*,*) ' WARNING: Therefore the derivatives of the bottom profile function are determined numerically.'\nWRITE(*,*) ' WARNING: Shoal center is at x=10.61m, y=13.72m. Waves should be in the x-direction'\nEND SUBROUTINE BottomVincent\n", "meta": {"hexsha": "36fb24feed92ec012e0d1aa38df8b2300c79d840", "size": 1447, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/analyticalsolutions/bottomVincent.f90", "max_stars_repo_name": "apengsigkarup/OceanWave3D", "max_stars_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 46, "max_stars_repo_stars_event_min_datetime": "2016-01-08T12:36:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T06:56:45.000Z", "max_issues_repo_path": "src/analyticalsolutions/bottomVincent.f90", "max_issues_repo_name": "apengsigkarup/OceanWave3D", "max_issues_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-10-10T19:45:08.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-07T07:37:11.000Z", "max_forks_repo_path": "src/analyticalsolutions/bottomVincent.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": 37.1025641026, "max_line_length": 118, "alphanum_fraction": 0.6482377332, "num_tokens": 518, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.682226806244086}} {"text": "!*==dlasv2.f90 processed by SPAG 7.51RB at 20:08 on 3 Mar 2022\n!> \\brief \\b DLASV2 computes the singular value decomposition of a 2-by-2 triangular matrix.\n!\n! =========== DOCUMENTATION ===========\n!\n! Online html documentation available at\n! http://www.netlib.org/lapack/explore-html/\n!\n!> \\htmlonly\n!> Download DLASV2 + dependencies\n!> \n!> [TGZ]\n!> \n!> [ZIP]\n!> \n!> [TXT]\n!> \\endhtmlonly\n!\n! Definition:\n! ===========\n!\n! SUBROUTINE DLASV2( F, G, H, SSMIN, SSMAX, SNR, CSR, SNL, CSL )\n!\n! .. Scalar Arguments ..\n! DOUBLE PRECISION CSL, CSR, F, G, H, SNL, SNR, SSMAX, SSMIN\n! ..\n!\n!\n!> \\par Purpose:\n! =============\n!>\n!> \\verbatim\n!>\n!> DLASV2 computes the singular value decomposition of a 2-by-2\n!> triangular matrix\n!> [ F G ]\n!> [ 0 H ].\n!> On return, abs(SSMAX) is the larger singular value, abs(SSMIN) is the\n!> smaller singular value, and (CSL,SNL) and (CSR,SNR) are the left and\n!> right singular vectors for abs(SSMAX), giving the decomposition\n!>\n!> [ CSL SNL ] [ F G ] [ CSR -SNR ] = [ SSMAX 0 ]\n!> [-SNL CSL ] [ 0 H ] [ SNR CSR ] [ 0 SSMIN ].\n!> \\endverbatim\n!\n! Arguments:\n! ==========\n!\n!> \\param[in] F\n!> \\verbatim\n!> F is DOUBLE PRECISION\n!> The (1,1) element of the 2-by-2 matrix.\n!> \\endverbatim\n!>\n!> \\param[in] G\n!> \\verbatim\n!> G is DOUBLE PRECISION\n!> The (1,2) element of the 2-by-2 matrix.\n!> \\endverbatim\n!>\n!> \\param[in] H\n!> \\verbatim\n!> H is DOUBLE PRECISION\n!> The (2,2) element of the 2-by-2 matrix.\n!> \\endverbatim\n!>\n!> \\param[out] SSMIN\n!> \\verbatim\n!> SSMIN is DOUBLE PRECISION\n!> abs(SSMIN) is the smaller singular value.\n!> \\endverbatim\n!>\n!> \\param[out] SSMAX\n!> \\verbatim\n!> SSMAX is DOUBLE PRECISION\n!> abs(SSMAX) is the larger singular value.\n!> \\endverbatim\n!>\n!> \\param[out] SNL\n!> \\verbatim\n!> SNL is DOUBLE PRECISION\n!> \\endverbatim\n!>\n!> \\param[out] CSL\n!> \\verbatim\n!> CSL is DOUBLE PRECISION\n!> The vector (CSL, SNL) is a unit left singular vector for the\n!> singular value abs(SSMAX).\n!> \\endverbatim\n!>\n!> \\param[out] SNR\n!> \\verbatim\n!> SNR is DOUBLE PRECISION\n!> \\endverbatim\n!>\n!> \\param[out] CSR\n!> \\verbatim\n!> CSR is DOUBLE PRECISION\n!> The vector (CSR, SNR) is a unit right singular vector for the\n!> singular value abs(SSMAX).\n!> \\endverbatim\n!\n! Authors:\n! ========\n!\n!> \\author Univ. of Tennessee\n!> \\author Univ. of California Berkeley\n!> \\author Univ. of Colorado Denver\n!> \\author NAG Ltd.\n!\n!> \\date December 2016\n!\n!> \\ingroup OTHERauxiliary\n!\n!> \\par Further Details:\n! =====================\n!>\n!> \\verbatim\n!>\n!> Any input parameter may be aliased with any output parameter.\n!>\n!> Barring over/underflow and assuming a guard digit in subtraction, all\n!> output quantities are correct to within a few units in the last\n!> place (ulps).\n!>\n!> In IEEE arithmetic, the code works correctly if one matrix element is\n!> infinite.\n!>\n!> Overflow will not occur unless the largest singular value itself\n!> overflows or is within a few ulps of overflow. (On machines with\n!> partial overflow, like the Cray, overflow may occur if the largest\n!> singular value is within a factor of 2 of overflow.)\n!>\n!> Underflow is harmless if underflow is gradual. Otherwise, results\n!> may correspond to a matrix modified by perturbations of size near\n!> the underflow threshold.\n!> \\endverbatim\n!>\n! =====================================================================\n SUBROUTINE DLASV2(F,G,H,Ssmin,Ssmax,Snr,Csr,Snl,Csl)\n IMPLICIT NONE\n!*--DLASV2142\n!\n! -- LAPACK auxiliary routine (version 3.7.0) --\n! -- LAPACK is a software package provided by Univ. of Tennessee, --\n! -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n! December 2016\n!\n! .. Scalar Arguments ..\n DOUBLE PRECISION Csl , Csr , F , G , H , Snl , Snr , Ssmax , Ssmin\n! ..\n!\n! =====================================================================\n!\n! .. Parameters ..\n DOUBLE PRECISION ZERO\n PARAMETER (ZERO=0.0D0)\n DOUBLE PRECISION HALF\n PARAMETER (HALF=0.5D0)\n DOUBLE PRECISION ONE\n PARAMETER (ONE=1.0D0)\n DOUBLE PRECISION TWO\n PARAMETER (TWO=2.0D0)\n DOUBLE PRECISION FOUR\n PARAMETER (FOUR=4.0D0)\n! ..\n! .. Local Scalars ..\n LOGICAL gasmal , swap\n INTEGER pmax\n DOUBLE PRECISION a , clt , crt , d , fa , ft , ga , gt , ha , ht ,&\n & l , m , mm , r , s , slt , srt , t , temp , &\n & tsign , tt\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC ABS , SIGN , SQRT\n! ..\n! .. External Functions ..\n DOUBLE PRECISION DLAMCH\n EXTERNAL DLAMCH\n! ..\n! .. Executable Statements ..\n!\n ft = F\n fa = ABS(ft)\n ht = H\n ha = ABS(H)\n!\n! PMAX points to the maximum absolute element of matrix\n! PMAX = 1 if F largest in absolute values\n! PMAX = 2 if G largest in absolute values\n! PMAX = 3 if H largest in absolute values\n!\n pmax = 1\n swap = (ha>fa)\n IF ( swap ) THEN\n pmax = 3\n temp = ft\n ft = ht\n ht = temp\n temp = fa\n fa = ha\n ha = temp\n!\n! Now FA .ge. HA\n!\n ENDIF\n gt = G\n ga = ABS(gt)\n IF ( ga==ZERO ) THEN\n!\n! Diagonal matrix\n!\n Ssmin = ha\n Ssmax = fa\n clt = ONE\n crt = ONE\n slt = ZERO\n srt = ZERO\n ELSE\n gasmal = .TRUE.\n IF ( ga>fa ) THEN\n pmax = 2\n IF ( (fa/ga)ONE ) THEN\n Ssmin = fa/(ga/ha)\n ELSE\n Ssmin = (fa/ga)*ha\n ENDIF\n clt = ONE\n slt = ht/gt\n srt = ONE\n crt = ft/gt\n ENDIF\n ENDIF\n IF ( gasmal ) THEN\n!\n! Normal case\n!\n d = fa - ha\n IF ( d==fa ) THEN\n!\n! Copes with infinite F or H\n!\n l = ONE\n ELSE\n l = d/fa\n ENDIF\n!\n! Note that 0 .le. L .le. 1\n!\n m = gt/ft\n!\n! Note that abs(M) .le. 1/macheps\n!\n t = TWO - l\n!\n! Note that T .ge. 1\n!\n mm = m*m\n tt = t*t\n s = SQRT(tt+mm)\n!\n! Note that 1 .le. S .le. 1 + 1/macheps\n!\n IF ( l==ZERO ) THEN\n r = ABS(m)\n ELSE\n r = SQRT(l*l+mm)\n ENDIF\n!\n! Note that 0 .le. R .le. 1 + 1/macheps\n!\n a = HALF*(s+r)\n!\n! Note that 1 .le. A .le. 1 + abs(M)\n!\n Ssmin = ha/a\n Ssmax = fa*a\n IF ( mm/=ZERO ) THEN\n t = (m/(s+t)+m/(r+l))*(ONE+a)\n!\n! Note that M is very tiny\n!\n ELSEIF ( l==ZERO ) THEN\n t = SIGN(TWO,ft)*SIGN(ONE,gt)\n ELSE\n t = gt/SIGN(d,ft) + m/t\n ENDIF\n l = SQRT(t*t+FOUR)\n crt = TWO/l\n srt = t/l\n clt = (crt+srt*m)/a\n slt = (ht/ft)*srt/a\n ENDIF\n ENDIF\n IF ( swap ) THEN\n Csl = srt\n Snl = crt\n Csr = slt\n Snr = clt\n ELSE\n Csl = clt\n Snl = slt\n Csr = crt\n Snr = srt\n ENDIF\n!\n! Correct signs of SSMAX and SSMIN\n!\n IF ( pmax==1 ) tsign = SIGN(ONE,Csr)*SIGN(ONE,Csl)*SIGN(ONE,F)\n IF ( pmax==2 ) tsign = SIGN(ONE,Snr)*SIGN(ONE,Csl)*SIGN(ONE,G)\n IF ( pmax==3 ) tsign = SIGN(ONE,Snr)*SIGN(ONE,Snl)*SIGN(ONE,H)\n Ssmax = SIGN(Ssmax,tsign)\n Ssmin = SIGN(Ssmin,tsign*SIGN(ONE,F)*SIGN(ONE,H))\n!\n! End of DLASV2\n!\n END SUBROUTINE DLASV2\n", "meta": {"hexsha": "02b64aeedc617aa5887412aaa3314f36e37a984e", "size": 8301, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/double/dlasv2.f90", "max_stars_repo_name": "urbanjost/spag_lapack", "max_stars_repo_head_hexsha": "1b082638c0ff5feb1a295a3aa4624c538d14847c", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2022-03-04T13:15:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-04T17:40:26.000Z", "max_issues_repo_path": "src/double/dlasv2.f90", "max_issues_repo_name": "urbanjost/spag_lapack", "max_issues_repo_head_hexsha": "1b082638c0ff5feb1a295a3aa4624c538d14847c", "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": "src/double/dlasv2.f90", "max_forks_repo_name": "urbanjost/spag_lapack", "max_forks_repo_head_hexsha": "1b082638c0ff5feb1a295a3aa4624c538d14847c", "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": 25.6203703704, "max_line_length": 111, "alphanum_fraction": 0.5093362246, "num_tokens": 2644, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528170040852, "lm_q2_score": 0.8006920068519378, "lm_q1q2_score": 0.6821518107901626}} {"text": "*DECK BISECT\n SUBROUTINE BISECT (N, EPS1, D, E, E2, LB, UB, MM, M, W, IND, IERR,\n + RV4, RV5)\nC***BEGIN PROLOGUE BISECT\nC***PURPOSE Compute the eigenvalues of a symmetric tridiagonal matrix\nC in a given interval using Sturm sequencing.\nC***LIBRARY SLATEC (EISPACK)\nC***CATEGORY D4A5, D4C2A\nC***TYPE SINGLE PRECISION (BISECT-S)\nC***KEYWORDS EIGENVALUES, EISPACK\nC***AUTHOR Smith, B. T., et al.\nC***DESCRIPTION\nC\nC This subroutine is a translation of the bisection technique\nC in the ALGOL procedure TRISTURM by Peters and Wilkinson.\nC HANDBOOK FOR AUTO. COMP., VOL.II-LINEAR ALGEBRA, 418-439(1971).\nC\nC This subroutine finds those eigenvalues of a TRIDIAGONAL\nC SYMMETRIC matrix which lie in a specified interval,\nC using bisection.\nC\nC On INPUT\nC\nC N is the order of the matrix. N is an INTEGER variable.\nC\nC EPS1 is an absolute error tolerance for the computed\nC eigenvalues. If the input EPS1 is non-positive,\nC it is reset for each submatrix to a default value,\nC namely, minus the product of the relative machine\nC precision and the 1-norm of the submatrix.\nC EPS1 is a REAL variable.\nC\nC D contains the diagonal elements of the input matrix.\nC D is a one-dimensional REAL array, dimensioned D(N).\nC\nC E contains the subdiagonal elements of the input matrix\nC in its last N-1 positions. E(1) is arbitrary.\nC E is a one-dimensional REAL array, dimensioned E(N).\nC\nC E2 contains the squares of the corresponding elements of E.\nC E2(1) is arbitrary. E2 is a one-dimensional REAL array,\nC dimensioned E2(N).\nC\nC LB and UB define the interval to be searched for eigenvalues.\nC If LB is not less than UB, no eigenvalues will be found.\nC LB and UB are REAL variables.\nC\nC MM should be set to an upper bound for the number of\nC eigenvalues in the interval. WARNING - If more than\nC MM eigenvalues are determined to lie in the interval,\nC an error return is made with no eigenvalues found.\nC MM is an INTEGER variable.\nC\nC On OUTPUT\nC\nC EPS1 is unaltered unless it has been reset to its\nC (last) default value.\nC\nC D and E are unaltered.\nC\nC Elements of E2, corresponding to elements of E regarded\nC as negligible, have been replaced by zero causing the\nC matrix to split into a direct sum of submatrices.\nC E2(1) is also set to zero.\nC\nC M is the number of eigenvalues determined to lie in (LB,UB).\nC M is an INTEGER variable.\nC\nC W contains the M eigenvalues in ascending order.\nC W is a one-dimensional REAL array, dimensioned W(MM).\nC\nC IND contains in its first M positions the submatrix indices\nC associated with the corresponding eigenvalues in W --\nC 1 for eigenvalues belonging to the first submatrix from\nC the top, 2 for those belonging to the second submatrix, etc.\nC IND is an one-dimensional INTEGER array, dimensioned IND(MM).\nC\nC IERR is an INTEGER flag set to\nC Zero for normal return,\nC 3*N+1 if M exceeds MM. In this case, M contains the\nC number of eigenvalues determined to lie in\nC (LB,UB).\nC\nC RV4 and RV5 are one-dimensional REAL arrays used for temporary\nC storage, dimensioned RV4(N) and RV5(N).\nC\nC The ALGOL procedure STURMCNT contained in TRISTURM\nC appears in BISECT in-line.\nC\nC Note that subroutine TQL1 or IMTQL1 is generally faster than\nC BISECT, if more than N/4 eigenvalues are to be found.\nC\nC Questions and comments should be directed to B. S. Garbow,\nC Applied Mathematics Division, ARGONNE NATIONAL LABORATORY\nC ------------------------------------------------------------------\nC\nC***REFERENCES B. T. Smith, J. M. Boyle, J. J. Dongarra, B. S. Garbow,\nC Y. Ikebe, V. C. Klema and C. B. Moler, Matrix Eigen-\nC system Routines - EISPACK Guide, Springer-Verlag,\nC 1976.\nC***ROUTINES CALLED R1MACH\nC***REVISION HISTORY (YYMMDD)\nC 760101 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890831 Modified array declarations. (WRB)\nC 890831 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE BISECT\nC\n INTEGER I,J,K,L,M,N,P,Q,R,S,II,MM,M1,M2,TAG,IERR,ISTURM\n REAL D(*),E(*),E2(*),W(*),RV4(*),RV5(*)\n REAL U,V,LB,T1,T2,UB,XU,X0,X1,EPS1,MACHEP,S1,S2\n INTEGER IND(*)\n LOGICAL FIRST\nC\n SAVE FIRST, MACHEP\n DATA FIRST /.TRUE./\nC***FIRST EXECUTABLE STATEMENT BISECT\n IF (FIRST) THEN\n MACHEP = R1MACH(4)\n ENDIF\n FIRST = .FALSE.\nC\n IERR = 0\n TAG = 0\n T1 = LB\n T2 = UB\nC .......... LOOK FOR SMALL SUB-DIAGONAL ENTRIES ..........\n DO 40 I = 1, N\n IF (I .EQ. 1) GO TO 20\n S1 = ABS(D(I)) + ABS(D(I-1))\n S2 = S1 + ABS(E(I))\n IF (S2 .GT. S1) GO TO 40\n 20 E2(I) = 0.0E0\n 40 CONTINUE\nC .......... DETERMINE THE NUMBER OF EIGENVALUES\nC IN THE INTERVAL ..........\n P = 1\n Q = N\n X1 = UB\n ISTURM = 1\n GO TO 320\n 60 M = S\n X1 = LB\n ISTURM = 2\n GO TO 320\n 80 M = M - S\n IF (M .GT. MM) GO TO 980\n Q = 0\n R = 0\nC .......... ESTABLISH AND PROCESS NEXT SUBMATRIX, REFINING\nC INTERVAL BY THE GERSCHGORIN BOUNDS ..........\n 100 IF (R .EQ. M) GO TO 1001\n TAG = TAG + 1\n P = Q + 1\n XU = D(P)\n X0 = D(P)\n U = 0.0E0\nC\n DO 120 Q = P, N\n X1 = U\n U = 0.0E0\n V = 0.0E0\n IF (Q .EQ. N) GO TO 110\n U = ABS(E(Q+1))\n V = E2(Q+1)\n 110 XU = MIN(D(Q)-(X1+U),XU)\n X0 = MAX(D(Q)+(X1+U),X0)\n IF (V .EQ. 0.0E0) GO TO 140\n 120 CONTINUE\nC\n 140 X1 = MAX(ABS(XU),ABS(X0)) * MACHEP\n IF (EPS1 .LE. 0.0E0) EPS1 = -X1\n IF (P .NE. Q) GO TO 180\nC .......... CHECK FOR ISOLATED ROOT WITHIN INTERVAL ..........\n IF (T1 .GT. D(P) .OR. D(P) .GE. T2) GO TO 940\n M1 = P\n M2 = P\n RV5(P) = D(P)\n GO TO 900\n 180 X1 = X1 * (Q-P+1)\n LB = MAX(T1,XU-X1)\n UB = MIN(T2,X0+X1)\n X1 = LB\n ISTURM = 3\n GO TO 320\n 200 M1 = S + 1\n X1 = UB\n ISTURM = 4\n GO TO 320\n 220 M2 = S\n IF (M1 .GT. M2) GO TO 940\nC .......... FIND ROOTS BY BISECTION ..........\n X0 = UB\n ISTURM = 5\nC\n DO 240 I = M1, M2\n RV5(I) = UB\n RV4(I) = LB\n 240 CONTINUE\nC .......... LOOP FOR K-TH EIGENVALUE\nC FOR K=M2 STEP -1 UNTIL M1 DO --\nC (-DO- NOT USED TO LEGALIZE -COMPUTED GO TO-) ..........\n K = M2\n 250 XU = LB\nC .......... FOR I=K STEP -1 UNTIL M1 DO -- ..........\n DO 260 II = M1, K\n I = M1 + K - II\n IF (XU .GE. RV4(I)) GO TO 260\n XU = RV4(I)\n GO TO 280\n 260 CONTINUE\nC\n 280 IF (X0 .GT. RV5(K)) X0 = RV5(K)\nC .......... NEXT BISECTION STEP ..........\n 300 X1 = (XU + X0) * 0.5E0\n S1 = 2.0E0*(ABS(XU) + ABS(X0) + ABS(EPS1))\n S2 = S1 + ABS(X0 - XU)\n IF (S2 .EQ. S1) GO TO 420\nC .......... IN-LINE PROCEDURE FOR STURM SEQUENCE ..........\n 320 S = P - 1\n U = 1.0E0\nC\n DO 340 I = P, Q\n IF (U .NE. 0.0E0) GO TO 325\n V = ABS(E(I)) / MACHEP\n IF (E2(I) .EQ. 0.0E0) V = 0.0E0\n GO TO 330\n 325 V = E2(I) / U\n 330 U = D(I) - X1 - V\n IF (U .LT. 0.0E0) S = S + 1\n 340 CONTINUE\nC\n GO TO (60,80,200,220,360), ISTURM\nC .......... REFINE INTERVALS ..........\n 360 IF (S .GE. K) GO TO 400\n XU = X1\n IF (S .GE. M1) GO TO 380\n RV4(M1) = X1\n GO TO 300\n 380 RV4(S+1) = X1\n IF (RV5(S) .GT. X1) RV5(S) = X1\n GO TO 300\n 400 X0 = X1\n GO TO 300\nC .......... K-TH EIGENVALUE FOUND ..........\n 420 RV5(K) = X1\n K = K - 1\n IF (K .GE. M1) GO TO 250\nC .......... ORDER EIGENVALUES TAGGED WITH THEIR\nC SUBMATRIX ASSOCIATIONS ..........\n 900 S = R\n R = R + M2 - M1 + 1\n J = 1\n K = M1\nC\n DO 920 L = 1, R\n IF (J .GT. S) GO TO 910\n IF (K .GT. M2) GO TO 940\n IF (RV5(K) .GE. W(L)) GO TO 915\nC\n DO 905 II = J, S\n I = L + S - II\n W(I+1) = W(I)\n IND(I+1) = IND(I)\n 905 CONTINUE\nC\n 910 W(L) = RV5(K)\n IND(L) = TAG\n K = K + 1\n GO TO 920\n 915 J = J + 1\n 920 CONTINUE\nC\n 940 IF (Q .LT. N) GO TO 100\n GO TO 1001\nC .......... SET ERROR -- UNDERESTIMATE OF NUMBER OF\nC EIGENVALUES IN INTERVAL ..........\n 980 IERR = 3 * N + 1\n 1001 LB = T1\n UB = T2\n RETURN\n END\n", "meta": {"hexsha": "03891425a3e5bd2d76924ebe096e22dabda07008", "size": 9021, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/bisect.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/bisect.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/bisect.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.6526315789, "max_line_length": 72, "alphanum_fraction": 0.5356390644, "num_tokens": 3072, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528094861981, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.6821517986928405}} {"text": "PROGRAM volterrasolve\n\n! Tom Hagstrom wrote this to solve the same 2nd-kind Volterra IE as AHB's\n! test_volterra.m\n\nUSE volterra \n\nUSE SpecFuns\n\nIMPLICIT NONE \n\nINTEGER :: q,nnodes,n,m,j,it,nsteps,im,jdat \nDOUBLE PRECISION, DIMENSION(:), ALLOCATABLE :: c,u\nDOUBLE PRECISION :: ttot,err,size,t,ermax,dt,g,tspan,val \n\ntspan=1.d0 \nttot=100.d0 \n\nnnodes=128\n\nn=8 \nq=4\n\nDO im=1,4 \n!\n m=10*im+q+1\n nnodes=16*im \n ermax=0.d0\n jdat=19+im\n OPEN(UNIT=jdat)\n ALLOCATE(u(0:m),c(0:m))\n CALL BuildCofs(q,nnodes,tspan,Ker,m,dt,c)\n u=0.d0\n!\n nsteps=INT(100.d0/dt)\n!\n DO it=1,nsteps \n t=DBLE(it)*dt \n CALL f(t,val)\n u(m)=val \n DO j=0,m-1\n u(m)=u(m)-c(j)*u(j)\n END DO \n u(m)=u(m)/c(m) \n err=abs(u(m)-sol(t))\n WRITE (jdat,*)t,u(m)\n IF (err > ermax) THEN\n ermax=err\n END IF \n!\n! Shuffle\n!\n DO j=0,m-1\n u(j)=u(j+1)\n END DO\n END DO\n!\n PRINT *,dt,ermax\n DEALLOCATE(c,u) \n CLOSE(UNIT=jdat)\n!\nEND DO\n\nCONTAINS\n\nDOUBLE PRECISION FUNCTION sol(t)\n\nDOUBLE PRECISION, INTENT(IN) :: t\n\nsol=(1.d0+TANH(2.d0*(t-10.d0)))*SIN(20.d0*t)\n\nEND FUNCTION sol\n\nDOUBLE PRECISION FUNCTION Ker(t)\n\nDOUBLE PRECISION, INTENT(IN) :: t\n\nKer=1.d0\n\nEND FUNCTION Ker\n\nSUBROUTINE f(t,val)\n\nDOUBLE PRECISION, INTENT(IN) :: t\nDOUBLE PRECISION, INTENT(OUT) :: val \nDOUBLE PRECISION, DIMENSION(0:1024), SAVE :: s,w\nLOGICAL :: first_call=.TRUE.\nINTEGER :: j\n\nIF (first_call) THEN\n CALL GaussQCofs(s,w,1024)\n s=.5d0*tspan*(s+1.d0)\n w=.5d0*tspan*w\n first_call=.FALSE.\nEND IF \n\nval=sol(t)\n\nDO j=0,1024 \n val=val+w(j)*Ker(s(j))*sol(t-s(j))\nEND DO\n\nEND SUBROUTINE f \n\nEND PROGRAM volterrasolve \n\n", "meta": {"hexsha": "b84b787220c323539b781b4004af3202754fe14d", "size": 1605, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "timedomainwaveeqn/timeinterp/volterrasolve.f90", "max_stars_repo_name": "ahbarnett/BIE3D", "max_stars_repo_head_hexsha": "12f35cecc97d6a106540e54a2a875b66ea6eebc7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2018-12-06T03:34:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-30T01:40:08.000Z", "max_issues_repo_path": "timedomainwaveeqn/timeinterp/volterrasolve.f90", "max_issues_repo_name": "ahbarnett/BIE3D", "max_issues_repo_head_hexsha": "12f35cecc97d6a106540e54a2a875b66ea6eebc7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "timedomainwaveeqn/timeinterp/volterrasolve.f90", "max_forks_repo_name": "ahbarnett/BIE3D", "max_forks_repo_head_hexsha": "12f35cecc97d6a106540e54a2a875b66ea6eebc7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2019-03-03T22:57:27.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-08T19:56:33.000Z", "avg_line_length": 15.0, "max_line_length": 73, "alphanum_fraction": 0.6342679128, "num_tokens": 633, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476800298183, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.6820625950557898}} {"text": "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!\n!! LowPassFilterModule -- A Fortran 90 module for low-pass filtering of\n!! discrete graph signals.\n!!\n!! This module provides the core procedures that implement the low-pass\n!! filtering of discrete graph signals described in [1,2]. By generalizing\n!! classical discrete fourier analysis to discrete graph signals --\n!! functions defined on the nodes of an undirected graph -- the problem\n!! of smoothing is reduced to that of low-pass filtering.\n!!\n!! Classical Fourier analysis decomposes a signal into the eigencomponents\n!! of the Laplacian, so to extend Fourier analysis to discrete graph signals,\n!! one merely needs to define a generalized laplacian on the graph. The\n!! simplest definition, and the one used here, is to define the \"laplacian\"\n!! at a node to be the difference between the signal at that node and the\n!! mean of the signals at the neighboring nodes.\n!!\n!! In the context of surface and mesh smoothing, the relevent discrete graph\n!! signal is the node coordinates on the graph associated with the simplicial\n!! mesh. In this instance, we may desire that the filtering preserve\n!! certain intrinsic topological features of mesh as well as some extrinsic\n!! \"geometric\" features. This is easily accomplished by modifying the\n!! neighbor structure of the graph (see CreateLaplacian below).\n!!\n!! [1] Gabriel Taubin, \"A signal processing approach to fair surface design\".\n!! Computer Graphics, p351-358, August 1995 (Proceedings SIGGRAPH'95).\n!! [2] Taubin, Zhang, and Golub, \"Optimal surface smoothing as filter design\".\n!! IBM research report, RC-20404(#90237), Computer Sciences, 3/12/96.\n!!\n!! PROGRAMMING INTERFACE\n!!\n!! A integer parameter, r8, is provided that gives the kind value of all\n!! reals used in the module. Typically this should correspond to\n!! 8-byte reals.\n!!\n!! An ADT, ASetType, is provided to facilitate the construction of the\n!! Laplacian (see CreateLaplacian below). It has a single component\n!! which is a pointer to a rank-1 integer array.\n!!\n!! call HammingFilterCoef (f, n, k_pb [,sigma]) returns the polynomial\n!! coefficients of the Nth degree Hamming filter. The coefficients\n!! are normalized to sum to 1, which make them, strictly speaking,\n!! not the true Hamming coefficients. F is an intent(out), rank-1,\n!! real array containing the filter coefficients. Its length must be\n!! at least N+1. K_PB is a real intent(in) variable that specifies\n!! the pass-band value, and should lie within the interval (0,2).\n!! The Hamming filter can be regarded as the convolution of the ideal\n!! low-pass filter with a mollification kernel that is a trig series\n!! defined by the filter coefficients. If the real, intent(in)\n!! variable SIGMA is not present, the pass-band is shifted right by\n!! an amount equal to the radius of this mollification kernel. This\n!! assures that the filter will be approximately 1 in the entire\n!! interval (0, K_PB). If SIGMA is present, its value is used as the\n!! shift amount.\n!!\n!! PolynomialFilter (x, f) returns the filtered \"signal\". F is a rank-1,\n!! real, intent(in) array that contains the coefficients of a polynomial\n!! filter, such as is returned by HammingFilterCoef. X is a rank-2,\n!! real, intent(in) array that contains the input \"signal\"; X(:,j) is\n!! the signal at node j.\n!!\n!! GaussianFilter (x, lambda) returns the Gaussian filtered \"signal\".\n!! LAMBDA is a real, intent(in) variable, and X is a rank-2, real,\n!! intent(in) array that contains the input \"signal\". The filtered\n!! signal is simply X - LAMBDA * Laplacian(X).\n!!\n!! call CreateLaplacian (mask, xset, aset, cvtx [,cnbr, cmat]) constructs\n!! the Laplacian that is central to the filtering algorithm.\n!!\n!! Unless otherwise noted, all arguments are intent(in).\n!!\n!! MASK is a rank-1, integer array. Node j is ignored if MASK(j) == 0.\n!!\n!! CVTX is a rank-2 integer array giving the vertices of the\n!! simplicial cells which form the mesh. CVTX(:,j) are the\n!! vertices of cell j.\n!!\n!! CNBR is a rank-2 integer array giving the neighbors of the cells.\n!! CNBR(:,j) are the neighbors of cell j encoded in the following\n!! manner. If cells j and j' are adjacent, with face k of cell j\n!! and face k' of cell j' being the shared face then\n!! CNBR(k,j) = k' + n * (j'-1) and CNBR(k',j') = k + n * (j-1)\n!! where n is the number of vertices of the simplicial cell.\n!! If CNBR(k,j) = 0 then this face is a boundary face, and if\n!! CNBR(k,j) < 0 then this is a material interface face, with\n!! |CNBR(k,j)| giving the neighbor encoded as above.\n!!\n!! CMAT is a rank-1, integer array giving the material numbers for\n!! the cells. If adjacent cells have different material numbers\n!! then their shared face should be indicated as a material\n!! interface face in CNBR, and conversely.\n!!\n!! The graph that defines the laplacian is derived from the simplicial\n!! mesh described by CVTX, CNBR, and CMAT. There are two possible\n!! cases. If CNBR and CMAT are present, then the mesh is a multi-\n!! material mesh and there is a distinguished hierarchy of topological\n!! features. For a 3D mesh, there are the 3D material volumes, the\n!! 2D material interface network, the 1D network of interface\n!! boundaries/singularities, and the isolated point set of singularity\n!! points of the 1D network. The neighbors of a node in one class are\n!! restricted to those in the same or subsequent classes. By\n!! modifying the graph in this way, the resulting filtering will respect\n!! these topological features; a material interface, for example, is\n!! smoothed as a unit without regard to connected volume nodes. For\n!! a 2D mesh the situation is similar.\n!!\n!! If CNBR and CMAT are absent, then the mesh is complex of simplicial\n!! cells described completely by CVTX. It may be a simple 2D surface,\n!! for example, or a 2D surface network such as the material interface\n!! network of a multi-material 3D mesh. In any case, there is also\n!! a (shorter) hierarchy of topological features, and the graph\n!! associated with the mesh is modified as above.\n!!\n!! The remaining arguments describe the extrinsic \"geometric\" features\n!! of the mesh that the filtering should respect. This is modeled in\n!! the following way. Associated with each node is an integer set of\n!! \"attributes\" (possibly empty). The neighbors of one node are\n!! restricted to those nodes whose attribute sets contain the attribute\n!! set of the first.\n!!\n!! XSET is a rank-1 integer array giving the attribute set index for\n!! each node. If XSET(j) == 0 the the attribute set for node j\n!! is empty.\n!!\n!! ASET is a rank-1 array of ASetType values. ASET(j) is the jth\n!! attribute set.\n!!\n!! call DeleteLaplacian () deallocates all storage associated with the\n!! Laplacian.\n!!\n!!\n!! CHANGE HISTORY\n!!\n!! $Log: LowPassFilterModule.f90,v $\n!! Revision 2.00 2007/11/05 19:45:45 spchu\n!! Import to CVS\n!!\n!PVCS\n!PVCS Rev 1.2 Sat May 01 22:08:50 1999 nnc\n!PVCSMade argument MASK of CreateLaplacian intent(in).\n!PVCS\n!PVCS Rev 1.1 Mon Nov 30 14:52:40 1998 nnc\n!PVCSAdded documentation.\n!PVCS\n!PVCS Rev 1.0 Mon Nov 16 14:19:00 1998 dcg\n!PVCSInitial revision.\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\nmodule LowPassFilterModule\n \n implicit none\n private\n \n public :: HammingFilterCoef, PolynomialFilter, GaussianFilter, CreateLaplacian, DeleteLaplacian\n private :: laplacian\n \n ! This should give 8-byte reals (double precision)\n integer, parameter, public :: r8 = selected_real_kind (10, 50)\n \n type, public :: ASetType\n integer, dimension(:), pointer :: attr\n end type ASetType\n \n integer, dimension(:), pointer, private, save :: xnbrs, nbrs\n \n contains\n \n subroutine HammingFilterCoef( f, n, k_pb, sigma )\n \n real(kind=r8), dimension(0:), intent(out) :: f\n integer, intent(in) :: n\n real(kind=r8), intent(in) :: k_pb\n real(kind=r8), intent(in), optional :: sigma\n \n integer :: j\n real(kind=r8) :: pi, theta_pb\n real(kind=r8), dimension(0:size(f)-1) :: w\n \n pi = 4.0_r8 * atan(1.0_r8)\n \n theta_pb = acos( 1.0_r8 - 0.5_r8 * k_pb )\n \n if (present(sigma)) then\n theta_pb = theta_pb + sigma\n else\n theta_pb = theta_pb + 1.0_r8 / (0.2331592_r8 + 0.1592799_r8 * n)\n end if\n \n !! Truncated fourier series for ideal LP filter (rectangular window)\n f(0) = theta_pb / pi\n do j = 1, n\n f(j) = 2.0_r8 * sin( j * theta_pb ) / (j * pi)\n end do\n \n !! Hamming window coefficients.\n w(0) = 1.0_r8\n do j = 1, n\n w(j) = 0.54_r8 + 0.46_r8 * cos( j * pi / (n + 1) )\n end do\n \n f = f * w !! The Hamming filter coefficients.\n f = f / sum(f) !! Normalize (strictly speaking this shouldn't be done)\n \n end subroutine HammingFilterCoef\n \n \n function PolynomialFilter( x, f ) result( y )\n \n real(kind=r8), dimension(:,:), intent(inout) :: x\n real(kind=r8), dimension(0:), intent(in) :: f\n real(kind=r8), dimension(size(x,dim=1),size(x,dim=2)) :: y\n \n integer :: n, j\n real(kind=r8), dimension(:,:), pointer :: y0, y1, y2, yt\n real(kind=r8), dimension(size(x,dim=1),size(x,dim=2),3), target :: work\n \n y0 => work(:,:,1)\n y1 => work(:,:,2)\n y2 => work(:,:,3)\n \n n = size(f) - 1\n \n y2 = 0.0_r8\n y1 = f(n) * x\n \n do j = n-1, 1, -1\n y0 = 2.0_r8 * y1 - laplacian(y1) - y2 + f(j) * x\n yt => y2 !! Shift the sequence values\n y2 => y1\n y1 => y0\n y0 => yt\n end do\n \n y = y1 - 0.5_r8 * laplacian(y1) - y2 + f(0) * x\n \n end function PolynomialFilter\n \n \n function GaussianFilter( x, lambda ) result( y )\n \n real(kind=r8), dimension(:,:), intent(inout) :: x\n real(kind=r8), intent(in) :: lambda\n real(kind=r8), dimension(size(x,dim=1),size(x,dim=2)) :: y\n \n y = x - lambda * laplacian(x)\n \n end function GaussianFilter\n \n \n subroutine CreateLaplacian( mask, xset, aset, cvtx, cnbr, cmat )\n \n use GraphModule\n \n integer, dimension(:), intent(in) :: mask ! Node mask\n integer, dimension(:), intent(in) :: xset ! Node attribute set index\n type(ASetType), dimension(:), intent(in) :: aset ! Attribute sets\n integer, dimension(:,:), intent(in) :: cvtx ! Cell vertices\n integer, dimension(:,:), intent(in), optional :: cnbr ! Cell neighbors (encoded)\n integer, dimension(:), intent(in), optional :: cmat ! Cell materials\n \n integer, dimension(size(mask)) :: tag\n integer, dimension(:), pointer :: nbr, index\n integer :: nnod, ncell, nvtx, i, j, k, jnbr, dimen\n logical :: multimaterial\n type(NGraphType) :: g\n \n integer, dimension(3,4), parameter :: tet_face_vtx = &\n reshape( source=(/ 2,3,4, 1,4,3, 1,2,4, 1,3,2 /), shape=(/3,4/) )\n integer, dimension(2,3), parameter :: tri_face_vtx = &\n reshape( source=(/ 2,3, 3,1, 1,2 /), shape=(/2,3/) )\n \n nnod = size(mask)\n nvtx = size(cvtx, dim=1)\n ncell = size(cvtx, dim=2)\n\n tag = mask\n \n if (present(cnbr) .and. present(cmat)) then\n multimaterial = .true.\n else\n multimaterial = .false.\n end if\n \n g = CreateGraph (nnod, directed=.true., mult_edge=.true.)\n \n !! Add the edges of the surface/line network to the graph.\n \n if (multimaterial) then\n \n !! Make an initial pass through the cells adding the edges of\n !! material interface faces and boundary faces only.\n \n do j = 1, ncell\n do k = 1, nvtx\n if (cnbr(k,j) > 0) cycle ! This is an interior face\n if (cnbr(k,j) < 0) then ! This is an interface face\n jnbr = 1 + (abs(cnbr(k,j)) - 1) / nvtx\n if (cmat(jnbr) <= cmat(j)) cycle ! We'll do this one later.\n end if\n select case (nvtx)\n case (3)\n call AddClique (g, cvtx(tri_face_vtx(:,k),j))\n case (4)\n call AddClique (g, cvtx(tet_face_vtx(:,k),j))\n end select\n end do\n end do\n \n dimen = nvtx - 2\n \n else\n \n do j = 1, ncell\n call AddClique (g, cvtx(:,j))\n end do\n \n dimen = nvtx - 1\n \n end if\n \n !! Examine the surface edges to determine the topological hierarchy of\n !! point types: surface interior, surface boundary, and boundary of\n !! surface boundary. Nodes of one type are blinded to those of the\n !! preceding types by dropping the relevent edges.\n \n do j = 1, nnod\n \n call GetNeighborList (g, j, nbr, index)\n if (size(index) == 0) cycle\n \n if (tag(j) == 0) then\n \n call DeleteEdge (g, j) !! Ignore this node; blind it to all other nodes.\n \n else\n \n tag(j) = 0 !! Ignore this node in the subsequent pass throught the cells.\n \n select case (dimen)\n \n case (1) !! Line Network\n \n !! The degree of this node is SIZE(INDEX):\n !! degree = 1 <==> line endpoint node\n !! degree = 2 <==> line interior node\n !! degree > 2 <==> line junction node\n \n if (size(index) /= 2) then !! Blind this node to all other nodes.\n call DeleteEdge (g, j)\n end if\n \n case (2) !! Surface Network\n \n !! index = 1 <==> surface boundary edge\n !! index = 2 <==> surface interior edge\n !! index > 2 <==> surface singularity edge (e.g. triple line edge)\n \n if (any(index /= 2)) then\n \n !! This node lies on a surface boundary or singularity.\n !! Blind it to all nodes but those connected by boundary or\n !! singularity edges by dropping all surface-interior edges.\n \n do i = 1, size(index)\n if (index(i) == 2) then\n call DeleteEdge (g, j, nbr(i))\n end if\n end do\n \n !! The only edges remaining for this node are boundary or singularity\n !! edges which link it to other boundary or singularity nodes.\n !! COUNT(INDEX /= 2) is the resulting degree of this node:\n !! degree = 1 <==> line endpoint node (very strange!)\n !! degree = 2 <==> line interior node\n !! degree > 2 <==> line junction node (e.g. a quadruple point)\n \n if (count(index /= 2) /= 2) then !! Blind this node to all other nodes.\n call DeleteEdge (g, j)\n end if\n \n end if\n \n end select\n \n end if\n \n deallocate (nbr, index)\n \n end do\n \n if (multimaterial) then\n !! Make a second pass through the cells, adding the edges for the material\n !! nodes. Note that the interface and boundary nodes have been masked off.\n do j = 1, ncell\n do k = 1, nvtx\n if (tag(cvtx(k,j)) == 0) cycle\n select case (nvtx)\n case (3)\n call AddEdge (g, cvtx(k,j), cvtx(tri_face_vtx(:,k),j))\n case (4)\n call AddEdge (g, cvtx(k,j), cvtx(tet_face_vtx(:,k),j))\n end select\n end do\n end do\n end if\n \n !! Finally we examine all edges, dropping those that don't respect the hierarchy\n !! of attributes: N is blind to M if there is an attribute of N not shared by M.\n \n do j = 1, nnod\n if (xset(j) == 0) cycle\n call GetNeighborList (g, j, nbr)\n if (size(nbr) == 0) cycle\n do k = 1, size(nbr)\n if (xset(j) == xset(nbr(k))) cycle\n if (xset(nbr(k)) == 0) then\n call DeleteEdge (g, j, nbr(k))\n cycle\n end if\n do i = 1, size(aset(xset(j)) % attr)\n if (any( aset(xset(j)) % attr(i) == aset(xset(nbr(k))) % attr)) cycle\n call DeleteEdge (g, j, nbr(k))\n exit\n end do\n end do\n deallocate (nbr)\n end do\n \n !! Generate the neighbor structure which defines the topological Laplacian.\n call GetNeighborStructure (g, xnbrs, nbrs)\n \n call DeleteGraph (g)\n \n end subroutine CreateLaplacian\n \n \n subroutine DeleteLaplacian( )\n \n deallocate (xnbrs, nbrs)\n \n end subroutine DeleteLaplacian\n \n \n function laplacian (x) result (y)\n \n real(kind=r8), dimension(:,:), intent(in) :: x\n real(kind=r8), dimension(size(x,dim=1),size(x,dim=2)) :: y\n \n integer :: j, degree\n \n do j = 1, size(x,dim=2)\n degree = xnbrs(j+1) - xnbrs(j)\n if (degree == 0) then\n y(:,j) = 0.0_r8\n else\n y(:,j) = x(:,j) - sum( x(:,nbrs(xnbrs(j):xnbrs(j+1)-1)), dim=2 ) / degree\n end if\n end do\n \n end function laplacian\n \nend module LowPassFilterModule\n", "meta": {"hexsha": "078ad32f960fac1a8964618e10c3e0a8bc66db74", "size": 17467, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/LowPassFilterModule.f90", "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/LowPassFilterModule.f90", "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/LowPassFilterModule.f90", "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": 37.6443965517, "max_line_length": 98, "alphanum_fraction": 0.5915154291, "num_tokens": 4797, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767970940975, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6820625880384179}} {"text": "program test\n\n use, intrinsic:: ieee_arithmetic\n use lineclip,only: Ccohensutherland, cohensutherland\n use assert, only: wp, errorstop, assert_isclose\n\n implicit none\n \n call test_lineclip()\n call test_array_lineclip()\n\ncontains\n \nsubroutine test_array_lineclip()\n\n integer, parameter :: Np=2\n real(wp), dimension(Np) :: length, x1,x2,y1,y2\n real(wp),parameter :: xmin=1., ymax=5.,xmax=4., ymin=3.\n real(wp),parameter :: truelength(Np) =[2.40370083, 3.]\n\n x1=[0.,0.]\n y1=[0.,4.]\n x2=[4.,5.]\n y2=[6.,4.]\n\n \n call Ccohensutherland(xmin,ymax,xmax,ymin,Np,x1,y1,x2,y2)\n \n length = hypot((x2-x1), (y2-y1))\n call assert_isclose(length, truelength)\n \n!-----------\n\n call cohensutherland(xmin,ymax,xmax,ymin,x1,y1,x2,y2)\n \n length = hypot((x2-x1), (y2-y1))\n call assert_isclose(length, truelength)\n\n \n print *, 'OK array_lineclip'\n \n\nend subroutine test_array_lineclip\n\n!--------------------\n\nsubroutine test_lineclip()\n\n real(wp), parameter :: xmin=1., ymax=5., xmax=4., ymin=3.\n real(wp) :: x1, y1, x2, y2 !not a parameter\n\n! make box with corners LL/UR (1,3) (4,5)\n! and line segment with ends (0,0) (4,6)\n\n! LOWER to UPPER test \n x1=0.; y1=0.; x2=4.; y2=6.\n\n call cohensutherland(xmin,ymax,xmax,ymin,x1,y1,x2,y2)\n \n call assert_isclose(x1, 2._wp)\n call assert_isclose(y1, 3._wp)\n call assert_isclose(x2, 3.3333333_wp)\n call assert_isclose(y2, 5._wp)\n \n! no intersection test\n x1=0.;y1=0.1;x2=0.;y2=0.1\n \n call cohensutherland(xmin,ymax,xmax,ymin,x1,y1,x2,y2)\n if (.not.all(ieee_is_nan([x1,y1,x2,y2]))) call errorstop() !'failed no intersection test'\n \n print *, 'OK lineclip'\n \nend subroutine test_lineclip\n\n\nend program\n", "meta": {"hexsha": "0a7e8bfe7c9e93c2845fbe7fd7bdd60f693a31ff", "size": 1762, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "DemoLineclip.f90", "max_stars_repo_name": "toddrme2178/lineclipping-python-fortran", "max_stars_repo_head_hexsha": "e6ad96891452d7974a9658d04b24bd58f3b2ddd2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "DemoLineclip.f90", "max_issues_repo_name": "toddrme2178/lineclipping-python-fortran", "max_issues_repo_head_hexsha": "e6ad96891452d7974a9658d04b24bd58f3b2ddd2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "DemoLineclip.f90", "max_forks_repo_name": "toddrme2178/lineclipping-python-fortran", "max_forks_repo_head_hexsha": "e6ad96891452d7974a9658d04b24bd58f3b2ddd2", "max_forks_repo_licenses": ["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.8831168831, "max_line_length": 93, "alphanum_fraction": 0.6231555051, "num_tokens": 607, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476793890012, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6820625855478827}} {"text": " program test_uniax_tens_ps\n use tensor_operations\n\n implicit none\n double precision:: sig, eps, H, C, ome,alp, gam, sig_0, epsp_b,\n & epsp_bn, D_epsp_b,A_c, f, Teps\n !Parameters GTN mode\n double precision:: xE, xnu, sigy0, q1, q2, q3, f_0, f_n, s_n, \n & f_f, E_n, NU, mu, q_el, kap\n double precision :: d_sig_0_d_epsp_b, dsig_deps, df_deps, \n & depsp_b_deps\n double precision :: dp_deps_v, df_deps_v, depsp_b_deps_v, epsv_y\n double precision, dimension(13):: mat_param\n double precision:: l0, uf, Teps_f, D_u ,u, Teps1, D_eps, eps_fi,\n & l, lsi,lf, l_y\n double precision:: pi, steps\n double precision:: ph, eps_vf, epsv, epsv1, D_epsv, eps_y\n integer :: i, stat\n\n mat_param(1) = 300.0*200.0 ! xE\n mat_param(2) = 0.33 ! xnu \n mat_param(3) = 200.0 !200 ! xsigy0\n mat_param(4) = 50.0*mat_param(3); ! 50 ! xH\n mat_param(5) = 100.0*mat_param(3); ! 10 ! xh\n mat_param(6) = 1.5 ! q1 \n mat_param(7) = 1.0 ! q2\n mat_param(8) = 1.5 ! q1=q3 Aricle G.Vadillo\n mat_param(9) = 0.0 ! f_0\n mat_param(10) = 0.04 ! f_n\n mat_param(11) = 0.1 ! s_n\n mat_param(12) = 0.2025 ! f_f\n mat_param(13) = 0.3 ! E_n\n\n xE = mat_param(1)\n xnu = mat_param(2) \n sigy0 = mat_param(3)\n q1 = mat_param(6) \n q2 = mat_param(7)\n q3 = q1**2\n f = mat_param(9)\n f_n = mat_param(10)\n s_n = mat_param(11)\n f_f = mat_param(12)\n E_n = mat_param(13)\n mu = xE/(2.0*(1.0+xnu))\n kap = xE/(3.0*(1.0-2.0*xnu))\n q_el = -0.5*(kap-2.0/3.0*mu)/(kap+1.0/3.0*mu)\n NU = 0.1\n\n pi = 4.D0*DATAN(1.D0)\nc initial values\n \nc=======================================================================\nc Unixial tension Plane stress\nc=======================================================================\nc test on a plane stress element\nc the direction of stressing is at 45\u201d with the X-axis\nc Test test is displacement controlled, with equal increments of 2.5 per cent the original length (I understand that this is the Abaqus job)\n\ncThe set of non-linear equations (32)-(34) is integrated using a forward Euler scheme with equal\ncstrain increments of 1/1000 of the yield strain \n\n D_u=0.2/10000.0\n \n l0=0.004\n Teps_f=0.38 !1.0 maximum true strain \n lf=(DEXP(Teps_f)-1)*l0+l0\n eps_fi=(lf-l0)/l0\n steps=(lf-l0)/D_u\n print*, \"steps\" , steps\n \n i=0\n eps_y=sigy0/xE !Strain at yield point \n l=0\n l=l+eps_y*l0+l0 !Length at yied point\n lsi=l !longitud od start of iteration\n Teps=dlog(1+eps_y) !This must be the logarithmic strain defined as eps_t=ln (1+eps)\n print*, \"eps_y\", eps_y,\"Teps_y\",Teps , \"Length at yied point\", \n & l, \"Final lengt\", lf, \"eps max\"\n & ,eps_fi\n sig=sigy0 !This must be the macroscopic axial true stress defined as sig_t=sig*(1+eps)\n sig_0=sigy0\n epsp_b=0.0\n open(unit=1, iostat=stat, file='data_test_ut_ps.csv', \n $ status='old')\n if (stat == 0) close(1, status='delete')\n open(1, file = 'data_test_ut_ps.csv', status = 'new')\n !u=0.0\n 10 if (lllmax) then \n\t\tWrite(88,*) \"Error in Sbr. PLMBAR_MOD: The degree exceeds 512\", lmax \n\t \tWrite(88,*) \"The program will STOP ----------------\"\n \t Write(* ,*) \"Error in Sbr. PLMBAR_MOD: The degree exceeds 512\", lmax \n\t \tWrite(* ,*) \"The program will STOP ----------------\"\n call stop_config \n\t Stop 2\t\t\n Endif \n!\n!\n!\n! ---- \"z\" is cos(theta), theta is co-latitude \n!\n\tz=cosdd(90.-lat) \n!\n! ---- Builds the SHTOOLS Legendre functions including the Condon-Shortley phase \n!\n \tcall PlmBar(plm, lmax, z, -1) \n!\n!\n! ---- Scales to obtain our Legendre functions, dividing by sqrt(2-delta(0,m))\n! \n \tdo j=1, j_index(lmax,lmax)\n \t\tif(mj(j)/=0) plm(j)=plm(j)/sqrt(2.)\n \tenddo\n!\n END SUBROUTINE PLMBAR_MOD \n!\n!\n!\n", "meta": {"hexsha": "08e8bd2f4e2b45ff30be983f43d844a0b5a2ebd2", "size": 1655, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/plmbar_mod.f90", "max_stars_repo_name": "gassmoeller/selen", "max_stars_repo_head_hexsha": "796ed0c3b994e0a8d447934f3ec2863a2d2804ab", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2016-01-15T16:22:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-11T03:05:48.000Z", "max_issues_repo_path": "src/plmbar_mod.f90", "max_issues_repo_name": "gassmoeller/selen", "max_issues_repo_head_hexsha": "796ed0c3b994e0a8d447934f3ec2863a2d2804ab", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2015-10-14T21:07:01.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T20:08:24.000Z", "max_forks_repo_path": "src/plmbar_mod.f90", "max_forks_repo_name": "gassmoeller/selen", "max_forks_repo_head_hexsha": "796ed0c3b994e0a8d447934f3ec2863a2d2804ab", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2015-08-26T10:55:15.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-01T16:31:11.000Z", "avg_line_length": 28.5344827586, "max_line_length": 81, "alphanum_fraction": 0.5975830816, "num_tokens": 537, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.89330940889474, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6820272343288443}} {"text": "program problem34\n implicit none\n integer, dimension(10) :: factorials\n integer :: i,limit,answer=0\n\n limit=9999999 ! seven nines > (9!)*7\n\n factorials(1)=1\n do i=1,9\n factorials(i+1)=factorials(i)*i\n end do\n\n do i=10,limit\n if (i == transmute(i)) answer=answer+i\n end do\n\n print *, answer\n\ncontains\n pure function transmute(n)\n implicit none\n integer, intent(in) :: n\n integer :: transmute\n integer :: temp\n\n transmute = 0\n temp=n\n do while (temp>0)\n transmute=transmute+factorials(mod(temp,10)+1)\n temp=temp/10\n end do\n end function transmute\n\nend program problem34\n", "meta": {"hexsha": "fc4642e4838feb61000fe4b29974b8a1d762a597", "size": 663, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "problem34.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": "problem34.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": "problem34.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": 18.9428571429, "max_line_length": 53, "alphanum_fraction": 0.6063348416, "num_tokens": 203, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543488, "lm_q2_score": 0.7634837635542925, "lm_q1q2_score": 0.682027227352824}} {"text": "!\n! rhOver - a FORTRAN program to determine magnetic anisotropy and related \n! properties for dysprosium(III) single-ion magnets by semi-empirical approaches\n! Copyright (C) 2014-2019 Michael B\u00f6hme \n!\n! Permission is hereby granted, free of charge, to any person obtaining a copy\n! of this software and associated documentation files (the \"Software\"), to deal\n! in the Software without restriction, including without limitation the rights\n! to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n! copies of the Software, and to permit persons to whom the Software is\n! furnished to do so, subject to the following conditions:\n! \n! The above copyright notice and this permission notice shall be included in all\n! copies or substantial portions of the Software.\n! \n! THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n! SOFTWARE.\n!\n\n! *************************************************************************\n! * spherical harmonics up to l = 15 with m = -l, ..., +l\n! *************************************************************************\nfunction SphericalHarmonicY(l, m, theta, phi) result(res)\n\tuse global_c\n\timplicit none\n!\t\n\tinteger, intent(in) :: l, m\n\tdouble precision, intent(in) :: theta, phi\n\tdouble complex :: res\n\tdouble precision :: costheta, sintheta\n\tdouble complex :: prefac\n!\t\n\tif ( l .ne. 0 ) then\n\t\tcostheta = dcos(theta)\n\tend if\n\t\n\tif ( m .ne. 0 ) then\n\t\n\t\tsintheta = dsin(theta)\n\t\tprefac = cdexp( m * cmplx(0.0, 1.0) * phi ) \n\t\tif ( m .gt. 0 ) then\n\t\t\tprefac = prefac * ( - 1 )**m\n\t\tend if\n\t\t\n\tend if\n\n\tselect case ( l )\n\t\n\t\tcase ( 0 )\n\t\t\tres = 0.5d0 / dsqrt( pi )\n\t\t\treturn\n\t\t\t\n\t\tcase ( 1 )\n\t\t\t\n\t\t\tselect case ( m )\n\t\t\t\tcase ( -1, 1)\n\t\t\t\t\tres = 0.5d0 * prefac * dsqrt( 3.0d0 / ( 2.0d0 * pi) ) * sintheta\n\t\t\t\t\treturn\n\t\t\t\tcase ( 0 )\n\t\t\t\t\tres = 0.5d0 * dsqrt( 3.0d0 / pi ) * costheta\n\t\t\t\t\treturn\n\t\t\tend select\n\t\t\t\n\t\tcase ( 2 )\n\t\t\t\n\t\t\tselect case ( m )\n\t\t\t\tcase ( -2, 2 )\n\t\t\t\t\tres = 0.25d0 * prefac * dsqrt( 15.0d0 / ( 2.0d0 * pi ) ) * &\n\t\t\t\t\t\tsintheta**2\n\t\t\t\t\treturn\n\t\t\t\tcase ( -1, 1 )\n\t\t\t\t\tres = 0.50d0 * prefac * dsqrt( 15.0d0 / ( 2.0d0 * pi ) ) * &\n\t\t\t\t\t\tsintheta * costheta\n\t\t\t\t\treturn\n\t\t\t\tcase ( 0 )\n\t\t\t\t\tres = 0.25d0 * dsqrt( 5.0d0 / pi ) * ( 3.d0 * costheta**2 - 1.0d0 )\n\t\t\t\t\treturn\n\t\t\tend select\n\t\t\t\n\t\tcase ( 3 )\n\t\t\n\t\t\tselect case ( m )\n\t\t\t\tcase ( -3, 3 )\n\t\t\t\t\tres = 0.125d0 * prefac * dsqrt( 35.0d0 / pi ) * &\n\t\t\t\t\t\tsintheta**3\n\t\t\t\t\treturn\n\t\t\t\tcase ( -2, 2 )\n\t\t\t\t\tres = 0.250d0 * prefac * dsqrt( 105.d0 / ( 2.0d0 * pi ) ) * &\n\t\t\t\t\t\tsintheta**2 * costheta\n\t\t\t\t\treturn\n\t\t\t\tcase ( -1, 1 )\n\t\t\t\t\tres = 0.125d0 * prefac * dsqrt( 21.d0 / pi ) * &\n\t\t\t\t\t\tsintheta * ( 5.0d0 * costheta**2 - 1.0d0 )\n\t\t\t\t\treturn\n\t\t\t\tcase ( 0 )\n\t\t\t\t\tres = 0.25d0 * dsqrt( 7.0d0 / pi ) * ( 5.d0 * costheta**3 - 3.0d0 * costheta )\n\t\t\t\t\treturn\n\t\t\tend select\n\t\t\t\n\t\tcase ( 4 )\n\t\t\n\t\t\tselect case ( m )\n\t\t\t\tcase ( -4, 4 )\n\t\t\t\t\tres = 3.0d0 / 16.0d0 * prefac * dsqrt( 35.0d0 / ( 2.0d0 * pi ) ) * &\n\t\t\t\t\t\tsintheta**4\n\t\t\t\t\treturn\n\t\t\t\tcase ( -3, 3 )\n\t\t\t\t\tres = 3.0d0 / 8.0d0 * prefac * dsqrt( 35.0d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**3 * costheta\n\t\t\t\t\treturn\n\t\t\t\tcase ( -2, 2 )\n\t\t\t\t\tres = 3.0d0 / 8.0d0 * prefac * dsqrt( 5.0d0 / ( 2.0d0 * pi ) ) * &\n\t\t\t\t\t\tsintheta**2 * ( 7.0d0 * costheta**2 - 1 )\n\t\t\t\t\treturn\n\t\t\t\tcase ( -1, 1 )\n\t\t\t\t\tres = 3.0d0 / 8.0d0 * prefac * dsqrt( 5.0d0 / ( pi ) ) * &\n\t\t\t\t\t\tcostheta * sintheta * ( 7.0d0 * costheta**2 - 3.0d0 )\n\t\t\t\t\treturn\n\t\t\t\tcase ( 0 )\n\t\t\t\t\tres = 3.0d0 * ( 35d0*costheta**4 - 30d0*costheta**2 + 3d0) / ( 16d0 * dsqrt( pi ) )\n\t\t\t\t\treturn\n\t\t\tend select\n\t\t\t\n\t\tcase ( 5 )\n\t\t\t\n\t\t\tselect case ( m )\n\t\t\t\tcase ( -5, 5 )\n\t\t\t\t\tres = 3.0d0 / 32.d0 * prefac * dsqrt( 77.0d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**5\n\t\t\t\t\treturn\n\t\t\t\tcase ( -4, 4 )\n\t\t\t\t\tres = 3.0d0 / 16.d0 * prefac * dsqrt( 385.0d0 / ( 2.0d0 * pi ) ) * &\n\t\t\t\t\t\tsintheta**4 * costheta\n\t\t\t\t\treturn\n\t\t\t\tcase ( -3, 3 )\n\t\t\t\t\tres = 1.0d0 / 32.d0 * prefac * dsqrt( 385.0d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**3 * ( 9.0d0 * costheta**2 - 1.0d0 )\n\t\t\t\t\treturn\n\t\t\t\tcase ( -2, 2 )\n\t\t\t\t\tres = 1.0d0 / 8.d0 * prefac * dsqrt( 1155.0d0 / ( 2.0d0 * pi ) ) * &\n\t\t\t\t\t\tsintheta**2 * costheta * ( 3.0d0*costheta**2 - 1.0d0 )\n\t\t\t\t\treturn\n\t\t\t\tcase ( -1, 1 )\n\t\t\t\t\tres = 1.0d0 / 16.d0 * prefac * dsqrt( 165.0d0 / ( 2.0d0 * pi ) ) * &\n\t\t\t\t\t\tsintheta * ( 21.0d0 * costheta**4 - 14.0d0 * costheta**2 + 1.0d0 )\n\t\t\t\t\treturn\n\t\t\t\tcase ( 0 )\n\t\t\t\t\tres = 1.0d0 / 16.d0 * dsqrt( 11.0d0 / pi ) * &\n\t\t\t\t\t\t( 63.0d0*costheta**5 - 70.0d0*costheta**3 + 15.0d0*costheta )\n\t\t\t\t\treturn\n\t\t\tend select\n\t\t\t\n\t\tcase ( 6 )\n\t\t\n\t\t\tselect case ( m )\n\t\t\t\tcase ( -6, 6 )\n\t\t\t\t\tres = prefac / 64.0d0 * dsqrt( 3003.0d0 / pi ) * &\n\t\t\t\t\t\tsintheta**6\n\t\t\t\t\treturn\n\t\t\t\tcase ( -5, 5 )\n\t\t\t\t\tres = 3.0d0 / 32.0d0 * prefac * dsqrt( 1001.0d0 / pi ) * &\n\t\t\t\t\t\tsintheta**5 * costheta\n\t\t\t\t\treturn\n\t\t\t\tcase ( -4, 4 )\n\t\t\t\t\tres = 3.0d0 / 32.0d0 * prefac * dsqrt( 91.0d0 / ( 2.0d0 * pi ) ) * &\n\t\t\t\t\t\tsintheta**4 * ( 11.0d0 * costheta**2 - 1.d0 )\n\t\t\t\t\treturn\n\t\t\t\tcase ( -3, 3 )\n\t\t\t\t\tres = 1.0d0 / 32.0d0 * prefac * dsqrt( 1365.0d0 / pi ) * &\n\t\t\t\t\t\tsintheta**3 * costheta * ( 11.0d0 * costheta**2 - 3.d0 )\n\t\t\t\t\treturn\n\t\t\t\tcase ( -2, 2 )\n\t\t\t\t\tres = 1.0d0 / 64.0d0 * prefac * dsqrt( 1365.0d0 / pi ) * &\n\t\t\t\t\t\tsintheta**2 * ( 33.0d0 * costheta**4 - 18.d0 * costheta**2 + 1.d0 )\n\t\t\t\t\treturn\n\t\t\t\tcase ( -1, 1 )\n\t\t\t\t\tres = 1.0d0 / 16.0d0 * prefac * dsqrt( 273.0d0 / ( 2.0d0 * pi ) ) * &\n\t\t\t\t\t\tsintheta * costheta * ( 33.0d0 * costheta**4 - 30.d0 * costheta**2 + 5.d0 )\n\t\t\t\t\treturn\n\t\t\t\tcase ( 0 )\n\t\t\t\t\tres = dsqrt(13.d0 / pi) / 32.d0 * ( &\n\t\t\t\t\t\t+ 231.d0 * costheta**6 - 315.0d0 * costheta**4 + 105.d0 * costheta**2 - 5.0d0 )\n\t\t\t\t\treturn\n\t\t\tend select\n\t\t\t\n\t\tcase ( 7 )\n\t\t\n\t\t\tselect case ( m )\n\t\t\t\tcase ( -7, 7 )\n\t\t\t\t\tres = 3.0d0 / 64.0d0 * prefac * dsqrt( 715d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**7\n\t\t\t\t\treturn\n\t\t\t\tcase ( -6, 6 )\n\t\t\t\t\tres = 3.0d0 / 64.0d0 * prefac * dsqrt( 5005d0 / ( pi ) ) * &\n\t\t\t\t\t\tcostheta * sintheta**6\n\t\t\t\t\treturn\n\t\t\t\tcase ( -5, 5 )\n\t\t\t\t\tres = 3.0d0 / 64.0d0 * prefac * dsqrt( 385d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**5 * (13d0*costheta**2 - 1d0)\t\t\t\n\t\t\t\t\treturn\n\t\t\t\tcase ( -4, 4 )\n\t\t\t\t\tres = 3.0d0 / 32.0d0 * prefac * dsqrt( 385d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tcostheta * sintheta**4 * (13d0*costheta**2 - 3d0)\n\t\t\t\t\treturn\t\t\t\n\t\t\t\tcase ( -3, 3 )\n\t\t\t\t\tres = 3.0d0 / 64.0d0 * prefac * dsqrt( 35.0d0 / ( 2.0d0 * pi ) ) * &\n\t\t\t\t\t\tsintheta**3 * (143d0*costheta**4 - 66d0*costheta**2 + 3d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -2, 2 )\t\t\t\t\t\n\t\t\t\t\tres = 3.0d0 / 64.0d0 * prefac * dsqrt( 35.0d0 / ( pi ) ) * &\n\t\t\t\t\t\tcostheta * sintheta**2 * (143d0*costheta**4 - 110d0*costheta**2 + 15d0)\t\t\t\n\t\t\t\t\treturn\n\t\t\t\tcase ( -1, 1 )\t\t\t\t\t\n\t\t\t\t\tres = 1.0d0 / 64.0d0 * prefac * dsqrt( 105.0d0 / ( 2.0d0 * pi ) ) * &\n\t\t\t\t\t\tsintheta * (429d0*costheta**6 - 495d0*costheta**4 + 135d0*costheta**2 - 5d0)\n\t\t\t\t\treturn\t\t\t\n\t\t\t\tcase ( 0 )\n\t\t\t\t\tres = 1d0 / 32d0 * dsqrt(15.d0 / pi) * ( &\n\t\t\t\t\t\t429d0*costheta**7 - 693d0*costheta**5 + 315d0*costheta**3 - 35d0*costheta)\n\t\t\t\t\treturn\n\t\t\tend select\n\t\t\t\n\t\tcase ( 8 )\n\t\t\n\t\t\tselect case ( m )\n\t\t\t\tcase ( -8, 8 )\n\t\t\t\t\tres = 3d0 / 256d0 * prefac * dsqrt( 12155d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**8 \n\t\t\t\t\treturn\t\t\t\n\t\t\t\tcase ( -7, 7 )\n\t\t\t\t\tres = 3d0 / 64d0 * prefac * dsqrt( 12155d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tcostheta * sintheta**7 \n\t\t\t\t\treturn\t\n\t\t\t\tcase ( -6, 6 )\n\t\t\t\t\tres = 1d0 / 128d0 * prefac * dsqrt( 7293d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**6 * ( 15d0*costheta**2 - 1d0 )\t\t\t\n\t\t\t\t\treturn\n\t\t\t\tcase ( -5, 5 )\n\t\t\t\t\tres = 3d0 / 64d0 * prefac * dsqrt( 17017d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tcostheta * sintheta**5 * ( 5d0*costheta**2 - 1d0 )\n\t\t\t\t\treturn\n\t\t\t\tcase ( -4, 4 )\n\t\t\t\t\tres = 3d0 / 128d0 * prefac * dsqrt( 1309d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**4 * ( 65d0*costheta**4 - 26d0*costheta**2 + 1d0 )\t\t\t\n\t\t\t\t\treturn\n\t\t\t\tcase ( -3, 3 )\n\t\t\t\t\tres = 1d0 / 64d0 * prefac * dsqrt( 19635d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tcostheta * sintheta**3 * ( 39d0*costheta**4 - 26d0*costheta**2 + 3d0 )\n\t\t\t\t\treturn\n\t\t\t\tcase ( -2, 2 )\n\t\t\t\t\tres = 3d0 / 128d0 * prefac * dsqrt( 595d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**2 * ( 143d0*costheta**6 - 143d0*costheta**4 + 33d0*costheta**2 - 1d0 )\n\t\t\t\t\treturn\n\t\t\t\tcase ( -1, 1 )\n\t\t\t\t\tres = 3d0 / 64d0 * prefac * dsqrt( 17d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta * costheta * ( 715d0*costheta**6 - 1001d0*costheta**4 + 385d0*costheta**2 - 35d0 )\n\t\t\t\t\treturn\n\t\t\t\tcase ( 0 )\n\t\t\t\t\tres = 1d0/256d0 * dsqrt(17d0/pi) * ( &\n\t\t\t\t\t\t6435d0*costheta**8 - 12012d0*costheta**6 + 6930d0*costheta**4 - 1260d0*costheta**2 + 35d0)\n\t\t\t\t\treturn\n\t\t\tend select\n\t\t\t\n\t\tcase ( 9 )\n\t\t\n\t\t\tselect case ( m )\n\t\t\t\tcase ( -9, 9 )\n\t\t\t\t\tres = 1d0 / 512d0 * prefac * dsqrt( 230945d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**9\n\t\t\t\t\treturn\n\t\t\t\tcase ( -8, 8 )\n\t\t\t\t\tres = 3d0 / 256d0 * prefac * dsqrt( 230945d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**8 * costheta\n\t\t\t\t\treturn\n\t\t\t\tcase ( -7, 7 )\n\t\t\t\t\tres = 3d0 / 512d0 * prefac * dsqrt( 13585d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**7 * ( 17d0*costheta**2 - 1d0 )\t\t\t\n\t\t\t\t\treturn\n\t\t\t\tcase ( -6, 6 )\n\t\t\t\t\tres = 1d0 / 128d0 * prefac * dsqrt( 40755d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**6 * costheta * ( 17d0*costheta**2 - 3d0 )\t\t\t\n\t\t\t\t\treturn\n\t\t\t\tcase ( -5, 5 )\n\t\t\t\t\tres = 3d0 / 256d0 * prefac * dsqrt( 2717d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**5 * ( 85d0*costheta**4 - 30d0*costheta**2 + 1d0 )\n\t\t\t\t\treturn\n\t\t\t\tcase ( -4, 4 )\n\t\t\t\t\tres = 3d0 / 128d0 * prefac * dsqrt( 95095d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**4 *costheta * ( 17d0*costheta**4 - 10d0*costheta**2 + 1d0 )\t\t\t\n\t\t\t\t\treturn\n\t\t\t\tcase ( -3, 3 )\n\t\t\t\t\tres = 1d0 / 256d0 * prefac * dsqrt( 21945d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**3 * ( 221d0*costheta**6 - 195d0*costheta**4 + 39d0*costheta**2 - 1d0 )\n\t\t\t\t\treturn\n\t\t\t\tcase ( -2, 2 )\n\t\t\t\t\tres = 3d0 / 128d0 * prefac * dsqrt( 1045d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**2 * costheta * ( 221d0*costheta**6 - 273d0*costheta**4 + 91d0*costheta**2 - 7d0 )\n\t\t\t\t\treturn\n\t\t\t\tcase ( -1, 1 )\n\t\t\t\t\tres = 3d0 / 256d0 * prefac * dsqrt( 95d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta * ( 2431d0*costheta**8 - 4004d0*costheta**6 + 2002d0*costheta**4 - 308d0*costheta**2 + 7d0 )\n\t\t\t\t\treturn\n\t\t\t\tcase ( 0 )\n\t\t\t\t\tres = 1d0/256d0 * dsqrt(19d0/pi) * ( &\n\t\t\t\t\t\t12155d0*costheta**9 - 25740d0*costheta**7 + 18018d0*costheta**5 - 4620d0*costheta**3 + 315d0*costheta)\t\t\n\t\t\t\t\treturn\n\t\t\tend select\n\t\t\t\n\t\tcase ( 10 )\n\t\t\n\t\t\tselect case ( m )\n\t\t\t\tcase ( -10, 10 )\n\t\t\t\t\tres = 1d0 / 1024d0 * prefac * dsqrt( 969969d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**10\n\t\t\t\t\treturn\t\t\t\n\t\t\t\tcase ( -9, 9 )\n\t\t\t\t\tres = 1d0 / 512d0 * prefac * dsqrt( 4849845d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**9 * costheta\n\t\t\t\t\treturn\n\t\t\t\tcase ( -8, 8 )\n\t\t\t\t\tres = 1d0 / 512d0 * prefac * dsqrt( 255255d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**8 * ( 19d0*costheta**2 - 1d0 )\t\t\t\n\t\t\t\t\treturn\n\t\t\t\tcase ( -7, 7 )\n\t\t\t\t\tres = 3d0 / 512d0 * prefac * dsqrt( 85085d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**7 * costheta * ( 19d0*costheta**2 - 3d0 )\t\t\t\n\t\t\t\t\treturn\n\t\t\t\tcase ( -6, 6 )\n\t\t\t\t\tres = 3d0 / 1024d0 * prefac * dsqrt( 5005d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**6 * ( 323d0*costheta**4 - 102d0*costheta**2 + 3d0 )\t\t\t\n\t\t\t\t\treturn\n\t\t\t\tcase ( -5, 5 )\n\t\t\t\t\tres = 3d0 / 256d0 * prefac * dsqrt( 1001d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**5 * costheta * ( 323d0*costheta**4 - 170d0*costheta**2 + 15d0 )\n\t\t\t\t\treturn\n\t\t\t\tcase ( -4, 4 )\n\t\t\t\t\tres = 3d0 / 256d0 * prefac * dsqrt( 5005d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**4 * ( 323d0*costheta**6 - 255d0*costheta**4 + 45d0*costheta**2 - 1d0 )\n\t\t\t\t\treturn\n\t\t\t\tcase ( -3, 3 )\n\t\t\t\t\tres = 3d0 / 256d0 * prefac * dsqrt( 5005d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**3 * costheta * ( 323d0*costheta**6 - 357d0*costheta**4 + 105d0*costheta**2 - 7d0 )\n\t\t\t\t\treturn\n\t\t\t\tcase ( -2, 2 )\n\t\t\t\t\tres = 3d0 / 512d0 * prefac * dsqrt( 385d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**2 * ( 4199d0*costheta**8 - 6188d0*costheta**6 + 2730d0*costheta**4 - 364d0*costheta**2 + 7d0 )\n\t\t\t\t\treturn\n\t\t\t\tcase ( -1, 1 )\n\t\t\t\t\tres = 1d0 / 256d0 * prefac * dsqrt( 1155d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta * costheta * ( 4199d0*costheta**8 - 7956d0*costheta**6 + 4914d0*costheta**4 - 1092d0*costheta**2 + 63d0 )\n\t\t\t\t\treturn\n\t\t\t\tcase ( 0 )\n\t\t\t\t\tres = 1d0/512d0 * dsqrt(21d0/pi) * ( &\n\t\t\t\t\t\t46189d0*costheta**10 - 109395d0*costheta**8 + 90090d0*costheta**6 - 30030d0*costheta**4 + 3465d0*costheta**2 - 63d0)\n\t\t\t\t\treturn\n\t\t\tend select\n\t\t\t\n\t\tcase ( 11 )\n\t\t\n\t\t\tselect case ( m )\t\n\t\t\t\tcase ( -11, 11 )\n\t\t\t\t\tres = 1d0 / 1024d0 * prefac * dsqrt( 2028117d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**11\n\t\t\t\t\treturn\n\t\t\t\tcase ( -10, 10 )\n\t\t\t\t\tres = 1d0 / 1024d0 * prefac * dsqrt( 22309287d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**10 * costheta\n\t\t\t\t\treturn\n\t\t\t\tcase ( -9, 9 )\n\t\t\t\t\tres = 1d0 / 1024d0 * prefac * dsqrt( 1062347d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**9 * ( 21d0*costheta**2 - 1d0 )\n\t\t\t\t\treturn\n\t\t\t\tcase ( -8, 8 )\n\t\t\t\t\tres = 1d0 / 512d0 * prefac * dsqrt( 15935205d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**8 * costheta * ( 7d0*costheta**2 - 1d0 )\n\t\t\t\t\treturn\n\t\t\t\tcase ( -7, 7 )\n\t\t\t\t\tres = 1d0 / 1024d0 * prefac * dsqrt( 838695d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**7 * ( 133d0*costheta**4 - 38d0*costheta**2 + 1d0 )\n\t\t\t\t\treturn\n\t\t\t\tcase ( -6, 6 )\n\t\t\t\t\tres = 1d0 / 1024d0 * prefac * dsqrt( 167739d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**6 * costheta * ( 399d0*costheta**4 - 190d0*costheta**2 + 15d0 )\t\t\t\n\t\t\t\t\treturn\n\t\t\t\tcase ( -5, 5 )\n\t\t\t\t\tres = 3d0 / 1024d0 * prefac * dsqrt( 3289d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**5 * ( 2261d0*costheta**6 - 1615d0*costheta**4 + 255d0*costheta**2 - 5d0 )\n\t\t\t\t\treturn\n\t\t\t\tcase ( -4, 4 )\n\t\t\t\t\tres = 3d0 / 256d0 * prefac * dsqrt( 23023d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**4 * costheta * ( 323d0*costheta**6 - 323d0*costheta**4 + 85d0*costheta**2 - 5d0 )\n\t\t\t\t\treturn\n\t\t\t\tcase ( -3, 3 )\n\t\t\t\t\tres = 1d0 / 1024d0 * prefac * dsqrt( 345345d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**3 * ( 969d0*costheta**8 - 1292d0*costheta**6 + 510d0*costheta**4 - 60d0*costheta**2 + 1d0 )\n\t\t\t\t\treturn\n\t\t\t\tcase ( -2, 2 )\n\t\t\t\t\tres = 1d0 / 512d0 * prefac * dsqrt( 49335d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**2 * costheta * ( 2261d0*costheta**8 - 3876d0*costheta**6 + 2142d0*costheta**4 - 420d0*costheta**2 + 21d0 )\n\t\t\t\t\treturn\n\t\t\t\tcase ( -1, 1 )\n\t\t\t\t\tres = 1d0 / 1024d0 * prefac * dsqrt( 759d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta * ( 29393d0*costheta**10 - 62985d0*costheta**8 + 46410d0*costheta**6 - 13650d0*costheta**4 + 1365d0*costheta**2 - 21d0 )\n\t\t\t\t\treturn\n\t\t\t\tcase ( 0 )\n\t\t\t\t\tres = 1d0/512d0 * dsqrt(23d0/pi) * ( &\n\t\t\t\t\t\t88179d0*costheta**11 - 230945d0*costheta**9 + 218790d0*costheta**7 - 90090d0*costheta**5 + 15015d0*costheta**3 - 693d0*costheta)\n\t\t\t\t\treturn\n\t\t\tend select\n\t\t\t\n\t\tcase ( 12 )\n\t\t\n\t\t\tselect case ( m )\n\t\t\t\tcase ( -12, 12 )\n\t\t\t\t\tres = 5d0 / 4096d0 * prefac * dsqrt( 676039d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**12\n\t\t\t\t\treturn\n\t\t\t\tcase ( -11, 11 )\n\t\t\t\t\tres = 5d0 / 1024d0 * prefac * dsqrt( 2028117d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**11 * costheta\n\t\t\t\t\treturn\n\t\t\t\tcase ( -10, 10 )\n\t\t\t\t\tres = 5d0 / 2048d0 * prefac * dsqrt( 88179d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**10 * ( 23d0*costheta**2 - 1d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -9, 9 )\n\t\t\t\t\tres = 5d0 / 1024d0 * prefac * dsqrt( 323323d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**9 * costheta * ( 23d0*costheta**2 - 3d0)\n\t\t\t\t\treturn\t\t\n\t\t\t\tcase ( -8, 8 )\n\t\t\t\t\tres = 5d0 / 2048d0 * prefac * dsqrt( 138567d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**8 * ( 161d0*costheta**4 - 42d0*costheta**2 + 1d0)\t\t\t\n\t\t\t\t\treturn\n\t\t\t\tcase ( -7, 7 )\n\t\t\t\t\tres = 5d0 / 1024d0 * prefac * dsqrt( 138567d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**7 * costheta * ( 161d0*costheta**4 - 70d0*costheta**2 + 5d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -6, 6 )\n\t\t\t\t\tres = 5d0 / 2048d0 * prefac * dsqrt( 2431d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**6 * ( 3059d0*costheta**6 - 1995d0*costheta**4 + 285d0*costheta**2 - 5d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -5, 5 )\n\t\t\t\t\tres = 15d0 / 1024d0 * prefac * dsqrt( 17017d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**5 * costheta * ( 437d0*costheta**6 - 399d0*costheta**4 + 95d0*costheta**2 - 5d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -4, 4 )\n\t\t\t\t\tres = 15d0 / 4096d0 * prefac * dsqrt( 1001d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**4 * ( 7429d0*costheta**8 - 9044d0*costheta**6 + 3230d0*costheta**4 - 340d0*costheta**2 + 5d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -3, 3 )\n\t\t\t\t\tres = 5d0 / 1024d0 * prefac * dsqrt( 1001d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**3 * costheta * ( 7429d0*costheta**8 - 11628d0*costheta**6 + 5814d0*costheta**4 - 1020d0*costheta**2 + 45d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -2, 2 )\n\t\t\t\t\tres = 5d0 / 1024d0 * prefac * dsqrt( 3003d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**2 * ( 7429d0*costheta**10 - 14535d0*costheta**8 + 9690d0*costheta**6 - 2550d0*costheta**4 + 225d0*costheta**2 - 3d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -1, 1 )\n\t\t\t\t\tres = 5d0 / 1024d0 * prefac * dsqrt( 39d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta * costheta * ( 52003d0*costheta**10 - 124355d0*costheta**8 + 106590d0*costheta**6 - 39270d0*costheta**4 + 5775d0*costheta**2 - 231d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( 0 )\n\t\t\t\t\tres = 5d0/2048d0 * dsqrt(1d0/pi) * ( &\n\t\t\t\t\t\t676039d0*costheta**12 - 1939938d0*costheta**10 + 2078505d0*costheta**8 - 1021020d0*costheta**6 + 225225d0*costheta**4 - 18018d0*costheta**2 + 231d0)\n\t\t\t\t\treturn\n\t\t\tend select\n\t\t\t\n\t\tcase ( 13 )\n\t\t\n\t\t\tselect case ( m )\n\t\t\t\tcase ( -13, 13 )\n\t\t\t\t\tres = 15d0 / 4096d0 * prefac * dsqrt( 156009d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**13\n\t\t\t\t\treturn\n\t\t\t\tcase ( -12, 12 )\n\t\t\t\t\tres = 15d0 / 4096d0 * prefac * dsqrt( 2028117d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**12 * costheta\n\t\t\t\t\treturn\n\t\t\t\tcase ( -11, 11 )\n\t\t\t\t\tres = 3d0 / 4096d0 * prefac * dsqrt( 2028117d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**11 * ( 25d0*costheta**2 - 1d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -10, 10 )\n\t\t\t\t\tres = 3d0 / 2048d0 * prefac * dsqrt( 2028117d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**10 * costheta * ( 25d0*costheta**2 - 3d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -9, 9 )\n\t\t\t\t\tres = 3d0 / 4096d0 * prefac * dsqrt( 88179d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**9 * ( 575d0*costheta**4 - 138d0*costheta**2 + 3d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -8, 8 )\n\t\t\t\t\tres = 3d0 / 2048d0 * prefac * dsqrt( 4849845d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**8 * costheta * ( 115d0*costheta**4 - 46d0*costheta**2 + 3d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -7, 7 )\n\t\t\t\t\tres = 3d0 / 4096d0 * prefac * dsqrt( 692835d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**7 * ( 805d0*costheta**6 - 483d0*costheta**4 + 63d0*costheta**2 - 1d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -6, 6 )\n\t\t\t\t\tres = 3d0 / 2048d0 * prefac * dsqrt( 969969d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**6 * costheta * ( 575d0*costheta**6 - 483d0*costheta**4 + 105d0*costheta**2 - 5d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -5, 5 )\n\t\t\t\t\tres = 3d0 / 4096d0 * prefac * dsqrt( 51051d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**5 * ( 10925d0*costheta**8 - 12236d0*costheta**6 + 3990d0*costheta**4 - 380d0*costheta**2 + 5d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -4, 4 )\n\t\t\t\t\tres = 3d0 / 4096d0 * prefac * dsqrt( 51051d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**4 * costheta * ( 10925d0*costheta**8 - 15732d0*costheta**6 + 7182d0*costheta**4 - 1140d0*costheta**2 + 45d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -3, 3 )\n\t\t\t\t\tres = 3d0 / 4096d0 * prefac * dsqrt( 15015d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**3 * ( 37145d0*costheta**10 - 66861d0*costheta**8 + 40698d0*costheta**6 - 9690d0*costheta**4 + 765d0*costheta**2 - 9d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -2, 2 )\n\t\t\t\t\tres = 3d0 / 1024d0 * prefac * dsqrt( 1365d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**2 * costheta * ( 37145d0*costheta**10 - 81719d0*costheta**8 + 63954d0*costheta**6 - 21318d0*costheta**4 + 2805d0*costheta**2 - 99d0)\t\t\t\n\t\t\t\t\treturn\n\t\t\t\tcase ( -1, 1 )\n\t\t\t\t\tres = 3d0 / 2048d0 * prefac * dsqrt( 273d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta * ( 185725d0*costheta**12 - 490314d0*costheta**10 + 479655d0*costheta**8 - 213180d0*costheta**6 + 42075d0*costheta**4 - 2970d0*costheta**2 + 33d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( 0 )\n\t\t\t\t\tres = 3d0/2048d0 * dsqrt(3d0/pi) * ( &\n\t\t\t\t\t\t1300075d0*costheta**13 - 4056234d0*costheta**11 + 4849845d0*costheta**9 - 2771340d0*costheta**7 + 765765d0*costheta**5 - 90090d0*costheta**3 + 3003d0*costheta)\n\t\t\t\t\treturn\n\t\t\tend select\n\t\t\t\t\n\t\tcase ( 14 )\n\t\t\n\t\t\tselect case ( m )\n\t\t\t\tcase ( -14, 14 )\n\t\t\t\t\tres = 15d0 / 8192d0 * prefac * dsqrt( 646323d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**14\n\t\t\t\t\treturn\n\t\t\t\tcase ( -13, 13 )\n\t\t\t\t\tres = 15d0 / 4096d0 * prefac * dsqrt( 4524261d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**13 * costheta\n\t\t\t\t\treturn\n\t\t\t\tcase ( -12, 12 )\n\t\t\t\t\tres = 5d0 / 8192d0 * prefac * dsqrt( 1508087d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**12 * ( 27d0*costheta**2 - 1d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -11, 11 )\n\t\t\t\t\tres = 5d0 / 4096d0 * prefac * dsqrt( 58815393d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**11 * costheta * ( 9d0*costheta**2 - 1d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -10, 10 )\n\t\t\t\t\tres = 1d0 / 8192d0 * prefac * dsqrt( 58815393d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**10 * ( 225d0*costheta**4 - 50d0*costheta**2 + 1d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -9, 9 )\n\t\t\t\t\tres = 1d0 / 4096d0 * prefac * dsqrt( 98025655d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**9 * costheta * ( 135d0*costheta**4 - 50d0*costheta**2 + 3d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -8, 8 )\n\t\t\t\t\tres = 1d0 / 4096d0 * prefac * dsqrt( 12785955d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**8 * ( 1035d0*costheta**6 - 575d0*costheta**4 + 69d0*costheta**2 - 1d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -7, 7 )\n\t\t\t\t\tres = 1d0 / 4096d0 * prefac * dsqrt( 20092215d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**7 * costheta * ( 1035d0*costheta**6 - 805d0*costheta**4 + 161d0*costheta**2 - 7d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -6, 6 )\n\t\t\t\t\tres = 1d0 / 8192d0 * prefac * dsqrt( 46881835d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**6 * ( 3105d0*costheta**8 - 3220d0*costheta**6 + 966d0*costheta**4 - 84d0*costheta**2 + 1d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -5, 5 )\n\t\t\t\t\tres = 3d0 / 4096d0 * prefac * dsqrt( 9376367d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**5 * costheta * ( 1725d0*costheta**8 - 2300d0*costheta**6 + 966d0*costheta**4 - 140d0*costheta**2 + 5d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -4, 4 )\n\t\t\t\t\tres = 3d0 / 8192d0 * prefac * dsqrt( 2467465d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**4 * ( 6555d0*costheta**10 - 10925d0*costheta**8 + 6118d0*costheta**6 - 1330d0*costheta**4 + 95d0*costheta**2 - 1d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -3, 3 )\n\t\t\t\t\tres = 1d0 / 4096d0 * prefac * dsqrt( 224315d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**3 * costheta * ( 58995d0*costheta**10 - 120175d0*costheta**8 + 86526d0*costheta**6 - 26334d0*costheta**4 + 3135d0*costheta**2 - 99d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -2, 2 )\n\t\t\t\t\tres = 1d0 / 8192d0 * prefac * dsqrt( 39585d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**2 * ( 334305d0*costheta**12 - 817190d0*costheta**10 + 735471d0*costheta**8 - 298452d0*costheta**6 + 53295d0*costheta**4 - 3366d0*costheta**2 + 33d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -1, 1 )\n\t\t\t\t\tres = 1d0 / 2048d0 * prefac * dsqrt( 3045d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta * costheta * ( 334305d0*costheta**12 - 965770d0*costheta**10 + 1062347d0*costheta**8 - 554268d0*costheta**6 + 138567d0*costheta**4 - 14586d0*costheta**2 + 429d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( 0 )\n\t\t\t\t\tres = 1d0/4096d0 * dsqrt(29d0/pi) * ( &\n\t\t\t\t\t\t5014575d0*costheta**14 - 16900975d0*costheta**12 + 22309287d0*costheta**10 - 14549535d0*costheta**8 + 4849845d0*costheta**6 - 765765d0*costheta**4 + 45045d0*costheta**2 - 429d0)\n\t\t\t\t\treturn\n\t\t\tend select\n\t\t\t\n\t\tcase ( 15 )\n\t\t\n\t\t\tselect case ( m )\n\t\t\t\tcase ( -15, 15 )\n\t\t\t\t\tres = 3d0 / 16384d0 * prefac * dsqrt( 33393355d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**15\n\t\t\t\t\treturn\n\t\t\t\tcase ( -14, 14 )\n\t\t\t\t\tres = 15d0 / 8192d0 * prefac * dsqrt( 20036013d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**14 * costheta \n\t\t\t\t\treturn\n\t\t\t\tcase ( -13, 13 )\n\t\t\t\t\tres = 15d0 / 16384d0 * prefac * dsqrt( 690897d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**13 * ( 29d0*costheta**2 - 1d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -12, 12 )\n\t\t\t\t\tres = 15d0 / 8192d0 * prefac * dsqrt( 1612093d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**12 * costheta * ( 29d0*costheta**2 - 3d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -11, 11 )\n\t\t\t\t\tres = 5d0 / 16384d0 * prefac * dsqrt( 4836279d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**11 * ( 261d0*costheta**4 - 54d0*costheta**2 + 1d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -10, 10 )\n\t\t\t\t\tres = 1d0 / 8192d0 * prefac * dsqrt( 314358135d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**10 * costheta * ( 261d0*costheta**4 - 90d0*costheta**2 + 5d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -9, 9 )\n\t\t\t\t\tres = 1d0 / 16384d0 * prefac * dsqrt( 104786045d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**9 * ( 1305d0*costheta**6 - 675d0*costheta**4 + 75d0*costheta**2 - 1d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -8, 8 )\n\t\t\t\t\tres = 1d0 / 4096d0 * prefac * dsqrt( 44908305d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**8 * costheta * ( 1305d0*costheta**6 - 945d0*costheta**4 + 175d0*costheta**2 - 7d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -7, 7 )\n\t\t\t\t\tres = 1d0 / 16384d0 * prefac * dsqrt( 1952535d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**7 * ( 30015d0*costheta**8 - 28980d0*costheta**6 + 8050d0*costheta**4 - 644d0*costheta**2 + 7d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -6, 6 )\n\t\t\t\t\tres = 1d0 / 8192d0 * prefac * dsqrt( 21477885d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**6 * costheta * ( 10005d0*costheta**8 - 12420d0*costheta**6 + 4830d0*costheta**4 - 644d0*costheta**2 + 21d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -5, 5 )\n\t\t\t\t\tres = 3d0 / 16384d0 * prefac * dsqrt( 10023013d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**5 * ( 10005d0*costheta**10 - 15525d0*costheta**8 + 8050d0*costheta**6 - 1610d0*costheta**4 + 105d0*costheta**2 - 1d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -4, 4 )\n\t\t\t\t\tres = 3d0 / 8192d0 * prefac * dsqrt( 4555915d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**4 * costheta * ( 10005d0*costheta**10 - 18975d0*costheta**8 + 12650d0*costheta**6 - 3542d0*costheta**4 + 385d0*costheta**2 - 11d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -3, 3 )\n\t\t\t\t\tres = 1d0 / 16384d0 * prefac * dsqrt( 719355d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta**3 * ( 190095d0*costheta**12 - 432630d0*costheta**10 + 360525d0*costheta**8 - 134596d0*costheta**6 + 21945d0*costheta**4 - 1254d0*costheta**2 + 11d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -2, 2 )\n\t\t\t\t\tres = 1d0 / 8192d0 * prefac * dsqrt( 55335d0 / ( 2d0*pi ) ) * &\n\t\t\t\t\t\tsintheta**2 * costheta * ( 570285d0*costheta**12 - 1533870d0*costheta**10 + 1562275d0*costheta**8 - 749892d0*costheta**6 + 171171d0*costheta**4 - 16302d0*costheta**2 + 429d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( -1, 1 )\n\t\t\t\t\tres = 1d0 / 16384d0 * prefac * dsqrt( 465d0 / ( pi ) ) * &\n\t\t\t\t\t\tsintheta * ( 9694845d0*costheta**14 - 30421755d0*costheta**12 + 37182145d0*costheta**10 - 22309287d0*costheta**8 + 6789783d0*costheta**6 - 969969d0*costheta**4 + 51051d0*costheta**2 - 429d0)\n\t\t\t\t\treturn\n\t\t\t\tcase ( 0 )\n\t\t\t\t\tres = 1d0/4096d0 * dsqrt(31d0/pi) * ( &\n\t\t\t\t\t\t9694845d0*costheta**15 - 35102025d0*costheta**13 + 50702925d0*costheta**11 - 37182145d0*costheta**9 + 14549535d0*costheta**7 - 2909907d0*costheta**5 + 255255d0*costheta**3 - 6435d0*costheta**1)\n\t\t\t\t\treturn\n\t\t\tend select\n\t\t\t\n\tend select\n\n\tif ( ( m .gt. l ) .OR. ( m .lt. -l ) ) then\n\t\twrite(*,*) \"ERROR! Invalid spherical harmonic!\"\n\t\twrite(*,*)\n\t\tstop\n\tend if\n\t\n\twrite(*,*) \"ERROR! Spherical harmonic not implemented!\"\n\twrite(*,*)\n\tstop\n\t\nend function\n", "meta": {"hexsha": "4c5f67db151d1a90b1a029f93df756f87b0f932f", "size": 26565, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "util_ylm.f90", "max_stars_repo_name": "micb25/rhOver", "max_stars_repo_head_hexsha": "3c7796c77f26ee7dfc5965880495aea9716891c6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "util_ylm.f90", "max_issues_repo_name": "micb25/rhOver", "max_issues_repo_head_hexsha": "3c7796c77f26ee7dfc5965880495aea9716891c6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-09-13T12:54:11.000Z", "max_issues_repo_issues_event_max_datetime": "2019-09-26T19:05:52.000Z", "max_forks_repo_path": "util_ylm.f90", "max_forks_repo_name": "micb25/rhOver", "max_forks_repo_head_hexsha": "3c7796c77f26ee7dfc5965880495aea9716891c6", "max_forks_repo_licenses": ["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.0088105727, "max_line_length": 199, "alphanum_fraction": 0.5447769622, "num_tokens": 12281, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.7634837635542925, "lm_q1q2_score": 0.6820272230156388}} {"text": " Program dgeevx_example\n\n! DGEEVX Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_interfaces, Only: dgeevx\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nb = 64, nin = 5, nout = 6\n! .. Local Scalars ..\n Complex (Kind=dp) :: eig\n Real (Kind=dp) :: abnrm, eps, tol\n Integer :: i, ihi, ilo, info, j, k, lda, ldvl, ldvr, lwork, n\n Logical :: pair\n! .. Local Arrays ..\n Real (Kind=dp), Allocatable :: a(:, :), rconde(:), rcondv(:), scale(:), &\n vl(:, :), vr(:, :), wi(:), work(:), wr(:)\n Real (Kind=dp) :: dummy(1)\n Integer, Allocatable :: iwork(:)\n! .. Intrinsic Procedures ..\n Intrinsic :: cmplx, epsilon, max, maxloc, nint\n! .. Executable Statements ..\n Write (nout, *) 'DGEEVX Example Program Results'\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n\n lda = n\n ldvl = n\n ldvr = n\n lwork = (2+nb)*n\n Allocate (a(lda,n), rconde(n), rcondv(n), scale(n), vl(ldvl,n), &\n vr(ldvr,n), wi(n), wr(n), iwork(2*n-2))\n\n! Use routine workspace query to get optimal workspace.\n lwork = -1\n Call dgeevx('Balance', 'Vectors (left)', 'Vectors (right)', &\n 'Both reciprocal condition numbers', n, a, lda, wr, wi, vl, ldvl, vr, &\n ldvr, ilo, ihi, scale, abnrm, rconde, rcondv, dummy, lwork, iwork, &\n info)\n\n! Make sure that there is enough workspace for block size nb.\n lwork = max((nb+2)*n, nint(dummy(1)))\n Allocate (work(lwork))\n\n! Read the matrix A from data file\n\n Read (nin, *)(a(i,1:n), i=1, n)\n\n! Solve the eigenvalue problem\n Call dgeevx('Balance', 'Vectors (left)', 'Vectors (right)', &\n 'Both reciprocal condition numbers', n, a, lda, wr, wi, vl, ldvl, vr, &\n ldvr, ilo, ihi, scale, abnrm, rconde, rcondv, work, lwork, iwork, &\n info)\n\n If (info==0) Then\n\n! Compute the machine precision\n eps = epsilon(1.0E0_dp)\n tol = eps*abnrm\n pair = .False.\n\n! Print the eigenvalues and vectors, and associated condition\n! number and bounds\n\n Write (nout, *)\n Write (nout, *) 'Eigenvalues'\n Write (nout, *)\n Write (nout, *) ' Eigenvalue rcond error'\n\n Do j = 1, n\n\n! Print information on j-th eigenvalue\n\n If (wi(j)==0.0_dp) Then\n If (rconde(j)>0.0_dp) Then\n If (tol/rconde(j)<10.0_dp*eps) Then\n Write (nout, 100) j, wr(j), rconde(j), '-'\n Else\n Write (nout, 110) j, wr(j), rconde(j), tol/rconde(j)\n End If\n Else\n Write (nout, 110) j, wr(j), rconde(j), 'Inf'\n End If\n Else\n If (rconde(j)>0.0_dp) Then\n If (tol/rconde(j)<10.0_dp*eps) Then\n Write (nout, 120) j, wr(j), wi(j), rconde(j), '-'\n Else\n Write (nout, 130) j, wr(j), wi(j), rconde(j), tol/rconde(j)\n End If\n Else\n Write (nout, 120) j, wr(j), wi(j), rconde(j), 'Inf'\n End If\n End If\n End Do\n\n Write (nout, *)\n Write (nout, *) 'Eigenvectors'\n Write (nout, *)\n Write (nout, *) ' Eigenvector rcond error'\n\n Do j = 1, n\n\n! Print information on j-th eigenvector\n Write (nout, *)\n\n If (wi(j)==0.0E0_dp) Then\n! Make real eigenvectors have positive first entry\n If (vr(1,j)<0.0_dp) Then\n vr(1:n, j) = -vr(1:n, j)\n End If\n If (rcondv(j)>0.0_dp) Then\n If (tol/rcondv(j)<10.0_dp*eps) Then\n Write (nout, 100) j, vr(1, j), rcondv(j), '-'\n Else\n Write (nout, 110) j, vr(1, j), rcondv(j), tol/rcondv(j)\n End If\n Else\n Write (nout, 110) j, vr(1, j), rcondv(j), 'Inf'\n End If\n Write (nout, 140) vr(2:n, j)\n Else\n If (pair) Then\n eig = cmplx(vr(1,j-1), -vr(1,j), kind=dp)\n Else\n! Make largest eigenvector element have positive first entry\n work(1:n) = vr(1:n, j)**2 + vr(1:n, j+1)**2\n k = maxloc(work(1:n), 1)\n If (vr(k,j)<0.0_dp) Then\n vr(1:n, j) = -vr(1:n, j)\n End If\n eig = cmplx(vr(1,j), vr(1,j+1), kind=dp)\n End If\n If (rcondv(j)>0.0_dp) Then\n If (tol/rcondv(j)<10.0_dp*eps) Then\n Write (nout, 120) j, eig, rcondv(j), '-'\n Else\n Write (nout, 130) j, eig, rcondv(j), tol/rcondv(j)\n End If\n Else\n Write (nout, 120) j, eig, rcondv(j), 'Inf'\n End If\n If (pair) Then\n Write (nout, 150)(vr(i,j-1), -vr(i,j), i=2, n)\n Else\n Write (nout, 150)(vr(i,j), vr(i,j+1), i=2, n)\n End If\n pair = .Not. pair\n End If\n End Do\n Write (nout, *)\n Write (nout, *) 'Errors below 10*machine precision are not displayed'\n Else\n Write (nout, *)\n Write (nout, 160) 'Failure in DGEEVX. INFO = ', info\n End If\n\n100 Format (1X, I2, 2X, 1P, E11.4, 14X, 0P, F7.4, 4X, A)\n110 Format (1X, I2, 2X, 1P, E11.4, 11X, 0P, F7.4, 1X, 1P, E8.1)\n120 Format (1X, I2, 1X, '(', 1P, E11.4, ',', E11.4, ')', 1X, 0P, F7.4, 4X, &\n A)\n130 Format (1X, I2, 1X, '(', 1P, E11.4, ',', E11.4, ')', 1X, 0P, F7.4, 1X, &\n 1P, E8.1)\n140 Format (1X, 4X, 1P, E11.4)\n150 Format (1X, 3X, '(', 1P, E11.4, ',', E11.4, ')')\n160 Format (1X, A, I4)\n End Program\n", "meta": {"hexsha": "e9e94240ee5c36ca820a5df2b43f50ccf0dc4434", "size": 5969, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/dgeevx_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/dgeevx_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/dgeevx_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 34.3045977011, "max_line_length": 90, "alphanum_fraction": 0.4838331379, "num_tokens": 1997, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093946927837, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6820272186784533}} {"text": "program ch0402\n ! Simple Numeric I/O and Arithmetic\n implicit none\n\n real :: n1, n2, n3, average = 0., total = 0.\n integer :: n = 3\n\n print *, ' type in three numbers.'\n print *, ' Separated by spaces or commas'\n read *, n1, n2, n3\n total = n1+n2+n3\n average = total/n\n print *, ' Total of numbers is ', total\n print *, ' Average of the numbers is ', average\nend program\n", "meta": {"hexsha": "1c34eb8daff90532bbbaa96f9e7fe4b98345839b", "size": 404, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ch04/ch0402.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": "ch04/ch0402.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": "ch04/ch0402.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.25, "max_line_length": 51, "alphanum_fraction": 0.599009901, "num_tokens": 122, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8438951104066295, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.6819239684467694}} {"text": "module diag_dom_utility\ncontains\n subroutine to_diag_dom(n,m,A,out_status)\n !This routime checks if a given matriz A can be converted to diagonally\n !dominant form, and in case that is true, it makes the conversion and returns\n !the diagonally dominant matrix.\n !\n !For the matrix to be convertible, two conditions must be satisfied:\n ! #1 The largest elements (in abs value) of each row must all belong to\n ! different columns, so the can be placed at the main diagonal by\n ! changing rows or columns.\n ! #2 The largest element of each row must be 'dominant', that is, must be\n ! grater than the sum of the abs value of all other elements in the\n ! same row.\n !\n !If both conditions are met the routine returns out_status=.TRUE. and the\n !modified matrix in array A.\n !If any of the conditions is not met, the routine returns out_status=.FALSE.\n !and the original matriz in array A.\n implicit none\n !Declaration of arguments\n integer(2), intent(in) :: n,m\n integer(2), intent(inout) :: A(n,m)\n logical, intent(out) :: out_status\n\n !Declaration of internal variables\n integer(2) :: i\n integer(2) :: m_index(n), sum_row(n)\n logical :: max_are_dominant, max_in_dif_col\n\n\n !Find the position of the largest element (in abs value)\n !for each row.\n !Read about MAXLOC function at: https://gcc.gnu.org/onlinedocs/gcc-4.4.3/gfortran/MAXLOC.html\n m_index=maxloc(abs(A),dim=2)\n\n !Check if the largest element of each row is in a different column\n !then, after rearranging rows it will be possible to place the those\n !elements in the main diagonal of the matrix.\n max_in_dif_col=all_different(m_index)\n\n !Compute the summation of all elements in each row.\n !Substracting the value of the row's maximum we get the sum of all other elements\n !Substracting the value of the row's maximum again, if the maximums are dominant\n !we get an array with all negative values.\n sum_row=0\n do i=1,n\n sum_row(i)=sum(abs(A(i,:)))-2*abs(A(i,m_index(i)))\n enddo\n\n !Check if all values are negative. If that is the case we set\n !max_are_dominant to true because the matriz mets the first conditions\n !to be convertible to diagonally dominant form\n if (all(sum_row<0)) max_are_dominant=.true.\n\n if ((max_are_dominant).and.(max_in_dif_col)) then\n call convert_to_diag_dom(A, m_index)\n out_status=.true.\n else\n out_status=.false.\n endif\n end subroutine\n\n logical function all_different(arr)\n !This function returns TRUE if all elements of array 'arr'\n !are different to each other. If not, it returns FALSE.\n implicit none\n !Declaration of arguments\n integer(2), intent(in) :: arr(:) !<----This is an automatic array not\n !a dynamic array (allocatable)\n !Ask Google about it or go to consulta\n\n !Declaration of internal variables\n integer(2) :: i\n\n all_different=.true.\n\n !Read about intrisinc function SIZE at:\n !https://gcc.gnu.org/onlinedocs/gcc-4.4.3/gfortran/SIZE.html#SIZE\n do i=1,size(arr)-1\n !Read about intrisinc function ANY at:\n !https://gcc.gnu.org/onlinedocs/gcc-4.4.3/gfortran/ANY.html#ANY\n if (any(arr(i)==arr(i+1:size(arr)))) then\n all_different=.false.\n exit\n endif\n enddo\n\n end function\n\n subroutine convert_to_diag_dom(M,m_index)\n !This routine places each row in the correspondig place.\n implicit none\n integer(2), intent(in) :: m_index(:)\n integer(2), intent(inout) :: M(:,:)\n\n integer(2) :: i\n integer(2) :: aux(size(M,1),size(M,2))\n\n do i=1,size(M,1)\n aux(m_index(i),:)=M(i,:)\n enddo\n\n M=aux\n\n end subroutine convert_to_diag_dom\nend module diag_dom_utility\n\nprogram test_ddomin\n use diag_dom_utility\n implicit none\n integer(2) :: i,n,m\n integer(2), allocatable :: A(:,:) !This is a dynamic array (allocatable)\n logical :: ddiag_status\n\n open(unit=10,file='datos.in',status='old')\n\n read(10,*) n,m\n allocate(A(n,m))\n\n do i=1,n\n read(10,*) A(i,:)\n write(*,*) A(i,:)\n enddo\n close(10)\n\n call to_diag_dom(n,m,A,ddiag_status)\n print *, \"---------------------------------\"\n\n if (ddiag_status) then\n do i=1,size(A,1)\n print *, A(i,:)\n enddo\n else\n print *, \" \"\n print *, \"The matrix cannot be converted to diagonally dominant form\"\n endif\n\nend program\n", "meta": {"hexsha": "c673d191f84cee1be9f06030f127cf209b508d19", "size": 4807, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "diag_dom_new.f90", "max_stars_repo_name": "MaxiRam/CCN-fortran-codes", "max_stars_repo_head_hexsha": "b7b50e27f3bff47890b690432efb3fd5dce36f02", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "diag_dom_new.f90", "max_issues_repo_name": "MaxiRam/CCN-fortran-codes", "max_issues_repo_head_hexsha": "b7b50e27f3bff47890b690432efb3fd5dce36f02", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "diag_dom_new.f90", "max_forks_repo_name": "MaxiRam/CCN-fortran-codes", "max_forks_repo_head_hexsha": "b7b50e27f3bff47890b690432efb3fd5dce36f02", "max_forks_repo_licenses": ["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.3357142857, "max_line_length": 101, "alphanum_fraction": 0.6074474724, "num_tokens": 1214, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951025545426, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.6819239679527068}} {"text": " implicit real*8(a-h,o-z)\n external f1\n write(*,*) \"enter the intial guess and step value\"\n read (*,*) x0,xinc\n call bracket(f1,x0,xinc,a,b)\n write(*,*)\"The brackets are \",a,b\n x=bisec(f1,a,b)\n write(*,*)\"The solution is \",x,a,b\n end\n\n real*8 function f1(x)\n implicit real*8(a-h,o-z)\n f1=sin(x)\n end\n\n\n subroutine bracket(f,x0,xinc,xpos,xneg)\n* sign of xinc should be +/- for increasing/decreasing function\n implicit real*8(a-h,o-z)\n logical flag\n flag=.true.\n x=x0\n if(f(x).gt.0.0)then\n xpos=x\n ival=1\n x=x-xinc\n else\n xneg=x\n ival=-1\n x=x+xinc\n end if\n do iterate=1,50\n if(f(x).gt.0.0)then\n xpos=x\n if(ival.eq.-1)then\n flag=.false.\n exit\n end if\n x=x-xinc\n else\n xneg=x\n if(ival.eq.1)then\n flag=.false.\n exit\n end if\n x=x+xinc\n end if\n end do\n if(flag)then\n write(*,*)'Havent got change in sign for bracketing'\n stop\n end if\n end\n\n\n real*8 function bisec(f,xpos,xneg)\n implicit real*8(a-h,o-z)\n logical flag\n flag=.true.\n if(f(xpos).lt.0)then\n t=xpos\n xpos=xneg\n xneg=t\n endif\n x0=(xpos+xneg)/2.0d0\n do iterate=1,300\n x=x0\n fx=f(x)\n if(fx.gt.0.0)then\n xpos=x\n else\n xneg=x\n end if\n x0=(xpos+xneg)/2.0d0\nc print *,iterate,x,fx\n if((dabs(x0-x).lt.1.0e-8).and.(dabs(fx).lt.1e-3))then\n flag=.false.\n bisec=x0\n exit\n end if\n end do\n if(flag)then\n write(*,*)'Bisection method did not converge'\n stop\n end if\n end\n", "meta": {"hexsha": "f0cc28e7fa3ce32accbf1054daf8afed1293263b", "size": 1835, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "aru/bisec.f", "max_stars_repo_name": "deadbeatfour/phn624-comp-nuc-phy", "max_stars_repo_head_hexsha": "deaeaac5240a1f33425c4ca50539aee4fae2f370", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "aru/bisec.f", "max_issues_repo_name": "deadbeatfour/phn624-comp-nuc-phy", "max_issues_repo_head_hexsha": "deaeaac5240a1f33425c4ca50539aee4fae2f370", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "aru/bisec.f", "max_forks_repo_name": "deadbeatfour/phn624-comp-nuc-phy", "max_forks_repo_head_hexsha": "deaeaac5240a1f33425c4ca50539aee4fae2f370", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.091954023, "max_line_length": 63, "alphanum_fraction": 0.4692098093, "num_tokens": 586, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950947024555, "lm_q2_score": 0.8080672227971211, "lm_q1q2_score": 0.6819239655083267}} {"text": "module timestep_module\n\n use datatypes_module\n\n implicit none\n\ncontains\n\n subroutine compute_dt(U, dt)\n\n use grid_module\n use runtime_params_module, only : gamma, cfl\n\n implicit none\n\n real(dp_t), intent(in) :: U(a_lo:a_hi, NVAR)\n real(dp_t), intent(out) :: dt\n\n real(dp_t) :: vel, p, cs\n integer :: i\n\n dt = 1.e33_dp_t\n\n do i = ilo, ihi\n vel = U(i, UMX)/U(i, URHO)\n p = (U(i, UENER) - 0.5_dp_t * U(i, URHO) * vel**2)*(gamma - 1.0_dp_t)\n\n cs = sqrt(gamma * p / U(i, URHO))\n dt = min(dt, cfl*dx/(abs(vel) + cs))\n enddo\n\n end subroutine compute_dt\n\nend module timestep_module\n", "meta": {"hexsha": "abe0a06916fde15df2f01bfab3f323173bd56381", "size": 632, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "compressible/MOL/Fortran/timestep.f90", "max_stars_repo_name": "python-hydro/hydro_examples", "max_stars_repo_head_hexsha": "55b7750a7644f3e2187f7fe338b6bc1d6fb9c139", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 66, "max_stars_repo_stars_event_min_datetime": "2018-09-01T10:44:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-26T23:50:57.000Z", "max_issues_repo_path": "compressible/MOL/Fortran/timestep.f90", "max_issues_repo_name": "python-hydro/hydro_examples", "max_issues_repo_head_hexsha": "55b7750a7644f3e2187f7fe338b6bc1d6fb9c139", "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": "compressible/MOL/Fortran/timestep.f90", "max_forks_repo_name": "python-hydro/hydro_examples", "max_forks_repo_head_hexsha": "55b7750a7644f3e2187f7fe338b6bc1d6fb9c139", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 39, "max_forks_repo_forks_event_min_datetime": "2018-09-06T20:02:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-27T17:05:24.000Z", "avg_line_length": 18.0571428571, "max_line_length": 76, "alphanum_fraction": 0.5949367089, "num_tokens": 212, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942119105696, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6819103431028153}} {"text": " subroutine evol_alphadyopl(n_K,n_alpha,np1_K,np1_alpha,x,Nx,ht,myz\n &ero,phys_bdy,res)\n implicit none\n integer i\n integer Nx\n real*8 ht\n real*8 myzero\n real*8 n_K(Nx)\n real*8 n_alpha(Nx)\n real*8 np1_K(Nx)\n real*8 np1_alpha(Nx)\n real*8 x(Nx)\n integer phys_bdy(2)\n real*8 res(Nx)\n real*8 qb\n if (phys_bdy(1) .eq. 1) then\n do i=1, 1, 1\n qb = np1_alpha(i) - 0.1D1 / (np1_K(i) * ht + 0.1D1) * ht * ((-0.1D\n #1 * n_alpha(i) + np1_alpha(i)) / ht + np1_alpha(i) * np1_K(i) + n_\n #alpha(i) * n_K(i))\n res(i)=qb\n end do\n endif\n do i=2, Nx-1, 1\n qb = np1_alpha(i) - 0.1D1 / (np1_K(i) * ht + 0.1D1) * ht * ((-0.1D\n #1 * n_alpha(i) + np1_alpha(i)) / ht + np1_alpha(i) * np1_K(i) + n_\n #alpha(i) * n_K(i))\n res(i)=qb\n end do\n if (phys_bdy(2) .eq. 1) then\n do i=Nx, Nx, 1\n qb = -0.1D1 * myzero * x(i) + 0.1D1\n res(i)=qb\n end do\n endif\n END\n", "meta": {"hexsha": "566625eafa72f51af0c809ff74cd7b4f50903c2f", "size": 1001, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/FD/evol_alphadyopl.f", "max_stars_repo_name": "rmanak/bssn_spher", "max_stars_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/FD/evol_alphadyopl.f", "max_issues_repo_name": "rmanak/bssn_spher", "max_issues_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/FD/evol_alphadyopl.f", "max_forks_repo_name": "rmanak/bssn_spher", "max_forks_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.0540540541, "max_line_length": 72, "alphanum_fraction": 0.4965034965, "num_tokens": 428, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.903294214513915, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6819103351066337}} {"text": "PROGRAM main\n\n IMPLICIT NONE\n REAL(8), DIMENSION(10) :: A\n\n A = (/ 1d0, 3d0, 2d0, 4d0, 5d0, 10d0, 50d0, 7d0, 1.5d0, 0.3d0 /)\n\n WRITE(*,*) 'Input vector'\n WRITE(*,'( F6.2 )') A\n WRITE(*,*) ' '\n\n CALL bubblesort(A)\n\n WRITE(*,*) 'Output vector'\n WRITE(*,'(F6.2)') A\n\nCONTAINS\n\nSUBROUTINE bubblesort(array)\n\n IMPLICIT NONE\n INTEGER :: array_length, i, j, n\n REAL(8) :: tmp\n REAL(8), DIMENSION(:), INTENT(INOUT) :: array\n\n array_length = size(array)\n n = array_length\n \n DO i=1, n\n DO j=1, n-1\n IF ( array(j) > array(j+1) ) THEN\n\n tmp = array(j+1)\n array(j+1) = array(j)\n array(j) = tmp\n \n END IF\n END DO\n END DO\nEND SUBROUTINE bubblesort\n \nEND PROGRAM main \n", "meta": {"hexsha": "fb903f0d3cb4058b37976b8ca67618ceca395551", "size": 890, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "contents/bubble_sort/code/fortran/bubble.f90", "max_stars_repo_name": "atocil/algorithm-archive", "max_stars_repo_head_hexsha": "2eb30cb103508c9efb91621564bd3114eb49d3af", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-08-30T09:58:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-28T12:49:47.000Z", "max_issues_repo_path": "contents/bubble_sort/code/fortran/bubble.f90", "max_issues_repo_name": "atocil/algorithm-archive", "max_issues_repo_head_hexsha": "2eb30cb103508c9efb91621564bd3114eb49d3af", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-05-20T04:32:16.000Z", "max_issues_repo_issues_event_max_datetime": "2018-05-20T05:54:18.000Z", "max_forks_repo_path": "contents/bubble_sort/code/fortran/bubble.f90", "max_forks_repo_name": "atocil/algorithm-archive", "max_forks_repo_head_hexsha": "2eb30cb103508c9efb91621564bd3114eb49d3af", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-01-08T16:03:44.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-23T19:22:17.000Z", "avg_line_length": 20.6976744186, "max_line_length": 68, "alphanum_fraction": 0.4483146067, "num_tokens": 288, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7549149868676283, "lm_q2_score": 0.9032942054022056, "lm_q1q2_score": 0.6819103332088108}} {"text": "program Approximate_pi\r\nimplicit none\r\n real :: a , b = 0 , delta , pi\r\n integer:: n , i\r\n read* , n\r\n \r\n do i = 1 , n\r\n delta = 1. / i**2\r\n a = b + delta\r\n b = a\r\n end do\r\n pi = sqrt(6*b)\r\n write(*,\"(a,f5.2)\") 'pi=',pi\r\n \r\nend", "meta": {"hexsha": "1120cbd6788c9a52eaee1911842c2dd196f00974", "size": 275, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "GitHub_FortranHomework/B20211126.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/B20211126.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/B20211126.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.3333333333, "max_line_length": 35, "alphanum_fraction": 0.4072727273, "num_tokens": 96, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9032942067038785, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6819103292107201}} {"text": "program test_poisson_3d\n\nuse mesh_fields_m\nuse poisson_3d_m\nuse output_m\n\nimplicit none\n\ntype(mesh_t) :: mesh\ntype(fields_3d_t) :: fields\ntype(poisson_3d_t) :: poisson\n\ninteger, parameter :: nx = 32, ny = 64, nz = 128\nreal(8) :: xmin, xmax, ymin, ymax, zmin, zmax\nreal(8) :: pi\ninteger :: i, j, k\nreal(8) :: x, y, z\nreal(8) :: err_x, err_y, err_z\n\npi = 4d0 * atan(1d0)\n\nxmin = 0d0\nxmax = 2d0 * pi\nymin = 0d0\nymax = 4d0 * pi\nzmin = 0d0\nzmax = 6d0 * pi\n\ncall init_mesh( mesh, xmin, xmax, nx, ymin, ymax, ny, zmin, zmax, nz )\n\ncall init_fields( fields, mesh )\n\ncall init_poisson( poisson, mesh)\n\ndo k = 1, nz\n z = (k-1) * mesh%dz\n do j = 1, ny\n y = (j-1) * mesh%dy\n do i = 1, nx\n x = (i-1) * mesh%dx\n fields%rho(i,j,k) = - 3d0 * sin(x) * sin(y) * sin(z)\n end do\n end do\nend do\n\ncall solve_poisson( poisson, fields)\n\ncall write_data( 1, fields)\n\nerr_x = 0d0\nerr_y = 0d0\nerr_z = 0d0\ndo k = 1, nz+1\n z = (k-1) * mesh%dz\n do j = 1, ny+1\n y = (j-1) * mesh%dy\n do i = 1, nx+1\n x = (i-1) * mesh%dx\n err_x = err_x + abs( fields%e(1,i,j,k) - cos(x)*sin(y)*sin(z))\n err_y = err_y + abs( fields%e(2,i,j,k) - cos(y)*sin(x)*sin(z))\n err_z = err_z + abs( fields%e(3,i,j,k) - cos(z)*sin(x)*sin(y))\n end do\n end do\nend do\n\nprint*, err_x, err_y, err_z\n\nend \n", "meta": {"hexsha": "8558eac3a49228c44316d29c0224085ab8030cc5", "size": 1426, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/test_poisson_3d.f90", "max_stars_repo_name": "JuliaVlasov/UAPIC.jl", "max_stars_repo_head_hexsha": "c11a786cddb0b3cc5f70ea372f39cbae1b338239", "max_stars_repo_licenses": ["MIT"], "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/test_poisson_3d.f90", "max_issues_repo_name": "JuliaVlasov/UAPIC.jl", "max_issues_repo_head_hexsha": "c11a786cddb0b3cc5f70ea372f39cbae1b338239", "max_issues_repo_licenses": ["MIT"], "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/test_poisson_3d.f90", "max_forks_repo_name": "JuliaVlasov/UAPIC.jl", "max_forks_repo_head_hexsha": "c11a786cddb0b3cc5f70ea372f39cbae1b338239", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.6666666667, "max_line_length": 74, "alphanum_fraction": 0.5273492286, "num_tokens": 578, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941962904956, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6819103263302443}} {"text": "subroutine frivel(delta,tveno,vikin,velfr)\n!------------------------------------------------------------------------\n!****f* Mathru/frivel\n! NAME \n! frivel\n! DESCRIPTION\n! Computes the friction velocity by the Newton-Raphson method. This \n! friction velocity is computed from U_p/U_*=(1/X)log(U_* D/nu)+C, \n! where X=0.41 (VONKA) is the von Karman constant, U_p is the tangent \n! wall velocity at the current integration point, C is a constant \n! which value is 5.5 and D = DELTA is a user defined parameter \n! (DELTA, its physical meaning being the boundary layer width. \n! The result is VELFR.\n! USES\n! USED BY\n! nsm_bouwal\n! tur_updnbc\n!***\n!------------------------------------------------------------------------\n use typre\n implicit none\n real(rp), intent(in) :: delta,tveno,vikin\n real(rp), intent(out) :: velfr\n integer(ip) :: itera,ndelt,j\n real(rp) :: xmuit,fdvfr,devfr\n real(rp) :: vkinv,diffd,parco,dplus\n real(rp) :: ypele,expye,expyt,oneoe,firsl\n!\n! Wall law taking into account the buffer zone and log layer:\n! u+ =1/k*ln(1+0.4*y+)+7.8*[1-exp(-y+/11-y+/11*exp(-0.33*y+)] \n! \n if (delta>0.0_rp) then\n velfr=sqrt(tveno*vikin/delta)\n if(velfr*delta/vikin>5.0_rp) then\n vkinv=1.0_rp/0.41_rp\n xmuit=delta/vikin ! D/nu\n itera=0 ! i=0\n velfr=tveno ! U_*^0\n parco=1.0_rp\n oneoe=1.0_rp/11.0_rp\n do while((parco>=1.0e-6).and.itera<100)\n itera=itera+1 ! i=i+1\n if(velfr<0.0_rp) velfr=0.0_rp\n dplus=velfr*xmuit\n ypele=dplus*oneoe\n expye=exp(-ypele)\n expyt=exp(-dplus*0.33_rp) \n firsl=vkinv*log(1.0_rp+0.4_rp*dplus)\n fdvfr=velfr*(firsl+7.8_rp*(1.0_rp-expye-ypele*expyt))-tveno ! F(U_*^i)\n diffd=firsl+vkinv*0.4_rp*dplus/(1.0_rp+0.4_rp*dplus)& ! DF(U_*^i)\n +7.8_rp*(1.0_rp-expye*(1.0_rp+ypele)&\n -ypele*expyt*(2.0_rp-dplus*0.33_rp)) \n devfr=-fdvfr/diffd ! delta(U_*^0)\n parco=abs(devfr/tveno) ! U_*^i=U_*^i-1\n velfr=velfr+devfr ! +delta(U_*)\n end do\n end if\n!\n! If DELTA = 0, the friction velocity is set to zero.\n!\n else\n velfr=0.0_rp\n end if\n \nend subroutine frivel\n", "meta": {"hexsha": "6963ec624b88b99578b713f04d1d25f4d0da9ecd", "size": 2646, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Sources/mathru/frivel.f90", "max_stars_repo_name": "ciaid-colombia/InsFEM", "max_stars_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-24T08:19:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-24T08:19:54.000Z", "max_issues_repo_path": "Sources/mathru/frivel.f90", "max_issues_repo_name": "ciaid-colombia/InsFEM", "max_issues_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Sources/mathru/frivel.f90", "max_forks_repo_name": "ciaid-colombia/InsFEM", "max_forks_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.0909090909, "max_line_length": 87, "alphanum_fraction": 0.4758125472, "num_tokens": 833, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172644875641, "lm_q2_score": 0.7185943925708561, "lm_q1q2_score": 0.6818866252744396}} {"text": "c program DRSEVUN\nc>> 1994-10-19 DRSEVUN Krogh Changes to use M77CON\nc>> 1992-04-23 DRSEVUN CLL Declaring all variables.\nc>> 1992-03-04 DRSEVUN Krogh Initial version.\nc Demonstrate unsymmetric eigenvalue subroutine SEVUN.\nc ------------------------------------------------------------------\nc--S replaces \"?\": DR?EVUN, ?EVUN, ?VECP\nc ------------------------------------------------------------------\n integer I, KASE, LDA, N\n parameter (LDA = 3)\n integer IFLAG(LDA)\n real A(LDA,LDA,3), VR(LDA), VI(LDA)\nc\n data (A(1,I,1), I=1,3) / -954.0e0, -464.0e0, -2088.0e0 /\n data (A(2,I,1), I=1,3) / 792.0e0, 387.0e0, 1728.0e0 /\n data (A(3,I,1), I=1,3) / 264.0e0, 128.0e0, 579.0e0 /\nc\n data (A(1,I,2), I=1,3) / 4.0e0, 1.0e0, 1.0e0 /\n data (A(2,I,2), I=1,3) / 2.0e0, 4.0e0, 1.0e0 /\n data (A(3,I,2), I=1,3) / 0.0e0, 1.0e0, 4.0e0 /\nc\n data (A(1,I,3), I=1,3) / 8.0e0, -1.0e0, -5.0e0 /\n data (A(2,I,3), I=1,3) / -4.0e0, 4.0e0, -2.0e0 /\n data (A(3,I,3), I=1,3) / 18.0e0, -5.0e0, -7.0e0 /\n data N / LDA /\nc ------------------------------------------------------------------\n print*,'DRSEVUN.. Demo driver for SEVUN.'\n do 10 KASE = 1, 3\n print '(/a,i2)',' Beginning Case =', KASE\n call SEVUN(A(1, 1, KASE), LDA, N, VR, VI, IFLAG)\n print '(a,i2)',' IFLAG(1) =', IFLAG(1)\n if (IFLAG(1) .le. 2) then\n call SVECP(VR, N, ' Real part of the eigenvalues')\n call SVECP(VI, N, ' Imaginary part of the eigenvalues')\n else\n print '(/a)',' Failure in SEVUN.'\n end if\n 10 continue\n stop\n end\n", "meta": {"hexsha": "885b86b1b3f10dcdcd79cb14ec6092b507ab6cf5", "size": 1682, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drsevun.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drsevun.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drsevun.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 41.0243902439, "max_line_length": 72, "alphanum_fraction": 0.4524375743, "num_tokens": 702, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637541053282, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.6818044457041414}} {"text": "!**********************************************************************\n! matmult.f90 - simple matrix multiply implementation \n!************************************************************************\n subroutine initialize(a, b, n)\n double precision a(n,n)\n double precision b(n,n)\n integer n\n\n! first initialize the A matrix\n do i = 1,n \n do j = 1,n \n a(j,i) = i \n end do\n end do\n\n! then initialize the B matrix\n do i = 1,n \n do j = 1,n \n b(j,i) = i \n end do\n end do\n\n end subroutine initialize\n \n subroutine multiply_matrices(answer, buffer, b, matsize)\n double precision buffer(matsize), answer(matsize)\n double precision b(matsize, matsize)\n integer i, j\n! multiply the row with the column \n\n do i = 1,matsize \n answer(i) = 0.0 \n do j = 1,matsize \n answer(i) = answer(i) + buffer(j)*b(j,i) \n end do\n end do\n end subroutine multiply_matrices\n\n program main\n include \"mpif.h\"\n\n integer SIZE_OF_MATRIX\n parameter (SIZE_OF_MATRIX = 1000) \n! try changing this value to 2000 to get rid of transient effects \n! at startup\n double precision a(SIZE_OF_MATRIX,SIZE_OF_MATRIX) \n double precision b(SIZE_OF_MATRIX,SIZE_OF_MATRIX) \n double precision c(SIZE_OF_MATRIX,SIZE_OF_MATRIX) \n double precision buffer(SIZE_OF_MATRIX), answer(SIZE_OF_MATRIX)\n\n integer myid, master, maxpe, ierr, status(MPI_STATUS_SIZE) \n integer i, j, numsent, sender \n integer answertype, row, flag\n integer matsize\n\n call MPI_INIT( ierr ) \n call MPI_COMM_RANK( MPI_COMM_WORLD, myid, ierr ) \n call MPI_COMM_SIZE( MPI_COMM_WORLD, maxpe, ierr ) \n print *, \"Process \", myid, \" of \", maxpe, \" is active\"\n\n master = 0 \n matsize = SIZE_OF_MATRIX \n\n if ( myid .eq. master ) then \n! master initializes and then dispatches \n! initialize a and b \n call initialize(a, b, matsize)\n numsent = 0\n\n! send b to each other process \n do i = 1,matsize \n call MPI_BCAST(b(1,i), matsize, MPI_DOUBLE_PRECISION, master, &\n MPI_COMM_WORLD, ierr) \n end do\n\n! send a row of a to each other process; tag with row number \n do i = 1,maxpe-1 \n do j = 1,matsize \n buffer(j) = a(i,j) \n end do\n call MPI_SEND(buffer, matsize, MPI_DOUBLE_PRECISION, i, &\n i, MPI_COMM_WORLD, ierr) \n numsent = numsent+1 \n end do\n\n do i = 1,matsize \n call MPI_RECV(answer, matsize, MPI_DOUBLE_PRECISION, &\n MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, status, ierr)\n sender = status(MPI_SOURCE) \n answertype = status(MPI_TAG) \n do j = 1,matsize \n c(answertype,j) = answer(j) \n end do\n\n if (numsent .lt. matsize) then \n do j = 1,matsize \n buffer(j) = a(numsent+1,j) \n end do\n call MPI_SEND(buffer, matsize, MPI_DOUBLE_PRECISION, sender,&\n numsent+1, MPI_COMM_WORLD, ierr) \n numsent = numsent+1 \n else \n call MPI_SEND(1.0, 1, MPI_DOUBLE_PRECISION, sender, 0, &\n MPI_COMM_WORLD, ierr) \n endif \n end do\n\n! print out one element of the answer\n print *, \"c(\", matsize, \",\", matsize, \") = \", c(matsize,matsize)\n else \n! workers receive B, then compute rows of C until done message \n do i = 1,matsize \n call MPI_BCAST(b(1,i), matsize, MPI_DOUBLE_PRECISION, master, &\n MPI_COMM_WORLD, ierr) \n end do\n flag = 1\n do while (flag .ne. 0)\n call MPI_RECV(buffer, matsize, MPI_DOUBLE_PRECISION, master, &\n MPI_ANY_TAG, MPI_COMM_WORLD, status, ierr) \n row = status(MPI_TAG) \n flag = row\n if (flag .ne. 0) then\n! multiply the matrices here using C(i,j) += sum (A(i,k)* B(k,j))\n call multiply_matrices(answer, buffer, b, matsize)\n call MPI_SEND(answer, matsize, MPI_DOUBLE_PRECISION, master,&\n row, MPI_COMM_WORLD, ierr) \n endif \n end do\n endif\n\n call MPI_FINALIZE(ierr) \n end program main\n", "meta": {"hexsha": "0ec30dfb095be33982facb1c2b6ec24fa0c5c0c1", "size": 4315, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/sc15/f90-mpi/matmult.f90", "max_stars_repo_name": "eugeneswalker/taucmdr", "max_stars_repo_head_hexsha": "33190f5268678979700793229602a5ec7638783e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "examples/sc15/f90-mpi/matmult.f90", "max_issues_repo_name": "eugeneswalker/taucmdr", "max_issues_repo_head_hexsha": "33190f5268678979700793229602a5ec7638783e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2015-01-07T17:32:03.000Z", "max_issues_repo_issues_event_max_datetime": "2015-01-14T13:53:48.000Z", "max_forks_repo_path": "examples/sc15/f90-mpi/matmult.f90", "max_forks_repo_name": "eugeneswalker/taucmdr", "max_forks_repo_head_hexsha": "33190f5268678979700793229602a5ec7638783e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2015-02-04T17:50:43.000Z", "max_forks_repo_forks_event_max_datetime": "2015-04-14T04:46:17.000Z", "avg_line_length": 32.4436090226, "max_line_length": 73, "alphanum_fraction": 0.5513325608, "num_tokens": 1108, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637469145054, "lm_q2_score": 0.7931059536292271, "lm_q1q2_score": 0.6818044357971034}} {"text": "program test_bessel\nuse types, only: dp\nuse constants, only: pi\nuse special_functions, only: Fm, Inu_formula2\nuse utils, only: assert, init_random\nimplicit none\ninteger :: i, n, k\nreal(dp) :: r\nreal(dp), allocatable :: yf(:), yr(:), x(:)\nreal(dp) :: t1, t2, t3\n\ncall init_random()\n\nn = 100000\nallocate(x(n), yf(n), yr(n))\ndo k = 0, 4\n print *, \"Testing k =\", k\n do i = 1, n\n call random_number(r)\n x(i) = r*40\n end do\n call cpu_time(t1)\n do i = 1, n\n yf(i) = f(k, x(i))\n end do\n call cpu_time(t2)\n do i = 1, n\n yr(i) = Inu_formula2(k, x(i))\n end do\n call cpu_time(t3)\n print *, \"abs:\", maxval(abs(yf-yr))\n print *, \"rel:\", maxval(abs(yf-yr) / max(abs(yf), abs(yr)))\n print *, \"time f(r):\", t2-t1\n print *, \"time r(r):\", t3-t2\n !print *, \"speedup:\", (t2-t1) / (t3-t2)\n print *\nend do\n\ncontains\n\nreal(dp) pure function f(k, x) result(r)\ninteger, intent(in) :: k\nreal(dp), intent(in) :: x\nselect case (k)\n case (0)\n r = sinh(x)\n case (1)\n r = -sinh(x)/x + cosh(x)\n case (2)\n r = (3/x**2 + 1)*sinh(x) - 3/x*cosh(x)\n case (3)\n r = -(15/x**3 + 6/x)*sinh(x) + (15/x**2 + 1)*cosh(x)\n case (4)\n r = (105/x**4 + 45/x**2 + 1)*sinh(x) - (105/x**3 + 10/x)*cosh(x)\nend select\nr = r * sqrt(2/(pi*x)) / exp(x)\nend function\n\nend program\n", "meta": {"hexsha": "844529262404dcf5fa0c11ad2afe2cf3c922071c", "size": 1346, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/test_bessel.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/tests/test_bessel.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/tests/test_bessel.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": 22.4333333333, "max_line_length": 72, "alphanum_fraction": 0.5237741456, "num_tokens": 520, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099168, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.681804430240738}} {"text": "SUBROUTINE DSPSVX_F95(A, B, X, UPLO, AFP, IPIV, FACT, &\n FERR, BERR, RCOND, INFO)\n!\n! -- LAPACK95 interface driver routine (version 3.0) --\n! UNI-C, Denmark; Univ. of Tennessee, USA; NAG Ltd., UK\n! September, 2000\n!\n! .. USE STATEMENTS ..\n USE LA_PRECISION, ONLY: WP => DP\n USE LA_AUXMOD, ONLY: LSAME, ERINFO\n USE F77_LAPACK, ONLY: SPSVX_F77 => LA_SPSVX\n! .. IMPLICIT STATEMENT ..\n IMPLICIT NONE\n! .. SCALAR ARGUMENTS ..\n CHARACTER(LEN=1), INTENT(IN), OPTIONAL :: UPLO, FACT\n INTEGER, INTENT(OUT), OPTIONAL :: INFO\n REAL(WP), INTENT(OUT), OPTIONAL :: RCOND\n! .. ARRAY ARGUMENTS ..\n REAL(WP), INTENT(IN) :: A(:), B(:,:)\n REAL(WP), INTENT(OUT) :: X(:,:)\n INTEGER, INTENT(INOUT), OPTIONAL, TARGET :: IPIV(:)\n REAL(WP), INTENT(INOUT), OPTIONAL, TARGET :: AFP(:)\n REAL(WP), INTENT(OUT), OPTIONAL, TARGET :: FERR(:), BERR(:)\n!----------------------------------------------------------------------\n! \n! Purpose\n! =======\n! \n! LA_SPSVX computes the solution to a linear system of equations\n! A*X = B, where A is a real or complex symmetric matrix stored in packed\n! format and X and B are rectangular matrices or vectors.\n! LA_HPSVX computes the solution to a linear system of equations \n! A*X = B, where A is a complex Hermitian matrix stored in packed format \n! and X and B are rectangular matrices or vectors.\n! LA_SPSVX and LA_HPSVX can also optionally estimate the condition \n! number of A and compute error bounds.\n! \n! =========\n! \n! SUBROUTINE LA_SPSVX / LA_HPSVX( AP, B, X, UPLO=uplo, AFP=afp, &\n! IPIV=ipiv, FACT=fact, FERR=ferr, BERR=berr, &\n! RCOND=rcond, INFO=info )\n! (), INTENT(IN) :: AP(:), \n! (), INTENT(OUT) :: \n! CHARACTER(LEN=1), INTENT(IN), OPTIONAL :: UPLO\n! (), INTENT(INOUT), OPTIONAL :: AFP(:)\n! INTEGER, INTENT(INOUT), OPTIONAL :: IPIV(:)\n! CHARACTER(LEN=1), INTENT(IN), OPTIONAL :: FACT\n! REAL(), INTENT(OUT), OPTIONAL :: , RCOND\n! INTEGER, INTENT(OUT), OPTIONAL :: INFO\n! where\n! ::= REAL | COMPLEX\n! ::= KIND(1.0) | KIND(1.0D0)\n! ::= B(:,:) | B(:)\n! ::= X(:,:) | X(:)\n! ::= FERR(:), BERR(:) | FERR, BERR\n! \n! Arguments\n! =========\n! \n! AP (input) REAL or COMPLEX array, shape (:) with size(AP ) = \n! n*(n + 1)/2, where n is the order of A.\n! On entry, the upper or lower triangle of matrix A in packed \n! \t storage. The elements are stored columnwise as follows:\n! if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j<=n;\n! \t if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for 1<=j<=i<=n.\n! B (input) REAL or COMPLEX array, shape (:,:) with \n! size(B,1) = n or shape (:) with size(B) = n.\n! The matrix B.\n! X (output) REAL or COMPLEX array, shape (:,:) with \n! size(X,1) = n and size(X,2) = size(B,2), or shape (:) with \n! \t size(X) = n.\n! The solution matrix X .\n! UPLO Optional (input) CHARACTER(LEN=1).\n! = 'U': Upper triangle of A is stored;\n! = 'L': Lower triangle of A is stored.\n! Default value: 'U'.\n! AFP Optional (input or output) REAL or COMPLEX array, shape (:,:)\n! with the same size as AP.\n! If FACT = 'F', then AFP is an input argument that contains \n! \t the block diagonal matrix D and the multipliers used to \n! \t obtain the factor L or U from the factorization of A, returned\n! \t by a previous call to LA_SPSVX or LA_HPSVX and stored as a \n! \t packed triangular matrix in the same storage format as A.\n! If FACT = 'N', then AFP is an output argument that contains \n! \t the block diagonal matrix D and the multipliers used to obtain\n! \t the factor L or U from the factorization of A, stored as a\n! packed triangular matrix in the same storage format as A.\n! IPIV Optional (input or output) INTEGER array, shape (:) with \n! size(IPIV) = size(A,1).\n! If FACT = 'F', then IPIV is an input argument that contains \n! \t details of the row and column interchanges and the block \n! \t structure of D.\n! If IPIV(k) > 0 , then rows and columns k and IPIV(k) were \n! \t interchanged and D(k,k) is a 1 by 1 diagonal block.\n! If IPIV(k) < 0 , then there are two cases:\n! 1. If UPLO = 'U' and IPIV(k) = IPIV(k-1) < 0, then rows and\n! \t columns (k-1) and -IPIV(k) were interchanged and \n! \t D(k-1:k,k-1:k) is a 2 by 2 diagonal block.\n! 2. If UPLO = 'L' and IPIV(k) = IPIV(k+1) < 0, then rows and\n! \t columns (k+1) and -IPIV(k) were interchanged and \n! \t D(k:k+1,k:k+1) is a 2 by 2 diagonal block.\n! If FACT = 'N', then IPIV is an output argument and on exit \n! \t contains details of the interchanges and the block structure\n! \t of D (as described above).\n! FACT Optional (input) CHARACTER(LEN=1).\n! Specifies whether the factored form of A has been supplied \n! \t on entry.\n! = 'N': The matrix A will be copied to AFP and factored.\n! = 'F': AFP and IPIV contain the factored form of A.\n! Default value: 'N'.\n! FERR Optional (output) REAL array of shape (:), with size(FERR)=\n! size(X,2), or REAL scalar.\n! The estimated forward error bound for each solution vector \n! \t X(j) (the j-th column of the solution matrix X). If XTRUE is\n! \t the true solution corresponding to X(j) , FERR(j) is an\n! estimated upper bound for the magnitude of the largest element\n! \t in (X(j)-XTRUE) divided by the magnitude of the largest \n! \t element in X(j). The estimate is as reliable as the estimate\n! for RCOND, and is almost always a slight overestimate of the \n! \t true error.\n! BERR Optional (output) REAL array of shape (:), with size(BERR) =\n! size(X,2), or REAL scalar.\n! The componentwise relative backward error of each solution \n! \t vector X(j) (i.e., the smallest relative change in any element\n! \t of A or B that makes X(j) an exact solution).\n! RCOND Optional (output) REAL\n! The estimate of the reciprocal condition number of A. If RCOND\n! \t is less than the machine precision, the matrix is singular to\n! \t working precision. This condition is indicated by a return\n! code of INFO > 0.\n! INFO (output) INTEGER\n! = 0: successful exit.\n! < 0: if INFO = -i, the i-th argument had an illegal value.\n! > 0: if INFO = i, and i is\n! <= n: D(i,i) = 0. The factorization has been completed, but\n! \t the block diagonal matrix D is singular, so the \n! \t\t solution could not be computed.\n! = n+1: D is nonsingular, but RCOND is less than machine \n! \t precision, so the matrix is singular to working \n! \t\t precision. Nevertheless, the solution and error bounds\n! \t\t are computed because the computed solution can be more\n! \t\t accurate than the value of RCOND would suggest.\n! n is the order of A.\n! If INFO is not present and an error occurs, then the program\n! \t is terminated with an error message.\n!----------------------------------------------------------------------\n! .. PARAMETERS ..\n CHARACTER(LEN=8), PARAMETER :: SRNAME = 'LA_SPSVX'\n! .. LOCAL SCALARS ..\n CHARACTER(LEN=1) :: LFACT, LUPLO\n INTEGER :: LINFO, NRHS, N, NN, ISTAT, ISTAT1, SIPIV, SAF, SFERR, SBERR\n REAL(WP) :: LRCOND\n COMPLEX(WP) :: WW\n! .. LOCAL POINTERS ..\n INTEGER, POINTER :: IWORK(:), LPIV(:)\n REAL(WP), POINTER :: LFERR(:), LBERR(:)\n REAL(WP), POINTER :: WORK(:), LAF(:)\n! .. INTRINSIC FUNCTIONS ..\n INTRINSIC MAX, PRESENT, SIZE\n! .. EXECUTABLE STATEMENTS ..\n LINFO = 0; ISTAT = 0; NN = SIZE(A); NRHS = SIZE(B, 2)\n WW = (-1+SQRT(1+8*REAL(NN,WP)))*0.5; N = INT(WW)\n IF( PRESENT(RCOND) ) RCOND = 1.0_WP\n IF( PRESENT(FACT) )THEN; LFACT = FACT; ELSE; LFACT='N'; END IF\n IF( PRESENT(UPLO) ) THEN; LUPLO = UPLO; ELSE; LUPLO = 'U'; END IF\n IF( PRESENT(IPIV) )THEN; SIPIV = SIZE(IPIV); ELSE; SIPIV = N; END IF\n IF( PRESENT(AFP) )THEN; SAF = SIZE(AFP); ELSE; SAF = NN; END IF\n IF( PRESENT(FERR) )THEN; SFERR = SIZE(FERR); ELSE; SFERR = NRHS; END IF\n IF( PRESENT(BERR) )THEN; SBERR = SIZE(BERR); ELSE; SBERR = NRHS; END IF\n! .. TEST THE ARGUMENTS\n IF( NN < 0 .OR. AIMAG(WW) /= 0 .OR. REAL(N,WP) /= REAL(WW) ) THEN; LINFO = -1\n ELSE IF( SIZE(B, 1) /= N .OR. NRHS < 0 )THEN; LINFO = -2\n ELSE IF( SIZE(X, 1) /= N .OR. SIZE(X, 2) /= NRHS )THEN; LINFO = -3\n ELSE IF( .NOT.LSAME(LUPLO,'U') .AND. .NOT.LSAME(LUPLO,'L') )THEN; LINFO = -4\n ELSE IF( SAF /= NN ) THEN; LINFO = -5\n ELSE IF( SIPIV /= N )THEN; LINFO = -6\n ELSE IF( ( .NOT. LSAME(LFACT,'F') .AND. .NOT. LSAME(LFACT,'N') ) .OR. &\n ( LSAME(LFACT,'F') .AND. .NOT.( PRESENT(AFP) .AND. PRESENT(IPIV) ) ) )THEN; LINFO = -7\n ELSE IF( SFERR /= NRHS )THEN; LINFO = -8\n ELSE IF( SBERR /= NRHS )THEN; LINFO = -9\n ELSE IF ( N > 0 )THEN\n IF( .NOT.PRESENT(AFP) ) THEN; ALLOCATE( LAF(NN), STAT=ISTAT )\n ELSE; LAF => AFP; END IF\n IF( ISTAT == 0 )THEN\n IF( .NOT.PRESENT(IPIV) )THEN; ALLOCATE( LPIV(N), STAT=ISTAT )\n ELSE; LPIV => IPIV; END IF\n END IF\n IF( ISTAT == 0 )THEN\n IF( .NOT.PRESENT(FERR) )THEN; ALLOCATE( LFERR(NRHS), STAT=ISTAT )\n ELSE; LFERR => FERR; END IF\n END IF\n IF( ISTAT == 0 )THEN\n IF( .NOT.PRESENT(BERR) )THEN; ALLOCATE( LBERR(NRHS), STAT=ISTAT )\n ELSE; LBERR => BERR; END IF\n END IF\n IF( ISTAT == 0 )THEN\n ALLOCATE(WORK(MAX(1,3*N)), IWORK(N), STAT=ISTAT)\n END IF\n IF( ISTAT == 0 )THEN\n! .. CALL LAPACK77 ROUTINE\n CALL SPSVX_F77( LFACT, LUPLO, N, NRHS, A, LAF, LPIV, B, N, X, N, &\n LRCOND, LFERR, LBERR, WORK, IWORK, LINFO )\n ELSE; LINFO = -100; END IF\n IF( .NOT.PRESENT(AFP) ) DEALLOCATE( LAF, STAT=ISTAT1 )\n IF( .NOT.PRESENT(IPIV) ) DEALLOCATE( LPIV, STAT=ISTAT1 )\n IF( .NOT.PRESENT(FERR) ) DEALLOCATE( LFERR, STAT=ISTAT1 )\n IF( .NOT.PRESENT(BERR) ) DEALLOCATE( LBERR, STAT=ISTAT1 )\n IF( PRESENT(RCOND) ) RCOND=LRCOND\n DEALLOCATE( WORK, IWORK, STAT=ISTAT1 )\n END IF\n CALL ERINFO( LINFO, SRNAME, INFO, ISTAT )\nEND SUBROUTINE DSPSVX_F95\n", "meta": {"hexsha": "185225430ce3dfa710b06ad4939a778bf5688784", "size": 10391, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/la_dspsvx.f90", "max_stars_repo_name": "MattBurn/LAPACK95", "max_stars_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-12-29T15:07:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T10:09:22.000Z", "max_issues_repo_path": "src/la_dspsvx.f90", "max_issues_repo_name": "MattBurn/LAPACK95", "max_issues_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-02-21T10:46:38.000Z", "max_issues_repo_issues_event_max_datetime": "2017-10-20T17:03:14.000Z", "max_forks_repo_path": "src/la_dspsvx.f90", "max_forks_repo_name": "MattBurn/LAPACK95", "max_forks_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-12-29T15:34:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-15T07:12:40.000Z", "avg_line_length": 48.5560747664, "max_line_length": 91, "alphanum_fraction": 0.5775190068, "num_tokens": 3376, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772417253256, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.68177404728965}} {"text": " PROGRAM TEST\n INTEGER X\n \n X = 14 + 2\n ASSERT X.EQ.16\n \n X = 14 - 2\n ASSERT X.EQ.12\n \n X = 14 * 2\n ASSERT X.EQ.28\n \n X = 14 / 2\n ASSERT X.EQ.7\n \n X = 2 * 3 + 4\n ASSERT X.EQ.10\n \n X = 2 + 3 * 4\n ASSERT X.EQ.14\n \n X = 2 * (3 + 4)\n ASSERT X.EQ.14\n \n END\n", "meta": {"hexsha": "128412e7352d6d623d93d9faf1208ace99a984cf", "size": 377, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/library/fortran/arithmetic.f", "max_stars_repo_name": "chrisseaton/katahdin", "max_stars_repo_head_hexsha": "5746e3a6dab10749815af59202dbaf28595d6e1b", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 115, "max_stars_repo_stars_event_min_datetime": "2015-01-20T08:25:15.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-19T18:10:08.000Z", "max_issues_repo_path": "tests/library/fortran/arithmetic.f", "max_issues_repo_name": "chrisseaton/katahdin", "max_issues_repo_head_hexsha": "5746e3a6dab10749815af59202dbaf28595d6e1b", "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": "tests/library/fortran/arithmetic.f", "max_forks_repo_name": "chrisseaton/katahdin", "max_forks_repo_head_hexsha": "5746e3a6dab10749815af59202dbaf28595d6e1b", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2015-08-16T02:51:35.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-20T22:34:55.000Z", "avg_line_length": 14.5, "max_line_length": 21, "alphanum_fraction": 0.3342175066, "num_tokens": 139, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648677, "lm_q2_score": 0.7799929104825006, "lm_q1q2_score": 0.6817740466427423}} {"text": "subroutine cal_combination(n, m, cnm)\n use m_constants, only: dp\n\n implicit none\n\n ! external variables\n integer, intent(in) :: n\n integer, intent(in) :: m\n integer, intent(out) :: cnm\n\n ! local variables\n integer :: small\n integer :: large\n integer :: i\n\n real(dp) :: x\n real(dp) :: y\n\n small = min(m,n-m)\n large = max(m,n-m)\n \n x = 1.0_dp\n y = 1.0_dp\n do i=large+1, n\n x = x * dble(i)\n enddo \n\n do i=1, small\n y = y * dble(i)\n enddo\n\n cnm = nint(x / y)\n\n return\nend subroutine cal_combination\n\n!!>>> get new fock state and the sign\nsubroutine make_newfock(c_type, pos, old, new, sgn)\n use m_constants, only: mystd, dp\n\n implicit none\n\n character(1), intent(in) :: c_type\n integer, intent(in) :: pos\n integer(dp), intent(in) :: old\n integer(dp), intent(out) :: new\n integer, intent(out) :: sgn\n\n integer :: i\n\n sgn = 0\n do i=1,pos-1\n if (btest(old, i-1) .eqv. .true.) sgn = sgn + 1\n enddo \n sgn = mod(sgn,2)\n sgn = (-1)**sgn\n\n if (c_type == '+') then\n new = old + (2_dp)**(pos-1)\n elseif (c_type == '-') then\n new = old - (2_dp)**(pos-1)\n else\n write(mystd, \"(58a,a)\") \"edrixs >>> error of create and destroy operator type: \", c_type\n STOP\n endif\n\n return\nend subroutine make_newfock\n", "meta": {"hexsha": "adabf99cf8bec2d820c701e999c26cce5ae59c64", "size": 1372, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fock.f90", "max_stars_repo_name": "danielballan/edrixs", "max_stars_repo_head_hexsha": "57fbd11ba9aaeaa393c3e2f06af41e4e386749e4", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/fock.f90", "max_issues_repo_name": "danielballan/edrixs", "max_issues_repo_head_hexsha": "57fbd11ba9aaeaa393c3e2f06af41e4e386749e4", "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/fock.f90", "max_forks_repo_name": "danielballan/edrixs", "max_forks_repo_head_hexsha": "57fbd11ba9aaeaa393c3e2f06af41e4e386749e4", "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.884057971, "max_line_length": 97, "alphanum_fraction": 0.5415451895, "num_tokens": 460, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648677, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6817740332321329}} {"text": "( http://www.softsynth.com/pforth/pf_tut.php )\n\n: square ( n -- s )\n dup * ;\n\n\n: fibonacci ( n -- s )\n dup 1 <=\n if drop 1\n else dup 1 - swap 2 -\n recurse swap recurse\n + then ;\n\n: sum-of-squares ( a b -- c )\n square swap square + ;\n\n", "meta": {"hexsha": "d29cf4e7eca20f87761a5a7da7fe987e059d1b65", "size": 251, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "exercises/challenges/forth/fibonacci-sum-of-squares.f", "max_stars_repo_name": "luksamuk/study", "max_stars_repo_head_hexsha": "7a4062cb894be52d786852b4729ac6a4e784b5a3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-13T02:16:44.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-05T21:14:18.000Z", "max_issues_repo_path": "exercises/challenges/forth/fibonacci-sum-of-squares.f", "max_issues_repo_name": "luksamuk/study", "max_issues_repo_head_hexsha": "7a4062cb894be52d786852b4729ac6a4e784b5a3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-03-15T00:52:59.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-15T00:53:54.000Z", "max_forks_repo_path": "exercises/challenges/forth/fibonacci-sum-of-squares.f", "max_forks_repo_name": "luksamuk/study", "max_forks_repo_head_hexsha": "7a4062cb894be52d786852b4729ac6a4e784b5a3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-03-05T21:14:29.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-05T21:14:29.000Z", "avg_line_length": 14.7647058824, "max_line_length": 46, "alphanum_fraction": 0.5298804781, "num_tokens": 82, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8740772351648677, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6817740332321329}} {"text": "!*****************************************************************************************\n!>\n! Units test for 1d-6d tensor product b-spline interpolation (object-oriented version).\n\n program bspline_oo_test\n\n use bspline_module\n use bspline_kinds_module, only: wp, ip\n\n implicit none\n\n integer(ip),parameter :: nx = 6 !number of points\n integer(ip),parameter :: ny = 6\n integer(ip),parameter :: nz = 6\n integer(ip),parameter :: nq = 6\n integer(ip),parameter :: nr = 6\n integer(ip),parameter :: ns = 6\n\n integer(ip),parameter :: kx = 4 !order\n integer(ip),parameter :: ky = 4\n integer(ip),parameter :: kz = 4\n integer(ip),parameter :: kq = 4\n integer(ip),parameter :: kr = 4\n integer(ip),parameter :: ks = 4\n\n real(wp) :: x(nx),y(ny),z(nz),q(nq),r(nr),s(ns)\n real(wp) :: fcn_1d(nx)\n real(wp) :: fcn_2d(nx,ny)\n real(wp) :: fcn_3d(nx,ny,nz)\n real(wp) :: fcn_4d(nx,ny,nz,nq)\n real(wp) :: fcn_5d(nx,ny,nz,nq,nr)\n real(wp) :: fcn_6d(nx,ny,nz,nq,nr,ns)\n\n type(bspline_1d) :: s1\n type(bspline_2d) :: s2\n type(bspline_3d) :: s3\n type(bspline_4d) :: s4\n type(bspline_5d) :: s5\n type(bspline_6d) :: s6\n\n real(wp) :: tol\n real(wp),dimension(6) :: val,tru,err,errmax\n logical :: fail\n integer(ip) :: i,j,k,l,m,n,idx,idy,idz,idq,idr,ids\n integer(ip),dimension(6) :: iflag\n\n fail = .false.\n tol = 100 * epsilon(1.0_wp)\n idx = 0\n idy = 0\n idz = 0\n idq = 0\n idr = 0\n ids = 0\n\n do i=1,nx\n x(i) = real(i-1,wp)/real(nx-1,wp)\n end do\n do j=1,ny\n y(j) = real(j-1,wp)/real(ny-1,wp)\n end do\n do k=1,nz\n z(k) = real(k-1,wp)/real(nz-1,wp)\n end do\n do l=1,nq\n q(l) = real(l-1,wp)/real(nq-1,wp)\n end do\n do m=1,nr\n r(m) = real(m-1,wp)/real(nr-1,wp)\n end do\n do n=1,ns\n s(n) = real(n-1,wp)/real(ns-1,wp)\n end do\n do i=1,nx\n fcn_1d(i) = f1(x(i))\n do j=1,ny\n fcn_2d(i,j) = f2(x(i),y(j))\n do k=1,nz\n fcn_3d(i,j,k) = f3(x(i),y(j),z(k))\n do l=1,nq\n fcn_4d(i,j,k,l) = f4(x(i),y(j),z(k),q(l))\n do m=1,nr\n fcn_5d(i,j,k,l,m) = f5(x(i),y(j),z(k),q(l),r(m))\n do n=1,ns\n fcn_6d(i,j,k,l,m,n) = f6(x(i),y(j),z(k),q(l),r(m),s(n))\n end do\n end do\n end do\n end do\n end do\n end do\n\n !initialize:\n\n call s1%initialize(x,fcn_1d,kx,iflag(1))\n call s2%initialize(x,y,fcn_2d,kx,ky,iflag(2))\n call s3%initialize(x,y,z,fcn_3d,kx,ky,kz,iflag(3))\n call s4%initialize(x,y,z,q,fcn_4d,kx,ky,kz,kq,iflag(4))\n call s5%initialize(x,y,z,q,r,fcn_5d,kx,ky,kz,kq,kr,iflag(5))\n call s6%initialize(x,y,z,q,r,s,fcn_6d,kx,ky,kz,kq,kr,ks,iflag(6))\n\n if (any(iflag/=0)) then\n do i=1,6\n if (iflag(i)/=0) then\n write(*,*) 'Error initializing ',i,'D spline: '//get_status_message(iflag(i))\n end if\n end do\n end if\n\n write(*,*) ''\n write(*,*) 'size of 1d structure: ', s1%size_of()*8_ip, 'bytes'\n write(*,*) 'size of 2d structure: ', s2%size_of()*8_ip, 'bytes'\n write(*,*) 'size of 3d structure: ', s3%size_of()*8_ip, 'bytes'\n write(*,*) 'size of 4d structure: ', s4%size_of()*8_ip, 'bytes'\n write(*,*) 'size of 5d structure: ', s5%size_of()*8_ip, 'bytes'\n write(*,*) 'size of 6d structure: ', s6%size_of()*8_ip, 'bytes'\n write(*,*) ''\n\n ! compute max error at interpolation points\n\n errmax = 0.0_wp\n do i=1,nx\n call s1%evaluate(x(i),idx,val(1),iflag(1))\n tru(1) = f1(x(i))\n err(1) = abs(tru(1)-val(1))\n errmax(1) = max(err(1),errmax(1))\n do j=1,ny\n call s2%evaluate(x(i),y(j),idx,idy,val(2),iflag(2))\n tru(2) = f2(x(i),y(j))\n err(2) = abs(tru(2)-val(2))\n errmax(2) = max(err(2),errmax(2))\n do k=1,nz\n call s3%evaluate(x(i),y(j),z(k),idx,idy,idz,val(3),iflag(3))\n tru(3) = f3(x(i),y(j),z(k))\n err(3) = abs(tru(3)-val(3))\n errmax(3) = max(err(3),errmax(3))\n do l=1,nq\n call s4%evaluate(x(i),y(j),z(k),q(l),idx,idy,idz,idq,val(4),iflag(4))\n tru(4) = f4(x(i),y(j),z(k),q(l))\n err(4) = abs(tru(4)-val(4))\n errmax(4) = max(err(4),errmax(4))\n do m=1,nr\n call s5%evaluate(x(i),y(j),z(k),q(l),r(m),idx,idy,idz,idq,idr,val(5),iflag(5))\n tru(5) = f5(x(i),y(j),z(k),q(l),r(m))\n err(5) = abs(tru(5)-val(5))\n errmax(5) = max(err(5),errmax(5))\n do n=1,ns\n call s6%evaluate(x(i),y(j),z(k),q(l),r(m),s(n),idx,idy,idz,idq,idr,ids,val(6),iflag(6))\n tru(6) = f6(x(i),y(j),z(k),q(l),r(m),s(n))\n err(6) = abs(tru(6)-val(6))\n errmax(6) = max(err(6),errmax(6))\n end do\n end do\n end do\n end do\n end do\n end do\n\n ! check max error against tolerance\n do i=1,6\n write(*,*) i,'D: max error:', errmax(i)\n if (errmax(i) >= tol) then\n write(*,*) ' ** test failed ** '\n else\n write(*,*) ' ** test passed ** '\n end if\n write(*,*) ''\n end do\n\n contains\n\n real(wp) function f1(x) !! 1d test function\n implicit none\n real(wp) :: x\n f1 = 0.5_wp * (x*exp(-x) + sin(x) )\n end function f1\n\n real(wp) function f2(x,y) !! 2d test function\n implicit none\n real(wp) x,y,piov2\n piov2 = 2.0_wp * atan(1.0_wp)\n f2 = 0.5_wp * (y*exp(-x) + sin(piov2*y) )\n end function f2\n\n real(wp) function f3 (x,y,z) !! 3d test function\n implicit none\n real(wp) x,y,z,piov2\n piov2 = 2.0_wp*atan(1.0_wp)\n f3 = 0.5_wp*( y*exp(-x) + z*sin(piov2*y) )\n end function f3\n\n real(wp) function f4 (x,y,z,q) !! 4d test function\n implicit none\n real(wp) x,y,z,q,piov2\n piov2 = 2.0_wp*atan(1.0_wp)\n f4 = 0.5_wp*( y*exp(-x) + z*sin(piov2*y) + q )\n end function f4\n\n real(wp) function f5 (x,y,z,q,r) !! 5d test function\n implicit none\n real(wp) x,y,z,q,r,piov2\n piov2 = 2.0_wp*atan(1.0_wp)\n f5 = 0.5_wp*( y*exp(-x) + z*sin(piov2*y) + q*r )\n end function f5\n\n real(wp) function f6 (x,y,z,q,r,s) !! 6d test function\n implicit none\n real(wp) x,y,z,q,r,s,piov2\n piov2 = 2.0_wp*atan(1.0_wp)\n f6 = 0.5_wp*( y*exp(-x) + z*sin(piov2*y) + q*r + 2.0_wp*s )\n end function f6\n\n end program bspline_oo_test\n", "meta": {"hexsha": "00bab30e226d248803f990288a0e01242518d04e", "size": 7118, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/test_oo.f90", "max_stars_repo_name": "jacobwilliams/bspline-fortran", "max_stars_repo_head_hexsha": "5c0f836e0043e51d86420f321f607ff8ae21ca98", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 139, "max_stars_repo_stars_event_min_datetime": "2015-02-25T08:11:20.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T17:33:50.000Z", "max_issues_repo_path": "src/tests/test_oo.f90", "max_issues_repo_name": "jacobwilliams/bspline-fortran", "max_issues_repo_head_hexsha": "5c0f836e0043e51d86420f321f607ff8ae21ca98", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 46, "max_issues_repo_issues_event_min_datetime": "2015-06-19T18:25:15.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T21:14:15.000Z", "max_forks_repo_path": "src/tests/test_oo.f90", "max_forks_repo_name": "jacobwilliams/bspline-fortran", "max_forks_repo_head_hexsha": "5c0f836e0043e51d86420f321f607ff8ae21ca98", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 51, "max_forks_repo_forks_event_min_datetime": "2015-09-17T16:52:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-26T03:18:28.000Z", "avg_line_length": 33.261682243, "max_line_length": 111, "alphanum_fraction": 0.4551840405, "num_tokens": 2532, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.6817370513605344}} {"text": " PROGRAM xmprove\r\nC driver for routine mprove\r\n INTEGER N,NP\r\n PARAMETER(N=5,NP=5)\r\n INTEGER i,j,idum,indx(N)\r\n REAL d,a(NP,NP),b(N),x(N),aa(NP,NP),ran3\r\n DATA a/1.0,2.0,1.0,4.0,5.0,2.0,3.0,1.0,5.0,1.0,\r\n * 3.0,4.0,1.0,1.0,2.0,4.0,5.0,1.0,2.0,3.0,\r\n * 5.0,1.0,1.0,3.0,4.0/\r\n DATA b/1.0,1.0,1.0,1.0,1.0/\r\n do 12 i=1,N\r\n x(i)=b(i)\r\n do 11 j=1,N\r\n aa(i,j)=a(i,j)\r\n11 continue\r\n12 continue\r\n call ludcmp(aa,N,NP,indx,d)\r\n call lubksb(aa,N,NP,indx,x)\r\n write(*,'(/1x,a)') 'Solution vector for the equations:'\r\n write(*,'(1x,5f12.6)') (x(i),i=1,N)\r\nC now phoney up x and let mprove fix it\r\n idum=-13\r\n do 13 i=1,N\r\n x(i)=x(i)*(1.0+0.2*ran3(idum))\r\n13 continue\r\n write(*,'(/1x,a)') 'Solution vector with noise added:'\r\n write(*,'(1x,5f12.6)') (x(i),i=1,N)\r\n call mprove(a,aa,N,NP,indx,b,x)\r\n write(*,'(/1x,a)') 'Solution vector recovered by MPROVE:'\r\n write(*,'(1x,5f12.6)') (x(i),i=1,N)\r\n END\r\n", "meta": {"hexsha": "4b9ea0c1216a9f06a27c616c07c4f8178f8a2e20", "size": 1053, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xmprove.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xmprove.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xmprove.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.90625, "max_line_length": 64, "alphanum_fraction": 0.4890788224, "num_tokens": 466, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.787931190663057, "lm_q1q2_score": 0.6817370470518588}} {"text": "program main\n use MathClass\n implicit none\n \n ! computing derivative\n print *, d_dx(myfunc ,x=0.10d0)\n print *, d_dx(my_vec_func ,x=[0.10d0, 2.0d0],dim_num=2)\n \ncontains\n\nfunction myfunc(x) result(ret)\n real(real64),parameter :: a=2.0d0\n real(real64),parameter :: b=1.0d0\n real(real64),intent(in) :: x\n real(real64) :: ret\n ret = a*x*x + b\nend function\n\n\nfunction my_vec_func(x) result(ret)\n real(real64),parameter :: a=2.0d0\n real(real64),parameter :: b=1.0d0\n real(real64),intent(in) :: x(:)\n real(real64),allocatable :: ret(:)\n ret = a*x + b\nend function\n\nend program main", "meta": {"hexsha": "6eaf8c52c44b34228eacf857b0ca369f14c5aaa1", "size": 631, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/automatic_derivative.f90", "max_stars_repo_name": "kazulagi/faba", "max_stars_repo_head_hexsha": "7ef140f1ebea0e0ca496d14fdb94a3c024393cfa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-05T06:04:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:04:25.000Z", "max_issues_repo_path": "Tutorial/std/automatic_derivative.f90", "max_issues_repo_name": "kazulagi/plantFEM_binary", "max_issues_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Tutorial/std/automatic_derivative.f90", "max_forks_repo_name": "kazulagi/plantFEM_binary", "max_forks_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.5357142857, "max_line_length": 59, "alphanum_fraction": 0.6244057052, "num_tokens": 211, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513842182777, "lm_q2_score": 0.760650658103136, "lm_q1q2_score": 0.6817342052314795}} {"text": "subroutine SHReturnTapers(theta0, lmax, tapers, eigenvalues, taper_order)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis subroutine will return all the eigenvalues and \n!\teigenfunctions for the space concentration problem of\n!\ta spherical cap of angular radius theta0. The returned\n!\teigenfunctions correspond to \"geodesy\" normalized spherical \n!\tharmonic coefficients, and the eigenfunctions are further\n!\tnormalized such that they have unit power (i.e., the integral \n!\tof the function squared over the sphere divided by 4 pi is 1, \n!\tand the sum of the squares of their coefficients is 1). \n!\tThe eigenfunctions are calculated using the\n!\tkernel of Grunbaum et al. 1982, and the eigenvalues are \n!\tcalculated by numerical integration. \n!\n!\n!\tCalling Parameters\n!\t\tIN\n!\t\t\ttheta0\t\tAngular radius of spherical cap\n!\t\t\t\t\tin RADIANS.\n!\t\t\tlmax\t\tMaximum spherical harmonic degree\n!\t\t\t\t\tfor the concentration problem.\n!\t\tOUT\n!\t\t\ttapers\t\tAn (lmax+1) by (lmax+1) array containing\n!\t\t\t\t\tall the eigenfunctions of the space-\n!\t\t\t\t\tconcentration kernel. Eigenfunctions\n!\t\t\t\t\tare listed by columns in decreasing order\n!\t\t\t\t\tcorresponding to value of their eigenvalue.\n!\t\t\teigenvalues\tA vector of length lmax+1 containing the\n!\t\t\t\t\teigenvalued corresponding to the individual\n!\t\t\t\t\teigenfunctions.\n!\t\t\ttaper_order\tA vector of dimension X denoting which order m\n!\t\t\t\t\tcorresponds to the column of tapers and \n!\t\t\t\t\teigenvalues.\n!\n!\tDependencies: LAPACK, BLAS, ComputeDG82, EigValVecSymTri, PreGLQ, PlmBar, PlmIndex\n!\n!\tWritten by Mark Wieczorek 2006\n!\n!\tCopyright (c) 2005, Mark A. Wieczorek\n!\tAll rights reserved.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\tuse SHTOOLS, only: ComputeDG82, EigValVecSymTri, PreGLQ, PlmBar, PlmIndex\n\n\timplicit none\n\t\t\n\treal*8, intent(in) ::\ttheta0\n\tinteger, intent(in) ::\tlmax\n\treal*8, intent(out) ::\ttapers(:,:), eigenvalues(:)\n\tinteger, intent(out) ::\ttaper_order(:)\n\tinteger ::\t\tl, m, nt, nt2, n, i, j, jj(1), astat(8), n_int\n\treal*8, allocatable :: \teval(:), evec(:, :), tapers_unordered(:,:), &\n\t\t\t\tdllmtri(:,:), eval_unordered(:), p(:)\n\treal*8 :: \t\tpi, upper, lower, w(lmax+1), zero(lmax+1), h\n\tinteger, allocatable ::\tm_unordered(:)\n\t\n\t\n\tif (size(tapers(:,1)) < (lmax+1) .or. size(tapers(1,:)) < (lmax+1)**2) then\n\t\tprint*, \"Error --- SHReturnTapers\"\n\t\tprint*, \"TAPERS must be dimensioned as ( LMAX+1, (LMAX+1)**2 ) where LMAX is \", lmax\n\t\tprint*, \"Input array is dimensioned as \", size(tapers(:,1)), size(tapers(1,:))\n\t\tstop\n\telseif(size(eigenvalues) < (lmax+1)**2) then\n\t\tprint*, \"Error --- SHReturnTapers\"\n\t\tprint*, \"EIGENVALUES must be dimensioned as (LMAX+1)**2 where LMAX is \", lmax\n\t\tprint*, \"Input array is dimensioned as \", size(eigenvalues)\n\t\tstop\n\telseif(size(taper_order) < (lmax+1)**2) then\n\t\tprint*, \"Error --- SHReturnTapers\"\n\t\tprint*, \"TAPER_ORDER must be dimensioned as (LMAX+1)**2 where LMAX is \", lmax\n\t\tprint*, \"Input array is dimensioned as \", size(taper_order)\n\t\tstop\n\tendif\n\n\t\n\tallocate(eval(lmax+1), stat = astat(1))\n\tallocate(evec(lmax+1, lmax+1), stat = astat(2))\n\tallocate(tapers_unordered(lmax+1, (lmax+1)**2), stat = astat(3))\n\tallocate(dllmtri(lmax+1, lmax+1), stat = astat(4))\n\tallocate(eval_unordered((lmax+1)**2), stat = astat(5))\n\tallocate(m_unordered((lmax+1)**2), stat = astat(6))\n\tallocate(p((lmax+1)*(lmax+2)/2), stat = astat(7))\n\t\n\tif (astat(1) /= 0 .or. astat(2) /= 0 .or. astat(3) /= 0 .or. astat(4) /=0 &\n\t\t.or. astat(5) /= 0 .or. astat(6) /=0 .or. astat(7) /=0 ) then\n\t\tprint*, \"ERROR ---- SHReturnTapers\"\n\t\tprint*, \"Problem allocating memory for temporary arrays\", astat\n\t\tstop\n\tendif\n\t\n\tpi = acos(-1.0d0)\n\t\n\ttapers = 0.0d0\n\ttapers_unordered = 0.0d0\n\teigenvalues = 0.0d0\n\teval_unordered = 0.0d0\n\tm_unordered = 0\n\ttaper_order = 0\n\t\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t!\n\t!\tCalculate eigenfunctions of the Grunbaum et al. kernel.\n\t!\t\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t\n\tnt = 0\n\t\n\tdo m=0, lmax\n\t\t\n\t\tn = lmax + 1 - m\n\t\t\n\t\tcall ComputeDG82(dllmtri(1:n,1:n), lmax, m, theta0)\n\t\tcall EigValVecSymTri(dllmtri(1:n, 1:n), n, eval(1:n), evec(1:n,1:n))\n\t\t\n\t\ttapers_unordered(m+1:lmax+1, nt+1:nt+n) = evec(1:n,1:n)\n\t\tm_unordered(nt+1:nt+n) = m\n\t\t\n\t\tnt = nt + n\n\tenddo\n\t\t\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t!\n\t!\tCalculate true eigenvalues\n\t!\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t\n\tupper = 1.0d0\n\tlower = cos(theta0)\n\tn_int = lmax+1\n\t\n\tcall PreGLQ(lower, upper, n_int, zero, w)\n\t\n\tdo i=1, n_int\n\t\n\t\tcall PlmBar(p, lmax, zero(i))\n\t\t\n\t\tdo j=1, nt\n\t\t\n\t\t\th = 0.0d0\n\t\t\t\n\t\t\tdo l=m_unordered(j), lmax\n\t\t\t\th = h + p(PlmIndex(l, m_unordered(j))) * tapers_unordered(l+1, j)\n\t\t\tenddo\n\t\t\t\n\t\t\teval_unordered(j) = eval_unordered(j) + w(i) * h**2\n\t\tenddo\n\tenddo\n\t\n\tdo j=1, nt\n\t\tif (m_unordered(j) == 0) then\n\t\t\teval_unordered(j) = eval_unordered(j) / 2.0d0\n\t\telse\n\t\t\teval_unordered(j) = eval_unordered(j) / 4.0d0\n\t\tendif\n\tenddo\n\t\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t!\n\t!\tReorder tapers and eigenvalues\n\t!\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t\n\tnt2 = 0\n\t\n\tdo i=1, nt\n\t\n\t\tjj = maxloc(eval_unordered(1:nt))\n\t\tj = jj(1)\n\t\t\n\t\tif (m_unordered(j) == 0) then\n\t\t\tnt2 = nt2 + 1\n\t\t\ttaper_order(nt2) = m_unordered(j)\n\t\t\teigenvalues(nt2) = eval_unordered(j)\n\t\t\ttapers(1:lmax+1,nt2) = tapers_unordered(1:lmax+1,j)\n\t\telse\n\t\t\tnt2 = nt2 + 1\n\t\t\ttaper_order(nt2) = -m_unordered(j)\n\t\t\teigenvalues(nt2) = eval_unordered(j)\n\t\t\ttapers(1:lmax+1,nt2) = tapers_unordered(1:lmax+1,j)\n\t\t\tnt2 = nt2 + 1\n\t\t\ttaper_order(nt2) = m_unordered(j)\n\t\t\teigenvalues(nt2) = eval_unordered(j)\n\t\t\ttapers(1:lmax+1,nt2) = tapers_unordered(1:lmax+1,j)\n\t\tendif\n\t\t\n\t\teval_unordered(j) = -1.0d25\n\t\n\tenddo\n\t\n\tcall PlmBar(p, -1, zero(1))\n\tdeallocate(eval) ; deallocate(evec) ; deallocate(tapers_unordered)\n\tdeallocate(dllmtri) ; deallocate(eval_unordered)\n\tdeallocate(m_unordered) ; deallocate(p)\n\t\t\t\t\t\nend subroutine SHReturnTapers\n", "meta": {"hexsha": "676364ecf90a0fffecc42aee8515d368a3b54ca3", "size": 6029, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "spherical_splines/SHTOOLS/src/SHReturnTapers.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/SHReturnTapers.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/SHReturnTapers.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.6040609137, "max_line_length": 86, "alphanum_fraction": 0.6032509537, "num_tokens": 2038, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6817341961527802}} {"text": "!--------------------------------------------------------------------------------\n! Copyright (c) 2016 Peter Gr\u00fcnberg Institut, Forschungszentrum J\u00fclich, 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\n MODULE m_modcylk\n use m_juDFT\nc generates Makdonald's function K_m(x) for a given\nc order m and point x\nc Y.Mokrousov\n CONTAINS\n SUBROUTINE modcylk(\n > m,x,\n < kJ) \n \n\n implicit none\n \n integer, intent (in) :: m\n real, intent (in) :: x\n real, intent (out) :: kJ\n \n real, parameter :: zero = 0.0\n real, parameter :: gamma = \n = 0.5772156649015328608\n \n integer :: mm,i,mass,fact,j,m1\n real :: quot,t,k0,k1,kJ1,kJ2,psi,a\nc real, allocatable :: aux(:)\n \n \n if (x.le.zero) CALL juDFT_error(\"x.le.zero\",calledby=\"modcylk\")\n\nc K_0 and K_1 part\n \n if (x.gt.1.0) then\n t = 1./x\n k0 = exp(-x)*sqrt(t)*(1.2533141373 -\n - 0.1566641816*t + 0.0881112782*(t**2) -\n - 0.0913909546*(t**3) + 0.1344569228*(t**4) -\n - 0.2299850328*(t**5) + 0.3792409730*(t**6) -\n - 0.5247277331*(t**7) + 0.5575368367*(t**8) -\n - 0.4262632912*(t**9) + 0.2184518096*(t**10) - \n - 0.0668097672*(t**11)+ 0.0091893830*(t**12))\n k1 = exp(-x)*sqrt(t)*(1.2533141373 +\n + 0.4699927013*t - 0.1468582957*(t**2) +\n + 0.1280426636*(t**3) - 0.1736431637*(t**4) +\n + 0.2847618149*(t**5) - 0.4594342117*(t**6) +\n + 0.6283380681*(t**7) - 0.6632295430*(t**8) +\n + 0.5050238576*(t**9) - 0.2581303765*(t**10) + \n + 0.0788000118*(t**11)- 0.0108241775*(t**12))\n end if\n if (x.le.1.0) then\n t = 1./x\n k0 = - gamma - log(x/2.)\n k1 = t\n do i = 1,8\n psi = -gamma\n fact = 1\n do j = 1,i\n psi = psi + 1./j\n fact = fact*j\n end do\n if (i.le.6) then\n k0 = k0 + ((x/2.)**(2*i))*(psi-log(x/2.))/\n / (fact*fact)\n end if\n k1 = k1 + ((x/2.)**(2*i-1))*(0.5 - i*\n * (psi - log(x/2.)))/(fact*fact)\n end do\n end if\n if (m.eq.0) then\n kJ = k0\n return\n end if\n if (m.eq.1 .or. m.eq.-1) then \n kJ = k1\n return\n end if\n\nc forward recursion\n\n kJ1 = k0\n kJ2 = k1\n m1 = int(abs(m))\n do mm = 2,m1\n a = kJ2\n kJ2 = 2*(mm-1)*t*kJ2 + kJ1\n kJ1 = a\n end do\n kJ = kJ2\n \n END SUBROUTINE modcylk\n END MODULE m_modcylk\n", "meta": {"hexsha": "b7c5a2b12a2f2a18faedf4d6433001c02da69ca6", "size": 2980, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "vgen/modcylk.f", "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": "vgen/modcylk.f", "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": "vgen/modcylk.f", "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": 31.0416666667, "max_line_length": 81, "alphanum_fraction": 0.416442953, "num_tokens": 1047, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513703624558, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6817341898291162}} {"text": "\nmodule problem\n\n ! Specify the function f defining the problem to be solved, \n ! and the true solution for checking the answers.\n\n ! These functions must be consistent: the second derivative of\n ! u_true should equal -f(x).\n\n\ncontains\n\n real(kind=8) function f(x)\n ! right hand side\n implicit none\n real(kind=8), intent(in) :: x\n f = 100.d0 * exp(x)\n end function f\n\n real(kind=8) function u_true(x)\n ! true solution\n implicit none\n real(kind=8), intent(in) :: x\n u_true = (100.d0*exp(1.d0) - 60.d0)*x + 120 - 100.d0*exp(x)\n end function u_true\n\n\nend module problem\n", "meta": {"hexsha": "f5a945dd6d9f27df77071550307791889774392f", "size": 647, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/homeworks/project/part1/problem.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/homeworks/project/part1/problem.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/homeworks/project/part1/problem.f90", "max_forks_repo_name": "philipwangdk/HPC", "max_forks_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.3103448276, "max_line_length": 67, "alphanum_fraction": 0.6089644513, "num_tokens": 178, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8962513675912913, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6817341877212281}} {"text": "c\nc\nc =====================================================\n double precision function philim(a,b,meth)\nc =====================================================\n implicit none\n\n double precision a,b\n integer meth\n\n double precision r, c\nc\nc # Compute a limiter based on wave strengths a and b.\nc # meth determines what limiter is used.\nc # a is assumed to be nonzero.\nc\n r = b/a\n goto (10, 20, 30, 40) meth\n\n\n 10 continue\nc --------\nc # minmod\nc --------\n philim = dmax1(0.d0, dmin1(1.d0, r))\n return\nc\n 20 continue\nc ----------\nc # superbee\nc ----------\n philim = dmax1(0.d0, dmin1(1.d0, 2.d0*r), dmin1(2.d0, r))\n return\nc\n 30 continue\nc ----------\nc # van Leer\nc ----------\n philim = (r + dabs(r)) / (1.d0 + dabs(r))\n return\nc\n 40 continue\nc ------------------------------\nc # monotinized centered\nc ------------------------------\n c = (1.d0 + r)/2.d0\n philim = dmax1(0.d0, dmin1(c, 2.d0, 2.d0*r))\n\n return\n end\n", "meta": {"hexsha": "0a2738aa8a3206f1e2ad21b2e888f46b2b048a1d", "size": 1074, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran_source2d/philim.f", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2017-09-26T13:39:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:56:23.000Z", "max_issues_repo_path": "src/fortran_source2d/philim.f", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 75, "max_issues_repo_issues_event_min_datetime": "2017-08-02T19:56:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T12:36:32.000Z", "max_forks_repo_path": "src/fortran_source2d/philim.f", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-02-21T00:10:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T19:08:36.000Z", "avg_line_length": 21.0588235294, "max_line_length": 63, "alphanum_fraction": 0.4162011173, "num_tokens": 320, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513648201267, "lm_q2_score": 0.7606506418255927, "lm_q1q2_score": 0.6817341758874929}} {"text": " SUBROUTINE lpbut3p( corner, sample, number, data )\n! lpbut3p is a recursive three-pole Butterworth low-pass filter.\n! Taken from Gold and Rader, \"Digital Processing of Signals\", pg57\n!\n! ARGUMENTS:\n! corner - the corner frequency in hertz\n! sample - the sampling frequency in hertz\n! number - the number of data points in the time series\n! data - the input and output data array\n!\n! Variables:\n! delay - unfiltered data for the previous point\n! twc - corner / sample\n!\n REAL data(111)\n\n twc = corner / sample\n expon = EXP(-twc)\n expon2 = EXP(-twc / 2. )\n term = twc * SQRT(3.) / 2.\n beta = 2. * expon2 * COS(term)\n eta = expon2 * (COS(term) + SIN(term) / SQRT(3.))\n delay = data(2)\n delayd = 0.\n delay1 = 0.\n delay2 = 0.\n\n DO 510 i = 3, number\n out1 = twc * data(i) + expon * delay\n out2 = twc * (eta*delayd-data(i)) + beta*delay1 - expon*delay2\n delayd = data(i)\n delay = out1\n delay2 = delay1\n delay1 = out2\n data(i) = -(out1 + out2)\n 510 CONTINUE\n\n RETURN\n END\n", "meta": {"hexsha": "82d2d41391984c0a9fd451ccd5ad55140e5951a7", "size": 1118, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "lpbut3p.f", "max_stars_repo_name": "henkart/sioseis-2020.5.0", "max_stars_repo_head_hexsha": "1c7e606b5a3a615abf3cdd6687115f8a4117e855", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lpbut3p.f", "max_issues_repo_name": "henkart/sioseis-2020.5.0", "max_issues_repo_head_hexsha": "1c7e606b5a3a615abf3cdd6687115f8a4117e855", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lpbut3p.f", "max_forks_repo_name": "henkart/sioseis-2020.5.0", "max_forks_repo_head_hexsha": "1c7e606b5a3a615abf3cdd6687115f8a4117e855", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.95, "max_line_length": 71, "alphanum_fraction": 0.5733452594, "num_tokens": 359, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765328159726, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6817296933088643}} {"text": "c=======================================================================\nc\nc subroutine ALLOCVAR \nc\nc Asset allocation s.t. maximum Value-at-Risk (upper bound) constraint\nc\nc Max[ rho*w]\nc s.t. \nc VaR(w) <= VaRmax (Value-at-Risk constraint)\nc C*w <= b (linear constraints) \nc Cinf <= w <= Csup (lower/upper bounds)\nc\nc w : portfolio weights \nc Q : covariance matrix \nc rho : assets performance \nc VaRmax : VaR upper bound \nc\nc-----------------------------------------------------------------------\n SUBROUTINE allocvar ( n, cov, rho,\n & neq, nin, ccst, bcst, cinf, csup,\n & vrimax, conflp, maxdic, epsdic,\n & iwork, dwork,\n & wopt, vriopt, info )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : portfolio size integer\nc cov : covariance matrix (n*n) double\nc rho : mean returns (n) double\nc neq : number of equality constraints integer\nc nin : number of inequality constraints integer\nc ccst : constraints matrix (n*(neq + nin)) double\nc bcst : constraints vector (neq + nin) double\nc cinf : lower bound (n) double\nc csup : upper bound (n) double\nc vrimax : Value-at-Risk constraint double\nc conflp : confidence level parameter ( 01)READ(10,*)etype\n READ(10,*)x_coords,y_coords\n READ(10,*)dtim,nstep,theta,npri,nres,ntime\n CALL sample(element,points,weights)\n globma=zero\n gc=one\n !---------create and store element and global lumped mass matrices--------\n elements_1: DO iel=1,nels\n CALL geom_rect(element,iel,x_coords,y_coords,coord,num,dir)\n kay=zero\n DO i=1,ndim\n kay(i,i)=prop(i,etype(iel))\n END DO\n g_num(:,iel)=num\n g_coord(:,num)=TRANSPOSE(coord)\n kc=zero\n mm=zero\n gauss_pts: DO i=1,nip\n CALL shape_der(der,points,i)\n CALL shape_fun(fun,points,i)\n jac=MATMUL(der,coord)\n det=determinant(jac)\n CALL invert(jac)\n deriv=MATMUL(jac,der)\n if(type_2d=='axisymmetric')gc=MATMUL(fun,coord)\n kc=kc+MATMUL(MATMUL(TRANSPOSE(deriv),kay),deriv)*det*weights(i)*gc(1)\n CALL cross_product(fun,fun,ntn)\n mm=mm+ntn*det*weights(i)*gc(1)\n END DO gauss_pts\n store_kc(:,:,iel)=kc\n DO i=1,nod\n globma(num(i))=globma(num(i))+SUM(mm(i,:))\n END DO\n END DO elements_1\n CALL mesh(g_coord,g_num,argv,nlen,12)\n!-----------------------recover element a and b matrices------------------\n elements_2: DO iel=1,nels\n num=g_num(:,iel)\n kc=-store_kc(:,:,iel)*(one-theta)*dtim*pt5\n mm=store_kc(:,:,iel)*theta*dtim*pt5\n DO i=1,nod\n mm(i,i)=mm(i,i)+globma(num(i))\n kc(i,i)=kc(i,i)+globma(num(i))\n END DO\n CALL invert(mm)\n mm=MATMUL(mm,kc)\n store_kc(:,:,iel)=mm\n END DO elements_2\n!-----------------------specify initial and boundary values---------------\n READ(10,*)loads(1:)\n loads(0)=zero\n READ(10,*)fixed_freedoms\n IF(fixed_freedoms/=0)THEN\n ALLOCATE(node(fixed_freedoms),value(fixed_freedoms))\n READ(10,*)(node(i),value(i),i=1,fixed_freedoms)\n END IF\n!-----------------------time stepping loop--------------------------------\n WRITE(11,'(/a,i3,a)')\" Time Pressure (node\",nres,\")\"\n WRITE(11,'(2e12.4)')0.0,loads(nres)\n timesteps: DO j=1,nstep\n time=j*dtim\n!-----------------------first pass (1 to nels)----------------------------\n elements_3: DO iel=1,nels\n num=g_num(:,iel)\n mm=store_kc(:,:,iel)\n loads(num)=MATMUL(mm,loads(num))\n loads(0)=zero\n loads(node)=value\n END DO elements_3\n!-----------------------second pass (nels to 1)---------------------------\n elements_4: DO iel=nels,1,-1\n num=g_num(:,iel)\n mm=store_kc(:,:,iel)\n loads(num)=MATMUL(mm,loads(num))\n loads(0)=zero\n loads(node)=value\n END DO elements_4\n IF(nod==4.AND.j==ntime)THEN\n READ(10,*)nci\n CALL contour(loads,g_coord,g_num,nci,argv,nlen,13)\n END IF\n IF(j/npri*npri==j)WRITE(11,'(2e12.4)')time,loads(nres)\n END DO timesteps\n\nEND SUBROUTINE p87\n", "meta": {"hexsha": "53e56714ad2f5297842b1cf9f7d6504f8105b444", "size": 4583, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "subordinates/Transient-Problems/p87.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": "subordinates/Transient-Problems/p87.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": "subordinates/Transient-Problems/p87.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": 36.9596774194, "max_line_length": 75, "alphanum_fraction": 0.5852061968, "num_tokens": 1501, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765210631689, "lm_q2_score": 0.7461389873857264, "lm_q1q2_score": 0.6817296742241861}} {"text": " REAL FUNCTION VECL (VX,VY,VZ)\n\nC This function returns the length of a 3D vector.\n\n REAL VX,VY,VZ, VECL2\n\n VECL = SQRT (VECL2 (VX,VY,VZ) )\n\n END\n", "meta": {"hexsha": "a4b5f453e53e1625504009b927b7ac0f74f51ec2", "size": 168, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "third_party/Phigs/PVT/PVT_fort/V2LIB/vecl.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/vecl.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/vecl.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": 16.8, "max_line_length": 51, "alphanum_fraction": 0.5892857143, "num_tokens": 62, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9173026573249612, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6817099943570663}} {"text": "module constants_mod\n implicit none\n save\n\n real*8, parameter :: pi = 4.*atan(1.)\n real*8, parameter:: twopi=2.*pi\n real*8, parameter:: fourpi=4.*pi\n\n real*8, parameter :: h=6.626D-34 !Planck\n real*8, parameter :: c=3.D+8 !Speed of light\n real*8, parameter :: Na=6.022D+23 !Avogadro\n\nend module constants_mod\n", "meta": {"hexsha": "fb9da1d2d4004b780d86169eefdf4e0500ca2ee2", "size": 323, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uvc/constants.f90", "max_stars_repo_name": "i-brnrd/code_underpinning_PhD_thesis", "max_stars_repo_head_hexsha": "b3b66f05b5a66246c449340d8d154b13003a95e6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "uvc/constants.f90", "max_issues_repo_name": "i-brnrd/code_underpinning_PhD_thesis", "max_issues_repo_head_hexsha": "b3b66f05b5a66246c449340d8d154b13003a95e6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "uvc/constants.f90", "max_forks_repo_name": "i-brnrd/code_underpinning_PhD_thesis", "max_forks_repo_head_hexsha": "b3b66f05b5a66246c449340d8d154b13003a95e6", "max_forks_repo_licenses": ["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.0714285714, "max_line_length": 51, "alphanum_fraction": 0.6594427245, "num_tokens": 119, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9099070158103778, "lm_q2_score": 0.7490872243177518, "lm_q1q2_score": 0.6815997208606446}} {"text": "Subroutine RanGauss (Gau)\n\n Use cte\n Implicit None\n\n Real :: Ran1, Ran2, Gau\n\n\n1 Call Random_Number (Ran1)\n Call Random_Number (Ran2)\n\n ! Condicion para evitar que el logaritmo diverja\n\n If (Ran1 .LE. 1E-8) Then\n\n Go To 1\n\n End If\n\n ! Aqui se generan los numeros aleatorios con distribucion Gaussiana\n\n Gau = sqrt(-2.0 * Log(Ran1) ) * Cos(2.0 * Pi * Ran2)\n\n\nEnd Subroutine RanGauss\n", "meta": {"hexsha": "d7fa8c37fd2f942b160caac5de001ef195e0f762", "size": 396, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "P_DB/RGAUSS.f03", "max_stars_repo_name": "maps16/DesExpII", "max_stars_repo_head_hexsha": "d9d12b445e0fe86e32fce028be4f5b8bcfd2391f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "P_DB/RGAUSS.f03", "max_issues_repo_name": "maps16/DesExpII", "max_issues_repo_head_hexsha": "d9d12b445e0fe86e32fce028be4f5b8bcfd2391f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "P_DB/RGAUSS.f03", "max_forks_repo_name": "maps16/DesExpII", "max_forks_repo_head_hexsha": "d9d12b445e0fe86e32fce028be4f5b8bcfd2391f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.2307692308, "max_line_length": 69, "alphanum_fraction": 0.6742424242, "num_tokens": 144, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.7490872243177518, "lm_q1q2_score": 0.6815997172004811}} {"text": "program harmonics\n use constants\n use io\n use samples\n use spectra\n implicit none\n\n integer :: n\n integer, parameter :: nmax = 100\n\n real(dp) :: wave(2 * nmax), amplitude, phase\n complex(dp) :: spectrum(nmax)\n\n call sample(wave, 'wave', command_argument(1, 'circular'))\n\n call fourier(wave, spectrum)\n\n write (*, \"(/ 'f(t) = sum r[n] cos(n omega t - phi[n])' /)\")\n write (*, '(A2, 2A15)') 'n', 'r[n]', 'phi[n]'\n\n do n = 1, size(spectrum)\n amplitude = 2 * abs(spectrum(n))\n\n if (amplitude .lt. 1e-10_dp) cycle\n\n phase = atan2(aimag(spectrum(n)), real(spectrum(n)))\n\n write (*, '(I2, 2F15.10)') n, amplitude, phase\n end do\nend program harmonics\n", "meta": {"hexsha": "75299fc30e58058c38e3c2610ee045120d2f188f", "size": 693, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/harmonics.f90", "max_stars_repo_name": "janberges/Tonbandfetzen", "max_stars_repo_head_hexsha": "f64a7761e924001b938e1c97cb894d6b7701c925", "max_stars_repo_licenses": ["0BSD"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/harmonics.f90", "max_issues_repo_name": "janberges/Tonbandfetzen", "max_issues_repo_head_hexsha": "f64a7761e924001b938e1c97cb894d6b7701c925", "max_issues_repo_licenses": ["0BSD"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/harmonics.f90", "max_forks_repo_name": "janberges/Tonbandfetzen", "max_forks_repo_head_hexsha": "f64a7761e924001b938e1c97cb894d6b7701c925", "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": 22.3548387097, "max_line_length": 63, "alphanum_fraction": 0.5887445887, "num_tokens": 231, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070158103777, "lm_q2_score": 0.7490872187162397, "lm_q1q2_score": 0.6815997157637894}} {"text": " subroutine realtr(a,b,n,isn)\nc if isn=1, this subroutine completes the fourier transform\nc of 2*n real data values, where the original data values are\nc stored alternately in arrays a and b, and are first\nc transformed by a complex fourier transform of dimension n.\nc the cosine coefficients are in a(1),a(2),...,a(n+1) and\nc the sine coefficients are in b(1),b(2),...,b(n+1).\nc a typical calling sequence is\nc call fft(a,b,n,n,n,1)\nc call realtr(a,b,n,1)\nc the results should be multiplied by 1.0/(2.0*n) to give the\nc usual scaling of coefficients.\nc if isn=-1, the inverse transformation is done, the first step\nc in evaluating a real fourier series.\nc a typical calling sequence is\nc call realtr(a,b,n,-1)\nc call fft(a,b,n,n,n,-1)\nc the results should be multiplied by 0.5 to give the usual\nc scaling, and the time domain results alternate in arrays a\nc and b, i.e. a(1),b(1),a(2),b(2),...,a(n),b(n).\nc with most fortran compilers the data can alternatively be\nc stored in a single complex array a, then the magnitude of isn\nc changed to two to give the correct indexing increment and a(2)\nc used to pass the initial address for the sequence of imaginary\nc values, e.g.\nc call fft(a,a(2),n,n,n,2)\nc call realtr(a,a(2),n,2)\nc in this case, the cosine and sine coefficients alternate in a.\nc by r. c. singleton, stanford research institute, sept. 1968\n dimension a(1),b(1)\n real im\n inc=iabs(isn)\n nk=n*inc+2\n nh=nk/2\n sd=2.0*atan(1.0)/float(n)\n cd=2.0*sin(sd)**2\n sd=sin(sd+sd)\n sn=0.0\n if(isn .lt. 0) go to 30\n cn=1.0\n a(nk-1)=a(1)\n b(nk-1)=b(1)\n 10 do 20 j=1,nh,inc\n k=nk-j\n aa=a(j)+a(k)\n ab=a(j)-a(k)\n ba=b(j)+b(k)\n bb=b(j)-b(k)\n re=cn*ba+sn*ab\n im=sn*ba-cn*ab\n b(k)=im-bb\n b(j)=im+bb\n a(k)=aa-re\n a(j)=aa+re\n aa=cn-(cd*cn+sd*sn)\n sn=(sd*cn-cd*sn)+sn\n cn=2.0-(aa**2+sn**2)\n sn=cn*sn\n 20 cn=cn*aa\n return\n 30 cn=-1.0\n sd=-sd\n go to 10\n end\n", "meta": {"hexsha": "25c93b4b424e0e2c4041ac98b7788db7ac132018", "size": 2105, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "benchees/singleton/realtr.f", "max_stars_repo_name": "mreineck/benchfft", "max_stars_repo_head_hexsha": "6c754dca9f53f16886a71744199a0bbce40b3e1a", "max_stars_repo_licenses": ["ImageMagick"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2019-08-11T02:13:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T01:31:41.000Z", "max_issues_repo_path": "benchees/singleton/realtr.f", "max_issues_repo_name": "mreineck/benchfft", "max_issues_repo_head_hexsha": "6c754dca9f53f16886a71744199a0bbce40b3e1a", "max_issues_repo_licenses": ["ImageMagick"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2020-12-01T18:15:43.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-21T21:39:55.000Z", "max_forks_repo_path": "benchees/singleton/realtr.f", "max_forks_repo_name": "mreineck/benchfft", "max_forks_repo_head_hexsha": "6c754dca9f53f16886a71744199a0bbce40b3e1a", "max_forks_repo_licenses": ["ImageMagick"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2020-06-02T08:44:13.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-26T11:50:36.000Z", "avg_line_length": 32.3846153846, "max_line_length": 67, "alphanum_fraction": 0.6019002375, "num_tokens": 733, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070133672955, "lm_q2_score": 0.7490872187162396, "lm_q1q2_score": 0.6815997139337077}} {"text": "module gaussmod\n!! Helper for [[vscoul_mod]]\ncontains\n \nsubroutine gauss(n,ldim,a,x,c)\n implicit none\n integer n,ldim\n real(8) a,x,c\n integer i,j,k\n real(8) swap,fact\n dimension a(ldim,ldim),x(ldim),c(ldim)\n do i=1,n\n x(i)=c(i)\n end do\n do i=1,n-1\n k=i\n do j=i+1,n\n if(abs(a(k,i)) .lt. abs(a(j,i))) k=j\n end do\n if(k .ne. i) then\n do j=i,n\n swap=a(i,j)\n a(i,j)=a(k,j)\n a(k,j)=swap\n enddo\n swap=x(i)\n x(i)=x(k)\n x(k)=swap\n end if\n do k=i+1,n\n fact=a(k,i)/a(i,i)\n do j=i+1,n\n a(k,j)=a(k,j)-fact*a(i,j)\n end do\n x(k)=x(k)-fact*x(i)\n end do\n end do\n x(n)=x(n)/a(n,n)\n do i=n-1,1,-1\n do k=i+1,n\n x(i)=x(i)-a(i,k)*x(k)\n end do\n x(i)=x(i)/a(i,i)\n end do\n return\nend subroutine\n\nend module gaussmod\n", "meta": {"hexsha": "b1a9bf98c509133b2f88a94a34f5c29dddf73ae7", "size": 907, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/nrg/gauss.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/nrg/gauss.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/nrg/gauss.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": 18.5102040816, "max_line_length": 45, "alphanum_fraction": 0.4421168688, "num_tokens": 340, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.909907010924213, "lm_q2_score": 0.7490872187162397, "lm_q1q2_score": 0.6815997121036259}} {"text": "function gaussian_kernel(a, b) result(kernel)\n\n double precision, dimension(:), intent(in) :: a\n double precision, dimension(:), intent(in) :: b\n\n double precision :: kernel\n integer :: i\n double precision :: temp\n double precision :: sigma\n \n kernel = 0.0d0 \n sigma = 724.0d0\n\n do i = 1, size(a)\n temp = a(i) - b(i)\n kernel = kernel + temp * temp\n enddo\n\n kernel = exp(-0.5d0 * sqrt(kernel) / (sigma*sigma))\n\nend function gaussian_kernel\n\n\nfunction laplace_kernel(a, b) result(kernel)\n\n double precision, dimension(:), intent(in) :: a\n double precision, dimension(:), intent(in) :: b\n\n double precision :: kernel\n\n kernel = sum(abs(a(:) - b(:)))\n kernel = exp(-0.00025118864315095795d0 * kernel)\n\nend function laplace_kernel\n\nsubroutine kgaussian_kernel(a, na, b, nb, k, sigma)\n\n double precision, dimension(:,:), intent(in) :: a\n double precision, dimension(:,:), intent(in) :: b\n\n integer, intent(in) :: na, nb\n\n double precision, dimension(:,:), intent(inout) :: k\n double precision, intent(in) :: sigma\n\n double precision, allocatable, dimension(:) :: temp\n\n double precision :: inv_sigma\n integer :: l\n\n inv_sigma = -0.5d0 / (sigma*sigma)\n\n allocate(temp(size(a, dim=1)))\n\n!$OMP PARALLEL DO PRIVATE(temp)\n do i = 1, nb \n do j = 1, na\n temp(:) = a(:,j) - b(:,i)\n K(j,i) = exp(inv_sigma * sqrt(sum(temp*temp)))\n enddo\n enddo\n!$OMP END PARALLEL DO\n\n deallocate(temp)\nend subroutine kgaussian_kernel\n\nsubroutine klaplace_kernel(a, na, b, nb, k, sigma)\n\n double precision, dimension(:,:), intent(in) :: a\n double precision, dimension(:,:), intent(in) :: b\n\n integer, intent(in) :: na, nb\n\n double precision, dimension(:,:), intent(inout) :: k\n double precision, intent(in) :: sigma\n\n double precision :: inv_sigma\n\n inv_sigma = -1.0d0 / sigma\n\n!$OMP PARALLEL DO\n do i = 1, nb \n do j = 1, na\n k(j,i) = exp(inv_sigma * sum(abs(a(:,j) - b(:,i))))\n enddo\n enddo\n!$OMP END PARALLEL DO\n\nend subroutine klaplace_kernel\n", "meta": {"hexsha": "c00b2f042bc57453845c7e6ca5d7bbb00b0dce51", "size": 2100, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fkernels.f90", "max_stars_repo_name": "andersx/dftb3-delta-machine", "max_stars_repo_head_hexsha": "6721fdda3aaf5b17b80a7477967fdcc01276dfef", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2016-10-11T20:37:05.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-11T12:45:36.000Z", "max_issues_repo_path": "fkernels.f90", "max_issues_repo_name": "andersx/dftb3-delta-machine", "max_issues_repo_head_hexsha": "6721fdda3aaf5b17b80a7477967fdcc01276dfef", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fkernels.f90", "max_forks_repo_name": "andersx/dftb3-delta-machine", "max_forks_repo_head_hexsha": "6721fdda3aaf5b17b80a7477967fdcc01276dfef", "max_forks_repo_licenses": ["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.3333333333, "max_line_length": 59, "alphanum_fraction": 0.6047619048, "num_tokens": 600, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.7490872131147276, "lm_q1q2_score": 0.6815997070067707}} {"text": "c\n\tsubroutine cart_to_pol(x_in,lat,long,radial)\n\tparameter (pi=3.1415927)\r\n\treal lat,long,radial,x_in(3),row\nc\n\trow=sqrt(x_in(1)*x_in(1)+x_in(2)*x_in(2))\n\tradial=sqrt(row*row+x_in(3)*x_in(3))\n\tlat=atan2(x_in(3),row)\n\tlong=atan2(x_in(2),x_in(1))\r\n\tlong=long + (1.0-sign(1.0,long))*pi\nc\n\treturn\n\tend\n", "meta": {"hexsha": "2fdae161ce2f484a1825744aa89fa93e936f7fbd", "size": 298, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "PyGCPM/__data/libgcpm/xform/Cart_to_pol.for", "max_stars_repo_name": "mattkjames7/PyGCPM", "max_stars_repo_head_hexsha": "90d1c29b82b7b286f570eb49f7bf7618ddc4717b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "PyGCPM/__data/libgcpm/xform/Cart_to_pol.for", "max_issues_repo_name": "mattkjames7/PyGCPM", "max_issues_repo_head_hexsha": "90d1c29b82b7b286f570eb49f7bf7618ddc4717b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "PyGCPM/__data/libgcpm/xform/Cart_to_pol.for", "max_forks_repo_name": "mattkjames7/PyGCPM", "max_forks_repo_head_hexsha": "90d1c29b82b7b286f570eb49f7bf7618ddc4717b", "max_forks_repo_licenses": ["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.2857142857, "max_line_length": 45, "alphanum_fraction": 0.6845637584, "num_tokens": 131, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9099070060380482, "lm_q2_score": 0.7490872131147276, "lm_q1q2_score": 0.6815997033466071}} {"text": "!> \\file rho.f90\n!! \\BRIEF \n!> Module with rho function - computes in situ density from S, T, P\nMODULE mrho\nCONTAINS\n!> Function to compute in situ density from salinity (psu), in situ temperature (C), & pressure (bar)\nFUNCTION rho(salt, temp, pbar)\n\n ! Compute in situ density from salinity (psu), in situ temperature (C), & pressure (bar)\n\n#if USE_PRECISION == 2\n# define SGLE(x) (x)\n#else\n# define SGLE(x) REAL(x)\n#endif\n\n USE msingledouble\n IMPLICIT NONE\n\n !> salinity [psu]\n REAL(kind=rx) :: salt\n !> in situ temperature (C)\n REAL(kind=rx) :: temp\n !> pressure (bar) [Note units: this is NOT in decibars]\n REAL(kind=rx) :: pbar\n\n REAL(kind=r8) :: s, t, p\n! REAL(kind=r8) :: t68\n REAL(kind=r8) :: X\n REAL(kind=r8) :: rhow, rho0\n REAL(kind=r8) :: a, b, c\n REAL(kind=r8) :: Ksbmw, Ksbm0, Ksbm\n REAL(kind=r8) :: drho\n\n REAL(kind=rx) :: rho\n\n ! Input arguments:\n ! -------------------------------------\n ! s = salinity [psu (PSS-78) ]\n ! t = in situ temperature [degree C (IPTS-68)]\n ! p = pressure [bar] !!!! (not in [db]\n\n s = DBLE(salt)\n t = DBLE(temp)\n p = DBLE(pbar)\n\n! Convert the temperature on today's \"ITS 90\" scale to older IPTS 68 scale\n! (see Dickson et al., Best Practices Guide, 2007, Chap. 5, p. 7, including footnote)\n! According to Best-Practices guide, line above should be commented & 2 lines below should be uncommented\n! Guide's answer of rho (s=35, t=25, p=0) = 1023.343 is for temperature given on ITPS-68 scale\n! t68 = (T - 0.0002) / 0.99975\n! X = t68\n! Finally, don't do the ITS-90 to IPTS-68 conversion (T input var now already on IPTS-68 scale)\n X = T\n\n! Density of pure water\n rhow = 999.842594d0 + 6.793952e-2_r8*X &\n -9.095290e-3_r8*X*X + 1.001685e-4_r8*X**3 &\n -1.120083e-6_r8*X**4 + 6.536332e-9_r8*X**5\n\n! Density of seawater at 1 atm, P=0\n A = 8.24493e-1_r8 - 4.0899e-3_r8*X &\n + 7.6438e-5_r8*X*X - 8.2467e-7_r8*X**3 + 5.3875e-9_r8*X**4\n B = -5.72466e-3_r8 + 1.0227e-4_r8*X - 1.6546e-6_r8*X*X\n C = 4.8314e-4_r8\n\n rho0 = rhow + A*S + B*S*SQRT(S) + C*S**2.0d0\n\n! Secant bulk modulus of pure water\n! The secant bulk modulus is the average change in pressure\n! divided by the total change in volume per unit of initial volume.\n Ksbmw = 19652.21d0 + 148.4206d0*X - 2.327105d0*X*X &\n + 1.360477e-2_r8*X**3 - 5.155288e-5_r8*X**4\n\n! Secant bulk modulus of seawater at 1 atm\n Ksbm0 = Ksbmw + S*( 54.6746d0 - 0.603459d0*X + 1.09987e-2_r8*X**2 &\n - 6.1670e-5_r8*X**3) &\n + S*SQRT(S)*( 7.944e-2_r8 + 1.6483e-2_r8*X - 5.3009e-4_r8*X**2)\n\n! Secant bulk modulus of seawater at S,T,P\n Ksbm = Ksbm0 &\n + P*(3.239908d0 + 1.43713e-3_r8*X + 1.16092e-4_r8*X**2 - 5.77905e-7_r8*X**3) &\n + P*S*(2.2838e-3_r8 - 1.0981e-5_r8*X - 1.6078e-6_r8*X**2) &\n + P*S*SQRT(S)*1.91075e-4_r8 &\n + P*P*(8.50935e-5_r8 - 6.12293e-6_r8*X + 5.2787e-8_r8*X**2) &\n + P*P*S*(-9.9348e-7_r8 + 2.0816e-8_r8*X + 9.1697e-10_r8*X**2)\n\n! Density of seawater at S,T,P\n drho = rho0/(1.0d0 - P/Ksbm)\n rho = SGLE(drho)\n\n RETURN\nEND FUNCTION rho\n\n\n!> Function to compute in situ density from salinity (psu), in situ temperature (C), & pressure (bar)\n!! and its derivatives with respect to salinity and temperature.\nFUNCTION rho_DNAD(salt, temp, pbar)\n\n ! Compute in situ density from salinity (psu), in situ temperature (C), & pressure (bar)\n !\n ! It is similar to subroutine 'rho' above except that it computes\n ! partial derivatives of in situ density\n ! with respect to salinity and temperature.\n\n USE msingledouble\n USE Dual_Num_Auto_Diff\n IMPLICIT NONE\n\n !> salinity [psu]\n TYPE (DUAL_NUM) :: salt\n !> in situ temperature (C)\n TYPE (DUAL_NUM) :: temp\n !> pressure (bar) [Note units: this is NOT in decibars]\n TYPE (DUAL_NUM) :: pbar\n\n TYPE (DUAL_NUM) :: s, p\n! REAL(kind=r8) :: t68\n TYPE (DUAL_NUM) :: X\n TYPE (DUAL_NUM) :: rhow, rho0\n TYPE (DUAL_NUM) :: a, b, c\n TYPE (DUAL_NUM) :: Ksbmw, Ksbm0, Ksbm\n \n TYPE (DUAL_NUM) :: rho_DNAD\n\n ! Input arguments:\n ! -------------------------------------\n ! s = salinity [psu (PSS-78) ]\n ! t = in situ temperature [degree C (IPTS-68)]\n ! p = pressure [bar] !!!! (not in [db]\n\n s = salt\n p = pbar\n\n! Convert the temperature on today's \"ITS 90\" scale to older IPTS 68 scale\n! (see Dickson et al., Best Practices Guide, 2007, Chap. 5, p. 7, including footnote)\n! According to Best-Practices guide, line above should be commented & 2 lines below should be uncommented\n! Guide's answer of rho (s=35, t=25, p=0) = 1023.343 is for temperature given on ITPS-68 scale\n! t68 = (T - 0.0002) / 0.99975\n! X = t68\n! Finally, don't do the ITS-90 to IPTS-68 conversion (T input var now already on IPTS-68 scale)\n X = temp\n\n! Density of pure water\n rhow = 999.842594d0 + 6.793952e-2_r8*X &\n -9.095290e-3_r8*X*X + 1.001685e-4_r8*X**3 &\n -1.120083e-6_r8*X**4 + 6.536332e-9_r8*X**5\n\n! Density of seawater at 1 atm, P=0\n A = 8.24493e-1_r8 - 4.0899e-3_r8*X &\n + 7.6438e-5_r8*X*X - 8.2467e-7_r8*X**3 + 5.3875e-9_r8*X**4\n B = -5.72466e-3_r8 + 1.0227e-4_r8*X - 1.6546e-6_r8*X*X\n C = 4.8314e-4_r8\n\n rho0 = rhow + A*S + B*S*SQRT(S) + C*S**2.0d0\n\n! Secant bulk modulus of pure water\n! The secant bulk modulus is the average change in pressure\n! divided by the total change in volume per unit of initial volume.\n Ksbmw = 19652.21d0 + 148.4206d0*X - 2.327105d0*X*X &\n + 1.360477e-2_r8*X**3 - 5.155288e-5_r8*X**4\n\n! Secant bulk modulus of seawater at 1 atm\n Ksbm0 = Ksbmw + S*( 54.6746d0 - 0.603459d0*X + 1.09987e-2_r8*X**2 &\n - 6.1670e-5_r8*X**3) &\n + S*SQRT(S)*( 7.944e-2_r8 + 1.6483e-2_r8*X - 5.3009e-4_r8*X**2)\n\n! Secant bulk modulus of seawater at S,T,P\n Ksbm = Ksbm0 &\n + P*(3.239908d0 + 1.43713e-3_r8*X + 1.16092e-4_r8*X**2 - 5.77905e-7_r8*X**3) &\n + P*S*(2.2838e-3_r8 - 1.0981e-5_r8*X - 1.6078e-6_r8*X**2) &\n + P*S*SQRT(S)*1.91075e-4_r8 &\n + P*P*(8.50935e-5_r8 - 6.12293e-6_r8*X + 5.2787e-8_r8*X**2) &\n + P*P*S*(-9.9348e-7_r8 + 2.0816e-8_r8*X + 9.1697e-10_r8*X**2)\n\n! Density of seawater at S,T,P\n rho_DNAD = rho0/(1.0d0 - P/Ksbm)\n\n RETURN\nEND FUNCTION rho_DNAD\nEND MODULE mrho\n", "meta": {"hexsha": "072787d388fc54c7d1a1da4fa8990f3a8280caf4", "size": 6262, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/rho.f90", "max_stars_repo_name": "tomaslovato/mocsy", "max_stars_repo_head_hexsha": "ede19cde4be5cd37ed192a3f3394e81302d11616", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2017-06-20T13:08:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-04T09:51:49.000Z", "max_issues_repo_path": "src/rho.f90", "max_issues_repo_name": "tomaslovato/mocsy", "max_issues_repo_head_hexsha": "ede19cde4be5cd37ed192a3f3394e81302d11616", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-11-12T19:46:14.000Z", "max_issues_repo_issues_event_max_datetime": "2020-01-23T14:57:14.000Z", "max_forks_repo_path": "src/rho.f90", "max_forks_repo_name": "tomaslovato/mocsy", "max_forks_repo_head_hexsha": "ede19cde4be5cd37ed192a3f3394e81302d11616", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2015-11-01T01:06:21.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-04T12:58:24.000Z", "avg_line_length": 34.4065934066, "max_line_length": 105, "alphanum_fraction": 0.6108272118, "num_tokens": 2584, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070035949657, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6815997015165252}} {"text": "SUBROUTINE p54(input_file,output_file) \n!-------------------------------------------------------------------------\n! Program 5.4 General two- (plane strain) or three-dimensional analysis\n! of elastic solids (optional gravity loading).\n!-------------------------------------------------------------------------\n USE main \n USE geom \n IMPLICIT NONE\n CHARACTER(len=70),INTENT(IN) :: input_file\n CHARACTER(len=70),INTENT(OUT) :: output_file\n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\n INTEGER::fixed_freedoms,i,iel,k,loaded_nodes,ndim,ndof,nels,neq,nip,nlen,&\n nn,nod,nodof,nprops=3,np_types,nr,nst \n REAL(iwp)::det,penalty=1.0e20_iwp,zero=0.0_iwp\n CHARACTER(len=15)::argv,element\n!-----------------------dynamic arrays------------------------------------\n INTEGER,ALLOCATABLE::etype(:),g(:),g_g(:,:),g_num(:,:),kdiag(:),nf(:,:), &\n no(:),node(:),num(:),sense(:) \n REAL(iwp),ALLOCATABLE::bee(:,:),coord(:,:),dee(:,:),der(:,:),deriv(:,:), &\n eld(:),fun(:),gc(:),gravlo(:),g_coord(:,:),jac(:,:),km(:,:),kv(:), &\n loads(:),points(:,:),prop(:,:),sigma(:),value(:),weights(:) \n!-----------------------input and initialisation--------------------------\n\n OPEN(10,FILE=input_file) \n OPEN(11,FILE=output_file)\n READ(10,*)element,nod,nels,nn,nip,nodof,nst,ndim,np_types \n ndof=nod*nodof\n ALLOCATE(nf(nodof,nn),points(nip,ndim),dee(nst,nst),g_coord(ndim,nn), &\n coord(nod,ndim),jac(ndim,ndim),weights(nip),num(nod),g_num(nod,nels), &\n der(ndim,nod),deriv(ndim,nod),bee(nst,ndof),km(ndof,ndof),eld(ndof), &\n sigma(nst),g(ndof),g_g(ndof,nels),gc(ndim),fun(nod),etype(nels), &\n prop(nprops,np_types))\n READ(10,*)prop \n etype=1 \n IF(np_types>1)READ(10,*)etype\n READ(10,*)g_coord \n READ(10,*)g_num\n IF(ndim==2)CALL mesh(g_coord,g_num,argv,nlen,12)\n nf=1 \n READ(10,*)nr,(k,nf(:,k),i=1,nr) \n CALL formnf(nf) \n neq=MAXVAL(nf) \n ALLOCATE(kdiag(neq),loads(0:neq),gravlo(0:neq)) \n kdiag=0\n!-----------------------loop the elements to find global arrays sizes-----\n elements_1: DO iel=1,nels\n num=g_num(:,iel) \n CALL num_to_g(num,nf,g) \n g_g(:,iel)=g\n CALL fkdiag(kdiag,g)\n END DO elements_1\n DO i=2,neq \n kdiag(i)=kdiag(i)+kdiag(i-1) \n END DO \n ALLOCATE(kv(kdiag(neq)))\n WRITE(11,'(2(A,I5))') &\n \" There are\",neq,\" equations and the skyline storage is\",kdiag(neq)\n!-----------------------element stiffness integration and assembly--------\n CALL sample(element,points,weights) \n kv=zero \n gravlo=zero\n elements_2: DO iel=1,nels\n CALL deemat(dee,prop(1,etype(iel)),prop(2,etype(iel))) \n num=g_num(:,iel)\n coord=TRANSPOSE(g_coord(:,num)) \n g=g_g(:,iel) \n km=zero \n eld=zero\n int_pts_1: DO i=1,nip\n CALL shape_fun(fun,points,i) \n CALL shape_der(der,points,i)\n jac=MATMUL(der,coord) \n det=determinant(jac) \n CALL invert(jac)\n deriv=MATMUL(jac,der) \n CALL beemat(bee,deriv)\n km=km+MATMUL(MATMUL(transpose(bee),dee),bee)*det*weights(i)\n eld(nodof:ndof:nodof)=eld(nodof:ndof:nodof)+fun(:)*det*weights(i)\n END DO int_pts_1\n CALL fsparv(kv,km,g,kdiag) \n gravlo(g)=gravlo(g)-eld*prop(3,etype(iel))\n END DO elements_2\n loads=zero \n READ(10,*)loaded_nodes,(k,loads(nf(:,k)),i=1,loaded_nodes)\n loads=loads+gravlo \n READ(10,*)fixed_freedoms\n IF(fixed_freedoms/=0)THEN\n ALLOCATE(node(fixed_freedoms),sense(fixed_freedoms), &\n value(fixed_freedoms),no(fixed_freedoms))\n READ(10,*)(node(i),sense(i),value(i),i=1,fixed_freedoms)\n DO i=1,fixed_freedoms \n no(i)=nf(sense(i),node(i)) \n END DO \n kv(kdiag(no))=kv(kdiag(no))+penalty \n loads(no)=kv(kdiag(no))*value\n END IF\n!-----------------------equation solution---------------------------------\n CALL sparin(kv,kdiag) \n CALL spabac(kv,loads,kdiag) \n loads(0)=zero\n IF(ndim==3)THEN \n WRITE(11,'(/A)')\" Node x-disp y-disp z-disp\"\n ELSE \n WRITE(11,'(/A)')\" Node x-disp y-disp\"\n END IF\n DO k=1,nn \n WRITE(11,'(I5,3E12.4)')k,loads(nf(:,k)) \n END DO\n!-----------------------recover stresses at element Gauss-points----------\n!nip=1 \n!DEALLOCATE(points,weights) \n!ALLOCATE(points(nip,ndim),weights(nip))\n!CALL sample(element,points,weights)\n WRITE(11,'(/A,I2,A)')\" The integration point (nip=\",nip,\") stresses are:\"\n IF(ndim==3)THEN \n WRITE(11,'(A,/,A)')\" Element x-coord y-coord z-coord\", &\n \" sig_x sig_y sig_z tau_xy tau_yz tau_zx\" \n ELSE \n WRITE(11,'(A,A)') \" Element x-coord y-coord\", &\n \" sig_x sig_y tau_xy\" \n END IF\n elements_3: DO iel=1,nels\n CALL deemat(dee,prop(1,etype(iel)),prop(2,etype(iel))) \n num=g_num(:,iel)\n coord=TRANSPOSE(g_coord(:,num)) \n g=g_g(:,iel) \n eld=loads(g)\n int_pts_2: DO i=1,nip\n CALL shape_der(der,points,i) \n CALL shape_fun(fun,points,i)\n gc=MATMUL(fun,coord) \n jac=MATMUL(der,coord) \n CALL invert(jac)\n deriv=MATMUL(jac,der) \n CALL beemat(bee,deriv)\n sigma=MATMUL(dee,MATMUL(bee,eld))\n IF(ndim==3)THEN \n WRITE(11,'(I8,4X,3E12.4)')iel,gc\n WRITE(11,'(6E12.4)')sigma\n ELSE \n WRITE(11,'(I8,2E12.4,5X,3E12.4)')iel,gc,sigma\n END IF\n END DO int_pts_2\n END DO elements_3\n IF(ndim==2)THEN \n CALL dismsh(loads,nf,0.05_iwp,g_coord,g_num,argv,nlen,13)\n CALL vecmsh(loads,nf,0.05_iwp,0.1_iwp,g_coord,g_num,argv,nlen,14)\n END IF\n\nEND SUBROUTINE p54\n", "meta": {"hexsha": "4ccaeaf1c7ab4512dfc1c06e9482c681f0f25c11", "size": 5390, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "subordinates/Static-Equilibrium-Linear-Elastic-Solids/p54.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": "subordinates/Static-Equilibrium-Linear-Elastic-Solids/p54.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": "subordinates/Static-Equilibrium-Linear-Elastic-Solids/p54.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": 35.6953642384, "max_line_length": 76, "alphanum_fraction": 0.5844155844, "num_tokens": 1859, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070035949656, "lm_q2_score": 0.7490872075132152, "lm_q1q2_score": 0.6815996964196699}} {"text": "C TMWN JULY 94\nC Savitsky Golay smoothing subroutines.\nC Taken from \"Numerical Recipes\" by Flannery and Press.\nC Stored here in a separate file to assist debugging.\n\n SUBROUTINE savgol(c,np,nl,nr,ld,m)\nC Savitsky Golay smoothing.\nC Taken from Numerical Recipes, Flannery and Press.\nC Calculates coefficients for linear smoothing,\nC such that higher moments are preserved.\nC Re. correlation function analysis, smoothing used\nC to ease the join between calc. and expt. data.\n INTEGER ld,m,nl,np,nr,mmax\n REAL c(np)\n PARAMETER (mmax=6)\n INTEGER imj,ipj,j,k,kk,mm,indx(mmax+1)\n REAL d,fac,sum,a(mmax+1,mmax+1),b(mmax+1)\n\n \n IF (np.LT.nl+nr+1.OR.nl.LT.0.OR.nr.LT.0.OR.ld.GT.m.OR.m.GT.mmax\n +.OR.nl+nr.LT.m) PAUSE 'Bad arguments passed to subroutine savgol'\n\n DO ipj=0,2*m\n sum=0.\n IF (ipj .EQ. 0) sum=1.\n\n DO k=1,nr\n sum=sum+FLOAT(k)**ipj\n END DO\n\n DO k=1,nl\n sum=sum+FLOAT(-k)**ipj\n END DO\n\n mm=MIN(ipj,2*m-ipj)\n DO imj=-mm,mm,2\n a(1+(ipj+imj)/2,1+(ipj-imj)/2)=sum\n END DO\n END DO\n\n CALL ludcmp(a,m+1,mmax+1,indx,d)\n\n DO j=1,m+1\n b(j)=0.\n END DO\n b(ld+1)=1\n\n CALL lubksb(a,m+1,mmax+1,indx,b)\n\n DO kk=1,np\n c(kk)=0.\n END DO\n\n DO k=-nl,nr\n sum=b(1)\n fac=1.\n DO mm=1,m\n fac=fac*k\n sum=sum+b(mm+1)*fac\n END DO\n kk=MOD(np-k,np)+1\n c(kk)=sum\n END DO\n\n RETURN\n END\n\n\n\n SUBROUTINE ludcmp(a,n,np,indx,d)\nC LU decomposition.\nC Taken from Numerical Recipes, Flannery and Press.\nC Used by subroutine savgol.\n INTEGER n,np,indx(n),nmax\n REAL d,a(np,np),tiny\n PARAMETER (nmax=500,tiny=1.E-8)\n INTEGER i,imax,j,k \n REAL aamax,dum,sum,vv(nmax)\n\n d=1.\n DO i=1,n\n aamax=0.\n DO j=1,n\n IF (ABS(a(i,j)) .GT. aamax) aamax=ABS(a(i,j))\n END DO\n IF (aamax .EQ. 0.) PAUSE 'Singular matrix in subroutine ludcmp'\n vv(i)=1./aamax\n END DO\n \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 aamax=0.\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 .GE. aamax) THEN\n imax=i\n aamax=dum\n ENDIF\n END DO\n IF (j .NE. 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 d=-d\n vv(imax)=vv(j)\n ENDIF\n indx(j)=imax\n IF (a(j,j) .EQ. 0.) a(j,j)=tiny\n IF (j .NE. n) THEN\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\n \n RETURN\n END\n\n\n\n SUBROUTINE lubksb(a,n,np,indx,b)\nC Subroutine associated with LU decomposition.\nC Taken from \"Numerical Recipes\" Flannery and Press.\nC Used in Savitsky Golay smoothing.\n INTEGER n,np,indx(n)\n REAL a(np,np),b(n)\n INTEGER i,ii,j,ll\n REAL sum\n ii=0\n DO i=1,n\n ll=indx(i)\n sum=b(ll)\n b(ll)=b(i)\n IF (ii .NE. 0) THEN\n DO j=ii,i-1\n sum=sum-a(i,j)*b(j)\n END DO\n ELSEIF (sum .NE. 0.) THEN\n ii=i\n ENDIF\n b(i)=sum\n END DO\n DO i=n,1,-1\n sum=b(i)\n DO j=i+1,n\n sum=sum-a(i,j)*b(j)\n END DO\n b(i)=sum/a(i,i)\n END DO\n\n RETURN\n END\n", "meta": {"hexsha": "7706e133e90a4c184c1d4e4b192c8726e3eaa678", "size": 3727, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "corfunc/fortran/corfunc/savgol.f", "max_stars_repo_name": "scattering-central/CCP13", "max_stars_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "corfunc/fortran/corfunc/savgol.f", "max_issues_repo_name": "scattering-central/CCP13", "max_issues_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "corfunc/fortran/corfunc/savgol.f", "max_forks_repo_name": "scattering-central/CCP13", "max_forks_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-09-05T15:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-15T11:13:45.000Z", "avg_line_length": 22.3173652695, "max_line_length": 71, "alphanum_fraction": 0.4781325463, "num_tokens": 1247, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069962657177, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6815996960262792}} {"text": "module loglikelihood_module\n use utils_module, only: dp\n\n integer :: nDims\n integer :: n_knots\n integer :: nStats\n\n real(dp), allocatable, dimension(:) :: theta_saved\n real(dp), allocatable, dimension(:,:) :: spline_data\n\n real(dp), allocatable, dimension(:) :: x0\n real(dp), allocatable, dimension(:) :: y0\n real(dp), allocatable, dimension(:) :: sigmax\n real(dp), allocatable, dimension(:) :: sigmay\n\n real(dp) :: x_min_int, x_max_int\n real(dp) :: x_min, x_max\n\n contains\n\n function loglikelihood(theta,phi)\n use utils_module, only: logzero, logincexp,logTwoPi\n implicit none\n real(dp), intent(in), dimension(:) :: theta !> Input parameters\n real(dp), intent(out), dimension(:) :: phi !> Output derived parameters\n real(dp) :: loglikelihood ! loglikelihood value to output\n\n real(dp) :: loglikelihood_temp\n integer :: i_stats\n integer :: i_int\n real(dp) :: x,y\n\n\n ! Read in the spline array if necessary\n if(any(theta_saved /= theta ) ) then\n\n ! Calculate the spline array\n spline_data(:,1) = theta(1:n_knots)\n spline_data(:,2) = theta(n_knots+1:nDims)\n\n ! Save the current theta\n theta_saved = theta\n\n end if\n\n\n ! Calculate the likelihood\n loglikelihood_temp = logzero\n loglikelihood = 0d0\n\n ! Iterate over all points in the file\n do i_stats = 1,nStats\n\n\n ! If there's no error in the x variable then this is a lot simpler\n if(sigmax(i_stats) <=0d0) then\n\n ! calculate the likelihood\n x = x0(i_stats)\n y = linear_interpolate(x,spline_data,0)\n loglikelihood_temp = - log( sigmay(i_stats) ) - logTwoPi/2d0 - ((y-y0(i_stats))/sigmay(i_stats))**2/2d0 \n\n else\n ! Integrate the spline\n loglikelihood_temp = log_exp_int(x0(i_stats),y0(i_stats),sigmax(i_stats),sigmay(i_stats),x_min,x_max)\n\n ! Normalise via the normalising constants, and the width of the\n ! integral\n loglikelihood_temp = loglikelihood_temp &\n - log( sigmay(i_stats) ) - log( sigmax(i_stats) ) - logTwoPi &\n - log(x_max-x_min)\n\n end if\n\n\n ! Add the likelihood from this point to the total likelihood (note\n ! that this is in fact multiplication)\n loglikelihood = loglikelihood + loglikelihood_temp\n\n end do\n\n end function loglikelihood\n\n\n\n\n\n ! This function computes the logarithm of:\n !\n ! /xmax \n ! | exp( - (x-x0)^2/2sx^2 - (y0-f(x))^2/2sy^2 ) dx \n ! /xmin \n !\n ! where f(x) is a linear spline defined by spline_arr.\n !\n ! This is effectively a piecewise linear integral:\n ! \n ! /xmax \n ! | exp( - (x-x0)^2/2sx^2 - (y0-(m x + c))^2/2sy^2 ) dx \n ! /xmin \n !\n ! where m and c change depending on which interval one is in.\n !\n ! Completing the square on the integrand yields:\n ! 1 / \\2 1 1 \n ! - ----- | x - e s^2 | - --- f + --- e\n ! 2 s^2 \\ / 2 2 \n !\n ! where \n !\n ! s = (sx^-2 + m^2 sy^-2)^-(1/2)\n ! e = x0/sx^2 + (y-c) m/ sy^2\n ! f = x0^2 /sx^2 + (y-c)^2 / sy^2\n !\n ! The integral can then be computed with error functions, since\n !\n ! /x2\n ! | exp( (x-x0)^2/2s^2 ) dx = \n ! /x1\n !\n ! sqrt(pi/2) s ( erf( (x2-x0)/sqrt2 s) - erf( (x1-x0)/sqrt2 s) )\n !\n function log_exp_int(x0,y0,sx,sy,xmin,xmax)\n use utils_module, only: logzero,logincexp\n implicit none\n\n real(dp), intent(in) :: x0,y0,sx,sy,xmin,xmax\n real(dp) :: log_exp_int\n\n integer :: i,n\n real(dp) :: m,c,x1,x2,y1,y2\n\n real(dp) :: s,e,f\n\n real(dp),parameter :: logsqrtpiby2 = log(sqrt(atan(1d0)*2d0))\n\n log_exp_int = logzero\n\n n = size(spline_data,1)\n\n do i=1,n-1\n\n ! Here are some useful local variables\n x1 = spline_data(i,1)\n y1 = spline_data(i,2)\n x2 = spline_data(i+1,1)\n y2 = spline_data(i+1,2)\n\n m = (y2-y1)/(x2-x1)\n c = y1 - m*x1\n\n ! Check to see our integration range\n if(x2xmax) cycle\n if(x2>xmax) x2 = xmax\n\n ! Define the reduced variables\n s = (1/sx**2 + m**2/sy**2)**(-0.5)\n e = x0/sx**2 + (y0-c)*m/sy**2\n f = x0**2 /sx**2 + (y0-c)**2/sy**2\n\n\n call logincexp(log_exp_int,&\n logsqrtpiby2 + log(s) +&\n logderf(&\n (x1-e*s**2)/sqrt(2d0)/s ,&\n (x2-e*s**2)/sqrt(2d0)/s &\n )&\n - f/2 + e**2*s**2/2 &\n )\n\n end do\n\n end function log_exp_int\n\n function logderf(a,b)\n use utils_module, only: logzero\n implicit none\n real(dp),intent(in) :: a,b\n real(dp) logderf\n\n real(dp) :: erfa,erfb\n\n erfb = erf(b)\n erfa = erf(a)\n\n if(erfb<=erfa) then\n logderf = logzero\n else\n logderf = log(erfb-erfa)\n end if\n\n end function logderf\n\n function erfapprox(x)\n implicit none\n real(dp), intent(in) :: x\n real(dp) erfapprox\n\n real(dp), parameter :: pi = atan(1d0)*4d0\n real(dp), parameter :: a = 8*(pi-3)/(3*pi*(4-pi))\n\n erfapprox = sign(1d0,x)*sqrt(1-exp(-x**2*(4/pi + a*x**2)/(1+a*x**2)))\n end function erfapprox\n\n\n subroutine setup_loglikelihood(settings)\n use settings_module, only: program_settings\n use abort_module, only: halt_program\n implicit none\n type(program_settings), intent(in) :: settings\n\n integer, parameter :: stats_unit = 1000\n\n integer :: ioerror\n integer :: i_stats\n\n\n ! Save the current theta for use next call\n nDims = settings%nDims\n n_knots = nDims/2\n\n\n ! Allocate any arrays that need to be allocated\n if(allocated(theta_saved)) deallocate(theta_saved)\n if(allocated(spline_data)) deallocate(spline_data)\n if(allocated(x0)) deallocate(x0)\n if(allocated(y0)) deallocate(y0)\n if(allocated(sigmax)) deallocate(sigmax)\n if(allocated(sigmay)) deallocate(sigmay)\n\n allocate(theta_saved(nDims),spline_data(n_knots,2))\n\n\n ! Find out the number of points\n open(stats_unit,file='data/data.dat')\n\n nStats = 0\n do \n read(stats_unit,*,iostat=ioerror)\n if( ioerror==0 ) then\n nStats = nStats+1\n else\n exit\n end if\n end do\n\n close(stats_unit)\n\n if (nStats == 0) call halt_program('Error reading data/data.dat')\n\n\n\n ! Allocate the data arrays\n allocate(x0(nStats),y0(nStats),sigmax(nStats),sigmay(nStats))\n\n ! Read in the data array\n open(stats_unit,file='data/data.dat')\n do i_stats=1,nStats\n read(stats_unit,*) x0(i_stats), y0(i_stats), sigmax(i_stats), sigmay(i_stats) \n end do\n close(stats_unit)\n\n ! Read in the mins and maxs array\n open(stats_unit,file='data/data_min_max.dat')\n read(stats_unit,*) x_min\n read(stats_unit,*) x_max\n close(stats_unit)\n\n\n\n end subroutine setup_loglikelihood\n\n\n\n\n function linear_interpolate(x,spline_array,deriv) result(y)\n\n implicit none \n\n real(dp) :: y ! dependent variable\n real(dp),intent(in) :: x ! independent variable\n real(dp),intent(in) :: spline_array(:,:) ! x coords of interpolation\n ! y coords of interpolation\n integer, intent(in) :: deriv ! whether 0 or 1 derivatives\n\n integer i\n integer :: num_nodes\n real(dp), dimension(size(spline_array,1)) :: x_node\n real(dp), dimension(size(spline_array,1)) :: y_node\n\n !------------------------------------------------------------------------------\n ! \n ! y_node(2)^ +\n ! <-+-> ^ +\n ! y_node(1)^ + v + <-+->\n ! <-+-> + ^ + v y_node(num_nodes)\n ! + v <-+-> \n ! + v y_node(3) \n ! \n ! \n !----------------+-------------+-----------+---------------+-------------------\n ! x_node(1) x_node(2) x_node(3) x_node(num_nodes)\n !\n ! This function constructs a linear interpolation: \n ! http://en.wikipedia.org/wiki/Linear_interpolation\n !\n ! The interpolation points are\n ! { ( x_node(i) , y_node(i) ) : i=1..num_nodes }\n ! \n ! Outside of the range, the function is continued with the previous\n ! gradient\n !\n\n num_nodes = size(spline_array,1)\n x_node = spline_array(:,1)\n y_node = spline_array(:,2)\n\n\n ! We need a positive number of nodes\n if (num_nodes < 1) then\n write(*,*) 'linear_interpolate: cannot have less than 1 node'\n stop\n else if (num_nodes==1) then \n ! If we have only a single node, then this is a 'flat function'\n ! defined only by the y_node\n select case(deriv)\n case(0) \n y=y_node(1)\n case(1)\n y=0d0\n end select\n return\n endif\n\n ! We should also check that the x values are ordered properly\n do i=2,num_nodes\n if( x_node(i-1)>x_node(i) ) then\n write(*,*) 'linear_interpolate: nodes are not ordered correctly'\n write(*,*) 'x_nodes:', x_node\n stop\n endif\n end do\n\n\n ! We proceed from low x to high x.\n\n ! First consider the case when we're below the bottom x_node\n if ( x <= x_node(1) ) then\n ! we want a 'line continuation' on this side\n select case(deriv)\n case(0)\n y = y_node(1) + (y_node(2)-y_node(1)) * (x-x_node(1)) / (x_node(2)-x_node(1))\n case(1)\n y = (y_node(2)-y_node(1)) / (x_node(2)-x_node(1))\n end select\n return\n\n endif\n\n ! Now consider the cases when we're in between\n do i=2,num_nodes\n if ( x <= x_node(i) ) then\n select case(deriv)\n case(0)\n y = y_node(i-1) + (y_node(i)-y_node(i-1)) * (x-x_node(i-1)) / (x_node(i)-x_node(i-1))\n case(1)\n y = (y_node(i)-y_node(i-1)) / (x_node(i)-x_node(i-1))\n end select\n return\n endif\n enddo\n\n\n\n ! Finally consider the case when we're above the top x_node\n if ( x >= x_node(num_nodes) ) then\n ! we want a 'line continuation' on this side\n select case(deriv)\n case(0)\n y = y_node(num_nodes-1) &\n + (y_node(num_nodes)-y_node(num_nodes-1)) &\n * (x-x_node(num_nodes-1)) &\n / (x_node(num_nodes)-x_node(num_nodes-1))\n case(1)\n y = (y_node(num_nodes)-y_node(num_nodes-1)) &\n / (x_node(num_nodes)-x_node(num_nodes-1))\n end select\n return\n\n endif\n\n\n end function linear_interpolate\n\n\n\nend module loglikelihood_module\n", "meta": {"hexsha": "30a63734f5e0d58b3f9ab748c5d53984d604c77d", "size": 12294, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Externals/PolyChord/likelihoods/examples/fitting.f90", "max_stars_repo_name": "yuanfangtardis/vscode_project", "max_stars_repo_head_hexsha": "2d78a85413cc85789cc4fee8ec991eb2a0563ef8", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Externals/PolyChord/likelihoods/examples/fitting.f90", "max_issues_repo_name": "yuanfangtardis/vscode_project", "max_issues_repo_head_hexsha": "2d78a85413cc85789cc4fee8ec991eb2a0563ef8", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Externals/PolyChord/likelihoods/examples/fitting.f90", "max_forks_repo_name": "yuanfangtardis/vscode_project", "max_forks_repo_head_hexsha": "2d78a85413cc85789cc4fee8ec991eb2a0563ef8", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-15T12:22:30.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-15T12:22:30.000Z", "avg_line_length": 30.6583541147, "max_line_length": 120, "alphanum_fraction": 0.4781194078, "num_tokens": 3153, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850039701655, "lm_q2_score": 0.7279754607093178, "lm_q1q2_score": 0.6815925071204066}} {"text": " SUBROUTINE TG01BD( JOBE, COMPQ, COMPZ, N, M, P, ILO, IHI, A, LDA,\n $ E, LDE, B, LDB, C, LDC, Q, LDQ, Z, LDZ, DWORK,\n $ LDWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To reduce the matrices A and E of the system pencil\nC\nC S = ( A B ) - lambda ( E 0 ) ,\nC ( C 0 ) ( 0 0 )\nC\nC corresponding to the descriptor triple (A-lambda E,B,C),\nC to generalized upper Hessenberg form using orthogonal\nC transformations,\nC\nC Q' * A * Z = H, Q' * E * Z = T,\nC\nC where H is upper Hessenberg, T is upper triangular, Q and Z\nC are orthogonal, and ' means transpose. The corresponding\nC transformations, written compactly as diag(Q',I) * S * diag(Z,I),\nC are also applied to B and C, getting Q' * B and C * Z.\nC\nC The orthogonal matrices Q and Z are determined as products of\nC Givens rotations. They may either be formed explicitly, or they\nC may be postmultiplied into input matrices Q1 and Z1, so that\nC\nC Q1 * A * Z1' = (Q1*Q) * H * (Z1*Z)'\nC Q1 * E * Z1' = (Q1*Q) * T * (Z1*Z)'.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC JOBE CHARACTER*1\nC Specifies whether E is a general square or an upper\nC triangular matrix, as follows:\nC = 'G': E is a general square matrix;\nC = 'U': E is an upper triangular matrix.\nC\nC COMPQ CHARACTER*1\nC Indicates what should be done with matrix Q, as follows:\nC = 'N': do not compute Q;\nC = 'I': Q is initialized to the unit matrix, and the\nC orthogonal matrix Q is returned;\nC = 'V': Q must contain an orthogonal matrix Q1 on entry,\nC and the product Q1*Q is returned.\nC\nC COMPZ CHARACTER*1\nC Indicates what should be done with matrix Z, as follows:\nC = 'N': do not compute Z;\nC = 'I': Z is initialized to the unit matrix, and the\nC orthogonal matrix Z is returned;\nC = 'V': Z must contain an orthogonal matrix Z1 on entry,\nC and the product Z1*Z is returned.\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The order of the matrices A, E, and the number of rows of\nC the matrix B. N >= 0.\nC\nC M (input) INTEGER\nC The number of columns of the matrix B. M >= 0.\nC\nC P (input) INTEGER\nC The number of rows of the matrix C. P >= 0.\nC\nC ILO (input) INTEGER\nC IHI (input) INTEGER\nC It is assumed that A and E are already upper triangular in\nC rows and columns 1:ILO-1 and IHI+1:N. ILO and IHI could\nC normally be set by a previous call to LAPACK Library\nC routine DGGBAL; otherwise they should be set to 1 and N,\nC respectively.\nC 1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0.\nC If JOBE = 'U', the matrix E is assumed upper triangular.\nC\nC A (input/output) DOUBLE PRECISION array, dimension (LDA,N)\nC On entry, the leading N-by-N part of this array must\nC contain the state dynamics matrix A.\nC On exit, the leading N-by-N part of this array contains\nC the upper Hessenberg matrix H = Q' * A * Z. The elements\nC below the first subdiagonal are set to zero.\nC\nC LDA INTEGER\nC The leading dimension of array A. LDA >= MAX(1,N).\nC\nC E (input/output) DOUBLE PRECISION array, dimension (LDE,N)\nC On entry, the leading N-by-N part of this array must\nC contain the descriptor matrix E. If JOBE = 'U', this\nC matrix is assumed upper triangular.\nC On exit, the leading N-by-N part of this array contains\nC the upper triangular matrix T = Q' * E * Z. The elements\nC below the diagonal are set to zero.\nC\nC LDE INTEGER\nC The leading dimension of array E. LDE >= MAX(1,N).\nC\nC B (input/output) DOUBLE PRECISION array, dimension (LDB,M)\nC On entry, the leading N-by-M part of this array must\nC contain the input/state matrix B.\nC On exit, if M > 0, the leading N-by-M part of this array\nC contains the transformed matrix Q' * B.\nC The array B is not referenced if M = 0.\nC\nC LDB INTEGER\nC The leading dimension of array B.\nC LDB >= MAX(1,N) if M > 0; LDB >= 1 if M = 0.\nC\nC C (input/output) DOUBLE PRECISION array, dimension (LDC,N)\nC On entry, the leading P-by-N part of this array must\nC contain the state/output matrix C.\nC On exit, if P > 0, the leading P-by-N part of this array\nC contains the transformed matrix C * Z.\nC The array C is not referenced if P = 0.\nC\nC LDC INTEGER\nC The leading dimension of array C. LDC >= MAX(1,P).\nC\nC Q (input/output) DOUBLE PRECISION array, dimension (LDQ,N)\nC If COMPQ = 'N': Q is not referenced;\nC If COMPQ = 'I': on entry, Q need not be set, and on exit\nC it contains the orthogonal matrix Q,\nC where Q' is the product of the Givens\nC transformations which are applied to A,\nC E, and B on the left;\nC If COMPQ = 'V': on entry, Q must contain an orthogonal\nC matrix Q1, and on exit this is\nC overwritten by Q1*Q.\nC\nC LDQ INTEGER\nC The leading dimension of array Q.\nC LDQ >= 1, if COMPQ = 'N';\nC LDQ >= MAX(1,N), if COMPQ = 'I' or 'V'.\nC\nC Z (input/output) DOUBLE PRECISION array, dimension (LDZ,N)\nC If COMPZ = 'N': Z is not referenced;\nC If COMPZ = 'I': on entry, Z need not be set, and on exit\nC it contains the orthogonal matrix Z,\nC which is the product of the Givens\nC transformations applied to A, E, and C\nC on the right;\nC If COMPZ = 'V': on entry, Z must contain an orthogonal\nC matrix Z1, and on exit this is\nC overwritten by Z1*Z.\nC\nC LDZ INTEGER\nC The leading dimension of array Z.\nC LDZ >= 1, if COMPZ = 'N';\nC LDZ >= MAX(1,N), if COMPZ = 'I' or 'V'.\nC\nC Workspace\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0, DWORK(1) contains the optimal value\nC of LDWORK.\nC\nC LDWORK INTEGER\nC The dimension of the array DWORK.\nC LDWORK >= 1, if JOBE = 'U';\nC LDWORK >= MAX(1,IHI+1-ILO+MAX(NI,M)), if JOBE = 'G', where\nC NI = N+1-ILO, if COMPQ = 'N', and NI = N, otherwise.\nC For good performance, if JOBE = 'G', LDWORK must generally\nC be larger, LDWORK >= MAX(1,IHI+1-ILO+MAX(NI,M)*NB), where\nC NB is the optimal block size.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit.\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value.\nC\nC METHOD\nC\nC First, this routine computes the QR factorization of E and applies\nC the transformations to A, B, and possibly Q. Then, the routine\nC reduces A to upper Hessenberg form, preserving E triangular, by\nC an unblocked reduction [1], using two sequences of plane rotations\nC applied alternately from the left and from the right. The\nC corresponding transformations may be accumulated and/or applied\nC to the matrices B and C. If JOBE = 'U', the initial reduction of E\nC to upper triangular form is skipped.\nC\nC This routine is a modification and extension of the LAPACK Library\nC routine DGGHRD [2].\nC\nC REFERENCES\nC\nC [1] Golub, G.H. and van Loan, C.F.\nC Matrix Computations. Third Edition.\nC M. D. Johns Hopkins University Press, Baltimore, 1996.\nC\nC [2] Anderson, E., Bai, Z., Bischof, C., Demmel, J., Dongarra, J.,\nC Du Croz, J., Greenbaum, A., Hammarling, S., McKenney, A.,\nC Ostrouchov, S., and Sorensen, D.\nC LAPACK Users' Guide: Second Edition.\nC SIAM, Philadelphia, 1995.\nC\nC CONTRIBUTOR\nC\nC D. Sima, University of Bucharest, May 2001.\nC V. Sima, Research Institute for Informatics, Bucharest, May 2001.\nC\nC REVISIONS\nC\nC -\nC\nC KEYWORDS\nC\nC Eigenvalue, matrix algebra, matrix operations, similarity\nC transformation.\nC\nC *********************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ONE, ZERO\n PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 )\nC .. Scalar Arguments ..\n CHARACTER COMPQ, COMPZ, JOBE\n INTEGER IHI, ILO, INFO, LDA, LDB, LDC, LDE, LDQ,\n $ LDWORK, LDZ, M, N, P\nC .. Array Arguments ..\n DOUBLE PRECISION A( LDA, * ), B( LDB, * ), C( LDC, * ),\n $ DWORK( * ), E( LDE, * ), Q( LDQ, * ),\n $ Z( LDZ, * )\nC .. Local Scalars ..\n LOGICAL ILQ, ILZ, INQ, INZ, UPPER, WITHB, WITHC\n INTEGER IERR, ITAU, IWRK, JCOL, JROW, MAXWRK, MINWRK\n DOUBLE PRECISION CS, S, TEMP\nC .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\nC .. External Subroutines ..\n EXTERNAL DGEQRF, DLARTG, DLASET, DORMQR, DROT, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC INT, MAX\nC\nC .. Executable Statements ..\nC\nC Test the input scalar parameters.\nC\n UPPER = LSAME( JOBE, 'U' )\n INQ = LSAME( COMPQ, 'I' )\n ILQ = LSAME( COMPQ, 'V' ) .OR. INQ\n INZ = LSAME( COMPZ, 'I' )\n ILZ = LSAME( COMPZ, 'V' ) .OR. INZ\n WITHB = M.GT.0\n WITHC = P.GT.0\nC\n INFO = 0\n IF( .NOT.( UPPER .OR. LSAME( JOBE, 'G' ) ) ) THEN\n INFO = -1\n ELSE IF( .NOT.( ILQ .OR. LSAME( COMPQ, 'N' ) ) ) THEN\n INFO = -2\n ELSE IF( .NOT.( ILZ .OR. LSAME( COMPZ, 'N' ) ) ) THEN\n INFO = -3\n ELSE IF( N.LT.0 ) THEN\n INFO = -4\n ELSE IF( M.LT.0 ) THEN\n INFO = -5\n ELSE IF( P.LT.0 ) THEN\n INFO = -6\n ELSE IF( ILO.LT.1 ) THEN\n INFO = -7\n ELSE IF( IHI.GT.N .OR. IHI.LT.ILO-1 ) THEN\n INFO = -8\n ELSE IF( LDA.LT.MAX( 1, N ) ) THEN\n INFO = -10\n ELSE IF( LDE.LT.MAX( 1, N ) ) THEN\n INFO = -12\n ELSE IF( ( WITHB .AND. LDB.LT.N ) .OR. LDB.LT.1 ) THEN\n INFO = -14\n ELSE IF( LDC.LT.MAX( 1, P ) ) THEN\n INFO = -16\n ELSE IF( ( ILQ .AND. LDQ.LT.N ) .OR. LDQ.LT.1 ) THEN\n INFO = -18\n ELSE IF( ( ILZ .AND. LDZ.LT.N ) .OR. LDZ.LT.1 ) THEN\n INFO = -20\n ELSE\n JROW = IHI + 1 - ILO\n JCOL = N + 1 - ILO\n IF( UPPER ) THEN\n MINWRK = 1\n MAXWRK = 1\n ELSE\n IF( ILQ ) THEN\n MINWRK = N\n ELSE\n MINWRK = JCOL\n END IF\n MINWRK = MAX( 1, JROW + MAX( MINWRK, M ) )\n END IF\n IF( LDWORK.LT.MINWRK )\n $ INFO = -22\n END IF\nC\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'TG01BD', -INFO )\n RETURN\n END IF\nC\nC Initialize Q and Z if desired.\nC\n IF( INQ )\n $ CALL DLASET( 'Full', N, N, ZERO, ONE, Q, LDQ )\n IF( INZ )\n $ CALL DLASET( 'Full', N, N, ZERO, ONE, Z, LDZ )\nC\nC Quick return if possible.\nC\n IF( N.LE.1 ) THEN\n DWORK( 1 ) = ONE\n RETURN\n END IF\nC\n IF( .NOT.UPPER ) THEN\nC\nC Reduce E to triangular form (QR decomposition of E).\nC\nC (Note: Comments in the code beginning \"Workspace:\" describe the\nC minimal amount of real workspace needed at that point in the\nC code, as well as the preferred amount for good performance.\nC NB refers to the optimal block size for the immediately\nC following subroutine, as returned by ILAENV.)\nC\nC Workspace: need IHI+1-ILO+N+1-ILO;\nC prefer IHI+1-ILO+(N+1-ILO)*NB.\nC\n ITAU = 1\n IWRK = ITAU + JROW\n CALL DGEQRF( JROW, JCOL, E( ILO, ILO ), LDE, DWORK( ITAU ),\n $ DWORK( IWRK ), LDWORK-IWRK+1, IERR )\n MAXWRK = MAX( INT( DWORK( IWRK ) ) + IWRK - 1, MINWRK )\nC\nC Apply the orthogonal transformation to matrices A, B, and Q.\nC Workspace: need IHI+1-ILO+N+1-ILO;\nC prefer IHI+1-ILO+(N+1-ILO)*NB.\nC\n CALL DORMQR( 'Left', 'Transpose', JROW, JCOL, JROW,\n $ E( ILO, ILO ), LDE, DWORK( ITAU ), A( ILO, ILO ),\n $ LDA, DWORK( IWRK ), LDWORK-IWRK+1, IERR )\n MAXWRK = MAX( INT( DWORK( IWRK ) ) + IWRK - 1, MAXWRK )\nC\n IF ( WITHB ) THEN\nC\nC Workspace: need IHI+1-ILO+M;\nC prefer IHI+1-ILO+M*NB.\nC\n CALL DORMQR( 'Left', 'Transpose', JROW, M, JROW,\n $ E( ILO, ILO ), LDE, DWORK( ITAU ), B( ILO, 1 ),\n $ LDB, DWORK( IWRK ), LDWORK-IWRK+1, IERR )\n MAXWRK = MAX( INT( DWORK( IWRK ) ) + IWRK - 1, MAXWRK )\n END IF\nC\n IF( ILQ ) THEN\nC\nC Workspace: need IHI+1-ILO+N;\nC prefer IHI+1-ILO+N*NB.\nC\n CALL DORMQR( 'Right', 'No Transpose', N, JROW, JROW,\n $ E( ILO, ILO ), LDE, DWORK( ITAU ), Q( 1, ILO ),\n $ LDQ, DWORK( IWRK ), LDWORK-IWRK+1, IERR )\n MAXWRK = MAX( INT( DWORK( IWRK ) ) + IWRK - 1, MAXWRK )\n END IF\n END IF\nC\nC Zero out lower triangle of E.\nC\n IF( JROW.GT.1 )\n $ CALL DLASET( 'Lower', JROW-1, JROW-1, ZERO, ZERO,\n $ E( ILO+1, ILO ), LDE )\nC\nC Reduce A and E and apply the transformations to B, C, Q and Z.\nC\n DO 20 JCOL = ILO, IHI - 2\nC\n DO 10 JROW = IHI, JCOL + 2, -1\nC\nC Step 1: rotate rows JROW-1, JROW to kill A(JROW,JCOL).\nC\n TEMP = A( JROW-1, JCOL )\n CALL DLARTG( TEMP, A( JROW, JCOL ), CS, S,\n $ A( JROW-1, JCOL ) )\n A( JROW, JCOL ) = ZERO\n CALL DROT( N-JCOL, A( JROW-1, JCOL+1 ), LDA,\n $ A( JROW, JCOL+1 ), LDA, CS, S )\n CALL DROT( N+2-JROW, E( JROW-1, JROW-1 ), LDE,\n $ E( JROW, JROW-1 ), LDE, CS, S )\n IF( WITHB )\n $ CALL DROT( M, B( JROW-1, 1 ), LDB, B( JROW, 1 ), LDB,\n $ CS, S )\n IF( ILQ )\n $ CALL DROT( N, Q( 1, JROW-1 ), 1, Q( 1, JROW ), 1, CS, S )\nC\nC Step 2: rotate columns JROW, JROW-1 to kill E(JROW,JROW-1).\nC\n TEMP = E( JROW, JROW )\n CALL DLARTG( TEMP, E( JROW, JROW-1 ), CS, S,\n $ E( JROW, JROW ) )\n E( JROW, JROW-1 ) = ZERO\n CALL DROT( IHI, A( 1, JROW ), 1, A( 1, JROW-1 ), 1, CS, S )\n CALL DROT( JROW-1, E( 1, JROW ), 1, E( 1, JROW-1 ), 1, CS,\n $ S )\n IF( WITHC )\n $ CALL DROT( P, C( 1, JROW ), 1, C( 1, JROW-1 ), 1, CS, S )\n IF( ILZ )\n $ CALL DROT( N, Z( 1, JROW ), 1, Z( 1, JROW-1 ), 1, CS, S )\n 10 CONTINUE\nC\n 20 CONTINUE\nC\n DWORK( 1 ) = MAXWRK\n RETURN\nC *** Last line of TG01BD ***\n END\n", "meta": {"hexsha": "489fc0d1e48d96087e20187d3923c1af815af449", "size": 15756, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/TG01BD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/TG01BD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/TG01BD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 37.4251781473, "max_line_length": 72, "alphanum_fraction": 0.5120588982, "num_tokens": 4923, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9362850075259039, "lm_q2_score": 0.7279754430043072, "lm_q1q2_score": 0.681592493131961}} {"text": "!-----------------------------------------------------------------------\r\n! Update soil temperatures\r\n!-----------------------------------------------------------------------\r\nsubroutine SOIL(csoil,Gsoil,ksoil)\r\n\r\nuse DRIVING, only : &\r\n dt ! Timestep (s)\r\n\r\nuse GRID, only : &\r\n Dzsoil, &! Soil layer thicknesses (m)\r\n Nsoil ! Number of soil layers\r\n\r\nuse STATE_VARIABLES, only : &\r\n Tsoil ! Soil layer temperatures (K)\r\n\r\nimplicit none\r\n\r\nreal, intent(in) :: &\r\n csoil(Nsoil), &! Areal heat capacity of soil (J/K/m^2)\r\n Gsoil, &! Heat flux into soil (W/m^2)\r\n ksoil(Nsoil) ! Thermal conductivity of soil (W/m/K)\r\n\r\ninteger :: &\r\n k ! Level counter\r\n\r\nreal :: &\r\n a(Nsoil), &! Below-diagonal matrix elements\r\n b(Nsoil), &! Diagonal matrix elements\r\n c(Nsoil), &! Above-diagonal matrix elements\r\n dTs(Nsoil), &! Temperature increments (k)\r\n Gs(Nsoil), &! Thermal conductivity between layers (W/m^2/k)\r\n rhs(Nsoil) ! Matrix equation rhs\r\n\r\ndo k = 1, Nsoil - 1\r\n Gs(k) = 2 / (Dzsoil(k)/ksoil(k) + Dzsoil(k+1)/ksoil(k+1))\r\nend do\r\na(1) = 0\r\nb(1) = csoil(1) + Gs(1)*dt\r\nc(1) = - Gs(1)*dt\r\nrhs(1) = (Gsoil - Gs(1)*(Tsoil(1) - Tsoil(2)))*dt\r\ndo k = 2, Nsoil - 1\r\n a(k) = c(k-1)\r\n b(k) = csoil(k) + (Gs(k-1) + Gs(k))*dt\r\n c(k) = - Gs(k)*dt\r\n rhs(k) = Gs(k-1)*(Tsoil(k-1) - Tsoil(k))*dt &\r\n + Gs(k)*(Tsoil(k+1) - Tsoil(k))*dt \r\nend do\r\nk = Nsoil\r\nGs(k) = ksoil(k)/Dzsoil(k)\r\na(k) = c(k-1)\r\nb(k) = csoil(k) + (Gs(k-1) + Gs(k))*dt\r\nc(k) = 0\r\nrhs(k) = Gs(k-1)*(Tsoil(k-1) - Tsoil(k))*dt\r\ncall TRIDIAG(Nsoil,Nsoil,a,b,c,rhs,dTs)\r\ndo k = 1, Nsoil\r\n Tsoil(k) = Tsoil(k) + dTs(k)\r\nend do\r\n\r\nend subroutine SOIL\r\n", "meta": {"hexsha": "a14790151647fae476f4cb4a13e06466538627ca", "size": 1777, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/SOIL.f90", "max_stars_repo_name": "tkupek/FSM", "max_stars_repo_head_hexsha": "b86909ab3b02acb6f5253a4e49dbef8d1b907c8a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2015-04-16T04:04:37.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-17T01:45:10.000Z", "max_issues_repo_path": "src/SOIL.f90", "max_issues_repo_name": "tkupek/FSM", "max_issues_repo_head_hexsha": "b86909ab3b02acb6f5253a4e49dbef8d1b907c8a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-05-16T13:33:34.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-03T18:47:06.000Z", "max_forks_repo_path": "src/SOIL.f90", "max_forks_repo_name": "tkupek/FSM", "max_forks_repo_head_hexsha": "b86909ab3b02acb6f5253a4e49dbef8d1b907c8a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2015-07-17T15:53:49.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-28T07:14:58.000Z", "avg_line_length": 29.6166666667, "max_line_length": 73, "alphanum_fraction": 0.4800225098, "num_tokens": 651, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850093037732, "lm_q2_score": 0.7279754371026368, "lm_q1q2_score": 0.6815924889005607}} {"text": "PROGRAM YULETIDE\n\nIMPLICIT NONE\n\nINTEGER :: day, year\n\nWRITE(*, \"(A)\", ADVANCE=\"NO\") \"25th of December is a Sunday in\"\nDO year = 2008, 2121\n day = Day_of_week(25, 12, year)\n IF (day == 1) WRITE(*, \"(I5)\", ADVANCE=\"NO\") year\nEND DO\n\nCONTAINS\n\nFUNCTION Day_of_week(d, m, y)\n INTEGER :: Day_of_week, j, k, mm, yy\n INTEGER, INTENT(IN) :: d, m, y\n\n mm=m\n yy=y\n IF(mm.le.2) THEN\n mm=mm+12\n yy=yy-1\n END IF\n j = yy / 100\n k = MOD(yy, 100)\n Day_of_week = MOD(d + ((mm+1)*26)/10 + k + k/4 + j/4 + 5*j, 7)\nEND FUNCTION Day_of_week\n\nEND PROGRAM YULETIDE\n", "meta": {"hexsha": "7fff889988c8d2534478062b13f8adff422d7424", "size": 575, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Day-of-the-week/Fortran/day-of-the-week.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/Day-of-the-week/Fortran/day-of-the-week.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/Day-of-the-week/Fortran/day-of-the-week.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.5483870968, "max_line_length": 65, "alphanum_fraction": 0.587826087, "num_tokens": 228, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362849986365572, "lm_q2_score": 0.727975443004307, "lm_q1q2_score": 0.6815924866607348}} {"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", "meta": {"hexsha": "825db5330df1c2a46b2a58447c61568c2dda88dd", "size": 350, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ch21/maths_module.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/maths_module.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/maths_module.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": 26.9230769231, "max_line_length": 50, "alphanum_fraction": 0.6685714286, "num_tokens": 114, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850039701653, "lm_q2_score": 0.7279754371026367, "lm_q1q2_score": 0.681592485017825}} {"text": "module type_GaussianGrid\n\n use, intrinsic :: ISO_Fortran_env, only: &\n stderr => ERROR_UNIT\n\n use spherepack_precision, only: &\n wp, & ! working precision\n ip ! integer precision\n\n use type_SphericalGrid, only: &\n SphericalGrid\n\n use gaussian_latitudes_and_weights_routines, only: &\n compute_gaussian_latitudes_and_weights\n\n ! Explicit typing only\n implicit none\n\n ! Everything is private unless stated otherwise\n private\n public :: GaussianGrid\n \n type, public, extends(SphericalGrid) :: GaussianGrid\n ! Type components\n real(wp), allocatable, public :: gaussian_weights(:)\n contains\n ! Type-bound procedures\n procedure, public :: assert_initialized => assert_init_gaussian_grid\n procedure, public :: create => create_gaussian_grid\n procedure, public :: destroy => destroy_gaussian_grid\n procedure, public, nopass :: get_latitudes_and_gaussian_weights\n procedure, public :: unformatted_print\n generic, public :: assignment (=) => copy_gaussian_grid\n procedure, private :: copy_gaussian_grid\n end type GaussianGrid\n\n ! Declare user-defined constructor\n interface GaussianGrid\n module procedure gaussian_grid_constructor\n end interface\n\ncontains\n\n function gaussian_grid_constructor(nlat, nlon) &\n result (return_value)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat ! number of latitudinal points 0 <= theta <= pi\n integer(ip), intent(in) :: nlon ! number of longitudinal points 0 <= phi <= 2*pi\n type(GaussianGrid) :: return_value\n\n call return_value%create(nlat, nlon)\n\n end function gaussian_grid_constructor\n\n subroutine assert_init_gaussian_grid(self, routine)\n\n ! Dummy arguments\n class(GaussianGrid), intent(inout) :: self\n character(len=*), intent(in) :: routine\n\n ! Check if object is usable\n select type(self)\n class is (GaussianGrid)\n if (.not.self%initialized) then\n write (stderr, '(a)') &\n 'Uninitialized object of class(GaussianGrid) in '//routine\n end if\n end select\n\n end subroutine assert_init_gaussian_grid\n\n subroutine copy_gaussian_grid(self, other)\n\n ! Dummy arguments\n class(GaussianGrid), intent(out) :: self\n class(GaussianGrid), intent(in) :: other\n\n ! Check if object is usable\n if (.not.other%initialized) then\n error stop 'Uninitialized object of class(GaussianGrid): '&\n //'in assignment (=) '\n end if\n\n ! Make copies\n self%initialized = other%initialized\n self%NUMBER_OF_LONGITUDES = other%NUMBER_OF_LONGITUDES\n self%NUMBER_OF_LATITUDES = other%NUMBER_OF_LATITUDES\n self%LONGITUDINAL_MESH = other%LONGITUDINAL_MESH\n self%latitudes = other%latitudes\n self%longitudes = other%longitudes\n self%gaussian_weights = other%gaussian_weights\n self%grid_type = other%grid_type\n\n end subroutine copy_gaussian_grid\n\n subroutine create_gaussian_grid(self, nlat, nlon)\n\n ! Dummy arguments\n class(GaussianGrid), intent(inout) :: self\n integer(ip), intent(in) :: nlat ! number of latitudinal points 0 <= theta <= pi\n integer(ip), intent(in) :: nlon ! number of longitudinal points 0 <= phi <= 2*pi\n\n ! Ensure that object is usable\n call self%destroy()\n\n ! Set contants\n self%NUMBER_OF_LATITUDES = nlat\n self%NUMBER_OF_LONGITUDES = nlon\n\n ! Set the gaussian grid type\n allocate (self%grid_type, source='gaussian')\n\n ! Set longitudinal grid: 0 <= phi <= 2*pi\n call self%get_equally_spaced_longitudes(nlon, self%longitudes)\n\n ! Set latitudinal grid: 0 <= theta <= pi\n call self%get_latitudes_and_gaussian_weights(nlat, self%latitudes, self%gaussian_weights)\n\n ! Set initialization flag\n self%initialized = .true.\n\n end subroutine create_gaussian_grid\n\n subroutine destroy_gaussian_grid(self)\n\n ! Dummy arguments\n class(GaussianGrid), intent(inout) :: self\n\n ! Check initialization flag\n if (.not.self%initialized) return\n\n ! Release memory\n if (allocated(self%gaussian_weights)) deallocate (self%gaussian_weights)\n\n call self%destroy_grid()\n\n ! Reset initialization flag\n self%initialized = .false.\n\n end subroutine destroy_gaussian_grid\n\n subroutine get_latitudes_and_gaussian_weights(nlat, gaussian_latitudes, gaussian_weights)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat ! number of latitudinal points\n real(wp), allocatable, intent(out) :: gaussian_latitudes(:) ! latitudinal points: 0 <= theta <= pi\n real(wp), allocatable, intent(out) :: gaussian_weights(:)\n\n ! Local variables\n integer(ip) :: error_flag\n\n ! Check input argument\n if (nlat <= 0) then\n error stop 'Object of class(GaussianGrid): '&\n //'invalid argument nlat <= 0 '&\n //'in get_equally_spaced_latitudes'\n end if\n\n ! Allocate memory\n allocate (gaussian_latitudes(nlat))\n allocate (gaussian_weights(nlat))\n\n ! Compute gaussian weights and latitudes\n call compute_gaussian_latitudes_and_weights( &\n nlat, gaussian_latitudes, gaussian_weights, error_flag)\n\n ! Address error flag\n select case (error_flag)\n case(0)\n return\n case(1)\n error stop 'Object of class(GaussianGrid) '&\n //'fails to satisfy nlat >= 0 '&\n //'in get_latitudes_and_gaussian_weights'\n case default\n error stop 'Object of class(GaussianGrid): '&\n //'undetermined error in '&\n //'get_latitudes_and_gaussian_weights'\n end select\n\n end subroutine get_latitudes_and_gaussian_weights\n\n subroutine unformatted_print(self, header)\n\n ! Dummy arguments\n class(GaussianGrid), intent(inout) :: self\n character(len=*), intent(in) :: header\n\n ! Local variables\n integer(ip) :: file_unit\n\n ! Check if object is usable\n call self%assert_initialized('unformatted_print')\n\n ! Write latitudes and longitudes\n call self%print_to_unformatted_binary_files(header)\n\n ! Write gaussian weights\n associate (wts => self%gaussian_weights)\n open( newunit=file_unit, &\n file=header//'gaussian_weights.dat', &\n status='replace', form='unformatted', &\n action='write', access='stream')\n write (file_unit) wts\n close( file_unit)\n end associate\n\n end subroutine unformatted_print\n\nend module type_GaussianGrid\n", "meta": {"hexsha": "c14fcefaa824d3543ca2dd7bc1a9d0df106fed05", "size": 6961, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/type_GaussianGrid.f90", "max_stars_repo_name": "jlokimlin/spherepack4.1", "max_stars_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-06-28T14:01:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T21:59:28.000Z", "max_issues_repo_path": "src/type_GaussianGrid.f90", "max_issues_repo_name": "jlokimlin/spherepack4.1", "max_issues_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2016-05-07T23:00:35.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-22T23:52:30.000Z", "max_forks_repo_path": "src/type_GaussianGrid.f90", "max_forks_repo_name": "jlokimlin/spherepack4.1", "max_forks_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-06-28T14:03:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T12:53:54.000Z", "avg_line_length": 32.8349056604, "max_line_length": 108, "alphanum_fraction": 0.6302255423, "num_tokens": 1555, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619091240701, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.6815923840348925}} {"text": "! Copyright (c) 2015 Alex Kramer \n! See the LICENSE.txt file in the top-level directory of this distribution.\n\n! Assorted numerical helper functions\n! Note: This is a program-independent module\nmodule numerics\n use globvars, only: dp\n\n implicit none\n\n private\n\n public :: numerics_linspace\n public :: numerics_d1\n public :: numerics_d2\n public :: numerics_rk4\n public :: numerics_cmplx_phase\n public :: numerics_trapz\n\ncontains\n\n ! Populate an array with linearly-spaced values between x_min and x_max\n !\n ! x_min :: minimum array value\n ! x_max :: maximum array value\n ! x_arr(:) :: array to populate, must already be allocated\n ! dx :: step size of `x_arr(:)`, given its size and `x_min`, `x_max`\n subroutine numerics_linspace(x_min, x_max, x_arr, dx)\n\n real(dp), intent(in) :: x_min, x_max\n real(dp), intent(out) :: x_arr(:)\n real(dp), intent(out) :: dx\n\n integer :: i_x, n_x\n\n n_x = size(x_arr)\n dx = (x_max - x_min) / n_x\n\n do i_x = 1, n_x\n x_arr(i_x) = x_min + i_x * dx\n end do\n\n end subroutine numerics_linspace\n\n ! Calculate the 1st derivative of a complex array-valued function with\n ! respect to a real-valued coordinate with constant spacing:\n !\n ! f'(x) ~= (f(x + dx) - f(x - dx)) / (2 dx)\n !\n ! arr :: function array\n ! d_arr :: array to populate\n ! dx :: coordinate spacing\n subroutine numerics_d1(arr, d_arr, dx)\n\n complex(dp), intent(in) :: arr(:)\n complex(dp), intent(inout) :: d_arr(:)\n real(dp), intent(in) :: dx\n integer :: i_x, n_x\n real(dp) :: scale\n\n n_x = size(arr)\n scale = 1.0_dp / (2.0_dp * dx)\n\n ! Special edge cases - we assume the grid is fine enough and the function\n ! is smooth enough that this is accurate enough. For the left case:\n !\n ! f(x + h) = arr(2), f(x - h) = arr(1)\n !\n ! For the right case:\n !\n ! f(x + h) = arr(n), f(x - h) = arr(n - 1)\n d_arr(1) = arr(2) - arr(1)\n do i_x = 2, n_x - 1\n d_arr(i_x) = arr(i_x + 1) - arr(i_x - 1)\n end do\n d_arr(n_x) = arr(n_x) - arr(n_x - 1)\n\n d_arr(:) = scale * d_arr(:)\n\n end subroutine numerics_d1\n\n ! Calculate the 2nd derivative of a complex array-valued function with\n ! respect to a real-valued coordinate with constant spacing:\n !\n ! f''(x) ~= (f(x - dx) - 2 f(x) + f(x + dx)) / (dx**2)\n !\n ! arr :: function array\n ! d2_arr :: array to populate\n ! dx :: coordinate spacing\n subroutine numerics_d2(arr, d2_arr, dx)\n\n complex(dp), intent(in) :: arr(:)\n complex(dp), intent(inout) :: d2_arr(:)\n real(dp), intent(in) :: dx\n integer :: i_x, n_x\n real(dp) :: scale\n\n n_x = size(arr)\n scale = 1.0_dp / dx**2\n\n ! Special edge cases - we assume the grid is fine enough and the function\n ! is smooth enough that this is accurate enough. For the left case:\n !\n ! f(x + h) = arr(2), f(x - h) = arr(1)\n !\n ! For the right case:\n !\n ! f(x + h) = arr(n), f(x - h) = arr(n - 1)\n d2_arr(1) = arr(1) + arr(2)\n do i_x = 2, n_x - 1\n d2_arr(i_x) = arr(i_x - 1) - 2 * arr(i_x) + arr(i_x + 1)\n end do\n d2_arr(n_x) = arr(n_x) + arr(n_x - 1)\n\n d2_arr(:) = scale * d2_arr(:)\n\n end subroutine numerics_d2\n\n\n ! 4th order Runge-Kutta propagator for the first order system of differential\n ! equations dy/dt = f(t, y)\n !\n ! f :: differential equation dy/dt = f(y, t) that returns values of the same\n ! dimension as y\n ! y :: current state array\n ! t :: current time parameter\n ! dt :: time step\n !\n ! Note that the state array is overwritten during propagation.\n subroutine numerics_rk4(f, y, t, dt)\n complex(dp), intent(inout) :: y(:)\n real(dp), intent(in) :: t\n real(dp), intent(in) :: dt\n\n complex(dp), dimension(size(y)) :: k1, k2, k3, k4\n\n ! Explicit interface for external differential equation system\n interface\n\n function f(y, t) result(val)\n import dp\n real(dp) :: t\n complex(dp) :: y(:), val(size(y))\n end function f\n\n end interface\n\n k1 = f(y, t)\n k2 = f(y + dt / 2 * k1, t + dt / 2)\n k3 = f(y + dt / 2 * k2, t + dt / 2)\n k4 = f(y + dt * k3, t + dt)\n\n y = y + dt / 6 * (k1 + 2 * k2 + 2 * k3 + k4)\n\n end subroutine numerics_rk4\n\n ! Get the phase of a complex number z = A exp(i phi), where A determines the\n ! magnitude, and phi determines the phase angle.\n real(dp) function numerics_cmplx_phase(z) result(val)\n complex(dp), intent(in) :: z\n\n val = atan2(aimag(z),real(z))\n\n end function numerics_cmplx_phase\n\n real(dp) function numerics_trapz(f_arr, dx) result(val)\n real(dp), intent(in) :: f_arr(:)\n real(dp), intent(in) :: dx\n\n integer :: i_x\n real(dp) :: trapz_cnst\n\n trapz_cnst = dx / 2.0_dp\n val = 0.0_dp\n\n do i_x = 1, size(f_arr) - 1\n val = val + (f_arr(i_x) + f_arr(i_x + 1))\n end do\n\n val = val * trapz_cnst\n\n end function numerics_trapz\n\nend module numerics\n", "meta": {"hexsha": "3d690045b818e505fd2f81e9bac46d18be02a0ba", "size": 4901, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "numerics.f90", "max_stars_repo_name": "kramer314/2d-vd-test", "max_stars_repo_head_hexsha": "a6a5a349fda3443d9a76b1553a54246dde75bd0b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "numerics.f90", "max_issues_repo_name": "kramer314/2d-vd-test", "max_issues_repo_head_hexsha": "a6a5a349fda3443d9a76b1553a54246dde75bd0b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "numerics.f90", "max_forks_repo_name": "kramer314/2d-vd-test", "max_forks_repo_head_hexsha": "a6a5a349fda3443d9a76b1553a54246dde75bd0b", "max_forks_repo_licenses": ["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.4918918919, "max_line_length": 79, "alphanum_fraction": 0.598857376, "num_tokens": 1609, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127678225575, "lm_q2_score": 0.7981867873410141, "lm_q1q2_score": 0.6815818888177605}} {"text": "c # ----------------------------------------------------------------------------------\nc # Output and diagnostics\nc # ----------------------------------------------------------------------------------\n subroutine user_fort_conservation_check(mx,my,mbc,meqn,\n & dx,dy,area,q,sum)\n implicit none\n\n integer mx,my,mbc,meqn\n double precision dx, dy, dxdy\n double precision sum(meqn)\n double precision q(1-mbc:mx+mbc,1-mbc:my+mbc,meqn)\n\n include 'fclaw2d_metric_terms.i'\n\n integer i,j,m\n integer*8 cont, get_context\n logical fclaw2d_map_is_used\n\n cont = get_context()\n\n dxdy = dx*dy\n do m = 1,meqn\n if (fclaw2d_map_is_used(cont)) then\n do j = 1,my\n do i = 1,mx\n sum(m) = sum(m) + q(i,j,m)*area(i,j)\n enddo\n enddo\n else\n do j = 1,my\n do i = 1,mx\n sum(m) = sum(m) + q(i,j,m)*dx*dy\n enddo\n enddo\n endif\n enddo\n\n end\n\nc # Compute area of a patch\n double precision function\n & fc2d_clawpack46_fort_compute_patch_area\n & (mx,my, mbc,dx,dy,area)\n implicit none\n\n integer mx,my, mbc\n double precision dx, dy\n double precision sum\n\n include 'fclaw2d_metric_terms.i'\n\n integer i,j,m\n integer*8 cont, get_context\n logical fclaw2d_map_is_used\n\n cont = get_context()\n\n if (fclaw2d_map_is_used(cont)) then\n sum = 0\n do j = 1,my\n do i = 1,mx\n sum = sum + area(i,j)\n enddo\n enddo\n else\n sum = dx*dy*mx*my\n endif\n\n fc2d_clawpack46_fort_compute_patch_area = sum\n\n end\n\n\n subroutine user_fort_compute_error_norm(mx,my,mbc,\n & meqn,dx,dy,area,error,error_norm)\n implicit none\n\n integer mx,my,mbc,meqn\n double precision dx, dy, dxdy, eij\n double precision error_norm(meqn,3)\n double precision error(1-mbc:mx+mbc,1-mbc:my+mbc,meqn)\n\n include 'fclaw2d_metric_terms.i'\n\n integer i,j,m\n integer*8 cont, get_context\n logical fclaw2d_map_is_used\n\n cont = get_context()\n\nc # error_norm(:) comes in with values; do not initialize it here!\n dxdy = dx*dy\n do m = 1,meqn\n if (fclaw2d_map_is_used(cont)) then\n do j = 1,my\n do i = 1,mx\n eij = abs(error(i,j,m))\n error_norm(m,1) = error_norm(m,1) +\n & eij*area(i,j)\n error_norm(m,2) = error_norm(m,2) +\n & eij**2*area(i,j)\n error_norm(m,3) = max(eij,error_norm(m,3))\n enddo\n enddo\n else\n do j = 1,my\n do i = 1,mx\n eij = abs(error(i,j,m))\n error_norm(m,1) = error_norm(m,1) +\n & eij*dxdy\n error_norm(m,2) = error_norm(m,2) +\n & eij**2*dxdy\n error_norm(m,3) = max(eij,error_norm(m,3))\n enddo\n enddo\n endif\n enddo\n\n end\n", "meta": {"hexsha": "2b25e671ddef1aa0d08fcc61e72448044eb82fa4", "size": 3175, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/user_fortran_source2d/diagnostics.f", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2017-09-26T13:39:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:56:23.000Z", "max_issues_repo_path": "src/user_fortran_source2d/diagnostics.f", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 75, "max_issues_repo_issues_event_min_datetime": "2017-08-02T19:56:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T12:36:32.000Z", "max_forks_repo_path": "src/user_fortran_source2d/diagnostics.f", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-02-21T00:10:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T19:08:36.000Z", "avg_line_length": 26.4583333333, "max_line_length": 89, "alphanum_fraction": 0.4749606299, "num_tokens": 909, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127566694178, "lm_q2_score": 0.798186787341014, "lm_q1q2_score": 0.6815818799154716}} {"text": " program choles\n integer n\n real*8 a(n,n), p(n), x\n integer i, j, k\n do i=1,n\n x = a(i,i)\n do k = 1, i-1\n x = x - a(i,k)**2\n end do\n p(i) = 1.0/sqrt(x)\n do j = i+1, n\n x = a(i,j)\n do k=1,i-1\n x = x - a(j,k) * a(i,k)\n end do\n a(j,i) = x * p(i)\n end do\n end do\n end\n \n", "meta": {"hexsha": "043538046f3cd78de5d82888b98586df675ef96b", "size": 423, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "packages/PIPS/validation/Static_controlize/choles.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/Static_controlize/choles.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/Static_controlize/choles.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.1428571429, "max_line_length": 38, "alphanum_fraction": 0.2955082742, "num_tokens": 149, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517043, "lm_q2_score": 0.7981867801399694, "lm_q1q2_score": 0.681581870798978}} {"text": "module m\r\nimplicit none\r\ncontains\r\nfunction pos_first_positive_each_row(x) result(ipos)\r\n! return vector with position of first positive \r\n! element in each row\r\nreal, intent(in) :: x(:,:)\r\ninteger :: ipos(size(x,1))\r\ninteger :: i,j\r\nipos = 0\r\niloop: do i=1,size(x,1)\r\n jloop: do j=1,size(x,2)\r\n if (x(i,j) > 0.0) then\r\n ipos(i) = j\r\n cycle iloop ! or write exit jloop\r\n end if\r\n end do jloop\r\nend do iloop\r\nend function pos_first_positive_each_row \r\nend module m\r\n!\r\nprogram test_cycle\r\nuse m\r\ninteger, parameter :: n1 = 5, n2 = 3\r\nreal :: x(n1,n2)\r\ninteger :: i,ipos_positive(n1),j\r\ncall random_number(x)\r\nx = x - 0.5\r\nipos_positive = pos_first_positive_each_row(x)\r\nprint \"(*(a8))\",\"i\",\"x(i,:)\"\r\ndo i=1,n1\r\n print \"(i8,*(f8.2))\",ipos_positive(i),x(i,:)\r\nend do\r\n! print square root of first positive element in each row\r\nprint \"(/,2a3,*(a14))\",\"i\",\"j\",\"x(i,j)\",\"sqrt(x(i,j))\"\r\ndo i=1,n1\r\n j = ipos_positive(i)\r\n if (j == 0) cycle ! avoid computing sqrt of negative #\r\n print \"(2i3,*(f14.2))\",i,j,x(i,j),sqrt(x(i,j))\r\nend do\r\nend program test_cycle\r\n! sample output:\r\n! i x(i,:)\r\n! 2 -0.23 0.28 -0.48\r\n! 2 -0.37 0.27 -0.09\r\n! 0 -0.02 -0.06 -0.43\r\n! 1 0.07 -0.20 -0.25\r\n! 0 -0.17 -0.16 -0.13\r\n! \r\n! i j x(i,j) sqrt(x(i,j))\r\n! 1 2 0.28 0.53\r\n! 2 2 0.27 0.52\r\n! 4 1 0.07 0.27\r\n", "meta": {"hexsha": "ba693505fa5c0d5d9c29ef304c41abc264887f8a", "size": 1482, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "cycle.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": "cycle.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": "cycle.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": 27.4444444444, "max_line_length": 58, "alphanum_fraction": 0.5269905533, "num_tokens": 554, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517043, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.681581864649914}} {"text": "!\n! CalculiX - A 3-dimensional finite element program\n! Copyright (C) 1998-2015 Guido Dhondt\n! \n! This program is free software; you can redistribute it and/or\n! modify it under the terms of the GNU General Public License as\n! published by the Free Software Foundation(version 2);\n! \n! \n! This program is distributed in the hope that it will be useful,\n! but WITHOUT ANY WARRANTY; without even the implied warranty of \n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \n! GNU General Public License for more details.\n! \n! You should have received a copy of the GNU General Public License\n! along with this program; if not, write to the Free Software\n! Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n! \n subroutine tt_calc(xflow,Tt,Pt,kappa,r,a,Ts,icase,iflag)\n! \n! this subroutine solves the implicit equation\n! f=xflow*dsqrt(Tt)/(a*Pt)-C*(TtdT)**expon*(Ttdt-1)**0.5d0\n! in order to find Tt when ts , xflow, pt and a are given\n!\n! author: Yannick Muller\n! \n implicit none\n!\n integer inv,icase,i,iflag\n! \n real*8 xflow,Tt,Pt,Ts,kappa,r,f,df,a,expon,Tt_old,C,TtzTs,\n & deltaTt,TtzTs_crit, Qred_crit,Qred,h1,h2,h3,Tt_crit\n! \n expon=-0.5d0*(kappa+1.d0)/(kappa-1.d0)\n! \n C=dsqrt(2.d0/r*kappa/(kappa-1.d0))\n! \n! f=xflow*dsqrt(Tt)/(a*Pt)-C*(TtdT)**expon*(Ttdt-1)**0.5d0\n!\n! df=-C*Ttdt**expon*(expon/Ts*(TtdT-1)**0.5d0\n! & -0.5d0*TtdT/Ts*(TtdT-1.d0)**(-0.5d0))\n! \n Tt_old=Tt\n! \n!\n if(xflow.lt.0d0) then \n inv=-1\n else\n inv=1\n endif\n! \n if(dabs(xflow).le.1e-9) then\n Tt=Ts\n return\n endif\n!\n Qred=abs(xflow)*dsqrt(Tt)/(a*Pt)\n!\nc write(*,*) 'epsilon',(Qred/C)**2\n!\n! optimised estimate of T static\n!\n Tt=Ts*(1+(Qred**2/C**2))\n! \n! adiabatic\n! \n if(icase.eq.0) then\n!\n TtzTs_crit=(kappa+1.d0)/2.d0\n! \n! isothermal\n!\n else\n! \n! if(iflag.ne.3) then \n TtzTs_crit=(1d0+(kappa-1.d0)/(2.d0*kappa))\n if(iflag.ne.3) then\n Tt_crit=(A*pt/(dabs(xflow))*C*Ttzts_crit**expon*\n & (TtzTs_crit-1)**0.5d0)**2\n! if(iflag.ne.3) then\n if(Tt.gt.Tt_crit) then\n Tt=Tt_crit\n endif\n endif\n! Tt=Tt_crit\n! Qred=abs(xflow)*dsqrt(Tt)/(a*Pt)\n!\n endif\n!\n Qred_crit=C*(TtzTs_crit)**expon*(Ttzts_crit-1.d0)**0.5d0\n! \n! \n if(Qred.ge.Qred_crit) then\n! \n Tt=Ts*TtzTs_crit\n! \n return\n! \n endif\n i=0\n! \n do \n i=i+1\n Ttzts=Tt/Ts\n h1=Ttzts-1.d0\n h2= dsqrt(h1)\n h3=Ttzts**expon\n! \n f=C*h2*h3\n! \n df=0.5*inv*xflow/(A*Pt*dsqrt(Tt))\n & -1/Tt*C*h2*h3*(expon+0.5d0*(h1)**(-1))\n!\n f=Qred-f\n deltaTt=-f/df\nc write(*,*) 'deltaTs=',deltaTs\n! \n Tt=Tt+deltaTt\nc write(*,*) 'Ts',Ts\n! \n if( (((dabs(Tt-Tt_old)/tt_old).le.1.E-8))\n & .or.((dabs(Tt-Tt_old)).le.1.E-10) \n & .or.((f.le.1E-5).and.(deltaTt.lt.1E-3))) then\nc write(*,*) 'f=',f\nc write(*,*) 'Ts=',Ts\nc write(*,*) 'i',i\nc$$$c write(*,*) ''\nc$$$ write(*,*) 'f',f\nc$$$ write(*,*) ''\nc$$$ write(*,*) 'Ts',Ts\nc$$$ write(*,*) 'Tt',Tt\nc$$$ write(*,*) ''\n Qred_crit=C*(TtzTs_crit)**expon*(Ttzts_crit-1.d0)**0.5d0\n Qred=abs(xflow)*dsqrt(Tt)/(a*Pt)\n! \n if((Qred.ge.Qred_crit).and.(iflag.eq.3)) then\n! \n Tt=Ts*TtzTs_crit\n! \n endif\n exit\n else if((i.gt.40)) then\n Tt=0.99*Ts*TtzTs_crit\nc$$$ Tt=1.2*Ts\nc$$$ write(*,*) 'Break'\nc$$$ write(*,*) 'f',f\nc$$$ write(*,*) 'Ts',Ts\nc$$$ write(*,*) 'Tt',Tt\nc$$$ write(*,*) ''\n exit\n endif\n Tt_old=Tt\n enddo\n! \nC write(*,*) 'end of ts_clac.f'\nc write(*,*) ''\n return\n end\n \n \n \n", "meta": {"hexsha": "af5d9fea8c7e425ff92c2124f955981a91eeb040", "size": 4193, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ccx_prool/CalculiX/ccx_2.9/src/tt_calc.f", "max_stars_repo_name": "alleindrach/calculix-desktop", "max_stars_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ccx_prool/CalculiX/ccx_2.9/src/tt_calc.f", "max_issues_repo_name": "alleindrach/calculix-desktop", "max_issues_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ccx_prool/CalculiX/ccx_2.9/src/tt_calc.f", "max_forks_repo_name": "alleindrach/calculix-desktop", "max_forks_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.8827160494, "max_line_length": 71, "alphanum_fraction": 0.483901741, "num_tokens": 1481, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087926320945, "lm_q2_score": 0.7341195327172401, "lm_q1q2_score": 0.6815630290176503}} {"text": "subroutine getGamma(x, T, n, m, amk, vk, Rk, Qk, gamma1)\n implicit none\n\n integer, intent(in) :: n, m\n real(8), dimension(n), intent(in) :: x\n real(8), dimension(m), intent(in) :: Rk, Qk\n integer, dimension(n,m), intent(in) :: vk\n real(8), dimension(m,m), intent(in) ::amk\n real(8), intent(in) :: T\n real(8), dimension(n), intent(out) :: gamma1\n integer :: ii, kk\n real(8) :: sum_rx, sum_qx\n\n real(8) :: r(n), q(n), e(m,n), beta(n,m), theta(m), s(m),L(n),J(n),ln_gamma_C(n), ln_gamma_R(n), tau(m,m)\n\n tau = exp(-amk/T) \n\n do ii=1,n\n r(ii) = sum(vk(ii,:)*Rk(:))\n q(ii) = sum(vk(ii,:)*Qk(:))\n enddo\n\n sum_rx = sum(x*r)\n sum_qx = sum(x*q)\n\n ! r, q\n do ii=1,n \n e(:, ii) = vk(ii,:)*Qk(:)/q(ii)\n enddo\n\n ! beta\n do ii=1, n\n do kk=1, m\n beta(ii,kk) = sum(e(:,ii)*tau(:,kk))\n end do\n end do\n\n do kk=1,m\n theta(kk) = sum(x*q*e(kk,:))\n end do\n theta = theta/sum_qx\n\n do kk=1,m\n s(kk) = sum(theta*tau(:,kk))\n end do\n\n J = r/sum_rx\n L = q/sum_qx\n ln_gamma_C = 1.0_8 - J + log(J) - 5.0_8*q*(1.-J/L+log(J/L))\n\n do ii=1,n\n ln_gamma_R(ii) = q(ii)*(1.0_8 - sum(theta*beta(ii,:)/s - e(:,ii)*log(beta(ii,:)/s)))\n end do\n\n gamma1 = exp(ln_gamma_C + ln_gamma_R)\n\nend subroutine\n\nsubroutine getGammaTrange(x, T, l, n, m, amk, vk, Rk, Qk, gammas)\n implicit none\n integer, intent(in) :: n, m,l\n real(8), dimension(n), intent(in) :: x\n real(8), dimension(m), intent(in) :: Rk, Qk\n integer, dimension(n,m), intent(in) :: vk\n real(8), dimension(m,m), intent(in) ::amk\n real(8), intent(in) :: T(l)\n real(8), dimension(l,n), intent(out) :: gammas\n integer :: ii\n do ii=1, l\n call getGamma(x,T(ii),n,m,amk,vk,Rk,Qk, gammas(ii,:))\n end do\nend subroutine", "meta": {"hexsha": "22517dd7586a2146f2acc573846549d5346732c7", "size": 1829, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Sindri/fortran/UNIFAC.f90", "max_stars_repo_name": "mrcsbrn/TCC_software", "max_stars_repo_head_hexsha": "17a5335aed17d4740c3bbd0ef828b0fc5dcea1da", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2019-10-17T02:01:51.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:39:34.000Z", "max_issues_repo_path": "Sindri/fortran/UNIFAC.f90", "max_issues_repo_name": "mrcsbrn/TCC_software", "max_issues_repo_head_hexsha": "17a5335aed17d4740c3bbd0ef828b0fc5dcea1da", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-07-25T22:16:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-03-28T01:59:59.000Z", "max_forks_repo_path": "Sindri/fortran/UNIFAC.f90", "max_forks_repo_name": "mrcsbrn/TCC_software", "max_forks_repo_head_hexsha": "17a5335aed17d4740c3bbd0ef828b0fc5dcea1da", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-07-15T18:19:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-24T08:06:24.000Z", "avg_line_length": 25.4027777778, "max_line_length": 109, "alphanum_fraction": 0.5188627665, "num_tokens": 692, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896824119663, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6815449104739056}} {"text": "program MaxSubSeq\n implicit none\n\n integer, parameter :: an = 11\n integer, dimension(an) :: a = (/ -1, -2, 3, 5, 6, -2, -1, 4, -4, 2, -1 /)\n\n integer, dimension(an,an) :: mix\n integer :: i, j\n integer, dimension(2) :: m\n\n forall(i=1:an,j=1:an) mix(i,j) = sum(a(i:j))\n m = maxloc(mix)\n ! a(m(1):m(2)) is the wanted subsequence\n print *, a(m(1):m(2))\n\nend program MaxSubSeq\n", "meta": {"hexsha": "bf37b7f4d380d1848d7000f048b00ba73790ce1a", "size": 382, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Greatest-subsequential-sum/Fortran/greatest-subsequential-sum.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-subsequential-sum/Fortran/greatest-subsequential-sum.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-subsequential-sum/Fortran/greatest-subsequential-sum.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.4705882353, "max_line_length": 75, "alphanum_fraction": 0.5732984293, "num_tokens": 157, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896845856297, "lm_q2_score": 0.7401743505760728, "lm_q1q2_score": 0.6815449068053154}} {"text": "! FFLAGS=\"-fopenmp -fPIC -Ofast -ffree-line-length-none\" f2py-2.7 -c -m TS_mcm_code_full TS_mcm_code_full.f90 wigner3j_sub.f -lgomp\r\n! scinet: FFLAGS=\"-openmp -Ofast -fPIC -xhost\" f2py --fcompiler=intelem --noopt -c -m TS_mcm_code_full TS_mcm_code_full.f90 wigner3j_sub.f -liomp5\r\n\r\nsubroutine calc_mcm(cl,cl_cross,cl_pol,wl, mcm, mcm_p, mcm_pp, mcm_mm)\r\n implicit none\r\n real(8), intent(in) :: cl(:),cl_cross(:),cl_pol(:),wl(:)\r\n real(8), intent(inout) :: mcm(:,:),mcm_p(:,:),mcm_pp(:,:),mcm_mm(:,:)\r\n real(8), parameter :: pi = 3.14159265358979323846264d0\r\n integer :: l1, l2, l3, info, nlmax, lmin, lmax, i\r\n real(8) :: l1f(2), fac\r\n real(8) :: thrcof0(2*size(mcm,1)),thrcof1(2*size(mcm,1)) \r\n nlmax = size(mcm,1)-1\r\n\r\n ! l2,l3 are running over 2,lmax, note that it's tempting to make them run over 0,lmax but the wigner3j associated with polarisation\r\n ! crash for l2,l3 <0 ( |l2-m2| & |l3-m3| has to be greater or equal to zero)\r\n ! mcm(l2=2,l3=2)=mcm(1,1)\r\n ! l1 run in all the non zero wigner 3j it can start at 0 so cl(l=n)=cl(n+1) so cl(l=0)=cl(1)\r\n\r\n !$omp parallel do private(l3,l2,l1,fac,info,l1f,thrcof0,thrcof1,lmin,lmax,i) schedule(dynamic)\r\n do l1 = 2, nlmax\r\n fac=(2*l1+1)/(4*pi)*wl(l1+1)\r\n do l2 = 2, nlmax\r\n\r\n call drc3jj(dble(l1),dble(l2),0d0,0d0,l1f(1),l1f(2),thrcof0, size(thrcof0),info)\r\n call drc3jj(dble(l1),dble(l2),-2d0,2d0,l1f(1),l1f(2),thrcof1, size(thrcof1),info)\r\n\r\n lmin=INT(l1f(1))\r\n lmax=MIN(nlmax,INT(l1f(2)))\r\n\r\n do l3=lmin,lmax\r\n i = l3-lmin+1\r\n mcm(l1-1,l2-1) =mcm(l1-1,l2-1)+ fac*(cl(l3+1)*thrcof0(i)**2d0)\r\n mcm_p(l1-1,l2-1) =mcm_p(l1-1,l2-1)+ fac*(cl_cross(l3+1)*thrcof0(i)*thrcof1(i))\r\n mcm_pp(l1-1,l2-1) =mcm_pp(l1-1,l2-1)+ fac*(cl_pol(l3+1)*thrcof1(i)**2*(1+(-1)**(l1+l2+l3))/2)\r\n mcm_mm(l1-1,l2-1) =mcm_mm(l1-1,l2-1)+ fac*(cl_pol(l3+1)*thrcof1(i)**2*(1-(-1)**(l1+l2+l3))/2)\r\n \r\n end do\r\n end do\r\n end do\r\n\r\nend subroutine\r\n\r\nsubroutine bin_mcm(mcm, binLo,binHi, binsize, mbb)\r\n ! Bin the given mode coupling matrix mcm(0:lmax,0:lmax) into\r\n ! mbb(nbin,nbin) using bins of the given binsize\r\n implicit none\r\n real(8), intent(in) :: mcm(:,:)\r\n integer, intent(in) :: binLo(:),binHi(:),binsize(:)\r\n real(8), intent(inout) :: mbb(:,:)\r\n integer :: b1, b2, l1, l2, lmax\r\n lmax = size(mcm,1)-1\r\n mbb = 0\r\n \r\n do b2=1,size(mbb,1)\r\n do b1=1,size(mbb,1)\r\n do l2=binLo(b2),binHi(b2)\r\n do l1=binLo(b1),binHi(b1)\r\n mbb(b1,b2)=mbb(b1,b2) + mcm(l1-1,l2-1)!*l2*(l2+1d0)/(l1*(l1+1d0)) !*mcm(l2-1,l3-1)\r\n end do\r\n end do\r\n mbb(b1,b2) = mbb(b1,b2) / binsize(b2)\r\n\r\n end do\r\n end do\r\nend subroutine\r\n\r\nsubroutine binning_matrix(mcm, binLo,binHi, binsize, bbl)\r\n implicit none\r\n real(8), intent(in) :: mcm(:,:)\r\n integer(8), intent(in) :: binLo(:),binHi(:),binsize(:)\r\n real(8), intent(inout) :: bbl(:,:)\r\n integer(8) :: b2, l1, l2,lmax\r\n\r\n lmax = size(mcm,1)-1\r\n ! mcm is transposed\r\n ! compute \\sum_{l'} M_l'l\r\n do l1=2,lmax\r\n do b2=1,size(binLo)\r\n do l2=binLo(b2),binHi(b2)\r\n bbl(l1-1,b2)=bbl(l1-1,b2)+mcm(l1-1,l2-1)\r\n end do\r\n bbl(l1-1,b2)=bbl(l1-1,b2)/(binsize(b2)*1d0)\r\n end do\r\n end do\r\nend subroutine\r\n\r\n\r\n\r\n", "meta": {"hexsha": "76a8437d48ecac40152325b762d37319f814a812", "size": 3501, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "pitas/mcm_core/mcm_core.f90", "max_stars_repo_name": "dwhan89/pitas", "max_stars_repo_head_hexsha": "5da2d5fe84714e082e76a8b50c31f6faebeb8579", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-02-26T16:08:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-08T01:12:11.000Z", "max_issues_repo_path": "pitas/mcm_core/mcm_core.f90", "max_issues_repo_name": "dwhan89/pitas", "max_issues_repo_head_hexsha": "5da2d5fe84714e082e76a8b50c31f6faebeb8579", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2018-07-24T18:10:14.000Z", "max_issues_repo_issues_event_max_datetime": "2019-07-30T13:37:03.000Z", "max_forks_repo_path": "pitas/mcm_core/mcm_core.f90", "max_forks_repo_name": "dwhan89/pitas", "max_forks_repo_head_hexsha": "5da2d5fe84714e082e76a8b50c31f6faebeb8579", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-07-30T04:58:14.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-30T04:58:14.000Z", "avg_line_length": 39.3370786517, "max_line_length": 147, "alphanum_fraction": 0.549842902, "num_tokens": 1421, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.920789673717312, "lm_q2_score": 0.7401743505760728, "lm_q1q2_score": 0.6815448987608654}} {"text": " subroutine sqrt_array(vect, vect_len, res)\n \n implicit none\n \n integer, intent(in) :: vect_len\n real(kind=8), intent(in) :: vect(vect_len)\n real(kind=8), intent(out) :: res(vect_len)\n \n integer :: i\n\n do i=1,vect_len\n res(i) = sqrt(vect(i))\n enddo \n\n\n end subroutine\n\n subroutine say_hello()\n\n write(*,*), \"Hello from Fortran!\"\n\n end subroutine\n\n", "meta": {"hexsha": "0b37768e57447596e0829f59878669621542fd05", "size": 471, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "pypkgexample/mymodule_fortran/hello_subr.f90", "max_stars_repo_name": "giadarol/hellofrom", "max_stars_repo_head_hexsha": "18f4030dc35bd4a7f61f4417f6fdc649f6ed0211", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "pypkgexample/mymodule_fortran/hello_subr.f90", "max_issues_repo_name": "giadarol/hellofrom", "max_issues_repo_head_hexsha": "18f4030dc35bd4a7f61f4417f6fdc649f6ed0211", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "pypkgexample/mymodule_fortran/hello_subr.f90", "max_forks_repo_name": "giadarol/hellofrom", "max_forks_repo_head_hexsha": "18f4030dc35bd4a7f61f4417f6fdc649f6ed0211", "max_forks_repo_licenses": ["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.625, "max_line_length": 57, "alphanum_fraction": 0.4925690021, "num_tokens": 114, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289387998695209, "lm_q2_score": 0.8221891327004132, "lm_q1q2_score": 0.6815444729264427}} {"text": " PROGRAM TASSIG\n PARAMETER (PI=3.14159265)\n TEST = 2.0* PI\n WRITE(*,*) TEST\n END\n", "meta": {"hexsha": "b1e4381e8e377f2aa0f8d8be73f02a22085cff0a", "size": 106, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/roseTests/astOutliningTests/parameter2.f", "max_stars_repo_name": "maurizioabba/rose", "max_stars_repo_head_hexsha": "7597292cf14da292bdb9a4ef573001b6c5b9b6c0", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/roseTests/astOutliningTests/parameter2.f", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/roseTests/astOutliningTests/parameter2.f", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 17.6666666667, "max_line_length": 31, "alphanum_fraction": 0.5, "num_tokens": 38, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.822189121808099, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.6815444673719089}} {"text": "program ch0513\n ! Binary Representation of Different Integer Kind\n ! Type Numbers\n use iso_fortran_env\n implicit none\n\n integer :: i, j\n integer(int8) :: i1\n integer(int16) :: i2\n integer(int32) :: i3\n character(32) :: i_in_bits = ' '\n\n print *, ' type in an integer '\n read *, i\n i1 = int(i,int8)\n i2 = int(i,int16)\n i3 = int(i,int32)\n\n do j = 0, 7\n if (btest(i1,j)) then\n i_in_bits(8-j:8-j) = '1'\n else\n i_in_bits(8-j:8-j) = '0'\n end if\n end do\n print *, ' 1 2 3'\n print *, '12345678901234567890123456789012'\n print *, i1\n print *, i_in_bits\n\n do j = 0, 15\n if (btest(i2,j)) then\n i_in_bits(16-j:16-j) = '1'\n else\n i_in_bits(16-j:16-j) = '0'\n end if\n end do\n print *, i2\n print *, i_in_bits\n\n do j = 0, 31\n if (btest(i3, j)) then\n i_in_bits(32-j:32-j) = '1'\n else\n i_in_bits(32-j:32-j) = '0'\n end if\n end do\n print *, i3\n print *, i_in_bits\nend program\n", "meta": {"hexsha": "d2c4b0a4cc1b209f16e65a251b92d12335e4aee8", "size": 1092, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ch05/ch0513.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": "ch05/ch0513.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": "ch05/ch0513.f90", "max_forks_repo_name": "hechengda/fortran", "max_forks_repo_head_hexsha": "44735609ece7995d049016f758590d710b8a4f15", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.4117647059, "max_line_length": 53, "alphanum_fraction": 0.489010989, "num_tokens": 377, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424528443251, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.681518470037146}} {"text": "program main5\r\n use Util\r\n use Func\r\n use Matrix\r\n use Calc\r\n use Plotlib\r\n implicit none\r\n\r\n double precision :: XMIN, XMAX, YMIN, YMAX\r\n\r\n! Command-line Args\r\n integer :: argc\r\n\r\n! ENABLE_DEBUG = .TRUE.\r\n\r\n! Random seed definition\r\n call init_random_seed()\r\n\r\n! Get Command-Line Args\r\n argc = iargc()\r\n\r\n if (argc == 0) then\r\n goto 100\r\n else\r\n goto 11\r\n end if\r\n\r\n! ====== Success ===================================\r\n10 call info(':: Sucesso ::')\r\n goto 1\r\n! ====== Errors ====================================\r\n11 call error('Este programa n\u00e3o aceita par\u00e2metross.')\r\n goto 1\r\n! ====== Finish ====================================\r\n1 stop\r\n! ==================================================\r\n\r\n100 goto 200\r\n\r\n200 call Q2\r\n goto 300\r\n\r\n300 call Q3\r\n goto 400\r\n\r\n400 call Q4\r\n goto 500\r\n\r\n500 call Q5\r\n goto 600\r\n\r\n600 call Q6\r\n goto 700\r\n\r\n700 call Q7\r\n goto 800\r\n\r\n800 call warn(ENDL//\":: Complmento ::\"//ENDL)\r\n call QE1; call QE2; call QE3;\r\n goto 10\r\n\r\n! ===============================\r\n\r\n contains\r\n\r\n subroutine Q2\r\n implicit none\r\n integer :: n = 10\r\n double precision :: a, b, s\r\n\r\n call info(\"2)\"//ENDL//F6_NAME)\r\n a = 0.0D0\r\n b = 1.0D0\r\n call info(\"[a, b] = [\"//DSTR(a)//\", \"//DSTR(b)//\"]\")\r\n call info(\":: Integra\u00e7\u00e3o Polinomial ::\")\r\n s = num_int(f6, a, b, n, kind=\"polynomial\")\r\n call blue(\"I1 = \u222bf(x) dx \u2248 \"//DSTR(s))\r\n call info(\":: Quadratura de Gauss-Legendre ::\")\r\n s = num_int(f6, a, b, n, kind=\"gauss-legendre\")\r\n call blue(\"I1 = \u222bf(x) dx \u2248 \"//DSTR(s))\r\n call info(\":: M\u00e9todo de Romberg ::\")\r\n s = num_int(f6, a, b, n, kind=\"romberg\")\r\n call blue(\"I1 = \u222bf(x) dx \u2248 \"//DSTR(s))\r\n\r\n a = 0.0D0\r\n b = 5.0D0\r\n call info(\"[a, b] = [\"//DSTR(a)//\", \"//DSTR(b)//\"]\")\r\n call info(\":: Integra\u00e7\u00e3o Polinomial ::\")\r\n s = num_int(f6, a, b, n, kind=\"polynomial\")\r\n call blue(\"I2 = \u222bf(x) dx \u2248 \"//DSTR(s))\r\n call info(\":: Quadratura de Gauss-Legendre ::\")\r\n s = num_int(f6, a, b, n, kind=\"gauss-legendre\")\r\n call blue(\"I2 = \u222bf(x) dx \u2248 \"//DSTR(s))\r\n call info(\":: M\u00e9todo de Romberg ::\")\r\n s = num_int(f6, a, b, n, kind=\"romberg\")\r\n call blue(\"I2 = \u222bf(x) dx \u2248 \"//DSTR(s))\r\n\r\n end subroutine\r\n\r\n subroutine Q3\r\n implicit none\r\n integer :: n\r\n double precision :: a, b, r\r\n double precision, dimension(INT_N) :: x\r\n double precision, dimension(4, INT_N) :: y\r\n\r\n type(StringArray), dimension(:), allocatable :: legend, with\r\n\r\n allocate(legend(4), with(4))\r\n\r\n legend(1)%str = 'Polinomial'\r\n legend(2)%str = 'Gauss-Legendre'\r\n legend(3)%str = 'Romberg'\r\n legend(4)%str = 'Adaptativo (Gauss)'\r\n\r\n with(1)%str = 'linespoints'\r\n with(2)%str = 'linespoints'\r\n with(3)%str = 'linespoints'\r\n with(4)%str = 'lines'\r\n\r\n a = 0.00D0\r\n b = 10.0D0\r\n\r\n call info(ENDL//\"3)\"//ENDL//F7_NAME)\r\n\r\n call info(\"[a, b] = [\"//DSTR(a)//\", \"//DSTR(b)//\"]\")\r\n\r\n INT_N = 128\r\n\r\n XMIN = 1.0D0\r\n XMAX = INT_N\r\n YMIN = -100.0D0\r\n YMAX = 300.0D0\r\n\r\n x = (/ (n, n=1, INT_N) /)\r\n\r\n call begin_plot(fname='L5-Q3')\r\n\r\n call subplots(2, 1)\r\n\r\n call info(ENDL//\"m0 ~ \"//F7a_NAME//ENDL)\r\n\r\n r = adapt_int(f7a, a, b, INT_N, tol=1.0D-8, kind=\"gauss-legendre\")\r\n\r\n call info(\":: Valor de refer\u00eancia (Integra\u00e7\u00e3o Adaptativa) tol = 1E-8 ::\")\r\n call blue(\"m0 = \u222bS\u03c3(\u03c9) d\u03c9 \u2248 \"//DSTR(r))\r\n\r\n do n = 1, INT_N\r\n y(:, n) = (/ &\r\n num_int(f7a, a, b, n, kind=\"polynomial\"), &\r\n! \r\n num_int(f7a, a, b, n, kind=\"gauss-legendre\"), &\r\n!\r\n num_int(f7a, a, b, n, kind=\"romberg\"), &\r\n!\r\n r &\r\n /)\r\n end do\r\n\r\n call info(\":: Integra\u00e7\u00e3o Polinomial ::\")\r\n call blue(\"m0 = \u222bS\u03c3(\u03c9) d\u03c9 \u2248 \"//DSTR(y(1, 10)))\r\n call info(\":: Quadratura de Gauss-Legendre ::\")\r\n call blue(\"m0 = \u222bS\u03c3(\u03c9) d\u03c9 \u2248 \"//DSTR(y(2, 10)))\r\n call info(\":: M\u00e9todo de Romberg ::\")\r\n call blue(\"m0 = \u222bS\u03c3(\u03c9) d\u03c9 \u2248 \"//DSTR(y(3, 10)))\r\n\r\n do n = 1, 4\r\n call subplot(1, 1, x, y(n, :), INT_N)\r\n end do\r\n\r\n call subplot_config(1, 1, title='m0 = \u222bS\u03c3(\u03c9) d\u03c9 \u2248 '//DSTR(r), xlabel='n', ylabel='m0', grid=.TRUE., &\r\n legend=legend, with=with, xmin=XMIN, xmax=XMAX, ymin=YMIN, ymax=YMAX)\r\n\r\n call info(ENDL//\"m2 ~ \"//F7b_NAME//ENDL)\r\n\r\n r = adapt_int(f7b, a, b, INT_N, tol=1.0D-8, kind=\"gauss-legendre\")\r\n\r\n call info(\":: Valor de refer\u00eancia (Integra\u00e7\u00e3o Adaptativa) tol = 1E-8 ::\")\r\n call blue(\"m2 = \u222bS\u03c3(\u03c9) d\u03c9 \u2248 \"//DSTR(r))\r\n\r\n do n = 1, INT_N\r\n y(:, n) = (/ &\r\n num_int(f7b, a, b, n, kind=\"polynomial\"), &\r\n! \r\n num_int(f7b, a, b, n, kind=\"gauss-legendre\"), &\r\n!\r\n num_int(f7b, a, b, n, kind=\"romberg\"), &\r\n!\r\n r &\r\n /)\r\n end do\r\n\r\n call info(\":: Integra\u00e7\u00e3o Polinomial ::\")\r\n call blue(\"m2 = \u222bS\u03c3(\u03c9) d\u03c9 \u2248 \"//DSTR(y(1, 10)))\r\n call info(\":: Quadratura de Gauss-Legendre ::\")\r\n call blue(\"m2 = \u222bS\u03c3(\u03c9) d\u03c9 \u2248 \"//DSTR(y(2, 10)))\r\n call info(\":: M\u00e9todo de Romberg ::\")\r\n call blue(\"m2 = \u222bS\u03c3(\u03c9) d\u03c9 \u2248 \"//DSTR(y(3, 10)))\r\n\r\n do n = 1, 4\r\n call subplot(2, 1, x, y(n, :), INT_N)\r\n end do\r\n\r\n call subplot_config(2, 1, title='m2 = \u222b\u03c9\u00b2 S\u03c3(\u03c9) d\u03c9 \u2248 '//DSTR(r), xlabel='n', ylabel='m2', grid=.TRUE., &\r\n legend=legend, with=with, xmin=XMIN, xmax=XMAX, ymin=YMIN, ymax=YMAX)\r\n\r\n call render_plot(clean=.TRUE.)\r\n end subroutine\r\n\r\n subroutine Q4\r\n implicit none\r\n integer :: n\r\n double precision :: a, b, r\r\n double precision, dimension(INT_N) :: x\r\n double precision, dimension(4, INT_N) :: y\r\n\r\n type(StringArray), dimension(:), allocatable :: legend, with\r\n\r\n allocate(legend(4), with(4))\r\n\r\n legend(1)%str = 'Polinomial'\r\n legend(2)%str = 'Gauss-Legendre'\r\n legend(3)%str = 'Romberg'\r\n legend(4)%str = 'Adaptativo (Gauss)'\r\n\r\n with(1)%str = 'linespoints'\r\n with(2)%str = 'linespoints'\r\n with(3)%str = 'linespoints'\r\n with(4)%str = 'lines'\r\n\r\n a = 0.00D0\r\n b = 10.0D0\r\n\r\n call info(ENDL//\"4)\"//ENDL//F8_NAME)\r\n\r\n call info(\"[a, b] = [\"//DSTR(a)//\", \"//DSTR(b)//\"]\")\r\n\r\n INT_N = 128\r\n\r\n XMIN = 1.0D0\r\n XMAX = INT_N\r\n YMIN = -10.0D0\r\n YMAX = 100.0D0\r\n\r\n x = (/ (n, n=1, INT_N) /)\r\n\r\n call begin_plot(fname='L5-Q4')\r\n\r\n call subplots(2, 1)\r\n\r\n call info(ENDL//\"m0 ~ \"//F8a_NAME//ENDL)\r\n\r\n r = adapt_int(f8a, a, b, INT_N, tol=1.0D-8, kind=\"gauss-legendre\")\r\n\r\n call info(\":: Valor de refer\u00eancia (Integra\u00e7\u00e3o Adaptativa) tol = 1E-8 ::\")\r\n call blue(\"m0 = \u222bS\u03c3(\u03c9) d\u03c9 \u2248 \"//DSTR(r))\r\n\r\n do n = 1, INT_N\r\n y(:, n) = (/ &\r\n num_int(f8a, a, b, n, kind=\"polynomial\"), &\r\n! \r\n num_int(f8a, a, b, n, kind=\"gauss-legendre\"), &\r\n!\r\n num_int(f8a, a, b, n, kind=\"romberg\"), &\r\n!\r\n r &\r\n /)\r\n end do\r\n\r\n call info(\":: Integra\u00e7\u00e3o Polinomial ::\")\r\n call blue(\"m0 = \u222bS\u03c3(\u03c9) d\u03c9 \u2248 \"//DSTR(y(1, 10)))\r\n call info(\":: Quadratura de Gauss-Legendre ::\")\r\n call blue(\"m0 = \u222bS\u03c3(\u03c9) d\u03c9 \u2248 \"//DSTR(y(2, 10)))\r\n call info(\":: M\u00e9todo de Romberg ::\")\r\n call blue(\"m0 = \u222bS\u03c3(\u03c9) d\u03c9 \u2248 \"//DSTR(y(3, 10)))\r\n\r\n do n = 1, 4\r\n call subplot(1, 1, x, y(n, :), INT_N)\r\n end do\r\n\r\n call subplot_config(1, 1, title='m0 = \u222bS\u03c3(\u03c9) d\u03c9 \u2248 '//DSTR(r), xlabel='n', ylabel='m0', grid=.TRUE., &\r\n legend=legend, with=with, xmin=XMIN, xmax=XMAX, ymin=YMIN, ymax=YMAX)\r\n\r\n call info(ENDL//\"m2 ~ \"//F8b_NAME//ENDL)\r\n\r\n r = adapt_int(f8b, a, b, INT_N, tol=1.0D-8, kind=\"gauss-legendre\")\r\n\r\n call info(\":: Valor de refer\u00eancia (Integra\u00e7\u00e3o Adaptativa) tol = 1E-8 ::\")\r\n call blue(\"m2 = \u222bS\u03c3(\u03c9) d\u03c9 \u2248 \"//DSTR(r))\r\n\r\n do n = 1, INT_N\r\n y(:, n) = (/ &\r\n num_int(f8b, a, b, n, kind=\"polynomial\"), &\r\n! \r\n num_int(f8b, a, b, n, kind=\"gauss-legendre\"), &\r\n!\r\n num_int(f8b, a, b, n, kind=\"romberg\"), &\r\n!\r\n r &\r\n /)\r\n end do\r\n\r\n call info(\":: Integra\u00e7\u00e3o Polinomial ::\")\r\n call blue(\"m2 = \u222bS\u03c3(\u03c9) d\u03c9 \u2248 \"//DSTR(y(1, 10)))\r\n call info(\":: Quadratura de Gauss-Legendre ::\")\r\n call blue(\"m2 = \u222bS\u03c3(\u03c9) d\u03c9 \u2248 \"//DSTR(y(2, 10)))\r\n call info(\":: M\u00e9todo de Romberg ::\")\r\n call blue(\"m2 = \u222bS\u03c3(\u03c9) d\u03c9 \u2248 \"//DSTR(y(3, 10)))\r\n\r\n do n = 1, 4\r\n call subplot(2, 1, x, y(n, :), INT_N)\r\n end do\r\n\r\n call subplot_config(2, 1, title='m2 = \u222b\u03c9\u00b2 S\u03c3(\u03c9) d\u03c9 \u2248 '//DSTR(r), xlabel='n', ylabel='m2', grid=.TRUE., &\r\n legend=legend, with=with, xmin=XMIN, xmax=XMAX, ymin=YMIN, ymax=YMAX)\r\n\r\n call render_plot(clean=.TRUE.)\r\n end subroutine\r\n\r\n subroutine Q5\r\n implicit none\r\n integer :: n\r\n double precision :: a, b, s\r\n\r\n call info(ENDL//\"5) \"//F9_NAME)\r\n a = 0.0D0\r\n b = 4.0D0\r\n call info(\"[a, b] = [\"//DSTR(a)//\", \"//DSTR(b)//\"]\")\r\n \r\n n = 4\r\n call info(\":: Integra\u00e7\u00e3o Polinomial ::\")\r\n call blue('n = '//STR(n))\r\n s = num_int(f9, a, b, n, kind=\"polynomial\")\r\n call blue(\"A = \u222bf(x) dx \u2248 \"//DSTR(s))\r\n\r\n n = 2\r\n call info(\":: Quadratura de Gauss-Legendre ::\")\r\n call blue('n = '//STR(n))\r\n s = num_int(f9, a, b, n, kind=\"gauss-legendre\")\r\n call blue(\"A = \u222bf(x) dx \u2248 \"//DSTR(s))\r\n end subroutine\r\n\r\n subroutine Q6\r\n implicit none\r\n integer :: n\r\n double precision :: a, b, s\r\n\r\n n = 10\r\n\r\n call blue('n = '//STR(n))\r\n\r\n call info(ENDL//\"6) \"//F10_NAME)\r\n a = 0.0D0\r\n b = 3.0D0\r\n call info(\"[a, b] = [\"//DSTR(a)//\", \"//DSTR(b)//\"]\")\r\n call info(\":: Integra\u00e7\u00e3o Polinomial ::\")\r\n s = num_int(f10, a, b, n, kind=\"polynomial\")\r\n call blue(\"A = \u222bf(x) dx \u2248 \"//DSTR(s))\r\n call info(\":: Quadratura de Gauss-Legendre ::\")\r\n s = num_int(f10, a, b, n, kind=\"gauss-legendre\")\r\n call blue(\"A = \u222bf(x) dx \u2248 \"//DSTR(s)) \r\n call info(\":: M\u00e9todo de Romberg ::\")\r\n s = num_int(f10, a, b, n, kind=\"romberg\")\r\n call blue(\"A = \u222bf(x) dx \u2248 \"//DSTR(s)) \r\n end subroutine\r\n\r\n subroutine Q7\r\n implicit none\r\n integer :: n\r\n double precision :: a, b, r, s\r\n\r\n call info(ENDL//\"7)\")\r\n\r\n n = 10\r\n\r\n call blue('n = '//STR(n))\r\n\r\n call info(\"A1 ~ \"//F11_NAME)\r\n a = DNINF\r\n b = 1.0D0\r\n call info(\"[a, b] = [\"//DSTR(a)//\", \"//DSTR(b)//\"]\")\r\n call info(\":: Quadratura de Gauss-Hermite e de Gauss-Legendre ::\")\r\n r = num_int(f11a, a, -a, n, kind=\"gauss-hermite\")\r\n s = num_int(f11b, -b, b, n, kind=\"gauss-legendre\")\r\n call blue(\"A1 = \u222bf(x) dx \u2248 \"//DSTR(r+s))\r\n \r\n call info(\"A2 ~ \"//F12_NAME)\r\n a = DNINF\r\n b = DINF\r\n call info(\"[a, b] = [\"//DSTR(a)//\", \"//DSTR(b)//\"]\")\r\n call info(\":: Quadratura de Gauss-Hermite ::\")\r\n s = num_int(f12, a, b, n, kind=\"gauss-hermite\")\r\n call blue(\"A2 = \u222bf(x) dx \u2248 \"//DSTR(s))\r\n end subroutine\r\n\r\n subroutine QE1\r\n implicit none\r\n double precision :: x, y, dy\r\n\r\n x = 3.0D0\r\n\r\n call info(ENDL//'1)')\r\n\r\n call info(FL5_QE1_NAME)\r\n call info(DFL5_QE1_NAME)\r\n\r\n call info(':: Derivada Anal\u00edtica ::')\r\n dy = DFL5_QE1(x)\r\n call blue(\"f'(\"//DSTR(x)//\") = \"//DSTR(dy))\r\n\r\n call info(\":: Diferen\u00e7as Finitas ::\"//ENDL)\r\n\r\n call info(':: Diferen\u00e7a Central (\u0394x = 1E-2)::')\r\n y = d(FL5_QE1, x, dx=1.0D-2, kind='central')\r\n call blue(\"f'(\"//DSTR(x)//\") \u2248 \"//DSTR(dy))\r\n call blue(\"|\u03b4y| = \"//DSTR(DABS(y - dy)))\r\n\r\n call info(':: Passo \u00e0 frente (\u0394x = 1E-2)::')\r\n y = d(FL5_QE1, x, dx=1.0D-2, kind='forward')\r\n call blue(\"f'(\"//DSTR(x)//\") \u2248 \"//DSTR(dy))\r\n call blue(\"|\u03b4y| = \"//DSTR(DABS(y - dy)))\r\n\r\n call info(':: Passo atr\u00e1s (\u0394x = 1E-2)::')\r\n y = d(FL5_QE1, x, dx=1.0D-2, kind='backward')\r\n call blue(\"f'(\"//DSTR(x)//\") \u2248 \"//DSTR(dy))\r\n call blue(\"|\u03b4y| = \"//DSTR(DABS(y - dy)))\r\n\r\n call info(ENDL//\":: Extrapola\u00e7\u00e3o de Richard ::\")\r\n\r\n call info(':: Diferen\u00e7a Central (\u0394x = 1E-2, p = 1)::')\r\n y = richard(FL5_QE1, x, dx=1.0D-2, kind='central')\r\n call blue(\"f'(\"//DSTR(x)//\") \u2248 \"//DSTR(dy))\r\n call blue(\"|\u03b4y| = \"//DSTR(DABS(y - dy)))\r\n\r\n call info(':: Diferen\u00e7a Central (\u0394x = 1E-2, p = 2)::')\r\n y = richard(FL5_QE1, x, dx=1.0D-2, p=2.0D0, kind='central')\r\n call blue(\"f'(\"//DSTR(x)//\") \u2248 \"//DSTR(dy))\r\n call blue(\"|\u03b4y| = \"//DSTR(DABS(y - dy)))\r\n\r\n call info(':: Passo \u00e0 frente (\u0394x = 1E-2, p = 1)::')\r\n y = richard(FL5_QE1, x, dx=1.0D-2, kind='forward')\r\n call blue(\"f'(\"//DSTR(x)//\") \u2248 \"//DSTR(dy))\r\n call blue(\"|\u03b4y| = \"//DSTR(DABS(y - dy)))\r\n\r\n call info(':: Passo \u00e0 frente (\u0394x = 1E-2, p = 2)::')\r\n y = richard(FL5_QE1, x, dx=1.0D-2, p=2.0D0, kind='forward')\r\n call blue(\"f'(\"//DSTR(x)//\") \u2248 \"//DSTR(dy))\r\n call blue(\"|\u03b4y| = \"//DSTR(DABS(y - dy)))\r\n\r\n call info(':: Passo atr\u00e1s (\u0394x = 1E-2, p = 1)::')\r\n y = richard(FL5_QE1, x, dx=1.0D-2, kind='backward')\r\n call blue(\"f'(\"//DSTR(x)//\") \u2248 \"//DSTR(dy))\r\n call blue(\"|\u03b4y| = \"//DSTR(DABS(y - dy)))\r\n\r\n call info(':: Passo atr\u00e1s (\u0394x = 1E-2, p = 2)::')\r\n y = richard(FL5_QE1, x, dx=1.0D-2, p=2.0D0, kind='backward')\r\n call blue(\"f'(\"//DSTR(x)//\") \u2248 \"//DSTR(dy))\r\n call blue(\"|\u03b4y| = \"//DSTR(DABS(y - dy)))\r\n\r\n end subroutine\r\n\r\n subroutine QE2\r\n implicit none\r\n double precision :: x, y, dy\r\n\r\n x = 2.0D0\r\n\r\n call info(ENDL//'2)')\r\n\r\n call info(FL5_QE2_NAME)\r\n call info(DFL5_QE2_NAME)\r\n\r\n call info(':: Derivada Anal\u00edtica ::')\r\n dy = DFL5_QE2(x)\r\n call blue(\"f'(\"//DSTR(x)//\") = \"//DSTR(dy))\r\n\r\n call info(\":: Diferen\u00e7as Finitas ::\"//ENDL)\r\n\r\n call info(':: Diferen\u00e7a Central (\u0394x = 1E-2)::')\r\n y = d(FL5_QE2, x, dx=1.0D-2, kind='central')\r\n call blue(\"f'(\"//DSTR(x)//\") \u2248 \"//DSTR(dy))\r\n call blue(\"|\u03b4y| = \"//DSTR(DABS(y - dy)))\r\n\r\n call info(':: Passo \u00e0 frente (\u0394x = 1E-2)::')\r\n y = d(FL5_QE2, x, dx=1.0D-2, kind='forward')\r\n call blue(\"f'(\"//DSTR(x)//\") \u2248 \"//DSTR(dy))\r\n call blue(\"|\u03b4y| = \"//DSTR(DABS(y - dy)))\r\n\r\n call info(':: Passo atr\u00e1s (\u0394x = 1E-2)::')\r\n y = d(FL5_QE2, x, dx=1.0D-2, kind='backward')\r\n call blue(\"f'(\"//DSTR(x)//\") \u2248 \"//DSTR(dy))\r\n call blue(\"|\u03b4y| = \"//DSTR(DABS(y - dy)))\r\n\r\n call info(ENDL//\":: Extrapola\u00e7\u00e3o de Richard ::\")\r\n\r\n call info(':: Diferen\u00e7a Central (\u0394x = 1E-2, p = 1)::')\r\n y = richard(FL5_QE2, x, dx=1.0D-2, kind='central')\r\n call blue(\"f'(\"//DSTR(x)//\") \u2248 \"//DSTR(dy))\r\n call blue(\"|\u03b4y| = \"//DSTR(DABS(y - dy)))\r\n\r\n call info(':: Diferen\u00e7a Central (\u0394x = 1E-2, p = 2)::')\r\n y = richard(FL5_QE2, x, dx=1.0D-2, p=2.0D0, kind='central')\r\n call blue(\"f'(\"//DSTR(x)//\") \u2248 \"//DSTR(dy))\r\n call blue(\"|\u03b4y| = \"//DSTR(DABS(y - dy)))\r\n\r\n call info(':: Passo \u00e0 frente (\u0394x = 1E-2, p = 1)::')\r\n y = richard(FL5_QE2, x, dx=1.0D-2, kind='forward')\r\n call blue(\"f'(\"//DSTR(x)//\") \u2248 \"//DSTR(dy))\r\n call blue(\"|\u03b4y| = \"//DSTR(DABS(y - dy)))\r\n\r\n call info(':: Passo \u00e0 frente (\u0394x = 1E-2, p = 2)::')\r\n y = richard(FL5_QE2, x, dx=1.0D-2, p=2.0D0, kind='forward')\r\n call blue(\"f'(\"//DSTR(x)//\") \u2248 \"//DSTR(dy))\r\n call blue(\"|\u03b4y| = \"//DSTR(DABS(y - dy)))\r\n\r\n call info(':: Passo atr\u00e1s (\u0394x = 1E-2, p = 1)::')\r\n y = richard(FL5_QE2, x, dx=1.0D-2, kind='backward')\r\n call blue(\"f'(\"//DSTR(x)//\") \u2248 \"//DSTR(dy))\r\n call blue(\"|\u03b4y| = \"//DSTR(DABS(y - dy)))\r\n\r\n call info(':: Passo atr\u00e1s (\u0394x = 1E-2, p = 2)::')\r\n y = richard(FL5_QE2, x, dx=1.0D-2, p=2.0D0, kind='backward')\r\n call blue(\"f'(\"//DSTR(x)//\") \u2248 \"//DSTR(dy))\r\n call blue(\"|\u03b4y| = \"//DSTR(DABS(y - dy)))\r\n end subroutine\r\n\r\n subroutine QE3\r\n implicit none\r\n double precision :: x, y, dy\r\n\r\n x = 6.0D0\r\n\r\n call info(ENDL//'3)')\r\n\r\n call info(FL5_QE3_NAME)\r\n call info(DFL5_QE3_NAME)\r\n\r\n call info(':: Derivada Anal\u00edtica ::')\r\n dy = DFL5_QE3(x)\r\n call blue(\"f'(\"//DSTR(x)//\") = \"//DSTR(dy))\r\n\r\n call info(\":: Diferen\u00e7as Finitas ::\"//ENDL)\r\n\r\n call info(':: Diferen\u00e7a Central (\u0394x = 1E-2)::')\r\n y = d(FL5_QE3, x, dx=1.0D-2, kind='central')\r\n call blue(\"f'(\"//DSTR(x)//\") \u2248 \"//DSTR(dy))\r\n call blue(\"|\u03b4y| = \"//DSTR(DABS(y - dy)))\r\n\r\n call info(':: Passo \u00e0 frente (\u0394x = 1E-2)::')\r\n y = d(FL5_QE3, x, dx=1.0D-2, kind='forward')\r\n call blue(\"f'(\"//DSTR(x)//\") \u2248 \"//DSTR(dy))\r\n call blue(\"|\u03b4y| = \"//DSTR(DABS(y - dy)))\r\n\r\n call info(':: Passo atr\u00e1s (\u0394x = 1E-2)::')\r\n y = d(FL5_QE3, x, dx=1.0D-2, kind='backward')\r\n call blue(\"f'(\"//DSTR(x)//\") \u2248 \"//DSTR(dy))\r\n call blue(\"|\u03b4y| = \"//DSTR(DABS(y - dy)))\r\n\r\n call info(ENDL//\":: Extrapola\u00e7\u00e3o de Richard ::\")\r\n\r\n call info(':: Diferen\u00e7a Central (\u0394x = 1E-2, p = 1)::')\r\n y = richard(FL5_QE3, x, dx=1.0D-2, kind='central')\r\n call blue(\"f'(\"//DSTR(x)//\") \u2248 \"//DSTR(dy))\r\n call blue(\"|\u03b4y| = \"//DSTR(DABS(y - dy)))\r\n\r\n call info(':: Diferen\u00e7a Central (\u0394x = 1E-2, p = 2)::')\r\n y = richard(FL5_QE3, x, dx=1.0D-2, p=2.0D0, kind='central')\r\n call blue(\"f'(\"//DSTR(x)//\") \u2248 \"//DSTR(dy))\r\n call blue(\"|\u03b4y| = \"//DSTR(DABS(y - dy)))\r\n\r\n call info(':: Passo \u00e0 frente (\u0394x = 1E-2, p = 1)::')\r\n y = richard(FL5_QE3, x, dx=1.0D-2, kind='forward')\r\n call blue(\"f'(\"//DSTR(x)//\") \u2248 \"//DSTR(dy))\r\n call blue(\"|\u03b4y| = \"//DSTR(DABS(y - dy)))\r\n\r\n call info(':: Passo \u00e0 frente (\u0394x = 1E-2, p = 2)::')\r\n y = richard(FL5_QE3, x, dx=1.0D-2, p=2.0D0, kind='forward')\r\n call blue(\"f'(\"//DSTR(x)//\") \u2248 \"//DSTR(dy))\r\n call blue(\"|\u03b4y| = \"//DSTR(DABS(y - dy)))\r\n\r\n call info(':: Passo atr\u00e1s (\u0394x = 1E-2, p = 1)::')\r\n y = richard(FL5_QE3, x, dx=1.0D-2, kind='backward')\r\n call blue(\"f'(\"//DSTR(x)//\") \u2248 \"//DSTR(dy))\r\n call blue(\"|\u03b4y| = \"//DSTR(DABS(y - dy)))\r\n\r\n call info(':: Passo atr\u00e1s (\u0394x = 1E-2, p = 2)::')\r\n y = richard(FL5_QE3, x, dx=1.0D-2, p=2.0D0, kind='backward')\r\n call blue(\"f'(\"//DSTR(x)//\") \u2248 \"//DSTR(dy))\r\n call blue(\"|\u03b4y| = \"//DSTR(DABS(y - dy)))\r\n end subroutine\r\nend program main5", "meta": {"hexsha": "9558a7ba3ae255d401066294c6b75b022c7fae17", "size": 19166, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/main5.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/main5.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/main5.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.4297800338, "max_line_length": 113, "alphanum_fraction": 0.4570072003, "num_tokens": 6736, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84594244507642, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.6815184578574134}} {"text": "program testNormSinglePerformance\n use frand123\n use omp_lib\n use, intrinsic :: iso_c_binding, only: c_float, c_int64_t\n implicit none\n\n type( frand123State_t ) :: state\n integer( kind = c_int64_t ), dimension( 2 ) :: seed\n integer, parameter :: ctr_kind = selected_int_kind( 14 )\n integer( kind = ctr_kind ), parameter :: rounds = 1000 * 1000 * 100\n integer( kind = ctr_kind ) :: i\n real( kind = c_float ), parameter :: mu = 0.d0\n real( kind = c_float ), parameter :: sigma = 1.d0\n real( kind = c_float ), dimension( 2 ) :: buffer\n real( kind = c_float ), dimension( 2 ) :: resArr\n real( kind = c_float ) :: res\n double precision :: startTime, stopTime\n\n ! serial\n startTime = omp_get_wtime()\n ! initialize state\n seed = (/ 0, 0 /)\n call frand123Init( state, 0, 0, seed)\n ! run for rounds\n resArr = 0.d0\n do i = 1, rounds\n ! generate pair of random variates\n call frand123NormSingle( state, mu, sigma, buffer )\n ! summation\n resArr = resArr + buffer\n enddo\n ! sum up two entries of resArr\n res = sum( resArr ) / rounds\n stopTime = omp_get_wtime()\n write(*,'( \"Serial version: result: \", E14.7, \", runtime: \", E11.4 )' ) &\n res, stopTime - startTime\n\n ! parallel\n startTime = omp_get_wtime();\n !$OMP parallel default( none ) private( buffer, state ) shared( seed, resArr )\n call frand123Init( state, 0, omp_get_thread_num(), seed )\n resArr = 0.d0\n !$OMP do reduction( +: resArr )\n do i = 1, rounds\n ! generate pair of random variates\n call frand123NormSingle( state, mu, sigma, buffer )\n ! summation\n resArr = resArr + buffer\n enddo\n !$OMP end do\n !$OMP end parallel\n ! sum up two entries of resArr\n res = sum( resArr ) / rounds\n stopTime = omp_get_wtime()\n write(*,'( \"Parallel version: result: \", E14.7, \", runtime: \", E11.4 )' ) &\n res, stopTime - startTime\nend program\n", "meta": {"hexsha": "df9fce887de1fb2fb27679fffae3ab957e71efff", "size": 1907, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/testNormSinglePerformance.f90", "max_stars_repo_name": "maedoc/frand123", "max_stars_repo_head_hexsha": "81591c06d8d705b3fc87531da6c3681e2127b228", "max_stars_repo_licenses": ["Intel"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tests/testNormSinglePerformance.f90", "max_issues_repo_name": "maedoc/frand123", "max_issues_repo_head_hexsha": "81591c06d8d705b3fc87531da6c3681e2127b228", "max_issues_repo_licenses": ["Intel"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/testNormSinglePerformance.f90", "max_forks_repo_name": "maedoc/frand123", "max_forks_repo_head_hexsha": "81591c06d8d705b3fc87531da6c3681e2127b228", "max_forks_repo_licenses": ["Intel"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.8793103448, "max_line_length": 81, "alphanum_fraction": 0.6297850026, "num_tokens": 591, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424373085146, "lm_q2_score": 0.8056321796478255, "lm_q1q2_score": 0.6815184496254526}} {"text": " SUBROUTINE CSHEP2 (N,X,Y,F,NC,NW,NR, LCELL,LNEXT,XMIN,\n . YMIN,DX,DY,RMAX,RW,A,IER)\n INTEGER N, NC, NW, NR, LCELL(NR,NR), LNEXT(N), IER\n DOUBLE PRECISION X(N), Y(N), F(N), XMIN, YMIN, DX,\n . DY, RMAX, RW(N), A(9,N)\nC\nC***********************************************************\nC\nC This subroutine computes a set of parameters defining a\nC C2 (twice continuously differentiable) bivariate function\nC C(X,Y) which interpolates data values F at a set of N\nC arbitrarily distributed points (X,Y) in the plane (nodes).\nC The interpolant C may be evaluated at an arbitrary point\nC by function CS2VAL, and its first partial derivatives are\nC computed by Subroutine CS2GRD.\nC\nC The interpolation scheme is a modified Cubic Shepard\nC method:\nC\nC C = [W(1)*C(1)+W(2)*C(2)+..+W(N)*C(N)]/[W(1)+W(2)+..+W(N)]\nC\nC for bivariate functions W(k) and C(k). The nodal func-\nC tions are given by\nC\nC C(k)(x,y) = A(1,k)*(x-X(k))**3 +\nC A(2,k)*(x-X(k))**2*(y-Y(k)) +\nC A(3,k)*(x-X(k))*(y-Y(k))**2 +\nC A(4,k)*(y-Y(k))**3 + A(5,k)*(x-X(k))**2 +\nC A(6,k)*(x-X(k))*(y-Y(k)) + A(7,k)*(y-Y(k))**2\nC + A(8,k)*(x-X(k)) + A(9,k)*(y-Y(k)) + F(k) .\nC\nC Thus, C(k) is a cubic function which interpolates the data\nC value at node k. Its coefficients A(,k) are obtained by a\nC weighted least squares fit to the closest NC data points\nC with weights similar to W(k). Note that the radius of\nC influence for the least squares fit is fixed for each k,\nC but varies with k.\nC\nC The weights are taken to be\nC\nC W(k)(x,y) = ( (R(k)-D(k))+ / R(k)*D(k) )**3 ,\nC\nC where (R(k)-D(k))+ = 0 if R(k) < D(k), and D(k)(x,y) is\nC the Euclidean distance between (x,y) and (X(k),Y(k)). The\nC radius of influence R(k) varies with k and is chosen so\nC that NW nodes are within the radius. Note that W(k) is\nC not defined at node (X(k),Y(k)), but C(x,y) has limit F(k)\nC as (x,y) approaches (X(k),Y(k)).\nC\nC On input:\nC\nC N = Number of nodes and data values. N .GE. 10.\nC\nC X,Y = Arrays of length N containing the Cartesian\nC coordinates of the nodes.\nC\nC F = Array of length N containing the data values\nC in one-to-one correspondence with the nodes.\nC\nC NC = Number of data points to be used in the least\nC squares fit for coefficients defining the nodal\nC functions C(k). Values found to be optimal for\nC test data sets ranged from 11 to 25. A recom-\nC mended value for general data sets is NC = 17.\nC For nodes lying on (or close to) a rectangular\nC grid, the recommended value is NC = 11. In any\nC case, NC must be in the range 9 to Min(40,N-1).\nC\nC NW = Number of nodes within (and defining) the radii\nC of influence R(k) which enter into the weights\nC W(k). For N sufficiently large, a recommended\nC value is NW = 30. In general, NW should be\nC about 1.5*NC. 1 .LE. NW .LE. Min(40,N-1).\nC\nC NR = Number of rows and columns in the cell grid de-\nC fined in Subroutine STORE2. A rectangle con-\nC taining the nodes is partitioned into cells in\nC order to increase search efficiency. NR =\nC Sqrt(N/3) is recommended. NR .GE. 1.\nC\nC The above parameters are not altered by this routine.\nC\nC LCELL = Array of length .GE. NR**2.\nC\nC LNEXT = Array of length .GE. N.\nC\nC RW = Array of length .GE. N.\nC\nC A = Array of length .GE. 9N.\nC\nC On output:\nC\nC LCELL = NR by NR array of nodal indexes associated\nC with cells. Refer to Subroutine STORE2.\nC\nC LNEXT = Array of length N containing next-node\nC indexes. Refer to Subroutine STORE2.\nC\nC XMIN,YMIN,DX,DY = Minimum nodal coordinates and cell\nC dimensions. Refer to Subroutine\nC STORE2.\nC\nC RMAX = Largest element in RW -- maximum radius R(k).\nC\nC RW = Array containing the the radii R(k) which enter\nC into the weights W(k).\nC\nC A = 9 by N array containing the coefficients for\nC cubic nodal function C(k) in column k.\nC\nC Note that the output parameters described above are not\nC defined unless IER = 0.\nC\nC IER = Error indicator:\nC IER = 0 if no errors were encountered.\nC IER = 1 if N, NC, NW, or NR is outside its\nC valid range.\nC IER = 2 if duplicate nodes were encountered.\nC IER = 3 if all nodes are collinear.\nC\nC Modules required by CSHEP2: GETNP2, GIVENS, ROTATE,\nC SETUP2, STORE2\nC\nC Intrinsic functions called by CSHEP2: ABS, DBLE, MAX,\nC MIN, SQRT\nC\nC***********************************************************\nC\n INTEGER LMX\n PARAMETER (LMX=40)\n INTEGER I, IERR, IP1, IRM1, IROW, J, JP1, K, LMAX,\n . LNP, NEQ, NN, NNC, NNR, NNW, NP, NPTS(LMX),\n . NCWMAX\n DOUBLE PRECISION B(10,10), C, DDX, DDY, DMIN, DTOL,\n . FK, RC, RS, RSMX, RSOLD, RTOL, RWS,\n . S, SF, SFC, SFS, STF, SUM, T, XK,\n . XMN, YK, YMN\nC\n DATA RTOL/1.D-5/, DTOL/.01/\n NEQ = 0\nC\nC Local parameters:\nC\nC B = Transpose of the augmented regression matrix\nC C = First component of the plane rotation used to\nC zero the lower triangle of B**T -- computed\nC by Subroutine GIVENS\nC DDX,DDY = Local variables for DX and DY\nC DMIN = Minimum of the magnitudes of the diagonal\nC elements of the regression matrix after\nC zeros are introduced below the diagonal\nC DTOL = Tolerance for detecting an ill-conditioned\nC system. The system is accepted when\nC DMIN*RC .GE. DTOL.\nC FK = Data value at mode K -- F(K)\nC I = Index for A, B, and NPTS\nC IERR = Error flag for the call to Subroutine STORE2\nC IP1 = I+1\nC IRM1 = IROW-1\nC IROW = Row index for B\nC J = Index for A and B\nC JP1 = J+1\nC K = Nodal function index and column index for A\nC LMAX = Maximum number of NPTS elements\nC LMX = Maximum value of LMAX\nC LNP = Current length of NPTS\nC NEQ = Number of equations in the least squares fit\nC NN,NNC,NNR = Local copies of N, NC, and NR\nC NNW = Local copy of NW\nC NP = NPTS element\nC NPTS = Array containing the indexes of a sequence of\nC nodes to be used in the least squares fit\nC or to compute RW. The nodes are ordered\nC by distance from K, and the last element\nC (usually indexed by LNP) is used only to\nC determine RC, or RW(K) if NW > NC.\nC NCWMAX = Max(NC,NW)\nC RC = Radius of influence which enters into the\nC weights for C(K) (see Subroutine SETUP2)\nC RS = Squared distance between K and NPTS(LNP) --\nC used to compute RC and RW(K)\nC RSMX = Maximum squared RW element encountered\nC RSOLD = Squared distance between K and NPTS(LNP-1) --\nC used to compute a relative change in RS\nC between succeeding NPTS elements\nC RTOL = Tolerance for detecting a sufficiently large\nC relative change in RS. If the change is\nC not greater than RTOL, the nodes are\nC treated as being the same distance from K\nC RWS = Current squared value of RW(K)\nC S = Second component of the plane rotation deter-\nC mined by subroutine GIVENS\nC SF = Scale factor for the linear terms (columns 8\nC and 9) in the least squares fit -- inverse\nC of the root-mean-square distance between K\nC and the nodes (other than K) in the least\nC squares fit\nC SFS = Scale factor for the quadratic terms (columns\nC 5, 6, and 7) in the least squares fit --\nC SF*SF\nC SFC = Scale factor for the cubic terms (first 4\nC columns) in the least squares fit -- SF**3\nC STF = Marquardt stabilization factor used to damp\nC out the first 4 solution components (third\nC partials of the cubic) when the system is\nC ill-conditioned. As STF increases, the\nC fitting function approaches a quadratic\nC polynomial.\nC SUM = Sum of squared Euclidean distances between\nC node K and the nodes used in the least\nC squares fit (unless additional nodes are\nC added for stability)\nC T = Temporary variable for accumulating a scalar\nC product in the back solve\nC XK,YK = Coordinates of node K -- X(K), Y(K)\nC XMN,YMN = Local variables for XMIN and YMIN\nC\n NN = N\n NNC = NC\n NNW = NW\n NNR = NR\n NCWMAX = MAX(NNC,NNW)\n LMAX = MIN(LMX,NN-1)\n IF (NNC .LT. 9 .OR. NNW .LT. 1 .OR. NCWMAX .GT.\n . LMAX .OR. NNR .LT. 1) GO TO 21\nC\nC Create the cell data structure, and initialize RSMX.\nC\n CALL STORE2 (NN,X,Y,NNR, LCELL,LNEXT,XMN,YMN,DDX,DDY,\n . IERR)\n IF (IERR .NE. 0) GO TO 23\n RSMX = 0.\nC\nC Outer loop on node K:\nC\n DO 16 K = 1,NN\n XK = X(K)\n YK = Y(K)\n FK = F(K)\nC\nC Mark node K to exclude it from the search for nearest\nC neighbors.\nC\n LNEXT(K) = -LNEXT(K)\nC\nC Initialize for loop on NPTS.\nC\n RS = 0.\n SUM = 0.\n RWS = 0.\n RC = 0.\n LNP = 0\nC\nC Compute NPTS, LNP, RWS, NEQ, RC, and SFS.\nC\n 1 SUM = SUM + RS\n IF (LNP .EQ. LMAX) GO TO 2\n LNP = LNP + 1\n RSOLD = RS\n CALL GETNP2 (XK,YK,X,Y,NNR,LCELL,LNEXT,XMN,YMN,\n . DDX,DDY, NP,RS)\n IF (RS .EQ. 0.) GO TO 22\n NPTS(LNP) = NP\n IF ( (RS-RSOLD)/RS .LT. RTOL ) GO TO 1\n IF (RWS .EQ. 0. .AND. LNP .GT. NNW) RWS = RS\n IF (RC .EQ. 0. .AND. LNP .GT. NNC) THEN\nC\nC RC = 0 (not yet computed) and LNP > NC. RC = Sqrt(RS)\nC is sufficiently large to (strictly) include NC nodes.\nC The least squares fit will include NEQ = LNP - 1\nC equations for 9 .LE. NC .LE. NEQ .LT. LMAX .LE. N-1.\nC\n NEQ = LNP - 1\n RC = SQRT(RS)\n SFS = DBLE(NEQ)/SUM\n ENDIF\nC\nC Bottom of loop -- test for termination.\nC\n IF (LNP .GT. NCWMAX) GO TO 3\n GO TO 1\nC\nC All LMAX nodes are included in NPTS. RWS and/or RC**2 is\nC (arbitrarily) taken to be 10 percent larger than the\nC distance RS to the last node included.\nC\n 2 IF (RWS .EQ. 0.) RWS = 1.1*RS\n IF (RC .EQ. 0.) THEN\n NEQ = LMAX\n RC = SQRT(1.1*RS)\n SFS = DBLE(NEQ)/SUM\n ENDIF\nC\nC Store RW(K), update RSMX if necessary, and compute SF\nC and SFC.\nC\n 3 RW(K) = SQRT(RWS)\n IF (RWS .GT. RSMX) RSMX = RWS\n SF = SQRT(SFS)\n SFC = SF*SFS\nC\nC A Q-R decomposition is used to solve the least squares\nC system. The transpose of the augmented regression\nC matrix is stored in B with columns (rows of B) defined\nC as follows: 1-4 are the cubic terms, 5-7 are the quad-\nC ratic terms, 8 and 9 are the linear terms, and the last\nC column is the right hand side.\nC\nC Set up the equations and zero out the lower triangle with\nC Givens rotations.\nC\n I = 0\n 4 I = I + 1\n NP = NPTS(I)\n IROW = MIN(I,10)\n CALL SETUP2 (XK,YK,FK,X(NP),Y(NP),F(NP),SF,SFS,\n . SFC,RC, B(1,IROW))\n IF (I .EQ. 1) GO TO 4\n IRM1 = IROW-1\n DO 5 J = 1,IRM1\n JP1 = J + 1\n CALL GIVENS (B(J,J),B(J,IROW),C,S)\n CALL ROTATE (10-J,C,S,B(JP1,J),B(JP1,IROW))\n 5 CONTINUE\n IF (I .LT. NEQ) GO TO 4\nC\nC Test the system for ill-conditioning.\nC\n DMIN = MIN( ABS(B(1,1)),ABS(B(2,2)),ABS(B(3,3)),\n . ABS(B(4,4)),ABS(B(5,5)),ABS(B(6,6)),\n . ABS(B(7,7)),ABS(B(8,8)),ABS(B(9,9)) )\n IF (DMIN*RC .GE. DTOL) GO TO 11\n IF (NEQ .EQ. LMAX) GO TO 7\nC\nC Increase RC and add another equation to the system to\nC improve the conditioning. The number of NPTS elements\nC is also increased if necessary.\nC\n 6 RSOLD = RS\n NEQ = NEQ + 1\n IF (NEQ .EQ. LMAX) THEN\n RC = SQRT(1.1*RS)\n GO TO 4\n ENDIF\n IF (NEQ .LT. LNP) THEN\nC\nC NEQ < LNP.\nC\n NP = NPTS(NEQ+1)\n RS = (X(NP)-XK)**2 + (Y(NP)-YK)**2\n IF ( (RS-RSOLD)/RS .LT. RTOL ) GO TO 6\n RC = SQRT(RS)\n GO TO 4\n ENDIF\nC\nC NEQ = LNP. Add an element to NPTS.\nC\n LNP = LNP + 1\n CALL GETNP2 (XK,YK,X,Y,NNR,LCELL,LNEXT,XMN,YMN,\n . DDX,DDY, NP,RS)\n IF (NP .EQ. 0) GO TO 22\n NPTS(LNP) = NP\n IF ( (RS-RSOLD)/RS .LT. RTOL ) GO TO 6\n RC = SQRT(RS)\n GO TO 4\nC\nC Stabilize the system by damping third partials -- add\nC multiples of the first four unit vectors to the first\nC four equations.\nC\n 7 STF = 1.0/RC\n DO 10 I = 1,4\n B(I,10) = STF\n IP1 = I + 1\n DO 8 J = IP1,10\n B(J,10) = 0.\n 8 CONTINUE\n DO 9 J = I,9\n JP1 = J + 1\n CALL GIVENS (B(J,J),B(J,10),C,S)\n CALL ROTATE (10-J,C,S,B(JP1,J),B(JP1,10))\n 9 CONTINUE\n 10 CONTINUE\nC\nC Test the damped system for ill-conditioning.\nC\n DMIN = MIN( ABS(B(5,5)),ABS(B(6,6)),ABS(B(7,7)),\n . ABS(B(8,8)),ABS(B(9,9)) )\n IF (DMIN*RC .LT. DTOL) GO TO 23\nC\nC Solve the 9 by 9 triangular system for the coefficients.\nC\n 11 DO 13 I = 9,1,-1\n T = 0.\n IF (I .NE. 9) THEN\n IP1 = I + 1\n DO 12 J = IP1,9\n T = T + B(J,I)*A(J,K)\n 12 CONTINUE\n ENDIF\n A(I,K) = (B(10,I)-T)/B(I,I)\n 13 CONTINUE\nC\nC Scale the coefficients to adjust for the column scaling.\nC\n DO 14 I = 1,4\n A(I,K) = A(I,K)*SFC\n 14 CONTINUE\n A(5,K) = A(5,K)*SFS\n A(6,K) = A(6,K)*SFS\n A(7,K) = A(7,K)*SFS\n A(8,K) = A(8,K)*SF\n A(9,K) = A(9,K)*SF\nC\nC Unmark K and the elements of NPTS.\nC\n LNEXT(K) = -LNEXT(K)\n DO 15 I = 1,LNP\n NP = NPTS(I)\n LNEXT(NP) = -LNEXT(NP)\n 15 CONTINUE\n 16 CONTINUE\nC\nC No errors encountered.\nC\n XMIN = XMN\n YMIN = YMN\n DX = DDX\n DY = DDY\n RMAX = SQRT(RSMX)\n IER = 0\n RETURN\nC\nC N, NC, NW, or NR is outside its valid range.\nC\n 21 IER = 1\n RETURN\nC\nC Duplicate nodes were encountered by GETNP2.\nC\n 22 IER = 2\n RETURN\nC\nC No unique solution due to collinear nodes.\nC\n 23 XMIN = XMN\n YMIN = YMN\n DX = DDX\n DY = DDY\n IER = 3\n RETURN\n END\n\n DOUBLE PRECISION FUNCTION CS2VAL (PX,PY,N,X,Y,F,NR,\n . LCELL,LNEXT,XMIN,YMIN,DX,DY,RMAX,RW,A)\n INTEGER N, NR, LCELL(NR,NR), LNEXT(N)\n DOUBLE PRECISION PX, PY, X(N), Y(N), F(N), XMIN, YMIN,\n . DX, DY, RMAX, RW(N), A(9,N)\nC\nC***********************************************************\nC\nC This function returns the value C(PX,PY), where C is the\nC weighted sum of cubic nodal functions defined in Subrou-\nC tine CSHEP2. CS2GRD may be called to compute a gradient\nC of C along with the value, and/or to test for errors.\nC CS2HES may be called to compute a value, first partial\nC derivatives, and second partial derivatives at a point.\nC\nC On input:\nC\nC PX,PY = Cartesian coordinates of the point P at\nC which C is to be evaluated.\nC\nC N = Number of nodes and data values defining C.\nC N .GE. 10.\nC\nC X,Y,F = Arrays of length N containing the nodes and\nC data values interpolated by C.\nC\nC NR = Number of rows and columns in the cell grid.\nC Refer to Subroutine STORE2. NR .GE. 1.\nC\nC LCELL = NR by NR array of nodal indexes associated\nC with cells. Refer to Subroutine STORE2.\nC\nC LNEXT = Array of length N containing next-node\nC indexes. Refer to Subroutine STORE2.\nC\nC XMIN,YMIN,DX,DY = Minimum nodal coordinates and cell\nC dimensions. DX and DY must be\nC positive. Refer to Subroutine\nC STORE2.\nC\nC RMAX = Largest element in RW -- maximum radius R(k).\nC\nC RW = Array containing the the radii R(k) which enter\nC into the weights W(k) defining C.\nC\nC A = 9 by N array containing the coefficients for\nC cubic nodal function C(k) in column k.\nC\nC Input parameters are not altered by this function. The\nC parameters other than PX and PY should be input unaltered\nC from their values on output from CSHEP2. This function\nC should not be called if a nonzero error flag was returned\nC by CSHEP2.\nC\nC On output:\nC\nC CS2VAL = Function value C(PX,PY) unless N, NR, DX,\nC DY, or RMAX is invalid, in which case no\nC value is returned.\nC\nC Modules required by CS2VAL: NONE\nC\nC Intrinsic functions called by CS2VAL: INT, SQRT\nC\nC***********************************************************\nC\n INTEGER I, IMAX, IMIN, J, JMAX, JMIN, K, KP\n DOUBLE PRECISION D, DELX, DELY, R, SW, SWC, W, XP, YP\n CS2VAL = 0.0\nC\nC Local parameters:\nC\nC D = Distance between P and node K\nC DELX = XP - X(K)\nC DELY = YP - Y(K)\nC I = Cell row index in the range IMIN to IMAX\nC IMIN,IMAX = Range of cell row indexes of the cells\nC intersected by a disk of radius RMAX\nC centered at P\nC J = Cell column index in the range JMIN to JMAX\nC JMIN,JMAX = Range of cell column indexes of the cells\nC intersected by a disk of radius RMAX\nC centered at P\nC K = Index of a node in cell (I,J)\nC KP = Previous value of K in the sequence of nodes\nC in cell (I,J)\nC R = Radius of influence for node K\nC SW = Sum of weights W(K)\nC SWC = Sum of weighted nodal function values at P\nC W = Weight W(K) value at P: ((R-D)+/(R*D))**3,\nC where (R-D)+ = 0 if R < D\nC XP,YP = Local copies of PX and PY -- coordinates of P\nC\n XP = PX\n YP = PY\n IF (N .LT. 10 .OR. NR .LT. 1 .OR. DX .LE. 0. .OR.\n . DY .LE. 0. .OR. RMAX .LT. 0.) RETURN\nC\nC Set IMIN, IMAX, JMIN, and JMAX to cell indexes defining\nC the range of the search for nodes whose radii include\nC P. The cells which must be searched are those inter-\nC sected by (or contained in) a circle of radius RMAX\nC centered at P.\nC\n IMIN = INT((XP-XMIN-RMAX)/DX) + 1\n IMAX = INT((XP-XMIN+RMAX)/DX) + 1\n IF (IMIN .LT. 1) IMIN = 1\n IF (IMAX .GT. NR) IMAX = NR\n JMIN = INT((YP-YMIN-RMAX)/DY) + 1\n JMAX = INT((YP-YMIN+RMAX)/DY) + 1\n IF (JMIN .LT. 1) JMIN = 1\n IF (JMAX .GT. NR) JMAX = NR\nC\nC The following is a test for no cells within the circle\nC of radius RMAX.\nC\n IF (IMIN .GT. IMAX .OR. JMIN .GT. JMAX) GOTO 6\nC\nC Accumulate weight values in SW and weighted nodal function\nC values in SWC. The weights are W(K) = ((R-D)+/(R*D))**3\nC for R = RW(K) and D = distance between P and node K.\nC\n SW = 0.\n SWC = 0.\nC\nC Outer loop on cells (I,J).\nC\n DO 4 J = JMIN,JMAX\n DO 3 I = IMIN,IMAX\n K = LCELL(I,J)\n IF (K .EQ. 0) GO TO 3\nC\nC Inner loop on nodes K.\nC\n 1 DELX = XP - X(K)\n DELY = YP - Y(K)\n D = SQRT(DELX*DELX + DELY*DELY)\n R = RW(K)\n IF (D .GE. R) GOTO 2\n IF (D .EQ. 0.) GOTO 5\n W = (1.0/D - 1.0/R)**3\n SW = SW + W\n SWC = SWC + W*( ( (A(1,K)*DELX+A(2,K)*DELY+\n . A(5,K))*DELX + (A(3,K)*DELY+\n . A(6,K))*DELY + A(8,K) )*DELX +\n . ( (A(4,K)*DELY+A(7,K))*DELY +\n . A(9,K) )*DELY + F(K) )\nC\nC Bottom of loop on nodes in cell (I,J).\nC\n 2 KP = K\n K = LNEXT(KP)\n IF (K .NE. KP) GOTO 1\n 3 CONTINUE\n 4 CONTINUE\nC\nC SW = 0 iff P is not within the radius R(K) for any node K.\nC\n IF (SW .EQ. 0.) GOTO 6\n CS2VAL = SWC/SW\n RETURN\nC\nC (PX,PY) = (X(K),Y(K)).\nC\n 5 CS2VAL = F(K)\n RETURN\nC\nC All weights are 0 at P.\nC\n 6 CS2VAL = 0.\n RETURN\n END\n\n SUBROUTINE CS2GRD (PX,PY,N,X,Y,F,NR,LCELL,LNEXT,XMIN,\n . YMIN,DX,DY,RMAX,RW,A, C,CX,CY,IER)\n INTEGER N, NR, LCELL(NR,NR), LNEXT(N), IER\n DOUBLE PRECISION PX, PY, X(N), Y(N), F(N), XMIN, YMIN,\n . DX, DY, RMAX, RW(N), A(9,N), C, CX,\n . CY\nC\nC***********************************************************\nC\nC From CSHEP2D\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 02/03/97\nC\nC This subroutine computes the value and gradient at P =\nC (PX,PY) of the interpolatory function C defined in Sub-\nC routine CSHEP2. C is a weighted sum of cubic nodal\nC functions.\nC\nC On input:\nC\nC PX,PY = Cartesian coordinates of the point P at\nC which C and its partial derivatives are\nC to be evaluated.\nC\nC N = Number of nodes and data values defining C.\nC N .GE. 10.\nC\nC X,Y,F = Arrays of length N containing the nodes and\nC data values interpolated by C.\nC\nC NR = Number of rows and columns in the cell grid.\nC Refer to Subroutine STORE2. NR .GE. 1.\nC\nC LCELL = NR by NR array of nodal indexes associated\nC with cells. Refer to Subroutine STORE2.\nC\nC LNEXT = Array of length N containing next-node\nC indexes. Refer to Subroutine STORE2.\nC\nC XMIN,YMIN,DX,DY = Minimum nodal coordinates and cell\nC dimensions. DX and DY must be\nC positive. Refer to Subroutine\nC STORE2.\nC\nC RMAX = Largest element in RW -- maximum radius R(k).\nC\nC RW = Array of length N containing the the radii R(k)\nC which enter into the weights W(k) defining C.\nC\nC A = 9 by N array containing the coefficients for\nC cubic nodal function C(k) in column k.\nC\nC Input parameters are not altered by this subroutine.\nC The parameters other than PX and PY should be input\nC unaltered from their values on output from CSHEP2. This\nC subroutine should not be called if a nonzero error flag\nC was returned by CSHEP2.\nC\nC On output:\nC\nC C = Value of C at (PX,PY) unless IER .EQ. 1, in\nC which case no values are returned.\nC\nC CX,CY = First partial derivatives of C at (PX,PY)\nC unless IER .EQ. 1.\nC\nC IER = Error indicator:\nC IER = 0 if no errors were encountered.\nC IER = 1 if N, NR, DX, DY or RMAX is invalid.\nC IER = 2 if no errors were encountered but\nC (PX,PY) is not within the radius R(k)\nC for any node k (and thus C=CX=CY=0).\nC\nC Modules required by CS2GRD: None\nC\nC Intrinsic functions called by CS2GRD: INT, SQRT\nC\nC***********************************************************\nC\n INTEGER I, IMAX, IMIN, J, JMAX, JMIN, K, KP\n DOUBLE PRECISION CK, CKX, CKY, D, DELX, DELY, R, SW,\n . SWC, SWCX, SWCY, SWS, SWX, SWY, T, W,\n . WX, WY, XP, YP\nC\nC Local parameters:\nC\nC CK = Value of cubic nodal function C(K) at P\nC CKX,CKY = Partial derivatives of C(K) with respect to X\nC and Y, respectively\nC D = Distance between P and node K\nC DELX = XP - X(K)\nC DELY = YP - Y(K)\nC I = Cell row index in the range IMIN to IMAX\nC IMIN,IMAX = Range of cell row indexes of the cells\nC intersected by a disk of radius RMAX\nC centered at P\nC J = Cell column index in the range JMIN to JMAX\nC JMIN,JMAX = Range of cell column indexes of the cells\nC intersected by a disk of radius RMAX\nC centered at P\nC K = Index of a node in cell (I,J)\nC KP = Previous value of K in the sequence of nodes\nC in cell (I,J)\nC R = Radius of influence for node K\nC SW = Sum of weights W(K)\nC SWC = Sum of weighted nodal function values at P\nC SWCX,SWCY = Partial derivatives of SWC with respect to X\nC and Y, respectively\nC SWS = SW**2\nC SWX,SWY = Partial derivatives of SW with respect to X\nC and Y, respectively\nC T = Temporary variable\nC W = Weight W(K) value at P: ((R-D)+/(R*D))**3,\nC where (R-D)+ = 0 if R < D\nC WX,WY = Partial derivatives of W with respect to X\nC and Y, respectively\nC XP,YP = Local copies of PX and PY -- coordinates of P\nC\n XP = PX\n YP = PY\n IF (N .LT. 10 .OR. NR .LT. 1 .OR. DX .LE. 0. .OR.\n . DY .LE. 0. .OR. RMAX .LT. 0.) GO TO 6\nC\nC Set IMIN, IMAX, JMIN, and JMAX to cell indexes defining\nC the range of the search for nodes whose radii include\nC P. The cells which must be searched are those inter-\nC sected by (or contained in) a circle of radius RMAX\nC centered at P.\nC\n IMIN = INT((XP-XMIN-RMAX)/DX) + 1\n IMAX = INT((XP-XMIN+RMAX)/DX) + 1\n IF (IMIN .LT. 1) IMIN = 1\n IF (IMAX .GT. NR) IMAX = NR\n JMIN = INT((YP-YMIN-RMAX)/DY) + 1\n JMAX = INT((YP-YMIN+RMAX)/DY) + 1\n IF (JMIN .LT. 1) JMIN = 1\n IF (JMAX .GT. NR) JMAX = NR\nC\nC The following is a test for no cells within the circle\nC of radius RMAX.\nC\n IF (IMIN .GT. IMAX .OR. JMIN .GT. JMAX) GO TO 7\nC\nC C = SWC/SW = Sum(W(K)*C(K))/Sum(W(K)), where the sum is\nC from K = 1 to N, C(K) is the cubic nodal function value,\nC and W(K) = ((R-D)+/(R*D))**3 for radius R(K) and dist-\nC ance D(K). Thus\nC\nC CX = (SWCX*SW - SWC*SWX)/SW**2 and\nC CY = (SWCY*SW - SWC*SWY)/SW**2\nC\nC where SWCX and SWX are partial derivatives with respect\nC to X of SWC and SW, respectively. SWCY and SWY are de-\nC fined similarly.\nC\n SW = 0.\n SWX = 0.\n SWY = 0.\n SWC = 0.\n SWCX = 0.\n SWCY = 0.\nC\nC Outer loop on cells (I,J).\nC\n DO 4 J = JMIN,JMAX\n DO 3 I = IMIN,IMAX\n K = LCELL(I,J)\n IF (K .EQ. 0) GO TO 3\nC\nC Inner loop on nodes K.\nC\n 1 DELX = XP - X(K)\n DELY = YP - Y(K)\n D = SQRT(DELX*DELX + DELY*DELY)\n R = RW(K)\n IF (D .GE. R) GO TO 2\n IF (D .EQ. 0.) GO TO 5\n T = (1.0/D - 1.0/R)\n W = T**3\n T = -3.0*T*T/(D**3)\n WX = DELX*T\n WY = DELY*T\n T = A(2,K)*DELX + A(3,K)*DELY + A(6,K)\n CKY = ( 3.0*A(4,K)*DELY + A(3,K)*DELX +\n . 2.0*A(7,K) )*DELY + T*DELX + A(9,K)\n T = T*DELY + A(8,K)\n CKX = ( 3.0*A(1,K)*DELX + A(2,K)*DELY +\n . 2.0*A(5,K) )*DELX + T\n CK = ( (A(1,K)*DELX+A(5,K))*DELX + T )*DELX +\n . ( (A(4,K)*DELY+A(7,K))*DELY + A(9,K) )*DELY +\n . F(K)\n SW = SW + W\n SWX = SWX + WX\n SWY = SWY + WY\n SWC = SWC + W*CK\n SWCX = SWCX + WX*CK + W*CKX\n SWCY = SWCY + WY*CK + W*CKY\nC\nC Bottom of loop on nodes in cell (I,J).\nC\n 2 KP = K\n K = LNEXT(KP)\n IF (K .NE. KP) GO TO 1\n 3 CONTINUE\n 4 CONTINUE\nC\nC SW = 0 iff P is not within the radius R(K) for any node K.\nC\n IF (SW .EQ. 0.) GO TO 7\n C = SWC/SW\n SWS = SW*SW\n CX = (SWCX*SW - SWC*SWX)/SWS\n CY = (SWCY*SW - SWC*SWY)/SWS\n IER = 0\n RETURN\nC\nC (PX,PY) = (X(K),Y(K)).\nC\n 5 C = F(K)\n CX = A(8,K)\n CY = A(9,K)\n IER = 0\n RETURN\nC\nC Invalid input parameter.\nC\n 6 IER = 1\n RETURN\nC\nC No cells contain a point within RMAX of P, or\nC SW = 0 and thus D .GE. RW(K) for all K.\nC\n 7 C = 0.\n CX = 0.\n CY = 0.\n IER = 2\n RETURN\n END\n SUBROUTINE CS2HES (PX,PY,N,X,Y,F,NR,LCELL,LNEXT,XMIN,\n . YMIN,DX,DY,RMAX,RW,A, C,CX,CY,CXX,\n . CXY,CYY,IER)\n INTEGER N, NR, LCELL(NR,NR), LNEXT(N), IER\n DOUBLE PRECISION PX, PY, X(N), Y(N), F(N), XMIN, YMIN,\n . DX, DY, RMAX, RW(N), A(9,N), C, CX,\n . CY, CXX, CXY, CYY\nC\nC***********************************************************\nC\nC From CSHEP2D\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 02/03/97\nC\nC This subroutine computes the value, gradient, and\nC Hessian at P = (PX,PY) of the interpolatory function C\nC defined in Subroutine CSHEP2. C is a weighted sum of\nC cubic nodal functions.\nC\nC On input:\nC\nC PX,PY = Cartesian coordinates of the point P at\nC which C and its partial derivatives are\nC to be evaluated.\nC\nC N = Number of nodes and data values defining C.\nC N .GE. 10.\nC\nC X,Y,F = Arrays of length N containing the nodes and\nC data values interpolated by C.\nC\nC NR = Number of rows and columns in the cell grid.\nC Refer to Subroutine STORE2. NR .GE. 1.\nC\nC LCELL = NR by NR array of nodal indexes associated\nC with cells. Refer to Subroutine STORE2.\nC\nC LNEXT = Array of length N containing next-node\nC indexes. Refer to Subroutine STORE2.\nC\nC XMIN,YMIN,DX,DY = Minimum nodal coordinates and cell\nC dimensions. DX and DY must be\nC positive. Refer to Subroutine\nC STORE2.\nC\nC RMAX = Largest element in RW -- maximum radius R(k).\nC\nC RW = Array of length N containing the the radii R(k)\nC which enter into the weights W(k) defining C.\nC\nC A = 9 by N array containing the coefficients for\nC cubic nodal function C(k) in column k.\nC\nC Input parameters are not altered by this subroutine.\nC The parameters other than PX and PY should be input\nC unaltered from their values on output from CSHEP2. This\nC subroutine should not be called if a nonzero error flag\nC was returned by CSHEP2.\nC\nC On output:\nC\nC C = Value of C at (PX,PY) unless IER .EQ. 1, in\nC which case no values are returned.\nC\nC CX,CY = First partial derivatives of C at (PX,PY)\nC unless IER .EQ. 1.\nC\nC CXX,CXY,CYY = Second partial derivatives of C at\nC (PX,PY) unless IER .EQ. 1.\nC\nC IER = Error indicator:\nC IER = 0 if no errors were encountered.\nC IER = 1 if N, NR, DX, DY or RMAX is invalid.\nC IER = 2 if no errors were encountered but\nC (PX,PY) is not within the radius R(k)\nC for any node k (and thus C = 0).\nC\nC Modules required by CS2HES: None\nC\nC Intrinsic functions called by CS2HES: INT, SQRT\nC\nC***********************************************************\nC\n INTEGER I, IMAX, IMIN, J, JMAX, JMIN, K, KP\n DOUBLE PRECISION CK, CKX, CKXX, CKXY, CKY, CKYY, D,\n . DELX, DELY, DXSQ, DYSQ, R, SW, SWC,\n . SWCX, SWCXX, SWCXY, SWCY, SWCYY, SWS,\n . SWX, SWXX, SWXY, SWY, SWYY, T1, T2,\n . T3, T4, W, WX, WXX, WXY, WY, WYY, XP,\n . YP\nC\nC Local parameters:\nC\nC CK = Value of cubic nodal function C(K) at P\nC CKX,CKY = Partial derivatives of C(K) with respect to X\nC and Y, respectively\nC CKXX,CKXY,CKYY = Second partial derivatives of CK\nC D = Distance between P and node K\nC DELX = XP - X(K)\nC DELY = YP - Y(K)\nC DXSQ,DYSQ = DELX**2, DELY**2\nC I = Cell row index in the range IMIN to IMAX\nC IMIN,IMAX = Range of cell row indexes of the cells\nC intersected by a disk of radius RMAX\nC centered at P\nC J = Cell column index in the range JMIN to JMAX\nC JMIN,JMAX = Range of cell column indexes of the cells\nC intersected by a disk of radius RMAX\nC centered at P\nC K = Index of a node in cell (I,J)\nC KP = Previous value of K in the sequence of nodes\nC in cell (I,J)\nC R = Radius of influence for node K\nC SW = Sum of weights W(K)\nC SWC = Sum of weighted nodal function values at P\nC SWCX,SWCY = Partial derivatives of SWC with respect to X\nC and Y, respectively\nC SWCXX,SWCXY,SWCYY = Second partial derivatives of SWC\nC SWS = SW**2\nC SWX,SWY = Partial derivatives of SW with respect to X\nC and Y, respectively\nC SWXX,SWXY,SWYY = Second partial derivatives of SW\nC T1,T2,T3,T4 = Temporary variables\nC W = Weight W(K) value at P: ((R-D)+/(R*D))**3,\nC where (R-D)+ = 0 if R < D\nC WX,WY = Partial derivatives of W with respect to X\nC and Y, respectively\nC WXX,WXY,WYY = Second partial derivatives of W\nC XP,YP = Local copies of PX and PY -- coordinates of P\nC\n XP = PX\n YP = PY\n IF (N .LT. 10 .OR. NR .LT. 1 .OR. DX .LE. 0. .OR.\n . DY .LE. 0. .OR. RMAX .LT. 0.) GO TO 6\nC\nC Set IMIN, IMAX, JMIN, and JMAX to cell indexes defining\nC the range of the search for nodes whose radii include\nC P. The cells which must be searched are those inter-\nC sected by (or contained in) a circle of radius RMAX\nC centered at P.\nC\n IMIN = INT((XP-XMIN-RMAX)/DX) + 1\n IMAX = INT((XP-XMIN+RMAX)/DX) + 1\n IF (IMIN .LT. 1) IMIN = 1\n IF (IMAX .GT. NR) IMAX = NR\n JMIN = INT((YP-YMIN-RMAX)/DY) + 1\n JMAX = INT((YP-YMIN+RMAX)/DY) + 1\n IF (JMIN .LT. 1) JMIN = 1\n IF (JMAX .GT. NR) JMAX = NR\nC\nC The following is a test for no cells within the circle\nC of radius RMAX.\nC\n IF (IMIN .GT. IMAX .OR. JMIN .GT. JMAX) GO TO 7\nC\nC C = SWC/SW = Sum(W(K)*C(K))/Sum(W(K)), where the sum is\nC from K = 1 to N, C(K) is the cubic nodal function value,\nC and W(K) = ((R-D)+/(R*D))**3 for radius R(K) and dist-\nC ance D(K). Thus\nC\nC CX = (SWCX*SW - SWC*SWX)/SW**2 and\nC CY = (SWCY*SW - SWC*SWY)/SW**2\nC\nC where SWCX and SWX are partial derivatives with respect\nC to x of SWC and SW, respectively. SWCY and SWY are de-\nC fined similarly. The second partials are\nC\nC CXX = ( SW*(SWCXX - 2*SWX*CX) - SWC*SWXX )/SW**2\nC CXY = ( SW*(SWCXY-SWX*CY-SWY*CX) - SWC*SWXY )/SW**2\nC CYY = ( SW*(SWCYY - 2*SWY*CY) - SWC*SWYY )/SW**2\nC\nC where SWCXX and SWXX are second partials with respect\nC to x, SWCXY and SWXY are mixed partials, and SWCYY and\nC SWYY are second partials with respect to y.\nC\n SW = 0.\n SWX = 0.\n SWY = 0.\n SWXX = 0.\n SWXY = 0.\n SWYY = 0.\n SWC = 0.\n SWCX = 0.\n SWCY = 0.\n SWCXX = 0.\n SWCXY = 0.\n SWCYY = 0.\nC\nC Outer loop on cells (I,J).\nC\n DO 4 J = JMIN,JMAX\n DO 3 I = IMIN,IMAX\n K = LCELL(I,J)\n IF (K .EQ. 0) GO TO 3\nC\nC Inner loop on nodes K.\nC\n 1 DELX = XP - X(K)\n DELY = YP - Y(K)\n DXSQ = DELX*DELX\n DYSQ = DELY*DELY\n D = SQRT(DXSQ + DYSQ)\n R = RW(K)\n IF (D .GE. R) GO TO 2\n IF (D .EQ. 0.) GO TO 5\n T1 = (1.0/D - 1.0/R)\n W = T1**3\n T2 = -3.0*T1*T1/(D**3)\n WX = DELX*T2\n WY = DELY*T2\n T1 = 3.0*T1*(2.0+3.0*D*T1)/(D**6)\n WXX = T1*DXSQ + T2\n WXY = T1*DELX*DELY\n WYY = T1*DYSQ + T2\n T1 = A(1,K)*DELX + A(2,K)*DELY + A(5,K)\n T2 = T1 + T1 + A(1,K)*DELX\n T3 = A(4,K)*DELY + A(3,K)*DELX + A(7,K)\n T4 = T3 + T3 + A(4,K)*DELY\n CK = (T1*DELX + A(6,K)*DELY + A(8,K))*DELX +\n . (T3*DELY + A(9,K))*DELY + F(K)\n CKX = T2*DELX + (A(3,K)*DELY+A(6,K))*DELY + A(8,K)\n CKY = T4*DELY + (A(2,K)*DELX+A(6,K))*DELX + A(9,K)\n CKXX = T2 + 3.0*A(1,K)*DELX\n CKXY = 2.0*(A(2,K)*DELX + A(3,K)*DELY) + A(6,K)\n CKYY = T4 + 3.0*A(4,K)*DELY\n SW = SW + W\n SWX = SWX + WX\n SWY = SWY + WY\n SWXX = SWXX + WXX\n SWXY = SWXY + WXY\n SWYY = SWYY + WYY\n SWC = SWC + W*CK\n SWCX = SWCX + WX*CK + W*CKX\n SWCY = SWCY + WY*CK + W*CKY\n SWCXX = SWCXX + W*CKXX + 2.0*WX*CKX + CK*WXX\n SWCXY = SWCXY + W*CKXY + WX*CKY + WY*CKX + CK*WXY\n SWCYY = SWCYY + W*CKYY + 2.0*WY*CKY + CK*WYY\nC\nC Bottom of loop on nodes in cell (I,J).\nC\n 2 KP = K\n K = LNEXT(KP)\n IF (K .NE. KP) GO TO 1\n 3 CONTINUE\n 4 CONTINUE\nC\nC SW = 0 iff P is not within the radius R(K) for any node K.\nC\n IF (SW .EQ. 0.) GO TO 7\n C = SWC/SW\n SWS = SW*SW\n CX = (SWCX*SW - SWC*SWX)/SWS\n CY = (SWCY*SW - SWC*SWY)/SWS\n CXX = (SW*(SWCXX-2.0*SWX*CX) - SWC*SWXX)/SWS\n CXY = (SW*(SWCXY-SWY*CX-SWX*CY) - SWC*SWXY)/SWS\n CYY = (SW*(SWCYY-2.0*SWY*CY) - SWC*SWYY)/SWS\n IER = 0\n RETURN\nC\nC (PX,PY) = (X(K),Y(K)).\nC\n 5 C = F(K)\n CX = A(8,K)\n CY = A(9,K)\n CXX = 2.0*A(5,K)\n CXY = A(6,K)\n CYY = 2.0*A(7,K)\n IER = 0\n RETURN\nC\nC Invalid input parameter.\nC\n 6 IER = 1\n RETURN\nC\nC No cells contain a point within RMAX of P, or\nC SW = 0 and thus D .GE. RW(K) for all K.\nC\n 7 C = 0.\n CX = 0.\n CY = 0.\n CXX = 0.\n CXY = 0.\n CYY = 0.\n IER = 2\n RETURN\n END\n SUBROUTINE GETNP2 (PX,PY,X,Y,NR,LCELL,LNEXT,XMIN,YMIN,\n . DX,DY, NP,DSQ)\n INTEGER NR, LCELL(NR,NR), LNEXT(*), NP\n DOUBLE PRECISION PX, PY, X(*), Y(*), XMIN, YMIN, DX,\n . DY, DSQ\nC\nC***********************************************************\nC\nC\nC Given a set of N nodes and the data structure defined in\nC Subroutine STORE2, this subroutine uses the cell method to\nC find the closest unmarked node NP to a specified point P.\nC NP is then marked by setting LNEXT(NP) to -LNEXT(NP). (A\nC node is marked if and only if the corresponding LNEXT ele-\nC ment is negative. The absolute values of LNEXT elements,\nC however, must be preserved.) Thus, the closest M nodes to\nC P may be determined by a sequence of M calls to this rou-\nC tine. Note that if the nearest neighbor to node K is to\nC be determined (PX = X(K) and PY = Y(K)), then K should be\nC marked before the call to this routine.\nC\nC The search is begun in the cell containing (or closest\nC to) P and proceeds outward in rectangular layers until all\nC cells which contain points within distance R of P have\nC been searched, where R is the distance from P to the first\nC unmarked node encountered (infinite if no unmarked nodes\nC are present).\nC\nC This code is essentially unaltered from the subroutine\nC of the same name in QSHEP2D.\nC\nC On input:\nC\nC PX,PY = Cartesian coordinates of the point P whose\nC nearest unmarked neighbor is to be found.\nC\nC X,Y = Arrays of length N, for N .GE. 2, containing\nC the Cartesian coordinates of the nodes.\nC\nC NR = Number of rows and columns in the cell grid.\nC Refer to Subroutine STORE2. NR .GE. 1.\nC\nC LCELL = NR by NR array of nodal indexes associated\nC with cells. Refer to Subroutine STORE2.\nC\nC LNEXT = Array of length N containing next-node\nC indexes (or their negatives). Refer to\nC Subroutine STORE2.\nC\nC XMIN,YMIN,DX,DY = Minimum nodal coordinates and cell\nC dimensions. DX and DY must be\nC positive. Refer to Subroutine\nC STORE2.\nC\nC Input parameters other than LNEXT are not altered by\nC this routine. With the exception of (PX,PY) and the signs\nC of LNEXT elements, these parameters should be unaltered\nC from their values on output from Subroutine STORE2.\nC\nC On output:\nC\nC NP = Index (for X and Y) of the nearest unmarked\nC node to P, or 0 if all nodes are marked or NR\nC .LT. 1 or DX .LE. 0 or DY .LE. 0. LNEXT(NP)\nC .LT. 0 IF NP .NE. 0.\nC\nC DSQ = Squared Euclidean distance between P and node\nC NP, or 0 if NP = 0.\nC\nC Modules required by GETNP2: None\nC\nC Intrinsic functions called by GETNP2: ABS, INT, SQRT\nC\nC***********************************************************\nC\n INTEGER I, I0, I1, I2, IMAX, IMIN, J, J0, J1, J2,\n . JMAX, JMIN, L, LMIN, LN\n LOGICAL FIRST\n DOUBLE PRECISION DELX, DELY, R, RSMIN, RSQ, XP, YP\n LMIN = 0\n RSMIM = 0.0\nC\nC Local parameters:\nC\nC DELX,DELY = PX-XMIN, PY-YMIN\nC FIRST = Logical variable with value TRUE iff the\nC first unmarked node has yet to be\nC encountered\nC I,J = Cell indexes in the range [I1,I2] X [J1,J2]\nC I0,J0 = Indexes of the cell containing or closest\nC to P\nC I1,I2,J1,J2 = Range of cell indexes defining the layer\nC whose intersection with the range\nC [IMIN,IMAX] X [JMIN,JMAX] is currently\nC being searched\nC IMIN,IMAX = Cell row indexes defining the range of the\nC search\nC JMIN,JMAX = Cell column indexes defining the range of\nC the search\nC L,LN = Indexes of nodes in cell (I,J)\nC LMIN = Current candidate for NP\nC R = Distance from P to node LMIN\nC RSMIN = Squared distance from P to node LMIN\nC RSQ = Squared distance from P to node L\nC XP,YP = Local copy of PX,PY -- coordinates of P\nC\n XP = PX\n YP = PY\nC\nC Test for invalid input parameters.\nC\n IF (NR .LT. 1 .OR. DX .LE. 0. .OR. DY .LE. 0.)\n . GO TO 9\nC\nC Initialize parameters.\nC\n FIRST = .TRUE.\n IMIN = 1\n IMAX = NR\n JMIN = 1\n JMAX = NR\n DELX = XP - XMIN\n DELY = YP - YMIN\n I0 = INT(DELX/DX) + 1\n IF (I0 .LT. 1) I0 = 1\n IF (I0 .GT. NR) I0 = NR\n J0 = INT(DELY/DY) + 1\n IF (J0 .LT. 1) J0 = 1\n IF (J0 .GT. NR) J0 = NR\n I1 = I0\n I2 = I0\n J1 = J0\n J2 = J0\nC\nC Outer loop on layers, inner loop on layer cells, excluding\nC those outside the range [IMIN,IMAX] X [JMIN,JMAX].\nC\n 1 DO 6 J = J1,J2\n IF (J .GT. JMAX) GO TO 7\n IF (J .LT. JMIN) GO TO 6\n DO 5 I = I1,I2\n IF (I .GT. IMAX) GO TO 6\n IF (I .LT. IMIN) GO TO 5\n IF (J .NE. J1 .AND. J .NE. J2 .AND. I .NE. I1\n . .AND. I .NE. I2) GO TO 5\nC\nC Search cell (I,J) for unmarked nodes L.\nC\n L = LCELL(I,J)\n IF (L .EQ. 0) GO TO 5\nC\nC Loop on nodes in cell (I,J).\nC\n 2 LN = LNEXT(L)\n IF (LN .LT. 0) GO TO 4\nC\nC Node L is not marked.\nC\n RSQ = (X(L)-XP)**2 + (Y(L)-YP)**2\n IF (.NOT. FIRST) GO TO 3\nC\nC Node L is the first unmarked neighbor of P encountered.\nC Initialize LMIN to the current candidate for NP, and\nC RSMIN to the squared distance from P to LMIN. IMIN,\nC IMAX, JMIN, and JMAX are updated to define the smal-\nC lest rectangle containing a circle of radius R =\nC Sqrt(RSMIN) centered at P, and contained in [1,NR] X\nC [1,NR] (except that, if P is outside the rectangle\nC defined by the nodes, it is possible that IMIN > NR,\nC IMAX < 1, JMIN > NR, or JMAX < 1). FIRST is reset to\nC FALSE.\nC\n LMIN = L\n RSMIN = RSQ\n R = SQRT(RSMIN)\n IMIN = INT((DELX-R)/DX) + 1\n IF (IMIN .LT. 1) IMIN = 1\n IMAX = INT((DELX+R)/DX) + 1\n IF (IMAX .GT. NR) IMAX = NR\n JMIN = INT((DELY-R)/DY) + 1\n IF (JMIN .LT. 1) JMIN = 1\n JMAX = INT((DELY+R)/DY) + 1\n IF (JMAX .GT. NR) JMAX = NR\n FIRST = .FALSE.\n GO TO 4\nC\nC Test for node L closer than LMIN to P.\nC\n 3 IF (RSQ .GE. RSMIN) GO TO 4\nC\nC Update LMIN and RSMIN.\nC\n LMIN = L\n RSMIN = RSQ\nC\nC Test for termination of loop on nodes in cell (I,J).\nC\n 4 IF (ABS(LN) .EQ. L) GO TO 5\n L = ABS(LN)\n GO TO 2\n 5 CONTINUE\n 6 CONTINUE\nC\nC Test for termination of loop on cell layers.\nC\n 7 IF (I1 .LE. IMIN .AND. I2 .GE. IMAX .AND.\n . J1 .LE. JMIN .AND. J2 .GE. JMAX) GO TO 8\n I1 = I1 - 1\n I2 = I2 + 1\n J1 = J1 - 1\n J2 = J2 + 1\n GO TO 1\nC\nC Unless no unmarked nodes were encountered, LMIN is the\nC closest unmarked node to P.\nC\n 8 IF (FIRST) GO TO 9\n NP = LMIN\n DSQ = RSMIN\n LNEXT(LMIN) = -LNEXT(LMIN)\n RETURN\nC\nC Error: NR, DX, or DY is invalid or all nodes are marked.\nC\n 9 NP = 0\n DSQ = 0.\n RETURN\n END\n SUBROUTINE GIVENS ( A,B, C,S)\n DOUBLE PRECISION A, B, C, S\nC\nC***********************************************************\nC\nC From SRFPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 09/01/88\nC\nC This subroutine constructs the Givens plane rotation,\nC\nC ( C S)\nC G = ( ) , where C*C + S*S = 1,\nC (-S C)\nC\nC which zeros the second component of the vector (A,B)**T\nC (transposed). Subroutine ROTATE may be called to apply\nC the transformation to a 2 by N matrix.\nC\nC This routine is identical to subroutine SROTG from the\nC LINPACK BLAS (Basic Linear Algebra Subroutines).\nC\nC On input:\nC\nC A,B = Components of the vector defining the rota-\nC tion. These are overwritten by values R\nC and Z (described below) which define C and S.\nC\nC On output:\nC\nC A = Signed Euclidean norm R of the input vector:\nC R = +/-SQRT(A*A + B*B)\nC\nC B = Value Z such that:\nC C = SQRT(1-Z*Z) and S=Z if ABS(Z) .LE. 1, and\nC C = 1/Z and S = SQRT(1-C*C) if ABS(Z) > 1.\nC\nC C = +/-(A/R) or 1 if R = 0.\nC\nC S = +/-(B/R) or 0 if R = 0.\nC\nC Modules required by GIVENS: None\nC\nC Intrinsic functions called by GIVENS: ABS, SQRT\nC\nC***********************************************************\nC\n DOUBLE PRECISION AA, BB, R, U, V\nC\nC Local parameters:\nC\nC AA,BB = Local copies of A and B\nC R = C*A + S*B = +/-SQRT(A*A+B*B)\nC U,V = Variables used to scale A and B for computing R\nC\n AA = A\n BB = B\n IF (ABS(AA) .LE. ABS(BB)) GO TO 1\nC\nC ABS(A) > ABS(B).\nC\n U = AA + AA\n V = BB/U\n R = SQRT(.25 + V*V) * U\n C = AA/R\n S = V * (C + C)\nC\nC Note that R has the sign of A, C > 0, and S has\nC SIGN(A)*SIGN(B).\nC\n B = S\n A = R\n RETURN\nC\nC ABS(A) .LE. ABS(B).\nC\n 1 IF (BB .EQ. 0.) GO TO 2\n U = BB + BB\n V = AA/U\nC\nC Store R in A.\nC\n A = SQRT(.25 + V*V) * U\n S = BB/A\n C = V * (S + S)\nC\nC Note that R has the sign of B, S > 0, and C has\nC SIGN(A)*SIGN(B).\nC\n B = 1.\n IF (C .NE. 0.) B = 1./C\n RETURN\nC\nC A = B = 0.\nC\n 2 C = 1.\n S = 0.\n RETURN\n END\n SUBROUTINE ROTATE (N,C,S, X,Y )\n INTEGER N\n DOUBLE PRECISION C, S, X(N), Y(N)\nC\nC***********************************************************\nC\nC From SRFPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 09/01/88\nC\nC ( C S)\nC This subroutine applies the Givens rotation ( ) to\nC (-S C)\nC (X(1) ... X(N))\nC the 2 by N matrix ( ) .\nC (Y(1) ... Y(N))\nC\nC This routine is identical to subroutine SROT from the\nC LINPACK BLAS (Basic Linear Algebra Subroutines).\nC\nC On input:\nC\nC N = Number of columns to be rotated.\nC\nC C,S = Elements of the Givens rotation. Refer to\nC subroutine GIVENS.\nC\nC The above parameters are not altered by this routine.\nC\nC X,Y = Arrays of length .GE. N containing the compo-\nC nents of the vectors to be rotated.\nC\nC On output:\nC\nC X,Y = Arrays containing the rotated vectors (not\nC altered if N < 1).\nC\nC Modules required by ROTATE: None\nC\nC***********************************************************\nC\n INTEGER I\n DOUBLE PRECISION XI, YI\nC\n DO 1 I = 1,N\n XI = X(I)\n YI = Y(I)\n X(I) = C*XI + S*YI\n Y(I) = -S*XI + C*YI\n 1 CONTINUE\n RETURN\n END\n SUBROUTINE SETUP2 (XK,YK,ZK,XI,YI,ZI,S1,S2,S3,R, ROW)\n DOUBLE PRECISION XK, YK, ZK, XI, YI, ZI, S1, S2, S3,\n . R, ROW(10)\nC\nC***********************************************************\nC\nC From CSHEP2D\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 02/03/97\nC\nC This subroutine sets up the I-th row of an augmented re-\nC gression matrix for a weighted least squares fit of a\nC cubic function f(x,y) to a set of data values z, where\nC f(XK,YK) = ZK. The first four columns (cubic terms) are\nC scaled by S3, the next three columns (quadratic terms)\nC are scaled by S2, and the eighth and ninth columns (lin-\nC ear terms) are scaled by S1.\nC\nC On input:\nC\nC XK,YK = Coordinates of node K.\nC\nC ZK = Data value at node K to be interpolated by f.\nC\nC XI,YI,ZI = Coordinates and data value at node I.\nC\nC S1,S2,S3 = Scale factors.\nC\nC R = Radius of influence about node K defining the\nC weight.\nC\nC The above parameters are not altered by this routine.\nC\nC ROW = Array of length 10.\nC\nC On output:\nC\nC ROW = Array containing a row of the augmented re-\nC gression matrix.\nC\nC Modules required by SETUP2: None\nC\nC Intrinsic function called by SETUP2: SQRT\nC\nC***********************************************************\nC\n INTEGER I\n DOUBLE PRECISION D, DX, DXSQ, DY, DYSQ, W, W1, W2, W3\nC\nC Local parameters:\nC\nC D = Distance between nodes K and I\nC DX = XI - XK\nC DXSQ = DX*DX\nC DY = YI - YK\nC DYSQ = DY*DY\nC I = DO-loop index\nC W = Weight associated with the row: (R-D)/(R*D)\nC (0 if D = 0 or D > R)\nC W1 = S1*W\nC W2 = S2*W\nC W3 = W3*W\nC\n DX = XI - XK\n DY = YI - YK\n DXSQ = DX*DX\n DYSQ = DY*DY\n D = SQRT(DXSQ + DYSQ)\n IF (D .LE. 0. .OR. D .GE. R) GO TO 1\n W = (R-D)/R/D\n W1 = S1*W\n W2 = S2*W\n W3 = S3*W\n ROW(1) = DXSQ*DX*W3\n ROW(2) = DXSQ*DY*W3\n ROW(3) = DX*DYSQ*W3\n ROW(4) = DYSQ*DY*W3\n ROW(5) = DXSQ*W2\n ROW(6) = DX*DY*W2\n ROW(7) = DYSQ*W2\n ROW(8) = DX*W1\n ROW(9) = DY*W1\n ROW(10) = (ZI - ZK)*W\n RETURN\nC\nC Nodes K and I coincide or node I is outside of the radius\nC of influence. Set ROW to the zero vector.\nC\n 1 DO 2 I = 1,10\n ROW(I) = 0.\n 2 CONTINUE\n RETURN\n END\n SUBROUTINE STORE2 (N,X,Y,NR, LCELL,LNEXT,XMIN,YMIN,DX,\n . DY,IER)\n INTEGER N, NR, LCELL(NR,NR), LNEXT(N), IER\n DOUBLE PRECISION X(N), Y(N), XMIN, YMIN, DX, DY\nC\nC***********************************************************\nC\nC From CSHEP2D\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 03/28/97\nC\nC Given a set of N arbitrarily distributed nodes in the\nC plane, this subroutine creates a data structure for a\nC cell-based method of solving closest-point problems. The\nC smallest rectangle containing the nodes is partitioned\nC into an NR by NR uniform grid of cells, and nodes are as-\nC sociated with cells. In particular, the data structure\nC stores the indexes of the nodes contained in each cell.\nC For a uniform random distribution of nodes, the nearest\nC node to an arbitrary point can be determined in constant\nC expected time.\nC\nC This code is essentially unaltered from the subroutine\nC of the same name in QSHEP2D.\nC\nC On input:\nC\nC N = Number of nodes. N .GE. 2.\nC\nC X,Y = Arrays of length N containing the Cartesian\nC coordinates of the nodes.\nC\nC NR = Number of rows and columns in the grid. The\nC cell density (average number of nodes per cell)\nC is D = N/(NR**2). A recommended value, based\nC on empirical evidence, is D = 3 -- NR =\nC Sqrt(N/3). NR .GE. 1.\nC\nC The above parameters are not altered by this routine.\nC\nC LCELL = Array of length .GE. NR**2.\nC\nC LNEXT = Array of length .GE. N.\nC\nC On output:\nC\nC LCELL = NR by NR cell array such that LCELL(I,J)\nC contains the index (for X and Y) of the\nC first node (node with smallest index) in\nC cell (I,J), or LCELL(I,J) = 0 if no nodes\nC are contained in the cell. The upper right\nC corner of cell (I,J) has coordinates (XMIN+\nC I*DX,YMIN+J*DY). LCELL is not defined if\nC IER .NE. 0.\nC\nC LNEXT = Array of next-node indexes such that\nC LNEXT(K) contains the index of the next node\nC in the cell which contains node K, or\nC LNEXT(K) = K if K is the last node in the\nC cell for K = 1,...,N. (The nodes contained\nC in a cell are ordered by their indexes.)\nC If, for example, cell (I,J) contains nodes\nC 2, 3, and 5 (and no others), then LCELL(I,J)\nC = 2, LNEXT(2) = 3, LNEXT(3) = 5, and\nC LNEXT(5) = 5. LNEXT is not defined if\nC IER .NE. 0.\nC\nC XMIN,YMIN = Cartesian coordinates of the lower left\nC corner of the rectangle defined by the\nC nodes (smallest nodal coordinates) un-\nC less IER = 1. The upper right corner is\nC (XMAX,YMAX) for XMAX = XMIN + NR*DX and\nC YMAX = YMIN + NR*DY.\nC\nC DX,DY = Dimensions of the cells unless IER = 1. DX\nC = (XMAX-XMIN)/NR and DY = (YMAX-YMIN)/NR,\nC where XMIN, XMAX, YMIN, and YMAX are the\nC extrema of X and Y.\nC\nC IER = Error indicator:\nC IER = 0 if no errors were encountered.\nC IER = 1 if N < 2 or NR < 1.\nC IER = 2 if DX = 0 or DY = 0.\nC\nC Modules required by STORE2: None\nC\nC Intrinsic functions called by STORE2: DBLE, INT\nC\nC***********************************************************\nC\n INTEGER I, J, K, L, NN, NNR\n DOUBLE PRECISION DELX, DELY, XMN, XMX, YMN, YMX\nC\nC Local parameters:\nC\nC DELX,DELY = Components of the cell dimensions -- local\nC copies of DX,DY\nC I,J = Cell indexes\nC K = Nodal index\nC L = Index of a node in cell (I,J)\nC NN = Local copy of N\nC NNR = Local copy of NR\nC XMN,XMX = Range of nodal X coordinates\nC YMN,YMX = Range of nodal Y coordinates\nC\n NN = N\n NNR = NR\n IF (NN .LT. 2 .OR. NNR .LT. 1) GO TO 5\nC\nC Compute the dimensions of the rectangle containing the\nC nodes.\nC\n XMN = X(1)\n XMX = XMN\n YMN = Y(1)\n YMX = YMN\n DO 1 K = 2,NN\n IF (X(K) .LT. XMN) XMN = X(K)\n IF (X(K) .GT. XMX) XMX = X(K)\n IF (Y(K) .LT. YMN) YMN = Y(K)\n IF (Y(K) .GT. YMX) YMX = Y(K)\n 1 CONTINUE\n XMIN = XMN\n YMIN = YMN\nC\nC Compute cell dimensions and test for zero area.\nC\n DELX = (XMX-XMN)/DBLE(NNR)\n DELY = (YMX-YMN)/DBLE(NNR)\n DX = DELX\n DY = DELY\n IF (DELX .EQ. 0. .OR. DELY .EQ. 0.) GO TO 6\nC\nC Initialize LCELL.\nC\n DO 3 J = 1,NNR\n DO 2 I = 1,NNR\n LCELL(I,J) = 0\n 2 CONTINUE\n 3 CONTINUE\nC\nC Loop on nodes, storing indexes in LCELL and LNEXT.\nC\n DO 4 K = NN,1,-1\n I = INT((X(K)-XMN)/DELX) + 1\n IF (I .GT. NNR) I = NNR\n J = INT((Y(K)-YMN)/DELY) + 1\n IF (J .GT. NNR) J = NNR\n L = LCELL(I,J)\n LNEXT(K) = L\n IF (L .EQ. 0) LNEXT(K) = K\n LCELL(I,J) = K\n 4 CONTINUE\nC\nC No errors encountered.\nC\n IER = 0\n RETURN\nC\nC Invalid input parameter.\nC\n 5 IER = 1\n RETURN\nC\nC DX = 0 or DY = 0.\nC\n 6 IER = 2\n RETURN\n END\n", "meta": {"hexsha": "32a69a6b182d689d91b9d34ba392e2f171ac5824", "size": 57607, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/calelm/cshep2d.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/cshep2d.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/cshep2d.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": 31.8094975152, "max_line_length": 60, "alphanum_fraction": 0.5278872359, "num_tokens": 18848, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768620069626, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6814532413479961}} {"text": "C NCLFORTSTART\n subroutine detcalc(a,n,det)\n implicit none\nc input\n integer n\n double precision a(n,n)\nc output\n double precision det\nC NCLEND\nc local (dynamic)\n integer indx(n)\n\n call dtrm(a,n,det,indx)\n\n return\n end\nc=======================================================================\n\nc Updated 10/24/2001.\nc\nccccccccccccccccccccccccc Program 4.2 cccccccccccccccccccccccccc\nc\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\nc c\nc Please Note: c\nc c\nc (1) This computer program is part of the book, \"An Introduction to c\nc Computational Physics,\" written by Tao Pang and published and c\nc copyrighted by Cambridge University Press in 1997. c\nc c\nc (2) No warranties, express or implied, are made for this program. c\nc c\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\nc\n SUBROUTINE DTRM(A,N,D,INDX)\n IMPLICIT NONE\nC\nC Subroutine for evaluating the determinant of a matrix using \nC the partial-pivoting Gaussian elimination scheme.\nC\n INTEGER N\n DOUBLE PRECISION A(N,N), D\n INTEGER INDX(N)\nC\n INTEGER I, J, MSGN\n\n CALL ELGS(A,N,INDX)\nC\n D = 1.0D0\n DO I = 1,N\n D = D*A(INDX(I),I)\n END DO \nC\n MSGN = 1\n DO I=1,N\n DO WHILE (I.NE.INDX(I))\n MSGN = -MSGN\n J = INDX(I)\n INDX(I) = INDX(J)\n INDX(J) = J\n END DO\n END DO\n D = MSGN*D\nC\n RETURN\n END\nC ---\n SUBROUTINE ELGS(A,N,INDX)\n IMPLICIT NONE\n INTEGER N\n DOUBLE PRECISION A(N,N),C(N)\n INTEGER INDX(N)\nC\nC Subroutine to perform the partial-pivoting Gaussian elimination.\nC A(N,N) is the original matrix in the input and transformed\nC matrix plus the pivoting element ratios below the diagonal in\nC the output. INDX(N) records the pivoting order.\n\n INTEGER I, J, K, ITMP\n DOUBLE PRECISION C1, PI1, PI, PJ\nC\nC Initialize the index\nC\n DO I=1,N\n INDX(I) = I\n END DO\nC\nC Find the rescaling factors, one from each row\nC\n DO I=1,N\n C1= 0.0D0\n DO J=1,N\n C1 = AMAX1(C1,ABS(A(I,J)))\n END DO\n C(I) = C1\n END DO\nC\nC Search the pivoting (largest) element from each column\nC\n DO J=1,N-1\n PI1 = 0.0D0\n DO I=J,N\n PI = ABS(A(INDX(I),J))/C(INDX(I))\n IF (PI.GT.PI1) THEN\n PI1 = PI\n K = I\n ELSE\n ENDIF\n END DO\nC\nC Interchange the rows via INDX(N) to record pivoting order\nC\n ITMP = INDX(J)\n INDX(J) = INDX(K)\n INDX(K) = ITMP\n DO I=J+1,N\n PJ = A(INDX(I),J)/A(INDX(J),J)\nC\nC Record pivoting ratios below the diagonal\nC\n A(INDX(I),J) = PJ\nC\nC Modify other elements accordingly\nC\n DO K=J+1,N\n A(INDX(I),K) = A(INDX(I),K)-PJ*A(INDX(J),K)\n END DO\n END DO\n END DO\nC\n RETURN\n END\n", "meta": {"hexsha": "31d6fd6a5411e5c89ee3eca59530075bc87f1275", "size": 3396, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ni/src/lib/nfpfort/det_code42.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "ni/src/lib/nfpfort/det_code42.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "ni/src/lib/nfpfort/det_code42.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 25.5338345865, "max_line_length": 72, "alphanum_fraction": 0.4994110718, "num_tokens": 947, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430562234878, "lm_q2_score": 0.819893340314393, "lm_q1q2_score": 0.6814486566461888}} {"text": "submodule (stdlib_linalg) stdlib_linalg_outer_product\n\n implicit none\n\ncontains\n\n pure module function outer_product_rdp(u, v) result(res)\n real(dp), intent(in) :: u(:), v(:)\n real(dp) :: res(size(u),size(v))\n integer :: col\n do col = 1, size(v)\n res(:,col) = v(col) * u\n end do\n end function outer_product_rdp\n pure module function outer_product_cdp(u, v) result(res)\n complex(dp), intent(in) :: u(:), v(:)\n complex(dp) :: res(size(u),size(v))\n integer :: col\n do col = 1, size(v)\n res(:,col) = v(col) * u\n end do\n end function outer_product_cdp\n pure module function outer_product_iint32(u, v) result(res)\n integer(int32), intent(in) :: u(:), v(:)\n integer(int32) :: res(size(u),size(v))\n integer :: col\n do col = 1, size(v)\n res(:,col) = v(col) * u\n end do\n end function outer_product_iint32\n\nend submodule\n", "meta": {"hexsha": "1890982fa9b984ce41cfa9a68ca50971d2cabe22", "size": 925, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/stdlib_linalg_outer_product.f90", "max_stars_repo_name": "zoziha/dp-stdlib", "max_stars_repo_head_hexsha": "d317f4d273cb0fcabf532578a7ec0e4687e18700", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-12-08T04:45:43.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-09T11:42:41.000Z", "max_issues_repo_path": "src/stdlib_linalg_outer_product.f90", "max_issues_repo_name": "zoziha/dp-stdlib", "max_issues_repo_head_hexsha": "d317f4d273cb0fcabf532578a7ec0e4687e18700", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2021-12-08T12:35:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-17T02:33:12.000Z", "max_forks_repo_path": "src/stdlib_linalg_outer_product.f90", "max_forks_repo_name": "zoziha/dp-stdlib", "max_forks_repo_head_hexsha": "d317f4d273cb0fcabf532578a7ec0e4687e18700", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-09T01:54:34.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-09T01:54:34.000Z", "avg_line_length": 28.0303030303, "max_line_length": 63, "alphanum_fraction": 0.587027027, "num_tokens": 267, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430645886583, "lm_q2_score": 0.8198933271118221, "lm_q1q2_score": 0.6814486525315111}} {"text": "! ---- Monte Carlo integration\n\n program MonteCarlo\n use sci \n use common \n use Monte \n\n implicit real*8(a-h, o-z)\n\n \n real*8, dimension(nx) :: rho \n \n integer (kind = 4) adjustInterval \n \n integer (kind = 4) thermSteps\n \n real*8 gasdev, ran1 \n\n MCSteps = 10000\n\n\n\n!#def oneMonteCarloStep():\n!\n! # perform N Metropolis steps\n! #for i in range(N):\n! # MetropolisStep()\n\n\n\n write(6, *) 'Monte Carlo for Gaussian integration '\n\n print *, '---------------------------------'\n print *, \" Enter number of Monte Carlo steps: \", MCSteps \n\n xmax = 6d0\n xmin = -6d0\n dx = (xmax-xmin)/nx\n \n delta = 1.0 ! jump size \n idum = 54 \n \n! \"\"\"initialize the random walkers\"\"\"\n x = rand(0)\n \n rho = 0d0\n\n! perform 20% of MCSteps as thermalization steps\n! and adjust step size so acceptance ratio ~50%\n\n thermSteps = int(0.2 * MCSteps)\n adjustInterval = int(0.1 * thermSteps) + 1\n nAccept = 0\n print *, ' Performing thermalization steps ...', thermSteps\n\n do i=1, thermSteps\n !oneMonteCarloStep()\n \n call MetropolisStep(x, rho) \n\n if(mod(i+1, adjustInterval) == 0) then\n \n delta = delta * dble(nAccept) / (0.5 * dble(adjustInterval))\n nAccept = 0\n \n endif\n enddo \n \n print *, ' Adjusted Gaussian step size ', delta\n\n\n\n nAccept = 0 ! accumulator for number of accepted steps\n eSum = 0.\n eSqdSum = 0.\n\n nAccept = 0;\n print *, \" Performing production steps ...\", MCSteps\n\n\n\n do i=1, MCSteps\n !MonteCarloStep()\n call MetropolisStep(x, rho)\n \n enddo\n\n\n! compute and print energy\n\n eAve = eSum / MCSteps\n\n eVar = eSqdSum / MCSteps - eAve * eAve\n\n error = sqrt(eVar / MCSteps)\n\n write(6, 1012) eAve, error\n1012 format('Expectation = ',f14.8, ' +/- ', f14.8)\n\n write(6, 1013) eVar\n1013 format('Variance = ',f14.8) \n\n\n! write wave function squared in file\n open(100, file = \"psiSqd.data\")\n\n\n psiNorm = sum(rho) * dx\n do i=1,nx\n z = xmin + i * dx\n write(100, *) z, rho(i) / psiNorm\n enddo\n\n stop \n end program \n ! ---------------------------\n\n subroutine prob(y, x, a)\n implicit real*8(a-h, o-z)\n\n! trial function is exp(-alpha*x^2)\n! compute the ratio of rho(x') / rho(x)\n\n alpha = 1.0\n a = exp(- alpha/2. * (y-2)**2 + alpha * (x-2)**2/2)\n end subroutine\n\n! --- compute the local energy\n\n subroutine local(x,z)\n\n use sci, only : pi\n\n implicit real*8(a-h, o-z)\n\n z = sqrt(1./2./pi) * exp(-1./2. * (x+2)**2)\n\n end subroutine\n\n! --- Metropolis Scheme\n\n subroutine MetropolisStep(x, rho)\n\n use Monte, only : idum, xmin, xmax, dx, delta \n use common, only : eSum, eSqdSum, nAccept, nx \n \n implicit real*8(a-h, o-z)\n \n real*8 gasdev \n real*8 rho(nx) \n \n \n \n\n ! chose a walker at random\n ! n = int(np.random.rand() * N)\n\n ! make a trial move\n y = x + delta * gasdev(idum)\n\n ! Metropolis test\n call prob(y,x,a)\n \n if (a > rand(0)) then\n \n x = y\n nAccept = nAccept + 1\n endif\n\n ! accumulate local functions\n call local(x,e)\n eSum = eSum + e\n eSqdSum = eSqdSum + e * e\n i = int((x - xmin) / dx)\n if(i .ge. 0 .and. i < nx) then\n rho(i) = rho(i) + 1\n endif\n\n return\n end subroutine\n\n", "meta": {"hexsha": "9d026a771660d2da1c4f7ca69c2ca481dffb1538", "size": 3375, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "QMC/MC_exchange/Metropolis/1dim/monte.f90", "max_stars_repo_name": "binggu56/qmd", "max_stars_repo_head_hexsha": "e2628710de15f8a8b9a1280fcf92f9e87559414c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "QMC/MC_exchange/Metropolis/1dim/monte.f90", "max_issues_repo_name": "binggu56/qmd", "max_issues_repo_head_hexsha": "e2628710de15f8a8b9a1280fcf92f9e87559414c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "QMC/MC_exchange/Metropolis/1dim/monte.f90", "max_forks_repo_name": "binggu56/qmd", "max_forks_repo_head_hexsha": "e2628710de15f8a8b9a1280fcf92f9e87559414c", "max_forks_repo_licenses": ["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.543956044, "max_line_length": 72, "alphanum_fraction": 0.5374814815, "num_tokens": 1062, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972684083609, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.6813838162621437}} {"text": "program elemental_test\n use, intrinsic :: iso_fortran_env, only : INT32, INT64, REAL64\n implicit none\n integer, parameter :: n = 16, p = 6\n integer :: i\n integer(kind=INT64), dimension(n) :: input = [ (i - 1, i = 1, n) ], &\n output\n real(kind=REAL64), dimension(p) :: x = [ (real(i - 1, kind=REAL64), &\n i = 1, p) ], &\n y\n integer(kind=INT64), dimension(p) :: degree = [ (i - 1, i = 1, p) ]\n\n print '(A)', '# factorial'\n output = factorial(input)\n do i = 1, n\n print '(I2, I20)', input(i), output(i)\n end do\n\n print '(A)', '# in place factorial'\n call in_place_factorial(input)\n do i = 1, n\n print '(I2, I20)', i, input(i)\n end do\n\n print '(A)', '# powers'\n y = power(x, degree)\n do i = 1, p\n print '(F8.2, I4, F20.2)', x(i), degree(i), y(i)\n end do\n\ncontains\n\n elemental function factorial(n) result(fac)\n implicit none\n integer(kind=INT64), intent(in) :: n\n integer(kind=INT64) :: fac\n integer(kind=INT32) :: i\n fac = 1\n do i = 2, n\n fac = fac*i\n end do\n end function factorial\n\n elemental subroutine in_place_factorial(i)\n implicit none\n integer(kind=int64), intent(inout) :: i\n i = factorial(i)\n end subroutine in_place_factorial\n\n elemental function power(x, n) result(y)\n implicit none\n real(kind=REAL64), intent(in) :: x\n integer(kind=INT64), intent(in) :: n\n real(kind=REAL64) :: y\n y = x**n\n end function power\n\nend program elemental_test\n", "meta": {"hexsha": "1b3a3d4cd97bcedcbd8de502b520f22234c9ffcf", "size": 1683, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran/Functions/elemental_test.f90", "max_stars_repo_name": "Gjacquenot/training-material", "max_stars_repo_head_hexsha": "16b29962bf5683f97a1072d961dd9f31e7468b8d", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 115, "max_stars_repo_stars_event_min_datetime": "2015-03-23T13:34:42.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T00:27:21.000Z", "max_issues_repo_path": "Fortran/Functions/elemental_test.f90", "max_issues_repo_name": "Gjacquenot/training-material", "max_issues_repo_head_hexsha": "16b29962bf5683f97a1072d961dd9f31e7468b8d", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 56, "max_issues_repo_issues_event_min_datetime": "2015-02-25T15:04:26.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-03T07:42:48.000Z", "max_forks_repo_path": "Fortran/Functions/elemental_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": 28.5254237288, "max_line_length": 73, "alphanum_fraction": 0.513368984, "num_tokens": 478, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972549785201, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6813838101645451}} {"text": "! \"utility_random_walk.f95\" generates random walk distributions.\n\nsubroutine random_walk_fast_2d(step_size, phi, box_size, x_start, y_start, periodic, length, x, y)\n ! Generates a random walk on a 2D grid.\n !\n ! Parameters\n ! ----------\n ! step_size : float\n ! A set of input step size values.\n ! phi : array\n ! Random angles.\n ! box_size : float\n ! box size parameters.\n ! x_start, y_start : float\n ! Starting x & y coordinates.\n ! periodic : {0, 1}, int\n ! 0 = does not enforce periodic boundary conditions.\n ! 1 = enforces periodic boundary conditions.\n ! length : int\n ! Length of the x & y coordinates.\n !\n ! Returns\n ! -------\n ! x, y : array\n ! The coordinates of the random walk simulation.\n\n implicit none\n\n integer, intent(in) :: length\n real, intent(in) :: step_size(length), phi(length)\n real, intent(in) :: box_size, x_start, y_start\n integer, intent(in) :: periodic\n real, intent(out) :: x(length+1), y(length+1)\n integer :: i\n real :: delta_x, delta_y, x_current, y_current\n\n x(1) = x_start\n y(1) = y_start\n\n x_current = x_start\n y_current = y_start\n\n do i = 2, length+1\n\n delta_x = step_size(i-1)*cos(phi(i-1))\n delta_y = step_size(i-1)*sin(phi(i-1))\n\n x_current = x_current + delta_x\n y_current = y_current + delta_y\n\n if (periodic == 1) then\n\n do while (x_current < 0. .or. x_current > box_size)\n if (x_current < 0.) then\n x_current = x_current + box_size\n else if (x_current > box_size) then\n x_current = x_current - box_size\n end if\n end do\n\n do while (y_current < 0. .or. y_current > box_size)\n if (y_current < 0.) then\n y_current = y_current + box_size\n else if (y_current > box_size) then\n y_current = y_current - box_size\n end if\n end do\n\n end if\n\n x(i) = x_current\n y(i) = y_current\n\n end do\n\nend subroutine random_walk_fast_2d\n\nsubroutine random_walk_fast_3d(step_size, phi, theta, box_size, x_start, y_start, z_start, periodic, length, x, y, z)\n ! Generates a random walk on a 3D grid.\n !\n ! Parameters\n ! ----------\n ! step_size : float\n ! A set of input step size values.\n ! phi, theta : array\n ! Random phi (longitude) and theta (latitude) angles.\n ! box_size : float\n ! box size parameters.\n ! x_start, y_start, z_start : float\n ! Starting x & y coordinates.\n ! periodic : {0, 1}, int\n ! 0 = does not enforce periodic boundary conditions.\n ! 1 = enforces periodic boundary conditions.\n ! length : int\n ! Length of the x & y coordinates.\n !\n ! Returns\n ! -------\n ! x, y, z: array\n ! The coordinates of the random walk simulation.\n\n implicit none\n\n integer, intent(in) :: length\n real, intent(in) :: step_size(length), theta(length), phi(length)\n real, intent(in) :: box_size, x_start, y_start, z_start\n integer, intent(in) :: periodic\n real, intent(out) :: x(length+1), y(length+1), z(length+1)\n integer :: i\n real :: delta_x, delta_y, delta_z, x_current, y_current, z_current\n\n x(1) = x_start\n y(1) = y_start\n z(1) = z_start\n\n x_current = x_start\n y_current = y_start\n z_current = z_start\n\n do i = 2, length+1\n\n delta_x = step_size(i-1)*cos(phi(i-1))*sin(theta(i-1))\n delta_y = step_size(i-1)*sin(phi(i-1))*sin(theta(i-1))\n delta_z = step_size(i-1)*cos(theta(i-1))\n\n x_current = x_current + delta_x\n y_current = y_current + delta_y\n z_current = z_current + delta_z\n\n if (periodic == 1) then\n\n do while (x_current < 0. .or. x_current > box_size)\n if (x_current < 0.) then\n x_current = x_current + box_size\n else if (x_current > box_size) then\n x_current = x_current - box_size\n end if\n end do\n\n do while (y_current < 0. .or. y_current > box_size)\n if (y_current < 0.) then\n y_current = y_current + box_size\n else if (y_current > box_size) then\n y_current = y_current - box_size\n end if\n end do\n\n do while (z_current < 0. .or. z_current > box_size)\n if (z_current < 0.) then\n z_current = z_current + box_size\n else if (z_current > box_size) then\n z_current = z_current - box_size\n end if\n end do\n\n end if\n\n x(i) = x_current\n y(i) = y_current\n z(i) = z_current\n\n end do\n\nend subroutine random_walk_fast_3d\n", "meta": {"hexsha": "e2fea73221db597dcfd2d67de24f492a51bf02e4", "size": 4863, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mistree/levy_flight/utility_random_walk.f90", "max_stars_repo_name": "knaidoo29/MiSTree", "max_stars_repo_head_hexsha": "20ef822ca349d2cc8118bbeca277713f03e10cd2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 27, "max_stars_repo_stars_event_min_datetime": "2019-07-03T08:01:10.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T09:28:58.000Z", "max_issues_repo_path": "mistree/levy_flight/utility_random_walk.f90", "max_issues_repo_name": "knaidoo29/MiSTree", "max_issues_repo_head_hexsha": "20ef822ca349d2cc8118bbeca277713f03e10cd2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 15, "max_issues_repo_issues_event_min_datetime": "2019-09-12T03:56:20.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-14T22:27:44.000Z", "max_forks_repo_path": "mistree/levy_flight/utility_random_walk.f90", "max_forks_repo_name": "knaidoo29/MiSTree", "max_forks_repo_head_hexsha": "20ef822ca349d2cc8118bbeca277713f03e10cd2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2019-07-03T05:00:20.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-03T19:37:32.000Z", "avg_line_length": 29.4727272727, "max_line_length": 117, "alphanum_fraction": 0.5531564878, "num_tokens": 1315, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213853793452, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6813491249331246}} {"text": "! *********************************************************************\r\n! * *\r\n! * subroutine las2g *\r\n! * *\r\n! *********************************************************************\r\n! Single Precision Version 3.42\r\n! Written by Gordon A. Fenton, TUNS, July 19, 1992\r\n! Latest Update: Jun 9, 1999\r\n!\r\n! PURPOSE produces a 2-D quadrant symmetric stationary Gaussian random field\r\n! using the Local Average Subdivision algorithm.\r\n!\r\n! This routine creates a zero-mean realization of a 2-D random process given\r\n! its variance function (as defined by E.H. Vanmarcke in \"Random Fields:\r\n! Analysis and Synthesis\", MIT Press, 1984). Each discrete value generated\r\n! herein represents the local average of a realization of the process over\r\n! the area Dx x Dy, where (Dx,Dy) is the grid spacing of the desired field.\r\n! The construction of the realization proceeds recursively as follows;\r\n!\r\n! 1) generate a low resolution field of size k1 x k2. If (N1 x N2) is\r\n! the desired field resolution, then k1 and k2 are determined so\r\n! that N1 = k1*2**m, N2 = k2*2**m, where 2**m is a common factor and\r\n! k1*k2 <= MXK. Generally k1 and k2 are maximized where possible.\r\n! This is refered to subsequently as the Stage 0 generation.\r\n!\r\n! 2) subdivide the domain m times by dividing each cell into 4 equal\r\n! parts (2 x 2). In each subdivision, new random values are generated\r\n! for each new cell. The parent cells of the previous stage are used\r\n! to obtain best linear estimates of the mean of each new cell so that\r\n! the spatial correlation is approximated. Also upwards averaging is\r\n! preserved (ie the average of the 4 new values is the same as the\r\n! parent cell value). Only parent cells in a neighbourhood of 3 x 3\r\n! are considered (thus the approximation to the spatial correlation).\r\n!\r\n! The linear estimation of the mean is accomplished by using the covariance\r\n! between local averages over each cell, consistent with the goal of\r\n! producing a local average field. Note that this conditioning process\r\n! implies that the construction of cells near the edge of the boundary will\r\n! require the use of values which are, strictly speaking, outside the\r\n! boundary of the field in question. This is handled by using special\r\n! reduced neighbourhoods along the boundaries (equivalent to saying that\r\n! what goes on beyond the boundary has no effect on the process within the\r\n! boundary).\r\n!\r\n! Note that this routine sets up a number of parameters on the\r\n! first call and thus the time required to produce the first realization\r\n! is substantially greater than on subsequent calls (see INIT). For\r\n! more information on local average processes, see\r\n!\r\n! 1) G.A. Fenton, \"Simulation and Analysis of Random Fields\", Ph.D. thesis,\r\n! Dept. of Civil Eng. and Op. Research, Princeton University, Princeton,\r\n! New Jersey, 1990.\r\n! 2) G.A. Fenton and E.H. Vanmarcke \"Simulation of Random Fields\r\n! via Local Average Subdivision\", ASCE Journal of Engineering Mechanics,\r\n! Vol. 116, No. 8, August 1990.\r\n! 3) E. H. Vanmarcke, Random Fields: Analysis and Synthesis, MIT Press,\r\n! 1984\r\n! 4) G.A. Fenton, Error evaluation of three random field generators,\r\n! ASCE Journal of Engineering Mechanics (to appear), 1993.\r\n!\r\n! Arguments to this routine are as follows;\r\n!\r\n! Z real array of size at least N1 x (5*N2/4) which on output will\r\n! contain the realization of the 2-D process in the first N1 x N2\r\n! locations. When dimensioned as Z(N1,5*N2/4) in the calling routine\r\n! and indexed as Z(i,j), Z(1,1) is the lower left cell, Z(2,1) is\r\n! the next cell in the X direction (to the right), etc.,\r\n! while Z(1,2) is the next cell in the Y direction (upwards), etc.\r\n! The extra space is required for workspace (specifically to store\r\n! the previous stage in the subdivision). (output)\r\n!\r\n! N1,N2 number of cells to discretize the field in the x and y directions\r\n! respectively (corresponding to the first and second indices of Z\r\n! respectively). Both N1 and N2 must have the form N1 = k1 * 2**m\r\n! and N2 = k2 * 2**m where m is common to both and k1 and k2 are\r\n! positive integers satisfying k1*k2 <= MXK. Generally k1 and k2\r\n! are chosen to be as large as possible and still satisfy the above\r\n! requirements so the the first stage involves directly simulating\r\n! a k1 x k2 field by inversion of a covariance matrix.\r\n! A potential example is (N1,N2) = (160,256) which gives k1 = 5,\r\n! k2 = 8, and m = 5. Note that in general N1 and N2 cannot be chosen\r\n! arbitrarily - it is usually best to choose m first then\r\n! k1 and k2 so as to satisfy or exceed the problem requirements. Note\r\n! that because of the requirements on k1*k2, N1 cannot be more than\r\n! MXK times as big (or smaller) than N2. (input)\r\n!\r\n! XL,YL physical dimensions of the process. (input)\r\n!\r\n! dvarfn external real*8 function which returns the variance of the random\r\n! process averaged over a given area. dvarfn is referenced as follows\r\n!\r\n! var = dvarfn( V1, V2 )\r\n!\r\n! where (V1,V2) are the side dimensions of the rectangular averaging\r\n! domain. Any other parameters to the function must be passed by\r\n! common block from the calling routine. Note that the variance of\r\n! the random process averaged over the area (V1 x V2) is the product\r\n! of the point variance and the traditionally defined \"variance\"\r\n! function, as discussed by Vanmarcke (pg 186).\r\n!\r\n! KSEED integer seed to be used to initialize the pseudo-random number\r\n! generator. The generator is only initialized on the first call\r\n! to this routine or when abs(INIT) = 1.\r\n! If KSEED = 0, then a random seed will be used (based on the\r\n! process ID of the current program invocation - see iseed.f)\r\n! On output, KSEED is set to the value of the actual seed used.\r\n!\r\n! INIT integer flag which must be 1 when parameters of the process\r\n! are to be calculated or recalculated. If multiple realizations\r\n! of the same process are desired, then subsequent calls should\r\n! use INIT equal to 0 and M less than or equal to the value used \r\n! initially. Note that if INIT = -1 is used, then only the\r\n! initialization is performed.\r\n!\r\n! IOUT unit number to which error and warning messages are to be logged.\r\n! (input)\r\n! -------------------------------------------------------------------------\r\n! PARAMETERS:\r\n! MXM represents the maximum value that m can have in the decomposition\r\n! N = k * 2**m.\r\n!\r\n! MXK represents the maximum number of cells (k1 x k2) in the initial\r\n! field, k1*k2 <= MXK. If the value of MXK is changed here, it must\r\n! also be changed in LAS2I.\r\n!\r\n! NGS represents the maximum number of random Gaussian variates that can\r\n! be produced on each call to VNORM. NGS should be 3*[9*2**(MXM-1)],\r\n! but not less than MXK.\r\n!\r\n! Notes: \r\n! 1) Simulation timing is available through common block LASTYM where\r\n! TI is the time required to initialize the parameters of the\r\n! process and TS is the cumulative simulation time. These timings\r\n! are obtained through the function SECOND which returns elapsed\r\n! user time in seconds since the start of the program.\r\n! 2) In 2 and higher dimensions, the LAS method yeilds a slight pattern\r\n! in the point variance field. This is due to the neighborhood\r\n! approximations. This error lessens for larger scales of fluctuation\r\n! and smaller numbers of subdivisions.\r\n! 3) The parameter `tol' is the maximum relative error allowed on the\r\n! Cholesky decomposition of covariance matrices before a warning\r\n! message is emitted. The relative error is estimated by computing\r\n! the lower-right most element of L*L' and comparing to the original\r\n! element of A (where L*L' = A is the decomposition). This give some\r\n! measure of the roundoff errors accumulated in the computation of L.\r\n!\r\n! Requires:\r\n! 1) from libGAFsim:\tISEED, LAS2I, DCVIT2, DCVMT2, DCHOL2, CORN2D, SIDE2D,\r\n!\t\t\tINTR2D, DCVAA2, DCVAB2, DSIFA, DSISL, DAXPY, DSWAP,\r\n!\t\t\tIDAMAX, DDOT, VNORM, RANDF, SECOND\r\n! 2) user defined external variance function (see DVARFN)\r\n!\r\n! REVISION HISTORY:\r\n! 3.41\texport saved parameters via /las2gb/ (previously just static)\r\n! 3.42\treplaced dummy dimensions with a (*) for GNU's compiler (Jun 9/99)\r\n! ==========================================================================\r\n subroutine las2g( Z, N1, N2, XL, YL, dvarfn, kseed, init, iout )\r\n parameter( MXM = 9, MXK = 256, NGS = 6912 )\r\n real Z(*)\r\n real C0((MXK*(MXK + 1))/2), U(NGS)\r\n real CT(6,2), CC(6,4,MXM), CS(6,4,MXM), CI(6,MXM)\r\n real AT(3,3,2), AC(4,3,4,MXM), AS(6,3,4,MXM), AI(9,3,MXM)\r\n external dvarfn\r\n common/las2gb/C0,CT,CC,CS,CI,AT,AC,AS,AI,M,K1,K2,KK,NN\r\n common/LASTYM/ ti, ts\r\n data ifirst/1/, zero/0.0/, four/4.0/\r\n data tol/1.e-3/\r\n!-------------------------------------- initialize LAS generator -------------\r\n\r\n if( ifirst .eq. 1 .or. iabs(init) .eq. 1 ) then\r\n!\t\t\t\t\t\tstart timer\r\n ti = second()\r\n call las2i( dvarfn, N1, N2, XL, YL, kseed, MXM,C0, CT, CC, CS, &\r\n\t\t CI, AT, AC, AS, AI, M,k1, k2, kk, iout, tol )\r\n NN = N1*N2\r\n ifirst = 0\r\n!\t\t\t\t\t\tall done, set timers\r\n ts = zero\r\n ti = second() - ti\r\n if( init .eq. -1 ) return\r\n endif\r\n!-------------------------------------- generate realization -----------------\r\n tt = second()\r\n if( mod(M,2) .eq. 0 ) then\r\n iz = 0\r\n jz = NN\r\n else\r\n iz = NN\r\n jz = 0\r\n endif\r\n!\t\t\t\t\tgenerate stage 0 field\r\n call vnorm( U, kk )\r\n L = 1\r\n do 20 i = 1, kk\r\n Z(iz+i) = C0(L)*U(1)\r\n do 10 j = 2, i\r\n Z(iz+i) = Z(iz+i) + C0(L+j-1)*U(j)\r\n 10 continue\r\n L = L + i\r\n 20 continue\r\n!\t\t\t\t\tgenerate stage 1, 2, ..., M sub-fields\r\n jx = k1\r\n jy = k2\r\n nm = 1\r\n if( (k1.eq.1 .or. k2.eq.1) .and. M .gt. 0 ) then\r\n jq = max0(k1,k2)\r\n call vnorm( U, 3*jq )\r\n it = jz\r\n jz = iz\r\n iz = it\r\n ix = 2*k1\r\n iy = 2\r\n if( k1 .eq. 1 ) iy = 4\r\n i0 = iz + 1\r\n i1 = i0 + ix\r\n j0 = jz + 1\r\n Z(i0) = AT(1,1,1)*Z(j0) + AT(2,1,1)*Z(j0+1) + CT(1,1)*U(1)\r\n Z(i0+1) = AT(1,2,1)*Z(j0) + AT(2,2,1)*Z(j0+1) + CT(2,1)*U(1) + CT(3,1)*U(2)\r\n Z(i1) = AT(1,3,1)*Z(j0) + AT(2,3,1)*Z(j0+1) + CT(4,1)*U(1) + CT(5,1)*U(2) + CT(6,1)*U(3)\r\n Z(i1+1) = four*Z(j0) - Z(i0) - Z(i0+1) - Z(i1)\r\n L = 4\r\n do 30 js = 1, jq-2\r\n i0 = i0 + iy\r\n i1 = i1 + iy\r\n Z(i0) = AT(1,1,2)*Z(j0 ) + AT(2,1,2)*Z(j0+1) + AT(3,1,2)*Z(j0+2) + CT(1,2)*U(L)\r\n Z(i0+1) = AT(1,2,2)*Z(j0 ) + AT(2,2,2)*Z(j0+1) + AT(3,2,2)*Z(j0+2) + CT(2,2)*U(L) + CT(3,2)*U(L+1)\r\n Z(i1) = AT(1,3,2)*Z(j0 ) + AT(2,3,2)*Z(j0+1) + AT(3,3,2)*Z(j0+2) + CT(4,2)*U(L) + CT(5,2)*U(L+1) + CT(6,2)*U(L+2)\r\n Z(i1+1) = four*Z(j0+1) - Z(i0) - Z(i0+1) - Z(i1)\r\n j0 = j0 + 1\r\n L = L + 3\r\n 30 continue\r\n i0 = i0 + iy\r\n i1 = i1 + iy\r\n Z(i0) = AT(2,1,1)*Z(j0) + AT(1,1,1)*Z(j0+1) + CT(1,1)*U(1)\r\n Z(i0+1) = AT(2,2,1)*Z(j0) + AT(1,2,1)*Z(j0+1) + CT(2,1)*U(1) + CT(3,1)*U(2)\r\n Z(i1) = AT(2,3,1)*Z(j0) + AT(1,3,1)*Z(j0+1) + CT(4,1)*U(1) + CT(5,1)*U(2) + CT(6,1)*U(3)\r\n Z(i1+1) = four*Z(j0+1) - Z(i0) - Z(i0+1) - Z(i1)\r\n jx = 2*k1\r\n jy = 2*k2\r\n nm = 2\r\n endif\r\n\r\n do 80 i = nm, M\r\n!\t\t\t\t\t\tswap current and prev fields\r\n it = jz\r\n jz = iz\r\n iz = it\r\n!\t\t\t\t\t\tnew field dimensions\r\n ix = 2*jx\r\n iy = 2*jy\r\n!\t\t\t\t\t\tpointers into Z\r\n j0 = jz + 1\r\n j1 = j0 + jx\r\n i0 = iz + 1\r\n i1 = i0 + ix\r\n call vnorm( U, 3*jx )\r\n!\t\t\t\t\t\t\t\tcorner #1\r\n Z(i0) = AC(1,1,1,i)*Z(j0) + AC(2,1,1,i)*Z(j0+1) &\r\n\t\t + AC(3,1,1,i)*Z(j1) + AC(4,1,1,i)*Z(j1+1) &\r\n\t\t\t\t + CC(1, 1,i)*U(1)\r\n!\r\n Z(i0+1) = AC(1,2,1,i)*Z(j0) + AC(2,2,1,i)*Z(j0+1) &\r\n\t\t + AC(3,2,1,i)*Z(j1) + AC(4,2,1,i)*Z(j1+1) &\r\n\t\t\t\t + CC(2, 1,i)*U(1) + CC(3, 1,i)*U(2)\r\n Z(i1) = AC(1,3,1,i)*Z(j0) + AC(2,3,1,i)*Z(j0+1) &\r\n\t\t + AC(3,3,1,i)*Z(j1) + AC(4,3,1,i)*Z(j1+1) &\r\n\t\t\t\t + CC(4, 1,i)*U(1) + CC(5, 1,i)*U(2) &\r\n\t\t\t\t + CC(6, 1,i)*U(3)\r\n Z(i1+1) = four*Z(j0) - Z(i0) - Z(i0+1) - Z(i1)\r\n!\t\t\t\t\t\t\t\tside #1\r\n L = 4\r\n do 40 js = 1, jx-2\r\n i0 = i0 + 2\r\n i1 = i1 + 2\r\n Z(i0) = AS(1,1,1,i)*Z(j0 ) + AS(2,1,1,i)*Z(j0+1) &\r\n\t\t\t + AS(3,1,1,i)*Z(j0+2) + AS(4,1,1,i)*Z(j1 ) &\r\n\t\t\t\t\t + AS(5,1,1,i)*Z(j1+1) + AS(6,1,1,i)*Z(j1+2) &\r\n\t\t\t\t\t + CS(1, 1,i)*U(L)\r\n Z(i0+1) = AS(1,2,1,i)*Z(j0 ) + AS(2,2,1,i)*Z(j0+1) &\r\n\t\t\t + AS(3,2,1,i)*Z(j0+2) + AS(4,2,1,i)*Z(j1 ) &\r\n\t\t\t\t\t + AS(5,2,1,i)*Z(j1+1) + AS(6,2,1,i)*Z(j1+2) &\r\n\t\t\t\t\t + CS(2, 1,i)*U(L) + CS(3, 1,i)*U(L+1)\r\n Z(i1) = AS(1,3,1,i)*Z(j0 ) + AS(2,3,1,i)*Z(j0+1) &\r\n\t\t\t + AS(3,3,1,i)*Z(j0+2) + AS(4,3,1,i)*Z(j1 ) &\r\n\t\t\t\t\t + AS(5,3,1,i)*Z(j1+1) + AS(6,3,1,i)*Z(j1+2) &\r\n\t\t\t\t\t + CS(4, 1,i)*U(L) + CS(5, 1,i)*U(L+1) &\r\n\t\t\t\t\t + CS(6, 1,i)*U(L+2)\r\n Z(i1+1) = four*Z(j0+1) - Z(i0) - Z(i0+1) - Z(i1)\r\n j0 = j0 + 1\r\n j1 = j1 + 1\r\n L = L + 3\r\n 40 continue\r\n!\t\t\t\t\t\t\t\tcorner #2\r\n i0 = i0 + 2\r\n i1 = i1 + 2\r\n Z(i0) = AC(1,1,2,i)*Z(j0) + AC(2,1,2,i)*Z(j0+1) &\r\n\t\t + AC(3,1,2,i)*Z(j1) + AC(4,1,2,i)*Z(j1+1) &\r\n\t\t\t\t + CC(1, 2,i)*U(L)\r\n Z(i0+1) = AC(1,2,2,i)*Z(j0) + AC(2,2,2,i)*Z(j0+1) &\r\n\t\t + AC(3,2,2,i)*Z(j1) + AC(4,2,2,i)*Z(j1+1) &\r\n\t\t\t\t + CC(2, 2,i)*U(L) + CC(3, 2,i)*U(L+1)\r\n Z(i1) = AC(1,3,2,i)*Z(j0) + AC(2,3,2,i)*Z(j0+1) &\r\n\t\t + AC(3,3,2,i)*Z(j1) + AC(4,3,2,i)*Z(j1+1) &\r\n\t\t\t\t + CC(4, 2,i)*U(L) + CC(5, 2,i)*U(L+1) &\r\n\t\t\t\t + CC(6, 2,i)*U(L+2)\r\n Z(i1+1) = four*Z(j0+1) - Z(i0) - Z(i0+1) - Z(i1)\r\n\r\n j0 = jz + 1\r\n do 60 ks = 1, jy-2\r\n j1 = j0 + jx\r\n j2 = j1 + jx\r\n i0 = i1 + 2\r\n i1 = i0 + ix\r\n call vnorm( U, 3*jx )\r\n!\t\t\t\t\t\t\t\tside #2\r\n Z(i0) = AS(1,1,2,i)*Z(j0) + AS(2,1,2,i)*Z(j0+1) &\r\n\t\t\t + AS(3,1,2,i)*Z(j1) + AS(4,1,2,i)*Z(j1+1) &\r\n\t\t\t\t\t + AS(5,1,2,i)*Z(j2) + AS(6,1,2,i)*Z(j2+1) &\r\n\t\t\t\t\t + CS(1, 2,i)*U(1)\r\n Z(i0+1) = AS(1,2,2,i)*Z(j0) + AS(2,2,2,i)*Z(j0+1) &\r\n\t\t\t + AS(3,2,2,i)*Z(j1) + AS(4,2,2,i)*Z(j1+1) &\r\n\t\t\t\t\t + AS(5,2,2,i)*Z(j2) + AS(6,2,2,i)*Z(j2+1) &\r\n\t\t\t\t\t + CS(2, 2,i)*U(1) + CS(3, 2,i)*U(2)\r\n Z(i1) = AS(1,3,2,i)*Z(j0) + AS(2,3,2,i)*Z(j0+1) &\r\n\t\t\t + AS(3,3,2,i)*Z(j1) + AS(4,3,2,i)*Z(j1+1) &\r\n\t\t\t\t\t + AS(5,3,2,i)*Z(j2) + AS(6,3,2,i)*Z(j2+1) &\r\n\t\t\t\t\t + CS(4, 2,i)*U(1) + CS(5, 2,i)*U(2) &\r\n\t\t\t\t\t + CS(6, 2,i)*U(3)\r\n Z(i1+1) = four*Z(j1) - Z(i0) - Z(i0+1) - Z(i1)\r\n!\t\t\t\t\t\t\t\tinterior\r\n L = 4\r\n do 50 js = 1, jx-2\r\n i0 = i0 + 2\r\n it = i0 + 1\r\n i1 = i1 + 2\r\n Z(i0)=AI(1,1,i)*Z(j0)+AI(2,1,i)*Z(j0+1)+AI(3,1,i)*Z(j0+2) &\r\n\t\t\t +AI(4,1,i)*Z(j1)+AI(5,1,i)*Z(j1+1)+AI(6,1,i)*Z(j1+2) &\r\n\t\t\t\t\t +AI(7,1,i)*Z(j2)+AI(8,1,i)*Z(j2+1)+AI(9,1,i)*Z(j2+2) &\r\n\t\t\t\t\t +CI(1, i)*U(L)\r\n Z(it)=AI(1,2,i)*Z(j0)+AI(2,2,i)*Z(j0+1)+AI(3,2,i)*Z(j0+2) &\r\n\t\t\t +AI(4,2,i)*Z(j1)+AI(5,2,i)*Z(j1+1)+AI(6,2,i)*Z(j1+2) &\r\n\t\t\t\t\t +AI(7,2,i)*Z(j2)+AI(8,2,i)*Z(j2+1)+AI(9,2,i)*Z(j2+2) &\r\n\t\t\t\t\t +CI(2, i)*U(L) +CI(3, i)*U(L+1)\r\n Z(i1)=AI(1,3,i)*Z(j0)+AI(2,3,i)*Z(j0+1)+AI(3,3,i)*Z(j0+2) &\r\n\t\t\t +AI(4,3,i)*Z(j1)+AI(5,3,i)*Z(j1+1)+AI(6,3,i)*Z(j1+2) &\r\n\t\t\t\t\t +AI(7,3,i)*Z(j2)+AI(8,3,i)*Z(j2+1)+AI(9,3,i)*Z(j2+2) &\r\n\t\t\t\t\t +CI(4, i)*U(L) +CI(5, i)*U(L+1) +CI(6, i)*U(L+2)\r\n Z(i1+1) = four*Z(j1+1) - Z(i0) - Z(it) - Z(i1)\r\n j0 = j0 + 1\r\n j1 = j1 + 1\r\n j2 = j2 + 1\r\n L = L + 3\r\n 50 continue\r\n!\t\t\t\t\t\t\t\tside #3\r\n i0 = i0 + 2\r\n i1 = i1 + 2\r\n Z(i0) = AS(1,1,3,i)*Z(j0) + AS(2,1,3,i)*Z(j0+1) &\r\n\t\t\t + AS(3,1,3,i)*Z(j1) + AS(4,1,3,i)*Z(j1+1) &\r\n\t\t\t\t\t + AS(5,1,3,i)*Z(j2) + AS(6,1,3,i)*Z(j2+1) &\r\n\t\t\t\t\t + CS(1, 3,i)*U(L)\r\n Z(i0+1) = AS(1,2,3,i)*Z(j0) + AS(2,2,3,i)*Z(j0+1) &\r\n\t\t\t + AS(3,2,3,i)*Z(j1) + AS(4,2,3,i)*Z(j1+1) &\r\n\t\t\t\t\t + AS(5,2,3,i)*Z(j2) + AS(6,2,3,i)*Z(j2+1) &\r\n\t\t\t\t\t + CS(2, 3,i)*U(L) + CS(3, 3,i)*U(L+1)\r\n Z(i1) = AS(1,3,3,i)*Z(j0) + AS(2,3,3,i)*Z(j0+1) &\r\n\t\t\t + AS(3,3,3,i)*Z(j1) + AS(4,3,3,i)*Z(j1+1) &\r\n\t\t\t\t\t + AS(5,3,3,i)*Z(j2) + AS(6,3,3,i)*Z(j2+1) &\r\n\t\t\t\t\t + CS(4, 3,i)*U(L) + CS(5, 3,i)*U(L+1) &\r\n\t\t\t\t\t + CS(6, 3,i)*U(L+2)\r\n Z(i1+1) = four*Z(j1+1) - Z(i0) - Z(i0+1) - Z(i1)\r\n j0 = j0 + 2\r\n 60 continue\r\n\r\n j1 = j0 + jx\r\n i0 = i1 + 2\r\n i1 = i0 + ix\r\n call vnorm( U, 3*jx )\r\n!\t\t\t\t\t\t\t\tcorner #3\r\n Z(i0) = AC(1,1,3,i)*Z(j0) + AC(2,1,3,i)*Z(j0+1) &\r\n\t\t + AC(3,1,3,i)*Z(j1) + AC(4,1,3,i)*Z(j1+1) &\r\n\t\t\t\t + CC(1, 3,i)*U(1)\r\n\t\t Z(i0+1) = AC(1,2,3,i)*Z(j0) + AC(2,2,3,i)*Z(j0+1) &\r\n\t\t + AC(3,2,3,i)*Z(j1) + AC(4,2,3,i)*Z(j1+1) &\r\n\t\t\t\t + CC(2, 3,i)*U(1) + CC(3, 3,i)*U(2)\r\n Z(i1) = AC(1,3,3,i)*Z(j0) + AC(2,3,3,i)*Z(j0+1) &\r\n\t\t + AC(3,3,3,i)*Z(j1) + AC(4,3,3,i)*Z(j1+1) &\r\n\t\t\t\t + CC(4, 3,i)*U(1) + CC(5, 3,i)*U(2) &\r\n\t\t\t\t + CC(6, 3,i)*U(3)\r\n Z(i1+1) = four*Z(j1) - Z(i0) - Z(i0+1) - Z(i1)\r\n!\t\t\t\t\t\t\t\tside #4\r\n L = 4\r\n do 70 js = 1, jx-2\r\n i0 = i0 + 2\r\n i1 = i1 + 2\r\n Z(i0) = AS(1,1,4,i)*Z(j0 ) + AS(2,1,4,i)*Z(j0+1) &\r\n\t\t\t + AS(3,1,4,i)*Z(j0+2) + AS(4,1,4,i)*Z(j1 ) &\r\n\t\t\t\t\t + AS(5,1,4,i)*Z(j1+1) + AS(6,1,4,i)*Z(j1+2) &\r\n\t\t\t\t\t + CS(1, 4,i)*U(L)\r\n Z(i0+1) = AS(1,2,4,i)*Z(j0 ) + AS(2,2,4,i)*Z(j0+1) &\r\n\t\t\t + AS(3,2,4,i)*Z(j0+2) + AS(4,2,4,i)*Z(j1 ) &\r\n\t\t\t\t\t + AS(5,2,4,i)*Z(j1+1) + AS(6,2,4,i)*Z(j1+2) &\r\n\t\t\t\t\t + CS(2, 4,i)*U(L) + CS(3, 4,i)*U(L+1)\r\n Z(i1) = AS(1,3,4,i)*Z(j0 ) + AS(2,3,4,i)*Z(j0+1) &\r\n\t\t\t + AS(3,3,4,i)*Z(j0+2) + AS(4,3,4,i)*Z(j1 ) &\r\n\t\t\t\t\t + AS(5,3,4,i)*Z(j1+1) + AS(6,3,4,i)*Z(j1+2) &\r\n\t\t\t\t\t + CS(4, 4,i)*U(L) + CS(5, 4,i)*U(L+1) &\r\n\t\t\t\t\t + CS(6, 4,i)*U(L+2)\r\n Z(i1+1) = four*Z(j1+1) - Z(i0) - Z(i0+1) - Z(i1)\r\n j0 = j0 + 1\r\n j1 = j1 + 1\r\n L = L + 3\r\n 70 continue\r\n!\t\t\t\t\t\t\t\tcorner #4\r\n i0 = i0 + 2\r\n i1 = i1 + 2\r\n Z(i0) = AC(1,1,4,i)*Z(j0) + AC(2,1,4,i)*Z(j0+1) &\r\n\t\t + AC(3,1,4,i)*Z(j1) + AC(4,1,4,i)*Z(j1+1) &\r\n\t\t\t\t + CC(1, 4,i)*U(L)\r\n Z(i0+1) = AC(1,2,4,i)*Z(j0) + AC(2,2,4,i)*Z(j0+1) &\r\n\t\t + AC(3,2,4,i)*Z(j1) + AC(4,2,4,i)*Z(j1+1) &\r\n\t\t\t\t + CC(2, 4,i)*U(L) + CC(3, 4,i)*U(L+1)\r\n Z(i1) = AC(1,3,4,i)*Z(j0) + AC(2,3,4,i)*Z(j0+1) &\r\n\t\t + AC(3,3,4,i)*Z(j1) + AC(4,3,4,i)*Z(j1+1) &\r\n\t\t\t\t + CC(4, 4,i)*U(L) + CC(5, 4,i)*U(L+1) &\r\n\t\t\t\t + CC(6, 4,i)*U(L+2)\r\n Z(i1+1) = four*Z(j1+1) - Z(i0) - Z(i0+1) - Z(i1)\r\n\r\n jx = ix\r\n jy = iy\r\n 80 continue\r\n!\t\t\t\t\t\tall done, compute elapsed time\r\n ts = ts + (second() - tt)\r\n\r\n return\r\n end\r\n", "meta": {"hexsha": "48da006328b7fdec4e3bfeb7a34489d6b0f7e83e", "size": 20849, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/libs/gaf95/las2g.f95", "max_stars_repo_name": "leemargetts/PoreFEM", "max_stars_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/libs/gaf95/las2g.f95", "max_issues_repo_name": "leemargetts/PoreFEM", "max_issues_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/libs/gaf95/las2g.f95", "max_forks_repo_name": "leemargetts/PoreFEM", "max_forks_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.8188073394, "max_line_length": 129, "alphanum_fraction": 0.4586790733, "num_tokens": 8044, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.899121388082479, "lm_q2_score": 0.7577943658046609, "lm_q1q2_score": 0.6813491220633685}} {"text": "!================================================================================\n! CONSTRUCCION DE UNA CONFIGURACION INICIAL ALEATORIA EN CELDA BIDIMENSIONAL\n! SIN TRASLAPES\n! Autor: Martin Paredes Sosa\n!================================================================================\n\nSubroutine ConfigIni\n Use cte\n Implicit None\n Real :: xRan, yRan, zRan, xij, yij, zij, dist\n Integer :: i, j, k !CONTADOR\n \n !CALCULANDO DIMENSIONES DE LA CAJA\n BoxL = (1.0*N/Dens )**(1.0/Dim)\n Write(*,*) \"LONGITUD DE LA CELDA:\", BoxL\n\n Open (1, File = \"ConIni.dat\" ) \n \n Colocar: Do i=1, N !BUSCAR LA POSICION ALEATORIA PARA LAS PARTICULAS\n 2 Call Random_Number(xRan) !VALOR ALEATORIO DE POSICION X \\\n Call Random_Number(yRan) !VALOR ALEATORIO DE POSICION Y | TENTATIVO \n Call Random_Number(zRan) !VALOR ALEATORIO DE POSICION Z /\n\n !COLOCAR DENTRO DE LA CELDA\n X(i) = (xRan-0.5)*(BoxL-1) !\\\n Y(i) = (yRan-0.5)*(BoxL-1) !| [-(BoxL-1)/2 , (BoxL-1)/2]\n Z(i) = (zRan-0.5)*(BoxL-1) !/\n !Write(*,*) X(i), Y(i), Z(i) !DEBUG\n\n Traslape: Do j=1 , i-1\n \n xij = X(i) - X(j) !CALCULANDO LA DISTANCIA ENTRE PARTICULAS\n yij = Y(i) - Y(j)\n zij = Z(i) - Z(j)\n !Write(*,*) i,j,xij, yij, zij !DEBUG\n dist = xij*xij + yij*yij + zij*zij\n\n DectTras: If(dist .LE. sigma ) Then !CHECAR SI EXISTE TRASLAPE\n\n GO TO 2 !VOLVER A CALCULAR UNA POSICION IR A LOS CALL_RANDOM_NUMBER\n\n End If DectTras\n\n End Do Traslape\n \n Write(1,*) X(i), Y(i), Z(i) !GUARDANDO EN ARCHIVO LA CONFIGURACION INICIAL\n\n End Do Colocar\n\n Close(1)\n\n\nEnd Subroutine ConfigIni\n", "meta": {"hexsha": "7f7437d069cf1fc8e9f785fbaa168f214106a2d6", "size": 1818, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "Portafolio_II/Tarea_III/Act_4/ConfigIni.f03", "max_stars_repo_name": "maps16/DesExpII", "max_stars_repo_head_hexsha": "d9d12b445e0fe86e32fce028be4f5b8bcfd2391f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Portafolio_II/Tarea_III/Act_4/ConfigIni.f03", "max_issues_repo_name": "maps16/DesExpII", "max_issues_repo_head_hexsha": "d9d12b445e0fe86e32fce028be4f5b8bcfd2391f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Portafolio_II/Tarea_III/Act_4/ConfigIni.f03", "max_forks_repo_name": "maps16/DesExpII", "max_forks_repo_head_hexsha": "d9d12b445e0fe86e32fce028be4f5b8bcfd2391f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.6666666667, "max_line_length": 109, "alphanum_fraction": 0.4939493949, "num_tokens": 602, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213853793452, "lm_q2_score": 0.7577943658046608, "lm_q1q2_score": 0.6813491200149489}} {"text": "!^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^!^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n!^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^!^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n!! 3D oil reservoir Simulator project \n!! by Mehrdad Gharib Shirangi From Spring 2010 until Fall 2010\n!! mehrdad.ghsh@gmail.com\n!! Copy Right by Mehrdad Gharib Shirangi\n!^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^!^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n!^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^!^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nSubroutine solve(N,AA,BB,XX)\n\nuse globalvar\n\nimplicit none\n\nINTEGER :: N\nReal*8, intent(out) :: XX(N)\nReal*8, intent(in) :: BB(N) , AA(N,N)\n\nREAL*8, ALLOCATABLE , DIMENSION(:,:):: L , U\nREAL*8, ALLOCATABLE , DIMENSION(:):: bprim\n\ninteger :: i , j , k\nreal*8 :: sum\n\n\n! to trasform an n*n matrix into LU\n\nAllocate (L(N,N))\nAllocate (U(N,N))\nAllocate (bprim(N))\n\n\nL = 0\nU = 0\nbprim = 0\n\n\nDo i = 1 ,N\n L(i,1) = AA(i,1)\nEndDo ! For i\n\n!For j=1 To n\nDo j = 1 ,N\n U(1,j) = AA(1,j)/ L(1,1)\nEndDo ! for j\n\n\n!pause\n\n! For j = 2 To n\nDo j = 2 , N\n !For i = j To n\n Do i = j , N\n\tsum = 0\n\t!For k = 1 To j-1\n\tDo k = 1 , j-1\n\t Sum = sum + L(i,k)* U(k,j)\n\tEndDo ! for k\n\tL(i,j) = AA(i,j) - Sum\n EndDo ! for i\n\n U(j,j) = 1\n\n !For i = j + 1 To n\n Do i = j + 1 , N\n\tsum = 0.0\n\t!For k = 1 To j-1\n\tDo k = 1 , j-1\n\t Sum = Sum + L(j,k) * U (k,i)\n\tEndDo ! for k\n\tU(j,i) = (AA(j,i) - Sum) / L(j,j)\n EndDo !for i\nEndDo ! for j\n\n\n\n\n\nbprim(1) = BB (1) / L(1,1)\n\nDo i = 2 , N\n Sum = 0 \n Do k = 1 , i-1\n sum = sum + L(i,k) * bprim ( k )\n End Do\n bprim(i) = (BB(i) - sum) / L(i,i)\nEndDo\n\nXX(N) = bprim (N)\n\n\nDo j = N - 1 , 1 , -1\n sum = 0\n Do k = j+1 , N\n sum = sum + U(j,k) * XX(k)\n EndDo\n XX(j) = bprim(j) - sum\nEndDo\n\n\nDeAllocate (L)\nDeAllocate (U)\nDeAllocate (bprim)\n\nEnd\n", "meta": {"hexsha": "1629923fdaf55d15659d307045c9e51317a44d65", "size": 2022, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "my solver.f90", "max_stars_repo_name": "mehrdad-shirangi/reservoir_simulator", "max_stars_repo_head_hexsha": "1c0d4c49a1175d9c622f410c7949cd2c007ae69d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-11-28T17:12:26.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-16T10:05:14.000Z", "max_issues_repo_path": "my solver.f90", "max_issues_repo_name": "mehrdad-shirangi/reservoir_simulator", "max_issues_repo_head_hexsha": "1c0d4c49a1175d9c622f410c7949cd2c007ae69d", "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": "my solver.f90", "max_forks_repo_name": "mehrdad-shirangi/reservoir_simulator", "max_forks_repo_head_hexsha": "1c0d4c49a1175d9c622f410c7949cd2c007ae69d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-10-20T19:01:16.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-01T10:06:27.000Z", "avg_line_length": 18.8971962617, "max_line_length": 138, "alphanum_fraction": 0.3808110781, "num_tokens": 796, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898254600902, "lm_q2_score": 0.7520125848754472, "lm_q1q2_score": 0.6813157505150977}} {"text": " subroutine wmmul(Ar,Ai,na,Br,Bi,nb,Cr,Ci,nc,l,m,n)\n*\n* PURPOSE\n* computes the matrix product C = A * B where the\n* matrices are complex with the scilab storage\n* C = A * B\n* (l,n) (l,m) * (m,n)\n* \n* PARAMETERS\n* input \n* -----\n* Ar, Ai : real and imaginary part of the matrix A\n* (double) arrays (l, m) with leading dim na\n* \n* Br, Bi : real and imaginary part of the matrix B\n* (double) arrays (m, n) with leading dim nb\n* \n* na, nb, nc, l, m, n : integers\n*\n* output \n* ------\n* Cr, Ci : real and imaginary part of the matrix C\n* (double) arrays (l, n) with leading dim nc\n*\n* METHOD\n* Cr = Ar * Br - Ai * Bi\n* Ci = Ar * Bi + Ai * Br\n*\n* NOTE\n* modification of the old wmmul to use blas calls\n*\n implicit none\n\n integer na, nb, nc, l, m, n\n double precision Ar(na,m), Ai(na,m), Br(nb,n), Bi(nb,n), \n $ Cr(nc,n), Ci(nc,n)\n\n* Cr <- 1*Ar*Br + 0*Cr\n call dgemm('n','n', l, n, m, 1.d0, Ar, na, Br, nb, 0.d0, Cr, nc)\n* Cr <- -1*Ai*Bi + 1*Cr\n call dgemm('n','n', l, n, m,-1.d0, Ai, na, Bi, nb, 1.d0, Cr, nc)\n* Ci <- 1*Ar*Bi + 0*Ci\n call dgemm('n','n', l, n, m, 1.d0, Ar, na, Bi, nb, 0.d0, Ci, nc)\n* Ci <- 1*Ai*Br + 1*Ci\n call dgemm('n','n', l, n, m, 1.d0, Ai, na, Br, nb, 1.d0, Ci, nc)\n\n end\n\n\n", "meta": {"hexsha": "5ac0baa5adef0c2c889d30ca64b035b3250de148", "size": 1484, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/calelm/wmmul.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/wmmul.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/wmmul.f", "max_forks_repo_name": "alpgodev/numx", "max_forks_repo_head_hexsha": "d2d3a0713020e1b83b65d3a661c3801ea256aff9", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.68, "max_line_length": 70, "alphanum_fraction": 0.4541778976, "num_tokens": 542, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898254600902, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6813157404444319}} {"text": "*DECK SEPELI\n SUBROUTINE SEPELI (INTL, IORDER, A, B, M, MBDCND, BDA, ALPHA, BDB,\n + BETA, C, D, N, NBDCND, BDC, GAMA, BDD, XNU, COFX, COFY, GRHS,\n + USOL, IDMN, W, PERTRB, IERROR)\nC***BEGIN PROLOGUE SEPELI\nC***PURPOSE Discretize and solve a second and, optionally, a fourth\nC order finite difference approximation on a uniform grid to\nC the general separable elliptic partial differential\nC equation on a rectangle with any combination of periodic or\nC mixed boundary conditions.\nC***LIBRARY SLATEC (FISHPACK)\nC***CATEGORY I2B1A2\nC***TYPE SINGLE PRECISION (SEPELI-S)\nC***KEYWORDS ELLIPTIC, FISHPACK, HELMHOLTZ, PDE, SEPARABLE\nC***AUTHOR Adams, J., (NCAR)\nC Swarztrauber, P. N., (NCAR)\nC Sweet, R., (NCAR)\nC***DESCRIPTION\nC\nC Dimension of BDA(N+1), BDB(N+1), BDC(M+1), BDD(M+1),\nC Arguments USOL(IDMN,N+1), GRHS(IDMN,N+1),\nC W (see argument list)\nC\nC Latest Revision March 1977\nC\nC Purpose SEPELI solves for either the second-order\nC finite difference approximation or a\nC fourth-order approximation to a separable\nC elliptic equation.\nC\nC 2 2\nC AF(X)*d U/dX + BF(X)*dU/dX + CF(X)*U +\nC 2 2\nC DF(Y)*d U/dY + EF(Y)*dU/dY + FF(Y)*U\nC\nC = G(X,Y)\nC\nC on a rectangle (X greater than or equal to A\nC and less than or equal to B; Y greater than\nC or equal to C and less than or equal to D).\nC Any combination of periodic or mixed boundary\nC conditions is allowed.\nC\nC Purpose The possible boundary conditions are:\nC in the X-direction:\nC (0) Periodic, U(X+B-A,Y)=U(X,Y) for all Y,X\nC (1) U(A,Y), U(B,Y) are specified for all Y\nC (2) U(A,Y), dU(B,Y)/dX+BETA*U(B,Y) are\nC specified for all Y\nC (3) dU(A,Y)/dX+ALPHA*U(A,Y),dU(B,Y)/dX+\nC BETA*U(B,Y) are specified for all Y\nC (4) dU(A,Y)/dX+ALPHA*U(A,Y),U(B,Y) are\nC specified for all Y\nC\nC in the Y-direction:\nC (0) Periodic, U(X,Y+D-C)=U(X,Y) for all X,Y\nC (1) U(X,C),U(X,D) are specified for all X\nC (2) U(X,C),dU(X,D)/dY+XNU*U(X,D) are specified\nC for all X\nC (3) dU(X,C)/dY+GAMA*U(X,C),dU(X,D)/dY+\nC XNU*U(X,D) are specified for all X\nC (4) dU(X,C)/dY+GAMA*U(X,C),U(X,D) are\nC specified for all X\nC\nC Arguments\nC\nC On Input INTL\nC = 0 On initial entry to SEPELI or if any of\nC the arguments C, D, N, NBDCND, COFY are\nC changed from a previous call\nC = 1 If C, D, N, NBDCND, COFY are unchanged\nC from the previous call.\nC\nC IORDER\nC = 2 If a second-order approximation is sought\nC = 4 If a fourth-order approximation is sought\nC\nC A,B\nC The range of the X-independent variable;\nC i.e., X is greater than or equal to A and\nC less than or equal to B. A must be less than\nC B.\nC\nC M\nC The number of panels into which the interval\nC [A,B] is subdivided. Hence, there will be\nC M+1 grid points in the X-direction given by\nC XI=A+(I-1)*DLX for I=1,2,...,M+1 where\nC DLX=(B-A)/M is the panel width. M must be\nC less than IDMN and greater than 5.\nC\nC MBDCND\nC Indicates the type of boundary condition at\nC X=A and X=B\nC = 0 If the solution is periodic in X; i.e.,\nC U(X+B-A,Y)=U(X,Y) for all Y,X\nC = 1 If the solution is specified at X=A and\nC X=B; i.e., U(A,Y) and U(B,Y) are\nC specified for all Y\nC = 2 If the solution is specified at X=A and\nC the boundary condition is mixed at X=B;\nC i.e., U(A,Y) and dU(B,Y)/dX+BETA*U(B,Y)\nC are specified for all Y\nC = 3 If the boundary conditions at X=A and X=B\nC are mixed; i.e., dU(A,Y)/dX+ALPHA*U(A,Y)\nC and dU(B,Y)/dX+BETA*U(B,Y) are specified\nC for all Y\nC = 4 If the boundary condition at X=A is mixed\nC and the solution is specified at X=B;\nC i.e., dU(A,Y)/dX+ALPHA*U(A,Y) and U(B,Y)\nC are specified for all Y\nC\nC BDA\nC A one-dimensional array of length N+1 that\nC specifies the values of dU(A,Y)/dX+\nC ALPHA*U(A,Y) at X=A, when MBDCND=3 or 4.\nC BDA(J) = dU(A,YJ)/dX+ALPHA*U(A,YJ);\nC J=1,2,...,N+1\nC when MBDCND has any other value, BDA is a\nC dummy parameter.\nC\nC On Input ALPHA\nC The scalar multiplying the solution in case\nC of a mixed boundary condition at X=A (see\nC argument BDA). If MBDCND = 3,4 then ALPHA is\nC a dummy parameter.\nC\nC BDB\nC A one-dimensional array of length N+1 that\nC specifies the values of dU(B,Y)/dX+\nC BETA*U(B,Y) at X=B. When MBDCND=2 or 3\nC BDB(J) = dU(B,YJ)/dX+BETA*U(B,YJ);\nC J=1,2,...,N+1\nC When MBDCND has any other value, BDB is a\nC dummy parameter.\nC\nC BETA\nC The scalar multiplying the solution in case\nC of a mixed boundary condition at X=B (see\nC argument BDB). If MBDCND=2,3 then BETA is a\nC dummy parameter.\nC\nC C,D\nC The range of the Y-independent variable;\nC i.e., Y is greater than or equal to C and\nC less than or equal to D. C must be less than\nC D.\nC\nC N\nC The number of panels into which the interval\nC [C,D] is subdivided. Hence, there will be\nC N+1 grid points in the Y-direction given by\nC YJ=C+(J-1)*DLY for J=1,2,...,N+1 where\nC DLY=(D-C)/N is the panel width. In addition,\nC N must be greater than 4.\nC\nC NBDCND\nC Indicates the types of boundary conditions at\nC Y=C and Y=D\nC = 0 If the solution is periodic in Y; i.e.,\nC U(X,Y+D-C)=U(X,Y) for all X,Y\nC = 1 If the solution is specified at Y=C and\nC Y = D, i.e., U(X,C) and U(X,D) are\nC specified for all X\nC = 2 If the solution is specified at Y=C and\nC the boundary condition is mixed at Y=D;\nC i.e., U(X,C) and dU(X,D)/dY+XNU*U(X,D)\nC are specified for all X\nC = 3 If the boundary conditions are mixed at\nC Y=C and Y=D; i.e., dU(X,D)/dY+GAMA*U(X,C)\nC and dU(X,D)/dY+XNU*U(X,D) are specified\nC for all X\nC = 4 If the boundary condition is mixed at Y=C\nC and the solution is specified at Y=D;\nC i.e. dU(X,C)/dY+GAMA*U(X,C) and U(X,D)\nC are specified for all X\nC\nC BDC\nC A one-dimensional array of length M+1 that\nC specifies the value of dU(X,C)/dY+GAMA*U(X,C)\nC at Y=C. When NBDCND=3 or 4\nC BDC(I) = dU(XI,C)/dY + GAMA*U(XI,C);\nC I=1,2,...,M+1.\nC When NBDCND has any other value, BDC is a\nC dummy parameter.\nC\nC GAMA\nC The scalar multiplying the solution in case\nC of a mixed boundary condition at Y=C (see\nC argument BDC). If NBDCND=3,4 then GAMA is a\nC dummy parameter.\nC\nC BDD\nC A one-dimensional array of length M+1 that\nC specifies the value of dU(X,D)/dY +\nC XNU*U(X,D) at Y=C. When NBDCND=2 or 3\nC BDD(I) = dU(XI,D)/dY + XNU*U(XI,D);\nC I=1,2,...,M+1.\nC When NBDCND has any other value, BDD is a\nC dummy parameter.\nC\nC XNU\nC The scalar multiplying the solution in case\nC of a mixed boundary condition at Y=D (see\nC argument BDD). If NBDCND=2 or 3 then XNU is\nC a dummy parameter.\nC\nC COFX\nC A user-supplied subprogram with\nC parameters X, AFUN, BFUN, CFUN which\nC returns the values of the X-dependent\nC coefficients AF(X), BF(X), CF(X) in\nC the elliptic equation at X.\nC\nC COFY\nC A user-supplied subprogram with\nC parameters Y, DFUN, EFUN, FFUN which\nC returns the values of the Y-dependent\nC coefficients DF(Y), EF(Y), FF(Y) in\nC the elliptic equation at Y.\nC\nC NOTE: COFX and COFY must be declared external\nC in the calling routine. The values returned in\nC AFUN and DFUN must satisfy AFUN*DFUN greater\nC than 0 for A less than X less than B,\nC C less than Y less than D (see IERROR=10).\nC The coefficients provided may lead to a matrix\nC equation which is not diagonally dominant in\nC which case solution may fail (see IERROR=4).\nC\nC GRHS\nC A two-dimensional array that specifies the\nC values of the right-hand side of the elliptic\nC equation; i.e., GRHS(I,J)=G(XI,YI), for\nC I=2,...,M; J=2,...,N. At the boundaries,\nC GRHS is defined by\nC\nC MBDCND GRHS(1,J) GRHS(M+1,J)\nC ------ --------- -----------\nC 0 G(A,YJ) G(B,YJ)\nC 1 * *\nC 2 * G(B,YJ) J=1,2,...,N+1\nC 3 G(A,YJ) G(B,YJ)\nC 4 G(A,YJ) *\nC\nC NBDCND GRHS(I,1) GRHS(I,N+1)\nC ------ --------- -----------\nC 0 G(XI,C) G(XI,D)\nC 1 * *\nC 2 * G(XI,D) I=1,2,...,M+1\nC 3 G(XI,C) G(XI,D)\nC 4 G(XI,C) *\nC\nC where * means these quantities are not used.\nC GRHS should be dimensioned IDMN by at least\nC N+1 in the calling routine.\nC\nC USOL\nC A two-dimensional array that specifies the\nC values of the solution along the boundaries.\nC At the boundaries, USOL is defined by\nC\nC MBDCND USOL(1,J) USOL(M+1,J)\nC ------ --------- -----------\nC 0 * *\nC 1 U(A,YJ) U(B,YJ)\nC 2 U(A,YJ) * J=1,2,...,N+1\nC 3 * *\nC 4 * U(B,YJ)\nC\nC NBDCND USOL(I,1) USOL(I,N+1)\nC ------ --------- -----------\nC 0 * *\nC 1 U(XI,C) U(XI,D)\nC 2 U(XI,C) * I=1,2,...,M+1\nC 3 * *\nC 4 * U(XI,D)\nC\nC where * means the quantities are not used in\nC the solution.\nC\nC If IORDER=2, the user may equivalence GRHS\nC and USOL to save space. Note that in this\nC case the tables specifying the boundaries of\nC the GRHS and USOL arrays determine the\nC boundaries uniquely except at the corners.\nC If the tables call for both G(X,Y) and\nC U(X,Y) at a corner then the solution must be\nC chosen. For example, if MBDCND=2 and\nC NBDCND=4, then U(A,C), U(A,D), U(B,D) must be\nC chosen at the corners in addition to G(B,C).\nC\nC If IORDER=4, then the two arrays, USOL and\nC GRHS, must be distinct.\nC\nC USOL should be dimensioned IDMN by at least\nC N+1 in the calling routine.\nC\nC IDMN\nC The row (or first) dimension of the arrays\nC GRHS and USOL as it appears in the program\nC calling SEPELI. This parameter is used to\nC specify the variable dimension of GRHS and\nC USOL. IDMN must be at least 7 and greater\nC than or equal to M+1.\nC\nC W\nC A one-dimensional array that must be provided\nC by the user for work space. Let\nC K=INT(log2(N+1))+1 and set L=2**(K+1).\nC then (K-2)*L+K+10*N+12*M+27 will suffice\nC as a length of W. THE actual length of W in\nC the calling routine must be set in W(1) (see\nC IERROR=11).\nC\nC On Output USOL\nC Contains the approximate solution to the\nC elliptic equation. USOL(I,J) is the\nC approximation to U(XI,YJ) for I=1,2...,M+1\nC and J=1,2,...,N+1. The approximation has\nC error O(DLX**2+DLY**2) if called with\nC IORDER=2 and O(DLX**4+DLY**4) if called with\nC IORDER=4.\nC\nC W\nC Contains intermediate values that must not be\nC destroyed if SEPELI is called again with\nC INTL=1. In addition W(1) contains the exact\nC minimal length (in floating point) required\nC for the work space (see IERROR=11).\nC\nC PERTRB\nC If a combination of periodic or derivative\nC boundary conditions (i.e., ALPHA=BETA=0 if\nC MBDCND=3; GAMA=XNU=0 if NBDCND=3) is\nC specified and if the coefficients of U(X,Y)\nC in the separable elliptic equation are zero\nC (i.e., CF(X)=0 for X greater than or equal to\nC A and less than or equal to B; FF(Y)=0 for\nC Y greater than or equal to C and less than\nC or equal to D) then a solution may not exist.\nC PERTRB is a constant calculated and\nC subtracted from the right-hand side of the\nC matrix equations generated by SEPELI which\nC insures that a solution exists. SEPELI then\nC computes this solution which is a weighted\nC minimal least squares solution to the\nC original problem.\nC\nC IERROR\nC An error flag that indicates invalid input\nC parameters or failure to find a solution\nC = 0 No error\nC = 1 If A greater than B or C greater than D\nC = 2 If MBDCND less than 0 or MBDCND greater\nC than 4\nC = 3 If NBDCND less than 0 or NBDCND greater\nC than 4\nC = 4 If attempt to find a solution fails.\nC (the linear system generated is not\nC diagonally dominant.)\nC = 5 If IDMN is too small (see discussion of\nC IDMN)\nC = 6 If M is too small or too large (see\nC discussion of M)\nC = 7 If N is too small (see discussion of N)\nC = 8 If IORDER is not 2 or 4\nC = 9 If INTL is not 0 or 1\nC = 10 If AFUN*DFUN less than or equal to 0 for\nC some interior mesh point (XI,YJ)\nC = 11 If the work space length input in W(1)\nC is less than the exact minimal work\nC space length required output in W(1).\nC\nC NOTE (concerning IERROR=4): for the\nC coefficients input through COFX, COFY, the\nC discretization may lead to a block\nC tridiagonal linear system which is not\nC diagonally dominant (for example, this\nC happens if CFUN=0 and BFUN/(2.*DLX) greater\nC than AFUN/DLX**2). In this case solution may\nC fail. This cannot happen in the limit as\nC DLX, DLY approach zero. Hence, the condition\nC may be remedied by taking larger values for M\nC or N.\nC\nC Entry Points SEPELI, SPELIP, CHKPRM, CHKSNG, ORTHOG, MINSOL,\nC TRISP, DEFER, DX, DY, BLKTRI, BLKTR1, INDXB,\nC INDXA, INDXC, PROD, PRODP, CPROD, CPRODP,\nC PPADD, PSGF, BSRH, PPSGF, PPSPF, COMPB,\nC TRUN1, STOR1, TQLRAT\nC\nC Special Conditions NONE\nC\nC Common Blocks SPLP, CBLKT\nC\nC I/O NONE\nC\nC Precision Single\nC\nC Specialist John C. Adams, NCAR, Boulder, Colorado 80307\nC\nC Language FORTRAN\nC\nC History Developed at NCAR during 1975-76.\nC\nC Algorithm SEPELI automatically discretizes the separable\nC elliptic equation which is then solved by a\nC generalized cyclic reduction algorithm in the\nC subroutine, BLKTRI. The fourth-order solution\nC is obtained using 'Deferred Corrections' which\nC is described and referenced in sections,\nC references and method.\nC\nC Space Required 14654 (octal) = 6572 (decimal)\nC\nC Accuracy and Timing The following computational results were\nC obtained by solving the sample problem at the\nC end of this write-up on the Control Data 7600.\nC The op count is proportional to M*N*log2(N).\nC In contrast to the other routines in this\nC chapter, accuracy is tested by computing and\nC tabulating second- and fourth-order\nC discretization errors. Below is a table\nC containing computational results. The times\nC given do not include initialization (i.e.,\nC times are for INTL=1). Note that the\nC fourth-order accuracy is not realized until the\nC mesh is sufficiently refined.\nC\nC Second-order Fourth-order Second-order Fourth-order\nC M N Execution Time Execution Time Error Error\nC (M SEC) (M SEC)\nC 6 6 6 14 6.8E-1 1.2E0\nC 14 14 23 58 1.4E-1 1.8E-1\nC 30 30 100 247 3.2E-2 9.7E-3\nC 62 62 445 1,091 7.5E-3 3.0E-4\nC 126 126 2,002 4,772 1.8E-3 3.5E-6\nC\nC Portability There are no machine-dependent constants.\nC\nC Required Resident SQRT, ABS, LOG\nC Routines\nC\nC References Keller, H.B., 'Numerical Methods for Two-point\nC Boundary-value Problems', Blaisdel (1968),\nC Waltham, Mass.\nC\nC Swarztrauber, P., and R. Sweet (1975):\nC 'Efficient FORTRAN Subprograms for The\nC Solution of Elliptic Partial Differential\nC Equations'. NCAR Technical Note\nC NCAR-TN/IA-109, pp. 135-137.\nC\nC***REFERENCES H. B. Keller, Numerical Methods for Two-point\nC Boundary-value Problems, Blaisdel, Waltham, Mass.,\nC 1968.\nC P. N. Swarztrauber and R. Sweet, Efficient Fortran\nC subprograms for the solution of elliptic equations,\nC NCAR TN/IA-109, July 1975, 138 pp.\nC***ROUTINES CALLED CHKPRM, SPELIP\nC***REVISION HISTORY (YYMMDD)\nC 801001 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890531 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE SEPELI\nC\n DIMENSION GRHS(IDMN,*) ,USOL(IDMN,*)\n DIMENSION BDA(*) ,BDB(*) ,BDC(*) ,BDD(*) ,\n 1 W(*)\n EXTERNAL COFX ,COFY\nC***FIRST EXECUTABLE STATEMENT SEPELI\n CALL CHKPRM (INTL,IORDER,A,B,M,MBDCND,C,D,N,NBDCND,COFX,COFY,\n 1 IDMN,IERROR)\n IF (IERROR .NE. 0) RETURN\nC\nC COMPUTE MINIMUM WORK SPACE AND CHECK WORK SPACE LENGTH INPUT\nC\n L = N+1\n IF (NBDCND .EQ. 0) L = N\n LOGB2N = INT(LOG(L+0.5)/LOG(2.0))+1\n LL = 2**(LOGB2N+1)\n K = M+1\n L = N+1\n LENGTH = (LOGB2N-2)*LL+LOGB2N+MAX(2*L,6*K)+5\n IF (NBDCND .EQ. 0) LENGTH = LENGTH+2*L\n IERROR = 11\n LINPUT = INT(W(1)+0.5)\n LOUTPT = LENGTH+6*(K+L)+1\n W(1) = LOUTPT\n IF (LOUTPT .GT. LINPUT) RETURN\n IERROR = 0\nC\nC SET WORK SPACE INDICES\nC\n I1 = LENGTH+2\n I2 = I1+L\n I3 = I2+L\n I4 = I3+L\n I5 = I4+L\n I6 = I5+L\n I7 = I6+L\n I8 = I7+K\n I9 = I8+K\n I10 = I9+K\n I11 = I10+K\n I12 = I11+K\n I13 = 2\n CALL SPELIP (INTL,IORDER,A,B,M,MBDCND,BDA,ALPHA,BDB,BETA,C,D,N,\n 1 NBDCND,BDC,GAMA,BDD,XNU,COFX,COFY,W(I1),W(I2),W(I3),\n 2 W(I4),W(I5),W(I6),W(I7),W(I8),W(I9),W(I10),W(I11),\n 3 W(I12),GRHS,USOL,IDMN,W(I13),PERTRB,IERROR)\n RETURN\n END\n", "meta": {"hexsha": "c778fd9285f5534a5b467a9ebbae19f50cfa8578", "size": 25508, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/sepeli.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/sepeli.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/sepeli.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.3384912959, "max_line_length": 72, "alphanum_fraction": 0.4288850557, "num_tokens": 6178, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898229217591, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.681315738535575}} {"text": "module mdft_coulomb_solvers\n implicit none\n private\n public :: solve_coulomb\ncontains\n\n subroutine solve_coulomb ( Nsource, source_coo, source_charge, Ntarget, target_coo, target_electric_field, method )\n implicit none\n integer, intent(in) :: Nsource\n double precision, intent(in) :: source_coo(3,Nsource) ! coordinates of sources\n double precision, intent(in) :: source_charge(Nsource) ! the charge of each source in electron units\n integer, intent(in) :: Ntarget\n double precision, intent(in) :: target_coo(3,Ntarget) ! target coordinates\n double precision, intent(out) :: target_electric_field(Ntarget) ! what we are looking for : the electric field at target coordinates\n integer, intent(in) :: method ! 0 for direct sum\n integer :: itarget, isource\n\n !\n ! At this point the target_electric_field is unknown. Initialization:\n !\n target_electric_field = 0.d0\n\n select case (method)\n\n case (0) ! direct sum\n\n do itarget=1,Ntarget\n do isource=1,Nsource\n target_electric_field(itarget) = target_electric_field(itarget) + source_charge(isource) &\n / norm2(source_coo(:,isource) - target_coo(:,itarget)) ! electric_field(target) = sum_sources ( qsource/r)\n end do\n end do\n\n case default\n print*, \"In module mdft_coulomb_solver, method\", method,\" is not implemented\"\n error stop \"KLXZkbh7jdMpkj5Z\"\n end select\n\n end subroutine solve_coulomb\n\nend module mdft_coulomb_solvers\n", "meta": {"hexsha": "a7b09968354058d055c1a90a325e03e8756e7271", "size": 1483, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/mdft_coulomb_solvers.f90", "max_stars_repo_name": "maxlevesque/mdft_coulomb_solvers", "max_stars_repo_head_hexsha": "4147edd13132eca862f9e5c2bb00c517d24f1349", "max_stars_repo_licenses": ["MIT"], "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/mdft_coulomb_solvers.f90", "max_issues_repo_name": "maxlevesque/mdft_coulomb_solvers", "max_issues_repo_head_hexsha": "4147edd13132eca862f9e5c2bb00c517d24f1349", "max_issues_repo_licenses": ["MIT"], "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/mdft_coulomb_solvers.f90", "max_forks_repo_name": "maxlevesque/mdft_coulomb_solvers", "max_forks_repo_head_hexsha": "4147edd13132eca862f9e5c2bb00c517d24f1349", "max_forks_repo_licenses": ["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.3095238095, "max_line_length": 136, "alphanum_fraction": 0.7107215105, "num_tokens": 389, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989815306765, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6813157328090037}} {"text": "C\nC $Id: idlsqf.f,v 1.4 2008-07-27 00:17:30 haley Exp $\nC \nC Copyright (C) 2000\nC University Corporation for Atmospheric Research\nC All Rights Reserved\nC\nC The use of this Software is governed by a License Agreement.\nC\n SUBROUTINE IDLSQF (X,Y,Z,N,A,B,C,XAVG,YAVG)\nC\n DIMENSION X(N),Y(N),Z(N)\nC\nC IDLSQF fits a plane to the data defined by points (X(I),Y(I),Z(I)),\nC for I from 1 to N. It returns the coefficients A, B, and C in the\nC equation \"Z=AX+BY+C\". It also returns the average X and average Y.\nC\n SA=0.\n SB=0.\n SC=0.\n SD=0.\n SE=0.\n SF=0.\n SG=0.\n SH=0.\nC\n DO 101 I=1,N\n SA=SA+X(I)\n SB=SB+Y(I)\n SC=SC+Z(I)\n SD=SD+X(I)*X(I)\n SE=SE+Y(I)*Y(I)\n SF=SF+X(I)*Y(I)\n SG=SG+Y(I)*Z(I)\n SH=SH+X(I)*Z(I)\n 101 CONTINUE\nC\n RN=REAL(N)\nC\n A=((RN*SH-SA*SC)*(RN*SE-SB*SB)-(RN*SF-SA*SB)*(RN*SG-SB*SC))/\n + ((RN*SD-SA*SA)*(RN*SE-SB*SB)-(RN*SF-SA*SB)*(RN*SF-SA*SB))\n B=((RN*SD-SA*SA)*(RN*SG-SB*SC)-(RN*SF-SA*SB)*(RN*SH-SA*SC))/\n + ((RN*SD-SA*SA)*(RN*SE-SB*SB)-(RN*SF-SA*SB)*(RN*SF-SA*SB))\n C=(SC-SA*A-SB*B)/RN\nC\n XAVG=SA/RN\n YAVG=SB/RN\nC\nC Done.\nC\n RETURN\nC\n END\n", "meta": {"hexsha": "6539c05cf32913bbc63bd66e489839a78094623b", "size": 1373, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ncarg2d/src/libncarg/support/idlsqf.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "ncarg2d/src/libncarg/support/idlsqf.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "ncarg2d/src/libncarg/support/idlsqf.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 25.4259259259, "max_line_length": 71, "alphanum_fraction": 0.4705025492, "num_tokens": 514, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898203834277, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6813157315913849}} {"text": "!this module is used to calculate the M and h in the CSI \n!this module have a function to calculate f[x1,x2,x3]\nMODULE csi_mod\n USE threediag_mod\n IMPLICIT NONE\n PRIVATE\n PUBLIC::CSI\nCONTAINS\n SUBROUTINE CSI(n_in,x,y,condition,a_in,b_in,M,h)\n INTEGER(4),INTENT(IN):: n_in\n REAL(8),DIMENSION(:),INTENT(IN)::x(n_in),y(n_in)\n CHARACTER(10),INTENT(IN)::condition\n REAL(8),INTENT(IN)::a_in,b_in\n REAL(8),ALLOCATABLE::miu(:),lamda(:),d(:)\n REAL(8),DIMENSION(:),INTENT(OUT)::M(n_in),h(n_in-1)\n REAL(8),ALLOCATABLE::a_three(:),b_three(:),c_three(:),d_three(:),M_three(:)\n INTEGER(4)::i\n M=0\n h=0\n ALLOCATE(miu(n_in-2))\n ALLOCATE(lamda(n_in-2))\n ALLOCATE(d(n_in))\n miu=0\n lamda=0\n d=0\n DO i=2,n_in\n h(i-1)=x(i)-x(i-1) !calculate h\n END DO\n DO i=2,n_in-1\n d(i)=6*diff3(x(i-1),x(i),x(i+1),y(i-1),y(i),y(i+1))\n END DO\n DO i=1,n_in-2\n miu(i)=h(i)/(h(i)+h(i+1))\n lamda(i)=1-miu(i)\n END DO\n SELECT CASE(condition)\n CASE('first') !the first condition\n M(1)=a_in\n M(n_in)=b_in\n d(2)=d(2)-miu(1)*M(1)\n d(n_in-1)=d(n_in-1)-lamda(n_in-1)*M(n_in)\n ALLOCATE(a_three(n_in-2))\n ALLOCATE(b_three(n_in-2))\n ALLOCATE(c_three(n_in-2))\n ALLOCATE(d_three(n_in-2))\n ALLOCATE(M_three(n_in-2)) !define a,b,c,d,m to use the threediag Ax=b\n a_three=0\n b_three=2 !b=2\n c_three=0\n d_three=0\n M_three=0\n c_three(1)=lamda(1)\n d_three(1)=d(2)\n a_three(n_in-2)=miu(n_in-2)\n d_three(n_in-2)=d(n_in-1)\n DO i=2,n_in-3\n a_three(i)=miu(i)\n c_three(i)=lamda(i)\n d_three(i)=d(i+1)\n END DO\n CALL threediag(n_in-2,a_three,b_three,c_three,d_three,&\n M_three)\n DO i=1,n_in-2\n M(i+1)=M_three(i) !get the M\n END DO\n DEALLOCATE(a_three)\n DEALLOCATE(b_three)\n DEALLOCATE(c_three)\n DEALLOCATE(d_three)\n DEALLOCATE(M_three)\n CASE('second') !the second condition\n d(1)=(6/h(1))*((y(2)-y(1))/h(1)-a_in)\n d(n_in)=(6/h(n_in-1))*(b_in-(y(n_in)-y(n_in-1))/h(n_in-1))\n ALLOCATE(a_three(n_in))\n ALLOCATE(b_three(n_in))\n ALLOCATE(c_three(n_in))!define a,b,c to use the threediag Ax=b\n a_three=0\n b_three=2 !b=2\n c_three=0\n c_three(1)=1\n a_three(n_in)=1\n DO i=2,n_in-1\n a_three(i)=miu(i-1)\n c_three(i)=lamda(i-1)\n END DO\n CALL threediag(n_in,a_three,b_three,c_three,d,&\n M) \n DEALLOCATE(a_three)\n DEALLOCATE(b_three)\n DEALLOCATE(c_three)\n CASE('third')\n ALLOCATE(a_three(n_in-1))\n ALLOCATE(b_three(n_in-1))\n ALLOCATE(c_three(n_in-1))!define a,b,c,d,m to use the threediag Ax=b\n b_three=2\n a_three(1:n_in-2)=miu(1:n_in-2)\n c_three(1:n_in-2)=lamda(1:n_in-2)\n a_three(n_in-1)=h(n_in-1)/(h(n_in-1)+h(1))\n c_three(n_in-1)=1-a_three(n_in-1)\n d(n_in)=(6/(h(n_in-1)+h(1)))*((y(2)-y(n_in))/h(1)-(y(n_in)-y(n_in-1))/h(n_in-1))\n ALLOCATE(d_three(n_in-1))\n ALLOCATE(M_three(n_in-1))\n d_three(1:n_in-1)=d(2:n_in)\n CALL boundary3(n_in-1,a_three,b_three,c_three,&\n d_three,M_three)\n M(2:n_in)=M_three(1:n_in-1)\n M(1)=M_three(n_in-1)\n DEALLOCATE(a_three)\n DEALLOCATE(b_three)\n DEALLOCATE(c_three)\n DEALLOCATE(d_three)\n DEALLOCATE(M_three)\n END SELECT\n DEALLOCATE(miu)\n DEALLOCATE(lamda)\n DEALLOCATE(d)\n END SUBROUTINE\n SUBROUTINE boundary3(n,a,b,c,d,x)\n INTEGER(4),INTENT(IN)::n\n REAL(8),DIMENSION(:),INTENT(IN)::a(n),b(n),c(n),d(n)\n REAL(8),DIMENSION(:),INTENT(INOUT)::x(n)\n REAL(8),ALLOCATABLE::u(:),l(:),y(:)\n INTEGER(4)::i\n ALLOCATE(y(n))\n ALLOCATE(u(n))\n ALLOCATE(l(n))\n x=0\n y=0\n u=0\n l=0\n u(1)=b(1)\n y(1)=d(1)\n l(1)=a(1)\n u(n)=c(n)/u(1)\n DO i=2,n\n l(i)=a(i)/u(i-1)\n u(i)=b(i)-l(i)*c(i-1)\n y(i)=d(i)-l(i)*y(i-1)\n END DO\n y(n)=y(n)-u(n)*l(1)\n x(n)=y(n)/u(n)\n DO i=n-1,2,-1\n x(i)=(y(i)-c(i)*x(i+1))/u(i)\n END DO\n x(1)=(y(1)-c(2)*x(2)-l(1)*x(n))/u(1)\n DEALLOCATE(y)\n DEALLOCATE(u)\n DEALLOCATE(l)\n END SUBROUTINE\n\n\n\n FUNCTION diff3(x1,x2,x3,y1,y2,y3)\n REAL(8),INTENT(IN)::x1,x2,x3\n REAL(8),INTENT(IN)::y1,y2,y3\n REAL(8)::f1,f2,diff3\n f1=(y2-y1)/(x2-x1)\n f2=(y3-y2)/(x3-x2)\n diff3=(f2-f1)/(x3-x1)\n END FUNCTION\nEND MODULE", "meta": {"hexsha": "2094fe7a4e6e0da098f9d442e2abbd39ab6bf84c", "size": 5508, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "CSI/src/CSI_mod.f90", "max_stars_repo_name": "Huang-Yihan/jisuanfangfa", "max_stars_repo_head_hexsha": "1e48104988b01f66da216f639fd0654a6b1ff6c4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "CSI/src/CSI_mod.f90", "max_issues_repo_name": "Huang-Yihan/jisuanfangfa", "max_issues_repo_head_hexsha": "1e48104988b01f66da216f639fd0654a6b1ff6c4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "CSI/src/CSI_mod.f90", "max_forks_repo_name": "Huang-Yihan/jisuanfangfa", "max_forks_repo_head_hexsha": "1e48104988b01f66da216f639fd0654a6b1ff6c4", "max_forks_repo_licenses": ["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.2111801242, "max_line_length": 96, "alphanum_fraction": 0.4449891068, "num_tokens": 1760, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133464597458, "lm_q2_score": 0.7248702702332475, "lm_q1q2_score": 0.6813152414441118}} {"text": "*DECK DEFC\n SUBROUTINE DEFC (NDATA, XDATA, YDATA, SDDATA, NORD, NBKPT, BKPT,\n + MDEIN, MDEOUT, COEFF, LW, W)\nC***BEGIN PROLOGUE DEFC\nC***PURPOSE Fit a piecewise polynomial curve to discrete data.\nC The piecewise polynomials are represented as B-splines.\nC The fitting is done in a weighted least squares sense.\nC***LIBRARY SLATEC\nC***CATEGORY K1A1A1, K1A2A, L8A3\nC***TYPE DOUBLE PRECISION (EFC-S, DEFC-D)\nC***KEYWORDS B-SPLINE, CONSTRAINED LEAST SQUARES, CURVE FITTING\nC***AUTHOR Hanson, R. J., (SNLA)\nC***DESCRIPTION\nC\nC This subprogram fits a piecewise polynomial curve\nC to discrete data. The piecewise polynomials are\nC represented as B-splines.\nC The fitting is done in a weighted least squares sense.\nC\nC The data can be processed in groups of modest size.\nC The size of the group is chosen by the user. This feature\nC may be necessary for purposes of using constrained curve fitting\nC with subprogram DFC( ) on a very large data set.\nC\nC For a description of the B-splines and usage instructions to\nC evaluate them, see\nC\nC C. W. de Boor, Package for Calculating with B-Splines.\nC SIAM J. Numer. Anal., p. 441, (June, 1977).\nC\nC For further discussion of (constrained) curve fitting using\nC B-splines, see\nC\nC R. J. Hanson, Constrained Least Squares Curve Fitting\nC to Discrete Data Using B-Splines, a User's\nC Guide. Sandia Labs. Tech. Rept. SAND-78-1291,\nC December, (1978).\nC\nC Input.. All TYPE REAL variables are DOUBLE PRECISION\nC NDATA,XDATA(*),\nC YDATA(*),\nC SDDATA(*)\nC The NDATA discrete (X,Y) pairs and the Y value\nC standard deviation or uncertainty, SD, are in\nC the respective arrays XDATA(*), YDATA(*), and\nC SDDATA(*). No sorting of XDATA(*) is\nC required. Any non-negative value of NDATA is\nC allowed. A negative value of NDATA is an\nC error. A zero value for any entry of\nC SDDATA(*) will weight that data point as 1.\nC Otherwise the weight of that data point is\nC the reciprocal of this entry.\nC\nC NORD,NBKPT,\nC BKPT(*)\nC The NBKPT knots of the B-spline of order NORD\nC are in the array BKPT(*). Normally the\nC problem data interval will be included between\nC the limits BKPT(NORD) and BKPT(NBKPT-NORD+1).\nC The additional end knots BKPT(I),I=1,...,\nC NORD-1 and I=NBKPT-NORD+2,...,NBKPT, are\nC required to compute the functions used to fit\nC the data. No sorting of BKPT(*) is required.\nC Internal to DEFC( ) the extreme end knots may\nC be reduced and increased respectively to\nC accommodate any data values that are exterior\nC to the given knot values. The contents of\nC BKPT(*) is not changed.\nC\nC NORD must be in the range 1 .LE. NORD .LE. 20.\nC The value of NBKPT must satisfy the condition\nC NBKPT .GE. 2*NORD.\nC Other values are considered errors.\nC\nC (The order of the spline is one more than the\nC degree of the piecewise polynomial defined on\nC each interval. This is consistent with the\nC B-spline package convention. For example,\nC NORD=4 when we are using piecewise cubics.)\nC\nC MDEIN\nC An integer flag, with one of two possible\nC values (1 or 2), that directs the subprogram\nC action with regard to new data points provided\nC by the user.\nC\nC =1 The first time that DEFC( ) has been\nC entered. There are NDATA points to process.\nC\nC =2 This is another entry to DEFC(). The sub-\nC program DEFC( ) has been entered with MDEIN=1\nC exactly once before for this problem. There\nC are NDATA new additional points to merge and\nC process with any previous points.\nC (When using DEFC( ) with MDEIN=2 it is import-\nC ant that the set of knots remain fixed at the\nC same values for all entries to DEFC( ).)\nC LW\nC The amount of working storage actually\nC allocated for the working array W(*).\nC This quantity is compared with the\nC actual amount of storage needed in DEFC( ).\nC Insufficient storage allocated for W(*) is\nC an error. This feature was included in DEFC\nC because misreading the storage formula\nC for W(*) might very well lead to subtle\nC and hard-to-find programming bugs.\nC\nC The length of the array W(*) must satisfy\nC\nC LW .GE. (NBKPT-NORD+3)*(NORD+1)+\nC (NBKPT+1)*(NORD+1)+\nC 2*MAX(NDATA,NBKPT)+NBKPT+NORD**2\nC\nC Output.. All TYPE REAL variables are DOUBLE PRECISION\nC MDEOUT\nC An output flag that indicates the status\nC of the curve fit.\nC\nC =-1 A usage error of DEFC( ) occurred. The\nC offending condition is noted with the SLATEC\nC library error processor, XERMSG( ). In case\nC the working array W(*) is not long enough, the\nC minimal acceptable length is printed.\nC\nC =1 The B-spline coefficients for the fitted\nC curve have been returned in array COEFF(*).\nC\nC =2 Not enough data has been processed to\nC determine the B-spline coefficients.\nC The user has one of two options. Continue\nC to process more data until a unique set\nC of coefficients is obtained, or use the\nC subprogram DFC( ) to obtain a specific\nC set of coefficients. The user should read\nC the usage instructions for DFC( ) for further\nC details if this second option is chosen.\nC COEFF(*)\nC If the output value of MDEOUT=1, this array\nC contains the unknowns obtained from the least\nC squares fitting process. These N=NBKPT-NORD\nC parameters are the B-spline coefficients.\nC For MDEOUT=2, not enough data was processed to\nC uniquely determine the B-spline coefficients.\nC In this case, and also when MDEOUT=-1, all\nC values of COEFF(*) are set to zero.\nC\nC If the user is not satisfied with the fitted\nC curve returned by DEFC( ), the constrained\nC least squares curve fitting subprogram DFC( )\nC may be required. The work done within DEFC( )\nC to accumulate the data can be utilized by\nC the user, if so desired. This involves\nC saving the first (NBKPT-NORD+3)*(NORD+1)\nC entries of W(*) and providing this data\nC to DFC( ) with the \"old problem\" designation.\nC The user should read the usage instructions\nC for subprogram DFC( ) for further details.\nC\nC Working Array.. All TYPE REAL variables are DOUBLE PRECISION\nC W(*)\nC This array is typed DOUBLE PRECISION.\nC Its length is specified as an input parameter\nC in LW as noted above. The contents of W(*)\nC must not be modified by the user between calls\nC to DEFC( ) with values of MDEIN=1,2,2,... .\nC The first (NBKPT-NORD+3)*(NORD+1) entries of\nC W(*) are acceptable as direct input to DFC( )\nC for an \"old problem\" only when MDEOUT=1 or 2.\nC\nC Evaluating the\nC Fitted Curve..\nC To evaluate derivative number IDER at XVAL,\nC use the function subprogram DBVALU( ).\nC\nC F = DBVALU(BKPT,COEFF,NBKPT-NORD,NORD,IDER,\nC XVAL,INBV,WORKB)\nC\nC The output of this subprogram will not be\nC defined unless an output value of MDEOUT=1\nC was obtained from DEFC( ), XVAL is in the data\nC interval, and IDER is nonnegative and .LT.\nC NORD.\nC\nC The first time DBVALU( ) is called, INBV=1\nC must be specified. This value of INBV is the\nC overwritten by DBVALU( ). The array WORKB(*)\nC must be of length at least 3*NORD, and must\nC not be the same as the W(*) array used in the\nC call to DEFC( ).\nC\nC DBVALU( ) expects the breakpoint array BKPT(*)\nC to be sorted.\nC\nC***REFERENCES R. J. Hanson, Constrained least squares curve fitting\nC to discrete data using B-splines, a users guide,\nC Report SAND78-1291, Sandia Laboratories, December\nC 1978.\nC***ROUTINES CALLED DEFCMN\nC***REVISION HISTORY (YYMMDD)\nC 800801 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890531 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900510 Change Prologue comments to refer to XERMSG. (RWC)\nC 900607 Editorial changes to Prologue to make Prologues for EFC,\nC DEFC, FC, and DFC look as much the same as possible. (RWC)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE DEFC\nC\nC SUBROUTINE FUNCTION/REMARKS\nC\nC DBSPVN( ) COMPUTE FUNCTION VALUES OF B-SPLINES. FROM\nC THE B-SPLINE PACKAGE OF DE BOOR NOTED ABOVE.\nC\nC DBNDAC( ), BANDED LEAST SQUARES MATRIX PROCESSORS.\nC DBNDSL( ) FROM LAWSON-HANSON, SOLVING LEAST\nC SQUARES PROBLEMS.\nC\nC DSORT( ) DATA SORTING SUBROUTINE, FROM THE\nC SANDIA MATH. LIBRARY, SAND77-1441.\nC\nC XERMSG( ) ERROR HANDLING ROUTINE\nC FOR THE SLATEC MATH. LIBRARY.\nC SEE SAND78-1189, BY R. E. JONES.\nC\nC DCOPY( ),DSCAL( ) SUBROUTINES FROM THE BLAS PACKAGE.\nC\nC WRITTEN BY R. HANSON, SANDIA NATL. LABS.,\nC ALB., N. M., AUGUST-SEPTEMBER, 1980.\nC\n DOUBLE PRECISION BKPT(*),COEFF(*),W(*),SDDATA(*),XDATA(*),YDATA(*)\n INTEGER LW, MDEIN, MDEOUT, NBKPT, NDATA, NORD\nC\n EXTERNAL DEFCMN\nC\n INTEGER LBF, LBKPT, LG, LPTEMP, LWW, LXTEMP, MDG, MDW\nC\nC***FIRST EXECUTABLE STATEMENT DEFC\nC LWW=1 USAGE IN DEFCMN( ) OF W(*)..\nC LWW,...,LG-1 W(*,*)\nC\nC LG,...,LXTEMP-1 G(*,*)\nC\nC LXTEMP,...,LPTEMP-1 XTEMP(*)\nC\nC LPTEMP,...,LBKPT-1 PTEMP(*)\nC\nC LBKPT,...,LBF BKPT(*) (LOCAL TO DEFCMN( ))\nC\nC LBF,...,LBF+NORD**2 BF(*,*)\nC\n MDG = NBKPT+1\n MDW = NBKPT-NORD+3\n LWW = 1\n LG = LWW + MDW*(NORD+1)\n LXTEMP = LG + MDG*(NORD+1)\n LPTEMP = LXTEMP + MAX(NDATA,NBKPT)\n LBKPT = LPTEMP + MAX(NDATA,NBKPT)\n LBF = LBKPT + NBKPT\n CALL DEFCMN(NDATA,XDATA,YDATA,SDDATA,\n 1 NORD,NBKPT,BKPT,\n 2 MDEIN,MDEOUT,\n 3 COEFF,\n 4 W(LBF),W(LXTEMP),W(LPTEMP),W(LBKPT),\n 5 W(LG),MDG,W(LWW),MDW,LW)\n RETURN\n END\n", "meta": {"hexsha": "ded6e8443e89e16a0ae912721eb18fb06ae12a67", "size": 12753, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/idl/extern/sdss/idlutils/src/slatec/defc.f", "max_stars_repo_name": "sfarrens/cosmostat", "max_stars_repo_head_hexsha": "a475315cda06dca346095a1e83cb6ad23979acae", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-02-09T05:03:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-26T10:20:02.000Z", "max_issues_repo_path": "src/idl/extern/sdss/idlutils/src/slatec/defc.f", "max_issues_repo_name": "sfarrens/cosmostat", "max_issues_repo_head_hexsha": "a475315cda06dca346095a1e83cb6ad23979acae", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2020-04-28T17:09:50.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-01T16:24:43.000Z", "max_forks_repo_path": "src/idl/extern/sdss/idlutils/src/slatec/defc.f", "max_forks_repo_name": "sfarrens/cosmostat", "max_forks_repo_head_hexsha": "a475315cda06dca346095a1e83cb6ad23979acae", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-06-22T07:53:00.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-10T19:59:53.000Z", "avg_line_length": 47.4089219331, "max_line_length": 72, "alphanum_fraction": 0.5233278444, "num_tokens": 3127, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418178895029, "lm_q2_score": 0.737158174177441, "lm_q1q2_score": 0.6812386951564472}} {"text": "MODULE mod_fft\nIMPLICIT NONE\nPRIVATE\nPUBLIC :: init_fft, fft23, fft23han ! SUBROUTINE\nINTEGER, PUBLIC :: indx576(1152), indx192(384)\nCOMPLEX (KIND = 8), PUBLIC :: omega576(0:1151), omega192(0:383), sqrt3_2\nREAL (KIND = 8), PUBLIC :: han576(1152), han192(384)\nREAL (KIND = 8) :: pi\nCONTAINS\n!-----------------------------------------------------------------------------------------------------------------\nSUBROUTINE init_fft\nIMPLICIT NONE\nINTEGER :: i, k, n, m\npi = 4.0d0 * ATAN(1.0d0)\nsqrt3_2 = CMPLX(0.0d0, SQRT(0.75d0), KIND = 8) ! iSQRT(3) / 2\n!\nindx576 = 1\nDO i = 1, 1152\n DO k = 1, 7\n n = 2**(k - 1)\n m = 1152 / 2**k\n indx576(i) = indx576(i) + ( MOD(i - 1, 2 * m) / m ) * n\n END DO\n DO k = 1, 2\n n = 2**6 * 3**(k - 1) \n m = 1152 / 2**6 / 3**k\n indx576(i) = indx576(i) + ( MOD(i - 1, 3 * m) / m ) * n\n END DO\n omega576(i - 1) = EXP( CMPLX(0.0d0, 2.0d0 * pi / 1152.0d0 * REAL(i - 1, KIND = 8), KIND = 8) )\n! han576(i) = SQRT(8.0d0 / 3.0d0) * 0.5d0 *( 1.0d0 - COS(2.0d0 * pi * REAL(i - 1, KIND = 8) / 1152.0d0 ) )\n han576(i) = 0.5d0 *( 1.0d0 - COS(2.0d0 * pi * REAL(i - 1, KIND = 8) / 1152.0d0 ) )\nEND DO\n!\nindx192 = 1\nDO i = 1, 192\n DO k = 1, 6\n n = 2**(k - 1)\n m = 384 / 2**k\n indx192(i) = indx192(i) + ( MOD(i - 1, 2 * m) / m ) * n\n END DO\n DO k = 1, 1\n n = 2**6 * 3**(k - 1) \n m = 384 / 2**6 / 3**k\n indx192(i) = indx192(i) + ( MOD(i - 1, 3 * m) / m ) * n\n END DO\n omega192(i - 1) = EXP( CMPLX(0.0d0, 2.0d0 * pi / 384.0d0 * REAL(i - 1, KIND = 8), KIND = 8) )\n! han192(i) = SQRT(8.0d0 / 3.0d0) * 0.5d0 *( 1.0d0 - COS(2.0d0 * pi * REAL(i - 1, KIND = 8) / 384.0d0 ) )\n han192(i) = 0.5d0 *( 1.0d0 - COS(2.0d0 * pi * REAL(i - 1, KIND = 8) / 384.0d0 ) )\nEND DO\nEND SUBROUTINE init_fft\n!-----------------------------------------------------------------------------------------------------------------\nSUBROUTINE fft23(np2, np3, indx, omega, fft)\nINTEGER , INTENT(IN ) :: np2, np3, indx(:)\nCOMPLEX (KIND = 8), INTENT(IN ) :: omega(0:)\nCOMPLEX (KIND = 8), INTENT(IN OUT) :: fft(:)\nCOMPLEX (KIND = 8) :: c1, c2, c3, c4, tmp1, tmp2, tmp3\nINTEGER :: i, j, nn, iphase1, iphase2, m1, m2, m3, k3, kn3, k2, kn2\nnn = 2**np2 * 3**np3\nfft = fft(indx) / REAL(nn, KIND = 8) ! reorder and normalize\n! 3**np3\nDO k3 = 1, np3 ! 3^n (n=2)\n kn3 = 3**(k3 - 1)\n DO i = 1, nn, 3 * kn3 \n DO j = 1, kn3\n iphase1 = 2**np2 * 3**(np3 - k3) * (j - 1) \n iphase2 = 2 * iphase1\n c1 = omega( MOD(iphase1, nn) )\n c2 = omega( MOD(iphase2, nn) )\n m1 = i + j - 1\n m2 = m1 + kn3\n m3 = m2 + kn3\n tmp1 = fft(m1)\n tmp2 = c1 * fft(m2)\n tmp3 = c2 * fft(m3)\n fft(m1) = tmp1 + tmp2 + tmp3\n c3 = tmp1 - 0.5d0 * ( tmp2 + tmp3 )\n c4 = sqrt3_2 * ( tmp2 - tmp3 ) ! sqrt3_2 = i sqrt(3) / 2\n fft(m2) = c3 + c4\n fft(m3) = c3 - c4\n END DO\n END DO\nEND DO\n! 2**np2\nDO k2 = 1, np2\n kn2 = 2**(k2 - 1) * 3**np3\n DO i = 1, nn, 2 * kn2\n DO j = 1, kn2 \n iphase1 = 2**(np2 - k2) * (j - 1) \n c1 = omega( MOD(iphase1, nn) )\n m1 = i + j - 1\n m2 = m1 + kn2\n tmp2 = c1 * fft(m2)\n fft(m2) = fft(m1) - tmp2\n fft(m1) = fft(m1) + tmp2\n END DO\n END DO\nEND DO\nRETURN\nEND SUBROUTINE fft23\n!-----------------------------------------------------------------------------------------------------------------\nSUBROUTINE fft23han(np2, np3, indx, omega, fft, han)\nINTEGER , INTENT(IN ) :: np2, np3, indx(:)\nCOMPLEX (KIND = 8), INTENT(IN ) :: omega(0:)\nCOMPLEX (KIND = 8), INTENT(IN OUT) :: fft(:)\nREAL (KIND = 8), INTENT(IN ) :: han(:)\nfft = fft * han\nCALL fft23(np2, np3, indx, omega, fft)\nRETURN\nEND SUBROUTINE fft23han\n!-----------------------------------------------------------------------------------------------------------------\nEND MODULE mod_fft\n!==================================================================================================================\nMODULE mod_psycho\nUSE mod_mpg\nUSE mod_fft\nIMPLICIT NONE\nPRIVATE\nPUBLIC :: psycho, calc_mask ! subroutine\nREAL (KIND = 8) :: pi, pi2\nREAL (KIND = 8) :: ath_l(576) , ath_s(192, 3)\nREAL (KIND = 8) :: sf_l(576, 576), sf_s(192, 192) \nREAL (KIND = 8) :: afft_l(576, 2, 2), afft_s(192, 3, 2, 2)\nREAL (KIND = 8) :: phi_l(576, 2, 2), phi_s(192, 3, 2, 2)\nREAL (KIND = 8) :: freq_l(576), freq_s(192), bark_l(576), bark_s(192), bw_l(576), bw_s(192)\nREAL (KIND = 8) :: weight_l(576), weight_s(192)\nINTEGER :: ibark_l(576), ibark_s(192), ifb_l(25, 0:2), ifb_s(25, 0:2)\n!\nCONTAINS\n!----------------------------------------------------------------\nSUBROUTINE init_absolute_threshold(isample_rate)\nIMPLICIT NONE\nINTEGER, INTENT(IN ) :: isample_rate\nREAL(KIND = 8):: freq, temp !, ath(576)\nINTEGER :: i, k\npi = 4.0d0 * ATAN(1.0d0)\npi2 = 2.0d0 * pi \nDO i = 1, 576\n freq = REAL(isample_rate, KIND = 8) / 2.0d0 / 1000.0d0 * (REAL(i, KIND = 8) - 0.0d0) / 576.0d0\n! temp = 3.64d0 * freq ** (-0.8d0) & \n! - 6.50d0 * EXP(-0.6d0 * (freq - 3.3d0)**2.0d0) &\n! + 0.001d0 * freq ** 4.0d0 & \n! + ath_min\n temp = 3.64d0 * freq ** (-0.8d0) & ! alternative ATH function \n - 6.50d0 * EXP(-0.6d0 * (freq - 3.3d0)**2.0d0) & ! reference: LAME ath-type 3 \n + 5.1d0 \n!\n IF (freq > 5.0d0 .AND. freq <= 5.5d0) THEN\n temp = 5.1d0 + 4.0d0 * (freq - 5.0d0) \n ELSE IF (freq > 5.5d0 .AND. freq <= 8.0d0) THEN \n temp = 7.1d0 + 2.76d0 * (freq - 5.5d0) \n ELSE IF (freq > 8.0d0 .AND. freq <= 10.0d0) THEN\n temp = 14.0d0 + 1.00d0 * (freq - 8.0d0) \n ELSE IF (freq > 10.0d0 .AND. freq <= 11.5d0) THEN\n temp = 16.0d0 + 0.33d0 * (freq - 10.0d0) \n ELSE IF (freq > 11.5d0 .AND. freq <= 12.0d0) THEN\n temp = 16.5d0 + 2.0d0 * (freq - 11.5d0) \n ELSE IF (freq > 12.0d0) THEN\n temp = 0.001d0 * freq ** 3.81d0 + 4.60d0 ! 12.93 \n!\n! temp = 0.001d0 * freq ** 3.80d0 + 4.92d0 ! 12.61 \n! temp = 0.001d0 * freq ** 3.81d0 + 4.60d0 ! 12.93 \n! temp = 0.001d0 * freq ** 3.82d0 + 4.27d0 ! 13.26 \n! temp = 0.001d0 * freq ** 3.83d0 + 3.94d0 ! 13.59 \n! temp = 0.001d0 * freq ** 3.84d0 + 3.61d0 ! 13.93 \n! temp = 0.001d0 * freq ** 3.85d0 + 3.27d0 ! 14.28 \n! temp = 0.001d0 * freq ** 4.00d0 - 2.86d0 ! 20.70 \n END IF\n temp = MIN(temp + ath_min, ath_max) \n ath_l(i) = 10.0d0**(temp / 20.0d0) \nEND DO\n!\nDO i = 1, 192\n k = 3 * (i - 1) + 1\n ath_s(i, :) = MINVAL( ath_l(k:k + 2) ) \nEND DO\nRETURN\nEND SUBROUTINE init_absolute_threshold\n!------------------------------------------------------------------------------------------------\nFUNCTION switch_q(wx) RESULT(ires) ! attack detection (UZURA original)\nIMPLICIT NONE\nREAL (KIND = 8), INTENT(IN) :: wx(:, :)\nINTEGER :: ires\nREAL (KIND = 8), SAVE :: sum0a, sum1a, sum0b, sum1b\nsum0a = sum1a\nsum1a = SUM( wx(1:36, :) )\nsum0b = sum1b\nsum1b = SUM( wx(37: , :) ) \nIF ( sum1a > switch * sum0a .OR. sum1b > switch * sum0b ) THEN\n ires = mblock_type_param\n IF (q_sm .AND. sum1a < xsm * sum0a .AND. sum0a < xsm * sum1a ) ires = 21 ! mixed \nELSE \n ires = 0 \nEND IF\nIF (mblock_type_param == 0) ires = 0 ! force long-only mode\n!debug info\nif ( sum1a >= switch * sum0a ) nn1 = nn1 + 1\nif ( sum1b >= switch * sum0b ) nn2 = nn2 + 1\nRETURN\nEND FUNCTION switch_q\n!--------------------------------------------------------------------------------------------------------------------\nSUBROUTINE attack(wx, mblock_type) !..... ! ISO Figure C.7 (p.95) Window Switching State Diagram\nIMPLICIT NONE\nREAL (KIND = 8), INTENT(IN ) :: wx(:, :, :)\nINTEGER , INTENT(OUT) :: mblock_type(:, :)\nINTEGER :: i, iattack\nINTEGER, SAVE :: mblock_prev = 0\nDO i = 1, 2\n iattack = switch_q(wx(:, i, :))\n SELECT CASE (iattack)\n CASE (0) ! no-attack\n SELECT CASE (mblock_prev)\n CASE ( 0, 30, 31) ! long\n mblock_type(i, :) = 0\n CASE (10) \n mblock_type(i, :) = 20\n CASE (11) \n mblock_type(i, :) = 21\n CASE (20) ! short\n mblock_type(i, :) = 30\n CASE (21) ! mixed\n mblock_type(i, :) = 31\n CASE DEFAULT\n WRITE(*, *) 'error: psycho : unexpected block type: case 0-x', i, mblock_prev, mblock_type(i, 1) \n STOP\n END SELECT\n CASE (20) ! attack-short\n SELECT CASE (mblock_prev)\n CASE ( 0, 30, 31) \n mblock_type(i, :) = 10\n CASE (10) \n mblock_type(i, :) = 20\n CASE (11) \n mblock_type(i, :) = 21\n CASE (20) \n mblock_type(i, :) = 20\n CASE (21) \n mblock_type(i, :) = 21 \n CASE DEFAULT\n WRITE(*, *) 'error: psycho : unexpected block type: case 20-x', i, mblock_prev, mblock_type(i, 1) \n STOP\n END SELECT\n CASE (21) ! attack-mixed\n SELECT CASE (mblock_prev)\n CASE ( 0, 30, 31) \n mblock_type(i, :) = 11\n CASE (10) \n mblock_type(i, :) = 20\n CASE (11) \n mblock_type(i, :) = 21\n CASE (20) \n mblock_type(i, :) = 20 \n CASE (21) \n mblock_type(i, :) = 21\n CASE DEFAULT\n WRITE(*, *) 'error: psycho : unexpected block type: case 21-x', i, mblock_prev, mblock_type(i, 1) \n STOP\n END SELECT\n CASE DEFAULT\n WRITE(*, *) 'error: psycho : unexpected block type'\n STOP\n END SELECT\n !mblock_type = 20 ! for debug\n mblock_prev = mblock_type(i, 1)\n!....... debug info ...............................................\n select case ( mblock_type(i, 1) )\n case ( 0) \n long = long + 1\n case (20)\n nshort = nshort + 1\n case (21) \n mix = mix + 1\n case (10, 11)\n m1 = m1 + 1\n case (30, 31)\n m3 = m3 + 1\n end select\n!\nEND DO\nRETURN\nEND SUBROUTINE attack\n!-----------------------------------------------------------------------------------------------------------------------\n! not working correctly ; MDCT based version is better \nSUBROUTINE mid_side(mpg, wx, mblock_type) ! ISO C.2.4.3.4.9.2, G.2 MS_Stereo and intensity stereo coding Layer III\nIMPLICIT NONE \nREAL (KIND = 8) , INTENT(IN ) :: wx(:, :, :)\nTYPE (mpeg_parameters), INTENT(IN OUT) :: mpg\nINTEGER , INTENT(IN) :: mblock_type(:, :)\nINTEGER :: igranule, nchannel, n0, n1\nREAL (KIND = 8) :: tmp1, tmp2\nINTEGER, SAVE :: mode_old = 0, mode_ext_old = 0\nLOGICAL :: qms\nnchannel = SIZE(wx, 3)\nqms = qms_stereo\nSELECT CASE (mpg%isample_rate) ! threshold ~ 7kHz (empirical value)\n CASE (0) ! 44.1kHz\n n0 = 183\n CASE (1) ! 48.0kHz\n n0 = 168\n CASE (2) ! 32.0kHz\n n0 = 252\n CASE DEFAULT\n STOP ' sample_rate error : SUBROUTINE mid_side '\nEND SELECT\nn1 = n0 + 1\ntmp1 = 0.0d0\ntmp2 = 0.0d0\nDO igranule = 1, 2\n! pop musics often have different L-R behavior in low and high frequency \n tmp1 = tmp1 + SUM( ABS( wx(1:n0, igranule, 1) - wx(1:n0, igranule, 2) ) ) \n tmp2 = tmp2 + SUM( ( wx(1:n0, igranule, 1) + wx(1:n0, igranule, 2) ) ) \nEND DO\nIF ( tmp1 > xms * tmp2 ) THEN \n qms = .FALSE.\n ns1 = ns1 + 1\n ns = ns + 1\nEND IF\nn1 = n0 + 1\ntmp1 = 0.0d0\ntmp2 = 0.0d0\nDO igranule = 1, 2\n! pop musics often have different L-R behavior in low and high frequency \n tmp1 = tmp1 + SUM( ABS( wx(n1:, igranule, 1) - wx(n1:, igranule, 2) ) ) \n tmp2 = tmp2 + SUM( ( wx(n1:, igranule, 1) + wx(n1:, igranule, 2) ) ) \nEND DO\nIF ( ABS(tmp1) > xms * ABS(tmp2) ) THEN \n qms = .FALSE.\n ns1 = ns1 + 1\n ns = ns + 1\nEND IF\n!\nIF (mblock_type(1, 1) /= 0 .AND. mblock_type(1, 1) /= 20 .AND. mblock_type(1, 1) /= 21) THEN \n mpg%mode = 0 !mode_old \n mpg%mode_extension = 0 ! mode_ext_old\nELSE\n IF (qms) THEN \n mpg%mode = 1 ! joint stereo\n mpg%mode_extension = 2 ! intensity_stereo off / ms_stereo on\n ms = ms + 1 \n ELSE\n mpg%mode = 0 ! normal stereo\n mpg%mode_extension = 0 ! intensity_stereo off / ms_stereo off \n END IF\nEND IF \nmode_old = mpg%mode \nmode_ext_old = mpg%mode_extension \nRETURN\nEND SUBROUTINE mid_side\n!------------------------------------------------------------------------------------------------\nSUBROUTINE fft_long(nchannel, pcm, afft_l, phi_l)\nIMPLICIT NONE\nINTEGER , INTENT(IN ) :: nchannel\nREAL (KIND = 8), INTENT(IN ) :: pcm(:, :)\nREAL (KIND = 8), INTENT(OUT) :: afft_l(:, :, :), phi_l(:, :, :)\nCOMPLEX (KIND = 8) :: fft576(1152, 2, 2)\nINTEGER :: ichannel, igranule, m1,m2\nDO igranule = 1, 2\n DO ichannel = 1, nchannel\n m1 = 1 + 480 * (igranule - 1)\n m2 = m1 + 1152 - 1\n fft576(:, igranule, ichannel) = CMPLX(PCM(m1:m2, ichannel), 0.0d0, KIND = 8) ! put 1152 real data -> get 576 complex FFT\n! CALL fft23han(7, 2, indx576, omega576, fft576(:, igranule, ichannel), han576 ) ! 2^7 * 3^2 = 1152\n CALL fft23(7, 2, indx576, omega576, fft576(:, igranule, ichannel) )\n afft_l (:, igranule, ichannel) = ABS(fft576(1:576, igranule, ichannel))\n afft_l (:, igranule, ichannel) = afft_l (:, igranule, ichannel) \n phi_l(:, igranule, ichannel) = ATAN2(AIMAG(fft576(1:576, igranule, ichannel)), REAL(fft576(1:576, igranule, ichannel)))\n END DO\nEND DO\nphi_l = phi_l + pi ! ATAN -pi~pi -> 0~2pi\nRETURN\nEND SUBROUTINE fft_long\n!------------------------------------------------------------------------------------------------\nSUBROUTINE fft_short(nchannel, pcm, afft_s, phi_s)\nIMPLICIT NONE\nINTEGER , INTENT(IN ) :: nchannel\nREAL (KIND = 8), INTENT(IN ) :: pcm(:, :)\nREAL (KIND = 8), INTENT(OUT) :: afft_s(:, :, :, :), phi_s(:, :, :, :)\nCOMPLEX (KIND = 8) :: fft192(384, 3, 2, 2)\nINTEGER :: ichannel, igranule, iwin, m1, m2\nDO igranule = 1, 2\n DO ichannel = 1, nchannel\n DO iwin = 1, 3\n m1 = 1 + 480 * (igranule - 1) + 384 * (iwin - 1)\n m2 = m1 + 384 - 1\n fft192(:, iwin, igranule, ichannel) = CMPLX(PCM(m1:m2, ichannel), 0.0d0, KIND = 8) ! put 384 real data -> get 192 complex FFT\n ! CALL fft23han(7, 1, indx192, omega192, fft192(:, iwin, igranule, ichannel), han192 ) ! 2^7 * 3^1 = 384\n CALL fft23(7, 1, indx192, omega192, fft192(:, iwin, igranule, ichannel) )\n afft_s (:, iwin, igranule, ichannel) = ABS(fft192(1:192, iwin, igranule, ichannel))\n afft_s (:, iwin, igranule, ichannel) = afft_s (:, iwin, igranule, ichannel) \n phi_s(:, iwin, igranule, ichannel) = ATAN2(AIMAG(fft192(1:192, iwin, igranule, ichannel)), REAL(fft192(1:192, iwin, igranule, ichannel)))\n END DO\n END DO\nEND DO\nphi_s = phi_s + pi ! ATAN2 -pi~pi -> 0~2pi\nRETURN\nEND SUBROUTINE fft_short\n!------------------------------------------------------------------------------------------------\nSUBROUTINE calc_wx(nchannel, wx)\nIMPLICIT NONE\nINTEGER , INTENT(IN ) :: nchannel\nREAL(KIND = 8), INTENT(OUT) :: wx(:, :, :)\nINTEGER :: igranule, ichannel\nDO igranule = 1, 2\n DO ichannel = 1, nchannel\n wx(:, igranule, ichannel) = ( afft_l(:, igranule, ichannel) * weight_l )**2.0d0 \n END DO\nEND DO\nRETURN\nEND SUBROUTINE calc_wx\n!------------------------------------------------------------------------------------------------\nSUBROUTINE psycho(pcm, mpg, mblock_type)\nIMPLICIT NONE\nTYPE (mpeg_parameters), INTENT(IN OUT) :: mpg\nINTEGER , INTENT( OUT) :: mblock_type(:, :)\nREAL (KIND = 8) , INTENT(IN ) :: pcm(:, :)\nLOGICAL, SAVE :: qfirst = .true.\nINTEGER :: igranule, ichannel, nchannel\nreal (kind = 8) :: wx(576, 2, 2), pm, pm0(2, 2)\n!..... initialization .........................................................................................\nIF (qfirst) THEN\n qfirst = .false. \n !!!- to avoid VBR bug of portable MP3 player DIAMOND MULTIMEDIA RIO500. first frame bitrate must be less than average bitrate\n IF (q_vbr .and. q_rio500) mpg%ibit_rate = 8 ! force first frame 112kbps for RIO500 (firmware 1.15) \n CALL init_absolute_threshold( mpeg_sample_rates(mpg%isample_rate) )\n CALL init_mask( mpeg_sample_rates(mpg%isample_rate) )\n CALL init_fft()\nEND IF\n!..... FFT 576/192 ............................................................................................\nnchannel = SIZE(mblock_type, 2) \nCALL fft_long (nchannel, pcm, afft_l, phi_l)\nCALL fft_short(nchannel, pcm, afft_s, phi_s)\n!..... weighted intensity .....................................................................................\nCALL calc_wx(nchannel, wx)\n!..... attack detection .......................................................................................\nCALL attack(wx, mblock_type)\n!..... MS/NS selection ........................................................................................\n!CALL mid_side(mpg, wx, mblock_type) ! not working correctly : MDCT based model works better\n!..... VBR ...................................................................................................\nIF (q_vbr) THEN ! simple implimentation \n DO igranule = 1, 2\n DO ichannel = 1, nchannel\n pm0(igranule, ichannel) = SUM(wx(:, igranule, ichannel) * bark_l) !Psychoacoustic Moment (UZURA original) \n END DO \n END DO\n pm = SUM(pm0) / ( SUM(wx) + 1.0d-9 )\n IF (pm < 0.1d0) THEN\n mpg%ibit_rate = 1 \n ELSE IF (pm < 1.0d0) THEN\n mpg%ibit_rate = 9 \n ELSE IF (pm * pm_factor < 2.5d0) THEN\n mpg%ibit_rate = 10 \n ELSE IF (pm * pm_factor < 3.5d0) THEN\n mpg%ibit_rate = 11 \n ELSE IF (pm * pm_factor < 5.0d0) THEN\n mpg%ibit_rate = 12 \n ELSE IF (pm * pm_factor < 7.0d0) THEN \n mpg%ibit_rate = 13 \n ELSE \n mpg%ibit_rate = 14\n END IF\nEND IF\nnbits(mpg%ibit_rate) = nbits(mpg%ibit_rate) + 1\nRETURN\nEND SUBROUTINE psycho\n!------------------------------------------------------------------------------------------------\nSUBROUTINE init_mask(nsample_rate)\nIMPLICIT NONE\nINTEGER, INTENT(IN) :: nsample_rate\nINTEGER :: i, j\nREAL (KIND = 8) :: f0, f1\nDO i = 1, 576\n freq_l(i) = REAL(nsample_rate, KIND = 8) / 2.0d0 * (REAL(i, KIND = 8) - 0.5d0) / 576.0d0 ! kHz\n bark_l(i) = bark(freq_l(i) / 1000.0d0) \n ibark_l(i) = INT(bark_l(i) + 0.1d0) + 1 \n f0 = REAL(nsample_rate, KIND = 8) / 2000.0d0 * REAL(i - 1, KIND = 8) / 576.0d0\n f1 = REAL(nsample_rate, KIND = 8) / 2000.0d0 * REAL(i , KIND = 8) / 576.0d0\n bw_l(i) = bark(f1) - bark(f0)\n weight_l(i) = ( bark(f1) - bark(f0) ) / (f1 - f0) \nEND DO\nDO i = 1, 192\n freq_s(i) = REAL(nsample_rate, KIND = 8) / 2.0d0 * (REAL(i, KIND = 8) - 0.5d0) / 192.0d0 ! kHz\n bark_s(i) = bark(freq_s(i) / 1000.0d0) \n ibark_s(i) = INT(bark_s(i)) + 1\n f0 = REAL(nsample_rate, KIND = 8) / 2000.0d0 * REAL(i - 1, KIND = 8) / 192.0d0\n f1 = REAL(nsample_rate, KIND = 8) / 2000.0d0 * REAL(i , KIND = 8) / 192.0d0\n bw_s(i) = bark(f1) - bark(f0)\n weight_s(i) = ( bark(f1) - bark(f0) ) / (f1 - f0) \nEND DO\n!\nifb_l(1, 1) = 1\nDO i = 1, 25\n DO j = 1, 576\n IF (ibark_l(j) == i - 1) ifb_l(i, 1) = j + 1 \n IF (ibark_l(j) == i ) ifb_l(i, 2) = j \n END DO\n ifb_l(i, 0) = ifb_l(i, 2) - ifb_l(i, 1) + 1\nEND DO\nifb_s(1, 1) = 1\nDO i = 1, 25\n DO j = 1, 192\n IF (ibark_s(j) == i - 1) ifb_s(i, 1) = j + 1 \n IF (ibark_s(j) == i ) ifb_s(i, 2) = j \n END DO\n ifb_s(i, 0) = ifb_s(i, 2) - ifb_s(i, 1) + 1\nEND DO\n!\nDO i = 1, 576\n DO j = 1, 576\n sf_l(i, j) = 10.0d0 ** ( spreading_function( bark_l(i) - bark_l(j) ) / 20.0d0 ) \n END DO\nEND DO \nDO i = 1, 192\n DO j = 1, 192\n sf_s(i, j) = 10.0d0 ** ( spreading_function( bark_s(i) - bark_s(j) ) / 20.0d0 ) \n END DO\nEND DO \nRETURN\nEND SUBROUTINE init_mask\n!------------------------------------------------------------------------------------------------\nSUBROUTINE calc_mask(igranule, ichannel, mblock_type, xmask, xnoise)\nIMPLICIT NONE\nINTEGER , INTENT(IN ) :: igranule, ichannel, mblock_type\nREAL (KIND = 8), INTENT( OUT) :: xmask(:, :), xnoise(:, :)\nREAL (KIND = 8) :: x0_l(576), x0_s(192, 3), y0_l(576), y0_s(192, 3)\nREAL (KIND = 8) :: d2phi_l(576), tone_l(576), fk_l(576), fl_l(576), tn_l(576)\nREAL (KIND = 8) :: d2phi_s(192), tone_s(192), fk_s(192), fl_s(192), tn_s(192)\nREAL (KIND = 8) :: yn(25)\nREAL (KIND = 8), SAVE :: x1_l(576) = 0.0d0, x1_s(192, 3) = 0.0d0\nREAL (KIND = 8), SAVE :: phi1_l(576, 2) = 0.0d0, phi2_l(576, 2) = 0.0d0\nREAL (KIND = 8), SAVE :: phi1_s(192, 2) = 0.0d0, phi2_s(192, 2) = 0.0d0\nREAL (KIND = 8), SAVE :: p0_l(576, 2) = 0.0d0, p1_l(576, 2) = 0.0d0, p2_l(576, 2) = 0.0d0\nREAL (KIND = 8), SAVE :: p0_s(192, 2) = 0.0d0, p1_s(192, 2) = 0.0d0, p2_s(192, 2) = 0.0d0\nREAL (KIND = 8), SAVE :: p3_s(192, 2) = 0.0d0, p4_s(192, 2) = 0.0d0, p5_s(192, 2) = 0.0d0\nINTEGER :: icritical_band, iwin\n!---------------------------------------------------------------------------------------------\n! masking / allowed noise : reference Bosse Lincoln \"An Experimental High Fidelity Perceptual Audio Coder Project in MUS420 Win 97\"\n!---------------------------------------------------------------------------------------------\nd2phi_l = phi_l(:, igranule, ichannel) + phi2_l(:, ichannel) - 2.0d0 * phi1_l(:, ichannel) \np0_l(:, ichannel) = MOD( ABS(d2phi_l), pi2 ) / pi2 \ntone_l = 1.0d0 - MAX(p0_l(:, ichannel), p1_l(:, ichannel), p2_l(:, ichannel) ) \n! mask for long block\nfk_l = 0.3d0 * tone_l + 0.5d0 * (1 - tone_l) \nfl_l = 34.0d0 * tone_l + 20.0d0 * (1 - tone_l) \ntn_l = 10.0d0**( - ( fk_l * bark_l + fl_l + offset ) / 20.0d0 ) \nx0_l = MATMUL(sf_l, afft_l(:, igranule, ichannel) * tn_l * weight_l) + ath_l\nx1_l = tempo * x1_l + (1.0d0 - tempo) * x0_l ! temporal masking\nx0_l = MAX(x0_l, x1_l)\n! allowed noise for long block : average mask over a critical band\nDO icritical_band = 1, 25\n yn(icritical_band) = SUM( x0_l(ifb_l(icritical_band, 1):ifb_l(icritical_band, 2)) ) / REAL(ifb_l(icritical_band, 0), KIND = 8)\nEND DO\ny0_l = MAX( ath_l, yn(ibark_l) ) \n! save old data\np1_l(:, ichannel) = p0_l(:, ichannel)\np2_l(:, ichannel) = p1_l(:, ichannel)\nphi1_l(:, ichannel) = phi_l(:, igranule, ichannel)\nphi2_l(:, ichannel) = phi1_l(:, ichannel)\n!\nDO iwin = 1, 3\n d2phi_s = phi_s(:, iwin, igranule, ichannel) + phi2_s(:, ichannel) - 2.0d0 * phi1_s(:, ichannel)\n p0_s(:, ichannel) = MOD( ABS(d2phi_s), pi2 ) / pi2\n tone_s = 1.0d0 - MAX( p0_s(:, ichannel), p1_s(:, ichannel), p2_s(:, ichannel), & \n p3_s(:, ichannel), p4_s(:, ichannel), p5_s(:, ichannel) )\n! mask for short block\n fk_s = 0.3d0 * tone_s + 0.5d0 * (1 - tone_s) \n fl_s = 34.0d0 * tone_s + 20.0d0 * (1 - tone_s) \n tn_s = 10.0d0**( - ( fk_s * bark_s + fl_s + offset ) / 20.0d0 )\n x0_s(:, iwin) = MATMUL(sf_s, afft_s(:, iwin, igranule, ichannel) * tn_s * weight_s) + ath_s(:, iwin)\n! save old data\n p1_s(:, ichannel) = p0_s(:, ichannel)\n p2_s(:, ichannel) = p1_s(:, ichannel)\n p3_s(:, ichannel) = p2_s(:, ichannel)\n p4_s(:, ichannel) = p3_s(:, ichannel)\n p5_s(:, ichannel) = p4_s(:, ichannel)\n phi1_s(:, ichannel) = phi_s(:, iwin, igranule, ichannel)\n phi2_s(:, ichannel) = phi1_s(:, ichannel)\nEND DO\nx1_s(:, 1) = tempo * x1_s(:, 3) + (1.0d0 - tempo) * x0_s(:, 1) ! temporal masking \nx1_s(:, 2) = tempo * x1_s(:, 1) + (1.0d0 - tempo) * x0_s(:, 2) ! \nx1_s(:, 3) = tempo * x1_s(:, 2) + (1.0d0 - tempo) * x0_s(:, 3) ! \nx0_s = MAX(x0_s, x1_s)\n! allowed noise for short block : average mask over a critical band\nDO iwin = 1, 3\n DO icritical_band = 1, 25\n yn(icritical_band) = SUM( x0_s(ifb_s(icritical_band, 1):ifb_s(icritical_band, 2), iwin) ) / REAL(ifb_s(icritical_band, 0), KIND = 8) \n END DO\n y0_s(:, iwin) = MAX( ath_s(:, iwin), yn(ibark_s(:)) ) \nEND DO\n! order to r_mdct style\nSELECT CASE (mblock_type)\n CASE (0, 10, 11, 30, 31)\n CALL deorder_l(x0_l, xmask )\n CALL deorder_l(y0_l, xnoise)\n CASE (20)\n CALL deorder_s(x0_s, xmask )\n CALL deorder_s(y0_s, xnoise)\n CASE (21) \n CALL deorder_m(x0_l, x0_s, xmask )\n CALL deorder_m(y0_l, y0_s , xnoise)\n CASE DEFAULT\n STOP 'SUBROUTINE: calc_noise'\nEND SELECT\nRETURN\nEND SUBROUTINE calc_mask\n!------------------------------------------------------------------------------------------------\nSUBROUTINE deorder_l(zl, xth)\nIMPLICIT NONE\nREAL (KIND = 8), INTENT(IN ) :: zl(:)\nREAL (KIND = 8), INTENT(OUT) :: xth(:, :)\nINTEGER :: i, iband\nDO iband = 1, 32\n DO i = 1, 18\n xth(iband, i) = zl(18 * (iband - 1) + i)\n END DO\nEND DO\nRETURN\nEND SUBROUTINE deorder_l\n!------------------------------------------------------------------------------------------------\nSUBROUTINE deorder_s(zs, xth)\nIMPLICIT NONE\nREAL (KIND = 8), INTENT(IN ) :: zs(:, :)\nREAL (KIND = 8), INTENT(OUT) :: xth(:, :)\nINTEGER :: i, iwin, iband\nDO iband = 1, 32\n DO iwin = 1, 3 \n DO i = 1, 6\n xth(iband, 6 * (iwin - 1) + i) = zs(6 * (iband - 1) + i, iwin) \n END DO\n END DO \nEND DO\nRETURN\nEND SUBROUTINE deorder_s\n!------------------------------------------------------------------------------------------------\nSUBROUTINE deorder_m(zl, zs, xth)\nIMPLICIT NONE\nREAL (KIND = 8), INTENT(IN ) :: zl(:), zs(:, :)\nREAL (KIND = 8), INTENT(OUT) :: xth(:, :)\nINTEGER :: i, iwin, iband\nDO iband = 1, 2\n DO i = 1, 18\n xth(iband, i) = zl( 18 * (iband - 1) + i)\n END DO\nEND DO\nDO iband = 3, 32\n DO iwin = 1, 3 \n DO i = 1, 6\n xth(iband, 6 * (iwin - 1) + i) = zs(6 * (iband - 1) + i, iwin) \n END DO\n END DO \nEND DO\nRETURN\nEND SUBROUTINE deorder_m\n!------------------------------------------------------------------------------------------------\nFUNCTION bark(f) RESULT(res)\nIMPLICIT NONE\nREAL (KIND = 8), INTENT(IN) :: f\nREAL (KIND = 8) :: res\nres = 13.0d0 * ATAN(0.76d0 * f) + 3.5d0 * ATAN( (f / 7.5d0)**2.0d0 )\nRETURN\nEND FUNCTION bark\n!------------------------------------------------------------------------------------------------\nFUNCTION spreading_function(z) RESULT(res)\nIMPLICIT NONE\nREAL (KIND = 8), INTENT(IN) :: z\nREAL (KIND = 8) :: res\nres = 15.81d0 + 7.5d0 * (z + 0.474d0) - 17.5d0 * SQRT(1.0d0 + (z + 0.474d0)**2.0d0) \nRETURN\nEND FUNCTION spreading_function\n!------------------------------------------------------------------------------------------------\nFUNCTION spreading_function0(z) RESULT(res)\nIMPLICIT NONE\nREAL (KIND = 8), INTENT(IN) :: z\nREAL (KIND = 8) :: res\nIF (z < 0.0d0) THEN\n res = 25.0d0 * z\nELSE\n res = -10.0d0 * z\nEND IF \nRETURN\nEND FUNCTION spreading_function0\n!------------------------------------------------------------------------------------------------\nFUNCTION spreading_function2(z, y) RESULT(res)\nIMPLICIT NONE\nREAL (KIND = 8), INTENT(IN) :: z, y\nREAL (KIND = 8) :: res\nres = (15.81d0 - y) + 7.5d0 * (z + 0.474d0) - (17.5d0 - y) * SQRT(1.0d0 + (z + 0.474d0)**2.0d0) \nRETURN\nEND FUNCTION spreading_function2\n!------------------------------------------------------------------------------------------------\nEND MODULE mod_psycho", "meta": {"hexsha": "555dafa64f8a61a1c0e7fde5fc50f8ad605e2bb7", "size": 25744, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "psycho.f90", "max_stars_repo_name": "cure-honey/uzura3", "max_stars_repo_head_hexsha": "890a3a808dd8aa0fd37412367def863fb3bffe78", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2018-04-23T17:51:17.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-17T08:15:17.000Z", "max_issues_repo_path": "psycho.f90", "max_issues_repo_name": "cure-honey/uzura3", "max_issues_repo_head_hexsha": "890a3a808dd8aa0fd37412367def863fb3bffe78", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-01-21T15:48:41.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-21T15:48:41.000Z", "max_forks_repo_path": "psycho.f90", "max_forks_repo_name": "cure-honey/uzura3", "max_forks_repo_head_hexsha": "890a3a808dd8aa0fd37412367def863fb3bffe78", "max_forks_repo_licenses": ["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.3642960813, "max_line_length": 140, "alphanum_fraction": 0.5230733375, "num_tokens": 10024, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418137109956, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6812386814035365}} {"text": " PROGRAM xgolden\r\nC driver for routine golden\r\n REAL EQL,TOL\r\n PARAMETER(TOL=1.0E-6,EQL=1.E-3)\r\n INTEGER i,iflag,j,nmin\r\n REAL amin(20),ax,bx,cx,fa,fb,fc,g,xmin\r\n REAL bessj0,bessj1,golden\r\n EXTERNAL bessj0\r\n nmin=0\r\n write(*,'(/1x,a)') 'Minima of the function BESSJ0'\r\n write(*,'(/1x,t6,a,t19,a,t27,a,t40,a/)') 'Min. #','X',\r\n * 'BESSJ0(X)','BESSJ1(X)'\r\n do 12 i=1,100\r\n ax=i\r\n bx=i+1.0\r\n call mnbrak(ax,bx,cx,fa,fb,fc,bessj0)\r\n g=golden(ax,bx,cx,bessj0,TOL,xmin)\r\n if (nmin.eq.0) then\r\n amin(1)=xmin\r\n nmin=1\r\n write(*,'(1x,5x,i2,3x,3f12.6)') nmin,xmin,\r\n * bessj0(xmin),bessj1(xmin)\r\n else\r\n iflag=0\r\n do 11 j=1,nmin\r\n if (abs(xmin-amin(j)).le.EQL*xmin)\r\n * iflag=1\r\n11 continue\r\n if (iflag.eq.0) then\r\n nmin=nmin+1\r\n amin(nmin)=xmin\r\n write(*,'(1x,5x,i2,3x,3f12.6)') nmin,\r\n * xmin,bessj0(xmin),bessj1(xmin)\r\n endif\r\n endif\r\n12 continue\r\n END\r\n", "meta": {"hexsha": "511563349f11bcbff767171fd58abef7224cfbe7", "size": 1126, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xgolden.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xgolden.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xgolden.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.6315789474, "max_line_length": 61, "alphanum_fraction": 0.4751332149, "num_tokens": 427, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314858927011, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.6811216684402177}} {"text": "program realcomp\n ! This program tests and compares the performance\n ! of single and double precision real problems\n\n use flips\n use rand\n\n implicit none\n\n ! types\n type(flips_c) :: gs\n type(flips_z) :: gd\n\n ! data matrices\n complex(sp), dimension(:,:), allocatable :: amat_s, smat_s, mmat_s\n complex(dp), dimension(:,:), allocatable :: amat_d, smat_d, mmat_d\n\n\n ! Errors\n complex(sp) :: meanerr_d,meanerr_s\n real(dp) :: maxerr_d,maxerr_s\n\n\n ! Residuals\n real(sp) :: res_s\n real(dp) :: res_d\n\n\n ! Clocks/times\n real(dp) :: cts,cte,ctime1,ctime2\n real(sp) :: wts,wte,wtime1,wtime2\n\n ! Aux variables\n integer :: ns,n,bs\n real(sp), dimension(:,:), allocatable :: sauxmat, sauxmat2\n real(dp), dimension(:,:), allocatable :: dauxmat, dauxmat2\n\n ! Set random seed\n call set_rand_seed()\n\n ! Ask size\n write(*,*) 'Give matrix size:'\n read(*,*) ns\n\n bs = 50000/ns\n\n ! allocate things\n allocate(amat_s(ns,ns),amat_d(ns,ns),smat_s(ns,1),smat_d(ns,1),&\n mmat_s(ns,1),mmat_d(ns,1),sauxmat(ns,ns),sauxmat2(ns,1),&\n dauxmat(ns,ns),dauxmat2(ns,1))\n\n ! Single pprecision\n\n ! Create data (theory matrix random, soluton 1's)\n call random_number(sauxmat)\n amat_s = sauxmat\n call random_number(sauxmat)\n amat_s = amat_s + (0.0,1.0)*sauxmat\n smat_s = (1.0,1.0)\n mmat_s = matmul(amat_s,smat_s)\n\n ! init flips\n call flips_init(gs,ns,1,buffersize=bs)\n\n ! add data and solve with residual\n call cpu_time(cts)\n !call system_clock(wts)\n do n = 1,ns\n call flips_add(gs,1,amat_s(n,:),mmat_s(n,:))\n end do\n call flips_solve(gs)\n call cpu_time(cte)\n !call system_clock(wte)\n !wtime1 = wte-wts\n ctime1 = cte-cts\n\n ! Calculate diagonal of the covariance\n call cpu_time(cts)\n !call system_clock(wts)\n call flips_calc_cov(gs,full=.TRUE.)\n call cpu_time(cte)\n !call system_clock(wte)\n !wtime2 = wte-wts\n ctime2 = cte-cts\n\n ! Errors\n maxerr_s = maxval(abs(smat_s(:,1) - gs%solmat))\n meanerr_s = sum(smat_s(:,1) - gs%solmat)/ns\n\n ! Print results\n write(*,*) '---------------------------------------'\n write(*,*) 'Single precision complex, size:',ns\n write(*,*) '---------------------------------------'\n write(*,*) ' Solution, CPU time:',ctime1\n !write(*,*) 'Solution, wall clock:',wtime1\n write(*,*) 'Covariance, CPU time:',ctime2\n !write(*,*) 'Covariance, wall clock:',wtime2\n write(*,*) ' Mean error:',meanerr_s\n write(*,*) ' Max. abs. error:',maxerr_s\n write(*,*) ' Residual:',gs%residual\n ! write(*,*) gs%cmat\n write(*,*) '---------------------------------------\\n'\n\n\n\n ! Double precision\n\n ! Create data (theory matrix random, soluton 1's)\n call random_number(dauxmat)\n amat_d = dauxmat\n call random_number(dauxmat)\n amat_d = amat_d + (0.0D0,1.0D0)*dauxmat\n smat_d = (1.0D0,1.0D0)\n mmat_d = matmul(amat_d,smat_d)\n\n ! init flips\n call flips_init(gd,ns,1,buffersize=bs)\n\n ! add data and solve with residual\n call cpu_time(cts)\n !call system_clock(wts)\n do n = 1,ns\n call flips_add(gd,1,amat_d(n,:),mmat_d(n,:))\n end do\n call flips_solve(gd)\n call cpu_time(cte)\n !call system_clock(wte)\n !wtime1 = wte-wts\n ctime1 = cte-cts\n\n ! Calculate diagonal of the covariance\n call cpu_time(cts)\n !call system_clock(wts)\n call flips_calc_cov(gd,full=.TRUE.)\n call cpu_time(cte)\n !call system_clock(wte)\n !wtime2 = wte-wts\n ctime2 = cte-cts\n\n ! Errors\n maxerr_d = maxval(abs(smat_d(:,1) - gd%solmat))\n meanerr_d = sum(smat_d(:,1) - gd%solmat)/ns\n\n ! Print results\n write(*,*) '---------------------------------------'\n write(*,*) 'Double precision complex, size:',ns\n write(*,*) '---------------------------------------'\n write(*,*) ' Solution, CPU time:',ctime1\n !write(*,*) 'Solution, wall clock:',wtime1\n write(*,*) 'Covariance, CPU time:',ctime2\n !write(*,*) 'Covariance, wall clock:',wtime2\n write(*,*) ' Mean error:',meanerr_d\n write(*,*) ' Max. abs. error:',maxerr_d\n write(*,*) ' Residual:',gd%residual\n ! write(*,*) gd%cmat\n write(*,*) '---------------------------------------\\n'\n\n\nend program realcomp\n", "meta": {"hexsha": "b522642f4fd5199d00fd444073dec4b18c958df8", "size": 4055, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/cplx_comp.f90", "max_stars_repo_name": "morispaa/flips", "max_stars_repo_head_hexsha": "f6c98bd33bf01261f98db3a5bd581c2adbe4e2e7", "max_stars_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-12-03T09:16:08.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-03T09:16:08.000Z", "max_issues_repo_path": "tests/cplx_comp.f90", "max_issues_repo_name": "morispaa/flips", "max_issues_repo_head_hexsha": "f6c98bd33bf01261f98db3a5bd581c2adbe4e2e7", "max_issues_repo_licenses": ["BSD-2-Clause-FreeBSD"], "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/cplx_comp.f90", "max_forks_repo_name": "morispaa/flips", "max_forks_repo_head_hexsha": "f6c98bd33bf01261f98db3a5bd581c2adbe4e2e7", "max_forks_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.34375, "max_line_length": 68, "alphanum_fraction": 0.603945746, "num_tokens": 1380, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314768368161, "lm_q2_score": 0.7690802264851918, "lm_q1q2_score": 0.6811216567880735}} {"text": "PROGRAM select_kinds\nUSE iso_Fortran_env\nIMPLICIT NONE\nINTEGER, PARAMETER :: SGL = SELECTED_REAL_KIND(p=6, r=37)\nINTEGER, PARAMETER :: DBL = SELECTED_REAL_KIND(p=13,r=200)\nREAL(kind=SGL) :: var1 = 0.\nREAL(kind=DBL) :: var2 = 0._DBL\nREAL(kind=REAL32) :: var3 = 1.\nREAL(kind=REAL128) :: var4 = 1.\nWRITE(*, 100) 'var1', KIND(var1), PRECISION(var1), RANGE(var1)\nWRITE(*, 100) 'var2', KIND(var2), PRECISION(var2), RANGE(var2)\nWRITE(*, 100) 'var3', KIND(var3), PRECISION(var3), RANGE(var3)\nWRITE(*, 100) 'var4', KIND(var4), PRECISION(var4), RANGE(var4)\n100 FORMAT (A, ': kind = ', I2, ', precision = ', I2, ', range = ', I4)\nEND PROGRAM select_kinds\n", "meta": {"hexsha": "322d59621a8d2de04c717990e819c64c779adc9b", "size": 644, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap11/select_kinds.f90", "max_stars_repo_name": "evanmacbride/fortran-practice", "max_stars_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/chap11/select_kinds.f90", "max_issues_repo_name": "evanmacbride/fortran-practice", "max_issues_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/chap11/select_kinds.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": 40.25, "max_line_length": 71, "alphanum_fraction": 0.6739130435, "num_tokens": 232, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835452961427, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.6811133285691332}} {"text": "Program abdulmalik\n\tIMPLICIT NONE\n INTEGER::n\n REAL::w(20),k,SUM_P_V\n print*,\"enter n\"\n read*,n\n call READ_REAL_VECROR(w,20,n)\n K = SUM_P_V(w,n,20)\n print*,k\nEND Program abdulmalik\n\nSUBROUTINE READ_REAL_VECROR(w,s,n)\n\tIMPLICIT NONE\n INTEGER,INTENT(IN)::n,s\n REAL,INTENT(out)::w(s)\n INTEGER::i\n do i=1,n\n print*,\"enter w(i)\"\n read*,w(i)\n enddo\nEND SUBROUTINE READ_REAL_VECROR\n\nREAL FUNCTION SUM_P_V(w,n,s)\n\tIMPLICIT NONE\n INTEGER,INTENT(IN)::n,s\n REAL,INTENT(in)::w(s)\n INTEGER::i,a=0\n REAL::sum=0,y\n do i=1,n\n y=w(i)\n if(Mod(y,2.)==1)then\n sum=sum+w(i)\n a=a+1\n endif \n enddo\n SUM_P_V=sum/a\nend FUNCTION SUM_P_V\n", "meta": {"hexsha": "1b49f6ac6cf84067b408d795427369a12848db34", "size": 711, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "S2-ex2 Calculate Average of odd numbers Using Arrays.f95", "max_stars_repo_name": "abdulmlik/CS111-homework", "max_stars_repo_head_hexsha": "fbcf635eeab7713713d62bb84eef3fe6213c1a1e", "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": "S2-ex2 Calculate Average of odd numbers Using Arrays.f95", "max_issues_repo_name": "abdulmlik/CS111-homework", "max_issues_repo_head_hexsha": "fbcf635eeab7713713d62bb84eef3fe6213c1a1e", "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": "S2-ex2 Calculate Average of odd numbers Using Arrays.f95", "max_forks_repo_name": "abdulmlik/CS111-homework", "max_forks_repo_head_hexsha": "fbcf635eeab7713713d62bb84eef3fe6213c1a1e", "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": 18.7105263158, "max_line_length": 34, "alphanum_fraction": 0.5935302391, "num_tokens": 261, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835207180243, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.6811133104075282}} {"text": "module matrix_module\n implicit none\n\n type matrix\n integer :: shape(2)\n real, allocatable :: data(:,:)\n contains\n procedure :: construct\n procedure :: destruct\n procedure :: print\n procedure :: det\n end type matrix\n\ncontains\n\n subroutine construct(this, m, n)\n class(matrix) :: this\n integer :: m,n\n this%shape = [m,n]\n allocate(this%data(m,n))\n end subroutine construct\n\n subroutine destruct(this)\n class(matrix) :: this\n deallocate(this%data)\n end subroutine destruct\n\n ! print: formatted print of matrix\n subroutine print(this)\n class(matrix) :: this\n ! row_fmt: format character string for row printing\n ! fmt: temporary format string\n character(32) :: row_fmt, fmt = '(a,i0,a,i0,a,i0,a)'\n ! w: width of each entry printed\n ! d: number of decimal digits printed\n integer :: w, d = 2, row\n ! find largest width of element in matrix\n w = ceiling(log10(maxval(abs(this%data)))) + d + 2\n ! write row formatting to 'row_fmt' variable\n write(row_fmt,fmt) '(',this%shape(2),'(f',w,'.',d,',1x))'\n ! print matrix row by row\n do row = 1,this%shape(1)\n print row_fmt, this%data(row,:)\n end do\n end subroutine print\n\n ! det: compute determinant of matrix\n ! using recursive definition based on cofactors\n recursive function det(this) result(d)\n class(matrix) :: this\n type(matrix) :: submatrix\n real :: d, sgn, element, minor\n integer :: m, n, row, col, i, j\n\n m = this%shape(1)\n n = this%shape(2)\n d = 0.0\n\n ! compute cofactor\n ! if 1x1 matrix, return value\n if (m==1.and.n==1) then\n d = this%data(1,1)\n ! if square and not 1x1\n else if (m==n) then\n ! cofactor sum down the first column\n do row = 1,m\n ! sign of term\n sgn = (-1.0)**(row+1)\n ! matrix element\n element = this%data(row,1)\n ! construct the cofactor submatrix and compute its determinant\n call submatrix%construct(m-1,n-1)\n if (row==1) then\n submatrix%data = this%data(2:,2:)\n else if (row==m) then\n submatrix%data = this%data(:m-1,2:)\n else\n submatrix%data(:row-1,:) = this%data(:row-1,2:)\n submatrix%data(row:,:) = this%data(row+1:,2:)\n end if\n minor = submatrix%det()\n call submatrix%destruct()\n\n ! determinant accumulator\n d = d + sgn*element*minor\n end do\n end if\n end function det\n\n ! random_matrix: generate matrix with random entries in [-1,1]\n ! m,n: number of rows,cols\n function random_matrix(m,n) result(mat)\n integer :: m,n,i,j\n type(matrix) :: mat\n ! allocate memory for matrix\n call mat%construct(m,n)\n ! seed random number generator\n call srand(time())\n ! populate matrix\n do i = 1,m\n do j = 1,n\n mat%data(i,j) = 2.0*rand() - 1.0\n end do\n end do\n end function random_matrix\n\nend module matrix_module\n", "meta": {"hexsha": "1ae14a21e4566433c730d1a75edca881e3111715", "size": 2966, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "teaching/acm-computing-seminar/resources/langs/fortran/matrix/matrix_module.f90", "max_stars_repo_name": "notmatthancock/notmatthancock.github.io", "max_stars_repo_head_hexsha": "abcd91cc7c2653c5243fe96ba2fd681ec03930bb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "teaching/acm-computing-seminar/resources/langs/fortran/matrix/matrix_module.f90", "max_issues_repo_name": "notmatthancock/notmatthancock.github.io", "max_issues_repo_head_hexsha": "abcd91cc7c2653c5243fe96ba2fd681ec03930bb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "teaching/acm-computing-seminar/resources/langs/fortran/matrix/matrix_module.f90", "max_forks_repo_name": "notmatthancock/notmatthancock.github.io", "max_forks_repo_head_hexsha": "abcd91cc7c2653c5243fe96ba2fd681ec03930bb", "max_forks_repo_licenses": ["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.462962963, "max_line_length": 72, "alphanum_fraction": 0.5947403911, "num_tokens": 849, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278788223264, "lm_q2_score": 0.7718434978390746, "lm_q1q2_score": 0.6810962205809394}} {"text": "!+\r\nMODULE SplineProcedures\r\n! ------------------------------------------------------------------------------\r\n! PURPOSE - Collect several procedures associated with spline functions that\r\n! are used in the NACA airfoil calculations.\r\n! AUTHOR - Ralph L. Carmichael, Public Domain Aeronautical Software\r\n\r\n! REVISION HISTORY\r\n! DATE PERSON STATEMENT OF CHANGES\r\n! 09Oct01 RLC 0.5 Original coding\r\n! 24Nov01 RLC 0.6 Made a,fa... PRIVATE\r\n! 05Dec01 RLC 0.7 Added material from Cubics and IntUtil\r\n! 26Dec01 RLC 0.8 Made function values optional in PClookup and elsewhere\r\n! 4Jan02 RLC 1.0 Final cleanup for release of PDAS 7\r\n! 16Jan09 RLC 1.1 Additional cosmetic improvements\r\n\r\n\r\n IMPLICIT NONE\r\n!-------------------------------------------------------------------------------\r\n CHARACTER(LEN=*),PARAMETER,PUBLIC:: &\r\n SPLINE_PROCEDURES_VERSION=\"1.1 (16 January 2009)\"\r\n\r\n PRIVATE:: EvaluateCubic\r\n PUBLIC:: EvaluateCubicAndDerivs\r\n PUBLIC:: FMMspline\r\n PRIVATE:: InterpolatePolynomial\r\n PRIVATE:: LookUp\r\n PUBLIC:: PClookup\r\n PUBLIC:: SplineZero\r\n PUBLIC:: TableLookup\r\n PRIVATE:: Zeroin\r\n\r\n!... Module-wide variables set in SplineZero and used by EvaluateCubic\r\n REAL,PRIVATE:: a,fa,fpa ! a, f(a), f'(a) at first point\r\n REAL,PRIVATE:: b,fb,fpb ! b, f(b), f'(b) at second point\r\n\r\n\r\nCONTAINS\r\n\r\n!+\r\nPURE FUNCTION EvaluateCubic(u) RESULT(fu)\r\n! ------------------------------------------------------------------------------\r\n! PURPOSE - Evaluate a cubic polynomial defined by the function and the\r\n! 1st derivative at two points\r\n REAL,INTENT(IN):: u ! point where function is to be evaluated\r\n REAL:: fu ! computed value of f(u)\r\n\r\n! REAL:: a,fa,fpa ! a, f(a), f'(a) at first point\r\n! REAL:: b,fb,fpb ! b, f(b), f'(b) at second point\r\n \r\n\r\n REAL:: d,t,p\r\n!-------------------------------------------------------------------------------\r\n d=(fb-fa)/(b-a)\r\n t=(u-a)/(b-a)\r\n p=1.0-t\r\n\r\n fu = p*fa + t*fb - p*t*(b-a)*(p*(d-fpa)-t*(d-fpb))\r\n RETURN\r\nEND Function EvaluateCubic ! -------------------------------------------------\r\n\r\n!+\r\nPURE SUBROUTINE EvaluateCubicAndDerivs(a,fa,fpa, b,fb,fpb, u, f,fp,fpp,fppp)\r\n! ------------------------------------------------------------------------------\r\n! PURPOSE - Evaluate a cubic polynomial and its 1st, 2nd, and 3rd\r\n! derivatives at a specified point. The cubic is defined by the function\r\n! and the 1st derivative at two points. The cubic is mapped onto [0,1]\r\n! for some savings in computation. If no derivatives are wanted, it is\r\n! probably preferable to use functions EvaluateCubic above.\r\n\r\n REAL,INTENT(IN):: a,fa,fpa ! a, f(a), f'(a) at first point\r\n REAL,INTENT(IN):: b,fb,fpb ! b, f(b), f'(b) at second point\r\n REAL,INTENT(IN):: u ! point where function is to be evaluated\r\n\r\n REAL,INTENT(OUT),OPTIONAL:: f,fp,fpp,fppp ! f(u),f'(u),f''(u),f'''(u)\r\n \r\n REAL,PARAMETER:: ONE=1.0, TWO=2.0, THREE=3.0, SIX=6.0\r\n! the \"magic\" matrix. This is how you declare a constant 4x4 matrix\r\n REAL,PARAMETER,DIMENSION(4,4):: MAGIC = RESHAPE( &\r\n & (/2.0, -3.0, 0.0, 1.0, -2.0, 3.0, 0.0, 0.0, &\r\n & 1.0, -2.0, 1.0, 0.0, 1.0, -1.0, 0.0, 0.0/), (/4,4/) )\r\n REAL,DIMENSION(4)::coef,rhs\r\n REAL:: h,t\r\n! ------------------------------------------------------------------------------\r\n rhs(1)=fa\r\n rhs(2)=fb\r\n rhs(3)=fpa*(b-a)\r\n rhs(4)=fpb*(b-a)\r\n coef=MATMUL(MAGIC,rhs)\r\n\r\n! CAUTION - these are not the coefficients of the cubic in the original \r\n! coordinates. This is the cubic on [0,1] from the mapping t=(x-a)/(b-a). \r\n! That is why the h terms appear in the derivatives. \r\n\r\n h=ONE/(b-a)\r\n t=(u-a)*h\r\n IF (Present(f)) THEN\r\n f= coef(4) + t*(coef(3) + t*(coef(2) + t*coef(1)))\r\n END IF\r\n IF (Present(fp)) THEN\r\n fp= h*(coef(3) + t*(TWO*coef(2) + t*THREE*coef(1)))\r\n END IF\r\n IF (Present(fpp)) THEN\r\n fpp= h*h*(TWO*coef(2) + t*SIX*coef(1))\r\n END IF\r\n IF (Present(fppp)) THEN\r\n fppp=h*h*h*SIX*coef(1)\r\n END IF\r\n RETURN\r\nEND Subroutine EvaluateCubicAndDerivs ! -------------------------------------\r\n\r\n!+\r\nPURE SUBROUTINE FMMspline(x,y, yp)\r\n! ------------------------------------------------------------------------------\r\n! PURPOSE - Compute the cubic spline with endpoint conditions chosen\r\n! by FMM (from the book by Forsythe,Malcolm & Moler)\r\n REAL,INTENT(IN),DIMENSION(:):: x,y\r\n REAL,INTENT(OUT),DIMENSION(:):: yp\r\n\r\n INTEGER:: i,n\r\n REAL,ALLOCATABLE,DIMENSION(:):: dx,dy,delta,dd,alpha,beta,sigma\r\n REAL:: deriv1,deriv2\r\n!-------------------------------------------------------------------------------\r\n n=SIZE(x) ! y and yp must be at least this size\r\n IF (n<2) THEN\r\n yp(1)=0.0\r\n RETURN\r\n END IF\r\n ALLOCATE(dx(n-1), dy(n-1), delta(n-1))\r\n dx(:)=x(2:n)-x(1:n-1)\r\n dy(:)=y(2:n)-y(1:n-1)\r\n delta(:)=dy(:)/dx(:)\r\n IF (n==2) THEN\r\n yp(1)=delta(1)\r\n yp(2)=delta(1)\r\n DEALLOCATE(dx,dy,delta)\r\n RETURN\r\n END IF\r\n ALLOCATE(dd(n-2))\r\n dd(:)=delta(2:n-1)-delta(1:n-2)\r\n IF (n==3) THEN\r\n deriv2=dd(1)/(x(3)-x(1))\r\n deriv1=delta(1)-deriv2*dx(1)\r\n yp(1)=deriv1\r\n yp(2)=deriv1+deriv2*dx(1)\r\n yp(3)=deriv1+deriv2*(x(3)-x(1))\r\n DEALLOCATE(dx,dy,delta,dd)\r\n RETURN\r\n END IF\r\n! This gets rid of the trivial cases n=1,2,3. Assume from here on n>3\r\n\r\n ALLOCATE(alpha(n),beta(n),sigma(n))\r\n alpha(1)=-dx(1)\r\n alpha(2:n-1)=2.0*(dx(1:n-2)+dx(2:n-1))\r\n DO i=2,n-1 ! serial loop\r\n alpha(i)=alpha(i)-dx(i-1)*dx(i-1)/alpha(i-1) ! fwd elimination\r\n END DO\r\n alpha(n)=-dx(n-1)-dx(n-1)*dx(n-1)/alpha(n-1)\r\n\r\n beta(1)=dd(2)/(x(4)-x(2)) - dd(1)/(x(3)-x(1))\r\n beta(1)=beta(1)*dx(1)*dx(1)/(x(4)-x(1))\r\n\r\n beta(2:n-1)=dd(1:n-2)\r\n\r\n beta(n)=dd(n-2)/(x(n)-x(n-2)) - dd(n-3)/(x(n-1)-x(n-3))\r\n beta(n)=-beta(n)*dx(n-1)*dx(n-1)/(x(n)-x(n-3)) \r\n\r\n DO i=2,n ! serial loop\r\n beta(i)=beta(i)-dx(i-1)*beta(i-1)/alpha(i-1) ! fwd elimination\r\n END DO\r\n\r\n sigma(n)=beta(n)/alpha(n)\r\n DO i=n-1,1,-1 ! reverse order serial loop\r\n sigma(i)=(beta(i)-dx(i)*sigma(i+1))/alpha(i) ! back substitution\r\n END DO\r\n\r\n yp(1:n-1)=delta-dx*(sigma(1:n-1)+sigma(1:n-1)+sigma(2:n))\r\n yp(n)=yp(n-1)+dx(n-1)*3.0*(sigma(n)+sigma(n-1))\r\n\r\n DEALLOCATE(dx,dy,delta, alpha,beta,sigma, dd)\r\n\r\n RETURN\r\nEND SUBROUTINE FMMspline ! ---------------------------------------------------\r\n\r\n!+\r\nPURE FUNCTION InterpolatePolynomial(x,y,u) RESULT(sum)\r\n! ------------------------------------------------------------------------------\r\n! PURPOSE -Compute the value of the interpolating polynomial thru\r\n! x- and y-arrays at the x-value of u, using Lagrange's equation.\r\n\r\n REAL,INTENT(IN),DIMENSION(:):: x,y ! tables of coordinates\r\n REAL,INTENT(IN):: u ! value of x-coordinate for interpolation\r\n REAL:: sum\r\n INTEGER:: i,j\r\n REAL:: fact\r\n REAL,DIMENSION(SIZE(x)):: du\r\n!-------------------------------------------------------------------------------\r\n du(:)=u-x(:)\r\n sum=0.0\r\n DO j=1,SIZE(x)\r\n fact=1.0\r\n DO i=1,SIZE(x)\r\n IF (i /= j) fact=fact*du(i)/(x(j)-x(i))\r\n END DO\r\n sum=sum+y(j)*fact\r\n END DO\r\n RETURN\r\nEND Function InterpolatePolynomial ! -----------------------------------------\r\n\r\n!+\r\nPURE FUNCTION Lookup(xtab,x) RESULT (i)\r\n! ------------------------------------------------------------------------------\r\n! PURPOSE - Search a sorted (increasing) array to find the interval\r\n! bounding a given number. If n is the size of the array a,\r\n! return 0 if number x is < a(1)\r\n! return n if x > a(n).\r\n! return i if a(i) <= x < a(i+1).\r\n! If x is exactly equal to a(n), return n-1.\r\n\r\n REAL,INTENT(IN),DIMENSION(:):: xtab ! input array \r\n REAL,INTENT(IN):: x ! input number \r\n\r\n INTEGER:: i ! index of interval such that xtab(i) <= x < xtab(i+1)\r\n ! =0 if x < xtab(1) and =n if x > xtab(i)\r\n INTEGER:: j,k,n\r\n!-------------------------------------------------------------------------------\r\n n=SIZE(xtab)\r\n IF (n <= 0) THEN\r\n i=-1\r\n RETURN\r\n END IF\r\n\r\n IF (x < xtab(1)) THEN\r\n i=0\r\n RETURN\r\n END IF\r\n\r\n IF (x > xtab(n)) THEN\r\n i=n\r\n RETURN\r\n END IF\r\n\r\n i=1 \r\n j=SIZE(xtab)\r\n DO\r\n IF (j <= i+1) EXIT\r\n k=(i+j)/2 ! integer division\r\n IF (x < xtab(k)) THEN\r\n j=k\r\n ELSE\r\n i=k\r\n END IF \r\n END DO\r\n\r\n RETURN\r\nEND Function Lookup ! --------------------------------------------------------\r\n\r\n!+\r\nSUBROUTINE PClookup(x,y,yp, u, f,fp,fpp,fppp)\r\n! ------------------------------------------------------------------------------\r\n! PURPOSE - Interpolate in a cubic spline at one point \r\n REAL,INTENT(IN),DIMENSION(:):: x,y,yp ! defines the cubic spline\r\n REAL,INTENT(IN):: u ! point where spline is to be evaluated\r\n REAL,INTENT(OUT),OPTIONAL:: f,fp,fpp,fppp ! f(u),f'(u), f''(u), f'''(u)\r\n\r\n REAL:: ud, a,fa,fpa, b,fb,fpb\r\n REAL:: z,zp,zpp,zppp\r\n INTEGER:: k\r\n!-------------------------------------------------------------------------------\r\n k=LookUp(x,u)\r\n k=MAX(1, MIN(SIZE(x)-1,k) )\r\n a=x(k)\r\n fa=y(k)\r\n fpa=yp(k)\r\n b=x(k+1)\r\n fb=y(k+1)\r\n fpb=yp(k+1)\r\n ud=u\r\n CALL EvaluateCubicAndDerivs(a,fa,fpa, b,fb,fpb, ud, z,zp,zpp,zppp)\r\n IF(Present(f)) f=z\r\n IF(Present(fp)) fp=zp\r\n IF(Present(fpp)) fpp=zpp\r\n IF(Present(fppp)) fppp=zppp\r\n\r\n RETURN\r\nEND Subroutine PClookup ! ----------------------------------------------------\r\n\r\n!+\r\nSUBROUTINE SplineZero(x,f,fp, fbar,tol, xbar,errCode) \r\n! ------------------------------------------------------------------------------\r\n! PURPOSE - Find a value of x corresponding to a value of fbar of the cubic\r\n! spline defined by arrays x,f,fp. f is the value of the spline at x and fp\r\n! is the first derivative.\r\n! NOTES - The spline is searched for an interval that crosses the specified\r\n! value. Then Brent's method is used for finding the zero.\r\n\r\n IMPLICIT NONE\r\n REAL,INTENT(IN),DIMENSION(:):: x,f,fp\r\n REAL,INTENT(IN):: fbar\r\n REAL,INTENT(IN):: tol\r\n REAL,INTENT(OUT):: xbar\r\n INTEGER,INTENT(OUT):: errCode\r\n\r\n INTEGER:: k,n\r\n REAL,ALLOCATABLE,DIMENSION(:):: fLocal\r\n REAL,PARAMETER:: ZERO=0.0\r\n!-------------------------------------------------------------------------------\r\n n=SIZE(x)\r\n\r\n DO k=1,n ! look for an exact match. Could happen...\r\n IF (ABS(f(k)-fbar) < tol) THEN\r\n xbar=x(k)\r\n errCode=0\r\n RETURN\r\n END IF\r\n END DO\r\n\r\n ALLOCATE(fLocal(n))\r\n fLocal(1:n)=f(1:n)-fbar ! look for a zero of fLocal\r\n\r\n DO k=2,n\r\n IF ( fLocal(k-1)*fLocal(k) < ZERO) EXIT\r\n END DO\r\n IF (k==n+1) THEN ! no crossing could be found\r\n errCode=1\r\n DEALLOCATE(fLocal)\r\n RETURN\r\n END IF\r\n\r\n errCode=0\r\n a=x(k-1) ! set the global variables for EvaluateCubic\r\n fa=fLocal(k-1)\r\n fpa=fp(k-1)\r\n b=x(k)\r\n fb=fLocal(k)\r\n fpb=fp(k)\r\n DEALLOCATE(fLocal)\r\n\r\n xbar=Zeroin(a,b,EvaluateCubic,tol)\r\n\r\n RETURN\r\nEND Subroutine SplineZero ! --------------------------------------------------\r\n\r\n!+\r\nPURE FUNCTION TableLookup(x,y,order,u) RESULT(fu)\r\n! ------------------------------------------------------------------------------\r\n! PURPOSE - Use polynomial evaluation for table lookup. Find points ahead\r\n! and behind evaluation point to match order of interpolation desired.\r\n\r\n REAL,INTENT(IN),DIMENSION(:):: x,y ! data tables\r\n INTEGER,INTENT(IN):: order ! order of interpolation\r\n ! (1=linear, 2=quadratic...)\r\n REAL,INTENT(IN):: u ! x-coor where function is to be evaluated\r\n REAL:: fu ! interpolated function value\r\n INTEGER:: j,m\r\n!-------------------------------------------------------------------------------\r\n m=MIN(order+1, SIZE(x)) ! number of points used for interpolating poly\r\n j=Lookup(x,u)\r\n j=j-(m/2-1)\r\n j=MIN(1+SIZE(x)-m, j) ! j+m-1 must not exceed SIZE(x)\r\n j=MAX(1,j) ! j must be positive\r\n ! use points j thru j+m-1 for interpolation (m points)\r\n fu=InterpolatePolynomial(x(j:j+m-1),y(j:j+m-1),u)\r\n RETURN\r\nEND Function TableLookup ! ---------------------------------------------------\r\n\r\n!+\r\n FUNCTION Zeroin (ax,bx,f,tol) RESULT(z)\r\n! ------------------------------------------------------------------------------\r\n! PURPOSE - Compute a zero of f in the interval (ax,bx)\r\n! AUTHORS - Van Winjngaarden,Decker,Brendt, et al\r\n! Forsythe, Malcolm, & Moler, \r\n! Press, et.al, Numerical Recipes\r\n! Ralph L. Carmichael, Public Domain Aeronautical Software\r\n\r\n! REVISIONS - DATE PERSON STATEMENT OF CHANGES\r\n\r\n\r\n IMPLICIT NONE\r\n REAL,INTENT(IN):: ax,bx ! left and right endpoints of interval\r\n REAL,INTENT(IN):: tol ! desired interval of uncertainity \r\n \r\n REAL:: z\r\n\r\n INTERFACE\r\n FUNCTION F(x) RESULT(g)\r\n IMPLICIT NONE\r\n REAL,INTENT(IN):: x\r\n REAL:: g\r\n END Function F\r\n END INTERFACE \r\n\r\n INTEGER,PARAMETER:: MAX_ITER=500\r\n INTEGER:: k\r\n REAL,PARAMETER:: ZERO=0.0, ONE=1.0, TWO=2.0, THREE=3.0, HALF=0.5\r\n REAL:: a,b,c,d,e,eps,fa,fb,fc,tol1,xm,p,q,r,s\r\n!-------------------------------------------------------------------------------\r\n eps=EPSILON(ax)\r\n! tol1=ONE+eps\r\n\r\n a=ax ! initialization\r\n b=bx\r\n fa=f(a)\r\n fb=f(b) ! should test that fa and fb have opposite signs\r\n c=b\r\n fc=fb\r\n\r\n DO k=1,MAX_ITER ! begin iteration\r\n\r\n IF ((fb > ZERO .AND. fc > ZERO) .OR. (fb < ZERO .AND. fc < ZERO)) THEN\r\n c=a\r\n fc=fa\r\n d=b-a\r\n e=d\r\n END IF\r\n\r\n IF (ABS(fc) < ABS(fb)) THEN\r\n a=b\r\n b=c\r\n c=a\r\n fa=fb\r\n fb=fc\r\n fc=fa\r\n END IF\r\n \r\n tol1=TWO*eps*ABS(b) + HALF*tol ! convergence test\r\n xm=0.5*(c-b)\r\n IF (ABS(xm)<=tol1 .OR. fb==0.0) THEN\r\n z=b\r\n RETURN ! the only way out!\r\n END IF \r\n\r\n!.....is bisection necessary?...........................................\r\n IF (ABS(e)<=tol1 .AND. ABS(fa)>ABS(fb)) THEN\r\n s=fb/fa ! is quadratic interpolation possible ?\r\n IF (a==c) THEN\r\n s=fb/fa ! use linear interpolation\r\n p=TWO*xm*s\r\n q=ONE-s\r\n ELSE\r\n q=fa/fc ! use inverse quadratic interpolation\r\n r=fb/fc\r\n s=fb/fa\r\n p=s*(TWO*xm*q*(q-r)-(b-a)*(r-ONE))\r\n q=(q-ONE)*(r-ONE)*(s-ONE)\r\n END IF\r\n\r\n IF (p > ZERO) q=-q ! adjust signs\r\n p=ABS(p)\r\n\r\n IF (p+p < MIN(THREE*xm*q-ABS(tol1*q),ABS(e*q))) THEN\r\n e=d ! use interpolation\r\n d=p/q\r\n ELSE\r\n d=xm ! use bisection\r\n e=d\r\n END IF\r\n ELSE\r\n d=xm ! use bisection\r\n e=d\r\n END IF\r\n\r\n\r\n a=b\r\n fa=fb\r\n IF (ABS(d)> tol1) THEN\r\n b=b+d\r\n ELSE\r\n b=b+SIGN(TOL1,XM)\r\n END IF\r\n fb=f(b)\r\n\r\n END DO\r\n\r\n z=b ! but this is a bad return. Max iterations exceeded.\r\n RETURN\r\n END Function Zeroin ! --------------------------------------------------\r\n\r\nEND Module SplineProcedures ! ================================================\r\n", "meta": {"hexsha": "facd94a8155894186ab9622a63bcbc0653f58456", "size": 15519, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "naca456/splprocs.f90", "max_stars_repo_name": "oscarmarino/airfoilGenerator", "max_stars_repo_head_hexsha": "a71168481058cc4c3877f7080cd30c6268b5ae78", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "naca456/splprocs.f90", "max_issues_repo_name": "oscarmarino/airfoilGenerator", "max_issues_repo_head_hexsha": "a71168481058cc4c3877f7080cd30c6268b5ae78", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "naca456/splprocs.f90", "max_forks_repo_name": "oscarmarino/airfoilGenerator", "max_forks_repo_head_hexsha": "a71168481058cc4c3877f7080cd30c6268b5ae78", "max_forks_repo_licenses": ["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.33125, "max_line_length": 81, "alphanum_fraction": 0.4770925962, "num_tokens": 4612, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278695464501, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6810962134214148}} {"text": "module mod_statistics\n use mod_types\n use random\n implicit none\n\n contains \n\n ! Random number generation\n function rnorm(mu, sigma)\n real(kind=r2), intent(in) :: mu, sigma\n real(kind=r2) :: z\n real(kind=r2) :: rnorm\n\n rnorm = mu + random_normal() * sigma\n return\n end function\n\n function rgamma(shp, scl)\n ! NOTE: random_gamma takes real(4) as argument for shape.\n ! Therefore, coerce real(8) (r2) argument `shp` to real(4) (r1)\n ! by copying.\n real(kind=r2), intent(in) :: shp, scl\n real(kind=r1) :: shp2 \n real(kind=r2) :: rgamma\n\n shp2 = shp\n rgamma = random_gamma(shp2, .true.) * scl\n return\n end function\n\n ! Density calculation\n function ldnorm(x, mu, sigma)\n real(kind=r2), intent(in) :: x, mu, sigma\n real(kind=r2) :: hlog2pi, lsig, xm, s2, ex\n real(kind=r2) :: ldnorm\n\n hlog2pi = -0.39908993417 !! -0.5 * log(2pi)\n lsig = -log(sigma)\n xm = x - mu\n s2 = 2 * sigma * sigma\n ex = -xm * xm / s2\n ldnorm = hlog2pi + lsig + ex\n return\n end function\n\nend module \n", "meta": {"hexsha": "dbc7683c030cd77096ce9128cf64fdad9c3cf7ce", "size": 1176, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "modules/rtm/src/RTM/modules/mod_statistics.f90", "max_stars_repo_name": "Kah5/pecan", "max_stars_repo_head_hexsha": "72bec0eebbda513d492e6fa4b3f50757aa9448d0", "max_stars_repo_licenses": ["NCSA", "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": "modules/rtm/src/RTM/modules/mod_statistics.f90", "max_issues_repo_name": "Kah5/pecan", "max_issues_repo_head_hexsha": "72bec0eebbda513d492e6fa4b3f50757aa9448d0", "max_issues_repo_licenses": ["NCSA", "Unlicense"], "max_issues_count": 141, "max_issues_repo_issues_event_min_datetime": "2015-05-22T20:00:39.000Z", "max_issues_repo_issues_event_max_datetime": "2018-02-26T15:49:19.000Z", "max_forks_repo_path": "modules/rtm/src/RTM/modules/mod_statistics.f90", "max_forks_repo_name": "Kah5/pecan", "max_forks_repo_head_hexsha": "72bec0eebbda513d492e6fa4b3f50757aa9448d0", "max_forks_repo_licenses": ["NCSA", "Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-13T22:55:09.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-13T22:55:09.000Z", "avg_line_length": 25.0212765957, "max_line_length": 71, "alphanum_fraction": 0.5416666667, "num_tokens": 361, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544912, "lm_q2_score": 0.7718434978390746, "lm_q1q2_score": 0.6810962110349063}} {"text": "! Generate .gr3 (e.g. shapiro.gr3) using bottom slope as a criterion.\n! Works for mixed tri/quads \n! Inputs: hgrid.gr3 (not in lon/lat!); consts below\n! Output: slope_filter.gr3\n\n! ifort -O2 -CB -o gen_slope_filter gen_slope_filter.f90\n\n implicit real*8(a-h,o-z)\n !parameter(mnp=1000000)\n !parameter(mne=2000000)\n parameter(mnei=50)\n\n integer,allocatable :: i34(:),elnode(:,:),nwild(:)\n real*8,allocatable :: x(:),y(:),dp(:),area(:),dldxy(:,:)\n real*8,allocatable :: slope(:),hdif(:),hdif_e(:),rlh(:)\n integer,allocatable :: nne(:),indel(:,:)\n\n !Formula: depth=hdif_max*tanh(2*gam/threshold_slope), where gam is\n !slope\n hdif_max=0.5 !max \n\n print*, 'Input ref slope:'\n read*, threshold_slope \n\n open(14,file='hgrid.gr3',status='old')\n open(13,file='slope_filter.gr3',status='replace')\n read(14,*)\n read(14,*) ne,np\n !if(ne>mne.or.np>mnp) then\n ! write(*,*)'Increase mne/mnp',mne,mnp,ne,np\n ! stop\n !endif\n allocate(i34(ne),elnode(4,ne),nwild(3), &\n & x(np),y(np),dp(np),area(ne),dldxy(2,3), &\n & slope(ne),hdif(np),hdif_e(ne),rlh(4), &\n & nne(np),indel(mnei,np),stat=istat)\n\n do i=1,np\n read(14,*) j,x(i),y(i),dp(i)\n enddo !i=1,np\n\n slope=0 !init\n do i=1,ne\n read(14,*) j,i34(i),elnode(1:i34(i),i)\n\n do m=1,i34(i)-2 !split into tri\n if(m==1) then\n nwild(1:3)=(/1,2,3/)\n else !quad\n nwild(1:3)=(/1,3,4/)\n endif !m\n\n n1=elnode(nwild(1),i)\n n2=elnode(nwild(2),i)\n n3=elnode(nwild(3),i)\n area(i)=signa(x(n1),x(n2),x(n3),y(n1),y(n2),y(n3))\n if(area(i)<=0) then\n write(*,*)'Negative area at',i\n stop\n endif\n \n! if(i34(i)==4) then\n! n4=elnode(4,i)\n! area(i)=area(i)+signa(x(n1),x(n3),x(n4),y(n1),y(n3),y(n4))\n! endif\n\n do j=1,3\n nj1=j+1\n nj2=j+2\n if(nj1>3) nj1=nj1-3\n if(nj2>3) nj2=nj2-3\n nd1=elnode(nwild(nj1),i)\n nd2=elnode(nwild(nj2),i)\n dldxy(1,j)=(y(nd1)-y(nd2))/2/area(i)\n dldxy(2,j)=(x(nd2)-x(nd1))/2/area(i)\n enddo !j\n slx=dot_product(dp(elnode(nwild(1:3),i)),dldxy(1,:))\n sly=dot_product(dp(elnode(nwild(1:3),i)),dldxy(2,:))\n slope(i)=max(slope(i),sqrt(slx**2+sly**2))\n enddo !m\n\n write(99,*)i,slope(i)\n enddo !i=1,ne \n\n! Neighborhood\n nne=0\n do i=1,ne\n do j=1,i34(i)\n nd=elnode(j,i)\n nne(nd)=nne(nd)+1\n if(nne(nd)>mnei) then\n write(*,*)'Too many neighbors',nd\n stop\n endif\n indel(nne(nd),nd)=i\n enddo\n enddo\n\n hdif=0\n do i=1,np\n slopemax=0\n do j=1,nne(i)\n ie=indel(j,i)\n slopemax=max(slopemax,slope(ie))\n enddo !j\n hdif(i)=hdif_max*tanh(2*slopemax/threshold_slope)\n enddo !i\n\n write(13,*)'threshold_slope=',threshold_slope\n write(13,*)ne,np\n do i=1,np\n write(13,*)i,real(x(i)),real(y(i)),real(hdif(i))\n enddo !i\n do i=1,ne\n write(13,*) i,i34(i),elnode(1:i34(i),i)\n enddo !i\n\n print*, 'Max bottom slope=',maxval(slope(1:ne))\n print*, 'Min/max = ',minval(hdif(1:np)),maxval(hdif(1:np))\n\n stop\n end\n\n function signa(x1,x2,x3,y1,y2,y3)\n!... Compute signed area formed by pts 1,2,3\n implicit real*8(a-h,o-z)\n\n signa=((x1-x3)*(y2-y3)-(x2-x3)*(y1-y3))/2\n\n return\n end\n\n", "meta": {"hexsha": "bc921be889e4631762d2db157c25d909e19b1034", "size": 3649, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/Utility/Pre-Processing/NWM/Shapiro/gen_slope_filter.f90", "max_stars_repo_name": "josephzhang8/test1", "max_stars_repo_head_hexsha": "290ccacffd5d162e1168162c9cf0ab25e3c04c9c", "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/Utility/Pre-Processing/NWM/Shapiro/gen_slope_filter.f90", "max_issues_repo_name": "josephzhang8/test1", "max_issues_repo_head_hexsha": "290ccacffd5d162e1168162c9cf0ab25e3c04c9c", "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/Utility/Pre-Processing/NWM/Shapiro/gen_slope_filter.f90", "max_forks_repo_name": "josephzhang8/test1", "max_forks_repo_head_hexsha": "290ccacffd5d162e1168162c9cf0ab25e3c04c9c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.4360902256, "max_line_length": 74, "alphanum_fraction": 0.4963003563, "num_tokens": 1328, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705731, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6810962108930667}} {"text": "!file: coord_desc.f90\nsubroutine coord_desc(converged, prec, corr, latent, weight, & !outputs\n observation, dims_pop, & !inputs :: data\n lambda_ridge, lambda_glasso, & !inputs :: parameters\n ths, max_iter, & !inputs, optional :: opt. parameters\n prec_init, weight_init,& !inputs, optional :: initial parameters\n verbose, verb_period, & !inputs, optional :: etc.\n num_pop, dim_obs, num_trial) !inputs :: dimensions\n \n implicit none\n \n !inputs :: dimensions\n integer, intent(in) :: num_pop, dim_obs, num_trial\n \n !inputs :: data\n real(8), dimension(dim_obs, num_trial), intent(in) :: observation\n integer, dimension(num_pop), intent(in) :: dims_pop\n \n !inputs :: parameters\n real(8), dimension(num_pop, num_pop), intent(in) :: lambda_glasso\n real(8), dimension(num_pop), intent(in) :: lambda_ridge\n \n !inputs, optional :: opt.parameters\n integer, intent(in) :: max_iter\n real(8), intent(in) :: ths\n \n!f2py integer optional, intent(in) :: max_iter = 10000\n!f2py real(8) optional, intent(in) :: ths = 0.0001 \n\n !inputs, optional :: initial parameters\n real(8), dimension(num_pop, num_pop), intent(in) :: prec_init\n real(8), dimension(dim_obs), intent(in) :: weight_init\n\n!f2py real(8) optional, dimension(num_pop, num_pop), intent(in) :: prec_init = 0\n!f2py real(8) optional, dimension(dim_obs), intent(in) :: weight_init = 1\n\n !inputs, optional :: etc.\n logical, intent(in) :: verbose\n integer, intent(in) :: verb_period\n\n!f2py integer optional, intent(in) :: verbose = 0\n!f2py integer optional, intent(in) :: verb_period = 10\n \n !outputs\n logical, intent(out) :: converged\n real(8), dimension(num_pop, num_pop), intent(out) :: prec, corr\n real(8), dimension(num_pop, num_trial), intent(out) :: latent\n real(8), dimension(dim_obs), intent(out) :: weight\n\n !local variables\n integer :: i, info\n real(8) :: cost, cost_old, diff\n real(8), dimension(num_pop) :: w\n real(8), dimension(num_pop, num_pop) :: prec_copy\n real(8), dimension(max(1, 3*num_pop-1)) :: work_eigen\n\n external DSYEV\n \n if (sum(dims_pop) /= dim_obs) then\n stop 'Dimensions of population does not match with observation'\n end if\n \n call coord_desc_init(prec, corr, latent, weight, & !outputs\n observation, dims_pop, & !inputs :: data\n lambda_ridge, prec_init, weight_init, & !inputs :: parameters\n num_pop, dim_obs, num_trial)\n \n !initial setting\n cost_old = huge(1.)\n converged = .false.\n \n !iteration \n do i = 1, max_iter\n call coord_desc_iter(prec, corr, latent, weight, &\n observation, dims_pop, lambda_ridge, lambda_glasso, &\n num_pop, dim_obs, num_trial)\n \n ! calculate cost\n prec_copy = prec\n\n call DSYEV('N', 'U', num_pop, prec_copy, num_pop, w, work_eigen, &\n max(3*num_pop-1, 1), info)\n \n if ( w(1) <= 0 .or. product(w) <= 0 ) then\n if (verbose .and. mod(i, verb_period) == 0) then\n print *, 'Iteration ', i, ', Precision is not positive definite!'\n end if\n cost_old = huge(1.)\n else\n cost = - log(product(w)) + sum(prec * corr) + &\n sum(max(lambda_glasso, 0.0) * abs(prec))\n diff = cost_old - cost\n\n if (verbose .and. mod(i, verb_period) == 0) then \n print *, 'Iteration ', i, ', cost: ', cost, ', difference: ', diff\n end if\n\n if (abs(diff) < ths) then\n converged = .true.\n exit\n end if\n \n cost_old = cost\n end if\n end do\n \nend subroutine coord_desc", "meta": {"hexsha": "8c10f66006fd81cc2dbe8d7b844058b3e91f9482", "size": 3939, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "miccs/optimize/coord_desc.f90", "max_stars_repo_name": "HeejongBong/MICCS", "max_stars_repo_head_hexsha": "68b57cead8849e0c4bafb38521c08f4b7bf18b1a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "miccs/optimize/coord_desc.f90", "max_issues_repo_name": "HeejongBong/MICCS", "max_issues_repo_head_hexsha": "68b57cead8849e0c4bafb38521c08f4b7bf18b1a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "miccs/optimize/coord_desc.f90", "max_forks_repo_name": "HeejongBong/MICCS", "max_forks_repo_head_hexsha": "68b57cead8849e0c4bafb38521c08f4b7bf18b1a", "max_forks_repo_licenses": ["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.8130841121, "max_line_length": 86, "alphanum_fraction": 0.5651180503, "num_tokens": 1016, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544912, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6810962064037289}} {"text": "module matrixMath\n\nUSE IntrinsicTypesModule, RK=>REAL_KIND\nUSE units_mod\n\nIMPLICIT NONE\n\nCONTAINS\n\nSUBROUTINE mat_mult_const_mat(a, b, c)\n\n IMPLICIT NONE\n\n REAL(RK), INTENT(IN) :: a(:, :, :), b(:, :)\n REAL(RK), INTENT(OUT):: c(:, :, :)\n\n INTEGER :: i, j, k\n\n INTEGER lda, ldb, ldc, lta, ltb, n\n!\n!----------------------------------------------------------------------\n\n lda = ubound(a, 2)\n ldb = ubound(b, 1)\n lta = ubound(a, 3)\n ltb = ubound(b, 2)\n\n c = 0.0_RK\n\n do k = 1,ltb\n do j = 1,ldb\n do i = 1,lda\n c(:, i, k) = c(:, i, k) + a(:, i, j)*b(j, k)\n end do\n end do\n end do\n\nEND SUBROUTINE mat_mult_const_mat\n\nSUBROUTINE mat_const_mult_mat(a, b, c)\n\n IMPLICIT NONE\n\n REAL(RK), INTENT(IN) :: a(:, :), b(:, :, :)\n REAL(RK), INTENT(OUT):: c(:, :, :)\n\n INTEGER :: i, j, k\n\n INTEGER lda, ldb, lta, ltb\n!\n!----------------------------------------------------------------------\n\n lda = ubound(a, 1)\n ldb = ubound(b, 2)\n lta = ubound(a, 2)\n ltb = ubound(b, 3)\n\n c = 0.0_RK\n\n do k = 1,ltb\n do j = 1,ldb\n do i = 1,lda\n c(:, i, k) = c(:, i, k) + a(i, j)*b(:, j, k)\n end do\n end do\n end do\n\nEND SUBROUTINE mat_const_mult_mat\n\nSUBROUTINE matrix_mult(a, b, c)\n\n\n IMPLICIT NONE\n\n REAL(RK), INTENT(IN) :: a(:, :, :), b(:, :, :)\n REAL(RK), INTENT(OUT):: c(:, :, :)\n\n INTEGER :: i, j, k\n\n INTEGER lda, ldb, lta, ltb\n!\n!----------------------------------------------------------------------\n\n lda = ubound(a, 2)\n ldb = ubound(b, 2)\n lta = ubound(a, 3)\n ltb = ubound(b, 3)\n\n c = 0.0_RK\n\n do k = 1,ltb\n do j = 1,ldb\n do i = 1,lda\n c(:, i, k) = c(:, i, k) + a(:, i, j)*b(:, j, k)\n end do\n end do\n end do\n\nEND SUBROUTINE matrix_mult\n\nSUBROUTINE mat_const_mult_vec(a, b, c)\n\n IMPLICIT NONE\n\n REAL(RK), INTENT(IN) :: a(:, :), b(:, :)\n REAL(RK), INTENT(OUT):: c(:, :)\n\n INTEGER :: j, k\n\n INTEGER lda, ldb , lta, ltb\n!\n!----------------------------------------------------------------------\n\n lda = ubound(a, 1)\n ldb = ubound(b, 1)\n lta = ubound(a, 2)\n ltb = ubound(b, 2)\n\n c = 0.0_RK\n\n do k = 1,ltb\n do j = 1,lda\n c(:, j) = c(:, j) + a(j, k)*b(:, k)\n end do\n end do\n\nEND SUBROUTINE mat_const_mult_vec\n\nSUBROUTINE vec_dot_prod(a, b, c)\n\n IMPLICIT NONE\n REAL(RK), INTENT(IN) :: a(:, :), b(:, :)\n REAL(RK), INTENT(OUT) :: c(:)\n\n\n\n INTEGER :: i, lta\n lta = ubound(a, 2)\n\n c = 0.0_RK\n\n do i = 1,lta\n c(:) = c(:) + a(:, i)*b(:, i)\n end do\n\nEND SUBROUTINE vec_dot_prod\n\nSUBROUTINE ltwonorm(vec, norm)\n\n IMPLICIT NONE\n REAL(RK), INTENT(IN) :: vec(:)\n REAL(RK), INTENT(OUT) :: norm\n\n REAL(RK), ALLOCATABLE :: svec(:)\n INTEGER :: i, lta\n\n lta = ubound(vec,1)\n ALLOCATE(svec(1:lta))\n\n svec = vec*vec\n norm = 0.0_RK\n\n do i = 1, lta\n norm = norm + sqrt(svec(i))\n end do\n\nEND SUBROUTINE ltwonorm\n\nSUBROUTINE getskewmat(mat, skew, dim)\n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: dim\n REAL(RK), INTENT(IN) :: mat(0:dim, 0:DIMS1, 0:DIMS1)\n REAL(RK), INTENT(OUT) :: skew(0:dim, 0:DIMS1, 0:DIMS1)\n\n skew = 0.0_RK\n\n skew(:, 0, 1) = 0.5_RK * (mat(:, 0, 1) - mat(:, 1, 0))\n skew(:, 0, 2) = 0.5_RK * (mat(:, 0, 2) - mat(:, 2, 0))\n skew(:, 1, 2) = 0.5_RK * (mat(:, 1, 2) - mat(:, 2, 1))\n\n skew(:, 1, 0) = - skew(:, 0, 1)\n skew(:, 2, 0) = - skew(:, 0, 2)\n skew(:, 2, 1) = - skew(:, 1, 2)\n\n\nEND SUBROUTINE getskewmat\n\nSUBROUTINE getsymmat(mat, sym, dim)\n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: dim\n REAL(RK), INTENT(IN) :: mat(0:dim, 0:DIMS1, 0:DIMS1)\n REAL(RK), INTENT(OUT) :: sym(0:dim, 0:DIMS1, 0:DIMS1)\n\n sym = 0.0_RK\n\n sym(:, 0, 0) = mat(:, 0, 0)\n sym(:, 1, 1) = mat(:, 1, 1)\n sym(:, 2, 2) = mat(:, 2, 2)\n\n sym(:, 0, 1) = 0.5_RK * (mat(:, 0, 1) + mat(:, 1, 0))\n sym(:, 0, 2) = 0.5_RK * (mat(:, 0, 2) + mat(:, 2, 0))\n sym(:, 1, 2) = 0.5_RK * (mat(:, 1, 2) + mat(:, 2, 1))\n\n sym(:, 1, 0) = sym(:, 0, 1)\n sym(:, 2, 0) = sym(:, 0, 2)\n sym(:, 2, 1) = sym(:, 1, 2)\n\n\nEND SUBROUTINE getsymmat\n\nSUBROUTINE getDevMat(mat, dev)\n\n IMPLICIT NONE\n\n REAL(RK), INTENT(IN) :: mat(0:nelem1, 0:DIMS1, 0:DIMS1)\n REAL(RK), INTENT(OUT) :: dev(0:nelem1, 0:DIMS1, 0:DIMS1)\n\n REAL(RK) :: trVal(0:nelem1)\n\n trVal = 1.0_RK/3.0_RK * (mat(:, 0, 0)+mat(:, 1, 1)+mat(:, 2, 2))\n\n dev(:, 0, 0) = mat(:, 0, 0) - trVal\n dev(:, 1, 1) = mat(:, 1, 1) - trVal\n dev(:, 2, 2) = mat(:, 2, 2) - trVal\n\n dev(:, 0, 1) = mat(:, 0, 1)\n dev(:, 0, 2) = mat(:, 0, 2)\n dev(:, 1, 2) = mat(:, 1, 2)\n\n dev(:, 1, 0) = mat(:, 1, 0)\n dev(:, 2, 0) = mat(:, 2, 0)\n dev(:, 2, 1) = mat(:, 2, 1)\n\n\nEND SUBROUTINE getDevMat\n\nSUBROUTINE invert4x4(m, invOut)\n !Took this from a stackoverflow topic on how to code a inverted 4x4 matrix\n IMPLICIT NONE\n\n REAL(RK), INTENT(IN) :: m(0:15)\n REAL(RK), INTENT(OUT) :: invOut(0:15)\n REAL(RK) :: inv(0:15)\n REAL(RK) :: det, idet\n\n inv(0) = m(5) * m(10) * m(15) - m(5) * m(11) * m(14) - m(9)&\n &* m(6) * m(15) + m(9) * m(7) * m(14) + m(13) * m(6) * m(11) - m(13) * m(7) * m(10)\n\n inv(4) = -m(4) * m(10) * m(15) + m(4) * m(11) * m(14) + m(8)&\n &* m(6) * m(15) - m(8) * m(7) * m(14) - m(12) * m(6) * m(11) + m(12) * m(7) * m(10)\n\n inv(8) = m(4) * m(9) * m(15) - m(4) * m(11) * m(13) - m(8)&\n &* m(5) * m(15) + m(8) * m(7) * m(13) + m(12) * m(5) * m(11) - m(12) * m(7) * m(9)\n\n inv(12) = -m(4) * m(9) * m(14) + m(4) * m(10) * m(13) + m(8)&\n &* m(5) * m(14) - m(8) * m(6) * m(13) - m(12) * m(5) * m(10) + m(12) * m(6) * m(9)\n\n inv(1) = -m(1) * m(10) * m(15) + m(1) * m(11) * m(14) + m(9)&\n &* m(2) * m(15) - m(9) * m(3) * m(14) - m(13) * m(2) * m(11) + m(13) * m(3) * m(10)\n\n inv(5) = m(0) * m(10) * m(15) - m(0) * m(11) * m(14) - m(8)&\n &* m(2) * m(15) + m(8) * m(3) * m(14) + m(12) * m(2) * m(11) - m(12) * m(3) * m(10)\n\n inv(9) = -m(0) * m(9) * m(15) + m(0) * m(11) * m(13) + m(8)&\n &* m(1) * m(15) - m(8) * m(3) * m(13) - m(12) * m(1) * m(11) + m(12) * m(3) * m(9)\n\n inv(13) = m(0) * m(9) * m(14) - m(0) * m(10) * m(13) - m(8)&\n &* m(1) * m(14) + m(8) * m(2) * m(13) + m(12) * m(1) * m(10) - m(12) * m(2) * m(9)\n\n inv(2) = m(1) * m(6) * m(15) - m(1) * m(7) * m(14) - m(5)&\n &* m(2) * m(15) + m(5) * m(3) * m(14) + m(13) * m(2) * m(7) - m(13) * m(3) * m(6)\n\n inv(6) = -m(0) * m(6) * m(15) + m(0) * m(7) * m(14) + m(4)&\n &* m(2) * m(15) - m(4) * m(3) * m(14) - m(12) * m(2) * m(7) + m(12) * m(3) * m(6)\n\n inv(10) = m(0) * m(5) * m(15) - m(0) * m(7) * m(13) - m(4)&\n &* m(1) * m(15) + m(4) * m(3) * m(13) + m(12) * m(1) * m(7) - m(12) * m(3) * m(5)\n\n inv(14) = -m(0) * m(5) * m(14) + m(0) * m(6) * m(13) + m(4)&\n &* m(1) * m(14) - m(4) * m(2) * m(13) - m(12) * m(1) * m(6) + m(12) * m(2) * m(5)\n\n inv(3) = -m(1) * m(6) * m(11) + m(1) * m(7) * m(10) + m(5)&\n &* m(2) * m(11) - m(5) * m(3) * m(10) - m(9) * m(2) * m(7) + m(9) * m(3) * m(6)\n\n inv(7) = m(0) * m(6) * m(11) - m(0) * m(7) * m(10) - m(4)&\n &* m(2) * m(11) + m(4) * m(3) * m(10) + m(8) * m(2) * m(7) - m(8) * m(3) * m(6)\n\n inv(11) = -m(0) * m(5) * m(11) + m(0) * m(7) * m(9) + m(4)&\n &* m(1) * m(11) - m(4) * m(3) * m(9) - m(8) * m(1) * m(7) + m(8) * m(3) * m(5)\n\n inv(15) = m(0) * m(5) * m(10) - m(0) * m(6) * m(9) - m(4)&\n &* m(1) * m(10) + m(4) * m(2) * m(9) + m(8) * m(1) * m(6) - m(8) * m(2) * m(5)\n\n det = m(0) * inv(0) + m(1) * inv(4) + m(2) * inv(8) + m(3) * inv(12);\n\n idet = 1.0_RK/det;\n\n invOut(:) = inv(:) * idet;\n\nEND SUBROUTINE invert4x4\n\nSUBROUTINE solve4x4(m, v, x)\n\n !We are going to be using this for finding the barycentric coordinates of a tetrahedron\n !This can then be used to tell us if a point is inside a tetrahedron or not. It can also\n !be used to linearly interpolate scalar values out to the coords of the tetrahedron.\n\n IMPLICIT NONE\n\n REAL(RK), INTENT(IN) :: m(4,4), v(4)\n REAL(RK), INTENT(OUT) :: x(4)\n\n REAL(RK) :: inv_m(4,4)\n !Just giving a rough parameter for machine precision\n REAL(RK), PARAMETER :: mach_eps = 2.2e-16\n\n call invert4x4(m, inv_m)\n\n x = matmul(inv_m, v)\n\n !If under machine precision we're just going to set the value to zero\n !This should also help us deal with points that lie on an edge or point of the\n !tetrahedron\n where(abs(x) .LE. mach_eps) x = 0.0_RK\n\nEND SUBROUTINE solve4x4\n\nend module matrixMath", "meta": {"hexsha": "24db255aa8c3d3da402a0f039e92e57229b634a4", "size": 8607, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "PythonFortranCode/matrixMath.f90", "max_stars_repo_name": "rcarson3/pyFEpX", "max_stars_repo_head_hexsha": "f95851e41025fb57893041d0395d53a5745b7e6c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-03-27T21:24:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T13:35:59.000Z", "max_issues_repo_path": "PythonFortranCode/matrixMath.f90", "max_issues_repo_name": "rcarson3/pyFEpX", "max_issues_repo_head_hexsha": "f95851e41025fb57893041d0395d53a5745b7e6c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-09-10T22:54:10.000Z", "max_issues_repo_issues_event_max_datetime": "2018-09-10T22:54:10.000Z", "max_forks_repo_path": "PythonFortranCode/matrixMath.f90", "max_forks_repo_name": "rcarson3/pyFEpX", "max_forks_repo_head_hexsha": "f95851e41025fb57893041d0395d53a5745b7e6c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-05-13T07:44:35.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-11T13:36:00.000Z", "avg_line_length": 26.0818181818, "max_line_length": 95, "alphanum_fraction": 0.4333681887, "num_tokens": 3985, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.882427860270573, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6810962016307118}} {"text": " subroutine sfncge(delxi,xval0,xtargv,dxval0,nord,nrd1mx,resx)\nc\nc This subroutine computes a general search function for\nc EQ6/search.f. This search function is a residual defined as the\nc difference between the calculated value of a function (xvalc)\nc described by a truncated Taylor's series and a target value\nc (xtargv).\nc\nc This subroutine is called by:\nc\nc EQ6/search.f\nc\nc-----------------------------------------------------------------------\nc\nc Principal input:\nc\nc delxi = step size\nc xtargv = target value\nc xval0 = the function value at delxi = 0\nc dxval0 = the derivatives of this function at delxi = 0\nc nord = the order of the truncated Taylor's series\nc\nc Principal output:\nc\nc resx = value of residual function\nc\nc-----------------------------------------------------------------------\nc\n implicit none\nc\nc-----------------------------------------------------------------------\nc\nc Calling sequence variable declarations.\nc\n integer nrd1mx\nc\n integer nord\nc\n real*8 dxval0(nrd1mx)\nc\n real*8 delxi,resx,xtargv,xval0\nc\n real*8 fctrl\nc\nc-----------------------------------------------------------------------\nc\nc Local variable declarations.\nc\n integer n\nc\n real*8 dxp,xvalc\nc\nc-----------------------------------------------------------------------\nc\n xvalc = xval0\n if (nord .gt. 0) then\n dxp = 1.\n do n = 1,nord\n dxp = dxp*delxi\n xvalc = xvalc + ( dxval0(n)/fctrl(n) )*dxp\n enddo\n endif\n resx = xvalc - xtargv\nc\n end\n", "meta": {"hexsha": "879c4e5e04f7c23afe3690163ae281bea67a7b07", "size": 1633, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/eq6/src/sfncge.f", "max_stars_repo_name": "39alpha/eq3_6", "max_stars_repo_head_hexsha": "4ff7eec3d34634f1470ae5f67d8e294694216b6e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/eq6/src/sfncge.f", "max_issues_repo_name": "39alpha/eq3_6", "max_issues_repo_head_hexsha": "4ff7eec3d34634f1470ae5f67d8e294694216b6e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-11-30T15:48:52.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-02T18:16:22.000Z", "max_forks_repo_path": "src/eq6/src/sfncge.f", "max_forks_repo_name": "39alpha/eq3_6", "max_forks_repo_head_hexsha": "4ff7eec3d34634f1470ae5f67d8e294694216b6e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.7424242424, "max_line_length": 72, "alphanum_fraction": 0.490508267, "num_tokens": 422, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278540866548, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6810962014888723}} {"text": "c program DRDEVVUN\nc>> 1996-05-28 DRDEVVUN Krogh Added external statement.\nc>> 1994-10-19 DRDEVVUN Krogh Changes to use M77CON\nc>> 1994-09-22 DRDEVVUN CLL\nc>> 1992-04-23 CLL\nc>> 1992-03-04 DRDEVVUN Krogh Initial version.\nc Demonstrate unsymmetric eigenvalue/eigenvector subroutine DEVVUN.\nc ------------------------------------------------------------------\nc--D replaces \"?\": DR?EVVUN, ?EVVUN, ?VECP, ?MATP, ?DOT\nc ------------------------------------------------------------------\n integer I, J, LDA, N\n parameter (LDA = 3)\n integer IFLAG(LDA)\n double precision A(LDA,LDA), VR(LDA), VI(LDA), VEC(LDA, LDA)\n double precision WORK(LDA), ASAV(LDA, LDA), D(LDA, LDA), ANORM\n external DDOT\n double precision DDOT\n data (A(1,I), I=1,3) / 8.0d0, -1.0d0, -5.0d0 /\n data (A(2,I), I=1,3) / -4.0d0, 4.0d0, -2.0d0 /\n data (A(3,I), I=1,3) / 18.0d0, -5.0d0, -7.0d0 /\n data ANORM / 30.0d0 /\n data N / LDA /\nc ------------------------------------------------------------------\n print*,'DRDEVVUN.. Demo driver for DEVVUN.'\nc\nc First copy A() to ASAV() for later residual check.\nc\n do 20 J = 1, N\n do 10 I = 1, N\n ASAV(I, J) = A(I, J)\n 10 continue\n 20 continue\n\n call DEVVUN(A(1, 1), LDA, N, VR, VI, VEC, IFLAG, WORK)\n\n print '(a, I2)',' IFLAG(1) =',IFLAG(1)\n if (IFLAG(1) .le. 2) then\n call DVECP(VR, N, ' Real part of the eigenvalues')\n call DVECP(VI, N, ' Imaginary part of the eigenvalues')\n call DMATP(VEC, LDA, N, N,\n * '0 Eigenvectors as columns or pairs of columns')\nc\nc As a check compute D = (ASAV*VEC - VEC*EVAL) / ANORM.\nc Expect D to be close to the machine precision.\nc\n do 50 J = 1, N\n if (VI(J) .eq. 0.0d0) then\nc Compute residual for a real eigenvalue and eigenvector\n do 30 I = 1, N\n D(I, J) = (DDOT(N, ASAV(I,1), LDA, VEC(1,J), 1) -\n * VEC(I,J) * VR(J)) / ANORM\n 30 continue\n else if (VI(J) .gt. 0.0d0) then\n do 40 I = 1, N\n D(I, J) = (DDOT(N,ASAV(I,1),LDA,VEC(1,J),1) -\n * VEC(I,J)*VR(J)+VEC(I,J+1)*VI(J))/ANORM\n D(I, J+1) = (DDOT(N,ASAV(I,1),LDA,VEC(1,J+1),1) -\n * VEC(I,J)*VI(J)-VEC(I,J+1)*VR(J))/ANORM\n 40 continue\n end if\n 50 continue\n call DMATP(D, LDA, N, N,\n * '0 Packed residual matrix D = (A*EVEC - EVEC*EVAL) / ANORM')\n else\n print'(/a)', ' Failure in DEVVUN. '\n end if\n stop\n end\n", "meta": {"hexsha": "d9b2397ab337d7773b2b721269892ae8239078da", "size": 2746, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drdevvun.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drdevvun.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drdevvun.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.7971014493, "max_line_length": 72, "alphanum_fraction": 0.4584850692, "num_tokens": 956, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278540866547, "lm_q2_score": 0.7718434873426302, "lm_q1q2_score": 0.6810961922265172}} {"text": "!----------------------------------------\n subroutine computeorthogradient(msk,psi,dx,dy,nh,n,m,u,v)\n\n! compute u,v= (-dpsi/dy,dpsi/dx)\n!\n \n implicit none\n\n integer,intent(in):: n,m,nh\n integer*1,dimension(m,n) :: msk\n real*8,dimension(m,n) :: psi,u,v\n real*8::dx,dy\n\n!f2py intent(inplace)::psi,msk,u,v\n\n real*8::zdx,zdy\n integer:: i,j\n integer*1:: mm\n\n zdx = 1./dx\n zdy = 1./dy\n do j=2,m-1!nh-1,m-nh+1\n do i=2,n-1!nh-1,n-nh+1\n mm=msk(j,i)+msk(j,i+1)\n if(mm.eq.2)then\n u(j,i) = zdy*(psi(j-1,i)-psi(j,i))\n else\n u(j,i) = 0.\n endif\n mm=msk(j,i)+msk(j+1,i)\n if(mm.eq.2)then\n v(j,i) = zdx*(psi(j,i)-psi(j,i-1))\n else\n v(j,i) = 0.\n endif\n enddo\n enddo\n\n end subroutine\n\n\n\n!----------------------------------------\n subroutine celltocorner(xr,xp,n,m)\n\n! average 4 cell centers at upper right cell corner\n!\n \n implicit none\n\n integer,intent(in):: n,m\n real*8,dimension(m,n) :: xr,xp\n\n!f2py intent(inplace)::xr,xp\n\n integer:: i,j\n\n do j=1,m-1\n do i=1,n-1\n xp(j,i)=0.25*(xr(j,i)+xr(j,i+1)+xr(j+1,i)+xr(j+1,i+1))\n enddo\n enddo\n\n end subroutine\n\n!----------------------------------------\n subroutine celltocornerbicubic(xr,xp,n,m)\n\n! average 4x4 cell centers at upper right cell corner\n! using the finite difference interpolation [-1,9,9,1]/16 in each direction\n \n implicit none\n\n integer,intent(in):: n,m\n real*8,dimension(m,n) :: xr,xp\n\n!f2py intent(inplace)::xr,xp\n real:: cff\n integer:: i,j,jj,k1,k2,k3,k4\n real*8,dimension(n,4)::z\n\n cff = 1./12.\n do j=1,m\n k1 = mod(j-1,4)+1\n do i=2,n-2\n z(i,k1)=cff*(-xr(j,i-1)+7*(xr(j,i)+xr(j,i+1))-xr(j,i+2))\n enddo\n if (j.ge.4)then\n k2 = mod(j-2,4)+1\n k3 = mod(j-3,4)+1\n k4 = mod(j-4,4)+1\n jj = j-2\n do i=2,n-2\n xp(jj,i)=cff*(-z(i,k1)+7*(z(i,k2)+z(i,k3))-z(i,k4))\n enddo\n endif\n enddo\n\n end subroutine\n\n!----------------------------------------\n subroutine cornertocell(xp,xr,n,m)\n\n! average 4 cell centers at upper right cell corner\n!\n \n implicit none\n\n integer,intent(in):: n,m\n real*8,dimension(m,n) :: xr,xp\n\n!f2py intent(inplace)::xr,xp\n\n integer:: i,j\n\n do j=2,m\n do i=2,n\n xr(j,i)=0.25*(xp(j,i)+xp(j,i-1)+xp(j-1,i)+xp(j-1,i-1))\n enddo\n enddo\n\n end subroutine\n\n!----------------------------------------\n subroutine add_diffusion(msk,trac,dx,nh,Kdiff,dtrac,n,m)\n\n! add a diffusion term (with homogenous Neumann BC) on trac\n!\n \n implicit none\n\n integer,intent(in):: n,m,nh\n integer*1,dimension(m,n) :: msk\n real*8,dimension(m,n) :: trac,dtrac\n real*8,intent(in)::dx,Kdiff\n\n!f2py intent(inplace)::msk,trac,dtrac\n\n real*8::coef,dbl,dbr\n integer:: i,j\n integer*1:: mm,ml,mr\n\n coef = Kdiff/(dx*dx)\n do j=2,m-1\n do i=2,n-1\n if (msk(j,i).eq.1) then\n dtrac(j,i) = dtrac(j,i) + coef*( &\n + msk(j,i-1) * ( trac(j,i-1)-trac(j,i) ) &\n + msk(j,i+1) * ( trac(j,i+1)-trac(j,i) ) &\n + msk(j-1,i) * ( trac(j-1,i)-trac(j,i) ) &\n + msk(j+1,i) * ( trac(j+1,i)-trac(j,i) ) )\n endif\n enddo\n enddo\n\n end subroutine\n\n\n!----------------------------------------\n subroutine computewallshear(msk,x,y,total,dx,nh,m,n)\n\n! compute y=b-A*x\n\n implicit none\n\n integer,intent(in):: n,m,nh\n integer*1,dimension(m,n) :: msk\n real*8,dimension(m,n) :: x\n real*8,dimension(m,n) :: y\n real*8::dx,total\n\n!f2py intent(inplace)::msk,x\n!f2py intent(inplace)::y\n!f2py intent(out)::total\n\n! real*8,dimension(n,3) :: xo\n integer:: i,j\n integer*1::msku,mskv\n real*8::cff,u,v\n\n cff=1./(2*dx*dx) \n\n! y(:,:)=0.\n total=0.\n y(1:nh,:)=0.\n do j=nh+1,m-nh+1\n y(j,1:nh)=0.\n do i=nh+1,n-nh+1\n y(j,i)=0.\n msku=msk(j,i-1)+msk(j,i)\n if (msku.eq.1)then\n if(msk(j,i).ne.0)then\n v=(x(j,i+1)+x(j-1,i+1))*cff\n y(j,i)=y(j,i)-v\n total=total-v\n else\n v=(x(j,i-3)+x(j-1,i-3))*cff\n y(j,i-1)=y(j,i-1)+v\n total=total+v\n endif\n endif\n mskv=msk(j-1,i)+msk(j,i)\n if (mskv.eq.1)then\n if(msk(j,i).ne.0)then\n u=(x(j+1,i)+x(j+1,i-1))*cff\n y(j,i)=y(j,i)+u\n total=total+u\n else\n u=(x(j-3,i)+x(j-3,i-1))*cff\n y(j-1,i)=y(j-1,i)-u\n total=total-u\n endif\n endif\n enddo\n enddo\n\n\n end subroutine \n\n!----------------------------------------\n subroutine computenoslipsourceterm(msk,x,y,total,dx,dy,nh,m,n)\n\n! compute y=b-A*x\n\n implicit none\n\n integer,intent(in):: n,m,nh\n integer*1,dimension(m,n) :: msk\n real*8,dimension(m,n) :: x\n real*8,dimension(m,n) :: y\n real*8::dx,dy,total\n\n!f2py intent(inplace)::msk,x\n!f2py intent(inplace)::y\n!f2py intent(out)::total\n\n! real*8,dimension(n,3) :: xo\n integer:: i,j\n integer*1::msku,mskv\n real*8::cff,u,v\n\n cff=1./(2*dx*dy)\n\n! y(:,:)=0.\n total=0.\n y(1:nh,:)=0.\n do j=nh+1,m-nh+1\n y(j,1:nh)=0.\n do i=nh+1,n-nh+1\n y(j,i)=0.\n msku=msk(j,i-1)+msk(j,i)\n if (msku.eq.1)then\n v=(x(j,i)+x(j-1,i)-x(j,i-2)-x(j-1,i-2))*cff\n if(msk(j,i).ne.0)then\n y(j,i)=y(j,i)-v\n total=total-v\n else\n y(j,i-1)=y(j,i-1)+v\n total=total+v\n endif\n endif\n mskv=msk(j-1,i)+msk(j,i)\n if (mskv.eq.1)then\n u=-(x(j,i)+x(j,i-1)-x(j-2,i)-x(j-2,i-1))*cff\n if(msk(j,i).ne.0)then\n y(j,i)=y(j,i)+u\n total=total+u\n else\n y(j-1,i)=y(j-1,i)-u\n total=total-u\n endif\n endif\n enddo\n enddo\n\n\n end subroutine \n\n\n!----------------------------------------\n subroutine computenoslipsourceterm_regularized(msk,x,y,cu,cv,total,dx,nh,m,n)\n\n! compute y=b-A*x\n\n implicit none\n\n integer,intent(in):: n,m,nh\n integer*1,dimension(m,n) :: msk\n real*8,dimension(m,n) :: x,cu,cv\n real*8,dimension(m,n) :: y\n real*8::dx,total\n\n!f2py intent(inplace)::msk,x,cu,cv\n!f2py intent(inplace)::y\n!f2py intent(out)::total\n\n! real*8,dimension(n,3) :: xo\n integer:: i,j\n integer*1::msku,mskv\n real*8::cff,ul,ur,vl,vr,z\n\n cff=2./(dx*dx)\n\n! y(:,:)=0.\n total=0.\n y(1:nh,:)=0.\n do j=nh+1,m-nh+1\n y(j,1:nh)=0.\n do i=nh+1,n-nh+1\n if(msk(j,i).ne.0)then \n vl = (x(j,i)-x(j,i-1))*cv(j,i-1)/(msk(j,i)+msk(j,i-1))\n vr = (x(j,i)-x(j,i+1))*cv(j,i)/(msk(j,i)+msk(j,i+1))\n\n ul = (x(j,i)-x(j-1,i))*cu(j-1,i)/(msk(j,i)+msk(j-1,i))\n ur = (x(j,i)-x(j+1,i))*cu(j,i)/(msk(j,i)+msk(j+1,i))\n \n z = -(vl+ur+vr+ul)*cff\n y(j,i) = z\n total=total+z\n else\n y(j,i)=0.\n endif\n enddo\n enddo\n\n\n end subroutine \n\n!----------------------------------------\n subroutine add_torque(msk,buoy,dx,nh,gravity,domega,n,m)\n\n! add torque db/dx to domega\n!\n \n implicit none\n\n integer,intent(in):: n,m,nh\n integer*1,dimension(m,n) :: msk\n real*8,dimension(m,n) :: buoy,domega\n real*8,intent(in)::dx,gravity\n\n!f2py intent(inplace)::msk,buoy,domega\n\n real*8::coef,dbl,dbr,sum,z\n integer:: i,j,ii\n integer*1:: ml,mr,mm,one\n\n coef = 0.5*gravity/(dx)\n\n one = 1\n do j=1+nh,m-nh\n! sum=0.\n i=1+nh\n ml = max(one,msk(j,i)+ msk(j,i-1))\n dbl = (buoy(j,i)*msk(j,i)+buoy(j,i-1)*msk(j,i-1))/ml\n do i=1+nh,n-nh\n\n mr = max(one,msk(j,i+1)+ msk(j,i))\n dbr=(buoy(j,i+1)*msk(j,i+1)+buoy(j,i)*msk(j,i))/mr\n\n mm=(ml+mr)\n! if(mm.gt.0) then\n! z = (dbr-dbl)*(coef)\n! else\n! z=0.\n! endif\n if (mm.eq.4) then\n! domega(j,i) = domega(j,i) + (dbr-dbl)*(coef)*msk(j,i)\n domega(j,i) = domega(j,i) + (buoy(j,i+1)-buoy(j,i-1))*(coef)*msk(j,i)\n endif\n! sum=sum+z\n! if(mm.gt.0) domega(j,i) = domega(j,i)+(dbr-dbl)*(coef/mm)\n ml=mr\n dbl=dbr\n! ii=ii+1\n enddo\n! write(*,*)\"sum=\",j,ii,sum\n enddo\n\n\n end subroutine \n\n\n", "meta": {"hexsha": "208df611bcec7771235e3861997d5dfa6cd0edd6", "size": 9117, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fluid2d/core/fortran_operators.f90", "max_stars_repo_name": "chenyg1119/fluid-simulation", "max_stars_repo_head_hexsha": "f504042602fab54855177f20be2dfe1c7ee4f2d9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Fluid2d/core/fortran_operators.f90", "max_issues_repo_name": "chenyg1119/fluid-simulation", "max_issues_repo_head_hexsha": "f504042602fab54855177f20be2dfe1c7ee4f2d9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fluid2d/core/fortran_operators.f90", "max_forks_repo_name": "chenyg1119/fluid-simulation", "max_forks_repo_head_hexsha": "f504042602fab54855177f20be2dfe1c7ee4f2d9", "max_forks_repo_licenses": ["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.7421875, "max_line_length": 86, "alphanum_fraction": 0.4274432379, "num_tokens": 3114, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382023207901, "lm_q2_score": 0.7905303285397349, "lm_q1q2_score": 0.6810720781301869}} {"text": "! Forlab\n!-----------------------------------------------------------------------\n! Forlab aims to provide a package of functions for scientific\n! computing in Fortran.\n!\n! Created by\n! Keurfon Luu \n! MINES ParisTech - Centre de G\u00e9osciences\n! PSL - Research University\n!\n! Notes\n!-----------------------------------------------------------------------\n! When changing precision (IPRE and/or RPRE), the whole program needs to\n! be recompiled.\n\nmodule forlab\n\n use forlab_kinds\n\n implicit none\n\n ! Parameters\n integer, public, parameter :: IPRE = 4\n integer, public, parameter :: RPRE = 8\n integer, public, parameter :: CLEN = 512\n real(kind=8), public, parameter :: pi = 3.141592653589793238460d0\n real(kind=8), public, save :: tic_time\n real(sp),public, parameter ::pi_sp=acos(-1.0_sp)\n real(dp),public, parameter ::pi_dp=acos(-1.0_dp)\n real(qp),public, parameter ::pi_qp=acos(-1.0_qp)\n ! Functions\n private\n public :: File, acosd, asind, atand, argmax, argmin, argsort, arange, &\n angle, bsplrep1, bsplrep2, bspline1, bspline2, chol, cosd, countlines, &\n cov, cumsum, chi2cdf, chi2pdf, chi2inv, chi2rand, check_directory, &\n det, diag, disp, deg2utm, datenum, datevec, datestr, deboor, diff, &\n eig, empty, eye, &\n find, flip, fliplr, flipud, fminbnd, gammainc, horzcat, &\n hann, interp1, interp2, interp3, inv, ismember, isoutlier, issquare, &\n isleap, issymmetric, kurtosis, k2test, kde, loadtxt, loadbin, linspace, &\n mean, median, mad, meshgrid, nextpow2, norm, normpdf, num2str, ones, &\n outer, pascal, prctile, progress_bar, progress_perc, rng, randu, randn, &\n randi, randperm, repmat, rms, savetxt, savebin, sind, sort, solve, &\n svd, svdsolve, std, spline1, spline2, skewness, signum, sinc, &\n split_argument, tand, tic, toc, trace, tril, triu, utm2deg, vertcat, &\n var, zeros, dbindex, gmm, kmeans, mbkmeans, silhouette\n ! #ifdef do_mpi\n public :: mpi_rpre\n ! #endif\n \n ! Operators\n public :: operator(.i.), operator(.x.)\n\n type file\n integer :: unit\n character(len=CLEN) :: filename\n contains\n procedure, private :: open1, open2, countlines1, file_exist\n procedure, public :: close\n generic, public :: open => open1, open2\n generic, public :: countlines => countlines1\n generic, public :: exist => file_exist\n end type file\n\n ! Abstract function\n abstract interface\n real(kind=RPRE) function func1d(x)\n import :: RPRE\n real(kind=RPRE), intent(in) :: x\n end function func1d\n end interface\n\n !! Polymorphic Interfaces\n interface det\n !! det computes the matrix determinant.\n !!\n !! Syntax\n !!-----------------------------------------------------------------------\n !! ```fortran\n !! x = det(A) \n !! x = det(A, L, U) \n !! ```\n !! Description\n !!-----------------------------------------------------------------------\n !! x = det(A) returns the determinant of the square matrix A, as the\n !! product of the diagonal elements of the upper triangular matrix from\n !! the LU factorization of A.\n !!\n !! x = det(A, L, U) returns the determinant of the square matrix A and\n !! outputs the LU factorization matrices of A used for the calculation.\n !!\n !! Examples\n !!-----------------------------------------------------------------------\n !! ```fortran\n !! A = reshape([ 1., 2., 3., 4., 5., 6., 7., 8., 0. ], [ 3, 3 ], & \n !! order = [ 2, 1 ]) \n !! x = det(A) \n !! 27. \n !! ```\n real(sp) module function det_sp (A, outL, outU)\n real(sp), dimension(:, :), intent(in) :: A\n real(sp), dimension(:, :), allocatable, intent(inout), optional :: outL, outU\n end function\n real(dp) module function det_dp (A, outL, outU)\n real(dp), dimension(:, :), intent(in) :: A\n real(dp), dimension(:, :), allocatable, intent(inout), optional :: outL, outU\n end function\n real(qp) module function det_qp (A, outL, outU)\n real(qp), dimension(:, :), intent(in) :: A\n real(qp), dimension(:, :), allocatable, intent(inout), optional :: outL, outU\n end function\n end interface\n\n interface acosd\n<<<<<<< HEAD\n pure elemental module function acosd_sp(x)\n=======\n pure elemental module function acosd_sp(x)\n>>>>>>> upstream/master\n real(sp),intent(in)::x\n real(sp)::acosd_sp\n end function\n<<<<<<< HEAD\n pure elemental module function acosd_dp(x)\n=======\n pure elemental module function acosd_dp(x)\n>>>>>>> upstream/master\n real(dp),intent(in)::x\n real(dp)::acosd_dp\n end function\n<<<<<<< HEAD\n pure elemental module function acosd_qp(x)\n=======\n pure elemental module function acosd_qp(x)\n>>>>>>> upstream/master\n real(qp),intent(in)::x\n real(qp)::acosd_qp\n end function\n end interface acosd\n\n interface asind\n<<<<<<< HEAD\n pure elemental module function asind_sp(x)\n=======\n pure elemental module function asind_sp(x)\n>>>>>>> upstream/master\n real(sp),intent(in)::x\n real(sp)::asind_sp\n end function\n<<<<<<< HEAD\n pure elemental module function asind_dp(x)\n=======\n pure elemental module function asind_dp(x)\n>>>>>>> upstream/master\n real(dp),intent(in)::x\n real(dp)::asind_dp\n end function\n<<<<<<< HEAD\n pure elemental module function asind_qp(x)\n=======\n pure elemental module function asind_qp(x)\n>>>>>>> upstream/master\n real(qp),intent(in)::x\n real(qp)::asind_qp\n end function\n end interface asind\n\n interface atand\n<<<<<<< HEAD\n pure elemental module function atand_sp(x)\n=======\n pure elemental module function atand_sp(x)\n>>>>>>> upstream/master\n real(sp),intent(in)::x\n real(sp)::atand_sp\n end function\n<<<<<<< HEAD\n pure elemental module function atand_dp(x)\n=======\n pure elemental module function atand_dp(x)\n>>>>>>> upstream/master\n real(dp),intent(in)::x\n real(dp)::atand_dp\n end function\n<<<<<<< HEAD\n pure elemental module function atand_qp(x)\n=======\n pure elemental module function atand_qp(x)\n>>>>>>> upstream/master\n real(qp),intent(in)::x\n real(qp)::atand_qp\n end function\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\n pure elemental module function cosd_dp(x)\n real(dp),intent(in)::x\n real(dp)::cosd_dp\n end function\n pure elemental module function cosd_qp(x)\n real(qp),intent(in)::x\n real(qp)::cosd_qp\n end function\n end interface cosd\n\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\n pure elemental module function sind_dp(x)\n real(dp),intent(in)::x\n real(dp)::sind_dp\n end function\n pure elemental module function sind_qp(x)\n real(qp),intent(in)::x\n real(qp)::sind_qp\n end function\n end interface sind\n\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\n pure elemental module function tand_dp(x)\n real(dp),intent(in)::x\n real(dp)::tand_dp\n end function\n pure elemental module function tand_qp(x)\n real(qp),intent(in)::x\n real(qp)::tand_qp\n end function\n end interface tand\n\n\n\n interface angle\n module procedure angle0, angle1\n end interface angle\n\n interface arange\n ! arange\n !-----------------------------------------------------------------------\n ! arange returns evenly spaced vector.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! x = arange(first, last)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! x = arange(first, last) returns an evenly spaced integer vector\n ! starting from first and ending at last.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! x = arange(1, 9) \n ! 1 2 3 4 5 6 7 8 9\n module function arange_int8 (first, last)\n integer(int8), dimension(:), allocatable :: arange_int8\n integer(int8), intent(in) :: first, last\n end function\n module function arange_int16 (first, last)\n integer(int16), dimension(:), allocatable :: arange_int16\n integer(int16), intent(in) :: first, last\n end function\n module function arange_int32 (first, last)\n integer(int32), dimension(:), allocatable :: arange_int32\n integer(int32), intent(in) :: first, last\n end function\n module function arange_int64 (first, last)\n integer(int64), dimension(:), allocatable :: arange_int64\n integer(int64), intent(in) :: first, last\n end function\n end interface\n\n interface argmax\n module procedure argmax1, argmax2, argmax3\n end interface argmax\n\n interface argmin\n module procedure argmin1, argmin2, argmin3\n end interface argmin\n\n interface bspline1\n module procedure bspline1_1\n end interface bspline1\n\n interface bspline2\n module procedure bspline2_2\n end interface bspline2\n\n interface chi2cdf\n module procedure chi2cdf0, chi2cdf1_0, chi2cdf1_1\n end interface chi2cdf\n\n interface chi2inv\n module procedure chi2inv0, chi2inv1_0, chi2inv1_1\n end interface chi2inv\n\n interface chi2pdf\n module procedure chi2pdf0, chi2pdf1_0, chi2pdf1_1\n end interface chi2pdf\n\n interface chi2rand\n module procedure chi2rand0, chi2rand1\n end interface chi2rand\n\n interface countlines\n module procedure countlines2\n end interface countlines\n\n interface cov\n module procedure cov1_1, cov1_2, cov2_1, cov2_2\n end interface cov\n\n interface cumsum\n module procedure cumsum1, cumsum2\n end interface cumsum\n\n interface datenum\n module procedure datenum0\n end interface datenum\n\n interface datestr\n module procedure datestr0_0\n end interface datestr\n\n interface datevec\n module procedure datevec0\n end interface datevec\n\n interface dbindex\n module procedure dbindex1, dbindex2\n end interface dbindex\n\n interface deg2utm\n module procedure deg2utm0, deg2utm1\n end interface deg2utm\n\n interface diag\n !! diag creates diagonal matrix or get the diagonal of a matrix.\n !!\n !! Syntax\n !!-----------------------------------------------------------------------\n !! x = diag(A) \n !! A = diag(x)\n !!\n !! Description\n !!-----------------------------------------------------------------------\n !! x = diag(A) returns the main diagonal of matrix A.\n !!\n !! A = diag(x) returns a square diagonal matrix with the elements of x on\n !! the main diagonal.\n !!\n !! Examples\n !!-----------------------------------------------------------------------\n !! A = eye(3) \n !! x = diag(A) \n !! 1. 1. 1.\n !!\n !! x = [ 1., 2., 3. ] \n !! A = diag(x) \n !! 1. 0. 0. \n !! 0. 2. 0. \n !! 0. 0. 3. \n module function diag1_sp (A)\n real(sp), dimension(:), allocatable :: diag1_sp\n real(sp), dimension(:, :), intent(in) :: A\n end function\n module function diag2_sp (x)\n real(sp), dimension(:, :), allocatable :: diag2_sp\n real(sp), dimension(:), intent(in) :: x\n end function\n module function diag1_dp (A)\n real(dp), dimension(:), allocatable :: diag1_dp\n real(dp), dimension(:, :), intent(in) :: A\n end function\n module function diag2_dp (x)\n real(dp), dimension(:, :), allocatable :: diag2_dp\n real(dp), dimension(:), intent(in) :: x\n end function\n module function diag1_qp (A)\n real(qp), dimension(:), allocatable :: diag1_qp\n real(qp), dimension(:, :), intent(in) :: A\n end function\n module function diag2_qp (x)\n real(qp), dimension(:, :), allocatable :: diag2_qp\n real(qp), dimension(:), intent(in) :: x\n end function\n end interface diag\n\n interface diff\n module procedure diff1, diff2\n end interface diff\n\n interface disp\n ! disp\n !-----------------------------------------------------------------------\n ! disp displays the value of a variable.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! call disp(x) \n ! call disp(x, string) \n ! call disp(A) \n ! call disp(A, string) \n ! call disp(X) \n ! call disp(X, 1) \n ! call disp(X, 1, string) \n ! call disp(X, 2) \n ! call disp(X, 2, string) \n ! call disp(X, 3) \n ! call disp(X, 3, string) \n !\n ! Description\n !-----------------------------------------------------------------------\n ! call disp(x) displays the scalar or the vector x.\n !\n ! call disp(x, string) displays the scalar or the vector x preceded by\n ! string.\n !\n ! call disp(A) displays the matrix A.\n !\n ! call disp(A, string) displays the matrix A preceded by string.\n !\n ! call disp(X) displays the 3-dimensional matrix X along the axis 1.\n !\n ! call disp(X, 1) (see call disp(X)).\n !\n ! call disp(X, 1, string) displays the 3-dimensional matrix X along the\n ! axis 1 preceded by string.\n !\n ! call disp(X, 2) displays the 3-dimensional matrix X along the axis 2.\n !\n ! call disp(X, 2, string) displays the 3-dimensional matrix X along the\n ! axis 2 preceded by string.\n !\n ! call disp(X, 3) displays the 3-dimensional matrix X along the axis 3.\n !\n ! call disp(X, 3, string) displays the 3-dimensional matrix X along the\n ! axis 3 preceded by string.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! x = [ 1. 2. 3. ] \n ! call disp(x) \n ! 1. \n ! 2. \n ! 3. \n ! call disp(x, \"x = \") \n ! x = \n ! 1. \n ! 2. \n ! 3.\n !\n ! A = reshape([ 1., 2., 3., 4., 5., 6., 7., 8., 9. ], [ 3, 3 ], & \n ! order = [ 2, 1 ]) \n ! call disp(A, \"Matrix A is\") \n ! Matrix A is \n ! 1. 2. 3. \n ! 4. 5. 6. \n ! 7. 8. 9. \n module subroutine disp_rsp0(x, string)\n real(sp), intent(in) :: x\n character(len=*), intent(in), optional :: string\n end subroutine\n\n module subroutine disp_rsp1(x, string)\n real(sp), dimension(:), intent(in) :: x\n character(len=*), intent(in), optional :: string\n end subroutine\n\n module subroutine disp_rsp2(A, string)\n real(sp), dimension(:, :), intent(in) :: A\n character(len=*), intent(in), optional :: string\n end subroutine\n\n module subroutine disp_rsp3(X, dim, string)\n real(sp), dimension(:, :, :), intent(in) :: X\n integer, intent(in), optional :: dim\n character(len=*), intent(in), optional :: string\n end subroutine\n module subroutine disp_rdp0(x, string)\n real(dp), intent(in) :: x\n character(len=*), intent(in), optional :: string\n end subroutine\n\n module subroutine disp_rdp1(x, string)\n real(dp), dimension(:), intent(in) :: x\n character(len=*), intent(in), optional :: string\n end subroutine\n\n module subroutine disp_rdp2(A, string)\n real(dp), dimension(:, :), intent(in) :: A\n character(len=*), intent(in), optional :: string\n end subroutine\n\n module subroutine disp_rdp3(X, dim, string)\n real(dp), dimension(:, :, :), intent(in) :: X\n integer, intent(in), optional :: dim\n character(len=*), intent(in), optional :: string\n end subroutine\n module subroutine disp_rqp0(x, string)\n real(qp), intent(in) :: x\n character(len=*), intent(in), optional :: string\n end subroutine\n\n module subroutine disp_rqp1(x, string)\n real(qp), dimension(:), intent(in) :: x\n character(len=*), intent(in), optional :: string\n end subroutine\n\n module subroutine disp_rqp2(A, string)\n real(qp), dimension(:, :), intent(in) :: A\n character(len=*), intent(in), optional :: string\n end subroutine\n\n module subroutine disp_rqp3(X, dim, string)\n real(qp), dimension(:, :, :), intent(in) :: X\n integer, intent(in), optional :: dim\n character(len=*), intent(in), optional :: string\n end subroutine\n module subroutine disp_csp0(x, string)\n complex(sp), intent(in) :: x\n character(len=*), intent(in), optional :: string\n end subroutine\n\n module subroutine disp_csp1(x, string)\n complex(sp), dimension(:), intent(in) :: x\n character(len=*), intent(in), optional :: string\n end subroutine\n module subroutine disp_csp2(A, string)\n complex(sp), dimension(:, :), intent(in) :: A\n character(len=*), intent(in), optional :: string\n end subroutine\n module subroutine disp_cdp0(x, string)\n complex(dp), intent(in) :: x\n character(len=*), intent(in), optional :: string\n end subroutine\n\n module subroutine disp_cdp1(x, string)\n complex(dp), dimension(:), intent(in) :: x\n character(len=*), intent(in), optional :: string\n end subroutine\n module subroutine disp_cdp2(A, string)\n complex(dp), dimension(:, :), intent(in) :: A\n character(len=*), intent(in), optional :: string\n end subroutine\n module subroutine disp_cqp0(x, string)\n complex(qp), intent(in) :: x\n character(len=*), intent(in), optional :: string\n end subroutine\n\n module subroutine disp_cqp1(x, string)\n complex(qp), dimension(:), intent(in) :: x\n character(len=*), intent(in), optional :: string\n end subroutine\n module subroutine disp_cqp2(A, string)\n complex(qp), dimension(:, :), intent(in) :: A\n character(len=*), intent(in), optional :: string\n end subroutine\n module subroutine disp_l0(x, string)\n logical, intent(in) :: x\n character(len=*), intent(in), optional :: string\n end subroutine\n module subroutine disp_l1(x, string)\n logical, dimension(:), intent(in) :: x\n character(len=*), intent(in), optional :: string\n end subroutine disp_l1\n module subroutine disp_l2(A, string)\n logical, dimension(:, :), intent(in) :: A\n character(len=*), intent(in), optional :: string\n end subroutine disp_l2\n module subroutine disp_iint80(x, string)\n integer(int8), intent(in) :: x\n character(len=*), intent(in), optional :: string\n end subroutine\n module subroutine disp_iint81(x, string)\n integer(int8), dimension(:), intent(in) :: x\n character(len=*), intent(in), optional :: string\n end subroutine\n module subroutine disp_iint82(A, string)\n integer(int8), dimension(:, :), intent(in) :: A\n character(len=*), intent(in), optional :: string\n end subroutine\n module subroutine disp_iint83(X, dim, string)\n integer(int8), dimension(:, :, :), intent(in) :: X\n integer, intent(in), optional :: dim\n !! \\fixme: dim precision\n character(len=*), intent(in), optional :: string\n end subroutine\n module subroutine disp_iint160(x, string)\n integer(int16), intent(in) :: x\n character(len=*), intent(in), optional :: string\n end subroutine\n module subroutine disp_iint161(x, string)\n integer(int16), dimension(:), intent(in) :: x\n character(len=*), intent(in), optional :: string\n end subroutine\n module subroutine disp_iint162(A, string)\n integer(int16), dimension(:, :), intent(in) :: A\n character(len=*), intent(in), optional :: string\n end subroutine\n module subroutine disp_iint163(X, dim, string)\n integer(int16), dimension(:, :, :), intent(in) :: X\n integer, intent(in), optional :: dim\n !! \\fixme: dim precision\n character(len=*), intent(in), optional :: string\n end subroutine\n module subroutine disp_iint320(x, string)\n integer(int32), intent(in) :: x\n character(len=*), intent(in), optional :: string\n end subroutine\n module subroutine disp_iint321(x, string)\n integer(int32), dimension(:), intent(in) :: x\n character(len=*), intent(in), optional :: string\n end subroutine\n module subroutine disp_iint322(A, string)\n integer(int32), dimension(:, :), intent(in) :: A\n character(len=*), intent(in), optional :: string\n end subroutine\n module subroutine disp_iint323(X, dim, string)\n integer(int32), dimension(:, :, :), intent(in) :: X\n integer, intent(in), optional :: dim\n !! \\fixme: dim precision\n character(len=*), intent(in), optional :: string\n end subroutine\n module subroutine disp_iint640(x, string)\n integer(int64), intent(in) :: x\n character(len=*), intent(in), optional :: string\n end subroutine\n module subroutine disp_iint641(x, string)\n integer(int64), dimension(:), intent(in) :: x\n character(len=*), intent(in), optional :: string\n end subroutine\n module subroutine disp_iint642(A, string)\n integer(int64), dimension(:, :), intent(in) :: A\n character(len=*), intent(in), optional :: string\n end subroutine\n module subroutine disp_iint643(X, dim, string)\n integer(int64), dimension(:, :, :), intent(in) :: X\n integer, intent(in), optional :: dim\n !! \\fixme: dim precision\n character(len=*), intent(in), optional :: string\n end subroutine\n module subroutine disp_str(string)\n character(len=*), intent(in), optional :: string\n end subroutine\n end interface\n\n interface empty\n !! Create uninitialized matrices quickly, faster than `ones` function,\n !! and use `empty` function with caution.\n !!\n !! Example\n !! ---\n !! real, allocatable :: x(:, :)\n !! x = empty(2, 3)\n module function empty_1_default (dim1)\n integer, intent(in) :: dim1\n real(dp), allocatable :: empty_1_default (:)\n end function\n\n module function empty_2_default (dim1, dim2)\n integer, intent(in) :: dim1, dim2\n real(dp), allocatable :: empty_2_default (:,:)\n end function\n\n module function empty_3_default (dim1, dim2, dim3)\n integer, intent(in) :: dim1, dim2, dim3\n real(dp), allocatable :: empty_3_default (:,:,:)\n end function\n\n module function empty_1_sp (dim1, flag)\n integer, intent(in) :: dim1\n real(sp), allocatable :: empty_1_sp (:)\n real(sp), intent(in) :: flag\n end function\n\n module function empty_1_dp (dim1, flag)\n integer, intent(in) :: dim1\n real(dp), allocatable :: empty_1_dp (:)\n real(dp), intent(in) :: flag\n end function\n\n module function empty_1_qp (dim1, flag)\n integer, intent(in) :: dim1\n real(qp), allocatable :: empty_1_qp (:)\n real(qp), intent(in) :: flag\n end function\n\n module function empty_2_sp (dim1, dim2, flag)\n integer, intent(in) :: dim1, dim2\n real(sp), allocatable :: empty_2_sp (:,:)\n real(sp), intent(in) :: flag\n end function\n\n module function empty_2_dp (dim1, dim2, flag)\n integer, intent(in) :: dim1, dim2\n real(dp), allocatable :: empty_2_dp (:,:)\n real(dp), intent(in) :: flag\n end function\n\n module function empty_2_qp (dim1, dim2, flag)\n integer, intent(in) :: dim1, dim2\n real(qp), allocatable :: empty_2_qp (:,:)\n real(qp), intent(in) :: flag\n end function\n\n module function empty_3_sp (dim1, dim2, dim3, flag)\n integer, intent(in) :: dim1, dim2, dim3\n real(sp), allocatable :: empty_3_sp (:,:,:)\n real(sp), intent(in) :: flag\n end function\n\n module function empty_3_dp (dim1, dim2, dim3, flag)\n integer, intent(in) :: dim1, dim2, dim3\n real(dp), allocatable :: empty_3_dp (:,:,:)\n real(dp), intent(in) :: flag\n end function\n\n module function empty_3_qp (dim1, dim2, dim3, flag)\n integer, intent(in) :: dim1, dim2, dim3\n real(qp), allocatable :: empty_3_qp (:,:,:)\n real(qp), intent(in) :: flag\n end function\n\n end interface\n\n interface eye\n !! Version: experimental\n !!\n !! eye creates the identity matrix.\n !!\n !!## Syntax\n !! I = eye(dim1)\n !! I = eye(dim1, dim2)\n !!\n !!## Description\n !! `I = eye(dim1)` returns an dim1-by-dim1 matrix with ones on the main\n !! diagonal and zeros elsewhere. \n !! `I = eye(dim1, dim2)` returns a dim1-by-dim2 matrix with ones on the\n !! main diagonal and zeros elsewhere.\n !!\n !!## Examples\n !! I = eye(3) \n !! 1. 0. 0. \n !! 0. 1. 0. \n !! 0. 0. 1.\n !!\n !! I = eye(3, 4) \n !! 1. 0. 0. 0. \n !! 0. 1. 0. 0. \n !! 0. 0. 1. 0.\n !!\n !! I = eye(4, 3) \n !! 1. 0. 0.\n !! 0. 1. 0.\n !! 0. 0. 1.\n !! 0. 0. 0. \n module function eye_1_default (dim1)\n real(dp), dimension(:, :), allocatable :: eye_1_default\n integer, intent(in) :: dim1\n end function\n\n module function eye_2_default (dim1, dim2)\n real(dp), dimension(:, :), allocatable :: eye_2_default\n integer, intent(in) :: dim1\n integer, intent(in) :: dim2\n end function\n module function eye_1_sp (dim1, flag)\n real(sp), dimension(:, :), allocatable :: eye_1_sp \n integer, intent(in) :: dim1\n real(sp), intent(in) :: flag\n\n end function\n\n module function eye_2_sp (dim1, dim2, flag)\n real(sp), dimension(:, :), allocatable :: eye_2_sp\n integer, intent(in) :: dim1\n integer, intent(in) :: dim2\n real(sp), intent(in) :: flag\n end function\n \n module function eye_1_dp (dim1, flag)\n real(dp), dimension(:, :), allocatable :: eye_1_dp \n integer, intent(in) :: dim1\n real(dp), intent(in) :: flag\n\n end function\n\n module function eye_2_dp (dim1, dim2, flag)\n real(dp), dimension(:, :), allocatable :: eye_2_dp\n integer, intent(in) :: dim1\n integer, intent(in) :: dim2\n real(dp), intent(in) :: flag\n end function\n \n module function eye_1_qp (dim1, flag)\n real(qp), dimension(:, :), allocatable :: eye_1_qp \n integer, intent(in) :: dim1\n real(qp), intent(in) :: flag\n\n end function\n\n module function eye_2_qp (dim1, dim2, flag)\n real(qp), dimension(:, :), allocatable :: eye_2_qp\n integer, intent(in) :: dim1\n integer, intent(in) :: dim2\n real(qp), intent(in) :: flag\n end function\n \n end interface\n \n interface file\n module procedure init_file\n end interface file\n\n interface find\n module procedure find1, find2, find3\n end interface find\n\n interface flip\n module procedure flip_i1, flip_r1, flip_i2, flip_r2, flip_i3, flip_r3\n end interface flip\n\n interface flipud\n module procedure flipud_i1, flipud_r1, flipud_i2, flipud_r2\n end interface flipud\n\n interface fliplr\n module procedure fliplr_i1, fliplr_r1, fliplr_i2, fliplr_r2\n end interface fliplr\n\n interface gammainc\n module procedure gammainc0, gammainc1_0\n end interface gammainc\n\n interface gmm\n module procedure gmm1, gmm2\n end interface gmm\n\n interface horzcat\n module procedure horzcat_i1, horzcat_r1, horzcat_i2, horzcat_r2, horzcat_i12, &\n horzcat_r12, horzcat_i21, horzcat_r21\n end interface horzcat\n\n interface interp1\n module procedure interp1_0, interp1_1\n end interface interp1\n\n interface interp2\n module procedure interp2_0, interp2_1, interp2_2\n end interface interp2\n\n interface interp3\n module procedure interp3_0, interp3_1\n end interface interp3\n\n interface inv\n !! Version: expermental\n !! inv computes the matrix inverse.\n !! inv0\n !!-----------------------------------------------------------------------\n !! inv0 computes the real matrix inverse.\n !!\n !! Syntax\n !!-----------------------------------------------------------------------\n !! B = inv0(A)\n !!\n !! Description\n !!-----------------------------------------------------------------------\n !! B = inv0(A) returns the inverse of the real matrix A if A is inversible\n !! (det(A) /= 0.).\n !!\n !! Examples\n !!-----------------------------------------------------------------------\n !! A = reshape([ 1., 2., 3., 4., 5., 6., 7., 8., 0. ], [ 3, 3 ], &\n !! order = [ 2, 1 ])\n !! B = inv0(A)\n !! -1.77777779 0.888888896 -0.111111112\n !! 1.55555558 -0.777777791 0.222222224\n !! -0.11111112 0.222222224 -0.111111112\n\n ! isleap\n !-----------------------------------------------------------------------\n ! isleap determines whether a year is a leap year.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! bool = isleap(year)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! bool = isleap(year) returns .true. if year is a leap year, .false.\n ! otherwise.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! bool = isleap(2016)\n ! .true.\n module function inv_rsp (A)\n real(sp), dimension(:, :), allocatable :: inv_rsp\n real(sp), dimension(:, :), intent(in) :: A\n end function\n module function inv_rdp (A)\n real(dp), dimension(:, :), allocatable :: inv_rdp\n real(dp), dimension(:, :), intent(in) :: A\n end function\n module function inv_rqp (A)\n real(qp), dimension(:, :), allocatable :: inv_rqp\n real(qp), dimension(:, :), intent(in) :: A\n end function\n module function inv_csp (A)\n complex(sp), dimension(:, :), allocatable :: inv_csp\n complex(sp), dimension(:, :), intent(in) :: A\n end function\n module function inv_cdp (A)\n complex(dp), dimension(:, :), allocatable :: inv_cdp\n complex(dp), dimension(:, :), intent(in) :: A\n end function\n module function inv_cqp (A)\n complex(qp), dimension(:, :), allocatable :: inv_cqp\n complex(qp), dimension(:, :), intent(in) :: A\n end function\n end interface inv\n\n interface operator(.i.)\n !! Calculate the inverse of a real matrix.\n !! Example\n !! ---\n !! inv_of_A = .i.A\n procedure inv_rsp\n procedure inv_rdp\n procedure inv_rqp\n\n procedure inv_csp\n procedure inv_cdp\n procedure inv_cqp\n end interface operator(.i.)\n\n interface operator(.x.)\n !! Version: expermental\n !! Real and complex matrix multiplication\n !!## Example\n !! z(1:2,1:2) = x(1:2, 1:3) .x. y(1:3, 1:2)\n module function rmut_sp(m1, m2) result(ret)\n real(sp), intent(in) :: m1(:, :), m2(:, :)\n real(sp) :: ret(size(m1, 1), size(m2, 2))\n end function\n\n module function cmut_sp(m1, m2) result(ret)\n complex(sp), intent(in) :: m1(:, :), m2(:, :)\n complex(sp) :: ret(size(m1, 1), size(m2, 2))\n end function\n\n module function rcmut_sp(m1, m2) result(ret)\n real(sp), intent(in) :: m1(:, :)\n complex(sp), intent(in) :: m2(:, :)\n complex(sp) :: ret(size(m1, 1), size(m2, 2))\n end function\n \n module function crmut_sp(m1, m2) result(ret)\n real(sp), intent(in) :: m2(:, :)\n complex(sp), intent(in) :: m1(:, :)\n complex(sp) :: ret(size(m1, 1), size(m2, 2))\n end function\n \n module function rmut_dp(m1, m2) result(ret)\n real(dp), intent(in) :: m1(:, :), m2(:, :)\n real(dp) :: ret(size(m1, 1), size(m2, 2))\n end function\n\n module function cmut_dp(m1, m2) result(ret)\n complex(dp), intent(in) :: m1(:, :), m2(:, :)\n complex(dp) :: ret(size(m1, 1), size(m2, 2))\n end function\n\n module function rcmut_dp(m1, m2) result(ret)\n real(dp), intent(in) :: m1(:, :)\n complex(dp), intent(in) :: m2(:, :)\n complex(dp) :: ret(size(m1, 1), size(m2, 2))\n end function\n \n module function crmut_dp(m1, m2) result(ret)\n real(dp), intent(in) :: m2(:, :)\n complex(dp), intent(in) :: m1(:, :)\n complex(dp) :: ret(size(m1, 1), size(m2, 2))\n end function\n \n module function rmut_qp(m1, m2) result(ret)\n real(qp), intent(in) :: m1(:, :), m2(:, :)\n real(qp) :: ret(size(m1, 1), size(m2, 2))\n end function\n\n module function cmut_qp(m1, m2) result(ret)\n complex(qp), intent(in) :: m1(:, :), m2(:, :)\n complex(qp) :: ret(size(m1, 1), size(m2, 2))\n end function\n\n module function rcmut_qp(m1, m2) result(ret)\n real(qp), intent(in) :: m1(:, :)\n complex(qp), intent(in) :: m2(:, :)\n complex(qp) :: ret(size(m1, 1), size(m2, 2))\n end function\n \n module function crmut_qp(m1, m2) result(ret)\n real(qp), intent(in) :: m2(:, :)\n complex(qp), intent(in) :: m1(:, :)\n complex(qp) :: ret(size(m1, 1), size(m2, 2))\n end function\n \n end interface\n\n interface ismember\n module procedure ismember_i0i1, ismember_i0r1, ismember_i0i2, &\n ismember_i0r2, ismember_i0i3, ismember_i0r3, ismember_r0i1, &\n ismember_r0r1, ismember_r0i2, ismember_r0r2, ismember_r0i3, &\n ismember_r0r3\n end interface ismember\n\n interface issquare\n !! Determine if it is a square matrix\n !!\n !! Ex:\n !! --------------------------------------\n !! A = eye(3) \n !! bool = issquare(A) \n !! .true. \n !! A = eye(3, 4) \n !! bool = issquare0(A) \n !! .false.\n logical module function issquare_rsp (A)\n ! import sp\n real(sp), dimension(:, :), intent(in) :: A\n end function\n logical module function issquare_rdp (A)\n ! import dp\n real(dp), dimension(:, :), intent(in) :: A\n end function\n logical module function issquare_rqp (A)\n ! import qp\n real(qp), dimension(:, :), intent(in) :: A\n end function\n logical module function issquare_csp (A)\n ! import sp\n complex(sp), dimension(:, :), intent(in) :: A\n end function\n logical module function issquare_cdp (A)\n ! import dp\n complex(dp), dimension(:, :), intent(in) :: A\n end function\n logical module function issquare_cqp (A)\n ! import qp\n complex(qp), dimension(:, :), intent(in) :: A\n end function\n end interface issquare\n\n interface kde\n module procedure kde1, kde2\n end interface kde\n\n interface kmeans\n module procedure kmeans1, kmeans2\n end interface kmeans\n\n interface kurtosis\n module procedure kurtosis1, kurtosis2\n end interface kurtosis\n\n interface linspace\n module procedure linspace_r8r8, linspace_r4r4, linspace_i4i4, &\n linspace_r8i4, linspace_r4i4, linspace_i4r8, linspace_i4r4\n end interface linspace\n\n interface loadbin\n module procedure loadbin0, loadbin1, loadbin2, loadbin3\n end interface loadbin\n\n interface loadtxt\n module procedure loadtxt1, loadtxt2\n end interface loadtxt\n\n interface log2\n module procedure log2_i0, log2_r0, log2_i1, log2_r1\n end interface log2\n\n interface lu\n !! lu computes the LU matrix factorization.\n !!\n !! Syntax\n !!-----------------------------------------------------------------------\n !! call lu(A, L, U) \n !!\n !! Description\n !!---------------------------------------------------------------------\n !! call lu(A, L, U) returns the LU matrix factorization of the input\n !! square m-by-m matrix A. The output matrices are: \n !! - L is a m-by-m lower triangular matrix with ones on the diagonal, \n !! - U is a m-by-m upper triangular matrix.\n !!\n !! Examples\n !!---------------------------------------------------------------------\n !! A = reshape([ 1., 2., 3., 4., 5., 6., 7., 8., 9. ], [ 3, 3 ], & \n !! order = [ 2, 1 ]) \n !! call lu(A, L, U) \n !! call disp(L) \n !! 1. 0. 0. \n !! 4. 1. 0. \n !! 7. 2. 1. \n !! call disp(U) \n !! 1. 2. 3. \n !! 0. -3. -6. \n !! 0. 0. 0. \n !! call disp(matmul(L, U)) \n !! 1. 2. 3. \n !! 4. 5. 6. \n !! 7. 8. 9. \n module subroutine lu_sp (A, L, U)\n real(sp), dimension(:, :), intent(in) :: A\n real(sp), dimension(:, :), allocatable, intent(out) :: L, U\n end subroutine\n module subroutine lu_dp (A, L, U)\n real(dp), dimension(:, :), intent(in) :: A\n real(dp), dimension(:, :), allocatable, intent(out) :: L, U\n end subroutine\n module subroutine lu_qp (A, L, U)\n real(qp), dimension(:, :), intent(in) :: A\n real(qp), dimension(:, :), allocatable, intent(out) :: L, U\n end subroutine\n end interface\n\n interface mad\n module procedure mad1, mad2\n end interface mad\n\n interface mbkmeans\n module procedure mbkmeans1, mbkmeans2\n end interface mbkmeans\n\n interface median\n module procedure median1, median2\n end interface median\n\n interface mean\n module procedure mean1, mean2\n end interface mean\n\n interface meshgrid\n module procedure meshgrid2\n end interface meshgrid\n\n interface nextpow2\n module procedure nextpow2_0, nextpow2_1\n end interface nextpow2\n\n interface norm\n module procedure norm1, norm2\n end interface norm\n\n interface normpdf\n module procedure normpdf0, normpdf1, normpdf2\n end interface normpdf\n\n interface num2str\n module procedure num2str_i4, num2str_i8, num2str_r4, num2str_r8\n end interface num2str\n\n interface ones\n module procedure ones1, ones2, ones3\n end interface ones\n\n interface prctile\n module procedure prctile0, prctile1\n end interface prctile\n\n interface randi\n module procedure randi0_0, randi0_1, randi1_0, randi1_1, randi2_0, &\n randi2_1, randi3_0, randi3_1\n end interface randi\n\n interface randu\n !! Version: experimental\n !!\n ! randu\n !-----------------------------------------------------------------------\n ! randu generates uniformly distributed random numbers.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! x = randu()\n ! x = randu(dim1)\n ! A = randu(dim1, dim2)\n ! X = randu(dim1, dim2, dim3)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! x = randu() returns a single uniformly distributed random number in\n ! the interval [0,1].\n !\n ! x = randu(dim1) returns a dim1 vector of uniformly distributed random\n ! numbers.\n !\n ! A = randu(dim1, dim2) returns a dim1-by-dim2 matrix of uniformly\n ! distributed random numbers.\n !\n ! X = randu(dim1, dim2, dim3) returns a dim1-by-dim2-by-dim3\n ! 3-dimensional matrix of uniformly distributed random numbers.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! x = randu()\n ! 0.383413825\n !\n ! x = randu(5)*2 - 1\n ! 0.640258908 -0.873707294 0.787327528\n !! Default versions\n module function randu_0_default ()\n real(dp) :: randu_0_default \n end function\n module function randu_1_default (dim1)\n integer, intent(in) :: dim1\n real(dp), allocatable :: randu_1_default (:)\n end function\n module function randu_2_default (dim1, dim2)\n integer, intent(in) :: dim1, dim2\n real(dp), allocatable :: randu_2_default (:,:)\n end function\n module function randu_3_default (dim1, dim2, dim3)\n integer, intent(in) :: dim1, dim2, dim3\n real(dp), allocatable :: randu_3_default (:,:,:)\n end function\n !! Multi-precision versions\n module function randu_0_sp (flag)\n real(sp) :: randu_0_sp \n real(sp), intent(in) :: flag\n end function\n module function randu_0_dp (flag)\n real(dp) :: randu_0_dp \n real(dp), intent(in) :: flag\n end function\n module function randu_0_qp (flag)\n real(qp) :: randu_0_qp \n real(qp), intent(in) :: flag\n end function\n module function randu_1_sp (dim1, flag)\n !! Unlike dynamic scripting languages, static languages generally\n !! have multiple precision variables, so we need to explicitly provide precision hints.\n integer, intent(in) :: dim1\n real(sp), allocatable :: randu_1_sp (:)\n real(sp), intent(in) :: flag\n end function\n module function randu_1_dp (dim1, flag)\n !! Unlike dynamic scripting languages, static languages generally\n !! have multiple precision variables, so we need to explicitly provide precision hints.\n integer, intent(in) :: dim1\n real(dp), allocatable :: randu_1_dp (:)\n real(dp), intent(in) :: flag\n end function\n module function randu_1_qp (dim1, flag)\n !! Unlike dynamic scripting languages, static languages generally\n !! have multiple precision variables, so we need to explicitly provide precision hints.\n integer, intent(in) :: dim1\n real(qp), allocatable :: randu_1_qp (:)\n real(qp), intent(in) :: flag\n end function\n module function randu_2_sp (dim1, dim2, flag)\n integer, intent(in) :: dim1, dim2\n real(sp), allocatable :: randu_2_sp (:,:)\n real(sp), intent(in) :: flag\n end function\n module function randu_2_dp (dim1, dim2, flag)\n integer, intent(in) :: dim1, dim2\n real(dp), allocatable :: randu_2_dp (:,:)\n real(dp), intent(in) :: flag\n end function\n module function randu_2_qp (dim1, dim2, flag)\n integer, intent(in) :: dim1, dim2\n real(qp), allocatable :: randu_2_qp (:,:)\n real(qp), intent(in) :: flag\n end function\n module function randu_3_sp (dim1, dim2, dim3, flag)\n integer, intent(in) :: dim1, dim2, dim3\n real(sp), allocatable :: randu_3_sp (:,:,:)\n real(sp), intent(in) :: flag\n end function\n module function randu_3_dp (dim1, dim2, dim3, flag)\n integer, intent(in) :: dim1, dim2, dim3\n real(dp), allocatable :: randu_3_dp (:,:,:)\n real(dp), intent(in) :: flag\n end function\n module function randu_3_qp (dim1, dim2, dim3, flag)\n integer, intent(in) :: dim1, dim2, dim3\n real(qp), allocatable :: randu_3_qp (:,:,:)\n real(qp), intent(in) :: flag\n end function\n end interface\n\n interface randn\n !! Version: experimental\n !!\n ! randn\n !-----------------------------------------------------------------------\n ! randn generates normally distributed random numbers using polar\n ! Box-Muller algorithm.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! x = randn()\n ! x = randn(dim1)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! x = randn() returns a single normally distributed random number with\n ! mean 0 and standard deviation 1.\n !\n ! x = randn(dim1) returns a dim1 vector of normally distributed random\n ! numbers.\n !\n ! A = randn(dim1, dim2) returns a dim1-by-dim2 matrix of normally\n ! distributed random numbers.\n !\n ! X = randn(dim1, dim2, dim3) returns a dim1-by-dim2-by-dim3\n ! 3-dimensional matrix of normally distributed random numbers.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! x = randn(3)\n ! -1.22003853 -0.211721316 0.522971511\n !! Default versions\n module function randn_0_default ()\n real(dp) :: randn_0_default \n end function\n module function randn_1_default (dim1)\n integer, intent(in) :: dim1\n real(dp), allocatable :: randn_1_default (:)\n end function\n module function randn_2_default (dim1, dim2)\n integer, intent(in) :: dim1, dim2\n real(dp), allocatable :: randn_2_default (:,:)\n end function\n module function randn_3_default (dim1, dim2, dim3)\n integer, intent(in) :: dim1, dim2, dim3\n real(dp), allocatable :: randn_3_default (:,:,:)\n end function\n !! Multi-precision versions\n module function randn_0_sp (flag)\n real(sp) :: randn_0_sp \n real(sp), intent(in) :: flag\n end function\n module function randn_0_dp (flag)\n real(dp) :: randn_0_dp \n real(dp), intent(in) :: flag\n end function\n module function randn_0_qp (flag)\n real(qp) :: randn_0_qp \n real(qp), intent(in) :: flag\n end function\n module function randn_1_sp (dim1, flag)\n !! Unlike dynamic scripting languages, static languages generally\n !! have multiple precision variables, so we need to explicitly provide precision hints.\n integer, intent(in) :: dim1\n real(sp), allocatable :: randn_1_sp (:)\n real(sp), intent(in) :: flag\n end function\n module function randn_1_dp (dim1, flag)\n !! Unlike dynamic scripting languages, static languages generally\n !! have multiple precision variables, so we need to explicitly provide precision hints.\n integer, intent(in) :: dim1\n real(dp), allocatable :: randn_1_dp (:)\n real(dp), intent(in) :: flag\n end function\n module function randn_1_qp (dim1, flag)\n !! Unlike dynamic scripting languages, static languages generally\n !! have multiple precision variables, so we need to explicitly provide precision hints.\n integer, intent(in) :: dim1\n real(qp), allocatable :: randn_1_qp (:)\n real(qp), intent(in) :: flag\n end function\n module function randn_2_sp (dim1, dim2, flag)\n integer, intent(in) :: dim1, dim2\n real(sp), allocatable :: randn_2_sp (:,:)\n real(sp), intent(in) :: flag\n end function\n module function randn_2_dp (dim1, dim2, flag)\n integer, intent(in) :: dim1, dim2\n real(dp), allocatable :: randn_2_dp (:,:)\n real(dp), intent(in) :: flag\n end function\n module function randn_2_qp (dim1, dim2, flag)\n integer, intent(in) :: dim1, dim2\n real(qp), allocatable :: randn_2_qp (:,:)\n real(qp), intent(in) :: flag\n end function\n module function randn_3_sp (dim1, dim2, dim3, flag)\n integer, intent(in) :: dim1, dim2, dim3\n real(sp), allocatable :: randn_3_sp (:,:,:)\n real(sp), intent(in) :: flag\n end function\n module function randn_3_dp (dim1, dim2, dim3, flag)\n integer, intent(in) :: dim1, dim2, dim3\n real(dp), allocatable :: randn_3_dp (:,:,:)\n real(dp), intent(in) :: flag\n end function\n module function randn_3_qp (dim1, dim2, dim3, flag)\n integer, intent(in) :: dim1, dim2, dim3\n real(qp), allocatable :: randn_3_qp (:,:,:)\n real(qp), intent(in) :: flag\n end function\n end interface\n\n interface repmat\n module procedure repmat1, repmat2\n end interface repmat\n\n interface rms\n module procedure rms1, rms2\n end interface rms\n\n interface savebin\n !! Version: expermental\n !!\n ! savebin saves arrays to binary files.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! call savebin(filename, x)\n ! call savebin(filename, A)\n ! call savebin(filename, X)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! call savebin(filename, x) saves a vector x into the binary file\n ! filename.\n !\n ! call savebin(filename, A) saves a 2-dimensional array into the binary\n ! file filename.\n !\n ! call savebin(filename, X) saves a 3-dimensional array into the binary\n ! file filename.\n module subroutine savebin_1_sp(filename, x)\n character(len=*), intent(in) :: filename\n real(sp), dimension(:), intent(in) :: x\n end subroutine\n\n module subroutine savebin_2_sp(filename, A)\n character(len=*), intent(in) :: filename\n real(sp), dimension(:, :), intent(in) :: A\n end subroutine\n\n module subroutine savebin_3_sp(filename, X)\n character(len=*), intent(in) :: filename\n real(sp), dimension(:, :, :), intent(in) :: X\n end subroutine\n\n module subroutine savebin_1_dp(filename, x)\n character(len=*), intent(in) :: filename\n real(dp), dimension(:), intent(in) :: x\n end subroutine\n\n module subroutine savebin_2_dp(filename, A)\n character(len=*), intent(in) :: filename\n real(dp), dimension(:, :), intent(in) :: A\n end subroutine\n\n module subroutine savebin_3_dp(filename, X)\n character(len=*), intent(in) :: filename\n real(dp), dimension(:, :, :), intent(in) :: X\n end subroutine\n\n module subroutine savebin_1_qp(filename, x)\n character(len=*), intent(in) :: filename\n real(qp), dimension(:), intent(in) :: x\n end subroutine\n\n module subroutine savebin_2_qp(filename, A)\n character(len=*), intent(in) :: filename\n real(qp), dimension(:, :), intent(in) :: A\n end subroutine\n\n module subroutine savebin_3_qp(filename, X)\n character(len=*), intent(in) :: filename\n real(qp), dimension(:, :, :), intent(in) :: X\n end subroutine\n\n end interface savebin\n\n interface savetxt\n !! Version: expermental\n !!\n ! savetxt saves 1 and 2-dimensional arrays to txt files.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! call savetxt(filename, x)\n ! call savetxt(filename, A)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! call savetxt(filename, x) saves a vector array x into the txt file\n ! filename.\n !\n ! call savetxt(filename, A) saves a 2-dimensional array A into the txt\n ! file filename.\n module subroutine savetxt_1_sp(filename, x)\n character(len=*), intent(in) :: filename\n real(sp), dimension(:), intent(in) :: x\n end subroutine\n\n module subroutine savetxt_2_sp(filename, A)\n character(len=*), intent(in) :: filename\n real(sp), dimension(:, :), intent(in) :: A\n end subroutine\n\n module subroutine savetxt_1_dp(filename, x)\n character(len=*), intent(in) :: filename\n real(dp), dimension(:), intent(in) :: x\n end subroutine\n\n module subroutine savetxt_2_dp(filename, A)\n character(len=*), intent(in) :: filename\n real(dp), dimension(:, :), intent(in) :: A\n end subroutine\n\n module subroutine savetxt_1_qp(filename, x)\n character(len=*), intent(in) :: filename\n real(qp), dimension(:), intent(in) :: x\n end subroutine\n\n module subroutine savetxt_2_qp(filename, A)\n character(len=*), intent(in) :: filename\n real(qp), dimension(:, :), intent(in) :: A\n end subroutine\n\n !! Integer Versions\n module subroutine savetxt_1_int8(filename, x)\n character(len=*), intent(in) :: filename\n integer(int8), dimension(:), intent(in) :: x\n end subroutine\n\n module subroutine savetxt_2_int8(filename, A)\n character(len=*), intent(in) :: filename\n integer(int8), dimension(:, :), intent(in) :: A\n end subroutine\n\n module subroutine savetxt_1_int16(filename, x)\n character(len=*), intent(in) :: filename\n integer(int16), dimension(:), intent(in) :: x\n end subroutine\n\n module subroutine savetxt_2_int16(filename, A)\n character(len=*), intent(in) :: filename\n integer(int16), dimension(:, :), intent(in) :: A\n end subroutine\n\n module subroutine savetxt_1_int32(filename, x)\n character(len=*), intent(in) :: filename\n integer(int32), dimension(:), intent(in) :: x\n end subroutine\n\n module subroutine savetxt_2_int32(filename, A)\n character(len=*), intent(in) :: filename\n integer(int32), dimension(:, :), intent(in) :: A\n end subroutine\n\n module subroutine savetxt_1_int64(filename, x)\n character(len=*), intent(in) :: filename\n integer(int64), dimension(:), intent(in) :: x\n end subroutine\n\n module subroutine savetxt_2_int64(filename, A)\n character(len=*), intent(in) :: filename\n integer(int64), dimension(:, :), intent(in) :: A\n end subroutine\n\n end interface\n\n interface signum\n module procedure signum0, signum1, signum2\n end interface signum\n\n interface sinc\n module procedure sinc0, sinc1\n end interface sinc\n\n interface silhouette\n module procedure silhouette1, silhouette2\n end interface silhouette\n\n interface skewness\n module procedure skewness1, skewness2\n end interface skewness\n\n interface spline1\n module procedure spline1_0, spline1_1\n end interface spline1\n\n interface spline2\n module procedure spline2_1, spline2_2\n end interface spline2\n\n interface std\n module procedure std1, std2\n end interface std\n\n interface tril\n module procedure tril_i, tril_r, tril_c\n end interface tril\n\n interface triu\n module procedure triu_i, triu_r, triu_c\n end interface triu\n\n interface utm2deg\n module procedure utm2deg0, utm2deg1\n end interface utm2deg\n\n interface var\n module procedure var1, var2\n end interface var\n\n interface vertcat\n module procedure vertcat_r1, vertcat_r2, vertcat_c2, vertcat_r12, &\n vertcat_r21\n end interface vertcat\n\n interface zeros\n !! Version: experimental\n !!\n !! zeros creates array all of zeros.\n !!\n !! Syntax\n !!-----------------------------------------------------------------------\n !! Default version Multi-precision version\n !! x = zeros(dim1) or x = zeros(dim1, flag) \n !! A = zeros(dim1, dim2) A = zeros(dim1, dim2, flag)\n !! X = zeros(dim1, dim2, dim3) X = zeros(dim1, dim2, dim3, flag)\n !! \n !! Description\n !!-----------------------------------------------------------------------\n !! The precision of the flag variable should be consistent with \n !! the return value of the function. \n !! Unlike dynamic scripting languages, static languages generally\n !! have multiple precision variables, so we need to explicitly provide precision hints.\n !!\n !! x = zeros(dim1) returns a dim1 vector of zeros.\n !!\n !! A = zeros(dim1, dim2) returns a dim1-by-dim2 matrix of zeros.\n !!\n !! X = zeros(dim1, dim2, dim3) returns a dim1-by-dim2-by-dim3\n !! 3-dimensional matrix of zeros.\n !!\n !! Examples\n !!-----------------------------------------------------------------------\n !! x = zeros(3) \n !! x = \n !! 0. 0. 0. \n !!\n !! A = zeros(3, 3) \n !! A = \n !! 0. 0. 0. \n !! 0. 0. 0. \n !! 0. 0. 0.\n module function zeros_1_default (dim1)\n integer, intent(in) :: dim1\n real(dp), allocatable :: zeros_1_default (:)\n end function\n module function zeros_2_default (dim1, dim2)\n integer, intent(in) :: dim1, dim2\n real(dp), allocatable :: zeros_2_default (:,:)\n end function\n module function zeros_3_default (dim1, dim2, dim3)\n integer, intent(in) :: dim1, dim2, dim3\n real(dp), allocatable :: zeros_3_default (:,:,:)\n end function\n\n module function zeros_1_sp (dim1, flag)\n integer, intent(in) :: dim1\n real(sp), allocatable :: zeros_1_sp (:)\n real(sp), intent(in) :: flag\n end function\n module function zeros_1_dp (dim1, flag)\n integer, intent(in) :: dim1\n real(dp), allocatable :: zeros_1_dp (:)\n real(dp), intent(in) :: flag\n end function\n module function zeros_1_qp (dim1, flag)\n integer, intent(in) :: dim1\n real(qp), allocatable :: zeros_1_qp (:)\n real(qp), intent(in) :: flag\n end function\n module function zeros_2_sp (dim1, dim2, flag)\n integer, intent(in) :: dim1, dim2\n real(sp), allocatable :: zeros_2_sp (:,:)\n real(sp), intent(in) :: flag\n end function\n module function zeros_2_dp (dim1, dim2, flag)\n integer, intent(in) :: dim1, dim2\n real(dp), allocatable :: zeros_2_dp (:,:)\n real(dp), intent(in) :: flag\n end function\n module function zeros_2_qp (dim1, dim2, flag)\n integer, intent(in) :: dim1, dim2\n real(qp), allocatable :: zeros_2_qp (:,:)\n real(qp), intent(in) :: flag\n end function\n module function zeros_3_sp (dim1, dim2, dim3, flag)\n integer, intent(in) :: dim1, dim2, dim3\n real(sp), allocatable :: zeros_3_sp (:,:,:)\n real(sp), intent(in) :: flag\n end function\n module function zeros_3_dp (dim1, dim2, dim3, flag)\n integer, intent(in) :: dim1, dim2, dim3\n real(dp), allocatable :: zeros_3_dp (:,:,:)\n real(dp), intent(in) :: flag\n end function\n module function zeros_3_qp (dim1, dim2, dim3, flag)\n integer, intent(in) :: dim1, dim2, dim3\n real(qp), allocatable :: zeros_3_qp (:,:,:)\n real(qp), intent(in) :: flag\n end function\n end interface\n\n !! Normal Interfaces\n interface\n module subroutine rng(seed) \n !! Version: experimental\n !!\n ! rng\n !-----------------------------------------------------------------------\n ! rng controls random number generation.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! call rng()\n ! call rng(seed)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! call rng() uses the current date and time as seed for random number\n ! generation.\n !\n ! call rng(seed) sets the input seed for random number generation.\n !\n ! Notes\n !-----------------------------------------------------------------------\n ! It is advised to call rng at the beginning of a program so that each\n ! run of the program produces different sequences of random numbers.\n integer, intent(in), optional :: seed\n end subroutine rng\n end interface\ncontains\n\n\n ! angle\n !-----------------------------------------------------------------------\n ! angle compute the phase angle.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! p = angle(z)\n ! P = angle(Z)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! p = angle(z) returns the phase angle in radians of the complex\n ! number z.\n !\n ! P = angle(Z) returns the phase angles in radians of each complex\n ! numbers in vector Z.\n\n real(kind=RPRE) function angle0(z)\n complex(kind=RPRE), intent(in) :: z\n\n angle0 = imag(log(z))\n return\n end function angle0\n\n function angle1(Z)\n real(kind=RPRE), dimension(:), allocatable :: angle1\n complex(kind=RPRE), dimension(:), intent(in) :: Z\n integer(kind=IPRE) :: i, n\n\n n = size(Z)\n angle1 = zeros(n)\n do i = 1, n\n angle1(i) = angle0(Z(i))\n end do\n return\n end function angle1\n\n ! argmax\n !-----------------------------------------------------------------------\n ! argmax computes the indices of the maximum value of an array.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! y = argmax(x)\n ! y = argmax(A)\n ! y = argmax(X)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! y = argmax(x) returns the index of the maximum value of the vector x.\n !\n ! y = argmax(A) returns a 2-elements vector with the indices of the\n ! maximum value of the matrix A.\n !\n ! y = argmax(X) returns a 3-elements vector with the indices of the\n ! maximum value of the 3-dimensional matrix X.\n !\n ! Notes\n !-----------------------------------------------------------------------\n ! argmax ignores NaN values.\n\n integer(kind=IPRE) function argmax1(x)\n real(kind=RPRE), dimension(:), intent(in) :: x\n\n argmax1 = maxloc(x, 1,.not. isnan(x))\n return\n end function argmax1\n\n function argmax2(A)\n integer(kind=IPRE) :: argmax2(2)\n real(kind=IPRE), dimension(:, :), intent(in) :: A\n\n argmax2 = maxloc(A,.not. isnan(A))\n return\n end function argmax2\n\n function argmax3(X)\n integer(kind=IPRE) :: argmax3(3)\n real(kind=IPRE), dimension(:, :, :), intent(in) :: X\n\n argmax3 = maxloc(X,.not. isnan(X))\n return\n end function argmax3\n\n ! argmin\n !-----------------------------------------------------------------------\n ! argmin computes the indices of the minimum value of an array.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! y = argmin(x)\n ! y = argmin(A)\n ! y = argmin(X)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! y = argmin(x) returns the index of the minimum value of the vector x.\n !\n ! y = argmin(A) returns a 2-elements vector with the indices of the\n ! minimum value of the matrix A.\n !\n ! y = argmin(X) returns a 3-elements vector with the indices of the\n ! minimum value of the 3-dimensional matrix X.\n !\n ! Notes\n !-----------------------------------------------------------------------\n ! argmin ignores NaN values.\n\n integer(kind=IPRE) function argmin1(x)\n real(kind=RPRE), dimension(:), intent(in) :: x\n\n argmin1 = minloc(x, 1,.not. isnan(x))\n return\n end function argmin1\n\n function argmin2(A)\n integer(kind=IPRE) :: argmin2(2)\n real(kind=IPRE), dimension(:, :), intent(in) :: A\n\n argmin2 = minloc(A,.not. isnan(A))\n return\n end function argmin2\n\n function argmin3(X)\n integer(kind=IPRE) :: argmin3(3)\n real(kind=IPRE), dimension(:, :, :), intent(in) :: X\n\n argmin3 = minloc(X,.not. isnan(X))\n return\n end function argmin3\n\n ! argsort\n !-----------------------------------------------------------------------\n ! argsort generates the indices that would sort an array.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! y = argsort(x)\n ! y = argsort(x, 1)\n ! y = argsort(x, 2)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! y = argsort(x) returns the indices that would sort an array in\n ! ascending order.\n !\n ! y = argsort(x, 1) (see y = argsort(x)).\n !\n ! y = argsort(x, 2) returns the indices that would sort an array in\n ! descending order.\n !\n ! Notes\n !-----------------------------------------------------------------------\n ! x(argsort(x), order) returns the same result as sort(x, order).\n\n function argsort(x, order)\n integer(kind=IPRE), dimension(:), allocatable :: argsort\n real(kind=RPRE), dimension(:), intent(in) :: x\n integer(kind=IPRE), intent(in), optional :: order\n integer(kind=IPRE) :: i, n\n real(kind=RPRE), dimension(:), allocatable :: xsort\n\n n = size(x)\n xsort = x\n argsort = [(i, i=1, n)]\n if ((.not. present(order)) .or. (order .eq. 1)) then\n call quickargsort(xsort, argsort, n, 1)\n elseif (order .eq. 2) then\n call quickargsort(xsort, argsort, n, 2)\n end if\n return\n\n contains\n\n !-------------------------------------------------------------------\n ! quickargsort\n !-------------------------------------------------------------------\n recursive subroutine quickargsort(x, idx, n, order)\n real(kind=RPRE), dimension(n), intent(inout) :: x\n integer(kind=IPRE), dimension(n), intent(inout) :: idx\n integer(kind=IPRE), intent(in) :: n, order\n integer(kind=IPRE) :: left, right, marker\n real(kind=RPRE) :: pivot, tmp\n\n if (n .gt. 1) then\n left = 0\n right = n + 1\n pivot = x(randi(n))\n\n select case (order)\n case (1)\n do while (left .lt. right)\n left = left + 1\n right = right - 1\n do while (x(left) .lt. pivot)\n left = left + 1\n end do\n do while (x(right) .gt. pivot)\n right = right - 1\n end do\n if (left .lt. right) then\n tmp = x(left)\n x(left) = x(right)\n x(right) = tmp\n tmp = idx(left)\n idx(left) = idx(right)\n idx(right) = tmp\n end if\n end do\n case (2)\n do while (left .lt. right)\n left = left + 1\n right = right - 1\n do while (x(left) .gt. pivot)\n left = left + 1\n end do\n do while (x(right) .lt. pivot)\n right = right - 1\n end do\n if (left .lt. right) then\n tmp = x(left)\n x(left) = x(right)\n x(right) = tmp\n tmp = idx(left)\n idx(left) = idx(right)\n idx(right) = tmp\n end if\n end do\n end select\n\n if (left .eq. right) then\n marker = left + 1\n else\n marker = left\n end if\n\n call quickargsort(x(:marker - 1), idx(:marker - 1), marker - 1, order)\n call quickargsort(x(marker:), idx(marker:), n - marker + 1, order)\n end if\n return\n end subroutine quickargsort\n\n end function argsort\n\n ! bsplrep1\n !-----------------------------------------------------------------------\n ! bsplrep1 computes the B-spline representation C(t) of a set of\n ! 1-dimensional control points with a uniform knot vector.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! call bsplrep1(x, y, xq, yq)\n ! call bsplrep1(x, y, xq, yq, order)\n ! call bsplrep1(x, y, xq, yq, order, n1)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! call bsplrep1(x, y, xq, yq) returns the B-spline representation C(t)\n ! given the control points defined by x and y using a cubic spline\n ! (order 4 / degree 3).\n !\n ! call bsplrep1(x, y, xq, yq, order) returns the B-spline representation\n ! C(t) given the control points defined by x and y and the order.\n !\n ! call bsplrep1(x, y, xq, yq, order, n1) returns the n1-points B-spline\n ! representation C(t) given the control points defined by x and y, and\n ! the order.\n\n subroutine bsplrep1(x, y, xq, yq, order, n1)\n real(kind=RPRE), dimension(:), intent(in) :: x, y\n real(kind=RPRE), dimension(:), allocatable, intent(out) :: xq, yq\n integer(kind=IPRE), intent(in), optional :: order, n1\n integer(kind=IPRE) :: opt_n1, i, iq, j, k, n\n real(kind=RPRE) :: w\n integer(kind=IPRE), dimension(:), allocatable :: x0\n real(kind=RPRE), dimension(:), allocatable :: t, y1\n\n n = size(x)\n k = 4\n opt_n1 = 100\n if (present(order)) k = order\n if (present(n1)) opt_n1 = n1\n\n if (k .gt. n) then\n print *, \"Error: in bsplrep1, order k should be less than the \" &\n //\"number of control points (\"//num2str(k)//\" > \" &\n //num2str(n)//\").\"\n stop\n end if\n\n xq = zeros(opt_n1)\n yq = zeros(opt_n1)\n t = [zeros(k - 1), linspace(0, 1, n - k + 2), ones(k - 1)]\n y1 = linspace(0, 1, opt_n1)\n\n do iq = 1, opt_n1\n x0 = find(y1(iq) .ge. t)\n j = min(n, x0(size(x0)))\n do i = j - k + 1, j\n w = deboor(i, k, y1(iq), t)\n xq(iq) = xq(iq) + x(i)*w\n yq(iq) = yq(iq) + y(i)*w\n end do\n end do\n return\n end subroutine bsplrep1\n\n ! bsplrep2\n !-----------------------------------------------------------------------\n ! bsplrep2 computes the B-spline surface representation S(t) of a set of\n ! 2-dimensional control points with uniform knot vectors.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! call bsplrep2(x, y, z, xq, yq, zq)\n ! call bsplrep2(x, y, z, xq, yq, zq, order)\n ! call bsplrep2(x, y, z, xq, yq, zq, order, n1, n2)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! call bsplrep2(x, y, z, xq, yq, zq) returns the B-spline surface\n ! representation S(t) = (xq, yq, zq) given the control points defined by\n ! x, y and z using a cubic spline (order 4 / degree 3).\n !\n ! call bsplrep2(x, y, z, xq, yq, zq, order) returns the B-spline surface\n ! representation S(t) = (xq, yq, zq) given the control points defined by\n ! x, y and z, and the order.\n !\n ! call bsplrep2(x, y, z, xq, yq, zq, order, n1, n2) returns the\n ! n1-by-b2-points B-spline surface representation S(t) = (xq, yq, zq)\n ! given the control points defined by x, y and z, and the order.\n\n subroutine bsplrep2(x, y, z, xq, yq, zq, order, n1, n2)\n real(kind=RPRE), dimension(:), intent(in) :: x, y\n real(kind=RPRE), dimension(:, :), intent(in) :: z\n real(kind=RPRE), dimension(:, :), allocatable, intent(out) :: xq, yq, zq\n integer(kind=IPRE), intent(in), optional :: order, n1, n2\n integer(kind=IPRE) :: opt_n1, opt_n2, i1, i2, iq1, iq2, j1, j2, k, m, n\n real(kind=RPRE) :: w1, w2\n integer(kind=IPRE), dimension(:), allocatable :: x0, y0\n real(kind=RPRE), dimension(:), allocatable :: t1, t2, y1, y2\n\n m = size(x)\n n = size(y)\n k = 4\n opt_n1 = 100\n opt_n2 = 100\n if (present(order)) k = order\n if (present(n1)) opt_n1 = n1\n if (present(n2)) opt_n2 = n2\n\n if (k .gt. min(m, n)) then\n print *, \"Error: in bsplrep2, order k should be less than the \" &\n //\"number of control points (\"//num2str(k)//\" > \" &\n //num2str(min(m, n))//\").\"\n stop\n end if\n\n xq = zeros(opt_n1, opt_n2)\n yq = zeros(opt_n1, opt_n2)\n zq = zeros(opt_n1, opt_n2)\n t1 = [zeros(k - 1), linspace(0, 1, m - k + 2), ones(k - 1)]\n t2 = [zeros(k - 1), linspace(0, 1, n - k + 2), ones(k - 1)]\n y1 = linspace(0, 1, opt_n1)\n y2 = linspace(0, 1, opt_n2)\n\n do iq1 = 1, opt_n1\n x0 = find(y1(iq1) .ge. t1)\n j1 = min(m, x0(size(x0)))\n do iq2 = 1, opt_n2\n y0 = find(y2(iq2) .ge. t2)\n j2 = min(n, y0(size(y0)))\n do i1 = j1 - k + 1, j1\n w1 = deboor(i1, k, y1(iq1), t1)\n do i2 = j2 - k + 1, j2\n w2 = deboor(i2, k, y2(iq2), t2)\n xq(iq1, iq2) = xq(iq1, iq2) + x(i1)*w1*w2\n yq(iq1, iq2) = yq(iq1, iq2) + y(i2)*w1*w2\n zq(iq1, iq2) = zq(iq1, iq2) + z(i1, i2)*w1*w2\n end do\n end do\n end do\n end do\n return\n end subroutine bsplrep2\n\n ! bspline1\n !-----------------------------------------------------------------------\n ! bspline1 approximates a set of 1-dimensional control points with\n ! spline curves in B-spline form.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! yq = bspline1(x, y, xq)\n ! yq = bspline1(x, y, xq, order)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! yq = bspline1(x, y, xq) returns the approximated vector yq at the\n ! query points in xq using a cubic spline (order 4 / degree 3).\n !\n ! yq = bspline1(x, y, xq, order) returns the approximated vector yq at\n ! the query points in xq with spline curves given the order.\n\n function bspline1_1(x, y, xq, order, n1) result(yq)\n real(kind=RPRE), dimension(:), allocatable :: yq\n real(kind=RPRE), dimension(:), intent(in) :: x, y, xq\n integer(kind=IPRE), intent(in), optional :: order, n1\n integer(kind=IPRE) :: k, n, opt_n1\n real(kind=RPRE), dimension(:), allocatable :: bspl_x, bspl_y\n\n n = size(x)\n k = 4\n opt_n1 = 100\n if (present(order)) k = order\n if (present(n1)) opt_n1 = n1\n if (k .gt. n) then\n print *, \"Error: in bspline1, order k should be less than the \" &\n //\"number of control points (\"//num2str(k)//\" > \" &\n //num2str(n)//\").\"\n stop\n end if\n\n call bsplrep1(x, y, bspl_x, bspl_y, k, opt_n1)\n yq = spline1(bspl_x, bspl_y, xq)\n return\n end function bspline1_1\n\n ! bspline2\n !-----------------------------------------------------------------------\n ! bspline2 approximates a set of 2-dimensional control points with\n ! spline curves in B-spline form.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! ZQ = bspline2(x, y, z, XQ, YQ)\n ! ZQ = bspline2(x, y, z, XQ, YQ, order)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! ZQ = bspline2(x, y, Z, XQ, YQ) returns the evaluated matrix ZQ given\n ! mesh type grids XQ and YQ using a bicubic spline (degree 3). ZQ is of\n ! the same shape as XQ and YQ.\n !\n ! ZQ = bspline2(x, y, Z, XQ, YQ, order) returns the evaluated matrix ZQ\n ! given mesh type grids XQ and YQ with spline curves given the order. ZQ\n ! is of the same shape as XQ and YQ.\n\n function bspline2_2(x, y, z, xq, yq, order) result(zq)\n real(kind=RPRE), dimension(:, :), allocatable :: zq\n real(kind=RPRE), dimension(:), intent(in) :: x, y\n real(kind=RPRE), dimension(:, :), intent(in) :: z, xq, yq\n integer(kind=IPRE), intent(in), optional :: order\n integer(kind=IPRE) :: i, m, n, ny, k\n real(kind=RPRE), dimension(:, :), allocatable :: tmp\n\n m = size(xq, 1)\n n = size(xq, 2)\n ny = size(y)\n k = 4\n if (present(order)) k = order\n\n tmp = zeros(ny, n)\n do i = 1, ny\n tmp(i, :) = bspline1(x, z(i, :), xq(i, :), k)\n end do\n\n zq = zeros(m, n)\n do i = 1, n\n zq(:, i) = bspline1(y, tmp(:, i), yq(:, i), k)\n end do\n\n return\n end function bspline2_2\n\n ! check_directory\n !-----------------------------------------------------------------------\n ! check_directory appends '/' do a directory name.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! call check_directory(dirname)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! call check_directory(dirname) returns a directory name dirname that\n ! ends with '/'.\n\n subroutine check_directory(dirname)\n character(len=:), allocatable, intent(inout) :: dirname\n integer(kind=IPRE) :: i\n\n i = len_trim(dirname)\n if (dirname(i:i) .ne. \"/\") dirname = trim(dirname)//\"/\"\n return\n end subroutine check_directory\n\n ! chi2cdf\n !-----------------------------------------------------------------------\n ! chi2cdf computes the chi-square cumulative distribution function.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! p = chi2cdf(x, v)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! p = chi2cdf(x, v) returns the chi-square cdf at each of the values\n ! in x.\n\n real(kind=RPRE) function chi2cdf0(x, v)\n real(kind=RPRE), intent(in) :: x\n integer(kind=IPRE), intent(in) :: v\n\n chi2cdf0 = gammainc(real(x/2., RPRE), real(v/2., RPRE))\n return\n end function chi2cdf0\n\n function chi2cdf1_0(X, v)\n real(kind=RPRE), dimension(:), allocatable :: chi2cdf1_0\n real(kind=RPRE), dimension(:), intent(in) :: X\n integer(kind=IPRE), intent(in) :: v\n integer(kind=IPRE) :: i, n\n\n n = size(X)\n chi2cdf1_0 = zeros(n)\n do i = 1, n\n chi2cdf1_0(i) = chi2cdf0(X(i), v)\n end do\n return\n end function chi2cdf1_0\n\n function chi2cdf1_1(X, V)\n real(kind=RPRE), dimension(:), allocatable :: chi2cdf1_1\n real(kind=RPRE), dimension(:), intent(in) :: X\n integer(kind=IPRE), dimension(:), intent(in) :: V\n integer(kind=IPRE) :: i, n\n\n n = size(X)\n chi2cdf1_1 = zeros(n)\n do i = 1, n\n chi2cdf1_1(i) = chi2cdf0(X(i), V(i))\n end do\n return\n end function chi2cdf1_1\n\n ! chi2inv\n !-----------------------------------------------------------------------\n ! chi2inv computes the chi-square inverse cumulative distribution\n ! function.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! x = chi2inv(p, v)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! x = chi2inv(p, v) returns the chi-square inverse cdf at each of the\n ! values in p.\n\n real(kind=RPRE) function chi2inv0(p, v)\n real(kind=RPRE), intent(in), target :: p\n integer(kind=IPRE), intent(in), target :: v\n real(kind=RPRE) :: a, b\n real(kind=RPRE), pointer, save :: p_ptr\n integer(kind=IPRE), pointer, save :: v_ptr\n\n if (p .le. 0. .or. p .ge. 1.) then\n print *, \"Error: in chi2inv0(p, v), p should be between 0 and 1\"\n stop\n end if\n if (v .le. 0) then\n print *, \"Error: in chi2inv0(p, v), v should be greater than 0\"\n stop\n end if\n\n p_ptr => p\n v_ptr => v\n a = 0.\n b = real(v, RPRE)\n do while (chi2cdf(b, v) .lt. p)\n b = b*b\n end do\n chi2inv0 = fminbnd(chi2func, a, b)\n return\n contains\n\n real(kind=RPRE) function chi2func(x)\n real(kind=RPRE), intent(in) :: x\n chi2func = abs(chi2cdf0(x, v_ptr) - p_ptr)\n return\n end function chi2func\n\n end function chi2inv0\n\n function chi2inv1_0(P, v)\n real(kind=RPRE), dimension(:), allocatable :: chi2inv1_0\n real(kind=RPRE), dimension(:), intent(in) :: P\n integer(kind=IPRE), intent(in) :: v\n integer(kind=IPRE) :: i, n\n\n n = size(P)\n chi2inv1_0 = zeros(n)\n do i = 1, n\n chi2inv1_0(i) = chi2inv0(P(i), v)\n end do\n return\n end function chi2inv1_0\n\n function chi2inv1_1(P, V)\n real(kind=RPRE), dimension(:), allocatable :: chi2inv1_1\n real(kind=RPRE), dimension(:), intent(in) :: P\n integer(kind=IPRE), dimension(:), intent(in) :: V\n integer(kind=IPRE) :: i, n\n\n n = size(P)\n chi2inv1_1 = zeros(n)\n do i = 1, n\n chi2inv1_1(i) = chi2inv0(P(i), V(i))\n end do\n return\n end function chi2inv1_1\n\n ! chi2pdf\n !-----------------------------------------------------------------------\n ! chi2pdf computes the chi-square probability distribution function.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! y = chi2pdf(x, v)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! y = chi2pdf(x, v) returns the chi-square pdf at each of the values\n ! in x.\n\n real(kind=RPRE) function chi2pdf0(x, v)\n real(kind=RPRE), intent(in) :: x\n integer(kind=IPRE), intent(in) :: v\n real(kind=RPRE) :: v2\n\n if (x .gt. 0.) then\n v2 = 0.5*real(v, RPRE)\n chi2pdf0 = 1./(2.*gamma(v2))*(x/2)**(v2 - 1.)*exp(-x/2.)\n else\n chi2pdf0 = 0.\n end if\n return\n end function chi2pdf0\n\n function chi2pdf1_0(X, v)\n real(kind=RPRE), dimension(:), allocatable :: chi2pdf1_0\n real(kind=RPRE), dimension(:), intent(in) :: X\n integer(kind=IPRE), intent(in) :: v\n integer(kind=IPRE) :: i, n\n\n n = size(X)\n chi2pdf1_0 = zeros(n)\n do i = 1, n\n chi2pdf1_0(i) = chi2pdf0(X(i), v)\n end do\n return\n end function chi2pdf1_0\n\n function chi2pdf1_1(X, V)\n real(kind=RPRE), dimension(:), allocatable :: chi2pdf1_1\n real(kind=RPRE), dimension(:), intent(in) :: X\n integer(kind=IPRE), dimension(:), intent(in) :: V\n integer(kind=IPRE) :: i, n\n\n n = size(X)\n chi2pdf1_1 = zeros(n)\n do i = 1, n\n chi2pdf1_1(i) = chi2pdf0(X(i), V(i))\n end do\n return\n end function chi2pdf1_1\n\n ! chi2rand\n !-----------------------------------------------------------------------\n ! chi2rand generates chi-square random numbers.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! r = chi2rand(v)\n ! r = chi2rand(v, dim1)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! r = chi2rand(v) returns a chi-square distributed random number with\n ! v degrees of freedom.\n !\n ! r = chi2rand(v, dim1) returns a dim1 vector of chi-square distributed\n ! random number with v degrees of freedom.\n\n real(kind=RPRE) function chi2rand0(v)\n integer(kind=IPRE), intent(in) :: v\n chi2rand0 = sum(randn(v)**2)\n return\n end function chi2rand0\n\n function chi2rand1(v, dim1)\n real(kind=RPRE), dimension(:), allocatable :: chi2rand1\n integer(kind=IPRE), intent(in) :: v, dim1\n chi2rand1 = sum(randn(dim1, v)**2, dim=2)\n return\n end function chi2rand1\n\n ! chol\n !-----------------------------------------------------------------------\n ! chol computes Cholesky's decomposition of a symmetric positive\n ! definite matrix.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! L = chol(A)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! L = chol(A) returns a lower triangular matrix L satisfying the\n ! equation A = L*Lt.\n\n function chol(A) result(L)\n real(kind=RPRE), dimension(:, :), allocatable :: L\n real(kind=RPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE) :: i, j, k, n\n real(kind=RPRE) :: sum1, sum2\n real(kind=RPRE), dimension(:), allocatable :: d\n real(kind=RPRE), dimension(:, :), allocatable :: V\n\n call eig(A, V, d)\n if (all(d .gt. 0.0d0)) then\n n = size(A, 1)\n L = zeros(n, n)\n L(1, 1) = sqrt(A(1, 1))\n do i = 2, n\n L(i, 1) = A(i, 1)/L(1, 1)\n end do\n\n do i = 2, n\n do k = 1, i\n sum1 = 0.0d0\n sum2 = 0.0d0\n do j = 1, k - 1\n if (i .eq. k) then\n sum1 = sum1 + (L(k, j)*L(k, j))\n L(k, k) = sqrt(A(k, k) - sum1)\n elseif (i .gt. k) then\n sum2 = sum2 + (L(i, j)*L(k, j))\n L(i, k) = (1.0d0/L(k, k))*(A(i, k) - sum2)\n else\n L(i, k) = 0.0d0\n end if\n end do\n end do\n end do\n else\n stop \"Error: in chol(A), A should be positive definite.\"\n end if\n return\n end function chol\n\n ! close\n !-----------------------------------------------------------------------\n ! close closes a File object.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! call ofile%close()\n !\n ! Description\n !-----------------------------------------------------------------------\n ! call ofile%close() closes the File object ofile.\n\n subroutine close (self)\n class(File) :: self\n\n close (self%unit)\n return\n end subroutine close\n\n ! countlines\n !-----------------------------------------------------------------------\n ! countlines counts the number of lines in a txt file.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! n = countlines(filename)\n ! n = ofile%countlines()\n !\n ! Description\n !-----------------------------------------------------------------------\n ! n = countlines(filename) returns the number of lines in the txt file\n ! filename.\n !\n ! n = ofile%countlines() returns the number of lines in the txt file\n ! associated to the File object ofile.\n\n integer(kind=IPRE) function countlines1(self)\n class(File), intent(inout) :: self\n integer(kind=IPRE) :: ierr\n\n countlines1 = 0\n call self%open()\n do\n read (self%unit, *, iostat=ierr)\n if (ierr .lt. 0) exit\n countlines1 = countlines1 + 1\n end do\n call self%close()\n return\n end function countlines1\n\n integer(kind=IPRE) function countlines2(filename)\n !! The `countlines2` function returns the number of lines of the file\n character(len=*), intent(in) :: filename\n integer(kind=IPRE) :: ierr\n type(File) :: infile\n\n infile = File(999, trim(filename))\n countlines2 = 0\n call infile%open()\n do\n read (infile%unit, *, iostat=ierr)\n if (ierr .lt. 0) exit\n countlines2 = countlines2 + 1\n end do\n call infile%close()\n return\n end function countlines2\n\n ! cov\n !-----------------------------------------------------------------------\n ! cov computes the covariance.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! c = cov(x)\n ! c = cov(x, w)\n ! C = cov(X)\n ! C = cov(X, w)\n ! C = cov(x, y)\n ! C = cov(x, y, w)\n ! C = cov(X, Y)\n ! C = cov(X, Y, w)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! c = cov(x) returns the covariance of vector x normalized by the number\n ! of observations minus 1.\n !\n ! c = cov(x, w) returns the covariance of vector x with the\n ! normalization option w.\n ! - 0 (default) normalize by N-1,\n ! - 1 normalize by N.\n !\n ! C = cov(X) returns the the covariance matrix with the corresponding\n ! column variances along the diagonal normalized by the number of\n ! observations minus 1.\n !\n ! C = cov(X, w) returns the the covariance matrix with the corresponding\n ! column variances along the diagonal with the normalization option w.\n !\n ! C = cov(x, y) returns the 2-by-2 covariance matrix normalized by the\n ! number of observations minus 1.\n !\n ! C = cov(x, y, w) returns the 2-by-2 covariance matrix with the\n ! normalization option w.\n !\n ! C = cov(X, Y) returns the the 2-by-2 covariance matrix normalized by\n ! the number of observations minus 1. X and Y are treated as column\n ! vectors.\n !\n ! C = cov(X, Y, w) returns the the 2-by-2 covariance matrix with the\n ! normalisation option w. X and Y are treated as column vectors.\n\n real(kind=RPRE) function cov1_1(x, w)\n real(kind=RPRE), dimension(:), intent(in) :: x\n integer(kind=IPRE), intent(in), optional :: w\n integer(kind=IPRE) :: opt_w\n real(kind=RPRE), dimension(:), allocatable :: tmp\n\n opt_w = 0\n if (present(w)) opt_w = w\n\n tmp = x - mean(x)\n select case (opt_w)\n case (0)\n cov1_1 = dot_product(tmp, tmp)/(size(x) - 1)\n case (1)\n cov1_1 = dot_product(tmp, tmp)/size(x)\n end select\n return\n end function cov1_1\n\n function cov1_2(X, w)\n real(kind=RPRE), dimension(:, :), allocatable :: cov1_2\n real(kind=RPRE), dimension(:, :), intent(in) :: X\n integer(kind=IPRE), intent(in), optional :: w\n integer(kind=IPRE) :: opt_w\n real(kind=RPRE), dimension(:, :), allocatable :: tmp\n\n opt_w = 0\n if (present(w)) opt_w = w\n\n tmp = X - repmat(mean(X, 1), size(X, 1), 2)\n select case (opt_w)\n case (0)\n cov1_2 = matmul(transpose(tmp), tmp)/(size(X, 1) - 1)\n case (1)\n cov1_2 = matmul(transpose(tmp), tmp)/size(X, 1)\n end select\n return\n end function cov1_2\n\n function cov2_1(x, y, w)\n real(kind=RPRE), dimension(:, :), allocatable :: cov2_1\n real(kind=RPRE), dimension(:), intent(in) :: x, y\n integer(kind=IPRE), intent(in), optional :: w\n integer(kind=IPRE) :: opt_w\n real(kind=RPRE), dimension(:, :), allocatable :: tmp\n\n opt_w = 0\n if (present(w)) opt_w = w\n\n cov2_1 = cov1_2(horzcat(x, y), opt_w)\n return\n end function cov2_1\n\n function cov2_2(X, Y, w)\n real(kind=RPRE), dimension(:, :), allocatable :: cov2_2\n real(kind=RPRE), dimension(:, :), intent(in) :: X, Y\n integer(kind=IPRE), intent(in), optional :: w\n integer(kind=IPRE) :: opt_w\n\n opt_w = 0\n if (present(w)) opt_w = w\n\n if (all(shape(X) .eq. shape(Y))) then\n cov2_2 = cov1_2(horzcat([X], [Y]), opt_w)\n else\n stop \"Error: in cov(X, Y), X and Y should have the same shape.\"\n end if\n return\n end function cov2_2\n\n ! cumsum\n !-----------------------------------------------------------------------\n ! cumsum computes the cumulative sum of a vector or array.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! y = cumsum(x)\n ! B = cumsum(A)\n ! B = cumsum(A, dim)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! y = cumsum(x) returns a vector containing the cumulative sum of the\n ! elements of A.\n !\n ! B = cumsum(A) returns a matrix containing the cumulative sums for each\n ! column of A.\n !\n ! B = cumsum(A) returns a matrix containing the cumulative sums for each\n ! elements A along the specified dimension dim.\n\n function cumsum1(x)\n real(kind=RPRE), dimension(:), allocatable :: cumsum1\n real(kind=RPRE), dimension(:), intent(in) :: x\n integer(kind=IPRE) :: i, n\n real(kind=RPRE), dimension(:), allocatable :: xsort\n\n n = size(x)\n xsort = sort(x, 1)\n cumsum1 = [(sum(xsort(1:i)), i=1, n)]\n return\n end function cumsum1\n\n function cumsum2(A, dim)\n real(kind=RPRE), dimension(:, :), allocatable :: cumsum2\n real(kind=RPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE), intent(in), optional :: dim\n integer(kind=IPRE) :: i, m, n\n\n m = size(A, 1)\n n = size(A, 2)\n cumsum2 = zeros(m, n)\n if ((.not. present(dim)) .or. (dim .eq. 1)) then\n do i = 1, n\n cumsum2(:, i) = cumsum1(A(:, i))\n end do\n elseif (dim .eq. 2) then\n do i = 1, m\n cumsum2(i, :) = cumsum1(A(i, :))\n end do\n end if\n return\n end function cumsum2\n\n ! datenum\n !-----------------------------------------------------------------------\n ! datenum converts the datetime values into serial date numbers (since\n ! 0000-01-01 00:00:00).\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! d = datenum(year, month, day)\n ! d = datenum(year, month, day, hour, minute, second)\n ! d = datenum(year, month, day, hour, minute, second, microsecond)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! d = datenum(year, month, day) returns an integer serial date number\n ! given by year, month and day.\n !\n ! d = datenum(year, month, day, hour, minute, second) returns a floating\n ! serial date number given by year, month, day, hour, minute and second.\n !\n ! d = datenum(year, month, day, hour, minute, second, microsecond)\n ! returns a floating serial date number given by year, month, day, hour,\n ! minute, second and microsecond.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! d = datenum(2016, 1, 1)\n ! 736330.\n !\n ! d = datenum(2016, 1, 17, 22, 28, 30, 250000)\n ! 736346.93646122678\n !\n ! Notes\n !-----------------------------------------------------------------------\n ! Use double precision for accuracy.\n\n real(kind=8) function datenum0(year, month, day, hour, minute, &\n second, microsecond)\n integer(kind=IPRE), intent(in) :: year, month, day\n integer(kind=IPRE), intent(in), optional :: hour, minute, second, microsecond\n integer(kind=IPRE) :: i, days_per_month(12)\n\n if ((month .lt. 1) .and. (month .gt. 12)) then\n print *, \"Error: month should be between 1 and 12 (\"//num2str(month)//\").\"\n end if\n if ((day .lt. 1) .and. (day .gt. 31)) then\n print *, \"Error: day should be between 1 and 31 (\"//num2str(day)//\").\"\n end if\n if ((present(hour)) .and. (hour .lt. 0) .and. (hour .gt. 23)) then\n print *, \"Error: hour should be between 0 and 23 (\"//num2str(hour)//\").\"\n end if\n if ((present(minute)) .and. (minute .lt. 0) .and. (minute .gt. 59)) then\n print *, \"Error: minute should be between 0 and 59 (\"//num2str(minute)//\").\"\n end if\n if ((present(second)) .and. (second .lt. 0) .and. (second .gt. 59)) then\n print *, \"Error: second should be between 0 and 59 (\"//num2str(second)//\").\"\n end if\n if ((present(microsecond)) .and. (microsecond .lt. 0) .and. (microsecond .ge. 1.0d+6)) then\n print *, \"Error: microsecond should be between 0 and 999,999 (\"//num2str(microsecond)//\").\"\n end if\n days_per_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n datenum0 = 0\n do i = 0, year - 1\n if (isleap(i)) then\n datenum0 = datenum0 + 366\n else\n datenum0 = datenum0 + 365\n end if\n end do\n datenum0 = datenum0 + sum(days_per_month(:month - 1))\n if (isleap(year) .and. (month .gt. 2)) datenum0 = datenum0 + 1\n datenum0 = datenum0 + day\n if (present(hour)) datenum0 = datenum0 + real(hour, kind=8)/24.0d0\n if (present(minute)) datenum0 = datenum0 + real(minute, kind=8)/(24.0d0*60.0d0)\n if (present(second)) datenum0 = datenum0 + real(second, kind=8)/(24.0d0*60.0d0*60.0d0)\n if (present(microsecond)) datenum0 = datenum0 + real(microsecond, kind=8)/(24.0d0*60.0d0*60.0d0*1.0d+6)\n return\n end function datenum0\n\n\n ! datestr\n !-----------------------------------------------------------------------\n ! datestr creates a string of a datetime.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! dstr = datestr(t)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! dstr = datestr(t) returns a string of the serial date number t.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! t = datenum([ 1991, 9, 14, 16, 5, 0, 0])\n ! dstr = datestr(t)\n ! 14-Sep-1991 16:04:59:999998\n !\n ! Notes\n !-----------------------------------------------------------------------\n ! Output string may slightly differ from the input date vector in\n ! datenum due to accuracy in the calculation of the serial date number.\n\n function datestr0_0(t)\n character(len=:), allocatable :: datestr0_0\n real(kind=8), intent(in) :: t\n integer(kind=IPRE) :: d(7)\n character(len=CLEN) :: dstr\n character(len=3) :: months_in_letters(12)\n\n d = datevec(t)\n\n ! Day\n !=====\n if (d(3) .lt. 10) then\n dstr = \"0\"//num2str(d(3))//\"-\"\n else\n dstr = num2str(d(3))//\"-\"\n end if\n\n ! Month\n !=======\n months_in_letters = [\"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\", &\n \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\"]\n dstr = trim(dstr)//months_in_letters(d(2))//\"-\"\n\n ! Year\n !======\n dstr = trim(dstr)//num2str(d(1))\n\n if ((d(4) .eq. 0) .and. (d(5) .eq. 0) &\n .and. (d(6) .eq. 0) .and. (d(7) .eq. 0)) then\n datestr0_0 = trim(dstr)\n return\n\n else\n\n ! Hour\n !======\n if (d(4) .lt. 10) then\n dstr = trim(dstr)//\" \"//\"0\"//num2str(d(4))//\":\"\n else\n dstr = trim(dstr)//\" \"//num2str(d(4))//\":\"\n end if\n\n ! Minute\n !========\n if (d(5) .lt. 10) then\n dstr = trim(dstr)//\"0\"//num2str(d(5))//\":\"\n else\n dstr = trim(dstr)//num2str(d(5))//\":\"\n end if\n\n ! Second\n !========\n if (d(6) .lt. 10) then\n dstr = trim(dstr)//\"0\"//num2str(d(6))//\".\"\n else\n dstr = trim(dstr)//num2str(d(6))//\".\"\n end if\n\n ! Microsecond\n !=============\n if (d(7) .lt. 10) then\n dstr = trim(dstr)//\"00000\"//num2str(d(7))\n elseif (d(7) .lt. 100) then\n dstr = trim(dstr)//\"0000\"//num2str(d(7))\n elseif (d(7) .lt. 1000) then\n dstr = trim(dstr)//\"000\"//num2str(d(7))\n elseif (d(7) .lt. 10000) then\n dstr = trim(dstr)//\"00\"//num2str(d(7))\n elseif (d(7) .lt. 100000) then\n dstr = trim(dstr)//\"0\"//num2str(d(7))\n else\n dstr = trim(dstr)//num2str(d(7))\n end if\n\n datestr0_0 = trim(dstr)\n end if\n return\n end function datestr0_0\n\n ! datevec\n !-----------------------------------------------------------------------\n ! datevec converts date and time to vector of components.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! d = datevec(t)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! d = datevec(t) returns a 7-elements datetime vector given the serial\n ! date number t.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! d = datevec(727455.67013888888d0)\n ! 1991 9 14 16 4 59 999998\n !\n ! Notes\n !-----------------------------------------------------------------------\n ! Input is in double precision for accuracy.\n\n function datevec0(t)\n integer(kind=IPRE) :: datevec0(7)\n real(kind=8), intent(in) :: t\n integer(kind=IPRE) :: i, days_per_month(12)\n real(kind=8) :: tmp, dateres\n\n datevec0 = 0\n\n ! Year\n !======\n tmp = 0.0d0\n do\n if (isleap(datevec0(1))) then\n tmp = tmp + 366.0d0\n else\n tmp = tmp + 365.0d0\n end if\n if (tmp .lt. floor(t)) then\n datevec0(1) = datevec0(1) + 1\n else\n exit\n end if\n end do\n dateres = floor(t) - datenum(datevec0(1), 1, 1)\n\n ! Month\n !=======\n tmp = 0.0d0\n days_per_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n do i = 1, 12\n tmp = tmp + days_per_month(i)\n if ((isleap(datevec0(1))) .and. (i .eq. 2)) tmp = tmp + 1\n if (tmp .ge. dateres) then\n datevec0(2) = i\n exit\n end if\n end do\n dateres = floor(t) - datenum(datevec0(1), datevec0(2), 1)\n\n ! Day\n !=====\n datevec0(3) = floor(dateres) + 1\n dateres = t - floor(t)\n\n ! Hour\n !======\n datevec0(4) = floor(dateres*24.0d0)\n dateres = dateres - datevec0(4)/24.0d0\n\n ! Minute\n !========\n datevec0(5) = floor(dateres*24.0d0*60.0d0)\n dateres = dateres - datevec0(5)/(24.0d0*60.0d0)\n\n ! Second\n !========\n datevec0(6) = floor(dateres*24.0d0*60.0d0*60.0d0)\n dateres = dateres - datevec0(6)/(24.0d0*60.0d0*60.0d0)\n\n ! Microsecond\n !=============\n datevec0(7) = floor(dateres*24.0d0*60.0d0*60.0d0*1.0d+6)\n\n return\n end function datevec0\n\n ! dbindex\n !-----------------------------------------------------------------------\n ! dbindex computes the Davies-Bouldin index for evaluating clutering\n ! algorithms.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! db = dbindex(x, cluster, means)\n ! db = dbindex(x, cluster, means, p, q)\n ! db = dbindex(X, cluster, means)\n ! db = dbindex(X, cluster, means, p, q)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! db = dbindex(x, cluster, means) returns the Davies-Bouldin index using\n ! the Euclidian distance.\n !\n ! db = dbindex(x, cluster, means, p, q) returns the Davies-Bouldin index\n ! using the metric defined by p and q.\n !\n ! db = dbindex(X, cluster, means) returns the Davies-Bouldin index using\n ! the Euclidian distance, each row of array X being an observation and\n ! each column a parameter.\n !\n ! db = dbindex(X, cluster, means, p, q) returns the Davies-Bouldin index\n ! using the metric defined by p and q, each row of array X being an\n ! observation and each column a parameter.\n !\n ! Notes\n !-----------------------------------------------------------------------\n ! After Davies D. L. and Bouldin D. W. (1979): \"A Cluster Separation\n ! Measure\".\n\n real(kind=RPRE) function dbindex1(x, cluster, means, p, q) result(db)\n real(kind=RPRE), dimension(:), intent(in) :: x, means\n integer(kind=IPRE), dimension(:), intent(in) :: cluster\n real(kind=RPRE), intent(in), optional :: p, q\n integer(kind=IPRE) :: K, n\n real(kind=RPRE) :: opt_p, opt_q\n real(kind=RPRE), dimension(:, :), allocatable :: A, mu\n\n K = size(means)\n if (K .eq. 1) then\n print *, \"Warning: in dbindex, the Davies-Bouldin index cannot \" &\n //\"be defined for K = 1.\"\n db = 1.0d0\n return\n end if\n\n opt_p = 2.\n opt_q = 2.\n if (present(p)) opt_p = p\n if (present(q)) opt_q = q\n\n n = size(x)\n A = reshape(x, shape=[n, 1], order=[1, 2])\n mu = reshape(x, shape=[K, 1], order=[1, 2])\n db = dbindex2(A, cluster, mu, opt_p, opt_q)\n return\n end function dbindex1\n\n real(kind=RPRE) function dbindex2(X, cluster, means, p, q) result(db)\n real(kind=RPRE), dimension(:, :), intent(in) :: X\n integer(kind=IPRE), dimension(:), intent(in) :: cluster\n real(kind=RPRE), dimension(:, :), intent(in) :: means\n real(kind=RPRE), intent(in), optional :: p, q\n integer(kind=IPRE) :: i, j, K\n real(kind=RPRE) :: opt_p, opt_q, Mij\n integer(kind=IPRE), dimension(:), allocatable :: idx\n real(kind=RPRE), dimension(:), allocatable :: S\n real(kind=RPRE), dimension(:, :), allocatable :: R\n\n K = size(means, 1)\n if (K .eq. 1) then\n print *, \"Warning: in dbindex, the Davies-Bouldin index cannot \" &\n //\"be defined for K = 1.\"\n db = 1.0d0\n return\n end if\n\n opt_p = 2.\n opt_q = 2.\n if (present(p)) opt_p = p\n if (present(q)) opt_q = q\n\n ! Measure the scattering within each cluster\n !============================================\n S = zeros(K)\n do i = 1, K\n idx = find(cluster .eq. i)\n do j = 1, size(idx)\n S(i) = S(i) + norm(X(idx(j), :) - means(i, :), opt_q)**2\n end do\n S(i) = sqrt(S(i)/real(size(idx), RPRE))\n end do\n\n ! Measure the similarity function R between each cluster\n !========================================================\n R = zeros(K, K)\n do i = 1, K - 1\n do j = i + 1, K\n Mij = norm(means(i, :) - means(j, :), opt_p) ! Distance between clusters i and j\n R(i, j) = (S(i) + S(j))/Mij\n R(j, i) = R(i, j)\n end do\n end do\n\n ! Compute the Davies-Bouldin index\n !==================================\n db = mean([(maxval(R(i, :)), i=1, K)])\n\n return\n end function dbindex2\n\n ! deboor\n !-----------------------------------------------------------------------\n ! deboor evaluates recursively the spline polynomial basis using\n ! Cox-de-Boor algorithm.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! db = deboor(i, k, x, t)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! db = deboor(i, k, x, t) returns the polynomial basis given the control\n ! point index i, the polynomial order k (degree k-1), the evaluated\n ! point x, and the knots vector t.\n\n recursive function deboor(i, k, x, t) result(db)\n real(kind=RPRE) :: db\n integer(kind=IPRE), intent(in) :: i, k\n real(kind=RPRE), intent(in) :: x\n real(kind=RPRE), dimension(:), intent(in) :: t\n real(kind=RPRE) :: A1, A2\n\n if (k .eq. 1) then\n if (x .ne. t(size(t))) then\n if ((x .ge. t(i)) .and. (x .lt. t(i + 1))) then\n db = 1.0d0\n else\n db = 0.0d0\n end if\n else\n if ((x .ge. t(i)) .and. (x .le. t(i + 1))) then\n db = 1.0d0\n else\n db = 0.0d0\n end if\n end if\n else\n if (t(i + k - 1) - t(i) .ne. 0.0d0) then\n A1 = (x - t(i))/(t(i + k - 1) - t(i))\n else\n A1 = 0.0d0\n end if\n if (t(i + k) - t(i + 1) .ne. 0.0d0) then\n A2 = (t(i + k) - x)/(t(i + k) - t(i + 1))\n else\n A2 = 0.0d0\n end if\n db = A1*deboor(i, k - 1, x, t) + A2*deboor(i + 1, k - 1, x, t)\n end if\n return\n end function deboor\n\n ! deg2utm\n !-----------------------------------------------------------------------\n ! deg2utm converts latitude / longitude (in degrees) coordinates to\n ! UTM-WGS84 coordinates.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! call deg2utm(lat, lon, east, north, zn, zl)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! call deg2utm(lat, lon, east, north, zn, zl) converts the coordinates\n ! in lat and lon (in degrees) to UTM-WGS84 coordinates. It outputs the\n ! easting east, northing north, zone number zn, and zone letter zl.\n !\n ! Notes\n !-----------------------------------------------------------------------\n ! This function has been translated and adapted from the Python's\n ! module utm: https://pypi.python.org/pypi/utm\n\n subroutine deg2utm0(lat, lon, east, north, zn, zl)\n real(kind=RPRE), intent(in) :: lat, lon\n real(kind=RPRE), intent(out) :: east, north\n integer(kind=IPRE), intent(out) :: zn\n character(len=1), intent(out) :: zl\n\n real(kind=8), parameter :: K0 = 0.9996d0\n real(kind=8), parameter :: E = 0.00669438d0\n real(kind=8), parameter :: R = 6378137\n real(kind=8) :: E_P2, m, n, c, a\n real(kind=8) :: M1, M2, M3, M4\n real(kind=8) :: lat_rad, lat_sin, lat_cos, lat_tan, lat_tan2, &\n lat_tan4, lon_rad, central_lon, central_lon_rad\n\n E_P2 = E/(1.0d0 - E)\n M1 = (1 - E/4 - 3*E**2/64 - 5*E**3/256)\n M2 = (3*E/8 + 3*E**2/32 + 45*E**3/1024)\n M3 = (15*E**2/256 + 45*E**3/1024)\n M4 = (35*E**3/3072)\n\n lat_rad = lat*pi/180.0d0\n lat_sin = sin(lat_rad)\n lat_cos = cos(lat_rad)\n lat_tan = lat_sin/lat_cos\n lat_tan2 = lat_tan**2\n lat_tan4 = lat_tan2**2\n\n zn = zone_number(lat, lon)\n zl = zone_letter(lat)\n\n lon_rad = lon*pi/180.0d0\n central_lon = central_longitude(zn)\n central_lon_rad = central_lon*pi/180.0d0\n\n n = R/sqrt(1 - E*lat_sin**2)\n c = E_P2*lat_cos**2\n a = lat_cos*(lon_rad - central_lon_rad)\n m = R*(M1*lat_rad &\n - M2*sin(2*lat_rad) &\n + M3*sin(4*lat_rad) &\n - M4*sin(6*lat_rad))\n east = K0*n*(a + &\n a**3/6*(1 - lat_tan2 + c) + &\n a**5/120*(5 - 18*lat_tan2 + lat_tan4 + 72*c - 58*E_P2)) + 500000\n north = K0*(m + n*lat_tan*(a**2/2 + &\n a**4/24*(5 - lat_tan2 + 9*c + 4*c**2) + &\n a**6/720*(61 - 58*lat_tan2 + lat_tan4 + 600*c - 330*E_P2)))\n if (lat .lt. 0.0d0) north = north + 10000000\n return\n\n contains\n\n !-------------------------------------------------------------------\n ! zone_number\n !-------------------------------------------------------------------\n integer(kind=IPRE) function zone_number(lat, lon)\n real(kind=RPRE), intent(in) :: lat, lon\n if ((lat .ge. 56.0d0) .and. (lat .le. 64.0d0) &\n .and. (lon .ge. 3.0d0) .and. (lon .le. 12.0d0)) then\n zone_number = 32\n return\n end if\n\n if ((lat .ge. 72.0d0) .and. (lat .le. 84.0d0) &\n .and. (lon .ge. 0.0d0)) then\n if (lon .le. 9.0d0) then\n zone_number = 31\n return\n elseif (lon .le. 21.0d0) then\n zone_number = 33\n return\n elseif (lon .le. 42.0d0) then\n zone_number = 37\n return\n end if\n end if\n\n zone_number = int((lon + 180.0d0)/6.0d0) + 1\n return\n end function zone_number\n\n !-------------------------------------------------------------------\n ! zone_letter\n !-------------------------------------------------------------------\n character(len=1) function zone_letter(lat)\n real(kind=RPRE), intent(in) :: lat\n character(len=*), parameter :: ZONE_LETTERS = \"OXWVUTSRQPNMLKJHGFEDC\"\n integer(kind=IPRE) :: ZONE_LATS(21) = [84, 72, 64, 56, 48, 40, 32, 24, 16, 8, 0, &\n -8, -16, -24, -32, -40, -48, -56, -64, -72, -80]\n integer(kind=IPRE) :: i\n do i = 1, 21\n if (lat .ge. ZONE_LATS(i)) then\n zone_letter = ZONE_LETTERS(i:i)\n exit\n end if\n end do\n return\n end function zone_letter\n\n !-------------------------------------------------------------------\n ! central_longitude\n !-------------------------------------------------------------------\n real(kind=RPRE) function central_longitude(zn)\n integer(kind=IPRE), intent(in) :: zn\n central_longitude = (zn - 1)*6 - 180 + 3\n return\n end function central_longitude\n\n end subroutine deg2utm0\n\n subroutine deg2utm1(lat, lon, east, north, zn, zl)\n real(kind=RPRE), dimension(:), intent(in) :: lat, lon\n real(kind=RPRE), dimension(:), allocatable, intent(out) :: east, north\n integer(kind=IPRE), dimension(:), allocatable, intent(out) :: zn\n character(len=1), dimension(:), allocatable, intent(out) :: zl\n integer(kind=IPRE) :: i, n\n\n n = size(lat)\n allocate (east(n), north(n), zn(n), zl(n))\n do i = 1, n\n call deg2utm(lat(i), lon(i), east(i), north(i), zn(i), zl(i))\n end do\n return\n end subroutine deg2utm1\n\n ! diff\n !-----------------------------------------------------------------------\n ! diff computes differences of arrays\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! y = diff(x)\n ! y = diff(x, n)\n ! B = diff(A)\n ! B = diff(A, n)\n ! B = diff(A, dim)\n ! B = diff(A, n, dim)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! y = diff(x) returns differences between adjacent elements of vector x.\n !\n ! y = diff(x, n) returns the nth difference by applying the diff(x)\n ! operator recursively n times.\n !\n ! B = diff(A) returns differences between adjacent elements of array A\n ! along the first dimension.\n !\n ! B = diff(A, n) returns the nth difference by applying the diff(A)\n ! operator recursively n times.\n !\n ! B = diff(A, dim) returns differences between adjacent elements of\n ! array A along the dimension given by dim.\n !\n ! B = diff(A, n, dim) returns the nth difference along the dimension\n ! given by dim by applying the diff(A, dim) operator recursively\n ! n times.\n\n function diff1(x, n)\n real(kind=RPRE), dimension(:), allocatable :: diff1\n real(kind=RPRE), dimension(:), intent(in) :: x\n integer(kind=IPRE), intent(in), optional :: n\n integer(kind=IPRE) :: opt_n, i\n\n opt_n = 1\n if (present(n)) opt_n = n\n\n diff1 = x\n do i = 1, opt_n\n diff1 = diff1(2:) - diff1(:size(diff1) - 1)\n end do\n return\n end function diff1\n\n function diff2(A, n, dim)\n real(kind=RPRE), dimension(:, :), allocatable :: diff2\n real(kind=RPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE), intent(in), optional :: n, dim\n integer(kind=IPRE) :: opt_n, i\n\n opt_n = 1\n if (present(n)) opt_n = n\n\n diff2 = A\n if ((.not. present(dim)) .or. (dim .eq. 1)) then\n do i = 1, opt_n\n diff2 = diff2(2:, :) - diff2(:size(diff2, 1) - 1, :)\n end do\n elseif (dim .eq. 2) then\n do i = 1, opt_n\n diff2 = diff2(:, 2:) - diff2(:, :size(diff2, 2) - 1)\n end do\n end if\n return\n end function diff2\n\n ! eig\n !-----------------------------------------------------------------------\n ! eig computes eigenvalues and eigenvectors of symmetric matrix using\n ! Jacobi algorithm.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! call eig(A, V, d)\n ! call eig(A, V, d, itermax)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! call eig(A, V, d) returns the eigenvalues of the symmetric matrix A\n ! in the vector d and the associated eigenvectors in the matrix V.\n !\n ! call eig(A, V, d) returns eigenvalues and eigenvectors with a maximum\n ! of itermax iterations.\n\n subroutine eig(A, V, d, itermax)\n real(kind=RPRE), dimension(:, :), intent(in) :: A\n real(kind=RPRE), dimension(:, :), allocatable, intent(out) :: V\n real(kind=RPRE), dimension(:), allocatable, intent(out) :: d\n integer(kind=IPRE), intent(in), optional :: itermax\n integer(kind=IPRE) :: opt_itermax, iter, i, j, k, n\n integer(kind=IPRE), dimension(:), allocatable :: idx\n real(kind=RPRE) :: threshold, gapj, termi, termj, h, term, t, &\n theta, c, s, tau, g\n real(kind=RPRE), dimension(:), allocatable :: bw, zw\n real(kind=RPRE), dimension(:, :), allocatable :: B\n\n opt_itermax = 1000\n if (present(itermax)) opt_itermax = itermax\n\n if (.not. issymmetric(A)) then\n stop \"Error: in eig(A), A is not symmetric.\"\n else\n if (allocated(V)) deallocate (V)\n if (allocated(d)) deallocate (d)\n\n B = A\n n = size(B, 1)\n V = eye(n)\n d = diag(B)\n bw = d\n zw = zeros(n)\n\n iter = 0\n do while (iter .lt. opt_itermax)\n iter = iter + 1\n\n threshold = sqrt(sum(triu(B, 1)**2))/(4.0*n)\n if (threshold .eq. 0.0d0) exit\n\n do i = 1, n\n do j = i + 1, n\n gapj = 10.0d0*abs(B(i, j))\n termi = gapj + abs(d(i))\n termj = gapj + abs(d(j))\n\n if ((iter .gt. 4) .and. (termi .eq. abs(d(i))) &\n .and. (termj .eq. abs(d(j)))) then\n B(i, j) = 0.0d0\n elseif (threshold .le. abs(B(i, j))) then\n h = d(j) - d(i)\n term = abs(h) + gapj\n\n if (term .eq. abs(h)) then\n t = B(i, j)/h\n else\n theta = 0.5d0*h/B(i, j)\n t = 1.0d0/(abs(theta) + sqrt(1.0d0 + theta*theta))\n if (theta .lt. 0.0d0) t = -t\n end if\n\n c = 1.0d0/sqrt(1.0d0 + t*t)\n s = t*c\n tau = s/(1.0d0 + c)\n h = t*B(i, j)\n\n zw(i) = zw(i) - h\n zw(j) = zw(j) + h\n d(i) = d(i) - h\n d(j) = d(j) + h\n B(i, j) = 0.0d0\n\n do k = 1, i - 1\n g = B(k, i)\n h = B(k, j)\n B(k, i) = g - s*(h + g*tau)\n B(k, j) = h + s*(g - h*tau)\n end do\n\n do k = i + 1, j - 1\n g = B(i, k)\n h = B(k, j)\n B(i, k) = g - s*(h + g*tau)\n B(k, j) = h + s*(g - h*tau)\n end do\n\n do k = j + 1, n\n g = B(i, k)\n h = B(j, k)\n B(i, k) = g - s*(h + g*tau)\n B(j, k) = h + s*(g - h*tau)\n end do\n\n do k = 1, n\n g = V(k, i)\n h = V(k, j)\n v(k, i) = g - s*(h + g*tau)\n v(k, j) = h + s*(g - h*tau)\n end do\n\n end if\n end do\n end do\n\n bw = bw + zw\n d = bw\n zw = 0.0d0\n end do\n\n idx = argsort(d, 1)\n d = d(idx)\n V = V(:, idx)\n end if\n\n return\n end subroutine eig\n\n ! file_exist\n !-----------------------------------------------------------------------\n ! file_exist determines whether a File object already exists.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! exist = ofile % exist()\n !\n ! Description\n !-----------------------------------------------------------------------\n ! call ofile % exist() returns .true. if the File object ofile exists,\n ! .false. otherwise.\n\n logical function file_exist(self)\n class(File), intent(inout) :: self\n\n inquire (file=trim(self%filename), exist=file_exist)\n return\n end function file_exist\n\n ! File (constructor)\n !-----------------------------------------------------------------------\n ! File constructs a File object.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! ofile = File(unit, filename)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! ofile = File(unit, filename) returns a File object associated to the\n ! file filename with the identifier unit.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! type(File) :: ofile\n !\n ! ofile = File(10, \"myfile.txt\")\n ! call ofile%open()\n ! ! ... some operations on this file ...\n ! call ofile%close()\n\n type(File) function init_File(unit, filename)\n !! test todo\n integer, intent(in) :: unit\n character(len=*), intent(in) :: filename\n\n init_File%unit = unit\n init_File%filename = trim(filename)\n return\n end function init_File\n\n ! find\n !-----------------------------------------------------------------------\n ! find finds indices of values in arrays that satisfy input condition.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! x = find(condition)\n ! A = find(condition)\n ! X = find(condition)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! x = find(condition) returns a vector with the indices of the values\n ! that satisfy condition.\n !\n ! A = find(condition) returns a 2-columns array with the indices of the\n ! values that satisfy condition.\n !\n ! X = find(condition) returns a 3-columns array with the indices of the\n ! values that satisfy condition.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! x = [ 2., 1., 8., 7., 4., 6., 9., 3., 5. ]\n ! y = find(x .ge. 5.)\n ! 3 4 6 7 9\n !\n ! A = diag([1., 2., 3.])\n ! y = find(A .ne. 0.)\n ! 1 1\n ! 2 2\n ! 3 3\n\n function find1(bool)\n integer(kind=IPRE), dimension(:), allocatable :: find1\n logical, dimension(:), intent(in) :: bool\n integer(kind=IPRE) :: i, j, n\n\n n = count(bool)\n if (n .ne. 0) then\n find1 = zeros(n)\n j = 1\n do i = 1, size(bool)\n if (bool(i)) then\n find1(j) = i\n j = j + 1\n end if\n end do\n else\n find1 = zeros(0)\n end if\n return\n end function find1\n\n function find2(bool)\n integer(kind=IPRE), dimension(:, :), allocatable :: find2\n logical, dimension(:, :), intent(in) :: bool\n integer(kind=IPRE) :: i, j, k, n\n\n n = count(bool)\n if (n .ne. 0) then\n find2 = zeros(n, 2)\n k = 1\n do i = 1, size(bool, 1)\n do j = 1, size(bool, 2)\n if (bool(i, j)) then\n find2(k, 1) = i\n find2(k, 2) = j\n k = k + 1\n end if\n end do\n end do\n else\n find2 = zeros(0, 2)\n end if\n return\n end function find2\n\n function find3(bool)\n integer(kind=IPRE), dimension(:, :), allocatable :: find3\n logical, dimension(:, :, :), intent(in) :: bool\n integer(kind=IPRE) :: i, j, k, l, n\n\n n = count(bool)\n if (n .ne. 0) then\n find3 = zeros(n, 3)\n l = 1\n do i = 1, size(bool, 1)\n do j = 1, size(bool, 2)\n do k = 1, size(bool, 3)\n if (bool(i, j, k)) then\n find3(l, 1) = i\n find3(l, 2) = j\n find3(l, 3) = k\n l = l + 1\n end if\n end do\n end do\n end do\n else\n find3 = zeros(0, 3)\n end if\n return\n end function find3\n\n ! fminbnd\n !-----------------------------------------------------------------------\n ! fminbnd solves a 1-dimensional problem defined by\n ! min_x f(x) | a < x < b\n ! with x, a, b finite scalars, and f(x) a function that returns a\n ! scalar. The golden section search algorithm is used.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! x = fminbnd(fitness, a, b)\n ! x = fminbnd(fitness, a, b, eps)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! x = fminbnd(fitness, a, b) returns the scalar x that is a local\n ! minimizer of the function fitness in the interval a < x < b.\n !\n ! x = fminbnd(fitness, a, b, eps) returns the local minimizer x with the\n ! convergence tolerance specified by eps.\n\n real(kind=RPRE) function fminbnd(fitness, a, b, eps)\n procedure(func1d) :: fitness\n real(kind=RPRE), intent(in) :: a, b\n real(kind=RPRE), intent(in), optional :: eps\n real(kind=RPRE) :: opt_eps, x1, x2, x3, x4\n real(kind=RPRE), parameter :: gr = 0.6180339887498949d0\n\n opt_eps = 1.0d-4\n if (present(eps)) opt_eps = eps\n\n x1 = a\n x2 = b\n x3 = x2 - gr*(x2 - x1)\n x4 = x1 + gr*(x2 - x1)\n do while (abs(x3 - x4) .gt. opt_eps)\n if (fitness(x3) .lt. fitness(x4)) then\n x2 = x4\n else\n x1 = x3\n end if\n x3 = x2 - gr*(x2 - x1)\n x4 = x1 + gr*(x2 - x1)\n end do\n fminbnd = 0.5d0*(x1 + x2)\n return\n end function fminbnd\n\n ! flip\n !-----------------------------------------------------------------------\n ! flip reverses order of elements of arrays.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! y = flip(x)\n ! B = flip(A)\n ! B = flip(A, dim)\n ! Y = flip(X)\n ! Y = flip(X, dim)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! y = flip(x) returns the vector x in reversed order.\n !\n ! B = flip(A) returns the matrix A with its rows flipped in the\n ! up-to-down direction.\n !\n ! B = flip(A, dim) returns the matrix A with its elements in reversed\n ! order along the dimension dim.\n !\n ! Y = flip(X) returns the 3-dimensional array X with its elements in\n ! reversed order along the first dimension.\n !\n ! Y = flip(X, dim) returns the 3-dimensional array X with its elements\n ! in reversed order along the dimension dim.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! x = linspace(1, 9, 9)\n ! y = flip(x)\n ! 9. 8. 7. 6. 5. 4. 3. 2. 1.\n !\n ! A = eye(3)\n ! B = flip(A, 1)\n ! 0. 0. 1.\n ! 0. 1. 0.\n ! 1. 0. 0.\n ! C = flip(A, 2)\n ! 0. 0. 1.\n ! 0. 1. 0.\n ! 1. 0. 0.\n\n function flip_i1(x)\n integer(kind=IPRE), dimension(:), allocatable :: flip_i1\n integer(kind=IPRE), dimension(:), intent(in) :: x\n\n flip_i1 = flipud(x)\n return\n end function flip_i1\n\n function flip_r1(x)\n real(kind=RPRE), dimension(:), allocatable :: flip_r1\n real(kind=RPRE), dimension(:), intent(in) :: x\n\n flip_r1 = flipud(x)\n return\n end function flip_r1\n\n function flip_i2(A, dim)\n integer(kind=IPRE), dimension(:, :), allocatable :: flip_i2\n integer(kind=IPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE), intent(in), optional :: dim\n\n if ((.not. present(dim)) .or. (dim .eq. 1)) then\n flip_i2 = flipud(A)\n elseif (dim .eq. 2) then\n flip_i2 = fliplr(A)\n end if\n return\n end function flip_i2\n\n function flip_r2(A, dim)\n real(kind=RPRE), dimension(:, :), allocatable :: flip_r2\n real(kind=RPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE), intent(in), optional :: dim\n\n if ((.not. present(dim)) .or. (dim .eq. 1)) then\n flip_r2 = flipud(A)\n elseif (dim .eq. 2) then\n flip_r2 = fliplr(A)\n end if\n return\n end function flip_r2\n\n function flip_i3(X, dim)\n integer(kind=IPRE), dimension(:, :, :), allocatable :: flip_i3\n integer(kind=IPRE), dimension(:, :, :), intent(in) :: X\n integer(kind=IPRE), intent(in), optional :: dim\n integer(kind=IPRE) :: n\n\n if ((.not. present(dim)) .or. (dim .eq. 1)) then\n n = size(X, 1)\n flip_i3 = X(n:1:-1, :, :)\n elseif (dim .eq. 2) then\n n = size(X, 2)\n flip_i3 = X(:, n:1:-1, :)\n elseif (dim .eq. 3) then\n n = size(X, 3)\n flip_i3 = X(:, :, n:1:-1)\n end if\n return\n end function flip_i3\n\n function flip_r3(X, dim)\n real(kind=IPRE), dimension(:, :, :), allocatable :: flip_r3\n real(kind=IPRE), dimension(:, :, :), intent(in) :: X\n integer(kind=IPRE), intent(in), optional :: dim\n integer(kind=IPRE) :: n\n\n if ((.not. present(dim)) .or. (dim .eq. 1)) then\n n = size(X, 1)\n flip_r3 = X(n:1:-1, :, :)\n elseif (dim .eq. 2) then\n n = size(X, 2)\n flip_r3 = X(:, n:1:-1, :)\n elseif (dim .eq. 3) then\n n = size(X, 3)\n flip_r3 = X(:, :, n:1:-1)\n end if\n return\n end function flip_r3\n\n ! fliplr\n !-----------------------------------------------------------------------\n ! fliplr reverses vector and matrix left to right.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! y = fliplr(x)\n ! B = fliplr(A)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! y = fliplr(x) returns the vector x in reversed order.\n !\n ! B = fliplr(A) returns the matrix A with its columns flipped in the\n ! left-to-right direction.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! x = linspace(1, 9, 9)\n ! y = fliplr(x)\n ! 9. 8. 7. 6. 5. 4. 3. 2. 1.\n !\n ! A = eye(3)\n ! B = fliplr(A)\n ! 0. 0. 1.\n ! 0. 1. 0.\n ! 1. 0. 0.\n\n function fliplr_i1(x)\n integer(kind=IPRE), dimension(:), allocatable :: fliplr_i1\n integer(kind=IPRE), dimension(:), intent(in) :: x\n integer(kind=IPRE) :: n\n\n n = size(x)\n fliplr_i1 = x(n:1:-1)\n return\n end function fliplr_i1\n\n function fliplr_r1(x)\n real(kind=RPRE), dimension(:), allocatable :: fliplr_r1\n real(kind=RPRE), dimension(:), intent(in) :: x\n integer(kind=IPRE) :: n\n\n n = size(x)\n fliplr_r1 = x(n:1:-1)\n return\n end function fliplr_r1\n\n function fliplr_i2(A)\n integer(kind=IPRE), dimension(:, :), allocatable :: fliplr_i2\n integer(kind=IPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE) :: n\n\n n = size(A, 2)\n fliplr_i2 = A(:, n:1:-1)\n return\n end function fliplr_i2\n\n function fliplr_r2(A)\n real(kind=RPRE), dimension(:, :), allocatable :: fliplr_r2\n real(kind=RPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE) :: n\n\n n = size(A, 2)\n fliplr_r2 = A(:, n:1:-1)\n return\n end function fliplr_r2\n\n ! flipud\n !-----------------------------------------------------------------------\n ! flipud reverses vector and matrix up to down.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! y = flipud(x)\n ! B = flipud(A)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! y = flipud(x) returns the vector x in reversed order.\n !\n ! B = flipud(A) returns the matrix A with its rows flipped in the\n ! up-to-down direction.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! x = linspace(1, 9, 9)\n ! y = flipud(x)\n ! 9. 8. 7. 6. 5. 4. 3. 2. 1.\n !\n ! A = eye(3)\n ! B = flipud(A)\n ! 0. 0. 1.\n ! 0. 1. 0.\n ! 1. 0. 0.\n\n function flipud_i1(x)\n integer(kind=IPRE), dimension(:), allocatable :: flipud_i1\n integer(kind=IPRE), dimension(:), intent(in) :: x\n integer(kind=IPRE) :: n\n\n n = size(x)\n flipud_i1 = x(n:1:-1)\n return\n end function flipud_i1\n\n function flipud_r1(x)\n real(kind=RPRE), dimension(:), allocatable :: flipud_r1\n real(kind=RPRE), dimension(:), intent(in) :: x\n integer(kind=IPRE) :: n\n\n n = size(x)\n flipud_r1 = x(n:1:-1)\n return\n end function flipud_r1\n\n function flipud_i2(A)\n integer(kind=IPRE), dimension(:, :), allocatable :: flipud_i2\n integer(kind=IPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE) :: n\n\n n = size(A, 1)\n flipud_i2 = A(n:1:-1, :)\n return\n end function flipud_i2\n\n function flipud_r2(A)\n real(kind=RPRE), dimension(:, :), allocatable :: flipud_r2\n real(kind=RPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE) :: n\n\n n = size(A, 1)\n flipud_r2 = A(n:1:-1, :)\n return\n end function flipud_r2\n\n ! gammainc\n !-----------------------------------------------------------------------\n ! gammainc returns the incomplete gamma function.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! y = gammainc(x, a)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! y = gammainc(x, a) returns the incomplete gamma function of\n ! corresponding elements of x and a.\n\n real(kind=RPRE) function gammainc0(x, a)\n real(kind=RPRE), intent(in) :: x, a\n\n if (x .lt. 0. .or. a .le. 0.) then\n print *, \"Error: in gammainc, x < 0 and/or a <= 0\"\n stop\n end if\n if (x .lt. a + 1.) then\n gammainc0 = gser(x, a)\n else\n gammainc0 = 1.-gcf(x, a)\n end if\n\n return\n contains\n\n real(kind=RPRE) function gser(x, a)\n real(kind=RPRE), intent(in) :: x, a\n integer(kind=IPRE), parameter :: itermax = 100\n real(kind=RPRE), parameter :: eps = 3.e-7\n integer(kind=IPRE) :: n\n real(kind=RPRE) :: gln, ap, del, s\n\n gln = log(gamma(a))\n if (x .le. 0.) then\n gser = 0.\n else\n ap = a\n s = 1./a\n del = s\n do n = 1, itermax\n ap = ap + 1.\n del = del*x/ap\n s = s + del\n if (abs(del) .lt. abs(s)*eps) exit\n end do\n gser = s*exp(-x + a*log(x) - gln)\n end if\n return\n end function gser\n\n real(kind=RPRE) function gcf(x, a)\n real(kind=RPRE), intent(in) :: x, a\n integer(kind=IPRE), parameter :: itermax = 100\n real(kind=RPRE), parameter :: eps = 3.e-7, fpmin = 1.e-30\n integer(kind=IPRE) :: i\n real(kind=RPRE) :: an, b, c, d, del, h, gln\n\n gln = log(gamma(a))\n b = x + 1.-a\n c = 1./fpmin\n d = 1./b\n h = d\n do i = 1, itermax\n an = -i*(i - a)\n b = b + 2\n d = an*d + b\n if (abs(d) .lt. fpmin) d = fpmin\n c = b + an/c\n if (abs(c) .lt. fpmin) c = fpmin\n d = 1./d\n del = d*c\n h = h*del\n if (abs(del - 1.) .lt. eps) exit\n end do\n gcf = h*exp(-x + a*log(x) - gln)\n return\n end function gcf\n\n end function gammainc0\n\n function gammainc1_0(X, a)\n real(kind=RPRE), dimension(:), allocatable :: gammainc1_0\n real(kind=RPRE), dimension(:), intent(in) :: X\n real(kind=RPRE), intent(in) :: a\n integer(kind=IPRE) :: i, n\n\n n = size(X)\n gammainc1_0 = zeros(n)\n do i = 1, n\n gammainc1_0(i) = gammainc0(X(i), a)\n end do\n return\n end function\n\n ! gmm\n !-----------------------------------------------------------------------\n ! gmm performs Gaussian Mixture Modelling using Expectation-Maximization\n ! algorithm.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! idx = gmm(x, K, [options = ])\n ! idx = gmm(A, K, [options = ])\n !\n ! Description\n !-----------------------------------------------------------------------\n ! idx = gmm(x, K, [options = ]) returns the cluster indices of each\n ! element in vector x.\n !\n ! idx = gmm(A, K, [options = ]) returns the cluster indices of each\n ! rows in matrix A.\n !\n ! Options\n !-----------------------------------------------------------------------\n ! means Output centroids\n ! stdev / covar Output standard deviation / covariance matrix\n ! prob Output probabilities\n ! itermax = 1000 Maximum number of iterations\n ! niter Output number of iterations\n\n function gmm1(x, K, means, stdev, prob, itermax, niter) result(idx)\n integer(kind=IPRE), dimension(:), allocatable :: idx\n real(kind=RPRE), dimension(:), intent(in) :: x\n integer(kind=IPRE), intent(in) :: K\n real(kind=RPRE), dimension(:), allocatable, intent(inout), optional :: prob, means, stdev\n integer(kind=IPRE), intent(in), optional :: itermax\n integer(kind=IPRE), intent(inout), optional :: niter\n integer(kind=IPRE) :: opt_itermax, i, j, n, iter\n real(kind=RPRE), dimension(:), allocatable :: phi, mu, mu_prev, sigma\n real(kind=RPRE), dimension(:, :), allocatable :: w, pdf, pdf_w\n\n n = size(x)\n\n opt_itermax = 1000\n if (present(itermax)) opt_itermax = itermax\n\n ! Initialization\n !================\n phi = ones(K)/real(K) ! Equal initial probabilities for each cluster\n mu = x(randperm(n, K)) ! Random initial means\n sigma = ones(K)*std(x) ! Covariance matrices for each variable\n\n ! Loop until convergence\n !========================\n w = zeros(n, K)\n iter = 0\n do while (iter .lt. opt_itermax)\n iter = iter + 1\n\n ! Expectation\n !=============\n pdf = zeros(n, K)\n do j = 1, K\n pdf(:, j) = normpdf(x, mu(j), sigma(j))\n end do\n\n pdf_w = pdf*repmat(phi, n, 2)\n w = pdf_w/repmat(sum(pdf_w, dim=2), K)\n\n ! Maximization\n !==============\n mu_prev = mu\n do j = 1, K\n phi(j) = mean(w(:, j))\n mu(j) = dot_product(w(:, j), x)/sum(w(:, j))\n sigma(j) = dot_product(w(:, j), (x - mu(j))**2)/sum(w(:, j))\n sigma(j) = sqrt(sigma(j))\n end do\n\n if (norm(mu - mu_prev) .lt. 1.0d-10) exit\n end do\n\n idx = zeros(n)\n do i = 1, n\n idx(i:i) = maxloc(pdf(i, :))\n end do\n\n if (present(niter)) niter = iter\n if (present(means)) means = mu\n if (present(stdev)) stdev = sigma\n if (present(prob)) prob = phi\n\n return\n end function gmm1\n\n function gmm2(A, K, means, covar, prob, itermax, niter) result(idx)\n integer(kind=IPRE), dimension(:), allocatable :: idx\n real(kind=RPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE), intent(in) :: K\n real(kind=RPRE), dimension(:), allocatable, intent(inout), optional :: prob\n real(kind=RPRE), dimension(:, :), allocatable, intent(inout), optional :: means\n real(kind=RPRE), dimension(:, :, :), allocatable, intent(inout), optional :: covar\n integer(kind=IPRE), intent(in), optional :: itermax\n integer(kind=IPRE), intent(inout), optional :: niter\n\n integer(kind=IPRE) :: opt_itermax, i, j, n, p, iter\n real(kind=RPRE), dimension(:), allocatable :: phi\n real(kind=RPRE), dimension(:, :), allocatable :: mu, mu_prev, w, pdf, &\n pdf_w, tmp\n real(kind=RPRE), dimension(:, :, :), allocatable :: sigma\n\n n = size(A, 1)\n p = size(A, 2)\n\n opt_itermax = 1000\n if (present(itermax)) opt_itermax = itermax\n\n ! Initialization\n !================\n phi = ones(K)/real(K) ! Equal initial probabilities for each cluster\n mu = A(randperm(n, K), :) ! Random initial means\n sigma = zeros(p, p, K) ! Covariance matrices for each variable\n\n tmp = cov(A)\n do j = 1, K\n sigma(:, :, j) = tmp\n end do\n\n ! Loop until convergence\n !========================\n w = zeros(n, K)\n iter = 0\n do while (iter .lt. opt_itermax)\n iter = iter + 1\n\n ! Expectation\n !=============\n pdf = zeros(n, K)\n do j = 1, K\n pdf(:, j) = normpdf(A, mu(j, :), sigma(:, :, j))\n end do\n\n pdf_w = pdf*repmat(phi, n, 2)\n w = pdf_w/repmat(sum(pdf_w, dim=2), K)\n\n ! Maximization\n !==============\n mu_prev = mu\n do j = 1, K\n phi(j) = mean(w(:, j))\n mu(j, :) = matmul(w(:, j), A)/sum(w(:, j))\n tmp = A - repmat(mu(j, :), n, 2)\n\n sigma(:, :, j) = zeros(p, p)\n do i = 1, n\n sigma(:, :, j) = sigma(:, :, j) &\n + w(i, j)*matmul(transpose(tmp(i:i, :)), tmp(i:i, :)) &\n /sum(w(:, j))\n end do\n end do\n\n if (means_residuals(mu, mu_prev) .lt. 1.0d-10) exit\n end do\n\n idx = zeros(n)\n do i = 1, n\n idx(i:i) = maxloc(pdf(i, :))\n end do\n\n if (present(niter)) niter = iter\n if (present(means)) means = mu\n if (present(covar)) covar = sigma\n if (present(prob)) prob = phi\n\n return\n contains\n\n !-------------------------------------------------------------------\n ! means_residuals\n !-------------------------------------------------------------------\n function means_residuals(means1, means2) result(eps)\n real(kind=RPRE) :: eps\n real(kind=RPRE), dimension(:, :), intent(in) :: means1, means2\n real(kind=RPRE), dimension(:, :), allocatable :: means\n integer(kind=IPRE) :: k\n\n eps = 0.0d0\n means = abs(means2 - means1)\n do k = 1, p\n eps = eps + sum(means(:, k))**2\n end do\n eps = sqrt(eps)\n return\n end function means_residuals\n\n end function gmm2\n\n ! horzcat\n !-----------------------------------------------------------------------\n ! horzcat concatenates arrays horizontally.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! A = horzcat(x1, x2)\n ! A = horzcat(A1, A2)\n ! B = horzcat(x1, A2)\n ! B = horzcat(A1, x2)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! A = horzcat(x1, x2) concatenates the vectors x1 and x2 treated as\n ! column vectors along the dimension 1. If the length of x1 and x2 are\n ! not equal, empty elements will be filled with zeros.\n !\n ! A = horzcat(A1, A2) concatenates the matrices A1 and A2 along the\n ! dimension 1. If the first dimensions of A1 and A2 are not equal, empty\n ! elements will be filled with zeros.\n !\n ! B = horzcat(x1, A2) concatenates the vector x treated as column vector\n ! and the matrix A along the dimension 1. If the length of x and the\n ! first dimension of A are not equal, empty elements will be filled with\n ! zeros.\n !\n ! B = horzcat(A1, x2) concatenates the matrix A and the vector x treated\n ! as column vector along the dimension 1. If the first dimension o A and\n ! the length of x are not equal, empty elements will be filled with\n ! zeros.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! A1 = reshape([ 1., 2., 3., 4. ], [ 2, 2 ], order = [ 2, 1 ])\n ! A2 = reshape([ 5., 6., 7., 8. ], [ 2, 2 ], order = [ 2, 1 ])\n ! A = horzcat(A1, A2)\n ! 1. 2. 5. 6.\n ! 3. 4. 7. 8.\n\n function horzcat_i1(x1, x2)\n integer(kind=IPRE), dimension(:, :), allocatable :: horzcat_i1\n integer(kind=IPRE), dimension(:), intent(in) :: x1, x2\n integer(kind=IPRE) :: m1, m2\n\n m1 = size(x1)\n m2 = size(x2)\n\n horzcat_i1 = zeros(max(m1, m2), 2)\n horzcat_i1(1:m1, 1) = x1\n horzcat_i1(1:m2, 2) = x2\n return\n end function horzcat_i1\n\n function horzcat_r1(x1, x2)\n real(kind=RPRE), dimension(:, :), allocatable :: horzcat_r1\n real(kind=RPRE), dimension(:), intent(in) :: x1, x2\n integer(kind=IPRE) :: m1, m2\n\n m1 = size(x1)\n m2 = size(x2)\n\n horzcat_r1 = zeros(max(m1, m2), 2)\n horzcat_r1(1:m1, 1) = x1\n horzcat_r1(1:m2, 2) = x2\n return\n end function horzcat_r1\n\n function horzcat_i2(A1, A2)\n integer(kind=IPRE), dimension(:, :), allocatable :: horzcat_i2\n integer(kind=IPRE), dimension(:, :), intent(in) :: A1, A2\n integer(kind=IPRE) :: m1, n1, m2, n2\n\n m1 = size(A1, 1)\n n1 = size(A1, 2)\n m2 = size(A2, 1)\n n2 = size(A2, 2)\n\n horzcat_i2 = zeros(max(m1, m2), n1 + n2)\n horzcat_i2(1:m1, 1:n1) = A1\n horzcat_i2(1:m2, n1 + 1:) = A2\n return\n end function horzcat_i2\n\n function horzcat_r2(A1, A2)\n real(kind=RPRE), dimension(:, :), allocatable :: horzcat_r2\n real(kind=RPRE), dimension(:, :), intent(in) :: A1, A2\n integer(kind=IPRE) :: m1, n1, m2, n2\n\n m1 = size(A1, 1)\n n1 = size(A1, 2)\n m2 = size(A2, 1)\n n2 = size(A2, 2)\n\n horzcat_r2 = zeros(max(m1, m2), n1 + n2)\n horzcat_r2(1:m1, 1:n1) = A1\n horzcat_r2(1:m2, n1 + 1:) = A2\n return\n end function horzcat_r2\n\n function horzcat_i12(x1, A2)\n integer(kind=IPRE), dimension(:, :), allocatable :: horzcat_i12\n integer(kind=IPRE), dimension(:), intent(in) :: x1\n integer(kind=IPRE), dimension(:, :), intent(in) :: A2\n integer(kind=IPRE) :: m1, m2, n2\n\n m1 = size(x1)\n m2 = size(A2, 1)\n n2 = size(A2, 2)\n\n horzcat_i12 = zeros(max(m1, m2), n2 + 1)\n horzcat_i12(1:m1, 1) = x1\n horzcat_i12(1:m2, 2:) = A2\n return\n end function horzcat_i12\n\n function horzcat_r12(x1, A2)\n real(kind=RPRE), dimension(:, :), allocatable :: horzcat_r12\n real(kind=RPRE), dimension(:), intent(in) :: x1\n real(kind=RPRE), dimension(:, :), intent(in) :: A2\n integer(kind=IPRE) :: m1, m2, n2\n\n m1 = size(x1)\n m2 = size(A2, 1)\n n2 = size(A2, 2)\n\n horzcat_r12 = zeros(max(m1, m2), n2 + 1)\n horzcat_r12(1:m1, 1) = x1\n horzcat_r12(1:m2, 2:) = A2\n return\n end function horzcat_r12\n\n function horzcat_i21(A1, x2)\n integer(kind=IPRE), dimension(:, :), allocatable :: horzcat_i21\n integer(kind=IPRE), dimension(:, :), intent(in) :: A1\n integer(kind=IPRE), dimension(:), intent(in) :: x2\n integer(kind=IPRE) :: m1, n1, m2\n\n m1 = size(A1, 1)\n n1 = size(A1, 2)\n m2 = size(x2)\n\n horzcat_i21 = zeros(max(m1, m2), n1 + 1)\n horzcat_i21(1:m1, 1:n1) = A1\n horzcat_i21(1:m2, n1 + 1) = x2\n return\n end function horzcat_i21\n\n function horzcat_r21(A1, x2)\n real(kind=RPRE), dimension(:, :), allocatable :: horzcat_r21\n real(kind=RPRE), dimension(:, :), intent(in) :: A1\n real(kind=RPRE), dimension(:), intent(in) :: x2\n integer(kind=IPRE) :: m1, n1, m2\n\n m1 = size(A1, 1)\n n1 = size(A1, 2)\n m2 = size(x2)\n\n horzcat_r21 = zeros(max(m1, m2), n1 + 1)\n horzcat_r21(1:m1, 1:n1) = A1\n horzcat_r21(1:m2, n1 + 1) = x2\n return\n end function horzcat_r21\n\n ! hann\n !-----------------------------------------------------------------------\n ! hann defines a Hanning window.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! w = hann(n)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! w = hann(n) returns an n-point symmetric Hanning window.\n\n function hann(n)\n real(kind=RPRE), dimension(:), allocatable :: hann\n integer(kind=IPRE), intent(in) :: n\n\n hann = 0.5d0*(1 - cos(2.0d0*pi*linspace(0, n - 1, n)/n))\n return\n end function hann\n\n ! interp1\n !-----------------------------------------------------------------------\n ! interp1 performs a linear interpolation.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! vq = interp1(x, v, xq)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! vq = interp1(x, v, xq) returns the evaluated vector yq at the query\n ! points in xq using a linear interpolation.\n\n function interp1_0(x, v, xq) result(vq)\n real(kind=RPRE) :: vq\n real(kind=RPRE), intent(in) :: xq\n real(kind=RPRE), dimension(:), intent(in) :: x, v\n integer(kind=IPRE) :: i, x1, x2, ix(2)\n real(kind=RPRE) :: vn, xr(2), vr(2)\n\n x1 = minloc(xq - x, 1, mask=xq .ge. x)\n x2 = maxloc(xq - x, 1, mask=xq .lt. x)\n if (x2 .ne. 0) then\n vn = abs((x(x2) - x(x1)))\n xr = x([x1, x2])\n vr = v([x1, x2])\n vq = vr(1)*(xr(2) - xq) + vr(2)*(xq - xr(1))\n vq = vq/vn\n else\n vq = v(size(v))\n end if\n return\n end function interp1_0\n\n function interp1_1(x, v, xq) result(vq)\n real(kind=RPRE), dimension(:), allocatable :: vq\n real(kind=RPRE), dimension(:), intent(in) :: xq, x, v\n integer(kind=IPRE) :: i, n\n\n n = size(xq)\n vq = zeros(n)\n do i = 1, n\n vq(i) = interp1_0(x, v, xq(i))\n end do\n return\n end function interp1_1\n\n ! interp2\n !-----------------------------------------------------------------------\n ! interp2 performs a bilinear interpolation.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! vq = interp2(x, y, V, xq, yq)\n ! VQ = interp2(x, y, V, XQ, YQ)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! vq = interp2(x, y, V, xq, yq) returns the evaluated vector vq at the\n ! query points in xq and yq using a bilinear interpolation.\n !\n ! VQ = interp2(x, y, V, XQ, YQ) returns the evaluated matrix VQ given\n ! mesh type grids XQ and YQ using a bilinear interpolation. VQ is of the\n ! same shape as XQ and YQ.\n\n function interp2_0(x, y, v, xq, yq) result(vq)\n real(kind=RPRE) :: vq\n real(kind=RPRE), intent(in) :: xq, yq\n real(kind=RPRE), dimension(:), intent(in) :: x, y\n real(kind=RPRE), dimension(:, :), intent(in) :: v\n integer(kind=IPRE) :: i, x1, y1, x2, y2, ix(4), iy(4)\n real(kind=RPRE) :: vn, xr(2), yr(2), N(4), vr(4)\n\n x1 = minloc(xq - x, 1, mask=xq .ge. x)\n y1 = minloc(yq - y, 1, mask=yq .ge. y)\n x2 = maxloc(xq - x, 1, mask=xq .lt. x)\n y2 = maxloc(yq - y, 1, mask=yq .lt. y)\n vn = abs((x(x2) - x(x1)) &\n *(y(y2) - y(y1)))\n xr = x([x1, x2])\n yr = y([y1, y2])\n ix = [2, 1, 2, 1]\n iy = [2, 2, 1, 1]\n do i = 1, 4\n N(i) = abs((xr(ix(i)) - xq)*(yr(iy(i)) - yq))\n end do\n vr = reshape(v([x1, x2], &\n [y1, y2]), shape=[4])\n vq = dot_product(vr, N/vn)\n return\n end function interp2_0\n\n function interp2_1(x, y, v, xq, yq) result(vq)\n real(kind=RPRE), dimension(:), allocatable :: vq\n real(kind=RPRE), dimension(:), intent(in) :: xq, yq, x, y\n real(kind=RPRE), dimension(:, :), intent(in) :: v\n integer(kind=IPRE) :: i, n\n\n n = size(xq)\n vq = zeros(n)\n do i = 1, n\n vq(i) = interp2_0(x, y, v, xq(i), yq(i))\n end do\n return\n end function interp2_1\n\n function interp2_2(x, y, v, xq, yq) result(vq)\n real(kind=RPRE), dimension(:, :), allocatable :: vq\n real(kind=RPRE), dimension(:), intent(in) :: x, y\n real(kind=RPRE), dimension(:, :), intent(in) :: v, xq, yq\n integer(kind=IPRE) :: m, n\n\n m = size(xq, 1)\n n = size(xq, 2)\n vq = reshape(interp2_1(y, x, v, [yq], [xq]), shape=[m, n])\n return\n end function interp2_2\n\n ! interp3\n !-----------------------------------------------------------------------\n ! interp3 performs a trilinear interpolation.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! vq = interp3(x, y, z, v, xq, yq, zq)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! vq = interp3(x, y, z, v, xq, yq, zq) returns the evaluated vector vq\n ! at the query points in xq, yq and zq using a trilinear interpolation.\n\n function interp3_0(x, y, z, v, xq, yq, zq) result(vq)\n real(kind=RPRE) :: vq\n real(kind=RPRE), intent(in) :: xq, yq, zq\n real(kind=RPRE), dimension(:), intent(in) :: x, y, z\n real(kind=RPRE), dimension(:, :, :), intent(in) :: v\n integer(kind=IPRE) :: i, x1, y1, z1, x2, y2, z2, &\n ix(8), iy(8), iz(8)\n real(kind=RPRE) :: vn, xr(2), yr(2), zr(2), N(8), vr(8)\n\n x1 = minloc(xq - x, 1, mask=xq .ge. x)\n y1 = minloc(yq - y, 1, mask=yq .ge. y)\n z1 = minloc(zq - z, 1, mask=zq .ge. z)\n x2 = maxloc(xq - x, 1, mask=xq .lt. x)\n y2 = maxloc(yq - y, 1, mask=yq .lt. y)\n z2 = maxloc(zq - z, 1, mask=zq .lt. z)\n vn = abs((x(x2) - x(x1)) &\n *(y(y2) - y(y1)) &\n *(z(z2) - z(z1)))\n xr = x([x1, x2])\n yr = y([y1, y2])\n zr = z([z1, z2])\n ix = [2, 1, 2, 1, 2, 1, 2, 1]\n iy = [2, 2, 1, 1, 2, 2, 1, 1]\n iz = [2, 2, 2, 2, 1, 1, 1, 1]\n do i = 1, 8\n N(i) = abs((xr(ix(i)) - xq)*(yr(iy(i)) - yq)*(zr(iz(i)) - zq))\n end do\n vr = reshape(v([x1, x2], &\n [y1, y2], &\n [z1, z2]), shape=[8])\n vq = dot_product(vr, N/vn)\n return\n end function interp3_0\n\n function interp3_1(x, y, z, v, xq, yq, zq) result(vq)\n real(kind=RPRE), dimension(:), allocatable :: vq\n real(kind=RPRE), dimension(:), intent(in) :: xq, yq, zq, x, y, z\n real(kind=RPRE), dimension(:, :, :), intent(in) :: v\n integer(kind=IPRE) :: i, n\n\n n = size(xq)\n vq = zeros(n)\n do i = 1, n\n vq(i) = interp3_0(x, y, z, v, xq(i), yq(i), zq(i))\n end do\n return\n end function interp3_1\n\n logical function isleap(year)\n integer(kind=IPRE), intent(in) :: year\n if ((mod(year, 400) .eq. 0) .or. &\n ((mod(year, 4) .eq. 0) .and. (mod(year, 100) .ne. 0))) then\n isleap = .true.\n else\n isleap = .false.\n end if\n return\n end function isleap\n\n ! ismember\n !-----------------------------------------------------------------------\n ! ismember determines whether a value is present in an array.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! bool = ismember(x, y)\n ! bool = ismember(x, A)\n ! bool = ismember(x, Y)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! bool = ismember(x, y) returns .true. if x is present in the\n ! 1-dimensional array y, .false. otherwise.\n !\n ! bool = ismember(x, A) returns .true. if x is present in the\n ! 2-dimensional array A, .false. otherwise.\n !\n ! bool = ismember(x, Y) returns .true. if x is present in the\n ! 3-dimensional array Y, .false. otherwise.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! y = [ 1., 2., 3., 4., 5. ]\n ! bool = ismember(3., y)\n ! .true.\n ! bool = ismember(6., y)\n ! .false.\n\n logical function ismember_i0i1(x, y)\n integer(kind=IPRE), intent(in) :: x\n integer(kind=IPRE), dimension(:), intent(in) :: y\n integer(kind=IPRE) :: i, dim1\n\n ismember_i0i1 = .false.\n dim1 = size(y)\n do i = 1, dim1\n if (x .eq. y(i)) then\n ismember_i0i1 = .true.\n return\n end if\n end do\n return\n end function ismember_i0i1\n\n logical function ismember_i0r1(x, y)\n integer(kind=IPRE), intent(in) :: x\n real(kind=RPRE), dimension(:), intent(in) :: y\n integer(kind=IPRE) :: i, dim1\n\n ismember_i0r1 = .false.\n dim1 = size(y)\n do i = 1, dim1\n if (x .eq. y(i)) then\n ismember_i0r1 = .true.\n return\n end if\n end do\n return\n end function ismember_i0r1\n\n logical function ismember_i0i2(x, A)\n integer(kind=IPRE), intent(in) :: x\n integer(kind=IPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE) :: i, j, dim1, dim2\n\n ismember_i0i2 = .false.\n dim1 = size(A, 1)\n dim2 = size(A, 2)\n do i = 1, dim1\n do j = 1, dim2\n if (x .eq. A(i, j)) then\n ismember_i0i2 = .true.\n return\n end if\n end do\n end do\n return\n end function ismember_i0i2\n\n logical function ismember_i0r2(x, A)\n integer(kind=IPRE), intent(in) :: x\n real(kind=RPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE) :: i, j, dim1, dim2\n\n ismember_i0r2 = .false.\n dim1 = size(A, 1)\n dim2 = size(A, 2)\n do i = 1, dim1\n do j = 1, dim2\n if (x .eq. A(i, j)) then\n ismember_i0r2 = .true.\n return\n end if\n end do\n end do\n return\n end function ismember_i0r2\n\n logical function ismember_i0i3(x, Y)\n integer(kind=IPRE), intent(in) :: x\n integer(kind=IPRE), dimension(:, :, :), intent(in) :: Y\n integer(kind=IPRE) :: i, j, k, dim1, dim2, dim3\n\n ismember_i0i3 = .false.\n dim1 = size(Y, 1)\n dim2 = size(Y, 2)\n dim3 = size(Y, 3)\n do i = 1, dim1\n do j = 1, dim2\n do k = 1, dim2\n if (x .eq. Y(i, j, k)) then\n ismember_i0i3 = .true.\n return\n end if\n end do\n end do\n end do\n return\n end function ismember_i0i3\n\n logical function ismember_i0r3(x, Y)\n integer(kind=IPRE), intent(in) :: x\n real(kind=RPRE), dimension(:, :, :), intent(in) :: Y\n integer(kind=IPRE) :: i, j, k, dim1, dim2, dim3\n\n ismember_i0r3 = .false.\n dim1 = size(Y, 1)\n dim2 = size(Y, 2)\n dim3 = size(Y, 3)\n do i = 1, dim1\n do j = 1, dim2\n do k = 1, dim2\n if (x .eq. Y(i, j, k)) then\n ismember_i0r3 = .true.\n return\n end if\n end do\n end do\n end do\n return\n end function ismember_i0r3\n\n logical function ismember_r0i1(x, y)\n real(kind=RPRE), intent(in) :: x\n integer(kind=IPRE), dimension(:), intent(in) :: y\n integer(kind=IPRE) :: i, dim1\n\n ismember_r0i1 = .false.\n dim1 = size(y)\n do i = 1, dim1\n if (x .eq. y(i)) then\n ismember_r0i1 = .true.\n return\n end if\n end do\n return\n end function ismember_r0i1\n\n logical function ismember_r0r1(x, y)\n real(kind=RPRE), intent(in) :: x\n real(kind=RPRE), dimension(:), intent(in) :: y\n integer(kind=IPRE) :: i, dim1\n\n ismember_r0r1 = .false.\n dim1 = size(y)\n do i = 1, dim1\n if (x .eq. y(i)) then\n ismember_r0r1 = .true.\n return\n end if\n end do\n return\n end function ismember_r0r1\n\n logical function ismember_r0i2(x, A)\n real(kind=RPRE), intent(in) :: x\n integer(kind=IPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE) :: i, j, dim1, dim2\n\n ismember_r0i2 = .false.\n dim1 = size(A, 1)\n dim2 = size(A, 2)\n do i = 1, dim1\n do j = 1, dim2\n if (x .eq. A(i, j)) then\n ismember_r0i2 = .true.\n return\n end if\n end do\n end do\n return\n end function ismember_r0i2\n\n logical function ismember_r0r2(x, A)\n real(kind=RPRE), intent(in) :: x\n real(kind=RPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE) :: i, j, dim1, dim2\n\n ismember_r0r2 = .false.\n dim1 = size(A, 1)\n dim2 = size(A, 2)\n do i = 1, dim1\n do j = 1, dim2\n if (x .eq. A(i, j)) then\n ismember_r0r2 = .true.\n return\n end if\n end do\n end do\n return\n end function ismember_r0r2\n\n logical function ismember_r0i3(x, Y)\n real(kind=RPRE), intent(in) :: x\n integer(kind=IPRE), dimension(:, :, :), intent(in) :: Y\n integer(kind=IPRE) :: i, j, k, dim1, dim2, dim3\n\n ismember_r0i3 = .false.\n dim1 = size(Y, 1)\n dim2 = size(Y, 2)\n dim3 = size(Y, 3)\n do i = 1, dim1\n do j = 1, dim2\n do k = 1, dim2\n if (x .eq. Y(i, j, k)) then\n ismember_r0i3 = .true.\n return\n end if\n end do\n end do\n end do\n return\n end function ismember_r0i3\n\n logical function ismember_r0r3(x, Y)\n real(kind=RPRE), intent(in) :: x\n real(kind=RPRE), dimension(:, :, :), intent(in) :: Y\n integer(kind=IPRE) :: i, j, k, dim1, dim2, dim3\n\n ismember_r0r3 = .false.\n dim1 = size(Y, 1)\n dim2 = size(Y, 2)\n dim3 = size(Y, 3)\n do i = 1, dim1\n do j = 1, dim2\n do k = 1, dim2\n if (x .eq. Y(i, j, k)) then\n ismember_r0r3 = .true.\n return\n end if\n end do\n end do\n end do\n return\n end function ismember_r0r3\n\n ! isoutlier\n !-----------------------------------------------------------------------\n ! isoutlier determines outliers in a vector.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! bool = isoutlier(x)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! bool = isoutlier(x) returns a logical vector with .true. if x(i) is\n ! an outlier, .false. otherwise.\n\n function isoutlier(x, m)\n logical, dimension(:), allocatable :: isoutlier\n real(kind=RPRE), dimension(:), intent(in) :: x\n integer(kind=IPRE), intent(in), optional :: m\n integer(kind=IPRE) :: opt_m\n\n opt_m = 3\n if (present(m)) opt_m = m\n isoutlier = abs(x - median(x)) .gt. opt_m*mad(x, 2)\n return\n end function isoutlier\n\n ! issymmetric\n !-----------------------------------------------------------------------\n ! issymmetric determines whether a square matrix is symmetric.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! bool = issymmetric(A)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! bool = issymmetric(A) returns .true. if A is symmetric, .false.\n ! otherwise.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! A = eye(3)\n ! bool = issymmetric(A)\n ! .true.\n\n logical function issymmetric(A)\n real(kind=RPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE) :: i, j, n\n\n issymmetric = .true.\n if (.not. issquare(A)) then\n issymmetric = .false.\n return\n else\n n = size(A, 1)\n do i = 1, n\n do j = 1, n\n if (A(i, j) .ne. A(j, i)) then\n issymmetric = .false.\n return\n end if\n end do\n end do\n end if\n return\n end function issymmetric\n\n ! k2test\n !-----------------------------------------------------------------------\n ! k2test performs the D'Agostino-Pearson's K2 test to assess normality\n ! of a distribution.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! p = k2test(x)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! p = k2test(x) returns the p-value for the null hypothesis that the\n ! data in vector x comes from a normal distribution. According to\n ! Fisher, the null hypothesis is highly rejectable for p-values lower\n ! that 0.05.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! x = randn(1000)\n ! p1 = k2test(x)\n ! 0.551972866 ! > 0.05\n !\n ! y = randu(1000)\n ! p2 = k2test(y)\n ! 0.000000000 ! < 0.05\n !\n ! Notes\n !-----------------------------------------------------------------------\n ! The K2 statistic has approximately a chi-squared distribution with\n ! k = 2 degrees of freedom when the population is normally distributed.\n ! The CDF of the chi-squared with 2 degrees of freedom can be written:\n ! F(x,2) = 1 - exp(-x/2)\n\n function k2test(x) result(p)\n real(kind=RPRE) :: p\n real(kind=RPRE), dimension(:), intent(in) :: x\n integer(kind=8) :: n\n real(kind=8) :: b1, b2, K2\n real(kind=8) :: Y, beta2, W2, delta, alpha, Z1\n real(kind=8) :: E, v2, xx, beta1, A, Z2\n\n n = size(x)\n b1 = skewness(x)\n b2 = kurtosis(x)\n\n ! Skewness test\n !===============\n Y = b1*sqrt((n + 1.)*(n + 3.)/(6.*(n - 2.)))\n beta2 = 3.*(n*n + 27.*n - 70.)*(n + 1.)*(n + 3.)/((n - 2.)*(n + 5.)*(n + 7.)*(n + 9.))\n W2 = -1.+sqrt(2.*(beta2 - 1.))\n delta = 1./sqrt(0.5*log(W2))\n alpha = sqrt(2./(W2 - 1.))\n Z1 = delta*log(Y/alpha + sqrt((Y/alpha)**2 + 1.))\n\n ! Kurtosis test\n !===============\n E = 3.*(n - 1.)/(n + 1.)\n v2 = 24.*n*(n - 2.)*(n - 3.)/((n + 1.)**2*(n + 3.)*(n + 5.))\n xx = (b2 - E)/sqrt(v2)\n beta1 = 6.*(n**2 - 5.*n + 2.)/((n + 7.)*(n + 9.)) &\n *sqrt(6.*(n + 3.)*(n + 5.)/(n*(n - 2.)*(n - 3.)))\n A = 6.+8./beta1*(2./beta1 + sqrt(1.+4./(beta1*beta1)))\n Z2 = ((1.-2./(9.*A)) - ((1.-2./A)/(1.+xx*sqrt(2./(A - 4.))))**(1./3.)) &\n /sqrt(2./(9.*A))\n\n ! Omnibus test\n !==============\n K2 = Z1*Z1 + Z2*Z2\n p = exp(-0.5*K2)\n\n return\n end function k2test\n\n ! kde\n !-----------------------------------------------------------------------\n ! kde computes the kernel density estimation assuming Gaussian kernels\n ! for univariate and bivariate data. The default bandwidth is calculated\n ! using Silverman's rule of thumb.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! call kde(x, f, xi)\n ! call kde(x, f, xi, bw)\n ! call kde(A, f, xi, yi)\n ! call kde(A, f, xi, yi, H)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! call kde(x, f, xi) returns the probability density estimation f at\n ! points xi for the sample data in the vector x.\n !\n ! call kde(x, f, xi, bw) returns the PDE f at points xi using the kernel\n ! bandwidth bw.\n !\n ! call kde(A, f, xi, yi) returns the PDE f at points xi and yi.\n !\n ! call kde(A, f, xi, yi, H) returns the PDE f at points xi and yi using\n ! the bandwidth H.\n\n subroutine kde1(x, f, xi, bw)\n real(kind=RPRE), dimension(:), intent(in) :: x\n real(kind=RPRE), dimension(:), allocatable, intent(out) :: f\n real(kind=RPRE), dimension(:), allocatable, intent(inout), optional :: xi\n real(kind=RPRE), intent(in), optional :: bw\n integer(kind=IPRE) :: ix, j, n, nx\n real(kind=RPRE) :: opt_bw\n real(kind=RPRE), dimension(:), allocatable :: opt_xi\n\n n = size(x)\n opt_bw = (4.*std(x)**5/(3.*n))**0.2\n if (present(bw)) opt_bw = bw\n if (present(xi) .and. allocated(xi)) then\n nx = size(xi)\n opt_xi = xi\n else\n nx = 100\n opt_xi = linspace(minval(x) - 3*opt_bw, maxval(x) + 3*opt_bw, nx)\n end if\n\n f = zeros(nx)\n do ix = 1, nx\n do j = 1, n\n f(ix) = f(ix) + exp(-0.5*((opt_xi(ix) - x(j))/opt_bw)**2)\n end do\n end do\n f = 0.3989422804014327*f/(n*opt_bw)\n\n if (present(xi) .and. .not. allocated(xi)) xi = opt_xi\n return\n end subroutine kde1\n\n subroutine kde2(A, f, xi, yi, H)\n real(kind=RPRE), dimension(:, :), intent(in) :: A\n real(kind=RPRE), dimension(:, :), allocatable, intent(out) :: f\n real(kind=RPRE), dimension(:), allocatable, intent(inout), optional :: xi, yi\n real(kind=RPRE), dimension(:, :), intent(in), optional :: H\n integer(kind=IPRE) :: ix, iy, j, n, nx, ny\n real(kind=RPRE) :: opt_H(2, 2), invH(2, 2), x(2)\n real(kind=RPRE), dimension(:), allocatable :: opt_xi, opt_yi\n\n n = size(A, 1)\n if (present(H)) then\n opt_H = H\n else\n opt_H = cov(A)*n**(-1./3.) ! Squared\n end if\n if (present(xi) .and. allocated(xi)) then\n nx = size(xi)\n opt_xi = xi\n else\n nx = 100\n opt_xi = linspace(minval(A(:, 1)) - 3*opt_H(1, 1), maxval(A(:, 1)) + 3*opt_H(1, 1), nx)\n end if\n if (present(yi) .and. allocated(yi)) then\n ny = size(yi)\n opt_yi = yi\n else\n ny = 100\n opt_yi = linspace(minval(A(:, 2)) - 3*opt_H(2, 2), maxval(A(:, 2)) + 3*opt_H(2, 2), ny)\n end if\n\n invH = inv(opt_H)\n f = zeros(nx, ny)\n do ix = 1, nx\n do iy = 1, ny\n do j = 1, n\n x = [opt_xi(ix), opt_yi(iy)] - [A(j, :)]\n f(ix, iy) = f(ix, iy) + exp(-0.5*dot_product(matmul(x, invH), x))\n end do\n end do\n end do\n f = f/(sqrt(det(real(2.*pi, RPRE)*opt_H))*real(n, RPRE))\n\n if (present(xi) .and. .not. allocated(xi)) xi = opt_xi\n if (present(yi) .and. .not. allocated(yi)) yi = opt_yi\n return\n end subroutine kde2\n\n ! kurtosis\n !-----------------------------------------------------------------------\n ! kurtosis computes vector and matrix kurtosis.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! y = kurtosis(x)\n ! y = kurtosis(x, flag)\n ! x = kurtosis(A)\n ! x = kurtosis(A, flag)\n ! x = kurtosis(A, 1)\n ! x = kurtosis(A, flag, 1)\n ! x = kurtosis(A, 2)\n ! x = kurtosis(A, flag, 2)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! y = kurtosis(x) returns the kurtosis of the vector x.\n !\n ! y = kurtosis(x, w) returns the kurtosis of the vector x given the\n ! flag. By default, flag is 1. If flag is 0, the function corrects for\n ! the systematic bias due to the size of the sample.\n !\n ! x = kurtosis(A) returns a dim2 vector with the kurtosis of each\n ! column of matrix A.\n !\n ! x = kurtosis(A, flag) returns a dim2 vector given the flag.\n !\n ! x = kurtosis(A, 1) (see x = kurtosis(A)).\n !\n ! x = kurtosis(A, flag, 1) (see x = kurtosis(A, flag))\n !\n ! x = kurtosis(A, 2) returns a dim1 vector with the kurtosis of\n ! each row of matrix A.\n !\n ! x = kurtosis(A, flag, 2) returns a dim1 vector given the flag.\n\n real(kind=RPRE) function kurtosis1(x, flag)\n real(kind=RPRE), dimension(:), intent(in) :: x\n integer(kind=IPRE), intent(in), optional :: flag\n integer(kind=IPRE) :: opt_flag, n\n\n opt_flag = 1\n if (present(flag)) opt_flag = flag\n\n n = size(x)\n kurtosis1 = (sum((x - mean(x))**4)/n)/(var(x, 1)**2)\n if (opt_flag .eq. 0) then\n kurtosis1 = (n - 1)/((n - 2)*(n - 3))*((n + 1)*kurtosis1 - 3*(n - 1)) + 3\n end if\n return\n end function kurtosis1\n\n function kurtosis2(A, flag, dim)\n real(kind=RPRE), dimension(:), allocatable :: kurtosis2\n real(kind=RPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE), intent(in), optional :: flag, dim\n integer(kind=IPRE) :: opt_flag, i, m, n\n\n opt_flag = 1\n if (present(flag)) opt_flag = flag\n\n m = size(A, 1)\n n = size(A, 2)\n if ((.not. present(dim)) .or. (dim .eq. 1)) then\n allocate (kurtosis2(n))\n do i = 1, n\n kurtosis2(i) = kurtosis1(A(:, i), opt_flag)\n end do\n elseif (dim .eq. 2) then\n allocate (kurtosis2(m))\n do i = 1, m\n kurtosis2(i) = kurtosis1(A(i, :), opt_flag)\n end do\n end if\n return\n end function kurtosis2\n\n ! linspace\n !-----------------------------------------------------------------------\n ! linspace creates a linearly spaced vector.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! x = linspace(x1, x2, n)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! x = linspace(x1, x2, n) returns a vector of n evenly spaced points\n ! between x1 and x2.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! x = linspace(0, 10, 11)\n ! 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10.\n\n function linspace_r8r8(first, last, n)\n real(kind=RPRE), dimension(:), allocatable :: linspace_r8r8\n real(kind=8), intent(in) :: first, last\n integer(kind=IPRE), intent(in) :: n\n integer(kind=IPRE) :: i\n real(kind=8) :: step\n\n allocate (linspace_r8r8(n))\n step = (last - first)/(n - 1)\n linspace_r8r8 = first + step*real([(i - 1, i=1, n)], RPRE)\n return\n end function linspace_r8r8\n\n function linspace_r4r4(first, last, n)\n real(kind=RPRE), dimension(:), allocatable :: linspace_r4r4\n real(kind=4), intent(in) :: first, last\n integer(kind=IPRE), intent(in) :: n\n\n linspace_r4r4 = linspace(real(first, kind=8), real(last, kind=8), n)\n return\n end function linspace_r4r4\n\n function linspace_i4i4(first, last, n)\n real(kind=RPRE), dimension(:), allocatable :: linspace_i4i4\n integer(kind=4), intent(in) :: first, last\n integer(kind=IPRE), intent(in) :: n\n\n linspace_i4i4 = linspace(real(first, kind=8), real(last, kind=8), n)\n return\n end function linspace_i4i4\n\n function linspace_r8i4(first, last, n)\n real(kind=RPRE), dimension(:), allocatable :: linspace_r8i4\n real(kind=8), intent(in) :: first\n integer(kind=4), intent(in) :: last\n integer(kind=IPRE), intent(in) :: n\n\n linspace_r8i4 = linspace(first, real(last, kind=8), n)\n return\n end function linspace_r8i4\n\n function linspace_r4i4(first, last, n)\n real(kind=RPRE), dimension(:), allocatable :: linspace_r4i4\n real(kind=4), intent(in) :: first\n integer(kind=4), intent(in) :: last\n integer(kind=IPRE), intent(in) :: n\n\n linspace_r4i4 = linspace(real(first, kind=8), real(last, kind=8), n)\n return\n end function linspace_r4i4\n\n function linspace_i4r8(first, last, n)\n real(kind=RPRE), dimension(:), allocatable :: linspace_i4r8\n integer(kind=4), intent(in) :: first\n real(kind=8), intent(in) :: last\n integer(kind=IPRE), intent(in) :: n\n\n linspace_i4r8 = linspace(real(first, kind=8), last, n)\n return\n end function linspace_i4r8\n\n function linspace_i4r4(first, last, n)\n real(kind=RPRE), dimension(:), allocatable :: linspace_i4r4\n integer(kind=4), intent(in) :: first\n real(kind=4), intent(in) :: last\n integer(kind=IPRE), intent(in) :: n\n\n linspace_i4r4 = linspace(real(first, kind=8), real(last, kind=8), n)\n return\n end function linspace_i4r4\n\n ! loadbin\n !-----------------------------------------------------------------------\n ! loadbin loads binary files.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! x = loadbin(filename)\n ! x = loadbin(filename, kind)\n ! x = loadbin(filename, kind, dim1)\n ! A = loadbin(filename, kind, dim1, dim2)\n ! X = loadbin(filename, kind, dim1, dim2, dim3)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! x = loadbin(filename) loads a 1-dimensional array into x from the\n ! binary file filename treated as 32 bytes floating points.\n !\n ! x = loadbin(filename, kind) loads a 1-dimensional array into x from\n ! the binary file filename.\n !\n ! x = loadbin(filename, kind, dim1) loads a 1-dimensional array into x\n ! from the binary file filename.\n !\n ! A = loadbin(filename, kind, dim1, dim2) loads a 2-dimensional array\n ! into A from the binary file filename.\n !\n ! X = loadbin(filename, kind, dim1, dim2, dim3) loads a 3-dimensional\n ! array into X from the binary file filename.\n !\n ! Notes\n !-----------------------------------------------------------------------\n ! Make sure to use the exact kind:\n ! - 4 for 32 bytes floating points,\n ! - 8 for 64 bytes floating points.\n\n function loadbin0(filename, kind)\n real(kind=RPRE), dimension(:), allocatable :: loadbin0\n character(len=*), intent(in) :: filename\n integer(kind=IPRE), intent(in), optional :: kind\n integer(kind=IPRE) :: opt_kind, dim1, fs\n real(kind=4), dimension(:), allocatable :: tmp4\n real(kind=8), dimension(:), allocatable :: tmp8\n type(File) :: infile\n\n opt_kind = 4\n if (present(kind)) opt_kind = kind\n\n infile = File(999, trim(filename))\n if (infile%exist()) then\n inquire (file=filename, size=fs)\n select case (opt_kind)\n case (4)\n if (mod(fs, 4) .eq. 0) then\n dim1 = fs/4\n allocate (tmp4(dim1), loadbin0(dim1))\n call infile%open(4*dim1)\n read (infile%unit, rec=1) tmp4\n call infile%close()\n loadbin0 = tmp4\n else\n print *, \"Error: in loadbin, file size mismatches kind.\"\n stop\n end if\n case (8)\n if (mod(fs, 8) .eq. 0) then\n dim1 = fs/8\n allocate (tmp8(dim1), loadbin0(dim1))\n call infile%open(8*dim1)\n read (infile%unit, rec=1) tmp8\n call infile%close()\n loadbin0 = tmp8\n else\n print *, \"Error: in loadbin, file size mismatches kind.\"\n stop\n end if\n end select\n else\n print *, \"Error: '\"//trim(filename)//\"' not found\"\n stop\n end if\n return\n end function loadbin0\n\n function loadbin1(filename, kind, dim1)\n real(kind=RPRE), dimension(:), allocatable :: loadbin1\n character(len=*), intent(in) :: filename\n integer(kind=IPRE), intent(in) :: kind, dim1\n real(kind=4), dimension(:), allocatable :: tmp4\n real(kind=8), dimension(:), allocatable :: tmp8\n type(File) :: infile\n\n infile = File(999, trim(filename))\n if (infile%exist()) then\n allocate (loadbin1(dim1))\n select case (kind)\n case (4)\n allocate (tmp4(dim1))\n call infile%open(4*dim1)\n read (infile%unit, rec=1) tmp4\n call infile%close()\n loadbin1 = tmp4\n case (8)\n allocate (tmp8(dim1))\n call infile%open(8*dim1)\n read (infile%unit, rec=1) tmp8\n call infile%close()\n loadbin1 = tmp8\n end select\n else\n print *, \"Error: '\"//trim(filename)//\"' not found\"\n stop\n end if\n return\n end function loadbin1\n\n function loadbin2(filename, kind, dim1, dim2)\n real(kind=RPRE), dimension(:, :), allocatable :: loadbin2\n character(len=*), intent(in) :: filename\n integer(kind=IPRE), intent(in) :: kind, dim1, dim2\n real(kind=4), dimension(:, :), allocatable :: tmp4\n real(kind=8), dimension(:, :), allocatable :: tmp8\n type(File) :: infile\n\n infile = File(999, trim(filename))\n if (infile%exist()) then\n allocate (loadbin2(dim1, dim2))\n select case (kind)\n case (4)\n allocate (tmp4(dim1, dim2))\n call infile%open(4*dim1*dim2)\n read (infile%unit, rec=1) tmp4\n call infile%close()\n loadbin2 = tmp4\n case (8)\n allocate (tmp8(dim1, dim2))\n call infile%open(8*dim1*dim2)\n read (infile%unit, rec=1) tmp8\n call infile%close()\n loadbin2 = tmp8\n end select\n else\n print *, \"Error: '\"//trim(filename)//\"' not found\"\n stop\n end if\n return\n end function loadbin2\n\n function loadbin3(filename, kind, dim1, dim2, dim3)\n real(kind=RPRE), dimension(:, :, :), allocatable :: loadbin3\n character(len=*), intent(in) :: filename\n integer(kind=IPRE), intent(in) :: kind, dim1, dim2, dim3\n real(kind=4), dimension(:, :, :), allocatable :: tmp4\n real(kind=8), dimension(:, :, :), allocatable :: tmp8\n type(File) :: infile\n\n infile = File(999, trim(filename))\n if (infile%exist()) then\n allocate (loadbin3(dim1, dim2, dim3))\n select case (kind)\n case (4)\n allocate (tmp4(dim1, dim2, dim3))\n call infile%open(4*dim1*dim2*dim3)\n read (infile%unit, rec=1) tmp4\n call infile%close()\n loadbin3 = tmp4\n case (8)\n allocate (tmp8(dim1, dim2, dim3))\n call infile%open(8*dim1*dim2*dim3)\n read (infile%unit, rec=1) tmp8\n call infile%close()\n loadbin3 = tmp8\n end select\n else\n print *, \"Error: '\"//trim(filename)//\"' not found\"\n stop\n end if\n return\n end function loadbin3\n\n ! loadtxt\n !-----------------------------------------------------------------------\n ! loadtxt loads txt files.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! x = loadtxt(filename)\n ! A = loadtxt(filename, dim2)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! x = loadtxt(filename) loads a 1-dimensional array into x from a txt\n ! file filename.\n !\n ! A = loadtxt(filename, dim2) loads a 2-dimensional array into A from a\n ! txt file filename. dim2 indicates the number of columns of the array.\n\n function loadtxt1(filename)\n real(kind=RPRE), dimension(:), allocatable :: loadtxt1\n character(len=*), intent(in) :: filename\n integer(kind=IPRE) :: i, m\n type(File) :: infile\n\n infile = File(999, trim(filename))\n if (infile%exist()) then\n m = infile%countlines()\n allocate (loadtxt1(m))\n call infile%open()\n do i = 1, m\n read (infile%unit, *) loadtxt1(i)\n end do\n call infile%close()\n else\n print *, \"Error: '\"//trim(filename)//\"' not found\"\n stop\n end if\n return\n end function loadtxt1\n\n function loadtxt2(filename, dim2)\n real(kind=RPRE), dimension(:, :), allocatable :: loadtxt2\n character(len=*), intent(in) :: filename\n integer(kind=IPRE), intent(in) :: dim2\n integer(kind=IPRE) :: i, j, m\n type(File) :: infile\n\n infile = File(999, trim(filename))\n if (infile%exist()) then\n m = infile%countlines()\n allocate (loadtxt2(m, dim2))\n call infile%open()\n do i = 1, m\n read (infile%unit, *) (loadtxt2(i, j), j=1, dim2)\n end do\n call infile%close()\n else\n print *, \"Error: '\"//trim(filename)//\"' not found\"\n stop\n end if\n return\n end function loadtxt2\n\n ! log2\n !-----------------------------------------------------------------------\n ! log2 computes the base 2 logarithm.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! y = log2(x)\n ! Y = log2(X)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! y = log2(x) returns the base 2 logarithm of x.\n !\n ! Y = log2(X) returns a vector Y with the base 2 logarithm of the\n ! elements in X.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! y = log2(arange(1, 10))\n ! 0.000 1.000 1.585 2.000 2.322 2.585 2.807 3.000 3.170 3.322\n !\n ! m = mod(log2([ 16, 17 ]), 1.)\n ! 0. 0.0875\n !\n ! Note\n !-----------------------------------------------------------------------\n ! The latter example shows how log2 can be used to tell whether a number\n ! is a power of 2. Fortran intrinsic binary substraction function iand\n ! can also be used for this purpose.\n\n real(kind=RPRE) function log2_i0(x)\n integer(kind=IPRE), intent(in) :: x\n\n log2_i0 = log(real(x))/log(2.0d0)\n return\n end function log2_i0\n\n real(kind=RPRE) function log2_r0(x)\n real(kind=RPRE), intent(in) :: x\n\n log2_r0 = log(x)/log(2.0d0)\n return\n end function log2_r0\n\n function log2_i1(x)\n real(kind=RPRE), dimension(:), allocatable :: log2_i1\n integer(kind=IPRE), dimension(:), intent(in) :: x\n\n log2_i1 = log(real(x))/log(2.0d0)\n return\n end function log2_i1\n\n function log2_r1(x)\n real(kind=RPRE), dimension(:), allocatable :: log2_r1\n real(kind=RPRE), dimension(:), intent(in) :: x\n\n log2_r1 = log(x)/log(2.0d0)\n return\n end function log2_r1\n\n ! lsweight\n !-----------------------------------------------------------------------\n ! lsweight computes the least-square inversion weights.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! W = lsweight(r, \"none\")\n ! W = lsweight(r, \"biweight\")\n !\n ! Description\n !-----------------------------------------------------------------------\n ! W = lsweight(r, \"none\") returns the identity matrix.\n !\n ! W = lsweight(r, \"biweight\") returns the weights using a biweight norm.\n\n function lsweight(r, ntype)\n real(kind=RPRE), dimension(:, :), allocatable :: lsweight\n real(kind=RPRE), dimension(:), intent(in) :: r\n character(len=*), intent(in) :: ntype\n integer(kind=IPRE) :: i, n\n real(kind=RPRE) :: eps\n\n eps = 4.685d0*mad(r, 2)/0.6745d0\n n = size(r)\n if ((eps .eq. 0.0d0) .or. (ntype .eq. \"none\")) then\n lsweight = eye(n)\n elseif (ntype .eq. \"biweight\") then\n lsweight = zeros(n, n)\n do i = 1, n\n if (abs(r(i)) .le. eps) lsweight(i, i) = (1.0d0 - (r(i)/eps)**2)**2\n end do\n end if\n return\n end function lsweight\n\n ! kmeans\n !-----------------------------------------------------------------------\n ! kmeans performs K-means clustering.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! idx = kmeans(x, K, [options = ])\n ! idx = kmeans(A, K, [options = ])\n !\n ! Description\n !-----------------------------------------------------------------------\n ! idx = kmeans(x, K, [options = ]) returns the cluster indices of each\n ! element in vector x.\n !\n ! idx = kmeans(A, K, [options = ]) returns the cluster indices of each\n ! rows in matrix A.\n !\n ! Options\n !-----------------------------------------------------------------------\n ! means Output centroids\n ! init Initial centroids\n ! itermax = 1000 Maximum number of iterations\n ! niter Output number of iterations\n !\n ! Notes\n !-----------------------------------------------------------------------\n ! By default, initials centroids are randomly chosen among data points.\n\n function kmeans1(x, K, means, init, itermax, niter) result(idx)\n integer(kind=IPRE), dimension(:), allocatable :: idx\n real(kind=RPRE), dimension(:), intent(in) :: x\n integer(kind=IPRE), intent(in) :: K\n real(kind=RPRE), dimension(:), intent(in), optional :: init\n real(kind=RPRE), dimension(:), allocatable, intent(inout), optional :: means\n integer(kind=IPRE), intent(in), optional :: itermax\n integer(kind=IPRE), intent(inout), optional :: niter\n integer(kind=IPRE) :: opt_itermax, n, iter\n real(kind=RPRE), dimension(:, :), allocatable :: m1\n real(kind=RPRE), dimension(:, :), allocatable :: opt_init, A\n\n n = size(x)\n\n opt_itermax = 100\n if (present(itermax)) opt_itermax = itermax\n if (present(init)) then\n opt_init = reshape(init, shape=[K, 1], order=[1, 2])\n else\n opt_init = reshape(x(randperm(n, K)), shape=[K, 1], order=[1, 2])\n end if\n\n A = reshape(x, shape=[n, 1], order=[1, 2])\n idx = kmeans2(A, K, m1, opt_init, opt_itermax, iter)\n\n if (present(niter)) niter = iter\n if (present(means)) means = [m1]\n\n return\n end function kmeans1\n\n function kmeans2(A, K, means, init, itermax, niter) result(idx)\n integer(kind=IPRE), dimension(:), allocatable :: idx\n real(kind=RPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE), intent(in) :: K\n real(kind=RPRE), dimension(:, :), intent(in), optional :: init\n real(kind=RPRE), dimension(:, :), allocatable, intent(inout), optional :: means\n integer(kind=IPRE), intent(in), optional :: itermax\n integer(kind=IPRE), intent(inout), optional :: niter\n integer(kind=IPRE) :: opt_itermax, i, n, p, iter\n real(kind=RPRE), dimension(:, :), allocatable :: opt_init, m, m1\n\n n = size(A, 1)\n p = size(A, 2)\n\n opt_itermax = 1000\n if (present(itermax)) opt_itermax = itermax\n if (present(init)) then\n opt_init = init\n else\n opt_init = A(randperm(n, K), :)\n end if\n\n ! Initialization\n !================\n m = opt_init\n idx = update_index(A, m)\n m1 = update_means(A, idx)\n\n ! Loop until convergence\n !========================\n iter = 0\n do while ((means_residuals(m, m1) .gt. 1.0d-10) &\n .and. (iter .lt. opt_itermax))\n iter = iter + 1\n m = m1\n idx = update_index(A, m)\n m1 = update_means(A, idx)\n end do\n\n if (present(niter)) niter = iter\n if (present(means)) means = m1\n\n return\n contains\n\n !-------------------------------------------------------------------\n ! update_index\n !-------------------------------------------------------------------\n function update_index(A, means) result(idx)\n integer(kind=IPRE), dimension(:), allocatable :: idx\n real(kind=RPRE), dimension(:, :), intent(in) :: A, means\n integer(kind=IPRE) :: i, j, b(1)\n real(kind=RPRE), dimension(:), allocatable :: dist\n\n idx = zeros(n)\n do i = 1, n\n dist = zeros(K)\n do j = 1, K\n dist(j) = norm(A(i, :) - means(j, :))\n end do\n b = minloc(dist)\n idx(i) = b(1)\n end do\n return\n end function update_index\n\n !-------------------------------------------------------------------\n ! update_means\n !-------------------------------------------------------------------\n function update_means(A, idx) result(means)\n real(kind=RPRE), dimension(:, :), allocatable :: means\n real(kind=RPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE), dimension(:), intent(in) :: idx\n integer(kind=IPRE) :: j\n\n means = zeros(K, p)\n do j = 1, K\n means(j, :) = mean(A(find(idx .eq. j), :))\n end do\n return\n end function update_means\n\n !-------------------------------------------------------------------\n ! means_residuals\n !-------------------------------------------------------------------\n function means_residuals(means1, means2) result(eps)\n real(kind=RPRE) :: eps\n real(kind=RPRE), dimension(:, :), intent(in) :: means1, means2\n real(kind=RPRE), dimension(:, :), allocatable :: means\n integer(kind=IPRE) :: k\n\n eps = 0.0d0\n means = abs(means2 - means1)\n do k = 1, p\n eps = eps + sum(means(:, k))**2\n end do\n eps = sqrt(eps)\n return\n end function means_residuals\n\n end function kmeans2\n\n ! mad\n !-----------------------------------------------------------------------\n ! mad computes the mean-absolute-deviation or the median-absolute\n ! -deviation of a vector.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! y = mad(x)\n ! y = mad(x, 1)\n ! y = mad(x, 2)\n ! x = mad(A)\n ! x = mad(A, 1, 1)\n ! x = mad(A, 1, 2)\n ! x = mad(A, 2, 1)\n ! x = mad(A, 2, 2)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! y = mad(x) returns the mean-absolute-deviation of the vector x.\n !\n ! y = mad(x, 1) (see y = mad(x)).\n !\n ! y = mad(x, 2) returns the median-absolute-deviation of the vector x.\n !\n ! x = mad(A) returns a dim2 vector with the mean-absolute-deviation of\n ! each column of matrix A.\n !\n ! x = mad(A, 1, 1) (see x = mad(A)).\n !\n ! x = mad(A, 1, 2) returns a dim2 vector with the median-absolute\n ! -deviation of each column of matrix A.\n !\n ! x = mad(A, 2, 1) returns a dim1 vector with the mean-absolute\n ! -deviation of each row of matrix A.\n !\n ! x = mad(A, 2, 2) returns a dim1 vector with the median-absolute\n ! -deviation of each row of matrix A.\n\n real(kind=RPRE) function mad1(x, method)\n real(kind=RPRE), dimension(:), intent(in) :: x\n integer(kind=IPRE), intent(in), optional :: method\n\n if ((.not. present(method)) .or. (method .eq. 1)) then\n mad1 = mean(abs(x - mean(x)))\n elseif (method .eq. 2) then\n mad1 = median(abs(x - median(x)))\n end if\n return\n end function mad1\n\n function mad2(A, dim, method)\n real(kind=RPRE), dimension(:), allocatable :: mad2\n real(kind=RPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE), intent(in), optional :: dim, method\n integer(kind=IPRE) :: i, m, n\n\n m = size(A, 1)\n n = size(A, 2)\n if ((.not. present(dim)) .or. (dim .eq. 1)) then\n allocate (mad2(n))\n if ((.not. present(method)) .or. (method .eq. 1)) then\n do i = 1, n\n mad2(i) = mad(A(:, i), 1)\n end do\n elseif (method .eq. 2) then\n do i = 1, n\n mad2(i) = mad(A(:, i), 2)\n end do\n end if\n elseif (dim .eq. 2) then\n allocate (mad2(m))\n if ((.not. present(method)) .or. (method .eq. 1)) then\n do i = 1, m\n mad2(i) = mad(A(i, :), 1)\n end do\n elseif (method .eq. 2) then\n do i = 1, m\n mad2(i) = mad(A(i, :), 2)\n end do\n end if\n end if\n return\n end function mad2\n\n ! mbkmeans\n !-----------------------------------------------------------------------\n ! mbkmeans performs Mini-batch K-means clustering.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! idx = mbkmeans(x, K, [options = ])\n ! idx = mbkmeans(A, K, [options = ])\n !\n ! Description\n !-----------------------------------------------------------------------\n ! idx = mbkmeans(x, K, [options = ]) returns the cluster indices of each\n ! element in vector x.\n !\n ! idx = mbkmeans(A, K, [options = ]) returns the cluster indices of each\n ! rows in matrix A.\n !\n ! Options\n !-----------------------------------------------------------------------\n ! perc = 0.2 Size of the batch (percentage)\n ! means Output centroids\n ! init Initial centroids\n ! itermax = 50 Maximum number of iterations\n ! niter Output number of iterations\n\n function mbkmeans1(x, K, perc, means, init, itermax, niter) result(idx)\n integer(kind=IPRE), dimension(:), allocatable :: idx\n real(kind=RPRE), dimension(:), intent(in) :: x\n integer(kind=IPRE), intent(in) :: K\n real(kind=RPRE), intent(in), optional :: perc\n real(kind=RPRE), dimension(:), intent(in), optional :: init\n real(kind=RPRE), dimension(:), allocatable, intent(inout), optional :: means\n integer(kind=IPRE), intent(in), optional :: itermax\n integer(kind=IPRE), intent(inout), optional :: niter\n integer(kind=IPRE) :: opt_itermax, n, iter\n real(kind=RPRE) :: opt_perc\n real(kind=RPRE), dimension(:, :), allocatable :: m1\n real(kind=RPRE), dimension(:, :), allocatable :: opt_init, A\n\n n = size(x)\n\n opt_itermax = 50\n opt_perc = 0.2d0\n if (present(itermax)) opt_itermax = itermax\n if (present(perc)) opt_perc = perc\n if (present(init)) then\n opt_init = reshape(init, shape=[K, 1], order=[1, 2])\n else\n opt_init = reshape(x(randperm(n, K)), shape=[K, 1], order=[1, 2])\n end if\n\n A = reshape(x, shape=[n, 1], order=[1, 2])\n idx = mbkmeans2(A, K, perc, m1, opt_init, opt_itermax, iter)\n\n if (present(niter)) niter = iter\n if (present(means)) means = [m1]\n\n return\n end function mbkmeans1\n\n function mbkmeans2(A, K, perc, means, init, itermax, niter) result(idx)\n integer(kind=IPRE), dimension(:), allocatable :: idx\n real(kind=RPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE), intent(in) :: K\n real(kind=RPRE), intent(in), optional :: perc\n real(kind=RPRE), dimension(:, :), intent(in), optional :: init\n real(kind=RPRE), dimension(:, :), allocatable, intent(inout), optional :: means\n integer(kind=IPRE), intent(in), optional :: itermax\n integer(kind=IPRE), intent(inout), optional :: niter\n integer(kind=IPRE) :: opt_itermax, n, p, bs, iter\n real(kind=RPRE) :: opt_perc\n integer(kind=IPRE), dimension(:), allocatable :: v\n real(kind=RPRE), dimension(:, :), allocatable :: opt_init, m, m1, B\n\n n = size(A, 1)\n p = size(A, 2)\n\n opt_itermax = 50\n opt_perc = 0.2d0\n if (present(itermax)) opt_itermax = itermax\n if (present(perc)) opt_perc = perc\n if (present(init)) then\n opt_init = init\n else\n opt_init = A(randperm(n, K), :)\n end if\n\n ! Initialization\n !================\n bs = nint(opt_perc*n) ! Batch size\n m = opt_init ! Initial centroids\n v = zeros(K) ! Per-center counter\n\n ! Iterate until convergence\n !===========================\n do iter = 1, opt_itermax\n B = A(randperm(n, bs), :) ! Batch\n m1 = m ! Previous means\n idx = cache_means(B, m) ! Cache means\n call update_means(m, v, B, idx) ! Update means with gradient\n if (means_residuals(m, m1) .lt. 1.0d-2) exit\n end do\n\n idx = cache_means(A, m)\n\n if (present(niter)) niter = iter - 1\n if (present(means)) means = m\n\n return\n contains\n\n !-------------------------------------------------------------------\n ! cache_means\n !-------------------------------------------------------------------\n function cache_means(A, means) result(idx)\n integer(kind=IPRE), dimension(:), allocatable :: idx\n real(kind=RPRE), dimension(:, :), intent(in) :: A, means\n integer(kind=IPRE) :: i, j, n, b(1)\n real(kind=RPRE), dimension(:), allocatable :: dist\n\n n = size(A, 1)\n idx = zeros(n)\n dist = zeros(K)\n do i = 1, n\n dist = 0.0d0\n do j = 1, K\n dist(j) = norm(A(i, :) - means(j, :))\n end do\n b = minloc(dist)\n idx(i) = b(1)\n end do\n return\n end function cache_means\n\n !-------------------------------------------------------------------\n ! update_means\n !-------------------------------------------------------------------\n subroutine update_means(means, v, A, idx)\n real(kind=RPRE), dimension(:, :), intent(inout) :: means\n integer(kind=IPRE), dimension(:), intent(inout) :: v\n real(kind=RPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE), dimension(:), intent(in) :: idx\n integer(kind=IPRE) :: i, n, c\n real(kind=RPRE) :: eta\n\n n = size(A, 1)\n do i = 1, n\n c = idx(i)\n v(c) = v(c) + 1\n eta = 1.0d0/real(v(c), RPRE)\n means(c, :) = (1.0d0 - eta)*means(c, :) + eta*A(i, :)\n end do\n return\n end subroutine update_means\n\n !-------------------------------------------------------------------\n ! means_residuals\n !-------------------------------------------------------------------\n function means_residuals(means1, means2) result(eps)\n real(kind=RPRE) :: eps\n real(kind=RPRE), dimension(:, :), intent(in) :: means1, means2\n real(kind=RPRE), dimension(:, :), allocatable :: means\n integer(kind=IPRE) :: k\n\n eps = 0.0d0\n means = abs(means2 - means1)\n do k = 1, p\n eps = eps + sum(means(:, k))**2\n end do\n eps = sqrt(eps)\n return\n end function means_residuals\n\n end function mbkmeans2\n\n ! mean\n !-----------------------------------------------------------------------\n ! mean computes the mean value of an array.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! y = mean(x)\n ! x = mean(A)\n ! x = mean(A, 1)\n ! x = mean(A, 2)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! y = mean(x) returns the mean value of the vector x.\n !\n ! x = mean(A) returns a dim2 vector with the mean values of each column\n ! of matrix A.\n !\n ! x = mean(A, 1) (see x = mean(A)).\n !\n ! x = mean(A, 2) returns a dim1 vector with the mean values of each row\n ! of matrix A.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! x = [ 1., 2., 3. ]\n ! y = mean(x)\n ! 2.\n !\n ! A = reshape([ 1., 2., 3., 4., 5., 6., 7., 8., 9. ], [ 3, 3 ], &\n ! order = [ 2, 1 ])\n ! x = mean(A)\n ! 4. 5. 6.\n ! x = mean(A, 2)\n ! 2. 5. 8.\n\n real(kind=RPRE) function mean1(x)\n real(kind=RPRE), dimension(:), intent(in) :: x\n\n mean1 = sum(x)/size(x)\n return\n end function mean1\n\n function mean2(A, dim)\n real(kind=RPRE), dimension(:), allocatable :: mean2\n real(kind=RPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE), intent(in), optional :: dim\n integer(kind=IPRE) :: i, m, n\n\n m = size(A, 1)\n n = size(A, 2)\n if ((.not. present(dim)) .or. (dim .eq. 1)) then\n allocate (mean2(n))\n do i = 1, n\n mean2(i) = mean(A(:, i))\n end do\n elseif (dim .eq. 2) then\n allocate (mean2(m))\n do i = 1, m\n mean2(i) = mean(A(i, :))\n end do\n end if\n return\n end function mean2\n\n ! median\n !-----------------------------------------------------------------------\n ! median computes the median value of an array.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! y = median(x)\n ! x = median(A)\n ! x = median(A, 1)\n ! x = median(A, 2)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! y = median(x) returns the median value of the vector x.\n !\n ! x = median(A) returns a dim2 vector with the median values of each\n ! column of matrix A.\n !\n ! x = median(A, 1) (see x = median(A)).\n !\n ! x = median(A, 2) returns a dim1 vector with the median values of each\n ! row of matrix A.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! x = [ 3., 1., 2. ]\n ! y = median(x)\n ! 2.\n !\n ! x = [ 3., 4., 1., 2. ]\n ! y = median(x)\n ! 2.5\n !\n ! A = reshape([ 3., 7., 1., 8., 2., 5., 4., 9., 6. ], [ 3, 3 ], &\n ! order = [ 2, 1 ])\n ! x = median(A)\n ! 4. 7. 5.\n ! x = median(A, 2)\n ! 3. 5. 6.\n\n real(kind=RPRE) function median1(x)\n real(kind=RPRE), dimension(:), intent(in) :: x\n real(kind=RPRE), dimension(:), allocatable :: x_sort\n integer(kind=IPRE) :: i, n\n\n n = size(x)\n x_sort = sort(x)\n i = ceiling(real(n/2.0d0))\n if (mod(n, 2) .eq. 0) then\n median1 = (x_sort(i) + x_sort(i + 1))/2\n else\n median1 = x_sort(i)\n end if\n return\n end function median1\n\n function median2(A, dim)\n real(kind=RPRE), dimension(:), allocatable :: median2\n real(kind=RPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE), intent(in), optional :: dim\n integer(kind=IPRE) :: i, m, n\n\n m = size(A, 1)\n n = size(A, 2)\n if ((.not. present(dim)) .or. (dim .eq. 1)) then\n allocate (median2(n))\n do i = 1, n\n median2(i) = median(A(:, i))\n end do\n elseif (dim .eq. 2) then\n allocate (median2(m))\n do i = 1, m\n median2(i) = median(A(i, :))\n end do\n end if\n return\n end function median2\n\n ! meshgrid\n !-----------------------------------------------------------------------\n ! meshgrid generates rectangular grid in 2 dimensions.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! call meshgrid(ax, ay, X, Y)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! call meshgrid(ax, ay, X, Y) returns replicated grid vectors of ax and\n ! ay that form a full grid.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! ax = linspace(1, 3, 3)\n ! ay = linspace(10, 14, 5)\n ! call meshgrid(ax, ay, X, Y)\n ! X =\n ! 1. 2. 3.\n ! 1. 2. 3.\n ! 1. 2. 3.\n ! 1. 2. 3.\n ! 1. 2. 3.\n ! Y =\n ! 10. 10. 10.\n ! 11. 11. 11.\n ! 12. 12. 12.\n ! 13. 13. 13.\n ! 14. 14. 14.\n\n subroutine meshgrid2(ax, ay, x, y)\n real(kind=RPRE), dimension(:), intent(in) :: ax, ay\n real(kind=RPRE), dimension(:, :), allocatable, intent(out) :: x, y\n integer(kind=IPRE) :: i, m, n\n\n m = size(ax)\n n = size(ay)\n if (.not. allocated(x)) allocate (x(n, m))\n if (.not. allocated(y)) allocate (y(n, m))\n do i = 1, n\n x(i, :) = ax\n end do\n do i = 1, m\n y(:, i) = ay\n end do\n return\n end subroutine meshgrid2\n\n ! mpi_rpre\n !-----------------------------------------------------------------------\n ! mpi_rpre returns either MPI_REAL or MPI_DOUBLE depending on RPRE.\n !\n ! Notes\n !-----------------------------------------------------------------------\n ! When calling MPI functions, use mpi_rpre instead of MPI_REAL or\n ! MPI_DOUBLE.\n !\\note: fpm has not support macro command analysis.\n ! #ifdef do_mpi\n integer(kind=4) function mpi_rpre()\n select case (RPRE)\n case (4)\n mpi_rpre = RPRE ! mpi_real\n case (8)\n mpi_rpre = RPRE ! mpi_double\n end select\n return\n end function mpi_rpre\n ! #endif\n\n ! nextpow2\n !-----------------------------------------------------------------------\n ! nextpow2 computes the exponent of the next higher power of 2.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! p = nextpow2(x)\n ! P = nextpow2(X)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! p = nextpow2(x) returns the exponent for the smallest power of two\n ! that satisfy 2**p .le. abs(x).\n !\n ! P = nextpow2(X) returns the next power of 2 of each element in\n ! vector x.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! y = nextpow2(15)\n ! 4\n !\n ! x = [ 1, -2, 3, -4, 5, 9, 519 ]\n ! y = nextpow2(x)\n ! 0 1 2 2 3 4 10\n\n function nextpow2_0(x) result(pow)\n integer(kind=IPRE) :: pow\n integer(kind=IPRE), intent(in) :: x\n\n pow = ceiling(log(real(abs(x)))/log(2.))\n return\n end function nextpow2_0\n\n function nextpow2_1(x) result(pow)\n integer(kind=IPRE), dimension(:), allocatable :: pow\n integer(kind=IPRE), dimension(:), intent(in) :: x\n\n pow = ceiling(log(real(abs(x)))/log(2.))\n return\n end function nextpow2_1\n\n ! norm\n !-----------------------------------------------------------------------\n ! norm computes vector and matrix norms.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! y = norm(x)\n ! y = norm(x, p)\n ! x = norm(A)\n ! x = norm(A, p)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! y = norm(x) returns the 2-norm or Euclidian norm of vector x.\n !\n ! y = norm(x, p) returns the p-norm of vector x, where p is any positive\n ! real value.\n !\n ! x = norm(A) returns the 2-norm of matrix A (largest singular value).\n !\n ! x = norm(A, p) returns the p-norm of matrix A, where p is {1, 2}.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! x = [ 1., 2., 3. ]\n ! y = norm(x)\n ! 3.74165750\n ! y = norm(x, 3.)\n ! 3.30192733\n\n real(kind=RPRE) function norm1(x, p)\n real(kind=RPRE), dimension(:), intent(in) :: x\n real(kind=RPRE), intent(in), optional :: p\n\n if ((.not. present(p)) .or. (p .eq. 2.)) then\n norm1 = sqrt(sum(abs(x)**2))\n elseif (p .eq. 1.) then\n norm1 = sum(abs(x))\n else\n norm1 = (sum(abs(x)**p))**(1.0d0/p)\n end if\n return\n end function norm1\n\n real(kind=RPRE) function norm2(A, p)\n real(kind=RPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE), intent(in), optional :: p\n real(kind=RPRE), dimension(:), allocatable :: w\n\n if ((.not. present(p)) .or. (p .eq. 2.)) then\n call svd(A, w)\n norm2 = maxval(w)\n elseif (p .eq. 1.) then\n norm2 = maxval(sum(abs(A), dim=2))\n end if\n return\n end function norm2\n\n\n ! normpdf\n !-----------------------------------------------------------------------\n ! normpdf computes the normal probability density function.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! y = normpdf(x, mu, sigma)\n ! y = normpdf(X, mu, sigma)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! y = normpdf(x, mu, sigma) returns the PDF at each of the points in\n ! vector x using the normal distribution with mean mu and standard\n ! deviation sigma.\n !\n ! y = normpdf(X, mu, sigma) returns the PDF at each of the\n ! multidimensional points in matrix X using the normal distribution with\n ! mean mu and covariance matrix sigma.\n\n real(kind=RPRE) function normpdf0(x, mu, sigma) result(pdf)\n real(kind=RPRE), intent(in) :: x, mu, sigma\n\n pdf = exp(-0.5d0*(x - mu)**2/sigma**2)\n pdf = pdf/(sigma*sqrt(2.0d0*pi))\n return\n end function normpdf0\n\n function normpdf1(x, mu, sigma) result(pdf)\n real(kind=RPRE), dimension(:), allocatable :: pdf\n real(kind=RPRE), dimension(:), intent(in) :: x\n real(kind=RPRE), intent(in) :: mu, sigma\n\n pdf = exp(-0.5d0*(x - mu)**2/sigma**2)\n pdf = pdf/(sigma*sqrt(2.0d0*pi))\n return\n end function normpdf1\n\n function normpdf2(X, mu, sigma) result(pdf)\n real(kind=RPRE), dimension(:), allocatable :: pdf\n real(kind=RPRE), dimension(:, :), intent(in) :: X, sigma\n real(kind=RPRE), dimension(:), intent(in) :: mu\n integer(kind=IPRE) :: n\n real(kind=RPRE), dimension(:, :), allocatable :: tmp\n\n n = size(X, 2)\n tmp = X - repmat(mu, size(X, 1), 2)\n pdf = exp(-0.5d0*sum(matmul(tmp, inv(sigma))*tmp, dim=2))\n pdf = pdf/sqrt((2.0d0*pi)**n*det(sigma))\n return\n end function normpdf2\n\n ! num2str\n !-----------------------------------------------------------------------\n ! num2str converts numbers to strings.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! str = num2str(x)\n ! str = num2str(x, fmt)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! str = num2str(x) converts x into a string.\n !\n ! str = num2str(x, fmt) converts x into a string with the format fmt.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! print *, \"Percentage: \" // num2str(50.431, \"(F6.2)\") // \"%\"\n ! Percentage: 50.43%\n\n function num2str_i4(x, fmt)\n character(len=:), allocatable :: num2str_i4\n integer(kind=4), intent(in) :: x\n character(len=*), intent(in), optional :: fmt\n character(len=CLEN) :: xstr\n\n if (present(fmt)) then\n write (xstr, fmt) x\n else\n write (xstr, *) x\n end if\n xstr = adjustl(xstr)\n num2str_i4 = trim(xstr)\n return\n end function num2str_i4\n\n function num2str_i8(x, fmt)\n character(len=:), allocatable :: num2str_i8\n integer(kind=8), intent(in) :: x\n character(len=*), intent(in), optional :: fmt\n character(len=CLEN) :: xstr\n\n if (present(fmt)) then\n write (xstr, fmt) x\n else\n write (xstr, *) x\n end if\n xstr = adjustl(xstr)\n num2str_i8 = trim(xstr)\n return\n end function num2str_i8\n\n function num2str_r4(x, fmt)\n character(len=:), allocatable :: num2str_r4\n real(kind=4), intent(in) :: x\n character(len=*), intent(in), optional :: fmt\n character(len=CLEN) :: xstr\n\n if (present(fmt)) then\n write (xstr, fmt) x\n else\n write (xstr, *) x\n end if\n xstr = adjustl(xstr)\n num2str_r4 = trim(xstr)\n return\n end function num2str_r4\n\n function num2str_r8(x, fmt)\n character(len=:), allocatable :: num2str_r8\n real(kind=8), intent(in) :: x\n character(len=*), intent(in), optional :: fmt\n character(len=CLEN) :: xstr\n\n if (present(fmt)) then\n write (xstr, fmt) x\n else\n write (xstr, *) x\n end if\n xstr = adjustl(xstr)\n num2str_r8 = trim(xstr)\n return\n end function num2str_r8\n\n ! ones\n !-----------------------------------------------------------------------\n ! ones creates array all of ones.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! x = ones(dim1)\n ! A = ones(dim1, dim2)\n ! X = ones(dim1, dim2, dim3)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! x = ones(dim1) returns a dim1 vector of ones.\n !\n ! A = ones(dim1, dim2) returns a dim1-by-dim2 matrix of ones.\n !\n ! X = ones(dim1, dim2, dim3) returns a dim1-by-dim2-by-dim3\n ! 3-dimensional matrix of ones.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! x = ones(3)\n ! x =\n ! 1. 1. 1.\n !\n ! A = ones(3, 3)\n ! A =\n ! 1. 1. 1.\n ! 1. 1. 1.\n ! 1. 1. 1.\n\n function ones1(dim1)\n real(kind=RPRE), dimension(:), allocatable :: ones1\n integer(kind=IPRE), intent(in) :: dim1\n integer(kind=IPRE) :: ierr\n\n allocate (ones1(dim1), stat=ierr)\n if (ierr .ne. 0) then\n print *, \"Error: in ones, could not allocate array.\"\n stop\n else\n ones1 = 1.0d0\n end if\n return\n end function ones1\n\n function ones2(dim1, dim2)\n real(kind=RPRE), dimension(:, :), allocatable :: ones2\n integer(kind=IPRE), intent(in) :: dim1, dim2\n integer(kind=IPRE) :: ierr\n\n allocate (ones2(dim1, dim2), stat=ierr)\n if (ierr .ne. 0) then\n print *, \"Error: in ones, could not allocate array.\"\n stop\n else\n ones2 = 1.0d0\n end if\n return\n end function ones2\n\n function ones3(dim1, dim2, dim3)\n real(kind=RPRE), dimension(:, :, :), allocatable :: ones3\n integer(kind=IPRE), intent(in) :: dim1, dim2, dim3\n integer(kind=IPRE) :: ierr\n\n allocate (ones3(dim1, dim2, dim3), stat=ierr)\n if (ierr .ne. 0) then\n print *, \"Error: in ones, could not allocate array.\"\n stop\n else\n ones3 = 1.0d0\n end if\n return\n end function ones3\n ! open\n !-----------------------------------------------------------------------\n ! open opens a File object with sequential or direct access.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! call ofile % open()\n ! call ofile % open(r)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! call ofile % open() open the File object ofile with sequential access.\n !\n ! call ofile % open(r) open the File object ofile with direct access,\n ! where r is the record length.\n\n subroutine open1(self)\n !! Version: expermental\n !! \n !! Use fortran08 NEWUNIT syntax.\n class(File), intent(inout) :: self\n integer(kind=IPRE) :: ierr\n\n open (newunit=self%unit, file=self%filename, access=\"sequential\", &\n form=\"formatted\", status=\"unknown\", iostat=ierr)\n if (ierr .ne. 0) then\n print *, \"Error: cannot read '\"//trim(self%filename)//\"'\"\n stop\n end if\n return\n end subroutine open1\n\n subroutine open2(self, r)\n !! Version: expermental\n !! \n !! Use fortran08 NEWUNIT syntax.\n class(File), intent(inout) :: self\n integer(kind=IPRE), intent(in) :: r\n integer(kind=IPRE) :: ierr\n\n open (newunit=self%unit, file=self%filename, access=\"direct\", &\n form=\"unformatted\", status=\"unknown\", recl=r, iostat=ierr)\n if (ierr .ne. 0) then\n print *, \"Error: cannot read '\"//trim(self%filename)//\"'\"\n stop\n end if\n return\n end subroutine open2\n\n ! outer\n !-----------------------------------------------------------------------\n ! outer computes the outer product of two vectors.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! A = outer(x, y)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! A = outer(x, y) returns the outer product of vectors x and y.\n\n function outer(x, y) result(A)\n real(kind=RPRE), dimension(:, :), allocatable :: A\n real(kind=RPRE), dimension(:), intent(in) :: x, y\n integer(kind=IPRE) :: m, n\n\n m = size(x)\n n = size(y)\n A = spread(x, 2, n)*spread(y, 1, m)\n return\n end function outer\n\n ! pascal\n !-----------------------------------------------------------------------\n ! pascal computes the Pascal's matrix.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! A = pascal(n)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! A = pascal(n) returns the Pascal's matrix of order n.\n !\n ! Example\n !-----------------------------------------------------------------------\n ! A = pascal(5)\n ! 1 1 1 1 1\n ! 1 2 3 4 5\n ! 1 3 6 10 15\n ! 1 4 10 20 35\n ! 1 5 15 35 70\n\n function pascal(n)\n integer(kind=IPRE), dimension(:, :), allocatable :: pascal\n integer(kind=IPRE), intent(in) :: n\n integer(kind=IPRE) :: i, j\n\n pascal = ones(n, n)\n do i = 2, n\n do j = 2, n\n pascal(i, j) = pascal(i - 1, j) + pascal(i, j - 1)\n end do\n end do\n return\n end function pascal\n\n ! prctile\n !-----------------------------------------------------------------------\n ! prctile computes the percentiles of a data set.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! q = prctile(x, p)\n ! Q = prctile(x, P)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! q = prctile(x, p) returns the p-th percentile of vector x.\n !\n ! Q = prctile(x, P) returns each percentile of vector x contained in\n ! vector P.\n\n real(kind=RPRE) function prctile0(x, p)\n real(kind=RPRE), dimension(:), intent(in) :: x\n integer(kind=IPRE), intent(in) :: p\n real(kind=RPRE) :: tmp(1)\n\n tmp = prctile1(x, [p])\n prctile0 = tmp(1)\n return\n end function prctile0\n\n function prctile1(x, p)\n real(kind=RPRE), dimension(:), allocatable :: prctile1\n real(kind=RPRE), dimension(:), intent(in) :: x\n integer(kind=IPRE), dimension(:), intent(in) :: p\n integer(kind=IPRE) :: i, nx, np, idx\n real(kind=RPRE), dimension(:), allocatable :: xsort, ap\n\n nx = size(x)\n np = size(p)\n prctile1 = zeros(np)\n xsort = sort(x)\n do i = 1, np\n if (p(i) .le. 50.0d0/real(nx, RPRE)) then\n prctile1(i) = xsort(1)\n elseif (p(i) .ge. 100.0d0*((nx - 0.5d0)/real(nx, RPRE))) then\n prctile1(i) = xsort(nx)\n else\n ap = 100.0d0*(linspace(1, nx, nx) - 0.5d0)/real(nx, RPRE)\n idx = maxval(find(p(i) .gt. ap))\n prctile1(i) = xsort(idx) &\n + (xsort(idx + 1) - xsort(idx))*(p(i) - ap(idx)) &\n /(ap(idx + 1) - ap(idx))\n end if\n end do\n return\n end function prctile1\n\n ! progress_bar\n !-----------------------------------------------------------------------\n ! Display a progression bar.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! call progress_bar(iter, itermax, step)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! call progress_bar(iter, itermax, step) displays a progress bar given\n ! the current iteration iter, the maximum number of iterations itermax,\n ! and the length of the bar steps.\n\n subroutine progress_bar(iter, itermax, step)\n integer(kind=IPRE), intent(in) :: iter, itermax\n integer(kind=IPRE), intent(in), optional :: step\n integer(kind=IPRE) :: i, perc, opt_step\n character(len=:), allocatable :: bar\n\n opt_step = 50\n if (present(step)) opt_step = step\n\n ! Initialize the bar\n bar = \" [\"\n do i = 1, opt_step\n bar = bar//\" \"\n end do\n bar = bar//\"]\"\n\n ! Compute the percentage\n perc = real(iter)/real(itermax)*100.\n\n ! Fill the bar\n do i = 1, floor(perc/(100./opt_step))\n bar(3 + i:3 + i) = \"=\"\n end do\n\n ! Place the percentage\n i = ceiling((opt_step + 2)/2.)\n write (bar(i + 1:i + 3), \"(I3)\") perc\n bar(i + 4:i + 4) = \"%\"\n\n ! Fill the space\n if (perc .lt. 100 .and. perc .gt. 50 - 100/opt_step) bar(i + 1:i + 1) = \"=\"\n\n ! Return to the beginning of the line and display the bar\n write (*, \"(A1, A)\", advance=\"no\") char(13), bar\n return\n end subroutine progress_bar\n\n ! progress_perc\n !-----------------------------------------------------------------------\n ! Display a progression percentage.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! call progress_perc(iter, itermax, prefix)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! call progress_perc(iter, itermax, prefix) displays a percentage given\n ! the current iteration iter, the maximum number of iterations itermax,\n ! and a prefix.\n\n subroutine progress_perc(iter, itermax, prefix)\n integer(kind=IPRE), intent(in) :: iter, itermax\n character(len=*), intent(in), optional :: prefix\n real(kind=RPRE) :: perc\n character(len=:), allocatable :: opt_prefix\n\n opt_prefix = \"\"\n if (present(prefix)) opt_prefix = prefix\n\n perc = real(iter)/real(itermax)*100.\n write (*, \"(A1, A, F6.2, A)\", advance=\"no\") char(13), opt_prefix, perc, \"%\"\n return\n end subroutine progress_perc\n \n\n ! randi\n !-----------------------------------------------------------------------\n ! randi generates uniformly distributed random integers.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! x = randi(imax)\n ! x = randi([imin, imax])\n ! x = randi(imax, dim1)\n ! x = randi([imin, imax], dim1)\n ! A = randi(imax, dim1, dim2)\n ! A = randi([imin, imax], dim1, dim2)\n ! X = randi(imax, dim1, dim2, dim3)\n ! X = randi([imin, imax], dim1, dim2, dim3)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! x = randi(imax) returns a random scalar integer between 1 and imax.\n !\n ! x = randi([imin, imax]) returns a random scalar integer between imin\n ! and imax.\n !\n ! x = randi(imax, dim1) returns a dim1 vector of random scalar integers\n ! between 1 and imax.\n !\n ! x = randi([imin, imax], dim1) returns a dim1 vector of random scalar\n ! integers between imin and imax.\n !\n ! A = randi(imax, dim1, dim2) returns a dim1-by-dim2 matrix of random\n ! scalar integers between 1 and imax.\n !\n ! A = randi([imin, imax], dim1, dim2) returns a dim1-by-dim2 matrix of\n ! random scalar integers between imin and imax.\n !\n ! X = randi(imax, dim1, dim2, dim3) returns a dim1-by-dim2-by-dim3\n ! 3-dimensional matrix of random scalar integers between 1 and imax.\n !\n ! X = randi([imin, imax], dim1, dim2, dim3) returns a dim1-by-dim2-by-dim3\n ! 3-dimensional matrix of random scalar integers between imin and imax.\n\n integer(kind=IPRE) function randi0_0(imax)\n integer(kind=IPRE), intent(in) :: imax\n\n randi0_0 = floor(randu()*real(imax)) + 1\n return\n end function randi0_0\n\n integer(kind=IPRE) function randi0_1(imax)\n integer(kind=IPRE), dimension(2), intent(in) :: imax\n\n randi0_1 = minval(imax) + nint(randu()*real(maxval(imax) - minval(imax)))\n return\n end function randi0_1\n\n function randi1_0(imax, dim1)\n integer(kind=IPRE), dimension(:), allocatable :: randi1_0\n integer(kind=IPRE), intent(in) :: imax, dim1\n\n randi1_0 = floor(randu(dim1)*real(imax)) + 1\n return\n end function randi1_0\n\n function randi1_1(imax, dim1)\n integer(kind=IPRE), dimension(:), allocatable :: randi1_1\n integer(kind=IPRE), dimension(2), intent(in) :: imax\n integer(kind=IPRE), intent(in) :: dim1\n\n randi1_1 = minval(imax) + nint(randu(dim1)*real(maxval(imax) - minval(imax)))\n return\n end function randi1_1\n\n function randi2_0(imax, dim1, dim2)\n integer(kind=IPRE), dimension(:, :), allocatable :: randi2_0\n integer(kind=IPRE), intent(in) :: imax, dim1, dim2\n\n randi2_0 = floor(randu(dim1, dim2)*real(imax)) + 1\n return\n end function randi2_0\n\n function randi2_1(imax, dim1, dim2)\n integer(kind=IPRE), dimension(:, :), allocatable :: randi2_1\n integer(kind=IPRE), dimension(2), intent(in) :: imax\n integer(kind=IPRE), intent(in) :: dim1, dim2\n\n randi2_1 = minval(imax) + nint(randu(dim1, dim2)*real(maxval(imax) - minval(imax)))\n return\n end function randi2_1\n\n function randi3_0(imax, dim1, dim2, dim3)\n integer(kind=IPRE), dimension(:, :, :), allocatable :: randi3_0\n integer(kind=IPRE), intent(in) :: imax, dim1, dim2, dim3\n\n randi3_0 = floor(randu(dim1, dim2, dim3)*real(imax)) + 1\n return\n end function randi3_0\n\n function randi3_1(imax, dim1, dim2, dim3)\n integer(kind=IPRE), dimension(:, :, :), allocatable :: randi3_1\n integer(kind=IPRE), dimension(2), intent(in) :: imax\n integer(kind=IPRE), intent(in) :: dim1, dim2, dim3\n\n randi3_1 = minval(imax) + nint(randu(dim1, dim2, dim3)*real(maxval(imax) - minval(imax)))\n return\n end function randi3_1 \n\n ! randperm\n !-----------------------------------------------------------------------\n ! randperm draws unique random integers.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! x = randperm(n)\n ! x = randperm(n, k)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! x = randperm(n) returns a row vector containing a random permutation\n ! of the integers from 1 to n inclusive.\n !\n ! x = randperm(n, k) returns a row vector containing k unique integers\n ! selected randomly from 1 to n inclusive.\n\n function randperm(n, k)\n integer(kind=IPRE), dimension(:), allocatable :: randperm\n integer(kind=IPRE), intent(in) :: n\n integer(kind=IPRE), intent(in), optional :: k\n integer(kind=IPRE) :: opt_k, i, j, tmp\n integer(kind=IPRE), dimension(:), allocatable :: a\n\n opt_k = n\n if (present(k)) opt_k = k\n\n a = linspace(1, n, n)\n do i = n, n - opt_k + 1, -1\n j = randi(i)\n tmp = a(i)\n a(i) = a(j)\n a(j) = tmp\n end do\n randperm = a(n - opt_k + 1:n)\n return\n end function randperm\n \n ! repmat\n !-----------------------------------------------------------------------\n ! repmat repeats copies of arrays.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! A = repmat(x, n1)\n ! A = repmat(x, n1, dim)\n ! B = repmat(A, n1, n2)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! A = repmat(x, n1) returns an array A with n1 copies of vector x. x is\n ! treated as a column vector, therefore shape(A) = ( size(x), n1 ).\n !\n ! A = repmat(x, n1, dim) returns an array A with n1 copies of vector x\n ! along the direction specified by dim.\n !\n ! B = repmat(A, n1, 2) returns an array B with n1 copies of A in first\n ! dimension and n2 copies of B in second dimension.\n\n function repmat1(x, n1, dim)\n real(kind=RPRE), dimension(:, :), allocatable :: repmat1\n real(kind=RPRE), dimension(:), intent(in) :: x\n integer(kind=IPRE), intent(in) :: n1\n integer(kind=IPRE), intent(in), optional :: dim\n integer(kind=IPRE) :: i, m\n\n m = size(x)\n if ((.not. present(dim)) .or. (dim .eq. 1)) then\n repmat1 = zeros(m, n1)\n do i = 1, n1\n repmat1(:, i) = x\n end do\n elseif (dim .eq. 2) then\n repmat1 = zeros(n1, m)\n do i = 1, n1\n repmat1(i, :) = x\n end do\n end if\n return\n end function repmat1\n\n function repmat2(A, n1, n2)\n real(kind=RPRE), dimension(:, :), allocatable :: repmat2\n real(kind=RPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE), intent(in) :: n1, n2\n integer(kind=IPRE) :: i, j, m, n\n\n m = size(A, 1)\n n = size(A, 2)\n repmat2 = zeros(m*n1, n*n2)\n do i = 1, n1\n do j = 1, n2\n repmat2((i - 1)*m + 1:i*m, (j - 1)*n + 1:j*n) = A\n end do\n end do\n return\n end function repmat2\n\n ! rms\n !-----------------------------------------------------------------------\n ! rms computes the root-mean-square level of an array.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! y = rms(x)\n ! x = rms(A)\n ! x = rms(A, 1)\n ! x = rms(A, 2)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! y = rms(x) returns the root-mean-square level of the vector x.\n !\n ! x = rms(A) returns a dim2 vector with the root-mean-square level of\n ! each column of matrix A.\n !\n ! x = rms(A, 1) (see x = rms(A)).\n !\n ! x = rms(A, 2) returns a dim1 vector with the root-mean-square level of\n ! each row of matrix A.\n\n real(kind=RPRE) function rms1(x)\n real(kind=RPRE), dimension(:), intent(in) :: x\n\n rms1 = sqrt(sum(x*x)/size(x))\n return\n end function rms1\n\n function rms2(A, dim)\n real(kind=RPRE), dimension(:), allocatable :: rms2\n real(kind=RPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE), intent(in), optional :: dim\n integer(kind=IPRE) :: i, m, n\n\n m = size(A, 1)\n n = size(A, 2)\n if ((.not. present(dim)) .or. (dim .eq. 1)) then\n allocate (rms2(n))\n do i = 1, n\n rms2(i) = rms(A(:, i))\n end do\n elseif (dim .eq. 2) then\n allocate (rms2(m))\n do i = 1, m\n rms2(i) = rms(A(i, :))\n end do\n end if\n return\n end function rms2\n\n ! signum\n !-----------------------------------------------------------------------\n ! signum returns the sign of an array.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! y = signum(x)\n ! Y = signum(X)\n ! B = signum(A)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! y = signum(x) returns the sign of x (scalar).\n !\n ! Y = signum(X) returns a vector Y with the signs of each element in the\n ! vector X.\n !\n ! B = signum(A) returns a matrix B with the signs of each elements in\n ! the matrix A.\n\n real(kind=RPRE) function signum0(x)\n real(kind=RPRE), intent(in) :: x\n if (x .lt. 0.0d0) then\n signum0 = -1.0d0\n elseif (x .gt. 0.0d0) then\n signum0 = 1.0d0\n else\n signum0 = 0.0d0\n end if\n return\n end function signum0\n\n function signum1(x)\n real(kind=RPRE), dimension(:), allocatable :: signum1\n real(kind=RPRE), dimension(:), intent(in) :: x\n integer(kind=IPRE) :: i, n\n\n n = size(x)\n signum1 = zeros(n)\n do i = 1, n\n signum1(i) = signum0(x(i))\n end do\n return\n end function signum1\n\n function signum2(A)\n real(kind=RPRE), dimension(:, :), allocatable :: signum2\n real(kind=RPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE) :: i, j, m, n\n\n m = size(A, 1)\n n = size(A, 2)\n signum2 = zeros(m, n)\n do i = 1, m\n do j = 1, n\n signum2(i, j) = signum0(A(i, j))\n end do\n end do\n return\n end function signum2\n\n ! silhouette\n !-----------------------------------------------------------------------\n ! silhouette computes the silhouette values for every observations given\n ! the clustering indices.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! s = silhouette(x, cluster)\n ! s = silhouette(X, cluster)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! s = silhouette(x, cluster) returns the silhouette values for every\n ! elements in the vector x.\n !\n ! s = silhouette(X, cluster) returns the silhouette values for every\n ! elements in the array X, each row being an observation and each\n ! column a parameter.\n !\n ! Notes\n !-----------------------------------------------------------------------\n ! After Rousseeuw P. J. (1986): \"Silhouettes: a graphical aid to the\n ! interpretation and validation of cluster analysis\".\n\n function silhouette1(x, cluster) result(s)\n real(kind=RPRE), dimension(:), allocatable :: s\n real(kind=RPRE), dimension(:), intent(in) :: x\n integer(kind=IPRE), dimension(:), intent(in) :: cluster\n integer(kind=IPRE) :: n\n real(kind=RPRE), dimension(:, :), allocatable :: A\n\n n = size(x)\n A = reshape(x, shape=[n, 1], order=[1, 2])\n s = silhouette2(A, cluster)\n return\n end function silhouette1\n\n function silhouette2(X, cluster) result(s)\n real(kind=RPRE), dimension(:), allocatable :: s\n real(kind=RPRE), dimension(:, :), intent(in) :: X\n integer(kind=IPRE), dimension(:), intent(in) :: cluster\n integer(kind=IPRE) :: i, j, K, l, n\n real(kind=RPRE) :: a, b\n integer(kind=IPRE), dimension(:), allocatable :: idx, cs\n real(kind=RPRE), dimension(:), allocatable :: d\n\n n = size(X, 1)\n K = maxval(cluster)\n if (K .eq. 1) then\n print *, \"Warning: in silhouette, the silhouette value cannot \" &\n //\"be defined for K = 1.\"\n s = zeros(n)\n return\n end if\n\n ! Size of each cluster\n !======================\n allocate (cs(K))\n do j = 1, K\n idx = find(cluster .eq. j) ! All objects in cluster j\n cs(j) = size(idx)\n end do\n\n ! Loop over objects\n !===================\n s = zeros(n)\n do i = 1, n\n\n ! Compute the dissimilarity for each cluster to current object i\n !================================================================\n d = zeros(K) ! Cluster dissimilarity to object i\n do j = 1, K\n idx = find(cluster .eq. j)\n d(j) = sum((X(idx, :) - repmat(X(i, :), cs(j), 2))**2)/cs(j)\n end do\n\n ! Compute a(i)\n !==============\n j = cluster(i)\n if (cs(j) .eq. 1) then\n s(i) = 0.0d0\n cycle ! Skip next statements and begin next iteration\n else\n a = d(j)*cs(j)/(cs(j) - 1)\n end if\n\n ! Compute b(i)\n !==============\n b = minval(d, mask=d .ne. d(j) .and. d .ne. real(0., RPRE))\n\n ! Compute s(i)\n !==============\n s(i) = (b - a)/max(a, b)\n\n end do\n\n return\n end function silhouette2\n\n ! sinc\n !-----------------------------------------------------------------------\n ! sinc computes sinc function defined as sinc(x) = sin(pi*x) / (pi*x),\n ! with the convention sinc(0) = 1.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! y = sinc(x)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! y = sinc(x) returns the sinc function of the elements in x.\n\n real(kind=RPRE) function sinc0(x)\n real(kind=RPRE), intent(in) :: x\n real(kind=RPRE) :: y\n\n if (x .eq. 0.0d0) then\n sinc0 = 1.0d0\n else\n y = pi*x\n sinc0 = sin(y)/y\n end if\n return\n end function sinc0\n\n function sinc1(x)\n real(kind=RPRE), dimension(:), allocatable :: sinc1\n real(kind=RPRE), dimension(:), intent(in) :: x\n real(kind=RPRE), dimension(:), allocatable :: y\n\n allocate (y(size(x)))\n y = pi*merge(real(1.0e-20, RPRE), x, x .eq. 0.0d0)\n sinc1 = sin(y)/y\n return\n end function sinc1\n\n ! skewness\n !-----------------------------------------------------------------------\n ! skewness computes vector and matrix skewnesses.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! y = skewness(x)\n ! y = skewness(x, flag)\n ! x = skewness(A)\n ! x = skewness(A, flag)\n ! x = skewness(A, 1)\n ! x = skewness(A, flag, 1)\n ! x = skewness(A, 2)\n ! x = skewness(A, flag, 2)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! y = skewness(x) returns the skewness of the vector x.\n !\n ! y = skewness(x, w) returns the skewness of the vector x given the\n ! flag. By default, flag is 1. If flag is 0, the function corrects for\n ! the systematic bias due to the size of the sample.\n !\n ! x = skewness(A) returns a dim2 vector with the skewnesses of each\n ! column of matrix A.\n !\n ! x = skewness(A, flag) returns a dim2 vector given the flag.\n !\n ! x = skewness(A, 1) (see x = skewness(A)).\n !\n ! x = skewness(A, flag, 1) (see x = skewness(A, flag))\n !\n ! x = skewness(A, 2) returns a dim1 vector with the skewnesses of\n ! each row of matrix A.\n !\n ! x = skewness(A, flag, 2) returns a dim1 vector given the flag.\n\n real(kind=RPRE) function skewness1(x, flag)\n real(kind=RPRE), dimension(:), intent(in) :: x\n integer(kind=IPRE), intent(in), optional :: flag\n integer(kind=IPRE) :: opt_flag, n\n\n opt_flag = 1\n if (present(flag)) opt_flag = flag\n\n n = size(x)\n skewness1 = (sum((x - mean(x))**3)/n)/(var(x, 1)**1.5)\n if (opt_flag .eq. 0) then\n skewness1 = skewness1*sqrt(real(n*(n - 1), RPRE))/real((n - 2), RPRE)\n end if\n return\n end function skewness1\n\n function skewness2(A, flag, dim)\n real(kind=RPRE), dimension(:), allocatable :: skewness2\n real(kind=RPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE), intent(in), optional :: flag, dim\n integer(kind=IPRE) :: opt_flag, i, m, n\n\n opt_flag = 1\n if (present(flag)) opt_flag = flag\n\n m = size(A, 1)\n n = size(A, 2)\n if ((.not. present(dim)) .or. (dim .eq. 1)) then\n allocate (skewness2(n))\n do i = 1, n\n skewness2(i) = skewness1(A(:, i), opt_flag)\n end do\n elseif (dim .eq. 2) then\n allocate (skewness2(m))\n do i = 1, m\n skewness2(i) = skewness1(A(i, :), opt_flag)\n end do\n end if\n return\n end function skewness2\n\n ! solve\n !-----------------------------------------------------------------------\n ! solve solves a linear matrix equation.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! x = solve(A, b)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! x = solve(A, b) returns the \"exact\" solution of the well-determined\n ! linear matrix equation Ax = b.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! A = reshape([ 11., 7., 3., 2., 12., 6., 7., 9., 4. ], [ 3, 3 ], &\n ! order = [ 2, 1 ])\n ! b = [ 34., 44., 37. ]\n ! x = solve(A, b)\n ! 1. 2. 3.\n\n function solve(A, b) result(x)\n real(kind=RPRE), dimension(:, :), intent(in) :: A\n real(kind=RPRE), dimension(:), intent(in) :: b\n integer :: i, j, m, n\n real(kind=RPRE), dimension(:), allocatable :: w, x, y\n real(kind=RPRE), dimension(:, :), allocatable :: L, U, V\n\n m = size(A, 1)\n n = size(A, 2)\n if (issquare(A)) then\n x = zeros(m)\n y = zeros(m)\n y(1) = b(1)\n\n ! LU decomposition to solve LUx = b\n !===================================\n call lu(A, L, U)\n\n ! Forward substitution: Ly = b\n !==============================\n do i = 2, m\n y(i) = b(i)\n do j = 1, i - 1\n y(i) = y(i) - y(j)*L(i, j)\n end do\n end do\n\n ! Back substitution: Ux = y\n !===========================\n x(m) = y(m)/U(m, m)\n do i = m - 1, 1, -1\n x(i) = y(i)\n do j = m, i + 1, -1\n x(i) = x(i) - x(j)*U(i, j)\n end do\n x(i) = x(i)/U(i, i)\n end do\n else\n x = svdsolve(A, b)\n end if\n return\n end function solve\n\n ! sort\\tofix\n !-----------------------------------------------------------------------\n ! sort sorts arrays elements.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! y = sort(x)\n ! y = sort(x, 1)\n ! y = sort(x, 2)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! y = sort(x) returns the sorted elements of the vector x in the\n ! ascending order.\n !\n ! y = sort(x, 1) (see y = sort(x)).\n !\n ! y = sort(x, 2) returns the sorted elements of the vector x in the\n ! descending order.\n\n function sort(x, order)\n real(kind=RPRE), dimension(:), allocatable :: sort\n real(kind=RPRE), dimension(:), intent(in) :: x\n integer(kind=IPRE), optional :: order\n integer(kind=IPRE) :: n\n logical :: l\n\n n = size(x)\n sort = x\n if ((.not. present(order)) .or. (order .eq. 1)) then\n call quicksort(sort, n, 1)\n elseif (order .eq. 2) then\n call quicksort(sort, n, 2)\n end if\n return\n\n contains\n\n !-------------------------------------------------------------------\n ! quicksort\n !-------------------------------------------------------------------\n recursive subroutine quicksort(x, n, order)\n real(kind=RPRE), dimension(n), intent(inout) :: x\n integer(kind=IPRE), intent(in) :: n, order\n integer(kind=IPRE) :: left, right, marker\n real(kind=RPRE) :: pivot, tmp\n\n if (n .gt. 1) then\n left = 0\n right = n + 1\n pivot = x(randi(n))\n\n select case (order)\n case (1)\n do while (left .lt. right)\n left = left + 1\n right = right - 1\n do while (x(left) .lt. pivot)\n left = left + 1\n end do\n do while (x(right) .gt. pivot)\n right = right - 1\n end do\n if (left .lt. right) then\n tmp = x(left)\n x(left) = x(right)\n x(right) = tmp\n end if\n end do\n case (2)\n do while (left .lt. right)\n left = left + 1\n right = right - 1\n do while (x(left) .gt. pivot)\n left = left + 1\n end do\n do while (x(right) .lt. pivot)\n right = right - 1\n end do\n if (left .lt. right) then\n tmp = x(left)\n x(left) = x(right)\n x(right) = tmp\n end if\n end do\n end select\n\n if (left .eq. right) then\n marker = left + 1\n else\n marker = left\n end if\n\n call quicksort(x(:marker - 1), marker - 1, order)\n call quicksort(x(marker:), n - marker + 1, order)\n end if\n return\n end subroutine quicksort\n\n end function sort\n\n ! spline1\n !-----------------------------------------------------------------------\n ! spline1 performs a cubic spline interpolation with natural end\n ! condition.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! yq = spline1(x, y, xq)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! yq = spline1(x, y, xq) returns the evaluated vector yq at the query\n ! points in xq using a cubic spline interpolation.\n\n real(kind=RPRE) function spline1_0(x, y, xq) result(yq)\n real(kind=RPRE), dimension(:), intent(in) :: x, y\n real(kind=RPRE), intent(in) :: xq\n real(kind=RPRE) :: tmp(1)\n\n tmp = spline1(x, y, [xq])\n yq = tmp(1)\n return\n end function spline1_0\n\n function spline1_1(x, y, xq) result(yq)\n real(kind=RPRE), dimension(:), allocatable :: yq\n real(kind=RPRE), dimension(:), intent(in) :: x, y, xq\n integer(kind=IPRE) :: i, n, nq, x1\n real(kind=RPRE), dimension(:), allocatable :: w, h, z, a, b, c, d\n\n n = size(x)\n nq = size(xq)\n allocate (w(n - 1), h(n - 1), z(n), a(n - 1), b(n - 1), c(n - 1), d(n - 1), yq(nq))\n\n ! Compute h and b\n !=================\n do i = 1, n - 1\n w(i) = x(i + 1) - x(i)\n h(i) = (y(i + 1) - y(i))/w(i)\n end do\n\n ! Compute z\n !===========\n z(1) = 0.0d0\n do i = 1, n - 2\n z(i + 1) = 3.0d0*(h(i + 1) - h(i))/(w(i + 1) + w(i))\n end do\n z(n) = 0.0d0\n\n ! Basis functions\n !=================\n do i = 1, n - 1\n a(i) = (z(i + 1) - z(i))/(6.0d0*w(i))\n b(i) = 0.5d0*z(i)\n c(i) = h(i) - w(i)*(z(i + 1) + 2.0d0*z(i))/6.0d0\n d(i) = y(i)\n end do\n\n ! Evaluate\n !==========\n do i = 1, nq\n x1 = max(1, minloc(xq(i) - x, 1, mask=xq(i) .gt. x))\n yq(i) = d(x1) + (xq(i) - x(x1)) &\n *(c(x1) + (xq(i) - x(x1)) &\n *(b(x1) + (xq(i) - x(x1)) &\n *a(x1)))\n end do\n return\n end function spline1_1\n\n ! spline2\n !-----------------------------------------------------------------------\n ! spline2 performs a bicubic spline interpolation with natural end\n ! condition.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! zq = spline2(x, y, Z, xq, yq)\n ! ZQ = spline2(x, y, Z, XQ, YQ)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! zq = spline2(x, y, Z, xq, yq) returns the evaluated vector zq at the\n ! query points in xq and yq using a bicubic interpolation.\n !\n ! ZQ = spline2(x, y, Z, XQ, YQ) returns the evaluated matrix ZQ given\n ! mesh type grids XQ and YQ using a bicubic interpolation. ZQ is of the\n ! same shape as XQ and YQ.\n\n function spline2_1(x, y, z, xq, yq) result(zq)\n real(kind=RPRE), dimension(:), allocatable :: zq\n real(kind=RPRE), dimension(:), intent(in) :: x, y, xq, yq\n real(kind=RPRE), dimension(:, :), intent(in) :: z\n integer(kind=IPRE) :: i, iq, j, k, m, n, nq, x0, y0\n real(kind=RPRE) :: wt(16, 16), zv(16), c(4, 4), dx, dy, t, u\n real(kind=RPRE), dimension(:, :), allocatable :: zt, z1, z2, z12\n\n m = size(x)\n n = size(y)\n nq = size(xq)\n\n ! Work on the transpose so that x corresponds to the 2nd dimension\n ! and y to the 1st dimension\n !==================================================================\n zt = transpose(z)\n\n ! Inverted coefficient matrix\n !=============================\n wt = reshape([1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., &\n 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., &\n -3., 3., 0., 0., -2., -1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., &\n 2., -2., 0., 0., 1., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., &\n 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., &\n 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., &\n 0., 0., 0., 0., 0., 0., 0., 0., -3., 3., 0., 0., -2., -1., 0., 0., &\n 0., 0., 0., 0., 0., 0., 0., 0., 2., -2., 0., 0., 1., 1., 0., 0., &\n -3., 0., 3., 0., 0., 0., 0., 0., -2., 0., -1., 0., 0., 0., 0., 0., &\n 0., 0., 0., 0., -3., 0., 3., 0., 0., 0., 0., 0., -2., 0., -1., 0., &\n 9., -9., -9., 9., 6., 3., -6., -3., 6., -6., 3., -3., 4., 2., 2., 1., &\n -6., 6., 6., -6., -3., -3., 3., 3., -4., 4., -2., 2., -2., -2., -1., -1., &\n 2., 0., -2., 0., 0., 0., 0., 0., 1., 0., 1., 0., 0., 0., 0., 0., &\n 0., 0., 0., 0., 2., 0., -2., 0., 0., 0., 0., 0., 1., 0., 1., 0., &\n -6., 6., 6., -6., -4., -2., 4., 2., -3., 3., -3., 3., -2., -1., -2., -1., &\n 4., -4., -4., 4., 2., 2., -2., -2., 2., -2., 2., -2., 1., 1., 1., 1.], &\n shape=[16, 16], order=[2, 1])\n\n ! Compute partial derivatives along x-axis and y-axis, and cross\n ! derivatives\n !================================================================\n call zdiff(x, y, zt, z1, z2, z12)\n\n ! Loop for each query point\n !===========================\n zq = zeros(nq)\n\n do iq = 1, nq\n\n ! Locate the query point\n !========================\n x0 = minloc(xq(iq) - x, 1, mask=xq(iq) .ge. x)\n y0 = minloc(yq(iq) - y, 1, mask=yq(iq) .ge. y)\n dx = x(x0 + 1) - x(x0)\n dy = y(y0 + 1) - y(y0)\n\n ! Build zv so that wt\u00b7zv = c, the cubic basis coefficients\n !==========================================================\n zv = [zt(x0, y0), &\n zt(x0 + 1, y0), &\n zt(x0, y0 + 1), &\n zt(x0 + 1, y0 + 1), &\n z1(x0, y0)*dx, &\n z1(x0 + 1, y0)*dx, &\n z1(x0, y0 + 1)*dx, &\n z1(x0 + 1, y0 + 1)*dx, &\n z2(x0, y0)*dy, &\n z2(x0 + 1, y0)*dy, &\n z2(x0, y0 + 1)*dy, &\n z2(x0 + 1, y0 + 1)*dy, &\n z12(x0, y0)*dx*dy, &\n z12(x0 + 1, y0)*dx*dy, &\n z12(x0, y0 + 1)*dx*dy, &\n z12(x0 + 1, y0 + 1)*dx*dy]\n\n ! Solve for c\n !=============\n c = reshape(matmul(wt, zv), shape=[4, 4], order=[1, 2])\n\n ! Scaling coefficients so that 0 <= (t, u) <= 1\n !===============================================\n t = (xq(iq) - x(x0))/dx\n u = (yq(iq) - y(y0))/dy\n\n ! Evaluate at the query point\n !=============================\n do i = 1, 4\n do j = 1, 4\n zq(iq) = zq(iq) + c(i, j)*t**(i - 1)*u**(j - 1)\n end do\n end do\n\n end do\n return\n\n contains\n\n !-------------------------------------------------------------------\n ! zdiff\n !-------------------------------------------------------------------\n subroutine zdiff(x, y, zt, z1, z2, z12)\n real(kind=RPRE), dimension(:), intent(in) :: x, y\n real(kind=RPRE), dimension(:, :), intent(in) :: zt\n real(kind=RPRE), dimension(:, :), allocatable, intent(out) :: z1, z2, z12\n\n allocate (z1(m, n), z2(m, n), z12(m, n))\n\n ! Middle\n !========\n do j = 2, m - 1\n do k = 2, n - 1\n z1(j, k) = (zt(j + 1, k) - zt(j - 1, k))/(x(j + 1) - x(j - 1))\n z2(j, k) = (zt(j, k + 1) - zt(j, k - 1))/(y(k + 1) - y(k - 1))\n z12(j, k) = (zt(j + 1, k + 1) - zt(j + 1, k - 1) - zt(j - 1, k + 1) + zt(j - 1, k - 1)) &\n /((x(j + 1) - x(j - 1))*(y(k + 1) - y(k - 1)))\n end do\n end do\n\n ! Left edge\n !===========\n do j = 2, m - 1\n z1(j, 1) = (zt(j + 1, 1) - zt(j, 1))/(x(j + 1) - x(j))\n z2(j, 1) = (zt(j, 2) - zt(j, 1))/(y(2) - y(1))\n z12(j, 1) = (zt(j + 1, 2) - zt(j + 1, 1) - zt(j, 2) + zt(j, 1)) &\n /((x(j + 1) - x(j))*(y(2) - y(1)))\n end do\n\n ! Upper edge\n !============\n do k = 2, n - 1\n z1(1, k) = (zt(2, k) - zt(1, k))/(x(2) - x(1))\n z2(1, k) = (zt(1, k + 1) - zt(1, k))/(y(k + 1) - y(k))\n z12(1, k) = (zt(2, k + 1) - zt(2, k) - zt(1, k + 1) + zt(1, k)) &\n /((x(2) - x(1))*(y(k + 1) - y(k)))\n end do\n\n ! Right edge\n !============\n do j = 2, m - 1\n z1(j, n) = (zt(j + 1, n) - zt(j, n))/(x(j + 1) - x(j))\n z2(j, n) = (zt(j, n) - zt(j, n - 1))/(y(n) - y(n - 1))\n z12(j, n) = (zt(j + 1, n) - zt(j + 1, n - 1) - zt(j, n) + zt(j, n - 1)) &\n /((x(j + 1) - x(j))*(y(n) - y(n - 1)))\n end do\n\n ! Lower edge\n !============\n do k = 2, n - 1\n z1(m, k) = (zt(m, k) - zt(m - 1, k))/(x(m) - x(m - 1))\n z2(m, k) = (zt(m, k + 1) - zt(m, k))/(y(k + 1) - y(k))\n z12(m, k) = (zt(m, k + 1) - zt(m, k) - zt(m - 1, k + 1) + zt(m - 1, k)) &\n /((x(m) - x(m - 1))*(y(k + 1) - y(k)))\n end do\n\n ! Upper-left corner\n !===================\n z1(1, 1) = (zt(2, 1) - zt(1, 1))/(x(2) - x(1))\n z2(1, 1) = (zt(1, 2) - zt(1, 1))/(y(2) - y(1))\n z12(1, 1) = (zt(2, 2) - zt(2, 1) - zt(1, 2) + zt(1, 1)) &\n /((x(2) - x(1))*(y(2) - y(1)))\n\n ! Upper-right corner\n !====================\n z1(1, n) = (zt(2, n) - zt(1, n))/(x(2) - x(1))\n z2(1, n) = (zt(1, n) - zt(1, n - 1))/(y(n) - y(n - 1))\n z12(1, n) = (zt(2, n) - zt(2, n - 1) - zt(1, n) + zt(1, n - 1)) &\n /((x(2) - x(1))*(y(n) - y(n - 1)))\n\n ! Lower-left corner\n !===================\n z1(m, 1) = (zt(m, 1) - zt(m - 1, 1))/(x(m) - x(m - 1))\n z2(m, 1) = (zt(m, 2) - zt(m, 1))/(y(2) - y(1))\n z12(m, 1) = (zt(m, 2) - zt(m, 1) - zt(m - 1, 2) + zt(m - 1, 1)) &\n /((x(m) - x(m - 1))*(y(2) - y(1)))\n\n ! Lower-right corner\n !====================\n z1(m, n) = (zt(m, n) - zt(m - 1, n))/(x(m) - x(m - 1))\n z2(m, n) = (zt(m, n) - zt(m, n - 1))/(y(n) - y(n - 1))\n z12(m, n) = (zt(m, n) - zt(m, n - 1) - zt(m - 1, n) + zt(m - 1, n - 1)) &\n /((x(m) - x(m - 1))*(y(m) - y(m - 1)))\n\n return\n end subroutine zdiff\n\n end function spline2_1\n\n function spline2_2(x, y, z, xq, yq) result(zq)\n real(kind=RPRE), dimension(:, :), allocatable :: zq\n real(kind=RPRE), dimension(:), intent(in) :: x, y\n real(kind=RPRE), dimension(:, :), intent(in) :: z, xq, yq\n integer(kind=IPRE) :: m, n\n\n m = size(xq, 1)\n n = size(xq, 2)\n zq = reshape(spline2_1(x, y, z, [xq], [yq]), shape=[m, n])\n return\n end function spline2_2\n\n ! split_argument\n !-----------------------------------------------------------------------\n ! split_argument takes a command line argument of type 'argname=argval'\n ! (obtained by get_command_argument) and returns argname and argval.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! call split_argument(argin, argname, argval)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! call split_argument(argin, argname, argval) splits argin into argname\n ! and argval as strings.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! nargin = command_argument_count()\n ! do i = 1, nargin\n ! call get_command_argument(i, argin)\n ! call split_argument(argin, argname, argval)\n ! print *, argname, argval\n ! end do\n\n subroutine split_argument(argin, argname, argval)\n character(len=*), intent(in) :: argin\n character(len=:), allocatable, intent(out) :: argname, argval\n integer(kind=IPRE) :: idx\n\n idx = index(argin, \"=\")\n if (idx .ne. 0) then\n argname = trim(argin(:idx - 1))\n argval = trim(argin(idx + 1:))\n else\n print *, \"Error: missing '=' in argument '\"//trim(argin)//\"'\"\n stop\n end if\n return\n end subroutine split_argument\n\n ! std\n !-----------------------------------------------------------------------\n ! std computes vector and matrix standard deviations.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! y = std(x)\n ! y = std(x, w)\n ! x = std(A)\n ! x = std(A, w)\n ! x = std(A, 1)\n ! x = std(A, w, 1)\n ! x = std(A, 2)\n ! x = std(A, w, 2)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! y = std(x) returns the standard deviation of the vector x.\n !\n ! y = std(x, w) returns the standard deviation of the vector x with the\n ! normalization option w.\n ! - 0 (default) normalize by N-1,\n ! - 1 normalize by N.\n !\n ! x = std(A) returns a dim2 vector with the standard deviations of each\n ! column of matrix A.\n !\n ! x = std(A, w) returns a dim2 vector with the normalization option w.\n !\n ! x = std(A, 1) (see x = std(A)).\n !\n ! x = std(A, w, 1) (see x = std(A, w))\n !\n ! x = std(A, 2) returns a dim1 vector with the standard deviations of\n ! each row of matrix A.\n !\n ! x = std(A, w, 2) returns a dim1 vector with the normalization option\n ! w.\n\n real(kind=RPRE) function std1(x, w)\n real(kind=RPRE), dimension(:), intent(in) :: x\n integer(kind=IPRE), intent(in), optional :: w\n integer(kind=IPRE) :: opt_w\n\n opt_w = 0\n if (present(w)) opt_w = w\n\n std1 = sqrt(var(x, opt_w))\n return\n end function std1\n\n function std2(A, w, dim)\n real(kind=RPRE), dimension(:), allocatable :: std2\n real(kind=RPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE), intent(in), optional :: w, dim\n integer(kind=IPRE) :: opt_w\n\n opt_w = 0\n if (present(w)) opt_w = w\n\n if (.not. present(dim)) then\n std2 = sqrt(var(A, opt_w))\n else\n std2 = sqrt(var(A, opt_w, dim))\n end if\n return\n end function std2\n\n ! svd\n !-----------------------------------------------------------------------\n ! svd computes the singular value decomposition.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! call svd(A, w)\n ! call svd(A, w, U, V)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! call svd(A, w) returns the singular values of the matrix A sorted in\n ! descending order.\n !\n ! call svd(A, w, U, V) returns the singular values of the m-by-n\n ! matrix A sorted in descending order. The output matrices are:\n ! - w is a n vector\n ! - U is a m-by-n unitary matrix\n ! - V is a n-by-n unitary matrix\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! A = reshape([ 1., 2., 3., 4., 5., 6., 7., 8., 9. ], [ 3, 3 ], &\n ! order = [ 2, 1 ])\n ! call svd(A, w)\n ! call disp(w)\n ! 16.8481007 1.06836963 2.10855418E-07\n ! call svd(A, w, U, V)\n ! call disp(U)\n ! -0.214837193 -0.887230873 -0.408247918\n ! -0.520587385 -0.249643773 -0.816496670\n ! -0.826337695 0.387942642 0.408248365\n ! call disp(V)\n ! -0.479671091 0.776690900 -0.408248752\n ! -0.572367728 0.075686932 0.816496611\n ! -0.665064454 -O.625318289 -0.408247977\n !\n ! Notes\n !-----------------------------------------------------------------------\n ! This code is adapted from Numerical Recipes in Fortran 90.\n\n subroutine svd(a, w, u, v, d, ierr)\n real(kind=RPRE), dimension(:, :), intent(in) :: a\n real(kind=RPRE), dimension(:), allocatable, intent(out) :: w\n real(kind=RPRE), dimension(:, :), allocatable, intent(out), optional :: u, v\n logical, intent(in), optional :: d\n integer(kind=IPRE), intent(out), optional :: ierr\n integer(kind=IPRE) :: m, n, i, its, i1, j, k, kk, k1, l, ll, l1, mn\n integer(kind=IPRE), dimension(:), allocatable :: idx\n real(kind=RPRE) :: c, f, g, h, s, scale, tst1, tst2, x, y, z\n real(kind=RPRE), dimension(:), allocatable :: rv1\n real(kind=RPRE), dimension(:, :), allocatable :: opt_u, opt_v\n logical :: outu = .false., outv = .false., opt_d = .true., outierr = .false.\n\n m = size(a, 1)\n n = size(a, 2)\n\n if (.not. allocated(w)) allocate (w(n))\n allocate (rv1(n), opt_u(m, n), opt_v(n, n))\n\n opt_u = a\n\n if (present(d)) opt_d = d\n if (present(u)) outu = .true.\n if (present(v)) outv = .true.\n if (present(ierr)) outierr = .true.\n\n ! Householder reduction to bidiagonal form\n !==========================================\n g = 0.0d0\n scale = 0.0d0\n x = 0.0d0\n\n do i = 1, n\n l = i + 1\n rv1(i) = scale*g\n g = 0.0d0\n s = 0.0d0\n scale = 0.0d0\n if (i .le. m) then\n scale = sum(abs(opt_u(i:m, i)))\n if (scale .ne. 0.0d0) then\n opt_u(i:m, i) = opt_u(i:m, i)/scale\n s = sum(opt_u(i:m, i)**2)\n f = opt_u(i, i)\n g = -sign(sqrt(s), f)\n h = f*g - s\n opt_u(i, i) = f - g\n if (i .ne. n) then\n do j = l, n\n s = dot_product(opt_u(i:m, i), opt_u(i:m, j))\n opt_u(i:m, j) = opt_u(i:m, j) + s*opt_u(i:m, i)/h\n end do\n end if\n opt_u(i:m, i) = scale*opt_u(i:m, i)\n end if\n end if\n\n w(i) = scale*g\n g = 0.0d0\n s = 0.0d0\n scale = 0.0d0\n\n if ((i .le. m) .and. (i .ne. n)) then\n scale = sum(abs(opt_u(i, l:n)))\n if (scale .ne. 0.0d0) then\n opt_u(i, l:n) = opt_u(i, l:n)/scale\n s = sum(opt_u(i, l:n)**2)\n f = opt_u(i, l)\n g = -sign(sqrt(s), f)\n h = f*g - s\n opt_u(i, l) = f - g\n rv1(l:n) = opt_u(i, l:n)/h\n\n if (i .ne. m) then\n do j = l, m\n s = dot_product(opt_u(j, l:n), opt_u(i, l:n))\n opt_u(j, l:n) = opt_u(j, l:n) + s*rv1(l:n)\n end do\n end if\n\n opt_u(i, l:n) = scale*opt_u(i, l:n)\n end if\n end if\n\n x = max(x, abs(w(i)) + abs(rv1(i)))\n end do\n\n ! Accumulation of right-hand transformations\n !============================================\n if (outv) then\n do i = n, 1, -1\n if (i .ne. n) then\n if (g .ne. 0.0d0) then\n opt_v(l:n, i) = (opt_u(i, l:n)/opt_u(i, l))/g\n do j = l, n\n s = dot_product(opt_u(i, l:n), opt_v(l:n, j))\n opt_v(l:n, j) = opt_v(l:n, j) + s*opt_v(l:n, i)\n end do\n end if\n opt_v(i, l:n) = 0.0d0\n opt_v(l:n, i) = 0.0d0\n end if\n opt_v(i, i) = 1.0d0\n g = rv1(i)\n l = i\n end do\n end if\n\n ! Accumulation of left-hand transformations\n !===========================================\n if (outu) then\n mn = min(m, n)\n do i = min(m, n), 1, -1\n l = i + 1\n g = w(i)\n if (i .ne. n) opt_u(i, l:n) = 0.0d0\n if (g .ne. 0.0d0) then\n if (i .ne. mn) then\n do j = l, n\n s = dot_product(opt_u(l:m, i), opt_u(l:m, j))\n f = (s/opt_u(i, i))/g\n opt_u(i:m, j) = opt_u(i:m, j) + f*opt_u(i:m, i)\n end do\n end if\n opt_u(i:m, i) = opt_u(i:m, i)/g\n else\n opt_u(i:m, i) = 0.0d0\n end if\n opt_u(i, i) = opt_u(i, i) + 1.0d0\n end do\n end if\n\n ! Diagonalization of the bidiagonal form\n !========================================\n tst1 = x\n do kk = 1, n\n k1 = n - kk\n k = k1 + 1\n its = 0\n\n ! Test for splitting\n !====================\n520 continue\n do ll = 1, k\n l1 = k - ll\n l = l1 + 1\n tst2 = tst1 + abs(rv1(l))\n if (tst2 .eq. tst1) goto 565\n tst2 = tst1 + abs(w(l1))\n if (tst2 .eq. tst1) exit\n end do\n\n ! Cancellation of rv1(l) if L greater than 1\n !============================================\n c = 0.0d0\n s = 1.0d0\n do i = l, k\n f = s*rv1(i)\n rv1(i) = c*rv1(i)\n tst2 = tst1 + abs(f)\n if (tst2 .eq. tst1) goto 565\n g = w(i)\n h = pythag(f, g)\n w(i) = h\n c = g/h\n s = -f/h\n if (outu) then\n do j = 1, m\n y = opt_u(j, l1)\n z = opt_u(j, i)\n opt_u(j, l1) = y*c + z*s\n opt_u(j, i) = -y*s + z*c\n end do\n end if\n end do\n\n ! Test for convergence\n !======================\n565 continue\n z = w(k)\n if (l .eq. k) goto 650\n\n ! Shift from bottom 2 by 2 minor\n !================================\n if (its .ge. 30) then\n if (outierr) ierr = k\n return\n end if\n its = its + 1\n x = w(l)\n y = w(k1)\n g = rv1(k1)\n h = rv1(k)\n f = 0.5d0*(((g + z)/h)*((g - z)/y) + y/h - h/y)\n g = pythag(f, real(1., kind=RPRE))\n f = x - (z/x)*z + (h/x)*(y/(f + sign(g, f)) - h)\n\n ! Next QR transformation\n !========================\n c = 1.0d0\n s = 1.0d0\n do i1 = l, k1\n i = i1 + 1\n g = rv1(i)\n y = w(i)\n h = s*g\n g = c*g\n z = pythag(f, h)\n rv1(i1) = z\n c = f/z\n s = h/z\n f = x*c + g*s\n g = -x*s + g*c\n h = y*s\n y = y*c\n if (outv) then\n do j = 1, n\n x = opt_v(j, i1)\n z = opt_v(j, i)\n opt_v(j, i1) = x*c + z*s\n opt_v(j, i) = -x*s + z*c\n end do\n end if\n z = pythag(f, h)\n w(i1) = z\n\n ! Rotation can be arbitrary if Z is zero\n !========================================\n if (z .ne. 0.0d0) then\n c = f/z\n s = h/z\n end if\n f = c*g + s*y\n x = -s*g + c*y\n if (outu) then\n do j = 1, m\n y = opt_u(j, i1)\n z = opt_u(j, i)\n opt_u(j, i1) = y*c + z*s\n opt_u(j, i) = -y*s + z*c\n end do\n end if\n end do\n rv1(l) = 0.0d0\n rv1(k) = f\n w(k) = x\n go to 520\n\n ! Convergence\n !=============\n650 continue\n if (z .le. 0.0d0) then\n w(k) = -z\n if (outv) then\n opt_v(1:n, k) = -opt_v(1:n, k)\n end if\n end if\n end do\n\n ! Sort singular values\n !======================\n if (opt_d) then\n idx = argsort(w, 2)\n w = w(idx)\n if (present(u)) u = opt_u(:, idx)\n if (present(v)) v = opt_v(:, idx)\n else\n if (present(u)) u = opt_u\n if (present(v)) v = opt_v\n end if\n\n return\n\n contains\n\n !-------------------------------------------------------------------\n ! pythag\n !-------------------------------------------------------------------\n real(kind=RPRE) function pythag(x1, x2)\n real(kind=RPRE), intent(in) :: x1, x2\n real(kind=RPRE) :: r, s, t, u\n\n pythag = max(abs(x1), abs(x2))\n if (pythag .ne. 0.0d0) then\n r = (min(abs(x1), abs(x2))/pythag)**2\n do\n t = 4.0d0 + r\n if (t .eq. 4.0d0) exit\n s = r/t\n u = 1.0d0 + 2.0d0*s\n pythag = u*pythag\n r = (s/u)**2*r\n end do\n end if\n return\n end function pythag\n\n end subroutine svd\n\n ! svdsolve\n !-----------------------------------------------------------------------\n ! svdsolve solves a linear matrix equation from the singular value\n ! decomposition of A.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! x = svdsolve(A, b)\n ! x = svdsolve(A, b, k)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! x = svdsolve(A, b) returns the full-rank solution of the linear matrix\n ! equation Ax = b.\n !\n ! x = svdsolve(A, b, k) returns the reduced-rank solution of the linear\n ! matrix equation Ax = b, where A is a m-by-n matrix. Therefore, the\n ! rank of the solution is n-k.\n !\n ! Notes\n !-----------------------------------------------------------------------\n ! Sometimes, too small singular values produce very large solution. A\n ! proper way to determine the cut-off singular value is using a L-curve\n ! criterion. The cut-off singular value corresponds to the singular\n ! value from which the residuals norm is not improved while the solution\n ! norm increases substantially.\n\n function svdsolve(A, b, cutoff) result(x)\n real(kind=RPRE), dimension(:, :), intent(in) :: A\n real(kind=RPRE), dimension(:), intent(in) :: b\n integer(kind=IPRE), intent(in), optional :: cutoff\n integer :: i, k, n\n real(kind=RPRE), dimension(:), allocatable :: w, x, xnorm, resnorm\n real(kind=RPRE), dimension(:, :), allocatable :: U, V\n\n n = size(A, 2)\n k = n\n if (present(cutoff)) k = k - cutoff\n xnorm = zeros(n)\n resnorm = zeros(n)\n call svd(A, w, U, V)\n do i = 1, n\n x = matmul(matmul(matmul(V(:, :i), diag(1/w(:i))), transpose(U(:, :i))), b)\n xnorm(i) = norm(x)\n resnorm(i) = norm(matmul(A, x) - b)\n end do\n x = matmul(matmul(matmul(V(:, :k), diag(1/w(:k))), transpose(U(:, :k))), b)\n return\n end function svdsolve\n\n ! tic / toc\n !-----------------------------------------------------------------------\n ! tic saves the elapsed CPU time in seconds.\n ! toc displays and returns the elapsed time since tic.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! call tic()\n ! call toc()\n ! call toc(t)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! call tic() saves the elapsed CPU time in seconds.\n !\n ! call toc() displays the elapsed time since call tic().\n !\n ! call toc(t) displays and saves the elapsed time since call tic().\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! call tic()\n ! ! ... some codes ...\n ! call toc()\n ! Elapsed time: 0.1 seconds\n\n subroutine tic()\n integer(kind=IPRE) :: values(8)\n call date_and_time(values=values)\n tic_time = datenum(values(1), values(2), values(3), values(5), &\n values(6), values(7), values(8)*1000) &\n *24.0d0*60.0d0*60.0d0\n return\n end subroutine tic\n\n subroutine toc(t)\n real(kind=8), intent(out), optional :: t\n integer(kind=IPRE) :: values(8)\n real(kind=8) :: toc_time, elapsed_time\n\n call date_and_time(values=values)\n toc_time = datenum(values(1), values(2), values(3), values(5), &\n values(6), values(7), values(8)*1000) &\n *24.0d0*60.0d0*60.0d0\n elapsed_time = toc_time - tic_time\n if (present(t)) then\n t = elapsed_time\n else\n print *, \"Elapsed time: \" &\n //num2str(real(elapsed_time, kind=RPRE), \"(F12.3)\") &\n //\" seconds\"\n end if\n return\n end subroutine toc\n\n ! trace\n !-----------------------------------------------------------------------\n ! trace computes the sum of diagonal elements.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! x = trace(A)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! x = trace(A) returns the sum of the elements on the main diagonal of\n ! the matrix A.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! A = eye(3)\n ! x = trace(A)\n ! 3.\n\n real(kind=RPRE) function trace(A)\n real(kind=RPRE), dimension(:, :), intent(in) :: A\n\n trace = sum(diag(A))\n return\n end function trace\n\n ! tril\n !-----------------------------------------------------------------------\n ! tril extracts the lower triangular part of a matrix.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! B = tril(A)\n ! B = tril(A, k)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! B = tril(A) returns the lower triangular part of matrix A.\n !\n ! B = tril(A, k) returns the elements on and below the kth diagonal of\n ! matrix X:\n ! - k = 0 is the main diagonal,\n ! - k > 0 is above the main diagonal,\n ! - k < 0 is below the main diagonal.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! A = ones(4, 4)\n ! B = tril(A, -1)\n ! 0. 0. 0. 0.\n ! 1. 0. 0. 0.\n ! 1. 1. 0. 0.\n ! 1. 1. 1. 0.\n\n function tril_i(A, k)\n integer(kind=IPRE), dimension(:, :), allocatable :: tril_i\n integer(kind=IPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE), intent(in), optional :: k\n integer(kind=IPRE) :: opt_k, i, m, n\n\n opt_k = 0\n if (present(k)) opt_k = k\n\n m = size(A, 1)\n n = size(A, 2)\n tril_i = A\n do i = 1, min(m, n)\n tril_i(:i - opt_k - 1, i) = 0.0d0\n end do\n return\n end function tril_i\n\n function tril_r(A, k)\n real(kind=RPRE), dimension(:, :), allocatable :: tril_r\n real(kind=RPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE), intent(in), optional :: k\n integer(kind=IPRE) :: opt_k, i, m, n\n\n opt_k = 0\n if (present(k)) opt_k = k\n\n m = size(A, 1)\n n = size(A, 2)\n tril_r = A\n do i = 1, min(m, n)\n tril_r(:i - opt_k - 1, i) = 0.0d0\n end do\n return\n end function tril_r\n\n function tril_c(A, k)\n complex(kind=RPRE), dimension(:, :), allocatable :: tril_c\n complex(kind=RPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE), intent(in), optional :: k\n integer(kind=IPRE) :: opt_k, i, m, n\n\n opt_k = 0\n if (present(k)) opt_k = k\n\n m = size(A, 1)\n n = size(A, 2)\n tril_c = A\n do i = 1, min(m, n)\n tril_c(:i - opt_k - 1, i) = 0.0d0\n end do\n return\n end function tril_c\n\n ! triu\n !-----------------------------------------------------------------------\n ! triu extracts the upper triangular part of a matrix.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! B = triu(A)\n ! B = triu(A, k)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! B = triu(A) returns the upper triangular part of matrix A.\n !\n ! B = triu(A, k) returns the elements on and above the kth diagonal of\n ! matrix X:\n ! - k = 0 is the main diagonal,\n ! - k > 0 is above the main diagonal,\n ! - k < 0 is below the main diagonal.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! A = ones(4, 4)\n ! B = triu(A, -1)\n ! 1. 1. 1. 1.\n ! 1. 1. 1. 1.\n ! 0. 1. 1. 1.\n ! 0. 0. 1. 1.\n\n function triu_i(A, k)\n integer(kind=IPRE), dimension(:, :), allocatable :: triu_i\n integer(kind=IPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE), intent(in), optional :: k\n integer(kind=IPRE) :: opt_k, i, m, n\n\n opt_k = 0\n if (present(k)) opt_k = k\n\n m = size(A, 1)\n n = size(A, 2)\n triu_i = A\n do i = 1, min(m, n)\n triu_i(i - opt_k + 1:, i) = 0.0d0\n end do\n return\n end function triu_i\n\n function triu_r(A, k)\n real(kind=RPRE), dimension(:, :), allocatable :: triu_r\n real(kind=RPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE), intent(in), optional :: k\n integer(kind=IPRE) :: opt_k, i, m, n\n\n opt_k = 0\n if (present(k)) opt_k = k\n\n m = size(A, 1)\n n = size(A, 2)\n triu_r = A\n do i = 1, min(m, n)\n triu_r(i - opt_k + 1:, i) = 0.0d0\n end do\n return\n end function triu_r\n\n function triu_c(A, k)\n complex(kind=RPRE), dimension(:, :), allocatable :: triu_c\n complex(kind=RPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE), intent(in), optional :: k\n integer(kind=IPRE) :: opt_k, i, m, n\n\n opt_k = 0\n if (present(k)) opt_k = k\n\n m = size(A, 1)\n n = size(A, 2)\n triu_c = A\n do i = 1, min(m, n)\n triu_c(i - opt_k + 1:, i) = 0.0d0\n end do\n return\n end function triu_c\n\n ! utm2deg\n !-----------------------------------------------------------------------\n ! utm2deg converts UTM-WGS84 coordinates to latitude / longitude\n ! (in degrees) coordinates.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! call utm2deg(east, north, zn, zl, lat, lon)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! call utm2deg(east, north, zn, zl, lat, lon) converts the UTM-WGS84\n ! coordinates in east and north to latitude / longitude coordinates\n ! (in degrees). It outputs the latitudes lat and the longitudes lon.\n !\n ! Notes\n !-----------------------------------------------------------------------\n ! This function has been translated and adapted from the Python's\n ! module utm: https://pypi.python.org/pypi/utm\n\n subroutine utm2deg0(east, north, zn, zl, lat, lon)\n real(kind=RPRE), intent(in) :: east, north\n integer(kind=IPRE), intent(in) :: zn\n character(len=1), intent(in) :: zl\n real(kind=RPRE), intent(out) :: lat, lon\n real(kind=8), parameter :: K0 = 0.9996d0\n real(kind=8), parameter :: E = 0.00669438d0\n real(kind=8), parameter :: R = 6378137\n real(kind=8) :: m, mu, n, s, c, c2, d, x, y\n real(kind=8) :: E_P2, M1, F, P2, P3, P4, P5\n real(kind=8) :: p_rad, p_sin, p_sin2, p_cos, p_tan, p_tan2, p_tan4, &\n ep_sin, ep_sin_sqrt\n\n x = east - 500000\n y = north\n if (verify(zl, \"OXWVUTSRQPN\") .ne. 0) y = y - 10000000\n\n E_P2 = E/(1.0d0 - E)\n M1 = (1 - E/4 - 3*E**2/64 - 5*E**3/256)\n F = (1 - sqrt(1 - E))/(1 + sqrt(1 - E))\n P2 = (3.0d0/2*F - 27.0d0/32*F**3 + 269.0d0/512*F**5)\n P3 = (21.0d0/16*F**2 - 55.0d0/32*F**4)\n P4 = (151.0d0/96*F**3 - 417.0d0/128*F**5)\n P5 = (1097.0d0/512*F**4)\n\n m = y/K0\n mu = m/(R*M1)\n\n p_rad = (mu + P2*sin(2*mu) &\n + P3*sin(4*mu) &\n + P4*sin(6*mu) &\n + P5*sin(8*mu))\n\n p_sin = sin(p_rad)\n p_sin2 = p_sin**2\n\n p_cos = cos(p_rad)\n\n p_tan = p_sin/p_cos\n p_tan2 = p_tan**2\n p_tan4 = p_tan2**2\n\n ep_sin = 1 - E*p_sin2\n ep_sin_sqrt = sqrt(1 - E*p_sin2)\n\n n = R/ep_sin_sqrt\n s = (1 - E)/ep_sin\n c = F*p_cos**2\n c2 = c**2\n\n d = x/(n*K0)\n lat = (p_rad - (p_tan/s) &\n *(d**2/2 &\n - d**4/24*(5 + 3*p_tan2 + 10*c - 4*c2 - 9*E_P2)) &\n + d**6/720*(61 + 90*p_tan2 + 298*c + 45*p_tan4 - 252*E_P2 - 3*c2))\n lon = (d &\n - d**3/6*(1 + 2*p_tan2 + c) &\n + d**5/120*(5 - 2*c + 28*p_tan2 - 3*c2 + 8*E_P2 + 24*p_tan4))/p_cos\n\n lat = lat*180.0d0/pi\n lon = lon*180.0d0/pi + (zn - 1)*6 - 180 + 3\n return\n end subroutine utm2deg0\n\n subroutine utm2deg1(east, north, zn, zl, lat, lon)\n real(kind=RPRE), dimension(:), intent(in) :: east, north\n integer(kind=IPRE), dimension(:), intent(in) :: zn\n character(len=1), dimension(:), intent(in) :: zl\n real(kind=RPRE), dimension(:), allocatable, intent(out) :: lat, lon\n integer(kind=IPRE) :: i, n\n\n n = size(east)\n allocate (lat(n), lon(n))\n do i = 1, n\n call utm2deg(east(i), north(i), zn(i), zl(i), lat(i), lon(i))\n end do\n return\n end subroutine utm2deg1\n\n ! var\n !-----------------------------------------------------------------------\n ! var computes vector and matrix variances.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! y = var(x)\n ! y = var(x, w)\n ! x = var(A)\n ! x = var(A, w)\n ! x = var(A, 1)\n ! x = var(A, w, 1)\n ! x = var(A, 2)\n ! x = var(A, w, 2)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! y = var(x) returns the variance of the vector x.\n !\n ! y = var(x, w) returns the variance of the vector x with the\n ! normalization option w.\n ! - 0 (default) normalize by N-1,\n ! - 1 normalize by N.\n !\n ! x = var(A) returns a dim2 vector with the variances of each column of\n ! matrix A.\n !\n ! x = var(A, w) returns a dim2 vector with the normalization option w.\n !\n ! x = var(A, 1) (see x = var(A)).\n !\n ! w = var(A, w, 1) (see x = var(A, w))\n !\n ! x = var(A, 2) returns a dim1 vector with the variances of each row of\n ! matrix A.\n !\n ! x = var(A, w, 2) returns a dim1 vector with the normalization option\n ! w.\n\n real(kind=RPRE) function var1(x, w)\n real(kind=RPRE), dimension(:), intent(in) :: x\n integer(kind=IPRE), intent(in), optional :: w\n integer(kind=IPRE) :: opt_w\n\n opt_w = 0\n if (present(w)) opt_w = w\n\n select case (opt_w)\n case (0)\n var1 = sum((x - mean(x))**2)/(size(x) - 1)\n case (1)\n var1 = sum((x - mean(x))**2)/size(x)\n end select\n return\n end function var1\n\n function var2(A, w, dim)\n real(kind=RPRE), dimension(:), allocatable :: var2\n real(kind=RPRE), dimension(:, :), intent(in) :: A\n integer(kind=IPRE), intent(in), optional :: w, dim\n integer(kind=IPRE) :: opt_w, i, m, n\n\n opt_w = 0\n if (present(w)) opt_w = w\n\n m = size(A, 1)\n n = size(A, 2)\n if ((.not. present(dim)) .or. (dim .eq. 1)) then\n allocate (var2(n))\n do i = 1, n\n var2(i) = var1(A(:, i), opt_w)\n end do\n elseif (dim .eq. 2) then\n allocate (var2(m))\n do i = 1, m\n var2(i) = var1(A(i, :), opt_w)\n end do\n end if\n end function var2\n\n ! vertcat\n !-----------------------------------------------------------------------\n ! vertcat concatenates arrays vertically.\n !\n ! Syntax\n !-----------------------------------------------------------------------\n ! A = vertcat(x1, x2)\n ! A = vertcat(A1, A2)\n ! B = vertcat(x1, A2)\n ! B = vertcat(A1, x2)\n !\n ! Description\n !-----------------------------------------------------------------------\n ! A = vertcat(x1, x2) concatenates the vectors x1 and x2 treated as line\n ! vectors along the dimension 2. If the length of x1 and x2 are not\n ! equal, empty elements will be filled with zeros.\n !\n ! A = vertcat(A1, A2) concatenates the matrices A1 and A2 along the\n ! dimension 2. If the second dimension of A1 and A2 are not equal, empty\n ! elements will be filled with zeros.\n !\n ! B = vertcat(x1, A2) concatenates the vector x treated as line vector\n ! and the matrix A along the dimension 2. If the length of x and the\n ! second dimension of A are not equal, empty elements will be filled\n ! with zeros.\n !\n ! B = vertcat(A1, x2) concatenates the matrix A and the vector x treated\n ! as a line vector along the dimension 2. If the second dimension of A\n ! and the length of x are not equal, empty elements will be filled with\n ! zeros.\n !\n ! Examples\n !-----------------------------------------------------------------------\n ! A1 = reshape([ 1., 2., 3., 4. ], [ 2, 2 ], order = [ 2, 1 ])\n ! A2 = reshape([ 5., 6., 7., 8. ], [ 2, 2 ], order = [ 2, 1 ])\n ! A = vertcat(A1, A2, 2)\n ! 1. 2.\n ! 3. 4.\n ! 5. 6.\n ! 7. 8.\n\n function vertcat_r1(x1, x2)\n real(kind=RPRE), dimension(:, :), allocatable :: vertcat_r1\n real(kind=RPRE), dimension(:), intent(in) :: x1, x2\n integer(kind=IPRE) :: n1, n2\n\n n1 = size(x1)\n n2 = size(x2)\n\n vertcat_r1 = zeros(2, max(n1, n2))\n vertcat_r1(1, 1:n1) = x1\n vertcat_r1(2, 1:n2) = x2\n return\n end function vertcat_r1\n\n function vertcat_r2(A1, A2)\n real(kind=RPRE), dimension(:, :), allocatable :: vertcat_r2\n real(kind=RPRE), dimension(:, :), intent(in) :: A1, A2\n integer(kind=IPRE) :: m1, n1, m2, n2\n\n m1 = size(A1, 1)\n n1 = size(A1, 2)\n m2 = size(A2, 1)\n n2 = size(A2, 2)\n\n vertcat_r2 = zeros(m1 + m2, max(n1, n2))\n vertcat_r2(1:m1, 1:n1) = A1\n vertcat_r2(m1 + 1:, 1:n2) = A2\n return\n end function vertcat_r2\n\n function vertcat_c2(A1, A2)\n complex(kind=RPRE), dimension(:, :), allocatable :: vertcat_c2\n complex(kind=RPRE), dimension(:, :), intent(in) :: A1, A2\n integer(kind=IPRE) :: m1, n1, m2, n2\n\n m1 = size(A1, 1)\n n1 = size(A1, 2)\n m2 = size(A2, 1)\n n2 = size(A2, 2)\n\n vertcat_c2 = zeros(m1 + m2, max(n1, n2))\n vertcat_c2(1:m1, 1:n1) = A1\n vertcat_c2(m1 + 1:, 1:n2) = A2\n return\n end function vertcat_c2\n\n function vertcat_r12(x1, A2)\n real(kind=RPRE), dimension(:, :), allocatable :: vertcat_r12\n real(kind=RPRE), dimension(:), intent(in) :: x1\n real(kind=RPRE), dimension(:, :), intent(in) :: A2\n integer(kind=IPRE) :: n1, m1, n2\n\n n1 = size(x1)\n m1 = size(A2, 1)\n n2 = size(A2, 2)\n\n vertcat_r12 = zeros(m1 + 1, max(n1, n2))\n vertcat_r12(1, 1:n1) = x1\n vertcat_r12(2:, 1:n2) = A2\n return\n end function vertcat_r12\n\n function vertcat_r21(A1, x2)\n real(kind=RPRE), dimension(:, :), allocatable :: vertcat_r21\n real(kind=RPRE), dimension(:, :), intent(in) :: A1\n real(kind=RPRE), dimension(:), intent(in) :: x2\n integer(kind=IPRE) :: m1, n1, n2\n\n m1 = size(A1, 1)\n n1 = size(A1, 2)\n n2 = size(x2)\n\n vertcat_r21 = zeros(m1 + 1, max(n1, n2))\n vertcat_r21(1:m1, 1:n1) = A1\n vertcat_r21(m1 + 1, 1:n2) = x2\n return\n end function vertcat_r21\nend module forlab\n", "meta": {"hexsha": "093b5f797de0c3ef5c2ce0761ffcac88ec6db170", "size": 305642, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/forlab.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.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.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": 34.4191441441, "max_line_length": 111, "alphanum_fraction": 0.4457731594, "num_tokens": 83002, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382058759129, "lm_q2_score": 0.7905303236047048, "lm_q1q2_score": 0.6810720766889021}} {"text": "c program DRZCOMP\nc>> 2001-01-24 DRZCOMP ZSQRT -> ZSQRTX to fix C lib. problems.\nc>> 1998-01-22 DRZCOMP Krogh Added ZDIF,..., ZSUM to exernal statement.\nc>> 1996-05-28 DRZCOMP Krogh Added external statement.\nc>> 1993-02-04 CLL Added call to DZABS.\nc>> 1987-12-09 DRZCOMP Lawson Initial Code.\nc Demo driver for DZABS, ZSUM, ZDIF, ZPRO, ZQUO, and ZSQRTX.\nc C. L. Lawson, JPL, 1987 Feb 17.\nc ------------------------------------------------------------------\n external DZABS, ZDIF, ZPRO, ZQUO, ZSQRTX, ZSUM\n double precision DZABS\n double precision A(2), B(2), C(2), DMAG, U(2), U2(2), V(2), V2(2)\n double precision W(2), W2(2), TEST(2), Z(2)\nc ------------------------------------------------------------------\n A(1) = 6.0D0/7.0D0\n A(2) = -14.0D0/15.0D0\n B(1) = -29.0D0/31.0D0\n B(2) = 47.0D0/43.0D0\n U(1) = 51.0D0/53.0D0\n U(2) = 73.0D0/71.0D0\n call ZSUM(U, A, V)\n call ZPRO(V, B, W)\n call ZSQRTX(W, Z)\n call ZPRO(Z, Z, W2)\n call ZQUO(W2, B, V2)\n call ZDIF(V2, A, U2)\n call ZDIF(U2, U, TEST)\n C(1) = 3.0d0/7.0d0\n C(2) = -4.0d0/7.0d0\n DMAG = DZABS(C)\n print'(a/)',' ODZCOMP'\n print '(1x,a,f19.15,a,f19.15,a)',\n * 'A = (',A(1),',',A(2), ')',\n * 'B = (',B(1),',',B(2), ')',\n * 'U = (',U(1),',',U(2), ')',\n * 'V = U+A = (',V(1),',',V(2), ')',\n * 'W = V*B = (',W(1),',',W(2), ')',\n * 'Z=sqrt(W)= (',Z(1),',',Z(2), ')',\n * 'W2 = Z*Z = (',W2(1),',',W2(2), ')',\n * 'V2= W2/B = (',V2(1),',',V2(2), ')',\n * 'U2= V2-A = (',U2(1),',',U2(2), ')'\n print '(1x,a,g19.3,a,g19.3,a)',\n * 'TEST=U2-U= (',TEST(1),',',TEST(2), ')'\n C(1) = 3.0d0/7.0d0\n C(2) = -4.0d0/7.0d0\n DMAG = DZABS(C)\n print '(/1x,a,f19.15,a,f19.15,a)',\n * 'C = (',C(1),',',C(2), ')'\n print '(1x,a,g11.3)',\n * 'TEST2 = DZABS(C)-(5/7) = ',DMAG-(5.0d0/7.0d0)\n stop\n\n end\n", "meta": {"hexsha": "72419d2d8be58d17aaa202a9500f4f01e7c798a1", "size": 2024, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drzcomp.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drzcomp.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drzcomp.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": 37.4814814815, "max_line_length": 72, "alphanum_fraction": 0.4071146245, "num_tokens": 923, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310357, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.6810720752476176}} {"text": "! Like array_constructor_6.f90, but test for nested iterators.\n! { dg-do run }\nprogram main\n implicit none\n call build (17)\ncontains\n subroutine build (order)\n integer :: order, i, j\n\n call test (order, (/ (((j + 100) * i, j = 1, i), i = 1, order) /))\n call test (9, (/ (((j + 100) * i, j = 1, i), i = 1, 9) /))\n call test (3, (/ 101, 202, 204, 303, 306, 309 /))\n end subroutine build\n\n subroutine test (order, values)\n integer, dimension (:) :: values\n integer :: order, i, j\n\n if (size (values, dim = 1) .ne. order * (order + 1) / 2) call abort\n do i = 1, order\n do j = 1, i\n if (values (i * (i - 1) / 2 + j) .ne. (j + 100) * i) call abort\n end do\n end do\n end subroutine test\nend program main\n", "meta": {"hexsha": "65ec26c8750b7922569fbb31ce3b8194981249ef", "size": 746, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/array_constructor_7.f90", "max_stars_repo_name": "maurizioabba/rose", "max_stars_repo_head_hexsha": "7597292cf14da292bdb9a4ef573001b6c5b9b6c0", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/array_constructor_7.f90", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/array_constructor_7.f90", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 27.6296296296, "max_line_length": 71, "alphanum_fraction": 0.5509383378, "num_tokens": 272, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778258, "lm_q2_score": 0.8031738034238807, "lm_q1q2_score": 0.6810654896771406}} {"text": "PROGRAM StandingAccretionShock1D\n\n USE KindModule, ONLY: &\n DP, Pi\n USE ProgramInitializationModule, ONLY: &\n InitializeProgram, &\n FinalizeProgram\n USE InitializationModule, ONLY: &\n InitializeStandingAccretionShock\n USE TimeSteppingModule, ONLY: &\n EvolveFields, &\n SSP_RK\n USE GravitySolutionModule, ONLY: &\n SolveGravity\n\n IMPLICIT NONE\n\n ! --- Problem Parameters ---\n\n REAL(DP), PARAMETER :: AccretionRate = 4.0_DP * pi\n REAL(DP), PARAMETER :: GravitationalMass = 0.5_DP\n REAL(DP), PARAMETER :: ShockRadius = 1.0_DP\n REAL(DP), PARAMETER :: PolytropicGamma = 4.0_DP / 3.0_DP\n REAL(DP), PARAMETER :: MachNumber = 3.0d1\n\n CALL InitializeProgram &\n ( ProgramName_Option &\n = 'StandingAccretionShock1D', &\n nX_Option &\n = [ 128, 1, 1 ], &\n swX_Option &\n = [ 1, 0, 0 ], &\n bcX_Option &\n = [ 10, 0, 0 ], &\n xL_Option &\n = [ 0.2_DP, 0.0_DP, 0.0_DP ], &\n xR_Option &\n = [ 2.0_DP, Pi, 4.0_DP ], &\n zoomX_Option &\n = [ 1.0_DP, 1.0_DP, 1.0_DP ], &\n nNodes_Option &\n = 2, &\n CoordinateSystem_Option &\n = 'SPHERICAL', &\n EquationOfState_Option &\n = 'IDEAL', &\n Gamma_IDEAL_Option &\n = PolytropicGamma, &\n FluidSolver_Option &\n = 'Euler_DG', &\n FluidRiemannSolver_Option &\n = 'HLLC', &\n EvolveFluid_Option &\n = .TRUE., &\n ApplySlopeLimiter_Option &\n = .TRUE., &\n BetaTVB_Option &\n = 0.0d0, &\n BetaTVD_Option &\n = 1.8d0, &\n ApplyPositivityLimiter_Option &\n = .TRUE., &\n EvolveGravity_Option &\n = .TRUE., &\n GravitySolver_Option &\n = 'Newtonian_PointMass', &\n PointMass_Option &\n = GravitationalMass, &\n nStages_SSP_RK_Option &\n = 2 )\n\n CALL InitializeStandingAccretionShock &\n ( AccretionRate, &\n GravitationalMass, &\n ShockRadius, &\n PolytropicGamma, &\n MachNumber )\n\n CALL SolveGravity\n\n CALL EvolveFields &\n ( t_begin = 0.00_DP, &\n t_end = 5.00_DP, &\n dt_write = 0.50_DP, &\n UpdateFields = SSP_RK )\n\n CALL FinalizeProgram\n\nEND PROGRAM StandingAccretionShock1D\n", "meta": {"hexsha": "64d3d1d0fc7b500c810394079cb4920317c50987", "size": 2484, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Applications/StandingAccretionShock/StandingAccretionShock1D.f90", "max_stars_repo_name": "srichers/thornado", "max_stars_repo_head_hexsha": "bc6666cbf9ae8b39b1ba5feffac80303c2b1f9a8", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-12-08T16:16:55.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-24T19:31:21.000Z", "max_issues_repo_path": "Applications/StandingAccretionShock/StandingAccretionShock1D.f90", "max_issues_repo_name": "srichers/thornado", "max_issues_repo_head_hexsha": "bc6666cbf9ae8b39b1ba5feffac80303c2b1f9a8", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2019-07-10T20:13:15.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-11T13:21:00.000Z", "max_forks_repo_path": "Applications/StandingAccretionShock/StandingAccretionShock1D.f90", "max_forks_repo_name": "srichers/thornado", "max_forks_repo_head_hexsha": "bc6666cbf9ae8b39b1ba5feffac80303c2b1f9a8", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2018-11-14T01:13:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-24T02:08:20.000Z", "avg_line_length": 27.6, "max_line_length": 60, "alphanum_fraction": 0.5144927536, "num_tokens": 703, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588052782737, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6810502274649228}} {"text": "! mod_least65.f90\n!**********************************************************************\n! Copyright (c) 2018, Hiroaki Kadowaki (kadowaki@tmu.ac.jp)\n! All rights reserved.\n! \n! Redistribution and use in source and binary forms, with or without \n! modification, are permitted provided that the following conditions are met:\n! \n! 1. Redistributions of source code must retain the above copyright notice, \n! this list of conditions and the following disclaimer.\n! \n! 2. Redistributions in binary form must reproduce the above copyright notice, \n! this list of conditions and the following disclaimer in the documentation and/or \n! other materials provided with the distribution.\n! \n! 3. Neither the name of the copyright holder nor the names of its contributors may \n! be used to endorse or promote products derived from this software without specific \n! prior written permission.\n! \n! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND \n! ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED \n! WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. \n! IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, \n! INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT \n! NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR \n! PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, \n! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) \n! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE \n! POSSIBILITY OF SUCH DAMAGE.\n! \n! (See https://opensource.org/licenses/BSD-3-Clause )\n!\n!**********************************************************************\n! A fortran90 program of non-linear least squares\n! using LAPACK subroutines DGEQP3, DORMQR, DTRTRS, DSYEVR\n!\n! mod_least65.f90 : fortran90 source code\n! test_mod_ls65.f90 : test program\n! tsls65.dat : test input data\n! tsls65.out : test output\n!\n! compile and link:\n! $ gfortran -Wall -O -o test_mod_ls65.ex mod_least65.f90 test_mod_ls65.f90 -llapack -lblas\n! ($ ifort -mkl -O -o test_mod_ls65.ex mod_least65.f90 test_mod_ls65.f90 )\n! run\n! $ ./test_mod_ls65.ex < tsls65.dat > tsls65.out\n!**********************************************************************\n! 1035 LINES\n! non-linear least squares\n! Ver-6.5 f90 module\n! kadowaki@tmu.ac.jp\n!**********************************************************************\n! SUBROUTINES: LEAST MARQRT DFMDL DIAGNO DSYEVR DGEQP3 DORMQR DTRTRS\n! MODULE least_var\n!**********************************************************************\n! LEAST CALCULATES PA(IPFIT(J)) (J=1-NPFIT)\n! SUMS=SUMMATION(((OBS(I)-CALC(I))/WSQRT(I))**2) (I=1-NS) = minimum\n!**********************************************************************\n! HOW TO USE\n!**********************************************************************\n! NS INPUT :NUMBER OF OBSERVED DATA\n! OUTPUT:NO CHANGE\n! OBS(1-NS) INPUT :OBSERVED DATA\n! OUTPUT:NO CHANGE\n! WSQRT(1-NS) INPUT:ERROR OF OBSERVED DATA (ONE SIGMA OF NORMAL\n! DISTRIBUTION) IF YOU DO NOT KNOW ERROR OF\n!\t\t OBSERVATION, GIVE APPROXIMATE VALUES.\n! OUTPUT:NO CHANGE\n! NP INPUT :NUMBER OF PARAMETERS\n! OUTPUT:NO CHANGE\n! NPFIT INPUT :NUMBER OF FITTED PARAMETERS (NPFIT >= NP)\n! OUTPUT:NO CHANGE\n! IPFIT(1-NPFIT) INPUT :INDEX OF FITTED PARAMETERS\n! OUTPUT:NO CHANGE\n! PA(1-NP) INPUT :INITIAL VALUES OF PARAMETERS\n! OUTPUT:FITTED VALUES FOR PA(IPFIT(1-NPFIT))\n! EPSR INPUT :CONVERGENCE CRITERION VALUE\n! FOR NORMAL USE GIVE EPSR = 1.0d-5\n! IF CONVERGENCE IS TOO SLOW, GIVE 1.0d-3 > EPSR > 1.0d-5\n! OUTPUT:EPSR > 1.0d-3 --> EPSR = 1.0d-3\n! EPSR < 1.0d-5 --> EPSR = 1.0d-5\n! OTHERWISE NO CHANGE\n! MAXX INPUT :MAXIMUM ITERATION OF LEAST SQUARE LOOP (MAXX >= 1)\n! OUTPUT:NO CHANGE\n! IDRSW INPUT :SWITCH OF DERIVATIVE\n! =0 --> ANALYTIC DERIVATIVE USING DFMODL\n! =1 --> NUMERICAL DERIVATIVE USING FMODL\n! OUTPUT:NO CHANGE\n! NPR INPUT :'UNIT' NUMBER FOR PRINT OUT (WRITE(NPR,*))\n! OUTPUT:NO CHANGE\n! IPRSW INPUT :SWITCH OF PRINT OUTPUT\n! =0 --> PRINT OUT STANDARD STATEMENTS\n! =1 --> PRINT OUT ALL STATEMENTS\n! =2 --> PRINT OUT ONLY ERROR MESSAGES\n! =3 --> PRINT OUT NOTHING\n! OUTPUT:NO CHANGE\n! CALC(1-NS) OUTPUT:CALCULATED DATA USING FITTED PA(1-NS)\n! ERPA(1-NP) OUTPUT:ERROR OF PA(1-NS)\n! ERPA(J)=SQRT(ERMPA(J,J))\n! ERMPA(1-NP,1-NP) OUTPUT:ERROR MATRIX OF PA(1-NP)\n! ERMPA(I,J)=<(PA(I)-TRUE PA(I))*(PA(J)-TRUE PA(J))>\n! SUMS OUTPUT:SUMMATION(((OBS(I)-CALC(I))/WSQRT(I))**2) (I=1-NS)\n! USING FITTED PA(1-NS)\n! THIS IS KAISQUARE WITH DEGREE OF FREEDOM (NS-NPFIT)\n! SIGST OUTPUT:SIGST=SQRT(SUMS/(NS-NPFIT))\n! IF YOU DO NOT KNOW ERROR OF OBSERVATION (WSQRT(1-NS)),\n! USE THIS FOR NORMARIZATION OF ERROR OF\n! PA(IPFIT(1-NPFIT)). IN THIS CASE, ERROR OF PA(J) IS\n! SIGST*ERPA(J), AND ERROR MATRIX OF PA(J) IS\n! SIGST**2*ERMPA(I,J).\n! ICONL OUTPUT:CONDITION CODE\n! =0 NO ERROR\n! =10 ITERATION NUMBER > MAXX\n! =20 MARQUARDT NUMBER > UPPER LIMIT\n! USUALLY FITTING IS OK\n! =30 RANK REDUCTION OF JACOBIAN MATRIX\n! PARAMETERS ARE NOT INDEPENDENT OR MISTAKES IN\n! DERIVATIVE\n! =40 IMPOSSIBLE TO DIAGONALIZE TRANSPOSE(AP)*(AP)\n! =50 ERROR IN NUMERICAL DERIVATIVE\n! =100 ERROR IN INPUT\n!\n! WRITE FOLLOWING TWO SUBROUTINES WHICH GIVE MODEL FUNCTION (CALC(I))\n! AND ITS PARTIAL DERIVATIVE.\n! SUBROUTINE FMODL\n! INPUT: PA(1-NP)\n! OUTPUT: CALC(1-NS) MODEL FUNCTION\n! SUBROUTINE DFMODL\n! INPUT: PA(1-NP)\n! OUTPUT: AP(I,J)=PARTIAL DERIVATIVE OF CALC(I) BY PA(J)\n! =DELTA(CALC(I))/DELTA(PA(J))\n! I=1-NS, J=IPFIT(1-NPFIT)\n! IDRSW=0 --> THIS SUBROUTINE IS INDISPENSABLE\n! IDRSW=1 --> THIS SUBROUTINE IS NOT CALLED, BUT MUST EXIST FOR\n! LINKAGE. \"RETURN\" AND \"END\" IS ENOUGH.\n!\n!*********** EXAMPLE\n!MODULE least_var\n! IMPLICIT NONE\n! integer, parameter :: DP = kind(1.0D0)\n! integer(4), parameter :: set_NSMAX=200\n! real(DP) :: Q(set_NSMAX)\n!END MODULE least_var\n!-----\n!program ts_modls64\n! use mod_least, only : NPR,NS,NP,NPFIT,IPFIT,PA,IPRSW,IDRSW,OBS,WSQRT,LEAST,least_alloc,least_dealloc\n! use least_var, only : Q\n! IMPLICIT NONE\n! .....\n! NS=200\n! NP=20\n! call least_alloc\n! .....\n! CALL LEAST(EPSR,MAXX,SUMS,SIGST,ICON)\n! call least_dealloc\n! .....\n!end program ts_modls63\n!-----\n!subroutine FMODL\n! use mod_least, only : PA,CALC,NS\n! use least_var, only : Q\n! IMPLICIT NONE\n! integer(4) :: I\n! DO I=1,NS\n! CALC(I)=PA(1)+PA(2)*Q(I)+PA(3)/( (Q(I)-PA(4))**2 + PA(5)**2 )\n! end do\n!end subroutine FMODL\n!\n!-----\nMODULE mod_least\n IMPLICIT NONE\n private\n public :: LEAST,least_alloc,least_dealloc\n public :: NS,OBS,WSQRT,NP,NPFIT,IPFIT,PA,IDRSW,NPR,IPRSW,CALC,ERPA,ERMPA\n public :: AP\n!\n integer, parameter :: DP = kind(1.0D0)\n!\n integer(4), save :: NSMAX=200 ! =UPPER LIMIT OF NS\n integer(4), save :: NPMAX=20 ! =UPPER LIMIT OF NP (NPMAX.GE.4)\n integer(4), save :: NSPMAX ! =NSMAX+NPMAX\n integer(4), save :: NPMAX2 ! =2*NPMAX\n!\n real(DP), save, ALLOCATABLE :: PA(:),CALC(:),WSQRT(:),AP(:,:) &\n &,OBS(:),ERMPA(:,:),ERPA(:)\n integer(4), save :: NS,NP,NPFIT,IPRSW,IDRSW,NPR=6\n integer(4), save, ALLOCATABLE :: IPFIT(:)\n!\n integer(4), save, ALLOCATABLE :: IVW(:),IPIV(:)\n real(DP), save, ALLOCATABLE :: PAULI(:),PASCAL(:),DELX(:),VP(:)\n real(DP), save, ALLOCATABLE :: VPP(:),APP(:,:),FD(:)\n real(DP), save, ALLOCATABLE :: ERMX(:,:),ERMXX(:,:)\n!\n integer(4), save :: LWORK ! DGEQP3 + DORMQR + DTRTRS\n integer(4), save, ALLOCATABLE :: JPVT(:) ! DGEQP3 + DORMQR + DTRTRS\n real(DP), save, ALLOCATABLE :: TAU(:),WORK(:) ! DGEQP3 + DORMQR + DTRTRS\n!\ncontains\n!-----\n SUBROUTINE least_alloc\n IMPLICIT NONE\n integer(4) :: ICON ! DGEQP3 + DORMQR + DTRTRS\n NSMAX=NS\n NPMAX=max(4,NP)\n NSPMAX=NSMAX+NPMAX\n NPMAX2=2*NPMAX\n if( ALLOCATED( PA) ) DEALLOCATE( PA)\n if( ALLOCATED( CALC) ) DEALLOCATE( CALC)\n if( ALLOCATED( WSQRT) ) DEALLOCATE( WSQRT)\n if( ALLOCATED( AP) ) DEALLOCATE( AP)\n if( ALLOCATED( OBS) ) DEALLOCATE( OBS)\n if( ALLOCATED( ERMPA) ) DEALLOCATE( ERMPA)\n if( ALLOCATED( ERPA) ) DEALLOCATE( ERPA)\n if( ALLOCATED( IPFIT) ) DEALLOCATE( IPFIT)\n if( ALLOCATED( IVW) ) DEALLOCATE( IVW)\n if( ALLOCATED( IPIV) ) DEALLOCATE( IPIV)\n if( ALLOCATED( PAULI) ) DEALLOCATE( PAULI)\n if( ALLOCATED(PASCAL) ) DEALLOCATE(PASCAL)\n if( ALLOCATED( DELX) ) DEALLOCATE( DELX)\n if( ALLOCATED( VP) ) DEALLOCATE( VP)\n if( ALLOCATED( VPP) ) DEALLOCATE( VPP)\n if( ALLOCATED( APP) ) DEALLOCATE( APP)\n if( ALLOCATED( FD) ) DEALLOCATE( FD)\n if( ALLOCATED( ERMX) ) DEALLOCATE( ERMX)\n if( ALLOCATED( ERMXX) ) DEALLOCATE( ERMXX)\n if( ALLOCATED( JPVT) ) DEALLOCATE( JPVT) ! DGEQP3 + DORMQR + DTRTRS\n if( ALLOCATED( TAU) ) DEALLOCATE( TAU) ! DGEQP3 + DORMQR + DTRTRS\n if( ALLOCATED( WORK) ) DEALLOCATE( WORK) ! DGEQP3 + DORMQR + DTRTRS\n ALLOCATE( PA(NPMAX) )\n ALLOCATE( CALC(NSMAX) )\n ALLOCATE( WSQRT(NSMAX) )\n ALLOCATE( AP(NSPMAX,NPMAX) )\n ALLOCATE( OBS(NSMAX) )\n ALLOCATE( ERMPA(NPMAX,NPMAX) )\n ALLOCATE( ERPA(NPMAX) )\n ALLOCATE( IPFIT(NPMAX) )\n ALLOCATE( IVW(NPMAX) )\n ALLOCATE( IPIV(NPMAX) )\n ALLOCATE( PAULI(NPMAX) )\n ALLOCATE(PASCAL(NPMAX) )\n ALLOCATE( DELX(NPMAX) )\n ALLOCATE( VP(NSPMAX) )\n ALLOCATE( VPP(NSPMAX) )\n ALLOCATE( APP(NSPMAX,NPMAX) )\n ALLOCATE( FD(NPMAX2) )\n ALLOCATE( ERMX(NPMAX,NPMAX) )\n ALLOCATE( ERMXX(NPMAX,NPMAX) )\n ALLOCATE( JPVT(NPMAX) ) ! DGEQP3 + DORMQR + DTRTRS\n ALLOCATE( TAU(NPMAX) ) ! DGEQP3 + DORMQR + DTRTRS\n!\n ALLOCATE(WORK(1)) ! DGEQP3 + DORMQR + DTRTRS\n LWORK=-1\n JPVT(1:NPMAX) = 0\n APP(1:NSPMAX,1:NPMAX) = 0.0d0\n ICON=0\n CALL DGEQP3(NSPMAX,NPMAX,APP,NSPMAX,JPVT,TAU,WORK,LWORK,ICON)\n! WRITE(*,'(/,A,I10,G15.7)')' LWORK=-1 DGEQP3 ; ICON, WORK(1) = ',ICON,WORK(1)\n LWORK=NINT(WORK(1))\n DEALLOCATE(WORK)\n ALLOCATE(WORK(LWORK)) ! DGEQP3 + DORMQR + DTRTRS\n!\n END SUBROUTINE least_alloc\n!-----\n SUBROUTINE least_dealloc\n IMPLICIT NONE\n if( ALLOCATED( PA) ) DEALLOCATE( PA)\n if( ALLOCATED( CALC) ) DEALLOCATE( CALC)\n if( ALLOCATED( WSQRT) ) DEALLOCATE( WSQRT)\n if( ALLOCATED( AP) ) DEALLOCATE( AP)\n if( ALLOCATED( OBS) ) DEALLOCATE( OBS)\n if( ALLOCATED( ERMPA) ) DEALLOCATE( ERMPA)\n if( ALLOCATED( ERPA) ) DEALLOCATE( ERPA)\n if( ALLOCATED( IPFIT) ) DEALLOCATE( IPFIT)\n if( ALLOCATED( IVW) ) DEALLOCATE( IVW)\n if( ALLOCATED( IPIV) ) DEALLOCATE( IPIV)\n if( ALLOCATED( PAULI) ) DEALLOCATE( PAULI)\n if( ALLOCATED(PASCAL) ) DEALLOCATE(PASCAL)\n if( ALLOCATED( DELX) ) DEALLOCATE( DELX)\n if( ALLOCATED( VP) ) DEALLOCATE( VP)\n if( ALLOCATED( VPP) ) DEALLOCATE( VPP)\n if( ALLOCATED( APP) ) DEALLOCATE( APP)\n if( ALLOCATED( FD) ) DEALLOCATE( FD)\n if( ALLOCATED( ERMX) ) DEALLOCATE( ERMX)\n if( ALLOCATED( ERMXX) ) DEALLOCATE( ERMXX)\n if( ALLOCATED( JPVT) ) DEALLOCATE( JPVT) ! DGEQP3 + DORMQR + DTRTRS\n if( ALLOCATED( TAU) ) DEALLOCATE( TAU) ! DGEQP3 + DORMQR + DTRTRS\n if( ALLOCATED( WORK) ) DEALLOCATE( WORK) ! DGEQP3 + DORMQR + DTRTRS\n END SUBROUTINE least_dealloc\n!\n!----\n SUBROUTINE LEAST(EPSR,MAXX,SUMS,SIGST,ICONL)\n!\n IMPLICIT NONE\n integer, parameter :: DP = kind(1.0D0)\n real(DP), intent(inout) :: EPSR\n real(DP), intent(out) :: SUMS,SIGST\n integer(4), intent(in) :: MAXX\n integer(4), intent(out) :: ICONL\n real(DP) :: SUMSN,WSQRTI(NSMAX),yy\n integer(4) :: J,I,ICON,NDG,NPP\n!\n!-----------CHECK INPUT\n IF( NS > NSMAX .OR. NS <= 0 &\n & .OR. NP > NPMAX .OR. NP <= 0 &\n & .OR. NPFIT > NS .OR. NPFIT > NP .OR. NPFIT <= 0 &\n & .OR. EPSR < 0.0d0 .OR. MAXX <= 0 &\n & .OR. IPRSW >= 4 .OR. IPRSW <= -1 &\n & .OR. IDRSW >= 2 .OR. IDRSW <= -1 ) THEN\n IF(IPRSW /= 3) write(NPR,'(A)')' INVALID NS, NP, NPFIT, EPSR, MAXX, IPRSW OR IDRSW'\n ICONL=100 ; RETURN\n ENDIF\n DO J=1,NPFIT\n IF(IPFIT(J) <= 0 .OR. IPFIT(J) > NP) THEN\n IF(IPRSW /= 3) write(NPR,'(A,I3,A,I3)')' INVALID IPFIT(',J,')=',IPFIT(J)\n ICONL=100 ; RETURN\n ENDIF\n IF(J < NPFIT) THEN\n DO I=J+1,NPFIT\n IF(IPFIT(J) == IPFIT(I)) THEN\n IF(IPRSW /= 3) write(NPR,'(A,I3,A,I3,A)')' INVALID IPFIT(',J,')=IPFIT(',I,')'\n ICONL=100 ; RETURN\n ENDIF\n end do\n ENDIF\n end do\n DO I=1,NS\n IF(WSQRT(I) <= 0.0d0) THEN\n IF(IPRSW /= 3) WRITE(NPR,'(A,I5)')' INVALID WSQRT(I) <= 0 I=',I\n ICONL=100 ; RETURN\n ENDIF\n end do\n!----------- INPUT OK\n IF(IPRSW == 1) write(NPR,'(A)')' --------SUBROUTINE LEAST START---------'\n ICONL=0\n IF(EPSR > 1.0d-3) THEN\n EPSR=1.0d-3\n IF(IPRSW == 1 .OR. IPRSW == 0) write(NPR,'(A)')' EPSR IS CHANGED TO 1.0d-3'\n ENDIF\n IF(EPSR < 1.0d-5) THEN\n EPSR=1.0d-5\n IF(IPRSW == 1 .OR. IPRSW == 0) write(NPR,'(A)')' EPSR IS CHANGED TO 1.0d-5'\n ENDIF\n ERMPA(:,:)=0.0d0\n ERPA(:)=0.0d0\n WSQRTI(1:NS)=1.0d0/WSQRT(1:NS)\n IF(IPRSW == 1) write(NPR,'(A,G15.7)')' CONVERGENCE CRITERION VALUE EPSR=',EPSR\n!-------- LEAST SQUARE PROGRAM ---- MARQUARDT METHOD\n CALL MARQRT(EPSR,MAXX,SUMS,WSQRTI,ICON)\n!\n IF(ICON /= 0 .AND. IPRSW /= 3) write(NPR,'(A,I5)')' AT MARQRT ICON=',ICON\n ICONL=ICON\n IF(ICON == 50) RETURN\n IF(ICON /= 30) THEN\n!-- CALCULATE ERROR MATRIX = ERMX\n APP(1:NS,1:NPFIT)=AP(1:NS,1:NPFIT) ! copy\n call set_ERMX_RAMC('ERMX',ICONL,yy)\n ENDIF\n!-------- DIAGNOSYS OF MATRIX AP\n if(IPRSW==0 .OR. IPRSW==1) then\n CALL DIAGNO(SUMS,WSQRTI,ICONL,ICON)\n IF(ICON /= 0) THEN\n IF(IPRSW /= 3) WRITE(NPR,'(A,I5)')' AT DIAGNO ICON=',ICON\n ICONL=40\n ENDIF\n endif\n!---------\n IF(ICONL == 30) RETURN\n DO J=1,NPFIT\n DO I=1,NPFIT\n ERMPA(IPFIT(I),IPFIT(J))=ERMX(I,J)*PASCAL(I) *PASCAL(J)\n end do\n end do\n DO I=1,NPFIT\n ERPA(IPFIT(I))=SQRT(ERMPA(IPFIT(I),IPFIT(I)))\n end do\n!----------\n!----CHI SQUARE\n NDG=NS-NPFIT\n IF(NS > NPFIT) THEN\n SUMSN=SUMS/NDG\n!-- IF ABSOLUTE ERROR IS NOT KNOWN THE FOLLOWING ERROR SHOULD BE USED\n SIGST=SQRT(SUMSN)\n ELSE\n SUMSN=0.0d0\n SIGST=0.0d0\n ENDIF\n!---------PRINT OUT RESULTS\n IF(IPRSW == 0 .OR. IPRSW == 1) THEN\n write(NPR,'(/,A,G15.7)') ' CHI SQUARE SUMS=',SUMS\n write(NPR,'(A,I5)' ) ' DEGREE OF FREEDOM NS-NPFIT=',NDG\n write(NPR,'(A,G15.7)') ' SUMS/(NS-NPFIT)=',SUMSN\n write(NPR,'(/,A)')' I PA FINAL ERROR ERROR*SQRT(SUMS/(NP-NPFIT))'\n do I=1,NP\n write(NPR,'(2X,I3,3G15.7)') I,PA(I),ERPA(I),SIGST*ERPA(I)\n end do\n ENDIF\n!\n IF(IPRSW == 1) THEN\n NPP= MIN(10,NPFIT)\n write(NPR,'(A)')' ERROR MATRIX OF PA'\n write(NPR,'(5X,10(I5,6X))')(IPFIT(J),J=1,NPP)\n DO I=1,NPFIT\n WRITE(NPR,'(I5,10G11.3)') IPFIT(I),(ERMPA(IPFIT(I),IPFIT(J)),J=1,NPP)\n end do\n IF(NPFIT > 10) THEN\n NPP= MIN(20,NPFIT)\n write(NPR,'(A)')' ERROR MATRIX next PART'\n write(NPR,'(5X,10(I5,6X))')(IPFIT(J),J=11,NPP)\n DO I=1,NPFIT\n WRITE(NPR,'(I5,10G11.3)') IPFIT(I),(ERMPA(IPFIT(I),IPFIT(J)),J=11,NPP)\n end do\n ENDIF\n ENDIF\n!\n IF(IPRSW == 1) THEN\n write(NPR,'(/,4X,A,9X,A,10X,A)')'I OBS ','CALC ','OBS-CALC'\n do I=1,NS\n write(NPR,'(I5,3G15.7)') I,OBS(I),CALC(I),OBS(I)-CALC(I)\n end do\n ENDIF\n!\n IF(IPRSW == 1) write(NPR,'(A)')' ----------LEAST END-----------'\n!\n END SUBROUTINE LEAST\n!\n!-----\n SUBROUTINE MARQRT(EPSR,MAXX,SUMS,WSQRTI,ICONM)\n!\n IMPLICIT NONE\n integer, parameter :: DP = kind(1.0D0)\n real(DP), intent(in) :: EPSR,WSQRTI(*)\n real(DP), intent(out) :: SUMS\n integer(4), intent(in) :: MAXX\n integer(4), intent(out) :: ICONM\n real(DP) :: RAM,XX,RMAX,RAMC,RAMUL,EDELS,SUMSN,RSUMS\n integer(4) :: ITN,ITNS,J,I,IER,K,ISW,N,ICON\n integer(4) :: NRHS ! DGEQP3 + DORMQR + DTRTRS\n!\n ICONM=0\n ITN=0\n ITNS=0\n RAM=0.0d0\n RAMUL=0.0d0\n IF(IDRSW == 1) THEN\n! SET INITIAL DELPA(J)=ERMX(J,1) AND PAP(J)=ERMX(J,2) FOR DFMDL\n DO J=1,NPFIT\n IF( ABS(PA(IPFIT(J))) > 1.0d-30) THEN\n ERMX(J,1)=0.0004d0*ABS(PA(IPFIT(J)))\n ELSE\n ERMX(J,1)=0.0004d0\n ENDIF\n ERMX(J,2)=PA(IPFIT(J))+4.0d0*ERMX(J,1)\n end do\n ENDIF\n IF(IPRSW == 1) write(NPR,'(A)')' ---------SOBROUTINE MARQRT START---------'\n!-----CALCULATE SUMS VP AP -------\n CALL FMODL\n!\n VP(1:NS) = WSQRTI(1:NS)*(OBS(1:NS)-CALC(1:NS))\n SUMS = DOT_PRODUCT(VP(1:NS),VP(1:NS))\n!-----------------\n CALL DFMDL(WSQRTI,IER)\n IF(IER == 1) THEN\n ICONM=50\n RETURN\n ENDIF\n!\n!----- SET PASCAL, PAULI, AND AP\n DO J=1,NPFIT\n XX=DOT_PRODUCT(AP(1:NS,J),AP(1:NS,J))\n PASCAL(J)=SIGN(10.0d0/SQRT(XX) , PA(IPFIT(J)) )\n PAULI(J)=PA(IPFIT(J))-PASCAL(J)\n AP(1:NS,J)=PASCAL(J)*AP(1:NS,J)\n end do\n!-----START ITERATION OF MARQUARDT METHOD\n IF(IPRSW == 0 .OR. IPRSW== 1) then\n WRITE(NPR,'(/,A)')' ITN SUMSN MAX(ABS(DELX)) MARQUARDT NUMBER'\n endif\n!-----ITN=NUMBER OF ITERATION\n 40 ITN=ITN+1\n!-----SOLVE VP=AP*DELX LINEAR LEAST SQUARE SOLUTION\n!-----SET VP AND AP\n VP(NS+1:NS+NPFIT)=0.0d0\n AP(NS+1:NS+NPFIT,1:NPFIT)=0.0d0\n XX=SQRT(RAM)\n DO J=1,NPFIT\n AP(NS+J,J)=XX\n end do\n APP(1:NS+NPFIT,1:NPFIT)=AP(1:NS+NPFIT,1:NPFIT) ! copy\n VPP(1:NS+NPFIT)=VP(1:NS+NPFIT) ! copy\n!\n! Solve the least squares problem min( norm2(VPP - APP X) ) for X\n K=NSPMAX\n ISW=1\n N=NS+NPFIT\n!\n!------LLS HOUSEHOLDER QR factorization\n JPVT(1:NPFIT) = 0 ! DGEQP3 + DORMQR + DTRTRS\n CALL DGEQP3(N,NPFIT,APP,K,JPVT,TAU,WORK,LWORK,ICON) ! DGEQP3 + DORMQR + DTRTRS\n!!!!! CALL LAXL(APP,K,N,NPFIT,VPP,ISW,FD,IVW,ICON) ! LAXL = ULALH + ULALB\n!-----\n IF(ICON /= 0) THEN\n IF(IPRSW /= 3) then\n write(NPR,'(A,I7)')' error AT DGEQP3 (or LAXL) ICON=',ICON\n endif\n ICONM=30 ; RETURN\n ENDIF\n!\n NRHS=1 ! DGEQP3 + DORMQR + DTRTRS\n CALL DORMQR('L','T',N,NRHS,NPFIT,APP,K,TAU,VPP,K,WORK,LWORK,ICON) ! DGEQP3 + DORMQR + DTRTRS\n CALL DTRTRS('U','N','N',NPFIT,NRHS,APP,K,VPP,K,ICON) ! DGEQP3 + DORMQR + DTRTRS\n FD(JPVT(1:NPFIT)) = VPP(1:NPFIT) ! DGEQP3 + DORMQR + DTRTRS\n VPP(1:NPFIT) = FD(1:NPFIT) ! DGEQP3 + DORMQR + DTRTRS\n!\n!------CONVERGENCE CRITERION VALUE RMAX=MAX(ABS(DELX(I=1-NPFIT)))--\n DELX(1:NPFIT)=VPP(1:NPFIT)\n RMAX=MAXVAL(ABS(DELX(1:NPFIT)))\n!\n IF ( ( MOD(ITNS,5) == 0 .AND. ITNS /= 0) .OR. (RMAX > 0.1d0) .OR. (ITN == 1) ) THEN\n!-- CALCULATE STANDARD MARQUARDT NUMBER = RAMC\n APP(1:NS,1:NPFIT)=AP(1:NS,1:NPFIT) ! copy\n call set_ERMX_RAMC('RAMC',IER,RAMC) ! calc RAMC using APP\n RAMUL=RAMC*1.0d8 ! upper limit of RAM\n ENDIF\n!------PARAMETER INDICATING NONLINEALITY RSUMS ---\n!------CONVERGENCE CRITERION VALUE RMAX=MAX(ABS(DELX(I)))--\n!------ RSUMS=(SUMSN-SUMS)/EDELS\n!------ EDELS=EXPECTED DECREASE OF SUMS\n!------ EDELS=-2*RAM*NORM(DELX)**2-NORM(AP*DELX)**2\n PA(IPFIT(1:NPFIT))=PAULI(1:NPFIT)+(1.0d0+DELX(1:NPFIT))*PASCAL(1:NPFIT)\n EDELS = -2.0d0 * RAM * DOT_PRODUCT( DELX(1:NPFIT) , DELX(1:NPFIT) )\n!----------\n CALL FMODL\n!----------\n DO I=1,NS\n XX= DOT_PRODUCT( AP(I,1:NPFIT) , DELX(1:NPFIT) )\n EDELS=EDELS-XX*XX\n end do\n VPP(1:NS)= ( OBS(1:NS) - CALC(1:NS) ) * WSQRTI(1:NS)\n SUMSN = DOT_PRODUCT( VPP(1:NS) , VPP(1:NS) )\n IF(EDELS < 0.0d0) THEN\n RSUMS=(SUMSN-SUMS)/EDELS\n ELSE\n RSUMS=0.0d0\n ENDIF\n!------\n IF(SUMSN < SUMS) THEN\n ITNS=ITNS+1\n IF(IPRSW == 0 .OR. IPRSW == 1) write(NPR,'(I5,G20.12,2G15.7)')ITN,SUMSN,RMAX,RAM\n ENDIF\n!------CHECK NEW SUMS (.LE. OR .GT.) OLD SUMS\n IF(SUMS <= SUMSN) THEN\n!-------PA NOT IMPROVED. SET OLD VALUES\n PA(IPFIT(1:NPFIT))=PAULI(1:NPFIT)+PASCAL(1:NPFIT)\n ELSE\n!-------SET SUMS VP AP PAULI PASCAL USING IMPROVED PA\n SUMS=SUMSN\n VP(1:NS)=VPP(1:NS)\n!---\n CALL DFMDL(WSQRTI,IER)\n IF(IER == 1) THEN\n ICONM=50 ; RETURN\n ENDIF\n!---\n DO J=1,NPFIT\n XX=DOT_PRODUCT(AP(1:NS,J),AP(1:NS,J))\n PASCAL(J)=SIGN(10.0d0/SQRT(XX) , PA(IPFIT(J)) )\n PAULI(J)=PA(IPFIT(J))-PASCAL(J)\n AP(1:NS,J)=PASCAL(J)*AP(1:NS,J)\n end do\n ENDIF\n!----- CHECK CONVERGENCE\n IF(RMAX <= EPSR) THEN\n!----- CONVERGENCE EXIT\n GOTO 250\n ELSE\n!----- NO CONVERGENCE\n!----- CHECK ITN= MAXX) THEN\n ICONM=10 ; GOTO 250\n ELSEIF(RAM > RAMUL) THEN\n ICONM=20 ; GOTO 250\n ENDIF\n!C----- CONTINUE ITERATION ADJUST RAM\n IF(RSUMS >= 0.75d0) THEN\n RAM=0.5d0*RAM\n IF(RAM < RAMC) RAM=0.0d0\n ELSEIF(RSUMS <= 0.25d0 .AND. RSUMS >= 0.0d0) THEN\n RAM=2.0d0*RAM\n IF(RAM < RAMC) RAM=RAMC\n ELSEIF(RSUMS < 0.0d0) THEN\n RAM=MIN(2.0d0-RSUMS,10.0d0)*RAM\n IF(RAM < RAMC) RAM=RAMC\n ENDIF\n GOTO 40\n ENDIF\n!----- RETURN\n 250 continue\n CALC(1:NS)=-VP(1:NS)/WSQRTI(1:NS)+OBS(1:NS)\n!\n IF((ITNS == 0) .AND. (IPRSW /= 3)) write(NPR,'(A)')' I CANNOT IMPROVE PARAMETERS SOMETHING WRONG?'\n IF((IPRSW == 0) .OR. (IPRSW == 1)) write(NPR,'(A,I5)')' ITERATION NUMBER ITN=',ITN\n IF(IPRSW == 1) THEN \n write(NPR,'(A,G15.7)')' STANDARD MARQUARDT NUMBER RAMC=',RAMC\n write(NPR,'(A,G15.7)')' LAST MARQUARDT NUMBER RAM=',RAM\n write(NPR,'(A)')' ----- MARQRT END -----'\n ENDIF\n!\n END SUBROUTINE MARQRT\n!\n!-----\n SUBROUTINE DFMDL(WSQRTI,IER)\n!\n IMPLICIT NONE\n integer, parameter :: DP = kind(1.0D0)\n real(DP), intent(in) :: WSQRTI(*)\n integer(4), intent(out) :: IER\n integer(4) :: J,I,IPFJ,ISW,ISWB,K\n integer(4), parameter :: KMAX=20\n real(DP), parameter :: EPSRP=1.0d-7,EPSRC=1.0d-6,FACD=0.25d0,FACI=4.0d0\n real(DP) :: PRC(2),XX,XXX,XXXX,XXXXX,FACT,CONV,YY\n!\n!! DATA EPSRP,EPSRC,FACD,FACI,KMAX /1.E-7,1.E-6, .25, 4.,20 /\n! IDRSW=0-ANALYTIC DEREVATIVE =1-NUMERICAL DERIVATIVE\n! APP(I,ISW)=DELTA(CALC(I)*WSQRTI(I))/DELTA(PA(IPFIT(J)))\n! DELTA( )=( )(PA(IPFJ)+DELPA(J))-( )(PA(IPFJ)-DELPA(J))\n! APP(I,ISWB)=PREVIOUS APP(I,ISW) BEFORE DELPA(J)=FACT*DELPA(J)\n! ISW,ISWB=1,2 OR 2,1\n! FACT=FACD OR FACI\n! PRC(ISW)=MEASURE OF ROUNDOFF ERROR OF APP(I,ISW)\n! CONV=MEASURE OF CONVERGENCE\n! =SQRT(SUM((APP(I,1)-APP(I,2))**2)/SUM(APP(I,ISW)**2))\n! PAP(J)=PREVIOUS PA(IPFFIT(J))\n! IER= ERROR CODE =0-NO ERROR =1-ERROR\n IER=0\n IF(IDRSW == 0) THEN\n CALL DFMODL\n APP(1:NS,1:NPFIT)=AP(1:NS,IPFIT(1:NPFIT))\n DO J=1,NPFIT\n AP(1:NS,J)=WSQRTI(1:NS)*APP(1:NS,J)\n end do\n RETURN\n ELSEIF(IDRSW == 1) THEN\n DO J=1,NPFIT\n IPFJ=IPFIT(J)\n XX=PA(IPFJ)\n ISW=1\n PA(IPFJ)=XX+ERMX(J,1) ! PA(IPFJ)=XX+DELPA(J)\n CALL FMODL\n APP(1:NS,3)=CALC(1:NS)*WSQRTI(1:NS)\n PA(IPFJ)=XX-ERMX(J,1) ! PA(IPFJ)=XX-DELPA(J)\n CALL FMODL\n XXX=0.5d0/ERMX(J,1) ! XXX=.5/DELPA(J)\n PRC(ISW)=0.0d0\n DO I=1,NS\n APP(I,4)=CALC(I)*WSQRTI(I)\n XXXX=APP(I,3)-APP(I,4)\n APP(I,ISW)=XXXX*XXX\n XXXXX=( ABS(APP(I,3)) + ABS(APP(I,4)) )*0.5d0\n IF(XXXXX > 1.0d-60) THEN\n PRC(ISW)=MAX(PRC(ISW),ABS(XXXX/XXXXX))\n ENDIF\n end do\n IF(ABS(XX-ERMX(J,2)) <= ERMX(J,1) )THEN ! IF(ABS(XX-PAP(J)).LE.DELPA(J))THEN\n AP(1:NS,J)=APP(1:NS,ISW)\n GOTO 180\n ENDIF\n ISW=2\n ISWB=1\n FACT=FACD\n DO K=1,KMAX\n ERMX(J,1)=FACT*ERMX(J,1) ! DELPA(J)=FACT*DELPA(J)\n PA(IPFJ)=XX+ERMX(J,1) ! PA(IPFJ)=XX+DELPA(J)\n CALL FMODL\n APP(1:NS,3)=CALC(1:NS)*WSQRTI(1:NS)\n PA(IPFJ)=XX-ERMX(J,1) ! PA(IPFJ)=XX-DELPA(J)\n CALL FMODL\n XXX=0.5d0/ERMX(J,1) ! XXX=.5/DELPA(J)\n PRC(ISW)=0.0d0\n CONV=0.0d0\n YY=0.0d0\n DO I=1,NS\n APP(I,4)=CALC(I)*WSQRTI(I)\n XXXX=APP(I,3)-APP(I,4)\n APP(I,ISW)=XXXX*XXX\n XXXXX=( ABS(APP(I,3)) + ABS(APP(I,4)) )*0.5d0\n IF(XXXXX > 1.0d-60) THEN\n PRC(ISW)=MAX(PRC(ISW),ABS(XXXX/XXXXX))\n ENDIF\n CONV=CONV+(APP(I,1)-APP(I,2))**2\n YY=YY+APP(I,ISW)**2\n end do\n IF(YY < 1.0d-60) GOTO 400\n CONV=SQRT(CONV/YY)\n IF(K == 1) THEN\n IF(PRC(1) < EPSRP .AND. PRC(2) < EPSRP) GOTO 200\n ENDIF\n IF(CONV <= EPSRC .AND. PRC(ISWB) >= EPSRP) THEN\n! CONVERGENCE NEXT J\n IF(PRC(ISW) >= EPSRP) THEN\n AP(1:NS,J)=APP(1:NS,ISW)\n ELSE\n AP(1:NS,J)=APP(1:NS,ISWB)\n ENDIF\n ERMX(J,1)=ERMX(J,1)/FACT ! DELPA(J)=DELPA(J)/FACT\n GOTO 180\n ELSEIF(PRC(1) >= EPSRP .AND. PRC(2) >= EPSRP) THEN\n! SMALLER DELPA(J) NEXT K\n IF(ISW == 1) THEN\n ISW=2\n ISWB=1\n ELSE\n ISW=1\n ISWB=2\n ENDIF\n ELSE\n! ERROR RETURN\n IF(IPRSW /= 3) THEN\n WRITE(NPR,'(A)') ' no convergence of derivative IN DFMDL'\n WRITE(NPR,'(A)') ' decreasing DELPA(J) = delta PA(IPFIT(J))'\n ENDIF\n GOTO 300\n ENDIF\n end do\n! ERROR K=KMAX RETURN\n IF(IPRSW /= 3) THEN\n WRITE(NPR,'(A)') ' no convergence of derivative IN DFMDL'\n WRITE(NPR,'(A)') ' decreasing DELPA(J) = delta PA(IPFIT(J))'\n WRITE(NPR,'(A,I5)') ' K > KMAX=',KMAX\n ENDIF\n GOTO 300\n!\n 200 continue\n ERMX(J,1)=ERMX(J,1)/FACT ! DELPA(J)=DELPA(J)/FACT\n FACT=FACI\n DO K=1,KMAX\n ERMX(J,1)=FACT*ERMX(J,1) ! DELPA(J)=FACT*DELPA(J)\n PA(IPFJ)=XX+ERMX(J,1) ! PA(IPFJ)=XX+DELPA(J)\n CALL FMODL\n APP(1:NS,3)=CALC(1:NS)*WSQRTI(1:NS)\n PA(IPFJ)=XX-ERMX(J,1) ! PA(IPFJ)=XX-DELPA(J)\n CALL FMODL\n XXX=0.5d0/ERMX(J,1) ! XXX=.5/DELPA(J)\n PRC(ISW)=0.0d0\n CONV=0.0d0\n YY=0.0d0\n DO I=1,NS\n APP(I,4)=CALC(I)*WSQRTI(I)\n XXXX=APP(I,3)-APP(I,4)\n APP(I,ISW)=XXXX*XXX\n XXXXX=( ABS(APP(I,3)) + ABS(APP(I,4)) )*0.5d0\n IF(XXXXX > 1.0d-60) THEN\n PRC(ISW)=MAX(PRC(ISW),ABS(XXXX/XXXXX))\n ENDIF\n CONV=CONV+(APP(I,1)-APP(I,2))**2\n YY=YY+APP(I,ISW)**2\n end do\n IF(YY < 1.0d-60) GOTO 400\n CONV=SQRT(CONV/YY)\n IF(CONV <= EPSRC .AND. PRC(ISW) >= EPSRP) THEN\n! CONVERGENCE NEXT J\n IF(PRC(ISWB) >= EPSRP) THEN\n AP(1:NS,J)=APP(1:NS,ISWB)\n ELSE\n AP(1:NS,J)=APP(1:NS,ISW)\n ENDIF\n GOTO 180\n ELSEIF(PRC(1) < EPSRP .AND. PRC(2) < EPSRP) THEN\n! LARGER DELPA(J) NEXT K\n IF(ISW == 1) THEN\n ISW=2\n ISWB=1\n ELSE\n ISW=1\n ISWB=2\n ENDIF\n ELSE\n! ERROR RETURN\n IF(IPRSW /= 3) THEN\n WRITE(NPR,'(A)') ' no convergence of derivative IN DFMDL'\n WRITE(NPR,'(A)') ' increasing DELPA(J) = delta PA(IPFIT(J))'\n ENDIF\n GOTO 300\n ENDIF\n end do\n! ERROR K=KMAX RETURN\n IF(IPRSW /= 3) THEN\n WRITE(NPR,'(A)') ' no convergence of derivative IN DFMDL'\n WRITE(NPR,'(A)') ' decreasing DELPA(J) = delta PA(IPFIT(J))'\n WRITE(NPR,'(A,I5)') ' K > KMAX=',KMAX\n ENDIF\n GOTO 300\n!\n 180 continue\n PA(IPFJ)=XX\n ERMX(J,2)=XX ! PAP(J)=XX\n end do\n RETURN\n ENDIF\n RETURN\n!\n 300 continue\n IER=1\n PA(IPFJ)=XX\n IF(IPRSW /= 3) THEN\n WRITE(NPR,'(A)')' ERROR IN DFMDL'\n WRITE(NPR,'(A)')' K,J,IPFIT(J),PA(IPFIT(J)),DELPA(J)'\n WRITE(NPR,'(3I5,2G15.7)')K,J,IPFJ,XX,ERMX(J,1) ! ' /3I5,2G15.7)')K,J,IPFJ,XX,DELPA(J)\n WRITE(NPR,'(A)')' ISW,FACT,CONV,PRC(ISW),PRC(ISWB)'\n WRITE(NPR,'(I5,F7.3,3G15.7)')ISW,FACT,CONV,PRC(ISW),PRC(ISWB)\n ENDIF\n RETURN\n!\n 400 continue\n IER=1\n PA(IPFJ)=XX\n IF(IPRSW /= 3) THEN\n WRITE(NPR,'(A)')' ERROR IN DFMDL'\n WRITE(NPR,'(A,I3,A)')' ZERO DERIVATIVE - PA(',IPFJ,')'\n ENDIF\n RETURN\n END SUBROUTINE DFMDL\n!\n!-----\n SUBROUTINE DIAGNO(SUMS,WSQRTI,ICONL,ICOND)\n!\n IMPLICIT NONE\n integer, parameter :: DP = kind(1.0D0)\n real(DP), intent(in) :: SUMS\n real(DP), intent(in) :: WSQRTI(*)\n integer(4), intent(in) :: ICONL\n integer(4), intent(out) :: ICOND\n real(DP) :: CONDAP,S,SS,XX,SSUM ! DSYEVR\n!!!!! real(DP) :: AMACH,CONDAP,S,SS,XX,SSUM ! HSHOUS\n integer(4) :: I,J,K,ICON\n real(DP) :: AMYU(NPFIT),VORTH(NPFIT,NPFIT) ! DSYEVR\n!!!!! real(DP) :: AMYU(NPMAX),VORTH(NPMAX,NPMAX) ! HSHOUS\n INTEGER(4) :: il,iu,liwork,lwork,m,isuppz(2*NPFIT) ! DSYEVR\n REAL(DP) :: abstol,vl,vu ! DSYEVR\n REAL(DP), Allocatable :: work(:) ! DSYEVR\n Integer(4), Allocatable :: iwork(:) ! DSYEVR\n!!!!! real(DP) :: W1(NPMAX),W2(NPMAX),W3(NPMAX),W4(NPMAX),W5(NPMAX),W6(NPMAX) ! HSHOUS\n!!!!! real(DP) :: W7(1) ! dummy ! HSHOUS\n!!!!! AMACH=1.0d-6 ! DATA AMACH/1.E-6/ ! HSHOUS\n ICOND=0\n IF(IPRSW == 1) WRITE(NPR,'(A)')' ------SOBROUTINE DIAGNO START---------'\n!\n!-----DIAGNOSIS OF AP\n IF(IPRSW == 1) THEN\n write(NPR,'(A)')' DIAGNOSIS OF JACOBIAN MATRIX (AP) FOR THE FOLLOWING PARAMETERS'\n write(NPR,'(A)')' I=IPFIT(J) PA(I)=PAULI(J)+X(J)*PASCAL(J) X(J)=1'\n write(NPR,'(A)')' I J PA(I) PAULI(J) PASCAL(J) '\n DO I=1,NP\n K=0\n DO J=1,NPFIT\n IF(I == IPFIT(J)) THEN\n WRITE(NPR,'(1X,2I5,3G15.7)')I,J,PA(I),PAULI(J),PASCAL(J)\n K=1 ; exit\n ENDIF\n end do\n if(K==0) WRITE(NPR,'(2X,I5,5X,G15.7)')I,PA(I)\n end do\n ENDIF\n ERMXX(1:NPFIT,1:NPFIT)=MATMUL( TRANSPOSE(AP(1:NS,1:NPFIT)) , AP(1:NS,1:NPFIT) )\n!-----DIAGONALIZE ERMXX=TRANSPOSE(AP)*AP\n!----- =VORTH*DIAG(AMYU(I)**2)*TRANS(VORTH)\n IF(NPFIT == 1) THEN\n AMYU(1)=SQRT(ERMXX(1,1))\n VORTH(1,1)=1.0d0\n CONDAP=1.0d0\n ELSEIF(NPFIT >= 2) THEN\n K=NPMAX\n I=1\n! Solve the symmetric eigenvalue problem\n abstol=0.0d0 ; lwork = -1 ; liwork = -1 ! DSYEVR\n allocate(work(1),iwork(1))\n call DSYEVR('V','A','U',NPFIT,ERMXX,NPMAX,vl,vu,il,iu,abstol,m,AMYU,VORTH,NPFIT,isuppz,work,lwork,iwork,liwork,ICON)\n lwork = nint(work(1)) ; liwork = iwork(1)\n deallocate(work,iwork)\n allocate(work(lwork),iwork(liwork))\n Call DSYEVR('V','A','U',NPFIT,ERMXX,NPMAX,vl,vu,il,iu,abstol,m,AMYU,VORTH,NPFIT,isuppz,work,lwork,iwork,liwork,ICON)\n deallocate(work,iwork) ! DSYEVR\n!!!!! CALL NSHOUS(ERMXX,K,NPFIT,NPFIT,NPFIT,AMACH,I,AMYU,VORTH,ICON,W1,W2,W3,W4,W5,W6,W7) ! HSHOUS\n IF(ICON /= 0) THEN\n IF(IPRSW /= 3) write(NPR,'(A,I6)')' DSYEVR ICON=',ICON ! DSYEVR\n!!!!! IF(IPRSW /= 3) write(NPR,'(A,I6)')' NSHOUS ICON=',ICON ! HSHOUS\n ICOND=50\n GOTO 9000\n ENDIF\n AMYU(1:NPFIT)=SQRT(AMYU(1:NPFIT))\n CONDAP=AMYU(NPFIT)/AMYU(1) ! DSYEVR\n!!!!! CONDAP=AMYU(1)/AMYU(NPFIT) ! HSHOUS\n ENDIF\n!-----PRINT OUT\n IF(IPRSW==0 .OR. IPRSW==1) write(NPR,'(A,G15.7)')' CONDITION NUMBER CONDAP=',CONDAP\n IF(IPRSW == 1) THEN\n WRITE(NPR,'(A)')' K SINGULAR VALUE EIGEN VECTOR (DELTA_PA(IPFIT(J)))'\n DO K=1,NPFIT\n WRITE(NPR,'(I4,6G11.3,/,20(15X,5G11.3,/))') K,AMYU(NPFIT+1-K),(PASCAL(J)*VORTH(J,NPFIT+1-K),J=1,NPFIT) ! DSYEVR\n!!!!! WRITE(NPR,'(I4,6G11.3,/,10(15X,5G11.3,/))') K,AMYU(K),(PASCAL(J)*VORTH(J,K),J=1,NPFIT) ! HSHOUS\n end do\n ENDIF\n!----- STEEPEST DECRESING DIRECTION DELX=TRANS(AP)*VP/NORM\n SSUM=0.0D0\n DO J=1,NPFIT\n XX=DOT_PRODUCT(AP(1:NS,J),VP(1:NS))\n SSUM=SSUM+XX**2\n DELX(J)=XX\n end do\n SSUM=SQRT(SSUM)\n IF(SSUM > 0.0D0)THEN\n DELX(1:NPFIT)=DELX(1:NPFIT)/SSUM\n ENDIF\n IF(IPRSW == 1) then\n write(NPR,'(A)')' - GRADIENT SUMS (DELTA_PA(IPFIT(J)))'\n write(NPR,'(20(3X,5G11.3,/))')(PASCAL(I)*DELX(I),I=1,NPFIT)\n endif\n!\n IF(ICONL /= 0 .AND. ICONL /= 10 .AND. ICONL /= 20)GOTO 9000\n!----- SUMS(X+VORTH/AMYU)-SUMS(X)\n!----- SUMS(X-VORTH/AMYU)-SUMS(X)\n VPP(1:NS)=CALC(1:NS)\n IF(IPRSW==0 .OR. IPRSW==1) THEN\n write(NPR,'(/,A)')' CHECK VALIDITY OF ERRORS'\n write(NPR,'(A)')' IF SOME OF THE FOLLOWING VALUES ARE MUCH DIFFERENT FROM 1 (FACTOR 2),'\n write(NPR,'(A)')' THE CALCULATED ERRORS ARE NOT RELIABLE.'\n write(NPR,'(A)')' K SUMS(X+-VORTH(K)/AMYU(K))-SUMS(X) =1, IF LINEAR'\n ENDIF\n DO K=1,NPFIT\n PA(IPFIT(1:NPFIT))=PAULI(1:NPFIT)+(1.0d0+VORTH(1:NPFIT,NPFIT+1-K)/AMYU(NPFIT+1-K))*PASCAL(1:NPFIT) ! DSYEVR\n!!!!! PA(IPFIT(1:NPFIT))=PAULI(1:NPFIT)+(1.0d0+VORTH(1:NPFIT,K)/AMYU(K))*PASCAL(1:NPFIT) ! HSHOUS\n CALL FMODL\n S=0.0d0\n DO I=1,NS\n S=S+( WSQRTI(I)*(OBS(I)-CALC(I)) )**2\n end do\n S=S-SUMS\n PA(IPFIT(1:NPFIT))=PAULI(1:NPFIT)+(1.0d0-VORTH(1:NPFIT,NPFIT+1-K)/AMYU(NPFIT+1-K))*PASCAL(1:NPFIT) ! DSYEVR\n!!!!! PA(IPFIT(1:NPFIT))=PAULI(1:NPFIT)+(1.0d0-VORTH(1:NPFIT,K)/AMYU(K))*PASCAL(1:NPFIT) ! HSHOUS\n CALL FMODL\n SS=0.0d0\n DO I=1,NS\n SS=SS+( WSQRTI(I)*(OBS(I)-CALC(I)) )**2\n end do\n SS=SS-SUMS\n IF(IPRSW==0 .OR. IPRSW==1) WRITE(NPR,'(I5,2G15.7)')K,S,SS\n end do\n CALC(1:NS)=VPP(1:NS)\n PA(IPFIT(1:NPFIT))=PAULI(1:NPFIT)+PASCAL(1:NPFIT)\n!\n 9000 IF(IPRSW == 1) WRITE(NPR,'(A)')' ----------DIAGNO END----------'\n!\n END SUBROUTINE DIAGNO\n!\n!-----\n subroutine set_ERMX_RAMC(EorR,ICONL,RAMC)\n!\n IMPLICIT NONE\n integer, parameter :: DP = kind(1.0D0)\n character(4), intent(in) :: EorR ! 'ERMX' (set error matrix) or 'RAMC' (set STANDARD MARQUARDT NUMBER)\n real(DP), intent(out) :: RAMC\n integer(4), intent(out) :: ICONL\n integer(4) :: J,I,ICON,K\n real(DP) :: XX\n! EorR='ERMX' --> set error matrix = ERMX\n! ='RAMC' --> set STANDARD MARQUARDT NUMBER = RAMC\n!\n!-- Compute the QR factorization of APP\n K=NSPMAX\n ICON=0\n!\n JPVT(1:NPFIT) = 0 ! DGEQP3\n CALL DGEQP3(NS,NPFIT,APP,K,JPVT,TAU,WORK,LWORK,ICON) ! DGEQP3\n!!!!! CALL ULALH(APP,K,NS,NPFIT,FD,IVW,ICON) ! ULALH\n!\n IF(ICON /= 0) THEN\n if(EorR == 'ERMX') then\n IF(IPRSW /= 3) write(NPR,'(A,I7)')' at DGEQP3 (ULALH) in set_ERMX_RAMC ICON=',ICON\n ICONL=40\n ERMX(1:NPFIT,1:NPFIT)=0.0d0 ! set error matrix = ERMX = 0\n return\n elseif(EorR == 'RAMC')then\n IF(IPRSW /= 3) write(NPR,'(A,I7)')' AT DGEQP3 (ULALH) IN set_ERMX_RAMC ICON=',ICON\n endif\n endif\n!\n! inverting R = APP = upper triangular matrix\n! --> APP=INV(R)\n DO I=1,NPFIT\n!!!!! APP(I,I)=1.0d0/FD(I) ! ULALH diagonal elements of APP=INV(R)\n APP(I,I)=1.0d0/APP(I,I) ! DGEQP3\n end do\n IF(NPFIT >= 2) THEN\n DO I=NPFIT-1,1,-1\n DO J=NPFIT,I+1,-1\n APP(I,J)=-APP(I,I)*DOT_PRODUCT( APP(I,I+1:J) , APP(I+1:J,J) ) ! APP=INV(R) upper part\n APP(J,I)=0.0d0 ! APP=INV(R) lower part\n end do\n end do\n ENDIF\n!\n if(EorR == 'ERMX') then\n!-- CALCULATE ERROR MATRIX = ERMXX USING R\n!-- ERMXX=INV(R)*TRANSPOSE(INV(R))=APP * TRANSPOSE(APP)=ERROR MATRIX (not permuted)\n ERMXX(1:NPFIT,1:NPFIT)=MATMUL( APP(1:NPFIT,1:NPFIT), TRANSPOSE(APP(1:NPFIT,1:NPFIT)) )\n!\n!-- CALCULATE ERROR MATRIX ERMX\n!-- PERFORM PERMUTATION ERMX=INV(TRANSOSE(AP)*AP)=ERROR MATRIX OF X\n!-- SET IPIV (permuation) using PIVOTING info\n IPIV(JPVT(1:NPFIT))=(/ (i,i=1,NPFIT) /) ! DGEQP3\n!!!!! IPIV(1:NPFIT)= (/ (I, I=1,NPFIT) /) ! ULALH\n!!!!! DO I=NPFIT,1,-1\n!!!!! IF(I /= IVW(I)) THEN\n!!!!! J=IPIV(I)\n!!!!! IPIV(I)=IPIV(IVW(I))\n!!!!! IPIV(IVW(I))=J\n!!!!! ENDIF\n!!!!! end do\n ERMX(1:NPFIT,1:NPFIT)=ERMXX(IPIV(1:NPFIT),IPIV(1:NPFIT))\n!\n elseif(EorR == 'RAMC')then\n!-- CALCULATE RAMC using R RAMC = 1.0d0/trace( INV(R) TRANSPOSE(INV(R)) )\n!-- XX=trace( INV(R) TRANSPOSE(INV(R)) )\n! =trace( APP TRANSPOSE(APP) ) APP=INV(R)=UPPER TRIANGULAR MATRIX\n XX=0.0D0\n DO I=1,NPFIT\n XX=XX + DOT_PRODUCT( APP(I,I:NPFIT) , APP(I,I:NPFIT) )\n end do\n RAMC=ABS(1.0d0/XX)\n endif\n!\n end subroutine set_ERMX_RAMC\n!\nEND MODULE mod_least\n!\n", "meta": {"hexsha": "2cc88ac3793dcf166d62ba61b1be0008f068e0c8", "size": 38177, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mod_least65.f90", "max_stars_repo_name": "kadowaki-h/least65", "max_stars_repo_head_hexsha": "7f61f92f7b201dfa3339a9f62c3b0151fc93ebda", "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": "mod_least65.f90", "max_issues_repo_name": "kadowaki-h/least65", "max_issues_repo_head_hexsha": "7f61f92f7b201dfa3339a9f62c3b0151fc93ebda", "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": "mod_least65.f90", "max_forks_repo_name": "kadowaki-h/least65", "max_forks_repo_head_hexsha": "7f61f92f7b201dfa3339a9f62c3b0151fc93ebda", "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": 36.8503861004, "max_line_length": 121, "alphanum_fraction": 0.5363962595, "num_tokens": 14836, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318196, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6810502204635643}} {"text": "*DECK COSQF1\n SUBROUTINE COSQF1 (N, X, W, XH)\nC***BEGIN PROLOGUE COSQF1\nC***SUBSIDIARY\nC***PURPOSE Compute the forward cosine transform with odd wave numbers.\nC***LIBRARY SLATEC (FFTPACK)\nC***CATEGORY J1A3\nC***TYPE SINGLE PRECISION (COSQF1-S)\nC***KEYWORDS FFTPACK, FOURIER TRANSFORM\nC***AUTHOR Swarztrauber, P. N., (NCAR)\nC***DESCRIPTION\nC\nC Subroutine COSQF1 computes the fast Fourier transform of quarter\nC wave data. That is, COSQF1 computes the coefficients in a cosine\nC series representation with only odd wave numbers. The transform\nC is defined below at Output Parameter X\nC\nC***REFERENCES P. N. Swarztrauber, Vectorizing the FFTs, in Parallel\nC Computations (G. Rodrigue, ed.), Academic Press,\nC 1982, pp. 51-83.\nC***ROUTINES CALLED RFFTF\nC***REVISION HISTORY (YYMMDD)\nC 790601 DATE WRITTEN\nC 830401 Modified to use SLATEC library source file format.\nC 860115 Modified by Ron Boisvert to adhere to Fortran 77 by\nC changing dummy array size declarations (1) to (*).\nC 881128 Modified by Dick Valent to meet prologue standards.\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE COSQF1\n DIMENSION X(*), W(*), XH(*)\nC***FIRST EXECUTABLE STATEMENT COSQF1\n NS2 = (N+1)/2\n NP2 = N+2\n DO 101 K=2,NS2\n KC = NP2-K\n XH(K) = X(K)+X(KC)\n XH(KC) = X(K)-X(KC)\n 101 CONTINUE\n MODN = MOD(N,2)\n IF (MODN .EQ. 0) XH(NS2+1) = X(NS2+1)+X(NS2+1)\n DO 102 K=2,NS2\n KC = NP2-K\n X(K) = W(K-1)*XH(KC)+W(KC-1)*XH(K)\n X(KC) = W(K-1)*XH(K)-W(KC-1)*XH(KC)\n 102 CONTINUE\n IF (MODN .EQ. 0) X(NS2+1) = W(NS2)*XH(NS2+1)\n CALL RFFTF (N,X,XH)\n DO 103 I=3,N,2\n XIM1 = X(I-1)-X(I)\n X(I) = X(I-1)+X(I)\n X(I-1) = XIM1\n 103 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "30e8fd4db94513163bb72c851acfebc414cef7cc", "size": 1912, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/cosqf1.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/cosqf1.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/cosqf1.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.1428571429, "max_line_length": 72, "alphanum_fraction": 0.6182008368, "num_tokens": 709, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587934924569, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6810502184335263}} {"text": "module mod_monolis_c3d4_shape\n use mod_monolis_prm\n implicit none\n\n private\n\n real(kdouble), parameter :: gsp(3) = [ &\n 0.25d0, 0.25d0, 0.25d0 &\n ]\n\n real(kdouble), parameter :: np(3,4) = reshape([ &\n 0.0d0, 0.0d0, 0.0d0, &\n 1.0d0, 0.0d0, 0.0d0, &\n 0.0d0, 1.0d0, 0.0d0, &\n 0.0d0, 0.0d0, 1.0d0 &\n ], [3,4])\n\n public :: monolis_C3D4_num_gauss_point\n public :: monolis_C3D4_weight\n public :: monolis_C3D4_integral_point\n public :: monolis_C3D4_node_point\n public :: monolis_C3D4_shapefunc\n public :: monolis_C3D4_shapefunc_deriv\n\ncontains\n\n function monolis_C3D4_num_gauss_point()\n implicit none\n integer(kint) :: monolis_C3D4_num_gauss_point\n monolis_C3D4_num_gauss_point = 1\n end function monolis_C3D4_num_gauss_point\n\n function monolis_C3D4_weight(i)\n implicit none\n integer(kint), optional :: i\n real(kdouble) :: monolis_C3D4_weight\n monolis_C3D4_weight = 0.166666666666666d0\n end function monolis_C3D4_weight\n\n subroutine monolis_C3D4_integral_point(i, r)\n implicit none\n integer(kint) :: i\n real(kdouble) :: r(3)\n\n r(1) = gsp(1)\n r(2) = gsp(2)\n r(3) = gsp(3)\n end subroutine monolis_C3D4_integral_point\n\n subroutine monolis_C3D4_node_point(i, r)\n implicit none\n integer(kint) :: i\n real(kdouble) :: r(3)\n\n r(1) = np(1,i)\n r(2) = np(2,i)\n r(3) = np(3,i)\n end subroutine monolis_C3D4_node_point\n\n subroutine monolis_C3D4_shapefunc(local, func)\n implicit none\n real(kdouble) :: local(3), func(4)\n\n func(1) = 1.0d0 - local(1) - local(2) - local(3)\n func(2) = local(1)\n func(3) = local(2)\n func(4) = local(3)\n end subroutine monolis_C3D4_shapefunc\n\n subroutine monolis_C3D4_shapefunc_deriv(local, func)\n implicit none\n real(kdouble) :: local(3), func(4,3)\n\n func(1,1) = -1.d0\n func(2,1) = 1.d0\n func(3,1) = 0.d0\n func(4,1) = 0.d0\n\n func(1,2) = -1.d0\n func(2,2) = 0.d0\n func(3,2) = 1.d0\n func(4,2) = 0.d0\n\n func(1,3) = -1.d0\n func(2,3) = 0.d0\n func(3,3) = 0.d0\n func(4,3) = 1.d0\n end subroutine monolis_C3D4_shapefunc_deriv\n\nend module mod_monolis_c3d4_shape\n", "meta": {"hexsha": "13555ea1d6b0c6b0cb767b42620dfc7ffcc540a5", "size": 2140, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/shape/shape_C3D4.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_C3D4.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_C3D4.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": 23.5164835165, "max_line_length": 54, "alphanum_fraction": 0.6448598131, "num_tokens": 867, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318196, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.6810502157200549}} {"text": "!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 1998 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Spherepack *\n! * *\n! * A Package of Fortran Subroutines and Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams and Paul Swarztrauber *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\nsubmodule(vector_analysis_routines) vector_analysis_regular_grid_saved\n\ncontains\n\n ! Purpose:\n !\n ! subroutine vhaes(nlat, nlon, ityp, nt, v, w, idvw, jdvw, br, bi, cr, ci, &\n ! mdab, ndab, wvhaes, lvhaes, work, lwork, ierror)\n !\n ! subroutine vhaes performs the vector spherical harmonic analysis\n ! on the vector field (v, w) and stores the result in the arrays\n ! br, bi, cr, and ci. v(i, j) and w(i, j) are the colatitudinal\n ! (measured from the north pole) and east longitudinal components\n ! respectively, located at colatitude theta(i) = (i-1)*pi/(nlat-1)\n ! and longitude phi(j) = (j-1)*2*pi/nlon. the spectral\n ! representation of (v, w) is given at output parameters v, w in\n ! subroutine vhses.\n !\n ! input parameters\n !\n ! nlat the number of colatitudes on the full sphere including the\n ! poles. for example, nlat = 37 for a five degree grid.\n ! nlat determines the grid increment in colatitude as\n ! pi/(nlat-1). if nlat is odd the equator is located at\n ! grid point i=(nlat + 1)/2. if nlat is even the equator is\n ! located half way between points i=nlat/2 and i=nlat/2+1.\n ! nlat must be at least 3. note: on the half sphere, the\n ! number of grid points in the colatitudinal direction is\n ! nlat/2 if nlat is even or (nlat + 1)/2 if nlat is odd.\n !\n ! nlon the number of distinct londitude points. nlon determines\n ! the grid increment in longitude as 2*pi/nlon. for example\n ! nlon = 72 for a five degree grid. nlon must be greater\n ! than zero. the axisymmetric case corresponds to nlon=1.\n ! the efficiency of the computation is improved when nlon\n ! is a product of small prime numbers.\n !\n ! ityp = 0 no symmetries exist about the equator. the analysis\n ! is performed on the entire sphere. i.e. on the\n ! arrays v(i, j), w(i, j) for i=1, ..., nlat and\n ! j=1, ..., nlon.\n !\n ! = 1 no symmetries exist about the equator. the analysis\n ! is performed on the entire sphere. i.e. on the\n ! arrays v(i, j), w(i, j) for i=1, ..., nlat and\n ! j=1, ..., nlon. the curl of (v, w) is zero. that is,\n ! (d/dtheta (sin(theta) w) - dv/dphi)/sin(theta) = 0.\n ! the coefficients cr and ci are zero.\n !\n ! = 2 no symmetries exist about the equator. the analysis\n ! is performed on the entire sphere. i.e. on the\n ! arrays v(i, j), w(i, j) for i=1, ..., nlat and\n ! j=1, ..., nlon. the divergence of (v, w) is zero. i.e.,\n ! (d/dtheta (sin(theta) v) + dw/dphi)/sin(theta) = 0.\n ! the coefficients br and bi are zero.\n !\n ! = 3 v is symmetric and w is antisymmetric about the\n ! equator. the analysis is performed on the northern\n ! hemisphere only. i.e., if nlat is odd the analysis\n ! is performed on the arrays v(i, j), w(i, j) for\n ! i=1, ..., (nlat + 1)/2 and j=1, ..., nlon. if nlat is\n ! even the analysis is performed on the the arrays\n ! v(i, j), w(i, j) for i=1, ..., nlat/2 and j=1, ..., nlon.\n !\n ! = 4 v is symmetric and w is antisymmetric about the\n ! equator. the analysis is performed on the northern\n ! hemisphere only. i.e., if nlat is odd the analysis\n ! is performed on the arrays v(i, j), w(i, j) for\n ! i=1, ..., (nlat + 1)/2 and j=1, ..., nlon. if nlat is\n ! even the analysis is performed on the the arrays\n ! v(i, j), w(i, j) for i=1, ..., nlat/2 and j=1, ..., nlon.\n ! the curl of (v, w) is zero. that is,\n ! (d/dtheta (sin(theta) w) - dv/dphi)/sin(theta) = 0.\n ! the coefficients cr and ci are zero.\n !\n ! = 5 v is symmetric and w is antisymmetric about the\n ! equator. the analysis is performed on the northern\n ! hemisphere only. i.e., if nlat is odd the analysis\n ! is performed on the arrays v(i, j), w(i, j) for\n ! i=1, ..., (nlat + 1)/2 and j=1, ..., nlon. if nlat is\n ! even the analysis is performed on the the arrays\n ! v(i, j), w(i, j) for i=1, ..., nlat/2 and j=1, ..., nlon.\n ! the divergence of (v, w) is zero. i.e.,\n ! (d/dtheta (sin(theta) v) + dw/dphi)/sin(theta) = 0.\n ! the coefficients br and bi are zero.\n !\n ! = 6 v is antisymmetric and w is symmetric about the\n ! equator. the analysis is performed on the northern\n ! hemisphere only. i.e., if nlat is odd the analysis\n ! is performed on the arrays v(i, j), w(i, j) for\n ! i=1, ..., (nlat + 1)/2 and j=1, ..., nlon. if nlat is\n ! even the analysis is performed on the the arrays\n ! v(i, j), w(i, j) for i=1, ..., nlat/2 and j=1, ..., nlon.\n !\n ! = 7 v is antisymmetric and w is symmetric about the\n ! equator. the analysis is performed on the northern\n ! hemisphere only. i.e., if nlat is odd the analysis\n ! is performed on the arrays v(i, j), w(i, j) for\n ! i=1, ..., (nlat + 1)/2 and j=1, ..., nlon. if nlat is\n ! even the analysis is performed on the the arrays\n ! v(i, j), w(i, j) for i=1, ..., nlat/2 and j=1, ..., nlon.\n ! the curl of (v, w) is zero. that is,\n ! (d/dtheta (sin(theta) w) - dv/dphi)/sin(theta) = 0.\n ! the coefficients cr and ci are zero.\n !\n ! = 8 v is antisymmetric and w is symmetric about the\n ! equator. the analysis is performed on the northern\n ! hemisphere only. i.e., if nlat is odd the analysis\n ! is performed on the arrays v(i, j), w(i, j) for\n ! i=1, ..., (nlat + 1)/2 and j=1, ..., nlon. if nlat is\n ! even the analysis is performed on the the arrays\n ! v(i, j), w(i, j) for i=1, ..., nlat/2 and j=1, ..., nlon.\n ! the divergence of (v, w) is zero. i.e.,\n ! (d/dtheta (sin(theta) v) + dw/dphi)/sin(theta) = 0.\n ! the coefficients br and bi are zero.\n !\n !\n ! nt the number of analyses. in the program that calls vhaes,\n ! the arrays v, w, br, bi, cr, and ci can be three dimensional\n ! in which case multiple analyses will be performed.\n ! the third index is the analysis index which assumes the\n ! values k=1, ..., nt. for a single analysis set nt=1. the\n ! discription of the remaining parameters is simplified\n ! by assuming that nt=1 or that all the arrays are two\n ! dimensional.\n !\n ! v, w two or three dimensional arrays (see input parameter nt)\n ! that contain the vector function to be analyzed.\n ! v is the colatitudnal component and w is the east\n ! longitudinal component. v(i, j), w(i, j) contain the\n ! components at colatitude theta(i) = (i-1)*pi/(nlat-1)\n ! and longitude phi(j) = (j-1)*2*pi/nlon. the index ranges\n ! are defined above at the input parameter ityp.\n !\n ! idvw the first dimension of the arrays v, w as it appears in\n ! the program that calls vhaes. if ityp <= 2 then idvw\n ! must be at least nlat. if ityp > 2 and nlat is\n ! even then idvw must be at least nlat/2. if ityp > 2\n ! and nlat is odd then idvw must be at least (nlat + 1)/2.\n !\n ! jdvw the second dimension of the arrays v, w as it appears in\n ! the program that calls vhaes. jdvw must be at least nlon.\n !\n ! mdab the first dimension of the arrays br, bi, cr, and ci as it\n ! appears in the program that calls vhaes. mdab must be at\n ! least min(nlat, nlon/2) if nlon is even or at least\n ! min(nlat, (nlon + 1)/2) if nlon is odd.\n !\n ! ndab the second dimension of the arrays br, bi, cr, and ci as it\n ! appears in the program that calls vhaes. ndab must be at\n ! least nlat.\n !\n ! lvhaes an array which must be initialized by subroutine vhaesi.\n ! once initialized, wvhaes can be used repeatedly by vhaes\n ! as long as nlon and nlat remain unchanged. wvhaes must\n ! not be altered between calls of vhaes.\n !\n ! lvhaes the dimension of the array wvhaes as it appears in the\n ! program that calls vhaes. define\n !\n ! l1 = min(nlat, nlon/2) if nlon is even or\n ! l1 = min(nlat, (nlon + 1)/2) if nlon is odd\n !\n ! and\n !\n ! l2 = nlat/2 if nlat is even or\n ! l2 = (nlat + 1)/2 if nlat is odd\n !\n ! then lvhaes must be at least\n !\n ! l1*l2(2*nlat-l1+1)+nlon+15\n !\n ! output parameters\n !\n ! br, bi two or three dimensional arrays (see input parameter nt)\n ! cr, ci that contain the vector spherical harmonic coefficients\n ! in the spectral representation of v(i, j) and w(i, j) given\n ! in the discription of subroutine vhses. br(mp1, np1),\n ! bi(mp1, np1), cr(mp1, np1), and ci(mp1, np1) are computed\n ! for mp1=1, ..., mmax and np1=mp1, ..., nlat except for np1=nlat\n ! and odd mp1. mmax=min(nlat, nlon/2) if nlon is even or\n ! mmax=min(nlat, (nlon + 1)/2) if nlon is odd.\n !\n ! ierror = 0 no errors\n ! = 1 error in the specification of nlat\n ! = 2 error in the specification of nlon\n ! = 3 error in the specification of ityp\n ! = 4 error in the specification of nt\n ! = 5 error in the specification of idvw\n ! = 6 error in the specification of jdvw\n ! = 7 error in the specification of mdab\n ! = 8 error in the specification of ndab\n ! = 9 error in the specification of lvhaes\n !\n module subroutine vhaes(nlat, nlon, ityp, nt, v, w, idvw, jdvw, br, bi, cr, ci, &\n mdab, ndab, wvhaes, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n integer(ip), intent(in) :: ityp\n integer(ip), intent(in) :: nt\n real(wp), intent(in) :: v(idvw, jdvw, nt)\n real(wp), intent(in) :: w(idvw, jdvw, nt)\n integer(ip), intent(in) :: idvw\n integer(ip), intent(in) :: jdvw\n real(wp), intent(out) :: br(mdab, ndab, nt)\n real(wp), intent(out) :: bi(mdab, ndab, nt)\n real(wp), intent(out) :: cr(mdab, ndab, nt)\n real(wp), intent(out) :: ci(mdab, ndab, nt)\n integer(ip), intent(in) :: mdab\n integer(ip), intent(in) :: ndab\n real(wp), intent(in) :: wvhaes(:)\n integer(ip), intent(out) :: ierror\n\n ! Local variables\n integer(ip) :: idv, imid, idz, ist, lnl, lzimn, mmax\n integer(ip) :: required_wavetable_size\n integer(ip) :: lwork, workspace_indices(6)\n type(VectorAnalysisUtility) :: util\n\n imid = (nlat + 1)/2\n mmax = min(nlat, (nlon + 1)/2)\n idz = (mmax*(2*nlat-mmax+1))/2\n lzimn = idz*imid\n required_wavetable_size = (2 * lzimn) + nlon + 15\n\n ! Check calling arguments\n call util%check_vector_analysis_inputs(nlat, nlon, ityp, idvw, jdvw, &\n mdab, ndab, nt, required_wavetable_size, wvhaes, ierror)\n\n ! Check error flag\n if (ierror /= 0) return\n\n select case (ityp)\n case(0:2)\n idv = nlat\n ist = imid\n case default\n idv = imid\n ist = 0\n end select\n\n lnl = nt*idv*nlon\n\n ! Set required workspace size\n lwork = 2*lnl+idv*nlon\n\n block\n real(wp) :: work(lwork)\n\n ! Set workspace indices\n workspace_indices = get_vhaes_workspace_indices(ist, lnl, lzimn)\n\n associate (&\n iw1 => workspace_indices(1), &\n iw2 => workspace_indices(2), &\n iw3 => workspace_indices(3), &\n iw4 => workspace_indices(4), &\n jw1 => workspace_indices(5), &\n jw2 => workspace_indices(6) &\n )\n call vhaes_lower_utility_routine(nlat, nlon, ityp, nt, imid, idvw, jdvw, v, w, mdab, ndab, &\n br, bi, cr, ci, idv, work, work(iw1:), work(iw2:), work(iw3:), &\n work(iw4:), idz, wvhaes, wvhaes(jw1:), wvhaes(jw2:))\n end associate\n end block\n\n end subroutine vhaes\n\n ! Purpose:\n !\n ! subroutine vhaesi(nlat, nlon, wvhaes, ierror)\n !\n ! subroutine vhaesi initializes the array wvhaes which can then be\n ! used repeatedly by subroutine vhaes until nlat or nlon is changed.\n !\n ! input parameters\n !\n ! nlat the number of colatitudes on the full sphere including the\n ! poles. for example, nlat = 37 for a five degree grid.\n ! nlat determines the grid increment in colatitude as\n ! pi/(nlat-1). if nlat is odd the equator is located at\n ! grid point i=(nlat + 1)/2. if nlat is even the equator is\n ! located half way between points i=nlat/2 and i=nlat/2+1.\n ! nlat must be at least 3. note: on the half sphere, the\n ! number of grid points in the colatitudinal direction is\n ! nlat/2 if nlat is even or (nlat + 1)/2 if nlat is odd.\n !\n ! nlon the number of distinct londitude points. nlon determines\n ! the grid increment in longitude as 2*pi/nlon. for example\n ! nlon = 72 for a five degree grid. nlon must be greater\n ! than zero. the axisymmetric case corresponds to nlon=1.\n ! the efficiency of the computation is improved when nlon\n ! is a product of small prime numbers.\n !\n ! lvhaes the dimension of the array wvhaes as it appears in the\n ! program that calls vhaes. define\n !\n ! l1 = min(nlat, nlon/2) if nlon is even or\n ! l1 = min(nlat, (nlon + 1)/2) if nlon is odd\n !\n ! and\n !\n ! l2 = nlat/2 if nlat is even or\n ! l2 = (nlat + 1)/2 if nlat is odd\n !\n ! then lvhaes must be at least\n !\n ! l1*l2*(2*nlat-l1+1)+nlon+15\n !\n ! output parameters\n !\n ! wvhaes an array which is initialized for use by subroutine vhaes.\n ! once initialized, wvhaes can be used repeatedly by vhaes\n ! as long as nlat or nlon remain unchanged. wvhaes must not\n ! be altered between calls of vhaes.\n !\n !\n ! ierror = 0 no errors\n ! = 1 error in the specification of nlat\n ! = 2 error in the specification of nlon\n ! = 3 error in the specification of lvhaes\n !\n module subroutine vhaesi(nlat, nlon, wvhaes, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n real(wp), intent(out) :: wvhaes(:)\n integer(ip), intent(out) :: ierror\n\n ! Local variables\n integer(ip) :: imid, labc, lzimn, mmax\n integer(ip) :: required_wavetable_size\n integer(ip) :: workspace_indices(4)\n integer(ip) :: lwork, ldwork\n type(SpherepackUtility) :: util\n\n mmax = min(nlat, (nlon + 1)/2)\n imid = (nlat + 1)/2\n lzimn = (imid*mmax*(2*nlat-mmax+1))/2\n labc = 3*(max(mmax-2, 0)*(2*nlat-mmax-1))/2\n required_wavetable_size = 2*lzimn+nlon+15\n\n ! Check calling arguments\n if (nlat < 3) then\n ierror = 1\n else if (nlon < 1) then\n ierror = 2\n else if (size(wvhaes) < required_wavetable_size) then\n ierror = 3\n else\n ierror = 0\n end if\n\n ! Check error flag\n if (ierror /= 0) return\n\n ! Set workspace indices\n workspace_indices = get_vhaesi_workspace_indices(lzimn, nlat, imid, mmax)\n\n ! Set required workspace sizes\n lwork = 5*nlat*imid+labc\n ldwork = 2 * (nlat + 1)\n\n block\n real(wp) :: work(lwork), dwork(ldwork)\n\n associate (&\n jw1 => workspace_indices(1), &\n jw2 => workspace_indices(2), &\n iw1 => workspace_indices(3), &\n idz => workspace_indices(4) &\n )\n call vhaesi_lower_utility_routine( &\n nlat, nlon, imid, wvhaes, wvhaes(jw1:), idz, work, work(iw1:), dwork)\n\n call util%hfft%initialize(nlon, wvhaes(jw2:))\n end associate\n end block\n\n end subroutine vhaesi\n\n pure function get_vhaes_workspace_indices(ist, lnl, lzimn) &\n result (return_value)\n\n ! Dummy arguments\n integer(ip), intent(in) :: ist\n integer(ip), intent(in) :: lnl\n integer(ip), intent(in) :: lzimn\n integer(ip) :: return_value(6)\n\n associate (i => return_value)\n i(1) = ist+1\n i(2) = lnl+1\n i(3) = i(2)+ist\n i(4) = i(2)+lnl\n i(5) = lzimn+1\n i(6) = i(5)+lzimn\n end associate\n\n end function get_vhaes_workspace_indices\n\n subroutine vhaes_lower_utility_routine(nlat, nlon, ityp, nt, imid, idvw, jdvw, v, w, mdab, &\n ndab, br, bi, cr, ci, idv, ve, vo, we, wo, work, idz, zv, zw, wrfft)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n integer(ip), intent(in) :: ityp\n integer(ip), intent(in) :: nt\n integer(ip), intent(in) :: imid\n integer(ip), intent(in) :: idvw\n integer(ip), intent(in) :: jdvw\n real(wp), intent(in) :: v(idvw, jdvw, nt)\n real(wp), intent(in) :: w(idvw, jdvw, nt)\n integer(ip), intent(in) :: mdab\n integer(ip), intent(in) :: ndab\n real(wp), intent(out) :: br(mdab, ndab, nt)\n real(wp), intent(out) :: bi(mdab, ndab, nt)\n real(wp), intent(out) :: cr(mdab, ndab, nt)\n real(wp), intent(out) :: ci(mdab, ndab, nt)\n integer(ip), intent(in) :: idv\n real(wp), intent(out) :: ve(idv, nlon, nt)\n real(wp), intent(out) :: vo(idv, nlon, nt)\n real(wp), intent(out) :: we(idv, nlon, nt)\n real(wp), intent(out) :: wo(idv, nlon, nt)\n real(wp), intent(out) :: work(*)\n integer(ip), intent(in) :: idz\n real(wp), intent(in) :: zv(idz, *)\n real(wp), intent(in) :: zw(idz, *)\n real(wp), intent(in) :: wrfft(:)\n\n ! Local variables\n integer(ip) :: i, imm1, k, m, mb\n integer(ip) :: mmax, mp1, mp2, odd_stride, even_stride, np1\n type(VectorAnalysisUtility) :: util\n\n call util%analysis_setup(idvw, jdvw, mdab, ndab, &\n bi, br, ci, cr, even_stride, idv, imid, imm1, ityp, &\n mmax, nlat, nlon, nt, odd_stride, v, ve, vo, w, we, wo, wrfft)\n\n ! Compute coefficients br, bi, cr, ci\n select case (ityp)\n case (0)\n\n ! case ityp=0, no symmetries\n\n ! case m=0\n do k=1, nt\n do i=1, imid\n do np1=2, even_stride, 2\n br(1, np1, k) = br(1, np1, k)+zv(np1, i)*ve(i, 1, k)\n cr(1, np1, k) = cr(1, np1, k)-zv(np1, i)*we(i, 1, k)\n end do\n end do\n end do\n\n do k=1, nt\n do i=1, imm1\n do np1=3, odd_stride, 2\n br(1, np1, k) = br(1, np1, k)+zv(np1, i)*vo(i, 1, k)\n cr(1, np1, k) = cr(1, np1, k)-zv(np1, i)*wo(i, 1, k)\n end do\n end do\n end do\n\n ! case m = 1 through nlat-1\n if (mmax < 2) return\n\n main_loop_case_0: do mp1=2, mmax\n m = mp1-1\n mb = m*(nlat-1)-(m*(m-1))/2\n mp2 = mp1+1\n\n if (mp1 <= odd_stride) then\n do k=1, nt\n do i=1, imm1\n do np1=mp1, odd_stride, 2\n br(mp1, np1, k) = br(mp1, np1, k)+zv(np1+mb, i)*vo(i, 2*mp1-2, k) &\n +zw(np1+mb, i)*we(i, 2*mp1-1, k)\n bi(mp1, np1, k) = bi(mp1, np1, k)+zv(np1+mb, i)*vo(i, 2*mp1-1, k) &\n -zw(np1+mb, i)*we(i, 2*mp1-2, k)\n cr(mp1, np1, k) = cr(mp1, np1, k)-zv(np1+mb, i)*wo(i, 2*mp1-2, k) &\n +zw(np1+mb, i)*ve(i, 2*mp1-1, k)\n ci(mp1, np1, k) = ci(mp1, np1, k)-zv(np1+mb, i)*wo(i, 2*mp1-1, k) &\n -zw(np1+mb, i)*ve(i, 2*mp1-2, k)\n end do\n end do\n end do\n if (mod(nlat, 2) /= 0) then\n do k=1, nt\n do np1=mp1, odd_stride, 2\n br(mp1, np1, k) = br(mp1, np1, k)+zw(np1+mb, imid)*we(imid, 2*mp1-1, k)\n bi(mp1, np1, k) = bi(mp1, np1, k)-zw(np1+mb, imid)*we(imid, 2*mp1-2, k)\n cr(mp1, np1, k) = cr(mp1, np1, k)+zw(np1+mb, imid)*ve(imid, 2*mp1-1, k)\n ci(mp1, np1, k) = ci(mp1, np1, k)-zw(np1+mb, imid)*ve(imid, 2*mp1-2, k)\n end do\n end do\n end if\n end if\n\n if (mp2 > even_stride) cycle main_loop_case_0\n\n do k=1, nt\n do i=1, imm1\n do np1=mp2, even_stride, 2\n br(mp1, np1, k) = br(mp1, np1, k)+zv(np1+mb, i)*ve(i, 2*mp1-2, k) &\n +zw(np1+mb, i)*wo(i, 2*mp1-1, k)\n bi(mp1, np1, k) = bi(mp1, np1, k)+zv(np1+mb, i)*ve(i, 2*mp1-1, k) &\n -zw(np1+mb, i)*wo(i, 2*mp1-2, k)\n cr(mp1, np1, k) = cr(mp1, np1, k)-zv(np1+mb, i)*we(i, 2*mp1-2, k) &\n +zw(np1+mb, i)*vo(i, 2*mp1-1, k)\n ci(mp1, np1, k) = ci(mp1, np1, k)-zv(np1+mb, i)*we(i, 2*mp1-1, k) &\n -zw(np1+mb, i)*vo(i, 2*mp1-2, k)\n end do\n end do\n end do\n\n if (mod(nlat, 2) == 0) cycle main_loop_case_0\n\n do k=1, nt\n do np1=mp2, even_stride, 2\n br(mp1, np1, k) = br(mp1, np1, k)+zv(np1+mb, imid)*ve(imid, 2*mp1-2, k)\n bi(mp1, np1, k) = bi(mp1, np1, k)+zv(np1+mb, imid)*ve(imid, 2*mp1-1, k)\n cr(mp1, np1, k) = cr(mp1, np1, k)-zv(np1+mb, imid)*we(imid, 2*mp1-2, k)\n ci(mp1, np1, k) = ci(mp1, np1, k)-zv(np1+mb, imid)*we(imid, 2*mp1-1, k)\n end do\n end do\n end do main_loop_case_0\n case (1)\n !\n ! case ityp=1 , no symmetries but cr and ci equal zero\n !\n ! case m=0\n !\n do k=1, nt\n do i=1, imid\n do np1=2, even_stride, 2\n br(1, np1, k) = br(1, np1, k)+zv(np1, i)*ve(i, 1, k)\n end do\n end do\n end do\n\n do k=1, nt\n do i=1, imm1\n do np1=3, odd_stride, 2\n br(1, np1, k) = br(1, np1, k)+zv(np1, i)*vo(i, 1, k)\n end do\n end do\n end do\n !\n ! case m = 1 through nlat-1\n !\n if (mmax < 2) return\n\n do mp1=2, mmax\n m = mp1-1\n mb = m*(nlat-1)-(m*(m-1))/2\n mp2 = mp1+1\n\n if (mp1 <= odd_stride) then\n do k=1, nt\n do i=1, imm1\n do np1=mp1, odd_stride, 2\n br(mp1, np1, k) = br(mp1, np1, k)+zv(np1+mb, i)*vo(i, 2*mp1-2, k) &\n +zw(np1+mb, i)*we(i, 2*mp1-1, k)\n bi(mp1, np1, k) = bi(mp1, np1, k)+zv(np1+mb, i)*vo(i, 2*mp1-1, k) &\n -zw(np1+mb, i)*we(i, 2*mp1-2, k)\n end do\n end do\n end do\n\n if (mod(nlat, 2) /= 0) then\n do k=1, nt\n do np1=mp1, odd_stride, 2\n br(mp1, np1, k) = br(mp1, np1, k)+zw(np1+mb, imid)*we(imid, 2*mp1-1, k)\n bi(mp1, np1, k) = bi(mp1, np1, k)-zw(np1+mb, imid)*we(imid, 2*mp1-2, k)\n end do\n end do\n end if\n end if\n\n if (mp2 > even_stride) return\n\n do k=1, nt\n do i=1, imm1\n do np1=mp2, even_stride, 2\n br(mp1, np1, k) = br(mp1, np1, k)+zv(np1+mb, i)*ve(i, 2*mp1-2, k) &\n +zw(np1+mb, i)*wo(i, 2*mp1-1, k)\n bi(mp1, np1, k) = bi(mp1, np1, k)+zv(np1+mb, i)*ve(i, 2*mp1-1, k) &\n -zw(np1+mb, i)*wo(i, 2*mp1-2, k)\n end do\n end do\n end do\n\n if (mod(nlat, 2) == 0) return\n\n do k=1, nt\n do np1=mp2, even_stride, 2\n br(mp1, np1, k) = br(mp1, np1, k)+zv(np1+mb, imid)*ve(imid, 2*mp1-2, k)\n bi(mp1, np1, k) = bi(mp1, np1, k)+zv(np1+mb, imid)*ve(imid, 2*mp1-1, k)\n end do\n end do\n end do\n case (2)\n !\n ! case ityp=2 , no symmetries but br and bi equal zero\n !\n ! case m=0\n !\n do k=1, nt\n do i=1, imid\n do np1=2, even_stride, 2\n cr(1, np1, k) = cr(1, np1, k)-zv(np1, i)*we(i, 1, k)\n end do\n end do\n end do\n\n do k=1, nt\n do i=1, imm1\n do np1=3, odd_stride, 2\n cr(1, np1, k) = cr(1, np1, k)-zv(np1, i)*wo(i, 1, k)\n end do\n end do\n end do\n !\n ! case m = 1 through nlat-1\n !\n if (mmax < 2) return\n\n do mp1=2, mmax\n m = mp1-1\n mb = m*(nlat-1)-(m*(m-1))/2\n mp2 = mp1+1\n\n if (mp1 <= odd_stride) then\n do k=1, nt\n do i=1, imm1\n do np1=mp1, odd_stride, 2\n cr(mp1, np1, k) = cr(mp1, np1, k)-zv(np1+mb, i)*wo(i, 2*mp1-2, k) &\n +zw(np1+mb, i)*ve(i, 2*mp1-1, k)\n ci(mp1, np1, k) = ci(mp1, np1, k)-zv(np1+mb, i)*wo(i, 2*mp1-1, k) &\n -zw(np1+mb, i)*ve(i, 2*mp1-2, k)\n end do\n end do\n end do\n\n if (mod(nlat, 2) /= 0) then\n do k=1, nt\n do np1=mp1, odd_stride, 2\n cr(mp1, np1, k) = cr(mp1, np1, k)+zw(np1+mb, imid)*ve(imid, 2*mp1-1, k)\n ci(mp1, np1, k) = ci(mp1, np1, k)-zw(np1+mb, imid)*ve(imid, 2*mp1-2, k)\n end do\n end do\n end if\n end if\n\n if (mp2 > even_stride) return\n\n do k=1, nt\n do i=1, imm1\n do np1=mp2, even_stride, 2\n cr(mp1, np1, k) = cr(mp1, np1, k)-zv(np1+mb, i)*we(i, 2*mp1-2, k) &\n +zw(np1+mb, i)*vo(i, 2*mp1-1, k)\n ci(mp1, np1, k) = ci(mp1, np1, k)-zv(np1+mb, i)*we(i, 2*mp1-1, k) &\n -zw(np1+mb, i)*vo(i, 2*mp1-2, k)\n end do\n end do\n end do\n\n if (mod(nlat, 2) == 0) return\n\n do k=1, nt\n do np1=mp2, even_stride, 2\n cr(mp1, np1, k) = cr(mp1, np1, k)-zv(np1+mb, imid)*we(imid, 2*mp1-2, k)\n ci(mp1, np1, k) = ci(mp1, np1, k)-zv(np1+mb, imid)*we(imid, 2*mp1-1, k)\n end do\n end do\n end do\n case (3)\n !\n ! case ityp=3 , v even , w odd\n !\n ! case m=0\n !\n do k=1, nt\n do i=1, imid\n do np1=2, even_stride, 2\n br(1, np1, k) = br(1, np1, k)+zv(np1, i)*ve(i, 1, k)\n end do\n end do\n end do\n\n do k=1, nt\n do i=1, imm1\n do np1=3, odd_stride, 2\n cr(1, np1, k) = cr(1, np1, k)-zv(np1, i)*wo(i, 1, k)\n end do\n end do\n end do\n !\n ! case m = 1 through nlat-1\n !\n if (mmax < 2) return\n\n do mp1=2, mmax\n m = mp1-1\n mb = m*(nlat-1)-(m*(m-1))/2\n mp2 = mp1+1\n\n if (mp1 <= odd_stride) then\n do k=1, nt\n do i=1, imm1\n do np1=mp1, odd_stride, 2\n cr(mp1, np1, k) = cr(mp1, np1, k)-zv(np1+mb, i)*wo(i, 2*mp1-2, k) &\n +zw(np1+mb, i)*ve(i, 2*mp1-1, k)\n ci(mp1, np1, k) = ci(mp1, np1, k)-zv(np1+mb, i)*wo(i, 2*mp1-1, k) &\n -zw(np1+mb, i)*ve(i, 2*mp1-2, k)\n end do\n end do\n end do\n\n if (mod(nlat, 2) /= 0) then\n do k=1, nt\n do np1=mp1, odd_stride, 2\n cr(mp1, np1, k) = cr(mp1, np1, k)+zw(np1+mb, imid)*ve(imid, 2*mp1-1, k)\n ci(mp1, np1, k) = ci(mp1, np1, k)-zw(np1+mb, imid)*ve(imid, 2*mp1-2, k)\n end do\n end do\n end if\n end if\n\n if (mp2 > even_stride) return\n\n do k=1, nt\n do i=1, imm1\n do np1=mp2, even_stride, 2\n br(mp1, np1, k) = br(mp1, np1, k)+zv(np1+mb, i)*ve(i, 2*mp1-2, k) &\n +zw(np1+mb, i)*wo(i, 2*mp1-1, k)\n bi(mp1, np1, k) = bi(mp1, np1, k)+zv(np1+mb, i)*ve(i, 2*mp1-1, k) &\n -zw(np1+mb, i)*wo(i, 2*mp1-2, k)\n end do\n end do\n end do\n\n if (mod(nlat, 2) == 0) return\n\n do k=1, nt\n do np1=mp2, even_stride, 2\n br(mp1, np1, k) = br(mp1, np1, k)+zv(np1+mb, imid)*ve(imid, 2*mp1-2, k)\n bi(mp1, np1, k) = bi(mp1, np1, k)+zv(np1+mb, imid)*ve(imid, 2*mp1-1, k)\n end do\n end do\n end do\n case (4)\n !\n ! case ityp=4 , v even, w odd, and cr and ci equal 0.\n !\n ! case m=0\n !\n do k=1, nt\n do i=1, imid\n do np1=2, even_stride, 2\n br(1, np1, k) = br(1, np1, k)+zv(np1, i)*ve(i, 1, k)\n end do\n end do\n end do\n !\n ! case m = 1 through nlat-1\n !\n if (mmax < 2) return\n\n do mp1=2, mmax\n m = mp1-1\n mb = m*(nlat-1)-(m*(m-1))/2\n mp2 = mp1+1\n\n if (mp2 > even_stride) exit\n\n do k=1, nt\n do i=1, imm1\n do np1=mp2, even_stride, 2\n br(mp1, np1, k) = br(mp1, np1, k)+zv(np1+mb, i)*ve(i, 2*mp1-2, k) &\n +zw(np1+mb, i)*wo(i, 2*mp1-1, k)\n bi(mp1, np1, k) = bi(mp1, np1, k)+zv(np1+mb, i)*ve(i, 2*mp1-1, k) &\n -zw(np1+mb, i)*wo(i, 2*mp1-2, k)\n end do\n end do\n end do\n\n if (mod(nlat, 2) == 0) return\n\n do k=1, nt\n do np1=mp2, even_stride, 2\n br(mp1, np1, k) = br(mp1, np1, k)+zv(np1+mb, imid)*ve(imid, 2*mp1-2, k)\n bi(mp1, np1, k) = bi(mp1, np1, k)+zv(np1+mb, imid)*ve(imid, 2*mp1-1, k)\n end do\n end do\n end do\n case (5)\n !\n ! case ityp=5 v even, w odd, and br and bi equal zero\n !\n ! case m=0\n !\n do k=1, nt\n do i=1, imm1\n do np1=3, odd_stride, 2\n cr(1, np1, k) = cr(1, np1, k)-zv(np1, i)*wo(i, 1, k)\n end do\n end do\n end do\n !\n ! case m = 1 through nlat-1\n !\n if (mmax < 2) return\n\n do mp1=2, mmax\n m = mp1-1\n mb = m*(nlat-1)-(m*(m-1))/2\n mp2 = mp1+1\n\n if (mp1 > odd_stride) exit\n\n do k=1, nt\n do i=1, imm1\n do np1=mp1, odd_stride, 2\n cr(mp1, np1, k) = cr(mp1, np1, k)-zv(np1+mb, i)*wo(i, 2*mp1-2, k) &\n +zw(np1+mb, i)*ve(i, 2*mp1-1, k)\n ci(mp1, np1, k) = ci(mp1, np1, k)-zv(np1+mb, i)*wo(i, 2*mp1-1, k) &\n -zw(np1+mb, i)*ve(i, 2*mp1-2, k)\n end do\n end do\n end do\n\n if (mod(nlat, 2) == 0) exit\n\n do k=1, nt\n do np1=mp1, odd_stride, 2\n cr(mp1, np1, k) = cr(mp1, np1, k)+zw(np1+mb, imid)*ve(imid, 2*mp1-1, k)\n ci(mp1, np1, k) = ci(mp1, np1, k)-zw(np1+mb, imid)*ve(imid, 2*mp1-2, k)\n end do\n end do\n end do\n case (6)\n !\n ! case ityp=6 , v odd , w even\n !\n ! case m=0\n !\n do k=1, nt\n do i=1, imid\n do np1=2, even_stride, 2\n cr(1, np1, k) = cr(1, np1, k)-zv(np1, i)*we(i, 1, k)\n end do\n end do\n end do\n\n do k=1, nt\n do i=1, imm1\n do np1=3, odd_stride, 2\n br(1, np1, k) = br(1, np1, k)+zv(np1, i)*vo(i, 1, k)\n end do\n end do\n end do\n !\n ! case m = 1 through nlat-1\n !\n if (mmax < 2) return\n\n do mp1=2, mmax\n m = mp1-1\n mb = m*(nlat-1)-(m*(m-1))/2\n mp2 = mp1+1\n\n if (mp1 <= odd_stride) then\n\n do k=1, nt\n do i=1, imm1\n do np1=mp1, odd_stride, 2\n br(mp1, np1, k) = br(mp1, np1, k)+zv(np1+mb, i)*vo(i, 2*mp1-2, k) &\n +zw(np1+mb, i)*we(i, 2*mp1-1, k)\n bi(mp1, np1, k) = bi(mp1, np1, k)+zv(np1+mb, i)*vo(i, 2*mp1-1, k) &\n -zw(np1+mb, i)*we(i, 2*mp1-2, k)\n end do\n end do\n end do\n\n if (mod(nlat, 2) /= 0) then\n do k=1, nt\n do np1=mp1, odd_stride, 2\n br(mp1, np1, k) = br(mp1, np1, k)+zw(np1+mb, imid)*we(imid, 2*mp1-1, k)\n bi(mp1, np1, k) = bi(mp1, np1, k)-zw(np1+mb, imid)*we(imid, 2*mp1-2, k)\n end do\n end do\n end if\n end if\n\n if (mp2 > even_stride) return\n\n do k=1, nt\n do i=1, imm1\n do np1=mp2, even_stride, 2\n cr(mp1, np1, k) = cr(mp1, np1, k)-zv(np1+mb, i)*we(i, 2*mp1-2, k) &\n +zw(np1+mb, i)*vo(i, 2*mp1-1, k)\n ci(mp1, np1, k) = ci(mp1, np1, k)-zv(np1+mb, i)*we(i, 2*mp1-1, k) &\n -zw(np1+mb, i)*vo(i, 2*mp1-2, k)\n end do\n end do\n end do\n\n if (mod(nlat, 2) == 0) return\n\n do k=1, nt\n do np1=mp2, even_stride, 2\n cr(mp1, np1, k) = cr(mp1, np1, k)-zv(np1+mb, imid)*we(imid, 2*mp1-2, k)\n ci(mp1, np1, k) = ci(mp1, np1, k)-zv(np1+mb, imid)*we(imid, 2*mp1-1, k)\n end do\n end do\n end do\n case (7)\n !\n ! case ityp=7 v odd, w even, and cr and ci equal zero\n !\n ! case m=0\n !\n do k=1, nt\n do i=1, imm1\n do np1=3, odd_stride, 2\n br(1, np1, k) = br(1, np1, k)+zv(np1, i)*vo(i, 1, k)\n end do\n end do\n end do\n !\n ! case m = 1 through nlat-1\n !\n if (mmax < 2) return\n\n do mp1=2, mmax\n m = mp1-1\n mb = m*(nlat-1)-(m*(m-1))/2\n mp2 = mp1+1\n\n if (mp1 > odd_stride) return\n\n do k=1, nt\n do i=1, imm1\n do np1=mp1, odd_stride, 2\n br(mp1, np1, k) = br(mp1, np1, k)+zv(np1+mb, i)*vo(i, 2*mp1-2, k) &\n +zw(np1+mb, i)*we(i, 2*mp1-1, k)\n bi(mp1, np1, k) = bi(mp1, np1, k)+zv(np1+mb, i)*vo(i, 2*mp1-1, k) &\n -zw(np1+mb, i)*we(i, 2*mp1-2, k)\n end do\n end do\n end do\n\n if (mod(nlat, 2) == 0) return\n\n do k=1, nt\n do np1=mp1, odd_stride, 2\n br(mp1, np1, k) = br(mp1, np1, k)+zw(np1+mb, imid)*we(imid, 2*mp1-1, k)\n bi(mp1, np1, k) = bi(mp1, np1, k)-zw(np1+mb, imid)*we(imid, 2*mp1-2, k)\n end do\n end do\n end do\n case (8)\n !\n ! case ityp=8 v odd, w even, and both br and bi equal zero\n !\n ! case m=0\n !\n do k=1, nt\n do i=1, imid\n do np1=2, even_stride, 2\n cr(1, np1, k) = cr(1, np1, k)-zv(np1, i)*we(i, 1, k)\n end do\n end do\n end do\n !\n ! case m = 1 through nlat-1\n !\n if (mmax < 2) return\n\n do mp1=2, mmax\n m = mp1-1\n mb = m*(nlat-1)-(m*(m-1))/2\n mp2 = mp1+1\n\n if (mp2 > even_stride) return\n\n do k=1, nt\n do i=1, imm1\n do np1=mp2, even_stride, 2\n cr(mp1, np1, k) = cr(mp1, np1, k)-zv(np1+mb, i)*we(i, 2*mp1-2, k) &\n +zw(np1+mb, i)*vo(i, 2*mp1-1, k)\n ci(mp1, np1, k) = ci(mp1, np1, k)-zv(np1+mb, i)*we(i, 2*mp1-1, k) &\n -zw(np1+mb, i)*vo(i, 2*mp1-2, k)\n end do\n end do\n end do\n\n if (mod(nlat, 2) == 0) return\n\n do k=1, nt\n do np1=mp2, even_stride, 2\n cr(mp1, np1, k) = cr(mp1, np1, k)-zv(np1+mb, imid)*we(imid, 2*mp1-2, k)\n ci(mp1, np1, k) = ci(mp1, np1, k)-zv(np1+mb, imid)*we(imid, 2*mp1-1, k)\n end do\n end do\n end do\n end select\n\n end subroutine vhaes_lower_utility_routine\n\n pure function get_vhaesi_workspace_indices(lzimn, nlat, imid, mmax) &\n result (return_value)\n\n ! Dummy arguments\n integer(ip), intent(in) :: lzimn\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: imid\n integer(ip), intent(in) :: mmax\n integer(ip) :: return_value(4)\n\n\n associate (i => return_value)\n i(1) = lzimn+1\n i(2) = 2*lzimn+1\n i(3) = 3*nlat*imid+1\n i(4) = (mmax*(2*nlat-mmax+1))/2\n end associate\n\n end function get_vhaesi_workspace_indices\n\n subroutine vhaesi_lower_utility_routine(nlat, nlon, imid, zv, zw, idz, zin, wzvin, dwork)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n integer(ip), intent(in) :: imid\n real(wp), intent(out) :: zv(idz, *)\n real(wp), intent(out) :: zw(idz, *)\n integer(ip), intent(in) :: idz\n real(wp), intent(out) :: zin(imid, nlat, 3)\n real(wp), intent(out) :: wzvin(*)\n real(wp), intent(out) :: dwork(*)\n\n ! Local variables\n integer(ip) :: i3, m, mn, mp1, np1, mmax\n type(SpherepackUtility) :: util\n\n mmax = min(nlat, (nlon + 1)/2)\n\n call util%zvinit(nlat, nlon, wzvin, dwork)\n\n do mp1=1, mmax\n m = mp1-1\n call util%zvin(0, nlat, nlon, m, zin, i3, wzvin)\n do np1=mp1, nlat\n mn = m*(nlat-1)-(m*(m-1))/2+np1\n zv(mn, 1:imid) = zin(1:imid, np1, i3)\n end do\n end do\n\n call util%zwinit(nlat, nlon, wzvin, dwork)\n\n do mp1=1, mmax\n m = mp1-1\n call util%zwin(0, nlat, nlon, m, zin, i3, wzvin)\n do np1=mp1, nlat\n mn = m*(nlat-1)-(m*(m-1))/2+np1\n zw(mn, 1:imid) = zin(1:imid, np1, i3)\n end do\n end do\n\n end subroutine vhaesi_lower_utility_routine\n\nend submodule vector_analysis_regular_grid_saved\n", "meta": {"hexsha": "e7d2f7a1753154edc7fe22e8c2ef3aa185af935f", "size": 48250, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/vector_analysis_regular_grid_saved.f90", "max_stars_repo_name": "jlokimlin/spherepack4.1", "max_stars_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-06-28T14:01:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T21:59:28.000Z", "max_issues_repo_path": "src/vector_analysis_regular_grid_saved.f90", "max_issues_repo_name": "jlokimlin/spherepack4.1", "max_issues_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2016-05-07T23:00:35.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-22T23:52:30.000Z", "max_forks_repo_path": "src/vector_analysis_regular_grid_saved.f90", "max_forks_repo_name": "jlokimlin/spherepack4.1", "max_forks_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-06-28T14:03:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T12:53:54.000Z", "avg_line_length": 43.3902877698, "max_line_length": 108, "alphanum_fraction": 0.3875025907, "num_tokens": 14046, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587964389112, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6810502112043567}} {"text": " program Ising2d_equilibrium_f77\n use benchmark_m\n implicit real(8) (a-h,o-z)\n parameter(nx=51, ny=50, N=nx*ny, noff=nx, nall=N+2*noff)\n parameter(ilb=-noff+1, irb=ilb+nall)\n parameter(nkbt=50, dkbt_beg=2.6d0, dkbt_end=2.0d0)\n parameter(mcs_relx=500000, mcs_smpl=500000)\n dimension Ising(ilb:irb)\n dimension exparr(-8:8)\n dimension dkbts(nkbt), dmagne(nkbt), energy(nkbt)\n dimension rnd(N)\n type(benchmark_t) :: bm\n write(6, '(a,i0)' ) \"# N = \", N\n write(6, '(a,i0)' ) \"# MCS(relaxation) = \", mcs_relx\n write(6, '(a,i0)' ) \"# MCS(sampling) = \", mcs_smpl\n write(0, '(3(a, i0))' ) \"nx\", nx, \" ny\", ny\n write(0, '(a, f30.18)') \"method: METROPOLIS\"\n bm = benchmark_t()\nc initialize dkbts, Ising, energy, dmagne.\n do i = 1, nkbt\n dkbts(i) =\n & ( (nkbt-1-i+1)*dkbt_beg\n & + (i-1) *dkbt_end ) / (nkbt-1) ! internal division point.\n end do\n call random_number(rnd)\n do i = 1, N\n if (rnd(i) .lt. 0.5d0) then\n Ising(i) = +1\n else\n Ising(i) = -1\n end if\nc$$$ print '(i5, a, i0)', i, \": \", Ising(i)\n end do\n energy = 0.0d0\n dmagne = 0.0d0\nc update norishiro.\n do i = 1, noff\n Ising(i-noff) = Ising(i+N-noff)\n Ising(i+N) = Ising(i)\n end do\nc calculate initial magnetization and energy.\n magne = 0\n ienergy = 0\n do i = 1, N\n magne = magne + Ising(i)\n ienergy = ienergy - Ising(i)*(Ising(i+1)+Ising(i+nx))\n end do\nc update Ising in each temperatures.\n exparr = 1.0d0\n call bm%stamp(\"start update\")\n do k = 1, nkbt\n dbeta = 1/dkbts(k)\n write(0, '(a, i7, es23.15)') \"iterate: \", k, dkbts(k)\nc Initialize exparr.\n do i = 1, 8\n exparr(i) = exp(-dbeta*i)\n end do\nc relax Ising with Metropolis.\n do j = 1, mcs_relx\nc update Ising with checkerboard pattern.\n call random_number(rnd)\n do is = 1, 2\n do i = is, N, 2\n ide = 2*Ising(i)*\n & (Ising(i+1)+Ising(i-1)+Ising(i+nx)+Ising(i-nx))\n if (rnd(i) .lt. exparr(ide)) then\n Ising(i) = -Ising(i)\n magne = magne + 2*Ising(i)\n ienergy = ienergy + ide\n end if\n end do\nc update norishiro.\n do i = 1, noff\n Ising(i-noff) = Ising(i+N-noff)\n Ising(i+N) = Ising(i)\n end do\n end do\n end do ! end j (1:mcs_relx)\nc relax Ising with Metropolis and calculate parameters.\n dm = 0.0d0\n e = 0.0d0\n do j = 1, mcs_smpl\nc update Ising with checkerboard pattern.\n call random_number(rnd)\n do is = 1, 2\n do i = is, N, 2\n ide = 2*Ising(i)*\n & (Ising(i+1)+Ising(i-1)+Ising(i+nx)+Ising(i-nx))\n if (rnd(i) .lt. exparr(ide)) then\n Ising(i) = -Ising(i)\n magne = magne + 2*Ising(i)\n ienergy = ienergy + ide\n end if\n end do\nc update norishiro.\n do i = 1, noff\n Ising(i-noff) = Ising(i+N-noff)\n Ising(i+N) = Ising(i)\n end do\n end do\n dm = dm + abs(1.0d0*magne / N)\n e = e + 1.0d0*ienergy / N\n end do ! end j (1:mcs_smpl)\n dmagne(k) = dm / mcs_smpl\n energy(k) = e / mcs_smpl\n end do ! end k (1:nkbt)\n call bm%stamp(\"end update\")\nc print parameters.\n write(6, '(a)') \"# temperature, magne, energy\"\n do k = 1, nkbt\n write(6, '(i0,a,i0,\" \",i0,\" \",*(es20.12))')\n & nx, \"x\", ny,\n & k, dkbts(k), dmagne(k), energy(k)\n end do\n call bm%dump()\n call destroy_benchmark_t(bm)\nc print all spins including norishiro\nc$$$ do j = 0, ny+1\nc$$$ write(0, '(i8, a)', advance=\"NO\") j, \": \"\nc$$$ do i = 1, nx\nc$$$ write(0, '(i3)', advance=\"NO\") Ising((j-1)*nx+i)\nc$$$ end do\nc$$$ write(0, *)\nc$$$ end do\n stop\n end program Ising2d_equilibrium_f77\n", "meta": {"hexsha": "2b1589b92310ec806f9cf5b0cb7fb9f4e65f20a5", "size": 4387, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "app/Ising2d_equilibrium_f77.f", "max_stars_repo_name": "osada-yum/spin-simulation", "max_stars_repo_head_hexsha": "3074529b95e6eb319e3585c360e2ea86c1cab57e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app/Ising2d_equilibrium_f77.f", "max_issues_repo_name": "osada-yum/spin-simulation", "max_issues_repo_head_hexsha": "3074529b95e6eb319e3585c360e2ea86c1cab57e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "app/Ising2d_equilibrium_f77.f", "max_forks_repo_name": "osada-yum/spin-simulation", "max_forks_repo_head_hexsha": "3074529b95e6eb319e3585c360e2ea86c1cab57e", "max_forks_repo_licenses": ["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.5433070866, "max_line_length": 77, "alphanum_fraction": 0.4586277638, "num_tokens": 1474, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.888758793492457, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6810502089465076}} {"text": " subroutine setglonglat(IMAX,JMAX,GLON,GLAT)\n!-----------------------------------------------------------------------\n use m_die,only : die\n implicit none\n integer,intent(in) :: IMAX,JMAX\n real,dimension(imax),intent(out) :: GLON\n real,dimension(jmax),intent(out) :: GLAT\n\n integer :: JHF\n real,dimension(JMAX/2) :: COLRAD,WGT,WGTCS,RCS2\n real :: PI,RDR,DLN\n integer :: LL,LLS,LN\n\n if(mod(JMAX,2)/=0) call die(\"setglonglat\",\"mod(JMAX,2)/=0\")\n JHF=JMAX/2\n\n CALL GLATS(JHF,COLRAD,WGT,WGTCS,RCS2)\n\n PI=ASIN(1.)*2\n RDR=180./PI\nC\n DO LL = 1,JHF\n LLS = JMAX+1 - LL\n GLAT(LL) = 90. - COLRAD(LL)*RDR\n GLAT(LLS) = -GLAT(LL)\n ENDDO\nC\n DLN = 360.0/FLOAT(IMAX)\n DO LN = 1,IMAX\n GLON(LN) = (LN-1) * DLN\n ENDDO\n end subroutine setglonglat\n\tsubroutine setglonglat2(IMAX,JMAX,GLON,GLAT)\n!-----------------------------------------------------------------------\n!-- define 2-d (lon,lat) grid with Gaussian latitudes.\n\tuse m_die,only : die\n\timplicit none\n\tinteger,intent(in) :: IMAX,JMAX\n\treal,dimension(IMAX,JMAX),intent(out) :: GLON\n\treal,dimension(IMAX,JMAX),intent(out) :: GLAT\n\n\tinteger :: JHF\n\treal,dimension(JMAX/2) :: COLRAD,WGT,WGTCS,RCS2\n\n real :: PI,RAD,DLN\n\tinteger :: I,LL,LLS\n\tinteger :: J,LN\n\n\tif(mod(JMAX,2)/=0) call die(\"setglonglat2\",\"mod(JMAX,2)/=0\")\n\tJHF=JMAX/2\n\n CALL GLATS(JHF,COLRAD,WGT,WGTCS,RCS2)\nC\n PI=ASIN(1.)*2\n RAD=PI/180.\nC\n DO I = 1,IMAX\n DO LL = 1,JHF\n LLS = JMAX+1 - LL\n GLAT(I,LL) = 90. - COLRAD(LL)/RAD\n GLAT(I,LLS) = -GLAT(I,LL)\n ENDDO\n ENDDO\nC\n DLN = 360.0/FLOAT(IMAX)\n DO J = 1,JMAX\n DO LN = 1,IMAX\n GLON(LN,J) = (LN-1) * DLN\n ENDDO\n ENDDO\n end subroutine setglonglat2\n SUBROUTINE GLATS(LGGHAF,COLRAD,WGT,WGTCS,RCS2)\n!-----------------------------------------------------------------------\nC$$$ SUBPROGRAM DOCUMENTATION BLOCK\nC . . . .\nC SUBPROGRAM: GLATS COMPUTES LOCATION OF GAUSSIAN LATITUDES.\nC PRGMMR: JOSEPH SELA ORG: W/NMC23 DATE: 88-04-05\nC\nC ABSTRACT: COMPUTES THE LOCATION OF THE GAUSSIAN LATITUDES FOR THE\nC INPUT LGGHAF. THE LATITUDES ARE DETERMINED BY FINDING\nC THE ZEROS OF THE LEGENDRE POLYNOMIALS.\nC\nC PROGRAM HISTORY LOG:\nC 88-04-05 JOSEPH SELA\nC\nC USAGE: CALL GLATS (LGGHAF, COLRAD, WGT, WGTCS, RCS2)\nC INPUT ARGUMENT LIST:\nC LGGHAF - NUMBER OF GAUSSIAN LATITUDES IN A HEMISPHERE.\nC\nC OUTPUT ARGUMENT LIST:\nC COLRAD - ARRAY OF COLATITUDE OF GAUSSIAN LATITUDES\nC IN NORTHERN HEMISPHERE.\nC WGT - ARRAY OF WEIGHTS AT EACH GAUSSIAN LATITUDE\nC REQUIRED FOR GAUSSIAN QUADRATURE.\nC WGTCS - ARRAY OF GAUSSIAN WEIGHT/SIN OF COLATITUDE SQUARED.\nC RCS2 - ARRAY OF RECIPROCAL OF SIN OF COLATITUDE SQUARED.\nC\nC OUTPUT FILES:\nC OUTPUT - PRINTOUT FILE.\nC\nC ATTRIBUTES:\nC LANGUAGE: FORTRAN 200.\nC MACHINE: CYBER 205.\nC\nC$$$\nCCCC HALF PRECISION COLRAD,WGT,WGTCS,RCS2\n REAL COLRAD(LGGHAF),WGT(LGGHAF),WGTCS(LGGHAF)\n REAL RCS2(LGGHAF)\n EPS=1.E-12\nC PRINT 101\nC101 FORMAT ('0 I COLAT COLRAD WGT', 12X, 'WGTCS',\nCCCC 1 10X, 'ITER RES')\n SI = 1.0\n L2=2*LGGHAF\n RL2=L2\n SCALE = 2.0/(RL2*RL2)\n K1=L2-1\n PI = ATAN(SI)*4.E+00\n DRADZ = PI / 360.\n RAD = 0.0\n DO 1000 K=1,LGGHAF\n ITER=0\n DRAD=DRADZ\n1 CALL POLY(L2,RAD,P2)\n2 P1 =P2\n ITER=ITER+1\n RAD=RAD+DRAD\n CALL POLY(L2,RAD,P2)\n IF(SIGN(SI,P1).EQ.SIGN(SI,P2)) GO TO 2\n IF(DRAD.LT.EPS)GO TO 3\n RAD=RAD-DRAD\n DRAD = DRAD * 0.25\n GO TO 1\n3 CONTINUE\n COLRAD(K)=RAD\n PHI = RAD * 180 / PI\n CALL POLY(K1,RAD,P1)\n X = COS(RAD)\n W = SCALE * (1.0 - X*X)/ (P1*P1)\n WGT(K) = W\n SN = SIN(RAD)\n W=W/(SN*SN)\n WGTCS(K) = W\n RC=1./(SN*SN)\n RCS2(K) = RC\n CALL POLY(L2,RAD,P1)\nC PRINT 102,K,PHI,COLRAD(K),WGT(K),WGTCS(K),ITER,P1\nC102 FORMAT(1H ,I2,2X,F6.2,2X,F10.7,2X,E13.7,2X,E13.7,2X,I4,2X,D13.7)\n1000 CONTINUE\n RETURN\n END SUBROUTINE GLATS\n SUBROUTINE POLY(N,RAD,P)\n!-----------------------------------------------------------------------\nC$$$ SUBPROGRAM DOCUMENTATION BLOCK\nC . . . .\nC SUBPROGRAM: POLY EVALUATES LEGENDRE POLYNOMIAL.\nC PRGMMR: JOSEPH SELA ORG: W/NMC23 DATE: 88-04-01\nC\nC ABSTRACT: EVALUATES THE UNNORMALIZED LEGENDRE POLYNOMIAL\nC OF SPECIFIED DEGREE AT A GIVEN COLATITUDE USING A STANDARD\nC RECURSION FORMULA. REAL ARITHMETIC IS USED.\nC\nC PROGRAM HISTORY LOG:\nC 88-04-01 JOSEPH SELA\nC\nC USAGE: CALL POLY (N, RAD, P)\nC INPUT ARGUMENT LIST:\nC N - DEGREE OF LEGENDRE POLYNOMIAL.\nC RAD - REAL COLATITUDE IN RADIANS.\nC\nC OUTPUT ARGUMENT LIST:\nC P - REAL VALUE OF LEGENDRE POLYNOMIAL.\nC\nC ATTRIBUTES:\nC LANGUAGE: FORTRAN 200.\nC MACHINE: CYBER 205.\nC\nC$$$\n X = COS(RAD)\n Y1 = 1.0\n Y2=X\n DO 1 I=2,N\n G=X*Y2\n Y3=G-Y1+G-(G-Y1)/FLOAT(I)\n Y1=Y2\n Y2=Y3\n1 CONTINUE\n P=Y3\n RETURN\n END SUBROUTINE POLY\n subroutine maxmin(a,len,k,k1,k2,ch)\n!-----------------------------------------------------------------------\n dimension a(len,k)\n character ch*(*)\nc\ncccc cmic$ do all\ncccc cmic$1 shared(a,ch,len,k1,k2)\ncccc cmic$1 private(aamax,aamin,m)\n do 100 j=k1,k2\n aamax = a(1,j)\n aamin = a(1,j)\n do 10 m=1,len\n aamax = max( aamax, a(m,j) )\n aamin = min( aamin, a(m,j) )\n10 continue\nC print *,ch,' has max=',aamax,' min=',aamin\n100 continue\n return\n end subroutine maxmin\n SUBROUTINE WRIT1(IRX,JRX,DIN,NWT1,NWRT1,MTV2,NST,IUT,HDAT)\n !!PARAMETER (IRX=41,JRX=41,NST=10)\n implicit none\n integer,intent(in) :: IRX,JRX\n REAL,intent(in) :: DIN(IRX,JRX)\n integer,intent(inout) :: NWT1,NWRT1\n integer,intent(in) :: MTV2,NST,IUT\n real,intent(out) :: HDAT(IRX,JRX,MTV2,NST)\n\n integer :: I,J\n NWRT1=NWRT1+1\n NWT1=NWT1+1\nc PRINT*,'WRIT1 COUNT = ',NWRT1,NWT1,IUT\n DO J=1,JRX\n DO I=1,IRX\n HDAT(I,J,NWRT1,IUT)=DIN(I,J)\n END DO\n END DO\n END SUBROUTINE WRIT1\n SUBROUTINE READ1(IUT,NRED1,MTV3,DOUT,PDAT)\n PARAMETER (IRX=41,JRX=41)\n REAL DOUT(IRX,JRX),PDAT(IRX,JRX,MTV3)\n NRED1=NRED1+1\nc PRINT*,'READ1 COUNT = ',NRED1\n DO J=1,JRX\n DO I=1,IRX\n DOUT(I,J)=PDAT(I,J,NRED1)\n END DO\n END DO\n END SUBROUTINE READ1\n SUBROUTINE WRIT2(IMAX,JMAX,NWRT2,MTV,DIN,HDATA)\n REAL DIN(IMAX,JMAX),HDATA(IMAX,JMAX,MTV)\n NWRT2=NWRT2+1\nc PRINT*,'WRIT2 COUNT = ',NWRT2\nc call maxmin(DIN,IMAX*JMAX,1,1,1,'DIN in gbl')\n DO J=1,JMAX\n DO I=1,IMAX\n HDATA(I,J,NWRT2)=DIN(I,J)\n END DO\n END DO\n END SUBROUTINE WRIT2\n SUBROUTINE READ2(IMAX,JMAX,NRED2,MTV,DOUT,HDATA)\n REAL DOUT(IMAX,JMAX),HDATA(IMAX,JMAX,MTV)\n NRED2=NRED2+1\nc PRINT*,'READ2 COUNT = ',NRED2\n DO J=1,JMAX\n DO I=1,IMAX\n DOUT(I,J)=HDATA(I,J,NRED2)\n END DO\n END DO\n END SUBROUTINE READ2\n SUBROUTINE FIND_NEWCT(UD,VD)\n PARAMETER (IR=15,IT=24,IX=41,JX=41,ID=7,JD=7)\n DIMENSION TNMX(ID,JD),UD(IX,JX),VD(IX,JX)\n DIMENSION WTM(IR),R0(IT)\n \n\t! intent(in) :: ix,jx\n\t! intent(in) :: ud(ix,jx),vd(ix,jx)\n\t! intent(in) :: ir,it\n \t! intent(in) :: slon,slat,clon,clat\n\t! intent(inout) :: clon_new,clat_new\n\t! unused :: r0(it), xvect(it), yvect(it)\n\t! remove :: common/POSIT/,common/vect/\n\t! integer,parameter,local :: id=7,jd=7\n\t! local :: wnmx(id,jd),wtm(ir)\n\n COMMON /POSIT/CLON_NEW,CLAT_NEW,SLON,SLAT,CLON,CLAT,RAD\n COMMON /vect/R0,XVECT(IT),YVECT(IT)\nC\n PI=ASIN(1.)*2.\n RAD=PI/180.\nC\n XLAT = CLAT-3.\n XLON = CLON-3.\nc print *,'STARTING LAT, LON AT FIND NEW CENTER ',XLAT,XLON\nC\n DO I=1,ID\n DO J=1,JD\n TNMX(I,J) = 0.\n BLON = XLON + (I-1)\n BLAT = XLAT + (J-1)\nC\nC.. CALCULATE TANGENTIAL WIND EVERY 1 deg INTERVAL\nC.. 7*7 deg AROUND 1ST 1ST GUESS VORTEX CENTER\nC\n DO 10 JL=1,IR\n WTS= 0.\n DO 20 IL=1,IT\n DR = JL\n DD = (IL-1)*15*RAD\n DLON = DR*COS(DD)\n DLAT = DR*SIN(DD)\n TLON = BLON + DLON\n TLAT = BLAT + DLAT\nC.. INTERPOLATION U, V AT TLON,TLAT AND CLACULATE TANGENTIAL WIND\n IDX = IFIX(TLON) - SLON + 1\n IDY = IFIX(TLAT) - SLAT + 1\n DXX = TLON - IFIX(TLON)\n DYY = TLAT - IFIX(TLAT)\nC\n X1 = UD(IDX ,IDY+1)*DYY + UD(IDX ,IDY)*(1-DYY)\n X2 = UD(IDX+1,IDY+1)*DYY + UD(IDX+1,IDY)*(1-DYY)\n Y1 = UD(IDX+1,IDY )*DXX + UD(IDX,IDY )*(1-DXX)\n Y2 = UD(IDX+1,IDY+1)*DXX + UD(IDX,IDY+1)*(1-DXX)\n UT = (X1*(1-DXX)+X2*DXX + Y1*(1-DYY)+Y2*DYY)/2.\n IF(IL.EQ.0.OR.IL.EQ.13) UT = Y1\n IF(IL.EQ.7.OR.IL.EQ.19) UT = X1\nC\n X1 = VD(IDX ,IDY+1)*DYY + VD(IDX ,IDY)*(1-DYY)\n X2 = VD(IDX+1,IDY+1)*DYY + VD(IDX+1,IDY)*(1-DYY)\n Y1 = VD(IDX+1,IDY )*DXX + VD(IDX,IDY )*(1-DXX)\n Y2 = VD(IDX+1,IDY+1)*DXX + VD(IDX,IDY+1)*(1-DXX)\n VT = (X1*(1-DXX)+X2*DXX + Y1*(1-DYY)+Y2*DYY)/2.\n IF(IL.EQ.0.OR.IL.EQ.13) VT = Y1\n IF(IL.EQ.7.OR.IL.EQ.19) VT = X1\nC.. TANGENTIAL WIND\n WT = -SIN(DD)*UT + COS(DD)*VT\n WTS = WTS+WT\n20 CONTINUE\n WTM(JL) = WTS/24.\n10 CONTINUE\nC\nC Southern Hemisphere\n IF(CLAT_NEW.LT.0)THEN\n DO JL=1,IR\n WTM(JL)=-WTM(JL)\n END DO\n END IF\nC EnD SH\n\n TX = -10000000.\n DO KL = 1,IR\n IF(WTM(KL).GE.TX) THEN\n TX = WTM(KL)\n ENDIF\n ENDDO\nC\n TNMX(I,J) = TX\n ENDDO\n ENDDO\nC.. FIND NEW CENTER\n TTX = -1000000.\n DO I=1,ID\n DO J=1,JD\n IF(TNMX(I,J).GE.TTX) THEN\n TTX = TNMX(I,J)\n NIC = I\n NJC = J\n ENDIF\n ENDDO\n ENDDO\nC\n CLAT_NEW = XLAT + (NJC-1)\n CLON_NEW = XLON + (NIC-1)\nC\n print *,'NEW CENTER, I, J IS ',NIC,NJC\n print *,'NEW CENTER, LAT,LON IS ',CLAT_NEW,CLON_NEW\n print *,'MAX TAN. WIND AT NEW CENTER IS ',TTX\nC\n RETURN\n END SUBROUTINE FIND_NEWCT\n SUBROUTINE TWIND(UD,VD,TW)\nC\n PARAMETER (IX=41,JX=41,NF=11,IT=24,IR=120)\n DIMENSION UD(IX,JX),VD(IX,JX),TW(IT,IR),R0(IT)\n COMMON /POSIT/CLON_NEW,CLAT_NEW,SLON,SLAT,CLON,CLAT,RAD\n COMMON /vect/R0,XVECT(IT),YVECT(IT)\nc COMMON /CT/SLON,SLAT,CLON,CLAT,RAD\nc COMMON /GA/CLON_NEW,CLAT_NEW,R0\nC\n DO J=1,IR\n DO I=1,IT\nC.. DETERMINE LAT, LON AREOUND CIRCLE\n DR = 0.1*J\n DD = (I-1)*15.*RAD\n DLON = DR*COS(DD)\n DLAT = DR*SIN(DD)\n TLON = CLON_NEW + DLON\n TLAT = CLAT_NEW + DLAT\nC.. INTERPOLATION U, V AT TLON,TLAT AND CLACULATE TANGENTIAL WIND\n IDX = IFIX(TLON) - SLON + 1\n IDY = IFIX(TLAT) - SLAT + 1\n DXX = TLON - IFIX(TLON)\n DYY = TLAT - IFIX(TLAT)\nC\n X1 = UD(IDX ,IDY+1)*DYY + UD(IDX ,IDY)*(1-DYY)\n X2 = UD(IDX+1,IDY+1)*DYY + UD(IDX+1,IDY)*(1-DYY)\n Y1 = UD(IDX+1,IDY )*DXX + UD(IDX,IDY )*(1-DXX)\n Y2 = UD(IDX+1,IDY+1)*DXX + UD(IDX,IDY+1)*(1-DXX)\n UT = (X1*(1-DXX)+X2*DXX + Y1*(1-DYY)+Y2*DYY)/2.\n IF(I.EQ.0.OR.I.EQ.13) UT = Y1\n IF(I.EQ.7.OR.I.EQ.19) UT = X1\nC\n X1 = VD(IDX ,IDY+1)*DYY + VD(IDX ,IDY)*(1-DYY)\n X2 = VD(IDX+1,IDY+1)*DYY + VD(IDX+1,IDY)*(1-DYY)\n Y1 = VD(IDX+1,IDY )*DXX + VD(IDX,IDY )*(1-DXX)\n Y2 = VD(IDX+1,IDY+1)*DXX + VD(IDX,IDY+1)*(1-DXX)\n VT = (X1*(1-DXX)+X2*DXX + Y1*(1-DYY)+Y2*DYY)/2.\n IF(I.EQ.0.OR.I.EQ.13) VT = Y1\n IF(I.EQ.7.OR.I.EQ.19) VT = X1\nC.. TANGENTIAL WIND\n TW(I,J) = -SIN(DD)*UT + COS(DD)*VT\nC\n ENDDO\n ENDDO\nC SH\n IF(CLAT_NEW.LT.0)THEN\n DO J=1,IR\n DO I=1,IT\n TW(I,J)=-TW(I,J)\n ENDDO\n ENDDO\n END IF\nC End SH\nC\n RETURN\n END SUBROUTINE TWIND\n SUBROUTINE STRT_PT(RMX,TW,RFAVG)\nC\n PARAMETER (IX=41,JX=41,NF=11,IT=24,IR=120)\n DIMENSION TW(IT,IR),TWM(IR),TMXX(IT),RMX(IT)\n REAL JMX\nC\n DO I=1,IR\n TWM(I) = 0.\n ENDDO\nC\nC.. CALCULATE MEAN TANGENTIAL WIND\nC\n DO 10 J=1,IR\n TM=0.\n DO 20 I=1,IT\n TM = TM + TW(I,J)\n20 CONTINUE\n TWM(J) = TM/24.\nc print *,'MEAN TANGENTIAL WIND ',J,TWM(J)\n10 CONTINUE\nC\nC.. FIND MAXIMUM TANGENTIAL WIND RADIUS\nC\n TMX=-100000000000.\n DO J=1,IR\n IF(TWM(J).GE.TMX) THEN\n TMX=TWM(J)\n JMX = J*0.1\n ENDIF\n ENDDO\nC\n print *,'MAXIMUM TANGENTIAL WIND RADIUS ',JMX\n JJ=IFIX(JMX*10.)\n print *,'MAXIMUM TANGENTIAL WIND SPEED ',TWM(JJ)\nC\n JXX = 15 * JMX\nc print *,'JXX, 15*JMX is ',JXX\nC\n ICK = 1\n CNT = 0.000004\nc print *,'CNT ',CNT\nC\n DO 30 K=JXX,IR-1\n IF(TWM(K).GE.6..OR.TWM(K).LT.3.) GO TO 30\n DXX = 10000.\n DV = TWM(K) - TWM(K+1)\n DVDR = DV/DXX\n IF(DVDR.LT.CNT) ICK = ICK+1\n IF(ICK.EQ.3) THEN\n RF=K*0.1\n GO TO 40\n ENDIF\n30 CONTINUE\nC\n40 CONTINUE\n IF(ICK.NE.3) THEN\n DO IK=JXX,120\n IF(TWM(IK).LE.3) THEN\n RF = IK*0.1\n ICK=3\n GO TO 50\n ENDIF\n ENDDO\n ENDIF\nC\n50 CONTINUE\n IF(ICK.NE.3) RF = 12.\nC\n RFAVG = RF\nc\nC.. CALCULATE Ra, Rb.. REF. KURIHARA ET AL. 1995\nC\n RA = IFIX((0.5 * JMX)*10.)/10.\n RB = IFIX((0.75 * JMX + 0.25 * RF)*10.)/10.\n IRA = IFIX(RA*10.+0.5)\n IRB = IFIX(RB*10.+0.5)\nC\nc print *,'Ra, Rb, Rf ', RA,RB,RF\nC\nC.. DETERMINE STARTING POINT FOR EVERY 24 DIRECTION\nC\n DO I=1,IT\n TMXX(I) = -100000000.\n DO J=1,IR\n IF(TW(I,J).GE.TMXX(I)) THEN\n TMXX(I) = TW(I,J)\n RMX(I) = J*0.1*1.1\n ENDIF\n ENDDO\n ENDDO\nC\nc DO I=1,IT\nc print *,'I, MX TANGENTIAL WIND RADIUS ',I,RMX(I),TMXX(I)\nc ENDDO\nC\n DO I=1,IT\n IF (RMX(I).GT.RB.OR.RMX(I).LT.RA) THEN\n TMX = -10000000.\n DO KK=IRA,IRB\n IF(TW(I,KK).GE.TMX) RM = KK * 0.1 * 1.1\n ENDDO\n MR = IFIX(RM*10. + 0.5)\n ICL=0\n DO LL = MR,IRB\n IF(TW(I,LL).LT.0.) ICL=ICL+1\n ENDDO\n IF(ICL.EQ.0) RMX(I) = RM*1.1\n ENDIF\n ENDDO\nC\nc DO I=1,IT\nc print *,'I, RST ',I,RMX(I)\nc ENDDO\nC\n RETURN\n END SUBROUTINE STRT_PT\n SUBROUTINE FILTER(RS,TW,RF,RFAVG)\n PARAMETER (IX=41,JX=41,IT=24,IR=120)\nC\n DIMENSION RS(IT),TW(IT,IR),RF(IT),R0(IT),IST(IT)\n COMMON /vect/R0,XVECT(IT),YVECT(IT)\nc COMMON /GA/CLON_NEW,CLAT_NEW,R0\nC\n ICK = 1\n CNT = 0.000004\nc print *,'CNT ',CNT\nC\n DO I=1,IT\n IST(I) = IFIX(RS(I)*10)\nc print *,'STARTING POINT ',I,IST(I)\n ENDDO\nC\n DO 100 I=1,IT\n IS = IST(I)\nC\n DO 30 K=IS,IR-1\n IF(TW(I,K).GE.6..OR.TW(I,K).LT.3.) GO TO 30\n DXX = 10000.\n DV = TW(I,K) - TW(I,K+1)\n DVDR = DV/DXX\n IF(DVDR.LT.CNT) THEN\n ICK = ICK+1\n ENDIF\n IF(ICK.EQ.3) THEN\n RF(I)=K*0.1 + 0.0000001\nc print *,'1st Catagory ',I\n GO TO 100\n ENDIF\n30 CONTINUE\nC\n40 CONTINUE\n DO IK=IS,IR\n IF(TW(I,IK).LE.3) THEN\n RF(I) = IK*0.1 + 0.00000001\nc print *,'2nd Catagory ',I\n GO TO 100\n ENDIF\n ENDDO\nC\n50 CONTINUE\nc print *,'3rd Catagory ',I\n RF(I) = 12.\n100 CONTINUE\nC\nc RMAX=0.\n DO I=1,IT\n R0(I) = 1.25 * RF(I)\n!! NEW\n IF(R0(I).LT.2.0)R0(I)=2.0\nc IF(RMAX.LT.R0(I))RMAX=R0(I)\nc print *,'R0,Rf AT EACH DIRECTION ',I,R0(I),RF(I)\n ENDDO\nC test for circular domain\nc DO I=1,IT\nc R0(I)=RMAX\ncc R0(I) = RFAVG*1.25\nc print *,'R0,Rf AT EACH DIRECTION ',I,R0(I),RF(I)\nc ENDDO\nC\n RETURN\n END SUBROUTINE FILTER\n SUBROUTINE GMOVE(KST,KSTM,\n 1\t\t KMAX,IGU,JGU,MTV,GLON,GLAT,HDATA,PSLB,ZDATG,\n 1 IX,JX,ALON,ALAT,DM1,\n 2\t\t IB,ING,JNG,MDX,MDY,AMDX,AMDY, IV,IS1,IFLAG)\n\n use m_die,only : die\n use m_vtxgrid, only: vtxgrid_lonModulo\n! (index,count) of all storm grids\n integer,intent(in) :: KST,KSTM\t! they should be removed later\n \t\t\t\t\t! along with ZDATG/T1/PSLB and\n\t\t\t\t\t! SPL2SP().\n\n! grid attributes of the background state\n integer,intent(in) :: KMAX,IGU,JGU,MTV\n real,dimension(IGU,JGU),intent(in) :: GLON,GLAT\n REAL,dimension(IGU,JGU,MTV),intent(inout) :: HDATA\n REAL,dimension(IGU,JGU),intent(inout) :: PSLB\n REAL,dimension(IGU,JGU),intent(in) :: ZDATG\n\n integer,intent(in) :: IX,JX\n real,intent(in) :: ALAT(JX),ALON(IX)\n real,intent(in) :: DM1(IX,JX)\n\n! grid mapping information for a given storm grid\n integer,intent(in) :: IB\n integer,dimension(IB),intent(in) :: ING,JNG\n integer,intent(in) :: MDX,MDY\n real,intent(in) :: AMDX,AMDY\n\n \t! Additional control flags\n integer,intent(in) :: IV,IS1,IFLAG\n\n! Local variables\n DIMENSION DMM(IX,JX),DATG(IGU,JGU),DDAT(IGU,JGU)\n DIMENSION T1(IGU,JGU),PSL(IGU,JGU)\n\n COMMON /HDAT3/NWRT2,NRED2\t! pointers of HDATA's put() and get().\n\n DIMENSION DATG2(IGU,JGU)\n\n real:: HLO,HLA\n integer,parameter:: RK=kind(HLO)\n\nC\nC.. SETTING BASIC VARIABLES FOR INTERPOLATING GAUSSIAN GRID\nC\n!!\tprint'(1x,a,8i6)','GMOVE(): ',\n!! &\t\tKST,IV,IS1,IFLAG,NRED2+1,NWRT2+1\n\n ISE = IS1\n DO I=1,IX\n DO J=1,JX\n DMM(I,J) = DM1(I,J)\n ENDDO\n ENDDO\nC\nC.. INTERPOLATE TO GAUSSIAN GRID\nC\n CALL READ2(IGU,JGU,NRED2,MTV,DATG,HDATA)\n \t!!?? DATG(:,:)=HDATA(:,:,NRED2++)\nc\n DO I=1,IGU\n DO J=1,JGU\n DATG2(I,J)=DATG(I,J)\n DDAT(I,J)=0.\n ENDDO\n ENDDO\nC\n RDIST2=AMDX*AMDX+AMDY*AMDY\n IF(RDIST2.GT.0.02)THEN\ncc test\n DO I = 1,IB\n IW = ING(I)\n JW = JNG(I)\n\nc DO IW = 1, IGU\nc DO JW = 1, JGU\n HLA = GLAT(IW,JW)\n\n ! Bi-linearly interpolate a field DMM defined on grid (ALON,ALAT),\n ! to scattered locations (HLO,HLA) of DATG on grid (GLON,GLAT).\n\n ! First, if HLO is out of the range of ALON(1:IX), adjust it to one\n ! of its periodic (n*360, for n=...,-3,-2,-1,0,1,2,3,...) values,\n ! such that it falls inside the range [ALON(1), ALON(1)+360.).\n\n HLO = GLON(IW,JW)\n ! This is, HLO=ALON(1)+modulo(HLO-ALON(1),360.). Condition\n ! HLO>ALON(IX) is used instead of HLO>=ALON(1)+360., because there\n ! is a possibility of HLO, being out of the range [ALON(1),ALON(IX)].\n if(HLOALON(IX)) HLO=vtxgrid_lonModulo(HLO,reflon=ALON(1))\n\nC\n LX=-2\n LY=-2\n DO II=1,IX-1\n IF( (II==1.and.HLO==ALON(II)) .or.\n & (HLO.GT.ALON(II).and.HLO.LE.ALON(II+1)) )THEN\n! IF( (HLO.GT.ALON(II).and.HLO.LE.ALON(II+1)) )THEN\n LX=II\n LY=-1\n DO JJ=1,JX-1\n IF( (JJ==1.and.HLA==ALAT(JJ)) .or.\n & (HLA.GT.ALAT(JJ).and.HLA.LE.ALAT(JJ+1)) )THEN\n! IF( (HLA.GT.ALAT(JJ).and.HLA.LE.ALAT(JJ+1)) )THEN\n LX=II\n LY=JJ\n\n DXX = HLO-ALON(LX)\n DYY = HLA-ALAT(LY)\nC\n X1 = DMM(LX ,LY+1)*DYY + DMM(LX ,LY )*(1-DYY)\n X2 = DMM(LX+1,LY+1)*DYY + DMM(LX+1,LY )*(1-DYY)\n Y1 = DMM(LX+1,LY )*DXX + DMM(LX ,LY )*(1-DXX)\n Y2 = DMM(LX+1,LY+1)*DXX + DMM(LX ,LY+1)*(1-DXX)\n DATG(IW,JW)=(X1*(1-DXX)+X2*DXX + Y1*(1-DYY)+Y2*DYY)/2.\n\n IF(ISE.GE.2) DDAT(IW,JW)=DATG2(IW,JW)-DATG(IW,JW)\n GO TO 555\n\n END IF\n END DO\n END IF\n END DO\n if(LX<0.or.LY<0) then\n \twrite(6,'(a,2i4 )') 'GMOVE() >>> ERROR <<< unlocated LHS (H) grid point, IW,JW =',IW,JW\n \twrite(6,'(a,2i4 )') 'GMOVE() >>> ERROR <<< indexed RHS (A) location at, LX,LY =',LX,LY\n \twrite(6,'(a,3f8.2)') 'GMOVE() >>> ERROR <<< HLO, ALON(1), ALON(IX) =',HLO,ALON(1),ALON(IX)\n \twrite(6,'(a,3f8.2)') 'GMOVE() >>> ERROR <<< HLA, ALAT(1), ALAT(JX) =',HLA,ALAT(1),ALAT(JX)\n call die(\"GMOVE()\")\n endif\n 555 CONTINUE\nc ENDDO\nc ENDDO\n ENDDO\n END IF\nc end test\n\n IF(ISE.EQ.1) THEN\nc\nc READ(70) PSL\n PSL=PSLB\n\n DO I = 1,IB\n IW = ING(I)\n JW = JNG(I)\n DDAT(IW,JW)=PSL(IW,JW)-DATG(IW,JW)\n PSL(IW,JW)=DATG(IW,JW)\n END DO\nc\nc Move vortex\n\ncc DO I = 1,IB\ncc IW = ING(I)\ncc JW = JNG(I)\ncc IWX=IW+MDX\ncc JWY=JW+MDY\ncc IF(IWX.GT.IGU)IWX=IWX-IGU\ncc IF(IWX.LT.1)IWX=IWX+IGU\nCQLIUC\ncc PSL(IWX,JWY) = PSL(IWX,JWY)+DDAT(IW,JW)\ncc ENDDO\n\n CALL MOVETX(IGU,JGU,GLON,GLAT,PSL,DDAT,\n & IB,ING,JNG,MDX,MDY,AMDX,AMDY)\n\n PSLB = PSL\n\n!!! CALL WRIT2(IGU,JGU,NWRT2,MTV,PSL,HDATA)\n\tNWRT2=NWRT2+1\nc\n ELSEIF(ISE.EQ.2) THEN\ncyc REWIND 36\ncyc READ(36) PSL\n PSL = PSLB\n IF(IFLAG.EQ.1)THEN\n DO I=1,IGU\n DO J=1,JGU\n T1(I,J) = DATG2(I,J)\n ENDDO\n ENDDO\n ELSE\n DO I=1,IGU\n DO J=1,JGU\n T1(I,J) = DATG(I,J)\n ENDDO\n ENDDO\n END IF\n IF(KST.EQ.KSTM)THEN\n CALL SLP2SP(IGU,JGU,ZDATG,KUNIT,T1,PSL)\n!!\t print*,'PSL(GMOVE/0) = ',exp(minval(PSL)),\n!! &\t\t\t\t exp(maxval(PSL)),NWRT2\n\t NWRT2=NWRT2-1\t\t! backup 1 record for PSL output\n CALL WRIT2(IGU,JGU,NWRT2,MTV,PSL,HDATA)\n!!\t print*,'PSL(GMOVE/1) = ',exp(minval(HDATA(:,:,2))),\n!! &\t\t\t\t exp(maxval(HDATA(:,:,2)))\n END IF\n END IF\n\nc temperature field\nc qliu\n\n IF(ISE.GE.2.and.ISE.LE.(KMAX+1))then\n IF(IFLAG.EQ.1)THEN\ncold IF(KST.EQ.KSTM) THEN\ncql READ(20)SKIP2\ncold NCNT2 = NCNT2 + 1\ncold WRITE(KUNIT)(SKIP2(NW,NCNT2),NW=1,MAXWV2)\ncold END IF\n CALL WRIT2(IGU,JGU,NWRT2,MTV,DATG2,HDATA)\n ELSE\n\nc Move vortex\ncc DO I = 1,IB\ncc IW = ING(I)\ncc JW = JNG(I)\ncc IWX=IW+MDX\ncc JWY=JW+MDY\ncc IF(IWX.GT.IGU)IWX=IWX-IGU\ncc IF(IWX.LT.1)IWX=IWX+IGU\nCQLIUC\ncc DATG(IWX,JWY) = DATG(IWX,JWY)+DDAT(IW,JW)\ncc ENDDO\n\n CALL MOVETX(IGU,JGU,GLON,GLAT,DATG,DDAT,\n & IB,ING,JNG,MDX,MDY,AMDX,AMDY)\n\ncnew IF(KST.EQ.KSTM) THEN\ncql READ(20)SKIP2\ncnew NCNT2 = NCNT2 + 1\ncnew CALL G2SPC(DATG)\ncnew END IF\n\n CALL WRIT2(IGU,JGU,NWRT2,MTV,DATG,HDATA)\n\n END IF\n END IF\nC\n IF(ISE.GT.(KMAX+1).and.ISE.LE.(3*KMAX+1))THEN\nc Move vortex\n\ncc DO I = 1,IB\ncc IW = ING(I)\ncc JW = JNG(I)\ncc IWX=IW+MDX\ncc JWY=JW+MDY\ncc IF(IWX.GT.IGU)IWX=IWX-IGU\ncc IF(IWX.LT.1)IWX=IWX+IGU\nCQLIUC\ncc DATG(IWX,JWY) = DATG(IWX,JWY)+DDAT(IW,JW)\ncc ENDDO\n\n CALL MOVETX(IGU,JGU,GLON,GLAT,DATG,DDAT,\n & IB,ING,JNG,MDX,MDY,AMDX,AMDY)\nC\ncnew IF(KST.EQ.KSTM) THEN\ncnew CALL G2SPC(DATG)\ncnew END IF\n\n CALL WRIT2(IGU,JGU,NWRT2,MTV,DATG,HDATA)\n\n ENDIF\n\n IF(ISE.GT.(3*KMAX+1))THEN\n IF(IFLAG.EQ.1)THEN\ncold IF(KST.EQ.KSTM) THEN\ncold CALL G2SPC(KUNIT,MWAVE,IGU,JGU,DATG2)\ncold END IF\n CALL WRIT2(IGU,JGU,NWRT2,MTV,DATG2,HDATA)\n ELSE\n\nc Move vortex\ncc DO I = 1,IB\ncc IW = ING(I)\ncc JW = JNG(I)\ncc IWX=IW+MDX\ncc JWY=JW+MDY\ncc IF(IWX.GT.IGU)IWX=IWX-IGU\ncc IF(IWX.LT.1)IWX=IWX+IGU\nCQLIUC\ncc DATG(IWX,JWY) = DATG(IWX,JWY)+DDAT(IW,JW)\ncc ENDDO\n\n CALL MOVETX(IGU,JGU,GLON,GLAT,DATG,DDAT,\n & IB,ING,JNG,MDX,MDY,AMDX,AMDY)\n\ncnew IF(KST.EQ.KSTM) THEN\ncnew CALL G2SPC(DATG)\ncnew END IF\n\n CALL WRIT2(IGU,JGU,NWRT2,MTV,DATG,HDATA)\n\n END IF\n ENDIF\n!!\t print*,'PSL(GMOVE/2) = ',exp(minval(HDATA(:,:,2))),\n!! &\t\t\t\t exp(maxval(HDATA(:,:,2))),NWRT2,ISE\n\nC\n RETURN\n END SUBROUTINE GMOVE\n SUBROUTINE SLP2SP(IGU,JGU,ZDATG,KUNIT,T1,PSL)\nc PARAMETER (IGU=384,JGU=190)\nC\n DIMENSION T1(IGU,JGU),PSL(IGU,JGU)\n DIMENSION ZDATG(IGU,JGU)\nc COMMON /TR/ZDATG,GLON,GLAT,ING,JNG,IB\nC\nC.. MAKE SFC PRESSURE FROM MSLP\nC\n G = 9.8\n R = 287.05\n GAMMA = 6.7*0.001\nC\n DO JH=1,JGU\n DO IH=1,IGU\n PMSL = ALOG(PSL(IH,JH))\n A = (GAMMA * ZDATG(IH,JH)) / T1(IH,JH)\n B = ALOG(1+A)\n C = (G*B)/(R*GAMMA)\n DD = PMSL - C\n D1 = EXP(DD)/1000.\nc IF (D1.LE.10.) PRINT*,'SP is Less than 100mb at ',IH,JH,D1\n PSL(IH,JH) = ALOG(D1)\n ENDDO\n ENDDO\nC\nC.. GAUSSIAN GRID TO SPECTRAL COEFFEICENT\nC\n!! call maxmin(psl,igu*jgu,1,1,1,'global SLP at SLP after int')\n!! CALL G2SPC(KUNIT,MWAVE,IGU,JGU,PSL)\n!!\tprint*,'PSL(SLP2SP) = ',exp(minval(PSL)),exp(maxval(PSL))\n\n!! call maxmin(t1,igu*jgu,1,1,1,'global T1 at SLP after int')\nc CALL G2SPC(KUNIT,T1)\nC\n RETURN\n END SUBROUTINE SLP2SP\n SUBROUTINE G2SPC(KUNIT,MWAVE,IMAX,JMAX,Q1)\nC\nc PARAMETER ( IMAX= 384,JMAX= 190 )\nC\n REAL Q1(IMAX,JMAX)\n\n REAL, ALLOCATABLE :: DN(:)\n REAL(4),ALLOCATABLE :: WORK_3(:)\n\n MAXWV2=(MWAVE+1)*(MWAVE+2)\n MAXWV22=MAXWV2+1\n\n ALLOCATE ( DN(MAXWV22) )\n ALLOCATE ( WORK_3(MAXWV2) )\nC\nc call maxmin(dn,MAXWV2,1,1,1,'surface pressure after making')\n\n!! print*,'specgrid(g2spc), grid_psfc=',sum(Q1)\n call SPTEZ(0,MWAVE,4,IMAX,JMAX,DN,Q1,-1)\n\n DO I=1,MAXWV2\n WORK_3(I)=DN(I)\n END DO\n WRITE(KUNIT) (WORK_3(NW),NW=1,MAXWV2)\n!! print*,'specgrid(g2spc), spec_psfc=',sum(work_3)\n\n DEALLOCATE (DN)\n DEALLOCATE (WORK_3)\n\n RETURN\n END SUBROUTINE G2SPC\n", "meta": {"hexsha": "58b8989e0f350174151b1d638c1014cc8db6e064", "size": 25553, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/Applications/NCEP_Etc/NCEP_vtxreloc/mv_nvortex.f", "max_stars_repo_name": "GEOS-ESM/GEOSadas", "max_stars_repo_head_hexsha": "8e3665af71eb37c48573c65ed0e9daa5ca429535", "max_stars_repo_licenses": ["NASA-1.3", "Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-09-07T09:00:32.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-12T02:25:56.000Z", "max_issues_repo_path": "src/Applications/NCEP_Etc/NCEP_vtxreloc/mv_nvortex.f", "max_issues_repo_name": "GEOS-ESM/GEOSadas", "max_issues_repo_head_hexsha": "8e3665af71eb37c48573c65ed0e9daa5ca429535", "max_issues_repo_licenses": ["NASA-1.3", "Apache-2.0"], "max_issues_count": 81, "max_issues_repo_issues_event_min_datetime": "2019-07-05T19:28:50.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-04T19:37:47.000Z", "max_forks_repo_path": "src/Applications/NCEP_Etc/NCEP_vtxreloc/mv_nvortex.f", "max_forks_repo_name": "GEOS-ESM/GEOSadas", "max_forks_repo_head_hexsha": "8e3665af71eb37c48573c65ed0e9daa5ca429535", "max_forks_repo_licenses": ["NASA-1.3", "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.181352459, "max_line_length": 110, "alphanum_fraction": 0.5345751967, "num_tokens": 10574, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995482, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6810502044308091}} {"text": "PROGRAM TestInterpMat \n\nUSE dspline\n\nIMPLICIT NONE\n\nINTEGER :: m,n,j,k,jmin,jmax,jd,r,ir,nc,kloc \nDOUBLE PRECISION, ALLOCATABLE, DIMENSION(:) :: u,p,tinterp,ui,upi \nDOUBLE PRECISION, DIMENSION(:,:), ALLOCATABLE :: umat,upmat \nDOUBLE PRECISION :: dt,t,tnow,uev,upev,utrue,uptrue,frac,s,erloc,uermax,upermax,tloc \n\nn=500\ntnow=17.137d0\ndt=tnow/DBLE(n)\n\nr=2157\nALLOCATE(tinterp(r),ui(r),upi(r))\n!\nDO m=2,12,2\n ALLOCATE(p(0:m))\n DO j=0,m\n CALL RANDOM_NUMBER(p(j))\n p(j)=-1.d0+2.d0*p(j)\n END DO \n PRINT *,m\n!\n! choose a bunch of points in 3 time steps\n!\n DO kloc=0,314,314\n!\n tloc=-dt*DBLE(kloc)\n!\n DO ir=1,r\n CALL RANDOM_NUMBER(frac)\n tinterp(ir)=tloc-3.d0*dt*frac \n END DO\n CALL InterpMat(r,tinterp,dt,m,jmax,jmin,umat,upmat)\n!\n! Create data - here we assume that the polynomial is centered at 0\n!\n nc=jmax-jmin+1\n ALLOCATE(u(nc)) \n DO k=1,nc \n s=dt*DBLE(jmin+k-1)-tloc\n u(k)=p(m)\n DO jd=m-1,0,-1\n u(k)=s*u(k)+p(jd)\n END DO \n END DO\n!\n! DO ir=1,r\n! DO k=1,nc\n! PRINT *,ir,k,umat(ir,k),upmat(ir,k)\n! END DO\n! END DO \n CALL dgemv('N',r,nc,1.d0,umat,r,u,1,0.d0,ui,1)\n CALL dgemv('N',r,nc,1.d0,upmat,r,u,1,0.d0,upi,1)\n!\n uermax=0.d0\n upermax=0.d0 \n DO ir=1,r \n s=tinterp(ir)-tloc\n utrue=p(m)\n uptrue=DBLE(m)*p(m)\n DO jd=m-1,1,-1 \n utrue=s*utrue+p(jd)\n uptrue=s*uptrue+DBLE(jd)*p(jd)\n END DO\n utrue=s*utrue+p(0)\n erloc=ABS(ui(ir)-utrue)\n IF (erloc > uermax) THEN\n uermax=erloc\n END IF \n erloc=ABS(upi(ir)-uptrue)\n IF (erloc > upermax) THEN\n upermax=erloc\n END IF\n END DO\n!\n PRINT *,kloc,uermax,upermax \n DEALLOCATE(u,umat,upmat)\n!\n END DO \n!\n DEALLOCATE(p)\nEND DO\n\nDEALLOCATE(tinterp,ui,upi) \n\nEND PROGRAM TestInterpMat \n\n \n \n \n", "meta": {"hexsha": "f4a54767034605c4cf58e0af7f3859ca333b97d3", "size": 1752, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "timedomainwaveeqn/timeinterp/TestInterpMat.f90", "max_stars_repo_name": "ahbarnett/BIE3D", "max_stars_repo_head_hexsha": "12f35cecc97d6a106540e54a2a875b66ea6eebc7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2018-12-06T03:34:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-30T01:40:08.000Z", "max_issues_repo_path": "timedomainwaveeqn/timeinterp/TestInterpMat.f90", "max_issues_repo_name": "ahbarnett/BIE3D", "max_issues_repo_head_hexsha": "12f35cecc97d6a106540e54a2a875b66ea6eebc7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "timedomainwaveeqn/timeinterp/TestInterpMat.f90", "max_forks_repo_name": "ahbarnett/BIE3D", "max_forks_repo_head_hexsha": "12f35cecc97d6a106540e54a2a875b66ea6eebc7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2019-03-03T22:57:27.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-08T19:56:33.000Z", "avg_line_length": 18.4421052632, "max_line_length": 87, "alphanum_fraction": 0.6124429224, "num_tokens": 748, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095294, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.6809724875046468}} {"text": "!# Program to find standard deviation\r\n!\r\n! Authour: Ramsha Javed\r\n!\r\n!\r\nPROGRAM ste_dev\r\nIMPLICIT NONE\r\n\r\nINTEGER:: steps,ndim\r\nREAL*8,ALLOCATABLE::mean(:),stdev(:)\r\n\r\nndim=2\r\nOPEN(1,file=\"COLVAR\")\r\n\r\nALLOCATE(mean(ndim))\r\nALLOCATE(stdev(ndim))\r\n\r\nCALL get_steps(1,steps)\r\n\r\nCALL cal_mean(steps,mean,1,ndim)\r\n\r\nCALL standard_dev(1,steps,stdev,mean,ndim)\r\n\r\nDEALLOCATE(mean,stdev)\r\n\r\nEND PROGRAM\r\n\r\nSUBROUTINE get_steps(file_number,steps)\r\nIMPLICIT NONE\r\n\r\nINTEGER :: file_number, steps, ios\r\n\r\nsteps=0\r\nDO\r\n READ(file_number,*,iostat=ios)\r\n IF(ios.NE.0)EXIT\r\n steps=steps+1\r\nEND DO\r\nREWIND(file_number)\r\nEND SUBROUTINE get_steps\r\n\r\nSUBROUTINE cal_mean(steps,mean,file_number,ndim)\r\nIMPLICIT NONE\r\n\r\nINTEGER::steps,file_number,i,ndim\r\nREAL*8::mean(ndim)\r\nREAL*8:: dummy,cv(ndim)\r\n\r\nmean(1:ndim)=0.d0\r\n\r\nDO i=1,steps\r\n READ(file_number,*) dummy,cv(1:ndim)\r\n mean(1:ndim)=mean(1:ndim)+cv(1:ndim)\r\nEND DO\r\n\r\nREWIND(file_number)\r\nmean(1:ndim)=mean(1:ndim)/steps\r\nPRINT*,mean(1:ndim)\r\n\r\nEND SUBROUTINE\r\n\r\nSUBROUTINE standard_dev(file_number,steps,stdev,mean,ndim)\r\nIMPLICIT NONE\r\n\r\nINTEGER:: i,file_number,steps,ndim\r\nREAL*8:: stdev(ndim),mean(ndim)\r\nREAL*8::cv(ndim),dummy\r\n\r\nstdev(1:ndim)=0.d0\r\nDO i=1,steps\r\n READ(file_number,*) dummy,cv(1:ndim)\r\n stdev(1:ndim)=stdev(1:ndim)+(cv(1:ndim)-mean(1:ndim))**2\r\nEND DO\r\nstdev(1:ndim)=dsqrt(stdev(1:ndim)/steps)\r\nPRINT*,stdev(1:ndim)\r\nEND SUBROUTINE\r\n", "meta": {"hexsha": "bf0c272438a5e27b748a638c07e9da1e14eeb8cc", "size": 1393, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ANALYSIS_SCRIPTS/metad_standard_dev.f90", "max_stars_repo_name": "NNairIITK/BASH_SCRIPTS", "max_stars_repo_head_hexsha": "93a84bc2c7d562e3cc3bfec0c77f7298b475bef5", "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": "ANALYSIS_SCRIPTS/metad_standard_dev.f90", "max_issues_repo_name": "NNairIITK/BASH_SCRIPTS", "max_issues_repo_head_hexsha": "93a84bc2c7d562e3cc3bfec0c77f7298b475bef5", "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": "ANALYSIS_SCRIPTS/metad_standard_dev.f90", "max_forks_repo_name": "NNairIITK/BASH_SCRIPTS", "max_forks_repo_head_hexsha": "93a84bc2c7d562e3cc3bfec0c77f7298b475bef5", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-05-08T10:55:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-03T21:07:02.000Z", "avg_line_length": 18.0909090909, "max_line_length": 59, "alphanum_fraction": 0.7056712132, "num_tokens": 486, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146780175245, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.6809724835911056}} {"text": "module tridiag\n\nuse iso_c_binding, only: c_double, c_int\n\nimplicit none\n\ncontains\n\n! The expression bind(c) tells the compiler to\n! make the naming convention in the object file\n! match the naming convention here.\n! This will be a subroutine since it does not\n! return any values.\nsubroutine ftridiag(a, b, c, x, n) bind(c)\n \n! Here we declare the types for the inputs.\n! Thisis where we use the c_double and c_int types.\n! The 'dimension' statement tells the compiler that\n! the argument is an array of the given shape.\n integer(c_int), intent(in) :: n\n real(c_double),dimension(n),intent(in) :: b\n real(c_double),dimension(n),intent(inout) :: x\n real(c_double),dimension(n-1),intent(in) :: a\n real(c_double),dimension(n-1),intent(inout) :: c\n \n! Two temporary varaibles.\n! 'm' is a temporary value.\n! 'i' is the index for the loops.\n real(c_double) m\n integer i\n \n! Here is the actual computation:\n c(1) = c(1) / b(1)\n x(1) = x(1) / b(1)\n! This is the syntax for a 'for' loop in Fortran.\n! Indexing for arrays in fortran starts at 1\n! instead of starting at 0 like it does in Python.\n! Arrays are accessed using parentheses\n! instead of brackets.\n do i = 1,n-2\n m = 1.0D0 / (b(i+1) - a(i) * c(i))\n c(i+1) = c(i+1) * m\n x(i+1) = x(i+1) - a(i) * x(i)\n x(i+1) = x(i+1) * m\n! Note that you have to explicitly end the loop.\n enddo\n x(n) = (x(n) - a(n-1) * x(n-1)) / (b(n) - a(n-1) * c(n-1))\n do i = n-1,1,-1\n x(i) = x(i) - c(i) * x(i+1)\n enddo\n! You must also explicitly end the function or subroutine.\nend subroutine ftridiag\n\nend module\n", "meta": {"hexsha": "6f270ffa9d57bc040335353b83011e326e55b703", "size": 1652, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Python/cython_wrapping/ftridiag/ftridiag.f90", "max_stars_repo_name": "jessicaleete/numerical_computing", "max_stars_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2016-10-18T19:54:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-09T20:12:38.000Z", "max_issues_repo_path": "Python/cython_wrapping/ftridiag/ftridiag.f90", "max_issues_repo_name": "jessicaleete/numerical_computing", "max_issues_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Python/cython_wrapping/ftridiag/ftridiag.f90", "max_forks_repo_name": "jessicaleete/numerical_computing", "max_forks_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-14T16:07:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-20T09:05:06.000Z", "avg_line_length": 30.0363636364, "max_line_length": 62, "alphanum_fraction": 0.6210653753, "num_tokens": 540, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095294, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6809724829299155}} {"text": "!*==scnrm2.f90 processed by SPAG 7.51RB at 20:37 on 3 Mar 2022\n!> \\brief \\b SCNRM2\n!\n! =========== DOCUMENTATION ===========\n!\n! Online html documentation available at\n! http://www.netlib.org/lapack/explore-html/\n!\n! Definition:\n! ===========\n!\n! REAL FUNCTION SCNRM2(N,X,INCX)\n!\n! .. Scalar Arguments ..\n! INTEGER INCX,N\n! ..\n! .. Array Arguments ..\n! COMPLEX X(*)\n! ..\n!\n!\n!> \\par Purpose:\n! =============\n!>\n!> \\verbatim\n!>\n!> SCNRM2 returns the euclidean norm of a vector via the function\n!> name, so that\n!>\n!> SCNRM2 := sqrt( x**H*x )\n!> \\endverbatim\n!\n! Arguments:\n! ==========\n!\n!> \\param[in] N\n!> \\verbatim\n!> N is INTEGER\n!> number of elements in input vector(s)\n!> \\endverbatim\n!>\n!> \\param[in] X\n!> \\verbatim\n!> X is COMPLEX array, dimension (N)\n!> complex vector with N elements\n!> \\endverbatim\n!>\n!> \\param[in] INCX\n!> \\verbatim\n!> INCX is INTEGER\n!> storage spacing between elements of X\n!> \\endverbatim\n!\n! Authors:\n! ========\n!\n!> \\author Univ. of Tennessee\n!> \\author Univ. of California Berkeley\n!> \\author Univ. of Colorado Denver\n!> \\author NAG Ltd.\n!\n!> \\date November 2017\n!\n!> \\ingroup single_blas_level1\n!\n!> \\par Further Details:\n! =====================\n!>\n!> \\verbatim\n!>\n!> -- This version written on 25-October-1982.\n!> Modified on 14-October-1993 to inline the call to CLASSQ.\n!> Sven Hammarling, Nag Ltd.\n!> \\endverbatim\n!>\n! =====================================================================\n REAL FUNCTION SCNRM2(N,X,Incx)\n IMPLICIT NONE\n!*--SCNRM279\n!\n! -- Reference BLAS level1 routine (version 3.8.0) --\n! -- Reference BLAS is a software package provided by Univ. of Tennessee, --\n! -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n! November 2017\n!\n! .. Scalar Arguments ..\n INTEGER Incx , N\n! ..\n! .. Array Arguments ..\n COMPLEX X(*)\n! ..\n!\n! =====================================================================\n!\n! .. Parameters ..\n REAL ONE , ZERO\n PARAMETER (ONE=1.0E+0,ZERO=0.0E+0)\n! ..\n! .. Local Scalars ..\n REAL norm , scale , ssq , temp\n INTEGER ix\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC ABS , AIMAG , REAL , SQRT\n! ..\n IF ( N<1 .OR. Incx<1 ) THEN\n norm = ZERO\n ELSE\n scale = ZERO\n ssq = ONE\n! The following loop is equivalent to this call to the LAPACK\n! auxiliary routine:\n! CALL CLASSQ( N, X, INCX, SCALE, SSQ )\n!\n DO ix = 1 , 1 + (N-1)*Incx , Incx\n IF ( REAL(X(ix))/=ZERO ) THEN\n temp = ABS(REAL(X(ix)))\n IF ( scale Version: Experimental\n !>\n !> `diff` computes differences of arrays.\n !> ([Specification](../page/specs/forlab_linalg.html))\n interface diff\n pure module function diff_1_sp(x, n) result(result)\n real(sp), dimension(:), intent(in) :: x\n integer, intent(in), optional :: n\n real(sp), dimension(:), allocatable :: result\n end function diff_1_sp\n pure module function diff_2_sp(A, n, dim) result(result)\n real(sp), dimension(:, :), intent(in) :: A\n integer, intent(in), optional :: n, dim\n real(sp), dimension(:, :), allocatable :: result\n end function diff_2_sp\n pure module function diff_1_dp(x, n) result(result)\n real(dp), dimension(:), intent(in) :: x\n integer, intent(in), optional :: n\n real(dp), dimension(:), allocatable :: result\n end function diff_1_dp\n pure module function diff_2_dp(A, n, dim) result(result)\n real(dp), dimension(:, :), intent(in) :: A\n integer, intent(in), optional :: n, dim\n real(dp), dimension(:, :), allocatable :: result\n end function diff_2_dp\n pure module function diff_1_int8(x, n) result(result)\n integer(int8), dimension(:), intent(in) :: x\n integer, intent(in), optional :: n\n integer(int8), dimension(:), allocatable :: result\n end function diff_1_int8\n pure module function diff_2_int8(A, n, dim) result(result)\n integer(int8), dimension(:, :), intent(in) :: A\n integer, intent(in), optional :: n, dim\n integer(int8), dimension(:, :), allocatable :: result\n end function diff_2_int8\n pure module function diff_1_int16(x, n) result(result)\n integer(int16), dimension(:), intent(in) :: x\n integer, intent(in), optional :: n\n integer(int16), dimension(:), allocatable :: result\n end function diff_1_int16\n pure module function diff_2_int16(A, n, dim) result(result)\n integer(int16), dimension(:, :), intent(in) :: A\n integer, intent(in), optional :: n, dim\n integer(int16), dimension(:, :), allocatable :: result\n end function diff_2_int16\n pure module function diff_1_int32(x, n) result(result)\n integer(int32), dimension(:), intent(in) :: x\n integer, intent(in), optional :: n\n integer(int32), dimension(:), allocatable :: result\n end function diff_1_int32\n pure module function diff_2_int32(A, n, dim) result(result)\n integer(int32), dimension(:, :), intent(in) :: A\n integer, intent(in), optional :: n, dim\n integer(int32), dimension(:, :), allocatable :: result\n end function diff_2_int32\n pure module function diff_1_int64(x, n) result(result)\n integer(int64), dimension(:), intent(in) :: x\n integer, intent(in), optional :: n\n integer(int64), dimension(:), allocatable :: result\n end function diff_1_int64\n pure module function diff_2_int64(A, n, dim) result(result)\n integer(int64), dimension(:, :), intent(in) :: A\n integer, intent(in), optional :: n, dim\n integer(int64), dimension(:, :), allocatable :: result\n end function diff_2_int64\n end interface diff\n\n interface eig\n !! eig computes eigenvalues and eigenvectors of symmetric matrix using Jacobi algorithm.\n module subroutine eig_sp(A, V, d, itermax)\n real(sp), dimension(:, :), intent(in) :: A\n real(sp), dimension(:, :), allocatable, intent(out) :: V\n real(sp), dimension(:), allocatable, intent(out) :: d\n integer, intent(in), optional :: itermax\n end subroutine eig_sp\n module subroutine eig_dp(A, V, d, itermax)\n real(dp), dimension(:, :), intent(in) :: A\n real(dp), dimension(:, :), allocatable, intent(out) :: V\n real(dp), dimension(:), allocatable, intent(out) :: d\n integer, intent(in), optional :: itermax\n end subroutine eig_dp\n end interface eig\n\n interface eye\n module subroutine eye_sp(X)\n real(sp), intent(out) :: X(:, :)\n end subroutine eye_sp\n module subroutine eye_dp(X)\n real(dp), intent(out) :: X(:, :)\n end subroutine eye_dp\n end interface eye\n\n interface horzcat\n module function horzcat_r_1_sp(x1, x2) result(result)\n real(sp), dimension(:, :), allocatable :: result\n real(sp), dimension(:), intent(in) :: x1, x2\n end function horzcat_r_1_sp\n module function horzcat_r_2_sp(A1, A2) result(result)\n real(sp), dimension(:, :), allocatable :: result\n real(sp), dimension(:, :), intent(in) :: A1, A2\n end function horzcat_r_2_sp\n module function horzcat_r_21_sp(A1, x2) result(result)\n real(sp), dimension(:, :), allocatable :: result\n real(sp), dimension(:, :), intent(in) :: A1\n real(sp), dimension(:), intent(in) :: x2\n end function horzcat_r_21_sp\n module function horzcat_r_12_sp(x1, A2) result(result)\n real(sp), dimension(:, :), allocatable :: result\n real(sp), dimension(:), intent(in) :: x1\n real(sp), dimension(:, :), intent(in) :: A2\n end function horzcat_r_12_sp\n module function horzcat_r_1_dp(x1, x2) result(result)\n real(dp), dimension(:, :), allocatable :: result\n real(dp), dimension(:), intent(in) :: x1, x2\n end function horzcat_r_1_dp\n module function horzcat_r_2_dp(A1, A2) result(result)\n real(dp), dimension(:, :), allocatable :: result\n real(dp), dimension(:, :), intent(in) :: A1, A2\n end function horzcat_r_2_dp\n module function horzcat_r_21_dp(A1, x2) result(result)\n real(dp), dimension(:, :), allocatable :: result\n real(dp), dimension(:, :), intent(in) :: A1\n real(dp), dimension(:), intent(in) :: x2\n end function horzcat_r_21_dp\n module function horzcat_r_12_dp(x1, A2) result(result)\n real(dp), dimension(:, :), allocatable :: result\n real(dp), dimension(:), intent(in) :: x1\n real(dp), dimension(:, :), intent(in) :: A2\n end function horzcat_r_12_dp\n module function horzcat_c_1_sp(x1, x2) result(result)\n complex(sp), dimension(:, :), allocatable :: result\n complex(sp), dimension(:), intent(in) :: x1, x2\n end function horzcat_c_1_sp\n module function horzcat_c_2_sp(A1, A2) result(result)\n complex(sp), dimension(:, :), allocatable :: result\n complex(sp), dimension(:, :), intent(in) :: A1, A2\n end function horzcat_c_2_sp\n module function horzcat_c_21_sp(A1, x2) result(result)\n complex(sp), dimension(:, :), allocatable :: result\n complex(sp), dimension(:, :), intent(in) :: A1\n complex(sp), dimension(:), intent(in) :: x2\n end function horzcat_c_21_sp\n module function horzcat_c_12_sp(x1, A2) result(result)\n complex(sp), dimension(:, :), allocatable :: result\n complex(sp), dimension(:), intent(in) :: x1\n complex(sp), dimension(:, :), intent(in) :: A2\n end function horzcat_c_12_sp\n module function horzcat_c_1_dp(x1, x2) result(result)\n complex(dp), dimension(:, :), allocatable :: result\n complex(dp), dimension(:), intent(in) :: x1, x2\n end function horzcat_c_1_dp\n module function horzcat_c_2_dp(A1, A2) result(result)\n complex(dp), dimension(:, :), allocatable :: result\n complex(dp), dimension(:, :), intent(in) :: A1, A2\n end function horzcat_c_2_dp\n module function horzcat_c_21_dp(A1, x2) result(result)\n complex(dp), dimension(:, :), allocatable :: result\n complex(dp), dimension(:, :), intent(in) :: A1\n complex(dp), dimension(:), intent(in) :: x2\n end function horzcat_c_21_dp\n module function horzcat_c_12_dp(x1, A2) result(result)\n complex(dp), dimension(:, :), allocatable :: result\n complex(dp), dimension(:), intent(in) :: x1\n complex(dp), dimension(:, :), intent(in) :: A2\n end function horzcat_c_12_dp\n module function horzcat_i_1_int8(x1, x2) result(result)\n integer(int8), dimension(:, :), allocatable :: result\n integer(int8), dimension(:), intent(in) :: x1, x2\n end function horzcat_i_1_int8\n module function horzcat_i_2_int8(A1, A2) result(result)\n integer(int8), dimension(:, :), allocatable :: result\n integer(int8), dimension(:, :), intent(in) :: A1, A2\n end function horzcat_i_2_int8\n module function horzcat_i_21_int8(A1, x2) result(result)\n integer(int8), dimension(:, :), allocatable :: result\n integer(int8), dimension(:, :), intent(in) :: A1\n integer(int8), dimension(:), intent(in) :: x2\n end function horzcat_i_21_int8\n module function horzcat_i_12_int8(x1, A2) result(result)\n integer(int8), dimension(:, :), allocatable :: result\n integer(int8), dimension(:), intent(in) :: x1\n integer(int8), dimension(:, :), intent(in) :: A2\n end function horzcat_i_12_int8\n module function horzcat_i_1_int16(x1, x2) result(result)\n integer(int16), dimension(:, :), allocatable :: result\n integer(int16), dimension(:), intent(in) :: x1, x2\n end function horzcat_i_1_int16\n module function horzcat_i_2_int16(A1, A2) result(result)\n integer(int16), dimension(:, :), allocatable :: result\n integer(int16), dimension(:, :), intent(in) :: A1, A2\n end function horzcat_i_2_int16\n module function horzcat_i_21_int16(A1, x2) result(result)\n integer(int16), dimension(:, :), allocatable :: result\n integer(int16), dimension(:, :), intent(in) :: A1\n integer(int16), dimension(:), intent(in) :: x2\n end function horzcat_i_21_int16\n module function horzcat_i_12_int16(x1, A2) result(result)\n integer(int16), dimension(:, :), allocatable :: result\n integer(int16), dimension(:), intent(in) :: x1\n integer(int16), dimension(:, :), intent(in) :: A2\n end function horzcat_i_12_int16\n module function horzcat_i_1_int32(x1, x2) result(result)\n integer(int32), dimension(:, :), allocatable :: result\n integer(int32), dimension(:), intent(in) :: x1, x2\n end function horzcat_i_1_int32\n module function horzcat_i_2_int32(A1, A2) result(result)\n integer(int32), dimension(:, :), allocatable :: result\n integer(int32), dimension(:, :), intent(in) :: A1, A2\n end function horzcat_i_2_int32\n module function horzcat_i_21_int32(A1, x2) result(result)\n integer(int32), dimension(:, :), allocatable :: result\n integer(int32), dimension(:, :), intent(in) :: A1\n integer(int32), dimension(:), intent(in) :: x2\n end function horzcat_i_21_int32\n module function horzcat_i_12_int32(x1, A2) result(result)\n integer(int32), dimension(:, :), allocatable :: result\n integer(int32), dimension(:), intent(in) :: x1\n integer(int32), dimension(:, :), intent(in) :: A2\n end function horzcat_i_12_int32\n module function horzcat_i_1_int64(x1, x2) result(result)\n integer(int64), dimension(:, :), allocatable :: result\n integer(int64), dimension(:), intent(in) :: x1, x2\n end function horzcat_i_1_int64\n module function horzcat_i_2_int64(A1, A2) result(result)\n integer(int64), dimension(:, :), allocatable :: result\n integer(int64), dimension(:, :), intent(in) :: A1, A2\n end function horzcat_i_2_int64\n module function horzcat_i_21_int64(A1, x2) result(result)\n integer(int64), dimension(:, :), allocatable :: result\n integer(int64), dimension(:, :), intent(in) :: A1\n integer(int64), dimension(:), intent(in) :: x2\n end function horzcat_i_21_int64\n module function horzcat_i_12_int64(x1, A2) result(result)\n integer(int64), dimension(:, :), allocatable :: result\n integer(int64), dimension(:), intent(in) :: x1\n integer(int64), dimension(:, :), intent(in) :: A2\n end function horzcat_i_12_int64\n end interface horzcat\n interface vertcat\n module function vertcat_r_1_sp(x1, x2) result(result)\n real(sp), dimension(:, :), allocatable :: result\n real(sp), dimension(:), intent(in) :: x1, x2\n end function vertcat_r_1_sp\n module function vertcat_r_2_sp(A1, A2) result(result)\n real(sp), dimension(:, :), allocatable :: result\n real(sp), dimension(:, :), intent(in) :: A1, A2\n end function vertcat_r_2_sp\n module function vertcat_r_21_sp(A1, x2) result(result)\n real(sp), dimension(:, :), allocatable :: result\n real(sp), dimension(:, :), intent(in) :: A1\n real(sp), dimension(:), intent(in) :: x2\n end function vertcat_r_21_sp\n module function vertcat_r_12_sp(x1, A2) result(result)\n real(sp), dimension(:, :), allocatable :: result\n real(sp), dimension(:), intent(in) :: x1\n real(sp), dimension(:, :), intent(in) :: A2\n end function vertcat_r_12_sp\n module function vertcat_r_1_dp(x1, x2) result(result)\n real(dp), dimension(:, :), allocatable :: result\n real(dp), dimension(:), intent(in) :: x1, x2\n end function vertcat_r_1_dp\n module function vertcat_r_2_dp(A1, A2) result(result)\n real(dp), dimension(:, :), allocatable :: result\n real(dp), dimension(:, :), intent(in) :: A1, A2\n end function vertcat_r_2_dp\n module function vertcat_r_21_dp(A1, x2) result(result)\n real(dp), dimension(:, :), allocatable :: result\n real(dp), dimension(:, :), intent(in) :: A1\n real(dp), dimension(:), intent(in) :: x2\n end function vertcat_r_21_dp\n module function vertcat_r_12_dp(x1, A2) result(result)\n real(dp), dimension(:, :), allocatable :: result\n real(dp), dimension(:), intent(in) :: x1\n real(dp), dimension(:, :), intent(in) :: A2\n end function vertcat_r_12_dp\n module function vertcat_c_1_sp(x1, x2) result(result)\n complex(sp), dimension(:, :), allocatable :: result\n complex(sp), dimension(:), intent(in) :: x1, x2\n end function vertcat_c_1_sp\n module function vertcat_c_2_sp(A1, A2) result(result)\n complex(sp), dimension(:, :), allocatable :: result\n complex(sp), dimension(:, :), intent(in) :: A1, A2\n end function vertcat_c_2_sp\n module function vertcat_c_21_sp(A1, x2) result(result)\n complex(sp), dimension(:, :), allocatable :: result\n complex(sp), dimension(:, :), intent(in) :: A1\n complex(sp), dimension(:), intent(in) :: x2\n end function vertcat_c_21_sp\n module function vertcat_c_12_sp(x1, A2) result(result)\n complex(sp), dimension(:, :), allocatable :: result\n complex(sp), dimension(:), intent(in) :: x1\n complex(sp), dimension(:, :), intent(in) :: A2\n end function vertcat_c_12_sp\n module function vertcat_c_1_dp(x1, x2) result(result)\n complex(dp), dimension(:, :), allocatable :: result\n complex(dp), dimension(:), intent(in) :: x1, x2\n end function vertcat_c_1_dp\n module function vertcat_c_2_dp(A1, A2) result(result)\n complex(dp), dimension(:, :), allocatable :: result\n complex(dp), dimension(:, :), intent(in) :: A1, A2\n end function vertcat_c_2_dp\n module function vertcat_c_21_dp(A1, x2) result(result)\n complex(dp), dimension(:, :), allocatable :: result\n complex(dp), dimension(:, :), intent(in) :: A1\n complex(dp), dimension(:), intent(in) :: x2\n end function vertcat_c_21_dp\n module function vertcat_c_12_dp(x1, A2) result(result)\n complex(dp), dimension(:, :), allocatable :: result\n complex(dp), dimension(:), intent(in) :: x1\n complex(dp), dimension(:, :), intent(in) :: A2\n end function vertcat_c_12_dp\n module function vertcat_i_1_int8(x1, x2) result(result)\n integer(int8), dimension(:, :), allocatable :: result\n integer(int8), dimension(:), intent(in) :: x1, x2\n end function vertcat_i_1_int8\n module function vertcat_i_2_int8(A1, A2) result(result)\n integer(int8), dimension(:, :), allocatable :: result\n integer(int8), dimension(:, :), intent(in) :: A1, A2\n end function vertcat_i_2_int8\n module function vertcat_i_21_int8(A1, x2) result(result)\n integer(int8), dimension(:, :), allocatable :: result\n integer(int8), dimension(:, :), intent(in) :: A1\n integer(int8), dimension(:), intent(in) :: x2\n end function vertcat_i_21_int8\n module function vertcat_i_12_int8(x1, A2) result(result)\n integer(int8), dimension(:, :), allocatable :: result\n integer(int8), dimension(:), intent(in) :: x1\n integer(int8), dimension(:, :), intent(in) :: A2\n end function vertcat_i_12_int8\n module function vertcat_i_1_int16(x1, x2) result(result)\n integer(int16), dimension(:, :), allocatable :: result\n integer(int16), dimension(:), intent(in) :: x1, x2\n end function vertcat_i_1_int16\n module function vertcat_i_2_int16(A1, A2) result(result)\n integer(int16), dimension(:, :), allocatable :: result\n integer(int16), dimension(:, :), intent(in) :: A1, A2\n end function vertcat_i_2_int16\n module function vertcat_i_21_int16(A1, x2) result(result)\n integer(int16), dimension(:, :), allocatable :: result\n integer(int16), dimension(:, :), intent(in) :: A1\n integer(int16), dimension(:), intent(in) :: x2\n end function vertcat_i_21_int16\n module function vertcat_i_12_int16(x1, A2) result(result)\n integer(int16), dimension(:, :), allocatable :: result\n integer(int16), dimension(:), intent(in) :: x1\n integer(int16), dimension(:, :), intent(in) :: A2\n end function vertcat_i_12_int16\n module function vertcat_i_1_int32(x1, x2) result(result)\n integer(int32), dimension(:, :), allocatable :: result\n integer(int32), dimension(:), intent(in) :: x1, x2\n end function vertcat_i_1_int32\n module function vertcat_i_2_int32(A1, A2) result(result)\n integer(int32), dimension(:, :), allocatable :: result\n integer(int32), dimension(:, :), intent(in) :: A1, A2\n end function vertcat_i_2_int32\n module function vertcat_i_21_int32(A1, x2) result(result)\n integer(int32), dimension(:, :), allocatable :: result\n integer(int32), dimension(:, :), intent(in) :: A1\n integer(int32), dimension(:), intent(in) :: x2\n end function vertcat_i_21_int32\n module function vertcat_i_12_int32(x1, A2) result(result)\n integer(int32), dimension(:, :), allocatable :: result\n integer(int32), dimension(:), intent(in) :: x1\n integer(int32), dimension(:, :), intent(in) :: A2\n end function vertcat_i_12_int32\n module function vertcat_i_1_int64(x1, x2) result(result)\n integer(int64), dimension(:, :), allocatable :: result\n integer(int64), dimension(:), intent(in) :: x1, x2\n end function vertcat_i_1_int64\n module function vertcat_i_2_int64(A1, A2) result(result)\n integer(int64), dimension(:, :), allocatable :: result\n integer(int64), dimension(:, :), intent(in) :: A1, A2\n end function vertcat_i_2_int64\n module function vertcat_i_21_int64(A1, x2) result(result)\n integer(int64), dimension(:, :), allocatable :: result\n integer(int64), dimension(:, :), intent(in) :: A1\n integer(int64), dimension(:), intent(in) :: x2\n end function vertcat_i_21_int64\n module function vertcat_i_12_int64(x1, A2) result(result)\n integer(int64), dimension(:, :), allocatable :: result\n integer(int64), dimension(:), intent(in) :: x1\n integer(int64), dimension(:, :), intent(in) :: A2\n end function vertcat_i_12_int64\n end interface vertcat\n\n interface inv\n module function inv_rsp(A) result(inv)\n real(sp), dimension(:, :), intent(in) :: A\n real(sp), dimension(:, :), allocatable :: inv\n end function inv_rsp\n module function inv_rdp(A) result(inv)\n real(dp), dimension(:, :), intent(in) :: A\n real(dp), dimension(:, :), allocatable :: inv\n end function inv_rdp\n module function inv_csp(A) result(inv)\n complex(sp), dimension(:, :), intent(in) :: A\n complex(sp), dimension(:, :), allocatable :: inv\n end function inv_csp\n module function inv_cdp(A) result(inv)\n complex(dp), dimension(:, :), intent(in) :: A\n complex(dp), dimension(:, :), allocatable :: inv\n end function inv_cdp\n end interface inv\n\n interface is_square\n procedure :: is_square_rsp\n procedure :: is_square_rdp\n procedure :: is_square_csp\n procedure :: is_square_cdp\n end interface is_square\n\n interface is_symmetric\n procedure :: is_symmetric_rsp\n procedure :: is_symmetric_rdp\n procedure :: is_symmetric_csp\n procedure :: is_symmetric_cdp\n end interface is_symmetric\n\n interface linspace\n pure module subroutine linspace_sp(X, from, to)\n real(sp), intent(out) :: X(:)\n real(sp), intent(in) :: from, to\n end subroutine linspace_sp\n pure module subroutine linspace_dp(X, from, to)\n real(dp), intent(out) :: X(:)\n real(dp), intent(in) :: from, to\n end subroutine linspace_dp\n end interface linspace\n interface logspace\n pure module subroutine logspace_sp(X, from, to)\n real(sp), intent(out) :: X(:)\n real(sp), intent(in) :: from, to\n end subroutine logspace_sp\n pure module subroutine logspace_dp(X, from, to)\n real(dp), intent(out) :: X(:)\n real(dp), intent(in) :: from, to\n end subroutine logspace_dp\n end interface logspace\n\n interface lu\n !! lu computes the LU matrix factorization.\n module subroutine lu_sp(A, L, U)\n real(sp), dimension(:, :), intent(in) :: A\n real(sp), dimension(:, :), allocatable, intent(out) :: L, U\n end subroutine lu_sp\n module subroutine lu_dp(A, L, U)\n real(dp), dimension(:, :), intent(in) :: A\n real(dp), dimension(:, :), allocatable, intent(out) :: L, U\n end subroutine lu_dp\n end interface lu\n\n interface matpow\n !! Calculat matrix power\n module function matpow_sp(a, num) result(c)\n real(sp), dimension(:, :), intent(in) :: a\n real(sp), allocatable :: c(:, :)\n integer::num\n end function matpow_sp\n module function matpow_dp(a, num) result(c)\n real(dp), dimension(:, :), intent(in) :: a\n real(dp), allocatable :: c(:, :)\n integer::num\n end function matpow_dp\n end interface matpow\n\n interface norm\n !! norm computes vector and matrix norms.\n real(sp) module function norm1_sp(x, p)\n real(sp), dimension(:), intent(in) :: x\n real(sp), intent(in), optional :: p\n end function norm1_sp\n real(sp) module function norm2_sp(A, p)\n real(sp), dimension(:, :), intent(in) :: A\n real(sp), intent(in), optional :: p\n end function norm2_sp\n real(dp) module function norm1_dp(x, p)\n real(dp), dimension(:), intent(in) :: x\n real(dp), intent(in), optional :: p\n end function norm1_dp\n real(dp) module function norm2_dp(A, p)\n real(dp), dimension(:, :), intent(in) :: A\n real(dp), intent(in), optional :: p\n end function norm2_dp\n end interface norm\n\n interface operator(.i.)\n !! Calculate the inverse of a real matrix.\n procedure inv_rsp\n procedure inv_rdp\n procedure inv_csp\n procedure inv_cdp\n end interface operator(.i.)\n\n interface operator(.x.)\n procedure :: rmut_sp\n procedure :: rmut_dp\n procedure :: cmut_sp\n procedure :: cmut_dp\n procedure :: rcmut_sp\n procedure :: rcmut_dp\n procedure :: crmut_sp\n procedure :: crmut_dp\n end interface operator(.x.)\n\n !> Version: experimental\n !>\n !> Creates a rank-1 or rank-2 array filled ones.\n !> ([Specification](../page/specs/forlab_linalg.html#zerosones))\n interface ones\n procedure :: ones_1_default\n procedure :: ones_2_default\n end interface ones\n\n interface outer\n module function outer_int8(x, y)\n integer(int8), dimension(:, :), allocatable :: outer_int8\n integer(int8), dimension(:), intent(in) :: x, y\n end function\n module function outer_int16(x, y)\n integer(int16), dimension(:, :), allocatable :: outer_int16\n integer(int16), dimension(:), intent(in) :: x, y\n end function\n module function outer_int32(x, y)\n integer(int32), dimension(:, :), allocatable :: outer_int32\n integer(int32), dimension(:), intent(in) :: x, y\n end function\n module function outer_int64(x, y)\n integer(int64), dimension(:, :), allocatable :: outer_int64\n integer(int64), dimension(:), intent(in) :: x, y\n end function\n module function outer_sp(x, y)\n real(sp), dimension(:, :), allocatable :: outer_sp\n real(sp), dimension(:), intent(in) :: x, y\n end function\n module function outer_dp(x, y)\n real(dp), dimension(:, :), allocatable :: outer_dp\n real(dp), dimension(:), intent(in) :: x, y\n end function\n end interface outer\n\n interface qr\n module subroutine qr_sp(a, q, r, l)\n real(sp), intent(in)::a(:, :)\n real(sp), allocatable, intent(out) :: q(:, :), r(:, :)\n integer, optional::l\n end subroutine qr_sp\n module subroutine qr_dp(a, q, r, l)\n real(dp), intent(in)::a(:, :)\n real(dp), allocatable, intent(out) :: q(:, :), r(:, :)\n integer, optional::l\n end subroutine qr_dp\n end interface qr\n\n interface seq\n !! seq returns evenly spaced vector.\n module subroutine seq_sp(X, from, to, by)\n real(sp), dimension(:), allocatable, intent(out) :: X\n real(sp), intent(in) :: from, to\n real(sp), optional, intent(in) :: by\n end subroutine seq_sp\n module subroutine seq_dp(X, from, to, by)\n real(dp), dimension(:), allocatable, intent(out) :: X\n real(dp), intent(in) :: from, to\n real(dp), optional, intent(in) :: by\n end subroutine seq_dp\n module subroutine seq_int8(X, from, to, by)\n integer(int8), dimension(:), allocatable, intent(out) :: X\n integer(int8), intent(in) :: from, to\n integer(int8), optional, intent(in) :: by\n end subroutine seq_int8\n module subroutine seq_int16(X, from, to, by)\n integer(int16), dimension(:), allocatable, intent(out) :: X\n integer(int16), intent(in) :: from, to\n integer(int16), optional, intent(in) :: by\n end subroutine seq_int16\n module subroutine seq_int32(X, from, to, by)\n integer(int32), dimension(:), allocatable, intent(out) :: X\n integer(int32), intent(in) :: from, to\n integer(int32), optional, intent(in) :: by\n end subroutine seq_int32\n module subroutine seq_int64(X, from, to, by)\n integer(int64), dimension(:), allocatable, intent(out) :: X\n integer(int64), intent(in) :: from, to\n integer(int64), optional, intent(in) :: by\n end subroutine seq_int64\n end interface seq\n\n interface solve\n module function solve_sp(A, b) result(x)\n real(sp), dimension(:, :), intent(in) :: A\n real(sp), dimension(:), intent(in) :: b\n real(sp), dimension(:), allocatable :: x\n end function solve_sp\n module function solve_dp(A, b) result(x)\n real(dp), dimension(:, :), intent(in) :: A\n real(dp), dimension(:), intent(in) :: b\n real(dp), dimension(:), allocatable :: x\n end function solve_dp\n end interface solve\n\n interface svd\n module subroutine svd_sp(a, w, u, v, d, ierr)\n real(sp), dimension(:, :), intent(in) :: a\n real(sp), dimension(:), allocatable, intent(out) :: w\n real(sp), dimension(:, :), allocatable, intent(out), optional :: u, v\n integer, intent(out), optional :: ierr\n logical, intent(in), optional ::d\n end subroutine svd_sp\n module subroutine svd_dp(a, w, u, v, d, ierr)\n real(dp), dimension(:, :), intent(in) :: a\n real(dp), dimension(:), allocatable, intent(out) :: w\n real(dp), dimension(:, :), allocatable, intent(out), optional :: u, v\n integer, intent(out), optional :: ierr\n logical, intent(in), optional ::d\n end subroutine svd_dp\n end interface svd\n\n interface svdsolve\n module function svdsolve_sp(A, b, cutoff) result(x)\n real(sp), dimension(:, :), intent(in) :: A\n real(sp), dimension(:), intent(in) :: b\n real(sp), dimension(:), allocatable :: x\n integer, intent(in), optional :: cutoff\n end function svdsolve_sp\n module function svdsolve_dp(A, b, cutoff) result(x)\n real(dp), dimension(:, :), intent(in) :: A\n real(dp), dimension(:), intent(in) :: b\n real(dp), dimension(:), allocatable :: x\n integer, intent(in), optional :: cutoff\n end function svdsolve_dp\n end interface svdsolve\n\n interface trace\n procedure :: trace_sp\n procedure :: trace_dp\n end interface trace\n\n interface tril\n module function tril_int8(A, k)\n integer(int8), dimension(:, :), allocatable :: tril_int8\n integer(int8), dimension(:, :), intent(in) :: A\n integer, intent(in), optional :: k\n end function tril_int8\n module function tril_int16(A, k)\n integer(int16), dimension(:, :), allocatable :: tril_int16\n integer(int16), dimension(:, :), intent(in) :: A\n integer, intent(in), optional :: k\n end function tril_int16\n module function tril_int32(A, k)\n integer(int32), dimension(:, :), allocatable :: tril_int32\n integer(int32), dimension(:, :), intent(in) :: A\n integer, intent(in), optional :: k\n end function tril_int32\n module function tril_int64(A, k)\n integer(int64), dimension(:, :), allocatable :: tril_int64\n integer(int64), dimension(:, :), intent(in) :: A\n integer, intent(in), optional :: k\n end function tril_int64\n module function tril_sp(A, k)\n real(sp), dimension(:, :), allocatable :: tril_sp\n real(sp), dimension(:, :), intent(in) :: A\n integer, intent(in), optional :: k\n end function tril_sp\n module function tril_dp(A, k)\n real(dp), dimension(:, :), allocatable :: tril_dp\n real(dp), dimension(:, :), intent(in) :: A\n integer, intent(in), optional :: k\n end function tril_dp\n module function tril_csp(A, k)\n complex(sp), dimension(:, :), allocatable :: tril_csp\n complex(sp), dimension(:, :), intent(in) :: A\n integer, intent(in), optional :: k\n end function tril_csp\n module function tril_cdp(A, k)\n complex(dp), dimension(:, :), allocatable :: tril_cdp\n complex(dp), dimension(:, :), intent(in) :: A\n integer, intent(in), optional :: k\n end function tril_cdp\n end interface tril\n\n interface triu\n module function triu_int8(A, k)\n integer(int8), dimension(:, :), allocatable :: triu_int8\n integer(int8), dimension(:, :), intent(in) :: A\n integer, intent(in), optional :: k\n end function triu_int8\n module function triu_int16(A, k)\n integer(int16), dimension(:, :), allocatable :: triu_int16\n integer(int16), dimension(:, :), intent(in) :: A\n integer, intent(in), optional :: k\n end function triu_int16\n module function triu_int32(A, k)\n integer(int32), dimension(:, :), allocatable :: triu_int32\n integer(int32), dimension(:, :), intent(in) :: A\n integer, intent(in), optional :: k\n end function triu_int32\n module function triu_int64(A, k)\n integer(int64), dimension(:, :), allocatable :: triu_int64\n integer(int64), dimension(:, :), intent(in) :: A\n integer, intent(in), optional :: k\n end function triu_int64\n module function triu_sp(A, k)\n real(sp), dimension(:, :), allocatable :: triu_sp\n real(sp), dimension(:, :), intent(in) :: A\n integer, intent(in), optional :: k\n end function triu_sp\n module function triu_dp(A, k)\n real(dp), dimension(:, :), allocatable :: triu_dp\n real(dp), dimension(:, :), intent(in) :: A\n integer, intent(in), optional :: k\n end function triu_dp\n module function triu_csp(A, k)\n complex(sp), dimension(:, :), allocatable :: triu_csp\n complex(sp), dimension(:, :), intent(in) :: A\n integer, intent(in), optional :: k\n end function triu_csp\n module function triu_cdp(A, k)\n complex(dp), dimension(:, :), allocatable :: triu_cdp\n complex(dp), dimension(:, :), intent(in) :: A\n integer, intent(in), optional :: k\n end function triu_cdp\n end interface triu\n\n !> Version: experimental\n !>\n !> Creates a rank-1 or rank-2 array filled zeros.\n !> ([Specification](../page/specs/forlab_linalg.html#zerosones))\n interface zeros\n procedure :: zeros_1_default\n procedure :: zeros_2_default\n end interface zeros\n\ncontains\n\n function rmut_sp(m1, m2) result(res)\n !! complex(dp) matrix multiplication\n real(sp), intent(in) :: m1(:, :), m2(:, :)\n real(sp) :: res(size(m1, 1), size(m2, 2))\n\n if (size(m1, 2) == size(m2, 1)) then\n res = matmul(m1, m2)\n else\n call error_stop('Error: size(matrix_1, 2) /= size(matrix_2, 1)')\n end if\n end function rmut_sp\n function rmut_dp(m1, m2) result(res)\n !! complex(dp) matrix multiplication\n real(dp), intent(in) :: m1(:, :), m2(:, :)\n real(dp) :: res(size(m1, 1), size(m2, 2))\n\n if (size(m1, 2) == size(m2, 1)) then\n res = matmul(m1, m2)\n else\n call error_stop('Error: size(matrix_1, 2) /= size(matrix_2, 1)')\n end if\n end function rmut_dp\n function cmut_sp(m1, m2) result(res)\n !! complex(dp) matrix multiplication\n complex(sp), intent(in) :: m1(:, :), m2(:, :)\n complex(sp) :: res(size(m1, 1), size(m2, 2))\n\n if (size(m1, 2) == size(m2, 1)) then\n res = matmul(m1, m2)\n else\n call error_stop('Error: size(matrix_1, 2) /= size(matrix_2, 1)')\n end if\n end function cmut_sp\n function cmut_dp(m1, m2) result(res)\n !! complex(dp) matrix multiplication\n complex(dp), intent(in) :: m1(:, :), m2(:, :)\n complex(dp) :: res(size(m1, 1), size(m2, 2))\n\n if (size(m1, 2) == size(m2, 1)) then\n res = matmul(m1, m2)\n else\n call error_stop('Error: size(matrix_1, 2) /= size(matrix_2, 1)')\n end if\n end function cmut_dp\n function rcmut_sp(m1, m2) result(res)\n !! complex(dp) matrix multiplication\n real(sp), intent(in) :: m1(:, :)\n complex(sp), intent(in) :: m2(:, :)\n complex(sp) :: res(size(m1, 1), size(m2, 2))\n\n if (size(m1, 2) == size(m2, 1)) then\n res = matmul(m1, m2)\n else\n call error_stop('Error: size(matrix_1, 2) /= size(matrix_2, 1)')\n end if\n end function rcmut_sp\n function rcmut_dp(m1, m2) result(res)\n !! complex(dp) matrix multiplication\n real(dp), intent(in) :: m1(:, :)\n complex(dp), intent(in) :: m2(:, :)\n complex(dp) :: res(size(m1, 1), size(m2, 2))\n\n if (size(m1, 2) == size(m2, 1)) then\n res = matmul(m1, m2)\n else\n call error_stop('Error: size(matrix_1, 2) /= size(matrix_2, 1)')\n end if\n end function rcmut_dp\n function crmut_sp(m1, m2) result(res)\n !! complex(dp) matrix multiplication\n complex(sp), intent(in) :: m1(:, :)\n real(sp), intent(in) :: m2(:, :)\n complex(sp) :: res(size(m1, 1), size(m2, 2))\n\n if (size(m1, 2) == size(m2, 1)) then\n res = matmul(m1, m2)\n else\n call error_stop('Error: size(matrix_1, 2) /= size(matrix_2, 1)')\n end if\n end function crmut_sp\n function crmut_dp(m1, m2) result(res)\n !! complex(dp) matrix multiplication\n complex(dp), intent(in) :: m1(:, :)\n real(dp), intent(in) :: m2(:, :)\n complex(dp) :: res(size(m1, 1), size(m2, 2))\n\n if (size(m1, 2) == size(m2, 1)) then\n res = matmul(m1, m2)\n else\n call error_stop('Error: size(matrix_1, 2) /= size(matrix_2, 1)')\n end if\n end function crmut_dp\n\n function is_square_rsp(A) result(is_square)\n !! real(sp) matrix is square or not.\n real(sp), intent(in) :: A(:, :)\n logical :: is_square\n is_square = .false.\n if (size(A, 1) == size(A, 2)) is_square = .true.\n return\n end function is_square_rsp\n function is_square_rdp(A) result(is_square)\n !! real(dp) matrix is square or not.\n real(dp), intent(in) :: A(:, :)\n logical :: is_square\n is_square = .false.\n if (size(A, 1) == size(A, 2)) is_square = .true.\n return\n end function is_square_rdp\n function is_square_csp(A) result(is_square)\n !! complex(sp) matrix is square or not.\n complex(sp), intent(in) :: A(:, :)\n logical :: is_square\n is_square = .false.\n if (size(A, 1) == size(A, 2)) is_square = .true.\n return\n end function is_square_csp\n function is_square_cdp(A) result(is_square)\n !! complex(dp) matrix is square or not.\n complex(dp), intent(in) :: A(:, :)\n logical :: is_square\n is_square = .false.\n if (size(A, 1) == size(A, 2)) is_square = .true.\n return\n end function is_square_cdp\n\n function is_symmetric_rsp(A) result(is_symmetric)\n !! real(sp) matrix is symmetric or not.\n real(sp), intent(in) :: A(:, :)\n logical :: is_symmetric\n integer :: i, j, n\n is_symmetric = .true.\n if (.not. is_square(A)) then\n is_symmetric = .false.\n return\n else\n n = size(A, 1)\n do i = 1, n\n do j = 1, n\n if (A(i, j) .ne. A(j, i)) then\n is_symmetric = .false.\n return\n end if\n end do\n end do\n end if\n return\n end function is_symmetric_rsp\n function is_symmetric_rdp(A) result(is_symmetric)\n !! real(dp) matrix is symmetric or not.\n real(dp), intent(in) :: A(:, :)\n logical :: is_symmetric\n integer :: i, j, n\n is_symmetric = .true.\n if (.not. is_square(A)) then\n is_symmetric = .false.\n return\n else\n n = size(A, 1)\n do i = 1, n\n do j = 1, n\n if (A(i, j) .ne. A(j, i)) then\n is_symmetric = .false.\n return\n end if\n end do\n end do\n end if\n return\n end function is_symmetric_rdp\n function is_symmetric_csp(A) result(is_symmetric)\n !! complex(sp) matrix is symmetric or not.\n complex(sp), intent(in) :: A(:, :)\n logical :: is_symmetric\n integer :: i, j, n\n is_symmetric = .true.\n if (.not. is_square(A)) then\n is_symmetric = .false.\n return\n else\n n = size(A, 1)\n do i = 1, n\n do j = 1, n\n if (A(i, j) .ne. A(j, i)) then\n is_symmetric = .false.\n return\n end if\n end do\n end do\n end if\n return\n end function is_symmetric_csp\n function is_symmetric_cdp(A) result(is_symmetric)\n !! complex(dp) matrix is symmetric or not.\n complex(dp), intent(in) :: A(:, :)\n logical :: is_symmetric\n integer :: i, j, n\n is_symmetric = .true.\n if (.not. is_square(A)) then\n is_symmetric = .false.\n return\n else\n n = size(A, 1)\n do i = 1, n\n do j = 1, n\n if (A(i, j) .ne. A(j, i)) then\n is_symmetric = .false.\n return\n end if\n end do\n end do\n end if\n return\n end function is_symmetric_cdp\n\n function trace_sp(A) result(trace)\n real(sp), dimension(:, :), intent(in) :: A\n real(sp) :: trace\n\n trace = sum(diag(A))\n\n end function trace_sp\n function trace_dp(A) result(trace)\n real(dp), dimension(:, :), intent(in) :: A\n real(dp) :: trace\n\n trace = sum(diag(A))\n\n end function trace_dp\n\n !> `ones` creates a rank-1 array, filled completely with `1` `integer` type values.\n pure function ones_1_default(dim) result(result)\n integer, intent(in) :: dim\n integer(kind=int8), allocatable :: result(:)\n\n allocate (result(dim), source=1_int8)\n\n end function ones_1_default\n\n !> `ones` creates a rank-2 array, filled completely with `1` `integer` type values.\n pure function ones_2_default(dim1, dim2) result(result)\n integer, intent(in) :: dim1, dim2\n integer(kind=int8), allocatable :: result(:, :)\n\n allocate (result(dim1, dim2), source=1_int8)\n\n end function ones_2_default\n\n !> `zeros` creates a rank-1 array, filled completely with `0` `integer` type values.\n pure function zeros_1_default(dim) result(result)\n integer, intent(in) :: dim\n integer(kind=int8), allocatable :: result(:)\n\n allocate (result(dim), source=0_int8)\n\n end function zeros_1_default\n\n !> `zeros` creates a rank-2 array, filled completely with `0` `integer` type values.\n pure function zeros_2_default(dim1, dim2) result(result)\n integer, intent(in) :: dim1, dim2\n integer(kind=int8), allocatable :: result(:, :)\n\n allocate (result(dim1, dim2), source=0_int8)\n\n end function zeros_2_default\n\nend module forlab_linalg\n", "meta": {"hexsha": "b39e1424eef5e22ba7b381288d57246742ec5f67", "size": 46844, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/forlab_linalg.f90", "max_stars_repo_name": "zoziha/forlab_z", "max_stars_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2021-08-31T15:23:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T02:44:46.000Z", "max_issues_repo_path": "src/forlab_linalg.f90", "max_issues_repo_name": "zoziha/forlab_z", "max_issues_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-08-22T11:47:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-31T00:57:16.000Z", "max_forks_repo_path": "src/forlab_linalg.f90", "max_forks_repo_name": "zoziha/forlab_z", "max_forks_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-07-16T03:16:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-31T13:09:42.000Z", "avg_line_length": 43.6570363467, "max_line_length": 96, "alphanum_fraction": 0.5681197165, "num_tokens": 11995, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511616741042, "lm_q2_score": 0.7956580976404297, "lm_q1q2_score": 0.6809649071609697}} {"text": "!*****************************************************************************************\n!> author: Jacob Williams\n! date: 9/6/2017\n!\n! 1D definite integral test using the bspline module.\n!\n! This test case evaluates the integral:\n!\n! $$ \\int_{0}^{\\pi} x^2 \\sin (x) dx = 2 $$\n!\n! using a B-Spline of the points:\n!\n! $$ \\left[ \\sin(0^{\\circ}), \\sin(1^{\\circ}), ..., \\sin(180^{\\circ}) \\right] $$\n\n program bspline_integrate_test\n\n use bspline_module\n use bspline_kinds_module, only: wp, ip\n\n implicit none\n\n real(wp),parameter :: pi = acos(-1.0_wp) !! \\( \\pi \\)\n real(wp),parameter :: deg2rad = pi/180.0_wp !! degrees to radians\n integer(ip),parameter :: iknot = 0 !! automatically select the knots\n real(wp),parameter :: x1 = 0.0_wp !! left endpoint\n real(wp),parameter :: x2 = pi !! right endpoint\n integer(ip),parameter :: nx = 181 !! number of points in x dimension\n !! in original grid\n real(wp),parameter :: tol = 10.0_wp*epsilon(1.0_wp) !! tolerance for [[db1fqad]]\n\n real(wp),dimension(:),allocatable :: tx !! x knots\n integer(ip) :: kx !! x bspline order\n real(wp),dimension(nx) :: x !! new grid x points\n real(wp),dimension(nx) :: fcn !! original grid\n !! function evaluations\n integer(ip) :: i !! counter\n integer(ip) :: iflag !! status flag\n real(wp) :: f !! the evaluated integral\n integer :: imeth !! method counter\n character(len=:),allocatable :: meth !! method string\n real(wp) :: f_true !! the true integral of\n !! the analytic function\n real(wp),dimension(:),allocatable :: w1_1d !! work array\n\n do imeth = 1,2 ! the two methods\n\n write(*,*) ''\n write(*,'(A8,1X,A5,1X,A30,1X,A30)') 'Method','Order','Integral','Error'\n\n do kx = 2, 15 ! spline orders\n\n if (allocated(tx)) deallocate(tx)\n if (allocated(w1_1d)) deallocate(w1_1d)\n allocate(tx(nx+kx))\n allocate(w1_1d(3*kx))\n\n ! x^2 * sin(x) function evaluations for original grid:\n do i=1,nx\n x(i) = deg2rad*real(i-1,wp)\n if (imeth==1) then\n fcn(i) = x(i)**2 * sin(x(i))\n else\n ! for this one the x^2 will be handled by func\n fcn(i) = sin(x(i))\n end if\n end do\n\n f_true = pi**2 - 4.0_wp\n\n ! initialize:\n ! [note we are overwriting fcn here with the b coeffs]\n call db1ink(x,nx,fcn,kx,iknot,tx,fcn,iflag)\n if (iflag/=0) error stop 'error calling db1ink'\n\n ! integrate:\n if (imeth==1) then\n if (kx>20) cycle\n meth = 'db1sqad'\n call db1sqad(tx,fcn,nx,kx,x1,x2,f,iflag,w1_1d)\n else\n meth = 'db1fqad'\n call db1fqad(test_function,tx,fcn,nx,kx,0_ip,x1,x2,tol,f,iflag,w1_1d)\n end if\n\n ! display results:\n if (iflag/=0) then\n write(*,*) ''\n write(*,*) 'iflag: ',iflag\n write(*,*) 'error calling '//meth\n error stop\n else\n write(*,'(A8,1X,I5,1X,E30.16,1X,E30.16)') meth,kx,f,f-f_true\n end if\n\n end do\n end do\n write(*,*) ''\n\n contains\n\n function test_function(x) result(f)\n\n !! the function \\( f(x) = x^2 \\)\n !! to use for [[db1fqad]] test.\n\n implicit none\n\n real(wp),intent(in) :: x\n real(wp) :: f !! f(x)\n\n f = x*x\n\n end function test_function\n\n end program bspline_integrate_test\n!*****************************************************************************************\n", "meta": {"hexsha": "a307cef61601ed851b8519d1f19fe432f0c28b4d", "size": 4142, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/test_integrate.f90", "max_stars_repo_name": "pan3rock/bspline-fortran", "max_stars_repo_head_hexsha": "7c44ea784d7e3e7d945f617d0ce65664550defcb", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 139, "max_stars_repo_stars_event_min_datetime": "2015-02-25T08:11:20.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T17:33:50.000Z", "max_issues_repo_path": "src/tests/test_integrate.f90", "max_issues_repo_name": "pan3rock/bspline-fortran", "max_issues_repo_head_hexsha": "7c44ea784d7e3e7d945f617d0ce65664550defcb", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 46, "max_issues_repo_issues_event_min_datetime": "2015-06-19T18:25:15.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T21:14:15.000Z", "max_forks_repo_path": "src/tests/test_integrate.f90", "max_forks_repo_name": "pan3rock/bspline-fortran", "max_forks_repo_head_hexsha": "7c44ea784d7e3e7d945f617d0ce65664550defcb", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 51, "max_forks_repo_forks_event_min_datetime": "2015-09-17T16:52:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-26T03:18:28.000Z", "avg_line_length": 35.4017094017, "max_line_length": 90, "alphanum_fraction": 0.4468855625, "num_tokens": 1089, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511396138365, "lm_q2_score": 0.7956581073313276, "lm_q1q2_score": 0.6809648979025049}} {"text": "program dinamica\n\nimplicit none\n\nreal, dimension (1:500) :: x, t\nreal :: xo, vo, a, cont\ninteger :: k\n\nxo = 2\nvo = 4\na = 6\n\ncont = 0\ndo k = 1,500\n cont = cont + 0.01\n t(k) = cont\n x(k) = xo + vo*t(k)+((a*(t(k)**2))/2)\nend do\n\ndo k = 1,500\n write(*,*) x(k), t(k)\nend do\n\nopen(1,file = \"dados.txt\")\n\ndo k = 1,500\n write(1,*) x(k), t(k)\nend do\n\nclose (1)\n\nend program dinamica", "meta": {"hexsha": "97082737f4e53d5e11ffadfe51157d10efe8723d", "size": 388, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "aula04/prog8.f90", "max_stars_repo_name": "j-rheinheimer/Fisica-Computacional-I", "max_stars_repo_head_hexsha": "9d3d434cfb787391db5b57829e93d1461cc65f1c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "aula04/prog8.f90", "max_issues_repo_name": "j-rheinheimer/Fisica-Computacional-I", "max_issues_repo_head_hexsha": "9d3d434cfb787391db5b57829e93d1461cc65f1c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "aula04/prog8.f90", "max_forks_repo_name": "j-rheinheimer/Fisica-Computacional-I", "max_forks_repo_head_hexsha": "9d3d434cfb787391db5b57829e93d1461cc65f1c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 12.125, "max_line_length": 41, "alphanum_fraction": 0.5309278351, "num_tokens": 167, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.7956581000631541, "lm_q1q2_score": 0.6809648975328408}} {"text": " SUBROUTINE DG01OD( SCR, WGHT, N, A, W, INFO )\r\nC\r\nC SLICOT RELEASE 5.5.\r\nC\r\nC Copyright (c) 2002-2012 NICONET e.V.\r\nC\r\nC PURPOSE\r\nC\r\nC To compute the (scrambled) discrete Hartley transform of\r\nC a real signal.\r\nC\r\nC ARGUMENTS\r\nC\r\nC Mode Parameters\r\nC\r\nC SCR CHARACTER*1\r\nC Indicates whether the signal is scrambled on input or\r\nC on output as follows:\r\nC = 'N': the signal is not scrambled at all;\r\nC = 'I': the input signal is bit-reversed;\r\nC = 'O': the output transform is bit-reversed.\r\nC\r\nC WGHT CHARACTER*1\r\nC Indicates whether the precomputed weights are available\r\nC or not, as follows:\r\nC = 'A': available;\r\nC = 'N': not available.\r\nC Note that if N > 1 and WGHT = 'N' on entry, then WGHT is\r\nC set to 'A' on exit.\r\nC\r\nC Input/Output Parameters\r\nC\r\nC N (input) INTEGER\r\nC Number of real samples. N must be a power of 2.\r\nC N >= 0.\r\nC\r\nC A (input/output) DOUBLE PRECISION array, dimension (N)\r\nC On entry with SCR = 'N' or SCR = 'O', this array must\r\nC contain the input signal.\r\nC On entry with SCR = 'I', this array must contain the\r\nC bit-reversed input signal.\r\nC On exit with SCR = 'N' or SCR = 'I', this array contains\r\nC the Hartley transform of the input signal.\r\nC On exit with SCR = 'O', this array contains the\r\nC bit-reversed Hartley transform.\r\nC\r\nC W (input/output) DOUBLE PRECISION array,\r\nC dimension (N - LOG2(N))\r\nC On entry with WGHT = 'A', this array must contain the long\r\nC weight vector computed by a previous call of this routine\r\nC with the same value of N. If WGHT = 'N', the contents of\r\nC this array on entry is ignored.\r\nC On exit, this array contains the long weight vector.\r\nC\r\nC Error Indicator\r\nC\r\nC INFO INTEGER\r\nC = 0: successful exit;\r\nC < 0: if INFO = -i, the i-th argument had an illegal\r\nC value.\r\nC\r\nC METHOD\r\nC\r\nC This routine uses a Hartley butterfly algorithm as described\r\nC in [1].\r\nC\r\nC REFERENCES\r\nC\r\nC [1] Van Loan, Charles.\r\nC Computational frameworks for the fast Fourier transform.\r\nC SIAM, 1992.\r\nC\r\nC NUMERICAL ASPECTS\r\nC\r\nC The algorithm is backward stable and requires O(N log(N))\r\nC floating point operations.\r\nC\r\nC CONTRIBUTOR\r\nC\r\nC D. Kressner, Technical Univ. Berlin, Germany, April 2001.\r\nC\r\nC REVISIONS\r\nC\r\nC V. Sima, Research Institute for Informatics, Bucharest, Apr. 2000.\r\nC\r\nC KEYWORDS\r\nC\r\nC Digital signal processing, fast Hartley transform, real signals.\r\nC\r\nC ******************************************************************\r\nC\r\nC .. Parameters ..\r\n DOUBLE PRECISION ONE, TWO, FOUR\r\n PARAMETER ( ONE = 1.0D0, TWO = 2.0D0, FOUR = 4.0D0 )\r\nC .. Scalar Arguments ..\r\n CHARACTER SCR, WGHT\r\n INTEGER INFO, N\r\nC .. Array Arguments ..\r\n DOUBLE PRECISION A(*), W(*)\r\nC .. Local Scalars ..\r\n INTEGER I, J, L, LEN, M, P1, P2, Q1, Q2, R1, R2, S1, S2,\r\n $ WPOS\r\n LOGICAL LFWD, LSCR, LWGHT\r\n DOUBLE PRECISION CF, SF, T1, T2, TH\r\nC .. External Functions ..\r\n LOGICAL LSAME\r\n EXTERNAL LSAME\r\nC .. External Subroutines ..\r\n EXTERNAL XERBLA\r\nC .. Intrinsic Functions ..\r\n INTRINSIC ATAN, COS, DBLE, MOD, SIN\r\nC .. Executable Statements ..\r\nC\r\n INFO = 0\r\n LFWD = LSAME( SCR, 'N' ) .OR. LSAME( SCR, 'I' )\r\n LSCR = LSAME( SCR, 'I' ) .OR. LSAME( SCR, 'O' )\r\n LWGHT = LSAME( WGHT, 'A' )\r\nC\r\nC Test the input scalar arguments.\r\nC\r\n IF( .NOT.( LFWD .OR. LSCR ) ) THEN\r\n INFO = -1\r\n ELSE IF( .NOT.LWGHT .AND. .NOT.LSAME( WGHT, 'N' ) ) THEN\r\n INFO = -2\r\n ELSE\r\n M = 0\r\n J = 0\r\n IF( N.GE.1 ) THEN\r\n J = N\r\nC WHILE ( MOD( J, 2 ).EQ.0 ) DO\r\n 10 CONTINUE\r\n IF ( MOD( J, 2 ).EQ.0 ) THEN\r\n J = J/2\r\n M = M + 1\r\n GO TO 10\r\n END IF\r\nC END WHILE 10\r\n IF ( J.NE.1 ) INFO = -3\r\n ELSE IF ( N.LT.0 ) THEN\r\n INFO = -3\r\n END IF\r\n END IF\r\nC\r\n IF ( INFO.NE.0 ) THEN\r\nC\r\nC Error return.\r\nC\r\n CALL XERBLA( 'DG01OD', -INFO )\r\n RETURN\r\n END IF\r\nC\r\nC Quick return if possible.\r\nC\r\n IF ( N.LE.1 )\r\n $ RETURN\r\nC\r\n IF ( .NOT. LWGHT ) THEN\r\nC\r\nC Compute the long weight vector via subvector scaling.\r\nC\r\n R1 = 1\r\n LEN = 1\r\n TH = FOUR*ATAN( ONE ) / DBLE( N )\r\nC\r\n DO 30 L = 1, M - 2\r\n LEN = 2*LEN\r\n TH = TWO*TH\r\n CF = COS(TH)\r\n SF = SIN(TH)\r\n W(R1) = CF\r\n W(R1+1) = SF\r\n R1 = R1 + 2\r\nC\r\n DO 20 I = 1, LEN - 2, 2\r\n W(R1) = CF*W(I) - SF*W(I+1)\r\n W(R1+1) = SF*W(I) + CF*W(I+1)\r\n R1 = R1 + 2\r\n 20 CONTINUE\r\nC\r\n 30 CONTINUE\r\nC\r\n P1 = 3\r\n Q1 = R1 - 2\r\nC\r\n DO 50 L = M - 2, 1, -1\r\nC\r\n DO 40 I = P1, Q1, 4\r\n W(R1) = W(I)\r\n W(R1+1) = W(I+1)\r\n R1 = R1 + 2\r\n 40 CONTINUE\r\nC\r\n P1 = Q1 + 4\r\n Q1 = R1 - 2\r\n 50 CONTINUE\r\nC\r\n WGHT = 'A'\r\nC\r\n END IF\r\nC\r\n IF ( LFWD .AND. .NOT.LSCR ) THEN\r\nC\r\nC Inplace shuffling of data.\r\nC\r\n J = 1\r\nC\r\n DO 70 I = 1, N\r\n IF ( J.GT.I ) THEN\r\n T1 = A(I)\r\n A(I) = A(J)\r\n A(J) = T1\r\n END IF\r\n L = N/2\r\nC REPEAT\r\n 60 IF ( J.GT.L ) THEN\r\n J = J - L\r\n L = L/2\r\n IF ( L.GE.2 ) GO TO 60\r\n END IF\r\nC UNTIL ( L.LT.2 )\r\n J = J + L\r\n 70 CONTINUE\r\nC\r\n END IF\r\nC\r\n IF ( LFWD ) THEN\r\nC\r\nC Compute Hartley transform with butterfly operators.\r\nC\r\n DO 110 J = 2, N, 2\r\n T1 = A(J)\r\n A(J) = A(J-1) - T1\r\n A(J-1) = A(J-1) + T1\r\n 110 CONTINUE\r\nC\r\n LEN = 1\r\n WPOS = N - 2*M + 1\r\nC\r\n DO 140 L = 1, M - 1\r\n LEN = 2*LEN\r\n P2 = 1\r\n Q2 = LEN + 1\r\n R2 = LEN / 2 + 1\r\n S2 = R2 + Q2 - 1\r\nC\r\n DO 130 I = 0, N/( 2*LEN ) - 1\r\n T1 = A(Q2)\r\n A(Q2) = A(P2) - T1\r\n A(P2) = A(P2) + T1\r\n T1 = A(S2)\r\n A(S2) = A(R2) - T1\r\n A(R2) = A(R2) + T1\r\nC\r\n P1 = P2 + 1\r\n Q1 = P1 + LEN\r\n R1 = Q1 - 2\r\n S1 = R1 + LEN\r\nC\r\n DO 120 J = WPOS, WPOS + LEN - 3, 2\r\n CF = W(J)\r\n SF = W(J+1)\r\n T1 = CF*A(Q1) + SF*A(S1)\r\n T2 = -CF*A(S1) + SF*A(Q1)\r\n A(Q1) = A(P1) - T1\r\n A(P1) = A(P1) + T1\r\n A(S1) = A(R1) - T2\r\n A(R1) = A(R1) + T2\r\n P1 = P1 + 1\r\n Q1 = Q1 + 1\r\n R1 = R1 - 1\r\n S1 = S1 - 1\r\n 120 CONTINUE\r\nC\r\n P2 = P2 + 2*LEN\r\n Q2 = Q2 + 2*LEN\r\n R2 = R2 + 2*LEN\r\n S2 = S2 + 2*LEN\r\n 130 CONTINUE\r\nC\r\n WPOS = WPOS - 2*LEN + 2\r\n 140 CONTINUE\r\nC\r\n ELSE\r\nC\r\nC Compute Hartley transform with transposed butterfly operators.\r\nC\r\n WPOS = 1\r\n LEN = N\r\nC\r\n DO 230 L = M - 1, 1, -1\r\n LEN = LEN / 2\r\n P2 = 1\r\n Q2 = LEN + 1\r\n R2 = LEN / 2 + 1\r\n S2 = R2 + Q2 - 1\r\nC\r\n DO 220 I = 0, N/( 2*LEN ) - 1\r\n T1 = A(Q2)\r\n A(Q2) = A(P2) - T1\r\n A(P2) = A(P2) + T1\r\n T1 = A(S2)\r\n A(S2) = A(R2) - T1\r\n A(R2) = A(R2) + T1\r\nC\r\n P1 = P2 + 1\r\n Q1 = P1 + LEN\r\n R1 = Q1 - 2\r\n S1 = R1 + LEN\r\nC\r\n DO 210 J = WPOS, WPOS + LEN - 3, 2\r\n CF = W(J)\r\n SF = W(J+1)\r\n T1 = A(P1) - A(Q1)\r\n T2 = A(R1) - A(S1)\r\n A(P1) = A(P1) + A(Q1)\r\n A(R1) = A(R1) + A(S1)\r\n A(Q1) = CF*T1 + SF*T2\r\n A(S1) = -CF*T2 + SF*T1\r\n P1 = P1 + 1\r\n Q1 = Q1 + 1\r\n R1 = R1 - 1\r\n S1 = S1 - 1\r\n 210 CONTINUE\r\nC\r\n P2 = P2 + 2*LEN\r\n Q2 = Q2 + 2*LEN\r\n R2 = R2 + 2*LEN\r\n S2 = S2 + 2*LEN\r\n 220 CONTINUE\r\nC\r\n WPOS = WPOS + LEN - 2\r\n 230 CONTINUE\r\nC\r\n DO 240 J = 2, N, 2\r\n T1 = A(J)\r\n A(J) = A(J-1) - T1\r\n A(J-1) = A(J-1) + T1\r\n 240 CONTINUE\r\nC\r\n END IF\r\n RETURN\r\nC *** Last line of DG01OD ***\r\n END\r\n", "meta": {"hexsha": "2527edfb3c1b233965411c3ddf9f76f3b9af2250", "size": 9386, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "External/SLICOT/DG01OD.f", "max_stars_repo_name": "bgin/MissileSimulation", "max_stars_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2016-08-28T23:20:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-15T14:43:58.000Z", "max_issues_repo_path": "External/SLICOT/DG01OD.f", "max_issues_repo_name": "bgin/MissileSimulation", "max_issues_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-06-02T21:29:51.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-05T05:59:31.000Z", "max_forks_repo_path": "External/SLICOT/DG01OD.f", "max_forks_repo_name": "bgin/MissileSimulation", "max_forks_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-07-04T22:38:22.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-04T22:38:22.000Z", "avg_line_length": 27.2848837209, "max_line_length": 73, "alphanum_fraction": 0.3977200085, "num_tokens": 3033, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511396138365, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.6809648875350474}} {"text": " SUBROUTINE pearsn(x,y,n,r,prob,z)\r\n INTEGER n\r\n REAL prob,r,z,x(n),y(n),TINY\r\n PARAMETER (TINY=1.e-20)\r\nCU USES betai\r\n INTEGER j\r\n REAL ax,ay,df,sxx,sxy,syy,t,xt,yt,betai\r\n ax=0.\r\n ay=0.\r\n do 11 j=1,n\r\n ax=ax+x(j)\r\n ay=ay+y(j)\r\n11 continue\r\n ax=ax/n\r\n ay=ay/n\r\n sxx=0.\r\n syy=0.\r\n sxy=0.\r\n do 12 j=1,n\r\n xt=x(j)-ax\r\n yt=y(j)-ay\r\n sxx=sxx+xt**2\r\n syy=syy+yt**2\r\n sxy=sxy+xt*yt\r\n12 continue\r\n r=sxy/(sqrt(sxx*syy)+TINY)\r\n z=0.5*log(((1.+r)+TINY)/((1.-r)+TINY))\r\n df=n-2\r\n t=r*sqrt(df/(((1.-r)+TINY)*((1.+r)+TINY)))\r\n prob=betai(0.5*df,0.5,df/(df+t**2))\r\nC prob=erfcc(abs(z*sqrt(n-1.))/1.4142136)\r\n return\r\n END\r\n", "meta": {"hexsha": "007ac2558311230b08be620ad85759ae20580cdd", "size": 783, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/pearsn.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/pearsn.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/pearsn.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.0294117647, "max_line_length": 49, "alphanum_fraction": 0.4444444444, "num_tokens": 316, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625107731765, "lm_q2_score": 0.7310585903489891, "lm_q1q2_score": 0.6809536700887685}} {"text": "use SeismicAnalysisClass\n\ntype(SeismicAnalysis_) :: seismic\nreal(real64) :: u(1),v(1),a(1),u_n(1),v_n(1),a_n(1)\nreal(real64) :: u_upd(1),v_upd(1),a_upd(1)\nreal(real64) :: beta, gamma, dt, T\nreal(real64) :: M(1,1), K(1,1), C(1,1),force(1)\nreal(real64) :: Amat(1,1),bvec(1),omega\n\ninteger(int32) :: i\ntype(Math_) :: math\ntype(IO_) :: f,fu,fv,fa\n! 1-D problem\n! with sin wave\n\nM = 1.0d0\nK = 2000.0d0\n!C =0.0d0\nC = 0.52400d0*M + 0.00129d0*K\nC = 0.50d0*C\nomega = sqrt( K(1,1)/M(1,1) ) ! natural period\nT = 2.0d0*math%PI/omega\n\nbeta = 0.250d0\ngamma = 0.50d0\n\n\nu_n = 1.0d0\nv_n = 0.0d0\na_n = 0.0d0\n\ncall f%open(\"1D_seismic_result.csv\")\ncall fu%open(\"seismic_u.txt\")\ncall fv%open(\"seismic_v.txt\")\ncall fa%open(\"seismic_a.txt\")\n! V&V\n! fix time = t=smt, caluculate numerical/analytical solution, plot errors.\n\ndo i=1,30000\n\n dt = dble(1.0e-4)\n\n ! do not destroy the second order accuracy.\n !force =0.10d0*sin(dble(i)*dt/T)\n force = 0.0d0\n !if(i<10)then\n ! force = 1.0d0\n !else\n ! force = 0.0d0 \n !endif\n\n Amat = seismic%getNewmarkBetaMatrix(M=M, C=C,K=K,beta=beta,gamma=gamma,dt=dt)\n bvec = seismic%getNewmarkBetaVector(M=M,C=C,u_n=u_n,v_n=v_n, a_n=a_n, &\n force=force,beta=beta,gamma=gamma,dt=dt)\n \n ! update\n ! Solve Au = b\n u_upd = 1.0d0/Amat(1,1)*bvec(1)\n\n v_upd = seismic%updateVelocityNewmarkBeta(u=u_upd,u_n=u_n,v_n=v_n,a_n=a_n,&\n gamma=gamma,beta=beta,dt=dt)\n a_upd = seismic%updateAccelNewmarkBeta(u=u_upd,u_n=u_n,v_n=v_n,a_n=a_n,&\n gamma=gamma,beta=beta,dt=dt)\n\n u_n = u_upd\n v_n = v_upd\n a_n = a_upd\n \n write(fu%fh,*)dble(i-1)*dt,u_n\n write(fv%fh,*)dble(i-1)*dt,v_n\n write(fa%fh,*)dble(i-1)*dt,a_n \n\n write(f%fh,*)dble(i-1)*dt,\",\",u_n,\",\",v_n,\",\",a_n,\",\",force \nenddo\ncall f%close()\ncall fu%close()\ncall fv%close()\ncall fa%close()\nprint *, \"Natural period : \",T,\" sec.\"\n\n\nend", "meta": {"hexsha": "712133db43b0a53bbdffc70a200f4c83cc127026", "size": 1881, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/sim/SeismicAnalysis1D.f90", "max_stars_repo_name": "kazulagi/plantFEM", "max_stars_repo_head_hexsha": "20bf2df8202d41aa5dc25d1cc820385dabbc604f", "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/sim/SeismicAnalysis1D.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/sim/SeismicAnalysis1D.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": 22.9390243902, "max_line_length": 81, "alphanum_fraction": 0.6220095694, "num_tokens": 806, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465134460242, "lm_q2_score": 0.7279754607093178, "lm_q1q2_score": 0.6809093090487236}} {"text": "module loglikelihood_module\n use utils_module, only: dp\n\n\n real(dp), parameter :: sigma = 0.1 ! width of peak\n\n real(dp), allocatable, dimension(:,:) :: invcovmat ! inverse covariance matrix\n real(dp), allocatable, dimension(:) :: mu ! Mean\n real(dp) :: logdetcovmat ! log(det(covariance matrix))\n\n contains\n !> Random Correlated gaussian loglikelihood\n !! \n !! It is normalised so that it should output an evidence of 1.0 for\n !! effectively infinite priors.\n\n function loglikelihood(theta,phi)\n use utils_module, only: log_gauss\n implicit none\n !> Input parameters\n real(dp), intent(in), dimension(:) :: theta\n !> Output derived parameters\n real(dp), intent(out), dimension(:) :: phi\n\n real(dp) :: loglikelihood\n\n ! Compute log likelihood\n loglikelihood = log_gauss(theta,mu,invcovmat,logdetcovmat)\n\n end function loglikelihood\n\n\n\n subroutine setup_loglikelihood(settings)\n#ifdef MPI\n use mpi_module\n#endif\n use settings_module, only: program_settings\n use random_module, only: random_inverse_covmat\n implicit none\n type(program_settings), intent(in) :: settings\n\n integer :: nDims\n\n ! Get the dimensionality from settings\n nDims = settings%nDims\n\n ! Allocate the mean vector and inverse covariance matrix\n allocate(mu(nDims),invcovmat(nDims,nDims))\n\n ! Create a mean vector at the center of the space\n mu = 0.5d0\n\n ! Generate a random covariance matrix, its inverse and logdet on the root node\n call initialise_mpi\n call random_inverse_covmat(invcovmat,logdetcovmat,sigma,nDims)\n\n#ifdef MPI\n ! Broadcast the covariance matrix and normalisation data to the\n ! rest of the nodes\n ! Covariance matrix:\n call MPI_BCAST( &\n invcovmat, & ! inverse covariance matrix data to be broadcast\n nDims*nDims, & ! size of the data\n MPI_DOUBLE_PRECISION, & ! type of data\n 0, & ! root node id\n MPI_COMM_WORLD, & ! communication info\n mpierror) ! error (from mpiutils)\n ! normalisation logdet covmat\n call MPI_BCAST( &\n logdetcovmat, & ! log(determinant of inverse covariance matrix) data to be broadcast\n 1, & ! size of the data\n MPI_DOUBLE_PRECISION, & ! type of data\n 0, & ! root node id\n MPI_COMM_WORLD, & ! communication info\n mpierror) ! error (from mpiutils)\n#endif\n\n end subroutine setup_loglikelihood\n\nend module loglikelihood_module\n", "meta": {"hexsha": "3719ac98d8ba940d09fafd7523fce72d9269656f", "size": 2815, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Externals/PolyChord/likelihoods/examples/random_gaussian.f90", "max_stars_repo_name": "yuanfangtardis/vscode_project", "max_stars_repo_head_hexsha": "2d78a85413cc85789cc4fee8ec991eb2a0563ef8", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Externals/PolyChord/likelihoods/examples/random_gaussian.f90", "max_issues_repo_name": "yuanfangtardis/vscode_project", "max_issues_repo_head_hexsha": "2d78a85413cc85789cc4fee8ec991eb2a0563ef8", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Externals/PolyChord/likelihoods/examples/random_gaussian.f90", "max_forks_repo_name": "yuanfangtardis/vscode_project", "max_forks_repo_head_hexsha": "2d78a85413cc85789cc4fee8ec991eb2a0563ef8", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-15T12:22:30.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-15T12:22:30.000Z", "avg_line_length": 34.3292682927, "max_line_length": 104, "alphanum_fraction": 0.5953818828, "num_tokens": 636, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465098415279, "lm_q2_score": 0.7279754430043072, "lm_q1q2_score": 0.6809092898644188}} {"text": "program Primes\n\n use ISO_FORTRAN_ENV\n\n implicit none\n\n integer(int64), dimension(7) :: data = (/2099726827, 15780709, 1122725370, 15808973, 576460741, 12878611, 12757923/)\n integer(int64), dimension(100) :: outprimes\n integer(int64) :: largest_factor = 0, largest = 0, minim = 0, val = 0\n integer(int16) :: count = 0, OMP_GET_THREAD_NUM\n\n call omp_set_num_threads(4);\n !$omp parallel do private(val,outprimes,count) shared(data,largest_factor,largest)\n do val = 1, 7\n outprimes = 0\n call find_factors(data(val), outprimes, count)\n minim = minval(outprimes(1:count))\n if (minim > largest_factor) then\n largest_factor = minim\n largest = data(val)\n end if\n write(*, fmt = '(A7,i0,A2,i12,100i12)') 'Thread ', OMP_GET_THREAD_NUM(), ': ', data(val), outprimes(1:count)\n end do\n !$omp end parallel do\n\n write(*, fmt = '(i0,A26,i0)') largest, ' have the Largest factor: ', largest_factor\n\n return\n\ncontains\n\n subroutine find_factors(n, d, count)\n integer(int64), intent(in) :: n\n integer(int64), dimension(:), intent(out) :: d\n integer(int16), intent(out) :: count\n integer(int16) :: i\n integer(int64) :: div, next, rest\n\n i = 1\n div = 2; next = 3; rest = n\n\n do while (rest /= 1)\n do while (mod(rest, div) == 0)\n d(i) = div\n i = i + 1\n rest = rest / div\n end do\n div = next\n next = next + 2\n end do\n count = i - 1\n end subroutine find_factors\n\nend program Primes\n", "meta": {"hexsha": "54b9a9072dd4c5a10166520b4324dc102491fd77", "size": 1624, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Parallel-calculations/Fortran/parallel-calculations.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/Parallel-calculations/Fortran/parallel-calculations.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/Parallel-calculations/Fortran/parallel-calculations.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 29.5272727273, "max_line_length": 120, "alphanum_fraction": 0.5671182266, "num_tokens": 479, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357735451834, "lm_q2_score": 0.7853085808877581, "lm_q1q2_score": 0.6808906329016876}} {"text": "module Const\n implicit none\n\n integer,parameter :: mpc=8 ! \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0440\u0430\u0437\u043d\u043e\u0432\u0438\u0434\u043d\u043e\u0441\u0442\u0438 \u0442\u0438\u043f\u0430 \u0434\u043b\u044f real\n real(mpc), parameter :: EPS = epsilon(1.0_mpc)\n real(mpc), parameter :: phi = (1.0_mpc + sqrt(5.0_mpc))/2.0_mpc\n real(mpc), parameter :: Pi = atan(1.0_mpc)*4.0_mpc\n \n !> error codes\n integer,parameter :: &\n &EXIT_SUCCESS = 0&\n &,EXIT_FAILURE = 1&\n &;\nend module Const\n", "meta": {"hexsha": "5fc3431f6b6cc7e96f266e7a0865bd6d09a19f2d", "size": 415, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/Const.f90", "max_stars_repo_name": "taxus-d/integrators", "max_stars_repo_head_hexsha": "90464d4994298343b70c10682a07183e391a18e3", "max_stars_repo_licenses": ["MIT"], "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/Const.f90", "max_issues_repo_name": "taxus-d/integrators", "max_issues_repo_head_hexsha": "90464d4994298343b70c10682a07183e391a18e3", "max_issues_repo_licenses": ["MIT"], "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/Const.f90", "max_forks_repo_name": "taxus-d/integrators", "max_forks_repo_head_hexsha": "90464d4994298343b70c10682a07183e391a18e3", "max_forks_repo_licenses": ["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.6666666667, "max_line_length": 73, "alphanum_fraction": 0.5975903614, "num_tokens": 137, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8670357735451835, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.680890628545143}} {"text": "program test\n ! gfortran -O3 matr4.f90 -o matr4\n implicit none\n integer :: n, stat, i, j\n character(len=32) :: nstr\n real, allocatable :: fs(:), sines(:, :), res(:)\n real :: dt, tic, toc\n real, parameter :: pi = 4*atan(1.)\n\n if (command_argument_count() < 1) then\n stop 'ERROR must supply array size as command line argument'\n endif\n call get_command_argument(1, nstr)\n read(nstr, *, iostat=stat) n\n\n allocate(fs(n), sines(n, n), res(n))\n do j = 1, n\n fs(j) = j\n do i = 1, n\n sines(i, j) = sin(i*j*pi/real(n + 1, 8))\n enddo\n enddo\n\n call cpu_time(tic)\n res = matmul(sines, fs)\n call cpu_time(toc)\n dt = toc - tic\n print *,'matr4 n = ', n, ' time = ', dt, ' secs res = ', sum(res)\nend program test\n", "meta": {"hexsha": "b17b498ffbe3af9c3456be3467a6952fa9c89cbf", "size": 793, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "matr4.f90", "max_stars_repo_name": "chrisdjscott/fft_test", "max_stars_repo_head_hexsha": "f0634d75f5fcc174451bdbd81120ec413030bcd0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "matr4.f90", "max_issues_repo_name": "chrisdjscott/fft_test", "max_issues_repo_head_hexsha": "f0634d75f5fcc174451bdbd81120ec413030bcd0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "matr4.f90", "max_forks_repo_name": "chrisdjscott/fft_test", "max_forks_repo_head_hexsha": "f0634d75f5fcc174451bdbd81120ec413030bcd0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-07-13T23:41:55.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-13T23:41:55.000Z", "avg_line_length": 26.4333333333, "max_line_length": 69, "alphanum_fraction": 0.5472887768, "num_tokens": 271, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.867035752930664, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.6808906167129285}} {"text": "!> \\file mo_ode_solver.f90\n\n!> \\brief This module provides a set of iterative methods for the approximation of solutions\n!> of Ordinary Differential Equations (ODE).\n\n!> \\details\n!> It includes the possibilities to integrate a system of Ordinary Differential Equations using Euler,\n!> a fourth-order Runge-Kutta with fixed time-steps increments or a fourth-order Runge-Kutta with\n!> adaptive stepsize control.\n\n!> \\authors Giovanni Dalmasso, Sebastian Mueller\n!> \\date Mar 2015\nmodule mo_ode_solver\n\n ! This module provides a set of iterative methods for the approximation of solutions\n ! of Ordinary Differential Equations (ODE).\n\n ! Written Giovanni Dalmasso, Jul 2012\n ! Modified Giovanni Dalmasso, Mar 2013 - adapted to JAMS Fortran structure\n ! - collected together different methods\n ! - speeded up\n ! Apr 2013 - added documentation\n ! Modified Sebastian Mueller, Jan 2015 - added a parameter input for the derivatives to use the solver dynamically\n ! Mar 2015 - added RBstiff as a solver for stiff ODEs\n\n\n ! License\n ! -------\n ! This file is part of the JAMS Fortran package, distributed under the MIT License.\n !\n ! Copyright (c) 2012-2015 Giovanni Dalmasso, Sebastian Mueller\n !\n ! Permission is hereby granted, free of charge, to any person obtaining a copy\n ! of this software and associated documentation files (the \"Software\"), to deal\n ! in the Software without restriction, including without limitation the rights\n ! to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n ! copies of the Software, and to permit persons to whom the Software is\n ! furnished to do so, subject to the following conditions:\n !\n ! The above copyright notice and this permission notice shall be included in all\n ! copies or substantial portions of the Software.\n !\n ! THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n ! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n ! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n ! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n ! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n ! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n ! SOFTWARE.\n\n ! Note on Numerical Recipes License\n ! ---------------------------------\n ! Be aware that some code is under the Numerical Recipes License 3rd\n ! edition \n !\n ! The Numerical Recipes Personal Single-User License lets you personally\n ! use Numerical Recipes code (\"the code\") on any number of computers,\n ! but only one computer at a time. You are not permitted to allow anyone\n ! else to access or use the code. You may, under this license, transfer\n ! precompiled, executable applications incorporating the code to other,\n ! unlicensed, persons, providing that (i) the application is\n ! noncommercial (i.e., does not involve the selling or licensing of the\n ! application for a fee), and (ii) the application was first developed,\n ! compiled, and successfully run by you, and (iii) the code is bound\n ! into the application in such a manner that it cannot be accessed as\n ! individual routines and cannot practicably be unbound and used in\n ! other programs. That is, under this license, your application user\n ! must not be able to use Numerical Recipes code as part of a program\n ! library or \"mix and match\" workbench.\n !\n ! Businesses and organizations that purchase the disk or code download,\n ! and that thus acquire one or more Numerical Recipes Personal\n ! Single-User Licenses, may permanently assign those licenses, in the\n ! number acquired, to individual employees. Such an assignment must be\n ! made before the code is first used and, once made, it is irrevocable\n ! and can not be transferred.\n !\n ! If you do not hold a Numerical Recipes License, this code is only for\n ! informational and educational purposes but cannot be used.\n\n implicit none\n\n public :: Euler ! Euler method with equal time-steps increments\n public :: RK4 ! Fourth-order Runge-Kutta method with equal time-steps increments\n public :: RK4as ! Fourth-order Runge-Kutta method with adaptive stepsize control\n public :: RBstiff ! Rosenbrock Method for stiff ODEs with adaptive stepsize control\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! Euler\n\n ! PURPOSE\n ! Integration of Ordinary Differential Equations using Euler method.\n ! Starting from N initial values vstart known at x1, use Euler to advance nstep equal increments to x2.\n ! Results are stored in the variables xout and yout.\n\n !> \\brief Euler.\n\n !> \\details Starting from $N$ initial values $v_{start}$ known at $x_1$,\n !> use Euler to advance $n$-steps equal increments to $x_2$.\n !> Results are stored in the variables $x_{out}$ and $y_{out}$.\n !> If you use \"para\" as parameters for derivs, the interface for derivs has to look like:\n !>\n !> interface\n !> subroutine derivs( x, y, para, dydx )\n !> use mo_kind, only: sp/dp\n !> implicit none\n !> real(sp/dp), intent(in) :: x ! time\n !> real(sp/dp), dimension(:), intent(in) :: y ! unknowns of the equations\n !> real(sp/dp), dimension(:), intent(in) :: para ! parameter for the derivatives\n !> real(sp/dp), dimension(:), intent(out) :: dydx ! derivatives of y\n !> end subroutine derivs\n !> end interface\n !>\n !> Elsewise \"para\" must be left out:\n !>\n !> interface\n !> subroutine derivs( x, y, dydx )\n !> use mo_kind, only: sp/dp\n !> implicit none\n !> real(sp/dp), intent(in) :: x ! time\n !> real(sp/dp), dimension(:), intent(in) :: y ! unknowns of the equations\n !> real(sp/dp), dimension(:), intent(out) :: dydx ! derivatives of y\n !> end subroutine derivs\n !> end interface\n\n ! INTENT(IN)\n !> \\param[in] \"real(sp/dp), dimension(:) :: vstart\" initial conditions.\n !> $N$ inital values known at the time $x_1$\n !> (given $N$ ODEs)\n\n !> \\param[in] \"real(sp/dp) :: x1\" initial time.\n !> \\param[in] \"real(sp/dp) :: x2\" final time.\n !> \\param[in] \"real(sp/dp) :: h\" size of the incremental time step (fixed).\n !> \\param[in] \"interface :: derivs_sp/dp\" returns derivatives $dydx$ of $y$ at $x$.\n\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n !> \\param[out] \"real(sp/dp), dimension(:), allocatable :: xout\" storage for outputs (time).\n !> \\param[out] \"real(sp/dp), dimension(:), allocatable :: yout\" storage for outputs\n !> (incremented variables).\n !> dim 1 = function evaluation\n !> at any time point.\n !> dim 2 = number of equations.\n\n ! INTENT(IN), OPTIONAL\n !> \\param[in] \"real(sp/dp), dimension(:) :: para\" parameter for the derivatives $dydx$\n\n ! INTENT(INOUT), OPTIONAL\n ! None\n\n ! INTENT(OUT), OPTIONAL\n ! None\n\n ! RESTRICTIONS\n !> \\note The user has to supply the subroutine derivs(x,y,dydx), which returns derivatives $dydx$ at $x$.\n\n ! EXAMPLE\n ! call Euler( vstart, x1, x2, h, derivs, xout, yout )\n ! --> see example in test directory --> test_mo_ode_solver\n\n ! LITERATURE\n ! http://en.wikipedia.org/wiki/Euler_method\n\n ! HISTORY\n !> \\author Giovanni Dalmasso\n !> \\date Jul 2012\n ! Modified, Giovanni Dalmasso, Mar 2013\n ! Modified, Sebastian Mueller, Jan 2015\n interface Euler\n module procedure Euler_sp, Euler_dp, Euler_para_sp, Euler_para_dp\n end interface Euler\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! RK4\n\n ! PURPOSE\n ! Integration of Ordinary Differential Equations using a fourth-order Runge-Kutta method\n ! with fixed time-steps increments.\n ! Starting from N initial values vstart known at x1, use Euler to advance nstep equal increments to x2.\n ! Results are stored in the variables xout and yout.\n\n !> \\brief fourth-order Runge-Kutta.\n\n !> \\details Starting from $N$ initial values $v_{start}$ known at $x_1$,\n !> use a fourth-order Runge-Kutta with fixed time-steps increments\n !> to advance $n$-steps equal increments to $x_2$.\n !> Results are stored in the variables $x_{out}$ and $y_{out}$.\n !> If you use \"para\" as parameters for derivs, the interface for derivs has to look like:\n !>\n !> interface\n !> subroutine derivs( x, y, para, dydx )\n !> use mo_kind, only: sp/dp\n !> implicit none\n !> real(sp/dp), intent(in) :: x ! time\n !> real(sp/dp), dimension(:), intent(in) :: y ! unknowns of the equations\n !> real(sp/dp), dimension(:), intent(in) :: para ! parameter for the derivatives\n !> real(sp/dp), dimension(:), intent(out) :: dydx ! derivatives of y\n !> end subroutine derivs\n !> end interface\n !>\n !> Elsewise \"para\" must be left out:\n !>\n !> interface\n !> subroutine derivs( x, y, dydx )\n !> use mo_kind, only: sp/dp\n !> implicit none\n !> real(sp/dp), intent(in) :: x ! time\n !> real(sp/dp), dimension(:), intent(in) :: y ! unknowns of the equations\n !> real(sp/dp), dimension(:), intent(out) :: dydx ! derivatives of y\n !> end subroutine derivs\n !> end interface\n\n ! INTENT(IN)\n !> \\param[in] \"real(sp/dp), dimension(:) :: vstart\" initial conditions.\n !> $N$ inital values known at the time $x_1$\n !> (given $N$ ODEs)\n\n !> \\param[in] \"real(sp/dp) :: x1\" initial time.\n !> \\param[in] \"real(sp/dp) :: x2\" final time.\n !> \\param[in] \"real(sp/dp) :: h\" size of the incremental time step (fixed).\n !> \\param[in] \"interface :: derivs_sp/dp\" returns derivatives $dydx$ of $y$ at $x$.\n\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n !> \\param[out] \"real(sp/dp), dimension(:), allocatable :: xout\" storage for outputs (time).\n !> \\param[out] \"real(sp/dp), dimension(:), allocatable :: yout\" storage for outputs\n !> (incremented variables).\n !> dim 1 = function evaluation\n !> at any time point.\n !> dim 2 = number of equations.\n\n ! INTENT(IN), OPTIONAL\n !> \\param[in] \"real(sp/dp), dimension(:) :: para\" parameter for the derivatives $dydx$\n\n ! INTENT(INOUT), OPTIONAL\n ! None\n\n ! INTENT(OUT), OPTIONAL\n ! None\n\n ! RESTRICTIONS\n !> \\note The user has to supply the subroutine derivs(x,y,dydx), which returns derivatives $dydx$ at $x$.\n\n ! EXAMPLE\n ! call RK4( vstart, x1, x2, h, derivs, xout, yout )\n ! --> see example in test directory --> test_mo_ode_solver\n\n ! LITERATURE\n ! 1) Press WH, Teukolsky SA, Vetterling WT, & Flannery BP - Numerical Recipes in Fortran 77 -\n ! The Art of Parallel Scientific Computing, 2nd Edition, Volume 1 of Fortran Numerical Recipes,\n ! Cambridge University Press, UK, 1992\n ! 2) Press WH, Teukolsky SA, Vetterling WT, & Flannery BP - Numerical Recipes in Fortran 90 -\n ! The Art of Parallel Scientific Computing, 2nd Edition, Volume 2 of Fortran Numerical Recipes,\n ! Cambridge University Press, UK, 1996\n\n ! HISTORY\n !> \\author Giovanni Dalmasso\n !> \\date Jul 2012\n ! Modified, Giovanni Dalmasso, Mar 2013\n ! Modified, Sebastian Mueller, Jan 2015\n interface RK4\n module procedure RK4_sp, RK4_dp, RK4_para_sp, RK4_para_dp\n end interface RK4\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! RK4as\n\n ! PURPOSE\n ! Integration of Ordinary Differential Equations using a fourth-order Runge-Kutta method\n ! with adaptive stepsize control.\n ! Integrate the array of starting values ystart from x1 to x2 with accuracy eps, storing intermediate results\n ! in the module variables. h1 should be set as a guessed first stepsize,\n ! hmin as the minimum allowed stepsize (can be zero).\n ! On output ystart is replaced by values at the end of the integration interval.\n\n !> \\brief fourth-order Runge-Kutta with adaptive stepsize control.\n\n !> \\details Integrate the array of starting values $y_{start} from $x_1$ to $x_2$ with accuracy $\\varepsilon$,\n !> storing intermediate results in the module variables.\n !> $h_1$ should be set as a guessed first stepsize, $h_{min} as the minimum allowed stepsize (can be zero).\n !> On output $y_{start}$ is replaced by values at the end of the integration interval.\n !> If you use \"para\" as parameters for derivs, the interface for derivs has to look like:\n !>\n !> interface\n !> subroutine derivs( x, y, para, dydx )\n !> use mo_kind, only: sp/dp\n !> implicit none\n !> real(sp/dp), intent(in) :: x ! time\n !> real(sp/dp), dimension(:), intent(in) :: y ! unknowns of the equations\n !> real(sp/dp), dimension(:), intent(in) :: para ! parameter for the derivatives\n !> real(sp/dp), dimension(:), intent(out) :: dydx ! derivatives of y\n !> end subroutine derivs\n !> end interface\n !>\n !> Elsewise \"para\" must be left out:\n !>\n !> interface\n !> subroutine derivs( x, y, dydx )\n !> use mo_kind, only: sp/dp\n !> implicit none\n !> real(sp/dp), intent(in) :: x ! time\n !> real(sp/dp), dimension(:), intent(in) :: y ! unknowns of the equations\n !> real(sp/dp), dimension(:), intent(out) :: dydx ! derivatives of y\n !> end subroutine derivs\n !> end interface\n\n ! INTENT(IN)\n !> \\param[in] \"real(sp/dp), dimension(:) :: vstart\" initial conditions.\n !> $N$ inital values known at the time $x_1$\n !> (given $N$ ODEs)\n !> \\param[in] \"real(sp/dp) :: x1\" initial time.\n !> \\param[in] \"real(sp/dp) :: x2\" final time.\n !> \\param[in] \"real(sp/dp) :: h\" guessed first stepsize.\n !> \\param[in] \"interface :: derivs_sp/dp\" derivatives $dydx$ of $y$ at $x$.\n\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n !> \\param[out] \"real(sp/dp), dimension(:), allocatable :: xout\" storage for outputs (time).\n !> \\param[out] \"real(sp/dp), dimension(:), allocatable :: yout\" storage for outputs\n !> (incremented variables).\n !> dim 1 = function evaluations\n !> at any time point.\n !> dim 2 = number of equations.\n\n ! INTENT(IN), OPTIONAL\n !> \\param[in] \"real(sp/dp), optional :: hmin\" minimum allowed stepsize (can be 0.)\n !> DEFAULT: 0.0\n !> \\param[in] \"real(sp/dp), optional :: eps\" accuracy (overall tolerance level)\n !> DEFAULT: 1E-6\n !> \\param[in] \"real(sp/dp), dimension(:) :: para\" parameter for the derivatives $dydx$\n\n ! INTENT(INOUT), OPTIONAL\n ! None\n\n ! INTENT(OUT), OPTIONAL\n ! None\n\n ! RESTRICTIONS\n !> \\note The user has to supply the subroutine derivs(x,y,dydx), which returns derivatives $dydx$ at $x$.\n\n ! EXAMPLE\n ! call RK4as( ystart, x1, x2, h, derivs, xout, yout, hmin, eps )\n ! --> see example in test directory --> test_mo_ode_solver\n\n ! LITERATURE\n ! 1) Press WH, Teukolsky SA, Vetterling WT, & Flannery BP - Numerical Recipes in Fortran 77 -\n ! The Art of Parallel Scientific Computing, 2nd Edition, Volume 1 of Fortran Numerical Recipes,\n ! Cambridge University Press, UK, 1992\n ! 2) Press WH, Teukolsky SA, Vetterling WT, & Flannery BP - Numerical Recipes in Fortran 90 -\n ! The Art of Parallel Scientific Computing, 2nd Edition, Volume 2 of Fortran Numerical Recipes,\n ! Cambridge University Press, UK, 1996\n\n ! HISTORY\n !> \\author Giovanni Dalmasso\n !> \\date Jul 2012\n ! Modified, Giovanni Dalmasso, Mar 2013\n ! Modified, Sebastian Mueller, Jan 2015\n interface RK4as\n module procedure RK4as_sp, RK4as_dp, RK4as_para_sp, RK4as_para_dp\n end interface RK4as\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! RBstiff\n\n ! PURPOSE\n ! Integration of Ordinary Differential Equations using a Rosenbrock Method\n ! with adaptive stepsize control.\n ! Integrate the array of starting values ystart from x1 to x2 with accuracy eps, storing intermediate results\n ! in the module variables. h1 should be set as a guessed first stepsize,\n ! hmin as the minimum allowed stepsize (can be zero).\n ! On output ystart is replaced by values at the end of the integration interval.\n\n !> \\brief Rosenbrock Method with adaptive stepsize control.\n\n !> \\details Integrate the array of starting values $y_{start} from $x_1$ to $x_2$ with accuracy $\\varepsilon$,\n !> storing intermediate results in the module variables.\n !> $h_1$ should be set as a guessed first stepsize, $h_{min} as the minimum allowed stepsize (can be zero).\n !> On output $y_{start}$ is replaced by values at the end of the integration interval.\n !> If you use \"para\" as parameters for derivs/jacobn, the interface for derivs has to look like:\n !>\n !> interface\n !> subroutine derivs( x, y, para, dydx )\n !> use mo_kind, only: sp/dp\n !> implicit none\n !> real(sp/dp), intent(in) :: x ! time\n !> real(sp/dp), dimension(:), intent(in) :: y ! unknowns of the equations\n !> real(sp/dp), dimension(:), intent(in) :: para ! parameter for the derivatives\n !> real(sp/dp), dimension(:), intent(out) :: dydx ! derivatives of y\n !> end subroutine derivs\n !> subroutine jacobn(x, y, para, dfdx, dfdy)\n !> use mo_kind, only: sp\n !> implicit none\n !> real(sp/dp), intent(in) :: x ! time\n !> real(sp/dp),dimension(:), intent(in) :: y ! unknowns of the equations\n !> real(sp/dp),dimension(:), intent(in) :: para ! parameters for derivs\n !> real(sp/dp),dimension(:), intent(out) :: dfdx ! derivatives of f for x\n !> real(sp/dp),dimension(:,:), intent(out) :: dfdy ! jacobi-matrix df/dy\n !> end subroutine jacobn\n !> end interface\n !>\n !> Elsewise \"para\" must be left out:\n !>\n !> interface\n !> subroutine derivs( x, y, dydx )\n !> use mo_kind, only: sp/dp\n !> implicit none\n !> real(sp/dp), intent(in) :: x ! time\n !> real(sp/dp), dimension(:), intent(in) :: y ! unknowns of the equations\n !> real(sp/dp), dimension(:), intent(out) :: dydx ! derivatives of y\n !> end subroutine derivs\n !> subroutine jacobn(x, y, dfdx, dfdy)\n !> use mo_kind, only: sp\n !> implicit none\n !> real(sp/dp), intent(in) :: x ! time\n !> real(sp/dp),dimension(:), intent(in) :: y ! unknowns of the equations\n !> real(sp/dp),dimension(:), intent(out) :: dfdx ! derivatives of f for x\n !> real(sp/dp),dimension(:,:), intent(out) :: dfdy ! jacobi-matrix df/dy\n !> end subroutine jacobn\n !> end interface\n\n ! INTENT(IN)\n !> \\param[in] \"real(sp/dp), dimension(:) :: vstart\" initial conditions.\n !> $N$ inital values known at the time $x_1$\n !> (given $N$ ODEs)\n !> \\param[in] \"real(sp/dp) :: x1\" initial time.\n !> \\param[in] \"real(sp/dp) :: x2\" final time.\n !> \\param[in] \"real(sp/dp) :: h\" guessed first stepsize.\n !> \\param[in] \"interface :: derivs_sp/dp\" derivatives $dydx$ of $y$ at $x$.\n !> \\param[in] \"interface :: jacobn_sp/dp\" derivatives of the RHS: $dfdx$ and $dfdy$\n\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n !> \\param[out] \"real(sp/dp), dimension(:), allocatable :: xout\" storage for outputs (time).\n !> \\param[out] \"real(sp/dp), dimension(:), allocatable :: yout\" storage for outputs\n !> (incremented variables).\n !> dim 1 = function evaluations\n !> at any time point.\n !> dim 2 = number of equations.\n\n ! INTENT(IN), OPTIONAL\n !> \\param[in] \"real(sp/dp), optional :: hmin\" minimum allowed stepsize (can be 0.)\n !> DEFAULT: 0.0\n !> \\param[in] \"real(sp/dp), optional :: eps\" accuracy (overall tolerance level)\n !> DEFAULT: 1E-6\n !> \\param[in] \"real(sp/dp), dimension(:) :: para\" parameter for the derivatives\n\n ! INTENT(INOUT), OPTIONAL\n ! None\n\n ! INTENT(OUT), OPTIONAL\n ! None\n\n ! RESTRICTIONS\n !> \\note The user has to supply the subroutine derivs(x,y,dydx), which returns derivatives $dydx$ at $x$.\n\n ! EXAMPLE\n ! call RK4as( ystart, x1, x2, h, derivs, jacobn, xout, yout, hmin, eps )\n ! --> see example in test directory --> test_mo_ode_solver\n\n ! LITERATURE\n ! 1) Press WH, Teukolsky SA, Vetterling WT, & Flannery BP - Numerical Recipes in Fortran 77 -\n ! The Art of Parallel Scientific Computing, 2nd Edition, Volume 1 of Fortran Numerical Recipes,\n ! Cambridge University Press, UK, 1992\n ! 2) Press WH, Teukolsky SA, Vetterling WT, & Flannery BP - Numerical Recipes in Fortran 90 -\n ! The Art of Parallel Scientific Computing, 2nd Edition, Volume 2 of Fortran Numerical Recipes,\n ! Cambridge University Press, UK, 1996\n\n ! HISTORY\n !> \\author Sebastian Mueller\n !> \\date Mar 2015\n interface RBstiff\n module procedure RBstiff_sp, RBstiff_dp, RBstiff_para_sp, RBstiff_para_dp\n end interface RBstiff\n\n private\n\n ! Private method\n interface CashKarpRK\n module procedure CashKarpRK_sp, CashKarpRK_dp, CashKarpRK_para_sp, CashKarpRK_para_dp\n end interface CashKarpRK\n\n interface RBstep\n module procedure RBstep_sp, RBstep_dp, RBstep_para_sp, RBstep_para_dp\n end interface RBstep\n\n ! ------------------------------------------------------------------\n\ncontains\n\n ! ------------------------------------------------------------------\n\n ! SINGLE PRECISION Euler\n subroutine Euler_sp( ystart, x1, x2, h, derivs, xout, yout ) ! all obligatory\n\n use mo_kind, only: i4, sp\n\n implicit none\n\n ! Intent IN\n real(sp), dimension(:), intent(in) :: ystart ! initial conditions\n real(sp), intent(in) :: x1, x2 ! initial and final time\n real(sp), intent(in) :: h ! step size\n\n ! Intent OUT\n real(sp), dimension(:), allocatable, intent(out) :: xout\n real(sp), dimension(:,:), allocatable, intent(out) :: yout\n\n interface\n subroutine derivs( x, y, dydx )\n use mo_kind, only: sp\n implicit none\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 end subroutine derivs\n end interface\n\n ! Internal variables\n integer(i4) :: j ! counter\n integer(i4) :: nstep ! number of steps\n real(sp) :: x\n real(sp), dimension( size(ystart) ) :: dy, y\n\n y(:) = ystart(:) ! load starting values\n nstep = nint( (x2-x1)/h, i4 ) ! find number of steps\n\n if ( allocated(xout) ) deallocate(xout) ! clear out old stored variables if necessary\n if ( allocated(yout) ) deallocate(yout)\n allocate( xout(nstep+1_i4) ) ! allocate storage for saved values\n allocate( yout(nstep+1_i4, size(ystart)) )\n\n yout(1,:) = y(:)\n xout(1) = x1\n x = x1\n\n do j=1, nstep ! take nstep steps\n call derivs( x, y, dy )\n y = y + h*dy ! step EULER\n if ( h .lt. tiny(1._sp) ) stop 'Euler_sp --> stepsize not significant!'\n x = x+h\n xout(j+1_i4) = x ! store intermediate steps\n yout(j+1_i4,:) = y(:)\n end do\n\n end subroutine Euler_sp\n\n\n ! DOUBLE PRECISION Euler\n subroutine Euler_dp( ystart, x1, x2, h, derivs, xout, yout ) ! all obligatory\n\n use mo_kind, only: i4, dp\n\n implicit none\n\n ! Intent IN\n real(dp), dimension(:), intent(in) :: ystart ! initial conditions\n real(dp), intent(in) :: x1, x2 ! initial and final time\n real(dp), intent(in) :: h ! step size\n\n ! Intent OUT\n real(dp), dimension(:), allocatable, intent(out) :: xout\n real(dp), dimension(:,:), allocatable, intent(out) :: yout\n\n interface\n subroutine derivs( x, y, dydx )\n use mo_kind, only: dp\n implicit none\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 end subroutine derivs\n end interface\n\n ! Internal variables\n integer(i4) :: j ! counter\n integer(i4) :: nstep ! nuber of steps\n real(dp) :: x\n real(dp), dimension( size(ystart) ) :: dy, y\n\n y(:) = ystart(:) ! load starting values\n nstep = nint( (x2-x1)/h, i4 ) ! find number of steps\n\n if ( allocated(xout) ) deallocate(xout) ! clear out old stored variables if necessary\n if ( allocated(yout) ) deallocate(yout)\n allocate( xout(nstep+1_i4) ) ! allocate storage for saved values\n allocate( yout(nstep+1_i4, size(ystart)) )\n\n yout(1,:) = y(:)\n xout(1) = x1\n x = x1\n\n do j=1, nstep ! take nstep steps\n call derivs( x, y, dy )\n y = y + h*dy ! step EULER\n if ( h .lt. tiny(1._dp) ) stop 'Euler_dp --> stepsize not significant!'\n x = x+h\n xout(j+1_i4) = x ! store intermediate steps\n yout(j+1_i4,:) = y(:)\n end do\n\n end subroutine Euler_dp\n\n ! ------------------------------------------------------------------\n\n ! SINGLE PRECISION 4th order RUNGE-KUTTA\n subroutine RK4_sp( ystart, x1, x2, h, derivs, xout, yout ) ! all obligatory\n\n use mo_kind, only: i4, sp\n\n implicit none\n\n ! Intent IN\n real(sp), dimension(:), intent(in) :: ystart ! initial conditions\n real(sp), intent(in) :: x1, x2 ! initial and final time\n real(sp), intent(in) :: h ! step size\n\n ! Intent OUT\n real(sp), dimension(:), allocatable, intent(out) :: xout\n real(sp), dimension(:,:), allocatable, intent(out) :: yout\n\n interface\n subroutine derivs( x, y, dydx )\n use mo_kind, only: sp\n implicit none\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 end subroutine derivs\n end interface\n\n ! Internal variables\n integer(i4) :: j ! counter\n integer(i4) :: nstep ! nuber of steps\n real(sp) :: x\n real(sp) :: hh, h6, xh\n real(sp), dimension( size(ystart) ) :: dy, dyt, dym, y, yt\n\n y(:) = ystart(:) ! load starting values\n nstep = nint( (x2-x1)/h, i4 ) ! find number of steps\n\n if ( allocated(xout) ) deallocate(xout) ! clear out old stored variables if necessary\n if ( allocated(yout) ) deallocate(yout)\n allocate( xout(nstep+1_i4) ) ! allocate storage for saved values\n allocate( yout(nstep+1_i4, size(ystart)) )\n\n yout(1,:) = y(:)\n xout(1) = x1\n x = x1\n\n hh = h*0.5_sp\n h6 = h/6.0_sp\n xh = x+hh\n\n do j=1, nstep ! take nstep steps\n call derivs( x, y, dy )\n yt = y + hh*dy ! first step\n call derivs( xh, yt, dyt ) ! second step\n yt = y + hh*dyt\n call derivs( xh, yt, dym ) ! third step\n yt = y + h*dym\n dym = dyt + dym\n call derivs( x+h, yt, dyt ) ! fourth step\n y = y + h6*( dy+dyt+2.0_sp*dym ) ! accumulate increments with proper weights\n if ( h .lt. tiny(1._sp) ) stop 'RK4_sp --> stepsize not significant!'\n x = x+h\n xout(j+1_i4) = x ! store intermediate steps\n yout(j+1_i4,:) = y(:)\n end do\n\n end subroutine RK4_sp\n\n\n ! DOUBLE PRECISION 4th order RUNGE-KUTTA\n subroutine RK4_dp( ystart, x1, x2, h, derivs, xout, yout ) ! all obligatory\n\n use mo_kind, only: i4, dp\n\n implicit none\n\n ! Intent IN\n real(dp), dimension(:), intent(in) :: ystart ! initial conditions\n real(dp), intent(in) :: x1, x2 ! initial and final time\n real(dp), intent(in) :: h ! step size\n\n ! Intent OUT\n real(dp), dimension(:), allocatable, intent(out) :: xout\n real(dp), dimension(:,:), allocatable, intent(out) :: yout\n\n interface\n subroutine derivs( x, y, dydx )\n use mo_kind, only: dp\n implicit none\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 end subroutine derivs\n end interface\n\n ! Internal variables\n integer(i4) :: j ! counter\n integer(i4) :: nstep ! nuber of steps\n real(dp) :: x\n real(dp) :: hh, h6, xh\n real(dp), dimension( size(ystart) ) :: dy, dyt, dym, y, yt\n\n y(:) = ystart(:) ! load starting values\n nstep = nint( (x2-x1)/h, i4 ) ! find number of steps\n\n if ( allocated(xout) ) deallocate(xout) ! clear out old stored variables if necessary\n if ( allocated(yout) ) deallocate(yout)\n allocate( xout(nstep+1_i4) ) ! allocate storage for saved values\n allocate( yout(nstep+1_i4, size(ystart)) )\n\n yout(1,:) = y(:)\n xout(1) = x1\n x = x1\n\n hh = h*0.5_dp\n h6 = h/6.0_dp\n xh = x+hh\n\n do j=1, nstep ! take nstep steps\n call derivs( x, y, dy )\n yt = y + hh*dy ! first step\n call derivs( xh, yt, dyt ) ! second step\n yt = y + hh*dyt\n call derivs( xh, yt, dym ) ! third step\n yt = y + h*dym\n dym = dyt + dym\n call derivs( x+h, yt, dyt ) ! fourth step\n y = y + h6*( dy+dyt+2.0_dp*dym ) ! accumulate increments with proper weights\n if ( h .lt. tiny(1._dp) ) stop 'RK4_sp --> stepsize not significant!'\n x = x+h\n xout(j+1_i4) = x ! store intermediate steps\n yout(j+1_i4,:) = y(:)\n end do\n\n end subroutine RK4_dp\n\n ! ------------------------------------------------------------------\n\n ! SINGLE PRECISION 4th order RUNGE-KUTTA Adaptive Step-size\n subroutine RK4as_sp( ystart, x1, x2, h, derivs, xout, yout, & ! obligatory\n hmin, eps ) ! optional\n\n use mo_kind, only: i4, sp\n use mo_nrutil, only: reallocate\n\n implicit none\n\n ! Intent IN\n real(sp), intent(in) :: x1, x2 ! initial and final time\n real(sp), intent(in) :: h ! guessed step size\n real(sp), dimension(:), intent(in) :: ystart ! initial conditions\n real(sp), optional, intent(in) :: hmin\n real(sp), optional, intent(in) :: eps\n\n ! Intent OUT\n real(sp), dimension(:), allocatable, intent(out) :: xout\n real(sp), dimension(:,:), allocatable, intent(out) :: yout\n\n interface\n subroutine derivs( x, y, dydx )\n use mo_kind, only: sp\n implicit none\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 end subroutine derivs\n end interface\n\n ! Internal variables\n integer(i4) :: nstep ! nuber of steps\n integer(i4) :: nok, nbad ! number of good and bad (but retried and fixed) steps taken\n integer(i4) :: kount ! total number of saved steps\n real(sp) :: hIN, hdid, hnext, x, hminIN, epsIN, xsav, dxsav, errmax, htemp, xnew\n real(sp), dimension(size(ystart)) :: dydx, y, yscal, yerr, ytemp\n ! Pointers\n real(sp), dimension(:), pointer :: xp\n real(sp), dimension(:,:), pointer :: yp\n\n ! parameters\n integer(i4), parameter :: MAXstp = 1000000_i4 ! max number of steps\n real(sp), parameter :: safety = 0.9_sp, pgrow = -0.2_sp, pshrnk = -0.25_sp\n real(sp) :: errcon\n\n errcon = exp( (1._sp/pgrow)*log(5._sp/safety) )\n\n if( present(hmin) ) then\n hminIN = hmin\n else\n hminIN = 0.0_sp\n end if\n\n if( present(eps) ) then\n epsIN = eps\n else\n epsIN = 1e-6_sp\n end if\n\n x = x1\n hIN = sign( h, x2-x1 )\n nok = 0_i4\n nbad = 0_i4\n kount = 0_i4\n y(:) = ystart(:)\n dxsav = tiny(1._sp)\n\n xsav = x-2.0_sp*dxsav ! assures storage of first step\n nullify( xp, yp )\n allocate( xp(256) )\n allocate( yp(size(xp), size(ystart)) )\n\n call save_a_step ! save initial step\n\n do nstep=1, MAXstp ! take at most MAXstp steps\n\n call derivs( x, y, dydx )\n yscal(:) = abs( y(:) ) + abs( hIN*dydx(:) ) + tiny(1._sp) ! scaling used to monitor accuracy\n ! --> CAN BE MODIFIED...\n\n if ( abs(x-xsav) .gt. abs(dxsav) ) call save_a_step ! store intermediate results\n\n if ( (x+hIN-x2)*(x+hIN-x1) .gt. 0.0_sp ) hIN = x2-x ! if stepsize can overshoot, decrease\n\n do\n call CashKarpRK( y, dydx, x, hIN, ytemp, yerr, derivs ) ! take a step\n errmax = maxval( abs(yerr(:)/yscal(:)) )/epsIN ! evaluate accuracy\n if ( errmax .lt. 1.0_sp ) exit ! step succeeded\n htemp = safety*hIN*(errmax**pshrnk) ! truncation error too large, reduce stepsize\n hIN = sign( max( abs(htemp), 0.1_sp*abs(hIN) ), hIN ) ! no more than a factor of 10\n xnew = x+hIN\n if ( abs(xnew-x) .lt. epsilon(1.0_sp) ) stop 'RK4as_sp --> hey !!! stepsize underflow!'\n end do\n\n if ( errmax .gt. errcon ) then ! compute size of next step\n hnext = safety*hIN*(errmax**pgrow)\n else ! no more than a factor of 5 increase\n hnext = 5.0_sp*hIN\n end if\n\n hdid = hIN\n x = x+hIN\n y(:) = ytemp(:)\n\n if ( abs(hdid-hIN) .gt. epsilon(1.0_sp) ) then\n nbad = nbad+1_i4\n else\n nok = nok+1_i4\n end if\n\n if ( (x-x2)*(x2-x1) .ge. 0.0_sp ) then ! are we done?!?!\n call save_a_step ! save final step\n allocate( xout(kount) ) ! allocate storage for outputs\n xout(:) = xp(1:kount)\n allocate( yout(kount, size(yp,2)) ) ! allocate storage for outputs\n yout(:,:) = yp(1:kount, :)\n deallocate( xp, yp ) ! clear out old stored variables\n return ! normal exit\n end if\n\n if ( abs(hnext-hminIN) .lt. epsilon(1.0_sp) ) stop 'RK4as_sp --> WTF! ...stepsize smaller than minimum!!!'\n hIN = hnext\n\n end do\n\n stop 'RK4as_sp --> dude, too many steps!!!'\n\n contains\n\n subroutine save_a_step ! --> like a macro in C\n kount = kount+1\n if ( kount .gt. size(xp) ) then\n xp=>reallocate( xp, 2*size(xp) )\n yp=>reallocate( yp, size(xp), size(yp,2) )\n end if\n xp(kount) = x\n yp(kount, :) = y(:)\n xsav = x\n end subroutine save_a_step\n\n end subroutine RK4as_sp\n\n\n ! DOUBLE PRECISION 4th order RUNGE-KUTTA Adaptive Step-size\n subroutine RK4as_dp( ystart, x1, x2, h, derivs, xout, yout, & ! obligatory\n hmin, eps ) ! optional\n\n use mo_kind, only: i4, dp\n use mo_nrutil, only: reallocate\n\n implicit none\n\n ! Intent IN\n real(dp), intent(in) :: x1, x2 ! initial and final time\n real(dp), intent(in) :: h ! guessed step size\n real(dp), dimension(:), intent(in) :: ystart ! initial conditions\n real(dp), optional, intent(in) :: hmin\n real(dp), optional, intent(in) :: eps\n\n ! Intent OUT\n real(dp), dimension(:), allocatable, intent(out) :: xout\n real(dp), dimension(:,:), allocatable, intent(out) :: yout\n\n interface\n subroutine derivs( x, y, dydx )\n use mo_kind, only: dp\n implicit none\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 end subroutine derivs\n end interface\n\n ! Internal variables\n integer(i4) :: nstep ! nuber of steps\n integer(i4) :: nok, nbad ! number of good and bad (but retried and fixed) steps taken\n integer(i4) :: kount ! total number of saved steps\n real(dp) :: hIN, hdid, hnext, x, hminIN, epsIN, xsav, dxsav, errmax, htemp, xnew\n real(dp), dimension(size(ystart)) :: dydx, y, yscal, yerr, ytemp\n ! Pointers\n real(dp), dimension(:), pointer :: xp\n real(dp), dimension(:,:), pointer :: yp\n\n ! parameters\n integer(i4), parameter :: MAXstp = 1000000_i4 ! max nuber of steps\n real(dp), parameter :: safety = 0.9_dp, pgrow = -0.2_dp, pshrnk = -0.25_dp\n real(dp) :: errcon\n\n errcon = exp( (1._dp/pgrow)*log(5._dp/safety) )\n\n if( present(hmin) ) then\n hminIN = hmin\n else\n hminIN = 0.0_dp\n end if\n\n if( present(eps) ) then\n epsIN = eps\n else\n epsIN = 1e-6_dp\n end if\n\n x = x1\n hIN = sign( h, x2-x1 )\n nok = 0_i4\n nbad = 0_i4\n kount = 0_i4\n y(:) = ystart(:)\n dxsav = tiny(1._dp)\n\n xsav = x-2.0_dp*dxsav ! assures storage of first step\n nullify( xp, yp )\n allocate( xp(256) )\n allocate( yp(size(xp), size(ystart)) )\n\n call save_a_step ! save initial step\n\n do nstep=1, MAXstp ! take at most MAXstp steps\n\n call derivs( x, y, dydx )\n yscal(:) = abs( y(:) ) + abs( hIN*dydx(:) ) + tiny(1._dp) ! scaling used to monitor accuracy --> CAN BE MODIFIED...\n\n if ( abs(x-xsav) .gt. abs(dxsav) ) call save_a_step ! store intermediate results\n\n if ( (x+hIN-x2)*(x+hIN-x1) .gt. 0.0_dp ) hIN = x2-x ! if stepsize can overshoot, decrease\n\n do\n call CashKarpRK( y, dydx, x, hIN, ytemp, yerr, derivs ) ! take a step\n errmax = maxval( abs(yerr(:)/yscal(:)) )/epsIN ! evaluate accuracy\n if ( errmax .lt. 1.0_dp ) exit ! step succeeded\n htemp = safety*hIN*(errmax**pshrnk) ! truncation error too large, reduce stepsize\n hIN = sign( max( abs(htemp), 0.1_dp*abs(hIN) ), hIN ) ! no more than a factor of 10\n xnew = x+hIN\n if ( abs(xnew-x) .lt. epsilon(1._dp) ) stop 'RK4as_dp --> hey!!! stepsize underflow!'\n end do\n\n if ( errmax .gt. errcon ) then ! compute size of next step\n hnext = safety*hIN*(errmax**pgrow)\n else ! no more than a factor of 5 increase\n hnext = 5.0_dp*hIN\n end if\n\n hdid = hIN\n x = x+hIN\n y(:) = ytemp(:)\n\n if ( abs(hdid-hIN) .gt. epsilon(1._dp) ) then\n nbad = nbad+1_i4\n else\n nok = nok+1_i4\n end if\n\n if ( (x-x2)*(x2-x1) .ge. 0.0_dp ) then ! are we done?!?!\n call save_a_step ! save final step\n allocate( xout(kount) ) ! allocate storage for outputs\n xout(:) = xp(1:kount)\n allocate( yout(kount, size(yp,2)) ) ! allocate storage for outputs\n yout(:,:) = yp(1:kount, :)\n deallocate( xp, yp ) ! clear out old stored variables\n return ! normal exit\n end if\n\n if ( abs(hnext-hminIN) .lt. epsilon(1.0_dp) ) stop 'RK4as_dp --> WTF! ...stepsize smaller than minimum!!!'\n hIN = hnext\n\n end do\n\n stop 'RK4as_dp --> dude, too many steps!!!'\n\n contains\n\n subroutine save_a_step ! --> like a macro in C\n kount = kount+1\n if ( kount .gt. size(xp) ) then\n xp=>reallocate( xp, 2*size(xp) )\n yp=>reallocate( yp, size(xp), size(yp,2) )\n end if\n xp(kount) = x\n yp(kount, :) = y(:)\n xsav = x\n end subroutine save_a_step\n\n end subroutine RK4as_dp\n\n ! ------------------------------------------------------------------\n\n ! SINGLE PRECISION Rosenbrock Method for stiff ode's\n subroutine RBstiff_sp( ystart, x1, x2, h, derivs, jacobn, xout, yout, & ! obligatory\n hmin, eps ) ! optional\n\n use mo_kind, only : i4, sp\n use mo_utils, only : ge\n use mo_nrutil, only : reallocate\n\n implicit none\n\n ! Intent IN\n real(sp), intent(in) :: x1, x2 ! initial and final time\n real(sp), intent(in) :: h ! guessed step size\n real(sp), dimension(:), intent(in) :: ystart ! initial conditions\n real(sp), optional, intent(in) :: hmin\n real(sp), optional, intent(in) :: eps\n\n ! Intent OUT\n real(sp), dimension(:), allocatable, intent(out) :: xout\n real(sp), dimension(:,:), allocatable, intent(out) :: yout\n\n interface\n subroutine derivs( x, y, dydx )\n use mo_kind, only: sp\n implicit none\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 end subroutine derivs\n\n subroutine jacobn(x, y, dfdx, dfdy)\n use mo_kind, only: sp\n implicit none\n real(sp), intent(in) :: x\n real(sp), dimension(:), intent(in) :: y\n real(sp), dimension(:), intent(out) :: dfdx\n real(sp), dimension(:,:), intent(out) :: dfdy\n end subroutine jacobn\n end interface\n\n ! Internal variables\n integer(i4) :: n \n integer(i4) :: nstep ! nuber of steps\n integer(i4) :: kount ! total number of saved steps\n real(sp) :: hIN, hdid, hnext, x, hminIN, epsIN, xsav, dxsav\n real(sp), dimension(size(ystart)) :: dydx, y, yscal, C\n\n ! Pointers\n real(sp), dimension(:), pointer :: xp\n real(sp), dimension(:,:), pointer :: yp\n\n ! parameters\n integer(i4), parameter :: MAXstp = 1000000_i4 ! max number of steps\n\n\n if( present(hmin) ) then\n hminIN = abs(hmin)\n else\n hminIN = 0.0_sp\n end if\n\n if( present(eps) ) then\n epsIN = abs(eps)\n else\n epsIN = 1e-6_sp\n end if\n \n C = 1.0_sp !lower boundary for scaling\n\n hIN = sign( h, x2-x1 )\n hnext = 0.0_sp\n hdid = 0.0_sp\n\n kount = 0_i4\n\n x = x1\n y(:) = ystart(:)\n dxsav = tiny(1._sp)\n xsav = x-2.0_sp*dxsav ! assures storage of first step\n\n nullify( xp, yp )\n allocate( xp(256) )\n allocate( yp(size(xp), size(ystart)) )\n\n call save_a_step ! save initial step\n\n do nstep=1, MAXstp ! take at most MAXstp steps\n\n call derivs( x, y, dydx )\n forall( n = 1:size(yscal) ) yscal(n) = max (abs(y(n)),C(n)) ! scaling used to monitor accuracy --> CAN BE MODIFIED...\n\n if ( abs(x-xsav) .gt. abs(dxsav) ) call save_a_step ! store intermediate results\n\n if ( (x+hIN-x2)*(x+hIN-x1) .gt. 0.0_sp ) hIN = x2-x ! if stepsize can overshoot, decrease\n\n call RBstep( y, dydx, x, hIN, epsIN, yscal, hdid, hnext, derivs, jacobn) !do one Rosenbrock-Step\n\n if ( ge((x-x2)*(x2-x1), 0.0_sp) ) then ! are we done?!?!\n call save_a_step ! save final step\n allocate( xout(kount) ) ! allocate storage for outputs\n xout(:) = xp(1:kount)\n allocate( yout(kount, size(yp,2)) ) ! allocate storage for outputs\n yout(:,:) = yp(1:kount, :)\n deallocate( xp, yp ) ! clear out old stored variables\n return ! normal exit\n end if\n\n if ( abs(hnext-hminIN) .lt. epsilon(1.0_sp) ) stop 'RBstiff_sp --> WTF! ...stepsize smaller than minimum!!!'\n \n hIN = hnext\n\n end do\n\n stop 'RBstiff_sp --> dude, too many steps!!!'\n\n contains\n\n subroutine save_a_step ! --> like a macro in C\n kount = kount+1_i4\n if ( kount .gt. size(xp) ) then\n xp=>reallocate( xp, 2*size(xp) )\n yp=>reallocate( yp, size(xp), size(yp,2) )\n end if\n xp(kount) = x\n yp(kount, :) = y(:)\n xsav = x\n end subroutine save_a_step\n\n end subroutine RBstiff_sp\n\n ! DOUBLE PRECISION Rosenbrock Method for stiff ode's\n subroutine RBstiff_dp( ystart, x1, x2, h, derivs, jacobn, xout, yout, & ! obligatory\n hmin, eps ) ! optional\n\n use mo_kind, only : i4, dp\n use mo_utils, only : ge\n use mo_nrutil, only : reallocate\n\n implicit none\n\n ! Intent IN\n real(dp), intent(in) :: x1, x2 ! initial and final time\n real(dp), intent(in) :: h ! guessed step size\n real(dp), dimension(:), intent(in) :: ystart ! initial conditions\n real(dp), optional, intent(in) :: hmin\n real(dp), optional, intent(in) :: eps\n\n ! Intent OUT\n real(dp), dimension(:), allocatable, intent(out) :: xout\n real(dp), dimension(:,:), allocatable, intent(out) :: yout\n\n interface\n subroutine derivs( x, y, dydx )\n use mo_kind, only: dp\n implicit none\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 end subroutine derivs\n\n subroutine jacobn(x, y, dfdx, dfdy)\n use mo_kind, only: dp\n implicit none\n real(dp), intent(in) :: x\n real(dp), dimension(:), intent(in) :: y\n real(dp), dimension(:), intent(out) :: dfdx\n real(dp), dimension(:,:), intent(out) :: dfdy\n end subroutine jacobn\n end interface\n\n ! Internal variables\n integer(i4) :: n \n integer(i4) :: nstep ! nuber of steps\n integer(i4) :: kount ! total number of saved steps\n real(dp) :: hIN, hdid, hnext, x, hminIN, epsIN, xsav, dxsav\n real(dp), dimension(size(ystart)) :: dydx, y, yscal, C\n\n ! Pointers\n real(dp), dimension(:), pointer :: xp\n real(dp), dimension(:,:), pointer :: yp\n\n ! parameters\n integer(i4), parameter :: MAXstp = 1000000_i4 ! max number of steps\n\n\n if( present(hmin) ) then\n hminIN = abs(hmin)\n else\n hminIN = 0.0_dp\n end if\n\n if( present(eps) ) then\n epsIN = abs(eps)\n else\n epsIN = 1e-6_dp\n end if\n \n C = 1.0_dp !lower boundary for scaling\n\n hIN = sign( h, x2-x1 )\n hnext = 0.0_dp\n hdid = 0.0_dp\n\n kount = 0_i4\n\n x = x1\n y(:) = ystart(:)\n dxsav = tiny(1._dp)\n xsav = x-2.0_dp*dxsav ! assures storage of first step\n\n nullify( xp, yp )\n allocate( xp(256) )\n allocate( yp(size(xp), size(ystart)) )\n\n call save_a_step ! save initial step\n\n do nstep=1, MAXstp ! take at most MAXstp steps\n\n call derivs( x, y, dydx )\n forall( n = 1:size(yscal) ) yscal(n) = max (abs(y(n)),C(n)) ! scaling used to monitor accuracy --> CAN BE MODIFIED...\n\n if ( abs(x-xsav) .gt. abs(dxsav) ) call save_a_step ! store intermediate results\n\n if ( (x+hIN-x2)*(x+hIN-x1) .gt. 0.0_dp ) hIN = x2-x ! if stepsize can overshoot, decrease\n\n call RBstep( y, dydx, x, hIN, epsIN, yscal, hdid, hnext, derivs, jacobn) !do one Rosenbrock-Step\n\n if ( ge((x-x2)*(x2-x1), 0.0_dp) ) then ! are we done?!?!\n call save_a_step ! save final step\n if (allocated(xout)) deallocate(xout)\n allocate( xout(kount) ) ! allocate storage for outputs\n xout(:) = xp(1:kount)\n if (allocated(yout)) deallocate(yout)\n allocate( yout(kount, size(yp,2)) ) ! allocate storage for outputs\n yout(:,:) = yp(1:kount, :)\n deallocate( xp, yp ) ! clear out old stored variables\n return ! normal exit\n end if\n\n if ( abs(hnext-hminIN) .lt. epsilon(1.0_dp) ) stop 'RBstiff_dp --> WTF! ...stepsize smaller than minimum!!!'\n \n hIN = hnext\n\n end do\n\n stop 'RBstiff_dp --> dude, too many steps!!!'\n\n contains\n\n subroutine save_a_step ! --> like a macro in C\n kount = kount+1_i4\n if ( kount .gt. size(xp) ) then\n xp=>reallocate( xp, 2*size(xp) )\n yp=>reallocate( yp, size(xp), size(yp,2) )\n end if\n xp(kount) = x\n yp(kount, :) = y(:)\n xsav = x\n end subroutine save_a_step\n\n end subroutine RBstiff_dp\n\n ! ------------------------------------------------------------------\n ! PRIVATE METHODS\n ! ------------------------------------------------------------------\n\n ! SINGLE PRECISION CASH-KARP RUNGE-KUTTA step\n subroutine CashKarpRK_sp( y, dydx, x, h, yout, yerr, derivs )\n ! Given values for N variables y and their derivatives dydx known at x, use the fifth-order\n ! Cash-Karp Runge-Kutta method to advance the solution over an interval h and return\n ! the incremented variables as yout. Also return an estimate of the local truncation error\n ! in yout using the embedded fourth order method.\n\n use mo_kind, only : i4, sp\n use mo_nrutil, only : assert_eq\n\n implicit none\n\n ! Intent IN\n real(sp), dimension(:), intent(in) :: y, dydx\n real(sp), intent(in) :: x, h\n\n ! Intent OUT\n real(sp), dimension(:), intent(out) :: yout, yerr\n\n interface\n subroutine derivs( x, y, dydx )\n use mo_kind, only: sp\n implicit none\n real(sp), intent(in) :: x\n real(sp), dimension(:), intent(in) :: y\n real(sp), dimension(:), intent(out) :: dydx\n end subroutine derivs\n end interface\n\n ! Internal variables\n integer(i4) :: ndum\n real(sp), dimension(:), allocatable :: ak2, ak3, ak4, ak5, ak6, ytemp\n\n ! parameters\n real(sp), parameter :: A2=0.2_sp, A3=0.3_sp, A4=0.6_sp, A5=1._sp, A6=0.875_sp, B21=0.2_sp, B31=3._sp/40._sp, &\n B32=9._sp/40._sp, B41=0.3_sp, B42=-0.9_sp, B43=1.2_sp, B51=-11._sp/54._sp, B52=2.5_sp, &\n B53=-70._sp/27._sp, B54=35._sp/27._sp, B61=1631._sp/55296._sp, B62=175._sp/512._sp, &\n B63=575._sp/13824._sp, B64=44275._sp/110592._sp, B65=253._sp/4096._sp, &\n C1=37._sp/378._sp, C3=250._sp/621._sp, C4=125._sp/594._sp, C6=512._sp/1771._sp, &\n DC1=C1-2825._sp/27648._sp, DC3=C3-18575._sp/48384._sp, &\n DC4=C4-13525._sp/55296._sp, DC5=-277._sp/14336._sp, DC6=C6-.25_sp\n\n ndum = assert_eq( size(y), size(dydx) ,size(yout) ,size(yerr) , 'CashKarpRK_sp' )\n\n allocate( ak2(ndum), ak3(ndum), ak4(ndum), ak5(ndum), ak6(ndum), ytemp(ndum) )\n\n ytemp = y + B21*h*dydx ! first step\n call derivs( x+A2*h, ytemp, ak2 ) ! second step\n ytemp = y + h*(B31*dydx+B32*ak2)\n call derivs( x+A3*h, ytemp, ak3 ) ! third step\n ytemp = y + h*(B41*dydx+B42*ak2+B43*ak3)\n call derivs( x+A4*h, ytemp, ak4 ) ! fourth step\n ytemp = y + h*(B51*dydx+B52*ak2+B53*ak3+B54*ak4)\n call derivs( x+A5*h, ytemp, ak5 ) ! fifth step\n ytemp = y + h*(B61*dydx+B62*ak2+B63*ak3+B64*ak4+B65*ak5)\n call derivs( x+A6*h, ytemp, ak6 ) ! sixth step\n yout = y + h*(C1*dydx+C3*ak3+C4*ak4+C6*ak6) ! accumulate increments with proper weights\n yerr = h*(DC1*dydx+DC3*ak3+DC4*ak4+DC5*ak5+DC6*ak6)\n\n end subroutine CashKarpRK_sp\n\n\n ! DOUBLE PRECISION CASH-KARP RUNGE-KUTTA step\n subroutine CashKarpRK_dp( y, dydx, x, h, yout, yerr, derivs )\n ! Given values for N variables y and their derivatives dydx known at x, use the fifth-order\n ! Cash-Karp Runge-Kutta method to advance the solution over an interval h and return\n ! the incremented variables as yout. Also return an estimate of the local truncation error\n ! in yout using the embedded fourth order method.\n\n use mo_kind, only: i4, dp\n use mo_nrutil, only: assert_eq\n\n implicit none\n\n ! Intent IN\n real(dp), dimension(:), intent(in) :: y, dydx\n real(dp), intent(in) :: x, h\n\n ! Intent OUT\n real(dp), dimension(:), intent(out) :: yout, yerr\n\n interface\n subroutine derivs( x, y, dydx )\n use mo_kind, only: dp\n implicit none\n real(dp), intent(in) :: x\n real(dp), dimension(:), intent(in) :: y\n real(dp), dimension(:), intent(out) :: dydx\n end subroutine derivs\n end interface\n\n ! Internal variables\n integer(i4) :: ndum\n real(dp), dimension(:), allocatable :: ak2, ak3, ak4, ak5, ak6, ytemp\n\n ! parameters\n real(dp), parameter :: A2=0.2_dp, A3=0.3_dp, A4=0.6_dp, A5=1._dp, A6=0.875_dp, B21=0.2_dp, B31=3._dp/40._dp, &\n B32=9._dp/40._dp, B41=0.3_dp, B42=-0.9_dp, B43=1.2_dp, B51=-11._dp/54._dp, B52=2.5_dp, &\n B53=-70._dp/27._dp, B54=35._dp/27._dp, B61=1631._dp/55296._dp, B62=175._dp/512._dp, &\n B63=575._dp/13824._dp, B64=44275._dp/110592._dp, B65=253._dp/4096._dp, &\n C1=37._dp/378._dp, C3=250._dp/621._dp, C4=125._dp/594._dp, C6=512._dp/1771._dp, &\n DC1=C1-2825._dp/27648._dp, DC3=C3-18575._dp/48384._dp, &\n DC4=C4-13525._dp/55296._dp, DC5=-277._dp/14336._dp, DC6=C6-.25_dp\n\n ndum = assert_eq( size(y), size(dydx) ,size(yout) ,size(yerr) , 'CashKarpRK_dp' )\n\n allocate( ak2(ndum), ak3(ndum), ak4(ndum), ak5(ndum), ak6(ndum), ytemp(ndum) )\n\n ytemp = y + B21*h*dydx ! first step\n call derivs( x+A2*h, ytemp, ak2 ) ! second step\n ytemp = y + h*(B31*dydx+B32*ak2)\n call derivs( x+A3*h, ytemp, ak3 ) ! third step\n ytemp = y + h*(B41*dydx+B42*ak2+B43*ak3)\n call derivs( x+A4*h, ytemp, ak4 ) ! fourth step\n ytemp = y + h*(B51*dydx+B52*ak2+B53*ak3+B54*ak4)\n call derivs( x+A5*h, ytemp, ak5 ) ! fifth step\n ytemp = y + h*(B61*dydx+B62*ak2+B63*ak3+B64*ak4+B65*ak5)\n call derivs( x+A6*h, ytemp, ak6 ) ! sixth step\n yout = y + h*(C1*dydx+C3*ak3+C4*ak4+C6*ak6) ! accumulate increments with proper weights\n yerr = h*(DC1*dydx+DC3*ak3+DC4*ak4+DC5*ak5+DC6*ak6)\n\n end subroutine CashKarpRK_dp\n\n ! ------------------------------------------------------------------\n\n ! SINGLE PRECISION ROSENBROCK step\n subroutine RBstep_sp(y, dydx, x, htry, eps, yscal, hdid, hnext, derivs, jacobn)\n\n use mo_kind, only : i4, sp\n use mo_utils, only : eq, le\n use mo_nrutil, only : assert_eq, diagadd\n use mo_linear_algebra, only : solve_linear_equations\n\n implicit none\n\n real(sp), dimension(:), intent(inout) :: y\n real(sp), dimension(:), intent(in) :: dydx, yscal\n real(sp), intent(inout) :: x\n\n real(sp), intent(in) :: htry, eps\n real(sp), intent(out) :: hdid, hnext\n\n interface\n subroutine derivs(x, y, dydx)\n use mo_kind, only: sp\n implicit none\n real(sp), intent(in) :: x\n real(sp), dimension(:), intent(in) :: y\n real(sp), dimension(:), intent(out) :: dydx\n end subroutine derivs\n\n subroutine jacobn(x, y, dfdx, dfdy)\n use mo_kind, only: sp\n implicit none\n real(sp), intent(in) :: x\n real(sp), dimension(:), intent(in) :: y\n real(sp), dimension(:), intent(out) :: dfdx\n real(sp), dimension(:,:), intent(out) :: dfdy\n end subroutine jacobn\n end interface\n\n integer(i4) :: jtry,ndum\n! integer(i4), dimension(size(y)) :: indx\n real(sp), dimension(size(y)) :: dfdx,dytmp,err,g1,g2,g3,g4,ysav\n real(sp), dimension(size(y),size(y)) :: a,dfdy\n real(sp) :: errmax,h,xsav !,d\n\n integer(i4), parameter :: maxtry = 40_i4\n real(sp), parameter :: safety = 0.9_sp, grow = 1.5_sp, pgrow = -0.25_sp,&\n shrnk = 0.5_sp, pshrnk = -1.0_sp/3.0_sp, errcon = 0.1296_sp,&\n gam = 1.0_sp/2.0_sp,&\n a21 = 2.0_sp, a31 = 48.0_sp/25.0_sp, a32 = 6.0_sp/25.0_sp,&\n c21 = -8.0_sp, c31 = 372.0_sp/25.0_sp, c32 = 12.0_sp/5.0_sp,&\n c41 = -112.0_sp/125.0_sp, c42 = -54._sp/125.0_sp, c43 = -2.0_sp/5.0_sp,&\n b1 = 19.0_sp/9.0_sp, b2 = 1.0_sp/2.0_sp, b3 = 25.0_sp/108.0_sp,&\n b4 = 125.0_sp/108.0_sp,&\n e1 = 17.0_sp/54.0_sp, e2 = 7.0_sp/36.0_sp, e3 = 0.0_sp,&\n e4 = 125.0_sp/108.0_sp,&\n c1x = 1.0_sp/2.0_sp, c2x = -3.0_sp/2.0_sp, c3x = 121.0_sp/50.0_sp,&\n c4x = 29.0_sp/250.0_sp,&\n a2x = 1.0_sp, a3x = 3.0_sp/5.0_sp\n\n\n ndum = assert_eq(size(y),size(dydx),size(yscal),'stiff')\n xsav = x\n ysav(:) = y(:)\n\n call jacobn(xsav,ysav,dfdx,dfdy)\n\n h = htry\n\n do jtry=1,maxtry\n\n a(:,:) = -dfdy(:,:)\n\n call diagadd(a,1.0_sp/(gam*h))\n! call ludcmp(a,indx,d)\n\n g1 = dydx+h*c1x*dfdx\n g1 = solve_linear_equations(a,g1)\n\n ! call lubksb(a,indx,g1)\n\n y = ysav+a21*g1\n x = xsav+a2x*h\n\n call derivs(x,y,dytmp)\n\n g2 = dytmp+h*c2x*dfdx+c21*g1/h\n g2 = solve_linear_equations(a,g2)\n\n ! call lubksb(a,indx,g2)\n\n y = ysav+a31*g1+a32*g2\n x = xsav+a3x*h\n\n call derivs(x,y,dytmp)\n\n g3 = dytmp+h*c3x*dfdx+(c31*g1+c32*g2)/h\n g3 = solve_linear_equations(a,g3)\n\n ! call lubksb(a,indx,g3)\n\n g4 = dytmp+h*c4x*dfdx+(c41*g1+c42*g2+c43*g3)/h\n g4 = solve_linear_equations(a,g4)\n\n ! call lubksb(a,indx,g4)\n\n y = ysav+b1*g1+b2*g2+b3*g3+b4*g4\n err = e1*g1+e2*g2+e3*g3+e4*g4\n x = xsav+h\n\n if (eq(x,xsav)) stop 'stepsize not significant in RBstep_sp'\n\n errmax = maxval(abs(err/yscal))/eps\n\n if (le(errmax,1.0_sp)) then\n hdid = h\n hnext = merge(safety*h*errmax**pgrow, grow*h, errmax > errcon)\n return\n else\n hnext = safety*h*errmax**pshrnk\n h = sign(max(abs(hnext),shrnk*abs(h)),h)\n end if\n\n end do\n\n stop 'exceeded maxtry in RBstep_sp'\n\n end subroutine RBstep_sp\n\n\n ! DOUBLE PRECISION ROSENBROCK step\n subroutine RBstep_dp(y, dydx, x, htry, eps, yscal, hdid, hnext, derivs, jacobn)\n\n use mo_kind, only : i4, dp\n use mo_utils, only : eq, le\n use mo_nrutil, only : assert_eq, diagadd\n use mo_linear_algebra, only : solve_linear_equations\n\n implicit none\n\n real(dp), dimension(:), intent(inout) :: y\n real(dp), dimension(:), intent(in) :: dydx, yscal\n real(dp), intent(inout) :: x\n\n real(dp), intent(in) :: htry, eps\n real(dp), intent(out) :: hdid, hnext\n\n interface\n subroutine derivs(x, y, dydx)\n use mo_kind, only: dp\n implicit none\n real(dp), intent(in) :: x\n real(dp), dimension(:), intent(in) :: y\n real(dp), dimension(:), intent(out) :: dydx\n end subroutine derivs\n\n subroutine jacobn(x, y, dfdx, dfdy)\n use mo_kind, only: dp\n implicit none\n real(dp), intent(in) :: x\n real(dp), dimension(:), intent(in) :: y\n real(dp), dimension(:), intent(out) :: dfdx\n real(dp), dimension(:,:), intent(out) :: dfdy\n end subroutine jacobn\n end interface\n\n integer(i4) :: jtry,ndum\n! integer(i4), dimension(size(y)) :: indx\n real(dp), dimension(size(y)) :: dfdx,dytmp,err,g1,g2,g3,g4,ysav\n real(dp), dimension(size(y),size(y)) :: a,dfdy\n real(dp) :: errmax,h,xsav !,d\n\n integer(i4), parameter :: maxtry = 40_i4\n real(dp), parameter :: safety = 0.9_dp, grow = 1.5_dp, pgrow = -0.25_dp,&\n shrnk = 0.5_dp, pshrnk = -1.0_dp/3.0_dp, errcon = 0.1296_dp,&\n gam = 1.0_dp/2.0_dp,&\n a21 = 2.0_dp, a31 = 48.0_dp/25.0_dp, a32 = 6.0_dp/25.0_dp,&\n c21 = -8.0_dp, c31 = 372.0_dp/25.0_dp, c32 = 12.0_dp/5.0_dp,&\n c41 = -112.0_dp/125.0_dp, c42 = -54._dp/125.0_dp, c43 = -2.0_dp/5.0_dp,&\n b1 = 19.0_dp/9.0_dp, b2 = 1.0_dp/2.0_dp, b3 = 25.0_dp/108.0_dp,&\n b4 = 125.0_dp/108.0_dp,&\n e1 = 17.0_dp/54.0_dp, e2 = 7.0_dp/36.0_dp, e3 = 0.0_dp,&\n e4 = 125.0_dp/108.0_dp,&\n c1x = 1.0_dp/2.0_dp, c2x = -3.0_dp/2.0_dp, c3x = 121.0_dp/50.0_dp,&\n c4x = 29.0_dp/250.0_dp,&\n a2x = 1.0_dp, a3x = 3.0_dp/5.0_dp\n\n\n ndum = assert_eq(size(y),size(dydx),size(yscal),'stiff')\n xsav = x\n ysav(:) = y(:)\n\n call jacobn(xsav,ysav,dfdx,dfdy)\n\n h = htry\n\n do jtry=1,maxtry\n\n a(:,:) = -dfdy(:,:)\n\n call diagadd(a,1.0_dp/(gam*h))\n! call ludcmp(a,indx,d)\n\n g1 = dydx+h*c1x*dfdx\n g1 = solve_linear_equations(a,g1)\n\n ! call lubksb(a,indx,g1)\n\n y = ysav+a21*g1\n x = xsav+a2x*h\n\n call derivs(x,y,dytmp)\n\n g2 = dytmp+h*c2x*dfdx+c21*g1/h\n g2 = solve_linear_equations(a,g2)\n\n ! call lubksb(a,indx,g2)\n\n y = ysav+a31*g1+a32*g2\n x = xsav+a3x*h\n\n call derivs(x,y,dytmp)\n\n g3 = dytmp+h*c3x*dfdx+(c31*g1+c32*g2)/h\n g3 = solve_linear_equations(a,g3)\n\n ! call lubksb(a,indx,g3)\n\n g4 = dytmp+h*c4x*dfdx+(c41*g1+c42*g2+c43*g3)/h\n g4 = solve_linear_equations(a,g4)\n\n ! call lubksb(a,indx,g4)\n\n y = ysav+b1*g1+b2*g2+b3*g3+b4*g4\n err = e1*g1+e2*g2+e3*g3+e4*g4\n x = xsav+h\n\n if (eq(x,xsav)) stop 'stepsize not significant in RBstep_dp'\n\n errmax = maxval(abs(err/yscal))/eps\n\n if (le(errmax,1.0_dp)) then\n hdid = h\n hnext = merge(safety*h*errmax**pgrow, grow*h, errmax > errcon)\n return\n else\n hnext = safety*h*errmax**pshrnk\n h = sign(max(abs(hnext),shrnk*abs(h)),h)\n end if\n\n end do\n\n stop 'exceeded maxtry in RBstep_dp'\n\n end subroutine RBstep_dp\n\n ! ------------------------------------------------------------------\n\n\n!-----------------------------------------------------------|\n!the second version with parameter-input for the derivatives|\n!-----------------------------------------------------------|\n\n\n ! ------------------------------------------------------------------\n\n ! SINGLE PRECISION Euler\n subroutine Euler_para_sp( ystart, x1, x2, h, derivs, para, xout, yout ) ! all obligatory\n\n use mo_kind, only: i4, sp\n\n implicit none\n\n ! Intent IN\n real(sp), dimension(:), intent(in) :: ystart ! initial conditions\n real(sp), intent(in) :: x1, x2 ! initial and final time\n real(sp), intent(in) :: h ! step size\n real(sp), dimension(:), intent(in) :: para ! parameters for derivs\n\n ! Intent OUT\n real(sp), dimension(:), allocatable, intent(out) :: xout\n real(sp), dimension(:,:), allocatable, intent(out) :: yout\n\n interface\n subroutine derivs( x, y, para, dydx )\n use mo_kind, only: sp\n implicit none\n real(sp), intent(in) :: x ! time\n real(sp), dimension(:), intent(in) :: y ! unknowns of the equations\n real(sp), dimension(:), intent(in) :: para ! parameters for derivs\n real(sp), dimension(:), intent(out) :: dydx ! derivatives of y\n end subroutine derivs\n end interface\n\n ! Internal variables\n integer(i4) :: j ! counter\n integer(i4) :: nstep ! number of steps\n real(sp) :: x\n real(sp), dimension( size(ystart) ) :: dy, y\n\n y(:) = ystart(:) ! load starting values\n nstep = nint( (x2-x1)/h, i4 ) ! find number of steps\n\n if ( allocated(xout) ) deallocate(xout) ! clear out old stored variables if necessary\n if ( allocated(yout) ) deallocate(yout)\n allocate( xout(nstep+1_i4) ) ! allocate storage for saved values\n allocate( yout(nstep+1_i4, size(ystart)) )\n\n yout(1,:) = y(:)\n xout(1) = x1\n x = x1\n\n do j=1, nstep ! take nstep steps\n call derivs( x, y, para, dy )\n y = y + h*dy ! step EULER\n if ( h .lt. tiny(1._sp) ) stop 'Euler_para_sp --> stepsize not significant!'\n x = x+h\n xout(j+1_i4) = x ! store intermediate steps\n yout(j+1_i4,:) = y(:)\n end do\n\n end subroutine Euler_para_sp\n\n ! DOUBLE PRECISION Euler\n subroutine Euler_para_dp( ystart, x1, x2, h, derivs, para, xout, yout ) ! all obligatory\n\n use mo_kind, only: i4, dp\n\n implicit none\n\n ! Intent IN\n real(dp), dimension(:), intent(in) :: ystart ! initial conditions\n real(dp), intent(in) :: x1, x2 ! initial and final time\n real(dp), intent(in) :: h ! step size\n real(dp), dimension(:), intent(in) :: para ! parameters for derivs\n\n ! Intent OUT\n real(dp), dimension(:), allocatable, intent(out) :: xout\n real(dp), dimension(:,:), allocatable, intent(out) :: yout\n\n interface\n subroutine derivs( x, y, para, dydx )\n use mo_kind, only: dp\n implicit none\n real(dp), intent(in) :: x ! time\n real(dp), dimension(:), intent(in) :: y ! unknowns of the equations\n real(dp), dimension(:), intent(in) :: para ! parameters for derivs\n real(dp), dimension(:), intent(out) :: dydx ! derivatives of y\n end subroutine derivs\n end interface\n\n ! Internal variables\n integer(i4) :: j ! counter\n integer(i4) :: nstep ! nuber of steps\n real(dp) :: x\n real(dp), dimension( size(ystart) ) :: dy, y\n\n y(:) = ystart(:) ! load starting values\n nstep = nint( (x2-x1)/h, i4 ) ! find number of steps\n\n if ( allocated(xout) ) deallocate(xout) ! clear out old stored variables if necessary\n if ( allocated(yout) ) deallocate(yout)\n allocate( xout(nstep+1_i4) ) ! allocate storage for saved values\n allocate( yout(nstep+1_i4, size(ystart)) )\n\n yout(1,:) = y(:)\n xout(1) = x1\n x = x1\n\n do j=1, nstep ! take nstep steps\n call derivs( x, y, para, dy )\n y = y + h*dy ! step EULER\n if ( h .lt. tiny(1._dp) ) stop 'Euler_para_dp --> stepsize not significant!'\n x = x+h\n xout(j+1_i4) = x ! store intermediate steps\n yout(j+1_i4,:) = y(:)\n end do\n\n end subroutine Euler_para_dp\n\n ! ------------------------------------------------------------------\n\n ! SINGLE PRECISION 4th order RUNGE-KUTTA\n subroutine RK4_para_sp( ystart, x1, x2, h, derivs, para, xout, yout ) ! all obligatory\n\n use mo_kind, only: i4, sp\n\n implicit none\n\n ! Intent IN\n real(sp), dimension(:), intent(in) :: ystart ! initial conditions\n real(sp), intent(in) :: x1, x2 ! initial and final time\n real(sp), intent(in) :: h ! step size\n real(sp), dimension(:), intent(in) :: para ! parameters for derivs\n\n ! Intent OUT\n real(sp), dimension(:), allocatable, intent(out) :: xout\n real(sp), dimension(:,:), allocatable, intent(out) :: yout\n\n interface\n subroutine derivs( x, y, para, dydx )\n use mo_kind, only: sp\n implicit none\n real(sp), intent(in) :: x ! time\n real(sp), dimension(:), intent(in) :: y ! unknowns of the equations\n real(sp), dimension(:), intent(in) :: para ! parameters for derivs\n real(sp), dimension(:), intent(out) :: dydx ! derivatives of y\n end subroutine derivs\n end interface\n\n ! Internal variables\n integer(i4) :: j ! counter\n integer(i4) :: nstep ! nuber of steps\n real(sp) :: x\n real(sp) :: hh, h6, xh\n real(sp), dimension( size(ystart) ) :: dy, dyt, dym, y, yt\n\n y(:) = ystart(:) ! load starting values\n nstep = nint( (x2-x1)/h, i4 ) ! find number of steps\n\n if ( allocated(xout) ) deallocate(xout) ! clear out old stored variables if necessary\n if ( allocated(yout) ) deallocate(yout)\n allocate( xout(nstep+1_i4) ) ! allocate storage for saved values\n allocate( yout(nstep+1_i4, size(ystart)) )\n\n yout(1,:) = y(:)\n xout(1) = x1\n x = x1\n\n hh = h*0.5_sp\n h6 = h/6.0_sp\n xh = x+hh\n\n do j=1, nstep ! take nstep steps\n call derivs( x, y, para, dy ) ! first step\n yt = y + hh*dy\n call derivs( xh, yt, para, dyt ) ! second step\n yt = y + hh*dyt\n call derivs( xh, yt, para, dym ) ! third step\n yt = y + h*dym\n dym = dyt + dym\n call derivs( x+h, yt, para, dyt ) ! fourth step\n y = y + h6*( dy+dyt+2.0_sp*dym ) ! accumulate increments with proper weights\n if ( h .lt. tiny(1._sp) ) stop 'RK4_para_sp --> stepsize not significant!'\n x = x+h\n xout(j+1_i4) = x ! store intermediate steps\n yout(j+1_i4,:) = y(:)\n end do\n\n end subroutine RK4_para_sp\n\n\n ! DOUBLE PRECISION 4th order RUNGE-KUTTA\n subroutine RK4_para_dp( ystart, x1, x2, h, derivs, para, xout, yout ) ! all obligatory\n\n use mo_kind, only: i4, dp\n\n implicit none\n\n ! Intent IN\n real(dp), dimension(:), intent(in) :: ystart ! initial conditions\n real(dp), intent(in) :: x1, x2 ! initial and final time\n real(dp), intent(in) :: h ! step size\n real(dp), dimension(:), intent(in) :: para ! parameters for derivs\n\n ! Intent OUT\n real(dp), dimension(:), allocatable, intent(out) :: xout\n real(dp), dimension(:,:), allocatable, intent(out) :: yout\n\n interface\n subroutine derivs( x, y, para, dydx )\n use mo_kind, only: dp\n implicit none\n real(dp), intent(in) :: x ! time\n real(dp), dimension(:), intent(in) :: y ! unknowns of the equations\n real(dp), dimension(:), intent(in) :: para ! parameters for derivs\n real(dp), dimension(:), intent(out) :: dydx ! derivatives of y\n end subroutine derivs\n end interface\n\n ! Internal variables\n integer(i4) :: j ! counter\n integer(i4) :: nstep ! nuber of steps\n real(dp) :: x\n real(dp) :: hh, h6, xh\n real(dp), dimension( size(ystart) ) :: dy, dyt, dym, y, yt\n\n y(:) = ystart(:) ! load starting values\n nstep = nint( (x2-x1)/h, i4 ) ! find number of steps\n\n if ( allocated(xout) ) deallocate(xout) ! clear out old stored variables if necessary\n if ( allocated(yout) ) deallocate(yout)\n allocate( xout(nstep+1_i4) ) ! allocate storage for saved values\n allocate( yout(nstep+1_i4, size(ystart)) )\n\n yout(1,:) = y(:)\n xout(1) = x1\n x = x1\n\n hh = h*0.5_dp\n h6 = h/6.0_dp\n xh = x+hh\n\n do j=1, nstep ! take nstep steps\n call derivs( x, y, para, dy )\n yt = y + hh*dy ! first step\n call derivs( xh, yt, para, dyt ) ! second step\n yt = y + hh*dyt\n call derivs( xh, yt, para, dym ) ! third step\n yt = y + h*dym\n dym = dyt + dym\n call derivs( x+h, yt, para, dyt ) ! fourth step\n y = y + h6*( dy+dyt+2.0_dp*dym ) ! accumulate increments with proper weights\n if ( h .lt. tiny(1._dp) ) stop 'RK4_para_dp --> stepsize not significant!'\n x = x+h\n xout(j+1_i4) = x ! store intermediate steps\n yout(j+1_i4,:) = y(:)\n end do\n\n end subroutine RK4_para_dp\n\n ! ------------------------------------------------------------------\n\n ! SINGLE PRECISION 4th order RUNGE-KUTTA Adaptive Step-size\n subroutine RK4as_para_sp( ystart, x1, x2, h, derivs, para, xout, yout, & ! obligatory\n hmin, eps ) ! optional\n\n use mo_kind, only: i4, sp\n use mo_nrutil, only: reallocate\n\n implicit none\n\n ! Intent IN\n real(sp), intent(in) :: x1, x2 ! initial and final time\n real(sp), intent(in) :: h ! guessed step size\n real(sp), dimension(:), intent(in) :: ystart ! initial conditions\n real(sp), optional, intent(in) :: hmin\n real(sp), optional, intent(in) :: eps\n real(sp), dimension(:), intent(in) :: para ! parameters for derivs\n\n ! Intent OUT\n real(sp), dimension(:), allocatable, intent(out) :: xout\n real(sp), dimension(:,:), allocatable, intent(out) :: yout\n\n interface\n subroutine derivs( x, y, para, dydx )\n use mo_kind, only: sp\n implicit none\n real(sp), intent(in) :: x ! time\n real(sp), dimension(:), intent(in) :: y ! unknowns of the equations\n real(sp), dimension(:), intent(in) :: para ! parameters for derivs\n real(sp), dimension(:), intent(out) :: dydx ! derivatives of y\n end subroutine derivs\n end interface\n\n ! Internal variables\n integer(i4) :: nstep ! nuber of steps\n integer(i4) :: nok, nbad ! number of good and bad (but retried and fixed) steps taken\n integer(i4) :: kount ! total number of saved steps\n real(sp) :: hIN, hdid, hnext, x, hminIN, epsIN, xsav, dxsav, errmax, htemp, xnew\n real(sp), dimension(size(ystart)) :: dydx, y, yscal, yerr, ytemp\n ! Pointers\n real(sp), dimension(:), pointer :: xp\n real(sp), dimension(:,:), pointer :: yp\n\n ! parameters\n integer(i4), parameter :: MAXstp = 1000000_i4 ! max number of steps\n real(sp), parameter :: safety = 0.9_sp, pgrow = -0.2_sp, pshrnk = -0.25_sp\n real(sp) :: errcon\n\n errcon = exp( (1._sp/pgrow)*log(5._sp/safety) )\n\n if( present(hmin) ) then\n hminIN = hmin\n else\n hminIN = 0.0_sp\n end if\n\n if( present(eps) ) then\n epsIN = eps\n else\n epsIN = 1e-6_sp\n end if\n\n x = x1\n hIN = sign( h, x2-x1 )\n nok = 0_i4\n nbad = 0_i4\n kount = 0_i4\n y(:) = ystart(:)\n dxsav = tiny(1._sp)\n\n xsav = x-2.0_sp*dxsav ! assures storage of first step\n nullify( xp, yp )\n allocate( xp(256) )\n allocate( yp(size(xp), size(ystart)) )\n\n call save_a_step ! save initial step\n\n do nstep=1, MAXstp ! take at most MAXstp steps\n\n call derivs( x, y, para, dydx )\n yscal(:) = abs( y(:) ) + abs( hIN*dydx(:) ) + tiny(1._sp) ! scaling used to monitor accuracy\n ! --> CAN BE MODIFIED...\n\n if ( abs(x-xsav) .gt. abs(dxsav) ) call save_a_step ! store intermediate results\n\n if ( (x+hIN-x2)*(x+hIN-x1) .gt. 0.0_sp ) hIN = x2-x ! if stepsize can overshoot, decrease\n\n do\n call CashKarpRK(y, dydx, x, hIN, ytemp, yerr, derivs, para) ! take a step\n errmax = maxval( abs(yerr(:)/yscal(:)) )/epsIN ! evaluate accuracy\n if ( errmax .lt. 1.0_sp ) exit ! step succeeded\n htemp = safety*hIN*(errmax**pshrnk) ! truncation error too large, reduce stepsize\n hIN = sign( max( abs(htemp), 0.1_sp*abs(hIN) ), hIN ) ! no more than a factor of 10\n xnew = x+hIN\n if ( abs(xnew-x) .lt. epsilon(1.0_sp) ) stop 'RK4as_para_sp --> hey !!! stepsize underflow!'\n end do\n\n if ( errmax .gt. errcon ) then ! compute size of next step\n hnext = safety*hIN*(errmax**pgrow)\n else ! no more than a factor of 5 increase\n hnext = 5.0_sp*hIN\n end if\n\n hdid = hIN\n x = x+hIN\n y(:) = ytemp(:)\n\n if ( abs(hdid-hIN) .gt. epsilon(1.0_sp) ) then\n nbad = nbad+1_i4\n else\n nok = nok+1_i4\n end if\n\n if ( (x-x2)*(x2-x1) .ge. 0.0_sp ) then ! are we done?!?!\n call save_a_step ! save final step\n if (allocated(xout)) deallocate(xout)\n allocate( xout(kount) ) ! allocate storage for outputs\n xout(:) = xp(1:kount)\n if (allocated(yout)) deallocate(yout)\n allocate( yout(kount, size(yp,2)) ) ! allocate storage for outputs\n yout(:,:) = yp(1:kount, :)\n deallocate( xp, yp ) ! clear out old stored variables\n return ! normal exit\n end if\n\n if ( abs(hnext-hminIN) .lt. epsilon(1.0_sp) ) stop 'RK4as_para_sp --> WTF! ...stepsize smaller than minimum!!!'\n hIN = hnext\n\n end do\n\n stop 'RK4as_para_sp --> dude, too many steps!!!'\n\n contains\n\n subroutine save_a_step ! --> like a macro in C\n kount = kount+1\n if ( kount .gt. size(xp) ) then\n xp=>reallocate( xp, 2*size(xp) )\n yp=>reallocate( yp, size(xp), size(yp,2) )\n end if\n xp(kount) = x\n yp(kount, :) = y(:)\n xsav = x\n end subroutine save_a_step\n\n end subroutine RK4as_para_sp\n\n\n ! DOUBLE PRECISION 4th order RUNGE-KUTTA Adaptive Step-size\n subroutine RK4as_para_dp( ystart, x1, x2, h, derivs, para, xout, yout, & ! obligatory\n hmin, eps ) ! optional\n\n use mo_kind, only: i4, dp\n use mo_nrutil, only: reallocate\n\n implicit none\n\n ! Intent IN\n real(dp), intent(in) :: x1, x2 ! initial and final time\n real(dp), intent(in) :: h ! guessed step size\n real(dp), dimension(:), intent(in) :: ystart ! initial conditions\n real(dp), optional, intent(in) :: hmin\n real(dp), optional, intent(in) :: eps\n real(dp), dimension(:), intent(in) :: para ! parameters for derivs\n\n ! Intent OUT\n real(dp), dimension(:), allocatable, intent(out) :: xout\n real(dp), dimension(:,:), allocatable, intent(out) :: yout\n\n interface\n subroutine derivs( x, y, para, dydx )\n use mo_kind, only: dp\n implicit none\n real(dp), intent(in) :: x ! time\n real(dp), dimension(:), intent(in) :: y ! unknowns of the equations\n real(dp), dimension(:), intent(in) :: para ! parameters for derivs\n real(dp), dimension(:), intent(out) :: dydx ! derivatives of y\n end subroutine derivs\n end interface\n\n ! Internal variables\n integer(i4) :: nstep ! nuber of steps\n integer(i4) :: nok, nbad ! number of good and bad (but retried and fixed) steps taken\n integer(i4) :: kount ! total number of saved steps\n real(dp) :: hIN, hdid, hnext, x, hminIN, epsIN, xsav, dxsav, errmax, htemp, xnew\n real(dp), dimension(size(ystart)) :: dydx, y, yscal, yerr, ytemp\n ! Pointers\n real(dp), dimension(:), pointer :: xp\n real(dp), dimension(:,:), pointer :: yp\n\n ! parameters\n integer(i4), parameter :: MAXstp = 1000000_i4 ! max nuber of steps\n real(dp), parameter :: safety = 0.9_dp, pgrow = -0.2_dp, pshrnk = -0.25_dp\n real(dp) :: errcon\n\n errcon = exp( (1._dp/pgrow)*log(5._dp/safety) )\n\n if( present(hmin) ) then\n hminIN = hmin\n else\n hminIN = 0.0_dp\n end if\n\n if( present(eps) ) then\n epsIN = eps\n else\n epsIN = 1e-6_dp\n end if\n\n x = x1\n hIN = sign( h, x2-x1 )\n nok = 0_i4\n nbad = 0_i4\n kount = 0_i4\n y(:) = ystart(:)\n dxsav = tiny(1._dp)\n\n xsav = x-2.0_dp*dxsav ! assures storage of first step\n nullify( xp, yp )\n allocate( xp(256) )\n allocate( yp(size(xp), size(ystart)) )\n\n call save_a_step ! save initial step\n\n do nstep=1, MAXstp ! take at most MAXstp steps\n\n call derivs( x, y, para, dydx )\n yscal(:) = abs( y(:) ) + abs( hIN*dydx(:) ) + tiny(1._dp) ! scaling used to monitor accuracy --> CAN BE MODIFIED...\n\n if ( abs(x-xsav) .gt. abs(dxsav) ) call save_a_step ! store intermediate results\n\n if ( (x+hIN-x2)*(x+hIN-x1) .gt. 0.0_dp ) hIN = x2-x ! if stepsize can overshoot, decrease\n\n do\n call CashKarpRK( y, dydx, x, hIN, ytemp, yerr, derivs, para ) ! take a step\n errmax = maxval( abs(yerr(:)/yscal(:)) )/epsIN ! evaluate accuracy\n if ( errmax .lt. 1.0_dp ) exit ! step succeeded\n htemp = safety*hIN*(errmax**pshrnk) ! truncation error too large, reduce stepsize\n hIN = sign( max( abs(htemp), 0.1_dp*abs(hIN) ), hIN ) ! no more than a factor of 10\n xnew = x+hIN\n!!test\n!write(*,*) hIN\n if ( abs(xnew-x) .lt. epsilon(1._dp) ) stop 'RK4as_para_dp --> hey!!! stepsize underflow!'\n end do\n\n if ( errmax .gt. errcon ) then ! compute size of next step\n hnext = safety*hIN*(errmax**pgrow)\n else ! no more than a factor of 5 increase\n hnext = 5.0_dp*hIN\n end if\n\n hdid = hIN\n x = x+hIN\n y(:) = ytemp(:)\n\n if ( abs(hdid-hIN) .gt. epsilon(1._dp) ) then\n nbad = nbad+1_i4\n else\n nok = nok+1_i4\n end if\n\n if ( (x-x2)*(x2-x1) .ge. 0.0_dp ) then ! are we done?!?!\n call save_a_step ! save final step\n if (allocated(xout)) deallocate(xout)\n allocate( xout(kount) ) ! allocate storage for outputs\n xout(:) = xp(1:kount)\n if (allocated(yout)) deallocate(yout)\n allocate( yout(kount, size(yp,2)) ) ! allocate storage for outputs\n yout(:,:) = yp(1:kount, :)\n deallocate( xp, yp ) ! clear out old stored variables\n return ! normal exit\n end if\n\n if ( abs(hnext-hminIN) .lt. epsilon(1.0_dp) ) stop 'RK4as_para_dp --> WTF! ...stepsize smaller than minimum!!!'\n hIN = hnext\n\n end do\n\n stop 'RK4as_para_dp --> dude, too many steps!!!'\n\n contains\n\n subroutine save_a_step ! --> like a macro in C\n kount = kount+1\n if ( kount .gt. size(xp) ) then\n xp=>reallocate( xp, 2*size(xp) )\n yp=>reallocate( yp, size(xp), size(yp,2) )\n end if\n xp(kount) = x\n yp(kount, :) = y(:)\n xsav = x\n end subroutine save_a_step\n\n end subroutine RK4as_para_dp\n\n\n ! ------------------------------------------------------------------\n\n ! SINGLE PRECISION Rosenbrock Method for stiff ode's\n subroutine RBstiff_para_sp( ystart, x1, x2, h, derivs, jacobn, para, xout, yout, & ! obligatory\n hmin, eps ) ! optional\n\n use mo_kind, only : i4, sp\n use mo_utils, only : ge\n use mo_nrutil, only : reallocate\n\n implicit none\n\n ! Intent IN\n real(sp), intent(in) :: x1, x2 ! initial and final time\n real(sp), intent(in) :: h ! guessed step size\n real(sp), dimension(:), intent(in) :: ystart ! initial conditions\n real(sp), optional, intent(in) :: hmin\n real(sp), optional, intent(in) :: eps\n real(sp), dimension(:), intent(in) :: para ! parameters for derivs\n\n ! Intent OUT\n real(sp), dimension(:), allocatable, intent(out) :: xout\n real(sp), dimension(:,:), allocatable, intent(out) :: yout\n\n interface\n subroutine derivs( x, y, para, dydx )\n use mo_kind, only: sp\n implicit none\n real(sp), intent(in) :: x ! time\n real(sp), dimension(:), intent(in) :: y ! unknowns of the equations\n real(sp), dimension(:), intent(in) :: para ! parameters for derivs\n real(sp), dimension(:), intent(out) :: dydx ! derivatives of y\n end subroutine derivs\n\n subroutine jacobn(x, y, para, dfdx, dfdy)\n use mo_kind, only: sp\n implicit none\n real(sp), intent(in) :: x\n real(sp), dimension(:), intent(in) :: y\n real(sp), dimension(:), intent(in) :: para ! parameters for derivs\n real(sp), dimension(:), intent(out) :: dfdx\n real(sp), dimension(:,:), intent(out) :: dfdy\n end subroutine jacobn\n end interface\n\n ! Internal variables\n integer(i4) :: n \n integer(i4) :: nstep ! nuber of steps\n integer(i4) :: kount ! total number of saved steps\n real(sp) :: hIN, hdid, hnext, x, hminIN, epsIN, xsav, dxsav\n real(sp), dimension(size(ystart)) :: dydx, y, yscal, C\n\n ! Pointers\n real(sp), dimension(:), pointer :: xp\n real(sp), dimension(:,:), pointer :: yp\n\n ! parameters\n integer(i4), parameter :: MAXstp = 1000000_i4 ! max number of steps\n\n\n if( present(hmin) ) then\n hminIN = abs(hmin)\n else\n hminIN = 0.0_sp\n end if\n\n if( present(eps) ) then\n epsIN = abs(eps)\n else\n epsIN = 1e-6_sp\n end if\n \n C = 1.0_sp !lower boundary for scaling\n\n hIN = sign( h, x2-x1 )\n hnext = 0.0_sp\n hdid = 0.0_sp\n\n kount = 0_i4\n\n x = x1\n y(:) = ystart(:)\n dxsav = tiny(1._sp)\n xsav = x-2.0_sp*dxsav ! assures storage of first step\n\n nullify( xp, yp )\n allocate( xp(256) )\n allocate( yp(size(xp), size(ystart)) )\n\n call save_a_step ! save initial step\n\n do nstep=1, MAXstp ! take at most MAXstp steps\n\n call derivs( x, y, para, dydx )\n forall( n = 1:size(yscal) ) yscal(n) = max (abs(y(n)),C(n)) ! scaling used to monitor accuracy --> CAN BE MODIFIED...\n\n if ( abs(x-xsav) .gt. abs(dxsav) ) call save_a_step ! store intermediate results\n\n if ( (x+hIN-x2)*(x+hIN-x1) .gt. 0.0_sp ) hIN = x2-x ! if stepsize can overshoot, decrease\n\n call RBstep( y, dydx, x, hIN, epsIN, yscal, hdid, hnext, derivs, jacobn, para) !do one Rosenbrock-Step\n\n if ( ge((x-x2)*(x2-x1), 0.0_sp) ) then ! are we done?!?!\n call save_a_step ! save final step\n if (allocated(xout)) deallocate(xout)\n allocate( xout(kount) ) ! allocate storage for outputs\n xout(:) = xp(1:kount)\n if (allocated(yout)) deallocate(yout)\n allocate( yout(kount, size(yp,2)) ) ! allocate storage for outputs\n yout(:,:) = yp(1:kount, :)\n deallocate( xp, yp ) ! clear out old stored variables\n return ! normal exit\n end if\n\n if ( abs(hnext-hminIN) .lt. epsilon(1.0_sp) ) stop 'RBstiff_para_sp --> WTF! ...stepsize smaller than minimum!!!'\n \n hIN = hnext\n\n end do\n\n stop 'RBstiff_para_sp --> dude, too many steps!!!'\n\n contains\n\n subroutine save_a_step ! --> like a macro in C\n kount = kount+1_i4\n if ( kount .gt. size(xp) ) then\n xp=>reallocate( xp, 2*size(xp) )\n yp=>reallocate( yp, size(xp), size(yp,2) )\n end if\n xp(kount) = x\n yp(kount, :) = y(:)\n xsav = x\n end subroutine save_a_step\n\n end subroutine RBstiff_para_sp\n\n ! DOUBLE PRECISION Rosenbrock Method for stiff ode's\n subroutine RBstiff_para_dp( ystart, x1, x2, h, derivs, jacobn, para, xout, yout, & ! obligatory\n hmin, eps ) ! optional\n\n use mo_kind, only : i4, dp\n use mo_utils, only : ge\n use mo_nrutil, only : reallocate\n\n implicit none\n\n ! Intent IN\n real(dp), intent(in) :: x1, x2 ! initial and final time\n real(dp), intent(in) :: h ! guessed step size\n real(dp), dimension(:), intent(in) :: ystart ! initial conditions\n real(dp), optional, intent(in) :: hmin\n real(dp), optional, intent(in) :: eps\n real(dp), dimension(:), intent(in) :: para ! parameters for derivs\n\n ! Intent OUT\n real(dp), dimension(:), allocatable, intent(out) :: xout\n real(dp), dimension(:,:), allocatable, intent(out) :: yout\n\n interface\n subroutine derivs( x, y, para, dydx )\n use mo_kind, only: dp\n implicit none\n real(dp), intent(in) :: x ! time\n real(dp), dimension(:), intent(in) :: y ! unknowns of the equations\n real(dp), dimension(:), intent(in) :: para ! parameters for derivs\n real(dp), dimension(:), intent(out) :: dydx ! derivatives of y\n end subroutine derivs\n\n subroutine jacobn(x, y, para, dfdx, dfdy)\n use mo_kind, only: dp\n implicit none\n real(dp), intent(in) :: x\n real(dp), dimension(:), intent(in) :: y\n real(dp), dimension(:), intent(in) :: para ! parameters for derivs\n real(dp), dimension(:), intent(out) :: dfdx\n real(dp), dimension(:,:), intent(out) :: dfdy\n end subroutine jacobn\n end interface\n\n ! Internal variables\n integer(i4) :: n \n integer(i4) :: nstep ! nuber of steps\n integer(i4) :: kount ! total number of saved steps\n real(dp) :: hIN, hdid, hnext, x, hminIN, epsIN, xsav, dxsav\n real(dp), dimension(size(ystart)) :: dydx, y, yscal, C\n\n ! Pointers\n real(dp), dimension(:), pointer :: xp\n real(dp), dimension(:,:), pointer :: yp\n\n ! parameters\n integer(i4), parameter :: MAXstp = 1000000_i4 ! max number of steps\n\n\n if( present(hmin) ) then\n hminIN = abs(hmin)\n else\n hminIN = 0.0_dp\n end if\n\n if( present(eps) ) then\n epsIN = abs(eps)\n else\n epsIN = 1e-6_dp\n end if\n \n C = 1.0_dp !lower boundary for scaling\n\n hIN = sign( h, x2-x1 )\n hnext = 0.0_dp\n hdid = 0.0_dp\n\n kount = 0_i4\n\n x = x1\n y(:) = ystart(:)\n dxsav = tiny(1._dp)\n xsav = x-2.0_dp*dxsav ! assures storage of first step\n\n nullify( xp, yp )\n allocate( xp(256) )\n allocate( yp(size(xp), size(ystart)) )\n\n call save_a_step ! save initial step\n\n do nstep=1, MAXstp ! take at most MAXstp steps\n\n call derivs( x, y, para, dydx )\n forall( n = 1:size(yscal) ) yscal(n) = max (abs(y(n)),C(n)) ! scaling used to monitor accuracy --> CAN BE MODIFIED...\n\n if ( abs(x-xsav) .gt. abs(dxsav) ) call save_a_step ! store intermediate results\n\n if ( (x+hIN-x2)*(x+hIN-x1) .gt. 0.0_dp ) hIN = x2-x ! if stepsize can overshoot, decrease\n\n call RBstep( y, dydx, x, hIN, epsIN, yscal, hdid, hnext, derivs, jacobn, para) !do one Rosenbrock-Step\n\n if ( ge((x-x2)*(x2-x1), 0.0_dp) ) then ! are we done?!?!\n call save_a_step ! save final step\n if (allocated(xout)) deallocate(xout)\n allocate( xout(kount) ) ! allocate storage for outputs\n xout(:) = xp(1:kount)\n if (allocated(yout)) deallocate(yout)\n allocate( yout(kount, size(yp,2)) ) ! allocate storage for outputs\n yout(:,:) = yp(1:kount, :)\n deallocate( xp, yp ) ! clear out old stored variables\n return ! normal exit\n end if\n\n if ( abs(hnext-hminIN) .lt. epsilon(1.0_dp) ) stop 'RBstiff_para_dp --> WTF! ...stepsize smaller than minimum!!!'\n \n hIN = hnext\n\n end do\n\n stop 'RBstiff_para_dp --> dude, too many steps!!!'\n\n contains\n\n subroutine save_a_step ! --> like a macro in C\n kount = kount+1_i4\n if ( kount .gt. size(xp) ) then\n xp=>reallocate( xp, 2*size(xp) )\n yp=>reallocate( yp, size(xp), size(yp,2) )\n end if\n xp(kount) = x\n yp(kount, :) = y(:)\n xsav = x\n end subroutine save_a_step\n\n end subroutine RBstiff_para_dp\n\n ! ------------------------------------------------------------------\n ! PRIVATE METHODS\n ! ------------------------------------------------------------------\n\n ! SINGLE PRECISION CASH-KARP RUNGE-KUTTA step\n subroutine CashKarpRK_para_sp( y, dydx, x, h, yout, yerr, derivs, para )\n ! Given values for N variables y and their derivatives dydx known at x, use the fifth-order\n ! Cash-Karp Runge-Kutta method to advance the solution over an interval h and return\n ! the incremented variables as yout. Also return an estimate of the local truncation error\n ! in yout using the embedded fourth order method.\n\n use mo_kind, only : i4, sp\n use mo_nrutil, only : assert_eq\n\n implicit none\n\n ! Intent IN\n real(sp), dimension(:), intent(in) :: y, dydx\n real(sp), intent(in) :: x, h\n real(sp), dimension(:), intent(in) :: para ! parameters for derivs\n\n ! Intent OUT\n real(sp), dimension(:), intent(out) :: yout, yerr\n\n interface\n subroutine derivs( x, y, para, dydx )\n use mo_kind, only: sp\n implicit none\n real(sp), intent(in) :: x\n real(sp), dimension(:), intent(in) :: y\n real(sp), dimension(:), intent(in) :: para ! parameters for derivs\n real(sp), dimension(:), intent(out) :: dydx\n end subroutine derivs\n end interface\n\n ! Internal variables\n integer(i4) :: ndum\n real(sp), dimension(:), allocatable :: ak2, ak3, ak4, ak5, ak6, ytemp\n\n ! parameters\n real(sp), parameter :: A2=0.2_sp, A3=0.3_sp, A4=0.6_sp, A5=1._sp, A6=0.875_sp, B21=0.2_sp, B31=3._sp/40._sp, &\n B32=9._sp/40._sp, B41=0.3_sp, B42=-0.9_sp, B43=1.2_sp, B51=-11._sp/54._sp, B52=2.5_sp, &\n B53=-70._sp/27._sp, B54=35._sp/27._sp, B61=1631._sp/55296._sp, B62=175._sp/512._sp, &\n B63=575._sp/13824._sp, B64=44275._sp/110592._sp, B65=253._sp/4096._sp, &\n C1=37._sp/378._sp, C3=250._sp/621._sp, C4=125._sp/594._sp, C6=512._sp/1771._sp, &\n DC1=C1-2825._sp/27648._sp, DC3=C3-18575._sp/48384._sp, &\n DC4=C4-13525._sp/55296._sp, DC5=-277._sp/14336._sp, DC6=C6-.25_sp\n\n ndum = assert_eq( size(y), size(dydx) ,size(yout) ,size(yerr) , 'CashKarpRK_para_sp' )\n\n allocate( ak2(ndum), ak3(ndum), ak4(ndum), ak5(ndum), ak6(ndum), ytemp(ndum) )\n\n ytemp = y + B21*h*dydx ! first step\n call derivs( x+A2*h, ytemp, para, ak2 ) ! second step\n ytemp = y + h*(B31*dydx+B32*ak2)\n call derivs( x+A3*h, ytemp, para, ak3 ) ! third step\n ytemp = y + h*(B41*dydx+B42*ak2+B43*ak3)\n call derivs( x+A4*h, ytemp, para, ak4 ) ! fourth step\n ytemp = y + h*(B51*dydx+B52*ak2+B53*ak3+B54*ak4)\n call derivs( x+A5*h, ytemp, para, ak5 ) ! fifth step\n ytemp = y + h*(B61*dydx+B62*ak2+B63*ak3+B64*ak4+B65*ak5)\n call derivs( x+A6*h, ytemp, para, ak6 ) ! sixth step\n yout = y + h*(C1*dydx+C3*ak3+C4*ak4+C6*ak6) ! accumulate increments with proper weights\n yerr = h*(DC1*dydx+DC3*ak3+DC4*ak4+DC5*ak5+DC6*ak6)\n\n end subroutine CashKarpRK_para_sp\n\n\n ! DOUBLE PRECISION CASH-KARP RUNGE-KUTTA step\n subroutine CashKarpRK_para_dp( y, dydx, x, h, yout, yerr, derivs, para )\n ! Given values for N variables y and their derivatives dydx known at x, use the fifth-order\n ! Cash-Karp Runge-Kutta method to advance the solution over an interval h and return\n ! the incremented variables as yout. Also return an estimate of the local truncation error\n ! in yout using the embedded fourth order method.\n\n use mo_kind, only: i4, dp\n use mo_nrutil, only: assert_eq\n\n implicit none\n\n ! Intent IN\n real(dp), dimension(:), intent(in) :: y, dydx\n real(dp), intent(in) :: x, h\n real(dp), dimension(:), intent(in) :: para ! parameters for derivs\n\n ! Intent OUT\n real(dp), dimension(:), intent(out) :: yout, yerr\n\n interface\n subroutine derivs( x, y, para, dydx )\n use mo_kind, only: dp\n implicit none\n real(dp), intent(in) :: x\n real(dp), dimension(:), intent(in) :: y\n real(dp), dimension(:), intent(in) :: para ! parameters for derivs\n real(dp), dimension(:), intent(out) :: dydx\n end subroutine derivs\n end interface\n\n ! Internal variables\n integer(i4) :: ndum\n real(dp), dimension(:), allocatable :: ak2, ak3, ak4, ak5, ak6, ytemp\n\n ! parameters\n real(dp), parameter :: A2=0.2_dp, A3=0.3_dp, A4=0.6_dp, A5=1._dp, A6=0.875_dp, B21=0.2_dp, B31=3._dp/40._dp, &\n B32=9._dp/40._dp, B41=0.3_dp, B42=-0.9_dp, B43=1.2_dp, B51=-11._dp/54._dp, B52=2.5_dp, &\n B53=-70._dp/27._dp, B54=35._dp/27._dp, B61=1631._dp/55296._dp, B62=175._dp/512._dp, &\n B63=575._dp/13824._dp, B64=44275._dp/110592._dp, B65=253._dp/4096._dp, &\n C1=37._dp/378._dp, C3=250._dp/621._dp, C4=125._dp/594._dp, C6=512._dp/1771._dp, &\n DC1=C1-2825._dp/27648._dp, DC3=C3-18575._dp/48384._dp, &\n DC4=C4-13525._dp/55296._dp, DC5=-277._dp/14336._dp, DC6=C6-.25_dp\n\n ndum = assert_eq( size(y), size(dydx) ,size(yout) ,size(yerr) , 'CashKarpRK_para_dp' )\n\n allocate( ak2(ndum), ak3(ndum), ak4(ndum), ak5(ndum), ak6(ndum), ytemp(ndum) )\n\n ytemp = y + B21*h*dydx ! first step\n call derivs( x+A2*h, ytemp, para, ak2 ) ! second step\n ytemp = y + h*(B31*dydx+B32*ak2)\n call derivs( x+A3*h, ytemp, para, ak3 ) ! third step\n ytemp = y + h*(B41*dydx+B42*ak2+B43*ak3)\n call derivs( x+A4*h, ytemp, para, ak4 ) ! fourth step\n ytemp = y + h*(B51*dydx+B52*ak2+B53*ak3+B54*ak4)\n call derivs( x+A5*h, ytemp, para, ak5 ) ! fifth step\n ytemp = y + h*(B61*dydx+B62*ak2+B63*ak3+B64*ak4+B65*ak5)\n call derivs( x+A6*h, ytemp, para, ak6 ) ! sixth step\n yout = y + h*(C1*dydx+C3*ak3+C4*ak4+C6*ak6) ! accumulate increments with proper weights\n yerr = h*(DC1*dydx+DC3*ak3+DC4*ak4+DC5*ak5+DC6*ak6)\n\n end subroutine CashKarpRK_para_dp\n\n\n ! SINGLE PRECISION ROSENBROCK step\n subroutine RBstep_para_sp(y, dydx, x, htry, eps, yscal, hdid, hnext, derivs, jacobn, para)\n\n use mo_kind, only : i4, sp\n use mo_utils, only : eq, le\n use mo_nrutil, only : assert_eq, diagadd\n use mo_linear_algebra, only : solve_linear_equations\n\n implicit none\n\n real(sp), dimension(:), intent(inout) :: y\n real(sp), dimension(:), intent(in) :: dydx, yscal\n real(sp), intent(inout) :: x\n real(sp), dimension(:), intent(in) :: para ! parameters for derivs\n\n real(sp), intent(in) :: htry, eps\n real(sp), intent(out) :: hdid, hnext\n\n interface\n subroutine derivs(x, y, para, dydx)\n use mo_kind, only: sp\n implicit none\n real(sp), intent(in) :: x\n real(sp), dimension(:), intent(in) :: y\n real(sp), dimension(:), intent(in) :: para ! parameters for derivs\n real(sp), dimension(:), intent(out) :: dydx\n end subroutine derivs\n\n subroutine jacobn(x, y, para, dfdx, dfdy)\n use mo_kind, only: sp\n implicit none\n real(sp), intent(in) :: x\n real(sp), dimension(:), intent(in) :: y\n real(sp), dimension(:), intent(in) :: para ! parameters for derivs\n real(sp), dimension(:), intent(out) :: dfdx\n real(sp), dimension(:,:), intent(out) :: dfdy\n end subroutine jacobn\n end interface\n\n integer(i4) :: jtry,ndum\n! integer(i4), dimension(size(y)) :: indx\n real(sp), dimension(size(y)) :: dfdx,dytmp,err,g1,g2,g3,g4,ysav\n real(sp), dimension(size(y),size(y)) :: a,dfdy\n real(sp) :: errmax,h,xsav !,d\n\n integer(i4), parameter :: maxtry = 40_i4\n real(sp), parameter :: safety = 0.9_sp, grow = 1.5_sp, pgrow = -0.25_sp,&\n shrnk = 0.5_sp, pshrnk = -1.0_sp/3.0_sp, errcon = 0.1296_sp,&\n gam = 1.0_sp/2.0_sp,&\n a21 = 2.0_sp, a31 = 48.0_sp/25.0_sp, a32 = 6.0_sp/25.0_sp,&\n c21 = -8.0_sp, c31 = 372.0_sp/25.0_sp, c32 = 12.0_sp/5.0_sp,&\n c41 = -112.0_sp/125.0_sp, c42 = -54._sp/125.0_sp, c43 = -2.0_sp/5.0_sp,&\n b1 = 19.0_sp/9.0_sp, b2 = 1.0_sp/2.0_sp, b3 = 25.0_sp/108.0_sp,&\n b4 = 125.0_sp/108.0_sp,&\n e1 = 17.0_sp/54.0_sp, e2 = 7.0_sp/36.0_sp, e3 = 0.0_sp,&\n e4 = 125.0_sp/108.0_sp,&\n c1x = 1.0_sp/2.0_sp, c2x = -3.0_sp/2.0_sp, c3x = 121.0_sp/50.0_sp,&\n c4x = 29.0_sp/250.0_sp,&\n a2x = 1.0_sp, a3x = 3.0_sp/5.0_sp\n\n\n ndum = assert_eq(size(y),size(dydx),size(yscal),'stiff')\n xsav = x\n ysav(:) = y(:)\n\n call jacobn(xsav,ysav,para,dfdx,dfdy)\n\n h = htry\n\n do jtry=1,maxtry\n\n a(:,:) = -dfdy(:,:)\n\n call diagadd(a,1.0_sp/(gam*h))\n! call ludcmp(a,indx,d)\n\n g1 = dydx+h*c1x*dfdx\n g1 = solve_linear_equations(a,g1)\n\n ! call lubksb(a,indx,g1)\n\n y = ysav+a21*g1\n x = xsav+a2x*h\n\n call derivs(x,y,para,dytmp)\n\n g2 = dytmp+h*c2x*dfdx+c21*g1/h\n g2 = solve_linear_equations(a,g2)\n\n ! call lubksb(a,indx,g2)\n\n y = ysav+a31*g1+a32*g2\n x = xsav+a3x*h\n\n call derivs(x,y,para,dytmp)\n\n g3 = dytmp+h*c3x*dfdx+(c31*g1+c32*g2)/h\n g3 = solve_linear_equations(a,g3)\n\n ! call lubksb(a,indx,g3)\n\n g4 = dytmp+h*c4x*dfdx+(c41*g1+c42*g2+c43*g3)/h\n g4 = solve_linear_equations(a,g4)\n\n ! call lubksb(a,indx,g4)\n\n y = ysav+b1*g1+b2*g2+b3*g3+b4*g4\n err = e1*g1+e2*g2+e3*g3+e4*g4\n x = xsav+h\n\n if (eq(x,xsav)) stop 'stepsize not significant in RBstep_para_sp'\n\n errmax = maxval(abs(err/yscal))/eps\n\n if (le(errmax,1.0_sp)) then\n hdid = h\n hnext = merge(safety*h*errmax**pgrow, grow*h, errmax > errcon)\n return\n else\n hnext = safety*h*errmax**pshrnk\n h = sign(max(abs(hnext),shrnk*abs(h)),h)\n end if\n\n end do\n\n stop 'exceeded maxtry in RBstep_para_sp'\n\n end subroutine RBstep_para_sp\n\n\n ! DOUBLE PRECISION ROSENBROCK step\n subroutine RBstep_para_dp(y, dydx, x, htry, eps, yscal, hdid, hnext, derivs, jacobn, para)\n\n use mo_kind, only : i4, dp\n use mo_utils, only : eq, le\n use mo_nrutil, only : assert_eq, diagadd\n use mo_linear_algebra, only : solve_linear_equations\n\n implicit none\n\n real(dp), dimension(:), intent(inout) :: y\n real(dp), dimension(:), intent(in) :: dydx, yscal\n real(dp), intent(inout) :: x\n real(dp), dimension(:), intent(in) :: para ! parameters for derivs\n\n real(dp), intent(in) :: htry, eps\n real(dp), intent(out) :: hdid, hnext\n\n interface\n subroutine derivs(x, y, para, dydx)\n use mo_kind, only: dp\n implicit none\n real(dp), intent(in) :: x\n real(dp), dimension(:), intent(in) :: y\n real(dp), dimension(:), intent(in) :: para ! parameters for derivs\n real(dp), dimension(:), intent(out) :: dydx\n end subroutine derivs\n\n subroutine jacobn(x, y, para, dfdx, dfdy)\n use mo_kind, only: dp\n implicit none\n real(dp), intent(in) :: x\n real(dp), dimension(:), intent(in) :: y\n real(dp), dimension(:), intent(in) :: para ! parameters for derivs\n real(dp), dimension(:), intent(out) :: dfdx\n real(dp), dimension(:,:), intent(out) :: dfdy\n end subroutine jacobn\n end interface\n\n integer(i4) :: jtry,ndum\n! integer(i4), dimension(size(y)) :: indx\n real(dp), dimension(size(y)) :: dfdx,dytmp,err,g1,g2,g3,g4,ysav\n real(dp), dimension(size(y),size(y)) :: a,dfdy\n real(dp) :: errmax,h,xsav !,d\n\n integer(i4), parameter :: maxtry = 40_i4\n real(dp), parameter :: safety = 0.9_dp, grow = 1.5_dp, pgrow = -0.25_dp,&\n shrnk = 0.5_dp, pshrnk = -1.0_dp/3.0_dp, errcon = 0.1296_dp,&\n gam = 1.0_dp/2.0_dp,&\n a21 = 2.0_dp, a31 = 48.0_dp/25.0_dp, a32 = 6.0_dp/25.0_dp,&\n c21 = -8.0_dp, c31 = 372.0_dp/25.0_dp, c32 = 12.0_dp/5.0_dp,&\n c41 = -112.0_dp/125.0_dp, c42 = -54._dp/125.0_dp, c43 = -2.0_dp/5.0_dp,&\n b1 = 19.0_dp/9.0_dp, b2 = 1.0_dp/2.0_dp, b3 = 25.0_dp/108.0_dp,&\n b4 = 125.0_dp/108.0_dp,&\n e1 = 17.0_dp/54.0_dp, e2 = 7.0_dp/36.0_dp, e3 = 0.0_dp,&\n e4 = 125.0_dp/108.0_dp,&\n c1x = 1.0_dp/2.0_dp, c2x = -3.0_dp/2.0_dp, c3x = 121.0_dp/50.0_dp,&\n c4x = 29.0_dp/250.0_dp,&\n a2x = 1.0_dp, a3x = 3.0_dp/5.0_dp\n\n\n ndum = assert_eq(size(y),size(dydx),size(yscal),'stiff')\n xsav = x\n ysav(:) = y(:)\n\n call jacobn(xsav,ysav,para,dfdx,dfdy)\n\n h = htry\n\n do jtry=1,maxtry\n\n a(:,:) = -dfdy(:,:)\n\n call diagadd(a,1.0_dp/(gam*h))\n! call ludcmp(a,indx,d)\n\n g1 = dydx+h*c1x*dfdx\n g1 = solve_linear_equations(a,g1)\n\n ! call lubksb(a,indx,g1)\n\n y = ysav+a21*g1\n x = xsav+a2x*h\n\n call derivs(x,y,para,dytmp)\n\n g2 = dytmp+h*c2x*dfdx+c21*g1/h\n g2 = solve_linear_equations(a,g2)\n\n ! call lubksb(a,indx,g2)\n\n y = ysav+a31*g1+a32*g2\n x = xsav+a3x*h\n\n call derivs(x,y,para,dytmp)\n\n g3 = dytmp+h*c3x*dfdx+(c31*g1+c32*g2)/h\n g3 = solve_linear_equations(a,g3)\n\n ! call lubksb(a,indx,g3)\n\n g4 = dytmp+h*c4x*dfdx+(c41*g1+c42*g2+c43*g3)/h\n g4 = solve_linear_equations(a,g4)\n\n ! call lubksb(a,indx,g4)\n\n y = ysav+b1*g1+b2*g2+b3*g3+b4*g4\n err = e1*g1+e2*g2+e3*g3+e4*g4\n x = xsav+h\n\n if (eq(x,xsav)) stop 'stepsize not significant in RBstep_para_dp'\n\n errmax = maxval(abs(err/yscal))/eps\n\n if (le(errmax,1.0_dp)) then\n hdid = h\n hnext = merge(safety*h*errmax**pgrow, grow*h, errmax > errcon)\n return\n else\n hnext = safety*h*errmax**pshrnk\n h = sign(max(abs(hnext),shrnk*abs(h)),h)\n end if\n\n end do\n\n stop 'exceeded maxtry in RBstep_para_dp'\n\n end subroutine RBstep_para_dp\n\n ! ------------------------------------------------------------------\n\n\nend module mo_ode_solver\n", "meta": {"hexsha": "a562dde88e7b5d40492a27e7da73de7c41eccc0d", "size": 131778, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mo_ode_solver.f90", "max_stars_repo_name": "mcuntz/jams_fortran", "max_stars_repo_head_hexsha": "a1dcab78eda21f930aa6c8c3633598a522f01659", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2020-02-28T00:14:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-20T23:32:41.000Z", "max_issues_repo_path": "mo_ode_solver.f90", "max_issues_repo_name": "mcuntz/jams_fortran", "max_issues_repo_head_hexsha": "a1dcab78eda21f930aa6c8c3633598a522f01659", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-05-09T15:33:11.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-28T16:16:09.000Z", "max_forks_repo_path": "mo_ode_solver.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": 45.1758656154, "max_line_length": 129, "alphanum_fraction": 0.4469107135, "num_tokens": 34415, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.89181104831338, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6808832555455983}} {"text": " real*8 function interp_bilin (a1, a2, av, b1, b2, bv, t1, t2, t3,\n & t4)\n!***********************************************************************\n! Copyright 2010 Los Alamos National Security, LLC All rights reserved\n! Unless otherwise indicated, this information has been authored by an \n! employee or employees of the Los Alamos National Security, LLC (LANS),\n! operator of the Los Alamos National Laboratory under Contract No.\n! DE-AC52-06NA25396 with the U. S. Department of Energy. The U. S.\n! Government has rights to use, reproduce, and distribute this\n! information. The public may copy and use this information without\n! charge, provided that this Notice and any statement of authorship are\n! reproduced on all copies. Neither the Government nor LANS makes any\n! warranty, express or implied, or assumes any liability or\n! responsibility for the use of this information. \n!**********************************************************************\n!\n! PURPOSE\n!\n! To calculate particle time delay using type curves.\n!\n!**********************************************************************\n!\n! Initial implementation: 09-Nov-10, Programmer: Scott Painter\n!\n!**********************************************************************\n! Return the interpolated time value\n \n!argument list same as interp4\n\n implicit none \n\n real*8 a1, a2, av, b1, b2, bv, t1, t2, t3, t4 \n real*8 u, t\n real*8 omt, omu\n\n t=(av-a1)/(a2-a1) \n u=(bv-b1)/(b2-b1) \n\n! if linear in log-space then \n! t=(dlog10 (av) - dlog10 (a1)) / (dlog10 (a2) - dlog10 (a1)) \n! u=(dlog10 (bv) - dlog10 (b1)) / (dlog10 (b2) - dlog10 (b1)) \n\n omt=1.0d0 - t \n omu=1.0d0 - u \n\n interp_bilin =omt*omu*t1 + t*omu*t3 + t*u*t4 + omt*u*t2 \n \n return \n\n end function interp_bilin\n\n", "meta": {"hexsha": "2c78fe4e5e5f25579a8fbf6bbcb67919d38f38c0", "size": 1861, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/interp_bilin.f", "max_stars_repo_name": "satkarra/FEHM", "max_stars_repo_head_hexsha": "5d8d8811bf283fcca0a8a2a1479f442d95371968", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2018-08-09T04:55:28.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-31T21:46:32.000Z", "max_issues_repo_path": "src/interp_bilin.f", "max_issues_repo_name": "satkarra/FEHM", "max_issues_repo_head_hexsha": "5d8d8811bf283fcca0a8a2a1479f442d95371968", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 19, "max_issues_repo_issues_event_min_datetime": "2018-04-06T16:17:14.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-14T04:40:14.000Z", "max_forks_repo_path": "src/interp_bilin.f", "max_forks_repo_name": "satkarra/FEHM", "max_forks_repo_head_hexsha": "5d8d8811bf283fcca0a8a2a1479f442d95371968", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2018-06-07T21:11:55.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-11T13:48:22.000Z", "avg_line_length": 35.7884615385, "max_line_length": 72, "alphanum_fraction": 0.5491671145, "num_tokens": 529, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110425624792, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6808832511548789}} {"text": "PROGRAM F067\n\n ! Copyright 2021 Melwyn Francis Carlo\n\n IMPLICIT NONE\n\n INTEGER, DIMENSION(100, 100) :: TRIANGLE\n\n CHARACTER (LEN=50), PARAMETER :: FILENAME = \"problems/067/p067_triangle.txt\"\n CHARACTER (LEN=300) :: TRIANGLE_NUM_ROW\n CHARACTER (LEN=2) :: TRIANGLE_NUM\n\n INTEGER :: I = 1\n\n INTEGER :: J, DIGITS_I, DIGITS_N\n\n OPEN (2, FILE = FILENAME, STATUS = 'OLD')\n\n DO\n\n READ(2, '(A)', END=10) TRIANGLE_NUM_ROW\n\n J = 1;\n DIGITS_N = 1;\n\n DO DIGITS_I = 1, LEN_TRIM(TRIANGLE_NUM_ROW) + 1\n\n IF (DIGITS_N <= 2) THEN\n TRIANGLE_NUM(DIGITS_N:DIGITS_N) = TRIANGLE_NUM_ROW(DIGITS_I:DIGITS_I);\n DIGITS_N = DIGITS_N + 1\n ELSE\n READ(TRIANGLE_NUM, *) TRIANGLE(I, J)\n DIGITS_N = 1\n J = J + 1\n END IF\n\n END DO\n\n IF (J <= 100) THEN\n DO WHILE (J /= 100)\n TRIANGLE(I, J) = 0\n J = J + 1\n END DO\n END IF\n\n I = I + 1\n\n END DO\n\n 10 CLOSE(2)\n\n DO I = 99, 1, -1\n\n DO J = 1, I\n\n IF (TRIANGLE(I+1, J) >= TRIANGLE(I+1, J+1)) THEN\n TRIANGLE(I, J) = TRIANGLE(I, J) + TRIANGLE(I+1, J)\n ELSE\n TRIANGLE(I, J) = TRIANGLE(I, J) + TRIANGLE(I+1, J+1)\n END IF\n\n END DO\n\n END DO\n\n PRINT ('(I0)'), TRIANGLE(1, 1)\n\nEND PROGRAM F067\n", "meta": {"hexsha": "af2ad61662d44a0473f73196f74a5c1c48bf1701", "size": 1460, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "problems/067/067.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/067/067.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/067/067.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": 21.1594202899, "max_line_length": 86, "alphanum_fraction": 0.4739726027, "num_tokens": 465, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375734, "lm_q2_score": 0.8376199694135332, "lm_q1q2_score": 0.680873897904369}} {"text": "!= static_assert pre(T)\n!= static_assert post(\"x == r + y * q\" & \"r < y\")\nsubroutine example(x, y, q, r)\n\n implicit none\n\n integer :: x, y\n integer :: q\n integer :: r\n\n r = x\n q = 0\n != static_assert seq(\"r == x\" & \"q == 0\")\n do while (y <= r)\n != static_assert invariant(\"x == r + y * q\")\n r = r - y\n q = q + 1\n end do\nend subroutine example\n\n\n!= static_assert post(\"x <= y\" -> \"min == x\")\n!= static_assert post(\"y <= x\" -> \"min == y\")\ninteger (kind=8) function min(x, y)\n implicit none\n\n integer (kind=8) :: x, y\n\n if (x <= y) then\n min = x\n else\n min = y\n end if\n\nend function min\n\n\n!= static_assert post(\"x <= y\" -> \"minf == x\")\n!= static_assert post(\"y <= x\" -> \"minf == y\")\nreal function minf(x, y)\n implicit none\n\n real :: x, y\n\n if (x <= y) then\n minf = x\n else\n minf = y\n end if\n\nend function minf\n\n\n!= decl_aux(\"integer\" :: x_)\n!= decl_aux(\"integer\" :: y_)\n!= static_assert pre(\"x == x_\" & \"y == y_\")\n!= static_assert post(\"multiply == x_ * y_\")\ninteger function multiply(x, y)\n implicit none\n\n integer :: x, y\n integer :: r, n\n\n if (x < 0) then\n x = -x\n y = -y\n end if\n\n r = 0\n n = 0\n != static_assert seq(\"x * y == x_ * y_\" & \"n == 0\" & \"r == 0\" & \"n <= x\")\n do while (n < x)\n != static_assert invariant(\"x * y == x_ * y_\" & \"r == n * y\" & \"n <= x\")\n r = r + y\n n = n + 1\n end do\n\n multiply = r\nend function multiply\n\n\n!= static_assert pre(\"x >= 0\")\n!= static_assert post(\"2 * halve > x - 2\")\n!= static_assert post(\"2 * halve <= x\")\ninteger function halve(x)\n implicit none\n\n integer :: x\n integer :: n, q\n\n n = 2\n q = 0\n\n != static_assert seq(\"n == 2\" & \"q == 0\" & \"n <= x + 2\")\n do while (n <= x)\n != static_assert invariant(\"n <= x + 2\" & \"2 * q == n - 2\")\n q = q + 1\n n = n + 2\n end do\n\n halve = q\nend function halve\n\n\n! Performs (positive) integer division, rounded down.\n!= decl_aux(\"integer\" :: x_)\n!= decl_aux(\"integer\" :: y_)\n!= static_assert pre(\"x == x_\" & \"y == y_\")\n!= static_assert pre(\"x >= 0\")\n!= static_assert post(\"y_ * div > x_ - y_\")\n!= static_assert post(\"y_ * div <= x_\")\ninteger function div(x, y)\n\n integer :: x, y\n integer :: n = y, q = 0\n\n != static_assert seq(\"x == x_\" & \"y == y_\" & \"n == y\" & \"q == 0\" & \"n <= x + y\")\n do while (n <= x)\n != static_assert invariant(\"x == x_\" & \"y == y_\" & \"n <= x + y\" & \"y * q == n - y\")\n q = q + 1\n n = n + y\n end do\n\n div = q\n\nend function div\n\n\n!= decl_aux(\"integer\" :: x_)\n!= decl_aux(\"real\" :: y_)\n!= static_assert pre(\"x == x_\" & \"y == y_\")\n!= static_assert post(\"multiplyf == x_ * y_\")\nreal function multiplyf(x, y)\n implicit none\n\n integer :: x, n\n real :: y, r\n\n if (x < 0) then\n x = -x\n y = -y\n end if\n\n r = 0.0\n n = 0\n != static_assert seq(\"x * y == x_ * y_\" & \"n == 0\" & \"r == 0\" & \"n <= x\")\n do while (n < x)\n != static_assert invariant(\"x * y == x_ * y_\" & \"r == n * y\" & \"n <= x\")\n r = r + y\n n = n + 1\n end do\n\n multiplyf = r\nend function multiplyf\n", "meta": {"hexsha": "8d22de2d9df959cf79e496b487d1986bf5324908", "size": 2986, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "samples/invariants/invariants.f90", "max_stars_repo_name": "raehik/camfort", "max_stars_repo_head_hexsha": "2f5ac9a478116ae8c7aa2a5e079b81aa58988e45", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 90, "max_stars_repo_stars_event_min_datetime": "2016-06-02T15:37:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-30T20:10:14.000Z", "max_issues_repo_path": "samples/invariants/invariants.f90", "max_issues_repo_name": "apthorpe/camfort", "max_issues_repo_head_hexsha": "1e307ae972b2fe6f63af6d3b0a3d106eec77e8a8", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 124, "max_issues_repo_issues_event_min_datetime": "2016-05-25T13:21:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-10T14:26:03.000Z", "max_forks_repo_path": "samples/invariants/invariants.f90", "max_forks_repo_name": "raehik/camfort", "max_forks_repo_head_hexsha": "2f5ac9a478116ae8c7aa2a5e079b81aa58988e45", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 16, "max_forks_repo_forks_event_min_datetime": "2016-06-02T14:51:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-14T15:59:33.000Z", "avg_line_length": 19.264516129, "max_line_length": 88, "alphanum_fraction": 0.5053583389, "num_tokens": 1106, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.8128673110375458, "lm_q1q2_score": 0.6808738872660984}} {"text": "module adams_bashforth\n implicit none\n\n contains\n\n \n ! ---------------------------------------------------------------------------\n !> A first-order Forward Euler algorithm\n !! This is not a good algorithm. Don't use it, except to show how\n !! how bad it is.\n\n subroutine ForwardEuler(X_new, dXdt, X, dt, xlow, xhigh, ylow, yhigh, layers, OL, AB_order)\n implicit none\n\n double precision, intent(out) :: X_new(xlow-OL:xhigh+OL, ylow-OL:yhigh+OL, layers)\n double precision, intent(inout) :: dXdt(xlow-OL:xhigh+OL, ylow-OL:yhigh+OL, layers, AB_order)\n double precision, intent(in) :: X(xlow-OL:xhigh+OL, ylow-OL:yhigh+OL, layers)\n double precision, intent(in) :: dt\n integer, intent(in) :: xlow, xhigh, ylow, yhigh, layers, OL, AB_order\n\n X_new = X + dt*dXdt(:,:,:,1)\n\n end subroutine ForwardEuler\n\n! ---------------------------------------------------------------------------\n !> A second-order Adams-Bashforth algorithm\n subroutine AB2(X_new, dXdt, X, dt, xlow, xhigh, ylow, yhigh, layers, OL, AB_order)\n implicit none\n\n double precision, intent(out) :: X_new(xlow-OL:xhigh+OL, ylow-OL:yhigh+OL, layers)\n double precision, intent(inout) :: dXdt(xlow-OL:xhigh+OL, ylow-OL:yhigh+OL, layers, AB_order)\n double precision, intent(in) :: X(xlow-OL:xhigh+OL, ylow-OL:yhigh+OL, layers)\n double precision, intent(in) :: dt\n integer, intent(in) :: xlow, xhigh, ylow, yhigh, layers, OL, AB_order\n\n X_new = X + dt*(3d0*dXdt(:,:,:,1) - 1d0*dXdt(:,:,:,2))/2d0\n\n ! Cycle tendencies\n dXdt(:,:,:,2) = dXdt(:,:,:,1)\n \n end subroutine AB2\n\n! ---------------------------------------------------------------------------\n !> A third-order Adams-Bashforth algorithm\n subroutine AB3(X_new, dXdt, X, dt, xlow, xhigh, ylow, yhigh, layers, OL, AB_order)\n implicit none\n\n double precision, intent(out) :: X_new(xlow-OL:xhigh+OL, ylow-OL:yhigh+OL, layers)\n double precision, intent(inout) :: dXdt(xlow-OL:xhigh+OL, ylow-OL:yhigh+OL, layers, AB_order)\n double precision, intent(in) :: X(xlow-OL:xhigh+OL, ylow-OL:yhigh+OL, layers)\n double precision, intent(in) :: dt\n integer, intent(in) :: xlow, xhigh, ylow, yhigh, layers, OL, AB_order\n\n X_new = X + dt*(23d0*dXdt(:,:,:,1) - 16d0*dXdt(:,:,:,2) + &\n 5d0*dXdt(:,:,:,3))/12d0\n\n ! Cycle tendencies\n dXdt(:,:,:,3) = dXdt(:,:,:,2)\n dXdt(:,:,:,2) = dXdt(:,:,:,1)\n \n end subroutine AB3\n\n! ---------------------------------------------------------------------------\n !> A fourth-order Adams-Bashforth algorithm\n subroutine AB4(X_new, dXdt, X, dt, xlow, xhigh, ylow, yhigh, layers, OL, AB_order)\n implicit none\n\n double precision, intent(out) :: X_new(xlow-OL:xhigh+OL, ylow-OL:yhigh+OL, layers)\n double precision, intent(inout) :: dXdt(xlow-OL:xhigh+OL, ylow-OL:yhigh+OL, layers, AB_order)\n double precision, intent(in) :: X(xlow-OL:xhigh+OL, ylow-OL:yhigh+OL, layers)\n double precision, intent(in) :: dt\n integer, intent(in) :: xlow, xhigh, ylow, yhigh, layers, OL, AB_order\n\n X_new = X + dt*(55d0*dXdt(:,:,:,1) - 59d0*dXdt(:,:,:,2) + &\n 37d0*dXdt(:,:,:,3) - 9d0*dXdt(:,:,:,4))/24d0\n\n ! Cycle tendencies\n dXdt(:,:,:,4) = dXdt(:,:,:,3)\n dXdt(:,:,:,3) = dXdt(:,:,:,2)\n dXdt(:,:,:,2) = dXdt(:,:,:,1)\n \n end subroutine AB4\n\n\n! ---------------------------------------------------------------------------\n !> A fifth-order Adams-Bashforth algorithm\n subroutine AB5(X_new, dXdt, X, dt, xlow, xhigh, ylow, yhigh, layers, OL, AB_order)\n implicit none\n\n double precision, intent(out) :: X_new(xlow-OL:xhigh+OL, ylow-OL:yhigh+OL, layers)\n double precision, intent(inout) :: dXdt(xlow-OL:xhigh+OL, ylow-OL:yhigh+OL, layers, AB_order)\n double precision, intent(in) :: X(xlow-OL:xhigh+OL, ylow-OL:yhigh+OL, layers)\n double precision, intent(in) :: dt\n integer, intent(in) :: xlow, xhigh, ylow, yhigh, layers, OL, AB_order\n\n X_new = X + dt*(1901d0*dXdt(:,:,:,1) - 2774d0*dXdt(:,:,:,2) + &\n 2616d0*dXdt(:,:,:,3) - 1274d0*dXdt(:,:,:,4) + &\n 251d0*dXdt(:,:,:,5))/720d0\n\n ! Cycle tendencies\n dXdt(:,:,:,5) = dXdt(:,:,:,4)\n dXdt(:,:,:,4) = dXdt(:,:,:,3)\n dXdt(:,:,:,3) = dXdt(:,:,:,2)\n dXdt(:,:,:,2) = dXdt(:,:,:,1)\n \n end subroutine AB5\n\nend module adams_bashforth\n", "meta": {"hexsha": "7b4e40b158006584cf680911bae00a81643c1de8", "size": 4360, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/adams_bashforth.f90", "max_stars_repo_name": "edoddridge/aronnax", "max_stars_repo_head_hexsha": "7c33836fe8d6c8ea4283f2357325d12ff655bc10", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2017-05-03T17:21:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-17T21:01:06.000Z", "max_issues_repo_path": "src/adams_bashforth.f90", "max_issues_repo_name": "edoddridge/aronnax", "max_issues_repo_head_hexsha": "7c33836fe8d6c8ea4283f2357325d12ff655bc10", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 172, "max_issues_repo_issues_event_min_datetime": "2017-03-26T16:00:03.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-18T23:34:08.000Z", "max_forks_repo_path": "src/adams_bashforth.f90", "max_forks_repo_name": "edoddridge/aronnax", "max_forks_repo_head_hexsha": "7c33836fe8d6c8ea4283f2357325d12ff655bc10", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2017-08-19T12:41:16.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-18T08:32:48.000Z", "avg_line_length": 40.0, "max_line_length": 97, "alphanum_fraction": 0.5509174312, "num_tokens": 1448, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206870747658, "lm_q2_score": 0.7549149978955811, "lm_q1q2_score": 0.6808734535850279}} {"text": "c\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc . .\nc . copyright (c) 1998 by UCAR .\nc . .\nc . University Corporation for Atmospheric Research .\nc . .\nc . all rights reserved .\nc . .\nc . .\nc . SPHEREPACK3.0 .\nc . .\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc\nc\nc\nc ... file idvtgs.f\nc\nc this file includes documentation and code for\nc subroutine idvtgs i\nc\nc ... files which must be loaded with idvtgs.f\nc\nc sphcom.f, hrfft.f, vhsgs.f,shags.f, gaqd.f\nc\nc\nc subroutine idvtgs(nlat,nlon,isym,nt,v,w,idvw,jdvw,ad,bd,av,bv,\nc +mdab,ndab,wvhsgs,lvhsgs,work,lwork,pertbd,pertbv,ierror)\nc\nc given the scalar spherical harmonic coefficients ad,bd precomputed\nc by subroutine shaes for the scalar field divg and coefficients av,bv\nc precomputed by subroutine shaes for the scalar field vort, subroutine\nc idvtgs computes a vector field (v,w) whose divergence is divg - pertbd\nc and whose vorticity is vort - pertbv. w the is east longitude component\nc and v is the colatitudinal component of the velocity. if nt=1 (see nt\nc below) pertrbd and pertbv are constants which must be subtracted from\nc divg and vort for (v,w) to exist (see the description of pertbd and\nc pertrbv below). usually pertbd and pertbv are zero or small relative\nc to divg and vort. w(i,j) and v(i,j) are the velocity components at\nc gaussian colatitude theta(i) (see nlat as input argument) and longitude\nc lambda(j) = (j-1)*2*pi/nlon\nc\nc the\nc\nc divergence(v(i,j),w(i,j))\nc\nc = [d(sint*v)/dtheta + dw/dlambda]/sint\nc\nc = divg(i,j) - pertbd\nc\nc and\nc\nc vorticity(v(i,j),w(i,j))\nc\nc = [-dv/dlambda + d(sint*w)/dtheta]/sint\nc\nc = vort(i,j) - pertbv\nc\nc where\nc\nc sint = cos(theta(i)).\nc\nc\nc input parameters\nc\nc nlat the number of points in the gaussian colatitude grid on the\nc full sphere. these lie in the interval (0,pi) and are computed\nc in radians in theta(1) <...< theta(nlat) by subroutine gaqd.\nc if nlat is odd the equator will be included as the grid point\nc theta((nlat+1)/2). if nlat is even the equator will be\nc excluded as a grid point and will lie half way between\nc theta(nlat/2) and theta(nlat/2+1). nlat must be at least 3.\nc note: on the half sphere, the number of grid points in the\nc colatitudinal direction is nlat/2 if nlat is even or\nc (nlat+1)/2 if nlat is odd.\nc\nc nlon the number of distinct londitude points. nlon determines\nc the grid increment in longitude as 2*pi/nlon. for example\nc nlon = 72 for a five degree grid. nlon must be greater\nc than 3. the axisymmetric case corresponds to nlon=1.\nc the efficiency of the computation is improved when nlon\nc is a product of small prime numbers.\nc\nc\nc isym isym determines whether (v,w) are computed on the full or half\nc sphere as follows:\nc\nc = 0\nc divg,vort are neither pairwise symmetric/antisymmetric nor\nc antisymmetric/symmetric about the equator as described for\nc isym = 1 or isym = 2 below. in this case, the vector field\nc (v,w) is computed on the entire sphere. i.e., in the arrays\nc w(i,j) and v(i,j) i=1,...,nlat and j=1,...,nlon.\nc\nc = 1\nc\nc divg is antisymmetric and vort is symmetric about the equator.\nc in this case w is antisymmetric and v is symmetric about the\nc equator. w and v are computed on the northern hemisphere only.\nc if nlat is odd they are computed for i=1,...,(nlat+1)/2\nc and j=1,...,nlon. if nlat is even they are computed for\nc i=1,...,nlat/2 and j=1,...,nlon.\nc\nc = 2\nc\nc divg is symmetric and vort is antisymmetric about the equator.\nc in this case w is symmetric and v is antisymmetric about the\nc equator. w and v are computed on the northern hemisphere only.\nc if nlat is odd they are computed for i=1,...,(nlat+1)/2\nc and j=1,...,nlon. if nlat is even they are computed for\nc i=1,...,nlat/2 and j=1,...,nlon.\nc\nc\nc nt in the program that calls idvtgs, nt is the number of scalar\nc and vector fields. some computational efficiency is obtained\nc for multiple fields. the arrays ad,bd,av,bv,u, and v can be\nc three dimensional and pertbd,pertbv can be one dimensional\nc corresponding to indexed multiple arrays divg, vort. in this\nc case, multiple synthesis will be performed to compute each\nc vector field. the third index for ad,bd,av,bv,v,w and first\nc pertrbd,pertbv is the synthesis index which assumes the values\nc k=1,...,nt. for a single synthesis set nt=1. the description of\nc remaining parameters is simplified by assuming that nt=1 or that\nc ad,bd,av,bv,v,w are two dimensional and pertbd,pertbv are\nc constants.\nc\nc idvw the first dimension of the arrays v,w as it appears in\nc the program that calls idvtgs. if isym = 0 then idvw\nc must be at least nlat. if isym = 1 or 2 and nlat is\nc even then idvw must be at least nlat/2. if isym = 1 or 2\nc and nlat is odd then idvw must be at least (nlat+1)/2.\nc\nc jdvw the second dimension of the arrays v,w as it appears in\nc the program that calls idvtgs. jdvw must be at least nlon.\nc\nc ad,bd two or three dimensional arrays (see input parameter nt)\nc that contain scalar spherical harmonic coefficients\nc of the divergence array divg as computed by subroutine shaes.\nc\nc av,bv two or three dimensional arrays (see input parameter nt)\nc that contain scalar spherical harmonic coefficients\nc of the vorticity array vort as computed by subroutine shaes.\nc *** ad,bd,av,bv must be computed by shaes prior to calling idvtgs.\nc\nc mdab the first dimension of the arrays ad,bd,av,bv as it appears\nc in the program that calls idvtgs (and shags). mdab must be at\nc least min0(nlat,(nlon+2)/2) if nlon is even or at least\nc min0(nlat,(nlon+1)/2) if nlon is odd.\nc\nc ndab the second dimension of the arrays ad,bd,av,bv as it appears in\nc the program that calls idvtgs (and shags). ndab must be at\nc least nlat.\nc\nc wvhsgs an array which must be initialized by subroutine vhsgsi.\nc wvhsgs can be used repeatedly by idvtgs as long as nlon\nc and nlat remain unchanged. wvhsgs must not be altered\nc between calls of idvtgs.\nc\nc\nc lvhsgs the dimension of the array wvhsgs as it appears in the\nc program that calls idvtgs. define\nc\nc l1 = min0(nlat,nlon/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc and\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc then lvhsgs must be at least\nc\nc l1*l2*(nlat+nlat-l1+1)+nlon+15+2*nlat\nc\nc work a work array that does not have to be saved.\nc\nc lwork the dimension of the array work as it appears in the\nc program that calls idvtgs. define\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc l1 = min0(nlat,nlon/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc if isym = 0 then lwork must be at least\nc\nc nlat*((2*nt+1)*nlon+4*nt*l1+1)\nc\nc if isym = 1 or 2 then lwork must be at least\nc\nc (2*nt+1)*l2*nlon+nlat*(4*nt*l1+1)\nc\nc **************************************************************\nc\nc output parameters\nc\nc\nc v,w two or three dimensional arrays (see input parameter nt) that\nc contain a vector field whose divergence is divg - pertbd and\nc whose vorticity is vort - pertbv. w(i,j) is the east longitude\nc component and v(i,j) is the colatitudinal component of velocity\nc at the colatitude theta(i) = (i-1)*pi/(nlat-1) and longitude\nc lambda(j) = (j-1)*2*pi/nlon for i=1,...,nlat and j=1,...,nlon.\nc\nc pertbd a nt dimensional array (see input parameter nt and assume nt=1\nc for the description that follows). divg - pertbd is a scalar\nc field which can be the divergence of a vector field (v,w).\nc pertbd is related to the scalar harmonic coefficients ad,bd\nc of divg (computed by shaes) by the formula\nc\nc pertbd = ad(1,1)/(2.*sqrt(2.))\nc\nc an unperturbed divg can be the divergence of a vector field\nc only if ad(1,1) is zero. if ad(1,1) is nonzero (flagged by\nc pertbd nonzero) then subtracting pertbd from divg yields a\nc scalar field for which ad(1,1) is zero. usually pertbd is\nc zero or small relative to divg.\nc\nc pertbv a nt dimensional array (see input parameter nt and assume nt=1\nc for the description that follows). vort - pertbv is a scalar\nc field which can be the vorticity of a vector field (v,w).\nc pertbv is related to the scalar harmonic coefficients av,bv\nc of vort (computed by shaes) by the formula\nc\nc pertbv = av(1,1)/(2.*sqrt(2.))\nc\nc an unperturbed vort can be the vorticity of a vector field\nc only if av(1,1) is zero. if av(1,1) is nonzero (flagged by\nc pertbv nonzero) then subtracting pertbv from vort yields a\nc scalar field for which av(1,1) is zero. usually pertbv is\nc zero or small relative to vort.\nc\nc ierror = 0 no errors\nc = 1 error in the specification of nlat\nc = 2 error in the specification of nlon\nc = 3 error in the specification of isym\nc = 4 error in the specification of nt\nc = 5 error in the specification of idvw\nc = 6 error in the specification of jdvw\nc = 7 error in the specification of mdab\nc = 8 error in the specification of ndab\nc = 9 error in the specification of lvhsgs\nc = 10 error in the specification of lwork\nc **********************************************************************\nc \nc \n subroutine idvtgs(nlat,nlon,isym,nt,v,w,idvw,jdvw,ad,bd,av,bv,\n +mdab,ndab,wvhsgs,lvhsgs,work,lwork,pertbd,pertbv,ierror)\n dimension w(idvw,jdvw,nt),v(idvw,jdvw,nt),pertbd(nt),pertbv(nt)\n dimension ad(mdab,ndab,nt),bd(mdab,ndab,nt)\n dimension av(mdab,ndab,nt),bv(mdab,ndab,nt)\n dimension wvhsgs(lvhsgs),work(lwork)\nc\nc check input parameters\nc\n ierror = 1\n if(nlat .lt. 3) return\n ierror = 2\n if(nlon .lt. 4) return\n ierror = 3\n if(isym.lt.0 .or. isym.gt.2) return\n ierror = 4\n if(nt .lt. 0) return\n ierror = 5\n imid = (nlat+1)/2\n if((isym.eq.0 .and. idvw.lt.nlat) .or.\n + (isym.ne.0 .and. idvw.lt.imid)) return\n ierror = 6\n if(jdvw .lt. nlon) return\n ierror = 7\n mmax = min0(nlat,(nlon+1)/2)\n if(mdab .lt. min0(nlat,(nlon+2)/2)) return\n ierror = 8\n if(ndab .lt. nlat) return\n ierror = 9\n idz = (mmax*(nlat+nlat-mmax+1))/2\n lzimn = idz*imid\n if(lvhsgs .lt. lzimn+lzimn+nlon+15) return\n ierror = 10\nc\nc verify unsaved work space length\nc\n mn = mmax*nlat*nt\n if(isym.ne.0 .and. lwork .lt.\n +nlat*(2*nt*nlon+max0(6*imid,nlon))+4*mn+nlat) return\n if(isym.eq.0 .and. lwork .lt.\n +imid*(2*nt*nlon+max0(6*nlat,nlon))+4*mn+nlat) return\n ierror = 0\nc\nc set work space pointers\nc\n ibr = 1\n ibi = ibr+mn\n icr = ibi+mn\n ici = icr + mn\n is = ici + mn\n iwk = is + nlat\n liwk = lwork-4*mn-nlat\n call idvtgs1(nlat,nlon,isym,nt,v,w,idvw,jdvw,work(ibr),\n +work(ibi),work(icr),work(ici),mmax,work(is),mdab,ndab,ad,bd,\n +av,bv,wvhsgs,lvhsgs,work(iwk),liwk,pertbd,pertbv,ierror)\n return\n end\n\n subroutine idvtgs1(nlat,nlon,isym,nt,v,w,idvw,jdvw,br,bi,\n +cr,ci,mmax,sqnn,mdab,ndab,ad,bd,av,bv,wvhsgs,lvhsgs,wk,lwk,\n +pertbd,pertbv,ierror)\n dimension w(idvw,jdvw,nt),v(idvw,jdvw,nt)\n dimension br(mmax,nlat,nt),bi(mmax,nlat,nt),sqnn(nlat)\n dimension cr(mmax,nlat,nt),ci(mmax,nlat,nt)\n dimension ad(mdab,ndab,nt),bd(mdab,ndab,nt)\n dimension av(mdab,ndab,nt),bv(mdab,ndab,nt)\n dimension wvhsgs(lvhsgs),wk(lwk)\n dimension pertbd(nt),pertbv(nt)\nc\nc preset coefficient multiplyers in vector\nc\n do 1 n=2,nlat\n fn = float(n-1)\n sqnn(n) = sqrt(fn*(fn+1.))\n 1 continue\nc\nc compute multiple vector fields coefficients\nc\n do 2 k=1,nt\nc\nc set divergence,vorticity perturbation constants\nc\n pertbd(k) = ad(1,1,k)/(2.*sqrt(2.))\n pertbv(k) = av(1,1,k)/(2.*sqrt(2.))\nc\nc preset br,bi,cr,ci to 0.0\nc\n do 3 n=1,nlat\n do 4 m=1,mmax\n br(m,n,k) = 0.0\n bi(m,n,k) = 0.0\n cr(m,n,k) = 0.0\n ci(m,n,k) = 0.0\n 4 continue\n 3 continue\nc\nc compute m=0 coefficients\nc\n do 5 n=2,nlat\n br(1,n,k) = -ad(1,n,k)/sqnn(n)\n bi(1,n,k) = -bd(1,n,k)/sqnn(n)\n cr(1,n,k) = av(1,n,k)/sqnn(n)\n ci(1,n,k) = bv(1,n,k)/sqnn(n)\n 5 continue\nc\nc compute m>0 coefficients\nc\n do 6 m=2,mmax\n do 7 n=m,nlat\n br(m,n,k) = -ad(m,n,k)/sqnn(n)\n bi(m,n,k) = -bd(m,n,k)/sqnn(n)\n cr(m,n,k) = av(m,n,k)/sqnn(n)\n ci(m,n,k) = bv(m,n,k)/sqnn(n)\n 7 continue\n 6 continue\n 2 continue\nc\nc set ityp for vector synthesis without assuming div=0 or curl=0\nc\n if (isym.eq.0) then\n ityp = 0\n else if (isym.eq.1) then\n ityp = 3\n else if (isym.eq.2) then\n ityp = 6\n end if\nc\nc sythesize br,bi,cr,ci into the vector field (v,w)\nc\n call vhsgs(nlat,nlon,ityp,nt,v,w,idvw,jdvw,br,bi,cr,ci,\n + mmax,nlat,wvhsgs,lvhsgs,wk,lwk,ierror)\n return\n end\n", "meta": {"hexsha": "c26ddddaa1b8e60e5b3d824885065c5739ac2903", "size": 14829, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "contrib/spherepack/Src/idvtgs.f", "max_stars_repo_name": "xylar/cdat", "max_stars_repo_head_hexsha": "8a5080cb18febfde365efc96147e25f51494a2bf", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 62, "max_stars_repo_stars_event_min_datetime": "2018-03-30T15:46:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-08T23:30:24.000Z", "max_issues_repo_path": "contrib/spherepack/Src/idvtgs.f", "max_issues_repo_name": "xylar/cdat", "max_issues_repo_head_hexsha": "8a5080cb18febfde365efc96147e25f51494a2bf", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 114, "max_issues_repo_issues_event_min_datetime": "2018-03-21T01:12:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-05T12:29:54.000Z", "max_forks_repo_path": "contrib/spherepack/Src/idvtgs.f", "max_forks_repo_name": "CDAT/uvcdat", "max_forks_repo_head_hexsha": "5133560c0c049b5c93ee321ba0af494253b44f91", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2018-06-06T02:42:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-26T03:27:00.000Z", "avg_line_length": 39.0236842105, "max_line_length": 79, "alphanum_fraction": 0.5753590937, "num_tokens": 4653, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206870747657, "lm_q2_score": 0.7549149978955811, "lm_q1q2_score": 0.6808734535850278}} {"text": "*DECK DPOFS\n SUBROUTINE DPOFS (A, LDA, N, V, ITASK, IND, WORK)\nC***BEGIN PROLOGUE DPOFS\nC***PURPOSE Solve a positive definite symmetric system of linear\nC equations.\nC***LIBRARY SLATEC\nC***CATEGORY D2B1B\nC***TYPE DOUBLE PRECISION (SPOFS-S, DPOFS-D, CPOFS-C)\nC***KEYWORDS HERMITIAN, LINEAR EQUATIONS, POSITIVE DEFINITE, SYMMETRIC\nC***AUTHOR Voorhees, E. A., (LANL)\nC***DESCRIPTION\nC\nC Subroutine DPOFS solves a positive definite symmetric\nC NxN system of double precision linear equations using\nC LINPACK subroutines DPOCO and DPOSL. That is, if A is an\nC NxN double precision positive definite symmetric matrix and if\nC X and B are double precision N-vectors, then DPOFS solves\nC the equation\nC\nC A*X=B.\nC\nC The matrix A is first factored into upper and lower tri-\nC angular matrices R and R-TRANPOSE. These factors are used to\nC find the solution vector X. An approximate condition number is\nC calculated to provide a rough estimate of the number of\nC digits of accuracy in the computed solution.\nC\nC If the equation A*X=B is to be solved for more than one vector\nC B, the factoring of A does not need to be performed again and\nC the option only to solve (ITASK .GT. 1) will be faster for\nC the succeeding solutions. In this case, the contents of A,\nC LDA, and N must not have been altered by the user following\nC factorization (ITASK=1). IND will not be changed by DPOFS\nC in this case.\nC\nC Argument Description ***\nC\nC A DOUBLE PRECISION(LDA,N)\nC on entry, the doubly subscripted array with dimension\nC (LDA,N) which contains the coefficient matrix. Only\nC the upper triangle, including the diagonal, of the\nC coefficient matrix need be entered and will subse-\nC quently be referenced and changed by the routine.\nC on return, A contains in its upper triangle an upper\nC triangular matrix R such that A = (R-TRANPOSE) * R .\nC LDA INTEGER\nC the leading dimension of the array A. LDA must be great-\nC er than or equal to N. (terminal error message IND=-1)\nC N INTEGER\nC the order of the matrix A. N must be greater\nC than or equal to 1. (terminal error message IND=-2)\nC V DOUBLE PRECISION(N)\nC on entry, the singly subscripted array(vector) of di-\nC mension N which contains the right hand side B of a\nC system of simultaneous linear equations A*X=B.\nC on return, V contains the solution vector, X .\nC ITASK INTEGER\nC If ITASK = 1, the matrix A is factored and then the\nC linear equation is solved.\nC If ITASK .GT. 1, the equation is solved using the existing\nC factored matrix A.\nC If ITASK .LT. 1, then terminal error message IND=-3 is\nC printed.\nC IND INTEGER\nC GT. 0 IND is a rough estimate of the number of digits\nC of accuracy in the solution, X.\nC LT. 0 See error message corresponding to IND below.\nC WORK DOUBLE PRECISION(N)\nC a singly subscripted array of dimension at least N.\nC\nC Error Messages Printed ***\nC\nC IND=-1 Terminal N is greater than LDA.\nC IND=-2 Terminal N is less than 1.\nC IND=-3 Terminal ITASK is less than 1.\nC IND=-4 Terminal The matrix A is computationally singular or\nC is not positive definite. A solution\nC has not been computed.\nC IND=-10 Warning The solution has no apparent significance.\nC The solution may be inaccurate or the\nC matrix A may be poorly scaled.\nC\nC Note- The above Terminal(*fatal*) Error Messages are\nC designed to be handled by XERMSG in which\nC LEVEL=1 (recoverable) and IFLAG=2 . LEVEL=0\nC for warning error messages from XERMSG. Unless\nC the user provides otherwise, an error message\nC will be printed followed by an abort.\nC\nC***REFERENCES J. J. Dongarra, J. R. Bunch, C. B. Moler, and G. W.\nC Stewart, LINPACK Users' Guide, SIAM, 1979.\nC***ROUTINES CALLED D1MACH, DPOCO, DPOSL, XERMSG\nC***REVISION HISTORY (YYMMDD)\nC 800514 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890831 Modified array declarations. (WRB)\nC 890831 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\nC 900510 Convert XERRWV calls to XERMSG calls. (RWC)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE DPOFS\nC\n INTEGER LDA,N,ITASK,IND,INFO\n DOUBLE PRECISION A(LDA,*),V(*),WORK(*),D1MACH\n DOUBLE PRECISION RCOND\n CHARACTER*8 XERN1, XERN2\nC***FIRST EXECUTABLE STATEMENT DPOFS\n IF (LDA.LT.N) THEN\n IND = -1\n WRITE (XERN1, '(I8)') LDA\n WRITE (XERN2, '(I8)') N\n CALL XERMSG ('SLATEC', 'DPOFS', 'LDA = ' // XERN1 //\n * ' IS LESS THAN N = ' // XERN2, -1, 1)\n RETURN\n ENDIF\nC\n IF (N.LE.0) THEN\n IND = -2\n WRITE (XERN1, '(I8)') N\n CALL XERMSG ('SLATEC', 'DPOFS', 'N = ' // XERN1 //\n * ' IS LESS THAN 1', -2, 1)\n RETURN\n ENDIF\nC\n IF (ITASK.LT.1) THEN\n IND = -3\n WRITE (XERN1, '(I8)') ITASK\n CALL XERMSG ('SLATEC', 'DPOFS', 'ITASK = ' // XERN1 //\n * ' IS LESS THAN 1', -3, 1)\n RETURN\n ENDIF\nC\n IF (ITASK.EQ.1) THEN\nC\nC FACTOR MATRIX A INTO R\nC\n CALL DPOCO(A,LDA,N,RCOND,WORK,INFO)\nC\nC CHECK FOR POSITIVE DEFINITE MATRIX\nC\n IF (INFO.NE.0) THEN\n IND = -4\n CALL XERMSG ('SLATEC', 'DPOFS',\n * 'SINGULAR OR NOT POSITIVE DEFINITE - NO SOLUTION', -4, 1)\n RETURN\n ENDIF\nC\nC COMPUTE IND (ESTIMATE OF NO. OF SIGNIFICANT DIGITS)\nC AND CHECK FOR IND GREATER THAN ZERO\nC\n IND = -LOG10(D1MACH(4)/RCOND)\n IF (IND.EQ.0) THEN\n IND = -10\n CALL XERMSG ('SLATEC', 'DPOFS',\n * 'SOLUTION MAY HAVE NO SIGNIFICANCE', -10, 0)\n ENDIF\n ENDIF\nC\nC SOLVE AFTER FACTORING\nC\n CALL DPOSL(A,LDA,N,V)\n RETURN\n END\n", "meta": {"hexsha": "d5234c8c22ef52e7cd2acd8ad758ea799db44378", "size": 6505, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/dpofs.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/dpofs.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/dpofs.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.4242424242, "max_line_length": 72, "alphanum_fraction": 0.6035357417, "num_tokens": 1889, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206791658465, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6808734426412968}} {"text": " program main\n implicit none\n\n call runge_kutta_nystrom(0.01d0, 10000, 0.0d0)\n end\n\n subroutine runge_kutta_nystrom(h, N, x0)\n implicit none\n real*8 h, x0\n real*8 k1, k2, k3, k4, K, L\n real*8 x, y, yd, f\n real*8 i, hon2\n integer N\n\n hon2 = h/2.0d0\n x = x0\n y = 0.0d0\n yd = 1.0d0\n\n do i = 0, N-1, +1\n k1 = hon2*f(x, y, yd)\n\n K = hon2*(yd + k1/2.0d0)\n k2 = hon2*f(x + hon2, y + K, yd + k1)\n\n k3 = hon2*f(x + hon2, y + K, yd + k2)\n\n L = h*(yd + k3)\n k4 = hon2*f(x + h, y + L, yd + 2.0d0*k3)\n\n x = x + h\n y = y + h*(yd + (k1 + k2 + k3)/3.0d0 )\n\n yd = yd + (k1 + 2.0d0*k2 + 2.0d0*k3 + k4)/3.0d0\n\n write(*,*)x, y\n end do\n \n end\n\n double precision function f(x, y, yd)\n implicit none\n real*8 f2, f3\n real*8 x, y, yd\n\n f = (f2(x,y,yd)/f3(x,y,yd))**2.0d0\n return\n end\n\n double precision function f1(x, y, yd)\n implicit none\n real*8 x, y, yd\n\n f1 = (-3.0d0/(x + 1))*yd\n return\n end\n\n double precision function f2(x, y, yd)\n implicit none\n real*8 x, y, yd\n\n f2 = ((-7.0d0/2.0d0)*(x+1)*yd-3.0d0*y/2.0d0)/((x+1)**2.0d0)\n return\n end\n\n double precision function f3(x, y, yd)\n implicit none\n real*8 x, y, yd\n\n f3 = ((-7.0d0/2.0d0)*(x+1)*yd)/((x+1)**2.0d0)\n return\n end\n\n", "meta": {"hexsha": "ec3d14193e1f946942053c7391b0aeed9df43f45", "size": 1733, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/lense.f", "max_stars_repo_name": "mikepsn/gravitational-lensing", "max_stars_repo_head_hexsha": "6273de4880fcc1a4a065a90857a94620ab21c186", "max_stars_repo_licenses": ["MIT"], "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/lense.f", "max_issues_repo_name": "mikepsn/gravitational-lensing", "max_issues_repo_head_hexsha": "6273de4880fcc1a4a065a90857a94620ab21c186", "max_issues_repo_licenses": ["MIT"], "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/lense.f", "max_forks_repo_name": "mikepsn/gravitational-lensing", "max_forks_repo_head_hexsha": "6273de4880fcc1a4a065a90857a94620ab21c186", "max_forks_repo_licenses": ["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.4189189189, "max_line_length": 71, "alphanum_fraction": 0.3756491633, "num_tokens": 635, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.90192067652954, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6808734406511094}} {"text": "SUBROUTINE interp_bilinear(di,dj,var,velp)\n !== give 4 corner points of a square, interpolate point values inside\n !== di is the distance of the particle to the left face\n !== dj is the distance of the particle to the southern face\n\n IMPLICIT NONE\n REAL*8, INTENT(in) :: di,dj\n REAL*4, INTENT(in), DIMENSION( 2, 2 ) :: var\n REAL*8, INTENT(out) :: velp\n REAL*8 :: i1,i4\n\n ! calcuate the bilinear interpolation\n i1 = (var(2,1) - var(1,1))*di + var(1,1)\n i4 = (var(2,2) - var(1,2))*di + var(1,2)\n velp = (i4 - i1)*dj + i1\n\nEND SUBROUTINE interp_bilinear\n", "meta": {"hexsha": "751c20d9c7ec2ce3578c3ff612d2a07d7c9f5a9b", "size": 587, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/interp_bilinear.f90", "max_stars_repo_name": "jinbow/Octupus", "max_stars_repo_head_hexsha": "ea753c0ff46e8557182f32e0fdfef2146b06cf7b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2015-08-31T19:11:10.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-13T21:14:58.000Z", "max_issues_repo_path": "src/interp_bilinear.f90", "max_issues_repo_name": "jinbow/Octupus", "max_issues_repo_head_hexsha": "ea753c0ff46e8557182f32e0fdfef2146b06cf7b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2016-08-01T20:44:17.000Z", "max_issues_repo_issues_event_max_datetime": "2016-08-17T00:08:59.000Z", "max_forks_repo_path": "src/interp_bilinear.f90", "max_forks_repo_name": "jinbow/Octupus", "max_forks_repo_head_hexsha": "ea753c0ff46e8557182f32e0fdfef2146b06cf7b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2016-01-10T12:54:21.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-11T19:21:30.000Z", "avg_line_length": 32.6111111111, "max_line_length": 73, "alphanum_fraction": 0.6286201022, "num_tokens": 206, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206765295399, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6808734307047706}} {"text": "C voronoi_center and routines using voronoi center\n\n subroutine voronoi_center (\n 1 pts11,pts12,pts13,\n 2 pts21,pts22,pts23,\n 3 pts31,pts32,pts33,\n 4 pts41,pts42,pts43,\n 5 center1, center2, center3, radius )\nc\nc This code takes pts as input and outputs the\nc Voronoi point of the tetrahedra formed by the 4 pts.\nc This is the translation to Fortran of the C code of \nc Mike Murphy called compute_center.\nC\nC CHANGE HISTORY -\nC\nC $Log: voronoi_center.f,v $\nC Revision 2.00 2007/11/09 20:04:06 spchu\nC Import to CVS\nC\nCPVCS \nCPVCS Rev 1.1 08 Feb 2006 14:38:08 dcg\nCPVCS \"enforce lower case - add external statements for shift routines\nCPVCS these changes needed to compile with absoft pro fortran\"\nCPVCS \nCPVCS Rev 1.0 Thu Jun 19 17:33:08 1997 gable\nCPVCS Initial revision.\nc\n implicit none\n \n real*8 A(3,3)\n real*8 B(3)\n real*8 f11,f12,f13,f21,f22,f23,f31,f32,f33\n real*8 pts11,pts12,pts13,pts21,pts22,pts23,\n x pts31,pts32,pts33,pts41,pts42,pts43,\n x center1, center2, center3, radius\n real*8 deta,detai\n real*8 det3\n det3(f11,f12,f13,f21,f22,f23,f31,f32,f33) =\n 1 ((f31*((f12*f23)-(f22*f13)))-\n 2 (f32*((f11*f23)-(f13*f21)))+\n 3 (f33*((f11*f22)-(f21*f12))))\n \n A(1,1) = pts41 - pts11\n A(1,2) = pts42 - pts12\n A(1,3) = pts43 - pts13\n\n A(2,1) = pts41 - pts21\n A(2,2) = pts42 - pts22\n A(2,3) = pts43 - pts23\n\n A(3,1) = pts41 - pts31\n A(3,2) = pts42 - pts32\n A(3,3) = pts43 - pts33\n \n B(1) = 0.5d0*(A(1,1)*(pts11+pts41)+\n 1 A(1,2)*(pts12+pts42)+\n 2 A(1,3)*(pts13+pts43))\n\n\n B(2) = 0.5d0*(A(2,1)*(pts21+pts41)+\n 1 A(2,2)*(pts22+pts42)+\n 2 A(2,3)*(pts23+pts43))\n\n\n B(3) = 0.5d0*(A(3,1)*(pts31+pts41)+\n 1 A(3,2)*(pts32+pts42)+\n 2 A(3,3)*(pts33+pts43))\n \n deta = det3(A(1,1),A(1,2),A(1,3),\n 1 A(2,1),A(2,2),A(2,3), \n 2 A(3,1),A(3,2),A(3,3))\n \n detai = 1.0d0/(deta + 1.e-30)\n \n center1 = det3(B(1),A(1,2),A(1,3),\n 1 B(2),A(2,2),A(2,3), \n 2 B(3),A(3,2),A(3,3))*detai\n\n center2 = det3(A(1,1),B(1),A(1,3),\n 1 A(2,1),B(2),A(2,3), \n 2 A(3,1),B(3),A(3,3))*detai\n\n center3 = det3(A(1,1),A(1,2),B(1),\n 1 A(2,1),A(2,2),B(2),\n 2 A(3,1),A(3,2),B(3))*detai\n\n\n radius = sqrt((center1-pts11)**2 +\n 1 (center2-pts12)**2 +\n 2 (center3-pts13)**2 )\n return\n end\n\nC####################\n\n subroutine voronoi_vector_area (\n 1 x1,y1,z1,\n 1 x2,y2,z2,\n 1 x3,y3,z3,\n 5 xarea, yarea, zarea )\nc\nc This code takes 3 pts of triangle as input \nc and outputs the Voronoi area associated with first point \nc which is the sum of 2 triangles formed with \nc point 1, edge midpoints, voronoi center point\nc\nc note convention has faces pointing inward\n\n implicit none\n \n real*8 x1,y1,z1,x2,y2,z2,x3,y3,z3,xarea,yarea,zarea \n real*8 xvor,yvor,zvor,xm,ym,zm,ax1,ay1,az1,ax2,ay2,az2\n\n xarea=0.0d+00\n yarea=0.0d+00\n zarea=0.0d+00\n\n call voronoi_center_2d(x1,y1,z1,x2,y2,z2,x3,y3,z3,\n * xvor,yvor,zvor)\n\nC area of right side triangle first (pt,midpt,vorpt)\n xm=(x2+x1)*0.5d+00\n ym=(y2+y1)*0.5d+00\n zm=(z2+z1)*0.5d+00\n\n ax1= 0.5d+00*((y1-ym)*(zvor-zm)-(yvor-ym)*(z1-zm))\n ay1= -0.5d+00*((x1-xm)*(zvor-zm)-(xvor-xm)*(z1-zm))\n az1= 0.5d+00*((x1-xm)*(yvor-ym)-(xvor-xm)*(y1-ym))\n\nC area of left side triangle (pt,vorpt,midpt)\n xm=(x3+x1)*0.5d+00\n ym=(y3+y1)*0.5d+00\n zm=(z3+z1)*0.5d+00\n\n ax2= 0.5d+00*((y1-yvor)*(zm-zvor)-(ym-yvor)*(z1-zvor))\n ay2= -0.5d+00*((x1-xvor)*(zm-zvor)-(xm-xvor)*(z1-zvor))\n az2= 0.5d+00*((x1-xvor)*(ym-yvor)-(xm-xvor)*(y1-yvor))\n\n xarea = ax1 + ax2\n yarea = ay1 + ay2\n zarea = az1 + az2\n\nc print*,\"area 1: \",ax1,ay1,az1\nc print*,\"area 2: \",ax2,ay2,az2\nc print*,\"area sum: \",xarea,yarea,zarea\n\n return\n end\n", "meta": {"hexsha": "aebb98e278394c41770e104e749aeedb6c61ec14", "size": 4450, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/voronoi_center.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/voronoi_center.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/voronoi_center.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.6666666667, "max_line_length": 74, "alphanum_fraction": 0.4982022472, "num_tokens": 1815, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475730993027, "lm_q2_score": 0.7217432003123989, "lm_q1q2_score": 0.6808546964156255}} {"text": "! vim: set ft=fortran sw=4 ts=4 :\n\nprogram stock_volatility\n\n use mod_arrays, only: reverse, average, std, moving_average, moving_std\n use mod_io, only: read_stock, write_stock\n\n implicit none\n\n character(len=4), allocatable :: symbols(:)\n character(len=:), allocatable :: time(:)\n real, allocatable :: open(:), high(:), low(:),&\n close(:), adjclose(:), volume(:)\n real, allocatable :: mvavg(:), mvstd(:)\n integer :: n, im\n real :: gain, mean, stddev\n\n symbols = ['AAPL', 'AMZN', 'CRAY', 'CSCO', 'HPQ ',&\n 'IBM ', 'INTC', 'MSFT', 'NVDA', 'ORCL']\n\n do n = 1, size(symbols)\n call read_stock('data/' // trim(symbols(n)) // '.csv', time,&\n open, high, low, close, adjclose, volume)\n\n im = size(time)\n\n adjclose = reverse(adjclose)\n time = time(size(time):1:-1)\n\n gain = (adjclose(size(adjclose)) - adjclose(1))\n mean = average(adjclose)\n stddev = std(adjclose)\n\n mvavg = moving_average(adjclose, 30)\n mvstd = moving_std(adjclose, 30)\n\n if (n == 1) then\n print *, time(size(time)) // ' through ' // time(1)\n print *, 'Symbol, Gain (USD), Relative gain (%), Mean (USD), Standard deviation (USD)'\n print *, '---------------------------------------------------------------------------'\n end if\n print *, symbols(n), gain, nint(gain / adjclose(1) * 100), mean, stddev\n\n call write_stock('results/' // trim(symbols(n)) // '_volatility',&\n time, adjclose, mvavg, mvstd)\n end do\nend program stock_volatility\n\n\n", "meta": {"hexsha": "b7ba87e795abbde01ffa3d7d802097232013d8d0", "size": 1606, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran/ModernFortran/stock-prices/stock_volatility.f90", "max_stars_repo_name": "kkirstein/proglang-playground", "max_stars_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Fortran/ModernFortran/stock-prices/stock_volatility.f90", "max_issues_repo_name": "kkirstein/proglang-playground", "max_issues_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran/ModernFortran/stock-prices/stock_volatility.f90", "max_forks_repo_name": "kkirstein/proglang-playground", "max_forks_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.12, "max_line_length": 100, "alphanum_fraction": 0.5317559153, "num_tokens": 431, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096181702031, "lm_q2_score": 0.743168019989179, "lm_q1q2_score": 0.6808233710285927}} {"text": "! ======================================================================\n! NAME\n!\n! FTPSD\n!\n! DESCRIPTION\n!\n! FTPSD is a supporting program of GPECN1DTDPBC that uses the \n! Fourier-Transform Phase Shift Determination algorithm* to compute \n! the phase shift observed in the probability densities generated by\n! interferometry-related simulations.\n!\n! * Goldberg, K. A. and Bokor, J., \"Fourier-Transform Method of \n! Phase-Shift Determination\", Applied Optics, 40 (17): 2886-2894 \n! (2001).\n!\n! AUTHOR\n!\n! Marty Kandes, Ph.D.\n! Computational & Data Science Research Specialist\n! User Services Group\n! San Diego Supercomputer Center\n! University of California, San Diego\n!\n! COPYRIGHT\n! \n! Copyright (c) 2010, 2011, 2017 Martin Charles Kandes\n!\n! COPYRIGHT\n! \n! Copyright (c) 2010 - 2021 Martin Charles Kandes\n!\n! LICENSE\n!\n! The MIT License (MIT)\n!\n! LAST UPDATED\n!\n! Friday, March 31st, 2017 \n!\n! ----------------------------------------------------------------------\n PROGRAM FTPSD\n IMPLICIT NONE\n\n! Parameter Declarations:\n! -----------------------\n REAL, PARAMETER :: PI = 3.1415926535897932384626433832795028841971E0\n\n! Input Variable and Array Declarations:\n! --------------------------------------\n INTEGER :: NUMBER_OF_GRID_POINTS\n INTEGER :: NUMBER_OF_TIME_STEPS_BEFORE_WRITE\n INTEGER :: START_FILE\n INTEGER :: END_FILE\n\n REAL :: RADIUS\n REAL :: GAMMA_FACTOR\n REAL :: CARRIER_FREQUENCY\n\n! Internal Variable and Array Declarations:\n! -----------------------------------------\n CHARACTER(80) :: BUFFER\n\n INTEGER :: CURRENT_GRID_POINT\n INTEGER :: CURRENT_FILE\n INTEGER :: LENGTH\n INTEGER :: INFO\n\n REAL :: ANGULAR_GRID_SPACING_SIZE\n REAL :: TIME_STEP_SIZE\n\n COMPLEX :: FOURIER_TRANSFORM\n\n COMPLEX, ALLOCATABLE, DIMENSION(:) :: WAVEFUNCTION\n\n! Input Variable Assignment Read from Command-line Arguments:\n! -----------------------------------------------------------\n CALL GET_COMMAND_ARGUMENT(1,BUFFER,LENGTH,INFO)\n READ(BUFFER,*) NUMBER_OF_GRID_POINTS\n\n CALL GET_COMMAND_ARGUMENT(2,BUFFER,LENGTH,INFO)\n READ(BUFFER,*) NUMBER_OF_TIME_STEPS_BEFORE_WRITE\n\n CALL GET_COMMAND_ARGUMENT(3,BUFFER,LENGTH,INFO)\n READ(BUFFER,*) START_FILE\n\n CALL GET_COMMAND_ARGUMENT(4,BUFFER,LENGTH,INFO)\n READ(BUFFER,*) END_FILE\n\n CALL GET_COMMAND_ARGUMENT(5,BUFFER,LENGTH,INFO)\n READ(BUFFER,*) RADIUS\n\n CALL GET_COMMAND_ARGUMENT(6,BUFFER,LENGTH,INFO)\n READ(BUFFER,*) GAMMA_FACTOR\n\n CALL GET_COMMAND_ARGUMENT(7,BUFFER,LENGTH,INFO)\n READ(BUFFER,*) CARRIER_FREQUENCY\n\n WRITE(6,*) NUMBER_OF_GRID_POINTS\n WRITE(6,*) NUMBER_OF_TIME_STEPS_BEFORE_WRITE\n WRITE(6,*) START_FILE\n WRITE(6,*) END_FILE\n WRITE(6,*) RADIUS\n WRITE(6,*) GAMMA_FACTOR\n WRITE(6,*) CARRIER_FREQUENCY\n\n\n! Internal Variable Assignment:\n! -----------------------------\n ANGULAR_GRID_SPACING_SIZE = 2.0E0*PI/FLOAT(NUMBER_OF_GRID_POINTS)\n TIME_STEP_SIZE = ((RADIUS*ANGULAR_GRID_SPACING_SIZE)**2/(2.0E0*GAMMA_FACTOR))*FLOAT(NUMBER_OF_TIME_STEPS_BEFORE_WRITE)\n\n! Allocate Arrays:\n! ----------------\n ALLOCATE(WAVEFUNCTION(NUMBER_OF_GRID_POINTS))\n\n! Main Program:\n! -------------\n DO CURRENT_FILE = START_FILE, END_FILE\n OPEN(UNIT=CURRENT_FILE,ACTION='READ',FORM='UNFORMATTED')\n READ(UNIT=CURRENT_FILE) WAVEFUNCTION\n CLOSE(UNIT=CURRENT_FILE)\n FOURIER_TRANSFORM = CMPLX(0.0E0,0.0E0)\n DO CURRENT_GRID_POINT = 1, NUMBER_OF_GRID_POINTS\n FOURIER_TRANSFORM = FOURIER_TRANSFORM+CMPLX(ABS(WAVEFUNCTION(CURRENT_GRID_POINT))**2*ANGULAR_GRID_SPACING_SIZE,0.0E0)*EXP(CMPLX(0.0E0,-CARRIER_FREQUENCY*FLOAT(CURRENT_GRID_POINT-1)*ANGULAR_GRID_SPACING_SIZE))\n ENDDO\n WRITE(500,900) FLOAT(CURRENT_FILE-START_FILE)*TIME_STEP_SIZE, ATAN2(AIMAG(FOURIER_TRANSFORM),REAL(FOURIER_TRANSFORM)), REAL(FOURIER_TRANSFORM), AIMAG(FOURIER_TRANSFORM)\n ENDDO\n\n! Format Statements:\n! ------------------\n900 FORMAT(1X,4(F23.15))\n\n! Deallocate Arrays:\n! ------------------\n DEALLOCATE(WAVEFUNCTION)\n\n\n STOP\n ENDPROGRAM FTPSD\n! ======================================================================\n", "meta": {"hexsha": "83cb61434a185bc45e472deed28d9c74eb185959", "size": 4393, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/ftpsd.f", "max_stars_repo_name": "mkandes/gpecn1Dtdpbc", "max_stars_repo_head_hexsha": "51646d6804fcd6abfbac154c58d9e5739d795c6b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source/ftpsd.f", "max_issues_repo_name": "mkandes/gpecn1Dtdpbc", "max_issues_repo_head_hexsha": "51646d6804fcd6abfbac154c58d9e5739d795c6b", "max_issues_repo_licenses": ["MIT"], "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/ftpsd.f", "max_forks_repo_name": "mkandes/gpecn1Dtdpbc", "max_forks_repo_head_hexsha": "51646d6804fcd6abfbac154c58d9e5739d795c6b", "max_forks_repo_licenses": ["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.9366197183, "max_line_length": 220, "alphanum_fraction": 0.6027771455, "num_tokens": 1088, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096135894201, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6808233624131501}} {"text": " real*8 function expint(x, n)\n INTEGER n, MAXIT\n REAL*8 x, EPS, FPMIN, EULER\n PARAMETER (MAXIT=100,EPS=1.e-7,FPMIN=1.e-30,EULER=.5772156649)\n\n INTEGER i, ii, nm1\n REAL a, b, c, d, del, fact, h, psi\n nm1=n-1\n if(n.lt.0.or.x.lt.0..or.(x.eq.0..and.(n.eq.0.or.n.eq.1)))then\n write(*,*) 'bad arguments in expint', n, x\n else if(n.eq.0)then ! Special Case\n expint=exp(-x)/x\n else if(x.eq.0.)then ! Another special case\n expint=1./nm1\n else if(x.gt.1.) then ! Lentz's algorithm\n b=x+n\n c=1./FPMIN\n d=1./b\n h=d\n do i=1,MAXIT\n a=-1*(nm1+1)\n b=b+2\n d=1./(a*d+b)\n c=b+a/c\n del=c*d\n h=h*del\n if(abs(del-1.).lt.EPS)then\n expint=h*exp(-x)\n return\n endif\n enddo\n write(*,*) 'Continued Fraction failed in expint'\n else\n if(nm1.ne.0)then\n expint=1./nm1\n else\n expint=-log(x)-EULER\n endif\n fact=1.\n do i=1,MAXIT\n fact=-fact*x/i\n if(i.ne.nm1)then\n del=-fact/(i-nm1)\n else\n psi=-EULER\n do ii=1,nm1\n psi=psi+1./ii\n enddo\n endif\n expint=expint+del\n if(abs(del).lt.abs(expint)*EPS) return\n enddo\n write(*,*) 'series failed in expint'\n endif\n return\n END\n", "meta": {"hexsha": "b4b21c7b8e8b366a10accc928b420ef7ab7fb275", "size": 1620, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "MoogSource/Fexpint.f", "max_stars_repo_name": "soylentdeen/MoogPy", "max_stars_repo_head_hexsha": "9485a7e302ef4d4339013f27672d1d5e7059a41f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2015-08-21T17:18:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-03T15:55:35.000Z", "max_issues_repo_path": "MoogSource/Fexpint.f", "max_issues_repo_name": "soylentdeen/MoogPy", "max_issues_repo_head_hexsha": "9485a7e302ef4d4339013f27672d1d5e7059a41f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MoogSource/Fexpint.f", "max_forks_repo_name": "soylentdeen/MoogPy", "max_forks_repo_head_hexsha": "9485a7e302ef4d4339013f27672d1d5e7059a41f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2016-03-28T09:39:44.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-20T07:47:39.000Z", "avg_line_length": 28.4210526316, "max_line_length": 68, "alphanum_fraction": 0.4086419753, "num_tokens": 495, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096204605946, "lm_q2_score": 0.7431680086124812, "lm_q1q2_score": 0.6808233623084361}} {"text": " subroutine mapc2m_cubedsphere(blockno,xc,yc,xp,yp,zp)\n implicit none\n\n double precision xc,yc,xp,yp,zp\n integer blockno\n\n if (blockno .eq. 0) then\n call csphere_basic(xc,yc,yp,xp,zp)\n zp = -zp\n elseif (blockno .eq. 1) then\n call csphere_basic(xc,yc,zp,xp,yp)\n elseif (blockno .eq. 2) then\n call csphere_basic(xc,yc,zp,yp,xp)\n xp = -xp\n elseif (blockno .eq. 3) then\n call csphere_basic(xc,yc,xp,yp,zp)\n elseif (blockno .eq. 4) then\n call csphere_basic(xc,yc,xp,zp,yp)\n yp = -yp\n elseif (blockno .eq. 5) then\n call csphere_basic(xc,yc,yp,zp,xp)\n endif\n\n end\n\n subroutine csphere_basic(xc,yc,xp,yp,zp)\n implicit none\n\n double precision xc,yc,xp,yp,zp\n double precision R, tan_xi, tan_eta\n\n \n double precision pi, pi2\n common /compi/ pi, pi2\n\n R = 1.d0\n tan_xi = tan(0.5d0*pi*(xc-0.5d0))\n tan_eta = tan(0.5d0*pi*(yc-0.5d0))\n zp = R/sqrt(tan_xi**2 + tan_eta**2 + 1.d0)\n xp = zp*tan_xi\n yp = zp*tan_eta\n\n end\n", "meta": {"hexsha": "1eda24a1a34670adc07f0ed4bb8a843a1e0b76ac", "size": 1106, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/mappings/cubedsphere/mapc2m_cubedsphere.f", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/mappings/cubedsphere/mapc2m_cubedsphere.f", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-08-02T09:52:43.000Z", "max_issues_repo_issues_event_max_datetime": "2017-08-02T14:16:23.000Z", "max_forks_repo_path": "src/mappings/cubedsphere/mapc2m_cubedsphere.f", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "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.1363636364, "max_line_length": 59, "alphanum_fraction": 0.5650994575, "num_tokens": 406, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096181702032, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6808233606062903}} {"text": "!=================================================\n! SUBROUTINES\n!\tSTTRANS\n!\n!=================================================\n\nmodule mod_sttrans\n\n\timplicit none\n\ncontains\n!==========\nsubroutine STTRANS\n\n\tuse prm_var\n\n\timplicit none\n\n\treal(8) :: rh, rd\n\n\tprint 600, aphi, adlt\n\t 600 FORMAT(' ','SOURCE GEOMETRY (PHI,DELT)=',2(F6.2,1X))\n\n\trh = aphi * pi/180.d0\n\trd = adlt * pi/180.d0\n\n\tt11 = dcos(rh)\n\tt12 = dsin(rh)\n\tu11 = dcos(rd)\n\tu12 = dsin(rd)\n\nreturn\nend subroutine STTRANS\n\nend module mod_sttrans\n", "meta": {"hexsha": "a9faa8912019b42059772d25d2f719db923f055d", "size": 505, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fort/m_sttrans.f90", "max_stars_repo_name": "s-watanabe-jhod/YM1992", "max_stars_repo_head_hexsha": "85793cba6a81aeded1569dd0c61566e4c934e050", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fort/m_sttrans.f90", "max_issues_repo_name": "s-watanabe-jhod/YM1992", "max_issues_repo_head_hexsha": "85793cba6a81aeded1569dd0c61566e4c934e050", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fort/m_sttrans.f90", "max_forks_repo_name": "s-watanabe-jhod/YM1992", "max_forks_repo_head_hexsha": "85793cba6a81aeded1569dd0c61566e4c934e050", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-08-27T07:38:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-27T07:38:59.000Z", "avg_line_length": 14.0277777778, "max_line_length": 58, "alphanum_fraction": 0.5207920792, "num_tokens": 153, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9124361700013356, "lm_q2_score": 0.7461390043208003, "lm_q1q2_score": 0.6808042153910809}} {"text": " subroutine insolation(calday, dgr_lat, dgr_lon, scon, radius, daysperyear, zen, solin)\nc\nc Returns instantaneous insolation and zenith angle at specified time, lat and lon\nc\n\nc In\n real calday ! Calendar day, including fraction\n real dgr_lat ! Current centered latitude (degrees)\n real dgr_lon ! Current centered longitude (degrees)\n real scon ! Solar constant (W m-2)\n real radius ! Mean orbital radius (au)\n real daysperyear ! No. days in a year\nc Out\n real zen ! Solar zenith angle (degrees)\n real solin ! Insolation (W m-2)\nc Local\n real delta ! Solar declination angle in radians\n real eccf ! Earth orbit eccentricity factor\n real coszrs ! Cosine of zenith angle\n \nc Get declination angle and eccen factor\n call eccf_decl(calday, daysperyear, delta, eccf)\n\nc get zenith angle\n call zenith(calday, dgr_lat, dgr_lon, delta, zen, coszrs)\n\n if (zen .lt. 0. .or. zen .gt. 90.) then\n solin = 0.\n else\n solin = scon*eccf*coszrs/radius/radius\n endif\n\n end\nc===============================================================================\n subroutine daily_avg_insolation(calday, dgr_lat, scon, radius, daysperyear, zen, solin)\nc\nc Returns daily-mean insolation and zenith angle at specified day and lat\nc\nc In\n real calday ! Calendar day, including fraction\n real dgr_lat ! Current centered latitude (degrees)\n real scon ! Solar constant (W m-2)\n real radius ! Mean orbital radius (au)\n real daysperyear ! No. days in a year\nc Out\n real zen ! Solar zenith angle (degrees)\n real solin ! Insolation (W m-2)\nc Local\n real delta ! Solar declination angle in radians\n real eccf ! Earth orbit eccentricity factor\n real coszrs ! Cosine of zenith angle\n \nc Get declination angle and eccen factor\n calday1 = int(calday) + 0.5 ! compute at noon \n call eccf_decl(calday1, daysperyear, delta, eccf)\n\nc Daily-avg zenith angle and insolation\n pi = abs(acos(-1.))\n deg2rad = pi/180.\n phi = dgr_lat*deg2rad\nc handle points poleward of polar circle\n polar_circle = pi/2. - abs(delta) \n if ( abs(phi) .ge. polar_circle ) then\nc summer hemisph (permanent day)\n if (phi*delta .gt. 0.) h0 = pi\nc winter hemisph (permanent night)\n if (phi*delta .lt. 0.) h0 = 0.\n else\n h0 = acos( -tan(phi)*tan(delta) )\n endif\n coszrs = ( h0*sin(phi)*sin(delta) + cos(phi)*cos(delta)*sin(h0) )/pi\n zen = acos(coszrs)/deg2rad\n solin = scon*eccf*coszrs/radius/radius\n\n end\nc===============================================================================\n subroutine annual_avg_insolation(dgr_lat, scon, radius, daysperyear, zen, solin)\nc\nc Returns annual-mean insolation and zenith angle at specified lat\nc\nc In\n real dgr_lat ! Current centered latitude (degrees)\n real scon ! Solar constant (W m-2)\n real radius ! Mean orbital radius (au)\n real daysperyear ! No. days in a year\nc Out\n real zen ! Solar zenith angle (degrees)\n real solin ! Insolation (W m-2)\n\n\nc Do it the brute-force way by averaging daily insolation\n zen_avg = 0.\n zen_count = 0.\n solin_avg = 0.\n do i = 1,int(daysperyear)\n calday = float(i) \n call daily_avg_insolation(calday, dgr_lat, scon, radius, daysperyear, zen, solin)\n solin_avg = solin_avg + solin\nc average zen only when sun is up\n if (solin .gt. 0.) then\n zen_avg = zen_avg + zen\n zen_count = zen_count + 1.\n endif\n enddo\n\n solin = solin_avg / int(daysperyear)\n zen = zen_avg / zen_count\n\n end\n", "meta": {"hexsha": "4ad46f29707d0a3c3d9296a1460b7dfd257a8e3a", "size": 3866, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/radiation/insolation/src/insolation_routines.f", "max_stars_repo_name": "CliMT/climt-legacy", "max_stars_repo_head_hexsha": "adbd4fe77426c90deb8d2c046a2f3dc3b72df89e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/radiation/insolation/src/insolation_routines.f", "max_issues_repo_name": "CliMT/climt-legacy", "max_issues_repo_head_hexsha": "adbd4fe77426c90deb8d2c046a2f3dc3b72df89e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/radiation/insolation/src/insolation_routines.f", "max_forks_repo_name": "CliMT/climt-legacy", "max_forks_repo_head_hexsha": "adbd4fe77426c90deb8d2c046a2f3dc3b72df89e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.1454545455, "max_line_length": 93, "alphanum_fraction": 0.5918261769, "num_tokens": 1051, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.912436167620237, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6808042084637259}} {"text": "program Factors\n implicit none\n integer :: i, number\n\n write(*,*) \"Enter a number between 1 and 2147483647\"\n read*, number\n\n do i = 1, int(sqrt(real(number))) - 1\n if (mod(number, i) == 0) write (*,*) i, number/i\n end do\n\n ! Check to see if number is a square\n i = int(sqrt(real(number)))\n if (i*i == number) then\n write (*,*) i\n else if (mod(number, i) == 0) then\n write (*,*) i, number/i\n end if\n\nend program\n", "meta": {"hexsha": "333765e87c5ffbb2ff9fd313553df779543026b2", "size": 433, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Factors-of-an-integer/Fortran/factors-of-an-integer.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/Factors-of-an-integer/Fortran/factors-of-an-integer.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/Factors-of-an-integer/Fortran/factors-of-an-integer.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 20.619047619, "max_line_length": 54, "alphanum_fraction": 0.5889145497, "num_tokens": 147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147438, "lm_q2_score": 0.7461390043208003, "lm_q1q2_score": 0.6808042047312977}} {"text": " SUBROUTINE AVEVAR(DATA,N,AVE,VAR)\n DIMENSION DATA(N)\n AVE=0.0\n VAR=0.0\n DO 11 J=1,N\n AVE=AVE+DATA(J)\n11 CONTINUE\n AVE=AVE/N\n DO 12 J=1,N\n S=DATA(J)-AVE\n VAR=VAR+S*S\n12 CONTINUE\n VAR=VAR/(N-1)\n RETURN\n END\n", "meta": {"hexsha": "cd92f30c37f14e311fec259add93526c1e875f76", "size": 283, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "Math3/NumRec/source/avevar.for", "max_stars_repo_name": "domijin/MM3", "max_stars_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Math3/NumRec/source/avevar.for", "max_issues_repo_name": "domijin/MM3", "max_issues_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Math3/NumRec/source/avevar.for", "max_forks_repo_name": "domijin/MM3", "max_forks_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.6875, "max_line_length": 39, "alphanum_fraction": 0.4840989399, "num_tokens": 109, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361652391385, "lm_q2_score": 0.7461389873857265, "lm_q1q2_score": 0.6808041963856463}} {"text": "Function fdpiel(s)\n Parameter (srt0=2.012)\n If (s<=srt0**2) Then\n fdpiel = 0.\n Else\n fdpiel = 63.*exp(-(s-4.67)**2/0.15) + 15.*exp(-(s-6.25)**2/0.3)\n End If\n Return\nEnd Function fdpiel\n", "meta": {"hexsha": "977302c325fce24fb8da910d6fff109187f6c58d", "size": 196, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fdpiel.f90", "max_stars_repo_name": "xiaohaijin/AMPT", "max_stars_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-12-24T19:37:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-14T12:58:59.000Z", "max_issues_repo_path": "src/fdpiel.f90", "max_issues_repo_name": "xiaohaijin/AMPT", "max_issues_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_issues_repo_licenses": ["MIT"], "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/fdpiel.f90", "max_forks_repo_name": "xiaohaijin/AMPT", "max_forks_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_forks_repo_licenses": ["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.6, "max_line_length": 67, "alphanum_fraction": 0.5816326531, "num_tokens": 90, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810436809829, "lm_q2_score": 0.7185943925708562, "lm_q1q2_score": 0.6807827056170797}} {"text": " program dsm_test\n\n !! This is a test program for subroutines [[dsm]] and [[fdjs]].\n !! the test data represents a neutron kinetics problem.\n !!\n !!### Reference\n !! * Argonne National Laboratory. MINPACK Project. July 1983.\n !! Thomas F. Coleman, Burton S. Garbow, Jorge J. More\n !! * Thomas F. Coleman, Burton S. Garbow, Jorge J. More, \"Algorithm 618:\n !! FORTRAN subroutines for estimating sparse Jacobian Matrices\",\n !! ACM Transactions on Mathematical Software (TOMS),\n !! Volume 10 Issue 3, Sept. 1984, Pages 346-347\n\n use dsm_module\n use iso_fortran_env, only: output_unit,wp => real64\n\n implicit none\n\n integer,parameter :: nwrite = output_unit !! unit for printing\n\n integer i , info , ip , j , jp , l , m , maxgrp , maxrow , &\n mingrp , minrow , n , nnz , numgrp\n integer indcol(6000) , indrow(6000) , ipntr(1201) , jpntr(1201) , &\n ngrp(1200)\n logical col\n real(wp) :: dnsm , errij , errmax , fjact , fjactr , sum\n real(wp) :: d(1200) , fjac(6000) , fjacd(1200) , fvec(1200) , x(1200) , &\n xd(1200)\n\n col = .true.\n!\n! TEST FOR DSM AND FDJS.\n!\n write (nwrite,99001)\n!\n! FORMAT STATEMENTS.\n!\n99001 format (//' TESTS FOR DSM AND FDJS - NEUTRON KINETICS PROBLEM'// &\n &' STATISTICS GENERATED '//' N - NUMBER OF COLUMNS '/&\n &' NNZ - NUMBER OF NON-ZERO ELEMENTS'/ &\n &' DNSM - MATRIX DENSITY (PERCENTAGE)'/ &\n &' MINROW - MINIMUM NUMBER OF NON-ZEROS IN ANY ROW'/ &\n &' MAXROW - MAXIMUM NUMBER OF NON-ZEROS IN ANY ROW'/ &\n &' MINGRP - LOWER BOUND ON NUMBER OF GROUPS'/ &\n &' MAXGRP - NUMBER OF GROUPS DETERMINED BY DSM'//)\n do n = 300 , 1200 , 300\n write (nwrite,99002)\n99002 format (//3x,'N',6x,'NNZ',5x,'DNSM',5x,'MINROW',4x,'MAXROW',4x,&\n &'MINGRP',4x,'MAXGRP'//)\n!\n! DEFINITION OF SPARSITY PATTERN.\n!\n m = n\n l = n/3\n nnz = 0\n do j = 1 , n\n nnz = nnz + 1\n indrow(nnz) = j\n indcol(nnz) = j\n if ( mod(j,l)/=0 ) then\n nnz = nnz + 1\n indrow(nnz) = j + 1\n indcol(nnz) = j\n endif\n if ( j<=2*l ) then\n nnz = nnz + 1\n indrow(nnz) = j + l\n indcol(nnz) = j\n if ( mod(j,l)/=1 ) then\n nnz = nnz + 1\n indrow(nnz) = j - 1\n indcol(nnz) = j\n endif\n endif\n nnz = nnz + 1\n if ( j>l ) then\n indrow(nnz) = j - l\n else\n indrow(nnz) = j + 2*l\n endif\n indcol(nnz) = j\n enddo\n!\n! CALL DSM.\n!\n call dsm(m,n,nnz,indrow,indcol,ngrp,maxgrp,mingrp,info,ipntr,jpntr)\n if ( info<=0 ) write (nwrite,99003) info\n99003 format (//' *** MISTAKE IN INPUT DATA, INFO IS ***',i6)\n!\n! STATISTICS FOR THE MATRIX.\n!\n maxrow = 0\n minrow = n\n do i = 1 , m\n maxrow = max(maxrow,ipntr(i+1)-ipntr(i))\n minrow = min(minrow,ipntr(i+1)-ipntr(i))\n enddo\n dnsm = real(100*nnz,wp)/real(m*n,wp)\n write (nwrite,99004) n , nnz , dnsm , minrow , maxrow , &\n & mingrp , maxgrp\n99004 format (2(i5,3x),f6.2,4x,4(i5,5x))\n!\n! TEST FOR FDJS.\n!\n do j = 1 , n\n x(j) = real(j,wp)/real(n,wp)\n enddo\n call fcn(n,x,indcol,ipntr,fvec)\n!\n! APPROXIMATE THE JACOBIAN MATRIX.\n!\n do numgrp = 1 , maxgrp\n do j = 1 , n\n d(j) = 0.0_wp\n if ( ngrp(j)==numgrp ) d(j) = 1.0e-6_wp !d(j) = 0.001_wp\n xd(j) = x(j) + d(j)\n enddo\n call fcn(n,xd,indcol,ipntr,fjacd)\n do i = 1 , m\n fjacd(i) = fjacd(i) - fvec(i)\n enddo\n if ( col ) then\n call fdjs(m,n,col,indrow,jpntr,ngrp,numgrp,d,fjacd,fjac)\n else\n call fdjs(m,n,col,indcol,ipntr,ngrp,numgrp,d,fjacd,fjac)\n endif\n enddo\n!\n! TEST THE APPROXIMATION TO THE JACOBIAN.\n!\n errmax = 0.0_wp\n if ( col ) then\n!\n! TEST FOR THE COLUMN-ORIENTED DEFINITION OF\n! THE SPARSITY PATTERN.\n!\n do j = 1 , n\n do jp = jpntr(j) , jpntr(j+1) - 1\n i = indrow(jp)\n sum = 0.0_wp\n do ip = ipntr(i) , ipntr(i+1) - 1\n sum = sum + x(indcol(ip))\n enddo\n sum = sum + x(i)\n fjact = 1.0_wp + 2.0_wp*sum\n if ( i==j ) fjact = 2.0_wp*fjact\n errij = fjac(jp) - fjact\n if ( fjact/=0.0_wp ) errij = errij/fjact\n errmax = max(errmax,abs(errij))\n enddo\n enddo\n else\n!\n! TEST FOR THE ROW-ORIENTED DEFINITION OF\n! THE SPARSITY PATTERN.\n!\n do i = 1 , m\n sum = 0.0_wp\n do ip = ipntr(i) , ipntr(i+1) - 1\n sum = sum + x(indcol(ip))\n enddo\n sum = sum + x(i)\n fjactr = 1.0_wp + 2.0_wp*sum\n do ip = ipntr(i) , ipntr(i+1) - 1\n j = indcol(ip)\n fjact = fjactr\n if ( i==j ) fjact = 2.0_wp*fjact\n errij = fjac(ip) - fjact\n if ( fjact/=0.0_wp ) errij = errij/fjact\n errmax = max(errmax,abs(errij))\n enddo\n enddo\n endif\n write (nwrite,99005) errmax\n99005 format (//' LARGEST RELATIVE ERROR OF APPROXIMATION IS',e10.2)\n col = .not.col\n enddo\n stop\n\n\n contains\n\n subroutine fcn(n,x,Indcol,Ipntr,Fvec)\n\n !! Function subroutine for testing [[fdjs]].\n\n implicit none\n\n integer n\n integer Indcol(*) , Ipntr(n+1)\n real(wp) ::x(n) , Fvec(n)\n\n integer i , ip\n real(wp) :: sum\n\n do i = 1 , n\n sum = 0.0_wp\n do ip = Ipntr(i) , Ipntr(i+1) - 1\n sum = sum + x(Indcol(ip))\n enddo\n sum = sum + x(i)\n Fvec(i) = sum*(1.0_wp+sum) + 1.0_wp\n enddo\n\n end subroutine fcn\n\n end program dsm_test\n", "meta": {"hexsha": "7d136a595371d06a96ecaa70c16c32cf20129049", "size": 6457, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/dsm_test.f90", "max_stars_repo_name": "sebastiandyrda/NumDiff", "max_stars_repo_head_hexsha": "76597b834b251669b052391346d2324be4f8a9eb", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 47, "max_stars_repo_stars_event_min_datetime": "2016-11-02T15:11:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-04T14:23:30.000Z", "max_issues_repo_path": "src/tests/dsm_test.f90", "max_issues_repo_name": "sebastiandyrda/NumDiff", "max_issues_repo_head_hexsha": "76597b834b251669b052391346d2324be4f8a9eb", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2018-08-27T13:10:38.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T02:04:55.000Z", "max_forks_repo_path": "src/tests/dsm_test.f90", "max_forks_repo_name": "sebastiandyrda/NumDiff", "max_forks_repo_head_hexsha": "76597b834b251669b052391346d2324be4f8a9eb", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-06-03T15:53:54.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-16T02:32:03.000Z", "avg_line_length": 31.0432692308, "max_line_length": 80, "alphanum_fraction": 0.4559392907, "num_tokens": 2054, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.875787001374006, "lm_q2_score": 0.7772998663336157, "lm_q1q2_score": 0.680749119104733}} {"text": " \nC ------------------------------------------------------------------------------\nC CONDITIONAL DISTRIBUTON: \n \n \n DOUBLE PRECISION FUNCTION DIST(Z, HH, SKEW, SHAPE, NDIST)\n IMPLICIT NONE\n INTEGER NDIST\n DOUBLE PRECISION Z, HH, SKEW, SHAPE\n DOUBLE PRECISION DNORM, DSNORM, DSTD, DSSTD, DGED, DSGED\n IF (NDIST.EQ.10) THEN\nC NORMAL:\n DIST = DNORM(Z/HH)/HH \n RETURN\n END IF \n IF (NDIST.EQ.11) THEN\nC SKEW NORMAL:\n DIST = DSNORM(Z/HH, SKEW)/HH \n RETURN\n END IF \n IF (NDIST.EQ.20) THEN\nC STUDENT-T:\n DIST = DSTD(Z/HH, SHAPE)/HH \n RETURN\n END IF \n IF (NDIST.EQ.21) THEN\nC SKEW STUDENT-T:\n DIST = DSSTD(Z/HH, SHAPE, SKEW)/HH \n RETURN\n END IF \n IF (NDIST.EQ.30) THEN\nC GED:\n DIST = DGED(Z/HH, SHAPE)/HH \n RETURN\n END IF \n IF (NDIST.EQ.31) THEN\nC SKEW GED:\n DIST = DSGED(Z/HH, SHAPE, SKEW)/HH \n RETURN\n END IF\n RETURN\n END\n \nC ------------------------------------------------------------------------------\nC NORMAL:\n\n\n DOUBLE PRECISION FUNCTION DNORM(X)\n IMPLICIT NONE\n DOUBLE PRECISION X\n DOUBLE PRECISION PI, TWO\n PI = 3.141592653589793D0 \n TWO = 2.0D0\n DNORM = DEXP(-X**2/TWO) / DSQRT(TWO*PI)\n RETURN\n END\n \n \nC ------------------------------------------------------------------------------\nC SKEW NORMAL:\n\n\n DOUBLE PRECISION FUNCTION DSNORM(X, XI)\n IMPLICIT NONE\n DOUBLE PRECISION X, XI\n DOUBLE PRECISION ONE, TWO, PI, M1, MU, SIGMA\n DOUBLE PRECISION Z, XXI, G\n DOUBLE PRECISION DNORM\n ONE = 1.0D0\n TWO = 2.0D0\n PI = 3.141592653589793D0 \n M1 = TWO/DSQRT(TWO*PI)\n MU = M1*(XI-ONE/XI)\n SIGMA = DSQRT((ONE-M1**2)*(XI**2+ONE/XI**2)+TWO*M1**2-ONE)\n Z = X*SIGMA+MU \n XXI = XI**SIGN(ONE, Z)\n IF (Z.EQ.0.0D0) THEN\n XXI = XI**0.0D0\n END IF \n G = TWO/(XI+ONE/XI)\n DSNORM = G*DNORM(Z/XXI)*SIGMA\n RETURN\n END\n\n \nC ------------------------------------------------------------------------------\nC GED:\n\n\n DOUBLE PRECISION FUNCTION DGED(X, NU) \n IMPLICIT NONE\n DOUBLE PRECISION X, NU\n DOUBLE PRECISION HALF, ONE, TWO, THREE, LAMBDA, G\n DOUBLE PRECISION DGAM\n HALF = 0.50D0\n ONE = 1.0D0\n TWO = 2.0D0\n THREE = 3.0D0\n LAMBDA = DSQRT(TWO**(-TWO/NU)*DGAM(ONE/NU)/DGAM(THREE/NU))\n G = NU/(LAMBDA*(TWO**(ONE+ONE/NU))*DGAM(ONE/NU))\n DGED = G*DEXP(-HALF*(DABS(X/LAMBDA))**NU)\n RETURN\n END\n \n \nC ------------------------------------------------------------------------------\nC SKEW GED:\n\n\n DOUBLE PRECISION FUNCTION DSGED(X, NU, XI) \n IMPLICIT NONE\n DOUBLE PRECISION X, NU, XI\n DOUBLE PRECISION HALF, ONE, TWO, THREE, LAMBDA, G, M1, MU\n DOUBLE PRECISION SIGMA, Z, XXI\n DOUBLE PRECISION DGAM, DGED\n HALF = 0.50D0\n ONE = 1.0D0\n TWO = 2.0D0\n THREE = 3.0D0 \n LAMBDA = DSQRT(TWO**(-TWO/NU)*DGAM(ONE/NU)/DGAM(THREE/NU))\n G = NU/(LAMBDA*(TWO**(ONE+ONE/NU))*DGAM(ONE/NU))\n M1 = (TWO**(ONE/NU))*LAMBDA*DGAM(TWO/NU)/DGAM(ONE/NU)\n MU = M1*(XI-ONE/XI)\n SIGMA = (ONE-M1**2)*(XI**2+ONE/(XI**2))+TWO*(M1**2)-ONE\n SIGMA = DSQRT(SIGMA)\n Z = X*SIGMA+MU\n XXI = XI**SIGN(ONE, Z)\n IF (Z.EQ.0.0D0) THEN\n XXI = XI**0.0D0\n END IF \n DSGED = (TWO/(XI+ONE/XI))*DGED(Z/XXI, NU)*SIGMA\n RETURN\n END\n \n \nC ------------------------------------------------------------------------------\nC STUDENT T:\n\n\n DOUBLE PRECISION FUNCTION DT(X, NU) \n IMPLICIT NONE\n DOUBLE PRECISION X, NU\n DOUBLE PRECISION ONE, TWO, PI, A, B\n DOUBLE PRECISION DGAM\n ONE = 1.0D0\n TWO = 2.0D0\n PI = 3.141592653589793D0 \n A = DGAM((NU+ONE)/TWO)/DSQRT(PI*NU)\n B = DGAM(NU/TWO)*(ONE+(X*X)/NU)**((NU+ONE)/TWO)\n DT = A/B\n RETURN\n END\n \n\nC ------------------------------------------------------------------------------\nC STANDARDIZED STUDENT T:\n\n \n DOUBLE PRECISION FUNCTION DSTD(X, NU) \n IMPLICIT NONE\n DOUBLE PRECISION X, NU\n DOUBLE PRECISION TWO, S\n DOUBLE PRECISION DT\n TWO = 2.0D0\n S = DSQRT(NU/(NU-TWO))\n DSTD = S*DT(X*S,NU)\n RETURN\n END\n\n \nC ------------------------------------------------------------------------------\nC STANDARDIZED SKEW STUDENT T:\n\n \n DOUBLE PRECISION FUNCTION DSSTD(X, NU, XI) \n IMPLICIT NONE\n DOUBLE PRECISION X, NU, XI\n DOUBLE PRECISION ONE, TWO, A, B, BETA, M1, MU\n DOUBLE PRECISION SIGMA, Z, G, XXI\n DOUBLE PRECISION DSTD, DGAM\n ONE = 1.0D0\n TWO = 2.0D0\n A = ONE/TWO\n B = NU/TWO\n BETA = (DGAM(A)/DGAM(A+B))*DGAM(B)\n M1 = TWO*DSQRT(NU-TWO)/(NU-ONE)/BETA\n MU = M1*(XI-ONE/XI)\n SIGMA = DSQRT((ONE-M1**2)*(XI**2+ONE/XI**2)+TWO*M1**2-ONE)\n Z = X*SIGMA+MU\n XXI = XI**SIGN(ONE, Z)\n IF (Z.EQ.0.0D0) THEN\n XXI = XI**0.0D0\n END IF\n G = TWO/(XI+ONE/XI)\n DSSTD = G*DSTD(Z/XXI,NU)*SIGMA \n RETURN\n END\n\n", "meta": {"hexsha": "6495f2676fc1f02fe9f4a1beb64af2d02feaaab1", "size": 5234, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "scripts/fGarch/src/dist.f", "max_stars_repo_name": "diegoacuna/tarch-based-volatility-model", "max_stars_repo_head_hexsha": "03ab1afc1f054e84772f9f181e8ac8aeee834f4f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-12-04T18:34:51.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-18T13:56:19.000Z", "max_issues_repo_path": "scripts/fGarch/src/dist.f", "max_issues_repo_name": "diegoacuna/tarch-based-volatility-model", "max_issues_repo_head_hexsha": "03ab1afc1f054e84772f9f181e8ac8aeee834f4f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "scripts/fGarch/src/dist.f", "max_forks_repo_name": "diegoacuna/tarch-based-volatility-model", "max_forks_repo_head_hexsha": "03ab1afc1f054e84772f9f181e8ac8aeee834f4f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-02-23T01:10:23.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-24T05:57:13.000Z", "avg_line_length": 26.3015075377, "max_line_length": 80, "alphanum_fraction": 0.4594956057, "num_tokens": 1736, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319863, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6807491075484733}} {"text": "!##############################################################################\n! MODULE globals\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!##############################################################################\nmodule globals\n\n ! variable declaration\n implicit none\n real*8 :: eta = 1.6d0\n real*8 :: c(2) = (/0.6d0, 0.8d0/)\n\ncontains\n\n\n ! function that defines the oligopoly equations\n function cournot(q)\n\n implicit none\n real*8, intent(in) :: q(:)\n real*8 :: cournot(size(q, 1)),QQ\n integer :: i\n\n QQ = sum(q)\n do i = 1,size(q, 1)\n cournot(i) = QQ**(-1d0/eta)-1d0/eta*QQ**(-1d0/eta-1)*q(i)-c(i)*q(i)\n enddo\n\n end function cournot\n\nend module\n", "meta": {"hexsha": "064a954f3625a000f9b9b7be75e5f46694c3170c", "size": 953, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "complete/prog02/prog02_08/prog02_08m.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_08/prog02_08m.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_08/prog02_08m.f90", "max_forks_repo_name": "aswinvk28/modflow_fortran", "max_forks_repo_head_hexsha": "0c8dd5da8fe08f0abcc6b677503e96cdcdb7ee1e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-04-07T12:27:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-07T12:27:47.000Z", "avg_line_length": 24.4358974359, "max_line_length": 79, "alphanum_fraction": 0.4711437566, "num_tokens": 262, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869786798663, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6807490924283432}} {"text": "! Created by EverLookNeverSee@GitHub on 5/28/20\n! For more information see FCS/img/Exercise_01.png\n\nprogram main\n ! I --> current(amps)\n ! E --> voltage(volts)\n ! R --> resistance(ohms)\n ! L --> inductance(henrys)\n ! C --> capacitance(farads)\n ! f --> frequency(herts)\n implicit none\n ! declaring variables\n real :: I, E, R, L, C, f\n ! getting user input\n print *, \"Enter values for E, R, L, C, and f respectively:\"\n read *, E, R, L, C, f\n ! calculating I and printing the result\n I = E / sqrt(R ** 2 + ((2.0 * 3.1415 / L) - 1.0 / (2.0 * 3.1415 * f * C)) ** 2)\n print \"(a3,f13.9)\", \"I: \", I\nend program main\n", "meta": {"hexsha": "87151716809473dd282745784355ac23a4385067", "size": 653, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/numerical methods/Exercise_01.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_01.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_01.f90", "max_forks_repo_name": "EverLookNeverSee/FCS", "max_forks_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-06-08T12:57:46.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-08T12:57:46.000Z", "avg_line_length": 31.0952380952, "max_line_length": 83, "alphanum_fraction": 0.5681470138, "num_tokens": 228, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425377849805, "lm_q2_score": 0.7401743735019595, "lm_q1q2_score": 0.6806958392507501}} {"text": " real*8 function qman(x1,x2,x3,x4) result (r_qman)\r\n \r\n!! ~ ~ ~ PURPOSE ~ ~ ~\r\n!! this subroutine calculates flow rate or flow velocity using Manning's\r\n!! equation. If x1 is set to 1, the velocity is calculated. If x1 is set to\r\n!! cross-sectional area of flow, the flow rate is calculated.\r\n\r\n!! ~ ~ ~ INCOMING VARIABLES ~ ~ ~\r\n!! name |units |definition\r\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ \r\n!! x1 |m^2 or none |cross-sectional flow area or 1.\r\n!! x2 |m |hydraulic radius\r\n!! x3 |none |Manning's \"n\" value for channel\r\n!! x4 |m/m |average slope of channel\r\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ \r\n\r\n!! ~ ~ ~ OUTGOING VARIABLES ~ ~ ~\r\n!! name |units |definition\r\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ \r\n!! qman |m^3/s or m/s |flow rate or flow velocity\r\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ \r\n\r\n!! ~ ~ ~ SUBROUTINES/FUNCTIONS CALLED ~ ~ ~\r\n!! Intrinsic: Sqrt\r\n\r\n!! ~ ~ ~ ~ ~ ~ END SPECIFICATIONS ~ ~ ~ ~ ~ ~\r\n\r\n real*8, intent (in) :: x1, x2, x3, x4\r\n\r\n r_qman = 0.\r\n r_qman = x1 * x2 ** .6666 * Sqrt(x4) / x3\r\n\r\n return\r\n end", "meta": {"hexsha": "19263df612e0c5cea4678f65c23cf74c5c4c4210", "size": 1342, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "swat_cli/rev670_source/qman.f", "max_stars_repo_name": "GISWAT/erosion-sediment", "max_stars_repo_head_hexsha": "6ab469eba99cba8e5c365cd4d18cba2e8781ccf6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-06-05T06:33:14.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-05T06:33:14.000Z", "max_issues_repo_path": "swat_cli/rev670_source/qman.f", "max_issues_repo_name": "GISWAT/erosion-sediment", "max_issues_repo_head_hexsha": "6ab469eba99cba8e5c365cd4d18cba2e8781ccf6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "swat_cli/rev670_source/qman.f", "max_forks_repo_name": "GISWAT/erosion-sediment", "max_forks_repo_head_hexsha": "6ab469eba99cba8e5c365cd4d18cba2e8781ccf6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.4705882353, "max_line_length": 79, "alphanum_fraction": 0.3964232489, "num_tokens": 459, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.939024825960626, "lm_q2_score": 0.7248702761768248, "lm_q1q2_score": 0.6806711849309738}} {"text": "c =====================================================\n subroutine clawpack46_qinit(maxmx,maxmy,meqn,mbc,mx,my,\n & xlower,ylower, dx,dy,q,maux,aux)\nc =====================================================\nc\nc # Set initial conditions for q.\nc # Sample scalar equation with data that is piecewise constant with\nc # q = 1.0 if 0.1 < x < 0.6 and 0.1 < y < 0.6\nc # 0.1 otherwise\nc\n implicit double precision (a-h,o-z)\n dimension q(1-mbc:maxmx+mbc, 1-mbc:maxmy+mbc, meqn)\n\n double precision a(3,3)\n\n double precision pi, pi2\n common /compi/ pi, pi2\n\n\n f(x,y)=dsin(8d0*datan(1d0)*x)*dsin(8d0*datan(1d0)*y)\n\n\n a(1,1)=1d0\n a(1,2)=4d0\n a(1,3)=1d0\n a(2,1)=4d0\n a(2,2)=16d0\n a(2,3)=4d0\n a(3,1)=1d0\n a(3,2)=4d0\n a(3,3)=1d0\n\n do 20 j=1-mbc,my+mbc\n do 10 i=1-mbc,mx+mbc\n q(i,j,1)=0d0\n 10 continue\n 20 continue\n\n do 22 j=1-mbc,my+mbc\n yj = ylower + (j-1d0)*dy\n do 12 i=1-mbc,mx+mbc\n xi = xlower + (i-1d0)*dx\n do 33 k=0,2\n do 44 l=0,2 \n q(i,j,1)=q(i,j,1)+(1d0/36d0)*a(k+1,l+1)\n & * f(dx*k/2d0+xi,dy*l/2d0+yj)\n 44 continue\n 33 continue\n 12 continue\n 22 continue\n\n return\n end\n", "meta": {"hexsha": "35a2b01e5709bd5c5edbd0e590c639b3a5c77536", "size": 1383, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "applications/clawpack/advection/2d/adv_order3/user_4.6/qinit.f", "max_stars_repo_name": "scivision/forestclaw", "max_stars_repo_head_hexsha": "4dae847a8abd1055e70acda9c2973cd3dd77d3f1", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "applications/clawpack/advection/2d/adv_order3/user_4.6/qinit.f", "max_issues_repo_name": "scivision/forestclaw", "max_issues_repo_head_hexsha": "4dae847a8abd1055e70acda9c2973cd3dd77d3f1", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "applications/clawpack/advection/2d/adv_order3/user_4.6/qinit.f", "max_forks_repo_name": "scivision/forestclaw", "max_forks_repo_head_hexsha": "4dae847a8abd1055e70acda9c2973cd3dd77d3f1", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.6111111111, "max_line_length": 72, "alphanum_fraction": 0.43890094, "num_tokens": 543, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178994073576, "lm_q2_score": 0.7490872187162397, "lm_q1q2_score": 0.6806340551428496}} {"text": "\n subroutine GAUSSJ(a,n,np,b,m,mp,ierr)\n\nc Purpose: Solution of the system of linear equations AX = B by\nc Gauss-Jordan elimination, where A is a matrix of order N and B is\nc an N x M matrix. On output A is replaced by its matrix inverse\nc and B is preplaced by the corresponding set of solution vectors.\n\nc Source: W.H. Press et al, \"Numerical Recipes,\" 1989, p. 28.\n\nc Modifications: \nc 1. Double precision.\nc 2. Error parameter IERR included. 0 = no error. 1 = singular \nc matrix encountered; no inverse is returned.\n\nc Prepared by J. Applequist, 8/17/91.\n\nc Set largest anticipated value of N.\n\n parameter (nmax=500)\n dimension a(np,np),b(np,mp),ipiv(nmax),indxr(nmax),indxc(nmax)\n\n ierr=0\n do 11 j=1,n\n ipiv(j)=0\n 11 continue\n do 22 i=1,n\n big=0.d0\n do 13 j=1,n\n if (ipiv(j).ne.1) then\n do 12 k=1,n\n if (ipiv(k).eq.0) then\n if (abs(a(j,k)).ge.big) then\n big=abs(a(j,k))\n irow=j\n icol=k\n endif\n else if (ipiv(k).gt.1) then\n ierr=1\n return\n endif\n 12 continue\n endif\n 13 continue\n ipiv(icol)=ipiv(icol)+1\n if (irow.ne.icol) then\n do 14 l=1,n\n dum=a(irow,l)\n a(irow,l)=a(icol,l)\n a(icol,l)=dum\n 14 continue\n do 15 l=1,m\n dum=b(irow,l)\n b(irow,l)=b(icol,l)\n b(icol,l)=dum\n 15 continue\n endif\n indxr(i)=irow\n indxc(i)=icol\n if (a(icol,icol).eq.0.d0) then\n ierr=1\n return\n endif\n pivinv=1.d0/a(icol,icol)\n a(icol,icol)=1.d0\n do 16 l=1,n\n a(icol,l)=a(icol,l)*pivinv\n 16 continue\n do 17 l=1,m\n b(icol,l)=b(icol,l)*pivinv\n 17 continue\n do 21 ll=1,n\n if (ll.ne.icol) then\n dum=a(ll,icol)\n a(ll,icol)=0.d0\n do 18 l=1,n\n a(ll,l)=a(ll,l)-a(icol,l)*dum\n 18 continue\n do 19 l=1,m\n b(ll,l)=b(ll,l)-b(icol,l)*dum\n 19 continue\n endif\n 21 continue\n 22 continue\n do 24 l=n,1,-1\n if (indxr(l).ne.indxc(l)) then\n do 23 k=1,n\n dum=a(k,indxr(l))\n a(k,indxr(l))=a(k,indxc(l))\n a(k,indxc(l))=dum\n 23 continue\n endif\n 24 continue\n return\n end\n", "meta": {"hexsha": "00913339563f3b71b92b7b03d20b95023da97f06", "size": 2203, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/lib/gaussj.f", "max_stars_repo_name": "maxinye/laps-mirror", "max_stars_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_stars_repo_licenses": ["Intel", "Unlicense", "OLDAP-2.2.1", "NetCDF"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-04-05T12:28:22.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-29T06:37:29.000Z", "max_issues_repo_path": "src/lib/gaussj.f", "max_issues_repo_name": "longwosion/laps-mirror", "max_issues_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_issues_repo_licenses": ["Intel", "NetCDF", "OLDAP-2.2.1", "Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/lib/gaussj.f", "max_forks_repo_name": "longwosion/laps-mirror", "max_forks_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_forks_repo_licenses": ["Intel", "NetCDF", "OLDAP-2.2.1", "Unlicense"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-04-27T12:51:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-19T13:57:44.000Z", "avg_line_length": 22.9479166667, "max_line_length": 71, "alphanum_fraction": 0.5524285066, "num_tokens": 810, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837706, "lm_q2_score": 0.7490872187162396, "lm_q1q2_score": 0.6806340495819354}} {"text": " Subroutine plegendr(n,x,pn,dpn)\n\nCf2py intent(in) n,x\nCf2py intent(out) pn,dpn\n\timplicit none\n\n\tinteger n,m,i\n\treal*8 x,x2,x3,x4,x5,pn,dpn\n\treal*8 pn_1,pn_2,dpn_1,dpn_2\n\n\tx2=x*x\n\tx4=x2*x2\n\n\tif (n.eq.0) then\n\t pn=1.\n\t dpn=0.\n\telseif (n.eq.1) then\n\t pn = x\n\t dpn = 1.\n\telseif (n.eq.2) then\n\t x2=x*x\n\t pn=1.5*x2-.5\n\t dpn=3.*x\n\telseif (n.eq.3) then\n\t x2=x*x\n\t x3=x2*x\n\t pn=2.5*x3-1.5*x\n\t dpn=7.5*x2-1.5\n\telseif (n.eq.4) then\n\t x2=x*x\n\t x3=x2*x\n\t x4=x3*x\n\t pn=4.375*x4-3.75*x2+.375\n\t dpn=17.5*x3-7.5*x\n\telseif (n.eq.5) then\n\t x2=x*x\n\t x3=x2*x\n\t x4=x3*x\n\t x5=x4*x\n\t pn=7.875*x5 - 8.75*x3+1.875*x\n\t dpn=39.375*x4-26.25*x2+1.875\n\telse\n\t x2=x*x\n\t x3=x2*x\n\t x4=x3*x\n\t x5=x4*x\n\t pn_2=4.375*x4-3.75*x2+.375\n\t dpn_2=17.5*x3-7.5*x\n\t pn_1=7.875*x5 - 8.75*x3+1.875*x\n\t dpn_1=39.375*x4-26.25*x2+1.875\n\t m=5\n\t do i=1,n-m\n\t m=m+1\n\t pn=(2.-1./m)*x*pn_1-(1.-1./m)*pn_2\n\t dpn=(2.-1./m)*(pn_1+x*dpn_1)-(1.-1./m)*dpn_2\n\t pn_2=pn_1\n\t dpn_2=dpn_1\n\t pn_1=pn\n\t dpn_1=dpn\n\t enddo\n\tendif\n\treturn\n\tend\n", "meta": {"hexsha": "d4ba67e6ffde65c4dc866bbdf8c57d0528011767", "size": 1031, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "dir.source/dir.projection/plegendr.f", "max_stars_repo_name": "space-physics/transcar", "max_stars_repo_head_hexsha": "a9305bd29723beb45004a8882627fa518d8a1bb6", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-06-13T11:32:22.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-02T10:31:46.000Z", "max_issues_repo_path": "dir.source/dir.projection/plegendr.f", "max_issues_repo_name": "scivision/transcar", "max_issues_repo_head_hexsha": "a9305bd29723beb45004a8882627fa518d8a1bb6", "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": "dir.source/dir.projection/plegendr.f", "max_forks_repo_name": "scivision/transcar", "max_forks_repo_head_hexsha": "a9305bd29723beb45004a8882627fa518d8a1bb6", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-07-08T19:03:24.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-08T19:03:24.000Z", "avg_line_length": 16.109375, "max_line_length": 49, "alphanum_fraction": 0.5499515034, "num_tokens": 591, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178944582997, "lm_q2_score": 0.7490872075132152, "lm_q1q2_score": 0.680634041256305}} {"text": "c=======================================================================\nc\nc subroutine PEGARCH \nc\nc Autoregressive Conditionally Heteroskedastic (ARCH) process generator\nc\nc e(t) = sigma(t)*u(t)\nc\nc where\nc\nc sigma(t) = sqrt[w + alpha(1)*e(t-1)^2 + ... + alpha(p)*e(t-p)^2]\nc\nc-----------------------------------------------------------------------\n SUBROUTINE pegarch ( T, N, P, Q, w, alpha, beta, y, sigma, info )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc T : time (days, months, years) integer\nc N : number of sub-division(s) integer \nc P : AR process order (P >= 0) integer\nc Q : MA process order (Q >= 0) integer\nc w : constant parameter double\nc alpha : GARCH P-parameter, vector (P) double\nc beta : GARCH Q-parameter, vector (Q) double\nc\nc OUTPUT \nc y : generated process (N) double\nc sigma : generated conditional volatility (N) double\nc info : diagnostic information integer \nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\nc\nc arguments i/o\n INTEGER N, T, P, Q, info\n DOUBLE PRECISION w, alpha(*), beta(*), y(*), sigma(*)\nc\nc local variables \n INTEGER M, i, j, k\n DOUBLE PRECISION sum, epsilon\n PARAMETER (epsilon = 1.E-15) \nc\nc external subroutines\n EXTERNAL PEARCH \nc\nc external functions\n DOUBLE PRECISION rn\n EXTERNAL rn\nc \nc intrinsic functions\n INTRINSIC max, sqrt \nc\nc-----------------------------------------------------------------------\nc\nc initialization\n info = 0\nc\nc maximum order max(P,Q)\n M = max(P,Q)\nc\nc case Q = 0 (ARCH process)\n IF (Q .EQ. 0) THEN\n CALL pearch ( T, N, P, w, alpha, y, sigma, info )\n RETURN\n ENDIF \nc\nc test if M < 0 or M > N\n IF ((M .LT. 1).OR.(M .GT. N)) THEN\n info = -3101\n RETURN\n ENDIF\nc\nc initialization step \n sum = 0.\n DO j = 1,P\n sum = sum + alpha(j)\n ENDDO\n DO j = 1,Q\n sum = sum + beta(j)\n ENDDO\nc\nc test if sum(alpha+beta) < 1. \n IF (sum .GE. (1. - epsilon)) THEN\n info = -3102\n RETURN\n ENDIF\nc \nc loop\n DO i = 1,M\n sigma(i) = sqrt(w/(1.-sum))\n y(i) = sigma(i)*rn()\n ENDDO \nc\nc loop \n DO i = 1,N-M\nc\nc conditional volatility \n sum = w \n IF (P .GE. 1) THEN \n DO j = 1,P\n k = i + P - j\n sum = sum + alpha(j)*y(k)*y(k)\n ENDDO\n ENDIF \n IF (Q .GE. 1) THEN\n DO j = 1,Q\n k = i + Q - j\n sum = sum + beta(j)*sigma(k)*sigma(k)\n ENDDO\n ENDIF \n sigma(i + M) = sqrt(sum) \nc\nc GARCH(P,Q) process\n y(i + M) = sigma(i + M)*rn()\n ENDDO\nc\n RETURN\n END\n", "meta": {"hexsha": "2f9e9ee30011c628ec167fb3bca41dd784b28f19", "size": 3273, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/rnd/process/pegarch.f", "max_stars_repo_name": "alpgodev/numx", "max_stars_repo_head_hexsha": "d2d3a0713020e1b83b65d3a661c3801ea256aff9", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-07-25T20:28:58.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-10T18:52:08.000Z", "max_issues_repo_path": "src/math/rnd/process/pegarch.f", "max_issues_repo_name": "alpgodev/numx", "max_issues_repo_head_hexsha": "d2d3a0713020e1b83b65d3a661c3801ea256aff9", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/math/rnd/process/pegarch.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": 27.275, "max_line_length": 81, "alphanum_fraction": 0.3923006416, "num_tokens": 874, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178895092414, "lm_q2_score": 0.7490872075132153, "lm_q1q2_score": 0.6806340375490288}} {"text": " RECURSIVE FUNCTION COMMON_FACTOR(N,m,ifact) RESULT(val)\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: N\n INTEGER, INTENT(IN) :: m\n INTEGER, INTENT(IN) :: ifact\n INTEGER:: val\n\n val = 0\n IF (mod(N,m)==0) THEN\n val = m\n ELSE\n val = COMMON_FACTOR(N,m+ifact,ifact)\n END IF\n\n END FUNCTION COMMON_FACTOR", "meta": {"hexsha": "1b097f8bb4ac702d33ee2f61722386538a907d5f", "size": 362, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "LIBSTELL/Sources/Miscel/common_factor.f", "max_stars_repo_name": "joseluisvelasco/STELLOPT", "max_stars_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2020-05-08T01:47:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T10:35:28.000Z", "max_issues_repo_path": "LIBSTELL/Sources/Miscel/common_factor.f", "max_issues_repo_name": "joseluisvelasco/STELLOPT", "max_issues_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 77, "max_issues_repo_issues_event_min_datetime": "2020-05-08T07:18:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:20:33.000Z", "max_forks_repo_path": "LIBSTELL/Sources/Miscel/common_factor.f", "max_forks_repo_name": "joseluisvelasco/STELLOPT", "max_forks_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-02-10T13:47:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T12:53:43.000Z", "avg_line_length": 24.1333333333, "max_line_length": 61, "alphanum_fraction": 0.5552486188, "num_tokens": 103, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969137, "lm_q2_score": 0.7606506526772883, "lm_q1q2_score": 0.6806221892655578}} {"text": "!> \nmodule VortexPoint2DPeriodic\n use PrecisionMod, only: MK\n implicit none\n real(MK),parameter :: MINNORM2=1e-8\ncontains\n subroutine fUi_VortexPoint2DPeriodicX_11(DeltaP,Intensity,Lambda,SmoothModel,SmoothParam,bComputeGrad,Uind, Grad)\n use MathConstants , only: twopi\n implicit none \n ! Input/output arguments \n real(MK), dimension(3), intent(in) :: DeltaP !< 3 x 1 Pcp-Pv\n real(MK), intent(in) :: Intensity !< Circulation Gamma\n real(MK), intent(in) :: Lambda !< Period in the X direction\n integer, intent(in) ,optional :: SmoothModel !< \n real(MK), intent(inout),optional :: SmoothParam !< \n logical, intent(in) :: bComputeGrad !< \n real(MK), dimension(3),intent(out) :: Uind !< No Side effects. Note that\n real(MK), dimension(9),intent(out) :: Grad !< No Side effects\n ! ! Variables declaration \n real(MK) :: x !< \n real(MK) :: y !< \n real(MK) :: r2 !< \n real(MK) :: factor !< \n real(MK) :: E !< \n real(MK) :: rho2 !< \n real(MK) :: Qm !< \n ! \n ! No need of gradient in 2D\n if(bComputeGrad) then\n Grad(1:9)=0.0_MK !\n else\n Grad(1:9)=0.0_MK\n endif\n factor = 1._MK\n if(SmoothModel>0 .and. SmoothParam>0) then\n rho2 = r2/SmoothParam**2;\n E = exp(-rho2);\n Qm = 1._MK;\n factor = (1._MK-Qm*E);\n !\n else\n SmoothParam=0.0_MK\n endif\n Uind=0.0_MK\n\n r2 = DeltaP(1)**2+ DeltaP(2)**2\n if (r2= fn(x(n))\n c = m + q*(x(:, n+1) - m)\n if (fn(c) < z(n+1)) then\n x(:, n+1) = c\n return\n end if\n\n ! if all else fails: shrinking\n do i=2, n+1\n x(:, i) = x(:, 1) + s*(x(:, i) - x(:, 1))\n end do\n return\n end subroutine step\n\n subroutine find(x, fn, tol, maxiter, conv)\n ! arguments\n real(8), dimension(n, n+1), intent(inout) :: x\n ! declaring fn two times is required for compilation with f2py\n real(8) :: fn\n external :: fn\n real(8), intent(in) :: tol\n integer, intent(in) :: maxiter\n logical, intent(out) :: conv\n integer :: step\n conv = .false.\n step = 0\n\n 100 step = step + 1\n if (all(std(x, n) < tol)) then\n conv = .true.\n return\n else if (step > maxiter) then\n return\n end if\n\n ! calculate and sort values fn(x)\n ! ONLY FOR size(x) == 3\n z = [( fn(x(:, i)), i=1,n+1 )]\n call sort3r(x, z)\n\n ! calculate middle, omitting x(:,n+1)\n m = sum(x(:,1:n), dim=1) / n\n\n ! calculate reflection\n r = m + a*(m - x(:, n+1))\n fr = fn(r)\n if (z(1) <= fr .and. fr <= z(n)) then\n x(:, n+1) = r\n goto 100\n end if\n\n ! calculate expansion\n if (fr < z(1)) then\n e = m + g*(r - m)\n if (fn(e) < fr) then\n x(:, n+1) = e\n else\n x(:, n+1) = r\n end if\n goto 100\n end if\n\n ! calculate contraction\n ! here it is known, that fn(r) >= fn(x(n))\n c = m + q*(x(:, n+1) - m)\n if (fn(c) < z(n+1)) then\n x(:, n+1) = c\n goto 100\n end if\n\n ! if all else fails: shrinking\n do i=2, n+1\n x(:, i) = x(:, 1) + s*(x(:, i) - x(:, 1))\n end do\n goto 100\n end subroutine find\n\nend module simplex\n\n\nprogram test\n use simplex, only: step, find\n implicit none\n ! integer :: i\n real(8), dimension(2, 3) :: x = reshape([-1., -3.5, 0., -4.5, 1., -3.5], &\n [2, 3])\n logical :: conv\n\n 100 format(2(3(3X, F9.6)/))\n\n call find(x, himmelblau, 1d-7, 100, conv)\n print 100, transpose(x)\n print *, 'convergence: ', conv\n\n ! print 100, transpose(x)\n ! do i=1, 20\n ! call step(x, himmelblau)\n ! print 100, transpose(x)\n ! end do\n\ncontains\n real(8) pure &\n function himmelblau(x)\n real(8), dimension(2), intent(in) :: x\n himmelblau = (x(1)**2+x(2)-11d0)**2 + (x(1)+x(2)**2-7d0)**2\n end function himmelblau\n\nend program\n", "meta": {"hexsha": "079cf48a118af2e7ce593ede2cd6d048fca26184", "size": 4351, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "1st_exercise/simplex/_simplex.f90", "max_stars_repo_name": "jerluebke/comp_phys", "max_stars_repo_head_hexsha": "94bca4ab79546f94e50a22476e4d02681efc4177", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-05-28T02:17:09.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-04T03:35:51.000Z", "max_issues_repo_path": "1st_exercise/simplex/_simplex.f90", "max_issues_repo_name": "jerluebke/comp_phys", "max_issues_repo_head_hexsha": "94bca4ab79546f94e50a22476e4d02681efc4177", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "1st_exercise/simplex/_simplex.f90", "max_forks_repo_name": "jerluebke/comp_phys", "max_forks_repo_head_hexsha": "94bca4ab79546f94e50a22476e4d02681efc4177", "max_forks_repo_licenses": ["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.2965116279, "max_line_length": 78, "alphanum_fraction": 0.4490921627, "num_tokens": 1371, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339756938818, "lm_q2_score": 0.8104789063814617, "lm_q1q2_score": 0.6805866742717342}} {"text": " ! -------------------------------------------------------------\n !\n ! Copyright (C) 2021 The Simons Foundation\n ! \n ! Author: Jason Kaye\n ! \n ! -------------------------------------------------------------\n ! \n ! libdlr is licensed under the Apache License, Version 2.0 (the\n ! \"License\"); you may not use this file except in compliance with\n ! the License. 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,\n ! software distributed under the License is distributed on an \"AS\n ! IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n ! express or implied. See the License for the specific language\n ! governing permissions and limitations under the License.\n ! \n ! -------------------------------------------------------------\n \n \n program conv_exp\n \n ! Test convolution of two DLR expansions for Green's functions\n ! which are each a single exponential. Compare result with\n ! analytically-known convolution. Test two methods of\n ! convolution; directly forming matrix of convolution, and fast\n ! convolution in the DLR coefficient domain.\n \n implicit none\n integer ntst\n real *8 lambda,eps,beta\n\n ! Input parameters\n\n lambda = 1000.0d0 ! DLR high energy cutoff\n eps = 1.0d-14 ! DLR error tolerance\n\n ntst = 10000 ! # imaginary time test points\n beta = 1000.0d0 ! Inverse temperature\n\n\n ! Main test subroutine\n\n call conv_exp_main(lambda,eps,ntst,beta)\n\n\n end program conv_exp\n\n\n subroutine conv_exp_main(lambda,eps,ntst,beta)\n\n implicit none\n integer ntst\n real *8 lambda,eps,beta\n\n integer i,j,r\n integer, allocatable :: it2cfp(:)\n real *8 one,gtrue,gtst1,gtst2\n real *8 err1l2,err2l2,err1linf,err2linf,gmax,gl2\n real *8, allocatable :: dlrit(:),dlrrf(:)\n real *8, allocatable :: cf2it(:,:),it2cf(:,:),fstconv(:,:)\n real *8, allocatable :: ttst(:),g1(:),g2(:),g31(:),g32(:)\n\n real *8, allocatable :: phi(:,:),gmat(:,:)\n\n one = 1.0d0\n\n\n ! Get DLR frequencies, imaginary time grid\n\n r = 500 ! Upper bound on DLR rank\n\n allocate(dlrrf(r),dlrit(r))\n\n call dlr_it_build(lambda,eps,r,dlrrf,dlrit)\n\n\n ! Get DLR coefficients -> imaginary time values matrix\n\n allocate(cf2it(r,r))\n\n call dlr_cf2it_init(r,dlrrf,dlrit,cf2it)\n\n\n ! Get imaginary time values -> DLR coefficients matrix (LU form)\n\n allocate(it2cf(r,r),it2cfp(r))\n\n call dlr_it2cf_init(r,dlrrf,dlrit,it2cf,it2cfp)\n\n\n ! Sample G1 and G2 at imaginary time nodes\n\n allocate(g1(r),g2(r),g31(r),g32(r))\n\n do i=1,r\n\n call gfun1(beta,dlrit(i),g1(i))\n call gfun2(beta,dlrit(i),g2(i))\n\n enddo\n\n\n ! Get convolution tensor\n\n allocate(phi(r*r,r))\n\n call dlr_convtens(beta,-1,r,dlrrf,dlrit,it2cf,it2cfp,phi)\n\n\n ! Get matrix of convolution by G1\n\n allocate(gmat(r,r))\n\n call dlr_convmat(r,1,it2cf,it2cfp,phi,g1,gmat)\n\n\n ! Get convolution G3 of G1 with G2\n\n call dlr_conv(r,1,gmat,g2,g31)\n\n \n ! Get DLR coefficients of G3\n\n call dlr_it2cf(r,1,it2cf,it2cfp,g31,g31)\n\n\n\n ! Initialize fast convolution routine\n\n allocate(fstconv(r,2*r))\n\n call dlr_fstconv_init(beta,r,dlrrf,dlrit,cf2it,fstconv)\n\n\n ! Get convolution G3 of G1 with G2 by fast convolution\n\n call dlr_fstconv(r,1,cf2it,it2cf,it2cfp,fstconv,g1,g2,g32)\n\n\n ! Get DLR coefficients of G3\n\n call dlr_it2cf(r,1,it2cf,it2cfp,g32,g32)\n\n\n ! Get test points in relative format\n\n allocate(ttst(ntst))\n\n call eqpts_rel(ntst,ttst)\n\n\n ! Measure L^inf and L^2 errors of convolution\n\n err1linf = 0*one\n err1l2 = 0*one\n err2linf = 0*one\n err2l2 = 0*one\n gmax = 0*one\n gl2 = 0*one\n\n do i=1,ntst\n\n ! Evaluate true convolution\n\n call gfun3(beta,ttst(i),gtrue)\n\n ! Evaluate DLR\n\n call dlr_it_eval(r,1,dlrrf,g31,ttst(i),gtst1)\n call dlr_it_eval(r,1,dlrrf,g32,ttst(i),gtst2)\n\n ! Update L^inf and L^2 errors, norms\n\n err1linf = max(err1linf,abs(gtrue-gtst1))\n err1l2 = err1l2 + (gtrue-gtst1)**2\n err2linf = max(err2linf,abs(gtrue-gtst2))\n err2l2 = err2l2 + (gtrue-gtst2)**2\n\n gmax = max(gmax,abs(gtrue))\n gl2 = gl2 + gtrue**2\n\n enddo\n\n err1l2 = sqrt((ttst(2)-ttst(1))*err1l2)\n err2l2 = sqrt((ttst(2)-ttst(1))*err2l2)\n gl2 = sqrt((ttst(2)-ttst(1))*gl2)\n\n write(6,*) ''\n write(6,*) 'DLR rank = ',r\n write(6,*) 'Abs L^inf err = ',err1linf\n write(6,*) 'Abs L^2 err = ',err1l2\n write(6,*) 'Rel L^inf err = ',err1linf/gmax\n write(6,*) 'Rel L^2 err = ',err1l2/gl2\n\n write(6,*) 'Abs L^inf err = ',err2linf\n write(6,*) 'Abs L^2 err = ',err2l2\n write(6,*) 'Rel L^inf err = ',err2linf/gmax\n write(6,*) 'Rel L^2 err = ',err2l2/gl2\n write(6,*) ''\n\n\n ! Return failed status if error is not sufficiently small\n\n if (err1linf.gt.1.0d-13.or.err2linf.gt.1.0d-13) then\n call exit(1)\n endif\n\n end subroutine conv_exp_main\n\n\n\n subroutine gfun1(beta,t,g)\n\n ! Evaluate single exponential Green's function\n\n implicit none\n real *8 beta,t,g\n real *8, external :: kfunf_rel\n\n real *8 a1\n\n a1 = 0.804d0\n\n g = kfunf_rel(t,beta*a1)\n\n end subroutine gfun1\n\n subroutine gfun2(beta,t,g)\n\n ! Evaluate single exponential Green's function\n\n implicit none\n real *8 beta,t,g\n real *8, external :: kfunf_rel\n\n real *8 a2\n\n a2 = -0.443d0\n\n g = kfunf_rel(t,beta*a2)\n\n end subroutine gfun2\n\n subroutine gfun3(beta,t,g)\n\n ! Evaluate Green's function corresponding to convolution of two \n ! single exponentials \n\n implicit none\n real *8 beta,t,g\n real *8, external :: kfunf_rel\n\n real *8 a1,a2\n\n a1 = 0.804d0\n a2 = -0.443d0\n\n g = (kfunf_rel(t,beta*a2)-kfunf_rel(t,beta*a1))/(a1-a2)\n\n end subroutine gfun3\n", "meta": {"hexsha": "e77fec90561e882dbf49ccb08b1b44a09a6d02fd", "size": 6223, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/conv_exp.f90", "max_stars_repo_name": "jasonkaye/libdlr", "max_stars_repo_head_hexsha": "7dcccc9713615e1ec17d4d0d069b19a5eecbc60d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2021-12-12T20:10:03.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-24T00:04:18.000Z", "max_issues_repo_path": "test/conv_exp.f90", "max_issues_repo_name": "jasonkaye/libdlr", "max_issues_repo_head_hexsha": "7dcccc9713615e1ec17d4d0d069b19a5eecbc60d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-12-17T20:27:01.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-26T20:16:44.000Z", "max_forks_repo_path": "test/conv_exp.f90", "max_forks_repo_name": "jasonkaye/libdlr", "max_forks_repo_head_hexsha": "7dcccc9713615e1ec17d4d0d069b19a5eecbc60d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-12-16T04:41:20.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-12T21:15:51.000Z", "avg_line_length": 23.4830188679, "max_line_length": 71, "alphanum_fraction": 0.5770528684, "num_tokens": 1950, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339716830606, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.6805866729430824}} {"text": "! { dg-do compile }\n!\n! PR fortran/53732\n! this was leading to an internal \"mismatching comparison operand types\"\n! error.\n!\n! Original testcase by minzastro \n! Fixed by Dominique Dhumieres \n\nprogram test\nimplicit none\n\nreal(8) arr(4,4,4,4)\n\narr(:,:,:,:) = 1d0\n\narr(1,:,:,:) = sum(arr, dim=1, mask=(arr(:,:,:,:) > 0d0))\n\nend program test\n", "meta": {"hexsha": "c04510dd0e23da99fffe9c1284e4afb8fc42066b", "size": 384, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/inline_sum_4.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/inline_sum_4.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/inline_sum_4.f90", "max_forks_repo_name": "brugger1/testsuite", "max_forks_repo_head_hexsha": "9b504db668cdeaf7c561f15b76c95d05bfdd1517", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2020-08-31T21:59:10.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-23T22:06:46.000Z", "avg_line_length": 19.2, "max_line_length": 72, "alphanum_fraction": 0.6692708333, "num_tokens": 128, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8397339596505965, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.6805866593469557}} {"text": "program FIRDMAIN\n\n implicit none\n\n ! LOCAL SCALARS\n integer :: flag,ftype,i,me,mi,n,fcnt\n logical :: verbose\n real(8) :: epsfeas,epsopt,f,feas\n\n ! LOCAL ARRAYS\n real(8), allocatable :: l(:), u(:), x(:)\n\n n = 2\n me = 1\n mi = 0\n \n allocate(x(n),l(n),u(n))\n\n x(1) = 5.0D0\n x(2) = 5.0D0\n\n l(1) = - 1.0D+20\n l(2) = - 1.0D+20\n u(1) = 1.0D+20\n u(2) = 1.0D+20\n\n verbose = .true.\n\n epsfeas = 1.0D-8\n epsopt = 1.0D-4\n\n ftype = 1\n\n call fird(n,x,l,u,me,mi,evalf,evalc,evaljac,verbose,ftype, &\n epsfeas,epsopt,f,feas,fcnt,flag)\n\n deallocate(x,l,u)\n\ncontains\n\n !------------------------------------------------------------!\n ! SUBROUTINE EVALF !\n ! !\n ! Defines the objetive function. !\n ! !\n !------------------------------------------------------------!\n\n subroutine evalf(n,x,f,flag)\n\n ! SCALAR ARGUMENTS\n integer :: flag,n\n real(8) :: f\n\n ! ARRAY ARGUMENTS\n real(8) :: x(n)\n\n intent(in ) :: n,x\n intent(out) :: f,flag\n\n flag = 0\n\n f = (x(1) * x(2)) ** 2.0D0\n\n end subroutine evalf\n\n !------------------------------------------------------------!\n ! SUBROUTINE EVALC !\n ! !\n ! Defines the contraints. !\n ! !\n !------------------------------------------------------------!\n\n subroutine evalc(n,x,ind,c,flag)\n\n ! SCALAR ARGUMENTS\n integer :: flag,ind,n\n real(8) :: c\n\n ! ARRAY ARGUMENTS\n real(8) :: x(n)\n\n intent(in ) :: ind,n,x\n intent(out) :: c,flag\n\n flag = 0\n\n if ( ind .eq. 1 ) then\n c = (x(1) - 1.0D0) ** 2.0D0 + 1.0D0 - x(2)\n else\n flag = 1\n end if\n\n end subroutine evalc\n\n !------------------------------------------------------------!\n ! SUBROUTINE EVALJAC !\n ! !\n ! Defines the Jacobian of the constraints. !\n ! !\n !------------------------------------------------------------!\n \n subroutine evaljac(n,x,ind,jcvar,jcval,jcnnz,flag)\n\n ! SCALAR ARGUMENTS\n integer :: flag,ind,jcnnz,n\n\n ! ARRAY ARGUMENTS\n integer :: jcvar(n)\n real(8) :: jcval(n),x(n)\n\n intent(in ) :: ind,n,x\n intent(out) :: flag,jcnnz,jcval,jcvar\n\n flag = 0\n\n if ( ind .eq. 1 ) then\n jcnnz = 2\n jcvar(1) = 1\n jcval(1) = 2.0D0 * (x(1) - 1.0D0)\n jcvar(2) = 2\n jcval(2) = - 1.0D0\n else\n flag = 1\n end if\n\n end subroutine evaljac\n\nend program FIRDMAIN\n", "meta": {"hexsha": "7000270f1db9bb0cddbb20d8df97c677882127c8", "size": 2847, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/examples/toyprob.f90", "max_stars_repo_name": "fsobral/fkss", "max_stars_repo_head_hexsha": "16ef79b194358c20e5ffb3554c6362742de1018c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-21T12:20:08.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-21T12:20:08.000Z", "max_issues_repo_path": "tests/examples/toyprob.f90", "max_issues_repo_name": "fsobral/fkss", "max_issues_repo_head_hexsha": "16ef79b194358c20e5ffb3554c6362742de1018c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/examples/toyprob.f90", "max_forks_repo_name": "fsobral/fkss", "max_forks_repo_head_hexsha": "16ef79b194358c20e5ffb3554c6362742de1018c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.0697674419, "max_line_length": 64, "alphanum_fraction": 0.3617843344, "num_tokens": 843, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711756575749, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.6805651203398914}} {"text": "module siter\n\nuse, intrinsic :: iso_fortran_env, only : dp=>real64,i64=>int64, stderr=>error_unit\nuse perf, only: sysclock2ms\nImplicit None\ninteger, parameter :: wp=dp\n\ncontains\n\nReal(dp) function simple_iter(N,Nrun) result(t)\n\ninteger,Intent(in) :: N,Nrun\n\ninteger :: j,i\ninteger(i64) :: tic,toc,tmin\nreal(wp) :: A(N)\n! volatile tells compiler that value is unpredictable, don't unroll, etc.\nreal(wp), volatile :: x\n\ntmin = huge(0_i64)\n\nDo j = 1, Nrun\n call random_number(A)\n call system_clock(tic)\n x = 0._wp\n Do i = 1, N\n x = 0.5_wp*x + modulo(A(i), 10._wp)\n End Do\n call system_clock(toc)\n if (toc-tic0) then\n call get_command_argument(1,argv)\n read(argv,*) N\nendif\n\nif (argc>1) then\n call get_command_argument(2,argv)\n read(argv,*) Nrun\nendif\n\nt = simple_iter(N, Nrun)\nprint '(A,ES12.4,A)', 'Iteration: ',t,' sec.'\n\n\nend program\n", "meta": {"hexsha": "173b14dea81bfe904da1256eab73e120c0b3670c", "size": 1161, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "iter/iter.f90", "max_stars_repo_name": "scienceopen/numba-examples", "max_stars_repo_head_hexsha": "1331ac4ef4a723d3d8353cd3ce90c9bf127fe547", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2017-03-10T07:41:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-17T16:35:46.000Z", "max_issues_repo_path": "iter/iter.f90", "max_issues_repo_name": "scienceopen/numba-examples", "max_issues_repo_head_hexsha": "1331ac4ef4a723d3d8353cd3ce90c9bf127fe547", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-03-22T22:04:51.000Z", "max_issues_repo_issues_event_max_datetime": "2018-03-22T22:04:51.000Z", "max_forks_repo_path": "iter/iter.f90", "max_forks_repo_name": "scienceopen/numba-examples", "max_forks_repo_head_hexsha": "1331ac4ef4a723d3d8353cd3ce90c9bf127fe547", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-10-16T04:37:17.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-08T12:35:54.000Z", "avg_line_length": 16.5857142857, "max_line_length": 83, "alphanum_fraction": 0.6916451335, "num_tokens": 389, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711680567799, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.68056511627522}} {"text": " PROGRAM entropy_value\n IMPLICIT NONE\n\n INTEGER (KIND=8),PARAMETER::n=100\n\n INTEGER (KIND=8):: i\n REAL (KIND=8):: S1,S2,S3,P1_av,P2_av,P3_av,Smax,Kab,Kad,n1\n REAL (KIND=8),DIMENSION(n):: P1,P2,P3,phi\n\n!!!=======================================================================================\n!!!======================================================================================= \n OPEN(unit=12,file='histogram.dat')\n OPEN(unit=13,file='entropy.dat')\n\n n1=real(n)\n\n CALL read_input_parameter()\n CALL entropy()\n\n CONTAINS\n!!!=======================================================================================\n!!!======================================================================================= \n SUBROUTINE read_input_parameter()\n IMPLICIT NONE\n\n CHARACTER (LEN=150) :: tamp\n OPEN(11,file='1parameter.in') \n READ(11, '(A50)') tamp\n READ(11, '(A50)') tamp\n READ(11, '(A50)') tamp\n READ(11, '(A50)') tamp\n READ(11, '(A50)') tamp\n READ(11, '(A50)') tamp\n READ(11, '(A50)') tamp\n READ(11, '(A30,(F12.6))') tamp, Kab\n READ(11, '(A30,(F12.6))') tamp, Kad\n READ(11, '(A50)') tamp\n READ(11, '(A50)') tamp\n READ(11, '(A50)') tamp\n READ(11, '(A50)') tamp\n READ(11, '(A50)') tamp\n READ(11, '(A50)') tamp\n READ(11, '(A50)') tamp\n READ(11, '(A50)') tamp\n READ(11, '(A50)') tamp\n\n CLOSE(11) \n\n END SUBROUTINE read_input_parameter\n\n!!!=======================================================================================\n!!!======================================================================================= \n SUBROUTINE entropy()\n IMPLICIT NONE\n \n!!! Doc gia tri P\n P1_av=0. ; P2_av=0. ; P3_av=0.\n DO i=1,n\n READ(12,*)phi(i),P1(i),P2(i),P3(i)\n P1_av=P1_av+P1(i)\n P2_av=P2_av+P2(i)\n P3_av=P3_av+P3(i)\n END DO\n\n!!! Smax\n\n ! Smax=log(100.)/log(2.)\n\n!!! Tinh entropy S\n S1=0. ; S2=0. ; S3=0. \n \n DO i=0,n \n \n !IF (P1(i)/=0.) THEN\n IF (P1(i)>0.001) THEN \n S1=S1-P1(i)*log(P1(i))\n END IF\n \n !IF (P2(i)/=0.) THEN \n IF (P2(i)>0.001) THEN \n S2=S2-P2(i)*log(P2(i))\n END IF\n \n !IF (P3(i)/=0.) THEN \n IF (P3(i)>0.001) THEN \n S3=S3-P3(i)*log(P3(i))\n END IF\n\n END DO\n \n !S1=S1/log(2.)/Smax ; S2=S2/log(2.)/Smax ; S3=S3/log(2.)/Smax\n S1=S1/log(n1) ; S2=S2/log(n1) ; S3=S3/log(n1)\n\n WRITE(13,*)Kad,Kab,S1,S2,S3\n WRITE(*,*)S1,S2,S3,P1_av,P2_av,P3_av,Smax\n\n CLOSE(12)\n CLOSE(13)\n\n END SUBROUTINE entropy\n \n END PROGRAM entropy_value\n\n", "meta": {"hexsha": "bec42e9278f7589f21a80bcc8d3fa95ccd064f8b", "size": 2698, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "071OCT15_ISLET_SYNC_Human_30Remove/Ref/4Entropy.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/4Entropy.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/4Entropy.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": 25.9423076923, "max_line_length": 91, "alphanum_fraction": 0.3991845812, "num_tokens": 869, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711642563824, "lm_q2_score": 0.8006920044739461, "lm_q1q2_score": 0.6805651152534965}} {"text": "\tSUBROUTINE DMATRX ( itype, np, xpt, ypt, dens, amtrx, coeff,\n +\t\t\t chord, npt, nout, iret )\nC************************************************************************\nC* DMATRX\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This subroutine computes the values for the chord length of each\t*\nC* segment, the coefficient matrix and a transformation matrix used\t*\nC* in the Gaussian matrix elimination.\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* DMATRX ( ITYPE, NP, XPT, YPT, DENS, AMTRX, COEFF,\t\t\t*\nC*\t CHORD, NPT, NOUT, IRET )\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tITYPE\t\tINTEGER\t\tType of end points\t\t*\nC*\t\t\t\t\t 0 = relaxed\t\t\t*\nC*\t\t\t\t\t 1 = cyclic\t\t\t*\nC*\tNP\t\tINTEGER\t\tNumber of input points\t\t*\nC*\tXPT (NP)\tREAL\t\tX input coordinates\t\t*\nC*\tYPT (NP)\tREAL\t\tY input coordinates\t\t*\nC*\tDENS\t\tREAL\t\tDensity of intermediate points\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tAMTRX (LLMXPT,3) REAL\t\tTransformation matrix\t\t*\nC*\tCOEFF (LLMXPT,2) REAL\t\tCoefficient matrix\t\t*\nC*\tCHORD (NP)\t REAL\t\tChord lengths\t\t\t*\nC*\tNPT (NP)\t INTEGER\tNumber of points per segment\t*\nC*\tNOUT\t\t INTEGER\tTotal number of output points\t*\nC*\tIRET\t\t INTEGER\tReturn code\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* S. Jacobs/NCEP\t 2/98\t\t\t\t\t\t*\nC************************************************************************\n\tINCLUDE\t\t'GEMPRM.PRM'\n\tINCLUDE\t\t'ERROR.PRM'\n\tINCLUDE\t\t'DEVCHR.CMN'\nC*\n\tINTEGER\t\tnpt (*)\n\tREAL\t\txpt (*), ypt (*), amtrx (LLMXPT,3),\n +\t\t\tcoeff (LLMXPT,2), chord (*)\nC------------------------------------------------------------------------\n\tiret = 0\nC\nC*\tCompute the chord length of each segment, and the total length.\nC\n\tDO i = 1, np-1\n\t q1 = xpt(i+1) - xpt(i)\n\t q1 = q1 ** 2\n\t q2 = ypt(i+1) - ypt(i)\n\t q2 = q2 ** 2\n\t chord(i) = SQRT (q1 + q2)\n\tEND DO\nC\nC*\tCompute the number of additional points for each segment.\nC\n\tnout = 0\n\tDO i = 1, np-1\n\t npt(i) = NINT ( chord(i) / ( crvscl / dens ) )\n\t nout = nout + npt(i)\n\tEND DO\n\tnout = nout + np\n\tIF ( nout .gt. LLMXPT ) THEN\n\t iret = NIPNTS\n\t RETURN\n\tEND IF\nC\nC*\tCompute the transformation matrix values for the\nC*\tcyclic conditions.\nC\n\tIF ( itype .eq. 2 ) THEN\n\t amtrx(1,3) = chord(np-1) / chord(1)\n\t amtrx(1,2) = 2.0 * (1.0 + amtrx(1,3))\n\t ELSE\nC\nC*\t Set the transformation matrix values for the\nC*\t relaxed conditions.\nC\n\t amtrx(1,2) = 1.0\n\t amtrx(1,3) = 0.5\n\t amtrx(np,1) = 2.0\n\t amtrx(np,2) = 4.0\n\tEND IF\nC\nC*\tFill in the body of the coefficient matrix.\nC\n\tDO i = 2, np-1\n\t q1 = 3.0 / ( chord(i-1) * chord(i) )\n\t q2 = ( chord(i-1)**2 ) * ( xpt(i+1) - xpt( i) )\n\t q2 = q2 + ( chord( i)**2 ) * ( xpt( i) - xpt(i-1) )\n\t coeff(i,1) = q2 * q1\n\t q2 = ( chord(i-1)**2 ) * ( ypt(i+1) - ypt( i) )\n\t q2 = q2 + ( chord( i)**2 ) * ( ypt( i) - ypt(i-1) )\n\t coeff(i,2) = q2 * q1\n\tEND DO\nC\nC*\tCompute the coefficient matrix values for the cyclic conditions.\nC\n\tIF ( itype .eq. 2 ) THEN\n\t a1 = chord(np-1) / ( chord(1) * chord(1) )\n\t q1 = ( xpt( 2) - xpt( 1) ) * a1\n\t q2 = ( xpt(np) - xpt(np-1) ) / chord(np-1)\n\t coeff(1,1) = 3.0 * ( q1 + q2 )\n\t q1 = ( ypt( 2) - ypt( 1) ) * a1\n\t q2 = ( ypt(np) - ypt(np-1) ) / chord(np-1)\n\t coeff(1,2) = 3.0 * ( q1 + q2 )\n\t ELSE\nC\nC*\t Compute the coefficient matrix values for the\nC*\t relaxed conditions.\nC\n\t coeff( 1,1) = ( 1.5 * ( xpt( 2)-xpt( 1) ) ) / chord(1)\n\t coeff( 1,2) = ( 1.5 * ( ypt( 2)-ypt( 1) ) ) / chord(1)\n\t coeff(np,1) = ( 6.0 * ( xpt(np)-xpt(np-1) ) ) / chord(np-1)\n\t coeff(np,2) = ( 6.0 * ( ypt(np)-ypt(np-1) ) ) / chord(np-1)\n\tEND IF\nC\nC*\tFill in the rest of the transformation matrix.\nC\n\tDO j = 2, np-1\n\t amtrx(j,1) = chord(j)\n\t amtrx(j,2) = 2 * ( chord(j) + chord(j-1) )\n\t amtrx(j,3) = chord(j-1)\n\tEND DO\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "76336fcc02fa1076f282647c42371589f2ad0519", "size": 3751, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/device/curve/dmatrx.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/device/curve/dmatrx.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/device/curve/dmatrx.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.5354330709, "max_line_length": 73, "alphanum_fraction": 0.5065315916, "num_tokens": 1512, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422241476943, "lm_q2_score": 0.7154239836484143, "lm_q1q2_score": 0.6804699590159565}} {"text": "************************************************************************\r\n*\r\n* Subroutine CENTER Called by: SETUPC\r\n*\r\n* compute the 'center' (CENT) of the data (XDATA) such that\r\n* explanatory variables involving linear and quadratic terms are\r\n* orthogonal.\r\n*\r\n* the center is equal to:\r\n* \r\n* XBAR + SUM((XDATA-XBAR)^3)/(2*SUM((XDATA-XBAR)^2))\r\n*\r\n* where\r\n* \r\n* XBAR is the mean of XDATA\r\n*\r\n************************************************************************\r\n SUBROUTINE CENTER(CENT,XDATA,NUM)\r\n*\r\n* subroutine arguments\r\n*\r\n INTEGER*4 NUM\r\n DOUBLE PRECISION CENT,XDATA(*)\r\n*\r\n* local vars\r\n*\r\n INTEGER*4 I\r\n DOUBLE PRECISION XBAR,SECOND,THIRD\r\n* \r\n* function declaration\r\n*\r\n DOUBLE PRECISION MEAN\r\n*\r\n* compute the mean (XBAR), 2nd, and 3rd moments (SECOND, THIRD)\r\n*\r\n XBAR = MEAN(XDATA,NUM)\r\n SECOND = 0.D0\r\n THIRD = 0.D0\r\n DO 10 I=1,NUM\r\n SECOND = SECOND+(XDATA(I)-XBAR)**2\r\n THIRD = THIRD+(XDATA(I)-XBAR)**3\r\n 10 CONTINUE\r\n SECOND = SECOND/DBLE(NUM)\r\n THIRD = THIRD/DBLE(NUM)\r\n*\r\n* compute the center\r\n*\r\n CENT = XBAR + THIRD/(2.D0*SECOND)\r\n\r\n RETURN\r\n END\r\n", "meta": {"hexsha": "bceb114c3db40cf16bc4bb29665a6f782cbf0bd6", "size": 1285, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "codeNexampls/[loadest]/loadsrc/loadest/source_USGS/center.f", "max_stars_repo_name": "lthiamodelers/baseflow-coefficients", "max_stars_repo_head_hexsha": "183fef49548fa2e1bf0bb8cff57e96e75d629760", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "codeNexampls/[loadest]/loadsrc/loadest/source_USGS/center.f", "max_issues_repo_name": "lthiamodelers/baseflow-coefficients", "max_issues_repo_head_hexsha": "183fef49548fa2e1bf0bb8cff57e96e75d629760", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "codeNexampls/[loadest]/loadsrc/loadest/source_USGS/center.f", "max_forks_repo_name": "lthiamodelers/baseflow-coefficients", "max_forks_repo_head_hexsha": "183fef49548fa2e1bf0bb8cff57e96e75d629760", "max_forks_repo_licenses": ["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.7115384615, "max_line_length": 73, "alphanum_fraction": 0.4692607004, "num_tokens": 324, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391727723468, "lm_q2_score": 0.7371581684030624, "lm_q1q2_score": 0.680425865965141}} {"text": "\tREAL*4 FUNCTION\r\n .\tLSAMPLESIZE\r\n . (NTR,XBAR,SX,SLOPES,XALPHA,POWER,\r\n . LAMBDA,SIGMA,\r\n .\t D_LAMBDA,XM,D_GAMMA)\r\n\tUSE MSIMSL\r\nC\r\nC-Description-----------------------------------------------------------\r\nC\r\n\tIMPLICIT NONE\r\nC\r\nC-Description-----------------------------------------------------------\r\nC Function:\r\nC\tMain routine of program to compute sample size calculations\r\nC\tinvolving Linear regression.\r\nC\r\nC Input:\r\nC\tNTR\t\t(Integer) Number of treatments (1 or 2)\r\nC\tXBAR(0:1)\t(Real)\r\nC\tSX(0:1)\t\t(Real)\r\nC\tSLOPES\t\t(Integer) 1=comparing slopes\r\nC\t\t\t\t 2=comparing intercepts\r\nC\r\nC Output:\r\nC\tLSAMPLESIZE\tSample size\r\nC\r\nC Notes:\r\nC\tThis routine was written by Dale Plummer\r\nC\r\nC-Declarations----------------------------------------------------------\r\nC\r\nC Arguments\r\nC\r\n\tINTEGER*4 NTR,SLOPES\r\n\tREAL*4 XBAR(0:1),SX(0:1)\r\n\tREAL*4 XALPHA,POWER,LAMBDA,SIGMA,D_LAMBDA,XM,D_GAMMA\r\nC\r\nC Functions\r\nC\r\n\tREAL*4 TSIZE,ZCRVALUE\r\n\tEXTERNAL TSIZE\r\nC\r\nC Locals\r\nC\r\n\tREAL*4 SIGR2\r\nC\r\nC Common used to pass needed values to passed name functions.\r\nC\r\n\tINTEGER ITYPE\r\n\tREAL*4 ALPHA, XBETA, DELTA, M, NU\r\n\tCOMMON /TSSCOMM/ ALPHA, XBETA, DELTA, M, NU, ITYPE\r\n\r\n\tREAL*4 EPS, ERRABS, ERRREL, ETA, XGUESS(1), XVECT(1)\r\n\tINTEGER*4 ITMAX, NROOT, INFO(1)\r\nC\r\nC-Code------------------------------------------------------------------\r\nC\r\n\tERRABS=1.0E-5\r\n\tEPS=1.0E-5\r\n\tERRREL=1.0E-5\r\n\tETA=1.0E-2\r\n\tITMAX=100\r\n\tNROOT=1\r\n\tALPHA=XALPHA\r\n\tM=XM\r\nC\r\nC First case...number of treatments is 1.\r\nC\r\n\tIF (NTR.EQ.1) THEN\r\n\t ITYPE=3\r\nC .\t\t' Enter ALPHA, POWER, LAMBDA and SIGMA: '\r\n\t XBETA=1.-POWER\r\n\t DELTA=SX(0)*LAMBDA/SIGMA\r\n\t XGUESS(1)=(ZCRVALUE(ALPHA/2.)+ZCRVALUE(XBETA))**2/DELTA**2\r\n\t CALL ZREAL(TSIZE,ERRABS,ERRREL,EPS,ETA,NROOT,ITMAX,\r\n .\t\t\t XGUESS,XVECT,INFO)\r\nC\r\nC If convergence was not reached then INFO(1) will be greater than\r\nC ITMAX. Check for that here.\r\nC\r\n\t\tIF (INFO(1).GT.ITMAX) THEN\r\n\t\t\tLSAMPLESIZE=-999\r\n\t\t\tRETURN\r\n\t\tEND IF\r\n\r\n\t LSAMPLESIZE=XVECT(1)\r\n\tELSE !(NTR.EQ.2) THEN\r\nC\r\nC Second case...number of treatments is 2.\r\nC\r\n\t ITYPE=4\r\nC\r\nC Comparing slopes (SLOPES=1)...\r\nC\r\n\t IF (SLOPES.EQ.1) THEN\r\nC .\t\t' Enter ALPHA, POWER, D_LAMBDA, SIGMA and M: '\r\n\t\t\tSIGR2=SIGMA**2 * (1./(M*SX(0)**2) + 1./SX(1)**2)\r\n\t\t\tDELTA=D_LAMBDA/SQRT(SIGR2)\r\n\t\t\tXBETA=1.-POWER\r\n\t\t\tXGUESS(1)=(ZCRVALUE(ALPHA/2.)+ZCRVALUE(XBETA))**2/DELTA**2\r\n\t\t\tCALL ZREAL(TSIZE,ERRABS,ERRREL,EPS,ETA,NROOT,ITMAX,\r\n .\t\t\tXGUESS,XVECT,INFO)\r\nC\r\nC If convergence was not reached then INFO(1) will be greater than\r\nC ITMAX. Check for that here.\r\nC\r\n\t\t\tIF (INFO(1).GT.ITMAX) THEN\r\n\t\t\t\tLSAMPLESIZE=-999\r\n\t\t\t\tRETURN\r\n\t\t\tEND IF\r\n\r\n\t\t\tLSAMPLESIZE=XVECT(1)\r\n\t ELSE !SLOPES=2\r\nC\r\nC Comparing intercepts (SLOPES=2)...\r\nC\r\nC .\t\t' Enter ALPHA, POWER, D_GAMMA, SIGMA, and M: '\r\n\t\t\tSIGR2=(SIGMA**2/M)*\r\n .\t\t\t(1. +\r\n .\t\t\tXBAR(0)**2/SX(0)**2 +\r\n .\t\t\tM*(1.+XBAR(1)**2/SX(1)**2))\r\n\t\t\tDELTA=D_GAMMA/SQRT(SIGR2)\r\n\t\t\tXBETA=1.-POWER\r\n\t\t\tXGUESS(1)=(ZCRVALUE(ALPHA/2.)+ZCRVALUE(XBETA))**2/DELTA**2\r\n\t\t\tCALL ZREAL(TSIZE,ERRABS,ERRREL,EPS,ETA,NROOT,ITMAX,\r\n .\t\t\tXGUESS,XVECT,INFO)\r\nC\r\nC If convergence was not reached then INFO(1) will be greater than\r\nC ITMAX. Check for that here.\r\nC\r\n\t\t\tIF (INFO(1).GT.ITMAX) THEN\r\n\t\t\t\tLSAMPLESIZE=-999\r\n\t\t\t\tRETURN\r\n\t\t\tEND IF\r\n\r\n\t\t\tLSAMPLESIZE=XVECT(1)\r\n\t END IF\r\n\tEND IF\r\nC\r\nC If conditions warrent then output the disclaimer. Do loop through\r\nC 6 and 7 to write to both terminal and log file.\r\nC\r\nCCC\tDO LUN=6,7\r\nCCC\t TALPHA=TCRVALUE(ALPHA/2.,NU)\r\nCCC\t TXBETA=TCRVALUE(XBETA/2.,NU)\r\nCCC\t IF (2.*TALPHA+TXBETA .LE. 3.1) THEN\r\nCCC\t\tCALL HLPMSG(LUN,7)\r\nCCC\t\tWRITE(UNIT=LUN,FMT='(5X,A,I6,A,F12.4,A,/,5X,A,F12.4,A,/)')\r\nCCC .' associated with N=',N,' will be no less than ',1.-XBETA,' and',\r\nCCC .' no greater than ',1.-XBETA+ALPHA/2.,'.'\r\nCCC\t END IF\r\nCCC\tEND DO\r\n\r\n\tRETURN\r\n\tEND\r\n", "meta": {"hexsha": "0cb6fa453dea629a3efd29cd6637c51edaa7eb2b", "size": 3931, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "misc/old_ps/ps-development-version/psDll/lsamples.for", "max_stars_repo_name": "vubiostat/ps", "max_stars_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2017-12-29T14:19:14.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-06T15:08:46.000Z", "max_issues_repo_path": "misc/old_ps/ps-development-version/psDll/lsamples.for", "max_issues_repo_name": "vubiostat/ps", "max_issues_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2020-04-30T16:57:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-07T00:26:02.000Z", "max_forks_repo_path": "misc/old_ps/ps-development-version/psDll/lsamples.for", "max_forks_repo_name": "vubiostat/ps", "max_forks_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-07T20:11:54.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-11T19:18:59.000Z", "avg_line_length": 25.1987179487, "max_line_length": 75, "alphanum_fraction": 0.5825489697, "num_tokens": 1482, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381604, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.680425857513898}} {"text": " subroutine mapc2m_annulus(blockno,xc,yc,xp,yp,zp,alpha)\n implicit none\n\n integer blockno\n double precision xc,yc,xp,yp,zp, r, alpha\n double precision pi\n common /compi/ pi\n\n r = alpha + (1-alpha)*yc\n xp = r*cos(2*pi*xc)\n yp = r*sin(2*pi*xc)\n zp = 0\n\n\n end\n", "meta": {"hexsha": "b61e17bf13649ab08fda793a578325847fe4b115", "size": 312, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/mappings/annulus/mapc2m_annulus.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/annulus/mapc2m_annulus.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/annulus/mapc2m_annulus.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": 19.5, "max_line_length": 61, "alphanum_fraction": 0.5608974359, "num_tokens": 104, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039738, "lm_q2_score": 0.7371581510799253, "lm_q1q2_score": 0.6804258437326768}} {"text": "c gmm01f\r\nc THIS FILE IS PART OF THE ORIGINAL GMM01F DISTRIBUTION\r\n SUBROUTINE orientud(BETAMI,BETAMX,THETMI,THETMX,PHIMIN,PHIMAX,\r\n & MXBETA,MXTHET,MXPHI,NBETA,NTHETA,NPHI,\r\n & BETA,THETA,PHI)\r\nC Arguments:\r\n INTEGER MXBETA,MXTHET,MXPHI,NBETA,NTHETA,NPHI\r\n double precision BETAMI,BETAMX,THETMI,THETMX,PHIMIN,PHIMAX\r\n double precision BETA(MXBETA),THETA(MXTHET),PHI(MXPHI)\r\nC Local variables:\r\n INTEGER J\r\n double precision DELTA\r\nC***********************************************************************\r\nC Given: BETAMI=minimum value of beta (radians)\r\nC BETAMX=maximum value of beta (radians)\r\nC THETMI=minimum value of theta (radians)\r\nC THETMX=maximum value of theta (radians)\r\nC PHIMIN=minimum value of phi (radians)\r\nC PHIMAX=maximum value of phi (radians)\r\nC MXBETA,MXTHET,MXPHI=dimensions of the arrays BETA,THETA,PHI\r\nC NBETA=number of values of beta\r\nC NTHETA=number of values of theta\r\nC NPHI=number of values of PHI\r\nC Returns: BETA(1-NBETA)=beta values (radians)\r\nC THETA(1-NTHETA)=theta values (radians)\r\nC PHI(1-NPHI)=phi values (radians)\r\nC Note: it is assumed that target orientation weight function\r\nC can be factored into WGTA*WGTB -- i.e., that rotations\r\nC around a1 are decoupled from orientation of a1.\r\nC Purpose: to generate a sequence of desired target orientations\r\nC Present version assumes:\r\nC beta to be uniformly distributed between BETAMI and BETAMX\r\nC theta to be uniformly distributed between THETMI and THETMX\r\nC phi to be uniformly distributed between PHIMIN and PHIMAX\r\nC first angle is THETMI, last angle is THETMX\r\nC***********************************************************************\r\n BETA(1)=BETAMI\r\n IF(NBETA.GT.1)THEN\r\n DELTA=(BETAMX-BETAMI)/DBLE(NBETA-1)\r\n DO 1000 J=2,NBETA\r\n BETA(J)=BETA(1)+DELTA*DBLE(J-1)\r\n 1000 CONTINUE\r\n ENDIF\r\n THETA(1)=THETMI\r\n IF(NTHETA.GT.1)THEN\r\n DELTA=(THETMX-THETMI)/DBLE(NTHETA-1)\r\n DO 2000 J=2,NTHETA\r\n THETA(J)=THETA(1)+DELTA*DBLE(J-1)\r\n 2000 CONTINUE\r\n ENDIF\r\n PHI(1)=PHIMIN\r\n IF(NPHI.GT.1)THEN\r\n DELTA=(PHIMAX-PHIMIN)/DBLE(NPHI-1)\r\n DO 3000 J=2,NPHI\r\n PHI(J)=PHI(1)+DELTA*DBLE(J-1)\r\n 3000 CONTINUE\r\n ENDIF\r\n RETURN\r\n END\r\n\r\n\r\n\r\n", "meta": {"hexsha": "41cb64ede0aa85f423a3a54f765c2ec07a6f1e6b", "size": 2457, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "GMM_FIELD/src/orientud.f", "max_stars_repo_name": "m-ringler/GMM-DIP", "max_stars_repo_head_hexsha": "016a4ca0ecf50c9d665cc17fb209031d0093c9a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "GMM_FIELD/src/orientud.f", "max_issues_repo_name": "m-ringler/GMM-DIP", "max_issues_repo_head_hexsha": "016a4ca0ecf50c9d665cc17fb209031d0093c9a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "GMM_FIELD/src/orientud.f", "max_forks_repo_name": "m-ringler/GMM-DIP", "max_forks_repo_head_hexsha": "016a4ca0ecf50c9d665cc17fb209031d0093c9a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-11-06T14:43:40.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-07T12:05:00.000Z", "avg_line_length": 39.0, "max_line_length": 73, "alphanum_fraction": 0.5991045991, "num_tokens": 761, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.7799929104825007, "lm_q1q2_score": 0.6804247625498843}} {"text": " SUBROUTINE PTINTR (A,AA,B,BB,S,K,EPS)\r\nC\r\nC RETURNS DOUBLE PRECISION VALUES OF X,Y COORDINATES (S) OF\r\nC POINT OF INTERSECTION (IF ANY) OF LINE SEGMENTS\r\nC FROM A TO AA AND B TO BB\r\nC A .NE. AA AND B .NE. BB\r\nC K IS CONDITION FLAG RETURNED --\r\nC K = 1 LINES INTERSECT AT S\r\nC K = 0 LINES INTERSECT AT S, AN ENDPOINT OF ONE LINE SEGMENT\r\nC K =-1 LINES DO NOT INTERSECT\r\nC\r\n DOUBLE PRECISION A(2),AA(2),B(2),BB(2),P(2),S(2)\r\n DOUBLE PRECISION AX,AY,BX,BY,AAA,PA,PAA,BBB,PB,PBB\r\n DOUBLE PRECISION EPS(2),D\r\n DOUBLE PRECISION DIST,X,Y,U,V\r\nC\r\nC EPS ARRAY FOR SIGNIFICANCE TESTING\r\nC EPS(1) IS AREA, ANGLE LIMIT\r\nC EPS(2) IS LENGTH LIMIT\r\nC\r\nC\r\nC DOUBLE PRECISION FUNCTION FOR DISTANCE BETWEEN 2 POINTS\r\nC\r\n DIST(X,Y,U,V) = (X-U)**2 +(Y-V)**2\r\nC\r\n X = 0.D0\r\n Y = X\r\n U = X\r\n V = X\r\n P(1) = 0.D0\r\n P(2) = 0.D0\r\n S(1) = 0.D0\r\n S(2) = 0.D0\r\nC\r\n K =-1\r\nC\r\n AX = AA(1) - A(1)\r\n AY = AA(2) - A(2)\r\n BX = BB(1) - B(1)\r\n BY = BB(2) - B(2)\r\nC\r\n AAA= AX**2 + AY**2\r\n BBB= BX**2 + BY**2\r\n D = BX*AY - AX*BY\r\nC\r\nC IS EITHER LINE TOO SHORT?\r\nC\r\n IF (AAA.LE.EPS(1) .OR. BBB.LE.EPS(1)) RETURN\r\nC\r\nC ARE A AND B PARALLEL?\r\nC\r\n IF (DABS(D) .GT. EPS(1)) GO TO 80\r\nC\r\nC A AND B ARE PARALLEL -- ARE THEY SAME LINE?\r\nC\r\n P(1) = B(1)\r\n P(2) = B(2)\r\n IF (DIST(B(1),B(2), A(1), A(2)) .LE. EPS(1) .OR.\r\n 1 DIST(B(1),B(2),AA(1),AA(2)) .LE. EPS(1)) GO TO 100\r\n P(1) = BB(1)\r\n P(2) = BB(2)\r\n IF (DIST(BB(1),BB(2), A(1), A(2)) .LE. EPS(1) .OR.\r\n 1 DIST(BB(1),BB(2),AA(1),AA(2)) .LE. EPS(1)) GO TO 100\r\nC\r\nC A PARALLEL TO B AND NOT SAME LINE\r\nC\r\n RETURN\r\nC\r\nC IS A PARALLEL TO Y AXIS?\r\nC\r\n 80 IF (DABS(AX) .GT. EPS(2)) GO TO 90\r\n P(1) = A(1)\r\n P(2) = B(2) + (P(1)-B(1))*BY/BX\r\n GO TO 100\r\n 90 P(1) = ((B(2)-A(2))*AX*BX + A(1)*AY*BX-B(1)*AX*BY)/D\r\n P(2) = A(2) + (P(1)-A(1))*AY/AX\r\nC\r\n 100 AAA = AAA + EPS(1)\r\n BBB = BBB + EPS(1)\r\n PA = DIST(P(1),P(2), A(1), A(2))\r\n PB = DIST(P(1),P(2), B(1), B(2))\r\n PAA = DIST(P(1),P(2),AA(1),AA(2))\r\n PBB = DIST(P(1),P(2),BB(1),BB(2))\r\nC\r\nC POINT OF INTERSECTION NOT ON EITHER SEGMENT\r\nC\r\n IF (PA.GT.AAA .OR. PAA.GT.AAA .OR. PB.GT.BBB .OR. PBB.GT.BBB)\r\n 1 RETURN\r\nC\r\nC LINES INTERSECT AT P\r\nC\r\n K = 1\r\n S(1) = P(1)\r\n S(2) = P(2)\r\nC\r\nC LINES INTERSECT AT P, AN ENDPOINT OF ONE SEGMENT\r\nC\r\n IF ((PA.LT.EPS(2) .OR. PAA.LT.EPS(2)) .OR.\r\n 1 (PB.LT.EPS(2) .OR. PBB.LT.EPS(2))) K= 0\r\n RETURN\r\n END\r\n", "meta": {"hexsha": "c7289b0aceddafa7c7adb44919eb8b96e529c891", "size": 2704, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "mis/ptintr.f", "max_stars_repo_name": "ldallolio/NASTRAN-95", "max_stars_repo_head_hexsha": "6d2c175f5b53ebaec4ba2b5186f7926ef9d0ed47", "max_stars_repo_licenses": ["NASA-1.3"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2016-01-09T14:33:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-18T11:51:42.000Z", "max_issues_repo_path": "mis/ptintr.f", "max_issues_repo_name": "gassive/NASTRAN95", "max_issues_repo_head_hexsha": "98cb3acaa7990d639360601648498834c7782056", "max_issues_repo_licenses": ["NASA-1.3"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2016-01-17T07:30:19.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-06T19:37:44.000Z", "max_forks_repo_path": "mis/ptintr.f", "max_forks_repo_name": "gassive/NASTRAN95", "max_forks_repo_head_hexsha": "98cb3acaa7990d639360601648498834c7782056", "max_forks_repo_licenses": ["NASA-1.3"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-04-07T20:51:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T14:16:01.000Z", "avg_line_length": 26.5098039216, "max_line_length": 72, "alphanum_fraction": 0.4730029586, "num_tokens": 1162, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422645, "lm_q2_score": 0.7520125848754472, "lm_q1q2_score": 0.6803085911765552}} {"text": " SUBROUTINE mapder\n\n use setup2d\n\n IMPLICIT NONE\n\n integer :: is,js,ifp,jfp\n double precision :: psi, eta\n\n ! compute the derivatives at the solution points\n\n do js=1,N\n do is=1,N\n \n psi = Xs(is)\n eta = Xs(js)\n !\n dmdxs(1,1,is,js) = eta - 1.d0\n dmdxs(1,2,is,js) = psi - 1.d0\n !\n dmdxs(2,1,is,js) = 1.d0 - eta\n dmdxs(2,2,is,js) = -psi\n !\n dmdxs(3,1,is,js) = eta\n dmdxs(3,2,is,js) = psi\n !\n dmdxs(4,1,is,js) = -eta\n dmdxs(4,2,is,js) = 1.d0 - psi\n\n end do\n end do\n\n ! compute the derivatives at the flux points (family 1)\n do jfp=1,N\n do ifp=1,N+1\n !\n psi = Xf(ifp)\n eta = Xs(jfp)\n !\n dmdxf1(1,1,ifp,jfp) = eta - 1.d0\n dmdxf1(1,2,ifp,jfp) = psi - 1.d0\n !\n dmdxf1(2,1,ifp,jfp) = 1.d0 - eta\n dmdxf1(2,2,ifp,jfp) = -psi\n !\n dmdxf1(3,1,ifp,jfp) = eta\n dmdxf1(3,2,ifp,jfp) = psi\n !\n dmdxf1(4,1,ifp,jfp) = -eta\n dmdxf1(4,2,ifp,jfp) = 1.d0 - psi\n !\n end do\n end do\n !\n ! compute the derivatives at the flux points (family 2)\n\n do jfp=1,N+1\n do ifp=1,N\n psi = Xs(ifp)\n eta = Xf(jfp)\n dmdxf2(1,1,ifp,jfp) = eta - 1.d0\n dmdxf2(1,2,ifp,jfp) = psi - 1.d0\n !\n dmdxf2(2,1,ifp,jfp) = 1.d0 - eta\n dmdxf2(2,2,ifp,jfp) = -psi\n !\n dmdxf2(3,1,ifp,jfp) = eta\n dmdxf2(3,2,ifp,jfp) = psi\n !\n dmdxf2(4,1,ifp,jfp) = -eta\n dmdxf2(4,2,ifp,jfp) = 1.d0 - psi\n !\n end do\n end do\n\n END SUBROUTINE mapder\n\n!****************************************************************************\n SUBROUTINE MapBaseFunc(func,xi,eta)\n IMPLICIT NONE\n DOUBLE PRECISION :: func(4),xi,eta\n func(1)= (1.0-xi)*(1.0-eta)\n func(2)= (1.0-eta)*xi\n func(3)= xi*eta\n func(4)= (1.0-xi)*eta\n RETURN\n END SUBROUTINE MapBaseFunc\n!****************************************************************************\n\n!****************************************************************************\n SUBROUTINE MapBaseFunc8(func8,xi,eta)\n IMPLICIT NONE\n DOUBLE PRECISION :: func8(8),xi,eta\n func8(1)= (1.0-xi)*(1.0-eta)*(-2.*xi-2.*eta+1.)\n func8(2)= xi*(1.0-eta)*(2.*xi-2.*eta-1.)\n func8(3)= xi*eta*(2.*xi+2.*eta-3.)\n func8(4)= (1.0-xi)*eta*(-2.*xi+2.*eta-1.)\n func8(5)= 4.*(1.-eta)*(1.-xi)*xi\n func8(6)= 4.*eta*(1.-eta)*xi\n func8(7)= 4.*(1.-xi)*xi*eta\n func8(8)= 4.*(1.-eta)*(1.-xi)*eta\n RETURN\n END SUBROUTINE MapBaseFunc8\n!***************************************************************************\n\n\n!!!!!!!!!!!!orientation!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!# 4---------7--------3\n! | |\n! | |\n! 8 6\n! | |\n! | |\n! | |\n! 1---------5--------2\n!****************************************************************\n SUBROUTINE MAPDER_8_NODE\n USE setup2d\n IMPLICIT NONE\n \n\n INTEGER\t:: IS,JS,IFP,JFP\n double precision :: psi, eta\n ! compute the derivatives at the solution points\n do js=1,N\n do is=1,N\n psi = Xs(is)\n eta = Xs(js)\n !\n dmdxs(1,1,is,js) = &\n (1.0-eta)*(4.*psi+2.*eta-3.)\n dmdxs(1,2,is,js) = &\n (1.0-psi) * (4.*eta+2.*psi-3)\n\n dmdxs(2,1,is,js) = &\n (1.0-eta) * (4.*psi - 2.*eta -1.)\n dmdxs(2,2,is,js) = &\n psi * (4.*eta - 2.*psi -1.)\n !\n dmdxs(3,1,is,js) = &\n eta * (4.*psi + 2.*eta -3.)\n dmdxs(3,2,is,js) = &\n psi * (4.*eta + 2.*psi -3.)\n !\n dmdxs(4,1,is,js) = &\n eta * (4.*psi -2.*eta -1.)\n dmdxs(4,2,is,js) = &\n (1.-psi)*(4.*eta - 2.*psi -1.)\n !\n dmdxs(5,1,is,js) = 4.*(1.-eta)*(1.-2.*psi)\n dmdxs(5,2,is,js) = 4.*psi*(psi-1.)\n !\n dmdxs(6,1,is,js) = 4.*eta*(1.-eta)\n dmdxs(6,2,is,js) = 4.*psi*(1.-2.*eta)\n !\n dmdxs(7,1,is,js) = 4.*eta*(1.-2.*psi)\n dmdxs(7,2,is,js) = 4.*psi*(1.-psi)\n !\n dmdxs(8,1,is,js) = 4.*eta*(eta-1.)\n dmdxs(8,2,is,js) = 4.*(1.-psi)*(1.-2.*eta)\n end do\n end do\n\n !\t% compute the derivatives at the flux points (family 1)\n do jfp=1,N\n do ifp=1,N+1\n !\n psi = Xf(ifp)\n eta = Xs(jfp)\n !\n dmdxf1(1,1,ifp,jfp) = (1.0-eta)*(4.*psi+2.*eta-3.)\n dmdxf1(1,2,ifp,jfp) = (1.0-psi) * (4.*eta+2.*psi-3)\n\n dmdxf1(2,1,ifp,jfp) = &\n (1.0-eta) * (4.*psi - 2.*eta -1.)\n dmdxf1(2,2,ifp,jfp) = &\n psi * (4.*eta - 2.*psi -1.)\n !\n dmdxf1(3,1,ifp,jfp) = &\n eta * (4.*psi + 2.*eta -3.)\n dmdxf1(3,2,ifp,jfp) = &\n psi * (4.*eta + 2.*psi -3.)\n !\n dmdxf1(4,1,ifp,jfp) = &\n eta * (4.*psi -2.*eta -1.)\n dmdxf1(4,2,ifp,jfp) = (1.-psi)*(4.*eta - 2.*psi -1.)\n\n dmdxf1(5,1,ifp,jfp) = 4.*(1.-eta)*(1.-2.*psi)\n dmdxf1(5,2,ifp,jfp) = 4.*psi*(psi-1.)\n\n dmdxf1(6,1,ifp,jfp) = &\n 4.*eta*(1.-eta)\n dmdxf1(6,2,ifp,jfp) = &\n 4.*psi*(1.-2.*eta)\n\n dmdxf1(7,1,ifp,jfp) = &\n 4.*eta*(1.-2.*psi)\n dmdxf1(7,2,ifp,jfp) = &\n 4.*psi*(1.-psi)\n\n dmdxf1(8,1,ifp,jfp) = &\n 4.*eta*(eta-1.)\n dmdxf1(8,2,ifp,jfp) = &\n 4.*(1.-psi)*(1.-2.*eta)\n !\n end do\n end do\n !\n ! compute the derivatives at the flux points (family 2)\n\n do jfp=1,N+1\n do ifp=1,N\n psi = Xs(ifp)\n eta = Xf(jfp)\n dmdxf2(1,1,ifp,jfp) = &\n (1.0-eta)*(4.*psi+2.*eta-3.)\n dmdxf2(1,2,ifp,jfp) = &\n (1.0-psi) * (4.*eta+2.*psi-3)\n !\n dmdxf2(2,1,ifp,jfp) = &\n (1.0-eta) * (4.*psi - 2.*eta -1.)\n dmdxf2(2,2,ifp,jfp) = &\n psi * (4.*eta - 2.*psi -1.)\n !\n dmdxf2(3,1,ifp,jfp) = &\n eta * (4.*psi + 2.*eta -3.)\n dmdxf2(3,2,ifp,jfp) = &\n psi * (4.*eta + 2.*psi -3.)\n !\n dmdxf2(4,1,ifp,jfp) = &\n eta * (4.*psi -2.*eta -1.)\n dmdxf2(4,2,ifp,jfp) = (1.-psi)*(4.*eta - 2.*psi -1.)\n\n dmdxf2(5,1,ifp,jfp) = 4.*(1.-eta)*(1.-2.*psi)\n dmdxf2(5,2,ifp,jfp) = 4.*psi*(psi-1.)\n\n dmdxf2(6,1,ifp,jfp) = 4.*eta*(1.-eta)\n dmdxf2(6,2,ifp,jfp) = 4.*psi*(1.-2.*eta)\n\n dmdxf2(7,1,ifp,jfp) = &\n 4.*eta*(1.-2.*psi)\n dmdxf2(7,2,ifp,jfp) = &\n 4.*psi*(1.-psi)\n\n dmdxf2(8,1,ifp,jfp) = &\n 4.*eta*(eta-1.)\n dmdxf2(8,2,ifp,jfp) = &\n 4.*(1.-psi)*(1.-2.*eta)\n !\n end do\n end do\n\n END SUBROUTINE MAPDER_8_NODE\n\n SUBROUTINE xyCoor_atGps(ns,xxs,xi,eta,xx)\n IMPLICIT NONE\n integer,intent(in)::ns\n integer :: i,nb\n double precision :: xxs(2,ns),xx(2),xi,eta\n double precision,pointer,dimension(:)::func\n allocate(func(ns))\n if(ns==4) call MapBaseFunc(func,xi,eta)\n if(ns==8) call MapBaseFunc8(func,xi,eta)\n\n do i=1,2\n xx(i)= 0.d0\n do nb = 1,ns\n xx(i) = xx(i)+xxs(i,nb)*func(nb)\n end do\n end do\n deallocate(func)\n return\n END SUBROUTINE xyCoor_atGps", "meta": {"hexsha": "7024e041b9f7f9151b2bca4ca6ec8495f30ef0c6", "size": 7353, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mapder.f90", "max_stars_repo_name": "chenkuangxu/CHORUS-MHD", "max_stars_repo_head_hexsha": "729b72439ddd368a16c14f60543cc392f167164d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "mapder.f90", "max_issues_repo_name": "chenkuangxu/CHORUS-MHD", "max_issues_repo_head_hexsha": "729b72439ddd368a16c14f60543cc392f167164d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "mapder.f90", "max_forks_repo_name": "chenkuangxu/CHORUS-MHD", "max_forks_repo_head_hexsha": "729b72439ddd368a16c14f60543cc392f167164d", "max_forks_repo_licenses": ["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.9340659341, "max_line_length": 77, "alphanum_fraction": 0.4037807698, "num_tokens": 2956, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422644, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6803085811207763}} {"text": "module multiple_values\nimplicit none\ntype res\n integer :: p, m\nend type\n\ncontains\n\nfunction addsub(x,y) result(r)\n integer :: x, y\n type(res) :: r\n r%p = x+y\n r%m = x-y\nend function\nend module\n\nprogram main\n use multiple_values\n print *, addsub(33, 22)\nend program\n", "meta": {"hexsha": "041193dd63c7fb1b963cacbb46a174b9c8aa4204", "size": 272, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Return-multiple-values/Fortran/return-multiple-values.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/Return-multiple-values/Fortran/return-multiple-values.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/Return-multiple-values/Fortran/return-multiple-values.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": 12.9523809524, "max_line_length": 30, "alphanum_fraction": 0.6838235294, "num_tokens": 87, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.680308568360131}} {"text": "program cdf2pdf\n!\n! Purpose: To evaluate the empirical probability density function\n! starting from a cumulative distribution function. \n!\n! Notes: \n! - Forward differentiation is the best choice?\n!\n! Record of revisions:\n! Date Who Description\n! ========== =============== =====================================\n! 9-12-2011 ThMosqueiro Original code.\n!\n!\n\n implicit none\n\n character(len=100) :: bugger, inputfile, outputfile\n\n! Volatile variables\n real(8) :: x, xold, cdf, cdfold\n\n\n! Purely auxiliary variables\n integer :: Reason\n \n\n\n! Reading input file name into inputfile variable.\n call getarg(1, bugger)\n read(bugger,*) inputfile\n\n! Openning as read-only the inputfile\n open(unit=27, file=inputfile, action=\"read\", status=\"old\")\n\n! Reading output file name into outputfile variable.\n call getarg(2, bugger)\n read(bugger,*) outputfile\n\n! Openning as read-only the inputfile\n open(unit=37, file=outputfile, action=\"write\", status=\"new\") \n\n read(27, *) xold, cdfold\n\n! Now read every line of the file and evaluate its contribution to\n! the entropy.\n do\n read(27, *, IOSTAT=Reason) x, cdf\n\n if ( Reason .lt. 0 ) then\n close(27)\n close(37)\n exit \n else\n \n write(37,*) xold, -(cdf - cdfold)/(x - xold)\n \n xold = x\n cdfold = cdf\n\n end if\n \n end do\n\n stop\nend program cdf2pdf\n", "meta": {"hexsha": "16d0f1093537fb466c1a1e5ec435635daa1d9136", "size": 1440, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gen_programs/cdf2pdf.f90", "max_stars_repo_name": "thmosqueiro/Probab-Greenberg-Hastings", "max_stars_repo_head_hexsha": "9702e6c981e0833bc148b4e0e0cf2db99005657d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2015-05-21T19:11:28.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-03T23:19:37.000Z", "max_issues_repo_path": "gen_programs/cdf2pdf.f90", "max_issues_repo_name": "thmosqueiro/Probab-Greenberg-Hastings", "max_issues_repo_head_hexsha": "9702e6c981e0833bc148b4e0e0cf2db99005657d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gen_programs/cdf2pdf.f90", "max_forks_repo_name": "thmosqueiro/Probab-Greenberg-Hastings", "max_forks_repo_head_hexsha": "9702e6c981e0833bc148b4e0e0cf2db99005657d", "max_forks_repo_licenses": ["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.4925373134, "max_line_length": 71, "alphanum_fraction": 0.5951388889, "num_tokens": 391, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680904463333, "lm_q2_score": 0.7931059609645724, "lm_q1q2_score": 0.6803009856581854}} {"text": "\nprogram main_heat1\n\n use heat_solvers, only: solve_heat_explicit\n use problem, only: k, u_true\n implicit none\n integer :: n, i, nsteps\n real(kind=8) :: error_max, dx, pi, tfinal, t0\n real(kind=8), dimension(:), allocatable :: x, u, ustar, u0\n\n pi = acos(-1.d0)\n\n open(unit=21, file='input_data.txt', status='old')\n read(21,*) n\n read(21,*) k\n read(21,*) tfinal\n read(21,*) nsteps\n print '(\"n = \",i6)', n\n print '(\"k = \",i6)', k\n print '(\"tfinal = \",f7.4)', tfinal\n print '(\"nsteps = \",i6)', nsteps\n\n allocate(x(0:n+1), u(0:n+1), ustar(0:n+1), u0(0:n+1))\n\n t0 = 0.d0\n dx = pi / (n+1)\n do i=0,n+1\n x(i) = i*dx\n enddo\n\n\n do i=0,n+1\n u0(i) = sin(k*x(i))\n ustar(i) = u_true(x(i), tfinal)\n enddo\n\n\n call solve_heat_explicit(x, u0, t0, tfinal, nsteps, u)\n\n\n error_max = 0.d0\n do i=0,n+1\n ustar(i) = u_true(x(i), tfinal)\n error_max = max(error_max, abs(u(i) - ustar(i)))\n enddo\n\n print '(\"error_max = \", e13.6)', error_max\n\n open(unit=22, file='solution.txt', status='unknown')\n do i=0,n+1\n write(22,220) x(i), u(i), ustar(i)\n220 format(3e22.14)\n enddo\n\n close(22)\n\nend program main_heat1\n", "meta": {"hexsha": "6eae9debaa793e68e494a2b728b43f0efd505e08", "size": 1240, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/homeworks/project/part2/main1.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/homeworks/project/part2/main1.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/homeworks/project/part2/main1.f90", "max_forks_repo_name": "philipwangdk/HPC", "max_forks_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.3793103448, "max_line_length": 62, "alphanum_fraction": 0.5330645161, "num_tokens": 466, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182186, "lm_q2_score": 0.7931059487389968, "lm_q1q2_score": 0.6803009809388523}} {"text": "module NewtSolve\n use Deriv\n use FuncIfaces\n use LseSolvers\n use IO\n implicit none\n \n type :: Ncube\n integer :: dimen\n integer, allocatable :: bdir(:)\n real(mpc),allocatable :: vertex(:)\n real(mpc) :: edge\n end type Ncube\n\ncontains\n \n !-----------------------------------------------------------------------\n ! newtitsolve (f) -> x\n ! f: \\R^n \\to \\R^n\n ! x0 : initial value\n ! N_max : max iterations number\n ! \tsolves nonlinear system iteratively using Newton's method\n !-----------------------------------------------------------------------\n function newtitsolve(f, x0, N_max, report_fd) result(root)\n ! NOTE: \u043f\u043e \u043f\u043e\u0432\u043e\u0434\u0443 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432 :\n !+ \u043c\u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043b\u0443\u0447\u0448\u0435, \u0435\u0441\u043b\u0438 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b (FuncIfaces)\n !+ \u0431\u0443\u0434\u0443\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u043e\u0442 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 (Samples).\n ! \u041f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435, \u0431\u043e\u043b\u044c\u0448\u0435 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a, \u0447\u0442\u043e \u0432\u0441\u0451 \u0445\u043e\u0440\u043e\u0448\u043e.\n procedure (fRnRn) :: f\n real(mpc), dimension(:) :: x0\n integer :: N_max\n intent(in) :: x0, N_max\n real(mpc), dimension(size(x0)) :: root\n integer, optional :: report_fd\n\n integer :: n, i\n\n real(mpc), dimension(:), allocatable :: x, x_prev\n real(mpc), dimension(:, :), allocatable :: exmtx ! \u0435\u0441\u043b\u0438 \u0432\u0434\u0440\u0443\u0433 \u0432 \u0441\u0442\u0435\u043a \u043d\u0435 \u0432\u043b\u0435\u0437\u0435\u0442..\n n = size(x0)\n \n allocate(x(n), x_prev(n), exmtx(n, n+1)) \n x_prev = huge(1.0_mpc)\n x = x0\n i = 1\n do while (i < N_max .and. norm2(x - x_prev) > sqrt(eps))\n if (present (report_fd)) write(report_fd,*) x, norm2(x-x_prev)\n x_prev = x\n exmtx(1:n, 1:n) = jacobimtx(f, x)\n exmtx(:, n+1) = -f(x) \n x = gauss_solve(exmtx) ! \u0440\u0435\u0448\u0430\u0435\u0442 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u043d\u043e\u0441\u0442\u0438\n x = x + x_prev\n i = i+ 1\n end do\n\n root = x\n deallocate(x, x_prev, exmtx)\n end function newtitsolve\n\n function halfdivsolve(f,x0,ini_offset,N_max,report_fd) result(root)\n procedure (fRnRn) :: f\n real(mpc), dimension(:) :: x0\n real(mpc) :: ini_offset\n integer :: N_max\n integer, optional :: report_fd\n intent(in) :: x0, N_max, ini_offset\n \n real(mpc), dimension(size(x0)) :: root, newvert, rootdir\n type(Ncube) :: solvcube\n integer :: direction(size(x0)), D,i, j\n \n D = size(x0)\n forall (i = 1:D)\n direction(i) = 1\n end forall\n\n allocate(solvcube%bdir(D))\n allocate(solvcube%vertex(D))\n solvcube = Ncube (&\n &dimen = D,&\n &bdir = direction,&\n &vertex = x0 - ini_offset,&\n &edge = 2*ini_offset)\n\n! solvcube%dimen = D\n! solvcube%bdir = direction\n! solvcube%vertex = x0 - ini_offset\n! solvcube%edge = 2*ini_offset\n \n rootdir = -f(solvcube%vertex)\n \n associate (x=>solvcube%vertex)\n \n i = 0\n do while (i < N_max .and. norm2(rootdir) > sqrt(eps))\n\n if(present(report_fd)) write(report_fd,*) x \n\n solvcube%edge = solvcube%edge / 2.0_mpc\n x = x + solvcube%edge * solvcube%bdir\n rootdir = -f(x)\n do j = 1, D\n if (abs(rootdir(j)) < eps) then\n solvcube%bdir(j) = 0\n else\n solvcube%bdir(j) = int(rootdir(j)/abs(rootdir(j)))\n end if\n end do\n i = i + 1\n\n end do\n\n end associate\n root = solvcube%vertex\n \n deallocate(solvcube%bdir)\n deallocate(solvcube%vertex)\n end function halfdivsolve\n \n function bisectsolve(f, x0, ini_offset, N_max, report_fd) result(root)\n procedure (fRnR1) :: f\n real(mpc), dimension(:) :: x0\n real(mpc) :: ini_offset\n integer :: N_max, i \n integer, optional :: report_fd\n intent(in) :: x0, N_max, ini_offset\n real(mpc), dimension(size(x0)):: left, right, mid, root\n left = x0 - ini_offset; right = x0 + ini_offset\n\n if (f(left)*f(right) > 0) stop 'unable to solve'\n\n\n i=0\n do while (i < N_max .and. norm2(left - right) > sqrt(eps))\n mid = 0.5*(left + right)\n if (f(mid)*f(left) > 0) then \n left = mid\n else\n right = mid\n endif\n i = i+1\n end do\n root = 0.5*(left+right)\n end function bisectsolve\n\n! function bisectsolve(f, x0, ini_offset, N_max, report_fd) result()\n! procedure (fRnR1) :: f\n! real(mpc), dimension(:) :: x0\n! real(mpc) :: ini_offset\n! integer :: N_max, n, k\n! integer, optional :: report_fd\n! intent(in) :: x0, N_max, ini_offset\n! real(mpc), dimension(size(x0)):: left, right, mid, root\n!\n! n = size(x0)\n! do k = 1, n\n!\n! end do\n!\n!\n! end function bisectsolve\n function broydenitsolve(f, x0, N_max, report_fd) result(root)\n ! NOTE: \u043f\u043e \u043f\u043e\u0432\u043e\u0434\u0443 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432 :\n !+ \u043c\u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043b\u0443\u0447\u0448\u0435, \u0435\u0441\u043b\u0438 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b (FuncIfaces)\n !+ \u0431\u0443\u0434\u0443\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u043e\u0442 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 (Samples).\n ! \u041f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435, \u0431\u043e\u043b\u044c\u0448\u0435 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a, \u0447\u0442\u043e \u0432\u0441\u0451 \u0445\u043e\u0440\u043e\u0448\u043e.\n procedure (fRnRn) :: f\n real(mpc), dimension(:) :: x0\n integer :: N_max\n intent(in) :: x0, N_max\n real(mpc), dimension(size(x0)) :: root\n integer, optional :: report_fd\n\n integer :: n, i\n\n real(mpc), dimension(:), allocatable :: xc, xp, fc, fp\n real(mpc), dimension(:, :), allocatable :: exmtx ! \u0435\u0441\u043b\u0438 \u0432\u0434\u0440\u0443\u0433 \u0432 \u0441\u0442\u0435\u043a \u043d\u0435 \u0432\u043b\u0435\u0437\u0435\u0442..\n n = size(x0)\n allocate(xc(n), xp(n), exmtx(n, n+1), fc(n), fp(n)) \n associate (J=>exmtx(1:n,1:n), B=>exmtx(:,n+1))\n xp = x0\n! if (present(report_fd)) write(report_fd,*) xp\n fp = f(x0)\n J = jacobimtx(f, xp)\n call prarr(J)\n B = -fp\n xc = gauss_solve(exmtx) + xp\n i = 1\n do while (i < N_max .and. norm2(xc - xp) > eps)\n if (present (report_fd)) write(report_fd,*) xc, norm2(f(xc))\n fc = f(xc) \n J = J + dyad_product(((fc-fp) - matmul(J,(xc-xp)))/norm2(xc-xp)**2,xc-xp) \n B = -fc \n xp = xc\n fp = fc\n xc = gauss_solve(exmtx) + xp! \u0440\u0435\u0448\u0430\u0435\u0442 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u043d\u043e\u0441\u0442\u0438\n i = i + 1\n end do\n end associate\n root = xc\n deallocate(xc, xp, fc,fp, exmtx)\n end function broydenitsolve\n \nend module NewtSolve\n", "meta": {"hexsha": "befc2bb8bb290209747ac8df54a605b2c2e67459", "size": 6543, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/solvers/Newtlike.f90", "max_stars_repo_name": "taxus-d/integrators", "max_stars_repo_head_hexsha": "90464d4994298343b70c10682a07183e391a18e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/solvers/Newtlike.f90", "max_issues_repo_name": "taxus-d/integrators", "max_issues_repo_head_hexsha": "90464d4994298343b70c10682a07183e391a18e3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/solvers/Newtlike.f90", "max_forks_repo_name": "taxus-d/integrators", "max_forks_repo_head_hexsha": "90464d4994298343b70c10682a07183e391a18e3", "max_forks_repo_licenses": ["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.9170731707, "max_line_length": 88, "alphanum_fraction": 0.5068011615, "num_tokens": 1993, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.7879311956428946, "lm_q1q2_score": 0.6802931890939681}} {"text": "C ****************************************************************************\nC FILE: mpi_prime.f\nC DESCRIPTION:\nC Generates prime numbers. All tasks distribute the work evenly, taking\nC every nth number, where n is the stride computed as: (rank *2) + 1\nC so that even numbers are automatically skipped. The method of using\nC stride is preferred over contiguous blocks of numbers, since numbers\nC in the higher range require more work to compute and may result in\nC load imbalance. This program demonstrates embarrassing parallelism.\nC Collective communications calls are used to reduce the only two data\nC elements requiring communications: the number of primes found and\nC the largest prime.\nC AUTHOR: Blaise Barney 11/25/95 - adapted from version contributed by \nC Richard Ng & Wong Sze Cheong during MHPCC Singapore Workshop (8/22/95).\nC LAST REVISED: 04/02/05\nC ****************************************************************************\nC Explanation of constants and variables\nC LIMIT = Increase this to find more primes \nC FIRST = Rank of first task \nC ntasks = total number of tasks in partitiion \nC rank = task identifier \nC n = loop variable \nC pc = prime counter\nC pcsum = number of primes found by all tasks \nC foundone = most recent prime found \nC maxprime = largest prime found \nC mystart = where to start calculating \nC stride = calculate every nth number\n\n program prime\n include 'mpif.h'\n\n integer LIMIT, FIRST\n parameter(LIMIT=2500000) \n parameter(FIRST=0)\n\n integer ntasks, rank, ierr, n, pc, pcsum, foundone, maxprime,\n & mystart, stride\n double precision start_time, end_time\n logical result\n\n call MPI_INIT(ierr)\n call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)\n call MPI_COMM_SIZE(MPI_COMM_WORLD, ntasks, ierr)\n if ((mod(ntasks,2).ne.0) .or. (mod(LIMIT,ntasks).ne.0)) then\n print *, mod(ntasks,2), mod(LIMIT,ntasks)\n print *,'Sorry -this exercise requires an even number of '\n print *,'processors evenly divisible into ',LIMIT,'.' \n print *,'Try 4 or 8.'\n call MPI_FINALIZE(ierr)\n stop\n endif\n\nC Initializations: mystart must be odd number. stride is multiplied\nC by 2 to skip over even numbers. \n start_time = MPI_WTIME()\n mystart = (rank*2) + 1\n stride = ntasks*2\n pc = 0\n foundone = 0\n\nC ------------------- task with rank 0 does this part ------------------\n if (rank .eq. FIRST) then\n print *,'Using',ntasks,'tasks to scan',LIMIT,'numbers'\nC Assume first four primes are counted here\n pc = 4\n do n=mystart,LIMIT,stride\n call isprime(n,result)\n if (result .eqv. .true.) then\n pc = pc + 1\n foundone = n\nC ***** Optional: print each prime as it is found\nC print *, foundone\nC *****\n endif\n enddo\n call MPI_Reduce(pc,pcsum,1,MPI_INTEGER,MPI_SUM,FIRST,\n & MPI_COMM_WORLD,ierr)\n call MPI_Reduce(foundone,maxprime,1,MPI_INTEGER,MPI_MAX,\n & FIRST,MPI_COMM_WORLD,ierr)\n end_time=MPI_WTIME()\n print *,'Done. Largest prime is ',maxprime,' Total primes ',pcsum\n print *,'Wallclock time elapsed: ' ,end_time-start_time\n endif\n\nC ------------------- all other tasks do this part ---------------------\n if (rank .gt. FIRST) then\n do n=mystart,LIMIT,stride\n call isprime(n,result)\n if (result .eqv. .true.) then\n pc = pc + 1\n foundone = n\nC ***** Optional: print each prime as it is found\nC print *, foundone\nC *****\n endif\n enddo\n call MPI_Reduce(pc,pcsum,1,MPI_INTEGER,MPI_SUM,FIRST,\n & MPI_COMM_WORLD,ierr)\n call MPI_Reduce(foundone,maxprime,1,MPI_INTEGER,MPI_MAX,\n & FIRST,MPI_COMM_WORLD,ierr)\n endif\n\n\n call MPI_FINALIZE(ierr)\n end\n\n\n subroutine isprime (n,result)\n integer n\n logical result\n integer i, squareroot\n real*4 realn\n if (n .gt. 10) then\n realn = real(n)\n squareroot = int (sqrt(realn))\n do i=3,squareroot,2\n if (mod(n,i) .eq. 0) then\n result = .false.\n return\n endif\n enddo\n result = .true.\n return \nC Assume first four primes are counted elsewhere. Forget everything else\n else \n result = .false.\n return\n endif\n end\n", "meta": {"hexsha": "7c4ad1c3b3e50e4a48880ade21b9f5ee82c3c872", "size": 4801, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "examples/mpi/LLNL_Blaise_Barney/mpi_prime.f", "max_stars_repo_name": "Fulayjan/ams250", "max_stars_repo_head_hexsha": "e72ab59a5f924728e69b46e2974914a2d3cab4c1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2018-05-01T20:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-06T18:43:27.000Z", "max_issues_repo_path": "examples/mpi/LLNL_Blaise_Barney/mpi_prime.f", "max_issues_repo_name": "Fulayjan/ams250", "max_issues_repo_head_hexsha": "e72ab59a5f924728e69b46e2974914a2d3cab4c1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-05-01T04:06:01.000Z", "max_issues_repo_issues_event_max_datetime": "2018-05-01T04:06:01.000Z", "max_forks_repo_path": "examples/mpi/LLNL_Blaise_Barney/mpi_prime.f", "max_forks_repo_name": "shawfdong/ams250", "max_forks_repo_head_hexsha": "e72ab59a5f924728e69b46e2974914a2d3cab4c1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-06-03T22:37:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-07T01:52:07.000Z", "avg_line_length": 36.6488549618, "max_line_length": 78, "alphanum_fraction": 0.5567590085, "num_tokens": 1153, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916205190224, "lm_q2_score": 0.787931188173138, "lm_q1q2_score": 0.6802931854142844}} {"text": "! compile: gfortran -o planets planets.f90 standish_module.o\r\nProgram Planets\r\n Use standish\r\n Implicit None\r\n Real (8) :: Julian, PV (6), QV (6), P (9, 6)\r\n Integer :: I, J, ITBL\r\n!\r\n Write (*,*) \"Approximate Positions of the Major Planets\"\r\n Write (*,*) \"Enter Julian (TT), eg 2451545.0\"\r\n Read (*,*) Julian\r\n Write (*,*)\r\n!\r\n\t! Compute Positions\r\n!\r\n Do J = 1, 9\r\n Call Helio (J, Julian, PV, ITBL)\r\n P (J, :) = PV\r\n End Do\r\n\t\r\n\t! Report Results\r\n!\r\n Call Title\r\n Write (*, '(A,F12.3)') \"Heliocentric Ecliptic Coordinates (J2000)&\r\n & Julian (TT)\", Julian\r\n Write (*,*) \"Planet X Y Z VX VY VZ \"\r\n\t Write (*,*) \" Position (AU) Velocity (KPS)\" \r\n Do J = 1, 9\r\n Write (*, '(A10, 3F9.3,3F9.4)') eph(1)%name(J), P (J, 1:3), s_KPS * P (J, 4:6)\r\n End Do\r\n!\r\n Write (*,*)\r\n Write (*, '(A,F12.3)') \"Heliocentric Equatorial Coordinates (ICRF&\r\n &) Julian (TT)\", Julian\r\n Write (*,*) \"Planet X Y Z VX VY VZ \"\r\n\t Write (*,*) \" Position (AU) Velocity (KPS)\" \r\n Do J = 1, 9\r\n Call ec2eq (P(J, :), QV)\r\n Write (*, '(A10, 3F9.3,3F9.4)') eph(1)%name(J), QV (1:3), s_KPS * QV (4:6)\r\n End Do\r\n\t Write (*,*)\r\n! +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\r\n! Copyright 2018 Cumulo Epsilon (epsilon0167) (GPG Key ID 8F126A52)\r\n\r\n! Redistribution and use in source and binary forms, with or without \r\n! modification, are permitted provided that the following conditions are met:\r\n\r\n! 1. Redistributions of source code must retain the above copyright \r\n! notice, this list of conditions and the following disclaimer.\r\n\r\n! 2. Redistributions in binary form must reproduce the above copyright \r\n! notice, this list of conditions and the following disclaimer in the \r\n! documentation and/or other materials provided with the distribution.\r\n\r\n! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r\n ! \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \r\n ! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS \r\n ! FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r\n ! COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r\n ! INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, \r\n ! BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; \r\n ! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER \r\n ! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT \r\n ! LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING \r\n ! IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF \r\n ! THE POSSIBILITY OF SUCH DAMAGE.\r\n! +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\r\n\t\r\nEnd Program\r\n\r\n! EAXMPLE OUTPUT\r\n!\r\n ! Approximate Positions of the Major Planets\r\n ! Method and Data from E. M. Standish, JPL/CalTech\r\n ! Keplerian Elements Valid 3000 BC - 3000 AD. \r\n ! (http://ssd.jpl.nasa.gov/txt/aprx_pos_planets.pdf)\r\n ! Planetary Ephemeris Module V1 2018 \r\n\r\n! Heliocentric Ecliptic Coordinates (J2000) Julian (TT) 2451545.000\r\n ! Planet X Y Z VX VY VZ \r\n ! Position (AU) Velocity (KPS)\r\n ! Mercury -0.130 -0.447 -0.025 36.9955 -11.1645 -4.3077\r\n ! Venus -0.718 -0.033 0.041 1.3832 -35.1403 -0.5601\r\n ! Earth -0.177 0.967 -0.000 -29.7870 -5.4789 0.0000\r\n ! Mars 1.391 -0.013 -0.034 1.1646 26.2975 0.5223\r\n ! Jupiter 3.998 2.946 -0.102 -7.9127 11.1382 0.1311\r\n ! Saturn 6.415 6.546 -0.369 -7.4126 6.7409 0.1773\r\n ! Uranus 14.425 -13.738 -0.238 4.6433 4.6120 -0.0431\r\n ! Neptune 16.805 -24.993 0.127 4.4730 3.0619 -0.1661\r\n ! Pluto -9.883 -27.964 5.851 5.2496 -2.6734 -1.2323\r\n\r\n! Heliocentric Equatorial Coordinates (ICRF) Julian (TT) 2451545.000\r\n ! Planet X Y Z VX VY VZ \r\n ! Position (AU) Velocity (KPS)\r\n ! Mercury -0.130 -0.401 -0.200 36.9955 -8.5297 -8.3932\r\n ! Venus -0.718 -0.046 0.025 1.3832 -32.0178 -14.4919\r\n ! Earth -0.177 0.887 0.385 -29.7870 -5.0268 -2.1794\r\n ! Mars 1.391 0.001 -0.037 1.1646 23.9198 10.9397\r\n ! Jupiter 3.998 2.743 1.078 -7.9127 10.1669 4.5508\r\n ! Saturn 6.415 6.152 2.265 -7.4126 6.1141 2.8440\r\n ! Uranus 14.425 -12.509 -5.683 4.6433 4.2485 1.7950\r\n ! Neptune 16.805 -22.981 -9.825 4.4730 2.8753 1.0655\r\n ! Pluto -9.883 -27.984 -5.755 5.2496 -1.9626 -2.1940\r\n\r\n \r\n! DE430 RESULTS\r\n ! DE430 Ephemeris (taken as authoritative)\r\n\r\n! Heliocentric Ecliptic Coordinates (J2000) Julian (TT) 2451545.000\r\n ! Planet X Y Z VX VY VZ \r\n ! Mercury -0.130 -0.447 -0.025 36.9950 -11.1644 -4.3076\r\n ! Venus -0.718 -0.033 0.041 1.3819 -35.1403 -0.5600\r\n ! Earth -0.177 0.967 -0.000 -29.7943 -5.4693 0.0002\r\n ! Mars 1.391 -0.013 -0.034 1.1627 26.2961 0.5223\r\n ! Jupiter 4.001 2.939 -0.102 -7.9098 11.1561 0.1309\r\n ! Saturn 6.406 6.570 -0.369 -7.4320 6.7359 0.1783\r\n ! Uranus 14.432 -13.734 -0.238 4.6370 4.6277 -0.0429\r\n ! Neptune 16.812 -24.992 0.127 4.4659 3.0766 -0.1661\r\n ! Pluto -9.875 -27.959 5.850 5.2442 -2.6626 -1.2331\r\n\r\n! Heliocentric Equatorial Coordinates (ICRF) Julian (TT) 2451545.000\r\n ! Planet X Y Z VX VY VZ \r\n ! Mercury -0.130 -0.401 -0.200 36.9950 -8.5297 -8.3931\r\n ! Venus -0.718 -0.046 0.025 1.3819 -32.0178 -14.4918\r\n ! Earth -0.177 0.887 0.385 -29.7943 -5.0181 -2.1754\r\n ! Mars 1.391 0.001 -0.037 1.1627 23.9184 10.9392\r\n ! Jupiter 4.001 2.737 1.076 -7.9098 10.1835 4.5577\r\n ! Saturn 6.406 6.175 2.275 -7.4320 6.1092 2.8429\r\n ! Uranus 14.432 -12.506 -5.682 4.6370 4.2629 1.8014\r\n ! Neptune 16.812 -22.980 -9.824 4.4659 2.8888 1.0715\r\n ! Pluto -9.875 -27.979 -5.754 5.2442 -1.9524 -2.1905\r\n", "meta": {"hexsha": "364083d50e0a9056a9a2e9234e25a94dfacfbaba", "size": 6414, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Standish2018v1.0/planets.f90", "max_stars_repo_name": "CumuloEpsilon/Standish-Ephemeris", "max_stars_repo_head_hexsha": "7253390bf1f8abd4ff5c48f43c9617c7bfeefe53", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2018-02-03T02:17:25.000Z", "max_stars_repo_stars_event_max_datetime": "2018-04-04T00:59:27.000Z", "max_issues_repo_path": "Standish2018v1.0/planets.f90", "max_issues_repo_name": "CumuloEpsilon/Standish-Ephemeris", "max_issues_repo_head_hexsha": "7253390bf1f8abd4ff5c48f43c9617c7bfeefe53", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2018-02-07T16:33:30.000Z", "max_issues_repo_issues_event_max_datetime": "2018-03-10T22:29:11.000Z", "max_forks_repo_path": "Standish2018v1.0/planets.f90", "max_forks_repo_name": "CumuloEpsilon/Standish-Ephemeris", "max_forks_repo_head_hexsha": "7253390bf1f8abd4ff5c48f43c9617c7bfeefe53", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-09-27T19:48:57.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-27T19:48:57.000Z", "avg_line_length": 48.9618320611, "max_line_length": 85, "alphanum_fraction": 0.5405363268, "num_tokens": 2388, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391602943619, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.6802931823149512}} {"text": "! Algebra routines\n!\n! ------------------------------------------------------------------------------\n! Copyright (c) 2009-13, Thomas P. Robitaille\n!\n! All rights reserved.\n!\n! Redistribution and use in source and binary forms, with or without\n! modification, are permitted provided that the following conditions are met:\n!\n! * Redistributions of source code must retain the above copyright notice, this\n! list of conditions and the following disclaimer.\n!\n! * Redistributions in binary form must reproduce the above copyright notice,\n! this list of conditions and the following disclaimer in the documentation\n! and/or other materials provided with the distribution.\n!\n! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n! DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\n! FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n! DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n! SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\n! OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n! OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n! ------------------------------------------------------------------------------\n\nmodule lib_algebra\n\n implicit none\n save\n\n private\n\n integer,parameter :: sp = selected_real_kind(p=6,r=37)\n integer,parameter :: dp = selected_real_kind(p=15,r=307)\n\n public :: cbrt\n interface cbrt\n module procedure cbrt_sp\n module procedure cbrt_dp\n end interface cbrt\n\n public :: quadratic\n interface quadratic\n module procedure quadratic_sp\n module procedure quadratic_dp\n end interface quadratic\n\n public :: quadratic_reduced\n interface quadratic_reduced\n module procedure quadratic_reduced_sp\n module procedure quadratic_reduced_dp\n end interface quadratic_reduced\n\n public :: quadratic_pascal\n interface quadratic_pascal\n module procedure quadratic_pascal_sp\n module procedure quadratic_pascal_dp\n end interface quadratic_pascal\n\n public :: quadratic_pascal_reduced\n interface quadratic_pascal_reduced\n module procedure quadratic_pascal_reduced_sp\n module procedure quadratic_pascal_reduced_dp\n end interface quadratic_pascal_reduced\n\n public :: lineq_gausselim\n interface lineq_gausselim\n module procedure lineq_gausselim_sp\n module procedure lineq_gausselim_dp\n end interface lineq_gausselim\n\ncontains\n\n !!@FOR real(sp):sp real(dp):dp\n\n @T function cbrt_(x)\n implicit none\n @T :: x\n @T,parameter :: alpha = 1._ / 3._\n if(x >= 0.) then\n cbrt_ = x**alpha\n else\n cbrt_ = - (abs(x))**alpha\n end if\n end function cbrt_\n\n subroutine quadratic_reduced_(b,c,x1,x2)\n implicit none\n @T,intent(in) :: b,c\n @T,intent(out) :: x1,x2\n @T :: delta\n delta = b*b - 4._*c\n if(delta > 0) then\n delta = sqrt(delta)\n x1 = ( - b - delta ) * 0.5_\n x2 = ( - b + delta ) * 0.5_\n else\n x1 = huge(x1)\n x2 = huge(x2)\n end if\n end subroutine quadratic_reduced_\n\n subroutine quadratic_(a,b,c,x1,x2)\n implicit none\n @T,intent(in) :: a,b,c\n @T,intent(out) :: x1,x2\n @T :: delta,factor\n delta = b*b - 4._*a*c\n if(delta > 0) then\n delta = sqrt(delta)\n factor = 0.5_ / a\n x1 = ( - b - delta ) * factor\n x2 = ( - b + delta ) * factor\n else\n x1 = huge(x1)\n x2 = huge(x2)\n end if\n end subroutine quadratic_\n\n subroutine quadratic_pascal_(a,b,c,x1,x2)\n implicit none\n @T,intent(in) :: a,b,c\n @T,intent(out) :: x1,x2\n @T :: q,delta\n delta = b*b - 4._*a*c\n if(delta > 0) then\n delta = sqrt(delta)\n delta = sign(delta,b)\n q = -0.5_ * ( b + delta )\n x1 = q / a\n x2 = c / q\n else if(delta < 0) then\n x1 = -huge(x1)\n x2 = -huge(x2)\n else\n x1 = - 2.0_ * c / b\n x2 = -huge(x2)\n end if\n end subroutine quadratic_pascal_\n\n subroutine quadratic_pascal_reduced_(b,c,x1,x2)\n implicit none\n @T,intent(in) :: b,c\n @T,intent(out) :: x1,x2\n @T :: q,delta\n delta = b*b - 4._*c\n if(delta > 0) then\n delta = sqrt(delta)\n delta = sign(delta,b)\n q = -0.5_ * ( b + delta )\n x1 = q\n x2 = c / q\n else if(delta < 0) then\n x1 = -huge(x1)\n x2 = -huge(x2)\n else\n x1 = - 2.0_ * c / b\n x2 = -huge(x2)\n end if\n end subroutine quadratic_pascal_reduced_\n\n subroutine lineq_gausselim_(a,b)\n\n implicit none\n real(),intent(inout) :: a(:,:),b(:)\n real() :: frac\n integer :: i,j\n integer :: n\n\n n = size(a,1)\n\n do i=1,n-1\n if(a(i,i)==0) stop \"Zero pivot value\"\n do j=i+1,n\n if(a(i,j).ne.0.) then\n frac = a(i,j)/a(i,i)\n b(j) = b(j) - frac * b(i)\n a(i:,j) = a(i:,j) - frac * a(i:,i)\n end if\n end do\n end do\n\n do i=n,2,-1\n do j=i-1,1,-1\n if(a(i,j).ne.0.) then\n frac = a(i,j)/a(i,i)\n b(j) = b(j) - frac * b(i)\n a(i:,j) = a(i:,j) - frac * a(i:,i)\n end if\n end do\n end do\n\n do i=1,n\n b(i) = b(i) / a(i,i)\n end do\n\n end subroutine lineq_gausselim_\n\n !!@END FOR\n\nend module lib_algebra\n", "meta": {"hexsha": "1a4e55ee50ed90ba898fd9e89cc95d779b71112f", "size": 5609, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "extra/Fortran/fortranlib-master/fortranlib-master/templates/lib_algebra_template.f90", "max_stars_repo_name": "jfitz/code-stat", "max_stars_repo_head_hexsha": "dd2a13177f3ef03ab42123ef3cfcbbd062a2ae26", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 255, "max_stars_repo_stars_event_min_datetime": "2015-01-22T20:12:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-16T05:39:48.000Z", "max_issues_repo_path": "extra/Fortran/fortranlib-master/fortranlib-master/templates/lib_algebra_template.f90", "max_issues_repo_name": "jfitz/code-stat", "max_issues_repo_head_hexsha": "dd2a13177f3ef03ab42123ef3cfcbbd062a2ae26", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2015-05-06T22:43:11.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-27T04:13:37.000Z", "max_forks_repo_path": "extra/Fortran/fortranlib-master/fortranlib-master/templates/lib_algebra_template.f90", "max_forks_repo_name": "jfitz/code-stat", "max_forks_repo_head_hexsha": "dd2a13177f3ef03ab42123ef3cfcbbd062a2ae26", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 75, "max_forks_repo_forks_event_min_datetime": "2015-02-17T13:48:32.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T20:03:53.000Z", "avg_line_length": 27.2281553398, "max_line_length": 80, "alphanum_fraction": 0.6002852558, "num_tokens": 1656, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916134888614, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.6802931820247763}} {"text": "MODULE FUN_xyCOPLANAR\n!!#### PURPOSE\n!! Test for coplanarity between:\n!! @ three points in R^2 \n!! @ a plane and a point in R^2 \n\n!!#### EXTERNAL KINDS\nUSE KND_IntrinsicTypes,ONLY: KIND_Rsp,KIND_Rdp !!((01-A-KND_IntrinsicTypes.f90))\n\n!!#### EXTERNAL PARAMETERS\nUSE PAR_Constants_Rsp,ONLY: c_0_Rsp => c_0 !!((02-A-PAR_Constants_Rsp.f90))\nUSE PAR_Constants_Rdp,ONLY: c_0_Rdp => c_0 !!((02-A-PAR_Constants_Rdp.f90))\n\n!!#### EXTERNAL PROCEDURES\nUSE FUN_xyPLANE,ONLY: xyPLANE_P2 !!((05-B-FUN_xyPLANE.f90))\nUSE FUN_xySDIST,ONLY: xySDIST_PnP !!((03-A-FUN_xySDIST.f90))\n\n!!#### DEFAULT IMPLICIT\nIMPLICIT NONE\n\n!!#### DEFAULT ACCESS\nPRIVATE\n\n!!#### PROCEDURE OVERLOADING\nINTERFACE xyCOPLANAR_P3\n MODULE PROCEDURE xyCOPLANAR_P3_Rsp\n MODULE PROCEDURE xyCOPLANAR_P3_Rdp\nEND INTERFACE\n\nINTERFACE xyCOPLANAR_PnP\n MODULE PROCEDURE xyCOPLANAR_PnP_Rsp\n MODULE PROCEDURE xyCOPLANAR_PnP_Rdp\nEND INTERFACE\n\n!!#### PUBLIC ACCESS LIST\nPUBLIC :: xyCOPLANAR_P3\nPUBLIC :: xyCOPLANAR_PnP\n\n\nCONTAINS\n\n\nPURE FUNCTION xyCOPLANAR_P3_Rsp( P3 ) RESULT(COPLANAR)\n!!#### LOCAL KINDS\nUSE KND_IntrinsicTypes,ONLY: KIND_R=>KIND_Rsp !!((01-A-KND_IntrinsicTypes.f90))\nINCLUDE \"06-B-FUN_xyCOPLANAR_P3.f90.hdr\"\n!!--begin--\nINCLUDE \"06-B-FUN_xyCOPLANAR_P3.f90.bdy\"\n!!--end--\nEND FUNCTION\n\nPURE FUNCTION xyCOPLANAR_P3_Rdp( P3 ) RESULT(COPLANAR)\n!!#### LOCAL KINDS\nUSE KND_IntrinsicTypes,ONLY: KIND_R=>KIND_Rdp !!((01-A-KND_IntrinsicTypes.f90))\nINCLUDE \"06-B-FUN_xyCOPLANAR_P3.f90.hdr\"\n!!--begin--\nINCLUDE \"06-B-FUN_xyCOPLANAR_P3.f90.bdy\"\n!!--end--\nEND FUNCTION\n\n\nPURE FUNCTION xyCOPLANAR_PnP_Rsp( Pn , P ) RESULT(COPLANAR)\n!!#### LOCAL KINDS\nUSE KND_IntrinsicTypes,ONLY: KIND_R=>KIND_Rsp !!((01-A-KND_IntrinsicTypes.f90))\n!!#### LOCAL PARAMETERS\nREAL(KIND_R),PARAMETER :: c_0 = c_0_Rsp\nINCLUDE \"06-B-FUN_xyCOPLANAR_PnP.f90.hdr\"\n!!--begin--\nINCLUDE \"06-B-FUN_xyCOPLANAR_PnP.f90.bdy\"\n!!--end--\nEND FUNCTION\n\nPURE FUNCTION xyCOPLANAR_PnP_Rdp( Pn , P ) RESULT(COPLANAR)\n!!#### LOCAL KINDS\nUSE KND_IntrinsicTypes,ONLY: KIND_R=>KIND_Rdp !!((01-A-KND_IntrinsicTypes.f90))\n!!#### LOCAL PARAMETERS\nREAL(KIND_R),PARAMETER :: c_0 = c_0_Rdp\nINCLUDE \"06-B-FUN_xyCOPLANAR_PnP.f90.hdr\"\n!!--begin--\nINCLUDE \"06-B-FUN_xyCOPLANAR_PnP.f90.bdy\"\n!!--end--\nEND FUNCTION\n\n\nEND MODULE\n", "meta": {"hexsha": "6986297606618858950edce627b8c111539f2387", "size": 2266, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/06-B-FUN_xyCOPLANAR.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/06-B-FUN_xyCOPLANAR.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/06-B-FUN_xyCOPLANAR.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": 26.3488372093, "max_line_length": 80, "alphanum_fraction": 0.7308031774, "num_tokens": 786, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737806, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.6802931792551346}} {"text": "program tquad\n\n! David H Bailey 31 Jan 2020\n\n! COPYRIGHT AND DISCLAIMER:\n! All software in this package (c) 2018 David H. Bailey.\n! By downloading or using this software you agree to the copyright, disclaimer\n! and license agreement in the accompanying file DISCLAIMER.txt.\n\n! This program demonstrates three quadrature routines:\n\n! quadts: Implements the tanh-sinh quadrature scheme of Takahashi and Mori,\n! for functions on a finite interval such as (0,1).\n! quades: Implements the exp-sinh scheme, for functions on a\n! semi-infinite interval such as (0, infinity).\n! quadss: Implements the sinh-sinh scheme, for functions on the entire\n! real line.\n\n! The separate program tquadgs.f90 implements Gaussian quadrature.\n\n! These schemes have some desirable properties, such as the cost of computing\n! weight-abscissa pairs only increases linearly with the number of evaluation\n! points (instead of quadratically, as with Gaussian quadrature). Also,\n! quadts in particular often works well even when the function has a blow-up\n! singularity or infinite derivative at one or both endpoints. The quadrature\n! computations proceed level-by-level, with the computational cost (and,\n! often, the accuracy) approximately doubling with each iteration, until a\n! target accuracy (500-digit precision in this case), based on an accuracy\n! estimate computed by the program, is achieved. The exp-sinh and sinh-sinh\n! schemes are variants of the tanh-sinh scheme, which is described here:\n\n! David H. Bailey, Xiaoye S. Li and Karthik Jeyabalan, \"A comparison of\n! three high-precision quadrature schemes,\" Experimental Mathematics, \n! vol. 14 (2005), no. 3, pg. 317-329, preprint available at\n! http://www.davidhbailey.com/dhbpapers/quadrature-em.pdf.\n\n! The function to be integrated must be defined in an external function\n! subprogram (see samples below), and the name of the function must be\n! included in a \"type (mp_real)\" and in an \"external\" statement. Prior to\n! calling the quadrature routine, the corresponding initialization routine\n! must be called to initialize the abscissa and weight arrays: initqts,\n! initqes and initqss, corresponding to the quadrature routines quadts,\n! quades and quadss, respectively.\n\n! All of these routines are 100% THREAD SAFE -- all requisite parameters\n! and arrays are passed through subroutine arguments. \n\n! Here are some specific instructions for the individual quadrature schemes:\n\n! quadts: \n\n! First call initqts with the arrays wkts and xkts as the last two arguments,\n! and then call quadts with these same two arrays as the last two arguments. \n! Set x1 and x2, the limits of integration, in executable statements,\n! using high precision (nwds2 words) if possible. For some integrand\n! functions, it is important that these endpoints be computed to higher\n! precision (nwds2 words) in the calling program, that these higher\n! precision values be passed to quadts (where scaled abscissas are\n! calculated), and that the function definition itself uses these higher\n! precision scaled abscissas in any initial subtractions or other\n! sensitive operations involving the input argument. Otherwise the\n! accuracy of the quadrature result might only be half as high as it\n! otherwise could be. Note in the examples below, x1 and x2 and set\n! using high-precision values of zero, one and pi (the variables zero,\n! one and mppic). See the function definitions of fun06, fun07, fun09\n! and fun10 for examples of how to scale within the function routine. Once\n! the input argument has been accurately scaled, the function evaluation\n! itself can and should be performed with standard precision (nwds1 words)\n! for faster run times.\n\n! In the initialization routine initqts, weight-abscissa pairs are\n! calculated until the weights are smaller than 10^(neps2), where neps2\n! is the high precision epsilon (typically twice the low precision\n! epsilon -- see below). In some problems it may be necessary to adjust\n! neps2 to a more negative value to obtain the best accuracy.\n\n! quades:\n\n! First call initqes with the arrays wkes and xkes as the last two arguments,\n! and then call quades with these same two arrays as the last two arguments. \n! It is assumed that the left endpoint is x1, and the right endpoint is\n! +infinity. The comment about computing the endpoints to high precision\n! in the note for quadts above also applies here, as does the comment\n! about computing weight-abscissa pairs based on neps2.\n\n! quadss:\n\n! First call initqss with the arrays wkss and xkss as the last two arguments,\n! and then call quadss with these same two arrays as the last two arguments. \n! No endpoints are specified here -- the integral is performed over the\n! entire real line. However, the comment about computing weight-abscissa\n! pairs, based on neps2, also applies here.\n\n! These inputs are set in the parameter statement below:\n\n! ndp1 Primary (\"low\") precision in digits; this is the target accuracy\n! of quadrature results.\n! ndp2 Secondary (\"high\") precision in digits. By default, ndp2 = 2*ndp1.\n! neps1 Log10 of the primary tolerance. By default, neps1 = - ndp1.\n! neps2 Log10 of the secondary tolerance. By default, neps2 = -ndp2.\n! nq1 Max number of phases in quadrature routine; adding 1 increases\n! (possibly doubles) the number of accurate digits in the result,\n! but also roughly doubles the run time. nq1 must be at least 3.\n! nq2 Space parameter for wk and xk arrays in the calling program. By\n! default it is set to 12 * 2^nq1. Increase nq2 if directed by a \n! message produced in initqts.\n! nwds1 Low precision in words. By default nwds1 = int (ndp1 / mpdpw + 2).\n! nwds2 High precision in words. By default nwds2 = int (ndp2 / mpdpw + 2).\n\nuse mpmodule\nimplicit none\ninteger i, ndp1, ndp2, neps1, neps2, nq1, nq2, nwds1, nwds2, n1\nparameter (ndp1 = 500, ndp2 = 1000, neps1 = -ndp1, neps2 = -ndp2, &\n nq1 = 11, nq2 = 12 * 2 ** nq1, nwds1 = int (ndp1 / mpdpw + 2), &\n nwds2 = int (ndp2 / mpdpw + 2))\nreal (8) dplog10q, d1, d2, second, tm0, tm1, tm2\ntype (mp_real) err, quades, quadss, quadts, fun01, fun02, fun03, fun04, &\n fun05, fun06, fun07, fun08, fun09, fun10, fun11, fun12, fun13, fun14, &\n fun15, fun16, fun17, fun18, one, t1, t2, t3, t4, wkes(-1:nq2), &\n xkes(-1:nq2), wkss(-1:nq2), xkss(-1:nq2), wkts(-1:nq2), xkts(-1:nq2), zero\ntype (mp_real) mppic, mpl02, x1, x2\nexternal fun01, fun02, fun03, fun04, fun05, fun06, fun07, fun08, &\n fun09, fun10, fun11, fun12, fun13, fun14, fun15, fun16, fun17, fun18, &\n quades, quadss, quadts, second\n\n! Check to see if default precision is high enough.\n\nif (ndp2 > mpipl) then\n write (6, '(\"Increase default precision in module MPFUNF.\")')\n stop\nendif\n\n! Compute pi and log(2) to high precision (nwds2 words).\n\none = mpreal (1.d0, nwds2)\nzero = mpreal (0.d0, nwds2)\nmppic = mppi (nwds2)\nmpl02 = mplog2 (nwds2)\n\nwrite (6, 1) nq1, ndp1, ndp2, neps1, neps2\n1 format ('Quadts test: Quadlevel =',i6/'Digits1 =',i6,' Digits2 =',i6, &\n ' Epsilon1 =',i6,' Epsilon2 =',i6)\n\n! Initialize quadrature tables wk and xk (weights and abscissas).\n\ntm0 = second ()\ncall initqes (nq1, nq2, nwds1, neps2, wkes, xkes)\ncall initqss (nq1, nq2, nwds1, neps2, wkss, xkss)\ncall initqts (nq1, nq2, nwds1, neps2, wkts, xkts)\ntm1 = second ()\ntm2 = tm1 - tm0\nwrite (6, 2) tm1 - tm0\n2 format ('Quadrature initialization completed: cpu time =',f12.6)\n\n! Begin quadrature tests.\n\nwrite (6, 11)\n11 format (/'Continuous functions on finite intervals:'//&\n 'Problem 1: Int_0^1 t*log(1+t) dt = 1/4'/)\nx1 = zero\nx2 = one\ntm0 = second ()\nt1 = quadts (fun01, x1, x2, nq1, nq2, nwds1, nwds2, neps1, wkts, xkts)\ntm1 = second ()\ntm2 = tm2 + (tm1 - tm0)\nwrite (6, 3) tm1 - tm0\n3 format ('Quadrature completed: CPU time =',f12.6/'Result =')\ncall mpwrite (6, ndp1 + 20, ndp1, t1)\nt2 = mpreal (0.25d0, nwds1)\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n4 format ('Actual error =',f10.6,'x10^',i6)\n\nwrite (6, 12)\n12 format (/'Problem 2: Int_0^1 t^2*arctan(t) dt = (pi - 2 + 2*log(2))/12'/)\nx1 = zero\nx2 = one\ntm0 = second ()\nt1 = quadts (fun02, x1, x2, nq1, nq2, nwds1, nwds2, neps1, wkts, xkts)\ntm1 = second ()\ntm2 = tm2 + (tm1 - tm0)\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, ndp1 + 20, ndp1, t1)\nt2 = (mppic - 2.d0 + 2.d0 * mpl02) / 12.d0\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 13)\n13 format (/'Problem 3: Int_0^(pi/2) e^t*cos(t) dt = 1/2*(e^(pi/2) - 1)'/)\nx1 = zero\nx2 = 0.5d0 * mppic\ntm0 = second ()\nt1 = quadts (fun03, x1, x2, nq1, nq2, nwds1, nwds2, neps1, wkts, xkts)\ntm1 = second ()\ntm2 = tm2 + (tm1 - tm0)\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, ndp1 + 20, ndp1, t1)\nt2 = 0.5d0 * (exp (0.5d0 * mppic) - 1.d0)\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 14)\n14 format (/ &\n 'Problem 4: Int_0^1 arctan(sqrt(2+t^2))/((1+t^2)sqrt(2+t^2)) dt = 5*Pi^2/96'/)\nx1 = zero\nx2 = one\ntm0 = second ()\nt1 = quadts (fun04, x1, x2, nq1, nq2, nwds1, nwds2, neps1, wkts, xkts)\ntm1 = second ()\ntm2 = tm2 + (tm1 - tm0)\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, ndp1 + 20, ndp1, t1)\nt2 = 5.d0 * mppic**2 / 96.d0\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 15)\n15 format (/&\n 'Continuous functions on finite intervals, but non-diff at an endpoint:'// &\n 'Problem 5: Int_0^1 sqrt(t)*log(t) dt = -4/9'/)\nx1 = zero\nx2 = one\ntm0 = second ()\nt1 = quadts (fun05, x1, x2, nq1, nq2, nwds1, nwds2, neps1, wkts, xkts)\ntm1 = second ()\ntm2 = tm2 + (tm1 - tm0)\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, ndp1 + 20, ndp1, t1)\nt2 = mpreal (-4.d0, nwds1) / 9.d0\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 16)\n16 format (/'Problem 6: Int_0^1 sqrt(1-t^2) dt = pi/4'/)\nx1 = zero\nx2 = one\ntm0 = second ()\nt1 = quadts (fun06, x1, x2, nq1, nq2, nwds1, nwds2, neps1, wkts, xkts)\ntm1 = second ()\ntm2 = tm2 + (tm1 - tm0)\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, ndp1 + 20, ndp1, t1)\nt2 = 0.25d0 * mppic\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 17)\n17 format (/&\n 'Functions on finite intervals with integrable singularity at an endpoint:'//&\n 'Problem 7: Int_0^1 sqrt(t)/sqrt(1-t^2) dt = 2*sqrt(pi)*gamma(3/4)/gamma(1/4)'/)\nx1 = zero\nx2 = one\ntm0 = second ()\nt1 = quadts (fun07, x1, x2, nq1, nq2, nwds1, nwds2, neps1, wkts, xkts)\ntm1 = second ()\ntm2 = tm2 + (tm1 - tm0)\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, ndp1 + 20, ndp1, t1)\nt2 = 2.d0 * sqrt (mpreal (mppic, nwds1)) * gamma (mpreal (0.75d0, nwds1)) &\n / gamma (mpreal (0.25d0, nwds1))\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 18)\n18 format (/'Problem 8: Int_0^1 log(t)^2 dt = 2'/)\nx1 = zero\nx2 = one\ntm0 = second ()\nt1 = quadts (fun08, x1, x2, nq1, nq2, nwds1, nwds2, neps1, wkts, xkts)\ntm1 = second ()\ntm2 = tm2 + (tm1 - tm0)\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, ndp1 + 20, ndp1, t1)\nt2 = mpreal (2.d0, nwds1)\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 19)\n19 format (/'Problem 9: Int_0^(pi/2) log(cos(t)) dt = -pi*log(2)/2'/)\nx1 = zero\nx2 = 0.5d0 * mppic\ntm0 = second ()\nt1 = quadts (fun09, x1, x2, nq1, nq2, nwds1, nwds2, neps1, wkts, xkts)\ntm1 = second ()\ntm2 = tm2 + (tm1 - tm0)\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, ndp1 + 20, ndp1, t1)\nt2 = -0.5d0 * mppic * mpl02\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 20)\n20 format (/'Problem 10: Int_0^(pi/2) sqrt(tan(t)) dt = pi*sqrt(2)/2'/)\nx1 = zero\nx2 = 0.5d0 * mppic\ntm0 = second ()\nt1 = quadts (fun10, x1, x2, nq1, nq2, nwds1, nwds2, neps1, wkts, xkts)\ntm1 = second ()\ntm2 = tm2 + (tm1 - tm0)\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, ndp1 + 20, ndp1, t1)\nt2 = 0.5d0 * mppic * sqrt (mpreal (2.d0, nwds1))\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 21)\n21 format (/&\n 'Functions on a semi-infinite interval:'//&\n 'Problem 11: Int_1^inf 1/(1+t^2) dt = pi/4'/)\nx1 = one\ntm0 = second ()\nt1 = quades (fun11, x1, nq1, nq2, nwds1, nwds2, neps1, wkes, xkes)\ntm1 = second ()\ntm2 = tm2 + (tm1 - tm0)\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, ndp1 + 20, ndp1, t1)\nt2 = 0.25d0 * mppic\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 22)\n22 format (/'Problem 12: Int_0^inf e^(-t)/sqrt(t) dt = sqrt(pi)'/)\nx1 = zero\ntm0 = second ()\nt1 = quades (fun12, x1, nq1, nq2, nwds1, nwds2, neps1, wkes, xkes)\ntm1 = second ()\ntm2 = tm2 + (tm1 - tm0)\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, ndp1 + 20, ndp1, t1)\nt2 = sqrt (mppic)\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 23)\n23 format (/'Problem 13: Int_0^inf e^(-t^2/2) dt = sqrt(pi/2)'/)\nx1 = zero\ntm0 = second ()\nt1 = quades (fun13, x1, nq1, nq2, nwds1, nwds2, neps1, wkes, xkes)\ntm1 = second ()\ntm2 = tm2 + (tm1 - tm0)\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, ndp1 + 20, ndp1, t1)\nt2 = sqrt (0.5d0 * mppic)\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 24)\n24 format (/'Problem 14: Int_pi^inf e^(-t)*cos(t) dt = -1/2 * exp(-pi)'/)\nx1 = mppic\ntm0 = second ()\nt1 = quades (fun14, x1, nq1, nq2, nwds1, nwds2, neps1, wkes, xkes)\ntm1 = second ()\ntm2 = tm2 + (tm1 - tm0)\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, ndp1 + 20, ndp1, t1)\nt2 = -0.5d0 * exp (- mpreal (mppic, nwds1))\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 25)\n25 format (/ &\n 'Functions on the entire real line:'// &\n 'Problem 15: Int_-inf^inf 1/(1+t^2) dt = Pi'/)\ntm0 = second ()\nt1 = quadss (fun15, nq1, nq2, nwds1, neps1, wkss, xkss)\ntm1 = second ()\ntm2 = tm2 + (tm1 - tm0)\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, ndp1 + 20, ndp1, t1)\nt2 = mppic\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 26)\n26 format (/'Problem 16: Int_-inf^inf 1/(1+t^4) dt = Pi/Sqrt(2)'/)\ntm0 = second ()\nt1 = quadss (fun16, nq1, nq2, nwds1, neps1, wkss, xkss)\ntm1 = second ()\ntm2 = tm2 + (tm1 - tm0)\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, ndp1 + 20, ndp1, t1)\nt2 = mppic / sqrt (mpreal (2.d0, nwds1))\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 27)\n27 format (/'Problem 17: Int_-inf^inf e^(-t^2/2) dt = sqrt (2*Pi)'/)\ntm0 = second ()\nt1 = quadss (fun17, nq1, nq2, nwds1, neps1, wkss, xkss)\ntm1 = second ()\ntm2 = tm2 + (tm1 - tm0)\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, ndp1 + 20, ndp1, t1)\nt2 = sqrt (2.d0 * mppic)\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 28)\n28 format (/'Problem 18: Int_-inf^inf e^(-t^2/2) cos(t) dt = sqrt (2*Pi/e)'/)\ntm0 = second ()\nt1 = quadss (fun18, nq1, nq2, nwds1, neps1, wkss, xkss)\ntm1 = second ()\ntm2 = tm2 + (tm1 - tm0)\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, ndp1 + 20, ndp1, t1)\nt2 = sqrt (2.d0 * mppic / exp (mpreal (1.d0, nwds1)))\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 99) tm2\n99 format ('Total CPU time =',f12.6)\n\nstop\nend\n\nfunction fun01 (t, nwds1, nwds2)\n\n! fun01(t) = t * log(1+t)\n\nuse mpmodule\nimplicit none\ninteger nwds1, nwds2\ntype (mp_real) fun01, t1, t2\ntype (mp_real) t\n\nt1 = mpreal (t, nwds1)\nfun01 = t1 * log (1.d0 + t1)\nreturn\nend\n\nfunction fun02 (t, nwds1, nwds2)\n\n! fun02(t) = t^2 * arctan(t)\n\nuse mpmodule\nimplicit none\ninteger nwds1, nwds2\ntype (mp_real) fun02, t1\ntype (mp_real) t\n\nt1 = mpreal (t, nwds1)\nfun02 = t1 ** 2 * atan (t1)\nreturn\nend\n\nfunction fun03 (t, nwds1, nwds2)\n\n! fun03(t) = e^t * cos(t)\n\nuse mpmodule\nimplicit none\ninteger nwds1, nwds2\ntype (mp_real) fun03, t1\ntype (mp_real) t\n\nt1 = mpreal (t, nwds1)\nfun03 = exp(t1) * cos(t1)\nreturn\nend\n\nfunction fun04 (t, nwds1, nwds2)\n\n! fun04(t) = arctan(sqrt(2+t^2))/((1+t^2)sqrt(2+t^2))\n\nuse mpmodule\nimplicit none\ninteger nwds1, nwds2\ntype (mp_real) fun04, t1, t2\ntype (mp_real) t\n\nt1 = mpreal (t, nwds1)\nt2 = sqrt (2.d0 + t1**2)\nfun04 = atan(t2) / ((1.d0 + t1**2) * t2)\nreturn\nend\n\nfunction fun05 (t, nwds1, nwds2)\n\n! fun05(t) = sqrt(t)*log(t)\n\nuse mpmodule\nimplicit none\ninteger nwds1, nwds2\ntype (mp_real) fun05, t1\ntype (mp_real) t\n\nt1 = mpreal (t, nwds1)\nfun05 = sqrt (t1) * log (t1)\nreturn\nend\n\nfunction fun06 (t, nwds1, nwds2)\n\n! fun06(t) = sqrt(1-t^2)\n\nuse mpmodule\nimplicit none\ninteger nwds1, nwds2\ntype (mp_real) fun06, t1, t2\ntype (mp_real) t\n\n! The subtraction to compute t2 must be performed using high precision\n! (nwds2), but after the subtraction its low precision value is fine.\n\nt1 = mpreal (t, nwds1)\nt2 = mpreal (1.d0 - t**2, nwds1)\nfun06 = sqrt (t2)\nreturn\nend\n\nfunction fun07 (t, nwds1, nwds2)\n\n! fun07(t) = sqrt (t) / sqrt(1-t^2)\n\nuse mpmodule\nimplicit none\ninteger nwds1, nwds2\ntype (mp_real) fun07, t1, t2\ntype (mp_real) t\n\n! The subtraction to compute t2 must be performed using high precision\n! (nwds2), but after the subtraction its low precision value is fine.\n\nt1 = mpreal (t, nwds1)\nt2 = mpreal (1.d0 - t, nwds1)\nfun07 = sqrt (t1) / sqrt (t2 * (1.d0 + t1))\nreturn\nend\n\nfunction fun08 (t, nwds1, nwds2)\n\n! fun08(t) = log(t)^2\n\nuse mpmodule\nimplicit none\ninteger nwds1, nwds2\ntype (mp_real) fun08, t1\ntype (mp_real) t\n\nt1 = mpreal (t, nwds1)\nfun08 = log (t1) ** 2\nreturn\nend\n\nfunction fun09 (t, nwds1, nwds2)\n\n! fun09(t) = log (cos (t))\n\nuse mpmodule\nimplicit none\ninteger nwds1, nwds2\ntype (mp_real) fun09, pi, t1, t2, t3, t4\ntype (mp_real) t\n\n! The subtraction to compute t2 must be performed using high precision\n! (nwds2), but after the subtraction its low precision value is fine.\n\nt1 = mpreal (t, nwds1)\npi = mppi (nwds2)\nt3 = mpreal (0.25d0 * pi, nwds1)\nt2 = mpreal (0.5d0 * pi - t, nwds1)\n\nif (t1 < t3) then\n t4 = cos (t1)\nelse\n t4 = sin (t2)\nendif\nfun09 = log (t4)\n\nreturn\nend\n\nfunction fun10 (t, nwds1, nwds2)\n\n! fun10(t) = sqrt(tan(t))\n\nuse mpmodule\nimplicit none\ninteger nwds1, nwds2\ntype (mp_real) fun10, pi, t1, t2, t3, t4\ntype (mp_real) t\n\n! The subtraction to compute t3 must be performed using high precision\n! (nwds2), but after the subtraction its low precision value is fine.\n\nt1 = mpreal (t, nwds1)\npi = mppi (nwds2)\nt3 = mpreal (0.25d0 * pi, nwds1)\nt2 = mpreal (0.5d0 * pi - t, nwds1)\n\nif (t1 < t3) then\n fun10 = sqrt (tan (t1))\nelse\n fun10 = 1.d0 / sqrt (tan (t2))\nendif\nreturn\nend\n\nfunction fun11 (t, nwds1, nwds2)\n\n! 1/(1 + t^2) on (0, Inf).\n\nuse mpmodule\nimplicit none\ninteger nwds1, nwds2\ntype (mp_real) fun11, t1\ntype (mp_real) t\n\nt1 = mpreal (t, nwds1)\nfun11 = 1.d0 / (1.d0 + t1 ** 2)\nreturn\nend\n\nfunction fun12 (t, nwds1, nwds2)\n\n! e^(-t)/sqrt(t) on (0, inf).\n\nuse mpmodule\nimplicit none\ninteger nwds1, nwds2\ntype (mp_real) fun12, t1, t2\ntype (mp_real) t\n\nt1 = mpreal (t, nwds1)\nfun12 = exp (-t1) / sqrt (t1)\nreturn\nend\n\nfunction fun13 (t, nwds1, nwds2)\n\n! e^(-t^2/2) on (0, inf).\n\nuse mpmodule\nimplicit none\ninteger nwds1, nwds2\ntype (mp_real) fun13, t1, t2\ntype (mp_real) t\n\nt1 = mpreal (t, nwds1)\nfun13 = exp (-0.5d0 * t1 ** 2)\nreturn\nend\n\nfunction fun14 (t, nwds1, nwds2)\n\n! e^(-t) cos(t) on (0, inf).\n\nuse mpmodule\nimplicit none\ninteger nwds1, nwds2\ntype (mp_real) fun14, t1, t2\ntype (mp_real) t\n\nt1 = mpreal (t, nwds1)\nfun14 = exp (-t1) * cos (t1)\nreturn\nend\n\nfunction fun15 (t, nwds1)\nuse mpmodule\nimplicit none\ninteger nwds1\ntype (mp_real) t, fun15\n\nfun15 = 1.d0 / (1.d0 + t**2)\nreturn\nend\n\nfunction fun16 (t, nwds1)\nuse mpmodule\nimplicit none\ninteger nwds1\ntype (mp_real) t, fun16\n\nfun16 = 1.d0 / (1.d0 + t**4)\nreturn\nend\n\nfunction fun17 (t, nwds1)\nuse mpmodule\nimplicit none\ninteger nwds1\ntype (mp_real) t, fun17\n\nfun17 = exp (-0.5d0 * t**2)\nreturn\nend\n\nfunction fun18 (t, nwds1)\nuse mpmodule\nimplicit none\ninteger nwds1\ntype (mp_real) t, fun18\n\nfun18 = exp (-0.5d0 * t**2) * cos (t)\nreturn\nend\n\nsubroutine initqes (nq1, nq2, nwds1, neps2, wkes, xkes)\n\n! This subroutine initializes the quadrature arrays xkes and wkes for quades.\n! The argument nq2 is the space allocated for wkes and xkes in the calling\n! program. By default it is set to 12 * 2^nq1. If initqes outputs the message\n! \"Table space parameter is too small\", adjust nq2. Also, if quades outputs\n! the message \"Terms too large\", adjust nq1 and neps2 as necessary in the call\n! to initqes. The argument neps2 controls termination of the loop below, which\n! ends when wkes(k) * 10^(neps2) > 1.\n\n! The wkes and xkes arrays are computed based on the transformation\n! t = exp (pi/2 * sinh (x)). See comments below.\n\n! Both initqes and quades are 100% THREAD SAFE -- all requisite parameters\n! and arrays are passed through subroutine arguments. \n\n! David H Bailey 31 Jan 2020\n\nuse mpmodule\nimplicit none\ninteger i, ierror, iprint, j, k, k1, ndebug, neps2, nq1, nq2, nwds1\nparameter (iprint = 1024, ndebug = 2)\ntype (mp_real) eps2, h, p2, t1, t2, t3, t4, u1, u2, &\n wkes(-1:nq2), xkes(-1:nq2)\n\nwrite (6, 1)\n1 format ('initqes: Exp-sinh quadrature initialization')\n\neps2 = mpreal (10.d0, nwds1) ** neps2\np2 = 0.5d0 * mppi (nwds1)\nh = mpreal (0.5d0 ** nq1, nwds1)\nwkes(-1) = mpreal (dble (nq1), nwds1)\n\ndo k = 0, nq2\n if (ndebug >= 2 .and. mod (k, iprint) == 0) write (6, *) k, nq2\n t1 = mpreal (dble (k) * h, nwds1)\n\n! xkes(k) = exp (u1)\n! wkes(k) = exp (u1) * u2\n! where u1 = pi/2 * sinh (t1) and u2 = pi/2 * cosh (t1)\n\n t2 = exp (t1)\n u1 = 0.5d0 * p2 * (t2 - 1.d0 / t2)\n u2 = 0.5d0 * p2 * (t2 + 1.d0 / t2)\n xkes(k) = exp (u1)\n wkes(k) = xkes(k) * u2\n\n if (wkes(k) * eps2 > 1.d0) goto 100\nenddo\n\nwrite (6, 2) nq2\n2 format ('initqes: Table space parameter is too small; value =',i8)\nstop\n\n100 continue\n\nxkes(-1) = mpreal (dble (k), nwds1)\nif (ndebug >= 2) then\n write (6, 3) k\n3 format ('initqes: Table spaced used =',i8)\nendif\n\nreturn\nend\n\nfunction quades (fun, x1, nq1, nq2, nwds1, nwds2, neps1, wkes, xkes)\n\n! This routine computes the integral of the function fun on the interval\n! (x1, inf) with a target tolerance of 10^neps1. The quadrature level is\n! progressively increased (approximately doubling the work with each level)\n! until level nq1 has been performed or the target tolerance has been met.\n! nq2 is the size of the wkes and xkes arrays, which must first be \n! initialized by calling initqes. If quades outputs the message \"Terms too\n! large\", adjust nq1 and neps2 as necessary in the call to initqes.\n\n! Both initqes and quades are 100% THREAD SAFE -- all requisite parameters\n! and arrays are passed through subroutine arguments. \n\n! For some functions, it is important that the endpoint x1 be\n! computed to high precision (nwds2 words) in the calling program, that\n! these high-precision values be passed to quades (where scaled abscissas\n! are calculated to high precision), and that the function definition\n! itself uses these high-precision scaled abscissas in any initial\n! subtractions or other sensitive operations involving the input argument.\n! Otherwise the accuracy of the quadrature result might only be half as\n! high as it otherwise could be. See the function definitions of fun06,\n! fun07, fun09 and fun10 for examples on how this is done. Otherwise the\n! function evaluation can and should be performed with low precision\n! (nwds1 words) for faster run times. The two precision levels (nwds1\n! and nwds2) are specified by the user in the calling program.\n\n! David H Bailey 31 Jan 2020\n\nuse mpmodule\nimplicit none\ninteger i, ierror, ip(0:100), iz1, iz2, izx, j, k, k1, k2, n, ndebug, &\n nds, neps1, nq1, nq2, nqq1, nwds1, nwds2\nparameter (izx = 5, ndebug = 2)\nlogical log1\nreal (8) d1, d2, d3, d4, dplog10q\ntype (mp_real) c10, eps1, eps2, epsilon1, err, fun, h, &\n quades, tsum, s1, s2, s3, t1, t2, t3, tw1, tw2, twi1, twi2, twmx, &\n wkes(-1:nq2), xkes(-1:nq2)\ntype (mp_real) x1, xx1, xx2\nexternal fun, dplog10q\n\nepsilon1 = mpreal (10.d0, nwds1) ** neps1\ntsum = mpreal (0.d0, nwds1)\ns1 = mpreal (0.d0, nwds1)\ns2 = mpreal (0.d0, nwds1)\nh = mpreal (1.d0, nwds1)\nc10 = mpreal (10.d0, nwds1)\n\nif (wkes(-1) < dble (nq1)) then\n write (6, 1) nq1\n1 format ('quades: quadrature arrays have not been initialized; nq1 =',i6)\n goto 140\nendif\nnqq1 = dble (wkes(-1))\nn = dble (xkes(-1))\n\ndo k = 0, nqq1\n ip(k) = 2 ** k\nenddo\n\ndo k = 1, nq1\n h = 0.5d0 * h\n s3 = s2\n s2 = s1\n k1 = ip(nqq1-k)\n k2 = ip(nqq1-k+1)\n iz1 = 0\n iz2 = 0\n twmx = mpreal (0.d0, nwds1)\n\n! Evaluate function at level k in x, avoiding unnecessary computation.\n\n do i = 0, n, k1\n if (mod (i, k2) /= 0 .or. k == 1) then\n\n! These next few lines, which scale the abscissas, must be performed in\n! high precision (nwds2 words) to ensure full accuracy in the quadrature\n! results, even though the abscissas xkes(i) were computed in low precision.\n\n xx1 = x1 + mpreal (xkes(i), nwds2)\n xx2 = x1 + 1.d0 / mpreal (xkes(i), nwds2)\n log1 = xx1 > x1\n \n! The remaining computations are performed in low precision (nwds1 words).\n\n if (iz1 < izx) then\n t1 = fun (xx1, nwds1)\n tw1 = t1 * wkes(i)\n twi1 = abs (tw1)\n if (twi1 < epsilon1) then\n iz1 = iz1 + 1\n else\n iz1 = 0\n endif\n else\n t1 = mpreal (0.d0, nwds1)\n tw1 = mpreal (0.d0, nwds1)\n endif\n\n if (i > 0 .and. log1 .and. iz2 < izx) then\n t2 = fun (xx2, nwds1)\n tw2 = t2 * wkes(i) / xkes(i)**2\n twi2 = abs (tw2)\n if (twi2 < epsilon1) then\n iz2 = iz2 + 1\n else\n iz2 = 0\n endif\n else\n t2 = mpreal (0.d0, nwds1)\n tw2 = mpreal (0.d0, nwds1)\n endif\n\n tsum = tsum + tw1 + tw2\n twmx = max (twmx, abs (tw1), abs (tw2))\n endif\n enddo\n\n! Compute s1 = current integral approximation and err = error estimate.\n! Tsum is the sum of all tw1 and tw2 from the loop above.\n! Twmx is the largest absolute value of tw1 and tw2 from the loop above.\n! Twi1 and twi2 are the final nonzero values of abs(tw1) and abs(tw2).\n\n s1 = h * tsum\n eps1 = twmx * epsilon1\n eps2 = abs (max (twi1, twi2) / s1)\n d1 = dplog10q (abs ((s1 - s2) / s1))\n d2 = dplog10q (abs ((s1 - s3) / s1))\n d3 = dplog10q (eps1) - 1.d0\n d4 = dplog10q (eps2) - 1.d0\n\n if (k <= 2) then\n err = mpreal (1.d0, nwds1)\n elseif (d1 .eq. -999999.d0) then\n err = mpreal (0.d0, nwds1)\n else\n err = c10 ** nint (min (0.d0, max (d1 ** 2 / d2, 2.d0 * d1, d3, d4)))\n endif\n\n! Output current integral approximation and error estimate, to 60 digits.\n\n if (ndebug >= 2) then\n write (6, 2) k, nq1, nint (dplog10q (abs (err)))\n2 format ('quades: Iteration',i3,' of',i3,'; est error = 10^',i7, &\n '; approx value =')\n call mpwrite (6, 80, 60, s1)\n endif\n\n if (k >= 3 .and. iz1 == 0 .and. iz2 == 0) then\n write (6, 3)\n3 format ('quades: Terms too large -- adjust neps2 in call to initqes.')\n goto 140\n endif\n\n if (k >= 3 .and. err < eps1) then\n write (6, 4) nint (dplog10q (abs (err)))\n4 format ('quades: Estimated error = 10^',i7)\n goto 140\n endif\n\n if (k >= 3 .and. err < eps2) then\n write (6, 5) nint (dplog10q (abs (err)))\n5 format ('quades: Estimated error = 10^',i7/&\n 'Adjust nq1 and neps2 in initqes for greater accuracy.')\n goto 140\n endif\nenddo\n\n140 continue\n\nquades = s1\nreturn\nend\n\nsubroutine initqss (nq1, nq2, nwds1, neps2, wkss, xkss)\n\n! This subroutine initializes the quadrature arrays xkss and wkss for quadss.\n! The argument nq2 is the space allocated for wkss and xkss in the calling\n! program. By default it is set to 12 * 2^nq1. If initqss outputs the message\n! \"Table space parameter is too small\", adjust nq2. Also, if quadss outputs\n! the message \"Terms too large\", adjust nq1 and neps2 as necessary in the call\n! to initqss. The argument neps2 controls termination of the loop below, which\n! ends when wkss(k) * 10^(neps2) > 1.\n\n! The wkss and xkss arrays are computed based on the transformation\n! t = sinh (pi/2 * sinh (x)). See comments below.\n\n! Both initqss and quadss are 100% THREAD SAFE -- all requisite parameters\n! and arrays are passed through subroutine arguments. \n\n! David H Bailey 31 Jan 2020\n\nuse mpmodule\nimplicit none\ninteger i, ierror, iprint, j, k, k1, ndebug, neps2, nq1, nq2, nwds1\nparameter (iprint = 1024, ndebug = 2)\ntype (mp_real) eps2, h, p2, t1, t2, t3, t4, u1, u2, &\n wkss(-1:nq2), xkss(-1:nq2)\n\nwrite (6, 1)\n1 format ('initqss: Sinh-sinh quadrature initialization')\n\neps2 = mpreal (10.d0, nwds1) ** neps2\np2 = 0.5d0 * mppi (nwds1)\nh = mpreal (0.5d0 ** nq1, nwds1)\nwkss(-1) = mpreal (dble (nq1), nwds1)\n\ndo k = 0, nq2\n if (ndebug >= 2 .and. mod (k, iprint) == 0) write (6, *) k, nq2\n t1 = mpreal (dble (k) * h, nwds1)\n\n! xkss(k) = sinh (u1)\n! wkss(k) = cosh (u1) * u2\n! where u1 = pi/2 * sinh (t1) and u2 = pi/2 * cosh (t1)\n\n t2 = exp (t1)\n u1 = 0.5d0 * p2 * (t2 - 1.d0 / t2)\n u2 = 0.5d0 * p2 * (t2 + 1.d0 / t2)\n t3 = exp (u1)\n xkss(k) = 0.5d0 * (t3 - 1.d0 / t3)\n wkss(k) = 0.5d0 * (t3 + 1.d0 / t3) * u2\n\n if (wkss(k) * eps2 > 1.d0) goto 100\nenddo\n\nwrite (6, 2) nq2\n2 format ('initqss: Table space parameter is too small; value =',i8)\nstop\n\n100 continue\n\nxkss(-1) = mpreal (dble (k), nwds1)\nif (ndebug >= 2) then\n write (6, 3) k\n3 format ('initqss: Table spaced used =',i8)\nendif\n\nreturn\nend\n\nfunction quadss (fun, nq1, nq2, nwds1, neps1, wkss, xkss)\n\n! This routine computes the integral of the function fun on the interval\n! (-inf, inf) with a target tolerance of 10^neps1. The quadrature level is\n! progressively increased (approximately doubling the work with each level)\n! until level nq1 has been performed or the target tolerance has been met.\n! nq2 is the size of the wkss and xkss arrays, which must first be \n! initialized by calling initqss. If quadss outputs the message \"Terms too\n! large\", adjust nq1 and neps2 as necessary in the call to initqss.\n\n! Both initqss and quadss are 100% THREAD SAFE -- all requisite parameters\n! and arrays are passed through subroutine arguments. \n\n! David H Bailey 31 Jan 2020\n\nuse mpmodule\nimplicit none\ninteger i, ierror, ip(0:100), iz1, iz2, izx, j, k, k1, k2, n, ndebug, &\n nds, neps1, nq1, nq2, nqq1, nwds1\nparameter (izx = 5, ndebug = 2)\nreal (8) d1, d2, d3, d4, dplog10q\ntype (mp_real) c10, eps1, eps2, epsilon1, err, fun, h, &\n quadss, tsum, s1, s2, s3, t1, t2, t3, tw1, tw2, twi1, twi2, twmx, &\n wkss(-1:nq2), xkss(-1:nq2)\nexternal fun, dplog10q\n\nepsilon1 = mpreal (10.d0, nwds1) ** neps1\ntsum = mpreal (0.d0, nwds1)\ns1 = mpreal (0.d0, nwds1)\ns2 = mpreal (0.d0, nwds1)\nh = mpreal (1.d0, nwds1)\nc10 = mpreal (10.d0, nwds1)\n\nif (wkss(-1) < dble (nq1)) then\n write (6, 1) nq1\n1 format ('quadss: quadrature arrays have not been initialized; nq1 =',i6)\n goto 140\nendif\nnqq1 = dble (wkss(-1))\nn = dble (xkss(-1))\n\ndo k = 0, nqq1\n ip(k) = 2 ** k\nenddo\n\ndo k = 1, nq1\n h = 0.5d0 * h\n s3 = s2\n s2 = s1\n k1 = ip(nqq1-k)\n k2 = ip(nqq1-k+1)\n iz1 = 0\n iz2 = 0\n twmx = mpreal (0.d0, nwds1)\n\n! Evaluate function at level k in x, avoiding unnecessary computation.\n\n do i = 0, n, k1\n if (mod (i, k2) /= 0 .or. k == 1) then\n if (iz1 < izx) then\n t1 = fun (xkss(i), nwds1)\n tw1 = t1 * wkss(i)\n twi1 = abs (tw1)\n if (twi1 < epsilon1) then\n iz1 = iz1 + 1\n else\n iz1 = 0\n endif\n else\n t1 = mpreal (0.d0, nwds1)\n tw1 = mpreal (0.d0, nwds1)\n endif\n\n if (i > 0 .and. iz2 < izx) then\n t2 = fun (-xkss(i), nwds1)\n tw2 = t2 * wkss(i)\n twi2 = abs (tw2)\n if (twi2 < epsilon1) then\n iz2 = iz2 + 1\n else\n iz2 = 0\n endif\n else\n t2 = mpreal (0.d0, nwds1)\n tw2 = mpreal (0.d0, nwds1)\n endif\n\n tsum = tsum + tw1 + tw2\n twmx = max (twmx, abs (tw1), abs (tw2))\n endif\n enddo\n\n! Compute s1 = current integral approximation and err = error estimate.\n! Tsum is the sum of all tw1 and tw2 from the loop above.\n! Twmx is the largest absolute value of tw1 and tw2 from the loop above.\n! Twi1 and twi2 are the final nonzero values of abs(tw1) and abs(tw2).\n\n s1 = h * tsum\n eps1 = twmx * epsilon1\n eps2 = abs (max (twi1, twi2) / s1)\n d1 = dplog10q (abs ((s1 - s2) / s1))\n d2 = dplog10q (abs ((s1 - s3) / s1))\n d3 = dplog10q (eps1) - 1.d0\n d4 = dplog10q (eps2) - 1.d0\n\n if (k <= 2) then\n err = mpreal (1.d0, nwds1)\n elseif (d1 .eq. -999999.d0) then\n err = mpreal (0.d0, nwds1)\n else\n err = c10 ** nint (min (0.d0, max (d1 ** 2 / d2, 2.d0 * d1, d3, d4)))\n endif\n\n! Output current integral approximation and error estimate, to 60 digits.\n\n if (ndebug >= 2) then\n write (6, 2) k, nq1, nint (dplog10q (abs (err)))\n2 format ('quadss: Iteration',i3,' of',i3,'; est error = 10^',i7, &\n '; approx value =')\n call mpwrite (6, 80, 60, s1)\n endif\n\n if (k >= 3 .and. iz1 == 0 .and. iz2 == 0) then\n write (6, 3)\n3 format ('quadss: Terms too large -- adjust neps2 in call to initqss.')\n goto 140\n endif\n\n if (k >= 3 .and. err < eps1) then\n write (6, 4) nint (dplog10q (abs (err)))\n4 format ('quadss: Estimated error = 10^',i7)\n goto 140\n endif\n\n if (k >= 3 .and. err < eps2) then\n write (6, 5) nint (dplog10q (abs (err)))\n5 format ('quadss: Estimated error = 10^',i7/&\n 'Adjust nq1 and neps2 in initqss for greater accuracy.')\n goto 140\n endif\nenddo\n\n140 continue\n\nquadss = s1\nreturn\nend\n\nsubroutine initqts (nq1, nq2, nwds1, neps2, wkts, xkts)\n\n! This subroutine initializes the quadrature arrays xkts and wkts for quadts.\n! The argument nq2 is the space allocated for wkts and xkts in the calling\n! program. By default it is set to 12 * 2^nq1. If initqts outputs the message\n! \"Table space parameter is too small\", adjust nq2. Also, if quadts outputs\n! the message \"Terms too large\", adjust nq1 and neps2 as necessary in the call\n! to initqts. The argument neps2 controls termination of the loop below, which\n! ends when wkts(k) < 10^(neps2).\n\n! The wkts and xkts arrays are computed based on the transformation\n! t = tanh (pi/2 * sinh (x)). Note however that xkts contains one minus the\n! conventional abscissas, in order to conserve precision. See comments below.\n\n! Both initqts and quadts are 100% THREAD SAFE -- all requisite parameters\n! and arrays are passed through subroutine arguments. \n\n! David H Bailey 31 Jan 2020\n\nuse mpmodule\nimplicit none\ninteger i, ierror, iprint, j, k, k1, ndebug, neps2, nq1, nq2, nwds1\nparameter (iprint = 1024, ndebug = 2)\ntype (mp_real) eps2, h, p2, t1, t2, t3, t4, u1, u2, wkts(-1:nq2), xkts(-1:nq2)\n\nwrite (6, 1)\n1 format ('initqts: Tanh-sinh quadrature initialization')\n\neps2 = mpreal (10.d0, nwds1) ** neps2\np2 = 0.5d0 * mppi (nwds1)\nh = mpreal (0.5d0 ** nq1, nwds1)\nwkts(-1) = mpreal (dble (nq1), nwds1)\n\ndo k = 0, nq2\n if (ndebug >= 2 .and. mod (k, iprint) == 0) write (6, *) k, nq2\n t1 = mpreal (dble (k) * h, nwds1)\n\n! xkts(k) = 1 - tanh (u1) = 1 /(e^u1 * cosh (u1))\n! wkts(k) = u2 / cosh (u1)^2\n! where u1 = pi/2 * cosh (t1), u2 = pi/2 * sinh (t1)\n\n t2 = exp (t1)\n u1 = 0.5d0 * p2 * (t2 + 1.d0 / t2)\n u2 = 0.5d0 * p2 * (t2 - 1.d0 / t2)\n t3 = exp (u2)\n t4 = 0.5d0 * (t3 + 1.d0 / t3)\n xkts(k) = 1.d0 / (t3 * t4)\n wkts(k) = u1 / t4 ** 2\n\n if (wkts(k) < eps2) goto 100\nenddo\n\nwrite (6, 2) nq2\n2 format ('initqts: Table space parameter is too small; value =',i8)\nstop\n\n100 continue\n\nxkts(-1) = mpreal (dble (k), nwds1)\nif (ndebug >= 2) then\n write (6, 3) k\n3 format ('initqts: Table spaced used =',i8)\nendif\n\nreturn\nend\n\nfunction quadts (fun, x1, x2, nq1, nq2, nwds1, nwds2, neps1, wkts, xkts)\n\n! This routine computes the integral of the function fun on the interval\n! (x1, x2) with a target tolerance of 10^neps1. The quadrature level is\n! progressively increased (approximately doubling the work with each level)\n! until level nq1 has been performed or the target tolerance has been met.\n! nq2 is the size of the wkts and xkts arrays, which must first be \n! initialized by calling initqts. If quadts outputs the message \"Terms too\n! large\", adjust nq1 and neps2 as necessary in the call to initqts.\n\n! Both initqts and quadts are 100% THREAD SAFE -- all requisite parameters\n! and arrays are passed through subroutine arguments. \n\n! For some functions, it is important that the endpoint x1 be\n! computed to high precision (nwds2 words) in the calling program, that\n! these high-precision values be passed to quadts (where scaled abscissas\n! are calculated to high precision), and that the function definition\n! itself uses these high-precision scaled abscissas in any initial\n! subtractions or other sensitive operations involving the input argument.\n! Otherwise the accuracy of the quadrature result might only be half as\n! high as it otherwise could be. See the function definitions of fun06,\n! fun07, fun09 and fun10 for examples on how this is done. Otherwise the\n! function evaluation can and should be performed with low precision\n! (nwds1 words) for faster run times. The two precision levels (nwds1\n! and nwds2) are specified by the user in the calling program.\n\n! David H Bailey 31 Jan 2020\n\nuse mpmodule\nimplicit none\ninteger i, ierror, ip(0:100), iz1, iz2, izx, j, k, k1, k2, n, ndebug, &\n nds, neps1, nq1, nq2, nqq1, nwds1, nwds2\nparameter (izx = 5, ndebug = 2)\nlogical log1, log2\nreal (8) d1, d2, d3, d4, dplog10q\ntype (mp_real) c10, eps1, eps2, epsilon1, err, fun, h, &\n quadts, tsum, s1, s2, s3, t1, t2, t3, tw1, tw2, twi1, twi2, twmx, &\n wkts(-1:nq2), xkts(-1:nq2)\ntype (mp_real) ax, bx, x1, x2, xki, xt1, xx1, xx2\nexternal fun, dplog10q\n\n! These two lines are performed in high precision (nwds2 words).\n\nax = 0.5d0 * (x2 - x1)\nbx = 0.5d0 * (x2 + x1)\n\n! The remaining initialization is performed in low precision (nwds1 words).\n\nepsilon1 = mpreal (10.d0, nwds1) ** neps1\ntsum = mpreal (0.d0, nwds1)\ns1 = mpreal (0.d0, nwds1)\ns2 = mpreal (0.d0, nwds1)\nh = mpreal (1.d0, nwds1)\nc10 = mpreal (10.d0, nwds1)\n\nif (wkts(-1) < dble (nq1)) then\n write (6, 1) nq1\n1 format ('quadts: Quadrature arrays have not been initialized; nq1 =',i6)\n goto 140\nendif\nnqq1 = dble (wkts(-1))\nn = dble (xkts(-1))\n\ndo k = 0, nqq1\n ip(k) = 2 ** k\nenddo\n\ndo k = 1, nq1\n h = 0.5d0 * h\n s3 = s2\n s2 = s1\n k1 = ip(nqq1-k)\n k2 = ip(nqq1-k+1)\n iz1 = 0\n iz2 = 0\n twmx = mpreal (0.d0, nwds1)\n\n! Evaluate function at level k in x, avoiding unnecessary computation.\n\n do i = 0, n, k1 \n if (mod (i, k2) /= 0 .or. k == 1) then\n\n! These next few lines, which scale the abscissas, must be performed in\n! high precision (nwds2 words) to ensure full accuracy in the quadrature\n! results, even though the abscissas xkts(i) were computed in low precision.\n\n xki = xkts(i)\n xt1 = 1.d0 - mpreal (xki, nwds2)\n xx1 = - ax * xt1 + bx\n xx2 = ax * xt1 + bx\n log1 = xx1 > x1\n log2 = xx2 < x2 \n\n! The remaining computations are performed in low precision (nwds1 words).\n\n if (log1 .and. iz1 < izx) then\n t1 = fun (xx1, nwds1, nwds2)\n tw1 = t1 * wkts(i)\n twi1 = abs (tw1)\n if (twi1 < epsilon1) then\n iz1 = iz1 + 1\n else\n iz1 = 0\n endif\n else\n t1 = mpreal (0.d0, nwds1)\n tw1 = mpreal (0.d0, nwds1)\n endif\n\n if (i > 0 .and. log2 .and. iz2 < izx) then\n t2 = fun (xx2, nwds1, nwds2)\n tw2 = t2 * wkts(i)\n twi2 = abs (tw2)\n if (twi2 < epsilon1) then\n iz2 = iz2 + 1\n else\n iz2 = 0\n endif\n else\n t2 = mpreal (0.d0, nwds1)\n tw2 = mpreal (0.d0, nwds1)\n endif\n\n tsum = tsum + tw1 + tw2\n twmx = max (twmx, abs (tw1), abs (tw2))\n endif\n enddo\n\n! Compute s1 = current integral approximation and err = error estimate.\n! Tsum is the sum of all tw1 and tw2 from the loop above.\n! Twmx is the largest absolute value of tw1 and tw2 from the loop above.\n! Twi1 and twi2 are the final nonzero values of abs(tw1) and abs(tw2).\n\n s1 = mpreal (ax, nwds1) * h * tsum\n eps1 = twmx * epsilon1\n eps2 = abs (max (twi1, twi2) / s1)\n d1 = dplog10q (abs ((s1 - s2) / s1))\n d2 = dplog10q (abs ((s1 - s3) / s1))\n d3 = dplog10q (eps1) - 1.d0\n d4 = dplog10q (eps2) - 1.d0\n\n if (k <= 2) then\n err = mpreal (1.d0, nwds1)\n elseif (d1 .eq. -999999.d0) then\n err = mpreal (0.d0, nwds1)\n else\n err = c10 ** nint (min (0.d0, max (d1 ** 2 / d2, 2.d0 * d1, d3, d4)))\n endif\n\n! Output current integral approximation and error estimate, to 60 digits.\n\n if (ndebug >= 2) then\n write (6, 2) k, nq1, nint (dplog10q (abs (err)))\n2 format ('quadts: Iteration',i3,' of',i3,'; est error = 10^',i7, &\n '; approx value =')\n call mpwrite (6, 80, 60, s1)\n endif\n\n if (k >= 3 .and. iz1 == 0 .and. iz2 == 0) then\n write (6, 3)\n3 format ('quadts: Terms too large -- adjust neps2 in call to initqts.')\n goto 140\n endif\n\n if (k >= 3 .and. err < eps1) then\n write (6, 4) nint (dplog10q (abs (err)))\n4 format ('quadts: Estimated error = 10^',i7)\n goto 140\n endif\n\n if (k >= 3 .and. err < eps2) then\n write (6, 5) nint (dplog10q (abs (err)))\n5 format ('quadts: Estimated error = 10^',i7/&\n 'Adjust nq1 and neps2 in initqts for greater accuracy.')\n goto 140\n endif\nenddo\n\n140 continue\n\nquadts = s1\nreturn\nend\n\nfunction dplog10q (a)\n\n! For input MP value a, this routine returns a DP approximation to log10 (a).\n\nuse mpmodule\nimplicit none\ninteger ia\nreal (8) da, dplog10q, t1\ntype (mp_real) a\n\ncall mpmdi (a, da, ia)\nif (da .eq. 0.d0) then\n dplog10q = -999999.d0\nelse\n dplog10q = log10 (abs (da)) + ia * log10 (2.d0)\nendif\n\n100 continue\nreturn\nend\n\nsubroutine decmdq (a, b, ib)\n\n! For input MP value a, this routine returns DP b and integer ib such that \n! a = b * 10^ib, with 1 <= abs (b) < 10 for nonzero a.\n\nuse mpmodule\nimplicit none\ninteger ia, ib\nreal (8) da, b, t1, xlt\nparameter (xlt = 0.3010299956639812d0)\ntype (mp_real) a\n\ncall mpmdi (a, da, ia)\nif (da .ne. 0.d0) then\n t1 = xlt * ia + log10 (abs (da))\n ib = t1\n if (t1 .lt. 0.d0) ib = ib - 1\n b = sign (10.d0 ** (t1 - ib), da)\nelse\n b = 0.d0\n ib = 0\nendif\n\nreturn\nend\n", "meta": {"hexsha": "f835150c5715ec3c0691978df3aaac15a04b4dbe", "size": 41637, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mpfun-mpfr-v10/fortran/tquad.f90", "max_stars_repo_name": "trcameron/FPML-Comp", "max_stars_repo_head_hexsha": "f71c968b5a9fc490fcce7490b8543e6c54dc7c42", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "mpfun-mpfr-v10/fortran/tquad.f90", "max_issues_repo_name": "trcameron/FPML-Comp", "max_issues_repo_head_hexsha": "f71c968b5a9fc490fcce7490b8543e6c54dc7c42", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "mpfun-mpfr-v10/fortran/tquad.f90", "max_forks_repo_name": "trcameron/FPML-Comp", "max_forks_repo_head_hexsha": "f71c968b5a9fc490fcce7490b8543e6c54dc7c42", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.734989648, "max_line_length": 82, "alphanum_fraction": 0.6443547806, "num_tokens": 16477, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391595913457, "lm_q2_score": 0.7879311856832191, "lm_q1q2_score": 0.680293163877017}} {"text": "! Routine for finding initial bounds for the golden \r\n! section method.\r\n! Igor Lopes, February 2015 \r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n!! ARGUMENTS\r\n!! XO,FO > Initial step and corresponding function\r\n!! XL,XU < Lower and upper limits\r\n!! XMAX,XMIN > Side constraints: limits for domain\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\nSUBROUTINE FINDBOUNDS1D(XO,FO,XL,XU,XMAX,XMIN)\r\n IMPLICIT NONE\r\n ! Parameters\r\n REAL(8) GOLD /1.61803398875/\r\n REAL(8) R1 /1.0D0/\r\n INTEGER MITER /50/\r\n ! Arguments\r\n REAL(8) :: XO,XL,XU,XMAX,XMIN,FO\r\n ! Locals\r\n REAL(8) :: XN,X1,FU,FL,F1,EVALFUNC1\r\n INTEGER :: I, NITER\r\n ! Begin algorithm\r\n XU=XO+R1\r\n FU=EVALFUNC1(XU)\r\n IF(FU.GE.FO)THEN\r\n ! Upper limit is found... but lower limit is not\r\n GOTO 10\r\n ENDIF\r\n XL=XO\r\n FL=FO\r\n DO\r\n X1=XU\r\n F1=FU\r\n XU=X1+(X1-XL)*GOLD\r\n IF(XU.GT.XMAX)THEN\r\n XU=XMAX\r\n GOTO 99\r\n ENDIF\r\n FU=EVALFUNC1(XU)\r\n IF(FU.GE.F1)GOTO 99\r\n XL=X1\r\n FL=F1\r\n ENDDO\r\n ! Find lower limit\r\n10 XL=XO-R1\r\n FL=EVALFUNC1(XL)\r\n IF(FL.GE.FO)GOTO 99 !XL is found\r\n DO\r\n X1=XL\r\n F1=FL\r\n XL=X1-(XU-X1)*GOLD\r\n IF(XL.LT.XMIN)THEN\r\n XL=XMIN\r\n GOTO 99\r\n ENDIF\r\n FL=EVALFUNC1(XL)\r\n IF(FL.GE.F1)GOTO 99\r\n XU=X1\r\n FU=F1\r\n ENDDO \r\n99 CONTINUE\r\nEND SUBROUTINE", "meta": {"hexsha": "c5bd669fa02bc8a8001dfdbcdafb960dc7655294", "size": 1529, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/golden_section/findbounds1d.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/findbounds1d.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/findbounds1d.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.0655737705, "max_line_length": 60, "alphanum_fraction": 0.4774362328, "num_tokens": 513, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953030553434, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6802684526853969}} {"text": "!*****************************************************************************************\n!> author: Jacob Williams\n!\n! Conversion factors.\n!\n!# See also\n!\n! 1. A. Thompson and B. N. Taylor, \"NIST Special Publication 811:\n! Guide for the use of the International System of Units\".\n! http://www.nist.gov/pml/pubs/sp811/\n\n module conversion_module\n\n use kind_module, only: wp\n use numbers_module, only: one,pi\n\n implicit none\n\n public\n\n !metric/imperial:\n real(wp),parameter :: lbm2kg = 0.45359237_wp !! exact\n real(wp),parameter :: lbf2N = 4.4482216152605_wp !! exact\n real(wp),parameter :: ft2m = 0.3048_wp !! exact\n real(wp),parameter :: mile2km = 1.609344_wp !! exact\n real(wp),parameter :: nmi2km = 1.852_wp !! exact\n real(wp),parameter :: slug2kg = lbf2N/ft2m !! approximately 14.593902937206362\n real(wp),parameter :: kg2lbm = one/lbm2kg !! approximately 2.2046226218487757\n real(wp),parameter :: N2lbf = one/lbf2N !! approximately 0.2248089430997105\n real(wp),parameter :: m2ft = one/ft2m !! approximately 3.280839895013123\n real(wp),parameter :: km2mile = one/mile2km !! approximately 0.621371192237334\n real(wp),parameter :: km2nmi = one/nmi2km !! approximately 0.5399568034557235\n real(wp),parameter :: kg2slug = ft2m/lbf2N !! approximately 0.06852176585679176\n\n !angles:\n real(wp),parameter :: deg2rad = pi/180.0_wp\n real(wp),parameter :: rad2deg = 180.0_wp/pi\n\n !metric:\n real(wp),parameter :: km2m = 1000.0_wp\n real(wp),parameter :: m2km = one/km2m\n real(wp),parameter :: au2m = 149597870700.0_wp !! IAU 2012 defined value\n\n !time:\n real(wp),parameter :: min2sec = 60.0_wp\n real(wp),parameter :: hr2min = 60.0_wp\n real(wp),parameter :: day2hr = 24.0_wp\n real(wp),parameter :: year2day = 365.25_wp !! julian year\n real(wp),parameter :: century2day = year2day*100.0_wp !! julian century\n real(wp),parameter :: deg2arcmin = 60.0_wp\n real(wp),parameter :: deg2arcsec = 3600.0_wp\n real(wp),parameter :: hr2sec = hr2min*min2sec\n real(wp),parameter :: day2min = day2hr*hr2min\n real(wp),parameter :: day2sec = day2min*min2sec\n real(wp),parameter :: century2sec = century2day*day2sec\n real(wp),parameter :: day2year = one/year2day\n real(wp),parameter :: day2century = one/century2day\n real(wp),parameter :: hr2day = one/day2hr\n real(wp),parameter :: sec2hr = one/hr2sec\n real(wp),parameter :: sec2day = one/day2sec\n real(wp),parameter :: sec2century = one/century2sec\n real(wp),parameter :: arcmin2deg = one/deg2arcmin\n real(wp),parameter :: arcsec2deg = one/deg2arcsec\n\n end module conversion_module\n!*****************************************************************************************\n", "meta": {"hexsha": "0fd90c2624a3ae3fc4507cb7ea4db3b8cd240673", "size": 2921, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/conversion_module.f90", "max_stars_repo_name": "jacobwilliams/Fortran-Astrodynamics-Toolk", "max_stars_repo_head_hexsha": "f8e18642dc8d78473d233b8fa6078fdbf7a1d6fc", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 122, "max_stars_repo_stars_event_min_datetime": "2015-01-29T05:40:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:20:21.000Z", "max_issues_repo_path": "src/conversion_module.f90", "max_issues_repo_name": "gandymagic/Fortran-Astrodynamics-Toolkit", "max_issues_repo_head_hexsha": "7f176fabc8c36cc1981349b02eeb6d8112f2bfbc", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 25, "max_issues_repo_issues_event_min_datetime": "2015-06-10T02:16:59.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T04:28:55.000Z", "max_forks_repo_path": "src/conversion_module.f90", "max_forks_repo_name": "gandymagic/Fortran-Astrodynamics-Toolkit", "max_forks_repo_head_hexsha": "7f176fabc8c36cc1981349b02eeb6d8112f2bfbc", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 43, "max_forks_repo_forks_event_min_datetime": "2015-02-12T13:24:23.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-30T04:30:49.000Z", "avg_line_length": 43.5970149254, "max_line_length": 90, "alphanum_fraction": 0.5963711058, "num_tokens": 896, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952948443462, "lm_q2_score": 0.7577943822145998, "lm_q1q2_score": 0.6802684513735243}} {"text": "C NCLFORTSTART\n subroutine cfftfdriver (nmx,xr,xi,acoef,bcoef,work,nw)\n implicit none\nc ! INPUT \n integer nmx,nw\n double precision xr(nmx),xi(nmx),work(nw)\nc ! OUTPUT \n double precision acoef(nmx), bcoef(nmx) \nc NCLEND\nc\nc NCL: coef = cfftf( xr, xi, opt) ! coef(2,...)\nc ! LOCAL \n integer n\nc double precision work(4*nmx+25) \n double complex carr(nmx) \n\n call cffti(nmx,work) \nc ! create complex input\n do n=1,nmx\n carr(n) = cmplx( xr(n), xi(n) ) \n end do\n\n call cfftf(nmx, carr, work)\n\n do n=1,nmx\n acoef(n) = dble ( carr(n) ) \n bcoef(n) = dimag( carr(n) )\n end do\n\n return\n end\n\nC NCLFORTSTART\n subroutine cfftbdriver (nmx,xr,xi,acoef,bcoef,work,nw)\n implicit none\nc ! INPUT \n integer nmx,nw\n double precision acoef(nmx), bcoef(nmx), work(nw)\nc ! OUTPUT \n double precision xr(nmx), xi(nmx)\nc NCLEND\nc\nc NCL: coef = cfftb( acoef, bcoef, opt )\nc ! LOCAL \n integer n\nc double precision work(4*nmx+25)\n double complex carr(nmx) \n\n call cffti(nmx,work) \nc ! create complex input\n do n=1,nmx\n carr(n) = cmplx( acoef(n), bcoef(n)) \n end do\n\n call cfftb(nmx, carr, work)\nc ! reconstruct ... normalize \n do n=1,nmx\n xr(n) = dble ( carr(n) ) / nmx\n xi(n) = dimag( carr(n) ) / nmx\n end do\n\n return\n end\n\nC NCLFORTSTART\n subroutine frqcfft (npts,frq)\n implicit none\nc\nc SPECIAL to generate frequencies for frq attribute: cfftf\nc . Need to allow for a back transform so no order change\nc ! input\n integer npts\nc ! output\n double precision frq(npts)\nC NCLEND\nc ! local\n integer n\n double precision df\nc frequency interval\n df = 1.0d0/npts\nc generate frequencies\n do n=1,npts\n frq(n) = (n-1)*df\n if (frq(n).gt.0.5d0) frq(n) = frq(n) - 1.0d0\n end do\n\n return\n end\n\nC NCLFORTSTART\n subroutine cfftffrqreorder (npts,frqi,cfai,cfbi,frqo,cfao,cfbo)\n implicit none\nc\nc SPECIAL to reorder frequencies to range from -0.5 to +0.5\nc . Generally, for graphics reasons only. \nc ! input\n integer npts\n double precision frqi(npts), cfai(npts), cfbi(npts) \nc ! output\n double precision frqo(npts), cfao(npts), cfbo(npts)\nC NCLEND\nc\nc NCL: cf_reorder = cfftf_frq_reorder( cf )\nc ! local\n integer n, n2\n\n n2 = npts/2\nc for clarity use two differnt sections\n if (mod(npts,2).eq.0) then\nc ! even \n do n=1,n2\n frqo(n) = frqi(n+n2)\n cfao(n) = cfai(n+n2)\n cfbo(n) = cfbi(n+n2)\n end do\n\n if (frqo(1).gt.0.0d0) frqo(1) = -frqo(1) \n \n do n=1,n2\n frqo(n2+n) = frqi(n)\n cfao(n2+n) = cfai(n)\n cfbo(n2+n) = cfbi(n)\n end do\n else\nc ! odd \n do n=1,n2\n frqo(n) = frqi(n+n2+1)\n cfao(n) = cfai(n+n2+1)\n cfbo(n) = cfbi(n+n2+1)\n end do\n\n do n=1,n2+1\n frqo(n2+n) = frqi(n)\n cfao(n2+n) = cfai(n)\n cfbo(n2+n) = cfbi(n)\n end do\n end if\n\n return\n end\n", "meta": {"hexsha": "a67bd3885bf445449d4f86e8b42a4af57d181403", "size": 4124, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ni/src/lib/nfpfort/cfft_driver.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "ni/src/lib/nfpfort/cfft_driver.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "ni/src/lib/nfpfort/cfft_driver.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 29.2482269504, "max_line_length": 69, "alphanum_fraction": 0.4216779825, "num_tokens": 1143, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953003183444, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6802684506113145}} {"text": "module pde\n\n! This module contains all information that appears inside the PDEs.\n! It specifies how many equations shall be solved, the numerical data,\n! the routines to compute the fluxes from the solution, routines for\n! computing primitive variables from the conserved solution U, etc.\n!\n! ---------- SHALLOW WATER EQUATIONS ----------\n\n use global_module\n\n implicit none\n\n integer, parameter :: Neq = 3 ! Number of equations\n real(kind=8), parameter :: g = 9.81 ! [N/kg] Earth's gravity\n\n ! Initial conditions\n real(kind=8), parameter :: h0 = 1.0 ! [m]\n real(kind=8), parameter :: ux0 = 0.0 ! [m/s]\n real(kind=8), parameter :: uy0 = 0.0 ! [m/s]\n\n ! Name of primitive variables, used ONLY for exporting the solution to VTK file\n ! NOTE: To initialize it here, all entries need to have the same length!!!\n ! I'm using two letters for simplicity.\n character(len=20), dimension(Neq) :: prim_names = (/'hh','Ux','Uy'/)\n\n contains\n\n ! ============================================================\n\n subroutine initialize_solution(U)\n \n implicit none\n\n real(kind=8), dimension(:,:,:), intent(inout) :: U\n\n ! Initialize internal cells (i = \"1,2\" and \"Nx-1, Nx\" are ghost cells. Same thing for j)\n U(1, 3:Nx-2, 3:Ny-2) = h0 ! Density\n U(2, 3:Nx-2, 3:Ny-2) = h0*ux0 ! Momentum along x\n U(3, 3:Nx-2, 3:Ny-2) = h0*uy0 ! Momentum along y\n\n\n U(1, floor((Nx)/3.0):floor(real(Nx)/2.0), floor((Ny)/3.0):floor(real(Ny)/2.0)) = 2.0*h0\n U(2, floor((Nx)/3.0):floor(real(Nx)/2.0), floor((Ny)/3.0):floor(real(Ny)/2.0)) = 2.0*h0*ux0\n U(3, floor((Nx)/3.0):floor(real(Nx)/2.0), floor((Ny)/3.0):floor(real(Ny)/2.0)) = 2.0*h0*uy0\n\n end subroutine \n\n ! ============================================================\n\n subroutine assign_BCs(U)\n\n ! This subroutine assigns boundary values to the ghost cells. \n ! In this form, we impose periodic BCs, by copying into the ghost cells the values inside the \n ! domain cells at the other side of the domain.\n \n implicit none\n\n real(kind=8), dimension(:,:,:), intent(inout) :: U\n\n integer :: i, j\n\n ! Periodic BCs\n U(:, 1:2, :) = U(:, Nx-3:Nx-2, :) ! Left BC\n U(:, Nx-1:Nx, :) = U(:, 3:4, :) ! Right BC\n U(:, :, 1:2) = U(:, :, Ny-3:Ny-2) ! Bottom BC\n U(:, :, Ny-1:Ny) = U(:, :, 3:4) ! Top BC\n\n end subroutine \n\n ! ============================================================\n\n subroutine compute_primitive_from_conserved(U, prim)\n\n ! Computes vector of primitive variables \"prim\" from the conserved variables \"U\"\n\n implicit none\n\n real(kind=8), dimension(Neq), intent(in) :: U\n real(kind=8), dimension(Neq), intent(out) :: prim\n\n ! Working variables\n real(kind=8) :: h, ux, uy\n\n ! Extract primitive variables\n h = U(1)\n ux = U(2)/(h + 1.0d-25) ! Use a small tolerance, since h may be zero\n uy = U(3)/(h + 1.0d-25) ! Use a small tolerance, since h may be zero\n\n ! Compose array of primitive variables\n prim(1) = h\n prim(2) = ux\n prim(3) = uy \n\n end subroutine\n \n ! ============================================================\n\n subroutine compute_conserved_from_primitive(prim, U)\n\n ! Computes vector of conserved variables \"U\" from the primitive variables \"prim\"\n\n implicit none\n\n real(kind=8), dimension(Neq), intent(in) :: prim\n real(kind=8), dimension(Neq), intent(out) :: U\n\n ! Working variables\n\n U(1) = prim(1)\n U(2) = prim(1)*prim(2)\n U(3) = prim(1)*prim(3)\n\n end subroutine\n \n ! ============================================================\n\n subroutine compute_flux_ws_x(U, Fx, ws_max, ws_min)\n\n ! Computes the convective flux along x,\n ! and also the maximum and minimum wave speeds (required by some numerical flux schemes)\n\n implicit none\n\n real(kind=8), dimension(Neq), intent(in) :: U\n real(kind=8), dimension(Neq), intent(out) :: Fx\n real(kind=8), intent(out) :: ws_max, ws_min\n \n real(kind=8), dimension(Neq) :: prim\n real(kind=8) :: h, ux, uy\n \n ! Compute primitive variables\n call compute_primitive_from_conserved(U, prim)\n h = prim(1)\n ux = prim(2)\n uy = prim(3)\n\n ! Assemble fluxes Fx\n Fx(1) = h*ux\n Fx(2) = h*ux*ux + 0.5*g*h**2\n Fx(3) = h*ux*uy\n \n ! Maximum and minimum wave speeds (eigenvalues of the Euler system)\n ws_max = ux + sqrt(g*h)\n ws_min = ux - sqrt(g*h)\n\n end subroutine\n\n ! ============================================================\n\n subroutine compute_flux_ws_y(U, Fy, ws_max, ws_min)\n\n ! Computes the convective flux along y,\n ! and also the maximum and minimum wave speeds (required by some numerical flux schemes)\n\n implicit none\n\n real(kind=8), dimension(Neq), intent(in) :: U\n real(kind=8), dimension(Neq), intent(out) :: Fy\n real(kind=8), intent(out) :: ws_max, ws_min\n \n real(kind=8), dimension(Neq) :: prim\n real(kind=8) :: h, ux, uy\n \n ! Compute primitive variables\n call compute_primitive_from_conserved(U, prim)\n h = prim(1)\n ux = prim(2)\n uy = prim(3)\n\n ! Assemble fluxes Fx\n Fy(1) = h*uy\n Fy(2) = h*ux*uy\n Fy(3) = h*uy*uy + 0.5*g*h*h\n \n ! Maximum and minimum wave speeds (eigenvalues of the Euler system)\n ws_max = uy + sqrt(g*h)\n ws_min = uy - sqrt(g*h)\n\n end subroutine\n\nend module\n", "meta": {"hexsha": "cb90bb0317e78027ac6d21e94df239999e0b6549", "size": 5296, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "hyper2D_single_core/hyper2D_basic/src_higher_order/src/pde.f03", "max_stars_repo_name": "sbocce/hyper2D", "max_stars_repo_head_hexsha": "7d1510ac3947b2c154aa0c09945ff05db4bfc8c4", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2022-02-17T14:26:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T01:56:37.000Z", "max_issues_repo_path": "hyper2D_single_core/hyper2D_basic/src_higher_order/src/pde.f03", "max_issues_repo_name": "sbocce/hyper2D", "max_issues_repo_head_hexsha": "7d1510ac3947b2c154aa0c09945ff05db4bfc8c4", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2022-02-28T10:22:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-01T06:25:03.000Z", "max_forks_repo_path": "hyper2D_single_core/hyper2D_basic/src_higher_order/src/pde.f03", "max_forks_repo_name": "sbocce/hyper2D", "max_forks_repo_head_hexsha": "7d1510ac3947b2c154aa0c09945ff05db4bfc8c4", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.9398907104, "max_line_length": 96, "alphanum_fraction": 0.5692975831, "num_tokens": 1613, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6802684443890669}} {"text": "! Routine for n-dimensional optimization through\r\n! quasi-Newton methods: DFP or BFGS.\r\n! Igor Lopes, February 2015 \r\nSUBROUTINE QUASINEWTON(NDIM)\r\n IMPLICIT NONE\r\n ! Parameters\r\n REAL(8) CONVTOL /1.0D-6/\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 :: NDIM\r\n ! Locals\r\n REAL(8) :: GOLD, FO, TOL, EVALFUNC, AMIN, FMIN, ANOR, &\r\n BNOR, BETA, THETA, SIGMA, TAU, RELDIF\r\n REAL(8),DIMENSION(NDIM) :: XO, XN, GRAD, GRADO, SDIR, XMAX, XMIN\r\n REAL(8),DIMENSION(NDIM,1) :: DX, DGRAD, AVEC\r\n REAL(8),DIMENSION(1,NDIM) :: DXT, AVECT\r\n REAL(8),DIMENSION(NDIM,NDIM) :: HMAT, DMAT, AMAT\r\n REAL(8),DIMENSION(2) :: ALPHO\r\n REAL(8),DIMENSION(4) :: ALPH, FN\r\n INTEGER :: I, ITER, MITER, NITER\r\n CHARACTER :: STRING*256\r\n ! Initialize\r\n GOLD=(R1+DSQRT(R5))/R2\r\n STRING='quasi_newton.res'\r\n CALL RESULTFILE(STRING)\r\n HMAT=R0\r\n DO I=1,NDIM\r\n HMAT(I,I)=R1\r\n ENDDO\r\n ! Formats\r\n5 FORMAT('-------------------------------------------------------------------------')\r\n10 FORMAT('ITER.',6X,('X_'I3,10X),'F',14X,'alpha')\r\n15 FORMAT(I3,4X,(G12.6,3X),G12.6,3X,G12.6) \r\n ! Begin algorithm\r\n20 WRITE(*,*)'Define THETA value:'\r\n WRITE(*,*)'0 - DFP (minimum)'\r\n WRITE(*,*)'1 - BFGS (maximum)'\r\n READ(*,*)THETA\r\n IF(THETA.LT.R0.OR.THETA.GT.R1)THEN\r\n WRITE(*,*)'THETA out of range.'\r\n GOTO 20\r\n ENDIF\r\n WRITE(*,*)'Define limits for each variable:'\r\n WRITE(11,*)'Variables limits:'\r\n WRITE(11,*)'i Xmin Xmax'\r\n DO I=1,NDIM\r\n WRITE(*,*)'Xmin_',I,' Xmax_',I\r\n READ(*,*)XMIN(I),XMAX(I)\r\n WRITE(11,*)I,XMIN(I),XMAX(I)\r\n ENDDO\r\n WRITE(*,*)'Give an initial guess for design variables X'\r\n READ(*,*)(XO(I),I=1,NDIM)\r\n WRITE(*,*)'Define maximum number of iterations'\r\n READ(*,*)MITER\r\n WRITE(*,*)'Define tolerance for step search'\r\n READ(*,*)TOL\r\n WRITE(11,*)'THETA=',THETA\r\n WRITE(11,*)'Maximum number of iterations=',MITER\r\n WRITE(11,*)'Tolerance for step search=',TOL\r\n NITER=INT(LOG(TOL)/LOG(GOLD-R1))+R1\r\n !\r\n FO=EVALFUNC(XO,NDIM)\r\n WRITE(11,5)\r\n WRITE(*,5)\r\n WRITE(11,10)(I,I=1,NDIM)\r\n WRITE(*,10)(I,I=1,NDIM)\r\n WRITE(11,5)\r\n WRITE(*,5)\r\n WRITE(11,15)0,XO,FO\r\n WRITE(*,15)0,XO,FO\r\n !\r\n CALL GRADIENT(GRAD,XO,NDIM)\r\n DO ITER=1,MITER\r\n CALL MATPRD(HMAT,GRAD,SDIR,NDIM,NDIM,1)\r\n SDIR=-SDIR\r\n CALL FINDBOUNDS(XO,FO,ALPHO(1),ALPHO(2),XMAX,XMIN,SDIR,NDIM)\r\n CALL GOLDENSECTIONNDIM(XO,ALPHO,ALPH,FN,NITER,SDIR,NDIM)\r\n ! Determine minimum\r\n AMIN=ALPH(1)\r\n FMIN=FN(1)\r\n DO I=2,4\r\n IF(FN(I).LT.FMIN)THEN\r\n FMIN=FN(I)\r\n AMIN=ALPH(I)\r\n ENDIF\r\n ENDDO\r\n XN=XO+AMIN*SDIR\r\n WRITE(11,15)ITER,(XN(I),I=1,NDIM),FMIN,AMIN\r\n WRITE(*,15)ITER,(XN(I),I=1,NDIM),FMIN,AMIN\r\n ! Check convergence\r\n RELDIF=DABS(FMIN-FO)\r\n IF(DABS(FO).GT.CONVTOL)RELDIF=RELDIF/DABS(FO)\r\n IF(RELDIF.LT.CONVTOL)THEN\r\n !FINISH PROCESS\r\n GOTO 99\r\n ENDIF\r\n ! Update HMAT\r\n GRADO=GRAD\r\n CALL GRADIENT(GRAD,XN,NDIM)\r\n DO I=1,NDIM\r\n DX(I,1)=XN(I)-XO(I)\r\n DGRAD(I,1)=GRAD(I)-GRADO(I)\r\n ENDDO\r\n SIGMA=DOT_PRODUCT(DX(:,1),DGRAD(:,1))\r\n CALL TRANSPOSE(DX,DXT,NDIM,1)\r\n CALL MATPRD(HMAT,DGRAD,AVEC,NDIM,NDIM,1)\r\n TAU=DOT_PRODUCT(DGRAD(:,1),AVEC(:,1))\r\n CALL MATPRD(DX,DXT,AMAT,NDIM,1,NDIM)\r\n DMAT=AMAT*(SIGMA+TAU*THETA)/(SIGMA*SIGMA)\r\n CALL TRANSPOSE(AVEC,AVECT,NDIM,1)\r\n CALL MATPRD(AVEC,AVECT,AMAT,NDIM,1,NDIM)\r\n DMAT=DMAT+AMAT*(THETA-R1)/TAU\r\n CALL MATPRD(AVEC,DXT,AMAT,NDIM,1,NDIM)\r\n DMAT=DMAT-AMAT*THETA/SIGMA\r\n CALL MATPRD(DX,AVECT,AMAT,NDIM,1,NDIM)\r\n DMAT=DMAT-AMAT*THETA/SIGMA\r\n HMAT=HMAT+DMAT\r\n XO=XN\r\n FO=FMIN\r\n ENDDO\r\n99 WRITE(11,5)\r\n WRITE(*,5)\r\n CLOSE(UNIT=11)\r\nEND SUBROUTINE", "meta": {"hexsha": "4b5299078ea292745882b567fc2ea897dbbc29f2", "size": 4158, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/quasi_newton/quasinewton.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/quasi_newton/quasinewton.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/quasi_newton/quasinewton.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": 32.7401574803, "max_line_length": 88, "alphanum_fraction": 0.5324675325, "num_tokens": 1576, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952921073469, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6802684443890668}} {"text": "module dimensions\n implicit none\n integer, parameter :: width = 1000\n integer, parameter :: height = 1000\nend module dimensions\n\nprogram main\n use dimensions\n implicit none\n \n double precision, parameter :: temp_tolerance = 0.01\n double precision :: worst_dt = 100.0\n integer :: i, j\n integer :: iteration = 1\n real :: begin_time, end_time, elapsed\n\n double precision :: temperature(0:height+1, 0:width+1)\n double precision :: temperature_previous(0:height+1, 0:width+1) \n\n ! Start measuring time\n call cpu_time(begin_time)\n\n ! initialize temperature profile\n call initialize(temperature_previous)\n\n do while (worst_dt > temp_tolerance)\n ! finite difference\n do j = 1, width\n do i = 1, height\n temperature(i,j) = 0.25 * (temperature_previous(i+1,j) &\n + temperature_previous(i-1,j) &\n + temperature_previous(i,j+1) &\n + temperature_previous(i,j-1)); \n enddo\n enddo\n \n ! calculate max difference between temperature and temperature_previous\n worst_dt = 0.0\n do j = 1, width\n do i = 1, height\n worst_dt = max(abs(temperature(i,j) - &\n temperature_previous(i,j)), & \n worst_dt);\n enddo\n enddo\n\n ! update temperature_previous\n do j = 1, width\n do i = 1, height\n temperature_previous(i,j) = temperature(i,j)\n enddo\n enddo\n\n ! track progress\n if (mod(iteration, 100) == 0) then\n call track_progress(iteration, temperature)\n endif\n\n iteration = iteration + 1\n enddo\n\n ! Stop measuring time and calculate the elapsed time\n call cpu_time(end_time)\n elapsed = end_time - begin_time\n\n write(*, '(\"Total time was \", f9.6, \" seconds.\")') elapsed\n write(*, '(\"Max error at iteration \", i0, \" was \", f9.6)') iteration-1, worst_dt\n\nend program main\n\nsubroutine initialize(temperature_previous)\n use dimensions\n implicit none\n\n double precision :: temperature_previous(0:height+1, 0:width+1) \n integer :: i,j\n\n ! initialize temperature_previous to 0.0\n do j = 0, width+1\n do i = 0, height+1\n temperature_previous(i,j) = 0.0 \n enddo\n enddo\n\n ! setting the left and right boundary conditions\n do i = 0, height+1\n temperature_previous(i,0) = 0.0\n temperature_previous(i,width+1) = (100.0/height)*i\n enddo\n\n ! setting the top and bottom boundary condition\n do j = 0, width+1\n temperature_previous(0,j) = 0.0\n temperature_previous(height+1,j) = (100.0/width)*j \n enddo\nend subroutine initialize\n\nsubroutine track_progress(iteration, temperature)\n use dimensions\n implicit none\n\n integer :: iteration\n double precision :: temperature(0:height+1, 0:width+1)\n integer :: i\n\n write(*, '(\"---------- Iteration number: \", i0, \" ----------\")') iteration\n do i = height-5, height\n write(*, '(\"[\"i0,\",\"i0,\"]:\",f6.2,\" \")', advance='no') &\n i, i, temperature(i,i)\n enddo\n write(*,*)\nend subroutine track_progress", "meta": {"hexsha": "289df02ac284f199fe521ad9872693a62bc3a709", "size": 3447, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/laplace/main_fortran.f90", "max_stars_repo_name": "jfkiviaho/MATAR", "max_stars_repo_head_hexsha": "e866a804e8f2082a78b026d6fd20a1cc03305d1b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-06-09T17:00:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T15:57:16.000Z", "max_issues_repo_path": "test/laplace/main_fortran.f90", "max_issues_repo_name": "jfkiviaho/MATAR", "max_issues_repo_head_hexsha": "e866a804e8f2082a78b026d6fd20a1cc03305d1b", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-12T16:42:30.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-22T16:14:08.000Z", "max_forks_repo_path": "test/laplace/main_fortran.f90", "max_forks_repo_name": "jfkiviaho/MATAR", "max_forks_repo_head_hexsha": "e866a804e8f2082a78b026d6fd20a1cc03305d1b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2021-01-28T18:00:25.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-13T00:34:37.000Z", "avg_line_length": 30.7767857143, "max_line_length": 84, "alphanum_fraction": 0.5491731941, "num_tokens": 844, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952921073469, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6802684394786918}} {"text": " MODULE cdf_neg_binomial_mod\n! ----------------------------------------------------------------------\n\n! cdf_neg_binomial_mod\n! *=*=*=*=*=*=*=*=*=*=\n\n! - SUBROUTINE CDF_NEG_BINOMIAL(WHICH, CUM, CCUM, F, S, PR, CPR,\n! STATUS, BCHECK_INPUT)\n! - REAL (dpkind) FUNCTION CUM_NEG_BINOMIAL(F, S, N, PR, CPR, STATUS,\n! CHECK_INPUT)\n! - REAL (dpkind)FUNCTION CCUM_NEG_BINOMIAL(F, S, N, PR, CPR, STATUS,\n! CHECK_INPUT)\n! - REAL (dpkind) FUNCTION INV_NEG_BINOMIAL(CUM, CCUM, N, PR, CPR,\n! STATUS, CHECK_INPUT)\n\n! The Distribution\n! ================\n\n! The density of the negative binomial distribution provides the\n! probability of precisely F failures before the S'th success in\n! independent binomial trials, each with probability of success PR.\n! The density is:\n\n! ( F+S-1 ) S F\n! ( S-1 )PR (1-PR)\n\n! The cumulative distribution function is the probability of F or fewer\n! failures before the F'th success.The negative binomial is extended to\n! non-integer values of F via the relation between the cumulative\n! distribution function of the negative binomial and the incomplete beta\n! function.\n! Arguments\n! =========\n\n! - INTEGER, INTENT(IN) :: WHICH. Integer indicating which of the next\n! four arguments is to be calculated.\n! Input Range: [ 1:4 ]\n! - 1 CUM and CCUM\n! - 2 F\n! - 3 S\n! - 4 PR and CPR\n! - REAL (dpkind), OPTIONAL :: CUM. The CDF of the negative-binomial\n! distribution.\n! Range: [ 0:1-10^-10 ]\n! - REAL (dpkind), OPTIONAL : CCUM. One minus the CDF of the binomial\n! distribution.\n! Range: [ 10^-10:1 ]\n! - REAL (dpkind) :: F. The number of failures before the S'th success.\n! Range: [ 0: ]\n! - REAL (dpkind) :: S. The number of successes to occur.\n! Input Range: [ 0: ]\n! - REAL (dpkind) :: PR. The probability of success in each independent\n! trial.\n! Range: [ 0:1 ]\n! - REAL (dpkind) :: CPR. One minus the probability of success in each\n! independent trial; the probability of failure in each trial.\n! Range: [ 0:1 ]\n! - INTEGER, OPTIONAL, INTENT(OUT) :: STATUS. Return code. Possible values:\n! 0 problem successfully solved\n! -1 WHICH outside input range\n! -2 CUM outside range\n! -3 CCUM outside range\n! -4 F outside range\n! -5 S outside range\n! -6 PR outside range\n! -7 CPR outside range\n! 3 CUM + CCUM is not nearly one\n! 4 PR + CPR is not nearly one\n! 10 cdf_beta (in local_cum_neg_binomial) has no answer.\n! -50 Answer (if any) is BELOW the LOWER search bound\n! 50 Answer (if any) is ABOVE the UPPER search bound\n! - LOGICAL, INTENT(IN), OPTIONAL :: CHECK_INPUT. If PRESENT and\n! .TRUE. input argument values are not checked for validity.\n\n! NOTE: CUM and CCUM and also PR and CPR must add to (nearly) one.\n! ----------------------------------------------------------------------\n! .. Use Statements ..\n USE biomath_constants_mod\n! ..\n! .. Default Accessibility ..\n PRIVATE\n! ..\n! .. Public Statements ..\n PUBLIC :: ccum_neg_binomial, cdf_neg_binomial, cum_neg_binomial, &\n inv_neg_binomial\n! ..\n CONTAINS\n\n!*********************************************************************\n\n FUNCTION ccum_neg_binomial(f,s,pr,cpr,status,check_input)\n! .. Function Return Value ..\n REAL (dpkind) :: ccum_neg_binomial\n! ..\n! .. Scalar Arguments ..\n REAL (dpkind), OPTIONAL, INTENT (IN) :: cpr, pr\n REAL (dpkind), INTENT (IN) :: f, s\n INTEGER, OPTIONAL, INTENT (OUT) :: status\n LOGICAL, OPTIONAL, INTENT (IN) :: check_input\n! ..\n CALL cdf_neg_binomial(which=1,cum=ccum_neg_binomial,f=f,s=s, &\n pr=pr,cpr=cpr,status=status,check_input=check_input)\n\n RETURN\n\n END FUNCTION ccum_neg_binomial\n\n!*********************************************************************\n\n SUBROUTINE cdf_neg_binomial(which,cum,ccum,f,s,pr,cpr,status, &\n check_input)\n! .. Use Statements ..\n USE cdf_aux_mod\n USE zero_finder\n! ..\n! .. Scalar Arguments ..\n REAL (dpkind), OPTIONAL :: ccum, cpr, cum, pr\n REAL (dpkind) :: f, s\n INTEGER, OPTIONAL, INTENT (OUT) :: status\n INTEGER, INTENT (IN) :: which\n LOGICAL, OPTIONAL, INTENT (IN) :: check_input\n! ..\n! .. Local Structures ..\n TYPE (zf_locals) :: local\n! ..\n! .. Local Arrays ..\n REAL (dpkind) :: params(6)\n! ..\n! .. Local Scalars ..\n REAL (dpkind) :: fx, local_ccum, local_cpr, local_cum, local_pr, &\n try_ccum, try_cpr, try_cum, try_pr\n INTEGER :: zf_status\n LOGICAL :: has_status, local_check_input, match_cum, vary_pr\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC PRESENT\n! ..\n has_status = PRESENT(status)\n\n! status = 0 means NO error\n\n IF (has_status) THEN\n status = 0\n END IF\n\n! Check that at least one of cum, ccum is present in the calling list\n\n CALL check_complements(cum,ccum,the_negative_binomial%name,'cum', &\n 'ccum',local_cum,local_ccum,set_values=(which/=1),bad_status=3, &\n status=status)\n\n IF (has_status) THEN\n IF (status/=0) THEN\n RETURN\n END IF\n END IF\n\n CALL check_complements(pr,cpr,the_negative_binomial%name,'pr', &\n 'cpr',local_pr,local_cpr,set_values=(which/=4),bad_status=4, &\n status=status)\n\n IF (has_status) THEN\n IF (status/=0) THEN\n RETURN\n END IF\n END IF\n\n!==========\n! Check that probabilities add to one\n!==========\n\n IF (which/=4) THEN\n IF ( .NOT. add_to_one(local_pr,local_cpr,the_binomial%name,'pr' &\n ,'cpr',4,status)) RETURN\n END IF\n\n params(1) = local_cum\n params(2) = local_ccum\n params(3) = f\n params(4) = s\n params(5) = local_pr\n params(6) = local_cpr\n\n IF (PRESENT(check_input)) THEN\n local_check_input = check_input\n ELSE\n local_check_input = .TRUE.\n END IF\n\n IF (local_check_input) THEN\n CALL validate_parameters(the_negative_binomial,which,params, &\n status)\n\n IF (has_status) THEN\n IF (status/=0) THEN\n RETURN\n END IF\n END IF\n END IF\n\n!++++++++++++++++++++++++++++++++++++++++++++++++++\n! Compute the Answers\n!++++++++++++++++++++++++++++++++++++++++++++++++++\n\n IF (which>1) match_cum = (local_cum<=half)\n\n SELECT CASE (which)\n\n CASE (1)\n! Calculate cum and ccum (cdf)\n\n CALL local_cum_neg_binomial(f,s,local_pr,local_cpr,local_cum, &\n local_ccum,status)\n\n IF (PRESENT(cum)) cum = local_cum\n IF (PRESENT(ccum)) ccum = local_ccum\n\n CASE (2)\n! Calculate f\n\n f = five\n zf_status = 0\n\n CALL cdf_set_zero_finder(the_negative_binomial,3,local)\n\n DO\n CALL rc_step_zf(zf_status,f,fx,local)\n\n IF (zf_status/=1) EXIT\n\n CALL local_cum_neg_binomial(f,s,local_pr,local_cpr,try_cum, &\n try_ccum,status)\n\n IF (has_status) THEN\n IF (status/=0) THEN\n RETURN\n END IF\n END IF\n\n IF (match_cum) THEN\n fx = try_cum - local_cum\n ELSE\n fx = try_ccum - local_ccum\n END IF\n\n END DO\n\n CASE (3)\n! Calculate s\n\n s = five\n zf_status = 0\n\n CALL cdf_set_zero_finder(the_negative_binomial,4,local)\n\n DO\n CALL rc_step_zf(zf_status,s,fx,local)\n\n IF (zf_status/=1) EXIT\n\n CALL local_cum_neg_binomial(f,s,local_pr,local_cpr,try_cum, &\n try_ccum,status)\n\n IF (has_status) THEN\n IF (status/=0) THEN\n RETURN\n END IF\n END IF\n\n IF (match_cum) THEN\n fx = try_cum - local_cum\n ELSE\n fx = try_ccum - local_ccum\n END IF\n\n END DO\n\n CASE (4)\n\n! Solve for probability\n\n!!! A difficult case -- we will try to match the lesser of cum and ccum\n!!! If the answer <= 1/2 we will vary pr else we will vary cpr\n\n zf_status = 0\n\n! Decide whether to vary pr or cpr\n\n CALL local_cum_neg_binomial(f,s,half,half,try_cum,try_ccum, &\n status)\n\n IF (has_status) THEN\n IF (status/=0) THEN\n RETURN\n END IF\n END IF\n\n! Opposite than for BINOMIAL distribution!!!\n\n vary_pr = (try_cum>local_cum)\n\n IF (match_cum .AND. vary_pr) THEN\n\n! We are trying to match cum varying pr\n\n CALL cdf_set_zero_finder(the_dummy_binomial,1,local)\n\n DO\n CALL rc_interval_zf(zf_status,try_pr,fx,local)\n\n IF (zf_status/=1) EXIT\n\n try_cpr = one - try_pr\n\n CALL local_cum_neg_binomial(f,s,try_pr,try_cpr,try_cum, &\n try_ccum,status)\n\n IF (has_status) THEN\n IF (status/=0) THEN\n RETURN\n END IF\n END IF\n\n fx = local_cum - try_cum\n END DO\n\n ELSE IF (match_cum .AND. .NOT. vary_pr) THEN\n! Try to match cum varying cpr\n\n CALL cdf_set_zero_finder(the_dummy_binomial,2,local)\n\n DO\n\n CALL rc_interval_zf(zf_status,try_cpr,fx,local)\n\n IF (zf_status/=1) EXIT\n\n try_pr = one - try_cpr\n\n CALL local_cum_neg_binomial(f,s,try_pr,try_cpr,try_cum, &\n try_ccum,status)\n\n IF (has_status) THEN\n IF (status/=0) THEN\n RETURN\n END IF\n END IF\n\n fx = local_cum - try_cum\n END DO\n\n ELSE IF ( .NOT. match_cum .AND. vary_pr) THEN\n! Try to match ccum varying pr\n\n CALL cdf_set_zero_finder(the_dummy_binomial,1,local)\n\n DO\n CALL rc_interval_zf(zf_status,try_pr,fx,local)\n\n IF (zf_status/=1) EXIT\n\n try_cpr = one - try_pr\n\n CALL local_cum_neg_binomial(f,s,try_pr,try_cpr,try_cum, &\n try_ccum,status)\n\n IF (has_status) THEN\n IF (status/=0) THEN\n RETURN\n END IF\n END IF\n\n fx = local_ccum - try_ccum\n\n END DO\n\n ELSE\n\n! Try to match ccum varying cpr\n\n CALL cdf_set_zero_finder(the_dummy_binomial,2,local)\n\n DO\n CALL rc_interval_zf(zf_status,try_cpr,fx,local)\n\n IF (zf_status/=1) THEN\n IF (PRESENT(pr)) pr = try_pr\n IF (PRESENT(cpr)) cpr = try_cpr\n\n EXIT\n END IF\n\n try_pr = one - try_cpr\n\n CALL local_cum_neg_binomial(f,s,try_pr,try_cpr,try_cum, &\n try_ccum,status)\n\n IF (has_status) THEN\n IF (status/=0) THEN\n RETURN\n END IF\n END IF\n\n fx = local_ccum - try_ccum\n END DO\n\n END IF\n\n END SELECT\n\n IF (has_status) THEN\n! Set the status of the zero finder\n CALL cdf_finalize_status(local,status)\n END IF\n\n RETURN\n\n END SUBROUTINE cdf_neg_binomial\n\n!*********************************************************************\n\n FUNCTION cum_neg_binomial(f,s,pr,cpr,status,check_input)\n! .. Function Return Value ..\n REAL (dpkind) :: cum_neg_binomial\n! ..\n! .. Scalar Arguments ..\n REAL (dpkind), OPTIONAL, INTENT (IN) :: cpr, pr\n REAL (dpkind), INTENT (IN) :: f, s\n INTEGER, OPTIONAL, INTENT (OUT) :: status\n LOGICAL, OPTIONAL, INTENT (IN) :: check_input\n! ..\n CALL cdf_neg_binomial(which=1,cum=cum_neg_binomial,f=f,s=s,pr=pr, &\n cpr=cpr,status=status,check_input=check_input)\n\n RETURN\n\n END FUNCTION cum_neg_binomial\n\n!*********************************************************************\n\n FUNCTION inv_neg_binomial(cum,ccum,s,pr,cpr,status,check_input)\n! .. Function Return Value ..\n REAL (dpkind) :: inv_neg_binomial\n! ..\n! .. Scalar Arguments ..\n REAL (dpkind), OPTIONAL, INTENT (IN) :: ccum, cpr, cum, pr\n REAL (dpkind), INTENT (IN) :: s\n INTEGER, OPTIONAL, INTENT (OUT) :: status\n LOGICAL, OPTIONAL, INTENT (IN) :: check_input\n! ..\n CALL cdf_neg_binomial(which=2,cum=cum,ccum=ccum, &\n f=inv_neg_binomial,s=s,pr=pr,cpr=cpr,status=status, &\n check_input=check_input)\n\n RETURN\n\n END FUNCTION inv_neg_binomial\n\n!*********************************************************************\n\n SUBROUTINE local_cum_neg_binomial(f,s,pr,cpr,cum,ccum,status)\n\n! METHOD\n\n! Formula 26.5.26 of Abramowitz and Stegun, Handbook of\n! Mathematical Functions (1966) is used to reduce the negative\n! binomial distribution to the cumulative beta distribution.\n! .. Use Statements ..\n USE cdf_beta_mod\n! ..\n! .. Scalar Arguments ..\n! .. Local Scalars\n REAL (dpkind), INTENT (OUT) :: ccum, cum\n REAL (dpkind), INTENT (IN) :: cpr, f, pr, s\n INTEGER, OPTIONAL, INTENT (OUT) :: status\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC PRESENT\n! ..\n! .. Local Scalars ..\n INTEGER :: beta_status\n! ..\n CALL cdf_beta(1,cum,ccum,x=pr,cx=cpr,a=s,b=f+one, &\n check_input=.FALSE.,status=beta_status)\n\n IF (beta_status/=0) THEN\n! cdf_beta has NO answer.\n\n IF (PRESENT(status)) THEN\n status = 10\n ELSE\n WRITE (*,*) &\n 'Error in local_cum_neg_binomial call to cdf_beta'\n WRITE (*,*) 'Status: ', beta_status\n\n STOP 'Error in local_cum_neg_binomial call to cdf_beta'\n END IF\n END IF\n\n RETURN\n\n END SUBROUTINE local_cum_neg_binomial\n\n!*********************************************************************\n\n END MODULE cdf_neg_binomial_mod\n", "meta": {"hexsha": "d79d96a9bcb8c9150773f2504be831730f05d153", "size": 14435, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mesas/sas/cdflib90/cdf_neg_binomial_mod.f90", "max_stars_repo_name": "OliverEvans96/mesas", "max_stars_repo_head_hexsha": "eb830074dd3b2977013cda1e2a30b79e10379190", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "mesas/sas/cdflib90/cdf_neg_binomial_mod.f90", "max_issues_repo_name": "OliverEvans96/mesas", "max_issues_repo_head_hexsha": "eb830074dd3b2977013cda1e2a30b79e10379190", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-12-14T03:16:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-14T16:37:17.000Z", "max_forks_repo_path": "mesas/sas/cdflib90/cdf_neg_binomial_mod.f90", "max_forks_repo_name": "OliverEvans96/mesas", "max_forks_repo_head_hexsha": "eb830074dd3b2977013cda1e2a30b79e10379190", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-09-09T18:20:55.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-09T18:20:55.000Z", "avg_line_length": 28.4714003945, "max_line_length": 76, "alphanum_fraction": 0.5269137513, "num_tokens": 3640, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703477, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6802684374046092}} {"text": "PROGRAM F015\n\n ! Copyright 2021 Melwyn Francis Carlo\n\n IMPLICIT NONE\n\n INTEGER, PARAMETER :: INPUT_GRID_DIMENSION = 20;\n\n REAL (KIND=8) :: ROUTES_N = 1;\n\n INTEGER :: I\n\n DO I = 1, INPUT_GRID_DIMENSION\n ROUTES_N = ROUTES_N * REAL(I + INPUT_GRID_DIMENSION, 8) / REAL(I, 8);\n END DO\n\n PRINT ('(I0)'), CEILING(ROUTES_N, 8)\n\nEND PROGRAM F015\n", "meta": {"hexsha": "79df7a2f60de37abe0ebc0bd5ee313022456fe14", "size": 373, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "problems/015/015.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/015/015.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/015/015.f90", "max_forks_repo_name": "melwyncarlo/ProjectEuler", "max_forks_repo_head_hexsha": "c4d30ed528ae6de82232f3d2044d608c6e8f1c37", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.65, "max_line_length": 77, "alphanum_fraction": 0.6219839142, "num_tokens": 121, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8976952811593496, "lm_q2_score": 0.7577943767446201, "lm_q1q2_score": 0.6802684360927359}} {"text": " ! Exponential Map of Tensor Arguments\n ! --------------------------------------------------------\n ! Algorithmic Sources\n ! Miehe(2002): Homogenization of inelastic solid materials\n ! at (nite strains based on incremental minimization\n ! principles. Application\n ! to the texture analysis of polycrystals\n \n ! --------------------------------------------------------\n ! Author: A. Dutzler, Graz University of Technology\n ! Date: 2018-04-06\n\n function dexp_2(T)\n implicit none\n \n type(Tensor2), intent(in) :: T\n type(Tensor2) :: Eye,N_i,N_j,N_r\n type(Tensor4) :: dexp_2\n real(kind=8) :: tol,I1,I2,I3,g_i\n integer :: i,j,r\n \n tol = 1.0d-8\n i = 2\n\n Eye = identity2(Eye)\n dexp_2 = Eye.cdya.Eye\n \n I1 = T**Eye\n I2 = 0.5*(I1**2-T**T)\n I3 = det(T)\n \n N_i = Eye\n do while (norm(N_i)/fact(i) .gt. tol)\n g_i = 1./fact(i)\n if (i >= 3) then\n ! Cayley-Hamilton recursive formula\n N_i = I1 * T**(i-1) - I2 * T**(i-2) + I3 * T**(i-3)\n else\n N_i = T**i\n end if\n \n do r=0,i-1\n j = i-1-r\n \n if (j >= 3) then\n ! Cayley-Hamilton recursive formula\n N_j = I1 * T**(j-1) - I2 * T**(j-2) + I3 * T**(j-3)\n else\n N_j = T**j\n end if\n \n if (r >= 3) then\n ! Cayley-Hamilton recursive formula\n N_r = I1 * T**(r-1) - I2 * T**(r-2) + I3 * T**(r-3)\n else\n N_r = T**r\n end if\n \n dexp_2 = dexp_2 + g_i * (N_j.cdya.N_r)\n \n end do\n \n i = i+1\n end do\n \n end function dexp_2\n \n function dexp_2s(T)\n implicit none\n \n type(Tensor2s), intent(in) :: T\n type(Tensor2s) :: Eye,N_i,N_j,N_r\n type(Tensor4s) :: dexp_2s\n real(kind=8) :: tol,I1,I2,I3,g_i\n integer :: i,j,r\n \n tol = 1.0d-8\n i = 2\n\n Eye = identity2(Eye)\n dexp_2s = Eye.cdya.Eye\n \n I1 = T**Eye\n I2 = 0.5*(I1**2-T**T)\n I3 = det(T)\n \n N_i = Eye\n do while (norm(N_i)/fact(i) .gt. tol)\n g_i = 1./fact(i)\n if (i >= 3) then\n ! Cayley-Hamilton recursive formula\n N_i = I1 * T**(i-1) - I2 * T**(i-2) + I3 * T**(i-3)\n else\n N_i = T**i\n end if\n \n do r=0,i-1\n j = i-1-r\n \n if (j >= 3) then\n ! Cayley-Hamilton recursive formula\n N_j = I1 * T**(j-1) - I2 * T**(j-2) + I3 * T**(j-3)\n else\n N_j = T**j\n end if\n \n if (r >= 3) then\n ! Cayley-Hamilton recursive formula\n N_r = I1 * T**(r-1) - I2 * T**(r-2) + I3 * T**(r-3)\n else\n N_r = T**r\n end if\n \n dexp_2s = dexp_2s + g_i * (N_j.cdya.N_r)\n \n end do\n \n i = i+1\n end do\n\n end function dexp_2s", "meta": {"hexsha": "065636943a2b521307e84d281ccf38fd1f35237c", "size": 3175, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ttb/libderivativeexp.f", "max_stars_repo_name": "pinkieli/Tensor-for-Fortran", "max_stars_repo_head_hexsha": "15372e07ad2031a83b8e3a4fe1c99bf538c4d20b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ttb/libderivativeexp.f", "max_issues_repo_name": "pinkieli/Tensor-for-Fortran", "max_issues_repo_head_hexsha": "15372e07ad2031a83b8e3a4fe1c99bf538c4d20b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ttb/libderivativeexp.f", "max_forks_repo_name": "pinkieli/Tensor-for-Fortran", "max_forks_repo_head_hexsha": "15372e07ad2031a83b8e3a4fe1c99bf538c4d20b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-18T02:02:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-18T02:02:31.000Z", "avg_line_length": 26.2396694215, "max_line_length": 65, "alphanum_fraction": 0.3911811024, "num_tokens": 1011, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953003183444, "lm_q2_score": 0.757794360334681, "lm_q1q2_score": 0.6802684358801891}} {"text": " subroutine clawpack46_qinit(maxmx,maxmy, meqn,mbc,mx,my,\n & xlower,ylower,dx,dy,q,maux,aux)\n implicit none\n\n integer meqn, mbc, mx, my, maux, maxmx, maxmy\n double precision xlower, ylower, dx, dy, xi, yj\n double precision q(1-mbc:maxmx+mbc, 1-mbc:maxmy+mbc, meqn)\n double precision aux(1-mbc:maxmx+mbc, 1-mbc:maxmy+mbc, maux)\n double precision a(3,3), f, x, y\n\n integer i, j, mq, l, k\n \n\n f(x,y)=dsin(8d0*datan(1d0)*x)*dsin(8d0*datan(1d0)*y)\n\n\n a(1,1)=1d0\n a(1,2)=4d0\n a(1,3)=1d0\n a(2,1)=4d0\n a(2,2)=16d0\n a(2,3)=4d0\n a(3,1)=1d0\n a(3,2)=4d0\n a(3,3)=1d0\n\n do 20 j=1-mbc,my+mbc\n do 10 i=1-mbc,mx+mbc\n q(i,j,1)=0d0\n 10 continue\n 20 continue\n\n do mq=1, meqn \n do j=1-mbc,my+mbc\n yj = ylower + (j-1d0)*dy\n do i=1-mbc,mx+mbc\n xi = xlower + (i-1d0)*dx\n do k=0,2\n do l=0,2 \n q(i,j,mq)=q(i,j,mq)+(1d0/36d0)*a(k+1,l+1)\n & * f(dx*k/2d0+xi,dy*l/2d0+yj)\n enddo\n enddo\n enddo\n enddo\n enddo\n\n return\n end\n", "meta": {"hexsha": "e91a61f0e92d8147a669f2cd214e73ab568478b5", "size": 1259, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "applications/advection/2d/adv_order3/user_4.6/qinit.f", "max_stars_repo_name": "scivision/forestclaw", "max_stars_repo_head_hexsha": "4dae847a8abd1055e70acda9c2973cd3dd77d3f1", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-09T23:06:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-09T23:06:42.000Z", "max_issues_repo_path": "applications/advection/2d/adv_order3/user_4.6/qinit.f", "max_issues_repo_name": "scottaiton/forestclaw", "max_issues_repo_head_hexsha": "2abaab636e6e93f5507a6f231490144a3f805b59", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "applications/advection/2d/adv_order3/user_4.6/qinit.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": 25.18, "max_line_length": 67, "alphanum_fraction": 0.4471803018, "num_tokens": 515, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333484, "lm_q2_score": 0.7577943658046609, "lm_q1q2_score": 0.6802684304201515}} {"text": "!\n! lab1_3_a.f90\n!\n! Copyright 2016 Bruno S \n!\n! This program is free software; you can redistribute it and/or modify\n! it under the terms of the GNU General Public License as published by\n! the Free Software Foundation; either version 2 of the License, or\n! (at your option) any later version.\n!\n! This program is distributed in the hope that it will be useful,\n! but WITHOUT ANY WARRANTY; without even the implied warranty of\n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n! GNU General Public License for more details.\n!\n! You should have received a copy of the GNU General Public License\n! along with this program; if not, write to the Free Software\n! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,\n! MA 02110-1301, USA.\n!\nPROGRAM lab1_3_a\nIMPLICIT NONE\n\nINTEGER :: i, j, k, n\nREAL(KIND=8) :: h, x0, xf, xi, integ, I_exact, er\nOPEN(UNIT=10, FILE='salida_ej3_a.dat', STATUS='UNKNOWN', ACTION='WRITE')\n\nx0 = 0.d0\nxf = 1.d0\n\nWRITE(*,*) \"EJERCICIO 3 a LABORATORIO 1\"\nWRITE(10, *) \"# I n k err I_exact\"\n\nI_exact = f(1.d0) - 1.d0\n\ndo k = 2, 16, 1\n n = 2**k\n h = (xf - x0)/n\n\n xi = x0\n integ = f(xi) / 2.d0\n do i=1, n-1, 1 ! INTEGRO DADO N\n xi = x0 + (h * i)\n integ = integ + f(xi)\n end do\n\n integ = integ + f(xf) / 2.d0\n integ = integ * h\n\n er = ABS(integ - I_exact)\n WRITE(10, *) integ, n, k, er, I_exact\n\nend do\n\nCONTAINS\n\nFUNCTION f(x)\nREAL (KIND=8) :: f\nREAL (KIND=8), INTENT(IN) :: x\n\n f = DEXP(x)\n\nEND FUNCTION f\n\n\n\nEND PROGRAM\n", "meta": {"hexsha": "044fed70b255437ddaba66dafd32069743788759", "size": 1560, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lab1/3/lab1_3_a.f90", "max_stars_repo_name": "BrunoSanchez/fisicaComp", "max_stars_repo_head_hexsha": "be5f61675fee6e370b6d3f5a7eb254fd112c61b0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lab1/3/lab1_3_a.f90", "max_issues_repo_name": "BrunoSanchez/fisicaComp", "max_issues_repo_head_hexsha": "be5f61675fee6e370b6d3f5a7eb254fd112c61b0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lab1/3/lab1_3_a.f90", "max_forks_repo_name": "BrunoSanchez/fisicaComp", "max_forks_repo_head_hexsha": "be5f61675fee6e370b6d3f5a7eb254fd112c61b0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.9411764706, "max_line_length": 72, "alphanum_fraction": 0.6423076923, "num_tokens": 519, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672227971212, "lm_q2_score": 0.8418256492357358, "lm_q1q2_score": 0.6802517144573045}} {"text": "! Program to test array arguments which depend on other array arguments\nprogram arrayarg2\n integer, dimension(5) :: a, b\n\n a = (/1, 2, 3, 4, 5/)\n b = (/2, 3, 4, 5, 6/)\n \n call test (a, b)\n\n if (any (b .ne. (/4, 7, 10, 13, 16/))) call abort\ncontains\nsubroutine test (x1, x2)\n implicit none\n integer, dimension(1:), intent(in) :: x1\n integer, dimension(1:), intent(inout) :: x2\n integer, dimension(1:size(x1)) :: x3\n\n x3 = x1 * 2\n x2 = x2 + x3\nend subroutine test\nend program\n", "meta": {"hexsha": "9cb5b613d64cc64d71de36a3dc9933d825086101", "size": 498, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.fortran-torture/execute/arrayarg2.f90", "max_stars_repo_name": "best08618/asylo", "max_stars_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-05-02T17:34:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-17T10:15:18.000Z", "max_issues_repo_path": "llvm-gcc-4.2-2.9/gcc/testsuite/gfortran.fortran-torture/execute/arrayarg2.f90", "max_issues_repo_name": "vidkidz/crossbridge", "max_issues_repo_head_hexsha": "ba0bf94aee0ce6cf7eb5be882382e52bc57ba396", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "llvm-gcc-4.2-2.9/gcc/testsuite/gfortran.fortran-torture/execute/arrayarg2.f90", "max_forks_repo_name": "vidkidz/crossbridge", "max_forks_repo_head_hexsha": "ba0bf94aee0ce6cf7eb5be882382e52bc57ba396", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-27T00:22:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-01T09:41:02.000Z", "avg_line_length": 22.6363636364, "max_line_length": 71, "alphanum_fraction": 0.6004016064, "num_tokens": 191, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256472515684, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.6802517011807574}} {"text": "! (C) Copyright 2019 UCAR\n!\n! This software is licensed under the terms of the Apache Licence Version 2.0\n! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.\n\nmodule femps_const_mod\n\nuse femps_kinds_mod\n\nimplicit none\nprivate\n\n! Pi\nreal(kind=kind_real), parameter, public :: piby4 = atan(1.0_kind_real)\nreal(kind=kind_real), parameter, public :: pi = 4.0_kind_real*piby4\nreal(kind=kind_real), parameter, public :: piby2 = 0.5_kind_real*pi\n\n! Earth's radius\nreal(kind=kind_real), parameter, public :: rearth = 6371220.0_kind_real\n\n! Radians to degrees\nreal(kind=kind_real), parameter, public :: rad2deg = 57.2957779186820_kind_real\nreal(kind=kind_real), parameter, public :: deg2rad = 0.01745329300562541_kind_real\n\nend module femps_const_mod\n", "meta": {"hexsha": "7fca256ea1ca457971be812ab43980886399ad1f", "size": 761, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/femps/femps_const_mod.f90", "max_stars_repo_name": "JCSDA/femps", "max_stars_repo_head_hexsha": "3437853f0f9c8407925f4d5376a63462e39da253", "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/femps/femps_const_mod.f90", "max_issues_repo_name": "JCSDA/femps", "max_issues_repo_head_hexsha": "3437853f0f9c8407925f4d5376a63462e39da253", "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/femps/femps_const_mod.f90", "max_forks_repo_name": "JCSDA/femps", "max_forks_repo_head_hexsha": "3437853f0f9c8407925f4d5376a63462e39da253", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.2692307692, "max_line_length": 82, "alphanum_fraction": 0.7713534823, "num_tokens": 229, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582516374121, "lm_q2_score": 0.7310585727705127, "lm_q1q2_score": 0.6802194814645931}} {"text": " SUBROUTINE SB02RD( JOB, DICO, HINV, TRANA, UPLO, SCAL, SORT, FACT,\n $ LYAPUN, N, A, LDA, T, LDT, V, LDV, G, LDG, Q,\n $ LDQ, X, LDX, SEP, RCOND, FERR, WR, WI, S, LDS,\n $ IWORK, DWORK, LDWORK, BWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To solve for X either the continuous-time algebraic Riccati\nC equation\nC -1\nC Q + op(A)'*X + X*op(A) - X*op(B)*R op(B)'*X = 0, (1)\nC\nC or the discrete-time algebraic Riccati equation\nC -1\nC X = op(A)'*X*op(A) - op(A)'*X*op(B)*(R + op(B)'*X*op(B)) *\nC op(B)'*X*op(A) + Q, (2)\nC\nC where op(M) = M or M' (M**T), A, op(B), Q, and R are N-by-N,\nC N-by-M, N-by-N, and M-by-M matrices respectively, with Q symmetric\nC and R symmetric nonsingular; X is an N-by-N symmetric matrix.\nC -1\nC The matrix G = op(B)*R *op(B)' must be provided on input, instead\nC of B and R, that is, the continuous-time equation\nC\nC Q + op(A)'*X + X*op(A) - X*G*X = 0, (3)\nC\nC or the discrete-time equation\nC -1\nC Q + op(A)'*X*(I_n + G*X) *op(A) - X = 0, (4)\nC\nC are solved, where G is an N-by-N symmetric matrix. SLICOT Library\nC routine SB02MT should be used to compute G, given B and R. SB02MT\nC also enables to solve Riccati equations corresponding to optimal\nC problems with coupling terms.\nC\nC The routine also returns the computed values of the closed-loop\nC spectrum of the optimal system, i.e., the stable eigenvalues\nC lambda(1),...,lambda(N) of the corresponding Hamiltonian or\nC symplectic matrix associated to the optimal problem. It is assumed\nC that the matrices A, G, and Q are such that the associated\nC Hamiltonian or symplectic matrix has N stable eigenvalues, i.e.,\nC with negative real parts, in the continuous-time case, and with\nC moduli less than one, in the discrete-time case.\nC\nC Optionally, estimates of the conditioning and error bound on the\nC solution of the Riccati equation (3) or (4) are returned.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC JOB CHARACTER*1\nC Specifies the computation to be performed, as follows:\nC = 'X': Compute the solution only;\nC = 'C': Compute the reciprocal condition number only;\nC = 'E': Compute the error bound only;\nC = 'A': Compute all: the solution, reciprocal condition\nC number, and the error bound.\nC\nC DICO CHARACTER*1\nC Specifies the type of Riccati equation to be solved or\nC analyzed, as follows:\nC = 'C': Equation (3), continuous-time case;\nC = 'D': Equation (4), discrete-time case.\nC\nC HINV CHARACTER*1\nC If DICO = 'D' and JOB = 'X' or JOB = 'A', specifies which\nC symplectic matrix is to be constructed, as follows:\nC = 'D': The matrix H in (6) (see METHOD) is constructed;\nC = 'I': The inverse of the matrix H in (6) is constructed.\nC HINV is not used if DICO = 'C', or JOB = 'C' or 'E'.\nC\nC TRANA CHARACTER*1\nC Specifies the form of op(A) to be used, as follows:\nC = 'N': op(A) = A (No transpose);\nC = 'T': op(A) = A**T (Transpose);\nC = 'C': op(A) = A**T (Conjugate transpose = Transpose).\nC\nC UPLO CHARACTER*1\nC Specifies which triangle of the matrices G and Q is\nC stored, as follows:\nC = 'U': Upper triangle is stored;\nC = 'L': Lower triangle is stored.\nC\nC SCAL CHARACTER*1\nC If JOB = 'X' or JOB = 'A', specifies whether or not a\nC scaling strategy should be used, as follows:\nC = 'G': General scaling should be used;\nC = 'N': No scaling should be used.\nC SCAL is not used if JOB = 'C' or 'E'.\nC\nC SORT CHARACTER*1\nC If JOB = 'X' or JOB = 'A', specifies which eigenvalues\nC should be obtained in the top of the Schur form, as\nC follows:\nC = 'S': Stable eigenvalues come first;\nC = 'U': Unstable eigenvalues come first.\nC SORT is not used if JOB = 'C' or 'E'.\nC\nC FACT CHARACTER*1\nC If JOB <> 'X', specifies whether or not a real Schur\nC factorization of the closed-loop system matrix Ac is\nC supplied on entry, as follows:\nC = 'F': On entry, T and V contain the factors from a real\nC Schur factorization of the matrix Ac;\nC = 'N': A Schur factorization of Ac will be computed\nC and the factors will be stored in T and V.\nC For a continuous-time system, the matrix Ac is given by\nC Ac = A - G*X, if TRANA = 'N', or\nC Ac = A - X*G, if TRANA = 'T' or 'C',\nC and for a discrete-time system, the matrix Ac is given by\nC Ac = inv(I_n + G*X)*A, if TRANA = 'N', or\nC Ac = A*inv(I_n + X*G), if TRANA = 'T' or 'C'.\nC FACT is not used if JOB = 'X'.\nC\nC LYAPUN CHARACTER*1\nC If JOB <> 'X', specifies whether or not the original or\nC \"reduced\" Lyapunov equations should be solved for\nC estimating reciprocal condition number and/or the error\nC bound, as follows:\nC = 'O': Solve the original Lyapunov equations, updating\nC the right-hand sides and solutions with the\nC matrix V, e.g., X <-- V'*X*V;\nC = 'R': Solve reduced Lyapunov equations only, without\nC updating the right-hand sides and solutions.\nC This means that a real Schur form T of Ac appears\nC in the equations, instead of Ac.\nC LYAPUN is not used if JOB = 'X'.\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The order of the matrices A, Q, G, and X. N >= 0.\nC\nC A (input) DOUBLE PRECISION array, dimension (LDA,N)\nC If JOB = 'X' or JOB = 'A' or FACT = 'N' or LYAPUN = 'O',\nC the leading N-by-N part of this array must contain the\nC coefficient matrix A of the equation.\nC If JOB = 'C' or 'E' and FACT = 'F' and LYAPUN = 'R', A is\nC not referenced.\nC\nC LDA INTEGER\nC The leading dimension of the array A.\nC LDA >= MAX(1,N), if JOB = 'X' or JOB = 'A' or\nC FACT = 'N' or LYAPUN = 'O'.\nC LDA >= 1, otherwise.\nC\nC T (input or output) DOUBLE PRECISION array, dimension\nC (LDT,N)\nC If JOB <> 'X' and FACT = 'F', then T is an input argument\nC and on entry, the leading N-by-N upper Hessenberg part of\nC this array must contain the upper quasi-triangular matrix\nC T in Schur canonical form from a Schur factorization of Ac\nC (see argument FACT).\nC If JOB <> 'X' and FACT = 'N', then T is an output argument\nC and on exit, if INFO = 0 or INFO = 7, the leading N-by-N\nC upper Hessenberg part of this array contains the upper\nC quasi-triangular matrix T in Schur canonical form from a\nC Schur factorization of Ac (see argument FACT).\nC If JOB = 'X', the array T is not referenced.\nC\nC LDT INTEGER\nC The leading dimension of the array T.\nC LDT >= 1, if JOB = 'X';\nC LDT >= MAX(1,N), if JOB <> 'X'.\nC\nC V (input or output) DOUBLE PRECISION array, dimension\nC (LDV,N)\nC If JOB <> 'X' and FACT = 'F', then V is an input argument\nC and on entry, the leading N-by-N part of this array must\nC contain the orthogonal matrix V from a real Schur\nC factorization of Ac (see argument FACT).\nC If JOB <> 'X' and FACT = 'N', then V is an output argument\nC and on exit, if INFO = 0 or INFO = 7, the leading N-by-N\nC part of this array contains the orthogonal N-by-N matrix\nC from a real Schur factorization of Ac (see argument FACT).\nC If JOB = 'X', the array V is not referenced.\nC\nC LDV INTEGER\nC The leading dimension of the array V.\nC LDV >= 1, if JOB = 'X';\nC LDV >= MAX(1,N), if JOB <> 'X'.\nC\nC G (input/output) DOUBLE PRECISION array, dimension (LDG,N)\nC On entry, the leading N-by-N upper triangular part (if\nC UPLO = 'U') or lower triangular part (if UPLO = 'L') of\nC this array must contain the upper triangular part or lower\nC triangular part, respectively, of the symmetric matrix G.\nC On exit, if JOB = 'X' and DICO = 'D', or JOB <> 'X' and\nC LYAPUN = 'R', the leading N-by-N part of this array\nC contains the symmetric matrix G fully stored.\nC If JOB <> 'X' and LYAPUN = 'R', this array is modified\nC internally, but restored on exit.\nC\nC LDG INTEGER\nC The leading dimension of the array G. LDG >= MAX(1,N).\nC\nC Q (input/output) DOUBLE PRECISION array, dimension (LDQ,N)\nC On entry, the leading N-by-N upper triangular part (if\nC UPLO = 'U') or lower triangular part (if UPLO = 'L') of\nC this array must contain the upper triangular part or lower\nC triangular part, respectively, of the symmetric matrix Q.\nC On exit, if JOB = 'X' and DICO = 'D', or JOB <> 'X' and\nC LYAPUN = 'R', the leading N-by-N part of this array\nC contains the symmetric matrix Q fully stored.\nC If JOB <> 'X' and LYAPUN = 'R', this array is modified\nC internally, but restored on exit.\nC\nC LDQ INTEGER\nC The leading dimension of the array Q. LDQ >= MAX(1,N).\nC\nC X (input or output) DOUBLE PRECISION array, dimension\nC (LDX,N)\nC If JOB = 'C' or JOB = 'E', then X is an input argument\nC and on entry, the leading N-by-N part of this array must\nC contain the symmetric solution matrix of the algebraic\nC Riccati equation. If LYAPUN = 'R', this array is modified\nC internally, but restored on exit; however, it could differ\nC from the input matrix at the round-off error level.\nC If JOB = 'X' or JOB = 'A', then X is an output argument\nC and on exit, if INFO = 0 or INFO >= 6, the leading N-by-N\nC part of this array contains the symmetric solution matrix\nC X of the algebraic Riccati equation.\nC\nC LDX INTEGER\nC The leading dimension of the array X. LDX >= MAX(1,N).\nC\nC SEP (output) DOUBLE PRECISION\nC If JOB = 'C' or JOB = 'A', and INFO = 0 or INFO = 7, the\nC estimated quantity\nC sep(op(Ac),-op(Ac)'), if DICO = 'C', or\nC sepd(op(Ac),op(Ac)'), if DICO = 'D'. (See METHOD.)\nC If JOB = 'C' or JOB = 'A' and X = 0, or JOB = 'E', SEP is\nC not referenced.\nC If JOB = 'X', and INFO = 0, INFO = 5 or INFO = 7,\nC SEP contains the scaling factor used, which should\nC multiply the (2,1) submatrix of U to recover X from the\nC first N columns of U (see METHOD). If SCAL = 'N', SEP is\nC set to 1.\nC\nC RCOND (output) DOUBLE PRECISION\nC If JOB = 'C' or JOB = 'A', and INFO = 0 or INFO = 7, an\nC estimate of the reciprocal condition number of the\nC algebraic Riccati equation.\nC If N = 0 or X = 0, RCOND is set to 1 or 0, respectively.\nC If JOB = 'X', or JOB = 'E', RCOND is not referenced.\nC\nC FERR (output) DOUBLE PRECISION\nC If JOB = 'E' or JOB = 'A', and INFO = 0 or INFO = 7, an\nC estimated forward error bound for the solution X. If XTRUE\nC is the true solution, FERR bounds the magnitude of the\nC largest entry in (X - XTRUE) divided by the magnitude of\nC the largest entry in X.\nC If N = 0 or X = 0, FERR is set to 0.\nC If JOB = 'X', or JOB = 'C', FERR is not referenced.\nC\nC WR (output) DOUBLE PRECISION array, dimension (2*N)\nC WI (output) DOUBLE PRECISION array, dimension (2*N)\nC If JOB = 'X' or JOB = 'A', and INFO = 0 or INFO >= 5,\nC these arrays contain the real and imaginary parts,\nC respectively, of the eigenvalues of the 2N-by-2N matrix S,\nC ordered as specified by SORT (except for the case\nC HINV = 'D', when the order is opposite to that specified\nC by SORT). The leading N elements of these arrays contain\nC the closed-loop spectrum of the system matrix Ac (see\nC argument FACT). Specifically,\nC lambda(k) = WR(k) + j*WI(k), for k = 1,2,...,N.\nC If JOB = 'C' or JOB = 'E', these arrays are not\nC referenced.\nC\nC S (output) DOUBLE PRECISION array, dimension (LDS,2*N)\nC If JOB = 'X' or JOB = 'A', and INFO = 0 or INFO >= 5, the\nC leading 2N-by-2N part of this array contains the ordered\nC real Schur form S of the (scaled, if SCAL = 'G')\nC Hamiltonian or symplectic matrix H. That is,\nC\nC ( S S )\nC ( 11 12 )\nC S = ( ),\nC ( 0 S )\nC ( 22 )\nC\nC where S , S and S are N-by-N matrices.\nC 11 12 22\nC If JOB = 'C' or JOB = 'E', this array is not referenced.\nC\nC LDS INTEGER\nC The leading dimension of the array S.\nC LDS >= MAX(1,2*N), if JOB = 'X' or JOB = 'A';\nC LDS >= 1, if JOB = 'C' or JOB = 'E'.\nC\nC Workspace\nC\nC IWORK INTEGER array, dimension (LIWORK)\nC LIWORK >= 2*N, if JOB = 'X';\nC LIWORK >= N*N, if JOB = 'C' or JOB = 'E';\nC LIWORK >= MAX(2*N,N*N), if JOB = 'A'.\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0, or INFO = 7, DWORK(1) returns the\nC optimal value of LDWORK. If INFO = 0, or INFO >= 5, and\nC JOB = 'X', or JOB = 'A', then DWORK(2) returns an estimate\nC RCONDU of the reciprocal of the condition number (in the\nC 1-norm) of the N-th order system of algebraic equations\nC from which the solution matrix X is obtained, and DWORK(3)\nC returns the reciprocal pivot growth factor for the LU\nC factorization of the coefficient matrix of that system\nC (see SLICOT Library routine MB02PD); if DWORK(3) is much\nC less than 1, then the computed X and RCONDU could be\nC unreliable.\nC If DICO = 'D', and JOB = 'X', or JOB = 'A', then DWORK(4)\nC returns the reciprocal condition number RCONDA of the\nC given matrix A, and DWORK(5) returns the reciprocal pivot\nC growth factor for A or for its leading columns, if A is\nC singular (see SLICOT Library routine MB02PD); if DWORK(5)\nC is much less than 1, then the computed S and RCONDA could\nC be unreliable.\nC On exit, if INFO = 0, or INFO >= 4, and JOB = 'X', the\nC elements DWORK(6:5+4*N*N) contain the 2*N-by-2*N\nC transformation matrix U which reduced the Hamiltonian or\nC symplectic matrix H to the ordered real Schur form S.\nC\nC LDWORK INTEGER\nC The length of the array DWORK.\nC LDWORK >= 5+MAX(1,4*N*N+8*N), if JOB = 'X' or JOB = 'A';\nC This may also be used for JOB = 'C' or JOB = 'E', but\nC exact bounds are as follows:\nC LDWORK >= 5 + MAX(1,LWS,LWE) + LWN, where\nC LWS = 0, if FACT = 'F' or LYAPUN = 'R';\nC = 5*N, if FACT = 'N' and LYAPUN = 'O' and\nC DICO = 'C' and JOB = 'C';\nC = 5*N+N*N, if FACT = 'N' and LYAPUN = 'O' and\nC DICO = 'C' and JOB = 'E';\nC = 5*N+N*N, if FACT = 'N' and LYAPUN = 'O' and\nC DICO = 'D';\nC LWE = 2*N*N, if DICO = 'C' and JOB = 'C';\nC = 4*N*N, if DICO = 'C' and JOB = 'E';\nC = MAX(3,2*N*N) + N*N, if DICO = 'D' and JOB = 'C';\nC = MAX(3,2*N*N) + 2*N*N, if DICO = 'D' and JOB = 'E';\nC LWN = 0, if LYAPUN = 'O' or JOB = 'C';\nC = 2*N, if LYAPUN = 'R' and DICO = 'C' and JOB = 'E';\nC = 3*N, if LYAPUN = 'R' and DICO = 'D' and JOB = 'E'.\nC For optimum performance LDWORK should sometimes be larger.\nC\nC BWORK LOGICAL array, dimension (LBWORK)\nC LBWORK >= 2*N, if JOB = 'X' or JOB = 'A';\nC LBWORK >= 1, if JOB = 'C' or JOB = 'E', and\nC FACT = 'N' and LYAPUN = 'R';\nC LBWORK >= 0, otherwise.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value;\nC = 1: if matrix A is (numerically) singular in discrete-\nC time case;\nC = 2: if the Hamiltonian or symplectic matrix H cannot be\nC reduced to real Schur form;\nC = 3: if the real Schur form of the Hamiltonian or\nC symplectic matrix H cannot be appropriately ordered;\nC = 4: if the Hamiltonian or symplectic matrix H has less\nC than N stable eigenvalues;\nC = 5: if the N-th order system of linear algebraic\nC equations, from which the solution matrix X would\nC be obtained, is singular to working precision;\nC = 6: if the QR algorithm failed to complete the reduction\nC of the matrix Ac to Schur canonical form, T;\nC = 7: if T and -T' have some almost equal eigenvalues, if\nC DICO = 'C', or T has almost reciprocal eigenvalues,\nC if DICO = 'D'; perturbed values were used to solve\nC Lyapunov equations, but the matrix T, if given (for\nC FACT = 'F'), is unchanged. (This is a warning\nC indicator.)\nC\nC METHOD\nC\nC The method used is the Schur vector approach proposed by Laub [1],\nC but with an optional scaling, which enhances the numerical\nC stability [6]. It is assumed that [A,B] is a stabilizable pair\nC (where for (3) or (4), B is any matrix such that B*B' = G with\nC rank(B) = rank(G)), and [E,A] is a detectable pair, where E is any\nC matrix such that E*E' = Q with rank(E) = rank(Q). Under these\nC assumptions, any of the algebraic Riccati equations (1)-(4) is\nC known to have a unique non-negative definite solution. See [2].\nC Now consider the 2N-by-2N Hamiltonian or symplectic matrix\nC\nC ( op(A) -G )\nC H = ( ), (5)\nC ( -Q -op(A)' ),\nC\nC for continuous-time equation, and\nC -1 -1\nC ( op(A) op(A) *G )\nC H = ( -1 -1 ), (6)\nC ( Q*op(A) op(A)' + Q*op(A) *G )\nC\nC for discrete-time equation, respectively, where\nC -1\nC G = op(B)*R *op(B)'.\nC The assumptions guarantee that H in (5) has no pure imaginary\nC eigenvalues, and H in (6) has no eigenvalues on the unit circle.\nC If Y is an N-by-N matrix then there exists an orthogonal matrix U\nC such that U'*Y*U is an upper quasi-triangular matrix. Moreover, U\nC can be chosen so that the 2-by-2 and 1-by-1 diagonal blocks\nC (corresponding to the complex conjugate eigenvalues and real\nC eigenvalues respectively) appear in any desired order. This is the\nC ordered real Schur form. Thus, we can find an orthogonal\nC similarity transformation U which puts (5) or (6) in ordered real\nC Schur form\nC\nC U'*H*U = S = (S(1,1) S(1,2))\nC ( 0 S(2,2))\nC\nC where S(i,j) is an N-by-N matrix and the eigenvalues of S(1,1)\nC have negative real parts in case of (5), or moduli greater than\nC one in case of (6). If U is conformably partitioned into four\nC N-by-N blocks\nC\nC U = (U(1,1) U(1,2))\nC (U(2,1) U(2,2))\nC\nC with respect to the assumptions we then have\nC (a) U(1,1) is invertible and X = U(2,1)*inv(U(1,1)) solves (1),\nC (2), (3), or (4) with X = X' and non-negative definite;\nC (b) the eigenvalues of S(1,1) (if DICO = 'C') or S(2,2) (if\nC DICO = 'D') are equal to the eigenvalues of optimal system\nC (the 'closed-loop' spectrum).\nC\nC [A,B] is stabilizable if there exists a matrix F such that (A-BF)\nC is stable. [E,A] is detectable if [A',E'] is stabilizable.\nC\nC The condition number of a Riccati equation is estimated as\nC\nC cond = ( norm(Theta)*norm(A) + norm(inv(Omega))*norm(Q) +\nC norm(Pi)*norm(G) ) / norm(X),\nC\nC where Omega, Theta and Pi are linear operators defined by\nC\nC Omega(W) = op(Ac)'*W + W*op(Ac),\nC Theta(W) = inv(Omega(op(W)'*X + X*op(W))),\nC Pi(W) = inv(Omega(X*W*X)),\nC\nC in the continuous-time case, and\nC\nC Omega(W) = op(Ac)'*W*op(Ac) - W,\nC Theta(W) = inv(Omega(op(W)'*X*op(Ac) + op(Ac)'X*op(W))),\nC Pi(W) = inv(Omega(op(Ac)'*X*W*X*op(Ac))),\nC\nC in the discrete-time case, and Ac has been defined (see argument\nC FACT). Details are given in the comments of SLICOT Library\nC routines SB02QD and SB02SD.\nC\nC The routine estimates the quantities\nC\nC sep(op(Ac),-op(Ac)') = 1 / norm(inv(Omega)),\nC sepd(op(Ac),op(Ac)') = 1 / norm(inv(Omega)),\nC\nC norm(Theta) and norm(Pi) using 1-norm condition estimator.\nC\nC The forward error bound is estimated using a practical error bound\nC similar to the one proposed in [5].\nC\nC REFERENCES\nC\nC [1] Laub, A.J.\nC A Schur Method for Solving Algebraic Riccati equations.\nC IEEE Trans. Auto. Contr., AC-24, pp. 913-921, 1979.\nC\nC [2] Wonham, W.M.\nC On a matrix Riccati equation of stochastic control.\nC SIAM J. Contr., 6, pp. 681-697, 1968.\nC\nC [3] Sima, V.\nC Algorithms for Linear-Quadratic Optimization.\nC Pure and Applied Mathematics: A Series of Monographs and\nC Textbooks, vol. 200, Marcel Dekker, Inc., New York, 1996.\nC\nC [4] Ghavimi, A.R. and Laub, A.J.\nC Backward error, sensitivity, and refinement of computed\nC solutions of algebraic Riccati equations.\nC Numerical Linear Algebra with Applications, vol. 2, pp. 29-49,\nC 1995.\nC\nC [5] Higham, N.J.\nC Perturbation theory and backward error for AX-XB=C.\nC BIT, vol. 33, pp. 124-136, 1993.\nC\nC [6] Petkov, P.Hr., Konstantinov, M.M., and Mehrmann, V.\nC DGRSVX and DMSRIC: Fortran 77 subroutines for solving\nC continuous-time matrix algebraic Riccati equations with\nC condition and accuracy estimates.\nC Preprint SFB393/98-16, Fak. f. Mathematik, Tech. Univ.\nC Chemnitz, May 1998.\nC\nC NUMERICAL ASPECTS\nC 3\nC The algorithm requires 0(N ) operations. The solution accuracy\nC can be controlled by the output parameter FERR.\nC\nC FURTHER COMMENTS\nC\nC To obtain a stabilizing solution of the algebraic Riccati\nC equation for DICO = 'D', set SORT = 'U', if HINV = 'D', or set\nC SORT = 'S', if HINV = 'I'.\nC\nC The routine can also compute the anti-stabilizing solutions of\nC the algebraic Riccati equations, by specifying\nC SORT = 'U' if DICO = 'D' and HINV = 'I', or DICO = 'C', or\nC SORT = 'S' if DICO = 'D' and HINV = 'D'.\nC\nC Usually, the combinations HINV = 'D' and SORT = 'U', or HINV = 'I'\nC and SORT = 'U', for stabilizing and anti-stabilizing solutions,\nC respectively, will be faster then the other combinations [3].\nC\nC The option LYAPUN = 'R' may produce slightly worse or better\nC estimates, and it is faster than the option 'O'.\nC\nC This routine is a functionally extended and more accurate\nC version of the SLICOT Library routine SB02MD. Transposed problems\nC can be dealt with as well. Iterative refinement is used whenever\nC useful to solve linear algebraic systems. Condition numbers and\nC error bounds on the solutions are optionally provided.\nC\nC CONTRIBUTOR\nC\nC V. Sima, Research Institute for Informatics, Bucharest, Apr. 1999.\nC\nC REVISIONS\nC\nC V. Sima, Research Institute for Informatics, Bucharest, Oct. 2001,\nC Dec. 2002, Oct. 2004.\nC\nC KEYWORDS\nC\nC Algebraic Riccati equation, closed loop system, continuous-time\nC system, discrete-time system, optimal regulator, Schur form.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, HALF, ONE\n PARAMETER ( ZERO = 0.0D0, HALF = 0.5D0, ONE = 1.0D0 )\nC .. Scalar Arguments ..\n CHARACTER DICO, FACT, HINV, JOB, LYAPUN, SCAL, SORT,\n $ TRANA, UPLO\n INTEGER INFO, LDA, LDG, LDQ, LDS, LDT, LDV, LDWORK, LDX,\n $ N\n DOUBLE PRECISION FERR, RCOND, SEP\nC .. Array Arguments ..\n LOGICAL BWORK(*)\n INTEGER IWORK(*)\n DOUBLE PRECISION A(LDA,*), DWORK(*), G(LDG,*), Q(LDQ,*),\n $ S(LDS,*), T(LDT,*), V(LDV,*), WI(*), WR(*),\n $ X(LDX,*)\nC .. Local Scalars ..\n LOGICAL COLEQU, DISCR, JBXA, JOBA, JOBC, JOBE, JOBX,\n $ LHINV, LSCAL, LSCL, LSORT, LUPLO, NOFACT,\n $ NOTRNA, ROWEQU, UPDATE\n CHARACTER EQUED, JOBS, LOFACT, LOUP, TRANAT\n INTEGER I, IERR, IU, IW, IWB, IWC, IWF, IWI, IWR, LDW,\n $ LWE, LWN, LWS, N2, NN, NP1, NROT\n DOUBLE PRECISION GNORM, QNORM, PIVOTA, PIVOTU, RCONDA, RCONDU,\n $ WRKOPT\nC .. External Functions ..\n LOGICAL LSAME, SB02MR, SB02MS, SB02MV, SB02MW\n DOUBLE PRECISION DLAMCH, DLANGE, DLANSY\n EXTERNAL DLAMCH, DLANGE, DLANSY, LSAME, SB02MR, SB02MS,\n $ SB02MV, SB02MW\nC .. External Subroutines ..\n EXTERNAL DAXPY, DCOPY, DGEES, DGESV, DLACPY, DLASCL,\n $ DLASET, DSCAL, DSWAP, DSYMM, MA02AD, MA02ED,\n $ MB01RU, MB01SD, MB02PD, SB02QD, SB02RU, SB02SD,\n $ XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC DBLE, MAX\nC .. Executable Statements ..\nC\nC Decode the input parameters.\nC\n N2 = N + N\n NN = N*N\n NP1 = N + 1\n INFO = 0\n JOBA = LSAME( JOB, 'A' )\n JOBC = LSAME( JOB, 'C' )\n JOBE = LSAME( JOB, 'E' )\n JOBX = LSAME( JOB, 'X' )\n NOFACT = LSAME( FACT, 'N' )\n NOTRNA = LSAME( TRANA, 'N' )\n DISCR = LSAME( DICO, 'D' )\n LUPLO = LSAME( UPLO, 'U' )\n LSCAL = LSAME( SCAL, 'G' )\n LSORT = LSAME( SORT, 'S' )\n UPDATE = LSAME( LYAPUN, 'O' )\n JBXA = JOBX .OR. JOBA\n LHINV = .FALSE.\n IF ( DISCR .AND. JBXA )\n $ LHINV = LSAME( HINV, 'D' )\nC\nC Test the input scalar arguments.\nC\n IF( .NOT.( JBXA .OR. JOBC .OR. JOBE ) ) THEN\n INFO = -1\n ELSE IF( .NOT.( DISCR .OR. LSAME( DICO, 'C' ) ) ) THEN\n INFO = -2\n ELSE IF( DISCR .AND. JBXA ) THEN\n IF( .NOT.( LHINV .OR. LSAME( HINV, 'I' ) ) )\n $ INFO = -3\n END IF\n IF( INFO.EQ.0 ) THEN\n IF( .NOT.( NOTRNA .OR. LSAME( TRANA, 'T' ) .OR.\n $ LSAME( TRANA, 'C' ) ) ) THEN\n INFO = -4\n ELSE IF( .NOT.( LUPLO .OR. LSAME( UPLO, 'L' ) ) )\n $ THEN\n INFO = -5\n ELSE IF( JBXA ) THEN\n IF( .NOT.( LSCAL .OR. LSAME( SCAL, 'N' ) ) ) THEN\n INFO = -6\n ELSE IF( .NOT.( LSORT .OR. LSAME( SORT, 'U' ) ) ) THEN\n INFO = -7\n END IF\n END IF\n IF( INFO.EQ.0 .AND. .NOT.JOBX ) THEN\n IF( .NOT.( NOFACT .OR. LSAME( FACT, 'F' ) ) ) THEN\n INFO = -8\n ELSE IF( .NOT.( UPDATE .OR. LSAME( LYAPUN, 'R' ) ) ) THEN\n INFO = -9\n END IF\n END IF\n IF( INFO.EQ.0 ) THEN\n IF( N.LT.0 ) THEN\n INFO = -10\n ELSE IF( LDA.LT.1 .OR. ( ( JBXA .OR. NOFACT .OR. UPDATE )\n $ .AND. LDA.LT.N ) ) THEN\n INFO = -12\n ELSE IF( LDT.LT.1 .OR. ( .NOT. JOBX .AND. LDT.LT.N ) ) THEN\n INFO = -14\n ELSE IF( LDV.LT.1 .OR. ( .NOT. JOBX .AND. LDV.LT.N ) ) THEN\n INFO = -16\n ELSE IF( LDG.LT.MAX( 1, N ) ) THEN\n INFO = -18\n ELSE IF( LDQ.LT.MAX( 1, N ) ) THEN\n INFO = -20\n ELSE IF( LDX.LT.MAX( 1, N ) ) THEN\n INFO = -22\n ELSE IF( LDS.LT.1 .OR. ( JBXA .AND. LDS.LT.N2 ) ) THEN\n INFO = -29\n ELSE\n IF( JBXA ) THEN\n IF( LDWORK.LT.5 + MAX( 1, 4*NN + 8*N ) )\n $ INFO = -32\n ELSE\n IF( NOFACT .AND. UPDATE ) THEN\n IF( .NOT.DISCR .AND. JOBC ) THEN\n LWS = 5*N\n ELSE\n LWS = 5*N + NN\n END IF\n ELSE\n LWS = 0\n END IF\n IF( DISCR ) THEN\n IF( JOBC ) THEN\n LWE = MAX( 3, 2*NN) + NN\n ELSE\n LWE = MAX( 3, 2*NN) + 2*NN\n END IF\n ELSE\n IF( JOBC ) THEN\n LWE = 2*NN\n ELSE\n LWE = 4*NN\n END IF\n END IF\n IF( UPDATE .OR. JOBC ) THEN\n LWN = 0\n ELSE\n IF( DISCR ) THEN\n LWN = 3*N\n ELSE\n LWN = 2*N\n END IF\n END IF\n IF( LDWORK.LT.5 + MAX( 1, LWS, LWE ) + LWN )\n $ INFO = -32\n END IF\n END IF\n END IF\n END IF\nC\n IF ( INFO.NE.0 ) THEN\nC\nC Error return.\nC\n CALL XERBLA( 'SB02RD', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF ( N.EQ.0 ) THEN\n IF( JOBX )\n $ SEP = ONE\n IF( JOBC .OR. JOBA )\n $ RCOND = ONE\n IF( JOBE .OR. JOBA )\n $ FERR = ZERO\n DWORK(1) = ONE\n DWORK(2) = ONE\n DWORK(3) = ONE\n IF ( DISCR ) THEN\n DWORK(4) = ONE\n DWORK(5) = ONE\n END IF\n RETURN\n END IF\nC\n IF ( JBXA ) THEN\nC\nC Compute the solution matrix X.\nC\nC Initialise the Hamiltonian or symplectic matrix associated with\nC the problem.\nC Workspace: need 0 if DICO = 'C';\nC 6*N, if DICO = 'D'.\nC\n CALL SB02RU( DICO, HINV, TRANA, UPLO, N, A, LDA, G, LDG, Q,\n $ LDQ, S, LDS, IWORK, DWORK, LDWORK, IERR )\nC\n IF ( IERR.NE.0 ) THEN\n INFO = 1\n IF ( DISCR ) THEN\n DWORK(4) = DWORK(1)\n DWORK(5) = DWORK(2)\n END IF\n RETURN\n END IF\nC\n IF ( DISCR ) THEN\n WRKOPT = 6*N\n RCONDA = DWORK(1)\n PIVOTA = DWORK(2)\n ELSE\n WRKOPT = 0\n END IF\nC\n IF ( LSCAL ) THEN\nC\nC Scale the Hamiltonian or symplectic matrix S, using the\nC square roots of the norms of the matrices Q and G.\nC\n QNORM = SQRT( DLANSY( '1-norm', UPLO, N, Q, LDQ, DWORK ) )\n GNORM = SQRT( DLANSY( '1-norm', UPLO, N, G, LDG, DWORK ) )\nC\n LSCL = QNORM.GT.GNORM .AND. GNORM.GT.ZERO\n IF( LSCL ) THEN\n CALL DLASCL( 'G', 0, 0, QNORM, GNORM, N, N, S(NP1,1),\n $ LDS, IERR )\n CALL DLASCL( 'G', 0, 0, GNORM, QNORM, N, N, S(1,NP1),\n $ LDS, IERR )\n END IF\n ELSE\n LSCL = .FALSE.\n END IF\nC\nC Find the ordered Schur factorization of S, S = U*H*U'.\nC Workspace: need 5 + 4*N*N + 6*N;\nC prefer larger.\nC\n IU = 6\n IW = IU + 4*NN\n LDW = LDWORK - IW + 1\n IF ( .NOT.DISCR ) THEN\n IF ( LSORT ) THEN\n CALL DGEES( 'Vectors', 'Sorted', SB02MV, N2, S, LDS,\n $ NROT, WR, WI, DWORK(IU), N2, DWORK(IW), LDW,\n $ BWORK, IERR )\n ELSE\n CALL DGEES( 'Vectors', 'Sorted', SB02MR, N2, S, LDS,\n $ NROT, WR, WI, DWORK(IU), N2, DWORK(IW), LDW,\n $ BWORK, IERR )\n END IF\n ELSE\n IF ( LSORT ) THEN\n CALL DGEES( 'Vectors', 'Sorted', SB02MW, N2, S, LDS,\n $ NROT, WR, WI, DWORK(IU), N2, DWORK(IW), LDW,\n $ BWORK, IERR )\n ELSE\n CALL DGEES( 'Vectors', 'Sorted', SB02MS, N2, S, LDS,\n $ NROT, WR, WI, DWORK(IU), N2, DWORK(IW), LDW,\n $ BWORK, IERR )\n END IF\n IF ( LHINV ) THEN\n CALL DSWAP( N, WR, 1, WR(NP1), 1 )\n CALL DSWAP( N, WI, 1, WI(NP1), 1 )\n END IF\n END IF\n IF ( IERR.GT.N2 ) THEN\n INFO = 3\n ELSE IF ( IERR.GT.0 ) THEN\n INFO = 2\n ELSE IF ( NROT.NE.N ) THEN\n INFO = 4\n END IF\n IF ( INFO.NE.0 ) THEN\n IF ( DISCR ) THEN\n DWORK(4) = RCONDA\n DWORK(5) = PIVOTA\n END IF\n RETURN\n END IF\nC\n WRKOPT = MAX( WRKOPT, DWORK(IW) + DBLE( IW - 1 ) )\nC\nC Compute the solution of X*U(1,1) = U(2,1) using\nC LU factorization and iterative refinement. The (2,1) block of S\nC is used as a workspace for factoring U(1,1).\nC Workspace: need 5 + 4*N*N + 8*N.\nC\nC First transpose U(2,1) in-situ.\nC\n DO 20 I = 1, N - 1\n CALL DSWAP( N-I, DWORK(IU+N+I*(N2+1)-1), N2,\n $ DWORK(IU+N+(I-1)*(N2+1)+1), 1 )\n 20 CONTINUE\nC\n IWR = IW\n IWC = IWR + N\n IWF = IWC + N\n IWB = IWF + N\n IW = IWB + N\nC\n CALL MB02PD( 'Equilibrate', 'Transpose', N, N, DWORK(IU), N2,\n $ S(NP1,1), LDS, IWORK, EQUED, DWORK(IWR),\n $ DWORK(IWC), DWORK(IU+N), N2, X, LDX, RCONDU,\n $ DWORK(IWF), DWORK(IWB), IWORK(NP1), DWORK(IW),\n $ IERR )\n IF( JOBX ) THEN\nC\nC Restore U(2,1) back in-situ.\nC\n DO 40 I = 1, N - 1\n CALL DSWAP( N-I, DWORK(IU+N+I*(N2+1)-1), N2,\n $ DWORK(IU+N+(I-1)*(N2+1)+1), 1 )\n 40 CONTINUE\nC\n IF( .NOT.LSAME( EQUED, 'N' ) ) THEN\nC\nC Undo the equilibration of U(1,1) and U(2,1).\nC\n ROWEQU = LSAME( EQUED, 'R' ) .OR. LSAME( EQUED, 'B' )\n COLEQU = LSAME( EQUED, 'C' ) .OR. LSAME( EQUED, 'B' )\nC\n IF( ROWEQU ) THEN\nC\n DO 60 I = 1, N\n DWORK(IWR+I-1) = ONE / DWORK(IWR+I-1)\n 60 CONTINUE\nC\n CALL MB01SD( 'Row scaling', N, N, DWORK(IU), N2,\n $ DWORK(IWR), DWORK(IWC) )\n END IF\nC\n IF( COLEQU ) THEN\nC\n DO 80 I = 1, N\n DWORK(IWC+I-1) = ONE / DWORK(IWC+I-1)\n 80 CONTINUE\nC\n CALL MB01SD( 'Column scaling', N, N, DWORK(IU), N2,\n $ DWORK(IWR), DWORK(IWC) )\n CALL MB01SD( 'Column scaling', N, N, DWORK(IU+N), N2,\n $ DWORK(IWR), DWORK(IWC) )\n END IF\n END IF\nC\nC Set S(2,1) to zero.\nC\n CALL DLASET( 'Full', N, N, ZERO, ZERO, S(NP1,1), LDS )\n END IF\nC\n PIVOTU = DWORK(IW)\nC\n IF ( IERR.GT.0 ) THEN\nC\nC Singular matrix. Set INFO and DWORK for error return.\nC\n INFO = 5\n GO TO 160\n END IF\nC\nC Make sure the solution matrix X is symmetric.\nC\n DO 100 I = 1, N - 1\n CALL DAXPY( N-I, ONE, X(I,I+1), LDX, X(I+1,I), 1 )\n CALL DSCAL( N-I, HALF, X(I+1,I), 1 )\n CALL DCOPY( N-I, X(I+1,I), 1, X(I,I+1), LDX )\n 100 CONTINUE\nC\n IF( LSCAL ) THEN\nC\nC Undo scaling for the solution matrix.\nC\n IF( LSCL )\n $ CALL DLASCL( 'G', 0, 0, GNORM, QNORM, N, N, X, LDX,\n $ IERR )\n END IF\n END IF\nC\n IF ( .NOT.JOBX ) THEN\n IF ( .NOT.JOBA )\n $ WRKOPT = 0\nC\nC Estimate the conditioning and compute an error bound on the\nC solution of the algebraic Riccati equation.\nC\n IW = 6\n LOFACT = FACT\n IF ( NOFACT .AND. .NOT.UPDATE ) THEN\nC\nC Compute Ac and its Schur factorization.\nC\n IF ( DISCR ) THEN\n CALL DLASET( 'Full', N, N, ZERO, ONE, DWORK(IW), N )\n CALL DSYMM( 'Left', UPLO, N, N, ONE, G, LDG, X, LDX,\n $ ONE, DWORK(IW), N )\n IF ( NOTRNA ) THEN\nC\nC Compute Ac = inv(I_n + G*X)*A.\nC\n CALL DLACPY( 'Full', N, N, A, LDA, T, LDT )\n CALL DGESV( N, N, DWORK(IW), N, IWORK, T, LDT, IERR )\n ELSE\nC\nC Compute Ac = A*inv(I_n + X*G).\nC\n CALL MA02AD( 'Full', N, N, A, LDA, T, LDT )\n CALL DGESV( N, N, DWORK(IW), N, IWORK, T, LDT, IERR )\n DO 120 I = 2, N\n CALL DSWAP( I-1, T(1,I), 1, T(I,1), LDT )\n 120 CONTINUE\n END IF\nC\n ELSE\nC\n CALL DLACPY( 'Full', N, N, A, LDA, T, LDT )\n IF ( NOTRNA ) THEN\nC\nC Compute Ac = A - G*X.\nC\n CALL DSYMM( 'Left', UPLO, N, N, -ONE, G, LDG, X, LDX,\n $ ONE, T, LDT )\n ELSE\nC\nC Compute Ac = A - X*G.\nC\n CALL DSYMM( 'Right', UPLO, N, N, -ONE, G, LDG, X, LDX,\n $ ONE, T, LDT )\n END IF\n END IF\nC\nC Compute the Schur factorization of Ac, Ac = V*T*V'.\nC Workspace: need 5 + 5*N.\nC prefer larger.\nC\n IWR = IW\n IWI = IWR + N\n IW = IWI + N\n LDW = LDWORK - IW + 1\nC\n CALL DGEES( 'Vectors', 'Not ordered', SB02MS, N, T, LDT,\n $ NROT, DWORK(IWR), DWORK(IWI), V, LDV, DWORK(IW),\n $ LDW, BWORK, IERR )\nC\n IF( IERR.NE.0 ) THEN\n INFO = 6\n GO TO 160\n END IF\nC\n WRKOPT = MAX( WRKOPT, DWORK(IW) + DBLE( IW - 1 ) )\n LOFACT = 'F'\n IW = 6\n END IF\nC\n IF ( .NOT.UPDATE ) THEN\nC\nC Update G, Q, and X using the orthogonal matrix V.\nC\n TRANAT = 'T'\nC\nC Save the diagonal elements of G and Q.\nC\n CALL DCOPY( N, G, LDG+1, DWORK(IW), 1 )\n CALL DCOPY( N, Q, LDQ+1, DWORK(IW+N), 1 )\n IW = IW + N2\nC\n IF ( JOBA )\n $ CALL DLACPY( 'Full', N, N, X, LDX, S(NP1,1), LDS )\n CALL MB01RU( UPLO, TRANAT, N, N, ZERO, ONE, X, LDX, V, LDV,\n $ X, LDX, DWORK(IW), NN, IERR )\n CALL DSCAL( N, HALF, X, LDX+1 )\n CALL MA02ED( UPLO, N, X, LDX )\n IF( .NOT.DISCR ) THEN\n CALL MA02ED( UPLO, N, G, LDG )\n CALL MA02ED( UPLO, N, Q, LDQ )\n END IF\n CALL MB01RU( UPLO, TRANAT, N, N, ZERO, ONE, G, LDG, V, LDV,\n $ G, LDG, DWORK(IW), NN, IERR )\n CALL DSCAL( N, HALF, G, LDG+1 )\n CALL MB01RU( UPLO, TRANAT, N, N, ZERO, ONE, Q, LDQ, V, LDV,\n $ Q, LDQ, DWORK(IW), NN, IERR )\n CALL DSCAL( N, HALF, Q, LDQ+1 )\n END IF\nC\nC Estimate the conditioning and/or the error bound.\nC Workspace: 5 + MAX(1,LWS,LWE) + LWN, where\nC\nC LWS = 0, if FACT = 'F' or LYAPUN = 'R';\nC = 5*N, if FACT = 'N' and LYAPUN = 'O' and DICO = 'C'\nC and JOB = 'C';\nC = 5*N+N*N, if FACT = 'N' and LYAPUN = 'O' and DICO = 'C'\nC and (JOB = 'E' or JOB = 'A');\nC = 5*N+N*N, if FACT = 'N' and LYAPUN = 'O' and\nC DICO = 'D';\nC LWE = 2*N*N, if DICO = 'C' and JOB = 'C';\nC = 4*N*N, if DICO = 'C' and (JOB = 'E' or\nC JOB = 'A');\nC = MAX(3,2*N*N) + N*N, if DICO = 'D' and JOB = 'C';\nC = MAX(3,2*N*N) + 2*N*N, if DICO = 'D' and (JOB = 'E' or\nC JOB = 'A');\nC LWN = 0, if LYAPUN = 'O' or JOB = 'C';\nC = 2*N, if LYAPUN = 'R' and DICO = 'C' and (JOB = 'E' or\nC JOB = 'A');\nC = 3*N, if LYAPUN = 'R' and DICO = 'D' and (JOB = 'E' or\nC JOB = 'A').\nC\n LDW = LDWORK - IW + 1\n IF ( JOBA ) THEN\n JOBS = 'B'\n ELSE\n JOBS = JOB\n END IF\nC\n IF ( DISCR ) THEN\n CALL SB02SD( JOBS, LOFACT, TRANA, UPLO, LYAPUN, N, A, LDA,\n $ T, LDT, V, LDV, G, LDG, Q, LDQ, X, LDX, SEP,\n $ RCOND, FERR, IWORK, DWORK(IW), LDW, IERR )\n ELSE\n CALL SB02QD( JOBS, LOFACT, TRANA, UPLO, LYAPUN, N, A, LDA,\n $ T, LDT, V, LDV, G, LDG, Q, LDQ, X, LDX, SEP,\n $ RCOND, FERR, IWORK, DWORK(IW), LDW, IERR )\n END IF\nC\n WRKOPT = MAX( WRKOPT, DWORK(IW) + DBLE( IW - 1 ) )\n IF( IERR.EQ.NP1 ) THEN\n INFO = 7\n ELSE IF( IERR.GT.0 ) THEN\n INFO = 6\n GO TO 160\n END IF\nC\n IF ( .NOT.UPDATE ) THEN\nC\nC Restore X, G, and Q and set S(2,1) to zero, if needed.\nC\n IF ( JOBA ) THEN\n CALL DLACPY( 'Full', N, N, S(NP1,1), LDS, X, LDX )\n CALL DLASET( 'Full', N, N, ZERO, ZERO, S(NP1,1), LDS )\n ELSE\n CALL MB01RU( UPLO, TRANA, N, N, ZERO, ONE, X, LDX, V,\n $ LDV, X, LDX, DWORK(IW), NN, IERR )\n CALL DSCAL( N, HALF, X, LDX+1 )\n CALL MA02ED( UPLO, N, X, LDX )\n END IF\n IF ( LUPLO ) THEN\n LOUP = 'L'\n ELSE\n LOUP = 'U'\n END IF\nC\n IW = 6\n CALL DCOPY( N, DWORK(IW), 1, G, LDG+1 )\n CALL MA02ED( LOUP, N, G, LDG )\n CALL DCOPY( N, DWORK(IW+N), 1, Q, LDQ+1 )\n CALL MA02ED( LOUP, N, Q, LDQ )\n END IF\nC\n END IF\nC\nC Set the optimal workspace and other details.\nC\n DWORK(1) = WRKOPT\n 160 CONTINUE\n IF( JBXA ) THEN\n DWORK(2) = RCONDU\n DWORK(3) = PIVOTU\n IF ( DISCR ) THEN\n DWORK(4) = RCONDA\n DWORK(5) = PIVOTA\n END IF\n IF( JOBX ) THEN\n IF ( LSCL ) THEN\n SEP = QNORM / GNORM\n ELSE\n SEP = ONE\n END IF\n END IF\n END IF\nC\n RETURN\nC *** Last line of SB02RD ***\n END\n", "meta": {"hexsha": "10a8cabbfbce86d2aa8e7458838a16c867cb4c63", "size": 45084, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/SB02RD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/SB02RD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/SB02RD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 40.2535714286, "max_line_length": 72, "alphanum_fraction": 0.4845621507, "num_tokens": 13714, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9465966702001758, "lm_q2_score": 0.7185943805178139, "lm_q1q2_score": 0.6802190478227207}} {"text": " subroutine log_normal(mu,sig,c)\r\n \r\n!! ~ ~ ~ PURPOSE ~ ~ ~\r\n!! this function generates a random number from a lognormal distribution curve\r\n!! for estimating constituent concentration in the effluent of urban bmps \r\n!! given mean and standard deviation values.\r\n!! Jaehak Jeong, 2017 \r\n\r\n!! ~ ~ ~ INCOMING VARIABLES ~ ~ ~\r\n!! name |units |definition\r\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\r\n!! mu |mg/l |mean value\r\n!! sig |mg/l |standard deviation\r\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\r\n\r\n!! ~ ~ ~ OUTGOING VARIABLES ~ ~ ~\r\n!! name |units |definition\r\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\r\n!! c |mg/l |value generated for distribution\r\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\r\n\r\n!! ~ ~ ~ LOCAL DEFINITIONS ~ ~ ~\r\n!! name |units |definition\r\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\r\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\r\n\r\n\r\n!! ~ ~ ~ ~ ~ ~ END SPECIFICATIONS ~ ~ ~ ~ ~ ~\r\n\r\n real*8,intent(in) :: mu,sig\r\n real*8,intent(out):: c\r\n real*8 :: temp(2),r,theta\r\n real*8,PARAMETER :: PI=3.141592653589793238462\r\n CALL RANDOM_NUMBER(temp)\r\n r = (-2.0d0*log(temp(1)))**0.5\r\n theta = 2.0d0*PI*temp(2)\r\n c = mu+sig*r*sin(theta)\r\n c = exp(c)\r\n end", "meta": {"hexsha": "c84b903ba4287167eab761a1d103736aa91609c5", "size": 1549, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "swat_cli/rev670_source/log_normal.f", "max_stars_repo_name": "GISWAT/erosion-sediment", "max_stars_repo_head_hexsha": "6ab469eba99cba8e5c365cd4d18cba2e8781ccf6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-06-05T06:33:14.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-05T06:33:14.000Z", "max_issues_repo_path": "swat_cli/rev670_source/log_normal.f", "max_issues_repo_name": "GISWAT/erosion-sediment", "max_issues_repo_head_hexsha": "6ab469eba99cba8e5c365cd4d18cba2e8781ccf6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "swat_cli/rev670_source/log_normal.f", "max_forks_repo_name": "GISWAT/erosion-sediment", "max_forks_repo_head_hexsha": "6ab469eba99cba8e5c365cd4d18cba2e8781ccf6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.7179487179, "max_line_length": 82, "alphanum_fraction": 0.3647514526, "num_tokens": 527, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240125464115, "lm_q2_score": 0.724870282120402, "lm_q1q2_score": 0.680018217638441}} {"text": "\tsubroutine bjdaz2 (zlat0,alon0,zlat,alon,delt,az1,az2,lattype) \nc---------------------------------------------------------------------- \nc calculate geocentric distance, azimuth, and back azimuth from a \nc reference point to another point on the earth's surface. \nc \nc\tbruce julian\t 29 dec 1976 \nc\tmodified by d gubbins 23 july 1977 \nc\tfurther modified by s roecker 1981 \nC\t This version allows inputs of lat or colat\nc \nc input arguments:\nc\tif lattype = 1 then \nc\tzlat0 = geocentric latitude of reference point. \nc\tzlat = geocentric latitude of point \nc\tif lattype = 0 then \nc\tzlat0 = geocentric colatitude of reference point.\nc\tzlat = geocentric colatitude of point \nc \nc\talon0 = longitude of reference point. \nc\talon = longitude of point \nc \nc output arguments: \nc\tdelt = epicentral distance \nc\taz1 = azimuth of the point from the reference point. \nc\taz2 = azimuth of the reference point from the point. \nc \nc *** note *** \nc\t all angles are in radians. \nc\t north latitude and east longitude are positive. \nc\t azimuth is measured clockwise from north. \nc\t if one point is at north or south pole, azimuth from that \nc\t\t point will be the limit of the azimuth as the pole is \nc\t\t approached along the meridian whose longitude is given. \nc---------------------------------------------------------------------- \n\timplicit double precision (a-h,o-z)\n\treal*4 zlat0,alon0,zlat,alon,delt,az1,az2\n\tdata pii/3.141592653/\n\ttwopi = pii*2.d0\n\tif (lattype.eq.1) then\n\t alat0=pii*0.5d0-dble(zlat0)\n\t alat=pii*0.5d0-dble(zlat)\n\telse\n\t alat0 = dble(zlat0)\n\t alat = dble(zlat)\n\tend if\n\tst0 = dsin(alat0) \n\tct0 = dcos(alat0) \n\tct1 = dcos(alat) \n\ts0c1 = st0*ct1 \n\tst1 = dsin(alat) \n\ts1c0 = st1*ct0 \n\tdlon = dble(alon) - dble(alon0)\n\tsdlon = dsin(dlon) \n\tcdlon = dcos(dlon) \n\tcdelt = st0*st1*cdlon + ct0*ct1 \n\tb = s0c1 - s1c0*cdlon \n\ta = st1*sdlon \n\tsdelt = dsqrt(b*b+a*a) \n\tddelt = datan2(sdelt, cdelt) \n\taze = 0.d0\n\tif (sdelt.ne.0.d0) aze = datan2(a,b) \nc------calculate back azimuth \n\ta = -sdlon*st0 \n\tb = s1c0 - s0c1*cdlon \n\tazs =pii\n\tif (sdelt.ne.0.d0) azs = datan2(a,b) \nc------make 0 < azimuth < twopi \n\tif(aze .lt. 0.d0) aze = aze + twopi \n\tif(azs .lt. 0.d0) azs = azs + twopi \n\tdelt = ddelt\n\taz1 = aze \n\taz2 = azs \n\treturn \n\tend \n\n", "meta": {"hexsha": "58fe2f4b8260d943aee480cdceafdf63823379dd", "size": 2302, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "lib/utility/libteles/bjdaz2.f", "max_stars_repo_name": "jreyes1108/antelope_contrib", "max_stars_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_stars_repo_licenses": ["BSD-2-Clause", "MIT"], "max_stars_count": 30, "max_stars_repo_stars_event_min_datetime": "2015-02-20T21:44:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-27T02:53:14.000Z", "max_issues_repo_path": "lib/utility/libteles/bjdaz2.f", "max_issues_repo_name": "jreyes1108/antelope_contrib", "max_issues_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_issues_repo_licenses": ["BSD-2-Clause", "MIT"], "max_issues_count": 14, "max_issues_repo_issues_event_min_datetime": "2015-07-07T19:17:24.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-19T19:18:53.000Z", "max_forks_repo_path": "lib/utility/libteles/bjdaz2.f", "max_forks_repo_name": "jreyes1108/antelope_contrib", "max_forks_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_forks_repo_licenses": ["BSD-2-Clause", "MIT"], "max_forks_count": 46, "max_forks_repo_forks_event_min_datetime": "2015-02-06T16:22:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T11:46:37.000Z", "avg_line_length": 30.2894736842, "max_line_length": 73, "alphanum_fraction": 0.6272806255, "num_tokens": 792, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.938124016006303, "lm_q2_score": 0.7248702642896702, "lm_q1q2_score": 0.6800182034189757}} {"text": "\tFUNCTION PR_PRES ( tmpc, thta )\nC************************************************************************\nC* PR_PRES \t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes PRES from TMPC and THTA. Poisson's equation\t*\nC* is used:\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* PRES = 1000. * ( PR_TMCK (TMPC) / THTA ) ** (1 / RKAPPA)\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PR_PRES ( TMPC, THTA )\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tTMPC\t\tREAL \tTemperature in Celsius\t\t*\nC*\tTHTA\t\tREAL \tPotential temperature in Kelvin\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPR_PRES\t\tREAL\t\tStation 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* M. Goodman/RDS\t8/84\tCleaned code\t\t\t\t*\nC* I. Graffman/RDS\t12/87\tGEMPAK4\t\t\t\t\t*\nC* G. Huffman/GSC 7/88\tDocumentation; bounds on tmpc, thta\t*\nC* G. Krueger/EAI 4/96 Replaced C->K constant with TMCK\t*\nC************************************************************************\n INCLUDE 'GEMPRM.PRM'\n INCLUDE 'ERMISS.FNC'\nC------------------------------------------------------------------------\nC*\tCheck for missing data.\nC\n\tIF ( ( ERMISS (tmpc) ) .or. ( ERMISS (thta) )\n * .or. ( tmpc .le. -TMCK ) .or. ( thta .le. 0.) ) THEN\n\t PR_PRES = RMISSD\n\t ELSE\n\t tmpk = PR_TMCK (tmpc)\n\t PR_PRES = 1000. * (tmpk / thta) ** (1 / RKAPPA)\n\tEND IF\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "539e5697adc0b38a10525e72c04927aec97714bf", "size": 1352, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/pr/prpres.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/prpres.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/prpres.f", "max_forks_repo_name": "oxelson/gempak", "max_forks_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 27, "max_forks_repo_forks_event_min_datetime": "2016-06-06T21:55:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T18:23:28.000Z", "avg_line_length": 33.8, "max_line_length": 73, "alphanum_fraction": 0.4474852071, "num_tokens": 449, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037282594921, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6800176601440958}} {"text": "!##############################################################################\n!# ****************************************************************************\n!# poisson2d_method0_simple \n!# ****************************************************************************\n!#\n!# \n!# This module is a demonstration program how to solve a simple Poisson\n!# optimal control problem with constant coefficients on a simple domain.\n!# \n!#\n!# Problem and system definition\n!# -----------------------------\n!# The system to solve is the following:\n!#\n!# -Laplace(y) = f + u\n!# -Laplace(p) = u - z\n!# u = P(-1/alpha p)\n!#\n!# with:\n!# u = primal solution\n!# p = dual solution\n!# z = target solution\n!#\n!# The boundary conditions for the dual solution are =0 on the\n!# Dirichlet boundary.\n!# The projection operator\n!#\n!# P(g) = P(g)g = P[a,b](g)g = max(a,min(b,g))\n!#\n!# with\n!#\n!# P(h)g = a , for all x with h(x) < a\n!# = g(x) , for all x with a <= h(x) <= b\n!# = b , for all x with h(x) > b\n!#\n!# for a function g=g(x) defines the projection to the interval [a,b].\n!# In the moment where this operator get's active, the system\n!# is going to be nonlinear!\n!#\n!# In the simple case b=-a=infinity, the projection operator is the\n!# identity, so we get the system\n!#\n!# -Laplace(y) + 1/alpha p = f\n!# -Laplace(p) - u = -z\n!#\n!# which corresponds to the system\n!#\n!# ( A 1/alpha M ) ( y )= ( f )\n!# ( -M A ) ( p ) ( -z )\n!#\n!# A simple UMFPACK Gauss elimination can be used to solve this\n!# system, as it is completely linear.\n!#\n!# In the moment where the projection is active, the whole\n!# thing gets a little bit harder. In that moment, we have\n!# to solve\n!#\n!# ( A -P(u) ) ( y ) = ( f )\n!# ( -M A ) ( p ) ( -z )\n!#\n!# To solve this system, we can use a Newton iteration.\n!# This is written down as follows:\n!#\n!# ( y_n+1 ) = ( y_n ) + ( A -P'(u_n)(-1/alpha .) )^-1 [ ( f ) - ( A -P(u_n)(-1/alpha .) ) ( y_n ) ]\n!# ( p_n+1 ) ( p_n ) ( -M A ) [ ( -z ) ( -M A ) ( p_n ) ]\n!#\n!# <=>\n!#\n!# ( y_n+1 ) = ( y_n ) + ( A P'(u_n)(1/alpha .) )^-1 [ ( f ) - ( A P(u_n)(1/alpha .) ) ( y_n ) ]\n!# ( p_n+1 ) ( p_n ) ( -M A ) [ ( -z ) ( -M A ) ( p_n ) ]\n!#\n!# where u_n = -1/alpha p_n and P'(g) (and its corresponding matrix) is\n!# the semismooth Newton operator the projection P(g). This operator is defined by\n!#\n!# P'(h)g (x) = g(x) , if a <= h(x) <= b\n!# = 0 , elsewhere\n!#\n!# or in another way of writing:\n!#\n!# P'(h) = Id , for all x with a <= h(x) <= b\n!# = 0 , elsewhere.\n!#\n!# For the corresponding matrix, this can be interpreted as\n!#\n!# P'(h)g = M , for all nodes (vertices) x where a <= h(x) <= b\n!# = 0 , elsewhere (-> insert a zero row to the mass matrix!)\n!#\n!# Iterating this Newton iteration to convergence gives the optimal control u.\n!#\n!# -----\n!#\n!# Current problem:\n!#\n!# 1.) bpointBC=TRUE:\n!#\n!# min J(y,u) = |y-z|^2 + alpha/2 |u|\n!#\n!# with alpha=0.001 and\n!#\n!# -Laplace(y) = u\n!# y = 0 in (0,0)\n!# dy/dn = 0 on boundary of [0,1]^2 \\ (0,0)\n!# -1 <= u <= 1\n!# z = x1 + x2\n!#\n!# 2.) bpointBC=FALSE:\n!#\n!# min J(y,u) = |y-z|^2 + alpha/2 |u|\n!#\n!# with alpha=0.001 and\n!#\n!# -Laplace(y) = u\n!# y = 0 on boundary of [0,1]^2\n!# 0 <= u <= 15\n!# z = x1 + x2\n!#\n!##############################################################################\n\nmodule poisson2d_method0_simple\n\n use fsystem\n use genoutput\n use storage\n use boundary\n use cubature\n use linearalgebra\n use matrixfilters\n use vectorfilters\n use bcassembly\n use triangulation\n use spatialdiscretisation\n use ucd\n use pprocerror\n use genoutput\n use stdoperators\n use spdiscprojection\n use convection\n use analyticprojection\n use optcontrolconvection\n use matrixio\n use collection\n use filtersupport\n use scalarpde\n use bilinearformevaluation\n use linearformevaluation\n use multilevelprojection\n use linearsolver\n use matrixmodification\n \n use poisson2d_callback\n \n implicit none\n\ncontains\n\n ! -----------------------------------------------------\n\n subroutine massmatfilter (rmatrix, rvector, dalphaC, dmin, dmax)\n \n ! Filters a mass matrix. The lines in the matrix rmatrix corresponding\n ! to all entries in the (control-)vector violating the constraints\n ! of the problem.\n \n ! Matrix to be filtered\n type(t_matrixScalar), intent(inout) :: rmatrix\n\n ! Vector containing a dial solution lambda. Whereever -1/alpha*lambda\n ! violates the control constraints given by rmatrixComponents, the corresponding\n ! lines are set to 0.\n type(t_vectorScalar), intent(in) :: rvector\n \n ! ALPHA regularisation parameter from the space-time matrix\n real(dp), intent(in) :: dalphaC\n \n ! minimum bound for the control\n real(dp), intent(in) :: dmin\n\n ! maximum bound for the control\n real(dp), intent(in) :: dmax\n \n ! local variables\n real(dp), dimension(:), pointer :: p_Ddata\n integer, dimension(:), allocatable :: p_Idofs\n integer :: i,nviolate\n real(dp) :: du\n \n ! Get the vector data\n call lsyssc_getbase_double (rvector,p_Ddata)\n \n ! Figure out the DOF's violating the constraints\n allocate(p_Idofs(rvector%NEQ))\n \n nviolate = 0\n do i=1,rvector%NEQ\n du = -p_Ddata(i)/dalphaC\n if ((du .le. dmin) .or. (du .ge. dmax)) then\n nviolate = nviolate + 1\n p_Idofs(nviolate) = i\n end if\n end do\n \n if (nviolate .gt. 0) then\n ! Filter the matrix\n call mmod_replaceLinesByZero (rmatrix,p_Idofs(1:nviolate))\n end if\n \n deallocate(p_Idofs)\n\n end subroutine\n\n ! ***************************************************************************\n \n!\n\n subroutine projectControlTimestep (rdualSolution,dumin,dumax)\n\n!\n ! Projects a dual solution vector u in such a way, that\n ! dumin <= u <= dumax holds.\n!\n\n!\n ! Minimum value for u\n real(DP), intent(in) :: dumin\n\n ! Maximum value for u\n real(DP), intent(in) :: dumax\n!\n\n!\n ! Vector to be restricted\n type(t_vectorScalar), intent(inout) :: rdualSolution\n!\n\n!\n \n ! local variables\n real(DP), dimension(:), pointer :: p_Ddata\n integer :: i\n \n ! Get the vector array\n call lsyssc_getbase_double (rdualSolution,p_Ddata)\n \n ! Restrict the vector\n do i=1,rdualSolution%NEQ\n p_Ddata(i) = min(max(p_Ddata(i),dumin),dumax)\n end do\n\n end subroutine\n \n ! ***************************************************************************\n\n!\n\n subroutine poisson2d_0_simple\n \n!\n ! This is an all-in-one poisson solver for directly solving a Poisson\n ! problem without making use of special features like collections\n ! and so on. The routine performs the following tasks:\n !\n ! 1.) Read in parametrisation\n ! 2.) Read in triangulation\n ! 3.) Set up RHS\n ! 4.) Set up matrix\n ! 5.) Create solver structure\n ! 6.) Solve the problem\n ! 7.) Write solution to GMV file\n ! 8.) Release all variables, finish\n!\n\n!\n\n ! Definitions of variables.\n !\n ! We need a couple of variables for this problem. Let's see...\n !\n ! An object for saving the domain:\n type(t_boundary) :: rboundary\n \n ! An object for saving the triangulation on the domain\n type(t_triangulation) :: rtriangulation\n\n ! An object specifying the discretisation.\n ! This contains also information about trial/test functions,...\n type(t_blockDiscretisation) :: rdiscretisation\n type(t_spatialDiscretisation) :: rdiscrOutput\n \n ! A bilinear and linear form describing the analytic problem to solve\n type(t_linearForm) :: rlinform\n \n ! A scalar matrix and vector. The vector accepts the RHS of the problem\n ! in scalar form.\n type(t_matrixScalar) :: rmatrixLaplace, rmatrixMass, rmatrixMassLump\n\n ! A block matrix and a couple of block vectors. These will be filled\n ! with data for the linear solver.\n type(t_matrixBlock) :: rmatrixBlock\n type(t_vectorBlock) :: rvectorBlock,rrhsBlock,rtempRhsBlock\n type(t_vectorScalar) :: rvectorTmp,rvectorOutput\n\n ! A set of variables describing the discrete boundary conditions.\n type(t_boundaryRegion) :: rboundaryRegion\n type(t_discreteBC), target :: rdiscreteBC\n\n ! A solver node that accepts parameters for the linear solver\n type(t_linsolNode), pointer :: p_rsolverNode\n\n ! An array for the system matrix(matrices) during the initialisation of\n ! the linear solver.\n type(t_matrixBlock), dimension(1) :: Rmatrices\n\n ! NLMAX receives the level where we want to solve.\n integer :: NLMAX\n \n ! Error indicator during initialisation of the solver\n integer :: ierror\n \n ! Error of FE function to reference function\n real(DP) :: derror\n \n ! Data for the Newton iteration\n integer :: ite, nmaxiterations\n real(dp) :: dinitRes, dcurrentRes\n \n ! Relaxation parameters\n real(DP) :: dalpha\n logical :: bboundsActive\n integer :: itypeBC\n real(dp) :: dmax,dmin\n \n ! Output block for UCD output to GMV file\n type(t_ucdExport) :: rexport\n real(DP), dimension(:), pointer :: p_Ddata\n\n ! Ok, let's start.\n !\n ! We want to solve our Poisson problem on level...\n NLMAX = 6\n \n ! Newton iteration counter\n nmaxiterations = 10\n \n ! Relaxation parameter\n dalpha = 0.001_DP\n \n ! 0=Neumann problem\n ! 1=BC on whole boundary.\n ! 2=BC only on (0,0). \n itypeBC = 0\n \n select case (itypeBC)\n case (0)\n bboundsActive = .false.\n case (1)\n ! Bounds on the control\n bboundsActive = .true.\n dmin = -1.0_DP\n dmax = 1.0_DP\n case (2)\n ! Bounds on the control\n bboundsActive = .true.\n dmin = 0.0_DP\n dmax = 15.0_DP\n case (3)\n ! No bounds\n bboundsActive = .false.\n case (4)\n ! No bounds\n bboundsActive = .false.\n end select\n \n ! At first, read in the parametrisation of the boundary and save\n ! it to rboundary.\n call boundary_read_prm(rboundary, './pre/QUAD.prm')\n \n ! Now read in the basic triangulation.\n call tria_readTriFile2D (rtriangulation, './pre/QUAD.tri', rboundary)\n \n ! Refine it.\n call tria_quickRefine2LevelOrdering (NLMAX-1,rtriangulation,rboundary)\n \n ! And create information about adjacencies and everything one needs from\n ! a triangulation.\n call tria_initStandardMeshFromRaw (rtriangulation,rboundary)\n \n ! Set up a block discretisation structure for two components:\n ! Primal and dual solution vector.\n call spdiscr_initBlockDiscr (rdiscretisation,2,&\n rtriangulation, rboundary)\n \n ! Set up the blocks. Both are discretised with the same finite element.\n call spdiscr_initDiscr_simple (rdiscretisation%RspatialDiscr(1), &\n EL_Q1,CUB_G3X3,rtriangulation, rboundary)\n call spdiscr_duplicateDiscrSc (rdiscretisation%RspatialDiscr(1), &\n rdiscretisation%RspatialDiscr(2), .true.)\n \n ! Now as the discretisation is set up, we can start to generate\n ! the structure of the system matrix which is to solve.\n ! We create a scalar matrix, based on the discretisation structure\n ! for our one and only solution component.\n call bilf_createMatrixStructure (rdiscretisation%RspatialDiscr(1),&\n LSYSSC_MATRIX9,rmatrixLaplace)\n \n ! Assemble the Laplace matrix.\n call stdop_assembleLaplaceMatrix (rmatrixLaplace)\n \n ! And a mass matrix; we need it for the coupling.\n ! Share the structure with the Laplace matrix.\n call lsyssc_duplicateMatrix (rmatrixLaplace,rmatrixMass,&\n LSYSSC_DUP_SHARE,LSYSSC_DUP_REMOVE)\n call stdop_assembleSimpleMatrix (rmatrixMass,DER_FUNC,DER_FUNC)\n \n ! Lumped mass matrix\n call lsyssc_duplicateMatrix (rmatrixMass,rmatrixMassLump,&\n LSYSSC_DUP_SHARE,LSYSSC_DUP_COPY)\n call lsyssc_lumpMatrixScalar (rmatrixMassLump,LSYSSC_LUMP_DIAG,.true.)\n\n ! -----\n ! Boundary conditions\n !\n ! In our example, we have pure Dirichlet-0-BC on all boundary components.\n \n call bcasm_initDiscreteBC(rdiscreteBC)\n \n select case (itypeBC)\n case (0)\n case (1,3)\n ! Edge 1 of boundary component 1 the domain.\n call boundary_createRegion(rboundary,1,1,rboundaryRegion)\n call bcasm_newDirichletBConRealBD (rdiscretisation,1,&\n rboundaryRegion,rdiscreteBC,&\n getBoundaryValuesPrimal_2D)\n \n ! Now to the edge 2 of boundary component 1 the domain.\n call boundary_createRegion(rboundary,1,2,rboundaryRegion)\n call bcasm_newDirichletBConRealBD (rdiscretisation,1,&\n rboundaryRegion,rdiscreteBC,&\n getBoundaryValuesPrimal_2D)\n \n ! Edge 3 of boundary component 1.\n call boundary_createRegion(rboundary,1,3,rboundaryRegion)\n call bcasm_newDirichletBConRealBD (rdiscretisation,1,&\n rboundaryRegion,rdiscreteBC,&\n getBoundaryValuesPrimal_2D)\n \n ! Edge 4 of boundary component 1. That's it.\n call boundary_createRegion(rboundary,1,4,rboundaryRegion)\n call bcasm_newDirichletBConRealBD (rdiscretisation,1,&\n rboundaryRegion,rdiscreteBC,&\n getBoundaryValuesPrimal_2D)\n\n ! ---\n ! The same for the dual variable.\n call boundary_createRegion(rboundary,1,1,rboundaryRegion)\n call bcasm_newDirichletBConRealBD (rdiscretisation,2,&\n rboundaryRegion,rdiscreteBC,&\n getBoundaryValuesDual_2D)\n\n ! Now to the edge 2 of boundary component 1 the domain.\n call boundary_createRegion(rboundary,1,2,rboundaryRegion)\n call bcasm_newDirichletBConRealBD (rdiscretisation,2,&\n rboundaryRegion,rdiscreteBC,&\n getBoundaryValuesDual_2D)\n \n ! Edge 3 of boundary component 1.\n call boundary_createRegion(rboundary,1,3,rboundaryRegion)\n call bcasm_newDirichletBConRealBD (rdiscretisation,2,&\n rboundaryRegion,rdiscreteBC,&\n getBoundaryValuesDual_2D)\n \n ! Edge 4 of boundary component 1. That's it.\n call boundary_createRegion(rboundary,1,4,rboundaryRegion)\n call bcasm_newDirichletBConRealBD (rdiscretisation,2,&\n rboundaryRegion,rdiscreteBC,&\n getBoundaryValuesDual_2D)\n \n case (2,4)\n ! Edge 1 of boundary component 1 the domain.\n call boundary_createRegion(rboundary,1,1,rboundaryRegion)\n rboundaryRegion%dmaxParam = 0.0_DP\n \n call bcasm_newDirichletBConRealBD (rdiscretisation,1,&\n rboundaryRegion,rdiscreteBC,&\n getBoundaryValuesPrimal_2D)\n \n ! ---\n ! The same for the dual variable.\n call boundary_createRegion(rboundary,1,1,rboundaryRegion)\n rboundaryRegion%dmaxParam = 0.0_DP\n \n call bcasm_newDirichletBConRealBD (rdiscretisation,2,&\n rboundaryRegion,rdiscreteBC,&\n getBoundaryValuesDual_2D)\n\n end select\n \n ! -----\n ! Linear system: Basic structure.\n !\n ! Create a 2x2 matrix and 2-block vectors from the discretisation.\n call lsysbl_createVecBlockByDiscr (rdiscretisation,rrhsBlock)\n call lsysbl_createVecBlockByDiscr (rdiscretisation,rvectorBlock)\n call lsysbl_createVecBlockByDiscr (rdiscretisation,rtempRhsBlock)\n call lsyssc_createVecByDiscr (rdiscretisation%RspatialDiscr(1),rvectorTmp)\n \n ! Create the RHS vector f of the primal equation\n rlinform%itermCount = 1\n rlinform%Idescriptors(1) = DER_FUNC\n call linf_buildVectorScalar (rdiscretisation%RspatialDiscr(1),&\n rlinform,.true.,rrhsBlock%RvectorBlock(1),&\n coeff_RHS_primal_2D)\n \n ! Create the RHS vector -z of the dual equation\n call linf_buildVectorScalar (rdiscretisation%RspatialDiscr(1),&\n rlinform,.true.,rrhsBlock%RvectorBlock(2),&\n coeff_RHS_dual_2D)\n \n call vecfil_discreteBCrhs (rrhsBlock,rdiscreteBC)\n \n ! -----\n ! Newton iteration\n !\n ! Initialise the solution vector.\n call lsysbl_clearVector (rvectorBlock)\n \n call vecfil_discreteBCsol (rvectorBlock,rdiscreteBC)\n \n do ite = 1,nmaxIterations\n \n ! Create the nonliear defect\n ! (d1) = ( f ) - ( A -P(u)(-1/alpha .) ) ( y )\n ! (d2) ( -z ) ( -M A ) ( p )\n ! We do this manually...\n \n call lsysbl_getbase_double (rtempRhsBlock,p_Ddata)\n call lsysbl_copyVector (rrhsBlock,rtempRhsBlock)\n \n call lsyssc_scalarMatVec (rmatrixLaplace,&\n rvectorBlock%RvectorBlock(1),rtempRhsBlock%RvectorBlock(1),-1.0_DP,1.0_DP)\n call lsyssc_scalarMatVec (rmatrixLaplace,&\n rvectorBlock%RvectorBlock(2),rtempRhsBlock%RvectorBlock(2),-1.0_DP,1.0_DP)\n call lsyssc_scalarMatVec (rmatrixMass,&\n rvectorBlock%RvectorBlock(1),rtempRhsBlock%RvectorBlock(2),1.0_DP,1.0_DP)\n \n ! No constraints: -P(u_n) = 1/alpha p_n -> multiply p_n by weighted Mass matrix.\n ! Constraints active: Create the projection and multiply by the weighted mass matrix.\n call lsyssc_copyVector (rvectorBlock%RvectorBlock(2),rvectorTmp)\n call lsyssc_scaleVector (rvectorTmp,-1.0_DP/dalpha)\n if (bboundsActive) then\n call projectControlTimestep (rvectorTmp,dmin,dmax)\n end if\n call lsyssc_scalarMatVec (rmatrixMass,&\n rvectorTmp,rtempRhsBlock%RvectorBlock(1),1.0_DP,1.0_DP)\n \n if (itypeBC .eq. 0) then\n ! Prepare a pure Neumann problem.\n !\n ! impose int(f)=0 into the RHS using the l1-0 filter\n call vecfil_subvectorSmallL1To0 (rtempRhsBlock,1)\n call vecfil_subvectorSmallL1To0 (rtempRhsBlock,2)\n end if\n\n ! Include boundary conditions\n call vecfil_discreteBCdef (rtempRhsBlock,rdiscreteBC)\n \n ! Check for convergence\n if (ite .eq. 1) then\n dinitRes = lsysbl_vectorNorm(rtempRhsBlock,LINALG_NORML2)\n call output_line ('Iteration: '//TRIM(sys_siL(ite-1,10))//&\n ', Initial defect: '//sys_sdEL(dinitRes,10))\n else\n dcurrentRes = lsysbl_vectorNorm(rtempRhsBlock,LINALG_NORML2)\n call output_line ('Iteration: '//TRIM(sys_siL(ite-1,10))//&\n ', Current defect: '//sys_sdEL(dcurrentRes,10))\n if (dcurrentRes .lt. dinitRes * 1E-10_DP) exit\n end if\n \n ! Prepare the preconditioner matrix (Newton).\n call lsysbl_createMatBlockByDiscr (rdiscretisation,rmatrixBlock)\n call lsyssc_duplicateMatrix (rmatrixLaplace,rmatrixBlock%RmatrixBlock(1,1),&\n LSYSSC_DUP_COPY,LSYSSC_DUP_COPY)\n call lsyssc_duplicateMatrix (rmatrixLaplace,rmatrixBlock%RmatrixBlock(2,2),&\n LSYSSC_DUP_COPY,LSYSSC_DUP_COPY)\n call lsyssc_duplicateMatrix (rmatrixMass,rmatrixBlock%RmatrixBlock(2,1),&\n LSYSSC_DUP_SHARE,LSYSSC_DUP_COPY)\n rmatrixBlock%RmatrixBlock(2,1)%dscaleFactor = -1.0_DP\n \n ! Copy also the mass matrix for the 4th block. In the case of no\n ! control constraints, that's it!\n call lsyssc_duplicateMatrix (rmatrixMass,rmatrixBlock%RmatrixBlock(1,2),&\n LSYSSC_DUP_SHARE,LSYSSC_DUP_COPY)\n rmatrixBlock%RmatrixBlock(1,2)%dscaleFactor = -(-1.0_DP/dalpha)\n\n if (bboundsActive) then\n ! Filter the mass matrix. Set those rows to zero where the DOF's are out\n ! of bounds. The result is the derivative of the projection operator...\n call massmatfilter (rmatrixBlock%RmatrixBlock(1,2), &\n rvectorBlock%RvectorBlock(2), dalpha, dmin, dmax)\n end if\n \n call matfil_discreteBC (rmatrixBlock,rdiscreteBC)\n \n if (itypeBC .eq. 0) then\n ! Prepare a pure Neumann problem.\n !\n ! impose int(f)=0 into the RHS using the l1-0 filter\n call vecfil_OneEntryZero (rtempRhsBlock,1,1)\n call vecfil_OneEntryZero (rtempRhsBlock,2,1)\n \n ! Impose the condition int(u)=0 into the matrix using\n ! the lumped mass matrix.\n call mmod_replaceLineByLumpedMass (rmatrixBlock%RmatrixBlock(1,1),1,rmatrixMassLump)\n call mmod_replaceLineByLumpedMass (rmatrixBlock%RmatrixBlock(2,2),1,rmatrixMassLump)\n call mmod_replaceLinesByZero (rmatrixBlock%RmatrixBlock(1,2),(/1/))\n call mmod_replaceLinesByZero (rmatrixBlock%RmatrixBlock(2,1),(/1/))\n \n end if\n \n ! Prepare an UMFPACK solver for the system\n call linsol_initUMFPACK4(p_rsolverNode)\n \n ! Set the output level of the solver to 2 for some output\n p_rsolverNode%ioutputLevel = 2\n \n ! Attach the system matrix to the solver.\n ! First create an array with the matrix data (on all levels, but we\n ! only have one level here), then call the initialisation\n ! routine to attach all these matrices.\n ! Remark: Don't make a call like\n ! CALL linsol_setMatrices(p_RsolverNode,(/p_rmatrix/))\n ! This doesn't work on all compilers, since the compiler would have\n ! to create a temp array on the stack - which does not always work!\n call linsol_setMatrix(p_RsolverNode,rmatrixBlock)\n \n ! Initialise structure/data of the solver. This allows the\n ! solver to allocate memory / perform some precalculation\n ! to the problem.\n call linsol_initStructure (p_rsolverNode, ierror)\n if (ierror .ne. LINSOL_ERR_NOERROR) stop\n call linsol_initData (p_rsolverNode, ierror)\n if (ierror .ne. LINSOL_ERR_NOERROR) stop\n \n ! Preconditioning of the defect by the inverse of the Newton matrix\n call linsol_precondDefect (p_rsolverNode,rtempRhsBlock)\n \n ! Release solver data and structure\n call linsol_doneData (p_rsolverNode)\n call linsol_doneStructure (p_rsolverNode)\n \n ! Release the solver node and all subnodes attached to it (if at all):\n call linsol_releaseSolver (p_rsolverNode)\n \n ! Release the matrix\n call lsysbl_releaseMatrix (rmatrixBlock)\n\n if (itypeBC .eq. 0) then\n ! Solution filter for the pure Neumann problem.\n ! Actually not necessaty.\n !\n ! Impose int(f)=0 into the correction using the L1-0 filter\n call vecfil_subvectorL1To0byLmass (rtempRhsBlock,1,rmatrixMassLump)\n\n end if\n\n ! Sum up the correction to the current solution.\n call lsysbl_vectorLinearComb (rtempRhsBlock,rvectorBlock,1.0_DP,1.0_DP)\n \n ! Plug in the BC's to the solution\n call vecfil_discreteBCsol (rvectorBlock,rdiscreteBC)\n \n end do\n \n ! That's it, rvectorBlock now contains our solution. We can now\n ! start the postprocessing.\n ! Start UCD export to GMV file:\n call ucd_startVTK (rexport,UCD_FLAG_STANDARD,rtriangulation,&\n 'gmv/up2d_0_simple.vtk')\n \n call spdp_stdProjectionToP1Q1Scalar (rvectorBlock%RvectorBlock(1),&\n rvectorOutput,rdiscrOutput)\n \n call lsyssc_getbase_double (rvectorOutput,p_Ddata)\n \n call ucd_addVariableVertexBased (rexport,'solprimal',UCD_VAR_STANDARD, p_Ddata)\n call spdp_stdProjectionToP1Q1Scalar (rvectorBlock%RvectorBlock(2),&\n rvectorOutput,rdiscrOutput)\n call ucd_addVariableVertexBased (rexport,'soldual',UCD_VAR_STANDARD, p_Ddata)\n \n call lsyssc_copyVector (rvectorBlock%RvectorBlock(2),rvectorTmp)\n call lsyssc_scaleVector (rvectorTmp,-1.0_DP/dalpha)\n if (bboundsActive) then\n call projectControlTimestep (rvectorTmp,dmin,dmax)\n end if\n call spdp_stdProjectionToP1Q1Scalar (rvectorTmp,&\n rvectorOutput,rdiscrOutput)\n call ucd_addVariableVertexBased (rexport,'control',UCD_VAR_STANDARD, p_Ddata)\n \n ! Write the file to disc, that's it.\n call ucd_write (rexport)\n call ucd_release (rexport)\n \n ! Calculate the error to the reference function.\n call pperr_scalar (rvectorBlock%RvectorBlock(1),PPERR_L2ERROR,derror,&\n getReferenceFunction_2D)\n call output_line ('L2-error: ' // sys_sdEL(derror,10) )\n\n call pperr_scalar (rvectorBlock%RvectorBlock(1),PPERR_H1ERROR,derror,&\n getReferenceFunction_2D)\n call output_line ('H1-error: ' // sys_sdEL(derror,10) )\n \n ! We are finished - but not completely!\n ! Now, clean up so that all the memory is available again.\n \n ! Release the block matrix/vectors\n call lsyssc_releaseVector (rvectorOutput)\n call lsyssc_releaseVector (rvectorTmp)\n call lsysbl_releaseVector (rtempRhsBlock)\n call lsysbl_releaseVector (rvectorBlock)\n call lsysbl_releaseVector (rrhsBlock)\n\n call lsyssc_releaseMatrix (rmatrixMassLump)\n call lsyssc_releaseMatrix (rmatrixMass)\n call lsyssc_releaseMatrix (rmatrixLaplace)\n \n ! Release our discrete version of the boundary conditions\n call bcasm_releaseDiscreteBC (rdiscreteBC)\n\n ! Release the discretisation structure and all spatial discretisation\n ! structures in it.\n call spdiscr_releaseDiscr(rdiscrOutput)\n call spdiscr_releaseBlockDiscr(rdiscretisation)\n \n ! Release the triangulation.\n call tria_done (rtriangulation)\n \n ! Finally release the domain, that's it.\n call boundary_release (rboundary)\n \n end subroutine\n\nend module\n", "meta": {"hexsha": "89936ee241a5eff7102715521899484372d85173", "size": 26185, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "area51/stationaryoptcontrol/src/poisson2d_method0_simple.f90", "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/stationaryoptcontrol/src/poisson2d_method0_simple.f90", "max_issues_repo_name": "tudo-math-ls3/FeatFlow2", "max_issues_repo_head_hexsha": "56159aff28f161aca513bc7c5e2014a2d11ff1b3", "max_issues_repo_licenses": ["Intel", "Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "area51/stationaryoptcontrol/src/poisson2d_method0_simple.f90", "max_forks_repo_name": "tudo-math-ls3/FeatFlow2", "max_forks_repo_head_hexsha": "56159aff28f161aca513bc7c5e2014a2d11ff1b3", "max_forks_repo_licenses": ["Intel", "Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.2422611036, "max_line_length": 109, "alphanum_fraction": 0.6265037235, "num_tokens": 7339, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037241905732, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6800176571570229}} {"text": "real*8 function SHSjkPG0(incspectra, j, k, l, m, evec, lwin)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis function will compute the expected windowed cross-power spectra for a two fields,\n!\twhich are windowed by tapers j and k. Note that this is only valid for zonal tapers. \n!\tThis corresponds to the variable (this is eq. D8 of Wieczoek and Simons 2005):\n!\n!\t (j,k)\n!\t< S (l,m) >\n!\t PG\n!\n!\tIt can be shown that SPGjk(l,-m) = SPGjk(l,m).\n!\n!\tCalling Parameteters\n!\t\tIN\n!\t\t\tincspectra\tKnonw input (cross) power spectra\n!\t\t\t\t\tas a function of degree.\n!\t\t\tj, k\t\tTaper numbers\n!\t\t\tl, m \t\tAngular degree and order.\n!\t\t\tevec\t\tMatrix containing the spectral coefficients of the \n!\t\t\t\t\tzonal tapers.\n!\t\t\tlwin\t\tSpherical harmonic bandwidth of the windows.\n!\n!\tDependencies: Wigner3j.\n!\n!\tWritten by Mark Wieczorek, May 2006.\n!\n!\tCopyright (c) 2005, Mark A. Wieczorek\n!\tAll rights reserved.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\t\t\n\tuse SHTOOLS, only: Wigner3j\n\timplicit none\n\t\n\treal*8, intent(in) ::\tincspectra(:), evec(:,:)\n\tinteger, intent(in) ::\tlwin, l, m, j, k\n\tinteger ::\ti, l1, l2, imin, imax, &\n\t\t\tl10min, l10max, l1min, l1max, l20min, l20max, l2min, l2max\n\treal*8 :: \twl10(lwin+l+1), wl20(lwin+l+1), &\n\t\t\twl1(lwin+l+1), wl2(lwin+l+1)\n\t\n\t\t\n\tif (size(evec(1,:)) < lwin+1 .or. size(evec(:,1)) < lwin+1) then\n\t\tprint*, \"Error --- SHSjkPG\"\n\t\tprint*, \"EVEC must be dimensioned (LWIN+1, LWIN+1) where LWIN is \", lwin\n\t\tprint*, \"Input array is dimensioned\", size(evec(:,1)), size(evec(1,:))\n\t\tstop\n\telseif(size(incspectra(:)) < l+lwin + 1) then\n\t\tprint*, \"Error --- SHSjkPG\"\n\t\tprint*, \"INCSPECTRA must be dimensioned as (L+LWIN+1) where L and LWIN are \", l, lwin\n\t\tprint*, \"Input arrays is dimensioned \", size(incspectra)\n\t\tstop\n\telseif(j>lwin+1 .or. k>lwin+1) then\n\t\tprint*, \"Error --- SHSjkPG\"\n\t\tprint*, \"J and K must be less then LWIN+1.\"\n\t\tprint*, \"J = \", j\n\t\tprint*, \"K = \", k\n\t\tstop\n\tendif\n\t\n\tSHSjkPG0 = 0.0d0\n\t\n\tif (l\n!\n! This program is free software; you can redistribute it and/or modify\n! it under the terms of the GNU General Public License as published by\n! the Free Software Foundation; either version 2 of the License, or\n! (at your option) any later version.\n!\n! This program is distributed in the hope that it will be useful,\n! but WITHOUT ANY WARRANTY; without even the implied warranty of\n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n! GNU General Public License for more details.\n!\nprogram powspec\n\nuse precision, pr => dp\n\nIMPLICIT NONE\n\ninclude \"/usr/include/fftw3.f\"\ninteger :: plan_rc, plan_cr\n\ninteger, parameter :: N = 500\ninteger :: i, j, k, t\nreal(pr) :: rr, trash1, trash2, trash3, fre, fim\nreal(pr), dimension(:) :: xc(200), x(200), d(N), r(5)\ncomplex(pr), dimension(101) :: x_hat, xc_hat\ncharacter(len=4) :: rj\n\n\nr = (/1.5_pr, 3.3_pr, 3.5_pr, 3.55_pr, 4._pr/)\n\nprint '(F4.2)', r(1), r(2), r(3), r(4), r(5)\n\ndo j = 1, 5\n\n write(rj, '(F4.2)') r(j)\n print *, 'ej8a_r_'//trim(rj)//'.dat'\n\n open(unit=10, file='ej8a_r_'//trim(rj)//'.dat', action='READ')\n read(10, *)\n\n do i = 1, N\n read(10, *) t, trash1, trash2, d(i), trash3, rr\n end do\n close(10)\n\n call dfftw_plan_dft_r2c_1d(plan_rc, 200, xc, xc_hat, FFTW_MEASURE)\n xc = d(301:500)\n call dfftw_execute_dft_r2c(plan_rc, xc, xc_hat)\n x_hat = xc_hat\n\n call dfftw_destroy_plan(plan_rc)\n\n open(unit=11, file='fourier'//'ej8a_r_'//trim(rj)//'.dat', action='write',&\n & status='unknown')\n write(11, *) \"# freq real imag\"\n\n do k = -100, 100, 1\n if (k < 0) then\n fre = real(conjg(x_hat(-k+1) )/real(200, pr))\n fim = imag(conjg(x_hat(-k+1) )/real(200, pr))\n write(11,*) real(k, pr), fre, fim\n else\n fre = real(x_hat(k+1) /real(200, pr))\n fim = imag(x_hat(k+1) /real(200, pr))\n write(11,*) real(k, pr), fre, fim\n end if\n end do\n close(11)\nend do\n\nend program powspec\n", "meta": {"hexsha": "2040c179ef7041c020bc93f2d69ed880c37e60b5", "size": 2112, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lab1/8/ej8b.f90", "max_stars_repo_name": "BrunoSanchez/fisicaComp", "max_stars_repo_head_hexsha": "be5f61675fee6e370b6d3f5a7eb254fd112c61b0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lab1/8/ej8b.f90", "max_issues_repo_name": "BrunoSanchez/fisicaComp", "max_issues_repo_head_hexsha": "be5f61675fee6e370b6d3f5a7eb254fd112c61b0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lab1/8/ej8b.f90", "max_forks_repo_name": "BrunoSanchez/fisicaComp", "max_forks_repo_head_hexsha": "be5f61675fee6e370b6d3f5a7eb254fd112c61b0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.7894736842, "max_line_length": 79, "alphanum_fraction": 0.5918560606, "num_tokens": 711, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527944504228, "lm_q2_score": 0.7981867873410141, "lm_q1q2_score": 0.6800174639685823}} {"text": "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! Main test program for the FFT interface\n! - use input data from a NAG FFT library for validation\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\nprogram fft_test_c2c\n\nuse decomp_2d\nuse decomp_2d_fft\n\nimplicit none\n\ninteger, parameter :: nx=2, ny=3, nz=4\ninteger, parameter :: p_row=2, p_col=2\n\ncomplex(mytype), allocatable, dimension(:,:,:) :: in, out\n\ncomplex(mytype), dimension(nx,ny,nz) :: in1, out1\ninteger :: ierror, i,j,k\n\ninterface\n subroutine assemble_global(ndir,local,global,nx,ny,nz)\n use decomp_2d\n integer, intent(IN) :: ndir\n integer, intent(IN) :: nx,ny,nz\n complex(mytype), dimension(:,:,:), intent(IN) :: local\n complex(mytype), dimension(nx,ny,nz), intent(OUT) :: global\n end subroutine assemble_global\nend interface\n\ncall MPI_INIT(ierror)\ncall decomp_2d_init(nx,ny,nz,p_row,p_col)\ncall decomp_2d_fft_init\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! (1) Testing the complex-to-complex interface (c2c) \n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n! input is X-pencil data\n! output is Z-pencil data\nallocate (in(xstart(1):xend(1),xstart(2):xend(2),xstart(3):xend(3)))\nallocate (out(zstart(1):zend(1),zstart(2):zend(2),zstart(3):zend(3)))\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! Following is the testing input for NAG library C06FXF\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \nin1(1,1,1) = (1.000, 0.000)\nin1(1,1,2) = (0.999, -0.040)\nin1(1,1,3) = (0.987, -0.159)\nin1(1,1,4) = (0.936, -0.352)\nin1(1,2,1) = (0.994, -0.111)\nin1(1,2,2) = (0.989, -0.151)\nin1(1,2,3) = (0.963, -0.268)\nin1(1,2,4) = (0.891, -0.454)\nin1(1,3,1) = (0.903, -0.430)\nin1(1,3,2) = (0.885, -0.466)\nin1(1,3,3) = (0.823, -0.568)\nin1(1,3,4) = (0.694, -0.720)\nin1(2,1,1) = (0.500, 0.500)\nin1(2,1,2) = (0.499, 0.040)\nin1(2,1,3) = (0.487, 0.159)\nin1(2,1,4) = (0.436, 0.352)\nin1(2,2,1) = (0.494, 0.111)\nin1(2,2,2) = (0.489, 0.151)\nin1(2,2,3) = (0.463, 0.268)\nin1(2,2,4) = (0.391, 0.454)\nin1(2,3,1) = (0.403, 0.430)\nin1(2,3,2) = (0.385, 0.466)\nin1(2,3,3) = (0.323, 0.568)\nin1(2,3,4) = (0.194, 0.720)\n\n! each processor gets its local portion of global data\ndo k=xstart(3),xend(3)\n do j=xstart(2),xend(2)\n do i=xstart(1),xend(1)\n in(i,j,k) = in1(i,j,k)\n end do\n end do\nend do\n\n! write out input, to match the format of NAG example result file\nif (nrank==0) then\n write(*,*) 'C06FXF Example Program Results'\n write(*,*) ''\n write(*,*) 'Original data values'\n write(*,*) ''\n call print_global(in1,nx,ny,nz)\nend if\n\n! ===== 3D forward FFT =====\ncall decomp_2d_fft_3d(in, out, DECOMP_2D_FFT_FORWARD)\n\n! normalisation - note FFTW doesn't normalise \ndo k=zstart(3),zend(3)\n do j=zstart(2),zend(2)\n do i=zstart(1),zend(1)\n out(i,j,k) = out(i,j,k) / sqrt(real(nx*ny*nz))\n end do\n end do\nend do\n\ncall assemble_global(3,out,out1,nx,ny,nz)\n\n! write out forward FFT result\nif (nrank==0) then\n write(*,*) 'Components of discrete Fourier transform'\n write(*,*) ''\n call print_global(out1,nx,ny,nz)\nend if\n\n! ===== 3D inverse FFT =====\ncall decomp_2d_fft_3d(out, in, DECOMP_2D_FFT_BACKWARD)\n\n! normalisation - note FFTW doesn't normalise\ndo k=xstart(3),xend(3)\n do j=xstart(2),xend(2)\n do i=xstart(1),xend(1)\n in(i,j,k) = in(i,j,k) / sqrt(real(nx*ny*nz))\n end do\n end do\nend do\n\ncall assemble_global(1,in,in1,nx,ny,nz)\n\n! write out inverse FFT result\nif (nrank==0) then\n write(*,*) 'Original sequence as restored by inverse transform'\n write(*,*) ''\n call print_global(in1,nx,ny,nz)\nend if\n\ncall decomp_2d_fft_finalize\ncall decomp_2d_finalize\ncall MPI_FINALIZE(ierror)\n\nend program fft_test_c2c\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! Collect data from each processor and assemble into a global array\n! at the master rank\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine assemble_global(ndir,local,global,nx,ny,nz)\n \n use decomp_2d\n use MPI\n \n implicit none\n \n integer, intent(IN) :: ndir ! 1 = X-pencil; 3 = Z-pencil\n integer, intent(IN) :: nx,ny,nz\n complex(mytype), dimension(:,:,:), intent(IN) :: local\n complex(mytype), dimension(nx,ny,nz), intent(OUT) :: global\n \n complex(mytype), allocatable, dimension(:,:,:) :: rbuf\n integer, dimension(9) :: sbuf1, rbuf1\n \n integer :: ierror, i,j,k,m, i1,i2,j1,j2,k1,k2, count\n integer, dimension(MPI_STATUS_SIZE) :: status\n \n if (nrank==0) then\n ! master writes its own data to a global array\n if (ndir==3) then ! Z-pencil \n i1 = zstart(1)\n i2 = zend(1)\n j1 = zstart(2)\n j2 = zend(2)\n k1 = zstart(3)\n k2 = zend(3)\n else if (ndir==1) then ! X-pencil\n i1 = xstart(1)\n i2 = xend(1)\n j1 = xstart(2)\n j2 = xend(2)\n k1 = xstart(3)\n k2 = xend(3)\n end if\n do k=k1,k2\n do j=j1,j2\n do i=i1,i2\n ! 'local' is assumbed shape array\n ! but it is OK as starting index for rank 0 always 1\n global(i,j,k)=local(i,j,k)\n end do\n end do\n end do\n ! then loop through all other ranks to collect data\n do m=1,nproc-1\n CALL MPI_RECV(rbuf1,9,MPI_INTEGER,m,m,MPI_COMM_WORLD, &\n status,ierror)\n allocate(rbuf(rbuf1(1):rbuf1(2),rbuf1(4):rbuf1(5), &\n rbuf1(7):rbuf1(8)))\n CALL MPI_RECV(rbuf,rbuf1(3)*rbuf1(6)*rbuf1(9),complex_type,m, &\n m+nproc,MPI_COMM_WORLD,status,ierror)\n do k=rbuf1(7),rbuf1(8)\n do j=rbuf1(4),rbuf1(5)\n do i=rbuf1(1),rbuf1(2)\n global(i,j,k)=rbuf(i,j,k)\n end do\n end do\n end do\n deallocate(rbuf)\n end do\n else\n ! slaves send data to mater\n if (ndir==3) then ! Z-pencil\n sbuf1(1) = zstart(1)\n sbuf1(2) = zend(1)\n sbuf1(3) = zsize(1)\n sbuf1(4) = zstart(2)\n sbuf1(5) = zend(2)\n sbuf1(6) = zsize(2)\n sbuf1(7) = zstart(3)\n sbuf1(8) = zend(3)\n sbuf1(9) = zsize(3)\n count = zsize(1)*zsize(2)*zsize(3)\n else if (ndir==1) then ! X-pencil\n sbuf1(1) = xstart(1)\n sbuf1(2) = xend(1)\n sbuf1(3) = xsize(1)\n sbuf1(4) = xstart(2)\n sbuf1(5) = xend(2)\n sbuf1(6) = xsize(2)\n sbuf1(7) = xstart(3)\n sbuf1(8) = xend(3)\n sbuf1(9) = xsize(3)\n count = xsize(1)*xsize(2)*xsize(3)\n end if\n ! send partition information\n CALL MPI_SEND(sbuf1,9,MPI_INTEGER,0,nrank,MPI_COMM_WORLD,ierror)\n ! send data array\n CALL MPI_SEND(local,count,complex_type,0, &\n nrank+nproc,MPI_COMM_WORLD,ierror)\n end if\n \n return\nend subroutine assemble_global\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! Print out a global data array using special format that matches\n! NAG library C06FXF Example Program Results for validation purpose\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine print_global(data,nx,ny,nz)\n\nuse decomp_2d\n\nimplicit none\n\ninteger, intent(IN) :: nx,ny,nz\ncomplex(mytype), dimension(nx,ny,nz), intent(IN) :: data\n\ninteger :: i,j,k\n\ndo i=1,nx\n write(*,10) i\n write(*,*) ''\n do j=1,ny\n write(*,20) (real(data(i,j,k)),k=1,nz)\n write(*,21) (aimag(data(i,j,k)),k=1,nz)\n write(*,*) ''\n end do\nend do\n10 format(1x,'z(i,j,k) for i =', I6)\n20 format(1x,'Real ', 4F10.3)\n21 format(1x,'Imag ', 4F10.3)\n\nreturn\nend subroutine print_global\n\n", "meta": {"hexsha": "080377f12e15016d3cba5bdfaf0531c6caeecec0", "size": 7648, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/fft_test_c2c/fft_test_c2c.f90", "max_stars_repo_name": "BenMql/2decomp_emptyFourierFourier", "max_stars_repo_head_hexsha": "a7655268d78937f7b65043871af3d23736c55845", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2018-02-13T11:00:08.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-06T01:13:04.000Z", "max_issues_repo_path": "libs/2decomp_fft/examples/fft_test_c2c/fft_test_c2c.f90", "max_issues_repo_name": "GeZhouyang/ICLS-release", "max_issues_repo_head_hexsha": "940c7937cff412566b3ce9f058d961de06b4ad7f", "max_issues_repo_licenses": ["AFL-3.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-02-03T10:45:50.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-04T11:49:27.000Z", "max_forks_repo_path": "examples/fft_test_c2c/fft_test_c2c.f90", "max_forks_repo_name": "BenMql/2decomp_emptyFourierFourier", "max_forks_repo_head_hexsha": "a7655268d78937f7b65043871af3d23736c55845", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-02-17T12:47:17.000Z", "max_forks_repo_forks_event_max_datetime": "2020-01-30T11:01:14.000Z", "avg_line_length": 28.221402214, "max_line_length": 73, "alphanum_fraction": 0.5409257322, "num_tokens": 2731, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527906914787, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.6800174589232594}} {"text": "c program DRSMPVAL\nc Demonstrates SMPDRV, SMPINT, and SMPVAL.\nc>> 1997-05-29 DRSMPVAL Krogh Special code for C conversion.\nc>> 1996-05-28 DRSMPVAL Krogh Added external statement.\nc>> 1994-10-19 DRSMPVAL Krogh Changes to use M77CON\nc>> 1993-02-04 DRSMPVAL CLL\nc>> 1987-12-09 DRSMPVAL Lawson Initial Code.\nc ------------------------------------------------------------------\nc--S replaces \"?\": DR?MPVAL, ?MPDRV, ?MPINT, ?MPVAL\nc ------------------------------------------------------------------\nc++ Code for .C. is inactive\nc%% long int n;\nc++ End\n integer NQ, NR\n external SMPVAL\n real P(6),Q(7),R(6),Z,SMPVAL\n data P/ 5.E0, 2.E0, 4.E0, -4.E0, 12.E0, 16.E0 /\nc ------------------------------------------------------------------\n call SMPINT(P, 3,Q,NQ)\n call SMPDRV(Q,NQ,R,NR)\n Z = SMPVAL(Q,NQ,6.E0) - SMPVAL(Q,NQ,4.E0)\nc++ Code for ~.C. is active\n print '(21x,''P ='',2f4.0,2x,4f7.2/)', P\n print '('' INTEGRAL OF P. Q ='',2f4.0,2x,5f7.2/)', Q\n print '('' DERIVATIVE OF Q. R ='',2f4.0,2x,4f7.2/)', R\n print '('' DEFINITE INTEGRAL. Z ='',f20.8)', Z\nc++ Code for .C. is inactive\nc%% printf( \" P =%4.0f%4.0f\", p[0], p[1] );\nc%% for(n=2L; n < (long)(sizeof(p)/sizeof(p[1])); n++)\nc%% printf( \"%7.2f\", p[n] );\nc%% printf( \"\\n\" );\nc%% printf( \" INTEGRAL OF P. Q =%4.0f%4.0f\", q[0], q[1] );\nc%% for(n=2L; n < (long)(sizeof(q)/sizeof(q[1])); n++)\nc%% printf( \"%7.2f\", q[n] );\nc%% printf( \"\\n\" );\nc%% printf( \" DERIVATIVE OF Q. R =%4.0f%4.0f\", r[0], r[1] );\nc%% for(n=2L; n < (long)(sizeof(r)/sizeof(r[1])); n++)\nc%% printf( \"%7.2f\", r[n] );\nc%% printf( \"\\n\" );\nc%% printf( \" DEFINITE INTEGRAL. Z =%20.8f\\n\", z );\nc++ End\n stop\n end\n", "meta": {"hexsha": "8853d4fa20feecd073fcf0091c0cfa0dd0ef54c6", "size": 1820, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drsmpval.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drsmpval.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drsmpval.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 41.3636363636, "max_line_length": 72, "alphanum_fraction": 0.4554945055, "num_tokens": 698, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527869325346, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.6800174436530195}} {"text": " program example1\n! page 27 \n use funcs ! for modern Fortran only, ex1.f90\n \n real :: a(5) = [27, 36, 29, 10, 1] ! modern way, I dislike obsolete \"DATA\"\n \n print *, avrgII(a,5)\n \n print *, avrg77(a,5)\n \n print *, avrg(a)\n \n end program\n \n \n function avrgII(alist, n)\n! Fortran II way \n dimension alist(5)\n \n sum = alist(1)\n \n do 10 i = 2, n\n10 sum = sum + alist(i)\n\n avrgII = sum / real(n)\n \n end\n \n \n function avrg77(alist, n)\n! Fortran 77 way\n dimension alist(n)\n \n sum = alist(1)\n \n do i = 2, n\n sum = sum + alist(i)\n end do\n \n avrg77 = sum / real(n)\n \n end\n \n", "meta": {"hexsha": "14de8dedf2577b822aa96dc2f4c3637177e6877f", "size": 772, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "example1.f", "max_stars_repo_name": "ElliotAlexander/fortran-II-examples", "max_stars_repo_head_hexsha": "52ded76fb769dff056a2db59c0375d21ed13c6ce", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2018-07-24T21:48:21.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T23:58:19.000Z", "max_issues_repo_path": "example1.f", "max_issues_repo_name": "ElliotAlexander/fortran-II-examples", "max_issues_repo_head_hexsha": "52ded76fb769dff056a2db59c0375d21ed13c6ce", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "example1.f", "max_forks_repo_name": "ElliotAlexander/fortran-II-examples", "max_forks_repo_head_hexsha": "52ded76fb769dff056a2db59c0375d21ed13c6ce", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-02-18T12:28:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T12:28:24.000Z", "avg_line_length": 17.5454545455, "max_line_length": 82, "alphanum_fraction": 0.432642487, "num_tokens": 230, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267796346598, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.6799981167251018}} {"text": "C\nC file hwsplr.f\nC\n SUBROUTINE HWSPLR (A,B,M,MBDCND,BDA,BDB,C,D,N,NBDCND,BDC,BDD,\n 1 ELMBDA,F,IDIMF,PERTRB,IERROR,W)\nC\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC * *\nC * copyright (c) 1999 by UCAR *\nC * *\nC * UNIVERSITY CORPORATION for ATMOSPHERIC RESEARCH *\nC * *\nC * all rights reserved *\nC * *\nC * FISHPACK version 4.1 *\nC * *\nC * A PACKAGE OF FORTRAN SUBPROGRAMS FOR THE SOLUTION OF *\nC * *\nC * SEPARABLE ELLIPTIC PARTIAL DIFFERENTIAL EQUATIONS *\nC * *\nC * BY *\nC * *\nC * JOHN ADAMS, PAUL SWARZTRAUBER AND ROLAND SWEET *\nC * *\nC * OF *\nC * *\nC * THE NATIONAL CENTER FOR ATMOSPHERIC RESEARCH *\nC * *\nC * BOULDER, COLORADO (80307) U.S.A. *\nC * *\nC * WHICH IS SPONSORED BY *\nC * *\nC * THE NATIONAL SCIENCE FOUNDATION *\nC * *\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC\nC\nC\nC DIMENSION OF BDA(N),BDB(N),BDC(M),BDD(M),F(IDIMF,N+1),\nC ARGUMENTS W(SEE ARGUMENT LIST)\nC\nC LATEST REVISION NOVEMBER 1988\nC\nC PURPOSE SOLVES A FINITE DIFFERENCE APPROXIMATION TO\nC THE HELMHOLTZ EQUATION IN POLAR COORDINATES.\nC THE EQUATION IS\nC\nC (1/R)(D/DR)(R(DU/DR)) +\nC (1/R**2)(D/DTHETA)(DU/DTHETA) +\nC LAMBDA*U = F(R,THETA).\nC\nC USAGE CALL HWSPLR (A,B,M,MBDCND,BDA,BDB,C,D,N,\nC NBDCND,BDC,BDD,ELMBDA,F,IDIMF,\nC PERTRB,IERROR,W)\nC\nC ARGUMENTS\nC ON INPUT A,B\nC THE RANGE OF R, I.E., A .LE. R .LE. B.\nC A MUST BE LESS THAN B AND A MUST BE\nC NON-NEGATIVE.\nC\nC M\nC THE NUMBER OF PANELS INTO WHICH THE\nC INTERVAL (A,B) IS SUBDIVIDED. HENCE,\nC THERE WILL BE M+1 GRID POINTS IN THE\nC R-DIRECTION GIVEN BY R(I) = A+(I-1)DR,\nC FOR I = 1,2,...,M+1,\nC WHERE DR = (B-A)/M IS THE PANEL WIDTH.\nC M MUST BE GREATER THAN 3.\nC\nC MBDCND\nC INDICATES THE TYPE OF BOUNDARY CONDITION\nC AT R = A AND R = B.\nC\nC = 1 IF THE SOLUTION IS SPECIFIED AT\nC R = A AND R = B.\nC = 2 IF THE SOLUTION IS SPECIFIED AT\nC R = A AND THE DERIVATIVE OF\nC THE SOLUTION WITH RESPECT TO R IS\nC SPECIFIED AT R = B.\nC = 3 IF THE DERIVATIVE OF THE SOLUTION\nC WITH RESPECT TO R IS SPECIFIED AT\nC R = A (SEE NOTE BELOW) AND R = B.\nC = 4 IF THE DERIVATIVE OF THE SOLUTION\nC WITH RESPECT TO R IS SPECIFIED AT\nC R = A (SEE NOTE BELOW) AND THE\nC SOLUTION IS SPECIFIED AT R = B.\nC = 5 IF THE SOLUTION IS UNSPECIFIED AT\nC R = A = 0 AND THE SOLUTION IS\nC SPECIFIED AT R = B.\nC = 6 IF THE SOLUTION IS UNSPECIFIED AT\nC R = A = 0 AND THE DERIVATIVE OF THE\nC SOLUTION WITH RESPECT TO R IS SPECIFIED\nC AT R = B.\nC\nC NOTE:\nC IF A = 0, DO NOT USE MBDCND = 3 OR 4, BUT\nC INSTEAD USE MBDCND = 1,2,5, OR 6 .\nC\nC BDA\nC A ONE-DIMENSIONAL ARRAY OF LENGTH N+1 THAT\nC SPECIFIES THE VALUES OF THE DERIVATIVE OF\nC THE SOLUTION WITH RESPECT TO R AT R = A.\nC\nC WHEN MBDCND = 3 OR 4,\nC BDA(J) = (D/DR)U(A,THETA(J)),\nC J = 1,2,...,N+1 .\nC\nC WHEN MBDCND HAS ANY OTHER VALUE, BDA IS\nC A DUMMY VARIABLE.\nC\nC BDB\nC A ONE-DIMENSIONAL ARRAY OF LENGTH N+1 THAT\nC SPECIFIES THE VALUES OF THE DERIVATIVE OF\nC THE SOLUTION WITH RESPECT TO R AT R = B.\nC\nC WHEN MBDCND = 2,3, OR 6,\nC BDB(J) = (D/DR)U(B,THETA(J)),\nC J = 1,2,...,N+1 .\nC\nC WHEN MBDCND HAS ANY OTHER VALUE, BDB IS\nC A DUMMY VARIABLE.\nC\nC C,D\nC THE RANGE OF THETA, I.E., C .LE.\nC THETA .LE. D. C MUST BE LESS THAN D.\nC\nC N\nC THE NUMBER OF PANELS INTO WHICH THE\nC INTERVAL (C,D) IS SUBDIVIDED. HENCE,\nC THERE WILL BE N+1 GRID POINTS IN THE\nC THETA-DIRECTION GIVEN BY\nC THETA(J) = C+(J-1)DTHETA FOR\nC J = 1,2,...,N+1, WHERE\nC DTHETA = (D-C)/N IS THE PANEL WIDTH.\nC N MUST BE GREATER THAN 3.\nC\nC NBDCND\nC INDICATES THE TYPE OF BOUNDARY CONDITIONS\nC AT THETA = C AND AT THETA = D.\nC\nC = 0 IF THE SOLUTION IS PERIODIC IN THETA,\nC I.E., U(I,J) = U(I,N+J).\nC = 1 IF THE SOLUTION IS SPECIFIED AT\nC THETA = C AND THETA = D\nC (SEE NOTE BELOW).\nC = 2 IF THE SOLUTION IS SPECIFIED AT\nC THETA = C AND THE DERIVATIVE OF THE\nC SOLUTION WITH RESPECT TO THETA IS\nC SPECIFIED AT THETA = D\nC (SEE NOTE BELOW).\nC = 4 IF THE DERIVATIVE OF THE SOLUTION\nC WITH RESPECT TO THETA IS SPECIFIED\nC AT THETA = C AND THE SOLUTION IS\nC SPECIFIED AT THETA = D\nC (SEE NOTE BELOW).\nC\nC NOTE:\nC WHEN NBDCND = 1,2, OR 4, DO NOT USE\nC MBDCND = 5 OR 6\nC (THE FORMER INDICATES THAT THE SOLUTION\nC IS SPECIFIED AT R = 0, THE LATTER INDICATES\nC THE SOLUTION IS UNSPECIFIED AT R = 0).\nC USE INSTEAD MBDCND = 1 OR 2 .\nC\nC BDC\nC A ONE-DIMENSIONAL ARRAY OF LENGTH M+1 THAT\nC SPECIFIES THE VALUES OF THE DERIVATIVE\nC OF THE SOLUTION WITH RESPECT TO THETA AT\nC THETA = C. WHEN NBDCND = 3 OR 4,\nC\nC BDC(I) = (D/DTHETA)U(R(I),C),\nC I = 1,2,...,M+1 .\nC\nC WHEN NBDCND HAS ANY OTHER VALUE, BDC IS\nC A DUMMY VARIABLE.\nC\nC BDD\nC A ONE-DIMENSIONAL ARRAY OF LENGTH M+1 THAT\nC SPECIFIES THE VALUES OF THE DERIVATIVE\nC OF THE SOLUTION WITH RESPECT TO THETA AT\nC THETA = D. WHEN NBDCND = 2 OR 3,\nC\nC BDD(I) = (D/DTHETA)U(R(I),D),\nC I = 1,2,...,M+1 .\nC\nC WHEN NBDCND HAS ANY OTHER VALUE, BDD IS\nC A DUMMY VARIABLE.\nC\nC ELMBDA\nC THE CONSTANT LAMBDA IN THE HELMHOLTZ\nC EQUATION. IF LAMBDA .LT. 0, A SOLUTION\nC MAY NOT EXIST. HOWEVER, HWSPLR WILL\nC ATTEMPT TO FIND A SOLUTION.\nC\nC F\nC A TWO-DIMENSIONAL ARRAY, OF DIMENSION AT\nC LEAST (M+1)*(N+1), SPECIFYING VALUES\nC OF THE RIGHT SIDE OF THE HELMHOLTZ\nC EQUATION AND BOUNDARY DATA (IF ANY).\nC\nC ON THE INTERIOR, F IS DEFINED AS FOLLOWS:\nC FOR I = 2,3,...,M AND J = 2,3,...,N\nC F(I,J) = F(R(I),THETA(J)).\nC\nC ON THE BOUNDARIES F IS DEFINED AS FOLLOWS:\nC FOR J = 1,2,...,N+1 AND I = 1,2,...,M+1\nC\nC MBDCND F(1,J) F(M+1,J)\nC ------ ------------- -------------\nC\nC 1 U(A,THETA(J)) U(B,THETA(J))\nC 2 U(A,THETA(J)) F(B,THETA(J))\nC 3 F(A,THETA(J)) F(B,THETA(J))\nC 4 F(A,THETA(J)) U(B,THETA(J))\nC 5 F(0,0) U(B,THETA(J))\nC 6 F(0,0) F(B,THETA(J))\nC\nC NBDCND F(I,1) F(I,N+1)\nC ------ --------- ---------\nC\nC 0 F(R(I),C) F(R(I),C)\nC 1 U(R(I),C) U(R(I),D)\nC 2 U(R(I),C) F(R(I),D)\nC 3 F(R(I),C) F(R(I),D)\nC 4 F(R(I),C) U(R(I),D)\nC\nC NOTE:\nC IF THE TABLE CALLS FOR BOTH THE SOLUTION\nC U AND THE RIGHT SIDE F AT A CORNER THEN\nC THEN THE SOLUTION MUST BE SPECIFIED.\nC\nC IDIMF\nC THE ROW (OR FIRST) DIMENSION OF THE ARRAY\nC F AS IT APPEARS IN THE PROGRAM CALLING\nC HWSPLR. THIS PARAMETER IS USED TO SPECIFY\nC THE VARIABLE DIMENSION OF F. IDIMF MUST\nC BE AT LEAST M+1.\nC\nC W\nC A ONE-DIMENSIONAL ARRAY THAT MUST BE\nC PROVIDED BY THE USER FOR WORK SPACE.\nC W MAY REQUIRE UP TO 4*(N+1) +\nC (13 + INT(LOG2(N+1)))*(M+1) LOCATIONS.\nC THE ACTUAL NUMBER OF LOCATIONS USED IS\nC COMPUTED BY HWSPLR AND IS RETURNED IN\nC LOCATION W(I).\nC\nC\nC ON OUTPUT F\nC CONTAINS THE SOLUTION U(I,J) OF THE FINITE\nC DIFFERENCE APPROXIMATION FOR THE GRID POINT\nC (R(I),THETA(J)),\nC I = 1,2,...,M+1, J = 1,2,...,N+1 .\nC\nC PERTRB\nC IF A COMBINATION OF PERIODIC, DERIVATIVE,\nC OR UNSPECIFIED BOUNDARY CONDITIONS IS\nC SPECIFIED FOR A POISSON EQUATION\nC (LAMBDA = 0), A SOLUTION MAY NOT EXIST.\nC PERTRB IS A CONSTANT, CALCULATED AND\nC SUBTRACTED FROM F, WHICH ENSURES THAT A\nC SOLUTION EXISTS. HWSPLR THEN COMPUTES\nC THIS SOLUTION, WHICH IS A LEAST SQUARES\nC SOLUTION TO THE ORIGINAL APPROXIMATION.\nC THIS SOLUTION PLUS ANY CONSTANT IS ALSO\nC A SOLUTION. HENCE, THE SOLUTION IS NOT\nC UNIQUE. PERTRB SHOULD BE SMALL COMPARED\nC TO THE RIGHT SIDE. OTHERWISE, A SOLUTION\nC IS OBTAINED TO AN ESSENTIALLY DIFFERENT\nC PROBLEM. THIS COMPARISON SHOULD ALWAYS\nC BE MADE TO INSURE THAT A MEANINGFUL\nC SOLUTION HAS BEEN OBTAINED.\nC\nC IERROR\nC AN ERROR FLAG THAT INDICATES INVALID INPUT\nC PARAMETERS. EXCEPT FOR NUMBERS 0 AND 11,\nC A SOLUTION IS NOT ATTEMPTED.\nC\nC = 0 NO ERROR.\nC = 1 A .LT. 0 .\nC = 2 A .GE. B.\nC = 3 MBDCND .LT. 1 OR MBDCND .GT. 6 .\nC = 4 C .GE. D.\nC = 5 N .LE. 3\nC = 6 NBDCND .LT. 0 OR .GT. 4 .\nC = 7 A = 0, MBDCND = 3 OR 4 .\nC = 8 A .GT. 0, MBDCND .GE. 5 .\nC = 9 MBDCND .GE. 5, NBDCND .NE. 0\nC AND NBDCND .NE. 3 .\nC = 10 IDIMF .LT. M+1 .\nC = 11 LAMBDA .GT. 0 .\nC = 12 M .LE. 3\nC\nC SINCE THIS IS THE ONLY MEANS OF INDICATING\nC A POSSIBLY INCORRECT CALL TO HWSPLR, THE\nC USER SHOULD TEST IERROR AFTER THE CALL.\nC\nC W\nC W(1) CONTAINS THE REQUIRED LENGTH OF W.\nC\nC SPECIAL CONDITIONS NONE\nC\nC I/O NONE\nC\nC PRECISION SINGLE\nC\nC REQUIRED LIBRARY GENBUN, GNBNAUX, AND COMF\nC FILES FROM FISHPACK\nC\nC LANGUAGE FORTRAN\nC\nC HISTORY WRITTEN BY ROLAND SWEET AT NCAR IN THE LATE\nC 1970'S. RELEASED ON NCAR'S PUBLIC SOFTWARE\nC LIBRARIES IN JANUARY 1980.\nC\nC PORTABILITY FORTRAN 77\nC\nC ALGORITHM THE ROUTINE DEFINES THE FINITE DIFFERENCE\nC EQUATIONS, INCORPORATES BOUNDARY DATA, AND\nC ADJUSTS THE RIGHT SIDE OF SINGULAR SYSTEMS\nC AND THEN CALLS GENBUN TO SOLVE THE SYSTEM.\nC\nC TIMING FOR LARGE M AND N, THE OPERATION COUNT\nC IS ROUGHLY PROPORTIONAL TO\nC M*N*(LOG2(N)\nC BUT ALSO DEPENDS ON INPUT PARAMETERS NBDCND\nC AND MBDCND.\nC\nC ACCURACY THE SOLUTION PROCESS EMPLOYED RESULTS IN A LOSS\nC OF NO MORE THAN THREE SIGNIFICANT DIGITS FOR N\nC AND M AS LARGE AS 64. MORE DETAILS ABOUT\nC ACCURACY CAN BE FOUND IN THE DOCUMENTATION FOR\nC SUBROUTINE GENBUN WHICH IS THE ROUTINE THAT\nC SOLVES THE FINITE DIFFERENCE EQUATIONS.\nC\nC REFERENCES SWARZTRAUBER,P. AND R. SWEET, \"EFFICIENT\nC FORTRAN SUBPROGRAMS FOR THE SOLUTION OF\nC ELLIPTIC EQUATIONS\"\nC NCAR TN/IA-109, JULY, 1975, 138 PP.\nC***********************************************************************\n DIMENSION F(IDIMF,*)\n DIMENSION BDA(*) ,BDB(*) ,BDC(*) ,BDD(*) ,\n 1 W(*)\nC\nC CHECK FOR INVALID PARAMETERS.\nC\n IERROR = 0\n IF (A .LT. 0.) IERROR = 1\n IF (A .GE. B) IERROR = 2\n IF (MBDCND.LE.0 .OR. MBDCND.GE.7) IERROR = 3\n IF (C .GE. D) IERROR = 4\n IF (N .LE. 3) IERROR = 5\n IF (NBDCND.LE.-1 .OR. NBDCND.GE.5) IERROR = 6\n IF (A.EQ.0. .AND. (MBDCND.EQ.3 .OR. MBDCND.EQ.4)) IERROR = 7\n IF (A.GT.0. .AND. MBDCND.GE.5) IERROR = 8\n IF (MBDCND.GE.5 .AND. NBDCND.NE.0 .AND. NBDCND.NE.3) IERROR = 9\n IF (IDIMF .LT. M+1) IERROR = 10\n IF (M .LE. 3) IERROR = 12\n IF (IERROR .NE. 0) RETURN\n MP1 = M+1\n DELTAR = (B-A)/FLOAT(M)\n DLRBY2 = DELTAR/2.\n DLRSQ = DELTAR**2\n NP1 = N+1\n DELTHT = (D-C)/FLOAT(N)\n DLTHSQ = DELTHT**2\n NP = NBDCND+1\nC\nC DEFINE RANGE OF INDICES I AND J FOR UNKNOWNS U(I,J).\nC\n MSTART = 2\n MSTOP = MP1\n GO TO (101,105,102,103,104,105),MBDCND\n 101 MSTOP = M\n GO TO 105\n 102 MSTART = 1\n GO TO 105\n 103 MSTART = 1\n 104 MSTOP = M\n 105 MUNK = MSTOP-MSTART+1\n NSTART = 1\n NSTOP = N\n GO TO (109,106,107,108,109),NP\n 106 NSTART = 2\n GO TO 109\n 107 NSTART = 2\n 108 NSTOP = NP1\n 109 NUNK = NSTOP-NSTART+1\nC\nC DEFINE A,B,C COEFFICIENTS IN W-ARRAY.\nC\n ID2 = MUNK\n ID3 = ID2+MUNK\n ID4 = ID3+MUNK\n ID5 = ID4+MUNK\n ID6 = ID5+MUNK\n A1 = 2./DLRSQ\n IJ = 0\n IF (MBDCND.EQ.3 .OR. MBDCND.EQ.4) IJ = 1\n DO 110 I=1,MUNK\n R = A+FLOAT(I-IJ)*DELTAR\n J = ID5+I\n W(J) = R\n J = ID6+I\n W(J) = 1./R**2\n W(I) = (R-DLRBY2)/(R*DLRSQ)\n J = ID3+I\n W(J) = (R+DLRBY2)/(R*DLRSQ)\n J = ID2+I\n W(J) = -A1+ELMBDA\n 110 CONTINUE\n GO TO (114,111,112,113,114,111),MBDCND\n 111 W(ID2) = A1\n GO TO 114\n 112 W(ID2) = A1\n 113 W(ID3+1) = A1\n 114 CONTINUE\nC\nC ENTER BOUNDARY DATA FOR R-BOUNDARIES.\nC\n GO TO (115,115,117,117,119,119),MBDCND\n 115 A1 = W(1)\n DO 116 J=NSTART,NSTOP\n F(2,J) = F(2,J)-A1*F(1,J)\n 116 CONTINUE\n GO TO 119\n 117 A1 = 2.*DELTAR*W(1)\n DO 118 J=NSTART,NSTOP\n F(1,J) = F(1,J)+A1*BDA(J)\n 118 CONTINUE\n 119 GO TO (120,122,122,120,120,122),MBDCND\n 120 A1 = W(ID4)\n DO 121 J=NSTART,NSTOP\n F(M,J) = F(M,J)-A1*F(MP1,J)\n 121 CONTINUE\n GO TO 124\n 122 A1 = 2.*DELTAR*W(ID4)\n DO 123 J=NSTART,NSTOP\n F(MP1,J) = F(MP1,J)-A1*BDB(J)\n 123 CONTINUE\nC\nC ENTER BOUNDARY DATA FOR THETA-BOUNDARIES.\nC\n 124 A1 = 1./DLTHSQ\n L = ID5-MSTART+1\n LP = ID6-MSTART+1\n GO TO (134,125,125,127,127),NP\n 125 DO 126 I=MSTART,MSTOP\n J = I+LP\n F(I,2) = F(I,2)-A1*W(J)*F(I,1)\n 126 CONTINUE\n GO TO 129\n 127 A1 = 2./DELTHT\n DO 128 I=MSTART,MSTOP\n J = I+LP\n F(I,1) = F(I,1)+A1*W(J)*BDC(I)\n 128 CONTINUE\n 129 A1 = 1./DLTHSQ\n GO TO (134,130,132,132,130),NP\n 130 DO 131 I=MSTART,MSTOP\n J = I+LP\n F(I,N) = F(I,N)-A1*W(J)*F(I,NP1)\n 131 CONTINUE\n GO TO 134\n 132 A1 = 2./DELTHT\n DO 133 I=MSTART,MSTOP\n J = I+LP\n F(I,NP1) = F(I,NP1)-A1*W(J)*BDD(I)\n 133 CONTINUE\n 134 CONTINUE\nC\nC ADJUST RIGHT SIDE OF EQUATION FOR UNKNOWN AT POLE WHEN HAVE\nC DERIVATIVE SPECIFIED BOUNDARY CONDITIONS.\nC\n IF (MBDCND.GE.5 .AND. NBDCND.EQ.3)\n 1 F(1,1) = F(1,1)-(BDD(2)-BDC(2))*4./(FLOAT(N)*DELTHT*DLRSQ)\nC\nC ADJUST RIGHT SIDE OF SINGULAR PROBLEMS TO INSURE EXISTENCE OF A\nC SOLUTION.\nC\n PERTRB = 0.\n IF (ELMBDA) 144,136,135\n 135 IERROR = 11\n GO TO 144\n 136 IF (NBDCND.NE.0 .AND. NBDCND.NE.3) GO TO 144\n S2 = 0.\n GO TO (144,144,137,144,144,138),MBDCND\n 137 W(ID5+1) = .5*(W(ID5+2)-DLRBY2)\n S2 = .25*DELTAR\n 138 A2 = 2.\n IF (NBDCND .EQ. 0) A2 = 1.\n J = ID5+MUNK\n W(J) = .5*(W(J-1)+DLRBY2)\n S = 0.\n DO 140 I=MSTART,MSTOP\n S1 = 0.\n IJ = NSTART+1\n K = NSTOP-1\n DO 139 J=IJ,K\n S1 = S1+F(I,J)\n 139 CONTINUE\n J = I+L\n S = S+(A2*S1+F(I,NSTART)+F(I,NSTOP))*W(J)\n 140 CONTINUE\n S2 = FLOAT(M)*A+DELTAR*(FLOAT((M-1)*(M+1))*.5+.25)+S2\n S1 = (2.+A2*FLOAT(NUNK-2))*S2\n IF (MBDCND .EQ. 3) GO TO 141\n S2 = FLOAT(N)*A2*DELTAR/8.\n S = S+F(1,1)*S2\n S1 = S1+S2\n 141 CONTINUE\n PERTRB = S/S1\n DO 143 I=MSTART,MSTOP\n DO 142 J=NSTART,NSTOP\n F(I,J) = F(I,J)-PERTRB\n 142 CONTINUE\n 143 CONTINUE\n 144 CONTINUE\nC\nC MULTIPLY I-TH EQUATION THROUGH BY (R(I)*DELTHT)**2.\nC\n DO 146 I=MSTART,MSTOP\n K = I-MSTART+1\n J = I+LP\n A1 = DLTHSQ/W(J)\n W(K) = A1*W(K)\n J = ID2+K\n W(J) = A1*W(J)\n J = ID3+K\n W(J) = A1*W(J)\n DO 145 J=NSTART,NSTOP\n F(I,J) = A1*F(I,J)\n 145 CONTINUE\n 146 CONTINUE\n W(1) = 0.\n W(ID4) = 0.\nC\nC CALL GENBUN TO SOLVE THE SYSTEM OF EQUATIONS.\nC\n CALL GENBUN (NBDCND,NUNK,1,MUNK,W(1),W(ID2+1),W(ID3+1),IDIMF,\n 1 F(MSTART,NSTART),IERR1,W(ID4+1))\n IWSTOR = W(ID4+1)+3.*FLOAT(MUNK)\n GO TO (157,157,157,157,148,147),MBDCND\nC\nC ADJUST THE SOLUTION AS NECESSARY FOR THE PROBLEMS WHERE A = 0.\nC\n 147 IF (ELMBDA .NE. 0.) GO TO 148\n YPOLE = 0.\n GO TO 155\n 148 CONTINUE\n J = ID5+MUNK\n W(J) = W(ID2)/W(ID3)\n DO 149 IP=3,MUNK\n I = MUNK-IP+2\n J = ID5+I\n LP = ID2+I\n K = ID3+I\n W(J) = W(I)/(W(LP)-W(K)*W(J+1))\n 149 CONTINUE\n W(ID5+1) = -.5*DLTHSQ/(W(ID2+1)-W(ID3+1)*W(ID5+2))\n DO 150 I=2,MUNK\n J = ID5+I\n W(J) = -W(J)*W(J-1)\n 150 CONTINUE\n S = 0.\n DO 151 J=NSTART,NSTOP\n S = S+F(2,J)\n 151 CONTINUE\n A2 = NUNK\n IF (NBDCND .EQ. 0) GO TO 152\n S = S-.5*(F(2,NSTART)+F(2,NSTOP))\n A2 = A2-1.\n 152 YPOLE = (.25*DLRSQ*F(1,1)-S/A2)/(W(ID5+1)-1.+ELMBDA*DLRSQ*.25)\n DO 154 I=MSTART,MSTOP\n K = L+I\n DO 153 J=NSTART,NSTOP\n F(I,J) = F(I,J)+YPOLE*W(K)\n 153 CONTINUE\n 154 CONTINUE\n 155 DO 156 J=1,NP1\n F(1,J) = YPOLE\n 156 CONTINUE\n 157 CONTINUE\n IF (NBDCND .NE. 0) GO TO 159\n DO 158 I=MSTART,MSTOP\n F(I,NP1) = F(I,1)\n 158 CONTINUE\n 159 CONTINUE\n W(1) = IWSTOR\n RETURN\nC\nC REVISION HISTORY---\nC\nC SEPTEMBER 1973 VERSION 1\nC APRIL 1976 VERSION 2\nC JANUARY 1978 VERSION 3\nC DECEMBER 1979 VERSION 3.1\nC FEBRUARY 1985 DOCUMENTATION UPGRADE\nC NOVEMBER 1988 VERSION 3.2, FORTRAN 77 CHANGES\nC-----------------------------------------------------------------------\n END\n", "meta": {"hexsha": "031b63076d441f7b3a16503ea5518d0c0e3561ff", "size": 23370, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/src/hwsplr.f", "max_stars_repo_name": "ipelupessy/omuse", "max_stars_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2020-03-25T10:02:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-18T00:28:35.000Z", "max_issues_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/src/hwsplr.f", "max_issues_repo_name": "ipelupessy/omuse", "max_issues_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 45, "max_issues_repo_issues_event_min_datetime": "2020-03-03T16:07:16.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-14T09:01:07.000Z", "max_forks_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/src/hwsplr.f", "max_forks_repo_name": "ipelupessy/omuse", "max_forks_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-03-03T13:28:50.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-26T09:20:02.000Z", "avg_line_length": 38.7562189055, "max_line_length": 72, "alphanum_fraction": 0.404792469, "num_tokens": 6856, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.950410982634296, "lm_q2_score": 0.7154239897159438, "lm_q1q2_score": 0.6799468170660786}} {"text": "!> @brief \n!> Module for Splines \n!> @details\n!> basic functions and routines for B-Splines\n!> in 1D, 2D and 3D\n!>\n!> This file contains two modules\n!> BSPLINE : basic functions and routines\n!> BSP : specific implementations for 1D,2D,3D\n!> Externaly, the user should call BSP\n\nmodule spl_m_pppack\nimplicit none\ncontains\ninclude \"interv.f90\"\ninclude \"bsplpp.f90\"\ninclude \"bsplvb.f90\"\ninclude \"ppvalu.f90\"\n \n\n! .......................................................\n!> @brief Determine non zero elements \n!>\n!> @param[in] n number of control points - 1\n!> @param[in] p spline degree \n!> @param[in] U Knot vector \n!> @param[in] n_elements number of non-zero elements \n!> @param[in] grid the corresponding grid\n! .......................................................\n\nend module spl_m_pppack\n", "meta": {"hexsha": "3f64c10bc6954528b0c05a85be379364280e1c9e", "size": 808, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/src/bspline/pppack.f90", "max_stars_repo_name": "pyccel/splf2003", "max_stars_repo_head_hexsha": "cd341942dadb7eac92eb1c824aff6617ad6365be", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2018-08-19T22:17:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-14T23:20:10.000Z", "max_issues_repo_path": "fortran/src/bspline/pppack.f90", "max_issues_repo_name": "pyccel/splf2003", "max_issues_repo_head_hexsha": "cd341942dadb7eac92eb1c824aff6617ad6365be", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/src/bspline/pppack.f90", "max_forks_repo_name": "pyccel/splf2003", "max_forks_repo_head_hexsha": "cd341942dadb7eac92eb1c824aff6617ad6365be", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-12-23T11:05:44.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-23T09:33:57.000Z", "avg_line_length": 25.25, "max_line_length": 57, "alphanum_fraction": 0.603960396, "num_tokens": 227, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9149009503523291, "lm_q2_score": 0.743168019989179, "lm_q1q2_score": 0.6799251277595586}} {"text": "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! INPUT & OUTPUT:\n! n_atoms: int\n! atom_type: int (n_atoms)\n! atom_coords: real(n_atoms, 3)\n! cutoff: real\n! allow_neighbor_limit: int, e.g. 80\n! n_neighbor_limit: int, e.g. 50\n! small_face_thres: real e.g. 0.05\n! pbc: int(3), e.g. [1, 1, 1]\n! bds: real(3, 2)\n!\n! n_neighbor_list: int (n_atoms),\n! neighbor_lists: int (n_atoms, n_neighbor_limit)\n! neighbor_area_lists: real(n_atoms, n_neighbor_limit)\n! neighbor_vol_lists: real(n_atoms, n_neighbor_limit)\n! neighbor_distance_lists: real(n_atoms, n_neighbor_limit)\n! neighbor_edge_lists: int (n_atoms, n_neighbor_limit)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\nsubroutine determinant(face, deter_value)\n REAL(16), dimension(3, 3), intent(in) :: face\n REAL(16), intent(out) :: deter_value\n deter_value=(face(1,1)*face(2,2)*face(3,3)+face(1,2)*face(2,3)*face(3,1)&\n +face(1,3)*face(2,1)*face(3,2)&\n -face(3,1)*face(2,2)*face(1,3)-face(2,1)*face(1,2)*face(3,3)&\n -face(1,1)*face(3,2)*face(2,3))\n return\nEND subroutine determinant\n\n\nsubroutine voronoi(n_atoms, atom_type, atom_coords, cutoff, allow_neighbor_limit, &\n n_neighbor_limit, small_face_thres, pbc, bds, &\n n_neighbor_list, neighbor_lists, &\n neighbor_area_lists, neighbor_vol_lists, neighbor_distance_lists, neighbor_edge_lists, &\n print_freq)\n\n use :: distance\n\n integer :: n_atoms, allow_neighbor_limit, n_neighbor_limit\n REAL(8) :: cutoff, small_face_thres\n integer, dimension(3) :: pbc\n REAL(8), dimension(3, 2) :: bds\n integer, dimension(n_atoms):: atom_type, n_neighbor_list\n REAL(8), dimension(n_atoms, 3):: atom_coords\n integer, dimension(n_atoms, n_neighbor_limit):: neighbor_lists, neighbor_edge_lists\n REAL(8), dimension(n_atoms, n_neighbor_limit):: neighbor_area_lists\n REAL(8), dimension(n_atoms, n_neighbor_limit):: neighbor_vol_lists\n REAL(8), dimension(n_atoms, n_neighbor_limit):: neighbor_distance_lists\n integer :: print_freq\n\n!f2py intent(in) n_atoms, atom_type, atom_coords, cutoff, small_face_thres\n!f2py intent(in) allow_neighbor_limit, n_neighbor_limit, pbc, bds, print_freq\n!f2py intent(in, out) n_neighbor_list\n!f2py intent(in, out) neighbor_lists, neighbor_edge_lists\n!f2py intent(in, out) neighbor_area_lists, neighbor_vol_lists, neighbor_distance_lists\n!f2py intent(in) print_freq\n\n integer :: atom, i, j, l, k, s, possible_n_neighbor, CN_test\n integer, dimension(allow_neighbor_limit) :: bool, possible_neighbor_list, vertex_face\n integer, dimension(allow_neighbor_limit, allow_neighbor_limit) :: facetvoro\n REAL(8) :: d, d_temp, vertex(allow_neighbor_limit, 3)\n REAL(16) :: deter_value1, deter_value2, deter_value\n REAL(8) :: area_sum\n REAL(8), dimension(3) :: r, vv, a, vertex_x\n REAL(8), dimension(3,3) :: v\n REAL(16), dimension(3,3) :: face, face_2\n REAL(16), dimension(n_neighbor_limit):: neighbor_area_list_with_small\n REAL(16), dimension(n_neighbor_limit):: neighbor_vol_list_with_small\n integer, dimension(n_atoms) :: n_vertex_list\n integer, dimension(n_neighbor_limit, 3) :: vertex_info\n\n do atom = 1, n_atoms\n if (atom == 1) then\n write(*, *) \"start voronoi nn\"\n else if (mod(atom, print_freq) == 0) then\n write(*, *) \"voronoi nn: atom\", atom\n end if\n\n vertex = 0\n vertex_info = 0\n facetvoro = 0\n bool = 0\n possible_n_neighbor=0\n possible_neighbor_list = 0\n neighbor_area_list_with_small = 0\n neighbor_vol_list_with_small = 0\n vertex_face = 0\n do i = 1, n_atoms\n call distance_info(atom_coords(atom, :), atom_coords(i, :), bds, pbc, r, d)\n! write(*,*) r, d\n if((i /= atom).and.(d < cutoff)) then\n possible_n_neighbor = possible_n_neighbor + 1\n possible_neighbor_list(possible_n_neighbor) = i\n end if\n end do\n! write(*,*) possible_n_neighbor\n! write(*,*) possible_neighbor_list\n if(possible_n_neighbor > allow_neighbor_limit) then\n write(*,*) \"possible_n_neighbor OUT of allow_neighbor_limit\"\n end if\n\n n_vertex_list(atom) = 0\n\n do i = 1, possible_n_neighbor\n call distance_info(atom_coords(atom, :), atom_coords(possible_neighbor_list(i), :), bds, pbc, r, d)\n! write(*, *) r\n v(1, :) = r(:)\n do j = i+1,possible_n_neighbor\n call distance_info(atom_coords(atom, :), atom_coords(possible_neighbor_list(j), :), bds, pbc, r, d)\n v(2, :) = r(:)\n do k = j+1,possible_n_neighbor\n call distance_info(atom_coords(atom, :), atom_coords(possible_neighbor_list(k), :), bds, pbc, r, d)\n v(3, :) = r(:)\n\n vv = 0\n do m = 1, 3\n do n = 1, 3\n vv(m) = vv(m) + v(m,n)*v(m,n) !sum of |v|^2\n end do\n end do\n! write(*, *) vv\n\n do m = 1, 3\n do n = 1, 3\n face(m,n) = 2.0 * v(m,n) / vv(m) !reciprocal space?\n end do\n end do\n\n face_2 = face\n do m = 1, 3\n face_2(m, 1)=1.0 !set x = 1\n end do\n\n call determinant(face_2(1:3,1:3), deter_value1)\n call determinant(face(1:3,1:3), deter_value2)\n! deter_value1 = determinant(face_2(1:3,1:3))\n! deter_value2 = determinant(face(1:3,1:3))\n vertex_x(1)=deter_value1/deter_value2\n\n face_2 = face\n do m = 1, 3\n face_2(m, 2)=1.0 !set y = 1\n end do\n\n call determinant(face_2(1:3,1:3), deter_value1)\n\n! deter_value1 = determinant(face_2(1:3,1:3))\n! deter_value2 = determinant(face(1:3,1:3))\n vertex_x(2)=deter_value1/deter_value2\n\n face_2 = face\n do m = 1, 3\n face_2(m, 3)=1.0 !set y = 1\n end do\n\n\n call determinant(face_2(1:3,1:3), deter_value1)\n\n! deter_value1 = determinant(face_2(1:3, 1:3))\n! deter_value2 = determinant(face(1:3, 1:3))\n vertex_x(3)=deter_value1/deter_value2\n\n l=0\n s=0\n do l = 1, possible_n_neighbor\n call distance_info(atom_coords(atom, :), atom_coords(possible_neighbor_list(l), :), bds, pbc, r, d_temp)\n a(:) = vertex_x(:) * r(:) / d_temp**2\n! write(*,*) vertex_x, r, a\n\n !if found the fourth possible_neighbor_list, set s=1 and skip the following iteration\n if((a(1) + a(2) + a(3)) > 0.5000001D0) then\n s = 1\n exit\n end if\n end do\n\n if(s == 0) then\n bool(i) = 1\n bool(j) = 1\n bool(k) = 1\n n_vertex_list(atom) = n_vertex_list(atom) + 1\n vertex(n_vertex_list(atom), :) = vertex_x(:)\n vertex_info(n_vertex_list(atom), 1) = i\n vertex_info(n_vertex_list(atom), 2) = j\n vertex_info(n_vertex_list(atom), 3) = k\n end if\n\n end do\n end do\n end do\n ! calculate the area and vol of each part of the Voronoi polyhedra(cluster)\n !! start of i-iteration\n j=0\n k=0\n s=0\n n_neighbor_list(atom)=0\n area_sum = 0\n CN_test = 0\n\n do i = 1, possible_n_neighbor\n if (bool(i) == 1) then\n CN_test = CN_test + 1\n! write(*,*) CN_test\n k = 0\n do l = 1, n_vertex_list(atom)\n if ((vertex_info(l, 1) == i) .or. (vertex_info(l, 2) == i) .or. (vertex_info(l, 3) == i)) then\n k = k + 1\n facetvoro(i, k) = l ! the edge number of atom-i is k\n\n exit\n end if\n end do\n\n j = l\n l = 1\n! write(*,*) 'j', j\n! write(*,*) 'k', k\n! write(*,*) 'vertex_info is ', vertex_info\n do while(l <= n_vertex_list(atom))\n\n if (((vertex_info(l,1) == i &\n .and.((vertex_info(l,2) == vertex_info(j,1)) &\n .or.(vertex_info(l,2) == vertex_info(j,2)) &\n .or.(vertex_info(l,2) == vertex_info(j,3)) &\n .or.(vertex_info(l,3) == vertex_info(j,1)) &\n .or.(vertex_info(l,3) == vertex_info(j,2)) &\n .or.(vertex_info(l,3) == vertex_info(j,3)))) &\n .or.(vertex_info(l,2) == i &\n .and.((vertex_info(l,1) == vertex_info(j,1)) &\n .or.(vertex_info(l,1) == vertex_info(j,2)) &\n .or.(vertex_info(l,1) == vertex_info(j,3)) &\n .or.(vertex_info(l,3) == vertex_info(j,1)) &\n .or.(vertex_info(l,3) == vertex_info(j,2)) &\n .or.(vertex_info(l,3) == vertex_info(j,3)))) &\n .or.(vertex_info(l,3) == i &\n .and.((vertex_info(l,1) == vertex_info(j,1)) &\n .or.(vertex_info(l,1) == vertex_info(j,2)) &\n .or.(vertex_info(l,1) == vertex_info(j,3)) &\n .or.(vertex_info(l,2) == vertex_info(j,1)) &\n .or.(vertex_info(l,2) == vertex_info(j,2)) &\n .or.(vertex_info(l,2) == vertex_info(j,3))))) &\n .and.(l /= facetvoro(i, 1)) &\n .and.(l /= facetvoro(i, k + 1*merge(-1, 0, k /= 1))) &\n .and.(l /= j)) then\n! write(*, *) 'l', l\n k = k + 1\n! if(k > (n_atoms)) then\n if(k > (allow_neighbor_limit)) then\n\n exit\n end if\n facetvoro(i, k) = l\n! write(*, *) 'goto 200'\n j = l\n l = 0\n end if\n l = l + 1\n end do\n vertex_face(i)=k\n\n neighbor_vol_list_with_small(i) = 0\n do l = 2, k - 1\n face_2(1, :) = vertex(facetvoro(i, 1), :)\n do m = 2, 3\n face_2(m, :)=vertex(facetvoro(i, l + m-2), :)\n end do\n\n call determinant(face_2(1:3, 1:3), deter_value)\n! deter_value = determinant(face_2(1:3, 1:3))\n neighbor_vol_list_with_small(i) = neighbor_vol_list_with_small(i) + abs(deter_value/6.0)\n! write(*, *) 'neighbor_vol_list_with_small', neighbor_vol_list_with_small(i)\n end do\n\n call distance_info(atom_coords(atom, :), atom_coords(possible_neighbor_list(i), :), bds, pbc, r, d)\n neighbor_area_list_with_small(i) = 6.0 * neighbor_vol_list_with_small(i)/d\n area_sum = area_sum + neighbor_area_list_with_small(i)\n end if\n end do\n\n if (small_face_thres > 0.0) then\n s = 0\n do i = 1, possible_n_neighbor\n if (bool(i) == 1) then\n if (neighbor_area_list_with_small(i) < small_face_thres * area_sum / CN_test) then !5% percent\n bool(i) = 0\n CN_test = CN_test - 1\n else\n! write(*,*) \"atom is : \", atom\n! write(*,*) n_neighbor_list(atom)\n\n s = s + 1;\n n_neighbor_list(atom) = n_neighbor_list(atom) + 1\n neighbor_lists(atom, s) = possible_neighbor_list(i)\n neighbor_area_lists(atom, s) = neighbor_area_list_with_small(i)\n neighbor_vol_lists(atom, s) = neighbor_vol_list_with_small(i)\n neighbor_edge_lists(atom, s) = vertex_face(i)\n call distance_info(atom_coords(atom, :), atom_coords(possible_neighbor_list(i), :), bds, pbc, r, d)\n neighbor_distance_lists(atom, s) = d\n end if\n end if\n end do\n! write(*,*) \"atom is : \", atom\n! write(*,*) \"__________________________\"\n! write(*,*) n_neighbor_list(atom)\n! write(*,*) \"__________________________\"\n! write(*,*) neighbor_lists(atom, :)\n! write(*,*) \"__________________________\"\n! write(*,*) neighbor_area_lists(atom, :)\n! write(*,*) \"__________________________\"\n! write(*,*) neighbor_vol_lists(atom, :)\n! write(*,*) \"__________________________\"\n! write(*,*) neighbor_edge_lists(atom, :)\n! write(*,*) \"__________________________\"\n end if\n\n! if (n_neighbor_list(atom) > n_neighbor_max) then\n! n_neighbor_max = n_neighbor_list(atom)\n! end if\n!\n! do m = 1, n_neighbor_list(atom)\n! if (neighbor_edge_lists(atom, m) > n_neighbor_max) then\n! n_edge_max = neighbor_edge_lists(atom, m)\n! end if\n! end do\n\n end do\n write(*, *) \"finish voronoi nn for atoms: \", n_atoms\nend subroutine voronoi\n\n", "meta": {"hexsha": "756f2f97b5903647715fe8f3bba8ffe1eac7e637", "size": 12757, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "amlearn/featurize/src/voronoi_nn.f90", "max_stars_repo_name": "Qi-max/amlearn", "max_stars_repo_head_hexsha": "88189519bc1079ab5085d5871169c223e0d03057", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2019-02-07T16:45:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-15T12:44:07.000Z", "max_issues_repo_path": "amlearn/featurize/src/voronoi_nn.f90", "max_issues_repo_name": "Qi-max/amlearn", "max_issues_repo_head_hexsha": "88189519bc1079ab5085d5871169c223e0d03057", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-11-22T04:59:10.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-05T14:22:29.000Z", "max_forks_repo_path": "amlearn/featurize/src/voronoi_nn.f90", "max_forks_repo_name": "Qi-max/amlearn", "max_forks_repo_head_hexsha": "88189519bc1079ab5085d5871169c223e0d03057", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2020-12-03T07:18:50.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-20T09:17:47.000Z", "avg_line_length": 38.5407854985, "max_line_length": 118, "alphanum_fraction": 0.5419769538, "num_tokens": 3681, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900950352329, "lm_q2_score": 0.743168019989179, "lm_q1q2_score": 0.6799251277595585}} {"text": "! The Computer Language Benchmarks Game\n! http://shootout.alioth.debian.org/\n!\n! Contributed by Jason Blevins\n! Adapted from Fortran versions by George R. Gonzalez and Simon Geard\n!\n! ifort -fast -openmp -o mandelbrot mandelbrot.f90\nprogram mandelbrot\n implicit none\n\n integer, parameter :: dp = selected_real_kind(15, 307)\n integer, parameter :: int8 = selected_int_kind(2)\n integer, parameter :: iter = 50\n real(dp), parameter :: limit2 = 4.0_dp\n character(len=8) :: argv\n integer :: n, x, y, i, pos, bit_num\n integer(int8) :: byte\n real(dp) :: inv_2n, Zi, Zr, Ti, Tr, Cr, Ci\n integer(int8), dimension(:,:), allocatable :: buf\n\n ! read dimension from command line\n call get_command_argument(1, argv)\n read(argv, *) n\n\n ! allocate output buffer\n allocate(buf(ceiling(n / 8.0_dp), n))\n\n ! precalculate constants\n inv_2n = 2.0_dp / n\n\n ! pbm header\n write(*,'(\"P4\",/,i0,\" \",i0)') n, n\n\n !$OMP PARALLEL DO DEFAULT(PRIVATE) SHARED(n, inv_2n, buf)\n do y = 0, n - 1\n bit_num = 8 ! when moving left to right, bits are numbered 7 to 0\n byte = 0_int8\n pos = 0\n Ci = inv_2n * y - 1.0_dp\n do x = 0, n - 1\n bit_num = bit_num - 1\n\n Zr = 0.0_dp\n Zi = 0.0_dp\n Tr = 0.0_dp\n Ti = 0.0_dp\n\n Cr = inv_2n * x - 1.5_dp\n do i = 1, iter\n Zi = 2.0 * Zr * Zi + Ci\n Zr = Tr - Ti + Cr\n Ti = Zi * Zi\n Tr = Zr * Zr\n if (Tr + Ti > limit2) then\n exit\n end if\n end do\n\n ! We're in the set, set this bit to 0\n if (i > iter) byte = ibset(byte, bit_num)\n\n if (bit_num == 0 .or. x == n - 1) then\n ! All bits set or end of row, so store full byte\n pos = pos + 1\n buf(pos, y + 1) = byte\n byte = 0_int8\n bit_num = 8\n end if\n end do\n end do\n !$OMP END PARALLEL DO\n\n ! print output\n do y = 1, n\n write(*, '(10000000a1)', advance='no') buf(:, y)\n end do\n deallocate(buf)\nend program mandelbrot\n", "meta": {"hexsha": "b4dc18c3da879548ac97953f2842eb5a13a6e201", "size": 2014, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "shootout/mandelbrot.ifc-4.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-4.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-4.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.4936708861, "max_line_length": 70, "alphanum_fraction": 0.5585898709, "num_tokens": 699, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009596336303, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.679925119044297}} {"text": "!---------------------------------------------------------------------!\n! OWNER: Ithaca Combustion Enterprise, LLC !\n! COPYRIGHT: \u00a9 2012, Ithaca Combustion Enterprise, LLC !\n! LICENSE: BSD 3-Clause License (The complete text of the license can !\n! be found in the `LICENSE-ICE.txt' file included in the ISAT-CK7 !\n! source directory.) !\n!---------------------------------------------------------------------!\n\nsubroutine ell_pair_separate( n, c1, gg1, c2, gg2, qual, max_it, xh, v, intersect )\n\n! Determine if two non-concentric ellipsoids, E1 and E2, intersect.\n! If they do not intersect, determine a separating hyperplane.\n! If they do intersect, determine the hyperplane which is the \n! perpendicular bisector of the line of centers.\n\n! E1 is defined by: (x-c1)^T * G1 * G1^T * (x-c1) <= 1. The array\n! gg1 contains the lower triangular n x n matrix G1 in packed format.\n! Similarly for E2. \n\n! The hyperplane is defined by v^T * ( x - xh ) = 0, where v is\n! a unit vector. The quantity s(x) = v^T * ( x - xh ) is the signed\n! distance of the point x from the hyperplane: s(c1) is negative, and \n! s(c2) is positive. If E1 and E2 do not intersect, then s(x) is negative\n! for all points x in E1, and positive for all points x in E2. \n\n! Method:\n!\n!Phase I\n! 1/ transform to y-space in which E1 is the unit ball: y = G1^T * ( x - c1 )\n! 2/ find the point y2 in E2 that is closest to the origin\n! 3/ if |y2| <= 1, then E1 and E2 intersect; otherwise...\n! 4/ define y1 = y2/|y2|; yh = (y1+y2)/2; vy = y2-y1; then vy^T * ( y - yh )\n! is a separating hyperplane\n! 5/ transform back to x-space to obtain xh and v (and x1 and x2)\n! 6/ all done if qual <=0 or max_it <=0\n!\n!Phase II\n! The objective of phase II is to improve the quality of the separating hyperplane.\n! The quality q ( q <= 1 ) is defined by: \n! q= (distance between supporting hyperplanes)/|x1-x2|.\n! Starting from the value of x2 obtained in phase I, iterations are performed to:\n! 7/ determine the point x1 in E1 closest to x2\n! 8/ determine the point x2 in E2 closest to x1\n! 9/ xh = (x1+x2)/2; v = (x2-x1)/|x2-x1|\n! These operations (7-9) are performed iteratively until q >= qual, or the number\n! of iterations exceeds max_it. The values of xh and v returned correspond to the\n! hyperplane of greatest separation encountered during (or before) the iterations\n! (which usually occurs on the final iteration). \n!\n! Notes:\n! 1/ For 7 and 8, the same algorithm is used as in ell_pt_near_far, but there are \n! efficiency gains in re-coding it here.\n! 2/ A quadratic programming routine could be used to solve the whole problem.\n! 3/ Convergence is slow if E1 and E2 nearly intersect; but then the separating\n! hyperplane obtained from phase I may be adequate.\n! 4/ Aitken extrapolation could be used to speed up convergence.\n\n! S.B. Pope 6/13/04, 12/28/04\n\nimplicit none\n\ninteger, parameter :: k_dp = kind(1.d0)\ninteger, intent(in) :: n, max_it\nreal(k_dp), intent(in) :: c1(n), gg1((n*(n+1))/2), c2(n), gg2((n*(n+1))/2), qual\nreal(k_dp), intent(out) :: xh(n), v(n)\nlogical, intent(out) :: intersect\n\n\ninteger :: itmax = 100 ! max. iterations in dgqt\ninteger :: lu_diag = -1 ! logical unit for diagnostics (set < 0 to suppress)\nreal(k_dp) :: atol = 1.d-6, rtol = 1.d-6 ! tolerances for dgqt\n\ninteger :: info, i, j, k, iter\nreal(k_dp) :: g1(n,n), g2(n,n), c2y(n), y2(n), y2norm, x1(n), x2(n), g2y(n,n), &\n dist, smin1, smax1, smin2, smax2, q, qual_tol, sep, sep_max, &\n\t\t\t v_best(n), xh_best(n), gi(n,n), delta, par1, par2, f, &\n a1(n,n), a2(n,n), b(n), z(n), wa1(n), wa2(n)\n\n! unpack gg1 and gg2 -----------------------------------------------------------\nk = 0\ng1 = 0.d0\ng2 = 0.d0\ndo j = 1, n\n do i = j, n\n k = k + 1\n\t g1(i,j) = gg1(k)\n\t g2(i,j) = gg2(k)\t \n end do\nend do\n\n! transform to y-space: y = G1^T * (x-c1); G2y = G1^{-1} * G2\ng2y = g2\ncall dtrsm( 'L', 'L', 'N', 'N', n, n, 1.d0, g1, n, g2y, n )\n\nc2y = c2 - c1 ! c2y = G1^T * ( c2 - c1 )\ncall dtrmv( 'L', 'T', 'N', n, g1, n, c2y, 1 )\n\n! find point y2 in E2 closest to the origin\nv = 0.d0 ! origin\ncall ellu_pt_near_far( 1, n, c2y, g2y, v, y2 ) \n\ny2norm = sum( y2*y2 ) ! if y2 in unit ball then E1 and E2 intersect\n\nif( y2norm <= 1.d0 ) then\n intersect = .true. ! E1 and E2 intersect: all done\n xh = 0.5d0 * (c1 + c2) ! mid-point between centers\n v = c2 - c1\n dist = sum( v*v )\n if( dist > 0.d0 ) then\n v = v / sqrt( dist ) ! unit vector from c1 to c2\n else\n v = 0.d0 ! E1 and E2 are concentric\n\t v(1) = 1.d0 ! set v = e_1\n endif\n\n return \nendif\n\nintersect = .false.\n\n! hyperplane in y-space is: vy^T * ( y - yh ) = 0\ny2norm = sqrt( y2norm )\nv = y2 \n \n! transform back to x-space\ncall dtrsv( 'L', 'T', 'N', n, g1, n, y2, 1 )\nx2 = y2 + c1 ! x2 = G1^{-T} * y2 + c1\nx1 = y2/y2norm + c1\nxh = 0.5d0 * ( x1 + x2 )\n\ncall dtrmv( 'L', 'N', 'N', n, g1, n, v, 1 ) ! v = G1 * vy\nv = v / sqrt( sum(v*v) ) ! make unit vector\n\n!----------- end of phase I -------------------------------------------\n\nif( max_it <=0 .or. qual <= 0.d0 ) then\n return ! accept existing separating hyperplane\nelse\n qual_tol = min( qual, 1.d0-1.d-6 ) ! qual must be less than unity\nendif\n\n!--- form matrices A1 and A2 used in minimization ----\n\ngi = g1 ! start formation of a1\ncall dtrtri( 'L', 'N', n, gi, n, info ) ! gi = G1^{-1} \n\na1 = 0.d0 ! a1 = lower triangle of gi \ndo j = 1, n\n a1(j:n,j) = gi(j:n,j)\nend do\n\ncall dtrmm ( 'R', 'L', 'T', 'N', n, n, 1.d0, gi, n, a1, n ) ! a1 = = G1^{-1} * G1^{-T}\n\ngi = g2 ! start formation of a2\ncall dtrtri( 'L', 'N', n, gi, n, info ) ! gi = G2^{-1} \n\na2 = 0.d0 ! a2 = lower triangle of gi \ndo j = 1, n\n a2(j:n,j) = gi(j:n,j)\nend do\n\ncall dtrmm ( 'R', 'L', 'T', 'N', n, n, 1.d0, gi, n, a2, n ) ! a2 = = G2^{-1} * G2^{-T}\n\n!--- initialization prior to iteration\npar1 = 0.d0\npar2 = 0.d0\ndelta = 1.d0\n\nv_best = v\nxh_best = xh\n\ncall ell_line_proj( n, c1, gg1, xh, v, smin1, smax1 )\ncall ell_line_proj( n, c2, gg2, xh, v, smin2, smax2 )\nsep_max = smin2 - smax1 ! distance between supporting hyperplanes\n\ndo iter = 1, max_it !------------------ iterations --------------------------\n\n! determine point x1 in E1 closest to x2 ----------\n b = c1 - x2\n call dtrsv( 'L', 'N', 'N', n, g1, n, b, 1 ) ! b = G1^{-1} * [c1-x2]\n\n call dgqt(n,a1,n,b,delta,rtol,atol,itmax,par1,f,x1,info,z,wa1,wa2)\n\n if( info >= 3 ) then\n write(0,*)'ell_pair_separate: dgqt incomplete convergence, info = ', info\n endif\n\n call dtrsv( 'L', 'T', 'N', n, g1, n, x1, 1 ) ! x1 = G1^{-T} * y1 + c1\n x1 = x1 + c1\n\n! determine point x2 in E2 closest to x1 ----------\n\n b = c2 - x1\n call dtrsv( 'L', 'N', 'N', n, g2, n, b, 1 ) ! b = G2^{-1} * [c2-x1]\n\n call dgqt(n,a2,n,b,delta,rtol,atol,itmax,par2,f,x2,info,z,wa1,wa2)\n\n if( info >= 3 ) then\n write(0,*)'ell_pair_separate: dgqt incomplete convergence, info = ', info\n endif\n\n call dtrsv( 'L', 'T', 'N', n, g2, n, x2, 1 ) ! x2 = G2^{-T} * y2 + c2\n x2 = x2 + c2\n\n! determine hyperplane, dist=distance(x1,x2), sep=separation distance between\n! supporting hyperplanes, and q = quality = sep/dist -------------\n\n v = x2 - x1\n dist = sqrt( sum( v*v ) ) ! distance between \"close\" points\n v = v / dist ! unit vector from x1 to x2\n xh = 0.5d0 * ( x1 + x2 ) ! mid-point between x1 and x2\n\n call ell_line_proj( n, c1, gg1, xh, v, smin1, smax1 )\n call ell_line_proj( n, c2, gg2, xh, v, smin2, smax2 )\n\n sep = smin2 - smax1 ! distance between supporting hyperplanes\n q = sep / dist ! quality of separating hyperplane\n\n if( lu_diag >= 0 ) write(lu_diag,'(a,i4,1p,10e13.4)') &\n 'iter, sep, dist, q = ', iter, sep, dist, q\n\n if( sep > sep_max ) then\n sep_max = sep ! store xh and v with largest separation\n\t xh_best = xh\n\t v_best = v\n endif\n\n if( q >= qual_tol ) exit\n\nend do\n\nxh = xh_best ! return xh and v with largest separation\nv = v_best \n\nreturn\nend subroutine ell_pair_separate\n", "meta": {"hexsha": "6a451b971b2d46150cfafb8017923204ff776e87", "size": 8243, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/isat/ell_lib/ell_pair_separate.f90", "max_stars_repo_name": "xuhan425/isat_ffd", "max_stars_repo_head_hexsha": "3a5449f7e49b686c33fe0e97ca90ea8d92fc2f00", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-04-10T20:16:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-15T11:09:44.000Z", "max_issues_repo_path": "src/isat/ell_lib/ell_pair_separate.f90", "max_issues_repo_name": "xuhan425/isat_ffd", "max_issues_repo_head_hexsha": "3a5449f7e49b686c33fe0e97ca90ea8d92fc2f00", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-06-07T14:10:25.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-07T14:10:25.000Z", "max_forks_repo_path": "src/isat/ell_lib/ell_pair_separate.f90", "max_forks_repo_name": "xuhan425/isat_ffd", "max_forks_repo_head_hexsha": "3a5449f7e49b686c33fe0e97ca90ea8d92fc2f00", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-06-07T03:44:12.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-05T05:54:10.000Z", "avg_line_length": 34.7805907173, "max_line_length": 88, "alphanum_fraction": 0.5639936916, "num_tokens": 3075, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.884039278690883, "lm_q2_score": 0.7690802264851918, "lm_q1q2_score": 0.6798971286773898}} {"text": "!{ dg-run }\n!{ dg-options \"-fno-range-check\" }\n! PR19310 and PR19904, allow disabling range check during compile.\n! Contributed by Jerry DeLisle \nprogram main\n real, parameter :: zero=0, nan=0/zero\n complex :: z = (-0.1,-2.2)/(0.0,0.0)\n complex :: z2 = (0.1,1)/0\n complex :: z3 = (1e300, -2e-200)/1234e-325\n complex :: z4 = (1e-300, -2e-200)/1234e325\n real :: a\n a = exp(1000.0)\n b = 1/exp(1000.0)\n print *, a\n print *, b\n print *, -1.0/b\n print *, b/0.0\n print *, 0.0/0.0\n print *, 1.0/-0.0\n print *, -2.0/0.0\n print *, 3.0/0.0\n print *, nan\n print *, z\n print *, z2\n print *, z3\n print *, z4\n\nend program main\n!{dg-output \" +Infinity\"\n!{dg-output \" 0.000000\"\n!{dg-output \" -Infinity\"\n!{dg-output \" NaN\"\n!{dg-output \" NaN\"\n!{dg-output \" -Infinity\"\n!{dg-output \" -Infinity\"\n!{dg-output \" +Infinity\"\n!{dg-output \" NaN\"\n!{dg-output \" ( NaN, NaN)\"\n!{dg-output \" ( NaN, NaN)\"\n!{dg-output \" ( +Infinity, -Infinity)\"\n!{dg-output \" ( 0.000000 , 0.000000 )\"\n", "meta": {"hexsha": "66cda9eab8073247c26910b36ddc3009f9c89ce1", "size": 1111, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "llvm-gcc-4.2-2.9/gcc/testsuite/gfortran.dg/real_const_3.f90", "max_stars_repo_name": "vidkidz/crossbridge", "max_stars_repo_head_hexsha": "ba0bf94aee0ce6cf7eb5be882382e52bc57ba396", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-04-09T02:58:13.000Z", "max_stars_repo_stars_event_max_datetime": "2016-04-09T02:58:13.000Z", "max_issues_repo_path": "llvm-gcc-4.2-2.9/gcc/testsuite/gfortran.dg/real_const_3.f90", "max_issues_repo_name": "vidkidz/crossbridge", "max_issues_repo_head_hexsha": "ba0bf94aee0ce6cf7eb5be882382e52bc57ba396", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "llvm-gcc-4.2-2.9/gcc/testsuite/gfortran.dg/real_const_3.f90", "max_forks_repo_name": "vidkidz/crossbridge", "max_forks_repo_head_hexsha": "ba0bf94aee0ce6cf7eb5be882382e52bc57ba396", "max_forks_repo_licenses": ["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.4523809524, "max_line_length": 66, "alphanum_fraction": 0.5247524752, "num_tokens": 429, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950947024555, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.679869052415683}} {"text": " subroutine setprob()\n implicit none\n\n double precision pi\n common /compi/ pi\n\n pi = 4.d0*atan(1.d0)\n\n end\n", "meta": {"hexsha": "c5129f1c740e1d6144078943412d5b2a3bed1a26", "size": 137, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "applications/clawpack/advection/2d/latlong/setprob.f", "max_stars_repo_name": "mattzett/forestclaw", "max_stars_repo_head_hexsha": "8c2d012c259e0d9121e44c1ee78dfe2ab4839ec8", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2017-09-26T13:39:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:56:23.000Z", "max_issues_repo_path": "applications/clawpack/advection/2d/latlong/setprob.f", "max_issues_repo_name": "mattzett/forestclaw", "max_issues_repo_head_hexsha": "8c2d012c259e0d9121e44c1ee78dfe2ab4839ec8", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 75, "max_issues_repo_issues_event_min_datetime": "2017-08-02T19:56:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T12:36:32.000Z", "max_forks_repo_path": "applications/clawpack/advection/2d/latlong/setprob.f", "max_forks_repo_name": "mattzett/forestclaw", "max_forks_repo_head_hexsha": "8c2d012c259e0d9121e44c1ee78dfe2ab4839ec8", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-02-21T00:10:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T19:08:36.000Z", "avg_line_length": 13.7, "max_line_length": 26, "alphanum_fraction": 0.5401459854, "num_tokens": 39, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8438950868503681, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.6798690500280062}} {"text": "SUBROUTINE phi_nonlinear(k,x,z,omega,time,n_four_modes,zz,phix,phiz,phi,phit)\n!\nUSE PRECISION\nUSE Constants\nIMPLICIT NONE\nINTEGER :: n_four_modes\nREAL(KIND=long), INTENT(IN) :: k,x,z,omega,time,zz(2*n_four_modes+10) ! GD: change zz(*)\nREAL(KIND=long), INTENT(OUT) :: phix,phiz\nREAL(KIND=long), INTENT(OUT), OPTIONAL :: phi,phit\n ! Local variables\nREAL(KIND=long) :: kx, km, sinkmkx, sinhzh, temp1, e, b, e_inv, dir\nINTEGER :: m\n!\ndir = omega/ABS(omega) !direction of the wavefield\nkx=k*x-omega*time\n!\nphix = zero\nphiz = zero\nIF(present(phit)) phit = zero\nIF(present(phi)) phi = zero\n!\n! FIXME: optimization of loops (remove tests inside?)\nDO m=1,n_four_modes\n km=DBLE(m)\n sinkmkx = SIN(km*kx)\n e=EXP(km*(zz(1)+z))\n temp1=zz(n_four_modes+m+10)*half/COSH(km*zz(1))\n e_inv=one/e\n b=(e+e_inv)*temp1\n sinhzh=km*(e-e_inv)*temp1\n phiz=phiz+sinhzh*sinkmkx\n !\n temp1=b*km*COS(km*kx)\n phix=phix+temp1\n IF(present(phit)) phit=phit-omega*temp1\n IF(present(phi)) phi=phi+b*sinkmkx\nENDDO\n!\nphiz= dir*phiz\nphix= dir*(phix + zz(5))\n\nIF(present(phi)) phi = dir*(phi + kx*zz(5)) !it's k*x-omega*time !check the time dependence...\nIF(present(phit)) phit= dir*(phit)+(-zz(9)+zz(4)**2/2.d0)-dir*omega*zz(5) !check the time dependence...\n\nEND SUBROUTINE phi_nonlinear\n", "meta": {"hexsha": "3acd7ac41d32c038caa0d8e0d6e4414a7890e240", "size": 1287, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/functions/phi_nonlinear.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_nonlinear.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_nonlinear.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": 27.9782608696, "max_line_length": 103, "alphanum_fraction": 0.6767676768, "num_tokens": 503, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797172476384, "lm_q2_score": 0.7461390043208003, "lm_q1q2_score": 0.6798667269844612}} {"text": " !> Test for ordinary differentiation\nProgram example_1\n use Mirana\n implicit none\n integer, parameter :: n1 = 1000, n2 = 500\n integer :: st1 = -500, st2 = -250\n double precision, parameter :: L = 2.0\n double precision :: h1,h2,x,y,e1,e2,e1h1,e1h2,e2h1,e2h2,e11,e22,e12,elp\n integer :: i,j,ed1,ed2\n double precision, dimension(:,:),allocatable :: p, px, py, pxh1, pxh2, pyh1, pyh2, ppxx, ppyy, ppxy, pl\n ed1 = st1 + n1 - 1\n ed2 = st2 + n2 - 1\n allocate(p(st1:ed1,st2:ed2))\n allocate(px(st1:ed1,st2:ed2))\n allocate(pxh1(st1:ed1,st2:ed2))\n allocate(pxh2(st1:ed1,st2:ed2))\n allocate(py(st1:ed1,st2:ed2))\n allocate(pyh1(st1:ed1,st2:ed2))\n allocate(pyh2(st1:ed1,st2:ed2))\n allocate(ppxx(st1:ed1,st2:ed2))\n allocate(ppyy(st1:ed1,st2:ed2))\n allocate(ppxy(st1:ed1,st2:ed2))\n allocate(pl(st1:ed1,st2:ed2))\n write(*,*) 'Hello, this is example_1, testing for ordinary differentiation'\n h1 = L / n1\n h2 = L / n2\n do i = st1,ed1\n do j = st2,ed2\n x = h1 * i\n y = h2 * j\n p(i,j) = sin(2*x)*cos(3*y)\n end do\n end do\n\n call d1(p, h1, st1, st2, px)\n call d2(p, h2, st1, st2, py)\n call d1h1(p, h1, st1, st2, pxh1)\n call d1h2(p, h1, st1, st2, pxh2)\n call d2h2(p, h2, st1, st2, pyh2)\n call d2h1(p, h2, st1, st2, pyh1)\n call d12(p, h1, h2, st1, st2, ppxy)\n call d11(p, h1, st1, st2, ppxx)\n call d22(p, h2, st1, st2, ppyy)\n call dlp(p, h1, h2, st1, st2, pl)\n\n\n e1 = 0\n e2 = 0\n e1h1 = 0\n e1h2 = 0\n e2h1 = 0\n e2h2 = 0\n e11 = 0\n e12 = 0\n e22 = 0\n elp = 0\n do i = st1,ed1\n do j = st2,ed2\n x = h1 * i\n y = h2 * j\n if (ist1 .and. ist2 .and. jst1 .and. j>st2 .and. i ABS(y)) THEN\r\n a = y / x\r\n fn_val = ABS(x) * SQRT(1.0_dp + a*a)\r\n RETURN\r\nEND IF\r\nIF (y /= 0.0_dp) THEN\r\n a = x / y\r\n fn_val = ABS(y) * SQRT(1.0_dp + a*a)\r\n RETURN\r\nEND IF\r\nfn_val = 0.0_dp\r\nRETURN\r\nEND FUNCTION cpabs\r\n\r\n\r\n\r\nSUBROUTINE dcrec(x, y, u, v)\r\n!-----------------------------------------------------------------------\r\n! COMPLEX RECIPROCAL U + I*V = 1/(X + I*Y)\r\n!-----------------------------------------------------------------------\r\nREAL (dp), INTENT(IN) :: x, y\r\nREAL (dp), INTENT(OUT) :: u, v\r\n\r\n! Local variables\r\nREAL (dp) :: t, d\r\n\r\nIF (ABS(x) <= ABS(y)) THEN\r\n t = x / y\r\n d = y + t * x\r\n u = t / d\r\n v = -1.0_dp / d\r\n RETURN\r\nEND IF\r\nt = y / x\r\nd = x + t * y\r\nu = 1.0_dp / d\r\nv = -t / d\r\nRETURN\r\nEND SUBROUTINE dcrec\r\n\r\n\r\n\r\nFUNCTION cdiv(a,b) RESULT(fn_val)\r\n!-----------------------------------------------------------------------\r\n! COMPLEX DIVISION A/B WHERE B IS NONZERO\r\n!-----------------------------------------------------------------------\r\n\r\nCOMPLEX (dp), INTENT(IN) :: a, b\r\nCOMPLEX (dp) :: fn_val\r\n\r\n\r\nREAL (dp) :: ai, ar, bi, br, d, t\r\nREAL (dp) :: u, v\r\n\r\nar = REAL(a, KIND=dp)\r\nai = AIMAG(a)\r\nbr = REAL(b, KIND=dp)\r\nbi = AIMAG(b)\r\n\r\nIF (ABS(br) >= ABS(bi)) THEN\r\n t = bi / br\r\n d = br + t * bi\r\n u = (ar+ai*t) / d\r\n v = (ai-ar*t) / d\r\n fn_val = CMPLX(u,v, KIND=dp)\r\n RETURN\r\nEND IF\r\nt = br / bi\r\nd = bi + t * br\r\nu = (ar*t+ai) / d\r\nv = (ai*t-ar) / d\r\nfn_val = CMPLX(u,v, KIND=dp)\r\nRETURN\r\nEND FUNCTION cdiv\r\n\r\n\r\n\r\nFUNCTION dsin1(x) RESULT(fn_val)\r\n!-----------------------------------------------------------------------\r\n\r\n! REAL (dp) EVALUATION OF SIN(PI*X)\r\n\r\n! --------------\r\n\r\n! THE EXPANSION FOR SIN(PI*A) (ABS(A) <= PI/4) USING A1,...,A13\r\n! IS ACCURATE TO WITHIN 2 UNITS OF THE 40-TH SIGNIFICANT DIGIT, AND\r\n! THE EXPANSION FOR COS(PI*A) (ABS(A) <= PI/4) USING B1,...,B13\r\n! IS ACCURATE TO WITHIN 4 UNITS OF THE 40-TH SIGNIFICANT DIGIT.\r\n\r\n!-----------------------------------------------------------------------\r\nREAL (dp), INTENT(IN) :: x\r\nREAL (dp) :: fn_val\r\n\r\n! Local variables\r\nREAL (dp) :: a, t, w\r\nREAL (dp), PARAMETER :: pi = 3.141592653589793238462643383279502884197D+00\r\nREAL (dp), PARAMETER :: a1 = -.1028083791780141522795259479153765743002D+00, &\r\n a2 = .3170868848763100170457042079710451905600D-02, &\r\n a3 = -.4657026956105571623449026167864697920000D-04, &\r\n a4 = .3989844942879455643410226655783424000000D-06, &\r\n a5 = -.2237397227721999776371894030796800000000D-08, &\r\n a6 = .8847045483056962709715066675200000000000D-11, &\r\n a7 = -.2598715447506450292885585920000000000000D-13, &\r\n a8 = .5893449774331011070033920000000000000000D-16 , &\r\n a9 = -.1062975472045522550784000000000000000000D-18, &\r\n a10 = .1561182648301780992000000000000000000000D-21, &\r\n a11 = -.1903193516670976000000000000000000000000D-24, &\r\n a12 = .1956617650176000000000000000000000000000D-27, &\r\n a13 = -.1711276032000000000000000000000000000000D-30\r\nREAL (dp), PARAMETER :: b1 = -.3084251375340424568385778437461297229882D+00, &\r\n b2 = .1585434424381550085228521039855226435920D-01, &\r\n b3 = -.3259918869273900136414318317506279360000D-03, &\r\n b4 = .3590860448591510079069203991239232000000D-05, &\r\n b5 = -.2461136950494199754009084061808640000000D-07, &\r\n b6 = .1150115912797405152263195572224000000000D-09, &\r\n b7 = -.3898073171259675439899172864000000000000D-12, &\r\n b8 = .1001886461636271969091584000000000000000D-14, &\r\n b9 = -.2019653396886572027084800000000000000000D-17, &\r\n b10 = .3278483561466560512000000000000000000000D-20, &\r\n b11 = -.4377345082051788800000000000000000000000D-23, &\r\n b12 = .4891532381388800000000000000000000000000D-26, &\r\n b13 = -.4617089843200000000000000000000000000000D-29\r\nINTEGER :: max, n\r\n!------------------------\r\n\r\n! ****** MAX IS A MACHINE DEPENDENT CONSTANT. MAX IS THE\r\n! LARGEST POSITIVE INTEGER THAT MAY BE USED.\r\n\r\n! MAX = IPMPAR(3)\r\nmax = HUGE(3)\r\n\r\n!------------------------\r\na = ABS(x)\r\nt = MAX\r\nIF (a >= t) THEN\r\n fn_val = 0.0_dp\r\n RETURN\r\nEND IF\r\n\r\nn = a\r\nt = n\r\na = a - t\r\nIF (a <= 0.75_dp) THEN\r\n IF (a < 0.25_dp) GO TO 10\r\n\r\n! 0.25 <= A <= 0.75\r\n\r\n a = 0.25_dp + (0.25_dp-a)\r\n t = 16._dp * a * a\r\n fn_val = (((((((((((((b13*t + b12)*t + b11)*t + b10)*t + b9)*t + b8)*t &\r\n + b7)*t + b6)*t + b5)*t + b4)*t + b3)*t + b2)*t + b1)*t + &\r\n 0.5_dp) + 0.5_dp\r\n GO TO 20\r\nEND IF\r\n\r\n! A < 0.25 OR A > 0.75\r\n\r\na = 0.25_dp + (0.75_dp-a)\r\n10 t = 16._dp * a * a\r\nw = (((((((((((((a13*t + a12)*t + a11)*t + a10)*t + a9)*t + a8)*t + a7)*t &\r\n + a6)*t + a5)*t + a4)*t + a3)*t + a2)*t + a1)*t + 0.5_dp) + 0.5_dp\r\nfn_val = pi * a * w\r\n\r\n! TERMINATION\r\n\r\n20 IF (x < 0.0) fn_val = -fn_val\r\nIF (MOD(n,2) /= 0) fn_val = -fn_val\r\nRETURN\r\nEND FUNCTION dsin1\r\n\r\n\r\n\r\nFUNCTION dcos1 (x) RESULT(fn_val)\r\n \r\n!-----------------------------------------------------------------------\r\n\r\n! REAL (dp) EVALUATION OF COS(PI*X)\r\n\r\n! --------------\r\n\r\n! THE EXPANSION FOR SIN(PI*A) (ABS(A) .LE. PI/4) USING A1,...,A13\r\n! IS ACCURATE TO WITHIN 2 UNITS OF THE 40-TH SIGNIFICANT DIGIT, AND\r\n! THE EXPANSION FOR COS(PI*A) (ABS(A) .LE. PI/4) USING B1,...,B13\r\n! IS ACCURATE TO WITHIN 4 UNITS OF THE 40-TH SIGNIFICANT DIGIT.\r\n\r\n!-----------------------------------------------------------------------\r\n\r\nREAL (dp), INTENT(IN) :: x\r\nREAL (dp) :: fn_val\r\n\r\nREAL (dp) :: a, t, w\r\nINTEGER :: MAX, n\r\n!------------------------\r\nREAL (dp), PARAMETER :: pi = 3.141592653589793238462643383279502884197_dp\r\n!------------------------\r\nREAL (dp), PARAMETER :: &\r\n a1 = -.1028083791780141522795259479153765743002D+00, &\r\n a2 = .3170868848763100170457042079710451905600D-02, &\r\n a3 = -.4657026956105571623449026167864697920000D-04, &\r\n a4 = .3989844942879455643410226655783424000000D-06, &\r\n a5 = -.2237397227721999776371894030796800000000D-08, &\r\n a6 = .8847045483056962709715066675200000000000D-11, &\r\n a7 = -.2598715447506450292885585920000000000000D-13, &\r\n a8 = .5893449774331011070033920000000000000000D-16, &\r\n a9 = -.1062975472045522550784000000000000000000D-18, &\r\n a10 = .1561182648301780992000000000000000000000D-21, &\r\n a11 = -.1903193516670976000000000000000000000000D-24, &\r\n a12 = .1956617650176000000000000000000000000000D-27, &\r\n a13 = -.1711276032000000000000000000000000000000D-30\r\n!------------------------\r\nREAL (dp), PARAMETER :: &\r\n b1 = -.3084251375340424568385778437461297229882D+00, &\r\n b2 = .1585434424381550085228521039855226435920D-01, &\r\n b3 = -.3259918869273900136414318317506279360000D-03, &\r\n b4 = .3590860448591510079069203991239232000000D-05, &\r\n b5 = -.2461136950494199754009084061808640000000D-07, &\r\n b6 = .1150115912797405152263195572224000000000D-09, &\r\n b7 = -.3898073171259675439899172864000000000000D-12, &\r\n b8 = .1001886461636271969091584000000000000000D-14, &\r\n b9 = -.2019653396886572027084800000000000000000D-17, &\r\n b10 = .3278483561466560512000000000000000000000D-20, &\r\n b11 = -.4377345082051788800000000000000000000000D-23, &\r\n b12 = .4891532381388800000000000000000000000000D-26, &\r\n b13 = -.4617089843200000000000000000000000000000D-29\r\n!------------------------\r\n\r\n! ****** MAX IS A MACHINE DEPENDENT CONSTANT. MAX IS THE\r\n! LARGEST POSITIVE INTEGER THAT MAY BE USED.\r\n\r\nMAX = HUGE(0)\r\n\r\n!------------------------\r\na = ABS(x)\r\nt = MAX\r\nIF (a < t) GO TO 10\r\nfn_val = 1.d0\r\nRETURN\r\n\r\n10 n = a\r\nt = n\r\na = a - t\r\nIF (a > 0.75D0) GO TO 20\r\nIF (a < 0.25D0) GO TO 21\r\n\r\n! 0.25 .LE. A .LE. 0.75\r\n\r\na = 0.25D0 + (0.25D0 - a)\r\nt = 16.d0*a*a\r\nw = (((((((((((((a13*t + a12)*t + a11)*t + a10)*t + a9)*t + &\r\n a8)*t + a7)*t + a6)*t + a5)*t + a4)*t + a3)*t + a2)*t + a1)*t + 0.5D0) + 0.5D0\r\nfn_val = pi*a*w\r\nGO TO 30\r\n\r\n! A .LT. 0.25 OR A .GT. 0.75\r\n\r\n20 a = 0.25D0 + (0.75D0 - a)\r\nn = n - 1\r\n21 t = 16.d0*a*a\r\nfn_val = (((((((((((((b13*t + b12)*t + b11)*t + b10)*t + b9)*t + b8)*t + &\r\n b7)*t + b6)*t + b5)*t + b4)*t + b3)*t + b2)*t + b1)*t + 0.5D0) + 0.5D0\r\n\r\n! TERMINATION\r\n\r\n30 IF (MOD(n,2) /= 0) fn_val = -fn_val\r\nRETURN\r\nEND FUNCTION dcos1\r\n\r\n\r\n\r\n\r\nFUNCTION drexp(x) RESULT(fn_val)\r\n!-----------------------------------------------------------------------\r\n! EVALUATION OF THE FUNCTION EXP(X) - 1\r\n!-----------------------------------------------------------------------\r\nREAL (dp), INTENT(IN) :: x\r\nREAL (dp) :: fn_val\r\n\r\n! Local variables\r\nREAL (dp) :: e, w, z\r\nREAL (dp) :: a0 = .248015873015873015873016D-04, &\r\n a1 = -.344452080605731005808147D-05, a2 = .206664230430046597475413D-06, &\r\n a3 = -.447300111094328162971036D-08, a4 = .114734027080634968083920D-11, &\r\n b1 = -.249994190011341852652396D+00, b2 = .249987228833107957725728D-01, &\r\n b3 = -.119037506846942249362528D-02, b4 = .228908693387350391768682D-04\r\nREAL (dp) :: c1 = .1666666666666666666666666666666667D+00, &\r\n c2 = .4166666666666666666666666666666667D-01, &\r\n c3 = .8333333333333333333333333333333333D-02, &\r\n c4 = .1388888888888888888888888888888889D-02, &\r\n c5 = .1984126984126984126984126984126984D-03\r\n!---------------------------\r\nIF (ABS(x) <= 0.15_dp) THEN\r\n\r\n! Z IS A MINIMAX APPROXIMATION OF THE SERIES\r\n\r\n! C6 + C7*X + C8*X**2 + ....\r\n\r\n! THIS APPROXIMATION IS ACCURATE TO WITHIN\r\n! 1 UNIT OF THE 23-RD SIGNIFICANT DIGIT.\r\n! THE RESULTING VALUE FOR W IS ACCURATE TO\r\n! WITHIN 1 UNIT OF THE 33-RD SIGNIFICANT DIGIT.\r\n\r\n z = ((((a4*x + a3)*x + a2)*x + a1)*x + a0) / &\r\n ((((b4*x + b3)*x + b2)*x + b1)*x + 1._dp)\r\n w = ((((((z*x + c5)*x + c4)*x + c3)*x + c2)*x + c1)*x + 0.5_dp)*x + 1._dp\r\n fn_val = x * w\r\n RETURN\r\nEND IF\r\n\r\nIF (x >= 0.0_dp) THEN\r\n e = EXP(x)\r\n fn_val = e * (0.5_dp + (0.5_dp - 1.0_dp/e))\r\n RETURN\r\nEND IF\r\nIF (x >= -77._dp) THEN\r\n fn_val = (EXP(x)-0.5_dp) - 0.5_dp\r\n RETURN\r\nEND IF\r\nfn_val = -1._dp\r\nRETURN\r\nEND FUNCTION drexp\r\n\r\n\r\n\r\nSUBROUTINE dcgama(mo, z, w)\r\n!-----------------------------------------------------------------------\r\n\r\n! EVALUATION OF THE COMPLEX GAMMA AND LOGGAMMA FUNCTIONS\r\n\r\n! ---------------\r\n\r\n! MO IS AN INTEGER. Z AND W ARE INTERPRETED AS REAL (dp)\r\n! COMPLEX NUMBERS. IT IS ASSUMED THAT Z(1) AND Z(2) ARE THE REAL\r\n! AND IMAGINARY PARTS OF THE COMPLEX NUMBER Z, AND THAT W(1) AND\r\n! W(2) ARE THE REAL AND IMAGINARY PARTS OF W.\r\n\r\n! W = GAMMA(Z) IF MO = 0\r\n! W = LN(GAMMA(Z)) OTHERWISE\r\n\r\n!-----------------------------------------------------------------------\r\nINTEGER, INTENT(IN) :: mo\r\nCOMPLEX (dp), INTENT(IN) :: z\r\nCOMPLEX (dp), INTENT(OUT) :: w\r\n\r\n! Local variables\r\nREAL (dp), PARAMETER :: c0(30) &\r\n = (/ .8333333333333333333333333333333333333333D-01, &\r\n -.2777777777777777777777777777777777777778D-02, &\r\n .7936507936507936507936507936507936507937D-03, &\r\n -.5952380952380952380952380952380952380952D-03, &\r\n .8417508417508417508417508417508417508418D-03, &\r\n -.1917526917526917526917526917526917526918D-02, &\r\n .6410256410256410256410256410256410256410D-02, &\r\n -.2955065359477124183006535947712418300654D-01, &\r\n .1796443723688305731649384900158893966944D+00, &\r\n -.1392432216905901116427432216905901116427D+01, &\r\n .1340286404416839199447895100069013112491D+02, &\r\n -.1568482846260020173063651324520889738281D+03, &\r\n .2193103333333333333333333333333333333333D+04, &\r\n -.3610877125372498935717326521924223073648D+05, &\r\n .6914722688513130671083952507756734675533D+06, &\r\n -.1523822153940741619228336495888678051866D+08, &\r\n .3829007513914141414141414141414141414141D+09, &\r\n -.1088226603578439108901514916552510537473D+11, &\r\n .3473202837650022522522522522522522522523D+12, &\r\n -.1236960214226927445425171034927132488108D+14, &\r\n .4887880647930793350758151625180229021085D+15, &\r\n -.2132033396091937389697505898213683855747D+17, &\r\n .1021775296525700077565287628053585500394D+19, &\r\n -.5357547217330020361082770919196920448485D+20, &\r\n .3061578263704883415043151051329622758194D+22, &\r\n -.1899991742639920405029371429306942902947D+24, &\r\n .1276337403382883414923495137769782597654D+26, &\r\n -.9252847176120416307230242348347622779519D+27, &\r\n .7218822595185610297836050187301637922490D+29, &\r\n -.6045183405995856967743148238754547286066D+31 /), &\r\n dlpi = 1.144729885849400174143427351353058711647_dp, &\r\n hl2p = .9189385332046727417803297364056176398614_dp, &\r\n pi = 3.141592653589793238462643383279502884197_dp, &\r\n pi2 = 6.283185307179586476925286766559005768394_dp\r\nREAL (dp) :: a, a1, a2, c, cn, cut, d, eps, et, e2t, h1, h2, q1, q2, s, sn, &\r\n s1, s2, t, t1, t2, u, u1, u2, v1, v2, w1, w2, x, y, y2\r\nINTEGER :: j, k, max, n, nm1\r\n!---------------------------\r\n! DLPI = LOG(PI)\r\n! HL2P = 0.5 * LOG(2*PI)\r\n!---------------------------\r\n\r\n! ****** MAX AND EPS ARE MACHINE DEPENDENT CONSTANTS.\r\n! MAX IS THE LARGEST POSITIVE INTEGER THAT MAY\r\n! BE USED, AND EPS IS THE SMALLEST NUMBER SUCH\r\n! THAT 1._dp + EPS > 1._dp.\r\n\r\n! MAX = IPMPAR(3)\r\nmax = HUGE(3)\r\neps = EPSILON(1.0_dp)\r\n\r\n!---------------------------\r\nx = REAL(z, KIND=dp)\r\ny = AIMAG(z)\r\nIF (x < 0._dp) THEN\r\n!-----------------------------------------------------------------------\r\n! CASE WHEN THE REAL PART OF Z IS NEGATIVE\r\n!-----------------------------------------------------------------------\r\n y = ABS(y)\r\n t = -pi * y\r\n et = EXP(t)\r\n e2t = et * et\r\n\r\n! SET A1 = (1 + E2T)/2 AND A2 = (1 - E2T)/2\r\n\r\n a1 = 0.5_dp * (1._dp+e2t)\r\n t2 = t + t\r\n IF (t2 >= -0.15_dp) THEN\r\n a2 = -0.5_dp * drexp(t2)\r\n ELSE\r\n a2 = 0.5_dp * (0.5_dp+(0.5_dp-e2t))\r\n END IF\r\n\r\n! COMPUTE SIN(PI*X) AND COS(PI*X)\r\n\r\n u = MAX\r\n IF (ABS(x) >= MIN(u,1._dp/eps)) GO TO 80\r\n k = ABS(x)\r\n u = x + k\r\n k = MOD(k,2)\r\n IF (u <= -0.5_dp) THEN\r\n u = 0.5_dp + (0.5_dp+u)\r\n k = k + 1\r\n END IF\r\n u = pi * u\r\n sn = SIN(u)\r\n cn = COS(u)\r\n IF (k == 1) THEN\r\n sn = -sn\r\n cn = -cn\r\n END IF\r\n\r\n! SET H1 + H2*I TO PI/SIN(PI*Z) OR LOG(PI/SIN(PI*Z))\r\n\r\n a1 = sn * a1\r\n a2 = cn * a2\r\n a = a1 * a1 + a2 * a2\r\n IF (a == 0._dp) GO TO 80\r\n IF (mo == 0) THEN\r\n\r\n h1 = a1 / a\r\n h2 = -a2 / a\r\n c = pi * et\r\n h1 = c * h1\r\n h2 = c * h2\r\n ELSE\r\n\r\n h1 = (dlpi+t) - 0.5_dp * LOG(a)\r\n h2 = -ATAN2(a2,a1)\r\n END IF\r\n IF (AIMAG(z) >= 0._dp) THEN\r\n x = 1.0 - x\r\n y = -y\r\n ELSE\r\n h2 = -h2\r\n x = 1.0 - x\r\n END IF\r\nEND IF\r\n!-----------------------------------------------------------------------\r\n! CASE WHEN THE REAL PART OF Z IS NONNEGATIVE\r\n!-----------------------------------------------------------------------\r\nw1 = 0._dp\r\nw2 = 0._dp\r\nn = 0\r\nt = x\r\ny2 = y * y\r\na = t * t + y2\r\ncut = 225._dp\r\nIF (eps > 1.d-30) cut = 144._dp\r\nIF (eps > 1.d-20) cut = 64._dp\r\nIF (a < cut) THEN\r\n IF (a == 0._dp) GO TO 80\r\n 10 n = n + 1\r\n t = t + 1._dp\r\n a = t * t + y2\r\n IF (a < cut) GO TO 10\r\n\r\n! LET S1 + S2*I BE THE PRODUCT OF THE TERMS (Z+J)/(Z+N)\r\n\r\n u1 = (x*t+y2) / a\r\n u2 = y / a\r\n s1 = u1\r\n s2 = n * u2\r\n IF (n >= 2) THEN\r\n u = t / a\r\n nm1 = n - 1\r\n DO j = 1, nm1\r\n v1 = u1 + j * u\r\n v2 = (n-j) * u2\r\n c = s1 * v1 - s2 * v2\r\n d = s1 * v2 + s2 * v1\r\n s1 = c\r\n s2 = d\r\n END DO\r\n END IF\r\n\r\n! SET W1 + W2*I = LOG(S1 + S2*I) WHEN MO IS NONZERO\r\n\r\n s = s1 * s1 + s2 * s2\r\n IF (mo /= 0) THEN\r\n w1 = 0.5_dp * LOG(s)\r\n w2 = ATAN2(s2,s1)\r\n END IF\r\nEND IF\r\n\r\n! SET V1 + V2*I = (Z - 0.5) * LOG(Z + N) - Z\r\n\r\nt1 = 0.5_dp * LOG(a) - 1._dp\r\nt2 = ATAN2(y,t)\r\nu = x - 0.5_dp\r\nv1 = (u*t1-0.5_dp) - y * t2\r\nv2 = u * t2 + y * t1\r\n\r\n! LET A1 + A2*I BE THE ASYMPTOTIC SUM\r\n\r\nu1 = t / a\r\nu2 = -y / a\r\nq1 = u1 * u1 - u2 * u2\r\nq2 = 2._dp * u1 * u2\r\na1 = 0._dp\r\na2 = 0._dp\r\nDO j = 1, 30\r\n t1 = a1\r\n t2 = a2\r\n a1 = a1 + c0(j) * u1\r\n a2 = a2 + c0(j) * u2\r\n IF (a1 == t1) THEN\r\n IF (a2 == t2) GO TO 40\r\n END IF\r\n t1 = u1 * q1 - u2 * q2\r\n t2 = u1 * q2 + u2 * q1\r\n u1 = t1\r\n u2 = t2\r\nEND DO\r\n!-----------------------------------------------------------------------\r\n! GATHERING TOGETHER THE RESULTS\r\n!-----------------------------------------------------------------------\r\n40 w1 = (((a1+hl2p)-w1)+v1) - n\r\nw2 = (a2-w2) + v2\r\nIF (REAL(z, KIND=dp) < 0.0_dp) GO TO 60\r\nIF (mo == 0) THEN\r\n\r\n! CASE WHEN THE REAL PART OF Z IS NONNEGATIVE AND MO = 0\r\n\r\n a = EXP(w1)\r\n w1 = a * COS(w2)\r\n w2 = a * SIN(w2)\r\n IF (n == 0) GO TO 70\r\n c = (s1*w1+s2*w2) / s\r\n d = (s1*w2-s2*w1) / s\r\n w1 = c\r\n w2 = d\r\n GO TO 70\r\nEND IF\r\n\r\n! CASE WHEN THE REAL PART OF Z IS NONNEGATIVE AND MO IS NONZERO.\r\n! THE ANGLE W2 IS REDUCED TO THE INTERVAL -PI < W2 <= PI.\r\n\r\n50 IF (w2 <= pi) THEN\r\n k = 0.5_dp - w2 / pi2\r\n w2 = w2 + pi2 * k\r\n GO TO 70\r\nEND IF\r\nk = w2 / pi2 - 0.5_dp\r\nu = k + 1\r\nw2 = w2 - pi2 * u\r\nIF (w2 <= -pi) w2 = pi\r\nGO TO 70\r\n\r\n! CASE WHEN THE REAL PART OF Z IS NEGATIVE AND MO IS NONZERO\r\n\r\n60 IF (mo /= 0) THEN\r\n w1 = h1 - w1\r\n w2 = h2 - w2\r\n GO TO 50\r\nEND IF\r\n\r\n! CASE WHEN THE REAL PART OF Z IS NEGATIVE AND MO = 0\r\n\r\na = EXP(-w1)\r\nt1 = a * COS(-w2)\r\nt2 = a * SIN(-w2)\r\nw1 = h1 * t1 - h2 * t2\r\nw2 = h1 * t2 + h2 * t1\r\nIF (n /= 0) THEN\r\n c = w1 * s1 - w2 * s2\r\n d = w1 * s2 + w2 * s1\r\n w1 = c\r\n w2 = d\r\nEND IF\r\n\r\n! TERMINATION\r\n\r\n70 w = CMPLX(w1, w2, KIND=dp)\r\nRETURN\r\n!-----------------------------------------------------------------------\r\n! THE REQUESTED VALUE CANNOT BE COMPUTED\r\n!-----------------------------------------------------------------------\r\n80 w = CMPLX(0.0_dp, 0.0_dp, KIND=dp)\r\nRETURN\r\nEND SUBROUTINE dcgama\r\n\r\n\r\n\r\n\r\nFUNCTION cgam0(z) RESULT(fn_val)\r\n!-----------------------------------------------------------------------\r\n! EVALUATION OF 1/GAMMA(1 + Z) FOR ABS(Z) < 1.0\r\n!-----------------------------------------------------------------------\r\n\r\nCOMPLEX (dp), INTENT(IN) :: z\r\nCOMPLEX (dp) :: fn_val\r\n\r\nCOMPLEX (dp) :: w\r\nINTEGER :: i, k, n\r\n!-----------------------\r\nREAL (dp) :: x, y\r\nREAL, PARAMETER :: a(25) = (/ .577215664901533_dp, -.655878071520254_dp, &\r\n -.420026350340952D-01, .166538611382291_dp, -.421977345555443D-01, &\r\n -.962197152787697D-02, .721894324666310D-02, -.116516759185907D-02, &\r\n -.215241674114951D-03, .128050282388116D-03, -.201348547807882D-04, &\r\n -.125049348214267D-0, .113302723198170D-05, -.205633841697761D-0, &\r\n .611609510448142D-08, .500200764446922D-08, -.118127457048702D-08, &\r\n .104342671169110D-09, .778226343990507D-11, -.369680561864221D-11, &\r\n .510037028745448D-12, -.205832605356651D-13, -.534812253942302D-14, &\r\n .122677862823826D-14, -.118125930169746D-15 /)\r\n!-----------------------\r\nn = 25\r\nx = REAL(z, KIND=dp)\r\ny = AIMAG(z)\r\nIF (x*x+y*y <= 0.04D0) n = 14\r\n\r\nk = n\r\nw = a(n)\r\nDO i = 2, n\r\n k = k - 1\r\n w = a(k) + z * w\r\nEND DO\r\nfn_val = 1.0D0 + z * w\r\nRETURN\r\nEND FUNCTION cgam0\r\n\r\n\r\n\r\nFUNCTION dgamma(a) RESULT(fn_val)\r\n!-----------------------------------------------------------------------\r\n\r\n! EVALUATION OF THE GAMMA FUNCTION FOR\r\n! REAL (dp) ARGUMENTS\r\n\r\n! -----------\r\n\r\n! DGAMMA(A) IS ASSIGNED THE VALUE 0 WHEN THE GAMMA FUNCTION CANNOT\r\n! BE COMPUTED.\r\n\r\n!-----------------------------------------------------------------------\r\n! WRITTEN BY ALFRED H. MORRIS, JR.\r\n! NAVAL SURFACE WEAPONS CENTER\r\n! DAHLGREN, VIRGINIA\r\n!-----------------------------------------------------------------------\r\nREAL (dp), INTENT(IN) :: a\r\nREAL (dp) :: fn_val\r\n\r\n! Local variables\r\nREAL (dp), PARAMETER :: d = 0.41893853320467274178032973640562_dp, &\r\n pi = 3.14159265358979323846264338327950_dp\r\nREAL (dp) :: s, t, x, w\r\nINTEGER :: j, n\r\n!-----------------------------------------------------------------------\r\n! D = 0.5*(LN(2*PI) - 1)\r\n!-----------------------------------------------------------------------\r\nfn_val = 0.0_dp\r\nx = a\r\nIF (ABS(a) <= 20._dp) THEN\r\n!-----------------------------------------------------------------------\r\n! EVALUATION OF DGAMMA(A) FOR ABS(A) <= 20\r\n!-----------------------------------------------------------------------\r\n t = 1.0_dp\r\n n = x\r\n n = n - 1\r\n\r\n! LET T BE THE PRODUCT OF A-J WHEN A >= 2\r\n\r\n IF (n < 0) THEN\r\n GO TO 40\r\n ELSE IF (n == 0) THEN\r\n GO TO 30\r\n END IF\r\n\r\n DO j = 1, n\r\n x = x - 1._dp\r\n t = x * t\r\n END DO\r\n 30 x = x - 1._dp\r\n GO TO 60\r\n\r\n! LET T BE THE PRODUCT OF A+J WHEN A < 1\r\n\r\n 40 t = a\r\n IF (a <= 0._dp) THEN\r\n n = -n - 1\r\n IF (n /= 0) THEN\r\n DO j = 1, n\r\n x = x + 1._dp\r\n t = x * t\r\n END DO\r\n END IF\r\n x = (x+0.5_dp) + 0.5_dp\r\n t = x * t\r\n IF (t == 0._dp) RETURN\r\n END IF\r\n\r\n! THE FOLLOWING CODE CHECKS IF 1/T CAN OVERFLOW. THIS\r\n! CODE MAY BE OMITTED IF DESIRED.\r\n\r\n IF (ABS(t) < 1.d-33) THEN\r\n IF (ABS(t)*HUGE(1.0_dp) <= 1.000000001_dp) RETURN\r\n fn_val = 1._dp / t\r\n RETURN\r\n END IF\r\n\r\n! COMPUTE DGAMMA(1 + X) FOR 0 <= X < 1\r\n\r\n 60 fn_val = 1._dp / (1._dp + dgam1(x))\r\n\r\n! TERMINATION\r\n\r\n IF (a >= 1._dp) THEN\r\n fn_val = fn_val * t\r\n RETURN\r\n END IF\r\n fn_val = fn_val / t\r\n RETURN\r\nEND IF\r\n!-----------------------------------------------------------------------\r\n! EVALUATION OF DGAMMA(A) FOR ABS(A) > 20\r\n!-----------------------------------------------------------------------\r\nIF (ABS(a) >= 1.d3) RETURN\r\nIF (a <= 0._dp) THEN\r\n s = dsin1(a) / pi\r\n IF (s == 0._dp) RETURN\r\n x = -a\r\nEND IF\r\n\r\n! COMPUTE THE MODIFIED ASYMPTOTIC SUM\r\n\r\nw = dpdel(x)\r\n\r\n! FINAL ASSEMBLY\r\n\r\nw = (d+w) + (x-0.5_dp) * (LOG(x)-1._dp)\r\nIF (w > dxparg(0)) RETURN\r\nfn_val = EXP(w)\r\nIF (a < 0._dp) fn_val = (1._dp/(fn_val*s)) / x\r\n\r\nRETURN\r\nEND FUNCTION dgamma\r\n\r\n\r\n\r\nFUNCTION glog(x) RESULT(fn_val)\r\n! -------------------\r\n! EVALUATION OF LN(X) FOR X >= 15\r\n! -------------------\r\nREAL (dp), INTENT(IN) :: x\r\nREAL (dp) :: fn_val\r\n\r\n! Local variables\r\nREAL (dp), PARAMETER :: c1 = .286228750476730_dp, c2 = .399999628131494+dp, &\r\n c3 = .666666666752663_dp\r\nREAL (dp), PARAMETER :: w(163) = (/ .270805020110221007D+01, .277258872223978124D+01, &\r\n .283321334405621608D+01, .289037175789616469D+01, .294443897916644046D+01, .299573227355399099D+01, .304452243772342300D+01, &\r\n .309104245335831585D+01, .313549421592914969D+01, .317805383034794562D+01, .321887582486820075D+01, .325809653802148205D+01, &\r\n .329583686600432907D+01, .333220451017520392D+01, .336729582998647403D+01, .340119738166215538D+01, .343398720448514625D+01, &\r\n .346573590279972655D+01, .349650756146648024D+01, .352636052461616139D+01, .355534806148941368D+01, .358351893845611000D+01, &\r\n .361091791264422444D+01, .363758615972638577D+01, .366356164612964643D+01, .368887945411393630D+01, .371357206670430780D+01, &\r\n .373766961828336831D+01, .376120011569356242D+01, .378418963391826116D+01, .380666248977031976D+01, .382864139648909500D+01, &\r\n .385014760171005859D+01, .387120101090789093D+01, .389182029811062661D+01, .391202300542814606D+01, .393182563272432577D+01, &\r\n .395124371858142735D+01, .397029191355212183D+01, .398898404656427438D+01, .400733318523247092D+01, .402535169073514923D+01, &\r\n .404305126783455015D+01, .406044301054641934D+01, .407753744390571945D+01, .409434456222210068D+01, .411087386417331125D+01, &\r\n .412713438504509156D+01, .414313472639153269D+01, .415888308335967186D+01, .417438726989563711D+01, .418965474202642554D+01, &\r\n .420469261939096606D+01, .421950770517610670D+01, .423410650459725938D+01, .424849524204935899D+01, .426267987704131542D+01, &\r\n .427666611901605531D+01, .429045944114839113D+01, .430406509320416975D+01, .431748811353631044D+01, .433073334028633108D+01, &\r\n .434380542185368385D+01, .435670882668959174D+01, .436944785246702149D+01, .438202663467388161D+01, .439444915467243877D+01, &\r\n .440671924726425311D+01, .441884060779659792D+01, .443081679884331362D+01, .444265125649031645D+01, .445434729625350773D+01, &\r\n .446590811865458372D+01, .447733681447820647D+01, .448863636973213984D+01, .449980967033026507D+01, .451085950651685004D+01, &\r\n .452178857704904031D+01, .453259949315325594D+01, .454329478227000390D+01, .455387689160054083D+01, .456434819146783624D+01, &\r\n .457471097850338282D+01, .458496747867057192D+01, .459511985013458993D+01, .460517018598809137D+01, .461512051684125945D+01, &\r\n .462497281328427108D+01, .463472898822963577D+01, .464439089914137266D+01, .465396035015752337D+01, .466343909411206714D+01, &\r\n .467282883446190617D+01, .468213122712421969D+01, .469134788222914370D+01, .470048036579241623D+01, .470953020131233414D+01, &\r\n .471849887129509454D+01, .472738781871234057D+01, .473619844839449546D+01, .474493212836325007D+01, .475359019110636465D+01, &\r\n .476217393479775612D+01, .477068462446566476D+01, .477912349311152939D+01, .478749174278204599D+01, .479579054559674109D+01, &\r\n .480402104473325656D+01, .481218435537241750D+01, .482028156560503686D+01, .482831373730230112D+01, .483628190695147800D+01, &\r\n .484418708645859127D+01, .485203026391961717D+01, .485981240436167211D+01, .486753445045558242D+01, .487519732320115154D+01, &\r\n .488280192258637085D+01, .489034912822175377D+01, .489783979995091137D+01, .490527477843842945D+01, .491265488573605201D+01, &\r\n .491998092582812492D+01, .492725368515720469D+01, .493447393313069176D+01, .494164242260930430D+01, .494875989037816828D+01, &\r\n .495582705760126073D+01, .496284463025990728D+01, .496981329957600062D+01, .497673374242057440D+01, .498360662170833644D+01, &\r\n .499043258677873630D+01, .499721227376411506D+01, .500394630594545914D+01, .501063529409625575D+01, .501727983681492433D+01, &\r\n .502388052084627639D+01, .503043792139243546D+01, .503695260241362916D+01, .504342511691924662D+01, .504985600724953705D+01, &\r\n .505624580534830806D+01, .506259503302696680D+01, .506890420222023153D+01, .507517381523382692D+01, .508140436498446300D+01, &\r\n .508759633523238407D+01, .509375020080676233D+01, .509986642782419842D+01, .510594547390058061D+01, .511198778835654323D+01, &\r\n .511799381241675511D+01, .512396397940325892D+01, .512989871492307347D+01, .513579843705026176D+01, .514166355650265984D+01, &\r\n .514749447681345304D+01, .515329159449777895D+01, .515905529921452903D+01, .516478597392351405D+01, .517048399503815178D+01, &\r\n .517614973257382914D+01 /)\r\nREAL (dp) :: t, t2, z\r\nINTEGER :: n\r\n! -------------------\r\n\r\nIF (x < 178.0_dp) THEN\r\n n = x\r\n t = (x-n) / (x+n)\r\n t2 = t * t\r\n z = (((c1*t2 + c2)*t2 + c3)*t2 + 2.0) * t\r\n fn_val = w(n-14) + z\r\n RETURN\r\nEND IF\r\n\r\nfn_val = LOG(x)\r\nRETURN\r\nEND FUNCTION glog\r\n\r\n\r\n\r\nSUBROUTINE cbsslj(z,cnu,w)\r\n!-----------------------------------------------------------------------\r\n\r\n! EVALUATION OF THE COMPLEX BESSEL FUNCTION J (Z)\r\n! CNU\r\n!-----------------------------------------------------------------------\r\n\r\n! WRITTEN BY\r\n! ANDREW H. VAN TUYL AND ALFRED H. MORRIS, JR.\r\n! NAVAL SURFACE WARFARE CENTER\r\n! OCTOBER, 1991\r\n\r\n! A MODIFICATION OF THE PROCEDURE DEVELOPED BY ALLEN V. HERSHEY\r\n! (NAVAL SURFACE WARFARE CENTER) IN 1978 FOR HANDLING THE DEBYE\r\n! APPROXIMATION IS EMPLOYED.\r\n\r\n!-----------------------------------------------------------------------\r\n\r\nCOMPLEX (dp), INTENT(IN) :: z\r\nCOMPLEX (dp), INTENT(IN) :: cnu\r\nCOMPLEX (dp), INTENT(OUT) :: w\r\n\r\nCOMPLEX (dp) :: c, nu, s, sm1, sm2, t, tsc, w0, w1, zn, zz\r\n!-----------------------\r\nREAL (dp) :: a, cn1, cn2, e, fn\r\nREAL (dp) :: pn, qm, qn, qnp1\r\nREAL (dp) :: r, rn2, r2, sn, t1, t2\r\nREAL (dp) :: u, v, x, y\r\nINTEGER :: i, k, m, n\r\nREAL (dp), PARAMETER :: pi = 3.141592653589793238462643383279502884197_dp\r\n!-----------------------\r\nx = REAL(z, KIND=dp)\r\ny = AIMAG(z)\r\nr = cpabs(x,y)\r\ncn1 = REAL(cnu, KIND=dp)\r\ncn2 = AIMAG(cnu)\r\nrn2 = cn1 * cn1 + cn2 * cn2\r\npn = INT(cn1)\r\nfn = cn1 - pn\r\nsn = 1.0_dp\r\n\r\n! CALCULATION WHEN ORDER IS AN INTEGER\r\n\r\nIF (fn == 0.0_dp .AND. cn2 == 0.0_dp) THEN\r\n n = pn\r\n pn = ABS(pn)\r\n cn1 = pn\r\n IF (n < 0 .AND. n /= (n/2)*2) sn = -1.0_dp\r\nEND IF\r\n\r\n! SELECTION OF METHOD\r\n\r\nIF (r > 17.5D0) THEN\r\n IF (r > 17.5D0 + 0.5D0*rn2) GO TO 10\r\n GO TO 20\r\nEND IF\r\n\r\n! USE MACLAURIN EXPANSION AND RECURSION\r\n\r\nIF (cn1 < 0.0D0) THEN\r\n qn = -1.25D0 * (r + 0.5D0*ABS(cn2) - ABS(y-0.5D0*cn2))\r\n IF (cn1 < qn) THEN\r\n qn = 1.25D0 * (r - MAX(1.2D0*r,ABS(y-cn2)))\r\n IF (cn1 < qn) THEN\r\n qn = MIN(pn, REAL(-INT(1.25D0*(r-ABS(cn2))), KIND=dp))\r\n GO TO 60\r\n END IF\r\n END IF\r\nEND IF\r\n\r\nr2 = r * r\r\nqm = 0.0625D0 * r2 * r2 - cn2 * cn2\r\nqn = MAX(pn, REAL(INT(SQRT(MAX(0.0D0,qm))), KIND=dp))\r\nGO TO 60\r\n\r\n! USE ASYMPTOTIC EXPANSION\r\n\r\n10 CALL cbja(z,cnu,w)\r\nRETURN\r\n\r\n! CALCULATION FOR 17.5 < ABS(Z) <= 17.5 + 0.5*ABS(CNU)**2\r\n\r\n20 n = 0\r\nIF (ABS(cn2) < 0.8D0*ABS(y)) THEN\r\n qm = -1.25D0 * (r + 0.5D0*ABS(cn2) - ABS(y-0.5D0*cn2))\r\n IF (cn1 < qm) THEN\r\n qm = 1.25D0 * (r - MAX(1.2D0*r, ABS(y-cn2)))\r\n IF (cn1 < qm) n = 1\r\n END IF\r\nEND IF\r\n\r\nqn = pn\r\na = 4.d-3 * r * r\r\nzz = z\r\nIF (x < 0.0D0) zz = -z\r\n\r\n! CALCULATION OF ZONE OF EXCLUSION OF DEBYE APPROXIMATION\r\n\r\n30 nu = CMPLX(qn+fn,cn2, KIND=dp)\r\nzn = nu / z\r\nt2 = AIMAG(zn) * AIMAG(zn)\r\nu = 1.0D0 - REAL(zn, KIND=dp)\r\nt1 = u * u + t2\r\nu = 1.0D0 + DBLE(zn)\r\nt2 = u * u + t2\r\nu = t1 * t2\r\nv = a * u / (t1*t1 + t2*t2)\r\nIF (u*v*v <= 1.0D0) THEN\r\n \r\n! THE ARGUMENT LIES INSIDE THE ZONE OF EXCLUSION\r\n \r\n qn = qn + 1.0D0\r\n IF (n == 0) GO TO 30\r\n \r\n! USE MACLAURIN EXPANSION WITH FORWARD RECURRENCE\r\n \r\n qn = MIN(pn, REAL(-INT(1.25D0*(r-ABS(cn2))), KIND=dp))\r\nELSE\r\n \r\n! USE BACKWARD RECURRENCE STARTING FROM THE ASYMPTOTIC EXPANSION\r\n \r\n qnp1 = qn + 1.0D0\r\n IF (ABS(qn) < ABS(pn)) THEN\r\n IF (r >= 17.5D0 + 0.5D0*(qnp1*qnp1 + cn2*cn2)) THEN\r\n \r\n nu = CMPLX(qn+fn,cn2, KIND=dp)\r\n CALL cbja(zz,nu,sm1)\r\n nu = CMPLX(qnp1+fn,cn2, KIND=dp)\r\n CALL cbja(zz,nu,sm2)\r\n GO TO 40\r\n END IF\r\n END IF\r\n \r\n! USE BACKWARD RECURRENCE STARTING FROM THE DEBYE APPROXIMATION\r\n \r\n nu = CMPLX(qn+fn,cn2, KIND=dp)\r\n CALL cbdb(zz,nu,fn,sm1)\r\n IF (qn == pn) GO TO 50\r\n nu = CMPLX(qnp1+fn,cn2, KIND=dp)\r\n CALL cbdb(zz,nu,fn,sm2)\r\n \r\n 40 nu = CMPLX(qn+fn,cn2, KIND=dp)\r\n tsc = 2.0D0 * nu * sm1 / zz - sm2\r\n sm2 = sm1\r\n sm1 = tsc\r\n qn = qn - 1.0D0\r\n IF (qn /= pn) GO TO 40\r\n \r\n 50 w = sm1\r\n IF (sn < 0.0D0) w = -w\r\n IF (x >= 0.0D0) RETURN\r\n \r\n nu = pi * CMPLX(-cn2,cn1, KIND=dp)\r\n IF (y < 0.0D0) nu = -nu\r\n w = EXP(nu) * w\r\n RETURN\r\nEND IF\r\n\r\n! USE MACLAURIN EXPANSION WITH FORWARD OR BACKWARD RECURRENCE.\r\n\r\n60 m = qn - pn\r\nIF (ABS(m) <= 1) THEN\r\n nu = CMPLX(cn1,cn2, KIND=dp)\r\n CALL cbjm(z,nu,w)\r\nELSE\r\n nu = CMPLX(qn+fn,cn2, KIND=dp)\r\n CALL cbjm(z,nu,w1)\r\n w0 = 0.25D0 * z * z\r\n IF (m <= 0) THEN\r\n \r\n! FORWARD RECURRENCE\r\n \r\n m = ABS(m)\r\n nu = nu + 1.0D0\r\n CALL cbjm(z,nu,w)\r\n DO i = 2, m\r\n c = nu * (nu+1.0D0)\r\n t = (c/w0) * (w-w1)\r\n w1 = w\r\n w = t\r\n nu = nu + 1.0D0\r\n END DO\r\n ELSE\r\n \r\n! BACKWARD RECURRENCE\r\n \r\n nu = nu - 1.0D0\r\n CALL cbjm(z,nu,w)\r\n DO i = 2, m\r\n c = nu * (nu+1.0D0)\r\n t = (w0/c) * w1\r\n w1 = w\r\n w = w - t\r\n nu = nu - 1.0D0\r\n END DO\r\n END IF\r\nEND IF\r\n\r\n! FINAL ASSEMBLY\r\n\r\nIF (fn == 0.0D0 .AND. cn2 == 0.0D0) THEN\r\n k = pn\r\n IF (k == 0) RETURN\r\n e = sn / dgamma(pn+1.0D0)\r\n w = e * w * (0.5D0*z) ** k\r\n RETURN\r\nEND IF\r\n\r\ns = cnu * LOG(0.5D0*z)\r\nw = EXP(s) * w\r\nIF (rn2 <= 0.81D0) THEN\r\n w = w * cgam0(cnu)\r\n RETURN\r\nEND IF\r\nCALL dcgama(0,cnu,t)\r\nw = cdiv(w,cnu*t)\r\nRETURN\r\nEND SUBROUTINE cbsslj\r\n\r\n\r\n\r\nSUBROUTINE cbjm(z,cnu,w)\r\n!-----------------------------------------------------------------------\r\n\r\n! COMPUTATION OF (Z/2)**(-CNU) * GAMMA(CNU + 1) * J(CNU,Z)\r\n\r\n! -----------------\r\n\r\n! THE MACLAURIN EXPANSION IS USED. IT IS ASSUMED THAT CNU IS NOT\r\n! A NEGATIVE INTEGER.\r\n\r\n!-----------------------------------------------------------------------\r\n\r\nCOMPLEX (dp), INTENT(IN) :: z\r\nCOMPLEX (dp), INTENT(IN) :: cnu\r\nCOMPLEX (dp), INTENT(OUT) :: w\r\n\r\nCOMPLEX (dp) :: nu, nup1, p, s, sn, t, ti\r\n!--------------------------\r\nREAL (dp) :: a, a0, eps, inu, m, rnu\r\nINTEGER :: i, imin, k, km1, km2\r\n\r\n!--------------------------\r\n\r\n! ****** EPS IS A MACHINE DEPENDENT CONSTANT. EPS IS THE\r\n! SMALLEST NUMBER SUCH THAT 1.0 + EPS .GT. 1.0 .\r\n\r\neps = EPSILON(0.0_dp)\r\n\r\n!--------------------------\r\ns = -0.25D0 * (z*z)\r\nnu = cnu\r\nrnu = REAL(nu, KIND=dp)\r\ninu = AIMAG(nu)\r\na = 0.5D0 + (0.5D0+rnu)\r\nnup1 = CMPLX(a,inu, KIND=dp)\r\n\r\nIF (a > 0.0D0) THEN\r\n m = 1.0D0\r\n t = s / nup1\r\n w = 1.0D0 + t\r\nELSE\r\n \r\n! ADD 1.0 AND THE FIRST K-1 TERMS\r\n \r\n k = INT(-a) + 2\r\n km1 = k - 1\r\n w = (1.0D0,0.0D0)\r\n t = w\r\n DO i = 1, km1\r\n m = i\r\n t = t * (s/(m*(nu+m)))\r\n w = w + t\r\n IF (anorm(t) <= eps*anorm(w)) GO TO 20\r\n END DO\r\n GO TO 50\r\n \r\n! CHECK IF THE (K-1)-ST AND K-TH TERMS CAN BE IGNORED.\r\n! IF SO THEN THE SUMMATION IS COMPLETE.\r\n \r\n 20 IF (i /= km1) THEN\r\n imin = i + 1\r\n IF (imin < k-5) THEN\r\n ti = t\r\n \r\n m = km1\r\n t = s / (nu+m)\r\n a0 = anorm(t) / m\r\n t = t * (s/(nu+(m+1.0D0)))\r\n a = anorm(t) / (m*(m+1.0D0))\r\n a = MAX(a,a0)\r\n \r\n t = (1.0D0,0.0D0)\r\n km2 = k - 2\r\n DO i = imin, km2\r\n m = i\r\n t = t * (s/(m*(nu+m)))\r\n IF (a*anorm(t) < 0.5D0) RETURN\r\n END DO\r\n t = t * ti\r\n imin = km2\r\n END IF\r\n \r\n! ADD THE (K-1)-ST TERM\r\n \r\n a = 1.0D0\r\n p = (1.0D0,0.0D0)\r\n sn = p\r\n DO i = imin, km1\r\n m = i\r\n a = a * m\r\n p = p * (nu+m)\r\n sn = s * sn\r\n END DO\r\n t = t * (cdiv(sn,p)/a)\r\n w = w + t\r\n END IF\r\nEND IF\r\n\r\n! ADD THE REMAINING TERMS\r\n\r\n50 m = m + 1.0D0\r\nt = t * (s/(m*(nu+m)))\r\nw = w + t\r\nIF (anorm(t) > eps*anorm(w)) GO TO 50\r\n\r\nRETURN\r\nEND SUBROUTINE cbjm\r\n\r\n\r\n\r\nSUBROUTINE cbdb(cz,cnu,fn,w)\r\n!-----------------------------------------------------------------------\r\n\r\n! CALCULATION OF J (CZ) BY THE DEBYE APPROXIMATION\r\n! CNU\r\n! ------------------\r\n\r\n! IT IS ASSUMED THAT REAL(CZ) .GE. 0 AND THAT REAL(CNU) = FN + K\r\n! WHERE K IS AN INTEGER.\r\n\r\n!-----------------------------------------------------------------------\r\n\r\nCOMPLEX (dp), INTENT(IN) :: cz, cnu\r\nREAL (dp), INTENT(IN) :: fn\r\nCOMPLEX (dp), INTENT(OUT) :: w\r\n\r\n! Local variables\r\nREAL (dp) :: is, inu, izn\r\nCOMPLEX (dp) :: c1, c2, eta, nu, p, p1, q, r, s, s1, s2, sm, t, z, zn\r\n!----------------------\r\n! C = 1/SQRT(2*PI)\r\n! BND = PI/3\r\n!----------------------\r\nREAL (dp), PARAMETER :: c = .398942280401433_dp, pi = 3.14159265358979_dp, &\r\n pi2 = 6.28318530717959_dp, bnd = 1.04719755119660_dp\r\nCOMPLEX (dp), PARAMETER :: j = (0.0, 1.0)\r\nREAL (dp) :: alpha, am, aq, ar\r\nREAL (dp) :: phi, sgn, theta\r\nREAL (dp) :: u, v, x, y\r\nINTEGER :: ind, k, l, m\r\n\r\n!----------------------\r\n! COEFFICIENTS OF THE FIRST 16 POLYNOMIALS\r\n! IN THE DEBYE APPROXIMATION\r\n!----------------------\r\n\r\nREAL (dp) :: a(136) = (/ 1.0_dp, -.208333333333333_dp, .125000000000000_dp, .334201388888889_dp, &\r\n -.401041666666667_dp, .703125000000000D-01,-.102581259645062D+01, .184646267361111D+01, &\r\n -.891210937500000_dp, .732421875000000D-01, .466958442342625D+01,-.112070026162230D+02, &\r\n .878912353515625D+01,-.236408691406250D+01, .112152099609375_dp,-.282120725582002D+02, &\r\n .846362176746007D+02,-.918182415432400D+02, .425349987453885D+02,-.736879435947963D+01, &\r\n .227108001708984_dp, .212570130039217D+03,-.765252468141182D+03, .105999045252800D+04, &\r\n -.699579627376133D+03, .218190511744212D+03,-.264914304869516D+02, .572501420974731_dp, &\r\n -.191945766231841D+04, .806172218173731D+04,-.135865500064341D+05, .116553933368645D+05, &\r\n -.530564697861340D+04, .120090291321635D+04,-.108090919788395D+03, .172772750258446D+01, &\r\n .202042913309661D+05,-.969805983886375D+05, .192547001232532D+06,-.203400177280416D+06, &\r\n .122200464983017D+06,-.411926549688976D+05, .710951430248936D+04,-.493915304773088D+03, &\r\n .607404200127348D+01,-.242919187900551D+06, .131176361466298D+07,-.299801591853811D+07, &\r\n .376327129765640D+07,-.281356322658653D+07, .126836527332162D+07,-.331645172484564D+06, &\r\n .452187689813627D+05,-.249983048181121D+04, .243805296995561D+02, .328446985307204D+07, &\r\n -.197068191184322D+08, .509526024926646D+08,-.741051482115327D+08, .663445122747290D+08, &\r\n -.375671766607634D+08, .132887671664218D+08,-.278561812808645D+07, .308186404612662D+06, &\r\n -.138860897537170D+05, .110017140269247D+03,-.493292536645100D+08, .325573074185766D+09, &\r\n -.939462359681578D+09, .155359689957058D+10,-.162108055210834D+10, .110684281682301D+10, &\r\n -.495889784275030D+09, .142062907797533D+09,-.244740627257387D+08, .224376817792245D+07, &\r\n -.840054336030241D+05, .551335896122021D+03, .814789096118312D+09,-.586648149205185D+10, &\r\n .186882075092958D+11,-.346320433881588D+11, .412801855797540D+11,-.330265997498007D+11, &\r\n .179542137311556D+11,-.656329379261928D+10, .155927986487926D+10,-.225105661889415D+09, &\r\n .173951075539782D+08,-.549842327572289D+06, .303809051092238D+04,-.146792612476956D+11, &\r\n .114498237732026D+12,-.399096175224466D+12, .819218669548577D+12,-.109837515608122D+13, &\r\n .100815810686538D+13,-.645364869245377D+12, .287900649906151D+12,-.878670721780233D+11, &\r\n .176347306068350D+11,-.216716498322380D+10, .143157876718889D+09,-.387183344257261D+07, &\r\n .182577554742932D+05, .286464035717679D+12,-.240629790002850D+13, .910934118523990D+13, &\r\n -.205168994109344D+14, .305651255199353D+14,-.316670885847852D+14, .233483640445818D+14, &\r\n -.123204913055983D+14, .461272578084913D+13,-.119655288019618D+13, .205914503232410D+12, &\r\n -.218229277575292D+11, .124700929351271D+10,-.291883881222208D+08, .118838426256783D+06, &\r\n -.601972341723401D+13, .541775107551060D+14,-.221349638702525D+15, .542739664987660D+15, &\r\n -.889496939881026D+15, .102695519608276D+16,-.857461032982895D+15, .523054882578445D+15, &\r\n -.232604831188940D+15, .743731229086791D+14,-.166348247248925D+14, .248500092803409D+13, &\r\n -.229619372968246D+12, .114657548994482D+11,-.234557963522252D+09, .832859304016289D+06 /)\r\n\r\nz = cz\r\nnu = cnu\r\ninu = AIMAG(cnu)\r\nIF (inu < 0.0D0) THEN\r\n z = CONJG(z)\r\n nu = CONJG(nu)\r\nEND IF\r\nx = REAL(z, KIND=dp)\r\ny = AIMAG(z)\r\n\r\n! TANH(GAMMA) = SQRT(1 - (Z/NU)**2) = W/NU\r\n! T = EXP(NU*(TANH(GAMMA) - GAMMA))\r\n\r\nzn = z / nu\r\nizn = AIMAG(zn)\r\nIF (ABS(izn) <= 0.1D0*ABS(REAL(zn, KIND=dp))) THEN\r\n \r\n s = (1.0D0-zn) * (1.0D0+zn)\r\n eta = 1.0D0 / s\r\n q = SQRT(s)\r\n s = 1.0D0 / (nu*q)\r\n t = zn / (1.0D0 + q)\r\n t = EXP(nu*(q + LOG(t)))\r\nELSE\r\n \r\n s = (nu-z) * (nu+z)\r\n eta = (nu*nu) / s\r\n w = SQRT(s)\r\n q = w / nu\r\n IF (REAL(q, KIND=dp) < 0.0D0) w = -w\r\n s = 1.0D0 / w\r\n t = z / (nu+w)\r\n t = EXP(w + nu*LOG(t))\r\nEND IF\r\n\r\nis = AIMAG(s)\r\nr = SQRT(s)\r\nc1 = r * t\r\nar = REAL(r, KIND=dp) * REAL(r, KIND=dp) + AIMAG(r) * AIMAG(r)\r\naq = -1.0D0 / (REAL(q, KIND=dp)*REAL(q, KIND=dp) + AIMAG(q)*AIMAG(q))\r\n\r\nphi = ATAN2(y,x) / 3.0D0\r\nq = nu - z\r\ntheta = ATAN2(AIMAG(q),REAL(q, KIND=dp)) - phi\r\nind = 0\r\nIF (ABS(theta) >= 2.0D0*bnd) THEN\r\n \r\n ind = 1\r\n CALL dcrec(REAL(t, KIND=dp), AIMAG(t),u,v)\r\n c2 = -j * r * CMPLX(u,v, KIND=dp)\r\n IF (is >= 0.0D0) THEN\r\n IF (is > 0.0D0) GO TO 10\r\n IF (REAL(s, KIND=dp) <= 0.0D0) GO TO 10\r\n END IF\r\n c2 = -c2\r\nEND IF\r\n\r\n! SUMMATION OF THE SERIES S1 AND S2\r\n\r\n10 sm = s * s\r\np = (a(2)*eta + a(3)) * s\r\np1 = ((a(4)*eta + a(5))*eta + a(6)) * sm\r\ns1 = (1.0D0 + p) + p1\r\nIF (ind /= 0) s2 = (1.0D0-p) + p1\r\nsgn = 1.0D0\r\nam = ar * ar\r\nm = 4\r\nl = 6\r\n\r\n! P = VALUE OF THE M-TH POLYNOMIAL\r\n\r\n20 l = l + 1\r\nalpha = a(l)\r\np = CMPLX(a(l),0.0D0, KIND=dp)\r\nDO k = 2, m\r\n l = l + 1\r\n alpha = a(l) + aq * alpha\r\n p = a(l) + eta * p\r\nEND DO\r\n\r\n! ONLY THE S1 SUM IS FORMED WHEN IND = 0\r\n\r\nsm = s * sm\r\np = p * sm\r\ns1 = s1 + p\r\nIF (ind /= 0) THEN\r\n sgn = -sgn\r\n s2 = s2 + sgn * p\r\nEND IF\r\nam = ar * am\r\nIF (1.0D0 + alpha*am /= 1.0D0) THEN\r\n m = m + 1\r\n IF (m <= 16) GO TO 20\r\nEND IF\r\n\r\n! FINAL ASSEMBLY\r\n\r\ns1 = c * c1 * s1\r\nIF (ind == 0) THEN\r\n w = s1\r\nELSE\r\n \r\n s2 = c * c2 * s2\r\n q = nu + z\r\n theta = ATAN2(AIMAG(q),REAL(q, KIND=dp)) - phi\r\n IF (ABS(theta) <= bnd) THEN\r\n w = s1 + s2\r\n ELSE\r\n \r\n alpha = pi2\r\n IF (izn < 0.0D0) alpha = -alpha\r\n t = alpha * CMPLX(ABS(inu),-fn, KIND=dp)\r\n alpha = EXP(REAL(t))\r\n u = AIMAG(t)\r\n r = CMPLX(COS(u),SIN(u), KIND=dp)\r\n t = s1 - (alpha*r) * s1\r\n IF (x == 0.0D0 .AND. inu == 0.0D0) t = -t\r\n \r\n IF (y < 0.0D0) THEN\r\n IF (izn >= 0.0D0 .AND. theta <= SIGN(pi,theta)) s2 = &\r\n s2 * ( CONJG(r)/alpha)\r\n IF (x == 0.0D0) GO TO 40\r\n IF (izn >= 0.0D0) THEN\r\n IF (is < 0.0D0) GO TO 40\r\n END IF\r\n END IF\r\n \r\n w = s2 + t\r\n GO TO 50\r\n 40 w = s2 - t\r\n END IF\r\nEND IF\r\n\r\n50 IF (inu < 0.0D0) w = CONJG(w)\r\nRETURN\r\nEND SUBROUTINE cbdb\r\n\r\n\r\n\r\nSUBROUTINE cbja(cz,cnu,w)\r\n!-----------------------------------------------------------------------\r\n! COMPUTATION OF J(NU,Z) BY THE ASYMPTOTIC EXPANSION\r\n!-----------------------------------------------------------------------\r\n\r\nCOMPLEX (dp), INTENT(IN) :: cz\r\nCOMPLEX (dp), INTENT(IN) :: cnu\r\nCOMPLEX (dp), INTENT(OUT) :: w\r\n\r\n! Local variables\r\nREAL (dp) :: eps, inu, m\r\nCOMPLEX (dp) :: a, a1, arg, e, eta, nu, p, q, t, z, zr, zz\r\n!--------------------------\r\nREAL (dp) :: r, rnu, tol, u, v\r\nREAL (dp) :: x, y\r\nINTEGER :: i, ind\r\n\r\n!--------------------------\r\n! PIHALF = PI/2\r\n! C = 2*PI**(-1/2)\r\n!--------------------------\r\nREAL (dp), PARAMETER :: pihalf = 1.5707963267949_dp, c = 1.12837916709551_dp\r\nCOMPLEX (dp), PARAMETER :: j = (0.0_dp, 1.0_dp)\r\n!--------------------------\r\n\r\n! ****** EPS IS A MACHINE DEPENDENT CONSTANT. EPS IS THE\r\n! SMALLEST NUMBER SUCH THAT 1.0 + EPS .GT. 1.0 .\r\n\r\neps = EPSILON(0.0_dp)\r\n\r\n!--------------------------\r\nz = cz\r\nx = REAL(z, KIND=dp)\r\ny = AIMAG(z)\r\nnu = cnu\r\nind = 0\r\nIF (ABS(x) <= 1.d-2*ABS(y)) THEN\r\n IF (AIMAG(nu) < 0.0D0 .AND. ABS(REAL(nu)) < 1.d-2*ABS(AIMAG(nu))) THEN\r\n ind = 1\r\n nu = CONJG(nu)\r\n z = CONJG(z)\r\n y = -y\r\n END IF\r\nEND IF\r\n\r\nIF (x < -1.d-2*y) z = -z\r\nzz = z + z\r\nCALL dcrec(REAL(zz, KIND=dp),AIMAG(zz),u,v)\r\nzr = CMPLX(u,v, KIND=dp)\r\neta = -zr * zr\r\n\r\np = (0.0D0,0.0D0)\r\nq = (0.0D0,0.0D0)\r\na1 = nu * nu - 0.25D0\r\na = a1\r\nt = a1\r\nm = 1.0D0\r\ntol = eps * anorm(a1)\r\nDO i = 1, 16\r\n a = a - 2.0D0 * m\r\n m = m + 1.0D0\r\n t = t * a * eta / m\r\n p = p + t\r\n a = a - 2.0D0 * m\r\n m = m + 1.0D0\r\n t = t * a / m\r\n q = q + t\r\n IF (anorm(t) <= tol) GO TO 20\r\nEND DO\r\n\r\n20 p = p + 1.0D0\r\nq = (q+a1) * zr\r\nw = z - pihalf * nu\r\nIF (ABS(AIMAG(w)) <= 1.0D0) THEN\r\n arg = w - 0.5D0 * pihalf\r\n w = c * SQRT(zr) * (p*COS(arg) - q*SIN(arg))\r\nELSE\r\n e = EXP(-j*w)\r\n t = q - j * p\r\n IF (AIMAG(z) > 0.0D0 .AND. REAL(z, KIND=dp) <= 1.d-2*AIMAG(z).AND. &\r\n ABS(REAL(nu, KIND=dp)) < 1.d-2*AIMAG(nu)) t = 0.5D0 * t\r\n CALL dcrec(REAL(e, KIND=dp),AIMAG(e),u,v)\r\n w = 0.5D0 * c * SQRT(j*zr) * ((p-j*q)*e + t*CMPLX(u,v, KIND=dp))\r\nEND IF\r\n\r\nIF (x < -1.d-2*y) THEN\r\n IF (y < 0.0D0) nu = -nu\r\n \r\n! COMPUTATION OF EXP(I*PI*NU)\r\n \r\n rnu = REAL(nu, KIND=dp)\r\n inu = AIMAG(nu)\r\n r = EXP(-2.0D0*pihalf*inu)\r\n u = r * dcos1(rnu)\r\n v = r * dsin1(rnu)\r\n w = w * CMPLX(u,v, KIND=dp)\r\nEND IF\r\n\r\nIF (ind /= 0) w = CONJG(w)\r\nRETURN\r\nEND SUBROUTINE cbja\r\n\r\n\r\n\r\nFUNCTION anorm(z) RESULT(fn_val)\r\n! Replaces the statement function anorm in the F77 code.\r\n\r\nCOMPLEX (dp), INTENT(IN) :: z\r\nREAL (dp) :: fn_val\r\n\r\nfn_val = MAX( ABS( REAL(z, KIND=dp)), ABS(AIMAG(z) ) )\r\nRETURN\r\nEND FUNCTION anorm\r\n\r\n\r\n\r\nFUNCTION dgam1(x) RESULT(fn_val)\r\n!-----------------------------------------------------------------------\r\n! EVALUATION OF 1/GAMMA(1 + X) - 1 FOR -0.5 <= X <= 1.5\r\n!-----------------------------------------------------------------------\r\n\r\n! THE FOLLOWING ARE THE FIRST 49 COEFFICIENTS OF THE MACLAURIN\r\n! EXPANSION FOR 1/GAMMA(1 + X) - 1. THE COEFFICIENTS ARE\r\n! CORRECT TO 40 DIGITS. THE COEFFICIENTS WERE OBTAINED BY\r\n! ALFRED H. MORRIS JR. (NAVAL SURFACE WARFARE CENTER) AND ARE\r\n! GIVEN HERE FOR REFERENCE. ONLY THE FIRST 14 COEFFICIENTS ARE\r\n! USED IN THIS CODE.\r\n\r\n! -----------\r\n\r\n! DATA A(1) / .5772156649015328606065120900824024310422D+00/,\r\n! * A(2) /-.6558780715202538810770195151453904812798D+00/,\r\n! * A(3) /-.4200263503409523552900393487542981871139D-01/,\r\n! * A(4) / .1665386113822914895017007951021052357178D+00/,\r\n! * A(5) /-.4219773455554433674820830128918739130165D-01/,\r\n! * A(6) /-.9621971527876973562114921672348198975363D-02/,\r\n! * A(7) / .7218943246663099542395010340446572709905D-02/,\r\n! * A(8) /-.1165167591859065112113971084018388666809D-02/,\r\n! * A(9) /-.2152416741149509728157299630536478064782D-03/,\r\n! * A(10) / .1280502823881161861531986263281643233949D-03/\r\n! DATA A(11) /-.2013485478078823865568939142102181838229D-04/,\r\n! * A(12) /-.1250493482142670657345359473833092242323D-05/,\r\n! * A(13) / .1133027231981695882374129620330744943324D-05/,\r\n! * A(14) /-.2056338416977607103450154130020572836513D-06/,\r\n! * A(15) / .6116095104481415817862498682855342867276D-08/,\r\n! * A(16) / .5002007644469222930055665048059991303045D-08/,\r\n! * A(17) /-.1181274570487020144588126565436505577739D-08/,\r\n! * A(18) / .1043426711691100510491540332312250191401D-09/,\r\n! * A(19) / .7782263439905071254049937311360777226068D-11/,\r\n! * A(20) /-.3696805618642205708187815878085766236571D-11/\r\n! DATA A(21) / .5100370287454475979015481322863231802727D-12/,\r\n! * A(22) /-.2058326053566506783222429544855237419746D-13/,\r\n! * A(23) /-.5348122539423017982370017318727939948990D-14/,\r\n! * A(24) / .1226778628238260790158893846622422428165D-14/,\r\n! * A(25) /-.1181259301697458769513764586842297831212D-15/,\r\n! * A(26) / .1186692254751600332579777242928674071088D-17/,\r\n! * A(27) / .1412380655318031781555803947566709037086D-17/,\r\n! * A(28) /-.2298745684435370206592478580633699260285D-18/,\r\n! * A(29) / .1714406321927337433383963370267257066813D-19/,\r\n! * A(30) / .1337351730493693114864781395122268022875D-21/\r\n! DATA A(31) /-.2054233551766672789325025351355733796682D-21/,\r\n! * A(32) / .2736030048607999844831509904330982014865D-22/,\r\n! * A(33) /-.1732356445910516639057428451564779799070D-23/,\r\n! * A(34) /-.2360619024499287287343450735427531007926D-25/,\r\n! * A(35) / .1864982941717294430718413161878666898946D-25/,\r\n! * A(36) /-.2218095624207197204399716913626860379732D-26/,\r\n! * A(37) / .1297781974947993668824414486330594165619D-27/,\r\n! * A(38) / .1180697474966528406222745415509971518560D-29/,\r\n! * A(39) /-.1124584349277088090293654674261439512119D-29/,\r\n! * A(40) / .1277085175140866203990206677751124647749D-30/\r\n! DATA A(41) /-.7391451169615140823461289330108552823711D-32/,\r\n! * A(42) / .1134750257554215760954165259469306393009D-34/,\r\n! * A(43) / .4639134641058722029944804907952228463058D-34/,\r\n! * A(44) /-.5347336818439198875077418196709893320905D-35/,\r\n! * A(45) / .3207995923613352622861237279082794391090D-36/,\r\n! * A(46) /-.4445829736550756882101590352124643637401D-38/,\r\n! * A(47) /-.1311174518881988712901058494389922190237D-38/,\r\n! * A(48) / .1647033352543813886818259327906394145400D-39/,\r\n! * A(49) /-.1056233178503581218600561071538285049997D-40/\r\n\r\n! -----------\r\n\r\n! C = A(1) - 1 IS ALSO FREQUENTLY NEEDED. C HAS THE VALUE ...\r\n\r\n! DATA C /-.4227843350984671393934879099175975689578D+00/\r\n\r\n!-----------------------------------------------------------------------\r\nREAL (dp), INTENT(IN) :: x\r\nREAL (dp) :: fn_val\r\n\r\n! Local variables\r\nREAL (dp) :: d, t, w, z\r\nREAL (dp), PARAMETER :: a0 = .611609510448141581788D-08, a1 &\r\n = .624730830116465516210D-08, b1 = .203610414066806987300D+00, b2 &\r\n = .266205348428949217746D-01, b3 = .493944979382446875238D-03, b4 &\r\n = -.851419432440314906588D-05, b5 = -.643045481779353022248D-05, b6 &\r\n = .992641840672773722196D-06, b7 = -.607761895722825260739D-07, b8 &\r\n = .195755836614639731882D-09\r\nREAL (dp), PARAMETER :: p0 = .6116095104481415817861D-08, p1 &\r\n = .6871674113067198736152D-08, p2 = .6820161668496170657, p3 &\r\n = .4686843322948848031080D-10, p4 = .1572833027710446286995D-11, p5 &\r\n = -.1249441572276366213222D-12, p6 = .4343529937408594255178D-14, q1 &\r\n = .3056961078365221025009D+00, q2 = .5464213086042296536016D-01, q3 &\r\n = .4956830093825887312, q4 = .2692369466186361192876D-03\r\nREAL (dp), PARAMETER :: c = -.422784335098467139393487909917598D+00, c0 &\r\n = .577215664901532860606512090082402D+00, c1 &\r\n = -.655878071520253881077019515145390D+00, c2 &\r\n = -.420026350340952355290039348754298D-01, c3 &\r\n = .166538611382291489501700795102105D+00, c4 &\r\n = -.421977345555443367482083012891874D-01, c5 &\r\n = -.962197152787697356211492167234820D-02, c6 &\r\n = .721894324666309954239501034044657D-02, c7 &\r\n = -.116516759185906511211397108401839D-02, c8 &\r\n = -.215241674114950972815729963053648D-03, c9 &\r\n = .128050282388116186153198626328164D-03, c10 &\r\n = -.201348547807882386556893914210218D-04, c11 &\r\n = -.125049348214267065734535947383309D-05, c12 &\r\n = .113302723198169588237412962033074D-05, c13 &\r\n = -.205633841697760710345015413002057D-06\r\n!----------------------------\r\nt = x\r\nd = x - 0.5_dp\r\nIF (d > 0._dp) t = d - 0.5_dp\r\nIF (t < 0.0_dp) THEN\r\n GO TO 30\r\nELSE IF (t > 0.0_dp) THEN\r\n GO TO 20\r\nEND IF\r\n\r\nfn_val = 0._dp\r\nRETURN\r\n!------------\r\n\r\n! CASE WHEN 0 < T <= 0.5\r\n\r\n! W IS A MINIMAX APPROXIMATION FOR\r\n! THE SERIES A(15) + A(16)*T + ...\r\n\r\n!------------\r\n20 w = ((((((p6*t + p5)*t + p4)*t + p3)*t + p2)*t + p1)*t + p0) / &\r\n ((((q4*t+q3)*t + q2)*t + q1)*t + 1._dp)\r\nz = (((((((((((((w*t + c13)*t + c12)*t + c11)*t + c10)*t + c9)*t + c8)*t + c7)*t &\r\n + c6)*t + c5)*t + c4)*t + c3)*t + c2)*t + c1) * t + c0\r\n\r\nIF (d <= 0._dp) THEN\r\n fn_val = x * z\r\n RETURN\r\nEND IF\r\nfn_val = (t/x) * ((z-0.5_dp)-0.5_dp)\r\nRETURN\r\n!------------\r\n\r\n! CASE WHEN -0.5 <= T < 0\r\n\r\n! W IS A MINIMAX APPROXIMATION FOR\r\n! THE SERIES A(15) + A(16)*T + ...\r\n\r\n!------------\r\n30 w = (a1*t + a0) / ((((((((b8*t + b7)*t + b6)*t + b5)*t + b4)*t + b3)*t + b2)*t + b1)*t+1._dp)\r\nz = (((((((((((((w*t + c13)*t + c12)*t + c11)*t + c10)*t + c9)*t + c8)*t + c7)*t &\r\n + c6)*t + c5)*t + c4)*t + c3)*t + c2)*t + c1) * t + c\r\n\r\nIF (d <= 0._dp) THEN\r\n fn_val = x * ((z+0.5_dp)+0.5_dp)\r\n RETURN\r\nEND IF\r\nfn_val = t * z / x\r\nRETURN\r\nEND FUNCTION dgam1\r\n\r\n\r\n\r\nFUNCTION dpdel(x) RESULT(fn_val)\r\n!-----------------------------------------------------------------------\r\n\r\n! COMPUTATION OF THE FUNCTION DEL(X) FOR X >= 10 WHERE\r\n! LN(GAMMA(X)) = (X - 0.5)*LN(X) - X + 0.5*LN(2*PI) + DEL(X)\r\n\r\n! --------\r\n\r\n! THE SERIES FOR DPDEL ON THE INTERVAL 0.0 TO 1.0 DERIVED BY\r\n! A.H. MORRIS FROM THE CHEBYSHEV SERIES IN THE SLATEC LIBRARY\r\n! OBTAINED BY WAYNE FULLERTON (LOS ALAMOS).\r\n\r\n!-----------------------------------------------------------------------\r\nREAL (dp), INTENT(IN) :: x\r\nREAL (dp) :: fn_val\r\n\r\n! Local variables\r\nREAL (dp), PARAMETER :: a(15) = (/ .833333333333333333333333333333D-01, &\r\n -.277777777777777777777777752282D-04, &\r\n .793650793650793650791732130419D-07, &\r\n -.595238095238095232389839236182D-09, &\r\n .841750841750832853294451671990D-11, &\r\n -.191752691751854612334149171243D-12, &\r\n .641025640510325475730918472625D-14, &\r\n -.295506514125338232839867823991D-15, &\r\n .179643716359402238723287696452D-16, &\r\n -.139228964661627791231203060395D-17, &\r\n .133802855014020915603275339093D-18, &\r\n -.154246009867966094273710216533D-19, &\r\n .197701992980957427278370133333D-20, &\r\n -.234065664793997056856992426667D-21, &\r\n .171348014966398575409015466667D-22 /)\r\nREAL (dp) :: t, w\r\nINTEGER :: i, k\r\n!-----------------------------------------------------------------------\r\nt = (10._dp/x) ** 2\r\nw = a(15)\r\nDO i = 1, 14\r\n k = 15 - i\r\n w = t * w + a(k)\r\nEND DO\r\nfn_val = w / x\r\nRETURN\r\nEND FUNCTION dpdel\r\n\r\nEND MODULE Complex_Bessel\r\n", "meta": {"hexsha": "737f656418b95c2e7ccea68063f9cd3e65b24a19", "size": 54847, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/cbsslj.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/cbsslj.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/cbsslj.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": 31.8877906977, "max_line_length": 129, "alphanum_fraction": 0.5374405163, "num_tokens": 21794, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6798592402820806}} {"text": "subroutine atom(sol,k,eval)\nreal, intent(in) :: sol\ninteger, intent(in) :: k(2)\nreal, intent(out) :: eval(2)\nreal t1\n t1=sqrt(dble(k(1)**2)-(sol)**2)\n eval(1)=sol**2/sqrt(t1)-sol**2\nend subroutine\n\n", "meta": {"hexsha": "897e7aded0a3b73631d9a357a662d8d1eff6fb80", "size": 200, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/lto/pr41521_1.f90", "max_stars_repo_name": "brugger1/testsuite", "max_stars_repo_head_hexsha": "9b504db668cdeaf7c561f15b76c95d05bfdd1517", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/lto/pr41521_1.f90", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/lto/pr41521_1.f90", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 20.0, "max_line_length": 33, "alphanum_fraction": 0.635, "num_tokens": 77, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8872045996818986, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6798592401176482}} {"text": "*DECK SPENC\n FUNCTION SPENC (X)\nC***BEGIN PROLOGUE SPENC\nC***PURPOSE Compute a form of Spence's integral due to K. Mitchell.\nC***LIBRARY SLATEC (FNLIB)\nC***CATEGORY C5\nC***TYPE SINGLE PRECISION (SPENC-S, DSPENC-D)\nC***KEYWORDS FNLIB, SPECIAL FUNCTIONS, SPENCE'S INTEGRAL\nC***AUTHOR Fullerton, W., (LANL)\nC***DESCRIPTION\nC\nC Evaluate a form of Spence's function defined by\nC integral from 0 to X of -LOG(1-Y)/Y DY.\nC For ABS(X) .LE. 1, the uniformly convergent expansion\nC SPENC = sum K=1,infinity X**K / K**2 is valid.\nC\nC Spence's function can be used to evaluate much more general integral\nC forms. For example,\nC integral from 0 to Z of LOG(A*X+B)/(C*X+D) DX =\nC LOG(ABS(B-A*D/C))*LOG(ABS(A*(C*X+D)/(A*D-B*C)))/C\nC - SPENC (A*(C*Z+D)/(A*D-B*C)) / C.\nC\nC Ref -- K. Mitchell, Philosophical Magazine, 40, p. 351 (1949).\nC Stegun and Abromowitz, AMS 55, p. 1004.\nC\nC\nC Series for SPEN on the interval 0. to 5.00000D-01\nC with weighted error 6.82E-17\nC log weighted error 16.17\nC significant figures required 15.22\nC decimal places required 16.81\nC\nC***REFERENCES (NONE)\nC***ROUTINES CALLED CSEVL, INITS, R1MACH\nC***REVISION HISTORY (YYMMDD)\nC 780201 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890531 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC***END PROLOGUE SPENC\n DIMENSION SPENCS(19)\n LOGICAL FIRST\n SAVE SPENCS, PI26, NSPENC, XBIG, FIRST\n DATA SPENCS( 1) / .1527365598 892406E0 /\n DATA SPENCS( 2) / .0816965805 8051014E0 /\n DATA SPENCS( 3) / .0058141571 4077873E0 /\n DATA SPENCS( 4) / .0005371619 8145415E0 /\n DATA SPENCS( 5) / .0000572470 4675185E0 /\n DATA SPENCS( 6) / .0000066745 4612164E0 /\n DATA SPENCS( 7) / .0000008276 4673397E0 /\n DATA SPENCS( 8) / .0000001073 3156730E0 /\n DATA SPENCS( 9) / .0000000144 0077294E0 /\n DATA SPENCS(10) / .0000000019 8444202E0 /\n DATA SPENCS(11) / .0000000002 7940058E0 /\n DATA SPENCS(12) / .0000000000 4003991E0 /\n DATA SPENCS(13) / .0000000000 0582346E0 /\n DATA SPENCS(14) / .0000000000 0085767E0 /\n DATA SPENCS(15) / .0000000000 0012768E0 /\n DATA SPENCS(16) / .0000000000 0001918E0 /\n DATA SPENCS(17) / .0000000000 0000290E0 /\n DATA SPENCS(18) / .0000000000 0000044E0 /\n DATA SPENCS(19) / .0000000000 0000006E0 /\n DATA PI26 / 1.644934066 848226E0 /\n DATA FIRST /.TRUE./\nC***FIRST EXECUTABLE STATEMENT SPENC\n IF (FIRST) THEN\n NSPENC = INITS (SPENCS, 19, 0.1*R1MACH(3))\n XBIG = 1.0/R1MACH(3)\n ENDIF\n FIRST = .FALSE.\nC\n IF (X.GT.2.0) GO TO 60\n IF (X.GT.1.0) GO TO 50\n IF (X.GT.0.5) GO TO 40\n IF (X.GE.0.0) GO TO 30\n IF (X.GT.(-1.)) GO TO 20\nC\nC HERE IF X .LE. -1.0\nC\n ALN = LOG(1.0-X)\n SPENC = -PI26 - 0.5*ALN*(2.0*LOG(-X)-ALN)\n IF (X.GT.(-XBIG)) SPENC = SPENC\n 1 + (1.0 + CSEVL (4.0/(1.0-X)-1.0, SPENCS, NSPENC)) / (1.0-X)\n RETURN\nC\nC -1.0 .LT. X .LT. 0.0\nC\n 20 SPENC = -0.5*LOG(1.0-X)**2\n 1 - X*(1.0 + CSEVL (4.0*X/(X-1.0)-1.0, SPENCS, NSPENC)) / (X-1.0)\n RETURN\nC\nC 0.0 .LE. X .LE. 0.5\nC\n 30 SPENC = X*(1.0 + CSEVL (4.0*X-1.0, SPENCS, NSPENC))\n RETURN\nC\nC 0.5 .LT. X .LE. 1.0\nC\n 40 SPENC = PI26\n IF (X.NE.1.0) SPENC = PI26 - LOG(X)*LOG(1.0-X)\n 1 - (1.0-X)*(1.0 + CSEVL (4.0*(1.0-X)-1.0, SPENCS, NSPENC))\n RETURN\nC\nC 1.0 .LT. X .LE. 2.0\nC\n 50 SPENC = PI26 - 0.5*LOG(X)*LOG((X-1.0)**2/X)\n 1 + (X-1.)*(1.0 + CSEVL (4.0*(X-1.)/X-1.0, SPENCS, NSPENC))/X\n RETURN\nC\nC X .GT. 2.0\nC\n 60 SPENC = 2.0*PI26 - 0.5*LOG(X)**2\n IF (X.LT.XBIG) SPENC = SPENC\n 1 - (1.0 + CSEVL (4.0/X-1.0, SPENCS, NSPENC))/X\n RETURN\nC\n END\n", "meta": {"hexsha": "5fc086cfe1c5c7106ff9e60a147244884cf2653b", "size": 4019, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/spenc.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/spenc.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/spenc.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.0593220339, "max_line_length": 71, "alphanum_fraction": 0.5625777557, "num_tokens": 1707, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045817875224, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.67985923587573}} {"text": "program problem56\n use fmzm\n implicit none\n integer :: a,b\n integer :: best,temp\n integer, parameter :: limit=100\n\n best=-1\n do a=1,limit-1\n do b=1,limit-1\n temp=digit_sum(to_im(a)**to_im(b))\n if (temp>best) best=temp\n end do\n end do\n\n print *, best\n\ncontains\n\n function digit_sum(n)\n use fmzm\n implicit none\n type(im), intent(in) :: n\n type(im) :: temp\n integer :: digit_sum\n\n temp=n\n digit_sum=0\n do while(temp>0)\n digit_sum=digit_sum+to_int(mod(temp,to_im(10)))\n temp=temp/to_im(10)\n end do\n \n end function digit_sum\n\nend program problem56\n", "meta": {"hexsha": "c413169580f990a68e2db9d04da493808aea33fa", "size": 665, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "problem56.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": "problem56.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": "problem56.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": 17.972972973, "max_line_length": 54, "alphanum_fraction": 0.5714285714, "num_tokens": 195, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523148, "lm_q2_score": 0.7662936430859598, "lm_q1q2_score": 0.6798592357112985}} {"text": "module mod_blending_functions \n use mod_kinds, only: rk,ik\n use mod_constants, only: ZERO, HALF, ONE, TWO, THREE, FOUR, FIVE, EIGHT, PI\n implicit none\n\n\ncontains\n\n function transition_polynomial_order5(s) result(b)\n real(rk) :: s\n real(rk) :: b\n\n b = 10.0_rk*s**THREE - 15.0_rk*s**FOUR + 6.0_rk*s**FIVE\n\n end function transition_polynomial_order5\n\nend module mod_blending_functions\n", "meta": {"hexsha": "37d20423e8ed723d277dfa6fa702af3d3a955cd9", "size": 424, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/mesh_motion/prescribed_mesh_motion/hpaf_ho_ws/mod_blending_functions.f90", "max_stars_repo_name": "wanglican/ChiDG", "max_stars_repo_head_hexsha": "d3177b87cc2f611e66e26bb51616f9385168f338", "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/mesh_motion/prescribed_mesh_motion/hpaf_ho_ws/mod_blending_functions.f90", "max_issues_repo_name": "haohb/ChiDG", "max_issues_repo_head_hexsha": "d3177b87cc2f611e66e26bb51616f9385168f338", "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/mesh_motion/prescribed_mesh_motion/hpaf_ho_ws/mod_blending_functions.f90", "max_forks_repo_name": "haohb/ChiDG", "max_forks_repo_head_hexsha": "d3177b87cc2f611e66e26bb51616f9385168f338", "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": 23.5555555556, "max_line_length": 80, "alphanum_fraction": 0.6698113208, "num_tokens": 133, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6798375070057815}} {"text": "C *********************************************************\nC * *\nC * TEST NUMBER: 06.01.01/03 *\nC * TEST TITLE : Behavior of rotations *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n \n COMMON /GLOBNU/ CTLHND, ERRSIG, ERRFIL, IERRCT, UNERR,\n 1 TESTCT, IFLERR, PASSSW, ERRSW, MAXLIN,\n 2 CONID, MEMUN, WKID, WTYPE, GLBLUN, INDLUN,\n 3 DUMINT, DUMRL\n INTEGER CTLHND, ERRSIG, ERRFIL, IERRCT, UNERR,\n 1 TESTCT, IFLERR, PASSSW, ERRSW, MAXLIN,\n 2 CONID, MEMUN, WKID, WTYPE, GLBLUN, INDLUN,\n 3 DUMINT(20), ERRIND\n REAL DUMRL(20)\n \n COMMON /GLOBCH/ PIDENT, GLBERR, TSTMSG, FUNCID,\n 1 DUMCH\n CHARACTER PIDENT*40, GLBERR*60, TSTMSG*900, FUNCID*80,\n 1 DUMCH(20)*20\n \n REAL ACT4X4(4,4), EXP4X4(4,4), ROTANG\n REAL ACT3X3(3,3), EXP3X3(3,3)\n LOGICAL TRNSEQ\n \n CALL INITGL ('06.01.01/03')\n \nC open PHIGS\n CALL XPOPPH (ERRFIL, MEMUN)\n CALL SETMSG ('1 2 7', ' should return a correct ' //\n 1 'representation for the transformation to ' //\n 2 'rotate a 3D point counterclockwise around the ' //\n 3 'x-axis by the specified number of radians.')\n \n ROTANG = 5.678\n \nC with rotang returns act4x4 = actual array\n CALL PROX (ROTANG, ERRIND, ACT4X4)\n CALL CHKINQ ('prox', ERRIND)\n \nC Compute exp4x4 = expected array\n CALL EROX (ROTANG, EXP4X4)\n \nC pass if matrices represent same transformation\n CALL IFPF (TRNSEQ(4, ACT4X4, EXP4X4))\n \n CALL SETMSG ('1 2 8', ' should return a correct ' //\n 1 'representation for the transformation to ' //\n 2 'rotate a 3D point counterclockwise around the ' //\n 3 'y-axis by the specified number of radians.')\n \n ROTANG = -0.007373\n \nC with rotang returns act4x4 = actual array\n CALL PROY (ROTANG, ERRIND, ACT4X4)\n CALL CHKINQ ('proy', ERRIND)\n \nC Compute exp4x4 = expected array\n CALL EROY (ROTANG, EXP4X4)\n \nC pass if matrices represent same transformation\n CALL IFPF (TRNSEQ(4, ACT4X4, EXP4X4))\n \n CALL SETMSG ('1 2 9', ' should return a correct ' //\n 1 'representation for the transformation to ' //\n 2 'rotate a 3D point counterclockwise around the ' //\n 3 'z-axis by the specified number of radians.')\n \n ROTANG = 8.52525\n \nC with rotang returns act4x4 = actual array\n CALL PROZ (ROTANG, ERRIND, ACT4X4)\n CALL CHKINQ ('proz', ERRIND)\n \nC Compute exp4x4 = expected array\n CALL EROZ (ROTANG, EXP4X4)\n \nC pass if matrices represent same transformation\n CALL IFPF (TRNSEQ(4, ACT4X4, EXP4X4))\n \n CALL SETMSG ('1 2 10', ' should return a correct ' //\n 1 'representation for the transformation to ' //\n 2 'rotate a 2D point counterclockwise around the ' //\n 3 'origin by the specified number of radians.')\n \n ROTANG = -11.1111\n \nC with rotang returns act3x3 = actual array\n CALL PRO (ROTANG, ERRIND, ACT3X3)\n CALL CHKINQ ('pro', ERRIND)\n \nC Compute exp3x3 = expected array\n CALL ERO (ROTANG, EXP3X3)\n \nC pass if matrices represent same transformation\n CALL IFPF (TRNSEQ(3, ACT3X3, EXP3X3))\n \n CALL ENDIT\n END\n", "meta": {"hexsha": "f9b728e4374d255becfd9772e13c1352a389ca0d", "size": 3782, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "third_party/Phigs/PVT/PVT_fort/06/01/01/p03.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/06/01/01/p03.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/06/01/01/p03.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": 36.7184466019, "max_line_length": 70, "alphanum_fraction": 0.5312004231, "num_tokens": 1138, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6798375023831629}} {"text": "module class_Circle\n\n implicit none\n private\n real :: pi = acos(-1.0d0)\n\n type, public :: Circle\n real :: radius\n contains\n procedure :: area => circle_area\n procedure :: print => circle_print\n end type\n\ncontains\n\n pure function circle_area(this) result(area)\n\n class(Circle), intent(in) :: this\n real :: area\n\n area = pi * this%radius**2\n\n end function\n\n subroutine circle_print(this)\n\n class(Circle), intent(in) :: this\n real:: area\n\n area = this%area()\n print *, 'Circle: r = ', this%radius, ' area = ', area\n\n end subroutine\n\nend module\n", "meta": {"hexsha": "79835e6f31305a9f3850d1d3dfdf4d90d06a9d08", "size": 581, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "chapter-01/recipe-09/fortran-example/geometry_circle.f90", "max_stars_repo_name": "istupsm/cmake-cookbook", "max_stars_repo_head_hexsha": "342d0171802153619ea124c5b8e792ce45178895", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1600, "max_stars_repo_stars_event_min_datetime": "2018-05-24T01:32:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T09:24:11.000Z", "max_issues_repo_path": "chapter-01/recipe-09/fortran-example/geometry_circle.f90", "max_issues_repo_name": "istupsm/cmake-cookbook", "max_issues_repo_head_hexsha": "342d0171802153619ea124c5b8e792ce45178895", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 280, "max_issues_repo_issues_event_min_datetime": "2017-08-27T13:10:51.000Z", "max_issues_repo_issues_event_max_datetime": "2018-05-23T15:09:58.000Z", "max_forks_repo_path": "chapter-01/recipe-09/fortran-example/geometry_circle.f90", "max_forks_repo_name": "istupsm/cmake-cookbook", "max_forks_repo_head_hexsha": "342d0171802153619ea124c5b8e792ce45178895", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 475, "max_forks_repo_forks_event_min_datetime": "2018-05-23T15:26:27.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T07:28:19.000Z", "avg_line_length": 16.1388888889, "max_line_length": 58, "alphanum_fraction": 0.6316695353, "num_tokens": 158, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6798374880999882}} {"text": "subroutine ComputeDm(dllm, lmax, m, theta0, exitstatus)\n!------------------------------------------------------------------------------\n!\n! This routine will compute the kernel D for the space-concentration\n! problem of a spherical cap for a given spherical harmonic order.\n! (When m /= 0, the eigenfunctions will not be isotropic). All terms\n! are computed exactly using Gauss-Legendre quadrature. The eigenfunctions\n! of this kernel are spherical harmonic coefficients normalized according\n! to the \"geodesy\" convention. The diagonal elements of Dllm approaches\n! unity when theta0 appoaches 180 degrees.\n!\n! Calling Parameters\n!\n! IN\n! lmax Maximum spherical harmonic degree.\n! theta0 Angular radius of spherical cap IN RADIANS.\n! m Angular order used in the concentration problem.\n!\n! OUT\n! dllm Symmetric kernel of size lmax+1 by lmax+1.\n!\n! OPTIONAL (OUT)\n! exitstatus If present, instead of executing a STOP when an error\n! is encountered, the variable exitstatus will be\n! returned describing the error.\n! 0 = No errors;\n! 1 = Improper dimensions of input array;\n! 2 = Improper bounds for input variable;\n! 3 = Error allocating memory;\n! 4 = File IO error.\n!\n! Copyright (c) 2016, SHTOOLS\n! All rights reserved.\n!\n!------------------------------------------------------------------------------ \n use SHTOOLS, only: PreGLQ, PlmBar, NGLQ, PlmIndex\n\n implicit none\n\n real*8, intent(out) :: dllm(:,:)\n real*8, intent(in) :: theta0\n integer, intent(in) :: lmax, m\n integer, intent(out), optional :: exitstatus\n real*8 :: upper, zero(2*lmax+1), w(2*lmax+1), x\n real*8, allocatable :: plm(:)\n integer :: l, lp, i, n, astat\n\n if (present(exitstatus)) exitstatus = 0\n\n if (abs(m) > lmax) then\n print*, \"Error --- ComputeDm\"\n print*, \"M must be less than or equal to LMAX.\"\n print*, \"Input values of LMAX and M are\", lmax, m\n if (present(exitstatus)) then\n exitstatus = 2\n return\n else\n stop\n end if\n\n else if (size(dllm(1,:)) < lmax+1 .or. size(dllm(:,1)) < lmax+1) then\n print*, \"Error --- ComputeDm\"\n print*, \"DLLM must be dimensioned as (LMAX+1, LMAX+1) where \" // &\n \"LMAX is \", lmax\n print*, \"Input array is dimensioned as \", size(dllm(1,:)), & \n size(dllm(:,1))\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n end if\n\n allocate (plm( (lmax+1)*(lmax+2)/2 ), stat = astat)\n\n if (astat /= 0) then\n print*, \"Error --- ComputeDM\"\n print*, \"Problem allocating array PLM\", astat\n if (present(exitstatus)) then\n exitstatus = 3\n return\n else\n stop\n end if\n end if\n\n dllm = 0.0d0\n\n n = NGLQ(2*lmax)\n\n upper = 1.0d0\n x = cos(theta0)\n\n if (present(exitstatus)) then\n call PreGLQ(x, upper, n, zero, w, exitstatus = exitstatus)\n if (exitstatus /= 0) return\n else\n call PreGLQ(x, upper, n, zero, w)\n end if\n\n do i = 1, n\n if (present(exitstatus)) then\n call PlmBar(plm, lmax, zero(i), exitstatus = exitstatus)\n if (exitstatus /= 0) return\n else\n call PlmBar(plm, lmax, zero(i))\n end if\n\n do l = abs(m), lmax\n do lp = l, lmax\n dllm(l+1, lp+1) = dllm(l+1,lp+1) + w(i) * &\n plm(PlmIndex(l,abs(m))) * &\n plm(PlmIndex(lp,abs(m)))\n end do\n\n end do\n\n end do\n\n do l = abs(m), lmax\n do lp = l + 1, lmax, 1\n dllm(lp+1,l+1) = dllm(l+1,lp+1)\n end do\n end do\n\n if (m == 0) then\n dllm = dllm / 2.0d0\n else\n dllm = dllm / 4.0d0\n end if\n\n call PlmBar(plm, -1, zero(1)) ! deallocate memory\n\n deallocate (plm)\n\nend subroutine ComputeDm\n", "meta": {"hexsha": "8fef5f51c1bb25a2b20b7b6234fcdacee7f36468", "size": 4193, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/ComputeDm.f95", "max_stars_repo_name": "gaojiawei321/SHTOOLS", "max_stars_repo_head_hexsha": "9a115cf83002df2ddec6b7f41aeb6be688e285de", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-04-06T07:42:49.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-06T07:42:49.000Z", "max_issues_repo_path": "src/ComputeDm.f95", "max_issues_repo_name": "gaojiawei321/SHTOOLS", "max_issues_repo_head_hexsha": "9a115cf83002df2ddec6b7f41aeb6be688e285de", "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/ComputeDm.f95", "max_forks_repo_name": "gaojiawei321/SHTOOLS", "max_forks_repo_head_hexsha": "9a115cf83002df2ddec6b7f41aeb6be688e285de", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.384057971, "max_line_length": 80, "alphanum_fraction": 0.5129978536, "num_tokens": 1183, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480237330998, "lm_q2_score": 0.7401743677704878, "lm_q1q2_score": 0.6798355289761591}} {"text": " SUBROUTINE BB01AD(DEF, NR, DPAR, IPAR, BPAR, CHPAR, VEC, N, M, P,\r\n 1 A, LDA, B, LDB, C, LDC, G, LDG, Q, LDQ, X, LDX,\r\n 2 DWORK, LDWORK, INFO)\r\nC\r\nC SLICOT RELEASE 5.5.\r\nC\r\nC Copyright (c) 2002-2012 NICONET e.V.\r\nC\r\nC PURPOSE\r\nC\r\nC To generate the benchmark examples for the numerical solution of\r\nC continuous-time algebraic Riccati equations (CAREs) of the form\r\nC\r\nC 0 = Q + A'X + XA - XGX\r\nC\r\nC corresponding to the Hamiltonian matrix\r\nC\r\nC ( A G )\r\nC H = ( T ).\r\nC ( Q -A )\r\nC\r\nC A,G,Q,X are real N-by-N matrices, Q and G are symmetric and may\r\nC be given in factored form\r\nC\r\nC -1 T T\r\nC (I) G = B R B , (II) Q = C W C .\r\nC\r\nC Here, C is P-by-N, W P-by-P, B N-by-M, and R M-by-M, where W\r\nC and R are symmetric. In linear-quadratic optimal control problems,\r\nC usually W is positive semidefinite and R positive definite. The\r\nC factorized form can be used if the CARE is solved using the\r\nC deflating subspaces of the extended Hamiltonian pencil\r\nC\r\nC ( A 0 B ) ( I 0 0 )\r\nC ( T ) ( )\r\nC H - s K = ( Q A 0 ) - s ( 0 -I 0 ) ,\r\nC ( T ) ( )\r\nC ( 0 B R ) ( 0 0 0 )\r\nC\r\nC where I and 0 denote the identity and zero matrix, respectively,\r\nC of appropriate dimensions.\r\nC\r\nC NOTE: the formulation of the CARE and the related matrix (pencils)\r\nC used here does not include CAREs as they arise in robust\r\nC control (H_infinity optimization).\r\nC\r\nC ARGUMENTS\r\nC\r\nC Mode Parameters\r\nC\r\nC DEF CHARACTER\r\nC This parameter specifies if the default parameters are\r\nC to be used or not.\r\nC = 'N' or 'n' : The parameters given in the input vectors\r\nC xPAR (x = 'D', 'I', 'B', 'CH') are used.\r\nC = 'D' or 'd' : The default parameters for the example\r\nC are used.\r\nC This parameter is not meaningful if NR(1) = 1.\r\nC\r\nC Input/Output Parameters\r\nC\r\nC NR (input) INTEGER array, dimension (2)\r\nC This array determines the example for which CAREX returns\r\nC data. NR(1) is the group of examples.\r\nC NR(1) = 1 : parameter-free problems of fixed size.\r\nC NR(1) = 2 : parameter-dependent problems of fixed size.\r\nC NR(1) = 3 : parameter-free problems of scalable size.\r\nC NR(1) = 4 : parameter-dependent problems of scalable size.\r\nC NR(2) is the number of the example in group NR(1).\r\nC Let NEXi be the number of examples in group i. Currently,\r\nC NEX1 = 6, NEX2 = 9, NEX3 = 2, NEX4 = 4.\r\nC 1 <= NR(1) <= 4;\r\nC 1 <= NR(2) <= NEXi , where i = NR(1).\r\nC\r\nC DPAR (input/output) DOUBLE PRECISION array, dimension (7)\r\nC Double precision parameter vector. For explanation of the\r\nC parameters see [1].\r\nC DPAR(1) : defines the parameters\r\nC 'delta' for NR(1) = 3,\r\nC 'q' for NR(1).NR(2) = 4.1,\r\nC 'a' for NR(1).NR(2) = 4.2, and\r\nC 'mu' for NR(1).NR(2) = 4.3.\r\nC DPAR(2) : defines parameters\r\nC 'r' for NR(1).NR(2) = 4.1,\r\nC 'b' for NR(1).NR(2) = 4.2, and\r\nC 'delta' for NR(1).NR(2) = 4.3.\r\nC DPAR(3) : defines parameters\r\nC 'c' for NR(1).NR(2) = 4.2 and\r\nC 'kappa' for NR(1).NR(2) = 4.3.\r\nC DPAR(j), j=4,5,6,7: These arguments are only used to\r\nC generate Example 4.2 and define in\r\nC consecutive order the intervals\r\nC ['beta_1', 'beta_2'],\r\nC ['gamma_1', 'gamma_2'].\r\nC NOTE that if DEF = 'D' or 'd', the values of DPAR entries\r\nC on input are ignored and, on output, they are overwritten\r\nC with the default parameters.\r\nC\r\nC IPAR (input/output) INTEGER array, dimension (3)\r\nC On input, IPAR(1) determines the actual state dimension,\r\nC i.e., the order of the matrix A as follows, where\r\nC NO = NR(1).NR(2).\r\nC NR(1) = 1 or 2.1-2.8: IPAR(1) is ignored.\r\nC NO = 2.9 : IPAR(1) = 1 generates the CARE for\r\nC optimal state feedback (default);\r\nC IPAR(1) = 2 generates the Kalman\r\nC filter CARE.\r\nC NO = 3.1 : IPAR(1) is the number of vehicles\r\nC (parameter 'l' in the description\r\nC in [1]).\r\nC NO = 3.2, 4.1 or 4.2: IPAR(1) is the order of the matrix\r\nC A.\r\nC NO = 4.3 or 4.4 : IPAR(1) determines the dimension of\r\nC the second-order system, i.e., the\r\nC order of the stiffness matrix for\r\nC Examples 4.3 and 4.4 (parameter 'l'\r\nC in the description in [1]).\r\nC\r\nC The order of the output matrix A is N = 2*IPAR(1) for\r\nC Example 4.3 and N = 2*IPAR(1)-1 for Examples 3.1 and 4.4.\r\nC NOTE that IPAR(1) is overwritten for Examples 1.1-2.8. For\r\nC the other examples, IPAR(1) is overwritten if the default\r\nC parameters are to be used.\r\nC On output, IPAR(1) contains the order of the matrix A.\r\nC\r\nC On input, IPAR(2) is the number of colums in the matrix B\r\nC in (I) (in control problems, the number of inputs of the\r\nC system). Currently, IPAR(2) is fixed or determined by\r\nC IPAR(1) for all examples and thus is not referenced on\r\nC input.\r\nC On output, IPAR(2) is the number of columns of the\r\nC matrix B from (I).\r\nC NOTE that currently IPAR(2) is overwritten and that\r\nC rank(G) <= IPAR(2).\r\nC\r\nC On input, IPAR(3) is the number of rows in the matrix C\r\nC in (II) (in control problems, the number of outputs of the\r\nC system). Currently, IPAR(3) is fixed or determined by\r\nC IPAR(1) for all examples and thus is not referenced on\r\nC input.\r\nC On output, IPAR(3) contains the number of rows of the\r\nC matrix C in (II).\r\nC NOTE that currently IPAR(3) is overwritten and that\r\nC rank(Q) <= IPAR(3).\r\nC\r\nC BPAR (input) BOOLEAN array, dimension (6)\r\nC This array defines the form of the output of the examples\r\nC and the storage mode of the matrices G and Q.\r\nC BPAR(1) = .TRUE. : G is returned.\r\nC BPAR(1) = .FALSE. : G is returned in factored form, i.e.,\r\nC B and R from (I) are returned.\r\nC BPAR(2) = .TRUE. : The matrix returned in array G (i.e.,\r\nC G if BPAR(1) = .TRUE. and R if\r\nC BPAR(1) = .FALSE.) is stored as full\r\nC matrix.\r\nC BPAR(2) = .FALSE. : The matrix returned in array G is\r\nC provided in packed storage mode.\r\nC BPAR(3) = .TRUE. : If BPAR(2) = .FALSE., the matrix\r\nC returned in array G is stored in upper\r\nC packed mode, i.e., the upper triangle\r\nC of a symmetric n-by-n matrix is stored\r\nC by columns, e.g., the matrix entry\r\nC G(i,j) is stored in the array entry\r\nC G(i+j*(j-1)/2) for i <= j.\r\nC Otherwise, this entry is ignored.\r\nC BPAR(3) = .FALSE. : If BPAR(2) = .FALSE., the matrix\r\nC returned in array G is stored in lower\r\nC packed mode, i.e., the lower triangle\r\nC of a symmetric n-by-n matrix is stored\r\nC by columns, e.g., the matrix entry\r\nC G(i,j) is stored in the array entry\r\nC G(i+(2*n-j)*(j-1)/2) for j <= i.\r\nC Otherwise, this entry is ignored.\r\nC BPAR(4) = .TRUE. : Q is returned.\r\nC BPAR(4) = .FALSE. : Q is returned in factored form, i.e.,\r\nC C and W from (II) are returned.\r\nC BPAR(5) = .TRUE. : The matrix returned in array Q (i.e.,\r\nC Q if BPAR(4) = .TRUE. and W if\r\nC BPAR(4) = .FALSE.) is stored as full\r\nC matrix.\r\nC BPAR(5) = .FALSE. : The matrix returned in array Q is\r\nC provided in packed storage mode.\r\nC BPAR(6) = .TRUE. : If BPAR(5) = .FALSE., the matrix\r\nC returned in array Q is stored in upper\r\nC packed mode (see above).\r\nC Otherwise, this entry is ignored.\r\nC BPAR(6) = .FALSE. : If BPAR(5) = .FALSE., the matrix\r\nC returned in array Q is stored in lower\r\nC packed mode (see above).\r\nC Otherwise, this entry is ignored.\r\nC NOTE that there are no default values for BPAR. If all\r\nC entries are declared to be .TRUE., then matrices G and Q\r\nC are returned in conventional storage mode, i.e., as\r\nC N-by-N arrays where the array element Z(I,J) contains the\r\nC matrix entry Z_{i,j}.\r\nC\r\nC CHPAR (input/output) CHARACTER*255\r\nC On input, this is the name of a data file supplied by the\r\nC user.\r\nC In the current version, only Example 4.4 allows a\r\nC user-defined data file. This file must contain\r\nC consecutively DOUBLE PRECISION vectors mu, delta, gamma,\r\nC and kappa. The length of these vectors is determined by\r\nC the input value for IPAR(1).\r\nC If on entry, IPAR(1) = L, then mu and delta must each\r\nC contain L DOUBLE PRECISION values, and gamma and kappa\r\nC must each contain L-1 DOUBLE PRECISION values.\r\nC On output, this string contains short information about\r\nC the chosen example.\r\nC\r\nC VEC (output) LOGICAL array, dimension (9)\r\nC Flag vector which displays the availability of the output\r\nC data:\r\nC VEC(j), j=1,2,3, refer to N, M, and P, respectively, and\r\nC are always .TRUE.\r\nC VEC(4) refers to A and is always .TRUE.\r\nC VEC(5) is .TRUE. if BPAR(1) = .FALSE., i.e., the factors B\r\nC and R from (I) are returned.\r\nC VEC(6) is .TRUE. if BPAR(4) = .FALSE., i.e., the factors C\r\nC and W from (II) are returned.\r\nC VEC(7) refers to G and is always .TRUE.\r\nC VEC(8) refers to Q and is always .TRUE.\r\nC VEC(9) refers to X and is .TRUE. if the exact solution\r\nC matrix is available.\r\nC NOTE that VEC(i) = .FALSE. for i = 1 to 9 if on exit\r\nC INFO .NE. 0.\r\nC\r\nC N (output) INTEGER\r\nC The order of the matrices A, X, G if BPAR(1) = .TRUE., and\r\nC Q if BPAR(4) = .TRUE.\r\nC\r\nC M (output) INTEGER\r\nC The number of columns in the matrix B (or the dimension of\r\nC the control input space of the underlying dynamical\r\nC system).\r\nC\r\nC P (output) INTEGER\r\nC The number of rows in the matrix C (or the dimension of\r\nC the output space of the underlying dynamical system).\r\nC\r\nC A (output) DOUBLE PRECISION array, dimension (LDA,N)\r\nC The leading N-by-N part of this array contains the\r\nC coefficient matrix A of the CARE.\r\nC\r\nC LDA INTEGER\r\nC The leading dimension of array A. LDA >= N.\r\nC\r\nC B (output) DOUBLE PRECISION array, dimension (LDB,M)\r\nC If (BPAR(1) = .FALSE.), then the leading N-by-M part of\r\nC this array contains the matrix B of the factored form (I)\r\nC of G. Otherwise, B is used as workspace.\r\nC\r\nC LDB INTEGER\r\nC The leading dimension of array B. LDB >= N.\r\nC\r\nC C (output) DOUBLE PRECISION array, dimension (LDC,N)\r\nC If (BPAR(4) = .FALSE.), then the leading P-by-N part of\r\nC this array contains the matrix C of the factored form (II)\r\nC of Q. Otherwise, C is used as workspace.\r\nC\r\nC LDC INTEGER\r\nC The leading dimension of array C.\r\nC LDC >= P, where P is the number of rows of the matrix C,\r\nC i.e., the output value of IPAR(3). (For all examples,\r\nC P <= N, where N equals the output value of the argument\r\nC IPAR(1), i.e., LDC >= LDA is always safe.)\r\nC\r\nC G (output) DOUBLE PRECISION array, dimension (NG)\r\nC If (BPAR(2) = .TRUE.) then NG = LDG*N.\r\nC If (BPAR(2) = .FALSE.) then NG = N*(N+1)/2.\r\nC If (BPAR(1) = .TRUE.), then array G contains the\r\nC coefficient matrix G of the CARE.\r\nC If (BPAR(1) = .FALSE.), then array G contains the 'control\r\nC weighting matrix' R of G's factored form as in (I). (For\r\nC all examples, M <= N.) The symmetric matrix contained in\r\nC array G is stored according to BPAR(2) and BPAR(3).\r\nC\r\nC LDG INTEGER\r\nC If conventional storage mode is used for G, i.e.,\r\nC BPAR(2) = .TRUE., then G is stored like a 2-dimensional\r\nC array with leading dimension LDG. If packed symmetric\r\nC storage mode is used, then LDG is not referenced.\r\nC LDG >= N if BPAR(2) = .TRUE..\r\nC\r\nC Q (output) DOUBLE PRECISION array, dimension (NQ)\r\nC If (BPAR(5) = .TRUE.) then NQ = LDQ*N.\r\nC If (BPAR(5) = .FALSE.) then NQ = N*(N+1)/2.\r\nC If (BPAR(4) = .TRUE.), then array Q contains the\r\nC coefficient matrix Q of the CARE.\r\nC If (BPAR(4) = .FALSE.), then array Q contains the 'output\r\nC weighting matrix' W of Q's factored form as in (II).\r\nC The symmetric matrix contained in array Q is stored\r\nC according to BPAR(5) and BPAR(6).\r\nC\r\nC LDQ INTEGER\r\nC If conventional storage mode is used for Q, i.e.,\r\nC BPAR(5) = .TRUE., then Q is stored like a 2-dimensional\r\nC array with leading dimension LDQ. If packed symmetric\r\nC storage mode is used, then LDQ is not referenced.\r\nC LDQ >= N if BPAR(5) = .TRUE..\r\nC\r\nC X (output) DOUBLE PRECISION array, dimension (LDX,IPAR(1))\r\nC If an exact solution is available (NR = 1.1, 1.2, 2.1,\r\nC 2.3-2.6, 3.2), then the leading N-by-N part of this array\r\nC contains the solution matrix X in conventional storage\r\nC mode. Otherwise, X is not referenced.\r\nC\r\nC LDX INTEGER\r\nC The leading dimension of array X. LDX >= 1, and\r\nC LDX >= N if NR = 1.1, 1.2, 2.1, 2.3-2.6, 3.2.\r\nC\r\nC Workspace\r\nC\r\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\r\nC\r\nC LDWORK INTEGER\r\nC The length of the array DWORK.\r\nC LDWORK >= N*MAX(4,N).\r\nC\r\nC Error Indicator\r\nC\r\nC INFO INTEGER\r\nC = 0 : successful exit;\r\nC < 0 : if INFO = -i, the i-th argument had an illegal\r\nC value;\r\nC = 1 : data file could not be opened or had wrong format;\r\nC = 2 : division by zero;\r\nC = 3 : G can not be computed as in (I) due to a singular R\r\nC matrix.\r\nC\r\nC REFERENCES\r\nC\r\nC [1] Abels, J. and Benner, P.\r\nC CAREX - A Collection of Benchmark Examples for Continuous-Time\r\nC Algebraic Riccati Equations (Version 2.0).\r\nC SLICOT Working Note 1999-14, November 1999. Available from\r\nC http://www.win.tue.nl/niconet/NIC2/reports.html.\r\nC\r\nC This is an updated and extended version of\r\nC\r\nC [2] Benner, P., Laub, A.J., and Mehrmann, V.\r\nC A Collection of Benchmark Examples for the Numerical Solution\r\nC of Algebraic Riccati Equations I: Continuous-Time Case.\r\nC Technical Report SPC 95_22, Fak. f. Mathematik,\r\nC TU Chemnitz-Zwickau (Germany), October 1995.\r\nC\r\nC NUMERICAL ASPECTS\r\nC\r\nC If the original data as taken from the literature is given via\r\nC matrices G and Q, but factored forms are requested as output, then\r\nC these factors are obtained from Cholesky or LDL' decompositions of\r\nC G and Q, i.e., the output data will be corrupted by roundoff\r\nC errors.\r\nC\r\nC FURTHER COMMENTS\r\nC\r\nC Some benchmark examples read data from the data files provided\r\nC with the collection.\r\nC\r\nC CONTRIBUTOR\r\nC\r\nC Peter Benner (Universitaet Bremen), November 15, 1999.\r\nC\r\nC For questions concerning the collection or for the submission of\r\nC test examples, please send e-mail to benner@math.uni-bremen.de.\r\nC\r\nC REVISIONS\r\nC\r\nC 1999, December 23 (V. Sima).\r\nC\r\nC KEYWORDS\r\nC\r\nC Algebraic Riccati equation, Hamiltonian matrix.\r\nC\r\nC ******************************************************************\r\nC\r\nC .. Parameters ..\r\nC . # of examples available , # of examples with fixed size. .\r\n INTEGER NEX1, NEX2, NEX3, NEX4, NMAX\r\n PARAMETER ( NMAX = 9, NEX1 = 6, NEX2 = 9, NEX3 = 2,\r\n 1 NEX4 = 4 )\r\n DOUBLE PRECISION ZERO, ONE, TWO, THREE, FOUR, PI\r\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0, TWO = 2.0D0,\r\n 1 THREE = 3.0D0, FOUR = 4.0D0,\r\n 2 PI = .3141592653589793D1 )\r\nC\r\nC .. Scalar Arguments ..\r\n INTEGER INFO, LDA, LDB, LDC, LDG, LDQ, LDWORK, LDX, M, N,\r\n $ P\r\n CHARACTER DEF\r\nC\r\nC .. Array Arguments ..\r\n INTEGER IPAR(3), NR(2)\r\n DOUBLE PRECISION A(LDA,*), B(LDB,*), C(LDC,*), DPAR(*), DWORK(*),\r\n 1 G(*), Q(*), X(LDX,*)\r\n CHARACTER CHPAR*255\r\n LOGICAL BPAR(6), VEC(9)\r\nC\r\nC .. Local Scalars ..\r\n INTEGER GDIMM, I, IOS, ISYMM, J, K, L, MSYMM, NSYMM, POS,\r\n 1 PSYMM, QDIMM\r\n DOUBLE PRECISION APPIND, B1, B2, C1, C2, SUM, TEMP, TTEMP\r\nC\r\nC ..Local Arrays ..\r\n INTEGER MDEF(2,NMAX), NDEF(4,NMAX), NEX(4), PDEF(2,NMAX)\r\n DOUBLE PRECISION PARDEF(4,NMAX)\r\n CHARACTER IDENT*4\r\n CHARACTER*255 NOTES(4,NMAX)\r\nC\r\nC .. External Functions ..\r\nC . BLAS .\r\n DOUBLE PRECISION DDOT\r\n EXTERNAL DDOT\r\nC . LAPACK .\r\n LOGICAL LSAME\r\n DOUBLE PRECISION DLAPY2\r\n EXTERNAL LSAME, DLAPY2\r\nC\r\nC .. External Subroutines ..\r\nC . BLAS .\r\n EXTERNAL DCOPY, DGEMV, DSCAL, DSPMV, DSPR, DSYMM, DSYRK\r\nC . LAPACK .\r\n EXTERNAL DLASET, DPPTRF, DPPTRI, DPTTRF, DPTTRS, XERBLA\r\nC . SLICOT .\r\n EXTERNAL MA02DD, MA02ED\r\nC\r\nC .. Intrinsic Functions ..\r\n INTRINSIC COS, MAX, MIN, MOD, SQRT\r\nC\r\nC .. Data Statements ..\r\nC . default values for dimensions .\r\n DATA (NEX(I), I = 1, 4) /NEX1, NEX2, NEX3, NEX4/\r\n DATA (NDEF(1,I), I = 1, NEX1) /2, 2, 4, 8, 9, 30/\r\n DATA (NDEF(2,I), I = 1, NEX2) /2, 2, 2, 2, 2, 3, 4, 4, 55/\r\n DATA (NDEF(3,I), I = 1, NEX3) /20, 64/\r\n DATA (NDEF(4,I), I = 1, NEX4) /21, 100, 30, 211/\r\n DATA (MDEF(1,I), I = 1, NEX1) /1, 1, 2, 2, 3, 3/\r\n DATA (MDEF(2,I), I = 1, NEX2) /1, 2, 1, 2, 1, 3, 1, 1, 2/\r\n DATA (PDEF(1,I), I = 1, NEX1) /2, 2, 4, 8, 9, 5/\r\n DATA (PDEF(2,I), I = 1, NEX2) /1, 1, 2, 2, 2, 3, 2, 1, 10/\r\nC . default values for parameters .\r\n DATA (PARDEF(1,I), I = 1, NEX1) /ZERO, ZERO, ZERO, ZERO, ZERO,\r\n 1 ZERO/\r\n DATA (PARDEF(2,I), I = 1, NEX2) /.1D-5, .1D-7, .1D7, .1D-6, ZERO,\r\n 1 .1D7, .1D-5, .1D-5, .1D1/\r\n DATA (PARDEF(3,I), I = 1, NEX3) /ZERO, ZERO/\r\n DATA (PARDEF(4,I), I = 1, NEX4) /ONE, .1D-1, FOUR, ZERO/\r\nC . comments on examples .\r\n DATA (NOTES(1,I), I = 1, NEX1) /\r\n 1'Laub 1979, Ex.1', 'Laub 1979, Ex.2: uncontrollable-unobservable d\r\n 2ata', 'Beale/Shafai 1989: model of L-1011 aircraft', 'Bhattacharyy\r\n 3a et al. 1983: binary distillation column', 'Patnaik et al. 1980:\r\n 4tubular ammonia reactor', 'Davison/Gesing 1978: J-100 jet engine'/\r\n DATA (NOTES(2,I), I = 1, NEX2) /\r\n 1'Arnold/Laub 1984, Ex.1: (A,B) unstabilizable as EPS -> 0', 'Arnol\r\n 2d/Laub 1984, Ex.3: control weighting matrix singular as EPS -> 0',\r\n 3'Kenney/Laub/Wette 1989, Ex.2: ARE ill conditioned for EPS -> oo',\r\n 4'Bai/Qian 1994: ill-conditioned Hamiltonian for EPS -> 0', 'Laub 1\r\n 5992: H-infinity problem, eigenvalues +/- EPS +/- i', 'Petkov et a\r\n 6l. 1987: increasingly badly scaled Hamiltonian as EPS -> oo', 'Cho\r\n 7w/Kokotovic 1976: magnetic tape control system', 'Arnold/Laub 1984\r\n 8, Ex.2: poor sep. of closed-loop spectrum as EPS -> 0', 'IFAC Benc\r\n 9hmark Problem #90-06: LQG design for modified Boing B-767 at flutt\r\n 1er condition'/\r\n DATA (NOTES(3,I), I = 1, NEX3) /\r\n 1'Laub 1979, Ex.4: string of high speed vehicles', 'Laub 1979, Ex.5\r\n 2: circulant matrices'/\r\n DATA (NOTES(4,I), I = 1, NEX4) /\r\n 1'Laub 1979, Ex.6: ill-conditioned Riccati equation', 'Rosen/Wang 1\r\n 2992: lq control of 1-dimensional heat flow','Hench et al. 1995: co\r\n 3upled springs, dashpots and masses','Lang/Penzl 1994: rotating axl\r\n 4e' /\r\nC\r\nC .. Executable Statements ..\r\nC\r\n INFO = 0\r\n DO 5 I = 1, 9\r\n VEC(I) = .FALSE.\r\n 5 CONTINUE\r\nC\r\n IF ((NR(1) .NE. 1) .AND. (.NOT. (LSAME(DEF,'N')\r\n 1 .OR. LSAME(DEF,'D')))) THEN\r\n INFO = -1\r\n ELSE IF ((NR(1) .LT. 1) .OR. (NR(2) .LT. 1) .OR.\r\n 1 (NR(1) .GT. 4) .OR. (NR(2) .GT. NEX(NR(1)))) THEN\r\n INFO = -2\r\n ELSE IF (NR(1) .GT. 2) THEN\r\n IF (.NOT. LSAME(DEF,'N')) IPAR(1) = NDEF(NR(1),NR(2))\r\n IF (NR(1) .EQ. 3) THEN\r\n IF (NR(2) .EQ. 1) THEN\r\n IPAR(2) = IPAR(1)\r\n IPAR(3) = IPAR(1) - 1\r\n IPAR(1) = 2*IPAR(1) - 1\r\n ELSE IF (NR(2) .EQ. 2) THEN\r\n IPAR(2) = IPAR(1)\r\n IPAR(3) = IPAR(1)\r\n ELSE\r\n IPAR(2) = 1\r\n IPAR(3) = 1\r\n END IF\r\n ELSE IF (NR(1) .EQ. 4) THEN\r\n IF (NR(2) .EQ. 3) THEN\r\n L = IPAR(1)\r\n IPAR(2) = 2\r\n IPAR(3) = 2*L\r\n IPAR(1) = 2*L\r\n ELSE IF (NR(2) .EQ. 4) THEN\r\n L = IPAR(1)\r\n IPAR(2) = L\r\n IPAR(3) = L\r\n IPAR(1) = 2*L-1\r\n ELSE\r\n IPAR(2) = 1\r\n IPAR(3) = 1\r\n END IF\r\n END IF\r\n ELSE IF ((NR(1) .EQ. 2) .AND. (NR(2) .EQ. 9) .AND.\r\n 1 (IPAR(1) . EQ. 2)) THEN\r\n IPAR(1) = NDEF(NR(1),NR(2))\r\n IPAR(2) = MDEF(NR(1),NR(2))\r\n IPAR(3) = 3\r\n ELSE\r\n IPAR(1) = NDEF(NR(1),NR(2))\r\n IPAR(2) = MDEF(NR(1),NR(2))\r\n IPAR(3) = PDEF(NR(1),NR(2))\r\n END IF\r\n IF (INFO .NE. 0) GOTO 7\r\nC\r\n IF (IPAR(1) .LT. 1) THEN\r\n INFO = -4\r\n ELSE IF (IPAR(1) .GT. LDA) THEN\r\n INFO = -12\r\n ELSE IF (IPAR(1) .GT. LDB) THEN\r\n INFO = -14\r\n ELSE IF (IPAR(3) .GT. LDC) THEN\r\n INFO = -16\r\n ELSE IF (BPAR(2) .AND. (IPAR(1).GT. LDG)) THEN\r\n INFO = -18\r\n ELSE IF (BPAR(5) .AND. (IPAR(1).GT. LDQ)) THEN\r\n INFO = -20\r\n ELSE IF (LDX.LT.1) THEN\r\n INFO = -22\r\n ELSE IF ((NR(1) .EQ. 1) .AND.\r\n $ ((NR(2) .EQ. 1) .OR. (NR(2) .EQ.2))) THEN\r\n IF (IPAR(1) .GT. LDX) INFO = -22\r\n ELSE IF ((NR(1) .EQ. 2) .AND. (NR(2) .EQ. 1)) THEN\r\n IF (IPAR(1) .GT. LDX) INFO = -22\r\n ELSE IF ((NR(1) .EQ. 2) .AND. ((NR(2) .GE. 3) .AND.\r\n 1 (NR(2) .LE. 6))) THEN\r\n IF (IPAR(1) .GT. LDX) INFO = -22\r\n ELSE IF ((NR(1) .EQ. 3) .AND. (NR(2) .EQ. 2)) THEN\r\n IF (IPAR(1) .GT. LDX) INFO = -22\r\n ELSE IF (LDWORK .LT. N*(MAX(4,N))) THEN\r\n INFO = -24\r\n END IF\r\nC\r\n 7 CONTINUE\r\n IF (INFO .NE. 0) THEN\r\n CALL XERBLA( 'BB01AD', -INFO )\r\n RETURN\r\n END IF\r\nC\r\n NSYMM = (IPAR(1)*(IPAR(1)+1))/2\r\n MSYMM = (IPAR(2)*(IPAR(2)+1))/2\r\n PSYMM = (IPAR(3)*(IPAR(3)+1))/2\r\n IF (.NOT. LSAME(DEF,'N')) DPAR(1) = PARDEF(NR(1),NR(2))\r\nC\r\n CALL DLASET('A', IPAR(1), IPAR(1), ZERO, ZERO, A, LDA)\r\n CALL DLASET('A', IPAR(1), IPAR(2), ZERO, ZERO, B, LDB)\r\n CALL DLASET('A', IPAR(3), IPAR(1), ZERO, ZERO, C, LDC)\r\n CALL DLASET('L', MSYMM, 1, ZERO, ZERO, G, 1)\r\n CALL DLASET('L', PSYMM, 1, ZERO, ZERO, Q, 1)\r\nC\r\n IF (NR(1) .EQ. 1) THEN\r\n IF (NR(2) .EQ. 1) THEN\r\n A(1,2) = ONE\r\n B(2,1) = ONE\r\n Q(1) = ONE\r\n Q(3) = TWO\r\n IDENT = '0101'\r\n CALL DLASET('A', IPAR(1), IPAR(1), ONE, TWO, X, LDX)\r\nC\r\n ELSE IF (NR(2) .EQ. 2) THEN\r\n A(1,1) = FOUR\r\n A(2,1) = -.45D1\r\n A(1,2) = THREE\r\n A(2,2) = -.35D1\r\n CALL DLASET('A', IPAR(1), IPAR(2), -ONE, ONE, B, LDB)\r\n Q(1) = 9.0D0\r\n Q(2) = 6.0D0\r\n Q(3) = FOUR\r\n IDENT = '0101'\r\n TEMP = ONE + SQRT(TWO)\r\n CALL DLASET('A', IPAR(1), IPAR(1), 6.0D0*TEMP, FOUR*TEMP, X,\r\n 1 LDX)\r\n X(1,1) = 9.0D0*TEMP\r\nC\r\n ELSE IF ((NR(2) .GE. 3) .AND. (NR(2) .LE. 6)) THEN\r\n WRITE (CHPAR(1:11), '(A,I1,A,I1,A)') 'BB01', NR(1), '0',\r\n 1 NR(2) , '.dat'\r\n IF ((NR(2) .EQ. 3) .OR. (NR(2) .EQ. 4)) THEN\r\n IDENT = '0101'\r\n ELSE IF (NR(2) .EQ. 5) THEN\r\n IDENT = '0111'\r\n ELSE IF (NR(2) .EQ. 6) THEN\r\n IDENT = '0011'\r\n END IF\r\n OPEN(1, IOSTAT = IOS, STATUS = 'OLD', FILE = CHPAR(1:11))\r\n IF (IOS .NE. 0) THEN\r\n INFO = 1\r\n ELSE IF (NR(2) .LE. 6) THEN\r\n DO 10 I = 1, IPAR(1)\r\n READ (1, FMT = *, IOSTAT = IOS)\r\n 1 (A(I,J), J = 1, IPAR(1))\r\n IF (IOS .NE. 0) INFO = 1\r\n 10 CONTINUE\r\n DO 20 I = 1, IPAR(1)\r\n READ (1, FMT = *, IOSTAT = IOS)\r\n 1 (B(I,J), J = 1, IPAR(2))\r\n IF (IOS .NE. 0) INFO = 1\r\n 20 CONTINUE\r\n IF (NR(2) .LE. 4) THEN\r\n DO 30 I = 1, IPAR(1)\r\n POS = (I-1)*IPAR(1)\r\n READ (1, FMT = *, IOSTAT = IOS) (DWORK(POS+J),\r\n 1 J = 1,IPAR(1))\r\n 30 CONTINUE\r\n IF (IOS .NE. 0) THEN\r\n INFO = 1\r\n ELSE\r\n CALL MA02DD('Pack', 'Lower', IPAR(1), DWORK, IPAR(1), Q)\r\n END IF\r\n ELSE IF (NR(2) .EQ. 6) THEN\r\n DO 35 I = 1, IPAR(3)\r\n READ (1, FMT = *, IOSTAT = IOS)\r\n 1 (C(I,J), J = 1, IPAR(1))\r\n IF (IOS .NE. 0) INFO = 1\r\n 35 CONTINUE\r\n END IF\r\n CLOSE(1)\r\n END IF\r\n END IF\r\nC\r\n ELSE IF (NR(1) .EQ. 2) THEN\r\n IF (NR(2) .EQ. 1) THEN\r\n A(1,1) = ONE\r\n A(2,2) = -TWO\r\n B(1,1) = DPAR(1)\r\n CALL DLASET('U', IPAR(3), IPAR(1), ONE, ONE, C, LDC)\r\n IDENT = '0011'\r\n IF (DPAR(1) .NE. ZERO) THEN\r\n TEMP = DLAPY2(ONE, DPAR(1))\r\n X(1,1) = (ONE + TEMP)/DPAR(1)/DPAR(1)\r\n X(2,1) = ONE/(TWO + TEMP)\r\n X(1,2) = X(2,1)\r\n TTEMP = DPAR(1)*X(1,2)\r\n TEMP = (ONE - TTEMP) * (ONE + TTEMP)\r\n X(2,2) = TEMP / FOUR\r\n ELSE\r\n INFO = 2\r\n END IF\r\nC\r\n ELSE IF (NR(2) .EQ. 2) THEN\r\n A(1,1) = -.1D0\r\n A(2,2) = -.2D-1\r\n B(1,1) = .1D0\r\n B(2,1) = .1D-2\r\n B(2,2) = .1D-1\r\n CALL DLASET('L', MSYMM, 1, ONE, ONE, G, MSYMM)\r\n G(1) = G(1) + DPAR(1)\r\n C(1,1) = .1D2\r\n C(1,2) = .1D3\r\n IDENT = '0010'\r\nC\r\n ELSE IF (NR(2) .EQ. 3) THEN\r\n A(1,2) = DPAR(1)\r\n B(2,1) = ONE\r\n IDENT = '0111'\r\n IF (DPAR(1) .NE. ZERO) THEN\r\n TEMP = SQRT(ONE + TWO*DPAR(1))\r\n CALL DLASET('A', IPAR(1), IPAR(1), ONE, TEMP, X, LDX)\r\n X(1,1) = X(1,1)/DPAR(1)\r\n ELSE\r\n INFO = 2\r\n END IF\r\nC\r\n ELSE IF (NR(2) .EQ. 4) THEN\r\n TEMP = DPAR(1) + ONE\r\n CALL DLASET('A', IPAR(1), IPAR(1), ONE, TEMP, A, LDA)\r\n Q(1) = DPAR(1)**2\r\n Q(3) = Q(1)\r\n IDENT = '1101'\r\n X(1,1) = TWO*TEMP + SQRT(TWO)*(SQRT(TEMP**2 + ONE) + DPAR(1))\r\n X(1,1) = X(1,1)/TWO\r\n X(2,2) = X(1,1)\r\n TTEMP = X(1,1) - TEMP\r\n IF (TTEMP .NE. ZERO) THEN\r\n X(2,1) = X(1,1) / TTEMP\r\n X(1,2) = X(2,1)\r\n ELSE\r\n INFO = 2\r\n END IF\r\nC\r\n ELSE IF (NR(2) .EQ. 5) THEN\r\n A(1,1) = THREE - DPAR(1)\r\n A(2,1) = FOUR\r\n A(1,2) = ONE\r\n A(2,2) = TWO - DPAR(1)\r\n CALL DLASET('L', IPAR(1), IPAR(2), ONE, ONE, B, LDB)\r\n Q(1) = FOUR*DPAR(1) - 11.0D0\r\n Q(2) = TWO*DPAR(1) - 5.0D0\r\n Q(3) = TWO*DPAR(1) - TWO\r\n IDENT = '0101'\r\n CALL DLASET('A', IPAR(1), IPAR(1), ONE, ONE, X, LDX)\r\n X(1,1) = TWO\r\nC\r\n ELSE IF (NR(2) .EQ. 6) THEN\r\n IF (DPAR(1) .NE. ZERO) THEN\r\n A(1,1) = DPAR(1)\r\n A(2,2) = DPAR(1)*TWO\r\n A(3,3) = DPAR(1)*THREE\r\nC .. set C = V ..\r\n TEMP = TWO/THREE\r\n CALL DLASET('A', IPAR(3), IPAR(1), -TEMP, ONE - TEMP,\r\n 1 C, LDC)\r\n CALL DSYMM('L', 'L', IPAR(1), IPAR(1), ONE, C, LDC, A, LDA,\r\n 1 ZERO, DWORK, IPAR(1))\r\n CALL DSYMM('R', 'L', IPAR(1), IPAR(1), ONE, C, LDC, DWORK,\r\n 1 IPAR(1), ZERO, A, LDA)\r\nC .. G = R ! ..\r\n G(1) = DPAR(1)\r\n G(4) = DPAR(1)\r\n G(6) = DPAR(1)\r\n Q(1) = ONE/DPAR(1)\r\n Q(4) = ONE\r\n Q(6) = DPAR(1)\r\n IDENT = '1000'\r\n CALL DLASET('A', IPAR(1), IPAR(1), ZERO, ZERO, X, LDX)\r\n TEMP = DPAR(1)**2\r\n X(1,1) = TEMP + SQRT(TEMP**2 + ONE)\r\n X(2,2) = TEMP*TWO + SQRT(FOUR*TEMP**2 + DPAR(1))\r\n X(3,3) = TEMP*THREE + DPAR(1)*SQRT(9.0D0*TEMP + ONE)\r\n CALL DSYMM('L', 'L', IPAR(1), IPAR(1), ONE, C, LDC, X, LDX,\r\n 1 ZERO, DWORK, IPAR(1))\r\n CALL DSYMM('R', 'L', IPAR(1), IPAR(1), ONE, C, LDC, DWORK,\r\n 1 IPAR(1), ZERO, X, LDX)\r\n ELSE\r\n INFO = 2\r\n END IF\r\nC\r\n ELSE IF (NR(2) .EQ. 7) THEN\r\n IF (DPAR(1) .NE. ZERO) THEN\r\n A(1,2) = .400D0\r\n A(2,3) = .345D0\r\n A(3,2) = -.524D0/DPAR(1)\r\n A(3,3) = -.465D0/DPAR(1)\r\n A(3,4) = .262D0/DPAR(1)\r\n A(4,4) = -ONE/DPAR(1)\r\n B(4,1) = ONE/DPAR(1)\r\n C(1,1) = ONE\r\n C(2,3) = ONE\r\n IDENT = '0011'\r\n ELSE\r\n INFO = 2\r\n END IF\r\nC\r\n ELSE IF (NR(2) .EQ. 8) THEN\r\n A(1,1) = -DPAR(1)\r\n A(2,1) = -ONE\r\n A(1,2) = ONE\r\n A(2,2) = -DPAR(1)\r\n A(3,3) = DPAR(1)\r\n A(4,3) = -ONE\r\n A(3,4) = ONE\r\n A(4,4) = DPAR(1)\r\n CALL DLASET('L', IPAR(1), IPAR(2), ONE, ONE, B, LDB)\r\n CALL DLASET('U', IPAR(3), IPAR(1), ONE, ONE, C, LDC)\r\n IDENT = '0011'\r\nC\r\n ELSE IF (NR(2) .EQ. 9) THEN\r\n IF (IPAR(3) .EQ. 10) THEN\r\nC .. read LQR CARE ...\r\n WRITE (CHPAR(1:12), '(A,I1,A,I1,A)') 'BB01', NR(1), '0',\r\n 1 NR(2), '1.dat'\r\n OPEN(1, IOSTAT = IOS, STATUS = 'OLD', FILE = CHPAR(1:12))\r\n IF (IOS .NE. 0) THEN\r\n INFO = 1\r\n ELSE\r\n DO 36 I = 1, 27, 2\r\n READ (1, FMT = *, IOSTAT = IOS)\r\n 1 ((A(I+J,I+K), K = 0, 1), J = 0, 1)\r\n IF (IOS .NE. 0) INFO = 1\r\n 36 CONTINUE\r\n DO 37 I = 30, 44, 2\r\n READ (1, FMT = *, IOSTAT = IOS)\r\n 1 ((A(I+J,I+K), K = 0, 1), J = 0, 1)\r\n IF (IOS .NE. 0) INFO = 1\r\n 37 CONTINUE\r\n DO 38 I = 1, IPAR(1)\r\n READ (1, FMT = *, IOSTAT = IOS)\r\n 1 (A(I,J), J = 46, IPAR(1))\r\n IF (IOS .NE. 0) INFO = 1\r\n 38 CONTINUE\r\n A(29,29) = -.5301D1\r\n B(48,1) = .8D06\r\n B(51,2) = .8D06\r\n G(1) = .3647D03\r\n G(3) = .1459D02\r\n DO 39 I = 1,6\r\n READ (1, FMT = *, IOSTAT = IOS)\r\n 1 (C(I,J), J = 1,45)\r\n IF (IOS .NE. 0) INFO = 1\r\n 39 CONTINUE\r\n C(7,47) = ONE\r\n C(8,46) = ONE\r\n C(9,50) = ONE\r\n C(10,49) = ONE\r\n Q(11) = .376D-13\r\n Q(20) = .120D-12\r\n Q(41) = .245D-11\r\n END IF\r\n ELSE\r\nC .. read Kalman filter CARE ..\r\n WRITE (CHPAR(1:12), '(A,I1,A,I1,A)') 'BB01', NR(1), '0',\r\n 1 NR(2), '2.dat'\r\n OPEN(1, IOSTAT = IOS, STATUS = 'OLD', FILE = CHPAR(1:12))\r\n IF (IOS .NE. 0) THEN\r\n INFO = 1\r\n ELSE\r\n DO 40 I = 1, 27, 2\r\n READ (1, FMT = *, IOSTAT = IOS)\r\n 1 ((A(I+K,I+J), K = 0, 1), J = 0, 1)\r\n IF (IOS .NE. 0) INFO = 1\r\n 40 CONTINUE\r\n DO 41 I = 30, 44, 2\r\n READ (1, FMT = *, IOSTAT = IOS)\r\n 1 ((A(I+K,I+J), K = 0, 1), J = 0, 1)\r\n IF (IOS .NE. 0) INFO = 1\r\n 41 CONTINUE\r\n DO 42 I = 1, IPAR(1)\r\n READ (1, FMT = *, IOSTAT = IOS)\r\n 1 (A(J,I), J = 46, IPAR(1))\r\n IF (IOS .NE. 0) INFO = 1\r\n 42 CONTINUE\r\n A(29,29) = -.5301D1\r\n DO 43 J = 1, IPAR(2)\r\n READ (1, FMT = *, IOSTAT = IOS)\r\n 1 (B(I,J), I = 1, IPAR(1))\r\n IF (IOS .NE. 0) INFO = 1\r\n 43 CONTINUE\r\n G(1) = .685D-5\r\n G(3) = .373D3\r\n C(1,52) = .3713\r\n C(1,53) = .1245D1\r\n C(2,48) = .8D6\r\n C(2,54) = ONE\r\n C(3,51) = .8D6\r\n C(3,55) = ONE\r\n Q(1) = .28224D5\r\n Q(4) = .2742D-4\r\n Q(6) = .6854D-3\r\n END IF\r\n END IF\r\n CLOSE(1)\r\n IDENT = '0000'\r\n END IF\r\nC\r\n ELSE IF (NR(1) .EQ. 3) THEN\r\n IF (NR(2) .EQ. 1) THEN\r\n DO 45 I = 1, IPAR(1)\r\n IF (MOD(I,2) .EQ. 1) THEN\r\n A(I,I) = -ONE\r\n B(I,(I+1)/2) = ONE\r\n ELSE\r\n A(I,I-1) = ONE\r\n A(I,I+1) = -ONE\r\n C(I/2,I) = ONE\r\n END IF\r\n 45 CONTINUE\r\n ISYMM = 1\r\n DO 50 I = IPAR(3), 1, -1\r\n Q(ISYMM) = 10.0D0\r\n ISYMM = ISYMM + I\r\n 50 CONTINUE\r\n IDENT = '0001'\r\nC\r\n ELSE IF (NR(2) .EQ. 2) THEN\r\n DO 60 I = 1, IPAR(1)\r\n A(I,I) = -TWO\r\n IF (I .LT. IPAR(1)) THEN\r\n A(I,I+1) = ONE\r\n A(I+1,I) = ONE\r\n END IF\r\n 60\t CONTINUE\r\n A(1,IPAR(1)) = ONE\r\n A(IPAR(1),1) = ONE\r\n IDENT = '1111'\r\n TEMP = TWO * PI / DBLE(IPAR(1))\r\n DO 70 I = 1, IPAR(1)\r\n DWORK(I) = COS(TEMP*DBLE(I-1))\r\n DWORK(IPAR(1)+I) = -TWO + TWO*DWORK(I) +\r\n 1 SQRT(5.0D0 + FOUR*DWORK(I)*(DWORK(I) - TWO))\r\n 70 CONTINUE\r\n DO 90 J = 1, IPAR(1)\r\n DO 80 I = 1, IPAR(1)\r\n DWORK(2*IPAR(1)+I) = COS(TEMP*DBLE(I-1)*DBLE(J-1))\r\n 80 CONTINUE\r\n X(J,1) = DDOT(IPAR(1), DWORK(IPAR(1)+1), 1,\r\n 1 DWORK(2*IPAR(1)+1), 1)/DBLE(IPAR(1))\r\n 90 CONTINUE\r\nC .. set up circulant solution matrix ..\r\n DO 100 I = 2, IPAR(1)\r\n CALL DCOPY(IPAR(1)-I+1, X(1,1), 1, X(I,I), 1)\r\n CALL DCOPY(I-1, X(IPAR(1)-I+2,1), 1, X(1,I), 1)\r\n 100 CONTINUE\r\n END IF\r\nC\r\n ELSE IF (NR(1) .EQ. 4) THEN\r\n IF (NR(2) .EQ. 1) THEN\r\nC .. set up remaining parameter ..\r\n IF (.NOT. LSAME(DEF,'N')) THEN\r\n DPAR(1) = ONE\r\n DPAR(2) = ONE\r\n END IF\r\n CALL DLASET('A', IPAR(1)-1, IPAR(1)-1, ZERO, ONE, A(1,2), LDA)\r\n B(IPAR(1),1) = ONE\r\n C(1,1) = ONE\r\n Q(1) = DPAR(1)\r\n G(1) = DPAR(2)\r\n IDENT = '0000'\r\nC\r\n ELSE IF (NR(2) .EQ. 2) THEN\r\nC .. set up remaining parameters ..\r\n APPIND = DBLE(IPAR(1) + 1)\r\n IF (.NOT. LSAME(DEF,'N')) THEN\r\n DPAR(1) = PARDEF(NR(1), NR(2))\r\n DPAR(2) = ONE\r\n DPAR(3) = ONE\r\n DPAR(4) = .2D0\r\n DPAR(5) = .3D0\r\n DPAR(6) = .2D0\r\n DPAR(7) = .3D0\r\n END IF\r\nC .. set up stiffness matrix ..\r\n TEMP = -DPAR(1)*APPIND\r\n CALL DLASET('A', IPAR(1), IPAR(1), ZERO, TWO*TEMP, A, LDA)\r\n DO 110 I = 1, IPAR(1) - 1\r\n A(I+1,I) = -TEMP\r\n A(I,I+1) = -TEMP\r\n 110 CONTINUE\r\nC .. set up Gramian, stored by diagonals ..\r\n TEMP = ONE/(6.0D0*APPIND)\r\n CALL DLASET('L', IPAR(1), 1, FOUR*TEMP, FOUR*TEMP, DWORK,\r\n 1 IPAR(1))\r\n CALL DLASET('L', IPAR(1)-1, 1, TEMP, TEMP, DWORK(IPAR(1)+1),\r\n 1 IPAR(1))\r\n CALL DPTTRF(IPAR(1), DWORK(1), DWORK(IPAR(1)+1), INFO)\r\nC .. A = (inverse of Gramian) * (stiffness matrix) ..\r\n CALL DPTTRS(IPAR(1), IPAR(1), DWORK(1), DWORK(IPAR(1)+1),\r\n 1 A, LDA, INFO)\r\nC .. compute B, C ..\r\n DO 120 I = 1, IPAR(1)\r\n B1 = MAX(DBLE(I-1)/APPIND, DPAR(4))\r\n B2 = MIN(DBLE(I+1)/APPIND, DPAR(5))\r\n C1 = MAX(DBLE(I-1)/APPIND, DPAR(6))\r\n C2 = MIN(DBLE(I+1)/APPIND, DPAR(7))\r\n IF (B1 .GE. B2) THEN\r\n B(I,1) = ZERO\r\n ELSE\r\n B(I,1) = B2 - B1\r\n TEMP = MIN(B2, DBLE(I)/APPIND)\r\n IF (B1 .LT. TEMP) THEN\r\n B(I,1) = B(I,1) + APPIND*(TEMP**2 - B1**2)/TWO\r\n B(I,1) = B(I,1) + DBLE(I)*(B1 - TEMP)\r\n END IF\r\n TEMP = MAX(B1, DBLE(I)/APPIND)\r\n IF (TEMP .LT. B2) THEN\r\n B(I,1) = B(I,1) - APPIND*(B2**2 - TEMP**2)/TWO\r\n B(I,1) = B(I,1) - DBLE(I)*(TEMP - B2)\r\n END IF\r\n END IF\r\n IF (C1 .GE. C2) THEN\r\n C(1,I) = ZERO\r\n ELSE\r\n C(1,I) = C2 - C1\r\n TEMP = MIN(C2, DBLE(I)/APPIND)\r\n IF (C1 .LT. TEMP) THEN\r\n C(1,I) = C(1,I) + APPIND*(TEMP**2 - C1**2)/TWO\r\n C(1,I) = C(1,I) + DBLE(I)*(C1 - TEMP)\r\n END IF\r\n TEMP = MAX(C1, DBLE(I)/APPIND)\r\n IF (TEMP .LT. C2) THEN\r\n C(1,I) = C(1,I) - APPIND*(C2**2 - TEMP**2)/TWO\r\n C(1,I) = C(1,I) - DBLE(I)*(TEMP - C2)\r\n END IF\r\n END IF\r\n 120 CONTINUE\r\n CALL DSCAL(IPAR(1), DPAR(2), B(1,1), 1)\r\n CALL DSCAL(IPAR(1), DPAR(3), C(1,1), LDC)\r\n CALL DPTTRS(IPAR(1), 1, DWORK(1), DWORK(IPAR(1)+1), B, LDB,\r\n 1 INFO)\r\n IDENT = '0011'\r\nC\r\n ELSE IF (NR(2) .EQ. 3) THEN\r\nC .. set up remaining parameters ..\r\n IF (.NOT. LSAME(DEF,'N')) THEN\r\n DPAR(1) = PARDEF(NR(1),NR(2))\r\n DPAR(2) = FOUR\r\n DPAR(3) = ONE\r\n END IF\r\n IF (DPAR(1) . NE. 0) THEN\r\n CALL DLASET('A', L, L, ZERO, ONE, A(1,L+1), LDA)\r\n TEMP = DPAR(3) / DPAR(1)\r\n A(L+1,1) = -TEMP\r\n A(L+1,2) = TEMP\r\n A(IPAR(1),L-1) = TEMP\r\n A(IPAR(1),L) = -TEMP\r\n TTEMP = TWO*TEMP\r\n DO 130 I = 2, L-1\r\n A(L+I,I) = -TTEMP\r\n A(L+I,I+1) = TEMP\r\n A(L+I,I-1) = TEMP\r\n 130 CONTINUE\r\n CALL DLASET('A', L, L, ZERO, -DPAR(2)/DPAR(1), A(L+1,L+1),\r\n 1 LDA)\r\n B(L+1,1) = ONE / DPAR(1)\r\n B(IPAR(1),IPAR(2)) = -ONE / DPAR(1)\r\n IDENT = '0111'\r\n ELSE\r\n INFO = 2\r\n END IF\r\nC\r\n ELSE IF (NR(2) .EQ. 4) THEN\r\n IF (.NOT. LSAME(DEF,'N')) WRITE (CHPAR(1:11), '(A,I1,A,I1,A)')\r\n 1 'BB01', NR(1), '0', NR(2), '.dat'\r\n OPEN(1, IOSTAT = IOS, STATUS = 'OLD', FILE = CHPAR(1:11))\r\n IF (IOS .NE. 0) THEN\r\n INFO = 1\r\n ELSE\r\n READ (1, FMT = *, IOSTAT = IOS) (DWORK(I), I = 1, 4*L-2)\r\n IF (IOS .NE. 0) INFO = 1\r\n END IF\r\n CLOSE(1)\r\n IF (INFO .EQ. 0) THEN\r\n CALL DLASET('A', L-1, L-1, ZERO, ONE, A(L+1,2), LDA)\r\n POS = 2*L + 1\r\n A(1,2) = - DWORK(POS) / DWORK(1)\r\n DO 140 I = 2, L\r\n TEMP = DWORK(POS) / DWORK(I-1)\r\n TTEMP = DWORK(POS) / DWORK(I)\r\n IF (I .GT. 2) A(I-1,I) = TEMP\r\n A(I,I) = -(TEMP + TTEMP)\r\n IF (I .LT. L) A(I+1,I) = TTEMP\r\n POS = POS + 1\r\n 140 CONTINUE\r\n POS = L\r\n TEMP = DWORK(POS+1) / DWORK(1)\r\n A(1,1) = -TEMP\r\n DO 160 I = 2, L\r\n TTEMP = TEMP\r\n TEMP = DWORK(POS+I) / DWORK(I)\r\n SUM = TTEMP - TEMP\r\n A(I,1) = -SUM\r\n A(I,I) = A(I,I) - TEMP\r\n DO 150 J = 2, I-2\r\n A(I,J) = SUM\r\n 150 CONTINUE\r\n IF (I .GT. 2) A(I,I-1) = A(I,I-1) + SUM\r\n 160 CONTINUE\r\n POS = 3*L\r\n A(1,L+1) = -DWORK(3*L)/DWORK(1)\r\n DO 170 I = 2, L\r\n TEMP = DWORK(POS) / DWORK(I-1)\r\n TTEMP = DWORK(POS) / DWORK(I)\r\n IF (I .GT. 2) A(I-1,L+I-1) = TEMP\r\n A(I,L+I-1) = -(TEMP + TTEMP)\r\n IF (I .LT. L) A(I+1,L+I-1) = TTEMP\r\n POS = POS + 1\r\n 170 CONTINUE\r\n B(1,1) = ONE/DWORK(1)\r\n DO 180 I = 1, L\r\n TEMP = ONE/DWORK(I)\r\n IF (I .GT. 1) B(I,I) = -TEMP\r\n IF (I .LT. L) B(I+1,I) = TEMP\r\n 180 CONTINUE\r\n C(1,1) = ONE\r\n Q(1) = ONE\r\n POS = 2*L - 1\r\n ISYMM = L + 1\r\n DO 190 I = 2, L\r\n TEMP = DWORK(POS+I)\r\n TTEMP = DWORK(POS+L+I-1)\r\n C(I,I) = TEMP\r\n C(I,L+I-1) = TTEMP\r\n Q(ISYMM) = ONE / (TEMP*TEMP + TTEMP*TTEMP)\r\n ISYMM = ISYMM + L - I + 1\r\n 190 CONTINUE\r\n IDENT = '0001'\r\n END IF\r\n END IF\r\n END IF\r\nC\r\n IF (INFO .NE. 0) GOTO 2001\r\nC .. set up data in required format ..\r\nC\r\n IF (BPAR(1)) THEN\r\nC .. G is to be returned in product form ..\r\n GDIMM = IPAR(1)\r\n IF (IDENT(4:4) .EQ. '0') THEN\r\nC .. invert R using Cholesky factorization, store in G ..\r\n CALL DPPTRF('L', IPAR(2), G, INFO)\r\n IF (INFO .EQ. 0) THEN\r\n CALL DPPTRI('L', IPAR(2), G, INFO)\r\n IF (IDENT(1:1) .EQ. '0') THEN\r\nC .. B is not identity matrix ..\r\n DO 200 I = 1, IPAR(1)\r\n CALL DSPMV('L', IPAR(2), ONE, G, B(I,1), LDB, ZERO,\r\n 1 DWORK((I-1)*IPAR(1)+1), 1)\r\n 200 CONTINUE\r\n CALL DGEMV('T', IPAR(2), IPAR(1), ONE, DWORK, IPAR(1),\r\n 1 B(1,1), LDB, ZERO, G, 1)\r\n ISYMM = IPAR(1) + 1\r\n DO 210 I = 2, IPAR(1)\r\n CALL DGEMV('T', IPAR(2), IPAR(1), ONE, DWORK, IPAR(1),\r\n 1 B(I,1), LDB, ZERO, B(1,1), LDB)\r\n CALL DCOPY(IPAR(1) - I + 1, B(1,I), LDB, G(ISYMM), 1)\r\n ISYMM = ISYMM + (IPAR(1) - I + 1)\r\n 210 CONTINUE\r\n END IF\r\n ELSE\r\n IF (INFO .GT. 0) THEN\r\n INFO = 3\r\n GOTO 2001\r\n END IF\r\n END IF\r\n ELSE\r\nC .. R = identity ..\r\n IF (IDENT(1:1) .EQ. '0') THEN\r\nC .. B is not identity matrix ..\r\n IF (IPAR(2) .EQ. 1) THEN\r\n CALL DLASET('L', NSYMM, 1, ZERO, ZERO, G, 1)\r\n CALL DSPR('L', IPAR(1), ONE, B, 1, G)\r\n ELSE\r\n CALL DSYRK('L', 'N', IPAR(1), IPAR(2), ONE,\r\n 1 B, LDB, ZERO, DWORK, IPAR(1))\r\n CALL MA02DD('Pack', 'Lower', IPAR(1), DWORK, IPAR(1), G)\r\n END IF\r\n ELSE\r\nC .. B = R = identity ..\r\n ISYMM = 1\r\n DO 220 I = IPAR(1), 1, -1\r\n G(ISYMM) = ONE\r\n ISYMM = ISYMM + I\r\n 220 CONTINUE\r\n END IF\r\n END IF\r\n ELSE\r\n GDIMM = IPAR(2)\r\n IF (IDENT(1:1) .EQ. '1')\r\n 1 CALL DLASET('A', IPAR(1), IPAR(2), ZERO, ONE, B, LDB)\r\n IF (IDENT(4:4) .EQ. '1') THEN\r\n ISYMM = 1\r\n DO 230 I = IPAR(2), 1, -1\r\n G(ISYMM) = ONE\r\n ISYMM = ISYMM + I\r\n 230 CONTINUE\r\n END IF\r\n END IF\r\nC\r\n IF (BPAR(4)) THEN\r\nC .. Q is to be returned in product form ..\r\n QDIMM = IPAR(1)\r\n IF (IDENT(3:3) .EQ. '0') THEN\r\n IF (IDENT(2:2) .EQ. '0') THEN\r\nC .. C is not identity matrix ..\r\n DO 240 I = 1, IPAR(1)\r\n CALL DSPMV('L', IPAR(3), ONE, Q, C(1,I), 1, ZERO,\r\n 1 DWORK((I-1)*IPAR(1)+1), 1)\r\n 240 CONTINUE\r\nC .. use Q(1:IPAR(1)) as workspace and compute the first column\r\nC of Q in the end ..\r\n ISYMM = IPAR(1) + 1\r\n DO 250 I = 2, IPAR(1)\r\n CALL DGEMV('T', IPAR(3), IPAR(1), ONE, DWORK, IPAR(1),\r\n 1 C(1,I), 1, ZERO, Q(1), 1)\r\n CALL DCOPY(IPAR(1) - I + 1, Q(I), 1, Q(ISYMM), 1)\r\n ISYMM = ISYMM + (IPAR(1) - I + 1)\r\n 250 CONTINUE\r\n CALL DGEMV('T', IPAR(3), IPAR(1), ONE, DWORK, IPAR(1),\r\n 1 C(1,1), 1, ZERO, Q, 1)\r\n END IF\r\n ELSE\r\nC .. Q = identity ..\r\n IF (IDENT(2:2) .EQ. '0') THEN\r\nC .. C is not identity matrix ..\r\n IF (IPAR(3) .EQ. 1) THEN\r\n CALL DLASET('L', NSYMM, 1, ZERO, ZERO, Q, 1)\r\n CALL DSPR('L', IPAR(1), ONE, C, LDC, Q)\r\n ELSE\r\n CALL DSYRK('L', 'T', IPAR(1), IPAR(3), ONE, C, LDC,\r\n 1 ZERO, DWORK, IPAR(1))\r\n CALL MA02DD('Pack', 'Lower', IPAR(1), DWORK, IPAR(1), Q)\r\n END IF\r\n ELSE\r\nC .. C = Q = identity ..\r\n ISYMM = 1\r\n DO 260 I = IPAR(1), 1, -1\r\n Q(ISYMM) = ONE\r\n ISYMM = ISYMM + I\r\n 260 CONTINUE\r\n END IF\r\n END IF\r\n ELSE\r\n QDIMM = IPAR(3)\r\n IF (IDENT(2:2) .EQ. '1')\r\n 1 CALL DLASET('A', IPAR(3), IPAR(1), ZERO, ONE, C, LDC)\r\n IF (IDENT(3:3) .EQ. '1') THEN\r\n ISYMM = 1\r\n DO 270 I = IPAR(3), 1, -1\r\n Q(ISYMM) = ONE\r\n ISYMM = ISYMM + I\r\n 270 CONTINUE\r\n END IF\r\n END IF\r\nC\r\nC .. unpack symmetric matrices if desired ..\r\n IF (BPAR(2)) THEN\r\n ISYMM = (GDIMM * (GDIMM + 1)) / 2\r\n CALL DCOPY(ISYMM, G, 1, DWORK, 1)\r\n CALL MA02DD('Unpack', 'Lower', GDIMM, G, LDG, DWORK)\r\n CALL MA02ED('Lower', GDIMM, G, LDG)\r\n ELSE IF (BPAR(3)) THEN\r\n CALL MA02DD('Unpack', 'Lower', GDIMM, DWORK, GDIMM, G)\r\n CALL MA02ED('Lower', GDIMM, DWORK, GDIMM)\r\n CALL MA02DD('Pack', 'Upper', GDIMM, DWORK, GDIMM, G)\r\n END IF\r\n IF (BPAR(5)) THEN\r\n ISYMM = (QDIMM * (QDIMM + 1)) / 2\r\n CALL DCOPY(ISYMM, Q, 1, DWORK, 1)\r\n CALL MA02DD('Unpack', 'Lower', QDIMM, Q, LDQ, DWORK)\r\n CALL MA02ED('Lower', QDIMM, Q, LDQ)\r\n ELSE IF (BPAR(6)) THEN\r\n CALL MA02DD('Unpack', 'Lower', QDIMM, DWORK, QDIMM, Q)\r\n CALL MA02ED('Lower', QDIMM, DWORK, QDIMM)\r\n CALL MA02DD('Pack', 'Upper', QDIMM, DWORK, QDIMM, Q)\r\n END IF\r\nC\r\nC ...set VEC...\r\n VEC(1) = .TRUE.\r\n VEC(2) = .TRUE.\r\n VEC(3) = .TRUE.\r\n VEC(4) = .TRUE.\r\n VEC(5) = .NOT. BPAR(1)\r\n VEC(6) = .NOT. BPAR(4)\r\n VEC(7) = .TRUE.\r\n VEC(8) = .TRUE.\r\n IF (NR(1) .EQ. 1) THEN\r\n IF ((NR(2) .EQ. 1) .OR. (NR(2) .EQ. 2)) VEC(9) = .TRUE.\r\n ELSE IF (NR(1) .EQ. 2) THEN\r\n IF ((NR(2) .EQ. 1) .OR. ((NR(2) .GE. 3) .AND. (NR(2) .LE. 6)))\r\n 1 VEC(9) = .TRUE.\r\n ELSE IF (NR(1) .EQ. 3) THEN\r\n IF (NR(2) .EQ. 2) VEC(9) = .TRUE.\r\n END IF\r\n CHPAR = NOTES(NR(1),NR(2))\r\n N = IPAR(1)\r\n M = IPAR(2)\r\n P = IPAR(3)\r\n 2001 CONTINUE\r\n RETURN\r\nC *** Last line of BB01AD ***\r\n END\r\n", "meta": {"hexsha": "6baba8e17917574b2e3667479016958f8e2c94fe", "size": 50742, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "External/SLICOT/BB01AD.f", "max_stars_repo_name": "bgin/MissileSimulation", "max_stars_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2016-08-28T23:20:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-15T14:43:58.000Z", "max_issues_repo_path": "External/SLICOT/BB01AD.f", "max_issues_repo_name": "bgin/MissileSimulation", "max_issues_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-06-02T21:29:51.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-05T05:59:31.000Z", "max_forks_repo_path": "External/SLICOT/BB01AD.f", "max_forks_repo_name": "bgin/MissileSimulation", "max_forks_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-07-04T22:38:22.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-04T22:38:22.000Z", "avg_line_length": 39.8601728201, "max_line_length": 73, "alphanum_fraction": 0.4318710339, "num_tokens": 17226, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802440252811, "lm_q2_score": 0.7401743620390162, "lm_q1q2_score": 0.6798355286668524}} {"text": " SUBROUTINE qrdcmp(a,n,np,c,d,sing)\r\n INTEGER n,np\r\n REAL a(np,np),c(n),d(n)\r\n LOGICAL sing\r\n INTEGER i,j,k\r\n REAL scale,sigma,sum,tau\r\n sing=.false.\r\n do 17 k=1,n-1\r\n scale=0.\r\n do 11 i=k,n\r\n scale=max(scale,abs(a(i,k)))\r\n11 continue\r\n if(scale.eq.0.)then\r\n sing=.true.\r\n c(k)=0.\r\n d(k)=0.\r\n else\r\n do 12 i=k,n\r\n a(i,k)=a(i,k)/scale\r\n12 continue\r\n sum=0.\r\n do 13 i=k,n\r\n sum=sum+a(i,k)**2\r\n13 continue\r\n sigma=sign(sqrt(sum),a(k,k))\r\n a(k,k)=a(k,k)+sigma\r\n c(k)=sigma*a(k,k)\r\n d(k)=-scale*sigma\r\n do 16 j=k+1,n\r\n sum=0.\r\n do 14 i=k,n\r\n sum=sum+a(i,k)*a(i,j)\r\n14 continue\r\n tau=sum/c(k)\r\n do 15 i=k,n\r\n a(i,j)=a(i,j)-tau*a(i,k)\r\n15 continue\r\n16 continue\r\n endif\r\n17 continue\r\n d(n)=a(n,n)\r\n if(d(n).eq.0.)sing=.true.\r\n return\r\n END\r\n", "meta": {"hexsha": "3bb616df540acf95e27ebb0f0d4b309f6cafc2b9", "size": 1075, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/qrdcmp.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/qrdcmp.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/qrdcmp.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.8888888889, "max_line_length": 41, "alphanum_fraction": 0.3944186047, "num_tokens": 321, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178929, "lm_q2_score": 0.7549149978955811, "lm_q1q2_score": 0.6798234415920973}} {"text": "! vim: set ft=fortran sw=4 ts=4 :\n\n! mandelbrot.f95\n! Calculate Mandelbrot sets\n!\n\nmodule mandelbrot\n !use iso_fortran_env, only: int16\n\n implicit none\n private\n public :: create, create_omp\n\n real, parameter :: r_max = 2.0\n\ncontains\n\n ! calculate loop count for a (complex) pixel\n integer function pixel_value (z, n_max)\n\n complex, intent( in ) :: z\n integer, optional, intent( in ) :: n_max\n\n complex :: z1\n integer :: n, n_end\n\n if ( present(n_max) ) then\n n_end = n_max\n else\n n_end = 255\n end if\n z1 = 0\n\n do n = n_end, 0, -1\n if (abs(z1) > r_max) then\n pixel_value = n\n !write (*, *) n\n return\n end if\n z1 = z1**2 + z\n end do\n\n pixel_value = 0\n\n end function pixel_value\n\n ! calculate RGB for pixel value\n pure function calc_rgb(n)\n integer, intent(in) :: n\n integer, dimension(3) :: calc_rgb\n\n calc_rgb = [5 * mod(n, 15), 32 * mod(n, 7), 8 * mod(n, 31)]\n\n end function calc_rgb\n\n ! generate mandelbrot set (OpenMP version)\n function create_omp(width, height, x_center, y_center, pixel_size) result(img)\n use image\n\n !integer, dimension(:,:,:), allocatable :: image\n type(ImageRGB) :: img\n integer, intent( in ) :: width, height\n real, intent( in ) :: x_center, y_center\n real, intent( in ) :: pixel_size\n\n integer :: x, y\n complex :: offset, coord\n\n img = ImageRGB(width, height)\n\n offset = cmplx(x_center - 0.5*pixel_size*width, &\n y_center + 0.5*pixel_size*height)\n\n !$omp parallel do private(y, x, coord)\n do y = 1, height\n do x = 1, width\n coord = offset + cmplx(x*pixel_size, -y*pixel_size)\n call img % set(x, y, calc_rgb(pixel_value(coord, 255)))\n end do\n end do\n !$omp end parallel do\n\n end function create_omp\n\n ! generate mandelbrot set\n function create(width, height, x_center, y_center, pixel_size) result(img)\n use image\n\n !integer, dimension(:,:,:), allocatable :: image\n type(ImageRGB) :: img\n integer, intent( in ) :: width, height\n real, intent( in ) :: x_center, y_center\n real, intent( in ) :: pixel_size\n\n integer :: x, y\n complex :: offset, coord\n\n img = ImageRGB(width, height)\n\n offset = cmplx(x_center - 0.5*pixel_size*width, &\n y_center + 0.5*pixel_size*height)\n\n do y = 1, height\n do x = 1, width\n coord = offset + cmplx(x*pixel_size, -y*pixel_size)\n call img % set(x, y, calc_rgb(pixel_value(coord, 255)))\n end do\n end do\n\n end function create\n\nend module mandelbrot\n", "meta": {"hexsha": "58b349a621902bdff15fee6166b6329159f26277", "size": 2857, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran/Benchmark/src/mandelbrot.f90", "max_stars_repo_name": "kkirstein/proglang-playground", "max_stars_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Fortran/Benchmark/src/mandelbrot.f90", "max_issues_repo_name": "kkirstein/proglang-playground", "max_issues_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran/Benchmark/src/mandelbrot.f90", "max_forks_repo_name": "kkirstein/proglang-playground", "max_forks_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.2831858407, "max_line_length": 82, "alphanum_fraction": 0.5456772839, "num_tokens": 786, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297807787537, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.679823432596001}} {"text": "subroutine regcoil_svd_scan\n\n use regcoil_variables\n use stel_kinds\n\n implicit none\n\n integer :: iflag, tic, toc, countrate\n real(dp), dimension(:), allocatable :: singular_values, U_transpose_times_RHS\n real(dp), dimension(:,:), allocatable :: svd_matrix, U, VT\n real(dp) :: factor\n integer :: ilambda, itheta, izeta, index, n_singular_values\n\n ! Variables needed by LAPACK:\n integer :: INFO, LWORK, M, N, LDA, LDU, LDVT\n real(dp), dimension(:), allocatable :: WORK\n integer, dimension(:), allocatable :: IWORK\n character :: JOBZ\n\n if (allocated(lambda)) deallocate(lambda)\n ! Nescoil seems to require keeping at least 2 singular values in a svd scan. We will do the same to keep the number\n ! of solutions the same as nescoil.\n nlambda = num_basis_functions-1\n allocate(lambda(nlambda))\n lambda=0\n\n\n if (allocated(svd_matrix)) deallocate(svd_matrix)\n allocate(svd_matrix(ntheta_plasma*nzeta_plasma, num_basis_functions), stat=iflag)\n if (iflag .ne. 0) stop 'svd_scan Allocation error 16!'\n\n\n print *,\"Beginning SVD.\"\n call system_clock(tic,countrate)\n\n if (num_basis_functions > ntheta_plasma*nzeta_plasma) then\n print *,\"Error! The svd scan is only designed to work when num_basis_functions <= ntheta_plasma*nzeta_plasma\"\n stop\n end if\n \n index=0\n do itheta=1,ntheta_plasma\n do izeta = 1,nzeta_plasma\n !index = index+1\n index = (izeta-1)*ntheta_plasma + itheta\n factor = sqrt(norm_normal_plasma(itheta,izeta))\n RHS(index) = -(Bnormal_from_plasma_current(itheta,izeta) + Bnormal_from_net_coil_currents(itheta,izeta))*factor\n svd_matrix(index,:) = g(index,:) / factor\n end do\n end do\n\n !JOBZ='A' ! Compute ALL of the singular vectors.\n JOBZ='S' ! Compute only the first min(M,N) singular vectors, which is N in our case.\n M = ntheta_plasma*nzeta_plasma\n N = num_basis_functions\n LDA = M\n LDU = M\n LDVT = N\n ! This next formula comes from the LAPACK documentation at the end of the file.\n LWORK = max( 3*min(M,N) + max(max(M,N),7*min(M,N)), &\n 3*min(M,N) + max(max(M,N),5*min(M,N)*min(M,N)+4*min(M,N)), &\n min(M,N)*(6+4*min(M,N))+max(M,N))\n \n if (allocated(WORK)) deallocate(WORK)\n allocate(WORK(LWORK),stat=iflag)\n if (iflag .ne. 0) stop 'svd_scan Allocation error 18!'\n\n if (allocated(IWORK)) deallocate(IWORK)\n allocate(IWORK(8*min(M,N)),stat=iflag)\n if (iflag .ne. 0) stop 'svd_scan Allocation error 19!'\n \n n_singular_values = min(M,N)\n\n if (allocated(singular_values)) deallocate(singular_values)\n allocate(singular_values(n_singular_values),stat=iflag)\n if (iflag .ne. 0) stop 'svd_scan Allocation error 20!' \n\n if (allocated(U)) deallocate(U)\n allocate(U(M,N),stat=iflag) ! If all singular vectors were computed, U would be M*M. But here we only compute the first N singular vectors,\n ! so U is M*N.\n if (iflag .ne. 0) stop 'svd_scan Allocation error 21!'\n\n if (allocated(VT)) deallocate(VT)\n allocate(VT(N,N),stat=iflag)\n if (iflag .ne. 0) stop 'svd_scan Allocation error 22!'\n \n ! Call LAPACK to do the SVD:\n ! Note that svd_matrix is destroyed by LAPACK!\n call DGESDD(JOBZ, M, N, svd_matrix, LDA, singular_values, U, LDU, &\n VT, LDVT, WORK, LWORK, IWORK, INFO)\n \n if (INFO==0) then\n print *,\"SVD (DGESDD) successful.\"\n if (n_singular_values<5) then\n print *,\"Singular values:\",singular_values\n else\n print *,\"First 5 singular values:\",singular_values(1:5)\n print *,\"Last 5 singular values:\", &\n singular_values(n_singular_values-4:n_singular_values)\n end if\n else if (INFO>0) then\n print *,\"Error in SVD (DGESDD): Did not converge.\"\n else\n print *,\"Error in SVD (DGESDD): Argument\",INFO,\" was invalid.\"\n end if\n \n call system_clock(toc)\n print *,\"Took \",real(toc-tic)/countrate,\" sec.\"\n\n call system_clock(tic)\n\n if (allocated(U_transpose_times_RHS)) deallocate(U_transpose_times_RHS)\n allocate(U_transpose_times_RHS(num_basis_functions),stat=iflag)\n if (iflag .ne. 0) stop 'svd_scan Allocation error 23!'\n U_transpose_times_RHS = matmul(transpose(U),RHS)\n call system_clock(toc)\n print *,\"matmul: \",real(toc-tic)/countrate,\" sec.\"\n\n !solution = 0\n ! Add the contribution from the ilambda-th singular vectors and singular value:\n solution = solution + VT(1,:) * (1/singular_values(1)) * U_transpose_times_RHS(1)\n do ilambda = nlambda,1,-1\n print \"(a,es10.3,a,i3,a,i3,a)\",\" Solving system for lambda=\",lambda(ilambda),\" (\",ilambda,\" of \",nlambda,\")\"\n\n ! Add the contribution from the ilambda-th singular vectors and singular value:\n !solution = solution + VT(ilambda,:) * (1/singular_values(ilambda)) * U_transpose_times_RHS(ilambda)\n ! Go in reverse order, like NESCOIL\n index = num_basis_functions-ilambda+1\n print *,\"index=\",index\n solution = solution + VT(index,:) * (1/singular_values(index)) * U_transpose_times_RHS(index)\n\n call regcoil_diagnostics(ilambda)\n\n end do\n\nend subroutine regcoil_svd_scan\n\n ! Here is the LAPACK documentation for the relevant SVD subroutine:\n\n!!$* SUBROUTINE DGESDD( JOBZ, M, N, A, LDA, S, U, LDU, VT, LDVT, WORK,\n!!$* LWORK, IWORK, INFO )\n!!$* \n!!$* .. Scalar Arguments ..\n!!$* CHARACTER JOBZ\n!!$* INTEGER INFO, LDA, LDU, LDVT, LWORK, M, N\n!!$* ..\n!!$* .. Array Arguments ..\n!!$* INTEGER IWORK( * )\n!!$* DOUBLE PRECISION A( LDA, * ), S( * ), U( LDU, * ),\n!!$* $ VT( LDVT, * ), WORK( * )\n!!$* ..\n!!$* \n!!$*\n!!$*> \\par Purpose:\n!!$* =============\n!!$*>\n!!$*> \\verbatim\n!!$*>\n!!$*> DGESDD computes the singular value decomposition (SVD) of a real\n!!$*> M-by-N matrix A, optionally computing the left and right singular\n!!$*> vectors. If singular vectors are desired, it uses a\n!!$*> divide-and-conquer algorithm.\n!!$*>\n!!$*> The SVD is written\n!!$*>\n!!$*> A = U * SIGMA * transpose(V)\n!!$*>\n!!$*> where SIGMA is an M-by-N matrix which is zero except for its\n!!$*> min(m,n) diagonal elements, U is an M-by-M orthogonal matrix, and\n!!$*> V is an N-by-N orthogonal matrix. The diagonal elements of SIGMA\n!!$*> are the singular values of A; they are real and non-negative, and\n!!$*> are returned in descending order. The first min(m,n) columns of\n!!$*> U and V are the left and right singular vectors of A.\n!!$*>\n!!$*> Note that the routine returns VT = V**T, not V.\n!!$*>\n!!$*> The divide and conquer algorithm makes very mild assumptions about\n!!$*> floating point arithmetic. It will work on machines with a guard\n!!$*> digit in add/subtract, or on those binary machines without guard\n!!$*> digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or\n!!$*> Cray-2. It could conceivably fail on hexadecimal or decimal machines\n!!$*> without guard digits, but we know of none.\n!!$*> \\endverbatim\n!!$*\n!!$* Arguments:\n!!$* ==========\n!!$*\n!!$*> \\param[in] JOBZ\n!!$*> \\verbatim\n!!$*> JOBZ is CHARACTER*1\n!!$*> Specifies options for computing all or part of the matrix U:\n!!$*> = 'A': all M columns of U and all N rows of V**T are\n!!$*> returned in the arrays U and VT;\n!!$*> = 'S': the first min(M,N) columns of U and the first\n!!$*> min(M,N) rows of V**T are returned in the arrays U\n!!$*> and VT;\n!!$*> = 'O': If M >= N, the first N columns of U are overwritten\n!!$*> on the array A and all rows of V**T are returned in\n!!$*> the array VT;\n!!$*> otherwise, all columns of U are returned in the\n!!$*> array U and the first M rows of V**T are overwritten\n!!$*> in the array A;\n!!$*> = 'N': no columns of U or rows of V**T are computed.\n!!$*> \\endverbatim\n!!$*>\n!!$*> \\param[in] M\n!!$*> \\verbatim\n!!$*> M is INTEGER\n!!$*> The number of rows of the input matrix A. M >= 0.\n!!$*> \\endverbatim\n!!$*>\n!!$*> \\param[in] N\n!!$*> \\verbatim\n!!$*> N is INTEGER\n!!$*> The number of columns of the input matrix A. N >= 0.\n!!$*> \\endverbatim\n!!$*>\n!!$*> \\param[in,out] A\n!!$*> \\verbatim\n!!$*> A is DOUBLE PRECISION array, dimension (LDA,N)\n!!$*> On entry, the M-by-N matrix A.\n!!$*> On exit,\n!!$*> if JOBZ = 'O', A is overwritten with the first N columns\n!!$*> of U (the left singular vectors, stored\n!!$*> columnwise) if M >= N;\n!!$*> A is overwritten with the first M rows\n!!$*> of V**T (the right singular vectors, stored\n!!$*> rowwise) otherwise.\n!!$*> if JOBZ .ne. 'O', the contents of A are destroyed.\n!!$*> \\endverbatim\n!!$*>\n!!$*> \\param[in] LDA\n!!$*> \\verbatim\n!!$*> LDA is INTEGER\n!!$*> The leading dimension of the array A. LDA >= max(1,M).\n!!$*> \\endverbatim\n!!$*>\n!!$*> \\param[out] S\n!!$*> \\verbatim\n!!$*> S is DOUBLE PRECISION array, dimension (min(M,N))\n!!$*> The singular values of A, sorted so that S(i) >= S(i+1).\n!!$*> \\endverbatim\n!!$*>\n!!$*> \\param[out] U\n!!$*> \\verbatim\n!!$*> U is DOUBLE PRECISION array, dimension (LDU,UCOL)\n!!$*> UCOL = M if JOBZ = 'A' or JOBZ = 'O' and M < N;\n!!$*> UCOL = min(M,N) if JOBZ = 'S'.\n!!$*> If JOBZ = 'A' or JOBZ = 'O' and M < N, U contains the M-by-M\n!!$*> orthogonal matrix U;\n!!$*> if JOBZ = 'S', U contains the first min(M,N) columns of U\n!!$*> (the left singular vectors, stored columnwise);\n!!$*> if JOBZ = 'O' and M >= N, or JOBZ = 'N', U is not referenced.\n!!$*> \\endverbatim\n!!$*>\n!!$*> \\param[in] LDU\n!!$*> \\verbatim\n!!$*> LDU is INTEGER\n!!$*> The leading dimension of the array U. LDU >= 1; if\n!!$*> JOBZ = 'S' or 'A' or JOBZ = 'O' and M < N, LDU >= M.\n!!$*> \\endverbatim\n!!$*>\n!!$*> \\param[out] VT\n!!$*> \\verbatim\n!!$*> VT is DOUBLE PRECISION array, dimension (LDVT,N)\n!!$*> If JOBZ = 'A' or JOBZ = 'O' and M >= N, VT contains the\n!!$*> N-by-N orthogonal matrix V**T;\n!!$*> if JOBZ = 'S', VT contains the first min(M,N) rows of\n!!$*> V**T (the right singular vectors, stored rowwise);\n!!$*> if JOBZ = 'O' and M < N, or JOBZ = 'N', VT is not referenced.\n!!$*> \\endverbatim\n!!$*>\n!!$*> \\param[in] LDVT\n!!$*> \\verbatim\n!!$*> LDVT is INTEGER\n!!$*> The leading dimension of the array VT. LDVT >= 1; if\n!!$*> JOBZ = 'A' or JOBZ = 'O' and M >= N, LDVT >= N;\n!!$*> if JOBZ = 'S', LDVT >= min(M,N).\n!!$*> \\endverbatim\n!!$*>\n!!$*> \\param[out] WORK\n!!$*> \\verbatim\n!!$*> WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK))\n!!$*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK;\n!!$*> \\endverbatim\n!!$*>\n!!$*> \\param[in] LWORK\n!!$*> \\verbatim\n!!$*> LWORK is INTEGER\n!!$*> The dimension of the array WORK. LWORK >= 1.\n!!$*> If JOBZ = 'N',\n!!$*> LWORK >= 3*min(M,N) + max(max(M,N),7*min(M,N)).\n!!$*> If JOBZ = 'O',\n!!$*> LWORK >= 3*min(M,N) + \n!!$*> max(max(M,N),5*min(M,N)*min(M,N)+4*min(M,N)).\n!!$*> If JOBZ = 'S' or 'A'\n!!$*> LWORK >= min(M,N)*(6+4*min(M,N))+max(M,N)\n!!$*> For good performance, LWORK should generally be larger.\n!!$*> If LWORK = -1 but other input arguments are legal, WORK(1)\n!!$*> returns the optimal LWORK.\n!!$*> \\endverbatim\n!!$*>\n!!$*> \\param[out] IWORK\n!!$*> \\verbatim\n!!$*> IWORK is INTEGER array, dimension (8*min(M,N))\n!!$*> \\endverbatim\n!!$*>\n!!$*> \\param[out] INFO\n!!$*> \\verbatim\n!!$*> INFO is INTEGER\n!!$*> = 0: successful exit.\n!!$*> < 0: if INFO = -i, the i-th argument had an illegal value.\n!!$*> > 0: DBDSDC did not converge, updating process failed.\n!!$*> \\endverbatim\n", "meta": {"hexsha": "66b1b03b00c8af14272d3f5bd813a811a9cf167f", "size": 11922, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "regcoil_svd_scan.f90", "max_stars_repo_name": "landreman/regcoil", "max_stars_repo_head_hexsha": "99f9abf8b0b0c6ec7bb6e7975dbee5e438808162", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2017-05-26T14:08:43.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-30T10:22:26.000Z", "max_issues_repo_path": "regcoil_svd_scan.f90", "max_issues_repo_name": "landreman/regcoil", "max_issues_repo_head_hexsha": "99f9abf8b0b0c6ec7bb6e7975dbee5e438808162", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2018-02-17T07:44:41.000Z", "max_issues_repo_issues_event_max_datetime": "2020-06-30T20:34:25.000Z", "max_forks_repo_path": "regcoil_svd_scan.f90", "max_forks_repo_name": "landreman/regcoil", "max_forks_repo_head_hexsha": "99f9abf8b0b0c6ec7bb6e7975dbee5e438808162", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2016-12-13T18:15:05.000Z", "max_forks_repo_forks_event_max_datetime": "2019-06-07T20:58:01.000Z", "avg_line_length": 37.8476190476, "max_line_length": 141, "alphanum_fraction": 0.5806072807, "num_tokens": 3716, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297781091839, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6798234305807028}} {"text": "C Compute FFT of profile in array y(nmax), and return amplitude and phase\nC in arrays amp(nh) and pha(nh). Note that nh=nmax/2, and that the DC term\nC is returned in c(0), fundamental in c(1), ..., Nyquist freq in c(nh).\n\n\tsubroutine cprof(y,nmax,amp,pha)\n\n integer nh\n\treal*8 y(nmax),amp(nmax/2),pha(nmax/2)\n\tcomplex c(0:nmax/2),temp(nmax)\n\n nh=nmax/2\n\n\tdo 10 i=1,nh\n10\t temp(i)=cmplx(y(2*i-1),y(2*i))\n\tcall ffft_cdft(temp,nmax,1,1)\n\tc(0)=temp(1)\n\tdo 20 i=1,nh\n\t c(i)=temp(i+1)\n\t amp(i)=cabs(c(i))\n\t pha(i)=0.\n20\tif(amp(i).gt.0.) pha(i)=aimag(clog(c(i)))\n\treturn\n\tend\n\nccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\n\tsubroutine ffft_cdft(d,npts,isign,ireal)\n\nC Fourier transform of length npts=2**k, performed in place.\nC Input data in array d, treated as complex if ireal=0, and as real if ireal=1.\nC In either case the transform values are returned in array d, treated as\nC complex. The DC term is d(1), and d(npts/2+1) is the term at the Nyquist\nC frequency. The basic algorithm is the same as Norm Brenner's FOUR1, and\nC uses radix-2 transforms.\n\nC J. H. Taylor, Princeton University.\n\n integer npts\n\tcomplex d(npts),t,w,wstep,tt,uu\n real*8 pi\n\tparameter (pi=3.141592653589793)\n\nC Shuffle the data to bit-reversed order.\n\n\timax=npts/(ireal+1)\n\tirev=1\n\tdo 5 i=1,imax\n\tif(i.ge.irev) go to 2\n\tt=d(i)\n\td(i)=d(irev)\n\td(irev)=t\n2\tmmax=imax/2\n3\tif(irev.le.mmax) go to 5\n\tirev=irev-mmax\n\tmmax=mmax/2\n\tif(mmax.ge.1) go to 3\n5\tirev=irev+mmax\n\nC The radix-2 transform begins here.\n\n\tapi=isign*pi/2.\n\tmmax=1\n6\tistep=2*mmax\n\twstep=cmplx(-2.*sin(api/mmax)**2,sin(2.*api/mmax))\n\tw=1.\n\tdo 9 m=1,mmax\n\nC This in the inner-most loop -- optimization here is important!\n\tdo 8 i=m,imax,istep\n\tt=w*d(i+mmax)\n\td(i+mmax)=d(i)-t\n8\td(i)=d(i)+t\n\n9\tw=w*(1.+wstep)\n\tmmax=istep\n\tif(mmax.lt.imax) go to 6\n\n\tif(ireal.eq.0) return\n\nC Now complete the last stage of a doubled-up real transform.\n\n\tjmax=imax/2 + 1\n\twstep=cmplx(-2.*sin(isign*pi/npts)**2,sin(isign*pi/imax))\n\tw=1.0\n\td(imax+1)=d(1)\n\n\tdo 10 j=1,jmax\n\tuu=cmplx(real(d(j))+real(d(2+imax-j)),aimag(d(j)) - \n + aimag(d(2+imax-j)))\n\ttt=w*cmplx(aimag(d(j))+aimag(d(2+imax-j)),-real(d(j)) +\n + real(d(2+imax-j)))\n\td(j)=uu+tt\n\td(2+imax-j)=conjg(uu-tt)\n10\tw=w*(1.+wstep)\n\n\treturn\n\tend\n", "meta": {"hexsha": "d865d3358cf3278897c74be0f3026d822b942fae", "size": 2296, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Util/cdft/cprof.f", "max_stars_repo_name": "xuanyuanstar/psrchive_CDFT", "max_stars_repo_head_hexsha": "453c4dc05b8e901ea661cd02d4f0a30665dcaf35", "max_stars_repo_licenses": ["AFL-2.1"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Util/cdft/cprof.f", "max_issues_repo_name": "xuanyuanstar/psrchive_CDFT", "max_issues_repo_head_hexsha": "453c4dc05b8e901ea661cd02d4f0a30665dcaf35", "max_issues_repo_licenses": ["AFL-2.1"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Util/cdft/cprof.f", "max_forks_repo_name": "xuanyuanstar/psrchive_CDFT", "max_forks_repo_head_hexsha": "453c4dc05b8e901ea661cd02d4f0a30665dcaf35", "max_forks_repo_licenses": ["AFL-2.1"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.6701030928, "max_line_length": 80, "alphanum_fraction": 0.6637630662, "num_tokens": 901, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178929, "lm_q2_score": 0.7549149758396752, "lm_q1q2_score": 0.6798234217300969}} {"text": " REAL FUNCTION GLON(I)\nC\nC THIS FUNCTION RETURNS THE LONGITUDE OF THE REGULAR\nC GRID IN RADIANS\nC\nC CALLED BY: ANLYTC, ERRANL, FORCE, INIT, INPUT\nC CALLS:\nC\nC REVISIONS:\nC 7-13-92 CHANGE TO CCM CODING CONVENTIONS (R. JAKOB)\nC\nC\nC---- Model Parameters -------------------------------------------------\nC\n INCLUDE 'params.i'\nC\nC------------ Arguments ------------------------------------------------\nC\nC Input\nC\nC GRID INDEX (LONGITUDE)\n INTEGER I\nC\nC------ Local Parameters -----------------------------------------------\nC\n REAL PI\n PARAMETER (PI=3.141592653589793)\nC\nC----- Executable Statements -------------------------------------------\nC\n GLON = (2.0*PI)/REAL(NLON)*REAL(I-1)\n RETURN\nC\n END\n", "meta": {"hexsha": "f317abaf75ea3a1cebfef0ba0b9ab5a41834ffc5", "size": 740, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/glon.f", "max_stars_repo_name": "jhaoli/shallow_spectral", "max_stars_repo_head_hexsha": "a2580f9baad596a56efaaae20b80e1bd543c2502", "max_stars_repo_licenses": ["NetCDF"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-06-19T02:24:41.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-19T02:24:41.000Z", "max_issues_repo_path": "src/glon.f", "max_issues_repo_name": "jhaoli/shallow_spectral", "max_issues_repo_head_hexsha": "a2580f9baad596a56efaaae20b80e1bd543c2502", "max_issues_repo_licenses": ["NetCDF"], "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/glon.f", "max_forks_repo_name": "jhaoli/shallow_spectral", "max_forks_repo_head_hexsha": "a2580f9baad596a56efaaae20b80e1bd543c2502", "max_forks_repo_licenses": ["NetCDF"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.1428571429, "max_line_length": 72, "alphanum_fraction": 0.4783783784, "num_tokens": 195, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297754396142, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6798234186344045}} {"text": "\tprogram rumor_spreading\n\n\t\n\t! Rumor spreading model (SIHR) \n\n\n\t! The model consists on a set of particles in one of the 4 possible states : \n\t! I - ignorants\n\t! S - spreaders\n\t! H - hiberantors\n\t! R - stiflers\n\n\t! Particles evolve according to a master equation obtained under mean-field approximation.\n\t! The program runs a MC method using a Gillespie algorithm\n\n\t\n\timplicit none\n\n\tinteger N\t\t\t\t\t\t\t\t! total number of particles\n\tdouble precision ign, spr, hib, sti \t\t\t\t! fraction of particles in each state\n\tdouble precision t, tmax, t_trans, t_prev, dt \t\t\t! time variables and time-step between measures\n\tdouble precision k\t\t\t\t\t\t\t! average degree of the network\n\tdouble precision u, dran_u \t\t\t\t\t\t! random number generator\n\tdouble precision lambda, beta, delta, xi, eta, alpha\t\t! transition probabilities\n\tdouble precision rate1,rate2,rate3,rate4\t\t\t\t! transition rates\n\tdouble precision rate5,rate6,rate7,rate8,rate\t\t\t! and more transition rates\n\t\n\n\t! Parameters\n\t!lambda = 0.8d0\n\t!beta = 0.2d0\n\t!delta = 0.5d0\n\t!xi = 0.0d0\n\t!eta = 0.5d0\n\t!alpha = 0.5d0\n\n\t! Nekovee\n\tlambda = 0.09d0\n\tbeta = 0.0d0\n\tdelta = 0.9d0\n\txi = 0.5d0\n\teta = 0.0d0\n\talpha = 0.5d0\n\n\t! SIR\n\t!lambda = 0.6d0\n\t!beta = 0.0d0\n\t!delta = 0.0d0\n\t!xi = 0.0d0\n\t!eta = 0.0d0\n\t!alpha = 0.5d0\n\n\t! Homeopathy\n\t!lambda = 5.5d0\n\t!beta = 1d0\n\t!delta = 0.5d0\n\t!xi = 7d0\n\t!eta = 9d0\n\t!alpha = 0.5d0\n\n\tt = 0.0d0\n\ttmax = 10000000.0d0\n\tdt = 100.0d0\n\tk = 100d0\n\tN = 1000000\n\n\t! Initial conditions\n\tign = dble(N-1)/N\n\tspr = 1.0d0/N\n\thib = 0.0d0\n\tsti = 0.0d0\n\tcall dran_ini(481992)\n\n\t! open the output files\n\topen(unit=21,file='crit_thresh',status='replace',action='write')\n\t! write(21,*) \"time ignorants spreaders hibernators\tstiflers\"\n\twrite(21,*) t, \",\", ign,\",\", spr,\",\", hib,\",\", sti\n\n\t! Gillespie algorithm\n\tt_prev = 0.d0\n\tdo while (t .lt. tmax)\n\t rate1 = lambda*k*ign*spr\n\t rate2 = beta*k*ign*spr\n\t rate3 = delta*spr\n\t rate4 = xi*hib\n\t rate5 = eta*k*spr*hib\n\t rate6 = alpha*k*spr*spr\n\t rate7 = alpha*k*spr*hib\n\t rate8 = alpha*k*spr*sti\n\t rate = rate1+rate2+rate3+rate4+rate5+rate6+rate7+rate8\n\n\t t_trans = -dlog(dran_u())/rate\n\t t = t+t_trans\n\t u = dran_u()*rate\n\n\t if (u < rate1) then\n\t ign = ign-1.d0/N\n\t spr = spr+1.d0/N\n\t elseif (u < rate1+rate2) then\n\t ign = ign-1.d0/N\n\t sti = sti+1.d0/N\n\t elseif (u < rate1+rate2+rate3) then\n\t spr = spr-1.d0/N\n\t hib = hib+1.d0/N\n\t elseif (u < rate1+rate2+rate3+rate4+rate5) then\n\t hib = hib-1.d0/N\n\t spr = spr+1.d0/N\n\t else\n\t spr = spr-1.d0/N\n\t sti = sti+1.d0/N\n\t endif\n\t if (t-t_prev > dt) then\n\t write(21,*) t, \",\", ign,\",\", spr,\",\", hib,\",\", sti\n\t t_prev = t\n\t endif\n\n\tenddo\n\tclose(21)\n\tend program rumor_spreading\n", "meta": {"hexsha": "a777823d9e179fd4db9f89f444c1cc8745f1ef08", "size": 2684, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "code/rumor.f", "max_stars_repo_name": "PatrickSaga/rumor-spreading", "max_stars_repo_head_hexsha": "bb336eea788d4d1ebb666c9f9663e6241ccce61a", "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": "code/rumor.f", "max_issues_repo_name": "PatrickSaga/rumor-spreading", "max_issues_repo_head_hexsha": "bb336eea788d4d1ebb666c9f9663e6241ccce61a", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "code/rumor.f", "max_forks_repo_name": "PatrickSaga/rumor-spreading", "max_forks_repo_head_hexsha": "bb336eea788d4d1ebb666c9f9663e6241ccce61a", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.3666666667, "max_line_length": 97, "alphanum_fraction": 0.6345007452, "num_tokens": 1078, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297754396142, "lm_q2_score": 0.7549149758396752, "lm_q1q2_score": 0.6798234136689044}} {"text": "C$Procedure SAELGV ( Semi-axes of ellipse from generating vectors )\n \n SUBROUTINE SAELGV ( VEC1, VEC2, SMAJOR, SMINOR )\n \nC$ Abstract\nC\nC Find semi-axis vectors of an ellipse generated by two arbitrary\nC three-dimensional vectors.\nC\nC$ Disclaimer\nC\nC THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE\nC CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.\nC GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE\nC ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE\nC PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED \"AS-IS\"\nC TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY\nC WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A\nC PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC\nC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE\nC SOFTWARE AND RELATED MATERIALS, HOWEVER USED.\nC\nC IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA\nC BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT\nC LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,\nC INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,\nC REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE\nC REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.\nC\nC RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF\nC THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY\nC CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE\nC ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.\nC\nC$ Required_Reading\nC\nC ELLIPSES\nC\nC$ Keywords\nC\nC ELLIPSE\nC GEOMETRY\nC MATH\nC\nC$ Declarations\n \n DOUBLE PRECISION VEC1 ( 3 )\n DOUBLE PRECISION VEC2 ( 3 )\n DOUBLE PRECISION SMAJOR ( 3 )\n DOUBLE PRECISION SMINOR ( 3 )\n \nC$ Brief_I/O\nC\nC Variable I/O Description\nC -------- --- --------------------------------------------------\nC VEC1,\nC VEC2 I Two vectors used to generate an ellipse.\nC SMAJOR O Semi-major axis of ellipse.\nC SMINOR O Semi-minor axis of ellipse.\nC\nC$ Detailed_Input\nC\nC VEC1,\nC VEC2 are two vectors that define an ellipse.\nC The ellipse is the set of points in 3-space\nC\nC CENTER + cos(theta) VEC1 + sin(theta) VEC2\nC\nC where theta is in the interval ( -pi, pi ] and\nC CENTER is an arbitrary point at which the ellipse\nC is centered. An ellipse's semi-axes are\nC independent of its center, so the vector CENTER\nC shown above is not an input to this routine.\nC\nC VEC2 and VEC1 need not be linearly independent;\nC degenerate input ellipses are allowed.\nC\nC$ Detailed_Output\nC\nC SMAJOR\nC SMINOR are semi-major and semi-minor axes of the ellipse,\nC respectively.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC 1) If one or more semi-axes of the ellipse is found to be the\nC zero vector, the input ellipse is degenerate. This case is\nC not treated as an error; the calling program must determine\nC whether the semi-axes are suitable for the program's intended\nC use.\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC Two linearly independent but not necessarily orthogonal vectors\nC VEC1 and VEC2 can define an ellipse centered at the origin: the\nC ellipse is the set of points in 3-space\nC\nC CENTER + cos(theta) VEC1 + sin(theta) VEC2\nC\nC where theta is in the interval (-pi, pi] and CENTER is an\nC arbitrary point at which the ellipse is centered.\nC\nC This routine finds vectors that constitute semi-axes of an\nC ellipse that is defined, except for the location of its center,\nC by VEC1 and VEC2. The semi-major axis is a vector of largest\nC possible magnitude in the set\nC\nC cos(theta) VEC1 + sin(theta) VEC2\nC\nC There are two such vectors; they are additive inverses of each\nC other. The semi-minor axis is an analogous vector of smallest\nC possible magnitude. The semi-major and semi-minor axes are\nC orthogonal to each other. If SMAJOR and SMINOR are choices of\nC semi-major and semi-minor axes, then the input ellipse can also\nC be represented as the set of points\nC\nC CENTER + cos(theta) SMAJOR + sin(theta) SMINOR\nC\nC where theta is in the interval (-pi, pi].\nC\nC The capability of finding the axes of an ellipse is useful in\nC finding the image of an ellipse under a linear transformation.\nC Finding this image is useful for determining the orthogonal and\nC gnomonic projections of an ellipse, and also for finding the limb\nC and terminator of an ellipsoidal body.\nC\nC$ Examples\nC\nC 1) An example using inputs that can be readily checked by\nC hand calculation.\nC\nC Let\nC\nC VEC1 = ( 1.D0, 1.D0, 1.D0 )\nC VEC2 = ( 1.D0, -1.D0, 1.D0 )\nC\nC The subroutine call\nC\nC CALL SAELGV ( VEC1, VEC2, SMAJOR, SMINOR )\nC\nC returns\nC\nC SMAJOR = ( -1.414213562373095D0,\nC 0.0D0,\nC -1.414213562373095D0 )\nC and\nC\nC SMINOR = ( -2.4037033579794549D-17\nC 1.414213562373095D0,\nC -2.4037033579794549D-17 )\nC\nC\nC 2) This example is taken from the code of the SPICELIB routine\nC PJELPL, which finds the orthogonal projection of an ellipse\nC onto a plane. The code listed below is the portion used to\nC find the semi-axes of the projected ellipse.\nC\nC C\nC C Project vectors defining axes of ellipse onto plane.\nC C\nC CALL VPERP ( VEC1, NORMAL, PROJ1 )\nC CALL VPERP ( VEC2, NORMAL, PROJ2 )\nC\nC .\nC .\nC .\nC\nC CALL SAELGV ( PROJ1, PROJ2, SMAJOR, SMINOR )\nC\nC\nC The call to SAELGV determines the required semi-axes.\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Literature_References\nC\nC [1] Calculus, Vol. II. Tom Apostol. John Wiley & Sons, 1969.\nC See Chapter 5, `Eigenvalues of Operators Acting on Euclidean\nC Spaces'.\nC\nC$ Author_and_Institution\nC\nC N.J. Bachman (JPL)\nC W.L. Taber (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 1.1.1, 22-APR-2010 (NJB)\nC\nC Header correction: assertions that the output\nC can overwrite the input have been removed.\nC\nC- SPICELIB Version 1.1.0, 02-SEP-2005 (NJB)\nC\nC Updated to remove non-standard use of duplicate arguments\nC in VSCL calls.\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, 02-NOV-1990 (NJB) (WLT)\nC\nC-&\n \nC$ Index_Entries\nC\nC semi-axes of ellipse from generating vectors\nC\nC-&\n\nC$ Revisions\nC\nC- SPICELIB Version 1.1.0, 02-SEP-2005 (NJB)\nC\nC Updated to remove non-standard use of duplicate arguments\nC in VSCL calls.\nC\nC-& \n \n \n \nC\nC SPICELIB functions\nC\n DOUBLE PRECISION VDOT\n DOUBLE PRECISION VNORM\n \n LOGICAL RETURN\n \nC\nC Local variables\nC\n DOUBLE PRECISION C ( 2, 2 )\n DOUBLE PRECISION EIGVAL ( 2, 2 )\n DOUBLE PRECISION S ( 2, 2 )\n DOUBLE PRECISION SCALE\n DOUBLE PRECISION TMPVC1 ( 3 )\n DOUBLE PRECISION TMPVC2 ( 3 )\n\n INTEGER I\n INTEGER MAJOR\n INTEGER MINOR\n \n \nC\nC Standard SPICE error handling.\nC\n IF ( RETURN () ) THEN\n RETURN\n ELSE\n CALL CHKIN ( 'SAELGV' )\n END IF\n \nC\nC Let the notation\nC\nC < a, b >\nC\nC indicate the inner product of the vectors a and b.\nC\nC The semi-major and semi-minor axes of the input ellipse are\nC vectors of maximum and minimum norm in the set\nC\nC cos(x) VEC1 + sin(x) VEC2\nC\nC where x is in the interval (-pi, pi].\nC\nC The square of the norm of a vector in this set is\nC\nC 2\nC || cos(x) VEC1 + sin(x) VEC2 ||\nC\nC\nC = < cos(x)VEC1 + sin(x)VEC2, cos(x)VEC1 + sin(x)VEC2 > ;\nC\nC this last expression can be written as the matrix product\nC\nC T\nC X S X, (1)\nC\nC where X is the unit vector\nC\nC +- -+\nC | cos(x) |\nC | |\nC | sin(x) |\nC +- -+\nC\nC and S is the symmetric matrix\nC\nC +- -+\nC | < VEC1, VEC1 > < VEC1, VEC2 > |\nC | |.\nC | < VEC1, VEC2 > < VEC2, VEC2 > |\nC +- -+\nC\nC Because the 2x2 matrix above is symmetric, there exists a\nC rotation matrix that allows us to diagonalize it:\nC\nC T\nC C S C = D,\nC\nC where D is a diagonal matrix. Since rotation matrices are\nC orthogonal, we have\nC\nC T\nC C C = I.\nC\nC If the unit vector U is defined by\nC\nC T\nC U = C X,\nC\nC then\nC\nC T T T T T\nC X S X = ( U C ) C D C ( C U ) = U D U.\nC\nC So, letting\nC\nC +- -+\nC | u |\nC | | = U,\nC | v |\nC +- -+\nC\nC we may re-write the original quadratic expression (1) as\nC\nC +- -+ +- -+ +- -+\nC | u v | | D1 0 | | u |,\nC +- -+ | | | |\nC | | | v |\nC | 0 D2 | +- -+\nC +- -+\nC or\nC\nC 2 2\nC D1 u + D2 v,\nC\nC where the diagonal matrix above is D. The eigenvalues D1 and\nC D2 are non-negative because they are eigenvalues of a positive\nC semi-definite matrix of the form\nC\nC T\nC M M.\nC\nC We may require that\nC\nC D1 > D2;\nC -\nC\nC then the maximum and minimum values of\nC\nC 2 2\nC D1 u + D2 v (2)\nC\nC are D1 and D2 respectively. These values are the squares\nC of the lengths of the semi-major and semi-minor axes of the\nC ellipse, since the expression (2) is the square of the norm\nC of the point\nC\nC cos(x) VEC1 + sin(x) VEC2.\nC\nC Now we must find some eigenvectors. Since the extrema of (2)\nC occur when\nC\nC +- -+ +- -+\nC | 1 | | 0 |\nC U = | | or U = | |,\nC | 0 | | 1 |\nC +- -+ +- -+\nC\nC and since\nC\nC X = C U,\nC\nC we conclude that the extrema occur when X = C1 or X = C2, where\nC C1 and C2 are the first and second columns of C. Looking at\nC the definition of X, we see that the extrema occur when\nC\nC cos(x) = C1(1)\nC sin(x) = C1(2)\nC\nC and when\nC\nC cos(x) = C2(1),\nC sin(x) = C2(2)\nC\nC So the semi-major and semi-minor axes of the ellipse are\nC\nC C(1,1) VEC1 + C(2,1) VEC2\nC\nC and\nC\nC C(1,2) VEC1 + C(2,2) VEC2\nC\nC (the negatives of these vectors are also semi-axes).\nC\nC\nC Copy the input vectors.\nC\n CALL MOVED ( VEC1, 3, TMPVC1 )\n CALL MOVED ( VEC2, 3, TMPVC2 )\n \nC\nC Scale the vectors to try to prevent arithmetic unpleasantness.\nC We avoid using the quotient 1/SCALE, as this value may overflow.\nC No need to go further if SCALE turns out to be zero.\nC\n SCALE = MAX ( VNORM ( TMPVC1 ), VNORM ( TMPVC2 ) )\n \n IF ( SCALE .EQ. 0.D0 ) THEN\n \n CALL CLEARD ( 3, SMAJOR )\n CALL CLEARD ( 3, SMINOR )\n \n CALL CHKOUT ( 'SAELGV' )\n RETURN\n \n END IF\n \n DO I = 1, 3\n TMPVC1(I) = TMPVC1(I) / SCALE\n TMPVC2(I) = TMPVC2(I) / SCALE\n END DO\n \nC\nC Compute S and diagonalize it:\nC\n S(1,1) = VDOT ( TMPVC1, TMPVC1 )\n S(2,1) = VDOT ( TMPVC1, TMPVC2 )\n S(1,2) = S(2,1)\n S(2,2) = VDOT ( TMPVC2, TMPVC2 )\n \n CALL DIAGS2 ( S, EIGVAL, C )\n \nC\nC Find the semi-axes.\nC\n IF ( DABS( EIGVAL(1,1) ) .GE. DABS( EIGVAL(2,2) ) ) THEN\nC\nC The first eigenvector ( first column of C ) corresponds\nC to the semi-major axis of the ellipse.\nC\n MAJOR = 1\n MINOR = 2\n \n ELSE\nC\nC The second eigenvector corresponds to the semi-major axis.\nC\n MAJOR = 2\n MINOR = 1\n \n END IF\n \n CALL VLCOM ( C(1,MAJOR), TMPVC1, C(2,MAJOR), TMPVC2, SMAJOR )\n CALL VLCOM ( C(1,MINOR), TMPVC1, C(2,MINOR), TMPVC2, SMINOR )\n \nC\nC Undo the initial scaling.\nC\n CALL VSCLIP ( SCALE, SMAJOR )\n CALL VSCLIP ( SCALE, SMINOR )\n \n \n CALL CHKOUT ( 'SAELGV' )\n RETURN\n END\n", "meta": {"hexsha": "6496ebeec6ac8236b43e829de2ea15b26c705faa", "size": 13535, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/saelgv.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/saelgv.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/saelgv.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.0809128631, "max_line_length": 72, "alphanum_fraction": 0.546287403, "num_tokens": 4029, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.6797251915680006}} {"text": " Program zggev3_example\n\n! ZGGEV3 Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use blas_interfaces, Only: dznrm2\n Use lapack_example_aux, Only: nagf_file_print_matrix_complex_gen, &\n nagf_sort_cmplxvec_rank_rearrange, nagf_sort_realvec_rank\n Use lapack_interfaces, Only: zggev3\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nin = 5, nout = 6\n! .. Local Scalars ..\n Complex (Kind=dp) :: scal\n Integer :: i, ifail, info, j, k, lda, ldb, ldvr, lwork, n\n! .. Local Arrays ..\n Complex (Kind=dp), Allocatable :: a(:, :), alpha(:), b(:, :), beta(:), &\n temp(:), vr(:, :), work(:)\n Complex (Kind=dp) :: dummy(1, 1)\n Real (Kind=dp), Allocatable :: rwork(:)\n Integer, Allocatable :: irank(:)\n! .. Intrinsic Procedures ..\n Intrinsic :: abs, all, conjg, epsilon, maxloc, nint, real\n! .. Executable Statements ..\n Write (nout, *) 'ZGGEV3 Example Program Results'\n Write (nout, *)\n Flush (nout)\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n\n lda = n\n ldb = n\n ldvr = n\n Allocate (a(lda,n), alpha(n), b(ldb,n), beta(n), vr(ldvr,n), rwork(8*n))\n\n! Use routine workspace query to get optimal workspace.\n lwork = -1\n Call zggev3('No left vectors', 'Vectors (right)', n, a, lda, b, ldb, &\n alpha, beta, dummy, 1, vr, ldvr, dummy, lwork, rwork, info)\n\n lwork = nint(real(dummy(1,1)))\n Allocate (work(lwork))\n\n! Read in the matrices A and B\n\n Read (nin, *)(a(i,1:n), i=1, n)\n Read (nin, *)(b(i,1:n), i=1, n)\n\n! Solve the generalized eigenvalue problem\n\n Call zggev3('No left vectors', 'Vectors (right)', n, a, lda, b, ldb, &\n alpha, beta, dummy, 1, vr, ldvr, work, lwork, rwork, info)\n\n If (info>0) Then\n Write (nout, *)\n Write (nout, 100) 'Failure in ZGGEV3. INFO =', info\n Else If (all(abs(beta(1:n))>epsilon(1.0E0_dp))) Then\n! Re-normalize the eigenvectors, largest absolute element real\n Do i = 1, n\n rwork(1:n) = abs(vr(1:n,i))\n k = maxloc(rwork(1:n), 1)\n scal = conjg(vr(k,i))/rwork(k)/dznrm2(n, vr(1,i), 1)\n vr(1:n, i) = vr(1:n, i)*scal\n End Do\n alpha(1:n) = alpha(1:n)/beta(1:n)\n\n! Reorder eigenvalues by descending absolute value\n rwork(1:n) = abs(alpha(1:n))\n Allocate (irank(n), temp(n))\n ifail = 0\n Call nagf_sort_realvec_rank(rwork, 1, n, 'Descending', irank, ifail)\n Call nagf_sort_cmplxvec_rank_rearrange(alpha, 1, n, irank, ifail)\n\n! Reorder eigenvectors accordingly\n Do j = 1, n\n temp(1:n) = vr(j, 1:n)\n Call nagf_sort_cmplxvec_rank_rearrange(temp, 1, n, irank, ifail)\n vr(j, 1:n) = temp(1:n)\n End Do\n\n ifail = 0\n Call nagf_file_print_matrix_complex_gen('Gen', ' ', 1, n, alpha, 1, &\n 'Eigenvalues:', ifail)\n Write (nout, *)\n Flush (nout)\n Call nagf_file_print_matrix_complex_gen('Gen', ' ', n, n, vr, ldvr, &\n 'Right Eigenvectors (columns):', ifail)\n Else\n Write (nout, *) 'Some of the eigenvalues are infinite.'\n Write (nout, *)\n Flush (nout)\n ifail = 0\n Call nagf_file_print_matrix_complex_gen('Gen', ' ', 1, n, alpha, 1, &\n 'Alpha', ifail)\n Call nagf_file_print_matrix_complex_gen('Gen', ' ', 1, n, beta, 1, &\n 'Beta', ifail)\n End If\n\n100 Format (1X, A, I4)\n End Program\n", "meta": {"hexsha": "65b9012cfdbdd92cad112533a0b86eafff64daab", "size": 3766, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/zggev3_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/zggev3_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/zggev3_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 35.1962616822, "max_line_length": 90, "alphanum_fraction": 0.5690387679, "num_tokens": 1195, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6797251908750082}} {"text": "subroutine face_value(phi, phi_uf, phi_vf, dx, dy, nx, ny, xi, xf)\nuse kind_parameters\nimplicit none\n\ninteger, intent(in):: nx, ny, xi, xf\nreal(kind=dp), intent(inout), dimension(nx,xi-1:xf+1):: phi\nreal(kind=dp), intent(out), dimension(nx-1,xi-1:xf+1):: phi_uf\nreal(kind=dp), intent(out), dimension(nx,xi-1:xf+1):: phi_vf\nreal(kind=dp), dimension(nx), intent(in):: dx\nreal(kind=dp), dimension(ny), intent(in):: dy\ninteger:: i, j\nreal(kind=dp) :: fe_area, fn_area\n! Calculate the residual r = f - Au, where u is the guessed value\n! Input\n! u Matrix for variables\n! f Right Hand Side\n! hx grid spacing in x direction\n! hy grid spacing in y direction\n!\n! Output\n! r Residual\n\n! Author: Pratanu Roy\n! History:\n! First Written: July 20, 2012\n! Modified: Feb 11, 2013\n\n! Calculate boundary values by linear extrapolation\n!\ndo j = xi-1,xf+1\n\n phi(1,j) = (15.0d0*phi(2,j) - 10.0d0*phi(3,j) + 3.0d0*phi(4,j))/8.0d0\n phi(nx,j) = (15.0d0*phi(nx-1,j) - 10.0d0*phi(nx-2,j) + 3.0d0*phi(nx-3,j))/8.0d0\n\nend do\n\nif (xi .eq. 2) then\n\ndo i = 2,nx-1\n\n phi(i,1) = (15.0d0*phi(i,2) - 10.0d0*phi(i,3) + 3.0d0*phi(i,4))/8.0d0\n! phi(i,1) = phi(i,2)\n\nend do\n\nelse if (xf .eq. ny-1) then\n\ndo i = 2,nx-1\n\n phi(i,ny) = (15.0d0*phi(i,ny-1) - 10.0d0*phi(i,ny-2) + 3.0d0*phi(i,ny-3))/8.0d0\n! phi(i,ny) = phi(i,ny-1)\n\nend do\n\nend if\n\n!phi(1,:) = phi(2,:)\n!phi(nx,:) = phi(nx-1,:)\n!phi(:,1) = phi(:,2)\n!phi(:,ny) = phi(:,ny-1)\n\ncall exchange_data(phi, nx, xi, xf)\n\ndo j = xi,xf\n\n do i = 2,nx-1\n\n fe_area = dx(i+1)/(dx(i+1)+dx(i))\n phi_uf(i,j) = fe_area*phi(i,j) + (1.0d0-fe_area)*phi(i+1,j)\n\n end do\n\nend do\n\nphi_uf(1,:) = phi(1,:)\n!phi_uf(1,:) = phi_uf(2,:)\n!phi_uf(nx-1,:) = phi_uf(nx-2,:)\n\ndo j = xi,xf\n\n do i = 2,nx-1\n\n fn_area = dy(j+1)/(dy(j+1)+dy(j))\n phi_vf(i,j) = fn_area*phi(i,j) + (1.0d0-fn_area)*phi(i,j+1)\n\n end do\n\nend do\n\nif (xi .eq. 2) then\n\nphi_vf(1:nx,1) = phi(1:nx,1)\n!phi_vf(1:nx,1) = phi_vf(1:nx,2)\n\nend if\n\nif (xf .eq. ny-1) then\n\nphi_vf(1:nx,ny-1) = phi(1:nx,ny)\n!phi_vf(1:nx,ny-1) = phi_vf(1:nx,ny-2)\n\nend if\n\ncall exchange_data(phi_uf, nx-1, xi, xf)\ncall exchange_data(phi_vf, nx, xi, xf)\n\nend subroutine\n", "meta": {"hexsha": "b81dbda43cda4c3acae0ec86e595b911bd6f551b", "size": 2205, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "face_value.f90", "max_stars_repo_name": "pratanuroy/Multigrid_Cavity", "max_stars_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-09-11T12:01:52.000Z", "max_stars_repo_stars_event_max_datetime": "2017-09-11T12:01:52.000Z", "max_issues_repo_path": "face_value.f90", "max_issues_repo_name": "pratanuroy/Multigrid_Cavity", "max_issues_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "face_value.f90", "max_forks_repo_name": "pratanuroy/Multigrid_Cavity", "max_forks_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.4166666667, "max_line_length": 85, "alphanum_fraction": 0.5845804989, "num_tokens": 968, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6797251867767993}} {"text": "!*****************************************************************************************\n!>\n! LINCOA: **LIN**early **C**onstrained **O**ptimization **A**lgorithm\n!\n! The purpose of LINCOA is to seek the least value of a function F of several variables\n! subject to general linear inequality constraints on the variables,\n! when derivatives of F are not available.\n!\n!# History\n! * M.J.D. Powell, December 6th, 2013 : There are no\n! restrictions on or charges for the use of the software. I hope that the time\n! and effort I have spent on developing the package will be helpful to much\n! research and to many applications.\n! * Jacob Williams, July 2015 : refactoring of the code into modern Fortran.\n\n module lincoa_module\n\n use kind_module, only: wp\n\n private\n\n abstract interface\n subroutine func (n, x, f) !! calfun interface\n import :: wp\n implicit none\n integer :: n\n real(wp) :: x (*)\n real(wp) :: f\n end subroutine func\n end interface\n\n public :: lincoa\n public :: lincoa_test\n\n contains\n\n!*****************************************************************************************\n!>\n! \u00a0This subroutine seeks the least value of a function of many variables,\n! \u00a0subject to general linear inequality constraints, by a trust region\n! \u00a0method that forms quadratic models by interpolation.\n!\n! LINCOA solves the following optimization problem:\n!```\n! Minimize F(X(1),X(2),...X(N)) subject to:\n! A * X <= B\n!```\n!\n! Usually there\n! \u00a0is much freedom in each new model after satisfying the interpolation\n! \u00a0conditions, which is taken up by minimizing the Frobenius norm of\n! \u00a0the change to the second derivative matrix of the model. One new\n! \u00a0function value is calculated on each iteration, usually at a point\n! \u00a0where the current model predicts a reduction in the least value so\n! \u00a0far of the objective function subject to the linear constraints.\n! \u00a0Alternatively, a new vector of variables may be chosen to replace\n! \u00a0an interpolation point that may be too far away for reliability, and\n! \u00a0then the new point does not have to satisfy the linear constraints.\n\n subroutine lincoa (n, npt, m, a, ia, b, x, rhobeg, rhoend, iprint, maxfun, calfun)\n\n implicit none\n\n integer,intent(in) :: n !! the number of variables. must be at least 2.\n integer,intent(in) :: npt !! the number of interpolation conditions, which is\n !! required to be in the interval [N+2,(N+1)(N+2)/2]. Typical choices\n !! of the author are NPT=N+6 and NPT=2*N+1. Larger values tend to be\n !! highly inefficent when the number of variables is substantial, due\n !! to the amount of work and extra difficulty of adjusting more points.\n integer,intent(in) :: m !! the number of linear inequality constraints.\n integer,intent(in) :: ia !! the first dimension of the array A, which must be at least N.\n real(wp),dimension(ia,*),intent(in) :: a !! a matrix whose columns are the constraint gradients, which are\n !! required to be nonzero.\n real(wp),dimension(*),intent(in) :: b !! the vector of right hand sides of the constraints, the J-th\n !! constraint being that the scalar product of A(.,J) with X(.) is at\n !! most B(J). The initial vector X(.) is made feasible by increasing\n !! the value of B(J) if necessary.\n real(wp),dimension(*),intent(inout) :: x !! the vector of variables. Initial values of X(1),X(2),...,X(N)\n !! must be supplied. If they do not satisfy the constraints, then B\n !! is increased as mentioned above. X contains on return the variables\n !! that have given the least calculated F subject to the constraints.\n real(wp),intent(in) :: rhobeg !! RHOBEG and RHOEND must be set to the initial and final values of a\n !! trust region radius, so both must be positive with RHOEND<=RHOBEG.\n !! Typically, RHOBEG should be about one tenth of the greatest expected\n !! change to a variable, and RHOEND should indicate the accuracy that\n !! is required in the final values of the variables.\n real(wp),intent(in) :: rhoend !! RHOBEG and RHOEND must be set to the initial and final values of a\n !! trust region radius, so both must be positive with RHOEND<=RHOBEG.\n !! Typically, RHOBEG should be about one tenth of the greatest expected\n !! change to a variable, and RHOEND should indicate the accuracy that\n !! is required in the final values of the variables.\n integer,intent(in) :: iprint !! The value of IPRINT should be set to 0, 1, 2 or 3, which controls the\n !! amount of printing. Specifically, there is no output if IPRINT=0 and\n !! there is output only at the return if IPRINT=1. Otherwise, the best\n !! feasible vector of variables so far and the corresponding value of\n !! the objective function are printed whenever RHO is reduced, where\n !! RHO is the current lower bound on the trust region radius. Further,\n !! each new value of F with its variables are output if IPRINT=3.\n integer,intent(in) :: maxfun !! an upper bound on the number of calls of CALFUN,\n !! its value being at least NPT+1.\n procedure (func) :: calfun !! It must set\n !! F to the value of the objective function for the variables X(1),\n !! X(2),...,X(N). The value of the argument F is positive when CALFUN\n !! is called if and only if the current X satisfies the constraints\n\n real(wp),parameter :: zero = 0.0_wp\n\n real(wp),dimension(:),allocatable :: w\n integer, dimension(n) :: iact !to avoid type mismatch error - JW\n real(wp) :: smallx,sum,temp\n integer :: np,nptm,iamat,ib,iflag,i,iac,ibmat,ifv,igo,ihq,ipq,ipqw,&\n iqf,irc,isp,istp,iw,ixb,ixn,ixo,ixp,ixs,irf,izmat,j,ndim\n\n! W is an array used for working space. Its length must be at least\n! M*(2+N) + NPT*(4+N+NPT) + N*(9+3*N) + MAX [ M+3*N, 2*M+N, 2*NPT ].\n! On return, W(1) is set to the final value of F, and W(2) is set to\n! the total number of function evaluations plus 0.5.\n allocate(w(M*(2+N) + NPT*(4+N+NPT) + N*(9+3*N) + MAX(M+3*N, 2*M+N, 2*NPT)))\n\n!\n! Check that N, NPT and MAXFUN are acceptable.\n!\n smallx = 1.0e-6_wp * rhoend\n np = n + 1\n nptm = npt - np\n if (n <= 1) then\n print 10\n10 format (/ 4 x, 'Return from LINCOA because N is less than 2.')\n return\n end if\n if (npt < n+2 .or. npt > ((n+2)*np)/2) then\n print 20\n20 format (/ 4 x, 'Return from LINCOA because NPT is not in',&\n ' the required interval.')\n return\n end if\n if (maxfun <= npt) then\n print 30\n30 format (/ 4 x, 'Return from LINCOA because MAXFUN is less', ' than NPT+1.')\n return\n end if\n!\n! Normalize the constraints, and copy the resultant constraint matrix\n! and right hand sides into working space, after increasing the right\n! hand sides if necessary so that the starting point is feasible.\n!\n iamat = max (m+3*n, 2*m+n, 2*npt) + 1\n ib = iamat + m * n\n iflag = 0\n if (m > 0) then\n iw = iamat - 1\n do j = 1, m\n sum = zero\n temp = zero\n do i = 1, n\n sum = sum + a (i, j) * x (i)\n temp = temp + a (i, j) ** 2\n end do\n if (temp == zero) then\n print 50\n50 format (/ 4 x, 'Return from LINCOA because the gradient of',&\n ' a constraint is zero.')\n return\n end if\n temp = sqrt (temp)\n if (sum-b(j) > smallx*temp) iflag = 1\n w (ib+j-1) = max (b(j), sum) / temp\n do i = 1, n\n iw = iw + 1\n w (iw) = a (i, j) / temp\n end do\n end do\n end if\n if (iflag == 1) then\n if (iprint > 0) print 70\n70 format (/ 4 x, 'LINCOA has made the initial X feasible by',&\n ' increasing part(s) of B.')\n end if\n!\n! Partition the working space array, so that different parts of it can be\n! treated separately by the subroutine that performs the main calculation.\n!\n ndim = npt + n\n ixb = ib + m\n ixp = ixb + n\n ifv = ixp + n * npt\n ixs = ifv + npt\n ixo = ixs + n\n igo = ixo + n\n ihq = igo + n\n ipq = ihq + (n*np) / 2\n ibmat = ipq + npt\n izmat = ibmat + ndim * n\n istp = izmat + npt * nptm\n isp = istp + n\n ixn = isp + npt + npt\n iac = ixn + n\n irc = iac + n\n iqf = irc + m\n irf = iqf + n * n\n ipqw = irf + (n*np) / 2\n!\n! The above settings provide a partition of W for subroutine LINCOB.\n!\n call lincob (n, npt, m, w(iamat), w(ib), x, rhobeg, rhoend, iprint, maxfun, &\n w(ixb), w(ixp), w(ifv), w(ixs), w(ixo), w(igo), w(ihq), w(ipq), &\n w(ibmat), w(izmat), ndim, w(istp), w(isp), w(ixn), iact, w(irc), &\n w(iqf), w(irf), w(ipqw), w, calfun)\n\n deallocate(w)\n\n end subroutine lincoa\n!*****************************************************************************************\n\n subroutine lincob (n, npt, m, amat, b, x, rhobeg, rhoend, iprint, maxfun, xbase, xpt, &\n fval, xsav, xopt, gopt, hq, pq, bmat, zmat, ndim, step, sp, xnew, &\n iact, rescon, qfac, rfac, pqw, w, calfun)\n\n implicit real (wp) (a-h, o-z)\n\n dimension amat (n,*), b (*), x (*), xbase (*), xpt (npt,*), fval (*), xsav (*), &\n xopt (*), gopt (*), hq (*), pq (*), bmat (ndim,*), zmat (npt,*), &\n step (*), sp (*), xnew (*), iact (*), rescon (*), qfac (n,*), rfac (*), &\n pqw (*), w (*)\n procedure (func) :: calfun\n!\n! The arguments N, NPT, M, X, RHOBEG, RHOEND, IPRINT and MAXFUN are\n! identical to the corresponding arguments in SUBROUTINE LINCOA.\n! AMAT is a matrix whose columns are the constraint gradients, scaled\n! so that they have unit length.\n! B contains on entry the right hand sides of the constraints, scaled\n! as above, but later B is modified for variables relative to XBASE.\n! XBASE holds a shift of origin that should reduce the contributions\n! from rounding errors to values of the model and Lagrange functions.\n! XPT contains the interpolation point coordinates relative to XBASE.\n! FVAL holds the values of F at the interpolation points.\n! XSAV holds the best feasible vector of variables so far, without any\n! shift of origin.\n! XOPT is set to XSAV-XBASE, which is the displacement from XBASE of\n! the feasible vector of variables that provides the least calculated\n! F so far, this vector being the current trust region centre.\n! GOPT holds the gradient of the quadratic model at XSAV = XBASE+XOPT.\n! HQ holds the explicit second derivatives of the quadratic model.\n! PQ contains the parameters of the implicit second derivatives of the\n! quadratic model.\n! BMAT holds the last N columns of the big inverse matrix H.\n! ZMAT holds the factorization of the leading NPT by NPT submatrix\n! of H, this factorization being ZMAT times Diag(DZ) times ZMAT^T,\n! where the elements of DZ are plus or minus one, as specified by IDZ.\n! NDIM is the first dimension of BMAT and has the value NPT+N.\n! STEP is employed for trial steps from XOPT. It is also used for working\n! space when XBASE is shifted and in PRELIM.\n! SP is reserved for the scalar products XOPT^T XPT(K,.), K=1,2,...,NPT,\n! followed by STEP^T XPT(K,.), K=1,2,...,NPT.\n! XNEW is the displacement from XBASE of the vector of variables for\n! the current calculation of F, except that SUBROUTINE TRSTEP uses it\n! for working space.\n! IACT is an integer array for the indices of the active constraints.\n! RESCON holds useful information about the constraint residuals. Every\n! nonnegative RESCON(J) is the residual of the J-th constraint at the\n! current trust region centre. Otherwise, if RESCON(J) is negative, the\n! J-th constraint holds as a strict inequality at the trust region\n! centre, its residual being at least |RESCON(J)|; further, the value\n! of |RESCON(J)| is at least the current trust region radius DELTA.\n! QFAC is the orthogonal part of the QR factorization of the matrix of\n! active constraint gradients, these gradients being ordered in\n! accordance with IACT. When NACT is less than N, columns are added\n! to QFAC to complete an N by N orthogonal matrix, which is important\n! for keeping calculated steps sufficiently close to the boundaries\n! of the active constraints.\n! RFAC is the upper triangular part of this QR factorization, beginning\n! with the first diagonal element, followed by the two elements in the\n! upper triangular part of the second column and so on.\n! PQW is used for working space, mainly for storing second derivative\n! coefficients of quadratic functions. Its length is NPT+N.\n! The array W is also used for working space. The required number of\n! elements, namely MAX[M+3*N,2*M+N,2*NPT], is set in LINCOA.\n!\n! Set some constants.\n!\n real(wp),parameter :: half = 0.5_wp\n real(wp),parameter :: one = 1.0_wp\n real(wp),parameter :: tenth = 0.1_wp\n real(wp),parameter :: zero = 0.0_wp\n\n np = n + 1\n nh = (n*np) / 2\n nptm = npt - np\n!\n! Set the elements of XBASE, XPT, FVAL, XSAV, XOPT, GOPT, HQ, PQ, BMAT,\n! ZMAT and SP for the first iteration. An important feature is that,\n! if the interpolation point XPT(K,.) is not feasible, where K is any\n! integer from [1,NPT], then a change is made to XPT(K,.) if necessary\n! so that the constraint violation is at least 0.2*RHOBEG. Also KOPT\n! is set so that XPT(KOPT,.) is the initial trust region centre.\n!\n call prelim (n, npt, m, amat, b, x, rhobeg, iprint, xbase, xpt, fval, xsav, xopt, &\n gopt, kopt, hq, pq, bmat, zmat, idz, ndim, sp, rescon, step, pqw, w, &\n calfun)\n!\n! Begin the iterative procedure.\n!\n nf = npt\n fopt = fval (kopt)\n rho = rhobeg\n delta = rho\n ifeas = 0\n nact = 0\n itest = 3\n10 knew = 0\n nvala = 0\n nvalb = 0\n!\n! Shift XBASE if XOPT may be too far from XBASE. First make the changes\n! to BMAT that do not depend on ZMAT.\n!\n20 fsave = fopt\n xoptsq = zero\n do i = 1, n\n xoptsq = xoptsq + xopt (i) ** 2\n end do\n if (xoptsq >= 1.0e4_wp*delta*delta) then\n qoptsq = 0.25_wp * xoptsq\n do k = 1, npt\n sum = zero\n do i = 1, n\n sum = sum + xpt (k, i) * xopt (i)\n end do\n sum = sum - half * xoptsq\n w (npt+k) = sum\n sp (k) = zero\n do i = 1, n\n xpt (k, i) = xpt (k, i) - half * xopt (i)\n step (i) = bmat (k, i)\n w (i) = sum * xpt (k, i) + qoptsq * xopt (i)\n ip = npt + i\n do j = 1, i\n bmat (ip, j) = bmat (ip, j) + step (i) * w (j) + w (i) * step (j)\n end do\n end do\n end do\n!\n! Then the revisions of BMAT that depend on ZMAT are calculated.\n!\n do k = 1, nptm\n sumz = zero\n do i = 1, npt\n sumz = sumz + zmat (i, k)\n w (i) = w (npt+i) * zmat (i, k)\n end do\n do j = 1, n\n sum = qoptsq * sumz * xopt (j)\n do i = 1, npt\n sum = sum + w (i) * xpt (i, j)\n end do\n step (j) = sum\n if (k < idz) sum = - sum\n do i = 1, npt\n bmat (i, j) = bmat (i, j) + sum * zmat (i, k)\n end do\n end do\n do i = 1, n\n ip = i + npt\n temp = step (i)\n if (k < idz) temp = - temp\n do j = 1, i\n bmat (ip, j) = bmat (ip, j) + temp * step (j)\n end do\n end do\n end do\n!\n! Update the right hand sides of the constraints.\n!\n if (m > 0) then\n do j = 1, m\n temp = zero\n do i = 1, n\n temp = temp + amat (i, j) * xopt (i)\n end do\n b (j) = b (j) - temp\n end do\n end if\n!\n! The following instructions complete the shift of XBASE, including the\n! changes to the parameters of the quadratic model.\n!\n ih = 0\n do j = 1, n\n w (j) = zero\n do k = 1, npt\n w (j) = w (j) + pq (k) * xpt (k, j)\n xpt (k, j) = xpt (k, j) - half * xopt (j)\n end do\n do i = 1, j\n ih = ih + 1\n hq (ih) = hq (ih) + w (i) * xopt (j) + xopt (i) * w (j)\n bmat (npt+i, j) = bmat (npt+j, i)\n end do\n end do\n do j = 1, n\n xbase (j) = xbase (j) + xopt (j)\n xopt (j) = zero\n xpt (kopt, j) = zero\n end do\n end if\n!\n! In the case KNEW=0, generate the next trust region step by calling\n! TRSTEP, where SNORM is the current trust region radius initially.\n! The final value of SNORM is the length of the calculated step,\n! except that SNORM is zero on return if the projected gradient is\n! unsuitable for starting the conjugate gradient iterations.\n!\n delsav = delta\n ksave = knew\n if (knew == 0) then\n snorm = delta\n do i = 1, n\n xnew (i) = gopt (i)\n end do\n call trstep (n, npt, m, amat, b, xpt, hq, pq, nact, iact, rescon, qfac, rfac, &\n snorm, step, xnew, w, w(m+1), pqw, pqw(np), w(m+np))\n!\n! A trust region step is applied whenever its length, namely SNORM, is at\n! least HALF*DELTA. It is also applied if its length is at least 0.1999\n! times DELTA and if a line search of TRSTEP has caused a change to the\n! active set. Otherwise there is a branch below to label 530 or 560.\n!\n temp = half * delta\n if (xnew(1) >= half) temp = 0.1999_wp * delta\n if (snorm <= temp) then\n delta = half * delta\n if (delta <= 1.4_wp*rho) delta = rho\n nvala = nvala + 1\n nvalb = nvalb + 1\n temp = snorm / rho\n if (delsav > rho) temp = one\n if (temp >= half) nvala = zero\n if (temp >= tenth) nvalb = zero\n if (delsav > rho) go to 530\n if (nvala < 5 .and. nvalb < 3) go to 530\n if (snorm > zero) ksave = - 1\n go to 560\n end if\n nvala = zero\n nvalb = zero\n!\n! Alternatively, KNEW is positive. Then the model step is calculated\n! within a trust region of radius DEL, after setting the gradient at\n! XBASE and the second derivative parameters of the KNEW-th Lagrange\n! function in W(1) to W(N) and in PQW(1) to PQW(NPT), respectively.\n!\n else\n del = max (tenth*delta, rho)\n do i = 1, n\n w (i) = bmat (knew, i)\n end do\n do k = 1, npt\n pqw (k) = zero\n end do\n do j = 1, nptm\n temp = zmat (knew, j)\n if (j < idz) temp = - temp\n do k = 1, npt\n pqw (k) = pqw (k) + temp * zmat (k, j)\n end do\n end do\n call qmstep (n, npt, m, amat, b, xpt, xopt, nact, iact, rescon, qfac, kopt, &\n knew, del, step, w, pqw, w(np), w(np+m), ifeas)\n end if\n!\n! Set VQUAD to the change to the quadratic model when the move STEP is\n! made from XOPT. If STEP is a trust region step, then VQUAD should be\n! negative. If it is nonnegative due to rounding errors in this case,\n! there is a branch to label 530 to try to improve the model.\n!\n vquad = zero\n ih = 0\n do j = 1, n\n vquad = vquad + step (j) * gopt (j)\n do i = 1, j\n ih = ih + 1\n temp = step (i) * step (j)\n if (i == j) temp = half * temp\n vquad = vquad + temp * hq (ih)\n end do\n end do\n do k = 1, npt\n temp = zero\n do j = 1, n\n temp = temp + xpt (k, j) * step (j)\n sp (npt+k) = temp\n end do\n vquad = vquad + half * pq (k) * temp * temp\n end do\n if (ksave == 0 .and. vquad >= zero) go to 530\n!\n! Calculate the next value of the objective function. The difference\n! between the actual new value of F and the value predicted by the\n! model is recorded in DIFF.\n!\n220 nf = nf + 1\n if (nf > maxfun) then\n nf = nf - 1\n if (iprint > 0) print 230\n230 format (/ 4 x, 'Return from LINCOA because CALFUN has been',&\n ' called MAXFUN times.')\n go to 600\n end if\n xdiff = zero\n do i = 1, n\n xnew (i) = xopt (i) + step (i)\n x (i) = xbase (i) + xnew (i)\n xdiff = xdiff + (x(i)-xsav(i)) ** 2\n end do\n xdiff = sqrt (xdiff)\n if (ksave ==-1) xdiff = rho\n if (xdiff <= tenth*rho .or. xdiff >= delta+delta) then\n ifeas = 0\n if (iprint > 0) print 250\n250 format (/ 4 x, 'Return from LINCOA because rounding errors',&\n ' prevent reasonable changes to X.')\n go to 600\n end if\n if (ksave <= 0) ifeas = 1\n f = real (ifeas, wp)\n call calfun (n, x, f)\n if (iprint == 3) then\n print 260, nf, f, (x(i), i=1, n)\n260 format (/ 4 x, 'Function number', i6, ' F =', 1 pd18.10,&\n ' The corresponding X is:' / (2 x, 5d15.6))\n end if\n if (ksave ==-1) go to 600\n diff = f - fopt - vquad\n!\n! If X is feasible, then set DFFALT to the difference between the new\n! value of F and the value predicted by the alternative model.\n!\n if (ifeas == 1 .and. itest < 3) then\n do k = 1, npt\n pqw (k) = zero\n w (k) = fval (k) - fval (kopt)\n end do\n do j = 1, nptm\n sum = zero\n do i = 1, npt\n sum = sum + w (i) * zmat (i, j)\n end do\n if (j < idz) sum = - sum\n do k = 1, npt\n pqw (k) = pqw (k) + sum * zmat (k, j)\n end do\n end do\n vqalt = zero\n do k = 1, npt\n sum = zero\n do j = 1, n\n sum = sum + bmat (k, j) * step (j)\n end do\n vqalt = vqalt + sum * w (k)\n vqalt = vqalt + pqw (k) * sp (npt+k) * (half*sp(npt+k)+sp(k))\n end do\n dffalt = f - fopt - vqalt\n end if\n if (itest == 3) then\n dffalt = diff\n itest = 0\n end if\n!\n! Pick the next value of DELTA after a trust region step.\n!\n if (ksave == 0) then\n ratio = (f-fopt) / vquad\n if (ratio <= tenth) then\n delta = half * delta\n else if (ratio <= 0.7_wp) then\n delta = max (half*delta, snorm)\n else\n temp = sqrt (2.0_wp) * delta\n delta = max (half*delta, snorm+snorm)\n delta = min (delta, temp)\n end if\n if (delta <= 1.4_wp*rho) delta = rho\n end if\n!\n! Update BMAT, ZMAT and IDZ, so that the KNEW-th interpolation point\n! can be moved. If STEP is a trust region step, then KNEW is zero at\n! present, but a positive value is picked by subroutine UPDATE.\n!\n call update (n, npt, xpt, bmat, zmat, idz, ndim, sp, step, kopt, knew, pqw, w)\n if (knew == 0) then\n if (iprint > 0) print 320\n320 format (/ 4 x, &\n 'Return from LINCOA because the denominator of the updating formula is zero.')\n go to 600\n end if\n!\n! If ITEST is increased to 3, then the next quadratic model is the\n! one whose second derivative matrix is least subject to the new\n! interpolation conditions. Otherwise the new model is constructed\n! by the symmetric Broyden method in the usual way.\n!\n if (ifeas == 1) then\n itest = itest + 1\n if (abs(dffalt) >= tenth*abs(diff)) itest = 0\n end if\n!\n! Update the second derivatives of the model by the symmetric Broyden\n! method, using PQW for the second derivative parameters of the new\n! KNEW-th Lagrange function. The contribution from the old parameter\n! PQ(KNEW) is included in the second derivative matrix HQ. W is used\n! later for the gradient of the new KNEW-th Lagrange function.\n!\n if (itest < 3) then\n do k = 1, npt\n pqw (k) = zero\n end do\n do j = 1, nptm\n temp = zmat (knew, j)\n if (temp /= zero) then\n if (j < idz) temp = - temp\n do k = 1, npt\n pqw (k) = pqw (k) + temp * zmat (k, j)\n end do\n end if\n end do\n ih = 0\n do i = 1, n\n w (i) = bmat (knew, i)\n temp = pq (knew) * xpt (knew, i)\n do j = 1, i\n ih = ih + 1\n hq (ih) = hq (ih) + temp * xpt (knew, j)\n end do\n end do\n pq (knew) = zero\n do k = 1, npt\n pq (k) = pq (k) + diff * pqw (k)\n end do\n end if\n!\n! Include the new interpolation point with the corresponding updates of\n! SP. Also make the changes of the symmetric Broyden method to GOPT at\n! the old XOPT if ITEST is less than 3.\n!\n fval (knew) = f\n sp (knew) = sp (kopt) + sp (npt+kopt)\n ssq = zero\n do i = 1, n\n xpt (knew, i) = xnew (i)\n ssq = ssq + step (i) ** 2\n end do\n sp (npt+knew) = sp (npt+kopt) + ssq\n if (itest < 3) then\n do k = 1, npt\n temp = pqw (k) * sp (k)\n do i = 1, n\n w (i) = w (i) + temp * xpt (k, i)\n end do\n end do\n do i = 1, n\n gopt (i) = gopt (i) + diff * w (i)\n end do\n end if\n!\n! Update FOPT, XSAV, XOPT, KOPT, RESCON and SP if the new F is the\n! least calculated value so far with a feasible vector of variables.\n!\n if (f < fopt .and. ifeas == 1) then\n fopt = f\n do j = 1, n\n xsav (j) = x (j)\n xopt (j) = xnew (j)\n end do\n kopt = knew\n snorm = sqrt (ssq)\n do j = 1, m\n if (rescon(j) >= delta+snorm) then\n rescon (j) = snorm - rescon (j)\n else\n rescon (j) = rescon (j) + snorm\n if (rescon(j)+delta > zero) then\n temp = b (j)\n do i = 1, n\n temp = temp - xopt (i) * amat (i, j)\n end do\n temp = max (temp, zero)\n if (temp >= delta) temp = - temp\n rescon (j) = temp\n end if\n end if\n end do\n do k = 1, npt\n sp (k) = sp (k) + sp (npt+k)\n end do\n!\n! Also revise GOPT when symmetric Broyden updating is applied.\n!\n if (itest < 3) then\n ih = 0\n do j = 1, n\n do i = 1, j\n ih = ih + 1\n if (i < j) gopt (j) = gopt (j) + hq (ih) * step (i)\n gopt (i) = gopt (i) + hq (ih) * step (j)\n end do\n end do\n do k = 1, npt\n temp = pq (k) * sp (npt+k)\n do i = 1, n\n gopt (i) = gopt (i) + temp * xpt (k, i)\n end do\n end do\n end if\n end if\n!\n! Replace the current model by the least Frobenius norm interpolant if\n! this interpolant gives substantial reductions in the predictions\n! of values of F at feasible points.\n!\n if (itest == 3) then\n do k = 1, npt\n pq (k) = zero\n w (k) = fval (k) - fval (kopt)\n end do\n do j = 1, nptm\n sum = zero\n do i = 1, npt\n sum = sum + w (i) * zmat (i, j)\n end do\n if (j < idz) sum = - sum\n do k = 1, npt\n pq (k) = pq (k) + sum * zmat (k, j)\n end do\n end do\n do j = 1, n\n gopt (j) = zero\n do i = 1, npt\n gopt (j) = gopt (j) + w (i) * bmat (i, j)\n end do\n end do\n do k = 1, npt\n temp = pq (k) * sp (k)\n do i = 1, n\n gopt (i) = gopt (i) + temp * xpt (k, i)\n end do\n end do\n do ih = 1, nh\n hq (ih) = zero\n end do\n end if\n!\n! If a trust region step has provided a sufficient decrease in F, then\n! branch for another trust region calculation. Every iteration that\n! takes a model step is followed by an attempt to take a trust region\n! step.\n!\n knew = 0\n if (ksave > 0) go to 20\n if (ratio >= tenth) go to 20\n!\n! Alternatively, find out if the interpolation points are close enough\n! to the best point so far.\n!\n530 distsq = max (delta*delta, 4.0_wp*rho*rho)\n do k = 1, npt\n sum = zero\n do j = 1, n\n sum = sum + (xpt(k, j)-xopt(j)) ** 2\n end do\n if (sum > distsq) then\n knew = k\n distsq = sum\n end if\n end do\n!\n! If KNEW is positive, then branch back for the next iteration, which\n! will generate a \"model step\". Otherwise, if the current iteration\n! has reduced F, or if DELTA was above its lower bound when the last\n! trust region step was calculated, then try a \"trust region\" step\n! instead.\n!\n if (knew > 0) go to 20\n knew = 0\n if (fopt < fsave) go to 20\n if (delsav > rho) go to 20\n!\n! The calculations with the current value of RHO are complete.\n! Pick the next value of RHO.\n!\n560 if (rho > rhoend) then\n delta = half * rho\n if (rho > 250.0_wp*rhoend) then\n rho = tenth * rho\n else if (rho <= 16.0_wp*rhoend) then\n rho = rhoend\n else\n rho = sqrt (rho*rhoend)\n end if\n delta = max (delta, rho)\n if (iprint >= 2) then\n if (iprint >= 3) print 570\n570 format (5 x)\n print 580, rho, nf\n580 format (/ 4 x, 'New RHO =', 1 pd11.4, 5 x, 'Number of',&\n ' function values =', i6)\n print 590, fopt, (xbase(i)+xopt(i), i=1, n)\n590 format (4 x, 'Least value of F =', 1 pd23.15, 9 x,&\n 'The corresponding X is:'/(2 x, 5d15.6))\n end if\n go to 10\n end if\n!\n! Return from the calculation, after branching to label 220 for another\n! Newton-Raphson step if it has not been tried before.\n!\n if (ksave ==-1) go to 220\n600 if (fopt <= f .or. ifeas == 0) then\n do i = 1, n\n x (i) = xsav (i)\n end do\n f = fopt\n end if\n if (iprint >= 1) then\n print 620, nf\n620 format (/ 4 x, 'At the return from LINCOA', 5 x,&\n 'Number of function values =', i6)\n print 590, f, (x(i), i=1, n)\n end if\n w (1) = f\n w (2) = real (nf, wp) + half\n\n end subroutine lincob\n\n subroutine getact (n, m, amat, b, nact, iact, qfac, rfac, snorm, resnew, resact, g, &\n dw, vlam, w)\n\n implicit real (wp) (a-h, o-z)\n\n dimension amat (n,*), b (*), iact (*), qfac (n,*), rfac (*), resnew (*), &\n resact (*), g (*), dw (*), vlam (*), w (*)\n!\n! N, M, AMAT, B, NACT, IACT, QFAC and RFAC are the same as the terms\n! with these names in SUBROUTINE LINCOB. The current values must be\n! set on entry. NACT, IACT, QFAC and RFAC are kept up to date when\n! GETACT changes the current active set.\n! SNORM, RESNEW, RESACT, G and DW are the same as the terms with these\n! names in SUBROUTINE TRSTEP. The elements of RESNEW and RESACT are\n! also kept up to date.\n! VLAM and W are used for working space, the vector VLAM being reserved\n! for the Lagrange multipliers of the calculation. Their lengths must\n! be at least N.\n! The main purpose of GETACT is to pick the current active set. It is\n! defined by the property that the projection of -G into the space\n! orthogonal to the active constraint normals is as large as possible,\n! subject to this projected steepest descent direction moving no closer\n! to the boundary of every constraint whose current residual is at most\n! 0.2*SNORM. On return, the settings in NACT, IACT, QFAC and RFAC are\n! all appropriate to this choice of active set.\n! Occasionally this projected direction is zero, and then the final value\n! of W(1) is set to zero. Otherwise, the direction itself is returned\n! in DW, and W(1) is set to the square of the length of the direction.\n\n!\n! Set some constants and a temporary VLAM.\n!\n real(wp),parameter :: one = 1.0_wp\n real(wp),parameter :: tiny = 1.0e-60_wp\n real(wp),parameter :: zero = 0.0_wp\n\n tdel = 0.2_wp * snorm\n ddsav = zero\n do i = 1, n\n ddsav = ddsav + g (i) ** 2\n vlam (i) = zero\n end do\n ddsav = ddsav + ddsav\n!\n! Set the initial QFAC to the identity matrix in the case NACT=0.\n!\n if (nact == 0) then\n do i = 1, n\n do j = 1, n\n qfac (i, j) = zero\n end do\n qfac (i, i) = one\n end do\n go to 100\n end if\n!\n! Remove any constraints from the initial active set whose residuals\n! exceed TDEL.\n!\n iflag = 1\n ic = nact\n40 if (resact(ic) > tdel) go to 800\n50 ic = ic - 1\n if (ic > 0) go to 40\n!\n! Remove any constraints from the initial active set whose Lagrange\n! multipliers are nonnegative, and set the surviving multipliers.\n!\n iflag = 2\n60 if (nact == 0) go to 100\n ic = nact\n70 temp = zero\n do i = 1, n\n temp = temp + qfac (i, ic) * g (i)\n end do\n idiag = (ic*ic+ic) / 2\n if (ic < nact) then\n jw = idiag + ic\n do j = ic + 1, nact\n temp = temp - rfac (jw) * vlam (j)\n jw = jw + j\n end do\n end if\n if (temp >= zero) go to 800\n vlam (ic) = temp / rfac (idiag)\n ic = ic - 1\n if (ic > 0) go to 70\n!\n! Set the new search direction D. Terminate if the 2-norm of D is zero\n! or does not decrease, or if NACT=N holds. The situation NACT=N\n! occurs for sufficiently large SNORM if the origin is in the convex\n! hull of the constraint gradients.\n!\n100 if (nact == n) go to 290\n do j = nact + 1, n\n w (j) = zero\n do i = 1, n\n w (j) = w (j) + qfac (i, j) * g (i)\n end do\n end do\n dd = zero\n do i = 1, n\n dw (i) = zero\n do j = nact + 1, n\n dw (i) = dw (i) - w (j) * qfac (i, j)\n end do\n dd = dd + dw (i) ** 2\n end do\n if (dd >= ddsav) go to 290\n if (dd == zero) go to 300\n ddsav = dd\n dnorm = sqrt (dd)\n!\n! Pick the next integer L or terminate, a positive value of L being\n! the index of the most violated constraint. The purpose of CTOL\n! below is to estimate whether a positive value of VIOLMX may be\n! due to computer rounding errors.\n!\n l = 0\n if (m > 0) then\n test = dnorm / snorm\n violmx = zero\n do j = 1, m\n if (resnew(j) > zero .and. resnew(j) <= tdel) then\n sum = zero\n do i = 1, n\n sum = sum + amat (i, j) * dw (i)\n end do\n if (sum > test*resnew(j)) then\n if (sum > violmx) then\n l = j\n violmx = sum\n end if\n end if\n end if\n end do\n ctol = zero\n temp = 0.01_wp * dnorm\n if (violmx > zero .and. violmx < temp) then\n if (nact > 0) then\n do k = 1, nact\n j = iact (k)\n sum = zero\n do i = 1, n\n sum = sum + dw (i) * amat (i, j)\n end do\n ctol = max (ctol, abs(sum))\n end do\n end if\n end if\n end if\n w (1) = one\n if (l == 0) go to 300\n if (violmx <= 10.0_wp*ctol) go to 300\n!\n! Apply Givens rotations to the last (N-NACT) columns of QFAC so that\n! the first (NACT+1) columns of QFAC are the ones required for the\n! addition of the L-th constraint, and add the appropriate column\n! to RFAC.\n!\n nactp = nact + 1\n idiag = (nactp*nactp-nactp) / 2\n rdiag = zero\n do j = n, 1, - 1\n sprod = zero\n do i = 1, n\n sprod = sprod + qfac (i, j) * amat (i, l)\n end do\n if (j <= nact) then\n rfac (idiag+j) = sprod\n else\n if (abs(rdiag) <= 1.0e-20_wp*abs(sprod)) then\n rdiag = sprod\n else\n temp = sqrt (sprod*sprod+rdiag*rdiag)\n cosv = sprod / temp\n sinv = rdiag / temp\n rdiag = temp\n do i = 1, n\n temp = cosv * qfac (i, j) + sinv * qfac (i, j+1)\n qfac (i, j+1) = - sinv * qfac (i, j) + cosv * qfac (i, j+1)\n qfac (i, j) = temp\n end do\n end if\n end if\n end do\n if (rdiag < zero) then\n do i = 1, n\n qfac (i, nactp) = - qfac (i, nactp)\n end do\n end if\n rfac (idiag+nactp) = abs (rdiag)\n nact = nactp\n iact (nact) = l\n resact (nact) = resnew (l)\n vlam (nact) = zero\n resnew (l) = zero\n!\n! Set the components of the vector VMU in W.\n!\n220 w (nact) = one / rfac ((nact*nact+nact)/2) ** 2\n if (nact > 1) then\n do i = nact - 1, 1, - 1\n idiag = (i*i+i) / 2\n jw = idiag + i\n sum = zero\n do j = i + 1, nact\n sum = sum - rfac (jw) * w (j)\n jw = jw + j\n end do\n w (i) = sum / rfac (idiag)\n end do\n end if\n!\n! Calculate the multiple of VMU to subtract from VLAM, and update VLAM.\n!\n vmult = violmx\n ic = 0\n j = 1\n250 if (j < nact) then\n if (vlam(j) >= vmult*w(j)) then\n ic = j\n vmult = vlam (j) / w (j)\n end if\n j = j + 1\n go to 250\n end if\n do j = 1, nact\n vlam (j) = vlam (j) - vmult * w (j)\n end do\n if (ic > 0) vlam (ic) = zero\n violmx = max (violmx-vmult, zero)\n if (ic == 0) violmx = zero\n!\n! Reduce the active set if necessary, so that all components of the\n! new VLAM are negative, with resetting of the residuals of the\n! constraints that become inactive.\n!\n iflag = 3\n ic = nact\n270 if (vlam(ic) < zero) go to 280\n resnew (iact(ic)) = max (resact(ic), tiny)\n go to 800\n280 ic = ic - 1\n if (ic > 0) go to 270\n!\n! Calculate the next VMU if VIOLMX is positive. Return if NACT=N holds,\n! as then the active constraints imply D=0. Otherwise, go to label\n! 100, to calculate the new D and to test for termination.\n!\n if (violmx > zero) go to 220\n if (nact < n) go to 100\n290 dd = zero\n300 w (1) = dd\n return\n!\n! These instructions rearrange the active constraints so that the new\n! value of IACT(NACT) is the old value of IACT(IC). A sequence of\n! Givens rotations is applied to the current QFAC and RFAC. Then NACT\n! is reduced by one.\n!\n800 resnew (iact(ic)) = max (resact(ic), tiny)\n jc = ic\n810 if (jc < nact) then\n jcp = jc + 1\n idiag = jc * jcp / 2\n jw = idiag + jcp\n temp = sqrt (rfac(jw-1)**2+rfac(jw)**2)\n cval = rfac (jw) / temp\n sval = rfac (jw-1) / temp\n rfac (jw-1) = sval * rfac (idiag)\n rfac (jw) = cval * rfac (idiag)\n rfac (idiag) = temp\n if (jcp < nact) then\n do j = jcp + 1, nact\n temp = sval * rfac (jw+jc) + cval * rfac (jw+jcp)\n rfac (jw+jcp) = cval * rfac (jw+jc) - sval * rfac (jw+jcp)\n rfac (jw+jc) = temp\n jw = jw + j\n end do\n end if\n jdiag = idiag - jc\n do i = 1, n\n if (i < jc) then\n temp = rfac (idiag+i)\n rfac (idiag+i) = rfac (jdiag+i)\n rfac (jdiag+i) = temp\n end if\n temp = sval * qfac (i, jc) + cval * qfac (i, jcp)\n qfac (i, jcp) = cval * qfac (i, jc) - sval * qfac (i, jcp)\n qfac (i, jc) = temp\n end do\n iact (jc) = iact (jcp)\n resact (jc) = resact (jcp)\n vlam (jc) = vlam (jcp)\n jc = jcp\n go to 810\n end if\n nact = nact - 1\n go to (50, 60, 280), iflag\n\n end subroutine getact\n\n subroutine prelim (n, npt, m, amat, b, x, rhobeg, iprint, xbase, xpt, fval, xsav, &\n xopt, gopt, kopt, hq, pq, bmat, zmat, idz, ndim, sp, rescon, step, pqw, w, calfun)\n\n implicit real (wp) (a-h, o-z)\n\n dimension amat(n,*),b(*),x(*),xbase(*),xpt(npt,*),fval(*),xsav(*),&\n xopt(*),gopt(*),hq(*),pq(*),bmat(ndim,*),zmat(npt,*),sp(*),rescon(*),&\n step(*),pqw(*),w(*)\n procedure(func) :: calfun\n!\n! The arguments N, NPT, M, AMAT, B, X, RHOBEG, IPRINT, XBASE, XPT, FVAL,\n! XSAV, XOPT, GOPT, HQ, PQ, BMAT, ZMAT, NDIM, SP and RESCON are the\n! same as the corresponding arguments in SUBROUTINE LINCOB.\n! KOPT is set to the integer such that XPT(KOPT,.) is the initial trust\n! region centre.\n! IDZ is going to be set to one, so that every element of Diag(DZ) is\n! one in the product ZMAT times Diag(DZ) times ZMAT^T, which is the\n! factorization of the leading NPT by NPT submatrix of H.\n! STEP, PQW and W are used for working space, the arrays STEP and PQW\n! being taken from LINCOB. The length of W must be at least N+NPT.\n!\n! SUBROUTINE PRELIM provides the elements of XBASE, XPT, BMAT and ZMAT\n! for the first iteration, an important feature being that, if any of\n! of the columns of XPT is an infeasible point, then the largest of\n! the constraint violations there is at least 0.2*RHOBEG. It also sets\n! the initial elements of FVAL, XOPT, GOPT, HQ, PQ, SP and RESCON.\n!\n! Set some constants.\n!\n real(wp),parameter :: half = 0.5_wp\n real(wp),parameter :: one = 1.0_wp\n real(wp),parameter :: zero = 0.0_wp\n\n nptm = npt - n - 1\n rhosq = rhobeg * rhobeg\n recip = one / rhosq\n reciq = sqrt (half) / rhosq\n test = 0.2_wp * rhobeg\n idz = 1\n kbase = 1\n!\n! Set the initial elements of XPT, BMAT, SP and ZMAT to zero.\n!\n do j = 1, n\n xbase (j) = x (j)\n do k = 1, npt\n xpt (k, j) = zero\n end do\n do i = 1, ndim\n bmat (i, j) = zero\n end do\n end do\n do k = 1, npt\n sp (k) = zero\n do j = 1, npt - n - 1\n zmat (k, j) = zero\n end do\n end do\n!\n! Set the nonzero coordinates of XPT(K,.), K=1,2,...,min[2*N+1,NPT],\n! but they may be altered later to make a constraint violation\n! sufficiently large. The initial nonzero elements of BMAT and of\n! the first min[N,NPT-N-1] columns of ZMAT are set also.\n!\n do j = 1, n\n xpt (j+1, j) = rhobeg\n if (j < npt-n) then\n jp = n + j + 1\n xpt (jp, j) = - rhobeg\n bmat (j+1, j) = half / rhobeg\n bmat (jp, j) = - half / rhobeg\n zmat (1, j) = - reciq - reciq\n zmat (j+1, j) = reciq\n zmat (jp, j) = reciq\n else\n bmat (1, j) = - one / rhobeg\n bmat (j+1, j) = one / rhobeg\n bmat (npt+j, j) = - half * rhosq\n end if\n end do\n!\n! Set the remaining initial nonzero elements of XPT and ZMAT when the\n! number of interpolation points exceeds 2*N+1.\n!\n if (npt > 2*n+1) then\n do k = n + 1, npt - n - 1\n itemp = (k-1) / n\n ipt = k - itemp * n\n jpt = ipt + itemp\n if (jpt > n) jpt = jpt - n\n xpt (n+k+1, ipt) = rhobeg\n xpt (n+k+1, jpt) = rhobeg\n zmat (1, k) = recip\n zmat (ipt+1, k) = - recip\n zmat (jpt+1, k) = - recip\n zmat (n+k+1, k) = recip\n end do\n end if\n!\n! Update the constraint right hand sides to allow for the shift XBASE.\n!\n if (m > 0) then\n do j = 1, m\n temp = zero\n do i = 1, n\n temp = temp + amat (i, j) * xbase (i)\n end do\n b (j) = b (j) - temp\n end do\n end if\n!\n! Go through the initial points, shifting every infeasible point if\n! necessary so that its constraint violation is at least 0.2*RHOBEG.\n!\n do nf = 1, npt\n feas = one\n bigv = zero\n j = 0\n80 j = j + 1\n if (j <= m .and. nf >= 2) then\n resid = - b (j)\n do i = 1, n\n resid = resid + xpt (nf, i) * amat (i, j)\n end do\n if (resid <= bigv) go to 80\n bigv = resid\n jsav = j\n if (resid <= test) then\n feas = - one\n go to 80\n end if\n feas = zero\n end if\n if (feas < zero) then\n do i = 1, n\n step (i) = xpt (nf, i) + (test-bigv) * amat (i, jsav)\n end do\n do k = 1, npt\n sp (npt+k) = zero\n do j = 1, n\n sp (npt+k) = sp (npt+k) + xpt (k, j) * step (j)\n end do\n end do\n call update (n,npt,xpt,bmat,zmat,idz,ndim,sp,step,kbase,nf,pqw,w)\n do i = 1, n\n xpt (nf, i) = step (i)\n end do\n end if\n!\n! Calculate the objective function at the current interpolation point,\n! and set KOPT to the index of the first trust region centre.\n!\n do j = 1, n\n x (j) = xbase (j) + xpt (nf, j)\n end do\n f = feas\n call calfun (n, x, f)\n if (iprint == 3) then\n print 140, nf, f, (x(i), i=1, n)\n140 format (/ 4 x, 'Function number', i6, ' F =', 1 pd18.10,&\n ' The corresponding X is:' / (2 x, 5d15.6))\n end if\n if (nf == 1) then\n kopt = 1\n else if (f < fval(kopt) .and. feas > zero) then\n kopt = nf\n end if\n fval (nf) = f\n end do\n!\n! Set PQ for the first quadratic model.\n!\n do j = 1, nptm\n w (j) = zero\n do k = 1, npt\n w (j) = w (j) + zmat (k, j) * fval (k)\n end do\n end do\n do k = 1, npt\n pq (k) = zero\n do j = 1, nptm\n pq (k) = pq (k) + zmat (k, j) * w (j)\n end do\n end do\n!\n! Set XOPT, SP, GOPT and HQ for the first quadratic model.\n!\n do j = 1, n\n xopt (j) = xpt (kopt, j)\n xsav (j) = xbase (j) + xopt (j)\n gopt (j) = zero\n end do\n do k = 1, npt\n sp (k) = zero\n do j = 1, n\n sp (k) = sp (k) + xpt (k, j) * xopt (j)\n end do\n temp = pq (k) * sp (k)\n do j = 1, n\n gopt (j) = gopt (j) + fval (k) * bmat (k, j) + temp * xpt (k, j)\n end do\n end do\n do i = 1, (n*n+n) / 2\n hq (i) = zero\n end do\n!\n! Set the initial elements of RESCON.\n!\n do j = 1, m\n temp = b (j)\n do i = 1, n\n temp = temp - xopt (i) * amat (i, j)\n end do\n temp = max (temp, zero)\n if (temp >= rhobeg) temp = - temp\n rescon (j) = temp\n end do\n\n end subroutine prelim\n\n subroutine qmstep (n, npt, m, amat, b, xpt, xopt, nact, iact, rescon, qfac, kopt, &\n knew, del, step, gl, pqw, rstat, w, ifeas)\n\n implicit real (wp) (a-h, o-z)\n\n dimension amat (n,*), b (*), xpt (npt,*), xopt (*), iact (*), rescon (*), &\n qfac (n,*), step (*), gl (*), pqw (*), rstat (*), w (*)\n!\n! N, NPT, M, AMAT, B, XPT, XOPT, NACT, IACT, RESCON, QFAC, KOPT are the\n! same as the terms with these names in SUBROUTINE LINCOB.\n! KNEW is the index of the interpolation point that is going to be moved.\n! DEL is the current restriction on the length of STEP, which is never\n! greater than the current trust region radius DELTA.\n! STEP will be set to the required step from XOPT to the new point.\n! GL must be set on entry to the gradient of LFUNC at XBASE, where LFUNC\n! is the KNEW-th Lagrange function. It is used also for some other\n! gradients of LFUNC.\n! PQW provides the second derivative parameters of LFUNC.\n! RSTAT and W are used for working space. Their lengths must be at least\n! M and N, respectively. RSTAT(J) is set to -1.0, 0.0, or 1.0 if the\n! J-th constraint is irrelevant, active, or both inactive and relevant,\n! respectively.\n! IFEAS will be set to 0 or 1 if XOPT+STEP is infeasible or feasible.\n!\n! STEP is chosen to provide a relatively large value of the modulus of\n! LFUNC(XOPT+STEP), subject to ||STEP|| .LE. DEL. A projected STEP is\n! calculated too, within the trust region, that does not alter the\n! residuals of the active constraints. The projected step is preferred\n! if its value of | LFUNC(XOPT+STEP) | is at least one fifth of the\n! original one, but the greatest violation of a linear constraint must\n! be at least 0.2*DEL, in order to keep the interpolation points apart.\n! The remedy when the maximum constraint violation is too small is to\n! restore the original step, which is perturbed if necessary so that\n! its maximum constraint violation becomes 0.2*DEL.\n!\n! Set some constants.\n!\n real(wp),parameter :: half = 0.5_wp\n real(wp),parameter :: one = 1.0_wp\n real(wp),parameter :: tenth = 0.1_wp\n real(wp),parameter :: zero = 0.0_wp\n\n test = 0.2_wp * del\n!\n! Replace GL by the gradient of LFUNC at the trust region centre, and\n! set the elements of RSTAT.\n!\n do k = 1, npt\n temp = zero\n do j = 1, n\n temp = temp + xpt (k, j) * xopt (j)\n end do\n temp = pqw (k) * temp\n do i = 1, n\n gl (i) = gl (i) + temp * xpt (k, i)\n end do\n end do\n if (m > 0) then\n do j = 1, m\n rstat (j) = one\n if (abs(rescon(j)) >= del) rstat (j) = - one\n end do\n do k = 1, nact\n rstat (iact(k)) = zero\n end do\n end if\n!\n! Find the greatest modulus of LFUNC on a line through XOPT and\n! another interpolation point within the trust region.\n!\n iflag = 0\n vbig = zero\n do k = 1, npt\n if (k == kopt) cycle\n ss = zero\n sp = zero\n do i = 1, n\n temp = xpt (k, i) - xopt (i)\n ss = ss + temp * temp\n sp = sp + gl (i) * temp\n end do\n stp = - del / sqrt (ss)\n if (k == knew) then\n if (sp*(sp-one) < zero) stp = - stp\n vlag = abs (stp*sp) + stp * stp * abs (sp-one)\n else\n vlag = abs (stp*(one-stp)*sp)\n end if\n if (vlag > vbig) then\n ksav = k\n stpsav = stp\n vbig = vlag\n end if\n end do\n!\n! Set STEP to the move that gives the greatest modulus calculated above.\n! This move may be replaced by a steepest ascent step from XOPT.\n!\n gg = zero\n do i = 1, n\n gg = gg + gl (i) ** 2\n step (i) = stpsav * (xpt(ksav, i)-xopt(i))\n end do\n vgrad = del * sqrt (gg)\n if (vgrad <= tenth*vbig) go to 220\n!\n! Make the replacement if it provides a larger value of VBIG.\n!\n ghg = zero\n do k = 1, npt\n temp = zero\n do j = 1, n\n temp = temp + xpt (k, j) * gl (j)\n end do\n ghg = ghg + pqw (k) * temp * temp\n end do\n vnew = vgrad + abs (half*del*del*ghg/gg)\n if (vnew > vbig) then\n vbig = vnew\n stp = del / sqrt (gg)\n if (ghg < zero) stp = - stp\n do i = 1, n\n step (i) = stp * gl (i)\n end do\n end if\n if (nact == 0 .or. nact == n) go to 220\n!\n! Overwrite GL by its projection. Then set VNEW to the greatest\n! value of |LFUNC| on the projected gradient from XOPT subject to\n! the trust region bound. If VNEW is sufficiently large, then STEP\n! may be changed to a move along the projected gradient.\n!\n do k = nact + 1, n\n w (k) = zero\n do i = 1, n\n w (k) = w (k) + gl (i) * qfac (i, k)\n end do\n end do\n gg = zero\n do i = 1, n\n gl (i) = zero\n do k = nact + 1, n\n gl (i) = gl (i) + qfac (i, k) * w (k)\n end do\n gg = gg + gl (i) ** 2\n end do\n vgrad = del * sqrt (gg)\n if (vgrad <= tenth*vbig) go to 220\n ghg = zero\n do k = 1, npt\n temp = zero\n do j = 1, n\n temp = temp + xpt (k, j) * gl (j)\n end do\n ghg = ghg + pqw (k) * temp * temp\n end do\n vnew = vgrad + abs (half*del*del*ghg/gg)\n!\n! Set W to the possible move along the projected gradient.\n!\n stp = del / sqrt (gg)\n if (ghg < zero) stp = - stp\n ww = zero\n do i = 1, n\n w (i) = stp * gl (i)\n ww = ww + w (i) ** 2\n end do\n!\n! Set STEP to W if W gives a sufficiently large value of the modulus\n! of the Lagrange function, and if W either preserves feasibility\n! or gives a constraint violation of at least 0.2*DEL. The purpose\n! of CTOL below is to provide a check on feasibility that includes\n! a tolerance for contributions from computer rounding errors.\n!\n if (vnew/vbig >= 0.2_wp) then\n ifeas = 1\n bigv = zero\n j = 0\n170 j = j + 1\n if (j <= m) then\n if (rstat(j) == one) then\n temp = - rescon (j)\n do i = 1, n\n temp = temp + w (i) * amat (i, j)\n end do\n bigv = max (bigv, temp)\n end if\n if (bigv < test) go to 170\n ifeas = 0\n end if\n ctol = zero\n temp = 0.01_wp * sqrt (ww)\n if (bigv > zero .and. bigv < temp) then\n do k = 1, nact\n j = iact (k)\n sum = zero\n do i = 1, n\n sum = sum + w (i) * amat (i, j)\n end do\n ctol = max (ctol, abs(sum))\n end do\n end if\n if (bigv <= 10.0_wp*ctol .or. bigv >= test) then\n do i = 1, n\n step (i) = w (i)\n end do\n return\n end if\n end if\n!\n! Calculate the greatest constraint violation at XOPT+STEP with STEP at\n! its original value. Modify STEP if this violation is unacceptable.\n!\n220 ifeas = 1\n bigv = zero\n resmax = zero\n j = 0\n230 j = j + 1\n if (j <= m) then\n if (rstat(j) < zero) go to 230\n temp = - rescon (j)\n do i = 1, n\n temp = temp + step (i) * amat (i, j)\n end do\n resmax = max (resmax, temp)\n if (temp < test) then\n if (temp <= bigv) go to 230\n bigv = temp\n jsav = j\n ifeas = - 1\n go to 230\n end if\n ifeas = 0\n end if\n if (ifeas ==-1) then\n do i = 1, n\n step (i) = step (i) + (test-bigv) * amat (i, jsav)\n end do\n ifeas = 0\n end if\n!\n! Return the calculated STEP and the value of IFEAS.\n!\n\n end subroutine qmstep\n\n subroutine trstep (n, npt, m, amat, b, xpt, hq, pq, nact, iact, rescon, qfac, rfac, &\n snorm, step, g, resnew, resact, d, dw, w)\n\n implicit real (wp) (a-h, o-z)\n\n dimension amat (n,*), b (*), xpt (npt,*), hq (*), pq (*), iact (*), rescon (*), &\n qfac (n,*), rfac (*), step (*), g (*), resnew (*), resact (*), d (*), dw (*), w &\n (*)\n!\n! N, NPT, M, AMAT, B, XPT, HQ, PQ, NACT, IACT, RESCON, QFAC and RFAC\n! are the same as the terms with these names in LINCOB. If RESCON(J)\n! is negative, then |RESCON(J)| must be no less than the trust region\n! radius, so that the J-th constraint can be ignored.\n! SNORM is set to the trust region radius DELTA initially. On the\n! return, however, it is the length of the calculated STEP, which is\n! set to zero if the constraints do not allow a long enough step.\n! STEP is the total calculated step so far from the trust region centre,\n! its final value being given by the sequence of CG iterations, which\n! terminate if the trust region boundary is reached.\n! G must be set on entry to the gradient of the quadratic model at the\n! trust region centre. It is used as working space, however, and is\n! always the gradient of the model at the current STEP, except that\n! on return the value of G(1) is set to ONE instead of to ZERO if\n! and only if GETACT is called more than once.\n! RESNEW, RESACT, D, DW and W are used for working space. A negative\n! value of RESNEW(J) indicates that the J-th constraint does not\n! restrict the CG steps of the current trust region calculation, a\n! zero value of RESNEW(J) indicates that the J-th constraint is active,\n! and otherwise RESNEW(J) is set to the greater of TINY and the actual\n! residual of the J-th constraint for the current STEP. RESACT holds\n! the residuals of the active constraints, which may be positive.\n! D is the search direction of each line search. DW is either another\n! search direction or the change in gradient along D. The length of W\n! must be at least MAX[M,2*N].\n!\n! Set some numbers for the conjugate gradient iterations.\n!\n real(wp),parameter :: half = 0.5_wp\n real(wp),parameter :: one = 1.0_wp\n real(wp),parameter :: tiny = 1.0e-60_wp\n real(wp),parameter :: zero = 0.0_wp\n real(wp),parameter :: ctest = 0.01_wp\n\n snsq = snorm * snorm\n!\n! Set the initial elements of RESNEW, RESACT and STEP.\n!\n if (m > 0) then\n do j = 1, m\n resnew (j) = rescon (j)\n if (rescon(j) >= snorm) then\n resnew (j) = - one\n else if (rescon(j) >= zero) then\n resnew (j) = max (resnew(j), tiny)\n end if\n end do\n if (nact > 0) then\n do k = 1, nact\n resact (k) = rescon (iact(k))\n resnew (iact(k)) = zero\n end do\n end if\n end if\n do i = 1, n\n step (i) = zero\n end do\n ss = zero\n reduct = zero\n ncall = 0\n!\n! GETACT picks the active set for the current STEP. It also sets DW to\n! the vector closest to -G that is orthogonal to the normals of the\n! active constraints. DW is scaled to have length 0.2*SNORM, as then\n! a move of DW from STEP is allowed by the linear constraints.\n!\n40 ncall = ncall + 1\n call getact (n, m, amat, b, nact, iact, qfac, rfac, snorm, resnew, resact, g, dw, &\n w, w(n+1))\n if (w(n+1) == zero) go to 320\n scale = 0.2_wp * snorm / sqrt (w(n+1))\n do i = 1, n\n dw (i) = scale * dw (i)\n end do\n!\n! If the modulus of the residual of an active constraint is substantial,\n! then set D to the shortest move from STEP to the boundaries of the\n! active constraints.\n!\n resmax = zero\n if (nact > 0) then\n do k = 1, nact\n resmax = max (resmax, resact(k))\n end do\n end if\n gamma = zero\n if (resmax > 1.0e-4_wp*snorm) then\n ir = 0\n do k = 1, nact\n temp = resact (k)\n if (k >= 2) then\n do i = 1, k - 1\n ir = ir + 1\n temp = temp - rfac (ir) * w (i)\n end do\n end if\n ir = ir + 1\n w (k) = temp / rfac (ir)\n end do\n do i = 1, n\n d (i) = zero\n do k = 1, nact\n d (i) = d (i) + w (k) * qfac (i, k)\n end do\n end do\n!\n! The vector D that has just been calculated is also the shortest move\n! from STEP+DW to the boundaries of the active constraints. Set GAMMA\n! to the greatest steplength of this move that satisfies the trust\n! region bound.\n!\n rhs = snsq\n ds = zero\n dd = zero\n do i = 1, n\n sum = step (i) + dw (i)\n rhs = rhs - sum * sum\n ds = ds + d (i) * sum\n dd = dd + d (i) ** 2\n end do\n if (rhs > zero) then\n temp = sqrt (ds*ds+dd*rhs)\n if (ds <= zero) then\n gamma = (temp-ds) / dd\n else\n gamma = rhs / (temp+ds)\n end if\n end if\n!\n! Reduce the steplength GAMMA if necessary so that the move along D\n! also satisfies the linear constraints.\n!\n j = 0\n110 if (gamma > zero) then\n j = j + 1\n if (resnew(j) > zero) then\n ad = zero\n adw = zero\n do i = 1, n\n ad = ad + amat (i, j) * d (i)\n adw = adw + amat (i, j) * dw (i)\n end do\n if (ad > zero) then\n temp = max ((resnew(j)-adw)/ad, zero)\n gamma = min (gamma, temp)\n end if\n end if\n if (j < m) go to 110\n end if\n gamma = min (gamma, one)\n end if\n!\n! Set the next direction for seeking a reduction in the model function\n! subject to the trust region bound and the linear constraints.\n!\n if (gamma <= zero) then\n do i = 1, n\n d (i) = dw (i)\n end do\n icount = nact\n else\n do i = 1, n\n d (i) = dw (i) + gamma * d (i)\n end do\n icount = nact - 1\n end if\n alpbd = one\n!\n! Set ALPHA to the steplength from STEP along D to the trust region\n! boundary. Return if the first derivative term of this step is\n! sufficiently small or if no further progress is possible.\n!\n150 icount = icount + 1\n rhs = snsq - ss\n if (rhs <= zero) go to 320\n dg = zero\n ds = zero\n dd = zero\n do i = 1, n\n dg = dg + d (i) * g (i)\n ds = ds + d (i) * step (i)\n dd = dd + d (i) ** 2\n end do\n if (dg >= zero) go to 320\n temp = sqrt (rhs*dd+ds*ds)\n if (ds <= zero) then\n alpha = (temp-ds) / dd\n else\n alpha = rhs / (temp+ds)\n end if\n if (-alpha*dg <= ctest*reduct) go to 320\n!\n! Set DW to the change in gradient along D.\n!\n ih = 0\n do j = 1, n\n dw (j) = zero\n do i = 1, j\n ih = ih + 1\n if (i < j) dw (j) = dw (j) + hq (ih) * d (i)\n dw (i) = dw (i) + hq (ih) * d (j)\n end do\n end do\n do k = 1, npt\n temp = zero\n do j = 1, n\n temp = temp + xpt (k, j) * d (j)\n end do\n temp = pq (k) * temp\n do i = 1, n\n dw (i) = dw (i) + temp * xpt (k, i)\n end do\n end do\n!\n! Set DGD to the curvature of the model along D. Then reduce ALPHA if\n! necessary to the value that minimizes the model.\n!\n dgd = zero\n do i = 1, n\n dgd = dgd + d (i) * dw (i)\n end do\n alpht = alpha\n if (dg+alpha*dgd > zero) then\n alpha = - dg / dgd\n end if\n!\n! Make a further reduction in ALPHA if necessary to preserve feasibility,\n! and put some scalar products of D with constraint gradients in W.\n!\n alphm = alpha\n jsav = 0\n if (m > 0) then\n do j = 1, m\n ad = zero\n if (resnew(j) > zero) then\n do i = 1, n\n ad = ad + amat (i, j) * d (i)\n end do\n if (alpha*ad > resnew(j)) then\n alpha = resnew (j) / ad\n jsav = j\n end if\n end if\n w (j) = ad\n end do\n end if\n alpha = max (alpha, alpbd)\n alpha = min (alpha, alphm)\n if (icount == nact) alpha = min (alpha, one)\n!\n! Update STEP, G, RESNEW, RESACT and REDUCT.\n!\n ss = zero\n do i = 1, n\n step (i) = step (i) + alpha * d (i)\n ss = ss + step (i) ** 2\n g (i) = g (i) + alpha * dw (i)\n end do\n if (m > 0) then\n do j = 1, m\n if (resnew(j) > zero) then\n resnew (j) = max (resnew(j)-alpha*w(j), tiny)\n end if\n end do\n end if\n if (icount == nact .and. nact > 0) then\n do k = 1, nact\n resact (k) = (one-gamma) * resact (k)\n end do\n end if\n reduct = reduct - alpha * (dg+half*alpha*dgd)\n!\n! Test for termination. Branch to label 40 if there is a new active\n! constraint and if the distance from STEP to the trust region\n! boundary is at least 0.2*SNORM.\n!\n if (alpha == alpht) go to 320\n temp = - alphm * (dg+half*alphm*dgd)\n if (temp <= ctest*reduct) go to 320\n if (jsav > 0) then\n if (ss <= 0.64_wp*snsq) go to 40\n go to 320\n end if\n if (icount == n) go to 320\n!\n! Calculate the next search direction, which is conjugate to the\n! previous one except in the case ICOUNT=NACT.\n!\n if (nact > 0) then\n do j = nact + 1, n\n w (j) = zero\n do i = 1, n\n w (j) = w (j) + g (i) * qfac (i, j)\n end do\n end do\n do i = 1, n\n temp = zero\n do j = nact + 1, n\n temp = temp + qfac (i, j) * w (j)\n end do\n w (n+i) = temp\n end do\n else\n do i = 1, n\n w (n+i) = g (i)\n end do\n end if\n if (icount == nact) then\n beta = zero\n else\n wgd = zero\n do i = 1, n\n wgd = wgd + w (n+i) * dw (i)\n end do\n beta = wgd / dgd\n end if\n do i = 1, n\n d (i) = - w (n+i) + beta * d (i)\n end do\n alpbd = zero\n go to 150\n!\n! Return from the subroutine.\n!\n320 snorm = zero\n if (reduct > zero) snorm = sqrt (ss)\n g (1) = zero\n if (ncall > 1) g (1) = one\n\n end subroutine trstep\n\n subroutine update (n, npt, xpt, bmat, zmat, idz, ndim, sp, step, kopt, knew, vlag, w)\n\n implicit real (wp) (a-h, o-z)\n\n dimension xpt (npt,*), bmat (ndim,*), zmat (npt,*), sp (*), step (*), vlag (*), &\n w (*)\n\n!\n! The arguments N, NPT, XPT, BMAT, ZMAT, IDZ, NDIM ,SP and STEP are\n! identical to the corresponding arguments in SUBROUTINE LINCOB.\n! KOPT is such that XPT(KOPT,.) is the current trust region centre.\n! KNEW on exit is usually positive, and then it is the index of an\n! interpolation point to be moved to the position XPT(KOPT,.)+STEP(.).\n! It is set on entry either to its final value or to 0. In the latter\n! case, the final value of KNEW is chosen to maximize the denominator\n! of the matrix updating formula times a weighting factor.\n! VLAG and W are used for working space, the first NPT+N elements of\n! both of these vectors being required.\n!\n! The arrays BMAT and ZMAT with IDZ are updated, the new matrices being\n! the ones that are suitable after the shift of the KNEW-th point to\n! the new position XPT(KOPT,.)+STEP(.). A return with KNEW set to zero\n! occurs if the calculation fails due to a zero denominator in the\n! updating formula, which should never happen.\n!\n! Set some constants.\n!\n real(wp),parameter :: half = 0.5_wp\n real(wp),parameter :: one = 1.0_wp\n real(wp),parameter :: zero = 0.0_wp\n\n nptm = npt - n - 1\n!\n! Calculate VLAG and BETA for the current choice of STEP. The first NPT\n! elements of VLAG are set to the values of the Lagrange functions at\n! XPT(KOPT,.)+STEP(.). The first NPT components of W_check are held\n! in W, where W_check is defined in a paper on the updating method.\n!\n do k = 1, npt\n w (k) = sp (npt+k) * (half*sp(npt+k)+sp(k))\n sum = zero\n do j = 1, n\n sum = sum + bmat (k, j) * step (j)\n end do\n vlag (k) = sum\n end do\n beta = zero\n do k = 1, nptm\n sum = zero\n do i = 1, npt\n sum = sum + zmat (i, k) * w (i)\n end do\n if (k < idz) then\n beta = beta + sum * sum\n sum = - sum\n else\n beta = beta - sum * sum\n end if\n do i = 1, npt\n vlag (i) = vlag (i) + sum * zmat (i, k)\n end do\n end do\n bsum = zero\n dx = zero\n ssq = zero\n do j = 1, n\n sum = zero\n do i = 1, npt\n sum = sum + w (i) * bmat (i, j)\n end do\n bsum = bsum + sum * step (j)\n jp = npt + j\n do k = 1, n\n sum = sum + bmat (jp, k) * step (k)\n end do\n vlag (jp) = sum\n bsum = bsum + sum * step (j)\n dx = dx + step (j) * xpt (kopt, j)\n ssq = ssq + step (j) ** 2\n end do\n beta = dx * dx + ssq * (sp(kopt)+dx+dx+half*ssq) + beta - bsum\n vlag (kopt) = vlag (kopt) + one\n!\n! If KNEW is zero initially, then pick the index of the interpolation\n! point to be deleted, by maximizing the absolute value of the\n! denominator of the updating formula times a weighting factor.\n!\n if (knew == 0) then\n denmax = zero\n do k = 1, npt\n hdiag = zero\n do j = 1, nptm\n temp = one\n if (j < idz) temp = - one\n hdiag = hdiag + temp * zmat (k, j) ** 2\n end do\n denabs = abs (beta*hdiag+vlag(k)**2)\n distsq = zero\n do j = 1, n\n distsq = distsq + (xpt(k, j)-xpt(kopt, j)) ** 2\n end do\n temp = denabs * distsq * distsq\n if (temp > denmax) then\n denmax = temp\n knew = k\n end if\n end do\n end if\n!\n! Apply the rotations that put zeros in the KNEW-th row of ZMAT.\n!\n jl = 1\n if (nptm >= 2) then\n do j = 2, nptm\n if (j == idz) then\n jl = idz\n else if (zmat(knew, j) /= zero) then\n temp = sqrt (zmat(knew, jl)**2+zmat(knew, j)**2)\n tempa = zmat (knew, jl) / temp\n tempb = zmat (knew, j) / temp\n do i = 1, npt\n temp = tempa * zmat (i, jl) + tempb * zmat (i, j)\n zmat (i, j) = tempa * zmat (i, j) - tempb * zmat (i, jl)\n zmat (i, jl) = temp\n end do\n zmat (knew, j) = zero\n end if\n end do\n end if\n!\n! Put the first NPT components of the KNEW-th column of the Z Z^T matrix\n! into W, and calculate the parameters of the updating formula.\n!\n tempa = zmat (knew, 1)\n if (idz >= 2) tempa = - tempa\n if (jl > 1) tempb = zmat (knew, jl)\n do i = 1, npt\n w (i) = tempa * zmat (i, 1)\n if (jl > 1) w (i) = w (i) + tempb * zmat (i, jl)\n end do\n alpha = w (knew)\n tau = vlag (knew)\n tausq = tau * tau\n denom = alpha * beta + tausq\n vlag (knew) = vlag (knew) - one\n if (denom == zero) then\n knew = 0\n return\n end if\n sqrtdn = sqrt (abs(denom))\n!\n! Complete the updating of ZMAT when there is only one nonzero element\n! in the KNEW-th row of the new matrix ZMAT. IFLAG is set to one when\n! the value of IDZ is going to be reduced.\n!\n iflag = 0\n if (jl == 1) then\n tempa = tau / sqrtdn\n tempb = zmat (knew, 1) / sqrtdn\n do i = 1, npt\n zmat (i, 1) = tempa * zmat (i, 1) - tempb * vlag (i)\n end do\n if (denom < zero) then\n if (idz == 1) then\n idz = 2\n else\n iflag = 1\n end if\n end if\n else\n!\n! Complete the updating of ZMAT in the alternative case.\n!\n ja = 1\n if (beta >= zero) ja = jl\n jb = jl + 1 - ja\n temp = zmat (knew, jb) / denom\n tempa = temp * beta\n tempb = temp * tau\n temp = zmat (knew, ja)\n scala = one / sqrt (abs(beta)*temp*temp+tausq)\n scalb = scala * sqrtdn\n do i = 1, npt\n zmat (i, ja) = scala * (tau*zmat(i, ja)-temp*vlag(i))\n zmat (i, jb) = scalb * (zmat(i, jb)-tempa*w(i)-tempb*vlag(i))\n end do\n if (denom <= zero) then\n if (beta < zero) then\n idz = idz + 1\n else\n iflag = 1\n end if\n end if\n end if\n!\n! Reduce IDZ when the diagonal part of the ZMAT times Diag(DZ) times\n! ZMAT^T factorization gains another positive element. Then exchange\n! the first and IDZ-th columns of ZMAT.\n!\n if (iflag == 1) then\n idz = idz - 1\n do i = 1, npt\n temp = zmat (i, 1)\n zmat (i, 1) = zmat (i, idz)\n zmat (i, idz) = temp\n end do\n end if\n!\n! Finally, update the matrix BMAT.\n!\n do j = 1, n\n jp = npt + j\n w (jp) = bmat (knew, j)\n tempa = (alpha*vlag(jp)-tau*w(jp)) / denom\n tempb = (-beta*w(jp)-tau*vlag(jp)) / denom\n do i = 1, jp\n bmat (i, j) = bmat (i, j) + tempa * vlag (i) + tempb * w (i)\n if (i > npt) bmat (jp, i-npt) = bmat (i, j)\n end do\n end do\n\n end subroutine update\n\n!*****************************************************************************************\n!>\n! Test problem for [[lincoa]].\n!\n!\u00a0 Calculate the tetrahedron of least volume that encloses the points\n!\u00a0 `(XP(J),YP(J),ZP(J)), J=1,2,...,NP`. Our method requires the origin\n!\u00a0 to be strictly inside the convex hull of these points. There are\n!\u00a0 twelve variables that define the four faces of each tetrahedron\n!\u00a0 that is considered. Each face has the form `ALPHA*X+BETA*Y+GAMMA*Z=1`,\n!\u00a0 the variables `X(3K-2)`, `X(3K-1)` and `X(3K)` being the values of `ALPHA`,\n!\u00a0 `BETA` and `GAMMA` for the K-th face, K=1,2,3,4. Let the set T contain\n!\u00a0 all points in three dimensions that can be reached from the origin\n!\u00a0 without crossing a face. Because the volume of T may be infinite,\n!\u00a0 the objective function is the smaller of FMAX and the volume of T,\n!\u00a0 where FMAX is set to an upper bound on the final volume initially.\n!\u00a0 There are 4*NP linear constraints on the variables, namely that each\n!\u00a0 of the given points `(XP(J),YP(J),ZP(J))` shall be in T. Let `XS = min\n!\u00a0 XP(J)`, `YS = min YP(J)`, `ZS = min ZP(J)` and `SS = max XP(J)+YP(J)+ZP(J)`,\n!\u00a0 where J runs from 1 to NP. The initial values of the variables are\n!\u00a0 `X(1)=1/XS`, `X(5)=1/YS`, `X(9)=1/ZS`, `X(2)=X(3)=X(4)=X(6)=X(7)=X(8)=0`\n!\u00a0 and `X(10)=X(11)=X(12)=1/SS`, which satisfy the linear constraints,\n!\u00a0 and which provide the bound `FMAX=(SS-XS-YS-ZS)**3/6`. Other details\n!\u00a0 of the test calculation are given below, including the choice of\n!\u00a0 the data points `(XP(J),YP(J),ZP(J)), J=1,2,...,NP`. The smaller final\n!\u00a0 value of the objective function in the case NPT=35 shows that the\n!\u00a0 problem has local minima.\n\n subroutine lincoa_test ()\n\n implicit none\n\n real(wp) :: xp (50), yp (50), zp (50), a (12, 200), b (200), x (12)\n integer :: ia,n,np,j,iw,iprint,jcase,k,i,maxfun,npt,m\n real(wp) :: sumx,sumy,sumz,theta,fmax,rhobeg,rhoend,ss,xs,ys,zs\n !\n ! Set some constants.\n !\n real(wp),parameter :: one = 1.0_wp\n real(wp),parameter :: two = 2.0_wp\n real(wp),parameter :: zero = 0.0_wp\n real(wp),parameter :: pi = 4.0_wp * atan(one)\n\n ia = 12\n n = 12\n !\n ! Set the data points.\n !\n np = 50\n sumx = zero\n sumy = zero\n sumz = zero\n do j = 1, np\n theta = real (j-1, wp) * pi / real (np-1, wp)\n xp (j) = cos (theta) * cos (two*theta)\n sumx = sumx + xp (j)\n yp (j) = sin (theta) * cos (two*theta)\n sumy = sumy + yp (j)\n zp (j) = sin (two*theta)\n sumz = sumz + zp (j)\n end do\n sumx = sumx / real (np, wp)\n sumy = sumy / real (np, wp)\n sumz = sumz / real (np, wp)\n do j = 1, np\n xp (j) = xp (j) - sumx\n yp (j) = yp (j) - sumy\n zp (j) = zp (j) - sumz\n end do\n !\n ! Set the linear constraints.\n !\n m = 4 * np\n do k = 1, m\n b (k) = one\n do i = 1, n\n a (i, k) = zero\n end do\n end do\n do j = 1, np\n do i = 1, 4\n k = 4 * j + i - 4\n iw = 3 * i\n a (iw-2, k) = xp (j)\n a (iw-1, k) = yp (j)\n a (iw, k) = zp (j)\n end do\n end do\n !\n ! Set the initial vector of variables. The JCASE=1,6 loop gives six\n ! different choices of NPT when LINCOA is called.\n !\n xs = zero\n ys = zero\n zs = zero\n ss = zero\n do j = 1, np\n xs = min (xs, xp(j))\n ys = min (ys, yp(j))\n zs = min (zs, zp(j))\n ss = max (ss, xp(j)+yp(j)+zp(j))\n end do\n fmax = (ss-xs-ys-zs) ** 3 / 6.0_wp\n do jcase = 1, 6\n do i = 2, 8\n x (i) = zero\n end do\n x (1) = one / xs\n x (5) = one / ys\n x (9) = one / zs\n x (10) = one / ss\n x (11) = one / ss\n x (12) = one / ss\n !\n ! Call of LINCOA, which provides the printing given at the end of this\n ! note.\n !\n npt = 5 * jcase + 10\n rhobeg = 1.0_wp\n rhoend = 1.0e-6_wp\n iprint = 1\n maxfun = 10000\n print 70, npt, rhoend\n70 format (/ / 4 x, 'Output from LINCOA with NPT =', i4, ' and RHOEND =', 1 &\n & pd12.4)\n call lincoa(n,npt,m,a,ia,b,x,rhobeg,rhoend,iprint,maxfun,calfun)\n end do\n\n contains\n\n subroutine calfun (n, x, f)\n\n implicit none\n\n integer :: n\n real(wp) :: x (*)\n real(wp) :: f\n\n real(wp) :: v12,v13,v14,v23,v24,v34,del1,del2,del3,del4,temp\n\n f = fmax\n v12 = x (1) * x (5) - x (4) * x (2)\n v13 = x (1) * x (8) - x (7) * x (2)\n v14 = x (1) * x (11) - x (10) * x (2)\n v23 = x (4) * x (8) - x (7) * x (5)\n v24 = x (4) * x (11) - x (10) * x (5)\n v34 = x (7) * x (11) - x (10) * x (8)\n del1 = v23 * x (12) - v24 * x (9) + v34 * x (6)\n if (del1 <= zero) return\n del2 = - v34 * x (3) - v13 * x (12) + v14 * x (9)\n if (del2 <= zero) return\n del3 = - v14 * x (6) + v24 * x (3) + v12 * x (12)\n if (del3 <= zero) return\n del4 = - v12 * x (9) + v13 * x (6) - v23 * x (3)\n if (del4 <= zero) return\n temp = (del1+del2+del3+del4) ** 3 / (del1*del2*del3*del4)\n f = min (temp/6.0_wp, fmax)\n\n end subroutine calfun\n\n end subroutine lincoa_test\n!*****************************************************************************************\n\nend module lincoa_module\n", "meta": {"hexsha": "d31268b463669cc2c98cd42f5ba2bd8049029cba", "size": 86355, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/lincoa.f90", "max_stars_repo_name": "jacobwilliams/PowellOpt", "max_stars_repo_head_hexsha": "0124e2d9d9216cbf3dc342f9f35365e643b5560b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2015-07-19T04:43:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-28T05:13:56.000Z", "max_issues_repo_path": "src/lincoa.f90", "max_issues_repo_name": "jacobwilliams/PowellOpt", "max_issues_repo_head_hexsha": "0124e2d9d9216cbf3dc342f9f35365e643b5560b", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2021-09-15T02:51:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-12T22:55:38.000Z", "max_forks_repo_path": "src/lincoa.f90", "max_forks_repo_name": "jacobwilliams/PowellOpt", "max_forks_repo_head_hexsha": "0124e2d9d9216cbf3dc342f9f35365e643b5560b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2015-09-04T19:04:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-17T19:35:30.000Z", "avg_line_length": 37.0781451267, "max_line_length": 127, "alphanum_fraction": 0.4654044352, "num_tokens": 25235, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6797251867767993}} {"text": "!*****************************************************************************\n!\n! Different implementations of a simple single precision A-X plus Y function\n! on a CPU and GPU, to verify this code works.\n!\n! x = ax + y\n! x,y,z: vector\n! a: scalar\n!*****************************************************************************\n\n!*****************************************************************************\n! Setup/driver code\n!*****************************************************************************\n\nsubroutine test_saxpy_openmp_kernels()\n use saxpy_openmp_kernels_mod\n use saxpy_kernels_mod\n\n ! Number of elements in arrays\n integer :: n \n ! Arrays\n real :: x(2**20), y(2**20)\n ! Scalar value to multiply array x by.\n real :: a\n\n n = 2**20\n a = 2.0\n ! Initialize arrays\n x = 1.0\n y = 2.0\n\n ! Reference calculation - serial cpu code.\n do i=1,n\n y(i) = a*x(i)+y(i)\n end do\n\n ! OpenMP CPU\n y = 2.0\n call saxpy_cpu_openmp_kernel(n, a, x, y)\n\n ! OpenMP 4.5 GPU\n y = 2.0\n call saxpy_gpu_openmp_kernel(n, a, x, y)\n\nend subroutine test_saxpy_openmp_kernels\n\nsubroutine test_saxpy_cuda_kernels\n use cudafor\n use saxy_cuda_kernels_mod\n\n real, device :: x_d(2**20), y_d(2**20)\n x_d = 1.0\n y_d = 2.0\n\n ! Perform SAXPY on 1M elements\n call saxpy_gpu_cuda_kernel<<<4096, 256>>>(2.0, x_d, y_d)\n\n return\nend subroutine test_saxpy_cuda_kernels\n\n", "meta": {"hexsha": "66b9b8c79dbc0922a25f1bf72addd9a84d0b705f", "size": 1393, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "testing/compiler_interoperability_test_cases/xlc_mixed_cuda/v1/test_saxpy_all_kernels.f90", "max_stars_repo_name": "bblakeley/FGPU", "max_stars_repo_head_hexsha": "0bf46c2487775a99c0be51e0bdfbdeaddeb967fe", "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": "testing/compiler_interoperability_test_cases/xlc_mixed_cuda/v1/test_saxpy_all_kernels.f90", "max_issues_repo_name": "bblakeley/FGPU", "max_issues_repo_head_hexsha": "0bf46c2487775a99c0be51e0bdfbdeaddeb967fe", "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": "testing/compiler_interoperability_test_cases/xlc_mixed_cuda/v1/test_saxpy_all_kernels.f90", "max_forks_repo_name": "bblakeley/FGPU", "max_forks_repo_head_hexsha": "0bf46c2487775a99c0be51e0bdfbdeaddeb967fe", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-04-24T19:56:31.000Z", "max_forks_repo_forks_event_max_datetime": "2020-04-24T19:56:31.000Z", "avg_line_length": 22.8360655738, "max_line_length": 78, "alphanum_fraction": 0.5075376884, "num_tokens": 395, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436395, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6797251860838066}} {"text": " function permute_2(T,i1,j1)\n ! permute tensor of rank 2 for orders 2,1 = transpose(T)\n implicit none\n \n type(Tensor2), intent(in) :: T\n integer, intent(in) :: i1,j1\n \n type(Tensor2) :: permute_2\n \n permute_2%ab = transpose(T%ab)\n \n end function permute_2\n \n function permute_2s(T,i1,j1)\n ! permute tensor of rank 2 for orders 2,1 = transpose(T)\n implicit none\n \n type(Tensor2s), intent(in) :: T\n integer, intent(in) :: i1,j1\n \n type(Tensor2s) :: permute_2s\n \n permute_2s%a6 = T%a6\n \n end function permute_2s\n \n function permute_4(T,i1,j1,k1,l1)\n ! permute tensor of rank 4\n implicit none\n \n type(Tensor4), intent(in) :: T\n integer, intent(in) :: i1,j1,k1,l1\n \n type(Tensor4) :: permute_4\n integer i,j,k,l\n\nc hard-coded permutation\nc if (i1==1 .and. j1==3 .and. k1==2 .and. l1==4) then\nc forall(i=1:3,j=1:3,k=1:3,l=1:3) permute_4%abcd(i,j,k,l)\nc * = T%abcd(i,k,j,l)\nc else if (i1==1 .and. j1==4 .and. k1==2 .and. l1==3) then\nc forall(i=1:3,j=1:3,k=1:3,l=1:3) permute_4%abcd(i,j,k,l)\nc * = T%abcd(i,l,j,k)\nc else\nc permute_4%abcd = T%abcd\nc end if\n \n permute_4%abcd = reshape(T%abcd,(/3,3,3,3/),\n * (/0.d0/),(/i1,j1,k1,l1/))\n \n end function permute_4\n \n function permute_4s(T,i1,j1,k1,l1)\n ! permute tensor of rank 4s\n implicit none\n \n type(Tensor4s), intent(in) :: T\n type(Tensor4) :: Tp\n integer, intent(in) :: i1,j1,k1,l1\n type(Tensor4) :: permute_4\n type(Tensor4s) :: permute_4s\n \n integer i,j,k,l\n \n Tp = tensorstore(T)\n\n permute_4%abcd = reshape(Tp%abcd,(/3,3,3,3/),\n * (/0.d0/),(/i1,j1,k1,l1/))\n permute_4s = symstore(permute_4)\n \n end function permute_4s", "meta": {"hexsha": "fb689bb0bfdf0c44cc5fd07e2fec66e0d085c973", "size": 2153, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ttb/libpermute.f", "max_stars_repo_name": "kengwit/ttb", "max_stars_repo_head_hexsha": "e3e41fdc0a3b47a45f762d8d89dafce3ace838f4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 41, "max_stars_repo_stars_event_min_datetime": "2018-02-27T06:31:19.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-30T07:58:45.000Z", "max_issues_repo_path": "ttb/libpermute.f", "max_issues_repo_name": "kengwit/ttb", "max_issues_repo_head_hexsha": "e3e41fdc0a3b47a45f762d8d89dafce3ace838f4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 22, "max_issues_repo_issues_event_min_datetime": "2017-12-01T07:47:36.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-16T05:42:06.000Z", "max_forks_repo_path": "ttb/libpermute.f", "max_forks_repo_name": "kengwit/ttb", "max_forks_repo_head_hexsha": "e3e41fdc0a3b47a45f762d8d89dafce3ace838f4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-07-12T01:45:20.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-25T08:03:13.000Z", "avg_line_length": 30.323943662, "max_line_length": 65, "alphanum_fraction": 0.4732930794, "num_tokens": 693, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117855317474, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.6797134495414792}} {"text": " FUNCTION torflux_deriv (x)\n USE stel_kinds\n USE vmec_main, ONLY: zero\n USE vmec_input, ONLY: lRFP, tf => aphi\nC-----------------------------------------------\nC D u m m y A r g u m e n t s\nC-----------------------------------------------\n REAL(rprec), INTENT(IN) :: x\n REAL(rprec) :: torflux_deriv\n REAL(rprec), EXTERNAL :: polflux_deriv, piota\n INTEGER :: i\nC-----------------------------------------------\n! x: radial flux variable (=TOROIDAL FLUX ONLY IF APHI=1)\n\n IF (lRFP) THEN\n! RFP/TOKAMAK\n IF (piota(x) .eq. zero) STOP 'piota(x) = 0!'\n torflux_deriv = polflux_deriv(x)/piota(x)\n\n ELSE\n! TOKAMAK/STELLARATOR (default is tf(1) = 1)\n torflux_deriv = 0\n DO i = UBOUND(tf,1), LBOUND(tf,1), -1\n torflux_deriv = x*torflux_deriv + i*tf(i)\n END DO\n! torflux_deriv = 1\n END IF\n\n END FUNCTION torflux_deriv\n\n FUNCTION polflux_deriv (x)\n USE stel_kinds\n USE vmec_input, ONLY: lRFP\nC-----------------------------------------------\nC D u m m y A r g u m e n t s\nC-----------------------------------------------\n REAL(rprec), INTENT(IN) :: x\n REAL(rprec) :: tf, polflux_deriv\n REAL(rprec), EXTERNAL :: torflux, torflux_deriv, piota\nC-----------------------------------------------\n! x: radial flux variable (=TOROIDAL FLUX ONLY IF APHI=1)\n! polflux_deriv == d(chi)/dx = iota(TF(x)) * torflux_deriv(x)\n\n IF (lRFP) THEN\n! RFP/TOKAMAK\n polflux_deriv = 1\n\n ELSE\n! TOKAMAK/STELLARATOR: dchi/ds = iota * dphi/ds\n! piota is assumed to be a function of the TF(x) on input\n tf = torflux(x)\n tf = MIN(tf, 1.0_dp)\n polflux_deriv = piota(tf)*torflux_deriv(x)\n! polflux_deriv = piota(x)*torflux_deriv(x)\n END IF\n\n END FUNCTION polflux_deriv\n\n FUNCTION torflux (x)\n USE stel_kinds\nC-----------------------------------------------\nC D u m m y A r g u m e n t s\nC-----------------------------------------------\n REAL(rprec), INTENT(IN) :: x\n REAL(rprec) :: torflux, h, xi\n REAL(rprec), EXTERNAL :: torflux_deriv\n INTEGER :: i\nC-----------------------------------------------\n! x: radial flux variable (=TOROIDAL FLUX ONLY IF APHI=1)\n h = 1.E-2_dp*x\n torflux = 0\n DO i=1,101\n xi = (i-1)*h\n torflux = torflux + torflux_deriv(xi)\n END DO\n torflux = torflux-0.5_dp*(torflux_deriv(0._dp)+torflux_deriv(x))\n torflux = h*torflux\n\n END FUNCTION torflux\n\n FUNCTION polflux (x)\n USE stel_kinds\n! USE vmec_input, ONLY: af => achi\nC-----------------------------------------------\nC D u m m y A r g u m e n t s\nC-----------------------------------------------\n REAL(rprec), INTENT(IN) :: x\n REAL(rprec) :: polflux, h, xi\n REAL(rprec), EXTERNAL :: polflux_deriv\n INTEGER :: i\nC-----------------------------------------------\n h = 1.E-2_dp*x\n polflux = 0\n DO i=1,101\n xi = (i-1)*h\n polflux = polflux + polflux_deriv(xi)\n END DO\n polflux = polflux-0.5_dp*(polflux_deriv(0._dp)+polflux_deriv(x))\n polflux = h*polflux\n\n END FUNCTION polflux\n\n! function piota moved to a separate file, piota.f. J Hanson, 2010-03-16\n", "meta": {"hexsha": "aeebbfd89e2be2f8427705e2cc369009bf7dab06", "size": 3329, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "VMEC2000/Sources/Initialization_Cleanup/magnetic_fluxes.f", "max_stars_repo_name": "joseluisvelasco/STELLOPT", "max_stars_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2020-05-08T01:47:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T10:35:28.000Z", "max_issues_repo_path": "VMEC2000/Sources/Initialization_Cleanup/magnetic_fluxes.f", "max_issues_repo_name": "joseluisvelasco/STELLOPT", "max_issues_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 77, "max_issues_repo_issues_event_min_datetime": "2020-05-08T07:18:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:20:33.000Z", "max_forks_repo_path": "Sources/Initialization_Cleanup/magnetic_fluxes.f", "max_forks_repo_name": "mbkumar/VMEC2000", "max_forks_repo_head_hexsha": "334e3bd478f2432b6fe8cbb321f0d81d9a952152", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-02-10T13:47:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T12:53:43.000Z", "avg_line_length": 32.0096153846, "max_line_length": 73, "alphanum_fraction": 0.4740162211, "num_tokens": 958, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767906859264, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.6796789374896395}} {"text": "PROGRAM F049\n\n ! Copyright 2021 Melwyn Francis Carlo\n ! FILE REFERENCE: http://www.naturalnumbers.org/primes.html\n\n IMPLICIT NONE\n\n INTEGER, PARAMETER :: N = 10\n\n INTEGER :: PRIME_NUM\n CHARACTER (LEN=50), PARAMETER :: FILENAME = \"problems/003/PrimeNumbers_Upto_1000000\"\n\n INTEGER, DIMENSION (1200, N) :: PRIMES_NUMS = 0\n INTEGER, DIMENSION (1200) :: PRIMES_DIGITS_OCCURRENCES = 0\n\n CHARACTER (LEN=N) :: PRIME_DIGITS = ACHAR(0)\n CHARACTER (LEN=N), DIMENSION (1200) :: PRIMES_DIGITS = ACHAR(0)\n\n LOGICAL :: DUPLICATE_FOUND, SEQUENCE_FOUND\n\n INTEGER :: I, J, K, L, M, TEMP_VAL\n\n OPEN (2, FILE = FILENAME, STATUS = 'OLD')\n\n I = 1\n DO\n\n READ(2, *, END=10) PRIME_NUM\n\n IF (PRIME_NUM < 1000) CYCLE\n\n IF (PRIME_NUM > 9999) CYCLE\n\n PRIME_DIGITS = \"0000000000\"\n\n TEMP_VAL = INT(PRIME_NUM / 1000) + 1\n PRIME_DIGITS(TEMP_VAL:TEMP_VAL) = \"1\"\n TEMP_VAL = MOD(INT(PRIME_NUM / 100), 10) + 1\n PRIME_DIGITS(TEMP_VAL:TEMP_VAL) = \"1\"\n TEMP_VAL = MOD(INT(PRIME_NUM / 10), 10) + 1\n PRIME_DIGITS(TEMP_VAL:TEMP_VAL) = \"1\"\n TEMP_VAL = MOD(PRIME_NUM, 10) + 1\n PRIME_DIGITS(TEMP_VAL:TEMP_VAL) = \"1\"\n\n DUPLICATE_FOUND = .FALSE.\n DO J = 1, I\n\n IF (PRIMES_DIGITS(J) == PRIME_DIGITS) THEN\n\n IF (PRIMES_NUMS(J, N) == 0) THEN\n\n DO K = 2, N\n IF (PRIMES_NUMS(J, K) == 0) THEN\n PRIMES_NUMS(J, K) = PRIME_NUM\n EXIT\n END IF\n END DO\n\n PRIMES_DIGITS_OCCURRENCES(J) = PRIMES_DIGITS_OCCURRENCES(J) + 1\n\n END IF\n\n DUPLICATE_FOUND = .TRUE.\n EXIT\n\n END IF\n\n END DO\n\n IF (.NOT. DUPLICATE_FOUND) THEN\n PRIMES_DIGITS_OCCURRENCES(I) = 0\n PRIMES_NUMS(I, 1) = PRIME_NUM\n PRIMES_DIGITS(I) = PRIME_DIGITS\n I = I + 1\n END IF\n\n END DO\n\n 10 CLOSE(2)\n\n J = 1\n K = 1\n L = 1\n M = 1\n SEQUENCE_FOUND = .FALSE.\n\n DO J = 1, I\n\n IF (PRIMES_DIGITS_OCCURRENCES(J) < 3) CYCLE\n\n DO K = 1, (N - 2)\n\n IF (PRIMES_NUMS(J, K) == 0) EXIT\n\n IF (PRIMES_NUMS(J, K) == 1487) CYCLE\n\n DO L = (K + 1), (N - 1)\n\n IF (PRIMES_NUMS(J, L) == 0) EXIT\n\n DO M = (L + 1), N\n IF (PRIMES_NUMS(J, M) == 0) EXIT\n\n IF ((PRIMES_NUMS(J, M) - PRIMES_NUMS(J, L)) &\n == (PRIMES_NUMS(J, L) - PRIMES_NUMS(J, K))) THEN\n SEQUENCE_FOUND = .TRUE.\n EXIT\n END IF\n END DO\n\n IF (SEQUENCE_FOUND) EXIT\n\n END DO\n\n IF (SEQUENCE_FOUND) EXIT\n\n END DO\n\n IF (SEQUENCE_FOUND) EXIT\n\n END DO\n\n PRINT ('(3I0)'), PRIMES_NUMS(J, K), PRIMES_NUMS(J, L), PRIMES_NUMS(J, M)\n\nEND PROGRAM F049\n", "meta": {"hexsha": "020f4ce3528d74bf6be40a84601fa3678c166c9d", "size": 3034, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "problems/049/049.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/049/049.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/049/049.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": 24.0793650794, "max_line_length": 88, "alphanum_fraction": 0.491100857, "num_tokens": 977, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767810736693, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.6796789300441448}} {"text": "************************************************************************\n* Det computes the determinant of a matrix.\n* Input:\n* A: n-by-n matrix A\n* n: dimension of A\n* Output:\n* determinant of A\n* Warning: A is overwritten\n\n Double Complex function pvXDet(A, n)\n implicit none\n integer n\n include 'pvNmax.f'\n Double Complex A(n,n)\n\n integer i, perm(Nmax)\n\n call XLUDecomp(A, n, perm)\n pvXDet = dcmplx(1d0,0d0)\n do i = 1, n\n pvXDet = pvXDet*A(i,i)\n if( perm(i) .ne. i ) pvXDet = -pvXDet\n enddo\n end\n\n", "meta": {"hexsha": "0e3941c683a87d5960ee8b46b0c12f88a61a8513", "size": 577, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "MCFM-JHUGen/TensorReduction/pv/pvXdet.f", "max_stars_repo_name": "tmartini/JHUGen", "max_stars_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-06-08T13:09:28.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-04T19:59:36.000Z", "max_issues_repo_path": "MCFM-JHUGen/TensorReduction/pv/pvXdet.f", "max_issues_repo_name": "tmartini/JHUGen", "max_issues_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 64, "max_issues_repo_issues_event_min_datetime": "2015-06-24T15:08:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-25T04:59:32.000Z", "max_forks_repo_path": "MCFM-JHUGen/TensorReduction/pv/pvXdet.f", "max_forks_repo_name": "tmartini/JHUGen", "max_forks_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2015-05-04T22:15:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-06T10:04:40.000Z", "avg_line_length": 22.1923076923, "max_line_length": 72, "alphanum_fraction": 0.4974003466, "num_tokens": 167, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9073122263731811, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6796559870788049}} {"text": " function triangle_area(x1, x2, x3, y1, y2, y3)\n implicit double precision (a-h,o-z)\n\n triangle_area = dabs(0.5d0 * ( (x2 - x1) * (y3 - y1)\n & - (x3 - x1) * (y2 - y1) ))\n\n return\n end\n\n\n", "meta": {"hexsha": "c1a47e4ce764ffb9e3e9859945fe36713127a567", "size": 243, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/2d/triangle_area.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/triangle_area.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/triangle_area.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": 22.0909090909, "max_line_length": 61, "alphanum_fraction": 0.4362139918, "num_tokens": 87, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9073122238669026, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6796559852013838}} {"text": "program problem71\n use euler\n implicit none\n real*16, parameter :: target=(3.0q0/7.0q0)\n real*16 :: tempr,best\n integer, parameter :: limit=1000000\n integer*8 :: tempi,num,denom\n\n best=-huge(best)\n\n do denom=1,limit\n tempi=int8(floor(target*denom))\n tempr=real(tempi,16)/denom\n if (best= 0.\nC\nC M (input) INTEGER\nC The number of system inputs. M >= 0.\nC\nC P (input) INTEGER\nC The number of system outputs. P >= 0.\nC\nC NR (input/output) INTEGER\nC On entry with ORDSEL = 'F', NR is the desired order of\nC the resulting reduced order system. 0 <= NR <= N.\nC On exit, if INFO = 0, NR is the order of the resulting\nC reduced order model. NR is set as follows:\nC if ORDSEL = 'F', NR is equal to MIN(NR,NMINR), where NR\nC is the desired order on entry and NMINR is the number of\nC the Hankel singular values greater than N*EPS*S1, where\nC EPS is the machine precision (see LAPACK Library Routine\nC DLAMCH) and S1 is the largest Hankel singular value\nC (computed in HSV(1));\nC NR can be further reduced to ensure HSV(NR) > HSV(NR+1);\nC if ORDSEL = 'A', NR is equal to the number of Hankel\nC singular values greater than MAX(TOL1,N*EPS*S1).\nC\nC SCALEC (input) DOUBLE PRECISION\nC Scaling factor for the Cholesky factor S of the\nC controllability Grammian, i.e., S/SCALEC is used to\nC compute the Hankel singular values. SCALEC > 0.\nC\nC SCALEO (input) DOUBLE PRECISION\nC Scaling factor for the Cholesky factor R of the\nC observability Grammian, i.e., R/SCALEO is used to\nC compute the Hankel singular values. SCALEO > 0.\nC\nC A (input/output) DOUBLE PRECISION array, dimension (LDA,N)\nC On entry, the leading N-by-N part of this array must\nC contain the state dynamics matrix A. If FACT = 'S',\nC A is in a real Schur form.\nC On exit, if INFO = 0, the leading NR-by-NR part of this\nC array contains the state dynamics matrix Ar of the\nC reduced order system.\nC\nC LDA INTEGER\nC The leading dimension of array A. LDA >= MAX(1,N).\nC\nC B (input/output) DOUBLE PRECISION array, dimension (LDB,M)\nC On entry, the leading N-by-M part of this array must\nC contain the original input/state matrix B.\nC On exit, if INFO = 0, the leading NR-by-M part of this\nC array contains the input/state matrix Br of the reduced\nC order system.\nC\nC LDB INTEGER\nC The leading dimension of array B. LDB >= MAX(1,N).\nC\nC C (input/output) DOUBLE PRECISION array, dimension (LDC,N)\nC On entry, the leading P-by-N part of this array must\nC contain the original state/output matrix C.\nC On exit, if INFO = 0, the leading P-by-NR part of this\nC array contains the state/output matrix Cr of the reduced\nC order system.\nC\nC LDC INTEGER\nC The leading dimension of array C. LDC >= MAX(1,P).\nC\nC D (input/output) DOUBLE PRECISION array, dimension (LDD,M)\nC On entry, if JOB = 'S' or JOB = 'P', the leading P-by-M\nC part of this array must contain the original input/output\nC matrix D.\nC On exit, if INFO = 0 and JOB = 'S' or JOB = 'P', the\nC leading P-by-M part of this array contains the\nC input/output matrix Dr of the reduced order system.\nC If JOB = 'B' or JOB = 'F', this array is not referenced.\nC\nC LDD INTEGER\nC The leading dimension of array D.\nC LDD >= 1, if JOB = 'B' or JOB = 'F';\nC LDD >= MAX(1,P), if JOB = 'S' or JOB = 'P'.\nC\nC TI (input/output) DOUBLE PRECISION array, dimension (LDTI,N)\nC On entry, the leading N-by-N upper triangular part of\nC this array must contain the Cholesky factor S of a\nC controllability Grammian P = S*S'.\nC On exit, if INFO = 0, and NR > 0, the leading NMINR-by-N\nC part of this array contains the left truncation matrix\nC TI in (1), for the B&T approach, or in (2), for the\nC SPA approach.\nC\nC LDTI INTEGER\nC The leading dimension of array TI. LDTI >= MAX(1,N).\nC\nC T (input/output) DOUBLE PRECISION array, dimension (LDT,N)\nC On entry, the leading N-by-N upper triangular part of\nC this array must contain the Cholesky factor R of an\nC observability Grammian Q = R'*R.\nC On exit, if INFO = 0, and NR > 0, the leading N-by-NMINR\nC part of this array contains the right truncation matrix\nC T in (1), for the B&T approach, or in (2), for the\nC SPA approach.\nC\nC LDT INTEGER\nC The leading dimension of array T. LDT >= MAX(1,N).\nC\nC NMINR (output) INTEGER\nC The number of Hankel singular values greater than\nC MAX(TOL2,N*EPS*S1).\nC Note: If S and R are the Cholesky factors of the\nC controllability and observability Grammians of the\nC original system (A,B,C,D), respectively, then NMINR is\nC the order of a minimal realization of the original system.\nC\nC HSV (output) DOUBLE PRECISION array, dimension (N)\nC If INFO = 0, it contains the Hankel singular values,\nC ordered decreasingly. The Hankel singular values are\nC singular values of the product R*S.\nC\nC Tolerances\nC\nC TOL1 DOUBLE PRECISION\nC If ORDSEL = 'A', TOL1 contains the tolerance for\nC determining the order of the reduced system.\nC For model reduction, the recommended value lies in the\nC interval [0.00001,0.001].\nC If TOL1 <= 0 on entry, the used default value is\nC TOL1 = N*EPS*S1, where EPS is the machine precision\nC (see LAPACK Library Routine DLAMCH) and S1 is the largest\nC Hankel singular value (computed in HSV(1)).\nC If ORDSEL = 'F', the value of TOL1 is ignored.\nC\nC TOL2 DOUBLE PRECISION\nC The tolerance for determining the order of a minimal\nC realization of the system.\nC The recommended value is TOL2 = N*EPS*S1.\nC This value is used by default if TOL2 <= 0 on entry.\nC If TOL2 > 0, and ORDSEL = 'A', then TOL2 <= TOL1.\nC\nC Workspace\nC\nC IWORK INTEGER array, dimension (LIWORK), where\nC LIWORK = 0, if JOB = 'B';\nC LIWORK = N, if JOB = 'F';\nC LIWORK = 2*N, if JOB = 'S' or 'P'.\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0, DWORK(1) returns the optimal value\nC of LDWORK.\nC\nC LDWORK INTEGER\nC The length of the array DWORK.\nC LDWORK >= MAX( 1, 2*N*N + 5*N, N*MAX(M,P) ).\nC For optimum performance LDWORK should be larger.\nC\nC Warning Indicator\nC\nC IWARN INTEGER\nC = 0: no warning;\nC = 1: with ORDSEL = 'F', the selected order NR is greater\nC than NMINR, the order of a minimal realization of\nC the given system; in this case, the resulting NR is\nC set automatically to NMINR;\nC = 2: with ORDSEL = 'F', the selected order NR corresponds\nC to repeated singular values, which are neither all\nC included nor all excluded from the reduced model;\nC in this case, the resulting NR is set automatically\nC to the largest value such that HSV(NR) > HSV(NR+1).\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value;\nC = 1: the computation of Hankel singular values failed.\nC\nC METHOD\nC\nC Let be the stable linear system\nC\nC d[x(t)] = Ax(t) + Bu(t)\nC y(t) = Cx(t) + Du(t), (3)\nC\nC where d[x(t)] is dx(t)/dt for a continuous-time system and x(t+1)\nC for a discrete-time system. The subroutine AB09IX determines for\nC the given system (3), the matrices of a reduced NR order system\nC\nC d[z(t)] = Ar*z(t) + Br*u(t)\nC yr(t) = Cr*z(t) + Dr*u(t), (4)\nC\nC by using the square-root or balancing-free square-root\nC Balance & Truncate (B&T) or Singular Perturbation Approximation\nC (SPA) model reduction methods.\nC\nC The projection matrices TI and T are determined using the\nC Cholesky factors S and R of a controllability Grammian P and an\nC observability Grammian Q.\nC The Hankel singular values HSV(1), ...., HSV(N) are computed as\nC singular values of the product R*S.\nC\nC If JOB = 'B', the square-root Balance & Truncate technique\nC of [1] is used.\nC\nC If JOB = 'F', the balancing-free square-root version of the\nC Balance & Truncate technique [2] is used.\nC\nC If JOB = 'S', the square-root version of the Singular Perturbation\nC Approximation method [3,4] is used.\nC\nC If JOB = 'P', the balancing-free square-root version of the\nC Singular Perturbation Approximation method [3,4] is used.\nC\nC REFERENCES\nC\nC [1] Tombs M.S. and Postlethwaite I.\nC Truncated balanced realization of stable, non-minimal\nC state-space systems.\nC Int. J. Control, Vol. 46, pp. 1319-1330, 1987.\nC\nC [2] Varga A.\nC Efficient minimal realization procedure based on balancing.\nC Proc. of IMACS/IFAC Symp. MCTS, Lille, France, May 1991,\nC A. El Moudni, P. Borne, S. G. Tzafestas (Eds.),\nC Vol. 2, pp. 42-46.\nC\nC [3] Liu Y. and Anderson B.D.O.\nC Singular Perturbation Approximation of balanced systems.\nC Int. J. Control, Vol. 50, pp. 1379-1405, 1989.\nC\nC [4] Varga A.\nC Balancing-free square-root algorithm for computing singular\nC perturbation approximations.\nC Proc. 30-th CDC, Brighton, Dec. 11-13, 1991,\nC Vol. 2, pp. 1062-1065.\nC\nC NUMERICAL ASPECTS\nC\nC The implemented method relies on accuracy enhancing square-root\nC or balancing-free square-root methods.\nC\nC CONTRIBUTORS\nC\nC A. Varga, German Aerospace Center, Oberpfaffenhofen, August 2000.\nC D. Sima, University of Bucharest, August 2000.\nC V. Sima, Research Institute for Informatics, Bucharest, Aug. 2000.\nC\nC REVISIONS\nC\nC V. Sima, Research Institute for Informatics, Bucharest, Dec. 2000,\nC Sep. 2001.\nC\nC KEYWORDS\nC\nC Balance and truncate, minimal state-space representation,\nC model reduction, multivariable system,\nC singular perturbation approximation, state-space model.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ONE, ZERO\n PARAMETER ( ONE = 1.0D0, ZERO = 0.0D0 )\nC .. Scalar Arguments ..\n CHARACTER DICO, FACT, JOB, ORDSEL\n INTEGER INFO, IWARN, LDA, LDB, LDC, LDD, LDT, LDTI,\n $ LDWORK, M, N, NMINR, NR, P\n DOUBLE PRECISION SCALEC, SCALEO, TOL1, TOL2\nC .. Array Arguments ..\n INTEGER IWORK(*)\n DOUBLE PRECISION A(LDA,*), B(LDB,*), C(LDC,*), D(LDD,*),\n $ DWORK(*), HSV(*), T(LDT,*), TI(LDTI,*)\nC .. Local Scalars ..\n LOGICAL BAL, BTA, DISCR, FIXORD, RSF, SPA\n INTEGER IERR, IJ, J, K, KTAU, KU, KV, KW, LDW, LW,\n $ NRED, NR1, NS, WRKOPT\n DOUBLE PRECISION ATOL, RCOND, SKP, TEMP, TOLDEF\nC .. External Functions ..\n LOGICAL LSAME\n DOUBLE PRECISION DLAMCH\n EXTERNAL DLAMCH, LSAME\nC .. External Subroutines ..\n EXTERNAL AB09DD, DGEMM, DGEMV, DGEQRF, DGETRF, DGETRS,\n $ DLACPY, DORGQR, DSCAL, DTRMM, DTRMV, MA02AD,\n $ MB03UD, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC DBLE, INT, MAX, MIN, SQRT\nC .. Executable Statements ..\nC\n INFO = 0\n IWARN = 0\n DISCR = LSAME( DICO, 'D' )\n BTA = LSAME( JOB, 'B' ) .OR. LSAME( JOB, 'F' )\n SPA = LSAME( JOB, 'S' ) .OR. LSAME( JOB, 'P' )\n BAL = LSAME( JOB, 'B' ) .OR. LSAME( JOB, 'S' )\n RSF = LSAME( FACT, 'S' )\n FIXORD = LSAME( ORDSEL, 'F' )\nC\n LW = MAX( 1, 2*N*N + 5*N, N*MAX( M, P ) )\nC\nC Test the input scalar arguments.\nC\n IF( .NOT. ( LSAME( DICO, 'C' ) .OR. DISCR ) ) THEN\n INFO = -1\n ELSE IF( .NOT. ( BTA .OR. SPA ) ) THEN\n INFO = -2\n ELSE IF( .NOT. ( RSF .OR. LSAME( FACT, 'N' ) ) ) THEN\n INFO = -3\n ELSE IF( .NOT. ( FIXORD .OR. LSAME( ORDSEL, 'A' ) ) ) THEN\n INFO = -4\n ELSE IF( N.LT.0 ) THEN\n INFO = -5\n ELSE IF( M.LT.0 ) THEN\n INFO = -6\n ELSE IF( P.LT.0 ) THEN\n INFO = -7\n ELSE IF( FIXORD .AND. ( NR.LT.0 .OR. NR.GT.N ) ) THEN\n INFO = -8\n ELSE IF( SCALEC.LE.ZERO ) THEN\n INFO = -9\n ELSE IF( SCALEO.LE.ZERO ) THEN\n INFO = -10\n ELSE IF( LDA.LT.MAX( 1, N ) ) THEN\n INFO = -12\n ELSE IF( LDB.LT.MAX( 1, N ) ) THEN\n INFO = -14\n ELSE IF( LDC.LT.MAX( 1, P ) ) THEN\n INFO = -16\n ELSE IF( LDD.LT.1 .OR. ( SPA .AND. LDD.LT.P ) ) THEN\n INFO = -18\n ELSE IF( LDTI.LT.MAX( 1, N ) ) THEN\n INFO = -20\n ELSE IF( LDT.LT.MAX( 1, N ) ) THEN\n INFO = -22\n ELSE IF( TOL2.GT.ZERO .AND. .NOT.FIXORD .AND. TOL2.GT.TOL1 ) THEN\n INFO = -26\n ELSE IF( LDWORK.LT.LW ) THEN\n INFO = -29\n END IF\nC\n IF( INFO.NE.0 ) THEN\nC\nC Error return.\nC\n CALL XERBLA( 'AB09IX', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF( MIN( N, M, P ).EQ.0 ) THEN\n NR = 0\n NMINR = 0\n DWORK(1) = ONE\n RETURN\n END IF\nC\nC Save S in DWORK(KV).\nC\n KV = 1\n KU = KV + N*N\n KW = KU + N*N\n CALL DLACPY( 'Upper', N, N, TI, LDTI, DWORK(KV), N )\nC | x x |\nC Compute R*S in the form | 0 x | in TI.\nC\n DO 10 J = 1, N\n CALL DTRMV( 'Upper', 'NoTranspose', 'NonUnit', J, T, LDT,\n $ TI(1,J), 1 )\n 10 CONTINUE\nC\nC Compute the singular value decomposition R*S = V*Sigma*UT of the\nC upper triangular matrix R*S, with UT in TI and V in DWORK(KU).\nC\nC Workspace: need 2*N*N + 5*N;\nC prefer larger.\nC\n CALL MB03UD( 'Vectors', 'Vectors', N, TI, LDTI, DWORK(KU), N, HSV,\n $ DWORK(KW), LDWORK-KW+1, IERR )\n IF( IERR.NE.0 ) THEN\n INFO = 1\n RETURN\n ENDIF\n WRKOPT = INT( DWORK(KW) ) + KW - 1\nC\nC Scale the singular values.\nC\n CALL DSCAL( N, ONE / SCALEC / SCALEO, HSV, 1 )\nC\nC Partition Sigma, U and V conformally as:\nC\nC Sigma = diag(Sigma1,Sigma2,Sigma3), U = [U1,U2,U3] (U' in TI) and\nC V = [V1,V2,V3] (in DWORK(KU)).\nC\nC Compute NMINR, the order of a minimal realization, as the order\nC of [Sigma1 Sigma2].\nC\n TOLDEF = DBLE( N )*DLAMCH( 'Epsilon' )\n ATOL = MAX( TOL2, TOLDEF*HSV(1) )\n NMINR = N\n 20 IF( NMINR.GT.0 ) THEN\n IF( HSV(NMINR).LE.ATOL ) THEN\n NMINR = NMINR - 1\n GO TO 20\n END IF\n END IF\nC\nC Compute the order NR of reduced system, as the order of Sigma1.\nC\n IF( FIXORD ) THEN\nC\nC Check if the desired order is less than the order of a minimal\nC realization.\nC\n IF( NR.GT.NMINR ) THEN\nC\nC Reduce the order to NMINR.\nC\n NR = NMINR\n IWARN = 1\n END IF\nC\nC Check for singular value multiplicity at cut-off point.\nC\n IF( NR.GT.0 .AND. NR.LT.NMINR ) THEN\n SKP = HSV(NR)\n IF( SKP-HSV(NR+1).LE.TOLDEF*SKP ) THEN\n IWARN = 2\nC\nC Reduce the order such that HSV(NR) > HSV(NR+1).\nC\n 30 NR = NR - 1\n IF( NR.GT.0 ) THEN\n IF( HSV(NR)-SKP.LE.TOLDEF*SKP ) GO TO 30\n END IF\n END IF\n END IF\n ELSE\nC\nC The order is given as the number of singular values\nC exceeding MAX( TOL1, N*EPS*HSV(1) ).\nC\n ATOL = MAX( TOL1, ATOL )\n NR = 0\n DO 40 J = 1, NMINR\n IF( HSV(J).LE.ATOL ) GO TO 50\n NR = NR + 1\n 40 CONTINUE\n 50 CONTINUE\n ENDIF\nC\nC Finish if the order is zero.\nC\n IF( NR.EQ.0 ) THEN\n IF( SPA )\n $ CALL AB09DD( DICO, N, M, P, NR, A, LDA, B, LDB, C, LDC,\n $ D, LDD, RCOND, IWORK, DWORK, IERR )\n DWORK(1) = WRKOPT\n RETURN\n END IF\nC\nC Compute NS, the order of Sigma2. For BTA, NS = 0.\nC\n IF( SPA ) THEN\n NRED = NMINR\n ELSE\n NRED = NR\n END IF\n NS = NRED - NR\nC\nC Compute the truncation matrices.\nC\nC Compute TI' = | TI1' TI2' | = R'*| V1 V2 | in DWORK(KU).\nC\n CALL DTRMM( 'Left', 'Upper', 'Transpose', 'NonUnit', N, NRED,\n $ ONE, T, LDT, DWORK(KU), N )\nC\nC Compute T = | T1 T2 | = S*| U1 U2 | .\nC\n CALL MA02AD( 'Full', NRED, N, TI, LDTI, T, LDT )\n CALL DTRMM( 'Left', 'Upper', 'NoTranspose', 'NonUnit', N,\n $ NRED, ONE, DWORK(KV), N, T, LDT )\nC\n KTAU = KW\n IF( BAL ) THEN\n IJ = KU\nC\nC Square-Root B&T/SPA method.\nC\nC Compute the truncation matrices for balancing\nC -1/2 -1/2\nC T1*Sigma1 and TI1'*Sigma1 .\nC\n DO 60 J = 1, NR\n TEMP = ONE/SQRT( HSV(J) )\n CALL DSCAL( N, TEMP, T(1,J), 1 )\n CALL DSCAL( N, TEMP, DWORK(IJ), 1 )\n IJ = IJ + N\n 60 CONTINUE\nC\n ELSE\nC\nC Balancing-Free B&T/SPA method.\nC\nC Compute orthogonal bases for the images of matrices T1 and\nC TI1'.\nC\nC Workspace: need 2*N*N + 2*N;\nC prefer larger.\nC\n KW = KTAU + NR\n LDW = LDWORK - KW + 1\n CALL DGEQRF( N, NR, T, LDT, DWORK(KTAU), DWORK(KW), LDW, IERR )\n CALL DORGQR( N, NR, NR, T, LDT, DWORK(KTAU), DWORK(KW), LDW,\n $ IERR )\n CALL DGEQRF( N, NR, DWORK(KU), N, DWORK(KTAU), DWORK(KW), LDW,\n $ IERR )\n WRKOPT = MAX( WRKOPT, INT( DWORK(KW) ) + KW - 1 )\n CALL DORGQR( N, NR, NR, DWORK(KU), N, DWORK(KTAU), DWORK(KW),\n $ LDW, IERR )\n WRKOPT = MAX( WRKOPT, INT( DWORK(KW) ) + KW - 1 )\n ENDIF\nC\n IF( NS.GT.0 ) THEN\nC\nC Compute orthogonal bases for the images of matrices T2 and\nC TI2'.\nC\nC Workspace: need 2*N*N + 2*N;\nC prefer larger.\nC\n NR1 = NR + 1\n KW = KTAU + NS\n LDW = LDWORK - KW + 1\n CALL DGEQRF( N, NS, T(1,NR1), LDT, DWORK(KTAU), DWORK(KW), LDW,\n $ IERR )\n CALL DORGQR( N, NS, NS, T(1,NR1), LDT, DWORK(KTAU), DWORK(KW),\n $ LDW, IERR )\n CALL DGEQRF( N, NS, DWORK(KU+N*NR), N, DWORK(KTAU), DWORK(KW),\n $ LDW, IERR )\n WRKOPT = MAX( WRKOPT, INT( DWORK(KW) ) + KW - 1 )\n CALL DORGQR( N, NS, NS, DWORK(KU+N*NR), N, DWORK(KTAU),\n $ DWORK(KW), LDW, IERR )\n WRKOPT = MAX( WRKOPT, INT( DWORK(KW) ) + KW - 1 )\n ENDIF\nC\nC Transpose TI' in TI.\nC\n CALL MA02AD( 'Full', N, NRED, DWORK(KU), N, TI, LDTI )\nC\n IF( .NOT.BAL ) THEN\nC -1\nC Compute (TI1*T1) *TI1 in TI.\nC\n CALL DGEMM( 'NoTranspose', 'NoTranspose', NR, NR, N, ONE, TI,\n $ LDTI, T, LDT, ZERO, DWORK(KU), N )\n CALL DGETRF( NR, NR, DWORK(KU), N, IWORK, IERR )\n CALL DGETRS( 'NoTranspose', NR, N, DWORK(KU), N, IWORK, TI,\n $ LDTI, IERR )\nC\n IF( NS.GT.0 ) THEN\nC -1\nC Compute (TI2*T2) *TI2 in TI2.\nC\n CALL DGEMM( 'NoTranspose', 'NoTranspose', NS, NS, N, ONE,\n $ TI(NR1,1), LDTI, T(1,NR1), LDT, ZERO, DWORK(KU),\n $ N )\n CALL DGETRF( NS, NS, DWORK(KU), N, IWORK, IERR )\n CALL DGETRS( 'NoTranspose', NS, N, DWORK(KU), N, IWORK,\n $ TI(NR1,1), LDTI, IERR )\n END IF\n END IF\nC\nC Compute TI*A*T. Exploit RSF of A if possible.\nC Workspace: need N*N.\nC\n IF( RSF ) THEN\n IJ = 1\n DO 80 J = 1, N\n K = MIN( J+1, N )\n CALL DGEMV( 'NoTranspose', NRED, K, ONE, TI, LDTI,\n $ A(1,J), 1, ZERO, DWORK(IJ), 1 )\n IJ = IJ + N\n 80 CONTINUE\n ELSE\n CALL DGEMM( 'NoTranspose', 'NoTranspose', NRED, N, N, ONE,\n $ TI, LDTI, A, LDA, ZERO, DWORK, N )\n END IF\n CALL DGEMM( 'NoTranspose', 'NoTranspose', NRED, NRED, N, ONE,\n $ DWORK, N, T, LDT, ZERO, A, LDA )\nC\nC Compute TI*B and C*T.\nC Workspace: need N*MAX(M,P).\nC\n CALL DLACPY( 'Full', N, M, B, LDB, DWORK, N )\n CALL DGEMM( 'NoTranspose', 'NoTranspose', NRED, M, N, ONE, TI,\n $ LDTI, DWORK, N, ZERO, B, LDB )\nC\n CALL DLACPY( 'Full', P, N, C, LDC, DWORK, P )\n CALL DGEMM( 'NoTranspose', 'NoTranspose', P, NRED, N, ONE,\n $ DWORK, P, T, LDT, ZERO, C, LDC )\nC\nC Compute the singular perturbation approximation if possible.\nC Note that IERR = 1 on exit from AB09DD cannot appear here.\nC\nC Workspace: need real 4*(NMINR-NR);\nC need integer 2*(NMINR-NR).\nC\n IF( SPA) THEN\n CALL AB09DD( DICO, NRED, M, P, NR, A, LDA, B, LDB,\n $ C, LDC, D, LDD, RCOND, IWORK, DWORK, IERR )\n ELSE\n NMINR = NR\n END IF\n DWORK(1) = WRKOPT\nC\n RETURN\nC *** Last line of AB09IX ***\n END\n", "meta": {"hexsha": "f40de96c3a6095378b7fb185d98956311c1412bc", "size": 24607, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/AB09IX.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/AB09IX.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/AB09IX.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 36.0806451613, "max_line_length": 72, "alphanum_fraction": 0.5394806356, "num_tokens": 7724, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9416541610257062, "lm_q2_score": 0.7217432182679957, "lm_q1q2_score": 0.6796325046741426}} {"text": " module fft_module\n use m_kind\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_module\n\n module m_psycho\n use m_kind\n implicit none\n private\n public :: psychoacoustics\n real(kd), save :: freq_fft(0:256), pseud_bark(0:256), ath_fft(0:256)\n real(kd), save :: crbw_fft(0:256), cbwl_fft(0:256)\n real(kd), save :: sp(256, 256) ! spreading function for masking\n real(kd), save :: scale\n real(kd), parameter :: alpha = 0.27d0 ! non-linear factor\n contains\n subroutine psychoacoustics(pcm, isample_rate, smr)\n use fft_module\n real (kd), intent(in ) :: pcm(:, :) \n integer , intent(in ) :: isample_rate\n real (kd), intent(out) :: smr(:, :)\n complex(kd) :: cfft(512)\n integer :: ichannel, i0, i1\n logical, save :: qfirst = .true.\n if (qfirst) then\n qfirst = .false.\n call init_absolute_threshold(isample_rate)\n end if\n i0 = 161 \n i1 = i0 + 512 - 1\n do ichannel = 1, size(pcm, 2)\n call fft_window(pcm(i0:i1, ichannel), cfft)\n call calc_smr(cfft, smr(:, ichannel))\n end do\n end subroutine\n \n subroutine init_absolute_threshold(isample_rate)\n integer, intent(in) :: isample_rate\n real (kd) :: freq, tmp\n integer :: i, m, i0, i1\n do i = 0, size(freq_fft) - 1\n freq = real(isample_rate, kind = kd) / 2.0_kd / 1000.0_kd &\n * real(i, kind = kd) / real(size(freq_fft), kind = kd)\n ath_fft(i) = 3.64_kd * freq**(-0.8_kd) & ! \n - 6.5_kd * exp(-0.6_kd * (freq - 3.3_kd)**2) + 0.001_kd * freq**4.0_kd \n freq = freq * 1000.0_kd ! khz -> hz\n freq_fft(i) = freq\n end do\n scale = real(isample_rate, kind = kd) / 2 / 256 ! freq to fft-line scale\n crbw_fft = critical_band_width( freq_fft ) ! critical band width in hz\n cbwl_fft = decibel( crbw_fft ) ! critical band width in log\n tmp = 0.0_kd ! pseud bark: integrate critical band \n do m = 1, 256\n tmp = tmp + 1.0_kd / crbw_fft(m) ! integration\n pseud_bark(m) = tmp * scale \n end do\n ! spreading function\n forall(i = 1:256, m = 1:256) sp(i, m) = spreading( pseud_bark( i ) - pseud_bark( m ) ) ! top normalized to 1.0\n end subroutine init_absolute_threshold\n\n pure elemental real(kd) function spreading(z)\n real(kd), intent(in) :: z ! pseud-bark\n if ( z > 0.0d0 ) then\n spreading = -25.0_kd * z \n else\n spreading = 75.0_kd * z \n end if\n spreading = max(-160.0_kd, spreading)\n end function spreading\n\n pure elemental real(kd) function critical_band_width(f)\n real(kd), intent(in) :: f ! hz\n real(kd), parameter :: gamma = 0.69_kd\n critical_band_width = 25.0_kd + 75.0_kd * ( 1.0_kd + 1.4_kd * (f / 1000.0_kd)**2 )**gamma \n ! critical_band_width = 100.0d0 * ( 1.0d0 + 1.0d0 * (f / 1000.0d0)**2 )**gamma \n end function critical_band_width\n\n pure elemental real(kd) function decibel(x) \n real (kd), intent(in) :: x \n real (kd) :: tmp\n tmp = max(1.0e-100_kd, x)\n decibel = 10.0e0_kd * log10(tmp)\n end function decibel\n \n subroutine calc_smr(cfft, smr)\n complex(kd), intent(in) :: cfft(0:)\n real (kd), intent(out) :: smr(:)\n real (kd), parameter :: pi = 4 * atan(1.0_kd), pi2 = 2 * pi ! fortran2003\n real (kd) :: snr(32), rmnr(32)\n real (kd) :: xa(0:256), ya(0:256), za(0:256)\n integer :: iband, i, m, i0, i1\n xa = 2 * decibel( abs(cfft(0:256)) )\n ya = 0.0_kd\n do i = 1, 256 ! convolution of spreading function \n do m = 1, 256 ! i maskee, m masker\n ya(i) = ya(i) + 10.0_kd**( ((sp(i, m) + xa(m) - ath_fft(m)) * alpha - cbwl_fft(m)) / 10.0_kd ) ! non-linear sum\n end do \n end do \n ya = max(decibel(ya * scale) / alpha - 11.5_kd, ath_fft - 90.3_kd) ! 11.5 mask factor, 90.3dB = 2^15 ATH shift empirical \n ! effective spl\n do i = 1, 256\n m = nint( crbw_fft(i) / scale )\n i0 = max(i - m / 2, 1) !f0 - bw(f0) / 2 \n i1 = min(i0 + m - 1, 256) !f0 + bw(f0) / 2\n za(i) = sum( 10.0_kd**( (xa(i0:i1) * alpha - cbwl_fft(i)) / 10.0_kd ) ) \n end do\n za = decibel(za * scale) / alpha\n ! smr = snr' - mnr'\n do iband = 1, 32\n m = (iband - 1) * 8 + 1\n i0 = m - nint( crbw_fft(m) / 2 / scale ) ! fl - bw(fl) / 2 ; subband [fl..fh] \n i0 = max(i0, 1)\n m = m + 7\n i1 = m + nint( crbw_fft(m) / 2 / scale ) ! fh + bw(fh) / 2 \n i1 = min(i1, 256)\n snr(iband) = maxval( za(i0:i1) )\n rmnr(iband) = minval( ya(i0:i1) ) \n end do\n smr = snr - rmnr \n end subroutine calc_smr\n end module m_psycho", "meta": {"hexsha": "fe728dc986fd370fd1eb58094cf3447859059eac", "size": 7583, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "psycho.f90", "max_stars_repo_name": "cure-honey/uzura1", "max_stars_repo_head_hexsha": "5f91a5b1dcf41bd0a46dd641a7d6fa94e28b5e4d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-04-23T17:51:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-17T00:33:03.000Z", "max_issues_repo_path": "psycho.f90", "max_issues_repo_name": "cure-honey/uzura1", "max_issues_repo_head_hexsha": "5f91a5b1dcf41bd0a46dd641a7d6fa94e28b5e4d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "psycho.f90", "max_forks_repo_name": "cure-honey/uzura1", "max_forks_repo_head_hexsha": "5f91a5b1dcf41bd0a46dd641a7d6fa94e28b5e4d", "max_forks_repo_licenses": ["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.8418079096, "max_line_length": 134, "alphanum_fraction": 0.4467888698, "num_tokens": 2360, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541528387692, "lm_q2_score": 0.7217432003123989, "lm_q1q2_score": 0.6796324818573141}} {"text": "MODULE RungeKutta\n\t\n\tuse subs_raytracing\n\timplicit none\n\n\tcontains\n\n\tsubroutine RK4(x,y,dt,dxdt,dydt,param1,param2,x_1,y_1)\n\t\t!-----------------------------------------------------------------\n\t\t! Runge\u2013Kutta fourth-order method\n\t\t! CALLING SEQUENCE : RK4(x,y,dt,dxdt,dydt,param1,x_1,y_1)\n\t\t! INPUTS: x: 3*Nray dimension vector\n\t\t! y: 3*Nray dimension vector\n\t\t! dt: integration time step\n\t\t! dxdt: the derivative of x\n\t\t! dydt: the derivative of y\n\t\t! param1: parameter --> f\n\t\t!\t param2: parameter --> mode ('X' ou 'O' ou 'V')\n\t\t! OUTPUTS: x_1: 3*Nray dimension vector at n+1 step\n\t\t! y_1: 3*Nray dimension vector at n+1 step\n\t\t!-----------------------------------------------------------------\n\timplicit none\n\treal(kind=8), dimension(:,:), intent(in) :: x,y\n\treal(kind=8), dimension(:), intent(in) :: dt\n\treal(kind=8), intent(in) :: param1\n\tcharacter(len=1), intent(in), dimension(:):: param2\n\treal(kind=8), dimension(:,:), intent(out) :: x_1,y_1\n\t \n\texternal :: dxdt, dydt\n\t\n\treal(kind=8), dimension(3,size(dt)) :: dx1,dy1,dx2,dy2,dx3,dy3,dx4,dy4\n\treal(kind=8), dimension(3,size(dt)) :: dx1dt,dy1dt,dx2dt,dy2dt,dx3dt\t\n\treal(kind=8), dimension(3,size(dt)) :: dy3dt,dx4dt,dy4dt, Yp\n\treal(kind=8), dimension(size(dt))\t\t :: Xp\n\tinteger\t\t\t\t\t\t\t\t\t :: i\n\treal(kind=8), dimension(size(dt))\t\t :: nmode\n\t\n\tcall dxdt(x,y,param1,param2,dx1dt,size(dt)) !drdt\n\tcall varplasma(x,param1,Xp,Yp)\t\n\tforall (i=1:3) dx1(i,:)=dt(:)*dx1dt(i,:)!*sqrt((1.d0-Xp)/(dx1dt(1,:)**2+dx1dt(2,:)**2+dx1dt(3,:)**2))\n\t\n\tcall dydt(x,y,param1,param2,dy1dt,size(dt)) !dkdt\n\tforall (i=1:3) dy1(i,:)=dt(:)*dy1dt(i,:)!*sqrt((1.d0-Xp)/(dx1dt(1,:)**2+dx1dt(2,:)**2+dx1dt(3,:)**2))\n\n\tcall dxdt(x+dx1/2.d0,y+1.d0/2.d0*dy1,param1,param2,dx2dt,size(dt)) !drdt\n\tcall varplasma(x+dx1/2.d0,param1,Xp,Yp)\n\tforall (i=1:3) dx2(i,:)=dt(:)*dx2dt(i,:)!*sqrt((1.d0-Xp)/(dx2dt(1,:)**2+dx2dt(2,:)**2+dx2dt(3,:)**2))\n\t\t\n\tcall dydt(x+dx1/2.d0,y+1.d0/2.d0*dy1,param1,param2,dy2dt,size(dt)) !dkdt\n\tforall (i=1:3) dy2(i,:)=dt(:)*dy2dt(i,:)!*sqrt((1.d0-Xp)/(dx2dt(1,:)**2+dx2dt(2,:)**2+dx2dt(3,:)**2))\n\n\tcall dxdt(x+dx2/2.d0,y+1.d0/2.d0*dy2,param1,param2,dx3dt,size(dt)) !drdt\n\tcall varplasma(x+dx2/2.d0,param1,Xp,Yp)\n\tforall (i=1:3) dx3(i,:)=dt(:)*dx3dt(i,:)!*sqrt((1.d0-Xp)/(dx3dt(1,:)**2+dx3dt(2,:)**2+dx3dt(3,:)**2))\n\n\tcall dydt(x+dx2/2.d0,y+1.d0/2.d0*dy2,param1,param2,dy3dt,size(dt)) !drdt\n\tforall (i=1:3) dy3(i,:)=dt(:)*dy3dt(i,:)!*sqrt((1.d0-Xp)/(dx3dt(1,:)**2+dx3dt(2,:)**2+dx3dt(3,:)**2))\n\n\tcall dxdt(x+dx3,y+dy3,param1,param2,dx4dt,size(dt)) !drdt\n\tcall varplasma(x+dx3,param1,Xp,Yp)\n\tforall (i=1:3) dx4(i,:)=dt(:)*dx4dt(i,:)!*sqrt((1.d0-Xp)/(dx4dt(1,:)**2+dx4dt(2,:)**2+dx4dt(3,:)**2))\n\n\tcall dydt(x+dx3,y+dy3,param1,param2,dy4dt,size(dt)) !drdt\n\tforall (i=1:3) dy4(i,:)=dt(:)*dy4dt(i,:)!*sqrt((1.d0-Xp)/(dx4dt(1,:)**2+dx4dt(2,:)**2+dx4dt(3,:)**2))\n\n\t!change of sign of derivatives in Haselgrove_63 needed to get the right equations without B\n\twhere (param2 .eq. 'X')\n\t\tnmode =-1.d0\n\telse where\n\t\tnmode = 1.d0\n\tend where\n\t\n\n\tforall(i=1:3) x_1(i,:) = x(i,:) + nmode(:)*1.d0/6.d0*(dx1(i,:)+2.d0*dx2(i,:)+2.d0*dx3(i,:)+dx4(i,:))\n\tforall(i=1:3) y_1(i,:) = y(i,:) + nmode(:)*1.d0/6.d0*(dy1(i,:)+2.d0*dy2(i,:)+2.d0*dy3(i,:)+dy4(i,:))\n\n\tend subroutine RK4\nEND MODULE RungeKutta\n", "meta": {"hexsha": "4c6ad98a0fa47b219800940447c0b144b90c92d5", "size": 3359, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "RaytracingCode/RungeKutta.f90", "max_stars_repo_name": "maserlib/ARTEMIS-P", "max_stars_repo_head_hexsha": "4c10d3b92bcab079bc1f19b25f2613b1a23476c2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-17T13:50:47.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-17T13:50:47.000Z", "max_issues_repo_path": "RaytracingCode/RungeKutta.f90", "max_issues_repo_name": "maserlib/ARTEMIS-P", "max_issues_repo_head_hexsha": "4c10d3b92bcab079bc1f19b25f2613b1a23476c2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "RaytracingCode/RungeKutta.f90", "max_forks_repo_name": "maserlib/ARTEMIS-P", "max_forks_repo_head_hexsha": "4c10d3b92bcab079bc1f19b25f2613b1a23476c2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-29T17:32:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T17:32:19.000Z", "avg_line_length": 42.5189873418, "max_line_length": 102, "alphanum_fraction": 0.5677284906, "num_tokens": 1418, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218391455084, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6796022143552856}} {"text": " subroutine newton(x,fx,dfx,ermaxa,temper)\n! ----------------------------------\n implicit none\n integer num\n double precision x,fx,dfx,ermaxa,temper,eror,fx0\n double precision fxfx0,residu,err\n\n! methode de newton-raphson amelioree\n\n eror=1.d-10\n\n call phfunc(x,fx0,dfx,temper)\n fx=fx0\n\n num=1\n\n! commencer par des pas doubles jusqu'a ce que fx*fx0<0\n\n 1 continue\n x=x-2.*fx/dfx\n call phfunc(x,fx,dfx,temper)\n num=num+1\n fxfx0=fx*fx0\n if(num.ge.51)then\n write(74,*)'num=',num,' x=',x\n write(74,*)'fx=',fx,' dfx=',dfx\n write(74,*)'program stop'\n stop\n endif\n if(fxfx0.gt.0.)go to 1\n\n! continuer par newton-raphson classique\n\n 2 continue\n residu=-fx/dfx\n x=x+residu\n call phfunc(x,fx,dfx,temper)\n num=num+1\n err=dabs(residu/x)\n if(num.ge.101)then\n write(74,*)'num=',num,' x=',x\n write(74,*)'fx=',fx,' dfx=',dfx\n write(74,*)'program stop'\n stop\n endif\n if(err.gt.eror)go to 2\n\n return\n end\n", "meta": {"hexsha": "0a11c71b0d584e54bf40fced7bc3feb432e95fff", "size": 1035, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/newton.f", "max_stars_repo_name": "piermafrost/GEOCLIM5_sulf", "max_stars_repo_head_hexsha": "26c8d1e2cabc64619ae7ea000a9a507f6ed39982", "max_stars_repo_licenses": ["NetCDF"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source/newton.f", "max_issues_repo_name": "piermafrost/GEOCLIM5_sulf", "max_issues_repo_head_hexsha": "26c8d1e2cabc64619ae7ea000a9a507f6ed39982", "max_issues_repo_licenses": ["NetCDF"], "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/newton.f", "max_forks_repo_name": "piermafrost/GEOCLIM5_sulf", "max_forks_repo_head_hexsha": "26c8d1e2cabc64619ae7ea000a9a507f6ed39982", "max_forks_repo_licenses": ["NetCDF"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.7, "max_line_length": 57, "alphanum_fraction": 0.5642512077, "num_tokens": 392, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218391455084, "lm_q2_score": 0.7371581510799253, "lm_q1q2_score": 0.6796021983847073}} {"text": "C\nC $Id$\nC\n SUBROUTINE SHSTORE3 (N,X,Y,Z,NR, LCELL,LNEXT,XYZMIN,\n + XYZDEL,IER)\n INTEGER N, NR, LCELL(NR,NR,NR), LNEXT(N), IER\n REAL X(N), Y(N), Z(N), XYZMIN(3), XYZDEL(3)\nC\nC***********************************************************\nC\nC ROBERT RENKA\nC UNIV. OF NORTH TEXAS\nC (817) 565-2767\nC\nC Given a set of N arbitrarily distributed nodes in three-\nC space, this subroutine creates a data structure for a\nC cell-based method of solving closest-point problems. The\nC smallest box containing the nodes is partitioned into an\nC NR by NR by NR uniform grid of cells, and nodes are as-\nC sociated with cells. In particular, the data structure\nC stores the indices of the nodes contained in each cell.\nC For a uniform random distribution of nodes, the nearest\nC node to an arbitrary point can be determined in constant\nC expected time.\nC\nC ON INPUT --\nC\nC N = number of nodes. N .GE. 2.\nC\nC X,Y,Z = arrays of length N containing the Cartesian\nC coordinates of the nodes.\nC\nC NR = number of rows, columns, and planes in the\nC grid. The cell density (average number of\nC nodes per cell) is D = N/(NR**3). A recommended\nC value, based on empirical evidence, is D = 3\nC -- NR = (N/3)**(1/3). NR .GE. 1.\nC\nC The above parameters are not altered by this routine.\nC\nC LCELL = array of length .GE. NR**3.\nC\nC LNEXT = array of length .GE. N.\nC\nC XYZMIN,XYZDEL = arrays of length .GE. 3.\nC\nC ON OUTPUT --\nC\nC LCELL = NR by NR by NR cell array such that\nC LCELL(I,J,K) contains the index (for X, Y,\nC and Z) of the first node (node with smallest\nC index) in cell (I,J,K), or LCELL(I,J,K) = 0\nC If no nodes are contained in the cell. The\nC corner of cell (I,J,K) which is farthest\nC from the box corner defined by XYZMIN has\nC coordinates (XMIN+I*DX,YMIN+J*DY,ZMIN+K*DZ),\nC where (XMIN,YMIN,ZMIN) are the elements of\nC XYZMIN. LCELL is not defined if IER .NE. 0.\nC\nC LNEXT = Array of next-node indices such that\nC LNEXT(L) contains the index of the next node\nC in the cell which contains node L, or\nC LNEXT(L) = L if L is the last node in the\nC cell for L = 1,...,N. (The nodes contained\nC in a cell are ordered by their indices.)\nC If, for example, cell (I,J,K) contains nodes\nC 2, 3, and 5 (and no others), then\nC LCELL(I,J,K) = 2, LNEXT(2) = 3, LNEXT(3) =\nC 5, and LNEXT(5) = 5. LNEXT is not defined\nC if IER .NE. 0.\nC\nC XYZMIN = Array of length 3 containing the minimum\nC nodal coordinates XMIN, YMIN, and ZMIN (in\nC that order) unless IER = 1. The opposite\nC corner of the box defined by the nodes is\nC (XMIN+NR*DX,YMIN+NR*DY,ZMIN+NR*DZ).\nC\nC XYZDEL = Array of length 3 containing the dimensions\nC of the cells unless IER = 1. XYZDEL(1) =\nC (XMAX-XMIN)/NR, XYZDEL(2) = (YMAX-YMIN)/NR,\nC AND XYZDEL(3) = (ZMAX-ZMIN)/NR, where XMIN,\nC XMAX, YMIN, YMAX, ZMIN, and ZMAX are the\nC extrema of X, Y, and Z.\nC\nC IER = Error indicator --\nC IER = 0 if no errors were encountered.\nC IER = 1 if N .LT. 2 or NR .LT. 1.\nC IER = 2 if a component of XYZDEL is not positive.\nC\nC MODULES REQUIRED BY SHSTORE3 -- NONE\nC\nC INTRINSIC FUNCTIONS CALLED BY SHSTORE3 -- FLOAT, IFIX\nC\nC***********************************************************\nC\n NN = N\n NNR = NR\n IF (NN .LT. 2 .OR. NNR .LT. 1) GO TO 4\nC\nC Compute the dimensions of the rectangle containing the nodes.\nC\n XMN = X(1)\n XMX = XMN\n YMN = Y(1)\n YMX = YMN\n ZMN = Z(1)\n ZMX = ZMN\n DO 1 L = 2,NN\n IF (X(L) .LT. XMN) XMN = X(L)\n IF (X(L) .GT. XMX) XMX = X(L)\n IF (Y(L) .LT. YMN) YMN = Y(L)\n IF (Y(L) .GT. YMX) YMX = Y(L)\n IF (Z(L) .LT. ZMN) ZMN = Z(L)\n IF (Z(L) .GT. ZMX) ZMX = Z(L)\n 1 CONTINUE\n XYZMIN(1) = XMN\n XYZMIN(2) = YMN\n XYZMIN(3) = ZMN\nC\nC Compute cell dimensions and test for zero area.\nC\n DELX = (XMX-XMN)/FLOAT(NNR)\n DELY = (YMX-YMN)/FLOAT(NNR)\n DELZ = (ZMX-ZMN)/FLOAT(NNR)\n XYZDEL(1) = DELX\n XYZDEL(2) = DELY\n XYZDEL(3) = DELZ\n IF (DELX .EQ. 0. .OR. DELY .EQ. 0. .OR.\n + DELZ .EQ. 0.) GO TO 5\nC\nC INITIALIZE LCELL.\nC\n DO 7 K = 1,NNR\n DO 6 J = 1,NNR\n DO 2 I = 1,NNR\n LCELL(I,J,K) = 0\n 2 CONTINUE\n 6 CONTINUE\n 7 CONTINUE\nC\nC Loop on nodes, storing indices in LCELL and LNEXT.\nC\n NP1 = NN + 1\n DO 3 LL = 1,NN\n LB = NP1 - LL\n I = IFIX((X(LB)-XMN)/DELX) + 1\n IF (I .GT. NNR) I = NNR\n J = IFIX((Y(LB)-YMN)/DELY) + 1\n IF (J .GT. NNR) J = NNR\n K = IFIX((Z(LB)-ZMN)/DELZ) + 1\n IF (K .GT. NNR) K = NNR\n L = LCELL(I,J,K)\n LNEXT(LB) = L\n IF (L .EQ. 0) LNEXT(LB) = LB\n LCELL(I,J,K) = LB\n 3 CONTINUE\nC\nC No errors encountered.\nC\n IER = 0\n RETURN\nC\nC Invalid input parameter.\nC\n 4 CONTINUE\n CALL SHERR (1,'SHSTORE3 - number of input data must be > 9',41)\n IER = 1\n RETURN\nC\nC Nonpositive XYZDEL component.\nC\n 5 CONTINUE\n CALL SHERR (7,\n + 'SHSTORE3 - cell grid dimensions must be positive',\n + 48)\n IER = 7\n RETURN\n END\n", "meta": {"hexsha": "ebb071f30b5d34c5d2474807fa0e392f0d00e568", "size": 5649, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "contrib/shgrid/Src/shstore3.f", "max_stars_repo_name": "xylar/cdat", "max_stars_repo_head_hexsha": "8a5080cb18febfde365efc96147e25f51494a2bf", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 62, "max_stars_repo_stars_event_min_datetime": "2018-03-30T15:46:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-08T23:30:24.000Z", "max_issues_repo_path": "contrib/shgrid/Src/shstore3.f", "max_issues_repo_name": "xylar/cdat", "max_issues_repo_head_hexsha": "8a5080cb18febfde365efc96147e25f51494a2bf", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 114, "max_issues_repo_issues_event_min_datetime": "2018-03-21T01:12:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-05T12:29:54.000Z", "max_forks_repo_path": "contrib/shgrid/Src/shstore3.f", "max_forks_repo_name": "CDAT/uvcdat", "max_forks_repo_head_hexsha": "5133560c0c049b5c93ee321ba0af494253b44f91", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2018-06-06T02:42:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-26T03:27:00.000Z", "avg_line_length": 31.5586592179, "max_line_length": 69, "alphanum_fraction": 0.5354930076, "num_tokens": 1902, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190939, "lm_q2_score": 0.7905303137346446, "lm_q1q2_score": 0.6795902487123422}} {"text": "program select_kind\n implicit none\n integer, parameter :: i4=SELECTED_INT_KIND(4)\n integer, parameter :: i8=SELECTED_INT_KIND(8)\n integer, parameter :: i15=SELECTED_INT_KIND(15)\n integer, parameter :: r4=SELECTED_REAL_KIND(6,37)\n integer, parameter :: r8=SELECTED_REAL_KIND(15,307)\n integer(KIND=i4) :: ia\n integer(KIND=i8) :: ib\n integer(KIND=i15) :: ic\n real(KIND=r4) :: ra\n real(KIND=r8) :: rb\n\n print *,' Integer kind=', i4, ' biggest value=', huge(ia)\n print *,' Integer kind=', i8, ' biggest value=', huge(ib)\n print *,' Integer kind=', i15, ' biggest value=', huge(ic)\n print *,' Real kind=', r4, ' smallest value= ', tiny(ra) , &\n ' biggest value=', huge(ra)\n print *,' Real kind=', r8, ' smallest value= ', tiny(rb) , &\n ' biggest value=', huge(rb)\n\nend program select_kind\n", "meta": {"hexsha": "7b9a0d9466d226ab6638cd7fb2db98354981f7b4", "size": 827, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/gettingStarted/select_kind.f90", "max_stars_repo_name": "annefou/Fortran", "max_stars_repo_head_hexsha": "9d3d81de1ae32723e64eb3d07195867293a82c5e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 32, "max_stars_repo_stars_event_min_datetime": "2016-04-08T19:04:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-13T15:44:37.000Z", "max_issues_repo_path": "src/gettingStarted/select_kind.f90", "max_issues_repo_name": "inandi2/Fortran-1", "max_issues_repo_head_hexsha": "9d3d81de1ae32723e64eb3d07195867293a82c5e", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/gettingStarted/select_kind.f90", "max_forks_repo_name": "inandi2/Fortran-1", "max_forks_repo_head_hexsha": "9d3d81de1ae32723e64eb3d07195867293a82c5e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2016-04-08T19:05:49.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-08T19:57:51.000Z", "avg_line_length": 35.9565217391, "max_line_length": 62, "alphanum_fraction": 0.6336154776, "num_tokens": 255, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430562234877, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.6795213506810804}} {"text": "! Matrix Module\r\n\r\n module Matrix\r\n use Util\r\n implicit none\r\n integer :: D_MAX_ITER = 1000\r\n double precision :: D_TOL = 1.0D-5\r\n contains\r\n subroutine ill_cond()\r\n! Prompts the user with an ill-conditioning warning.\r\n implicit none\r\n call error('Matriz mal-condicionada: este m\u00e9todo n\u00e3o ir\u00e1 convergir.')\r\n end subroutine\r\n\r\n subroutine show_matrix(var, A, m, n)\r\n implicit none\r\n integer :: m, n\r\n character(len=*) :: var\r\n double precision, dimension(m, n), intent(in) :: A\r\n write (*, *) ''//achar(27)//'[36m'//var//' = '\r\n call print_matrix(A, m, n)\r\n write (*, *) ''//achar(27)//'[0m'\r\n end subroutine\r\n\r\n subroutine print_matrix(A, m, n)\r\n implicit none\r\n integer :: m, n\r\n double precision :: A(m, n)\r\n integer :: i, j\r\n20 format(' |', F32.12, ' ')\r\n21 format(F30.12, '|')\r\n22 format(F30.12, ' ')\r\n do i = 1, m\r\n do j = 1, n\r\n if (j == 1) then\r\n write(*, 20, advance='no') A(i, j)\r\n elseif (j == n) then\r\n write(*, 21, advance='yes') A(i, j)\r\n else\r\n write(*, 22, advance='no') A(i, j)\r\n end if\r\n end do\r\n end do\r\n end subroutine\r\n \r\n subroutine read_matrix(fname, A, m, n)\r\n implicit none\r\n character(len=*) :: fname\r\n integer :: m, n\r\n double precision, dimension(:, :), allocatable :: A\r\n integer :: i\r\n open(unit=33, file=fname, status='old', action='read')\r\n read(33, *) m\r\n read(33, *) n\r\n allocate(A(m, n))\r\n do i = 1, m\r\n read(33,*) A(i,:)\r\n end do\r\n close(33)\r\n end subroutine\r\n\r\n subroutine print_vector(x, n)\r\n implicit none\r\n integer :: n\r\n double precision :: x(n)\r\n integer :: i\r\n30 format(' |', F30.12, '|')\r\n do i = 1, n\r\n write(*, 30) x(i)\r\n end do\r\n end subroutine\r\n\r\n subroutine read_vector(fname, b, n)\r\n implicit none\r\n character(len=*) :: fname\r\n integer :: n\r\n double precision, allocatable :: b(:)\r\n\r\n open(unit=33, file=fname, status='old', action='read')\r\n read(33, *) n\r\n allocate(b(n))\r\n read(33, *) b(:)\r\n close(33)\r\n end subroutine\r\n\r\n subroutine show_vector(var, x, n)\r\n implicit none\r\n integer :: n\r\n character(len=*) :: var\r\n double precision :: x(n)\r\n write (*, *) ''//achar(27)//'[36m'//var//' = '\r\n call print_vector(x, n)\r\n write (*, *) ''//achar(27)//'[0m'\r\n end subroutine\r\n\r\n\r\n! =========== Matrix Methods ============\r\n\r\n function clip(x, n, a, b) result (y)\r\n integer, intent(in) :: n\r\n integer :: k\r\n double precision, intent(in) :: a, b\r\n double precision, dimension(n), intent(in) :: x\r\n double precision, dimension(n) :: y\r\n\r\n do k=1, n\r\n if ((a <= x(k)) .AND. (x(k) <= b)) then\r\n y(k) = x(k)\r\n else\r\n y(k) = DNAN\r\n end if\r\n end do\r\n return\r\n end function\r\n\r\n function rand_vector(n, a, b) result (r)\r\n implicit none\r\n integer :: n, i\r\n double precision, dimension(n) :: r\r\n double precision, optional :: a, b\r\n double precision :: t_a, t_b\r\n \r\n if (.NOT. PRESENT(a)) then\r\n t_a = -1.0D0\r\n else\r\n t_a = a\r\n end if\r\n\r\n if (.NOT. PRESENT(b)) then\r\n t_b = 1.0D0\r\n else\r\n t_b = b\r\n end if\r\n\r\n do i = 1, n\r\n r(i) = DRAND(t_a, t_b)\r\n end do\r\n return\r\n end function\r\n\r\n function rand_matrix(m, n, a, b) result (R)\r\n implicit none\r\n integer :: m, n, i\r\n double precision, dimension(m, n) :: R\r\n double precision, optional :: a, b\r\n \r\n do i = 1, m\r\n R(i, :) = rand_vector(n, a=a, b=b)\r\n end do\r\n return\r\n end function\r\n\r\n function id_matrix(n) result (A)\r\n implicit none\r\n integer :: n\r\n double precision :: A(n, n)\r\n integer :: j\r\n A(:, :) = 0.0D0\r\n do j = 1, n\r\n A(j, j) = 1.0D0\r\n end do\r\n return\r\n end function\r\n\r\n function given_matrix(A, n, i, j) result (G)\r\n implicit none\r\n\r\n integer :: n, i, j\r\n double precision :: A(n, n), G(n, n)\r\n double precision :: t, c, s\r\n\r\n G(:, :) = id_matrix(n)\r\n\r\n t = 0.5D0 * DATAN2(2.0D0 * A(i,j), A(i, i) - A(j, j))\r\n s = DSIN(t)\r\n c = DCOS(t)\r\n\r\n G(i, i) = c\r\n G(j, j) = c\r\n G(i, j) = -s\r\n G(j, i) = s\r\n\r\n return\r\n end function\r\n\r\n function vandermond_matrix(x, n) result (V)\r\n implicit none\r\n integer :: n, i\r\n double precision, dimension(n), intent(in) :: x\r\n double precision, dimension(n, n) :: V\r\n V(1, :) = 1.0D0\r\n do i=2, n\r\n V(i, :) = V(i-1, :) * x(:)\r\n end do\r\n return\r\n end function\r\n\r\n function diagonally_dominant(A, n) result (ok)\r\n implicit none\r\n\r\n integer :: n\r\n double precision :: A(n, n)\r\n\r\n logical :: ok\r\n integer :: i\r\n\r\n do i = 1, n\r\n if (DABS(A(i, i)) < SUM(DABS(A(i, :i-1))) + SUM(DABS(A(i, i+1:)))) then\r\n ok = .FALSE.\r\n return\r\n end if\r\n end do\r\n ok = .TRUE.\r\n return\r\n end function\r\n\r\n recursive function positive_definite(A, n) result (ok)\r\n! Checks wether a matrix is positive definite\r\n! according to Sylvester's criterion.\r\n implicit none\r\n\r\n integer :: n\r\n double precision A(n, n)\r\n\r\n logical :: ok\r\n\r\n if (n == 1) then\r\n ok = (A(1, 1) > 0)\r\n return\r\n else\r\n ok = positive_definite(A(:n-1, :n-1), n-1) .AND. (det(A, n) > 0)\r\n return\r\n end if\r\n end function\r\n\r\n function symmetrical(A, n) result (ok)\r\n! Check if the Matrix is symmetrical\r\n integer :: n\r\n\r\n double precision :: A(n, n)\r\n\r\n integer :: i, j\r\n logical :: ok\r\n \r\n do i = 1, n\r\n do j = 1, i-1\r\n if (A(i, j) /= A(j, i)) then\r\n ok = .FALSE.\r\n return\r\n end if\r\n end do\r\n end do\r\n ok = .TRUE.\r\n return\r\n end function\r\n\r\n subroutine swap_rows(A, i, j, n)\r\n implicit none\r\n\r\n integer :: n\r\n integer :: i, j\r\n double precision A(n, n)\r\n double precision temp(n)\r\n\r\n temp(:) = A(i, :)\r\n A(i, :) = A(j, :)\r\n A(j, :) = temp(:)\r\n end subroutine\r\n\r\n function outer_product(x, y, n) result (A)\r\n implicit none\r\n integer :: n\r\n double precision, dimension(n), intent(in) :: x, y\r\n double precision, dimension(n, n) :: A\r\n integer :: i, j\r\n do i=1,n\r\n do j=1,n\r\n A(i, j) = x(i) * y(j)\r\n end do\r\n end do\r\n return\r\n end function\r\n\r\n! ================= Matrix Method ====================\r\n function inv(A, n, ok) result (Ainv)\r\n integer :: n\r\n double precision :: A(n, n), Ainv(n, n)\r\n double precision :: work(n)\r\n integer :: ipiv(n) ! pivot indices\r\n integer :: info\r\n\r\n logical :: ok\r\n \r\n ! External procedures defined in LAPACK\r\n external DGETRF\r\n external DGETRI\r\n \r\n ! Store A in Ainv to prevent it from being overwritten by LAPACK\r\n Ainv(:, :) = A(:, :)\r\n \r\n ! DGETRF computes an LU factorization of a general M-by-N matrix A\r\n ! using partial pivoting with row interchanges.\r\n call DGETRF(n, n, Ainv, n, ipiv, info)\r\n \r\n if (info /= 0) then\r\n ok = .FALSE.\r\n return\r\n end if\r\n \r\n ! DGETRI computes the inverse of a matrix using the LU factorization\r\n ! computed by DGETRF.\r\n call DGETRI(n, Ainv, n, ipiv, work, n, info)\r\n \r\n if (info /= 0) then\r\n ok = .FALSE.\r\n return\r\n end if\r\n\r\n return\r\n end function\r\n\r\n function row_max(A, j, n) result(k)\r\n implicit none\r\n\r\n integer :: n\r\n double precision A(n, n)\r\n \r\n integer :: i, j, k\r\n double precision :: s\r\n\r\n s = 0.0D0\r\n do i = j, n\r\n if (A(i, j) > s) then\r\n s = A(i, j)\r\n k = i\r\n end if\r\n end do \r\n return \r\n end function\r\n\r\n function pivot_matrix(A, n) result (P)\r\n implicit none\r\n\r\n integer :: n\r\n double precision :: A(n, n)\r\n\r\n double precision :: P(n, n)\r\n\r\n integer :: j, k\r\n\r\n P = id_matrix(n)\r\n\r\n do j = 1, n\r\n k = row_max(A, j, n)\r\n if (j /= k) then \r\n call swap_rows(P, j, k, n)\r\n end if\r\n end do\r\n return\r\n end function\r\n\r\n function vector_norm(x, n) result (s)\r\n implicit none\r\n integer :: n\r\n double precision :: x(n)\r\n double precision :: s\r\n s = sqrt(dot_product(x, x))\r\n return\r\n end function\r\n\r\n function NORM(x, n) result (s)\r\n implicit none\r\n integer :: n\r\n double precision :: x(n)\r\n double precision :: s\r\n s = SQRT(DOT_PRODUCT(x, x))\r\n return\r\n end function\r\n\r\n function matrix_norm(A, n) result (s)\r\n! Frobenius norm\r\n implicit none\r\n integer :: n\r\n double precision :: A(n, n)\r\n double precision :: s\r\n\r\n s = DSQRT(SUM(A * A))\r\n return \r\n end function\r\n\r\n function spectral_radius(A, n) result (r)\r\n implicit none\r\n\r\n integer :: n\r\n double precision :: A(n, n), x(n)\r\n double precision :: r, l\r\n logical :: ok \r\n ok = power_method(A, n, x, l)\r\n r = DABS(l) \r\n return\r\n end function\r\n\r\n recursive function det(A, n) result (d)\r\n implicit none\r\n integer :: n\r\n double precision, dimension(n, n) :: A\r\n double precision, dimension(n-1, n-1) :: X\r\n integer :: i\r\n double precision :: d, s\r\n\r\n if (n == 1) then\r\n d = A(1, 1)\r\n return\r\n elseif (n == 2) then\r\n d = A(1, 1) * A(2, 2) - A(1, 2) * A(2, 1)\r\n return\r\n else\r\n d = 0.0D0\r\n s = 1.0D0\r\n do i = 1, n\r\n! Compute submatrix X\r\n X(:, :i-1) = A(2:, :i-1)\r\n X(:, i: ) = A(2:, i+1: )\r\n d = s * det(X, n-1) * A(1, i) + d\r\n s = -s\r\n end do\r\n end if\r\n return\r\n end function\r\n\r\n function LU_det(A, n) result (d)\r\n implicit none\r\n\r\n integer :: n\r\n integer :: i\r\n double precision :: A(n, n), L(n, n), U(n, n)\r\n double precision :: d\r\n\r\n d = 0.0D0\r\n\r\n if (.NOT. LU_decomp(A, L, U, n)) then\r\n call ill_cond()\r\n return\r\n end if\r\n\r\n do i = 1, n\r\n d = d * L(i, i) * U(i, i)\r\n end do\r\n\r\n return\r\n end function\r\n\r\n subroutine LU_matrix(A, L, U, n)\r\n! Splits Matrix in Lower and Upper-Triangular\r\n implicit none\r\n\r\n integer :: n\r\n double precision :: A(n, n), L(n, n), U(n, n)\r\n\r\n integer :: i\r\n\r\n L(:, :) = 0.0D0\r\n U(:, :) = 0.0D0\r\n \r\n do i = 1, n\r\n L(i, i) = 1.0D0\r\n L(i, :i-1) = A(i, :i-1)\r\n U(i, i: ) = A(i, i: )\r\n end do\r\n end subroutine\r\n\r\n! === Matrix Factorization Conditions ===\r\n function Cholesky_cond(A, n) result (ok)\r\n implicit none\r\n integer :: n\r\n double precision :: A(n, n)\r\n logical :: ok\r\n ok = symmetrical(A, n) .AND. positive_definite(A, n)\r\n return\r\n end function\r\n\r\n function PLU_cond(A, n) result (ok)\r\n implicit none\r\n integer :: n\r\n double precision A(n, n)\r\n integer :: i, j\r\n double precision :: s\r\n logical :: ok\r\n do j = 1, n\r\n s = 0.0D0\r\n do i = 1, j\r\n if (A(i, j) > s) then\r\n s = A(i, j)\r\n end if\r\n end do\r\n end do\r\n ok = (s < 0.01D0)\r\n return\r\n end function\r\n\r\n function LU_cond(A, n) result (ok)\r\n implicit none\r\n integer :: n\r\n double precision A(n, n)\r\n logical :: ok\r\n ok = positive_definite(A, n)\r\n return\r\n end function\r\n! _ _____ _____ _______ __ \r\n! | | |_ _|/ ____|__ __|/\\ /_ |\r\n! | | | | | (___ | | / \\ | |\r\n! | | | | \\___ \\ | | / /\\ \\ | |\r\n! | |____ _| |_ ____) | | |/ ____ \\ | |\r\n! |______|_____|_____/ |_/_/ \\_\\ |_|\r\n! ========================================\r\n \r\n! ======= Matrix Factorization Methods ========\r\n function PLU_decomp(A, P, L, U, n) result (ok)\r\n implicit none\r\n integer :: n\r\n double precision :: A(n,n), P(n,n), L(n,n), U(n,n)\r\n logical :: ok\r\n! Permutation Matrix\r\n P = pivot_matrix(A, n)\r\n! Decomposition over Row-Swapped Matrix\r\n ok = LU_decomp(matmul(P, A), L, U, n)\r\n return\r\n end function\r\n \r\n function LU_decomp(A, L, U, n) result (ok)\r\n implicit none\r\n integer :: n\r\n double precision :: A(n, n), L(n, n), U(n,n), M(n, n)\r\n logical :: ok\r\n integer :: i, j, k\r\n! Results Matrix\r\n M(:, :) = A(:, :)\r\n if (.NOT. LU_cond(A, n)) then\r\n call ill_cond()\r\n ok = .FALSE.\r\n return\r\n end if\r\n do k = 1, n-1\r\n do i = k+1, n\r\n M(i, k) = M(i, k) / M(k, k)\r\n end do\r\n do j = k+1, n\r\n do i = k+1, n\r\n M(i, j) = M(i, j) - M(i, k) * M(k, j)\r\n end do\r\n end do\r\n end do\r\n\r\n! Splits M into L & U\r\n call LU_matrix(M, L, U, n)\r\n\r\n ok = .TRUE.\r\n return\r\n\r\n end function\r\n\r\n function Cholesky_decomp(A, L, n) result (ok)\r\n implicit none\r\n\r\n integer :: n\r\n double precision :: A(n, n), L(n, n)\r\n\r\n logical :: ok\r\n\r\n integer :: i, j\r\n\r\n if (.NOT. Cholesky_cond(A, n)) then\r\n call ill_cond()\r\n ok = .FALSE.\r\n return\r\n end if\r\n\r\n do i = 1, n\r\n L(i, i) = sqrt(A(i, i) - sum(L(i, :i-1) * L(i, :i-1)))\r\n do j = 1 + 1, n\r\n L(j, i) = (A(i, j) - sum(L(i, :i-1) * L(j, :i-1))) / L(i, i)\r\n end do\r\n end do\r\n\r\n ok = .TRUE.\r\n return\r\n end function\r\n\r\n function Jacobi_cond(A, n) result (ok)\r\n implicit none\r\n\r\n integer :: n\r\n\r\n double precision :: A(n, n)\r\n\r\n logical :: ok\r\n\r\n if (.NOT. spectral_radius(A, n) < 1.0D0) then\r\n ok = .FALSE.\r\n call ill_cond()\r\n return\r\n else\r\n ok = .TRUE.\r\n return\r\n end if\r\n end function\r\n\r\n function Jacobi(A, x, b, e, n, tol, max_iter) result (ok)\r\n implicit none\r\n \r\n logical :: ok\r\n\r\n integer :: n, i, k, t_max_iter\r\n integer, optional :: max_iter\r\n\r\n double precision :: A(n, n)\r\n double precision :: b(n), x(n), x0(n)\r\n double precision :: e, t_tol\r\n double precision, optional :: tol\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 (.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 x0 = rand_vector(n)\r\n\r\n ok = Jacobi_cond(A, n)\r\n\r\n if (.NOT. ok) then\r\n return\r\n end if\r\n\r\n do k = 1, t_max_iter\r\n do i = 1, n\r\n x(i) = (b(i) - dot_product(A(i, :), x0)) / A(i, i)\r\n end do\r\n x0(:) = x(:)\r\n e = vector_norm(matmul(A, x) - b, n)\r\n if (e < t_tol) then\r\n return\r\n end if\r\n end do\r\n call error('Erro: Esse m\u00e9todo n\u00e3o convergiu.')\r\n ok = .FALSE.\r\n return\r\n end function\r\n\r\n function Gauss_Seidel_cond(A, n) result (ok)\r\n implicit none\r\n\r\n integer :: n\r\n\r\n double precision :: A(n, n)\r\n\r\n logical :: ok\r\n\r\n integer :: i\r\n\r\n do i = 1, n\r\n if (A(i, i) == 0.0D0) then\r\n ok = .FALSE.\r\n call ill_cond()\r\n return\r\n end if\r\n end do\r\n\r\n if (symmetrical(A, n) .AND. positive_definite(A, n)) then\r\n ok = .TRUE.\r\n return\r\n else\r\n call warn('Aviso: Esse m\u00e9todo pode n\u00e3o convergir.')\r\n return\r\n end if\r\n end function\r\n\r\n function Gauss_Seidel(A, x, b, e, n, tol, max_iter) result (ok)\r\n implicit none\r\n logical :: ok\r\n integer :: n, i, j, k, t_max_iter\r\n integer, optional :: max_iter\r\n double precision :: A(n, n)\r\n double precision :: b(n), x(n)\r\n double precision :: e, s, t_tol\r\n double precision, optional :: tol\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 (.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 ok = Gauss_Seidel_cond(A, n)\r\n\r\n if (.NOT. ok) then\r\n return\r\n end if\r\n\r\n do k = 1, t_max_iter\r\n do i = 1, n\r\n s = 0.0D0\r\n do j = 1, n\r\n if (i /= j) then\r\n s = s + A(i, j) * x(j)\r\n end if\r\n end do\r\n x(i) = (b(i) - s) / A(i, i)\r\n end do\r\n e = vector_norm(matmul(A, x) - b, n)\r\n if (e < t_tol) then\r\n return\r\n end if\r\n end do\r\n call error('Erro: Esse m\u00e9todo n\u00e3o convergiu.')\r\n ok = .FALSE.\r\n return\r\n end function\r\n\r\n! Decomposi\u00e7\u00e3o LU e afins\r\n subroutine LU_backsub(L, U, x, y, b, n)\r\n implicit none\r\n integer :: n\r\n double precision :: L(n, n), U(n, n)\r\n double precision :: b(n), x(n), y(n)\r\n integer :: i\r\n! Ly = b (Forward Substitution)\r\n do i = 1, n\r\n y(i) = (b(i) - SUM(L(i, 1:i-1) * y(1:i-1))) / L(i, i)\r\n end do\r\n! Ux = y (Backsubstitution)\r\n do i = n, 1, -1\r\n x(i) = (y(i) - SUM(U(i,i+1:n) * x(i+1:n))) / U(i, i)\r\n end do\r\n end subroutine\r\n\r\n function LU_solve(A, x, y, b, n) result (ok)\r\n implicit none\r\n\r\n integer :: n\r\n\r\n double precision :: A(n, n), L(n, n), U(n, n)\r\n double precision :: b(n), x(n), y(n)\r\n\r\n logical :: ok\r\n\r\n ok = LU_decomp(A, L, U, n)\r\n\r\n if (.NOT. ok) then\r\n return\r\n end if\r\n\r\n call LU_backsub(L, U, x, y, b, n)\r\n\r\n return\r\n end function\r\n\r\n function PLU_solve(A, x, y, b, n) result (ok)\r\n implicit none\r\n\r\n integer :: n\r\n\r\n double precision :: A(n, n), P(n,n), L(n, n), U(n, n)\r\n double precision :: b(n), x(n), y(n)\r\n\r\n logical :: ok\r\n\r\n ok = PLU_decomp(A, P, L, U, n)\r\n\r\n if (.NOT. ok) then\r\n return\r\n end if\r\n\r\n call LU_backsub(L, U, x, y, matmul(P, b), n)\r\n\r\n x(:) = matmul(P, x)\r\n\r\n return\r\n end function\r\n\r\n function Cholesky_solve(A, x, y, b, n) result (ok)\r\n implicit none\r\n\r\n integer :: n\r\n\r\n double precision :: A(n, n), L(n, n), U(n, n)\r\n double precision :: b(n), x(n), y(n)\r\n\r\n logical :: ok\r\n\r\n ok = Cholesky_decomp(A, L, n)\r\n\r\n if (.NOT. ok) then\r\n return\r\n end if\r\n\r\n U = transpose(L)\r\n\r\n call LU_backsub(L, U, x, y, b, n)\r\n\r\n return\r\n end function\r\n\r\n! _ _____ _____ _______ ___ \r\n! | | |_ _|/ ____|__ __|/\\ |__ \\\r\n! | | | | | (___ | | / \\ ) |\r\n! | | | | \\___ \\ | | / /\\ \\ / / \r\n! | |____ _| |_ ____) | | |/ ____ \\ / /_ \r\n! |______|_____|_____/ |_/_/ \\_\\ |____|\r\n! ==========================================\r\n\r\n! ============ Power Method ============\r\n function power_method(A, n, x, l, tol, max_iter) result (ok)\r\n implicit none\r\n logical :: ok\r\n integer :: n, k, t_max_iter\r\n integer, optional :: max_iter\r\n double precision :: A(n, n)\r\n double precision :: x(n)\r\n double precision :: l, ll, t_tol\r\n double precision, optional :: tol\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 (.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! Begin with random normal vector and set 1st component to zero\r\n x(:) = rand_vector(n)\r\n x(1) = 1.0D0\r\n\r\n! Initialize Eigenvalues\r\n l = 0.0D0\r\n\r\n! Checks if error tolerance was reached \r\n do k=1, t_max_iter\r\n ll = l\r\n\r\n x(:) = matmul(A, x) \r\n\r\n! Retrieve Eigenvalue\r\n l = x(1)\r\n\r\n! Retrieve Eigenvector \r\n x(:) = x(:) / l\r\n\r\n if (dabs((l - ll) / l) < t_tol) then\r\n ok = .TRUE.\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 Jacobi_eigen(A, n, L, X, tol, max_iter) result (ok)\r\n implicit none\r\n logical :: ok\r\n integer :: n, i, j, k, u, v, t_max_iter\r\n integer, optional :: max_iter\r\n double precision :: A(n, n), L(n, n), X(n, n), P(n, n)\r\n double precision :: y, z, t_tol\r\n double precision, optional :: tol\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 (.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 X(:, :) = id_matrix(n)\r\n L(:, :) = A(:, :)\r\n\r\n do k=1, t_max_iter\r\n z = 0.0D0\r\n do i = 1, n\r\n do j = 1, i - 1\r\n y = DABS(L(i, j))\r\n\r\n! Found new maximum absolute value \r\n if (y > z) then\r\n u = i\r\n v = j\r\n z = y\r\n end if\r\n end do\r\n end do\r\n\r\n if (z >= t_tol) then\r\n P(:, :) = given_matrix(L, n, u, v)\r\n L(:, :) = matmul(matmul(transpose(P), L), P)\r\n X(:, :) = matmul(X, P)\r\n else\r\n ok = .TRUE.\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! _ _____ _____ _______ _____ \r\n! | | |_ _|/ ____|__ __|/\\ |__ |\r\n! | | | | | (___ | | / \\ ) /\r\n! | | | | \\___ \\ | | / /\\ \\ |_ \\\r\n! | |____ _| |_ ____) | | |/ ____ \\ ___) |\r\n! |______|_____|_____/ |_/_/ \\_\\ |_____/ \r\n! ==========================================\r\n\r\n function least_squares(x, y, s, n) result (ok)\r\n implicit none\r\n integer :: n\r\n\r\n logical :: ok\r\n\r\n double precision :: A(2,2), b(2), s(2), r(2), x(n), y(n)\r\n \r\n A(1, 1) = n\r\n A(1, 2) = SUM(x)\r\n A(2, 1) = SUM(x)\r\n A(2, 2) = dot_product(x, x)\r\n\r\n b(1) = SUM(y)\r\n b(2) = dot_product(x, y)\r\n\r\n ok = Cholesky_solve(A, s, r, b, n)\r\n return\r\n end function\r\n\r\n! ========== Extra Stuff ======== \r\n \r\n function Gauss_solve(A0, x, b0, n) result (ok)\r\n implicit none \r\n integer n\r\n double precision, dimension(n, n), intent(in) :: A0\r\n double precision, dimension(n, n) :: A\r\n double precision, dimension(n), intent(in) :: b0\r\n double precision, dimension(n) :: b, x, s\r\n double precision :: c, pivot, store\r\n integer i, j, k, l\r\n\r\n logical :: ok\r\n \r\n ok = .TRUE.\r\n \r\n A(:, :) = A0(:, :)\r\n b(:) = b0(:)\r\n\r\n do k=1, n-1\r\n do i=k,n\r\n s(i) = 0.0\r\n do j=k,n\r\n s(i) = MAX(s(i), DABS(A(i,j)))\r\n end do\r\n end do\r\n \r\n pivot = DABS(A(k,k) / s(k))\r\n l = k\r\n do j=k+1,n\r\n if(DABS(A(j,k) / s(j)) > pivot) then\r\n pivot = DABS(A(j,k) / s(j))\r\n l = j\r\n end if\r\n end do\r\n \r\n if(pivot == 0.0) then\r\n ok = .FALSE.\r\n return\r\n end if\r\n \r\n if (l /= k) then\r\n do j=k,n\r\n store = A(k,j)\r\n A(k,j) = A(l,j)\r\n A(l,j) = store\r\n end do\r\n store = b(k)\r\n b(k) = b(l)\r\n b(l) = store\r\n end if\r\n \r\n do i=k+1,n\r\n c = A(i,k) / A(k,k)\r\n A(i,k) = 0.0D0\r\n b(i) = b(i)- c*b(k)\r\n do j=k+1,n\r\n A(i,j) = A(i,j) - c * A(k,j)\r\n end do\r\n end do\r\n end do\r\n \r\n x(n) = b(n) / A(n,n)\r\n do i=n-1,1,-1\r\n c = 0.0D0\r\n do j=i+1,n\r\n c = c + A(i,j) * x(j)\r\n end do \r\n x(i) = (b(i)- c) / A(i,i)\r\n end do\r\n \r\n return\r\n end function\r\n \r\n function solve(A, b, n, kind) result (x)\r\n implicit none\r\n integer :: n\r\n double precision, dimension(n), intent(in) :: b\r\n double precision, dimension(n) :: x, y\r\n double precision, dimension(n, n), intent(in) :: A\r\n character(len=*), optional :: kind\r\n character(len=:), allocatable :: t_kind\r\n\r\n logical :: ok = .TRUE.\r\n\r\n if (.NOT. PRESENT(kind)) then\r\n call debug(\"Indeed, not present.\")\r\n t_kind = \"gauss\"\r\n else\r\n t_kind = kind\r\n end if\r\n\r\n call debug(\"Now it is: \"//t_kind)\r\n if (t_kind == \"LU\") then\r\n ok = LU_solve(A, x, y, b, n)\r\n else if (t_kind == \"PLU\") then\r\n ok = PLU_solve(A, x, y, b, n)\r\n else if (t_kind ==\"cholesky\") then\r\n ok = Cholesky_solve(A, x, y, b, n)\r\n else if (t_kind ==\"gauss\") then\r\n ok = Gauss_solve(A, x, b, n)\r\n else\r\n ok = .FALSE.\r\n end if\r\n\r\n call debug(\":: Solved via `\"//t_kind//\"` ::\")\r\n\r\n if (.NOT. ok) then\r\n call error(\"Failed to solve system Ax = b.\")\r\n end if\r\n\r\n return\r\n end function\r\n \r\n end module Matrix\r\n", "meta": {"hexsha": "7e6902d9caa9c6a2b974a2efafb4eddc1fb3ec13", "size": 31168, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/matrixlib.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/matrixlib.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/matrixlib.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": 29.1289719626, "max_line_length": 88, "alphanum_fraction": 0.3604658624, "num_tokens": 7586, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.6795213475362867}} {"text": "!=======================================================================\n! Forlab\n!-----------------------------------------------------------------------\n! Forlab aims to provide a package of functions for scientific\n! computing in Fortran.\n!\n! Created by\n! Keurfon Luu \n! MINES ParisTech - Centre de G\u00e9osciences\n! PSL - Research University\n!\n! Notes\n!-----------------------------------------------------------------------\n! When changing precision (IPRE and/or RPRE), the whole program needs to\n! be recompiled.\n!=======================================================================\n\nmodule forlab\n\n#ifdef do_mpi\n use mpi\n#endif\n\n implicit none\n\n!=======================================================================\n! Parameters\n!=======================================================================\n\n integer, public, parameter :: IPRE = 4\n integer, public, parameter :: RPRE = 8\n integer, public, parameter :: CLEN = 512\n real(kind = 8), public, parameter :: pi = 3.141592653589793238460d0\n real(kind = 8), public, save :: tic_time\n\n!=======================================================================\n! Functions\n!=======================================================================\n\n private\n public :: File, acosd, asind, atand, argmax, argmin, argsort, arange, &\n angle, bsplrep1, bsplrep2, bspline1, bspline2, chol, cosd, countlines, &\n cov, cumsum, chi2cdf, chi2pdf, chi2inv, chi2rand, check_directory, &\n det, diag, disp, deg2utm, datenum, datevec, datestr, deboor, diff, &\n eye, eig, find, flip, fliplr, flipud, fminbnd, gammainc, horzcat, &\n hann, interp1, interp2, interp3, inv, ismember, isoutlier, issquare, &\n isleap, issymmetric, kurtosis, k2test, kde, loadtxt, loadbin, linspace, &\n mean, median, mad, meshgrid, nextpow2, norm, normpdf, num2str, ones, &\n pascal, prctile, progress_bar, progress_perc, rng, randu, randn, &\n randi, randperm, repmat, rms, savetxt, savebin, sind, sort, solve, &\n svd, svdsolve, std, spline1, spline2, skewness, signum, sinc, &\n split_argument, tand, tic, toc, trace, tril, triu, utm2deg, vertcat, &\n var, zeros, dbindex, gmm, kmeans, mbkmeans, silhouette\n#ifdef do_mpi\n public :: mpi_rpre\n#endif\n\n!=======================================================================\n! Object File\n!=======================================================================\n\n type File\n integer(kind = IPRE) :: unit\n character(len = CLEN) :: filename\n contains\n procedure, private :: open1, open2, countlines1, file_exist\n procedure, public :: close\n generic, public :: open => open1, open2\n generic, public :: countlines => countlines1\n generic, public :: exist => file_exist\n end type File\n\n!=======================================================================\n! Abstract function\n!=======================================================================\n\n abstract interface\n real(kind = RPRE) function func1d(x)\n import :: RPRE\n real(kind = RPRE), intent(in) :: x\n end function func1d\n end interface\n\n!=======================================================================\n! Polymorphic functions and subroutines\n!=======================================================================\n\n !---------------------------------------------------------------------\n ! Function acosd\n !---------------------------------------------------------------------\n interface acosd\n module procedure acosd0, acosd1, acosd2, acosd3\n end interface acosd\n\n !---------------------------------------------------------------------\n ! Function angle\n !---------------------------------------------------------------------\n interface angle\n module procedure angle0, angle1\n end interface angle\n\n !---------------------------------------------------------------------\n ! Function argmax\n !---------------------------------------------------------------------\n interface argmax\n module procedure argmax1, argmax2, argmax3\n end interface argmax\n\n !---------------------------------------------------------------------\n ! Function argmin\n !---------------------------------------------------------------------\n interface argmin\n module procedure argmin1, argmin2, argmin3\n end interface argmin\n\n !---------------------------------------------------------------------\n ! Function asind\n !---------------------------------------------------------------------\n interface asind\n module procedure asind0, asind1, asind2, asind3\n end interface asind\n\n !---------------------------------------------------------------------\n ! Function atand\n !---------------------------------------------------------------------\n interface atand\n module procedure atand0, atand1, atand2, atand3\n end interface atand\n\n !---------------------------------------------------------------------\n ! Function bspline1\n !---------------------------------------------------------------------\n interface bspline1\n module procedure bspline1_1\n end interface bspline1\n\n !---------------------------------------------------------------------\n ! Function bspline2\n !---------------------------------------------------------------------\n interface bspline2\n module procedure bspline2_2\n end interface bspline2\n\n !---------------------------------------------------------------------\n ! Function chi2cdf\n !---------------------------------------------------------------------\n interface chi2cdf\n module procedure chi2cdf0, chi2cdf1_0, chi2cdf1_1\n end interface chi2cdf\n\n !---------------------------------------------------------------------\n ! Function chi2inv\n !---------------------------------------------------------------------\n interface chi2inv\n module procedure chi2inv0, chi2inv1_0, chi2inv1_1\n end interface chi2inv\n\n !---------------------------------------------------------------------\n ! Function chi2pdf\n !---------------------------------------------------------------------\n interface chi2pdf\n module procedure chi2pdf0, chi2pdf1_0, chi2pdf1_1\n end interface chi2pdf\n\n !---------------------------------------------------------------------\n ! Function chi2rand\n !---------------------------------------------------------------------\n interface chi2rand\n module procedure chi2rand0, chi2rand1\n end interface chi2rand\n\n !---------------------------------------------------------------------\n ! Function cosd\n !---------------------------------------------------------------------\n interface cosd\n module procedure cosd0, cosd1, cosd2, cosd3\n end interface cosd\n\n !---------------------------------------------------------------------\n ! Function countlines\n !---------------------------------------------------------------------\n interface countlines\n module procedure countlines2\n end interface countlines\n\n !---------------------------------------------------------------------\n ! Function cov\n !---------------------------------------------------------------------\n interface cov\n module procedure cov1_1, cov1_2, cov2_1, cov2_2\n end interface cov\n\n !---------------------------------------------------------------------\n ! Function cumsum\n !---------------------------------------------------------------------\n interface cumsum\n module procedure cumsum1, cumsum2\n end interface cumsum\n\n !---------------------------------------------------------------------\n ! Function datenum\n !---------------------------------------------------------------------\n interface datenum\n module procedure datenum0\n end interface datenum\n\n !---------------------------------------------------------------------\n ! Function datestr\n !---------------------------------------------------------------------\n interface datestr\n module procedure datestr0_0\n end interface datestr\n\n !---------------------------------------------------------------------\n ! Function datevec\n !---------------------------------------------------------------------\n interface datevec\n module procedure datevec0\n end interface datevec\n\n !---------------------------------------------------------------------\n ! Function dbindex\n !---------------------------------------------------------------------\n interface dbindex\n module procedure dbindex1, dbindex2\n end interface dbindex\n\n !---------------------------------------------------------------------\n ! Function deg2utm\n !---------------------------------------------------------------------\n interface deg2utm\n module procedure deg2utm0, deg2utm1\n end interface deg2utm\n\n !---------------------------------------------------------------------\n ! Function diag\n !---------------------------------------------------------------------\n interface diag\n module procedure diag1, diag2\n end interface diag\n\n !---------------------------------------------------------------------\n ! Function diff\n !---------------------------------------------------------------------\n interface diff\n module procedure diff1, diff2\n end interface diff\n\n !---------------------------------------------------------------------\n ! Subroutine disp\n !---------------------------------------------------------------------\n interface disp\n module procedure disp_i0, disp_r0, disp_c0, disp_i1, disp_r1, &\n disp_c1, disp_i2, disp_r2, disp_i3, disp_r3\n end interface disp\n\n !---------------------------------------------------------------------\n ! Function File\n !---------------------------------------------------------------------\n interface File\n module procedure init_File\n end interface File\n\n !---------------------------------------------------------------------\n ! Function find\n !---------------------------------------------------------------------\n interface find\n module procedure find1, find2, find3\n end interface find\n\n !---------------------------------------------------------------------\n ! Function flip\n !---------------------------------------------------------------------\n interface flip\n module procedure flip_i1, flip_r1, flip_i2, flip_r2, flip_i3, &\n flip_r3\n end interface flip\n\n !---------------------------------------------------------------------\n ! Function flipud\n !---------------------------------------------------------------------\n interface flipud\n module procedure flipud_i1, flipud_r1, flipud_i2, flipud_r2\n end interface flipud\n\n !---------------------------------------------------------------------\n ! Function fliplr\n !---------------------------------------------------------------------\n interface fliplr\n module procedure fliplr_i1, fliplr_r1, fliplr_i2, fliplr_r2\n end interface fliplr\n\n !---------------------------------------------------------------------\n ! Function gammainc\n !---------------------------------------------------------------------\n interface gammainc\n module procedure gammainc0, gammainc1_0\n end interface gammainc\n\n !---------------------------------------------------------------------\n ! Function gmm\n !---------------------------------------------------------------------\n interface gmm\n module procedure gmm1, gmm2\n end interface gmm\n\n !---------------------------------------------------------------------\n ! Function horzcat\n !---------------------------------------------------------------------\n interface horzcat\n module procedure horzcat_i1, horzcat_r1, horzcat_i2, horzcat_r2, horzcat_i12, &\n horzcat_r12, horzcat_i21, horzcat_r21\n end interface horzcat\n\n !---------------------------------------------------------------------\n ! Function interp1\n !---------------------------------------------------------------------\n interface interp1\n module procedure interp1_0, interp1_1\n end interface interp1\n\n !---------------------------------------------------------------------\n ! Function interp2\n !---------------------------------------------------------------------\n interface interp2\n module procedure interp2_0, interp2_1, interp2_2\n end interface interp2\n\n !---------------------------------------------------------------------\n ! Function interp3\n !---------------------------------------------------------------------\n interface interp3\n module procedure interp3_0, interp3_1\n end interface interp3\n\n !---------------------------------------------------------------------\n ! Function ismember\n !---------------------------------------------------------------------\n interface ismember\n module procedure ismember_i0i1, ismember_i0r1, ismember_i0i2, &\n ismember_i0r2, ismember_i0i3, ismember_i0r3, ismember_r0i1, &\n ismember_r0r1, ismember_r0i2, ismember_r0r2, ismember_r0i3, &\n ismember_r0r3\n end interface ismember\n\n !---------------------------------------------------------------------\n ! Function kde\n !---------------------------------------------------------------------\n interface kde\n module procedure kde1, kde2\n end interface kde\n\n !---------------------------------------------------------------------\n ! Function kmeans\n !---------------------------------------------------------------------\n interface kmeans\n module procedure kmeans1, kmeans2\n end interface kmeans\n\n !---------------------------------------------------------------------\n ! Function kurtosis\n !---------------------------------------------------------------------\n interface kurtosis\n module procedure kurtosis1, kurtosis2\n end interface kurtosis\n\n !---------------------------------------------------------------------\n ! Function linspace\n !---------------------------------------------------------------------\n interface linspace\n module procedure linspace_r8r8, linspace_r4r4, linspace_i4i4, &\n linspace_r8i4, linspace_r4i4, linspace_i4r8, linspace_i4r4\n end interface linspace\n\n !---------------------------------------------------------------------\n ! Function loadbin\n !---------------------------------------------------------------------\n interface loadbin\n module procedure loadbin0, loadbin1, loadbin2, loadbin3\n end interface loadbin\n\n !---------------------------------------------------------------------\n ! Function loadtxt\n !---------------------------------------------------------------------\n interface loadtxt\n module procedure loadtxt1, loadtxt2\n end interface loadtxt\n\n !---------------------------------------------------------------------\n ! Function log2\n !---------------------------------------------------------------------\n interface log2\n module procedure log2_i0, log2_r0, log2_i1, log2_r1\n end interface log2\n\n !---------------------------------------------------------------------\n ! Function mad\n !---------------------------------------------------------------------\n interface mad\n module procedure mad1, mad2\n end interface mad\n\n !---------------------------------------------------------------------\n ! Function mbkmeans\n !---------------------------------------------------------------------\n interface mbkmeans\n module procedure mbkmeans1, mbkmeans2\n end interface mbkmeans\n\n !---------------------------------------------------------------------\n ! Function median\n !---------------------------------------------------------------------\n interface median\n module procedure median1, median2\n end interface median\n\n !---------------------------------------------------------------------\n ! Function mean\n !---------------------------------------------------------------------\n interface mean\n module procedure mean1, mean2\n end interface mean\n\n !---------------------------------------------------------------------\n ! Subroutine meshgrid\n !---------------------------------------------------------------------\n interface meshgrid\n module procedure meshgrid2\n end interface meshgrid\n\n !---------------------------------------------------------------------\n ! Function nextpow2\n !---------------------------------------------------------------------\n interface nextpow2\n module procedure nextpow2_0, nextpow2_1\n end interface nextpow2\n\n !---------------------------------------------------------------------\n ! Function norm\n !---------------------------------------------------------------------\n interface norm\n module procedure norm1, norm2\n end interface norm\n\n !---------------------------------------------------------------------\n ! Function normpdf\n !---------------------------------------------------------------------\n interface normpdf\n module procedure normpdf0, normpdf1, normpdf2\n end interface normpdf\n\n !---------------------------------------------------------------------\n ! Function num2str\n !---------------------------------------------------------------------\n interface num2str\n module procedure num2str_i4, num2str_i8, num2str_r4, num2str_r8\n end interface num2str\n\n !---------------------------------------------------------------------\n ! Function ones\n !---------------------------------------------------------------------\n interface ones\n module procedure ones1, ones2, ones3\n end interface ones\n\n !---------------------------------------------------------------------\n ! Function prctile\n !---------------------------------------------------------------------\n interface prctile\n module procedure prctile0, prctile1\n end interface prctile\n\n !---------------------------------------------------------------------\n ! Function randi\n !---------------------------------------------------------------------\n interface randi\n module procedure randi0_0, randi0_1, randi1_0, randi1_1, randi2_0, &\n randi2_1, randi3_0, randi3_1\n end interface randi\n\n !---------------------------------------------------------------------\n ! Function randu\n !---------------------------------------------------------------------\n interface randu\n module procedure randu0, randu1, randu2, randu3\n end interface randu\n\n !---------------------------------------------------------------------\n ! Function randn\n !---------------------------------------------------------------------\n interface randn\n module procedure randn0, randn1, randn2, randn3\n end interface randn\n\n !---------------------------------------------------------------------\n ! Function repmat\n !---------------------------------------------------------------------\n interface repmat\n module procedure repmat1, repmat2\n end interface repmat\n\n !---------------------------------------------------------------------\n ! Function rms\n !---------------------------------------------------------------------\n interface rms\n module procedure rms1, rms2\n end interface rms\n\n !---------------------------------------------------------------------\n ! Subroutine savebin\n !---------------------------------------------------------------------\n interface savebin\n module procedure savebin1_r4, savebin1_r8, savebin2_r4, savebin2_r8, &\n savebin3_r4, savebin3_r8\n end interface savebin\n\n !---------------------------------------------------------------------\n ! Subroutine savetxt\n !---------------------------------------------------------------------\n interface savetxt\n module procedure savetxt1_i4, savetxt1_r4, savetxt1_i8, savetxt1_r8, &\n savetxt2_i4, savetxt2_r4, savetxt2_i8, savetxt2_r8\n end interface savetxt\n\n !---------------------------------------------------------------------\n ! Function signum\n !---------------------------------------------------------------------\n interface signum\n module procedure signum0, signum1, signum2\n end interface signum\n\n !---------------------------------------------------------------------\n ! Function sinc\n !---------------------------------------------------------------------\n interface sinc\n module procedure sinc0, sinc1\n end interface sinc\n\n !---------------------------------------------------------------------\n ! Function silhouette\n !---------------------------------------------------------------------\n interface silhouette\n module procedure silhouette1, silhouette2\n end interface silhouette\n\n !---------------------------------------------------------------------\n ! Function sind\n !---------------------------------------------------------------------\n interface sind\n module procedure sind0, sind1, sind2, sind3\n end interface sind\n\n !---------------------------------------------------------------------\n ! Function skewness\n !---------------------------------------------------------------------\n interface skewness\n module procedure skewness1, skewness2\n end interface skewness\n\n !---------------------------------------------------------------------\n ! Function spline1\n !---------------------------------------------------------------------\n interface spline1\n module procedure spline1_0, spline1_1\n end interface spline1\n\n !---------------------------------------------------------------------\n ! Function spline2\n !---------------------------------------------------------------------\n interface spline2\n module procedure spline2_1, spline2_2\n end interface spline2\n\n !---------------------------------------------------------------------\n ! Function std\n !---------------------------------------------------------------------\n interface std\n module procedure std1, std2\n end interface std\n\n !---------------------------------------------------------------------\n ! Function tand\n !---------------------------------------------------------------------\n interface tand\n module procedure tand0, tand1, tand2, tand3\n end interface tand\n\n !---------------------------------------------------------------------\n ! Function tril\n !---------------------------------------------------------------------\n interface tril\n module procedure tril_i, tril_r, tril_c\n end interface tril\n\n !---------------------------------------------------------------------\n ! Function triu\n !---------------------------------------------------------------------\n interface triu\n module procedure triu_i, triu_r, triu_c\n end interface triu\n\n !---------------------------------------------------------------------\n ! Function utm2deg\n !---------------------------------------------------------------------\n interface utm2deg\n module procedure utm2deg0, utm2deg1\n end interface utm2deg\n\n !---------------------------------------------------------------------\n ! Function var\n !---------------------------------------------------------------------\n interface var\n module procedure var1, var2\n end interface var\n\n !---------------------------------------------------------------------\n ! Function vertcat\n !---------------------------------------------------------------------\n interface vertcat\n module procedure vertcat_r1, vertcat_r2, vertcat_c2, vertcat_r12, &\n vertcat_r21\n end interface vertcat\n\n !---------------------------------------------------------------------\n ! Function zeros\n !---------------------------------------------------------------------\n interface zeros\n module procedure zeros1, zeros2, zeros3\n end interface zeros\n\n!=======================================================================\n! End of declaration of interfaces\n!=======================================================================\n\ncontains\n\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 real(kind = RPRE) function acosd0(x)\n real(kind = RPRE), intent(in) :: x\n\n acosd0 = acos(x)*180.0d0/pi\n return\n end function acosd0\n\n function acosd1(x)\n real(kind = RPRE), dimension(:), allocatable :: acosd1\n real(kind = RPRE), dimension(:), intent(in) :: x\n\n acosd1 = acos(x)*180.0d0/pi\n return\n end function acosd1\n\n function acosd2(A)\n real(kind = RPRE), dimension(:,:), allocatable :: acosd2\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n\n acosd2 = acos(A)*180.0d0/pi\n return\n end function acosd2\n\n function acosd3(X)\n real(kind = RPRE), dimension(:,:,:), allocatable :: acosd3\n real(kind = RPRE), dimension(:,:,:), intent(in) :: X\n\n acosd3 = acos(X)*180.0d0/pi\n return\n end function acosd3\n\n!=======================================================================\n! angle\n!-----------------------------------------------------------------------\n! angle compute the phase angle.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! p = angle(z)\n! P = angle(Z)\n!\n! Description\n!-----------------------------------------------------------------------\n! p = angle(z) returns the phase angle in radians of the complex\n! number z.\n!\n! P = angle(Z) returns the phase angles in radians of each complex\n! numbers in vector Z.\n!=======================================================================\n\n real(kind = RPRE) function angle0(z)\n complex(kind = RPRE), intent(in) :: z\n\n angle0 = imag(log(z))\n return\n end function angle0\n\n function angle1(Z)\n real(kind = RPRE), dimension(:), allocatable :: angle1\n complex(kind = RPRE), dimension(:), intent(in) :: Z\n integer(kind = IPRE) :: i, n\n\n n = size(Z)\n angle1 = zeros(n)\n do i = 1, n\n angle1(i) = angle0(Z(i))\n end do\n return\n end function angle1\n\n!=======================================================================\n! arange\n!-----------------------------------------------------------------------\n! arange returns evenly spaced vector.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! x = arange(first, last)\n!\n! Description\n!-----------------------------------------------------------------------\n! x = arange(first, last) returns an evenly spaced integer vector\n! starting from first and ending at last.\n!\n! Examples\n!-----------------------------------------------------------------------\n! x = arange(1, 9)\n! 1 2 3 4 5 6 7 8 9\n!=======================================================================\n\n function arange(first, last)\n integer(kind = IPRE), dimension(:), allocatable :: arange\n integer(kind = IPRE), intent(in) :: first, last\n integer(kind = IPRE) :: i\n\n arange = [ ( i, i = first, last ) ]\n return\n end function arange\n\n!=======================================================================\n! argmax\n!-----------------------------------------------------------------------\n! argmax computes the indices of the maximum value of an array.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! y = argmax(x)\n! y = argmax(A)\n! y = argmax(X)\n!\n! Description\n!-----------------------------------------------------------------------\n! y = argmax(x) returns the index of the maximum value of the vector x.\n!\n! y = argmax(A) returns a 2-elements vector with the indices of the\n! maximum value of the matrix A.\n!\n! y = argmax(X) returns a 3-elements vector with the indices of the\n! maximum value of the 3-dimensional matrix X.\n!\n! Notes\n!-----------------------------------------------------------------------\n! argmax ignores NaN values.\n!=======================================================================\n\n integer(kind = IPRE) function argmax1(x)\n real(kind = RPRE), dimension(:), intent(in) :: x\n\n argmax1 = maxloc(x, 1, .not. isnan(x))\n return\n end function argmax1\n\n function argmax2(A)\n integer(kind = IPRE) :: argmax2(2)\n real(kind = IPRE), dimension(:,:), intent(in) :: A\n\n argmax2 = maxloc(A, .not. isnan(A))\n return\n end function argmax2\n\n function argmax3(X)\n integer(kind = IPRE) :: argmax3(3)\n real(kind = IPRE), dimension(:,:,:), intent(in) :: X\n\n argmax3 = maxloc(X, .not. isnan(X))\n return\n end function argmax3\n\n!=======================================================================\n! argmin\n!-----------------------------------------------------------------------\n! argmin computes the indices of the minimum value of an array.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! y = argmin(x)\n! y = argmin(A)\n! y = argmin(X)\n!\n! Description\n!-----------------------------------------------------------------------\n! y = argmin(x) returns the index of the minimum value of the vector x.\n!\n! y = argmin(A) returns a 2-elements vector with the indices of the\n! minimum value of the matrix A.\n!\n! y = argmin(X) returns a 3-elements vector with the indices of the\n! minimum value of the 3-dimensional matrix X.\n!\n! Notes\n!-----------------------------------------------------------------------\n! argmin ignores NaN values.\n!=======================================================================\n\n integer(kind = IPRE) function argmin1(x)\n real(kind = RPRE), dimension(:), intent(in) :: x\n\n argmin1 = minloc(x, 1, .not. isnan(x))\n return\n end function argmin1\n\n function argmin2(A)\n integer(kind = IPRE) :: argmin2(2)\n real(kind = IPRE), dimension(:,:), intent(in) :: A\n\n argmin2 = minloc(A, .not. isnan(A))\n return\n end function argmin2\n\n function argmin3(X)\n integer(kind = IPRE) :: argmin3(3)\n real(kind = IPRE), dimension(:,:,:), intent(in) :: X\n\n argmin3 = minloc(X, .not. isnan(X))\n return\n end function argmin3\n\n!=======================================================================\n! argsort\n!-----------------------------------------------------------------------\n! argsort generates the indices that would sort an array.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! y = argsort(x)\n! y = argsort(x, 1)\n! y = argsort(x, 2)\n!\n! Description\n!-----------------------------------------------------------------------\n! y = argsort(x) returns the indices that would sort an array in\n! ascending order.\n!\n! y = argsort(x, 1) (see y = argsort(x)).\n!\n! y = argsort(x, 2) returns the indices that would sort an array in\n! descending order.\n!\n! Notes\n!-----------------------------------------------------------------------\n! x(argsort(x), order) returns the same result as sort(x, order).\n!=======================================================================\n\n function argsort(x, order)\n integer(kind = IPRE), dimension(:), allocatable :: argsort\n real(kind = RPRE), dimension(:), intent(in) :: x\n integer(kind = IPRE), intent(in), optional :: order\n integer(kind = IPRE) :: i, n\n real(kind = RPRE), dimension(:), allocatable :: xsort\n\n n = size(x)\n xsort = x\n argsort = [ ( i, i = 1, n ) ]\n if ((.not. present(order)) .or. (order .eq. 1)) then\n call quickargsort(xsort, argsort, n, 1)\n elseif (order .eq. 2) then\n call quickargsort(xsort, argsort, n, 2)\n end if\n return\n\n contains\n\n !-------------------------------------------------------------------\n ! quickargsort\n !-------------------------------------------------------------------\n recursive subroutine quickargsort(x, idx, n, order)\n real(kind = RPRE), dimension(n), intent(inout) :: x\n integer(kind = IPRE), dimension(n), intent(inout) :: idx\n integer(kind = IPRE), intent(in) :: n, order\n integer(kind = IPRE) :: left, right, marker\n real(kind = RPRE) :: pivot, tmp\n\n if (n .gt. 1) then\n left = 0\n right = n + 1\n pivot = x(randi(n))\n\n select case(order)\n case(1)\n do while ( left .lt. right )\n left = left + 1\n right = right - 1\n do while ( x(left) .lt. pivot )\n left = left + 1\n end do\n do while ( x(right) .gt. pivot )\n right = right - 1\n end do\n if ( left .lt. right ) then\n tmp = x(left)\n x(left) = x(right)\n x(right) = tmp\n tmp = idx(left)\n idx(left) = idx(right)\n idx(right) = tmp\n end if\n end do\n case(2)\n do while ( left .lt. right )\n left = left + 1\n right = right - 1\n do while ( x(left) .gt. pivot )\n left = left + 1\n end do\n do while ( x(right) .lt. pivot )\n right = right - 1\n end do\n if ( left .lt. right ) then\n tmp = x(left)\n x(left) = x(right)\n x(right) = tmp\n tmp = idx(left)\n idx(left) = idx(right)\n idx(right) = tmp\n end if\n end do\n end select\n\n if ( left .eq. right ) then\n marker = left + 1\n else\n marker = left\n end if\n\n call quickargsort(x(:marker-1), idx(:marker-1), marker-1, order)\n call quickargsort(x(marker:), idx(marker:), n-marker+1, order)\n end if\n return\n end subroutine quickargsort\n\n end function argsort\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 real(kind = RPRE) function asind0(x)\n real(kind = RPRE), intent(in) :: x\n\n asind0 = asin(x)*180.0d0/pi\n return\n end function asind0\n\n function asind1(x)\n real(kind = RPRE), dimension(:), allocatable :: asind1\n real(kind = RPRE), dimension(:), intent(in) :: x\n\n asind1 = asin(x)*180.0d0/pi\n return\n end function asind1\n\n function asind2(A)\n real(kind = RPRE), dimension(:,:), allocatable :: asind2\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n\n asind2 = asin(A)*180.0d0/pi\n return\n end function asind2\n\n function asind3(X)\n real(kind = RPRE), dimension(:,:,:), allocatable :: asind3\n real(kind = RPRE), dimension(:,:,:), intent(in) :: X\n\n asind3 = asin(X)*180.0d0/pi\n return\n end function asind3\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!=======================================================================\n\n real(kind = RPRE) function atand0(x)\n real(kind = RPRE), intent(in) :: x\n\n atand0 = atan(x)*180.0d0/pi\n return\n end function atand0\n\n function atand1(x)\n real(kind = RPRE), dimension(:), allocatable :: atand1\n real(kind = RPRE), dimension(:), intent(in) :: x\n\n atand1 = atan(x)*180.0d0/pi\n return\n end function atand1\n\n function atand2(A)\n real(kind = RPRE), dimension(:,:), allocatable :: atand2\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n\n atand2 = atan(A)*180.0d0/pi\n return\n end function atand2\n\n function atand3(X)\n real(kind = RPRE), dimension(:,:,:), allocatable :: atand3\n real(kind = RPRE), dimension(:,:,:), intent(in) :: X\n\n atand3 = atan(X)*180.0d0/pi\n return\n end function atand3\n\n!=======================================================================\n! bsplrep1\n!-----------------------------------------------------------------------\n! bsplrep1 computes the B-spline representation C(t) of a set of\n! 1-dimensional control points with a uniform knot vector.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! call bsplrep1(x, y, xq, yq)\n! call bsplrep1(x, y, xq, yq, order)\n! call bsplrep1(x, y, xq, yq, order, n1)\n!\n! Description\n!-----------------------------------------------------------------------\n! call bsplrep1(x, y, xq, yq) returns the B-spline representation C(t)\n! given the control points defined by x and y using a cubic spline\n! (order 4 / degree 3).\n!\n! call bsplrep1(x, y, xq, yq, order) returns the B-spline representation\n! C(t) given the control points defined by x and y and the order.\n!\n! call bsplrep1(x, y, xq, yq, order, n1) returns the n1-points B-spline\n! representation C(t) given the control points defined by x and y, and\n! the order.\n!=======================================================================\n\n subroutine bsplrep1(x, y, xq, yq, order, n1)\n real(kind = RPRE), dimension(:), intent(in) :: x, y\n real(kind = RPRE), dimension(:), allocatable, intent(out) :: xq, yq\n integer(kind = IPRE), intent(in), optional :: order, n1\n integer(kind = IPRE) :: opt_n1, i, iq, j, k, n\n real(kind = RPRE) :: w\n integer(kind = IPRE), dimension(:), allocatable :: x0\n real(kind = RPRE), dimension(:), allocatable :: t, y1\n\n n = size(x)\n k = 4\n opt_n1 = 100\n if (present(order)) k = order\n if (present(n1)) opt_n1 = n1\n\n if (k .gt. n) then\n print *, \"Error: in bsplrep1, order k should be less than the \" &\n // \"number of control points (\" // num2str(k) // \" > \" &\n // num2str(n) // \").\"\n stop\n end if\n\n xq = zeros(opt_n1)\n yq = zeros(opt_n1)\n t = [ zeros(k-1), linspace(0, 1, n-k+2), ones(k-1) ]\n y1 = linspace(0, 1, opt_n1)\n\n do iq = 1, opt_n1\n x0 = find(y1(iq) .ge. t)\n j = min( n, x0(size(x0)) )\n do i = j-k+1, j\n w = deboor(i, k, y1(iq), t)\n xq(iq) = xq(iq) + x(i) * w\n yq(iq) = yq(iq) + y(i) * w\n end do\n end do\n return\n end subroutine bsplrep1\n\n!=======================================================================\n! bsplrep2\n!-----------------------------------------------------------------------\n! bsplrep2 computes the B-spline surface representation S(t) of a set of\n! 2-dimensional control points with uniform knot vectors.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! call bsplrep2(x, y, z, xq, yq, zq)\n! call bsplrep2(x, y, z, xq, yq, zq, order)\n! call bsplrep2(x, y, z, xq, yq, zq, order, n1, n2)\n!\n! Description\n!-----------------------------------------------------------------------\n! call bsplrep2(x, y, z, xq, yq, zq) returns the B-spline surface\n! representation S(t) = (xq, yq, zq) given the control points defined by\n! x, y and z using a cubic spline (order 4 / degree 3).\n!\n! call bsplrep2(x, y, z, xq, yq, zq, order) returns the B-spline surface\n! representation S(t) = (xq, yq, zq) given the control points defined by\n! x, y and z, and the order.\n!\n! call bsplrep2(x, y, z, xq, yq, zq, order, n1, n2) returns the\n! n1-by-b2-points B-spline surface representation S(t) = (xq, yq, zq)\n! given the control points defined by x, y and z, and the order.\n!=======================================================================\n\n subroutine bsplrep2(x, y, z, xq, yq, zq, order, n1, n2)\n real(kind = RPRE), dimension(:), intent(in) :: x, y\n real(kind = RPRE), dimension(:,:), intent(in) :: z\n real(kind = RPRE), dimension(:,:), allocatable, intent(out) :: xq, yq, zq\n integer(kind = IPRE), intent(in), optional :: order, n1, n2\n integer(kind = IPRE) :: opt_n1, opt_n2, i1, i2, iq1, iq2, j1, j2, k, m, n\n real(kind = RPRE) :: w1, w2\n integer(kind = IPRE), dimension(:), allocatable :: x0, y0\n real(kind = RPRE), dimension(:), allocatable :: t1, t2, y1, y2\n\n m = size(x)\n n = size(y)\n k = 4\n opt_n1 = 100\n opt_n2 = 100\n if (present(order)) k = order\n if (present(n1)) opt_n1 = n1\n if (present(n2)) opt_n2 = n2\n\n if (k .gt. min(m, n)) then\n print *, \"Error: in bsplrep2, order k should be less than the \" &\n // \"number of control points (\" // num2str(k) // \" > \" &\n // num2str(min(m, n)) // \").\"\n stop\n end if\n\n xq = zeros(opt_n1, opt_n2)\n yq = zeros(opt_n1, opt_n2)\n zq = zeros(opt_n1, opt_n2)\n t1 = [ zeros(k-1), linspace(0, 1, m-k+2), ones(k-1) ]\n t2 = [ zeros(k-1), linspace(0, 1, n-k+2), ones(k-1) ]\n y1 = linspace(0, 1, opt_n1)\n y2 = linspace(0, 1, opt_n2)\n\n do iq1 = 1, opt_n1\n x0 = find(y1(iq1) .ge. t1)\n j1 = min( m, x0(size(x0)) )\n do iq2 = 1, opt_n2\n y0 = find(y2(iq2) .ge. t2)\n j2 = min( n, y0(size(y0)) )\n do i1 = j1-k+1, j1\n w1 = deboor(i1, k, y1(iq1), t1)\n do i2 = j2-k+1, j2\n w2 = deboor(i2, k, y2(iq2), t2)\n xq(iq1,iq2) = xq(iq1,iq2) + x(i1) * w1 * w2\n yq(iq1,iq2) = yq(iq1,iq2) + y(i2) * w1 * w2\n zq(iq1,iq2) = zq(iq1,iq2) + z(i1,i2) * w1 * w2\n end do\n end do\n end do\n end do\n return\n end subroutine bsplrep2\n\n!=======================================================================\n! bspline1\n!-----------------------------------------------------------------------\n! bspline1 approximates a set of 1-dimensional control points with\n! spline curves in B-spline form.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! yq = bspline1(x, y, xq)\n! yq = bspline1(x, y, xq, order)\n!\n! Description\n!-----------------------------------------------------------------------\n! yq = bspline1(x, y, xq) returns the approximated vector yq at the\n! query points in xq using a cubic spline (order 4 / degree 3).\n!\n! yq = bspline1(x, y, xq, order) returns the approximated vector yq at\n! the query points in xq with spline curves given the order.\n!=======================================================================\n\n function bspline1_1(x, y, xq, order, n1) result(yq)\n real(kind = RPRE), dimension(:), allocatable :: yq\n real(kind = RPRE), dimension(:), intent(in) :: x, y, xq\n integer(kind = IPRE), intent(in), optional :: order, n1\n integer(kind = IPRE) :: k, n, opt_n1\n real(kind = RPRE), dimension(:), allocatable :: bspl_x, bspl_y\n\n n = size(x)\n k = 4\n opt_n1 = 100\n if (present(order)) k = order\n if (present(n1)) opt_n1 = n1\n if (k .gt. n) then\n print *, \"Error: in bspline1, order k should be less than the \" &\n // \"number of control points (\" // num2str(k) // \" > \" &\n // num2str(n) // \").\"\n stop\n end if\n\n call bsplrep1(x, y, bspl_x, bspl_y, k, opt_n1)\n yq = spline1(bspl_x, bspl_y, xq)\n return\n end function bspline1_1\n\n!=======================================================================\n! bspline2\n!-----------------------------------------------------------------------\n! bspline2 approximates a set of 2-dimensional control points with\n! spline curves in B-spline form.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! ZQ = bspline2(x, y, z, XQ, YQ)\n! ZQ = bspline2(x, y, z, XQ, YQ, order)\n!\n! Description\n!-----------------------------------------------------------------------\n! ZQ = bspline2(x, y, Z, XQ, YQ) returns the evaluated matrix ZQ given\n! mesh type grids XQ and YQ using a bicubic spline (degree 3). ZQ is of\n! the same shape as XQ and YQ.\n!\n! ZQ = bspline2(x, y, Z, XQ, YQ, order) returns the evaluated matrix ZQ\n! given mesh type grids XQ and YQ with spline curves given the order. ZQ\n! is of the same shape as XQ and YQ.\n!=======================================================================\n\n function bspline2_2(x, y, z, xq, yq, order) result(zq)\n real(kind = RPRE), dimension(:,:), allocatable :: zq\n real(kind = RPRE), dimension(:), intent(in) :: x, y\n real(kind = RPRE), dimension(:,:), intent(in) :: z, xq, yq\n integer(kind = IPRE), intent(in), optional :: order\n integer(kind = IPRE) :: i, m, n, ny, k\n real(kind = RPRE), dimension(:,:), allocatable :: tmp\n\n m = size(xq, 1)\n n = size(xq, 2)\n ny = size(y)\n k = 4\n if (present(order)) k = order\n\n tmp = zeros(ny, n)\n do i = 1, ny\n tmp(i,:) = bspline1(x, z(i,:), xq(i,:), k)\n end do\n\n zq = zeros(m, n)\n do i = 1, n\n zq(:,i) = bspline1(y, tmp(:,i), yq(:,i), k)\n end do\n\n return\n end function bspline2_2\n\n!=======================================================================\n! check_directory\n!-----------------------------------------------------------------------\n! check_directory appends '/' do a directory name.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! call check_directory(dirname)\n!\n! Description\n!-----------------------------------------------------------------------\n! call check_directory(dirname) returns a directory name dirname that\n! ends with '/'.\n!=======================================================================\n\n subroutine check_directory(dirname)\n character(len = :), allocatable, intent(inout) :: dirname\n integer(kind = IPRE) :: i\n\n i = len_trim(dirname)\n if (dirname(i:i) .ne. \"/\") dirname = trim(dirname) // \"/\"\n return\n end subroutine check_directory\n\n!=======================================================================\n! chi2cdf\n!-----------------------------------------------------------------------\n! chi2cdf computes the chi-square cumulative distribution function.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! p = chi2cdf(x, v)\n!\n! Description\n!-----------------------------------------------------------------------\n! p = chi2cdf(x, v) returns the chi-square cdf at each of the values\n! in x.\n!=======================================================================\n\n real(kind = RPRE) function chi2cdf0(x, v)\n real(kind = RPRE), intent(in) :: x\n integer(kind = IPRE), intent(in) :: v\n\n chi2cdf0 = gammainc(real(x/2., RPRE), real(v/2., RPRE))\n return\n end function chi2cdf0\n\n function chi2cdf1_0(X, v)\n real(kind = RPRE), dimension(:), allocatable :: chi2cdf1_0\n real(kind = RPRE), dimension(:), intent(in) :: X\n integer(kind = IPRE), intent(in) :: v\n integer(kind = IPRE) :: i, n\n\n n = size(X)\n chi2cdf1_0 = zeros(n)\n do i = 1, n\n chi2cdf1_0(i) = chi2cdf0(X(i), v)\n end do\n return\n end function chi2cdf1_0\n\n function chi2cdf1_1(X, V)\n real(kind = RPRE), dimension(:), allocatable :: chi2cdf1_1\n real(kind = RPRE), dimension(:), intent(in) :: X\n integer(kind = IPRE), dimension(:), intent(in) :: V\n integer(kind = IPRE) :: i, n\n\n n = size(X)\n chi2cdf1_1 = zeros(n)\n do i = 1, n\n chi2cdf1_1(i) = chi2cdf0(X(i), V(i))\n end do\n return\n end function chi2cdf1_1\n\n!=======================================================================\n! chi2inv\n!-----------------------------------------------------------------------\n! chi2inv computes the chi-square inverse cumulative distribution\n! function.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! x = chi2inv(p, v)\n!\n! Description\n!-----------------------------------------------------------------------\n! x = chi2inv(p, v) returns the chi-square inverse cdf at each of the\n! values in p.\n!=======================================================================\n\n real(kind = RPRE) function chi2inv0(p, v)\n real(kind = RPRE), intent(in), target :: p\n integer(kind = IPRE), intent(in), target :: v\n real(kind = RPRE) :: a, b\n real(kind = RPRE), pointer, save :: p_ptr\n integer(kind = IPRE), pointer, save :: v_ptr\n\n if ( p .le. 0. .or. p .ge. 1. ) then\n print *, \"Error: in chi2inv0(p, v), p should be between 0 and 1\"\n stop\n end if\n if ( v .le. 0 ) then\n print *, \"Error: in chi2inv0(p, v), v should be greater than 0\"\n stop\n end if\n\n p_ptr => p\n v_ptr => v\n a = 0.\n b = real(v, RPRE)\n do while ( chi2cdf(b, v) .lt. p )\n b = b * b\n end do\n chi2inv0 = fminbnd(chi2func, a, b)\n return\n contains\n\n real(kind = RPRE) function chi2func(x)\n real(kind = RPRE), intent(in) :: x\n chi2func = abs( chi2cdf0(x, v_ptr) - p_ptr )\n return\n end function chi2func\n\n end function chi2inv0\n\n function chi2inv1_0(P, v)\n real(kind = RPRE), dimension(:), allocatable :: chi2inv1_0\n real(kind = RPRE), dimension(:), intent(in) :: P\n integer(kind = IPRE), intent(in) :: v\n integer(kind = IPRE) :: i, n\n\n n = size(P)\n chi2inv1_0 = zeros(n)\n do i = 1, n\n chi2inv1_0(i) = chi2inv0(P(i), v)\n end do\n return\n end function chi2inv1_0\n\n function chi2inv1_1(P, V)\n real(kind = RPRE), dimension(:), allocatable :: chi2inv1_1\n real(kind = RPRE), dimension(:), intent(in) :: P\n integer(kind = IPRE), dimension(:), intent(in) :: V\n integer(kind = IPRE) :: i, n\n\n n = size(P)\n chi2inv1_1 = zeros(n)\n do i = 1, n\n chi2inv1_1(i) = chi2inv0(P(i), V(i))\n end do\n return\n end function chi2inv1_1\n\n!=======================================================================\n! chi2pdf\n!-----------------------------------------------------------------------\n! chi2pdf computes the chi-square probability distribution function.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! y = chi2pdf(x, v)\n!\n! Description\n!-----------------------------------------------------------------------\n! y = chi2pdf(x, v) returns the chi-square pdf at each of the values\n! in x.\n!=======================================================================\n\n real(kind = RPRE) function chi2pdf0(x, v)\n real(kind = RPRE), intent(in) :: x\n integer(kind = IPRE), intent(in) :: v\n real(kind = RPRE) :: v2\n\n if ( x .gt. 0. ) then\n v2 = 0.5 * real(v, RPRE)\n chi2pdf0 = 1. / (2.*gamma(v2)) * (x/2)**(v2-1.) * exp(-x/2.)\n else\n chi2pdf0 = 0.\n end if\n return\n end function chi2pdf0\n\n function chi2pdf1_0(X, v)\n real(kind = RPRE), dimension(:), allocatable :: chi2pdf1_0\n real(kind = RPRE), dimension(:), intent(in) :: X\n integer(kind = IPRE), intent(in) :: v\n integer(kind = IPRE) :: i, n\n\n n = size(X)\n chi2pdf1_0 = zeros(n)\n do i = 1, n\n chi2pdf1_0(i) = chi2pdf0(X(i), v)\n end do\n return\n end function chi2pdf1_0\n\n function chi2pdf1_1(X, V)\n real(kind = RPRE), dimension(:), allocatable :: chi2pdf1_1\n real(kind = RPRE), dimension(:), intent(in) :: X\n integer(kind = IPRE), dimension(:), intent(in) :: V\n integer(kind = IPRE) :: i, n\n\n n = size(X)\n chi2pdf1_1 = zeros(n)\n do i = 1, n\n chi2pdf1_1(i) = chi2pdf0(X(i), V(i))\n end do\n return\n end function chi2pdf1_1\n\n!=======================================================================\n! chi2rand\n!-----------------------------------------------------------------------\n! chi2rand generates chi-square random numbers.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! r = chi2rand(v)\n! r = chi2rand(v, dim1)\n!\n! Description\n!-----------------------------------------------------------------------\n! r = chi2rand(v) returns a chi-square distributed random number with\n! v degrees of freedom.\n!\n! r = chi2rand(v, dim1) returns a dim1 vector of chi-square distributed\n! random number with v degrees of freedom.\n!=======================================================================\n\n real(kind = RPRE) function chi2rand0(v)\n integer(kind = IPRE), intent(in) :: v\n chi2rand0 = sum(randn(v)**2)\n return\n end function chi2rand0\n\n function chi2rand1(v, dim1)\n real(kind = RPRE), dimension(:), allocatable :: chi2rand1\n integer(kind = IPRE), intent(in) :: v, dim1\n chi2rand1 = sum(randn(dim1, v)**2, dim = 2)\n return\n end function chi2rand1\n\n!=======================================================================\n! chol\n!-----------------------------------------------------------------------\n! chol computes Cholesky's decomposition of a symmetric positive\n! definite matrix.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! L = chol(A)\n!\n! Description\n!-----------------------------------------------------------------------\n! L = chol(A) returns a lower triangular matrix L satisfying the\n! equation A = L*Lt.\n!=======================================================================\n\n function chol(A) result(L)\n real(kind = RPRE), dimension(:,:), allocatable :: L\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE) :: i, j, k, n\n real(kind = RPRE) :: sum1, sum2\n real(kind = RPRE), dimension(:), allocatable :: d\n real(kind = RPRE), dimension(:,:), allocatable :: V\n\n call eig(A, V, d)\n if ( all(d .gt. 0.0d0 ) ) then\n n = size(A, 1)\n L = zeros(n, n)\n L(1,1) = sqrt(A(1,1))\n do i = 2, n\n L(i,1) = A(i,1) / L(1,1)\n end do\n\n do i = 2, n\n do k = 1, i\n sum1 = 0.0d0\n sum2 = 0.0d0\n do j = 1, k-1\n if ( i .eq. k ) then\n sum1 = sum1 + ( L(k,j) * L(k,j) )\n L(k,k) = sqrt(A(k,k) - sum1)\n elseif ( i .gt. k ) then\n sum2 = sum2 + ( L(i,j) * L(k,j) )\n L(i,k) = ( 1.0d0 / L(k,k) ) * ( A(i,k) - sum2 )\n else\n L(i,k) = 0.0d0\n end if\n end do\n end do\n end do\n else\n stop \"Error: in chol(A), A should be positive definite.\"\n end if\n return\n end function chol\n\n!=======================================================================\n! close\n!-----------------------------------------------------------------------\n! close closes a File object.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! call ofile%close()\n!\n! Description\n!-----------------------------------------------------------------------\n! call ofile%close() closes the File object ofile.\n!=======================================================================\n\n subroutine close(self)\n class(File) :: self\n\n close(self%unit)\n return\n end subroutine close\n\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\n real(kind = RPRE) function cosd0(x)\n real(kind = RPRE), intent(in) :: x\n\n cosd0 = cos(x*pi/180.0d0)\n return\n end function cosd0\n\n function cosd1(x)\n real(kind = RPRE), dimension(:), allocatable :: cosd1\n real(kind = RPRE), dimension(:), intent(in) :: x\n\n cosd1 = cos(x*pi/180.0d0)\n return\n end function cosd1\n\n function cosd2(A)\n real(kind = RPRE), dimension(:,:), allocatable :: cosd2\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n\n cosd2 = cos(A*pi/180.0d0)\n return\n end function cosd2\n\n function cosd3(X)\n real(kind = RPRE), dimension(:,:,:), allocatable :: cosd3\n real(kind = RPRE), dimension(:,:,:), intent(in) :: X\n\n cosd3 = cos(X*pi/180.0d0)\n return\n end function cosd3\n\n!=======================================================================\n! countlines\n!-----------------------------------------------------------------------\n! countlines counts the number of lines in a txt file.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! n = countlines(filename)\n! n = ofile%countlines()\n!\n! Description\n!-----------------------------------------------------------------------\n! n = countlines(filename) returns the number of lines in the txt file\n! filename.\n!\n! n = ofile%countlines() returns the number of lines in the txt file\n! associated to the File object ofile.\n!=======================================================================\n\n integer(kind = IPRE) function countlines1(self)\n class(File), intent(inout) :: self\n integer(kind = IPRE) :: ierr\n\n countlines1 = 0\n call self%open()\n do\n read(self%unit, *, iostat = ierr)\n if (ierr .lt. 0) exit\n countlines1 = countlines1 + 1\n end do\n call self%close()\n return\n end function countlines1\n\n integer(kind = IPRE) function countlines2(filename)\n character(len = *), intent(in) :: filename\n integer(kind = IPRE) :: ierr\n type(File) :: infile\n\n infile = File(999, trim(filename))\n countlines2 = 0\n call infile%open()\n do\n read(infile%unit, *, iostat = ierr)\n if (ierr .lt. 0) exit\n countlines2 = countlines2 + 1\n end do\n call infile%close()\n return\n end function countlines2\n\n!=======================================================================\n! cov\n!-----------------------------------------------------------------------\n! cov computes the covariance.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! c = cov(x)\n! c = cov(x, w)\n! C = cov(X)\n! C = cov(X, w)\n! C = cov(x, y)\n! C = cov(x, y, w)\n! C = cov(X, Y)\n! C = cov(X, Y, w)\n!\n! Description\n!-----------------------------------------------------------------------\n! c = cov(x) returns the covariance of vector x normalized by the number\n! of observations minus 1.\n!\n! c = cov(x, w) returns the covariance of vector x with the\n! normalization option w.\n! - 0 (default) normalize by N-1,\n! - 1 normalize by N.\n!\n! C = cov(X) returns the the covariance matrix with the corresponding\n! column variances along the diagonal normalized by the number of\n! observations minus 1.\n!\n! C = cov(X, w) returns the the covariance matrix with the corresponding\n! column variances along the diagonal with the normalization option w.\n!\n! C = cov(x, y) returns the 2-by-2 covariance matrix normalized by the\n! number of observations minus 1.\n!\n! C = cov(x, y, w) returns the 2-by-2 covariance matrix with the\n! normalization option w.\n!\n! C = cov(X, Y) returns the the 2-by-2 covariance matrix normalized by\n! the number of observations minus 1. X and Y are treated as column\n! vectors.\n!\n! C = cov(X, Y, w) returns the the 2-by-2 covariance matrix with the\n! normalisation option w. X and Y are treated as column vectors.\n!=======================================================================\n\n real(kind = RPRE) function cov1_1(x, w)\n real(kind = RPRE), dimension(:), intent(in) :: x\n integer(kind = IPRE), intent(in), optional :: w\n integer(kind = IPRE) :: opt_w\n real(kind = RPRE), dimension(:), allocatable :: tmp\n\n opt_w = 0\n if (present(w)) opt_w = w\n\n tmp = x - mean(x)\n select case(opt_w)\n case(0)\n cov1_1 = dot_product(tmp, tmp) / (size(x) - 1)\n case(1)\n cov1_1 = dot_product(tmp, tmp) / size(x)\n end select\n return\n end function cov1_1\n\n function cov1_2(X, w)\n real(kind = RPRE), dimension(:,:), allocatable :: cov1_2\n real(kind = RPRE), dimension(:,:), intent(in) :: X\n integer(kind = IPRE), intent(in), optional :: w\n integer(kind = IPRE) :: opt_w\n real(kind = RPRE), dimension(:,:), allocatable :: tmp\n\n opt_w = 0\n if (present(w)) opt_w = w\n\n tmp = X - repmat(mean(X, 1), size(X, 1), 2)\n select case(opt_w)\n case(0)\n cov1_2 = matmul(transpose(tmp), tmp) / (size(X, 1) - 1)\n case(1)\n cov1_2 = matmul(transpose(tmp), tmp) / size(X, 1)\n end select\n return\n end function cov1_2\n\n function cov2_1(x, y, w)\n real(kind = RPRE), dimension(:,:), allocatable :: cov2_1\n real(kind = RPRE), dimension(:), intent(in) :: x, y\n integer(kind = IPRE), intent(in), optional :: w\n integer(kind = IPRE) :: opt_w\n real(kind = RPRE), dimension(:,:), allocatable :: tmp\n\n opt_w = 0\n if (present(w)) opt_w = w\n\n cov2_1 = cov1_2(horzcat(x, y), opt_w)\n return\n end function cov2_1\n\n function cov2_2(X, Y, w)\n real(kind = RPRE), dimension(:,:), allocatable :: cov2_2\n real(kind = RPRE), dimension(:,:), intent(in) :: X, Y\n integer(kind = IPRE), intent(in), optional :: w\n integer(kind = IPRE) :: opt_w\n\n opt_w = 0\n if (present(w)) opt_w = w\n\n if ( all( shape(X) .eq. shape(Y) ) ) then\n cov2_2 = cov1_2(horzcat([ X ], [ Y ]), opt_w)\n else\n stop \"Error: in cov(X, Y), X and Y should have the same shape.\"\n end if\n return\n end function cov2_2\n\n!=======================================================================\n! cumsum\n!-----------------------------------------------------------------------\n! cumsum computes the cumulative sum of a vector or array.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! y = cumsum(x)\n! B = cumsum(A)\n! B = cumsum(A, dim)\n!\n! Description\n!-----------------------------------------------------------------------\n! y = cumsum(x) returns a vector containing the cumulative sum of the\n! elements of A.\n!\n! B = cumsum(A) returns a matrix containing the cumulative sums for each\n! column of A.\n!\n! B = cumsum(A) returns a matrix containing the cumulative sums for each\n! elements A along the specified dimension dim.\n!=======================================================================\n\n function cumsum1(x)\n real(kind = RPRE), dimension(:), allocatable :: cumsum1\n real(kind = RPRE), dimension(:), intent(in) :: x\n integer(kind = IPRE) :: i, n\n real(kind = RPRE), dimension(:), allocatable :: xsort\n\n n = size(x)\n xsort = sort(x, 1)\n cumsum1 = [ ( sum(xsort(1:i)), i = 1, n ) ]\n return\n end function cumsum1\n\n function cumsum2(A, dim)\n real(kind = RPRE), dimension(:,:), allocatable :: cumsum2\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE), intent(in), optional :: dim\n integer(kind = IPRE) :: i, m, n\n\n m = size(A, 1)\n n = size(A, 2)\n cumsum2 = zeros(m, n)\n if ((.not. present(dim)) .or. (dim .eq. 1)) then\n do i = 1, n\n cumsum2(:,i) = cumsum1(A(:,i))\n end do\n elseif (dim .eq. 2) then\n do i = 1, m\n cumsum2(i,:) = cumsum1(A(i,:))\n end do\n end if\n return\n end function cumsum2\n\n!=======================================================================\n! datenum\n!-----------------------------------------------------------------------\n! datenum converts the datetime values into serial date numbers (since\n! 0000-01-01 00:00:00).\n!\n! Syntax\n!-----------------------------------------------------------------------\n! d = datenum(year, month, day)\n! d = datenum(year, month, day, hour, minute, second)\n! d = datenum(year, month, day, hour, minute, second, microsecond)\n!\n! Description\n!-----------------------------------------------------------------------\n! d = datenum(year, month, day) returns an integer serial date number\n! given by year, month and day.\n!\n! d = datenum(year, month, day, hour, minute, second) returns a floating\n! serial date number given by year, month, day, hour, minute and second.\n!\n! d = datenum(year, month, day, hour, minute, second, microsecond)\n! returns a floating serial date number given by year, month, day, hour,\n! minute, second and microsecond.\n!\n! Examples\n!-----------------------------------------------------------------------\n! d = datenum(2016, 1, 1)\n! 736330.\n!\n! d = datenum(2016, 1, 17, 22, 28, 30, 250000)\n! 736346.93646122678\n!\n! Notes\n!-----------------------------------------------------------------------\n! Use double precision for accuracy.\n!=======================================================================\n\n real(kind = 8) function datenum0(year, month, day, hour, minute, &\n second, microsecond)\n integer(kind = IPRE), intent(in) :: year, month, day\n integer(kind = IPRE), intent(in), optional :: hour, minute, second, microsecond\n integer(kind = IPRE) :: i, days_per_month(12)\n\n if ((month .lt. 1) .and. (month .gt. 12)) then\n print *, \"Error: month should be between 1 and 12 (\" // num2str(month) // \").\"\n end if\n if ((day .lt. 1) .and. (day .gt. 31)) then\n print *, \"Error: day should be between 1 and 31 (\" // num2str(day) // \").\"\n end if\n if ((present(hour)) .and. (hour .lt. 0) .and. (hour .gt. 23)) then\n print *, \"Error: hour should be between 0 and 23 (\" // num2str(hour) // \").\"\n end if\n if ((present(minute)) .and. (minute .lt. 0) .and. (minute .gt. 59)) then\n print *, \"Error: minute should be between 0 and 59 (\" // num2str(minute) // \").\"\n end if\n if ((present(second)) .and. (second .lt. 0) .and. (second .gt. 59)) then\n print *, \"Error: second should be between 0 and 59 (\" // num2str(second) // \").\"\n end if\n if ((present(microsecond)) .and. (microsecond .lt. 0) .and. (microsecond .ge. 1.0d+6)) then\n print *, \"Error: microsecond should be between 0 and 999,999 (\" // num2str(microsecond) // \").\"\n end if\n days_per_month = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ]\n datenum0 = 0\n do i = 0, year-1\n if (isleap(i)) then\n datenum0 = datenum0 + 366\n else\n datenum0 = datenum0 + 365\n end if\n end do\n datenum0 = datenum0 + sum(days_per_month(:month-1))\n if (isleap(year) .and. (month .gt. 2)) datenum0 = datenum0 + 1\n datenum0 = datenum0 + day\n if (present(hour)) datenum0 = datenum0 + real(hour, kind = 8) / 24.0d0\n if (present(minute)) datenum0 = datenum0 + real(minute, kind = 8) / (24.0d0*60.0d0)\n if (present(second)) datenum0 = datenum0 + real(second, kind = 8) / (24.0d0*60.0d0*60.0d0)\n if (present(microsecond)) datenum0 = datenum0 + real(microsecond, kind = 8) / (24.0d0*60.0d0*60.0d0*1.0d+6)\n return\n end function datenum0\n\n!=======================================================================\n! datestr\n!-----------------------------------------------------------------------\n! datestr creates a string of a datetime.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! dstr = datestr(t)\n!\n! Description\n!-----------------------------------------------------------------------\n! dstr = datestr(t) returns a string of the serial date number t.\n!\n! Examples\n!-----------------------------------------------------------------------\n! t = datenum([ 1991, 9, 14, 16, 5, 0, 0])\n! dstr = datestr(t)\n! 14-Sep-1991 16:04:59:999998\n!\n! Notes\n!-----------------------------------------------------------------------\n! Output string may slightly differ from the input date vector in\n! datenum due to accuracy in the calculation of the serial date number.\n!=======================================================================\n\n function datestr0_0(t)\n character(len = :), allocatable :: datestr0_0\n real(kind = 8), intent(in) :: t\n integer(kind = IPRE) :: d(7)\n character(len = CLEN) :: dstr\n character(len = 3) :: months_in_letters(12)\n\n d = datevec(t)\n\n ! Day\n !=====\n if (d(3) .lt. 10) then\n dstr = \"0\" // num2str(d(3)) // \"-\"\n else\n dstr = num2str(d(3)) // \"-\"\n end if\n\n ! Month\n !=======\n months_in_letters = [ \"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\", &\n \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\" ]\n dstr = trim(dstr) // months_in_letters(d(2)) // \"-\"\n\n ! Year\n !======\n dstr = trim(dstr) // num2str(d(1))\n\n if ((d(4) .eq. 0) .and. (d(5) .eq. 0) &\n .and. (d(6) .eq. 0) .and. (d(7) .eq. 0)) then\n datestr0_0 = trim(dstr)\n return\n\n else\n\n ! Hour\n !======\n if (d(4) .lt. 10) then\n dstr = trim(dstr) // \" \" // \"0\" // num2str(d(4)) // \":\"\n else\n dstr = trim(dstr) // \" \" // num2str(d(4)) // \":\"\n end if\n\n ! Minute\n !========\n if (d(5) .lt. 10) then\n dstr = trim(dstr) // \"0\" // num2str(d(5)) // \":\"\n else\n dstr = trim(dstr) // num2str(d(5)) // \":\"\n end if\n\n ! Second\n !========\n if (d(6) .lt. 10) then\n dstr = trim(dstr) // \"0\" // num2str(d(6)) // \".\"\n else\n dstr = trim(dstr) // num2str(d(6)) // \".\"\n end if\n\n ! Microsecond\n !=============\n if (d(7) .lt. 10) then\n dstr = trim(dstr) // \"00000\" // num2str(d(7))\n elseif (d(7) .lt. 100) then\n dstr = trim(dstr) // \"0000\" // num2str(d(7))\n elseif (d(7) .lt. 1000) then\n dstr = trim(dstr) // \"000\" // num2str(d(7))\n elseif (d(7) .lt. 10000) then\n dstr = trim(dstr) // \"00\" // num2str(d(7))\n elseif (d(7) .lt. 100000) then\n dstr = trim(dstr) // \"0\" // num2str(d(7))\n else\n dstr = trim(dstr) // num2str(d(7))\n end if\n\n datestr0_0 = trim(dstr)\n end if\n return\n end function datestr0_0\n\n!=======================================================================\n! datevec\n!-----------------------------------------------------------------------\n! datevec converts date and time to vector of components.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! d = datevec(t)\n!\n! Description\n!-----------------------------------------------------------------------\n! d = datevec(t) returns a 7-elements datetime vector given the serial\n! date number t.\n!\n! Examples\n!-----------------------------------------------------------------------\n! d = datevec(727455.67013888888d0)\n! 1991 9 14 16 4 59 999998\n!\n! Notes\n!-----------------------------------------------------------------------\n! Input is in double precision for accuracy.\n!=======================================================================\n\n function datevec0(t)\n integer(kind = IPRE) :: datevec0(7)\n real(kind = 8), intent(in) :: t\n integer(kind = IPRE) :: i, days_per_month(12)\n real(kind = 8) :: tmp, dateres\n\n datevec0 = 0\n\n ! Year\n !======\n tmp = 0.0d0\n do\n if (isleap(datevec0(1))) then\n tmp = tmp + 366.0d0\n else\n tmp = tmp + 365.0d0\n end if\n if (tmp .lt. floor(t)) then\n datevec0(1) = datevec0(1) + 1\n else\n exit\n end if\n end do\n dateres = floor(t) - datenum(datevec0(1), 1, 1)\n\n ! Month\n !=======\n tmp = 0.0d0\n days_per_month = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ]\n do i = 1, 12\n tmp = tmp + days_per_month(i)\n if ((isleap(datevec0(1))) .and. (i .eq. 2)) tmp = tmp + 1\n if (tmp .ge. dateres) then\n datevec0(2) = i\n exit\n end if\n end do\n dateres = floor(t) - datenum(datevec0(1), datevec0(2), 1)\n\n ! Day\n !=====\n datevec0(3) = floor(dateres) + 1\n dateres = t - floor(t)\n\n ! Hour\n !======\n datevec0(4) = floor(dateres * 24.0d0)\n dateres = dateres - datevec0(4) / 24.0d0\n\n ! Minute\n !========\n datevec0(5) = floor(dateres * 24.0d0 * 60.0d0)\n dateres = dateres - datevec0(5) / (24.0d0 * 60.0d0)\n\n ! Second\n !========\n datevec0(6) = floor(dateres * 24.0d0 * 60.0d0 * 60.0d0)\n dateres = dateres - datevec0(6) / (24.0d0 * 60.0d0 * 60.0d0)\n\n ! Microsecond\n !=============\n datevec0(7) = floor(dateres * 24.0d0 * 60.0d0 * 60.0d0 * 1.0d+6)\n\n return\n end function datevec0\n\n!=======================================================================\n! dbindex\n!-----------------------------------------------------------------------\n! dbindex computes the Davies-Bouldin index for evaluating clutering\n! algorithms.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! db = dbindex(x, cluster, means)\n! db = dbindex(x, cluster, means, p, q)\n! db = dbindex(X, cluster, means)\n! db = dbindex(X, cluster, means, p, q)\n!\n! Description\n!-----------------------------------------------------------------------\n! db = dbindex(x, cluster, means) returns the Davies-Bouldin index using\n! the Euclidian distance.\n!\n! db = dbindex(x, cluster, means, p, q) returns the Davies-Bouldin index\n! using the metric defined by p and q.\n!\n! db = dbindex(X, cluster, means) returns the Davies-Bouldin index using\n! the Euclidian distance, each row of array X being an observation and\n! each column a parameter.\n!\n! db = dbindex(X, cluster, means, p, q) returns the Davies-Bouldin index\n! using the metric defined by p and q, each row of array X being an\n! observation and each column a parameter.\n!\n! Notes\n!-----------------------------------------------------------------------\n! After Davies D. L. and Bouldin D. W. (1979): \"A Cluster Separation\n! Measure\".\n!=======================================================================\n\n real(kind = RPRE) function dbindex1(x, cluster, means, p, q) result(db)\n real(kind = RPRE), dimension(:), intent(in) :: x, means\n integer(kind = IPRE), dimension(:), intent(in) :: cluster\n real(kind = RPRE), intent(in), optional :: p, q\n integer(kind = IPRE) :: K, n\n real(kind = RPRE) :: opt_p, opt_q\n real(kind = RPRE), dimension(:,:), allocatable :: A, mu\n\n K = size(means)\n if ( K .eq. 1 ) then\n print *, \"Warning: in dbindex, the Davies-Bouldin index cannot \" &\n // \"be defined for K = 1.\"\n db = 1.0d0\n return\n end if\n\n opt_p = 2.\n opt_q = 2.\n if (present(p)) opt_p = p\n if (present(q)) opt_q = q\n\n n = size(x)\n A = reshape( x, shape = [ n, 1 ], order = [ 1, 2 ] )\n mu = reshape( x, shape = [ K, 1 ], order = [ 1, 2 ] )\n db = dbindex2(A, cluster, mu, opt_p, opt_q)\n return\n end function dbindex1\n\n real(kind = RPRE) function dbindex2(X, cluster, means, p, q) result(db)\n real(kind = RPRE), dimension(:,:), intent(in) :: X\n integer(kind = IPRE), dimension(:), intent(in) :: cluster\n real(kind = RPRE), dimension(:,:), intent(in) :: means\n real(kind = RPRE), intent(in), optional :: p, q\n integer(kind = IPRE) :: i, j, K\n real(kind = RPRE) :: opt_p, opt_q, Mij\n integer(kind = IPRE), dimension(:), allocatable :: idx\n real(kind = RPRE), dimension(:), allocatable :: S\n real(kind = RPRE), dimension(:,:), allocatable :: R\n\n K = size(means, 1)\n if ( K .eq. 1 ) then\n print *, \"Warning: in dbindex, the Davies-Bouldin index cannot \" &\n // \"be defined for K = 1.\"\n db = 1.0d0\n return\n end if\n\n opt_p = 2.\n opt_q = 2.\n if (present(p)) opt_p = p\n if (present(q)) opt_q = q\n\n ! Measure the scattering within each cluster\n !============================================\n S = zeros(K)\n do i = 1, K\n idx = find( cluster .eq. i )\n do j = 1, size(idx)\n S(i) = S(i) + norm(X(idx(j),:) - means(i,:), opt_q)**2\n end do\n S(i) = sqrt( S(i) / real(size(idx), RPRE) )\n end do\n\n ! Measure the similarity function R between each cluster\n !========================================================\n R = zeros(K, K)\n do i = 1, K-1\n do j = i+1, K\n Mij = norm(means(i,:) - means(j,:), opt_p) ! Distance between clusters i and j\n R(i,j) = ( S(i) + S(j) ) / Mij\n R(j,i) = R(i,j)\n end do\n end do\n\n ! Compute the Davies-Bouldin index\n !==================================\n db = mean( [ ( maxval(R(i,:)), i = 1, K ) ] )\n\n return\n end function dbindex2\n\n!=======================================================================\n! deboor\n!-----------------------------------------------------------------------\n! deboor evaluates recursively the spline polynomial basis using\n! Cox-de-Boor algorithm.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! db = deboor(i, k, x, t)\n!\n! Description\n!-----------------------------------------------------------------------\n! db = deboor(i, k, x, t) returns the polynomial basis given the control\n! point index i, the polynomial order k (degree k-1), the evaluated\n! point x, and the knots vector t.\n!=======================================================================\n\n recursive function deboor(i, k, x, t) result(db)\n real(kind = RPRE) :: db\n integer(kind = IPRE), intent(in) :: i, k\n real(kind = RPRE), intent(in) :: x\n real(kind = RPRE), dimension(:), intent(in) :: t\n real(kind = RPRE) :: A1, A2\n\n if (k .eq. 1) then\n if (x .ne. t(size(t))) then\n if ( (x .ge. t(i)) .and. (x .lt. t(i+1)) ) then\n db = 1.0d0\n else\n db = 0.0d0\n end if\n else\n if ( (x .ge. t(i)) .and. (x .le. t(i+1)) ) then\n db = 1.0d0\n else\n db = 0.0d0\n end if\n end if\n else\n if (t(i+k-1) - t(i) .ne. 0.0d0) then\n A1 = (x - t(i)) / (t(i+k-1) - t(i))\n else\n A1 = 0.0d0\n end if\n if (t(i+k) - t(i+1) .ne. 0.0d0) then\n A2 = (t(i+k) - x) / (t(i+k) - t(i+1))\n else\n A2 = 0.0d0\n end if\n db = A1 * deboor(i, k-1, x, t) + A2 * deboor(i+1, k-1, x, t)\n end if\n return\n end function deboor\n\n!=======================================================================\n! deg2utm\n!-----------------------------------------------------------------------\n! deg2utm converts latitude / longitude (in degrees) coordinates to\n! UTM-WGS84 coordinates.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! call deg2utm(lat, lon, east, north, zn, zl)\n!\n! Description\n!-----------------------------------------------------------------------\n! call deg2utm(lat, lon, east, north, zn, zl) converts the coordinates\n! in lat and lon (in degrees) to UTM-WGS84 coordinates. It outputs the\n! easting east, northing north, zone number zn, and zone letter zl.\n!\n! Notes\n!-----------------------------------------------------------------------\n! This function has been translated and adapted from the Python's\n! module utm: https://pypi.python.org/pypi/utm\n!=======================================================================\n\n subroutine deg2utm0(lat, lon, east, north, zn, zl)\n real(kind = RPRE), intent(in) :: lat, lon\n real(kind = RPRE), intent(out) :: east, north\n integer(kind = IPRE), intent(out) :: zn\n character(len = 1), intent(out) :: zl\n\n real(kind = 8), parameter :: K0 = 0.9996d0\n real(kind = 8), parameter :: E = 0.00669438d0\n real(kind = 8), parameter :: R = 6378137\n real(kind = 8) :: E_P2, m, n, c, a\n real(kind = 8) :: M1, M2, M3, M4\n real(kind = 8) :: lat_rad, lat_sin, lat_cos, lat_tan, lat_tan2, &\n lat_tan4, lon_rad, central_lon, central_lon_rad\n\n E_P2 = E / (1.0d0 - E)\n M1 = (1 - E / 4 - 3 * E**2 / 64 - 5 * E**3 / 256)\n M2 = (3 * E / 8 + 3 * E**2 / 32 + 45 * E**3 / 1024)\n M3 = (15 * E**2 / 256 + 45 * E**3 / 1024)\n M4 = (35 * E**3 / 3072)\n\n lat_rad = lat*pi/180.0d0\n lat_sin = sin(lat_rad)\n lat_cos = cos(lat_rad)\n lat_tan = lat_sin / lat_cos\n lat_tan2 = lat_tan**2\n lat_tan4 = lat_tan2**2\n\n zn = zone_number(lat, lon)\n zl = zone_letter(lat)\n\n lon_rad = lon*pi/180.0d0\n central_lon = central_longitude(zn)\n central_lon_rad = central_lon*pi/180.0d0\n\n n = R / sqrt(1 - E * lat_sin**2)\n c = E_P2 * lat_cos**2\n a = lat_cos * (lon_rad - central_lon_rad)\n m = R * (M1 * lat_rad &\n - M2 * sin(2 * lat_rad) &\n + M3 * sin(4 * lat_rad) &\n - M4 * sin(6 * lat_rad))\n east = K0 * n * (a + &\n a**3 / 6 * (1 - lat_tan2 + c) + &\n a**5 / 120 * (5 - 18 * lat_tan2 + lat_tan4 + 72 * c - 58 * E_P2)) + 500000\n north = K0 * (m + n * lat_tan * (a**2 / 2 + &\n a**4 / 24 * (5 - lat_tan2 + 9 * c + 4 * c**2) + &\n a**6 / 720 * (61 - 58 * lat_tan2 + lat_tan4 + 600 * c - 330 * E_P2)))\n if (lat .lt. 0.0d0) north = north + 10000000\n return\n\n contains\n\n !-------------------------------------------------------------------\n ! zone_number\n !-------------------------------------------------------------------\n integer(kind = IPRE) function zone_number(lat, lon)\n real(kind = RPRE), intent(in) :: lat, lon\n if ((lat .ge. 56.0d0) .and. (lat .le. 64.0d0) &\n .and. (lon .ge. 3.0d0) .and. (lon .le. 12.0d0)) then\n zone_number = 32\n return\n end if\n\n if ((lat .ge. 72.0d0) .and. (lat .le. 84.0d0) &\n .and. (lon .ge. 0.0d0)) then\n if (lon .le. 9.0d0) then\n zone_number = 31\n return\n elseif (lon .le. 21.0d0) then\n zone_number = 33\n return\n elseif (lon .le. 42.0d0) then\n zone_number = 37\n return\n end if\n end if\n\n zone_number = int((lon + 180.0d0) / 6.0d0) + 1\n return\n end function zone_number\n\n !-------------------------------------------------------------------\n ! zone_letter\n !-------------------------------------------------------------------\n character(len = 1) function zone_letter(lat)\n real(kind = RPRE), intent(in) :: lat\n character(len = *), parameter :: ZONE_LETTERS = \"OXWVUTSRQPNMLKJHGFEDC\"\n integer(kind = IPRE) :: ZONE_LATS(21) = [ 84, 72, 64, 56, 48, 40, 32, 24, 16, 8, 0, &\n -8, -16, -24, -32, -40, -48, -56, -64, -72, -80 ]\n integer(kind = IPRE) :: i\n do i = 1, 21\n if (lat .ge. ZONE_LATS(i)) then\n zone_letter = ZONE_LETTERS(i:i)\n exit\n end if\n end do\n return\n end function zone_letter\n\n !-------------------------------------------------------------------\n ! central_longitude\n !-------------------------------------------------------------------\n real(kind = RPRE) function central_longitude(zn)\n integer(kind = IPRE), intent(in) :: zn\n central_longitude = (zn - 1) * 6 - 180 + 3\n return\n end function central_longitude\n\n end subroutine deg2utm0\n\n subroutine deg2utm1(lat, lon, east, north, zn, zl)\n real(kind = RPRE), dimension(:), intent(in) :: lat, lon\n real(kind = RPRE), dimension(:), allocatable, intent(out) :: east, north\n integer(kind = IPRE), dimension(:), allocatable, intent(out) :: zn\n character(len = 1), dimension(:), allocatable, intent(out) :: zl\n integer(kind = IPRE) :: i, n\n\n n = size(lat)\n allocate(east(n), north(n), zn(n), zl(n))\n do i = 1, n\n call deg2utm(lat(i), lon(i), east(i), north(i), zn(i), zl(i))\n end do\n return\n end subroutine deg2utm1\n\n!=======================================================================\n! det\n!-----------------------------------------------------------------------\n! det computes the matrix determinant.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! x = det(A)\n! x = det(A, L, U)\n!\n! Description\n!-----------------------------------------------------------------------\n! x = det(A) returns the determinant of the square matrix A, as the\n! product of the diagonal elements of the upper triangular matrix from\n! the LU factorization of A.\n!\n! x = det(A, L, U) returns the determinant of the square matrix A and\n! outputs the LU factorization matrices of A used for the calculation.\n!\n! Examples\n!-----------------------------------------------------------------------\n! A = reshape([ 1., 2., 3., 4., 5., 6., 7., 8., 0. ], [ 3, 3 ], &\n! order = [ 2, 1 ])\n! x = det(A)\n! 27.\n!=======================================================================\n\n real(kind = RPRE) function det(A, outL, outU)\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n real(kind = RPRE), dimension(:,:), allocatable, intent(inout), optional :: outL, outU\n real(kind = RPRE), dimension(:,:), allocatable :: L, U\n integer(kind = IPRE) :: m\n\n if (issquare(A)) then\n m = size(A, 1)\n if (m .eq. 2) then\n det = A(1,1)*A(2,2) - A(1,2)*A(2,1)\n elseif (m .eq. 3) then\n det = 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 = 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 function det\n\n!=======================================================================\n! diag\n!-----------------------------------------------------------------------\n! diag creates diagonal matrix or get the diagonal of a matrix.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! x = diag(A)\n! A = diag(x)\n!\n! Description\n!-----------------------------------------------------------------------\n! x = diag(A) returns the main diagonal of matrix A.\n!\n! A = diag(x) returns a square diagonal matrix with the elements of x on\n! the main diagonal.\n!\n! Examples\n!-----------------------------------------------------------------------\n! A = eye(3)\n! x = diag(A)\n! 1. 1. 1.\n!\n! x = [ 1., 2., 3. ]\n! A = diag(x)\n! 1. 0. 0.\n! 0. 2. 0.\n! 0. 0. 3.\n!=======================================================================\n\n function diag1(A)\n real(kind = RPRE), dimension(:), allocatable :: diag1\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE) :: i, n\n\n n = min(size(A, 1), size(A, 2))\n allocate(diag1(n))\n do i = 1, n\n diag1(i) = A(i,i)\n end do\n return\n end function diag1\n\n function diag2(x)\n real(kind = RPRE), dimension(:,:), allocatable :: diag2\n real(kind = RPRE), dimension(:), intent(in) :: x\n integer(kind = IPRE) :: i, n\n\n n = size(x)\n diag2 = zeros(n, n)\n do i = 1, n\n diag2(i,i) = x(i)\n end do\n return\n end function diag2\n\n!=======================================================================\n! diff\n!-----------------------------------------------------------------------\n! diff computes differences of arrays\n!\n! Syntax\n!-----------------------------------------------------------------------\n! y = diff(x)\n! y = diff(x, n)\n! B = diff(A)\n! B = diff(A, n)\n! B = diff(A, dim)\n! B = diff(A, n, dim)\n!\n! Description\n!-----------------------------------------------------------------------\n! y = diff(x) returns differences between adjacent elements of vector x.\n!\n! y = diff(x, n) returns the nth difference by applying the diff(x)\n! operator recursively n times.\n!\n! B = diff(A) returns differences between adjacent elements of array A\n! along the first dimension.\n!\n! B = diff(A, n) returns the nth difference by applying the diff(A)\n! operator recursively n times.\n!\n! B = diff(A, dim) returns differences between adjacent elements of\n! array A along the dimension given by dim.\n!\n! B = diff(A, n, dim) returns the nth difference along the dimension\n! given by dim by applying the diff(A, dim) operator recursively\n! n times.\n!=======================================================================\n\n function diff1(x, n)\n real(kind = RPRE), dimension(:), allocatable :: diff1\n real(kind = RPRE), dimension(:), intent(in) :: x\n integer(kind = IPRE), intent(in), optional :: n\n integer(kind = IPRE) :: opt_n, i\n\n opt_n = 1\n if (present(n)) opt_n = n\n\n diff1 = x\n do i = 1, opt_n\n diff1 = diff1(2:) - diff1(:size(diff1)-1)\n end do\n return\n end function diff1\n\n function diff2(A, n, dim)\n real(kind = RPRE), dimension(:,:), allocatable :: diff2\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE), intent(in), optional :: n, dim\n integer(kind = IPRE) :: opt_n, i\n\n opt_n = 1\n if (present(n)) opt_n = n\n\n diff2 = A\n if ((.not. present(dim)) .or. (dim .eq. 1)) then\n do i = 1, opt_n\n diff2 = diff2(2:,:) - diff2(:size(diff2,1)-1,:)\n end do\n elseif (dim .eq. 2) then\n do i = 1, opt_n\n diff2 = diff2(:,2:) - diff2(:,:size(diff2,2)-1)\n end do\n end if\n return\n end function diff2\n\n!=======================================================================\n! disp\n!-----------------------------------------------------------------------\n! disp displays the value of a variable.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! call disp(x)\n! call disp(x, string)\n! call disp(A)\n! call disp(A, string)\n! call disp(X)\n! call disp(X, 1)\n! call disp(X, 1, string)\n! call disp(X, 2)\n! call disp(X, 2, string)\n! call disp(X, 3)\n! call disp(X, 3, string)\n!\n! Description\n!-----------------------------------------------------------------------\n! call disp(x) displays the scalar or the vector x.\n!\n! call disp(x, string) displays the scalar or the vector x preceded by\n! string.\n!\n! call disp(A) displays the matrix A.\n!\n! call disp(A, string) displays the matrix A preceded by string.\n!\n! call disp(X) displays the 3-dimensional matrix X along the axis 1.\n!\n! call disp(X, 1) (see call disp(X)).\n!\n! call disp(X, 1, string) displays the 3-dimensional matrix X along the\n! axis 1 preceded by string.\n!\n! call disp(X, 2) displays the 3-dimensional matrix X along the axis 2.\n!\n! call disp(X, 2, string) displays the 3-dimensional matrix X along the\n! axis 2 preceded by string.\n!\n! call disp(X, 3) displays the 3-dimensional matrix X along the axis 3.\n!\n! call disp(X, 3, string) displays the 3-dimensional matrix X along the\n! axis 3 preceded by string.\n!\n! Examples\n!-----------------------------------------------------------------------\n! x = [ 1. 2. 3. ]\n! call disp(x)\n! 1.\n! 2.\n! 3.\n! call disp(x, \"x = \")\n! x =\n! 1.\n! 2.\n! 3.\n!\n! A = reshape([ 1., 2., 3., 4., 5., 6., 7., 8., 9. ], [ 3, 3 ], &\n! order = [ 2, 1 ])\n! call disp(A, \"Matrix A is\")\n! Matrix A is\n! 1. 2. 3.\n! 4. 5. 6.\n! 7. 8. 9.\n!=======================================================================\n\n subroutine disp_i0(x, string)\n integer(kind = IPRE), intent(in) :: x\n character(len = *), intent(in), optional :: string\n\n if (present(string)) print *, trim(string)\n print *, x\n return\n end subroutine disp_i0\n\n subroutine disp_r0(x, string)\n real(kind = RPRE), intent(in) :: x\n character(len = *), intent(in), optional :: string\n\n if (present(string)) print *, trim(string)\n print *, x\n return\n end subroutine disp_r0\n\n subroutine disp_c0(x, string)\n complex(kind = RPRE), intent(in) :: x\n character(len = *), intent(in), optional :: string\n\n if (present(string)) print *, trim(string)\n if (imag(x) .ge. 0.0d0) then\n print *, num2str(real(x)) // \" + \" // num2str(abs(imag(x))) // \"i\"\n else\n print *, num2str(real(x)) // \" - \" // num2str(abs(imag(x))) // \"i\"\n end if\n return\n end subroutine disp_c0\n\n subroutine disp_i1(x, string)\n integer(kind = IPRE), dimension(:), intent(in) :: x\n character(len = *), intent(in), optional :: string\n integer(kind = IPRE) :: i, m\n\n m = size(x)\n if (present(string)) print *, trim(string)\n do i = 1, m\n print *, x(i)\n end do\n return\n end subroutine disp_i1\n\n subroutine disp_r1(x, string)\n real(kind = RPRE), dimension(:), intent(in) :: x\n character(len = *), intent(in), optional :: string\n integer(kind = IPRE) :: i, m\n\n m = size(x)\n if (present(string)) print *, trim(string)\n do i = 1, m\n print *, x(i)\n end do\n return\n end subroutine disp_r1\n\n subroutine disp_c1(x, string)\n complex(kind = RPRE), dimension(:), intent(in) :: x\n character(len = *), intent(in), optional :: string\n integer(kind = IPRE) :: i, m\n\n m = size(x)\n if (present(string)) print *, trim(string)\n do i = 1, m\n call disp_c0(x(i))\n end do\n return\n end subroutine disp_c1\n\n subroutine disp_i2(A, string)\n integer(kind = IPRE), dimension(:,:), intent(in) :: A\n character(len = *), intent(in), optional :: string\n integer(kind = IPRE) :: i, j, m, n\n\n m = size(A, 1)\n n = size(A, 2)\n if (present(string)) print *, trim(string)\n do i = 1, m\n print *, (A(i,j), j = 1, n)\n end do\n return\n end subroutine disp_i2\n\n subroutine disp_r2(A, string)\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n character(len = *), intent(in), optional :: string\n integer(kind = IPRE) :: i, j, m, n\n\n m = size(A, 1)\n n = size(A, 2)\n if (present(string)) print *, trim(string)\n do i = 1, m\n print *, (A(i,j), j = 1, n)\n end do\n return\n end subroutine disp_r2\n\n subroutine disp_i3(X, dim, string)\n integer(kind = IPRE), dimension(:,:,:), intent(in) :: X\n integer(kind = IPRE), intent(in), optional :: dim\n character(len = *), intent(in), optional :: string\n integer(kind = IPRE) :: i, dim1, dim2, dim3\n\n dim1 = size(X, 1)\n dim2 = size(X, 2)\n dim3 = size(X, 3)\n if (present(string)) print *, trim(string)\n if ((.not. present(dim)) .or. (dim .eq. 1)) then\n do i = 1, dim1\n print *, \"Slice (\" // num2str(i) // \",:,:):\"\n call disp(X(i,:,:))\n end do\n elseif (dim .eq. 2) then\n do i = 1, dim2\n print *, \"Slice (:,\" // num2str(i) // \",:):\"\n call disp(X(:,i,:))\n end do\n elseif (dim .eq. 3) then\n do i = 1, dim3\n print * , \"Slice (:,:,\" // num2str(i) // \"):\"\n call disp(X(:,:,i))\n end do\n end if\n return\n end subroutine disp_i3\n\n subroutine disp_r3(X, dim, string)\n real(kind = RPRE), dimension(:,:,:), intent(in) :: X\n integer(kind = IPRE), intent(in), optional :: dim\n character(len = *), intent(in), optional :: string\n integer(kind = IPRE) :: i, dim1, dim2, dim3\n\n dim1 = size(X, 1)\n dim2 = size(X, 2)\n dim3 = size(X, 3)\n if (present(string)) print *, trim(string)\n if ((.not. present(dim)) .or. (dim .eq. 1)) then\n do i = 1, dim1\n print *, \"Slice (\" // num2str(i) // \",:,:):\"\n call disp(X(i,:,:))\n end do\n elseif (dim .eq. 2) then\n do i = 1, dim2\n print *, \"Slice (:,\" // num2str(i) // \",:):\"\n call disp(X(:,i,:))\n end do\n elseif (dim .eq. 3) then\n do i = 1, dim3\n print * , \"Slice (:,:,\" // num2str(i) // \"):\"\n call disp(X(:,:,i))\n end do\n end if\n return\n end subroutine disp_r3\n\n!=======================================================================\n! eig\n!-----------------------------------------------------------------------\n! eig computes eigenvalues and eigenvectors of symmetric matrix using\n! Jacobi algorithm.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! call eig(A, V, d)\n! call eig(A, V, d, itermax)\n!\n! Description\n!-----------------------------------------------------------------------\n! call eig(A, V, d) returns the eigenvalues of the symmetric matrix A\n! in the vector d and the associated eigenvectors in the matrix V.\n!\n! call eig(A, V, d) returns eigenvalues and eigenvectors with a maximum\n! of itermax iterations.\n!=======================================================================\n\n subroutine eig(A, V, d, itermax)\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n real(kind = RPRE), dimension(:,:), allocatable, intent(out) :: V\n real(kind = RPRE), dimension(:), allocatable, intent(out) :: d\n integer(kind = IPRE), intent(in), optional :: itermax\n integer(kind = IPRE) :: opt_itermax, iter, i, j, k, n\n integer(kind = IPRE), dimension(:), allocatable :: idx\n real(kind = RPRE) :: threshold, gapj, termi, termj, h, term, t, &\n theta, c, s, tau, g\n real(kind = RPRE), dimension(:), allocatable :: bw, zw\n real(kind = RPRE), dimension(:,:), allocatable :: B\n\n opt_itermax = 1000\n if (present(itermax)) opt_itermax = itermax\n\n if (.not. issymmetric(A)) then\n stop \"Error: in eig(A), A is not symmetric.\"\n else\n if (allocated(V)) deallocate(V)\n if (allocated(d)) deallocate(d)\n\n B = A\n n = size(B, 1)\n V = eye(n)\n d = diag(B)\n bw = d\n zw = zeros(n)\n\n iter = 0\n do while (iter .lt. opt_itermax)\n iter = iter + 1\n\n threshold = sqrt(sum(triu(B, 1)**2)) / (4.0*n)\n if (threshold .eq. 0.0d0) exit\n\n do i = 1, n\n do j = i+1, n\n gapj = 10.0d0 * abs(B(i,j))\n termi = gapj + abs(d(i))\n termj = gapj + abs(d(j))\n\n if ( ( iter .gt. 4 ) .and. ( termi .eq. abs(d(i)) ) &\n .and. ( termj .eq. abs(d(j)) ) ) then\n B(i,j) = 0.0d0\n elseif ( threshold .le. abs(B(i,j)) ) then\n h = d(j) - d(i)\n term = abs(h) + gapj\n\n if ( term .eq. abs(h) ) then\n t = B(i,j) / h\n else\n theta = 0.5d0 * h / B(i,j)\n t = 1.0d0 / ( abs(theta) + sqrt(1.0d0 + theta*theta) )\n if (theta .lt. 0.0d0) t = -t\n end if\n\n c = 1.0d0 / sqrt(1.0d0 + t*t)\n s = t * c\n tau = s / (1.0d0 + c)\n h = t * B(i,j)\n\n zw(i) = zw(i) - h\n zw(j) = zw(j) + h\n d(i) = d(i) - h\n d(j) = d(j) + h\n B(i,j) = 0.0d0\n\n do k = 1, i-1\n g = B(k,i)\n h = B(k,j)\n B(k,i) = g - s * (h + g * tau)\n B(k,j) = h + s * (g - h * tau)\n end do\n\n do k = i+1, j-1\n g = B(i,k)\n h = B(k,j)\n B(i,k) = g - s * (h + g * tau)\n B(k,j) = h + s * (g - h * tau)\n end do\n\n do k = j+1, n\n g = B(i,k)\n h = B(j,k)\n B(i,k) = g - s * (h + g * tau)\n B(j,k) = h + s * (g - h * tau)\n end do\n\n do k = 1, n\n g = V(k,i)\n h = V(k,j)\n v(k,i) = g - s * (h + g * tau)\n v(k,j) = h + s * (g - h * tau)\n end do\n\n end if\n end do\n end do\n\n bw = bw + zw\n d = bw\n zw = 0.0d0\n end do\n\n idx = argsort(d, 1)\n d = d(idx)\n V = V(:,idx)\n end if\n\n return\n end subroutine eig\n\n!=======================================================================\n! file_exist\n!-----------------------------------------------------------------------\n! file_exist determines whether a File object already exists.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! exist = ofile % exist()\n!\n! Description\n!-----------------------------------------------------------------------\n! call ofile % exist() returns .true. if the File object ofile exists,\n! .false. otherwise.\n!=======================================================================\n\n logical function file_exist(self)\n class(File), intent(inout) :: self\n\n inquire(file = trim(self % filename), exist = file_exist)\n return\n end function file_exist\n\n!=======================================================================\n! eye\n!-----------------------------------------------------------------------\n! eye creates the identity matrix.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! I = eye(dim1)\n! I = eye(dim1, dim2)\n!\n! Description\n!-----------------------------------------------------------------------\n! I = eye(dim1) returns an dim1-by-dim1 matrix with ones on the main\n! diagonal and zeros elsewhere.\n!\n! I = eye(dim1, dim2) returns a dim1-by-dim2 matrix with ones on the\n! main diagonal and zeros elsewhere.\n!\n! Examples\n!-----------------------------------------------------------------------\n! I = eye(3)\n! 1. 0. 0.\n! 0. 1. 0.\n! 0. 0. 1.\n!\n! I = eye(3, 4)\n! 1. 0. 0. 0.\n! 0. 1. 0. 0.\n! 0. 0. 1. 0.\n!\n! I = eye(4, 3)\n! 1. 0. 0.\n! 0. 1. 0.\n! 0. 0. 1.\n! 0. 0. 0.\n!=======================================================================\n\n function eye(dim1, dim2)\n real(kind = RPRE), dimension(:,:), allocatable :: eye\n integer(kind = IPRE), intent(in) :: dim1\n integer(kind = IPRE), intent(in), optional :: dim2\n integer(kind = IPRE) :: i\n\n if (.not. present(dim2)) then\n eye = zeros(dim1, dim1)\n do i = 1, dim1\n eye(i,i) = 1.0d0\n end do\n else\n eye = zeros(dim1, dim2)\n do i = 1, min(dim1, dim2)\n eye(i,i) = 1.0d0\n end do\n end if\n return\n end function eye\n\n!=======================================================================\n! File (constructor)\n!-----------------------------------------------------------------------\n! File constructs a File object.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! ofile = File(unit, filename)\n!\n! Description\n!-----------------------------------------------------------------------\n! ofile = File(unit, filename) returns a File object associated to the\n! file filename with the identifier unit.\n!\n! Examples\n!-----------------------------------------------------------------------\n! type(File) :: ofile\n!\n! ofile = File(10, \"myfile.txt\")\n! call ofile%open()\n! ! ... some operations on this file ...\n! call ofile%close()\n!=======================================================================\n\n type(File) function init_File(unit, filename)\n integer(kind = IPRE), intent(in) :: unit\n character(len = *), intent(in) :: filename\n\n init_File % unit = unit\n init_File % filename = trim(filename)\n return\n end function init_File\n\n!=======================================================================\n! find\n!-----------------------------------------------------------------------\n! find finds indices of values in arrays that satisfy input condition.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! x = find(condition)\n! A = find(condition)\n! X = find(condition)\n!\n! Description\n!-----------------------------------------------------------------------\n! x = find(condition) returns a vector with the indices of the values\n! that satisfy condition.\n!\n! A = find(condition) returns a 2-columns array with the indices of the\n! values that satisfy condition.\n!\n! X = find(condition) returns a 3-columns array with the indices of the\n! values that satisfy condition.\n!\n! Examples\n!-----------------------------------------------------------------------\n! x = [ 2., 1., 8., 7., 4., 6., 9., 3., 5. ]\n! y = find(x .ge. 5.)\n! 3 4 6 7 9\n!\n! A = diag([1., 2., 3.])\n! y = find(A .ne. 0.)\n! 1 1\n! 2 2\n! 3 3\n!=======================================================================\n\n function find1(bool)\n integer(kind = IPRE), dimension(:), allocatable :: find1\n logical, dimension(:), intent(in) :: bool\n integer(kind = IPRE) :: i, j, n\n\n n = count(bool)\n if (n .ne. 0) then\n find1 = zeros(n)\n j = 1\n do i = 1, size(bool)\n if (bool(i)) then\n find1(j) = i\n j = j + 1\n end if\n end do\n else\n find1 = zeros(0)\n end if\n return\n end function find1\n\n function find2(bool)\n integer(kind = IPRE), dimension(:,:), allocatable :: find2\n logical, dimension(:,:), intent(in) :: bool\n integer(kind = IPRE) :: i, j, k, n\n\n n = count(bool)\n if (n .ne. 0) then\n find2 = zeros(n, 2)\n k = 1\n do i = 1, size(bool, 1)\n do j = 1, size(bool, 2)\n if (bool(i,j)) then\n find2(k,1) = i\n find2(k,2) = j\n k = k + 1\n end if\n end do\n end do\n else\n find2 = zeros(0, 2)\n end if\n return\n end function find2\n\n function find3(bool)\n integer(kind = IPRE), dimension(:,:), allocatable :: find3\n logical, dimension(:,:,:), intent(in) :: bool\n integer(kind = IPRE) :: i, j, k, l, n\n\n n = count(bool)\n if (n .ne. 0) then\n find3 = zeros(n, 3)\n l = 1\n do i = 1, size(bool, 1)\n do j = 1, size(bool, 2)\n do k = 1, size(bool, 3)\n if (bool(i,j,k)) then\n find3(l,1) = i\n find3(l,2) = j\n find3(l,3) = k\n l = l + 1\n end if\n end do\n end do\n end do\n else\n find3 = zeros(0, 3)\n end if\n return\n end function find3\n\n!=======================================================================\n! fminbnd\n!-----------------------------------------------------------------------\n! fminbnd solves a 1-dimensional problem defined by\n! min_x f(x) | a < x < b\n! with x, a, b finite scalars, and f(x) a function that returns a\n! scalar. The golden section search algorithm is used.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! x = fminbnd(fitness, a, b)\n! x = fminbnd(fitness, a, b, eps)\n!\n! Description\n!-----------------------------------------------------------------------\n! x = fminbnd(fitness, a, b) returns the scalar x that is a local\n! minimizer of the function fitness in the interval a < x < b.\n!\n! x = fminbnd(fitness, a, b, eps) returns the local minimizer x with the\n! convergence tolerance specified by eps.\n!=======================================================================\n\n real(kind = RPRE) function fminbnd(fitness, a, b, eps)\n procedure(func1d) :: fitness\n real(kind = RPRE), intent(in) :: a, b\n real(kind = RPRE), intent(in), optional :: eps\n real(kind = RPRE) :: opt_eps, x1, x2, x3, x4\n real(kind = RPRE), parameter :: gr = 0.6180339887498949d0\n\n opt_eps = 1.0d-4\n if (present(eps)) opt_eps = eps\n\n x1 = a\n x2 = b\n x3 = x2 - gr * (x2 - x1)\n x4 = x1 + gr * (x2 - x1)\n do while ( abs(x3 - x4) .gt. opt_eps )\n if ( fitness(x3) .lt. fitness(x4) ) then\n x2 = x4\n else\n x1 = x3\n end if\n x3 = x2 - gr * (x2 - x1)\n x4 = x1 + gr * (x2 - x1)\n end do\n fminbnd = 0.5d0 * (x1 + x2)\n return\n end function fminbnd\n\n!=======================================================================\n! flip\n!-----------------------------------------------------------------------\n! flip reverses order of elements of arrays.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! y = flip(x)\n! B = flip(A)\n! B = flip(A, dim)\n! Y = flip(X)\n! Y = flip(X, dim)\n!\n! Description\n!-----------------------------------------------------------------------\n! y = flip(x) returns the vector x in reversed order.\n!\n! B = flip(A) returns the matrix A with its rows flipped in the\n! up-to-down direction.\n!\n! B = flip(A, dim) returns the matrix A with its elements in reversed\n! order along the dimension dim.\n!\n! Y = flip(X) returns the 3-dimensional array X with its elements in\n! reversed order along the first dimension.\n!\n! Y = flip(X, dim) returns the 3-dimensional array X with its elements\n! in reversed order along the dimension dim.\n!\n! Examples\n!-----------------------------------------------------------------------\n! x = linspace(1, 9, 9)\n! y = flip(x)\n! 9. 8. 7. 6. 5. 4. 3. 2. 1.\n!\n! A = eye(3)\n! B = flip(A, 1)\n! 0. 0. 1.\n! 0. 1. 0.\n! 1. 0. 0.\n! C = flip(A, 2)\n! 0. 0. 1.\n! 0. 1. 0.\n! 1. 0. 0.\n!=======================================================================\n\n function flip_i1(x)\n integer(kind = IPRE), dimension(:), allocatable :: flip_i1\n integer(kind = IPRE), dimension(:), intent(in) :: x\n\n flip_i1 = flipud(x)\n return\n end function flip_i1\n\n function flip_r1(x)\n real(kind = RPRE), dimension(:), allocatable :: flip_r1\n real(kind = RPRE), dimension(:), intent(in) :: x\n\n flip_r1 = flipud(x)\n return\n end function flip_r1\n\n function flip_i2(A, dim)\n integer(kind = IPRE), dimension(:,:), allocatable :: flip_i2\n integer(kind = IPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE), intent(in), optional :: dim\n\n if ((.not. present(dim)) .or. (dim .eq. 1)) then\n flip_i2 = flipud(A)\n elseif (dim .eq. 2) then\n flip_i2 = fliplr(A)\n end if\n return\n end function flip_i2\n\n function flip_r2(A, dim)\n real(kind = RPRE), dimension(:,:), allocatable :: flip_r2\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE), intent(in), optional :: dim\n\n if ((.not. present(dim)) .or. (dim .eq. 1)) then\n flip_r2 = flipud(A)\n elseif (dim .eq. 2) then\n flip_r2 = fliplr(A)\n end if\n return\n end function flip_r2\n\n function flip_i3(X, dim)\n integer(kind = IPRE), dimension(:,:,:), allocatable :: flip_i3\n integer(kind = IPRE), dimension(:,:,:), intent(in) :: X\n integer(kind = IPRE), intent(in), optional :: dim\n integer(kind = IPRE) :: n\n\n if ((.not. present(dim)) .or. (dim .eq. 1)) then\n n = size(X, 1)\n flip_i3 = X(n:1:-1,:,:)\n elseif (dim .eq. 2) then\n n = size(X, 2)\n flip_i3 = X(:,n:1:-1,:)\n elseif (dim .eq. 3) then\n n = size(X, 3)\n flip_i3 = X(:,:,n:1:-1)\n end if\n return\n end function flip_i3\n\n function flip_r3(X, dim)\n real(kind = IPRE), dimension(:,:,:), allocatable :: flip_r3\n real(kind = IPRE), dimension(:,:,:), intent(in) :: X\n integer(kind = IPRE), intent(in), optional :: dim\n integer(kind = IPRE) :: n\n\n if ((.not. present(dim)) .or. (dim .eq. 1)) then\n n = size(X, 1)\n flip_r3 = X(n:1:-1,:,:)\n elseif (dim .eq. 2) then\n n = size(X, 2)\n flip_r3 = X(:,n:1:-1,:)\n elseif (dim .eq. 3) then\n n = size(X, 3)\n flip_r3 = X(:,:,n:1:-1)\n end if\n return\n end function flip_r3\n\n!=======================================================================\n! fliplr\n!-----------------------------------------------------------------------\n! fliplr reverses vector and matrix left to right.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! y = fliplr(x)\n! B = fliplr(A)\n!\n! Description\n!-----------------------------------------------------------------------\n! y = fliplr(x) returns the vector x in reversed order.\n!\n! B = fliplr(A) returns the matrix A with its columns flipped in the\n! left-to-right direction.\n!\n! Examples\n!-----------------------------------------------------------------------\n! x = linspace(1, 9, 9)\n! y = fliplr(x)\n! 9. 8. 7. 6. 5. 4. 3. 2. 1.\n!\n! A = eye(3)\n! B = fliplr(A)\n! 0. 0. 1.\n! 0. 1. 0.\n! 1. 0. 0.\n!=======================================================================\n\n function fliplr_i1(x)\n integer(kind = IPRE), dimension(:), allocatable :: fliplr_i1\n integer(kind = IPRE), dimension(:), intent(in) :: x\n integer(kind = IPRE) :: n\n\n n = size(x)\n fliplr_i1 = x(n:1:-1)\n return\n end function fliplr_i1\n\n function fliplr_r1(x)\n real(kind = RPRE), dimension(:), allocatable :: fliplr_r1\n real(kind = RPRE), dimension(:), intent(in) :: x\n integer(kind = IPRE) :: n\n\n n = size(x)\n fliplr_r1 = x(n:1:-1)\n return\n end function fliplr_r1\n\n function fliplr_i2(A)\n integer(kind = IPRE), dimension(:,:), allocatable :: fliplr_i2\n integer(kind = IPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE) :: n\n\n n = size(A, 2)\n fliplr_i2 = A(:,n:1:-1)\n return\n end function fliplr_i2\n\n function fliplr_r2(A)\n real(kind = RPRE), dimension(:,:), allocatable :: fliplr_r2\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE) :: n\n\n n = size(A, 2)\n fliplr_r2 = A(:,n:1:-1)\n return\n end function fliplr_r2\n\n!=======================================================================\n! flipud\n!-----------------------------------------------------------------------\n! flipud reverses vector and matrix up to down.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! y = flipud(x)\n! B = flipud(A)\n!\n! Description\n!-----------------------------------------------------------------------\n! y = flipud(x) returns the vector x in reversed order.\n!\n! B = flipud(A) returns the matrix A with its rows flipped in the\n! up-to-down direction.\n!\n! Examples\n!-----------------------------------------------------------------------\n! x = linspace(1, 9, 9)\n! y = flipud(x)\n! 9. 8. 7. 6. 5. 4. 3. 2. 1.\n!\n! A = eye(3)\n! B = flipud(A)\n! 0. 0. 1.\n! 0. 1. 0.\n! 1. 0. 0.\n!=======================================================================\n\n function flipud_i1(x)\n integer(kind = IPRE), dimension(:), allocatable :: flipud_i1\n integer(kind = IPRE), dimension(:), intent(in) :: x\n integer(kind = IPRE) :: n\n\n n = size(x)\n flipud_i1 = x(n:1:-1)\n return\n end function flipud_i1\n\n function flipud_r1(x)\n real(kind = RPRE), dimension(:), allocatable :: flipud_r1\n real(kind = RPRE), dimension(:), intent(in) :: x\n integer(kind = IPRE) :: n\n\n n = size(x)\n flipud_r1 = x(n:1:-1)\n return\n end function flipud_r1\n\n function flipud_i2(A)\n integer(kind = IPRE), dimension(:,:), allocatable :: flipud_i2\n integer(kind = IPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE) :: n\n\n n = size(A, 1)\n flipud_i2 = A(n:1:-1,:)\n return\n end function flipud_i2\n\n function flipud_r2(A)\n real(kind = RPRE), dimension(:,:), allocatable :: flipud_r2\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE) :: n\n\n n = size(A, 1)\n flipud_r2 = A(n:1:-1,:)\n return\n end function flipud_r2\n\n!=======================================================================\n! gammainc\n!-----------------------------------------------------------------------\n! gammainc returns the incomplete gamma function.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! y = gammainc(x, a)\n!\n! Description\n!-----------------------------------------------------------------------\n! y = gammainc(x, a) returns the incomplete gamma function of\n! corresponding elements of x and a.\n!=======================================================================\n\n real(kind = RPRE) function gammainc0(x, a)\n real(kind = RPRE), intent(in) :: x, a\n\n if ( x .lt. 0. .or. a .le. 0.) then\n print *, \"Error: in gammainc, x < 0 and/or a <= 0\"\n stop\n end if\n if ( x .lt. a+1. ) then\n gammainc0 = gser(x, a)\n else\n gammainc0 = 1. - gcf(x, a)\n end if\n\n return\n contains\n\n real(kind = RPRE) function gser(x, a)\n real(kind = RPRE), intent(in) :: x, a\n integer(kind = IPRE), parameter :: itermax = 100\n real(kind = RPRE), parameter :: eps = 3.e-7\n integer(kind = IPRE) :: n\n real(kind = RPRE) :: gln, ap, del, s\n\n gln = log(gamma(a))\n if ( x .le. 0. ) then\n gser = 0.\n else\n ap = a\n s = 1. / a\n del = s\n do n = 1, itermax\n ap = ap + 1.\n del = del * x / ap\n s = s + del\n if ( abs(del) .lt. abs(s)*eps ) exit\n end do\n gser = s * exp(-x + a * log(x) - gln)\n end if\n return\n end function gser\n\n real(kind = RPRE) function gcf(x, a)\n real(kind = RPRE), intent(in) :: x, a\n integer(kind = IPRE), parameter :: itermax = 100\n real(kind = RPRE), parameter :: eps = 3.e-7, fpmin = 1.e-30\n integer(kind = IPRE) :: i\n real(kind = RPRE) :: an, b, c, d, del, h, gln\n\n gln = log(gamma(a))\n b = x + 1. - a\n c = 1. / fpmin\n d = 1. / b\n h = d\n do i = 1, itermax\n an = -i * (i - a)\n b = b + 2\n d = an * d + b\n if ( abs(d) .lt. fpmin ) d = fpmin\n c = b + an / c\n if ( abs(c) .lt. fpmin ) c = fpmin\n d = 1. / d\n del = d * c\n h = h * del\n if ( abs(del-1.) .lt. eps ) exit\n end do\n gcf = h * exp(-x + a * log(x) - gln)\n return\n end function gcf\n\n end function gammainc0\n\n function gammainc1_0(X, a)\n real(kind = RPRE), dimension(:), allocatable :: gammainc1_0\n real(kind = RPRE), dimension(:), intent(in) :: X\n real(kind = RPRE), intent(in) :: a\n integer(kind = IPRE) :: i, n\n\n n = size(X)\n gammainc1_0 = zeros(n)\n do i = 1, n\n gammainc1_0(i) = gammainc0(X(i), a)\n end do\n return\n end function\n\n!=======================================================================\n! gmm\n!-----------------------------------------------------------------------\n! gmm performs Gaussian Mixture Modelling using Expectation-Maximization\n! algorithm.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! idx = gmm(x, K, [options = ])\n! idx = gmm(A, K, [options = ])\n!\n! Description\n!-----------------------------------------------------------------------\n! idx = gmm(x, K, [options = ]) returns the cluster indices of each\n! element in vector x.\n!\n! idx = gmm(A, K, [options = ]) returns the cluster indices of each\n! rows in matrix A.\n!\n! Options\n!-----------------------------------------------------------------------\n! means Output centroids\n! stdev / covar Output standard deviation / covariance matrix\n! prob Output probabilities\n! itermax = 1000 Maximum number of iterations\n! niter Output number of iterations\n!=======================================================================\n\n function gmm1(x, K, means, stdev, prob, itermax, niter) result(idx)\n integer(kind = IPRE), dimension(:), allocatable :: idx\n real(kind = RPRE), dimension(:), intent(in) :: x\n integer(kind = IPRE), intent(in) :: K\n real(kind = RPRE), dimension(:), allocatable, intent(inout), optional :: prob, means, stdev\n integer(kind = IPRE), intent(in), optional :: itermax\n integer(kind = IPRE), intent(inout), optional :: niter\n integer(kind = IPRE) :: opt_itermax, i, j, n, iter\n real(kind = RPRE), dimension(:), allocatable :: phi, mu, mu_prev, sigma\n real(kind = RPRE), dimension(:,:), allocatable :: w, pdf, pdf_w\n\n n = size(x)\n\n opt_itermax = 1000\n if (present(itermax)) opt_itermax = itermax\n\n ! Initialization\n !================\n phi = ones(K) / real(K) ! Equal initial probabilities for each cluster\n mu = x(randperm(n, K)) ! Random initial means\n sigma = ones(K) * std(x) ! Covariance matrices for each variable\n\n ! Loop until convergence\n !========================\n w = zeros(n, K)\n iter = 0\n do while ( iter .lt. opt_itermax )\n iter = iter + 1\n\n ! Expectation\n !=============\n pdf = zeros(n, K)\n do j = 1, K\n pdf(:,j) = normpdf(x, mu(j), sigma(j))\n end do\n\n pdf_w = pdf * repmat(phi, n, 2)\n w = pdf_w / repmat(sum(pdf_w, dim = 2), K)\n\n ! Maximization\n !==============\n mu_prev = mu\n do j = 1, K\n phi(j) = mean(w(:,j))\n mu(j) = dot_product(w(:,j), x) / sum(w(:,j))\n sigma(j) = dot_product(w(:,j), (x - mu(j))**2) / sum(w(:,j))\n sigma(j) = sqrt(sigma(j))\n end do\n\n if ( norm(mu - mu_prev) .lt. 1.0d-10 ) exit\n end do\n\n idx = zeros(n)\n do i = 1, n\n idx(i:i) = maxloc(pdf(i,:))\n end do\n\n if (present(niter)) niter = iter\n if (present(means)) means = mu\n if (present(stdev)) stdev = sigma\n if (present(prob)) prob = phi\n\n return\n end function gmm1\n\n function gmm2(A, K, means, covar, prob, itermax, niter) result(idx)\n integer(kind = IPRE), dimension(:), allocatable :: idx\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE), intent(in) :: K\n real(kind = RPRE), dimension(:), allocatable, intent(inout), optional :: prob\n real(kind = RPRE), dimension(:,:), allocatable, intent(inout), optional :: means\n real(kind = RPRE), dimension(:,:,:), allocatable, intent(inout), optional :: covar\n integer(kind = IPRE), intent(in), optional :: itermax\n integer(kind = IPRE), intent(inout), optional :: niter\n\n integer(kind = IPRE) :: opt_itermax, i, j, n, p, iter\n real(kind = RPRE), dimension(:), allocatable :: phi\n real(kind = RPRE), dimension(:,:), allocatable :: mu, mu_prev, w, pdf, &\n pdf_w, tmp\n real(kind = RPRE), dimension(:,:,:), allocatable :: sigma\n\n n = size(A, 1)\n p = size(A, 2)\n\n opt_itermax = 1000\n if (present(itermax)) opt_itermax = itermax\n\n ! Initialization\n !================\n phi = ones(K) / real(K) ! Equal initial probabilities for each cluster\n mu = A(randperm(n, K),:) ! Random initial means\n sigma = zeros(p, p, K) ! Covariance matrices for each variable\n\n tmp = cov(A)\n do j = 1, K\n sigma(:,:,j) = tmp\n end do\n\n ! Loop until convergence\n !========================\n w = zeros(n, K)\n iter = 0\n do while ( iter .lt. opt_itermax )\n iter = iter + 1\n\n ! Expectation\n !=============\n pdf = zeros(n, K)\n do j = 1, K\n pdf(:,j) = normpdf(A, mu(j,:), sigma(:,:,j))\n end do\n\n pdf_w = pdf * repmat(phi, n, 2)\n w = pdf_w / repmat(sum(pdf_w, dim = 2), K)\n\n ! Maximization\n !==============\n mu_prev = mu\n do j = 1, K\n phi(j) = mean(w(:,j))\n mu(j,:) = matmul(w(:,j), A) / sum(w(:,j))\n tmp = A - repmat(mu(j,:), n, 2)\n\n sigma(:,:,j) = zeros(p, p)\n do i = 1, n\n sigma(:,:,j) = sigma(:,:,j) &\n + w(i,j) * matmul(transpose(tmp(i:i,:)), tmp(i:i,:)) &\n / sum(w(:,j))\n end do\n end do\n\n if ( means_residuals(mu, mu_prev) .lt. 1.0d-10 ) exit\n end do\n\n idx = zeros(n)\n do i = 1, n\n idx(i:i) = maxloc(pdf(i,:))\n end do\n\n if (present(niter)) niter = iter\n if (present(means)) means = mu\n if (present(covar)) covar = sigma\n if (present(prob)) prob = phi\n\n return\n contains\n\n !-------------------------------------------------------------------\n ! means_residuals\n !-------------------------------------------------------------------\n function means_residuals(means1, means2) result(eps)\n real(kind = RPRE) :: eps\n real(kind = RPRE), dimension(:,:), intent(in) :: means1, means2\n real(kind = RPRE), dimension(:,:), allocatable :: means\n integer(kind = IPRE) :: k\n\n eps = 0.0d0\n means = abs( means2 - means1 )\n do k = 1, p\n eps = eps + sum(means(:,k))**2\n end do\n eps = sqrt(eps)\n return\n end function means_residuals\n\n end function gmm2\n\n!=======================================================================\n! horzcat\n!-----------------------------------------------------------------------\n! horzcat concatenates arrays horizontally.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! A = horzcat(x1, x2)\n! A = horzcat(A1, A2)\n! B = horzcat(x1, A2)\n! B = horzcat(A1, x2)\n!\n! Description\n!-----------------------------------------------------------------------\n! A = horzcat(x1, x2) concatenates the vectors x1 and x2 treated as\n! column vectors along the dimension 1. If the length of x1 and x2 are\n! not equal, empty elements will be filled with zeros.\n!\n! A = horzcat(A1, A2) concatenates the matrices A1 and A2 along the\n! dimension 1. If the first dimensions of A1 and A2 are not equal, empty\n! elements will be filled with zeros.\n!\n! B = horzcat(x1, A2) concatenates the vector x treated as column vector\n! and the matrix A along the dimension 1. If the length of x and the\n! first dimension of A are not equal, empty elements will be filled with\n! zeros.\n!\n! B = horzcat(A1, x2) concatenates the matrix A and the vector x treated\n! as column vector along the dimension 1. If the first dimension o A and\n! the length of x are not equal, empty elements will be filled with\n! zeros.\n!\n! Examples\n!-----------------------------------------------------------------------\n! A1 = reshape([ 1., 2., 3., 4. ], [ 2, 2 ], order = [ 2, 1 ])\n! A2 = reshape([ 5., 6., 7., 8. ], [ 2, 2 ], order = [ 2, 1 ])\n! A = horzcat(A1, A2)\n! 1. 2. 5. 6.\n! 3. 4. 7. 8.\n!=======================================================================\n\n function horzcat_i1(x1, x2)\n integer(kind = IPRE), dimension(:,:), allocatable :: horzcat_i1\n integer(kind = IPRE), dimension(:), intent(in) :: x1, x2\n integer(kind = IPRE) :: m1, m2\n\n m1 = size(x1)\n m2 = size(x2)\n\n horzcat_i1 = zeros(max(m1, m2), 2)\n horzcat_i1(1:m1,1) = x1\n horzcat_i1(1:m2,2) = x2\n return\n end function horzcat_i1\n\n function horzcat_r1(x1, x2)\n real(kind = RPRE), dimension(:,:), allocatable :: horzcat_r1\n real(kind = RPRE), dimension(:), intent(in) :: x1, x2\n integer(kind = IPRE) :: m1, m2\n\n m1 = size(x1)\n m2 = size(x2)\n\n horzcat_r1 = zeros(max(m1, m2), 2)\n horzcat_r1(1:m1,1) = x1\n horzcat_r1(1:m2,2) = x2\n return\n end function horzcat_r1\n\n function horzcat_i2(A1, A2)\n integer(kind = IPRE), dimension(:,:), allocatable :: horzcat_i2\n integer(kind = IPRE), dimension(:,:), intent(in) :: A1, A2\n integer(kind = IPRE) :: m1, n1, m2, n2\n\n m1 = size(A1, 1)\n n1 = size(A1, 2)\n m2 = size(A2, 1)\n n2 = size(A2, 2)\n\n horzcat_i2 = zeros(max(m1, m2), n1+n2)\n horzcat_i2(1:m1,1:n1) = A1\n horzcat_i2(1:m2,n1+1:) = A2\n return\n end function horzcat_i2\n\n function horzcat_r2(A1, A2)\n real(kind = RPRE), dimension(:,:), allocatable :: horzcat_r2\n real(kind = RPRE), dimension(:,:), intent(in) :: A1, A2\n integer(kind = IPRE) :: m1, n1, m2, n2\n\n m1 = size(A1, 1)\n n1 = size(A1, 2)\n m2 = size(A2, 1)\n n2 = size(A2, 2)\n\n horzcat_r2 = zeros(max(m1, m2), n1+n2)\n horzcat_r2(1:m1,1:n1) = A1\n horzcat_r2(1:m2,n1+1:) = A2\n return\n end function horzcat_r2\n\n function horzcat_i12(x1, A2)\n integer(kind = IPRE), dimension(:,:), allocatable :: horzcat_i12\n integer(kind = IPRE), dimension(:), intent(in) :: x1\n integer(kind = IPRE), dimension(:,:), intent(in) :: A2\n integer(kind = IPRE) :: m1, m2, n2\n\n m1 = size(x1)\n m2 = size(A2, 1)\n n2 = size(A2, 2)\n\n horzcat_i12 = zeros(max(m1, m2), n2+1)\n horzcat_i12(1:m1,1) = x1\n horzcat_i12(1:m2,2:) = A2\n return\n end function horzcat_i12\n\n function horzcat_r12(x1, A2)\n real(kind = RPRE), dimension(:,:), allocatable :: horzcat_r12\n real(kind = RPRE), dimension(:), intent(in) :: x1\n real(kind = RPRE), dimension(:,:), intent(in) :: A2\n integer(kind = IPRE) :: m1, m2, n2\n\n m1 = size(x1)\n m2 = size(A2, 1)\n n2 = size(A2, 2)\n\n horzcat_r12 = zeros(max(m1, m2), n2+1)\n horzcat_r12(1:m1,1) = x1\n horzcat_r12(1:m2,2:) = A2\n return\n end function horzcat_r12\n\n function horzcat_i21(A1, x2)\n integer(kind = IPRE), dimension(:,:), allocatable :: horzcat_i21\n integer(kind = IPRE), dimension(:,:), intent(in) :: A1\n integer(kind = IPRE), dimension(:), intent(in) :: x2\n integer(kind = IPRE) :: m1, n1, m2\n\n m1 = size(A1, 1)\n n1 = size(A1, 2)\n m2 = size(x2)\n\n horzcat_i21 = zeros(max(m1, m2), n1+1)\n horzcat_i21(1:m1,1:n1) = A1\n horzcat_i21(1:m2,n1+1) = x2\n return\n end function horzcat_i21\n\n function horzcat_r21(A1, x2)\n real(kind = RPRE), dimension(:,:), allocatable :: horzcat_r21\n real(kind = RPRE), dimension(:,:), intent(in) :: A1\n real(kind = RPRE), dimension(:), intent(in) :: x2\n integer(kind = IPRE) :: m1, n1, m2\n\n m1 = size(A1, 1)\n n1 = size(A1, 2)\n m2 = size(x2)\n\n horzcat_r21 = zeros(max(m1, m2), n1+1)\n horzcat_r21(1:m1,1:n1) = A1\n horzcat_r21(1:m2,n1+1) = x2\n return\n end function horzcat_r21\n\n!=======================================================================\n! hann\n!-----------------------------------------------------------------------\n! hann defines a Hanning window.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! w = hann(n)\n!\n! Description\n!-----------------------------------------------------------------------\n! w = hann(n) returns an n-point symmetric Hanning window.\n!=======================================================================\n\n function hann(n)\n real(kind = RPRE), dimension(:), allocatable :: hann\n integer(kind = IPRE), intent(in) :: n\n\n hann = 0.5d0 * ( 1 - cos( 2.0d0 * pi * linspace(0, n-1, n) / n ) )\n return\n end function hann\n\n!=======================================================================\n! interp1\n!-----------------------------------------------------------------------\n! interp1 performs a linear interpolation.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! vq = interp1(x, v, xq)\n!\n! Description\n!-----------------------------------------------------------------------\n! vq = interp1(x, v, xq) returns the evaluated vector yq at the query\n! points in xq using a linear interpolation.\n!=======================================================================\n\n function interp1_0(x, v, xq) result(vq)\n real(kind = RPRE) :: vq\n real(kind = RPRE), intent(in) :: xq\n real(kind = RPRE), dimension(:), intent(in) :: x, v\n integer(kind = IPRE) :: i, x1, x2, ix(2)\n real(kind = RPRE) :: vn, xr(2), vr(2)\n\n x1 = minloc(xq - x, 1, mask = xq .ge. x)\n x2 = maxloc(xq - x, 1, mask = xq .lt. x)\n if ( x2 .ne. 0 ) then\n vn = abs( (x(x2) - x(x1)) )\n xr = x( [ x1, x2 ] )\n vr = v( [ x1, x2 ] )\n vq = vr(1) * ( xr(2) - xq ) + vr(2) * ( xq - xr(1) )\n vq = vq / vn\n else\n vq = v(size(v))\n end if\n return\n end function interp1_0\n\n function interp1_1(x, v, xq) result(vq)\n real(kind = RPRE), dimension(:), allocatable :: vq\n real(kind = RPRE), dimension(:), intent(in) :: xq, x, v\n integer(kind = IPRE) :: i, n\n\n n = size(xq)\n vq = zeros(n)\n do i = 1, n\n vq(i) = interp1_0(x, v, xq(i))\n end do\n return\n end function interp1_1\n\n!=======================================================================\n! interp2\n!-----------------------------------------------------------------------\n! interp2 performs a bilinear interpolation.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! vq = interp2(x, y, V, xq, yq)\n! VQ = interp2(x, y, V, XQ, YQ)\n!\n! Description\n!-----------------------------------------------------------------------\n! vq = interp2(x, y, V, xq, yq) returns the evaluated vector vq at the\n! query points in xq and yq using a bilinear interpolation.\n!\n! VQ = interp2(x, y, V, XQ, YQ) returns the evaluated matrix VQ given\n! mesh type grids XQ and YQ using a bilinear interpolation. VQ is of the\n! same shape as XQ and YQ.\n!=======================================================================\n\n function interp2_0(x, y, v, xq, yq) result(vq)\n real(kind = RPRE) :: vq\n real(kind = RPRE), intent(in) :: xq, yq\n real(kind = RPRE), dimension(:), intent(in) :: x, y\n real(kind = RPRE), dimension(:,:), intent(in) :: v\n integer(kind = IPRE) :: i, x1, y1, x2, y2, ix(4), iy(4)\n real(kind = RPRE) :: vn, xr(2), yr(2), N(4), vr(4)\n\n x1 = minloc(xq - x, 1, mask = xq .ge. x)\n y1 = minloc(yq - y, 1, mask = yq .ge. y)\n x2 = maxloc(xq - x, 1, mask = xq .lt. x)\n y2 = maxloc(yq - y, 1, mask = yq .lt. y)\n vn = abs( (x(x2) - x(x1)) &\n * (y(y2) - y(y1)) )\n xr = x( [ x1, x2 ] )\n yr = y( [ y1, y2 ] )\n ix = [ 2, 1, 2, 1 ]\n iy = [ 2, 2, 1, 1 ]\n do i = 1, 4\n N(i) = abs( (xr(ix(i)) - xq) * (yr(iy(i)) - yq) )\n end do\n vr = reshape(v( [ x1, x2 ], &\n [ y1, y2 ] ), shape = [ 4 ])\n vq = dot_product(vr, N/vn)\n return\n end function interp2_0\n\n function interp2_1(x, y, v, xq, yq) result(vq)\n real(kind = RPRE), dimension(:), allocatable :: vq\n real(kind = RPRE), dimension(:), intent(in) :: xq, yq, x, y\n real(kind = RPRE), dimension(:,:), intent(in) :: v\n integer(kind = IPRE) :: i, n\n\n n = size(xq)\n vq = zeros(n)\n do i = 1, n\n vq(i) = interp2_0(x, y, v, xq(i), yq(i))\n end do\n return\n end function interp2_1\n\n function interp2_2(x, y, v, xq, yq) result(vq)\n real(kind = RPRE), dimension(:,:), allocatable :: vq\n real(kind = RPRE), dimension(:), intent(in) :: x, y\n real(kind = RPRE), dimension(:,:), intent(in) :: v, xq, yq\n integer(kind = IPRE) :: m, n\n\n m = size(xq, 1)\n n = size(xq, 2)\n vq = reshape( interp2_1(y, x, v, [ yq ], [ xq ]), shape = [ m, n ] )\n return\n end function interp2_2\n\n!=======================================================================\n! interp3\n!-----------------------------------------------------------------------\n! interp3 performs a trilinear interpolation.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! vq = interp3(x, y, z, v, xq, yq, zq)\n!\n! Description\n!-----------------------------------------------------------------------\n! vq = interp3(x, y, z, v, xq, yq, zq) returns the evaluated vector vq\n! at the query points in xq, yq and zq using a trilinear interpolation.\n!=======================================================================\n\n function interp3_0(x, y, z, v, xq, yq, zq) result(vq)\n real(kind = RPRE) :: vq\n real(kind = RPRE), intent(in) :: xq, yq, zq\n real(kind = RPRE), dimension(:), intent(in) :: x, y, z\n real(kind = RPRE), dimension(:,:,:), intent(in) :: v\n integer(kind = IPRE) :: i, x1, y1, z1, x2, y2, z2, &\n ix(8), iy(8), iz(8)\n real(kind = RPRE) :: vn, xr(2), yr(2), zr(2), N(8), vr(8)\n\n x1 = minloc(xq - x, 1, mask = xq .ge. x)\n y1 = minloc(yq - y, 1, mask = yq .ge. y)\n z1 = minloc(zq - z, 1, mask = zq .ge. z)\n x2 = maxloc(xq - x, 1, mask = xq .lt. x)\n y2 = maxloc(yq - y, 1, mask = yq .lt. y)\n z2 = maxloc(zq - z, 1, mask = zq .lt. z)\n vn = abs( (x(x2) - x(x1)) &\n * (y(y2) - y(y1)) &\n * (z(z2) - z(z1)) )\n xr = x( [ x1, x2 ] )\n yr = y( [ y1, y2 ] )\n zr = z( [ z1, z2 ] )\n ix = [ 2, 1, 2, 1, 2, 1, 2, 1 ]\n iy = [ 2, 2, 1, 1, 2, 2, 1, 1 ]\n iz = [ 2, 2, 2, 2, 1, 1, 1, 1 ]\n do i = 1, 8\n N(i) = abs( (xr(ix(i)) - xq) * (yr(iy(i)) - yq) * (zr(iz(i)) - zq) )\n end do\n vr = reshape(v( [ x1, x2 ], &\n [ y1, y2 ], &\n [ z1, z2 ] ), shape = [ 8 ])\n vq = dot_product(vr, N/vn)\n return\n end function interp3_0\n\n function interp3_1(x, y, z, v, xq, yq, zq) result(vq)\n real(kind = RPRE), dimension(:), allocatable :: vq\n real(kind = RPRE), dimension(:), intent(in) :: xq, yq, zq, x, y, z\n real(kind = RPRE), dimension(:,:,:), intent(in) :: v\n integer(kind = IPRE) :: i, n\n\n n = size(xq)\n vq = zeros(n)\n do i = 1, n\n vq(i) = interp3_0(x, y, z, v, xq(i), yq(i), zq(i))\n end do\n return\n end function interp3_1\n\n!=======================================================================\n! inv\n!-----------------------------------------------------------------------\n! inv computes the matrix inverse.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! B = inv(A)\n!\n! Description\n!-----------------------------------------------------------------------\n! B = inv(A) returns the inverse of the matrix A if A is inversible\n! (det(A) /= 0.).\n!\n! Examples\n!-----------------------------------------------------------------------\n! A = reshape([ 1., 2., 3., 4., 5., 6., 7., 8., 0. ], [ 3, 3 ], &\n! order = [ 2, 1 ])\n! B = inv(A)\n! -1.77777779 0.888888896 -0.111111112\n! 1.55555558 -0.777777791 0.222222224\n! -0.11111112 0.222222224 -0.111111112\n!=======================================================================\n\n function inv(A)\n real(kind = RPRE), dimension(:,:), allocatable :: inv\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE) :: i, j, k, m\n real(kind = RPRE) :: D\n real(kind = RPRE), dimension(:), allocatable :: x, y, e\n real(kind = RPRE), dimension(:,:), allocatable :: L, U\n\n if (issquare(A)) then\n m = size(A, 1)\n if (m .le. 3) then\n D = det(A)\n else\n D = det(A, L, U)\n end if\n if (D .ne. 0.) then\n inv = zeros(m, m)\n if (m .eq. 2) then\n inv(1,1) = A(2,2)\n inv(1,2) = -A(1,2)\n inv(2,1) = -A(2,1)\n inv(2,2) = A(1,1)\n inv = inv/D\n elseif (m .eq. 3) then\n inv(1,1) = A(2,2)*A(3,3) - A(2,3)*A(3,2)\n inv(1,2) = A(1,3)*A(3,2) - A(1,2)*A(3,3)\n inv(1,3) = A(1,2)*A(2,3) - A(1,3)*A(2,2)\n inv(2,1) = A(2,3)*A(3,1) - A(2,1)*A(3,3)\n inv(2,2) = A(1,1)*A(3,3) - A(1,3)*A(3,1)\n inv(2,3) = A(1,3)*A(2,1) - A(1,1)*A(2,3)\n inv(3,1) = A(2,1)*A(3,2) - A(2,2)*A(3,1)\n inv(3,2) = A(1,2)*A(3,1) - A(1,1)*A(3,2)\n inv(3,3) = A(1,1)*A(2,2) - A(1,2)*A(2,1)\n inv = inv/D\n else\n do k = 1, m\n x = zeros(m)\n y = zeros(m)\n e = zeros(m)\n e(k) = 1.\n y(1) = e(1)\n\n ! Forward substitution: Ly = e\n !==============================\n do i = 2, m\n y(i) = e(i)\n do j = 1, i-1\n y(i) = y(i) - y(j)*L(i,j)\n end do\n end do\n\n ! Back substitution: Ux = y\n !===========================\n x(m) = y(m)/U(m,m)\n do i = m-1, 1, -1\n x(i) = y(i)\n do j = m, i+1, -1\n x(i) = x(i) - x(j)*U(i,j)\n end do\n x(i) = x(i)/U(i,i)\n end do\n\n ! The column k of the inverse is x\n !==================================\n inv(:,k) = x\n end do\n end if\n else\n stop \"Error: in det(A), A is not inversible (= 0).\"\n end if\n else\n stop \"Error: in inv(A), A should be square.\"\n end if\n return\n end function inv\n\n!=======================================================================\n! isleap\n!-----------------------------------------------------------------------\n! isleap determines whether a year is a leap year.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! bool = isleap(year)\n!\n! Description\n!-----------------------------------------------------------------------\n! bool = isleap(year) returns .true. if year is a leap year, .false.\n! otherwise.\n!\n! Examples\n!-----------------------------------------------------------------------\n! bool = isleap(2016)\n! .true.\n!=======================================================================\n\n logical function isleap(year)\n integer(kind = IPRE), intent(in) :: year\n if ( (mod(year, 400) .eq. 0) .or. &\n ((mod(year, 4) .eq. 0) .and. (mod(year, 100) .ne. 0)) ) then\n isleap = .true.\n else\n isleap = .false.\n end if\n return\n end function isleap\n\n!=======================================================================\n! ismember\n!-----------------------------------------------------------------------\n! ismember determines whether a value is present in an array.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! bool = ismember(x, y)\n! bool = ismember(x, A)\n! bool = ismember(x, Y)\n!\n! Description\n!-----------------------------------------------------------------------\n! bool = ismember(x, y) returns .true. if x is present in the\n! 1-dimensional array y, .false. otherwise.\n!\n! bool = ismember(x, A) returns .true. if x is present in the\n! 2-dimensional array A, .false. otherwise.\n!\n! bool = ismember(x, Y) returns .true. if x is present in the\n! 3-dimensional array Y, .false. otherwise.\n!\n! Examples\n!-----------------------------------------------------------------------\n! y = [ 1., 2., 3., 4., 5. ]\n! bool = ismember(3., y)\n! .true.\n! bool = ismember(6., y)\n! .false.\n!=======================================================================\n\n logical function ismember_i0i1(x, y)\n integer(kind = IPRE), intent(in) :: x\n integer(kind = IPRE), dimension(:), intent(in) :: y\n integer(kind = IPRE) :: i, dim1\n\n ismember_i0i1 = .false.\n dim1 = size(y)\n do i = 1, dim1\n if (x .eq. y(i)) then\n ismember_i0i1 = .true.\n return\n end if\n end do\n return\n end function ismember_i0i1\n\n logical function ismember_i0r1(x, y)\n integer(kind = IPRE), intent(in) :: x\n real(kind = RPRE), dimension(:), intent(in) :: y\n integer(kind = IPRE) :: i, dim1\n\n ismember_i0r1 = .false.\n dim1 = size(y)\n do i = 1, dim1\n if (x .eq. y(i)) then\n ismember_i0r1 = .true.\n return\n end if\n end do\n return\n end function ismember_i0r1\n\n logical function ismember_i0i2(x, A)\n integer(kind = IPRE), intent(in) :: x\n integer(kind = IPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE) :: i, j, dim1, dim2\n\n ismember_i0i2 = .false.\n dim1 = size(A, 1)\n dim2 = size(A, 2)\n do i = 1, dim1\n do j = 1, dim2\n if (x .eq. A(i,j)) then\n ismember_i0i2 = .true.\n return\n end if\n end do\n end do\n return\n end function ismember_i0i2\n\n logical function ismember_i0r2(x, A)\n integer(kind = IPRE), intent(in) :: x\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE) :: i, j, dim1, dim2\n\n ismember_i0r2 = .false.\n dim1 = size(A, 1)\n dim2 = size(A, 2)\n do i = 1, dim1\n do j = 1, dim2\n if (x .eq. A(i,j)) then\n ismember_i0r2 = .true.\n return\n end if\n end do\n end do\n return\n end function ismember_i0r2\n\n logical function ismember_i0i3(x, Y)\n integer(kind = IPRE), intent(in) :: x\n integer(kind = IPRE), dimension(:,:,:), intent(in) :: Y\n integer(kind = IPRE) :: i, j, k, dim1, dim2, dim3\n\n ismember_i0i3 = .false.\n dim1 = size(Y, 1)\n dim2 = size(Y, 2)\n dim3 = size(Y, 3)\n do i = 1, dim1\n do j = 1, dim2\n do k = 1, dim2\n if (x .eq. Y(i,j,k)) then\n ismember_i0i3 = .true.\n return\n end if\n end do\n end do\n end do\n return\n end function ismember_i0i3\n\n logical function ismember_i0r3(x, Y)\n integer(kind = IPRE), intent(in) :: x\n real(kind = RPRE), dimension(:,:,:), intent(in) :: Y\n integer(kind = IPRE) :: i, j, k, dim1, dim2, dim3\n\n ismember_i0r3 = .false.\n dim1 = size(Y, 1)\n dim2 = size(Y, 2)\n dim3 = size(Y, 3)\n do i = 1, dim1\n do j = 1, dim2\n do k = 1, dim2\n if (x .eq. Y(i,j,k)) then\n ismember_i0r3 = .true.\n return\n end if\n end do\n end do\n end do\n return\n end function ismember_i0r3\n\n logical function ismember_r0i1(x, y)\n real(kind = RPRE), intent(in) :: x\n integer(kind = IPRE), dimension(:), intent(in) :: y\n integer(kind = IPRE) :: i, dim1\n\n ismember_r0i1 = .false.\n dim1 = size(y)\n do i = 1, dim1\n if (x .eq. y(i)) then\n ismember_r0i1 = .true.\n return\n end if\n end do\n return\n end function ismember_r0i1\n\n logical function ismember_r0r1(x, y)\n real(kind = RPRE), intent(in) :: x\n real(kind = RPRE), dimension(:), intent(in) :: y\n integer(kind = IPRE) :: i, dim1\n\n ismember_r0r1 = .false.\n dim1 = size(y)\n do i = 1, dim1\n if (x .eq. y(i)) then\n ismember_r0r1 = .true.\n return\n end if\n end do\n return\n end function ismember_r0r1\n\n logical function ismember_r0i2(x, A)\n real(kind = RPRE), intent(in) :: x\n integer(kind = IPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE) :: i, j, dim1, dim2\n\n ismember_r0i2 = .false.\n dim1 = size(A, 1)\n dim2 = size(A, 2)\n do i = 1, dim1\n do j = 1, dim2\n if (x .eq. A(i,j)) then\n ismember_r0i2 = .true.\n return\n end if\n end do\n end do\n return\n end function ismember_r0i2\n\n logical function ismember_r0r2(x, A)\n real(kind = RPRE), intent(in) :: x\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE) :: i, j, dim1, dim2\n\n ismember_r0r2 = .false.\n dim1 = size(A, 1)\n dim2 = size(A, 2)\n do i = 1, dim1\n do j = 1, dim2\n if (x .eq. A(i,j)) then\n ismember_r0r2 = .true.\n return\n end if\n end do\n end do\n return\n end function ismember_r0r2\n\n logical function ismember_r0i3(x, Y)\n real(kind = RPRE), intent(in) :: x\n integer(kind = IPRE), dimension(:,:,:), intent(in) :: Y\n integer(kind = IPRE) :: i, j, k, dim1, dim2, dim3\n\n ismember_r0i3 = .false.\n dim1 = size(Y, 1)\n dim2 = size(Y, 2)\n dim3 = size(Y, 3)\n do i = 1, dim1\n do j = 1, dim2\n do k = 1, dim2\n if (x .eq. Y(i,j,k)) then\n ismember_r0i3 = .true.\n return\n end if\n end do\n end do\n end do\n return\n end function ismember_r0i3\n\n logical function ismember_r0r3(x, Y)\n real(kind = RPRE), intent(in) :: x\n real(kind = RPRE), dimension(:,:,:), intent(in) :: Y\n integer(kind = IPRE) :: i, j, k, dim1, dim2, dim3\n\n ismember_r0r3 = .false.\n dim1 = size(Y, 1)\n dim2 = size(Y, 2)\n dim3 = size(Y, 3)\n do i = 1, dim1\n do j = 1, dim2\n do k = 1, dim2\n if (x .eq. Y(i,j,k)) then\n ismember_r0r3 = .true.\n return\n end if\n end do\n end do\n end do\n return\n end function ismember_r0r3\n\n!=======================================================================\n! isoutlier\n!-----------------------------------------------------------------------\n! isoutlier determines outliers in a vector.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! bool = isoutlier(x)\n!\n! Description\n!-----------------------------------------------------------------------\n! bool = isoutlier(x) returns a logical vector with .true. if x(i) is\n! an outlier, .false. otherwise.\n!=======================================================================\n\n function isoutlier(x, m)\n logical, dimension(:), allocatable :: isoutlier\n real(kind = RPRE), dimension(:), intent(in) :: x\n integer(kind = IPRE), intent(in), optional :: m\n integer(kind = IPRE) :: opt_m\n\n opt_m = 3\n if (present(m)) opt_m = m\n isoutlier = abs(x - median(x)) .gt. opt_m*mad(x, 2)\n return\n end function isoutlier\n\n!=======================================================================\n! issquare\n!-----------------------------------------------------------------------\n! issquare determines whether a matrix is square.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! bool = issquare(A)\n!\n! Description\n!-----------------------------------------------------------------------\n! bool = issquare(A) returns .true. if A is square, .false. otherwise.\n!\n! Examples\n!-----------------------------------------------------------------------\n! A = eye(3)\n! bool = issquare(A)\n! .true.\n!\n! A = eye(3, 4)\n! bool = issquare(A)\n! .false.\n!=======================================================================\n\n logical function issquare(A)\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n\n issquare = .false.\n if (size(A, 1) .eq. size(A, 2)) issquare = .true.\n return\n end function issquare\n\n!=======================================================================\n! issymmetric\n!-----------------------------------------------------------------------\n! issymmetric determines whether a square matrix is symmetric.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! bool = issymmetric(A)\n!\n! Description\n!-----------------------------------------------------------------------\n! bool = issymmetric(A) returns .true. if A is symmetric, .false.\n! otherwise.\n!\n! Examples\n!-----------------------------------------------------------------------\n! A = eye(3)\n! bool = issymmetric(A)\n! .true.\n!=======================================================================\n\n logical function issymmetric(A)\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE) :: i, j, n\n\n issymmetric = .true.\n if (.not. issquare(A)) then\n issymmetric = .false.\n return\n else\n n = size(A, 1)\n do i = 1, n\n do j = 1, n\n if ( A(i,j) .ne. A(j,i) ) then\n issymmetric = .false.\n return\n end if\n end do\n end do\n end if\n return\n end function issymmetric\n\n!=======================================================================\n! k2test\n!-----------------------------------------------------------------------\n! k2test performs the D'Agostino-Pearson's K2 test to assess normality\n! of a distribution.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! p = k2test(x)\n!\n! Description\n!-----------------------------------------------------------------------\n! p = k2test(x) returns the p-value for the null hypothesis that the\n! data in vector x comes from a normal distribution. According to\n! Fisher, the null hypothesis is highly rejectable for p-values lower\n! that 0.05.\n!\n! Examples\n!-----------------------------------------------------------------------\n! x = randn(1000)\n! p1 = k2test(x)\n! 0.551972866 ! > 0.05\n!\n! y = randu(1000)\n! p2 = k2test(y)\n! 0.000000000 ! < 0.05\n!\n! Notes\n!-----------------------------------------------------------------------\n! The K2 statistic has approximately a chi-squared distribution with\n! k = 2 degrees of freedom when the population is normally distributed.\n! The CDF of the chi-squared with 2 degrees of freedom can be written:\n! F(x,2) = 1 - exp(-x/2)\n!=======================================================================\n\n function k2test(x) result(p)\n real(kind = RPRE) :: p\n real(kind = RPRE), dimension(:), intent(in) :: x\n integer(kind = 8) :: n\n real(kind = 8) :: b1, b2, K2\n real(kind = 8) :: Y, beta2, W2, delta, alpha, Z1\n real(kind = 8) :: E, v2, xx, beta1, A, Z2\n\n n = size(x)\n b1 = skewness(x)\n b2 = kurtosis(x)\n\n ! Skewness test\n !===============\n Y = b1 * sqrt( (n+1.)*(n+3.) / ( 6.*(n-2.) ) )\n beta2 = 3. * (n*n+27.*n-70.)*(n+1.)*(n+3.) / ( (n-2.)*(n+5.)*(n+7.)*(n+9.) )\n W2 = -1. + sqrt( 2.*(beta2-1.) )\n delta = 1. / sqrt( 0.5*log(W2) )\n alpha = sqrt( 2. / (W2-1.) )\n Z1 = delta * log( Y/alpha + sqrt( (Y/alpha)**2 + 1.) )\n\n ! Kurtosis test\n !===============\n E = 3. * (n-1.) / (n+1.)\n v2 = 24. * n*(n-2.)*(n-3.) / ( (n+1.)**2*(n+3.)*(n+5.) )\n xx = (b2-E) / sqrt(v2)\n beta1 = 6. * (n**2-5.*n+2.) / ( (n+7.)*(n+9.) ) &\n * sqrt( 6. * (n+3.)*(n+5.) / ( n*(n-2.)*(n-3.) ) )\n A = 6. + 8./beta1 * ( 2./beta1 + sqrt( 1. + 4./(beta1*beta1) ) )\n Z2 = ( (1.-2./(9.*A)) - ( (1.-2./A) / (1.+xx*sqrt( 2./(A-4.) )) )**(1./3.) ) &\n / sqrt( 2./(9.*A) )\n\n ! Omnibus test\n !==============\n K2 = Z1*Z1 + Z2*Z2\n p = exp(-0.5*K2)\n\n return\n end function k2test\n\n!=======================================================================\n! kde\n!-----------------------------------------------------------------------\n! kde computes the kernel density estimation assuming Gaussian kernels\n! for univariate and bivariate data. The default bandwidth is calculated\n! using Silverman's rule of thumb.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! call kde(x, f, xi)\n! call kde(x, f, xi, bw)\n! call kde(A, f, xi, yi)\n! call kde(A, f, xi, yi, H)\n!\n! Description\n!-----------------------------------------------------------------------\n! call kde(x, f, xi) returns the probability density estimation f at\n! points xi for the sample data in the vector x.\n!\n! call kde(x, f, xi, bw) returns the PDE f at points xi using the kernel\n! bandwidth bw.\n!\n! call kde(A, f, xi, yi) returns the PDE f at points xi and yi.\n!\n! call kde(A, f, xi, yi, H) returns the PDE f at points xi and yi using\n! the bandwidth H.\n!=======================================================================\n\n subroutine kde1(x, f, xi, bw)\n real(kind = RPRE), dimension(:), intent(in) :: x\n real(kind = RPRE), dimension(:), allocatable, intent(out) :: f\n real(kind = RPRE), dimension(:), allocatable, intent(inout), optional :: xi\n real(kind = RPRE), intent(in), optional :: bw\n integer(kind = IPRE) :: ix, j, n, nx\n real(kind = RPRE) :: opt_bw\n real(kind = RPRE), dimension(:), allocatable :: opt_xi\n\n n = size(x)\n opt_bw = ( 4.*std(x)**5 / (3.*n) )**0.2\n if (present(bw)) opt_bw = bw\n if (present(xi) .and. allocated(xi)) then\n nx = size(xi)\n opt_xi = xi\n else\n nx = 100\n opt_xi = linspace(minval(x)-3*opt_bw, maxval(x)+3*opt_bw, nx)\n end if\n\n f = zeros(nx)\n do ix = 1, nx\n do j = 1, n\n f(ix) = f(ix) + exp( -0.5 * ( ( opt_xi(ix) - x(j) ) / opt_bw )**2 )\n end do\n end do\n f = 0.3989422804014327 * f / ( n * opt_bw )\n\n if (present(xi) .and. .not. allocated(xi)) xi = opt_xi\n return\n end subroutine kde1\n\n subroutine kde2(A, f, xi, yi, H)\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n real(kind = RPRE), dimension(:,:), allocatable, intent(out) :: f\n real(kind = RPRE), dimension(:), allocatable, intent(inout), optional :: xi, yi\n real(kind = RPRE), dimension(:,:), intent(in), optional :: H\n integer(kind = IPRE) :: ix, iy, j, n, nx, ny\n real(kind = RPRE) :: opt_H(2,2), invH(2,2), x(2)\n real(kind = RPRE), dimension(:), allocatable :: opt_xi, opt_yi\n\n n = size(A, 1)\n if (present(H)) then\n opt_H = H\n else\n opt_H = cov(A) * n**(-1./3.) ! Squared\n end if\n if (present(xi) .and. allocated(xi)) then\n nx = size(xi)\n opt_xi = xi\n else\n nx = 100\n opt_xi = linspace(minval(A(:,1))-3*opt_H(1,1), maxval(A(:,1))+3*opt_H(1,1), nx)\n end if\n if (present(yi) .and. allocated(yi)) then\n ny = size(yi)\n opt_yi = yi\n else\n ny = 100\n opt_yi = linspace(minval(A(:,2))-3*opt_H(2,2), maxval(A(:,2))+3*opt_H(2,2), ny)\n end if\n\n invH = inv(opt_H)\n f = zeros(nx, ny)\n do ix = 1, nx\n do iy = 1, ny\n do j = 1, n\n x = [ opt_xi(ix), opt_yi(iy) ] - [ A(j,:) ]\n f(ix,iy) = f(ix,iy) + exp( -0.5 * dot_product(matmul(x, invH), x) )\n end do\n end do\n end do\n f = f / ( sqrt( det( real(2.*pi, RPRE) * opt_H ) ) * real(n, RPRE) )\n\n if (present(xi) .and. .not. allocated(xi)) xi = opt_xi\n if (present(yi) .and. .not. allocated(yi)) yi = opt_yi\n return\n end subroutine kde2\n\n!=======================================================================\n! kurtosis\n!-----------------------------------------------------------------------\n! kurtosis computes vector and matrix kurtosis.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! y = kurtosis(x)\n! y = kurtosis(x, flag)\n! x = kurtosis(A)\n! x = kurtosis(A, flag)\n! x = kurtosis(A, 1)\n! x = kurtosis(A, flag, 1)\n! x = kurtosis(A, 2)\n! x = kurtosis(A, flag, 2)\n!\n! Description\n!-----------------------------------------------------------------------\n! y = kurtosis(x) returns the kurtosis of the vector x.\n!\n! y = kurtosis(x, w) returns the kurtosis of the vector x given the\n! flag. By default, flag is 1. If flag is 0, the function corrects for\n! the systematic bias due to the size of the sample.\n!\n! x = kurtosis(A) returns a dim2 vector with the kurtosis of each\n! column of matrix A.\n!\n! x = kurtosis(A, flag) returns a dim2 vector given the flag.\n!\n! x = kurtosis(A, 1) (see x = kurtosis(A)).\n!\n! x = kurtosis(A, flag, 1) (see x = kurtosis(A, flag))\n!\n! x = kurtosis(A, 2) returns a dim1 vector with the kurtosis of\n! each row of matrix A.\n!\n! x = kurtosis(A, flag, 2) returns a dim1 vector given the flag.\n!=======================================================================\n\n real(kind = RPRE) function kurtosis1(x, flag)\n real(kind = RPRE), dimension(:), intent(in) :: x\n integer(kind = IPRE), intent(in), optional :: flag\n integer(kind = IPRE) :: opt_flag, n\n\n opt_flag = 1\n if (present(flag)) opt_flag = flag\n\n n = size(x)\n kurtosis1 = ( sum( ( x - mean(x) )**4 ) / n ) / ( var(x, 1)**2 )\n if (opt_flag .eq. 0) then\n kurtosis1 = (n-1)/((n-2)*(n-3)) * ((n+1)*kurtosis1-3*(n-1)) + 3\n end if\n return\n end function kurtosis1\n\n function kurtosis2(A, flag, dim)\n real(kind = RPRE), dimension(:), allocatable :: kurtosis2\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE), intent(in), optional :: flag, dim\n integer(kind = IPRE) :: opt_flag, i, m, n\n\n opt_flag = 1\n if (present(flag)) opt_flag = flag\n\n m = size(A, 1)\n n = size(A, 2)\n if ((.not. present(dim)) .or. (dim .eq. 1)) then\n allocate(kurtosis2(n))\n do i = 1, n\n kurtosis2(i) = kurtosis1(A(:,i), opt_flag)\n end do\n elseif (dim .eq. 2) then\n allocate(kurtosis2(m))\n do i = 1, m\n kurtosis2(i) = kurtosis1(A(i,:), opt_flag)\n end do\n end if\n return\n end function kurtosis2\n\n!=======================================================================\n! linspace\n!-----------------------------------------------------------------------\n! linspace creates a linearly spaced vector.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! x = linspace(x1, x2, n)\n!\n! Description\n!-----------------------------------------------------------------------\n! x = linspace(x1, x2, n) returns a vector of n evenly spaced points\n! between x1 and x2.\n!\n! Examples\n!-----------------------------------------------------------------------\n! x = linspace(0, 10, 11)\n! 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10.\n!=======================================================================\n\n function linspace_r8r8(first, last, n)\n real(kind = RPRE), dimension(:), allocatable :: linspace_r8r8\n real(kind = 8), intent(in) :: first, last\n integer(kind = IPRE), intent(in) :: n\n integer(kind = IPRE) :: i\n real(kind = 8) :: step\n\n allocate(linspace_r8r8(n))\n step = ( last - first ) / ( n-1 )\n linspace_r8r8 = first + step * real([ ( i-1, i = 1, n ) ], RPRE)\n return\n end function linspace_r8r8\n\n function linspace_r4r4(first, last, n)\n real(kind = RPRE), dimension(:), allocatable :: linspace_r4r4\n real(kind = 4), intent(in) :: first, last\n integer(kind = IPRE), intent(in) :: n\n\n linspace_r4r4 = linspace(real(first, kind = 8), real(last, kind = 8), n)\n return\n end function linspace_r4r4\n\n function linspace_i4i4(first, last, n)\n real(kind = RPRE), dimension(:), allocatable :: linspace_i4i4\n integer(kind = 4), intent(in) :: first, last\n integer(kind = IPRE), intent(in) :: n\n\n linspace_i4i4 = linspace(real(first, kind = 8), real(last, kind = 8), n)\n return\n end function linspace_i4i4\n\n function linspace_r8i4(first, last, n)\n real(kind = RPRE), dimension(:), allocatable :: linspace_r8i4\n real(kind = 8), intent(in) :: first\n integer(kind = 4), intent(in) :: last\n integer(kind = IPRE), intent(in) :: n\n\n linspace_r8i4 = linspace(first, real(last, kind = 8), n)\n return\n end function linspace_r8i4\n\n function linspace_r4i4(first, last, n)\n real(kind = RPRE), dimension(:), allocatable :: linspace_r4i4\n real(kind = 4), intent(in) :: first\n integer(kind = 4), intent(in) :: last\n integer(kind = IPRE), intent(in) :: n\n\n linspace_r4i4 = linspace(real(first, kind = 8), real(last, kind = 8), n)\n return\n end function linspace_r4i4\n\n function linspace_i4r8(first, last, n)\n real(kind = RPRE), dimension(:), allocatable :: linspace_i4r8\n integer(kind = 4), intent(in) :: first\n real(kind = 8), intent(in) :: last\n integer(kind = IPRE), intent(in) :: n\n\n linspace_i4r8 = linspace(real(first, kind = 8), last, n)\n return\n end function linspace_i4r8\n\n function linspace_i4r4(first, last, n)\n real(kind = RPRE), dimension(:), allocatable :: linspace_i4r4\n integer(kind = 4), intent(in) :: first\n real(kind = 4), intent(in) :: last\n integer(kind = IPRE), intent(in) :: n\n\n linspace_i4r4 = linspace(real(first, kind = 8), real(last, kind = 8), n)\n return\n end function linspace_i4r4\n\n!=======================================================================\n! loadbin\n!-----------------------------------------------------------------------\n! loadbin loads binary files.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! x = loadbin(filename)\n! x = loadbin(filename, kind)\n! x = loadbin(filename, kind, dim1)\n! A = loadbin(filename, kind, dim1, dim2)\n! X = loadbin(filename, kind, dim1, dim2, dim3)\n!\n! Description\n!-----------------------------------------------------------------------\n! x = loadbin(filename) loads a 1-dimensional array into x from the\n! binary file filename treated as 32 bytes floating points.\n!\n! x = loadbin(filename, kind) loads a 1-dimensional array into x from\n! the binary file filename.\n!\n! x = loadbin(filename, kind, dim1) loads a 1-dimensional array into x\n! from the binary file filename.\n!\n! A = loadbin(filename, kind, dim1, dim2) loads a 2-dimensional array\n! into A from the binary file filename.\n!\n! X = loadbin(filename, kind, dim1, dim2, dim3) loads a 3-dimensional\n! array into X from the binary file filename.\n!\n! Notes\n!-----------------------------------------------------------------------\n! Make sure to use the exact kind:\n! - 4 for 32 bytes floating points,\n! - 8 for 64 bytes floating points.\n!=======================================================================\n\n function loadbin0(filename, kind)\n real(kind = RPRE), dimension(:), allocatable :: loadbin0\n character(len = *), intent(in) :: filename\n integer(kind = IPRE), intent(in), optional :: kind\n integer(kind = IPRE) :: opt_kind, dim1, fs\n real(kind = 4), dimension(:), allocatable :: tmp4\n real(kind = 8), dimension(:), allocatable :: tmp8\n type(File) :: infile\n\n opt_kind = 4\n if (present(kind)) opt_kind = kind\n\n infile = File(999, trim(filename))\n if ( infile % exist() ) then\n inquire(file = filename, size = fs)\n select case(opt_kind)\n case(4)\n if ( mod(fs, 4) .eq. 0 ) then\n dim1 = fs / 4\n allocate(tmp4(dim1), loadbin0(dim1))\n call infile % open(4*dim1)\n read(infile % unit, rec = 1) tmp4\n call infile % close()\n loadbin0 = tmp4\n else\n print *, \"Error: in loadbin, file size mismatches kind.\"\n stop\n end if\n case(8)\n if ( mod(fs, 8) .eq. 0 ) then\n dim1 = fs / 8\n allocate(tmp8(dim1), loadbin0(dim1))\n call infile % open(8*dim1)\n read(infile % unit, rec = 1) tmp8\n call infile % close()\n loadbin0 = tmp8\n else\n print *, \"Error: in loadbin, file size mismatches kind.\"\n stop\n end if\n end select\n else\n print *, \"Error: '\" // trim(filename) // \"' not found\"\n stop\n end if\n return\n end function loadbin0\n\n function loadbin1(filename, kind, dim1)\n real(kind = RPRE), dimension(:), allocatable :: loadbin1\n character(len = *), intent(in) :: filename\n integer(kind = IPRE), intent(in) :: kind, dim1\n real(kind = 4), dimension(:), allocatable :: tmp4\n real(kind = 8), dimension(:), allocatable :: tmp8\n type(File) :: infile\n\n infile = File(999, trim(filename))\n if ( infile % exist() ) then\n allocate(loadbin1(dim1))\n select case(kind)\n case(4)\n allocate(tmp4(dim1))\n call infile % open(4*dim1)\n read(infile % unit, rec = 1) tmp4\n call infile % close()\n loadbin1 = tmp4\n case(8)\n allocate(tmp8(dim1))\n call infile % open(8*dim1)\n read(infile % unit, rec = 1) tmp8\n call infile % close()\n loadbin1 = tmp8\n end select\n else\n print *, \"Error: '\" // trim(filename) // \"' not found\"\n stop\n end if\n return\n end function loadbin1\n\n function loadbin2(filename, kind, dim1, dim2)\n real(kind = RPRE), dimension(:,:), allocatable :: loadbin2\n character(len = *), intent(in) :: filename\n integer(kind = IPRE), intent(in) :: kind, dim1, dim2\n real(kind = 4), dimension(:,:), allocatable :: tmp4\n real(kind = 8), dimension(:,:), allocatable :: tmp8\n type(File) :: infile\n\n infile = File(999, trim(filename))\n if ( infile % exist() ) then\n allocate(loadbin2(dim1, dim2))\n select case(kind)\n case(4)\n allocate(tmp4(dim1, dim2))\n call infile % open(4*dim1*dim2)\n read(infile % unit, rec = 1) tmp4\n call infile % close()\n loadbin2 = tmp4\n case(8)\n allocate(tmp8(dim1, dim2))\n call infile % open(8*dim1*dim2)\n read(infile % unit, rec = 1) tmp8\n call infile % close()\n loadbin2 = tmp8\n end select\n else\n print *, \"Error: '\" // trim(filename) // \"' not found\"\n stop\n end if\n return\n end function loadbin2\n\n function loadbin3(filename, kind, dim1, dim2, dim3)\n real(kind = RPRE), dimension(:,:,:), allocatable :: loadbin3\n character(len = *), intent(in) :: filename\n integer(kind = IPRE), intent(in) :: kind, dim1, dim2, dim3\n real(kind = 4), dimension(:,:,:), allocatable :: tmp4\n real(kind = 8), dimension(:,:,:), allocatable :: tmp8\n type(File) :: infile\n\n infile = File(999, trim(filename))\n if ( infile % exist() ) then\n allocate(loadbin3(dim1, dim2, dim3))\n select case(kind)\n case(4)\n allocate(tmp4(dim1, dim2, dim3))\n call infile % open(4*dim1*dim2*dim3)\n read(infile % unit, rec = 1) tmp4\n call infile % close()\n loadbin3 = tmp4\n case(8)\n allocate(tmp8(dim1, dim2, dim3))\n call infile % open(8*dim1*dim2*dim3)\n read(infile % unit, rec = 1) tmp8\n call infile % close()\n loadbin3 = tmp8\n end select\n else\n print *, \"Error: '\" // trim(filename) // \"' not found\"\n stop\n end if\n return\n end function loadbin3\n\n!=======================================================================\n! loadtxt\n!-----------------------------------------------------------------------\n! loadtxt loads txt files.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! x = loadtxt(filename)\n! A = loadtxt(filename, dim2)\n!\n! Description\n!-----------------------------------------------------------------------\n! x = loadtxt(filename) loads a 1-dimensional array into x from a txt\n! file filename.\n!\n! A = loadtxt(filename, dim2) loads a 2-dimensional array into A from a\n! txt file filename. dim2 indicates the number of columns of the array.\n!=======================================================================\n\nfunction loadtxt1(filename)\n real(kind = RPRE), dimension(:), allocatable :: loadtxt1\n character(len = *), intent(in) :: filename\n integer(kind = IPRE) :: i, m\n type(File) :: infile\n\n infile = File(999, trim(filename))\n if ( infile % exist() ) then\n m = infile % countlines()\n allocate(loadtxt1(m))\n call infile % open()\n do i = 1, m\n read(infile % unit, *) loadtxt1(i)\n end do\n call infile % close()\n else\n print *, \"Error: '\" // trim(filename) // \"' not found\"\n stop\n end if\n return\nend function loadtxt1\n\nfunction loadtxt2(filename, dim2)\n real(kind = RPRE), dimension(:,:), allocatable :: loadtxt2\n character(len = *), intent(in) :: filename\n integer(kind = IPRE), intent(in) :: dim2\n integer(kind = IPRE) :: i, j, m\n type(File) :: infile\n\n infile = File(999, trim(filename))\n if ( infile % exist() ) then\n m = infile % countlines()\n allocate(loadtxt2(m, dim2))\n call infile % open()\n do i = 1, m\n read(infile % unit, *) (loadtxt2(i,j), j = 1, dim2)\n end do\n call infile % close()\n else\n print *, \"Error: '\" // trim(filename) // \"' not found\"\n stop\n end if\n return\nend function loadtxt2\n\n!=======================================================================\n! log2\n!-----------------------------------------------------------------------\n! log2 computes the base 2 logarithm.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! y = log2(x)\n! Y = log2(X)\n!\n! Description\n!-----------------------------------------------------------------------\n! y = log2(x) returns the base 2 logarithm of x.\n!\n! Y = log2(X) returns a vector Y with the base 2 logarithm of the\n! elements in X.\n!\n! Examples\n!-----------------------------------------------------------------------\n! y = log2(arange(1, 10))\n! 0.000 1.000 1.585 2.000 2.322 2.585 2.807 3.000 3.170 3.322\n!\n! m = mod(log2([ 16, 17 ]), 1.)\n! 0. 0.0875\n!\n! Note\n!-----------------------------------------------------------------------\n! The latter example shows how log2 can be used to tell whether a number\n! is a power of 2. Fortran intrinsic binary substraction function iand\n! can also be used for this purpose.\n!=======================================================================\n\n real(kind = RPRE) function log2_i0(x)\n integer(kind = IPRE), intent(in) :: x\n\n log2_i0 = log(real(x)) / log(2.0d0)\n return\n end function log2_i0\n\n real(kind = RPRE) function log2_r0(x)\n real(kind = RPRE), intent(in) :: x\n\n log2_r0 = log(x) / log(2.0d0)\n return\n end function log2_r0\n\n function log2_i1(x)\n real(kind = RPRE), dimension(:), allocatable :: log2_i1\n integer(kind = IPRE), dimension(:), intent(in) :: x\n\n log2_i1 = log(real(x)) / log(2.0d0)\n return\n end function log2_i1\n\n function log2_r1(x)\n real(kind = RPRE), dimension(:), allocatable :: log2_r1\n real(kind = RPRE), dimension(:), intent(in) :: x\n\n log2_r1 = log(x) / log(2.0d0)\n return\n end function log2_r1\n\n!=======================================================================\n! lsweight\n!-----------------------------------------------------------------------\n! lsweight computes the least-square inversion weights.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! W = lsweight(r, \"none\")\n! W = lsweight(r, \"biweight\")\n!\n! Description\n!-----------------------------------------------------------------------\n! W = lsweight(r, \"none\") returns the identity matrix.\n!\n! W = lsweight(r, \"biweight\") returns the weights using a biweight norm.\n!=======================================================================\n\n function lsweight(r, ntype)\n real(kind = RPRE), dimension(:,:), allocatable :: lsweight\n real(kind = RPRE), dimension(:), intent(in) :: r\n character(len = *), intent(in) :: ntype\n integer(kind = IPRE) :: i, n\n real(kind = RPRE) :: eps\n\n eps = 4.685d0 * mad(r, 2) / 0.6745d0\n n = size(r)\n if ((eps .eq. 0.0d0) .or. (ntype .eq. \"none\")) then\n lsweight = eye(n)\n elseif (ntype .eq. \"biweight\") then\n lsweight = zeros(n, n)\n do i = 1, n\n if (abs(r(i)) .le. eps) lsweight(i,i) = (1.0d0 - (r(i)/eps)**2)**2\n end do\n end if\n return\n end function lsweight\n\n!=======================================================================\n! lu\n!-----------------------------------------------------------------------\n! lu computes the LU matrix factorization.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! call lu(A, L, U)\n!\n! Description\n!-----------------------------------------------------------------------\n! call lu(A, L, U) returns the LU matrix factorization of the input\n! square m-by-m matrix A. The output matrices are:\n! - L is a m-by-m lower triangular matrix with ones on the diagonal,\n! - U is a m-by-m upper triangular matrix.\n!\n! Examples\n!-----------------------------------------------------------------------\n! A = reshape([ 1., 2., 3., 4., 5., 6., 7., 8., 9. ], [ 3, 3 ], &\n! order = [ 2, 1 ])\n! call lu(A, L, U)\n! call disp(L)\n! 1. 0. 0.\n! 4. 1. 0.\n! 7. 2. 1.\n! call disp(U)\n! 1. 2. 3.\n! 0. -3. -6.\n! 0. 0. 0.\n! call disp(matmul(L, U))\n! 1. 2. 3.\n! 4. 5. 6.\n! 7. 8. 9.\n!=======================================================================\n\n subroutine lu(A, L, U)\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n real(kind = RPRE), dimension(:,:), allocatable, intent(out) :: L, U\n integer(kind = IPRE) :: i, j, k, m\n\n if (issquare(A)) then\n m = size(A, 1)\n if (.not. allocated(L)) L = eye(m)\n if (.not. allocated(U)) U = zeros(m, m)\n\n do i = 1, m\n do j = 1, m\n U(i,j) = A(i,j)\n do k = 1, i-1\n U(i,j) = U(i,j) - L(i,k)*U(k,j)\n end do\n end do\n do j = i+1, m\n L(j,i) = A(j,i)\n do k = 1, i-1\n L(j,i) = L(j,i) - L(j,k)*U(k,i)\n end do\n L(j,i) = L(j,i)/U(i,i)\n end do\n end do\n else\n stop \"Error: in A = LU, A should be square.\"\n end if\n return\n end subroutine lu\n\n!=======================================================================\n! kmeans\n!-----------------------------------------------------------------------\n! kmeans performs K-means clustering.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! idx = kmeans(x, K, [options = ])\n! idx = kmeans(A, K, [options = ])\n!\n! Description\n!-----------------------------------------------------------------------\n! idx = kmeans(x, K, [options = ]) returns the cluster indices of each\n! element in vector x.\n!\n! idx = kmeans(A, K, [options = ]) returns the cluster indices of each\n! rows in matrix A.\n!\n! Options\n!-----------------------------------------------------------------------\n! means Output centroids\n! init Initial centroids\n! itermax = 1000 Maximum number of iterations\n! niter Output number of iterations\n!\n! Notes\n!-----------------------------------------------------------------------\n! By default, initials centroids are randomly chosen among data points.\n!=======================================================================\n\n function kmeans1(x, K, means, init, itermax, niter) result(idx)\n integer(kind = IPRE), dimension(:), allocatable :: idx\n real(kind = RPRE), dimension(:), intent(in) :: x\n integer(kind = IPRE), intent(in) :: K\n real(kind = RPRE), dimension(:), intent(in), optional :: init\n real(kind = RPRE), dimension(:), allocatable, intent(inout), optional :: means\n integer(kind = IPRE), intent(in), optional :: itermax\n integer(kind = IPRE), intent(inout), optional :: niter\n integer(kind = IPRE) :: opt_itermax, n, iter\n real(kind = RPRE), dimension(:,:), allocatable :: m1\n real(kind = RPRE), dimension(:,:), allocatable :: opt_init, A\n\n n = size(x)\n\n opt_itermax = 100\n if (present(itermax)) opt_itermax = itermax\n if (present(init)) then\n opt_init = reshape( init, shape = [ K, 1 ], order = [ 1, 2 ])\n else\n opt_init = reshape( x(randperm(n, K)), shape = [ K, 1 ], order = [ 1, 2 ])\n end if\n\n A = reshape( x, shape = [ n, 1 ], order = [ 1, 2 ] )\n idx = kmeans2(A, K, m1, opt_init, opt_itermax, iter)\n\n if (present(niter)) niter = iter\n if (present(means)) means = [ m1 ]\n\n return\n end function kmeans1\n\n function kmeans2(A, K, means, init, itermax, niter) result(idx)\n integer(kind = IPRE), dimension(:), allocatable :: idx\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE), intent(in) :: K\n real(kind = RPRE), dimension(:,:), intent(in), optional :: init\n real(kind = RPRE), dimension(:,:), allocatable, intent(inout), optional :: means\n integer(kind = IPRE), intent(in), optional :: itermax\n integer(kind = IPRE), intent(inout), optional :: niter\n integer(kind = IPRE) :: opt_itermax, i, n, p, iter\n real(kind = RPRE), dimension(:,:), allocatable :: opt_init, m, m1\n\n n = size(A, 1)\n p = size(A, 2)\n\n opt_itermax = 1000\n if (present(itermax)) opt_itermax = itermax\n if (present(init)) then\n opt_init = init\n else\n opt_init = A(randperm(n, K),:)\n end if\n\n ! Initialization\n !================\n m = opt_init\n idx = update_index(A, m)\n m1 = update_means(A, idx)\n\n ! Loop until convergence\n !========================\n iter = 0\n do while ( ( means_residuals(m, m1) .gt. 1.0d-10 ) &\n .and. ( iter .lt. opt_itermax ) )\n iter = iter + 1\n m = m1\n idx = update_index(A, m)\n m1 = update_means(A, idx)\n end do\n\n if (present(niter)) niter = iter\n if (present(means)) means = m1\n\n return\n contains\n\n !-------------------------------------------------------------------\n ! update_index\n !-------------------------------------------------------------------\n function update_index(A, means) result(idx)\n integer(kind = IPRE), dimension(:), allocatable :: idx\n real(kind = RPRE), dimension(:,:), intent(in) :: A, means\n integer(kind = IPRE) :: i, j, b(1)\n real(kind = RPRE), dimension(:), allocatable :: dist\n\n idx = zeros(n)\n do i = 1, n\n dist = zeros(K)\n do j = 1, K\n dist(j) = norm(A(i,:) - means(j,:))\n end do\n b = minloc(dist)\n idx(i) = b(1)\n end do\n return\n end function update_index\n\n !-------------------------------------------------------------------\n ! update_means\n !-------------------------------------------------------------------\n function update_means(A, idx) result(means)\n real(kind = RPRE), dimension(:,:), allocatable :: means\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE), dimension(:), intent(in) :: idx\n integer(kind = IPRE) :: j\n\n means = zeros(K, p)\n do j = 1, K\n means(j,:) = mean(A(find(idx .eq. j),:))\n end do\n return\n end function update_means\n\n !-------------------------------------------------------------------\n ! means_residuals\n !-------------------------------------------------------------------\n function means_residuals(means1, means2) result(eps)\n real(kind = RPRE) :: eps\n real(kind = RPRE), dimension(:,:), intent(in) :: means1, means2\n real(kind = RPRE), dimension(:,:), allocatable :: means\n integer(kind = IPRE) :: k\n\n eps = 0.0d0\n means = abs( means2 - means1 )\n do k = 1, p\n eps = eps + sum(means(:,k))**2\n end do\n eps = sqrt(eps)\n return\n end function means_residuals\n\n end function kmeans2\n\n!=======================================================================\n! mad\n!-----------------------------------------------------------------------\n! mad computes the mean-absolute-deviation or the median-absolute\n! -deviation of a vector.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! y = mad(x)\n! y = mad(x, 1)\n! y = mad(x, 2)\n! x = mad(A)\n! x = mad(A, 1, 1)\n! x = mad(A, 1, 2)\n! x = mad(A, 2, 1)\n! x = mad(A, 2, 2)\n!\n! Description\n!-----------------------------------------------------------------------\n! y = mad(x) returns the mean-absolute-deviation of the vector x.\n!\n! y = mad(x, 1) (see y = mad(x)).\n!\n! y = mad(x, 2) returns the median-absolute-deviation of the vector x.\n!\n! x = mad(A) returns a dim2 vector with the mean-absolute-deviation of\n! each column of matrix A.\n!\n! x = mad(A, 1, 1) (see x = mad(A)).\n!\n! x = mad(A, 1, 2) returns a dim2 vector with the median-absolute\n! -deviation of each column of matrix A.\n!\n! x = mad(A, 2, 1) returns a dim1 vector with the mean-absolute\n! -deviation of each row of matrix A.\n!\n! x = mad(A, 2, 2) returns a dim1 vector with the median-absolute\n! -deviation of each row of matrix A.\n!=======================================================================\n\n real(kind = RPRE) function mad1(x, method)\n real(kind = RPRE), dimension(:), intent(in) :: x\n integer(kind = IPRE), intent(in), optional :: method\n\n if ((.not. present(method)) .or. (method .eq. 1)) then\n mad1 = mean(abs(x - mean(x)))\n elseif (method .eq. 2) then\n mad1 = median(abs(x - median(x)))\n end if\n return\n end function mad1\n\n function mad2(A, dim, method)\n real(kind = RPRE), dimension(:), allocatable :: mad2\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE), intent(in), optional :: dim, method\n integer(kind = IPRE) :: i, m, n\n\n m = size(A, 1)\n n = size(A, 2)\n if ((.not. present(dim)) .or. (dim .eq. 1)) then\n allocate(mad2(n))\n if ((.not. present(method)) .or. (method .eq. 1)) then\n do i = 1, n\n mad2(i) = mad(A(:,i), 1)\n end do\n elseif (method .eq. 2) then\n do i = 1, n\n mad2(i) = mad(A(:,i), 2)\n end do\n end if\n elseif (dim .eq. 2) then\n allocate(mad2(m))\n if ((.not. present(method)) .or. (method .eq. 1)) then\n do i = 1, m\n mad2(i) = mad(A(i,:), 1)\n end do\n elseif (method .eq. 2) then\n do i = 1, m\n mad2(i) = mad(A(i,:), 2)\n end do\n end if\n end if\n return\n end function mad2\n\n!=======================================================================\n! mbkmeans\n!-----------------------------------------------------------------------\n! mbkmeans performs Mini-batch K-means clustering.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! idx = mbkmeans(x, K, [options = ])\n! idx = mbkmeans(A, K, [options = ])\n!\n! Description\n!-----------------------------------------------------------------------\n! idx = mbkmeans(x, K, [options = ]) returns the cluster indices of each\n! element in vector x.\n!\n! idx = mbkmeans(A, K, [options = ]) returns the cluster indices of each\n! rows in matrix A.\n!\n! Options\n!-----------------------------------------------------------------------\n! perc = 0.2 Size of the batch (percentage)\n! means Output centroids\n! init Initial centroids\n! itermax = 50 Maximum number of iterations\n! niter Output number of iterations\n!=======================================================================\n\n function mbkmeans1(x, K, perc, means, init, itermax, niter) result(idx)\n integer(kind = IPRE), dimension(:), allocatable :: idx\n real(kind = RPRE), dimension(:), intent(in) :: x\n integer(kind = IPRE), intent(in) :: K\n real(kind = RPRE), intent(in), optional :: perc\n real(kind = RPRE), dimension(:), intent(in), optional :: init\n real(kind = RPRE), dimension(:), allocatable, intent(inout), optional :: means\n integer(kind = IPRE), intent(in), optional :: itermax\n integer(kind = IPRE), intent(inout), optional :: niter\n integer(kind = IPRE) :: opt_itermax, n, iter\n real(kind = RPRE) :: opt_perc\n real(kind = RPRE), dimension(:,:), allocatable :: m1\n real(kind = RPRE), dimension(:,:), allocatable :: opt_init, A\n\n n = size(x)\n\n opt_itermax = 50\n opt_perc = 0.2d0\n if (present(itermax)) opt_itermax = itermax\n if (present(perc)) opt_perc = perc\n if (present(init)) then\n opt_init = reshape( init, shape = [ K, 1 ], order = [ 1, 2 ])\n else\n opt_init = reshape( x(randperm(n, K)), shape = [ K, 1 ], order = [ 1, 2 ])\n end if\n\n A = reshape( x, shape = [ n, 1 ], order = [ 1, 2 ] )\n idx = mbkmeans2(A, K, perc, m1, opt_init, opt_itermax, iter)\n\n if (present(niter)) niter = iter\n if (present(means)) means = [ m1 ]\n\n return\n end function mbkmeans1\n\n function mbkmeans2(A, K, perc, means, init, itermax, niter) result(idx)\n integer(kind = IPRE), dimension(:), allocatable :: idx\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE), intent(in) :: K\n real(kind = RPRE), intent(in), optional :: perc\n real(kind = RPRE), dimension(:,:), intent(in), optional :: init\n real(kind = RPRE), dimension(:,:), allocatable, intent(inout), optional :: means\n integer(kind = IPRE), intent(in), optional :: itermax\n integer(kind = IPRE), intent(inout), optional :: niter\n integer(kind = IPRE) :: opt_itermax, n, p, bs, iter\n real(kind = RPRE) :: opt_perc\n integer(kind = IPRE), dimension(:), allocatable :: v\n real(kind = RPRE), dimension(:,:), allocatable :: opt_init, m, m1, B\n\n n = size(A, 1)\n p = size(A, 2)\n\n opt_itermax = 50\n opt_perc = 0.2d0\n if (present(itermax)) opt_itermax = itermax\n if (present(perc)) opt_perc = perc\n if (present(init)) then\n opt_init = init\n else\n opt_init = A(randperm(n, K),:)\n end if\n\n ! Initialization\n !================\n bs = nint(opt_perc*n) ! Batch size\n m = opt_init ! Initial centroids\n v = zeros(K) ! Per-center counter\n\n ! Iterate until convergence\n !===========================\n do iter = 1, opt_itermax\n B = A(randperm(n, bs),:) ! Batch\n m1 = m ! Previous means\n idx = cache_means(B, m) ! Cache means\n call update_means(m, v, B, idx) ! Update means with gradient\n if ( means_residuals(m, m1) .lt. 1.0d-2 ) exit\n end do\n\n idx = cache_means(A, m)\n\n if (present(niter)) niter = iter - 1\n if (present(means)) means = m\n\n return\n contains\n\n !-------------------------------------------------------------------\n ! cache_means\n !-------------------------------------------------------------------\n function cache_means(A, means) result(idx)\n integer(kind = IPRE), dimension(:), allocatable :: idx\n real(kind = RPRE), dimension(:,:), intent(in) :: A, means\n integer(kind = IPRE) :: i, j, n, b(1)\n real(kind = RPRE), dimension(:), allocatable :: dist\n\n n = size(A, 1)\n idx = zeros(n)\n dist = zeros(K)\n do i = 1, n\n dist = 0.0d0\n do j = 1, K\n dist(j) = norm(A(i,:) - means(j,:))\n end do\n b = minloc(dist)\n idx(i) = b(1)\n end do\n return\n end function cache_means\n\n !-------------------------------------------------------------------\n ! update_means\n !-------------------------------------------------------------------\n subroutine update_means(means, v, A, idx)\n real(kind = RPRE), dimension(:,:), intent(inout) :: means\n integer(kind = IPRE), dimension(:), intent(inout) :: v\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE), dimension(:), intent(in) :: idx\n integer(kind = IPRE) :: i, n, c\n real(kind = RPRE) :: eta\n\n n = size(A, 1)\n do i = 1, n\n c = idx(i)\n v(c) = v(c) + 1\n eta = 1.0d0 / real(v(c), RPRE)\n means(c,:) = ( 1.0d0 - eta ) * means(c,:) + eta * A(i,:)\n end do\n return\n end subroutine update_means\n\n !-------------------------------------------------------------------\n ! means_residuals\n !-------------------------------------------------------------------\n function means_residuals(means1, means2) result(eps)\n real(kind = RPRE) :: eps\n real(kind = RPRE), dimension(:,:), intent(in) :: means1, means2\n real(kind = RPRE), dimension(:,:), allocatable :: means\n integer(kind = IPRE) :: k\n\n eps = 0.0d0\n means = abs( means2 - means1 )\n do k = 1, p\n eps = eps + sum(means(:,k))**2\n end do\n eps = sqrt(eps)\n return\n end function means_residuals\n\n end function mbkmeans2\n\n!=======================================================================\n! mean\n!-----------------------------------------------------------------------\n! mean computes the mean value of an array.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! y = mean(x)\n! x = mean(A)\n! x = mean(A, 1)\n! x = mean(A, 2)\n!\n! Description\n!-----------------------------------------------------------------------\n! y = mean(x) returns the mean value of the vector x.\n!\n! x = mean(A) returns a dim2 vector with the mean values of each column\n! of matrix A.\n!\n! x = mean(A, 1) (see x = mean(A)).\n!\n! x = mean(A, 2) returns a dim1 vector with the mean values of each row\n! of matrix A.\n!\n! Examples\n!-----------------------------------------------------------------------\n! x = [ 1., 2., 3. ]\n! y = mean(x)\n! 2.\n!\n! A = reshape([ 1., 2., 3., 4., 5., 6., 7., 8., 9. ], [ 3, 3 ], &\n! order = [ 2, 1 ])\n! x = mean(A)\n! 4. 5. 6.\n! x = mean(A, 2)\n! 2. 5. 8.\n!=======================================================================\n\n real(kind = RPRE) function mean1(x)\n real(kind = RPRE), dimension(:), intent(in) :: x\n\n mean1 = sum(x)/size(x)\n return\n end function mean1\n\n function mean2(A, dim)\n real(kind = RPRE), dimension(:), allocatable :: mean2\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE), intent(in), optional :: dim\n integer(kind = IPRE) :: i, m, n\n\n m = size(A, 1)\n n = size(A, 2)\n if ((.not. present(dim)) .or. (dim .eq. 1)) then\n allocate(mean2(n))\n do i = 1, n\n mean2(i) = mean(A(:,i))\n end do\n elseif (dim .eq. 2) then\n allocate(mean2(m))\n do i = 1, m\n mean2(i) = mean(A(i,:))\n end do\n end if\n return\n end function mean2\n\n!=======================================================================\n! median\n!-----------------------------------------------------------------------\n! median computes the median value of an array.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! y = median(x)\n! x = median(A)\n! x = median(A, 1)\n! x = median(A, 2)\n!\n! Description\n!-----------------------------------------------------------------------\n! y = median(x) returns the median value of the vector x.\n!\n! x = median(A) returns a dim2 vector with the median values of each\n! column of matrix A.\n!\n! x = median(A, 1) (see x = median(A)).\n!\n! x = median(A, 2) returns a dim1 vector with the median values of each\n! row of matrix A.\n!\n! Examples\n!-----------------------------------------------------------------------\n! x = [ 3., 1., 2. ]\n! y = median(x)\n! 2.\n!\n! x = [ 3., 4., 1., 2. ]\n! y = median(x)\n! 2.5\n!\n! A = reshape([ 3., 7., 1., 8., 2., 5., 4., 9., 6. ], [ 3, 3 ], &\n! order = [ 2, 1 ])\n! x = median(A)\n! 4. 7. 5.\n! x = median(A, 2)\n! 3. 5. 6.\n!=======================================================================\n\n real(kind = RPRE) function median1(x)\n real(kind = RPRE), dimension(:), intent(in) :: x\n real(kind = RPRE), dimension(:), allocatable :: x_sort\n integer(kind = IPRE) :: i, n\n\n n = size(x)\n x_sort = sort(x)\n i = ceiling(real(n/2.0d0))\n if (mod(n, 2) .eq. 0) then\n median1 = (x_sort(i) + x_sort(i+1))/2\n else\n median1 = x_sort(i)\n end if\n return\n end function median1\n\n function median2(A, dim)\n real(kind = RPRE), dimension(:), allocatable :: median2\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE), intent(in), optional :: dim\n integer(kind = IPRE) :: i, m, n\n\n m = size(A, 1)\n n = size(A, 2)\n if ((.not. present(dim)) .or. (dim .eq. 1)) then\n allocate(median2(n))\n do i = 1, n\n median2(i) = median(A(:,i))\n end do\n elseif (dim .eq. 2) then\n allocate(median2(m))\n do i = 1, m\n median2(i) = median(A(i,:))\n end do\n end if\n return\n end function median2\n\n!=======================================================================\n! meshgrid\n!-----------------------------------------------------------------------\n! meshgrid generates rectangular grid in 2 dimensions.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! call meshgrid(ax, ay, X, Y)\n!\n! Description\n!-----------------------------------------------------------------------\n! call meshgrid(ax, ay, X, Y) returns replicated grid vectors of ax and\n! ay that form a full grid.\n!\n! Examples\n!-----------------------------------------------------------------------\n! ax = linspace(1, 3, 3)\n! ay = linspace(10, 14, 5)\n! call meshgrid(ax, ay, X, Y)\n! X =\n! 1. 2. 3.\n! 1. 2. 3.\n! 1. 2. 3.\n! 1. 2. 3.\n! 1. 2. 3.\n! Y =\n! 10. 10. 10.\n! 11. 11. 11.\n! 12. 12. 12.\n! 13. 13. 13.\n! 14. 14. 14.\n!=======================================================================\n\n subroutine meshgrid2(ax, ay, x, y)\n real(kind = RPRE), dimension(:), intent(in) :: ax, ay\n real(kind = RPRE), dimension(:,:), allocatable, intent(out) :: x, y\n integer(kind = IPRE) :: i, m, n\n\n m = size(ax)\n n = size(ay)\n if (.not. allocated(x)) allocate(x(n, m))\n if (.not. allocated(y)) allocate(y(n, m))\n do i = 1, n\n x(i,:) = ax\n end do\n do i = 1, m\n y(:,i) = ay\n end do\n return\n end subroutine meshgrid2\n\n!=======================================================================\n! mpi_rpre\n!-----------------------------------------------------------------------\n! mpi_rpre returns either MPI_REAL or MPI_DOUBLE depending on RPRE.\n!\n! Notes\n!-----------------------------------------------------------------------\n! When calling MPI functions, use mpi_rpre instead of MPI_REAL or\n! MPI_DOUBLE.\n!=======================================================================\n\n#ifdef do_mpi\n integer(kind = 4) function mpi_rpre()\n select case(RPRE)\n case(4)\n mpi_rpre = mpi_real\n case(8)\n mpi_rpre = mpi_double\n end select\n return\n end function mpi_rpre\n#endif\n\n!=======================================================================\n! nextpow2\n!-----------------------------------------------------------------------\n! nextpow2 computes the exponent of the next higher power of 2.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! p = nextpow2(x)\n! P = nextpow2(X)\n!\n! Description\n!-----------------------------------------------------------------------\n! p = nextpow2(x) returns the exponent for the smallest power of two\n! that satisfy 2**p .le. abs(x).\n!\n! P = nextpow2(X) returns the next power of 2 of each element in\n! vector x.\n!\n! Examples\n!-----------------------------------------------------------------------\n! y = nextpow2(15)\n! 4\n!\n! x = [ 1, -2, 3, -4, 5, 9, 519 ]\n! y = nextpow2(x)\n! 0 1 2 2 3 4 10\n!=======================================================================\n\n function nextpow2_0(x) result(pow)\n integer(kind = IPRE) :: pow\n integer(kind = IPRE), intent(in) :: x\n\n pow = ceiling( log( real( abs(x) ) ) / log(2.) )\n return\n end function nextpow2_0\n\n function nextpow2_1(x) result(pow)\n integer(kind = IPRE), dimension(:), allocatable :: pow\n integer(kind = IPRE), dimension(:), intent(in) :: x\n\n pow = ceiling( log( real( abs(x) ) ) / log(2.) )\n return\n end function nextpow2_1\n\n!=======================================================================\n! norm\n!-----------------------------------------------------------------------\n! norm computes vector and matrix norms.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! y = norm(x)\n! y = norm(x, p)\n! x = norm(A)\n! x = norm(A, p)\n!\n! Description\n!-----------------------------------------------------------------------\n! y = norm(x) returns the 2-norm or Euclidian norm of vector x.\n!\n! y = norm(x, p) returns the p-norm of vector x, where p is any positive\n! real value.\n!\n! x = norm(A) returns the 2-norm of matrix A (largest singular value).\n!\n! x = norm(A, p) returns the p-norm of matrix A, where p is {1, 2}.\n!\n! Examples\n!-----------------------------------------------------------------------\n! x = [ 1., 2., 3. ]\n! y = norm(x)\n! 3.74165750\n! y = norm(x, 3.)\n! 3.30192733\n!=======================================================================\n\n real(kind = RPRE) function norm1(x, p)\n real(kind = RPRE), dimension(:), intent(in) :: x\n real(kind = RPRE), intent(in), optional :: p\n\n if ((.not. present(p)) .or. (p .eq. 2.)) then\n norm1 = sqrt(sum(abs(x)**2))\n elseif (p .eq. 1.) then\n norm1 = sum(abs(x))\n else\n norm1 = (sum(abs(x)**p))**(1.0d0/p)\n end if\n return\n end function norm1\n\n real(kind = RPRE) function norm2(A, p)\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE), intent(in), optional :: p\n real(kind = RPRE), dimension(:), allocatable :: w\n\n if ((.not. present(p)) .or. (p .eq. 2.)) then\n call svd(A, w)\n norm2 = maxval(w)\n elseif (p .eq. 1.) then\n norm2 = maxval(sum(abs(A), dim = 2))\n end if\n return\n end function norm2\n\n!=======================================================================\n! normpdf\n!-----------------------------------------------------------------------\n! normpdf computes the normal probability density function.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! y = normpdf(x, mu, sigma)\n! y = normpdf(X, mu, sigma)\n!\n! Description\n!-----------------------------------------------------------------------\n! y = normpdf(x, mu, sigma) returns the PDF at each of the points in\n! vector x using the normal distribution with mean mu and standard\n! deviation sigma.\n!\n! y = normpdf(X, mu, sigma) returns the PDF at each of the\n! multidimensional points in matrix X using the normal distribution with\n! mean mu and covariance matrix sigma.\n!=======================================================================\n\n real(kind = RPRE) function normpdf0(x, mu, sigma) result(pdf)\n real(kind = RPRE), intent(in) :: x, mu, sigma\n\n pdf = exp( -0.5d0 * ( x - mu )**2 / sigma**2 )\n pdf = pdf / ( sigma * sqrt(2.0d0 * pi) )\n return\n end function normpdf0\n\n function normpdf1(x, mu, sigma) result(pdf)\n real(kind = RPRE), dimension(:), allocatable :: pdf\n real(kind = RPRE), dimension(:), intent(in) :: x\n real(kind = RPRE), intent(in) :: mu, sigma\n\n pdf = exp( -0.5d0 * ( x - mu )**2 / sigma**2 )\n pdf = pdf / ( sigma * sqrt(2.0d0 * pi) )\n return\n end function normpdf1\n\n function normpdf2(X, mu, sigma) result(pdf)\n real(kind = RPRE), dimension(:), allocatable :: pdf\n real(kind = RPRE), dimension(:,:), intent(in) :: X, sigma\n real(kind = RPRE), dimension(:), intent(in) :: mu\n integer(kind = IPRE) :: n\n real(kind = RPRE), dimension(:,:), allocatable :: tmp\n\n n = size(X, 2)\n tmp = X - repmat(mu, size(X, 1), 2)\n pdf = exp( -0.5d0 *sum(matmul(tmp, inv(sigma)) * tmp, dim = 2) )\n pdf = pdf / sqrt( (2.0d0 * pi)**n * det(sigma) )\n return\n end function normpdf2\n\n!=======================================================================\n! num2str\n!-----------------------------------------------------------------------\n! num2str converts numbers to strings.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! str = num2str(x)\n! str = num2str(x, fmt)\n!\n! Description\n!-----------------------------------------------------------------------\n! str = num2str(x) converts x into a string.\n!\n! str = num2str(x, fmt) converts x into a string with the format fmt.\n!\n! Examples\n!-----------------------------------------------------------------------\n! print *, \"Percentage: \" // num2str(50.431, \"(F6.2)\") // \"%\"\n! Percentage: 50.43%\n!=======================================================================\n\n function num2str_i4(x, fmt)\n character(len = :), allocatable :: num2str_i4\n integer(kind = 4), intent(in) :: x\n character(len = *), intent(in), optional :: fmt\n character(len = CLEN) :: xstr\n\n if (present(fmt)) then\n write(xstr, fmt) x\n else\n write(xstr, *) x\n end if\n xstr = adjustl(xstr)\n num2str_i4 = trim(xstr)\n return\n end function num2str_i4\n\n function num2str_i8(x, fmt)\n character(len = :), allocatable :: num2str_i8\n integer(kind = 8), intent(in) :: x\n character(len = *), intent(in), optional :: fmt\n character(len = CLEN) :: xstr\n\n if (present(fmt)) then\n write(xstr, fmt) x\n else\n write(xstr, *) x\n end if\n xstr = adjustl(xstr)\n num2str_i8 = trim(xstr)\n return\n end function num2str_i8\n\n function num2str_r4(x, fmt)\n character(len = :), allocatable :: num2str_r4\n real(kind = 4), intent(in) :: x\n character(len = *), intent(in), optional :: fmt\n character(len = CLEN) :: xstr\n\n if (present(fmt)) then\n write(xstr, fmt) x\n else\n write(xstr, *) x\n end if\n xstr = adjustl(xstr)\n num2str_r4 = trim(xstr)\n return\n end function num2str_r4\n\n function num2str_r8(x, fmt)\n character(len = :), allocatable :: num2str_r8\n real(kind = 8), intent(in) :: x\n character(len = *), intent(in), optional :: fmt\n character(len = CLEN) :: xstr\n\n if (present(fmt)) then\n write(xstr, fmt) x\n else\n write(xstr, *) x\n end if\n xstr = adjustl(xstr)\n num2str_r8 = trim(xstr)\n return\n end function num2str_r8\n\n!=======================================================================\n! ones\n!-----------------------------------------------------------------------\n! ones creates array all of ones.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! x = ones(dim1)\n! A = ones(dim1, dim2)\n! X = ones(dim1, dim2, dim3)\n!\n! Description\n!-----------------------------------------------------------------------\n! x = ones(dim1) returns a dim1 vector of ones.\n!\n! A = ones(dim1, dim2) returns a dim1-by-dim2 matrix of ones.\n!\n! X = ones(dim1, dim2, dim3) returns a dim1-by-dim2-by-dim3\n! 3-dimensional matrix of ones.\n!\n! Examples\n!-----------------------------------------------------------------------\n! x = ones(3)\n! x =\n! 1. 1. 1.\n!\n! A = ones(3, 3)\n! A =\n! 1. 1. 1.\n! 1. 1. 1.\n! 1. 1. 1.\n!=======================================================================\n\n function ones1(dim1)\n real(kind = RPRE), dimension(:), allocatable :: ones1\n integer(kind = IPRE), intent(in) :: dim1\n integer(kind = IPRE) :: ierr\n\n allocate(ones1(dim1), stat = ierr)\n if ( ierr .ne. 0 ) then\n print *, \"Error: in ones, could not allocate array.\"\n stop\n else\n ones1 = 1.0d0\n end if\n return\n end function ones1\n\n function ones2(dim1, dim2)\n real(kind = RPRE), dimension(:,:), allocatable :: ones2\n integer(kind = IPRE), intent(in) :: dim1, dim2\n integer(kind = IPRE) :: ierr\n\n allocate(ones2(dim1, dim2), stat = ierr)\n if ( ierr .ne. 0 ) then\n print *, \"Error: in ones, could not allocate array.\"\n stop\n else\n ones2 = 1.0d0\n end if\n return\n end function ones2\n\n function ones3(dim1, dim2, dim3)\n real(kind = RPRE), dimension(:,:,:), allocatable :: ones3\n integer(kind = IPRE), intent(in) :: dim1, dim2, dim3\n integer(kind = IPRE) :: ierr\n\n allocate(ones3(dim1, dim2, dim3), stat = ierr)\n if ( ierr .ne. 0 ) then\n print *, \"Error: in ones, could not allocate array.\"\n stop\n else\n ones3 = 1.0d0\n end if\n return\n end function ones3\n\n!=======================================================================\n! open\n!-----------------------------------------------------------------------\n! open opens a File object with sequential or direct access.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! call ofile % open()\n! call ofile % open(r)\n!\n! Description\n!-----------------------------------------------------------------------\n! call ofile % open() open the File object ofile with sequential access.\n!\n! call ofile % open(r) open the File object ofile with direct access,\n! where r is the record length.\n!=======================================================================\n\n subroutine open1(self)\n class(File), intent(inout) :: self\n integer(kind = IPRE) :: ierr\n\n open(unit = self % unit, file = self % filename, access = \"sequential\", &\n form = \"formatted\", status = \"unknown\", iostat = ierr)\n if ( ierr .ne. 0 ) then\n print *, \"Error: cannot read '\" // trim(self % filename) // \"'\"\n stop\n end if\n return\n end subroutine open1\n\n subroutine open2(self, r)\n class(File), intent(inout) :: self\n integer(kind = IPRE), intent(in) :: r\n integer(kind = IPRE) :: ierr\n\n open(unit = self % unit, file = self % filename, access = \"direct\", &\n form = \"unformatted\", status = \"unknown\", recl = r, iostat = ierr)\n if ( ierr .ne. 0 ) then\n print *, \"Error: cannot read '\" // trim(self % filename) // \"'\"\n stop\n end if\n return\n end subroutine open2\n\n!=======================================================================\n! pascal\n!-----------------------------------------------------------------------\n! pascal computes the Pascal's matrix.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! A = pascal(n)\n!\n! Description\n!-----------------------------------------------------------------------\n! A = pascal(n) returns the Pascal's matrix of order n.\n!\n! Example\n!-----------------------------------------------------------------------\n! A = pascal(5)\n! 1 1 1 1 1\n! 1 2 3 4 5\n! 1 3 6 10 15\n! 1 4 10 20 35\n! 1 5 15 35 70\n!=======================================================================\n\n function pascal(n)\n integer(kind = IPRE), dimension(:,:), allocatable :: pascal\n integer(kind = IPRE), intent(in) :: n\n integer(kind = IPRE) :: i, j\n\n pascal = ones(n, n)\n do i = 2, n\n do j = 2, n\n pascal(i,j) = pascal(i-1,j) + pascal(i,j-1)\n end do\n end do\n return\n end function pascal\n\n!=======================================================================\n! prctile\n!-----------------------------------------------------------------------\n! prctile computes the percentiles of a data set.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! q = prctile(x, p)\n! Q = prctile(x, P)\n!\n! Description\n!-----------------------------------------------------------------------\n! q = prctile(x, p) returns the p-th percentile of vector x.\n!\n! Q = prctile(x, P) returns each percentile of vector x contained in\n! vector P.\n!=======================================================================\n\n real(kind = RPRE) function prctile0(x, p)\n real(kind = RPRE), dimension(:), intent(in) :: x\n integer(kind = IPRE), intent(in) :: p\n real(kind = RPRE) :: tmp(1)\n\n tmp = prctile1(x, [ p ])\n prctile0 = tmp(1)\n return\n end function prctile0\n\n function prctile1(x, p)\n real(kind = RPRE), dimension(:), allocatable :: prctile1\n real(kind = RPRE), dimension(:), intent(in) :: x\n integer(kind = IPRE), dimension(:), intent(in) :: p\n integer(kind = IPRE) :: i, nx, np, idx\n real(kind = RPRE), dimension(:), allocatable :: xsort, ap\n\n nx = size(x)\n np = size(p)\n prctile1 = zeros(np)\n xsort = sort(x)\n do i = 1, np\n if ( p(i) .le. 50.0d0/real(nx, RPRE) ) then\n prctile1(i) = xsort(1)\n elseif ( p(i) .ge. 100.0d0 * ( ( nx - 0.5d0 ) / real(nx, RPRE) ) ) then\n prctile1(i) = xsort(nx)\n else\n ap = 100.0d0 * ( linspace(1, nx, nx) - 0.5d0 ) / real(nx, RPRE)\n idx = maxval( find( p(i) .gt. ap ) )\n prctile1(i) = xsort(idx) &\n + ( xsort(idx+1) - xsort(idx) ) * ( p(i) - ap(idx) ) &\n / ( ap(idx+1) - ap(idx) )\n end if\n end do\n return\n end function prctile1\n\n!=======================================================================\n! progress_bar\n!-----------------------------------------------------------------------\n! Display a progression bar.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! call progress_bar(iter, itermax, step)\n!\n! Description\n!-----------------------------------------------------------------------\n! call progress_bar(iter, itermax, step) displays a progress bar given\n! the current iteration iter, the maximum number of iterations itermax,\n! and the length of the bar steps.\n!=======================================================================\n\n subroutine progress_bar(iter, itermax, step)\n integer(kind = IPRE), intent(in) :: iter, itermax\n integer(kind = IPRE), intent(in), optional :: step\n integer(kind = IPRE) :: i, perc, opt_step\n character(len = :), allocatable :: bar\n\n opt_step = 50\n if ( present(step) ) opt_step = step\n\n ! Initialize the bar\n bar = \" [\"\n do i = 1, opt_step\n bar = bar // \" \"\n end do\n bar = bar // \"]\"\n\n ! Compute the percentage\n perc = real(iter) / real(itermax) * 100.\n\n ! Fill the bar\n do i = 1, floor( perc/(100./opt_step) )\n bar(3+i:3+i) = \"=\"\n end do\n\n ! Place the percentage\n i = ceiling( (opt_step+2)/2. )\n write(bar(i+1:i+3), \"(I3)\") perc\n bar(i+4:i+4) = \"%\"\n\n ! Fill the space\n if (perc .lt. 100 .and. perc .gt. 50-100/opt_step) bar(i+1:i+1) = \"=\"\n\n ! Return to the beginning of the line and display the bar\n write(*, \"(A1, A)\", advance = \"no\") char(13), bar\n return\n end subroutine progress_bar\n\n!=======================================================================\n! progress_perc\n!-----------------------------------------------------------------------\n! Display a progression percentage.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! call progress_perc(iter, itermax, prefix)\n!\n! Description\n!-----------------------------------------------------------------------\n! call progress_perc(iter, itermax, prefix) displays a percentage given\n! the current iteration iter, the maximum number of iterations itermax,\n! and a prefix.\n!=======================================================================\n\n subroutine progress_perc(iter, itermax, prefix)\n integer(kind = IPRE), intent(in) :: iter, itermax\n character(len = *), intent(in), optional :: prefix\n real(kind = RPRE) :: perc\n character(len = :), allocatable :: opt_prefix\n\n opt_prefix = \"\"\n if ( present(prefix) ) opt_prefix = prefix\n\n perc = real(iter) / real(itermax) * 100.\n write(*, \"(A1, A, F6.2, A)\", advance = \"no\") char(13), opt_prefix, perc, \"%\"\n return\n end subroutine progress_perc\n\n!=======================================================================\n! rng\n!-----------------------------------------------------------------------\n! rng controls random number generation.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! call rng()\n! call rng(seed)\n!\n! Description\n!-----------------------------------------------------------------------\n! call rng() uses the current date and time as seed for random number\n! generation.\n!\n! call rng(seed) sets the input seed for random number generation.\n!\n! Notes\n!-----------------------------------------------------------------------\n! It is advised to call rng at the beginning of a program so that each\n! run of the program produces different sequences of random numbers.\n!=======================================================================\n\n subroutine rng(seed)\n integer(kind = IPRE), intent(in), optional :: seed\n integer(kind = 4) :: seed_size, values(8)\n integer(kind = 4), dimension(:), allocatable :: seed_put\n\n call random_seed(size = seed_size)\n allocate(seed_put(seed_size))\n if (present(seed)) then\n seed_put = seed\n else\n call date_and_time(values = values)\n seed_put = values(8) * values(7) * values(6)\n end if\n call random_seed(put = seed_put)\n return\n end subroutine rng\n\n!=======================================================================\n! randi\n!-----------------------------------------------------------------------\n! randi generates uniformly distributed random integers.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! x = randi(imax)\n! x = randi([imin, imax])\n! x = randi(imax, dim1)\n! x = randi([imin, imax], dim1)\n! A = randi(imax, dim1, dim2)\n! A = randi([imin, imax], dim1, dim2)\n! X = randi(imax, dim1, dim2, dim3)\n! X = randi([imin, imax], dim1, dim2, dim3)\n!\n! Description\n!-----------------------------------------------------------------------\n! x = randi(imax) returns a random scalar integer between 1 and imax.\n!\n! x = randi([imin, imax]) returns a random scalar integer between imin\n! and imax.\n!\n! x = randi(imax, dim1) returns a dim1 vector of random scalar integers\n! between 1 and imax.\n!\n! x = randi([imin, imax], dim1) returns a dim1 vector of random scalar\n! integers between imin and imax.\n!\n! A = randi(imax, dim1, dim2) returns a dim1-by-dim2 matrix of random\n! scalar integers between 1 and imax.\n!\n! A = randi([imin, imax], dim1, dim2) returns a dim1-by-dim2 matrix of\n! random scalar integers between imin and imax.\n!\n! X = randi(imax, dim1, dim2, dim3) returns a dim1-by-dim2-by-dim3\n! 3-dimensional matrix of random scalar integers between 1 and imax.\n!\n! X = randi([imin, imax], dim1, dim2, dim3) returns a dim1-by-dim2-by-dim3\n! 3-dimensional matrix of random scalar integers between imin and imax.\n!=======================================================================\n\n integer(kind = IPRE) function randi0_0(imax)\n integer(kind = IPRE), intent(in) :: imax\n\n randi0_0 = floor( randu0() * real(imax) ) + 1\n return\n end function randi0_0\n\n integer(kind = IPRE) function randi0_1(imax)\n integer(kind = IPRE), dimension(2), intent(in) :: imax\n\n randi0_1 = minval(imax) + nint( randu0() * real(maxval(imax) - minval(imax)) )\n return\n end function randi0_1\n\n function randi1_0(imax, dim1)\n integer(kind = IPRE), dimension(:), allocatable :: randi1_0\n integer(kind = IPRE), intent(in) :: imax, dim1\n\n randi1_0 = floor( randu1(dim1) * real(imax) ) + 1\n return\n end function randi1_0\n\n function randi1_1(imax, dim1)\n integer(kind = IPRE), dimension(:), allocatable :: randi1_1\n integer(kind = IPRE), dimension(2), intent(in) :: imax\n integer(kind = IPRE), intent(in) :: dim1\n\n randi1_1 = minval(imax) + nint( randu1(dim1) * real(maxval(imax) - minval(imax)) )\n return\n end function randi1_1\n\n function randi2_0(imax, dim1, dim2)\n integer(kind = IPRE), dimension(:,:), allocatable :: randi2_0\n integer(kind = IPRE), intent(in) :: imax, dim1, dim2\n\n randi2_0 = floor( randu2(dim1, dim2) * real(imax) ) + 1\n return\n end function randi2_0\n\n function randi2_1(imax, dim1, dim2)\n integer(kind = IPRE), dimension(:,:), allocatable :: randi2_1\n integer(kind = IPRE), dimension(2), intent(in) :: imax\n integer(kind = IPRE), intent(in) :: dim1, dim2\n\n randi2_1 = minval(imax) + nint( randu2(dim1, dim2) * real(maxval(imax) - minval(imax)) )\n return\n end function randi2_1\n\n function randi3_0(imax, dim1, dim2, dim3)\n integer(kind = IPRE), dimension(:,:,:), allocatable :: randi3_0\n integer(kind = IPRE), intent(in) :: imax, dim1, dim2, dim3\n\n randi3_0 = floor( randu3(dim1, dim2, dim3) * real(imax) ) + 1\n return\n end function randi3_0\n\n function randi3_1(imax, dim1, dim2, dim3)\n integer(kind = IPRE), dimension(:,:,:), allocatable :: randi3_1\n integer(kind = IPRE), dimension(2), intent(in) :: imax\n integer(kind = IPRE), intent(in) :: dim1, dim2, dim3\n\n randi3_1 = minval(imax) + nint( randu3(dim1, dim2, dim3) * real(maxval(imax) - minval(imax)) )\n return\n end function randi3_1\n\n!=======================================================================\n! randn\n!-----------------------------------------------------------------------\n! randn generates normally distributed random numbers using polar\n! Box-Muller algorithm.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! x = randn()\n! x = randn(dim1)\n!\n! Description\n!-----------------------------------------------------------------------\n! x = randn() returns a single normally distributed random number with\n! mean 0 and standard deviation 1.\n!\n! x = randn(dim1) returns a dim1 vector of normally distributed random\n! numbers.\n!\n! A = randn(dim1, dim2) returns a dim1-by-dim2 matrix of normally\n! distributed random numbers.\n!\n! X = randn(dim1, dim2, dim3) returns a dim1-by-dim2-by-dim3\n! 3-dimensional matrix of normally distributed random numbers.\n!\n! Examples\n!-----------------------------------------------------------------------\n! x = randn(3)\n! -1.22003853 -0.211721316 0.522971511\n!=======================================================================\n\n real(kind = RPRE) function randn0()\n real(kind = RPRE) :: u, v, s\n\n do\n u = 2.*randu() - 1.\n v = 2.*randu() - 1.\n s = u*u + v*v\n if ( (s .gt. 0.) .and. (s .lt. 1.) ) exit\n end do\n randn0 = u * sqrt( -2.0d0 * log(s) / s )\n return\n end function randn0\n\n function randn1(dim1)\n real(kind = RPRE), dimension(:), allocatable :: randn1\n integer(kind = IPRE), intent(in) :: dim1\n integer(kind = IPRE) :: i\n\n allocate(randn1(dim1))\n do i = 1, dim1\n randn1(i) = randn0()\n end do\n return\n end function randn1\n\n function randn2(dim1, dim2)\n real(kind = RPRE), dimension(:,:), allocatable :: randn2\n integer(kind = IPRE), intent(in) :: dim1, dim2\n integer(kind = IPRE) :: i, j\n\n allocate(randn2(dim1, dim2))\n do i = 1, dim1\n do j = 1, dim2\n randn2(i,j) = randn()\n end do\n end do\n return\n end function randn2\n\n function randn3(dim1, dim2, dim3)\n real(kind = RPRE), dimension(:,:,:), allocatable :: randn3\n integer(kind = IPRE), intent(in) :: dim1, dim2, dim3\n integer(kind = IPRE) :: i, j, k\n\n allocate(randn3(dim1, dim2, dim3))\n do i = 1, dim1\n do j = 1, dim2\n do k = 1, dim3\n randn3(i,j,k) = randn()\n end do\n end do\n end do\n return\n end function randn3\n\n!=======================================================================\n! randperm\n!-----------------------------------------------------------------------\n! randperm draws unique random integers.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! x = randperm(n)\n! x = randperm(n, k)\n!\n! Description\n!-----------------------------------------------------------------------\n! x = randperm(n) returns a row vector containing a random permutation\n! of the integers from 1 to n inclusive.\n!\n! x = randperm(n, k) returns a row vector containing k unique integers\n! selected randomly from 1 to n inclusive.\n!=======================================================================\n\n function randperm(n, k)\n integer(kind = IPRE), dimension(:), allocatable :: randperm\n integer(kind = IPRE), intent(in) :: n\n integer(kind = IPRE), intent(in), optional :: k\n integer(kind = IPRE) :: opt_k, i, j, tmp\n integer(kind = IPRE), dimension(:), allocatable :: a\n\n opt_k = n\n if (present(k)) opt_k = k\n\n a = linspace(1, n, n)\n do i = n, n-opt_k+1, -1\n j = randi(i)\n tmp = a(i)\n a(i) = a(j)\n a(j) = tmp\n end do\n randperm = a(n-opt_k+1:n)\n return\n end function randperm\n\n!=======================================================================\n! randu\n!-----------------------------------------------------------------------\n! randu generates uniformly distributed random numbers.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! x = randu()\n! x = randu(dim1)\n! A = randu(dim1, dim2)\n! X = randu(dim1, dim2, dim3)\n!\n! Description\n!-----------------------------------------------------------------------\n! x = randu() returns a single uniformly distributed random number in\n! the interval [0,1].\n!\n! x = randu(dim1) returns a dim1 vector of uniformly distributed random\n! numbers.\n!\n! A = randu(dim1, dim2) returns a dim1-by-dim2 matrix of uniformly\n! distributed random numbers.\n!\n! X = randu(dim1, dim2, dim3) returns a dim1-by-dim2-by-dim3\n! 3-dimensional matrix of uniformly distributed random numbers.\n!\n! Examples\n!-----------------------------------------------------------------------\n! x = randu()\n! 0.383413825\n!\n! x = randu(5)*2 - 1\n! 0.640258908 -0.873707294 0.787327528\n!=======================================================================\n\n real(kind = RPRE) function randu0()\n call random_number(randu0)\n return\n end function randu0\n\n function randu1(dim1)\n real(kind = RPRE), dimension(:), allocatable :: randu1\n integer(kind = IPRE), intent(in) :: dim1\n\n allocate(randu1(dim1))\n call random_number(randu1)\n return\n end function randu1\n\n function randu2(dim1, dim2)\n real(kind = RPRE), dimension(:,:), allocatable :: randu2\n integer(kind = IPRE), intent(in) :: dim1, dim2\n\n allocate(randu2(dim1, dim2))\n call random_number(randu2)\n return\n end function randu2\n\n function randu3(dim1, dim2, dim3)\n real(kind = RPRE), dimension(:,:,:), allocatable :: randu3\n integer(kind = IPRE), intent(in) :: dim1, dim2, dim3\n\n allocate(randu3(dim1, dim2, dim3))\n call random_number(randu3)\n return\n end function randu3\n\n!=======================================================================\n! repmat\n!-----------------------------------------------------------------------\n! repmat repeats copies of arrays.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! A = repmat(x, n1)\n! A = repmat(x, n1, dim)\n! B = repmat(A, n1, n2)\n!\n! Description\n!-----------------------------------------------------------------------\n! A = repmat(x, n1) returns an array A with n1 copies of vector x. x is\n! treated as a column vector, therefore shape(A) = ( size(x), n1 ).\n!\n! A = repmat(x, n1, dim) returns an array A with n1 copies of vector x\n! along the direction specified by dim.\n!\n! B = repmat(A, n1, 2) returns an array B with n1 copies of A in first\n! dimension and n2 copies of B in second dimension.\n!=======================================================================\n\n function repmat1(x, n1, dim)\n real(kind = RPRE), dimension(:,:), allocatable :: repmat1\n real(kind = RPRE), dimension(:), intent(in) :: x\n integer(kind = IPRE), intent(in) :: n1\n integer(kind = IPRE), intent(in), optional :: dim\n integer(kind = IPRE) :: i, m\n\n m = size(x)\n if ((.not. present(dim)) .or. (dim .eq. 1)) then\n repmat1 = zeros(m, n1)\n do i = 1, n1\n repmat1(:,i) = x\n end do\n elseif (dim .eq. 2) then\n repmat1 = zeros(n1, m)\n do i = 1, n1\n repmat1(i,:) = x\n end do\n end if\n return\n end function repmat1\n\n function repmat2(A, n1, n2)\n real(kind = RPRE), dimension(:,:), allocatable :: repmat2\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE), intent(in) :: n1, n2\n integer(kind = IPRE) :: i, j, m, n\n\n m = size(A, 1)\n n = size(A, 2)\n repmat2 = zeros(m*n1, n*n2)\n do i = 1, n1\n do j = 1, n2\n repmat2((i-1)*m+1:i*m,(j-1)*n+1:j*n) = A\n end do\n end do\n return\n end function repmat2\n\n!=======================================================================\n! rms\n!-----------------------------------------------------------------------\n! rms computes the root-mean-square level of an array.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! y = rms(x)\n! x = rms(A)\n! x = rms(A, 1)\n! x = rms(A, 2)\n!\n! Description\n!-----------------------------------------------------------------------\n! y = rms(x) returns the root-mean-square level of the vector x.\n!\n! x = rms(A) returns a dim2 vector with the root-mean-square level of\n! each column of matrix A.\n!\n! x = rms(A, 1) (see x = rms(A)).\n!\n! x = rms(A, 2) returns a dim1 vector with the root-mean-square level of\n! each row of matrix A.\n!=======================================================================\n\n real(kind = RPRE) function rms1(x)\n real(kind = RPRE), dimension(:), intent(in) :: x\n\n rms1 = sqrt( sum(x*x) / size(x) )\n return\n end function rms1\n\n function rms2(A, dim)\n real(kind = RPRE), dimension(:), allocatable :: rms2\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE), intent(in), optional :: dim\n integer(kind = IPRE) :: i, m, n\n\n m = size(A, 1)\n n = size(A, 2)\n if ((.not. present(dim)) .or. (dim .eq. 1)) then\n allocate(rms2(n))\n do i = 1, n\n rms2(i) = rms(A(:,i))\n end do\n elseif (dim .eq. 2) then\n allocate(rms2(m))\n do i = 1, m\n rms2(i) = rms(A(i,:))\n end do\n end if\n return\n end function rms2\n\n!=======================================================================\n! savebin\n!-----------------------------------------------------------------------\n! savebin saves arrays to binary files.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! call savebin(filename, x)\n! call savebin(filename, A)\n! call savebin(filename, X)\n!\n! Description\n!-----------------------------------------------------------------------\n! call savebin(filename, x) saves a vector x into the binary file\n! filename.\n!\n! call savebin(filename, A) saves a 2-dimensional array into the binary\n! file filename.\n!\n! call savebin(filename, X) saves a 3-dimensional array into the binary\n! file filename.\n!=======================================================================\n\n subroutine savebin1_r4(filename, x)\n character(len = *), intent(in) :: filename\n real(kind = 4), dimension(:), intent(in) :: x\n type(File) :: infile\n\n infile = File(999, trim(filename))\n call infile%open(kind(x)*size(x))\n write(infile%unit, rec = 1) x\n call infile%close()\n return\n end subroutine savebin1_r4\n\n subroutine savebin1_r8(filename, x)\n character(len = *), intent(in) :: filename\n real(kind = 8), dimension(:), intent(in) :: x\n type(File) :: infile\n\n infile = File(999, trim(filename))\n call infile%open(kind(x)*size(x))\n write(infile%unit, rec = 1) x\n call infile%close()\n return\n end subroutine savebin1_r8\n\n subroutine savebin2_r4(filename, A)\n character(len = *), intent(in) :: filename\n real(kind = 4), dimension(:,:), intent(in) :: A\n type(File) :: infile\n\n infile = File(999, trim(filename))\n call infile%open(kind(A)*size(A))\n write(infile%unit, rec = 1) A\n call infile%close()\n return\n end subroutine savebin2_r4\n\n subroutine savebin2_r8(filename, A)\n character(len = *), intent(in) :: filename\n real(kind = 8), dimension(:,:), intent(in) :: A\n type(File) :: infile\n\n infile = File(999, trim(filename))\n call infile%open(kind(A)*size(A))\n write(infile%unit, rec = 1) A\n call infile%close()\n return\n end subroutine savebin2_r8\n\n subroutine savebin3_r4(filename, X)\n character(len = *), intent(in) :: filename\n real(kind = 4), dimension(:,:,:), intent(in) :: X\n type(File) :: infile\n\n infile = File(999, trim(filename))\n call infile%open(kind(X)*size(X))\n write(infile%unit, rec = 1) X\n call infile%close()\n return\n end subroutine savebin3_r4\n\n subroutine savebin3_r8(filename, X)\n character(len = *), intent(in) :: filename\n real(kind = 8), dimension(:,:,:), intent(in) :: X\n type(File) :: infile\n\n infile = File(999, trim(filename))\n call infile%open(kind(X)*size(X))\n write(infile%unit, rec = 1) X\n call infile%close()\n return\n end subroutine savebin3_r8\n\n!=======================================================================\n! savetxt\n!-----------------------------------------------------------------------\n! savetxt saves 1 and 2-dimensional arrays to txt files.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! call savetxt(filename, x)\n! call savetxt(filename, A)\n!\n! Description\n!-----------------------------------------------------------------------\n! call savetxt(filename, x) saves a vector array x into the txt file\n! filename.\n!\n! call savetxt(filename, A) saves a 2-dimensional array A into the txt\n! file filename.\n!=======================================================================\n\n subroutine savetxt1_i4(filename, x)\n character(len = *), intent(in) :: filename\n integer(kind = 4), dimension(:), intent(in) :: x\n integer(kind = IPRE) :: i, m\n type(File) :: infile\n\n infile = File(999, trim(filename))\n m = size(x)\n call infile%open()\n do i = 1, m\n write(infile%unit,*) x(i)\n end do\n call infile%close()\n return\n end subroutine savetxt1_i4\n\n subroutine savetxt1_r4(filename, x)\n character(len = *), intent(in) :: filename\n real(kind = 4), dimension(:), intent(in) :: x\n integer(kind = IPRE) :: i, m\n type(File) :: infile\n\n infile = File(999, trim(filename))\n m = size(x)\n call infile%open()\n do i = 1, m\n write(infile%unit,*) x(i)\n end do\n call infile%close()\n return\n end subroutine savetxt1_r4\n\n subroutine savetxt1_i8(filename, x)\n character(len = *), intent(in) :: filename\n integer(kind = 8), dimension(:), intent(in) :: x\n integer(kind = IPRE) :: i, m\n type(File) :: infile\n\n infile = File(999, trim(filename))\n m = size(x)\n call infile%open()\n do i = 1, m\n write(infile%unit,*) x(i)\n end do\n call infile%close()\n return\n end subroutine savetxt1_i8\n\n subroutine savetxt1_r8(filename, x)\n character(len = *), intent(in) :: filename\n real(kind = 8), dimension(:), intent(in) :: x\n integer(kind = IPRE) :: i, m\n type(File) :: infile\n\n infile = File(999, trim(filename))\n m = size(x)\n call infile%open()\n do i = 1, m\n write(infile%unit,*) x(i)\n end do\n call infile%close()\n return\n end subroutine savetxt1_r8\n\n subroutine savetxt2_r4(filename, A)\n character(len = *), intent(in) :: filename\n real(kind = 4), dimension(:,:), intent(in) :: A\n integer(kind = IPRE) :: i, m\n type(File) :: infile\n\n infile = File(999, trim(filename))\n m = size(A, 1)\n call infile%open()\n do i = 1, m\n write(infile%unit,*) A(i,:)\n end do\n call infile%close()\n return\n end subroutine savetxt2_r4\n\n subroutine savetxt2_i4(filename, A)\n character(len = *), intent(in) :: filename\n integer(kind = 4), dimension(:,:), intent(in) :: A\n integer(kind = IPRE) :: i, m\n type(File) :: infile\n\n infile = File(999, trim(filename))\n m = size(A, 1)\n call infile%open()\n do i = 1, m\n write(infile%unit,*) A(i,:)\n end do\n call infile%close()\n return\n end subroutine savetxt2_i4\n\n subroutine savetxt2_r8(filename, A)\n character(len = *), intent(in) :: filename\n real(kind = 8), dimension(:,:), intent(in) :: A\n integer(kind = IPRE) :: i, m\n type(File) :: infile\n\n infile = File(999, trim(filename))\n m = size(A, 1)\n call infile%open()\n do i = 1, m\n write(infile%unit,*) A(i,:)\n end do\n call infile%close()\n return\n end subroutine savetxt2_r8\n\n subroutine savetxt2_i8(filename, A)\n character(len = *), intent(in) :: filename\n integer(kind = 8), dimension(:,:), intent(in) :: A\n integer(kind = IPRE) :: i, m\n type(File) :: infile\n\n infile = File(999, trim(filename))\n m = size(A, 1)\n call infile%open()\n do i = 1, m\n write(infile%unit,*) A(i,:)\n end do\n call infile%close()\n return\n end subroutine savetxt2_i8\n\n!=======================================================================\n! signum\n!-----------------------------------------------------------------------\n! signum returns the sign of an array.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! y = signum(x)\n! Y = signum(X)\n! B = signum(A)\n!\n! Description\n!-----------------------------------------------------------------------\n! y = signum(x) returns the sign of x (scalar).\n!\n! Y = signum(X) returns a vector Y with the signs of each element in the\n! vector X.\n!\n! B = signum(A) returns a matrix B with the signs of each elements in\n! the matrix A.\n!=======================================================================\n\n real(kind = RPRE) function signum0(x)\n real(kind = RPRE), intent(in) :: x\n if (x .lt. 0.0d0) then\n signum0 = -1.0d0\n elseif (x .gt. 0.0d0) then\n signum0 = 1.0d0\n else\n signum0 = 0.0d0\n end if\n return\n end function signum0\n\n function signum1(x)\n real(kind = RPRE), dimension(:), allocatable :: signum1\n real(kind = RPRE), dimension(:), intent(in) :: x\n integer(kind = IPRE) :: i, n\n\n n = size(x)\n signum1 = zeros(n)\n do i = 1, n\n signum1(i) = signum0(x(i))\n end do\n return\n end function signum1\n\n function signum2(A)\n real(kind = RPRE), dimension(:,:), allocatable :: signum2\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE) :: i, j, m, n\n\n m = size(A, 1)\n n = size(A, 2)\n signum2 = zeros(m, n)\n do i = 1, m\n do j = 1, n\n signum2(i,j) = signum0(A(i,j))\n end do\n end do\n return\n end function signum2\n\n!=======================================================================\n! silhouette\n!-----------------------------------------------------------------------\n! silhouette computes the silhouette values for every observations given\n! the clustering indices.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! s = silhouette(x, cluster)\n! s = silhouette(X, cluster)\n!\n! Description\n!-----------------------------------------------------------------------\n! s = silhouette(x, cluster) returns the silhouette values for every\n! elements in the vector x.\n!\n! s = silhouette(X, cluster) returns the silhouette values for every\n! elements in the array X, each row being an observation and each\n! column a parameter.\n!\n! Notes\n!-----------------------------------------------------------------------\n! After Rousseeuw P. J. (1986): \"Silhouettes: a graphical aid to the\n! interpretation and validation of cluster analysis\".\n!=======================================================================\n\n function silhouette1(x, cluster) result(s)\n real(kind = RPRE), dimension(:), allocatable :: s\n real(kind = RPRE), dimension(:), intent(in) :: x\n integer(kind = IPRE), dimension(:), intent(in) :: cluster\n integer(kind = IPRE) :: n\n real(kind = RPRE), dimension(:,:), allocatable :: A\n\n n = size(x)\n A = reshape( x, shape = [ n, 1 ], order = [ 1, 2 ] )\n s = silhouette2(A, cluster)\n return\n end function silhouette1\n\n function silhouette2(X, cluster) result(s)\n real(kind = RPRE), dimension(:), allocatable :: s\n real(kind = RPRE), dimension(:,:), intent(in) :: X\n integer(kind = IPRE), dimension(:), intent(in) :: cluster\n integer(kind = IPRE) :: i, j, K, l, n\n real(kind = RPRE) :: a, b\n integer(kind = IPRE), dimension(:), allocatable :: idx, cs\n real(kind = RPRE), dimension(:), allocatable :: d\n\n n = size(X, 1)\n K = maxval(cluster)\n if ( K .eq. 1 ) then\n print *, \"Warning: in silhouette, the silhouette value cannot \" &\n // \"be defined for K = 1.\"\n s = zeros(n)\n return\n end if\n\n ! Size of each cluster\n !======================\n allocate(cs(K))\n do j = 1, K\n idx = find( cluster .eq. j ) ! All objects in cluster j\n cs(j) = size(idx)\n end do\n\n ! Loop over objects\n !===================\n s = zeros(n)\n do i = 1, n\n\n ! Compute the dissimilarity for each cluster to current object i\n !================================================================\n d = zeros(K) ! Cluster dissimilarity to object i\n do j = 1, K\n idx = find( cluster .eq. j )\n d(j) = sum( ( X(idx,:) - repmat(X(i,:), cs(j), 2) )**2 ) / cs(j)\n end do\n\n ! Compute a(i)\n !==============\n j = cluster(i)\n if ( cs(j) .eq. 1 ) then\n s(i) = 0.0d0\n cycle ! Skip next statements and begin next iteration\n else\n a = d(j) * cs(j) / ( cs(j) - 1 )\n end if\n\n ! Compute b(i)\n !==============\n b = minval(d, mask = d .ne. d(j) .and. d .ne. real(0., RPRE))\n\n ! Compute s(i)\n !==============\n s(i) = (b - a) / max(a, b)\n\n end do\n\n return\n end function silhouette2\n\n!=======================================================================\n! sinc\n!-----------------------------------------------------------------------\n! sinc computes sinc function defined as sinc(x) = sin(pi*x) / (pi*x),\n! with the convention sinc(0) = 1.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! y = sinc(x)\n!\n! Description\n!-----------------------------------------------------------------------\n! y = sinc(x) returns the sinc function of the elements in x.\n!=======================================================================\n\n real(kind = RPRE) function sinc0(x)\n real(kind = RPRE), intent(in) :: x\n real(kind = RPRE) :: y\n\n if ( x .eq. 0.0d0 ) then\n sinc0 = 1.0d0\n else\n y = pi * x\n sinc0 = sin(y) / y\n end if\n return\n end function sinc0\n\n function sinc1(x)\n real(kind = RPRE), dimension(:), allocatable :: sinc1\n real(kind = RPRE), dimension(:), intent(in) :: x\n real(kind = RPRE), dimension(:), allocatable :: y\n\n allocate(y(size(x)))\n y = pi * merge(real(1.0e-20, RPRE), x, x .eq. 0.0d0)\n sinc1 = sin(y) / y\n return\n end function sinc1\n\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\n real(kind = RPRE) function sind0(x)\n real(kind = RPRE), intent(in) :: x\n\n sind0 = sin(x*pi/180.0d0)\n return\n end function sind0\n\n function sind1(x)\n real(kind = RPRE), dimension(:), allocatable :: sind1\n real(kind = RPRE), dimension(:), intent(in) :: x\n\n sind1 = sin(x*pi/180.0d0)\n return\n end function sind1\n\n function sind2(A)\n real(kind = RPRE), dimension(:,:), allocatable :: sind2\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n\n sind2 = sin(A*pi/180.0d0)\n return\n end function sind2\n\n function sind3(X)\n real(kind = RPRE), dimension(:,:,:), allocatable :: sind3\n real(kind = RPRE), dimension(:,:,:), intent(in) :: X\n\n sind3 = sin(X*pi/180.0d0)\n return\n end function sind3\n\n!=======================================================================\n! skewness\n!-----------------------------------------------------------------------\n! skewness computes vector and matrix skewnesses.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! y = skewness(x)\n! y = skewness(x, flag)\n! x = skewness(A)\n! x = skewness(A, flag)\n! x = skewness(A, 1)\n! x = skewness(A, flag, 1)\n! x = skewness(A, 2)\n! x = skewness(A, flag, 2)\n!\n! Description\n!-----------------------------------------------------------------------\n! y = skewness(x) returns the skewness of the vector x.\n!\n! y = skewness(x, w) returns the skewness of the vector x given the\n! flag. By default, flag is 1. If flag is 0, the function corrects for\n! the systematic bias due to the size of the sample.\n!\n! x = skewness(A) returns a dim2 vector with the skewnesses of each\n! column of matrix A.\n!\n! x = skewness(A, flag) returns a dim2 vector given the flag.\n!\n! x = skewness(A, 1) (see x = skewness(A)).\n!\n! x = skewness(A, flag, 1) (see x = skewness(A, flag))\n!\n! x = skewness(A, 2) returns a dim1 vector with the skewnesses of\n! each row of matrix A.\n!\n! x = skewness(A, flag, 2) returns a dim1 vector given the flag.\n!=======================================================================\n\n real(kind = RPRE) function skewness1(x, flag)\n real(kind = RPRE), dimension(:), intent(in) :: x\n integer(kind = IPRE), intent(in), optional :: flag\n integer(kind = IPRE) :: opt_flag, n\n\n opt_flag = 1\n if (present(flag)) opt_flag = flag\n\n n = size(x)\n skewness1 = ( sum( ( x - mean(x) )**3 ) / n ) / ( var(x, 1)**1.5 )\n if (opt_flag .eq. 0) then\n skewness1 = skewness1 * sqrt(real(n*(n-1), RPRE)) / real((n-2), RPRE)\n end if\n return\n end function skewness1\n\n function skewness2(A, flag, dim)\n real(kind = RPRE), dimension(:), allocatable :: skewness2\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE), intent(in), optional :: flag, dim\n integer(kind = IPRE) :: opt_flag, i, m, n\n\n opt_flag = 1\n if (present(flag)) opt_flag = flag\n\n m = size(A, 1)\n n = size(A, 2)\n if ((.not. present(dim)) .or. (dim .eq. 1)) then\n allocate(skewness2(n))\n do i = 1, n\n skewness2(i) = skewness1(A(:,i), opt_flag)\n end do\n elseif (dim .eq. 2) then\n allocate(skewness2(m))\n do i = 1, m\n skewness2(i) = skewness1(A(i,:), opt_flag)\n end do\n end if\n return\n end function skewness2\n\n!=======================================================================\n! solve\n!-----------------------------------------------------------------------\n! solve solves a linear matrix equation.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! x = solve(A, b)\n!\n! Description\n!-----------------------------------------------------------------------\n! x = solve(A, b) returns the \"exact\" solution of the well-determined\n! linear matrix equation Ax = b.\n!\n! Examples\n!-----------------------------------------------------------------------\n! A = reshape([ 11., 7., 3., 2., 12., 6., 7., 9., 4. ], [ 3, 3 ], &\n! order = [ 2, 1 ])\n! b = [ 34., 44., 37. ]\n! x = solve(A, b)\n! 1. 2. 3.\n!=======================================================================\n\n function solve(A, b) result(x)\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n real(kind = RPRE), dimension(:), intent(in) :: b\n integer :: i, j, m, n\n real(kind = RPRE), dimension(:), allocatable :: w, x, y\n real(kind = RPRE), dimension(:,:), allocatable :: L, U, V\n\n m = size(A, 1)\n n = size(A, 2)\n if (issquare(A)) then\n x = zeros(m)\n y = zeros(m)\n y(1) = b(1)\n\n ! LU decomposition to solve LUx = b\n !===================================\n call lu(A, L, U)\n\n ! Forward substitution: Ly = b\n !==============================\n do i = 2, m\n y(i) = b(i)\n do j = 1, i-1\n y(i) = y(i) - y(j)*L(i,j)\n end do\n end do\n\n ! Back substitution: Ux = y\n !===========================\n x(m) = y(m)/U(m,m)\n do i = m-1, 1, -1\n x(i) = y(i)\n do j = m, i+1, -1\n x(i) = x(i) - x(j)*U(i,j)\n end do\n x(i) = x(i)/U(i,i)\n end do\n else\n x = svdsolve(A, b)\n end if\n return\n end function solve\n\n!=======================================================================\n! sort\n!-----------------------------------------------------------------------\n! sort sorts arrays elements.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! y = sort(x)\n! y = sort(x, 1)\n! y = sort(x, 2)\n!\n! Description\n!-----------------------------------------------------------------------\n! y = sort(x) returns the sorted elements of the vector x in the\n! ascending order.\n!\n! y = sort(x, 1) (see y = sort(x)).\n!\n! y = sort(x, 2) returns the sorted elements of the vector x in the\n! descending order.\n!=======================================================================\n\n function sort(x, order)\n real(kind = RPRE), dimension(:), allocatable :: sort\n real(kind = RPRE), dimension(:), intent(in) :: x\n integer(kind = IPRE), intent(in), optional :: order\n integer(kind = IPRE) :: n\n\n n = size(x)\n sort = x\n if ((.not. present(order)) .or. (order .eq. 1)) then\n call quicksort(sort, n, 1)\n elseif (order .eq. 2) then\n call quicksort(sort, n, 2)\n end if\n return\n\n contains\n\n !-------------------------------------------------------------------\n ! quicksort\n !-------------------------------------------------------------------\n recursive subroutine quicksort(x, n, order)\n real(kind = RPRE), dimension(n), intent(inout) :: x\n integer(kind = IPRE), intent(in) :: n, order\n integer(kind = IPRE) :: left, right, marker\n real(kind = RPRE) :: pivot, tmp\n\n if (n .gt. 1) then\n left = 0\n right = n + 1\n pivot = x(randi(n))\n\n select case(order)\n case(1)\n do while ( left .lt. right )\n left = left + 1\n right = right - 1\n do while ( x(left) .lt. pivot )\n left = left + 1\n end do\n do while ( x(right) .gt. pivot )\n right = right - 1\n end do\n if ( left .lt. right ) then\n tmp = x(left)\n x(left) = x(right)\n x(right) = tmp\n end if\n end do\n case(2)\n do while ( left .lt. right )\n left = left + 1\n right = right - 1\n do while ( x(left) .gt. pivot )\n left = left + 1\n end do\n do while ( x(right) .lt. pivot )\n right = right - 1\n end do\n if ( left .lt. right ) then\n tmp = x(left)\n x(left) = x(right)\n x(right) = tmp\n end if\n end do\n end select\n\n if ( left .eq. right ) then\n marker = left + 1\n else\n marker = left\n end if\n\n call quicksort(x(:marker-1), marker-1, order)\n call quicksort(x(marker:), n-marker+1, order)\n end if\n return\n end subroutine quicksort\n\n end function sort\n\n!=======================================================================\n! spline1\n!-----------------------------------------------------------------------\n! spline1 performs a cubic spline interpolation with natural end\n! condition.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! yq = spline1(x, y, xq)\n!\n! Description\n!-----------------------------------------------------------------------\n! yq = spline1(x, y, xq) returns the evaluated vector yq at the query\n! points in xq using a cubic spline interpolation.\n!=======================================================================\n\n real(kind = RPRE) function spline1_0(x, y, xq) result(yq)\n real(kind = RPRE), dimension(:), intent(in) :: x, y\n real(kind = RPRE), intent(in) :: xq\n real(kind = RPRE) :: tmp(1)\n\n tmp = spline1(x, y, [ xq ])\n yq = tmp(1)\n return\n end function spline1_0\n\n function spline1_1(x, y, xq) result(yq)\n real(kind = RPRE), dimension(:), allocatable :: yq\n real(kind = RPRE), dimension(:), intent(in) :: x, y, xq\n integer(kind = IPRE) :: i, n, nq, x1\n real(kind = RPRE), dimension(:), allocatable :: w, h, z, a, b, c, d\n\n n = size(x)\n nq = size(xq)\n allocate(w(n-1), h(n-1), z(n), a(n-1), b(n-1), c(n-1), d(n-1), yq(nq))\n\n ! Compute h and b\n !=================\n do i = 1, n-1\n w(i) = x(i+1) - x(i)\n h(i) = ( y(i+1) - y(i) ) / w(i)\n end do\n\n ! Compute z\n !===========\n z(1) = 0.0d0\n do i = 1, n-2\n z(i+1) = 3.0d0 * ( h(i+1) - h(i) ) / ( w(i+1) + w(i) )\n end do\n z(n) = 0.0d0\n\n ! Basis functions\n !=================\n do i = 1, n-1\n a(i) = ( z(i+1) - z(i) ) / ( 6.0d0 * w(i) )\n b(i) = 0.5d0 * z(i)\n c(i) = h(i) - w(i) * ( z(i+1) + 2.0d0*z(i) ) / 6.0d0\n d(i) = y(i)\n end do\n\n ! Evaluate\n !==========\n do i = 1, nq\n x1 = max(1, minloc(xq(i) - x, 1, mask = xq(i) .gt. x))\n yq(i) = d(x1) + ( xq(i) - x(x1) ) &\n * ( c(x1) + ( xq(i) - x(x1) ) &\n * ( b(x1) + ( xq(i) - x(x1) ) &\n * a(x1) ) )\n end do\n return\n end function spline1_1\n\n!=======================================================================\n! spline2\n!-----------------------------------------------------------------------\n! spline2 performs a bicubic spline interpolation with natural end\n! condition.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! zq = spline2(x, y, Z, xq, yq)\n! ZQ = spline2(x, y, Z, XQ, YQ)\n!\n! Description\n!-----------------------------------------------------------------------\n! zq = spline2(x, y, Z, xq, yq) returns the evaluated vector zq at the\n! query points in xq and yq using a bicubic interpolation.\n!\n! ZQ = spline2(x, y, Z, XQ, YQ) returns the evaluated matrix ZQ given\n! mesh type grids XQ and YQ using a bicubic interpolation. ZQ is of the\n! same shape as XQ and YQ.\n!=======================================================================\n\n function spline2_1(x, y, z, xq, yq) result(zq)\n real(kind = RPRE), dimension(:), allocatable :: zq\n real(kind = RPRE), dimension(:), intent(in) :: x, y, xq, yq\n real(kind = RPRE), dimension(:,:), intent(in) :: z\n integer(kind = IPRE) :: i, iq, j, k, m, n, nq, x0, y0\n real(kind = RPRE) :: wt(16,16), zv(16), c(4,4), dx, dy, t, u\n real(kind = RPRE), dimension(:,:), allocatable :: zt, z1, z2, z12\n\n m = size(x)\n n = size(y)\n nq = size(xq)\n\n ! Work on the transpose so that x corresponds to the 2nd dimension\n ! and y to the 1st dimension\n !==================================================================\n zt = transpose(z)\n\n ! Inverted coefficient matrix\n !=============================\n wt = reshape( [ 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., &\n 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., &\n -3., 3., 0., 0.,-2.,-1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., &\n 2.,-2., 0., 0., 1., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., &\n 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., &\n 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., &\n 0., 0., 0., 0., 0., 0., 0., 0.,-3., 3., 0., 0.,-2.,-1., 0., 0., &\n 0., 0., 0., 0., 0., 0., 0., 0., 2.,-2., 0., 0., 1., 1., 0., 0., &\n -3., 0., 3., 0., 0., 0., 0., 0.,-2., 0.,-1., 0., 0., 0., 0., 0., &\n 0., 0., 0., 0.,-3., 0., 3., 0., 0., 0., 0., 0.,-2., 0.,-1., 0., &\n 9.,-9.,-9., 9., 6., 3.,-6.,-3., 6.,-6., 3.,-3., 4., 2., 2., 1., &\n -6., 6., 6.,-6.,-3.,-3., 3., 3.,-4., 4.,-2., 2.,-2.,-2.,-1.,-1., &\n 2., 0.,-2., 0., 0., 0., 0., 0., 1., 0., 1., 0., 0., 0., 0., 0., &\n 0., 0., 0., 0., 2., 0.,-2., 0., 0., 0., 0., 0., 1., 0., 1., 0., &\n -6., 6., 6.,-6.,-4.,-2., 4., 2.,-3., 3.,-3., 3.,-2.,-1.,-2.,-1., &\n 4.,-4.,-4., 4., 2., 2.,-2.,-2., 2.,-2., 2.,-2., 1., 1., 1., 1. ], &\n shape = [ 16, 16 ], order = [ 2, 1 ] )\n\n ! Compute partial derivatives along x-axis and y-axis, and cross\n ! derivatives\n !================================================================\n call zdiff(x, y, zt, z1, z2, z12)\n\n ! Loop for each query point\n !===========================\n zq = zeros(nq)\n\n do iq = 1, nq\n\n ! Locate the query point\n !========================\n x0 = minloc(xq(iq) - x, 1, mask = xq(iq) .ge. x)\n y0 = minloc(yq(iq) - y, 1, mask = yq(iq) .ge. y)\n dx = x(x0+1) - x(x0)\n dy = y(y0+1) - y(y0)\n\n ! Build zv so that wt\u00b7zv = c, the cubic basis coefficients\n !==========================================================\n zv = [ zt(x0,y0), &\n zt(x0+1,y0), &\n zt(x0,y0+1), &\n zt(x0+1,y0+1), &\n z1(x0,y0)*dx, &\n z1(x0+1,y0)*dx, &\n z1(x0,y0+1)*dx, &\n z1(x0+1,y0+1)*dx, &\n z2(x0,y0)*dy, &\n z2(x0+1,y0)*dy, &\n z2(x0,y0+1)*dy, &\n z2(x0+1,y0+1)*dy, &\n z12(x0,y0)*dx*dy, &\n z12(x0+1,y0)*dx*dy, &\n z12(x0,y0+1)*dx*dy, &\n z12(x0+1,y0+1)*dx*dy ]\n\n ! Solve for c\n !=============\n c = reshape( matmul(wt, zv), shape = [ 4, 4 ], order = [ 1, 2 ] )\n\n ! Scaling coefficients so that 0 <= (t, u) <= 1\n !===============================================\n t = ( xq(iq) - x(x0) ) / dx\n u = ( yq(iq) - y(y0) ) / dy\n\n ! Evaluate at the query point\n !=============================\n do i = 1, 4\n do j = 1, 4\n zq(iq) = zq(iq) + c(i,j) * t**(i-1) * u**(j-1)\n end do\n end do\n\n end do\n return\n\n contains\n\n !-------------------------------------------------------------------\n ! zdiff\n !-------------------------------------------------------------------\n subroutine zdiff(x, y, zt, z1, z2, z12)\n real(kind = RPRE), dimension(:), intent(in) :: x, y\n real(kind = RPRE), dimension(:,:), intent(in) :: zt\n real(kind = RPRE), dimension(:,:), allocatable, intent(out) :: z1, z2, z12\n\n allocate(z1(m, n), z2(m, n), z12(m, n))\n\n ! Middle\n !========\n do j = 2, m-1\n do k = 2, n-1\n z1(j,k) = ( zt(j+1,k) - zt(j-1,k) ) / ( x(j+1) - x(j-1) )\n z2(j,k) = ( zt(j,k+1) - zt(j,k-1) ) / ( y(k+1) - y(k-1) )\n z12(j,k) = ( zt(j+1,k+1) - zt(j+1,k-1) - zt(j-1,k+1) + zt(j-1,k-1) ) &\n / ( ( x(j+1) - x(j-1) ) * ( y(k+1) - y(k-1) ) )\n end do\n end do\n\n ! Left edge\n !===========\n do j = 2, m-1\n z1(j,1) = ( zt(j+1,1) - zt(j,1) ) / ( x(j+1) - x(j) )\n z2(j,1) = ( zt(j,2) - zt(j,1) ) / ( y(2) - y(1) )\n z12(j,1) = ( zt(j+1,2) - zt(j+1,1) - zt(j,2) + zt(j,1) ) &\n / ( ( x(j+1) - x(j) ) * ( y(2) - y(1) ) )\n end do\n\n ! Upper edge\n !============\n do k = 2, n-1\n z1(1,k) = ( zt(2,k) - zt(1,k) ) / ( x(2) - x(1) )\n z2(1,k) = ( zt(1,k+1) - zt(1,k) ) / ( y(k+1) - y(k) )\n z12(1,k) = ( zt(2,k+1) - zt(2,k) - zt(1,k+1) + zt(1,k) ) &\n / ( ( x(2) - x(1) ) * ( y(k+1) - y(k) ) )\n end do\n\n ! Right edge\n !============\n do j = 2, m-1\n z1(j,n) = ( zt(j+1,n) - zt(j,n) ) / ( x(j+1) - x(j) )\n z2(j,n) = ( zt(j,n) - zt(j,n-1) ) / ( y(n) - y(n-1) )\n z12(j,n) = ( zt(j+1,n) - zt(j+1,n-1) - zt(j,n) + zt(j,n-1) ) &\n / ( ( x(j+1) - x(j) ) * ( y(n) - y(n-1) ) )\n end do\n\n ! Lower edge\n !============\n do k = 2, n-1\n z1(m,k) = ( zt(m,k) - zt(m-1,k) ) / ( x(m) - x(m-1) )\n z2(m,k) = ( zt(m,k+1) - zt(m,k) ) / ( y(k+1) - y(k) )\n z12(m,k) = ( zt(m,k+1) - zt(m,k) - zt(m-1,k+1) + zt(m-1,k) ) &\n / ( ( x(m) - x(m-1) ) * ( y(k+1) - y(k) ) )\n end do\n\n ! Upper-left corner\n !===================\n z1(1,1) = ( zt(2,1) - zt(1,1) ) / ( x(2) - x(1) )\n z2(1,1) = ( zt(1,2) - zt(1,1) ) / ( y(2) - y(1) )\n z12(1,1) = ( zt(2,2) - zt(2,1) - zt(1,2) + zt(1,1) ) &\n / ( ( x(2) - x(1) ) * ( y(2) - y(1) ) )\n\n ! Upper-right corner\n !====================\n z1(1,n) = ( zt(2,n) - zt(1,n) ) / ( x(2) - x(1) )\n z2(1,n) = ( zt(1,n) - zt(1,n-1) ) / ( y(n) - y(n-1) )\n z12(1,n) = ( zt(2,n) - zt(2,n-1) - zt(1,n) + zt(1,n-1) ) &\n / ( ( x(2) - x(1) ) * ( y(n) - y(n-1) ) )\n\n ! Lower-left corner\n !===================\n z1(m,1) = ( zt(m,1) - zt(m-1,1) ) / ( x(m) - x(m-1) )\n z2(m,1) = ( zt(m,2) - zt(m,1) ) / ( y(2) - y(1) )\n z12(m,1) = ( zt(m,2) - zt(m,1) - zt(m-1,2) + zt(m-1,1) ) &\n / ( ( x(m) - x(m-1) ) * ( y(2) - y(1) ) )\n\n ! Lower-right corner\n !====================\n z1(m,n) = ( zt(m,n) - zt(m-1,n) ) / ( x(m) - x(m-1) )\n z2(m,n) = ( zt(m,n) - zt(m,n-1) ) / ( y(n) - y(n-1) )\n z12(m,n) = ( zt(m,n) - zt(m,n-1) - zt(m-1,n) + zt(m-1,n-1) ) &\n / ( ( x(m) - x(m-1) ) * ( y(m) - y(m-1) ) )\n\n return\n end subroutine zdiff\n\n end function spline2_1\n\n function spline2_2(x, y, z, xq, yq) result(zq)\n real(kind = RPRE), dimension(:,:), allocatable :: zq\n real(kind = RPRE), dimension(:), intent(in) :: x, y\n real(kind = RPRE), dimension(:,:), intent(in) :: z, xq, yq\n integer(kind = IPRE) :: m, n\n\n m = size(xq, 1)\n n = size(xq, 2)\n zq = reshape( spline2_1(x, y, z, [ xq ], [ yq ]), shape = [ m, n ] )\n return\n end function spline2_2\n\n!=======================================================================\n! split_argument\n!-----------------------------------------------------------------------\n! split_argument takes a command line argument of type 'argname=argval'\n! (obtained by get_command_argument) and returns argname and argval.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! call split_argument(argin, argname, argval)\n!\n! Description\n!-----------------------------------------------------------------------\n! call split_argument(argin, argname, argval) splits argin into argname\n! and argval as strings.\n!\n! Examples\n!-----------------------------------------------------------------------\n! nargin = command_argument_count()\n! do i = 1, nargin\n! call get_command_argument(i, argin)\n! call split_argument(argin, argname, argval)\n! print *, argname, argval\n! end do\n!=======================================================================\n\n subroutine split_argument(argin, argname, argval)\n character(len = *), intent(in) :: argin\n character(len = :), allocatable, intent(out) :: argname, argval\n integer(kind = IPRE) :: idx\n\n idx = index(argin, \"=\")\n if (idx .ne. 0 ) then\n argname = trim(argin(:idx-1))\n argval = trim(argin(idx+1:))\n else\n print *, \"Error: missing '=' in argument '\" // trim(argin) // \"'\"\n stop\n end if\n return\n end subroutine split_argument\n\n!=======================================================================\n! std\n!-----------------------------------------------------------------------\n! std computes vector and matrix standard deviations.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! y = std(x)\n! y = std(x, w)\n! x = std(A)\n! x = std(A, w)\n! x = std(A, 1)\n! x = std(A, w, 1)\n! x = std(A, 2)\n! x = std(A, w, 2)\n!\n! Description\n!-----------------------------------------------------------------------\n! y = std(x) returns the standard deviation of the vector x.\n!\n! y = std(x, w) returns the standard deviation of the vector x with the\n! normalization option w.\n! - 0 (default) normalize by N-1,\n! - 1 normalize by N.\n!\n! x = std(A) returns a dim2 vector with the standard deviations of each\n! column of matrix A.\n!\n! x = std(A, w) returns a dim2 vector with the normalization option w.\n!\n! x = std(A, 1) (see x = std(A)).\n!\n! x = std(A, w, 1) (see x = std(A, w))\n!\n! x = std(A, 2) returns a dim1 vector with the standard deviations of\n! each row of matrix A.\n!\n! x = std(A, w, 2) returns a dim1 vector with the normalization option\n! w.\n!=======================================================================\n\n real(kind = RPRE) function std1(x, w)\n real(kind = RPRE), dimension(:), intent(in) :: x\n integer(kind = IPRE), intent(in), optional :: w\n integer(kind = IPRE) :: opt_w\n\n opt_w = 0\n if (present(w)) opt_w = w\n\n std1 = sqrt(var(x, opt_w))\n return\n end function std1\n\n function std2(A, w, dim)\n real(kind = RPRE), dimension(:), allocatable :: std2\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE), intent(in), optional :: w, dim\n integer(kind = IPRE) :: opt_w\n\n opt_w = 0\n if (present(w)) opt_w = w\n\n if (.not. present(dim)) then\n std2 = sqrt(var(A, opt_w))\n else\n std2 = sqrt(var(A, opt_w, dim))\n end if\n return\n end function std2\n\n!=======================================================================\n! svd\n!-----------------------------------------------------------------------\n! svd computes the singular value decomposition.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! call svd(A, w)\n! call svd(A, w, U, V)\n!\n! Description\n!-----------------------------------------------------------------------\n! call svd(A, w) returns the singular values of the matrix A sorted in\n! descending order.\n!\n! call svd(A, w, U, V) returns the singular values of the m-by-n\n! matrix A sorted in descending order. The output matrices are:\n! - w is a n vector\n! - U is a m-by-n unitary matrix\n! - V is a n-by-n unitary matrix\n!\n! Examples\n!-----------------------------------------------------------------------\n! A = reshape([ 1., 2., 3., 4., 5., 6., 7., 8., 9. ], [ 3, 3 ], &\n! order = [ 2, 1 ])\n! call svd(A, w)\n! call disp(w)\n! 16.8481007 1.06836963 2.10855418E-07\n! call svd(A, w, U, V)\n! call disp(U)\n! -0.214837193 -0.887230873 -0.408247918\n! -0.520587385 -0.249643773 -0.816496670\n! -0.826337695 0.387942642 0.408248365\n! call disp(V)\n! -0.479671091 0.776690900 -0.408248752\n! -0.572367728 0.075686932 0.816496611\n! -0.665064454 -O.625318289 -0.408247977\n!\n! Notes\n!-----------------------------------------------------------------------\n! This code is adapted from Numerical Recipes in Fortran 90.\n!=======================================================================\n\n subroutine svd(a, w, u, v, d, ierr)\n real(kind = RPRE), dimension(:,:), intent(in) :: a\n real(kind = RPRE), dimension(:), allocatable, intent(out) :: w\n real(kind = RPRE), dimension(:,:), allocatable, intent(out), optional :: u, v\n logical, intent(in), optional :: d\n integer(kind = IPRE), intent(out), optional :: ierr\n integer(kind = IPRE) :: m, n, i, its, i1, j, k, kk, k1, l, ll, l1, mn\n integer(kind = IPRE), dimension(:), allocatable :: idx\n real(kind = RPRE) :: c, f, g, h, s, scale, tst1, tst2, x, y, z\n real(kind = RPRE), dimension(:), allocatable :: rv1\n real(kind = RPRE), dimension(:,:), allocatable :: opt_u, opt_v\n logical :: outu = .false., outv = .false., opt_d = .true., outierr = .false.\n\n m = size(a, 1)\n n = size(a, 2)\n\n if (.not. allocated(w)) allocate(w(n))\n allocate(rv1(n), opt_u(m, n), opt_v(n, n))\n\n opt_u = a\n\n if (present(d)) opt_d = d\n if (present(u)) outu = .true.\n if (present(v)) outv = .true.\n if (present(ierr)) outierr = .true.\n\n ! Householder reduction to bidiagonal form\n !==========================================\n g = 0.0d0\n scale = 0.0d0\n x = 0.0d0\n\n do i = 1, n\n l = i + 1\n rv1(i) = scale*g\n g = 0.0d0\n s = 0.0d0\n scale = 0.0d0\n if (i .le. m) then\n scale = sum(abs(opt_u(i:m,i)))\n if (scale .ne. 0.0d0) then\n opt_u(i:m,i) = opt_u(i:m,i)/scale\n s = sum(opt_u(i:m,i)**2)\n f = opt_u(i,i)\n g = -sign(sqrt(s), f)\n h = f*g - s\n opt_u(i,i) = f - g\n if (i .ne. n) then\n do j = l, n\n s = dot_product(opt_u(i:m,i), opt_u(i:m,j))\n opt_u(i:m,j) = opt_u(i:m,j) + s*opt_u(i:m,i)/h\n end do\n end if\n opt_u(i:m,i) = scale*opt_u(i:m,i)\n end if\n end if\n\n w(i) = scale*g\n g = 0.0d0\n s = 0.0d0\n scale = 0.0d0\n\n if ((i .le. m) .and. (i .ne. n)) then\n scale = sum(abs(opt_u(i,l:n)))\n if (scale .ne. 0.0d0) then\n opt_u(i,l:n) = opt_u(i,l:n)/scale\n s = sum(opt_u(i,l:n)**2)\n f = opt_u(i,l)\n g = -sign(sqrt(s), f)\n h = f*g - s\n opt_u(i,l) = f - g\n rv1(l:n) = opt_u(i,l:n)/h\n\n if (i .ne. m) then\n do j = l, m\n s = dot_product(opt_u(j,l:n), opt_u(i,l:n))\n opt_u(j,l:n) = opt_u(j,l:n) + s*rv1(l:n)\n end do\n end if\n\n opt_u(i,l:n) = scale*opt_u(i,l:n)\n end if\n end if\n\n x = max(x, abs(w(i)) + abs(rv1(i)))\n end do\n\n ! Accumulation of right-hand transformations\n !============================================\n if (outv) then\n do i = n, 1, -1\n if (i .ne. n) then\n if (g .ne. 0.0d0) then\n opt_v(l:n,i) = (opt_u(i,l:n)/opt_u(i,l))/g\n do j = l, n\n s = dot_product(opt_u(i,l:n), opt_v(l:n,j))\n opt_v(l:n,j) = opt_v(l:n,j) + s*opt_v(l:n,i)\n end do\n end if\n opt_v(i,l:n) = 0.0d0\n opt_v(l:n,i) = 0.0d0\n end if\n opt_v(i,i) = 1.0d0\n g = rv1(i)\n l = i\n end do\n end if\n\n ! Accumulation of left-hand transformations\n !===========================================\n if (outu) then\n mn = min(m, n)\n do i = min(m, n), 1, -1\n l = i + 1\n g = w(i)\n if (i .ne. n) opt_u(i,l:n) = 0.0d0\n if (g .ne. 0.0d0) then\n if (i .ne. mn) then\n do j = l, n\n s = dot_product(opt_u(l:m,i), opt_u(l:m,j))\n f = (s/opt_u(i,i))/g\n opt_u(i:m,j) = opt_u(i:m,j) + f*opt_u(i:m,i)\n end do\n end if\n opt_u(i:m,i) = opt_u(i:m,i)/g\n else\n opt_u(i:m,i) = 0.0d0\n end if\n opt_u(i,i) = opt_u(i,i) + 1.0d0\n end do\n end if\n\n ! Diagonalization of the bidiagonal form\n !========================================\n tst1 = x\n do kk = 1, n\n k1 = n - kk\n k = k1 + 1\n its = 0\n\n ! Test for splitting\n !====================\n 520 continue\n do ll = 1, k\n l1 = k - ll\n l = l1 + 1\n tst2 = tst1 + abs(rv1(l))\n if (tst2 .eq. tst1) goto 565\n tst2 = tst1 + abs(w(l1))\n if (tst2 .eq. tst1) exit\n end do\n\n ! Cancellation of rv1(l) if L greater than 1\n !============================================\n c = 0.0d0\n s = 1.0d0\n do i = l, k\n f = s*rv1(i)\n rv1(i) = c*rv1(i)\n tst2 = tst1 + abs(f)\n if (tst2 .eq. tst1) goto 565\n g = w(i)\n h = pythag(f, g)\n w(i) = h\n c = g/h\n s = -f/h\n if (outu) then\n do j = 1, m\n y = opt_u(j,l1)\n z = opt_u(j,i)\n opt_u(j,l1) = y*c + z*s\n opt_u(j,i) = -y*s + z*c\n end do\n end if\n end do\n\n ! Test for convergence\n !======================\n 565 continue\n z = w(k)\n if (l .eq. k) goto 650\n\n ! Shift from bottom 2 by 2 minor\n !================================\n if (its .ge. 30) then\n if (outierr) ierr = k\n return\n end if\n its = its + 1\n x = w(l)\n y = w(k1)\n g = rv1(k1)\n h = rv1(k)\n f = 0.5d0*(((g+z)/h)*((g-z)/y) + y/h - h/y)\n g = pythag(f, real(1., kind = RPRE))\n f = x - (z/x)*z + (h/x)*(y/(f + sign(g, f)) - h)\n\n ! Next QR transformation\n !========================\n c = 1.0d0\n s = 1.0d0\n do i1 = l, k1\n i = i1 + 1\n g = rv1(i)\n y = w(i)\n h = s*g\n g = c*g\n z = pythag(f, h)\n rv1(i1) = z\n c = f/z\n s = h/z\n f = x*c + g*s\n g = -x*s + g*c\n h = y*s\n y = y*c\n if (outv) then\n do j = 1, n\n x = opt_v(j,i1)\n z = opt_v(j,i)\n opt_v(j,i1) = x*c + z*s\n opt_v(j,i) = -x*s + z*c\n end do\n end if\n z = pythag(f, h)\n w(i1) = z\n\n ! Rotation can be arbitrary if Z is zero\n !========================================\n if (z .ne. 0.0d0) then\n c = f/z\n s = h/z\n end if\n f = c*g + s*y\n x = -s*g + c*y\n if (outu) then\n do j = 1, m\n y = opt_u(j,i1)\n z = opt_u(j,i)\n opt_u(j,i1) = y*c + z*s\n opt_u(j,i) = - y*s + z*c\n end do\n end if\n end do\n rv1(l) = 0.0d0\n rv1(k) = f\n w(k) = x\n go to 520\n\n ! Convergence\n !=============\n 650 continue\n if (z .le. 0.0d0) then\n w(k) = -z\n if (outv) then\n opt_v(1:n,k) = -opt_v(1:n,k)\n end if\n end if\n end do\n\n ! Sort singular values\n !======================\n if ( opt_d ) then\n idx = argsort(w, 2)\n w = w(idx)\n if (present(u)) u = opt_u(:,idx)\n if (present(v)) v = opt_v(:,idx)\n else\n if (present(u)) u = opt_u\n if (present(v)) v = opt_v\n end if\n\n return\n\n contains\n\n !-------------------------------------------------------------------\n ! pythag\n !-------------------------------------------------------------------\n real(kind = RPRE) function pythag(x1, x2)\n real(kind = RPRE), intent(in) :: x1, x2\n real(kind = RPRE) :: r, s, t, u\n\n pythag = max(abs(x1), abs(x2))\n if (pythag .ne. 0.0d0) then\n r = (min(abs(x1), abs(x2))/pythag)**2\n do\n t = 4.0d0 + r\n if (t .eq. 4.0d0) exit\n s = r/t\n u = 1.0d0 + 2.0d0*s\n pythag = u*pythag\n r = (s/u)**2*r\n end do\n end if\n return\n end function pythag\n\n end subroutine svd\n\n!=======================================================================\n! svdsolve\n!-----------------------------------------------------------------------\n! svdsolve solves a linear matrix equation from the singular value\n! decomposition of A.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! x = svdsolve(A, b)\n! x = svdsolve(A, b, k)\n!\n! Description\n!-----------------------------------------------------------------------\n! x = svdsolve(A, b) returns the full-rank solution of the linear matrix\n! equation Ax = b.\n!\n! x = svdsolve(A, b, k) returns the reduced-rank solution of the linear\n! matrix equation Ax = b, where A is a m-by-n matrix. Therefore, the\n! rank of the solution is n-k.\n!\n! Notes\n!-----------------------------------------------------------------------\n! Sometimes, too small singular values produce very large solution. A\n! proper way to determine the cut-off singular value is using a L-curve\n! criterion. The cut-off singular value corresponds to the singular\n! value from which the residuals norm is not improved while the solution\n! norm increases substantially.\n!=======================================================================\n\n function svdsolve(A, b, cutoff) result(x)\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n real(kind = RPRE), dimension(:), intent(in) :: b\n integer(kind = IPRE), intent(in), optional :: cutoff\n integer :: i, k, n\n real(kind = RPRE), dimension(:), allocatable :: w, x, xnorm, resnorm\n real(kind = RPRE), dimension(:,:), allocatable :: U, V\n\n n = size(A, 2)\n k = n\n if (present(cutoff)) k = k - cutoff\n xnorm = zeros(n)\n resnorm = zeros(n)\n call svd(A, w, U, V)\n do i = 1, n\n x = matmul(matmul(matmul(V(:,:i), diag(1/w(:i))), transpose(U(:,:i))), b)\n xnorm(i) = norm(x)\n resnorm(i) = norm(matmul(A, x) - b)\n end do\n x = matmul(matmul(matmul(V(:,:k), diag(1/w(:k))), transpose(U(:,:k))), b)\n return\n end function svdsolve\n\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!=======================================================================\n\n real(kind = RPRE) function tand0(x)\n real(kind = RPRE), intent(in) :: x\n\n tand0 = tan(x*pi/180.0d0)\n return\n end function tand0\n\n function tand1(x)\n real(kind = RPRE), dimension(:), allocatable :: tand1\n real(kind = RPRE), dimension(:), intent(in) :: x\n\n tand1 = tan(x*pi/180.0d0)\n return\n end function tand1\n\n function tand2(A)\n real(kind = RPRE), dimension(:,:), allocatable :: tand2\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n\n tand2 = tan(A*pi/180.0d0)\n return\n end function tand2\n\n function tand3(X)\n real(kind = RPRE), dimension(:,:,:), allocatable :: tand3\n real(kind = RPRE), dimension(:,:,:), intent(in) :: X\n\n tand3 = tan(X*pi/180.0d0)\n return\n end function tand3\n\n!=======================================================================\n! tic / toc\n!-----------------------------------------------------------------------\n! tic saves the elapsed CPU time in seconds.\n! toc displays and returns the elapsed time since tic.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! call tic()\n! call toc()\n! call toc(t)\n!\n! Description\n!-----------------------------------------------------------------------\n! call tic() saves the elapsed CPU time in seconds.\n!\n! call toc() displays the elapsed time since call tic().\n!\n! call toc(t) displays and saves the elapsed time since call tic().\n!\n! Examples\n!-----------------------------------------------------------------------\n! call tic()\n! ! ... some codes ...\n! call toc()\n! Elapsed time: 0.1 seconds\n!=======================================================================\n\n subroutine tic()\n integer(kind = IPRE) :: values(8)\n call date_and_time(values = values)\n tic_time = datenum( values(1), values(2), values(3), values(5), &\n values(6), values(7), values(8) * 1000) &\n * 24.0d0 * 60.0d0 * 60.0d0\n return\n end subroutine tic\n\n subroutine toc(t)\n real(kind = 8), intent(out), optional :: t\n integer(kind = IPRE) :: values(8)\n real(kind = 8) :: toc_time, elapsed_time\n\n call date_and_time(values = values)\n toc_time = datenum( values(1), values(2), values(3), values(5), &\n values(6), values(7), values(8) * 1000) &\n * 24.0d0 * 60.0d0 * 60.0d0\n elapsed_time = toc_time - tic_time\n if (present(t)) then\n t = elapsed_time\n else\n print *, \"Elapsed time: \" &\n // num2str(real(elapsed_time, kind = RPRE), \"(F12.3)\") &\n // \" seconds\"\n end if\n return\n end subroutine toc\n\n!=======================================================================\n! trace\n!-----------------------------------------------------------------------\n! trace computes the sum of diagonal elements.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! x = trace(A)\n!\n! Description\n!-----------------------------------------------------------------------\n! x = trace(A) returns the sum of the elements on the main diagonal of\n! the matrix A.\n!\n! Examples\n!-----------------------------------------------------------------------\n! A = eye(3)\n! x = trace(A)\n! 3.\n!=======================================================================\n\n real(kind = RPRE) function trace(A)\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n\n trace = sum(diag(A))\n return\n end function trace\n\n!=======================================================================\n! tril\n!-----------------------------------------------------------------------\n! tril extracts the lower triangular part of a matrix.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! B = tril(A)\n! B = tril(A, k)\n!\n! Description\n!-----------------------------------------------------------------------\n! B = tril(A) returns the lower triangular part of matrix A.\n!\n! B = tril(A, k) returns the elements on and below the kth diagonal of\n! matrix X:\n! - k = 0 is the main diagonal,\n! - k > 0 is above the main diagonal,\n! - k < 0 is below the main diagonal.\n!\n! Examples\n!-----------------------------------------------------------------------\n! A = ones(4, 4)\n! B = tril(A, -1)\n! 0. 0. 0. 0.\n! 1. 0. 0. 0.\n! 1. 1. 0. 0.\n! 1. 1. 1. 0.\n!=======================================================================\n\n function tril_i(A, k)\n integer(kind = IPRE), dimension(:,:), allocatable :: tril_i\n integer(kind = IPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE), intent(in), optional :: k\n integer(kind = IPRE) :: opt_k, i, m, n\n\n opt_k = 0\n if (present(k)) opt_k = k\n\n m = size(A, 1)\n n = size(A, 2)\n tril_i = A\n do i = 1, min(m, n)\n tril_i(:i-opt_k-1,i) = 0.0d0\n end do\n return\n end function tril_i\n\n function tril_r(A, k)\n real(kind = RPRE), dimension(:,:), allocatable :: tril_r\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE), intent(in), optional :: k\n integer(kind = IPRE) :: opt_k, i, m, n\n\n opt_k = 0\n if (present(k)) opt_k = k\n\n m = size(A, 1)\n n = size(A, 2)\n tril_r = A\n do i = 1, min(m, n)\n tril_r(:i-opt_k-1,i) = 0.0d0\n end do\n return\n end function tril_r\n\n function tril_c(A, k)\n complex(kind = RPRE), dimension(:,:), allocatable :: tril_c\n complex(kind = RPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE), intent(in), optional :: k\n integer(kind = IPRE) :: opt_k, i, m, n\n\n opt_k = 0\n if (present(k)) opt_k = k\n\n m = size(A, 1)\n n = size(A, 2)\n tril_c = A\n do i = 1, min(m, n)\n tril_c(:i-opt_k-1,i) = 0.0d0\n end do\n return\n end function tril_c\n\n!=======================================================================\n! triu\n!-----------------------------------------------------------------------\n! triu extracts the upper triangular part of a matrix.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! B = triu(A)\n! B = triu(A, k)\n!\n! Description\n!-----------------------------------------------------------------------\n! B = triu(A) returns the upper triangular part of matrix A.\n!\n! B = triu(A, k) returns the elements on and above the kth diagonal of\n! matrix X:\n! - k = 0 is the main diagonal,\n! - k > 0 is above the main diagonal,\n! - k < 0 is below the main diagonal.\n!\n! Examples\n!-----------------------------------------------------------------------\n! A = ones(4, 4)\n! B = triu(A, -1)\n! 1. 1. 1. 1.\n! 1. 1. 1. 1.\n! 0. 1. 1. 1.\n! 0. 0. 1. 1.\n!=======================================================================\n\n function triu_i(A, k)\n integer(kind = IPRE), dimension(:,:), allocatable :: triu_i\n integer(kind = IPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE), intent(in), optional :: k\n integer(kind = IPRE) :: opt_k, i, m, n\n\n opt_k = 0\n if (present(k)) opt_k = k\n\n m = size(A, 1)\n n = size(A, 2)\n triu_i = A\n do i = 1, min(m, n)\n triu_i(i-opt_k+1:,i) = 0.0d0\n end do\n return\n end function triu_i\n\n function triu_r(A, k)\n real(kind = RPRE), dimension(:,:), allocatable :: triu_r\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE), intent(in), optional :: k\n integer(kind = IPRE) :: opt_k, i, m, n\n\n opt_k = 0\n if (present(k)) opt_k = k\n\n m = size(A, 1)\n n = size(A, 2)\n triu_r = A\n do i = 1, min(m, n)\n triu_r(i-opt_k+1:,i) = 0.0d0\n end do\n return\n end function triu_r\n\n function triu_c(A, k)\n complex(kind = RPRE), dimension(:,:), allocatable :: triu_c\n complex(kind = RPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE), intent(in), optional :: k\n integer(kind = IPRE) :: opt_k, i, m, n\n\n opt_k = 0\n if (present(k)) opt_k = k\n\n m = size(A, 1)\n n = size(A, 2)\n triu_c = A\n do i = 1, min(m, n)\n triu_c(i-opt_k+1:,i) = 0.0d0\n end do\n return\n end function triu_c\n\n!=======================================================================\n! utm2deg\n!-----------------------------------------------------------------------\n! utm2deg converts UTM-WGS84 coordinates to latitude / longitude\n! (in degrees) coordinates.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! call utm2deg(east, north, zn, zl, lat, lon)\n!\n! Description\n!-----------------------------------------------------------------------\n! call utm2deg(east, north, zn, zl, lat, lon) converts the UTM-WGS84\n! coordinates in east and north to latitude / longitude coordinates\n! (in degrees). It outputs the latitudes lat and the longitudes lon.\n!\n! Notes\n!-----------------------------------------------------------------------\n! This function has been translated and adapted from the Python's\n! module utm: https://pypi.python.org/pypi/utm\n!=======================================================================\n\n subroutine utm2deg0(east, north, zn, zl, lat, lon)\n real(kind = RPRE), intent(in) :: east, north\n integer(kind = IPRE), intent(in) :: zn\n character(len = 1), intent(in) :: zl\n real(kind = RPRE), intent(out) :: lat, lon\n real(kind = 8), parameter :: K0 = 0.9996d0\n real(kind = 8), parameter :: E = 0.00669438d0\n real(kind = 8), parameter :: R = 6378137\n real(kind = 8) :: m, mu, n, s, c, c2, d, x, y\n real(kind = 8) :: E_P2, M1, F, P2, P3, P4, P5\n real(kind = 8) :: p_rad, p_sin, p_sin2, p_cos, p_tan, p_tan2, p_tan4, &\n ep_sin, ep_sin_sqrt\n\n x = east - 500000\n y = north\n if (verify(zl, \"OXWVUTSRQPN\") .ne. 0) y = y - 10000000\n\n E_P2 = E / (1.0d0 - E)\n M1 = (1 - E / 4 - 3 * E**2 / 64 - 5 * E**3 / 256)\n F = (1 - sqrt(1 - E)) / (1 + sqrt(1 - E))\n P2 = (3.0d0 / 2 * F - 27.0d0 / 32 * F**3 + 269.0d0 / 512 * F**5)\n P3 = (21.0d0 / 16 * F**2 - 55.0d0 / 32 * F**4)\n P4 = (151.0d0 / 96 * F**3 - 417.0d0 / 128 * F**5)\n P5 = (1097.0d0 / 512 * F**4)\n\n m = y / K0\n mu = m / (R * M1)\n\n p_rad = (mu + P2 * sin(2 * mu) &\n + P3 * sin(4 * mu) &\n + P4 * sin(6 * mu) &\n + P5 * sin(8 * mu))\n\n p_sin = sin(p_rad)\n p_sin2 = p_sin**2\n\n p_cos = cos(p_rad)\n\n p_tan = p_sin / p_cos\n p_tan2 = p_tan**2\n p_tan4 = p_tan2**2\n\n ep_sin = 1 - E * p_sin2\n ep_sin_sqrt = sqrt(1 - E * p_sin2)\n\n n = R/ ep_sin_sqrt\n s = (1 - E) / ep_sin\n c = F * p_cos**2\n c2 = c**2\n\n d = x / (n * K0)\n lat = (p_rad - (p_tan / s) &\n * (d**2 / 2 &\n - d**4 / 24 * (5 + 3 * p_tan2 + 10 * c -4 * c2 - 9 * E_P2)) &\n + d**6 / 720 * (61 + 90 * p_tan2 + 298 * c + 45 * p_tan4 - 252 * E_P2 - 3 * c2))\n lon = ( d &\n - d**3 / 6 * (1 + 2 * p_tan2 + c) &\n + d**5 / 120 * (5 - 2 * c + 28 * p_tan2 - 3 * c2 + 8 * E_P2 + 24 * p_tan4)) / p_cos\n\n lat = lat*180.0d0/pi\n lon = lon*180.0d0/pi + (zn - 1) * 6 - 180 + 3\n return\n end subroutine utm2deg0\n\n subroutine utm2deg1(east, north, zn, zl, lat, lon)\n real(kind = RPRE), dimension(:), intent(in) :: east, north\n integer(kind = IPRE), dimension(:), intent(in) :: zn\n character(len = 1), dimension(:), intent(in) :: zl\n real(kind = RPRE), dimension(:), allocatable, intent(out) :: lat, lon\n integer(kind = IPRE) :: i, n\n\n n = size(east)\n allocate(lat(n), lon(n))\n do i = 1, n\n call utm2deg(east(i), north(i), zn(i), zl(i), lat(i), lon(i))\n end do\n return\n end subroutine utm2deg1\n\n!=======================================================================\n! var\n!-----------------------------------------------------------------------\n! var computes vector and matrix variances.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! y = var(x)\n! y = var(x, w)\n! x = var(A)\n! x = var(A, w)\n! x = var(A, 1)\n! x = var(A, w, 1)\n! x = var(A, 2)\n! x = var(A, w, 2)\n!\n! Description\n!-----------------------------------------------------------------------\n! y = var(x) returns the variance of the vector x.\n!\n! y = var(x, w) returns the variance of the vector x with the\n! normalization option w.\n! - 0 (default) normalize by N-1,\n! - 1 normalize by N.\n!\n! x = var(A) returns a dim2 vector with the variances of each column of\n! matrix A.\n!\n! x = var(A, w) returns a dim2 vector with the normalization option w.\n!\n! x = var(A, 1) (see x = var(A)).\n!\n! w = var(A, w, 1) (see x = var(A, w))\n!\n! x = var(A, 2) returns a dim1 vector with the variances of each row of\n! matrix A.\n!\n! x = var(A, w, 2) returns a dim1 vector with the normalization option\n! w.\n!=======================================================================\n\n real(kind = RPRE) function var1(x, w)\n real(kind = RPRE), dimension(:), intent(in) :: x\n integer(kind = IPRE), intent(in), optional :: w\n integer(kind = IPRE) :: opt_w\n\n opt_w = 0\n if (present(w)) opt_w = w\n\n select case(opt_w)\n case(0)\n var1 = sum( (x - mean(x))**2 ) / (size(x) - 1)\n case(1)\n var1 = sum( (x - mean(x))**2 ) / size(x)\n end select\n return\n end function var1\n\n function var2(A, w, dim)\n real(kind = RPRE), dimension(:), allocatable :: var2\n real(kind = RPRE), dimension(:,:), intent(in) :: A\n integer(kind = IPRE), intent(in), optional :: w, dim\n integer(kind = IPRE) :: opt_w, i, m, n\n\n opt_w = 0\n if (present(w)) opt_w = w\n\n m = size(A, 1)\n n = size(A, 2)\n if ((.not. present(dim)) .or. (dim .eq. 1)) then\n allocate(var2(n))\n do i = 1, n\n var2(i) = var1(A(:,i), opt_w)\n end do\n elseif (dim .eq. 2) then\n allocate(var2(m))\n do i = 1, m\n var2(i) = var1(A(i,:), opt_w)\n end do\n end if\n end function var2\n\n!=======================================================================\n! vertcat\n!-----------------------------------------------------------------------\n! vertcat concatenates arrays vertically.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! A = vertcat(x1, x2)\n! A = vertcat(A1, A2)\n! B = vertcat(x1, A2)\n! B = vertcat(A1, x2)\n!\n! Description\n!-----------------------------------------------------------------------\n! A = vertcat(x1, x2) concatenates the vectors x1 and x2 treated as line\n! vectors along the dimension 2. If the length of x1 and x2 are not\n! equal, empty elements will be filled with zeros.\n!\n! A = vertcat(A1, A2) concatenates the matrices A1 and A2 along the\n! dimension 2. If the second dimension of A1 and A2 are not equal, empty\n! elements will be filled with zeros.\n!\n! B = vertcat(x1, A2) concatenates the vector x treated as line vector\n! and the matrix A along the dimension 2. If the length of x and the\n! second dimension of A are not equal, empty elements will be filled\n! with zeros.\n!\n! B = vertcat(A1, x2) concatenates the matrix A and the vector x treated\n! as a line vector along the dimension 2. If the second dimension of A\n! and the length of x are not equal, empty elements will be filled with\n! zeros.\n!\n! Examples\n!-----------------------------------------------------------------------\n! A1 = reshape([ 1., 2., 3., 4. ], [ 2, 2 ], order = [ 2, 1 ])\n! A2 = reshape([ 5., 6., 7., 8. ], [ 2, 2 ], order = [ 2, 1 ])\n! A = vertcat(A1, A2, 2)\n! 1. 2.\n! 3. 4.\n! 5. 6.\n! 7. 8.\n!=======================================================================\n\n function vertcat_r1(x1, x2)\n real(kind = RPRE), dimension(:,:), allocatable :: vertcat_r1\n real(kind = RPRE), dimension(:), intent(in) :: x1, x2\n integer(kind = IPRE) :: n1, n2\n\n n1 = size(x1)\n n2 = size(x2)\n\n vertcat_r1 = zeros(2, max(n1, n2))\n vertcat_r1(1,1:n1) = x1\n vertcat_r1(2,1:n2) = x2\n return\n end function vertcat_r1\n\n function vertcat_r2(A1, A2)\n real(kind = RPRE), dimension(:,:), allocatable :: vertcat_r2\n real(kind = RPRE), dimension(:,:), intent(in) :: A1, A2\n integer(kind = IPRE) :: m1, n1, m2, n2\n\n m1 = size(A1, 1)\n n1 = size(A1, 2)\n m2 = size(A2, 1)\n n2 = size(A2, 2)\n\n vertcat_r2 = zeros(m1+m2, max(n1, n2))\n vertcat_r2(1:m1,1:n1) = A1\n vertcat_r2(m1+1:,1:n2) = A2\n return\n end function vertcat_r2\n\n function vertcat_c2(A1, A2)\n complex(kind = RPRE), dimension(:,:), allocatable :: vertcat_c2\n complex(kind = RPRE), dimension(:,:), intent(in) :: A1, A2\n integer(kind = IPRE) :: m1, n1, m2, n2\n\n m1 = size(A1, 1)\n n1 = size(A1, 2)\n m2 = size(A2, 1)\n n2 = size(A2, 2)\n\n vertcat_c2 = zeros(m1+m2, max(n1, n2))\n vertcat_c2(1:m1,1:n1) = A1\n vertcat_c2(m1+1:,1:n2) = A2\n return\n end function vertcat_c2\n\n function vertcat_r12(x1, A2)\n real(kind = RPRE), dimension(:,:), allocatable :: vertcat_r12\n real(kind = RPRE), dimension(:), intent(in) :: x1\n real(kind = RPRE), dimension(:,:), intent(in) :: A2\n integer(kind = IPRE) :: n1, m1, n2\n\n n1 = size(x1)\n m1 = size(A2, 1)\n n2 = size(A2, 2)\n\n vertcat_r12 = zeros(m1+1, max(n1, n2))\n vertcat_r12(1,1:n1) = x1\n vertcat_r12(2:,1:n2) = A2\n return\n end function vertcat_r12\n\n function vertcat_r21(A1, x2)\n real(kind = RPRE), dimension(:,:), allocatable :: vertcat_r21\n real(kind = RPRE), dimension(:,:), intent(in) :: A1\n real(kind = RPRE), dimension(:), intent(in) :: x2\n integer(kind = IPRE) :: m1, n1, n2\n\n m1 = size(A1, 1)\n n1 = size(A1, 2)\n n2 = size(x2)\n\n vertcat_r21 = zeros(m1+1, max(n1, n2))\n vertcat_r21(1:m1,1:n1) = A1\n vertcat_r21(m1+1,1:n2) = x2\n return\n end function vertcat_r21\n\n!=======================================================================\n! zeros\n!-----------------------------------------------------------------------\n! zeros creates array all of zeros.\n!\n! Syntax\n!-----------------------------------------------------------------------\n! x = zeros(dim1)\n! A = zeros(dim1, dim2)\n! X = zeros(dim1, dim2, dim3)\n!\n! Description\n!-----------------------------------------------------------------------\n! x = zeros(dim1) returns a dim1 vector of zeros.\n!\n! A = zeros(dim1, dim2) returns a dim1-by-dim2 matrix of zeros.\n!\n! X = zeros(dim1, dim2, dim3) returns a dim1-by-dim2-by-dim3\n! 3-dimensional matrix of zeros.\n!\n! Examples\n!-----------------------------------------------------------------------\n! x = zeros(3)\n! x =\n! 0. 0. 0.\n!\n! A = zeros(3, 3)\n! A =\n! 0. 0. 0.\n! 0. 0. 0.\n! 0. 0. 0.\n!=======================================================================\n\n function zeros1(dim1)\n real(kind = RPRE), dimension(:), allocatable :: zeros1\n integer(kind = IPRE), intent(in) :: dim1\n integer(kind = IPRE) :: ierr\n\n allocate(zeros1(dim1), stat = ierr)\n if ( ierr .ne. 0 ) then\n print *, \"Error: in zeros, could not allocate array.\"\n stop\n else\n zeros1 = 0.0d0\n end if\n return\n end function zeros1\n\n function zeros2(dim1, dim2)\n real(kind = RPRE), dimension(:,:), allocatable :: zeros2\n integer(kind = IPRE), intent(in) :: dim1, dim2\n integer(kind = IPRE) :: ierr\n\n allocate(zeros2(dim1, dim2), stat = ierr)\n if ( ierr .ne. 0 ) then\n print *, \"Error: in zeros, could not allocate array.\"\n stop\n else\n zeros2 = 0.0d0\n end if\n return\n end function zeros2\n\n function zeros3(dim1, dim2, dim3)\n real(kind = RPRE), dimension(:,:,:), allocatable :: zeros3\n integer(kind = IPRE), intent(in) :: dim1, dim2, dim3\n integer(kind = IPRE) :: ierr\n\n allocate(zeros3(dim1, dim2, dim3), stat = ierr)\n if ( ierr .ne. 0 ) then\n print *, \"Error: in zeros, could not allocate array.\"\n stop\n else\n zeros3 = 0.0d0\n end if\n return\n end function zeros3\n\nend module forlab\n", "meta": {"hexsha": "a917986e077a4985fe2c425e53f6e89b174649df", "size": 291807, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/lib/forlab.f90", "max_stars_repo_name": "keurfonluu/StochOptim", "max_stars_repo_head_hexsha": "3c80a7aa86c950187fa5c78e849688043930e01c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2018-11-10T14:48:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-02T10:10:13.000Z", "max_issues_repo_path": "src/lib/forlab.f90", "max_issues_repo_name": "eachonly/StochOptim", "max_issues_repo_head_hexsha": "3c80a7aa86c950187fa5c78e849688043930e01c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/lib/forlab.f90", "max_forks_repo_name": "eachonly/StochOptim", "max_forks_repo_head_hexsha": "3c80a7aa86c950187fa5c78e849688043930e01c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-11-10T14:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-17T16:04:25.000Z", "avg_line_length": 31.0333935978, "max_line_length": 111, "alphanum_fraction": 0.4459728519, "num_tokens": 82019, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430353105599, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.6795213372775608}} {"text": "program unformatted_write\n use, intrinsic :: iso_fortran_env, only : error_unit, DP => REAL64\n implicit none\n real(kind=DP), parameter :: PI = acos(-1.0_DP), &\n PHI = 0.5_DP*(1.0_DP + sqrt(5.0_DP)), &\n B_REC = 0.5_DP*PI/log(PHI), &\n DELTA_R = 1.0e-3_DP\n integer :: nr_values, i, unit_nr, istat\n character(len=1024) :: file_name, msg\n real(kind=DP) :: r\n\n call get_arguments(nr_values, file_name)\n open (newunit=unit_nr, file=file_name, form='unformatted', &\n access='sequential', action='write', status='new', iostat=istat, &\n iomsg=msg)\n if (istat /= 0) then\n write (unit=error_unit, fmt='(2A)') 'error: ', trim(msg)\n stop 3\n end if\n r = 1.0_DP\n do i = 1, nr_values\n write (unit=unit_nr, iostat=istat, iomsg=msg) &\n r, golden_spiral(r)\n if (istat /= 0) then\n write (unit=error_unit, fmt='(2A)') 'error: ', trim(msg)\n end if\n r = r + DELTA_R\n end do\n close(unit=unit_nr)\n\ncontains\n\n subroutine get_arguments(nr_values, file_name)\n implicit none\n integer, intent(out) :: nr_values\n character(len=*), intent(out) :: file_name\n character(len=128) :: buffer, msg\n integer :: istat\n\n if (command_argument_count() /= 2) then\n write (unit=error_unit, fmt='(A)') &\n 'error: expecting number of values and file name as arguments'\n stop 1\n end if\n\n call get_command_argument(1, buffer)\n read (buffer, fmt=*, iomsg=msg, iostat=istat) nr_values\n if (istat /= 0) then\n write (unit=error_unit, fmt='(2A)') 'error: ', trim(msg)\n stop 2\n end if\n call get_command_argument(2, file_name)\n end subroutine get_arguments\n\n function golden_spiral(r) result(theta)\n implicit none\n real(kind=DP), value :: r\n real(kind=DP) :: theta\n theta = B_REC*log(r)\n end function golden_spiral\n\nend program unformatted_write\n", "meta": {"hexsha": "b9670183d444e4cfd0ff702f52a7cdf6e17bab10", "size": 2089, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source_code/io_performance/sequential/unformatted_write.f90", "max_stars_repo_name": "caguerra/Fortran-MOOC", "max_stars_repo_head_hexsha": "fb8a9c24e62ce5f388deb06b21e3009aea6b78d4", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2021-05-20T12:03:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-16T19:46:26.000Z", "max_issues_repo_path": "source_code/io_performance/sequential/unformatted_write.f90", "max_issues_repo_name": "caguerra/Fortran-MOOC", "max_issues_repo_head_hexsha": "fb8a9c24e62ce5f388deb06b21e3009aea6b78d4", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-09-30T04:25:50.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-06T08:21:30.000Z", "max_forks_repo_path": "source_code/io_performance/sequential/unformatted_write.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": 33.1587301587, "max_line_length": 78, "alphanum_fraction": 0.5639061752, "num_tokens": 594, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744673038222, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.6795213346060386}} {"text": " MODULE cdf_beta_mod\n! ----------------------------------------------------------------------\n\n! cdf_beta_mod\n! *=*=*=*=*=*=\n\n! - SUBROUTINE CDF_BETA(WHICH, CUM, CCUM, X, CX, A, B, STATUS, CHECK_INPUT)\n! - REAL (dpkind) FUNCTION CUM_BETA(X, A, B, STATUS, CHECK_INPUT)\n! - REAL (dpkind) FUNCTION CCUM_BETA(X, A, B, STATUS, CHECK_INPUT)\n! - REAL (dpkind) FUNCTION INV_BETA(CUM, CCUM, A, B, STATUS, CHECK_INPUT)\n\n! The Distribution\n! ================\n\n! The density of the beta distribution is defined on x in [0,1] and is\n! proportional to:\n\n! a b\n! x (1-x)\n\n! Arguments\n! =========\n\n! - INTEGER, INTENT(IN) :: WHICH. Integer indicating which of the next\n! four arguments is to be calculated.\n! Input Range: [ 1:4 ]\n! 1. CUM and CCUM\n! 2. X and CX\n! 3. A\n! 4. B\n! - REAL (dpkind), OPTIONAL :: CUM. The CDF of the beta distribution.\n! Range: [ 0:1 ]\n! - REAL (dpkind), OPTIONAL :: CCUM. One minus the CDF of the beta\n! distribution.\n! Range: [ 0:1 ]\n! - REAL (dpkind), OPTIONAL :: X. The upper limit of integration of the\n! beta density. The lower limit is 0.\n! Range: [ 0:1 ]\n! - REAL (dpkind), OPTIONAL :: CX. One minus the upper limit of\n! integration of the beta density. The lower limit is 0.\n! Range: [ 0:1 ]\n! - REAL (dpkind) :: A. The first parameter of the beta density.\n! Range: [ 10^-10:10^10 ]\n! - REAL (dpkind) :: B. The second parameter of the beta density.\n! Range: [ 10^-10:10^10 ]\n! - INTEGER, OPTIONAL, INTENT(OUT) :: STATUS. Return code. Possible values:\n! 0 problem solved successfully\n! -1 WHICH outside input range\n! -2 CUM outside range\n! -3 CCUM outside range\n! -4 X outside range\n! -5 CX outside range\n! -6 A outside range\n! -7 B outside range\n! 3 CUM + CCUM is not nearly one\n! 4 X + CX is not nearly one\n! -50 Answer (if any) is BELOW the LOWER search bound\n! 50 Answer (if any) is ABOVE the UPPER search bound\n! - LOGICAL, INTENT(IN), OPTIONAL :: CHECK_INPUT. If PRESENT and\n! .TRUE. input argument values are not checked for validity.\n\n! NOTE: CUM and CCUM and also X and CX must add to (nearly) one.\n! ----------------------------------------------------------------------\n! .. Use Statements ..\n USE biomath_constants_mod\n! ..\n! .. Default Accessibility ..\n PRIVATE\n! ..\n! .. Public Statements ..\n PUBLIC :: ccum_beta, cdf_beta, cum_beta, inv_beta\n! ..\n CONTAINS\n\n!*********************************************************************\n\n FUNCTION ccum_beta(x,cx,a,b,status,check_input)\n! .. Function Return Value ..\n REAL (dpkind) :: ccum_beta\n! ..\n! .. Scalar Arguments ..\n REAL (dpkind), INTENT (IN) :: a, b\n REAL (dpkind), OPTIONAL, INTENT (IN) :: cx, x\n INTEGER, INTENT (OUT) :: status\n LOGICAL, INTENT (IN) :: check_input\n! ..\n CALL cdf_beta(which=1,ccum=ccum_beta,x=x,cx=cx,a=a,b=b, &\n status=status,check_input=check_input)\n\n RETURN\n\n END FUNCTION ccum_beta\n\n!*********************************************************************\n\n SUBROUTINE cdf_beta(which,cum,ccum,x,cx,a,b,status,check_input)\n! .. Use Statements ..\n USE cdf_aux_mod\n USE zero_finder\n! ..\n! .. Scalar Arguments ..\n REAL (dpkind) :: a, b\n REAL (dpkind), OPTIONAL :: ccum, cum, cx, x\n INTEGER, OPTIONAL, INTENT (OUT) :: status\n INTEGER, INTENT (IN) :: which\n LOGICAL, OPTIONAL, INTENT (IN) :: check_input\n! ..\n! .. Local Structures ..\n! .. Local Arrays\n TYPE (zf_locals) :: local\n! ..\n! .. Local Scalars ..\n REAL (dpkind) :: fx, local_ccum, local_cum, local_cx, local_x, &\n try_ccum, try_cum\n INTEGER :: zf_status\n LOGICAL :: has_status, local_check_input, match_cum\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC PRESENT\n! ..\n! .. Local Arrays ..\n REAL (dpkind) :: params(6)\n! ..\n has_status = PRESENT(status)\n\n! status = 0 means no error\n\n IF (has_status) THEN\n status = 0\n END IF\n\n CALL check_complements(cum,ccum,the_beta%name,'cum','ccum', &\n local_cum,local_ccum,set_values=(which/=1),bad_status=3, &\n status=status)\n\n IF (has_status) THEN\n IF (status/=0) THEN\n RETURN\n END IF\n END IF\n\n CALL check_complements(x,cx,the_beta%name,'x','cx',local_x, &\n local_cx,set_values=(which/=2),bad_status=4,status=status)\n\n IF (has_status) THEN\n IF (status/=0) THEN\n RETURN\n END IF\n END IF\n\n params(1) = local_cum\n params(2) = local_ccum\n params(3) = local_x\n params(4) = local_cx\n params(5) = a\n params(6) = b\n\n IF (PRESENT(check_input)) THEN\n local_check_input = check_input\n ELSE\n local_check_input = .TRUE.\n END IF\n\n! ++++++++++ ++++++++++ ++++++++++\n! Range check arguments and see that they add to one\n! ++++++++++ ++++++++++ ++++++++++\n\n IF (local_check_input) THEN\n! Assure that x + cx nearly one\n\n IF (which/=2) THEN\n IF ( .NOT. add_to_one(local_x,local_cx,the_beta%name,'x','cx' &\n ,4,status)) RETURN\n END IF\n\n CALL validate_parameters(the_beta,which,params,status)\n\n IF (has_status) THEN\n IF (status/=0) THEN\n RETURN\n END IF\n END IF\n\n END IF\n\n!++++++++++++++++++++++++++++++++++++++++++++++++++\n! Compute the Answers\n!++++++++++++++++++++++++++++++++++++++++++++++++++\n\n IF (which>1) match_cum = (local_cum<=half)\n\n SELECT CASE (which)\n\n CASE (1)\n! Calculate cum and ccum\n\n CALL local_cum_beta(local_x,local_cx,a,b,local_cum,local_ccum)\n\n IF (PRESENT(cum)) cum = local_cum\n IF (PRESENT(ccum)) ccum = local_ccum\n\n RETURN\n\n CASE (2)\n! Calculate x and cx\n\n local_x = half\n zf_status = 0\n\n CALL cdf_set_zero_finder(the_beta,3,local)\n\n IF (match_cum) THEN\n DO\n CALL rc_interval_zf(zf_status,local_x,fx,local)\n\n IF (zf_status/=1) EXIT\n\n local_cx = one - local_x\n\n CALL local_cum_beta(local_x,local_cx,a,b,try_cum,try_ccum)\n\n fx = try_cum - cum\n END DO\n\n ELSE\n DO\n CALL rc_interval_zf(zf_status,local_cx,fx,local)\n\n IF (zf_status/=1) EXIT\n\n local_x = one - local_cx\n\n CALL local_cum_beta(local_x,local_cx,a,b,try_cum,try_ccum)\n\n fx = try_ccum - ccum\n END DO\n END IF\n\n IF (PRESENT(x)) x = local_x\n IF (PRESENT(cx)) cx = local_cx\n\n CASE (3)\n! Calculate a\n\n a = five\n zf_status = 0\n\n CALL cdf_set_zero_finder(the_beta,5,local)\n\n DO\n CALL rc_step_zf(zf_status,a,fx,local)\n\n IF (zf_status/=1) EXIT\n\n CALL local_cum_beta(local_x,local_cx,a,b,try_cum,try_ccum)\n\n IF (match_cum) THEN\n fx = try_cum - cum\n ELSE\n fx = try_ccum - ccum\n END IF\n END DO\n\n CASE (4)\n! Calculate b\n\n b = five\n zf_status = 0\n\n CALL cdf_set_zero_finder(the_beta,6,local)\n\n DO\n CALL rc_step_zf(zf_status,b,fx,local)\n\n IF (zf_status/=1) EXIT\n\n CALL local_cum_beta(local_x,local_cx,a,b,try_cum,try_ccum)\n\n IF (match_cum) THEN\n fx = try_cum - cum\n ELSE\n fx = try_ccum - ccum\n END IF\n END DO\n\n END SELECT\n\n IF (has_status) THEN\n CALL cdf_finalize_status(local,status)\n END IF\n\n RETURN\n\n END SUBROUTINE cdf_beta\n\n!*********************************************************************\n\n FUNCTION cum_beta(x,cx,a,b,status,check_input)\n! .. Function Return Value ..\n REAL (dpkind) :: cum_beta\n! ..\n! .. Scalar Arguments ..\n REAL (dpkind), INTENT (IN) :: a, b\n REAL (dpkind), OPTIONAL, INTENT (IN) :: cx, x\n INTEGER, OPTIONAL, INTENT (OUT) :: status\n LOGICAL, OPTIONAL, INTENT (IN) :: check_input\n! ..\n CALL cdf_beta(which=1,cum=cum_beta,x=x,cx=cx,a=a,b=b, &\n status=status,check_input=check_input)\n\n RETURN\n\n END FUNCTION cum_beta\n\n!*********************************************************************\n\n FUNCTION inv_beta(cum,ccum,a,b,status,check_input)\n! .. Function Return Value ..\n REAL (dpkind) :: inv_beta\n! ..\n! .. Scalar Arguments ..\n REAL (dpkind), INTENT (IN) :: a, b\n REAL (dpkind), OPTIONAL, INTENT (IN) :: ccum, cum\n INTEGER, OPTIONAL, INTENT (OUT) :: status\n LOGICAL, OPTIONAL, INTENT (IN) :: check_input\n! ..\n CALL cdf_beta(which=2,cum=cum,ccum=ccum,x=inv_beta,a=a,b=b, &\n status=status,check_input=check_input)\n\n RETURN\n\n END FUNCTION inv_beta\n\n!*********************************************************************\n\n SUBROUTINE local_cum_beta(x,y,a,b,cum,ccum)\n!----------------------------------------------------------------------\n! Double precision cUMulative incomplete BETa distribution\n\n! Function\n\n! Calculates the cdf to X of the incomplete beta distribution\n! with parameters a and b. This is the integral from 0 to x\n! of (1/B(a,b))*f(t)) where f(t) = t**(a-1) * (1-t)**(b-1)\n\n! Arguments\n\n! X --> Upper limit of integration.\n! Y --> 1 - X.\n! A --> First parameter of the beta distribution.\n! B --> Second parameter of the beta distribution.\n! CUM <-- Cumulative incomplete beta distribution.\n! CCUM <-- Compliment of Cumulative incomplete beta distribution.\n\n! Method\n\n! Cumulative distribution function (CUM) is calculated directly by\n! code associated with the following reference.\n! DiDinato, A. R. and Morris, A. H. Algorithm 708: Significant\n! Digit Computation of the Incomplete Beta Function Ratios. ACM\n! Trans. Math. Softw. 18 (1993), 360-373.\n! Computation of other parameters involve a seach for a value that\n! produces the desired value of CUM. The search relies on the\n! monotinicity of CUM with the other parameter.\n!----------------------------------------------------------------------\n! .. Use Statements ..\n USE biomath_mathlib_mod\n! ..\n! .. Scalar Arguments ..\n REAL (dpkind), INTENT (IN) :: a, b, x, y\n REAL (dpkind), INTENT (OUT) :: ccum, cum\n! ..\n! .. Local Scalars ..\n INTEGER :: ierr\n! ..\n IF (x<=zero) THEN\n cum = zero\n ccum = one\n RETURN\n END IF\n\n IF (y<=zero) THEN\n cum = one\n ccum = zero\n RETURN\n END IF\n\n! Because of the bounds on a, b, x, y\n! ierr can not be <> 0\n\n CALL bratio(a,b,x,y,cum,ccum,ierr)\n\n RETURN\n\n END SUBROUTINE local_cum_beta\n\n!*********************************************************************\n\n END MODULE cdf_beta_mod\n", "meta": {"hexsha": "b714cbd702c48f1420ab596b831a3e0aaed6c3d8", "size": 11398, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mesas/sas/cdflib90/cdf_beta_mod.f90", "max_stars_repo_name": "OliverEvans96/mesas", "max_stars_repo_head_hexsha": "eb830074dd3b2977013cda1e2a30b79e10379190", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "mesas/sas/cdflib90/cdf_beta_mod.f90", "max_issues_repo_name": "OliverEvans96/mesas", "max_issues_repo_head_hexsha": "eb830074dd3b2977013cda1e2a30b79e10379190", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-12-14T03:16:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-14T16:37:17.000Z", "max_forks_repo_path": "mesas/sas/cdflib90/cdf_beta_mod.f90", "max_forks_repo_name": "OliverEvans96/mesas", "max_forks_repo_head_hexsha": "eb830074dd3b2977013cda1e2a30b79e10379190", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-09-09T18:20:55.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-09T18:20:55.000Z", "avg_line_length": 28.495, "max_line_length": 77, "alphanum_fraction": 0.5105281628, "num_tokens": 2949, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094088947399, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6794963849185466}} {"text": "\tSUBROUTINE TI_DAYW ( idtarr, idayw, iret )\nC************************************************************************\nC* TI_DAYW\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This subroutine returns the day of the week, IDAYW, given an integer\t*\nC* time. IDAYW is set to 1 for Sunday, 2 for Monday, 3 for Tuesday,\t*\nC* 4 for Wednesday, 5 for Thursday, 6 for Friday, and 7 for Saturday.\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This subroutine does not check that a valid time was entered. The \t*\nC* year must be a full four-digit year.\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* TI_DAYW ( IDTARR, IDAYW, IRET )\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tIDTARR (5)\tINTEGER\t\tTime array (YYYY,MM,DD,HH,MM)\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tIDAYW\t\tINTEGER\t\tDay of week (1 - Sun,...)\t*\nC*\tIRET\t\tINTEGER\t\tReturn code\t\t\t*\nC*\t\t\t\t\t 0 = normal return\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* M. desJardins/GSFC\t12/87\tAdapted from DAYOFWEEK in TRAFIC\t*\nC* M. desJardins/GSFC\t 9/88\tAdd 1900 to YY\t\t\t\t*\nC* I. Durham/GSC\t 9/98 Added March leap year correction\t*\nC* I. Durham/GSC\t 9/98\tRewrote using new computation\t\t*\nC* S. Jacobs/NCEP\t11/99\tSimplified calculation\t\t\t*\nC************************************************************************\n\tINTEGER\t\tidtarr (*)\nC*\n\tINTEGER\t\tjdtarr (5)\nC------------------------------------------------------------------------\n\tiret = 0\nC\nC*\tGet the number of days for the first of the given month.\nC\n\tDO i = 1, 5\n\t jdtarr (i) = idtarr (i)\n\tEND DO\n\tjdtarr (3) = 1\n\tCALL TI_ITOJ ( jdtarr, jyear, jday, ier )\nC\nC*\tCompute the offset for this month.\nC\n\tioff = MOD ( jday-1, 7 )\nC\nC*\tCompute the day of the week.\nC\n\tiy = idtarr (1)\n\tid = idtarr (3)\n\tidayw = MOD ( ( iy + (iy-1)/4 - (iy-1)/100 + (iy-1)/400 +\n +\t\t ioff + (id-1) ), 7 ) + 1\nC\n\tRETURN\n\tEND\n", "meta": {"hexsha": "a3112f6d5bda96006d4bd6179dca7fa1bcd63257", "size": 1754, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/gemlib/ti/tidayw.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/gemlib/ti/tidayw.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/gemlib/ti/tidayw.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.3214285714, "max_line_length": 73, "alphanum_fraction": 0.5216647662, "num_tokens": 624, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.6794963832838711}} {"text": " SUBROUTINE slVN (V, UV, VM)\n*+\n* - - -\n* V N\n* - - -\n*\n* Normalizes a 3-vector also giving the modulus (single precision)\n*\n* Given:\n* V real(3) vector\n*\n* Returned:\n* UV real(3) unit vector in direction of V\n* VM real modulus of V\n*\n* If the modulus of V is zero, UV is set to zero as well\n*\n* P.T.Wallace Starlink 23 November 1995\n*\n* Copyright (C) 1995 Rutherford Appleton Laboratory\n*\n* License:\n* This program is free software; you can redistribute it and/or modify\n* it under the terms of the GNU General Public License as published by\n* the Free Software Foundation; either version 2 of the License, or\n* (at your option) any later version.\n*\n* This program is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU General Public License for more details.\n*\n* You should have received a copy of the GNU General Public License\n* along with this program (see SLA_CONDITIONS); if not, write to the\n* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,\n* Boston, MA 02110-1301 USA\n*\n* Copyright (C) 1995 Association of Universities for Research in Astronomy Inc.\n*-\n\n IMPLICIT NONE\n\n REAL V(3),UV(3),VM\n\n INTEGER I\n REAL W1,W2\n\n\n* Modulus\n W1=0.0\n DO I=1,3\n W2=V(I)\n W1=W1+W2*W2\n END DO\n W1=SQRT(W1)\n VM=W1\n\n* Normalize the vector\n IF (W1.LE.0.0) W1=1.0\n DO I=1,3\n UV(I)=V(I)/W1\n END DO\n\n END\n", "meta": {"hexsha": "8bbb33d9758839526b5254ee374a87c4c1082765", "size": 1644, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iraf.v2161/math/slalib/vn.f", "max_stars_repo_name": "ysBach/irafdocgen", "max_stars_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:19:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T16:48:42.000Z", "max_issues_repo_path": "math/slalib/vn.f", "max_issues_repo_name": "kirxkirx/iraf", "max_issues_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-30T13:48:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-02T19:40:25.000Z", "max_forks_repo_path": "math/slalib/vn.f", "max_forks_repo_name": "kirxkirx/iraf", "max_forks_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.2923076923, "max_line_length": 80, "alphanum_fraction": 0.6228710462, "num_tokens": 489, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770433, "lm_q2_score": 0.7853085758631158, "lm_q1q2_score": 0.6794678920910487}} {"text": "cc Copyright (C) 2004-2009: Leslie Greengard and June-Yub Lee \ncc Contact: greengard@cims.nyu.edu\ncc \ncc This software is being released under a FreeBSD license\ncc (see license.txt in this directory). \nc\nc tweaked Alex Barnett to call FINUFFT 2/17/17\nc dyn malloc; type 2 uses same input data fk0, 3/8/17\nc Single-prec version 4/5/17 \nc\nc Compile with (multithreaded version):\nc gfortran nufft1d_demof.f dirft1df.f -o nufft1d_demof ../lib/libfinufft.a\nc -lstdc++ -lfftw3f -lfftw3f_threads -lm -fopenmp\nc\n program nufft1d_demof\n implicit none\nc\nc --- local variables\nc\n integer i,ier,iflag,j,k1,mx,ms,nj\n real*4, allocatable :: xj(:),sk(:)\n real*4 err,eps,pi\n parameter (pi=3.141592653589793238462643383279502884197e0)\n complex*8, allocatable :: cj(:),cj0(:),cj1(:),fk0(:),fk1(:)\nc\nc --------------------------------------------------\nc create some test data\nc --------------------------------------------------\n ms = 90\n nj = 128\nc first alloc everything\n allocate(fk0(ms))\n allocate(fk1(ms))\n allocate(sk(ms))\n allocate(xj(nj))\n allocate(cj(nj))\n allocate(cj0(nj))\n allocate(cj1(nj))\n do k1 = -nj/2, (nj-1)/2\n j = k1+nj/2+1\n xj(j) = pi * cos(-pi*j/nj)\n cj(j) = cmplx( sin(pi*j/nj), cos(pi*j/nj))\n enddo\nc\nc --------------------------------------------------\nc start tests\nc --------------------------------------------------\nc\n iflag = 1\n print*,' Start 1D testing: ', ' nj =',nj, ' ms =',ms\n do i = 1,3\n if (i.eq.1) eps=1e-2\n if (i.eq.2) eps=1e-4\n if (i.eq.3) eps=1e-6\n\t print*,' '\n \t print*,' Requested precision eps =',eps\n\t print*,' '\nc\nc -----------------------\nc call 1D Type1 method\nc -----------------------\nc\n call dirft1d1f(nj,xj,cj,iflag, ms,fk0)\n call finufft1d1_f(nj,xj,cj,iflag,eps, ms,fk1,ier)\n call errcomp(fk0,fk1,ms,err)\n print *,' ier = ',ier\n print *,' type 1 error = ',err\nc\nc -----------------------\nc call 1D Type2 method\nc -----------------------\nc\n call dirft1d2f(nj,xj,cj0,iflag, ms,fk0,ier)\n call finufft1d2_f(nj,xj,cj1,iflag, eps, ms,fk0,ier)\n call errcomp(cj0,cj1,nj,err)\n print *,' ier = ',ier\n print *,' type 2 error = ',err\nc\nc -----------------------\nc call 1D Type3 method\nc -----------------------\n do k1 = 1, ms\n sk(k1) = 48*cos(k1*pi/ms)\n enddo\n call dirft1d3f(nj,xj,cj,iflag, ms,sk,fk0)\n call finufft1d3_f(nj,xj,cj,iflag,eps, ms,sk,fk1,ier)\n call errcomp(cj0,cj1,nj,err)\n print *,' ier = ',ier\n print *,' type 3 error = ',err\n enddo\n stop\n end\nc\nc\nc\nc\nc\n subroutine errcomp(fk0,fk1,n,err)\n implicit none\n integer k,n\n complex*8 fk0(n), fk1(n)\n real *4 salg,ealg,err\nc\n ealg = 0d0\n salg = 0d0\n do k = 1, n\n ealg = ealg + cabs(fk1(k)-fk0(k))**2\n salg = salg + cabs(fk0(k))**2\n enddo\n err =sqrt(ealg/salg)\n return\n end\n", "meta": {"hexsha": "38ef922613849aecf13e7817d9426b738556604e", "size": 3125, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "fortran/nufft1d_demof.f", "max_stars_repo_name": "ludvigak/finufft", "max_stars_repo_head_hexsha": "a4d442906fdaebfe944283ca9bd2be36a40e2b3a", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-11-05T22:46:04.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-05T22:46:04.000Z", "max_issues_repo_path": "fortran/nufft1d_demof.f", "max_issues_repo_name": "zcgan/finufft", "max_issues_repo_head_hexsha": "05e70050ac9e418ff1ed46d2369209b63b0502fd", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/nufft1d_demof.f", "max_forks_repo_name": "zcgan/finufft", "max_forks_repo_head_hexsha": "05e70050ac9e418ff1ed46d2369209b63b0502fd", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.6548672566, "max_line_length": 74, "alphanum_fraction": 0.49504, "num_tokens": 1085, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240756264639, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.6794678909801406}} {"text": " real function crit(z,q)\r\nc\r\nc + + + PURPOSE + + +\r\nc\r\nc Function CRIT computes the critical flow depth.\r\nc\r\nc Called from: SRS FRICHN, FSLPAR\r\nc Author(s): Ascough II, R. van der Zweep, V. Lopes\r\nc Reference in User Guide:\r\nc\r\nc Version:\r\nc Date recoded:\r\nc Recoded by: Jim Ascough II\r\nc\r\nc + + + KEYWORDS + + +\r\nc\r\nc + + + PARAMETERS + + +\r\nc\r\nc + + + ARGUMENT DECLARATIONS + + +\r\nc\r\n real z, q\r\nc\r\nc + + + ARGUMENT DEFINITIONS + + +\r\nc\r\nc z -\r\nc q -\r\nc\r\nc + + + COMMON BLOCKS + + +\r\nc\r\n include 'cchcon.inc'\r\nc\r\nc + + + LOCAL VARIABLES + + +\r\nc\r\nc + + + LOCAL DEFINITIONS + + +\r\nc\r\nc + + + SAVES + + +\r\nc\r\nc + + + SUBROUTINES CALLED + + +\r\nc\r\nc + + + DATA INITIALIZATIONS + + +\r\nc\r\nc + + + END SPECIFICATIONS + + +\r\nc\r\nc\r\n crit = (2.0*beta*q**2/(agrav*z**2)) ** 0.2\r\nc\r\n return\r\n end\r\n", "meta": {"hexsha": "8b1e835d1934dfb4bd767b7a33262575bb7ffdb0", "size": 902, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/wepp2010.1/crit.for", "max_stars_repo_name": "jarad/dep", "max_stars_repo_head_hexsha": "fe73982f4c70039e1a31b9e8e2d9aac31502f803", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-11-26T17:49:19.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-26T17:49:19.000Z", "max_issues_repo_path": "src/wepp2010.1/crit.for", "max_issues_repo_name": "jarad/dep", "max_issues_repo_head_hexsha": "fe73982f4c70039e1a31b9e8e2d9aac31502f803", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 54, "max_issues_repo_issues_event_min_datetime": "2018-12-12T18:02:31.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T19:14:25.000Z", "max_forks_repo_path": "src/wepp2010.1/crit.for", "max_forks_repo_name": "akrherz/idep", "max_forks_repo_head_hexsha": "7189a26fbcec3d8c3cc7d7015107b8fb6c5f6a45", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-03-02T22:59:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-09T15:49:00.000Z", "avg_line_length": 18.4081632653, "max_line_length": 56, "alphanum_fraction": 0.4833702882, "num_tokens": 311, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9539660923657094, "lm_q2_score": 0.7122321781307374, "lm_q1q2_score": 0.6794453478284974}} {"text": " program main\n implicit none\n! include 'omp_lib.h'\n\n integer i, sum1;\n sum1 = 0\n!$omp parallel do reduction(+:sum1)\n do i = 1, 100\n sum1 = sum1 + i\n enddo \n print *, \"sum of 1 to 100 is:\", sum1\n\n end\n", "meta": {"hexsha": "8160f5bee3c467cb5aefa5808f85f8b7bd4b72e7", "size": 253, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/CompileTests/OpenMP_tests/fortran/reduction.f", "max_stars_repo_name": "maurizioabba/rose", "max_stars_repo_head_hexsha": "7597292cf14da292bdb9a4ef573001b6c5b9b6c0", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/CompileTests/OpenMP_tests/fortran/reduction.f", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/CompileTests/OpenMP_tests/fortran/reduction.f", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 18.0714285714, "max_line_length": 42, "alphanum_fraction": 0.5019762846, "num_tokens": 84, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8459424528443252, "lm_q2_score": 0.8031737963569016, "lm_q1q2_score": 0.6794388113504459}} {"text": "function YilmIndexVector(i, l, m)\n!-------------------------------------------------------------------------------\n!\n! This function will give the index in a 1-dimensional array of the spherical \n! harmonic coefficient corresponding to the element Cilm. The elements of the \n! 1D vector array are packed according to (where positive m corresponds \n! to i=1 (the cosine coefficients), and negative m corresponds to i=1 \n! (the sine coefficients))\n!\n! 0,0\n! 1, 0; 1, 1; 1, -1\n! 2,0 ; 2, 1; 2, 2; 2, -1; 2, -2\n!\n! This mapping is given by the function:\n!\n! YilmIndex = l**2 + (i-1)*l + m + 1\n!\n! Copyright (c) 2005-2019, SHTOOLS\n! All rights reserved.\n!\n!-------------------------------------------------------------------------------\n use ftypes\n\n implicit none\n\n integer(int32) :: YilmIndexVector\n integer(int32), intent(in) :: i, l, m\n\n if (i /= 1 .and. i /= 2) then\n print*, \"Error --- YilmIndexVector\"\n print*, \"I must be 1 (for cosine terms) or 2 (for sine terms).\"\n print*, \"I = \", i\n stop\n\n end if\n\n if (l < 0) then\n print*, \"Error --- YilmIndexVector\"\n print*, \"L must be positive.\"\n print*, \"L = \", l\n stop\n\n end if\n\n if (m < 0 .or. m > l) then\n print*, \"Error --- YilmIndexVector\"\n print*, \"M must be positive and less than L.\"\n print*, \"M = \", m\n print*, \"L = \", l\n stop\n\n end if\n\n if (m == 0 .and. i == 2) then\n print*, \"Error --- YilmIndexVector\"\n print*, \"When M = 0, I must be 1.\"\n print*, \"I = \", i\n print*, \"M = \", m\n stop\n\n end if\n\n yilmindexvector = l**2 + (i-1)*l + m + 1\n\nend function YilmIndexVector\n", "meta": {"hexsha": "c7cf7898f227ada73a834e57ca0d7a85e1a1f802", "size": 1713, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/YilmIndexVector.f95", "max_stars_repo_name": "mjc87/SHTOOLS", "max_stars_repo_head_hexsha": "8d83c42d1313d5624c4db8c2e57300c5d819834e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 251, "max_stars_repo_stars_event_min_datetime": "2015-01-27T12:58:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T17:19:36.000Z", "max_issues_repo_path": "src/YilmIndexVector.f95", "max_issues_repo_name": "mjc87/SHTOOLS", "max_issues_repo_head_hexsha": "8d83c42d1313d5624c4db8c2e57300c5d819834e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 193, "max_issues_repo_issues_event_min_datetime": "2015-03-11T06:21:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T14:05:45.000Z", "max_forks_repo_path": "src/YilmIndexVector.f95", "max_forks_repo_name": "mreineck/SHTOOLS", "max_forks_repo_head_hexsha": "fec33f203ee0b47008fd69d4080304d6ebd272e7", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 100, "max_forks_repo_forks_event_min_datetime": "2015-04-03T07:11:05.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-23T23:46:33.000Z", "avg_line_length": 25.9545454545, "max_line_length": 80, "alphanum_fraction": 0.4927028605, "num_tokens": 526, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424295406087, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.6794387946262639}} {"text": "subroutine mbvab1(a,b,c,n1,n2,en1,en2)\n\n!-----------------------------------------------------------------------\n!\n! This routine evaluates the matrix-vector product A = B C, where\n! A -> R(n1), B -> Mat(n1,n2), C -> R(n2), and also computes the\n! Euclidian norms of A and C\n!\n!-----------------------------------------------------------------------\n use typre\n implicit none\n integer(ip), intent(in) :: n1,n2\n real(rp), intent(in) :: b(n1,n2), c(n2)\n real(rp), intent(out) :: a(n1),en1,en2\n integer(ip) :: i,k\n\n do i=1,n1\n a(i)=0.0_rp\n do k=1,n2\n a(i)=a(i)+b(i,k)*c(k)\n end do\n end do\n \n en1=0.0_rp\n en2=0.0_rp\n do i=1,n1\n en1=en1+a(i)*a(i)\n end do\n do i=1,n2\n en2=en2+c(i)*c(i)\n end do\n en1=sqrt(en1)\n en2=sqrt(en2)\n\nend subroutine mbvab1\n\n\n", "meta": {"hexsha": "599d40d38f31870b86707eaaa320314810ec573d", "size": 814, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Sources/mathru/mbvab1.f90", "max_stars_repo_name": "ciaid-colombia/InsFEM", "max_stars_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-24T08:19:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-24T08:19:54.000Z", "max_issues_repo_path": "Sources/mathru/mbvab1.f90", "max_issues_repo_name": "ciaid-colombia/InsFEM", "max_issues_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Sources/mathru/mbvab1.f90", "max_forks_repo_name": "ciaid-colombia/InsFEM", "max_forks_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.4210526316, "max_line_length": 72, "alphanum_fraction": 0.4508599509, "num_tokens": 283, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517044, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.6794226007020461}} {"text": "module fmg_cycle_mod\n\ncontains\n\n recursive subroutine fmg_cycle(ct,lvl)\n\n use constants\n use traverse_mod\n use cycle_tower_mod\n use v_cycle_mod\n\n implicit none\n\n integer, intent(in) :: lvl\n type(cycle_tower), intent(inout) :: ct\n\n integer :: i \n\n ! Always start with initial guess of zero for the solution\n call setval(ct%uu(lvl),0.d0,all=.true.)\n\n call print_cycle_tower(ct,lvl,'Down FMG-cycle: ')\n\n if (lvl == 1) then\n\n if (parallel_IOProcessor()) then\n call print_cycle_tower(ct,lvl,'Before relaxation: ')\n end if\n\n if (ct%verbose >= 2) then\n write(*,'(a,i3,a)') ' FMG-Cycle BOTTOM -- Applying ',ct%fmg_bot,' relaxations.'\n end if\n\n ! Just smooth a bunch of times at the bottom; can choose a different solver\n do i = 1,ct%fmg_bot\n call gsrb(ct%uu(lvl),ct%ff(lvl),ct%bb(lvl,:),ct%dx(lvl))\n end do\n\n if (parallel_IOProcessor()) then\n call print_cycle_tower(ct,lvl,' After relaxation: ')\n end if\n\n else\n\n ! Coarsen and continue downwards\n call restriction(ct%ff(lvl-1),ct%res(lvl))\n call fmg_cycle(ct,lvl-1)\n\n ! Interpolate solution\n call prolongation(ct%uu(lvl),ct%uu(lvl-1),ct%interp_type)\n\n ! Apply entire V-cycle on the way up\n if (ct%verbose == 1) then\n ct%verbose = ct%verbose - 1\n call v_cycle(ct,lvl,lvl)\n ct%verbose = ct%verbose + 1\n else\n call v_cycle(ct,lvl,lvl)\n end if\n\n end if\n\n ! If at the top, correct solution by adding the error that we've just solved for\n if (lvl == ct%nlvl) then\n call plus_plus(ct%sol,ct%uu(lvl))\n call multifab_fill_boundary(ct%sol)\n end if\n\n end subroutine fmg_cycle\n\nend module fmg_cycle_mod\n\n\n", "meta": {"hexsha": "9bcd8df8717476d74fdf472bcdfc2277f981e57a", "size": 2003, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorials/MultiGrid_F/fmg_cycle.f90", "max_stars_repo_name": "memmett/BoxLib", "max_stars_repo_head_hexsha": "a235af87d30cbfc721d4d7eb4da9b8daadeded7d", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 79, "max_stars_repo_stars_event_min_datetime": "2015-08-03T18:29:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-15T11:42:40.000Z", "max_issues_repo_path": "Tutorials/MultiGrid_F/fmg_cycle.f90", "max_issues_repo_name": "memmett/BoxLib", "max_issues_repo_head_hexsha": "a235af87d30cbfc721d4d7eb4da9b8daadeded7d", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": 22, "max_issues_repo_issues_event_min_datetime": "2016-06-15T20:46:49.000Z", "max_issues_repo_issues_event_max_datetime": "2018-09-10T21:33:10.000Z", "max_forks_repo_path": "Tutorials/MultiGrid_F/fmg_cycle.f90", "max_forks_repo_name": "memmett/BoxLib", "max_forks_repo_head_hexsha": "a235af87d30cbfc721d4d7eb4da9b8daadeded7d", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": 48, "max_forks_repo_forks_event_min_datetime": "2015-08-05T02:19:33.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-18T12:33:14.000Z", "avg_line_length": 27.0675675676, "max_line_length": 98, "alphanum_fraction": 0.5471792312, "num_tokens": 511, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127455162773, "lm_q2_score": 0.7956581000631542, "lm_q1q2_score": 0.6794225927171929}} {"text": "\n# accumulate (sum) all the elements of a list\n\n__accum([], acc): acc.\n__accum(h <~ [t], acc):\n __accum(t, acc + h).\n\naccum(a):\n __accum(a, 0).\n\n\n# accumulate (sum) the first n elements of a list\n__accumn(_, acc, 0):\n acc.\n__accumn(h <~ [t], acc, n):\n __accumn(t, acc + h, n - 1).\n\n\naccumn(a,n):\n __accumn(a, 0, n).\n\n", "meta": {"hexsha": "448f8c3b2f180a5c38c1c3abdf69909868bbac80", "size": 335, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "include/accum.f", "max_stars_repo_name": "diegovalverde/funk", "max_stars_repo_head_hexsha": "39be1ad5ce6d5b306f23165bc0fe5882de56b2ee", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-04-05T14:24:42.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-17T20:05:09.000Z", "max_issues_repo_path": "include/accum.f", "max_issues_repo_name": "diegovalverde/funk", "max_issues_repo_head_hexsha": "39be1ad5ce6d5b306f23165bc0fe5882de56b2ee", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2019-01-31T15:39:34.000Z", "max_issues_repo_issues_event_max_datetime": "2019-08-16T17:34:31.000Z", "max_forks_repo_path": "include/accum.f", "max_forks_repo_name": "diegovalverde/funk", "max_forks_repo_head_hexsha": "39be1ad5ce6d5b306f23165bc0fe5882de56b2ee", "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.2272727273, "max_line_length": 49, "alphanum_fraction": 0.5582089552, "num_tokens": 119, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8740772417253256, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.6794201276676497}} {"text": " module KS\n implicit none\n save\n integer, parameter :: Nx = 131072\n integer,\t parameter :: Nruns = 8\n double precision, parameter :: dt = 1d0/16d0\n double precision, parameter :: T = 200d0\n double precision, parameter :: pi = 3.14159265358979323846d0\n double precision, parameter :: Lx = (pi/16d0)*Nx\n logical, parameter :: printnorms = .true.\n end module KS\n\n!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ndouble precision function ksnorm(u,Nx)\n double complex, intent(in) :: u(0:Nx-1)\n double precision :: s\n integer n;\n\n s = 0.0d0;\n do n = 0, Nx-1 \n s = s + (abs(u(n)))**2\n end do\n mynorm = sqrt(s/Nx)\n end function ksnorm\n\n\n!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n program main\n use KS\n implicit none\n integer :: i,Nt,r, skip=1\n real :: tstart, tend, avgtime\n double precision :: u0norm\n double precision :: uTnorm\n double precision :: x(0:Nx-1)\n double complex :: u0(0:Nx-1)\n double complex :: u(0:Nx-1)\n double precision :: s\n\n !allocate(x(0:Nx-1))\n !allocate(u(0:Nx-1))\n \n Nt = floor(T/dt)\n x = Lx * (/(i,i=0,Nx-1)/) / dble(Nx)\n u0 = cos(x) + 0.1d0*sin(x/8d0) + 0.01d0*cos((2*pi/Lx)*x)\n\n s = 0.0d0\n do i = 0, Nx-1 \n s = s + (abs(u0(i)))**2\n end do \n u0norm = sqrt(s/Nx)\n\n avgtime = 0.\n do r = 1, Nruns\n u = u0\n call cpu_time(tstart)\n call ksintegrate(Nt, u)\n call cpu_time(tend)\n print*, 'cputime = ', tend-tstart\n if(r>skip) avgtime = avgtime + tend-tstart\n end do\n avgtime = avgtime/(Nruns-skip)\n\n s = 0.0d0\n do i = 0, Nx-1 \n s = s + (abs(u(i)))**2\n end do \n uTnorm = sqrt(s/Nx)\n\n if (printnorms) then\n print*, 'norm(u(0)) = ', u0norm\n print*, 'norm(u(T)) = ', uTnorm\n end if\t \t \n\n print*, 'avgtime (seconds) = ', avgtime\n\n open(10, status='unknown', file='u.dat')\n write(10,'(3e20.12)') (x(i),u(i), i=0,Nx-1)\n close(10)\n\n end program main\n\n!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n subroutine ksintegrate(Nt, u)\n use KS\n implicit none\n integer, intent(in) :: Nt\n double complex, intent(inout) :: u(0:Nx-1)\n double precision :: dt2, dt32, Nx_inv\n double precision :: A_inv(0:Nx-1), B(0:Nx-1), L(0:Nx-1), kx(0:Nx-1)\n double complex :: alpha(0:Nx-1), G(0:Nx-1), Nn(0:Nx-1), Nn1(0:Nx-1)\n double complex, save :: u_(0:Nx-1), uu(0:Nx-1) \n double complex, save :: us(0:Nx-1), uus(0:Nx-1)\n logical, save :: planned=.false.\n integer*8, save :: plan_u2us, plan_us2u, plan_uu2uus \n integer :: n, fftw_patient=32, fftw_estimate=64, fftw_forward=-1, fftw_backward=1\n\n if(.not.planned) then\n call dfftw_plan_dft_1d(plan_u2us, Nx, u_, us, fftw_forward, fftw_estimate)\n call dfftw_plan_dft_1d(plan_us2u, Nx, us, u_, fftw_backward, fftw_estimate)\n call dfftw_plan_dft_1d(plan_uu2uus, Nx, uu, uus, fftw_forward, fftw_estimate)\n planned = .true.\n end if\n\n do n = 0, Nx/2-1\n kx(n) = n\n end do\n kx(Nx/2) = 0d0\n do n = Nx/2+1, Nx-1\n kx(n) = -Nx + n;\n end do\n alpha = (2d0*pi/Lx)*kx\n L = alpha**2 - alpha**4\n G = -0.5d0*dcmplx(0d0,1d0)*alpha\n \n Nx_inv = 1d0/Nx\n dt2 = dt/2d0\n dt32 = 3d0*dt/2d0\n A_inv = 1d0/(1d0 - dt2*L)\n B = 1d0 + dt2*L\n\n uu = u*u\n call dfftw_execute(plan_uu2uus)\n Nn = G*uus\n Nn1 = Nn\n\n u_ = u\n call dfftw_execute(plan_u2us)\n\n do n = 1, Nt\n Nn1 = Nn\n call dfftw_execute(plan_us2u)\n u_ = u_ * Nx_inv\n uu = u_*u_\n call dfftw_execute(plan_uu2uus)\n Nn = G*uus\n us = A_inv * (B*us + dt32*Nn - dt2*Nn1)\n !us = A_inv * (B*us)\n end do\n\n call dfftw_execute(plan_us2u)\n u = u_ * Nx_inv\n\n end subroutine ksintegrate\n", "meta": {"hexsha": "5a51aed338da4a7af92f3b2a62c4c990f44de438", "size": 3782, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "codes/ksbenchmark.f90", "max_stars_repo_name": "raphbacher/julia-intro", "max_stars_repo_head_hexsha": "ecf7d683b46a75fa2214edf55e9873ee57de3834", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 33, "max_stars_repo_stars_event_min_datetime": "2017-07-21T17:56:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-10T07:56:55.000Z", "max_issues_repo_path": "codes/ksbenchmark.f90", "max_issues_repo_name": "raphbacher/julia-intro", "max_issues_repo_head_hexsha": "ecf7d683b46a75fa2214edf55e9873ee57de3834", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2017-07-24T03:40:18.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-11T01:34:23.000Z", "max_forks_repo_path": "codes/ksbenchmark.f90", "max_forks_repo_name": "raphbacher/julia-intro", "max_forks_repo_head_hexsha": "ecf7d683b46a75fa2214edf55e9873ee57de3834", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2017-07-24T00:46:48.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-02T14:33:02.000Z", "avg_line_length": 26.0827586207, "max_line_length": 84, "alphanum_fraction": 0.5399259651, "num_tokens": 1539, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772417253256, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.6794201231583512}} {"text": "program test4\n\n use multigrid\n\n implicit none\n\n integer, parameter :: num=selected_real_kind(p=15)\n real(num) :: pi = 4.0_num * ATAN(1.0_num)\n real(num) :: pi2 = 8.0_num * ATAN(1.0_num)\n\n integer :: nx, ny, ix, iy\n\n real(num) :: x,y, dx, dy, L2, x_min, x_max, y_min, y_max\n\n real(num), dimension(:), allocatable :: xc, yc\n real(num), dimension(:,:), allocatable :: f,analytic, phi, eta\n real(num), dimension(:), allocatable :: L2_arr, n_arr\n\n integer :: power, power_min, power_max\n\n type(mg_input) :: input\n\n ! setup a test problem \n\n print *,'Test4: True test of D(eta G(phi)) = f , where eta is spatially varying'\n\n power_min = 3\n power_max = 10\n\n allocate(L2_arr(1:1+power_max-power_min))\n allocate(n_arr(1:1+power_max-power_min))\n L2_arr = 1e6_num\n n_arr = 0\n\n different_resolutions: do power= power_min, power_max\n\n nx = 2**power \n ny = nx\n x_min = 0.0_num\n x_max = 1.0_num\n y_min = x_min\n y_max = x_max\n \n allocate(xc(-1:nx+2))\n allocate(yc(-1:ny+2))\n \n dx = (x_max - x_min) / real(nx,num)\n xc(-1) = x_min - 3.0_num * dx / 2.0_num \n do ix = 0,nx+2\n xc(ix) = xc(ix-1) + dx\n enddo\n \n dy = (y_max - y_min) / real(ny,num)\n yc(-1) = y_min - 3.0_num * dy / 2.0_num \n do iy = 0,ny+2\n yc(iy) = yc(iy-1) + dy\n enddo\n \n allocate(phi(-1:nx+2,-1:ny+2)) ! again, redundant ghosts but for comparison to CCAPS\n phi = 0.0_num \n \n allocate(analytic(1:nx,1:ny)) ! again, redundant ghosts but for comparison to CCAPS\n analytic = 0.0_num \n \n \n allocate(f(1:nx,1:ny))\n \n do iy = 1, ny\n do ix = 1, nx\n x = xc(ix)\n y = yc(iy)\n f(ix,iy) = -16.0_num * pi**2 * (cos(pi2*x)*cos(pi2*y) +1.0_num) * sin(pi2*x) * sin(pi2*y)\n! f(ix,iy) = -4.0_num * pi**2 * ( 4.0_num * sin(pi2 * x) * sin(pi2 * y) + sin(2.0_num * pi2 *x) * sin(2.0_num * pi2 *y))\n enddo\n enddo\n \n allocate(eta(1:nx,1:ny)) ! again, redundant ghosts but for comparison to CCAPS\n do iy = 1, ny\n do ix = 1, nx\n eta(ix,iy) = 2.0_num + cos(2.0_num * pi * xc(ix)) * cos(2.0_num * pi * yc(iy)) \n enddo\n enddo \n ! solve for phi\n \n\n\n input = mg_input(tol = 1e-12_num, nx=nx, ny = ny, dx=dx, dy=dy, f = f, phi = phi, &\n & bc_xmin = 'periodic', bc_ymin='periodic', bc_xmax='periodic', bc_ymax = 'periodic', &\n & deallocate_after = .true., &\n & eta = eta, eta_present = .true., & \n & eta_bc_xmin = 'periodic', eta_bc_ymin='periodic', eta_bc_xmax='periodic', eta_bc_ymax = 'periodic')\n\n call mg_interface(input)\n\n phi = input%phi\n\n ! test against analytical solution\n \n do iy = 1, ny\n do ix = 1, nx\n x = xc(ix)\n y = yc(iy)\n analytic(ix,iy) = sin(pi2*x)*sin(pi2*y)\n enddo\n enddo\n\n ! subtract the average of phi since there is nothing to anchor the solution\n phi = phi- sum(phi(1:nx,1:ny)) / real(nx*ny,num) \n \n L2 = sqrt(sum(abs(analytic(1:nx,1:ny)-phi(1:nx,1:ny))**2) / real(nx*ny,num))\n \n \n print *,'L2',L2\n \n L2_arr(power-power_min+1) = L2\n n_arr(power-power_min+1) = real(nx,num)\n\n \n ! deallocate all so can do again\n \n deallocate(xc)\n deallocate(yc)\n deallocate(f)\n deallocate(phi)\n deallocate(analytic)\n deallocate(eta)\n\n enddo different_resolutions\n\n print *, 'L2 _arr',L2_arr\n print *, 'n _arr',n_arr\n\n call execute_command_line(\"rm -rf test4_l2.dat\")\n call execute_command_line(\"rm -rf test4_nx.dat\")\n\n open(10, file=\"test4_l2.dat\", access=\"stream\")\n write(10) L2_arr\n close(10)\n\n open(10, file=\"test4_nx.dat\", access=\"stream\")\n write(10) n_arr\n close(10)\n\n call execute_command_line(\"python test4_plots.py\")\n call execute_command_line(\"rm test4_l2.dat\")\n call execute_command_line(\"rm test4_nx.dat\")\n\n\nend program test4\n", "meta": {"hexsha": "48297222dde7758357816602fd593965ea931315", "size": 3758, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "multigrid/2D/test4.f90", "max_stars_repo_name": "JOThurgood/SimpleCFD", "max_stars_repo_head_hexsha": "d0dc2fae9dab21c33d50b443caa727fa763c95d9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-04-23T05:31:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-04T23:21:11.000Z", "max_issues_repo_path": "multigrid/2D/test4.f90", "max_issues_repo_name": "JOThurgood/SimpleCFD", "max_issues_repo_head_hexsha": "d0dc2fae9dab21c33d50b443caa727fa763c95d9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 39, "max_issues_repo_issues_event_min_datetime": "2018-08-31T23:48:02.000Z", "max_issues_repo_issues_event_max_datetime": "2019-08-07T10:03:11.000Z", "max_forks_repo_path": "multigrid/2D/test4.f90", "max_forks_repo_name": "JOThurgood/SimpleCFD", "max_forks_repo_head_hexsha": "d0dc2fae9dab21c33d50b443caa727fa763c95d9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-11-14T20:42:54.000Z", "max_forks_repo_forks_event_max_datetime": "2019-05-18T09:16:27.000Z", "avg_line_length": 25.0533333333, "max_line_length": 125, "alphanum_fraction": 0.5968600319, "num_tokens": 1364, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772417253256, "lm_q2_score": 0.7772998611746911, "lm_q1q2_score": 0.6794201186490525}} {"text": "!! BSD 3-Clause License\n!\n! Copyright (c) 2021, Fabio Durastante, Lidia Aceto\n! All rights reserved.\n!\n! Redistribution and use in source and binary forms, with or without\n! modification, are permitted provided that the following conditions are met:\n!\n! 1. Redistributions of source code must retain the above copyright notice, this\n! list of conditions and the following disclaimer.\n!\n! 2. Redistributions in binary form must reproduce the above copyright notice,\n! this list of conditions and the following disclaimer in the documentation\n! and/or other materials provided with the distribution.\n!\n! 3. Neither the name of the copyright holder nor the names of its\n! contributors may be used to endorse or promote products derived from\n! this software without specific prior written permission.\n!\n! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n! DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\n! FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n! DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n! SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\n! OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n! OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\nprogram optimalxitest\n ! This test program uses Brent's method to compute the value of the optimal\n ! :math:`\\xi`, and thus :math:`N`, for the computation of the Wright function.\n\n use iso_fortran_env, only: real32, real64, real128, output_unit\n use brentmod, only: fminbnd\n implicit none\n\n real(real64) :: c,N\n real(real64) :: mu = 3\n\n write(output_unit,'(\"Optimal c/N Test\")')\n\n N = fminbnd(0.1_real64, 0.99_real64, 0.5_real64, 200.0_real64, &\n & epsilon(c), epsilon(c), 1.0D-3, fobjective, c)\n\n write(output_unit,'(\"c = \",F20.16,\" N = \",I3)')c,floor(N)\n\ncontains\n\n function fobjective(carg) result(f)\n use iso_fortran_env, only: real64\n implicit none\n\n real(real64) :: carg\n real(real64) :: f\n ! Constants and local variables\n real(real64) :: pi = 3.141592653589793\n real(real64) :: l,ltol\n\n l = - log(epsilon(c))\n ltol = - log(1.0E-15)\n\n f = (sqrt(l*ltol)/pi)* &\n & sqrt(1.0_real64 + (1.0_real64/carg)*(1.0_real64 + ((2.0_real64 - mu)/ltol) &\n & *log(1.0_real64-carg)))\n\n write(output_unit,'(\"f = \",F20.16,\" c = \",F20.16)')f,carg\n\n end function fobjective\n\nend program optimalxitest\n", "meta": {"hexsha": "f67ae187ae9fce28cf9a4969b638013a39fab1e6", "size": 2746, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/optimalxitest.f90", "max_stars_repo_name": "Cirdans-Home/mwright", "max_stars_repo_head_hexsha": "60fa0d838304217ab5a9d8a7f262c6da150224b9", "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": "test/optimalxitest.f90", "max_issues_repo_name": "Cirdans-Home/mwright", "max_issues_repo_head_hexsha": "60fa0d838304217ab5a9d8a7f262c6da150224b9", "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": "test/optimalxitest.f90", "max_forks_repo_name": "Cirdans-Home/mwright", "max_forks_repo_head_hexsha": "60fa0d838304217ab5a9d8a7f262c6da150224b9", "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": 38.1388888889, "max_line_length": 88, "alphanum_fraction": 0.7199563001, "num_tokens": 739, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772417253255, "lm_q2_score": 0.7772998611746911, "lm_q1q2_score": 0.6794201186490524}} {"text": "module boundary_condition_m\n\n implicit none\n\n type bc_t\n\n character :: type ! N for Neumann, D for Dirichlet\n real(kind=8) :: a, b, c ! Boundary condition formulated as a+b*x+c*x^2\n\n end type bc_t\n\ncontains\n\nreal(kind=8) function bc_get_value(t, x)\n type(bc_t), intent(in) :: t\n real(kind=8), intent(in) :: x\n\n bc_get_value = t%a+t%b*x+t%c*x**2\n\nend function bc_get_value\n\nend module boundary_condition_m", "meta": {"hexsha": "822a7aadf282ae43de1cb933208eb5d127417ce3", "size": 436, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "boundary_condition.f95", "max_stars_repo_name": "corygoates/Flow81", "max_stars_repo_head_hexsha": "3285fcad89fc7cad5b003b7266e2ec767932d41b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-06-23T00:18:33.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-23T00:18:33.000Z", "max_issues_repo_path": "boundary_condition.f95", "max_issues_repo_name": "corygoates/Flow81", "max_issues_repo_head_hexsha": "3285fcad89fc7cad5b003b7266e2ec767932d41b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "boundary_condition.f95", "max_forks_repo_name": "corygoates/Flow81", "max_forks_repo_head_hexsha": "3285fcad89fc7cad5b003b7266e2ec767932d41b", "max_forks_repo_licenses": ["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.8181818182, "max_line_length": 78, "alphanum_fraction": 0.6605504587, "num_tokens": 128, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8740772351648677, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.6794201180589081}} {"text": "*DECK DBESJ0\n DOUBLE PRECISION FUNCTION DBESJ0 (X)\nC***BEGIN PROLOGUE DBESJ0\nC***PURPOSE Compute the Bessel function of the first kind of order\nC zero.\nC***LIBRARY SLATEC (FNLIB)\nC***CATEGORY C10A1\nC***TYPE DOUBLE PRECISION (BESJ0-S, DBESJ0-D)\nC***KEYWORDS BESSEL FUNCTION, FIRST KIND, FNLIB, ORDER ZERO,\nC SPECIAL FUNCTIONS\nC***AUTHOR Fullerton, W., (LANL)\nC***DESCRIPTION\nC\nC DBESJ0(X) calculates the double precision Bessel function of\nC the first kind of order zero for double precision argument X.\nC\nC Series for BJ0 on the interval 0. to 1.60000E+01\nC with weighted error 4.39E-32\nC log weighted error 31.36\nC significant figures required 31.21\nC decimal places required 32.00\nC\nC***REFERENCES (NONE)\nC***ROUTINES CALLED D1MACH, D9B0MP, DCSEVL, INITDS\nC***REVISION HISTORY (YYMMDD)\nC 770701 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890531 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC***END PROLOGUE DBESJ0\n DOUBLE PRECISION X, BJ0CS(19), AMPL, THETA, XSML, Y, D1MACH,\n 1 DCSEVL\n LOGICAL FIRST\n SAVE BJ0CS, NTJ0, XSML, FIRST\n DATA BJ0CS( 1) / +.1002541619 6893913701 0731272640 74 D+0 /\n DATA BJ0CS( 2) / -.6652230077 6440513177 6787578311 24 D+0 /\n DATA BJ0CS( 3) / +.2489837034 9828131370 4604687266 80 D+0 /\n DATA BJ0CS( 4) / -.3325272317 0035769653 8843415038 54 D-1 /\n DATA BJ0CS( 5) / +.2311417930 4694015462 9049241177 29 D-2 /\n DATA BJ0CS( 6) / -.9911277419 9508092339 0485193365 49 D-4 /\n DATA BJ0CS( 7) / +.2891670864 3998808884 7339037470 78 D-5 /\n DATA BJ0CS( 8) / -.6121085866 3032635057 8184074815 16 D-7 /\n DATA BJ0CS( 9) / +.9838650793 8567841324 7687486364 15 D-9 /\n DATA BJ0CS( 10) / -.1242355159 7301765145 5158970068 36 D-10 /\n DATA BJ0CS( 11) / +.1265433630 2559045797 9158272103 63 D-12 /\n DATA BJ0CS( 12) / -.1061945649 5287244546 9148175129 59 D-14 /\n DATA BJ0CS( 13) / +.7470621075 8024567437 0989155840 00 D-17 /\n DATA BJ0CS( 14) / -.4469703227 4412780547 6270079999 99 D-19 /\n DATA BJ0CS( 15) / +.2302428158 4337436200 5230933333 33 D-21 /\n DATA BJ0CS( 16) / -.1031914479 4166698148 5226666666 66 D-23 /\n DATA BJ0CS( 17) / +.4060817827 4873322700 8000000000 00 D-26 /\n DATA BJ0CS( 18) / -.1414383600 5240913919 9999999999 99 D-28 /\n DATA BJ0CS( 19) / +.4391090549 6698880000 0000000000 00 D-31 /\n DATA FIRST /.TRUE./\nC***FIRST EXECUTABLE STATEMENT DBESJ0\n IF (FIRST) THEN\n NTJ0 = INITDS (BJ0CS, 19, 0.1*REAL(D1MACH(3)))\n XSML = SQRT(8.0D0*D1MACH(3))\n ENDIF\n FIRST = .FALSE.\nC\n Y = ABS(X)\n IF (Y.GT.4.0D0) GO TO 20\nC\n DBESJ0 = 1.0D0\n IF (Y.GT.XSML) DBESJ0 = DCSEVL (.125D0*Y*Y-1.D0, BJ0CS, NTJ0)\n RETURN\nC\n 20 CALL D9B0MP (Y, AMPL, THETA)\n DBESJ0 = AMPL * COS(THETA)\nC\n RETURN\n END\n", "meta": {"hexsha": "4d4a0077f7df13e7d82335a2bae6a738e87f6414", "size": 3185, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "external/SLATEC/src/dbesj0.f", "max_stars_repo_name": "ygeorgi/MESS", "max_stars_repo_head_hexsha": "42db490295b08193dfc37496489467ccd2e5b6ae", "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": "external/SLATEC/src/dbesj0.f", "max_issues_repo_name": "ygeorgi/MESS", "max_issues_repo_head_hexsha": "42db490295b08193dfc37496489467ccd2e5b6ae", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "external/SLATEC/src/dbesj0.f", "max_forks_repo_name": "ygeorgi/MESS", "max_forks_repo_head_hexsha": "42db490295b08193dfc37496489467ccd2e5b6ae", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.0405405405, "max_line_length": 71, "alphanum_fraction": 0.6119309262, "num_tokens": 1258, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648678, "lm_q2_score": 0.7772998663336157, "lm_q1q2_score": 0.6794201180589081}} {"text": " SUBROUTINE fdjac(n,x,fvec,np,df)\r\n INTEGER n,np,NMAX\r\n REAL df(np,np),fvec(n),x(n),EPS\r\n PARAMETER (NMAX=40,EPS=1.e-4)\r\nCU USES funcv\r\n INTEGER i,j\r\n REAL h,temp,f(NMAX)\r\n do 12 j=1,n\r\n temp=x(j)\r\n h=EPS*abs(temp)\r\n if(h.eq.0.)h=EPS\r\n x(j)=temp+h\r\n h=x(j)-temp\r\n call funcv(n,x,f)\r\n x(j)=temp\r\n do 11 i=1,n\r\n df(i,j)=(f(i)-fvec(i))/h\r\n11 continue\r\n12 continue\r\n return\r\n END\r\n", "meta": {"hexsha": "d1bca8f28f706c8611c3809929123aa88d8fad33", "size": 498, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/fdjac.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/fdjac.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/fdjac.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.6363636364, "max_line_length": 39, "alphanum_fraction": 0.4578313253, "num_tokens": 170, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648677, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.6794201135496095}} {"text": " PROGRAM xzbrak\r\nC driver for routine zbrak\r\n INTEGER N,NBMAX\r\n REAL X1,X2\r\n PARAMETER(N=100,NBMAX=20,X1=1.0,X2=50.0)\r\n INTEGER i,nb\r\n REAL bessj0,xb1(NBMAX),xb2(NBMAX)\r\n EXTERNAL bessj0\r\n nb=NBMAX\r\n call zbrak(bessj0,X1,X2,N,xb1,xb2,nb)\r\n write(*,'(/1x,a/)') 'Brackets for roots of BESSJ0:'\r\n write(*,'(/1x,t17,a,t27,a,t40,a,t50,a/)') 'lower','upper',\r\n * 'F(lower)','F(upper)'\r\n do 11 i=1,nb\r\n write(*,'(1x,a,i2,2(4x,2f10.4))') 'Root ',i,xb1(i),xb2(i),\r\n * bessj0(xb1(i)),bessj0(xb2(i))\r\n11 continue\r\n END\r\n", "meta": {"hexsha": "a2bbf09dcbcdd3cc3dd2efc62e2a156b4e39b6c3", "size": 606, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xzbrak.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xzbrak.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xzbrak.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.8947368421, "max_line_length": 67, "alphanum_fraction": 0.5264026403, "num_tokens": 250, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648676, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6794201090403108}} {"text": "c=======================================================================\n subroutine sweep(a,dim,m,k1,k2,ier)\nc=======================================================================\nc Subroutine to sweep the mxm matrix a on its k1 st thru k2 th\nc diagonals. ier is 1 if a is singular. dim is the real dimension\nc of a.\nc \nc Typically in regression: sweep(a,dim,m+1,1,m,ier) \nc The output is:\nc (xtx)^(-1) : (xtx)^(-1) xty\nc -ytx (xtx)^(-1) : yty-ytx (xtx)^(-1) xty\nc\nc Alejandro Jara\nc Department of Statistics\nc Facultad de Matematicas\nc Pontificia Universidad Catolica de Chile\nc Casilla 306, Correo 22 \nc Santiago\nc Chile\nc Voice: +56-2-3544506 URL : http://www.mat.puc.cl/~ajara\nc Fax : +56-2-3547729 Email: atjara@uc.cl\nc\nc=======================================================================\n implicit none\n integer dim,i,ier,j,k,k1,k2,m\n real*8 a(dim,dim),d\n\n ier=1\n \n do k=k1,k2\n if(abs(a(k,k)).lt.1.e-20) return\n d=1./a(k,k)\n a(k,k)=1.\n do i=1,m\n a(k,i)=d*a(k,i)\n if(i.ne.k) a(i,k)=-a(i,k)*d\n end do\n\n do i=1,m\n do j=1,m\n if((i.ne.k).and.(j.ne.k)) a(i,j)=a(i,j)+a(i,k)*a(k,j)/d\n end do\n end do \n end do\n\n ier=0\n return\n end\n\nc=======================================================================\n subroutine condmvn(ind,a,m,aw,perm)\nc=======================================================================\nc computes the conditional covariance matrix \nc A1.2 = A11 - A12*inv(A22)*A21 and the\nc matrix for conditional mean vector A12*inv(A22)\nc\nc Note: perm = Q permutation matrix. The ind coordinate is\nc placed in the first entry by using Q*A*Q^T\nc\nc Alejandro Jara, 2007 \nc=======================================================================\n implicit none\n\nc+++++Input\n integer ind,m\n real*8 a(m,m)\n\nc+++++Working\n integer maxm\n parameter(maxm=100)\n integer i,j,k,ier\n integer counter\n real*8 aw2(maxm,maxm),tmp1\n\nc+++++Output\n real*8 aw(m,m),perm(m,m) \n\nc+++++Algorithm\n\n if(maxm.lt.m)then\n call rexit(\"Increase 'maxm' in 'condmvn'\")\n end if \n\n if(ind.eq.1)then \n do i=1,m\n do j=1,m\n perm(i,j)=0.0d0 \n end do\n end do \n do i=1,m\n perm(i,i)=1.d0\n end do\n do i=1,m\n do j=1,m\n aw(i,j)=a(i,j) \n end do\n end do \n else \n do i=1,m\n do j=1,m\n perm(i,j)=0.0d0 \n end do\n end do \n perm(1,ind)=1.0d0\n counter=1\n do i=1,m\n if(i.ne.ind)then\n counter=counter+1\n perm(counter,i)=1.0d0\n end if\n end do\n do i=1,m\n do j=1,m\n tmp1=0.d0 \n do k=1,m\n tmp1=tmp1+perm(i,k)*a(k,j) \n end do\n aw2(i,j)=tmp1\n end do \n end do \n\n do i=1,m\n do j=1,m\n tmp1=0.d0 \n do k=1,m\n tmp1=tmp1+aw2(i,k)*perm(j,k) \n end do\n aw(i,j)=tmp1\n end do \n end do \n end if \n\nc do i=1,m\nc do j=1,m\nc call dblepr(\"aw\",-1,aw(i,j),1) \nc end do\nc end do \n\n call sweep(aw,m,m,2,m,ier)\n if(ier.eq.1)then\n call rexit(\"error in computing conditionals\")\n end if \n \n return\n end\n \n \n\n", "meta": {"hexsha": "b32c489e325991350a1693ff35043efb13bf5ef1", "size": 3748, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "DPpackage-modified/src/ToolsSweep.f", "max_stars_repo_name": "kdevick/densitymediation", "max_stars_repo_head_hexsha": "12bd192f922dae5c8adb8b5573ba8718ea08e9ee", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-16T03:35:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-16T03:35:49.000Z", "max_issues_repo_path": "DPpackage-modified/src/ToolsSweep.f", "max_issues_repo_name": "kdevick/densitymediation", "max_issues_repo_head_hexsha": "12bd192f922dae5c8adb8b5573ba8718ea08e9ee", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "DPpackage-modified/src/ToolsSweep.f", "max_forks_repo_name": "kdevick/densitymediation", "max_forks_repo_head_hexsha": "12bd192f922dae5c8adb8b5573ba8718ea08e9ee", "max_forks_repo_licenses": ["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.1543624161, "max_line_length": 72, "alphanum_fraction": 0.3959445037, "num_tokens": 1074, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044094, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.6794201084501662}} {"text": "MODULE qshep2d\r\n\r\n! ALGORITHM 660, COLLECTED ALGORITHMS FROM ACM.\r\n\r\n! THIS WORK PUBLISHED IN TRANSACTIONS ON MATHEMATICAL SOFTWARE,\r\n! VOL. 14, NO. 2, P.149.\r\n\r\n! Code converted using TO_F90 by Alan Miller\r\n! Date: 2001-01-18 Time: 10:10:42\r\n\r\nIMPLICIT NONE\r\n\r\n\r\nCONTAINS\r\n\r\n\r\nSUBROUTINE qshep2(n,x,y,f,nq,nw,nr,lcell,lnext,xmin,ymin,dx,dy,rmax,rsq,a,ier)\r\nINTEGER, INTENT(IN) :: n, nq, nw, nr\r\nREAL, INTENT(IN) :: x(:), y(:), f(:)\r\nINTEGER, INTENT(OUT) :: lcell(:,:), lnext(:), ier\r\nREAL, INTENT(OUT) :: xmin, ymin, dx, dy, rmax, rsq(n), a(:,:)\r\n\r\n!***********************************************************\r\n\r\n! ROBERT RENKA\r\n! UNIV. OF NORTH TEXAS\r\n! (817) 565-2767\r\n! 01/08/90\r\n\r\n! THIS SUBROUTINE COMPUTES A SET OF PARAMETERS A AND RSQ DEFINING A SMOOTH\r\n! (ONCE CONTINUOUSLY DIFFERENTIABLE) BI-VARIATE FUNCTION Q(X,Y) WHICH\r\n! INTERPOLATES DATA VALUES F AT SCATTERED NODES (X,Y). THE INTERPOLANT Q MAY\r\n! BE EVALUATED AT AN ARBITRARY POINT BY FUNCTION QS2VAL, AND ITS FIRST\r\n! DERIVATIVES ARE COMPUTED BY SUBROUTINE QS2GRD.\r\n\r\n! THE INTERPOLATION SCHEME IS A MODIFIED QUADRATIC SHEPARD METHOD --\r\n\r\n! Q = (W(1)*Q(1)+W(2)*Q(2)+..+W(N)*Q(N))/(W(1)+W(2)+..+W(N))\r\n\r\n! FOR BIVARIATE FUNCTIONS W(K) AND Q(K). THE NODAL FUNCTIONS ARE GIVEN BY\r\n\r\n! Q(K)(X,Y) = A(1,K)*(X-X(K))**2 + A(2,K)*(X-X(K))*(Y-Y(K))\r\n! + A(3,K)*(Y-Y(K))**2 + A(4,K)*(X-X(K))\r\n! + A(5,K)*(Y-Y(K)) + F(K) .\r\n\r\n! THUS, Q(K) IS A QUADRATIC FUNCTION WHICH INTERPOLATES THE DATA VALUE AT\r\n! NODE K. ITS COEFFICIENTS A(,K) ARE OBTAINED BY A WEIGHTED LEAST SQUARES FIT\r\n! TO THE CLOSEST NQ DATA POINTS WITH WEIGHTS SIMILAR TO W(K).\r\n! NOTE THAT THE RADIUS OF INFLUENCE FOR THE LEAST SQUARES FIT IS FIXED FOR\r\n! EACH K, BUT VARIES WITH K.\r\n\r\n! THE WEIGHTS ARE TAKEN TO BE\r\n\r\n! W(K)(X,Y) = ( (R(K)-D(K))+ / R(K)*D(K) )**2\r\n\r\n! WHERE (R(K)-D(K))+ = 0 IF R(K) <= D(K) AND D(K)(X,Y) IS THE EUCLIDEAN\r\n! DISTANCE BETWEEN (X,Y) AND (X(K),Y(K)). THE RADIUS OF INFLUENCE R(K) VARIES\r\n! WITH K AND IS CHOSEN SO THAT NW NODES ARE WITHIN THE RADIUS.\r\n! NOTE THAT W(K) IS NOT DEFINED AT NODE (X(K),Y(K)), BUT Q(X,Y) HAS LIMIT F(K)\r\n! AS (X,Y) APPROACHES (X(K),Y(K)).\r\n\r\n! ON INPUT --\r\n\r\n! N = NUMBER OF NODES AND ASSOCIATED DATA VALUES.\r\n! N >= 6.\r\n\r\n! X,Y = ARRAYS OF LENGTH N CONTAINING THE CARTESIAN\r\n! COORDINATES OF THE NODES.\r\n\r\n! F = ARRAY OF LENGTH N CONTAINING THE DATA VALUES\r\n! IN ONE-TO-ONE CORRESPONDENCE WITH THE NODES.\r\n\r\n! NQ = NUMBER OF DATA POINTS TO BE USED IN THE LEAST SQUARES FIT FOR\r\n! COEFFICIENTS DEFINING THE NODAL FUNCTIONS Q(K).\r\n! A HIGHLY RECOMMENDED VALUE IS NQ = 13.\r\n! 5 <= NQ <= MIN(40,N-1).\r\n\r\n! NW = NUMBER OF NODES WITHIN (AND DEFINING) THE RADII OF INFLUENCE\r\n! R(K) WHICH ENTER INTO THE WEIGHTS W(K). FOR N SUFFICIENTLY\r\n! LARGE, A RECOMMENDED VALUE IS NW = 19.\r\n! 1 <= NW <= MIN(40,N-1).\r\n\r\n! NR = NUMBER OF ROWS AND COLUMNS IN THE CELL GRID DEFINED IN\r\n! SUBROUTINE STORE2. A RECTANGLE CONTAINING THE NODES IS\r\n! PARTITIONED INTO CELLS IN ORDER TO INCREASE SEARCH EFFICIENCY.\r\n! NR = SQRT(N/3) IS RECOMMENDED.\r\n! NR >= 1.\r\n\r\n! THE ABOVE PARAMETERS ARE NOT ALTERED BY THIS ROUTINE.\r\n\r\n! LCELL = ARRAY OF LENGTH >= NR**2.\r\n\r\n! LNEXT = ARRAY OF LENGTH >= N.\r\n\r\n! RSQ = ARRAY OF LENGTH >= N.\r\n\r\n! A = ARRAY OF LENGTH >= 5N.\r\n\r\n! ON OUTPUT --\r\n\r\n! LCELL = NR BY NR ARRAY OF NODAL INDICES ASSOCIATED\r\n! WITH CELLS. REFER TO STORE2.\r\n\r\n! LNEXT = ARRAY OF LENGTH N CONTAINING NEXT-NODE INDI-\r\n! CES. REFER TO STORE2.\r\n\r\n! XMIN,YMIN,DX,DY = MINIMUM NODAL COORDINATES AND CELL\r\n! DIMENSIONS. REFER TO STORE2.\r\n\r\n! RMAX = SQUARE ROOT OF THE LARGEST ELEMENT IN RSQ --\r\n! MAXIMUM RADIUS R(K).\r\n\r\n! RSQ = ARRAY CONTAINING THE SQUARES OF THE RADII R(K)\r\n! WHICH ENTER INTO THE WEIGHTS W(K).\r\n\r\n! A = 5 BY N ARRAY CONTAINING THE COEFFICIENTS FOR\r\n! QUADRATIC NODAL FUNCTION Q(K) IN COLUMN K.\r\n\r\n! NOTE THAT THE ABOVE OUTPUT PARAMETERS ARE NOT DEFINED\r\n! UNLESS IER = 0.\r\n\r\n! IER = ERROR INDICATOR --\r\n! IER = 0 IF NO ERRORS WERE ENCOUNTERED.\r\n! IER = 1 IF N, NQ, NW, OR NR IS OUT OF RANGE.\r\n! IER = 2 IF DUPLICATE NODES WERE ENCOUNTERED.\r\n! IER = 3 IF ALL NODES ARE COLLINEAR.\r\n\r\n! MODULES REQUIRED BY QSHEP2 -- GETNP2, GIVENS, ROTATE,\r\n! SETUP2, STORE2\r\n\r\n! INTRINSIC FUNCTIONS CALLED BY QSHEP2 -- ABS, MIN, FLOAT,\r\n! MAX0, MIN0, SQRT\r\n\r\n!***********************************************************\r\n\r\nINTEGER :: i, ib, ierr, ip1, irm1, irow, j, jp1, k, lmax, lnp, neq, &\r\n nn, nnq, nnr, nnw, np, npts(40), nqwmax\r\nREAL :: av, avsq, b(6,6), c, ddx, ddy, dmin, fk, rq, rs, rsmx, &\r\n rsold, rws, s, sum, t, xk, xmn, yk, ymn\r\n\r\nREAL, PARAMETER :: dtol = 0.01, rtol = 1.0e-5, sf = 1.0\r\n\r\n! LOCAL PARAMETERS --\r\n\r\n! AV = ROOT-MEAN-SQUARE DISTANCE BETWEEN K AND THE NODES IN THE\r\n! LEAST SQUARES SYSTEM (UNLESS ADDITIONAL NODES ARE\r\n! INTRODUCED FOR STABILITY).\r\n! THE FIRST 3 COLUMNS OF THE MATRIX ARE SCALED BY 1/AVSQ,\r\n! THE LAST 2 BY 1/AV\r\n! AVSQ = AV*AV\r\n! B = TRANSPOSE OF THE AUGMENTED REGRESSION MATRIX\r\n! C = FIRST COMPONENT OF THE PLANE ROTATION USED TO ZERO THE\r\n! LOWER TRIANGLE OF B**T -- COMPUTED BY SUBROUTINE GIVENS\r\n! DDX,DDY = LOCAL VARIABLES FOR DX AND DY\r\n! DMIN = MINIMUM OF THE MAGNITUDES OF THE DIAGONAL ELEMENTS OF THE\r\n! REGRESSION MATRIX AFTER ZEROS ARE INTRODUCED BELOW THE\r\n! DIAGONAL\r\n! DTOL = TOLERANCE FOR DETECTING AN ILL-CONDITIONED SYSTEM.\r\n! THE SYSTEM IS ACCEPTED WHEN DMIN >= DTOL\r\n! FK = DATA VALUE AT NODE K -- F(K)\r\n! I = INDEX FOR A, B, AND NPTS\r\n! IB = DO-LOOP INDEX FOR BACK SOLVE\r\n! IERR = ERROR FLAG FOR THE CALL TO STORE2\r\n! IP1 = I+1\r\n! IRM1 = IROW-1\r\n! IROW = ROW INDEX FOR B\r\n! J = INDEX FOR A AND B\r\n! JP1 = J+1\r\n! K = NODAL FUNCTION INDEX AND COLUMN INDEX FOR A\r\n! LMAX = MAXIMUM NUMBER OF NPTS ELEMENTS (MUST BE CONSISTENT WITH\r\n! THE DIMENSION STATEMENT ABOVE)\r\n! LNP = CURRENT LENGTH OF NPTS\r\n! NEQ = NUMBER OF EQUATIONS IN THE LEAST SQUARES FIT\r\n! NN,NNQ,NNR = LOCAL COPIES OF N, NQ, AND NR\r\n! NNW = LOCAL COPY OF NW\r\n! NP = NPTS ELEMENT\r\n! NPTS = ARRAY CONTAINING THE INDICES OF A SEQUENCE OF NODES TO BE USED\r\n! IN THE LEAST SQUARES FIT OR TO COMPUTE RSQ. THE NODES ARE\r\n! ORDERED BY DISTANCE FROM K AND THE LAST ELEMENT\r\n! (USUALLY INDEXED BY LNP) IS USED ONLY TO DETERMINE RQ,\r\n! OR RSQ(K) IF NW > NQ\r\n! NQWMAX = MAX(NQ,NW)\r\n! RQ = RADIUS OF INFLUENCE WHICH ENTERS INTO THE\r\n! WEIGHTS FOR Q(K) (SEE SUBROUTINE SETUP2)\r\n! RS = SQUARED DISTANCE BETWEEN K AND NPTS(LNP) --\r\n! USED TO COMPUTE RQ AND RSQ(K)\r\n! RSMX = MAXIMUM RSQ ELEMENT ENCOUNTERED\r\n! RSOLD = SQUARED DISTANCE BETWEEN K AND NPTS(LNP-1) --\r\n! USED TO COMPUTE A RELATIVE CHANGE IN RS\r\n! BETWEEN SUCCEEDING NPTS ELEMENTS\r\n! RTOL = TOLERANCE FOR DETECTING A SUFFICIENTLY LARGE\r\n! RELATIVE CHANGE IN RS. IF THE CHANGE IS\r\n! NOT GREATER THAN RTOL, THE NODES ARE\r\n! TREATED AS BEING THE SAME DISTANCE FROM K\r\n! RWS = CURRENT VALUE OF RSQ(K)\r\n! S = SECOND COMPONENT OF THE PLANE GIVENS ROTATION\r\n! SF = MARQUARDT STABILIZATION FACTOR USED TO DAMP\r\n! OUT THE FIRST 3 SOLUTION COMPONENTS (SECOND\r\n! PARTIALS OF THE QUADRATIC) WHEN THE SYSTEM\r\n! IS ILL-CONDITIONED. AS SF INCREASES, THE\r\n! FITTING FUNCTION APPROACHES A LINEAR\r\n! SUM = SUM OF SQUARED EUCLIDEAN DISTANCES BETWEEN\r\n! NODE K AND THE NODES USED IN THE LEAST\r\n! SQUARES FIT (UNLESS ADDITIONAL NODES ARE\r\n! ADDED FOR STABILITY)\r\n! T = TEMPORARY VARIABLE FOR ACCUMULATING A SCALAR\r\n! PRODUCT IN THE BACK SOLVE\r\n! XK,YK = COORDINATES OF NODE K -- X(K), Y(K)\r\n! XMN,YMN = LOCAL VARIABLES FOR XMIN AND YMIN\r\n\r\nnn = n\r\nnnq = nq\r\nnnw = nw\r\nnnr = nr\r\nnqwmax = MAX(nnq,nnw)\r\nlmax = MIN(40,nn-1)\r\nIF (5 <= nnq .AND. 1 <= nnw .AND. nqwmax <= lmax .AND. nnr >= 1) THEN\r\n \r\n! CREATE THE CELL DATA STRUCTURE, AND INITIALIZE RSMX.\r\n \r\n CALL store2(nn,x,y,nnr,lcell,lnext,xmn,ymn,ddx,ddy,ierr)\r\n IF (ierr /= 0) GO TO 150\r\n rsmx = 0.\r\n \r\n! OUTER LOOP ON NODE K\r\n \r\n DO k = 1, nn\r\n xk = x(k)\r\n yk = y(k)\r\n fk = f(k)\r\n \r\n! MARK NODE K TO EXCLUDE IT FROM THE SEARCH FOR NEAREST\r\n! NEIGHBORS.\r\n \r\n lnext(k) = -lnext(k)\r\n \r\n! INITIALIZE FOR LOOP ON NPTS.\r\n \r\n rs = 0.\r\n sum = 0.\r\n rws = 0.\r\n rq = 0.\r\n lnp = 0\r\n \r\n! COMPUTE NPTS, LNP, RWS, NEQ, RQ, AND AVSQ.\r\n \r\n 10 sum = sum + rs\r\n IF (lnp /= lmax) THEN\r\n lnp = lnp + 1\r\n rsold = rs\r\n CALL getnp2(xk,yk,x,y,nnr,lcell,lnext,xmn,ymn,ddx,ddy,np,rs)\r\n IF (rs == 0.) GO TO 140\r\n npts(lnp) = np\r\n IF ((rs-rsold)/rs < rtol) GO TO 10\r\n IF (rws == 0. .AND. lnp > nnw) rws = rs\r\n IF (rq == 0. .AND. lnp > nnq) THEN\r\n \r\n! RQ = 0 (NOT YET COMPUTED) AND LNP > NQ. RQ =\r\n! SQRT(RS) IS SUFFICIENTLY LARGE TO (STRICTLY) INCLUDE\r\n! NQ NODES. THE LEAST SQUARES FIT WILL INCLUDE NEQ =\r\n! LNP - 1 EQUATIONS FOR 5 <= NQ <= NEQ < LMAX\r\n! <= N-1.\r\n \r\n neq = lnp - 1\r\n rq = SQRT(rs)\r\n avsq = sum / REAL(neq)\r\n END IF\r\n \r\n! BOTTOM OF LOOP -- TEST FOR TERMINATION.\r\n \r\n IF (lnp > nqwmax) GO TO 20\r\n GO TO 10\r\n END IF\r\n \r\n! ALL LMAX NODES ARE INCLUDED IN NPTS. RWS AND/OR RQ**2 IS\r\n! (ARBITRARILY) TAKEN TO BE 10 PERCENT LARGER THAN THE\r\n! DISTANCE RS TO THE LAST NODE INCLUDED.\r\n \r\n IF (rws == 0.) rws = 1.1 * rs\r\n IF (rq == 0.) THEN\r\n neq = lmax\r\n rq = SQRT(1.1*rs)\r\n avsq = sum / REAL(neq)\r\n END IF\r\n \r\n! STORE RSQ(K), UPDATE RSMX IF NECESSARY, AND COMPUTE AV.\r\n \r\n 20 rsq(k) = rws\r\n IF (rws > rsmx) rsmx = rws\r\n av = SQRT(avsq)\r\n \r\n! SET UP THE AUGMENTED REGRESSION MATRIX (TRANSPOSED) AS THE COLUMNS OF B,\r\n! AND ZERO OUT THE LOWER TRIANGLE (UPPER TRIANGLE OF B) WITH GIVENS\r\n! ROTATIONS -- QR DECOMPOSITION WITH ORTHOGONAL MATRIX Q NOT STORED.\r\n \r\n i = 0\r\n 30 i = i + 1\r\n np = npts(i)\r\n irow = MIN(i,6)\r\n CALL setup2(xk,yk,fk,x(np),y(np),f(np),av,avsq,rq,b(1,irow))\r\n IF (i == 1) GO TO 30\r\n irm1 = irow - 1\r\n DO j = 1, irm1\r\n jp1 = j + 1\r\n CALL givens(b(j,j),b(j,irow),c,s)\r\n CALL rotate(6-j,c,s,b(jp1:,j),b(jp1:,irow))\r\n END DO\r\n IF (i < neq) GO TO 30\r\n \r\n! TEST THE SYSTEM FOR ILL-CONDITIONING.\r\n \r\n dmin = MIN(ABS(b(1,1)),ABS(b(2,2)),ABS(b(3,3)),ABS(b(4,4)), ABS(b(5,5)))\r\n IF (dmin*rq < dtol) THEN\r\n IF (neq /= lmax) THEN\r\n \r\n! INCREASE RQ AND ADD ANOTHER EQUATION TO THE SYSTEM TO IMPROVE THE\r\n! CONDITIONING. THE NUMBER OF NPTS ELEMENTS IS ALSO INCREASED IF NECESSARY.\r\n \r\n 50 rsold = rs\r\n neq = neq + 1\r\n IF (neq /= lmax) THEN\r\n IF (neq /= lnp) THEN\r\n \r\n! NEQ < LNP\r\n \r\n np = npts(neq+1)\r\n rs = (x(np)-xk) ** 2 + (y(np)-yk) ** 2\r\n IF ((rs-rsold)/rs < rtol) GO TO 50\r\n rq = SQRT(rs)\r\n GO TO 30\r\n END IF\r\n \r\n! ADD AN ELEMENT TO NPTS.\r\n \r\n lnp = lnp + 1\r\n CALL getnp2(xk,yk,x,y,nnr,lcell,lnext,xmn,ymn,ddx,ddy, np,rs)\r\n IF (np == 0) GO TO 140\r\n npts(lnp) = np\r\n IF ((rs-rsold)/rs < rtol) GO TO 50\r\n rq = SQRT(rs)\r\n GO TO 30\r\n END IF\r\n \r\n rq = SQRT(1.1*rs)\r\n GO TO 30\r\n END IF\r\n \r\n! STABILIZE THE SYSTEM BY DAMPING SECOND PARTIALS -- ADD MULTIPLES OF THE\r\n! FIRST THREE UNIT VECTORS TO THE FIRST THREE EQUATIONS.\r\n \r\n DO i = 1, 3\r\n b(i,6) = sf\r\n ip1 = i + 1\r\n DO j = ip1, 6\r\n b(j,6) = 0.\r\n END DO\r\n DO j = i, 5\r\n jp1 = j + 1\r\n CALL givens(b(j,j),b(j,6),c,s)\r\n CALL rotate(6-j,c,s,b(jp1:,j),b(jp1:,6))\r\n END DO\r\n END DO\r\n \r\n! TEST THE STABILIZED SYSTEM FOR ILL-CONDITIONING.\r\n \r\n dmin = MIN(ABS(b(1,1)),ABS(b(2,2)),ABS(b(3,3)), &\r\n ABS(b(4,4)),ABS(b(5,5)))\r\n IF (dmin*rq < dtol) GO TO 150\r\n END IF\r\n \r\n! SOLVE THE 5 BY 5 TRIANGULAR SYSTEM FOR THE COEFFICIENTS\r\n \r\n DO ib = 1, 5\r\n i = 6 - ib\r\n t = 0.\r\n IF (i /= 5) THEN\r\n ip1 = i + 1\r\n DO j = ip1, 5\r\n t = t + b(j,i) * a(j,k)\r\n END DO\r\n END IF\r\n a(i,k) = (b(6,i)-t) / b(i,i)\r\n END DO\r\n \r\n! SCALE THE COEFFICIENTS TO ADJUST FOR THE COLUMN SCALING.\r\n \r\n DO i = 1, 3\r\n a(i,k) = a(i,k) / avsq\r\n END DO\r\n a(4,k) = a(4,k) / av\r\n a(5,k) = a(5,k) / av\r\n \r\n! UNMARK K AND THE ELEMENTS OF NPTS.\r\n \r\n lnext(k) = -lnext(k)\r\n DO i = 1, lnp\r\n np = npts(i)\r\n lnext(np) = -lnext(np)\r\n END DO\r\n END DO\r\n \r\n! NO ERRORS ENCOUNTERED.\r\n \r\n xmin = xmn\r\n ymin = ymn\r\n dx = ddx\r\n dy = ddy\r\n rmax = SQRT(rsmx)\r\n ier = 0\r\n RETURN\r\nEND IF\r\n\r\n! N, NQ, NW, OR NR IS OUT OF RANGE.\r\n\r\nier = 1\r\nRETURN\r\n\r\n! DUPLICATE NODES WERE ENCOUNTERED BY GETNP2.\r\n\r\n140 ier = 2\r\nRETURN\r\n\r\n! NO UNIQUE SOLUTION DUE TO COLLINEAR NODES.\r\n\r\n150 xmin = xmn\r\nymin = ymn\r\ndx = ddx\r\ndy = ddy\r\nier = 3\r\n\r\nRETURN\r\nEND SUBROUTINE qshep2\r\n\r\n\r\n\r\nFUNCTION qs2val(px,py,n,x,y,f,nr,lcell,lnext,xmin,ymin,dx,dy,rmax,rsq,a) &\r\n RESULT(fn_val)\r\nINTEGER, INTENT(IN) :: n, nr, lcell(:,:), lnext(:)\r\nREAL, INTENT(IN) :: px, py, x(:), y(:), f(:), xmin, ymin, dx, dy, &\r\n rmax, rsq(:), a(:,:)\r\nREAL :: fn_val\r\n\r\n!***********************************************************\r\n\r\n! ROBERT RENKA\r\n! UNIV. OF NORTH TEXAS\r\n! (817) 565-2767\r\n! 10/28/87\r\n\r\n! THIS FUNCTION RETURNS THE VALUE Q(PX,PY) WHERE Q IS THE WEIGHTED SUM\r\n! OF QUADRATIC NODAL FUNCTIONS DEFINED IN SUBROUTINE QSHEP2.\r\n! QS2GRD MAY BE CALLED TO COMPUTE A GRADIENT OF Q ALONG WITH THE VALUE,\r\n! AND/OR TO TEST FOR ERRORS.\r\n\r\n! ON INPUT --\r\n\r\n! PX,PY = CARTESIAN COORDINATES OF THE POINT P AT\r\n! WHICH Q IS TO BE EVALUATED.\r\n\r\n! N = NUMBER OF NODES AND DATA VALUES DEFINING Q.\r\n! N >= 6.\r\n\r\n! X,Y,F = ARRAYS OF LENGTH N CONTAINING THE NODES AND\r\n! DATA VALUES INTERPOLATED BY Q.\r\n\r\n! NR = NUMBER OF ROWS AND COLUMNS IN THE CELL GRID.\r\n! REFER TO STORE2. NR >= 1.\r\n\r\n! LCELL = NR BY NR ARRAY OF NODAL INDICES ASSOCIATED WITH CELLS.\r\n! REFER TO STORE2.\r\n\r\n! LNEXT = ARRAY OF LENGTH N CONTAINING NEXT-NODE INDICES.\r\n! REFER TO STORE2.\r\n\r\n! XMIN,YMIN,DX,DY = MINIMUM NODAL COORDINATES AND CELL DIMENSIONS.\r\n! DX AND DY MUST BE POSITIVE. REFER TO STORE2.\r\n\r\n! RMAX = SQUARE ROOT OF THE LARGEST ELEMENT IN RSQ -- MAXIMUM RADIUS.\r\n\r\n! RSQ = ARRAY OF LENGTH N CONTAINING THE SQUARED RADII\r\n! WHICH ENTER INTO THE WEIGHTS DEFINING Q.\r\n\r\n! A = 5 BY N ARRAY CONTAINING THE COEFFICIENTS FOR THE\r\n! NODAL FUNCTIONS DEFINING Q.\r\n\r\n! INPUT PARAMETERS ARE NOT ALTERED BY THIS FUNCTION. THE PARAMETERS OTHER\r\n! THAN PX AND PY SHOULD BE INPUT UNALTERED FROM THEIR VALUES ON OUTPUT FROM\r\n! QSHEP2. THIS FUNCTION SHOULD NOT BE CALLED IF A NONZERO ERROR FLAG WAS\r\n! RETURNED BY QSHEP2.\r\n\r\n! ON OUTPUT --\r\n\r\n! QS2VAL = FUNCTION VALUE Q(PX,PY) UNLESS N, NR, DX, DY, OR RMAX IS\r\n! INVALID, IN WHICH CASE NO VALUE IS RETURNED.\r\n\r\n! MODULES REQUIRED BY QS2VAL -- NONE\r\n\r\n! INTRINSIC FUNCTIONS CALLED BY QS2VAL -- IFIX, SQRT\r\n\r\n!***********************************************************\r\n\r\n! Local variables\r\nREAL :: delx, dely, ds, dxsq, dysq, rd, rds, rs, sw, swq, w, xp, yp\r\nINTEGER :: i, imax, imin, j, jmax, jmin, k, kp\r\n\r\nxp = px\r\nyp = py\r\nIF (n < 6 .OR. nr < 1 .OR. dx <= 0. .OR. dy <= 0. .OR. rmax < 0.) RETURN\r\n\r\n! SET IMIN, IMAX, JMIN, AND JMAX TO CELL INDICES DEFINING THE RANGE OF THE\r\n! SEARCH FOR NODES WHOSE RADII INCLUDE P.\r\n! THE CELLS WHICH MUST BE SEARCHED ARE THOSE INTERSECTED BY (OR CONTAINED\r\n! IN) A CIRCLE OF RADIUS RMAX CENTERED AT P.\r\n\r\nimin = (xp-xmin-rmax)/dx + 1\r\nimax = (xp-xmin+rmax)/dx + 1\r\nIF (imin < 1) imin = 1\r\nIF (imax > nr) imax = nr\r\njmin = (yp-ymin-rmax)/dy + 1\r\njmax = (yp-ymin+rmax)/dy + 1\r\nIF (jmin < 1) jmin = 1\r\nIF (jmax > nr) jmax = nr\r\n\r\n! THE FOLLOWING IS A TEST FOR NO CELLS WITHIN THE CIRCLE OF RADIUS RMAX.\r\n\r\nIF (imin <= imax .AND. jmin <= jmax) THEN\r\n \r\n! ACCUMULATE WEIGHT VALUES IN SW AND WEIGHTED NODAL FUNCTION VALUES IN SWQ.\r\n! THE WEIGHTS ARE W(K) = ((R-D)+/(R*D))**2 FOR R**2 = RSQ(K) AND\r\n! D = DISTANCE BETWEEN P AND NODE K.\r\n \r\n sw = 0.\r\n swq = 0.\r\n \r\n! OUTER LOOP ON CELLS (I,J).\r\n \r\n DO j = jmin, jmax\r\n DO i = imin, imax\r\n k = lcell(i,j)\r\n IF (k /= 0) THEN\r\n \r\n! INNER LOOP ON NODES K.\r\n \r\n 10 delx = xp - x(k)\r\n dely = yp - y(k)\r\n dxsq = delx * delx\r\n dysq = dely * dely\r\n ds = dxsq + dysq\r\n rs = rsq(k)\r\n IF (ds < rs) THEN\r\n IF (ds == 0.) GO TO 40\r\n rds = rs * ds\r\n rd = SQRT(rds)\r\n w = (rs+ds-rd-rd) / rds\r\n sw = sw + w\r\n swq = swq + w * (a(1,k)*dxsq + a(2,k)*delx*dely + a(3,k)*dysq + &\r\n a(4,k)*delx + a(5,k)*dely + f(k))\r\n END IF\r\n \r\n! BOTTOM OF LOOP ON NODES IN CELL (I,J).\r\n \r\n kp = k\r\n k = lnext(kp)\r\n IF (k /= kp) GO TO 10\r\n END IF\r\n END DO\r\n END DO\r\n \r\n! SW = 0 IFF P IS NOT WITHIN THE RADIUS R(K) FOR ANY NODE K.\r\n \r\n IF (sw == 0.) GO TO 50\r\n fn_val = swq / sw\r\n RETURN\r\n \r\n! (PX,PY) = (X(K),Y(K))\r\n \r\n 40 fn_val = f(k)\r\n RETURN\r\nEND IF\r\n\r\n! ALL WEIGHTS ARE 0 AT P.\r\n\r\n50 fn_val = 0.\r\n\r\nRETURN\r\nEND FUNCTION qs2val\r\n\r\n\r\n\r\nSUBROUTINE qs2grd(px,py,n,x,y,f,nr,lcell,lnext,xmin,ymin,dx,dy, &\r\n rmax,rsq,a,q,qx,qy,ier)\r\nINTEGER, INTENT(IN) :: n, nr, lcell(:,:), lnext(:)\r\nREAL, INTENT(IN) :: px, py, x(:), y(:), f(:), xmin, ymin, dx, dy, &\r\n rmax, rsq(:), a(:,:)\r\nREAL, INTENT(OUT) :: q, qx, qy\r\nINTEGER, INTENT(OUT) :: ier\r\n\r\n!***********************************************************\r\n\r\n! ROBERT RENKA\r\n! UNIV. OF NORTH TEXAS\r\n! (817) 565-2767\r\n! 10/28/87\r\n\r\n! THIS SUBROUTINE COMPUTES THE VALUE AND GRADIENT AT (PX,PY) OF THE\r\n! INTERPOLATORY FUNCTION Q DEFINED IN SUBROUTINE QSHEP2.\r\n! Q(X,Y) IS A WEIGHTED SUM OF QUADRATIC NODAL FUNCTIONS.\r\n\r\n! ON INPUT --\r\n\r\n! PX,PY = CARTESIAN COORDINATES OF THE POINT AT WHICH\r\n! Q AND ITS PARTIALS ARE TO BE EVALUATED.\r\n\r\n! N = NUMBER OF NODES AND DATA VALUES DEFINING Q.\r\n! N >= 6.\r\n\r\n! X,Y,F = ARRAYS OF LENGTH N CONTAINING THE NODES AND\r\n! DATA VALUES INTERPOLATED BY Q.\r\n\r\n! NR = NUMBER OF ROWS AND COLUMNS IN THE CELL GRID.\r\n! REFER TO STORE2. NR >= 1.\r\n\r\n! LCELL = NR BY NR ARRAY OF NODAL INDICES ASSOCIATED WITH CELLS.\r\n! REFER TO STORE2.\r\n\r\n! LNEXT = ARRAY OF LENGTH N CONTAINING NEXT-NODE INDICES.\r\n! REFER TO STORE2.\r\n\r\n! XMIN,YMIN,DX,DY = MINIMUM NODAL COORDINATES AND CELL DIMENSIONS.\r\n! DX AND DY MUST BE POSITIVE. REFER TO STORE2.\r\n\r\n! RMAX = SQUARE ROOT OF THE LARGEST ELEMENT IN RSQ -- MAXIMUM RADIUS.\r\n\r\n! RSQ = ARRAY OF LENGTH N CONTAINING THE SQUARED RADII\r\n! WHICH ENTER INTO THE WEIGHTS DEFINING Q.\r\n\r\n! A = 5 BY N ARRAY CONTAINING THE COEFFICIENTS FOR THE\r\n! NODAL FUNCTIONS DEFINING Q.\r\n\r\n! INPUT PARAMETERS ARE NOT ALTERED BY THIS SUBROUTINE.\r\n! THE PARAMETERS OTHER THAN PX AND PY SHOULD BE INPUT UNALTERED FROM THEIR\r\n! VALUES ON OUTPUT FROM QSHEP2. THIS SUBROUTINE SHOULD NOT BE CALLED IF A\r\n! NONZERO ERROR FLAG WAS RETURNED BY QSHEP2.\r\n\r\n! ON OUTPUT --\r\n\r\n! Q = VALUE OF Q AT (PX,PY) UNLESS IER .EQ. 1, IN\r\n! WHICH CASE NO VALUES ARE RETURNED.\r\n\r\n! QX,QY = FIRST PARTIAL DERIVATIVES OF Q AT (PX,PY) UNLESS IER .EQ. 1.\r\n\r\n! IER = ERROR INDICATOR\r\n! IER = 0 IF NO ERRORS WERE ENCOUNTERED.\r\n! IER = 1 IF N, NR, DX, DY OR RMAX IS INVALID.\r\n! IER = 2 IF NO ERRORS WERE ENCOUNTERED BUT (PX,PY) IS NOT WITHIN\r\n! THE RADIUS R(K) FOR ANY NODE K (AND THUS Q=QX=QY=0).\r\n\r\n! MODULES REQUIRED BY QS2GRD -- NONE\r\n\r\n! INTRINSIC FUNCTIONS CALLED BY QS2GRD -- IFIX, SQRT\r\n\r\n!***********************************************************\r\n\r\n! Local variables\r\nREAL :: delx, dely, ds, dxsq, dysq, qk, qkx, qky, rd, rds, rs, &\r\n sw, swq, swqx, swqy, sws, swx, swy, t, w, wx, wy, xp, yp\r\nINTEGER :: i, imax, imin, j, jmax, jmin, k, kp\r\n\r\nxp = px\r\nyp = py\r\nIF (n >= 6 .AND. nr >= 1 .AND. dx > 0. .AND. dy > 0. .AND. rmax >= 0.) THEN\r\n \r\n! SET IMIN, IMAX, JMIN, AND JMAX TO CELL INDICES DEFINING P.\r\n! THE RANGE OF THE SEARCH FOR NODES WHOSE RADII INCLUDE THE CELLS WHICH MUST\r\n! BE SEARCHED ARE THOSE INTERSECTED BY (OR CONTAINED IN) A CIRCLE OF RADIUS\r\n! RMAX CENTERED AT P.\r\n \r\n imin = (xp-xmin-rmax)/dx + 1\r\n imax = (xp-xmin+rmax)/dx + 1\r\n IF (imin < 1) imin = 1\r\n IF (imax > nr) imax = nr\r\n jmin = (yp-ymin-rmax)/dy + 1\r\n jmax = (yp-ymin+rmax)/dy + 1\r\n IF (jmin < 1) jmin = 1\r\n IF (jmax > nr) jmax = nr\r\n \r\n! THE FOLLOWING IS A TEST FOR NO CELLS WITHIN THE CIRCLE OF RADIUS RMAX.\r\n \r\n IF (imin > imax .OR. jmin > jmax) GO TO 50\r\n \r\n! Q = SWQ/SW = SUM(W(K)*Q(K))/SUM(W(K)) WHERE THE SUM IS FROM K = 1 TO N,\r\n! Q(K) IS THE QUADRATIC NODAL FUNCTION, AND W(K) = ((R-D)+/(R*D))**2 FOR\r\n! RADIUS R(K) AND DISTANCE D(K).\r\n! THUS\r\n \r\n! QX = (SWQX*SW - SWQ*SWX)/SW**2 AND\r\n! QY = (SWQY*SW - SWQ*SWY)/SW**2\r\n \r\n! WHERE SWQX AND SWX ARE PARTIAL DERIVATIVES WITH RESPECT TO X OF SWQ\r\n! AND SW, RESPECTIVELY. SWQY AND SWY ARE DEFINED SIMILARLY.\r\n \r\n sw = 0.\r\n swx = 0.\r\n swy = 0.\r\n swq = 0.\r\n swqx = 0.\r\n swqy = 0.\r\n \r\n! OUTER LOOP ON CELLS (I,J).\r\n \r\n DO j = jmin, jmax\r\n DO i = imin, imax\r\n k = lcell(i,j)\r\n IF (k /= 0) THEN\r\n \r\n! INNER LOOP ON NODES K.\r\n \r\n 10 delx = xp - x(k)\r\n dely = yp - y(k)\r\n dxsq = delx * delx\r\n dysq = dely * dely\r\n ds = dxsq + dysq\r\n rs = rsq(k)\r\n IF (ds < rs) THEN\r\n IF (ds == 0.) GO TO 40\r\n rds = rs * ds\r\n rd = SQRT(rds)\r\n w = (rs+ds-rd-rd) / rds\r\n t = 2. * (rd-rs) / (ds*rds)\r\n wx = delx * t\r\n wy = dely * t\r\n qkx = 2. * a(1,k) * delx + a(2,k) * dely\r\n qky = a(2,k) * delx + 2. * a(3,k) * dely\r\n qk = (qkx*delx+qky*dely) / 2.\r\n qkx = qkx + a(4,k)\r\n qky = qky + a(5,k)\r\n qk = qk + a(4,k) * delx + a(5,k) * dely + f(k)\r\n sw = sw + w\r\n swx = swx + wx\r\n swy = swy + wy\r\n swq = swq + w * qk\r\n swqx = swqx + wx * qk + w * qkx\r\n swqy = swqy + wy * qk + w * qky\r\n END IF\r\n \r\n! BOTTOM OF LOOP ON NODES IN CELL (I,J).\r\n \r\n kp = k\r\n k = lnext(kp)\r\n IF (k /= kp) GO TO 10\r\n END IF\r\n END DO\r\n END DO\r\n \r\n! SW = 0 IFF P IS NOT WITHIN THE RADIUS R(K) FOR ANY NODE K.\r\n \r\n IF (sw == 0.) GO TO 50\r\n q = swq / sw\r\n sws = sw * sw\r\n qx = (swqx*sw-swq*swx) / sws\r\n qy = (swqy*sw-swq*swy) / sws\r\n ier = 0\r\n RETURN\r\n \r\n! (PX,PY) = (X(K),Y(K))\r\n \r\n 40 q = f(k)\r\n qx = a(4,k)\r\n qy = a(5,k)\r\n ier = 0\r\n RETURN\r\nEND IF\r\n\r\n! INVALID INPUT PARAMETER.\r\n\r\nier = 1\r\nRETURN\r\n\r\n! NO CELLS CONTAIN A POINT WITHIN RMAX OF P, OR\r\n! SW = 0 AND THUS DS >= RSQ(K) FOR ALL K.\r\n\r\n50 q = 0.\r\nqx = 0.\r\nqy = 0.\r\nier = 2\r\n\r\nRETURN\r\nEND SUBROUTINE qs2grd\r\n\r\n\r\n\r\nSUBROUTINE getnp2(px,py,x,y,nr,lcell,lnext,xmin,ymin,dx,dy,np,dsq)\r\nINTEGER, INTENT(IN) :: nr, lcell(:,:)\r\nINTEGER, INTENT(IN OUT) :: lnext(:)\r\nREAL, INTENT(IN) :: px, py, x(1), y(1), xmin, ymin, dx, dy\r\nINTEGER, INTENT(OUT) :: np\r\nREAL, INTENT(OUT) :: dsq\r\n\r\n!***********************************************************\r\n\r\n! ROBERT RENKA\r\n! UNIV. OF NORTH TEXAS\r\n! (817) 565-2767\r\n\r\n! GIVEN A SET OF N NODES AND THE DATA STRUCTURE DEFINED IN SUBROUTINE STORE2,\r\n! THIS SUBROUTINE USES THE CELL METHOD TO FIND THE CLOSEST UNMARKED NODE NP TO\r\n! A SPECIFIED POINT P.\r\n! NP IS THEN MARKED BY SETTING LNEXT(NP) TO -LNEXT(NP). (A NODE IS MARKED IF\r\n! AND ONLY IF THE CORRESPONDING LNEXT ELEMENT IS NEGATIVE. THE ABSOLUTE\r\n! VALUES OF LNEXT ELEMENTS, HOWEVER, MUST BE PRESERVED.) THUS, THE CLOSEST\r\n! M NODES TO P MAY BE DETERMINED BY A SEQUENCE OF M CALLS TO THIS ROUTINE.\r\n! NOTE THAT IF THE NEAREST NEIGHBOR TO NODE K IS TO BE DETERMINED (PX = X(K)\r\n! AND PY = Y(K)), THEN K SHOULD BE MARKED BEFORE THE CALL TO THIS ROUTINE.\r\n\r\n! THE SEARCH IS BEGUN IN THE CELL CONTAINING (OR CLOSEST TO) P AND PROCEEDS\r\n! OUTWARD IN RECTANGULAR LAYERS UNTIL ALL CELLS WHICH CONTAIN POINTS WITHIN\r\n! DISTANCE R OF P HAVE BEEN SEARCHED, WHERE R IS THE DISTANCE FROM P TO THE\r\n! FIRST UNMARKED NODE ENCOUNTERED (INFINITE IF NO UNMARKED NODES ARE PRESENT).\r\n\r\n! ON INPUT --\r\n\r\n! PX,PY = CARTESIAN COORDINATES OF THE POINT P WHOSE\r\n! NEAREST UNMARKED NEIGHBOR IS TO BE FOUND.\r\n\r\n! X,Y = ARRAYS OF LENGTH N, FOR N >= 2, CONTAINING\r\n! THE CARTESIAN COORDINATES OF THE NODES.\r\n\r\n! NR = NUMBER OF ROWS AND COLUMNS IN THE CELL GRID.\r\n! NR >= 1.\r\n\r\n! LCELL = NR BY NR ARRAY OF NODAL INDICES ASSOCIATED WITH CELLS.\r\n\r\n! LNEXT = ARRAY OF LENGTH N CONTAINING NEXT-NODE INDICES\r\n! (OR THEIR NEGATIVES).\r\n\r\n! XMIN,YMIN,DX,DY = MINIMUM NODAL COORDINATES AND CELL DIMENSIONS.\r\n! DX AND DY MUST BE POSITIVE.\r\n\r\n! INPUT PARAMETERS OTHER THAN LNEXT ARE NOT ALTERED BY THIS ROUTINE. WITH\r\n! THE EXCEPTION OF (PX,PY) AND THE SIGNS OF LNEXT ELEMENTS, THESE PARAMETERS\r\n! SHOULD BE UNALTERED FROM THEIR VALUES ON OUTPUT FROM SUBROUTINE STORE2.\r\n\r\n! ON OUTPUT --\r\n\r\n! NP = INDEX (FOR X AND Y) OF THE NEAREST UNMARKED NODE TO P,\r\n! OR 0 IF ALL NODES ARE MARKED OR NR < 1 OR DX <= 0 OR\r\n! DY <= 0.\r\n! LNEXT(NP) < 0 IF NP .NE. 0.\r\n\r\n! DSQ = SQUARED EUCLIDEAN DISTANCE BETWEEN P AND NODE\r\n! NP, OR 0 IF NP = 0.\r\n\r\n! MODULES REQUIRED BY GETNP2 -- NONE\r\n\r\n! INTRINSIC FUNCTIONS CALLED BY GETNP2 -- ABS, IFIX, SQRT\r\n\r\n!***********************************************************\r\n\r\n! Local variables\r\nLOGICAL :: first\r\nREAL :: delx, dely, r, rsmin, rsq, xp, yp\r\nINTEGER :: i, i0, i1, i2, imax, imin, j, j0, j1, j2, jmax, jmin, l, lmin, ln\r\n\r\nxp = px\r\nyp = py\r\n\r\n! TEST FOR INVALID INPUT PARAMETERS.\r\n\r\nIF (nr >= 1 .AND. dx > 0. .AND. dy > 0.) THEN\r\n \r\n! INITIALIZE PARAMETERS --\r\n \r\n! FIRST = TRUE IFF THE FIRST UNMARKED NODE HAS YET TO BE ENCOUNTERED,\r\n! IMIN,IMAX,JMIN,JMAX = CELL INDICES DEFINING THE RANGE OF THE SEARCH,\r\n! DELX,DELY = PX-XMIN AND PY-YMIN,\r\n! I0,J0 = CELL CONTAINING OR CLOSEST TO P,\r\n! I1,I2,J1,J2 = CELL INDICES OF THE LAYER WHOSE INTERSECTION WITH THE RANGE\r\n! DEFINED BY IMIN,..., JMAX IS CURRENTLY BEING SEARCHED.\r\n \r\n first = .true.\r\n imin = 1\r\n imax = nr\r\n jmin = 1\r\n jmax = nr\r\n delx = xp - xmin\r\n dely = yp - ymin\r\n i0 = delx/dx + 1\r\n IF (i0 < 1) i0 = 1\r\n IF (i0 > nr) i0 = nr\r\n j0 = dely/dy + 1\r\n IF (j0 < 1) j0 = 1\r\n IF (j0 > nr) j0 = nr\r\n i1 = i0\r\n i2 = i0\r\n j1 = j0\r\n j2 = j0\r\n \r\n! OUTER LOOP ON LAYERS, INNER LOOP ON LAYER CELLS, EXCLUDING\r\n! THOSE OUTSIDE THE RANGE (IMIN,IMAX) X (JMIN,JMAX).\r\n\r\n 10 i = 0\r\n loop40: DO j = j1, j2\r\n IF (j > jmax) GO TO 50\r\n IF (j >= jmin) THEN\r\n DO i = i1, i2\r\n IF (i > imax) CYCLE loop40\r\n IF (i >= imin) THEN\r\n IF (j == j1 .OR. j == j2 .OR. i == i1 .OR. i == i2) THEN\r\n \r\n! SEARCH CELL (I,J) FOR UNMARKED NODES L.\r\n \r\n l = lcell(i,j)\r\n IF (l /= 0) THEN\r\n \r\n! LOOP ON NODES IN CELL (I,J).\r\n \r\n 20 ln = lnext(l)\r\n IF (ln >= 0) THEN\r\n \r\n! NODE L IS NOT MARKED.\r\n \r\n rsq = (x(l)-xp) ** 2 + (y(l)-yp) ** 2\r\n IF (first) THEN\r\n \r\n! NODE L IS THE FIRST UNMARKED NEIGHBOR OF P ENCOUNTERED.\r\n! INITIALIZE LMIN TO THE CURRENT CANDIDATE FOR NP, AND RSMIN TO THE\r\n! SQUARED DISTANCE FROM P TO LMIN. IMIN, IMAX, JMIN, AND JMAX ARE UPDATED\r\n! TO DEFINE THE SMALLEST RECTANGLE CONTAINING A CIRCLE OF RADIUS R =\r\n! SQRT(RSMIN) CENTERED AT P, AND CONTAINED IN (1,NR) X (1,NR) (EXCEPT\r\n! THAT, IF P IS OUTSIDE THE RECTANGLE DEFINED BY THE NODES, IT IS POSSIBLE\r\n! THAT IMIN > NR, IMAX < 1, JMIN > NR, OR JMAX < 1).\r\n! FIRST IS RESET TO FALSE.\r\n \r\n lmin = l\r\n rsmin = rsq\r\n r = SQRT(rsmin)\r\n imin = (delx-r)/dx + 1\r\n IF (imin < 1) imin = 1\r\n imax = (delx+r)/dx + 1\r\n IF (imax > nr) imax = nr\r\n jmin = (dely-r)/dy + 1\r\n IF (jmin < 1) jmin = 1\r\n jmax = (dely+r)/dy + 1\r\n IF (jmax > nr) jmax = nr\r\n first = .false.\r\n ELSE\r\n \r\n! TEST FOR NODE L CLOSER THAN LMIN TO P.\r\n \r\n IF (rsq < rsmin) THEN\r\n \r\n! UPDATE LMIN AND RSMIN.\r\n \r\n lmin = l\r\n rsmin = rsq\r\n END IF\r\n END IF\r\n END IF\r\n \r\n! TEST FOR TERMINATION OF LOOP ON NODES IN CELL (I,J).\r\n \r\n IF (ABS(ln) /= l) THEN\r\n l = ABS(ln)\r\n GO TO 20\r\n END IF\r\n END IF\r\n END IF\r\n END IF\r\n END DO\r\n END IF\r\n END DO loop40\r\n \r\n! TEST FOR TERMINATION OF LOOP ON CELL LAYERS.\r\n \r\n 50 IF (i1 > imin .OR. i2 < imax .OR. j1 > jmin .OR. j2 < jmax) THEN\r\n i1 = i1 - 1\r\n i2 = i2 + 1\r\n j1 = j1 - 1\r\n j2 = j2 + 1\r\n GO TO 10\r\n END IF\r\n \r\n! UNLESS NO UNMARKED NODES WERE ENCOUNTERED, LMIN IS THE\r\n! CLOSEST UNMARKED NODE TO P.\r\n \r\n IF (.NOT.first) THEN\r\n np = lmin\r\n dsq = rsmin\r\n lnext(lmin) = -lnext(lmin)\r\n RETURN\r\n END IF\r\nEND IF\r\n\r\n! ERROR -- NR, DX, OR DY IS INVALID OR ALL NODES ARE MARKED.\r\n\r\nnp = 0\r\ndsq = 0.\r\n\r\nRETURN\r\nEND SUBROUTINE getnp2\r\n\r\n\r\n\r\nSUBROUTINE givens(a,b,c,s)\r\nREAL, INTENT(IN OUT) :: a, b\r\nREAL, INTENT(OUT) :: c, s\r\n\r\n!***********************************************************\r\n\r\n! ROBERT RENKA\r\n! UNIV. OF NORTH TEXAS\r\n! (817) 565-2767\r\n\r\n! THIS ROUTINE CONSTRUCTS THE GIVENS PLANE ROTATION --\r\n! ( C S)\r\n! G = ( ) WHERE C*C + S*S = 1 -- WHICH ZEROS THE SECOND ENTRY OF THE\r\n! (-S C)\r\n! 2-VECTOR (A B)-TRANSPOSE. A CALL TO GIVENS IS NORMALLY FOLLOWED BY A CALL\r\n! TO ROTATE WHICH APPLIES THE TRANSFORMATION TO A 2 BY N MATRIX.\r\n! THIS ROUTINE WAS TAKEN FROM LINPACK.\r\n\r\n! ON INPUT --\r\n\r\n! A,B = COMPONENTS OF THE 2-VECTOR TO BE ROTATED.\r\n\r\n! ON OUTPUT --\r\n\r\n! A = VALUE OVERWRITTEN BY R = +/-SQRT(A*A + B*B)\r\n\r\n! B = VALUE OVERWRITTEN BY A VALUE Z WHICH ALLOWS C\r\n! AND S TO BE RECOVERED AS FOLLOWS --\r\n! C = SQRT(1-Z*Z), S=Z IF ABS(Z) <= 1.\r\n! C = 1/Z, S = SQRT(1-C*C) IF ABS(Z) > 1.\r\n\r\n! C = +/-(A/R)\r\n\r\n! S = +/-(B/R)\r\n\r\n! MODULES REQUIRED BY GIVENS -- NONE\r\n\r\n! INTRINSIC FUNCTIONS CALLED BY GIVENS - ABS, SQRT\r\n\r\n!***********************************************************\r\n\r\nREAL :: aa, bb, r, u, v\r\n\r\n! LOCAL PARAMETERS --\r\n\r\n! AA,BB = LOCAL COPIES OF A AND B\r\n! R = C*A + S*B = +/-SQRT(A*A+B*B)\r\n! U,V = VARIABLES USED TO SCALE A AND B FOR COMPUTING R\r\n\r\naa = a\r\nbb = b\r\nIF (ABS(aa) > ABS(bb)) THEN\r\n \r\n! ABS(A) > ABS(B)\r\n \r\n u = aa + aa\r\n v = bb / u\r\n r = SQRT(.25+v*v) * u\r\n c = aa / r\r\n s = v * (c+c)\r\n \r\n! NOTE THAT R HAS THE SIGN OF A, C > 0, AND S HAS SIGN(A)*SIGN(B).\r\n \r\n b = s\r\n a = r\r\n RETURN\r\nEND IF\r\n\r\n! ABS(A) <= ABS(B)\r\n\r\nIF (bb /= 0.) THEN\r\n u = bb + bb\r\n v = aa / u\r\n \r\n! STORE R IN A.\r\n \r\n a = SQRT(.25+v*v) * u\r\n s = bb / a\r\n c = v * (s+s)\r\n \r\n! NOTE THAT R HAS THE SIGN OF B, S > 0, AND C HAS SIGN(A)*SIGN(B).\r\n \r\n b = 1.\r\n IF (c /= 0.) b = 1. / c\r\n RETURN\r\nEND IF\r\n\r\n! A = B = 0.\r\n\r\nc = 1.\r\ns = 0.\r\n\r\nRETURN\r\nEND SUBROUTINE givens\r\n\r\n\r\n\r\nSUBROUTINE rotate(n,c,s,x,y)\r\nINTEGER, INTENT(IN) :: n\r\nREAL, INTENT(IN) :: c, s\r\nREAL, INTENT(IN OUT) :: x(:), y(:)\r\n\r\n!***********************************************************\r\n\r\n! ROBERT RENKA\r\n! UNIV. OF NORTH TEXAS\r\n! (817) 565-2767\r\n\r\n! ( C S)\r\n! THIS ROUTINE APPLIES THE GIVENS ROTATION ( ) TO THE\r\n! (-S C)\r\n! (X(1) ... X(N))\r\n! 2 BY N MATRIX ( ).\r\n! (Y(1) ... Y(N))\r\n\r\n! ON INPUT --\r\n\r\n! N = NUMBER OF COLUMNS TO BE ROTATED.\r\n\r\n! C,S = ELEMENTS OF THE GIVENS ROTATION. THESE MAY BE DETERMINED\r\n! BY SUBROUTINE GIVENS.\r\n\r\n! X,Y = ARRAYS OF LENGTH >= N CONTAINING THE VECTORS TO BE ROTATED.\r\n\r\n! PARAMETERS N, C, AND S ARE NOT ALTERED BY THIS ROUTINE.\r\n\r\n! ON OUTPUT --\r\n\r\n! X,Y = ROTATED VECTORS.\r\n\r\n! MODULES REQUIRED BY ROTATE -- NONE\r\n\r\n!***********************************************************\r\n\r\nINTEGER :: i\r\nREAL :: xi, yi\r\n\r\n! LOCAL PARAMETERS --\r\n\r\n! I = DO-LOOP INDEX\r\n! XI,YI = X(I), Y(I)\r\n\r\nIF (n <= 0 .OR. (c == 1. .AND. s == 0.)) RETURN\r\nDO i = 1, n\r\n xi = x(i)\r\n yi = y(i)\r\n x(i) = c * xi + s * yi\r\n y(i) = -s * xi + c * yi\r\nEND DO\r\n\r\nRETURN\r\nEND SUBROUTINE rotate\r\n\r\n\r\n\r\nSUBROUTINE setup2(xk,yk,fk,xi,yi,fi,s1,s2,r,row)\r\nREAL, INTENT(IN) :: xk, yk, fk, xi, yi, fi, s1, s2, r\r\nREAL, INTENT(OUT) :: row(6)\r\n\r\n!***********************************************************\r\n\r\n! ROBERT RENKA\r\n! UNIV. OF NORTH TEXAS\r\n! (817) 565-2767\r\n\r\n! THIS ROUTINE SETS UP THE I-TH ROW OF AN AUGMENTED REGRESSION MATRIX FOR A\r\n! WEIGHTED LEAST-SQUARES FIT OF A QUADRATIC FUNCTION Q(X,Y) TO A SET OF DATA\r\n! VALUES F, WHERE Q(XK,YK) = FK. THE FIRST 3 COLUMNS (QUADRATIC TERMS) ARE\r\n! SCALED BY 1/S2 AND THE FOURTH AND FIFTH COLUMNS (LINEAR TERMS) ARE SCALED\r\n! BY 1/S1. THE WEIGHT IS (R-D)/(R*D) IF R > D AND 0 IF R <= D, WHERE D\r\n! IS THE DISTANCE BETWEEN NODES I AND K.\r\n\r\n! ON INPUT --\r\n\r\n! XK,YK,FK = COORDINATES AND DATA VALUE AT NODE K -- INTERPOLATED BY Q.\r\n\r\n! XI,YI,FI = COORDINATES AND DATA VALUE AT NODE I.\r\n\r\n! S1,S2 = RECIPROCALS OF THE SCALE FACTORS.\r\n\r\n! R = RADIUS OF INFLUENCE ABOUT NODE K DEFINING THE WEIGHT.\r\n\r\n! ROW = ARRAY OF LENGTH 6.\r\n\r\n! INPUT PARAMETERS ARE NOT ALTERED BY THIS ROUTINE.\r\n\r\n! ON OUTPUT --\r\n\r\n! ROW = VECTOR CONTAINING A ROW OF THE AUGMENTED REGRESSION MATRIX.\r\n\r\n! MODULES REQUIRED BY SETUP2 -- NONE\r\n\r\n! INTRINSIC FUNCTION CALLED BY SETUP2 -- SQRT\r\n\r\n!***********************************************************\r\n\r\nREAL :: d, dx, dy, dxsq, dysq, w, w1, w2\r\n\r\n! LOCAL PARAMETERS -\r\n\r\n! I = DO-LOOP INDEX\r\n! DX = XI - XK\r\n! DY = YI - YK\r\n! DXSQ = DX*DX\r\n! DYSQ = DY*DY\r\n! D = DISTANCE BETWEEN NODES K AND I\r\n! W = WEIGHT ASSOCIATED WITH THE ROW\r\n! W1 = W/S1\r\n! W2 = W/S2\r\n\r\ndx = xi - xk\r\ndy = yi - yk\r\ndxsq = dx * dx\r\ndysq = dy * dy\r\nd = SQRT(dxsq+dysq)\r\nIF (d > 0. .AND. d < r) THEN\r\n w = (r-d) / r / d\r\n w1 = w / s1\r\n w2 = w / s2\r\n row(1) = dxsq * w2\r\n row(2) = dx * dy * w2\r\n row(3) = dysq * w2\r\n row(4) = dx * w1\r\n row(5) = dy * w1\r\n row(6) = (fi-fk) * w\r\n RETURN\r\nEND IF\r\n\r\n! NODES K AND I COINCIDE OR NODE I IS OUTSIDE OF THE RADIUS OF INFLUENCE.\r\n! SET ROW TO THE ZERO VECTOR.\r\n\r\nrow(1:6) = 0.\r\n\r\nRETURN\r\nEND SUBROUTINE setup2\r\n\r\n\r\n\r\nSUBROUTINE store2(n,x,y,nr,lcell,lnext,xmin,ymin,dx,dy,ier)\r\nINTEGER, INTENT(IN) :: n, nr\r\nINTEGER, INTENT(IN OUT) :: lcell(:,:), lnext(:)\r\nREAL, INTENT(IN) :: x(:), y(:)\r\nREAL, INTENT(OUT) :: xmin, ymin, dx, dy\r\nINTEGER, INTENT(OUT) :: ier\r\n\r\n!***********************************************************\r\n\r\n! ROBERT RENKA\r\n! UNIV. OF NORTH TEXAS\r\n! (817) 565-2767\r\n\r\n! GIVEN A SET OF N ARBITRARILY DISTRIBUTED NODES IN THE PLANE, THIS\r\n! SUBROUTINE CREATES A DATA STRUCTURE FOR A CELL-BASED METHOD OF SOLVING\r\n! CLOSEST-POINT PROBLEMS. THE SMALLEST RECTANGLE CONTAINING THE NODES IS\r\n! PARTITIONED INTO AN NR BY NR UNIFORM GRID OF CELLS, AND NODES ARE\r\n! ASSOCIATED WITH CELLS. IN PARTICULAR, THE DATA STRUCTURE STORES THE\r\n! INDICES OF THE NODES CONTAINED IN EACH CELL.\r\n! FOR A UNIFORM RANDOM DISTRIBUTION OF NODES, THE NEAREST NODE TO AN\r\n! ARBITRARY POINT CAN BE DETERMINED IN CONSTANT EXPECTED TIME.\r\n\r\n! ON INPUT --\r\n\r\n! N = NUMBER OF NODES. N >= 2.\r\n\r\n! X,Y = ARRAYS OF LENGTH N CONTAINING THE CARTESIAN\r\n! COORDINATES OF THE NODES.\r\n\r\n! NR = NUMBER OF ROWS AND COLUMNS IN THE GRID. THE CELL DENSITY\r\n! (AVERAGE NUMBER OF NODES PER CELL) IS D = N/(NR**2).\r\n! A RECOMMENDED VALUE, BASED ON EMPIRICAL EVIDENCE,\r\n! IS D = 3 -- NR = SQRT(N/3). NR >= 1.\r\n\r\n! THE ABOVE PARAMETERS ARE NOT ALTERED BY THIS ROUTINE.\r\n\r\n! LCELL = ARRAY OF LENGTH >= NR**2.\r\n\r\n! LNEXT = ARRAY OF LENGTH >= N.\r\n\r\n! ON OUTPUT --\r\n\r\n! LCELL = NR BY NR CELL ARRAY SUCH THAT LCELL(I,J) CONTAINS THE INDEX\r\n! (FOR X AND Y) OF THE FIRST NODE (NODE WITH SMALLEST INDEX) IN\r\n! CELL (I,J), OR LCELL(I,J) = 0 IF NO NODES ARE CONTAINED IN\r\n! THE CELL. THE UPPER RIGHT CORNER OF CELL (I,J) HAS\r\n! COORDINATES (XMIN+I*DX,YMIN+J*DY).\r\n! LCELL IS NOT DEFINED IF IER .NE. 0.\r\n\r\n! LNEXT = ARRAY OF NEXT-NODE INDICES SUCH THAT LNEXT(K) CONTAINS THE\r\n! INDEX OF THE NEXT NODE IN THE CELL WHICH CONTAINS NODE K, OR\r\n! LNEXT(K) = K IF K IS THE LAST NODE IN THE CELL FOR\r\n! K = 1,...,N. (THE NODES CONTAINED IN A CELL ARE ORDERED BY\r\n! THEIR INDICES.)\r\n! IF, FOR EXAMPLE, CELL (I,J) CONTAINS NODES 2, 3, AND 5 (AND\r\n! NO OTHERS), THEN LCELL(I,J) = 2, LNEXT(2) = 3, LNEXT(3) = 5,\r\n! AND LNEXT(5) = 5. LNEXT IS NOT DEFINED IF IER .NE. 0.\r\n\r\n! XMIN,YMIN = CARTESIAN COORDINATES OF THE LOWER LEFT CORNER OF THE\r\n! RECTANGLE DEFINED BY THE NODES (SMALLEST NODAL\r\n! COORDINATES) UNLESS IER = 1. THE UPPER RIGHT CORNER IS\r\n! (XMAX,YMAX) FOR XMAX = XMIN + NR*DX AND\r\n! YMAX = YMIN + NR*DY.\r\n\r\n! DX,DY = DIMENSIONS OF THE CELLS UNLESS IER = 1. DX = (XMAX-XMIN)/NR\r\n! AND DY = (YMAX-YMIN)/NR WHERE XMIN, XMAX, YMIN, AND YMAX ARE\r\n! THE EXTREMA OF X AND Y.\r\n\r\n! IER = ERROR INDICATOR --\r\n! IER = 0 IF NO ERRORS WERE ENCOUNTERED.\r\n! IER = 1 IF N < 2 OR NR < 1.\r\n! IER = 2 IF DX = 0 OR DY = 0.\r\n\r\n! MODULES REQUIRED BY STORE2 -- NONE\r\n\r\n! INTRINSIC FUNCTIONS CALLED BY STORE2 -- FLOAT, IFIX\r\n\r\n!***********************************************************\r\n\r\n! Local variables\r\nINTEGER :: i, j, k, kb, l, nn, nnr, np1\r\nREAL :: delx, dely, xmn, xmx, ymn, ymx\r\n\r\nnn = n\r\nnnr = nr\r\nIF (nn >= 2 .AND. nnr >= 1) THEN\r\n \r\n! COMPUTE THE DIMENSIONS OF THE RECTANGLE CONTAINING THE NODES.\r\n \r\n xmn = x(1)\r\n xmx = xmn\r\n ymn = y(1)\r\n ymx = ymn\r\n DO k = 2, nn\r\n IF (x(k) < xmn) xmn = x(k)\r\n IF (x(k) > xmx) xmx = x(k)\r\n IF (y(k) < ymn) ymn = y(k)\r\n IF (y(k) > ymx) ymx = y(k)\r\n END DO\r\n xmin = xmn\r\n ymin = ymn\r\n \r\n! COMPUTE CELL DIMENSIONS AND TEST FOR ZERO AREA.\r\n \r\n delx = (xmx-xmn) / REAL(nnr)\r\n dely = (ymx-ymn) / REAL(nnr)\r\n dx = delx\r\n dy = dely\r\n IF (delx == 0. .OR. dely == 0.) GO TO 50\r\n \r\n! INITIALIZE LCELL.\r\n \r\n DO j = 1, nnr\r\n DO i = 1, nnr\r\n lcell(i,j) = 0\r\n END DO\r\n END DO\r\n \r\n! LOOP ON NODES, STORING INDICES IN LCELL AND LNEXT.\r\n \r\n np1 = nn + 1\r\n DO k = 1, nn\r\n kb = np1 - k\r\n i = (x(kb)-xmn)/delx + 1\r\n IF (i > nnr) i = nnr\r\n j = (y(kb)-ymn)/dely + 1\r\n IF (j > nnr) j = nnr\r\n l = lcell(i,j)\r\n lnext(kb) = l\r\n IF (l == 0) lnext(kb) = kb\r\n lcell(i,j) = kb\r\n END DO\r\n \r\n! NO ERRORS ENCOUNTERED\r\n \r\n ier = 0\r\n RETURN\r\nEND IF\r\n\r\n! INVALID INPUT PARAMETER\r\n\r\nier = 1\r\nRETURN\r\n\r\n! DX = 0 OR DY = 0\r\n\r\n50 ier = 2\r\nRETURN\r\nEND SUBROUTINE store2\r\n\r\nEND MODULE qshep2d\r\n\r\n\r\n\r\nPROGRAM qs2test\r\n! QS2TEST\r\n\r\n! THIS PROGRAM TESTS THE SCATTERED DATA INTERPOLATION PACKAGE QSHEP2D\r\n! BY PRINTING THE MAXIMUM ERRORS ASSOCIATED WITH INTERPOLATED VALUES AND\r\n! GRADIENTS ON A 10 BY 10 UNIFORM GRID IN THE UNIT SQUARE. THE DATA SET\r\n! CONSISTS OF 36 NODES WITH DATA VALUES TAKEN FROM A QUADRATIC FUNCTION FOR\r\n! WHICH THE METHOD IS EXACT. THE RATIO OF MAXIMUM INTERPOLATION ERROR\r\n! RELATIVE TO THE MACHINE PRECISION IS ALSO PRINTED. THIS SHOULD BE O(1).\r\n! THE INTERPOLATED VALUES FROM QS2VAL AND QS2GRD ARE COMPARED FOR AGREEMENT.\r\n\r\nUSE qshep2d\r\nIMPLICIT NONE\r\nINTEGER :: i, ier, j, k, lcell(3,3), lnext(36)\r\nREAL :: a(5,36), dx, dy, eps, eq, eqx, eqy, f(36), p(10), px, py, q, q1, &\r\n qx, qy, rmax, rq, rsq(36), x(36), xmin, y(36), yk, ymin\r\n\r\n! QSHEP2 PARAMETERS AND LOGICAL UNIT FOR OUTPUT\r\n\r\nINTEGER, PARAMETER :: lout = 6, n = 36, nq = 13, nr = 3, nw = 19\r\n\r\n! GENERATE A 6 BY 6 GRID OF NODES IN THE UNIT SQUARE WITH THE NATURAL ORDERING.\r\n\r\nk = 0\r\nDO j = 1, 6\r\n yk = (6-j) / 5.\r\n DO i = 1, 6\r\n k = k + 1\r\n x(k) = (i-1) / 5.\r\n y(k) = yk\r\n END DO\r\nEND DO\r\n\r\n! COMPUTE THE DATA VALUES.\r\n\r\nDO k = 1, n\r\n f(k) = fq(x(k),y(k))\r\nEND DO\r\n\r\n! COMPUTE PARAMETERS DEFINING THE INTERPOLANT Q.\r\n\r\nCALL qshep2(n,x,y,f,nq,nw,nr,lcell,lnext,xmin,ymin,dx,dy,rmax,rsq,a,ier)\r\nIF (ier == 0) THEN\r\n\r\n! GENERATE A 10 BY 10 UNIFORM GRID OF INTERPOLATION POINTS (P(I),P(J)) IN THE\r\n! UNIT SQUARE. THE FOUR CORNERS COINCIDE WITH NODES.\r\n\r\n DO i = 1, 10\r\n p(i) = (i-1) / 9.\r\n END DO\r\n\r\n! COMPUTE THE MACHINE PRECISION EPS.\r\n\r\n eps = EPSILON(1.0)\r\n\r\n! COMPUTE INTERPOLATION ERRORS AND TEST FOR AGREEMENT IN THE\r\n! Q VALUES RETURNED BY QS2VAL AND QS2GRD.\r\n\r\n EQ = 0.\r\n eqx = 0.\r\n eqy = 0.\r\n DO j = 1, 10\r\n py = p(j)\r\n DO i = 1, 10\r\n px = p(i)\r\n q1 = qs2val(px,py,n,x,y,f,nr,lcell,lnext,xmin,ymin,dx,dy,rmax,rsq,a)\r\n CALL qs2grd(px,py,n,x,y,f,nr,lcell,lnext,xmin,ymin,dx,dy, &\r\n rmax,rsq,a,q,qx,qy,ier)\r\n IF (ier /= 0) GO TO 80\r\n IF (ABS(q1-q) > 3.*ABS(q)*eps) GO TO 90\r\n EQ = MAX(EQ,ABS(fq(px,py)-q))\r\n eqx = MAX(eqx,ABS(fx(px,py)-qx))\r\n eqy = MAX(eqy,ABS(fy(px,py)-qy))\r\n END DO\r\n END DO\r\n\r\n! PRINT ERRORS AND THE RATIO EQ/EPS.\r\n\r\n rq = EQ / eps\r\n WRITE (lout,5000)\r\n WRITE (lout,5100) EQ, rq\r\n WRITE (lout,5200) eqx\r\n WRITE (lout,5300) eqy\r\n STOP\r\nEND IF\r\n\r\n! ERROR IN QSHEP2\r\n\r\nWRITE (lout,5400) ier\r\nSTOP\r\n\r\n! ERROR IN QS2GRD\r\n\r\n80 WRITE (lout,5500) ier\r\nSTOP\r\n\r\n! VALUES RETURNED BY QS2VAL AND QS2GRD DIFFER BY A RELATIVE\r\n! AMOUNT GREATER THAN 3*EPS.\r\n\r\n90 WRITE (lout,5600) q1, q\r\nSTOP\r\n\r\n5000 FORMAT(//' ','MAXIMUM ABSOLUTE ERRORS IN THE INTERPOLANT Q AND PARTIAL'/ &\r\n ' DERIVATIVES QX AND QY RELATIVE TO MACHINE PRECISION EPS'// &\r\n t12, 'FUNCTION MAX ERROR MAX ERROR/EPS'/)\r\n5100 FORMAT (t15, 'Q ', e9.3, ' ', f4.2)\r\n5200 FORMAT (t15, 'QX ', e9.3)\r\n5300 FORMAT (t15, 'QY ', e9.3)\r\n5400 FORMAT (///' *** ERROR IN QSHEP2 -- IER =', i2, ' ***')\r\n5500 FORMAT (///' *** ERROR IN QS2GRD -- IER =', i2, ' ***')\r\n5600 FORMAT (///' *** ERROR -- INTERPOLATED VALUES ', &\r\n 'Q1 (QS2VAL) AND Q2 (QS2GRD) DIFFER --'// &\r\n t7, 'Q1 = ', e21.14, ' Q2 = ', e21.14)\r\n\r\nCONTAINS\r\n\r\n! QUADRATIC TEST FUNCTION AND PARTIAL DERIVATIVES\r\n\r\n! fq(xx,yy) = ((xx + 2.*yy)/3.) ** 2\r\n! fx(xx,yy) = 2. * (xx + 2.*yy) / 9.\r\n! fy(xx,yy) = 4. * (xx + 2.*yy) / 9.\r\n\r\n\r\nFUNCTION fq(xx, yy) RESULT(fn_val)\r\nREAL, INTENT(IN) :: xx, yy\r\nREAL :: fn_val\r\n\r\nfn_val = ((xx + 2.*yy)/3.) ** 2\r\nRETURN\r\nEND FUNCTION fq\r\n\r\n\r\n\r\nFUNCTION fx(xx, yy) RESULT(fn_val)\r\nREAL, INTENT(IN) :: xx, yy\r\nREAL :: fn_val\r\n\r\nfn_val = 2. * (xx + 2.*yy) / 9.\r\nRETURN\r\nEND FUNCTION fx\r\n\r\n\r\n\r\nFUNCTION fy(xx, yy) RESULT(fn_val)\r\nREAL, INTENT(IN) :: xx, yy\r\nREAL :: fn_val\r\n\r\nfn_val = 4. * (xx + 2.*yy) / 9.\r\nRETURN\r\nEND FUNCTION fy\r\n\r\nEND PROGRAM qs2test\r\n", "meta": {"hexsha": "1f40cdeb32bc1e9b617f38ebc57106800079ad79", "size": 46537, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/toms660.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/toms660.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/toms660.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": 30.0626614987, "max_line_length": 80, "alphanum_fraction": 0.511743344, "num_tokens": 15415, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693702514737, "lm_q2_score": 0.7154240018510026, "lm_q1q2_score": 0.6794162613006308}} {"text": " SUBROUTINE kendl2(tab,i,j,ip,jp,tau,z,prob)\r\n INTEGER i,ip,j,jp\r\n REAL prob,tau,z,tab(ip,jp)\r\nCU USES erfcc\r\n INTEGER k,ki,kj,l,li,lj,m1,m2,mm,nn\r\n REAL en1,en2,pairs,points,s,var,erfcc\r\n en1=0.\r\n en2=0.\r\n s=0.\r\n nn=i*j\r\n points=tab(i,j)\r\n do 12 k=0,nn-2\r\n ki=k/j\r\n kj=k-j*ki\r\n points=points+tab(ki+1,kj+1)\r\n do 11 l=k+1,nn-1\r\n li=l/j\r\n lj=l-j*li\r\n m1=li-ki\r\n m2=lj-kj\r\n mm=m1*m2\r\n pairs=tab(ki+1,kj+1)*tab(li+1,lj+1)\r\n if(mm.ne.0)then\r\n en1=en1+pairs\r\n en2=en2+pairs\r\n if(mm.gt.0)then\r\n s=s+pairs\r\n else\r\n s=s-pairs\r\n endif\r\n else\r\n if(m1.ne.0)en1=en1+pairs\r\n if(m2.ne.0)en2=en2+pairs\r\n endif\r\n11 continue\r\n12 continue\r\n tau=s/sqrt(en1*en2)\r\n var=(4.*points+10.)/(9.*points*(points-1.))\r\n z=tau/sqrt(var)\r\n prob=erfcc(abs(z)/1.4142136)\r\n return\r\n END\r\n", "meta": {"hexsha": "3cf1fa1add0488d5b71b3189df38f007c03f3cd3", "size": 1062, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/kendl2.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/kendl2.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/kendl2.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.6976744186, "max_line_length": 50, "alphanum_fraction": 0.4425612053, "num_tokens": 377, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107878954105, "lm_q2_score": 0.724870282120402, "lm_q1q2_score": 0.6793562482280304}} {"text": "C$Procedure DRDPGR ( Derivative of rectangular w.r.t. planetographic )\n \n SUBROUTINE DRDPGR ( BODY, LON, LAT, ALT, RE, F, JACOBI )\n \nC$ Abstract\nC\nC This routine computes the Jacobian matrix of the transformation\nC from planetographic to rectangular coordinates.\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 COORDINATES\nC DERIVATIVES\nC MATRIX\nC\nC$ Declarations\n \n IMPLICIT NONE\n\n INCLUDE 'zzctr.inc'\n\n CHARACTER*(*) BODY\n DOUBLE PRECISION LON\n DOUBLE PRECISION LAT\n DOUBLE PRECISION ALT\n DOUBLE PRECISION RE\n DOUBLE PRECISION F\n DOUBLE PRECISION JACOBI ( 3, 3 )\n \nC$ Brief_I/O\nC\nC Variable I/O Description\nC -------- --- --------------------------------------------------\nC BODY I Name of body with which coordinates are associated.\nC LON I Planetographic longitude of a point (radians).\nC LAT I Planetographic latitude of a point (radians).\nC ALT I Altitude of a point above reference spheroid.\nC RE I Equatorial radius of the reference spheroid.\nC F I Flattening coefficient.\nC JACOBI O Matrix of partial derivatives.\nC\nC$ Detailed_Input\nC\nC BODY Name of the body with which the planetographic\nC coordinate system is associated.\nC\nC BODY is used by this routine to look up from the\nC kernel pool the prime meridian rate coefficient giving\nC the body's spin sense. See the Files and Particulars\nC header sections below for details.\nC\nC LON Planetographic longitude of the input point. This is\nC the angle between the prime meridian and the meridian\nC containing the input point. For bodies having\nC prograde (aka direct) rotation, the direction of\nC increasing longitude is positive west: from the +X\nC axis of the rectangular coordinate system toward the\nC -Y axis. For bodies having retrograde rotation, the\nC direction of increasing longitude is positive east:\nC from the +X axis toward the +Y axis.\nC\nC The earth, moon, and sun are exceptions:\nC planetographic longitude is measured positive east for\nC these bodies.\nC\nC The default interpretation of longitude by this\nC and the other planetographic coordinate conversion\nC routines can be overridden; see the discussion in\nC Particulars below for details.\nC\nC Longitude is measured in radians. On input, the range\nC of longitude is unrestricted.\nC\nC LAT Planetographic latitude of the input point. For a\nC point P on the reference spheroid, this is the angle\nC between the XY plane and the outward normal vector at\nC P. For a point P not on the reference spheroid, the\nC planetographic latitude is that of the closest point\nC to P on the spheroid.\nC\nC Latitude is measured in radians. On input, the\nC range of latitude is unrestricted. \nC\nC ALT Altitude of point above the reference spheroid.\nC Units of ALT must match those of RE.\nC\nC RE Equatorial radius of a reference spheroid. This\nC spheroid is a volume of revolution: its horizontal\nC cross sections are circular. The shape of the\nC spheroid is defined by an equatorial radius RE and\nC a polar radius RP. Units of RE must match those of \nC ALT.\nC\nC F Flattening coefficient = \nC\nC (RE-RP) / RE\nC\nC where RP is the polar radius of the spheroid, and the\nC units of RP match those of RE.\nC\nC$ Detailed_Output\nC\nC JACOBI is the matrix of partial derivatives of the conversion\nC from planetographic to rectangular coordinates. It\nC has the form\nC\nC .- -.\nC | DX/DLON DX/DLAT DX/DALT |\nC | DY/DLON DY/DLAT DY/DALT |\nC | DZ/DLON DZ/DLAT DZ/DALT |\nC `- -'\nC\nC evaluated at the input values of LON, LAT and ALT.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC 1) If the body name BODY cannot be mapped to a NAIF ID code,\nC and if BODY is not a string representation of an integer,\nC the error SPICE(IDCODENOTFOUND) will be signaled.\nC \nC 2) If the kernel variable \nC\nC BODY_PGR_POSITIVE_LON\nC\nC is present in the kernel pool but has a value other\nC than one of\nC\nC 'EAST'\nC 'WEST'\nC\nC the error SPICE(INVALIDOPTION) will be signaled. Case\nC and blanks are ignored when these values are interpreted.\nC\nC 3) If polynomial coefficients for the prime meridian of BODY\nC are not available in the kernel pool, and if the kernel\nC variable BODY_PGR_POSITIVE_LON is not present in\nC the kernel pool, the error SPICE(MISSINGDATA) will be signaled.\nC \nC 4) If the equatorial radius is non-positive, the error\nC SPICE(VALUEOUTOFRANGE) is signaled.\nC\nC 5) If the flattening coefficient is greater than or equal to one,\nC the error SPICE(VALUEOUTOFRANGE) is signaled.\nC\nC$ Files\nC\nC This routine expects a kernel variable giving BODY's prime\nC meridian angle as a function of time to be available in the\nC kernel pool. Normally this item is provided by loading a PCK\nC file. The required kernel variable is named \nC\nC BODY_PM \nC\nC where represents a string containing the NAIF integer \nC ID code for BODY. For example, if BODY is 'JUPITER', then \nC the name of the kernel variable containing the prime meridian \nC angle coefficients is \nC\nC BODY599_PM\nC\nC See the PCK Required Reading for details concerning the prime\nC meridian kernel variable.\nC\nC The optional kernel variable \nC \nC BODY_PGR_POSITIVE_LON\nC\nC also is normally defined via loading a text kernel. When this\nC variable is present in the kernel pool, the prime meridian\nC coefficients for BODY are not required by this routine. See the\nC Particulars section below for details.\nC\nC$ Particulars\nC\nC It is often convenient to describe the motion of an object in the\nC planetographic coordinate system. However, when performing\nC vector computations it's hard to beat rectangular coordinates.\nC\nC To transform states given with respect to planetographic\nC coordinates to states with respect to rectangular coordinates,\nC one makes use of the Jacobian of the transformation between the\nC two systems.\nC\nC Given a state in planetographic coordinates\nC\nC ( lon, lat, alt, dlon, dlat, dalt )\nC\nC the velocity in rectangular coordinates is given by the matrix\nC equation:\nC\nC t | t\nC (dx, dy, dz) = JACOBI| * (dlon, dlat, dalt)\nC |(lon,lat,alt)\nC\nC\nC This routine computes the matrix \nC\nC |\nC JACOBI|\nC |(lon,lat,alt)\nC\nC\nC In the planetographic coordinate system, longitude is defined\nC using the spin sense of the body. Longitude is positive to the\nC west if the spin is prograde and positive to the east if the spin\nC is retrograde. The spin sense is given by the sign of the first\nC degree term of the time-dependent polynomial for the body's prime\nC meridian Euler angle \"W\": the spin is retrograde if this term is\nC negative and prograde otherwise. For the sun, planets, most\nC natural satellites, and selected asteroids, the polynomial\nC expression for W may be found in a SPICE PCK kernel.\nC\nC The earth, moon, and sun are exceptions: planetographic longitude\nC is measured positive east for these bodies.\nC\nC If you wish to override the default sense of positive longitude\nC for a particular body, you can do so by defining the kernel\nC variable\nC\nC BODY_PGR_POSITIVE_LON\nC\nC where represents the NAIF ID code of the body. This\nC variable may be assigned either of the values\nC\nC 'WEST'\nC 'EAST'\nC\nC For example, you can have this routine treat the longitude\nC of the earth as increasing to the west using the kernel\nC variable assignment\nC\nC BODY399_PGR_POSITIVE_LON = 'WEST'\nC \nC Normally such assignments are made by placing them in a text\nC kernel and loading that kernel via FURNSH.\nC\nC The definition of this kernel variable controls the behavior of\nC the SPICELIB planetographic routines\nC\nC PGRREC\nC RECPGR\nC DPGRDR\nC DRDPGR\nC\nC It does not affect the other SPICELIB coordinate conversion\nC routines.\nC\nC$ Examples\nC\nC Numerical results shown for this example may differ between\nC platforms as the results depend on the SPICE kernels used as\nC input and the machine specific arithmetic implementation.\nC\nC\nC Find the planetographic state of the earth as seen from\nC Mars in the J2000 reference frame at January 1, 2005 TDB.\nC Map this state back to rectangular coordinates as a check.\nC\nC\nC PROGRAM EX1\nC IMPLICIT NONE\nC C\nC C SPICELIB functions\nC C\nC DOUBLE PRECISION RPD\nC C\nC C Local variables\nC C\nC DOUBLE PRECISION ALT\nC DOUBLE PRECISION DRECTN ( 3 )\nC DOUBLE PRECISION ET\nC DOUBLE PRECISION F\nC DOUBLE PRECISION JACOBI ( 3, 3 )\nC DOUBLE PRECISION LAT\nC DOUBLE PRECISION LON\nC DOUBLE PRECISION LT\nC DOUBLE PRECISION PGRVEL ( 3 )\nC DOUBLE PRECISION RADII ( 3 )\nC DOUBLE PRECISION RE\nC DOUBLE PRECISION RECTAN ( 3 )\nC DOUBLE PRECISION RP\nC DOUBLE PRECISION STATE ( 6 )\nC\nC INTEGER N\nC C\nC C Load a PCK file containing a triaxial\nC C ellipsoidal shape model and orientation\nC C data for Mars.\nC C\nC CALL FURNSH ( 'pck00008.tpc' )\nC\nC C\nC C Load an SPK file giving ephemerides of earth and Mars.\nC C\nC CALL FURNSH ( 'de405.bsp' )\nC\nC C\nC C Load a leapseconds kernel to support time conversion.\nC C\nC CALL FURNSH ( 'naif0007.tls' )\nC\nC C\nC C Look up the radii for Mars. Although we\nC C omit it here, we could first call BADKPV\nC C to make sure the variable BODY499_RADII\nC C has three elements and numeric data type.\nC C If the variable is not present in the kernel\nC C pool, BODVRD will signal an error.\nC C\nC CALL BODVRD ( 'MARS', 'RADII', 3, N, RADII )\nC\nC C\nC C Compute flattening coefficient.\nC C\nC RE = RADII(1)\nC RP = RADII(3)\nC F = ( RE - RP ) / RE\nC\nC C\nC C Look up the geometric state of earth as seen from Mars at\nC C January 1, 2005 TDB, relative to the J2000 reference\nC C frame.\nC C\nC CALL STR2ET ( 'January 1, 2005 TDB', ET )\nC\nC CALL SPKEZR ( 'Earth', ET, 'J2000', 'LT+S',\nC . 'Mars', STATE, LT )\nC\nC C\nC C Convert position to planetographic coordinates.\nC C\nC CALL RECPGR ( 'MARS', STATE, RE, F, LON, LAT, ALT )\nC\nC C\nC C Convert velocity to planetographic coordinates.\nC C\nC\nC CALL DPGRDR ( 'MARS', STATE(1), STATE(2), STATE(3),\nC . RE, F, JACOBI )\nC\nC CALL MXV ( JACOBI, STATE(4), PGRVEL )\nC\nC C\nC C As a check, convert the planetographic state back to\nC C rectangular coordinates.\nC C\nC CALL PGRREC ( 'MARS', LON, LAT, ALT, RE, F, RECTAN )\nC\nC CALL DRDPGR ( 'MARS', LON, LAT, ALT, RE, F, JACOBI )\nC\nC CALL MXV ( JACOBI, PGRVEL, DRECTN )\nC\nC\nC WRITE(*,*) ' '\nC WRITE(*,*) 'Rectangular coordinates:'\nC WRITE(*,*) ' '\nC WRITE(*,*) ' X (km) = ', STATE(1)\nC WRITE(*,*) ' Y (km) = ', STATE(2)\nC WRITE(*,*) ' Z (km) = ', STATE(3)\nC WRITE(*,*) ' '\nC WRITE(*,*) 'Rectangular velocity:'\nC WRITE(*,*) ' '\nC WRITE(*,*) ' dX/dt (km/s) = ', STATE(4)\nC WRITE(*,*) ' dY/dt (km/s) = ', STATE(5)\nC WRITE(*,*) ' dZ/dt (km/s) = ', STATE(6)\nC WRITE(*,*) ' '\nC WRITE(*,*) 'Ellipsoid shape parameters: '\nC WRITE(*,*) ' '\nC WRITE(*,*) ' Equatorial radius (km) = ', RE\nC WRITE(*,*) ' Polar radius (km) = ', RP\nC WRITE(*,*) ' Flattening coefficient = ', F\nC WRITE(*,*) ' '\nC WRITE(*,*) 'Planetographic coordinates:'\nC WRITE(*,*) ' '\nC WRITE(*,*) ' Longitude (deg) = ', LON / RPD()\nC WRITE(*,*) ' Latitude (deg) = ', LAT / RPD()\nC WRITE(*,*) ' Altitude (km) = ', ALT\nC WRITE(*,*) ' '\nC WRITE(*,*) 'Planetographic velocity:'\nC WRITE(*,*) ' '\nC WRITE(*,*) ' d Longitude/dt (deg/s) = ', PGRVEL(1)/RPD()\nC WRITE(*,*) ' d Latitude/dt (deg/s) = ', PGRVEL(2)/RPD()\nC WRITE(*,*) ' d Altitude/dt (km/s) = ', PGRVEL(3)\nC WRITE(*,*) ' '\nC WRITE(*,*) 'Rectangular coordinates from inverse ' //\nC . 'mapping:'\nC WRITE(*,*) ' '\nC WRITE(*,*) ' X (km) = ', RECTAN(1)\nC WRITE(*,*) ' Y (km) = ', RECTAN(2)\nC WRITE(*,*) ' Z (km) = ', RECTAN(3)\nC WRITE(*,*) ' '\nC WRITE(*,*) 'Rectangular velocity from inverse mapping:'\nC WRITE(*,*) ' '\nC WRITE(*,*) ' dX/dt (km/s) = ', DRECTN(1)\nC WRITE(*,*) ' dY/dt (km/s) = ', DRECTN(2)\nC WRITE(*,*) ' dZ/dt (km/s) = ', DRECTN(3)\nC WRITE(*,*) ' '\nC END\nC\nC\nC Output from this program should be similar to the following\nC (rounding and formatting differ across platforms):\nC\nC\nC Rectangular coordinates:\nC\nC X (km) = 146039732.\nC Y (km) = 278546607.\nC Z (km) = 119750315.\nC\nC Rectangular velocity:\nC\nC dX/dt (km/s) = -47.0428824\nC dY/dt (km/s) = 9.07021778\nC dZ/dt (km/s) = 4.75656274\nC\nC Ellipsoid shape parameters:\nC\nC Equatorial radius (km) = 3396.19\nC Polar radius (km) = 3376.2\nC Flattening coefficient = 0.00588600756\nC\nC Planetographic coordinates:\nC\nC Longitude (deg) = 297.667659\nC Latitude (deg) = 20.844504\nC Altitude (km) = 336531825.\nC\nC Planetographic velocity:\nC\nC d Longitude/dt (deg/s) = -8.35738632E-06\nC d Latitude/dt (deg/s) = 1.59349355E-06\nC d Altitude/dt (km/s) = -11.2144327\nC\nC Rectangular coordinates from inverse mapping:\nC\nC X (km) = 146039732.\nC Y (km) = 278546607.\nC Z (km) = 119750315.\nC\nC Rectangular velocity from inverse mapping:\nC\nC dX/dt (km/s) = -47.0428824\nC dY/dt (km/s) = 9.07021778\nC dZ/dt (km/s) = 4.75656274\nC\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC N.J. Bachman (JPL)\nC B.V. Semenov (JPL)\nC W.L. Taber (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 1.1.0, 21-SEP-2013 (BVS)\nC\nC Updated to save the input body name and ZZBODTRN state counter\nC and to do name-ID conversion only if the counter has changed.\nC\nC Updated to call LJUCRS instead of CMPRSS/UCASE. \nC\nC- SPICELIB Version 1.0.0, 26-DEC-2004 (NJB) (WLT)\nC\nC-&\n \nC$ Index_Entries\nC\nC Jacobian of rectangular w.r.t. planetographic coordinates\nC\nC-&\n \nC$ Revisions\nC\nC None.\nC\nC-&\n \n\n \nC\nC SPICELIB functions\nC\n INTEGER PLNSNS\n\n LOGICAL RETURN\n \nC\nC Local parameters\nC\n CHARACTER*(*) PMTMP\n PARAMETER ( PMTMP = 'BODY#_PM' )\n\n CHARACTER*(*) OVRTMP\n PARAMETER ( OVRTMP = 'BODY#_PGR_POSITIVE_LON' )\n\n\n INTEGER EARTH\n PARAMETER ( EARTH = 399 )\n\n INTEGER KVNMLN\n PARAMETER ( KVNMLN = 32 )\n\n INTEGER LNSIZE\n PARAMETER ( LNSIZE = 80 )\n\n INTEGER MOON\n PARAMETER ( MOON = 301 )\n\n INTEGER SENSLN\n PARAMETER ( SENSLN = 4 )\n\n INTEGER SUN\n PARAMETER ( SUN = 10 )\n\nC\nC Saved body name length.\nC\n INTEGER MAXL\n PARAMETER ( MAXL = 36 )\n\n\n \nC\nC Local variables\nC \n CHARACTER*(LNSIZE) KVALUE\n CHARACTER*(KVNMLN) PMKVAR\n CHARACTER*(SENSLN) PGRLON\n \n DOUBLE PRECISION GEOLON\n\n INTEGER BODYID\n INTEGER I\n INTEGER N\n INTEGER SENSE\n\n LOGICAL FOUND \n\nC\nC Saved name/ID item declarations.\nC\n INTEGER SVCTR1 ( CTRSIZ )\n CHARACTER*(MAXL) SVBODY\n INTEGER SVBDID\n LOGICAL SVFND1\n\n LOGICAL FIRST\n\nC\nC Saved name/ID items.\nC\n SAVE SVCTR1\n SAVE SVBODY\n SAVE SVBDID\n SAVE SVFND1\n\n SAVE FIRST\n\nC\nC Initial values.\nC\n DATA FIRST / .TRUE. /\n\n\nC\nC Standard SPICE error handling.\nC\n IF ( RETURN () ) THEN\n RETURN\n END IF\n\n CALL CHKIN ( 'DRDPGR' )\n \nC\nC Initialization.\nC\n IF ( FIRST ) THEN\n\nC\nC Initialize counter.\nC\n CALL ZZCTRUIN( SVCTR1 )\n\n FIRST = .FALSE.\n\n END IF\n\nC\nC Convert the body name to an ID code.\nC \n CALL ZZBODS2C ( SVCTR1, SVBODY, SVBDID, SVFND1,\n . BODY, BODYID, FOUND )\n \n IF ( .NOT. FOUND ) THEN\n \n CALL SETMSG ( 'The value of the input argument BODY is #, '\n . // 'this is not a recognized name of an '\n . // 'ephemeris object. The cause of this '\n . // 'problem may be that you need an updated '\n . // 'version of the SPICE Toolkit. ' )\n CALL ERRCH ( '#', BODY )\n CALL SIGERR ( 'SPICE(IDCODENOTFOUND)' )\n CALL CHKOUT ( 'DRDPGR' )\n RETURN\n \n END IF\n\nC\nC The equatorial radius must be positive. If not, signal an error\nC and check out.\nC\n IF ( RE .LE. 0.0D0 ) THEN\n\n CALL SETMSG ( 'Equatorial radius was #.' )\n CALL ERRDP ( '#', RE )\n CALL SIGERR ( 'SPICE(VALUEOUTOFRANGE)' )\n CALL CHKOUT ( 'DRDPGR' )\n RETURN\n\n END IF\n \nC\nC If the flattening coefficient is greater than 1, the polar radius\nC is negative. If F is equal to 1, the polar radius is zero. Either\nC case is a problem, so signal an error and check out.\nC\n IF ( F .GE. 1.D0 ) THEN\n\n CALL SETMSG ( 'Flattening coefficient was #.' )\n CALL ERRDP ( '#', F )\n CALL SIGERR ( 'SPICE(VALUEOUTOFRANGE)' )\n CALL CHKOUT ( 'DRDPGR' )\n RETURN\n\n END IF\n\nC\nC Look up the longitude sense override variable from the\nC kernel pool.\nC\n CALL REPMI ( OVRTMP, '#', BODYID, PMKVAR )\n CALL GCPOOL ( PMKVAR, 1, 1, N, KVALUE, FOUND )\n\n IF ( FOUND ) THEN\nC\nC Make sure we recognize the value of PGRLON.\nC\n CALL LJUCRS ( 0, KVALUE, PGRLON )\n\n IF ( PGRLON .EQ. 'EAST' ) THEN\n\n SENSE = 1\n\n ELSE IF ( PGRLON .EQ. 'WEST' ) THEN\n\n SENSE = -1\n\n ELSE\n \n CALL SETMSG ( 'Kernel variable # may have the values ' //\n . 'EAST or WEST. Actual value was #.' )\n CALL ERRCH ( '#', PMKVAR )\n CALL ERRCH ( '#', KVALUE )\n CALL SIGERR ( 'SPICE(INVALIDOPTION)' )\n CALL CHKOUT ( 'DRDPGR' )\n RETURN\n\n END IF\n\n\n ELSE\nC\nC Look up the spin sense of the body's prime meridian.\nC\n SENSE = PLNSNS ( BODYID )\n\nC\nC If the required prime meridian rate was not available, \nC PLNSNS returns the code 0. Here we consider this situation\nC to be an error.\nC \n IF ( SENSE .EQ. 0 ) THEN\n\n CALL REPMI ( PMTMP, '#', BODYID, PMKVAR )\n\n CALL SETMSG ( 'Prime meridian rate coefficient defined ' //\n . 'by kernel variable # is required but ' //\n . 'not available for body #. ' )\n CALL ERRCH ( '#', PMKVAR )\n CALL ERRCH ( '#', BODY )\n CALL SIGERR ( 'SPICE(MISSINGDATA)' )\n CALL CHKOUT ( 'DRDPGR' )\n RETURN\n\n END IF\n\nC\nC Handle the special cases: earth, moon, and sun.\nC\n IF ( ( BODYID .EQ. EARTH ) \n . .OR. ( BODYID .EQ. MOON ) \n . .OR. ( BODYID .EQ. SUN ) ) THEN\n \n SENSE = 1\n\n END IF\n\n END IF \n\nC\nC At this point, SENSE is set to +/- 1.\nC\nC Adjust the longitude according to the sense of the body's\nC spin, or according to the override value if one is provided.\nC We want positive east longitude.\nC\n GEOLON = SENSE * LON\n \nC\nC Now that we have geodetic longitude in hand, use the\nC geodetic equivalent of the input coordinates to find the\nC Jacobian matrix of rectangular coordinates with respect\nC to geodetic coordinates.\nC\n CALL DRDGEO ( GEOLON, LAT, ALT, RE, F, JACOBI )\n\nC\nC The matrix JACOBI is\nC\nC .- -.\nC | DX/DGEOLON DX/DLAT DX/DALT |\nC | DY/DGEOLON DY/DLAT DY/DALT |\nC | DZ/DGEOLON DZ/DLAT DZ/DALT |\nC `- -'\nC\nC which, applying the chain rule to D(*)/DGEOLON, is equivalent to\nC\nC .- -.\nC | (1/SENSE) * DX/DLON DX/DLAT DX/DALT |\nC | (1/SENSE) * DY/DLON DY/DLAT DY/DALT |\nC | (1/SENSE) * DZ/DLON DZ/DLAT DZ/DALT |\nC `- -'\nC\nC So, multiplying the first column of JACOBI by SENSE gives us the\nC matrix we actually want to compute: the Jacobian matrix of\nC rectangular coordinates with respect to planetographic\nC coordinates.\nC\n DO I = 1, 3 \n\n JACOBI(I,1) = SENSE * JACOBI(I,1)\n\n END DO\n\n CALL CHKOUT ( 'DRDPGR' )\n RETURN\n END\n", "meta": {"hexsha": "15dc68dfe02b83d4573d78d1b5582d88e9cc48ac", "size": 25829, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/drdpgr.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/drdpgr.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/drdpgr.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": 32.28625, "max_line_length": 72, "alphanum_fraction": 0.5361802625, "num_tokens": 6890, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107949104866, "lm_q2_score": 0.72487026428967, "lm_q1q2_score": 0.6793562366018963}} {"text": "! Calculate power spectrum P(k) of a 1-D pencil array of data. The \"overdensity\" input array is any scalar field (not just density)\n! in the form g(x) = (x/x_bar) - 1, where x_bar is the mean.\n\nsubroutine calc_ps1d (overdensity_fft_real, overdensity_fft_imag, lo, hi, ng, dir, num_bins, k_bin_edges, domain_length, &\n k_bin_count, k_bin_power_weighted_k_sum, k_bin_power_sum)\n\n use, intrinsic :: iso_c_binding\n implicit none\n\n integer(c_int), intent(in) :: lo(3), hi(3), ng, num_bins, dir\n real(c_double), intent(in), target :: overdensity_fft_real (lo(1)-ng:hi(1)+ng, lo(2)-ng:hi(2)+ng, lo(3)-ng:hi(3)+ng, 1)\n real(c_double), intent(in), target :: overdensity_fft_imag (lo(1)-ng:hi(1)+ng, lo(2)-ng:hi(2)+ng, lo(3)-ng:hi(3)+ng, 1)\n real(c_double), intent(in) :: k_bin_edges (num_bins+1)\n real(c_double), intent(in) :: domain_length\n\n integer(c_int), intent(out) :: k_bin_count (num_bins)\n real(c_double), intent(out) :: k_bin_power_weighted_k_sum (num_bins)\n real(c_double), intent(out) :: k_bin_power_sum (num_bins)\n\n integer(c_int) :: i\n integer(c_int) :: k\n integer(c_int) :: k_bin_index\n integer(c_int) :: k_index\n\n real(c_double) :: k_fund\n real(c_double) :: k_mag\n real(c_double) :: k_max\n real(c_double) :: k_min\n real(c_double) :: k_nyquist\n real(c_double) :: p_i\n real(c_double) :: pi\n\n real(c_double), pointer :: overdensity_fft_real_pencil (:)\n real(c_double), pointer :: overdensity_fft_imag_pencil (:)\n\n complex(c_double_complex), allocatable :: overdensity_fft_pencil (:)\n\n pi = acos(-1.0)\n\n ! Align 1-D array pointers along pencils to simplify indexing later on.\n if (dir == 0) then\n overdensity_fft_real_pencil => overdensity_fft_real (lo(1):hi(1), lo(2), lo(3), 1)\n overdensity_fft_imag_pencil => overdensity_fft_imag (lo(1):hi(1), lo(2), lo(3), 1)\n else if (dir == 1) then\n overdensity_fft_real_pencil => overdensity_fft_real (lo(1), lo(2):hi(2), lo(3), 1)\n overdensity_fft_imag_pencil => overdensity_fft_imag (lo(1), lo(2):hi(2), lo(3), 1)\n else if (dir == 2) then\n overdensity_fft_real_pencil => overdensity_fft_real (lo(1), lo(2), lo(3):hi(3), 1)\n overdensity_fft_imag_pencil => overdensity_fft_imag (lo(1), lo(2), lo(3):hi(3), 1)\n end if\n\n allocate(overdensity_fft_pencil(size(overdensity_fft_real_pencil)))\n\n ! Combine the real and imaginary parts into a single complex array.\n do i = 1, size(overdensity_fft_pencil)\n overdensity_fft_pencil(i) = cmplx(overdensity_fft_real_pencil(i), overdensity_fft_imag_pencil(i), c_double_complex)\n end do\n\n k_fund = 2.0 * pi / domain_length\n\n k_nyquist = k_fund * size(overdensity_fft_pencil)/2\n\n k_min = minval(k_bin_edges)\n k_max = maxval(k_bin_edges)\n\n if (k_min < 0.0 .or. k_max > k_nyquist) then\n print *, \"(k_min, k_max, k_nyquist) = \", k_min, k_max, k_nyquist\n stop 'spectral k values out of bounds'\n end if\n\n k_bin_count (:) = 0\n k_bin_power_weighted_k_sum (:) = 0.0\n k_bin_power_sum (:) = 0.0\n\n do i = lbound(overdensity_fft_pencil, 1), ubound(overdensity_fft_pencil, 1)\n if (i <= size(overdensity_fft_pencil)/2+1) then\n k_index = i-1\n else\n k_index = i-1 - size(overdensity_fft_pencil)\n end if\n\n if (k_index == 0) cycle\n\n k_mag = k_fund * real(abs(k_index), c_double)\n\n if (k_mag < k_min .or. k_mag >= k_max) cycle\n\n ! Find the k bin.\n k_bin_index = -1\n do k = 1, num_bins\n if (k_mag >= k_bin_edges(k) .and. k_mag < k_bin_edges(k+1)) then\n k_bin_index = k\n exit\n end if\n end do\n if (k_bin_index < 0) stop 'COULD NOT MATCH K BIN'\n\n p_i = (abs(overdensity_fft_pencil(i)))**2 / domain_length\n\n k_bin_count (k_bin_index) = k_bin_count (k_bin_index) + 1\n k_bin_power_weighted_k_sum (k_bin_index) = k_bin_power_weighted_k_sum (k_bin_index) + k_mag*p_i\n k_bin_power_sum (k_bin_index) = k_bin_power_sum (k_bin_index) + p_i\n\n end do\n\n deallocate(overdensity_fft_pencil)\n\nend subroutine calc_ps1d\n", "meta": {"hexsha": "6fc1febb02c219be8f3c68e4cea2599daff31c65", "size": 3989, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "calc_ps1d.f90", "max_stars_repo_name": "bcfriesen/gimlet", "max_stars_repo_head_hexsha": "153771cfb5bf810e4f1ca9a8ec4549935a51320a", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-12-14T16:19:12.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-14T16:19:12.000Z", "max_issues_repo_path": "calc_ps1d.f90", "max_issues_repo_name": "bcfriesen/gimlet", "max_issues_repo_head_hexsha": "153771cfb5bf810e4f1ca9a8ec4549935a51320a", "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": "calc_ps1d.f90", "max_forks_repo_name": "bcfriesen/gimlet", "max_forks_repo_head_hexsha": "153771cfb5bf810e4f1ca9a8ec4549935a51320a", "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": 36.5963302752, "max_line_length": 131, "alphanum_fraction": 0.6786161945, "num_tokens": 1315, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942067038784, "lm_q2_score": 0.7520125848754471, "lm_q1q2_score": 0.6792886112864}} {"text": "program ComputeGammaInt\n\n implicit none\n\n integer :: i\n\n write(*, \"(3A15)\") \"Simpson\", \"Lanczos\", \"Builtin\"\n do i=1, 10\n write(*, \"(3F15.8)\") my_gamma(i/3.0), lacz_gamma(i/3.0), gamma(i/3.0)\n end do\n\ncontains\n\n pure function intfuncgamma(x, y) result(z)\n real :: z\n real, intent(in) :: x, y\n\n z = x**(y-1.0) * exp(-x)\n end function intfuncgamma\n\n\n function my_gamma(a) result(g)\n real :: g\n real, intent(in) :: a\n\n real, parameter :: small = 1.0e-4\n integer, parameter :: points = 100000\n\n real :: infty, dx, p, sp(2, points), x\n integer :: i\n logical :: correction\n\n x = a\n\n correction = .false.\n ! value with x<1 gives \\infty, so we use\n ! \\Gamma(x+1) = x\\Gamma(x)\n ! to avoid the problem\n if ( x < 1.0 ) then\n correction = .true.\n x = x + 1\n end if\n\n ! find a \"reasonable\" infinity...\n ! we compute this integral indeed\n ! \\int_0^M dt t^{x-1} e^{-t}\n ! where M is such that M^{x-1} e^{-M} \u2264 \\epsilon\n infty = 1.0e4\n do while ( intfuncgamma(infty, x) > small )\n infty = infty * 10.0\n end do\n\n ! using simpson\n dx = infty/real(points)\n sp = 0.0\n forall(i=1:points/2-1) sp(1, 2*i) = intfuncgamma(2.0*(i)*dx, x)\n forall(i=1:points/2) sp(2, 2*i - 1) = intfuncgamma((2.0*(i)-1.0)*dx, x)\n g = (intfuncgamma(0.0, x) + 2.0*sum(sp(1,:)) + 4.0*sum(sp(2,:)) + &\n intfuncgamma(infty, x))*dx/3.0\n\n if ( correction ) g = g/a\n\n end function my_gamma\n\n\n recursive function lacz_gamma(a) result(g)\n real, intent(in) :: a\n real :: g\n\n real, parameter :: pi = 3.14159265358979324\n integer, parameter :: cg = 7\n\n ! these precomputed values are taken by the sample code in Wikipedia,\n ! and the sample itself takes them from the GNU Scientific Library\n real, dimension(0:8), parameter :: p = &\n (/ 0.99999999999980993, 676.5203681218851, -1259.1392167224028, &\n 771.32342877765313, -176.61502916214059, 12.507343278686905, &\n -0.13857109526572012, 9.9843695780195716e-6, 1.5056327351493116e-7 /)\n\n real :: t, w, x\n integer :: i\n\n x = a\n\n if ( x < 0.5 ) then\n g = pi / ( sin(pi*x) * lacz_gamma(1.0-x) )\n else\n x = x - 1.0\n t = p(0)\n do i=1, cg+2\n t = t + p(i)/(x+real(i))\n end do\n w = x + real(cg) + 0.5\n g = sqrt(2.0*pi) * w**(x+0.5) * exp(-w) * t\n end if\n end function lacz_gamma\n\nend program ComputeGammaInt\n", "meta": {"hexsha": "9e40c1fc16b1877c0b71c7e37135af7e7c0d30ab", "size": 2439, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Gamma-function/Fortran/gamma-function.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Gamma-function/Fortran/gamma-function.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Gamma-function/Fortran/gamma-function.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 24.6363636364, "max_line_length": 78, "alphanum_fraction": 0.5617056171, "num_tokens": 914, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942041005328, "lm_q2_score": 0.7520125848754472, "lm_q1q2_score": 0.6792886093286515}} {"text": " SUBROUTINE DRFVAL (X, Y, Z, RF, IERR)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nC>> 1998-10-29 DRFVAL Krogh Moved external statement up for mangle.\nC>> 1995-11-17 DRFVAL Krogh Converted SFTRAN to Fortran 77.\nc>> 1994-11-02 DRFVAL Krogh Changes to use M77CON\nc>> 1994-08-15 DRFVAL WV Snyder JPL use 2-arg min and max for C conv.\nc>> 1993-02-23 DRFVAL WV Snyder JPL Split DRFVLX into a separate subr.\nC>> 1991-10-31 DRFVAL WV Snyder JPL Incorporate changes from Carlson\nC>> 1990-11-27 DRFVAL WV Snyder JPL Convert Carlson's code for MATH77\nC\nC--D replaces \"?\": ?ERM1, ?ERV1, ?RFVAL, ?RFVLX\nC\nC CHECK ARGUMENT RANGES AND CALL DRFVLX TO DO THE COMPUTATION\nC OF CARLSON'S ELLIPTIC INTEGRAL RF(X,Y,Z).\nC\nC INPUT ...\nC\nC X, Y, AND Z ARE THE VARIABLES IN THE INTEGRAL RF(X,Y,Z).\nC\nC OUTPUT ...\nC\nC RF IS THE VALUE OF THE INCOMPLETE ELLIPTIC INTEGRAL.\nC\nC IERR IS THE RETURN ERROR CODE.\nC IERR = 0 FOR NORMAL COMPLETION OF THE SUBROUTINE.\nC IERR = 1 X, Y, OR Z IS NEGATIVE.\nC IERR = 2 X+Y, X+Z, OR Y+Z IS TOO SMALL.\nC IERR = 3 X, Y, OR Z IS TOO LARGE.\nC\n DOUBLE PRECISION X, Y, Z, RF\n INTEGER IERR\nC ----------------------------------------------------------------------\n EXTERNAL D1MACH\n DOUBLE PRECISION D1MACH\nC ----------------------------------------------------------------------\nC\nC MACHINE DEPENDENT PARAMETERS ...\nC\nC LOLIM AND UPLIM DETERMINE THE RANGE OF VALID ARGUMENTS.\nC LOLIM IS NOT LESS THAN THE MACHINE MINIMUM MULTIPLIED BY 5.\nC UPLIM IS NOT GREATER THAN THE MACHINE MAXIMUM DIVIDED BY 5.\nC\n DOUBLE PRECISION LOLIM, UPLIM\n SAVE LOLIM, UPLIM\n DATA LOLIM /-1.0d0/\nC ----------------------------------------------------------------------\nC WARNING. CHANGES IN THE PROGRAM MAY IMPROVE SPEED AT THE\nC EXPENSE OF ROBUSTNESS.\nC ----------------------------------------------------------------------\nC\n RF = 0.0d0\n IF (MIN(X,MIN(Y,Z)) .LT. 0.0d0) THEN\n IERR = 1\n CALL DERM1 ('DRFVAL',1,0,'One of X, Y or Z is negative','X',x,\n 1 ',')\n CALL DERV1 ('Y',Y,',')\n CALL DERV1 ('Z',Z,'.')\n RETURN\n END IF\n IF (LOLIM .LT. 0.0d0) THEN\n LOLIM = 5.0d0 * D1MACH(1)\n UPLIM = D1MACH(2) / 5.0d0\n END IF\n IF (MAX(X,MAX(Y,Z)) .GT. UPLIM) THEN\n IERR = 3\n CALL DERM1 ('DRFVAL',3,0,'One of X, Y or Z > UPLIM','X',\n 1 x,',')\n CALL DERV1 ('Y',Y,',')\n CALL DERV1 ('Z',Z,',')\n CALL DERV1 ('UPLIM',UPLIM,'.')\n RETURN\n END IF\n IF (MIN(X+Y,MIN(X+Z,Y+Z)) .LT. LOLIM) THEN\n IERR = 2\n CALL DERM1 ('DRFVAL',2,0,'One of X+Y, X+Z or Y+Z < LOLIM','X',\n 1 x,',')\n CALL DERV1 ('Y',Y,',')\n CALL DERV1 ('Z',Z,',')\n CALL DERV1 ('LOLIM',LOLIM,'.')\n RETURN\n END IF\nC\n IERR = 0\n CALL DRFVLX (X, Y, Z, RF)\n RETURN\n END\n\n SUBROUTINE DRFVLX (X, Y, Z, RF)\nc>> 1993-02-23 DRFVLX WV Snyder JPL Split DRFVLX into a separate subr.\nC ------------------------------------------------------------------\nC DRFVLX SHOULD ONLY BE CALLED FROM OTHER LIBRARY ROUTINES, WHERE WE\nC KNOW X, Y, Z ARE IN RANGE. USERS SHOULD NOT CALL DRFVLX DIRECTLY.\nC ------------------------------------------------------------------\nC\nC COMPUTE THE INCOMPLETE ELLIPTIC INTEGRAL OF THE FIRST KIND\nC\nC RF(X,Y,Z) = INTEGRAL FROM ZERO TO INFINITY OF\nC\nC -1/2 -1/2 -1/2\nC (1/2)(T+X) (T+Y) (T+Z) DT,\nC\nC WHERE X, Y, AND Z ARE NONNEGATIVE AND AT MOST ONE OF THEM\nC IS ZERO. IF ONE OF THEM IS ZERO, THE INTEGRAL IS COMPLETE.\nC THE DUPLICATION THEOREM IS ITERATED UNTIL THE VARIABLES ARE\nC NEARLY EQUAL, AND THE FUNCTION IS THEN EXPANDED IN TAYLOR\nC SERIES TO FIFTH ORDER.\nC REFERENCES: B. C. CARLSON AND E. M. NOTIS, ALGORITHMS FOR\nC INCOMPLETE ELLIPTIC INTEGRALS, ACM TRANSACTIONS ON MATHEMA-\nC TICAL SOFTWARE, 7 (1981), 398-403; B. C. CARLSON, COMPUTING\nC ELLIPTIC INTEGRALS BY DUPLICATION, NUMER. MATH., 33 (1979),\nC 1-16.\nC AUTHORS: B. C. CARLSON AND ELAINE M. NOTIS, AMES LABORATORY-\nC DOE, IOWA STATE UNIVERSITY, AMES, IA 50011, AND R. L. PEXTON,\nC LAWRENCE LIVERMORE NATIONAL LABORATORY, LIVERMORE, CA 94550.\nC AUG. 1, 1979, REVISED JAN. 15, 1987.\nC\nC CHECK VALUE: RF(0,1,2) = 1.31102 87771 46059 90523 24198\nC CHECK BY ADDITION THEOREM: RF(X,X+Z,X+W) + RF(Y,Y+Z,Y+W)\nC = RF(0,Z,W), WHERE X,Y,Z,W ARE POSITIVE AND X * Y = Z * W.\nC\n DOUBLE PRECISION X, Y, Z, RF\nC INPUT ...\nC\nC X, Y, AND Z ARE THE VARIABLES IN THE INTEGRAL RF(X,Y,Z).\nC\nC OUTPUT ...\nC\nC RF IS THE VALUE OF THE INCOMPLETE ELLIPTIC INTEGRAL.\nC\nC ----------------------------------------------------------------------\n EXTERNAL D1MACH\n DOUBLE PRECISION D1MACH\n DOUBLE PRECISION C1,C2,C3,E2,E3,EPSLON,ERRTOL,LAMDA\n DOUBLE PRECISION MU,S,XN,XNDEV,XNROOT\n DOUBLE PRECISION YN,YNDEV,YNROOT,ZN,ZNDEV,ZNROOT\n PARAMETER (C1 = 10.0d0 / 24.0d0)\n PARAMETER (C2 = 30.0d0 / 44.0d0)\n PARAMETER (C3 = 10.0d0 / 14.0d0)\nC ----------------------------------------------------------------------\nC MACHINE DEPENDENT PARAMETER ...\nC ERRTOL IS SET TO THE DESIRED ERROR TOLERANCE.\nC RELATIVE ERROR DUE TO TRUNCATION IS LESS THAN\nC ERRTOL ** 6 / (4 * (1 - ERRTOL)).\nC\n SAVE ERRTOL\n DATA ERRTOL /-1.0D0/\nC ----------------------------------------------------------------------\n IF (ERRTOL .LT. 0.0d0) ERRTOL = (3.6d0 * D1MACH(4))**(1.0d0/6.0d0)\n XN = X\n YN = Y\n ZN = Z\nC\n 20 CONTINUE\n MU = (XN + YN + ZN) / 3.0d0\n XNDEV = 2.0d0 - (MU + XN) / MU\n YNDEV = 2.0d0 - (MU + YN) / MU\n ZNDEV = 2.0d0 - (MU + ZN) / MU\n EPSLON = MAX(ABS(XNDEV),MAX(ABS(YNDEV),ABS(ZNDEV)))\n IF (EPSLON .LT. ERRTOL) THEN\n E3 = XNDEV * YNDEV\n E2 = E3 - ZNDEV * ZNDEV\n E3 = E3 * ZNDEV\n S = 10.0d0 + (C1 * E2 - 1.0d0 - C2 * E3) * E2 + C3 * E3\n RF = S / (10.0d0*SQRT(MU))\n RETURN\n END IF\n XNROOT = SQRT(XN)\n YNROOT = SQRT(YN)\n ZNROOT = SQRT(ZN)\n LAMDA = XNROOT * (YNROOT + ZNROOT) + YNROOT * ZNROOT\n XN = (XN + LAMDA) * 0.25d0\n YN = (YN + LAMDA) * 0.25d0\n ZN = (ZN + LAMDA) * 0.25d0\n GO TO 20\n END\n", "meta": {"hexsha": "2d5136492de704bd03e610fcbdae6a1005addb09", "size": 6580, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/drfval.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/drfval.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/drfval.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 36.9662921348, "max_line_length": 72, "alphanum_fraction": 0.5249240122, "num_tokens": 2320, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971872, "lm_q2_score": 0.7520125848754472, "lm_q1q2_score": 0.6792886073709028}} {"text": " SUBROUTINE DTGGRD(X,Y,NP,IP,W,TRIANG,MT,B,MB,NT,INFO)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc File: dtggrd.[f|for]\nc contains dtggrd, dtgang, dtgadj, dtgupd\nc\nc>> 1997-07-01 DTGGRD Krogh Reversed subscripts in B (CLL suggestion)\nc>> 1997-06-14 DTGGRD Krogh Removed implicit none, added external stmt.\nc>> 1997-06-14 DTGGRD CLL Argument INFO() replaces NBUSED, MODE, & OK1.\nC>> 1997-06-09 DTGGRD Krogh Converted SFTRAN code to Fortran.\nC>> 1995-09-26 DTGGRD CLL Editing for inclusion into MATH77.\nc>> 1991-11-20 DTGGRD CLL Using Math77 subroutine _SORTP for sorting.\nC\nC THIS SUBR CONSTRUCTS A LIST OF POINTERS IN THE ARRAY\nC TRIANG() DEFINING A TRIANGULAR GRID HAVING THE GIVEN (X,Y)\nC DATA AS VERTICES.\nC THE GRID WILL BE OPTIMAL IN THE SENSE OF THE MAX-MIN ANGLE\nC CRITERION. IT HAS BEEN SHOWN, INDEPENDENTLY BY LAWSON AND BY\nC R. SIBSON, THAT THIS IS EQUIVALENT TO SOME OTHER OPTIMALLITY\nC CRITERIA. THE GRID PRODUCED IS A DELAUNAY TRIANGULATION AND\nC IS THE GRAPH THEORETIC DUAL OF A TESSELLATION MADE UP OF\nC PROXIMITY REGIONS ASSOCIATED WITH THE NAMES DIRICHLET,\nC VORONOI, AND THIESSEN.\nC\nC C. L. LAWSON, JPL, 1976 NOV 28\nC C.L.L., 1979 MAR 3. CONVERTED TO SFTRAN3.\nC C.L.L., 1979 JUL 22. ADDED CALL TO DTGSIZ.\nC\nC X(1:NP),Y(1:NP) [in] (X,Y) DATA POINTS.\nC NP [in] NO. OF DATA POINTS. REQUIRE NP .GE. 3.\nC\nC IP() [scratch] WORK SPACE OF LENGTH at least NP.\nC W() [scratch] WORK SPACE OF LENGTH at least NP.\nC TRIANG() [out] ARRAY IN WHICH THIS SUBR WILL BUILD A LIST DEFINING\nC A triangular grid. access to this list is via the\nC four subrs DTGGET, DTGPUT, DTGSIZ, and DTGSET.\nC MT [in] DIMENSION OF ARRAY TRIANG(). NO. OF TRIANGLES IT\nC CAN HOLD, NTLIM, IS DETERMINED BY USE OF SUBROUTINE\nC DTGSIZ. NTLIM WILL BE MT/6 IF POINTERS ARE NOT\nC PACKED. NTLIM = (3*MT)/6 IF POINTERS ARE PACKED\nC THREE PER WORD.\nc Bdry(1:4, MB) [integer, out] Array containing pointers defining the\nc boundary of the (convex) triangular grid.\nC Bdry(1, K) = FWD POINTER. Points to next vertex in\nc counterclockwise order.\nC Bdry(2, K) = BACKWARD POINTER. Points to next vertex in\nc clockwise order.\nC Bdry(3, K) = A BOUNDARY POINT\nC Bdry(4, K) = A BOUNDARY TRIANGLE\nc The triangle Bdry(4, K) has a boundary edge that\nc connects the points Bdry(3, K) and Bdry(3, K+1).\nc\nc On return from this subroutine, some elements of the array Bdry()\nc may not be members of the linked list defining the boundary. The\nc entry with K = 1 will always be a member of the boundary list.\nc Thus for another subroutine to scan the Bdry() list made by this\nc subroutine it should start with K = 1 and follow the forward or\nc backward pointers.\nc\nC MB [in] FIRST DIMENSION OF B(,). SETTING MB = NP+1 WILL\nC ALWAYS BE ADEQUATE, HOWEVER A MUCH SMALLER VALUE\nC WILL OFTEN SUFFICE. SUGGEST TRYING MB = 6 * (cube root\nC of NP) WHEN NP .GE. 64.\nC NT [out] OUTPUT.. NO. OF TRIANGLES\nc\nc INFO(1:3) [out, integer] Termination status information.\nc\nc INFO(1) INDICATES STATUS ON TERMINATION.\nC 0 NORMAL TERMINATION. The triangular grid is complete\nc and successfully optimized.\nC 1 ERROR. The triangular grid is complete but not\nc successfully optimized. Apparent looping in DTGADJ.\nC GRID MAY NOT BE OPTIMAL.\nC 2 ERROR. ALL GIVEN POINTS ARE COLINEAR. NO TRIANGLES\nC CONSTRUCTED. (OR ELSE THERE ARE SOME DUPLICATE PTS)\nC 3 ERROR. DUPLICATE POINTS. TRIANGULAR GRID NOT\nC COMPLETED.\nC 4 ERROR. NOT ENOUGH SPACE IN B(,). USER MUST\nC INCREASE MB.\nC 5 NOT ENOUGH SPACE IN TRIANG(). USER MUST MAKE\nC MT BIGGER.\nC INFO(2) NO. OF BOUNDARY POINTS.\nC INFO(3) SMALLEST SETTING OF MB THAT WOULD SUFFICE FOR THIS DATA.\nc\nc [Relations to internal variables or previously used variable\nc names: INFO(1) = MODE, INFO(2) = NB, INFO(3) = MBUSED,\nc The value of INFO(1) = MODE will be set to 0 when\nc OK1 = .true. and 1 when OK1 = .false.]\nC\nC USE SUBR DTGSIZ TO COMPUTE NTLIM, THE MAX NO. OF\nC TRIANGLES, GIVEN THE DIMENSION PARAMETER MT.\nC\nc ------------------------------------------------------------------\nc--D replaces \"?\": ?TGGRD, ?TGANG, ?TGSET, ?TGGET, ?TGPUT, ?TGSIZ,\nc--& ?TGADJ, ?SORTP, ?TGUPD\nc ------------------------------------------------------------------\n INTEGER NP, mb, mt\n INTEGER AVAIL, B(4, MB), ext, TRI(6)\n integer i, i1, i2, i3, i3prev, index, INFO(3), ip(np), isave\n integer jhi, jlo, jnew\n integer k, kb1, kbhi, kblo, kbnew, kbz\n integer mode\n integer nb, nt, ntlim, mbused, TRIANG(MT)\n double precision aref, cross\n external DTGANG\n double precision DTGANG\n double precision dx12, dy12, eight, pangle\n DOUBLE PRECISION W(np), X(NP), xmean, Y(NP), ymean, zero\n parameter(zero = 0.0d0, eight = 8.0d0)\n LOGICAL OK, OK1\nc ------------------------------------------------------------------\n call DTGSIZ( MT, NTLIM )\n MODE = 0\n OK1 = .TRUE.\nC\nC FIND AN EXTREME POINT (X(EXT),Y(EXT))\nC\n EXT=1\n do 10 I = 1, NP\n if ( X(I) .lt. X(EXT)\n * .or. (X(I) .eq. X(EXT) .and. Y(I) .lt. Y(EXT) )) EXT=I\n 10 continue\nC\nC COMPUTE SQUARED DISTANCES FROM (X(EXT),Y(EXT)).\nC ALSO INITIALIZE IP().\n do 20 I = 1, NP\n W(I) = (X(I)-X(EXT))**2 + (Y(I)-Y(EXT))**2\n 20 continue\nc\nc Use _SORTP from the JPL MATH77 library to\nc determine a sorted order for the contents of W() and set\nc indices indicating the sorted order in IP().\nc IP() will be set so that W(IP(1)) is the smallest number in\nc W(), W(IP(2)) is the next larger number, etc. The contents\nc of IP() will be used as indices into the X() and Y() arrays.\nc The contents of W() will not be reordered by _SORTP, however\nc this does not matter here since the next time we reference W()\nc will be to store other things into it.\nc\n call DSORTP(W, 1, NP, IP)\nC\nC BUILD THE FIRST TRIANGLE USING POINTS IP(1), IP(2), AND\nC THE NEXT POINT THAT IS NOT COLINEAR WITH THESE TWO.\nC\n I1=IP(1)\n I2=IP(2)\n DX12= X(I2)-X(I1)\n DY12= Y(I2)-Y(I1)\n I3PREV = 0\n do 40 I = 3, NP\n I3 = IP(I)\n IP(I) = I3PREV\n CROSS =-(X(I3)-X(I2))*DY12 + (Y(I3)-Y(I2))*DX12\n if (CROSS .ne. 0.) then\n if (CROSS .lt. 0.) then\nC SWAP I2 AND I3\n ISAVE=I2\n I2 =I3\n I3 =ISAVE\n end if\n go to 50\n end if\n I3PREV=I3\n 40 continue\nC\nC ERROR IF DROP THRU TO HERE. ALL NP POINTS ARE COLINEAR\nC OR ELSE POINTS I1 AND I2 ARE IDENTICAL.\nC\n MODE = 2\n go to 999\nC\nC\n 50 continue\nC HERE THE VERTICES OF THE FIRST TRIANGLE ARE I1,I2,I3\nC\nC COMPUTE MEAN OF VERTICES OF FIRST TRIANGLE.\nC\n XMEAN = (X(I1)+X(I2)+X(I3))/3.\n YMEAN = (Y(I1)+Y(I2)+Y(I3))/3.\nC\nC COMPUTE THE PSEUDOANGLE OF VECTOR FROM (XMEAN,YMEAN)\nC TO I1.\nC\n AREF = DTGANG(X(I1)-XMEAN, Y(I1)-YMEAN, zero)\nC\nC INITIALIZE BOUNDARY POINTER STRUCTURE B(,).\nC B(1, K) = FWD POINTER\nC B(2, K) = BACKWARD POINTER\nC B(3, K) = A BOUNDARY POINT\nC B(4, K) = A BOUNDARY TRIANGLE\nC W(K) = PSEUDOANGLE OF POINT B(3, K)\nC\n do 70 K = 1, MB\n B(1, K) = K+1\n 70 continue\n B(1, MB) = 0\n B(1, 4) = 0\n AVAIL = 5\n do 80 K = 1, 4\n B(2, K) = K-1\n B(4, K) = 1\n 80 continue\n B(4, 4) = 0\nC\n B(3, 1) = I1\n B(3, 2) = I2\n B(3, 3) = I3\n B(3, 4) = I1\nC\n W(1) = zero\n W(2) = DTGANG(X(I2)-XMEAN,Y(I2)-YMEAN,AREF)\n W(3) = DTGANG(X(I3)-XMEAN,Y(I3)-YMEAN,AREF)\n W(4) = eight\n NB = 3\n MBUSED = 3\nC\nC BUILD FIRST TRIANGLE IN TRIANG().\nC\n if (NTLIM .le. 0) then\n MODE = 5\n go to 999\n end if\n call DTGSET(1,0,0,0,I1,I2,I3,TRIANG,MT)\n NT=1\nC ******************************************************************\nC\nC BEGIN MAIN LOOP. ADD ONE NEW POINT AT A TIME INTO\nC THE TRIANGULAR GRID STRUCTURE.\nC\nC ******************************************************************\n KBNEW=2\n do 200 INDEX = 4, NP\n JNEW = IP(INDEX)\n PANGLE = DTGANG(X(JNEW)-XMEAN, Y(JNEW)-YMEAN, AREF)\nC\nC USE PANGLE AS SEARCH KEY IN THE TABLE OF\nC PSEUDO ANGLES OF BOUNDARY POINTS.\nC START SEARCH AT PREVIOUS NEW BOUNDARY POINT.\nC\n KB1= KBNEW\n if ( PANGLE .gt. W(KB1)) then\n KBHI = KB1\n 100 KBLO = KBHI\n KBHI = B(1, KBLO)\n if ( PANGLE .gt. W(KBHI) ) go to 100\n else\nC HERE WE HAVE PANGLE .le. W(KB1)\n KBLO = KB1\n 110 KBHI = KBLO\n KBLO = B(2, KBHI)\n if ( PANGLE .lt. W(KBLO) ) go to 110\n end if\nC\n JLO = B(3, KBLO)\n JHI = B(3, KBHI)\nC\nC TEST FOR DUPLICATE POINTS\nC\n if ( PANGLE .eq. W(KBLO) ) then\n if ( X(JNEW) .eq. X(JLO) .and. Y(JNEW).eq.Y(JLO)) then\n MODE = 3\n go to 999\n end if\n else if (PANGLE .eq. W(KBHI) ) then\n if (X(JNEW).eq.X(JHI) .and. Y(JNEW).eq.Y(JHI)) then\n MODE = 3\n go to 999\n end if\n end if\nC\nC Attach point JNEW to JHI and JLOW.\n if (AVAIL .eq. 0) then\nC ERROR.. INSUFFICIENT STORAGE IN B()\nC TO REPRESENT THE BOUNDARY.\n MODE = 4\n go to 999\n endif\n if (NT .ge. NTLIM) then\nC ERROR.. INSUFFICIENT STORAGE IN\nC TRIANG()\n MODE=5\n go to 999\n endif\nC UPDATE TRIANG().\n NT=NT+1\n call DTGUPD(B(3, KBLO), B(4, KBLO), TRI, TRIANG, MT, NT)\n call DTGSET(NT,B(4, KBLO),0,0,JHI,JLO,JNEW,TRIANG,MT)\nC\nC UPDATE B() AND W().\n NB = NB+1\n if (NB .gt. MBUSED) MBUSED = NB\n KBNEW = AVAIL\n AVAIL = B(1, AVAIL)\n B(1, KBNEW) = KBHI\n B(2, KBNEW) = KBLO\n B(3, KBNEW) = JNEW\n B(4, KBNEW) = NT\n W(KBNEW) = PANGLE\n B(1, KBLO) = KBNEW\n B(2, KBHI) = KBNEW\n B(4, KBLO) = NT\nC\n call DTGADJ(NT,1,X,Y,NP,TRIANG,MT,B,MB, KBNEW, OK)\n OK1 = OK1 .and. OK\n\nC Done attaching point JNEW to JHI and JLOW.\nC We have just assigned JNEW the index KBNEW in the boundary list.\nC\nC LOOP BACKWARD ALONG BOUNDARY FROM KBNEW TO FIND OTHER\nC POINTS TO WHICH POINT JNEW CAN BE CONNECTED.\nC\n KBHI= KBLO\n KBLO = B(2, KBHI)\n 130 if (KBLO .ne. 0) then\n JHI = B(3, KBHI)\n JLO = B(3, KBLO)\n CROSS = -(Y(JHI)-Y(JNEW)) * (X(JLO)-X(JHI))\n * +(X(JHI)-X(JNEW)) * (Y(JLO)-Y(JHI))\n if (CROSS .gt. 0.) then\nC CONNECT POINT JNEW TO JLO\n if (NT .ge. NTLIM) then\nC ERROR.. INSUFFICIENT SPACE IN TRIANG().\nC\n MODE=5\n go to 999\n endif\nC UPDATE TRIANG()\n NT=NT+1\n call DTGUPD(B(3,KBLO), B(4,KBLO), TRI, TRIANG, MT, NT)\n call DTGUPD(B(3,KBHI), B(4,KBHI), TRI, TRIANG, MT, NT)\n call DTGSET(NT, B(4, KBLO), 0, B(4, KBHI), JHI, JLO,\n 1 JNEW, TRIANG, MT)\nC\nC UPDATE B()\n B(1, KBLO) = KBNEW\n B(2, KBNEW)= KBLO\n B(4, KBLO) = NT\n NB=NB-1\n B(1, KBHI) = AVAIL\n AVAIL = KBHI\nC\n call DTGADJ(NT,1,X,Y,NP,TRIANG,MT,B,MB, KBNEW, OK)\n OK1 = OK1 .and. OK\nc Done connecting point JNEW to JLO\nc\n KBHI = KBLO\n KBLO = B(2, KBHI)\n go to 130\n\n end if\n end if\nC\nC LOOP FORWARD ALONG BOUNDARY FROM KBNEW TO FIND OTHER\nC POINTS TO WHICH POINT JNEW CAN BE CONNECTED.\nC\n KBLO = B(1, KBNEW)\n KBHI = B(1, KBLO)\n 150 if (KBHI.ne.0) then\n JHI= B(3, KBHI)\n JLO= B(3, KBLO)\n CROSS = -(Y(JLO)-Y(JHI)) * (X(JNEW)-X(JLO))\n * +(X(JLO)-X(JHI)) * (Y(JNEW)-Y(JLO))\n if (CROSS .gt. 0) then\n if (NT .ge. NTLIM) then\nC ERROR.. INSUFFICIENT SPACE IN TRIANG().\n MODE = 5\n go to 999\n endif\nC Connect point JNEW to JHI -- Update TRIANG()\n NT=NT+1\n call DTGUPD(B(3, KBLO),B(4, KBLO),TRI,TRIANG,MT,NT)\n call DTGUPD(B(3, KBNEW),B(4, KBNEW),TRI,TRIANG,MT,NT)\n call DTGSET(NT, B(4, KBLO), B(4, KBNEW), 0, JHI, JLO,\n 1 JNEW, TRIANG, MT)\nC\nC UPDATE B()\n B(1, KBNEW) = KBHI\n B(2, KBHI) = KBNEW\n B(4, KBNEW) = NT\n NB=NB-1\n B(1, KBLO) = AVAIL\n AVAIL = KBLO\nC\n call DTGADJ(NT,1,X,Y,NP,TRIANG,MT,B,MB, KBNEW, OK)\n OK1 = OK1 .and. OK\nC Done connecting point JNEW to JHI\nc\n KBLO = KBHI\n KBHI = B(1, KBLO)\n go to 150\n\n end if\n end if\n 200 continue\n MBUSED = MBUSED + 1\nC\n 999 continue\nc\nc As built, the linked boundary list runs (counterclockwise) from\nc b(*, 1) to b(*, 4), with b(*, 1) and b(*, 4) representing the\nc same point. The back pointer in b(*, 1) and the forward\nc pointer in b(*, 4) are both zero, indicating ends of the list.\nc Change this so the linked list is fully circular, still\nc including b(*, 1), but detaching b(*, 4). Let kbz be the value\nc of the back pointer in b(*, 4). Set the back pointer in b(*,\nc 1) to be kbz, and the forward pointer in b(*, kbz) to be 1.\nc\n kbz = b(2, 4)\n b(2, 1) = kbz\n b(1, kbz) = 1\n\n if(MODE .eq. 0 .and. .not. OK1) MODE = 1\n INFO(1) = MODE\n INFO(2) = NB\n INFO(3) = MBUSED\n end\nc ==================================================================\n\n subroutine DTGUPD( JFIX, KB4, TRI, TRIANG, MT, NT)\nc Updates TRIANG, using JFIX and KB4\n integer JFIX, KB4, MT, NT, TRI(6), TRIANG(MT)\n integer I\nc\n call DTGGET(KB4,TRI,TRIANG)\n do 10 I = 1, 3\n if (TRI(I+3) .eq. JFIX) then\n TRI(I) = NT\n go to 20\n end if\n 10 continue\n 20 call DTGPUT(KB4, TRI, TRIANG, MT)\n return\n end\nc ==================================================================\n DOUBLE PRECISION FUNCTION DTGANG (XX,YY,AREF)\nC>> 1995-09-26 CLL Editing for inclusion into MATH77.\nC\nc Compute the pseudoangle DTGANG between the reference direction\nc whose pseudoangle is AREF and the vector (XX,YY).\nc Pseudoangle is measured counterclockwise with period 8.\nc Require 0. .le. AREF .lt. 8. on input.\nc On return DTGANG will be in the interval 0. .le. DTGANG .lt. 8.\nC\nc C.L.LAWSON, JPL, 1976 NOV 8\nC\nc ------------------------------------------------------------------\n double precision xx,yy,aref,a\n double precision eight, four, two, zero\n parameter(eight = 8.0d0, four = 4.0d0, two = 2.0d0, zero = 0.0d0)\nc ------------------------------------------------------------------\n if (abs(xx) .gt. abs(yy)) then\n a = yy/xx\n if (xx .lt. zero) then\n a=a+four\n else\n if (yy .lt. zero) then\n a=a+ eight\n end if\n end if\n else\n if (yy .eq. zero) then\n a = zero\n else\n a = two - xx/yy\n if (yy .lt. zero) a = a+four\n end if\n end if\nc . A IS NOW THE PSEUDOANGLE OF (XX,YY)\nc . RELATIVE TO (1.,0.) AND LYING IN\nc . THE INTERVAL 0. .le. A .lt. 8.\n dtgang = a - aref\n if (dtgang .lt. zero) dtgang = dtgang + eight\n return\n end\nc ==================================================================\n SUBROUTINE DTGADJ(TIN,NIN,X,Y,NP,TRIANG,MT,B,MB,KBNEW, OK)\nC>> 1995-09-26 CLL Editing for inclusion into MATH77.\nC\nC C.L.LAWSON, JPL, 1976 NOV 30, Changed 1977 APR 7\nC Changed 1977 June 16 to get rid of internal arrays\nc used to stack triangles to be tested.\nc\nc Given triangle TIN and the neighboring triangle that is in\nc position NIN relative to TIN, Test for possible exchange of\nc their common edge.\nc Use the criterion of maximizing the smallest angle, which is the\nc same as the criterion of the empty circumcircle.\nc If the swap is made then certain other edges must be tested.\nc This subr does the tests, swaps edges as needed, and does\nc tests and swaps on other edges as needed.\nc The counter COUNT is used to guard against infinite looping\nc which should never happen anyway. If count exceeds 100 the\nc subr sets OK = .false. indicating that the triangulation\nc produced may not be optimal.\nc ------------------------------------------------------------------\nC Subroutine Arguments\nc\nc TIN [integer, in]\nc NIN [integer, in]\nc X(),Y() [floating, in]\nc TRIANG() [integer, inout]\nc MT [integer, in]\nc B(1:4, ) [integer, inout]\nc MB [integer, in]\nc KBNEW [integer, in] Index into the boundary array, B(,).\nc OK [logical, out]\nc ------------------------------------------------------------------\n integer mb\n INTEGER ADD1(3)\n INTEGER B(4, MB), COUNT\n integer i, k, kbkwd,KBNEW, kfwd\n integer more, mt\n integer nabor1, nabor2, nin, np\n INTEGER QV1,QV2,QV3,QV4,QV1S(3),QV2S(3),QV3S(3),SUB1(3)\n INTEGER t1, T11,T12,t2, T21,T22, tin\n INTEGER TNEW, TOLD, TRI1(6),TRI2(6), TRIANG(MT)\n double precision a123, a234, a341, a412\n double precision diag13, diag24\n double precision dx12, dx23, dx34, dx41, dy12, dy23, dy34, dy41\n double precision s12, s23, s34, s41\n double precision tau13, tau24\n DOUBLE PRECISION X(NP),Y(NP)\n LOGICAL OK, SWAP\n DATA QV1S(1),QV1S(2),QV1S(3)/ 5, 6, 4/\n DATA QV2S(1),QV2S(2),QV2S(3)/ 6, 4, 5/\n DATA QV3S(1),QV3S(2),QV3S(3)/ 4, 5, 6/\n DATA ADD1(1),ADD1(2),ADD1(3)/ 2, 3, 1/\n DATA SUB1(1),SUB1(2),SUB1(3)/ 3, 1, 2/\nc ------------------------------------------------------------------\n T1=TIN\n NABOR1 = NIN\n COUNT = 1\n MORE = 1\n OK = .TRUE.\n 20 if ((MORE .gt. 0) .and. OK) then\n\n call DTGGET(T1,TRI1,TRIANG)\n T2 = TRI1(NABOR1)\n if ( T2 .ne. 0) then\nC T2=0 MEANS SIDE NABOR OF TRIANGLE T1 IS A BOUNDARY EDGE SO THERE IS NO\nC TRIANGLE T2. HERE WE HAVE T2 .ne. 0\n call DTGGET(T2,TRI2,TRIANG)\nC SET QV1,...,QV4 AS INDICES OF THE 4 VERTICES OF THE QUADRILATERAL\nC FORMED BY THE 2 TRIANGLES T1 AND T2\n I=QV1S(NABOR1)\n QV1=TRI1(I)\n I=QV2S(NABOR1)\n QV2=TRI1(I)\n I=QV3S(NABOR1)\n QV3=TRI1(I)\n do 40 NABOR2 = 1, 3\n if (TRI2(NABOR2) .eq. T1) then\n I=QV2S(NABOR2)\n QV4=TRI2(I)\n go to 50\n end if\n 40 continue\n 50 continue\n\nC The max-min angle test below is made using the max-min angle criterion\nc as described in JPL internal TECH. MEMO. 914-299, FEB., 1972 by\nc C. L. LAWSON.\nC\n DX23 = X(QV3)-X(QV2)\n DY23 = Y(QV3)-Y(QV2)\n DX34 = X(QV4)-X(QV3)\n DY34 = Y(QV4)-Y(QV3)\n A234 = DX23*DY34 - DY23*DX34\n if (A234 .le. 0.) then\n SWAP = .FALSE.\n else\n DX12 = X(QV2)-X(QV1)\n DY12 = Y(QV2)-Y(QV1)\n DX41 = X(QV1)-X(QV4)\n DY41 = Y(QV1)-Y(QV4)\n A412 = DX41*DY12 - DY41*DX12\n if (A412 .le. 0.) then\n SWAP = .FALSE.\n else\n A341 = DX34*DY41 - DY34*DX41\n A123 = A234 + A412 - A341\n S12 = DX12**2 + DY12**2\n S23 = DX23**2 + DY23**2\n S34 = DX34**2 + DY34**2\n S41 = DX41**2 + DY41**2\n DIAG13 = (X(QV3)-X(QV1))**2 + (Y(QV3)-Y(QV1))**2\n DIAG24 = (X(QV4)-X(QV2))**2 + (Y(QV4)-Y(QV2))**2\n TAU13 = min( A123**2 / max(S12,S23),\n * A341**2 / max(S34,S41)) / DIAG13\n TAU24 = min( A234**2 / max(S23,S34),\n * A412**2 / max(S41,S12)) / DIAG24\n SWAP = TAU24 .gt. TAU13\n end if\n end if\nc End of max-min angle test\n else\n SWAP = .FALSE.\n end if\n if ( SWAP) then\nc Remove the edge connecting QV1 and QV3. Insert new edge connecting\nC QV2 and QV4. Redefine triangle T1 to have vertices QV1, QV2, and\nC QV4. Redefine triangle T2 to have vertices QV2, QV3, AND QV4.\n I = ADD1(NABOR1)\n T11 = TRI1(I)\n I = ADD1(I)\n T12 = TRI1(I)\nC\n I = ADD1(NABOR2)\n T21 = TRI2(I)\n I = ADD1(I)\n T22 = TRI2(I)\nC\n call DTGSET(T1,T11,T2,T22,QV1,QV2,QV4,TRIANG,MT)\n call DTGSET(T2,T12,T21,T1,QV2,QV3,QV4,TRIANG,MT)\nC\n TNEW=T2\n if ( T12 .ne. 0) then\n call DTGGET( T12,TRI2, TRIANG)\n do 70 I = 1, 3\n if (TRI2(I) .eq. T1) then\n TRI2(I) = TNEW\n go to 80\n end if\n 70 continue\n 80 call DTGPUT( T12,TRI2, TRIANG, MT)\n else\nC The following test of (QV2 .eq. B(3, KBNEW)) will always be true if\nC the outer algorithm calling this subroutine is the one originally\nC planned, always adding new points from the exterior, not from the\nC interior. The false branch is provided to handle the more general\nc case.\n if (QV2 .eq. B(3, KBNEW) ) then\n B(4, KBNEW) = TNEW\n else\nC WRITE(6,1001) QV2,B(3, KBNEW)\nc Search alternately fwd and bkwd from KBNEW in the boundary list B()\nc for the point QV2. When found set the associated triangle to TNEW.\n KFWD = KBNEW\n KBKWD= B(2, KFWD )\n 90 continue\n if (KFWD .ne. 0) then\n if (B(3, KFWD) .eq. QV2) then\n B(4, KFWD) = TNEW\n go to 100\n end if\n KFWD = B(1, KFWD)\n end if\nC\n if (KBKWD .ne. 0) then\n if (B(3, KBKWD) .eq. QV2) then\n B(4, KBKWD) = TNEW\n go to 100\n end if\n KBKWD = B(2, KBKWD)\n end if\n go to 90\n end if\n end if\nC\n 100 TNEW=T1\n if ( T22 .ne. 0) then\n call DTGGET( T22,TRI2, TRIANG)\n DO 110 I = 1, 3\n if (TRI2(I) .eq. T2) then\n TRI2(I) = TNEW\n go to 120\n end if\n 110 continue\n 120 call DTGPUT( T22,TRI2, TRIANG, MT)\n else\nC WRITE(6,1002) QV4\nc Search alternately fwd and bkwd from KBNEW in the boundary list B()\nc for the point QV2. When found set the associated triangle to TNEW.\n KFWD = KBNEW\n KBKWD= B(2, KFWD )\n 140 continue\n if (KFWD .ne. 0) then\n if (B(3, KFWD) .eq. QV4) then\n B(4, KFWD) = TNEW\n go to 150\n end if\n KFWD = B(1, KFWD)\n end if\nC\n if (KBKWD .ne. 0) then\n if (B(3, KBKWD) .eq. QV4) then\n B(4, KBKWD) = TNEW\n go to 150\n end if\n KBKWD = B(2, KBKWD)\n end if\n go to 140\n end if\n 150 NABOR1 = 3\n MORE = MORE+1\n COUNT = COUNT+1\n OK = COUNT .le. 100\n else\n MORE = MORE-1\n if (MORE .gt. 0) then\n TOLD = T1\n I = SUB1(NABOR1)\n T1=TRI1(I)\n call DTGGET(T1,TRI1,TRIANG)\n do 160 K = 1, 3\n if (TRI1(K) .eq. TOLD) then\n NABOR1 = SUB1(K)\n go to 20\n end if\n 160 continue\n end if\n end if\n go to 20\n end if\n return\nC\nC1001 FORMAT(33H0ADJUST.. USING FIX-B WITH QV2 =,I5,5X,\nC * 12HB(3, KBNEW) =,I5)\nC1002 FORMAT(33H0ADJUST.. USING FIX-B WITH QV4 =,I5)\n end\n", "meta": {"hexsha": "9cca6b9a38e54faa2b258822f33a10f32fe77399", "size": 26131, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/dtggrd.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/dtggrd.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/dtggrd.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 36.1925207756, "max_line_length": 72, "alphanum_fraction": 0.4849412575, "num_tokens": 8472, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941962904956, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6792885883943519}} {"text": " program GF_num_inb ! Numerical calculation of the half-space\n ! electromagnetic Green's tensor\n ! by discretization of the Sommerfeld integrals\n !\n ! This program uses intrinsic Bessel functions\nc-----------------------------------------------------------------------\nc Authors:\nc George Y. Panasyuk, Vadim A. Markel, John C. Schotland\nc University of Pennsylvania\nc E-mail address for questions and comments:\nc vmarkel@mail.med.upenn.edu\nc For updates and additional info check\nc URL: http://whale.seas.upenn.edu/CODES/\nc--------------------------------------------------------------------------\n implicit none \n\n integer*4 key, nl, kl, idummy\n logical*4 logscale\n character*4 hdummy, output_prec, lambda_scale\n\n integer*8 N1, N2, N3, k\n\n real*8 ru, rz, two, three, four, half, pi, twopi, power\n real*8 lambda, lambda_max, lambda_min, dlambda, rlambda, lambda_p\n real*8 w, J0, J1, J0Hat, J1Hat\n real*8 y, y2, y3, y4, dy1, dy2, dy3, y_max\n real*8 t, gd, delta\n real*8 Rhat, Zhat_m, Zhat_p\n real*8 z1, z2, z_p, z_m, rho\n real*8 Rti, k1\n real*8 rpe, div, r_p, r_m\n real*8 xh, xh_2, zh_p, zh_p_2, zh_m, zh_m_2\n real*8 RJ01p, RJ0p, RJ1p\n real*8 DBESJ0, DBESJ1\n real*8 eps_2_r, eps_2_i, eps_1, eps0\n\n complex*16 cu, cz, eps, eps_2, eps1, kzeps\n complex*16 R, Rpr\n complex*16 c2, c3, cpe\n complex*16 J01p, J0p, J1p\n complex*16 s1xx,s1yy,s1xz,s1zz,s2xx,s2yy,s2xz,s2zz\n complex*16 sum1xz,sum2xz\n complex*16 sum1xx_a,sum1xx_b,sum1xx_c\n complex*16 sum1yy_a,sum1yy_b,sum1yy_c\n complex*16 sum1zz_a,sum1zz_b,sum1zz_c\n complex*16 sum2xx_a,sum2xx_b,sum2xx_c\n complex*16 sum2yy_a,sum2yy_b,sum2yy_c\n complex*16 sum2zz_a,sum2zz_b,sum2zz_c\n complex*16 Gxx1a,Gxx1b,Gxx2a1,Gxx2a2,Gxx2ah,Gxx2bh,Gxx2b1,Gxx2b2\n complex*16 Gyy1a,Gyy1b,Gyy2a1,Gyy2a2,Gyy2ah,Gyy2bh,Gyy2b1,Gyy2b2\n complex*16 Gzz1,Gzz2b1,Gzz2b2,Gzz2\n complex*16 Gxz1,Gxz2a1,Gxz2a2,Gxz2\n complex*16 GTxx,GTyy,GTzz,GTxz,GTzx\n complex*16 GFxx,GFyy,GFzz,GFxz,GFzx\n complex*16 GRxx,GRyy,GRzz,GRxz,GRzx\n\nc\nc------ Mathematical constants ------------------------------------\nc\n rz = 0.0d0\n ru = 1.0d0\n cz = (0.0d0,0.0d0)\n cu = (0.0d0,1.0d0)\n two = 2.0d0\n three = 3.0d0\n four = 4.0d0\n half = 0.5d0\n pi = two*dasin(1.0d0)\n twopi = two*pi\n delta = 1.d-100\nc\nc---------- Reading input parameters -----------------------------------\nc\n open(unit=70, file='GF.par', status='old', err=101)\n read(70,*) hdummy\n read(70,*) hdummy\n\n read(70,*) key\n if(key .eq. 0) then\n write(*,*) 'Assuming a metallic substrate'\n write(*,*) 'Drude formula will be used for eps_2'\n else if (key .eq. 1) then\n write(*,*) 'Assuming that the substrate has a'\n write(*,*) ' ... wavelength-independent permittivity'\n write(*,*) ' ... eps_2 = eps_2_r + i*eps_2_i'\n write(*,*) ' ... where eps_2_r, eps_2_i are given in GF.par'\n write(*,*) 'If you dont like this, use KEY=2'\n write(*,*) ' ... and program your own formula for eps_2'\n else if (key .eq. 2) then\n write(*,*) 'KEY=2 is used for user-defined permittivity'\n write(*,*) 'This option requires additional programming'\n write(*,*) 'But this has not been done so far'\n write(*,*) 'Go to the line \"if(key .eq. 2)\" below'\n write(*,*) ' ...and add your code directly after that line'\n write(*,*) 'Then comment this message out'\n write(*,*) 'For now, I am exiting. Goodby'\n stop\n else \n write(*,*) 'Error. Incorrect parameter: KEY=', key\n write(*,*) 'KEY is allowed to take only the values 0,1,2'\n write(*,*) 'Correct the error in GF.par and try again'\n stop\n end if\n\n read(70,*) idummy\n\n read(70,2) output_prec\n if(output_prec .eq. 'S') goto 3\n if(output_prec .eq. 's') goto 3\n if(output_prec .eq. 'D') goto 3\n if(output_prec .eq. 'd') goto 3\n write(*,*) 'Incorrect parameter OUTPUT_PREC'\n write(*,*) 'Only chars S, s, D, d are allowed'\n write(*,*) 'Correct the error in GF.par and try again'\n stop\n 3 continue\n\n read(70,4) lambda_scale\n if(lambda_scale .eq. 'LOG') goto 5\n if(lambda_scale .eq. 'log') goto 5\n if(lambda_scale .eq. 'LIN') goto 5\n if(lambda_scale .eq. 'lin') goto 5\n write(*,*) 'Incorrect parameter LAMBDA_SCALE'\n write(*,*) 'Only \"LOG\", \"log\", \"LIN\", \"lin\" are allowed'\n write(*,*) 'Correct the error in GF.par and try again'\n stop\n 5 continue\n\n read(70,*) lambda_min, lambda_max, nl\n write(*,*) 'lambda_min,lambda_max:', sngl(lambda_min), \n $ sngl(lambda_max), ' [nm]'\n write(*,*) 'nl:', nl\n if(lambda_min.lt.rz) then\n write(*,*) 'Error. Incorrect parameters: lambda_min<0'\n write(*,*) 'Correct the error in GF.par and try again'\n stop\n else if(lambda_min.gt.lambda_max) then\n write(*,*) 'Error. Incorrect parameters: lambda_min>lambda_max'\n write(*,*) 'Correct the error in GF.par and try again'\n stop\n else if((lambda_min.eq.lambda_max) .and. (nl.ne.1) ) then\n write(*,*) 'Warning. lambda_min=lambda_max but nl=/=1'\n write(*,*) 'Setting nl=1 and continuing'\n nl=1\n else if((lambda_min .lt. lambda_max) .and. (nl.lt.2)) then\n write(*,*) 'Warning. lambda_min=0.002 (the value for Ag)'\n end if\n\n read(70,*) eps0\n\n read(70,*) eps_1\n if(eps_1.le.rz) then\n write(*,*) 'Error. Incorrect parameter: eps_1<=0; eps_1=', \n $ eps_1\n write(*,*) 'Correct the error in GF.par and try again'\n stop\n end if\n\n read(70,*) N1\n read(70,*) N2\n read(70,*) N3\n if(N1.lt.10) then\n write(*,*) 'Error. Incorrect parameter: N1<10; N1=', N1\n write(*,*) 'Correct the error in GF.par and try again'\n stop\n end if\n if(N2.lt.10) then\n write(*,*) 'Error. Incorrect parameter: N2<10; N2=', N2\n write(*,*) 'Correct the error in GF.par and try again'\n stop\n end if\n if(N3.lt.10) then\n write(*,*) 'Error. Incorrect parameter: N2<10; N2=', N2\n write(*,*) 'Correct the error in GF.par and try again'\n stop\n end if\n if((N1 .ne. N2) .or. (N1 .ne. N3)) then\n write(*,*) 'You are using different values for N1,N2,N3'\n write(*,*) 'Are you sure you know what you are doing?'\n end if\n \n read(70,*) y_max, div\n if(y_max.le.rz) then\n write(*,*) 'Error. Incorrect parameter: y_max<=0; y_max=', \n $ y_max\n write(*,*) 'Correct the error in GF.par and try again'\n stop\n end if\n if(div.le.rz) then\n write(*,*) 'Error. Incorrect parameter: div<=0; div=', div\n write(*,*) 'Correct the error in GF.par and try again'\n stop\n end if\n \n close(unit=70)\nc\nc------- End reading parameters -----------------------------\nc\n\n\nc\nc------- Input-dependent constants --------------------------\nc\n if(nl .gt. 1) then\n dlambda = (lambda_max - lambda_min)/dfloat(nl-1)\n else\n dlambda = rz\n end if\n\n z_p = z2 + z1\n z_m = z2 - z1\n r_p = dsqrt(rho*rho + z_p*z_p)\n r_m = dsqrt(rho*rho + z_m*z_m)\n zh_p = z_p/r_p\n zh_p_2 = zh_p*zh_p\n zh_m = z_m/r_m ! used only for G^F\n zh_m_2 = zh_m*zh_m\n xh = rho/r_m ! used only for G^F\n xh_2 = xh*xh\n\n N1 = 2*(N1/2)\n N2 = 2*(N2/2)\n N3 = 2*(N3/2)\n dy1 = ru/dfloat(N1)\n dy2 = div/dfloat(N2)\n dy3 = (y_max-div) / dfloat(N3)\n\n logscale = .false.\n if(lambda_scale .eq. 'LOG') logscale=.true.\n if(lambda_scale .eq. 'log') logscale=.true.\n if(logscale) then\n if(lambda_min .eq. rz) then\n write(*,*) 'If using logscale, lambda_min=0 is not allowed'\n write(*,*) 'Correct GF.par and try again; exiting'\n stop\n end if\n rlambda = lambda_max/lambda_min\n end if\nc\nc-------- End input-dependent constants block ------------------------\nc\n open(71, file='GRxx_num', status='unknown', err=102)\n open(72, file='GRyy_num', status='unknown', err=102)\n open(73, file='GRzz_num', status='unknown', err=102)\n open(74, file='GRxz_num', status='unknown', err=102)\n open(75, file='GRzx_num', status='unknown', err=102)\n\n open(76, file='GTxx_num', status='unknown', err=102)\n open(77, file='GTyy_num', status='unknown', err=102)\n open(78, file='GTzz_num', status='unknown', err=102)\n open(79, file='GTxz_num', status='unknown', err=102)\n open(80, file='GTzx_num', status='unknown', err=102)\nc\nc------- Start loop over wavelengths ---------------------------------\nc\n do 1, kl=1,nl\n if(logscale) then\n power = dfloat(kl-1)/dfloat(nl-1)\n lambda = lambda_min * rlambda**power\n else\n lambda = lambda_min + dlambda*dfloat(kl-1) \n end if\n write(*,*) kl, ': lambda=', sngl(lambda), '[nm]'\n\n k1 = twopi*dsqrt(eps_1)/lambda\n\n if(key .eq. 0) then\n t = lambda_p/lambda\n eps_2 = eps0 - ru/t/(t + cu*gd)\n else if(key .eq. 1) then\n eps_2 = eps_2_r + cu*eps_2_i\n else if(key .eq. 2) then\n ! Enter your own formula for eps_2 here\n continue\n ! Do not edit past this line\n else\n write(*,*) 'Unexpected error 1; exiting'\n write(*,*) 'Please report this error to code developers'\n stop\n end if \n \n eps_2 = dreal(eps_2) + cu*max(delta,dimag(eps_2))\n eps = eps_2/eps_1\n eps1 = eps - ru\n\n Zhat_p = k1*z_p ! Used for G^R\n Zhat_m = k1*z_m ! Used for G^F\n Rhat = k1*rho \n Rti = dsqrt(Rhat*Rhat + Zhat_m*Zhat_m) ! Argument for G^F\n\n J0Hat = DBESJ0(Rhat)\n J1Hat = DBESJ1(Rhat)/Rhat\nc\nc-------- Integrals over the finite interval (0,1) ---------\nc dy = dy1 = 1/N1 \nc\n s2xx = -J1Hat \n s2yy = rz \n s2zz = J0Hat \n s2xz = rz \n\n kzeps = cdsqrt(eps1 + ru)\n R = (ru-kzeps) /(ru+kzeps)\n Rpr = (kzeps-eps)/(kzeps+eps)\n cpe = half*cdexp(cu*Zhat_p)\n s1xx = s2xx + cpe*R \n s1yy = s2yy + cpe*Rpr \n s1zz = s2zz \n s1xz = s2xz \n\n sum1xx_a = cz\n sum1yy_a = cz\n sum1zz_a = cz\n sum1xx_b = cz\n sum1yy_b = cz\n sum1xz = cz\n do 11,k=1,N1-1,2\n y = k*dy1\n y2 = y*y\n y3 = ru-y2\n y4 = y*y3\n kzeps = cdsqrt(eps1 + y2)\n R = (y-kzeps)/(y+kzeps)\n Rpr = (kzeps-eps*y)/(kzeps+eps*y)\n cpe = cdexp(cu*y*Zhat_p)\n w = Rhat*dsqrt(y3)\n J0 = DBESJ0(w)\n J1 = DBESJ1(w)/w\n J01p = (J0-J1)*cpe\n J1p = J1*cpe\n J0p = J0*cpe\n sum1xx_a = sum1xx_a + J1p * R\n sum1yy_a = sum1yy_a + J1p * Rpr * y2\n sum1zz_a = sum1zz_a + J0p * Rpr * y3\n sum1xx_b = sum1xx_b + J01p * Rpr * y2\n sum1yy_b = sum1yy_b + J01p * R\n sum1xz = sum1xz + J1p * Rpr * y4\n 11 continue\n\n sum2xx_a = cz\n sum2yy_a = cz\n sum2zz_a = cz\n sum2xx_b = cz\n sum2yy_b = cz\n sum2xz = cz\n do 12, k=2,N1-2,2\n y = k*dy1\n y2 = y*y\n y3 = ru-y2\n y4 = y*y3\n kzeps = cdsqrt(eps1 + y2)\n R = (y-kzeps)/(y+kzeps)\n Rpr = (kzeps-eps*y)/(kzeps+eps*y)\n cpe = cdexp(cu*y*Zhat_p)\n w = Rhat*dsqrt(y3)\n J0 = DBESJ0(w)\n J1 = DBESJ1(w)/w\n J01p = (J0-J1)*cpe\n J1p = J1*cpe\n J0p = J0*cpe\n sum2xx_a = sum2xx_a + J1p * R \n sum2yy_a = sum2yy_a + J1p * Rpr * y2\n sum2zz_a = sum2zz_a + J0p * Rpr * y3\n sum2xx_b = sum2xx_b + J01p * Rpr * y2\n sum2yy_b = sum2yy_b + J01p * R\n sum2xz = sum2xz + J1p * Rpr * y4\n 12 continue\n\n Gxx1a = dy1*(two*sum2xx_a + four*sum1xx_a + s1xx)/three\n Gyy1a = dy1*(two*sum2yy_a + four*sum1yy_a + s1yy)/three\n Gzz1 = dy1*(two*sum2zz_a + four*sum1zz_a + s1zz)/three\n Gxz1 = dy1*(two*sum2xz + four*sum1xz + s1xz)/three\n \n s2xx = rz\n s2yy = J1Hat-J0Hat\n\n kzeps = cdsqrt(eps1 + ru)\n Rpr = (kzeps-eps)/(kzeps+eps)\n R = (ru-kzeps)/(ru+kzeps)\n cpe = half*cdexp(cu*Zhat_p)\n s1xx = s2xx + cpe*Rpr\n s1yy = s2yy + cpe*R\n\n Gxx1b = dy1*(two*sum2xx_b + four*sum1xx_b + s1xx)/three\n Gyy1b = dy1*(two*sum2yy_b + four*sum1yy_b + s1yy)/three\nc\nc-------- Integrals over the infinite interval (0,Inf) ---------\nc-------- The integlas is broken in two parts ------------------\nc-------- a) First, compute over the interval (0,div)\nc dy = dy2 = div/N2\nc\n s2xx = -J1Hat\n s2yy = rz\n s2xz = rz\n\n y = div\n y2 = y*y\n rpe = dexp(-y*Zhat_p)\n kzeps = cdsqrt(y2-eps1)\n R = (y-kzeps)/(y+kzeps)\n Rpr = (kzeps-eps*y)/(kzeps+eps*y)\n w = Rhat*dsqrt(ru+y2)\n J1 = DBESJ1(w)/w\n s1xx = s2xx + rpe*J1*R\n s1yy = s2yy + y2*rpe*J1*Rpr\n s1xz = s2xz + y*(y2+ru)*rpe*J1*Rpr\n\n sum1xx_a = cz\n sum1yy_a = cz\n sum1xx_b = cz\n sum1yy_b = cz\n sum1zz_b = cz\n sum1xz = cz\n do 21, k = 1, N2-1, 2\n y = k*dy2\n y2 = y*y\n y3 = ru+y2\n y4 = y*y3\n rpe = dexp(-y*Zhat_p)\n kzeps = cdsqrt(y2-eps1)\n R = (y-kzeps)/(y+kzeps)\n Rpr = (kzeps-eps*y)/(kzeps+eps*y)\n w = Rhat*dsqrt(y3)\n J0 = DBESJ0(w)\n J1 = DBESJ1(w)/w\n RJ01p = (J0-J1)*rpe\n RJ1p = J1*rpe\n RJ0p = J0*rpe\n sum1xx_a = sum1xx_a + RJ1p * R\n sum1yy_a = sum1yy_a + RJ1p * Rpr * y2\n sum1xx_b = sum1xx_b + RJ01p * Rpr * y2\n sum1yy_b = sum1yy_b + RJ01p * R\n sum1zz_b = sum1zz_b + RJ0p * Rpr * y3\n sum1xz = sum1xz + RJ1p * Rpr * y4 \n 21 continue\n\n sum2xx_a = cz\n sum2yy_a = cz\n sum2xx_b = cz\n sum2yy_b = cz\n sum2zz_b = cz\n sum2xz = cz\n do 22, k = 2, N2-2, 2\n y = k*dy2\n y2 = y*y\n y3 = ru+y2\n y4 = y*y3\n rpe = dexp(-y*Zhat_p)\n kzeps = cdsqrt(y2-eps1)\n R = (y-kzeps)/(y+kzeps)\n Rpr = (kzeps-eps*y)/(kzeps+eps*y)\n w = Rhat*dsqrt(y3)\n J0 = DBESJ0(w)\n J1 = DBESJ1(w)/w\n RJ01p = (J0-J1)*rpe\n RJ1p = J1*rpe\n RJ0p = J0*rpe\n sum2xx_a = sum2xx_a + RJ1p * R\n sum2yy_a = sum2yy_a + RJ1p * Rpr * y2\n sum2xx_b = sum2xx_b + RJ01p * Rpr * y2\n sum2yy_b = sum2yy_b + RJ01p * R\n sum2zz_b = sum2zz_b + RJ0p * Rpr * y3\n sum2xz = sum2xz + RJ1p * Rpr * y4\n 22 continue\n\n Gxx2a1 = dy2*(two*sum2xx_a + four*sum1xx_a + s1xx)/three\n Gyy2a1 = dy2*(two*sum2yy_a + four*sum1yy_a + s1yy)/three\n Gxz2a1 = dy2*(two*sum2xz + four*sum1xz + s1xz)/three\nc\nc-------- Integrals over the infinite interval (0,Inf) ---------\nc-------- The integlas is broken in two parts ------------------\nc-------- b) Second part, compute over the interval (div,y_max)\nc dy = dy3 = (y_max-div)/N3\nc\n y = div\n y2 = y*y\n rpe = dexp(-y*Zhat_p)\n kzeps = cdsqrt(y2-eps1)\n R = (y-kzeps)/(y+kzeps)\n Rpr = (kzeps-eps*y)/(kzeps+eps*y)\n w = Rhat*dsqrt(ru+y2)\n J1 = DBESJ1(w)/w\n s2xx = rpe*J1*R\n s2yy = y2*rpe*J1*Rpr\n s2xz = y*(y2+ru)*rpe*J1*Rpr\n\n y = y_max\n y2 = y*y\n rpe = dexp(-y*Zhat_p)\n kzeps = cdsqrt(y2-eps1)\n R = (y-kzeps)/(y+kzeps)\n Rpr = (kzeps-eps*y)/(kzeps+eps*y)\n w = Rhat*dsqrt(ru+y2)\n J1 = DBESJ1(w)/w\n s1xx = s2xx + rpe*J1*R\n s1yy = s2yy + y2*rpe*J1*Rpr\n s1xz = s2xz + y*(y2+ru)*rpe*J1*Rpr\n\n sum1xx_a = cz\n sum1yy_a = cz\n sum1xz = cz\n sum1xx_c = cz\n sum1yy_c = cz\n sum1zz_c = cz\n do 31, k = 1, N3-1, 2\n y = div + k*dy3\n y2 = y*y\n y3 = ru+y2\n y4 = y*y3\n rpe = dexp(-y*Zhat_p)\n kzeps = cdsqrt(y2-eps1)\n R = (y-kzeps)/(y+kzeps)\n Rpr = (kzeps-eps*y)/(kzeps+eps*y)\n w = Rhat*dsqrt(y3)\n J0 = DBESJ0(w)\n J1 = DBESJ1(w)/w\n RJ01p = (J0-J1)*rpe\n RJ1p = J1*rpe\n RJ0p = J0*rpe\n sum1xx_a = sum1xx_a + RJ1p * R\n sum1yy_a = sum1yy_a + RJ1p * Rpr * y2\n sum1xz = sum1xz + RJ1p * Rpr * y4\n sum1xx_c = sum1xx_c + RJ01p * Rpr * y2\n sum1yy_c = sum1yy_c + RJ01p * R\n sum1zz_c = sum1zz_c + RJ0p * Rpr * y3\n 31 continue\n \n sum2xx_a = cz\n sum2yy_a = cz\n sum2xz = cz\n sum2xx_c = cz\n sum2yy_c = cz\n sum2zz_c = cz\n do 32, k = 2, N3-2, 2\n y = div + k*dy3\n y2 = y*y\n y3 = ru+y2\n y4 = y*y3\n rpe = dexp(-y*Zhat_p)\n kzeps = cdsqrt(y2-eps1)\n R = (y-kzeps)/(y+kzeps)\n Rpr = (kzeps-eps*y)/(kzeps+eps*y)\n w = Rhat*dsqrt(y3)\n J0 = DBESJ0(w)\n J1 = DBESJ1(w)/w\n RJ01p = (J0-J1)*rpe\n RJ1p = J1*rpe\n RJ0p = J0*rpe\n sum2xx_a = sum2xx_a + RJ1p * R\n sum2yy_a = sum2yy_a + RJ1p * Rpr * y2\n sum2xz = sum2xz + RJ1p * Rpr * y4\n sum2xx_c = sum2xx_c + RJ01p * Rpr * y2\n sum2yy_c = sum2yy_c + RJ01p * R \n sum2zz_c = sum2zz_c + RJ0p * Rpr * y3\n 32 continue\n\n Gxx2a2 = dy3*(two*sum2xx_a + four*sum1xx_a + s1xx)/three\n Gyy2a2 = dy3*(two*sum2yy_a + four*sum1yy_a + s1yy)/three\n Gxz2a2 = dy3*(two*sum2xz + four*sum1xz + s1xz)/three\n Gxx2ah = Gxx2a1 + Gxx2a2\n Gyy2ah = Gyy2a1 + Gyy2a2\n Gxz2 = Gxz2a1 + Gxz2a2\n\n s2xx = rz\n s2yy = J1Hat - J0Hat\n s2zz = J0Hat\n\n y = div\n y2 = y*y\n rpe = dexp(-y*Zhat_p)\n kzeps = cdsqrt(y2-eps1)\n Rpr = (kzeps-eps*y)/(kzeps+eps*y)\n R = (y-kzeps)/(y+kzeps)\n w = Rhat*dsqrt(ru+y2)\n J0 = DBESJ0(w)\n J1 = DBESJ1(w)/w\n s1xx = s2xx + y2*rpe*Rpr*(J0-J1)\n s1yy = s2yy + rpe*R*(J0-J1)\n s1zz = s2zz + (y2+ru)*rpe*Rpr*J0\n\n Gxx2b1 = dy2*(two*sum2xx_b + four*sum1xx_b + s1xx)/three\n Gyy2b1 = dy2*(two*sum2yy_b + four*sum1yy_b + s1yy)/three\n Gzz2b1 = dy2*(two*sum2zz_b + four*sum1zz_b + s1zz)/three\n\n y = div\n y2 = y*y\n rpe = dexp(-y*Zhat_p)\n kzeps = cdsqrt(y2-eps1)\n Rpr = (kzeps-eps*y)/(kzeps+eps*y)\n R = (y-kzeps)/(y+kzeps)\n w = Rhat*dsqrt(ru+y2)\n J0 = DBESJ0(w)\n J1 = DBESJ1(w)/w\n s2xx = y2*rpe*Rpr*(J0-J1)\n s2yy = rpe*R*(J0-J1)\n s2zz = (y2+ru)*rpe*Rpr*J0\n\n y = y_max\n y2 = y*y\n rpe = dexp(-y*Zhat_p)\n kzeps = cdsqrt(y2-eps1)\n Rpr = (kzeps-eps*y)/(kzeps+eps*y)\n R = (y-kzeps)/(y+kzeps)\n w = Rhat*dsqrt(ru+y2)\n J0 = DBESJ0(w)\n J1 = DBESJ1(w)/w\n s1xx = s2xx + y2*rpe*Rpr*(J0-J1)\n s1yy = s2yy + rpe*R*(J0-J1)\n s1zz = s2zz + (y2+ru)*rpe*Rpr*J0\n\n Gxx2b2 = dy3*(two*sum2xx_c + four*sum1xx_c + s1xx)/three\n Gyy2b2 = dy3*(two*sum2yy_c + four*sum1yy_c + s1yy)/three\n Gzz2b2 = dy3*(two*sum2zz_c + four*sum1zz_c + s1zz)/three\n\n Gxx2bh = Gxx2b1 + Gxx2b2\n Gyy2bh = Gyy2b1 + Gyy2b2\n Gzz2 = Gzz2b1 + Gzz2b2\n\nc Dimensionless G^R/k1**3\n GRxx = cu*(Gxx1a + Gxx1b) + Gxx2ah - Gxx2bh\n GRyy = cu*(Gyy1a + Gyy1b) + Gyy2bh - Gyy2ah\n GRzz = -cu*Gzz1 - Gzz2\n GRxz = -Rhat*(Gxz1 + Gxz2)\n GRzx = -GRxz\n\nc Dimensionless G^F/k1**3\n c2 = cdexp(cu*Rti)/Rti \n c3 = (cu - ru/Rti)/Rti\n GFxx = c2*(ru - xh_2 + c3*(ru - three*xh_2)) \n GFyy = c2*(ru + c3) \n GFzz = c2*(ru - zh_m_2 + c3*(ru-three*zh_m_2))\n GFxz = c2*xh*zh_m*(three*c3 + ru)\n GFzx = GFxz\n\nc Dimensionless G^T/k1**3, where G^T=G^F+G^R\n GTxx = GRxx + GFxx\n GTyy = GRyy + GFyy \n GTzz = GRzz + GFzz \n GTxz = GRxz + GFxz \n GTzx = GRzx + GFzx\n\n if((output_prec.eq.'S') .or. (output_prec.eq.'s')) then \n\n write(71,6,err=102) sngl(lambda),\n $ sngl(dreal(GRxx)), sngl(dimag(GRxx))\n write(72,6,err=102) sngl(lambda), \n $ sngl(dreal(GRyy)), sngl(dimag(GRyy))\n write(73,6,err=102) sngl(lambda), \n $ sngl(dreal(GRzz)), sngl(dimag(GRzz))\n write(74,6,err=102) sngl(lambda), \n $ sngl(dreal(GRxz)), sngl(dimag(GRxz))\n write(75,6,err=102) sngl(lambda), \n $ sngl(dreal(GRzx)), sngl(dimag(GRzx))\n\n\n write(76,6,err=102) sngl(lambda), \n $ sngl(dreal(GTxx)), sngl(dimag(GTxx))\n write(77,6,err=102) sngl(lambda), \n $ sngl(dreal(GTyy)), sngl(dimag(GTyy))\n write(78,6,err=102) sngl(lambda), \n $ sngl(dreal(GTzz)), sngl(dimag(GTzz))\n write(79,6,err=102) sngl(lambda), \n $ sngl(dreal(GTxz)), sngl(dimag(GTxz))\n write(80,6,err=102) sngl(lambda), \n $ sngl(dreal(GTzx)), sngl(dimag(GTzx))\n\n else if((output_prec.eq.'D') .or. (output_prec.eq.'d')) then\n\n write(71,8,err=102) sngl(lambda), dreal(GRxx), dimag(GRxx)\n write(72,8,err=102) sngl(lambda), dreal(GRyy), dimag(GRyy)\n write(73,8,err=102) sngl(lambda), dreal(GRzz), dimag(GRzz)\n write(74,8,err=102) sngl(lambda), dreal(GRxz), dimag(GRxz)\n write(75,8,err=102) sngl(lambda), dreal(GRzx), dimag(GRzx)\n\n write(76,8,err=102) sngl(lambda), dreal(GTxx), dimag(GTxx)\n write(77,8,err=102) sngl(lambda), dreal(GTyy), dimag(GTyy)\n write(78,8,err=102) sngl(lambda), dreal(GTzz), dimag(GTzz)\n write(79,8,err=102) sngl(lambda), dreal(GTxz), dimag(GTxz)\n write(80,8,err=102) sngl(lambda), dreal(GTzx), dimag(GTzx)\n\n else\n\n write(*,*) 'Unexpected error 2; exiting'\n write(*,*) 'Please report this error to code developers'\n stop\n\n end if\n\nc$$$ These lines to be used for debugging only\nc$$$ write(*,*) '-----------------------------------------'\nc$$$ write(*,*) 'XX-I:', dimag(GRxx) \nc$$$ write(*,*) 'XX-R:', dreal(GRxx) \nc$$$ write(*,*) 'YY-I:', dimag(GRyy) \nc$$$ write(*,*) 'YY-R:', dreal(GRyy) \nc$$$ write(*,*) 'ZZ-I:', dimag(GRzz) \nc$$$ write(*,*) 'ZZ-R:', dreal(GRzz) \nc$$$ write(*,*) 'XZ-I:', dimag(GRxz) \nc$$$ write(*,*) 'XZ-R:', dreal(GRxz) \n\n 1 continue\n close(unit=71)\n close(unit=72)\n close(unit=73)\n close(unit=74)\n close(unit=75)\n close(unit=76)\n close(unit=77)\n close(unit=78)\n close(unit=79)\n close(unit=80)\n\n stop\n\n 101 continue\n write(*,*) 'Error opening input file GF.par; exiting'\n stop\n\n 102 continue\n write(*,*) 'Error opening an output file or writing data; exiting'\n stop\n\n 2 format(a1)\n 4 format(a3)\n 6 format(3G16.7E3)\n 8 format(3G23.14E3)\n\n end\n", "meta": {"hexsha": "2a0ba72a2f9d89d64e2d99bef28c70174bd88958", "size": 25582, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/dipole_over_dielectric/GF_LIB/GF_num_inb.f", "max_stars_repo_name": "Riarrieta/WindowedGreenFunctionMethod", "max_stars_repo_head_hexsha": "e6f965cac1acd8d9922e2bf94c33e3577ceb0dc9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/dipole_over_dielectric/GF_LIB/GF_num_inb.f", "max_issues_repo_name": "Riarrieta/WindowedGreenFunctionMethod", "max_issues_repo_head_hexsha": "e6f965cac1acd8d9922e2bf94c33e3577ceb0dc9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/dipole_over_dielectric/GF_LIB/GF_num_inb.f", "max_forks_repo_name": "Riarrieta/WindowedGreenFunctionMethod", "max_forks_repo_head_hexsha": "e6f965cac1acd8d9922e2bf94c33e3577ceb0dc9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.9664948454, "max_line_length": 75, "alphanum_fraction": 0.502579939, "num_tokens": 9436, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299570920386, "lm_q2_score": 0.7341195385342971, "lm_q1q2_score": 0.6792293891385149}} {"text": "******************************************************************\n SUBROUTINE GAUSSL(X,W,M)\nc a slightly modified version of a program in Numerical Recipes \nc (Cambridge Univ. Press, 1989)\nc input:\nc m = number of gaussian latitudes between pole and equator\nc output:\nc x(m) = sin(gaussian latitude) \nc w(m) = weights in gaussian quadrature (sum should equal 1.0)\n DOUBLE PRECISION Z,Z1,P1,P2,P3,PP,EPS\n DIMENSION X(M),W(M)\n PARAMETER (EPS=3.D-14)\n N=2*M\n DO 12 I=1,M\n Z=COS(3.141592654D0*(I-.25D0)/(N+.5D0))\n 1 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\n 11 CONTINUE\n PP=N*(Z*P1-P2)/(Z*Z-1.D0)\n Z1=Z\n Z=Z1-P1/PP\n IF(ABS(Z-Z1).GT.EPS) GO TO 1\n X(I)=Z\n W(I)=2.D0/((1.D0-Z*Z)*PP*PP)\n 12 CONTINUE\n RETURN\n END\n****************************************************************\n SUBROUTINE PARMTR(A)\n\n include \"atparam.h\"\nc include \"param1spec.h\"\n include \"com_spectral.h\"\n\nc initializes Legendre transforms and constants used for other\nc subroutines that manipulate spherical harmonics\nc\nc input: A = radius of the sphere\nc first compute Gaussian latitudes and weights at the IY points from \nc pole to equator\nc SIA(IY) is sin of latitude, WT(IY) are Gaussian weights for quadratures,\nc saved in COMMON/GAUSS (com_spectral.h)\n CALL GAUSSL(SIA,WT,IY)\n AM1 = 1./A\n AM2= 1./(A*A)\nc COA(IY) = cos(lat); WGHT needed for transforms, \nc saved in COMMON/GAUSS (com_spectral.h)\n DO 1 J=1,IY\n COSQR = 1.0-SIA(J)**2\n COA(J)=SQRT(COSQR)\n WGHT(J)=WT(J)/(A*COSQR)\n 1 CONTINUE\nc expand cosine and its reciprocal to cover both hemispheres, \nc saved in COMMON/GAUSS (com_spectral.h)\n DO 11 J=1,IY\n JJ=IL+1-J\n COSG(J)=COA(J)\n COSG(JJ)=COA(J)\n COSGR(J)=1./COA(J)\n COSGR(JJ)=1./COA(J)\n COSGR2(J)=1./(COA(J)*coa(j))\n COSGR2(JJ)=1./(COA(J)*coa(j))\n 11 CONTINUE\nc MM = zonal wavenumber = m\nc ISC=3 implies that only wavenumber 0,3,6,9,etc are included in model\nc LL = total wavenumber of spherical harmonic = l\nc L2 = l*(l+1)\nc EL2 = l*(l+1)/(a**2)\nc EL4 = EL2*EL2 ; for biharmonic diffusion\nc ELM2 = 1./EL2\nc TRFILT used to filter out \"non-triangular\" part of rhomboidal truncation\nc saved in COMMON/CSPEC (com_spectral.h)\n\n DO 2 N=1,NX\n nsh2(n)=0\n DO 2 M=1,MX\n MM(M)=ISC*(M-1)\n LL(M,N)=MM(M)+N-1\n L2(M,N)=LL(M,N)*(LL(M,N)+1)\n EL2(M,N)=FLOAT(L2(M,N))*AM2\n EL4(M,N)=EL2(M,N)*EL2(M,N)\n if (ll(m,n).le.ntrun1.or.ix.ne.4*iy) nsh2(n)=nsh2(n)+2\n if (ll(m,n).le.ntrun) then\n trfilt(m,n)=1.\n else\n trfilt(m,n)=0.\n endif\n 2 CONTINUE\n ELM2(1,1)=0.\n DO 3 M=2,MX\n DO 3 N=1,NX\n ELM2(M,N)=1./EL2(M,N)\n 3 CONTINUE\n DO 4 N=2,NX\n ELM2(1,N)=1./EL2(1,N)\n 4 CONTINUE\n\nc quantities needed to generate and differentiate Legendre polynomials\nc all m values up to MXP = ISC*MTRUN+1 are needed by recursion relation \nc saved in COMMON/LGND (com_spectral.h)\n DO 10 M=1,MXP\n DO 10 N=1,NXP\n EMM(M)=FLOAT(M-1)\n ELL(M,N)=FLOAT(N+M-2)\n EMM2=EMM(M)**2\n ELL2=ELL(M,N)**2\n IF(N.EQ.NXP) THEN\n EPSI(M,N)=0.0\n ELSE IF(N.EQ.1.AND.M.EQ.1) THEN\n EPSI(M,N)=0.0\n ELSE\n EPSI(M,N)=SQRT((ELL2-EMM2)/(4.*ELL2-1.))\n ENDIF\n REPSI(M,N)=0.0\n IF(EPSI(M,N).GT.0.) REPSI(M,N)=1./EPSI(M,N)\n 10 CONTINUE\n SQRHLF=SQRT(.5)\n DO 20 M=2,MXP\n CONSQ(M) = SQRT(.5*(2.*EMM(M)+1.)/EMM(M))\n 20 CONTINUE\nc quantities required by subroutines GRAD, UVSPEC, and VDS\nc saved in COMMON/UV, COMMON/GRADC, and COMMON/VDS (com_spectral.h)\n DO 15 M=1,MX\n DO 15 N=1,NX\n M1=MM(M)\n M2=M1+1\n EL1=FLOAT(LL(M,N))\n IF(N.EQ.1) THEN\n GRADX(M)=FLOAT(M1)/A\n UVDX(M,1)=-A/FLOAT(M1+1)\n UVDYM(M,1)=0.0\n VDDYM(M,1)=0.0\n ELSE\n UVDX(M,N)=-A*FLOAT(M1)/(EL1*(EL1+1))\n GRADYM(M,N)=(EL1-1.)*EPSI(M2,N)/A\n UVDYM(M,N)=-A*EPSI(M2,N)/EL1\n VDDYM(M,N)=(EL1+1)*EPSI(M2,N)/A\n ENDIF\n GRADYP(M,N)=(EL1+2.)*EPSI(M2,N+1)/A\n UVDYP(M,N)=-A*EPSI(M2,N+1)/(EL1+1.)\n VDDYP(M,N)=EL1*EPSI(M2,N+1)/A\n 15 CONTINUE\nc generate associated Legendre polynomial\nc LGNDRE computes the polynomials at a particular latitiude, POLY(MX,NX), and stores\nc them in COMMON/POL (com_spectral.h)\nc polynomials and 'clones' stored in COMMON/POL1 (com_spectral.h)\n DO 30 J=1,IY\n CALL LGNDRE(J)\n DO 51 N=1,NX\n DO 51 M=1,MX\n M1=2*M-1\n M2=2*M\n CPOL(M1,N,J)=POLY(M,N)\n CPOL(M2,N,J)=POLY(M,N)\n 51 CONTINUE\n 30 CONTINUE\n RETURN\n END\n****************************************************************\n SUBROUTINE LGNDRE(J)\nc follows Leith Holloways code \n\n include \"atparam.h\"\nc include \"param1spec.h\"\n PARAMETER (SMALL = 1.E-30)\n include \"com_spectral.h\"\n\n DIMENSION ALP(MXP,NX)\n Y = COA(J)\n X = SIA(J)\nc start recursion with N=1 (M=L) diagonal \n ALP(1,1) = SQRHLF\n DO 31 M=2,MXP\n ALP(M,1) = CONSQ(M)*Y*ALP(M-1,1)\n 31 CONTINUE\nc continue with other elements\n DO 32 M=1,MXP\n ALP(M,2)=(X*ALP(M,1))*REPSI(M,2)\n 32 CONTINUE\n DO 33 N=3,NX\n DO 33 M=1,MXP\n ALP(M,N)=(X*ALP(M,N-1)-EPSI(M,N-1)*ALP(M,N-2))*REPSI(M,N)\n 33 CONTINUE\nc zero polynomials with absolute values smaller than 10**(-30)\n DO 34 N=1,NX\n DO 34 M=1,MXP\n IF(ABS(ALP(M,N)) .LE. SMALL) ALP(M,N)=0.0\n 34 CONTINUE\nc pick off the required polynomials\n DO 35 N=1,NX\n DO 35 M=1,MX\n MM2=ISC*(M-1)+1\n POLY(M,N)=ALP(MM2,N)\n 35 CONTINUE\n RETURN\n END\n***************************************************************\n SUBROUTINE LAP(STRM,VORM)\n\n include \"atparam.h\"\nc include \"param1spec.h\"\n include \"com_spectral.h\"\n\n COMPLEX VORM(MX,NX),STRM(MX,NX)\n DO 1 N=1,NX\n DO 1 M=1,MX\n VORM(M,N)=-STRM(M,N)*EL2(M,N)\n 1 CONTINUE \n\n RETURN\n END\n*******************************************************************\n SUBROUTINE INVLAP(VORM,STRM)\n\n include \"atparam.h\"\nc include \"param1spec.h\"\n include \"com_spectral.h\"\n\n COMPLEX VORM(MX,NX),STRM(MX,NX)\n DO 1 N=1,NX\n DO 1 M=1,MX\n STRM(M,N)=-VORM(M,N)*ELM2(M,N)\n 1 CONTINUE\nc DO 1 M=1,MXNX\nc STRM(M,1)=-VORM(M,1)*ELM2(M,1)\nc 1 CONTINUE\n RETURN\n END\n*********************************************************************\n SUBROUTINE GRAD(PSI,PSDX,PSDY)\n\n include \"atparam.h\"\nc include \"param1spec.h\"\n include \"com_spectral.h\"\n\n DIMENSION PSI(2,MX,NX),PSDX(2,MX,NX),PSDY(2,MX,NX)\n DO 1 N=1,NX\n DO 1 M=1,MX\n PSDX(2,M,N)=GRADX(M)*PSI(1,M,N)\n PSDX(1,M,N)=-GRADX(M)*PSI(2,M,N)\n 1 CONTINUE\n DO 2 K=1,2\n DO 2 M=1,MX\n PSDY(K,M,1)=GRADYP(M,1)*PSI(K,M,2)\n PSDY(K,M,NX)=-GRADYM(M,NX)*PSI(K,M,NTRUN1)\n 2 CONTINUE\n DO 3 K=1,2\n DO 3 N=2,NTRUN1\n DO 3 M=1,MX\n PSDY(K,M,N)=-GRADYM(M,N)*PSI(K,M,N-1)+GRADYP(M,N)*PSI(K,M,N+1)\n 3 CONTINUE\n RETURN\n END\n******************************************************************\n SUBROUTINE VDS(UCOSM,VCOSM,VORM,DIVM)\n\n include \"atparam.h\"\nc include \"param1spec.h\"\n include \"com_spectral.h\"\n \n DIMENSION VORM(2,MX,NX),DIVM(2,MX,NX),UCOSM(2,MX,NX),\n * VCOSM(2,MX,NX),ZC(2,MX,NX),ZP(2,MX,NX)\n do 1 n=1,nx\n DO 1 M=1,MX\n ZP(2,M,n)=GRADX(M)*UCOSM(1,M,n)\n ZP(1,M,n)=-GRADX(M)*UCOSM(2,M,n)\n ZC(2,M,n)=GRADX(M)*VCOSM(1,M,n)\n ZC(1,M,n)=-GRADX(M)*VCOSM(2,M,n)\n 1 CONTINUE\n DO 3 K=1,2\n DO 3 M=1,MX\n VORM(K,M,1)=ZC(K,M,1)-VDDYP(M,1)*UCOSM(K,M,2)\n VORM(K,M,NX)=VDDYM(M,NX)*UCOSM(K,M,NTRUN1)\n DIVM(K,M,1)=ZP(K,M,1)+VDDYP(M,1)*VCOSM(K,M,2)\n DIVM(K,M,NX)=-VDDYM(M,NX)*VCOSM(K,M,NTRUN1)\n 3 CONTINUE\n DO 4 K=1,2\n DO 4 N=2,NTRUN1\n DO 4 M=1,MX\n VORM(K,M,N)=VDDYM(M,N)*UCOSM(K,M,N-1)-VDDYP(M,N)*\n * UCOSM(K,M,N+1)+ZC(K,M,N) \n DIVM(K,M,N)=-VDDYM(M,N)*VCOSM(K,M,N-1)+VDDYP(M,N)*\n * VCOSM(K,M,N+1)+ZP(K,M,N)\n 4 CONTINUE\n RETURN \n END\n******************************************************************\n SUBROUTINE UVSPEC(VORM,DIVM,UCOSM,VCOSM)\n\n include \"atparam.h\"\nc include \"param1spec.h\"\n include \"com_spectral.h\"\n \n DIMENSION VORM(2,MX,NX),DIVM(2,MX,NX),UCOSM(2,MX,NX),\n * VCOSM(2,MX,NX),ZC(2,MX,NX),ZP(2,MX,NX)\nc DO 1 M=1,MXNX\n DO 1 M=1,MX\n DO 1 n=1,NX\n ZP(2,M,n)=UVDX(M,n)*VORM(1,M,n)\n ZP(1,M,n)=-UVDX(M,n)*VORM(2,M,n)\n ZC(2,M,n)=UVDX(M,n)*DIVM(1,M,n)\n ZC(1,M,n)=-UVDX(M,n)*DIVM(2,M,n)\n 1 CONTINUE\n DO 3 K=1,2\n DO 3 M=1,MX\n UCOSM(K,M,1)=ZC(K,M,1)-UVDYP(M,1)*VORM(K,M,2)\n UCOSM(K,M,NX)=UVDYM(M,NX)*VORM(K,M,NTRUN1)\n VCOSM(K,M,1)=ZP(K,M,1)+UVDYP(M,1)*DIVM(K,M,2)\n VCOSM(K,M,NX)=-UVDYM(M,NX)*DIVM(K,M,NTRUN1)\n 3 CONTINUE\n DO 4 K=1,2\n DO 4 N=2,NTRUN1\n DO 4 M=1,MX\n VCOSM(K,M,N)=-UVDYM(M,N)*DIVM(K,M,N-1)+UVDYP(M,N)*\n * DIVM(K,M,N+1)+ZP(K,M,N) \n UCOSM(K,M,N)= UVDYM(M,N)*VORM(K,M,N-1)-UVDYP(M,N)*\n * VORM(K,M,N+1)+ZC(K,M,N)\n 4 CONTINUE\n RETURN \n END\n*******************************************************************\n SUBROUTINE GRID(VORM,VORG,KCOS)\n\n include \"atparam.h\"\nc include \"param1spec.h\"\n\n DIMENSION VORG(IX,IL)\n DIMENSION VORM(MX2,NX),VARM(MX2,IL)\n CALL GRIDY(VORM,VARM)\n CALL GRIDX(VARM,VORG,KCOS)\n RETURN\n END\n*********************************************************************\n SUBROUTINE SPEC(VORG,VORM)\n\n include \"atparam.h\"\nc include \"param1spec.h\"\n\n DIMENSION VORG(IX,IL)\n DIMENSION VORM(MX2,NX),VARM(MX2,IL)\n CALL SPECX(VORG,VARM)\n CALL SPECY(VARM,VORM)\n RETURN\n END\n*********************************************************************\n SUBROUTINE VDSPEC(UG,VG,VORM,DIVM,KCOS)\n\n include \"atparam.h\"\nc include \"param1spec.h\"\n include \"com_spectral.h\"\n\n DIMENSION UG(IX,IL),VG(IX,IL)\n DIMENSION VORM(MX2,NX),DIVM(MX2,NX),UM(MX2,IL),VM(MX2,IL)\n DIMENSION UG1(IX,IL),VG1(IX,IL)\n DIMENSION DUMC1(MX2,NX),DUMC2(MX2,NX)\n IF (KCOS.EQ.2) THEN\n DO 7 J=1,IL\n DO 8 I=1,IX\n UG1(I,J)=UG(I,J)*COSGR(J)\n VG1(I,J)=VG(I,J)*COSGR(J)\n 8 CONTINUE\n 7 CONTINUE\n ELSE\n DO 77 J=1,IL\n DO 88 I=1,IX\n UG1(I,J)=UG(I,J)*COSGR2(J)\n VG1(I,J)=VG(I,J)*COSGR2(J)\n 88 CONTINUE\n 77 CONTINUE\n ENDIF\n CALL SPECX(UG1,UM) \n CALL SPECX(VG1,VM)\n CALL SPECY(UM,DUMC1)\n CALL SPECY(VM,DUMC2)\n CALL VDS(DUMC1,DUMC2,VORM,DIVM)\n RETURN\n END\n*********************************************************************\n SUBROUTINE GRIDY(V,VARM)\n\n include \"atparam.h\"\nc include \"param1spec.h\"\n include \"com_spectral.h\"\n\n DIMENSION VARM(MX2,IL),V(MX2,NX)\n DIMENSION VM1(MX2),VM2(MX2)\n\n DO 100 J=1,IY\n J1=IL+1-J\n\n DO M=1,MX2\n VM1(M)=0.\n VM2(M)=0.\n ENDDO\n\n DO N=1,NX,2\nC DO M=1,MX2\n DO M=1,nsh2(n)\n VM1(M)=VM1(M)+V(M,N)*CPOL(M,N,J)\n ENDDO\n ENDDO\n\n DO N=2,NX,2\nC DO M=1,MX2\n DO M=1,nsh2(n)\n VM2(M)=VM2(M)+V(M,N)*CPOL(M,N,J)\n ENDDO\n ENDDO\n\n DO M=1,MX2\n VARM(M,J1)=VM1(M)+VM2(M)\n VARM(M,J) =VM1(M)-VM2(M)\n ENDDO\n\n 100 CONTINUE\n\n RETURN\n END\n******************************************************************\n SUBROUTINE SPECY(VARM,VORM)\n\n include \"atparam.h\"\nc include \"param1spec.h\"\n include \"com_spectral.h\"\n\n DIMENSION VARM(MX2,IL), VORM(MX2,NX)\n dimension svarm(mx2,iy), dvarm(mx2,iy)\n\n DO N=1,NX\n DO M=1,MX2\n VORM(M,N)=0.\n ENDDO\n ENDDO\n\n do j=1,iy\n j1=il+1-j\n do m=1,mx2\n svarm(m,j)=(varm(m,j1)+varm(m,j))*wt(j)\n dvarm(m,j)=(varm(m,j1)-varm(m,j))*wt(j)\n ENDDO\n ENDDO\n\n DO 100 J=1,IY\n J1=IL+1-J\n\n DO N=1,NTRUN1,2\nC DO M=1,MX2\n DO M=1,nsh2(n)\n VORM(M,N) = VORM(M,N)+CPOL(M,N,J)*svarm(m,j)\n ENDDO\n ENDDO\n\n DO N=2,NTRUN1,2\nC DO M=1,MX2\n DO M=1,nsh2(n)\n VORM(M,N) = VORM(M,N)+CPOL(M,N,J)*dvarm(m,j)\n ENDDO\n ENDDO\n\n 100 CONTINUE\n\n RETURN\n END\n******************************************************************\n SUBROUTINE TRUNCT(VOR)\n\n include \"atparam.h\"\nc include \"param1spec.h\"\n include \"com_spectral.h\"\n\n COMPLEX VOR(MX,NX)\n\nc DO 20 M=1,MXNX\n DO 20 N=1,NX\n DO 20 M=1,MX\n VOR(M,N)=VOR(M,N)*TRFILT(M,N)\n 20 CONTINUE\n\n RETURN\n END\n", "meta": {"hexsha": "0c39672205f52fb7887a7ab27c9e09686f90bd8f", "size": 13387, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "models/speedy/t21/spe_spectral.f", "max_stars_repo_name": "enino84/AMLCS", "max_stars_repo_head_hexsha": "7a37cca01c9305afb99b652baeb9e0952ebe889b", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "models/speedy/t21/spe_spectral.f", "max_issues_repo_name": "enino84/AMLCS", "max_issues_repo_head_hexsha": "7a37cca01c9305afb99b652baeb9e0952ebe889b", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "models/speedy/t21/spe_spectral.f", "max_forks_repo_name": "enino84/AMLCS", "max_forks_repo_head_hexsha": "7a37cca01c9305afb99b652baeb9e0952ebe889b", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.5452674897, "max_line_length": 85, "alphanum_fraction": 0.48539628, "num_tokens": 5082, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299570920387, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6792293837563996}} {"text": "C$Procedure QXQ (Quaternion times quaternion)\n\n SUBROUTINE QXQ ( Q1, Q2, QOUT )\n\nC$ Abstract\nC\nC Multiply two quaternions.\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 ROTATION\nC \nC$ Keywords\nC\nC MATH\nC POINTING\nC ROTATION\nC\nC$ Declarations\n\n IMPLICIT NONE\n\n DOUBLE PRECISION Q1 ( 0 : 3 )\n DOUBLE PRECISION Q2 ( 0 : 3 )\n DOUBLE PRECISION QOUT ( 0 : 3 )\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC Q1 I First SPICE quaternion factor.\nC Q2 I Second SPICE quaternion factor.\nC QOUT O Product of Q1 and Q2.\nC\nC$ Detailed_Input\nC\nC Q1 is a 4-vector representing a SPICE-style\nC quaternion. See the discussion of quaternion\nC styles in Particulars below.\nC\nC Note that multiple styles of quaternions\nC are in use. This routine will not work properly\nC if the input quaternions do not conform to\nC the SPICE convention. See the Particulars\nC section for details.\nC\nC Q2 is a second SPICE-style quaternion.\nC\nC$ Detailed_Output\nC\nC QOUT is 4-vector representing the quaternion product \nC\nC Q1 * Q2\nC\nC Representing Q(i) as the sums of scalar (real)\nC part s(i) and vector (imaginary) part v(i)\nC respectively,\nC\nC Q1 = s1 + v1\nC Q2 = s2 + v2\nC\nC QOUT has scalar part s3 defined by\nC\nC s3 = s1 * s2 - \nC\nC and vector part v3 defined by\nC\nC v3 = s1 * v2 + s2 * v1 + v1 x v2\nC\nC where the notation < , > denotes the inner\nC product operator and x indicates the cross\nC product operator.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC Error free.\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC\nC Quaternion Styles\nC -----------------\nC\nC There are different \"styles\" of quaternions used in \nC science and engineering applications. Quaternion styles\nC are characterized by \nC\nC - The order of quaternion elements\nC\nC - The quaternion multiplication formula\nC\nC - The convention for associating quaternions\nC with rotation matrices\nC\nC Two of the commonly used styles are\nC\nC - \"SPICE\"\nC\nC > Invented by Sir William Rowan Hamilton\nC > Frequently used in mathematics and physics textbooks\nC\nC - \"Engineering\"\nC\nC > Widely used in aerospace engineering applications\nC\nC\nC SPICELIB subroutine interfaces ALWAYS use SPICE quaternions.\nC Quaternions of any other style must be converted to SPICE\nC quaternions before they are passed to SPICELIB routines.\nC \nC\nC Relationship between SPICE and Engineering Quaternions\nC ------------------------------------------------------\nC\nC Let M be a rotation matrix such that for any vector V, \nC\nC M*V\nC\nC is the result of rotating V by theta radians in the \nC counterclockwise direction about unit rotation axis vector A.\nC Then the SPICE quaternions representing M are\nC\nC (+/-) ( cos(theta/2), \nC sin(theta/2) A(1), \nC sin(theta/2) A(2), \nC sin(theta/2) A(3) ) \nC\nC while the engineering quaternions representing M are \nC\nC (+/-) ( -sin(theta/2) A(1), \nC -sin(theta/2) A(2), \nC -sin(theta/2) A(3),\nC cos(theta/2) )\nC\nC For both styles of quaternions, if a quaternion q represents\nC a rotation matrix M, then -q represents M as well.\nC\nC Given an engineering quaternion\nC\nC QENG = ( q0, q1, q2, q3 )\nC\nC the equivalent SPICE quaternion is\nC\nC QSPICE = ( q3, -q0, -q1, -q2 )\nC\nC\nC Associating SPICE Quaternions with Rotation Matrices\nC ----------------------------------------------------\nC\nC Let FROM and TO be two right-handed reference frames, for\nC example, an inertial frame and a spacecraft-fixed frame. Let the\nC symbols\nC\nC V , V\nC FROM TO\nC\nC denote, respectively, an arbitrary vector expressed relative to\nC the FROM and TO frames. Let M denote the transformation matrix\nC that transforms vectors from frame FROM to frame TO; then\nC\nC V = M * V\nC TO FROM\nC\nC where the expression on the right hand side represents left\nC multiplication of the vector by the matrix.\nC\nC Then if the unit-length SPICE quaternion q represents M, where\nC\nC q = (q0, q1, q2, q3)\nC\nC the elements of M are derived from the elements of q as follows:\nC\nC +- -+\nC | 2 2 |\nC | 1 - 2*( q2 + q3 ) 2*(q1*q2 - q0*q3) 2*(q1*q3 + q0*q2) |\nC | |\nC | |\nC | 2 2 |\nC M = | 2*(q1*q2 + q0*q3) 1 - 2*( q1 + q3 ) 2*(q2*q3 - q0*q1) |\nC | |\nC | |\nC | 2 2 |\nC | 2*(q1*q3 - q0*q2) 2*(q2*q3 + q0*q1) 1 - 2*( q1 + q2 ) |\nC | |\nC +- -+\nC\nC Note that substituting the elements of -q for those of q in the\nC right hand side leaves each element of M unchanged; this shows\nC that if a quaternion q represents a matrix M, then so does the\nC quaternion -q.\nC\nC To map the rotation matrix M to a unit quaternion, we start by\nC decomposing the rotation matrix as a sum of symmetric\nC and skew-symmetric parts:\nC\nC 2\nC M = [ I + (1-cos(theta)) OMEGA ] + [ sin(theta) OMEGA ]\nC\nC symmetric skew-symmetric\nC\nC\nC OMEGA is a skew-symmetric matrix of the form\nC\nC +- -+\nC | 0 -n3 n2 |\nC | |\nC OMEGA = | n3 0 -n1 |\nC | |\nC | -n2 n1 0 |\nC +- -+\nC\nC The vector N of matrix entries (n1, n2, n3) is the rotation axis\nC of M and theta is M's rotation angle. Note that N and theta\nC are not unique.\nC\nC Let\nC\nC C = cos(theta/2)\nC S = sin(theta/2)\nC\nC Then the unit quaternions Q corresponding to M are\nC\nC Q = +/- ( C, S*n1, S*n2, S*n3 )\nC\nC The mappings between quaternions and the corresponding rotations\nC are carried out by the SPICELIB routines\nC\nC Q2M {quaternion to matrix}\nC M2Q {matrix to quaternion}\nC\nC M2Q always returns a quaternion with scalar part greater than\nC or equal to zero.\nC\nC\nC SPICE Quaternion Multiplication Formula\nC ---------------------------------------\nC\nC Given a SPICE quaternion \nC\nC Q = ( q0, q1, q2, q3 )\nC\nC corresponding to rotation axis A and angle theta as above, we can\nC represent Q using \"scalar + vector\" notation as follows:\nC\nC s = q0 = cos(theta/2)\nC\nC v = ( q1, q2, q3 ) = sin(theta/2) * A\nC\nC Q = s + v\nC\nC Let Q1 and Q2 be SPICE quaternions with respective scalar\nC and vector parts s1, s2 and v1, v2:\nC \nC Q1 = s1 + v1\nC Q2 = s2 + v2\nC\nC We represent the dot product of v1 and v2 by\nC\nC \nC\nC and the cross product of v1 and v2 by\nC\nC v1 x v2\nC\nC Then the SPICE quaternion product is\nC\nC Q1*Q2 = s1*s2 - + s1*v2 + s2*v1 + (v1 x v2) \nC\nC If Q1 and Q2 represent the rotation matrices M1 and M2 \nC respectively, then the quaternion product\nC\nC Q1*Q2\nC\nC represents the matrix product\nC\nC M1*M2\nC\nC\nC$ Examples\nC\nC 1) Let QID, QI, QJ, QK be the \"basis\" quaternions\nC\nC QID = ( 1, 0, 0, 0 )\nC QI = ( 0, 1, 0, 0 )\nC QJ = ( 0, 0, 1, 0 )\nC QK = ( 0, 0, 0, 1 )\nC\nC respectively. Then the calls\nC\nC CALL QXQ ( QI, QJ, IXJ )\nC CALL QXQ ( QJ, QK, JXK )\nC CALL QXQ ( QK, QI, KXI )\nC\nC produce the results\nC\nC IXJ = QK\nC JXK = QI\nC KXI = QJ\nC\nC All of the calls\nC\nC CALL QXQ ( QI, QI, QOUT )\nC CALL QXQ ( QJ, QJ, QOUT )\nC CALL QXQ ( QK, QK, QOUT )\nC\nC produce the result\nC\nC QOUT = -QID\nC\nC For any quaternion Q, the calls\nC\nC CALL QXQ ( QID, Q, QOUT )\nC CALL QXQ ( Q, QID, QOUT )\nC\nC produce the result\nC\nC QOUT = Q\nC\nC\nC\nC 2) Composition of rotations: let CMAT1 and CMAT2 be two\nC C-matrices (which are rotation matrices). Then the\nC following code fragment computes the product CMAT1 * CMAT2:\nC\nC\nC C\nC C Convert the C-matrices to quaternions.\nC C\nC CALL M2Q ( CMAT1, Q1 )\nC CALL M2Q ( CMAT2, Q2 )\nC\nC C\nC C Find the product.\nC C\nC CALL QXQ ( Q1, Q2, QOUT )\nC\nC C\nC C Convert the result to a C-matrix.\nC C\nC CALL Q2M ( QOUT, CMAT3 )\nC\nC C\nC C Multiply CMAT1 and CMAT2 directly.\nC C\nC CALL MXM ( CMAT1, CMAT2, CMAT4 )\nC\nC C\nC C Compare the results. The difference DIFF of\nC C CMAT3 and CMAT4 should be close to the zero\nC C matrix.\nC C\nC CALL VSUBG ( 9, CMAT3, CMAT4, DIFF )\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC N.J. Bachman (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.1, 26-FEB-2008 (NJB)\nC\nC Updated header; added information about SPICE \nC quaternion conventions.\nC\nC- SPICELIB Version 1.0.0, 18-AUG-2002 (NJB)\nC\nC-&\n \nC$ Index_Entries\nC\nC quaternion times quaternion\nC multiply quaternion by quaternion\nC-&\n\n\nC\nC SPICELIB functions\nC\n DOUBLE PRECISION VDOT\n\nC\nC Local variables\nC\n DOUBLE PRECISION CROSS ( 3 )\n\n\nC\nC Compute the scalar part of the product.\nC\n QOUT(0) = Q1(0) * Q2(0) - VDOT( Q1(1), Q2(1) )\n\nC\nC And now the vector part. The SPICELIB routine VLCOM3 computes\nC a linear combination of three 3-vectors.\nC\n CALL VCRSS ( Q1(1), Q2(1), CROSS )\n\n CALL VLCOM3 ( Q1(0), Q2(1), \n . Q2(0), Q1(1),\n . 1.D0, CROSS, QOUT(1) )\n\n RETURN\n END\n\n\n \n", "meta": {"hexsha": "99abfdcb5a2e559adabd98d3666113fbfb6427c9", "size": 12593, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/qxq.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/qxq.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/qxq.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.109375, "max_line_length": 72, "alphanum_fraction": 0.5302946081, "num_tokens": 3661, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299591537478, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6792293745057095}} {"text": " SUBROUTINE MA01AD( XR, XI, YR, YI )\r\nC\r\nC SLICOT RELEASE 5.5.\r\nC\r\nC Copyright (c) 2002-2012 NICONET e.V.\r\nC\r\nC PURPOSE\r\nC\r\nC To compute the complex square root YR + i*YI of a complex number\r\nC XR + i*XI in real arithmetic. The returned result is so that\r\nC YR >= 0.0 and SIGN(YI) = SIGN(XI).\r\nC\r\nC ARGUMENTS\r\nC\r\nC Input/Output Parameters\r\nC\r\nC XR (input) DOUBLE PRECISION\r\nC XI (input) DOUBLE PRECISION\r\nC These scalars define the real and imaginary part of the\r\nC complex number of which the square root is sought.\r\nC\r\nC YR (output) DOUBLE PRECISION\r\nC YI (output) DOUBLE PRECISION\r\nC These scalars define the real and imaginary part of the\r\nC complex square root.\r\nC\r\nC METHOD\r\nC\r\nC The complex square root YR + i*YI of the complex number XR + i*XI\r\nC is computed in real arithmetic, taking care to avoid overflow.\r\nC\r\nC REFERENCES\r\nC\r\nC Adapted from EISPACK subroutine CSROOT.\r\nC\r\nC CONTRIBUTOR\r\nC\r\nC P. Benner, Universitaet Bremen, Germany, and\r\nC R. Byers, University of Kansas, Lawrence, USA,\r\nC Aug. 1998, routine DCROOT.\r\nC V. Sima, Research Institute for Informatics, Bucharest, Romania,\r\nC Oct. 1998, SLICOT Library version.\r\nC\r\nC REVISIONS\r\nC\r\nC -\r\nC\r\nC ******************************************************************\r\nC\r\nC .. Parameters ..\r\n DOUBLE PRECISION ZERO, HALF\r\n PARAMETER ( ZERO = 0.0D0, HALF = 1.0D0/2.0D0 )\r\nC ..\r\nC .. Scalar Arguments ..\r\n DOUBLE PRECISION XR, XI, YR, YI\r\nC ..\r\nC .. Local Scalars ..\r\n DOUBLE PRECISION S\r\nC ..\r\nC .. External Functions ..\r\n DOUBLE PRECISION DLAPY2\r\n EXTERNAL DLAPY2\r\nC\r\nC .. Intrinsic functions ..\r\n INTRINSIC ABS, SQRT\r\nC ..\r\nC .. Executable Statements ..\r\nC\r\n S = SQRT( HALF*( DLAPY2( XR, XI ) + ABS( XR ) ) )\r\n IF ( XR.GE.ZERO ) YR = S\r\n IF ( XI.LT.ZERO ) S = -S\r\n IF ( XR.LE.ZERO ) THEN\r\n YI = S\r\n IF ( XR.LT.ZERO ) YR = HALF*( XI/S )\r\n ELSE\r\n YI = HALF*( XI/YR )\r\n END IF\r\nC\r\n RETURN\r\nC *** Last line of MA01AD ***\r\n END\r\n", "meta": {"hexsha": "89a63b8fc394bc07259b438ebf02c3e87dbb6ebd", "size": 2248, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "External/SLICOT/MA01AD.f", "max_stars_repo_name": "bgin/MissileSimulation", "max_stars_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2016-08-28T23:20:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-15T14:43:58.000Z", "max_issues_repo_path": "External/SLICOT/MA01AD.f", "max_issues_repo_name": "bgin/MissileSimulation", "max_issues_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-06-02T21:29:51.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-05T05:59:31.000Z", "max_forks_repo_path": "External/SLICOT/MA01AD.f", "max_forks_repo_name": "bgin/MissileSimulation", "max_forks_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-07-04T22:38:22.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-04T22:38:22.000Z", "avg_line_length": 27.4146341463, "max_line_length": 73, "alphanum_fraction": 0.5431494662, "num_tokens": 680, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513842182775, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6791742591101928}} {"text": " SUBROUTINE CCOEF(N, CROOT, CCOF)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nC>> 1995-11-29 CCOEF Krogh Converted from SFTRAN to Fortran 77\nC>> 1987-02-25 CCOEF Lawson Initial code.\nc Conversion should only be done from \"Z\" to \"C\" for processing to C.\nc--C replaces \"?\": ?COEF\nC\nc Given N complex numbers, this subr computes the (complex)\nc coefficients of the Nth degree monic polynomial having these\nc numbers as its roots.\nc C. L. Lawson, JPL, 1987 Feb 13.\nc\nc N [In, Integer] Number of given roots and degree of poly.\nc CROOT() [In, Complex] The given ith complex root is CROOT(i).\nc CCOF() [Out, Complex] The (complex) coefficient of z**j will be\nc stored in CCOF(N+1-j) for j = 0, ...,N+1. The high\nc order coeff will be one, i.e. CCOF(1) = (1.0, 0.0).\nc -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n INTEGER N, I, J\n COMPLEX CROOT(N), CCOF(N+1), CROOTI\nc -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n CCOF(1) = 1.E0\n CCOF(2) = -CROOT(1)\n DO 20 I = 2,N\n CROOTI = CROOT(I)\n CCOF(I+1) = -CCOF(I) * CROOTI\n DO 10 J = I,2,-1\n CCOF(J) = CCOF(J) - CCOF(J-1) * CROOTI\n 10 continue\n 20 continue\n RETURN\n END\n", "meta": {"hexsha": "5e1ab0d9f61140e37bb99b25913a5ce2f9bf9dd4", "size": 1401, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/ccoef.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/ccoef.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/ccoef.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": 40.0285714286, "max_line_length": 72, "alphanum_fraction": 0.5538900785, "num_tokens": 516, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336204, "lm_q2_score": 0.7577943658046609, "lm_q1q2_score": 0.6791742409053483}} {"text": "SUBROUTINE DetermineGenericStencilsUniform(StencilsG,alpha)\n! By Allan P. Engsig-Karup.\nUSE Precision\nUSE Constants\nUSE DataTypes\nIMPLICIT NONE\nINTEGER :: alpha, i, rank, order\nREAL(KIND=long), DIMENSION(2*alpha+1,2*alpha+1,2) :: StencilsG\nREAL(KIND=long) :: x0, grid(2*alpha+1)\nREAL(KIND=long), DIMENSION(:,:), ALLOCATABLE :: c\nrank = 2*alpha+1\nALLOCATE( c(rank,3) )\nrank = 2*alpha+1\nDO i = 1, rank\n\tgrid(i) = REAL(i,long)\nEND DO\nDO order = 1, 2\n\tDO i = 1, rank\n\t\t! Expansion point where the approximation is to be defined\n\t\tx0 = REAL(i,long)\n\t\t! Determine local finite difference stencil coefficients\n\t\tCALL weights(x0,grid,rank-1,rank-1,order,c)\n\t\tStencilsG(1:rank,i,order) = c(1:rank,order+1)\n\tEND DO\nEND DO\nDEALLOCATE(c)\nEND SUBROUTINE DetermineGenericStencilsUniform\n", "meta": {"hexsha": "dd13780b87414cd78922b4291bfffd8f3680e91b", "size": 773, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/curvilinear/DetermineGenericStencilsUniform.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/curvilinear/DetermineGenericStencilsUniform.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/curvilinear/DetermineGenericStencilsUniform.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": 27.6071428571, "max_line_length": 62, "alphanum_fraction": 0.7309184994, "num_tokens": 277, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8705972684083608, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6790596883391404}} {"text": "!The preceding program implements recursion using arrays, since Fortran 77 does not allow recursive\n!functions. The same algorithm is much easier to follow in Fortran 90, using the RECURSIVE keyword.\n!Like previously, the program only counts solutions. It's pretty straightforward to adapt it to print\n!them too: one has to replace the 'm = m + 1' instruction with a PRINT statement.\n\nfunction numq(n)\n implicit none\n integer :: i, n, m, a(n), numq\n logical :: up(2*n - 1), down(2*n - 1)\n do i = 1, n\n a(i) = i\n end do\n up = .true.\n down = .true.\n m = 0\n call sub(1)\n numq = m\ncontains\n recursive subroutine sub(i)\n integer :: i, j, k, p, q, s\n do k = i, n\n j = a(k)\n p = i + j - 1\n q = i - j + n\n if(up(p) .and. down(q)) then\n if(i == n) then\n m = m + 1\n else\n up(p) = .false.\n down(q) = .false.\n s = a(i)\n a(i) = a(k)\n a(k) = s\n call sub(i + 1)\n up(p) = .true.\n down(q) = .true.\n s = a(i)\n a(i) = a(k)\n a(k) = s\n end if\n end if\n end do\n end subroutine\nend function\n\nprogram queens\n implicit none\n integer :: numq, n, m\n do n = 4, 16\n m = numq(n)\n print *, n, m\n end do\nend program\n", "meta": {"hexsha": "3dce5b80df5a04fd7d54be50b03db6c4f7ee9763", "size": 1501, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/N-queens-problem/Fortran/n-queens-problem-3.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/N-queens-problem/Fortran/n-queens-problem-3.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/N-queens-problem/Fortran/n-queens-problem-3.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 27.7962962963, "max_line_length": 101, "alphanum_fraction": 0.4483677548, "num_tokens": 417, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972583359805, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6790596804827553}} {"text": "#include \"eiscor.h\"\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! ZEXROU (Zomplex EXample Roots Of Unity)\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! This routine computes the Nth order roots of unity by solving a\n! corresponding unitary eigenvalue problem two different ways.\n!\n! 1) Form upper hessenberg permutation matrix and compute its \n! eigenvalues using ZUHFQR\n!\n! 2) Construct the factorization directly and compute its \n! eigenvalues using ZUFFQR\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nprogram ZEXROU\n\n implicit none\n \n ! compute variables\n integer, parameter :: N = 16\n integer :: ii, INFO\n real(8) :: WORK(5*N), Q(3*(N-1)), D(2*N)\n complex(8) :: H(N,N), Z\n integer :: ITS(N-1)\n \n ! print banner\n print*,\"\"\n print*,\"ZEXROU: Zomplex EXample Roots Of Unity\"\n print*,\"\"\n \n ! initialize H to be an upper hessenberg permutation matrix\n H = cmplx(0d0,0d0,kind=8)\n do ii=1,N-1\n H(ii+1,ii) = cmplx(1d0,0d0,kind=8)\n end do\n H(1,N) = cmplx(1d0,0d0,kind=8)\n \n ! call zuhfqr\n call ZUHFQR('N',N,H,Z,ITS,WORK,INFO)\n \n ! check INFO\n if (INFO.NE.0) then\n print*,\"ZUHFQR failed.\"\n print*,\"INFO:\",INFO\n end if\n \n ! print diag of H\n print*,\"Roots computed using ZUHFQR:\"\n do ii=1,N\n print*,dble(H(ii,ii)),aimag(H(ii,ii))\n end do\n print*,\"\"\n \n ! initialize Q and D to be an upper hessenberg permutation matrix\n do ii=1,N-1\n Q(3*ii-2) = 0d0\n Q(3*ii-1) = 0d0\n Q(3*ii) = 1d0\n end do\n do ii=1,N-1\n D(2*ii-1) = 1d0\n D(2*ii) = 0d0\n end do\n D(2*N-1) = (-1d0)**(N-1)\n D(2*N) = 0d0\n \n ! call zuffqr\n call ZUFFQR('N',N,Q,D,Z,ITS,INFO)\n \n ! check INFO\n if (INFO.NE.0) then\n print*,\"ZUFFQR failed.\"\n print*,\"INFO:\",INFO\n end if\n \n ! print D\n print*,\"Roots computed using ZUFFQR:\"\n do ii=1,N\n print*,D(2*ii-1),D(2*ii)\n end do\n print*,\"\"\n\n \nend program ZEXROU\n", "meta": {"hexsha": "56cd9fa5af27086d31ae9d9360de9fc41df26b1a", "size": 1931, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "deps/eiscor-master/examples/complex_double/ZEXROU.f90", "max_stars_repo_name": "andreasnoack/EiSCor.jl", "max_stars_repo_head_hexsha": "d03d217e30e006b35263b99cb4adafd9d7e1e973", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "deps/eiscor-master/examples/complex_double/ZEXROU.f90", "max_issues_repo_name": "andreasnoack/EiSCor.jl", "max_issues_repo_head_hexsha": "d03d217e30e006b35263b99cb4adafd9d7e1e973", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "deps/eiscor-master/examples/complex_double/ZEXROU.f90", "max_forks_repo_name": "andreasnoack/EiSCor.jl", "max_forks_repo_head_hexsha": "d03d217e30e006b35263b99cb4adafd9d7e1e973", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.9431818182, "max_line_length": 70, "alphanum_fraction": 0.5473847747, "num_tokens": 717, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972684083608, "lm_q2_score": 0.7799928900257127, "lm_q1q2_score": 0.6790596794343284}} {"text": " SUBROUTINE dfpmin(p,n,gtol,iter,fret,func,dfunc)\r\n INTEGER iter,n,NMAX,ITMAX\r\n REAL fret,gtol,p(n),func,EPS,STPMX,TOLX\r\n PARAMETER (NMAX=50,ITMAX=200,STPMX=100.,EPS=3.e-8,TOLX=4.*EPS)\r\n EXTERNAL dfunc,func\r\nCU USES dfunc,func,lnsrch\r\n INTEGER i,its,j\r\n LOGICAL check\r\n REAL den,fac,fad,fae,fp,stpmax,sum,sumdg,sumxi,temp,test,dg(NMAX),\r\n *g(NMAX),hdg(NMAX),hessin(NMAX,NMAX),pnew(NMAX),xi(NMAX)\r\n fp=func(p)\r\n call dfunc(p,g)\r\n sum=0.\r\n do 12 i=1,n\r\n do 11 j=1,n\r\n hessin(i,j)=0.\r\n11 continue\r\n hessin(i,i)=1.\r\n xi(i)=-g(i)\r\n sum=sum+p(i)**2\r\n12 continue\r\n stpmax=STPMX*max(sqrt(sum),float(n))\r\n do 27 its=1,ITMAX\r\n iter=its\r\n call lnsrch(n,p,fp,g,xi,pnew,fret,stpmax,check,func)\r\n fp=fret\r\n do 13 i=1,n\r\n xi(i)=pnew(i)-p(i)\r\n p(i)=pnew(i)\r\n13 continue\r\n test=0.\r\n do 14 i=1,n\r\n temp=abs(xi(i))/max(abs(p(i)),1.)\r\n if(temp.gt.test)test=temp\r\n14 continue\r\n if(test.lt.TOLX)return\r\n do 15 i=1,n\r\n dg(i)=g(i)\r\n15 continue\r\n call dfunc(p,g)\r\n test=0.\r\n den=max(fret,1.)\r\n do 16 i=1,n\r\n temp=abs(g(i))*max(abs(p(i)),1.)/den\r\n if(temp.gt.test)test=temp\r\n16 continue\r\n if(test.lt.gtol)return\r\n do 17 i=1,n\r\n dg(i)=g(i)-dg(i)\r\n17 continue\r\n do 19 i=1,n\r\n hdg(i)=0.\r\n do 18 j=1,n\r\n hdg(i)=hdg(i)+hessin(i,j)*dg(j)\r\n18 continue\r\n19 continue\r\n fac=0.\r\n fae=0.\r\n sumdg=0.\r\n sumxi=0.\r\n do 21 i=1,n\r\n fac=fac+dg(i)*xi(i)\r\n fae=fae+dg(i)*hdg(i)\r\n sumdg=sumdg+dg(i)**2\r\n sumxi=sumxi+xi(i)**2\r\n21 continue\r\n if(fac**2.gt.EPS*sumdg*sumxi)then\r\n fac=1./fac\r\n fad=1./fae\r\n do 22 i=1,n\r\n dg(i)=fac*xi(i)-fad*hdg(i)\r\n22 continue\r\n do 24 i=1,n\r\n do 23 j=1,n\r\n hessin(i,j)=hessin(i,j)+fac*xi(i)*xi(j)-fad*hdg(i)*hdg(j)+\r\n *fae*dg(i)*dg(j)\r\n23 continue\r\n24 continue\r\n endif\r\n do 26 i=1,n\r\n xi(i)=0.\r\n do 25 j=1,n\r\n xi(i)=xi(i)-hessin(i,j)*g(j)\r\n25 continue\r\n26 continue\r\n27 continue\r\n pause 'too many iterations in dfpmin'\r\n return\r\n END\r\n", "meta": {"hexsha": "28c6da40c6cb50f863b396fff890b24133d9a7f2", "size": 2434, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/dfpmin.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/dfpmin.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/dfpmin.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.0444444444, "max_line_length": 73, "alphanum_fraction": 0.4679539852, "num_tokens": 841, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.913676530465412, "lm_q2_score": 0.743167997235783, "lm_q1q2_score": 0.6790151572673191}} {"text": "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n!\r\n! This module contains code for representing functions via piecewise Chebyshev \r\n! expansions. More accurately, functions on an interval [a,b] can be represented either \r\n! via their values at the Chebyshev grids on a collection of subintervals [a,b] or\r\n! via their Chebyshev expansion coefficients on said subintervals. \r\n!\r\n! The following routines should be regarded as public:\r\n! \r\n! chebexps - construct the n-point Clenshaw-Curtis quadrature on the interval [-1,1],\r\n! the matrix which takes the values of a function to the Chebyshev coefficients of the \r\n! polynomial interpolating the function at the nodes of the quadrature rule, as well\r\n! as the \"left\" and \"right\" spectral integration matrices.!\r\n!\r\n! chebs - evaluate the Chebyshev polynomials of orders 0 through n at a specified\r\n! point in the interval [-1,1]\r\n!\r\n! chebeval - evaluate a polynomial of degree n-1 whose values are given \r\n! on the n-point Chebyshev grid on an interval [a,b] using the well-known \r\n! barycentric interpolation formula\r\n!\r\n! chebeval2 - use the Clenshaw algorithm in order to evaluate an n-term Chebyshev\r\n! expansion on the interval [a,b] at a specified point t in [a,b]\r\n!\r\n! chebevalder - evaluate an n-term Chebyshev expansion on the interval [a,b]\r\n! and its derivative at a specified point x in [a,b]\r\n!\r\n! chebpw_eval - evaluate a function specified by its values at k-point Chebyshev\r\n! grids on a collection of subintervals of [a,b] at an arbitrary point x in\r\n! [a,b]\r\n!\r\n! chebpw_eval2 - evaluate a piecewise Chebyshev expansion given on a collection\r\n! of subintervals of [a,b] at a specified point x in [a,b]\r\n!\r\n! chebpw_aint - apply the matrix interpolating a function from a piecewise\r\n! Chebyshev grid to a user-specified collection of points to a vector\r\n!\r\n! chebpw_aintt - apply the transpose of the matrix interpolating a function from \r\n! a piecewise Chebyshev grid to a user-specified collection of points to a vector\r\n!\r\n! chebpw_aint_c - apply the matrix interpolating a function from a piecewise\r\n! Chebyshev grid to a user-specified collection of points to a complex-valued\r\n! vector\r\n!\r\n! chebpw_aintt_c - apply the transpose of the matrix interpolating a function from \r\n! a piecewise Chebyshev grid to a user-specified collection of points to a complex-\r\n! valued vector\r\n!\r\n! write_chebexps - write a chebexps structure to a text file on the disk\r\n!\r\n! read_chebexps - read a chebexps structure from a text file on the disk\r\n!\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\nmodule chebyshev\r\n\r\nuse utils\r\n\r\n!\r\n! The chebexps_data structure contains the following elements:\r\n!\r\n! xs - an array containing the n quadrature nodes\r\n! whts - an array containing the n quadrature weights\r\n! u - the (n,n) matrix which takes the values of an n-term Chebyshev expansion\r\n! at the n quadrature nodes to the n expansion coefficients\r\n! v - the (n,n) matrix which takes the coefficients of an nterm-Chebyshev\r\n! expansion to its values at the n quadratue nodes\r\n! aintl - the \"left\" spectral integration matrix which takes the values\r\n! of a function f(t) on the Chebyshev nodes to the value of the function g(t) \r\n! defined via the formula\r\n!\r\n! t\r\n! g(t) = \\int f(u) du\r\n! a\r\n!\r\n! aintr - the \"right\" spectral integration matrix which takes the values\r\n! of a function f(t) on the Chebyshev nodes to the value of the function g(t) \r\n! defined via the formula\r\n!\r\n! t\r\n! g(t) = \\int_ f(u) du\r\n! b\r\n! aintr2, aintr3, aintl2, aintl3 - the higher order left and right spectral \r\n! integration matrices\r\n!\r\n\r\ntype chebexps_data\r\ninteger :: k\r\ndouble precision, allocatable :: xs(:),whts(:),u(:,:),v(:,:)\r\n\r\n! left and right spectral integration matrices \r\ndouble precision, allocatable :: aintr(:,:),aintr2(:,:),aintr3(:,:)\r\ndouble precision, allocatable :: aintl(:,:),aintl2(:,:),aintl3(:,:)\r\n\r\nend type chebexps_data\r\n\r\n\r\ncontains\r\n\r\nsubroutine chebpw_aint(chebdata,nints,ab,nts,ts,x,y)\r\nimplicit double precision (a-h,o-z)\r\n\r\ntype(chebexps_data) :: chebdata\r\ninteger :: nints\r\ndouble precision :: ab(2,nints), x(chebdata%k,nints)\r\ndouble precision :: ts(nts)\r\ndouble precision :: y(nts)\r\n\r\n!\r\n! Apply the matrix interpolating a function whose values are given at the\r\n! nodes of a piecewise Chebyshev discretization scheme to a set of user-specified \r\n! points.\r\n!\r\n! IMPORTANT - the list of user-specified points must be sorted in ascending order.\r\n!\r\n! Input parameters:\r\n! chebdata - chebyshev expansion and interpolation data\r\n! nints - the number of intervals in the discretization scheme\r\n! ab - a (2,nints) array giving the endpoints of the intervals in the discretization\r\n! scheme\r\n! nts - the number of user-specified nodes\r\n! ts - an array containing the user specified nodes SORTED IN ASCENDING ORDER\r\n! x - the vector to which the transpose of the matrix should be applied\r\n!\r\n! Output parameters:\r\n! y - the output vector\r\n!\r\n\r\n\r\ndouble precision :: whts(chebdata%k)\r\n\r\neps0 = epsilon(0.0d0)\r\nint0 = 1\r\nk = chebdata%k\r\n\r\ndo i=1,nts\r\nt = ts(i)\r\n\r\ndo int=int0,nints-1\r\nif (t .lt. ab(2,int)) exit\r\nend do\r\na = ab(1,int)\r\nb = ab(2,int)\r\nint0 = int\r\n\r\nxx = (2*t - (b+a) ) /(b-a)\r\ndsign = 1.0d0\r\ndo l=1,k\r\ndiff = chebdata%xs(l) - xx\r\nif (abs(diff) .lt. eps0) then\r\nval = x(l,int)\r\ngoto 1000\r\nendif\r\nwhts(l) = dsign/diff\r\ndsign = -dsign\r\nend do\r\n\r\nwhts(1) = whts(1)/2\r\nwhts(k) = whts(k)/2\r\nval = sum(whts*x(:,int))/sum(whts)\r\n\r\n1000 continue\r\n\r\ny(i) = val\r\nend do\r\n\r\n\r\nend subroutine\r\n\r\n\r\nsubroutine chebpw_aintt(chebdata,nints,ab,nts,ts,x,y)\r\nimplicit double precision (a-h,o-z)\r\n\r\ntype(chebexps_data) :: chebdata\r\ninteger :: nints\r\ndouble precision :: ab(2,nints)\r\ndouble precision :: ts(nts)\r\ndouble precision :: x(nts),y(chebdata%k,nints)\r\n\r\n!\r\n! Apply the transpose of the matrix interpolating a function whose values\r\n! are given at the nodes of a piecewise Chebyshev discretization scheme to\r\n! a set of user-specified points.\r\n!\r\n! IMPORTANT - the list of user-specified points must be sorted in ascending order.\r\n!\r\n! Input parameters:\r\n! chebdata - chebyshev expansion and interpolation data\r\n! nints - the number of intervals in the discretization scheme\r\n! ab - a (2,nints) array giving the endpoints of the intervals in the discretization\r\n! scheme\r\n! nts - the number of user-specified nodes\r\n! ts - an array containing the user specified nodes SORTED IN ASCENDING ORDER\r\n! x - the vector to which the transpose of the matrix should be applied\r\n!\r\n! Output parameters:\r\n! y - the output vector\r\n!\r\n\r\ndouble precision :: whts(chebdata%k)\r\n\r\neps0 = epsilon(0.0d0)\r\nint0 = 1\r\nk = chebdata%k\r\ny = 0\r\ncall prin2(\"x = \",x)\r\nstop\r\n\r\n!\r\n! Traverse the list of ts\r\n!\r\n\r\ndo i=1,nts\r\nt = ts(i)\r\n\r\ndo int=int0,nints-1\r\nif (t .lt. ab(2,int)) exit\r\nend do\r\na = ab(1,int)\r\nb = ab(2,int)\r\nint0 = int\r\n\r\nxx = (2*t - (b+a) ) /(b-a)\r\ndsign = 1.0d0\r\ndo l=1,k\r\ndiff = chebdata%xs(l) - xx\r\nif (abs(diff) .lt. eps0) then\r\ny(l,int) = y(l,int) + x(i)\r\ngoto 1000\r\nendif\r\nwhts(l) = dsign/diff\r\ndsign = -dsign\r\nend do\r\nwhts(1) = whts(1)/2\r\nwhts(k) = whts(k)/2\r\n\r\ny(:,int) = y(:,int) + x(i)*whts(:)/sum(whts)\r\n1000 continue\r\n\r\nend do\r\n\r\nend subroutine\r\n\r\n\r\nsubroutine chebpw_aint_c(chebdata,nints,ab,nts,ts,x,y)\r\nimplicit double precision (a-h,o-z)\r\n\r\ntype(chebexps_data) :: chebdata\r\ninteger :: nints\r\ndouble precision :: ab(2,nints)\r\ndouble precision :: ts(nts)\r\ndouble complex :: y(nts), x(chebdata%k,nints)\r\n\r\n\r\n!\r\n! Apply the matrix interpolating a function whose values are given at the\r\n! nodes of a piecewise Chebyshev discretization scheme to a set of user-specified \r\n! points.\r\n!\r\n! IMPORTANT - the list of user-specified points must be sorted in ascending order.\r\n!\r\n! Input parameters:\r\n! chebdata - chebyshev expansion and interpolation data\r\n! nints - the number of intervals in the discretization scheme\r\n! ab - a (2,nints) array giving the endpoints of the intervals in the discretization\r\n! scheme\r\n! nts - the number of user-specified nodes\r\n! ts - an array containing the user specified nodes SORTED IN ASCENDING ORDER\r\n! x - the vector to which the transpose of the matrix should be applied\r\n!\r\n! Output parameters:\r\n! y - the output vector\r\n!\r\n\r\n\r\ndouble precision :: whts(chebdata%k)\r\n\r\neps0 = epsilon(0.0d0)\r\nint0 = 1\r\nk = chebdata%k\r\n\r\ndo i=1,nts\r\nt = ts(i)\r\n\r\ndo int=int0,nints-1\r\nif (t .lt. ab(2,int)) exit\r\nend do\r\na = ab(1,int)\r\nb = ab(2,int)\r\nint0 = int\r\n\r\nxx = (2*t - (b+a) ) /(b-a)\r\ndsign = 1.0d0\r\ndo l=1,k\r\ndiff = chebdata%xs(l) - xx\r\nif (abs(diff) .lt. eps0) then\r\nval = x(l,int)\r\ngoto 1000\r\nendif\r\nwhts(l) = dsign/diff\r\ndsign = -dsign\r\nend do\r\n\r\nwhts(1) = whts(1)/2\r\nwhts(k) = whts(k)/2\r\nval = sum(whts*x(:,int))/sum(whts)\r\n\r\n1000 continue\r\n\r\ny(i) = val\r\nend do\r\n\r\n\r\nend subroutine\r\n\r\n\r\nsubroutine chebpw_aintt_c(chebdata,nints,ab,nts,ts,x,y)\r\nimplicit double precision (a-h,o-z)\r\n\r\ntype(chebexps_data) :: chebdata\r\ninteger :: nints\r\ndouble precision :: ab(2,nints)\r\ndouble precision :: ts(nts)\r\ndouble complex :: x(nts),y(chebdata%k,nints)\r\n\r\n!\r\n! Apply the transpose of the matrix interpolating a function whose values\r\n! are given at the nodes of a piecewise Chebyshev discretization scheme to\r\n! a set of user-specified points.\r\n!\r\n! IMPORTANT - the list of user-specified points must be sorted in ascending order.\r\n!\r\n! Input parameters:\r\n! chebdata - chebyshev expansion and interpolation data\r\n! nints - the number of intervals in the discretization scheme\r\n! ab - a (2,nints) array giving the endpoints of the intervals in the discretization\r\n! scheme\r\n! nts - the number of user-specified nodes\r\n! ts - an array containing the user specified nodes SORTED IN ASCENDING ORDER\r\n! x - the vector to which the transpose of the matrix should be applied\r\n!\r\n! Output parameters:\r\n! y - the output vector\r\n!\r\n\r\ndouble precision :: whts(chebdata%k)\r\n\r\neps0 = epsilon(0.0d0)\r\nint0 = 1\r\nk = chebdata%k\r\ny = 0\r\n\r\n!\r\n! Traverse the list of ts\r\n!\r\n\r\ndo i=1,nts\r\nt = ts(i)\r\n\r\ndo int=int0,nints-1\r\nif (t .lt. ab(2,int)) exit\r\nend do\r\na = ab(1,int)\r\nb = ab(2,int)\r\nint0 = int\r\n\r\nxx = (2*t - (b+a) ) /(b-a)\r\ndsign = 1.0d0\r\ndo l=1,k\r\ndiff = chebdata%xs(l) - xx\r\nif (abs(diff) .lt. eps0) then\r\ny(l,int) = y(l,int) + x(i)\r\ngoto 1000\r\nendif\r\nwhts(l) = dsign/diff\r\ndsign = -dsign\r\nend do\r\nwhts(1) = whts(1)/2\r\nwhts(k) = whts(k)/2\r\n\r\ny(:,int) = y(:,int) + x(i)*whts(:)/sum(whts)\r\n1000 continue\r\n\r\nend do\r\n\r\nend subroutine\r\n\r\n\r\n\r\n\r\n\r\nsubroutine chebexps(n,chebdata)\r\nimplicit double precision (a-h,o-z)\r\ninteger :: n\r\ntype(chebexps_data), intent(out) :: chebdata\r\n\r\n!\r\n! Populate a chebexps structure.\r\n!\r\n! Input parameters:\r\n! n - the number of points in the chebyshev grid\r\n!\r\n! Output parameters:\r\n! chebdata - the chebexps_data structure containing the elements described\r\n! above\r\n! \r\n!\r\n\r\ndouble precision, allocatable :: pols(:),c(:,:),d(:,:),xx(:,:)\r\ndata pi /3.14159265358979323846264338327950288d0/\r\n\r\nallocate(chebdata%xs(n),chebdata%whts(n),chebdata%u(n,n),chebdata%v(n,n))\r\nallocate(pols(n+1),c(1,n),d(1,n))\r\n\r\nchebdata%k = n\r\n!\r\n! Construct the nodes\r\n!\r\n\r\nh = pi/(n-1)\r\ndo i=1,n\r\nchebdata%xs(n-i+1) = cos(h*(i-1))\r\nend do\r\n\r\n!\r\n! Construct the matrix u which takes values to coefficients\r\n!\r\n\r\ndo i=1,n\r\nx = chebdata%xs(i)\r\ncall chebs(x,n-1,pols)\r\ndo j=1,n\r\nchebdata%u(j,i) = pols(j)\r\nchebdata%v(i,j) = pols(j)\r\nend do\r\nend do\r\n\r\n\r\nchebdata%u(1,:) = chebdata%u(1,:)/2\r\nchebdata%u(n,:) = chebdata%u(n,:)/2\r\nchebdata%u(:,1) = chebdata%u(:,1)/2\r\nchebdata%u(:,n) = chebdata%u(:,n)/2\r\nchebdata%u = chebdata%u*2.0d0/(n-1)\r\n\r\n!\r\n! Construct the weights by multiplying u^t on the left by the\r\n! integrals of the Chebyshev polynomials.\r\n!\r\n\r\nc=0\r\nc(1,1) = 2.0d0\r\ndo i=2,n-1,2\r\nc(1,i+1) = 1.0d0/(i+1)-1.0d0/(i-1)\r\nend do\r\n\r\nd = matmul(c,chebdata%u)\r\nchebdata%whts = d(1:n,1)\r\n\r\n!\r\n! Form the matrix which takes the values of a function f(t) to the values of\r\n!\r\n! t\r\n! g(t) = \\int f(u) du\r\n! a\r\n! \r\n\r\nallocate(xx(n,n),chebdata%aintr(n,n),chebdata%aintl(n,n))\r\n\r\ndo i=1,n\r\ncall chebs(chebdata%xs(i),n,pols)\r\nxx(i,1) = chebdata%xs(i)\r\nxx(i,2) = chebdata%xs(i)**2/2.0d0\r\ndo j=3,n\r\nxx(i,j) = 0.5d0 * (pols(j+1)/j-pols(j-1)/(j-2))\r\nend do\r\nend do\r\n\r\ndo i=2,n\r\nxx(i,:) = xx(i,:) - xx(1,:)\r\nend do\r\nxx(1,:) = 0\r\n\r\nchebdata%aintl = matmul(xx,chebdata%u)\r\n\r\n!\r\n! Form the matrix which takes the values of a function f(t) to the values of\r\n!\r\n! t\r\n! g(t) = \\int f(u) du\r\n! b\r\n! \r\n\r\nxx = 0\r\n\r\ndo i=1,n\r\ncall chebs(chebdata%xs(i),n,pols)\r\nxx(i,1) = chebdata%xs(i)\r\nxx(i,2) = chebdata%xs(i)**2/2.0d0\r\ndo j=3,n\r\nxx(i,j) = 0.5d0 * (pols(j+1)/j-pols(j-1)/(j-2))\r\nend do\r\nend do\r\n\r\ndo i=1,n-1\r\nxx(i,:) = xx(i,:) - xx(n,:)\r\nend do\r\nxx(n,:) = 0\r\n\r\nchebdata%aintr = matmul(xx,chebdata%u)\r\n\r\n!\r\n! Form the higher order spectral integration matrices\r\n!\r\n\r\nallocate(chebdata%aintr2(n,n),chebdata%aintr3(n,n))\r\nchebdata%aintr2 = matmul(chebdata%aintr,chebdata%aintr)\r\nchebdata%aintr3 = matmul(chebdata%aintr,chebdata%aintr2)\r\n\r\nallocate(chebdata%aintl2(n,n),chebdata%aintl3(n,n))\r\nchebdata%aintl2 = matmul(chebdata%aintl,chebdata%aintl)\r\nchebdata%aintl3 = matmul(chebdata%aintl,chebdata%aintl2)\r\n\r\n\r\nend subroutine\r\n\r\n\r\n\r\nsubroutine chebs(x,n,pols)\r\nimplicit double precision (a-h,o-z)\r\n\r\ninteger :: n \r\ndouble precision :: pols(0:n),x\r\n\r\n!\r\n! Evaluate the Chebyshev polynomials of degree 0 through n at a specified point\r\n! using the standard 3-term recurrence relation.\r\n!\r\n! Input parameters:\r\n!\r\n! x - point at which to evaluate the polynomials\r\n! n - the order of the polynomials to evaluate\r\n!\r\n! Output parameters:\r\n!\r\n! pols - this user-supplied and allocated array of length n+1 will\r\n! contain the values of the polynomials of order 0 through n upon\r\n! return\r\n!\r\n\r\nif (x .eq. 1.0d0) then\r\ndo i=0,n\r\npols(i) = 1.0d0\r\nend do\r\nreturn\r\nendif\r\n\r\nif (x .eq. -1.0d0) then\r\npols(0) = 1.0d0\r\ndo i=1,n\r\npols(i) = -pols(i-1)\r\nend do\r\nreturn\r\nendif\r\n\r\npols(0) = 1.0d0\r\nif (n .eq. 0) return\r\n\r\npols(1) = x\r\nif (n .eq. 1) return\r\n\r\nxx1 = 1.0d0\r\nxx2 = x\r\n\r\ndo i=1,n-1\r\nxx = 2*x*xx2 - xx1\r\npols(i+1) = xx\r\nxx1 = xx2\r\nxx2 = xx\r\nend do\r\n\r\nend subroutine\r\n\r\n\r\n\r\nsubroutine chebeval(a,b,n,xs,vals,x,val)\r\nimplicit double precision (a-h,o-z)\r\n\r\ninteger :: n\r\ndouble precision :: xs(n),vals(n),x,val\r\n\r\n!\r\n! Use the barycentric formula to evaluate a function given its values at the \r\n! n-point Chebyshev grid on an interval [a,b].\r\n!\r\n! Input parameters:\r\n!\r\n! (a,b) - the interval on which the function is given\r\n! n - the number of nodes in the Chebyshev grid\r\n! xs - an array specifying the n Chevyshev node on the interval [-1,1]\r\n! vals - the values of the function on the n Chebyshev nodes on the\r\n! interval [-1,1]\r\n! x - the point in the interval (a,b) at which the function is to be\r\n! evaluated\r\n! \r\n! Output parameters:\r\n!\r\n! val - the approximate value of the function at the point x\r\n!\r\n\r\neps0 = epsilon(0.0d0)\r\n\r\nxx = (2*x - (b+a) ) /(b-a)\r\n\r\nsum1=0\r\nsum2=0\r\n\r\ndd1 = 1.0d0\r\n\r\ndo i=1,n\r\ndd=1.0d0\r\nif (i .eq. 1 .OR. i .eq. n) dd = 0.5d0\r\n\r\ndiff = xx-xs(i)\r\n\r\n!\r\n! Handle the case in which the target node coincide with one of\r\n! of the Chebyshev nodes.\r\n!\r\n\r\nif(abs(diff) .le. eps0) then\r\nval = vals(i)\r\nreturn\r\nendif\r\n\r\n!\r\n! Otherwise, construct the sums.\r\n!\r\n\r\ndd = (dd1*dd)/diff\r\ndd1 = - dd1\r\nsum1 = sum1+dd*vals(i)\r\nsum2 = sum2+dd\r\ndd = - dd\r\nend do\r\n\r\nval = sum1/sum2\r\n\r\n\r\nend subroutine\r\n\r\n\r\nsubroutine chebeval2(a,b,n,coefs,x,val)\r\nimplicit double precision (a-h,o-z)\r\n\r\ninteger, intent(in) :: n\r\ndouble precision, intent(in) :: a,b,x,coefs(n)\r\ndouble precision, intent(out) :: val\r\n\r\n!\r\n! Use the Clenshaw algorithm in order to evaluate a Chebyshev expansion on the \r\n! interval [a,b].\r\n!\r\n! Input parameters:\r\n! (a,b) - the interval on which the expansion is given\r\n! n - the number of terms in the Chebyshev expansion\r\n! coefs - an array of length n specifying the expansion coefficients\r\n! x - the point at which to evaluate the expansion\r\n!\r\n! Output parameters:\r\n! val - the value of the expansion at the point x\r\n!\r\n\r\nxx = (x - (b+a)/2.0d0) * 2.0d0/(b-a)\r\n\r\nb2 = coefs(n)\r\nb1 = 2*xx*b2+coefs(n-1)\r\n\r\ndo i=n-2,2,-1\r\nb0 = coefs(i)+2*xx*b1-b2\r\nb2 = b1\r\nb1 = b0\r\nend do\r\n\r\nval = b1 * xx + (coefs(1)-b2)\r\n\r\nend subroutine\r\n\r\n\r\n\r\n\r\nsubroutine chebpw_eval(nints,ab,k,xscheb,vals,x,val)\r\nimplicit double precision (a-h,o-z)\r\n\r\ninteger, intent(in) :: nints,k\r\ndouble precision, intent(in) :: xscheb(k),ab(2,nints),vals(k,nints)\r\ndouble precision, intent(out) :: val\r\n\r\n!\r\n! Evaluate a function represented via its values at the nodes of the k-point\r\n! Chebyshev grids on a collection of subintervals of [a,b].\r\n!\r\n! Input parameters:\r\n!\r\n! (nints,ab) - arrays specifying the collection of subintervals of [a,b]\r\n! k - the number of terms in the Chebyshev expansions\r\n! xscheb - the nodes of the k-point Clenshaw-Curtis quadrature on [-1,1]\r\n! vals - a (k,nints) array the jth column of which gives the values of the\r\n! function at the nodes of the k-point Chebyshev grid in the jth\r\n! subinterval\r\n! x - the point in [a,b] at which to evaluate the function\r\n!\r\n! Output parameters:\r\n! val - the value of the function at the point x\r\n! \r\n\r\n\r\n!\r\n! Conduct several iterations of a binary search for the interval.\r\n!\r\n\r\neps0 = epsilon(0.0d0)\r\n\r\n\r\nniters = 7\r\nintl = 1\r\nintr = nints\r\n\r\ndo iter=1,niters\r\nint = (intl+intr)/2\r\nc = ab(1,int)\r\nif (x .gt. c) then\r\nintl = int\r\nelse\r\nif (int .gt. 1) intr = int-1\r\nendif\r\nend do\r\n\r\n\r\n!\r\n! Conduct a brute force check from here.\r\n!\r\n\r\ndo int = intl,intr-1\r\nb = ab(2,int)\r\nif (x .le. b) exit\r\nend do\r\n\r\n\r\n!\r\n! Call chebeval to evaluate the expansion and the save the index\r\n! of the interval containing x.\r\n!\r\n\r\na = ab(1,int)\r\nb = ab(2,int)\r\n\r\n\r\n! call chebeval(a,b,k,xscheb,vals(1,int),x,val)\r\n! return\r\nxx = (2*x - (b+a) ) /(b-a)\r\n\r\nsum1=0\r\nsum2=0\r\n\r\ndd1 = 1.0d0\r\n\r\ndo i=1,k\r\ndd=1.0d0\r\nif (i .eq. 1 .OR. i .eq. k) dd = 0.5d0\r\n\r\ndiff = xx-xscheb(i)\r\n\r\n!\r\n! Handle the case in which the target node coincide with one of\r\n! of the Chebyshev nodes.\r\n!\r\n\r\nif(abs(diff) .le. eps0 ) then\r\nval = vals(i,int)\r\nreturn\r\nendif\r\n\r\n!\r\n! Otherwise, construct the sums.\r\n!\r\n\r\ndd = (dd1*dd)/diff\r\ndd1 = - dd1\r\nsum1 = sum1+dd*vals(i,int)\r\nsum2 = sum2+dd\r\ndd = - dd\r\nend do\r\n\r\nval = sum1/sum2\r\n\r\n\r\nend subroutine\r\n\r\n\r\n\r\nsubroutine chebpw_eval2(nints,ab,k,coefs,x,val)\r\nimplicit double precision (a-h,o-z)\r\n\r\ninteger, intent(in) :: nints,k\r\ndouble precision, intent(in) :: ab(2,nints),coefs(k,nints)\r\ndouble precision, intent(out) :: val\r\n\r\n!\r\n! Evaluate a function represented via piecewise chebyshev expansions on\r\n! a collection of subintervals.\r\n!\r\n! Input parameters:\r\n! (nints,ab) - the \r\n! k - an integer specifying the order of the Chebyshev expansions; on\r\n! \r\n! coefs - a (k,nints) array whose jth column specified the coefficients\r\n! of the function's Chebyshev expansion on the jth subinterval\r\n! x - the point at which to evaluate\r\n!\r\n!\r\n! Output parameters:\r\n! val - the value of the function at the point x\r\n! \r\n\r\n\r\ndouble precision :: pols(k)\r\n!\r\n! Conduct several iterations of a binary search for the interval.\r\n!\r\n\r\nniters = 6\r\nintl = 1\r\nintr = nints\r\n\r\ndo iter=1,niters\r\nint = (intl+intr)/2\r\nc = ab(1,int)\r\nif (x .gt. c) then\r\nintl = int\r\nelse\r\nif (int .gt. 1) intr = int-1\r\nendif\r\nend do\r\n\r\n\r\n!\r\n! Conduct a brute force check from here.\r\n!\r\n\r\ndo int = intl,intr-1\r\nb = ab(2,int)\r\nif (x .le. b) exit\r\nend do\r\n\r\na = ab(1,int)\r\nb = ab(2,int)\r\n\r\n\r\n\r\n!\r\n! Evaluate the Chebyshev expansion\r\n!\r\n\r\n\r\nxx = (x - (b+a)/2.0d0) * 2.0d0/(b-a)\r\ncall chebs(xx,k-1,pols)\r\n\r\nval = 0\r\ndo i=1,k\r\nval = val + coefs(i,int)*pols(i)\r\nend do\r\n\r\n\r\nreturn\r\n\r\n! call chebeval2(a,b,k,coefs(1,int),x,val)\r\n\r\n\r\nxx = (x - (b+a)/2.0d0) * 2.0d0/(b-a)\r\nxx2 = 2*xx\r\n\r\nb2 = coefs(k,int)\r\nb1 = xx2*b2+coefs(k-1,int)\r\n\r\ndo i=k-2,2,-1\r\nb0 = coefs(i,int)+xx2*b1-b2\r\nb2 = b1\r\nb1 = b0\r\nend do\r\n\r\nval = b1 * xx + (coefs(1,int)-b2)\r\n\r\nreturn\r\nend subroutine\r\n\r\n\r\nsubroutine write_chebexps(iw,chebdata)\r\nimplicit double precision (a-h,o-z)\r\ntype(chebexps_data) :: chebdata\r\n\r\n\r\nwrite (iw,\"(I8.8)\") chebdata%k\r\nwrite (iw,\"(D30.20)\") chebdata%xs\r\nwrite (iw,\"(D30.20)\") chebdata%whts\r\nwrite (iw,\"(D30.20)\") chebdata%u\r\nwrite (iw,\"(D30.20)\") chebdata%v\r\nwrite (iw,\"(D30.20)\") chebdata%aintl\r\nwrite (iw,\"(D30.20)\") chebdata%aintl2\r\nwrite (iw,\"(D30.20)\") chebdata%aintl3\r\nwrite (iw,\"(D30.20)\") chebdata%aintr\r\nwrite (iw,\"(D30.20)\") chebdata%aintr2\r\nwrite (iw,\"(D30.20)\") chebdata%aintr3\r\n\r\nend subroutine\r\n\r\n\r\nsubroutine read_chebexps(iw,chebdata)\r\nimplicit double precision (a-h,o-z)\r\ntype(chebexps_data) :: chebdata\r\n\r\nread (iw,\"(I8.8)\") chebdata%k\r\nk = chebdata%k\r\nallocate(chebdata%xs(k),chebdata%whts(k))\r\nallocate(chebdata%u(k,k),chebdata%v(k,k))\r\nallocate(chebdata%aintl(k,k),chebdata%aintl2(k,k),chebdata%aintl3(k,k))\r\nallocate(chebdata%aintr(k,k),chebdata%aintr2(k,k),chebdata%aintr3(k,k))\r\nread (iw,\"(D30.20)\") chebdata%xs\r\nread (iw,\"(D30.20)\") chebdata%whts\r\nread (iw,\"(D30.20)\") chebdata%u\r\nread (iw,\"(D30.20)\") chebdata%v\r\nread (iw,\"(D30.20)\") chebdata%aintl\r\nread (iw,\"(D30.20)\") chebdata%aintl2\r\nread (iw,\"(D30.20)\") chebdata%aintl3\r\nread (iw,\"(D30.20)\") chebdata%aintr\r\nread (iw,\"(D30.20)\") chebdata%aintr2\r\nread (iw,\"(D30.20)\") chebdata%aintr3\r\n\r\nend subroutine\r\n\r\n\r\nend module\r\n", "meta": {"hexsha": "c6bf7c5603376c731c69942317be651f3943b2d5", "size": 22315, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "v2/specFun/fastJacobiTransform/src/chebyshev.f90", "max_stars_repo_name": "ButterflyLab/ButterflyLab", "max_stars_repo_head_hexsha": "fb152ba8f2c5dbdc2b15b516023516a5b538ef78", "max_stars_repo_licenses": ["0BSD"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2018-01-04T20:47:01.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-18T14:16:56.000Z", "max_issues_repo_path": "v2/specFun/fastJacobiTransform/src/chebyshev.f90", "max_issues_repo_name": "ButterflyLab/ButterflyLab", "max_issues_repo_head_hexsha": "fb152ba8f2c5dbdc2b15b516023516a5b538ef78", "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": "v2/specFun/fastJacobiTransform/src/chebyshev.f90", "max_forks_repo_name": "ButterflyLab/ButterflyLab", "max_forks_repo_head_hexsha": "fb152ba8f2c5dbdc2b15b516023516a5b538ef78", "max_forks_repo_licenses": ["0BSD"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-04-13T11:14:44.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-16T16:19:45.000Z", "avg_line_length": 23.6889596603, "max_line_length": 93, "alphanum_fraction": 0.6232578983, "num_tokens": 7310, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897459384731, "lm_q2_score": 0.7217432003123989, "lm_q1q2_score": 0.6790086020547222}} {"text": "!program new_astro\nsubroutine new_astro(dd,astro,ader)\n!c\tthis subroutine calculates the following five ephermides\n!c\tof the sun and moon\n!c\th = mean longitude of the sum\n!c\tpp = mean longitude of the solar perigee\n!c\ts = mean longitude of the moon\n!c\tp = mean longitude of the lunar perigee\n!c\tnp = negative of the longitude of the mean ascending node\n!c\tand their rates of change.\n!c\tUnits for the ephermides are cycles and for their derivatives\n!c\tare cycles/365 days\n!c\tThe formulae for calculating this ephermides were taken from\n!c\tpages 98 and 107 of the Explanatory Supplement to the\n!c\tAstronomical Ephermeris and the American Ephermis and\n!c\tNautical Almanac (1961)\n\n real :: d1, d,s,h,p,np,pp,dc,tau,dtau\n integer ::sc,hc,pc,npc,ppc\n real,dimension(4) :: args,dargs\n integer :: kd0\n real,dimension(6) :: astro,ader\n real*8 :: dd\n\n!Compute number of days from epoch of 12:00 UT Dec 31, 1899.\n ! (January 0.5 1900 ET)\n call gday(31,12,99,18,kd0,ier)\n if (ier.lt.0) then\n ierr=-1\n return\n end if\n d1=dd-dfloat(kd0)-0.5d0 ! -0.5 skyldes tidpunktet i kommentaren over\n d=d1/10000.0\n\n! Compute astronomical constants at time d1.\n args(1)=d1\n args(2)=d*d\n args(3)=d*d*d\n\n\n! These are the coefficients of the formulas in the Explan. Suppl.\n s = (270.434164d0 + 13.1763965268d0*args(1) - &\n 0.000085d0*args(2) + 0.000000039d0*args(3))/360.0d0\n h = (279.696678d0 + 0.9856473354d0*args(1) + &\n 0.00002267d0*args(2))/360.0d0\n p = (334.329556d0 + 0.1114040803d0*args(1) - &\n 0.0007739d0*args(2) - 0.00000026d0*args(3))/360.0d0\n np = (-259.183275d0 + 0.0529539222d0*args(1) - &\n 0.0001557d0*args(2) - 0.00000005d0*args(3))/360.0d0\n pp = (281.220844d0 + 0.0000470684d0*args(1) + & \n 0.0000339d0*args(2) + 0.000000070d0*args(3))/360.0d0\n\n\n sc=floor(s)\n hc=floor(h)\n pc=floor(p)\n npc=floor(np)\n ppc=floor(pp)\n ! Compute the parameters; we only need the factional part of the cycle.\n\n astro(2)=s-floor(s)\n astro(3)=h-floor(h)\n astro(4)=p-floor(p)\n astro(5)=np-floor(np)\n astro(6)=pp-floor(pp)\n\n ! Compute lunar time tau, based on fractional part of solar day.\n ! We add the hour angle to the longitude of the sun and subtract the\n ! longitude of the moon.\n dc=dd-floor(dd)\n tau=dc+astro(3)-astro(2)\n astro(1)=tau\n ! Compute rates of change.\n dargs(1)= 0.0\n dargs(2)= 1.0\n dargs(3)= 2.0E-4*d\n dargs(4)= 3.0E-4*d*d\n\n ader(2) = (270.434164d0*dargs(1) + 13.1763965268d0*dargs(2) - &\n 0.000085d0*dargs(3) + 0.000000039d0*dargs(4))/360.0d0\n ader(3) = (279.696678d0*dargs(1) + 0.9856473354d0*dargs(2) + &\n 0.00002267d0*dargs(3))/360.0d0\n ader(4) = (334.329556d0*dargs(1) + 0.1114040803d0*dargs(2) - &\n 0.0007739d0*dargs(3) - 0.00000026d0*dargs(4))/360.0d0\n ader(5) = (-259.183275d0*dargs(1) + 0.0529539222d0*dargs(2) - &\n 0.0001557d0*dargs(3) - 0.00000005d0*dargs(4))/360.0d0\n ader(6) = (281.220844d0*dargs(1) + 0.0000470684d0*dargs(2) + & \n 0.0000339d0*dargs(3) + 0.000000070d0*dargs(4))/360.0d0\n dtau=1.0+ader(3)-ader(1)\n ader(1)=dtau\nend subroutine\n", "meta": {"hexsha": "ac20befa11ff9ff2188b8149e5a4f0ecee4358cb", "size": 3172, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "create_tides_ROMS/Tides/new_astro.f90", "max_stars_repo_name": "jvmcgovern/romstools_MI", "max_stars_repo_head_hexsha": "57c70c2f630a190fd23ac15ed2ce1b2fae949660", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 18, "max_stars_repo_stars_event_min_datetime": "2015-03-02T14:27:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-16T05:53:08.000Z", "max_issues_repo_path": "create_tides_ROMS/Tides/new_astro.f90", "max_issues_repo_name": "jvmcgovern/romstools_MI", "max_issues_repo_head_hexsha": "57c70c2f630a190fd23ac15ed2ce1b2fae949660", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2016-08-08T12:21:45.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-03T22:40:52.000Z", "max_forks_repo_path": "create_tides_ROMS/Tides/new_astro.f90", "max_forks_repo_name": "jvmcgovern/romstools_MI", "max_forks_repo_head_hexsha": "57c70c2f630a190fd23ac15ed2ce1b2fae949660", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2015-10-05T15:36:28.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-28T16:46:54.000Z", "avg_line_length": 34.4782608696, "max_line_length": 73, "alphanum_fraction": 0.6462799496, "num_tokens": 1322, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072386, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6789639142022654}} {"text": " SUBROUTINE tridag(a,b,c,r,u,n)\r\n INTEGER n,NMAX\r\n REAL a(n),b(n),c(n),r(n),u(n)\r\n PARAMETER (NMAX=500)\r\n INTEGER j\r\n REAL bet,gam(NMAX)\r\n if(b(1).eq.0.)pause 'tridag: rewrite equations'\r\n bet=b(1)\r\n u(1)=r(1)/bet\r\n do 11 j=2,n\r\n gam(j)=c(j-1)/bet\r\n bet=b(j)-a(j)*gam(j)\r\n if(bet.eq.0.)pause 'tridag failed'\r\n u(j)=(r(j)-a(j)*u(j-1))/bet\r\n11 continue\r\n do 12 j=n-1,1,-1\r\n u(j)=u(j)-gam(j+1)*u(j+1)\r\n12 continue\r\n return\r\n END\r\n", "meta": {"hexsha": "f3dca840017f158f4ace2cc0a0369ecb66adf21e", "size": 533, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/tridag.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/tridag.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/tridag.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.380952381, "max_line_length": 54, "alphanum_fraction": 0.4634146341, "num_tokens": 201, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026528034426, "lm_q2_score": 0.7401743677704878, "lm_q1q2_score": 0.6789639110929794}} {"text": "C\nC $Id: moprin.f,v 1.4 2008-09-18 00:42:18 kennison Exp $\nC\nC Copyright (C) 2000\nC University Corporation for Atmospheric Research\nC All Rights Reserved\nC\nC The use of this Software is governed by a License Agreement.\nC\n SUBROUTINE MOPRIN (UVAL,VVAL,DLAT,DLON)\nC\n DOUBLE PRECISION UVAL,VVAL,DLAT,DLON\nC\nC The subroutine MOPRIN implements a closed form of the true Mollweide\nC projection, using formulas given on \"Wolfram MathWorld\".\nC\nC UVAL and VVAL are input values of U and V, in the projection plane.\nC DLAT and DLON are output values of latitude and longitude, in radians.\nC\nC The common block MAPCM0 contains mathematical constants.\nC\n COMMON /MAPCM0/ COS1,DTOR,DTRH,OOPI,PI,PIOF,PIOT,RTDD,RTOD,\n + SROT,SIN1,TOPI,TSRT\n DOUBLE PRECISION COS1,DTOR,DTRH,OOPI,PI,PIOF,PIOT,RTDD,RTOD,\n + SROT,SIN1,TOPI,TSRT\n SAVE /MAPCM0/\nC\nC Local variables.\nC\n DOUBLE PRECISION THTA,TVAL\nC\nC First, we must check the point (UVAL,VVAL) to see if it lies in the\nC ellipse occupied by the projection of the globe. If not, we return\nC the value \"1.D12\" to signal that fact.\nC\n IF ((UVAL/TSRT)**2+(VVAL/SROT)**2-1.D0.GT.1.D-12) THEN\n DLAT=1.D12\n DLON=1.D12\n RETURN\n END IF\nC\nC Do the math.\nC\n THTA=ASIN(MAX(-1.D0,MIN(+1.D0,VVAL/SROT)))\nC\n DLAT=ASIN(MAX(-1.D0,MIN(+1.D0,(2.D0*THTA+SIN(2.D0*THTA))/PI)))\n DLON=PI*UVAL/(TSRT*COS(THTA))\nC\n RETURN\nC\n END\n", "meta": {"hexsha": "31bd98780afdf805fc438663392a7ef74417f823", "size": 1534, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ncarg2d/src/libncarg/ezmap/moprin.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "ncarg2d/src/libncarg/ezmap/moprin.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "ncarg2d/src/libncarg/ezmap/moprin.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 29.5, "max_line_length": 72, "alphanum_fraction": 0.6447196871, "num_tokens": 527, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072385, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.678963908944771}} {"text": " SUBROUTINE trigfact(nu, nv, nvh, nuvh, mf, nf, cmunv, smunv,\n 1 cu, su, cv, sv)\n USE stel_kinds\n IMPLICIT NONE\nC-----------------------------------------------\nC D u m m y A r g u m e n t s\nC-----------------------------------------------\n INTEGER :: nu, nv, nvh, nuvh, mf, nf\n REAL(rprec), DIMENSION(nuvh,0:mf,-nf:nf) :: cmunv, smunv\n REAL(rprec), DIMENSION(nu,0:mf) :: cu, su\n REAL(rprec), DIMENSION(nvh,0:nf) :: cv, sv\nC-----------------------------------------------\nC L o c a l P a r a m e t e r s\nC-----------------------------------------------\n REAL(rprec), PARAMETER :: one = 1, zero = 0\nC-----------------------------------------------\nC L o c a l V a r i a b l e s\nC-----------------------------------------------\n INTEGER :: i, j, m, n, kv, ku\n REAL(rprec) :: pi2, du, dv, cc, ss, sc, cs\nC-----------------------------------------------\nc Calculate SIN/COS(m*u+n*nfp*v) factors for USE in FSIN transform\nc efficiently, i.e., SIN and COS are ONLY called once.\nc Must have nuvh=nu*(1+nv/2) = nu*nvh\nc nfp is the number of field periods\nc\nc Note: The m,n dimensions of SIN/COS are different here from\nc the version in fourfast.f\nc this version allows you to calculate all the sin/cos factors\nc at one time using the largest (m,n) and\nc then use them for all smaller (m,n) as long as nu,nv are same\nc\n pi2 = 4*ASIN(one)\n\n cu(:,0) = one !at m=0, m*u=0 for ALL u\n cv(:,0) = one\n su(:,0) = zero\n sv(:,0) = zero\n\n cu(1,:mf) = one !at u=0, m*u=0 for ALL m\n cv(1,:nf) = one !remember, u(i)=du*(i-1), so u=0 at i=1\n su(1,:mf) = zero\n sv(1,:nf) = zero\n\n du = pi2/nu !basic steps in u and v\n dv = pi2/nv !nfp factors cancelled out...\n cu(2,1) = COS(du) !These are the ONLY calls to COS/sin\n su(2,1) = SIN(du) !remember, u(i)=du*(i-1)\n cv(2,1) = COS(dv) !so u=du and v=dv at i=2\n sv(2,1) = SIN(dv)\n\nc.... Next, Calculate COS/SIN(m*u)=cos/SIN(u) for m=1\nc USE SIN/COS(du) to calculate SIN/COS(u) : u=i*du\n DO i = 3, nu\n j = i - 1\n cu(i,1) = cu(2,1)*cu(j,1) - su(2,1)*su(j,1)\n su(i,1) = su(2,1)*cu(j,1) + cu(2,1)*su(j,1)\n END DO\n\nc And calculate COS/SIN(n*v)=cos/SIN(v) for n=1\nc USE SIN/COS(dv) to calculate SIN/COS(v) : v=i*dv\n DO i = 3, nvh\n j = i - 1\n cv(i,1) = cv(2,1)*cv(j,1) - sv(2,1)*sv(j,1)\n sv(i,1) = sv(2,1)*cv(j,1) + cv(2,1)*sv(j,1)\n END DO\n\nc.... Then USE SIN/COS(u) to calculate SIN/COS(m*u) for ALL u\n DO i = 2, mf\n j = i - 1\n cu(:,i) = cu(:,1)*cu(:,j) - su(:,1)*su(:,j)\n su(:,i) = su(:,1)*cu(:,j) + cu(:,1)*su(:,j)\n END DO\n\nc And USE SIN/COS(v) to calculate SIN/COS(n*v) for ALL v\n DO i = 2, nf\n j = i - 1\n cv(:,i) = cv(:,1)*cv(:,j) - sv(:,1)*sv(:,j)\n sv(:,i) = sv(:,1)*cv(:,j) + cv(:,1)*sv(:,j)\n END DO\n\nc..... Now ALL the SIN/COS(m*u) and SIN/COS(n*v) are READy, so\nc Calculate SIN/COS(m*u+n*v) at ALL u,v for m=0,mf; n=-nf,nf\n DO m = 0, mf\n DO n = 0, nf\n i = 0 !i is REAL space INDEX 1,nuvh\n DO kv = 1, nvh\n DO ku = 1, nu\n i = i + 1 !i goes from 1 to nuvh=nu*(1+nv/2)\n cc = cu(ku,m)*cv(kv,n)\n ss = su(ku,m)*sv(kv,n)\n sc = su(ku,m)*cv(kv,n)\n cs = cu(ku,m)*sv(kv,n)\n cmunv(i,m,n) = cc - ss\n cmunv(i,m,(-n)) = cc + ss\n smunv(i,m,n) = sc + cs\n smunv(i,m,(-n)) = sc - cs\n END DO\n END DO\n END DO !ku loop\n END DO !kv loop\n\n END SUBROUTINE trigfact\n", "meta": {"hexsha": "02f82bb6a60369f28540d4ce8ddb044c6974cb0c", "size": 4075, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "LIBSTELL/Sources/FFTpack/trigfact.f", "max_stars_repo_name": "jonathanschilling/VMEC_8_00", "max_stars_repo_head_hexsha": "25519df38bf81bcb673dd9374bda11988de2d940", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2020-05-08T01:47:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T10:35:28.000Z", "max_issues_repo_path": "LIBSTELL/Sources/FFTpack/trigfact.f", "max_issues_repo_name": "jonathanschilling/VMEC_8_00", "max_issues_repo_head_hexsha": "25519df38bf81bcb673dd9374bda11988de2d940", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 77, "max_issues_repo_issues_event_min_datetime": "2020-05-08T07:18:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:20:33.000Z", "max_forks_repo_path": "LIBSTELL/Sources/FFTpack/trigfact.f", "max_forks_repo_name": "jonathanschilling/VMEC_8_00", "max_forks_repo_head_hexsha": "25519df38bf81bcb673dd9374bda11988de2d940", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-02-10T13:47:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T12:53:43.000Z", "avg_line_length": 39.1826923077, "max_line_length": 87, "alphanum_fraction": 0.4019631902, "num_tokens": 1359, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026573249611, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6789639039247032}} {"text": " subroutine idz_houseapp(n,vn,u,ifrescal,scal,v)\nc\nc applies the Householder matrix\nc identity_matrix - scal * vn * adjoint(vn)\nc to the vector u, yielding the vector v;\nc\nc scal = 2/(1 + |vn(2)|^2 + ... + |vn(n)|^2)\nc when vn(2), ..., vn(n) don't all vanish;\nc\nc scal = 0\nc when vn(2), ..., vn(n) do all vanish\nc (including when n = 1).\nc\nc input:\nc n -- size of vn, u, and v, though the indexing on vn goes\nc from 2 to n\nc vn -- components 2 to n of the Householder vector vn;\nc vn(1) is assumed to be 1 \nc u -- vector to be transformed\nc ifrescal -- set to 1 to recompute scal from vn(2), ..., vn(n);\nc set to 0 to use scal as input\nc scal -- see the entry for ifrescal in the decription\nc of the input\nc\nc output:\nc scal -- see the entry for ifrescal in the decription\nc of the input\nc v -- result of applying the Householder matrix to u;\nc it's O.K. to have v be the same as u\nc in order to apply the matrix to the vector in place\nc\nc reference:\nc Golub and Van Loan, \"Matrix Computations,\" 3rd edition,\nc Johns Hopkins University Press, 1996, Chapter 5.\nc\n implicit none\n save\n integer n,k,ifrescal\n real*8 scal,sum\n complex*16 vn(2:*),u(n),v(n),fact\nc\nc\nc Get out of this routine if n = 1.\nc\n if(n .eq. 1) then\n v(1) = u(1)\n return\n endif\nc\nc\n if(ifrescal .eq. 1) then\nc\nc\nc Calculate |vn(2)|^2 + ... + |vn(n)|^2.\nc\n sum = 0\n do k = 2,n\n sum = sum+vn(k)*conjg(vn(k))\n enddo ! k\nc\nc\nc Calculate scal.\nc\n if(sum .eq. 0) scal = 0\n if(sum .ne. 0) scal = 2/(1+sum)\nc\nc\n endif\nc\nc\nc Calculate fact = scal * adjoint(vn) * u.\nc\n fact = u(1)\nc\n do k = 2,n\n fact = fact+conjg(vn(k))*u(k)\n enddo ! k\nc\n fact = fact*scal\nc\nc\nc Subtract fact*vn from u, yielding v.\nc \n v(1) = u(1) - fact\nc\n do k = 2,n\n v(k) = u(k) - fact*vn(k)\n enddo ! k\nc\nc\n return\n end\nc\nc\nc\nc\n", "meta": {"hexsha": "65f358ebad3cfb2737deb3e24c450697a1f9f118", "size": 2238, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "contrib/python/scipy/scipy/linalg/src/id_dist/src/idz_house_subr_0.f", "max_stars_repo_name": "ibr11/catboost", "max_stars_repo_head_hexsha": "842a25b4fb856a61564b163b16a3f49ba35fdc14", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 6989, "max_stars_repo_stars_event_min_datetime": "2017-07-18T06:23:18.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T15:58:36.000Z", "max_issues_repo_path": "contrib/python/scipy/scipy/linalg/src/id_dist/src/idz_house_subr_0.f", "max_issues_repo_name": "birichie/catboost", "max_issues_repo_head_hexsha": "de75c6af12cf490700e76c22072fbdc15b35d679", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1978, "max_issues_repo_issues_event_min_datetime": "2017-07-18T09:17:58.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T14:28:43.000Z", "max_forks_repo_path": "contrib/python/scipy/scipy/linalg/src/id_dist/src/idz_house_subr_0.f", "max_forks_repo_name": "birichie/catboost", "max_forks_repo_head_hexsha": "de75c6af12cf490700e76c22072fbdc15b35d679", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1228, "max_forks_repo_forks_event_min_datetime": "2017-07-18T09:03:13.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T05:57:40.000Z", "avg_line_length": 23.0721649485, "max_line_length": 70, "alphanum_fraction": 0.5071492404, "num_tokens": 733, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677660619633, "lm_q2_score": 0.8006920092299293, "lm_q1q2_score": 0.6789610143703682}} {"text": "program bit_functions ! GitHub FortranTip bit_func.f90\r\nimplicit none\r\n! use 1-byte integers for illustration\r\ninteger, parameter :: ikind = selected_int_kind(1)\r\ninteger (kind=ikind) :: i, j, nbits\r\ninteger (kind=ikind), allocatable :: ivec(:)\r\ninteger, parameter :: ni = 4\r\nlogical, allocatable :: bits(:)\r\nnbits = bit_size(i)\r\nallocate (bits(nbits))\r\nivec = [(i,i=nbits-1,0,-1)]\r\nprint \"('bit representation of ',i0,'-bit integers')\",nbits\r\nprint \"(14x,'bit position')\"\r\nprint \"(9x,'i',2x,*(i3))\",ivec\r\ndo i=-2,ni\r\n print \"(i10,2x,*(i3))\",i,merge(1,0,btest(i,ivec))\r\nend do\r\nprint \"(/,a,*(1x,i0))\", &\r\n \"not(1), iand(2,3), ior(2,3), ieor(2,3) =\", &\r\n not(1), iand(2,3), ior(2,3), ieor(2,3)\r\nend program bit_functions\r\n! output:\r\n! bit representation of 8-bit integers\r\n! bit position\r\n! i 7 6 5 4 3 2 1 0\r\n! -2 1 1 1 1 1 1 1 0\r\n! -1 1 1 1 1 1 1 1 1\r\n! 0 0 0 0 0 0 0 0 0\r\n! 1 0 0 0 0 0 0 0 1\r\n! 2 0 0 0 0 0 0 1 0\r\n! 3 0 0 0 0 0 0 1 1\r\n! 4 0 0 0 0 0 1 0 0\r\n! \r\n! not(1), iand(2,3), ior(2,3), ieor(2,3) = -2 2 3 1", "meta": {"hexsha": "1fe667cb7b5cd1ddb2d7e9eab13ef0c92e84c8cf", "size": 1184, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "bit_func.f90", "max_stars_repo_name": "awvwgk/FortranTip", "max_stars_repo_head_hexsha": "3810038667e3d5d2ab33c39d4bd0f41870025420", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "bit_func.f90", "max_issues_repo_name": "awvwgk/FortranTip", "max_issues_repo_head_hexsha": "3810038667e3d5d2ab33c39d4bd0f41870025420", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "bit_func.f90", "max_forks_repo_name": "awvwgk/FortranTip", "max_forks_repo_head_hexsha": "3810038667e3d5d2ab33c39d4bd0f41870025420", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.8235294118, "max_line_length": 60, "alphanum_fraction": 0.5126689189, "num_tokens": 553, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677660619634, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.6789610123539079}} {"text": "program primeNo\n integer :: n;\n logical isPrime /.true./\n integer :: i, j;\n\n print *, \"Enter value of n...\";\n read *, n;\n\n print *, \"Prime no upto n : \";\n do i = 2, n, 1\n isPrime = .true.;\n do j = 2, int(sqrt(real(i))), 1 ! loop must have integer upper limit and sqrt takes real agruments\n if(mod(i,j) .eq. 0) then\n isPrime = .false.;\n exit;\n end if;\n end do\n \n if(isPrime) then\n print *, i;\n end if;\n end do;\nend program primeNo\n", "meta": {"hexsha": "8727ad3cc6490fb164bb6f5ef24628aefe0bc416", "size": 559, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "III-sem/NumericalMethod/FortranProgram/primeNumbers.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/primeNumbers.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/primeNumbers.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": 23.2916666667, "max_line_length": 106, "alphanum_fraction": 0.4704830054, "num_tokens": 152, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677430095496, "lm_q2_score": 0.8006920044739461, "lm_q1q2_score": 0.6789609918795643}} {"text": "module ranges\n\n use globals\n implicit none\n\ncontains\n\n pure subroutine linrange(x, xlo, xhi)\n real(r64), intent(out) :: x(:)\n real(r64), intent(in) :: xlo, xhi\n integer :: n, i\n real(r64) :: t\n\n n = size(x)\n\n do concurrent (i = 1:n)\n t = real(i - 1, r64) / real(n - 1, r64)\n x(i) = xlo * (1 - t) + xhi * t\n end do\n end subroutine\n\n pure subroutine logrange(x, xlo, xhi)\n real(r64), intent(out) :: x(:)\n real(r64), intent(in) :: xlo, xhi\n\n call linrange(x, log(xlo), log(xhi))\n x(:) = exp(x)\n end subroutine\n\nend module", "meta": {"hexsha": "85bc289432caa514fe8d05c856c1cb7549110261", "size": 567, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/ranges.f90", "max_stars_repo_name": "gronki/diskvert", "max_stars_repo_head_hexsha": "459238a46fc173c9fec3ff609cd42595bbc0c858", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/ranges.f90", "max_issues_repo_name": "gronki/diskvert", "max_issues_repo_head_hexsha": "459238a46fc173c9fec3ff609cd42595bbc0c858", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/ranges.f90", "max_forks_repo_name": "gronki/diskvert", "max_forks_repo_head_hexsha": "459238a46fc173c9fec3ff609cd42595bbc0c858", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.9, "max_line_length": 45, "alphanum_fraction": 0.5537918871, "num_tokens": 201, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677430095495, "lm_q2_score": 0.8006920044739461, "lm_q1q2_score": 0.6789609918795642}} {"text": " subroutine dqc25f(f,a,b,omega,integr,nrmom,maxp1,ksave,result,\n * abserr,neval,resabs,resasc,momcom,chebmo)\nc***begin prologue dqc25f\nc***date written 810101 (yymmdd)\nc***revision date 830518 (yymmdd)\nc***category no. h2a2a2\nc***keywords integration rules for functions with cos or sin\nc factor, clenshaw-curtis, gauss-kronrod\nc***author piessens,robert,appl. math. & progr. div. - k.u.leuven\nc de doncker,elise,appl. math. & progr. div. - k.u.leuven\nc***purpose to compute the integral i=integral of f(x) over (a,b)\nc where w(x) = cos(omega*x) or w(x)=sin(omega*x) and to\nc compute j = integral of abs(f) over (a,b). for small value\nc of omega or small intervals (a,b) the 15-point gauss-kronro\nc rule is used. otherwise a generalized clenshaw-curtis\nc method is used.\nc***description\nc\nc integration rules for functions with cos or sin factor\nc standard fortran subroutine\nc double precision version\nc\nc parameters\nc on entry\nc f - double precision\nc function subprogram defining the integrand\nc function f(x). the actual name for f needs to\nc be declared e x t e r n a l in the calling program.\nc\nc a - double precision\nc lower limit of integration\nc\nc b - double precision\nc upper limit of integration\nc\nc omega - double precision\nc parameter in the weight function\nc\nc integr - integer\nc indicates which weight function is to be used\nc integr = 1 w(x) = cos(omega*x)\nc integr = 2 w(x) = sin(omega*x)\nc\nc nrmom - integer\nc the length of interval (a,b) is equal to the length\nc of the original integration interval divided by\nc 2**nrmom (we suppose that the routine is used in an\nc adaptive integration process, otherwise set\nc nrmom = 0). nrmom must be zero at the first call.\nc\nc maxp1 - integer\nc gives an upper bound on the number of chebyshev\nc moments which can be stored, i.e. for the\nc intervals of lengths abs(bb-aa)*2**(-l),\nc l = 0,1,2, ..., maxp1-2.\nc\nc ksave - integer\nc key which is one when the moments for the\nc current interval have been computed\nc\nc on return\nc result - double precision\nc approximation to the integral i\nc\nc abserr - double precision\nc estimate of the modulus of the absolute\nc error, which should equal or exceed abs(i-result)\nc\nc neval - integer\nc number of integrand evaluations\nc\nc resabs - double precision\nc approximation to the integral j\nc\nc resasc - double precision\nc approximation to the integral of abs(f-i/(b-a))\nc\nc on entry and return\nc momcom - integer\nc for each interval length we need to compute the\nc chebyshev moments. momcom counts the number of\nc intervals for which these moments have already been\nc computed. if nrmom.lt.momcom or ksave = 1, the\nc chebyshev moments for the interval (a,b) have\nc already been computed and stored, otherwise we\nc compute them and we increase momcom.\nc\nc chebmo - double precision\nc array of dimension at least (maxp1,25) containing\nc the modified chebyshev moments for the first momcom\nc momcom interval lengths\nc\nc ......................................................................\nc***references (none)\nc***routines called d1mach,dgtsl,dqcheb,dqk15w,dqwgtf\nc***end prologue dqc25f\nc\n double precision a,abserr,ac,an,an2,as,asap,ass,b,centr,chebmo,\n * cheb12,cheb24,conc,cons,cospar,d,dabs,dcos,dsin,dqwgtf,d1,\n * d1mach,d2,estc,ests,f,fval,hlgth,oflow,omega,parint,par2,par22,\n * p2,p3,p4,resabs,resasc,resc12,resc24,ress12,ress24,result,\n * sinpar,v,x\n integer i,iers,integr,isym,j,k,ksave,m,momcom,neval,maxp1,\n * noequ,noeq1,nrmom\nc\n dimension chebmo(maxp1,25),cheb12(13),cheb24(25),d(25),d1(25),\n * d2(25),fval(25),v(28),x(11)\nc\n external f,dqwgtf\nc\nc the vector x contains the values cos(k*pi/24)\nc k = 1, ...,11, to be used for the chebyshev expansion of f\nc\n data x(1) / 0.9914448613 7381041114 4557526928 563d0 /\n data x(2) / 0.9659258262 8906828674 9743199728 897d0 /\n data x(3) / 0.9238795325 1128675612 8183189396 788d0 /\n data x(4) / 0.8660254037 8443864676 3723170752 936d0 /\n data x(5) / 0.7933533402 9123516457 9776961501 299d0 /\n data x(6) / 0.7071067811 8654752440 0844362104 849d0 /\n data x(7) / 0.6087614290 0872063941 6097542898 164d0 /\n data x(8) / 0.5000000000 0000000000 0000000000 000d0 /\n data x(9) / 0.3826834323 6508977172 8459984030 399d0 /\n data x(10) / 0.2588190451 0252076234 8898837624 048d0 /\n data x(11) / 0.1305261922 2005159154 8406227895 489d0 /\nc\nc list of major variables\nc -----------------------\nc\nc centr - mid point of the integration interval\nc hlgth - half-length of the integration interval\nc fval - value of the function f at the points\nc (b-a)*0.5*cos(k*pi/12) + (b+a)*0.5, k = 0, ..., 24\nc cheb12 - coefficients of the chebyshev series expansion\nc of degree 12, for the function f, in the\nc interval (a,b)\nc cheb24 - coefficients of the chebyshev series expansion\nc of degree 24, for the function f, in the\nc interval (a,b)\nc resc12 - approximation to the integral of\nc cos(0.5*(b-a)*omega*x)*f(0.5*(b-a)*x+0.5*(b+a))\nc over (-1,+1), using the chebyshev series\nc expansion of degree 12\nc resc24 - approximation to the same integral, using the\nc chebyshev series expansion of degree 24\nc ress12 - the analogue of resc12 for the sine\nc ress24 - the analogue of resc24 for the sine\nc\nc\nc machine dependent constant\nc --------------------------\nc\nc oflow is the largest positive magnitude.\nc\nc***first executable statement dqc25f\n oflow = d1mach(2)\nc\n centr = 0.5d+00*(b+a)\n hlgth = 0.5d+00*(b-a)\n parint = omega*hlgth\nc\nc compute the integral using the 15-point gauss-kronrod\nc formula if the value of the parameter in the integrand\nc is small.\nc\n if(dabs(parint).gt.0.2d+01) go to 10\n call dqk15w(f,dqwgtf,omega,p2,p3,p4,integr,a,b,result,\n * abserr,resabs,resasc)\n neval = 15\n go to 170\nc\nc compute the integral using the generalized clenshaw-\nc curtis method.\nc\n 10 conc = hlgth*dcos(centr*omega)\n cons = hlgth*dsin(centr*omega)\n resasc = oflow\n neval = 25\nc\nc check whether the chebyshev moments for this interval\nc have already been computed.\nc\n if(nrmom.lt.momcom.or.ksave.eq.1) go to 120\nc\nc compute a new set of chebyshev moments.\nc\n m = momcom+1\n par2 = parint*parint\n par22 = par2+0.2d+01\n sinpar = dsin(parint)\n cospar = dcos(parint)\nc\nc compute the chebyshev moments with respect to cosine.\nc\n v(1) = 0.2d+01*sinpar/parint\n v(2) = (0.8d+01*cospar+(par2+par2-0.8d+01)*sinpar/parint)/par2\n v(3) = (0.32d+02*(par2-0.12d+02)*cospar+(0.2d+01*\n * ((par2-0.80d+02)*par2+0.192d+03)*sinpar)/parint)/(par2*par2)\n ac = 0.8d+01*cospar\n as = 0.24d+02*parint*sinpar\n if(dabs(parint).gt.0.24d+02) go to 30\nc\nc compute the chebyshev moments as the solutions of a\nc boundary value problem with 1 initial value (v(3)) and 1\nc end value (computed using an asymptotic formula).\nc\n noequ = 25\n noeq1 = noequ-1\n an = 0.6d+01\n do 20 k = 1,noeq1\n an2 = an*an\n d(k) = -0.2d+01*(an2-0.4d+01)*(par22-an2-an2)\n d2(k) = (an-0.1d+01)*(an-0.2d+01)*par2\n d1(k+1) = (an+0.3d+01)*(an+0.4d+01)*par2\n v(k+3) = as-(an2-0.4d+01)*ac\n an = an+0.2d+01\n 20 continue\n an2 = an*an\n d(noequ) = -0.2d+01*(an2-0.4d+01)*(par22-an2-an2)\n v(noequ+3) = as-(an2-0.4d+01)*ac\n v(4) = v(4)-0.56d+02*par2*v(3)\n ass = parint*sinpar\n asap = (((((0.210d+03*par2-0.1d+01)*cospar-(0.105d+03*par2\n * -0.63d+02)*ass)/an2-(0.1d+01-0.15d+02*par2)*cospar\n * +0.15d+02*ass)/an2-cospar+0.3d+01*ass)/an2-cospar)/an2\n v(noequ+3) = v(noequ+3)-0.2d+01*asap*par2*(an-0.1d+01)*\n * (an-0.2d+01)\nc\nc solve the tridiagonal system by means of gaussian\nc elimination with partial pivoting.\nc\nc*** call to dgtsl has been replaced by call to\nc*** lapack routine dgtsv\nc\nc call dgtsl(noequ,d1,d,d2,v(4),iers)\n call dgtsv(noequ,1,d1(2:),d,d2(:noequ-1),v(4),noequ,iers)\n go to 50\nc\nc compute the chebyshev moments by means of forward\nc recursion.\nc\n 30 an = 0.4d+01\n do 40 i = 4,13\n an2 = an*an\n v(i) = ((an2-0.4d+01)*(0.2d+01*(par22-an2-an2)*v(i-1)-ac)\n * +as-par2*(an+0.1d+01)*(an+0.2d+01)*v(i-2))/\n * (par2*(an-0.1d+01)*(an-0.2d+01))\n an = an+0.2d+01\n 40 continue\n 50 do 60 j = 1,13\n chebmo(m,2*j-1) = v(j)\n 60 continue\nc\nc compute the chebyshev moments with respect to sine.\nc\n v(1) = 0.2d+01*(sinpar-parint*cospar)/par2\n v(2) = (0.18d+02-0.48d+02/par2)*sinpar/par2\n * +(-0.2d+01+0.48d+02/par2)*cospar/parint\n ac = -0.24d+02*parint*cospar\n as = -0.8d+01*sinpar\n if(dabs(parint).gt.0.24d+02) go to 80\nc\nc compute the chebyshev moments as the solutions of a boundary\nc value problem with 1 initial value (v(2)) and 1 end value\nc (computed using an asymptotic formula).\nc\n an = 0.5d+01\n do 70 k = 1,noeq1\n an2 = an*an\n d(k) = -0.2d+01*(an2-0.4d+01)*(par22-an2-an2)\n d2(k) = (an-0.1d+01)*(an-0.2d+01)*par2\n d1(k+1) = (an+0.3d+01)*(an+0.4d+01)*par2\n v(k+2) = ac+(an2-0.4d+01)*as\n an = an+0.2d+01\n 70 continue\n an2 = an*an\n d(noequ) = -0.2d+01*(an2-0.4d+01)*(par22-an2-an2)\n v(noequ+2) = ac+(an2-0.4d+01)*as\n v(3) = v(3)-0.42d+02*par2*v(2)\n ass = parint*cospar\n asap = (((((0.105d+03*par2-0.63d+02)*ass+(0.210d+03*par2\n * -0.1d+01)*sinpar)/an2+(0.15d+02*par2-0.1d+01)*sinpar-\n * 0.15d+02*ass)/an2-0.3d+01*ass-sinpar)/an2-sinpar)/an2\n v(noequ+2) = v(noequ+2)-0.2d+01*asap*par2*(an-0.1d+01)\n * *(an-0.2d+01)\nc\nc solve the tridiagonal system by means of gaussian\nc elimination with partial pivoting.\nc\nc*** call to dgtsl has been replaced by call to\nc*** lapack routine dgtsv\nc\nc call dgtsl(noequ,d1,d,d2,v(3),iers)\n call dgtsv(noequ,1,d1(2:),d,d2(:noequ-1),v(3),noequ,iers)\n go to 100\nc\nc compute the chebyshev moments by means of forward recursion.\nc\n 80 an = 0.3d+01\n do 90 i = 3,12\n an2 = an*an\n v(i) = ((an2-0.4d+01)*(0.2d+01*(par22-an2-an2)*v(i-1)+as)\n * +ac-par2*(an+0.1d+01)*(an+0.2d+01)*v(i-2))\n * /(par2*(an-0.1d+01)*(an-0.2d+01))\n an = an+0.2d+01\n 90 continue\n 100 do 110 j = 1,12\n chebmo(m,2*j) = v(j)\n 110 continue\n 120 if (nrmom.lt.momcom) m = nrmom+1\n if (momcom.lt.(maxp1-1).and.nrmom.ge.momcom) momcom = momcom+1\nc\nc compute the coefficients of the chebyshev expansions\nc of degrees 12 and 24 of the function f.\nc\n fval(1) = 0.5d+00*f(centr+hlgth)\n fval(13) = f(centr)\n fval(25) = 0.5d+00*f(centr-hlgth)\n do 130 i = 2,12\n isym = 26-i\n fval(i) = f(hlgth*x(i-1)+centr)\n fval(isym) = f(centr-hlgth*x(i-1))\n 130 continue\n call dqcheb(x,fval,cheb12,cheb24)\nc\nc compute the integral and error estimates.\nc\n resc12 = cheb12(13)*chebmo(m,13)\n ress12 = 0.0d+00\n k = 11\n do 140 j = 1,6\n resc12 = resc12+cheb12(k)*chebmo(m,k)\n ress12 = ress12+cheb12(k+1)*chebmo(m,k+1)\n k = k-2\n 140 continue\n resc24 = cheb24(25)*chebmo(m,25)\n ress24 = 0.0d+00\n resabs = dabs(cheb24(25))\n k = 23\n do 150 j = 1,12\n resc24 = resc24+cheb24(k)*chebmo(m,k)\n ress24 = ress24+cheb24(k+1)*chebmo(m,k+1)\n resabs = dabs(cheb24(k))+dabs(cheb24(k+1))\n k = k-2\n 150 continue\n estc = dabs(resc24-resc12)\n ests = dabs(ress24-ress12)\n resabs = resabs*dabs(hlgth)\n if(integr.eq.2) go to 160\n result = conc*resc24-cons*ress24\n abserr = dabs(conc*estc)+dabs(cons*ests)\n go to 170\n 160 result = conc*ress24+cons*resc24\n abserr = dabs(conc*ests)+dabs(cons*estc)\n 170 return\n end\n", "meta": {"hexsha": "d1efe39e06e4f373d04e58fc5509a86ae77b5940", "size": 13270, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "scipy/integrate/quadpack/dqc25f.f", "max_stars_repo_name": "jeanpauphilet/scipy", "max_stars_repo_head_hexsha": "b3808a13b3c485a8c186352435b7b909c36b66e4", "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": "scipy/integrate/quadpack/dqc25f.f", "max_issues_repo_name": "jeanpauphilet/scipy", "max_issues_repo_head_hexsha": "b3808a13b3c485a8c186352435b7b909c36b66e4", "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": "scipy/integrate/quadpack/dqc25f.f", "max_forks_repo_name": "jeanpauphilet/scipy", "max_forks_repo_head_hexsha": "b3808a13b3c485a8c186352435b7b909c36b66e4", "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": 37.2752808989, "max_line_length": 72, "alphanum_fraction": 0.5676714393, "num_tokens": 4757, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069987088004, "lm_q2_score": 0.7461390043208003, "lm_q1q2_score": 0.678917102041112}} {"text": " subroutine pmicad(a,b,x,nx0,m,n,mdim,norm,eps,svd,solv)\nc --- solve A.x=b using \"Best Corrector Method\" ----------\n implicit real*8 (a-h,o-z)\nc parameter (nmax=1000,prec=1d-2)\n parameter (nmax=1000,prec=1d-6)\n dimension a(mdim,n),b(m),x(n),iw(nmax)\n logical norm,svd,solv\nc begin begin initialize for preventing compiler warning\n tm=0.d0\n small=0.d0\n k=0\n sk=0.d0\nc end begin initialize for preventing compiler warning\n\nc call cputime(ctime0,irtc)\n nx=min(nx0,m,n)\n if(n.gt.nmax) then\n print *,' Too many variables:',n\n return\n endif\n do 5 i=1,n\n iw(i)=i\n 5 continue\n if(norm) then\n tm=0d0\n do 7 j=1,n\n s=0d0\n do 6 i=1,m\n s=s+a(i,j)**2\n 6 continue\n if(s.gt.tm) tm=s\n 7 continue\n endif\n do 100 l=1,nx\n if(norm) small=tm*prec**2\n sm=0d0\n tm=0d0\n do 10 j=l,n\n s=0d0\n sd=0d0\n do 9 i=l,m\nc09MAY94 t=a(i,j)**2\nc09MAY94 s=s+t*b(i)**2\n s=s+a(i,j)*b(i)\n sd=sd+a(i,j)**2\n 9 continue\n s=s**2\n if(sd.gt.tm) tm=sd\n if(norm) s=s/(sd+small)\nc ... normalize the inner product (aj,b) by norm of aj\n if(s.ge.sm)then\n sm=s\n k=j\n sk=sd\n endif\n 10 continue\n i=iw(l)\n iw(l)=iw(k)\n iw(k)=i\n do 11 i=1,m\n t=a(i,l)\n a(i,l)=a(i,k)\n a(i,k)=t\n 11 continue\n sk=sign(sqrt(sk),a(l,l))\nc09MAY94h=sk*(sk+a(l,l))\n h=1d0/(sk*(sk+a(l,l)))\n a(l,l)=a(l,l)+sk\n do 13 j=l+1,n\n s=0d0\n do 12 i=l,m\n s=s+a(i,l)*a(i,j)\n 12 continue\n s=s*h\n do i=l,m\n a(i,j)=a(i,j)-a(i,l)*s\n enddo\nc09MAY94 x(j)=s/h\n 13 continue\nc09MAY94 --->\nc do 15 j=l+1,n\nc do 14 i=l,m\nc a(i,j)=a(i,j)-a(i,l)*x(j)\nc 14 continue\nc 15 continue\nc09MAY94 <---\n s=0d0\n do 16 i=l,m\n s=s+a(i,l)*b(i)\n 16 continue\nc09MAY94s=s/h\n s=s*h\n do 17 i=l,m\n b(i)=b(i)-a(i,l)*s\n 17 continue\nc s=0d0\nc do 18 i=l+1,m\nc s=s+b(i)**2\nc 18 continue\nc s=sqrt(s/real(m))\nc print *,'l=',l,' iw=',iw(l),' Residual rms: ',sngl(s)\n a(l,l)=-sk\n do 19 i=l+1,m\n a(i,l)=0d0\n 19 continue\n 100 continue\nc call cputime(ctime1,irtc)\nc call tsolva(a,b,x,nx,nx,mdim,eps)\n if(solv)then\n call tsvd(a,b,x,nx,nx,mdim,eps,svd)\n endif\nc call cputime(ctime2,irtc)\nc print *,'ctime(Htrans)=',sngl(1d-6*(ctime1-ctime0))\nc 1 ,'ctime(Tsolvg)=',sngl(1d-6*(ctime2-ctime1))\nc\n if(svd .and. solv) then\n do i=1,nx\n err=0d0\n do j=1,nx\n err=err+(b(j)*a(j,i))**2\n enddo\n a(1,i)=sqrt(err)\n enddo\n do i=1,nx\n b(i)=a(1,i)\n enddo\n do i=nx+1,m\n b(i)=0d0\n enddo\n endif\n do 101 i=nx+1,n\n x(i)=0d0\n 101 continue\n if(.not.solv)then\n do i=1,nx\n x(i)=1.d0\n enddo\n endif\nc call msort2(iw,x,nx)\n call msortn(iw,x,b,nx,1,nx)\n do 102 i=nx,1,-1\n if(iw(i).eq.i) return\n x(iw(i))=x(i)\n x(i)=0d0\n if(svd) then\n b(iw(i))=b(i)\n b(i)=0d0\n endif\n 102 continue\n return\n end\n", "meta": {"hexsha": "b8c3f73c1bc60dbaba3e252f95453da5509fba0e", "size": 3481, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/pmicad.f", "max_stars_repo_name": "noboruatkek/SAD", "max_stars_repo_head_hexsha": "3881a190af8903537774c57b56963ffc94cfc039", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2019-04-01T15:54:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-09T16:47:20.000Z", "max_issues_repo_path": "src/pmicad.f", "max_issues_repo_name": "noboruatkek/SAD", "max_issues_repo_head_hexsha": "3881a190af8903537774c57b56963ffc94cfc039", "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/pmicad.f", "max_forks_repo_name": "noboruatkek/SAD", "max_forks_repo_head_hexsha": "3881a190af8903537774c57b56963ffc94cfc039", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2017-03-15T08:52:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-19T08:06:40.000Z", "avg_line_length": 22.9013157895, "max_line_length": 62, "alphanum_fraction": 0.4481470842, "num_tokens": 1331, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.746138993030751, "lm_q1q2_score": 0.6789171008826129}} {"text": "*********************************************************\nC\n DOUBLE PRECISION FUNCTION CONTR5(I,N,X,CONT,XSOL,HSOL) \nC ----------------------------------------------------------\nC THIS FUNCTION CAN BE USED FOR CONINUOUS OUTPUT. IT PROVIDES AN\nC APPROXIMATION TO THE I-TH COMPONENT OF THE SOLUTION AT X.\nC IT GIVES THE VALUE OF THE COLLOCATION POLYNOMIAL, DEFINED FOR\nC THE LAST SUCCESSFULLY COMPUTED STEP (BY RADAR5).\nC ----------------------------------------------------------\n IMPLICIT DOUBLE PRECISION (A-H,O-Z)\n INTEGER, PARAMETER :: DP=kind(1D0)\n REAL(kind=DP), dimension(1), intent(in) :: CONT\nC --- REQUIRED CONSTANTS\n COMMON /CONSTN/C1,C2,C1M1,C2M1,C1MC2\n\n N2=2*N\n N3=3*N\n\n S=(X-XSOL)/HSOL\n\n CONTR5=CONT(I)+S*(CONT(I+N)+(S-C2M1)*(CONT(I+N2)\n & +(S-C1M1)*CONT(I+N3)))\n\n RETURN\n END\nC\nC END OF FUNCTION CONTR5\nC\nC ***********************************************************\n\n", "meta": {"hexsha": "a226acccebf73e4aa2b45190216b4acb80e0a991", "size": 966, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "TwoStateModel/contr5.f", "max_stars_repo_name": "ebenjaminrandall/DelayDDEBifurcationAnalysis", "max_stars_repo_head_hexsha": "9020d83bf6e07f1d8af1d062954a68055b5cbe6f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-09-22T14:05:30.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-10T10:06:06.000Z", "max_issues_repo_path": "code/contr5.f", "max_issues_repo_name": "ebenjaminrandall/Randall_VMPaper", "max_issues_repo_head_hexsha": "b84d2cc599a0a80b3f795a0e5a6999435f497103", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-05-25T09:14:28.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-25T09:14:28.000Z", "max_forks_repo_path": "code/contr5.f", "max_forks_repo_name": "ebenjaminrandall/Randall_VMPaper", "max_forks_repo_head_hexsha": "b84d2cc599a0a80b3f795a0e5a6999435f497103", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-04-27T10:14:46.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-27T10:14:46.000Z", "avg_line_length": 31.1612903226, "max_line_length": 68, "alphanum_fraction": 0.4772256729, "num_tokens": 256, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069987088004, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6789170969046647}} {"text": " SUBROUTINE SPLINE(X,Y,N,YP1,YPN,Y2)\r\n implicit double precision (a-h,o-z)\r\n PARAMETER (NMAX=100)\r\n DIMENSION X(N),Y(N),Y2(N),U(NMAX)\r\n IF (YP1.GT..99D30) THEN\r\n Y2(1)=0.\r\n U(1)=0.\r\n ELSE\r\n Y2(1)=-0.5d0\r\n U(1)=(3.d0/(X(2)-X(1)))*((Y(2)-Y(1))/(X(2)-X(1))-YP1)\r\n ENDIF\r\n DO 11 I=2,N-1\r\n SIG=(X(I)-X(I-1))/(X(I+1)-X(I-1))\r\n P=SIG*Y2(I-1)+2.d0\r\n Y2(I)=(SIG-1.)/P\r\n U(I)=(6.d0*((Y(I+1)-Y(I))/(X(I+1)-X(I))-(Y(I)-Y(I-1))\r\n * /(X(I)-X(I-1)))/(X(I+1)-X(I-1))-SIG*U(I-1))/P\r\n11 CONTINUE\r\n IF (YPN.GT..99d30) THEN\r\n QN=0.d0\r\n UN=0.d0\r\n ELSE\r\n QN=0.5d0\r\n UN=(3.d0/(X(N)-X(N-1)))*(YPN-(Y(N)-Y(N-1))/(X(N)-X(N-1)))\r\n ENDIF\r\n Y2(N)=(UN-QN*U(N-1))/(QN*Y2(N-1)+1.d0)\r\n DO 12 K=N-1,1,-1\r\n Y2(K)=Y2(K)*Y2(K+1)+U(K)\r\n12 CONTINUE\r\n RETURN\r\n END\r\n", "meta": {"hexsha": "3021b8dbf9f3d2f717283c691cb07b1f180f7227", "size": 907, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ext/recipes/spline.f", "max_stars_repo_name": "VishalKandala/Cantera-1.7", "max_stars_repo_head_hexsha": "750786f9b845a56fc177a9f1d5a9c5bb6ebd87cc", "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": "ext/recipes/spline.f", "max_issues_repo_name": "VishalKandala/Cantera-1.7", "max_issues_repo_head_hexsha": "750786f9b845a56fc177a9f1d5a9c5bb6ebd87cc", "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": "ext/recipes/spline.f", "max_forks_repo_name": "VishalKandala/Cantera-1.7", "max_forks_repo_head_hexsha": "750786f9b845a56fc177a9f1d5a9c5bb6ebd87cc", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.34375, "max_line_length": 66, "alphanum_fraction": 0.3991179713, "num_tokens": 419, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.909907001151883, "lm_q2_score": 0.7461389930307512, "lm_q1q2_score": 0.6789170935910965}} {"text": "\tSUBROUTINE IM_TTOB ( nvals, tmpk, brit, iret )\nC************************************************************************\nC* IM_TTOB\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This image processing function converts a real temperature (degrees\t*\nC* Kelvin) to an 8-bit brightness pixel temperature count (in a \t*\nC* 4-byte real value). Brightness counts are also called mode-A \t*\nC* counts or Ca. \t\t\t\t\t\t\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*\tIf (TMPK <= 242) BRIT = 418 - TMPK\t\t\t\t*\nC*\tIf (TMPK > 242) BRIT = 2 * (330 - TMPK)\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* SUBROUTINE IM_TTOB ( NVALS, TMPK, BRIT, IRET )\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tNVALS\t\tINTEGER\t\tNumber of values to convert\t*\nC*\tTMPK\t\tREAL\t\tTemperature in Kelvin\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tBRIT\t\tREAL\t\tBrightness (0-255)\t\t*\nC*\tIRET\t\tINTEGER\t\tReturn code\t\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* J. Cowie/COMET\t 4/96\t\t\t\t\t\t*\nC* D.W.Plummer/NCEP\t 2/03\tConvert from function to subroutine\t*\nC* T. Piper/SAIC\t07/06\tSet iret to zero\t\t\t*\nC************************************************************************\n INCLUDE\t\t'GEMPRM.PRM'\n\tREAL\t\ttmpk(*), brit(*)\nC------------------------------------------------------------------------\n\tiret = 0\n\tDO ii = 1, nvals\nC\n\t IF ( (tmpk(ii) .lt. 163.0) .or. (tmpk(ii) .gt. 330.0)) THEN\n\t brit(ii) = RMISSD\n\t ELSE IF ( tmpk(ii) .le. 242.0 ) THEN\n\t brit(ii) = 418.0 - tmpk(ii)\n\t ELSE\n\t brit(ii) = 2 * (330.0 - tmpk(ii))\n\t END IF\nC\n\tEND DO\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "77b789f8256b4206b394281f1233f3042dd65056", "size": 1532, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/gemlib/im/imttob.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/gemlib/im/imttob.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/gemlib/im/imttob.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.9166666667, "max_line_length": 73, "alphanum_fraction": 0.4765013055, "num_tokens": 528, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070011518829, "lm_q2_score": 0.746138993030751, "lm_q1q2_score": 0.6789170935910964}} {"text": " subroutine kscube (a1,a2,a3,a4,f1,f2,f3,f4,astar,fstar)\n implicit double precision (a-h,o-z)\nc\nc routine to compute the minimum of a cubic\nc curve through points a1,f1 a2,f2 a3,f3 and a4,f4.\nc\nc author - Gregory A. Wrenn\nc location - Lockheed Engineering and Sciences Co.\nc 144 Research Drive\nc Hampton, Va. 23666\nc\nc last modification - 27 April 1989\nc\n a1c = a1 * a1 * a1\n a2c = a2 * a2 * a2\n a3c = a3 * a3 * a3\n a4c = a4 * a4 * a4\nc\n q1 = a3c * (a2 - a1) - a2c * (a3 - a1) + a1c * (a3 - a2)\n q2 = a4c * (a2 - a1) - a2c * (a4 - a1) + a1c * (a4 - a2)\n q3 = (a3 - a2) * (a2 - a1) * (a3 - a1)\n q4 = (a4 - a2) * (a2 - a1) * (a4 - a1)\n q5 = f3 * (a2 - a1) - f2 * (a3 - a1) + f1 * (a3 - a2)\n q6 = f4 * (a2 - a1) - f2 * (a4 - a1) + f1 * (a4 - a2)\nc\n d1 = q2 * q3 - q1 * q4\n d2 = a2 - a1\n if (d1 .lt. 1.0e-12 .or. d2 .lt. 1.0e-12) go to 10\nc\n b3 = (q3 * q6 - q4 * q5) / d1\n b2 = (q5 - b3 * q1) / q3\n b1 = (f2 - f1) / d2 - b3 * (a2c - a1c) / d2 - b2 * (a1 + a2)\n b0 = f1 - b1 * a1 - b2 * a1 * a1 - b3 * a1c\nc\n bb = b2 * b2 - 3.0 * b1 * b3\n if (bb .lt. 0.0 .or. abs(b3) .lt. 1.0e-12) go to 10\n astar = (-b2 + sqrt(bb)) / (3.0 * b3)\n if (astar .lt. a1 .or. astar .gt. a4) go to 10\n as2 = astar * astar\n as3 = astar * as2\n fstar = b0 + b1 * astar + b2 * as2 + b3 * as3\n go to 40\nc\n 10 continue\n astar = a1\n fstar = f1\n if (f2 .ge. fstar) go to 20\n astar = a2\n fstar = f2\n 20 continue\n if (f3 .ge. fstar) go to 30\n astar = a3\n fstar = f3\n 30 continue\n if (f4 .ge. fstar) go to 40\n astar = a4\n fstar = f4\nc\n 40 continue\n return\n end\n ", "meta": {"hexsha": "8c4a94243bcb79f9ecd3d95d21a96975d2abd0d6", "size": 1818, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "docker/optimization/pyOpt/tags/v1.2.0/pyOpt/pyKSOPT/source/kscube.f", "max_stars_repo_name": "liujiamingustc/phd", "max_stars_repo_head_hexsha": "4f815a738abad43531d02ac66f5bd0d9a1def52a", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-01-06T03:01:18.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T03:02:55.000Z", "max_issues_repo_path": "docker/optimization/pyOpt/tags/v1.2.0/pyOpt/pyKSOPT/source/kscube.f", "max_issues_repo_name": "liujiamingustc/phd", "max_issues_repo_head_hexsha": "4f815a738abad43531d02ac66f5bd0d9a1def52a", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docker/optimization/pyOpt/tags/v1.2.0/pyOpt/pyKSOPT/source/kscube.f", "max_forks_repo_name": "liujiamingustc/phd", "max_forks_repo_head_hexsha": "4f815a738abad43531d02ac66f5bd0d9a1def52a", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.3225806452, "max_line_length": 66, "alphanum_fraction": 0.4548954895, "num_tokens": 856, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070133672954, "lm_q2_score": 0.7461389817407016, "lm_q1q2_score": 0.6789170924325968}} {"text": " PROGRAM TB0104\n\n IMPLICIT NONE\n\n*----------- VARIABLE DECLARATION --------------------------------------\n\n* IMPORTANT SUBROUTINE DESCRIPTION\n* DNTAP: DOUBLE PRECISION ANALYTICALLY NEWTON ROOT FINDER (PROCESS)\n* DSCP: DOUBLE PRECISION SECANT ROOT FINDER (PROCESS)\n* DSRP: DOUBLE PRECISION SEARCH ROOT FINDER (PROCESS)\n* (PROCESS MEANS THEY ONLY DO ONE ITERATION; WE SHOULD WRAP THEM BY \n* THE LOOPS)\n* THESE SUBROUTINES ARE EXPECTED TO RETURN ROOT VALUES AND UPDATED \n* METHOD SPECIFIC PARAMETERS.\n\n* FUNCTION DECLARATION\n* DFUNC: THE FUNCTION WE ARE DISCUSSING\n* DDERV: THE 1ST ANALYTIC DERVIATIVE OF THE FUNCTION 'DFUNC'\n DOUBLE PRECISION DFUNC, DDERV\n EXTERNAL DFUNC, DDERV\n\n* CALCULATION VARIABLES\n* ITR: ITERATION NUMBER\n* ITRMAX: MAXIMUN ITERATION NUMBER\n* ITRTHR: ITERATION THREAHOLD\n* DSRPR1: SEARCH METHOD PARAMETER 1 --- CURRENT GUESS\n* DSRPR2: SEARCH METHOD PARAMETER 2 --- CURRENT STEP\n* DNTPR: NEWTON METHOD PARAMETER --- CURRENT GUESS\n* DSCPR1: SECANT METHOD PARAMETER 1 --- CURRENT LOWER GUESS\n* DSCRP2: SECANT METHOD PARAMETER 2 --- CURRENT UPPER GUESS\n DOUBLE PRECISION DSRPR1, DSRPR2, DNTPR, DSCPR1, DSCPR2, ITRTHR\n INTEGER ITR, ITRMAX\n\n*---------- MAIN PROGRAM -----------------------------------------------\n\n* FILE OPERATION\n\n OPEN (11, FILE='Table-1-4.txt')\n 1000 FORMAT ( 1X, I5, 4X, 3(F12.6) )\n 1001 FORMAT ( A46 )\n 1002 FORMAT ( 1X, A9, 3(A12) )\n\n WRITE(11,*) 'On the book, the deviation of 5th iteration for' \n WRITE(11,*) 'secant method is actually wrong'\n WRITE(11,*)\n WRITE(11,*) 'I do not know if different compliers behave diff-'\n WRITE(11,*) 'erently facing NaN. It is possible letting iteration'\n WRITE(11,*) 'numbers reach a very large number.'\n WRITE(11,*)\n\n* CALCULATION\n\n WRITE(11,1001) '----------------------------------------------'\n WRITE(11,1002) 'Iteration', ' Search', ' Newton',\n $ ' Secant'\n WRITE(11,1002) ' ', ' ', ' Eq.(1.14)',\n $ ' Eq.(1.15)'\n WRITE(11,1001) '----------------------------------------------'\n\n ITR = 0\n ITRMAX = 100\n ITRTHR = 1.0D-6\n DSRPR1 = 1.0D0\n DSRPR2 = 0.5D0\n DNTPR = 1.0D0\n DSCPR1 = 0.5D0\n DSCPR2 = 1.0D0\n WRITE(11,1000) ITR, DSRPR1-DSQRT(5.0D0), DNTPR-DSQRT(5.0D0), \n $ DSCPR2-DSQRT(5.0D0)\n 10 CONTINUE\n ITR = ITR + 1\n CALL DSRP(DFUNC, DSRPR1, DSRPR2)\n CALL DNTAP(DFUNC, DDERV, DNTPR)\n CALL DSCP(DFUNC, DSCPR1, DSCPR2)\n WRITE(11,1000) ITR, DSRPR1-DSQRT(5.0D0), DNTPR-DSQRT(5.0D0), \n $ DSCPR2-DSQRT(5.0D0)\n IF (ITR.LT.ITRMAX.AND.MAX(DABS(DSRPR2), \n $ DABS(DNTPR-DSQRT(5.0D0)), DABS(DSCPR2-DSCPR1))\n $ .GT.ITRTHR) GOTO 10\n \n WRITE(11,1001) '----------------------------------------------'\n\n END PROGRAM TB0104\n\n*-----------------------------------------------------------------------\n\n SUBROUTINE DSRP(DFUNC, DSRPR1, DSRPR2)\n\n IMPLICIT NONE\n\n* FUNCTION VARIABLE DECLARATION\n DOUBLE PRECISION DFUNC, DSRPR1, DSRPR2\n EXTERNAL DFUNC\n\n DSRPR1 = DSRPR1 + DSRPR2\n IF (DFUNC(DSRPR1) * DFUNC(DSRPR1-DSRPR2).LE.0.0D0) THEN\n DSRPR2 = - DSRPR2 / 2.0D0\n END IF \n\n END SUBROUTINE DSRP\n\n*-----------------------------------------------------------------------\n\n SUBROUTINE DNTAP(DFUNC, DDERV, DNTPR)\n\n IMPLICIT NONE\n\n* FUNCTION VARIABLE DECLARATION\n DOUBLE PRECISION DFUNC, DDERV, DNTPR\n EXTERNAL DFUNC, DDERV\n\n DNTPR = DNTPR - DFUNC(DNTPR) / DDERV(DNTPR)\n\n END SUBROUTINE DNTAP\n\n*-----------------------------------------------------------------------\n\n SUBROUTINE DSCP(DFUNC, DSCPR1, DSCPR2)\n\n IMPLICIT NONE\n* FUNCTION VARIABLE DECLARATION\n DOUBLE PRECISION DFUNC, DSCPR1, DSCPR2\n EXTERNAL DFUNC\n* TEMPORARY VARIABLE STORAGE\n DOUBLE PRECISION DTMP\n\n DTMP = DSCPR2 - DFUNC(DSCPR2) * (DSCPR2 - DSCPR1) / (DFUNC(DSCPR2)\n $ - DFUNC(DSCPR1))\n DSCPR1 = DSCPR2\n DSCPR2 = DTMP\n\n END SUBROUTINE\n\n*-----------------------------------------------------------------------\n\n FUNCTION DFUNC(DVAR)\n\n IMPLICIT NONE\n\n DOUBLE PRECISION DVAR, DFUNC\n\n DFUNC = DVAR * DVAR - 5.0D0\n\n END FUNCTION DFUNC\n\n*-----------------------------------------------------------------------\n\n FUNCTION DDERV(DVAR)\n\n IMPLICIT NONE\n\n DOUBLE PRECISION DVAR, DDERV\n\n DDERV = 2.0D0 * DVAR\n\n END FUNCTION DDERV\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "b14861503e924accd0b2ae5f17106a786bfcedbf", "size": 4628, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "ErrTable/Chapter-01/Table-1-4/Table-1-4.for", "max_stars_repo_name": "ajz34/Comp-Phys-Koonin", "max_stars_repo_head_hexsha": "9fc371bdb44b7030025d254eda040a55bfa3b7cd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-10-29T12:21:38.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-31T17:03:43.000Z", "max_issues_repo_path": "ErrTable/Chapter-01/Table-1-4/Table-1-4.for", "max_issues_repo_name": "ajz34/Comp-Phys-Koonin", "max_issues_repo_head_hexsha": "9fc371bdb44b7030025d254eda040a55bfa3b7cd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ErrTable/Chapter-01/Table-1-4/Table-1-4.for", "max_forks_repo_name": "ajz34/Comp-Phys-Koonin", "max_forks_repo_head_hexsha": "9fc371bdb44b7030025d254eda040a55bfa3b7cd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.5476190476, "max_line_length": 72, "alphanum_fraction": 0.5280898876, "num_tokens": 1479, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.6788733175972307}} {"text": " PROGRAM EX0103\n\n IMPLICIT NONE\n\n*----------- VARIABLE DECLARATION -------------------------------------\n\n* THE SAME AS EX0102\n* USE D5P AS THE EVALUATING METHOD (HOWEVER REMOVE THE COMPARASON WITH\n* THE TRUE VALUE)\n* DFUN1 REFERS TO THE INTEGRAL FROM 0 - 1/2; WHILE DFUN2 1/2 - 1\n* DEV REFERS TO THE DEVIATION BETWEEN THE APPROXIMATE AND THE TRUE VALUE\n\n* FUNCTION DECLARATION\n DOUBLE PRECISION D5P, DFUN1, DFUN2\n EXTERNAL D5P, DFUN1, DFUN2\n* INTEGRAL GRID CALCULATION\n DOUBLE PRECISION DMIN, DMAX\n INTEGER N\n* RESULTS\n DOUBLE PRECISION DSOL1, DSOL2, DSOL, DEV\n\n*----------------------------------------------------------------------\n\n* INTEGRAL FROM 0 TO 1/2 : DSOL1\n \n N = 512\n DMIN = 0.0D0\n DMAX = 0.5D0 ** (1.0D0 / 3.0D0)\n DSOL1 = D5P(N, DFUN1, DMIN, DMAX)\n\n* INTEGRAL FROM 1/2 TO 1 : DSOL2\n\n N = 512\n DMIN = 0.0D0\n DMAX = 0.5D0 ** (2.0D0 / 3.0D0)\n DSOL2 = D5P(N, DFUN2, DMIN, DMAX)\n\n* FINAL RESULT\n\n DSOL = DSOL1 + DSOL2\n DEV = DSOL - 4.0D0 * DASIN(1.0D0) / DSQRT(3.0D0)\n\n PRINT *, 'INTEGRAL FROM 0 TO 0.5 : ', DSOL1\n PRINT *, 'INTEGRAL FROM 0.5 TO 1 : ', DSOL2\n PRINT *, 'TOTAL INTEGRAL VALUE : ', DSOL\n PRINT *, 'DEVIATION FROM EXACT : ', DEV\n \n END PROGRAM EX0103\n\n*----------------------------------------------------------------------\n\n FUNCTION D5P(N, DFUNC, DMIN, DMAX)\n\n IMPLICIT NONE\n\n* FUNCTION VARIABLE DECLARATION\n DOUBLE PRECISION D5P, DFUNC, DMIN, DMAX\n INTEGER FLR\n EXTERNAL DFUNC, FLR\n* DUMMY \n INTEGER I\n* ERROR CALCULATION VARIABLES\n DOUBLE PRECISION DH\n* CONVERT REAL TO INTEGER FOR THE DUMMY\n INTEGER K, N\n\n* DEFINING THE INTEGRAL GRIDS\n K = FLR(REAL(DBLE(N) / 4.0D0))\n DH = (DMAX - DMIN) / (4.0D0 * DBLE(K)) \n\n* INITIAL AND FINAL POINT CALCULATION\n D5P = 7.0D0 * DFUNC(DMIN) - 7.0D0 * DFUNC(DMAX)\n\n* INTERNAL GRID POINT CALCULATION\n DO 10 I = 1, K\n D5P = D5P + 32.0D0 * DFUNC(DMIN + DBLE(I*4-3) * DH)\n D5P = D5P + 12.0D0 * DFUNC(DMIN + DBLE(I*4-2) * DH)\n D5P = D5P + 32.0D0 * DFUNC(DMIN + DBLE(I*4-1) * DH)\n D5P = D5P + 14.0D0 * DFUNC(DMIN + DBLE(I*4) * DH)\n 10 CONTINUE\n\n D5P = D5P * DH * 2.0D0 / 45.0D0\n\n RETURN\n END FUNCTION D5P\n\n*----------------------------------------------------------------------\n\n FUNCTION DFUN1(DVAR)\n\n IMPLICIT NONE\n\n DOUBLE PRECISION DFUN1, DVAR\n\n DFUN1 = 3.0D0 * (1 - DVAR * DVAR * DVAR) ** (-1.0D0 / 3.0D0)\n\n RETURN\n END FUNCTION DFUN1\n\n*----------------------------------------------------------------------\n\n FUNCTION DFUN2(DVAR)\n\n IMPLICIT NONE\n\n DOUBLE PRECISION DFUN2, DVAR\n\n DFUN2 = 1.5D0 * (1 - DVAR ** 1.5D0) ** (-2.0D0 / 3.0D0)\n\n RETURN\n END FUNCTION DFUN2\n\n*----------------------------------------------------------------------\n\n FUNCTION FLR(SVAR)\n\n IMPLICIT NONE\n\n* FUNCTION VARIABLE DECLARATION\n REAL SVAR\n INTEGER FLR\n\n* MAIN PROGRAM\n\n FLR = INT(SVAR)\n\n IF (SVAR .LT. 0) FLR = FLR - 1\n\n RETURN\n END FUNCTION FLR\n\n*----------------------------------------------------------------------\n\n", "meta": {"hexsha": "7700fa918c816525cd4a8f15a933d6cc0bba29b3", "size": 3284, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "Exercise/Chapter-01/01-03/01-03.for", "max_stars_repo_name": "ajz34/Comp-Phys-Koonin", "max_stars_repo_head_hexsha": "9fc371bdb44b7030025d254eda040a55bfa3b7cd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-10-29T12:21:38.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-31T17:03:43.000Z", "max_issues_repo_path": "Exercise/Chapter-01/01-03/01-03.for", "max_issues_repo_name": "ajz34/Comp-Phys-Koonin", "max_issues_repo_head_hexsha": "9fc371bdb44b7030025d254eda040a55bfa3b7cd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Exercise/Chapter-01/01-03/01-03.for", "max_forks_repo_name": "ajz34/Comp-Phys-Koonin", "max_forks_repo_head_hexsha": "9fc371bdb44b7030025d254eda040a55bfa3b7cd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.5074626866, "max_line_length": 72, "alphanum_fraction": 0.4814250914, "num_tokens": 1089, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382200964034, "lm_q2_score": 0.7879312031126512, "lm_q1q2_score": 0.6788328462880912}} {"text": "Program abdulmalik\n\tIMPLICIT NONE\n INTEGER::n,i\n REAL::w(20),k,SUM_P_V,h,max,min\n print*,\"enter n\"\n read*,n\n call READ_REAL_VECROR(w,20,n)\n K = SUM_P_V(w,n,20)\n max=w(1)\n min=w(1)\n do i=2,n\n if(w(i)>max)then\n max=w(i)\n elseif(w(i)real64,sp=>real32\n implicit none\n real(kind=dp), dimension(3) :: x = [ -1.0d0, 0.0d0, 1.0d0 ]\n\n write (*,*) asinh(x)\n\n end program demo_asinh\n", "meta": {"hexsha": "23201cb395011285fb667b13a67d5d787c5a2e02", "size": 230, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/asinh.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/asinh.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/asinh.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": 25.5555555556, "max_line_length": 66, "alphanum_fraction": 0.6086956522, "num_tokens": 84, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8558511396138364, "lm_q2_score": 0.793105951184112, "lm_q1q2_score": 0.6787806321554379}} {"text": "MODULE PE2D_VAR\n USE PE2D_TYPE\n IMPLICIT NONE\n !-----------------------------------------------------------\n !COMPLEX(DPC), PARAMETER :: IM = CMPLX(0.0_DP,1.0_DP,KIND=DP)\n CHARACTER :: TRACK, FREQ, SRCE, ATMO, WIDE, RIG\n CHARACTER(LEN=100) :: VAR_L, VAR_F, VAR_ZX, VAR_ZY, VAR_ANGLE, VAR_DC, VAR_ZS, VAR_RIG\n CHARACTER(LEN=100) :: PATH_TOPO, FILE_TOPO, TOPO, OUT_LP, OUT_LPG, OUT_P, OUT_PC, OUT_TOPO, OUT_EXT\n INTEGER(I4B) :: N, NT, NSYS, M, NS, NR, NA, NZ, MX, NELT, KU, KL, INFO, NDIAG\n INTEGER(I4B) :: NLINES, NCOLS, SRCE_I, FREQ_I, TOPO_I, ATMO_I, WIDE_I, N1, N2\n INTEGER(I4B), ALLOCATABLE, DIMENSION(:) :: IPIV, NN\n REAL(DP) :: ZX, ZY\n REAL(DP) :: C0, DC, L, LX, LY, H, HA, F, ZS, Z0, ZR, AS, K0, LMBDA0, DKZ, DZ, DR, Z1, Z2\n REAL(DP) :: A0, A2, B, TI, TF, NORM, RCOND, FREQ_NAT(2,4), FREQ_VAL(3), ATMO_REF(3)\n REAL(DP) :: LP0, LQ0, LQR, LPR, PR, QR, P0, Q0\n REAL(DP), ALLOCATABLE, DIMENSION(:) :: ALT, X, C, LPG, LPG1, LPG2, LQG, WORK, RWORK, CH\n REAL(DP), ALLOCATABLE, DIMENSION(:,:) :: P, Q, LP, LQ, MCOND, WA, GMT_DATA\n REAL(DP) :: GHX(3), H0, X0, S, XL, XR, ANGLE, THETA\n REAL(DP), ALLOCATABLE, DIMENSION(:) :: LIN, TERR, TERR1, TERR2, SLOPX\n COMPLEX(DPC) :: A, C1, C2, BETA1, BETA2, TAU1, TAU2, SIGMA1, SIGMA2, R, Z, Z_VAL(3)\n COMPLEX(DPC), ALLOCATABLE, DIMENSION(:) :: K, KZ, DK2, CWORK, PHASE, PG\n COMPLEX(DPC), ALLOCATABLE, DIMENSION(:,:) :: TEMP, PHI, PHI1, PHI2, PC, QC\n COMPLEX(DPC), ALLOCATABLE, DIMENSION(:,:) :: T, D, I, E, DD, M1, M2, MB1, MB2, M1T, M2T, MB1T, MB2T\n TYPE(US), SAVE :: SPMAT, SP1, SP2\n !FFT Arrays\n COMPLEX(DP), ALLOCATABLE, DIMENSION(:,:) :: FPHI, FPHIi, FPHIr\n COMPLEX(DP), ALLOCATABLE, DIMENSION(:) :: BUFR, FPHIs\n INTEGER(I4B), DIMENSION(100) :: IFAC\n !-----------------------------------------------------------\nEND MODULE PE2D_VAR\n\n! !Propagation domain discretization\r\n!### INTEGER :: N, Ns, Na, M, nz, mx\r\n!### REAL(DP) :: k0, lmbda0, Ha, dz, dr, dkz\n!### REAL(DP), ALLOCATABLE, DIMENSION(:) :: r, z\r\n!### COMPLEX(DP) :: beta\r\n!## !Atmosphere variables\r\n! #COMPLEX(DP), ALLOCATABLE, DIMENSION(:) :: k, dk2, kz, Phase, Ref, DELTA\n!# !Terrain coordinate transform\r\n!# REAL(DP) :: H0, x0, s, xl, xr\r\n!# REAL(DP), ALLOCATABLE, DIMENSION(:) :: alti, linear, alpha, dalpha\r\n! !z-domain Pressure field\r\n!## COMPLEX(DP), ALLOCATABLE, DIMENSION(:,:) :: P, PHI, PHI1, PHI2, Preal, Pimag\r\n!## COMPLEX(DP) :: A0, A2, B\r\n!## REAL(DP) :: Ps\n! !kz-domain Pressure field\r\n!### REAL(DP), ALLOCATABLE, DIMENSION(:,:) :: WA, LP, LPrms, P0\r\n!### REAL(DP), ALLOCATABLE, DIMENSION(:) :: CH, LPg, LPrmsg\n! !FFT Work array\n! COMPLEX(DP), ALLOCATABLE, DIMENSION(:,:) :: FPHI, FPHIi, FPHIr\n! COMPLEX(DP), ALLOCATABLE, DIMENSION(:) :: BUFR, FPHIs\n! INTEGER, DIMENSION(100) :: IFAC\r\n! !CPU Time\r\n! REAL :: start, finish\n", "meta": {"hexsha": "62d0f7e783e3f51fc0cf1d52fbc225505c7da93b", "size": 2737, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "Parabolic_Equation/2DPE/SRC/MODULES/PE2D_VAR.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/SRC/MODULES/PE2D_VAR.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/SRC/MODULES/PE2D_VAR.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": 49.7636363636, "max_line_length": 100, "alphanum_fraction": 0.6068688345, "num_tokens": 1139, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896758909756, "lm_q2_score": 0.7371581510799253, "lm_q1q2_score": 0.6787676150132753}} {"text": "PROGRAM main\n\n USE mo_kind, ONLY: dp, sp\n use mo_ansi_colors, only: color, c_red, c_green\n USE mo_moment, ONLY: absdev, average, central_moment, central_moment_var, correlation, &\n covariance, kurtosis, mean, mixed_central_moment, mixed_central_moment_var, &\n moment, skewness, stddev, variance\n USE mo_utils, only: ne\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(10) :: dat1, dat2\n REAL(dp) :: a_dp, v_dp, s_dp, k_dp, m_dp, std_dp, ad_dp\n\n REAL(sp), DIMENSION(10) :: sat1, sat2\n REAL(sp) :: a_sp, v_sp, s_sp, k_sp, m_sp, std_sp, ad_sp\n\n LOGICAL :: isgood\n\n real(sp) :: stmp\n real(dp) :: dtmp\n\n Write(*,*) ''\n Write(*,*) 'Test mo_moment.f90'\n\n ! Double precision\n dat1 = (/ 1., 2., 3., 4., 5., 6., 7., 8., 9., 10. /)\n isgood = .true.\n ! Test standard\n dtmp = mean(dat1)\n isgood = isgood .and. (nint(10._dp*dtmp) == 55)\n if (.not. isgood) write(*,*) 'mo_moment mean 1'\n dtmp = average(dat1)\n isgood = isgood .and. (nint(10._dp*dtmp) == 55)\n if (.not. isgood) write(*,*) 'mo_moment average 1'\n dtmp = variance(dat1, ddof=1)\n isgood = isgood .and. (nint(10._dp*dtmp) == 92)\n if (.not. isgood) write(*,*) 'mo_moment variance 1'\n dtmp = stddev(dat1, ddof=1)\n isgood = isgood .and. (nint(10._dp*dtmp) == 30)\n if (.not. isgood) write(*,*) 'mo_moment stddev 1'\n dtmp = skewness(dat1)\n isgood = isgood .and. (nint(10._dp*dtmp) == 00)\n if (.not. isgood) write(*,*) 'mo_moment skewness 1'\n dtmp = kurtosis(dat1)\n isgood = isgood .and. (nint(10._dp*dtmp) == -16)\n if (.not. isgood) write(*,*) 'mo_moment kurtosis 1'\n dtmp = absdev(dat1)\n isgood = isgood .and. (nint(10._dp*dtmp) == 25)\n if (.not. isgood) write(*,*) 'mo_moment absdev 1'\n dtmp = central_moment(dat1,2)\n isgood = isgood .and. (nint(100._dp*dtmp) == 825)\n if (.not. isgood) write(*,*) 'mo_moment central_moment 1'\n dtmp = central_moment_var(dat1,2)\n isgood = isgood .and. (nint(10._dp*dtmp) == 53)\n if (.not. isgood) write(*,*) 'mo_moment central_moment_var 1'\n ! Test the mask\n dtmp = mean(dat1(1:9))\n isgood = isgood .and. (nint(10._dp*dtmp) == 50)\n dtmp = average(dat1(1:9))\n isgood = isgood .and. (nint(10._dp*dtmp) == 50)\n dtmp = variance(dat1(1:9), ddof=1)\n isgood = isgood .and. (nint(10._dp*dtmp) == 75)\n dtmp = stddev(dat1(1:9), ddof=1)\n isgood = isgood .and. (nint(10._dp*dtmp) == 27)\n dtmp = skewness(dat1(1:9))\n isgood = isgood .and. (nint(10._dp*dtmp) == 00)\n dtmp = kurtosis(dat1(1:9))\n isgood = isgood .and. (nint(10._dp*dtmp) == -16)\n dtmp = absdev(dat1(1:9))\n isgood = isgood .and. (nint(10._dp*dtmp) == 22)\n dtmp = central_moment(dat1(1:9),2)\n isgood = isgood .and. (nint(10._dp*dtmp) == 67)\n dtmp = central_moment_var(dat1(1:9),2)\n isgood = isgood .and. (nint(10._dp*dtmp) == 38)\n dtmp = mean(dat1, mask=ne(dat1,10._dp))\n isgood = isgood .and. (nint(10._dp*dtmp) == 50)\n dtmp = average(dat1, mask=ne(dat1,10._dp))\n isgood = isgood .and. (nint(10._dp*dtmp) == 50)\n dtmp = variance(dat1, mask=ne(dat1,10._dp), ddof=1)\n isgood = isgood .and. (nint(10._dp*dtmp) == 75)\n dtmp = stddev(dat1, mask=ne(dat1,10._dp), ddof=1)\n isgood = isgood .and. (nint(10._dp*dtmp) == 27)\n dtmp = skewness(dat1, mask=ne(dat1,10._dp))\n isgood = isgood .and. (nint(10._dp*dtmp) == 00)\n dtmp = kurtosis(dat1, mask=ne(dat1,10._dp))\n isgood = isgood .and. (nint(10._dp*dtmp) == -16)\n dtmp = absdev(dat1, mask=ne(dat1,10._dp))\n isgood = isgood .and. (nint(10._dp*dtmp) == 22)\n dtmp = central_moment(dat1, 2, mask=ne(dat1,10._dp))\n isgood = isgood .and. (nint(10._dp*dtmp) == 67)\n dtmp = central_moment_var(dat1, 2, mask=ne(dat1,10._dp))\n isgood = isgood .and. (nint(10._dp*dtmp) == 38)\n if (.not. isgood) write(*,*) 'mo_moment mask'\n ! Test moment\n call moment(dat1, average=a_dp, variance=v_dp, skewness=s_dp, kurtosis=k_dp, mean=m_dp, &\n stddev=std_dp, absdev=ad_dp, mask=ne(dat1,10._dp), ddof=1)\n isgood = isgood .and. (nint(10._dp*m_dp) == 50)\n isgood = isgood .and. (nint(10._dp*a_dp) == 50)\n isgood = isgood .and. (nint(10._dp*v_dp) == 75)\n isgood = isgood .and. (nint(10._dp*std_dp) == 27)\n isgood = isgood .and. (nint(10._dp*s_dp) == 00)\n isgood = isgood .and. (nint(10._dp*k_dp) == -16)\n isgood = isgood .and. (nint(10._dp*ad_dp) == 25)\n if (.not. isgood) write(*,*) 'mo_moment moment'\n ! Test the double input functions\n dat2 = (/ 1.3, 2.7, 3.9, 5.5, 7., 8.8, 11., 13., 15., 16. /)\n dtmp = correlation(dat1,dat2, ddof=1)\n isgood = isgood .and. (nint(10._dp*dtmp) == 10)\n if (.not. isgood) write(*,*) 'mo_moment correlation 1'\n dtmp = covariance(dat1,dat2, ddof=1)\n isgood = isgood .and. (nint(10._dp*dtmp) == 157)\n if (.not. isgood) write(*,*) 'mo_moment covariance 1'\n dtmp = mixed_central_moment(dat1,dat2,1,1)\n isgood = isgood .and. (nint(10._dp*dtmp) == 141)\n dtmp = mixed_central_moment_var(dat1,dat2,1,1)\n isgood = isgood .and. (nint(10._dp*dtmp) == 142)\n dtmp = correlation(dat1(1:9),dat2(1:9), ddof=1)\n isgood = isgood .and. (nint(10._dp*dtmp) == 10)\n if (.not. isgood) write(*,*) 'mo_moment correlation 2'\n dtmp = covariance(dat1(1:9),dat2(1:9), ddof=1)\n isgood = isgood .and. (nint(10._dp*dtmp) == 129)\n if (.not. isgood) write(*,*) 'mo_moment covariance 2'\n dtmp = mixed_central_moment(dat1(1:9),dat2(1:9),1,1)\n isgood = isgood .and. (nint(10._dp*dtmp) == 115)\n dtmp = mixed_central_moment_var(dat1(1:9),dat2(1:9),1,1)\n isgood = isgood .and. (nint(10._dp*dtmp) == 113)\n dtmp = correlation(dat1,dat2, mask=(ne(dat1,10._dp).and.ne(dat2,10._dp)), ddof=1)\n isgood = isgood .and. (nint(10._dp*dtmp) == 10)\n if (.not. isgood) write(*,*) 'mo_moment correlation 3'\n dtmp = covariance(dat1,dat2, mask=(ne(dat1,10._dp).and.ne(dat2,10._dp)), ddof=1)\n isgood = isgood .and. (nint(10._dp*dtmp) == 129)\n if (.not. isgood) write(*,*) 'mo_moment covariance 3'\n dtmp = mixed_central_moment(dat1,dat2,1,1, mask=(ne(dat1,10._dp).and.ne(dat2,10._dp)))\n isgood = isgood .and. (nint(10._dp*dtmp) == 115)\n dtmp = mixed_central_moment_var(dat1,dat2,1,1, mask=(ne(dat1,10._dp).and.ne(dat2,10._dp)))\n isgood = isgood .and. (nint(10._dp*dtmp) == 113)\n if (.not. isgood) write(*,*) 'mo_moment covariance etc.'\n\n if (isgood) then\n write(*,*) 'mo_moment double precision ', color('o.k.', c_green)\n else\n write(*,*) 'mo_moment double precision ', color('failed!', c_red)\n endif\n\n ! Single precision\n sat1 = (/ 1., 2., 3., 4., 5., 6., 7., 8., 9., 10. /)\n isgood = .true.\n ! Test standard\n stmp = mean(sat1)\n isgood = isgood .and. (nint(10._sp*stmp) == 55)\n stmp = average(sat1)\n isgood = isgood .and. (nint(10._sp*stmp) == 55)\n stmp = variance(sat1, ddof=1)\n isgood = isgood .and. (nint(10._sp*stmp) == 92)\n stmp = stddev(sat1, ddof=1)\n isgood = isgood .and. (nint(10._sp*stmp) == 30)\n stmp = skewness(sat1)\n isgood = isgood .and. (nint(10._sp*stmp) == 00)\n stmp = kurtosis(sat1)\n isgood = isgood .and. (nint(10._sp*stmp) == -16)\n stmp = absdev(sat1)\n isgood = isgood .and. (nint(10._sp*stmp) == 25)\n stmp = central_moment(sat1,2)\n isgood = isgood .and. (nint(100._sp*stmp) == 825)\n stmp = central_moment_var(sat1,2)\n isgood = isgood .and. (nint(10._sp*stmp) == 53)\n if (.not. isgood) write(*,*) 'mo_moment sp 1'\n ! Test the mask\n stmp = mean(sat1(1:9))\n isgood = isgood .and. (nint(10._sp*stmp) == 50)\n stmp = average(sat1(1:9))\n isgood = isgood .and. (nint(10._sp*stmp) == 50)\n stmp = variance(sat1(1:9), ddof=1)\n isgood = isgood .and. (nint(10._sp*stmp) == 75)\n stmp = stddev(sat1(1:9), ddof=1)\n isgood = isgood .and. (nint(10._sp*stmp) == 27)\n stmp = skewness(sat1(1:9))\n isgood = isgood .and. (nint(10._sp*stmp) == 00)\n stmp = kurtosis(sat1(1:9))\n isgood = isgood .and. (nint(10._sp*stmp) == -16)\n stmp = absdev(sat1(1:9))\n isgood = isgood .and. (nint(10._sp*stmp) == 22)\n stmp = central_moment(sat1(1:9),2)\n isgood = isgood .and. (nint(10._sp*stmp) == 67)\n stmp = central_moment_var(sat1(1:9),2)\n isgood = isgood .and. (nint(10._sp*stmp) == 38)\n stmp = mean(sat1, mask=ne(sat1,10._sp))\n isgood = isgood .and. (nint(10._sp*stmp) == 50)\n stmp = average(sat1, mask=ne(sat1,10._sp))\n isgood = isgood .and. (nint(10._sp*stmp) == 50)\n stmp = variance(sat1, mask=ne(sat1,10._sp), ddof=1)\n isgood = isgood .and. (nint(10._sp*stmp) == 75)\n stmp = stddev(sat1, mask=ne(sat1,10._sp), ddof=1)\n isgood = isgood .and. (nint(10._sp*stmp) == 27)\n stmp = skewness(sat1, mask=ne(sat1,10._sp))\n isgood = isgood .and. (nint(10._sp*stmp) == 00)\n stmp = kurtosis(sat1, mask=ne(sat1,10._sp))\n isgood = isgood .and. (nint(10._sp*stmp) == -16)\n stmp = absdev(sat1, mask=ne(sat1,10._sp))\n isgood = isgood .and. (nint(10._sp*stmp) == 22)\n stmp = central_moment(sat1, 2, mask=ne(sat1,10._sp))\n isgood = isgood .and. (nint(10._sp*stmp) == 67)\n stmp = central_moment_var(sat1, 2, mask=ne(sat1,10._sp))\n isgood = isgood .and. (nint(10._sp*stmp) == 38)\n if (.not. isgood) write(*,*) 'mo_moment sp 2'\n ! Test moment\n call moment(sat1, average=a_sp, variance=v_sp, skewness=s_sp, kurtosis=k_sp, mean=m_sp, &\n stddev=std_sp, absdev=ad_sp, mask=ne(sat1,10._sp), ddof=1)\n isgood = isgood .and. (nint(10._sp*m_sp) == 50)\n isgood = isgood .and. (nint(10._sp*a_sp) == 50)\n isgood = isgood .and. (nint(10._sp*v_sp) == 75)\n isgood = isgood .and. (nint(10._sp*std_sp) == 27)\n isgood = isgood .and. (nint(10._sp*s_sp) == 00)\n isgood = isgood .and. (nint(10._sp*k_sp) == -16)\n isgood = isgood .and. (nint(10._sp*ad_sp) == 25)\n if (.not. isgood) write(*,*) 'mo_moment sp 3'\n ! Test the double input functions\n sat2 = (/ 1.3, 2.7, 3.9, 5.5, 7., 8.8, 11., 13., 15., 16. /)\n stmp = correlation(sat1,sat2, ddof=1)\n isgood = isgood .and. (nint(10._sp*stmp) == 10)\n if (.not. isgood) write(*,*) 'mo_moment sp 4.1'\n stmp = covariance(sat1, sat2, ddof=1)\n isgood = isgood .and. (nint(10._sp*stmp) == 157)\n if (.not. isgood) write(*,*) 'mo_moment sp 4.2'\n stmp = mixed_central_moment(sat1,sat2,1,1)\n isgood = isgood .and. (nint(10._sp*stmp) == 141)\n if (.not. isgood) write(*,*) 'mo_moment sp 4.3'\n stmp = mixed_central_moment_var(sat1,sat2,1,1)\n isgood = isgood .and. (nint(10._sp*stmp) == 142)\n if (.not. isgood) write(*,*) 'mo_moment sp 4.4'\n stmp = correlation(sat1(1:9),sat2(1:9), ddof=1)\n isgood = isgood .and. (nint(10._sp*stmp) == 10)\n if (.not. isgood) write(*,*) 'mo_moment sp 4.5'\n stmp = covariance(sat1(1:9),sat2(1:9), ddof=1)\n isgood = isgood .and. (nint(10._sp*stmp) == 129)\n if (.not. isgood) write(*,*) 'mo_moment sp 4.6'\n stmp = mixed_central_moment(sat1(1:9),sat2(1:9),1,1)\n isgood = isgood .and. (nint(10._sp*stmp) == 115)\n if (.not. isgood) write(*,*) 'mo_moment sp 4.7'\n stmp = mixed_central_moment_var(sat1(1:9),sat2(1:9),1,1)\n isgood = isgood .and. (nint(10._sp*stmp) == 113)\n if (.not. isgood) write(*,*) 'mo_moment sp 4.8'\n stmp = correlation(sat1,sat2, mask=(ne(sat1,10._sp).and.ne(sat2,10._sp)), ddof=1)\n isgood = isgood .and. (nint(10._sp*stmp) == 10)\n if (.not. isgood) write(*,*) 'mo_moment sp 4.9'\n stmp = covariance(sat1,sat2, mask=(ne(sat1,10._sp).and.ne(sat2,10._sp)), ddof=1)\n isgood = isgood .and. (nint(10._sp*stmp) == 129)\n if (.not. isgood) write(*,*) 'mo_moment sp 4.10'\n stmp = mixed_central_moment(sat1,sat2,1,1, mask=(ne(sat1,10._sp).and.ne(sat2,10._sp)))\n isgood = isgood .and. (nint(10._sp*stmp) == 115)\n if (.not. isgood) write(*,*) 'mo_moment sp 4.11'\n stmp = mixed_central_moment_var(sat1,sat2,1,1, mask=(ne(sat1,10._sp).and.ne(sat2,10._sp)))\n isgood = isgood .and. (nint(10._sp*stmp) == 113)\n if (.not. isgood) write(*,*) 'mo_moment sp 4.12'\n\n if (isgood) then\n write(*,*) 'mo_moment single precision ', color('o.k.', c_green)\n else\n write(*,*) 'mo_moment single precision ', color('failed!', c_red)\n endif\n\nEND PROGRAM main\n", "meta": {"hexsha": "09b443d8d4f69cd77d955158bf8f28568013a08c", "size": 11648, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/test_mo_moment/main.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_moment/main.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_moment/main.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": 44.1212121212, "max_line_length": 95, "alphanum_fraction": 0.6275755495, "num_tokens": 5069, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.899121388082479, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6787602059189541}} {"text": "!---------------------------------------------------------------------!\n! OWNER: Ithaca Combustion Enterprise, LLC !\n! COPYRIGHT: \u00a9 2012, Ithaca Combustion Enterprise, LLC !\n! LICENSE: BSD 3-Clause License (The complete text of the license can !\n! be found in the `LICENSE-ICE.txt' file included in the ISAT-CK7 !\n! source directory.) !\n!---------------------------------------------------------------------!\n\nsubroutine ell_aff_pr( n, c, gg, m, d, T, cp, ggp )\n\n! Given an ellipsoid E (in R^n), and an m-dimensional affine space A, \n! determine the ellipsoid P(E) which is the orthogonal projection of E onto A,\n! for 1 <= m <= n.\n\n! E is defined by: || G^T * (x-c) || <= 1, where the array gg\n! contains the lower Cholesky triangle G in packed format. \n\n! A is defined by { x | x = d + T * s }, where T is an n x m orthogonal\n! matrix, and s is any m-vector.\n\n! The orthogonal projection of the general point x is given by:\n! P(x) = { x | d + T * s, s = T^T * ( x - d ) }.\n\n! The orthogonal projection of E onto A is given by:\n! P(E) = { x | d + T * s, || GP^T * ( s - cp ) || <= 1 }, where the\n! array ggp contains GP in packed format. \n\n! Method:\n! cp = T^T * ( c - d )\n! F = G^{-1} * T = U * [ S ; 0 ] * V^T\n! B = V * S^{-1}\n! GP * GP^T = B * B^T\n\nimplicit none\n\ninteger, parameter :: k_dp = kind(1.d0)\ninteger, intent(in) :: n, m\nreal(k_dp), intent(in) :: c(n), gg((n*(n+1))/2), d(n), T(n,m)\nreal(k_dp), intent(out) :: cp(m), ggp((m*(m+1))/2)\n\ninteger, parameter :: ludiag = 0\ninteger :: i, j, k, info, lwork\nreal(k_dp) :: G(n,n), F(n,m), S(m), B(m,m), VT(m,m), work(5*n*n+20*n)\n\n! check dimensions\nif( n < 1 ) then\n write(ludiag,*)'ell_aff_pr: n < 1, n = ', n\n stop\nendif\n\nlwork = 5*n*n+20*n ! amount of work space for SVD\n\nif( m > n ) then\n write(ludiag,*)'ell_aff_pr: m > n, [m n] = ', m, n\n stop\nelseif( m < 1 ) then\n write(ludiag,*)'ell_aff_pr: m < 1, m = ', m\n stop\nendif\n\n! form cp = T^T * ( c - d )\n\ncp = matmul( (c-d) , T )\n\n! unpack G\n\nG = 0.d0\n\nk = 0\ndo j = 1, n\n do i = j, n\n k = k + 1\n\t G(i,j) = gg(k)\n end do\nend do\n\n! form F = G^{-1} * T\nF = T\ncall dtrsm('L','L','N','N',n,m,1.d0,G,n,F,n)\n\n! form S and V^T in: F = U * [ S ; 0 ] * V^T\n\ncall dgesvd('N','A',n,m,F,n,S,B,m,VT,m,work,lwork,info)\n\nif( info /= 0 ) then\n write(ludiag,*)'ell_aff_pr: SVD failed, info = ', info\n stop\nelseif( S(m) <= 0.d0 ) then\n write(ludiag,*)'ell_aff_pr: zero singular value, S = ', S\n stop\nendif\n\n! form B = V * S^{-1}\n\ndo j = 1, m\n B(1:m,j) = VT(j,1:m) / S(j)\nend do\n\n! form GP: GP * GP^T = B * B^T\n\ncall ell_bbt2chol( m, B, ggp )\n\nreturn\nend subroutine ell_aff_pr ", "meta": {"hexsha": "924d281a9b55328fa6e86660d108c048b31b45ae", "size": 2753, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/isat/ell_lib/ell_aff_pr.f90", "max_stars_repo_name": "xuhan425/isat_ffd", "max_stars_repo_head_hexsha": "3a5449f7e49b686c33fe0e97ca90ea8d92fc2f00", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-04-10T20:16:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-15T11:09:44.000Z", "max_issues_repo_path": "src/isat/ell_lib/ell_aff_pr.f90", "max_issues_repo_name": "xuhan425/isat_ffd", "max_issues_repo_head_hexsha": "3a5449f7e49b686c33fe0e97ca90ea8d92fc2f00", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-06-07T14:10:25.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-07T14:10:25.000Z", "max_forks_repo_path": "src/isat/ell_lib/ell_aff_pr.f90", "max_forks_repo_name": "xuhan425/isat_ffd", "max_forks_repo_head_hexsha": "3a5449f7e49b686c33fe0e97ca90ea8d92fc2f00", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-06-07T03:44:12.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-05T05:54:10.000Z", "avg_line_length": 26.4711538462, "max_line_length": 79, "alphanum_fraction": 0.5056302216, "num_tokens": 1014, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088005554475, "lm_q2_score": 0.7310585844894971, "lm_q1q2_score": 0.6787212235616573}} {"text": "program NN\n implicit none\n real :: inputs(4,1),weights(3,4),biases(3,1),outputs(3,1)\n\n inputs = reshape([ 1.0 , 2.0 , 3.0 , 2.5 ],shape(inputs))\n\n weights = reshape([ 0.2 , 0.8 , -0.5 , 1.0,&\n 0.5 , -0.91, 0.26, -0.5,& \n -0.26, -0.27, 0.17, 0.87], shape(weights),order=[2,1])\n\n biases = reshape([2.0, 3.0, 0.5], shape(biases))\n\n outputs = matmul(weights,inputs) + biases\n ! In fortran, dot_product is only for vectors\n\n print *, outputs\nend program NN\n", "meta": {"hexsha": "31afbe7d8878d49908a2fd4b772bca3ade4b37b2", "size": 540, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran/p003-Dot-Product.f90", "max_stars_repo_name": "yarikbratashchuk/NNfSiX", "max_stars_repo_head_hexsha": "6ea56e3187d3742752c8cbef1bf30d8cf91bfe09", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1045, "max_stars_repo_stars_event_min_datetime": "2020-04-16T20:11:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T14:33:49.000Z", "max_issues_repo_path": "Fortran/p003-Dot-Product.f90", "max_issues_repo_name": "yarikbratashchuk/NNfSiX", "max_issues_repo_head_hexsha": "6ea56e3187d3742752c8cbef1bf30d8cf91bfe09", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 87, "max_issues_repo_issues_event_min_datetime": "2020-04-17T02:36:52.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-15T01:04:27.000Z", "max_forks_repo_path": "Fortran/p003-Dot-Product.f90", "max_forks_repo_name": "yarikbratashchuk/NNfSiX", "max_forks_repo_head_hexsha": "6ea56e3187d3742752c8cbef1bf30d8cf91bfe09", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 359, "max_forks_repo_forks_event_min_datetime": "2020-04-16T21:41:30.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-28T10:23:47.000Z", "avg_line_length": 30.0, "max_line_length": 80, "alphanum_fraction": 0.5111111111, "num_tokens": 212, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087965937712, "lm_q2_score": 0.7310585727705127, "lm_q1q2_score": 0.6787212097854316}} {"text": " IMPLICIT NONE \n REAL(8)::x,vel,F,m,H\n INTEGER::ixx\n INTEGER,PARAMETER::itime = 100000\n\t REAL,PARAMETER::xposeq = 0.00d0, val=1.000d0,delta=0.002d0\n\t\t\n\t x = 0.00d0\n\t\tvel = 1.00d0\n F= -val*(x-xposeq)\n m=1.00d0\n ixx=0\n \n write(16,*) ixx*delta,x\n write(18,*) ixx*delta,vel\n H = 0.5d0 *(vel**2) + 0.5d0 * val *(x**2)\n write(20,*) x,vel\n write(24,*) ixx*delta,H\n \n\t\tdo ixx = 1, itime \n\t\t vel = vel + (0.5d0*(F/m)*delta)\n x=x + (vel*delta)\n F = -val*(x-xposeq)\n vel = vel + (0.5d0*(F/m)*delta) \n write(16,*) ixx*delta,x\n write(18,*) ixx*delta,vel\n H = 0.5d0 *(vel**2) + 0.5d0 * val *(x**2)\n write(20,*) x,vel\n write(24,*) ixx*delta,H\n\t\tend do\n\t\tstop\n\t\tend\n", "meta": {"hexsha": "88615b818fca8b3844e57c5a6c7ddc506eb96ee9", "size": 1029, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "verlet_harmonic/change_2/test.f90", "max_stars_repo_name": "promitray/MD_FORTRAN", "max_stars_repo_head_hexsha": "e349f55a572fe68caf04725ff4b99389a3aaa51e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "verlet_harmonic/change_2/test.f90", "max_issues_repo_name": "promitray/MD_FORTRAN", "max_issues_repo_head_hexsha": "e349f55a572fe68caf04725ff4b99389a3aaa51e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "verlet_harmonic/change_2/test.f90", "max_forks_repo_name": "promitray/MD_FORTRAN", "max_forks_repo_head_hexsha": "e349f55a572fe68caf04725ff4b99389a3aaa51e", "max_forks_repo_licenses": ["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.15625, "max_line_length": 67, "alphanum_fraction": 0.3654033042, "num_tokens": 343, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087985746093, "lm_q2_score": 0.7310585669110203, "lm_q1q2_score": 0.678721205793536}} {"text": "C Copyright(C) 1999-2020 National Technology & Engineering Solutions\nC of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with\nC NTESS, the U.S. Government retains certain rights in this software.\nC\nC See packages/seacas/LICENSE for details\n\n SUBROUTINE INTSCT (X1, Y1, X2, Y2, X3, Y3, X4, Y4, U, W, LCROSS)\nC***********************************************************************\n\nC SUBROUTINE INTSCT = CHECKS TO SEE IF THE LINE FROM N1 TO N2\nC INTERSECTS THE LINE FROM N3 TO N4\n\nC***********************************************************************\n\nC NOTE: THIS INTERSECTION ROUTINE IS BASED ON AN ALGORITHM GIVEN\nC IN THE BOOK \"GEOMETRIC MODELING\" BY MICHAEL E. MORTENSON ON\nC PAGES 319 - 320.\n\nC***********************************************************************\n\n LOGICAL LCROSS\n\n LCROSS = .FALSE.\n\n if (max(x1, x2) .lt. min(x3, x4)) return\n if (max(y1, y2) .lt. min(y3, y4)) return\n if (max(x3, x4) .lt. min(x1, x2)) return\n if (max(y3, y4) .lt. min(y1, y2)) return\n\nC SET UP THE FIRST LINE'S VECTORS (A AND B)\n\n XA = X1\n YA = Y1\n XB = X2 - X1\n YB = Y2 - Y1\n\nC SET UP THE SECOND LINE'S VECTORS (C AND D)\n\n XC = X3\n YC = Y3\n XD = X4 - X3\n YD = Y4 - Y3\n\nC NOW USE THE VECTORS AND SOLVE FOR W.\nC W IS THE PROPORTION OF THE DISTANCE ALONG THE VECTOR D\nC WHERE THE INTERSECTION OCCURS. LIKEWISE U IS THE PROPORTIONAL\nC DISTANCE ALONG THE VECTOR B FOR THE INTERSECTION. IF THERE IS\nC AN INTERSECTION, BOTH U AND W MUST BE BETWEEN 0 AND 1.\n\n DENOM = (YB * XD) - (XB * YD)\n\nC CHECK FOR SPECIAL PARALLEL CASE - THE DENOMINATOR IS EQUAL TO ZERO.\n\n IF (DENOM .NE. 0.) THEN\n\nC CHECK FOR INTERSECTION\n\n W = ( (YC * XB) - (XB * YA) - (XC * YB) + (YB * XA) ) / DENOM\n IF ( (W .LT. 1.) .AND. (W .GT. 0.) ) THEN\n\nC W INDICATES AN INTERSECTION HAS OCCURRED.\nC GET THE U VALUE AND CONFIRM.\n\n IF (XB .NE. 0.) THEN\n U = ( XC + (W * XD) - XA ) / XB\n ELSE\n U = ( YC + (W * YD) - YA ) / YB\n ENDIF\n IF ( (U .LT. 1.) .AND. (U .GT. 0.) ) THEN\n LCROSS = .TRUE.\n ENDIF\n ENDIF\n ENDIF\n\n RETURN\n\n END\n", "meta": {"hexsha": "b863e02890f31e95baf400e6c8ccd3b6278814d3", "size": 2285, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "packages/seacas/applications/fastq/intsct.f", "max_stars_repo_name": "jschueller/seacas", "max_stars_repo_head_hexsha": "14c34ae08b757cba43a3a03ec0f129c8a168a9d3", "max_stars_repo_licenses": ["Python-2.0", "Zlib", "BSD-2-Clause", "MIT", "NetCDF", "BSL-1.0", "X11", "BSD-3-Clause"], "max_stars_count": 82, "max_stars_repo_stars_event_min_datetime": "2016-02-04T18:38:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T03:01:49.000Z", "max_issues_repo_path": "packages/seacas/applications/fastq/intsct.f", "max_issues_repo_name": "jschueller/seacas", "max_issues_repo_head_hexsha": "14c34ae08b757cba43a3a03ec0f129c8a168a9d3", "max_issues_repo_licenses": ["Python-2.0", "Zlib", "BSD-2-Clause", "MIT", "NetCDF", "BSL-1.0", "X11", "BSD-3-Clause"], "max_issues_count": 206, "max_issues_repo_issues_event_min_datetime": "2015-11-20T01:57:47.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:12:04.000Z", "max_forks_repo_path": "packages/seacas/applications/fastq/intsct.f", "max_forks_repo_name": "jschueller/seacas", "max_forks_repo_head_hexsha": "14c34ae08b757cba43a3a03ec0f129c8a168a9d3", "max_forks_repo_licenses": ["Python-2.0", "Zlib", "BSD-2-Clause", "MIT", "NetCDF", "BSL-1.0", "X11", "BSD-3-Clause"], "max_forks_count": 68, "max_forks_repo_forks_event_min_datetime": "2016-01-13T22:46:51.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T06:25:05.000Z", "avg_line_length": 29.2948717949, "max_line_length": 75, "alphanum_fraction": 0.5115973742, "num_tokens": 748, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850110816424, "lm_q2_score": 0.7248702702332475, "lm_q1q2_score": 0.6786851689980893}} {"text": " SUBROUTINE MB03DD( UPLO, N1, N2, PREC, A, LDA, B, LDB, Q1, LDQ1,\n $ Q2, LDQ2, DWORK, LDWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute orthogonal matrices Q1 and Q2 for a real 2-by-2,\nC 3-by-3, or 4-by-4 regular block upper triangular pencil\nC\nC ( A11 A12 ) ( B11 B12 )\nC aA - bB = a ( ) - b ( ), (1)\nC ( 0 A22 ) ( 0 B22 )\nC\nC such that the pencil a(Q2' A Q1) - b(Q2' B Q1) is still in block\nC upper triangular form, but the eigenvalues in Spec(A11, B11),\nC Spec(A22, B22) are exchanged, where Spec(X,Y) denotes the spectrum\nC of the matrix pencil (X,Y) and the notation M' denotes the\nC transpose of the matrix M.\nC\nC Optionally, to upper triangularize the real regular pencil in\nC block lower triangular form\nC\nC ( A11 0 ) ( B11 0 )\nC aA - bB = a ( ) - b ( ), (2)\nC ( A21 A22 ) ( B21 B22 )\nC\nC while keeping the eigenvalues in the same diagonal position.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC UPLO CHARACTER*1\nC Specifies if the pencil is in lower or upper block\nC triangular form on entry, as follows:\nC = 'U': Upper block triangular, eigenvalues are exchanged\nC on exit;\nC = 'T': Upper block triangular, B triangular, eigenvalues\nC are exchanged on exit;\nC = 'L': Lower block triangular, eigenvalues are not\nC exchanged on exit.\nC\nC Input/Output Parameters\nC\nC N1 (input/output) INTEGER\nC Size of the upper left block, N1 <= 2.\nC If UPLO = 'U' or UPLO = 'T' and INFO = 0, or UPLO = 'L'\nC and INFO <> 0, N1 and N2 are exchanged on exit; otherwise,\nC N1 is unchanged on exit.\nC\nC N2 (input/output) INTEGER\nC Size of the lower right block, N2 <= 2.\nC If UPLO = 'U' or UPLO = 'T' and INFO = 0, or UPLO = 'L'\nC and INFO <> 0, N1 and N2 are exchanged on exit; otherwise,\nC N2 is unchanged on exit.\nC\nC PREC (input) DOUBLE PRECISION\nC The machine precision, (relative machine precision)*base.\nC See the LAPACK Library routine DLAMCH.\nC\nC A (input/output) DOUBLE PRECISION array, dimension\nC (LDA, N1+N2)\nC On entry, the leading (N1+N2)-by-(N1+N2) part of this\nC array must contain the matrix A of the pencil aA - bB.\nC On exit, if N1 = N2 = 1, this array is unchanged, if\nC UPLO = 'U' or UPLO = 'T', but, if UPLO = 'L', it contains\nC [ 0 1 ]\nC the matrix J' A J, where J = [ -1 0 ]; otherwise, this\nC array contains the transformed quasi-triangular matrix in\nC generalized real Schur form.\nC\nC LDA INTEGER\nC The leading dimension of the array A. LDA >= N1+N2.\nC\nC B (input/output) DOUBLE PRECISION array, dimension\nC (LDB, N1+N2)\nC On entry, the leading (N1+N2)-by-(N1+N2) part of this\nC array must contain the matrix B of the pencil aA - bB.\nC On exit, if N1 = N2 = 1, this array is unchanged, if\nC UPLO = 'U' or UPLO = 'T', but, if UPLO = 'L', it contains\nC the matrix J' B J; otherwise, this array contains the\nC transformed upper triangular matrix in generalized real\nC Schur form.\nC\nC LDB INTEGER\nC The leading dimension of the array B. LDB >= N1+N2.\nC\nC Q1 (output) DOUBLE PRECISION array, dimension (LDQ1, N1+N2)\nC The leading (N1+N2)-by-(N1+N2) part of this array contains\nC the first orthogonal transformation matrix.\nC\nC LDQ1 INTEGER\nC The leading dimension of the array Q1. LDQ1 >= N1+N2.\nC\nC Q2 (output) DOUBLE PRECISION array, dimension (LDQ2, N1+N2)\nC The leading (N1+N2)-by-(N1+N2) part of this array contains\nC the second orthogonal transformation matrix.\nC\nC LDQ2 INTEGER\nC The leading dimension of the array Q2. LDQ2 >= N1+N2.\nC\nC Workspace\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC If N1+N2 = 2 then DWORK is not referenced.\nC\nC LDWORK INTEGER\nC The dimension of the array DWORK.\nC If N1+N2 = 2, then LDWORK = 0; otherwise,\nC LDWORK >= 16*N1 + 10*N2 + 23, if UPLO = 'U';\nC LDWORK >= 7*N1 + 7*N2 + 16, if UPLO = 'T';\nC LDWORK >= 10*N1 + 16*N2 + 23, if UPLO = 'L'.\nC For good performance LDWORK should be generally larger.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: succesful exit;\nC = 3: the QZ iteration failed in the LAPACK routine DGGES\nC (if UPLO <> 'T') or DHGEQZ (if UPLO = 'T');\nC = 4: another error occured during execution of DHGEQZ;\nC = 5: reordering of aA - bB in the LAPACK routine DTGSEN\nC failed because the transformed matrix pencil aA - bB\nC would be too far from generalized Schur form;\nC the problem is very ill-conditioned.\nC\nC METHOD\nC\nC The algorithm uses orthogonal transformations as described in [2]\nC (page 30). The QZ algorithm is used for N1 = 2 or N2 = 2, but it\nC always acts on an upper block triangular pencil.\nC\nC REFERENCES\nC\nC [1] Benner, P., Byers, R., Mehrmann, V. and Xu, H.\nC Numerical computation of deflating subspaces of skew-\nC Hamiltonian/Hamiltonian pencils.\nC SIAM J. Matrix Anal. Appl., 24 (1), pp. 165-190, 2002.\nC\nC [2] Benner, P., Byers, R., Losse, P., Mehrmann, V. and Xu, H.\nC Numerical Solution of Real Skew-Hamiltonian/Hamiltonian\nC Eigenproblems.\nC Tech. Rep., Technical University Chemnitz, Germany,\nC Nov. 2007.\nC\nC NUMERICAL ASPECTS\nC\nC The algorithm is numerically backward stable.\nC\nC CONTRIBUTOR\nC\nC Matthias Voigt, Fakultaet fuer Mathematik, Technische Universitaet\nC Chemnitz, October 16, 2008.\nC\nC REVISIONS\nC\nC V. Sima, July 2009 (SLICOT version of the routine DBTUEX).\nC V. Sima, Nov. 2009, Oct. 2010, Nov. 2010, Mar. 2016, Apr. 2016,\nC May 2016.\nC M. Voigt, Jan. 2012.\nC\nC KEYWORDS\nC\nC Block triangular pencil, eigenvalue exchange.\nC\nC ******************************************************************\nC\n DOUBLE PRECISION ZERO, ONE, TEN, HUND\n PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0, TEN = 1.0D+1,\n $ HUND = 1.0D+2 )\nC\nC .. Scalar Arguments ..\n CHARACTER UPLO\n INTEGER INFO, LDA, LDB, LDQ1, LDQ2, LDWORK, N1, N2\n DOUBLE PRECISION PREC\nC\nC .. Array Arguments ..\n DOUBLE PRECISION A( LDA, * ), B( LDB, * ), DWORK( * ),\n $ Q1( LDQ1, * ), Q2( LDQ2, * )\nC\nC .. Local Scalars ..\n LOGICAL AEVINF, EVINF, LTRIU, LUPLO\n INTEGER CNT, EVSEL, I, IAEV, IDUM, IEVS, ITMP, J, M\n DOUBLE PRECISION A11, A22, ABSAEV, ABSEV, ADIF, B11, B22, CO,\n $ CO1, E, G, MX, NRA, NRB, SFMIN, SI, SI1, TMP,\n $ TOL, TOLB\nC\nC .. Local Arrays ..\n LOGICAL BWORK( 1 ), OUT( 2 ), SLCT( 4 )\n INTEGER IDM( 2 )\n DOUBLE PRECISION AS( 2, 2 ), BS( 2, 2 ), DUM( 8 )\nC\nC .. External Functions ..\n LOGICAL LSAME, SB02OW\n DOUBLE PRECISION DLAMCH, DLANGE, DLANHS\n EXTERNAL DLAMCH, DLANGE, DLANHS, LSAME, SB02OW\nC\nC .. External Subroutines ..\n EXTERNAL DCOPY, DGGES, DHGEQZ, DLACPY, DLAG2, DLARTG,\n $ DLASET, DROT, DSWAP, DTGEX2, DTGSEN, MB01QD\nC\nC .. Intrinsic Functions ..\n INTRINSIC ABS, MAX, SIGN\nC\nC .. Executable Statements ..\nC\nC Decode the input arguments.\nC\n LTRIU = LSAME( UPLO, 'T' )\n LUPLO = LSAME( UPLO, 'U' ) .OR. LTRIU\nC\nC For efficiency, the input arguments are not tested.\nC\n INFO = 0\nC\nC Computations.\nC\nC (Note: Comments in the code beginning \"Workspace:\" describe the\nC minimal amount of real workspace needed at that point in the\nC code, as well as the preferred amount for good performance.)\nC\n M = N1 + N2\n IF( M.GT.2 ) THEN\n IF( .NOT.LUPLO ) THEN\nC\nC Make the pencil upper block triangular.\nC Quick return if A21 = 0 and B21 = 0.\nC\n IF( DLANGE( '1-norm', N2, N1, A( N1+1, 1 ), LDA, DWORK )\n $ .EQ.ZERO .AND.\n $ DLANGE( '1-norm', N2, N1, B( N1+1, 1 ), LDB, DWORK )\n $ .EQ.ZERO ) THEN\n IF( N1.EQ.2 ) THEN\n CALL DGGES( 'Vectors', 'Vectors', 'Not sorted',\n $ SB02OW, N1, A, LDA, B, LDB, IDUM, DWORK,\n $ DWORK( M+1 ), DWORK( 2*M+1 ), Q2, LDQ2,\n $ Q1, LDQ1, DWORK( 3*M+1 ), LDWORK-2*M,\n $ BWORK, INFO )\n IF( INFO.NE.0 ) THEN\n IF( INFO.GE.1 .AND. INFO.LE.N1 ) THEN\n INFO = 3\n RETURN\n ELSE\n INFO = 4\n RETURN\n END IF\n END IF\n IF( N2.EQ.1 ) THEN\n Q1( 3, 3 ) = ONE\n Q2( 3, 3 ) = ONE\n END IF\n END IF\n IF( N2.EQ.2 ) THEN\n CALL DGGES( 'Vectors', 'Vectors', 'Not sorted',\n $ SB02OW, N2, A( N1+1, N1+1 ), LDA,\n $ B( N1+1, N1+1 ), LDB, IDUM, DWORK( N1+1 ),\n $ DWORK( M+N1+1 ), DWORK( 2*M+N1+1 ),\n $ Q2( N1+1, N1+1 ), LDQ2, Q1( N1+1, N1+1 ),\n $ LDQ1, DWORK( 3*M+1 ), LDWORK-2*M, BWORK,\n $ INFO )\n IF( INFO.NE.0 ) THEN\n IF( INFO.GE.1 .AND. INFO.LE.N2 ) THEN\n INFO = 3\n RETURN\n ELSE\n INFO = 4\n RETURN\n END IF\n END IF\n IF( N1.EQ.1 ) THEN\n Q1( 1, 1 ) = ONE\n Q2( 1, 1 ) = ONE\n END IF\n END IF\n CALL DLASET( 'Full', N2, N1, ZERO, ZERO, Q1( N1+1, 1 ),\n $ LDQ1 )\n CALL DLASET( 'Full', N1, N2, ZERO, ZERO, Q1( 1, N1+1 ),\n $ LDQ1 )\n CALL DLASET( 'Full', N2, N1, ZERO, ZERO, Q2( N1+1, 1 ),\n $ LDQ2 )\n CALL DLASET( 'Full', N1, N2, ZERO, ZERO, Q2( 1, N1+1 ),\n $ LDQ2 )\n RETURN\n END IF\n IF( N1.EQ.1 ) THEN\n DUM( 1 ) = A( 1, 1 )\n DUM( 2 ) = A( 2, 1 )\n A( 1, 1 ) = A( 2, 2 )\n A( 2, 1 ) = A( 3, 2 )\n A( 1, 2 ) = A( 2, 3 )\n A( 2, 2 ) = A( 3, 3 )\n A( 1, 3 ) = DUM( 2 )\n A( 2, 3 ) = A( 3, 1 )\n A( 3, 3 ) = DUM( 1 )\n A( 3, 1 ) = ZERO\n A( 3, 2 ) = ZERO\n DUM( 1 ) = B( 1, 1 )\n DUM( 2 ) = B( 2, 1 )\n B( 1, 1 ) = B( 2, 2 )\n B( 2, 1 ) = B( 3, 2 )\n B( 1, 2 ) = B( 2, 3 )\n B( 2, 2 ) = B( 3, 3 )\n B( 1, 3 ) = DUM( 2 )\n B( 2, 3 ) = B( 3, 1 )\n B( 3, 3 ) = DUM( 1 )\n B( 3, 1 ) = ZERO\n B( 3, 2 ) = ZERO\n ELSE IF( N2.EQ.1 ) THEN\n DUM( 1 ) = A( 3, 2 )\n DUM( 2 ) = A( 3, 3 )\n A( 2, 3 ) = A( 1, 2 )\n A( 3, 3 ) = A( 2, 2 )\n A( 2, 2 ) = A( 1, 1 )\n A( 3, 2 ) = A( 2, 1 )\n A( 1, 1 ) = DUM( 2 )\n A( 1, 2 ) = A( 3, 1 )\n A( 1, 3 ) = DUM( 1 )\n A( 2, 1 ) = ZERO\n A( 3, 1 ) = ZERO\n DUM( 1 ) = B( 3, 2 )\n DUM( 2 ) = B( 3, 3 )\n B( 2, 3 ) = B( 1, 2 )\n B( 3, 3 ) = B( 2, 2 )\n B( 2, 2 ) = B( 1, 1 )\n B( 3, 2 ) = B( 2, 1 )\n B( 1, 1 ) = DUM( 2 )\n B( 1, 2 ) = B( 3, 1 )\n B( 1, 3 ) = DUM( 1 )\n B( 2, 1 ) = ZERO\n B( 3, 1 ) = ZERO\n ELSE\nC\n DO 10 J = 1, N1\n CALL DSWAP( N1, A( 1, J ), 1, A( N1+1, N1+J ), 1 )\n CALL DSWAP( N1, A( 1, N1+J ), 1, A( N1+1, J ), 1 )\n CALL DSWAP( N1, B( 1, J ), 1, B( N1+1, N1+J ), 1 )\n CALL DSWAP( N1, B( 1, N1+J ), 1, B( N1+1, J ), 1 )\n 10 CONTINUE\nC\n END IF\nC\n ITMP = N1\n N1 = N2\n N2 = ITMP\n END IF\nC\nC Apply the QZ algorithm and order the eigenvalues in\nC DWORK(1:3*N1) to the top.\nC Note that N1 and N2 are interchanged for UPLO = 'L'.\nC\n IEVS = 3*N1 + 1\n IAEV = IEVS + 3*N1\n IF( N1.EQ.1 ) THEN\n DWORK( 1 ) = A( 1, 1 )*SIGN( ONE, B( 1, 1 ) )\n DWORK( 2 ) = ZERO\n DWORK( 3 ) = ABS( B( 1, 1 ) )\n ELSE\n SFMIN = DLAMCH( 'Safemin' )\n Q1( 1, 1 ) = A( 1, 1 )\n Q1( 2, 1 ) = A( 2, 1 )\n Q1( 1, 2 ) = A( 1, 2 )\n Q1( 2, 2 ) = A( 2, 2 )\n Q2( 1, 1 ) = B( 1, 1 )\n Q2( 2, 1 ) = B( 2, 1 )\n Q2( 1, 2 ) = B( 1, 2 )\n Q2( 2, 2 ) = B( 2, 2 )\n IF( .NOT.LTRIU .AND. B( 2, 1 ).NE.ZERO ) THEN\nC\nC Triangularize B11 and update A11.\nC\n A11 = ABS( Q1( 1, 1 ) )\n A22 = ABS( Q1( 2, 2 ) )\n B11 = ABS( Q2( 1, 1 ) )\n B22 = ABS( Q2( 2, 2 ) )\n MX = MAX( A11 + ABS( Q1( 2, 1 ) ),\n $ A22 + ABS( Q1( 1, 2 ) ),\n $ B11 + ABS( Q2( 2, 1 ) ),\n $ B22 + ABS( Q2( 1, 2 ) ), SFMIN )\n Q1( 1, 1 ) = Q1( 1, 1 ) / MX\n Q1( 2, 1 ) = Q1( 2, 1 ) / MX\n Q1( 1, 2 ) = Q1( 1, 2 ) / MX\n Q1( 2, 2 ) = Q1( 2, 2 ) / MX\n Q2( 1, 1 ) = Q2( 1, 1 ) / MX\n Q2( 2, 1 ) = Q2( 2, 1 ) / MX\n Q2( 1, 2 ) = Q2( 1, 2 ) / MX\n Q2( 2, 2 ) = Q2( 2, 2 ) / MX\n CALL DLARTG( Q2( 1, 1 ), Q2( 2, 1 ), CO, SI, E )\n CALL DLARTG( Q2( 2, 2 ), Q2( 2, 1 ), CO1, SI1, G )\n IF( ABS( CO *B( 2, 1 ) - SI *B( 1, 1 ) ).LE.\n $ ABS( CO1*B( 2, 1 ) - SI1*B( 2, 2 ) ) ) THEN\n CALL DROT( 2, Q1( 1, 1 ), LDQ1, Q1( 2, 1 ), LDQ1, CO,\n $ SI )\n Q2( 1, 1 ) = E\n TMP = Q2( 1, 2 )\n Q2( 1, 2 ) = SI*Q2( 2, 2 ) + CO*TMP\n Q2( 2, 2 ) = CO*Q2( 2, 2 ) - SI*TMP\n ELSE\n CALL DROT( 2, Q1( 1, 2 ), 1, Q1( 1, 1 ), 1, CO1, SI1 )\n Q2( 2, 2 ) = G\n TMP = Q2( 1, 2 )\n Q2( 1, 2 ) = SI1*Q2( 1, 1 ) + CO1*TMP\n Q2( 1, 1 ) = CO1*Q2( 1, 1 ) - SI1*TMP\n END IF\n Q2( 2, 1 ) = ZERO\n END IF\n CALL DLAG2( Q1, LDQ1, Q2, LDQ2, SFMIN*HUND, DWORK( 2*N1+1 ),\n $ DWORK( 2*N1+2 ), DWORK( 1 ), DWORK( 2 ),\n $ DWORK( N1+1 ) )\n DWORK( N1+2 ) = -DWORK( N1+1 )\n END IF\nC\n ITMP = IAEV + 3*M\n CALL DCOPY( 3*N1, DWORK, 1, DWORK( IEVS ), 1 )\n IF( LTRIU ) THEN\nC\nC Workspace: need 10*N1 + 4*N2.\nC\n CALL DHGEQZ( 'Schur', 'Identity', 'Identity', M, 1, M, A,\n $ LDA, B, LDB, DWORK( IAEV ), DWORK( IAEV+M ),\n $ DWORK( IAEV+2*M ), Q2, LDQ2, Q1, LDQ1,\n $ DWORK( ITMP ), LDWORK-ITMP+1, INFO )\n IF( INFO.GE.1 .AND. INFO.LE.M ) THEN\n INFO = 3\n RETURN\n ELSE IF( INFO.NE.0 ) THEN\n INFO = 4\n RETURN\n END IF\n ELSE\nC\nC Workspace: need 16*N1 + 10*N2 + 23;\nC prefer larger.\nC\n CALL DGGES( 'Vectors', 'Vectors', 'Not sorted', SB02OW, M,\n $ A, LDA, B, LDB, IDUM, DWORK( IAEV ),\n $ DWORK( IAEV+M ), DWORK( IAEV+2*M ), Q2, LDQ2,\n $ Q1, LDQ1, DWORK( ITMP ), LDWORK-ITMP+1, BWORK,\n $ INFO )\n IF( INFO.NE.0 ) THEN\n IF( INFO.GE.1 .AND. INFO.LE.M ) THEN\n INFO = 3\n RETURN\n ELSE\n INFO = 4\n RETURN\n END IF\n END IF\n END IF\nC\n TOL = PREC\n TOLB = TEN*PREC\n EVSEL = 0\n DO 20 I = 1, M\n SLCT( I ) = .TRUE.\n 20 CONTINUE\nC\nC WHILE( EVSEL.EQ.0 ) DO\nC\n 30 CONTINUE\n IF( EVSEL.EQ.0 ) THEN\n CNT = 0\n OUT( 1 ) = .FALSE.\n OUT( 2 ) = .FALSE.\nC\n DO 50 I = IAEV, IAEV + M - 1\n AEVINF = ABS( DWORK( 2*M+I ) ).LT.PREC*\n $ ( ABS( DWORK( I ) ) + ABS( DWORK( M+I ) ) )\n DO 40 J = 1, N1\nC\nC Check if an eigenvalue is selected and check if it\nC is infinite.\nC\n EVINF = ABS( DWORK( 2*N1+J ) ).LT.PREC*\n $ ( ABS( DWORK( J ) ) + ABS( DWORK( N1+J ) ) )\n IF( ( .NOT. EVINF .OR. AEVINF ) .AND.\n $ ( .NOT.AEVINF .OR. EVINF ) .AND.\n $ .NOT. OUT( J ) ) THEN\n IF( .NOT.EVINF .OR. .NOT.AEVINF ) THEN\n ADIF = ABS( DWORK( J )/DWORK( 2*N1+J ) -\n $ DWORK( I )/DWORK( 2*M+I ) ) +\n $ ABS( DWORK( N1+J )/DWORK( 2*N1+J ) -\n $ DWORK( M+I )/DWORK( 2*M+I ) )\n ABSEV = ABS( DWORK( J )/DWORK( 2*N1+J ) ) +\n $ ABS( DWORK( N1+J )/DWORK( 2*N1+J ) )\n ABSAEV = ABS( DWORK( I )/DWORK( 2*M+I ) ) +\n $ ABS( DWORK( M+I )/DWORK( 2*M+I ) )\n IF( ADIF.LE.TOL*MAX( TOLB, ABSEV, ABSAEV ) )\n $ THEN\n SLCT( I-IAEV+1 ) = .FALSE.\n OUT( J ) = .TRUE.\n CNT = CNT + 1\n END IF\n ELSE\n SLCT( I-IAEV+1 ) = .FALSE.\n OUT( J ) = .TRUE.\n CNT = CNT + 1\n END IF\n END IF\n 40 CONTINUE\n 50 CONTINUE\nC\n IF( CNT.EQ.N1 ) THEN\n EVSEL = 1\n ELSE\nC\nC CNT < N1, too few eigenvalues selected.\nC\n TOL = TEN*TOL\n CALL DCOPY( 3*N1, DWORK( IEVS ), 1, DWORK, 1 )\n END IF\n GO TO 30\n END IF\nC END WHILE 30\nC\nC Workspace: need 7*N1 + 7*N2 + 16;\nC prefer larger.\nC\n ITMP = 3*M + 1\n NRA = DLANHS( '1-norm', M, A, LDA, DWORK )\n NRB = DLANHS( '1-norm', M, B, LDB, DWORK )\n IDM( 1 ) = 2\n IDM( 2 ) = 2\n CALL MB01QD( 'Hess', M, M, 0, 0, NRA, ONE, 2, IDM, A, LDA,\n $ INFO )\n CALL MB01QD( 'Hess', M, M, 0, 0, NRB, ONE, 2, IDM, B, LDB,\n $ INFO )\n CALL DTGSEN( 0, .TRUE., .TRUE., SLCT, M, A, LDA, B, LDB, DWORK,\n $ DWORK( M+1 ), DWORK( 2*M+1 ), Q2, LDQ2, Q1, LDQ1,\n $ IDUM, TMP, TMP, DUM, DWORK( ITMP ), LDWORK-ITMP+1,\n $ IDM, 1, INFO )\n IF( INFO.EQ.1 ) THEN\n INFO = 5\n RETURN\n END IF\nC\n CALL MB01QD( 'Hess', M, M, 0, 0, ONE, NRA, 0, IDM, A, LDA,\n $ INFO )\n CALL MB01QD( 'Hess', M, M, 0, 0, ONE, NRB, 0, IDM, B, LDB,\n $ INFO )\nC\nC Interchange N1 and N2.\nC\n ITMP = N1\n N1 = N2\n N2 = ITMP\nC\n IF( .NOT.LUPLO ) THEN\nC\nC Permute the rows of Q1 and Q2.\nC\n IF( N1.EQ.1 ) THEN\nC\n DO 60 J = 1, M\n TMP = Q1( 3, J )\n Q1( 3, J ) = Q1( 2, J )\n Q1( 2, J ) = Q1( 1, J )\n Q1( 1, J ) = TMP\n TMP = Q2( 3, J )\n Q2( 3, J ) = Q2( 2, J )\n Q2( 2, J ) = Q2( 1, J )\n Q2( 1, J ) = TMP\n 60 CONTINUE\nC\n ELSE IF( N2.EQ.1 ) THEN\nC\n DO 70 J = 1, M\n TMP = Q1( 1, J )\n Q1( 1, J ) = Q1( 2, J )\n Q1( 2, J ) = Q1( 3, J )\n Q1( 3, J ) = TMP\n TMP = Q2( 1, J )\n Q2( 1, J ) = Q2( 2, J )\n Q2( 2, J ) = Q2( 3, J )\n Q2( 3, J ) = TMP\n 70 CONTINUE\nC\n ELSE\nC\n DO 80 J = 1, M\n CALL DSWAP( N1, Q1( 1, J ), 1, Q1( N1+1, J ), 1 )\n CALL DSWAP( N1, Q2( 1, J ), 1, Q2( N1+1, J ), 1 )\n 80 CONTINUE\nC\n END IF\n END IF\n ELSE\nC\nC 2-by-2 case.\nC\n IF( .NOT.LUPLO .AND. A( 2, 1 ).EQ.ZERO\n $ .AND. B( 2, 1 ).EQ.ZERO ) THEN\n CALL DLASET( 'Full', M, M, ZERO, ONE, Q1, LDQ1 )\n CALL DLASET( 'Full', M, M, ZERO, ONE, Q2, LDQ2 )\n RETURN\n ELSE IF( LUPLO ) THEN\n CALL DLASET( 'Full', M, M, ZERO, ONE, Q1, LDQ1 )\n CALL DLASET( 'Full', M, M, ZERO, ONE, Q2, LDQ2 )\n ELSE\n TMP = A( 1, 1 )\n A( 1, 1 ) = A( 2, 2 )\n A( 2, 2 ) = TMP\n A( 1, 2 ) = -A( 2, 1 )\n A( 2, 1 ) = ZERO\n TMP = B( 1, 1 )\n B( 1, 1 ) = B( 2, 2 )\n B( 2, 2 ) = TMP\n B( 1, 2 ) = -B( 2, 1 )\n B( 2, 1 ) = ZERO\n Q1( 1, 1 ) = ZERO\n Q1( 2, 1 ) = -ONE\n Q1( 1, 2 ) = ONE\n Q1( 2, 2 ) = ZERO\n Q2( 1, 1 ) = ZERO\n Q2( 2, 1 ) = -ONE\n Q2( 1, 2 ) = ONE\n Q2( 2, 2 ) = ZERO\n END IF\n A11 = A( 1, 1 )\n A22 = A( 2, 2 )\n B11 = B( 1, 1 )\n B22 = B( 2, 2 )\n MX = MAX( ABS( A11 ), ABS( A22 ), ABS( A( 1, 2 ) ),\n $ ABS( B11 ), ABS( B22 ), ABS( B( 1, 2 ) ),\n $ DLAMCH( 'Safemin' ) )\n AS( 1, 1 ) = A11 / MX\n AS( 2, 1 ) = ZERO\n AS( 1, 2 ) = A( 1, 2 ) / MX\n AS( 2, 2 ) = A22 / MX\n BS( 1, 1 ) = B11 / MX\n BS( 2, 2 ) = B22 / MX\n BS( 1, 2 ) = B( 1, 2 ) / MX \n CALL DLACPY( 'Full', M, M, A, LDA, AS, 2 )\n CALL DLACPY( 'Full', M, M, B, LDB, BS, 2 )\n CALL DTGEX2( .TRUE., .TRUE., M, AS, 2, BS, 2, Q2, LDQ2, Q1,\n $ LDQ1, 1, 1, 1, DUM, 8, ITMP )\nC\n END IF\nC\n RETURN\nC *** Last line of MB03DD ***\n END\n", "meta": {"hexsha": "9d6b44c56373dc5c7137da0e42ec759c71757185", "size": 23608, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB03DD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB03DD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB03DD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 36.6015503876, "max_line_length": 72, "alphanum_fraction": 0.3977465266, "num_tokens": 8346, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9362850093037731, "lm_q2_score": 0.7248702702332475, "lm_q1q2_score": 0.6786851677093646}} {"text": "! *********************************************************************\n! * *\n! * S U B R O U T I N E G D D C A L C *\n! * gm 1/21/05 *\n! * *\n! * *\n! *********************************************************************\n! Subroutine GDDCALC: Calculates growing degree-days by various\n! methods. See McMaster and Wilhelm ref here *** Method 1 is\n! most common for wheat and barley. Method 2 is most common for corn,\n! sorghum, and soybean.\n\n! INPUTS: gddday(C,R), gmethod(R), tbase(R), tmax(R), tmin(R), tupper(R) \n\n! OUTPUTS: gddday(C,R)\n\n subroutine gddcalc(cname, daynum, df, gddday, gmethod, pf, tbase, \n c tmax, tmin, toptlo, toptup, tupper) !, vf) \n! \n implicit none\n \n integer daynum, gmethod\n \n real df, gddday, pf, tbase, tmax, tmin, toptlo, toptup, tupper !, vf\n \n character *22 cname\n character *256 outfgdd\n \n! Local variables\n real m, tavg, tavgtemp, tf, tmaxtemp, tmintemp, topt, x, x1, x2,\n c x3, x4, y, y1, y2, y3, y4 \n \n! Initialize local variables \n tavg = 0.0\n tavgtemp = 0.0\n tmaxtemp = tmax\n tmintemp = tmin\n topt = (toptlo + toptup) / 2\n\n !tbase point coordinates\n x1 = tbase\n y1 = 0.0\n !toplo point ccordinates\n x2 = toptlo\n y2 = 1.0 ! maximum development rate\n !toptup point coordinates\n x3= toptup\n y3 = 1.0\n !tupper point coordinates\n x4 = tupper\n y4 = 0.0\n! print *, 'tbase = ', tbase, 'toptlo = ', toptlo, 'toptup = ',\n! c toptup, 'tupper = ', tupper\n! Determine method of calculating growing degree-days\n! Calculate using Method 1:\n! This is a linear model.\n\n if (gmethod .eq. 1) then\n tavg = (tmax + tmin)/2.0 !need to be able to print tavg \n !for method 1\n! gddday = ((tmax + tmin)/2.) - tbase\n gddday = tavg - tbase \n if (gddday .lt. 0.) gddday = 0.\n \n! Calculate using Method 2:\n! This is a linear model with an upper threshold limit where no \n! additional gdd's are accumulated.\n elseif (gmethod .eq. 2) then\n! adjust tmax and tmin if need be and store values in tmaxtemp and tmintemp \n if (tmax .lt. tbase) tmaxtemp = tbase\n if (tmax .gt. toptup) tmaxtemp = toptup\n if (tmin .lt. tbase) tmintemp = tbase\n if (tmin .gt. toptup) tmintemp = toptup\n\n tavgtemp = (tmaxtemp + tmintemp)/2.\n gddday = tavgtemp - tbase\n \n if (gddday .lt. 0.) gddday = 0.\n if (gddday .gt. toptup) gddday = toptup\n !print *, 'gddday Method2 = ', gddday\n\n! Calculate using Method 3: \n! This is a two-segmented linear model\n else if (gmethod .eq. 3) then\n tavg = (tmax + tmin)/2.\n\n! if (tavg .GE. tbase) then\n! print *, 'tavg = ', tavg\n! endif \n\n! use the slope equation to determine a temperature factor (tf) by which\n! the day's gdd is adjusted.\n if ((tavg .GE. tbase) .AND. (tavg .LE. topt)) then\n m = (y2-y1)/(x2-x1) ! find the slope of the line tbase -topt \n !next find the point on the first segment of the linear model where\n !a line drawn perpendicular from the tavg point on the x axis will \n !interesect the first segment of the linear model. The y part of that\n !point will be the tf factor or the y axis portion of the intersected\n !point. Know the slope of the line, now find the point of intersection. \n !Use the point-slope equation\n ! y-y1 = m(x-x1) ! x2 and y2 could also be used in place of x1 and y1 \n x= tavg\n y = m*x - m*x1 + y1\n tf = y \n gddday = tf*(tavg-tbase)\n elseif ((tavg .GT. topt) .AND. (tavg .LE. tupper)) then\n m = (y4-y2)/(x4-x2)! find the slope of the line topt-tupper\n x = tavg\n y = m*x - m*x4 + y4\n tf = y\n gddday = tf*(tavg-tbase)\n elseif ((tavg .LT. tbase) .OR. (tavg .GT. tupper)) then\n gddday = 0.0 \n endif\n\n! Calculate using Method 4:\n! This is a three segmented linear model\n elseif (gmethod .eq. 4) then !this is method 3 w/another line segment\n tavg = (tmax + tmin)/2. \n \n if ((tavg .GE. tbase) .AND. (tavg .LT. toptlo)) then\n m = (y2-y1)/(x2-x1) !find the slope of the line tbase -toptlo\n ! y-y1 = m(x-x1) ! x2 and y2 could also be used in place of x1 and y1 \n x= tavg\n y = m*x - m*x1 + y1\n tf = y \n gddday = tf*(tavg-tbase)\n elseif ((tavg .GE. toptlo) .AND. (tavg .LE. toptup)) then \n m = (y3-y2)/(x3-x2)! find the slope of the line toptlo-toptup\n x = tavg ! this slope should be 0\n y = m*x - m*x2 + y2\n tf = y\n gddday = tf*(tavg-tbase)\n elseif ((tavg .GT. toptup) .AND. (tavg .LE. tupper)) then \n m = (y4-y3)/(x4-x3)! find the slope of the line toptup-tupper\n x = tavg \n y = m*x - m*x3 + y3\n tf = y\n gddday = tf*(tavg-tbase)\n! no growth when tavg is lower than tbase or greater than tupper.\n elseif ((tavg .LT. tbase) .OR. (tavg .GT. tupper)) then\n gddday = 0.0\n endif\n endif \n \n! Adjust thermal development units with photoperiod and vernalization\n !dtdu = gddday*(min(df, vf)) is this correct? \n\n! if(gmethod .eq. 2) then\n! print *, 'tavgtemp = ', tavgtemp, 'method # ', gmethod,\n! c'gddday = ', gddday\n! elseif (gmethod .ne. 2) then\n! print *, 'tavg = ',tavg, 'method # ', gmethod, 'gddday = ', \n! cgddday \n! endif \n \n ! use the photoperiod factor from the new photoperiod subroutine\n ! applied to soybeans. Adjust the thermal development units with\n ! the photoperiod factor (pf).\n \n !if (cname .eq. 'Soybean') then\n ! gddday = gddday*pf\n !endif\n \n return\n end\n", "meta": {"hexsha": "cc97c74cbb5bb8c8bc20f3c5f58f196fcbbf0a34", "size": 6257, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "PhenologyMMS/gddcalc.for", "max_stars_repo_name": "USDA-ARS-WMSRU/phenologymms-science", "max_stars_repo_head_hexsha": "e753a303f47ac6602d492d02399343dfe670b696", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "PhenologyMMS/gddcalc.for", "max_issues_repo_name": "USDA-ARS-WMSRU/phenologymms-science", "max_issues_repo_head_hexsha": "e753a303f47ac6602d492d02399343dfe670b696", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "PhenologyMMS/gddcalc.for", "max_forks_repo_name": "USDA-ARS-WMSRU/phenologymms-science", "max_forks_repo_head_hexsha": "e753a303f47ac6602d492d02399343dfe670b696", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.4670658683, "max_line_length": 84, "alphanum_fraction": 0.5128655905, "num_tokens": 1954, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850004144266, "lm_q2_score": 0.7248702642896702, "lm_q1q2_score": 0.6786851557008594}} {"text": "C LAST UPDATE 20/12/94\nC+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\nC\n SUBROUTINE FPEARSON(X,A,Y,DYDA)\n IMPLICIT NONE\nC\nC Purpose: Y(X;A) is Pearson VII. The amplitude. centre and widths of \nC the Pearson VII are stored in consecutive locations of A: \nC A(1) = H, A(2) = P, A(3) = FWHM, A(4) = S\nC\nC-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-\nC Parameters:\nC\n DOUBLE PRECISION TINY,HALF,BIG\n PARAMETER(TINY=1.0D-10,HALF=0.5D0,BIG=1.0D03)\nC\nC Arguments:\nC\n DOUBLE PRECISION A(10),DYDA(10)\n DOUBLE PRECISION X,Y \nC\nC Local variables:\nC\n DOUBLE PRECISION ARG,EX,FAC\nC\nC-----------------------------------------------------------------------\n IF(A(3).LT.TINY)A(3) = TINY\n IF(A(4).LT.HALF)A(4) = HALF\n IF(A(4).GT.BIG)A(4) = BIG\n ARG = (X-A(2))/A(3)\n EX = 2.0D0**(1.0D0/A(4)) - 1.0D0\n FAC = (1.0D0+4.0D0*ARG*ARG*EX)\n Y = A(1)/FAC**A(4)\n DYDA(1) = 1.0D0/FAC**A(4)\n DYDA(2) = 8.0D0*ARG*A(4)*EX*Y/(A(3)*FAC)\n DYDA(3) = ARG*DYDA(2)\n DYDA(4) = (4.0D0*ARG*ARG*LOG(2.0D0)*(EX+1.0D0)/\n & (A(4)*FAC)-LOG(FAC))*Y\nC\n RETURN\n END\n\n\n", "meta": {"hexsha": "e1ead7bf7f541b5a225eb122b142e60e8a1f4aff", "size": 1209, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "software/guifix/FPEARSON.f", "max_stars_repo_name": "scattering-central/CCP13", "max_stars_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "software/guifix/FPEARSON.f", "max_issues_repo_name": "scattering-central/CCP13", "max_issues_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "software/guifix/FPEARSON.f", "max_forks_repo_name": "scattering-central/CCP13", "max_forks_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-09-05T15:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-15T11:13:45.000Z", "avg_line_length": 27.4772727273, "max_line_length": 72, "alphanum_fraction": 0.4449958644, "num_tokens": 470, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898203834277, "lm_q2_score": 0.7490872187162397, "lm_q1q2_score": 0.6786653947362474}} {"text": "!module METS2AORSA\n\n! private\n! public:: WMATPRECALC_AORSA,GETNONMAXSWMAT_AORSA,GETNONMAXSWMAT_AORSA_NEW\n\n!contains\n\n!\n!*************************************************************************\n!\n\n subroutine WMATPRECALC_AORSA(ZSPEC,ASPEC,ENORM,BMAG,KPER,UPER, &\n & NUPER,NBESSJ,NBESSJ_START,XI,JNXI,IFAIL)\n implicit none\n real, intent(IN):: ZSPEC, ASPEC, ENORM,BMAG,KPER\n integer, intent(IN):: NUPER\n real, dimension(NUPER), intent(IN):: UPER\n integer, intent(IN):: NBESSJ,NBESSJ_START\n real, dimension(NUPER), intent(OUT):: XI\n real, dimension(NUPER,NBESSJ), intent(OUT):: JNXI\n integer, intent(OUT):: IFAIL\n\n real, parameter:: EOVERAMU=9.64853e7\n real, parameter:: EVPERAMU=9.314943e8\n real, parameter:: MPC2=938271998.38\n real, parameter:: C=2.99792458e8\n real:: WC,MUT0,SQMUT0\n\n MUT0=0.5*MPC2*ASPEC/ENORM\n SQMUT0=SQRT(MUT0)\n WC=BMAG*ZSPEC*EOVERAMU/ASPEC\n XI(:)=KPER*UPER(:)*C/SQMUT0/WC\n\n call BESSJ(XI(1),JNXI(1,1),NUPER,NBESSJ,NBESSJ_START)\n\n end subroutine WMATPRECALC_AORSA\n\n!\n!*************************************************************************\n!\n\n subroutine GETNONMAXSIGMA_AORSA_NEW(W,ZSPEC,ASPEC,DENS,BMAG, &\n & K1,XI1,JNXI1,K2,XI2,JNXI2,NBESSJ,ENORM,UPARMIN,UPARMAX, &\n & NUPAR,NUPER,UPER,UPAR,DFDUPER,DFDUPAR,WSPEC,IFAIL)\n implicit none\n real, intent(IN):: W,ZSPEC,ASPEC,DENS,BMAG\n real, dimension(3):: K1,K2\n integer, intent(IN):: NUPAR,NUPER,NBESSJ\n real, dimension(NUPER), intent(IN):: XI1,XI2\n real, dimension(NUPER, NBESSJ), intent(IN):: JNXI1,JNXI2\n real, intent(IN):: ENORM,UPARMIN,UPARMAX\n real, dimension(NUPER), intent(IN):: UPER\n real, dimension(NUPAR), intent(IN):: UPAR\n real, dimension(NUPER,NUPAR), intent(IN):: DFDUPER,DFDUPAR\n real DFDTH(NUPER,NUPAR)\n complex, dimension(3,3), intent(OUT):: WSPEC\n integer, intent(OUT):: IFAIL\n\n complex:: BETAFACT\n real, parameter:: EOVERAMU = 9.64853e7\n real, parameter:: WP2FACT=1.745915\n real, parameter:: MPC2=938271998.38\n real, parameter:: C=2.99792458e8\n real, parameter:: PI=3.141592653597932384\n real, dimension(NUPER):: JN0XI1,JNP1XI1,JNM1XI1\n real, dimension(NUPER):: JN0XI2,JNP1XI2,JNM1XI2\n real, dimension(NUPER,3,3):: SSGG\n real, dimension(NUPAR,3,3):: SGG\n\n real ga_33(nupar)\n real, dimension(NUPAR,-1:NBESSJ-2) :: sgg_31\n real, dimension(NUPAR,-1:NBESSJ-2) :: sgg_11\n\n real, dimension(NUPAR) :: sgg_31_last, sgg_21p\n real, dimension(3,3):: THETARE,THETAIM\n real:: W2,WP2,WPFACT,WCW,RRP,RRM,RR,IRR, du_3, g_33, g_33j\n real:: MUT0,SQMUT0,BETA1,BETA2,KPARA1,NPARA1\n real:: ISQ2,CUPAR,CUPER,NWCW,DFACTPAR,DFACTPER,LF0,LNF0UPER\n real:: DFACTPERI\n real:: UPAR0,SFACT0,SFACTP1,SFACTM1, factor, kperp2, vperp_norm2\n real:: ssgg_11,ssgg_22,ssgg_31,ssgg_33,ssgg_32,ssgg_21,du, temp\n integer:: NHARM,IHARM,NJ,NJP1,NJM1,J,K,M,N\n\n logical, parameter :: use_original = .false.\n logical, parameter :: use_gemm = .false.\n real, dimension(nupar) :: irr_j, rr_j\n\n integer :: kdim, jdim \n real, dimension(nuper,nupar) :: LF0kj\n real :: ssgg_11a,ssgg_33a, ssgg_31a\n real :: maxabserr, maxrelerr\n real :: abserr_11, abserr_33, abserr_31\n real :: relerr_11, relerr_33, relerr_31\n\n real, dimension(:,:), pointer :: JN0N0,JN0N0U,JN0N1U\n real, dimension(:,:), pointer :: LF0JN0N0, LF0JN0N0U, LF0JN0N1U\n real, dimension(nupar,3*nbessj-1), target :: Jmat\n real, dimension(nuper,3*nbessj-1), target :: Kmat\n\n integer :: mm,nn,kk,ld1,ld2,ld3\n real :: alpha,beta\n\n integer :: mn\n integer, dimension(6) :: mlist,nlist\n real, dimension(3,3) :: sumsgg_even, sumsgg_odd\n real :: sum_even, sum_odd, JNP1XI1_K, JN0XI1_K\n!dir$ ssp_private CAUCHY_PPART2\n\n jdim = nupar\n kdim = nuper\n\n\n \n mn = 1\n do m=1,3\n do n=1,m\n mlist(mn) = m\n nlist(mn) = n\n mn = mn+1\n enddo\n enddo\n \n \n\n IFAIL=0\n WSPEC(1:3,1:3) = cmplx(0.,0.)\n W2=W*W\n WP2=DENS*ZSPEC**2*WP2FACT/ASPEC\n WPFACT=WP2/W2\n WCW=BMAG*ZSPEC*EOVERAMU/ASPEC/W\n BETA1=ATAN2(K1(2),K1(1))\n BETA2=ATAN2(K2(2),K2(1))\n KPARA1=K1(3)\n NPARA1=KPARA1*C/W\n MUT0=0.5*MPC2*ASPEC/ENORM\n SQMUT0=SQRT(MUT0)\n DFACTPER = NPARA1 / SQMUT0\n DFACTPERI = 1.0 / DFACTPER\n ISQ2=SQRT(0.5)\n NHARM=NBESSJ-2\n kperp2 = k1(1)*k1(1)+ k1(2)*k1(2)\n vperp_norm2 = mut0*wcw*wcw*w2/c/c/kperp2 ! need to fix kperp = 0\n\n\n\n\n! -------------------------------------------------------\n! do extra integral (STIX) to convert all elements to \"U\"\n! do perpendicular integral by inline trapezoidal rule\n! and parallel integral by simpson's rule\n! -------------------------------------------------------\n if (use_original) then\n\n do J = 1, NUPAR\n\t g_33j = 0.0\n\n do K = 2, NUPER - 1\n g_33j = g_33j + &\n & UPAR(J)*(UPER(K)*DFDUPAR(K,J)-UPAR(J)*DFDUPER(K,J))\n end do\n\n\n\t k = 1\n g_33j = g_33j + &\n & 0.5 * UPAR(J)*(UPER(K)*DFDUPAR(K,J)-UPAR(J)*DFDUPER(K,J))\n\n\n\t k = nuper\n g_33j = g_33j + &\n & 0.5 * UPAR(J)*(UPER(K)*DFDUPAR(K,J)-UPAR(J)*DFDUPER(K,J))\n\n\t\n\t du = (uper(nuper) - uper(1))/(nuper - 1)\n\t ga_33(j) = g_33j * du\n\n end do\n\n g_33 = 0.0\n\n! the uperp integral is done; now do parallel integral by simpson's rule\n\n call EQSIMPSON1D_2(NUPAR, UPAR, ga_33, g_33)\n\n\n do j = 1, nupar\n do k = 1 , nuper\n\t DFDTH(k,j) = upar(j) * DFDUPER(k,j) - uper(k) * DFDUPAR(k,j)\n end do\n end do\n\n \n\n else\n do j = 1, nupar\n do k = 1 , nuper\n\t DFDTH(k,j) = upar(j) * DFDUPER(k,j) - uper(k) * DFDUPAR(k,j)\n end do\n end do\n\n \n\n du = (uper(nuper) - uper(1))/(nuper - 1)\n do J = 1, NUPAR\n\n g_33j = 0.0\n do K = 2, NUPER - 1\n g_33j = g_33j + DFDTH(k,j)\n end do\n k = 1\n g_33j = g_33j + 0.5d0*DFDTH(k,j)\n k = nuper\n g_33j = g_33j + 0.5d0*DFDTH(k,j)\n\n g_33j = upar(j)*(-g_33j)\n\n ga_33(j) = g_33j * du\n\n enddo\n\n \n g_33 = 0.0\n\n! the uperp integral is done; now do parallel integral by simpson's rule\n\n call EQSIMPSON1D_2(NUPAR, UPAR, ga_33, g_33)\n\n\n\n endif\n\n\n if (.not.use_original) then\n\n\n JN0N0 => Kmat(1:kdim,1:nbessj)\n JN0N0U => Kmat(1:kdim,(nbessj+1):(2*nbessj) )\n JN0N1U => Kmat(1:kdim,(2*nbessj+1):(2*nbessj+nbessj-1) )\n\n LF0JN0N0 => Jmat(1:jdim,1:nbessj)\n LF0JN0N0U => Jmat(1:jdim,(nbessj+1):(2*nbessj) )\n LF0JN0N1U => Jmat(1:jdim,(2*nbessj+1):(2*nbessj+nbessj-1) )\n\n do j=1,jdim\n do k=1,kdim\n LF0kj(k,j) = DFDUPER(K,J) - DFACTPER * dfdth(k,j)\n enddo\n enddo\n\n! -------------------------------\n! precompute LF0kj(k,j) * vectors\n! -------------------------------\n do nj=1,nbessj\n do k=1,kdim\n JN0N0(k,nj) = JNXI1(k,nj)**2\n JN0N0U(k,nj) = (JNXI1(k,nj) * UPER(k))**2\n enddo\n enddo\n do nj=1,nbessj-1\n do k=1,kdim\n JN0N1U(k,nj) = JNXI1(k,nj)*JNXI1(k,nj+1)*UPER(k)\n enddo\n enddo\n\n!\t-----------------------------\n!\tone big happy matrix multiply\n!\t-----------------------------\n if (use_gemm) then\n\n mm = jdim\n nn = 3*nbessj-1\n kk = (kdim-1) - 2 + 1\n ld1 = size(LF0kj,1)\n ld2 = size(Kmat,1)\n ld3 = size(Jmat,1)\n alpha = 1.0\n beta = 0.0\n call dgemm( 'T', 'N', mm,nn,kk, &\n alpha, LF0kj(2,1), ld1, Kmat(2,1),ld2, &\n beta, Jmat(1,1), ld3 )\n\n else\n\n! LF0JN0N0(1:jdim,1:nbessj) = matmul( &\n! transpose(LF0kj(2:(kdim-1),1:jdim)), & \n! \t\t\tJN0N0(2:(kdim-1),1:nbessj) )\n! LF0JN0N0U(1:jdim,1:nbessj) = matmul( &\n! transpose(LF0kj(2:(kdim-1),1:jdim)), &\n! JN0N0U(2:(kdim-1),1:nbessj) )\n! LF0JN0N1U(1:jdim,1:(nbessj-1)) = matmul( &\n! transpose(LF0kj(2:(kdim-1),1:jdim)), &\n! JN0N1U(2:(kdim-1),1:(nbessj-1)) )\n\n Jmat(1:jdim,1:(3*nbessj-1)) = matmul( &\n transpose( LF0kj(2:(kdim-1), 1:jdim)), &\n Kmat(2:(kdim-1),1:(3*nbessj-1)) )\n\n endif\n \n endif\n \n\n\n maxabserr = 0.0\n maxrelerr = 0.0\n\n\n! -------------------\n! Loop over harmonics\n! -------------------\n\n do IHARM = -1, NHARM\n\n\n NWCW=real(IHARM)*WCW !L*omega_cyc\n\n BETAFACT=exp(cmplx(0.,IHARM*(BETA1-BETA2)))\n NJ=ABS(IHARM)+1\n NJP1=ABS(IHARM+1)+1\n NJM1=ABS(IHARM-1)+1\n SFACT0=real(sign(1,IHARM))**ABS(IHARM)\n SFACTP1=real(sign(1,IHARM+1))**ABS(IHARM+1)\n SFACTM1=real(sign(1,IHARM-1))**ABS(IHARM-1)\n\n\n if (use_original) then\n JN0XI1(1:NUPER)=SFACT0*JNXI1(1:NUPER,NJ)\n JNP1XI1(1:NUPER)=SFACTP1*JNXI1(1:NUPER,NJP1)\n JNM1XI1(1:NUPER)=SFACTM1*JNXI1(1:NUPER,NJM1)\n endif\n\n ! -- Build array with integrand -- !\n\n\n\t\n do J=1,NUPAR\n\t\n ssgg_11 = 0.0\n ssgg_31 = 0.0\n ssgg_33 = 0.0\n\n if (use_original) then\n\n do K = 2, NUPER - 1\n\t\n LF0 = DFDUPER(K,J) - DFACTPER * dfdth(k,j)\n ssgg_33 = ssgg_33 + JN0XI1(K)**2 *LF0\n\t\t\n LF0 = UPER(K) * JNP1XI1(K) * LF0\n ssgg_11 = ssgg_11 + UPER(K) * JNP1XI1(K)* LF0\n ssgg_31 = ssgg_31 + UPAR(J) * JN0XI1(K) * LF0\n end do\n\n else\n! --------------------------------------------\n! sums already computed in the matrix multiply\n! --------------------------------------------\n\n ssgg_33a = LF0JN0N0(j,nj) * (sfact0**2) \n ssgg_11a = LF0JN0N0U(j,njp1) * (sfactp1**2) \n\n! -------------------------------------\n! note it is possible for njp1 .lt. nj \n! -------------------------------------\n ssgg_31a = LF0JN0N1U(j,min(nj,njp1)) * (sfact0*sfactp1) * upar(j)\n\n ssgg_33 = ssgg_33a\n ssgg_11 = ssgg_11a\n ssgg_31 = ssgg_31a\n\n endif\n\n!\n\n\t\n ssgg_11 = ssgg_11 * 0.5\n\t ssgg_31 = ssgg_31 * ISQ2\n\t\n\t\n if (use_original) then\n\t k = 1\n\n LF0 = DFDUPER(K,J) - DFACTPER * dfdth(k,j)\n ssgg_33 = ssgg_33 + 0.5 * JN0XI1(K)**2 *LF0\n\t\n LF0 = UPER(K) * JNP1XI1(K) * LF0\n ssgg_11 = ssgg_11 + 0.25 * UPER(K) * JNP1XI1(K)* LF0\n ssgg_31 = ssgg_31 + 0.5 * ISQ2 * UPAR(J) * JN0XI1(K) * LF0\n\n\n\t k = nuper\n\t\n\t LF0 = DFDUPER(K,J) - DFACTPER * dfdth(k,j)\n\t ssgg_33 = ssgg_33 + 0.5 * LF0 * JN0XI1(K)**2\n\t\n\t LF0 = UPER(K) * JNP1XI1(K) * LF0\n\t ssgg_11 = ssgg_11 + 0.25 * UPER(K) * JNP1XI1(K)* LF0\n ssgg_31 = ssgg_31 + 0.5 * ISQ2 * UPAR(J) * JN0XI1(K) * LF0\n\n\n else\n! ---------------------------------------------------\n! no need to form vectors for JN0XI1(:) or JNP1XI1(:)\n! ---------------------------------------------------\n\n k = 1\n\n LF0 = LF0kj(k,j)\n JN0XI1_K = (sfact0*JNXI1(k,nj))\n ssgg_33 = ssgg_33 + 0.5 * JN0XI1_K**2 *LF0\n\n JNP1XI1_k = (sfactp1*JNXI1(k,njp1))\n LF0 = UPER(K) * JNP1XI1_K * LF0\n ssgg_11 = ssgg_11 + 0.25 * UPER(K) * JNP1XI1_K * LF0\n ssgg_31 = ssgg_31 + 0.5 * ISQ2 * UPAR(J) * JN0XI1_K * LF0\n\n\n k = nuper\n\n LF0 = LF0kj(k,j)\n JN0XI1_K = (sfact0*JNXI1(k,nj))\n ssgg_33 = ssgg_33 + 0.5 * LF0 * JN0XI1_K**2\n\n JNP1XI1_K = (sfactp1 * JNXI1(k,njp1))\n LF0 = UPER(K) * JNP1XI1_K * LF0\n ssgg_11 = ssgg_11 + 0.25 * UPER(K) * JNP1XI1_K * LF0\n ssgg_31 = ssgg_31 + 0.5 * ISQ2 * UPAR(J) * JN0XI1_K * LF0\n\n\n\n endif\n\n ! end of the kperp loop\n\n\n\t\n\t du = (uper(nuper) - uper(1))/(nuper - 1)\n\t sgg_11(j,iharm) = ssgg_11 * du\n\t sgg_21p(j) = ssgg_33 * du ! this is a piece of 21\n\t sgg_31(j,iharm) =\tssgg_31 * du\n\t SGG(j,3,3) =\tUPAR(J)**2 * sgg_21p(j)\n\n end do\n\n\n\n! the perp integrals have been calculated now do\n! parallel, but reuse them for negative harmonics\n\n if(iharm .eq. -1) cycle\n\t\n du_3 = (UPAR(NUPAR)-UPAR(1))/real(nupar-1)/3.\t\n\t SGG(1:nupar,1,1) = sgg_11(1:nupar,iharm)\n\t\n\t ! do the 31--32, 21, 22 compression\n\t\n\t select case(iharm)\n\t case(0)\n SGG(1:nupar,2,2) = sgg_11(1:nupar,iharm) ! no -2 for 0 but they are the same\n\t SGG(1:nupar,2,1) = - SGG(1:nupar,2,2) ! 12--21 are anti symmetric\n\t case default\n\t SGG(1:nupar,2,2) = sgg_11(1:nupar,iharm-2)! look two back for 22\n SGG(1:nupar,2,1) = -0.5*(SGG(1:nupar,1,1)+ SGG(1:nupar,2,2))&\n\t &+ vperp_norm2*iharm*iharm*(sgg_21p(1:nupar)) ! use bessel function identity for 21\n\t end select\n\n\t SGG(1:nupar,3,2) = sgg_31(1:nupar,iharm-1)\n\t SGG(1:nupar,3,1) = sgg_31(1:nupar,iharm)\n\t\n\t \t\n ! -- Resonance relation -- !\n\n RRP=1. - NWCW - DFACTPER * UPARMAX\n RRM=1. - NWCW - DFACTPER * UPARMIN\n\t\n\t\n\n if (RRP*RRM.GT.0) then\n ! -- No resonance here -- !\n\t\n if (use_original) then\n do J=1,NUPAR\n RR = 1.- NWCW - DFACTPER * UPAR(J)\n IRR = 1. / RR\n do M=1,3\n do N=1,M\n SGG(J,M,N) = SGG(J,M,N) * IRR\n end do\n end do\n end do\n\n else\n do J=1,NUPAR\n RR = 1.- NWCW - DFACTPER * UPAR(J)\n IRR = 1. / RR\n rr_j(j) = rr\n irr_j(j) = irr\n enddo\n\n\n!dir$ concurrent\n do mn=1,6\n m = mlist(mn)\n n = nlist(mn)\n\n do j=1,nupar\n IRR = irr_j(j)\n\t SGG(J,M,N) = SGG(J,M,N) * IRR\n enddo\n\n end do\n\n endif\n\t\n\n !-- Hermitian part of $\\Theta/(2\\pi)$ --!\n\t\n if (use_original) then\n\t THETARE(1,1) = (sgg(1,1,1)+sgg(nupar,1,1)+2.*sum(sgg(2:nupar-1,1,1)) +&\n\t & 2.*sum(sgg(2:nupar-1:2,1,1)))*du_3\n\t THETARE(2,1) = (SGG(1,2,1)+SGG(nupar,2,1)+2.*sum(SGG(2:nupar-1,2,1)) +&\n\t & 2.*sum(SGG(2:nupar-1:2,2,1)))*du_3\n\t THETARE(3,1) = (sgg(1,3,1)+sgg(nupar,3,1)+2.*sum(sgg(2:nupar-1,3,1)) +&\n\t & 2.*sum(sgg(2:nupar-1:2,3,1)))*du_3\n\t THETARE(2,2) = (sgg(1,2,2)+sgg(nupar,2,2)+2.*sum(sgg(2:nupar-1,2,2)) +&\n\t & 2.*sum(sgg(2:nupar-1:2,2,2)))*du_3\n THETARE(3,2) = (sgg(1,3,2)+sgg(nupar,3,2)+2.*sum(sgg(2:nupar-1,3,2)) +&\n\t & 2.*sum(sgg(2:nupar-1:2,3,2)))*du_3\n\t THETARE(3,3) = (sgg(1,3,3)+sgg(nupar,3,3)+2.*sum(sgg(2:nupar-1,3,3)) +&\n\t & 2.*sum(sgg(2:nupar-1:2,3,3)))*du_3\n else\n\n!dir$ concurrent,preferstream,novector\n do mn=1,6\n m = mlist(mn)\n n = nlist(mn)\n!dir$ vector \n sum_even = sum(sgg(2:(nupar-1):2,m,n))\n sum_odd = sum(sgg(3:(nupar-1):2,m,n))\n \n thetare(m,n) = (sgg(1,m,n) + sgg(nupar,m,n) + &\n 2.0d0*(sum_odd + sum_even) + 2.0d0*sum_even ) * du_3\n enddo\n endif\n\t\n\t\n if (use_original) then\n\t do J=1,NUPAR ! restore sgg\n\t RR = 1.- NWCW - DFACTPER * UPAR(J)\n\t\n do M=1,3\n do N=1,M\n SGG(J,M,N) = SGG(J,M,N) * RR\n end do\n end do\n\t\n end do\n else\n\n!dir$ concurrent\n do mn=1,6\n m = mlist(mn)\n n = nlist(mn)\n\n do j=1,nupar\n SGG(J,M,N) = SGG(J,M,N) * rr_j(j)\n enddo\n end do\n\n endif\n\t\n \t THETARE(1,2) = THETARE(2,1)\n THETARE(1,3) = THETARE(3,1)\n THETARE(2,3) = THETARE(3,2)\n\n !-- Anti-hermitian part of $\\Theta/(2\\pi)$ --!\n THETAIM(1:3,1:3)=0.\n\n else\n\n ! -- There is a resonance all right -- !\n ! -- 1. Hermitian part -- !\n UPAR0 = (1. - NWCW) * DFACTPERI\n\t\n if (use_original) then\n call CAUCHY_PPART2(UPAR,NUPAR,UPAR0,SGG(1,1,1),THETARE(1,1))\n call CAUCHY_PPART2(UPAR,NUPAR,UPAR0,SGG(1,2,1),THETARE(2,1))\n call CAUCHY_PPART2(UPAR,NUPAR,UPAR0,SGG(1,3,1),THETARE(3,1))\n call CAUCHY_PPART2(UPAR,NUPAR,UPAR0,SGG(1,2,2),THETARE(2,2))\n call CAUCHY_PPART2(UPAR,NUPAR,UPAR0,SGG(1,3,2),THETARE(3,2))\n call CAUCHY_PPART2(UPAR,NUPAR,UPAR0,SGG(1,3,3),THETARE(3,3))\n else\n!dir$ concurrent\n do mn=1,6\n m = mlist(mn)\n n = nlist(mn)\n call CAUCHY_PPART2(UPAR,NUPAR,UPAR0,SGG(1,m,n),THETARE(m,n))\n enddo\n endif\n \n\n THETARE(1,2) = THETARE(2,1)\n THETARE(1,3) = THETARE(3,1)\n THETARE(2,3) = THETARE(3,2)\n\n ! -- 2. Anti-hermitian part -- !\n call WINTERP1D_2(UPAR,NUPAR,SGG(1,1,1),UPAR0,THETAIM(1,1))\n call WINTERP1D_2(UPAR,NUPAR,SGG(1,2,1),UPAR0,THETAIM(2,1))\n call WINTERP1D_2(UPAR,NUPAR,SGG(1,3,1),UPAR0,THETAIM(3,1))\n call WINTERP1D_2(UPAR,NUPAR,SGG(1,2,2),UPAR0,THETAIM(2,2))\n call WINTERP1D_2(UPAR,NUPAR,SGG(1,3,2),UPAR0,THETAIM(3,2))\n call WINTERP1D_2(UPAR,NUPAR,SGG(1,3,3),UPAR0,THETAIM(3,3))\n\n THETAIM(1,2) = THETAIM(2,1)\n THETAIM(1,3) = THETAIM(3,1)\n THETAIM(2,3) = THETAIM(3,2)\n\t\n\n do M=1,3\n do N=1,3\n THETARE(M,N) = -THETARE(M,N) * DFACTPERI\n THETAIM(M,N) = -PI * THETAIM(M,N) * abs(DFACTPERI)\n end do\n end do\n\n end if\n\n do N=1,3\n do M=1,3\n WSPEC(M,N)=WSPEC(M,N)+2.*PI*WPFACT*BETAFACT*cmplx(THETARE(M,N),THETAIM(M,N))\n end do\n end do\n\n\t if(iharm .ne. 0) then ! skip the negative for zero\n\n\t nwcw = - nwcw\n\n \t ! -- Resonance relation -- !\n\t\n\t\n RRP = 1. - NWCW - DFACTPER * UPARMAX\n RRM = 1. - NWCW - DFACTPER * UPARMIN\n\t\n if (RRP*RRM.GT.0) then\n \t ! -- No resonance here -- !\n\t\n if (use_original) then\n \t do J=1,NUPAR\n\n RR = 1. - NWCW - DFACTPER * UPAR(J)\n IRR = 1. / RR\n do M=1,3\n do N = 1,M\n SGG(J,M,N) = SGG(J,M,N) * IRR\n end do\n end do\n \t end do\n else\n do J=1,NUPAR\n RR = 1.- NWCW - DFACTPER * UPAR(J)\n IRR = 1. / RR\n rr_j(j) = rr\n irr_j(j) = irr\n enddo\n\n do mn=1,6\n m = mlist(mn)\n n = nlist(mn)\n do j=1,nupar\n IRR = irr_j(j)\n SGG(J,M,N) = SGG(J,M,N) * IRR\n enddo\n end do\n\n endif\n\t\t\n !-- Hermitian part of $\\Theta/(2\\pi)$ --!\n\n if (use_original) then\n\t THETARE(1,1) = (sgg(1,1,1)+sgg(nupar,1,1)+2.*sum(sgg(2:nupar-1,1,1)) +&\n\t & 2.*sum(sgg(2:nupar-1:2,1,1)))*du_3\n\t THETARE(2,1) = (SGG(1,2,1)+SGG(nupar,2,1)+2.*sum(SGG(2:nupar-1,2,1)) +&\n\t & 2.*sum(SGG(2:nupar-1:2,2,1)))*du_3\n\t THETARE(3,1) = (sgg(1,3,1)+sgg(nupar,3,1)+2.*sum(sgg(2:nupar-1,3,1)) +&\n\t & 2.*sum(sgg(2:nupar-1:2,3,1)))*du_3\n\t THETARE(2,2) = (sgg(1,2,2)+sgg(nupar,2,2)+2.*sum(sgg(2:nupar-1,2,2)) +&\n\t & 2.*sum(sgg(2:nupar-1:2,2,2)))*du_3\n THETARE(3,2) = (sgg(1,3,2)+sgg(nupar,3,2)+2.*sum(sgg(2:nupar-1,3,2)) +&\n\t & 2.*sum(sgg(2:nupar-1:2,3,2)))*du_3\n\t THETARE(3,3) = (sgg(1,3,3)+sgg(nupar,3,3)+2.*sum(sgg(2:nupar-1,3,3)) +&\n\t & 2.*sum(sgg(2:nupar-1:2,3,3)))*du_3\n else\n!dir$ concurrent,preferstream,novector\n\n do mn=1,6\n!dir$ vector\n m = mlist(mn)\n n = nlist(mn)\n \n sum_even = sum(sgg(2:(nupar-1):2,m,n))\n sum_odd = sum(sgg(3:(nupar-1):2,m,n))\n\n thetare(m,n) = (sgg(1,m,n)+sgg(nupar,m,n) + &\n 2.0d0*(sum_even + sum_odd) + 2.0d0*sum_even) * du_3\n enddo\n endif\n\t\n \n\n\n\t\t\n if (use_original) then\n do J=1,NUPAR ! restore sgg\n RR=1.- NWCW - DFACTPER * UPAR(J)\n\t do M=1,3\n do N=1,M\n SGG(J,M,N) = SGG(J,M,N) * RR\n \tend do\n end do\n \t end do\n else\n\n!dir$ concurrent\n do mn=1,6\n m = mlist(mn)\n n = nlist(mn)\n\n do j=1,nupar\n SGG(J,M,N) = SGG(J,M,N) * rr_j(j)\n enddo\n\n end do\n endif\n\n\t temp = THETARE(3,2)\n\t THETARE(3,2) = -THETARE(3,1)\n\t THETARE(3,1) = -temp\n\t\t\n\t temp = THETARE(1,1)\n\t THETARE(1,1) = THETARE(2,2)\n\t THETARE(2,2) = temp\n\n \t THETARE(1,2) = THETARE(2,1)\n \t THETARE(1,3) = THETARE(3,1)\n \t THETARE(2,3) = THETARE(3,2)\n\n \t !-- Anti-hermitian part of $\\Theta/(2\\pi)$ --!\n \t THETAIM(1:3,1:3)=0.\n\n else\n\n \t ! -- There is a resonance all right -- !\n \t ! -- 1. Hermitian part -- !\n\t\n\t\n \t UPAR0 = DFACTPERI * (1. - NWCW)\n\n if (use_original) then\n \t call CAUCHY_PPART2(UPAR,NUPAR,UPAR0,SGG(1,1,1),THETARE(1,1))\n \t call CAUCHY_PPART2(UPAR,NUPAR,UPAR0,SGG(1,2,1),THETARE(2,1))\n \t call CAUCHY_PPART2(UPAR,NUPAR,UPAR0,SGG(1,3,1),THETARE(3,1))\n \t call CAUCHY_PPART2(UPAR,NUPAR,UPAR0,SGG(1,2,2),THETARE(2,2))\n \t call CAUCHY_PPART2(UPAR,NUPAR,UPAR0,SGG(1,3,2),THETARE(3,2))\n \t call CAUCHY_PPART2(UPAR,NUPAR,UPAR0,SGG(1,3,3),THETARE(3,3))\n else\n\n!dir$ concurrent\n do mn=1,6\n m = mlist(mn)\n n = nlist(mn)\n \t call CAUCHY_PPART2(UPAR,NUPAR,UPAR0,SGG(1,m,n),THETARE(m,n))\n enddo\n endif\n\n\n\t\t temp = THETARE(3,2)\n\t\t THETARE(3,2) = -THETARE(3,1)\n\t\t THETARE(3,1) = -temp\n\t\t temp = THETARE(1,1)\n\t\t THETARE(1,1) = THETARE(2,2)\n\t\t THETARE(2,2) = temp\n\t\t\n \t THETARE(1,2) = THETARE(2,1)\n \t THETARE(1,3) = THETARE(3,1)\n \t THETARE(2,3) = THETARE(3,2)\n\n \t ! -- 2. Anti-hermitian part -- !\n \t call WINTERP1D_2(UPAR,NUPAR,SGG(1,1,1),UPAR0,THETAIM(1,1))\n \t call WINTERP1D_2(UPAR,NUPAR,SGG(1,2,1),UPAR0,THETAIM(2,1))\n \t call WINTERP1D_2(UPAR,NUPAR,SGG(1,3,1),UPAR0,THETAIM(3,1))\n \t call WINTERP1D_2(UPAR,NUPAR,SGG(1,2,2),UPAR0,THETAIM(2,2))\n \t call WINTERP1D_2(UPAR,NUPAR,SGG(1,3,2),UPAR0,THETAIM(3,2))\n \t call WINTERP1D_2(UPAR,NUPAR,SGG(1,3,3),UPAR0,THETAIM(3,3))\n\n\t temp = THETAIM(3,2)\n\t THETAIM(3,2) = -THETAIM(3,1)\n\t THETAIM(3,1) = -temp\n\t temp = THETAIM(1,1)\n\t THETAIM(1,1) = THETAIM(2,2)\n\t THETAIM(2,2) = temp\n\t\t\n \t THETAIM(1,2) = THETAIM(2,1)\n \t THETAIM(1,3) = THETAIM(3,1)\n \t THETAIM(2,3) = THETAIM(3,2)\n\n do M=1,3\n do N=1,3\n THETARE(M,N) = -THETARE(M,N) * DFACTPERI\n THETAIM(M,N) = -PI * THETAIM(M,N) * abs(DFACTPERI)\n end do\n \t end do\n\t\t\n\n end if !resonance exists\n\t\n\t do N=1,3\n \t do M=1,3\n WSPEC(M,N)=WSPEC(M,N)+ &\n 2.0d0*PI*WPFACT*BETAFACT*cmplx(THETARE(M,N),THETAIM(M,N))\n \t end do\n end do\n\n\t end if ! zero skip if\n end do !harmonic sum\n\n ! add in extra term in sig33 from the w to u conversion\n\n WSPEC(3,3)=WSPEC(3,3)+2.*PI*WPFACT*BETAFACT*cmplx(g_33,0.0)\n\n call WROTATE_AORSA(BETA1,BETA2,WSPEC)\n\n end subroutine GETNONMAXSIGMA_AORSA_NEW\n\n\n\n\n\n\n!\n!*************************************************************************\n!\n\n subroutine GETNONMAXSWMAT_AORSA_NEW(W,ZSPEC,ASPEC,DENS,BMAG, &\n & K1,XI1,JNXI1,K2,XI2,JNXI2,NBESSJ,ENORM,UPARMIN,UPARMAX, &\n & NUPAR,NUPER,UPER,UPAR,DFDUPER,DFDUPAR,WSPEC,IFAIL)\n implicit none\n real, intent(IN):: W,ZSPEC,ASPEC,DENS,BMAG\n real, dimension(3):: K1,K2\n integer, intent(IN):: NUPAR,NUPER,NBESSJ\n real, dimension(NUPER), intent(IN):: XI1,XI2\n real, dimension(NUPER, NBESSJ), intent(IN):: JNXI1,JNXI2\n real, intent(IN):: ENORM,UPARMIN,UPARMAX\n real, dimension(NUPER), intent(IN):: UPER\n real, dimension(NUPAR), intent(IN):: UPAR\n real, dimension(NUPER,NUPAR), intent(IN):: DFDUPER,DFDUPAR\n complex, dimension(3,3), intent(OUT):: WSPEC\n integer, intent(OUT):: IFAIL\n\n complex:: BETAFACT\n real, parameter:: EOVERAMU = 9.64853e7\n real, parameter:: WP2FACT=1.745915\n real, parameter:: MPC2=938271998.38\n real, parameter:: C=2.99792458e8\n real, parameter:: PI=3.141592653597932384\n real, dimension(NUPER):: JN0XI1,JNP1XI1,JNM1XI1\n real, dimension(NUPER):: JN0XI2,JNP1XI2,JNM1XI2\n real, dimension(NUPER,3,3):: SSGG\n real, dimension(NUPAR,3,3):: SGG\n real, dimension(3,3):: THETARE,THETAIM\n real:: W2,WP2,WPFACT,WCW,RRP,RRM,RR,IRR\n real:: MUT0,SQMUT0,BETA1,BETA2,KPARA1,NPARA1\n real:: ISQ2,CUPAR,CUPER,NWCW,DFACTPAR,DFACTPER,LF0,LNF0UPER\n real:: UPAR0,SFACT0,SFACTP1,SFACTM1\n integer:: NHARM,IHARM,NJ,NJP1,NJM1,J,K,M,N\n\n IFAIL=0\n WSPEC(1:3,1:3) = cmplx(0.,0.)\n W2=W*W\n WP2=DENS*ZSPEC**2*WP2FACT/ASPEC\n WPFACT=WP2/W2\n WCW=BMAG*ZSPEC*EOVERAMU/ASPEC/W\n BETA1=ATAN2(K1(2),K1(1))\n BETA2=ATAN2(K2(2),K2(1))\n KPARA1=K1(3)\n NPARA1=KPARA1*C/W\n MUT0=0.5*MPC2*ASPEC/ENORM\n SQMUT0=SQRT(MUT0)\n ISQ2=SQRT(0.5)\n NHARM=NBESSJ-2\n\n ! -- Loop over harmonics -- !\n do IHARM=-NHARM,NHARM\n NWCW=real(IHARM)*WCW\n\n BETAFACT=exp(cmplx(0.,IHARM*(BETA1-BETA2)))\n NJ=ABS(IHARM)+1\n NJP1=ABS(IHARM+1)+1\n NJM1=ABS(IHARM-1)+1\n SFACT0=real(sign(1,IHARM))**ABS(IHARM)\n SFACTP1=real(sign(1,IHARM+1))**ABS(IHARM+1)\n SFACTM1=real(sign(1,IHARM-1))**ABS(IHARM-1)\n JN0XI1(1:NUPER)=SFACT0*JNXI1(1:NUPER,NJ)\n JNP1XI1(1:NUPER)=SFACTP1*JNXI1(1:NUPER,NJP1)\n JNM1XI1(1:NUPER)=SFACTM1*JNXI1(1:NUPER,NJM1)\n JN0XI2(1:NUPER)=SFACT0*JNXI2(1:NUPER,NJ)\n JNP1XI2(1:NUPER)=SFACTP1*JNXI2(1:NUPER,NJP1)\n JNM1XI2(1:NUPER)=SFACTM1*JNXI2(1:NUPER,NJM1)\n\n ! -- Build array with integrand -- !\n do J=1,NUPAR\n CUPAR=UPAR(J)\n DFACTPAR=NPARA1*CUPAR/SQMUT0\n do K=1,NUPER\n CUPER=UPER(K)\n DFACTPER=NPARA1*CUPER/SQMUT0\n LF0=(1.-DFACTPAR)*DFDUPER(K,J)+DFACTPER*DFDUPAR(K,J)\n LNF0UPER=NWCW*DFDUPER(K,J)*CUPAR+(1.-NWCW)*DFDUPAR(K,J)*CUPER\n SSGG(K,1,1)=0.5*CUPER*LF0*JNP1XI1(K)*JNP1XI2(K)*CUPER\n SSGG(K,2,1)=0.5*CUPER*LF0*JNP1XI1(K)*JNM1XI2(K)*CUPER\n SSGG(K,3,1)=ISQ2*CUPAR*LF0*JNP1XI1(K)*JN0XI2(K)*CUPER\n SSGG(K,1,2)=0.5*CUPER*LF0*JNM1XI1(K)*JNP1XI2(K)*CUPER\n SSGG(K,2,2)=0.5*CUPER*LF0*JNM1XI1(K)*JNM1XI2(K)*CUPER\n SSGG(K,3,2)=ISQ2*CUPAR*LF0*JNM1XI1(K)*JN0XI2(K)*CUPER\n SSGG(K,1,3)=ISQ2*CUPER*LNF0UPER*JN0XI1(K)*JNP1XI2(K)\n SSGG(K,2,3)=ISQ2*CUPER*LNF0UPER*JN0XI1(K)*JNM1XI2(K)\n SSGG(K,3,3)=CUPAR*LNF0UPER*JN0XI1(K)*JN0XI2(K)\n end do\n\n ! -- Integrate of $u_\\perp$ -- !\n call EQSIMPSON1D(NUPER,UPER,SSGG(1,1,1),SGG(J,1,1))\n call EQSIMPSON1D(NUPER,UPER,SSGG(1,2,1),SGG(J,2,1))\n call EQSIMPSON1D(NUPER,UPER,SSGG(1,3,1),SGG(J,3,1))\n call EQSIMPSON1D(NUPER,UPER,SSGG(1,1,2),SGG(J,1,2))\n call EQSIMPSON1D(NUPER,UPER,SSGG(1,2,2),SGG(J,2,2))\n call EQSIMPSON1D(NUPER,UPER,SSGG(1,3,2),SGG(J,3,2))\n call EQSIMPSON1D(NUPER,UPER,SSGG(1,1,3),SGG(J,1,3))\n call EQSIMPSON1D(NUPER,UPER,SSGG(1,2,3),SGG(J,2,3))\n call EQSIMPSON1D(NUPER,UPER,SSGG(1,3,3),SGG(J,3,3))\n\n end do\n\n ! -- Resonance relation -- !\n RRP=1.-NWCW-NPARA1*UPARMAX/SQMUT0\n RRM=1.-NWCW-NPARA1*UPARMIN/SQMUT0\n\n if (RRP*RRM.GT.0) then\n ! -- No resonance here -- !\n do J=1,NUPAR\n CUPAR=UPAR(J)\n DFACTPAR=NPARA1*CUPAR/SQMUT0\n RR=1.-NWCW-DFACTPAR\n IRR=1./RR\n do N=1,3\n do M=1,3\n SGG(J,M,N)=SGG(J,M,N)*IRR\n end do\n end do\n end do\n\n !-- Hermitian part of $\\Theta/(2\\pi)$ --!\n call EQSIMPSON1D(NUPAR,UPAR,SGG(1,1,1),THETARE(1,1))\n call EQSIMPSON1D(NUPAR,UPAR,SGG(1,2,1),THETARE(2,1))\n call EQSIMPSON1D(NUPAR,UPAR,SGG(1,3,1),THETARE(3,1))\n call EQSIMPSON1D(NUPAR,UPAR,SGG(1,1,2),THETARE(1,2))\n call EQSIMPSON1D(NUPAR,UPAR,SGG(1,2,2),THETARE(2,2))\n call EQSIMPSON1D(NUPAR,UPAR,SGG(1,3,2),THETARE(3,2))\n call EQSIMPSON1D(NUPAR,UPAR,SGG(1,1,3),THETARE(1,3))\n call EQSIMPSON1D(NUPAR,UPAR,SGG(1,2,3),THETARE(2,3))\n call EQSIMPSON1D(NUPAR,UPAR,SGG(1,3,3),THETARE(3,3))\n\n !-- Anti-hermitian part of $\\Theta/(2\\pi)$ --!\n THETAIM(1:3,1:3)=0.\n\n else\n\n ! -- There is a resonance all right -- !\n ! -- 1. Hermitian part -- !\n UPAR0=SQMUT0/NPARA1*(1.-NWCW)\n call CAUCHY_PPART2(UPAR,NUPAR,UPAR0,SGG(1,1,1),THETARE(1,1))\n call CAUCHY_PPART2(UPAR,NUPAR,UPAR0,SGG(1,2,1),THETARE(2,1))\n call CAUCHY_PPART2(UPAR,NUPAR,UPAR0,SGG(1,3,1),THETARE(3,1))\n call CAUCHY_PPART2(UPAR,NUPAR,UPAR0,SGG(1,1,2),THETARE(1,2))\n call CAUCHY_PPART2(UPAR,NUPAR,UPAR0,SGG(1,2,2),THETARE(2,2))\n call CAUCHY_PPART2(UPAR,NUPAR,UPAR0,SGG(1,3,2),THETARE(3,2))\n call CAUCHY_PPART2(UPAR,NUPAR,UPAR0,SGG(1,1,3),THETARE(1,3))\n call CAUCHY_PPART2(UPAR,NUPAR,UPAR0,SGG(1,2,3),THETARE(2,3))\n call CAUCHY_PPART2(UPAR,NUPAR,UPAR0,SGG(1,3,3),THETARE(3,3))\n\n ! -- 2. Anti-hermitian part -- !\n call WINTERP1D(UPAR,NUPAR,SGG(1,1,1),UPAR0,THETAIM(1,1))\n call WINTERP1D(UPAR,NUPAR,SGG(1,2,1),UPAR0,THETAIM(2,1))\n call WINTERP1D(UPAR,NUPAR,SGG(1,3,1),UPAR0,THETAIM(3,1))\n call WINTERP1D(UPAR,NUPAR,SGG(1,1,2),UPAR0,THETAIM(1,2))\n call WINTERP1D(UPAR,NUPAR,SGG(1,2,2),UPAR0,THETAIM(2,2))\n call WINTERP1D(UPAR,NUPAR,SGG(1,3,2),UPAR0,THETAIM(3,2))\n call WINTERP1D(UPAR,NUPAR,SGG(1,1,3),UPAR0,THETAIM(1,3))\n call WINTERP1D(UPAR,NUPAR,SGG(1,2,3),UPAR0,THETAIM(2,3))\n call WINTERP1D(UPAR,NUPAR,SGG(1,3,3),UPAR0,THETAIM(3,3))\n\n do N=1,3\n do M=1,3\n THETARE(M,N)=-THETARE(M,N)*SQMUT0/NPARA1\n THETAIM(M,N)=-PI*THETAIM(M,N)*SQMUT0/abs(NPARA1)\n end do\n end do\n\n end if\n\n do N=1,3\n do M=1,3\n WSPEC(M,N)=WSPEC(M,N)+2.*PI*WPFACT*BETAFACT*cmplx(THETARE(M,N),THETAIM(M,N))\n end do\n end do\n\n end do\n\n call WROTATE_AORSA(BETA1,BETA2,WSPEC(1,1))\n\n end subroutine GETNONMAXSWMAT_AORSA_NEW\n\n!\n!*************************************************************************\n!\n\n\n subroutine GETNONMAXSWMAT_AORSA(W,ZSPEC,ASPEC,DENS,BMAG, &\n & K1,XI1,JNXI1,K2,XI2,JNXI2,NBESSJ,ENORM,UPARMIN,UPARMAX, &\n & NUPAR,NUPER,UPER,UPAR,DFDUPER,DFDUPAR,WSPEC,IFAIL)\n implicit none\n real, intent(IN):: W,ZSPEC,ASPEC,DENS,BMAG\n real, dimension(3):: K1,K2\n integer, intent(IN):: NUPAR,NUPER,NBESSJ\n real, dimension(NUPER), intent(IN):: XI1,XI2\n real, dimension(NUPER, NBESSJ), intent(IN):: JNXI1,JNXI2\n real, intent(IN):: ENORM,UPARMIN,UPARMAX\n real, dimension(NUPER), intent(IN):: UPER\n real, dimension(NUPAR), intent(IN):: UPAR\n real, dimension(NUPER,NUPAR), intent(IN):: DFDUPER,DFDUPAR\n complex, dimension(3,3), intent(OUT):: WSPEC\n integer, intent(OUT):: IFAIL\n\n complex:: BETAFACT\n real, parameter:: EOVERAMU = 9.64853e7\n real, parameter:: WP2FACT=1.745915\n real, parameter:: MPC2=938271998.38\n real, parameter:: C=2.99792458e8\n real, parameter:: PI=3.141592653597932384\n real:: W2,WP2,WPFACT,WCW,BETA1,BETA2\n real:: MUT0,SQMUT0,ISQ2,NWCW\n real:: SFACT0,SFACTP1,SFACTM1,RRP,RRM,KPARA1\n real:: KPARABS,NPARA1,CUPAR,CUPER,DFACTPAR,DFACTPER\n real:: RR,IRR,LF0,LNF0UPER,UPAR0,DUPARF,UPARMMAX\n real:: CLUPARF,CUPARP,CUPARM,DFACTPARP,DFACTPARM\n real:: IDFDUPARM,IDFDUPERM,IDFDUPARP,IDFDUPERP\n real:: LF0P,LF0M,LNF0PUPER,LNF0MUPER\n real:: DLF0,DLNF0UPER,UDLF0,UDLNF0UPER\n real:: DFDUPER0,DFDUPAR0\n real, dimension(3,3):: THETARE,THETAIM,G\n real, dimension(NUPER,3,3):: SWW\n real, dimension(NUPAR,3,3):: IRRG,GG,UDDGG\n real, dimension(NUPER):: JN0XI1,JNP1XI1,JNM1XI1\n real, dimension(NUPER):: JN0XI2,JNP1XI2,JNM1XI2\n real, dimension(NUPAR):: LUPARF,LLOGF\n integer:: IHARM,NHARM,NJ,NJP1,NJM1,I,J,J1,K,N,M\n\n IFAIL=0\n WSPEC(1:3,1:3) = cmplx(0.,0.)\n W2=W*W\n WP2=DENS*ZSPEC**2*WP2FACT/ASPEC\n WPFACT=WP2/W2\n WCW=BMAG*ZSPEC*EOVERAMU/ASPEC/W\n BETA1=ATAN2(K1(2),K1(1))\n BETA2=ATAN2(K2(2),K2(1))\n KPARA1=K1(3)\n NPARA1=KPARA1*C/W\n MUT0=0.5*MPC2*ASPEC/ENORM\n SQMUT0=SQRT(MUT0)\n ISQ2=SQRT(0.5)\n NHARM=NBESSJ-2\n\n ! -- Loop over harmonics -- !\n do IHARM=-NHARM,NHARM\n NWCW=real(IHARM)*WCW\n\n BETAFACT=exp(cmplx(0.,IHARM*(BETA1-BETA2)))\n NJ=ABS(IHARM)+1\n NJP1=ABS(IHARM+1)+1\n NJM1=ABS(IHARM-1)+1\n SFACT0=real(sign(1,IHARM))**ABS(IHARM)\n SFACTP1=real(sign(1,IHARM+1))**ABS(IHARM+1)\n SFACTM1=real(sign(1,IHARM-1))**ABS(IHARM-1)\n JN0XI1(1:NUPER)=SFACT0*JNXI1(1:NUPER,NJ)\n JNP1XI1(1:NUPER)=SFACTP1*JNXI1(1:NUPER,NJP1)\n JNM1XI1(1:NUPER)=SFACTM1*JNXI1(1:NUPER,NJM1)\n JN0XI2(1:NUPER)=SFACT0*JNXI2(1:NUPER,NJ)\n JNP1XI2(1:NUPER)=SFACTP1*JNXI2(1:NUPER,NJP1)\n JNM1XI2(1:NUPER)=SFACTM1*JNXI2(1:NUPER,NJM1)\n\n ! -- Resonance relation -- !\n RRP=1.-NWCW-NPARA1*UPARMAX/SQMUT0\n RRM=1.-NWCW-NPARA1*UPARMIN/SQMUT0\n\n if (RRP*RRM.GT.0) then\n\n !--------------------------------------!\n !-- First case: vector, no resonant --!\n !-- parallel velocity in the domain --!\n !--------------------------------------!\n\n do J=1,NUPAR\n CUPAR=UPAR(J)\n DFACTPAR=NPARA1*CUPAR/SQMUT0\n RR=1.-NWCW-DFACTPAR\n IRR=1./RR\n\n ! --- Computation of $sww=u_\\perp*w$ ---\n do K=1,NUPER\n CUPER=UPER(K)\n DFACTPER=NPARA1*CUPER/SQMUT0\n LF0=(1.-DFACTPAR)*DFDUPER(K,J)+DFACTPER*DFDUPAR(K,J)\n LNF0UPER=NWCW*DFDUPER(K,J)*CUPAR+(1.-NWCW)*DFDUPAR(K,J)*CUPER\n SWW(K,1,1)=0.5*CUPER*LF0*JNP1XI1(K)*JNP1XI2(K)*CUPER\n SWW(K,2,1)=0.5*CUPER*LF0*JNP1XI1(K)*JNM1XI2(K)*CUPER\n SWW(K,3,1)=ISQ2*CUPAR*LF0*JNP1XI1(K)*JN0XI2(K)*CUPER\n SWW(K,1,2)=0.5*CUPER*LF0*JNM1XI1(K)*JNP1XI2(K)*CUPER\n SWW(K,2,2)=0.5*CUPER*LF0*JNM1XI1(K)*JNM1XI2(K)*CUPER\n SWW(K,3,2)=ISQ2*CUPAR*LF0*JNM1XI1(K)*JN0XI2(K)*CUPER\n SWW(K,1,3)=ISQ2*CUPER*LNF0UPER*JN0XI1(K)*JNP1XI2(K)\n SWW(K,2,3)=ISQ2*CUPER*LNF0UPER*JN0XI1(K)*JNM1XI2(K)\n SWW(K,3,3)=CUPAR*LNF0UPER*JN0XI1(K)*JN0XI2(K)\n end do\n\n !-- Integration over $u_\\perp$ --!\n call EQTRAPZ1D(NUPER,UPER,SWW(1,1,1),G(1,1))\n call EQTRAPZ1D(NUPER,UPER,SWW(1,2,1),G(2,1))\n call EQTRAPZ1D(NUPER,UPER,SWW(1,3,1),G(3,1))\n call EQTRAPZ1D(NUPER,UPER,SWW(1,1,2),G(1,2))\n call EQTRAPZ1D(NUPER,UPER,SWW(1,2,2),G(2,2))\n call EQTRAPZ1D(NUPER,UPER,SWW(1,3,2),G(3,2))\n call EQTRAPZ1D(NUPER,UPER,SWW(1,1,3),G(1,3))\n call EQTRAPZ1D(NUPER,UPER,SWW(1,2,3),G(2,3))\n call EQTRAPZ1D(NUPER,UPER,SWW(1,3,3),G(3,3))\n\n do N=1,3\n do M=1,3\n IRRG(J,M,N)=G(M,N)*IRR\n end do\n end do\n\n end do\n\n !-- Hermitian part of $\\Theta/(2\\pi)$ --!\n call EQTRAPZ1D(NUPAR,UPAR,IRRG(1,1,1),THETARE(1,1))\n call EQTRAPZ1D(NUPAR,UPAR,IRRG(1,2,1),THETARE(2,1))\n call EQTRAPZ1D(NUPAR,UPAR,IRRG(1,3,1),THETARE(3,1))\n call EQTRAPZ1D(NUPAR,UPAR,IRRG(1,1,2),THETARE(1,2))\n call EQTRAPZ1D(NUPAR,UPAR,IRRG(1,2,2),THETARE(2,2))\n call EQTRAPZ1D(NUPAR,UPAR,IRRG(1,3,2),THETARE(3,2))\n call EQTRAPZ1D(NUPAR,UPAR,IRRG(1,1,3),THETARE(1,3))\n call EQTRAPZ1D(NUPAR,UPAR,IRRG(1,2,3),THETARE(2,3))\n call EQTRAPZ1D(NUPAR,UPAR,IRRG(1,3,3),THETARE(3,3))\n\n !-- Anti-hermitian part of $\\Theta/(2\\pi)$ --!\n THETAIM(1:3,1:3)=0.\n\n else\n\n !---------------------------------------------------!\n !-- Second case: there is a resonant --!\n !-- parallel velocity in the $u_\\parallel$ domain --!\n !---------------------------------------------------!\n\n !-- Resonant parallel velocity --!\n UPAR0=SQMUT0/NPARA1*(1.-NWCW)\n\n ! --- 1. Hermitian part --- !\n\n !-- New $u_\\parallel$ grid --!\n LUPARF(1)=0.\n LLOGF(1)=0.\n UPARMMAX=max(abs(UPARMIN),abs(UPARMAX))\n DUPARF=(UPARMMAX+ABS(UPAR0))/(NUPAR-1)\n do J1=2,NUPAR\n CLUPARF=DUPARF*(J1-1)\n LUPARF(J1)=CLUPARF\n LLOGF(J1)=CLUPARF*(LOG(ABS(CLUPARF))-1.)\n end do\n\n do J=1,NUPAR\n CUPARP=UPAR0+LUPARF(J)\n CUPARM=UPAR0-LUPARF(J)\n DFACTPARP=NPARA1*CUPARP/SQMUT0\n DFACTPARM=NPARA1*CUPARM/SQMUT0\n\n ! --- Computation of $sww=u_\\perp*w$ ---\n do K=1,NUPER\n CUPER=UPER(K)\n DFACTPER=NPARA1*CUPER/SQMUT0\n call WINTERP2D(UPER,NUPER,UPAR,NUPAR,DFDUPAR, &\n & CUPER,CUPARP,IDFDUPARP)\n call WINTERP2D(UPER,NUPER,UPAR,NUPAR,DFDUPER, &\n & CUPER,CUPARP,IDFDUPERP)\n call WINTERP2D(UPER,NUPER,UPAR,NUPAR,DFDUPAR, &\n & CUPER,CUPARM,IDFDUPARM)\n call WINTERP2D(UPER,NUPER,UPAR,NUPAR,DFDUPER, &\n & CUPER,CUPARM,IDFDUPERM)\n LF0P=(1.-DFACTPARP)*IDFDUPERP+DFACTPER*IDFDUPARP\n LF0M=(1.-DFACTPARM)*IDFDUPERM+DFACTPER*IDFDUPARM\n LNF0PUPER=NWCW*IDFDUPERP*CUPARP+(1.-NWCW)*IDFDUPARP*CUPER\n LNF0MUPER=NWCW*IDFDUPERM*CUPARM+(1.-NWCW)*IDFDUPARM*CUPER\n DLF0=LF0P-LF0M\n DLNF0UPER=LNF0PUPER-LNF0MUPER\n UDLF0=CUPARP*LF0P-CUPARM*LF0M\n UDLNF0UPER=CUPARP*LNF0PUPER-CUPARM*LNF0MUPER\n SWW(K,1,1)=0.5*CUPER*DLF0*JNP1XI1(K)*JNP1XI2(K)*CUPER\n SWW(K,2,1)=0.5*CUPER*DLF0*JNP1XI1(K)*JNM1XI2(K)*CUPER\n SWW(K,3,1)=ISQ2*UDLF0*JNP1XI1(K)*JN0XI2(K)*CUPER\n SWW(K,1,2)=0.5*CUPER*DLF0*JNM1XI1(K)*JNP1XI2(K)*CUPER\n SWW(K,2,2)=0.5*CUPER*DLF0*JNM1XI1(K)*JNM1XI2(K)*CUPER\n SWW(K,3,2)=ISQ2*UDLF0*JNM1XI1(K)*JN0XI2(K)*CUPER\n SWW(K,1,3)=ISQ2*CUPER*DLNF0UPER*JN0XI1(K)*JNP1XI2(K)\n SWW(K,2,3)=ISQ2*CUPER*DLNF0UPER*JN0XI1(K)*JNM1XI2(K)\n SWW(K,3,3)=UDLNF0UPER*JN0XI1(K)*JN0XI2(K)\n end do\n\n !-- Integration over $u_\\perp$ --!\n call EQTRAPZ1D(NUPER,UPER,SWW(1,1,1),GG(J,1,1))\n call EQTRAPZ1D(NUPER,UPER,SWW(1,2,1),GG(J,2,1))\n call EQTRAPZ1D(NUPER,UPER,SWW(1,3,1),GG(J,3,1))\n call EQTRAPZ1D(NUPER,UPER,SWW(1,1,2),GG(J,1,2))\n call EQTRAPZ1D(NUPER,UPER,SWW(1,2,2),GG(J,2,2))\n call EQTRAPZ1D(NUPER,UPER,SWW(1,3,2),GG(J,3,2))\n call EQTRAPZ1D(NUPER,UPER,SWW(1,1,3),GG(J,1,3))\n call EQTRAPZ1D(NUPER,UPER,SWW(1,2,3),GG(J,2,3))\n call EQTRAPZ1D(NUPER,UPER,SWW(1,3,3),GG(J,3,3))\n\n end do\n\n !-- $gg''*llogf$ --!\n UDDGG(1,1:3,1:3)=0.\n UDDGG(NUPAR,1:3,1:3)=0.\n do J=2,NUPAR-1\n UDDGG(J,1,1)=LLOGF(J)* &\n & (GG(J+1,1,1)-2.*GG(J,1,1)+GG(J-1,1,1))/DUPARF**2\n UDDGG(J,2,1)=LLOGF(J)* &\n & (GG(J+1,2,1)-2.*GG(J,2,1)+GG(J-1,2,1))/DUPARF**2\n UDDGG(J,3,1)=LLOGF(J)* &\n & (GG(J+1,3,1)-2.*GG(J,3,1)+GG(J-1,3,1))/DUPARF**2\n UDDGG(J,1,2)=LLOGF(J)* &\n & (GG(J+1,1,2)-2.*GG(J,1,2)+GG(J-1,1,2))/DUPARF**2\n UDDGG(J,2,2)=LLOGF(J)* &\n & (GG(J+1,2,2)-2.*GG(J,2,2)+GG(J-1,2,2))/DUPARF**2\n UDDGG(J,3,2)=LLOGF(J)* &\n & (GG(J+1,3,2)-2.*GG(J,3,2)+GG(J-1,3,2))/DUPARF**2\n UDDGG(J,1,3)=LLOGF(J)* &\n &(GG(J+1,1,3)-2.*GG(J,1,3)+GG(J-1,1,3))/DUPARF**2\n UDDGG(J,2,3)=LLOGF(J)* &\n & (GG(J+1,2,3)-2.*GG(J,2,3)+GG(J-1,2,3))/DUPARF**2\n UDDGG(J,3,3)=LLOGF(J)* &\n & (GG(J+1,3,3)-2.*GG(J,3,3)+GG(J-1,3,3))/DUPARF**2\n end do\n\n !-- Real part of $\\Theta/(2\\pi)$ --!\n call EQTRAPZ1D(NUPAR,LUPARF,UDDGG(1,1,1),THETARE(1,1))\n call EQTRAPZ1D(NUPAR,LUPARF,UDDGG(1,2,1),THETARE(2,1))\n call EQTRAPZ1D(NUPAR,LUPARF,UDDGG(1,3,1),THETARE(3,1))\n call EQTRAPZ1D(NUPAR,LUPARF,UDDGG(1,1,2),THETARE(1,2))\n call EQTRAPZ1D(NUPAR,LUPARF,UDDGG(1,2,2),THETARE(2,2))\n call EQTRAPZ1D(NUPAR,LUPARF,UDDGG(1,3,2),THETARE(3,2))\n call EQTRAPZ1D(NUPAR,LUPARF,UDDGG(1,1,3),THETARE(1,3))\n call EQTRAPZ1D(NUPAR,LUPARF,UDDGG(1,2,3),THETARE(2,3))\n call EQTRAPZ1D(NUPAR,LUPARF,UDDGG(1,3,3),THETARE(3,3))\n\n do N=1,3\n do M=1,3\n THETARE(M,N)=-THETARE(M,N)*SQMUT0/NPARA1\n end do\n end do\n\n ! --- 2. Anti-hermitian part --- !\n do K=1,NUPER\n CUPER=UPER(K)\n DFACTPER=NPARA1*CUPER/SQMUT0\n call WINTERP2D(UPER,NUPER,UPAR,NUPAR,DFDUPAR,CUPER,UPAR0,DFDUPAR0)\n call WINTERP2D(UPER,NUPER,UPAR,NUPAR,DFDUPER,CUPER,UPAR0,DFDUPER0)\n\n LF0=NWCW*DFDUPER0+DFACTPER*DFDUPAR0\n LNF0UPER=NWCW*DFDUPER0*UPAR0+(1.-NWCW)*DFDUPAR0*CUPER\n\n SWW(K,1,1)=0.5*CUPER*LF0*JNP1XI1(K)*JNP1XI2(K)*CUPER\n SWW(K,2,1)=0.5*CUPER*LF0*JNP1XI1(K)*JNM1XI2(K)*CUPER\n SWW(K,3,1)=ISQ2*UPAR0*LF0*JNP1XI1(K)*JN0XI2(K)*CUPER\n SWW(K,1,2)=0.5*CUPER*LF0*JNM1XI1(K)*JNP1XI2(K)*CUPER\n SWW(K,2,2)=0.5*CUPER*LF0*JNM1XI1(K)*JNM1XI2(K)*CUPER\n SWW(K,3,2)=ISQ2*UPAR0*LF0*JNM1XI1(K)*JN0XI2(K)*CUPER\n SWW(K,1,3)=ISQ2*CUPAR*LNF0UPER*JN0XI1(K)*JNP1XI2(K)\n SWW(K,2,3)=ISQ2*CUPER*LNF0UPER*JN0XI1(K)*JNM1XI2(K)\n SWW(K,3,3)=UPAR0*LNF0UPER*JN0XI1(K)*JN0XI2(K)\n end do\n\n !--- Integration over $u_perp$ ---!\n call EQTRAPZ1D(NUPER,UPER,SWW(1,1,1),G(1,1))\n call EQTRAPZ1D(NUPER,UPER,SWW(1,2,1),G(2,1))\n call EQTRAPZ1D(NUPER,UPER,SWW(1,3,1),G(3,1))\n call EQTRAPZ1D(NUPER,UPER,SWW(1,1,2),G(1,2))\n call EQTRAPZ1D(NUPER,UPER,SWW(1,2,2),G(2,2))\n call EQTRAPZ1D(NUPER,UPER,SWW(1,3,2),G(3,2))\n call EQTRAPZ1D(NUPER,UPER,SWW(1,1,3),G(1,3))\n call EQTRAPZ1D(NUPER,UPER,SWW(1,2,3),G(2,3))\n call EQTRAPZ1D(NUPER,UPER,SWW(1,3,3),G(3,3))\n\n !-- Imaginary part of $\\Theta/(2\\pi)$ --!\n do N=1,3\n do M=1,3\n THETAIM(M,N)=-PI*G(M,N)*SQMUT0/abs(NPARA1)\n end do\n end do\n\n end if\n\n do N=1,3\n do M=1,3\n WSPEC(M,N)=WSPEC(M,N)+ &\n & 2.*PI*WPFACT*BETAFACT*cmplx(THETARE(M,N),THETAIM(M,N))\n end do\n end do\n end do\n\n call WROTATE_AORSA(BETA1,BETA2,WSPEC(1,1))\n\n end subroutine GETNONMAXSWMAT_AORSA\n\n!\n!*************************************************************************\n!\n\n subroutine GETNONMAXSIGMA_AORSA(W,ZSPEC,ASPEC,DENS,BMAG, &\n & K1,XI1,JNXI1,K2,XI2,JNXI2,NBESSJ,ENORM,UPARMIN,UPARMAX, &\n & NUPAR,NUPER,UPER,UPAR,DFDUPER,DFDUPAR,WSPEC,IFAIL)\n implicit none\n real, intent(IN):: W,ZSPEC,ASPEC,DENS,BMAG\n real, dimension(3):: K1,K2\n integer, intent(IN):: NUPAR,NUPER,NBESSJ\n real, dimension(NUPER), intent(IN):: XI1,XI2\n real, dimension(NUPER, NBESSJ), intent(IN):: JNXI1,JNXI2\n real, intent(IN):: ENORM,UPARMIN,UPARMAX\n real, dimension(NUPER), intent(IN):: UPER\n real, dimension(NUPAR), intent(IN):: UPAR\n real, dimension(NUPER,NUPAR), intent(IN):: DFDUPER,DFDUPAR\n complex, dimension(3,3), intent(OUT):: WSPEC\n integer, intent(OUT):: IFAIL\n\n complex:: BETAFACT\n real, parameter:: EOVERAMU = 9.64853e7\n real, parameter:: WP2FACT=1.745915\n real, parameter:: MPC2=938271998.38\n real, parameter:: C=2.99792458e8\n real, parameter:: PI=3.141592653597932384\n real:: W2,WP2,WPFACT,WCW,BETA1,BETA2\n real:: MUT0,SQMUT0,ISQ2,NWCW\n real:: SFACT0,SFACTP1,SFACTM1,RRP,RRM,KPARA1\n real:: KPARABS,NPARA1,CUPAR,CUPER,DFACTPAR,DFACTPER\n real:: RR,IRR,LF0,LNF0UPER,UPAR0,DUPARF,UPARMMAX\n real:: CLUPARF,CUPARP,CUPARM,DFACTPARP,DFACTPARM\n real:: IDFDUPARM,IDFDUPERM,IDFDUPARP,IDFDUPERP\n real:: LF0P,LF0M,LNF0PUPER,LNF0MUPER\n real:: DLF0,DLNF0UPER,UDLF0,UDLNF0UPER\n real:: DFDUPER0,DFDUPAR0\n real, dimension(3,3):: THETARE,THETAIM,G\n real, dimension(NUPER,3,3):: SWW\n real, dimension(NUPAR,3,3):: IRRG,GG,UDDGG\n real, dimension(NUPER):: JN0XI1,JNP1XI1,JNM1XI1\n real, dimension(NUPER):: JN0XI2,JNP1XI2,JNM1XI2\n real, dimension(NUPAR):: LUPARF,LLOGF\n integer:: IHARM,NHARM,NJ,NJP1,NJM1,I,J,J1,K,N,M\n\n IFAIL=0\n WSPEC(1:3,1:3) = cmplx(0.,0.)\n W2=W*W\n WP2=DENS*ZSPEC**2*WP2FACT/ASPEC\n WPFACT=WP2/W2\n WCW=BMAG*ZSPEC*EOVERAMU/ASPEC/W\n BETA1=ATAN2(K1(2),K1(1))\n BETA2=ATAN2(K2(2),K2(1))\n KPARA1=K1(3)\n NPARA1=KPARA1*C/W\n MUT0=0.5*MPC2*ASPEC/ENORM\n SQMUT0=SQRT(MUT0)\n ISQ2=SQRT(0.5)\n NHARM=NBESSJ-2\n\n ! -- Loop over harmonics -- !\n do IHARM=-NHARM,NHARM\n NWCW=real(IHARM)*WCW\n\n BETAFACT=exp(cmplx(0.,IHARM*(BETA1-BETA2)))\n NJ=ABS(IHARM)+1\n NJP1=ABS(IHARM+1)+1\n NJM1=ABS(IHARM-1)+1\n SFACT0=real(sign(1,IHARM))**ABS(IHARM)\n SFACTP1=real(sign(1,IHARM+1))**ABS(IHARM+1)\n SFACTM1=real(sign(1,IHARM-1))**ABS(IHARM-1)\n JN0XI1(1:NUPER)=SFACT0*JNXI1(1:NUPER,NJ)\n JNP1XI1(1:NUPER)=SFACTP1*JNXI1(1:NUPER,NJP1)\n JNM1XI1(1:NUPER)=SFACTM1*JNXI1(1:NUPER,NJM1)\n JN0XI2(1:NUPER)=SFACT0*JNXI2(1:NUPER,NJ)\n JNP1XI2(1:NUPER)=SFACTP1*JNXI2(1:NUPER,NJP1)\n JNM1XI2(1:NUPER)=SFACTM1*JNXI2(1:NUPER,NJM1)\n\n ! -- Resonance relation -- !\n RRP=1.-NWCW-NPARA1*UPARMAX/SQMUT0\n RRM=1.-NWCW-NPARA1*UPARMIN/SQMUT0\n\n if (RRP*RRM.GT.0) then\n\n !--------------------------------------!\n !-- First case: vector, no resonant --!\n !-- parallel velocity in the domain --!\n !--------------------------------------!\n\n do J=1,NUPAR\n CUPAR=UPAR(J)\n DFACTPAR=NPARA1*CUPAR/SQMUT0\n RR=1.-NWCW-DFACTPAR\n IRR=1./RR\n\n ! --- Computation of $sww=u_\\perp*w$ ---\n do K=1,NUPER\n CUPER=UPER(K)\n DFACTPER=NPARA1*CUPER/SQMUT0\n LF0=(1.-DFACTPAR)*DFDUPER(K,J)+DFACTPER*DFDUPAR(K,J)\n LNF0UPER=NWCW*DFDUPER(K,J)*CUPAR+(1.-NWCW)*DFDUPAR(K,J)*CUPER\n SWW(K,1,1)=0.5*CUPER*LF0*JNP1XI1(K)*JNP1XI2(K)*CUPER\n SWW(K,2,1)=0.5*CUPER*LF0*JNP1XI1(K)*JNM1XI2(K)*CUPER\n SWW(K,3,1)=ISQ2*CUPAR*LF0*JNP1XI1(K)*JN0XI2(K)*CUPER\n SWW(K,1,2)=0.5*CUPER*LF0*JNM1XI1(K)*JNP1XI2(K)*CUPER\n SWW(K,2,2)=0.5*CUPER*LF0*JNM1XI1(K)*JNM1XI2(K)*CUPER\n SWW(K,3,2)=ISQ2*CUPAR*LF0*JNM1XI1(K)*JN0XI2(K)*CUPER\n SWW(K,1,3)=ISQ2*CUPER*LNF0UPER*JN0XI1(K)*JNP1XI2(K)\n SWW(K,2,3)=ISQ2*CUPER*LNF0UPER*JN0XI1(K)*JNM1XI2(K)\n SWW(K,3,3)=CUPAR*LNF0UPER*JN0XI1(K)*JN0XI2(K)\n end do\n\n !-- Integration over $u_\\perp$ --!\n call EQTRAPZ1D(NUPER,UPER,SWW(1,1,1),G(1,1))\n call EQTRAPZ1D(NUPER,UPER,SWW(1,2,1),G(2,1))\n call EQTRAPZ1D(NUPER,UPER,SWW(1,3,1),G(3,1))\n ! call EQTRAPZ1D(NUPER,UPER,SWW(1,1,2),G(1,2)) !\n call EQTRAPZ1D(NUPER,UPER,SWW(1,2,2),G(2,2))\n call EQTRAPZ1D(NUPER,UPER,SWW(1,3,2),G(3,2))\n ! call EQTRAPZ1D(NUPER,UPER,SWW(1,1,3),G(1,3)) !\n ! call EQTRAPZ1D(NUPER,UPER,SWW(1,2,3),G(2,3)) !\n call EQTRAPZ1D(NUPER,UPER,SWW(1,3,3),G(3,3))\n\t\n\t G(1,2) = - G(2,1)\n\t G(1,3) = G(3,1)\n\t G(2,3) = - G(3,2)\n\n do N=1,3\n do M=1,3\n IRRG(J,M,N)=G(M,N)*IRR\n end do\n end do\n\n end do\n\n !-- Hermitian part of $\\Theta/(2\\pi)$ --!\n call EQTRAPZ1D(NUPAR,UPAR,IRRG(1,1,1),THETARE(1,1))\n call EQTRAPZ1D(NUPAR,UPAR,IRRG(1,2,1),THETARE(2,1))\n call EQTRAPZ1D(NUPAR,UPAR,IRRG(1,3,1),THETARE(3,1))\n ! call EQTRAPZ1D(NUPAR,UPAR,IRRG(1,1,2),THETARE(1,2)) !\n call EQTRAPZ1D(NUPAR,UPAR,IRRG(1,2,2),THETARE(2,2))\n call EQTRAPZ1D(NUPAR,UPAR,IRRG(1,3,2),THETARE(3,2))\n ! call EQTRAPZ1D(NUPAR,UPAR,IRRG(1,1,3),THETARE(1,3)) !\n ! call EQTRAPZ1D(NUPAR,UPAR,IRRG(1,2,3),THETARE(2,3)) !\n call EQTRAPZ1D(NUPAR,UPAR,IRRG(1,3,3),THETARE(3,3))\n\t\n\t THETARE(1,2) = - THETARE(2,1)\n\t THETARE(1,3) = THETARE(3,1)\n\t THETARE(2,3) = - THETARE(3,2)\n\n !-- Anti-hermitian part of $\\Theta/(2\\pi)$ --!\n THETAIM(1:3,1:3)=0.\n\n else\n\n !---------------------------------------------------!\n !-- Second case: there is a resonant --!\n !-- parallel velocity in the $u_\\parallel$ domain --!\n !---------------------------------------------------!\n\n !-- Resonant parallel velocity --!\n UPAR0=SQMUT0/NPARA1*(1.-NWCW)\n\n ! --- 1. Hermitian part --- !\n\n !-- New $u_\\parallel$ grid --!\n LUPARF(1)=0.\n LLOGF(1)=0.\n UPARMMAX=max(abs(UPARMIN),abs(UPARMAX))\n DUPARF=(UPARMMAX+ABS(UPAR0))/(NUPAR-1)\n do J1=2,NUPAR\n CLUPARF=DUPARF*(J1-1)\n LUPARF(J1)=CLUPARF\n LLOGF(J1)=CLUPARF*(LOG(ABS(CLUPARF))-1.)\n end do\n\n do J=1,NUPAR\n CUPARP=UPAR0+LUPARF(J)\n CUPARM=UPAR0-LUPARF(J)\n DFACTPARP=NPARA1*CUPARP/SQMUT0\n DFACTPARM=NPARA1*CUPARM/SQMUT0\n\n ! --- Computation of $sww=u_\\perp*w$ ---\n do K=1,NUPER\n CUPER=UPER(K)\n DFACTPER=NPARA1*CUPER/SQMUT0\n call WINTERP2D(UPER,NUPER,UPAR,NUPAR,DFDUPAR, &\n & CUPER,CUPARP,IDFDUPARP)\n call WINTERP2D(UPER,NUPER,UPAR,NUPAR,DFDUPER, &\n & CUPER,CUPARP,IDFDUPERP)\n call WINTERP2D(UPER,NUPER,UPAR,NUPAR,DFDUPAR, &\n & CUPER,CUPARM,IDFDUPARM)\n call WINTERP2D(UPER,NUPER,UPAR,NUPAR,DFDUPER, &\n & CUPER,CUPARM,IDFDUPERM)\n LF0P=(1.-DFACTPARP)*IDFDUPERP+DFACTPER*IDFDUPARP\n LF0M=(1.-DFACTPARM)*IDFDUPERM+DFACTPER*IDFDUPARM\n LNF0PUPER=NWCW*IDFDUPERP*CUPARP+(1.-NWCW)*IDFDUPARP*CUPER\n LNF0MUPER=NWCW*IDFDUPERM*CUPARM+(1.-NWCW)*IDFDUPARM*CUPER\n DLF0=LF0P-LF0M\n DLNF0UPER=LNF0PUPER-LNF0MUPER\n UDLF0=CUPARP*LF0P-CUPARM*LF0M\n UDLNF0UPER=CUPARP*LNF0PUPER-CUPARM*LNF0MUPER\n SWW(K,1,1)=0.5*CUPER*DLF0*JNP1XI1(K)*JNP1XI2(K)*CUPER\n SWW(K,2,1)=0.5*CUPER*DLF0*JNP1XI1(K)*JNM1XI2(K)*CUPER\n SWW(K,3,1)=ISQ2*UDLF0*JNP1XI1(K)*JN0XI2(K)*CUPER\n SWW(K,1,2)=0.5*CUPER*DLF0*JNM1XI1(K)*JNP1XI2(K)*CUPER\n SWW(K,2,2)=0.5*CUPER*DLF0*JNM1XI1(K)*JNM1XI2(K)*CUPER\n SWW(K,3,2)=ISQ2*UDLF0*JNM1XI1(K)*JN0XI2(K)*CUPER\n SWW(K,1,3)=ISQ2*CUPER*DLNF0UPER*JN0XI1(K)*JNP1XI2(K)\n SWW(K,2,3)=ISQ2*CUPER*DLNF0UPER*JN0XI1(K)*JNM1XI2(K)\n SWW(K,3,3)=UDLNF0UPER*JN0XI1(K)*JN0XI2(K)\n end do\n\n !-- Integration over $u_\\perp$ --!\n call EQTRAPZ1D(NUPER,UPER,SWW(1,1,1),GG(J,1,1))\n call EQTRAPZ1D(NUPER,UPER,SWW(1,2,1),GG(J,2,1))\n call EQTRAPZ1D(NUPER,UPER,SWW(1,3,1),GG(J,3,1))\n ! call EQTRAPZ1D(NUPER,UPER,SWW(1,1,2),GG(J,1,2)) !\n call EQTRAPZ1D(NUPER,UPER,SWW(1,2,2),GG(J,2,2))\n call EQTRAPZ1D(NUPER,UPER,SWW(1,3,2),GG(J,3,2))\n ! call EQTRAPZ1D(NUPER,UPER,SWW(1,1,3),GG(J,1,3)) !\n ! call EQTRAPZ1D(NUPER,UPER,SWW(1,2,3),GG(J,2,3)) !\n call EQTRAPZ1D(NUPER,UPER,SWW(1,3,3),GG(J,3,3))\n\t\n\t GG(J,1,2) = - GG(J,2,1)\n\t GG(J,1,3) = GG(J,3,1)\n\t GG(J,2,3) = - GG(J,3,2)\n\n end do\n\n !-- $gg''*llogf$ --!\n UDDGG(1,1:3,1:3)=0.\n UDDGG(NUPAR,1:3,1:3)=0.\n do J=2,NUPAR-1\n UDDGG(J,1,1)=LLOGF(J)* &\n & (GG(J+1,1,1)-2.*GG(J,1,1)+GG(J-1,1,1))/DUPARF**2\n UDDGG(J,2,1)=LLOGF(J)* &\n & (GG(J+1,2,1)-2.*GG(J,2,1)+GG(J-1,2,1))/DUPARF**2\n UDDGG(J,3,1)=LLOGF(J)* &\n & (GG(J+1,3,1)-2.*GG(J,3,1)+GG(J-1,3,1))/DUPARF**2\n UDDGG(J,1,2)=LLOGF(J)* &\n & (GG(J+1,1,2)-2.*GG(J,1,2)+GG(J-1,1,2))/DUPARF**2\n UDDGG(J,2,2)=LLOGF(J)* &\n & (GG(J+1,2,2)-2.*GG(J,2,2)+GG(J-1,2,2))/DUPARF**2\n UDDGG(J,3,2)=LLOGF(J)* &\n & (GG(J+1,3,2)-2.*GG(J,3,2)+GG(J-1,3,2))/DUPARF**2\n UDDGG(J,1,3)=LLOGF(J)* &\n &(GG(J+1,1,3)-2.*GG(J,1,3)+GG(J-1,1,3))/DUPARF**2\n UDDGG(J,2,3)=LLOGF(J)* &\n & (GG(J+1,2,3)-2.*GG(J,2,3)+GG(J-1,2,3))/DUPARF**2\n UDDGG(J,3,3)=LLOGF(J)* &\n & (GG(J+1,3,3)-2.*GG(J,3,3)+GG(J-1,3,3))/DUPARF**2\n end do\n\n !-- Real part of $\\Theta/(2\\pi)$ --!\n call EQTRAPZ1D(NUPAR,LUPARF,UDDGG(1,1,1),THETARE(1,1))\n call EQTRAPZ1D(NUPAR,LUPARF,UDDGG(1,2,1),THETARE(2,1))\n call EQTRAPZ1D(NUPAR,LUPARF,UDDGG(1,3,1),THETARE(3,1))\n ! call EQTRAPZ1D(NUPAR,LUPARF,UDDGG(1,1,2),THETARE(1,2)) !\n call EQTRAPZ1D(NUPAR,LUPARF,UDDGG(1,2,2),THETARE(2,2))\n call EQTRAPZ1D(NUPAR,LUPARF,UDDGG(1,3,2),THETARE(3,2))\n ! call EQTRAPZ1D(NUPAR,LUPARF,UDDGG(1,1,3),THETARE(1,3)) !\n ! call EQTRAPZ1D(NUPAR,LUPARF,UDDGG(1,2,3),THETARE(2,3)) !\n call EQTRAPZ1D(NUPAR,LUPARF,UDDGG(1,3,3),THETARE(3,3))\n\t\n\t THETARE(1,2) = - THETARE(2,1)\n\t THETARE(1,3) = THETARE(3,1)\n\t THETARE(2,3) = - THETARE(3,2)\n\n do N=1,3\n do M=1,3\n THETARE(M,N)=-THETARE(M,N)*SQMUT0/NPARA1\n end do\n end do\n\n ! --- 2. Anti-hermitian part --- !\n do K=1,NUPER\n CUPER=UPER(K)\n DFACTPER=NPARA1*CUPER/SQMUT0\n call WINTERP2D(UPER,NUPER,UPAR,NUPAR,DFDUPAR,CUPER,UPAR0,DFDUPAR0)\n call WINTERP2D(UPER,NUPER,UPAR,NUPAR,DFDUPER,CUPER,UPAR0,DFDUPER0)\n\n LF0=NWCW*DFDUPER0+DFACTPER*DFDUPAR0\n LNF0UPER=NWCW*DFDUPER0*UPAR0+(1.-NWCW)*DFDUPAR0*CUPER\n\n SWW(K,1,1)=0.5*CUPER*LF0*JNP1XI1(K)*JNP1XI2(K)*CUPER\n SWW(K,2,1)=0.5*CUPER*LF0*JNP1XI1(K)*JNM1XI2(K)*CUPER\n SWW(K,3,1)=ISQ2*UPAR0*LF0*JNP1XI1(K)*JN0XI2(K)*CUPER\n SWW(K,1,2)=0.5*CUPER*LF0*JNM1XI1(K)*JNP1XI2(K)*CUPER\n SWW(K,2,2)=0.5*CUPER*LF0*JNM1XI1(K)*JNM1XI2(K)*CUPER\n SWW(K,3,2)=ISQ2*UPAR0*LF0*JNM1XI1(K)*JN0XI2(K)*CUPER\n SWW(K,1,3)=ISQ2*CUPAR*LNF0UPER*JN0XI1(K)*JNP1XI2(K)\n SWW(K,2,3)=ISQ2*CUPER*LNF0UPER*JN0XI1(K)*JNM1XI2(K)\n SWW(K,3,3)=UPAR0*LNF0UPER*JN0XI1(K)*JN0XI2(K)\n end do\n\n !--- Integration over $u_perp$ ---!\n call EQTRAPZ1D(NUPER,UPER,SWW(1,1,1),G(1,1))\n call EQTRAPZ1D(NUPER,UPER,SWW(1,2,1),G(2,1))\n call EQTRAPZ1D(NUPER,UPER,SWW(1,3,1),G(3,1))\n ! call EQTRAPZ1D(NUPER,UPER,SWW(1,1,2),G(1,2)) !\n call EQTRAPZ1D(NUPER,UPER,SWW(1,2,2),G(2,2))\n call EQTRAPZ1D(NUPER,UPER,SWW(1,3,2),G(3,2))\n ! call EQTRAPZ1D(NUPER,UPER,SWW(1,1,3),G(1,3)) !\n ! call EQTRAPZ1D(NUPER,UPER,SWW(1,2,3),G(2,3)) !\n call EQTRAPZ1D(NUPER,UPER,SWW(1,3,3),G(3,3))\n\t\n\t G(1,2) = - G(2,1)\n\t G(1,3) = G(3,1)\n\t G(2,3) = - G(3,2)\n\n !-- Imaginary part of $\\Theta/(2\\pi)$ --!\n do N=1,3\n do M=1,3\n THETAIM(M,N)=-PI*G(M,N)*SQMUT0/abs(NPARA1)\n end do\n end do\n\n end if\n\n do N=1,3\n do M=1,3\n WSPEC(M,N)=WSPEC(M,N)+ &\n & 2.*PI*WPFACT*BETAFACT*cmplx(THETARE(M,N),THETAIM(M,N))\n end do\n end do\n end do\n\n call WROTATE_AORSA(BETA1,BETA2,WSPEC(1,1))\n\n end subroutine GETNONMAXSIGMA_AORSA\n\n!\n!*************************************************************************\n!\n\n\n\n\n subroutine BESSJ(XI,JNXI,LXI,LNBESSJ,LNSBESSJ)\n implicit none\n integer, intent(IN):: LXI,LNBESSJ,LNSBESSJ\n real, dimension(LXI), intent(IN):: XI\n real, dimension(LXI,LNBESSJ), intent(OUT):: JNXI\n real, parameter:: BIGNO=1.e10,BIGNI=1.e-10\n real, dimension(LXI):: TOX,AXI,J0XI,J1XI\n real, dimension(LXI):: BJP,BJ,BJM,JSUM\n integer:: MSUM,IX,N,NP\n integer, dimension(LXI):: MCOR\n\n ! --- Returns the J bessel functions from 0 to LNBESSJ --- !\n ! --- LNSBESSJ is the starting point for the downard recurence --- !\n ! --- XI(LXI) is the argument array and JNXI(LXI,LNBESSJ) is the output ---!\n\n!dir$ preferstream,prefervector\n do IX=1,LXI \n JNXI(IX,1:LNBESSJ)=0.\n\n TOX(IX)=0.\n AXI(IX)=ABS(XI(IX))\n if (AXI(IX).GT.0.)then\n TOX(IX)=2./AXI(IX)\n endif\n\n BJP(IX)=0.\n BJ(IX)=1.\n JSUM(IX)=0.\n enddo\n! MSUM=0\n do N=LNSBESSJ,1,-1\n!dir$ concurrent,preferstream,prefervector\n do IX=1,LXI \n MSUM=mod((LNSBESSJ-N),2)\n MCOR(IX)=0\n BJM(IX)=REAL(N)*TOX(IX)*BJ(IX)-BJP(IX)\n BJP(IX)=BJ(IX)\n BJ(IX)=BJM(IX)\n if (ABS(BJ(IX)).GT.BIGNO)then\n BJ(IX)=BJ(IX)*BIGNI\n BJP(IX)=BJP(IX)*BIGNI\n JSUM(IX)=JSUM(IX)*BIGNI\n MCOR(IX)=1\n endif\n JSUM(IX)=JSUM(IX)+REAL(MSUM)*BJ(IX)\n! MSUM=1-MSUM\n if (N.LT.LNBESSJ) JNXI(IX,N+1)=BJP(IX)\n do NP=N+2,LNBESSJ\n if (MCOR(IX).EQ.1)then\n JNXI(IX,NP)=JNXI(IX,NP)*BIGNI\n endif\n end do\n enddo\n end do\n do IX=1,LXI \n\n JSUM(IX)=2.*JSUM(IX)-BJ(IX)\n do N=1,LNBESSJ\n JNXI(IX,N)=JNXI(IX,N)/JSUM(IX)\n end do\n end do\n\n ! --- Upward Recurrence for x>=n --- !\n call BESSJ0(AXI,J0XI,LXI)\n call BESSJ1(AXI,J1XI,LXI)\n do IX=1,LXI\n BJM(IX)=J0XI(IX)\n BJ(IX)=J1XI(IX)\n do N=1,LNBESSJ\n if (AXI(IX)>=real(N-1))then\n JNXI(IX,N)=BJM(IX)\n BJP(IX)=REAL(N)*TOX(IX)*BJ(IX)-BJM(IX)\n BJM(IX)=BJ(IX)\n BJ(IX)=BJP(IX)\n endif\n end do\n\n ! --- Zero --- !\n if (XI(IX)==0.) then\n JNXI(IX,1)=1.\n do N=2,LNBESSJ\n JNXI(IX,N)=0.\n end do\n end if\n! end do\n\n ! --- Revert when needed --- !\n ! --- N.B. J1 does not need to be reverted --- !\n! do IX=1,LXI\n do N=4,LNBESSJ,2\n if (XI(IX).LT.0.) JNXI(IX,N)=-JNXI(IX,N)\n end do\n end do\n\n end subroutine BESSJ\n\n!\n!*************************************************************************\n!\n\n\n subroutine BESSJ0(XI,J0XI,LXI)\n implicit none\n integer, intent(IN):: LXI\n real, dimension(LXI), intent(IN) :: XI\n real, dimension(LXI), intent(OUT) :: J0XI\n real, dimension(LXI) :: YI,AXI,XXI,ZI\n real, dimension(5):: P,Q\n real, dimension(6):: R,S\n P=(/1.0,-0.1098628627e-2,0.2734510407e-4, &\n -0.2073370639e-5,0.2093887211e-6/)\n Q=(/-0.1562499995e-1,0.1430488765e-3, &\n -0.6911147651e-5,0.7621095161e-6,-0.934945152e-7/)\n R=(/57568490574.0,-13362590354.0,651619640.7, &\n -11214424.18,77392.33017,-184.9052456/)\n S=(/57568490411.0,1029532985.0,&\n 9494680.718,59272.64853,267.8532712,1.0/)\n\n where (abs(XI).LT.8.0)\n YI=XI*XI\n J0XI=(R(1)+YI*(R(2)+YI*(R(3)+YI*(R(4)+YI*(R(5)+YI*R(6))))))/ &\n (S(1)+YI*(S(2)+YI*(S(3)+YI*(S(4)+YI*(S(5)+YI*S(6))))))\n elsewhere\n AXI=abs(XI)\n ZI=8./AXI\n YI=ZI*ZI\n XXI=AXI-0.785398164\n J0XI=sqrt(0.636619772/AXI)* &\n (cos(XXI)*(P(1)+YI*(P(2)+YI*(P(3)+YI*(P(4)+YI*P(5))))) &\n - ZI*sin(XXI)*(Q(1)+YI*(Q(2)+YI*(Q(3)+YI*(Q(4)+YI*Q(5))))))\n end where\n end subroutine BESSJ0\n\n!\n!*************************************************************************\n!\n\n\n\n subroutine BESSJ1(XI,J1XI,LXI)\n implicit none\n integer, intent(IN):: LXI\n real, dimension(LXI), intent(IN):: XI\n real, dimension(LXI), intent(OUT):: J1XI\n real, dimension(LXI) :: YI,AXI,XXI,ZI\n real, dimension(5):: P,Q\n real, dimension(6):: R,S\n integer:: IX\n\n P=(/1.0,0.183105e-2,-0.3516396496e-4, &\n 0.2457520174e-5,-0.240337019e-6/)\n Q=(/0.04687499995,-0.2002690873e-3, &\n 0.8449199096e-5,-0.88228987e-6,0.105787412e-6/)\n R=(/72362614232.0,-7895059235.0,242396853.1, &\n -2972611.439,15704.48260,-30.16036606/)\n S=(/144725228442.0,2300535178.0,18583304.74, &\n 99447.43394,376.9991397,1.0/)\n\n where (abs(XI).LT.8.0)\n YI=XI*XI\n J1XI=XI*(R(1)+YI*(R(2)+YI*(R(3)+YI*(R(4)+YI*(R(5)+YI*R(6))))))/ &\n (S(1)+YI*(S(2)+YI*(S(3)+YI*(S(4)+YI*(S(5)+YI*S(6))))))\n elsewhere\n AXI=abs(XI)\n ZI=8./AXI\n YI=ZI*ZI\n XXI=AXI-2.356194491\n J1XI=sqrt(0.636619772/AXI)* &\n (cos(XXI)*(P(1)+YI*(P(2)+YI*(P(3)+YI*(P(4)+YI*P(5))))) &\n - ZI*sin(XXI)*(Q(1)+YI*(Q(2)+YI*(Q(3)+YI*(Q(4)+YI*Q(5)))))) &\n *sign(1.0,XI)\n end where\n\n ! --- Revert if needed --- !\n do IX=1,LXI\n if (XI(IX).LT.0.) J1XI(IX)=-J1XI(IX)\n end do\n\n end subroutine BESSJ1\n\n!\n!*************************************************************************\n!\n\n\n subroutine EQTRAPZ1D(LNU,LU,ARRAY,INTEGRAL)\n ! -- 1D trapezoidal integration for equally spaced coordinates -- !\n implicit none\n integer, intent(IN):: LNU\n real, dimension(LNU), intent(IN):: LU,ARRAY\n real, intent(OUT):: INTEGRAL\n real:: DU\n\n DU=(LU(LNU)-LU(1))/(LNU-1.)\n INTEGRAL=(sum(ARRAY(2:LNU-1))+0.5*(ARRAY(1)+ARRAY(LNU)))*DU\n\n end subroutine EQTRAPZ1D\n\n!\n!*************************************************************************\n!\n\n subroutine sgrate2(nxmax, x, f, ans)\n\n implicit none\n\n integer n, nxmax\n real f(nxmax), x(nxmax), ans\n\n ans = 0.0\n do n = 1, nxmax-1\n ans = ans + (x(n+1) - x(n)) * (f(n) + f(n+1)) / 2.0\n end do\n\n return\n end\n!\n!*************************************************************************\n!\n\n\n subroutine EQSIMPSON1D(LNU,LU,ARRAY,INTEGRAL)\n ! -- 1D Simpson integration for equally spaced coordinates and odd N -- !\n implicit none\n integer, intent(IN):: LNU\n real, dimension(LNU), intent(IN):: LU,ARRAY\n real, intent(OUT):: INTEGRAL\n\n real:: DU\n integer:: I\n\n DU=(LU(LNU)-LU(1))/(LNU-1.)\n INTEGRAL=2.*sum(ARRAY(2:LNU-1))+ARRAY(1)+ARRAY(LNU)\n do I=1,(LNU-1)/2\n INTEGRAL=INTEGRAL+2.*ARRAY(2*I)\n end do\n INTEGRAL=INTEGRAL*DU / 3.\n\n end subroutine EQSIMPSON1D\n\n!\n!*************************************************************************\n!\n subroutine EQSIMPSON1D_2(LNU,LU,ARRAY,INTEGRAL)\n ! -- 1D Simpson integration for equally spaced coordinates and odd N -- !\n implicit none\n integer, intent(IN):: LNU\n real, dimension(LNU), intent(IN):: LU,ARRAY\n real, intent(OUT):: INTEGRAL\n\n real:: DU\n\n DU=(LU(LNU)-LU(1))/(LNU-1.)\n INTEGRAL=ARRAY(1)+ARRAY(LNU)+ 2.*sum(array(2:lnu-1))\n integral = integral + 2.*sum(array(2:lnu-1:2))\n\n INTEGRAL=INTEGRAL*DU / 3.\n\n end subroutine EQSIMPSON1D_2\n\n!\n!*************************************************************************\n!\n\n\n subroutine WINTERP2D(X,LX,Y,LY,FXY,X0,Y0,FXY0)\n implicit none\n integer, intent(IN):: LX,LY\n real, dimension(LX), intent(IN):: X\n real, dimension(LY), intent(IN):: Y\n real, dimension(LX,LY), intent(IN):: FXY\n real, intent(IN):: X0,Y0\n real, intent(OUT):: FXY0\n real:: A0,A1,A2,A3,A4,A5,P,Q\n real:: XMIN,XMAX,YMIN,YMAX,DX,DY\n integer:: I,J\n\n FXY0=0.\n XMIN=X(1)\n YMIN=Y(1)\n XMAX=X(LX)\n YMAX=Y(LY)\n DX=(XMAX-XMIN)/(LX-1)\n DY=(YMAX-YMIN)/(LY-1)\n if ((X0>=XMIN).and.(X0<=XMAX).and.(Y0>=YMIN).and.(Y0<=YMAX)) then\n\n I=int(1.+(X0-XMIN)/DX)\n J=int(1.+(Y0-YMIN)/DY)\n P=(X0-X(I))/DX\n Q=(Y0-Y(J))/DY\n\n if (I.eq.LX) I=LX-1\n if (J.eq.LY) J=LY-1\n if ((I.ne.1).and.(J.ne.1)) then\n A0=0.5*Q*(Q-1.)\n A1=0.5*P*(P-1.)\n A2=1.+P*Q-P*P-Q*Q\n A3=0.5*P*(P-2.*Q+1.)\n A4=0.5*Q*(Q-2.*P+1.)\n A5=P*Q\n FXY0=A0*FXY(I,J-1)+A1*FXY(I-1,J)+A2*FXY(I,J)+A3*FXY(I+1,J) &\n +A4*FXY(I,J+1)+A5*FXY(I+1,J+1)\n else\n A0=(1.-P)*(1.-Q)\n A1=P*(1.-Q)\n A2=Q*(1.-P)\n A3=P*Q\n FXY0=A0*FXY(I,J)+A1*FXY(I+1,J)+A2*FXY(I,J+1)+A3*FXY(I+1,J+1)\n end if\n end if\n end subroutine WINTERP2D\n\n!\n!*************************************************************************\n!\n\n\n SUBROUTINE WROTATE_AORSA(BETA1,BETA2,W)\n ! Apply unitary polarization matrices, eg., Wout = C2*Win*C1\n ! Transforms the perpendicular part of the tensor from right\n ! and left polarized components into fixed real components.\n IMPLICIT NONE\n real:: BETA1,BETA2\n complex :: W(3,3),WW(3,3),C1(3,3),C2(3,3)\n complex :: C1P,C1M,C2P,C2M\n INTEGER I,J,K\n real, parameter :: ZERO = 0.0, ONE = 1.0\n real, parameter :: ROOTHALF = 0.707106781\n C1P = ROOTHALF*EXP(CMPLX(ZERO,BETA1))\n C1M = ROOTHALF*EXP(CMPLX(ZERO,-BETA1))\n C2P = ROOTHALF*EXP(CMPLX(ZERO,BETA2))\n C2M = ROOTHALF*EXP(CMPLX(ZERO,-BETA2))\n C1(1,1) = C1P\n C1(2,1) = C1M\n C1(3,1) = CMPLX(ZERO,ZERO)\n C1(1,2) = C1P*CMPLX(ZERO,-ONE)\n C1(2,2) = C1M*CMPLX(ZERO,ONE)\n C1(3,2) = CMPLX(ZERO,ZERO)\n C1(1,3) = CMPLX(ZERO,ZERO)\n C1(2,3) = CMPLX(ZERO,ZERO)\n C1(3,3) = CMPLX(ONE,ZERO)\n C2(1,1) = C2M\n C2(2,1) = C2M*CMPLX(ZERO,ONE)\n C2(3,1) = CMPLX(ZERO,ZERO)\n C2(1,2) = C2P\n C2(2,2) = C2P*CMPLX(ZERO,-ONE)\n C2(3,2) = CMPLX(ZERO,ZERO)\n C2(1,3) = CMPLX(ZERO,ZERO)\n C2(2,3) = CMPLX(ZERO,ZERO)\n C2(3,3) = CMPLX(ONE,ZERO)\n DO I=1,3\n DO J=1,3\n WW(I,J) = CMPLX(ZERO,ZERO)\n DO K=1,3\n WW(I,J) = WW(I,J) + W(I,K)*C1(K,J)\n enddo\n enddo\n enddo\n DO I=1,3\n DO J=1,3\n W(I,J) = CMPLX(ZERO,ZERO)\n DO K=1,3\n W(I,J) = W(I,J) + C2(I,K)*WW(K,J)\n enddo\n enddo\n enddo\n RETURN\n END subroutine WROTATE_AORSA\n\n!\n!*************************************************************************\n!\n\n\n subroutine CAUCHY_PPART(X,NX,XRES,FX,PINT)\n ! -- Returns principal part of int(x,fx/(x-xres)) -- !\n implicit none\n integer, intent(IN):: NX\n real, dimension(NX), intent(IN):: X,FX\n real, intent(IN):: XRES\n real, intent(OUT):: PINT\n\n real:: CXP,CXM,FXP,FXM,LLOGF,XMAX,XMIN\n real:: CXF,DXF,DX\n real, dimension(NX):: LXF,INTGD,FXPP\n integer:: IX,IXM1,IXP1\n\n IXM1(IX)=MAX(IX-1,1)\n IXP1(IX)=MIN(IX+1,NX)\n\n XMAX=X(NX)\n XMIN=X(1)\n DXF=(XMAX+ABS(XRES))/(NX-1)\n DX=(XMAX-XMIN)/(NX-1)\n\n do IX=1,NX\n CXF=DXF*(IX-1)\n FXPP(IX)=(FX(IXP1(IX))-2.*FX(IX)+FX(IXM1(IX)))/DX**2\n LXF(IX)=CXF\n end do\n\n INTGD(1)=0.\n do IX=2,NX\n CXF=LXF(IX)\n LLOGF=CXF*(LOG(ABS(CXF))-1.)\n CXP=XRES+CXF\n CXM=XRES-CXF\n call WINTERP1D(X,NX,FXPP,CXP,FXP)\n call WINTERP1D(X,NX,FXPP,CXM,FXM)\n INTGD(IX)=LLOGF*(FXP-FXM)\n end do\n\n call EQSIMPSON1D(NX,LXF,INTGD,PINT)\n\n end subroutine CAUCHY_PPART\n\n!\n!*************************************************************************\n!\n subroutine WINTERP1D(X,LX,FX,X0,FX0)\n implicit none\n integer, intent(IN):: LX\n real, dimension(LX), intent(IN):: X,FX\n real, intent(IN):: X0\n real, intent(OUT):: FX0\n\n real:: FXY0,XMIN,XMAX,DX\n real:: P,A1,A2,A3\n integer:: I\n\n FX0=0.\n XMIN=X(1)\n XMAX=X(LX)\n DX=(XMAX-XMIN)/(LX-1)\n if ((X0>=XMIN).and.(X0<=XMAX)) then\n I=int(1.+(X0-XMIN)/DX)\n P=(X0-X(I))/DX\n if (I.eq.LX) I=LX-1\n if (I.eq.1) I=2\n A1=0.5*P*(P-1.)\n A2=1.-P*P\n A3=0.5*P*(P+1.)\n FX0=A1*FX(I-1)+A2*FX(I)+A3*FX(I+1)\n end if\n end subroutine WINTERP1D\n!\n!*************************************************************************\n!\n subroutine WINTERP1D_2(X,LX,FX,X0,FX0)\n implicit none\n integer, intent(IN):: LX\n real, dimension(LX), intent(IN):: X,FX\n real, intent(IN):: X0\n real, intent(OUT):: FX0\n\n real:: FXY0,XMIN,XMAX,DX\n real:: P,A1,A2,A3\n integer:: I\n\n FX0=0.\n XMIN=X(1)\n XMAX=X(LX)\n DX=(XMAX-XMIN)/(LX-1)\n if ((X0>=XMIN).and.(X0<=XMAX)) then\n I=int(1.+(X0-XMIN)/DX)\n P=(X0-X(I))/DX\n! if (I.eq.LX) I=LX-1\n! if (I.eq.1) I=2\n\n if(i .ne. 1 .and. i .ne. lx)then\n A1=0.5*P*(P-1.)\n A2=1.-P*P\n A3=0.5*P*(P+1.)\n FX0=A1*FX(I-1)+A2*FX(I)+A3*FX(I+1)\n else\n if(i .eq. lx) fx0 = fx(i)\n if(i .eq. 1) fx0 = fx(i) + (fx(i+1) - fx(i)) * p\n end if\n\n end if\n end subroutine WINTERP1D_2\n\n!\n!*************************************************************************\n!\n\n\n subroutine intplt1d(x, lx, fx, x0, fx0)\n\n! -----------------------\n! 1D linear interpolation\n! -----------------------\n\n implicit none\n\n integer lx, i\n real fx(lx), x(lx), fx0, x0, dx\n\n dx = (x(lx) - x(1)) / (lx - 1)\n i = int((x0 - x(1)) / dx) + 1\n\n if(i .eq. lx)then\n fx0 = fx(lx)\n else\n fx0 = fx(i) + (fx(i+1) - fx(i)) * (x0 - x(i)) / dx\n end if\n\n\t return\n\t end subroutine intplt1d\n\n!\n!*************************************************************************\n!\n\n\n\n!end module METS2AORSA\n\n", "meta": {"hexsha": "482d7b88a735b765e25c678d99025d323a479746", "size": 70178, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/CQL3D_SETUP/SAVE/mets2aorsa.f", "max_stars_repo_name": "ORNL-Fusion/aorsa", "max_stars_repo_head_hexsha": "82bab1e3b88e10e6bd5ca9b16589b11a97dd8f39", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2019-03-12T13:33:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-11T08:28:46.000Z", "max_issues_repo_path": "src/CQL3D_SETUP/SAVE/mets2aorsa.f", "max_issues_repo_name": "ORNL-Fusion/aorsa", "max_issues_repo_head_hexsha": "82bab1e3b88e10e6bd5ca9b16589b11a97dd8f39", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 29, "max_issues_repo_issues_event_min_datetime": "2020-01-24T15:58:55.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-28T15:16:05.000Z", "max_forks_repo_path": "src/CQL3D_SETUP/SAVE/mets2aorsa.f", "max_forks_repo_name": "ORNL-Fusion/aorsa", "max_forks_repo_head_hexsha": "82bab1e3b88e10e6bd5ca9b16589b11a97dd8f39", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-09-10T16:48:52.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-10T16:48:52.000Z", "avg_line_length": 32.0740402194, "max_line_length": 91, "alphanum_fraction": 0.5147054633, "num_tokens": 29529, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989822921759, "lm_q2_score": 0.7490872075132152, "lm_q1q2_score": 0.6786653864878528}} {"text": " subroutine compute_px(ctfmp,n_Axx,n_beta,n_divbeta,x,Nx,hx,myzero,\n &vee,phys_bdy,res)\n implicit none\n integer i\n integer Nx\n real*8 hx\n real*8 myzero\n real*8 vee\n real*8 ctfmp(Nx)\n real*8 n_Axx(Nx)\n real*8 n_beta(Nx)\n real*8 n_divbeta(Nx)\n real*8 x(Nx)\n integer phys_bdy(2)\n real*8 res(Nx)\n real*8 qb\n if (phys_bdy(1) .eq. 1) then\n do i=1, 1, 1\n qb = myzero * x(i)\n res(i)=qb\n end do\n endif\n do i=2, Nx-1, 1\n qb = -0.6666666666666667D0 * n_Axx(i) * vee * n_divbeta(i) + (n_Ax\n #x(i) * (-0.1D1 * n_beta(i - 1) + n_beta(i + 1)) + 0.50000000000000\n #00D0 * (-0.1D1 * n_Axx(i - 1) + n_Axx(i + 1)) * n_beta(i)) / ctfmp\n #(i) / hx\n res(i)=qb\n end do\n if (phys_bdy(2) .eq. 1) then\n do i=Nx, Nx, 1\n qb = myzero * x(i)\n res(i)=qb\n end do\n endif\n END\n", "meta": {"hexsha": "f789b1ab46730d6d6684c79109a1b4a43f2e38f1", "size": 919, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/FD/compute_px.f", "max_stars_repo_name": "rmanak/bssn_spher", "max_stars_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/FD/compute_px.f", "max_issues_repo_name": "rmanak/bssn_spher", "max_issues_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/FD/compute_px.f", "max_forks_repo_name": "rmanak/bssn_spher", "max_forks_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.8378378378, "max_line_length": 72, "alphanum_fraction": 0.5016322089, "num_tokens": 382, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898203834277, "lm_q2_score": 0.749087201911703, "lm_q1q2_score": 0.6786653795115082}} {"text": " FUNCTION RTSAFE(FUNCD,X1,X2,XACC)\n PARAMETER (MAXIT=100)\n CALL FUNCD(X1,FL,DF)\n CALL FUNCD(X2,FH,DF)\n IF(FL*FH.GE.0.) PAUSE 'root must be bracketed'\n IF(FL.LT.0.)THEN\n XL=X1\n XH=X2\n ELSE\n XH=X1\n XL=X2\n SWAP=FL\n FL=FH\n FH=SWAP\n ENDIF\n RTSAFE=.5*(X1+X2)\n DXOLD=ABS(X2-X1)\n DX=DXOLD\n CALL FUNCD(RTSAFE,F,DF)\n DO 11 J=1,MAXIT\n IF(((RTSAFE-XH)*DF-F)*((RTSAFE-XL)*DF-F).GE.0.\n * .OR. ABS(2.*F).GT.ABS(DXOLD*DF) ) THEN\n DXOLD=DX\n DX=0.5*(XH-XL)\n RTSAFE=XL+DX\n IF(XL.EQ.RTSAFE)RETURN\n ELSE\n DXOLD=DX\n DX=F/DF\n TEMP=RTSAFE\n RTSAFE=RTSAFE-DX\n IF(TEMP.EQ.RTSAFE)RETURN\n ENDIF\n IF(ABS(DX).LT.XACC) RETURN\n CALL FUNCD(RTSAFE,F,DF)\n IF(F.LT.0.) THEN\n XL=RTSAFE\n FL=F\n ELSE\n XH=RTSAFE\n FH=F\n ENDIF\n11 CONTINUE\n PAUSE 'RTSAFE exceeding maximum iterations'\n RETURN\n END\n", "meta": {"hexsha": "d00c6c190ec521054f3b0f85aee3a7c2e5b0eb40", "size": 1068, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "Math3/NumRec/source/rtsafe.for", "max_stars_repo_name": "domijin/MM3", "max_stars_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Math3/NumRec/source/rtsafe.for", "max_issues_repo_name": "domijin/MM3", "max_issues_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Math3/NumRec/source/rtsafe.for", "max_forks_repo_name": "domijin/MM3", "max_forks_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.7234042553, "max_line_length": 54, "alphanum_fraction": 0.4775280899, "num_tokens": 387, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898203834277, "lm_q2_score": 0.7490872019117029, "lm_q1q2_score": 0.6786653795115081}} {"text": "! hilbert transform\n\n\nuse MathClass\nuse ArrayClass\nuse IOClass\nimplicit none\n\ntype(Math_) :: math\ntype(IO_) :: f\ncomplex(complex64),allocatable :: t(:), wave(:), h_top_wave(:)&\n ,h_bottom_wave(:),spectre(:)\nreal(real64) :: omega_1\nreal(real64) :: omega_2\n\n\nomega_1=0.10d0/math%pi\nomega_2=0.3d0/math%pi\n\nt = linspace([0.0d0,1000.0d0],1024)\nwave = sin(omega_1*t(:)) * 0.30d0*sin(omega_2*t(:) +2.0d0)* exp(-omega_1/10.0d0*t(:) ) +0.10d0*sin(omega_1*10.0d0*t(:)) \n\ncall f%open(\"input_wave.txt\")\ncall f%write(abs(t),real(wave) )\ncall f%close()\ncall f%plot(option=\"with lines\")\n\nh_top_wave = hilbert(wave)\nh_bottom_wave = hilbert(-wave)\n\ncall f%open(\"ht_wave.txt\")\ncall f%write(abs(t),abs(h_top_wave) )\ncall f%plot(option=\"with lines\")\n\nend ", "meta": {"hexsha": "0045df79e56ed71b0c0b5590f81c3142e8827eb2", "size": 740, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/HilbertTransform.f90", "max_stars_repo_name": "kazulagi/faba", "max_stars_repo_head_hexsha": "7ef140f1ebea0e0ca496d14fdb94a3c024393cfa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-05T06:04:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:04:25.000Z", "max_issues_repo_path": "Tutorial/std/HilbertTransform.f90", "max_issues_repo_name": "kazulagi/plantFEM_binary", "max_issues_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Tutorial/std/HilbertTransform.f90", "max_forks_repo_name": "kazulagi/plantFEM_binary", "max_forks_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.1428571429, "max_line_length": 120, "alphanum_fraction": 0.6851351351, "num_tokens": 282, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898102301019, "lm_q2_score": 0.7490872075132153, "lm_q1q2_score": 0.678665376980695}} {"text": "program main\n use, intrinsic :: iso_c_binding\n\n integer(kind=4), parameter :: max_bits = 128\n integer(kind=4), parameter :: fraction_bits = 30\n integer(kind=4), parameter :: EBIAS = 127\n\n integer(kind=4), dimension(16), parameter :: PERM =&\n & [0, 1, 4, 5, 2, 8, 6, 9, 3, 12, 10, 7, 13, 11, 14, 15]\n\n integer(kind=4), parameter :: NBMASK = Z'aaaaaaaa'\n\n ! Golomb encoding\n integer, parameter :: G_M = 10\n integer, parameter :: G_b = 4\n\n ! Rice encoding\n integer, parameter :: R_k = 3\n integer, parameter :: R_M = 2**R_k\n\n real(kind=4), dimension(4, 4) :: x\n integer, dimension(4, 4) :: e\n integer, dimension(4, 4) :: qint, i\n integer, dimension(16) :: iblock\n integer :: max_exp\n\n ! bitstream\n ! the first bit (pos .eq. 0) : '0' - all values are either non-NaN or NaN\n ! the second bit (pos .eq. 1) : if the first bit is '0' then '0' : non-NaN, '1' : NaN\n integer(kind=16) :: bitstream\n integer :: pos\n integer :: bits\n\n ! loop counters\n integer ix, iy\n\n do iy = 1, 4\n do ix = 1, 4\n x(ix, iy) = ix*iy\n end do\n end do\n\n x(4/2, 4/2) = 6.4\n\n print *, x\n\n e = exponent(x)\n max_exp = maxval(e)\n\n print *, 'e:', e\n print *, 'max_exp:', max_exp\n\n ! clear the bitstream\n bitstream = 0\n pos = 0\n\n ! bitstream = ibset(bitstream, 0)\n ! call mvbits(int(3, kind=16), 0, 3, bitstream, pos)\n\n ! all values are non-NaN, emit '0';\n ! no need to do anything since initially bitstream = 0\n pos = pos + 1\n\n ! emit the biased exponent (8 bits)\n ! call mvbits(int(max_exp + EBIAS, kind=16), 0, 8, bitstream, pos)\n\n bits = max_exp + EBIAS\n write (*, '(a,b32.32)') 'biased max_exp ', bits\n\n call stream_write_bits(bitstream, bits, 8, pos)\n\n ! quantize\n i = e - max_exp + fraction_bits\n qint = nint(set_exponent(x, i))\n iblock = reshape(qint, (/16/))\n\n print *, 'i:', i\n print *, 'iblock:', iblock\n\n ! decorrelate\n call fwd_xform(iblock)\n print *, 'iblock:', iblock\n\n ! reorder signed coefficients and convert to unsigned integer\n call fwd_order(iblock)\n print *, 'ublock:', iblock\n\n ! encode 32-bit integers\n call encode_many_ints(iblock, bitstream, pos)\n\n if (pos .lt. max_bits) then\n call pad_stream(bitstream, max_bits - pos, pos)\n end if\n\n write (*, '(a,b128.128)') 'bitstream ', bitstream\n print *, 'pos', pos\n\n ! reverse the process\n pos = max_bits - 1\n\n ! read the NaN mask bit\n print *, 'NaN mask', stream_read_bit(bitstream, pos)\n\n bits = stream_read_bits(bitstream, pos, 8)\n max_exp = bits - EBIAS\n print *, 'max_exp', max_exp\n\n ! decode 32-bit integers\n call decode_many_ints(iblock, bitstream, pos)\n print *, 'ublock:', iblock\n\n ! reorder unsigned coefficients and convert to signed integer\n call inv_order(iblock)\n print *, 'iblock:', iblock\n\n ! perform decorrelating transform\n call inv_xform(iblock)\n print *, 'iblock:', iblock\n\n ! de-quantize\n qint = reshape(iblock, (/4, 4/))\n\n i = max_exp - fraction_bits\n x = scale(real(qint), i)\n\n print *, x\n\ncontains\n pure subroutine fwd_lift(p, offset, s)\n implicit none\n\n integer, dimension(16), intent(inout) :: p\n integer, intent(in) :: offset, s\n integer :: idx, x, y, z, w\n\n idx = 1 + offset\n\n x = p(idx)\n idx = idx + s\n\n y = p(idx)\n idx = idx + s\n\n z = p(idx)\n idx = idx + s\n\n w = p(idx)\n\n ! non-orthogonal transform\n ! ( 4 4 4 4) (x)\n ! 1/16 * ( 5 1 -1 -5) (y)\n ! (-4 4 4 -4) (z)\n ! (-2 6 -6 2) (w)\n\n ! shiftr does not preserve the sign bit\n ! therefore shifta is used in the code below\n\n x = x + w\n x = shifta(x, 1)\n w = w - x\n z = z + y\n z = shifta(z, 1)\n y = y - z\n x = x + z\n x = shifta(x, 1)\n z = z - x\n w = w + y\n w = shifta(w, 1)\n y = y - w\n w = w + shifta(y, 1)\n y = y - shifta(w, 1)\n\n p(idx) = w\n idx = idx - s\n\n p(idx) = z\n idx = idx - s\n\n p(idx) = y\n idx = idx - s\n\n p(idx) = x\n\n end subroutine fwd_lift\n\n ! inverse lifting transform of 4 - vector\n pure subroutine inv_lift(p, offset, s)\n implicit none\n\n integer, dimension(16), intent(inout) :: p\n integer, intent(in) :: offset, s\n integer :: idx, x, y, z, w\n\n idx = 1 + offset\n\n x = p(idx)\n idx = idx + s\n\n y = p(idx)\n idx = idx + s\n\n z = p(idx)\n idx = idx + s\n\n w = p(idx)\n\n ! non - orthogonal transform\n ! (4 6 - 4 - 1) (x)\n ! 1/4*(4 2 4 5) (y)\n ! (4 - 2 4 - 5) (z)\n ! (4 - 6 - 4 1) (w)\n\n ! shiftr does not preserve the sign bit\n ! therefore shifta is used in the code below\n\n y = y + shifta(w, 1)\n w = w - shifta(y, 1)\n y = y + w\n w = shiftl(w, 1)\n w = w - y\n z = z + x\n x = shiftl(x, 1)\n x = x - z\n y = y + z\n z = shiftl(z, 1)\n z = z - y\n w = w + x\n x = shiftl(x, 1)\n x = x - w\n\n p(idx) = w\n idx = idx - s\n\n p(idx) = z\n idx = idx - s\n\n p(idx) = y\n idx = idx - s\n\n p(idx) = x\n\n end subroutine inv_lift\n\n pure subroutine fwd_xform(p)\n implicit none\n\n integer, dimension(16), intent(inout) :: p\n integer :: x, y\n\n ! transform along x\n do y = 0, 3\n call fwd_lift(p, 4*y, 1)\n end do\n\n ! transform along y\n do x = 0, 3\n call fwd_lift(p, 1*x, 4)\n end do\n\n end subroutine fwd_xform\n\n ! inverse decorrelating 2D transform\n pure subroutine inv_xform(p)\n implicit none\n\n integer, dimension(16), intent(inout) :: p\n integer :: x, y\n\n ! transform along y\n do x = 0, 3\n call inv_lift(p, 1*x, 4)\n end do\n\n ! transform along x\n do y = 0, 3\n call inv_lift(p, 4*y, 1)\n end do\n\n end subroutine inv_xform\n\n ! reorder signed coefficients and convert to unsigned integer\n pure subroutine fwd_order(p)\n implicit none\n\n integer, dimension(16), intent(inout) :: p\n\n ! re-order and convert to unsigned integer\n p = int2uint(p(1 + PERM))\n\n end subroutine fwd_order\n\n ! reorder unsigned coefficients and convert to signed integer\n pure subroutine inv_order(p)\n implicit none\n\n integer, dimension(16), intent(inout) :: p\n\n ! convert to signed integer and re-order\n p(1 + PERM) = uint2int(p)\n\n end subroutine inv_order\n\n ! map two's complement signed integer to negabinary unsigned integer\n elemental integer function int2uint(x)\n implicit none\n\n integer, intent(in) :: x\n\n ! ((uint)x + NBMASK) ^ NBMASK\n int2uint = IEOR(x + NBMASK, NBMASK)\n\n end function int2uint\n\n ! map two's complement signed integer to negabinary unsigned integer\n elemental integer function uint2int(x)\n implicit none\n\n integer, intent(in) :: x\n\n ! (int)((x ^ NBMASK) - NBMASK)\n uint2int = IEOR(x, NBMASK) - NBMASK\n\n end function uint2int\n\n subroutine encode_many_ints(data, stream, pos)\n implicit none\n\n integer, dimension(16), intent(in) :: data\n integer(kind=16), intent(inout) :: stream\n integer, intent(inout) :: pos\n\n integer :: i, k, bit, c, n\n\n ! a counter for runs of '1'\n integer :: bcount\n\n bcount = 0\n n = 0\n\n ! iterate over 32 bits from MSB to LSB\n do k = 31, 0, -1\n print *, 'k', k, 'n', n, 'pos', pos\n\n ! gather / emit up to n bits from the k-th bit plane\n do i = 1, n\n bit = ibits(data(i), k, 1)\n\n ! check if there is space to write\n if (pos .eq. max_bits) return\n call stream_write_bit(stream, bit, pos)\n end do\n\n if (n .eq. 16) cycle\n\n ! reset the '1' bit counter\n bcount = 0\n\n ! count remaining '1's in the k-th bit plane\n do i = n + 1, 16\n bit = ibits(data(i), k, 1)\n\n if (bit .eq. 1) bcount = bcount + 1\n end do\n\n print *, '\"1\" bcount', bcount\n\n ! unary run-length encode the remaining bits\n if (bcount .gt. 0) then\n do c = 1, bcount\n print *, 'c', c\n\n ! emit '1'\n if (pos .eq. max_bits) return\n call stream_write_bit(stream, 1, pos)\n\n ! keep emitting '0' until '1' is encountered\n1001 n = n + 1\n if (n .gt. 16) exit\n\n bit = ibits(data(n), k, 1)\n\n if (pos .eq. max_bits) return\n call stream_write_bit(stream, bit, pos)\n\n if (bit .eq. 0) go to 1001\n end do\n end if\n\n if (n .lt. 16) then\n ! emit '0'\n if (pos .eq. max_bits) return\n call stream_write_bit(stream, 0, pos)\n end if\n\n end do\n\n end subroutine encode_many_ints\n\n subroutine decode_many_ints(data, stream, pos)\n implicit none\n\n integer, dimension(16), intent(out) :: data\n integer(kind=16), intent(in) :: stream\n integer, intent(inout) :: pos\n\n integer :: i, k, bit, c, n\n\n ! a counter for runs of '1'\n integer :: bcount\n\n bcount = 0\n n = 0\n\n ! zero-out the integer data array\n data = 0\n\n ! iterate over 32 bits from MSB to LSB\n do k = 31, 0, -1\n print *, 'k', k, 'n', n, 'pos', pos\n\n ! read the first n bits\n do i = 1, n\n bit = stream_read_bit(stream, pos)\n if (bit .lt. 0) return\n\n if (bit .eq. 1) data(i) = ibset(data(i), k)\n end do\n\n if (n .eq. 16) cycle\n\n ! read one bit, test it for '1'\n1002 bit = stream_read_bit(stream, pos)\n if (bit .lt. 0) return\n\n if (bit .eq. 1) then\n ! keep on reading '0' until '1' is encountered\n\n print *, 'a new sequence starting @', n + 1\n\n1003 bit = stream_read_bit(stream, pos)\n if (bit .lt. 0) return\n\n n = n + 1\n if (n .gt. 16) go to 1004\n\n if (bit .eq. 1) then\n print *, 'setting bit @', n\n data(n) = ibset(data(n), k)\n\n if (n .eq. 16) go to 1004\n\n go to 1002\n else\n go to 1003\n end if\n else\n go to 1004\n end if\n\n1004 continue\n\n end do\n\n end subroutine decode_many_ints\n\n subroutine encode_ints(data, stream, pos)\n implicit none\n\n integer, dimension(16), intent(in) :: data\n integer(kind=16), intent(inout) :: stream\n integer, intent(inout) :: pos\n\n integer(kind=2) :: val, i, k, bit\n\n ! a counter for runs of '0'\n integer :: zcount, status, bit_count\n\n zcount = 0\n bit_count = 0\n\n ! iterate over 32 bits from MSB to LSB\n do k = 31, 0, -1\n print *, 'k', k\n\n val = 0\n ! gather k-plane bits from the input data\n do i = 1, 16\n bit = int(ibits(data(i), k, 1), kind=2)\n ! print *, 'i', i, 'bit', bit, data(i)\n\n if (bit .eq. 1) then\n ! the runs of zeroes has finished\n\n ! Golomb or Rice-encode the zcount\n status = Golomb_encode(stream, pos, zcount)\n if (status .eq. -1) return\n\n ! reset the zeroes counters\n zcount = 0\n else\n zcount = zcount + 1\n end if\n\n bit_count = bit_count + 1\n print *, 'bit_count', bit_count\n\n ! val = ior(shiftl(val, 1), bit)\n end do\n\n ! display the value (validation)\n ! write (*, '(a,i0,a,b16.16)') 'k: ', k, ', val: ', val\n end do\n\n ! flush the encoder\n status = Golomb_encode(stream, pos, zcount)\n\n end subroutine encode_ints\n\n subroutine decode_ints(data, stream, pos)\n implicit none\n\n integer, dimension(16), intent(out) :: data\n integer(kind=16), intent(in) :: stream\n integer, intent(inout) :: pos\n\n integer :: i, k\n\n ! a counter for runs of '0'\n integer :: zcount\n\n data = 0\n zcount = -1\n\n ! iterate over 32 bits from MSB to LSB\n do k = 31, 0, -1\n\n ! set k-plane bits\n do i = 1, 16\n\n ! decode the next zero-run length\n if (zcount .lt. 0) then\n\n zcount = Golomb_decode(stream, pos)\n\n if (zcount .lt. 0) return\n\n print *, 'zcount', zcount\n\n end if\n\n zcount = zcount - 1\n\n if (zcount .lt. 0) then\n ! set the appropriate bit to '1'\n data(i) = ibset(data(i), k)\n end if\n\n end do\n end do\n\n end subroutine decode_ints\n\n integer function Golomb_encode(stream, pos, N)\n implicit none\n\n integer(kind=16), intent(inout) :: stream\n integer, intent(inout) :: pos\n integer, intent(in) :: N\n\n integer :: i, t, nbits\n\n ! quotient, remainder\n integer :: q, r\n\n Golomb_encode = -1\n\n q = N/G_M\n r = modulo(N, G_M)\n\n print *, 'Golomb encoder: N', N, 'pos', pos, 'q', q, 'r', r\n\n ! Quotient Code\n if (q .gt. 0) then\n do i = 1, q\n ! check if there is space to write\n if (pos .eq. max_bits) return\n call stream_write_bit(stream, 1, pos)\n end do\n end if\n\n if (pos .eq. max_bits) return\n\n call stream_write_bit(stream, 0, pos)\n\n ! Remainder Code\n t = 2**G_b - G_M\n\n if (r .lt. t) then\n\n nbits = G_b - 1\n\n print *, 'coding the remainder using', nbits, 'nbits'\n\n ! check if there is space to write\n if (pos + nbits .gt. max_bits) return\n call stream_write_bits(stream, r, nbits, pos)\n\n else\n\n nbits = G_b\n r = r + t\n\n print *, 'coding remainder+', r, 'using', nbits, 'nbits'\n\n ! check if there is space to write\n if (pos + nbits .gt. max_bits) return\n call stream_write_bits(stream, r, nbits, pos)\n\n end if\n\n Golomb_encode = 0\n\n return\n\n end function Golomb_encode\n\n integer function Golomb_decode(stream, pos)\n implicit none\n\n integer(kind=16), intent(in) :: stream\n integer, intent(inout) :: pos\n\n integer :: s, x, bit, t\n\n Golomb_decode = -1\n\n s = 0\n ! count the number of consecutive '1', stop at '0'\n\n do\n bit = stream_read_bit(stream, pos)\n\n if (bit .lt. 0) return\n\n if (bit .eq. 0) exit\n\n s = s + 1\n end do\n\n x = stream_read_bits(stream, pos, G_b - 1)\n\n if (x .lt. 0) return\n\n t = 2**G_b - G_M\n\n if (x .lt. t) then\n Golomb_decode = s*G_M + x\n return\n end if\n\n bit = stream_read_bit(stream, pos)\n\n if (bit .lt. 0) return\n\n x = shiftl(x, 1) + bit\n\n Golomb_decode = s*G_M + x - t\n\n return\n\n end function Golomb_decode\n\n subroutine Rice_encode(stream, pos, N)\n implicit none\n\n integer(kind=16), intent(inout) :: stream\n integer, intent(inout) :: pos\n integer, intent(in) :: N\n\n integer :: i\n\n ! quotient, pseudo-remainder\n integer :: q, r\n\n q = shiftr(N, R_k) ! divide by R_M = 2**R_k\n r = N\n\n print *, 'Rice encoder: N', N, 'pos', pos, 'q', q\n\n ! Quotient Code\n if (q .gt. 0) then\n do i = 1, q\n ! check if there is space to write\n if (pos .eq. max_bits) return\n\n call stream_write_bit(stream, 1, pos)\n end do\n end if\n\n if (pos .eq. max_bits) return\n\n call stream_write_bit(stream, 0, pos)\n\n ! Remainder Code\n ! check if there is space to write\n if (pos + R_k .gt. max_bits) return\n\n call stream_write_bits(stream, r, R_k, pos)\n\n end subroutine Rice_encode\n\n integer function Rice_decode(stream, pos)\n implicit none\n\n integer(kind=16), intent(in) :: stream\n integer, intent(inout) :: pos\n\n integer :: s, x, bit\n\n Rice_decode = -1\n\n s = 0\n ! count the number of consecutive '1', stop at '0'\n\n do\n bit = stream_read_bit(stream, pos)\n\n if (bit .lt. 0) return\n\n if (bit .eq. 0) exit\n\n s = s + 1\n end do\n\n x = stream_read_bits(stream, pos, R_k)\n\n if (x .lt. 0) return\n\n Rice_decode = shiftl(s, R_k) + x\n\n return\n\n end function Rice_decode\n\n subroutine stream_write_bit(stream, bit, pos)\n implicit none\n\n integer(kind=16), intent(inout) :: stream\n integer, intent(in) :: bit\n integer, intent(inout) :: pos\n\n ! make place for the new bit\n stream = shiftl(stream, 1)\n\n ! set the LSB bit\n if (bit .eq. 1) then\n stream = ibset(stream, 0)\n end if\n\n pos = pos + 1\n\n return\n\n end subroutine stream_write_bit\n\n subroutine stream_write_bits(stream, bits, n, pos)\n implicit none\n\n integer(kind=16), intent(inout) :: stream\n integer, intent(inout) :: bits\n integer, intent(in) :: n\n integer, intent(inout) :: pos\n\n integer :: i\n\n if (n .lt. 1) return\n\n stream = shiftl(stream, n)\n\n call mvbits(int(bits, kind=16), 0, n, stream, 0)\n\n pos = pos + n\n\n return\n\n end subroutine stream_write_bits\n\n subroutine pad_stream(stream, n, pos)\n implicit none\n\n integer(kind=16), intent(inout) :: stream\n integer, intent(in) :: n\n integer, intent(inout) :: pos\n\n integer :: i\n\n if (n .lt. 1) return\n\n print *, 'padding the stream with', n, '0 bits'\n\n stream = shiftl(stream, n)\n pos = pos + n\n\n return\n end subroutine pad_stream\n\n integer function stream_read_bit(stream, pos)\n implicit none\n\n integer(kind=16), intent(in) :: stream\n integer, intent(inout) :: pos\n\n if (pos .lt. 0) then\n stream_read_bit = -1\n return\n end if\n\n if (btest(stream, pos)) then\n stream_read_bit = 1\n else\n stream_read_bit = 0\n end if\n\n pos = pos - 1\n\n return\n\n end function stream_read_bit\n\n integer function stream_read_bits(stream, pos, n)\n implicit none\n\n integer(kind=16), intent(in) :: stream\n integer, intent(inout) :: pos\n integer, intent(in) :: n\n\n integer :: i\n\n stream_read_bits = -1\n\n if (n .lt. 1) return\n\n if (pos - n + 1 .lt. 0) return\n\n stream_read_bits = int(ibits(stream, pos - n + 1, n))\n\n pos = pos - n\n\n return\n\n end function stream_read_bits\n\nend program main\n", "meta": {"hexsha": "b673fef6cb9b47a36c9b30d59e3d2505b44d4243", "size": 19681, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/zfp_block_128.f90", "max_stars_repo_name": "jvo203/FITSWEBQLSE", "max_stars_repo_head_hexsha": "3b2b3c74d623c3510cfa81a4e30ac5bd0af48cb0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tests/zfp_block_128.f90", "max_issues_repo_name": "jvo203/FITSWEBQLSE", "max_issues_repo_head_hexsha": "3b2b3c74d623c3510cfa81a4e30ac5bd0af48cb0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/zfp_block_128.f90", "max_forks_repo_name": "jvo203/FITSWEBQLSE", "max_forks_repo_head_hexsha": "3b2b3c74d623c3510cfa81a4e30ac5bd0af48cb0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.0456674473, "max_line_length": 89, "alphanum_fraction": 0.495706519, "num_tokens": 5624, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898127684334, "lm_q2_score": 0.749087201911703, "lm_q1q2_score": 0.6786653738072135}} {"text": "module NewModule\n use iso_fortran_env\n use ArrayClass\n use RandomClass\n use IOClass\n implicit none\n\ncontains\n\n\n\nend module\n\nprogram main\n use LinearSolverClass\n implicit none\n \n integer(int32) :: i\n real(real64),allocatable :: coeff(:),fit_coeff(:)\n real(real64),allocatable :: training_data(:,:)\n real(real64) :: err\n type(IO_) :: f\n\n training_data = zeros(21,2)\n ! input\n training_data(:,1) = linspace([-10.0d0,10.0d0],21)\n ! result\n training_data(:,2) = training_data(:,1)*training_data(:,1)*training_data(:,1) - training_data(:,1) +1.0d0\n\n ! trial : -x^3 + x^2 + x + 1\n coeff = [-1.0d0, 1.0d0, 1.0d0, 1.0d0]\n\n ! fitting by Robbin-Monro algorithm (SGD)\n fit_coeff = fit(f=polynomial, training_data=training_data, params=coeff ,eta=0.000001d0, error=err,logfile=\"SGD.log\")\n\n ! show result\n call f%open(\"training_data.txt\",\"w\")\n do i=1,size(training_data,1)\n call f%write(training_data(i,1), training_data(i,2) )\n enddo\n call f%close()\n\n call f%open(\"SGD_fit.txt\",\"w\")\n do i=-20,20\n call f%write(dble(i), polynomial(x=dble(i),params=fit_coeff ) )\n enddo\n call f%close()\n call f%plot()\n\nend program main\n\n", "meta": {"hexsha": "dbd8543f18170fdfb74b5525ac82ccff61763b8a", "size": 1215, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/Curve_Fitting_By_SGD.f90", "max_stars_repo_name": "kazulagi/faba", "max_stars_repo_head_hexsha": "7ef140f1ebea0e0ca496d14fdb94a3c024393cfa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-05T06:04:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:04:25.000Z", "max_issues_repo_path": "Tutorial/Curve_Fitting_By_SGD.f90", "max_issues_repo_name": "kazulagi/faba", "max_issues_repo_head_hexsha": "7ef140f1ebea0e0ca496d14fdb94a3c024393cfa", "max_issues_repo_licenses": ["MIT"], "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/Curve_Fitting_By_SGD.f90", "max_forks_repo_name": "kazulagi/faba", "max_forks_repo_head_hexsha": "7ef140f1ebea0e0ca496d14fdb94a3c024393cfa", "max_forks_repo_licenses": ["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.3653846154, "max_line_length": 121, "alphanum_fraction": 0.6304526749, "num_tokens": 396, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278726384089, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6786578374865658}} {"text": "SUBROUTINE GridBarnes(f,l,n,b)\n\n!==========================================================\n! This routine applied a Barnes analysis to a gridded two\n! dimensional function as a filter.\n!\n! HISTORY: JAN. 2005 by YUANFU XIE.\n!==========================================================\n\n IMPLICIT NONE\n\n INTEGER, INTENT(IN) :: l(2),n(2)\n REAL, INTENT(IN) :: f(l(1),l(2))\n REAL, INTENT(OUT) :: b(l(1),l(2))\n\n ! Local variables:\n INTEGER :: i,j,ir,ni,nj,ip\n REAL :: gama,s,w,ws,t(l(1),l(2)),tmp\n\n gama = 0.2\n s = 2.0e3/gama ! kapa_0\n ir = 60\t ! neighbors\n \n ! Clean analysis field:\n b = 0.0\n t = 0.0\n\n ! Barnes analysis:\n DO ip=1,1\n\n s = s*gama\n\n ! For every gridpoint:\n DO j=1,n(2)\n DO i=1,n(1)\n\t \n\t ! For each neighbor within ir:\n\t ws = 0.0\n\t tmp = 0.0\n\t DO nj=-ir,ir,2\n\t DO ni=-ir,ir,2\n\t\t w = EXP(-(FLOAT(ni)**2+FLOAT(nj)**2)/s)\n\n\t\t IF ((i+ni .GE. 1) .AND. (i+ni .LE. n(1)) .AND. &\n\t\t (j+nj .GE. 1) .AND. (j+nj .LE. n(2))) THEN\n\t\t tmp = tmp+(f(i+ni,j+nj)-t(i+ni,j+nj))*w\n\t\t ws = ws + w\n\t\t ENDIF\n\n\t ENDDO\n\t ENDDO\n\n\t b(i,j) = b(i,j)+tmp/ws\n ENDDO\n ENDDO\n\n t = b\n\n ENDDO\n\nEND SUBROUTINE GridBarnes\n", "meta": {"hexsha": "4503512f234efef27f17d8095c6cdfa1743e2f92", "size": 1233, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/mesowave/recurs_iter/GridBarnes.f90", "max_stars_repo_name": "maxinye/laps-mirror", "max_stars_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_stars_repo_licenses": ["Intel", "Unlicense", "OLDAP-2.2.1", "NetCDF"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-04-05T12:28:22.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-29T06:37:29.000Z", "max_issues_repo_path": "src/mesowave/recurs_iter/GridBarnes.f90", "max_issues_repo_name": "longwosion/laps-mirror", "max_issues_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_issues_repo_licenses": ["Intel", "NetCDF", "OLDAP-2.2.1", "Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/mesowave/recurs_iter/GridBarnes.f90", "max_forks_repo_name": "longwosion/laps-mirror", "max_forks_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_forks_repo_licenses": ["Intel", "NetCDF", "OLDAP-2.2.1", "Unlicense"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-04-27T12:51:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-19T13:57:44.000Z", "avg_line_length": 19.8870967742, "max_line_length": 59, "alphanum_fraction": 0.4517437145, "num_tokens": 468, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278571786139, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.678657830267229}} {"text": "! CREATED BY ${USER_NAME} ON 11/27/18.\n\nPROGRAM SOLVE_REPRESS\n ! SOLVE CME OF THE REPRESSILATOR\n USE STATESPACE\n USE KRYLOVSOLVER\n IMPLICIT NONE\n\n INTERFACE\n DOUBLE PRECISION FUNCTION CLOCK()\n END FUNCTION CLOCK\n END INTERFACE\n\n DOUBLE PRECISION :: T = 10.0D0, EXP_TOL = 1.0D-14, FSP_TOL = 1.0D-4\n TYPE (CME_MODEL) :: MODEL\n TYPE (FINITE_STATE_PROJECTION) :: FSP_IN, FSP\n DOUBLE PRECISION, DIMENSION(NMAX) :: P0, P\n DOUBLE PRECISION :: TIC\n INTEGER :: I\n\n CALL RANDOM_SEED()\n\n CALL MODEL%CREATE(3, 6, 3)\n MODEL%STOICHIOMETRY = RESHAPE((/1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1/), (/3,6/))\n MODEL%CUSTOMPROP => PROPENSITY\n CALL MODEL%RESET_PARAMETERS([100.0D0, 25.0D0, 1.0D0])\n MODEL%LOADED = .TRUE.\n\n ! INITIALIZE THE ATTRIBUTES OF THE FSP BASED ON THE UNDERLYING MODEL\n TIC = CLOCK()\n WRITE(*,*) 'ALLOCATING MEMORY FOR THE FSP...'\n CALL FSP_IN%CREATE(MODEL)\n CALL FSP%CREATE(MODEL)\n WRITE(*, FMT = 200) CLOCK() - TIC\n\n FSP_IN%SIZE = 1\n FSP_IN%STATE(:, 1) = [22, 0, 0]\n P0(1) = 1.0\n FSP_IN%VECTOR = P0\n FSP = FSP_IN\n TIC = CLOCK()\n WRITE(*,*) 'CALLING THE SOLVER...'\n CALL CME_SOLVE(MODEL, T, FSP_IN, FSP, FSP_TOL, EXP_TOL, VERBOSITY = 1)\n WRITE(*, FMT = 200) CLOCK() - TIC\n200 FORMAT ('ELAPSED TIME :', F10.2)\n\n CALL FSP%CLEAR()\n CALL FSP_IN%CLEAR()\nCONTAINS\n DOUBLE PRECISION FUNCTION PROPENSITY(STATE, REACTION, PARAMETERS)\n INTEGER, INTENT(IN) :: STATE(:), REACTION\n DOUBLE PRECISION, INTENT(IN), OPTIONAL :: PARAMETERS(:)\n\n SELECT CASE (REACTION)\n CASE(1)\n PROPENSITY = PARAMETERS(1)/(1D0 + PARAMETERS(2)*STATE(2)**6.0D0)\n CASE(2)\n PROPENSITY = PARAMETERS(3)*STATE(1)\n CASE(3)\n PROPENSITY = PARAMETERS(1)/(1D0 + PARAMETERS(2)*STATE(3)**6.0D0)\n CASE(4)\n PROPENSITY = PARAMETERS(3)*STATE(2)\n CASE(5)\n PROPENSITY = PARAMETERS(1)/(1D0 + PARAMETERS(2)*STATE(1)**6.0D0)\n CASE(6)\n PROPENSITY = PARAMETERS(3)*STATE(3)\n\n END SELECT\n END FUNCTION PROPENSITY\nEND PROGRAM\n", "meta": {"hexsha": "6f6e381d418904cd8576af370394c27665b4f58d", "size": 1975, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/repressilator.f90", "max_stars_repo_name": "voduchuy/KrylovFspSsa", "max_stars_repo_head_hexsha": "26a6d49982c697b1dec28bfd2cda401ccc4ff745", "max_stars_repo_licenses": ["MIT"], "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/repressilator.f90", "max_issues_repo_name": "voduchuy/KrylovFspSsa", "max_issues_repo_head_hexsha": "26a6d49982c697b1dec28bfd2cda401ccc4ff745", "max_issues_repo_licenses": ["MIT"], "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/repressilator.f90", "max_forks_repo_name": "voduchuy/KrylovFspSsa", "max_forks_repo_head_hexsha": "26a6d49982c697b1dec28bfd2cda401ccc4ff745", "max_forks_repo_licenses": ["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.8169014085, "max_line_length": 84, "alphanum_fraction": 0.6506329114, "num_tokens": 735, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278540866547, "lm_q2_score": 0.7690802264851919, "lm_q1q2_score": 0.6786578138778063}} {"text": " program wavedd\n \n implicit none\n \n integer, parameter :: jprocs = 3, iprocs = 3\n integer, parameter :: isrc=14, jsrc=14\n real(8), parameter :: Lx=1000, Ly=1000, t=2\n real(8), parameter :: CFL=0.5, c=1\n real(8), parameter :: dx=0.1, dy=0.1\n \n integer :: i, j\n integer :: irank\n real(8), dimension(:,:), allocatable :: wn, wnm1\n integer :: ista, iend, jsta, jend\n real(8) :: tt\n integer, parameter :: nxlocal=Lx/dx, nylocal=Ly/dy\n integer, parameter :: nx=nxlocal+2, ny=nylocal+2\n real(8), parameter :: dt=CFL*dx/c\n integer :: curimage(2)\n ! alloc coarray\n real(8), allocatable :: wnp1(:,:)[:,:]\n \n \n allocate(wn(nx,ny))\n allocate(wnp1(nx,ny)[iprocs,*])\n allocate(wnm1(nx,ny))\n \n curimage=this_image(wnp1)\n ! write(*,*) this_image(wnp1)\n sync all\n \n !! Calculation of the wave equation\n wn=0\n wnp1=wn\n tt=0\n \n do while (tt 1) &\n wnp1(1,:)=wnp1(nx-1,:)[curimage(1)-1,curimage(2)]\n if (curimage(1) < iprocs) &\n wnp1(nx,:)=wnp1(2,:)[curimage(1)+1,curimage(2)]\n if (curimage(2)>1) &\n wnp1(:,1)=wnp1(:,ny-1)[curimage(1),curimage(2)-1]\n if (curimage(2) < jprocs) &\n wnp1(:,ny)=wnp1(:,2)[curimage(1),curimage(2)+1] \n \n sync all\n \n ista=2\n jsta=2\n iend=nx-1\n jend=ny-1\n if (curimage(1) == 1) then \n wn(ista,:)=0 \n ista=ista+1\n endif\n if (curimage(1) == iprocs) then \n wn(iend,:)=0 \n iend=iend-1\n endif\n if (curimage(2) == 1) then \n wn(:,jsta)=0 \n jsta=jsta+1\n endif\n if (curimage(2) == jprocs) then \n wn(:,jend)=0\n jend=jend-1\n endif \n \n wnm1=wn\n wn=wnp1\n do i=ista,iend\n do j=jsta,jend\n wnp1(i,j)=2*wn(i,j)-wnm1(i,j)+CFL*CFL*(wn(i+1,j)+wn(i,j+1)-4*wn(i,j)+wn(i-1,j)+wn(i,j-1))\n if (isrc == (curimage(1)-1)*nxlocal+i-1 .and. jsrc == (curimage(2)-1)*nylocal+j-1) then\n wnp1(i,j)=wnp1(i,j)+dt*dt*20*sin(30*3.14*tt/20)\n endif\n enddo\n enddo\n tt=tt+dt\n enddo\n \n ! Display and write the result \n !do irank=1, num_images()\n ! if (irank==this_image()) then\n ! write(*,*) \"image: \", this_image()\n ! write(*,*) wn(2:nx-1,2:ny-1)\n ! open(unit = 1 , file = \"wavedd.txt\", position=\"append\")\n ! write(1,*) wn(2:nx-1,2:ny-1)\n ! close(1)\n ! endif\n ! sync all\n !enddo\n \n end program wavedd\n", "meta": {"hexsha": "9e3f0fb1a02050b62dd09c0c7ec695f630147d0c", "size": 2786, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/MPI_block_wave.f90", "max_stars_repo_name": "quip95/wave_equation", "max_stars_repo_head_hexsha": "05f666cca7b0f4cb6a8844830a49ba847acc0506", "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/MPI_block_wave.f90", "max_issues_repo_name": "quip95/wave_equation", "max_issues_repo_head_hexsha": "05f666cca7b0f4cb6a8844830a49ba847acc0506", "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/MPI_block_wave.f90", "max_forks_repo_name": "quip95/wave_equation", "max_forks_repo_head_hexsha": "05f666cca7b0f4cb6a8844830a49ba847acc0506", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.1414141414, "max_line_length": 105, "alphanum_fraction": 0.4623115578, "num_tokens": 971, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554444, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6786537731300383}} {"text": " function sdist (r0, r1)\nc find distance squared between cartesian points r0 and r1\nc single precision\n dimension r0(3), r1(3)\n sdist = 0\n do 10 i = 1, 3\n sdist = sdist + (r0(i) - r1(i))**2\n 10 continue\n sdist = sqrt(sdist)\n return\n end\n", "meta": {"hexsha": "cef398384fa549b7928768755cac2e02e5f209bd", "size": 291, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/feff6/sdist.f", "max_stars_repo_name": "keechul/ifeffit", "max_stars_repo_head_hexsha": "306444e500cb3ecb1795fcbde9219369b003f1fa", "max_stars_repo_licenses": ["Naumen", "Condor-1.1", "MS-PL"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2016-01-05T21:29:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:59:17.000Z", "max_issues_repo_path": "src/feff6/sdist.f", "max_issues_repo_name": "bruceravel/ifeffit", "max_issues_repo_head_hexsha": "97f6458584e237a6a9e3681bb9b604c9d1ec9743", "max_issues_repo_licenses": ["Naumen", "Condor-1.1", "MS-PL"], "max_issues_count": 17, "max_issues_repo_issues_event_min_datetime": "2015-01-04T18:37:30.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-07T12:06:12.000Z", "max_forks_repo_path": "src/feff6/sdist.f", "max_forks_repo_name": "bruceravel/ifeffit", "max_forks_repo_head_hexsha": "97f6458584e237a6a9e3681bb9b604c9d1ec9743", "max_forks_repo_licenses": ["Naumen", "Condor-1.1", "MS-PL"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2016-01-05T21:29:26.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T13:11:01.000Z", "avg_line_length": 24.25, "max_line_length": 62, "alphanum_fraction": 0.5498281787, "num_tokens": 101, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8856314738181875, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6786537637769084}} {"text": "module global_module\n\n implicit none\n \n ! Time integration\n\n real(kind=8), parameter :: t_end = 0.2d0 ! [s] total simulated time (from 0 to t_end)\n real(kind=8), parameter :: CFL_target = 0.2d0\n\n real(kind=8), parameter :: x_min = -0.5d0 ! [m] \n real(kind=8), parameter :: x_max = 0.5d0 ! [m] \n\n ! Total number of cells (including 4 ghost cells for each side)\n ! (using 4 ghost cells makes it easy to reach higher order accuracy)\n\n integer, parameter :: Nx = 200\n\n logical, parameter :: bool_PERIODIC = .false.\n\n ! Note: we use 4 ghost cells per side. This allows to reach up to 5th order\n ! (with the WENO method)\n real(kind=8), parameter :: dx = (x_max-x_min)/(Nx-8) \n\n ! Order in space\n ! 1: uniform sol in cell, first order in space\n ! 2: MUSCL with TVD slope limiter, second order in space\n ! 3: WENO 3rd order\n ! 5: WENO 5th order\n integer, parameter :: space_order = 3\n\n ! Order in time\n ! 1: forward Euler, first order in time\n ! 2: midpoint Euler, second order in time\n ! 3: explicit TVD Runge-Kutta, third order in time\n integer, parameter :: time_order = 3\n\n ! Space fluxes: choose ONLY one\n logical, parameter :: flux_type_Rusanov = .false.\n logical, parameter :: flux_type_HLL = .true.\n\n ! Utilities\n real(kind=8) :: ws_maxabs ! Global variable, maximum wave speed\n\nend module\n", "meta": {"hexsha": "1ee7a7c7c395a5a0bb6a20fff833d354e0912350", "size": 1330, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "hyper1D/src_hyper1D/global_module.f03", "max_stars_repo_name": "sbocce/hyper2D", "max_stars_repo_head_hexsha": "7d1510ac3947b2c154aa0c09945ff05db4bfc8c4", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2022-02-17T14:26:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T01:56:37.000Z", "max_issues_repo_path": "hyper1D/src_hyper1D/global_module.f03", "max_issues_repo_name": "sbocce/hyper2D", "max_issues_repo_head_hexsha": "7d1510ac3947b2c154aa0c09945ff05db4bfc8c4", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2022-02-28T10:22:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-01T06:25:03.000Z", "max_forks_repo_path": "hyper1D/src_hyper1D/global_module.f03", "max_forks_repo_name": "sbocce/hyper2D", "max_forks_repo_head_hexsha": "7d1510ac3947b2c154aa0c09945ff05db4bfc8c4", "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.5555555556, "max_line_length": 92, "alphanum_fraction": 0.6729323308, "num_tokens": 418, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181875, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.6786537637769083}} {"text": "! RUN: %python %S/test_folding.py %s %flang_fc1\n! Tests folding of TRANSPOSE\nmodule m\n integer, parameter :: matrix(0:1,0:2) = reshape([1,2,3,4,5,6],shape(matrix))\n logical, parameter :: test_transpose_1 = all(transpose(matrix) == reshape([1,3,5,2,4,6],[3,2]))\nend module\n", "meta": {"hexsha": "0fb5f91361774fc370caf9b44fbd93beca2a0097", "size": 274, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "flang/test/Evaluate/folding26.f90", "max_stars_repo_name": "mkinsner/llvm", "max_stars_repo_head_hexsha": "589d48844edb12cd357b3024248b93d64b6760bf", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2338, "max_stars_repo_stars_event_min_datetime": "2018-06-19T17:34:51.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T11:00:37.000Z", "max_issues_repo_path": "flang/test/Evaluate/folding26.f90", "max_issues_repo_name": "mkinsner/llvm", "max_issues_repo_head_hexsha": "589d48844edb12cd357b3024248b93d64b6760bf", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 3740, "max_issues_repo_issues_event_min_datetime": "2019-01-23T15:36:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T22:01:13.000Z", "max_forks_repo_path": "flang/test/Evaluate/folding26.f90", "max_forks_repo_name": "mkinsner/llvm", "max_forks_repo_head_hexsha": "589d48844edb12cd357b3024248b93d64b6760bf", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 500, "max_forks_repo_forks_event_min_datetime": "2019-01-23T07:49:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T02:59:37.000Z", "avg_line_length": 39.1428571429, "max_line_length": 97, "alphanum_fraction": 0.6861313869, "num_tokens": 100, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.6786537591505966}} {"text": "program main_program\nimplicit none\n\ninteger :: n2, n_grid, a, i, k, j, l, n\ninteger, allocatable, dimension(:) :: combination\n\nwrite(*,*) 'm out of n?'\nread(*,*) n2\nread(*,*) n_grid\n\nallocate ( combination(n2) )\nopen(unit=4, file='combination.txt', status='replace', action='write')\n!\ndo i = 1, n2\n combination(i) = i !123\nend do\nwrite(4,*) combination\n!\n!--------------------------------------------------\n!now, we generate all of the other combinations:\n!--------------------------------------------------\n!\n!\na = 2\nk = n2 + 1 !drives the increase of the last integer in the\n! combination, combination(m)\n!\ndo while (combination(1) .lt. (n_grid - n2 + 1))\n if (combination(n2) .lt. n_grid) then\n combination(n2) = k !124 125 135 235\n k = k + 1\n !\n write(4,*) combination\n write(*,*) 'loop1', a, combination\n ! \n else if (combination(n2) .eq. n_grid) then\n do j = 1, n2\n l = n2 - j\n if ( combination(j) .eq. (n_grid - l) ) then\n combination(j-1) = combination(j-1) + 1\n do n = j, n2\n combination(n) = combination(n-1) + 1 !134 145 234 245 \n !345\n end do\n k = combination(n2) + 1\n !\n write(4,*) combination\n write(*,*) 'loop2', a, combination\n !\n exit\n end if\n end do\n end if\n a = a + 1\nend do \n\n\nend program main_program\n", "meta": {"hexsha": "3a3b320eb75b14c7fa790d7bc84c2582fe3d0eaf", "size": 1483, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "find_kth_combination/generate_all_one_by_one.f95", "max_stars_repo_name": "ElenaKusevska/coordinates_on_a_grid", "max_stars_repo_head_hexsha": "6605c76d9c6561fee6eaaa844fb954f7784f623c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "find_kth_combination/generate_all_one_by_one.f95", "max_issues_repo_name": "ElenaKusevska/coordinates_on_a_grid", "max_issues_repo_head_hexsha": "6605c76d9c6561fee6eaaa844fb954f7784f623c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "find_kth_combination/generate_all_one_by_one.f95", "max_forks_repo_name": "ElenaKusevska/coordinates_on_a_grid", "max_forks_repo_head_hexsha": "6605c76d9c6561fee6eaaa844fb954f7784f623c", "max_forks_repo_licenses": ["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.1355932203, "max_line_length": 70, "alphanum_fraction": 0.4814565071, "num_tokens": 428, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736773, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6785963668810602}} {"text": " FUNCTION ratval(x,cof,mm,kk)\r\n INTEGER kk,mm\r\n DOUBLE PRECISION ratval,x,cof(mm+kk+1)\r\n INTEGER j\r\n DOUBLE PRECISION sumd,sumn\r\n sumn=cof(mm+1)\r\n do 11 j=mm,1,-1\r\n sumn=sumn*x+cof(j)\r\n11 continue\r\n sumd=0.d0\r\n do 12 j=mm+kk+1,mm+2,-1\r\n sumd=(sumd+cof(j))*x\r\n12 continue\r\n ratval=sumn/(1.d0+sumd)\r\n return\r\n END\r\n", "meta": {"hexsha": "5e9c1b37d56809478149e67d5a93f64a9af928b1", "size": 393, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/ratval.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/ratval.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/ratval.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.1176470588, "max_line_length": 45, "alphanum_fraction": 0.524173028, "num_tokens": 147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.867035752930664, "lm_q2_score": 0.7826624840223699, "lm_q1q2_score": 0.6785963561249193}} {"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!$xmp nodes p(4,*)\n!$xmp template t(N1,N2)\n!insert directive here\n!insert directive here\n!insert directive here\n!insert directive here\n\n!$xmp loop (i,j) on t(i,j)\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!insert directive here\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!insert directive here\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!insert directives here\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!$xmp loop (i,j) on t(i,j) !add something here\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!$xmp task on p(1,1)\n print *, 'Verification =', value\n!$xmp end task\n \nend program laplace\n", "meta": {"hexsha": "ea50c8a92210d5985c9239447d55f1500e66e457", "size": 1108, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "beginner/2.globalview/xmp_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/xmp_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/xmp_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": 18.1639344262, "max_line_length": 69, "alphanum_fraction": 0.5496389892, "num_tokens": 457, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.867035752930664, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.6785963473341611}} {"text": "FUNCTION erfcc(x)\r\nREAL*8 erfcc,x\r\nREAL*8 t,z\r\nz=abs(x)\r\nt=1./(1.+0.5*z)\r\nerfcc=t*exp(-z*z-1.26551223+t*(1.00002368+t*(.37409196+t* &\r\n& (.09678418+t*(-.18628806+t*(.27886807+t*(-1.13520398+t* &\r\n& (1.48851587+t*(-.82215223+t*.17087277)))))))))\r\nif (x.lt.0.) erfcc=2.-erfcc\r\nreturn\r\nEND\r\n", "meta": {"hexsha": "44cac8e974cc9ca8269f74289fe1a3fb4caac959", "size": 288, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "spear/erfcc.f90", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "spear/erfcc.f90", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "spear/erfcc.f90", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.0, "max_line_length": 60, "alphanum_fraction": 0.6006944444, "num_tokens": 133, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.867035746059157, "lm_q2_score": 0.7826624688140726, "lm_q1q2_score": 0.6785963375607111}} {"text": "program main\n implicit none\n real(8), parameter :: pi = acos(-1.d0), kB = 1.d0\n integer :: clock, n, i\n integer, allocatable :: seed(:)\n\n real(8) :: T = 1.d0, dT = .1d0, T_final = 5.d0, beta\n integer, parameter :: L_x = 32, L_y = 32\n integer :: lattice(0:L_x - 1, 0:L_y - 1)\n integer, parameter :: n_warmup = 100000, n_evol = 100000\n real(8) :: J = 1.d0, B = 0.d0\n real(8) :: M\n\n integer :: x, y\n\n ! seed initialization\n call SYSTEM_CLOCK(clock)\n call RANDOM_SEED(size = n)\n allocate(seed(n))\n do i = 1, n\n seed(i) = clock + 37 * i\n end do\n call RANDOM_SEED(put = seed)\n\n open(unit = 1, file = 'M-T.txt', status = 'unknown')\n\n do while (T < T_final)\n\n ! spin initialization\n beta = 1.d0 / kB / T\n lattice = 1\n ! warm up\n do i = 1, n_warmup\n call EVOLUTION(lattice, L_x, L_y, beta, B, J)\n end do\n open(unit = 2, file = 'lattice.txt', status = 'unknown')\n do x = 0, L_x - 1\n do y = 0, L_y - 1\n write(2,'(3i4)') x, y, lattice(x,y)\n end do\n end do\n close(2)\n\n ! do while (T < T_final)\n beta = 1.d0 / kB / T\n M = 0.d0\n\n ! evolution\n do i = 1, n_evol\n call EVOLUTION(lattice, L_x, L_y, beta, B, J)\n M = M + dble(sum(lattice))\n end do\n M = M / dble(n_evol)\n write(*,'(2f15.5)') T, abs(M)\n write(1,'(2f15.5)') T, abs(M)\n T = T + dT\n end do\n close(1)\nend program main\n\nsubroutine EVOLUTION(lattice, L_x, L_y, beta, B, J)\n implicit none\n integer, intent(in) :: L_x, L_y\n integer, intent(inout) :: lattice(0:L_x - 1, 0:L_y - 1)\n real(8), intent(in) :: beta, B, J\n real(8) :: r\n integer :: x, y\n real(8) :: dE\n\n call RANDOM_NUMBER(r)\n x = floor(r * dble(L_x))\n call RANDOM_NUMBER(r)\n y = floor(r * dble(L_y))\n\n dE = 0.d0\n dE = dE + 2.d0 * J * lattice(x,y) * (lattice(modulo(x - 1, L_x), y)&\n + lattice(modulo(x + 1, L_x), y)&\n + lattice(x, modulo(y - 1, L_y))&\n + lattice(x, modulo(y + 1, L_y)))&\n + 2.d0 * B * dble(lattice(x,y))\n\n call RANDOM_NUMBER(r)\n if (r < exp(-beta * dE)) then\n lattice(x,y) = -lattice(x,y)\n end if\nend subroutine EVOLUTION\n", "meta": {"hexsha": "63458b9794b37e9f9e506a2b3f48a0dabfa1c1cc", "size": 2242, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Week-16-Project/Project/0-2DIsingModel.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-16-Project/Project/0-2DIsingModel.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-16-Project/Project/0-2DIsingModel.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": 25.7701149425, "max_line_length": 72, "alphanum_fraction": 0.5151650312, "num_tokens": 827, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467611766711, "lm_q2_score": 0.7718435030872967, "lm_q1q2_score": 0.6785637158744529}} {"text": "!!# FUNCTION MODULE: \nMODULE FUN_xyINTEGRALY\n\n!!## PURPOSE\n!! Integrates the function $Y$ over a polygon in 2D.\n\n\n!!## METHOD\n!! According to [1], the formula for the integral of $x$ over a polygon\n!! is given by:\n!\n!! $$ S = \\frac{1}{6} \\sum_{i=1}^N ( y_i^2 + y_i x_{i-1} + y_{i-1}^2 )\n!! ( x_i - x_{i-1} ) $$\n!\n!! where the vertices of the polygon are given by $(x_i,y_i)$\n!! for $i=1,...,N$ and $(x_0,y_0)=(x_N,y_N)$.\n\n\n!!## AUTHORS\n!! [jb] John Burkardt\n!! [waw] W. A. Wieselquist\n\n\n!!## MODIFIED\n!! 10 July 2001 [jb]\n!! 14 April 2007 [waw]\n\n\n!!## REFERENCES\n!! [1] SF Bockman,\n!! Generalizing the Formula for Areas of Polygons to Moments,\n!! American Mathematical Society Monthly,\n!! 1989, pages 131-132.\n\n!!## EXTERNAL MODULES\nUSE FUN_Error !!((04-A-FUN_Error.f90))\nUSE FUN_xyAVERAGEY !!((05-A-FUN_xyAVERAGEY.f90))\nUSE FUN_xyINTEGRAL1 !!((06-A-FUN_xyINTEGRAL1.f90))\n\n!!## DEFAULT IMPLICIT\nIMPLICIT NONE\nPRIVATE\n\n!!## PROCEDURE OVERLOADING\nINTERFACE xyINTEGRALY_Pg\n MODULE PROCEDURE xyINTEGRALY_Pg_Rsp\n MODULE PROCEDURE xyINTEGRALY_Pg_Rdp\nEND INTERFACE\n\n!!## PROCEDURE OVERLOADING\nINTERFACE xyINTEGRALY_Ls\n MODULE PROCEDURE xyINTEGRALY_Ls_Rsp\n MODULE PROCEDURE xyINTEGRALY_Ls_Rdp\nEND INTERFACE\n\n!!## PUBLIC ACCESS LIST\nPUBLIC :: xyINTEGRALY_Ls\nPUBLIC :: xyINTEGRALY_Ls_Rsp\nPUBLIC :: xyINTEGRALY_Ls_Rdp\n\n!!## PUBLIC ACCESS LIST\nPUBLIC :: xyINTEGRALY_Pg\nPUBLIC :: xyINTEGRALY_Pg_Rsp\nPUBLIC :: xyINTEGRALY_Pg_Rdp\n\n\n!!## CONTAINED PROCEDURES\nCONTAINS\n\n\n!!### FUNCTION \nFUNCTION xyINTEGRALY_Ls_Rsp( Ls ) RESULT(INTEGRALY)\n\n!!#### LOCAL MAPPINGS\nUSE PAR_Constants_Rsp !!((02-A-PAR_Constants_Rsp.f90))\nUSE KND_IntrinsicTypes,ONLY: KIND_R => KIND_Rsp !!((01-A-KND_IntrinsicTypes.f90))\nINCLUDE \"07-A-FUN_xyINTEGRALY_Ls.f90.hdr\"\n!!--begin--\nINCLUDE \"07-A-FUN_xyINTEGRALY_Ls.f90.bdy\"\n!!--end--\nEND FUNCTION\n\n\n\n!!### FUNCTION \nFUNCTION xyINTEGRALY_Ls_Rdp( Ls ) RESULT(INTEGRALY)\n\n!!#### LOCAL MAPPINGS\nUSE PAR_Constants_Rdp !!((02-A-PAR_Constants_Rdp.f90))\nUSE KND_IntrinsicTypes,ONLY: KIND_R => KIND_Rdp !!((01-A-KND_IntrinsicTypes.f90))\nINCLUDE \"07-A-FUN_xyINTEGRALY_Ls.f90.hdr\"\n!!--begin--\nINCLUDE \"07-A-FUN_xyINTEGRALY_Ls.f90.bdy\"\n!!--end--\nEND FUNCTION\n\n\n\n!!### FUNCTION \nFUNCTION xyINTEGRALY_Pg_Rsp( N , Pg ) RESULT(INTEGRALY)\n\n!!#### LOCAL MAPPINGS\nUSE PAR_Constants_Rsp !!((02-A-PAR_Constants_Rsp.f90))\nUSE KND_IntrinsicTypes,ONLY: KIND_R => KIND_Rsp !!((01-A-KND_IntrinsicTypes.f90))\n\nINCLUDE \"07-A-FUN_xyINTEGRALY_Pg.f90.hdr\"\n\n!!--begin--\nINCLUDE \"07-A-FUN_xyINTEGRALY_Pg.f90.bdy\"\n!!--end--\n\nEND FUNCTION\n\n\n\n!!### FUNCTION \nFUNCTION xyINTEGRALY_Pg_Rdp( N , Pg ) RESULT(INTEGRALY)\n\n!!#### LOCAL MAPPINGS\nUSE PAR_Constants_Rdp !!((02-A-PAR_Constants_Rdp.f90))\nUSE KND_IntrinsicTypes,ONLY: KIND_R => KIND_Rdp !!((01-A-KND_IntrinsicTypes.f90))\n\nINCLUDE \"07-A-FUN_xyINTEGRALY_Pg.f90.hdr\"\n!!--begin--\nINCLUDE \"07-A-FUN_xyINTEGRALY_Pg.f90.bdy\"\n\n!!--end--\nEND FUNCTION\n\n\nEND MODULE\n", "meta": {"hexsha": "9cdf1c337ae73c29b5e52109f4791a4a31cb4e37", "size": 3213, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/07-A-FUN_xyINTEGRALY.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/07-A-FUN_xyINTEGRALY.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/07-A-FUN_xyINTEGRALY.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": 24.3409090909, "max_line_length": 81, "alphanum_fraction": 0.6697790227, "num_tokens": 1073, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467580102419, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6785637134304651}} {"text": "\n PROGRAM FTEX07D\nC\nC This program illustrates the use of CURVS1DP and CURVS2DP to\nC interpolate a smoothing tension spline for data in the plane.\nC\nC Numeber of input data points and interpolation points.\nC\n PARAMETER (NUM_IN=4,NUM_OUT=101)\nC\nC GKS parameters.\nC\n PARAMETER (IERRF=6,LUNIT=2,IWTYPE=1,IWKID=1)\n DOUBLE PRECISION X\n DOUBLE PRECISION Y\n DOUBLE PRECISION XS\n DOUBLE PRECISION YS\n DOUBLE PRECISION XSP\n DOUBLE PRECISION YSP\n DOUBLE PRECISION TEMP\n DOUBLE PRECISION PARAM\n DOUBLE PRECISION XL\n DOUBLE PRECISION YL\n DOUBLE PRECISION XO\n DOUBLE PRECISION YO\n DOUBLE PRECISION XOO\n DOUBLE PRECISION YOO\n DOUBLE PRECISION SIGMA\n DOUBLE PRECISION D\n DOUBLE PRECISION S\n DOUBLE PRECISION EPS\n DOUBLE PRECISION XINC\n DOUBLE PRECISION T\nC\nC Declare arrays.\nC\n DIMENSION X(NUM_IN),Y(NUM_IN)\n DIMENSION XS(NUM_IN),YS(NUM_IN),XSP(NUM_IN),YSP(NUM_IN)\n DIMENSION TEMP(NUM_IN,19),PARAM(NUM_IN),XL(2),YL(2)\n DIMENSION XO(NUM_OUT),YO(NUM_OUT),XOO(NUM_OUT),YOO(NUM_OUT)\nC\nC Specify the original data points in the plane.\nC\n DATA X/0.5D0,-1.5D0,0.5D0,1.5D0/\n DATA Y/1.5D0,0.0D0,-2.5D0,-1.0D0/\nC\nC Tension factor.\nC\n SIGMA = 1.0D0\nC\nC Specify a uniform observational weight (the interpolated\nC curve can be this far away from the original data points)..\nC\n ISW = 1\n D = 0.2D0\nC\nC Smoothing factor (larger values result in smoother curves).\nC\n S = DBLE(NUM_IN)\nC\nC Computational tolerance value.\nC\n EPS = SQRT(2.D0/S)\nC\nC Call CURVS1DP and CURVS2DP to calculate the smoothing spline.\nC\n CALL CURVS1DP(NUM_IN,X,Y,D,ISW,S,EPS,PARAM,XS,YS,XSP,YSP,SIGMA,\n + TEMP,IERR)\nC\n XINC = 1.D0/DBLE(NUM_OUT-1)\n DO 10 I = 1,NUM_OUT\n T = DBLE(I-1)*XINC\n CALL CURVS2DP(T,NUM_IN,PARAM,XS,YS,XSP,YSP,SIGMA,XO(I),YO(I))\n 10 CONTINUE\nC\nC Not use CURVS1DP and CURVS2DP to compute an interpolating tension\nC spline by setting the smoothing parameter to zero.\nC\n S = 0.D0\n EPS = 0.D0\n CALL CURVS1DP(NUM_IN,X,Y,D,ISW,S,EPS,PARAM,XS,YS,XSP,YSP,SIGMA,\n + TEMP,IERR)\nC\n DO 20 I = 1,NUM_OUT\n T = DBLE(I-1)*XINC\n CALL CURVS2DP(T,NUM_IN,PARAM,XS,YS,XSP,YSP,SIGMA,XOO(I),\n + YOO(I))\n 20 CONTINUE\nC\nC This next section plots the data. You must have a double precision\nC version of NCAR Graphics in order for this section to compile and\nC run correctly. For now, it is commented out.\nC\nC Plot the two curves.\nC\nC CALL GOPKS(6,IBUF)\nC CALL GOPWK(IWKID,LUNIT,IWTYPE)\nC CALL GACWK(IWKID)\nC\nC Define colors.\nC\nC CALL GSCR(IWKID,0,1.D0,1.D0,1.D0)\nC CALL GSCR(IWKID,1,0.D0,0.D0,0.D0)\nC CALL GSCR(IWKID,2,1.D0,0.D0,0.D0)\nC CALL GSCR(IWKID,3,0.D0,0.D0,1.D0)\nC\nC Main title.\nC\nC CALL PCSETI('FN',25)\nC CALL PLCHHQ(0.5D0,0.95D0,'Demo for CURVS1DP/CURVS2DP',25.D0,0.D0,\nC + 0.D0)\nC CALL SET(0.1D0,0.95D0,0.2D0,0.90D0,-2.D0,3.D0,-3.D0,2.D0,1)\nC\nC Background grid.\nC\nC CALL GASETI('LTY',1)\nC CALL PCSETI('FN',21)\nC CALL GSPLCI(1)\nC CALL LABMOD('(F4.1)','(F4.1)',4,4,20,20,0,0,0)\nC CALL HALFAX(5,4,5,4,-2.D0,-3.D0,1,1)\nC\nC Plot the smoothing spline in red, and its informational label.\nC\nC CALL GSLWSC(3.D0)\nC CALL GSPLCI(2)\nC CALL GPL(NUM_OUT,XO,YO)\nC XL(1) = 0.250D0\nC XL(2) = 0.750D0\nC YL(1) = 0.625D0\nC YL(2) = 0.625D0\nC CALL GPL(2,XL,YL)\nC CALL PLCHHQ(0.875D0,0.625D0,'Smoothing spline',24.D0,0.D0,-1.D0)\nC\nC Plot the tension spline in blue, and its informational label.\nC\nC CALL GSPLCI(3)\nC CALL GPL(NUM_OUT,XOO,YOO)\nC XL(1) = 0.250D0\nC XL(2) = 0.750D0\nC YL(1) = 0.125D0\nC YL(2) = 0.125D0\nC CALL GPL(2,XL,YL)\nC CALL PLCHHQ(0.875D0,0.125D0,'Tension spline',24.D0,0.D0,-1.D0)\nC\nC Mark the original data with black dots, and label.\nC\nC CALL NGDOTS(X,Y,NUM_IN,0.13D0,1)\nC CALL NGDOTS(0.500D0,-0.375D0,1,0.13D0,1)\nC CALL PLCHHQ(0.875D0,-0.375D0,'Original data points',24.D0,0.D0,\nC + -1.D0)\nC\nC CALL FRAME\nC\nC CALL GDAWK(IWKID)\nC CALL GCLWK(IWKID)\nC CALL GCLKS\nC\n STOP\n END\n", "meta": {"hexsha": "485fb365eb07db41aa96e275e0f7ceb0c38d6f79", "size": 4241, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ngmath/src/examples/efitgrid/ftex07d.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "ngmath/src/examples/efitgrid/ftex07d.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "ngmath/src/examples/efitgrid/ftex07d.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 26.50625, "max_line_length": 72, "alphanum_fraction": 0.6356991276, "num_tokens": 1647, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146761176671, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6785637112604954}} {"text": "! { dg-do run }\n! Check the fix for PR28005, in which the mechanism for dealing\n! with matmul (transpose (a), b) would cause wrong results for\n! matmul (a(i, 1:n), b(1:n, 1:n)).\n!\n! Based on the original testcase contributed by\n! Tobias Burnus \n! \n implicit none\n integer, parameter :: nmax = 3\n integer :: i, n = 2\n integer, dimension(nmax,nmax) :: iB=0 , iC=1\n integer, dimension(nmax,nmax) :: iX1=99, iX2=99, iChk\n iChk = reshape((/30,66,102,36,81,126,42,96,150/),(/3,3/))\n\n! This would give 3, 3, 99\n iB = reshape((/1 ,3 ,0 ,2 ,5 ,0 ,0 ,0 ,0 /),(/3,3/))\n iX1(1:n,1) = matmul( iB(2,1:n),iC(1:n,1:n) )\n\n! This would give 4, 4, 99\n ib(3,1) = 1\n iX2(1:n,1) = matmul( iB(2,1:n),iC(1:n,1:n) )\n\n! Whereas, we should have 8, 8, 99\n if (any (iX1(1:n,1) .ne. (/8, 8, 99/))) call abort ()\n if (any (iX1 .ne. iX2)) call abort ()\n\n! Make sure that the fix does not break transpose temporaries.\n iB = reshape((/(i, i = 1, 9)/),(/3,3/))\n ic = transpose (iB)\n iX1 = transpose (iB)\n iX1 = matmul (iX1, iC)\n iX2 = matmul (transpose (iB), iC)\n if (any (iX1 .ne. iX2)) call abort ()\n if (any (iX1 .ne. iChk)) call abort ()\nend\n", "meta": {"hexsha": "f273e852f52f7cefac862fb38a748165f6ef4ae1", "size": 1218, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/matmul_3.f90", "max_stars_repo_name": "maurizioabba/rose", "max_stars_repo_head_hexsha": "7597292cf14da292bdb9a4ef573001b6c5b9b6c0", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/matmul_3.f90", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/matmul_3.f90", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 32.9189189189, "max_line_length": 63, "alphanum_fraction": 0.5697865353, "num_tokens": 523, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722394, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.6785614912639133}} {"text": "module mesh_module\n use iso_fortran_env\n implicit none\n\ncontains\n\nsubroutine create2DRectMesh(NodCoord, ElemNod, ElemMat,xn, yn, lx, ly)\n real(real64),allocatable,intent(inout) :: NodCoord(:,:)\n integer(int32),allocatable,intent(inout) :: ElemNod(:,:)\n integer(int32),allocatable,intent(inout) :: ElemMat(:)\n\n integer(int32),intent(in) :: xn ! \u8981\u7d20\u5206\u5272\u6570\u3000for X\u65b9\u5411\n integer(int32),intent(in) :: yn ! \u8981\u7d20\u5206\u5272\u6570\u3000for Y\u65b9\u5411\n \n real(real64),intent(in) :: lx ! x\u65b9\u5411\u9577\u3055\n real(real64),intent(in) :: ly ! y\u65b9\u5411\u9577\u3055\n\n real(real64) :: unitx, unity\n\n integer(int32) :: i,j,n\n\n unitx=lx/dble(xn)\n unity=ly/dble(yn)\n \n ! creating rectangular mesh\n allocate(NodCoord( (xn+1)*(yn+1) , 2 ))\n allocate(ElemNod( xn*yn,4) )\n allocate(ElemMat(xn*yn) )\n\n n=0\n do j=1, yn+1\n do i=1, xn+1\n n=n+1\n NodCoord(n,1)=lx/dble(xn)*dble(i-1)\n NodCoord(n,2)=ly/dble(yn)*dble(j-1)\n enddo\n enddo\n \n n=1\n ElemNod(1,1)=1\n ElemNod(1,2)=2\n ElemNod(1,3)=yn+3\n ElemNod(1,4)=yn+2\n ElemNod(2,1)=2\n ElemNod(2,2)=3\n ElemNod(2,3)=yn+4\n ElemNod(2,4)=yn+3\n\n \n n=0\n do j=1, yn\n do i=1, xn\n n=n+1\n ElemNod(n,1)=i + (j-1)*(xn+1)\n ElemNod(n,2)=i+1 + (j-1)*(xn+1)\n ElemNod(n,3)=xn+2+i+ (j-1)*(xn+1)\n ElemNod(n,4)=xn+1+i + (j-1)*(xn+1)\n ElemMat(n)=1\n enddo\n enddo\n\nend subroutine\n\nend module \n\nprogram main\n use iso_fortran_env\n use plantfem\n use mesh_module\n implicit none\n\n real(real64),allocatable :: NodCoord(:,:)\n integer(int32),allocatable :: ElemNod(:,:)\n integer(int32),allocatable :: ElemMat(:)\n\n integer(int32) :: xn=2 ! \u8981\u7d20\u5206\u5272\u6570\u3000for X\u65b9\u5411\n integer(int32) :: yn=2 ! \u8981\u7d20\u5206\u5272\u6570\u3000for Y\u65b9\u5411\n \n real(real64) :: lx=2.0d0 ! x\u65b9\u5411\u9577\u3055\n real(real64) :: ly=2.0d0 ! y\u65b9\u5411\u9577\u3055\n\n\n call create2DRectMesh(NodCoord=NodCoord, ElemNod=ElemNod, ElemMat=ElemMat,&\n xn=xn, yn=yn, lx=lx, ly=ly)\n ! \u6750\u6599\u756a\u53f7\u306e\u307f\u4fee\u6b63\n ElemMat(4)=2\n \n call print(Nodcoord)\n call print(ElemNod)\n call print(ElemMat)\n ! export\n ! ...\u7565\n \nend program main\n", "meta": {"hexsha": "9aab1d4858d3df17853e5c62ef5bbb66b46a6b8f", "size": 2126, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/playon_fem/ex0010_CreateMeshEx2.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/fem/ex0010_CreateMeshEx2.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/fem/ex0010_CreateMeshEx2.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": 22.3789473684, "max_line_length": 79, "alphanum_fraction": 0.5658513641, "num_tokens": 846, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588052782737, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6785529175458729}} {"text": "MODULE mo_poly\n\n ! This module determines wether a 2D point lies inside, outside, or\n ! on the vertice/edge of a 2D polygon\n ! and is part of the JAMS Fortran library.\n !\n ! Written Juliane Mai, July 2012\n ! Modified Maren Goehler, July 2012 - area & center of mass\n\n ! License\n ! -------\n ! This file is part of the JAMS Fortran package, distributed under the MIT License.\n !\n ! Copyright (c) 2012 Juliane Mai\n !\n ! Permission is hereby granted, free of charge, to any person obtaining a copy\n ! of this software and associated documentation files (the \"Software\"), to deal\n ! in the Software without restriction, including without limitation the rights\n ! to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n ! copies of the Software, and to permit persons to whom the Software is\n ! furnished to do so, subject to the following conditions:\n !\n ! The above copyright notice and this permission notice shall be included in all\n ! copies or substantial portions of the Software.\n !\n ! THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n ! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n ! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n ! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n ! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n ! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n ! SOFTWARE.\n\n\n USE mo_kind, ONLY: i4, sp, dp\n USE mo_utils, only: eq, ge, le\n\n IMPLICIT NONE\n\n PUBLIC :: areapoly ! compute the area of a polygon\n PUBLIC :: center_of_mass ! compute the center of mass of a polygon\n PUBLIC :: inpoly ! Test if 2D point is inside, outside or&\n ! on vertice/edge of a 2D polygon\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! areapoly\n\n ! PURPOSE\n ! Function for computing the area of a polygon\n ! The polygon can be convex or not.\n !\n ! The method is only applicable for 2D polygons and points.\n !\n ! http://de.wikipedia.org/wiki/Geometrischer_Schwerpunkt\n !\n ! CALLING SEQUENCE\n ! area = areapoly(coord)\n\n ! INTENT(IN)\n ! real(sp/dp) :: coord(:,2) (x,y) coordinates of edges of the polygon\n\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n ! None\n\n ! INTENT(IN), OPTIONAL\n ! None\n\n ! INTENT(INOUT), OPTIONAL\n ! None\n\n ! INTENT(OUT), OPTIONAL\n ! None\n\n ! RESTRICTIONS\n ! Only available in 2D version\n\n ! EXAMPLE\n ! polygon(:,1) = (/ 1.0_dp,2.0_dp,2.0_dp,1.0_dp /)\n ! polygon(:,2) = (/ 1.0_dp,1.0_dp,2.0_dp,2.0_dp /)\n !\n ! area = areapoly(polygon )\n !\n ! --> area = 1\n !\n ! -> see also example in test directory\n\n ! LITERATURE\n ! http://de.wikipedia.org/wiki/Geometrischer_Schwerpunkt\n\n ! HISTORY\n ! Written, Maren Goehler, July 2012\n INTERFACE areapoly\n MODULE PROCEDURE areapoly_sp, areapoly_dp\n END INTERFACE areapoly\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! center_of_mass\n\n ! PURPOSE\n ! Function for computing the center of mass of a polygon\n ! Computation of polygon area needed for center of mass.\n ! The polygon can be convex or not.\n !\n ! The method is only applicable for 2D polygons and points.\n !\n ! http://de.wikipedia.org/wiki/Geometrischer_Schwerpunkt\n !\n ! A = sum(xiyi+1-xi+1yi)\n ! xs = 1/(6*A) * sum(xi+xi+1)(xiyi+1-xi+1yi)\n ! ys = 1/(6*A) * sum(yi+yi+1)(xiyi+1-xi+1yi)\n\n ! CALLING SEQUENCE\n ! com = center_of_mass(coord)\n\n ! INTENT(IN)\n ! real(sp/dp) :: coord(:,2) (x,y) coordinates of edges of the polygon\n\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n ! None\n\n ! INTENT(IN), OPTIONAL\n ! None\n\n ! INTENT(INOUT), OPTIONAL\n ! None\n\n ! INTENT(OUT), OPTIONAL\n ! None\n\n ! RESTRICTIONS\n ! Only available in 2D version\n\n ! EXAMPLE\n ! polygon(:,1) = (/ 1.0_dp,2.0_dp,2.0_dp,1.0_dp /)\n ! polygon(:,2) = (/ 1.0_dp,1.0_dp,2.0_dp,2.0_dp /)\n !\n ! com = center_of_mass(polygon)\n !\n ! --> com = (/1.5_dp, 1.5_dp/)\n !\n ! -> see also example in test directory\n\n ! LITERATURE\n ! http://de.wikipedia.org/wiki/Geometrischer_Schwerpunkt\n\n ! HISTORY\n ! Written, Maren Goehler, July 2012\n INTERFACE center_of_mass\n MODULE PROCEDURE center_of_mass_sp,center_of_mass_dp\n END INTERFACE center_of_mass\n\n ! ------------------------------------------------------------------\n\n ! NAME\n ! inpoly\n\n ! PURPOSE\n ! Determines whether a 2D point falls in a polygon or is located outside or\n ! lies on a vertex or an edge of the polygon.\n ! The polygon can be convex or not.\n !\n ! The method is only applicable for 2D polygons and points.\n !\n ! The original version of the source code (pnpoly) was implemented by\n ! W. Randolph Franklin. It was insufficiently assigning vertex/edge points.\n\n ! CALLING SEQUENCE\n ! call inpoly( p, coord, inside )\n\n ! INTENT(IN)\n ! real(sp/dp) :: p(2) coordinates of the point in question\n ! real(sp/dp) :: coord(:,2) (x,y) coordinates of edges of the polygon\n\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n ! integer(i4) :: inside whether point is inside (=1), outside (=-1) or\n ! on a vertex/edge of the polygon\n\n ! INTENT(IN), OPTIONAL\n ! None\n\n ! INTENT(INOUT), OPTIONAL\n ! None\n\n ! INTENT(OUT), OPTIONAL\n ! None\n\n ! RESTRICTIONS\n ! Only available in 2D version\n\n ! EXAMPLE\n ! polygon(:,1) = (/ 1.0_dp,2.0_dp,2.0_dp,1.0_dp /)\n ! polygon(:,2) = (/ 1.0_dp,1.0_dp,2.0_dp,2.0_dp /)\n !\n ! point = (/ 1.5, 1.5 /)\n !\n ! call inpoly( point, polygon, inside )\n !\n ! --> inside = 1 ... point is inside the polygon\n !\n ! -> see also example in test directory\n\n ! LITERATURE\n ! http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html\n\n ! HISTORY\n ! Written, Juliane Mai, July 2012\n ! Modified, Juliane Mai, July 2012 - removing GOTO statements\n INTERFACE inpoly\n MODULE PROCEDURE inpoly_dp, inpoly_sp\n END INTERFACE inpoly\n\n ! ------------------------------------------------------------------\n\n PRIVATE\n\n ! ------------------------------------------------------------------\n\nCONTAINS\n\n ! ------------------------------------------------------------------\n\n\n FUNCTION areapoly_dp(coord)\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(:,:), INTENT(IN) :: coord ! Coordinates of the polygon in question\n REAL(dp) :: areapoly_dp\n\n ! Local variables\n INTEGER(i4) :: i,k ! loop\n INTEGER(i4) :: Nedges ! number of coordinates\n REAL(dp) :: xsum ! for summing up\n REAL(dp) :: ysum ! for summing up\n\n xsum = 0.0_dp\n ysum = 0.0_dp\n Nedges = size(coord,1)\n\n do i = 1, Nedges\n if (i .eq. Nedges) then\n k = 1_i4\n else\n k = i + 1_i4\n end if\n xsum = xsum + ( coord(i,1) * coord(k,2) )\n ysum = ysum + ( coord(i,2) * coord(k,1) )\n end do\n\n areapoly_dp = 0.5_sp * (xsum - ysum)\n\n RETURN\n END FUNCTION areapoly_dp\n\n\n FUNCTION areapoly_sp(coord)\n IMPLICIT NONE\n REAL(sp), dimension(:,:), INTENT(IN) :: coord ! Coordinates of the polygon in question\n REAL(sp) :: areapoly_sp\n\n ! Local variables\n INTEGER(i4) :: i,k ! loop\n INTEGER(i4) :: Nedges ! number of coordinates\n REAL(sp) :: xsum ! for summing up\n REAL(sp) :: ysum ! for summing up\n\n xsum = 0.0_sp\n ysum = 0.0_sp\n Nedges = size(coord,1)\n\n do i = 1, Nedges\n if (i .eq. Nedges) then\n k = 1_i4\n else\n k = i + 1_i4\n end if\n xsum = xsum + ( coord(i,1) * coord(k,2) )\n ysum = ysum + ( coord(i,2) * coord(k,1) )\n end do\n\n\n areapoly_sp = 0.5_sp * (xsum - ysum)\n\n END FUNCTION areapoly_sp\n\n ! ------------------------------------------------------------------\n\n ! ------------------------------------------------------------------\n\n FUNCTION center_of_mass_dp(coord)\n IMPLICIT NONE\n\n REAL(dp), dimension(:,:), INTENT(IN) :: coord ! Coordinates of polygon in question\n REAL(dp),dimension(2) :: center_of_mass_dp\n\n ! Local variables\n INTEGER(i4) :: i,k ! loop\n INTEGER(i4) :: Nedges ! number of coordinates\n REAL(dp) :: area ! area of the polygon\n REAL(dp) :: xsum ! for summing up\n REAL(dp) :: ysum ! for summing up\n REAL(dp) :: hotspot_x ! for summing up\n REAL(dp) :: hotspot_y ! for summing up\n\n xsum = 0.0_dp\n ysum = 0.0_dp\n Nedges = size(coord,1)\n\n area = areapoly_dp(coord)\n\n do i = 1, Nedges\n if (i .eq. Nedges ) then\n k = 1_i4\n else\n k = i + 1_i4\n end if\n ! multiply x coord by the y coord of next vertex\n xsum = xsum + ((coord(i,1) + coord(k,1)) * &\n ((coord(i,1) * coord(k,2) - coord(k,1) * coord(i,2))))\n\n ysum = ysum + ((coord(i,2) + coord(k,2)) * &\n ((coord(i,1) * coord(k,2) - coord(k,1) * coord(i,2))))\n end do\n\n hotspot_x = 1.0_dp / (6.0_dp * area) * xsum\n hotspot_y = 1.0_dp / (6.0_dp * area) * ysum\n\n center_of_mass_dp(1) = hotspot_x\n center_of_mass_dp(2) = hotspot_y\n\n RETURN\n END FUNCTION center_of_mass_dp\n\n\n FUNCTION center_of_mass_sp(coord)\n IMPLICIT NONE\n\n REAL(sp),dimension(:,:), INTENT(IN) :: coord ! Coordinates of polygon in question\n REAL(sp),dimension(2) :: center_of_mass_sp\n\n ! Local variables\n INTEGER(i4) :: i,k ! loop\n INTEGER(i4) :: Nedges ! number of coordinates\n REAL(sp) :: area ! area of the polygon\n REAL(sp) :: xsum ! for summing up\n REAL(sp) :: ysum ! for summing up\n REAL(sp) :: hotspot_x ! for summing up\n REAL(sp) :: hotspot_y ! for summing up\n\n xsum = 0.0_sp\n ysum = 0.0_sp\n Nedges = size(coord,1)\n\n area = areapoly_sp(coord)\n\n do i = 1, Nedges\n if (i .eq. Nedges ) then\n k = 1_i4\n else\n k = i + 1_i4\n end if\n ! multiply x coord by the y coord of next vertex\n xsum = xsum + ((coord(i,1) + coord(k,1)) * &\n ((coord(i,1) * coord(k,2) - coord(k,1) * coord(i,2))))\n\n ysum = ysum + ((coord(i,2) + coord(k,2)) * &\n ((coord(i,1) * coord(k,2) - coord(k,1) * coord(i,2))))\n end do\n\n hotspot_x = 1.0_sp / (6.0_sp * area) * xsum\n hotspot_y = 1.0_sp / (6.0_sp * area) * ysum\n\n center_of_mass_sp(1) = hotspot_x\n center_of_mass_sp(2) = hotspot_y\n\n RETURN\n END FUNCTION center_of_mass_sp\n\n ! ------------------------------------------------------------------\n\n SUBROUTINE inpoly_dp(P,coord,erg)\n !\n REAL(dp), dimension(2), INTENT(IN) :: P ! Point in question\n REAL(dp), dimension(:,:), INTENT(IN) :: coord ! Coordinates of the polygon\n INTEGER(i4), INTENT(OUT) :: erg ! Result:\n ! inside: erg = 1\n ! outside: erg = -1\n ! on vertex/edge: erg = 0\n\n ! Local variables\n REAL(dp), dimension(:), allocatable :: X, Y\n REAL(dp) :: lx, ly\n LOGICAL :: MX,MY,NX,NY, test1, test2\n INTEGER(i4) :: N, I, J\n\n N = size(coord,1)\n allocate(x(N))\n allocate(y(N))\n\n do i=1,N\n X(I)=coord(I,1)-P(1)\n Y(I)=coord(I,2)-P(2)\n ! Edge\n if ( eq(X(I),0.0_dp) .and. eq(Y(I),0.0_dp) ) then\n erg=0_i4\n return\n end if\n end do\n\n erg=-1_i4\n\n DO I=1,N\n J=1+MOD(I,N)\n ! vertical Vertex\n If ( eq(coord(I,1),coord(J,1)) .and. eq(coord(I,1),P(1)) ) then\n ly = (P(2)-coord(J,2)) / (coord(I,2)-coord(J,2))\n If ( ge(ly,0.0_dp) .and. le(ly,1.0_dp) ) then\n erg=0_i4\n return\n end if\n end if\n ! horizontal Vertex\n If ( eq(coord(I,2),coord(J,2)) .and. eq(coord(I,2),P(2)) ) then\n lx = (P(1)-coord(J,1)) / (coord(I,1)-coord(J,1))\n If ( ge(lx,0.0_dp ) .and. le(lx,1.0_dp) ) then\n erg=0_i4\n return\n end if\n end if\n !\n MX = ge(X(I),0.0_dp)\n NX = ge(X(J),0.0_dp)\n MY = ge(Y(I),0.0_dp)\n NY = ge(Y(J),0.0_dp)\n\n test1 = .NOT.((MY.OR.NY).AND.(MX.OR.NX)).OR.(MX.AND.NX)\n test2 = .NOT.(MY.AND.NY.AND.(MX.OR.NX).AND..NOT.(MX.AND.NX))\n\n if (.not. test1) then\n if (test2) then\n IF ((Y(I)*X(J)-X(I)*Y(J))/(X(J)-X(I)) .lt. 0.0_dp) then\n cycle\n ELSE\n IF ((Y(I)*X(J)-X(I)*Y(J))/(X(J)-X(I)) .gt. 0.0_dp) then\n erg = -erg\n cycle\n ELSE\n erg = 0_i4\n return\n END IF\n END IF\n else\n erg=-erg\n end if\n end if\n\n END DO\n\n deallocate(x)\n deallocate(y)\n\n END SUBROUTINE inpoly_dp\n\n SUBROUTINE inpoly_sp(P,coord,erg)\n !\n REAL(sp), dimension(2), INTENT(IN) :: P ! Point in question\n REAL(sp), dimension(:,:), INTENT(IN) :: coord ! Coordinates of the polygon\n INTEGER(i4), INTENT(OUT) :: erg ! Result:\n ! inside: erg = 1\n ! outside: erg = -1\n ! on vertex/edge: erg = 0\n\n ! Local variables\n REAL(sp), dimension(:), allocatable :: X, Y\n REAL(sp) :: lx, ly\n LOGICAL :: MX,MY,NX,NY, test1, test2\n INTEGER(i4) :: N, I, J\n\n N = size(coord,1)\n allocate(x(N))\n allocate(y(N))\n\n do i=1,N\n X(I)=coord(I,1)-P(1)\n Y(I)=coord(I,2)-P(2)\n ! Edge\n if ( eq(X(I),0.0_sp) .and. eq(Y(I),0.0_sp) ) then\n erg=0_i4\n return\n end if\n end do\n\n erg=-1_i4\n\n DO I=1,N\n J=1+MOD(I,N)\n ! vertical Vertex\n If ( eq(coord(I,1),coord(J,1)) .and. eq(coord(I,1),P(1)) ) then\n ly = (P(2)-coord(J,2)) / (coord(I,2)-coord(J,2))\n If ( ge(ly,0.0_sp) .and. le(ly,1.0_sp) ) then\n erg=0_i4\n return\n end if\n end if\n ! horizontal Vertex\n If ( eq(coord(I,2),coord(J,2)) .and. eq(coord(I,2),P(2)) ) then\n lx = (P(1)-coord(J,1)) / (coord(I,1)-coord(J,1))\n If ( ge(lx,0.0_sp ) .and. le(lx,1.0_sp) ) then\n erg=0_i4\n return\n end if\n end if\n !\n MX = ge(X(I),0.0_sp)\n NX = ge(X(J),0.0_sp)\n MY = ge(Y(I),0.0_sp)\n NY = ge(Y(J),0.0_sp)\n\n test1 = .NOT.((MY.OR.NY).AND.(MX.OR.NX)).OR.(MX.AND.NX)\n test2 = .NOT.(MY.AND.NY.AND.(MX.OR.NX).AND..NOT.(MX.AND.NX))\n\n if (.not. test1) then\n if (test2) then\n IF ((Y(I)*X(J)-X(I)*Y(J))/(X(J)-X(I)) .lt. 0.0_sp) then\n cycle\n ELSE\n IF ((Y(I)*X(J)-X(I)*Y(J))/(X(J)-X(I)) .gt. 0.0_sp) then\n erg = -erg\n cycle\n ELSE\n erg = 0_i4\n return\n END IF\n END IF\n else\n erg=-erg\n end if\n end if\n\n END DO\n\n deallocate(x)\n deallocate(y)\n\n END SUBROUTINE inpoly_sp\n\nEND MODULE mo_poly\n", "meta": {"hexsha": "6e1531418f71a8a0bcb37a1a531914d0a7a61a59", "size": 16779, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mo_poly.f90", "max_stars_repo_name": "mcuntz/jams_fortran", "max_stars_repo_head_hexsha": "a1dcab78eda21f930aa6c8c3633598a522f01659", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2020-02-28T00:14:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-20T23:32:41.000Z", "max_issues_repo_path": "mo_poly.f90", "max_issues_repo_name": "mcuntz/jams_fortran", "max_issues_repo_head_hexsha": "a1dcab78eda21f930aa6c8c3633598a522f01659", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-05-09T15:33:11.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-28T16:16:09.000Z", "max_forks_repo_path": "mo_poly.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": 29.9625, "max_line_length": 107, "alphanum_fraction": 0.4756540914, "num_tokens": 4886, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587905460027, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.6785529158638998}} {"text": "FUNCTION huc1(bwtdmx,bwtdmn,bctmax,bctmin)\n!\nIMPLICIT NONE\n!\n! Function arguments\n!\nREAL :: bctmax,bctmin,bwtdmn,bwtdmx\nREAL :: huc1\n!\n! Local variables\n!\nREAL :: heatunit\n!\n! author : amare retta\n! + + + purpose + + +\n! calculate single day heat units for given temperatures\n \n! + + + keywords + + +\n! heat units, daylength\n \n! + + + argument declarations + + +\n \n! + + + argument definitions + + +\n! bctmax - maximum crop growth temperature. Debe assumed this definition\n! bctmin - minimum crop growth temperature\n! bctopt - optimum crop growth temperature. Not currently used.\n! bwtdmn - daily minimum air temperature\n! bwtdmx - daily maximum air temperature\n! huc1 - returns the value of hte function. Debe assumed this definition\n\n! + + + local variable definitions + + +\n! heatunit - a function. This variable holds the value returned by \n! the Heatunit function. Debe assumed this definition\n\n! + + + output formats + + +\n!2000 format('+',109x,2(f8.2,1x))\n \n! + + + function declarations + + +\n \n! + + + end of specifications + + +\n \nhuc1 = heatunit(bwtdmx,bwtdmn,bctmin) - heatunit(bwtdmx,bwtdmn,bctmax)\nIF (huc1.LT.0.) huc1 = 0.\n! \nEND FUNCTION huc1\n", "meta": {"hexsha": "75a933df4a747de75f263659e8508aebaa160ea7", "size": 1246, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Project Documents/Source Code Original/Huc1.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/Huc1.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/Huc1.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": 27.0869565217, "max_line_length": 76, "alphanum_fraction": 0.6444622793, "num_tokens": 367, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995482, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6785529088313913}} {"text": "subroutine clawpack46_inlinelimiter(maxm,meqn,mwaves,mbc, & \n mx,wave,s,mthlim)\n!! =====================================================\n\n!! # Apply a limiter to the waves.\n!!\n!! # Version of December, 2002.\n!! # Modified from the original CLAWPACK routine to eliminate calls\n!! # to philim. Since philim was called for every wave at each cell\n!! # interface, this was adding substantial overhead in some cases.\n!!\n!! # The limiter is computed by comparing the 2-norm of each wave with\n!! # the projection of the wave from the interface to the left or\n!! # right onto the current wave. For a linear system this would\n!! # correspond to comparing the norms of the two waves. For a\n!! # nonlinear problem the eigenvectors are not colinear and so the\n!! # projection is needed to provide more limiting in the case where the\n!! # neighboring wave has large norm but points in a different direction\n!! # in phase space.\n!!\n!! # The specific limiter used in each family is determined by the\n!! # value of the corresponding element of the array mthlim.\n!! # Note that a different limiter may be used in each wave family.\n!!\n!! # dotl and dotr denote the inner product of wave with the wave to\n!! # the left or right. The norm of the projections onto the wave are then\n!! # given by dotl/wnorm2 and dotr/wnorm2, where wnorm2 is the 2-norm\n!! # of wave.\n\n implicit none\n\n integer :: maxm, meqn, mwaves, mbc, mx\n integer :: mthlim(mwaves)\n\n double precision :: wave(meqn,mwaves,1-mbc:maxm+mbc)\n double precision :: s(mwaves,1-mbc:maxm+mbc)\n\n integer :: mw,i, m\n double precision :: dotr, wnorm2, dotl, r, c, th\n double precision :: wlimitr\n\n wave_loop : do mw = 1,mwaves\n if (mthlim(mw) .eq. 0) then \n continue\n endif\n dotr = 0.d0\n i_loop : do i = 0, mx+1\n wnorm2 = 0.d0\n dotl = dotr\n dotr = 0.d0\n do m = 1,meqn\n wnorm2 = wnorm2 + wave(m,mw,i)**2\n dotr = dotr + wave(m,mw,i)*wave(m,mw,i+1)\n end do\n\n if (i .eq. 0 .or. wnorm2 .eq. 0) then\n cycle\n endif\n\n !! if (i .gt. 0 .and. wnorm2 .ne. 0) then\n if (s(mw,i) .gt. 0.d0) then\n r = dotl / wnorm2\n else\n r = dotr / wnorm2\n endif \n\n !! go to (10,20,30,40,50) mthlim(mw)\n wlimitr = 1.0\n if (mthlim(mw) .eq. 1) then\n !! 10 continue \n !! --------\n !! # minmod\n !! --------\n wlimitr = max(0., min(1., r))\n !! go to 170\n elseif (mthlim(mw) .eq. 2) then\n !! 20 continue\n !! ----------\n !! # superbee\n !! ----------\n wlimitr = max(0., min(1., 2.*r), min(2., r))\n !! go to 170\n elseif (mthlim(mw) .eq. 3) then\n !! 30 continue\n !! ----------\n !! # van Leer\n !! ----------\n wlimitr = (r + dabs(r)) / (1.d0 + dabs(r))\n !! go to 170\n elseif (mthlim(mw) .eq. 4) then\n !! 40 continue\n !! ------------------------------\n !! # monotinized centered\n !! ------------------------------\n c = (1.d0 + r)/2.d0\n wlimitr = dmax1(0.d0, dmin1(c, 2.d0, 2.d0*r))\n !! go to 170\n elseif (mthlim(mw) .eq. 5) then\n !! 50 continue\n !! ------------------------------\n !! # Beam-Warming\n !! ------------------------------\n wlimitr = r\n !! go to 170\n elseif (mthlim(mw) .eq. 6) then\n !! 60 continue\n !! ------------------------------\n !! # Generalized minmod\n !! ------------------------------\n th = 1.3\n wlimitr = dmax1(0.d0, dmin1(th*r,(1+r)/2.d0,th));\n !! go to 170\n endif\n\n!! 170 continue\n\n !! # apply limiter to waves:c\n do m = 1,meqn\n wave(m,mw,i) = wlimitr * wave(m,mw,i)\n end do\n end do i_loop\n end do wave_loop\n\n return\nend subroutine clawpack46_inlinelimiter\n", "meta": {"hexsha": "3acb3881e5444599370d5c49eaae28c8f3a5a42a", "size": 4465, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/solvers/fc3d_clawpack46/fortran_source/fc3d_clawpack46_inlinelimiter.f90", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/solvers/fc3d_clawpack46/fortran_source/fc3d_clawpack46_inlinelimiter.f90", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-08-02T09:52:43.000Z", "max_issues_repo_issues_event_max_datetime": "2017-08-02T14:16:23.000Z", "max_forks_repo_path": "src/solvers/fc3d_clawpack46/fortran_source/fc3d_clawpack46_inlinelimiter.f90", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "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": 35.4365079365, "max_line_length": 75, "alphanum_fraction": 0.4470324748, "num_tokens": 1200, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587817066392, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6785528995493127}} {"text": "subroutine pTuberiaSimple()\n use metodosLineales\n use messages\n implicit none\n !variables externas\n real:: Q, l, zy, ks, d, Sigma_km, nu\n !Variables externas no en el diagrama\n real:: H, p, E\n \n !variables internas\n integer :: i, Re, selection\n real:: v,Sigma_hm,ksd, f,hf, Pot,A\n character :: option\n !Parametros\n real, parameter :: pi = 4 * atan (1.0), g = 9.81, p_agua = 999.1\n \n \n print *, char(10),\" <<<<2: Potencia de Tuberia Simple>>>>\",char(10)\n \n !Etapa de lectura\n Q = 0.042;l=970;zy =16;ks=1.5e-6; d=6*0.0254;Sigma_km=9.4;nu = 1.14e-6\n write(*,*) \"Por defecto, se cargaran datos del ejemplo 2.2\",char(10)\n do i = 1,10\n print datosEjercicio2, Q, l, zy, ks, d, Sigma_km, nu\n \n write (*,'(a)',ADVANCE=\"NO\") \"Desea continuar con estos datos (y/n)? \"\n read(*,*) option\n if (option == 'y')then \n exit\n else\n write(*,*) char(10),\"introduzca los valores(7) como un vector con el sgte formato: \"\n print*,\"Q, l, zy, ks, d, Sigma_km, nu\"\n read(*,*)Q, l, zy, ks, d, Sigma_km, nu !DEBUG\n print*, char(10)\n end if\n end do\n \n \n !Calcular v, velocidad\n A = pi/4 * d**2\n v = Q /A\n \n !Calcular Sigma_hm, perdidas menores\n Sigma_hm = Sigma_km * ((v ** 2) / (2 * g))\n \n !Calcular Re y ksd\n Re = v * d / nu\n \n ksd = Ks / d\n \n !Calcular f con metodo numerico ecuacion 1.67\n print \"(a6,a18,a18,a12,a12)\",\"A\",\"v\",\"Sigma_hm\",\"Re\",\"ksd\"\n write(*,*)A,v,Sigma_hm,Re,ksd,char(10)\n \n print *, \"1- Newton\"\n print *, \"2- Newton-Rapson\"\n \n do while (.true.)\n write (*,'(a)',ADVANCE=\"NO\") \">Seleccione una opcion y presione ENTER (1 + ENTER): \"\n read(*,*) selection\n select case (selection)\n case (1)\n f= friccion1Pto(ksd,Re,0.001)\n exit\n case (2)\n f = friccionNewtonRapshon(ksd,Re,0.001)\n exit\n case default \n print *, \"caso no contemplado\"\n end select \n \n end do\n \n \n \n \n !Calcular h con 1.36\n hf = f * (l / d) * ((v ** 2) / (2 * g))\n \n !Calcular Htotal\n H = zy + hf + Sigma_hm\n \n print *, char(10) \n print \"(a6,a18,a12,a12)\",\"f\",\"hf\",\"H\"\n write(*,*)f,hf,H,char(10)\n !Potencia\n Pot = p_agua * Q * g * H\n \n !Imprimir\n write(*,*) \"P= \",Pot,\" W\"\n write(*,*) \"P= \",Pot/1000,\" kW\"\n read(*,*)\n \n \n \n end subroutine pTuberiaSimple", "meta": {"hexsha": "79ba0bc0174c84eb0a2ec65ab69a340e9360fde7", "size": 2832, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/pTuberiaSimple.f90", "max_stars_repo_name": "Athesto/Design_Pipes", "max_stars_repo_head_hexsha": "9ba0a33a2fcff295ea3d5c6bc582943ebc899afb", "max_stars_repo_licenses": ["MIT"], "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/pTuberiaSimple.f90", "max_issues_repo_name": "Athesto/Design_Pipes", "max_issues_repo_head_hexsha": "9ba0a33a2fcff295ea3d5c6bc582943ebc899afb", "max_issues_repo_licenses": ["MIT"], "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/pTuberiaSimple.f90", "max_forks_repo_name": "Athesto/Design_Pipes", "max_forks_repo_head_hexsha": "9ba0a33a2fcff295ea3d5c6bc582943ebc899afb", "max_forks_repo_licenses": ["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.5, "max_line_length": 96, "alphanum_fraction": 0.4523305085, "num_tokens": 879, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587817066392, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6785528947663744}} {"text": "\tFUNCTION PS_CTOT ( td850, t500 )\nC************************************************************************\nC* PS_CTOT\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes the cross totals index:\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* CTOT = TD850 - T500 \t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PS_CTOT ( TD850, T500 )\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*\tTD850\t\tREAL\t\t850 mb dewpoint in Celsius\t*\nC*\tT500\t\tREAL\t\t500 mb temperature in Celsius\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPS_CTOT\t\tREAL\t\tCross totals index\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* M. Goodman/RDS\t11/84\tOriginal source\t\t\t\t*\nC* M. desJardins/GSFC\t 3/88\tDocumentation\t\t\t\t*\nC************************************************************************\n INCLUDE 'GEMPRM.PRM'\n INCLUDE 'ERMISS.FNC'\nC------------------------------------------------------------------------------\n\tIF ( ERMISS (td850) .or. ERMISS (t500) ) THEN\n\t PS_CTOT = RMISSD\n\t ELSE\nC\nC*\t Compute the cross totals index by subtracting 500 mb \nC*\t temperature from the 850 mb dewpoint.\nC\n\t PS_CTOT = td850 - t500\n\tEND IF\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "9fa9df7d24565675faecb0634af0c6d9fc1f389a", "size": 1104, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/ps/psctot.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/ps/psctot.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/ps/psctot.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.8378378378, "max_line_length": 79, "alphanum_fraction": 0.4501811594, "num_tokens": 323, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587817066392, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6785528947663744}} {"text": " SUBROUTINE MB04SU( M, N, A, LDA, B, LDB, CS, TAU, DWORK, LDWORK,\n $ INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute a symplectic QR decomposition of a real 2M-by-N matrix\nC [A; B],\nC\nC [ A ] [ R11 R12 ]\nC [ ] = Q * R = Q [ ],\nC [ B ] [ R21 R22 ]\nC\nC where Q is a symplectic orthogonal matrix, R11 is upper triangular\nC and R21 is strictly upper triangular.\nC If [A; B] is symplectic then, theoretically, R21 = 0 and\nC R22 = inv(R11)^T. Unblocked version.\nC\nC ARGUMENTS\nC\nC Input/Output Parameters\nC\nC M (input) INTEGER\nC The number of rows of A and B. M >= 0.\nC\nC N (input) INTEGER\nC The number of columns of A and B. N >= 0.\nC\nC A (input/output) DOUBLE PRECISION array, dimension (LDA,N)\nC On entry, the leading M-by-N part of this array must\nC contain the matrix A.\nC On exit, the leading M-by-N part of this array contains\nC the matrix [ R11 R12 ] and, in the zero parts of R,\nC information about the elementary reflectors used to\nC compute the symplectic QR decomposition.\nC\nC LDA INTEGER\nC The leading dimension of the array A. LDA >= MAX(1,M).\nC\nC B (input/output) DOUBLE PRECISION array, dimension (LDB,N)\nC On entry, the leading M-by-N part of this array must\nC contain the matrix B.\nC On exit, the leading M-by-N part of this array contains\nC the matrix [ R21 R22 ] and, in the zero parts of B,\nC information about the elementary reflectors used to\nC compute the symplectic QR decomposition.\nC\nC LDB INTEGER\nC The leading dimension of the array B. LDB >= MAX(1,M).\nC\nC CS (output) DOUBLE PRECISION array, dimension (2 * min(M,N))\nC On exit, the first 2*min(M,N) elements of this array\nC contain the cosines and sines of the symplectic Givens\nC rotations used to compute the symplectic QR decomposition.\nC\nC TAU (output) DOUBLE PRECISION array, dimension (min(M,N))\nC On exit, the first min(M,N) elements of this array\nC contain the scalar factors of some of the elementary\nC reflectors.\nC\nC Workspace\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0, DWORK(1) returns the optimal\nC value of LDWORK.\nC On exit, if INFO = -10, DWORK(1) returns the minimum\nC value of LDWORK.\nC\nC LDWORK INTEGER\nC The length of the array DWORK. LDWORK >= MAX(1,N).\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value.\nC\nC METHOD\nC\nC The matrix Q is represented as a product of symplectic reflectors\nC and Givens rotations\nC\nC Q = diag( H(1),H(1) ) G(1) diag( F(1),F(1) )\nC diag( H(2),H(2) ) G(2) diag( F(2),F(2) )\nC ....\nC diag( H(k),H(k) ) G(k) diag( F(k),F(k) ),\nC\nC where k = min(m,n).\nC\nC Each H(i) has the form\nC\nC H(i) = I - tau * w * w'\nC\nC where tau is a real scalar, and w is a real vector with\nC w(1:i-1) = 0 and w(i) = 1; w(i+1:m) is stored on exit in\nC B(i+1:m,i), and tau in B(i,i).\nC\nC Each F(i) has the form\nC\nC F(i) = I - nu * v * v'\nC\nC where nu is a real scalar, and v is a real vector with\nC v(1:i-1) = 0 and v(i) = 1; v(i+1:m) is stored on exit in\nC A(i+1:m,i), and nu in TAU(i).\nC\nC Each G(i) is a Givens rotation acting on rows i of A and B,\nC where the cosine is stored in CS(2*i-1) and the sine in\nC CS(2*i).\nC\nC REFERENCES\nC\nC [1] Bunse-Gerstner, A.\nC Matrix factorizations for symplectic QR-like methods.\nC Linear Algebra Appl., 83, pp. 49-77, 1986.\nC\nC [2] Byers, R.\nC Hamiltonian and Symplectic Algorithms for the Algebraic\nC Riccati Equation.\nC Ph.D. Dissertation, Center for Applied Mathematics,\nC Cornell University, Ithaca, NY, 1983.\nC\nC NUMERICAL ASPECTS\nC\nC The algorithm requires\nC 8*M*N*N - 8/3*N*N*N + 2*M*N + 6*N*N + 8/3*N, if M >= N,\nC 8*M*M*N - 8/3*M*M*M + 14*M*N - 6*M*M + 8/3*N, if M <= N,\nC floating point operations and is numerically backward stable.\nC\nC CONTRIBUTORS\nC\nC D. Kressner, Technical Univ. Berlin, Germany, and\nC P. Benner, Technical Univ. Chemnitz, Germany, December 2003.\nC\nC REVISIONS\nC\nC V. Sima, June 2008 (SLICOT version of the HAPACK routine DGESQR).\nC\nC KEYWORDS\nC\nC Elementary matrix operations, orthogonal symplectic matrix.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ONE\n PARAMETER ( ONE = 1.0D0 )\nC .. Scalar Arguments ..\n INTEGER INFO, LDA, LDB, LDWORK, M, N\nC .. Array Arguments ..\n DOUBLE PRECISION A(LDA,*), B(LDB,*), CS(*), DWORK(*), TAU(*)\nC .. Local Scalars ..\n INTEGER I, K\n DOUBLE PRECISION ALPHA, NU, TEMP\nC .. External Subroutines ..\n EXTERNAL DLARF, DLARFG, DLARTG, DROT, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC DBLE, MAX, MIN\nC\nC .. Executable Statements ..\nC\nC Check the scalar input parameters.\nC\n INFO = 0\n IF ( M.LT.0 ) THEN\n INFO = -1\n ELSE IF ( N.LT.0 ) THEN\n INFO = -2\n ELSE IF ( LDA.LT.MAX( 1, M ) ) THEN\n INFO = -4\n ELSE IF ( LDB.LT.MAX( 1, M ) ) THEN\n INFO = -6\n ELSE IF ( LDWORK.LT.MAX( 1, N ) ) THEN\n DWORK(1) = DBLE( MAX( 1, N ) )\n INFO = -10\n END IF\nC\nC Return if there were illegal values.\nC\n IF ( INFO.NE.0 ) THEN\n CALL XERBLA( 'MB04SU', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n K = MIN( M,N )\n IF ( K.EQ.0 ) THEN\n DWORK(1) = ONE\n RETURN\n END IF\nC\n DO 10 I = 1, K\nC\nC Generate elementary reflector H(i) to annihilate B(i+1:m,i).\nC\n ALPHA = B(I,I)\n CALL DLARFG( M-I+1, ALPHA, B(MIN( I+1,M ),I), 1, NU )\nC\nC Apply H(i) to A(i:m,i:n) and B(i:m,i+1:n) from the left.\nC\n B(I,I) = ONE\n CALL DLARF( 'Left', M-I+1, N-I+1, B(I,I), 1, NU, A(I,I), LDA,\n $ DWORK )\n IF ( I.LT.N )\n $ CALL DLARF( 'Left', M-I+1, N-I, B(I,I), 1, NU, B(I,I+1),\n $ LDB, DWORK )\n B(I,I) = NU\nC\nC Generate symplectic Givens rotation G(i) to annihilate\nC B(i,i).\nC\n TEMP = A(I,I)\n CALL DLARTG( TEMP, ALPHA, CS(2*I-1), CS(2*I), A(I,I) )\n IF ( I.LT.N ) THEN\nC\nC Apply G(i) to [ A(i,i+1:n); B(i,i+1:n) ] from the left.\nC\n CALL DROT( N-I, A(I,I+1), LDA, B(I,I+1), LDB, CS(2*I-1),\n $ CS(2*I) )\n END IF\nC\nC Generate elementary reflector F(i) to annihilate A(i+1:m,i).\nC\n CALL DLARFG( M-I+1, A(I,I), A(MIN( I+1,M ),I), 1, TAU(I) )\n IF ( I.LT.N ) THEN\nC\nC Apply F(i) to A(i:m,i+1:n) and B(i:m,i+1:n) from the\nC left.\nC\n TEMP = A(I,I)\n A(I,I) = ONE\n CALL DLARF( 'Left', M-I+1, N-I, A(I,I), 1, TAU(I), A(I,I+1),\n $ LDA, DWORK )\n CALL DLARF( 'Left', M-I+1, N-I, A(I,I), 1, TAU(I), B(I,I+1),\n $ LDB, DWORK )\n A(I,I) = TEMP\n END IF\n 10 CONTINUE\n DWORK(1) = DBLE(MAX( 1, N ))\n RETURN\nC *** Last line of MB04SU ***\n END\n", "meta": {"hexsha": "7e820c8c5b8029800f4bc3f5023b8edec35914a1", "size": 7803, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB04SU.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB04SU.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB04SU.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 31.5910931174, "max_line_length": 72, "alphanum_fraction": 0.5253107779, "num_tokens": 2553, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768604361741, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6784802031946923}} {"text": "c-----------------------------------------------------------------------\nc\nc compute the metrics of the mapping from global to local \nc coordinates and the jacobian of the mapping (weighted by \nc the quadrature weight\nc\nc-----------------------------------------------------------------------\n subroutine e3metric( xl, shgl, dxidx,\n & shg, WdetJ)\n\n include \"common.h\"\n \n real*8 xl(npro,nenl,nsd), shgl(npro,nsd,nshl),\n & dxidx(npro,nsd,nsd), shg(npro,nshl,nsd), \n & WdetJ(npro)\n\n real*8 dxdxi(npro,nsd,nsd), tmp(npro), det(npro), invdet(npro)\n\nc\nc.... compute the deformation gradient\nc\n dxdxi = zero\nc\n do n = 1, nenl\n dxdxi(:,1,1) = dxdxi(:,1,1) + xl(:,n,1) * shgl(:,1,n)\n dxdxi(:,1,2) = dxdxi(:,1,2) + xl(:,n,1) * shgl(:,2,n)\n dxdxi(:,1,3) = dxdxi(:,1,3) + xl(:,n,1) * shgl(:,3,n)\n dxdxi(:,2,1) = dxdxi(:,2,1) + xl(:,n,2) * shgl(:,1,n)\n dxdxi(:,2,2) = dxdxi(:,2,2) + xl(:,n,2) * shgl(:,2,n)\n dxdxi(:,2,3) = dxdxi(:,2,3) + xl(:,n,2) * shgl(:,3,n)\n dxdxi(:,3,1) = dxdxi(:,3,1) + xl(:,n,3) * shgl(:,1,n)\n dxdxi(:,3,2) = dxdxi(:,3,2) + xl(:,n,3) * shgl(:,2,n)\n dxdxi(:,3,3) = dxdxi(:,3,3) + xl(:,n,3) * shgl(:,3,n)\n enddo\nc\n invdet = one /( dxdxi(:,1,1)*dxdxi(:,2,2)*dxdxi(:,3,3) \n & + dxdxi(:,2,1)*dxdxi(:,3,2)*dxdxi(:,1,3)\n & + dxdxi(:,3,1)*dxdxi(:,1,2)*dxdxi(:,2,3)\n & - dxdxi(:,1,1)*dxdxi(:,3,2)*dxdxi(:,2,3)\n & - dxdxi(:,3,1)*dxdxi(:,2,2)*dxdxi(:,1,3)\n & - dxdxi(:,2,1)*dxdxi(:,1,2)*dxdxi(:,3,3))\nc\nc.... compute the inverse of deformation gradient\nc\n dxidx(:,1,1) = ( dxdxi(:,2,2) * dxdxi(:,3,3) \n & - dxdxi(:,3,2) * dxdxi(:,2,3))\n dxidx(:,1,2) = dxdxi(:,3,2) * dxdxi(:,1,3) \n & - dxdxi(:,1,2) * dxdxi(:,3,3)\n dxidx(:,1,3) = dxdxi(:,1,2) * dxdxi(:,2,3) \n & - dxdxi(:,1,3) * dxdxi(:,2,2)\n tmp = one / ( dxidx(:,1,1) * dxdxi(:,1,1) \n & + dxidx(:,1,2) * dxdxi(:,2,1) \n & + dxidx(:,1,3) * dxdxi(:,3,1) )\n dxidx(:,1,1) = dxidx(:,1,1) * tmp\n dxidx(:,1,2) = dxidx(:,1,2) * tmp\n dxidx(:,1,3) = dxidx(:,1,3) * tmp\n dxidx(:,2,1) = (dxdxi(:,2,3) * dxdxi(:,3,1) \n & - dxdxi(:,2,1) * dxdxi(:,3,3)) * tmp\n dxidx(:,2,2) = (dxdxi(:,1,1) * dxdxi(:,3,3) \n & - dxdxi(:,3,1) * dxdxi(:,1,3)) * tmp\n dxidx(:,2,3) = (dxdxi(:,2,1) * dxdxi(:,1,3) \n & - dxdxi(:,1,1) * dxdxi(:,2,3)) * tmp\n dxidx(:,3,1) = (dxdxi(:,2,1) * dxdxi(:,3,2) \n & - dxdxi(:,2,2) * dxdxi(:,3,1)) * tmp\n dxidx(:,3,2) = (dxdxi(:,3,1) * dxdxi(:,1,2) \n & - dxdxi(:,1,1) * dxdxi(:,3,2)) * tmp\n dxidx(:,3,3) = (dxdxi(:,1,1) * dxdxi(:,2,2) \n & - dxdxi(:,1,2) * dxdxi(:,2,1)) * tmp\nc\n WdetJ = Qwt(lcsyst,intp) / tmp\nc\nc.... compute the global gradient of shape-functions\nc\n do n = 1, nshl\n shg(:,n,1) = shgl(:,1,n) * dxidx(:,1,1) + \n & shgl(:,2,n) * dxidx(:,2,1) +\n & shgl(:,3,n) * dxidx(:,3,1)\n shg(:,n,2) = shgl(:,1,n) * dxidx(:,1,2) + \n & shgl(:,2,n) * dxidx(:,2,2) +\n & shgl(:,3,n) * dxidx(:,3,2) \n shg(:,n,3) = shgl(:,1,n) * dxidx(:,1,3) + \n & shgl(:,2,n) * dxidx(:,2,3) +\n & shgl(:,3,n) * dxidx(:,3,3) \n enddo\n\n return\n end\n\n\n\n", "meta": {"hexsha": "d225e948292d82ce4bf3d5f86eea1e64ef13695d", "size": 3616, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "phSolver/common/e3metric.f", "max_stars_repo_name": "yangf4/phaseChangePhasta", "max_stars_repo_head_hexsha": "e54e22aff5071fe6c149a52f7bb049e5a1844811", "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": "phSolver/common/e3metric.f", "max_issues_repo_name": "yangf4/phaseChangePhasta", "max_issues_repo_head_hexsha": "e54e22aff5071fe6c149a52f7bb049e5a1844811", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 17, "max_issues_repo_issues_event_min_datetime": "2017-03-21T03:08:31.000Z", "max_issues_repo_issues_event_max_datetime": "2018-04-03T17:53:08.000Z", "max_forks_repo_path": "phSolver/common/e3metric.f", "max_forks_repo_name": "yangf4/phaseChangePhasta", "max_forks_repo_head_hexsha": "e54e22aff5071fe6c149a52f7bb049e5a1844811", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2016-02-08T15:51:11.000Z", "max_forks_repo_forks_event_max_datetime": "2019-10-13T00:55:14.000Z", "avg_line_length": 39.7362637363, "max_line_length": 73, "alphanum_fraction": 0.3827433628, "num_tokens": 1499, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768588653856, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6784802020659324}} {"text": "PROGRAM mlpn\n \n! Code converted using TO_F90 by Alan Miller\n! Date: 2004-06-28 Time: 12:58:12\n\n! ========================================================\n! Purpose: This program computes the Legendre polynomials\n! Pn(x) and their derivatives Pn'(x) using\n! subroutine LPN\n! Input : x --- Argument of Pn(x)\n! n --- Degree of Pn(x) ( n = 0,1,...)\n! Output: PN(n) --- Pn(x)\n! PD(n) --- Pn'(x)\n! Example: x = 0.5\n! n Pn(x) Pn'(x)\n! ---------------------------------------\n! 0 1.00000000 .00000000\n! 1 .50000000 1.00000000\n! 2 -.12500000 1.50000000\n! 3 -.43750000 .37500000\n! 4 -.28906250 -1.56250000\n! 5 .08984375 -2.22656250\n! ========================================================\n\nDOUBLE PRECISION :: pn,pd,x\nDIMENSION pn(0:100),pd(0:100)\nWRITE(*,*)' Please enter Nmax and x '\n! READ(*,*)N,X\nn=5\nx=.5\nWRITE(*,30)x\nWRITE(*,*)\nCALL lpn(n,x,pn,pd)\nWRITE(*,*)' n Pn(x) Pn''(X)'\nWRITE(*,*)'---------------------------------------'\nDO k=0,n\n WRITE(*,20)k,pn(k),pd(k)\nEND DO\n20 FORMAT(1X,i3,2E17.8)\n30 FORMAT(3X,'x =',f5.1)\nEND PROGRAM mlpn\n\n\nSUBROUTINE lpn(n,x,pn,pd)\n\n! ===============================================\n! Purpose: Compute Legendre polynomials Pn(x)\n! and their derivatives Pn'(x)\n! Input : x --- Argument of Pn(x)\n! n --- Degree of Pn(x) ( n = 0,1,...)\n! Output: PN(n) --- Pn(x)\n! PD(n) --- Pn'(x)\n! ===============================================\n\n\nINTEGER, INTENT(IN) :: n\nDOUBLE PRECISION, INTENT(IN) :: x\nDOUBLE PRECISION, INTENT(OUT) :: pn(0:n)\nDOUBLE PRECISION, INTENT(OUT) :: pd(0:n)\nIMPLICIT DOUBLE PRECISION (p,x)\n\n\npn(0)=1.0D0\npn(1)=x\npd(0)=0.0D0\npd(1)=1.0D0\np0=1.0D0\np1=x\nDO k=2,n\n pf=(2.0D0*k-1.0D0)/k*x*p1-(k-1.0D0)/k*p0\n pn(k)=pf\n IF (DABS(x) == 1.0D0) THEN\n pd(k)=0.5D0*x**(k+1)*k*(k+1.0D0)\n ELSE\n pd(k)=k*(p1-x*pf)/(1.0D0-x*x)\n END IF\n p0=p1\n p1=pf\nEND DO\nRETURN\nEND SUBROUTINE lpn\n", "meta": {"hexsha": "76374c4ad57d5abe623f77e73cc712f0540cd783", "size": 2324, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "MATLAB/f2matlab/comp_spec_func/mlpn.f90", "max_stars_repo_name": "vasaantk/bin", "max_stars_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MATLAB/f2matlab/comp_spec_func/mlpn.f90", "max_issues_repo_name": "vasaantk/bin", "max_issues_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MATLAB/f2matlab/comp_spec_func/mlpn.f90", "max_forks_repo_name": "vasaantk/bin", "max_forks_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.3414634146, "max_line_length": 64, "alphanum_fraction": 0.400172117, "num_tokens": 777, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711908591638, "lm_q2_score": 0.7981867825403177, "lm_q1q2_score": 0.6784357700838383}} {"text": "!---------------------------------------------------!\n! Copyright (c) 2016 Shunsuke A. Sato !\n! Released under the MIT license !\n! https://opensource.org/licenses/mit-license.php !\n!---------------------------------------------------!\n!-------10--------20--------30--------40--------50--------60--------70--------80--------90\nsubroutine wfn_rho\n use global_variables\n implicit none\n integer :: ix,iy\n real(dp) :: tmp\n\n rho(:)=0d0\n\n! do ix = 0,Nx\n! tmp = 0d0\n! do iy = 0,Nx\n! tmp = tmp + wfn(ix,iy)**2\n! end do\n! rho(ix) = tmp\n! end do\n\n do ix = 0,Nx\n rho(ix) = sum(wfn(ix,:)**2)\n end do\n rho = rho*dr\n\n do ix = 0,NR\n rho_n(ix) = sum(wfn(:,ix)**2)\n end do\n rho_n = rho_n*dx\n\n return\nend subroutine wfn_rho\n", "meta": {"hexsha": "33471eeeb2c70e05591178f267e69a34a59ec0d7", "size": 777, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/wfn_rho.f90", "max_stars_repo_name": "shunsuke-sato/tdse-1d-h2plus", "max_stars_repo_head_hexsha": "b626c51a2ba5233c908bcf37ee52e060b89c0ab9", "max_stars_repo_licenses": ["MIT"], "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/wfn_rho.f90", "max_issues_repo_name": "shunsuke-sato/tdse-1d-h2plus", "max_issues_repo_head_hexsha": "b626c51a2ba5233c908bcf37ee52e060b89c0ab9", "max_issues_repo_licenses": ["MIT"], "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/wfn_rho.f90", "max_forks_repo_name": "shunsuke-sato/tdse-1d-h2plus", "max_forks_repo_head_hexsha": "b626c51a2ba5233c908bcf37ee52e060b89c0ab9", "max_forks_repo_licenses": ["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.2, "max_line_length": 90, "alphanum_fraction": 0.4324324324, "num_tokens": 239, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711680567799, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.6784357416821426}} {"text": "program main\n\n!*****************************************************************************80\n!\n!! Demonstrates the use of NELMIN on ROSENBROCK.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 19 February 2008\n!\n! Author:\n!\n! John Burkardt\n!\n use mo_kind, only: i4, dp\n use mo_ansi_colors, only: color, c_red, c_green\n use mo_nelmin, only: nelmin, nelminxy\n\n implicit none\n\n integer(i4), parameter :: n = 2\n\n integer(i4) :: icount\n integer(i4) :: ifault\n integer(i4) :: kcount\n integer(i4) :: konvge\n integer(i4) :: numres\n real(dp) :: reqmin\n INTERFACE\n FUNCTION rosenbrock(pp)\n USE mo_kind, ONLY: dp\n IMPLICIT NONE\n REAL(dp), DIMENSION(:), INTENT(IN) :: pp\n REAL(dp) :: rosenbrock\n END FUNCTION rosenbrock\n END INTERFACE\n INTERFACE\n FUNCTION rosenbrockxy(pp, xx, yy)\n USE mo_kind, ONLY: dp\n IMPLICIT NONE\n REAL(dp), DIMENSION(:), INTENT(IN) :: pp\n REAL(dp), DIMENSION(:), INTENT(IN) :: xx\n REAL(dp), DIMENSION(:), INTENT(IN) :: yy\n REAL(dp) :: rosenbrockxy\n END FUNCTION rosenbrockxy\n END INTERFACE\n real(dp) :: start(n)\n real(dp) :: step(n)\n real(dp) :: xmin(n)\n real(dp) :: ynewlo\n real(dp) :: xx(1)\n real(dp) :: yy(1)\n real(dp), allocatable :: history(:)\n integer(i4) :: i\n\n\n LOGICAL :: isgood\n \n Write(*,*) ''\n Write(*,*) 'Test mo_nelmin.f90'\n\n isgood = .True.\n start(1:n) = (/ -1.2_dp, 1.0_dp /)\n reqmin = 1.0E-08_dp\n step(1:n) = (/ 1.0_dp, 1.0_dp /)\n konvge = 10\n kcount = 500\n xmin = nelmin( rosenbrock, start, funcmin=ynewlo, varmin=reqmin, step=step, &\n konvge=konvge, maxeval=kcount, neval=icount, numrestart=numres, ierror=ifault, history=history)\n do i=50, icount, 50\n write(*,'(A15,I3,A24,F12.7)') ' Minimum after ', i, ' function evaluations: ', history(i)\n end do\n write(*,'(A16,I3,A23,F12.7)') ' Minimum found (',icount,' iterations): ',ynewlo\n write(*,*) 'Call 1: ', xmin, anint(100._dp*xmin)\n isgood = isgood .and. (nint(100._dp*xmin(1)) == 100)\n isgood = isgood .and. (nint(100._dp*xmin(2)) == 100)\n\n start(1:n) = (/ -1.2_dp, 1.0_dp /)\n reqmin = 1.0E-08_dp\n step(1:n) = (/ 1.0_dp, 1.0_dp /)\n konvge = 10\n kcount = 500\n xmin = nelmin(rosenbrock, start, varmin=reqmin, step=step, konvge=konvge, maxeval=kcount)\n write(*,*) 'Call 2: ', xmin, anint(100._dp*xmin)\n isgood = isgood .and. (nint(100._dp*xmin(1)) == 100)\n isgood = isgood .and. (nint(100._dp*xmin(2)) == 100)\n\n start(1:n) = (/ -1.2_dp, 1.0_dp /)\n reqmin = 1.0E-08_dp\n konvge = 10\n kcount = 500\n xmin = nelmin(rosenbrock, start, varmin=reqmin, konvge=konvge, maxeval=kcount)\n write(*,*) 'Call 3: ', xmin, anint(100._dp*xmin)\n isgood = isgood .and. (nint(100._dp*xmin(1)) == 100)\n ! Less precision with new starting points\n isgood = isgood .and. (nint(100._dp*xmin(2)) == 99)\n\n start(1:n) = (/ -1.2_dp, 1.0_dp /)\n konvge = 10\n kcount = 500\n xmin = nelmin(rosenbrock, start, konvge=konvge, maxeval=kcount)\n write(*,*) 'Call 4: ', xmin, anint(100._dp*xmin)\n isgood = isgood .and. (nint(100._dp*xmin(1)) == 100)\n isgood = isgood .and. (nint(100._dp*xmin(2)) == 100)\n\n start(1:n) = (/ -1.2_dp, 1.0_dp /)\n xmin = nelmin(rosenbrock, start)\n write(*,*) 'Call 5: ', xmin, anint(100._dp*xmin)\n isgood = isgood .and. (nint(100._dp*xmin(1)) == 100)\n isgood = isgood .and. (nint(100._dp*xmin(2)) == 100)\n\n start(1:n) = (/ -12.0_dp, 10.0_dp /)\n xmin = nelmin(rosenbrock, start)\n write(*,*) 'Call 6: ', xmin, anint(100._dp*xmin)\n isgood = isgood .and. (nint(100._dp*xmin(1)) == 100)\n isgood = isgood .and. (nint(100._dp*xmin(2)) == 100)\n\n start(1:n) = (/ -12.0_dp, 10.0_dp /)\n xx(1) = 1.0_dp\n yy(1) = 100.0_dp\n xmin = nelminxy(rosenbrockxy, start, xx, yy, &\n neval=icount, history=history)\n do i=50, icount, 50\n write(*,'(A15,I3,A24,F12.7)') ' Minimum after ', i, ' function evaluations: ', history(i)\n end do\n write(*,'(A16,I3,A23,F12.7)') ' Minimum found (',icount,' iterations): ',ynewlo\n write(*,*) 'Call 7: ', xmin, anint(100._dp*xmin)\n isgood = isgood .and. (nint(100._dp*xmin(1)) == 100)\n isgood = isgood .and. (nint(100._dp*xmin(2)) == 100)\n\n if (isgood) then\n write(*,*) 'mo_nelmin double precision ', color('o.k.', c_green)\n else\n write(*,*) 'mo_nelmin double precision ', color('failed!', c_red)\n endif\n\n\nend program main\n", "meta": {"hexsha": "e45cf8501bf11c5ea1239a03f2666d244916a2c6", "size": 4391, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/test_mo_nelmin/main.f90", "max_stars_repo_name": "mcuntz/jams_fortran", "max_stars_repo_head_hexsha": "a1dcab78eda21f930aa6c8c3633598a522f01659", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2020-02-28T00:14:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-20T23:32:41.000Z", "max_issues_repo_path": "test/test_mo_nelmin/main.f90", "max_issues_repo_name": "mcuntz/jams_fortran", "max_issues_repo_head_hexsha": "a1dcab78eda21f930aa6c8c3633598a522f01659", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-05-09T15:33:11.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-28T16:16:09.000Z", "max_forks_repo_path": "test/test_mo_nelmin/main.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.7062937063, "max_line_length": 102, "alphanum_fraction": 0.5918925074, "num_tokens": 1713, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711604559846, "lm_q2_score": 0.7981867681382279, "lm_q1q2_score": 0.6784357335750615}} {"text": "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n!\r\n! This file contains code for approximating solutions of Jacobi's differential equations\r\n! using Taylor series expansions. \r\n!\r\n! More explicitly, these routines evaluate the functions\r\n!\r\n! ~(da,db) (da,db) (da,db)\r\n! P (t) = P ( cos(t) ) r(t) C (1)\r\n! dnu dnu dnu\r\n!\r\n! where P_dnu^(da,db) is the Jacobi polynomial of the first kind,\r\n! \r\n! r(t) = cos(t/2) ^(db+1/2) sin(t/2) ^(da+1/2)\r\n!\r\n! and C_dnu^(da,db) is a normalization constant. The normalization constant is\r\n! chosen so that the basis of solutions of Jacobi's differential equation consisting\r\n! of (1) and the corresponding Q function has Wronskian 1. The L^2 normalized\r\n! Jacobi polynomials are obtained by multiplying (1) by the constant\r\n!\r\n! sqrt((2*dnu+da+db+1)/pi) .\r\n!\r\n! Throughout, we let p denote the quantity dnu +(da+db+1)/2. The square of\r\n! the amplitude function is\r\n!\r\n!\r\n! (da, db) ~(da,db) ^2 ~(da,db) ^ 2\r\n! M (t) = P (t) + Q (t) . (2)\r\n! dnu dnu dnu\r\n!\r\n! The following subroutines should be regarded as publicly callable:\r\n!\r\n! jacobi_taylor_p - evaluate (1) and its first two derivatives when dnu is of\r\n! modest size and t is close to 0\r\n!\r\n! jacobi_taylor_q - evaluate the q function corresponding to (1) and its first\r\n! two derivatives when dnu is of modest size and t is close to 0\r\n!\r\n! jacobi_taylor_m - evaluate the amplitude (2) and its fiest two derivatives\r\n! when dnu is of modest szie and t is cloe to 0 \r\n!\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\n\r\nsubroutine jacobi_taylor_p(dnu,da,db,t,val,der,der2)\r\nimplicit double precision (a-h,o-z)\r\n\r\n! \r\n! Evaluate the function (1) at a point near 0 when dnu is of modest size.\r\n!\r\n\r\ndata pi / 3.14159265358979323846264338327950288d0 /\r\n\r\nrval = cos(t/2)**(db+0.5d0) * sin(t/2) ** (da+0.5d0)\r\nrder = (Cos(t/2.)**(-0.5d0 + db)*(da - db + (1 + da + db)*Cos(t))*Sin(t/2.)**(-0.5d0 + da))/4d0\r\nrder2 = (Cos(t/2)**(-1.5d0 + db)*(-3 - 2*da + 3*da**2 - 2*db - 2*da*db + 3*db**2 + &\r\n 4*(da**2 - db**2)*Cos(t) + (1 + da + db)**2*Cos(2*t))*Sin(t/2)**(-1.5d0 + da))/32.0d0\r\n\r\nx = cos(t)\r\n\r\ncall jacobi_taylor_j1(dnu,da,db,x,fval,fder,fder2)\r\n\r\ngval = fval\r\ngder = -sin(t)*fder\r\ngder2 = -cos(t)*fder + sin(t)**2*fder2\r\n\r\nfval = gval*rval\r\nfder = gder*rval + gval*rder\r\nfder2 = gder2*rval + 2*gder*rder + gval*rder2\r\n\r\n!\r\n! Now scale by the Wronskian\r\n!\r\n\r\ncall jacobi_gammaratio1(dnu+1,da,dd1)\r\ncall jacobi_gammaratio1(dnu+db+1,da,dd2)\r\ndconst = dd1/dd2 * 1/pi\r\ndconst = 1/sqrt(dconst)\r\n\r\nval = fval*dconst\r\nder = fder*dconst\r\nder2 = fder2*dconst\r\n\r\nend subroutine\r\n\r\n\r\n\r\nsubroutine jacobi_taylor_q(dnu,da,db,t,val,der,der2)\r\nimplicit double precision (a-h,o-z)\r\n\r\n! \r\n! Evaluate the scaled, Wronskain normalized Jacobi function of the\r\n! second kind at a point t near 0.\r\n!\r\n\r\ndata pi / 3.14159265358979323846264338327950288d0 /\r\n\r\nrval = cos(t/2)**(db+0.5d0) * sin(t/2) ** (da+0.5d0)\r\nrder = (Cos(t/2.)**(-0.5d0 + db)*(da - db + (1 + da + db)*Cos(t))*Sin(t/2.)**(-0.5d0 + da))/4d0\r\nrder2 = (Cos(t/2)**(-1.5d0 + db)*(-3 - 2*da + 3*da**2 - 2*db - 2*da*db + 3*db**2 + &\r\n 4*(da**2 - db**2)*Cos(t) + (1 + da + db)**2*Cos(2*t))*Sin(t/2)**(-1.5d0 + da))/32.0d0\r\n\r\nx = cos(t)\r\n\r\ncall jacobi_taylor_j4(dnu,da,db,x,fval,fder,fder2)\r\n\r\ngval = fval\r\ngder = -sin(t)*fder\r\ngder2 = -cos(t)*fder + sin(t)**2*fder2\r\n\r\nfval = gval*rval\r\nfder = gder*rval + gval*rder\r\nfder2 = gder2*rval + 2*gder*rder + gval*rder2\r\n\r\n!\r\n! Now scale by the Wronskian\r\n!\r\n\r\ncall jacobi_gammaratio1(dnu+1,da,dd1)\r\ncall jacobi_gammaratio1(dnu+db+1,da,dd2)\r\ndconst = dd1/dd2 * 1/pi\r\ndconst = 1/sqrt(dconst)\r\n\r\nval = fval*dconst\r\nder = fder*dconst\r\nder2 = fder2*dconst\r\n\r\nend subroutine\r\n\r\n\r\n\r\nsubroutine jacobi_taylor_j1(dnu,da,db,x,val,der,der2)\r\nimplicit double precision (a-h,o-z)\r\n\r\n!\r\n! Evaluate the Jacobi function J1 at a point x close to 1.\r\n!\r\n\r\ndata pi / 3.14159265358979323846264338327950288d0 /\r\n\r\n!\r\n! Evaluate the hypergeometric series\r\n!\r\n\r\nmaxterms = 100\r\neps0 = 1.0d-30\r\ndterm = 1.0d0\r\nxx = (x-1)/(x+1)\r\n\r\nval0 = 0 \r\nder0 = 0\r\nder20 = 0\r\n\r\ndo k=1,maxterms\r\n\r\nval0 = val0 + dterm\r\nder0 = der0 + dterm*2*(k-1)/(x**2-1)\r\nder20 = der20 + dterm*4*(k-1)*(k-1-x)/(x**2-1)**2\r\n\r\ndterm = dterm * xx/k\r\ndterm = dterm * (k-dnu-db-1)*(k-dnu-1)/(k+da) \r\n\r\n!if (abs(dterm) .lt. eps0*abs(val0)) exit\r\n\r\nend do\r\n\r\n!\r\n! Mulitply by ((1+x)/2)**n\r\n!\r\n\r\n\r\nval = val0 *((1+x)/2)**dnu\r\nder = der0 * ((1+x)/2)**dnu + val0 * 2.0d0**(-dnu)*dnu*(1+x)**(dnu-1)\r\nder2 = ((1 + x)**(-2 + dnu)*((-1 + dnu)*dnu*val0 + &\r\n (1 + x)*(2*der0*dnu + der20*(1 + x))))/2**dnu\r\n\r\n!\r\n! Scale by the appropriate constant\r\n!\r\n\r\ncall jacobi_gammaratio1(dnu+1,da,dd1)\r\ndconst = dd1 / gamma(1+da)\r\n\r\nval = val * dconst\r\nder = der * dconst\r\nder2 = der2 * dconst\r\n\r\nend subroutine\r\n\r\n\r\nsubroutine jacobi_taylor_j2(dnu,da,db,x,val,der,der2)\r\nimplicit double precision (a-h,o-z)\r\n\r\n! \r\n! Evaluate the Jacobi function J2 at a point close to 1.\r\n!\r\n\r\ndata pi / 3.14159265358979323846264338327950288d0 /\r\n\r\nmaxterms = 100\r\neps0 = 1.0d-30\r\n\r\n!\r\n! Evaluate the hypergeometric series 2F1(-n-a,-n-a-b,1-a,(x-1)/(x+1))\r\n!\r\n\r\ndterm = 1.0d0\r\nxx = (x-1)/(x+1)\r\nval0 = 0 \r\nder0 = 0\r\nder20 = 0\r\ndo k=1,maxterms\r\nval0 = val0 + dterm\r\nder0 = der0 + dterm*2*(k-1)/(x**2-1)\r\nder20 = der20 + dterm*4*(k-1)*(k-1-x)/(x**2-1)**2\r\n\r\ndterm = dterm * xx/k\r\ndterm = dterm * (-1-da+k-dnu)*(-1-da-db+k-dnu)/(k-da)\r\nif (abs(dterm) .lt. eps0*abs(val0)) exit\r\nend do\r\n\r\n!\r\n! Multiply by ((1+x)/2)^n\r\n!\r\n\r\nval2 = val0 *((1+x)/2)**dnu\r\nder2 = der0 * ((1+x)/2)**dnu + val0 * 2.0d0**(-dnu)*dnu*(1+x)**(dnu-1)\r\nder22 = ((1 + x)**(-2 + dnu)*((-1 + dnu)*dnu*val0 + &\r\n (1 + x)*(2*der0*dnu + der20*(1 + x))))/2**dnu\r\n\r\n!\r\n! Multiply by ((1+x)/(1-x))^da\r\n!\r\n\r\nval3 = val2 * ((1+x)/(1-x))**da\r\nder3 = (((1 + x)/(1 - x))**da*(-2*da*val2 + der2*(-1 + x**2)))/(-1 + x**2)\r\nder32 = (((1 + x)/(1 - x))**da*(4*da*val2*(da + x) + &\r\n (-1 + x**2)*(-4*da*der2 + der22*(-1 + x**2))))/(-1 + x**2)**2\r\n\r\n!\r\n! Scale by the appropriate constant\r\n!\r\n\r\ncall jacobi_gammaratio1(dnu+db+1,da,dd1)\r\ndconst = 1/dd1 *1/ gamma(1-da)\r\n\r\n\r\nval = val3 * dconst\r\nder = der3 * dconst\r\nder2 = der32 * dconst\r\n\r\nend subroutine\r\n\r\n\r\n\r\nrecursive subroutine jacobi_taylor_j4(dnu,da,db,x,val,der,der2)\r\nimplicit double precision (a-h,o-z)\r\n\r\n! \r\n! Evaluate the appropriate function of the second kind at the point x.\r\n!\r\n\r\ndouble precision :: whts(16),vals(16),ders(16),der2s(16),xs(16)\r\n\r\ndata pi / 3.14159265358979323846264338327950288d0 /\r\n\r\ndata ncheb / 16 /\r\n\r\ndata xs / -0.100000000000000000000000000000000000D+01, &\r\n -0.978147600733805637928566747869599532D+00, &\r\n -0.913545457642600895502127571985317191D+00, &\r\n -0.809016994374947424102293417182819080D+00, &\r\n -0.669130606358858213826273330686780548D+00, &\r\n -0.500000000000000000000000000000000096D+00, &\r\n -0.309016994374947424102293417182818984D+00, &\r\n -0.104528463267653471399834154802498051D+00, &\r\n 0.104528463267653471399834154802498147D+00, &\r\n 0.309016994374947424102293417182819032D+00, &\r\n 0.499999999999999999999999999999999952D+00, &\r\n 0.669130606358858213826273330686780452D+00, &\r\n 0.809016994374947424102293417182819080D+00, &\r\n 0.913545457642600895502127571985317191D+00, &\r\n 0.978147600733805637928566747869599532D+00, &\r\n 0.100000000000000000000000000000000000D+01 /\r\n\r\n! data xs / -0.1000000000000000D+01, &\r\n! -0.9781476007338056D+00, &\r\n! -0.9135454576426008D+00, &\r\n! -0.8090169943749473D+00, &\r\n! -0.6691306063588579D+00, &\r\n! -0.4999999999999998D+00, &\r\n! -0.3090169943749473D+00, &\r\n! -0.1045284632676533D+00, &\r\n! 0.1045284632676537D+00, &\r\n! 0.3090169943749475D+00, &\r\n! 0.5000000000000001D+00, &\r\n! 0.6691306063588582D+00, &\r\n! 0.8090169943749475D+00, &\r\n! 0.9135454576426009D+00, &\r\n! 0.9781476007338057D+00, &\r\n! 0.1000000000000000D+01 /\r\n\r\n!\r\n! When da of small magnitude, use interpolation to evaluate j4\r\n!\r\n\r\nif (abs(da) .lt. 0.01d0) then\r\neps0 = epsilon(0.0d0)\r\na = -0.097d0\r\nb = 0.097d0\r\nxx = (2*da - (b+a) ) /(b-a)\r\n\r\ndo i=1,ncheb\r\nalpha = xs(i)*(b-a)/2+ (b+a)/2\r\ncall jacobi_taylor_j4(dnu,alpha,db,x,vals(i),ders(i),der2s(i))\r\nend do\r\n\r\n!\r\n! do the interpolation\r\n!\r\n\r\ndsign = 1.0d0\r\ndo i=1,ncheb\r\ndiff = xx - xs(i)\r\nif (abs(diff) .lt. eps0) then\r\nval = vals(i)\r\nder = ders(i)\r\nder2 = der2s(i)\r\nreturn\r\nendif\r\n\r\nwhts(i) = dsign/diff\r\ndsign = -dsign\r\nend do\r\nwhts(1) = whts(1)/2 \r\nwhts(ncheb) = whts(ncheb)/2\r\n\r\ndd = sum(whts)\r\nval = sum(vals*whts)/dd\r\nder = sum(ders*whts)/dd\r\nder2 = sum(der2s*whts)/dd\r\n\r\nelse\r\n\r\ndd1 = gamma(1-da)/(gamma(0.5d0+da)*gamma(0.5d0-da))\r\ndd2 = gamma(1-da)/pi\r\n\r\ncall jacobi_taylor_j1(dnu,da,db,x,val1,der11,der12)\r\ncall jacobi_taylor_j2(dnu,da,db,x,val2,der21,der22)\r\n\r\nval = dd1*val1-dd2*val2\r\nder = dd1*der11-dd2*der21\r\nder2 = dd1*der12-dd2*der22\r\n\r\nval = val * gamma(da)\r\nder = der * gamma(da)\r\nder2 = der2* gamma(da)\r\n\r\nendif\r\n\r\nend subroutine\r\n\r\n\r\n\r\n\r\n\r\n\r\nsubroutine jacobi_taylor_m(dnu,da,db,t,val,der,der2)\r\nimplicit double precision (a-h,o-z)\r\n\r\n! \r\n! Evaluate the scaled, Wronskain normalized Jacobi function of the\r\n! second kind at a point t near 0.\r\n!\r\n\r\ndata pi / 3.14159265358979323846264338327950288d0 /\r\n\r\ncall jacobi_taylor_q(dnu,da,db,t,qval,qder,qder2)\r\ncall jacobi_taylor_p(dnu,da,db,t,pval,pder,pder2)\r\n\r\nval = pval**2+qval**2\r\nder = 2*pval*pder + 2*qval*qder\r\nder2 = 2*pder*pder + 2*pval*pder2 + 2*qder*qder+2*qval*qder2\r\n\r\nend subroutine\r\n\r\n", "meta": {"hexsha": "ef32f71db26bca3ad1f2fc8d72161138a7277739", "size": 10188, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "v2/specFun/fastJacobiTransform/src/jacobi_taylor.f90", "max_stars_repo_name": "ButterflyLab/ButterflyLab", "max_stars_repo_head_hexsha": "fb152ba8f2c5dbdc2b15b516023516a5b538ef78", "max_stars_repo_licenses": ["0BSD"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2018-01-04T20:47:01.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-18T14:16:56.000Z", "max_issues_repo_path": "v2/specFun/fastJacobiTransform/src/jacobi_taylor.f90", "max_issues_repo_name": "ButterflyLab/ButterflyLab", "max_issues_repo_head_hexsha": "fb152ba8f2c5dbdc2b15b516023516a5b538ef78", "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": "v2/specFun/fastJacobiTransform/src/jacobi_taylor.f90", "max_forks_repo_name": "ButterflyLab/ButterflyLab", "max_forks_repo_head_hexsha": "fb152ba8f2c5dbdc2b15b516023516a5b538ef78", "max_forks_repo_licenses": ["0BSD"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-04-13T11:14:44.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-16T16:19:45.000Z", "avg_line_length": 26.3255813953, "max_line_length": 97, "alphanum_fraction": 0.5715547703, "num_tokens": 3993, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418241572634, "lm_q2_score": 0.7341195152660687, "lm_q1q2_score": 0.6784305479874307}} {"text": "C==============================================================================\nC\nC LIBRARY ROUTINES FOR SPECTRAL METHODS\nC\nC March 1989\nC\nC For questions, comments or suggestions, please contact:\nC\nC Einar Malvin Ronquist\nC Room 3-243\nC Department of Mechanical Engineering\nC Massachusetts Institute of Technology\nC 77 Massachusetts Avenue\nC Cambridge, MA 0299\nC U.S.A.\nC\nC------------------------------------------------------------------------------\nC\nC ABBRIVIATIONS:\nC\nC M - Set of mesh points\nC Z - Set of collocation/quadrature points\nC W - Set of quadrature weights\nC H - Lagrangian interpolant\nC D - Derivative operator\nC I - Interpolation operator\nC GL - Gauss Legendre\nC GLL - Gauss-Lobatto Legendre\nC GJ - Gauss Jacobi\nC GLJ - Gauss-Lobatto Jacobi\nC\nC\nC MAIN ROUTINES:\nC\nC Points and weights:\nC\nC ZWGL Compute Gauss Legendre points and weights\nC ZWGLL Compute Gauss-Lobatto Legendre points and weights\nC ZWGJ Compute Gauss Jacobi points and weights (general)\nC ZWGLJ Compute Gauss-Lobatto Jacobi points and weights (general)\nC\nC Lagrangian interpolants:\nC\nC HGL Compute Gauss Legendre Lagrangian interpolant\nC HGLL Compute Gauss-Lobatto Legendre Lagrangian interpolant\nC HGJ Compute Gauss Jacobi Lagrangian interpolant (general)\nC HGLJ Compute Gauss-Lobatto Jacobi Lagrangian interpolant (general)\nC\nC Derivative operators:\nC\nC DGLL Compute Gauss-Lobatto Legendre derivative matrix\nC DGLLGL Compute derivative matrix for a staggered mesh (GLL->GL)\nC DGJ Compute Gauss Jacobi derivative matrix (general)\nC DGLJ Compute Gauss-Lobatto Jacobi derivative matrix (general)\nC DGLJGJ Compute derivative matrix for a staggered mesh (GLJ->GJ) (general)\nC\nC Interpolation operators:\nC\nC IGLM Compute interpolation operator GL -> M\nC IGLLM Compute interpolation operator GLL -> M\nC IGJM Compute interpolation operator GJ -> M (general)\nC IGLJM Compute interpolation operator GLJ -> M (general)\nC\nC Other:\nC\nC PNLEG Compute Legendre polynomial of degree N\nC PNDLEG Compute derivative of Legendre polynomial of degree N\nC\nC Comments:\nC\nC Note that many of the above routines exist in both single and\nC double precision. If the name of the single precision routine is\nC SUB, the double precision version is called SUBD. In most cases\nC all the \"low-level\" arithmetic is done in double precision, even\nC for the single precsion versions.\nC\nC Useful references:\nC\nC [1] Gabor Szego: Orthogonal Polynomials, American Mathematical Society,\nC Providence, Rhode Island, 1939.\nC [2] Abramowitz & Stegun: Handbook of Mathematical Functions,\nC Dover, New York, 1972.\nC [3] Canuto, Hussaini, Quarteroni & Zang: Spectral Methods in Fluid\nC Dynamics, Springer-Verlag, 1988.\nC\nC\nC==============================================================================\nC\nC--------------------------------------------------------------------\n SUBROUTINE ZWGL (Z,W,NP)\nC--------------------------------------------------------------------\nC\nC Generate NP Gauss Legendre points (Z) and weights (W)\nC associated with Jacobi polynomial P(N)(alpha=0,beta=0).\nC The polynomial degree N=NP-1.\nC Z and W are in single precision, but all the arithmetic\nC operations are done in double precision.\nC\nC--------------------------------------------------------------------\n REAL Z(1),W(1)\n ALPHA = 0.\n BETA = 0.\n CALL ZWGJ (Z,W,NP,ALPHA,BETA)\n RETURN\n END\nC\n SUBROUTINE ZWGLL (Z,W,NP)\nC--------------------------------------------------------------------\nC\nC Generate NP Gauss-Lobatto Legendre points (Z) and weights (W)\nC associated with Jacobi polynomial P(N)(alpha=0,beta=0).\nC The polynomial degree N=NP-1.\nC Z and W are in single precision, but all the arithmetic\nC operations are done in double precision.\nC\nC--------------------------------------------------------------------\n REAL Z(1),W(1)\n ALPHA = 0.\n BETA = 0.\n CALL ZWGLJ (Z,W,NP,ALPHA,BETA)\n RETURN\n END\nC\n SUBROUTINE ZWGJ (Z,W,NP,ALPHA,BETA)\nC--------------------------------------------------------------------\nC\nC Generate NP GAUSS JACOBI points (Z) and weights (W)\nC associated with Jacobi polynomial P(N)(alpha>-1,beta>-1).\nC The polynomial degree N=NP-1.\nC Single precision version.\nC\nC--------------------------------------------------------------------\n PARAMETER (NMAX=84)\n PARAMETER (NZD = NMAX)\n REAL*8 ZD(NZD),WD(NZD)\n REAL Z(1),W(1),ALPHA,BETA\nC\n NPMAX = NZD\n IF (NP.GT.NPMAX) THEN\n WRITE (6,*) 'Too large polynomial degree in ZWGJ'\n WRITE (6,*) 'Maximum polynomial degree is',NMAX\n WRITE (6,*) 'Here NP=',NP\n call exitt(1)\n ENDIF\n ALPHAD = ALPHA\n BETAD = BETA\n CALL ZWGJD (ZD,WD,NP,ALPHAD,BETAD)\n DO 100 I=1,NP\n Z(I) = ZD(I)\n W(I) = WD(I)\n 100 CONTINUE\n RETURN\n END\nC\n SUBROUTINE ZWGJD (Z,W,NP,ALPHA,BETA)\nC--------------------------------------------------------------------\nC\nC Generate NP GAUSS JACOBI points (Z) and weights (W)\nC associated with Jacobi polynomial P(N)(alpha>-1,beta>-1).\nC The polynomial degree N=NP-1.\nC Double precision version.\nC\nC--------------------------------------------------------------------\n IMPLICIT REAL*8 (A-H,O-Z)\n REAL*8 Z(1),W(1),ALPHA,BETA\nC\n N = NP-1\n DN = ((N))\n ONE = 1.\n TWO = 2.\n APB = ALPHA+BETA\nC\n IF (NP.LE.0) THEN\n WRITE (6,*) 'ZWGJD: Minimum number of Gauss points is 1',np\n call exitt(1)\n ENDIF\n IF ((ALPHA.LE.-ONE).OR.(BETA.LE.-ONE)) THEN\n WRITE (6,*) 'ZWGJD: Alpha and Beta must be greater than -1'\n call exitt(1)\n ENDIF\nC\n IF (NP.EQ.1) THEN\n Z(1) = (BETA-ALPHA)/(APB+TWO)\n W(1) = GAMMAF(ALPHA+ONE)*GAMMAF(BETA+ONE)/GAMMAF(APB+TWO)\n $ * TWO**(APB+ONE)\n RETURN\n ENDIF\nC\n CALL JACG (Z,NP,ALPHA,BETA)\nC\n NP1 = N+1\n NP2 = N+2\n DNP1 = ((NP1))\n DNP2 = ((NP2))\n FAC1 = DNP1+ALPHA+BETA+ONE\n FAC2 = FAC1+DNP1\n FAC3 = FAC2+ONE\n FNORM = PNORMJ(NP1,ALPHA,BETA)\n RCOEF = (FNORM*FAC2*FAC3)/(TWO*FAC1*DNP2)\n DO 100 I=1,NP\n CALL JACOBF (P,PD,PM1,PDM1,PM2,PDM2,NP2,ALPHA,BETA,Z(I))\n W(I) = -RCOEF/(P*PDM1)\n 100 CONTINUE\n RETURN\n END\nC\n SUBROUTINE ZWGLJ (Z,W,NP,ALPHA,BETA)\nC--------------------------------------------------------------------\nC\nC Generate NP GAUSS LOBATTO JACOBI points (Z) and weights (W)\nC associated with Jacobi polynomial P(N)(alpha>-1,beta>-1).\nC The polynomial degree N=NP-1.\nC Single precision version.\nC\nC--------------------------------------------------------------------\n PARAMETER (NMAX=84)\n PARAMETER (NZD = NMAX)\n REAL*8 ZD(NZD),WD(NZD)\n REAL Z(1),W(1),ALPHA,BETA\nC\n NPMAX = NZD\n IF (NP.GT.NPMAX) THEN\n WRITE (6,*) 'Too large polynomial degree in ZWGLJ'\n WRITE (6,*) 'Maximum polynomial degree is',NMAX\n WRITE (6,*) 'Here NP=',NP\n call exitt(1)\n ENDIF\n ALPHAD = ALPHA\n BETAD = BETA\n CALL ZWGLJD (ZD,WD,NP,ALPHAD,BETAD)\n DO 100 I=1,NP\n Z(I) = ZD(I)\n W(I) = WD(I)\n 100 CONTINUE\n RETURN\n END\nC\n SUBROUTINE ZWGLJD (Z,W,NP,ALPHA,BETA)\nC--------------------------------------------------------------------\nC\nC Generate NP GAUSS LOBATTO JACOBI points (Z) and weights (W)\nC associated with Jacobi polynomial P(N)(alpha>-1,beta>-1).\nC The polynomial degree N=NP-1.\nC Double precision version.\nC\nC--------------------------------------------------------------------\n IMPLICIT REAL*8 (A-H,O-Z)\n REAL*8 Z(NP),W(NP),ALPHA,BETA\nC\n N = NP-1\n NM1 = N-1\n ONE = 1.\n TWO = 2.\nC\n IF (NP.LE.1) THEN\n WRITE (6,*) 'ZWGLJD: Minimum number of Gauss-Lobatto points is 2'\n WRITE (6,*) 'ZWGLJD: alpha,beta:',alpha,beta,np\n call exitt(1)\n ENDIF\n IF ((ALPHA.LE.-ONE).OR.(BETA.LE.-ONE)) THEN\n WRITE (6,*) 'ZWGLJD: Alpha and Beta must be greater than -1'\n call exitt(1)\n ENDIF\nC\n IF (NM1.GT.0) THEN\n ALPG = ALPHA+ONE\n BETG = BETA+ONE\n CALL ZWGJD (Z(2),W(2),NM1,ALPG,BETG)\n ENDIF\n Z(1) = -ONE\n Z(NP) = ONE\n DO 100 I=2,NP-1\n W(I) = W(I)/(ONE-Z(I)**2)\n 100 CONTINUE\n CALL JACOBF (P,PD,PM1,PDM1,PM2,PDM2,N,ALPHA,BETA,Z(1))\n W(1) = ENDW1 (N,ALPHA,BETA)/(TWO*PD)\n CALL JACOBF (P,PD,PM1,PDM1,PM2,PDM2,N,ALPHA,BETA,Z(NP))\n W(NP) = ENDW2 (N,ALPHA,BETA)/(TWO*PD)\nC\n RETURN\n END\nC\n REAL*8 FUNCTION ENDW1 (N,ALPHA,BETA)\n IMPLICIT REAL*8 (A-H,O-Z)\n REAL*8 ALPHA,BETA\n ZERO = 0.\n ONE = 1.\n TWO = 2.\n THREE = 3.\n FOUR = 4.\n APB = ALPHA+BETA\n IF (N.EQ.0) THEN\n ENDW1 = ZERO\n RETURN\n ENDIF\n F1 = GAMMAF(ALPHA+TWO)*GAMMAF(BETA+ONE)/GAMMAF(APB+THREE)\n F1 = F1*(APB+TWO)*TWO**(APB+TWO)/TWO\n IF (N.EQ.1) THEN\n ENDW1 = F1\n RETURN\n ENDIF\n FINT1 = GAMMAF(ALPHA+TWO)*GAMMAF(BETA+ONE)/GAMMAF(APB+THREE)\n FINT1 = FINT1*TWO**(APB+TWO)\n FINT2 = GAMMAF(ALPHA+TWO)*GAMMAF(BETA+TWO)/GAMMAF(APB+FOUR)\n FINT2 = FINT2*TWO**(APB+THREE)\n F2 = (-TWO*(BETA+TWO)*FINT1 + (APB+FOUR)*FINT2)\n $ * (APB+THREE)/FOUR\n IF (N.EQ.2) THEN\n ENDW1 = F2\n RETURN\n ENDIF\n DO 100 I=3,N\n DI = ((I-1))\n ABN = ALPHA+BETA+DI\n ABNN = ABN+DI\n A1 = -(TWO*(DI+ALPHA)*(DI+BETA))/(ABN*ABNN*(ABNN+ONE))\n A2 = (TWO*(ALPHA-BETA))/(ABNN*(ABNN+TWO))\n A3 = (TWO*(ABN+ONE))/((ABNN+TWO)*(ABNN+ONE))\n F3 = -(A2*F2+A1*F1)/A3\n F1 = F2\n F2 = F3\n 100 CONTINUE\n ENDW1 = F3\n RETURN\n END\nC\n REAL*8 FUNCTION ENDW2 (N,ALPHA,BETA)\n IMPLICIT REAL*8 (A-H,O-Z)\n REAL*8 ALPHA,BETA\n ZERO = 0.\n ONE = 1.\n TWO = 2.\n THREE = 3.\n FOUR = 4.\n APB = ALPHA+BETA\n IF (N.EQ.0) THEN\n ENDW2 = ZERO\n RETURN\n ENDIF\n F1 = GAMMAF(ALPHA+ONE)*GAMMAF(BETA+TWO)/GAMMAF(APB+THREE)\n F1 = F1*(APB+TWO)*TWO**(APB+TWO)/TWO\n IF (N.EQ.1) THEN\n ENDW2 = F1\n RETURN\n ENDIF\n FINT1 = GAMMAF(ALPHA+ONE)*GAMMAF(BETA+TWO)/GAMMAF(APB+THREE)\n FINT1 = FINT1*TWO**(APB+TWO)\n FINT2 = GAMMAF(ALPHA+TWO)*GAMMAF(BETA+TWO)/GAMMAF(APB+FOUR)\n FINT2 = FINT2*TWO**(APB+THREE)\n F2 = (TWO*(ALPHA+TWO)*FINT1 - (APB+FOUR)*FINT2)\n $ * (APB+THREE)/FOUR\n IF (N.EQ.2) THEN\n ENDW2 = F2\n RETURN\n ENDIF\n DO 100 I=3,N\n DI = ((I-1))\n ABN = ALPHA+BETA+DI\n ABNN = ABN+DI\n A1 = -(TWO*(DI+ALPHA)*(DI+BETA))/(ABN*ABNN*(ABNN+ONE))\n A2 = (TWO*(ALPHA-BETA))/(ABNN*(ABNN+TWO))\n A3 = (TWO*(ABN+ONE))/((ABNN+TWO)*(ABNN+ONE))\n F3 = -(A2*F2+A1*F1)/A3\n F1 = F2\n F2 = F3\n 100 CONTINUE\n ENDW2 = F3\n RETURN\n END\nC\n REAL*8 FUNCTION GAMMAF (X)\n IMPLICIT REAL*8 (A-H,O-Z)\n REAL*8 X\n ZERO = 0.0\n HALF = 0.5\n ONE = 1.0\n TWO = 2.0\n FOUR = 4.0\n PI = FOUR*ATAN(ONE)\n GAMMAF = ONE\n IF (X.EQ.-HALF) GAMMAF = -TWO*SQRT(PI)\n IF (X.EQ. HALF) GAMMAF = SQRT(PI)\n IF (X.EQ. ONE ) GAMMAF = ONE\n IF (X.EQ. TWO ) GAMMAF = ONE\n IF (X.EQ. 1.5 ) GAMMAF = SQRT(PI)/2.\n IF (X.EQ. 2.5) GAMMAF = 1.5*SQRT(PI)/2.\n IF (X.EQ. 3.5) GAMMAF = 0.5*(2.5*(1.5*SQRT(PI)))\n IF (X.EQ. 3. ) GAMMAF = 2.\n IF (X.EQ. 4. ) GAMMAF = 6.\n IF (X.EQ. 5. ) GAMMAF = 24.\n IF (X.EQ. 6. ) GAMMAF = 120.\n RETURN\n END\nC\n REAL*8 FUNCTION PNORMJ (N,ALPHA,BETA)\n IMPLICIT REAL*8 (A-H,O-Z)\n REAL*8 ALPHA,BETA\n ONE = 1.\n TWO = 2.\n DN = ((N))\n CONST = ALPHA+BETA+ONE\n IF (N.LE.1) THEN\n PROD = GAMMAF(DN+ALPHA)*GAMMAF(DN+BETA)\n PROD = PROD/(GAMMAF(DN)*GAMMAF(DN+ALPHA+BETA))\n PNORMJ = PROD * TWO**CONST/(TWO*DN+CONST)\n RETURN\n ENDIF\n PROD = GAMMAF(ALPHA+ONE)*GAMMAF(BETA+ONE)\n PROD = PROD/(TWO*(ONE+CONST)*GAMMAF(CONST+ONE))\n PROD = PROD*(ONE+ALPHA)*(TWO+ALPHA)\n PROD = PROD*(ONE+BETA)*(TWO+BETA)\n DO 100 I=3,N\n DINDX = ((I))\n FRAC = (DINDX+ALPHA)*(DINDX+BETA)/(DINDX*(DINDX+ALPHA+BETA))\n PROD = PROD*FRAC\n 100 CONTINUE\n PNORMJ = PROD * TWO**CONST/(TWO*DN+CONST)\n RETURN\n END\nC\n SUBROUTINE JACG (XJAC,NP,ALPHA,BETA)\nC--------------------------------------------------------------------\nC\nC Compute NP Gauss points XJAC, which are the zeros of the\nC Jacobi polynomial J(NP) with parameters ALPHA and BETA.\nC ALPHA and BETA determines the specific type of Gauss points.\nC Examples:\nC ALPHA = BETA = 0.0 -> Legendre points\nC ALPHA = BETA = -0.5 -> Chebyshev points\nC\nC--------------------------------------------------------------------\n IMPLICIT REAL*8 (A-H,O-Z)\n REAL*8 XJAC(1)\n DATA KSTOP /10/\n DATA EPS/1.0e-12/\n N = NP-1\n one = 1.\n DTH = 4.*ATAN(one)/(2.*((N))+2.)\n DO 40 J=1,NP\n IF (J.EQ.1) THEN\n X = COS((2.*(((J))-1.)+1.)*DTH)\n ELSE\n X1 = COS((2.*(((J))-1.)+1.)*DTH)\n X2 = XLAST\n X = (X1+X2)/2.\n ENDIF\n DO 30 K=1,KSTOP\n CALL JACOBF (P,PD,PM1,PDM1,PM2,PDM2,NP,ALPHA,BETA,X)\n RECSUM = 0.\n JM = J-1\n DO 29 I=1,JM\n RECSUM = RECSUM+1./(X-XJAC(NP-I+1))\n 29 CONTINUE\n DELX = -P/(PD-RECSUM*P)\n X = X+DELX\n IF (ABS(DELX) .LT. EPS) GOTO 31\n 30 CONTINUE\n 31 CONTINUE\n XJAC(NP-J+1) = X\n XLAST = X\n 40 CONTINUE\n DO 200 I=1,NP\n XMIN = 2.\n DO 100 J=I,NP\n IF (XJAC(J).LT.XMIN) THEN\n XMIN = XJAC(J)\n JMIN = J\n ENDIF\n 100 CONTINUE\n IF (JMIN.NE.I) THEN\n SWAP = XJAC(I)\n XJAC(I) = XJAC(JMIN)\n XJAC(JMIN) = SWAP\n ENDIF\n 200 CONTINUE\n RETURN\n END\nC\n SUBROUTINE JACOBF (POLY,PDER,POLYM1,PDERM1,POLYM2,PDERM2,\n $ N,ALP,BET,X)\nC--------------------------------------------------------------------\nC\nC Computes the Jacobi polynomial (POLY) and its derivative (PDER)\nC of degree N at X.\nC\nC--------------------------------------------------------------------\n IMPLICIT REAL*8 (A-H,O-Z)\n APB = ALP+BET\n POLY = 1.\n PDER = 0.\n IF (N .EQ. 0) RETURN\n POLYL = POLY\n PDERL = PDER\n POLY = (ALP-BET+(APB+2.)*X)/2.\n PDER = (APB+2.)/2.\n IF (N .EQ. 1) RETURN\n DO 20 K=2,N\n DK = ((K))\n A1 = 2.*DK*(DK+APB)*(2.*DK+APB-2.)\n A2 = (2.*DK+APB-1.)*(ALP**2-BET**2)\n B3 = (2.*DK+APB-2.)\n A3 = B3*(B3+1.)*(B3+2.)\n A4 = 2.*(DK+ALP-1.)*(DK+BET-1.)*(2.*DK+APB)\n POLYN = ((A2+A3*X)*POLY-A4*POLYL)/A1\n PDERN = ((A2+A3*X)*PDER-A4*PDERL+A3*POLY)/A1\n PSAVE = POLYL\n PDSAVE = PDERL\n POLYL = POLY\n POLY = POLYN\n PDERL = PDER\n PDER = PDERN\n 20 CONTINUE\n POLYM1 = POLYL\n PDERM1 = PDERL\n POLYM2 = PSAVE\n PDERM2 = PDSAVE\n RETURN\n END\nC\n REAL FUNCTION HGJ (II,Z,ZGJ,NP,ALPHA,BETA)\nC---------------------------------------------------------------------\nC\nC Compute the value of the Lagrangian interpolant HGJ through\nC the NP Gauss Jacobi points ZGJ at the point Z.\nC Single precision version.\nC\nC---------------------------------------------------------------------\n PARAMETER (NMAX=84)\n PARAMETER (NZD = NMAX)\n REAL*8 ZD,ZGJD(NZD)\n REAL Z,ZGJ(1),ALPHA,BETA\n NPMAX = NZD\n IF (NP.GT.NPMAX) THEN\n WRITE (6,*) 'Too large polynomial degree in HGJ'\n WRITE (6,*) 'Maximum polynomial degree is',NMAX\n WRITE (6,*) 'Here NP=',NP\n call exitt(1)\n ENDIF\n ZD = Z\n DO 100 I=1,NP\n ZGJD(I) = ZGJ(I)\n 100 CONTINUE\n ALPHAD = ALPHA\n BETAD = BETA\n HGJ = HGJD (II,ZD,ZGJD,NP,ALPHAD,BETAD)\n RETURN\n END\nC\n REAL*8 FUNCTION HGJD (II,Z,ZGJ,NP,ALPHA,BETA)\nC---------------------------------------------------------------------\nC\nC Compute the value of the Lagrangian interpolant HGJD through\nC the NZ Gauss-Lobatto Jacobi points ZGJ at the point Z.\nC Double precision version.\nC\nC---------------------------------------------------------------------\n IMPLICIT REAL*8 (A-H,O-Z)\n REAL*8 Z,ZGJ(1),ALPHA,BETA\n EPS = 1.e-5\n ONE = 1.\n ZI = ZGJ(II)\n DZ = Z-ZI\n IF (ABS(DZ).LT.EPS) THEN\n HGJD = ONE\n RETURN\n ENDIF\n CALL JACOBF (PZI,PDZI,PM1,PDM1,PM2,PDM2,NP,ALPHA,BETA,ZI)\n CALL JACOBF (PZ,PDZ,PM1,PDM1,PM2,PDM2,NP,ALPHA,BETA,Z)\n HGJD = PZ/(PDZI*(Z-ZI))\n RETURN\n END\nC\n REAL FUNCTION HGLJ (II,Z,ZGLJ,NP,ALPHA,BETA)\nC---------------------------------------------------------------------\nC\nC Compute the value of the Lagrangian interpolant HGLJ through\nC the NZ Gauss-Lobatto Jacobi points ZGLJ at the point Z.\nC Single precision version.\nC\nC---------------------------------------------------------------------\n PARAMETER (NMAX=84)\n PARAMETER (NZD = NMAX)\n REAL*8 ZD,ZGLJD(NZD)\n REAL Z,ZGLJ(1),ALPHA,BETA\n NPMAX = NZD\n IF (NP.GT.NPMAX) THEN\n WRITE (6,*) 'Too large polynomial degree in HGLJ'\n WRITE (6,*) 'Maximum polynomial degree is',NMAX\n WRITE (6,*) 'Here NP=',NP\n call exitt(1)\n ENDIF\n ZD = Z\n DO 100 I=1,NP\n ZGLJD(I) = ZGLJ(I)\n 100 CONTINUE\n ALPHAD = ALPHA\n BETAD = BETA\n HGLJ = HGLJD (II,ZD,ZGLJD,NP,ALPHAD,BETAD)\n RETURN\n END\nC\n REAL*8 FUNCTION HGLJD (I,Z,ZGLJ,NP,ALPHA,BETA)\nC---------------------------------------------------------------------\nC\nC Compute the value of the Lagrangian interpolant HGLJD through\nC the NZ Gauss-Lobatto Jacobi points ZJACL at the point Z.\nC Double precision version.\nC\nC---------------------------------------------------------------------\n IMPLICIT REAL*8 (A-H,O-Z)\n REAL*8 Z,ZGLJ(1),ALPHA,BETA\n EPS = 1.e-5\n ONE = 1.\n ZI = ZGLJ(I)\n DZ = Z-ZI\n IF (ABS(DZ).LT.EPS) THEN\n HGLJD = ONE\n RETURN\n ENDIF\n N = NP-1\n DN = ((N))\n EIGVAL = -DN*(DN+ALPHA+BETA+ONE)\n CALL JACOBF (PI,PDI,PM1,PDM1,PM2,PDM2,N,ALPHA,BETA,ZI)\n CONST = EIGVAL*PI+ALPHA*(ONE+ZI)*PDI-BETA*(ONE-ZI)*PDI\n CALL JACOBF (P,PD,PM1,PDM1,PM2,PDM2,N,ALPHA,BETA,Z)\n HGLJD = (ONE-Z**2)*PD/(CONST*(Z-ZI))\n RETURN\n END\nC\n SUBROUTINE DGJ (D,DT,Z,NZ,NZD,ALPHA,BETA)\nC-----------------------------------------------------------------\nC\nC Compute the derivative matrix D and its transpose DT\nC associated with the Nth order Lagrangian interpolants\nC through the NZ Gauss Jacobi points Z.\nC Note: D and DT are square matrices.\nC Single precision version.\nC\nC-----------------------------------------------------------------\n PARAMETER (NMAX=84)\n PARAMETER (NZDD = NMAX)\n REAL*8 DD(NZDD,NZDD),DTD(NZDD,NZDD),ZD(NZDD)\n REAL D(NZD,NZD),DT(NZD,NZD),Z(1),ALPHA,BETA\nC\n IF (NZ.LE.0) THEN\n WRITE (6,*) 'DGJ: Minimum number of Gauss points is 1'\n call exitt(1)\n ENDIF\n IF (NZ .GT. NMAX) THEN\n WRITE (6,*) 'Too large polynomial degree in DGJ'\n WRITE (6,*) 'Maximum polynomial degree is',NMAX\n WRITE (6,*) 'Here Nz=',Nz\n call exitt(1)\n ENDIF\n IF ((ALPHA.LE.-1.).OR.(BETA.LE.-1.)) THEN\n WRITE (6,*) 'DGJ: Alpha and Beta must be greater than -1'\n call exitt(1)\n ENDIF\n ALPHAD = ALPHA\n BETAD = BETA\n DO 100 I=1,NZ\n ZD(I) = Z(I)\n 100 CONTINUE\n CALL DGJD (DD,DTD,ZD,NZ,NZDD,ALPHAD,BETAD)\n DO 200 I=1,NZ\n DO 200 J=1,NZ\n D(I,J) = DD(I,J)\n DT(I,J) = DTD(I,J)\n 200 CONTINUE\n RETURN\n END\nC\n SUBROUTINE DGJD (D,DT,Z,NZ,NZD,ALPHA,BETA)\nC-----------------------------------------------------------------\nC\nC Compute the derivative matrix D and its transpose DT\nC associated with the Nth order Lagrangian interpolants\nC through the NZ Gauss Jacobi points Z.\nC Note: D and DT are square matrices.\nC Double precision version.\nC\nC-----------------------------------------------------------------\n IMPLICIT REAL*8 (A-H,O-Z)\n REAL*8 D(NZD,NZD),DT(NZD,NZD),Z(1),ALPHA,BETA\n N = NZ-1\n DN = ((N))\n ONE = 1.\n TWO = 2.\nC\n IF (NZ.LE.1) THEN\n WRITE (6,*) 'DGJD: Minimum number of Gauss-Lobatto points is 2'\n call exitt(1)\n ENDIF\n IF ((ALPHA.LE.-ONE).OR.(BETA.LE.-ONE)) THEN\n WRITE (6,*) 'DGJD: Alpha and Beta must be greater than -1'\n call exitt(1)\n ENDIF\nC\n DO 200 I=1,NZ\n DO 200 J=1,NZ\n CALL JACOBF (PI,PDI,PM1,PDM1,PM2,PDM2,NZ,ALPHA,BETA,Z(I))\n CALL JACOBF (PJ,PDJ,PM1,PDM1,PM2,PDM2,NZ,ALPHA,BETA,Z(J))\n IF (I.NE.J) D(I,J) = PDI/(PDJ*(Z(I)-Z(J)))\n IF (I.EQ.J) D(I,J) = ((ALPHA+BETA+TWO)*Z(I)+ALPHA-BETA)/\n $ (TWO*(ONE-Z(I)**2))\n DT(J,I) = D(I,J)\n 200 CONTINUE\n RETURN\n END\nC\n SUBROUTINE DGLJ (D,DT,Z,NZ,NZD,ALPHA,BETA)\nC-----------------------------------------------------------------\nC\nC Compute the derivative matrix D and its transpose DT\nC associated with the Nth order Lagrangian interpolants\nC through the NZ Gauss-Lobatto Jacobi points Z.\nC Note: D and DT are square matrices.\nC Single precision version.\nC\nC-----------------------------------------------------------------\n PARAMETER (NMAX=84)\n PARAMETER (NZDD = NMAX)\n REAL*8 DD(NZDD,NZDD),DTD(NZDD,NZDD),ZD(NZDD)\n REAL D(NZD,NZD),DT(NZD,NZD),Z(1),ALPHA,BETA\nC\n IF (NZ.LE.1) THEN\n WRITE (6,*) 'DGLJ: Minimum number of Gauss-Lobatto points is 2'\n call exitt(1)\n ENDIF\n IF (NZ .GT. NMAX) THEN\n WRITE (6,*) 'Too large polynomial degree in DGLJ'\n WRITE (6,*) 'Maximum polynomial degree is',NMAX\n WRITE (6,*) 'Here NZ=',NZ\n call exitt(1)\n ENDIF\n IF ((ALPHA.LE.-1.).OR.(BETA.LE.-1.)) THEN\n WRITE (6,*) 'DGLJ: Alpha and Beta must be greater than -1'\n call exitt(1)\n ENDIF\n ALPHAD = ALPHA\n BETAD = BETA\n DO 100 I=1,NZ\n ZD(I) = Z(I)\n 100 CONTINUE\n CALL DGLJD (DD,DTD,ZD,NZ,NZDD,ALPHAD,BETAD)\n DO 200 I=1,NZ\n DO 200 J=1,NZ\n D(I,J) = DD(I,J)\n DT(I,J) = DTD(I,J)\n 200 CONTINUE\n RETURN\n END\nC\n SUBROUTINE DGLJD (D,DT,Z,NZ,NZD,ALPHA,BETA)\nC-----------------------------------------------------------------\nC\nC Compute the derivative matrix D and its transpose DT\nC associated with the Nth order Lagrangian interpolants\nC through the NZ Gauss-Lobatto Jacobi points Z.\nC Note: D and DT are square matrices.\nC Double precision version.\nC\nC-----------------------------------------------------------------\n IMPLICIT REAL*8 (A-H,O-Z)\n REAL*8 D(NZD,NZD),DT(NZD,NZD),Z(1),ALPHA,BETA\n N = NZ-1\n DN = ((N))\n ONE = 1.\n TWO = 2.\n EIGVAL = -DN*(DN+ALPHA+BETA+ONE)\nC\n IF (NZ.LE.1) THEN\n WRITE (6,*) 'DGLJD: Minimum number of Gauss-Lobatto points is 2'\n call exitt(1)\n ENDIF\n IF ((ALPHA.LE.-ONE).OR.(BETA.LE.-ONE)) THEN\n WRITE (6,*) 'DGLJD: Alpha and Beta must be greater than -1'\n call exitt(1)\n ENDIF\nC\n DO 200 I=1,NZ\n DO 200 J=1,NZ\n CALL JACOBF (PI,PDI,PM1,PDM1,PM2,PDM2,N,ALPHA,BETA,Z(I))\n CALL JACOBF (PJ,PDJ,PM1,PDM1,PM2,PDM2,N,ALPHA,BETA,Z(J))\n CI = EIGVAL*PI-(BETA*(ONE-Z(I))-ALPHA*(ONE+Z(I)))*PDI\n CJ = EIGVAL*PJ-(BETA*(ONE-Z(J))-ALPHA*(ONE+Z(J)))*PDJ\n IF (I.NE.J) D(I,J) = CI/(CJ*(Z(I)-Z(J)))\n IF ((I.EQ.J).AND.(I.NE.1).AND.(I.NE.NZ))\n $ D(I,J) = (ALPHA*(ONE+Z(I))-BETA*(ONE-Z(I)))/\n $ (TWO*(ONE-Z(I)**2))\n IF ((I.EQ.J).AND.(I.EQ.1))\n $ D(I,J) = (EIGVAL+ALPHA)/(TWO*(BETA+TWO))\n IF ((I.EQ.J).AND.(I.EQ.NZ))\n $ D(I,J) = -(EIGVAL+BETA)/(TWO*(ALPHA+TWO))\n DT(J,I) = D(I,J)\n 200 CONTINUE\n RETURN\n END\nC\n SUBROUTINE DGLL (D,DT,Z,NZ,NZD)\nC-----------------------------------------------------------------\nC\nC Compute the derivative matrix D and its transpose DT\nC associated with the Nth order Lagrangian interpolants\nC through the NZ Gauss-Lobatto Legendre points Z.\nC Note: D and DT are square matrices.\nC\nC-----------------------------------------------------------------\n PARAMETER (NMAX=84)\n REAL D(NZD,NZD),DT(NZD,NZD),Z(1)\n N = NZ-1\n IF (NZ .GT. NMAX) THEN\n WRITE (6,*) 'Subroutine DGLL'\n WRITE (6,*) 'Maximum polynomial degree =',NMAX\n WRITE (6,*) 'Polynomial degree =',NZ\n ENDIF\n IF (NZ .EQ. 1) THEN\n D(1,1) = 0.\n RETURN\n ENDIF\n FN = (N)\n d0 = FN*(FN+1.)/4.\n DO 200 I=1,NZ\n DO 200 J=1,NZ\n D(I,J) = 0.\n IF (I.NE.J) D(I,J) = PNLEG(Z(I),N)/\n $ (PNLEG(Z(J),N)*(Z(I)-Z(J)))\n IF ((I.EQ.J).AND.(I.EQ.1)) D(I,J) = -d0\n IF ((I.EQ.J).AND.(I.EQ.NZ)) D(I,J) = d0\n DT(J,I) = D(I,J)\n 200 CONTINUE\n RETURN\n END\nC\n REAL FUNCTION HGLL (I,Z,ZGLL,NZ)\nC---------------------------------------------------------------------\nC\nC Compute the value of the Lagrangian interpolant L through\nC the NZ Gauss-Lobatto Legendre points ZGLL at the point Z.\nC\nC---------------------------------------------------------------------\n REAL ZGLL(1)\n EPS = 1.E-5\n DZ = Z - ZGLL(I)\n IF (ABS(DZ) .LT. EPS) THEN\n HGLL = 1.\n RETURN\n ENDIF\n N = NZ - 1\n ALFAN = (N)*((N)+1.)\n HGLL = - (1.-Z*Z)*PNDLEG(Z,N)/\n $ (ALFAN*PNLEG(ZGLL(I),N)*(Z-ZGLL(I)))\n RETURN\n END\nC\n REAL FUNCTION HGL (I,Z,ZGL,NZ)\nC---------------------------------------------------------------------\nC\nC Compute the value of the Lagrangian interpolant HGL through\nC the NZ Gauss Legendre points ZGL at the point Z.\nC\nC---------------------------------------------------------------------\n REAL ZGL(1)\n EPS = 1.E-5\n DZ = Z - ZGL(I)\n IF (ABS(DZ) .LT. EPS) THEN\n HGL = 1.\n RETURN\n ENDIF\n N = NZ-1\n HGL = PNLEG(Z,NZ)/(PNDLEG(ZGL(I),NZ)*(Z-ZGL(I)))\n RETURN\n END\nC\n REAL FUNCTION PNLEG (Z,N)\nC---------------------------------------------------------------------\nC\nC Compute the value of the Nth order Legendre polynomial at Z.\nC (Simpler than JACOBF)\nC Based on the recursion formula for the Legendre polynomials.\nC\nC---------------------------------------------------------------------\nC\nC This next statement is to overcome the underflow bug in the i860. \nC It can be removed at a later date. 11 Aug 1990 pff.\nC\n IF(ABS(Z) .LT. 1.0E-25) Z = 0.0\nC\n P1 = 1.\n IF (N.EQ.0) THEN\n PNLEG = P1\n RETURN\n ENDIF\n P2 = Z\n P3 = P2\n DO 10 K = 1, N-1\n FK = (K)\n P3 = ((2.*FK+1.)*Z*P2 - FK*P1)/(FK+1.)\n P1 = P2\n P2 = P3\n 10 CONTINUE\n PNLEG = P3\n if (n.eq.0) pnleg = 1.\n RETURN\n END\nC\n REAL FUNCTION PNDLEG (Z,N)\nC----------------------------------------------------------------------\nC\nC Compute the derivative of the Nth order Legendre polynomial at Z.\nC (Simpler than JACOBF)\nC Based on the recursion formula for the Legendre polynomials.\nC\nC----------------------------------------------------------------------\n P1 = 1.\n P2 = Z\n P1D = 0.\n P2D = 1.\n P3D = 1.\n DO 10 K = 1, N-1\n FK = (K)\n P3 = ((2.*FK+1.)*Z*P2 - FK*P1)/(FK+1.)\n P3D = ((2.*FK+1.)*P2 + (2.*FK+1.)*Z*P2D - FK*P1D)/(FK+1.)\n P1 = P2\n P2 = P3\n P1D = P2D\n P2D = P3D\n 10 CONTINUE\n PNDLEG = P3D\n IF (N.eq.0) pndleg = 0.\n RETURN\n END\nC\n SUBROUTINE DGLLGL (D,DT,ZM1,ZM2,IM12,NZM1,NZM2,ND1,ND2)\nC-----------------------------------------------------------------------\nC\nC Compute the (one-dimensional) derivative matrix D and its\nC transpose DT associated with taking the derivative of a variable\nC expanded on a Gauss-Lobatto Legendre mesh (M1), and evaluate its\nC derivative on a Guass Legendre mesh (M2).\nC Need the one-dimensional interpolation operator IM12\nC (see subroutine IGLLGL).\nC Note: D and DT are rectangular matrices.\nC\nC-----------------------------------------------------------------------\n REAL D(ND2,ND1), DT(ND1,ND2), ZM1(ND1), ZM2(ND2), IM12(ND2,ND1)\n IF (NZM1.EQ.1) THEN\n D (1,1) = 0.\n DT(1,1) = 0.\n RETURN\n ENDIF\n EPS = 1.E-6\n NM1 = NZM1-1\n DO 10 IP = 1, NZM2\n DO 10 JQ = 1, NZM1\n ZP = ZM2(IP)\n ZQ = ZM1(JQ)\n IF ((ABS(ZP) .LT. EPS).AND.(ABS(ZQ) .LT. EPS)) THEN\n D(IP,JQ) = 0.\n ELSE\n D(IP,JQ) = (PNLEG(ZP,NM1)/PNLEG(ZQ,NM1)\n $ -IM12(IP,JQ))/(ZP-ZQ)\n ENDIF\n DT(JQ,IP) = D(IP,JQ)\n 10 CONTINUE\n RETURN\n END\nC\n SUBROUTINE DGLJGJ (D,DT,ZGL,ZG,IGLG,NPGL,NPG,ND1,ND2,ALPHA,BETA)\nC-----------------------------------------------------------------------\nC\nC Compute the (one-dimensional) derivative matrix D and its\nC transpose DT associated with taking the derivative of a variable\nC expanded on a Gauss-Lobatto Jacobi mesh (M1), and evaluate its\nC derivative on a Guass Jacobi mesh (M2).\nC Need the one-dimensional interpolation operator IM12\nC (see subroutine IGLJGJ).\nC Note: D and DT are rectangular matrices.\nC Single precision version.\nC\nC-----------------------------------------------------------------------\n REAL D(ND2,ND1), DT(ND1,ND2), ZGL(ND1), ZG(ND2), IGLG(ND2,ND1)\n PARAMETER (NMAX=84)\n PARAMETER (NDD = NMAX)\n REAL*8 DD(NDD,NDD), DTD(NDD,NDD)\n REAL*8 ZGD(NDD), ZGLD(NDD), IGLGD(NDD,NDD)\n REAL*8 ALPHAD, BETAD\nC\n IF (NPGL.LE.1) THEN\n WRITE(6,*) 'DGLJGJ: Minimum number of Gauss-Lobatto points is 2'\n call exitt(1)\n ENDIF\n IF (NPGL.GT.NMAX) THEN\n WRITE(6,*) 'Polynomial degree too high in DGLJGJ'\n WRITE(6,*) 'Maximum polynomial degree is',NMAX\n WRITE(6,*) 'Here NPGL=',NPGL\n call exitt(1)\n ENDIF\n IF ((ALPHA.LE.-1.).OR.(BETA.LE.-1.)) THEN\n WRITE(6,*) 'DGLJGJ: Alpha and Beta must be greater than -1'\n call exitt(1)\n ENDIF\nC\n ALPHAD = ALPHA\n BETAD = BETA\n DO 100 I=1,NPG\n ZGD(I) = ZG(I)\n DO 100 J=1,NPGL\n IGLGD(I,J) = IGLG(I,J)\n 100 CONTINUE\n DO 200 I=1,NPGL\n ZGLD(I) = ZGL(I)\n 200 CONTINUE\n CALL DGLJGJD (DD,DTD,ZGLD,ZGD,IGLGD,NPGL,NPG,NDD,NDD,ALPHAD,BETAD)\n DO 300 I=1,NPG\n DO 300 J=1,NPGL\n D(I,J) = DD(I,J)\n DT(J,I) = DTD(J,I)\n 300 CONTINUE\n RETURN\n END\nC\n SUBROUTINE DGLJGJD (D,DT,ZGL,ZG,IGLG,NPGL,NPG,ND1,ND2,ALPHA,BETA)\nC-----------------------------------------------------------------------\nC\nC Compute the (one-dimensional) derivative matrix D and its\nC transpose DT associated with taking the derivative of a variable\nC expanded on a Gauss-Lobatto Jacobi mesh (M1), and evaluate its\nC derivative on a Guass Jacobi mesh (M2).\nC Need the one-dimensional interpolation operator IM12\nC (see subroutine IGLJGJ).\nC Note: D and DT are rectangular matrices.\nC Double precision version.\nC\nC-----------------------------------------------------------------------\n IMPLICIT REAL*8 (A-H,O-Z)\n REAL*8 D(ND2,ND1), DT(ND1,ND2), ZGL(ND1), ZG(ND2)\n REAL*8 IGLG(ND2,ND1), ALPHA, BETA\nC\n IF (NPGL.LE.1) THEN\n WRITE(6,*) 'DGLJGJD: Minimum number of Gauss-Lobatto points is 2'\n call exitt(1)\n ENDIF\n IF ((ALPHA.LE.-1.).OR.(BETA.LE.-1.)) THEN\n WRITE(6,*) 'DGLJGJD: Alpha and Beta must be greater than -1'\n call exitt(1)\n ENDIF\nC\n EPS = 1.e-6\n ONE = 1.\n TWO = 2.\n NGL = NPGL-1\n DN = ((NGL))\n EIGVAL = -DN*(DN+ALPHA+BETA+ONE)\nC\n DO 100 I=1,NPG\n DO 100 J=1,NPGL\n DZ = ABS(ZG(I)-ZGL(J))\n IF (DZ.LT.EPS) THEN\n D(I,J) = (ALPHA*(ONE+ZG(I))-BETA*(ONE-ZG(I)))/\n $ (TWO*(ONE-ZG(I)**2))\n ELSE\n CALL JACOBF (PI,PDI,PM1,PDM1,PM2,PDM2,NGL,ALPHA,BETA,ZG(I))\n CALL JACOBF (PJ,PDJ,PM1,PDM1,PM2,PDM2,NGL,ALPHA,BETA,ZGL(J))\n FACI = ALPHA*(ONE+ZG(I))-BETA*(ONE-ZG(I))\n FACJ = ALPHA*(ONE+ZGL(J))-BETA*(ONE-ZGL(J))\n CONST = EIGVAL*PJ+FACJ*PDJ\n D(I,J) = ((EIGVAL*PI+FACI*PDI)*(ZG(I)-ZGL(J))\n $ -(ONE-ZG(I)**2)*PDI)/(CONST*(ZG(I)-ZGL(J))**2)\n ENDIF\n DT(J,I) = D(I,J)\n 100 CONTINUE\n RETURN\n END\nC\n SUBROUTINE IGLM (I12,IT12,Z1,Z2,NZ1,NZ2,ND1,ND2)\nC----------------------------------------------------------------------\nC\nC Compute the one-dimensional interpolation operator (matrix) I12\nC ands its transpose IT12 for interpolating a variable from a\nC Gauss Legendre mesh (1) to a another mesh M (2).\nC Z1 : NZ1 Gauss Legendre points.\nC Z2 : NZ2 points on mesh M.\nC\nC--------------------------------------------------------------------\n REAL I12(ND2,ND1),IT12(ND1,ND2),Z1(ND1),Z2(ND2)\n IF (NZ1 .EQ. 1) THEN\n I12 (1,1) = 1.\n IT12(1,1) = 1.\n RETURN\n ENDIF\n DO 10 I=1,NZ2\n ZI = Z2(I)\n DO 10 J=1,NZ1\n I12 (I,J) = HGL(J,ZI,Z1,NZ1)\n IT12(J,I) = I12(I,J)\n 10 CONTINUE\n RETURN\n END\nc\n SUBROUTINE IGLLM (I12,IT12,Z1,Z2,NZ1,NZ2,ND1,ND2)\nC----------------------------------------------------------------------\nC\nC Compute the one-dimensional interpolation operator (matrix) I12\nC ands its transpose IT12 for interpolating a variable from a\nC Gauss-Lobatto Legendre mesh (1) to a another mesh M (2).\nC Z1 : NZ1 Gauss-Lobatto Legendre points.\nC Z2 : NZ2 points on mesh M.\nC\nC--------------------------------------------------------------------\n REAL I12(ND2,ND1),IT12(ND1,ND2),Z1(ND1),Z2(ND2)\n IF (NZ1 .EQ. 1) THEN\n I12 (1,1) = 1.\n IT12(1,1) = 1.\n RETURN\n ENDIF\n DO 10 I=1,NZ2\n ZI = Z2(I)\n DO 10 J=1,NZ1\n I12 (I,J) = HGLL(J,ZI,Z1,NZ1)\n IT12(J,I) = I12(I,J)\n 10 CONTINUE\n RETURN\n END\nC\n SUBROUTINE IGJM (I12,IT12,Z1,Z2,NZ1,NZ2,ND1,ND2,ALPHA,BETA)\nC----------------------------------------------------------------------\nC\nC Compute the one-dimensional interpolation operator (matrix) I12\nC ands its transpose IT12 for interpolating a variable from a\nC Gauss Jacobi mesh (1) to a another mesh M (2).\nC Z1 : NZ1 Gauss Jacobi points.\nC Z2 : NZ2 points on mesh M.\nC Single precision version.\nC\nC--------------------------------------------------------------------\n REAL I12(ND2,ND1),IT12(ND1,ND2),Z1(ND1),Z2(ND2)\n IF (NZ1 .EQ. 1) THEN\n I12 (1,1) = 1.\n IT12(1,1) = 1.\n RETURN\n ENDIF\n DO 10 I=1,NZ2\n ZI = Z2(I)\n DO 10 J=1,NZ1\n I12 (I,J) = HGJ(J,ZI,Z1,NZ1,ALPHA,BETA)\n IT12(J,I) = I12(I,J)\n 10 CONTINUE\n RETURN\n END\nc\n SUBROUTINE IGLJM (I12,IT12,Z1,Z2,NZ1,NZ2,ND1,ND2,ALPHA,BETA)\nC----------------------------------------------------------------------\nC\nC Compute the one-dimensional interpolation operator (matrix) I12\nC ands its transpose IT12 for interpolating a variable from a\nC Gauss-Lobatto Jacobi mesh (1) to a another mesh M (2).\nC Z1 : NZ1 Gauss-Lobatto Jacobi points.\nC Z2 : NZ2 points on mesh M.\nC Single precision version.\nC\nC--------------------------------------------------------------------\n REAL I12(ND2,ND1),IT12(ND1,ND2),Z1(ND1),Z2(ND2)\n IF (NZ1 .EQ. 1) THEN\n I12 (1,1) = 1.\n IT12(1,1) = 1.\n RETURN\n ENDIF\n DO 10 I=1,NZ2\n ZI = Z2(I)\n DO 10 J=1,NZ1\n I12 (I,J) = HGLJ(J,ZI,Z1,NZ1,ALPHA,BETA)\n IT12(J,I) = I12(I,J)\n 10 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "ca40fb1824096527187631170419c39db90b8e71", "size": 36995, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/speclib.f", "max_stars_repo_name": "EPCCed/nekbarebone", "max_stars_repo_head_hexsha": "84aaeee7a6dff762fdac127a9e00f629f1f5c427", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-06-22T05:27:05.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-22T05:27:05.000Z", "max_issues_repo_path": "src/speclib.f", "max_issues_repo_name": "EPCCed/nekbarebone", "max_issues_repo_head_hexsha": "84aaeee7a6dff762fdac127a9e00f629f1f5c427", "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/speclib.f", "max_forks_repo_name": "EPCCed/nekbarebone", "max_forks_repo_head_hexsha": "84aaeee7a6dff762fdac127a9e00f629f1f5c427", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.4316057774, "max_line_length": 82, "alphanum_fraction": 0.4864170834, "num_tokens": 12567, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479466, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6783700563555323}} {"text": " subroutine chobk1(kb,loads)\r\n!Choleski back-substitution\r\n implicit none\r\n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\r\n REAL(iwp),intent(in)::kb(:,:)\r\n REAL(iwp),intent(in out)::loads(0:)\r\n integer::iw,n,i,j,k\r\n REAL(iwp)::x\r\n n=size(kb,1)\r\n iw=size(kb,2)-1\r\n loads(1)=loads(1)/kb(1,iw+1)\r\n do i=2,n\r\n x=.0\r\n k=1\r\n if(i<=iw+1)k=iw-i+2\r\n do j=k,iw\r\n x=x+kb(i,j)*loads(i+j-iw-1)\r\n end do\r\n loads(i)=(loads(i)-x)/kb(i,iw+1)\r\n end do\r\nreturn\r\nend subroutine chobk1\r\n\r\n\r\n", "meta": {"hexsha": "5f7cd10239fb1d990f8e4581e80fe42486f59172", "size": 486, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "src/libs/main/chobk1.f03", "max_stars_repo_name": "leemargetts/PoreFEM", "max_stars_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/libs/main/chobk1.f03", "max_issues_repo_name": "leemargetts/PoreFEM", "max_issues_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/libs/main/chobk1.f03", "max_forks_repo_name": "leemargetts/PoreFEM", "max_forks_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.44, "max_line_length": 47, "alphanum_fraction": 0.6008230453, "num_tokens": 192, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888302, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6783566533127713}} {"text": " SUBROUTINE kendl1(data1,data2,n,tau,z,prob)\r\n INTEGER n\r\n REAL prob,tau,z,data1(n),data2(n)\r\nCU USES erfcc\r\n INTEGER is,j,k,n1,n2\r\n REAL a1,a2,aa,var,erfcc\r\n n1=0\r\n n2=0\r\n is=0\r\n do 12 j=1,n-1\r\n do 11 k=j+1,n\r\n a1=data1(j)-data1(k)\r\n a2=data2(j)-data2(k)\r\n aa=a1*a2\r\n if(aa.ne.0.)then\r\n n1=n1+1\r\n n2=n2+1\r\n if(aa.gt.0.)then\r\n is=is+1\r\n else\r\n is=is-1\r\n endif\r\n else\r\n if(a1.ne.0.)n1=n1+1\r\n if(a2.ne.0.)n2=n2+1\r\n endif\r\n11 continue\r\n12 continue\r\n tau=float(is)/sqrt(float(n1)*float(n2))\r\n var=(4.*n+10.)/(9.*n*(n-1.))\r\n z=tau/sqrt(var)\r\n prob=erfcc(abs(z)/1.4142136)\r\n return\r\n END\r\n", "meta": {"hexsha": "abeb0a472af875bb0aa9549dffb0d6a4fd9d4c25", "size": 833, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/kendl1.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/kendl1.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/kendl1.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.8, "max_line_length": 50, "alphanum_fraction": 0.424969988, "num_tokens": 290, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545333502202, "lm_q2_score": 0.7154239957834733, "lm_q1q2_score": 0.6783325048696289}} {"text": " SUBROUTINE NF01BY( CJTE, NSMP, NZ, L, IPAR, LIPAR, WB, LWB, Z,\n $ LDZ, E, J, LDJ, JTE, DWORK, LDWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute the Jacobian of the error function for a neural network\nC of the structure\nC\nC - tanh(w1*z+b1) -\nC / : \\\nC z --- : --- sum(ws(i)*...)+ b(n+1) --- y,\nC \\ : /\nC - tanh(wn*z+bn) -\nC\nC for the single-output case. The Jacobian has the form\nC\nC d e(1) / d WB(1) ... d e(1) / d WB(NWB)\nC J = : : ,\nC d e(NSMP) / d WB(1) ... d e(NSMP) / d WB(NWB)\nC\nC where e(z) is the error function, WB is the set of weights and\nC biases of the network (for the considered output), and NWB is\nC the number of elements of this set, NWB = IPAR(1)*(NZ+2)+1\nC (see below).\nC\nC In the multi-output case, this routine should be called for each\nC output.\nC\nC NOTE: this routine must have the same arguments as SLICOT Library\nC routine NF01BD.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC CJTE CHARACTER*1\nC Specifies whether the matrix-vector product J'*e should be\nC computed or not, as follows:\nC = 'C' : compute J'*e;\nC = 'N' : do not compute J'*e.\nC\nC Input/Output Parameters\nC\nC NSMP (input) INTEGER\nC The number of training samples. NSMP >= 0.\nC\nC NZ (input) INTEGER\nC The length of each input sample. NZ >= 0.\nC\nC L (input) INTEGER\nC The length of each output sample.\nC Currently, L must be 1.\nC\nC IPAR (input/output) INTEGER array, dimension (LIPAR)\nC The integer parameters needed.\nC On entry, the first element of this array must contain\nC a value related to the number of neurons, n; specifically,\nC n = abs(IPAR(1)), since setting IPAR(1) < 0 has a special\nC meaning (see below).\nC On exit, if IPAR(1) < 0 on entry, then no computations are\nC performed, except the needed tests on input parameters,\nC but the following values are returned:\nC IPAR(1) contains the length of the array J, LJ;\nC LDJ contains the leading dimension of array J.\nC Otherwise, IPAR(1) and LDJ are unchanged on exit.\nC\nC LIPAR (input) INTEGER\nC The length of the vector IPAR. LIPAR >= 1.\nC\nC WB (input) DOUBLE PRECISION array, dimension (LWB)\nC The leading NWB = IPAR(1)*(NZ+2)+1 part of this array\nC must contain the weights and biases of the network,\nC WB = ( w(1,1), ..., w(1,NZ), ..., w(n,1), ..., w(n,NZ),\nC ws(1), ..., ws(n), b(1), ..., b(n+1) ),\nC where w(i,j) are the weights of the hidden layer,\nC ws(i) are the weights of the linear output layer and\nC b(i) are the biases.\nC\nC LWB (input) INTEGER\nC The length of array WB. LWB >= NWB.\nC\nC Z (input) DOUBLE PRECISION array, dimension (LDZ, NZ)\nC The leading NSMP-by-NZ part of this array must contain the\nC set of input samples,\nC Z = ( Z(1,1),...,Z(1,NZ); ...; Z(NSMP,1),...,Z(NSMP,NZ) ).\nC\nC LDZ INTEGER\nC The leading dimension of array Z. LDZ >= MAX(1,NSMP).\nC\nC E (input) DOUBLE PRECISION array, dimension (NSMP)\nC If CJTE = 'C', this array must contain the error vector e.\nC If CJTE = 'N', this array is not referenced.\nC\nC J (output) DOUBLE PRECISION array, dimension (LDJ, NWB)\nC The leading NSMP-by-NWB part of this array contains the\nC Jacobian of the error function.\nC\nC LDJ INTEGER\nC The leading dimension of array J. LDJ >= MAX(1,NSMP).\nC Note that LDJ is an input parameter, except for\nC IPAR(1) < 0 on entry, when it is an output parameter.\nC\nC JTE (output) DOUBLE PRECISION array, dimension (NWB)\nC If CJTE = 'C', this array contains the matrix-vector\nC product J'*e.\nC If CJTE = 'N', this array is not referenced.\nC\nC Workspace\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC This argument is included for combatibility with SLICOT\nC Library routine NF01BD.\nC\nC LDWORK INTEGER\nC Normally, the length of the array DWORK. LDWORK >= 0.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value.\nC\nC METHOD\nC\nC The Jacobian is computed analytically.\nC\nC CONTRIBUTORS\nC\nC A. Riedel, R. Schneider, Chemnitz University of Technology,\nC Oct. 2000, during a stay at University of Twente, NL.\nC V. Sima, Research Institute for Informatics, Bucharest, Mar. 2001.\nC\nC REVISIONS\nC\nC -\nC\nC KEYWORDS\nC\nC Input output description, neural network, nonlinear system,\nC optimization, system response.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, ONE, TWO\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0, TWO = 2.0D0 )\nC .. Scalar Arguments ..\n CHARACTER CJTE\n INTEGER INFO, L, LDJ, LDWORK, LDZ, LIPAR, LWB, NSMP, NZ\nC .. Array Arguments ..\n DOUBLE PRECISION DWORK(*), E(*), J(LDJ,*), JTE(*), WB(*),\n $ Z(LDZ,*)\n INTEGER IPAR(*)\nC .. Local Scalars ..\n LOGICAL WJTE\n INTEGER BP1, DI, I, IB, K, M, NN, NWB, WS\n DOUBLE PRECISION BIGNUM, SMLNUM, TMP\nC .. External Functions ..\n DOUBLE PRECISION DLAMCH\n LOGICAL LSAME\n EXTERNAL DLAMCH, LSAME\nC .. External Subroutines ..\n EXTERNAL DCOPY, DGEMM, DGEMV, DLABAD, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC ABS, EXP, LOG, MAX, MIN\nC ..\nC .. Executable Statements ..\nC\n WJTE = LSAME( CJTE, 'C' )\n INFO = 0\n NN = IPAR(1)\n NWB = NN*( NZ + 2 ) + 1\n IF( .NOT.( WJTE .OR. LSAME( CJTE, 'N' ) ) ) THEN\n INFO = -1\n ELSEIF ( NSMP.LT.0 ) THEN\n INFO = -2\n ELSEIF ( NZ.LT.0 ) THEN\n INFO = -3\n ELSEIF ( L.NE.1 ) THEN\n INFO = -4\n ELSEIF ( LIPAR.LT.1 ) THEN\n INFO = -6\n ELSEIF ( IPAR(1).LT.0 ) THEN\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'NF01BY', -INFO )\n ELSE\n IPAR(1) = NSMP*( ABS( NN )*( NZ + 2 ) + 1 )\n LDJ = NSMP\n ENDIF\n RETURN\n ELSEIF ( LWB.LT.NWB ) THEN\n INFO = -8\n ELSEIF ( LDZ.LT.MAX( 1, NSMP ) ) THEN\n INFO = -10\n ELSEIF ( LDJ.LT.MAX( 1, NSMP ) ) THEN\n INFO = -13\n ENDIF\nC\nC Return if there are illegal arguments.\nC\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'NF01BY', -INFO )\n RETURN\n ENDIF\nC\nC Quick return if possible.\nC\n IF ( MIN( NSMP, NZ ).EQ.0 )\n $ RETURN\nC\nC Set parameters to avoid overflows and increase accuracy for\nC extreme values.\nC\n SMLNUM = DLAMCH( 'Safe minimum' ) / DLAMCH( 'Precision' )\n BIGNUM = ONE / SMLNUM\n CALL DLABAD( SMLNUM, BIGNUM )\n SMLNUM = LOG( SMLNUM )\n BIGNUM = LOG( BIGNUM )\nC\n WS = NZ*NN + 1\n IB = WS + NN\n BP1 = IB + NN\nC\n J(1, BP1) = ONE\n CALL DCOPY( NSMP, J(1, BP1), 0, J(1, BP1), 1 )\nC\n DO 10 I = 0, NN - 1\n CALL DCOPY( NSMP, WB(IB+I), 0, J(1, WS+I), 1 )\n 10 CONTINUE\nC\n CALL DGEMM( 'NoTranspose', 'NoTranspose', NSMP, NN, NZ, -TWO, Z,\n $ LDZ, WB, NZ, -TWO, J(1, WS), LDJ )\n DI = 1\nC\n DO 50 I = 0, NN - 1\nC\n DO 20 K = 1, NSMP\n TMP = J(K, WS+I)\n IF ( ABS( TMP ).GE.BIGNUM ) THEN\n IF ( TMP.GT.ZERO ) THEN\n J(K, WS+I) = -ONE\n ELSE\n J(K, WS+I) = ONE\n END IF\n ELSE IF ( ABS( TMP ).LE.SMLNUM ) THEN\n J(K, WS+I) = ZERO\n ELSE\n J(K, WS+I) = TWO/( ONE + EXP( TMP ) ) - ONE\n END IF\n J(K, IB+I) = WB(WS+I)*( ONE - J(K, WS+I)**2 )\n 20 CONTINUE\nC\n DO 40 K = 0, NZ - 1\nC\n DO 30 M = 1, NSMP\n J(M, DI+K) = J(M, IB+I)*Z(M, K+1)\n 30 CONTINUE\nC\n 40 CONTINUE\nC\n DI = DI + NZ\n 50 CONTINUE\nC\n IF ( WJTE ) THEN\nC\nC Compute J'e.\nC\n CALL DGEMV( 'Transpose', NSMP, NWB, ONE, J, LDJ, E, 1, ZERO,\n $ JTE, 1 )\n END IF\nC\n RETURN\nC\nC *** Last line of NF01BY ***\n END\n", "meta": {"hexsha": "e768d2887e3826d7b3125214e0b6eb6e4e602c8e", "size": 8895, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/NF01BY.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/NF01BY.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/NF01BY.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 31.6548042705, "max_line_length": 72, "alphanum_fraction": 0.5112984823, "num_tokens": 2805, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9481545289551958, "lm_q2_score": 0.7154239897159438, "lm_q1q2_score": 0.6783324959723676}} {"text": "C\nC $Id: idgtcp.f,v 1.4 2008-07-27 00:17:30 haley Exp $\nC \nC Copyright (C) 2000\nC University Corporation for Atmospheric Research\nC All Rights Reserved\nC\nC The use of this Software is governed by a License Agreement.\nC\n SUBROUTINE IDGTCP (X1,Y1,X2,Y2,X3,Y3,XC,YC)\nC\nC This subroutine, given the coordinates of three points in the plane -\nC (X1,Y1), (X2,Y2), and (X3,Y3) - returns the coordinates of the center\nC of the circle passing through those three points: (XC,YC).\nC\n A=2.*(X1-X2)\n B=2.*(Y1-Y2)\n C=X1*X1-X2*X2+Y1*Y1-Y2*Y2\n D=2.*(X1-X3)\n E=2.*(Y1-Y3)\n F=X1*X1-X3*X3+Y1*Y1-Y3*Y3\n XC=(C*E-B*F)/(A*E-B*D)\n YC=(C*D-A*F)/(B*D-A*E)\nC\n RETURN\nC\n END\n", "meta": {"hexsha": "3660131aa8c2258bf56eb4a16b0a5b8a76c30b11", "size": 828, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ncarg2d/src/libncarg/support/idgtcp.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "ncarg2d/src/libncarg/support/idgtcp.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "ncarg2d/src/libncarg/support/idgtcp.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 29.5714285714, "max_line_length": 71, "alphanum_fraction": 0.5314009662, "num_tokens": 289, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206870747658, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6782557022270167}} {"text": " SUBROUTINE slDJCL (DJM, IY, IM, ID, FD, J)\n*+\n* - - - - -\n* D J C L\n* - - - - -\n*\n* Modified Julian Date to Gregorian year, month, day,\n* and fraction of a day.\n*\n* Given:\n* DJM dp modified Julian Date (JD-2400000.5)\n*\n* Returned:\n* IY int year\n* IM int month\n* ID int day\n* FD dp fraction of day\n* J int status:\n* 0 = OK\n* -1 = unacceptable date (before 4701BC March 1)\n*\n* The algorithm is adapted from Hatcher 1984 (QJRAS 25, 53-55).\n*\n* Last revision: 22 July 2004\n*\n* Copyright P.T.Wallace. All rights reserved.\n*\n* License:\n* This program is free software; you can redistribute it and/or modify\n* it under the terms of the GNU General Public License as published by\n* the Free Software Foundation; either version 2 of the License, or\n* (at your option) any later version.\n*\n* This program is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU General Public License for more details.\n*\n* You should have received a copy of the GNU General Public License\n* along with this program (see SLA_CONDITIONS); if not, write to the\n* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,\n* Boston, MA 02110-1301 USA\n*\n* Copyright (C) 1995 Association of Universities for Research in Astronomy Inc.\n*-\n\n IMPLICIT NONE\n\n DOUBLE PRECISION DJM\n INTEGER IY,IM,ID\n DOUBLE PRECISION FD\n INTEGER J\n\n DOUBLE PRECISION F,D\n INTEGER JD,N4,ND10\n\n\n* Check if date is acceptable.\n IF ( DJM.LE.-2395520D0 .OR. DJM.GE.1D9 ) THEN\n J = -1\n ELSE\n J = 0\n\n* Separate day and fraction.\n F = MOD(DJM,1D0)\n IF (F.LT.0D0) F = F+1D0\n D = ANINT(DJM-F)\n\n* Express day in Gregorian calendar.\n JD = NINT(D)+2400001\n\n N4 = 4*(JD+((6*((4*JD-17918)/146097))/4+1)/2-37)\n ND10 = 10*(MOD(N4-237,1461)/4)+5\n\n IY = N4/1461-4712\n IM = MOD(ND10/306+2,12)+1\n ID = MOD(ND10,306)/10+1\n FD = F\n\n J=0\n\n END IF\n\n END\n", "meta": {"hexsha": "7164ea371a7f719e3e9d95de96693aab5458c138", "size": 2271, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iraf.v2161/math/slalib/djcl.f", "max_stars_repo_name": "ysBach/irafdocgen", "max_stars_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:19:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T16:48:42.000Z", "max_issues_repo_path": "math/slalib/djcl.f", "max_issues_repo_name": "kirxkirx/iraf", "max_issues_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-30T13:48:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-02T19:40:25.000Z", "max_forks_repo_path": "math/slalib/djcl.f", "max_forks_repo_name": "kirxkirx/iraf", "max_forks_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.7176470588, "max_line_length": 80, "alphanum_fraction": 0.5825627477, "num_tokens": 696, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.901920681802153, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6782556932492282}} {"text": "c\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc . .\nc . copyright (c) 1998 by UCAR .\nc . .\nc . University Corporation for Atmospheric Research .\nc . .\nc . all rights reserved .\nc . .\nc . .\nc . SPHEREPACK .\nc . .\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc\nc\nc\nc\nc ... file slapec.f\nc\nc this file includes documentation and code for\nc subroutine slapec i\nc\nc ... files which must be loaded with slapec.f\nc\nc sphcom.f, hrfft.f, shaec.f, shsec.f\nc\nc\nc\nc subroutine slapec(nlat,nlon,isym,nt,slap,ids,jds,a,b,mdab,ndab,\nc + wshsec,lshsec,work,lwork,ierror)\nc\nc\nc given the scalar spherical harmonic coefficients a and b, precomputed\nc by subroutine shaec for a scalar field sf, subroutine slapec computes\nc the laplacian of sf in the scalar array slap. slap(i,j) is the\nc laplacian of sf at the colatitude\nc\nc theta(i) = (i-1)*pi/(nlat-1)\nc\nc and east longitude\nc\nc lambda(j) = (j-1)*2*pi/nlon\nc\nc on the sphere. i.e.\nc\nc slap(i,j) =\nc\nc 2 2\nc [1/sint*d (sf(i,j)/dlambda + d(sint*d(sf(i,j))/dtheta)/dtheta]/sint\nc\nc\nc where sint = sin(theta(i)). the scalar laplacian in slap has the\nc same symmetry or absence of symmetry about the equator as the scalar\nc field sf. the input parameters isym,nt,mdab,ndab must have the\nc same values used by shaec to compute a and b for sf. the associated\nc legendre functions are recomputed rather than stored as they are\nc in subroutine slapes.\n\nc\nc input parameters\nc\nc nlat the number of colatitudes on the full sphere including the\nc poles. for example, nlat = 37 for a five degree grid.\nc nlat determines the grid increment in colatitude as\nc pi/(nlat-1). if nlat is odd the equator is located at\nc grid point i=(nlat+1)/2. if nlat is even the equator is\nc located half way between points i=nlat/2 and i=nlat/2+1.\nc nlat must be at least 3. note: on the half sphere, the\nc number of grid points in the colatitudinal direction is\nc nlat/2 if nlat is even or (nlat+1)/2 if nlat is odd.\nc\nc nlon the number of distinct longitude points. nlon determines\nc the grid increment in longitude as 2*pi/nlon. for example\nc nlon = 72 for a five degree grid. nlon must be greater\nc than zero. the axisymmetric case corresponds to nlon=1.\nc the efficiency of the computation is improved when nlon\nc is a product of small prime numbers.\nc\nc isym this parameter should have the same value input to subroutine\nc shaec to compute the coefficients a and b for the scalar field\nc sf. isym is set as follows:\nc\nc = 0 no symmetries exist in sf about the equator. scalar\nc synthesis is used to compute slap on the entire sphere.\nc i.e., in the array slap(i,j) for i=1,...,nlat and\nc j=1,...,nlon.\nc\nc = 1 sf and slap are antisymmetric about the equator. the\nc synthesis used to compute slap is performed on the\nc northern hemisphere only. if nlat is odd, slap(i,j) is\nc computed for i=1,...,(nlat+1)/2 and j=1,...,nlon. if\nc nlat is even, slap(i,j) is computed for i=1,...,nlat/2\nc and j=1,...,nlon.\nc\nc\nc = 2 sf and slap are symmetric about the equator. the\nc synthesis used to compute slap is performed on the\nc northern hemisphere only. if nlat is odd, slap(i,j) is\nc computed for i=1,...,(nlat+1)/2 and j=1,...,nlon. if\nc nlat is even, slap(i,j) is computed for i=1,...,nlat/2\nc and j=1,...,nlon.\nc\nc\nc nt the number of analyses. in the program that calls slapec\nc the arrays slap,a, and b can be three dimensional in which\nc case multiple synthesis will be performed. the third index\nc is the synthesis index which assumes the values k=1,...,nt.\nc for a single analysis set nt=1. the description of the\nc remaining parameters is simplified by assuming that nt=1\nc or that all the arrays are two dimensional.\nc\nc ids the first dimension of the array slap as it appears in the\nc program that calls slapec. if isym = 0 then ids must be at\nc least nlat. if isym > 0 and nlat is even then ids must be\nc at least nlat/2. if isym > 0 and nlat is odd then ids must\nc be at least (nlat+1)/2.\nc\nc jds the second dimension of the array slap as it appears in the\nc program that calls slapec. jds must be at least nlon.\nc\nc\nc a,b two or three dimensional arrays (see input parameter nt)\nc that contain scalar spherical harmonic coefficients\nc of the scalar field sf as computed by subroutine shaec.\nc *** a,b must be computed by shaec prior to calling slapec.\nc\nc\nc mdab the first dimension of the arrays a and b as it appears\nc in the program that calls slapec. mdab must be at\nc least min0(nlat,(nlon+2)/2) if nlon is even or at least\nc min0(nlat,(nlon+1)/2) if nlon is odd.\nc\nc ndab the second dimension of the arrays a and b as it appears\nc in the program that calls slapec. ndbc must be at least\nc least nlat.\nc\nc mdab,ndab should have the same values input to shaec to\nc compute the coefficients a and b.\nc\nc\nc wshsec an array which must be initialized by subroutine shseci\nc before calling slapec. once initialized, wshsec\nc can be used repeatedly by slapec as long as nlat and nlon\nc remain unchanged. wshsec must not be altered between calls\nc of slapec.\nc\nc lshsec the dimension of the array wshsec as it appears in the\nc program that calls slapec. let\nc\nc l1 = min0(nlat,(nlon+2)/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc and\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc then lshsec must be greater than or equal to\nc\nc 2*nlat*l2+3*((l1-2)*(nlat+nlat-l1-1))/2+nlon+15\nc\nc\nc work a work array that does not have to be saved.\nc\nc lwork the dimension of the array work as it appears in the\nc program that calls slapec. define\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc l1 = min0(nlat,(nlon+2)/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc if isym = 0 let\nc\nc lwkmin = nlat*(2*nt*nlon+max0(6*l2,nlon)+2*nt*l1+1.\nc\nc if isym > 0 let\nc\nc lwkmin = l2*(2*nt*nlon+max0(6*nlat,nlon))+nlat*(2*nt*l1+1)\nc\nc\nc then lwork must be greater than or equal to lwkmin (see ierror=10)\nc\nc **************************************************************\nc\nc output parameters\nc\nc\nc slap a two or three dimensional arrays (see input parameter nt) that\nc contain the scalar laplacian of the scalar field sf. slap(i,j)\nc is the scalar laplacian at the colatitude\nc\nc theta(i) = (i-1)*pi/(nlat-1)\nc\nc and longitude\nc\nc lambda(j) = (j-1)*2*pi/nlon\nc\nc for i=1,...,nlat and j=1,...,nlon.\nc\nc\nc ierror a parameter which flags errors in input parameters as follows:\nc\nc = 0 no errors detected\nc\nc = 1 error in the specification of nlat\nc\nc = 2 error in the specification of nlon\nc\nc = 3 error in the specification of ityp\nc\nc = 4 error in the specification of nt\nc\nc = 5 error in the specification of ids\nc\nc = 6 error in the specification of jds\nc\nc = 7 error in the specification of mdbc\nc\nc = 8 error in the specification of ndbc\nc\nc = 9 error in the specification of lshsec\nc\nc = 10 error in the specification of lwork\nc\nc\nc **********************************************************************\nc \nc end of documentation for slapec\nc\nc **********************************************************************\nc\nc\n subroutine slapec(nlat,nlon,isym,nt,slap,ids,jds,a,b,mdab,ndab,\n + wshsec,lshsec,work,lwork,ierror)\n dimension slap(ids,jds,nt),a(mdab,ndab,nt),b(mdab,ndab,nt)\n dimension wshsec(lshsec),work(lwork)\nc\nc check input parameters\nc\n ierror = 1\n if(nlat .lt. 3) return\n ierror = 2\n if(nlon .lt. 4) return\n ierror = 3\n if (isym.lt.0 .or. isym.gt.2) return\n ierror = 4\n if(nt .lt. 0) return\n ierror = 5\n imid = (nlat+1)/2\n if((isym.eq.0 .and. ids.lt.nlat) .or.\n 1 (isym.gt.0 .and. ids.lt.imid)) return\n ierror = 6\n if(jds .lt. nlon) return\n ierror = 7\n mmax = min0(nlat,nlon/2+1)\n if(mdab .lt. mmax) return\n ierror = 8\n if(ndab .lt. nlat) return\n ierror = 9\nc\nc set and verify saved work space length\nc\nc\n l1 = min0(nlat,(nlon+2)/2)\n l2 = (nlat+1)/2\n lwmin = 2*nlat*l2+3*((l1-2)*(nlat+nlat-l1-1))/2+nlon+15\n if(lshsec .lt. lwmin) return\n ierror = 10\nc\nc set and verify unsaved work space length\nc\n ls = nlat\n if(isym .gt. 0) ls = imid\n nln = nt*ls*nlon\n mn = mmax*nlat*nt\nc lwmin = nln+ls*nlon+2*mn+nlat\nc if (lwork .lt. lwmin) return\n l2 = (nlat+1)/2\n l1 = min0(nlat,nlon/2+1)\n if (isym .eq. 0) then\n\tlwkmin = nlat*(2*nt*nlon+max0(6*l2,nlon)+2*nt*l1+1)\n else\n\tlwkmin = l2*(2*nt*nlon+max0(6*nlat,nlon))+nlat*(2*nt*l1+1)\n end if\n if (lwork .lt. lwkmin) return\n\n\n ierror = 0\nc\nc set work space pointers\nc\n ia = 1\n ib = ia+mn\n ifn = ib+mn\n iwk = ifn+nlat\n lwk = lwork-2*mn-nlat\n call slapec1(nlat,nlon,isym,nt,slap,ids,jds,a,b,mdab,ndab,\n +work(ia),work(ib),mmax,work(ifn),wshsec,lshsec,work(iwk),lwk,\n +ierror)\n return\n end\n\n subroutine slapec1(nlat,nlon,isym,nt,slap,ids,jds,a,b,mdab,ndab,\n + alap,blap,mmax,fnn,wshsec,lshsec,wk,lwk,ierror)\n dimension slap(ids,jds,nt),a(mdab,ndab,nt),b(mdab,ndab,nt)\n dimension alap(mmax,nlat,nt),blap(mmax,nlat,nt),fnn(nlat)\n dimension wshsec(lshsec),wk(lwk)\nc\nc set coefficient multiplyers\nc\n do 1 n=2,nlat\n fn = float(n-1)\n fnn(n) = fn*(fn+1.)\n 1 continue\nc\nc compute scalar laplacian coefficients for each vector field\nc\n do 2 k=1,nt\n do 3 n=1,nlat\n do 4 m=1,mmax\n alap(m,n,k) = 0.0\n blap(m,n,k) = 0.0\n 4 continue\n 3 continue\nc\nc compute m=0 coefficients\nc\n do 5 n=2,nlat\n alap(1,n,k) = -fnn(n)*a(1,n,k)\n blap(1,n,k) = -fnn(n)*b(1,n,k)\n 5 continue\nc\nc compute m>0 coefficients\nc\n do 6 m=2,mmax\n do 7 n=m,nlat\n alap(m,n,k) = -fnn(n)*a(m,n,k)\n blap(m,n,k) = -fnn(n)*b(m,n,k)\n 7 continue\n 6 continue\n 2 continue\nc\nc synthesize alap,blap into slap\nc\n call shsec(nlat,nlon,isym,nt,slap,ids,jds,alap,blap,\n + mmax,nlat,wshsec,lshsec,wk,lwk,ierror)\n return\n end\n", "meta": {"hexsha": "ddb74b2077a40d11ca5332671ca1be1666564a7c", "size": 12018, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/slapec.f", "max_stars_repo_name": "jprules321/colas", "max_stars_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/slapec.f", "max_issues_repo_name": "jprules321/colas", "max_issues_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/slapec.f", "max_forks_repo_name": "jprules321/colas", "max_forks_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.3371428571, "max_line_length": 79, "alphanum_fraction": 0.5481777334, "num_tokens": 3707, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.901920681802153, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6782556932492282}} {"text": "*DECK HFTI\n SUBROUTINE HFTI (A, MDA, M, N, B, MDB, NB, TAU, KRANK, RNORM, H,\n + G, IP)\nC***BEGIN PROLOGUE HFTI\nC***PURPOSE Solve a linear least squares problems by performing a QR\nC factorization of the matrix using Householder\nC transformations.\nC***LIBRARY SLATEC\nC***CATEGORY D9\nC***TYPE SINGLE PRECISION (HFTI-S, DHFTI-D)\nC***KEYWORDS CURVE FITTING, LINEAR LEAST SQUARES, QR FACTORIZATION\nC***AUTHOR Lawson, C. L., (JPL)\nC Hanson, R. J., (SNLA)\nC***DESCRIPTION\nC\nC DIMENSION A(MDA,N),(B(MDB,NB) or B(M)),RNORM(NB),H(N),G(N),IP(N)\nC\nC This subroutine solves a linear least squares problem or a set of\nC linear least squares problems having the same matrix but different\nC right-side vectors. The problem data consists of an M by N matrix\nC A, an M by NB matrix B, and an absolute tolerance parameter TAU\nC whose usage is described below. The NB column vectors of B\nC represent right-side vectors for NB distinct linear least squares\nC problems.\nC\nC This set of problems can also be written as the matrix least\nC squares problem\nC\nC AX = B,\nC\nC where X is the N by NB solution matrix.\nC\nC Note that if B is the M by M identity matrix, then X will be the\nC pseudo-inverse of A.\nC\nC This subroutine first transforms the augmented matrix (A B) to a\nC matrix (R C) using premultiplying Householder transformations with\nC column interchanges. All subdiagonal elements in the matrix R are\nC zero and its diagonal elements satisfy\nC\nC ABS(R(I,I)).GE.ABS(R(I+1,I+1)),\nC\nC I = 1,...,L-1, where\nC\nC L = MIN(M,N).\nC\nC The subroutine will compute an integer, KRANK, equal to the number\nC of diagonal terms of R that exceed TAU in magnitude. Then a\nC solution of minimum Euclidean length is computed using the first\nC KRANK rows of (R C).\nC\nC To be specific we suggest that the user consider an easily\nC computable matrix norm, such as, the maximum of all column sums of\nC magnitudes.\nC\nC Now if the relative uncertainty of B is EPS, (norm of uncertainty/\nC norm of B), it is suggested that TAU be set approximately equal to\nC EPS*(norm of A).\nC\nC The user must dimension all arrays appearing in the call list..\nC A(MDA,N),(B(MDB,NB) or B(M)),RNORM(NB),H(N),G(N),IP(N). This\nC permits the solution of a range of problems in the same array\nC space.\nC\nC The entire set of parameters for HFTI are\nC\nC INPUT..\nC\nC A(*,*),MDA,M,N The array A(*,*) initially contains the M by N\nC matrix A of the least squares problem AX = B.\nC The first dimensioning parameter of the array\nC A(*,*) is MDA, which must satisfy MDA.GE.M\nC Either M.GE.N or M.LT.N is permitted. There\nC is no restriction on the rank of A. The\nC condition MDA.LT.M is considered an error.\nC\nC B(*),MDB,NB If NB = 0 the subroutine will perform the\nC orthogonal decomposition but will make no\nC references to the array B(*). If NB.GT.0\nC the array B(*) must initially contain the M by\nC NB matrix B of the least squares problem AX =\nC B. If NB.GE.2 the array B(*) must be doubly\nC subscripted with first dimensioning parameter\nC MDB.GE.MAX(M,N). If NB = 1 the array B(*) may\nC be either doubly or singly subscripted. In\nC the latter case the value of MDB is arbitrary\nC but it should be set to some valid integer\nC value such as MDB = M.\nC\nC The condition of NB.GT.1.AND.MDB.LT. MAX(M,N)\nC is considered an error.\nC\nC TAU Absolute tolerance parameter provided by user\nC for pseudorank determination.\nC\nC H(*),G(*),IP(*) Arrays of working space used by HFTI.\nC\nC OUTPUT..\nC\nC A(*,*) The contents of the array A(*,*) will be\nC modified by the subroutine. These contents\nC are not generally required by the user.\nC\nC B(*) On return the array B(*) will contain the N by\nC NB solution matrix X.\nC\nC KRANK Set by the subroutine to indicate the\nC pseudorank of A.\nC\nC RNORM(*) On return, RNORM(J) will contain the Euclidean\nC norm of the residual vector for the problem\nC defined by the J-th column vector of the array\nC B(*,*) for J = 1,...,NB.\nC\nC H(*),G(*) On return these arrays respectively contain\nC elements of the pre- and post-multiplying\nC Householder transformations used to compute\nC the minimum Euclidean length solution.\nC\nC IP(*) Array in which the subroutine records indices\nC describing the permutation of column vectors.\nC The contents of arrays H(*),G(*) and IP(*)\nC are not generally required by the user.\nC\nC***REFERENCES C. L. Lawson and R. J. Hanson, Solving Least Squares\nC Problems, Prentice-Hall, Inc., 1974, Chapter 14.\nC***ROUTINES CALLED H12, R1MACH, XERMSG\nC***REVISION HISTORY (YYMMDD)\nC 790101 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 891006 Cosmetic changes to prologue. (WRB)\nC 891006 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\nC 901005 Replace usage of DIFF with usage of R1MACH. (RWC)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE HFTI\n DIMENSION A(MDA,*),B(MDB,*),H(*),G(*),RNORM(*)\n INTEGER IP(*)\n DOUBLE PRECISION SM,DZERO\n SAVE RELEPS\n DATA RELEPS /0.E0/\nC***FIRST EXECUTABLE STATEMENT HFTI\n IF (RELEPS.EQ.0) RELEPS = R1MACH(4)\n SZERO=0.\n DZERO=0.D0\n FACTOR=0.001\nC\n K=0\n LDIAG=MIN(M,N)\n IF (LDIAG.LE.0) GO TO 270\n IF (.NOT.MDA.LT.M) GO TO 5\n NERR=1\n IOPT=2\n CALL XERMSG ('SLATEC', 'HFTI', 'MDA.LT.M, PROBABLE ERROR.',\n + NERR, IOPT)\n RETURN\n 5 CONTINUE\nC\n IF (.NOT.(NB.GT.1.AND.MAX(M,N).GT.MDB)) GO TO 6\n NERR=2\n IOPT=2\n CALL XERMSG ('SLATEC', 'HFTI',\n + 'MDB.LT.MAX(M,N).AND.NB.GT.1. PROBABLE ERROR.', NERR, IOPT)\n RETURN\n 6 CONTINUE\nC\n DO 80 J=1,LDIAG\n IF (J.EQ.1) GO TO 20\nC\nC UPDATE SQUARED COLUMN LENGTHS AND FIND LMAX\nC ..\n LMAX=J\n DO 10 L=J,N\n H(L)=H(L)-A(J-1,L)**2\n IF (H(L).GT.H(LMAX)) LMAX=L\n 10 CONTINUE\n IF (FACTOR*H(LMAX) .GT. HMAX*RELEPS) GO TO 50\nC\nC COMPUTE SQUARED COLUMN LENGTHS AND FIND LMAX\nC ..\n 20 LMAX=J\n DO 40 L=J,N\n H(L)=0.\n DO 30 I=J,M\n 30 H(L)=H(L)+A(I,L)**2\n IF (H(L).GT.H(LMAX)) LMAX=L\n 40 CONTINUE\n HMAX=H(LMAX)\nC ..\nC LMAX HAS BEEN DETERMINED\nC\nC DO COLUMN INTERCHANGES IF NEEDED.\nC ..\n 50 CONTINUE\n IP(J)=LMAX\n IF (IP(J).EQ.J) GO TO 70\n DO 60 I=1,M\n TMP=A(I,J)\n A(I,J)=A(I,LMAX)\n 60 A(I,LMAX)=TMP\n H(LMAX)=H(J)\nC\nC COMPUTE THE J-TH TRANSFORMATION AND APPLY IT TO A AND B.\nC ..\n 70 CALL H12 (1,J,J+1,M,A(1,J),1,H(J),A(1,J+1),1,MDA,N-J)\n 80 CALL H12 (2,J,J+1,M,A(1,J),1,H(J),B,1,MDB,NB)\nC\nC DETERMINE THE PSEUDORANK, K, USING THE TOLERANCE, TAU.\nC ..\n DO 90 J=1,LDIAG\n IF (ABS(A(J,J)).LE.TAU) GO TO 100\n 90 CONTINUE\n K=LDIAG\n GO TO 110\n 100 K=J-1\n 110 KP1=K+1\nC\nC COMPUTE THE NORMS OF THE RESIDUAL VECTORS.\nC\n IF (NB.LE.0) GO TO 140\n DO 130 JB=1,NB\n TMP=SZERO\n IF (KP1.GT.M) GO TO 130\n DO 120 I=KP1,M\n 120 TMP=TMP+B(I,JB)**2\n 130 RNORM(JB)=SQRT(TMP)\n 140 CONTINUE\nC SPECIAL FOR PSEUDORANK = 0\n IF (K.GT.0) GO TO 160\n IF (NB.LE.0) GO TO 270\n DO 150 JB=1,NB\n DO 150 I=1,N\n 150 B(I,JB)=SZERO\n GO TO 270\nC\nC IF THE PSEUDORANK IS LESS THAN N COMPUTE HOUSEHOLDER\nC DECOMPOSITION OF FIRST K ROWS.\nC ..\n 160 IF (K.EQ.N) GO TO 180\n DO 170 II=1,K\n I=KP1-II\n 170 CALL H12 (1,I,KP1,N,A(I,1),MDA,G(I),A,MDA,1,I-1)\n 180 CONTINUE\nC\nC\n IF (NB.LE.0) GO TO 270\n DO 260 JB=1,NB\nC\nC SOLVE THE K BY K TRIANGULAR SYSTEM.\nC ..\n DO 210 L=1,K\n SM=DZERO\n I=KP1-L\n IF (I.EQ.K) GO TO 200\n IP1=I+1\n DO 190 J=IP1,K\n 190 SM=SM+A(I,J)*DBLE(B(J,JB))\n 200 SM1=SM\n 210 B(I,JB)=(B(I,JB)-SM1)/A(I,I)\nC\nC COMPLETE COMPUTATION OF SOLUTION VECTOR.\nC ..\n IF (K.EQ.N) GO TO 240\n DO 220 J=KP1,N\n 220 B(J,JB)=SZERO\n DO 230 I=1,K\n 230 CALL H12 (2,I,KP1,N,A(I,1),MDA,G(I),B(1,JB),1,MDB,1)\nC\nC RE-ORDER THE SOLUTION VECTOR TO COMPENSATE FOR THE\nC COLUMN INTERCHANGES.\nC ..\n 240 DO 250 JJ=1,LDIAG\n J=LDIAG+1-JJ\n IF (IP(J).EQ.J) GO TO 250\n L=IP(J)\n TMP=B(L,JB)\n B(L,JB)=B(J,JB)\n B(J,JB)=TMP\n 250 CONTINUE\n 260 CONTINUE\nC ..\nC THE SOLUTION VECTORS, X, ARE NOW\nC IN THE FIRST N ROWS OF THE ARRAY B(,).\nC\n 270 KRANK=K\n RETURN\n END\n", "meta": {"hexsha": "25c4056de0b30d239a15f66ac1d7e7ddd535a2c0", "size": 9942, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/hfti.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/hfti.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/hfti.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.401384083, "max_line_length": 72, "alphanum_fraction": 0.5485817743, "num_tokens": 3079, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206791658465, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6782556912666926}} {"text": " subroutine resid_hs3(ctfm,ctfmp,n_A,n_B,n_C1s,n_C5psi,n_psi,octfmp\n &,Nx,hx,myzero,phys_bdy,res)\n implicit none\n integer i\n integer Nx\n real*8 hx\n real*8 myzero\n real*8 ctfm(Nx)\n real*8 ctfmp(Nx)\n real*8 n_A(Nx)\n real*8 n_B(Nx)\n real*8 n_C1s(Nx)\n real*8 n_C5psi(Nx)\n real*8 n_psi(Nx)\n real*8 octfmp(Nx)\n integer phys_bdy(2)\n real*8 res\n real*8 qb\n res = 0.0D0\n if (phys_bdy(1) .eq. 1) then\n do i=1, 1, 1\n qb = -0.5000000000000000D0 * (0.3D1 * n_psi(i) - 0.4D1 * n_psi(i +\n # 1) + n_psi(i + 2)) / hx\n res = res + qb**2\n end do\n endif\n do i=2, Nx-1, 1\n qb = n_C1s(i) * n_psi(i) + n_C5psi(i) + (-0.5000000000000000D0 / n\n #_A(i) / ctfmp(i) * (-0.1D1 * n_psi(i - 1) + n_psi(i + 1)) * octfmp\n #(i) + 0.1D1 / ctfm(i) / n_A(i) / ctfmp(i) * (-0.1D1 * n_psi(i - 1)\n # + n_psi(i + 1))) / hx + (0.1D1 / n_A(i) * (n_psi(i - 1) - 0.2D1 *\n # n_psi(i) + n_psi(i + 1)) - 0.1250000000000000D0 / n_A(i) ** 2 * (\n #-0.1D1 * n_A(i - 1) + n_A(i + 1)) * (-0.1D1 * n_psi(i - 1) + n_psi\n #(i + 1)) + 0.2500000000000000D0 / n_B(i) / n_A(i) * (-0.1D1 * n_B(\n #i - 1) + n_B(i + 1)) * (-0.1D1 * n_psi(i - 1) + n_psi(i + 1))) / c\n #tfmp(i) ** 2 / hx ** 2\n res = res + qb**2\n end do\n if (phys_bdy(2) .eq. 1) then\n do i=Nx, Nx, 1\n qb = n_psi(i) - 0.1D1 + myzero * ctfm(i)\n res = res + qb**2\n end do\n endif\n res = sqrt(res/(1*Nx))\n END\n", "meta": {"hexsha": "bd720792f67eef8239ff6feb8d2dd0c39ce17f3b", "size": 1525, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/FD/resid_hs3.f", "max_stars_repo_name": "rmanak/bssn_spher", "max_stars_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/FD/resid_hs3.f", "max_issues_repo_name": "rmanak/bssn_spher", "max_issues_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/FD/resid_hs3.f", "max_forks_repo_name": "rmanak/bssn_spher", "max_forks_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.4468085106, "max_line_length": 72, "alphanum_fraction": 0.4780327869, "num_tokens": 735, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569267, "lm_q2_score": 0.752012562644147, "lm_q1q2_score": 0.6782556752936506}} {"text": "SUBROUTINE rsolv_sp(a,d,b)\n use mo_kind\n use mo_nrutil, ONLY : assert_eq\n IMPLICIT NONE\n REAL(SP), DIMENSION(:,:), INTENT(IN) :: a\n REAL(SP), DIMENSION(:), INTENT(IN) :: d\n REAL(SP), DIMENSION(:), INTENT(INOUT) :: b\n INTEGER(I4) :: i,n\n n=assert_eq(size(a,1),size(a,2),size(b),size(d),'rsolv')\n b(n)=b(n)/d(n)\n do i=n-1,1,-1\n b(i)=(b(i)-dot_product(a(i,i+1:n),b(i+1:n)))/d(i)\n end do\n END SUBROUTINE rsolv_sp\nSUBROUTINE rsolv_dp(a,d,b)\n use mo_kind\n use mo_nrutil, ONLY : assert_eq\n IMPLICIT NONE\n REAL(DP), DIMENSION(:,:), INTENT(IN) :: a\n REAL(DP), DIMENSION(:), INTENT(IN) :: d\n REAL(DP), DIMENSION(:), INTENT(INOUT) :: b\n INTEGER(I8) :: i,n\n n=assert_eq(size(a,1),size(a,2),size(b),size(d),'rsolv')\n b(n)=b(n)/d(n)\n do i=n-1,1,-1\n b(i)=(b(i)-dot_product(a(i,i+1:n),b(i+1:n)))/d(i)\n end do\n END SUBROUTINE rsolv_dp\n \n", "meta": {"hexsha": "b07d139aca79d57934da5822e8cc40ca79d5ea49", "size": 874, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "nr_jams/rsolv.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/rsolv.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/rsolv.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": 29.1333333333, "max_line_length": 59, "alphanum_fraction": 0.585812357, "num_tokens": 341, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256472515683, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.6782018330430026}} {"text": "! Fortran code for computing response spectra.\n! Originial version is writting by: Leonardo Ramirez-Guzman\n! The code base is tailored for F2py.\n!\n\n\nsubroutine max_osc_response(acc, npts, dt, period, csi, max_disp, &\n max_vel, max_acc)\n\n implicit none\n integer, intent(in) :: npts\n real, intent(in) :: acc(npts)\n real :: a(npts), v(npts), d(npts)\n real, intent(in) :: dt, period, csi \n real, intent(out) :: max_disp, max_vel, max_acc\n integer :: i=1\n real, parameter :: PI = 3.14159265359\n real :: w, ww, csicsi, dcsiw, rcsi, csircs, wd, ueskdt, dcsiew, um2csi, e, &\n s, c0, ca, cb, cc, cd, cap, cbp, ccp, cdp \n \n d(1) = 0.\n v(1) = 0.\n\n w = (2*PI)/period\n ww = w ** 2\n csicsi = csi ** 2\n dcsiw = 2. * csi * w\n\n rcsi = sqrt(1-csicsi)\n csircs = csi/rcsi\n wd = w * rcsi\n ueskdt = -1/(ww*dt)\n dcsiew = 2 * csi / w\n um2csi = (1.-2*csicsi)/wd\n e=exp(-w*dt*csi)\n s=sin(wd*dt)\n c0=cos(wd*dt)\n\n a(1) = -ww*d(1)-dcsiw*v(1) \n\n ca = e * (csircs*s+c0)\n cb = e * s/wd\n cc = (e*((um2csi-csircs*dt)*s -(dcsiew+dt)*c0)+dcsiew)*ueskdt\n cd = (e*(-um2csi*s+dcsiew*c0)+dt-dcsiew)*ueskdt\n cap = -cb * ww\n cbp = e * (c0-csircs*s)\n ccp = (e*((w*dt/rcsi+csircs)*s+c0)-1.)*ueskdt\n cdp = (1.-ca)*ueskdt\n\n do i=2,npts\n d(i) = ca*d(i-1)+cb*v(i-1)+cc*acc(i-1)+cd*acc(i)\n v(i) = cap*d(i-1)+cbp*v(i-1)+ccp*acc(i-1)+cdp*acc(i)\n a(i) = -ww*d(i)-dcsiw*v(i)\n end do\n\n max_disp = 0\n max_vel = 0\n max_acc = 0\n\n do i=1,npts\n if (abs(a(i)) .gt. max_acc) then\n max_acc = abs(a(i))\n end if\n end do \n\n do i=1,npts\n if (abs(v(i)) .gt. max_vel) then\n max_vel = abs(v(i))\n end if\n end do \n\n do i=1,npts\n if (abs(d(i)) .gt. max_disp) then\n max_disp = abs(d(i))\n end if\n end do \n\nend subroutine max_osc_response\n\n\nsubroutine calc_response(acc, npts, dt, periods, n_prds,csi, max_disps, &\n max_vels, max_accs)\n implicit none\n integer, intent(in) :: npts, n_prds\n real, intent(in) :: acc(npts)\n real, intent(in) :: dt, csi\n real, intent(in) :: periods(n_prds) \n real, intent(out) :: max_disps(n_prds), max_vels(n_prds), max_accs(n_prds)\n integer :: i=1\n\n do i=1,n_prds\n call max_osc_response(acc, npts, dt, periods(i), csi, max_disps(i),&\n max_vels(i), max_accs(i))\n end do\n\nend subroutine calc_response\n", "meta": {"hexsha": "a729ded4fccd7ae7e800fae9a3f79c3035a11854", "size": 2438, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "tsprocess/fsc/rsp.f95", "max_stars_repo_name": "Naeemkh/ts-process", "max_stars_repo_head_hexsha": "7947e2cc6e10be37664054ed63fa2aa836717f99", "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": "tsprocess/fsc/rsp.f95", "max_issues_repo_name": "Naeemkh/ts-process", "max_issues_repo_head_hexsha": "7947e2cc6e10be37664054ed63fa2aa836717f99", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 40, "max_issues_repo_issues_event_min_datetime": "2020-07-16T15:08:39.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-13T20:37:37.000Z", "max_forks_repo_path": "tsprocess/fsc/rsp.f95", "max_forks_repo_name": "Naeemkh/tsprocess", "max_forks_repo_head_hexsha": "7947e2cc6e10be37664054ed63fa2aa836717f99", "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.1340206186, "max_line_length": 80, "alphanum_fraction": 0.5533223954, "num_tokens": 951, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147438, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6780933660188092}} {"text": " SUBROUTINE TILING(A,B,SZ)\n \n INTEGER T,SZ\n INTEGER A(1:SZ,1:SZ)\n INTEGER B(0:SZ+1,0:SZ+1)\n INTEGER kernel(0:2,0:2)\n PARAMETER (T=10)\n\n if ( MOD(SZ,T) .NE. 0 ) RETURN\n\n DO i=1,SZ,T\n DO j=1,SZ,T\n DO k=i,i+T-1\n DO l=j,j+T-1\n A(k,l)=0\n DO m=-1,1\n DO n=-1,1\n A(k,l) = A(k,l) + B(k+m,l+n)*kernel(m+1,n+1)\n ENDDO\n ENDDO\n ENDDO\n ENDDO\n ENDDO\n ENDDO\n\n DO i=1,SZ\n DO j=1,SZ\n print *,A(i,j)\n ENDDO\n ENDDO\n END\n", "meta": {"hexsha": "063cea0c9c77151a05f5f6065c5ea18dcdbe4908", "size": 628, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "packages/PIPS/validation/Transformations/Symbolic_tiling.sub/tiling-symbolic.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/Transformations/Symbolic_tiling.sub/tiling-symbolic.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/Transformations/Symbolic_tiling.sub/tiling-symbolic.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": 19.625, "max_line_length": 62, "alphanum_fraction": 0.3694267516, "num_tokens": 234, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619885, "lm_q2_score": 0.7905303285397349, "lm_q1q2_score": 0.6780917075973779}} {"text": " Program zgetrs_example\n\n! ZGETRS Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_example_aux, Only: nagf_file_print_matrix_complex_gen_comp\n Use lapack_interfaces, Only: zgetrf, zgetrs\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nin = 5, nout = 6\n Character (1), Parameter :: trans = 'N'\n! .. Local Scalars ..\n Integer :: i, ifail, info, lda, ldb, n, nrhs\n! .. Local Arrays ..\n Complex (Kind=dp), Allocatable :: a(:, :), b(:, :)\n Integer, Allocatable :: ipiv(:)\n Character (1) :: clabs(1), rlabs(1)\n! .. Executable Statements ..\n Write (nout, *) 'ZGETRS Example Program Results'\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n, nrhs\n lda = n\n ldb = n\n Allocate (a(lda,n), b(ldb,nrhs), ipiv(n))\n\n! Read A and B from data file\n\n Read (nin, *)(a(i,1:n), i=1, n)\n Read (nin, *)(b(i,1:nrhs), i=1, n)\n\n! Factorize A\n\n Call zgetrf(n, n, a, lda, ipiv, info)\n\n Write (nout, *)\n Flush (nout)\n If (info==0) Then\n\n! Compute solution\n\n Call zgetrs(trans, n, nrhs, a, lda, ipiv, b, ldb, info)\n\n! Print solution\n\n! ifail: behaviour on error exit\n! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft\n ifail = 0\n Call nagf_file_print_matrix_complex_gen_comp('General', ' ', n, nrhs, &\n b, ldb, 'Bracketed', 'F7.4', 'Solution(s)', 'Integer', rlabs, &\n 'Integer', clabs, 80, 0, ifail)\n\n Else\n Write (nout, *) 'The factor U is singular'\n End If\n\n End Program\n", "meta": {"hexsha": "e0ecec89b01f47c1d7194f16758e1c98372565cf", "size": 1864, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/zgetrs_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/zgetrs_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/zgetrs_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 29.125, "max_line_length": 90, "alphanum_fraction": 0.5708154506, "num_tokens": 565, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901036, "lm_q2_score": 0.7905303137346446, "lm_q1q2_score": 0.6780916891493981}} {"text": "!---------------------------------------------------------------------- \n! Program: handy\n!> Purpose: Human and Nature Dynamics (from Motesharrei et al., 2014)\n!>
\n!> Author: Benjamin Menetrier\n!>
\n!> Licensing: this code is distributed under Apache License 2.0\n!----------------------------------------------------------------------\nprogram handy\n\nuse handy_mod\nimplicit none\n\n! Local variables\ninteger :: it,jt\nreal :: eta,deltastar,deltastar2,chimax\ntype(statetype) :: k1,k2,k3,k4\ntype(statetype),allocatable :: state(:)\ntype(partype) :: par\ncharacter(1024) :: filename\ncharacter(1024) :: subr = 'handy'\n\n!----------------------------------------------------------------------\n! Header\n!----------------------------------------------------------------------\n\nwrite(*,'(a)') '-------------------------------------------------------------------'\nwrite(*,'(a)') '--- You are running HANDY (from Motesharrei et al., 2014) --------'\nwrite(*,'(a)') '--- Author : Benjamin M\u00e9n\u00e9trier -----------------------------------'\n\n!----------------------------------------------------------------------\n! Initialization\n!----------------------------------------------------------------------\n\nwrite(*,'(a)') '-------------------------------------------------------------------'\nwrite(*,'(a)') '-1- Initialization'\n\n!----------------------------------------------------------------------\n! Read namelist\n!----------------------------------------------------------------------\n\nwrite(*,'(a)') '-------------------------------------------------------------------'\nwrite(*,'(a)') ' Read namelist'\nread(*,nml=handy_param)\n\n!----------------------------------------------------------------------\n! Memory allocation\n!----------------------------------------------------------------------\n\nwrite(*,'(a)') '-------------------------------------------------------------------'\nwrite(*,'(a)') ' Memory allocation'\nallocate(state(0:nt*dtrat))\n\n!----------------------------------------------------------------------\n! Initialization\n!----------------------------------------------------------------------\n\nwrite(*,'(a)') '-------------------------------------------------------------------'\nwrite(*,'(a)') ' Initialization'\n\n! Fixed parameters\npar%alpham = 1.0e-2\npar%alphamax = 7.0e-2\npar%s = 5.0e-4\npar%rho = 5.0e-3\npar%gamma = 1.0e-2\npar%lambda = 1.0e2\n\n! Fixed initial variables\nstate(0)%y = par%lambda\nstate(0)%w = 0.0\n\nselect case(trim(society))\ncase('egalitarian')\n ! Fixed parameters\n par%betac = 3.0e-2\n par%betae = 0.0\n par%kappa = 0.0\n state(0)%xc = 1.0e2\n state(0)%xe = 0.0\n\n ! Eta parameter\n eta = (par%alphamax - par%betac)/(par%alphamax - par%alpham)\n write(*,'(a,f6.2)') ' Eta parameter: ',eta\n\n ! Egalitarian optimal delta\n deltastar = 2.0*eta*par%s/par%lambda\n\n ! Select depletion factor\n select case(trim(config))\n case('optimal_soft_landing')\n par%delta = deltastar\n case('suboptimal_soft_landing')\n par%delta = 0.75*deltastar\n case('oscillatory_landing')\n par%delta = 2.5*deltastar\n case('cycles')\n par%delta = 4.0*deltastar\n case('collapse')\n par%delta = 5.5*deltastar\n case default\n write(*,'(a)') ' Not a valid config for an '//trim(society)//' society'\n stop\n end select\n\n ! Maximum carrying capacity\n chimax = par%gamma/(eta*par%s)*(par%lambda/2)**2\ncase('equitable')\n select case(trim(config))\n case('decreased_depletion')\n par%betac = 3.0e-2\n par%betae = 3.0e-2\n par%kappa = 1.0\n state(0)%xc = 1.0e2\n state(0)%xe = 6.0e2\n case default\n par%betac = 3.0e-2\n par%betae = 3.0e-2\n par%kappa = 1.0\n state(0)%xc = 1.0e2\n state(0)%xe = 2.5e1\n end select\n\n ! Eta parameter\n eta = (par%alphamax - par%betac)/(par%alphamax - par%alpham)\n write(*,'(a,f6.2)') ' Eta parameter: ',eta\n\n ! Egalitarian optimal delta\n deltastar2 = 2.0*eta*par%s/par%lambda*(1.0 + state(0)%xe/state(0)%xc)\n\n ! Select depletion factor\n select case(trim(config))\n case('optimal_soft_landing')\n par%delta = deltastar2\n case('suboptimal_soft_landing')\n par%delta = 0.75*deltastar2\n case('oscillatory_landing')\n par%delta = 2.64*deltastar2\n case('cycles')\n par%delta = 3.46*deltastar2\n case('collapse')\n par%delta = 5.0*deltastar2\n case('decreased_depletion')\n par%delta = 5.0*deltastar2\n case default\n write(*,'(a)') ' Not a valid config for an '//trim(society)//' society'\n stop\n end select\n\n ! Maximum carrying capacity\n chimax = par%gamma/(eta*par%s)*(par%lambda/2)**2\n\ncase('unequal')\n ! Predatory elite\n select case(trim(config))\n case('type-L_collapse')\n par%betac = 3.0e-2\n par%betae = 3.0e-2\n par%kappa = 100.0\n state(0)%xc = 1.0e2\n state(0)%xe = 1.0e-2\n case('type-N_collapse')\n par%betac = 3.0e-2\n par%betae = 3.0e-2\n par%kappa = 100.0\n state(0)%xc = 1.0e2\n state(0)%xe = 0.2\n case('optimal_soft_landing')\n par%betac = 6.5e-2\n par%betae = 2.0e-2\n par%kappa = 10.0\n state(0)%xc = 1.0e4\n state(0)%xe = 3.0e3\n case('oscillatory_landing')\n par%betac = 6.5e-2\n par%betae = 2.0e-2\n par%kappa = 10.0\n state(0)%xc = 1.0e4\n state(0)%xe = 3.0e3\n end select\n\n ! Eta parameter\n eta = (par%alphamax - par%betac)/(par%alphamax - par%alpham)\n write(*,'(a,f6.2)') ' Eta parameter: ',eta\n\n ! Egalitarian optimal delta\n deltastar = 2.0*eta*par%s/par%lambda\n\n ! Select depletion factor\n select case(trim(config))\n case('type-L_collapse')\n par%delta = deltastar\n case('type-N_collapse')\n par%delta = 1.0e-4\n case('optimal_soft_landing')\n par%delta = 6.35e-6\n case('oscillatory_landing')\n par%delta = 1.3e-5\n case default\n write(*,'(a)') ' Not a valid config for an '//trim(society)//' society'\n stop\n end select\n\n ! Maximum carrying capacity\n chimax = par%gamma/(eta*par%s)*(par%lambda/2)**2\ncase default\n write(*,'(a)') ' Not a valid society'\n stop\nend select\npar%nature_switch = .true.\n\n!----------------------------------------------------------------------\n! Integration\n!----------------------------------------------------------------------\n\nwrite(*,'(a)') '-------------------------------------------------------------------'\nwrite(*,'(a)') '-2- Integration'\n\ndo it=0,nt*dtrat-1\n ! Initialization\n state(it+1) = state(it)\n\n ! Check nature value\n if (lpos==3) par%nature_switch = par%nature_switch.and.(state(it+1)%y>1.0e-6*par%lambda)\n\n ! Integration\n if (trim(scheme)=='rk') then\n ! Fourth-order Runge-Kutta scheme\n call handy_step(state(it+1),par,k1)\n call handy_step(state(it+1) + k1/(2.0*float(dtrat)),par,k2)\n call handy_step(state(it+1) + k2/(2.0*float(dtrat)),par,k3)\n call handy_step(state(it+1) + k3/float(dtrat),par,k4)\n state(it+1) = state(it+1) + (k1 + 2.0*k2 + 2.0*k3 + k4)/(6.0*float(dtrat))\n elseif (trim(scheme)=='fe') then\n ! Forward Euler scheme\n call handy_step(state(it+1),par,k1)\n state(it+1) = state(it+1) + k1/float(dtrat)\n else\n write(*,'(a)') ' Not a valid integration scheme'\n stop\n end if\n\n if (it==0) write(*,'(a7,a6,a12,a12,a12,a12)') '','Year','Commoners','Elite','Nature','Accumulated wealth'\n write(*,'(a7,i6,e12.3,e12.3,e12.3,e12.3)') '',it,state(it+1)%xc,state(it+1)%xe,state(it+1)%y,state(it+1)%w\n\n if ((lpos>0).and.((state(it+1)%xc<0.0).or.(state(it+1)%xe<0.0).or.(state(it+1)%y<0.0).or.(state(it+1)%w<0.0))) then\n if (lpos==1) then\n ! Stop when negative values\n do jt=it+2,nt*dtrat\n state(jt)%xc = -999.0\n state(jt)%xe = -999.0\n state(jt)%y = -999.0\n state(jt)%w = -999.0\n end do\n exit\n elseif (lpos==2) then\n ! Force positivity\n state(it+1)%xc = max(0.0,state(it+1)%xc)\n state(it+1)%xe = max(0.0,state(it+1)%xe)\n state(it+1)%y = max(0.0,state(it+1)%y)\n state(it+1)%w = max(0.0,state(it+1)%w)\n elseif (lpos==3) then\n ! Threshold on nature regeneration (see handy_step)\n else\n write(*,'(a)') ' Not a valid positivity option'\n stop\n end if\n end if\nend do\n\n!----------------------------------------------------------------------\n! Write data\n!----------------------------------------------------------------------\n\nwrite(*,'(a)') '-------------------------------------------------------------------'\nwrite(*,'(a)') '-3- Write data'\n\nif (kind(1.0)==4) then\n write(filename,'(a,a,a,a,a,a,a,i2.2,a,i1,a)') '../data/',trim(society),'-',trim(config),'-',trim(scheme),'-',dtrat, &\n & '-lpos',lpos,'-sp.dat'\nelseif (kind(1.0)==8) then\n write(filename,'(a,a,a,a,a,a,a,i2.2,a,i1,a)') '../data/',trim(society),'-',trim(config),'-',trim(scheme),'-',dtrat, &\n & '-lpos',lpos,'-dp.dat'\nend if\nopen(unit=20,file=trim(filename),action='write',status='replace')\ndo it=0,nt*dtrat\n if (state(it)%xc>-999.0) then\n write(20,*) it,float(it)/float(dtrat),state(it)%xc/chimax,state(it)%xe/chimax,state(it)%y/par%lambda,state(it)%w/par%lambda\n else\n write(20,*) it,float(it)/float(dtrat),state(it)%xc,state(it)%xe,state(it)%y,state(it)%w\n end if\nend do\nclose(unit=20)\n\nend program handy\n", "meta": {"hexsha": "ec19c62f6e9903e494a9523b25276e385a796644", "size": 9258, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/handy.f90", "max_stars_repo_name": "benjaminmenetrier/handy", "max_stars_repo_head_hexsha": "eb5a0d6f4a020217a159f9fea78f8dffeacdc41e", "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/handy.f90", "max_issues_repo_name": "benjaminmenetrier/handy", "max_issues_repo_head_hexsha": "eb5a0d6f4a020217a159f9fea78f8dffeacdc41e", "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/handy.f90", "max_forks_repo_name": "benjaminmenetrier/handy", "max_forks_repo_head_hexsha": "eb5a0d6f4a020217a159f9fea78f8dffeacdc41e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.277027027, "max_line_length": 129, "alphanum_fraction": 0.4901706632, "num_tokens": 2885, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.857768094082276, "lm_q2_score": 0.7905303186696748, "lm_q1q2_score": 0.6780916847595412}} {"text": "SUBROUTINE RMINVE (A , AI , NSIZE , ERROR)\r\nIMPLICIT NONE\r\n!PARAMETER DECLARATION\r\nINTEGER, PARAMETER:: MSIZE=500\r\n!DATA DECLARATION\r\nREAL(8) R0 /0.0D0/\r\nREAL(8) R1 /1.0D0/\r\nCHARACTER*6 NAME\r\nDATA NAME/'RMINVE'/\r\n!SCALAR VARIABLES FROM ARGUMENTS\r\nINTEGER NSIZE\r\nLOGICAL ERROR\r\n!ARRAYS FROM ARGUMENTS\r\nREAL(8), DIMENSION(NSIZE,NSIZE):: A\r\nREAL(8), DIMENSION(NSIZE,NSIZE):: AI\r\n!LOCAL SCALAR VARIABLES\r\nINTEGER ISIZE, JSIZE\r\nREAL(8) DUMMY, DETA\r\n!LOCAL ARRAYS\r\nINTEGER, DIMENSION(NSIZE):: INDX\r\n!INITIALIZE LOCAL VARIABLES\r\nISIZE=0 ; JSIZE=0\r\nDUMMY=R0 ; DETA=R0\r\nINDX=0\r\n!***********************************************************************\r\n! Evaluate inverse matrix without determinant\r\n!*Arrays\r\n! A - A matrix\r\n!=AI - inversed A matrix\r\n!*Variables\r\n! NSIZE - Size of the matrix\r\n!=ERROR - Error flag\r\n!***********************************************************************\r\n! Set up identity matrix\r\n! ----------------------\r\nERROR=.FALSE.\r\nDO 20 ISIZE=1,NSIZE\r\n\tDO 10 JSIZE=1,NSIZE\r\n \tAI(ISIZE,JSIZE)=R0\r\n \t10 CONTINUE\r\n AI(ISIZE,ISIZE)=R1\r\n20 CONTINUE\r\n! LU decompose the matrix\r\nCALL LUDCMPX(A ,INDX ,DUMMY,NSIZE ,NSIZE ,ERROR )\r\nDETA=DUMMY\r\n! Find inverse by columns\r\nDO 30 ISIZE=1,NSIZE\r\n\tCALL LUBKSBX(A ,AI(1,ISIZE),INDX ,NSIZE ,NSIZE )\r\n! Obtain determinant\r\n DETA=DETA*A(ISIZE,ISIZE)\r\n30 CONTINUE\r\n999 CONTINUE\r\nRETURN\r\nEND", "meta": {"hexsha": "aaf3d989b03ce58d855a95e260144198b4336d62", "size": 1386, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/utils/rminve.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/rminve.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/rminve.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.6666666667, "max_line_length": 73, "alphanum_fraction": 0.601010101, "num_tokens": 435, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625069680097, "lm_q2_score": 0.727975460709318, "lm_q1q2_score": 0.6780818476434931}} {"text": "SUBROUTINE tide_pole_se (mjd,xp,yp , dC21,dS21)\r\n\r\n! ----------------------------------------------------------------------\r\n! SUBROUTINE: tide_pole_se.f90\r\n! ----------------------------------------------------------------------\r\n! Purpose:\r\n! Solid Earth pole tide effect to C21 and S21 spherical harmonic coefficients\r\n! of the geopotential harmonics expansion\r\n! ----------------------------------------------------------------------\r\n! Input arguments:\r\n! - mjd :\t\t\tModified Julian Day number in Terrestrial Time (TT)\r\n! \tincluding the fraction of the day \r\n! Output arguments:\r\n! - dC21 : \t\tC21 coefficient correction due to Solid Earth Pole Tide\r\n! - dS21 : \t\tS21 coefficient correction due to Solid Earth Pole Tide\r\n! ----------------------------------------------------------------------\r\n! Author :\tDr. Thomas Papanikolaou, Cooperative Research Centre for Spatial Information, Australia\r\n! Created:\tNovember 2015\r\n! ----------------------------------------------------------------------\r\n! Last modified:\r\n! - Dr. Thomas Papanikolaou, 30 October 2017:\r\n! The subroutine has been slightly modified in order to call the subroutine iau_JD2CAL.for from the IAU SOFA package \r\n! ----------------------------------------------------------------------\r\n\r\n\r\n USE mdl_precision\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) :: mjd, xp, yp\r\n! OUT\r\n REAL (KIND = prec_q), INTENT(OUT) :: dC21,dS21\r\n! ----------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n! Local variables declaration\r\n! ----------------------------------------------------------------------\r\n REAL (KIND = prec_q) :: m1,m2\r\n! ----------------------------------------------------------------------\r\n! Remark:\r\n! Variables \"epoch, xp_mean, yp_mean\" enter F77 code and thus, these are declared as DP.\r\n REAL (KIND = prec_d) :: epoch, xp_mean, yp_mean\r\n !REAL*8 epoch, xp_mean,yp_mean\r\n INTEGER error,version\r\n! ----------------------------------------------------------------------\r\n REAL (KIND = prec_d) :: jd0\r\n INTEGER IY, IM, ID, J_flag\r\n DOUBLE PRECISION FD \r\n! ----------------------------------------------------------------------\r\n\r\n\r\n\r\n! ----------------------------------------------------------------------\r\njd0 = 2400000.5D0\r\nCALL iau_JD2CAL ( jd0, mjd, IY, IM, ID, FD, J_flag )\t \r\n\r\nepoch = IY*1.D0 + IM/12.D0 + ID/365.25D0 + FD/365.25D0 \t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! Conventional Mean Pole\r\n\r\n! epoch_int = INT (epoch)\r\n! IF (epoch_int >= 2010) THEN\r\n! version = 2015\r\n! ELSE IF (epoch_int < 2010 .AND. epoch_int >= 2003) THEN\r\n!\t version = 2010\r\n! ELSE IF (epoch_int < 2003 .AND. epoch_int >= 2010)\t\t \r\n \r\n\t version = 2015\r\n CALL IERS_CMP_2015 (version,epoch , xp_mean,yp_mean,error)\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! Wobble variables m1, m2 (in seconds of arc)\r\n m1 = xp - xp_mean\r\n m2 = -1.0D0 * (yp - yp_mean)\r\n! ----------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n dC21 = -1.333D-9 * (m1 + 0.0115D0 * m2)\r\n dS21 = -1.333D-9 * (m2 - 0.0115D0 * m1)\r\n! ----------------------------------------------------------------------\r\n\r\n\r\nEND\r\n", "meta": {"hexsha": "d07bc65d3f0fd6083756d2f303e2f2b8896b75c8", "size": 3805, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/tide_pole_se.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/tide_pole_se.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/tide_pole_se.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": 41.3586956522, "max_line_length": 120, "alphanum_fraction": 0.3605781866, "num_tokens": 784, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625088705931, "lm_q2_score": 0.7279754548076477, "lm_q1q2_score": 0.6780818435313426}} {"text": "!\tGet multinomial probabilities for latent vector. Place in densitym.\r\n!\tInput involves linear component linth, quadrature points quadpoint, quadratic components quadth, and quadrature weights quadweight.\r\nfunction densitym(linth,quadpoint,quadth,quadweight)\r\nimplicit none\r\nreal(kind=8),intent(in)::linth(:),quadpoint(:,:),quadth(:,:),quadweight(:)\r\nreal(kind=8)::densitym(size(quadweight))\r\n!\tquad counts quadrature points.\r\ninteger::quad\r\n!\trescale density with rescale.\r\nreal(kind=8)::rescale\r\n\r\ndo quad=1,size(quadweight)\r\n\tdensitym(quad)=quadweight(quad)*exp(dot_product(quadpoint(:,quad),linth+matmul(quadth,quadpoint(:,quad))))\r\nend do\r\nrescale=1.0_8/sum(densitym)\r\ndensitym=rescale*densitym\r\nreturn\r\nend function densitym", "meta": {"hexsha": "292075f2559828f4925bd9caf976b86883ba68a7", "size": 731, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Source/densitym.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/densitym.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/densitym.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": 40.6111111111, "max_line_length": 134, "alphanum_fraction": 0.7701778386, "num_tokens": 198, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9314625069680098, "lm_q2_score": 0.7279754548076477, "lm_q1q2_score": 0.6780818421463086}} {"text": " subroutine gaus3(x,p,y,dydp,mp)\n implicit none\n real*8 x,p,y,dydp\n integer mp\n dimension p(mp),dydp(mp)\n\n dydp(1)=exp(-0.5*(x-p(3))**2/p(2)**2)\n y=p(1)*dydp(1)\n dydp(2)=p(1)*(x-p(3))**2/p(2)**3 *dydp(1)\n dydp(3)=p(1)*(x-p(3))/p(2)**2 *dydp(1)\n return\n end\n\n", "meta": {"hexsha": "ef980aa177506db34faa21c00ba37378dfa99195", "size": 313, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/gaus3.f", "max_stars_repo_name": "noboruatkek/SAD", "max_stars_repo_head_hexsha": "3881a190af8903537774c57b56963ffc94cfc039", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2019-04-01T15:54:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-09T16:47:20.000Z", "max_issues_repo_path": "src/gaus3.f", "max_issues_repo_name": "noboruatkek/SAD", "max_issues_repo_head_hexsha": "3881a190af8903537774c57b56963ffc94cfc039", "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/gaus3.f", "max_forks_repo_name": "noboruatkek/SAD", "max_forks_repo_head_hexsha": "3881a190af8903537774c57b56963ffc94cfc039", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2017-03-15T08:52:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-19T08:06:40.000Z", "avg_line_length": 22.3571428571, "max_line_length": 47, "alphanum_fraction": 0.4664536741, "num_tokens": 138, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9314625031628428, "lm_q2_score": 0.7279754430043072, "lm_q1q2_score": 0.6780818283818714}} {"text": "FUNCTION GET_LUMDIST(z)\n\n !compute luminosity distance to redshift z\n !assumes flat universe w/ only matter and lambda\n !assumes om0,ol0,H0 set in sps_vars.f90\n \n USE sps_vars; USE sps_utils, ONLY : tsum\n IMPLICIT NONE\n INTEGER :: i\n INTEGER, PARAMETER :: ii=10000\n REAL(SP), INTENT(in) :: z\n REAL(SP) :: get_lumdist, dhub\n REAL(SP), DIMENSION(ii) :: zz, hub\n\n !---------------------------------------------------------------!\n !---------------------------------------------------------------!\n\n get_lumdist = 0.0\n\n !Hubble distance in pc\n dhub = clight/1E13/H0*1E6\n\n DO i=1,ii\n zz(i) = REAL(i)/ii*z\n ENDDO\n \n hub = SQRT( om0*(1+zz)**3 + ol0 )\n\n get_lumdist = TSUM(zz,1/hub) * (1+z) * dhub\n\n\nEND FUNCTION GET_LUMDIST\n", "meta": {"hexsha": "c1ba144be1230b645e4deeead01a0c9975c4163b", "size": 742, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/get_lumdist.f90", "max_stars_repo_name": "christopherlovell/fsps", "max_stars_repo_head_hexsha": "1c09a47d7b0fb15a7f245ee3e9b2a7c54122ffdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 55, "max_stars_repo_stars_event_min_datetime": "2015-04-17T18:36:36.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-15T01:47:28.000Z", "max_issues_repo_path": "src/get_lumdist.f90", "max_issues_repo_name": "christopherlovell/fsps", "max_issues_repo_head_hexsha": "1c09a47d7b0fb15a7f245ee3e9b2a7c54122ffdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 27, "max_issues_repo_issues_event_min_datetime": "2015-11-04T03:19:44.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-15T22:03:19.000Z", "max_forks_repo_path": "src/get_lumdist.f90", "max_forks_repo_name": "christopherlovell/fsps", "max_forks_repo_head_hexsha": "1c09a47d7b0fb15a7f245ee3e9b2a7c54122ffdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 43, "max_forks_repo_forks_event_min_datetime": "2015-04-29T09:24:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T19:31:46.000Z", "avg_line_length": 22.4848484848, "max_line_length": 67, "alphanum_fraction": 0.5336927224, "num_tokens": 243, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096112990283, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.6780808523517258}} {"text": " function dpolardiskdens(r,ctheta)\n z=r*ctheta\n s=r*sqrt(1.0 - ctheta*ctheta)\n dpolardiskdens=diskdensestimate(s,z)\n return\n end\n\n function diskdensestimate(s,z)\n\n include 'commonblocks'\nc\n r=sqrt(s*s+z*z)\n t=sqrt(0.5d0)*(r-outdisk)/drtrunc\n t2=t*t\n if (t.lt.-5.0) then\n eerfc=1.\n elseif (t.lt.5.0) then\n eerfc=0.5*erfc(t)\n else\n eerfc=0\n endif\n if (r.gt.0.) then\n f=diskconst*eerfc*exp(-r/rdisk)\n else\n f=diskconst*eerfc\n endif\n zz=abs(z/zdisk)\n ezz=exp(-zz)\n e2zz=ezz*ezz\n tsech2=(2*ezz/(1+e2zz))**2\n diskdensestimate=f*tsech2\n\n return\n end\n\n function halodensity(r)\n\n include 'commonblocks'\n real nfwdens\n\n halodensity = nfwdens(r)*eerfc(r)\n\n return\n end\n\n function halodensprime(r)\n\n include 'commonblocks'\n real nfwdens, nfwdensprime\n\n halodensprime = nfwdens(r)*eerfcprime(r)+nfwdensprime(r)*eerfc(r)\n \n return\n end\n\n function halodens2prime(r)\n\n include 'commonblocks'\n real nfwdens, nfwdensprime, nfwdens2prime\n\n t1 = nfwdens2prime(r)*eerfc(r)\n t2 = 2.*nfwdensprime(r)*eerfcprime(r)\n t3 = nfwdens(r)*eerfc2prime(r)\n halodens2prime = t1 + t2 + t3\n return\n end\n\n function eerfc(r)\n\n include 'commonblocks'\n\n t=sqrt(0.5)*(r-chalo)/drtrunchalo\n t2=t*t\n if (t.lt.-4.) then\n eerfc=1.\n elseif (t.lt.4.) then\n eerfc=0.5*erfc(t)\n else\n eerfc=0\n endif\n \n return\n end\n\n function eerfcprime(r)\n\n include 'commonblocks'\n\n t=sqrt(0.5)*(r-chalo)/drtrunchalo\n t2=t*t\n\n if(t2.gt.16.) then\n eerfcprime = 0.\n else\n eerfcprime = -0.5*sqrt(2./pi)/drtrunchalo*exp(-t2)\n endif\n return\n end\n\n function eerfc2prime(r)\n\n include 'commonblocks'\n\n t=sqrt(0.5)*(r-chalo)/drtrunchalo\n t2=t*t\n\n if(t2.gt.16.) then\n eerfc2prime = 0.\n else\n eerfc2prime = 1./sqrt(pi)/drtrunchalo/drtrunchalo*t*exp(-t2)\n endif\nC write(77,*) r,eerfc2prime\n return\n end\n", "meta": {"hexsha": "32a8ce5afda94c62ccd49c9c50849ad9251199a4", "size": 2206, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/amuse/community/galactics/src/src/dpolardens.f", "max_stars_repo_name": "rknop/amuse", "max_stars_repo_head_hexsha": "85d5bdcc29cfc87dc69d91c264101fafd6658aec", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 131, "max_stars_repo_stars_event_min_datetime": "2015-06-04T09:06:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-01T12:11:29.000Z", "max_issues_repo_path": "src/amuse/community/galactics/src/src/dpolardens.f", "max_issues_repo_name": "rknop/amuse", "max_issues_repo_head_hexsha": "85d5bdcc29cfc87dc69d91c264101fafd6658aec", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 690, "max_issues_repo_issues_event_min_datetime": "2015-10-17T12:18:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:15:58.000Z", "max_forks_repo_path": "src/amuse/community/galactics/src/src/dpolardens.f", "max_forks_repo_name": "rieder/amuse", "max_forks_repo_head_hexsha": "3ac3b6b8f922643657279ddee5c8ab3fc0440d5e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 102, "max_forks_repo_forks_event_min_datetime": "2015-01-22T10:00:29.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-09T13:29:43.000Z", "avg_line_length": 19.1826086957, "max_line_length": 71, "alphanum_fraction": 0.546237534, "num_tokens": 759, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096181702032, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.678080852186937}} {"text": "!\n! CalculiX - A 3-dimensional finite element program\n! Copyright (C) 1998-2021 Guido Dhondt\n!\n! This program is free software; you can redistribute it and/or\n! modify it under the terms of the GNU General Public License as\n! published by the Free Software Foundation(version 2);\n! \n!\n! This program is distributed in the hope that it will be useful,\n! but WITHOUT ANY WARRANTY; without even the implied warranty of \n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \n! GNU General Public License for more details.\n!\n! You should have received a copy of the GNU General Public License\n! along with this program; if not, write to the Free Software\n! Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n!\n subroutine meshquality(netet_,kontet,cotet,quality,ielem)\n!\n! calculate the element quality. The measure used is proportional\n! to the ratio of the longest edge divided by the radius of the\n! inscribed sphere. The proportionality constant is such that\n! the quality is 1 for an equilateral tetrahedron. For all other\n! elements it exceeds 1. The bigger this number, the worse the\n! quality\n!\n! if ielem>0 the quality for this element is calculated, if\n! ielem=0 the quality for all elements in the mesh is determined\n!\n implicit none\n!\n integer netet_,kontet(4,*),ielem,i,j,nodes(4),n1,n2,ine(2,6)\n!\n real*8 cotet(3,*),quality(*),volume,surface(4),totsurface,alpha,\n & edgelength(6),hmax,radius\n!\n data ine /1,2,2,3,1,3,1,4,2,4,3,4/\n!\n! alpha is the proporionality factor\n! \n alpha=dsqrt(6.d0)/12.d0\n! \n if(ielem.eq.0) then\n!\n! calculating the quality for all elements\n!\n do i=1,netet_\n if(kontet(1,i).ne.0) then\n do j=1,4\n nodes(j)=kontet(j,i)\n enddo\n!\n! calculating the volume of the element\n!\n call calcvol(nodes(1),nodes(2),nodes(3),nodes(4),cotet,\n & volume)\n if(volume.le.0.d0) volume=1.d-30\n!\n! calculating area of each face in the element\n!\n call calcsurf(nodes(1),nodes(2),nodes(3),cotet,\n & surface(1))\n call calcsurf(nodes(2),nodes(3),nodes(4),cotet,\n & surface(2))\n call calcsurf(nodes(3),nodes(4),nodes(1),cotet,\n & surface(3))\n call calcsurf(nodes(4),nodes(1),nodes(2),cotet,\n & surface(4))\n!\n! calculating the total surface\n!\n totsurface=surface(1)+surface(2)+surface(3)+surface(4)\n!\n! radius of the inscribed sphere\n!\n radius=3.d0*volume/totsurface\n!\n! length of each edge\n!\n do j=1,6\n n1=nodes(ine(1,j))\n n2=nodes(ine(2,j))\n edgelength(j)=dsqrt((cotet(1,n1)-cotet(1,n2))**2+\n & (cotet(2,n1)-cotet(2,n2))**2+\n & (cotet(3,n1)-cotet(3,n2))**2)\n enddo\n!\n! maximum edge length\n!\n hmax=maxval(edgelength)\n!\n! quality\n!\n quality(i)=alpha*hmax/radius\n!\n! are the next lines really needed?\n!\nc if(quality(i).lt.1.d0) then\nc quality(i)=1.d0/quality(i)\nc endif\n endif\n enddo\n else\n!\n! calculating the quality for just one element\n!\n i=ielem\n! \n if(kontet(1,i).ne.0) then\n do j=1,4\n nodes(j)=kontet(j,i)\n enddo\n! \n! calculating the volume of the element\n! \n call calcvol(nodes(1),nodes(2),nodes(3),nodes(4),cotet,\n & volume)\n if(volume.le.0.d0) volume=1.d-30\n! \n! calculating area of each face in the element\n! \n call calcsurf(nodes(1),nodes(2),nodes(3),cotet,\n & surface(1))\n call calcsurf(nodes(2),nodes(3),nodes(4),cotet,\n & surface(2))\n call calcsurf(nodes(3),nodes(4),nodes(1),cotet,\n & surface(3))\n call calcsurf(nodes(4),nodes(1),nodes(2),cotet,\n & surface(4))\n! \n! calculating the total surface\n! \n totsurface=surface(1)+surface(2)+surface(3)+surface(4)\n! \n! radius of the inscribed sphere\n! \n radius=3.d0*volume/totsurface\n! \n! length of each edge\n! \n do j=1,6\n n1=nodes(ine(1,j))\n n2=nodes(ine(2,j))\n edgelength(j)=dsqrt((cotet(1,n1)-cotet(1,n2))**2+\n & (cotet(2,n1)-cotet(2,n2))**2+\n & (cotet(3,n1)-cotet(3,n2))**2)\n enddo\n! \n! maximum edge length\n! \n hmax=maxval(edgelength)\n! \n! quality\n! \n quality(i)=alpha*hmax/radius\n! \n! are the next lines really needed?\n! \nc if(quality(i).lt.1.d0) then\nc quality(i)=1.d0/quality(i)\nc endif\n endif\n endif\n! \n return\n end\n", "meta": {"hexsha": "c50f9f4d94cd35f27bf66ca4637da0113296e334", "size": 4911, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ccx_prool/CalculiX/ccx_2.19/src/meshquality.f", "max_stars_repo_name": "alleindrach/calculix-desktop", "max_stars_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ccx_prool/CalculiX/ccx_2.19/src/meshquality.f", "max_issues_repo_name": "alleindrach/calculix-desktop", "max_issues_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ccx_prool/CalculiX/ccx_2.19/src/meshquality.f", "max_forks_repo_name": "alleindrach/calculix-desktop", "max_forks_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.2321428571, "max_line_length": 71, "alphanum_fraction": 0.5567094278, "num_tokens": 1447, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.91610961358942, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6780808487963587}} {"text": "!\n! Program to test the Interpolate_Utility module procedures\n!\nPROGRAM Test_Interpolate_Utility\n\n ! ------------------\n ! Environment set up\n ! ------------------\n ! Module usage\n USE Type_Kinds, ONLY: fp=>fp_kind\n USE Message_Handler, ONLY: SUCCESS, FAILURE, Display_Message\n USE File_Utility, ONLY: Get_Lun\n USE Search_Utility, ONLY: Value_Locate\n USE Interpolate_Utility, ONLY: Linear_Interpolate, &\n Polynomial_Interpolate, &\n Spline_Initialize, Spline_Interpolate\n ! Disable implicit typing\n IMPLICIT NONE\n\n\n ! ----------\n ! Parameters\n ! ----------\n CHARACTER(*), PARAMETER :: PROGRAM_NAME = 'Test_Interpolate_Utility'\n CHARACTER(*), PARAMETER :: PROGRAM_RCS_ID = &\n INTEGER, PARAMETER :: N = 25\n! INTEGER, PARAMETER :: N = 12\n INTEGER, PARAMETER :: NI = 78\n INTEGER, PARAMETER :: NORDERS = 6\n INTEGER, PARAMETER, DIMENSION(NORDERS) :: ORDER=(/1,3,5,7,9,11/)\n REAL(fp), PARAMETER :: ZERO = 0.0_fp\n CHARACTER(*), PARAMETER, DIMENSION(2) :: FTYPE=(/'scalar','rank-1'/)\n\n\n ! ---------\n ! Variables\n ! ---------\n CHARACTER(256) :: message\n INTEGER :: Error_Status\n INTEGER :: IO_Status\n INTEGER :: FileID\n INTEGER :: i, j, k\n REAL(fp), DIMENSION(N) :: x, y\n REAL(fp), DIMENSION(N) :: y2\n REAL(fp), DIMENSION(NI) :: xInt, yTrue\n INTEGER, DIMENSION(NI) :: x_idx\n REAL(fp), DIMENSION(NI,2) :: LinInt\n REAL(fp), DIMENSION(NI,NORDERS,2) :: PolyInt\n REAL(fp), DIMENSION(NI,2) :: SplineInt\n REAL(fp), DIMENSION(2) :: LinError\n REAL(fp), DIMENSION(NORDERS,2) :: PolyError\n REAL(fp), DIMENSION(2) :: SplineError\n\n\n ! ------------------------------\n ! Create the data to interpolate\n ! ------------------------------\n ! Define the x-data\n x = (/ 0.0_fp, 0.01_fp, 0.05_fp, 0.12_fp, 0.14_fp, &\n 0.22_fp, 0.30_fp, 0.32_fp, 0.33_fp, 0.335_fp,&\n 0.36_fp, 0.39_fp, 0.40_fp, 0.405_fp,0.44_fp, &\n 0.5_fp, 0.54_fp, 0.62_fp, 0.64_fp, 0.65_fp, &\n 0.66_fp, 0.70_fp, 0.75_fp, 0.79_fp, 0.80_fp /)\n! x = (/ 0.0_fp, 0.12_fp, 0.22_fp, 0.32_fp, &\n! 0.36_fp, 0.44_fp, 0.45_fp, 0.54_fp, &\n! 0.64_fp, 0.70_fp, 0.72_fp, 0.80_fp /)\n ! Calculate the y-data\n y = Func(x)\n\n\n ! -----------------------------------------------------\n ! Create regular grid at which interpolates are desired\n ! -----------------------------------------------------\n xInt = (/ ( REAL(i-1), i=1,NI ) /) / REAL(NI-1)\n xInt = xInt * ( MAXVAL(x) - MINVAL(x) ) + MINVAL(x)\n ! Calculate the true curve\n yTrue = Func( xInt )\n\n\n ! --------------------\n ! Interpolate the data\n ! --------------------\n ! Initialise error sums\n PolyError = ZERO\n SplineError = ZERO\n WRITE( *, '( /5x, \"Interpolating....\" )' )\n ! Linear scalar\n x_idx = Value_Locate(x,xint)\n DO i = 1, NI\n Error_Status = Linear_Interpolate( x, y, xInt(i), LinInt(i,1) )\n END DO\n LinError(1) = SUM(ABS(yTrue-LinInt(:,1)))\n\n ! Linear rank-1\n Error_Status = Linear_Interpolate( x, y, xInt, LinInt(:,2) )\n LinError(2) = SUM(ABS(yTrue-LinInt(:,2)))\n\n ! Polynomial scalar\n x_idx = Value_Locate(x,xint)\n DO j = 1, NORDERS\n DO i = 1, NI\n Error_Status = Polynomial_Interpolate( x, y, &\n xInt(i), PolyInt(i,j,1), &\n x_idx=x_idx(i), &\n Order=ORDER(j) )\n END DO\n PolyError(j,1) = SUM(ABS(yTrue-PolyInt(:,j,1)))\n END DO\n\n ! Polynomial rank-1\n DO j = 1, NORDERS\n Error_Status = Polynomial_Interpolate( x, y, &\n xInt, PolyInt(:,j,2), &\n Order=ORDER(j) )\n PolyError(j,2) = SUM(ABS(yTrue-PolyInt(:,j,2)))\n END DO\n\n ! Spline scalar\n Error_Status = Spline_Initialize( x, y, y2 )\n DO i = 1, NI\n Error_Status = Spline_Interpolate( x, y, xInt(i), SplineInt(i,1), y2=y2 )\n END DO\n SplineError(1) = SUM(ABS(yTrue-SplineInt(:,1)))\n\n ! Spline rank-1\n Error_Status = Spline_Interpolate( x, y, xInt, SplineInt(:,2) )\n SplineError(2) = SUM(ABS(yTrue-SplineInt(:,2)))\n\n\n ! ----------------------\n ! Output the error summs\n ! ----------------------\n WRITE( *, '( /5x, \"Error sums, SUM(ABS(yTrue-yInt)):\" )' )\n DO k = 1, 2\n WRITE( *, '( 5x, \"LinInt \", a, \": \", es13.6 )' ) FTYPE(k), LinError(k)\n END DO\n DO k = 1, 2\n WRITE( *, '( 5x, \"PolyInt \", a )' ) FTYPE(k)\n DO j = 1, NORDERS\n WRITE( *, '( 7x, \"Order \", i2, \": \", es13.6 )' ) ORDER(j),PolyError(j,k) \n END DO\n END DO\n DO k = 1, 2\n WRITE( *, '( 5x, \"SplineInt \", a, \": \", es13.6 )' ) FTYPE(k), SplineError(k)\n END DO\n\n\n ! -----------------------\n ! Write the original data\n ! -----------------------\n FileID = Open_File('orig_xy.dat') \n DO i = 1, N\n WRITE( FileID, '( 2( 1x, es20.11e3 ) )' ) x(i), y(i)\n END DO\n CLOSE( FileID )\n\n\n ! ----------------------------------\n ! Write the linear interpolated data\n ! ----------------------------------\n DO k = 1, 2\n IF( k==1 ) THEN\n FileID=Open_File('linint-scalar_xy.dat')\n ELSE \n FileID=Open_File('linint-rank1_xy.dat') \n END IF\n DO i = 1, NI\n WRITE( FileID, '( 12(1x,es20.11e3,:) )' ) xInt(i), yTrue(i), LinInt(i,k)\n END DO\n CLOSE( FileID )\n END DO\n\n\n ! --------------------------------------\n ! Write the polynomial interpolated data\n ! --------------------------------------\n DO k = 1, 2\n IF( k==1 ) THEN\n FileID=Open_File('polyint-scalar_xy.dat')\n ELSE \n FileID=Open_File('polyint-rank1_xy.dat') \n END IF\n DO i = 1, NI\n WRITE( FileID, '( 12(1x,es20.11e3,:) )' ) xInt(i), yTrue(i), (PolyInt(i,j,k),j=1,NORDERS)\n END DO\n CLOSE( FileID )\n END DO\n\n\n ! Write the spline interpolated data\n ! ----------------------------------\n DO k = 1, 2\n IF( k==1 ) THEN\n FileID=Open_File('splineint-scalar_xy.dat')\n ELSE \n FileID=Open_File('splineint-rank1_xy.dat') \n END IF\n DO i = 1, NI\n WRITE( FileID, '( 12(1x,es20.11e3,:))' ) xInt(i), yTrue(i), SplineInt(i,k)\n END DO\n CLOSE( FileID )\n END DO\n\n\nCONTAINS\n\n\n FUNCTION Func( x ) RESULT( y )\n REAL(fp), DIMENSION(:), INTENT(IN) :: x\n REAL(fp), DIMENSION(SIZE(x)) :: y\n INTEGER, PARAMETER :: N_COEFF = 5\n REAL(fp), PARAMETER, DIMENSION( 0:N_COEFF ) :: COEFF = &\n (/ 0.2_fp, -25.0_fp, 200.0_fp, &\n -675.0_fp, 900.0_fp, -400.0_fp /)\n INTEGER :: i\n y = COEFF( N_COEFF )\n DO i = N_COEFF - 1, 0, -1\n y = ( x * y ) + COEFF( i )\n END DO\n END FUNCTION Func\n\n FUNCTION Open_File( Filename ) RESULT( FileID )\n CHARACTER(*), INTENT(IN) :: Filename\n INTEGER :: FileID\n FileID = Get_Lun()\n OPEN( FileID, FILE = Filename, &\n FORM = 'FORMATTED', &\n ACCESS = 'SEQUENTIAL', &\n STATUS = 'REPLACE' )\n END FUNCTION Open_File\n\nEND PROGRAM Test_Interpolate_Utility\n", "meta": {"hexsha": "1f3ada861032eca5b2aaff61d25deb379f337c83", "size": 6952, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/Utility/Interpolate_Utility/Test/Test_Interpolate_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/Interpolate_Utility/Test/Test_Interpolate_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/Interpolate_Utility/Test/Test_Interpolate_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": 29.8369098712, "max_line_length": 95, "alphanum_fraction": 0.5138089758, "num_tokens": 2310, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473846343393, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.6780755054727512}} {"text": "*======================================================================*\n*\n SUBROUTINE Store_roots\n*\n INCLUDE 'parameters.f'\n*\n************************************************************************\n* *\n* Stores the square root of the integers from 0 to 2*Nmax in *\n* the array \"root\", and square roots of the factorials in \"fact\" *\n* *\n************************************************************************\n*\n integer i\n real*8 root(0:2*Nmax), fact(0:2*Nmax)\n common /sqrts/ root, fact\n*\n root(0) = 0.d0\n fact(0) = 1.d0\n do i=1,2*Nmax\n root(i) = dsqrt((0.d0+i))\n fact(i) = root(i)*fact(i-1)\n end do\n*\n end\n*\n*======================================================================*\n*\n SUBROUTINE Fill_G\n*\n INCLUDE 'parameters.f'\n*\n************************************************************************\n* *\n* Fills the array G(nu,n,m) with the functions g_{\\nu n}^m as *\n* defined in equation (2.6) of the paper. *\n* *\n************************************************************************\n*\n integer nu,n,m,im\n real*8 root(0:2*Nmax), fact(0:2*Nmax)\n common /sqrts/ root, fact\n*\n do nu=0,Nmax\n do n=0,Nmax\n do m=-Nmax,Nmax\n g(nu,n,m) = 0.d0\n end do\n g(nu,n,n) = 1.d0\n do m=n-1,1,-1\n g(nu,n,m) = (nu+m+1.d0)*g(nu,n,m+1)/(0.d0+n-m)\n end do\n g(nu,n,-n) = 1.d0\n if (n .NE. 0) then\n g(nu,n,-n+1) = (nu+n)*g(nu,n,-n)\n do m=-n+1,-2\n g(nu,n,m+1) = (nu-m)*g(nu,n,m)/(n+m+1.d0)\n end do\n g(nu,n,0) = g(nu,n-1,0)*(nu+n)/(0.d0+n)\n else\n g(nu,n,0) = 1.d0\n end if\n end do\n end do\n*\n do n=0,Nmax\n do m=-n,n\n if (m .LT. 0) then \n im = -m\n else\n im = m\n end if\n FracH(n,n,m) = 1.d0\n do nu=n-1,im,-1\n FracH(n,nu,m) = root(2*nu+3)*root(nu-im+1)*\n + FracH(n,nu+1,m)/(root(2*nu+1)*root(nu+im+1))\n end do\n do nu=n+1,Nmax\n FracH(n,nu,m) = root(2*nu-1)*root(nu+im)*FracH(n,nu-1,m)/\n + (root(2*nu+1)*root(nu-im))\n end do\n end do\n end do\n*\n end\n*\n*======================================================================*\n*\n real*8 FUNCTION H(n,m)\n*\n INCLUDE 'parameters.f'\n*\n************************************************************************\n* *\n* The function H(n,m) is the constant h_n^m as *\n* defined in equation (2.6) of the paper. *\n* *\n************************************************************************\n*\n integer n,m,im\n real*8 root(0:2*Nmax), fact(0:2*Nmax)\n common /sqrts/ root, fact \n*\n if (m .LT. 0) then \n im = -m\n else\n im = m\n end if\n H = root(2*n+1)*fact(n-im)/fact(n+im)\n H = H/(2.d0*dsqrt(pi))\n*\n end\n*\n*======================================================================*\n*\n SUBROUTINE Set_N\n*\n INCLUDE 'parameters.f'\n*\n************************************************************************\n* *\n* Fixes the following constants: *\n* Neach(i): the number of n-terms of Lamb's solution to be used *\n* for particle i *\n* NN(i,j) : the N-value relevant to the separation between *\n* particles i and j (used for rotation matrices) *\n* MainN : the maximum of Neach(i) across all particles *\n* *\n* The method is based on equation (2.33) of the paper. *\n* *\n* If parameter NFUDGE is set to TRUE, the code will not abort if *\n* the matrices are too small for optimal accuracy; a warning *\n* message is printed out. *\n* *\n************************************************************************\n*\n integer i,j\n real*8 zeta,q\n*\n do i=1,Nspheres\n Neach(i) = 1\n end do\n MainN = 1\n do i=1,Nspheres\n do j=i+1,Nspheres\n zeta = 2.d0*dabs(r(i,j))/(radius(i)+radius(j))\n q = 0.5d0*(zeta - dsqrt(zeta**2 - 4.d0))\n NN(i,j) = int(dlog(globalerror)/dlog(q))+1\nc-----c\n if (NN(i,j) .GT. Nmax) then\n if (NFUDGE) then\n print *,'Using fudge for N'\n NN(i,j) = Nmax\n else\n print *,'Warning: N about to be too small',i,j,NN(i,j)\n end if\n end if\nc-----c\n NN(j,i) = NN(i,j)\n if (NN(i,j) .GT. Neach(i)) then\n Neach(i) = NN(i,j)\n end if\n if (NN(i,j) .GT. Neach(j)) then\n Neach(j) = NN(i,j)\n end if\n if (NN(i,j) .GT. MainN) then\n MainN = NN(i,j)\n end if\n end do\n end do\n* \n if (MainN .GT. Nmax) then \n print *,MainN,Nmax\n STOP 'Nmax is too small (or spheres too close)'\n end if\n*\n end\n*\n*======================================================================*\n*\n SUBROUTINE Update_Fields(i)\n*\n INCLUDE 'parameters.f'\n*\n integer i,j,m,n\n\n***********************************************************************\n* *\n* This subroutine completes a reflection by: *\n* * Adding X(*,i,2,*,*) to X(*,i,1,*,*); *\n* * Moving X(*,i,3,*,*) to X(*,i,2,*,*); and *\n* * Setting X(*,i,3,*,*) to zero ready for the next reflection * \n* * Setting X(*,i,4,*,*) to zero ready for the next reflection * \n* *\n***********************************************************************\n*\n do j=1,2\n do n=0,Neach(i)\n do m=-n,n\n A(j,i,1,n,m) = A(j,i,1,n,m) + A(j,i,2,n,m)\n A(j,i,2,n,m) = A(j,i,3,n,m)\n A(j,i,3,n,m) = 0.d0\n B(j,i,1,n,m) = B(j,i,1,n,m) + B(j,i,2,n,m)\n B(j,i,2,n,m) = B(j,i,3,n,m)\n B(j,i,3,n,m) = 0.d0\n C(j,i,1,n,m) = C(j,i,1,n,m) + C(j,i,2,n,m)\n C(j,i,2,n,m) = C(j,i,3,n,m)\n C(j,i,3,n,m) = 0.d0\n D(j,i,1,n,m) = D(j,i,1,n,m) + D(j,i,2,n,m)\n D(j,i,2,n,m) = 0.d0\n E(j,i,1,n,m) = E(j,i,1,n,m) + E(j,i,2,n,m)\n E(j,i,2,n,m) = 0.d0\n F(j,i,1,n,m) = F(j,i,1,n,m) + F(j,i,2,n,m)\n F(j,i,2,n,m) = 0.d0\n end do\n end do\n end do\n*\n end\n*\n*======================================================================*\n*\n real*8 FUNCTION Find_force(k,p)\n*\n INCLUDE 'parameters.f'\n*\n************************************************************************\n* *\n* Calculates the magnitude of the additional velocity contribution *\n* contained in the fields X(*,k,p,*,*). Result is the sum of the *\n* magnitudes of velocity and angular velocity vectors. Used to *\n* determine when to terminate the iterations; was also handy for *\n* debugging. *\n* *\n************************************************************************\n*\n* Inputs\n integer k,p\n*\n* Internal variables\n integer i,j\n real*8 Fxr, Fyr, Fzr, Fxi, Fyi, Fzi, H\n real*8 Txr, Tyr, Tzr, Txi, Tyi, Tzi, Torque\n real*8 Uxr, Uyr, Uzr, Uxi, Uyi, Uzi\n real*8 Oxr, Oyr, Ozr, Oxi, Oyi, Ozi\n real*8 V(1:2,-1:1), O(1:2,-1:1)\n*\n do i=1,2\n do j=-1,1\n V(i,j) = H(1,j)*(-5.d0*A(i,k,p,1,j)/radius(k)**3 + \n + 1.5d0*C(i,k,p,1,j)/radius(k) + \n + D(i,k,p,1,j))\n O(i,j) = H(1,j)*(B(i,k,p,1,j)/radius(k)**3+E(i,k,p,1,j))\n end do\n end do\n Uxr = V(1,0)\n Uxi = V(2,0)\n Uyr = -1.d0*(V(1,1)-V(1,-1))\n Uyi = -1.d0*(V(2,1)-V(2,-1))\n Uzr = -1.d0*(V(2,1)+V(2,-1))\n Uzi = V(1,1)+V(1,-1)\n*\n Oxr = O(1,0)\n Oxi = O(2,0)\n Oyr = O(1,-1)-O(1,1)\n Oyi = O(2,-1)-O(2,1)\n Ozr = -1.d0*(O(2,1)+O(2,-1))\n Ozi = O(1,1)+O(1,-1)\n*\n Find_force = Uxr**2.d0 + Uyr**2.d0 + Uzr**2.d0 + \n + Uxi**2.d0 + Uyi**2.d0 + Uzi**2.d0 \n Torque = Oxr**2.d0 + Oyr**2.d0 + Ozr**2.d0 + \n + Oxi**2.d0 + Oyi**2.d0 + Ozi**2.d0\n*\n Find_force = 6.d0*pi*radius(k)*\n + (dsqrt(Find_force) + dsqrt(Torque))\n* \n end\n*\n*======================================================================*\n", "meta": {"hexsha": "1f2d031bfde1de38aeed544c981969b3bfc50312", "size": 9686, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "find_resistance_scalars/helen_fortran/base.f", "max_stars_repo_name": "Pecnut/stokesian-dynamics", "max_stars_repo_head_hexsha": "89b9108f0e15414291f9d7134f312657ee64c496", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2019-01-30T14:54:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T20:25:07.000Z", "max_issues_repo_path": "find_resistance_scalars/helen_fortran/base.f", "max_issues_repo_name": "henryleeeee/stokesian-dynamics", "max_issues_repo_head_hexsha": "89b9108f0e15414291f9d7134f312657ee64c496", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "find_resistance_scalars/helen_fortran/base.f", "max_forks_repo_name": "henryleeeee/stokesian-dynamics", "max_forks_repo_head_hexsha": "89b9108f0e15414291f9d7134f312657ee64c496", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2019-07-05T01:08:11.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-27T17:05:33.000Z", "avg_line_length": 34.4697508897, "max_line_length": 72, "alphanum_fraction": 0.3134420814, "num_tokens": 2646, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473846343394, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.6780755009723769}} {"text": " SUBROUTINE SPOLZ2(A,Z)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc>> 1996-04-27 SPOLZ2 Krogh Changes to use .C. and C%%.\nc>> 1996-03-30 SPOLZ2 Krogh Added external statement.\nC>> 1996-01-18 SPOLZ2 Krogh Added code for M77CON for conversion to C.\nC>> 1992-03-13 SPOLZ2 FTK Removed implicit statements.\nC>> 1987-02-25 SPOLZ2 Lawson Initial code.\nc--S Replaces \"?\": ?POLZ2\nc++ Default NO_COMPLEX = .C. | (.N. == 'D')\nc++ Default COMPLEX = ~NO_COMPLEX\nC\nC ------------------------------------------------------------------\nC\nC Find the two roots of the quadratic polynomial\nC A(1)*X*X + A(2)*X + A(3)\nC Return the roots as the complex numbers (Z(1), Z(2)) and\nC (Z(3), Z(4)) if Z is not complex, else return the two complex\nC numbers, Z(1) and Z(2).\nC Require A(1) .ne. 0.\nC\nC Method:\nC Divide through by A(1). New polynomial is\nC X*X + P*X + Q\nC Let U = -P/2\nC Roots are U + SQRT(U*U-Q) and U - SQRT(U*U-Q).\nC Avoid computing U*U explicity if it might overflow or\nC underflow. In case of real roots, U + Z and U - Z, the first\nC root is U + SIGN(U)*ABS(Z) and the second is Q / Z(1).\nC\nc C. L. Lawson & S. Chiu, JPL, 1987 Feb 16.\nC ------------------------------------------------------------------\nC\n EXTERNAL R1MACH\n REAL A(3),AQ,AU,C1,C16,C2,D,R1MACH,F,HALF,ONE,P,Q\n REAL U,V,W,ZERO\n PARAMETER(ZERO=0.E0, HALF=.5E0, ONE=1.E0, C16=16.E0)\n LOGICAL FIRST\nc++ CODE for COMPLEX is active\n COMPLEX Z(2), R1, R2\nc++ CODE for NO_COMPLEX is inactive\nC REAL Z(4), R1, R2, R3, R4\nc++ END\nC\n SAVE FIRST, C1, C2\nC\n DATA FIRST / .TRUE. /\nC -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n IF (FIRST) THEN\n FIRST = .FALSE.\nC\nC R1MACH(1) is the underflow limit.\nC\n C1 = SQRT(R1MACH(1)*C16)\nC\nC R1MACH(2) is the overflow limit.\nC\n C2 = SQRT(R1MACH(2)/C16)\n END IF\nC\n IF (A(1) .EQ. ZERO) THEN\n CALL ERMSG('SPOLZ2',1,0,'A(1) .EQ. 0.','.')\n R1 = ZERO\n R2 = ZERO\nc++ CODE for NO_COMPLEX is inactive\nC R3 = ZERO\nC R4 = ZERO\nc++ END\n GO TO 99\n ELSE\n P = A(2) / A(1)\n Q = A(3) / A(1)\n END IF\nC\n IF (Q .EQ. ZERO) THEN\n R1 = ZERO\nc++ CODE for COMPLEX is active\n R2 = -P\nc++ CODE for NO_COMPLEX is inactive\nC R2 = ZERO\nC R3 = -P\nC R4 = ZERO\nc++ END\n GO TO 99\n END IF\nC\n IF (P .EQ. ZERO) THEN\n W = SQRT(ABS(Q))\n IF (Q .GT. ZERO) THEN\nc++ CODE for COMPLEX is active\n R1 = CMPLX(ZERO,W)\n R2 = CMPLX(ZERO,-W)\nc++ CODE for NO_COMPLEX is inactive\nC R1 = ZERO\nC R2 = W\nC R3 = ZERO\nC R4 = -W\nc++ END\n ELSE\nc++ CODE for COMPLEX is active\n R1 = CMPLX(W,ZERO)\n R2 = CMPLX(-W,ZERO)\nc++ CODE for NO_COMPLEX is inactive\nC R1 = W\nC R2 = ZERO\nC R3 = -W\nC R4 = ZERO\nc++ END\n END IF\n GO TO 99\n END IF\n U = -P * HALF\nC\nC Compute D having the sign of U*U-Q\nC and F = SQRT(ABS(U*U-Q))\nC\n AU = ABS(U)\n IF (AU .GT. C2) THEN\n D = ONE - (Q/U) / U\n F = AU * SQRT(ABS(D))\n ELSE IF (AU .LT. C1) THEN\n AQ = ABS(Q)\n D = U * (U/AQ) - SIGN(ONE, Q)\n F = SQRT(AQ) * SQRT(ABS(D))\n ELSE\n D = U*U - Q\n F = SQRT(ABS(D))\n END IF\nC\n IF (D .EQ. ZERO) THEN\nc++ CODE for COMPLEX is active\n R1 = CMPLX(U,ZERO)\n R2 = R1\nc++ CODE for NO_COMPLEX is inactive\nC R1 = U\nC R2 = ZERO\nC R3 = R1\nC R4 = ZERO\nc++ END\n ELSE\n IF (D .GT. ZERO) THEN\n IF (U .GT. ZERO) THEN\n V = U + F\n ELSE\n V = U - F\n END IF\nc++ CODE for COMPLEX is active\n R1 = CMPLX(V,ZERO)\n R2 = CMPLX(Q/V,ZERO)\nc++ CODE for NO_COMPLEX is inactive\nC R1 = V\nC R2 = ZERO\nC R3 = Q/V\nC R4 = ZERO\nc++ END\n ELSE\nc++ CODE for COMPLEX is active\n R1 = CMPLX(U,F)\n R2 = CMPLX(U,-F)\nc++ CODE for NO_COMPLEX is inactive\nC R1 = U\nC R2 = F\nC R3 = U\nC R4 = -F\nc++ END\n END IF\n END IF\nC\n 99 CONTINUE\n Z(1) = R1\n Z(2) = R2\nc++ CODE for NO_COMPLEX is inactive\nC Z(3) = R3\nC Z(4) = R4\nc++ END\n RETURN\n END\n", "meta": {"hexsha": "0dd271a4b143d80aee25168290aac4738fa9ba87", "size": 4556, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/spolz2.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/spolz2.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/spolz2.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": 25.4525139665, "max_line_length": 72, "alphanum_fraction": 0.4846356453, "num_tokens": 1635, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473647220786, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.6780754899949537}} {"text": " Program dhgeqz_example\n\n! DHGEQZ Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_example_aux, Only: nagf_file_print_matrix_real_gen\n Use lapack_interfaces, Only: dgeqrf, dggbal, dgghd3, dhgeqz, dormqr\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nin = 5, nout = 6\n! .. Local Scalars ..\n Integer :: i, ifail, ihi, ilo, info, irows, jwork, lda, ldb, ldq, ldz, &\n lwork, n\n Character (1) :: compq, compz, job\n! .. Local Arrays ..\n Real (Kind=dp), Allocatable :: a(:, :), alphai(:), alphar(:), b(:, :), &\n beta(:), lscale(:), q(:, :), rscale(:), tau(:), work(:), z(:, :)\n! .. Intrinsic Procedures ..\n Intrinsic :: nint\n! .. Executable Statements ..\n Write (nout, *) 'DHGEQZ Example Program Results'\n Flush (nout)\n\n! Skip heading in data file\n\n Read (nin, *)\n Read (nin, *) n\n ldq = 1\n ldz = 1\n lda = n\n ldb = n\n lwork = 6*n\n Allocate (alphai(n), alphar(n), beta(n), a(lda,n), lscale(n), &\n q(ldq,ldq), rscale(n), b(ldb,n), tau(n), work(lwork), z(ldz,ldz))\n\n! READ matrix A from data file\n Read (nin, *)(a(i,1:n), i=1, n)\n\n! READ matrix B from data file\n Read (nin, *)(b(i,1:n), i=1, n)\n\n! Balance matrix pair (A,B)\n job = 'B'\n\n Call dggbal(job, n, a, lda, b, ldb, ilo, ihi, lscale, rscale, work, &\n info)\n\n! Matrix A after balancing\n\n! ifail: behaviour on error exit\n! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft\n ifail = 0\n Call nagf_file_print_matrix_real_gen('General', ' ', n, n, a, lda, &\n 'Matrix A after balancing', ifail)\n\n Write (nout, *)\n Flush (nout)\n\n! Matrix B after balancing\n\n ifail = 0\n Call nagf_file_print_matrix_real_gen('General', ' ', n, n, b, ldb, &\n 'Matrix B after balancing', ifail)\n\n Write (nout, *)\n Flush (nout)\n\n! Reduce B to triangular form using QR\n irows = ihi + 1 - ilo\n\n Call dgeqrf(irows, irows, b(ilo,ilo), ldb, tau, work, lwork, info)\n\n! Apply the orthogonal transformation to matrix A\n Call dormqr('L', 'T', irows, irows, irows, b(ilo,ilo), ldb, tau, &\n a(ilo,ilo), lda, work, lwork, info)\n\n! Compute the generalized Hessenberg form of (A,B) -> (H,T)\n compq = 'N'\n compz = 'N'\n\n Call dgghd3(compq, compz, irows, 1, irows, a(ilo,ilo), lda, b(ilo,ilo), &\n ldb, q, ldq, z, ldz, work, lwork, info)\n\n! Matrix A (H) in generalized Hessenberg form.\n\n ifail = 0\n Call nagf_file_print_matrix_real_gen('General', ' ', n, n, a, lda, &\n 'Matrix A in Hessenberg form', ifail)\n\n Write (nout, *)\n Flush (nout)\n\n! Matrix B (T) in generalized Hessenberg form.\n\n ifail = 0\n Call nagf_file_print_matrix_real_gen('General', ' ', n, n, b, ldb, &\n 'Matrix B is triangular', ifail)\n\n! Routine DHGEQZ\n! Workspace query: jwork = -1\n\n jwork = -1\n job = 'E'\n\n Call dhgeqz(job, compq, compz, n, ilo, ihi, a, lda, b, ldb, alphar, &\n alphai, beta, q, ldq, z, ldz, work, jwork, info)\n\n Write (nout, *)\n Write (nout, 100) nint(work(1))\n Write (nout, 110) lwork\n Write (nout, *)\n\n! Compute the generalized Schur form\n! if the workspace lwork is adequate\n\n If (nint(work(1))<=lwork) Then\n\n Call dhgeqz(job, compq, compz, n, ilo, ihi, a, lda, b, ldb, alphar, &\n alphai, beta, q, ldq, z, ldz, work, lwork, info)\n\n! Print the generalized eigenvalues\n\n Write (nout, 120)\n\n Do i = 1, n\n If (beta(i)/=0.0E0_dp) Then\n Write (nout, 130) i, '(', alphar(i)/beta(i), ',', &\n alphai(i)/beta(i), ')'\n Else\n Write (nout, 150) i\n End If\n End Do\n Else\n Write (nout, 140)\n End If\n\n100 Format (1X, 'Minimal required LWORK = ', I6)\n110 Format (1X, 'Actual value of LWORK = ', I6)\n120 Format (1X, 'Generalized eigenvalues')\n130 Format (1X, I4, 5X, A, F7.3, A, F7.3, A)\n140 Format (1X, 'Insufficient workspace allocated for call to DHGEQZ')\n150 Format (1X, I4, 'Eigenvalue is infinite')\n End Program\n", "meta": {"hexsha": "c3ae335447144d0a02299a055ee655a7018fb027", "size": 4436, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/dhgeqz_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/dhgeqz_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/dhgeqz_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 29.5733333333, "max_line_length": 90, "alphanum_fraction": 0.5613165014, "num_tokens": 1462, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894604912849, "lm_q2_score": 0.757794360334681, "lm_q1q2_score": 0.6780664068472075}} {"text": "!*==srotg.f90 processed by SPAG 7.51RB at 20:37 on 3 Mar 2022\n!> \\brief \\b SROTG\n!\n! =========== DOCUMENTATION ===========\n!\n! Online html documentation available at\n! http://www.netlib.org/lapack/explore-html/\n!\n! Definition:\n! ===========\n!\n! SUBROUTINE SROTG(SA,SB,C,S)\n!\n! .. Scalar Arguments ..\n! REAL C,S,SA,SB\n! ..\n!\n!\n!> \\par Purpose:\n! =============\n!>\n!> \\verbatim\n!>\n!> SROTG construct givens plane rotation.\n!> \\endverbatim\n!\n! Arguments:\n! ==========\n!\n!> \\param[in,out] SA\n!> \\verbatim\n!> SA is REAL\n!> \\endverbatim\n!>\n!> \\param[in,out] SB\n!> \\verbatim\n!> SB is REAL\n!> \\endverbatim\n!>\n!> \\param[out] C\n!> \\verbatim\n!> C is REAL\n!> \\endverbatim\n!>\n!> \\param[out] S\n!> \\verbatim\n!> S is REAL\n!> \\endverbatim\n!\n! Authors:\n! ========\n!\n!> \\author Univ. of Tennessee\n!> \\author Univ. of California Berkeley\n!> \\author Univ. of Colorado Denver\n!> \\author NAG Ltd.\n!\n!> \\date November 2017\n!\n!> \\ingroup single_blas_level1\n!\n!> \\par Further Details:\n! =====================\n!>\n!> \\verbatim\n!>\n!> jack dongarra, linpack, 3/11/78.\n!> \\endverbatim\n!>\n! =====================================================================\n SUBROUTINE SROTG(Sa,Sb,C,S)\n IMPLICIT NONE\n!*--SROTG73\n!\n! -- Reference BLAS level1 routine (version 3.8.0) --\n! -- Reference BLAS is a software package provided by Univ. of Tennessee, --\n! -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n! November 2017\n!\n! .. Scalar Arguments ..\n REAL C , S , Sa , Sb\n! ..\n!\n! =====================================================================\n!\n! .. Local Scalars ..\n REAL r , roe , scale , z\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC ABS , SIGN , SQRT\n! ..\n scale = ABS(Sa) + ABS(Sb)\n IF ( scale==0.0 ) THEN\n C = 1.0\n S = 0.0\n r = 0.0\n z = 0.0\n ELSE\n roe = Sb\n IF ( ABS(Sa)>ABS(Sb) ) roe = Sa\n r = scale*SQRT((Sa/scale)**2+(Sb/scale)**2)\n r = SIGN(1.0,roe)*r\n C = Sa/r\n S = Sb/r\n z = 1.0\n IF ( ABS(Sa)>ABS(Sb) ) z = S\n IF ( ABS(Sb)>=ABS(Sa) .AND. C/=0.0 ) z = 1.0/C\n ENDIF\n Sa = r\n Sb = z\n END SUBROUTINE SROTG\n", "meta": {"hexsha": "a9cac8468d25ce44f02bb81cabf0f7b621c4b46d", "size": 2297, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/blas/srotg.f90", "max_stars_repo_name": "urbanjost/spag_lapack", "max_stars_repo_head_hexsha": "1b082638c0ff5feb1a295a3aa4624c538d14847c", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2022-03-04T13:15:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-04T17:40:26.000Z", "max_issues_repo_path": "src/blas/srotg.f90", "max_issues_repo_name": "urbanjost/spag_lapack", "max_issues_repo_head_hexsha": "1b082638c0ff5feb1a295a3aa4624c538d14847c", "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": "src/blas/srotg.f90", "max_forks_repo_name": "urbanjost/spag_lapack", "max_forks_repo_head_hexsha": "1b082638c0ff5feb1a295a3aa4624c538d14847c", "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": 20.5089285714, "max_line_length": 80, "alphanum_fraction": 0.46669569, "num_tokens": 764, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391624034103, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.6780288553588321}} {"text": "*----------------------------------------------------------------------*\n subroutine regular_tikhonov(ncol,nlin,mat,sv,omega2)\n*----------------------------------------------------------------------*\n* multiplies the columns of the input matrix with a regularization\n* factor based on the corresponding singular value,\n* in order to achieve Tikhonov regularization.\n* We assume that the input matrix already contains sv^(-1/2),\n* such that the needed factor is sv/sqrt(sv^2+omega2)\n*\n* matthias, jul 2012\n*----------------------------------------------------------------------*\n implicit none\n\n integer, intent(in) ::\n & ncol, nlin\n real(8), intent(inout) ::\n & mat(nlin,ncol)\n real(8), intent(in) ::\n & sv(ncol), omega2\n\n real(8) ::\n & fac\n integer ::\n & icol\n real(8), external ::\n & ddot\n\n if (nlin.eq.0) return\n\nc dbg\nc write(*,*) 'before Tikhonov:'\nc call wrtmat2(mat,nlin,ncol,nlin,ncol)\nc write(*,*) 'singular values:'\nc call wrtmat2(sv,1,ncol,1,ncol)\nc dbgend\n\n do icol = 1, ncol\n fac = sv(icol)/sqrt(sv(icol)**2+omega2)\nc ! modified regularization: s^-1/2 --> 1/(s^2+omega2)^0.25\nc fac = sqrt(sv(icol))/((sv(icol)**2+omega2)**0.25d0)\nc ! mod: just unitary matrix\nc fac = sqrt(sv(icol))\n mat(1:nlin,icol) = fac * mat(1:nlin,icol)\n end do\nc dbg\nc write(*,*) 'after Tikhonov:'\nc call wrtmat2(mat,nlin,ncol,nlin,ncol)\nc write(*,*) 'norms:'\nc do icol = 1, ncol\nc fac = ddot(nlin,mat(1,icol),1,mat(1,icol),1)\nc if (fac.gt.1d-12) print *,icol,fac\nc end do\nc dbgend\n\n return\n end\n", "meta": {"hexsha": "28efc7d1653a122c3024be362b19e23e85a00d81", "size": 1763, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "math/regular_tikhonov.f", "max_stars_repo_name": "ak-ustutt/GeCCo-public", "max_stars_repo_head_hexsha": "8d43a6c9323aeba7eb54625b95553bfd4b2418c6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "math/regular_tikhonov.f", "max_issues_repo_name": "ak-ustutt/GeCCo-public", "max_issues_repo_head_hexsha": "8d43a6c9323aeba7eb54625b95553bfd4b2418c6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "math/regular_tikhonov.f", "max_forks_repo_name": "ak-ustutt/GeCCo-public", "max_forks_repo_head_hexsha": "8d43a6c9323aeba7eb54625b95553bfd4b2418c6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.9298245614, "max_line_length": 72, "alphanum_fraction": 0.4826999433, "num_tokens": 519, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.67802885417622}} {"text": "program main\n implicit none\n integer :: counter\n !integer :: counter2\n real :: sum = 0\n integer :: factorial\n\n do counter = 1, 10\n !factorial = 1\n !do counter2 = 2, n\n ! factorial = factorial * counter2\n !end do\n sum = sum + 1.0 / factorial(counter)\n end do\n write (*,'(A, F0.6)') 'The result of 1/1!+1/2!+1/3!+1/$!+9+...+1/10! is ', sum\nend program main\n\nfunction factorial(n)\n implicit none\n integer :: n\n integer :: factorial\n integer :: counter\n\n factorial = 1\n do counter = 2, n\n factorial = factorial * counter\n end do\n return\nend function\n", "meta": {"hexsha": "7e1427354f9f24d42b8b271b858d38cf6b873dc8", "size": 639, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "homework/chapter6/6_4/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_4/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_4/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": 21.3, "max_line_length": 82, "alphanum_fraction": 0.5571205008, "num_tokens": 201, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391624034103, "lm_q2_score": 0.7853085783754369, "lm_q1q2_score": 0.6780288488514811}} {"text": "program leap_year\n implicit none\n\n print *, 1899, is_leap_year(1899)\n print *, 1936, is_leap_year(1936)\n print *, 1900, is_leap_year(1900)\n print *, 2000, is_leap_year(2000)\n\ncontains\n\n logical function is_leap_year(year)\n implicit none\n integer :: year\n\n if (mod(year, 4) == 0) then\n if (mod(year, 100) == 0) then\n if (mod(year, 400) == 0) then\n is_leap_year = .true.\n else\n is_leap_year = .false.\n end if\n else\n is_leap_year = .true.\n end if\n else\n is_leap_year = .false.\n end if\n end function is_leap_year\n\nend program leap_year\n", "meta": {"hexsha": "ad87fe10f827fd96c07101274cbcbef544f06cec", "size": 730, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "scenarios/Week_01/If_statements/leap_year_04.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": "scenarios/Week_01/If_statements/leap_year_04.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": "scenarios/Week_01/If_statements/leap_year_04.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": 23.5483870968, "max_line_length": 45, "alphanum_fraction": 0.5123287671, "num_tokens": 203, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916029436189, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.6780288431345276}} {"text": "c\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc . .\nc . copyright (c) 1998 by UCAR .\nc . .\nc . University Corporation for Atmospheric Research .\nc . .\nc . all rights reserved .\nc . .\nc . .\nc . SPHEREPACK .\nc . .\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc\nc\nc\nc ... file shagc.f\nc\nc this file contains code and documentation for subroutines\nc shagc and shagci\nc\nc ... files which must be loaded with shagc.f\nc\nc sphcom.f, hrfft.f, gaqd.f\nc\nc\nc subroutine shagc(nlat,nlon,isym,nt,g,idg,jdg,a,b,mdab,ndab,\nc + wshagc,lshagc,work,lwork,ierror)\nc\nc subroutine shagc performs the spherical harmonic analysis\nc on the array g and stores the result in the arrays a and b.\nc the analysis is performed on a gaussian grid in colatitude\nc and an equally spaced grid in longitude. the associated\nc legendre functions are recomputed rather than stored as they\nc are in subroutine shags. the analysis is described below\nc at output parameters a,b.\nc\nc input parameters\nc\nc nlat the number of points in the gaussian colatitude grid on the\nc full sphere. these lie in the interval (0,pi) and are compu\nc in radians in theta(1),...,theta(nlat) by subroutine gaqd.\nc if nlat is odd the equator will be included as the grid poi\nc theta((nlat+1)/2). if nlat is even the equator will be\nc excluded as a grid point and will lie half way between\nc theta(nlat/2) and theta(nlat/2+1). nlat must be at least 3.\nc note: on the half sphere, the number of grid points in the\nc colatitudinal direction is nlat/2 if nlat is even or\nc (nlat+1)/2 if nlat is odd.\nc\nc nlon the number of distinct londitude points. nlon determines\nc the grid increment in longitude as 2*pi/nlon. for example\nc nlon = 72 for a five degree grid. nlon must be greater\nc than or equal to 4. the efficiency of the computation is\nc improved when nlon is a product of small prime numbers.\nc\nc isym = 0 no symmetries exist about the equator. the analysis\nc is performed on the entire sphere. i.e. on the\nc array g(i,j) for i=1,...,nlat and j=1,...,nlon.\nc (see description of g below)\nc\nc = 1 g is antisymmetric about the equator. the analysis\nc is performed on the northern hemisphere only. i.e.\nc if nlat is odd the analysis is performed on the\nc array g(i,j) for i=1,...,(nlat+1)/2 and j=1,...,nlon.\nc if nlat is even the analysis is performed on the\nc array g(i,j) for i=1,...,nlat/2 and j=1,...,nlon.\nc\nc\nc = 2 g is symmetric about the equator. the analysis is\nc performed on the northern hemisphere only. i.e.\nc if nlat is odd the analysis is performed on the\nc array g(i,j) for i=1,...,(nlat+1)/2 and j=1,...,nlon.\nc if nlat is even the analysis is performed on the\nc array g(i,j) for i=1,...,nlat/2 and j=1,...,nlon.\nc\nc nt the number of analyses. in the program that calls shagc,\nc the arrays g,a and b can be three dimensional in which\nc case multiple analyses will be performed. the third\nc index is the analysis index which assumes the values\nc k=1,...,nt. for a single analysis set nt=1. the\nc discription of the remaining parameters is simplified\nc by assuming that nt=1 or that the arrays g,a and b\nc have only two dimensions.\nc\nc g a two or three dimensional array (see input parameter\nc nt) that contains the discrete function to be analyzed.\nc g(i,j) contains the value of the function at the gaussian\nc point theta(i) and longitude point phi(j) = (j-1)*2*pi/nlon\nc the index ranges are defined above at the input parameter\nc isym.\nc\nc idg the first dimension of the array g as it appears in the\nc program that calls shagc. if isym equals zero then idg\nc must be at least nlat. if isym is nonzero then idg must\nc be at least nlat/2 if nlat is even or at least (nlat+1)/2\nc if nlat is odd.\nc\nc jdg the second dimension of the array g as it appears in the\nc program that calls shagc. jdg must be at least nlon.\nc\nc mdab the first dimension of the arrays a and b as it appears\nc in the program that calls shagc. mdab must be at least\nc min0((nlon+2)/2,nlat) if nlon is even or at least\nc min0((nlon+1)/2,nlat) if nlon is odd\nc\nc ndab the second dimension of the arrays a and b as it appears\nc in the program that calls shaec. ndab must be at least nlat\nc\nc wshagc an array which must be initialized by subroutine shagci.\nc once initialized, wshagc can be used repeatedly by shagc.\nc as long as nlat and nlon remain unchanged. wshagc must\nc not be altered between calls of shagc.\nc\nc lshagc the dimension of the array wshagc as it appears in the\nc program that calls shagc. define\nc\nc l1 = min0(nlat,(nlon+2)/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc and\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc then lshagc must be at least\nc\nc nlat*(2*l2+3*l1-2)+3*l1*(1-l1)/2+nlon+15\nc\nc\nc work a work array that does not have to be saved.\nc\nc lwork the dimension of the array work as it appears in the\nc program that calls shagc. define\nc\nc l1 = min0(nlat,(nlon+2)/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc and\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc if isym is zero then lwork must be at least\nc\nc nlat*(nlon*nt+max0(3*l2,nlon))\nc\nc if isym is not zero then lwork must be at least\nc\nc l2*(nlon*nt+max0(3*nlat,nlon))\nc\nc **************************************************************\nc\nc output parameters\nc\nc a,b both a,b are two or three dimensional arrays (see input\nc parameter nt) that contain the spherical harmonic\nc coefficients in the representation of g(i,j) given in the\nc discription of subroutine shagc. for isym=0, a(m,n) and\nc b(m,n) are given by the equations listed below. symmetric\nc versions are used when isym is greater than zero.\nc\nc definitions\nc\nc 1. the normalized associated legendre functions\nc\nc pbar(m,n,theta) = sqrt((2*n+1)*factorial(n-m)/(2*factorial(n+m)))\nc *sin(theta)**m/(2**n*factorial(n)) times the\nc (n+m)th derivative of (x**2-1)**n with respect\nc to x=cos(theta).\nc\nc 2. the fourier transform of g(i,j).\nc\nc c(m,i) = 2/nlon times the sum from j=1 to j=nlon of\nc g(i,j)*cos((m-1)*(j-1)*2*pi/nlon)\nc (the first and last terms in this sum\nc are divided by 2)\nc\nc s(m,i) = 2/nlon times the sum from j=2 to j=nlon of\nc g(i,j)*sin((m-1)*(j-1)*2*pi/nlon)\nc\nc\nc 3. the gaussian points and weights on the sphere\nc (computed by subroutine gaqd).\nc\nc theta(1),...,theta(nlat) (gaussian pts in radians)\nc wts(1),...,wts(nlat) (corresponding gaussian weights)\nc\nc 4. the maximum (plus one) longitudinal wave number\nc\nc mmax = min0(nlat,(nlon+2)/2) if nlon is even or\nc mmax = min0(nlat,(nlon+1)/2) if nlon is odd.\nc\nc\nc then for m=0,...,mmax-1 and n=m,...,nlat-1 the arrays a,b\nc are given by\nc\nc a(m+1,n+1) = the sum from i=1 to i=nlat of\nc c(m+1,i)*wts(i)*pbar(m,n,theta(i))\nc\nc b(m+1,n+1) = the sum from i=1 to nlat of\nc s(m+1,i)*wts(i)*pbar(m,n,theta(i))\nc\nc ierror = 0 no errors\nc = 1 error in the specification of nlat\nc = 2 error in the specification of nlon\nc = 3 error in the specification of isym\nc = 4 error in the specification of nt\nc = 5 error in the specification of idg\nc = 6 error in the specification of jdg\nc = 7 error in the specification of mdab\nc = 8 error in the specification of ndab\nc = 9 error in the specification of lshagc\nc = 10 error in the specification of lwork\nc\nc\nc ****************************************************************\nc\nc subroutine shagci(nlat,nlon,wshagc,lshagc,dwork,ldwork,ierror)\nc\nc subroutine shagci initializes the array wshagc which can then\nc be used repeatedly by subroutines shagc. it precomputes\nc and stores in wshagc quantities such as gaussian weights,\nc legendre polynomial coefficients, and fft trigonometric tables.\nc\nc input parameters\nc\nc nlat the number of points in the gaussian colatitude grid on the\nc full sphere. these lie in the interval (0,pi) and are compu\nc in radians in theta(1),...,theta(nlat) by subroutine gaqd.\nc if nlat is odd the equator will be included as the grid poi\nc theta((nlat+1)/2). if nlat is even the equator will be\nc excluded as a grid point and will lie half way between\nc theta(nlat/2) and theta(nlat/2+1). nlat must be at least 3.\nc note: on the half sphere, the number of grid points in the\nc colatitudinal direction is nlat/2 if nlat is even or\nc (nlat+1)/2 if nlat is odd.\nc\nc nlon the number of distinct londitude points. nlon determines\nc the grid increment in longitude as 2*pi/nlon. for example\nc nlon = 72 for a five degree grid. nlon must be greater\nc than or equal to 4. the efficiency of the computation is\nc improved when nlon is a product of small prime numbers.\nc\nc wshagc an array which must be initialized by subroutine shagci.\nc once initialized, wshagc can be used repeatedly by shagc\nc as long as nlat and nlon remain unchanged. wshagc must\nc not be altered between calls of shagc.\nc\nc lshagc the dimension of the array wshagc as it appears in the\nc program that calls shagc. define\nc\nc l1 = min0(nlat,(nlon+2)/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc and\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc then lshagc must be at least\nc\nc nlat*(2*l2+3*l1-2)+3*l1*(1-l1)/2+nlon+15\nc\nC*PL*ERROR* Comment line too long\nc dwork a double precision work array that does not have to be saved.\nc\nc ldwork the dimension of the array dwork as it appears in the\nc program that calls shagci. ldwork must be at least\nc\nc nlat*(nlat+4)\nc\nc output parameter\nc\nc wshagc an array which must be initialized before calling shagc or\nc once initialized, wshagc can be used repeatedly by shagc or\nc as long as nlat and nlon remain unchanged. wshagc must not\nc altered between calls of shagc.\nc\nc ierror = 0 no errors\nc = 1 error in the specification of nlat\nc = 2 error in the specification of nlon\nc = 3 error in the specification of lshagc\nc = 4 error in the specification of ldwork\nc = 5 failure in gaqd to compute gaussian points\nc (due to failure in eigenvalue routine)\nc\nc\nc ****************************************************************\n SUBROUTINE DSHAGC(NLAT,NLON,ISYM,NT,G,IDG,JDG,A,B,MDAB,NDAB,\n + WSHAGC,LSHAGC,WORK,LWORK,IERROR)\n DOUBLE PRECISION G\n DOUBLE PRECISION A\n DOUBLE PRECISION B\n DOUBLE PRECISION WSHAGC\n DOUBLE PRECISION WORK\nc subroutine shagc performs the spherical harmonic analysis on\nc a gaussian grid on the array(s) in g and returns the coefficients\nc in array(s) a,b. the necessary legendre polynomials are computed\nc as needed in this version.\nc\n DIMENSION G(IDG,JDG,1),A(MDAB,NDAB,1),B(MDAB,NDAB,1),\n + WSHAGC(LSHAGC),WORK(LWORK)\nc check input parameters\n IERROR = 1\n IF (NLAT.LT.3) RETURN\n IERROR = 2\n IF (NLON.LT.4) RETURN\n IERROR = 3\n IF (ISYM.LT.0 .OR. ISYM.GT.2) RETURN\n IERROR = 4\n IF (NT.LT.1) RETURN\nc set upper limit on m for spherical harmonic basis\n L = MIN0((NLON+2)/2,NLAT)\nc set gaussian point nearest equator pointer\n LATE = (NLAT+MOD(NLAT,2))/2\nc set number of grid points for analysis/synthesis\n LAT = NLAT\n IF (ISYM.NE.0) LAT = LATE\n IERROR = 5\n IF (IDG.LT.LAT) RETURN\n IERROR = 6\n IF (JDG.LT.NLON) RETURN\n IERROR = 7\n IF (MDAB.LT.L) RETURN\n IERROR = 8\n IF (NDAB.LT.NLAT) RETURN\n L1 = L\n L2 = LATE\n IERROR = 9\nc check permanent work space length\n IF (LSHAGC.LT.NLAT* (2*L2+3*L1-2)+3*L1* (1-L1)/2+NLON+15) RETURN\n IERROR = 10\nc check temporary work space length\n IF (ISYM.EQ.0) THEN\n IF (LWORK.LT.NLAT* (NLON*NT+MAX0(3*L2,NLON))) RETURN\n ELSE\nc isym.ne.0\n IF (LWORK.LT.L2* (NLON*NT+MAX0(3*NLAT,NLON))) RETURN\n END IF\n IERROR = 0\nc starting address for gaussian wts in shigc and fft values\n IWTS = 1\n IFFT = NLAT + 2*NLAT*LATE + 3* (L* (L-1)/2+ (NLAT-L)* (L-1)) + 1\nc set pointers for internal storage of g and legendre polys\n IPMN = LAT*NLON*NT + 1\n CALL DSHAGC1(NLAT,NLON,L,LAT,ISYM,G,IDG,JDG,NT,A,B,MDAB,NDAB,\n + WSHAGC,WSHAGC(IWTS),WSHAGC(IFFT),LATE,WORK(IPMN),\n + WORK)\n RETURN\n END\n SUBROUTINE DSHAGC1(NLAT,NLON,L,LAT,MODE,GS,IDG,JDG,NT,A,B,MDAB,\n + NDAB,W,WTS,WFFT,LATE,PMN,G)\n DOUBLE PRECISION GS\n DOUBLE PRECISION A\n DOUBLE PRECISION B\n DOUBLE PRECISION W\n DOUBLE PRECISION WTS\n DOUBLE PRECISION WFFT\n DOUBLE PRECISION PMN\n DOUBLE PRECISION G\n DOUBLE PRECISION SFN\n DOUBLE PRECISION T1\n DOUBLE PRECISION T2\n DIMENSION GS(IDG,JDG,NT),A(MDAB,NDAB,NT),B(MDAB,NDAB,NT),\n + G(LAT,NLON,NT)\n DIMENSION W(1),WTS(NLAT),WFFT(1),PMN(NLAT,LATE,3)\nc set gs array internally in shagc1\n DO 100 K = 1,NT\n DO 100 J = 1,NLON\n DO 100 I = 1,LAT\n G(I,J,K) = GS(I,J,K)\n 100 CONTINUE\nc do fourier transform\n DO 101 K = 1,NT\n CALL DHRFFTF(LAT,NLON,G(1,1,K),LAT,WFFT,PMN)\n 101 CONTINUE\nc scale result\n SFN = 2.0D0/DBLE(NLON)\n DO 102 K = 1,NT\n DO 102 J = 1,NLON\n DO 102 I = 1,LAT\n G(I,J,K) = SFN*G(I,J,K)\n 102 CONTINUE\nc compute using gaussian quadrature\nc a(n,m) = s (ga(theta,m)*pnm(theta)*sin(theta)*dtheta)\nc b(n,m) = s (gb(theta,m)*pnm(theta)*sin(theta)*dtheta)\nc here ga,gb are the cos(phi),sin(phi) coefficients of\nc the fourier expansion of g(theta,phi) in phi. as a result\nc of the above fourier transform they are stored in array\nc g as follows:\nc for each theta(i) and k= l-1\nc ga(0),ga(1),gb(1),ga(2),gb(2),...,ga(k-1),gb(k-1),ga(k)\nc correspond to (in the case nlon=l+l-2)\nc g(i,1),g(i,2),g(i,3),g(i,4),g(i,5),...,g(i,2l-4),g(i,2l-3),g(i,2l-\nc initialize coefficients to zero\n DO 103 K = 1,NT\n DO 103 NP1 = 1,NLAT\n DO 103 MP1 = 1,L\n A(MP1,NP1,K) = 0.0D0\n B(MP1,NP1,K) = 0.0D0\n 103 CONTINUE\nc set m+1 limit on b(m+1) calculation\n LM1 = L\n IF (NLON.EQ.L+L-2) LM1 = L - 1\n IF (MODE.EQ.0) THEN\nc for full sphere (mode=0) and even/odd reduction:\nc overwrite g(i) with (g(i)+g(nlat-i+1))*wts(i)\nc overwrite g(nlat-i+1) with (g(i)-g(nlat-i+1))*wts(i)\n NL2 = NLAT/2\n DO 104 K = 1,NT\n DO 104 J = 1,NLON\n DO 105 I = 1,NL2\n IS = NLAT - I + 1\n T1 = G(I,J,K)\n T2 = G(IS,J,K)\n G(I,J,K) = WTS(I)* (T1+T2)\n G(IS,J,K) = WTS(I)* (T1-T2)\n 105 CONTINUE\nc adjust equator if necessary(nlat odd)\n IF (MOD(NLAT,2).NE.0) G(LATE,J,K) = WTS(LATE)*\n + G(LATE,J,K)\n 104 CONTINUE\nc set m = 0 coefficients first\n M = 0\n CALL DLEGIN(MODE,L,NLAT,M,W,PMN,KM)\n DO 106 K = 1,NT\n DO 106 I = 1,LATE\n IS = NLAT - I + 1\n DO 107 NP1 = 1,NLAT,2\nc n even\n A(1,NP1,K) = A(1,NP1,K) + G(I,1,K)*PMN(NP1,I,KM)\n 107 CONTINUE\n DO 108 NP1 = 2,NLAT,2\nc n odd\n A(1,NP1,K) = A(1,NP1,K) + G(IS,1,K)*PMN(NP1,I,KM)\n 108 CONTINUE\n 106 CONTINUE\nc compute coefficients for which b(m,n) is available\n DO 109 MP1 = 2,LM1\n M = MP1 - 1\n MP2 = M + 2\nc compute pmn for all i and n=m,...,l-1\n CALL DLEGIN(MODE,L,NLAT,M,W,PMN,KM)\n DO 110 K = 1,NT\n DO 111 I = 1,LATE\n IS = NLAT - I + 1\nc n-m even\n DO 112 NP1 = MP1,NLAT,2\n A(MP1,NP1,K) = A(MP1,NP1,K) +\n + G(I,2*M,K)*PMN(NP1,I,KM)\n B(MP1,NP1,K) = B(MP1,NP1,K) +\n + G(I,2*M+1,K)*PMN(NP1,I,KM)\n 112 CONTINUE\nc n-m odd\n DO 113 NP1 = MP2,NLAT,2\n A(MP1,NP1,K) = A(MP1,NP1,K) +\n + G(IS,2*M,K)*PMN(NP1,I,KM)\n B(MP1,NP1,K) = B(MP1,NP1,K) +\n + G(IS,2*M+1,K)*PMN(NP1,I,KM)\n 113 CONTINUE\n 111 CONTINUE\n 110 CONTINUE\n 109 CONTINUE\n IF (NLON.EQ.L+L-2) THEN\nc compute a(l,np1) coefficients only\n M = L - 1\n CALL DLEGIN(MODE,L,NLAT,M,W,PMN,KM)\n DO 114 K = 1,NT\n DO 114 I = 1,LATE\n IS = NLAT - I + 1\nc n-m even\n DO 124 NP1 = L,NLAT,2\n A(L,NP1,K) = A(L,NP1,K) +\n + 0.5D0*G(I,NLON,K)*PMN(NP1,I,KM)\n 124 CONTINUE\n LP1 = L + 1\nc n-m odd\n DO 125 NP1 = LP1,NLAT,2\n A(L,NP1,K) = A(L,NP1,K) +\n + 0.5D0*G(IS,NLON,K)*PMN(NP1,I,KM)\n 125 CONTINUE\n 114 CONTINUE\n END IF\n ELSE\nc half sphere\nc overwrite g(i) with wts(i)*(g(i)+g(i)) for i=1,...,nlate/2\n NL2 = NLAT/2\n DO 116 K = 1,NT\n DO 116 J = 1,NLON\n DO 115 I = 1,NL2\n G(I,J,K) = WTS(I)* (G(I,J,K)+G(I,J,K))\n 115 CONTINUE\nc adjust equator separately if a grid point\n IF (NL2.LT.LATE) G(LATE,J,K) = WTS(LATE)*G(LATE,J,K)\n 116 CONTINUE\nc set m = 0 coefficients first\n M = 0\n CALL DLEGIN(MODE,L,NLAT,M,W,PMN,KM)\n MS = 1\n IF (MODE.EQ.1) MS = 2\n DO 117 K = 1,NT\n DO 117 I = 1,LATE\n DO 117 NP1 = MS,NLAT,2\n A(1,NP1,K) = A(1,NP1,K) + G(I,1,K)*PMN(NP1,I,KM)\n 117 CONTINUE\nc compute coefficients for which b(m,n) is available\n DO 118 MP1 = 2,LM1\n M = MP1 - 1\n MS = MP1\n IF (MODE.EQ.1) MS = MP1 + 1\nc compute pmn for all i and n=m,...,nlat-1\n CALL DLEGIN(MODE,L,NLAT,M,W,PMN,KM)\n DO 119 K = 1,NT\n DO 119 I = 1,LATE\n DO 119 NP1 = MS,NLAT,2\n A(MP1,NP1,K) = A(MP1,NP1,K) +\n + G(I,2*M,K)*PMN(NP1,I,KM)\n B(MP1,NP1,K) = B(MP1,NP1,K) +\n + G(I,2*M+1,K)*PMN(NP1,I,KM)\n 119 CONTINUE\n 118 CONTINUE\n IF (NLON.EQ.L+L-2) THEN\nc compute coefficient a(l,np1) only\n M = L - 1\n CALL DLEGIN(MODE,L,NLAT,M,W,PMN,KM)\n NS = L\n IF (MODE.EQ.1) NS = L + 1\n DO 120 K = 1,NT\n DO 120 I = 1,LATE\n DO 120 NP1 = NS,NLAT,2\n A(L,NP1,K) = A(L,NP1,K) +\n + 0.5D0*G(I,NLON,K)*PMN(NP1,I,KM)\n 120 CONTINUE\n END IF\n END IF\n RETURN\n END\n SUBROUTINE DSHAGCI(NLAT,NLON,WSHAGC,LSHAGC,DWORK,LDWORK,IERROR)\n DOUBLE PRECISION WSHAGC\nc this subroutine must be called before calling shagc with\nc fixed nlat,nlon. it precomputes quantites such as the gaussian\nc points and weights, m=0,m=1 legendre polynomials, recursion\nc recursion coefficients.\n DIMENSION WSHAGC(LSHAGC)\nC*PT*WARNING* Already double-precision\n DOUBLE PRECISION DWORK(LDWORK)\n\n IERROR = 1\n IF (NLAT.LT.3) RETURN\n IERROR = 2\n IF (NLON.LT.4) RETURN\nc set triangular truncation limit for spherical harmonic basis\n L = MIN0((NLON+2)/2,NLAT)\nc set equator or nearest point (if excluded) pointer\n LATE = (NLAT+MOD(NLAT,2))/2\n L1 = L\n L2 = LATE\n IERROR = 3\nc check permanent work space length\n IF (LSHAGC.LT.NLAT* (2*L2+3*L1-2)+3*L1* (1-L1)/2+NLON+15) RETURN\n IERROR = 4\n IF (LDWORK.LT.NLAT* (NLAT+4)) RETURN\n IERROR = 0\nc set pointers\n I1 = 1\n I2 = I1 + NLAT\n I3 = I2 + NLAT*LATE\n I4 = I3 + NLAT*LATE\n I5 = I4 + L* (L-1)/2 + (NLAT-L)* (L-1)\n I6 = I5 + L* (L-1)/2 + (NLAT-L)* (L-1)\n I7 = I6 + L* (L-1)/2 + (NLAT-L)* (L-1)\nc set indices in temp work for double precision gaussian wts and pts\n IDTH = 1\n IDWTS = IDTH + NLAT\n IW = IDWTS + NLAT\n CALL DSHAGCI1(NLAT,NLON,L,LATE,WSHAGC(I1),WSHAGC(I2),WSHAGC(I3),\n + WSHAGC(I4),WSHAGC(I5),WSHAGC(I6),WSHAGC(I7),\n + DWORK(IDTH),DWORK(IDWTS),DWORK(IW),IERROR)\n IF (IERROR.NE.0) IERROR = 5\n RETURN\n END\n SUBROUTINE DSHAGCI1(NLAT,NLON,L,LATE,WTS,P0N,P1N,ABEL,BBEL,CBEL,\n + WFFT,DTHETA,DWTS,WORK,IER)\n DOUBLE PRECISION WTS\n DOUBLE PRECISION P0N\n DOUBLE PRECISION P1N\n DOUBLE PRECISION ABEL\n DOUBLE PRECISION BBEL\n DOUBLE PRECISION CBEL\n DOUBLE PRECISION WFFT\n DOUBLE PRECISION FN\n DOUBLE PRECISION FM\n DIMENSION WTS(NLAT),P0N(NLAT,LATE),P1N(NLAT,LATE),ABEL(1),BBEL(1),\n + CBEL(1),WFFT(1)\nC*PT*WARNING* Already double-precision\n DOUBLE PRECISION PB,DTHETA(NLAT),DWTS(NLAT),WORK(*),W\nc compute the nlat gaussian points and weights, the\nc m=0,1 legendre polys for gaussian points and all n,\nc and the legendre recursion coefficients\nc define index function used in storing\nc arrays for recursion coefficients (functions of (m,n))\nc the index function indx(m,n) is defined so that\nc the pairs (m,n) map to [1,2,...,indx(l-1,l-1)] with no\nc \"holes\" as m varies from 2 to n and n varies from 2 to l-1.\nc (m=0,1 are set from p0n,p1n for all n)\nc define for 2.le.n.le.l-1\n INDX(M,N) = (N-1)* (N-2)/2 + M - 1\nc define index function for l.le.n.le.nlat\n IMNDX(M,N) = L* (L-1)/2 + (N-L-1)* (L-1) + M - 1\nc preset quantites for fourier transform\n CALL DHRFFTI(NLON,WFFT)\nc compute double precision gaussian points and weights\nc lw = 4*nlat*(nlat+1)+2\n LW = NLAT* (NLAT+2)\n CALL DGAQD(NLAT,DTHETA,DWTS,W,LW,IER)\n IF (IER.NE.0) RETURN\nc store gaussian weights single precision to save computation\nc in inner loops in analysis\n DO 100 I = 1,NLAT\n WTS(I) = DWTS(I)\n 100 CONTINUE\nc initialize p0n,p1n using double precision dnlfk,dnlft\n DO 101 NP1 = 1,NLAT\n DO 101 I = 1,LATE\n P0N(NP1,I) = 0.0D0\n P1N(NP1,I) = 0.0D0\n 101 CONTINUE\nc compute m=n=0 legendre polynomials for all theta(i)\n NP1 = 1\n N = 0\n M = 0\n CALL DDNLFK(M,N,WORK)\n DO 103 I = 1,LATE\n CALL DDNLFT(M,N,DTHETA(I),WORK,PB)\n P0N(1,I) = PB\n 103 CONTINUE\nc compute p0n,p1n for all theta(i) when n.gt.0\n DO 104 NP1 = 2,NLAT\n N = NP1 - 1\n M = 0\n CALL DDNLFK(M,N,WORK)\n DO 105 I = 1,LATE\n CALL DDNLFT(M,N,DTHETA(I),WORK,PB)\n P0N(NP1,I) = PB\n 105 CONTINUE\nc compute m=1 legendre polynomials for all n and theta(i)\n M = 1\n CALL DDNLFK(M,N,WORK)\n DO 106 I = 1,LATE\n CALL DDNLFT(M,N,DTHETA(I),WORK,PB)\n P1N(NP1,I) = PB\n 106 CONTINUE\n 104 CONTINUE\nc compute and store swarztrauber recursion coefficients\nc for 2.le.m.le.n and 2.le.n.le.nlat in abel,bbel,cbel\n DO 107 N = 2,NLAT\n FN = DBLE(N)\n MLIM = MIN0(N,L)\n DO 107 M = 2,MLIM\n FM = DBLE(M)\n IMN = INDX(M,N)\n IF (N.GE.L) IMN = IMNDX(M,N)\n ABEL(IMN) = DSQRT(((2*FN+1)* (FM+FN-2)* (FM+FN-3))/\n + (((2*FN-3)* (FM+FN-1)* (FM+FN))))\n BBEL(IMN) = DSQRT(((2*FN+1)* (FN-FM-1)* (FN-FM))/\n + (((2*FN-3)* (FM+FN-1)* (FM+FN))))\n CBEL(IMN) = DSQRT(((FN-FM+1)* (FN-FM+2))/\n + (((FN+FM-1)* (FN+FM))))\n 107 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "71fecf37c47f765ebdd1f1d1f01d576e6286d9cc", "size": 26520, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "external/sphere3.1_dp/shagc.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "external/sphere3.1_dp/shagc.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "external/sphere3.1_dp/shagc.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 39.4056463596, "max_line_length": 75, "alphanum_fraction": 0.5300904977, "num_tokens": 8543, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632976542184, "lm_q2_score": 0.731058584489497, "lm_q1q2_score": 0.677956899690605}} {"text": " subroutine compute_ptheta(ctfm,ctfmp,n_Athth,n_beta,n_divbeta,x,Nx\n &,hx,myzero,vee,phys_bdy,res)\n implicit none\n integer i\n integer Nx\n real*8 hx\n real*8 myzero\n real*8 vee\n real*8 ctfm(Nx)\n real*8 ctfmp(Nx)\n real*8 n_Athth(Nx)\n real*8 n_beta(Nx)\n real*8 n_divbeta(Nx)\n real*8 x(Nx)\n integer phys_bdy(2)\n real*8 res(Nx)\n real*8 qb\n if (phys_bdy(1) .eq. 1) then\n do i=1, 1, 1\n qb = myzero * x(i)\n res(i)=qb\n end do\n endif\n do i=2, Nx-1, 1\n qb = 0.5000000000000000D0 / ctfmp(i) * (-0.1D1 * n_Athth(i - 1) + \n #n_Athth(i + 1)) / hx * n_beta(i) + 0.2D1 / ctfm(i) * n_Athth(i) * \n #n_beta(i) - 0.6666666666666667D0 * n_Athth(i) * vee * n_divbeta(i)\n res(i)=qb\n end do\n if (phys_bdy(2) .eq. 1) then\n do i=Nx, Nx, 1\n qb = myzero * x(i)\n res(i)=qb\n end do\n endif\n END\n", "meta": {"hexsha": "4758f23b33495ed78630ad667ec88473f442b5ab", "size": 939, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/FD/compute_ptheta.f", "max_stars_repo_name": "rmanak/bssn_spher", "max_stars_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/FD/compute_ptheta.f", "max_issues_repo_name": "rmanak/bssn_spher", "max_issues_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/FD/compute_ptheta.f", "max_forks_repo_name": "rmanak/bssn_spher", "max_forks_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.3783783784, "max_line_length": 72, "alphanum_fraction": 0.5197018104, "num_tokens": 391, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178994073577, "lm_q2_score": 0.7461390043208003, "lm_q1q2_score": 0.6779552547718629}} {"text": " subroutine ire_eqrpsi(n_a1,n_alpha,n_beta,n_rPHI,n_rPI,nm1_rpsi,np\n &1_rpsi,Nx,ht,res)\n implicit none\n integer i\n integer Nx\n real*8 ht\n real*8 n_a1(Nx)\n real*8 n_alpha(Nx)\n real*8 n_beta(Nx)\n real*8 n_rPHI(Nx)\n real*8 n_rPI(Nx)\n real*8 nm1_rpsi(Nx)\n real*8 np1_rpsi(Nx)\n real*8 res\n real*8 qb\n res = 0.0D0\n do i=1, Nx, 1\n qb = 0.5000000000000000D0 * (-0.1D1 * nm1_rpsi(i) + np1_rpsi(i)) /\n # ht - 0.1D1 * n_alpha(i) / n_a1(i) * n_rPI(i) - 0.1D1 * n_beta(i) \n #* n_rPHI(i)\n res = res + qb**2\n end do\n res = sqrt(res/(1*Nx))\n END\n", "meta": {"hexsha": "c5a824f7f763b9903203179532857142068ec188", "size": 647, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/FD/ire_eqrpsi.f", "max_stars_repo_name": "rmanak/bssn_spher", "max_stars_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/FD/ire_eqrpsi.f", "max_issues_repo_name": "rmanak/bssn_spher", "max_issues_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/FD/ire_eqrpsi.f", "max_forks_repo_name": "rmanak/bssn_spher", "max_forks_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.88, "max_line_length": 72, "alphanum_fraction": 0.5332302937, "num_tokens": 271, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179043564153, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6779552533353774}} {"text": "module module1\n implicit none\ncontains\n real function calc_it(x,y)\n real , intent(in):: x,y\n calc_it = sqrt(x**2 + y**2)\n end function calc_it\nend module module1\n", "meta": {"hexsha": "28a8aafaaea38deb05a3e203472c33eed8016ddf", "size": 171, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "exampleF95/module1.f95", "max_stars_repo_name": "hasanalrasyid/inline-fortran", "max_stars_repo_head_hexsha": "05f72f41d4aa29b97870ceb0415a16fa817c0c16", "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": "exampleF95/module1.f95", "max_issues_repo_name": "hasanalrasyid/inline-fortran", "max_issues_repo_head_hexsha": "05f72f41d4aa29b97870ceb0415a16fa817c0c16", "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": "exampleF95/module1.f95", "max_forks_repo_name": "hasanalrasyid/inline-fortran", "max_forks_repo_head_hexsha": "05f72f41d4aa29b97870ceb0415a16fa817c0c16", "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.0, "max_line_length": 31, "alphanum_fraction": 0.6842105263, "num_tokens": 51, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9086178870347121, "lm_q2_score": 0.7461389930307512, "lm_q1q2_score": 0.6779552352818089}} {"text": "!---------------------------------------------------------------------- \n! Subroutine: handy_step\n!> Purpose: HANDY integration step\n!>
\n!> Author: Benjamin Menetrier\n!>
\n!> Licensing: this code is distributed under Apache License 2.0\n!----------------------------------------------------------------------\nsubroutine handy_step(state_in,par,state_out)\n\nuse handy_mod\nimplicit none\n\n! Passed variables\ntype(statetype),intent(in) :: state_in\ntype(partype),intent(in) :: par\ntype(statetype),intent(inout) :: state_out\n\n! Local variables \nreal :: wth,omega,cc,ce,alphac,alphae\n\n! Diagnostics\nwth = par%rho*state_in%xc + par%kappa*par%rho*state_in%xe\nif (abs(wth)>0.0) then\n omega = state_in%w/wth\nelse\n omega = huge(1.0)\nend if\ncc = min(1.0,omega)*par%s*state_in%xc\nce = min(1.0,omega)*par%kappa*par%s*state_in%xe\nif (abs(par%s*state_in%xc)>0.0) then\n alphac = par%alpham + max(0.0,1.0-cc/(par%s*state_in%xc))*(par%alphamax - par%alpham)\nelse\n alphac = 0.0\nendif\nif (abs(par%s*state_in%xe)>0.0) then\n alphae = par%alpham + max(0.0,1.0-ce/(par%s*state_in%xe))*(par%alphamax - par%alpham)\nelse\n alphae = 0.0\nend if\n\n! Variables\nstate_out%xc = par%betac*state_in%xc - alphac*state_in%xc\nstate_out%xe = par%betae*state_in%xe - alphae*state_in%xe\nif (par%nature_switch) then\n state_out%y = par%gamma*state_in%y*(par%lambda - state_in%y) - par%delta*state_in%xc*state_in%y\nelse\n state_out%y = -par%delta*state_in%xc*state_in%y\nend if\nstate_out%w = par%delta*state_in%xc*state_in%y - cc - ce \n\nend subroutine handy_step\n", "meta": {"hexsha": "54dc111ab726b1e0647d514751a673a25453ee2f", "size": 1534, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/handy_step.f90", "max_stars_repo_name": "benjaminmenetrier/handy", "max_stars_repo_head_hexsha": "eb5a0d6f4a020217a159f9fea78f8dffeacdc41e", "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/handy_step.f90", "max_issues_repo_name": "benjaminmenetrier/handy", "max_issues_repo_head_hexsha": "eb5a0d6f4a020217a159f9fea78f8dffeacdc41e", "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/handy_step.f90", "max_forks_repo_name": "benjaminmenetrier/handy", "max_forks_repo_head_hexsha": "eb5a0d6f4a020217a159f9fea78f8dffeacdc41e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.9433962264, "max_line_length": 98, "alphanum_fraction": 0.649934811, "num_tokens": 527, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.919642528975397, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6779219969346993}} {"text": "module xc_mod\n use ISO_C_BINDING\n implicit none\n\ncontains\n\n !\n ! Calculates XC LDA density and potential from the charge density \"n\".\n !\n subroutine getvxc_scalar(n, relat, c_light, exc, Vxc) bind(C)\n real(c_double), intent(in) :: n ! charge density (scalar)\n real(c_double), intent(in) :: c_light ! speed of light\n logical(c_bool), intent(in) :: relat ! if .true. returns RLDA, otherwise LDA\n real(c_double), intent(out) :: exc ! XC density\n real(c_double), intent(out) :: Vxc ! XC potential\n\n real(c_double), parameter :: y0 = -0.10498_8\n real(c_double), parameter :: b = 3.72744_8\n real(c_double), parameter :: c = 12.9352_8\n real(c_double), parameter :: A = 0.0621814_8\n real(c_double), parameter :: pi = 3.1415926535897932384626433832795_8\n\n ! c = 137.0359895\n\n real(8) :: Q, rs, y, ec, ex, Vc, Vx, beta, mu, R, S\n\n if (n < epsilon(1.0_8)) then\n exc = 0\n Vxc = 0\n return\n end if\n\n Q = sqrt(4 * c - b**2)\n rs = (3 / (4 * pi * n))**(1.0_8 / 3)\n y = sqrt(rs)\n ec = A / 2 * (log(y**2 / get_Y(y, b, c)) + 2 * b / Q * atan(Q / (2 * y + b)) &\n - b * y0 / get_Y(y0, b, c) * (&\n log((y - y0)**2 / get_Y(y, b, c)) &\n + 2 * (b + 2 * y0) / Q * atan(Q / (2 * y + b)) &\n ))\n Vc = ec - A / 6 * (c * (y - y0) - b * y0 * y) / ((y - y0) * get_Y(y, b, c))\n ex = -3 / (4 * pi) * (3 * pi**2 * n)**(1.0_8 / 3)\n Vx = 4 * ex / 3\n\n if (relat) then\n beta = -4 * pi * ex / (3 * c_light)\n mu = sqrt(1 + beta**2)\n R = 1 - 3 * ((beta * mu - log(beta + mu)) / (beta ** 2))**2 / 2\n S = 3 * log(beta + mu) / (2 * beta * mu) - 1.0_8 / 2\n\n ex = ex * R\n Vx = Vx * S\n end if\n exc = ex + ec\n Vxc = Vx + Vc\n end subroutine\n\n function get_Y(y, b, c)\n real(8), intent(in) :: y, b, c\n real(8) :: get_Y\n get_Y = y**2 + b * y + c\n end function\n\nend module xc_mod\n", "meta": {"hexsha": "0e2ae68cac567274bafb8a0e25fa0b7fd767ff3a", "size": 2003, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Test/Unit/xc.f90", "max_stars_repo_name": "pmu2022/lsms", "max_stars_repo_head_hexsha": "3c5f266812cad0b6d570bef9f5abb590d044ef92", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-27T14:45:51.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-27T14:45:51.000Z", "max_issues_repo_path": "Test/Unit/xc.f90", "max_issues_repo_name": "pmu2022/lsms", "max_issues_repo_head_hexsha": "3c5f266812cad0b6d570bef9f5abb590d044ef92", "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": "Test/Unit/xc.f90", "max_forks_repo_name": "pmu2022/lsms", "max_forks_repo_head_hexsha": "3c5f266812cad0b6d570bef9f5abb590d044ef92", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.8153846154, "max_line_length": 85, "alphanum_fraction": 0.477783325, "num_tokens": 748, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475810629193, "lm_q2_score": 0.718594386544335, "lm_q1q2_score": 0.6778842763119909}} {"text": " subroutine vapoprs(sfctmp,sfcprs,q2sat,q2)\n parameter ( T0 = 273.16 )\nc\nc estimate the specific humidity, q2 in kg/kg, (Noah refer as the vapor \nc mixing ratio) from air temperature, sfctmp in K deg., and pressure, \nc sfcprs in Pa, q2sat is the saturation mixing ratio \nc First, Popov's empirical relationship (adjusted to SnowMIP2 data) is used\nc to estimate vapor pressure:\nc e2 = 446.02*EXP(0.0579*sfctmp), in Pa\nc Then, it's converted into mixin ratio:\nc q2 = 0.622*e2/(sfcprs-(1-0.622)*e2), in kg/kg\nc\nc calculate saturation mixing ratio\ncfews es=esat(sfctmp)\ncfews q2sat=0.622*es/(SFCPRS-(1.-0.622)*es)\n \nc then estimate actual mixing ratio\n e2 = 446.02*EXP(0.0579*(sfctmp-T0))\n q2 = 0.622*e2/(SFCPRS-(1.-0.622)*e2)\n if(q2 .lt. 0.1E-5) q2=0.1E-5\n if(q2 .ge. q2sat) q2=q2sat*0.99\n\n return\n end\n \n", "meta": {"hexsha": "701469a4b02e7c26f3e0448fcbe80444ac674b51", "size": 895, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "lis/surfacemodels/land/rdhm.3.5.6/sachtet/vapoprs.f", "max_stars_repo_name": "KathyNie/LISF", "max_stars_repo_head_hexsha": "5c3e8b94494fac5ff76a1a441a237e32af420d06", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 67, "max_stars_repo_stars_event_min_datetime": "2018-11-13T21:40:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-23T08:11:56.000Z", "max_issues_repo_path": "lis/surfacemodels/land/rdhm.3.5.6/sachtet/vapoprs.f", "max_issues_repo_name": "dmocko/LISF", "max_issues_repo_head_hexsha": "08d024d6d5fe66db311e43e78740842d653749f4", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 679, "max_issues_repo_issues_event_min_datetime": "2018-11-13T20:10:29.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T19:55:25.000Z", "max_forks_repo_path": "lis/surfacemodels/land/rdhm.3.5.6/sachtet/vapoprs.f", "max_forks_repo_name": "dmocko/LISF", "max_forks_repo_head_hexsha": "08d024d6d5fe66db311e43e78740842d653749f4", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 119, "max_forks_repo_forks_event_min_datetime": "2018-11-08T15:53:35.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-28T10:16:01.000Z", "avg_line_length": 34.4230769231, "max_line_length": 76, "alphanum_fraction": 0.6379888268, "num_tokens": 333, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475746920261, "lm_q2_score": 0.718594386544335, "lm_q1q2_score": 0.6778842717339028}} {"text": " subroutine phase2(r,p1,p2,p3,p4,wt,*)\n implicit none\n include 'constants.f'\n include 'mxdim.f'\n include 'x1x2.f'\nc---- generate phase space for 2-->2 process\nc---- r(mxdim),p1(4),p2(4) are inputs reversed in sign \nc---- from physical values \nc---- phase space for -p1-p2 --> p3+p4\nc---- with all 2 pi's (ie 1/(2*pi)^2)\n double precision r(mxdim)\n double precision p1(4),p2(4),p3(4),p4(4)\n double precision cosphi,sinphi,u,phi,rtshat,costh,sinth\n double precision wt,wt0\n include 'energy.f'\n parameter(wt0=1d0/8d0/pi)\n rtshat=dsqrt(xx(1)*xx(2))*sqrts\nC write out vectors in +,-,T,T notation\n u=r(3)\n costh=2d0*u-1d0\n sinth=dsqrt(1d0-costh**2)\n phi=two*pi*r(4)\n sinphi=dsin(phi)\n cosphi=dcos(phi)\n\n p3(4)=+half*sqrts*(u*xx(1)+(1d0-u)*xx(2))\n p3(1)=+half*sinth*sinphi*rtshat\n p3(2)=+half*sinth*cosphi*rtshat\n p3(3)=+half*sqrts*(u*xx(1)-(1d0-u)*xx(2))\n\n\n p4(4)=+half*sqrts*((1d0-u)*xx(1)+u*xx(2))\n p4(1)=-half*sinth*sinphi*rtshat\n p4(2)=-half*sinth*cosphi*rtshat\n p4(3)=+half*sqrts*((1d0-u)*xx(1)-u*xx(2))\n\nc---debug\n write(6,*) 'p3',p3(4),p3(3),p3(2),p3(1)\n write(6,*) 'p4',p4(4),p4(3),p4(2),p4(1)\n\n p3(4)=+u*p1(4)+(one-u)*p2(4)\n p3(1)=+half*sinth*sinphi*rtshat\n p3(2)=+half*sinth*cosphi*rtshat\n p3(4)=+u*p1(3)+(one-u)*p2(3)\n\n\n p4(4)=+(one-u)*p1(4)+u*p2(4)\n p4(1)=-half*sinth*sinphi*rtshat\n p4(2)=-half*sinth*cosphi*rtshat\n p4(3)=+(one-u)*p1(3)+u*p2(3)\n\n write(6,*) 'p3',p3(4),p3(3),p3(2),p3(1)\n write(6,*) 'p4',p4(4),p4(3),p4(2),p4(1)\nc pause\n wt=wt0\n\n end\n\n", "meta": {"hexsha": "b7c701fc08423c6a3cecdf8b8abea2eeb001b330", "size": 1662, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "MCFM-JHUGen/src/Phase/phase2.f", "max_stars_repo_name": "tmartini/JHUGen", "max_stars_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-06-08T13:09:28.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-04T19:59:36.000Z", "max_issues_repo_path": "MCFM-JHUGen/src/Phase/phase2.f", "max_issues_repo_name": "tmartini/JHUGen", "max_issues_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 64, "max_issues_repo_issues_event_min_datetime": "2015-06-24T15:08:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-25T04:59:32.000Z", "max_forks_repo_path": "MCFM-JHUGen/src/Phase/phase2.f", "max_forks_repo_name": "tmartini/JHUGen", "max_forks_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2015-05-04T22:15:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-06T10:04:40.000Z", "avg_line_length": 28.1694915254, "max_line_length": 61, "alphanum_fraction": 0.5517448857, "num_tokens": 755, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475762847495, "lm_q2_score": 0.7185943805178139, "lm_q1q2_score": 0.6778842671933207}} {"text": "! { dg-do run }\n! PR 27662. Don't zero the first stride to indicate a temporary. It\n! may be used later.\nprogram pr27662\n implicit none\n real(kind=kind(1.0d0)), dimension (2, 2):: x, y, z;\n integer i, j\n x(1,1) = 1.d0 \n x(2,1) = 0.d0\n x(1,2) = 0.d0\n x(2,2) = 1.d0 \n z = matmul (x, transpose (test ()))\n do i = 1, size (x, 1)\n do j = 1, size (x, 2)\n if (x (i, j) .ne. z (i, j)) call abort ()\n end do\n end do\n\ncontains\n function test () result (res)\n real(kind=kind(1.0d0)), dimension(2,2) :: res\n res(1,1) = 1.d0 \n res(2,1) = 0.d0\n res(1,2) = 0.d0\n res(2,2) = 1.d0 \n end function\nend\n", "meta": {"hexsha": "7bdf08d298469ca3de63e3e589427eb36068e98a", "size": 601, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/temporary_1.f90", "max_stars_repo_name": "maurizioabba/rose", "max_stars_repo_head_hexsha": "7597292cf14da292bdb9a4ef573001b6c5b9b6c0", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/temporary_1.f90", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/temporary_1.f90", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 21.4642857143, "max_line_length": 67, "alphanum_fraction": 0.5590682196, "num_tokens": 270, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891130942474, "lm_q2_score": 0.8244619306896956, "lm_q1q2_score": 0.6778636235737316}} {"text": "! =============================================================================\n! Mergesort\n! Sort an array of values in ascending order and return also the\n! re-ordering of the indices (in order to sort other arrays accordingly).\n!\n! Implemented according to Ottmann, T. and Widmayer, P., Algorithmen\n! und Datenstrukturen, 4. Auflage, 2002, Spektrum Akademischer Verlag\n! =============================================================================\nmodule merge_sort\n implicit none\n\n private :: mergesort, merging, imergesort, imerging\n\n ! 23 August 2021\n ! https://fortran-lang.discourse.group/t/question-about-interfaces-and-submodules/584\n interface msort\n module procedure :: dmsort\n module procedure :: imsort\n end interface\n\n contains\n\n ! a : value array to sort\n ! ai : index array\n subroutine dmsort(a, ai)\n double precision, intent(inout) :: a(:)\n integer, intent(out) :: ai(:)\n integer :: n, m\n\n m = size(a)\n\n do n = 1, m\n ai(n) = n\n enddo\n\n call mergesort(a, ai, 1, m)\n\n end subroutine dmsort\n\n recursive subroutine mergesort(a, ai, l, r)\n double precision, intent(inout) :: a(:)\n integer, intent(inout) :: ai(:)\n integer, intent(in) :: l, r\n integer :: m\n\n if (l < r) then\n m = (l + r) / 2\n\n call mergesort(a, ai, l, m)\n call mergesort(a, ai, m + 1, r)\n\n call merging(a, ai, l, m, r)\n endif\n end subroutine mergesort\n\n subroutine merging(a, ai, l, m, r)\n double precision, intent(inout) :: a(:)\n integer, intent(inout) :: ai(:)\n integer, intent(in) :: l, m, r\n double precision :: b(r)\n integer :: bi(r)\n integer :: i, j, k, h\n\n i = l\n j = m + 1\n k = l\n\n do while ((i <= m) .and. (j <= r))\n if (a(i) <= a(j)) then\n b(k) = a(i)\n bi(k) = ai(i)\n i = i + 1\n else\n b(k) = a(j)\n bi(k) = ai(j)\n j = j + 1\n endif\n k = k + 1\n enddo\n\n if (i > m) then\n do h = j, r\n b(k + h - j) = a(h)\n bi(k + h - j) = ai(h)\n enddo\n else\n do h = i, m\n b(k + h - i) = a(h)\n bi(k + h - i) = ai(h)\n enddo\n endif\n\n do h = l, r\n a(h) = b(h)\n ai(h) = bi(h)\n enddo\n end subroutine merging\n\n\n\n ! a : value array to sort\n ! ai : index array\n subroutine imsort(a, ai)\n integer, intent(inout) :: a(:)\n integer, intent(out) :: ai(:)\n integer :: n, m\n\n m = size(a)\n\n do n = 1, m\n ai(n) = n\n enddo\n\n call imergesort(a, ai, 1, m)\n\n end subroutine imsort\n\n recursive subroutine imergesort(a, ai, l, r)\n integer, intent(inout) :: a(:)\n integer, intent(inout) :: ai(:)\n integer, intent(in) :: l, r\n integer :: m\n\n if (l < r) then\n m = (l + r) / 2\n\n call imergesort(a, ai, l, m)\n call imergesort(a, ai, m + 1, r)\n\n call imerging(a, ai, l, m, r)\n endif\n end subroutine imergesort\n\n subroutine imerging(a, ai, l, m, r)\n integer, intent(inout) :: a(:)\n integer, intent(inout) :: ai(:)\n integer, intent(in) :: l, m, r\n integer :: b(r)\n integer :: bi(r)\n integer :: i, j, k, h\n\n i = l\n j = m + 1\n k = l\n\n do while ((i <= m) .and. (j <= r))\n if (a(i) <= a(j)) then\n b(k) = a(i)\n bi(k) = ai(i)\n i = i + 1\n else\n b(k) = a(j)\n bi(k) = ai(j)\n j = j + 1\n endif\n k = k + 1\n enddo\n\n if (i > m) then\n do h = j, r\n b(k + h - j) = a(h)\n bi(k + h - j) = ai(h)\n enddo\n else\n do h = i, m\n b(k + h - i) = a(h)\n bi(k + h - i) = ai(h)\n enddo\n endif\n\n do h = l, r\n a(h) = b(h)\n ai(h) = bi(h)\n enddo\n end subroutine imerging\n\nend module merge_sort\n", "meta": {"hexsha": "d82a987777cff14019fb846a7e7e669d8ddada5d", "size": 5117, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/utils/merge_sort.f90", "max_stars_repo_name": "matt-frey/epic", "max_stars_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2021-11-11T10:50:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T00:11:41.000Z", "max_issues_repo_path": "src/utils/merge_sort.f90", "max_issues_repo_name": "matt-frey/epic", "max_issues_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 47, "max_issues_repo_issues_event_min_datetime": "2021-11-12T17:09:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-24T16:50:58.000Z", "max_forks_repo_path": "src/utils/merge_sort.f90", "max_forks_repo_name": "matt-frey/epic", "max_forks_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.7471910112, "max_line_length": 89, "alphanum_fraction": 0.3462966582, "num_tokens": 1263, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581097540519, "lm_q2_score": 0.8519528019683106, "lm_q1q2_score": 0.6778631560137741}} {"text": "!! This would generally be supplied by the user\n\nSUBROUTINE rpn2qad_flux(meqn,maux,idir,iface,q,auxvec, & \n auxvec_edge,flux)\n\n IMPLICIT NONE\n\n INTEGER meqn,maux,idir, iface\n DOUBLE PRECISION q(meqn), flux(meqn)\n DOUBLE PRECISION auxvec(maux), auxvec_edge(maux)\n\n DOUBLE PRECISION urot, nv(2), u(2)\n INTEGER m\n\n u(1) = auxvec(2)\n u(2) = auxvec(3)\n\n nv(1) = auxvec(4+2*iface)\n nv(2) = auxvec(5+2*iface)\n\n urot = nv(1)*u(1) + nv(2)*u(2)\n\n DO m = 1,meqn\n !! Don't scale the flux here \n flux(m) = urot*q(m)\n ENDDO\n\nEND SUBROUTINE rpn2qad_flux\n\nSUBROUTINE rpn2qad_zero(meqn,maux, idir, iface, q, & \n auxvec, auxvec_edge,flux)\n IMPLICIT NONE\n\n INTEGER meqn,maux,idir, iface\n DOUBLE PRECISION q(meqn), flux(meqn)\n DOUBLE PRECISION auxvec(maux), auxvec_edge(maux)\n INTEGER m\n\n DO m = 1,meqn\n flux(m) = 0\n END DO\n\nEND SUBROUTINE RPN2QAD_ZERO\n\n", "meta": {"hexsha": "e15d10f8acfe0079c686046fd8b68e937b35dcf8", "size": 959, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "applications/paper/annulus/user_4.6/rpn2qad_flux.f90", "max_stars_repo_name": "scivision/forestclaw", "max_stars_repo_head_hexsha": "4dae847a8abd1055e70acda9c2973cd3dd77d3f1", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "applications/paper/annulus/user_4.6/rpn2qad_flux.f90", "max_issues_repo_name": "scivision/forestclaw", "max_issues_repo_head_hexsha": "4dae847a8abd1055e70acda9c2973cd3dd77d3f1", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "applications/paper/annulus/user_4.6/rpn2qad_flux.f90", "max_forks_repo_name": "scivision/forestclaw", "max_forks_repo_head_hexsha": "4dae847a8abd1055e70acda9c2973cd3dd77d3f1", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.3111111111, "max_line_length": 58, "alphanum_fraction": 0.6089676747, "num_tokens": 347, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527869325345, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.6778631296021088}} {"text": " program convolvef\n\n! Reads in a (short) pulse that is convolved with (longer)\n! waveform. Lengths are n_p and n_w. Output (conv)\n! has length n_w + n_p + 1. delta must be same for both.\n!\n! Easiily expanded to read in multiple waveforms.\n!\n! If disc_conv is \"y\", the output is not premultilied by delta\n! and the begin time for the pulse is treated as zero. The\n! result for \"y\" is the sae as one gets from SAC convolve.\n\n implicit none\n\n integer i,j\n! Define the Maximum length of waveform\n integer MAX\n parameter (MAX=10000)\n\n real waveform, pulse, ytmp, conv\n dimension waveform(MAX),pulse(MAX),ytmp(MAX),conv(MAX)\n character*16 kevnm\n\n! Declare Variables used in the rsac1() calls\n real b_w, delta, b_p, factor, b_p_in\n integer n_w, n_p, nmarg, iargc\n character*80 wf_name, p_name, c_name, kname\n character*1 disc_conv\n integer nerr\n\n nmarg = iargc()\n if (nmarg .eq. 0) then\n write(*,*) 'Usage: convolvef p_name wf_name c_name disc_conv'\n write(*,*) ' where the first three arguments are filenames'\n write(*,*) ' for pulse, waveform, and convolution output.'\n write(*,*) 'If disc_conv is y, it uses a discrete convolution'\n write(*,*) ' and the pulse begin time is set to zero. This'\n write(*,*) ' reproduces the result one gets for SAC convolve.'\n write(*,*) 'If disc_conv is n, pulse begin time is unchanged'\n write(*,*) ' and the output is multiolied by delta, which is'\n write(*,*) ' what one has in a time-series covolution.'\n stop\n end if\n call getarg(1,p_name)\n call getarg(2,wf_name)\n call getarg(3,c_name)\n call getarg(4,disc_conv)\n\n! Read in pulse time series\n call rsac1(p_name, pulse, n_p, b_p, delta, MAX, nerr)\n\n if(nerr .NE. 0) then\n write(*,*)'Error reading in file: ',p_name\n call exit(-1)\n endif\n\n! Test if want to do a discrete convolution\n\n factor = delta\n b_p_in = b_p\n if (disc_conv .eq. 'y') then\n factor = 1.0\n b_p_in = 0.0\n endif\n\n! If wanted to do more than one waveform, do loop starts here\n\n! Read in waveform time series\n\n call rsac1(wf_name, waveform, n_w, b_w, delta, MAX, nerr)\n\n if(nerr .NE. 0) then\n write(*,*)'Error reading in file: ',wf_name\n call exit(-1)\n endif\n\n! Do the convolution\n\n call td_conv(waveform,n_w,pulse,n_p,conv,delta,factor,b_p_in)\n\n call setnhv('npts',n_w+n_p-1,nerr)\n kevnm = 'Convolution'\n call setkhv ('kevnm', kevnm, nerr)\n\n! Write the SAC file\n call wsac0(c_name, ytmp, conv, nerr)\n if(nerr .NE. 0) then\n write(*,*)'Error writing out file: ',c_name,nerr\n call exit(-1)\n endif\n\n! If doing more than one waveform, do loop stops here\n\n call exit(0)\n\n end program convolvef\n\n\n subroutine td_conv(waveform,n_w,pulse,n_p,conv,delta,factor,b_p)\n!\n! waveform of length n_w is the time series against which pulse\n! of length n_p is convolved. Output: conv of length n_w+n_w+1.\n! waveform and pulse are unchanged.\n! If a time-series convolution, b_p is the input value and factor\n! is delta, if a discrete cnovolution, b+p is zero and factor=1.\n! The convoluton is done as an inner product in the time\n! domain.\n! Stops if n_w < n_p.\n!\n! Arthur Snoke 2015\n\n implicit none\n real*4 waveform(*), pulse(*), conv(*)\n real*4 delta,b_p,temp,factor\n integer n_p, n_w, j_1, i, j\n\n if (n_p .ge. n_w) then\n write(*,*) 'Need more points in waveform than pulse'\n write(*,*) 'n_w and n_p:',n_w, n_p\n stop\n end if\n\n j_1 = -nint(b_p/delta)+1\n do i=1,n_w+n_p-1\n temp = 0.0\n do j=1,n_w\n if (i.ge.(j-j_1) .and. n_p.ge.(i-j+j_1)) then\n temp = temp + waveform(j)*pulse(i-j+j_1)\n endif\n end do\n conv(i) = factor*temp\n end do\n return\n end\n", "meta": {"hexsha": "78ba4346aace122effba45054d36bf88282d6277", "size": 4094, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "examples/convolve/convolvef.f", "max_stars_repo_name": "savage13/sac", "max_stars_repo_head_hexsha": "f13063ae2e3331e40096037d191563c4ec1ca18b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-05-30T03:20:14.000Z", "max_stars_repo_stars_event_max_datetime": "2019-05-30T03:20:14.000Z", "max_issues_repo_path": "examples/convolve/convolvef.f", "max_issues_repo_name": "savage13/sac", "max_issues_repo_head_hexsha": "f13063ae2e3331e40096037d191563c4ec1ca18b", "max_issues_repo_licenses": ["MIT"], "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/convolve/convolvef.f", "max_forks_repo_name": "savage13/sac", "max_forks_repo_head_hexsha": "f13063ae2e3331e40096037d191563c4ec1ca18b", "max_forks_repo_licenses": ["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.3259259259, "max_line_length": 72, "alphanum_fraction": 0.595505618, "num_tokens": 1220, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118026095991, "lm_q2_score": 0.8198933425148213, "lm_q1q2_score": 0.6778155031380373}} {"text": "program main\n\n!*****************************************************************************80\n!\n!! MAIN is the main program for WAVE_MPI.\n!\n! Discussion:\n!\n! WAVE_MPI solves the wave equation in parallel using MPI.\n!\n! Discretize the equation for u(x,t):\n! d^2 u/dt^2 - c^2 * d^2 u/dx^2 = 0 for 0 < x < 1, 0 < t\n! with boundary conditions:\n! u(0,t) = u0(t) = sin ( 2 * pi * ( 0 - c * t ) )\n! u(1,t) = u1(t) = sin ( 2 * pi * ( 1 - c * t ) )\n! and initial conditions:\n! u(x,0) = g(x,t=0) = sin ( 2 * pi * ( x - c * t ) )\n! dudt(x,0) = h(x,t=0) = - 2 * pi * c * cos ( 2 * pi * ( x - c * t ) ) \n!\n! by:\n!\n! alpha = c * dt / dx.\n!\n! U(x,t+dt) = 2 U(x,t) - U(x,t-dt) \n! + alpha^2 ( U(x-dx,t) - 2 U(x,t) + U(x+dx,t) ).\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license. \n!\n! Modified:\n!\n! 17 November 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Geoffrey Fox, Mark Johnson, Gregory Lyzenga, Steve Otto, John Salmon, \n! David Walker,\n! Solving problems on concurrent processors, \n! Volume 1: General Techniques and Regular Problems,\n! Prentice Hall, 1988,\n! ISBN: 0-13-8230226,\n! LC: QA76.5.F627.\n!\n! Local parameters:\n!\n! Local, real ( kind = 8 ) DT, the time step.\n!\n! Local, integer ( kind = 4 ) ID, the MPI process ID.\n!\n! Local, integer ( kind = 4 ) N_GLOBAL, the total number of points.\n!\n! Local, integer ( kind = 4 ) N_LOCAL, the number of points visible to \n! this process.\n!\n! Local, integer ( kind = 4 ) NSTEPS, the number of time steps.\n!\n! Local, integer ( kind = 4 ) P, the number of MPI processes.\n!\n use mpi\n\n implicit none\n\n real ( kind = 8 ), parameter :: dt = 0.00125\n integer ( kind = 4 ) error\n integer ( kind = 4 ) i_global_hi\n integer ( kind = 4 ) i_global_lo\n integer ( kind = 4 ) id\n integer ( kind = 4 ), parameter :: n_global = 401\n! integer ( kind = 4 ), parameter :: n_global = 101\n integer ( kind = 4 ) n_local\n integer ( kind = 4 ), parameter :: nsteps = 4000\n! integer ( kind = 4 ), parameter :: nsteps = 2\n integer ( kind = 4 ) p\n real ( kind = 8 ), allocatable :: u1_local(:)\n real ( kind = 8 ) wtime\n!\n! Initialize MPI.\n!\n call MPI_Init ( error )\n\n call MPI_Comm_rank ( MPI_COMM_WORLD, id, error )\n\n call MPI_Comm_size ( MPI_COMM_WORLD, p, error )\n\n if ( id == 0 ) then\n call timestamp ( )\n write ( *, '(a)' ) ''\n write ( *, '(a)' ) 'MPI_WAVE:'\n write ( *, '(a)' ) ' FORTRAN90 version.'\n write ( *, '(a)' ) ' Estimate a solution of the wave equation using MPI.'\n write ( *, '(a)' ) ''\n write ( *, '(a,i2,a)' ) ' Using ', p, ' processes.'\n write ( *, '(a,i6,a)' ) ' Using a total of ', n_global, ' points.'\n write ( *, '(a,i6,a,g14.6)' ) ' Using ', nsteps, ' time steps of size ', dt\n write ( *, '(a,g14.6)' ) ' Computing final solution at time ', dt * nsteps\n end if\n\n wtime = MPI_Wtime ( )\n!\n! Determine N_LOCAL\n!\n i_global_lo = ( id * ( n_global - 1 ) ) / p\n i_global_hi = ( ( id + 1 ) * ( n_global - 1 ) ) / p\n if ( 0 < id ) then\n i_global_lo = i_global_lo - 1\n end if\n\n n_local = i_global_hi + 1 - i_global_lo\n allocate ( u1_local(1:n_local) )\n!\n! Update N_LOCAL values.\n!\n call update ( id, p, n_global, n_local, nsteps, dt, u1_local )\n!\n! Collect local values into global array.\n!\n call collect ( id, p, n_global, n_local, nsteps, dt, u1_local )\n!\n! Report elapsed wallclock time.\n!\n wtime = MPI_Wtime ( ) - wtime\n\n if ( id == 0 ) then\n write ( *, '(a)' ) ''\n write ( *, '(a,g14.6,a)' ) &\n ' Elapsed wallclock time was ', wtime, ' seconds.'\n end if\n!\n! Terminate MPI.\n!\n call MPI_Finalize ( error )\n!\n! Free memory.\n!\n deallocate ( u1_local )\n!\n! Terminate.\n!\n if ( id == 0 ) then\n write ( *, '(a)' ) ''\n write ( *, '(a)' ) 'WAVE_MPI:'\n write ( *, '(a)' ) ' Normal end of execution.'\n write ( *, '(a)' ) ''\n call timestamp ( )\n end if\n\n stop\nend\nsubroutine update ( id, p, n_global, n_local, nsteps, dt, u1_local ) \n\n!*****************************************************************************80\n!\n!! UPDATE advances the solution a given number of time steps.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license. \n!\n! Modified:\n!\n! 17 November 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) ID, the identifier of this process.\n!\n! Input, integer ( kind = 4 ) P, the number of processes.\n!\n! Input, integer ( kind = 4 ) N_GLOBAL, the total number of points.\n!\n! Input, integer ( kind = 4 ) N_LOCAL, the number of points visible to \n! this process.\n!\n! Input, integer ( kind = 4 ) NSTEPS, the number of time steps.\n!\n! Input, real ( kind = 8 ) DT, the size of the time step.\n!\n! Output, real ( kind = 8 ) U1_LOCAL(N_LOCAL), the portion of the solution\n! at the last time, as evaluated by this process.\n!\n use mpi\n\n implicit none\n\n integer ( kind = 4 ) n_local\n\n real ( kind = 8 ) alpha\n real ( kind = 8 ) c\n real ( kind = 8 ) dt\n real ( kind = 8 ) dudt\n real ( kind = 8 ) dx\n integer ( kind = 4 ) error\n real ( kind = 8 ) exact\n integer ( kind = 4 ) i\n integer ( kind = 4 ) i_global\n integer ( kind = 4 ) i_global_hi\n integer ( kind = 4 ) i_global_lo\n integer ( kind = 4 ) i_local\n integer ( kind = 4 ) i_local_hi\n integer ( kind = 4 ) i_local_lo\n integer ( kind = 4 ) id\n integer ( kind = 4 ) j\n integer ( kind = 4 ), parameter :: ltor = 20\n integer ( kind = 4 ) n_global\n integer ( kind = 4 ) nsteps\n integer ( kind = 4 ) p\n integer ( kind = 4 ), parameter :: rtol = 10\n integer ( kind = 4 ) status(MPI_STATUS_SIZE)\n real ( kind = 8 ) t\n real ( kind = 8 ) u0_local(n_local)\n real ( kind = 8 ) u1_local(n_local)\n real ( kind = 8 ) u2_local(n_local)\n real ( kind = 8 ) x\n!\n! Determine the value of ALPHA.\n!\n c = 1.0D+00\n dx = 1.0D+00 / real ( n_global - 1, kind = 8 )\n alpha = c * dt / dx\n\n if ( 1.0D+00 <= abs ( alpha ) ) then\n\n if ( id == 0 ) then\n write ( *, '(a)' ) ''\n write ( *, '(a)' ) 'UPDATE - Warning!'\n write ( *, '(a)' ) ' 1 <= |ALPHA| = | C * dT / dX |.'\n write ( *, '(a,g14.6)' ) ' C = ', c\n write ( *, '(a,g14.6)' ) ' dT = ', dt\n write ( *, '(a,g14.6)' ) ' dX = ', dx\n write ( *, '(a,g14.6)' ) ' ALPHA = ', alpha\n write ( *, '(a)' ) ' Computation will not be stable!'\n end if\n\n call MPI_Finalize ( error )\n stop 1\n\n end if\n!\n! The global array of N_GLOBAL points must be divided up among the processes.\n! Each process stores about 1/P of the total + 2 extra slots.\n!\n i_global_lo = ( id * ( n_global - 1 ) ) / p\n i_global_hi = ( ( id + 1 ) * ( n_global - 1 ) ) / p\n if ( 0 < id ) then\n i_global_lo = i_global_lo - 1\n end if\n\n i_local_lo = 0\n i_local_hi = i_global_hi - i_global_lo\n\n t = 0.0D+00\n do i_global = i_global_lo, i_global_hi\n x = real ( i_global, kind = 8 ) / real ( n_global - 1, kind = 8 )\n i_local = i_global - i_global_lo\n u1_local(i_local+1) = exact ( x, t )\n end do\n\n do i_local = i_local_lo, i_local_hi\n u0_local(i_local+1) = u1_local(i_local+1)\n end do\n!\n! Take NSTEPS time steps.\n!\n do i = 1, nsteps\n\n t = dt * real ( i, kind = 8 )\n! \n! For the first time step, we need to use the initial derivative information.\n!\n if ( i == 1 ) then\n\n do i_local = i_local_lo + 1, i_local_hi - 1\n i_global = i_global_lo + i_local\n x = real ( i_global, kind = 8 ) / real ( n_global - 1, kind = 8 )\n u2_local(i_local+1) = &\n + 0.5D+00 * alpha * alpha * u1_local(i_local-1+1) &\n + ( 1.0D+00 - alpha * alpha ) * u1_local(i_local+0+1) &\n + 0.5D+00 * alpha * alpha * u1_local(i_local+1+1) &\n + dt * dudt ( x, t )\n end do\n!\n! After the first time step, we can use the previous two solution estimates.\n!\n else\n\n do i_local = i_local_lo + 1, i_local_hi - 1\n u2_local(i_local+1) = &\n + alpha * alpha * u1_local(i_local-1+1) &\n + 2.0 * ( 1.0 - alpha * alpha ) * u1_local(i_local+0+1) &\n + alpha * alpha * u1_local(i_local+1+1) &\n - u0_local(i_local+0+1)\n end do\n\n end if\n!\n! Exchange data with \"left-hand\" neighbor. \n!\n if ( 0 < id ) then\n call MPI_Send ( u2_local(i_local_lo+2), 1, MPI_DOUBLE_PRECISION, &\n id - 1, rtol, MPI_COMM_WORLD, error )\n call MPI_Recv ( u2_local(i_local_lo+1), 1, MPI_DOUBLE_PRECISION, &\n id - 1, ltor, MPI_COMM_WORLD, status, error )\n else\n x = 0.0D+00\n u2_local(i_local_lo+1) = exact ( x, t )\n end if\n!\n! Exchange data with \"right-hand\" neighbor.\n!\n if ( id < p - 1 ) then\n call MPI_Send ( u2_local(i_local_hi), 1, MPI_DOUBLE_PRECISION, id + 1, &\n ltor, MPI_COMM_WORLD, error )\n call MPI_Recv ( u2_local(i_local_hi+1), 1, MPI_DOUBLE_PRECISION, &\n id + 1, rtol, MPI_COMM_WORLD, status, error )\n else\n x = 1.0D+00\n u2_local(i_local_hi+1) = exact ( x, t )\n end if\n!\n! Shift data for next time step.\n!\n do i_local = i_local_lo, i_local_hi\n u0_local(i_local+1) = u1_local(i_local+1)\n u1_local(i_local+1) = u2_local(i_local+1)\n end do\n\n end do\n\n return\nend\nsubroutine collect ( id, p, n_global, n_local, nsteps, dt, u_local ) \n\n!*****************************************************************************80\n!\n!! COLLECT has workers send results to the master, which prints them.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license. \n!\n! Modified:\n!\n! 17 November 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) ID, the identifier of this process.\n!\n! Input, integer ( kind = 4 ) P, the number of processes.\n!\n! Input, integer ( kind = 4 ) N_GLOBAL, the total number of points.\n!\n! Input, integer ( kind = 4 ) N_LOCAL, the number of points visible\n! to this process.\n!\n! Input, integer ( kind = 4 ) NSTEPS, the number of time steps.\n!\n! Input, real ( kind = 8 ) DT, the size of the time step.\n!\n! Input, real ( kind = 8 ) U_LOCAL(N_LOCAL), the final solution estimate \n! computed by this process.\n!\n use mpi\n\n implicit none\n\n integer ( kind = 4 ) n_global\n integer ( kind = 4 ) n_local\n\n integer ( kind = 4 ) buffer(2)\n integer ( kind = 4 ), parameter :: collect1 = 10\n integer ( kind = 4 ), parameter :: collect2 = 20\n real ( kind = 8 ) dt\n integer ( kind = 4 ) error\n real ( kind = 8 ) exact\n integer ( kind = 4 ) i\n integer ( kind = 4 ) i_global\n integer ( kind = 4 ) i_global_hi\n integer ( kind = 4 ) i_global_lo\n integer ( kind = 4 ) i_local\n integer ( kind = 4 ) i_local_hi\n integer ( kind = 4 ) i_local_lo\n integer ( kind = 4 ) id\n integer ( kind = 4 ) j\n integer ( kind = 4 ) n_local2\n integer ( kind = 4 ) nsteps\n integer ( kind = 4 ) p\n integer ( kind = 4 ) status(MPI_STATUS_SIZE)\n real ( kind = 8 ) t\n real ( kind = 8 ), allocatable :: u_global(:)\n real ( kind = 8 ) u_local(n_local)\n real ( kind = 8 ) x\n\n i_global_lo = ( id * ( n_global - 1 ) ) / p\n i_global_hi = ( ( id + 1 ) * ( n_global - 1 ) ) / p\n if ( 0 < id ) then\n i_global_lo = i_global_lo - 1\n end if\n\n i_local_lo = 0\n i_local_hi = i_global_hi - i_global_lo\n!\n! Master collects worker results into the U_GLOBAL array.\n!\n if ( id == 0 ) then\n!\n! Create the global array.\n!\n allocate ( u_global(1:n_global) )\n!\n! Copy the master's results into the global array.\n!\n do i_local = i_local_lo, i_local_hi\n i_global = i_global_lo + i_local - i_local_lo\n u_global(i_global+1) = u_local(i_local+1)\n end do\n!\n! Contact each worker.\n!\n do i = 1, p - 1\n!\n! Message \"collect1\" contains the global index and number of values.\n!\n call MPI_Recv ( buffer, 2, MPI_INTEGER, i, collect1, MPI_COMM_WORLD, &\n status, error )\n\n i_global_lo = buffer(1)\n n_local2 = buffer(2)\n\n if ( i_global_lo < 0 ) then\n write ( *, '(a,i6)' ) ' Illegal I_GLOBAL_LO = ', i_global_lo\n call MPI_Finalize ( error )\n stop 1\n else if ( n_global <= i_global_lo + n_local2 - 1 ) then\n write ( *, '(a,i6)' ) ' Illegal I_GLOBAL_LO + N_LOCAL = ', &\n i_global_lo + n_local2\n call MPI_Finalize ( error )\n stop 1\n end if\n!\n! Message \"collect2\" contains the values.\n!\n call MPI_Recv ( u_global(i_global_lo+1), n_local2, MPI_DOUBLE_PRECISION, &\n i, collect2, MPI_COMM_WORLD, status, error )\n\n end do\n!\n! Print the results.\n!\n t = dt * real ( nsteps, kind = 8 )\n write ( *, '(a)' ) ''\n write ( *, '(a)' ) ' I X F(X) Exact'\n write ( *, '(a)' ) ''\n do i_global = 0, n_global - 1\n x = real ( i_global, kind = 8 ) / real ( n_global - 1, kind = 8 )\n write ( *, '(2x,i3,2x,f6.3,2x,f6.3,2x,f6.3)' ) &\n i_global, x, u_global(i_global+1), exact ( x, t )\n end do\n\n deallocate ( u_global )\n!\n! Workers send results to process 0.\n!\n else\n!\n! Message \"collect1\" contains the global index and number of values.\n!\n buffer(1) = i_global_lo\n buffer(2) = n_local\n call MPI_Send ( buffer, 2, MPI_INTEGER, 0, collect1, MPI_COMM_WORLD, error )\n!\n! Message \"collect2\" contains the values.\n!\n call MPI_Send ( u_local, n_local, MPI_DOUBLE_PRECISION, 0, collect2, &\n MPI_COMM_WORLD, error )\n\n end if\n\n return\nend\nfunction exact ( x, t )\n\n!*****************************************************************************80\n!\n!! EXACT evaluates the exact solution\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license. \n!\n! Modified:\n!\n! 17 November 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the location.\n!\n! Input, real ( kind = 8 ) T, the time.\n!\n! Output, real ( kind = 8 ) EXACT, the value of the exact solution.\n!\n implicit none\n\n real ( kind = 8 ), parameter :: c = 1.0D+00\n real ( kind = 8 ) exact\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) t\n real ( kind = 8 ) x\n\n exact = sin ( 2.0D+00 * pi * ( x - c * t ) )\n\n return\nend\nfunction dudt ( x, t )\n\n!*****************************************************************************80\n!\n!! DUDT evaluates the partial derivative dudt.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license. \n!\n! Modified:\n!\n! 17 November 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the location.\n!\n! Input, real ( kind = 8 ) T, the time.\n!\n! Output, real ( kind = 8 ) DUDT, the value of the time derivative of \n! the solution.\n!\n implicit none\n\n real ( kind = 8 ), parameter :: c = 1.0D+00\n real ( kind = 8 ) dudt\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) t\n real ( kind = 8 ) x\n\n dudt = - 2.0D+00 * pi * c * cos ( 2.0D+00 * pi * ( x - c * t ) )\n\n return\nend\nsubroutine timestamp ( )\n\n!*****************************************************************************80\n!\n!! TIMESTAMP prints the current YMDHMS date as a time stamp.\n!\n! Example:\n!\n! 31 May 2001 9:45:54.872 AM\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 18 May 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! None\n!\n implicit none\n\n character ( len = 8 ) ampm\n integer ( kind = 4 ) d\n integer ( kind = 4 ) h\n integer ( kind = 4 ) m\n integer ( kind = 4 ) mm\n character ( len = 9 ), parameter, dimension(12) :: month = (/ &\n 'January ', 'February ', 'March ', 'April ', &\n 'May ', 'June ', 'July ', 'August ', &\n 'September', 'October ', 'November ', 'December ' /)\n integer ( kind = 4 ) n\n integer ( kind = 4 ) s\n integer ( kind = 4 ) values(8)\n integer ( kind = 4 ) y\n\n call date_and_time ( values = values )\n\n y = values(1)\n m = values(2)\n d = values(3)\n h = values(5)\n n = values(6)\n s = values(7)\n mm = values(8)\n\n if ( h < 12 ) then\n ampm = 'AM'\n else if ( h == 12 ) then\n if ( n == 0 .and. s == 0 ) then\n ampm = 'Noon'\n else\n ampm = 'PM'\n end if\n else\n h = h - 12\n if ( h < 12 ) then\n ampm = 'PM'\n else if ( h == 12 ) then\n if ( n == 0 .and. s == 0 ) then\n ampm = 'Midnight'\n else\n ampm = 'AM'\n end if\n end if\n end if\n\n write ( *, '(i2.2,1x,a,1x,i4,2x,i2,a1,i2.2,a1,i2.2,a1,i3.3,1x,a)' ) &\n d, trim ( month(m) ), y, h, ':', n, ':', s, '.', mm, trim ( ampm )\n\n return\nend\n", "meta": {"hexsha": "35ae9fbbbf38e6312e584a26d41ccb94b6d1e54f", "size": 16503, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "files/mpi/wave_mpi.f90", "max_stars_repo_name": "WVUHPC/Modern-Fortran", "max_stars_repo_head_hexsha": "97c4db834d4e6ca43802318e4dc63ce4faa641aa", "max_stars_repo_licenses": ["CC-BY-4.0"], "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": "files/mpi/wave_mpi.f90", "max_issues_repo_name": "WVUHPC/Modern-Fortran", "max_issues_repo_head_hexsha": "97c4db834d4e6ca43802318e4dc63ce4faa641aa", "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": "files/mpi/wave_mpi.f90", "max_forks_repo_name": "WVUHPC/Modern-Fortran", "max_forks_repo_head_hexsha": "97c4db834d4e6ca43802318e4dc63ce4faa641aa", "max_forks_repo_licenses": ["CC-BY-4.0"], "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": 25.4283513097, "max_line_length": 80, "alphanum_fraction": 0.548263952, "num_tokens": 5524, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933183101078, "lm_q2_score": 0.8267117855317474, "lm_q1q2_score": 0.6778154691256986}} {"text": " x_cp = x\n size_x = SIZE(x_cp)\n CALL c_sort(x_cp,size_x)\n IF (MOD(size_x,2) == 0) THEN\n res = (x_cp(size_x / 2) + x_cp(size_x / 2 + 1)) / REAL(2,prec)\n ELSE\n res = x_cp(size_x / 2 + 1)\n END IF\n", "meta": {"hexsha": "de622bb3babe41550dd93a83bebac7e28d8605ff", "size": 207, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/Statistics_M/include_median.f90", "max_stars_repo_name": "ecasglez/FortranUtilities", "max_stars_repo_head_hexsha": "a4c88fc190102524f0c669ac20489c5b85a754c1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/Statistics_M/include_median.f90", "max_issues_repo_name": "ecasglez/FortranUtilities", "max_issues_repo_head_hexsha": "a4c88fc190102524f0c669ac20489c5b85a754c1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Statistics_M/include_median.f90", "max_forks_repo_name": "ecasglez/FortranUtilities", "max_forks_repo_head_hexsha": "a4c88fc190102524f0c669ac20489c5b85a754c1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-16T08:04:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-16T08:04:24.000Z", "avg_line_length": 23.0, "max_line_length": 67, "alphanum_fraction": 0.5555555556, "num_tokens": 90, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8438951104066293, "lm_q2_score": 0.8031737892899221, "lm_q1q2_score": 0.6777944335885296}} {"text": "subroutine unsteady_functions(ap_zero, u, v, f_uvel, f_vvel, aw, ae, as, an, p_uf, p_vf, su, sv, fu, fv, rho, dx, dy, imax, jmax, xi, xf)\nuse parameters\nuse kind_parameters\nimplicit none\n\ninteger, intent(in):: imax, jmax, xi, xf\nreal(kind=dp), intent(in), dimension(imax, xi-1:xf+1):: u, v, rho, aw, ae, as, an\nreal(kind=dp), intent(inout), dimension(imax, xi-1:xf+1):: su, sv, ap_zero, fu, fv\nreal(kind=dp), intent(in) :: dx(imax), dy(jmax)\nreal(kind=dp), dimension(imax, xi-1:xf+1):: f_uvel, f_vvel\nreal(kind=dp), dimension(imax-1, xi-1:xf+1):: p_uf\nreal(kind=dp), dimension(imax, xi-1:xf+1):: p_vf\ninteger:: iu, ju, iv, jv\n\ndo ju = xi,xf\n\n do iu = 2,imax-1\n\n f_uvel(iu,ju) = (-(aw(iu,ju)+ae(iu,ju)+as(iu,ju)+an(iu,ju))*u(iu,ju)+aw(iu,ju)*u(iu-1,ju)+ae(iu,ju)*u(iu+1,ju)+as(iu,ju)*u(iu,ju-1)+an(iu,ju)*u(iu,ju+1)+dy(ju)*(p_uf(iu-1,ju)-p_uf(iu,ju)) + fu(iu,ju))/(rho(iu,ju)*dy(ju)*dx(iu))\n\n end do\n\nend do\n\ndo jv = xi,xf\n\n do iv = 2,imax-1\n\n f_vvel(iv,jv) = (-(aw(iv,jv)+ae(iv,jv)+as(iv,jv)+an(iv,jv))*v(iv,jv)+aw(iv,jv)*v(iv-1,jv)+ae(iv,jv)*v(iv+1,jv)+an(iv,jv)*v(iv,jv+1)+as(iv,jv)*v(iv,jv-1)+dx(iv)*(p_vf(iv,jv-1)-p_vf(iv,jv)) + fv(iv,jv))/(rho(iv,jv)*dx(iv)*dy(jv))\n\n end do\n\nend do\n\ncall exchange_data(f_uvel, imax, xi, xf)\ncall exchange_data(f_vvel, imax, xi, xf)\n\ndo ju = xi,xf\n\n do iu = 2,imax-1\n\n ap_zero(iu,ju) = rho(iu,ju)*dx(iu)*dy(ju)/(time_step*A22)\n\n end do\n\nend do\n\ncall exchange_data(ap_zero, imax, xi, xf)\n\nend subroutine\n", "meta": {"hexsha": "b1bb75c687e8ccc7addfb89af455358374176950", "size": 1461, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "unsteady_functions.f90", "max_stars_repo_name": "pratanuroy/Multigrid_Cavity", "max_stars_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-09-11T12:01:52.000Z", "max_stars_repo_stars_event_max_datetime": "2017-09-11T12:01:52.000Z", "max_issues_repo_path": "unsteady_functions.f90", "max_issues_repo_name": "pratanuroy/Multigrid_Cavity", "max_issues_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "unsteady_functions.f90", "max_forks_repo_name": "pratanuroy/Multigrid_Cavity", "max_forks_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.6470588235, "max_line_length": 232, "alphanum_fraction": 0.620807666, "num_tokens": 659, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248242542283, "lm_q2_score": 0.7217432003123989, "lm_q1q2_score": 0.6777347818300347}} {"text": "PROGRAM read_n_calc\nIMPLICIT NONE\nREAL, ALLOCATABLE, DIMENSION(:,:) :: data\nCHARACTER(LEN=20) :: filename\nINTEGER :: status\nINTEGER :: rows, cols, i, j\nCHARACTER(LEN=10) :: row_str, col_str\nCHARACTER(LEN=40) :: row_sum_fmt, col_sum_fmt\n\nWRITE(*, *) \"Enter the filename to read and process:\"\nREAD(*, *) filename\n\nOPEN(1, FILE=filename, STATUS='OLD', ACTION='READ', IOSTAT=status)\nREAD(1, *) rows, cols\nALLOCATE(data(1:rows, 1:cols))\n\nWRITE(row_str, '(I3)') rows\nWRITE(col_str, '(I3)') cols\nrow_str = TRIM(row_str)\ncol_str = TRIM(col_str)\nrow_sum_fmt = '(' // row_str // '(A, I4, 2X, A, F12.1, A))'\ncol_sum_fmt = '(' // col_str // '(A, I4, 2X, A, F12.1, A))'\nrow_sum_fmt = TRIM(row_sum_fmt)\ncol_sum_fmt = TRIM(col_sum_fmt)\n\nDO i = 1, rows\n READ(1, '(' // col_str // 'F8.1)', IOSTAT=status) (data(i, j), j = 1, cols)\n IF (status .lt. 0) THEN\n EXIT\n END IF\nEND DO\n\nWRITE(*, row_sum_fmt) (\"Row:\", i, \"Sum:\", SUM(data(i, 1:cols)), NEW_LINE('A'), i = 1, rows)\nWRITE(*, col_sum_fmt) (\"Col:\", i, \"Sum:\", SUM(data(1:rows, i)), NEW_LINE('A'), i = 1, cols)\n!WRITE(*, row_sum_fmt) (\"Row:\", i, \"Sum:\", SUM(data(i, 1:cols)), NEW_LINE('A'), i = 1, rows)\n!WRITE(*, col_sum_fmt) (\"Col:\", i, \"Sum:\", SUM(data(1:rows, i)), i = 1, cols)\n\nDEALLOCATE(data)\nEND PROGRAM read_n_calc\n", "meta": {"hexsha": "cc0b9577aa1cd71f2b8a9970c647f25a6714e6bc", "size": 1264, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap8/read_n_calc.f90", "max_stars_repo_name": "evanmacbride/fortran-practice", "max_stars_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/chap8/read_n_calc.f90", "max_issues_repo_name": "evanmacbride/fortran-practice", "max_issues_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/chap8/read_n_calc.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": 31.6, "max_line_length": 92, "alphanum_fraction": 0.628164557, "num_tokens": 471, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744939732856, "lm_q2_score": 0.8289388125473629, "lm_q1q2_score": 0.6777192302032266}} {"text": "C File: arrays-constr-07.f\nC This program has a simple 1-D array with the default lower bound of 1.\nC It shows the use of an array constructor to initialize the array.\n\n program main\n implicit none\n\nC A, B, C are 1-D arrays of integers with implicit lower-bound = 1\nC and upper bound of 12. \n integer, dimension(12) :: A\n integer, dimension(12) :: B = (/12,11,10,9,8,7,6,5,4,3,2,1/)\n integer, dimension(12) :: C = (/1,3,5,7,9,11,13,15,17,19,21,23/)\n integer :: i\n\nC array constructor III -- implied do loop, nested array expressions\nC This example is very similar to arrays-constr-06.f with the\nC difference that the iteration for the inner array expression goes\nC from 12 down to 1 (start value = 12, end value = 1, step = -1).\nC The inner expression B(12:1:-1) therefore gives the sequence of\nC values of B's elements in the order B(12), B(11), ..., B(1), i.e.:\nC\nC 1, 2, 3, ..., 10, 11, 12\nC\nC The outer expression uses this sequence of values to index into\nC the array C, giving the sequence of values of C's elements in the\nC order C(1), C(2), C(3), ..., C(10), C(11), C(12). The sequence of\nC values assigned to the elements of A is therefore:\nC\nC 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23\n\n A = (/ (C(B(12:1:-1))) /)\n\n do i = 1, 12\n write (*,10) A(i)\n end do\n\n 10 format(I5)\n\n stop\n end program main\n", "meta": {"hexsha": "d9789e317e2a9fbfe3fbd89ed8980c2ba575f768", "size": 1439, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/data/program_analysis/arrays/arrays-constr-07.f", "max_stars_repo_name": "mikiec84/delphi", "max_stars_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2018-03-03T11:57:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-16T21:19:54.000Z", "max_issues_repo_path": "tests/data/program_analysis/arrays/arrays-constr-07.f", "max_issues_repo_name": "mikiec84/delphi", "max_issues_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 385, "max_issues_repo_issues_event_min_datetime": "2018-02-21T16:52:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-17T07:44:56.000Z", "max_forks_repo_path": "tests/data/program_analysis/arrays/arrays-constr-07.f", "max_forks_repo_name": "mikiec84/delphi", "max_forks_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2018-03-20T01:08:11.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-29T01:04:49.000Z", "avg_line_length": 35.0975609756, "max_line_length": 72, "alphanum_fraction": 0.6108408617, "num_tokens": 481, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744939732855, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.677719228475713}} {"text": "! chk_isnan.f90\r\n! Check: can we check if a number is not-a-number via the IEEE features?\r\n!\r\nprogram chk_isnan\r\n use ieee_arithmetic\r\n implicit none\r\n\r\n real :: x\r\n\r\n call random_number( x )\r\n x = sqrt(x-1.0)\r\n\r\n write( *, '(a,a)' ) 'The value of x should be \"not-a-number\" - ', merge( 'YES', 'NO ', ieee_is_nan(x) )\r\n write( *, '(a,a)' ) 'The ieee_is_nan intrinsic function is available'\r\n\r\nend program chk_isnan\r\n", "meta": {"hexsha": "b5983db4e57242c70b92625f311fc5dbe83828b5", "size": 441, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "chkfeatures/chk_isnan.f90", "max_stars_repo_name": "timcera/flibs_from_svn", "max_stars_repo_head_hexsha": "7790369ac1f0ff6e35ef43546446b32446dccc6b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2017-01-16T11:28:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-04T15:58:19.000Z", "max_issues_repo_path": "chkfeatures/chk_isnan.f90", "max_issues_repo_name": "timcera/flibs_from_svn", "max_issues_repo_head_hexsha": "7790369ac1f0ff6e35ef43546446b32446dccc6b", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chkfeatures/chk_isnan.f90", "max_forks_repo_name": "timcera/flibs_from_svn", "max_forks_repo_head_hexsha": "7790369ac1f0ff6e35ef43546446b32446dccc6b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2017-06-08T07:29:08.000Z", "max_forks_repo_forks_event_max_datetime": "2019-02-24T02:07:22.000Z", "avg_line_length": 25.9411764706, "max_line_length": 108, "alphanum_fraction": 0.6099773243, "num_tokens": 126, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8175744850834649, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.6777192245616223}} {"text": "program where_test\n use, intrinsic :: iso_fortran_env, only : sp => REAL32, error_unit\n implicit none\n integer, parameter :: N = 5\n real, parameter :: eps = 1.0e-2_sp\n real(kind=sp), dimension(N, N) :: A\n integer, dimension(N, N) :: Pos, Neg, Zero\n real(kind=sp) :: r\n integer :: i, j\n character(len=40) :: r_fmt_str\n character(len=40) :: i_fmt_str\n\n write (r_fmt_str, \"('(', I2, 'F7.2)')\") N\n write (i_fmt_str, \"('(', I2, 'I7)')\") N\n\n do i = 1, N\n do j = 1, N\n call random_number(r)\n A(i, j) = 2.0_sp*(r - 0.5_sp)\n end do\n end do\n\n where (A > eps)\n Pos = 1\n Neg = 0\n Zero = 0\n elsewhere (A < eps)\n Pos = 0\n Neg = 1\n Zero = 0\n elsewhere\n Pos = 0\n Neg = 0\n Zero = 1\n end where\n\n print '(A)', 'matrix:'\n do i = 1, N\n print r_fmt_str, A(i, :)\n end do\n print '(2A)', '---------', 'positive'\n do i = 1, N\n print i_fmt_str, Pos(i, :)\n end do\n print '(2A)', '---------', 'negative'\n do i = 1, N\n print i_fmt_str, Neg(i, :)\n end do\n print '(2A)', '---------', 'zero'\n do i = 1, N\n print i_fmt_str, Zero(i, :)\n end do\n\n if (sum(Pos + Neg + Zero) /= N*N) then\n write (unit=error_unit, fmt='(A)') '# error: not all covered'\n stop 1\n end if\n\nend program where_test\n", "meta": {"hexsha": "bdd4940fc90406091fdb6dd29ab7c1f07cf32650", "size": 1390, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran/ControlStructures/where_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/ControlStructures/where_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/ControlStructures/where_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": 23.1666666667, "max_line_length": 70, "alphanum_fraction": 0.4748201439, "num_tokens": 479, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388167733099, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.6777192244468561}} {"text": "! Liao 1/5/2010\n! Several variants of Fortran Do loops\n program mymain\n integer i, n, sum\n \n sum = 0\n n = 10\n write (*,*) 'loop 1-----------------'\n do 10 i = 1, n\n sum = sum + i\n write(*,*) 'i =', i\n write(*,*) 'sum =', sum\n 10 continue\n \n! Decremental: -2, integer type\n write (*,*) 'loop 2-----------------'\n do 20 i = 10, 1, -2\n write(*,*) 'i =', i\n 20 continue\n\n! end do\n write (*,*) 'loop 3-----------------'\n do i = 1, n\n sum = sum + i\n write(*,*) 'i =', i\n end do \n end\n", "meta": {"hexsha": "8d4157dbdd95551f819a955b937b04f8c9af5ef4", "size": 595, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/roseTests/astInterfaceTests/inputdoLoopNormalization.f", "max_stars_repo_name": "maurizioabba/rose", "max_stars_repo_head_hexsha": "7597292cf14da292bdb9a4ef573001b6c5b9b6c0", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/roseTests/astInterfaceTests/inputdoLoopNormalization.f", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/roseTests/astInterfaceTests/inputdoLoopNormalization.f", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 21.25, "max_line_length": 43, "alphanum_fraction": 0.3798319328, "num_tokens": 208, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.82893881677331, "lm_q2_score": 0.8175744695262777, "lm_q1q2_score": 0.6777192133931792}} {"text": "module lnumz\n integer, parameter:: b4 = selected_real_kind(4)\nend module\nmodule csolve\n use lnumz\n contains\n subroutine ludcmp(a,n,np,indx,d)\n use lnumz\n implicit none\n integer n,np,indx(n)\n complex(b4) a(np,*),tiny\n complex(b4) :: tmp\n complex(b4) :: sum\n integer d\n parameter (tiny=1.0e-20_b4)\n integer i,imax,j,k\n real(b4),allocatable :: vv(:)\n real(b4) :: aamax,dum\n allocate(vv(n))\n d=1.0_b4\n do i=1,n\n aamax=0.0_b4\n do j=1,n\n if(abs(a(i,j)) .gt. aamax) aamax=abs(a(i,j))\n enddo\n if( aamax .eq. 0.0_b4)then\n write(*,*)\"sigular matrix\"\n stop\n endif\n vv(i)=1.0_b4/aamax\n enddo\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 enddo\n a(i,j)=sum\n enddo\n aamax=0.0_b4\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 enddo\n a(i,j)=sum\n dum=vv(i)*abs(sum)\n if (dum .ge. aamax)then\n imax=i\n aamax=dum\n endif\n enddo\n if ( j .ne. imax)then\n do k=1,n\n tmp=a(imax,k)\n a(imax,k)=a(j,k)\n a(j,k)=tmp\n enddo\n d=-d\n vv(imax)=vv(j)\n endif\n indx(j)=imax\n if(a(j,j) .eq. 0.0_b4)a(j,j)=tiny\n if(j .ne. n)then\n tmp=1.0_b4/a(j,j)\n do i=j+1,n\n a(i,j)=a(i,j)*tmp\n enddo\n endif\n enddo\n deallocate(vv)\n end subroutine\n\n subroutine lubksb(a,n,np,indx,b)\n use lnumz\n implicit none \n integer n,np,indx(n)\n complex(b4) :: a(np,np),b(n)\n integer i,ii,j,ll\n complex(b4) sum\n ii=0\n do i=1,n\n ll=indx(i)\n sum=b(ll)\n b(ll)=b(i)\n if (ii .ne. 0)then\n do j=ii,i-1\n sum=sum-a(i,j)*b(j)\n enddo\n else if (sum .ne. 0.0_b4) then\n ii=i\n endif\n b(i)=sum\n enddo\n do i=n,1,-1\n sum=b(i)\n do j=i+1,n\n sum=sum-a(i,j)*b(j)\n enddo\n b(i)=sum/a(i,i)\n enddo\n end subroutine\nend module\nsubroutine cgesv( n, nrhs, a, lda, ipiv, b, ldb, info )\n use lnumz\n use csolve\n implicit none\n integer n,nrhs,lda,ldb,info,id\n integer j\n complex(b4) :: a(lda,*),b(ldb,*)\n integer ipiv(*)\n call ludcmp(a,n,lda,ipiv,id)\n info=0\n do j=1,nrhs\n call lubksb(a,n,lda,ipiv,b(:,j))\n enddo\nend subroutine\n\n", "meta": {"hexsha": "1be64f9c1e8b45561497a4a94a623509e0fe0383", "size": 2803, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "scalapack/rcs09/cgesv.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": "scalapack/rcs09/cgesv.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": "scalapack/rcs09/cgesv.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": 23.5546218487, "max_line_length": 58, "alphanum_fraction": 0.4195504816, "num_tokens": 894, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813453, "lm_q2_score": 0.7549149978955811, "lm_q1q2_score": 0.6776836436844943}} {"text": " subroutine CGEI(A,LDA,N,IPVT,WORK)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nC>> 1992-05-18 CLL\nC>> 1987-08-14 CGEI Lawson Initial code.\nC\nc This subroutine computes the inverse of the N x N matrix, A,\nC using the LU factorization of A given in the array A().\nc ------------------------------------------------------------------\nc Subroutine arguments\nC\nC A(,) [inout] An array of size at least N x N. On entry must\nc contain the LU factors of an N x N matrix, A. It is\nc expected that this factorization will have been computed by\nc use of _GEFA, either directly or indirectly via use of _GEC\nc _GEFS or _GEFSC.\nc On return contains the N x N inverse matrix of A.\nC\nC LDA [in] Leading dimensioning parameter for the array A(,).\nC\nC N [in] The order of the original matrix, A.\nC\nC IPVT() [in] An integer array of length at least N, containg a\nc record of the row interchanges made during factorization of\nc A.\nC\nc WORK() [scratch] An array of length at least N used by this\nc subroutine as working space.\nc ------------------------------------------------------------------\nC ERROR CONDITION\nC\nC A DIVISION BY ZERO WILL OCCUR IF THE INPUT FACTOR CONTAINS A\nC ZERO ON THE DIAGONAL. TECHNICALLY THIS INDICATES SINGULARITY\nC BUT IT IS OFTEN CAUSED BY IMPROPER ARGUMENTS OR IMPROPER\nC setting of LDA. The user can avoid sending a singular matrix\nc to this subr by testing INFO (set by _GEFS or _GEFA) or\nc RCOND (set by _GEFSC or _GECO) before calling this subr.\nc Nonsingularity is indicated by INFO .eq. 0 or RCOND .ne. ZERO.\nc ------------------------------------------------------------------\nC LINPACK. THIS VERSION DATED 08/14/78 .\nC CLEVE MOLER, UNIVERSITY OF NEW MEXICO, ARGONNE NATIONAL LAB.\nc Ref: LINPACK Users' Guide, by J. J. Dongarra, C. B. Moler,\nc J. R. Bunch, and G. W. Stewart, publ by Soc. for Indust. and Appl.\nc Math, Philadelphia, 1979.\nc Adapted from LINPACK for the JPL Math77 library by\nc C. L. Lawson, JPL, Aug 1987.\nc ------------------------------------------------------------------\nc Subprograms referenced: CAXPY, CSCAL, CSWAP\nC ------------------------------------------------------------------\n integer LDA,N,IPVT(N),I,J,K,KB,KP1,L,NM1\n complex A(LDA,N), WORK(N), T, ONE, ZERO\n parameter(ONE = (1.E0,0.E0), ZERO = (0.E0,0.E0))\nC ------------------------------------------------------------------\nC COMPUTE INVERSE(U)\nC\n DO 100 K = 1, N\nc 5/18/92 CLL The following stmt rewritten to avoid a bug in\nc the current SUN Fortran compiler.\nc IF (A(K,K) .NE. ZERO) THEN\n if(real(A(K,K)) .ne. 0.0e0 .or.\n * aimag(A(K,K)) .ne. 0.0e0) then\n A(K,K) = ONE/A(K,K)\n ELSE\n CALL ERMSG('CGEI',1,0,'A diagonal element is zero','.')\n RETURN\n END IF\n T = -A(K,K)\n CALL CSCAL(K-1,T,A(1,K),1)\n KP1 = K + 1\n DO 80 J = KP1, N\n T = A(K,J)\n A(K,J) = ZERO\n CALL CAXPY(K,T,A(1,K),1,A(1,J),1)\n 80 CONTINUE\n 100 CONTINUE\nC\nC FORM INVERSE(U)*INVERSE(L)\nC\n NM1 = N - 1\n DO 130 KB = 1, NM1\n K = N - KB\n KP1 = K + 1\n DO 110 I = KP1, N\n WORK(I) = A(I,K)\n A(I,K) = ZERO\n 110 CONTINUE\n DO 120 J = KP1, N\n T = WORK(J)\n CALL CAXPY(N,T,A(1,J),1,A(1,K),1)\n 120 CONTINUE\n L = IPVT(K)\n IF (L .NE. K) CALL CSWAP(N,A(1,K),1,A(1,L),1)\n 130 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "3205845d14af5a4059c92cb1dac0af4edaf722b6", "size": 3928, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/cgei.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/cgei.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/cgei.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": 40.4948453608, "max_line_length": 72, "alphanum_fraction": 0.5061099796, "num_tokens": 1137, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953003183444, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6776836408008254}} {"text": "Program Sum_of_trace\nINTEGER N, trace\ninteger, dimension (50,50) :: matrix\nPrint *, \"Enter N\"\nread(*,*) N\nPrint *, \"Enter Matrix\"\ntrace=0\ndo i=1, N\n do j = 1, N\n read(*,*) matrix(i, j)\n if( i == j ) then\n trace = trace + matrix(i, j)\n end if\n end do\nend do\nPrint *, \"Trace= \", trace\nEnd Program Sum_of_trace\n", "meta": {"hexsha": "b27600f7d3ee0755903e04059e6ec0b45e5014b5", "size": 346, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Sum_of_trace.f", "max_stars_repo_name": "Sayan3990/Fortran", "max_stars_repo_head_hexsha": "8e138157be0ffc2e0a7afb9e6a3f901b802434d8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-08-14T02:14:36.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-14T03:45:52.000Z", "max_issues_repo_path": "Sum_of_trace.f", "max_issues_repo_name": "Sayan3990/Fortran", "max_issues_repo_head_hexsha": "8e138157be0ffc2e0a7afb9e6a3f901b802434d8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Sum_of_trace.f", "max_forks_repo_name": "Sayan3990/Fortran", "max_forks_repo_head_hexsha": "8e138157be0ffc2e0a7afb9e6a3f901b802434d8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-08-14T03:45:53.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-14T03:45:53.000Z", "avg_line_length": 19.2222222222, "max_line_length": 40, "alphanum_fraction": 0.5664739884, "num_tokens": 113, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8976952921073469, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6776836346022203}} {"text": " subroutine DCONMC(N, COEFF)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nC>> 1994-11-11 DCONMC Krogh Declared all vars.\nc>> 1994-10-20 DCONMC Krogh Changes to use M77CON\nc>> 1992-06-04 DCONMC Krogh Corrected line below.\nc>> 1992-01-31 DCONMC Krogh Initial Code.\nc--D replaces \"?\": ?CONMC\nc\nc Converts COEFF in monomial basis to the Chebyshev basis.\nc\n integer N, J, I\n double precision COEFF(0:N), TP\nc\n if (N .le. 0) return\n TP = .5D0**(N-1)\n COEFF(N) = TP * COEFF(N)\n COEFF(N-1) = TP * COEFF(N-1)\n do 20 J = N-2, 0, -1\n TP = 2.D0 * TP\n COEFF(J) = TP * COEFF(J)\n COEFF(J+1) = 2.D0 * COEFF(J+1)\n do 10 I = J, N-2\n COEFF(I) = COEFF(I) + COEFF(I+2)\n 10 continue\n 20 continue\n return\n end\n", "meta": {"hexsha": "1f12aa2c1a37316a3321a74926e5e752dd7ba2b7", "size": 894, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/dconmc.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/dconmc.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/dconmc.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": 29.8, "max_line_length": 70, "alphanum_fraction": 0.5973154362, "num_tokens": 330, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952811593496, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.677683626337413}} {"text": "Module MathLib\n\ncontains\n\n SUBROUTINE LEGS (A_,Nn,B_,Xx)\n INTEGER, INTENT (IN) :: Nn\n INTEGER :: iI,iJ\n INTEGER, DIMENSION (Nn) :: INDX\n REAL, INTENT (IN), DIMENSION (Nn,Nn) :: A_\n REAL, INTENT (IN), DIMENSION (Nn) :: B_\n REAL, DIMENSION (Nn,Nn) :: Aa\n REAL, DIMENSION (Nn) :: Bb\n REAL, INTENT (OUT), DIMENSION (Nn) :: Xx\n\n Aa = A_\n Bb = B_\n !\n CALL ELGS (Aa,Nn,INDX)\n !\n DO iI = 1, Nn-1\n DO iJ = iI+1, Nn\n Bb(INDX(iJ)) = Bb(INDX(iJ))-Aa(INDX(iJ),iI)*Bb(INDX(iI))\n END DO\n END DO\n !\n Xx(Nn) = Bb(INDX(Nn))/Aa(INDX(Nn),Nn)\n DO iI = Nn-1, 1, -1\n Xx(iI) = Bb(INDX(iI))\n DO iJ = iI+1, Nn\n Xx(iI) = Xx(iI)-Aa(INDX(iI),iJ)*Xx(iJ)\n END DO\n Xx(iI) = Xx(iI)/Aa(INDX(iI),iI)\n END DO\n !\n END SUBROUTINE LEGS\n !\n SUBROUTINE ELGS (Aa,Nn,INDX)\n INTEGER, INTENT (IN) :: Nn\n INTEGER :: iI, iJ, iK = 0, ITMP\n INTEGER, INTENT (OUT), DIMENSION (Nn) :: INDX\n REAL :: C1, PI, PI1,PJ\n REAL, INTENT (INOUT), DIMENSION (Nn,Nn) :: Aa\n REAL, DIMENSION (Nn) :: C\n !\n ! Initialize the index\n DO iI = 1, Nn\n INDX(iI) = iI\n END DO\n !\n ! Find the rescaling factors, one from each row\n DO iI = 1, Nn\n C1= 0.0\n DO iJ = 1, Nn\n C1 = AMAX1(C1,ABS(Aa(iI,iJ)))\n END DO\n C(iI) = C1\n END DO\n !\n ! Search the pivoting (largest) element from each column\n DO iJ = 1, Nn-1\n PI1 = 0.0\n DO iI = iJ, Nn\n PI = ABS(Aa(INDX(iI),iJ))/C(INDX(iI))\n IF (PI.GT.PI1) THEN\n PI1 = PI\n iK = iI\n ENDIF\n END DO\n !\n ! Interchange the rows via INDX(N) to record pivoting order\n ITMP = INDX(iJ)\n INDX(iJ) = INDX(iK)\n INDX(iK) = ITMP\n\n DO iI = iJ+1, Nn\n PJ = Aa(INDX(iI),iJ)/Aa(INDX(iJ),iJ)\n !\n ! Record pivoting ratios below the diagonal\n !\n Aa(INDX(iI),iJ) = PJ\n !\n ! Modify other elements accordingly\n DO iK = iJ+1, Nn\n Aa(INDX(iI),iK) = Aa(INDX(iI),iK)-PJ*Aa(INDX(iJ),iK)\n END DO\n END DO\n END DO\n !\n END SUBROUTINE ELGS\n !\n character(len=20) function rStr(rk)\n implicit none\n\n ! Convertir un intier en chaine de caract\u00e8res.\n real, intent(in) :: rk\n\n write(rStr, *) rk\n rStr = adjustl(rStr)\n end function rStr\n\n character(len=20) function Str(ik)\n implicit none\n\n ! Convertir un intier en chaine de caract\u00e8res.\n integer, intent(in) :: ik\n\n write(Str, *) ik\n Str = adjustl(str)\n end function Str\n\n Integer function Str2int(str_)\n implicit none\n\n character(len=*), intent(in) :: str_\n integer :: int_\n read(str_, *) int_\n Str2int = int_\n end function Str2int\n\n Real function Str2float(str_)\n implicit none\n\n character(len=*), intent(in) :: str_\n Real :: f_\n\n read(str_, \"(F9.3)\") f_\n Str2float = f_\n end function Str2float\n\n character(len=20) function Formatte(s_, nc_)\n ! Convertir un intier en chaine de caract\u00e8res.\n integer, intent(in) :: nc_\n integer, intent(in) :: s_\n character(len=20) :: sfmt\n\n if (s_ == 0) then\n sfmt = REPEAT(\" \", int(nc_/2)) // Str(s_) // REPEAT(\" \", int(nc_/2))\n else\n sfmt = REPEAT(\" \", int(nc_/2)) // \"-\" // REPEAT(\" \", int(nc_/2))\n endif\n write(Formatte, *) s_\n Formatte = adjustl(Formatte)\n end function Formatte\n\n ! Processus d'importation \u00e0 partir de fichier IEEE CDF\n\nEnd module MathLib\n\nprogram newtonrap\n\nUse MathLib\n\nImplicit none\n\n!> Declarations des variables\nreal,parameter :: pi=3.14159\ninteger :: N, I, J, W, NB, k, JN, Np, Ng, Kmax = 100, Cond, narg, slack = 1, io\ncharacter(len=30) :: NName\n\n!> Variables principales\ncomplex, allocatable, Dimension(:,:) :: Ya, Z, Spq, Ys\ncomplex, allocatable, Dimension(:) :: V, Sg, Sd\nreal, allocatable, dimension(:,:) :: YB, YG, Ja, c !, Vs\nInteger, allocatable, dimension(:) :: Nfrom, Nto, Indx\nreal, allocatable, dimension(:) :: P, Q, Fd, X, DX, ModV, Theta\ncharacter(1), allocatable, dimension(:) :: Typen\nreal :: eps = 0.001 , MaxDx, t1, t2, PL, QL, Sbase\ncharacter(100) :: A2Fmt, AFmt, A3Fmt, fnamein, fnameout, name, hlpfilename = \"NR.hlp\"\ncharacter(len=100) :: hlpstr\nlogical :: lookForIn = .false., fileExist, LookForInOut = .FALSE., Yes\nlogical :: lookForOut= .false., lookForCDF = .FALSE.\nCharacter(len=5) :: CalcWith = \"INV\"\nCharacter(1) :: Y_\n! variables g\u00e9n\u00e9riques\nreal :: a, b, d, e\n\n! ici commence mon programme\n\n! Passage des argument, correspondance au nom de fichier. narg repr\u00e9sente le nombre d'arguments\nnarg=command_argument_count()\n! V\u00e9rification des arguments\n! fnamein et fnameout sont respectivement les noms de fichiers d'entr\u00e9e et de sortie (noms complets)\nif (narg > 0) then\n do i= 1, narg\n call get_command_argument(i, name)\n select case(adjustl(name))\n case(\"--in\")\n lookForIn = .TRUE. !change logical value\n case(\"--out\")\n lookForOut = .TRUE.\n case(\"--cdfin\")\n lookForIn = .TRUE.\n lookForCDF = .TRUE.\n case(\"--INV\")\n calcWith = \"INV\"\n case(\"--GAUSS\")\n calcWith = \"GAUSS\"\n case(\"--LU\")\n calcWith = \"LU\"\n case(\"--help\")\n inquire(file = hlpfilename, exist = fileExist) ! V\u00e9rifier si le fichier d'aide existe\n if (.not. fileExist) then\n write(*, *) \"fichier d'aide \", hlpfilename, ' in\u00e9xistant'\n write(*, *) \"Utilisation de NRPower :\"\n write(*, *) \"NRPower [Option] [Attribut]\"\n write(*, *) \"Option : --help, --in, --out\"\n write(*, *) \"Attribut : Nom du fichier (d'Aide, d'entr\u00e9e de donn\u00e9es, de sortie des r\u00e9sultats\"\n stop\n else\n open(10, file=hlpfilename, action='write')\n io = 0\n do while (io == 0)\n read(10, *, IOSTAT=io) hlpstr\n write(*,*) adjustl(trim(hlpstr))\n end do\n endif\n case default\n if (LookForIn) then\n ! Nom du fichier d'entr\u00e9e des donn\u00e9es r\u00e9seau\n fnamein = adjustl(name)\n ! V\u00e9rifier son existance dans le chemin sp\u00e9cifi\u00e9\n inquire(file = fnamein, exist = fileExist)\n if (.not. fileExist) then\n write(*,*) \"fichier de donn\u00e9es \", fnamein, \" est in\u00e9xistant dans l'emplacement d\u00e9sign\u00e9 ...\"\n stop\n else\n write(*,*) \"Acc\u00e8s au fichier de donn\u00e9es \", fnamein, \"...\"\n open(50, file = fnamein, action = \"read\")\n if (LookForCDF) Then\n Call CDFImport1(50)\n ! Dimensionnement des matrices et vecteurs\n print*, \"Allocation m\u00e9moire des matrices du r\u00e9seau\"\n allocate (Ya(N,N), Z(N,N), Ys(N, N), YB(N,N), YG(N,N), Spq(N,N))\n allocate (V(N), P(N), Q(N), Typen(N), ModV(N), Theta(N), Sg(N), Sd(N), Indx(N))\n ! Initialisation des donn\u00e9es\n ! Matrice admittance\n Ya = cmplx(0., 0.)\n Call CDFImport2(50)\n allocate (Nfrom(NB), Nto(NB))\n ! Vecteurs Nfrom et Nto \u00e0 0\n Nfrom = 0\n Nto = 0\n Call CDFImport3(50)\n Call Mef\n Call SaveImport(fnamein)\n print*, \"D\u00e9-allocation dynamique de la m\u00e9moire des donn\u00e9es CDF ...\"\n deallocate (Ya, Z, Ys, YB, YG, Spq)\n deallocate (V, P, Q, Typen, ModV, Theta, Sg, Sd, Indx)\n deallocate (Nfrom, Nto)\n print*, \"Ouverture du fichier de donn\u00e9es conforme NMSS ... traitement.\"\n LookForCDF = .FALSE.\n close(50)\n open(50, file = fnamein, action = \"read\")\n endif\n endif\n LookForIn = .FALSE.\n LookForInOut = .TRUE.\n elseif (LookForOut) then\n ! Nom du fichier d'entr\u00e9e des donn\u00e9es r\u00e9seau\n fnameout = adjustl(name)\n ! V\u00e9rifier son existance dans le chemin sp\u00e9cifi\u00e9\n inquire(file = fnameout, exist = fileExist)\n if (fileExist) then\n write(*,*) \"fichier de sortie \", fnameout, \" \u00e9xiste dans l'emplacement d\u00e9sign\u00e9 ...\"\n Yes = .FALSE.\n Do While (.not. Yes)\n Print*, \"Comfirmer l'ecrasement (O/N) ? \"\n read(*, \"(A1)\") Y_\n if (Y_ == \"O\") Then\n Yes = .TRUE.\n write(*,*) \"Acc\u00e8s au fichier de sortie \", fnameout, \"...\"\n open(60, file = fnameout, action='write')\n else\n print*,\"Impossibilit\u00e9 de continuer ... Merci de r\u00e9essayer.\"\n stop\n endif\n EndDo\n else\n write(*,*) \"Acc\u00e8s au fichier de sortie \", fnameout, \"...\"\n open(60, file = fnameout, action='write')\n endif\n LookForOut = .FALSE.\n LookForInOut = .TRUE.\n else\n write(*,*)\"Option [\",adjustl(name),\"] inconnue\"\n endif\n end select\n end do\nendif\n\n! saisie Dimension r\u00e9seau\n\nif (.not. LookForIn .and. .not. LookForInOut) Then\n write(*,*) \"Execution des donn\u00e9es TEST ... \"\n open(50, file='/home/mtamali/NR/NR/obj/Debug/data.dat')\nend if\n\nif (.not. LookForOut .and. .not. LookForInOut) Then\n write(*,*) \"Ecriture des r\u00e9sultats selon donn\u00e9es TEST ... \"\n open(60, file='/home/mtamali/NR/NR/obj/Debug/result.res', action='write')\nend if\n\n! Choix de lam\u00e9thode d'entr\u00e9e des donn\u00e9es (CDF ou standard NMSS)\nIf (.not. lookForCDF) Then\n ! Lecture des nombres de noeuds et de branches\n read(50, *) NName, N, NB, Sbase\n ! Ecriture des donn\u00e9es du r\u00e9seau.\n print*, \"Lecture de l'identification du r\u00e9seau\"\n write(60, *) 'Identification : ', NName\n write(60, *) \"le nombre de noeuds N= \", trim(Str(N)), \", le nombre de branches Nb= \", trim(Str(NB)),&\n &\" et la puissance de base Sb= \", Sbase, \" MVA.\"\n\n print*, \"Allocation m\u00e9moire des matrices du r\u00e9seau\"\n allocate (Ya(N,N), Z(N,N), Ys(N, N), YB(N,N), YG(N,N), Spq(N,N), Indx(N))\n allocate (V(N), P(N), Q(N), Typen(N), ModV(N), Theta(N), Sg(N), Sd(N), Nfrom(NB), Nto(NB))\n ! Initialisation des donn\u00e9es\n ! Matrice admittance\n Ya = cmplx(0., 0.)\n ! Vecteurs Nfrom et Nto \u00e0 0\n Nfrom = 0\n Nto = 0\n ! Vecteur tension nodal\n print*, \"Initialisation du vecteur tension nodal du r\u00e9seau ...\"\n V=cmplx(1.,0.)\n ! Dimensionnement des matrices et vecteurs\n ! Initialisation des puissances\n Sg=(0.0, 0.0)\n Sd=(0.0, 0.0)\n ! Lecture des donn\u00e9es des lignes de transport\n print*, \"Lecture des don\u00e9es lignes de transport du r\u00e9seau\"\n do w=1,NB\n ! Bfrom BTo R X Gsh Bsh\n Read(50,*) I, J, a, b, d, e\n Nfrom(w) = I\n Nto(w) = J\n Z(I,J)=cmplx(a,b)\n Ys(I,J)=cmplx(d,e)\n end do\n ! Initialisation des variables Np et Ng : Nombre de noeuds consommateurs et g\u00e9n\u00e9rateurs respectivement\n Np = 0\n Ng = 0\n ! Initialisation des vecteur ModV et Theta, Module de tension nodal et Argument\n ModV = 1.0\n Theta = 0.0\n\n ! Saisie type des noeud, valeurs sp\u00e9cifi\u00e9es.\n ! Noeud G\u00e9n\u00e9rateur G (Lire V, Pg), Consommateur C (Lire Pd, Qd) et Bilan B (Affecter V)\n print*, \"Lecture des donn\u00e9es caract\u00e9ristiques des noeuds du r\u00e9seau (pu)\"\n do I = 1, N\n Read(50,*) typen(I), a, b\n if (typen(I) == \"G\") then\n Ng = Ng + 1\n ModV(i) = a\n V(I) = ModV(I)*(V(i)/ModCmplx(V(I)))\n Sg(I)=Cmplx(b, 0.0)\n P(I) = Real(Sg(I) - Sd(I))\n write(60,\"(A,A,A,F9.3,A,A,A,F9.3)\") \"Noeud g\u00e9n\u00e9rateur |V|(\", trim(Str(I)), \")=\", &\n &ModCmplx(V(I)), \" | Pg(\", trim(Str(I)), \")=\", P(I)\n elseif (typen(I)==\"C\") then\n Np = Np + 1\n Sd(I)=Cmplx(a, b)\n P(I) = Real(Sg(I) - Sd(I))\n Q(I) = Imag(Sg(I) - Sd(I))\n write(60,\"(A,A,A,F9.3,A6,A,A,F9.3)\") \"Noeud consommateur Pd(\", trim(Str(I)), \")=\", &\n &P(I), \" | Qd(\", trim(Str(I)), \")=\", Q(I)\n else\n slack = I\n ModV(I) = a\n Theta(I) = b\n V(I)=cmplx(a*cos(b), a*sin(b))\n write(60, \"(A,A,A,F9.3,A,A,A,F9.3)\") \"Noeud balancier |V|(\", trim(Str(I)), \")=\", ModCmplx(V(I)), &\n &\" | Theta(\", trim(Str(I)), \")=\", Argum(V(I))\n end if\n enddo\n !c:saisie de epsilon et de Kmax\n print*, \"Lecture des \u00e9l\u00e9ments de tol\u00e9rance/limite des it\u00e9rations des traitements ...\"\n read(50,*) a, Kmax\n eps=a\nendif\n\n! Mise en forme des indices de noeuds.\nCall Mef\n!Call SaveImport\n!stop\n\nwrite(60,*) '------------------------------------------------------------------'\nwrite(60,\"(A)\") 'le vecteur tension nodal apr\u00e8s initialisation ...'\nwrite(60,\"(2F6.3,A5)\") (V(Indx(I)),\"*i pu\", I = 1, N)\nwrite(60,*) '------------------------------------------------------------------'\n\n! Subroutine de calcul de la matrice admittance Ya\nCall CalcYa\n\n! Formation des matrices G et B\nprint*, \"Initialisation de la matrice admitance du r\u00e9seau\"\nYG=real(Ya)\nYB=aimag(Ya)\n! Initialisation des vecteurs P et Q\nP=0.\nQ=0.\n\nA2Fmt= \"(\" // Trim(Str(N)) // \"(A1,(F9.3,1X,F9.3),A3))\"\n\n! Impression de la matrice admittance (ligne/ligne)\n!write(60,*) 'la matrice admittance Y ...'\n!do I=1,N\n! write(60, A2Fmt) (\"(\", Ya(I,J), \"*i)\", J=1,N)\n!end do\n!write(60,*) '------------------------------------------------------------------'\n\nwrite(60,*) 'la matrice conductance G=Real(Y)'\nAFmt= \"(\" // Trim(Str(N)) // \"F9.3,1X)\"\ndo I=1,N\n write(60, AFmt) (YG(I,J), J=1,N)\nend do\n\nwrite(60,*) '------------------------------------------------------------------'\nwrite(60,*) 'la matrice susceptance B=Imag(Y)'\ndo I=1,N\n write(60, AFmt) (YB(I,J), J=1,N)\nend do\nwrite(60,*) '------------------------------------------------------------------'\n\n! Alloue dynamiquement la vraie dimension de Ja, Fd et DX\nJN = Ng+2*Np\nprint*, \"Initialisation de la matrice Jacobienne du r\u00e9seau ... \"\nAllocate (Ja(JN, JN), Fd(JN), DX(JN), X(JN), c(JN, JN)) !, INDX(JN)\n\n!-----------------------------------------------------------------------------------------------------\nwrite(60,\"(A28, A, A23, F9.3)\") \"Nombre max des it\u00e9rations : \", trim(Str(Kmax)), \", Pr\u00e9cision demand\u00e9e : \", eps\n\n! Affectation et formation de la valeur ESTIME du veteur des inconnues [Teta, |V|] \u00e0 l'it\u00e9ration k=0\nX = 0.\nprint*, \"Initialisation du vecteur INCONNUES du r\u00e9seau ...\"\nwrite(60,\"(A39)\") \"Vecteur inconnues apr\u00e8s initialisation ...\"\nwrite(60,*) '------------------------------------------------------------------'\ndo I = 1, N-1\n X(I) = Argum(V(Indx(I+1)))\nend do\ndo I = N, JN\n X(I) = ModCmplx(V(Indx(I - Np + 1)))\nend do\n\ndo I=1, JN\n if (I .le. N-1) then\n write(60, \"(A2,A,A4,F9.3,A)\") \"X(\", trim(Str(I)), \") = \", X(I), \" radian(s)\"\n else\n write(60, \"(A2,A,A4,F9.3,A)\") \"X(\", trim(Str(I)), \") = \", X(I), \" pu\"\n endif\nend do\nwrite(60,*) '=================================================================='\n\n! D\u00e9but des it\u00e9rations\nCond = 0 ! Condition d'arr\u00eat relative \u00e0 Epsilloon\nk=1 ! Indice de l'it\u00e9ration\nprint*, \"D\u00e9but du traitement du r\u00e9seau \", NName\n! Evaluation du moment du d\u00e9but des traitements\ncall cpu_time ( t1 )\nwrite(*, \"(A,f9.3,A2)\") \"Temps d\u00e9but du traitement \u00e9valu\u00e9 \u00e0 : \", t1, \" s\"\n\nDo while (Cond==0 .and. k<=Kmax)\n write(60, \"(A26, A)\") \"D\u00e9but de l'it\u00e9ration, k = \", trim(Str(k))\n\n !Calcul des composantes de la matrice Jacobienne\n Ja = 0.0\n ! Element de la sous-matrice J1\n do i = 2, N\n do j = 2, N\n if (Indx(i) == Indx(j)) then\n Ja(i-1, j-1) = DP_Dtetaii(Indx(i), N)\n else\n Ja(i-1, j-1) = DP_Dtetaij(Indx(i), Indx(j))\n end if\n end do\n enddo\n ! Element de la sous-matrice J2\n do i = 1, N-1\n do j = N, JN\n if (Indx(i+1) == Indx(j-Np+1)) then\n Ja(i, j) = DP_DModVii(Indx(i+1), N)\n else\n Ja(i, j) = DP_DModVij(Indx(i+1), Indx(j-Np+1))\n end if\n end do\n enddo\n ! Element de la sous-matrice J3\n do i = N, JN\n do j = 1, N-1\n if (Indx(i-Np+1) == Indx(j+1)) then\n Ja(i, j) = DQ_Dtetaii(Indx(i-Np+1), N)\n else\n Ja(i, j) = DQ_Dtetaij(Indx(i-Np+1), Indx(j+1))\n endif\n end do\n enddo\n ! Element de la sous-matrice J4\n do i = N, JN\n do j = N, JN\n if (Indx(i-Np+1) == Indx(j-Np+1)) then\n Ja(i, j) = DQ_DModVii(Indx(i-Np+1), N)\n else\n Ja(i, j) = DQ_DModVij(Indx(i-Np+1), Indx(j-Np+1))\n endif\n end do\n enddo\n\n write(60,*) '------------------------------------------------------------------'\n ! Impression des elements de la matrice Jacobienne\n A3Fmt= \"(\" // Trim(Str(JN)) // \"F9.3,1X)\"\n write(60, *) \"Matrice jacobienne \u00e0 l'it\u00e9ration k=\", trim(Str(k))\n do i = 1, JN\n write(60, A3Fmt) (Ja(i, j), j = 1, JN)\n end do\n\n write(60,*) '------------------------------------------------------------------'\n ! Calcul des fonctions DeltaF\n write(60, *) \"Vecteur second membre DF ( it\u00e9ration k :\",trim(Str(k)),\")\"\n Fd = 0\n ! Les DeltaP de tous le noeuds sauf balancier (Ng + Np)\n do I = 1, N-1\n ! Correspond \u00e0 P (Noeuds de type PV et PQ)\n Fd(I) = - P(Indx(I+1)) + calcP(Indx(I+1))\n enddo\n ! DeltaQ des neux consommateurs seulement (Np)\n do I = N, JN\n Fd(I) = - Q(Indx(I-Np+1)) + CalcQ(Indx(I-Np+1))\n enddo\n\n ! Impression des DeltaP, DeltaQ r\u00e9sultants\n write(60,*) \"Impression des DeltaP, DeltaQ r\u00e9sultants\"\n do I=1, JN\n write(60, \"(A3,A,A2,F9.3)\") \"DF(\",trim(Str(I)),\")= \",Fd(I)\n end do\n\n if (CalcWith == \"INV\") Then\n ! ! Inversion de la matrice Jacobienne, en utilisant La m\u00e9thode de Gauss-Jordan\n Call InvMat(Ja, c, JN)\n ! Calcul de la solution du syst\u00e8me lin\u00e9aire J.DX = F\n DX = MatMul(c, Fd)\n elseif (CalcWith == \"GAUSS\") then\n Call GaussMat(Ja, Fd, DX, JN)\n elseif (CalcWith == \"LU\") then\n Call LEGS(Ja, JN, Fd, DX)\n endif\n\n ! Calculer les nouvelles valeurs de Theta et ModV\n X = X - DX\n!\n write(60,*) '------------------------------------------------------------------'\n write(60,*) \"Vecteur corrections \u00e0 l'it\u00e9ration k= \", trim(Str(k))\n write(60, \"(E9.3)\") (DX(I), I = 1, JN)\n!\n write(60,*) '------------------------------------------------------------------'\n write(60,*) \"Vecteur solution interm\u00e9diaire \u00e0 l'it\u00e9ration k= \", trim(Str(k))\n write(60, \"(E9.3)\") (X(I), I = 1, JN)\n!\n ! R\u00e9-\u00e9tablissement des valeurs des vecteurs ModV et de Theta\n do i=1, N-1 ! les N premi\u00e8res valeurs sont pour les arguments Theta\n Theta(i+1) = X(i)\n end do\n do i = N, JN ! Les suivantes sont pour les modules de V\n ModV(i-Np+1) = X(i)\n end do\n ! R\u00e9-\u00e9valuation du vecteur tension nodal, \u00e0 partir des corrections obtenues\n do i = 1, N\n V(i) = cmplx(ModV(i)*cos(Theta(i)), ModV(i)*sin(Theta(i)))\n enddo\n!\n ! D\u00e9terminer le maximum des DX\n MaxDX=Maxval(DX)\n write(60,*) '------------------------------------------------------------------'\n write (60,\"(A8,E9.3,A12,E9.3)\") \"MaxDX = \",MaxDX, \" Epsillon = \",eps\n\n ! Comparer avec Eps\n if (MaxDX <= eps) then\n ! si petit terminer, imprimer resultats\n Cond=1\n write(60,*) '------------------------------------------------------------------'\n write(60,*) \" Vecteur tension nodal \u00e0 l'it\u00e9ration k= \", trim(Str(k))\n write(60,*) '------------------------------------------------------------------'\n write(60,*) ' V(I) (pu) |V| (pu) Theta (Deg)'\n write(60,*) '------------------------------------------------------------------'\n do i = 1, N\n write(60, \"(A1,2F12.8,A6, F12.8, 2X, F12.8)\") \"(\",V(i),\"*i) - \", ModCmplx(V(i)), Argum(V(i))*180/pi\n enddo\n\n write(60,*) '------------------------------------------------------------------'\n ! Calcul du transit des puissance P et Q dans le r\u00e9seau et des pertes avec les derni\u00e8res corrections\n PL=0.\n QL=0.\n do i=1, N\n if (Typen(i) == \"B\") Then\n P(i) = CalcP(i)\n Q(i) = calcQ(i)\n elseif (Typen(i) == \"G\") Then\n Q(i) = CalcQ(i)\n end if\n PL = PL + P(i)\n QL = QL + Q(i)\n enddo\n\n ! Calcul du transit de puissances Spq\n Spq = 0.\n do i=1, N\n do j=1, N\n if (i /= j) Then\n Spq(i, j) = (V(i) - V(j))*conjg((V(i) - V(j))*Ya(i, j) - Ys(i, j)*V(i))\n Spq(j, i) = (V(j) - V(i))*conjg((V(j) - V(i))*Ya(i, j) - Ys(j, i)*V(j))\n end if\n end do\n end do\n\n ! Impression du transit de puissance et des pertes par transmission\n write(60, \"(A,F9.3,A5)\") \" Tableau des puissances nodales (pu), Sbase = \", Sbase, \" MVA.\"\n write(60, *) \"------------------------------------------------------------------------------------\"\n write(60, *) \"| Si | Pgi | Qgi | Pdi | Qdi |\"\n write(60, *) \"------------------------------------------------------------------------------------\"\n AFmt = \"(A2,2F9.3,A1,F14.8,A1,F15.8,A1,F14.8,A1,F17.8,A1)\"\n do i=1, N\n write(60, AFmt) \"|\", Cmplx(P(i),Q(i)), \"|\", Real(Sg(i)), \"|\", Imag(Sg(i)), \"|\", &\n &Real(Sd(i)), \"|\", Imag(Sd(i)), \"|\"\n end do\n write(60, \"(A)\") \" Tableau des puissances transmises (pu)\"\n write(60, *) \"------------------------------------------------------------------------------------\"\n write(60, *) \"| i | j | Sij (pu) | Sij (pu) | SLij (pu) |\"\n write(60, *) \"------------------------------------------------------------------------------------\"\n AFmt = \"(A2,I3,A1,I3,A1,2F12.8,A1,2F12.8,A1,2F12.8,A1)\"\n do i=1, N\n do j=i+1, N\n write(60, AFmt) \"|\", i,\"|\",j,\"|\",Spq(i,j),\"|\",Spq(j,i),\"|\",(Spq(i,j)-Spq(j,i)),\"|\"\n end do\n end do\n write(60, *) \"------------------------------------------------------------------------------------\"\n write(60, \"(A)\") \" Pertes par transmission (pu)\"\n write(60, *) \"------------------------------------------------------------------------------------\"\n write(60,*) \" \", Cmplx(PL, QL)\n write(60, *) \"------------------------------------------------------------------------------------\"\n call cpu_time ( t2 )\n write(*, \"(A,f6.3)\") \"Arr\u00eat des traitement \u00e0 \", t2\n print*, '=================================================================='\n write(60, \"(A,f6.3,A)\") \"Arr\u00eat des traitement \u00e0 \", t2, \" s\"\n else ! sinon refaire le calcul Jacob Ja\n k=k+1\n end if\n !Cond=1\nenddo ! Fin de la boucle\n\n! Fin du programme Newton raphson pour le calcul du Load Flow\nwrite(*,\"(A,f6.3,A2)\") \"Dur\u00e9e du traitement est \u00e9valu\u00e9e \u00e0 \", (t2 - t1), \" s\"\nwrite(60, \"(A,f6.3,A2)\") \"Dur\u00e9e du traitement est \u00e9valu\u00e9e \u00e0 \", (t2 - t1), \" s\"\nwrite(60,*) '=================================================================='\n! Impression des r\u00e9sultats ans le fichier de sortie (60)\n!\nClose(50)\nClose(60)\n\ncontains\n\n ! Fonction de calcul de la amatrice admittance Ya\n Subroutine CalcYa()\n Integer :: w, i_, j_\n\n do w=1,NB\n i_ = Nfrom(w)\n j_ = Nto(w)\n Ya(i_,j_)=-1/Z(i_,j_)\n ! ce ne sont pas les meme valeurs, Yii et Yjj\n Ya(i_,i_)=Ya(i_,i_)+(-Ya(i_,j_)+Ys(i_,j_)/2)\n Ya(j_,j_)=Ya(j_,j_)+(-Ya(i_,j_)+Ys(i_,j_)/2)\n Ya(j_,i_)=Ya(i_,j_)\n Z(j_,i_)=Z(i_,j_)\n end do\n end Subroutine\n\n ! Fonction du calcul de la puissance active\n Real function calcP(iI)\n integer :: ik, k_\n integer, intent(IN) :: iI\n Real :: S\n\n S = 0.\n Do ik = 1, N\n k_ = Indx(ik)\n S = S + ModCmplx(V(k_))*(YG(iI,k_)*cos(Teta(iI,k_)) + YB(iI,k_)*sin(Teta(iI,k_)))\n enddo\n calcP = ModCmplx(V(iI))*S\n end function\n\n ! Fonction du calcul de la puissance r\u00e9active\n Real function calcQ(iI)\n integer :: ik, k_\n integer, intent(IN) :: iI\n Real :: S\n\n S = 0.\n Do ik = 1, N\n k_ = Indx(ik)\n S = S + ModCmplx(V(k_))*(YG(iI,k_)*sin(Teta(iI,k_)) - YB(iI,k_)*cos(Teta(iI,k_)))\n enddo\n calcQ = ModCmplx(V(iI))*S\n end function\n\n ! Fonction du calcul du module de la tension nodale en un noeud\n Real function ModCmplx(z)\n complex, intent(IN) :: z\n\n !ModCmplx = (sqrt(Real(z)**2 + imag(z)**2))\n ModCmplx = (cabs(z))\n end function ModCmplx\n\n ! Fonction du calcul de l'argument de la tension nodale en un noeud\n Real function Argum(z)\n real :: theta\n\n complex, intent(IN) :: z\n\n theta = atan(imag(z)/real(z))\n !Argum = (theta*180)/pi\n Argum = theta\n end function\n !\n ! Fonction du calcul de la solution du syst\u00e8me AX=B selon GAUSS\n Subroutine GaussMat(Jaa, Bb, Xx, Nn)\n\n integer, intent(IN) :: Nn\n Real, intent(IN) :: Jaa(:,:), Bb(:)\n Real, allocatable, intent(OUT) :: Xx(:)\n\n Real, allocatable, Dimension(:,:) :: Aa\n integer :: ii, ij, ik\n Real :: Xsum, xmult\n !character(len=40) :: A3Fmt\n\n ! Formation de la matrice a = [Jaa | I]\n allocate(Aa(Nn,Nn+1), Xx(Nn))\n\n Xx=0.\n Aa=0.\n do ii=1, Nn\n do ij=1, Nn+1\n Aa(ii,ij) = Jaa(ii,ij)\n end do\n Aa(ii, Nn+1) = Bb(ii)\n end do\n\n ! Elimination de Gauss\n do ik = 1, Nn-1\n do ii = ik+1, Nn\n xmult = Aa(ii, ik) / Aa(ik, ik)\n Aa(ii, ik) = 0.\n do ij = ik+1, Nn+1\n Aa(ii, ij) = Aa(ii, ij) - xmult * Aa(ik, ij)\n end do\n end do\n end do\n\n Xx(Nn) = Aa(Nn, Nn+1) / Aa(Nn, Nn)\n do ii = Nn-1, 1, -1\n Xsum = 0.\n do ij= ii+1, Nn\n Xsum = Xsum + Aa(ii, ij) * Xx(ij)\n end do\n Xx(ii) = (Aa(ii, Nn+1) - Xsum) / Aa(ii, ii)\n end do\n\n deallocate(Aa)\n End Subroutine\n\n ! Proc\u00e9dure d'inversion matrice selon GAUSS-JORDAN\n Subroutine InvMat(Aa, Cc, Nn)\n !implicit none\n\n integer, Intent(IN) :: Nn\n Real, Intent(INOUT) :: Aa(Nn,Nn)\n\n Real, Intent(OUT) :: Cc(Nn,Nn)\n Real :: L(Nn,Nn), U(Nn,Nn), b(Nn), d(Nn), Xx(Nn)\n Real :: coeff\n integer ii, ij, ik\n\n L = 0.0\n U = 0.0\n b = 0.0\n\n do ik = 1, Nn-1\n do ii = ik+1, Nn\n coeff = Aa(ii,ik) / Aa(ik,ik)\n L(ii,ik) = coeff\n do ij = ik + 1, Nn\n Aa(ii,ij) = Aa(ii,ij) - coeff*Aa(ik,ij)\n end do\n end do\n end do\n\n do ii = 1, Nn\n L(ii,ii) = 1.0\n end do\n\n do ij = 1, Nn\n do ii = 1, ij\n U(ii, ij) = Aa(ii,ij)\n end do\n end do\n\n do ik = 1, Nn\n b(ik) = 1.0\n d(1) = b(1)\n do ii = 2, Nn\n d(ii) = b(ii)\n do ij = 1, ii-1\n d(ii) = d(ii) - L(ii,ij)*d(ij)\n end do\n end do\n Xx(Nn)=d(Nn)/U(Nn,Nn)\n do ii = Nn-1, 1, -1\n Xx(ii) = d(ii)\n do ij = n, ii+1, -1\n Xx(ii) = Xx(ii) - U(ii, ij)*Xx(ij)\n end do\n Xx(ii) = Xx(ii)/U(ii,ii)\n end do\n do ii = 1, Nn\n Cc(ii, ik) = Xx(ii)\n end do\n b(ik)=0.0\n end do\n end subroutine InvMat\n !\n ! Function de calcul de dP/dTeta ii\n Real function DP_Dtetaii(ii, Nn)\n Integer, intent(IN) :: ii, Nn\n integer :: ij, j_\n Real :: S\n\n S = 0.\n do ij = 1, Nn\n j_ = Indx(ij)\n if (ii /= j_) then\n S = S + ModCmplx(V(j_))*(YB(ii,j_)*cos(Teta(ii,j_)) - YG(ii,j_)*sin(teta(ii,j_)))\n endif\n enddo\n DP_Dtetaii = S*ModCmplx(V(ii))\n end function\n\n ! Function de calcul de dP/dTeta ij\n Real function DP_Dtetaij(ii, ij)\n Integer, intent(IN) :: ii, ij\n\n DP_Dtetaij = ModCmplx(V(ii))*ModCmplx(V(ij))*(YG(ii,ij)*sin(teta(ii,ij)) - YB(ii,ij)*cos(teta(ii,ij)))\n end function\n\n ! Function de calcul de dQ/dTeta ii\n Real function DQ_Dtetaii(ii, Nn)\n Integer, intent(IN) :: ii, Nn\n\n Integer :: ij,j_\n Real :: S\n\n S=0.\n do ij=1,Nn\n j_ = Indx(ij)\n if (ii/=j_) then\n S = S + ModCmplx(V(j_))*(YG(ii,j_)*cos(teta(ii,j_)) + YB(ii,j_)*sin(teta(ii,j_)))\n endif\n enddo\n DQ_Dtetaii = CalcP(ii) - YG(ii,ii)*(ModCmplx(V(ii))**2)\n end function\n\n ! Function de calcul de dQ/dTeta ij\n Real function DQ_Dtetaij(ii, ij)\n Integer, intent(IN) :: ii, ij\n\n DQ_Dtetaij = - ModCmplx(V(ii))*ModCmplx(V(ij))*(YG(ii,ij)*cos(teta(ii,ij)) + YB(ii,ij)*sin(teta(ii,ij)))\n end function\n\n ! Function de calcul de dP/dMod ii\n Real function DP_DModVii(ii, Nn)\n Integer, intent(IN) :: ii, Nn\n\n Integer :: ij, j_\n Real :: S\n\n S=0.\n do ij=1,Nn\n j_ = Indx(ij)\n if (ii/=j_) then\n S = S + ModCmplx(V(j_))*(YG(ii,j_)*cos(teta(ii,j_)) + YB(ii,j_)*sin(teta(ii,j_)))\n endif\n enddo\n DP_DModVii = ModCmplx(V(ii))*S + 2*YG(ii,ii)*(ModCmplx(V(ii)))**2\n end function\n\n ! Function de calcul de dP/dMod ij\n Real function DP_DModVij(ii, ij)\n Integer, intent(IN) :: ii, ij\n\n DP_DModVij = ModCmplx(V(ii))*ModCmplx(V(ij))*(YG(ii,ij)*cos(teta(ii,ij)) + YB(ii,ij)*sin(teta(ii,ij)))\n end function\n\n ! Function de calcul de dQ/dMod ii\n Real function DQ_DModVii(ii, Nn)\n Integer, intent(IN) :: ii, Nn\n\n Integer :: ij, j_\n Real :: S\n\n S = 0.\n do ij=1, Nn\n j_ = Indx(ij)\n if (ii /= j_) then\n S = S + ModCmplx(V(j_))*(YG(ii,j_)*sin(teta(ii,j_)) - YB(ii,j_)*cos(teta(ii,j_)))\n endif\n enddo\n DQ_DModVii = ModCmplx(V(ii))*S - 2*YB(ii,ii)*(ModCmplx(V(ii)))**2\n end function\n\n ! Function de calcul de dP/dMod ij\n Real function DQ_DModVij(Ii, Ji)\n Integer, intent(IN) :: Ii, Ji\n\n DQ_DModVij = ModCmplx(V(Ii))*ModCmplx(V(Ji))*(YG(Ii,Ji)*sin(teta(Ii,Ji)) - YB(Ii,Ji)*cos(teta(Ii,Ji)))\n end function\n\n ! Fonction de calcul de la dif\u00e9rence des arguments de deux tensions nodale\n Real function Teta(Ii,Ji)\n Integer, intent(IN) :: Ii,Ji\n\n Teta = Argum(V(Ii)) - Argum(V(Ji))\n end function\n\n ! Fonction Import de donn\u00e9es \u00e0 partir de fichier CDF (Common Data Format)\n subroutine CDFImport1(f_)\n !implicit none\n\n Integer, Intent(In) :: f_\n character(len=200) :: a_\n\n ! Lecture des informations de la premi\u00e8re section (Identification du r\u00e9seau)\n read(f_,'(A)') a_\n !NName = adjustl(a_(11:30))\n NName = adjustl(a_(46:73))\n SBase = Str2float(a_(32: 37))\n\n ! Lecture de la deuxi\u00e8me section (Pas importante) mention du nombre de neuds dans le r\u00e9seau.\n read(f_, '(A)') a_\n N = Str2int(a_(30: 46))\n end subroutine CDFImport1\n\n subroutine CDFImport2(f_)\n\n Integer, Intent(In) :: f_\n Integer :: ii, t_, inn = 0\n character(len=200) :: a_\n Real :: Pd_, Qd_, Pg_, Qg_\n\n ! Lecture de la troisi\u00e8me section, Donn\u00e9es des noeuds\n loop1 : Do\n read(f_, \"(A)\") a_\n ii = Str2Int(a_(1: 4))\n If (ii /= -999) then\n inn = inn +1\n ii = Str2Int(a_(1: 4))\n t_ = Str2Int(a_(25: 26))\n If (t_ .le. 1) then\n Typen(ii) = \"C\"\n elseif (t_ == 2) then\n Typen(ii) = \"G\"\n else\n Typen(ii) = \"B\"\n endif\n Pd_ = Str2Float(a_(41: 49))\n Qd_ = Str2Float(a_(50: 59))\n Pg_ = Str2Float(a_(60: 67))\n Qg_ = Str2Float(a_(68: 75))\n V(ii) = Str2Float(a_(28: 33))\n Sd(ii) = Cmplx(Pd_/Sbase, Qd_/Sbase)\n Sg(ii) = Cmplx(Pg_/Sbase, Qg_/Sbase)\n else\n exit loop1\n endif\n ! Affectation du nombre de noeuds, exact.\n N = inn\n enddo loop1\n\n ! Apr\u00e8s detection de la fin de la section 3, lecture de la section quatri\u00e8me : Donn\u00e9es es lignes\n read(f_, '(A)') a_\n Nb = Str2Int(a_(30: 46))\n end subroutine CDFImport2\n\n subroutine CDFImport3(f_)\n Integer, Intent(In) :: f_\n Integer :: ii, jj, inb = 0\n character(len=200) :: a_\n Real :: r_ , x_\n\n loop2: Do\n read(f_, \"(A)\") a_\n ii = Str2Int(a_(1: 4))\n If (ii /= -999) then\n inb = inb + 1\n Nfrom(inb) = ii\n jj = Str2Int(a_(6: 9))\n Nto(inb) = jj\n\n r_ = Str2Float(a_(20: 29))\n x_ = Str2Float(a_(30: 40))\n Z(ii, jj) = Cmplx(r_, x_)\n Ys(ii, jj) = Cmplx(0., Str2Float(a_(41: 50))/2)\n else\n exit loop2\n endif\n enddo loop2\n end subroutine CDFImport3\n\n Subroutine Mef()\n\n Integer :: i_\n !character(30) :: fm\n\n Indx = 0\n If (LookForCDF) Then\n ! Domaine du noeud Bilan B, un seul noeud.\n do i_= 1, N\n If (Typen(i_) == \"B\") Then\n Indx(1) = i_\n !Indx(i_) = 1\n endif\n enddo\n ! Domaine des noeuds g\u00e9n\u00e9rateurs, \u00e0 partir de 2 (1 r\u00e9serv\u00e9 au noeud Bilan).\n Ng=0\n do i_= 1, N\n if (Typen(i_) == \"G\") then\n Ng = Ng +1\n Indx(Ng + 1) = i_\n !Indx(i_) = Ng + 1\n endif\n end do\n ! Domaine des neuds consommateurs, \u00e0 partir de (Ng+1).\n Np=0\n do i_= 1, N\n If (Typen(i_) == \"C\") Then\n Np = Np +1\n Indx(Np + (Ng + 1)) = i_\n !Indx(i_) = Np + (Ng + 1)\n end if\n end do\n else\n do i_ = 1, N\n Indx(i_) = i_\n enddo\n end if\n\n! fm = \"(\" // Str(Ng+1) // \"(I3,2X))\"\n! write(*, fm) (Indx(i_), i_=1,N)\n\n end Subroutine Mef\n\n Subroutine SaveImport(f_)\n implicit none\n\n character(len=100), intent(out) :: f_\n integer :: i_, j_, k_\n\n f_ = adjustl(trim(f_(1: len(f_)-4)) // trim(GenerateRndCar()) // \".dat\")\n write(*,*) \"Ecriture temporaire dans fichier conforme standard NMSS ...\"\n\n open (unit=70, file=f_, action=\"write\")\n ! Retrait de tous les espaces de Nname\n Call removesp(Nname)\n\n write(70, \"(A,1X,I4,1X,I4,1X,F6.1)\") Nname, N, NB, Sbase\n do i_=1,NB\n! j_ = Indx(Nfrom(i_))\n! k_ = Indx(Nto(i_))\n j_ = Nfrom(i_)\n k_ = Nto(i_)\n write(70, \"(I4,1X,I4,1X,2F10.4,1X,2F10.4, I3,1X,I3)\") Indx(j_), Indx(k_), Z(j_, k_), Ys(j_, k_)\n enddo\n do j_ = 1, N\n i_ = Indx(j_)\n if (Typen(i_) == \"B\") Then\n write(70, \"(A1,1X,F9.3, 1X, F9.3, 1X, I4)\") Typen(i_), ModCmplx(V(i_)), Argum(V(i_)), i_\n elseif (Typen(i_) == \"G\") Then\n write(70, \"(A1,1X,F9.3, 1X, F9.3, 1X, I4)\") Typen(i_), ModCmplx(V(i_)), Real(Sg(i_)), i_\n elseif (Typen(i_) == \"C\") Then\n write(70, \"(A1,1X,F9.3, 1X, F9.3, 1X, I4)\") Typen(i_), Real(Sd(i_)), Imag(Sd(i_)), i_\n endif\n enddo\n write(70, \"(F10.6,1X,I4)\") eps, Kmax\n print*, \"Fermeture du fichier temporaire ...\"\n close(70)\n End Subroutine\n\n subroutine Removesp(str)\n implicit none\n\n character(len=*):: str\n character(len=1):: ch\n character(len=len_trim(str))::outstr\n integer :: i_, k_, ich, lenstr\n\n str=adjustl(str)\n lenstr=len_trim(str)\n outstr=' '\n k_=0\n\n do i_=1,lenstr\n ch=str(i_:i_)\n ich=iachar(ch)\n select case(ich)\n case(0:32) ! space, tab, or control character\n cycle\n case(33:)\n k_=k_+1\n outstr(k_:k_)=ch\n end select\n end do\n\n str=adjustl(outstr)\n end subroutine Removesp\n\n character(len=30) Function GenerateRndCar()\n implicit none\n\n real :: r_ = 2008.1960\n\n call RANDOM_NUMBER(r_)\n GenerateRndCar = Adjustl(Str(floor(r_*10000)))\n\n end function\n\nend program newtonrap\n", "meta": {"hexsha": "0d63b567d2c3c94310e478450eb9a4bd3fae09af", "size": 37897, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "main.f95", "max_stars_repo_name": "mtamali/Load-Flow-Tools", "max_stars_repo_head_hexsha": "5d2db7ac44f529f2b17386d0c080226aea3bb0df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-04-01T20:21:47.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-01T20:21:47.000Z", "max_issues_repo_path": "main.f95", "max_issues_repo_name": "mtamali/Load-Flow-Tools", "max_issues_repo_head_hexsha": "5d2db7ac44f529f2b17386d0c080226aea3bb0df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "main.f95", "max_forks_repo_name": "mtamali/Load-Flow-Tools", "max_forks_repo_head_hexsha": "5d2db7ac44f529f2b17386d0c080226aea3bb0df", "max_forks_repo_licenses": ["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.4483671668, "max_line_length": 117, "alphanum_fraction": 0.4656569122, "num_tokens": 11958, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267762381844, "lm_q2_score": 0.7799929104825007, "lm_q1q2_score": 0.6776787259031498}} {"text": "res = PRODUCT(x)**(1._prec/REAL(SIZE(x),prec))\n", "meta": {"hexsha": "8280d1cffcaf6b067d99fb8a7e4a9f98c40f4f7e", "size": 47, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/Statistics_M/include_gmean.f90", "max_stars_repo_name": "ecasglez/FortranUtilities", "max_stars_repo_head_hexsha": "a4c88fc190102524f0c669ac20489c5b85a754c1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/Statistics_M/include_gmean.f90", "max_issues_repo_name": "ecasglez/FortranUtilities", "max_issues_repo_head_hexsha": "a4c88fc190102524f0c669ac20489c5b85a754c1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Statistics_M/include_gmean.f90", "max_forks_repo_name": "ecasglez/FortranUtilities", "max_forks_repo_head_hexsha": "a4c88fc190102524f0c669ac20489c5b85a754c1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-16T08:04:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-16T08:04:24.000Z", "avg_line_length": 23.5, "max_line_length": 46, "alphanum_fraction": 0.6382978723, "num_tokens": 17, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.868826789824086, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6776787231700028}} {"text": "! { dg-do run }\n! { dg-options \"-O2 -ftree-vectorize -ffast-math\" }\n!\n! Contributed by Joost VandeVondele \n!\nSUBROUTINE T(nsubcell,sab_max,subcells)\n INTEGER, PARAMETER :: dp=KIND(0.0D0)\n REAL(dp) :: sab_max(3), subcells,nsubcell(3)\n nsubcell(:) = MIN(MAX(1,NINT(0.5_dp*subcells/sab_max(:))),20)\nEND SUBROUTINE T\n\nINTEGER, PARAMETER :: dp=KIND(0.0D0)\nREAL(dp) :: sab_max(3), subcells,nsubcell(3)\nsubcells=2.0_dp\nsab_max=0.590060749244805_dp\nCALL T(nsubcell,sab_max,subcells)\nIF (ANY(nsubcell.NE.2.0_dp)) STOP 1\nEND\n", "meta": {"hexsha": "f13da82201bc1e14498a38a386b3f0c9b6aab537", "size": 535, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/pr32533.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/pr32533.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/pr32533.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": 28.1578947368, "max_line_length": 63, "alphanum_fraction": 0.7121495327, "num_tokens": 216, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267762381844, "lm_q2_score": 0.7799928900257127, "lm_q1q2_score": 0.6776787081297446}} {"text": "module runge_kutta_mod\n use object_space_mod\n\ncontains\n\n subroutine run_runge_kutta(list, timescale, siz, steps, output_file, everyNth)\n implicit none\n integer, intent(in) :: siz, steps, everyNth\n real, intent(in) :: timescale\n character(LEN=100), intent(in) :: output_file\n integer :: i, j, x\n type(object_space), intent(inout) :: list(siz)\n\n open(unit=1, file=output_file, status='replace')\n\n write(1,*) siz\n write(1,*) (steps / everyNth)\n\n do j=1, steps\n\n!Calculate acceleration\n do x=1, siz\n call total_acceleration(x, siz, list)\n end do\n\n!Calculate runge_kutta\n do i=1, siz\n\n call calculate_runge_kutta(i, list, timescale, siz)\n\n!Write position\n if (MOD(j, everyNth) == 1) then\n do x=1, siz\n write(1,*) list(x)%pos(1)\n write(1,*) list(x)%pos(2)\n write(1,*) list(x)%pos(3)\n end do\n end if\n end do\n\n end do\n\n close(unit=1, status='keep')\n\n end subroutine\n\n!Calculate the the position\n subroutine calculate_runge_kutta(object, list, timescale, siz)\n implicit none\n integer, intent(in) :: object, siz\n real, intent(in) :: timescale\n real :: ax, ay, bx, by, cx, cy, dx, dy, velx, vely, posx, posy\n type(object_space), intent(inout) :: list(siz)\n\n list(object)%vel(1) = list(object)%vel(1) + list(object)%acc(1)*timescale\n list(object)%vel(2) = list(object)%vel(2) + list(object)%acc(2)*timescale\n\n velx = list(object)%vel(1)\n vely = list(object)%vel(2)\n posx = list(object)%pos(1)\n posy = list(object)%pos(2)\n\n ax = velx\n ay = vely\n\n list(object)%pos(1) = list(object)%pos(1) + 0.5 *timescale * ax\n list(object)%pos(2) = list(object)%pos(2) + 0.5 *timescale * ay\n\n call total_acceleration(object, siz, list)\n\n bx = list(object)%vel(1) + list(object)%acc(1) * timescale\n by = list(object)%vel(2) + list(object)%acc(2) * timescale\n\n list(object)%pos(1) = list(object)%pos(1) + 0.5 *timescale * bx\n list(object)%pos(2) = list(object)%pos(2) + 0.5 *timescale * by\n\n call total_acceleration(object, siz, list)\n\n cx = list(object)%vel(1) + list(object)%acc(1) * timescale\n cy = list(object)%vel(2) + list(object)%acc(2) * timescale\n\n list(object)%pos(1) = list(object)%pos(1) + timescale * cx\n list(object)%pos(2) = list(object)%pos(2) + timescale * cy\n\n dx = list(object)%vel(1) + cx * timescale\n dy = list(object)%vel(2) + cy * timescale\n\n list(object)%pos(1) = posx + timescale * (ax + 2 * bx + 2 * cx + dx) / 6\n list(object)%pos(2) = posy + timescale * (ay + 2 * by + 2 * cy + dy) / 6\n\n end subroutine calculate_runge_kutta\n\nend module runge_kutta_mod\n", "meta": {"hexsha": "264c5c2e4bd465b80d154ca05d28039b3767d272", "size": 2677, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "runge_kutta.f95", "max_stars_repo_name": "MrCubanfrog/Gravity-simulation", "max_stars_repo_head_hexsha": "1553253f038be76e6a0ecffa3cd651a789649eff", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-27T02:57:44.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-27T02:57:44.000Z", "max_issues_repo_path": "runge_kutta.f95", "max_issues_repo_name": "MrCubanfrog/Gravity-simulation", "max_issues_repo_head_hexsha": "1553253f038be76e6a0ecffa3cd651a789649eff", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "runge_kutta.f95", "max_forks_repo_name": "MrCubanfrog/Gravity-simulation", "max_forks_repo_head_hexsha": "1553253f038be76e6a0ecffa3cd651a789649eff", "max_forks_repo_licenses": ["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.4787234043, "max_line_length": 80, "alphanum_fraction": 0.6137467314, "num_tokens": 883, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505453836382, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6776621558841478}} {"text": " SUBROUTINE GETACT (N,M,AMAT,B,NACT,IACT,QFAC,RFAC,SNORM,\r\n 1 RESNEW,RESACT,G,DW,VLAM,W)\r\n IMPLICIT REAL*8 (A-H,O-Z)\r\n DIMENSION AMAT(N,*),B(*),IACT(*),QFAC(N,*),RFAC(*),\r\n 1 RESNEW(*),RESACT(*),G(*),DW(*),VLAM(*),W(*)\r\nC\r\nC N, M, AMAT, B, NACT, IACT, QFAC and RFAC are the same as the terms\r\nC with these names in SUBROUTINE LINCOB. The current values must be\r\nC set on entry. NACT, IACT, QFAC and RFAC are kept up to date when\r\nC GETACT changes the current active set.\r\nC SNORM, RESNEW, RESACT, G and DW are the same as the terms with these\r\nC names in SUBROUTINE TRSTEP. The elements of RESNEW and RESACT are\r\nC also kept up to date.\r\nC VLAM and W are used for working space, the vector VLAM being reserved\r\nC for the Lagrange multipliers of the calculation. Their lengths must\r\nC be at least N.\r\nC The main purpose of GETACT is to pick the current active set. It is\r\nC defined by the property that the projection of -G into the space\r\nC orthogonal to the active constraint normals is as large as possible,\r\nC subject to this projected steepest descent direction moving no closer\r\nC to the boundary of every constraint whose current residual is at most\r\nC 0.2*SNORM. On return, the settings in NACT, IACT, QFAC and RFAC are\r\nC all appropriate to this choice of active set.\r\nC Occasionally this projected direction is zero, and then the final value\r\nC of W(1) is set to zero. Otherwise, the direction itself is returned\r\nC in DW, and W(1) is set to the square of the length of the direction.\r\nC\r\nC Set some constants and a temporary VLAM.\r\nC\r\n ONE=1.0D0\r\n TINY=1.0D-60\r\n ZERO=0.0D0\r\n TDEL=0.2D0*SNORM\r\n DDSAV=ZERO\r\n DO 10 I=1,N\r\n DDSAV=DDSAV+G(I)**2\r\n 10 VLAM(I)=ZERO\r\n DDSAV=DDSAV+DDSAV\r\nC\r\nC Set the initial QFAC to the identity matrix in the case NACT=0.\r\nC\r\n IF (NACT .EQ. 0) THEN\r\n DO 30 I=1,N\r\n DO 20 J=1,N\r\n 20 QFAC(I,J)=ZERO\r\n 30 QFAC(I,I)=ONE\r\n GOTO 100\r\n END IF\r\nC\r\nC Remove any constraints from the initial active set whose residuals\r\nC exceed TDEL.\r\nC\r\n IFLAG=1\r\n IC=NACT\r\n 40 IF (RESACT(IC) .GT. TDEL) GOTO 800\r\n 50 IC=IC-1\r\n IF (IC .GT. 0) GOTO 40\r\nC\r\nC Remove any constraints from the initial active set whose Lagrange\r\nC multipliers are nonnegative, and set the surviving multipliers.\r\nC\r\n IFLAG=2\r\n 60 IF (NACT .EQ. 0) GOTO 100\r\n IC=NACT\r\n 70 TEMP=ZERO\r\n DO 80 I=1,N\r\n 80 TEMP=TEMP+QFAC(I,IC)*G(I)\r\n IDIAG=(IC*IC+IC)/2\r\n IF (IC .LT. NACT) THEN\r\n JW=IDIAG+IC\r\n DO 90 J=IC+1,NACT\r\n TEMP=TEMP-RFAC(JW)*VLAM(J)\r\n 90 JW=JW+J\r\n END IF\r\n IF (TEMP .GE. ZERO) GOTO 800\r\n VLAM(IC)=TEMP/RFAC(IDIAG)\r\n IC=IC-1\r\n IF (IC .GT. 0) GOTO 70\r\nC\r\nC Set the new search direction D. Terminate if the 2-norm of D is zero\r\nC or does not decrease, or if NACT=N holds. The situation NACT=N\r\nC occurs for sufficiently large SNORM if the origin is in the convex\r\nC hull of the constraint gradients.\r\nC\r\n 100 IF (NACT .EQ. N) GOTO 290\r\n DO 110 J=NACT+1,N\r\n W(J)=ZERO\r\n DO 110 I=1,N\r\n 110 W(J)=W(J)+QFAC(I,J)*G(I)\r\n DD=ZERO\r\n DO 130 I=1,N\r\n DW(I)=ZERO\r\n DO 120 J=NACT+1,N\r\n 120 DW(I)=DW(I)-W(J)*QFAC(I,J)\r\n 130 DD=DD+DW(I)**2\r\n IF (DD .GE. DDSAV) GOTO 290\r\n IF (DD .EQ. ZERO) GOTO 300\r\n DDSAV=DD\r\n DNORM=DSQRT(DD)\r\nC\r\nC Pick the next integer L or terminate, a positive value of L being\r\nC the index of the most violated constraint. The purpose of CTOL\r\nC below is to estimate whether a positive value of VIOLMX may be\r\nC due to computer rounding errors.\r\nC\r\n L=0\r\n IF (M .GT. 0) THEN\r\n TEST=DNORM/SNORM\r\n VIOLMX=ZERO\r\n DO 150 J=1,M\r\n IF (RESNEW(J) .GT. ZERO .AND. RESNEW(J) .LE. TDEL) THEN\r\n SUM=ZERO\r\n DO 140 I=1,N\r\n 140 SUM=SUM+AMAT(I,J)*DW(I)\r\n IF (SUM .GT. TEST*RESNEW(J)) THEN\r\n IF (SUM .GT. VIOLMX) THEN\r\n L=J\r\n VIOLMX=SUM\r\n END IF\r\n END IF\r\n END IF\r\n 150 CONTINUE\r\n CTOL=ZERO\r\n TEMP=0.01D0*DNORM\r\n IF (VIOLMX .GT. ZERO .AND. VIOLMX .LT. TEMP) THEN\r\n IF (NACT .GT. 0) THEN\r\n DO 170 K=1,NACT\r\n J=IACT(K)\r\n SUM=ZERO\r\n DO 160 I=1,N\r\n 160 SUM=SUM+DW(I)*AMAT(I,J)\r\n 170 CTOL=DMAX1(CTOL,DABS(SUM))\r\n END IF\r\n END IF\r\n END IF\r\n W(1)=ONE\r\n IF (L .EQ. 0) GOTO 300\r\n IF (VIOLMX .LE. 10.0D0*CTOL) GOTO 300\r\nC\r\nC Apply Givens rotations to the last (N-NACT) columns of QFAC so that\r\nC the first (NACT+1) columns of QFAC are the ones required for the\r\nC addition of the L-th constraint, and add the appropriate column\r\nC to RFAC.\r\nC\r\n NACTP=NACT+1\r\n IDIAG=(NACTP*NACTP-NACTP)/2\r\n RDIAG=ZERO\r\n DO 200 J=N,1,-1\r\n SPROD=ZERO\r\n DO 180 I=1,N\r\n 180 SPROD=SPROD+QFAC(I,J)*AMAT(I,L)\r\n IF (J .LE. NACT) THEN\r\n RFAC(IDIAG+J)=SPROD\r\n ELSE\r\n IF (DABS(RDIAG) .LE. 1.0D-20*DABS(SPROD)) THEN\r\n RDIAG=SPROD\r\n ELSE\r\n TEMP=DSQRT(SPROD*SPROD+RDIAG*RDIAG)\r\n COSV=SPROD/TEMP\r\n SINV=RDIAG/TEMP\r\n RDIAG=TEMP\r\n DO 190 I=1,N\r\n TEMP=COSV*QFAC(I,J)+SINV*QFAC(I,J+1)\r\n QFAC(I,J+1)=-SINV*QFAC(I,J)+COSV*QFAC(I,J+1)\r\n 190 QFAC(I,J)=TEMP\r\n END IF\r\n END IF\r\n 200 CONTINUE\r\n IF (RDIAG .LT. ZERO) THEN\r\n DO 210 I=1,N\r\n 210 QFAC(I,NACTP)=-QFAC(I,NACTP)\r\n END IF\r\n RFAC(IDIAG+NACTP)=DABS(RDIAG)\r\n NACT=NACTP\r\n IACT(NACT)=L\r\n RESACT(NACT)=RESNEW(L)\r\n VLAM(NACT)=ZERO\r\n RESNEW(L)=ZERO\r\nC\r\nC Set the components of the vector VMU in W.\r\nC\r\n 220 W(NACT)=ONE/RFAC((NACT*NACT+NACT)/2)**2\r\n IF (NACT .GT. 1) THEN\r\n DO 240 I=NACT-1,1,-1\r\n IDIAG=(I*I+I)/2\r\n JW=IDIAG+I\r\n SUM=ZERO\r\n DO 230 J=I+1,NACT\r\n SUM=SUM-RFAC(JW)*W(J)\r\n 230 JW=JW+J\r\n 240 W(I)=SUM/RFAC(IDIAG)\r\n END IF\r\nC\r\nC Calculate the multiple of VMU to subtract from VLAM, and update VLAM.\r\nC\r\n VMULT=VIOLMX\r\n IC=0\r\n J=1\r\n 250 IF (J .LT. NACT) THEN\r\n IF (VLAM(J) .GE. VMULT*W(J)) THEN\r\n IC=J\r\n VMULT=VLAM(J)/W(J)\r\n END IF\r\n J=J+1\r\n GOTO 250\r\n END IF\r\n DO 260 J=1,NACT\r\n 260 VLAM(J)=VLAM(J)-VMULT*W(J)\r\n IF (IC .GT. 0) VLAM(IC)=ZERO\r\n VIOLMX=DMAX1(VIOLMX-VMULT,ZERO)\r\n IF (IC .EQ. 0) VIOLMX=ZERO\r\nC\r\nC Reduce the active set if necessary, so that all components of the\r\nC new VLAM are negative, with resetting of the residuals of the\r\nC constraints that become inactive.\r\nC\r\n IFLAG=3\r\n IC=NACT\r\n 270 IF (VLAM(IC) .LT. ZERO) GOTO 280\r\n RESNEW(IACT(IC))=DMAX1(RESACT(IC),TINY)\r\n GOTO 800\r\n 280 IC=IC-1\r\n IF (IC .GT. 0) GOTO 270\r\nC\r\nC Calculate the next VMU if VIOLMX is positive. Return if NACT=N holds,\r\nC as then the active constraints imply D=0. Otherwise, go to label\r\nC 100, to calculate the new D and to test for termination.\r\nC\r\n IF (VIOLMX .GT. ZERO) GOTO 220\r\n IF (NACT .LT. N) GOTO 100\r\n 290 DD=ZERO\r\n 300 W(1)=DD\r\n RETURN\r\nC\r\nC These instructions rearrange the active constraints so that the new\r\nC value of IACT(NACT) is the old value of IACT(IC). A sequence of\r\nC Givens rotations is applied to the current QFAC and RFAC. Then NACT\r\nC is reduced by one.\r\nC\r\n 800 RESNEW(IACT(IC))=DMAX1(RESACT(IC),TINY)\r\n JC=IC\r\n 810 IF (JC .LT. NACT) THEN\r\n JCP=JC+1\r\n IDIAG=JC*JCP/2\r\n JW=IDIAG+JCP\r\n TEMP=DSQRT(RFAC(JW-1)**2+RFAC(JW)**2)\r\n CVAL=RFAC(JW)/TEMP\r\n SVAL=RFAC(JW-1)/TEMP\r\n RFAC(JW-1)=SVAL*RFAC(IDIAG)\r\n RFAC(JW)=CVAL*RFAC(IDIAG)\r\n RFAC(IDIAG)=TEMP\r\n IF (JCP .LT. NACT) THEN\r\n DO 820 J=JCP+1,NACT\r\n TEMP=SVAL*RFAC(JW+JC)+CVAL*RFAC(JW+JCP)\r\n RFAC(JW+JCP)=CVAL*RFAC(JW+JC)-SVAL*RFAC(JW+JCP)\r\n RFAC(JW+JC)=TEMP\r\n 820 JW=JW+J\r\n END IF\r\n JDIAG=IDIAG-JC\r\n DO 830 I=1,N\r\n IF (I .LT. JC) THEN\r\n TEMP=RFAC(IDIAG+I)\r\n RFAC(IDIAG+I)=RFAC(JDIAG+I)\r\n RFAC(JDIAG+I)=TEMP\r\n END IF\r\n TEMP=SVAL*QFAC(I,JC)+CVAL*QFAC(I,JCP)\r\n QFAC(I,JCP)=CVAL*QFAC(I,JC)-SVAL*QFAC(I,JCP)\r\n 830 QFAC(I,JC)=TEMP\r\n IACT(JC)=IACT(JCP)\r\n RESACT(JC)=RESACT(JCP)\r\n VLAM(JC)=VLAM(JCP)\r\n JC=JCP\r\n GOTO 810\r\n END IF\r\n NACT=NACT-1\r\n GOTO (50,60,280),IFLAG\r\n END\r\n", "meta": {"hexsha": "8426ba79a7e202d5f4fab13f2fcb27bded2695ec", "size": 9041, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "lincoa/fortran/getact.f", "max_stars_repo_name": "emmt/Algorithms", "max_stars_repo_head_hexsha": "a92ce79c75e22ea01a07c742ad74b02009857153", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2015-06-03T21:15:24.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-22T06:34:29.000Z", "max_issues_repo_path": "lincoa/fortran/getact.f", "max_issues_repo_name": "emmt/Algorithms", "max_issues_repo_head_hexsha": "a92ce79c75e22ea01a07c742ad74b02009857153", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lincoa/fortran/getact.f", "max_forks_repo_name": "emmt/Algorithms", "max_forks_repo_head_hexsha": "a92ce79c75e22ea01a07c742ad74b02009857153", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2017-06-14T14:53:23.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-13T08:07:03.000Z", "avg_line_length": 32.5215827338, "max_line_length": 78, "alphanum_fraction": 0.5461785201, "num_tokens": 3151, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008904, "lm_q2_score": 0.7490872131147276, "lm_q1q2_score": 0.6776621481814731}} {"text": "module zfun_hilbert\r\nuse types, only : rprec => dp\r\nprivate\r\npublic :: zfun_hil_init, zfun_hil\r\n\r\n! to get a double precision version, set n = 30 (or so)\r\n! residuals are ~ 1.0e-14\r\ninteger, parameter :: n = 32 ! number of eigenfunctions used in expansion\r\ninteger :: ierr ! error flag for fftpack\r\ninteger, parameter :: mult = 2! sample multiplyer--default is 2\r\ninteger, parameter :: m = mult * n! number of velocity function sample\r\ninteger, parameter :: lensav = 2 * m + int(log(real(2 * m))/log(2.0)) + 4\r\nreal(kind = rprec), parameter :: inv_m = 1.0_rprec / real(m, kind = rprec)\r\nreal(kind = rprec), dimension(2 * m) :: work\r\nreal(kind = rprec), dimension(lensav) :: wsave\r\nreal(kind = rprec) :: length, & ! renormalization parameter--set by n\r\n d_theta ! theta grid increment\r\nlogical, save :: first_flag ! use for initialization\r\nreal(kind = rprec), parameter :: infinity = huge(1.0_rprec)\r\nreal(kind = rprec), parameter :: pi = 4.0_rprec * atan(1.0_rprec)\r\nreal(kind = rprec), dimension(:), allocatable :: &\r\n f_vel, & ! array of f values on velocity grid\r\n theta_grid, & ! theta grid-- -pi to pi - dtheta\r\n veloc_grid ! grid of velocity values from vel = length * tan(theta/2.0)\r\n ! first value is -infinity, not actuall used--value of function will\r\n ! be set to zero.\r\ncomplex(kind = rprec), dimension(:,:), allocatable :: exp_m ! precomputed exponentials\r\ncomplex(kind = rprec), dimension(:), allocatable :: an !array for eigenfunction expansion coefficents\r\nreal(kind = rprec), dimension(:), allocatable :: re_an\r\ncomplex(kind = rprec), parameter :: zi = cmplx(0.0_rprec, 1.0_rprec)\r\ncontains\r\nsubroutine zfun_hil_init(ieer)\r\ninteger :: i\r\n!print*, 'lensav = ', lensav, 'fft len = ', m\r\ncall rfft1i(2*m, wsave, lensav, ieer)\r\n!print *, 'fft init '\r\n!print *, 2*m, lensav\r\n!do i = 1, lensav\r\n! print*, wsave(i)\r\n!end do\r\n\r\n!if(ieer .eq. 2) then\r\n! print *, 'input parameter lensav not big enough'\r\n! return\r\n!end if\r\n! move initial calculations to init\r\nallocate(theta_grid(0:2 * m))\r\n! a standard [0, 2*pi] grid will be used with an\r\n! even number of intervals and an odd number to\r\n! grid points. all will be indexed [0,2*m]\r\n! but the last on won't be used because of periodicity.\r\n!print *, 'theta grid', 'points = ', 2*m + 1\r\nd_theta = pi * inv_m\r\ndo i = 0, 2 * m\r\n theta_grid(i) = real(i, rprec) * d_theta\r\n !print *, i, theta_grid(i)\r\nend do\r\n! set the renormaliztion parameter\r\nlength = sqrt(real(n, rprec) * 0.7_rprec)\r\n! fill the velocity grid\r\nallocate(veloc_grid(0:2 * m ))\r\nveloc_grid(0) = -infinity\r\nveloc_grid(2 * m) = infinity\r\nveloc_grid(1:2 * m - 1 ) = length * tan((theta_grid(1:2 * m - 1) - pi) * 0.5_rprec)\r\n\r\n! fill the function grid\r\nallocate(f_vel(0:2 * m ))\r\n! may need to truncate the fill for practical cases\r\n! put zeros at the ends\r\nf_vel(0) = 0.0_rprec\r\nf_vel(2 * m) = 0.0_rprec\r\n! and the rest\r\nf_vel(1:2 * m -1) = exp(- veloc_grid(1:2 * m-1)**2) * &\r\n (length**2 + veloc_grid(1:2 * m-1)**2)\r\n!last term is takes out the weighting function in\r\n!the hilbert transorm\r\n!f_vel = 1.0_rprec\r\n!do i = 0, 2 * m\r\n! print *, i, theta_grid(i), veloc_grid(i), f_vel(i)\r\n!end do\r\n!end do\r\n!print *, ''\r\n! ft f_vel\r\n! compute the exponentials (not needed in general when using fft)\r\n!allocate(exp_m(0:2 * m - 1, 0:2 * m - 1))\r\n!do i = 0, 2 * m -1\r\n! do j = 0, 2 * m -1\r\n! exp_m(i, j) = exp(- zi * j * theta_grid(i))\r\n! !if(j .eq. 0) print*, exp_m(i, j)\r\n! end do\r\n!end do\r\n\r\n\r\n! get the coefficients--will use fft of real function ultimately\r\nallocate(an(0:2 * m))\r\nallocate(re_an(0:m))\r\n\r\n\r\nan = cmplx(0.0_rprec, 0.0_rprec)\r\n!do j = 0, 2 * m - 1\r\n! do i = 0, 2 * m - 1\r\n! an(j) = an(j) + exp_m(i, j) * f_vel(i)\r\n! ! for odd harmonics need to give the fft negative values\r\n! !if(j.eq.0) print*, an(j)\r\n! end do\r\n!end do\r\n! try and make the fftpack call\r\n!print *, 'ier for fftf call = ', ieer!, sum(f_vel(0:2*m -1))/2.0_rprec/m\r\n!print *, 'size of work ', size(work), 2 * m, size(f_vel(0:2 * m -1))\r\ncall rfft1f(2 * m, 1, f_vel(0:2 * m -1), 2 * m, wsave, lensav, &\r\n work, 2 * m, ieer)\r\n!print *, 'ier for fftf call = ', ieer, sum(f_vel)\r\n!print *, 'long, real fft ', j, an(0)* 0.5_rprec * inv_m, f_vel(0)\r\ndo j = 1, m\r\n! print *, 'long, real fft ', j, an(j) * inv_m, f_vel(2*j-1), f_vel(2*j)\r\n! an(j) = (-1)**j * an(j) * 0.5_rprec * inv_m\r\n !an(j) = (-1)**j * f_vel(2*j-1) * 0.5_rprec\r\n re_an(j) = (-1)**j * f_vel(2*j-1) * 0.5_rprec\r\n ! need to adjust signs because of coordinate shift from\r\n ! [-pi, pi] to [0, 2*pi] and remove the 2*m dtf normalization\r\n ! don't need to higher j's since they are aliased to negative\r\n ! frequencies\r\nend do\r\n!an(0) = an(0) * 0.5_rprec * inv_m\r\n!an(m) = an(m) * 2.0_rprec\r\nre_an(m) = 2.0_rprec * re_an(m)\r\n!an(0) = cmplx(f_vel(0), kind = rprec)\r\nre_an(0) = f_vel(0)\r\n!re_an = real(an(0:m))\r\n!print *, 'fourier coefficients'\r\n\r\nreturn\r\nend subroutine zfun_hil_init\r\n\r\nsubroutine zfun_hil(z_in, z_out, flag)\r\n! This routine computes the 'Z' function using an expansion of the\r\n! in the distribution function in eigenfunctions of the\r\n! eigenfunctions of the Hilbert transform. These eigen functions,\r\n! when the integration variable is changed from +/1 infinity via a\r\n! y = tan(theta/2.0), are Fourier basis functions on the interval\r\n! [-pi, pi]. With this renormalized integration variable, the\r\n! coefficients in the eigenvalue expansions can be computed with\r\n! FFTs. In addition, with the further normalizaton z = L*tan(theta/2),\r\n! the convergence can be made competitive with the classical three-region\r\n! algogrithm presented by GPM Poppe, CMJ Wigers: More efficient\r\n! computation of the complex error function ACM Trans. Math. Software\r\n! Vol. 16, No. 1, pp.47 presented by Hammett, netlib, and used (until replaced\r\n! because of license restrictions) in scipy. While the advantages maybe small\r\n! for CPU Maxwellian calcualtions, there are no if tests, except perhaps\r\n! for faults. The present routine is only good in the upper half plane\r\n! including the real axis\r\n! version2--convert to ffts, first use fftpack\r\nimplicit none\r\ncomplex(kind = rprec), intent(in) :: z_in\r\ncomplex(kind = rprec), intent(out) :: z_out\r\nlogical, intent(out) :: flag\r\ninteger :: i ! dummy index\r\ncomplex(kind = rprec) :: z_poly, z_term, z_out2\r\nreal(kind = rprec) :: x_term, y_term, x_poly, y_poly, x_in, y_in, x_out, y_out, &\r\n x_sq, y_sq, len_sq, denom_in, denom, x_out_sav, z_mod_sq, denom_l_in\r\n! check for allocations\r\nz_term = (length + zi * z_in) / (length - zi * z_in)\r\n!x_in = real(z_in); y_in = aimag(z_in)\r\n!x_sq = x_in **2; y_sq = y_in**2; len_sq = length**2\r\n!z_mod_sq = x_sq + y_sq\r\n!denom = z_mod_sq + len_sq + 2.0_rprec * length * y_in\r\n!denom_l_in = 1.0_rprec /( z_mod_sq * (x_sq - y_sq) - 2.0_rprec * len_sq * x_in * y_in)\r\n\r\n!denom_in = 1.0_rprec / denom\r\n!x_term = (len_sq - z_mod_sq) * denom_in\r\n!y_term = 2.0_rprec * x_in * length * denom_in\r\n!print *, z_term, x_term, y_term\r\nz_out = re_an(m)\r\n!x_out = re_an(m)\r\n!y_out = 0.0_rprec\r\n\r\ndo i = m, 2, -1\r\n z_out = z_term * z_out + re_an(i -1)\r\n !x_out_sav = x_out\r\n !x_out = re_an(i-1) + x_term * x_out_sav - y_term * y_out\r\n !y_out = x_term * y_out + y_term * x_out_sav\r\nend do\r\n!print *, 'long/short ', z_out, x_out, y_out\r\n!z_out = cmplx(x_out, y_out, kind = rprec)\r\nz_out = 2.0_rprec * z_term * z_out / (length**2 + z_in**2)\r\nz_out = z_out + re_an(0) / length / (length - zi * z_in)\r\n!x_out_sav = x_out\r\n!x_out = 2.0_rprec * (x_term * x_out - y_term * y_out) * denom_l_in\r\n!y_out = 2.0_rprec * (x_term * y_out + y_term * x_out_sav) * denom_l_in\r\n!x_out_sav = x_out\r\n!x_out = x_out * (len_sq + x_sq + y_sq)\r\n!y_out = -y_out * (x_in * y_in)\r\n!x_out_sav = x_out\r\n!x_out = x_out + re_an(0) / length /\r\n!y_out = y_out * re_an(0) / length\r\n\r\n\r\n\r\n!print *, an(0) / length * sqrt(pi)\r\n!x_out_sav = x_out\r\n!x_out = -sqrt(pi) * y_out\r\n!Y_out = sqrt(pi) * x_out_sav\r\nz_out = zi * sqrt(pi) * z_out\r\n! set the flag for success\r\nflag = .true.\r\nif(aimag(z_in) .lt. 0.0_rprec) stop 'negative im(zeta)'\r\nreturn\r\n\r\n\r\nend subroutine zfun_hil\r\n\r\nend module zfun_hilbert\r\n\r\n", "meta": {"hexsha": "655a3e4144c3ce2db5b78db32b53ab04f8ce9774", "size": 8170, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/zfun_hilbert_mod.f90", "max_stars_repo_name": "ORNL-Fusion/aorsa", "max_stars_repo_head_hexsha": "82bab1e3b88e10e6bd5ca9b16589b11a97dd8f39", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2019-03-12T13:33:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-11T08:28:46.000Z", "max_issues_repo_path": "src/zfun_hilbert_mod.f90", "max_issues_repo_name": "ORNL-Fusion/aorsa", "max_issues_repo_head_hexsha": "82bab1e3b88e10e6bd5ca9b16589b11a97dd8f39", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 29, "max_issues_repo_issues_event_min_datetime": "2020-01-24T15:58:55.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-28T15:16:05.000Z", "max_forks_repo_path": "src/zfun_hilbert_mod.f90", "max_forks_repo_name": "ORNL-Fusion/aorsa", "max_forks_repo_head_hexsha": "82bab1e3b88e10e6bd5ca9b16589b11a97dd8f39", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-09-10T16:48:52.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-10T16:48:52.000Z", "avg_line_length": 38.1775700935, "max_line_length": 102, "alphanum_fraction": 0.64124847, "num_tokens": 2835, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391621868805, "lm_q2_score": 0.7341195385342971, "lm_q1q2_score": 0.677621083793717}} {"text": " subroutine newint(nr,r,f,g,ip0)\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\nc\nc----- this routine integrates functn f on a 1-d mesh by interpolation\nc the partial integrals (up to r(k)) are stored in b(k). the mesh\nc is arbitrary\nc xgz ornl 1998\nc\n implicit real*8 (a-h,o-z)\nc\n real*8 r(nr),cr(4)\n real*8 f(nr),g(nr)\n real*8 fr(4),rs(4)\n parameter (nj=6,njm1=nj-1)\n parameter (dnj=1.d0/nj)\n parameter (wt0=2.d0/(3.d0*nj),wt1=3.d0*wt0)\nc\n ip=2*ip0+1\n pip1=1.d0/dble(ip+1)\n pip2=1.d0/dble(ip+2)\n g(1)=0.d0\n i1=1\n i2=2\n i3=3\n i4=4\n i0=1\n do i=1,4\n\trs(i)=sqrt(r(i))\n\tfr(i)=f(i)\n enddo\n ip1=1\n ip2=4\n do i=1,nr-1\n\tip1=ip1+1\n\n\tif(i.gt.2.and.ip2.le.nr) then\n\t rs(i4)=sqrt(r(ip2))\n fr(i4)=f(ip2)\n\tendif\n call fit(rs,fr,4,i0,cr)\nc First integrate a linear frunction going through f(i) and f(ip1)\nc A4=fi-A1\n\trip1=rs(mod(i0,4)+1)\n\tgj=1.d0\n\tfj=rip1\n\tdo j=1,ip\n\t gj=gj*rs(i0)+fj\n\t fj=fj*rip1\n\tenddo\n\tfj=(gj*rs(i0)+fj)*pip2\n\tgj=gj*pip1\n\tgr=(fr(i0)-cr(3)*rs(i0))*gj+cr(3)*fj\nc Using Simpson's rule. No contribution from j=0 and j=nj.\n\tdr=rip1-rs(i0)\n h1=dnj*dr\n\th2=0.d0\n\twt=wt0\n\tdo j=1,njm1\n\t h2=h2+h1\n\t wt=wt1-wt\n\t fj=wt\n\t rj=rs(i0)+h2\n\t do k=1,ip\n\t fj=fj*rj\n\t enddo\n\t gj=h2*(dr-h2)\n\t c1=(cr(3)-cr(2))*h2+cr(1)\n\t c2=cr(4)*gj\n\t gr=gr-fj*c1*c2/(1.d0+c2)\n\tenddo\n\tg(ip1)=g(i)+2.d0*dr*gr\n\tif(i.gt.1.and.ip2.lt.nr) then\n\t ip2=ip2+1\n\t j=i1\n\t i1=i2\n\t i2=i3\n\t i3=i4\n\t i4=j\n\tendif\n\ti0=mod(i0,4)+1\n enddo\n return\n end\n", "meta": {"hexsha": "90a30fb6fcc5e55fbaa391dc9330a94e6d56d2d8", "size": 1611, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/Misc/newint.f", "max_stars_repo_name": "rdietric/lsms", "max_stars_repo_head_hexsha": "8d0d5f01186abf9a1cc54db3f97f9934b422cf92", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2020-01-05T20:05:31.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T09:08:01.000Z", "max_issues_repo_path": "src/Misc/newint.f", "max_issues_repo_name": "rdietric/lsms", "max_issues_repo_head_hexsha": "8d0d5f01186abf9a1cc54db3f97f9934b422cf92", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2019-07-30T13:59:18.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T17:43:35.000Z", "max_forks_repo_path": "lsms/src/Misc/newint.f", "max_forks_repo_name": "hkershaw-brown/MuST", "max_forks_repo_head_hexsha": "9db4bc5061c2f2c4d7dfd92f53b4ef952602c070", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2020-02-11T17:04:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-28T09:23:46.000Z", "avg_line_length": 19.1785714286, "max_line_length": 72, "alphanum_fraction": 0.5642458101, "num_tokens": 751, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391579526934, "lm_q2_score": 0.7341195385342971, "lm_q1q2_score": 0.6776210806853175}} {"text": "C$Procedure LATSPH ( Latitudinal to spherical coordinates )\n \n SUBROUTINE LATSPH ( RADIUS, LONG, LAT, RHO, COLAT, LONGS )\n \nC$ Abstract\nC\nC Convert from latitudinal coordinates to spherical coordinates.\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 CONVERSION, COORDINATES\nC\nC$ Declarations\n \n DOUBLE PRECISION RADIUS\n DOUBLE PRECISION LONG\n DOUBLE PRECISION LAT\n DOUBLE PRECISION RHO\n DOUBLE PRECISION COLAT\n DOUBLE PRECISION LONGS\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC RADIUS I Distance of a point from the origin.\nC LONG I Angle of the point from the XZ plane in radians.\nC LAT I Angle of the point from the XY plane in radians.\nC RHO O Distance of the point from the origin.\nC COLAT O Angle of the point from positive Z axis (radians).\nC LONGS O Angle of the point from the XZ plane (radians).\nC\nC$ Detailed_Input\nC\nC RADIUS Distance of a point from the origin.\nC\nC LONG Angle of the point from the XZ plane in radians.\nC\nC LAT Angle of the point from the XY plane in radians.\nC\nC$ Detailed_Output\nC\nC RHO Distance of the point from the origin.\nC\nC COLAT Angle between the vector from the origin to the point\nC and the positive Z axis in radians. COLAT is computed\nC as PI/2 - LAT.\nC\nC LONGS Angle of the point from the XZ plane (radians). LONGS\nC is set equal to LONG.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC Error free.\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC This routine returns the spherical coordinates of a point\nC whose position is input in latitudinal coordinates.\nC\nC Latitudinal coordinates are defined by a distance from a central\nC reference point, an angle from a reference meridian, and an angle\nC above the equator of a sphere centered at the central reference\nC point.\nC\nC Spherical coordinates are defined by a distance from a central\nC reference point, an angle from a reference meridian, and an angle\nC from the z-axis.\nC\nC$ Examples\nC\nC Co-latitude is obtained by subtracting latitude from HALFPI()\nC Radius and longitude mean the same thing in both latitudinal\nC and spherical coordinates. The table below lists LAT\nC corresponding COLAT in terms of degrees.\nC\nC LAT COLAT\nC ------ ------\nC 0 90\nC 20 70\nC 45 45\nC -30 120\nC 90 0\nC -45 135\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC W.L. Taber (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.2, 26-JUL-2016 (BVS)\nC\nC Minor headers edits.\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 latitudinal to spherical coordinates\nC\nC-&\n \n \nC$ Revisions\nC\nC- Beta Version 1.0.1, 1-Feb-1989 (WLT)\nC\nC Example section of header upgraded.\nC\nC-&\n \nC\nC SPICELIB functions\nC\n DOUBLE PRECISION HALFPI\n \nC\nC Local Variables\nC\n DOUBLE PRECISION TH\n DOUBLE PRECISION PH\n \nC\nC Convert to spherical coordinates, storing the results in\nC temporary variables\nC\n TH = HALFPI() - LAT\n PH = LONG\n \nC\nC Move results to output variables\nC\n RHO = RADIUS\n COLAT = TH\n LONGS = PH\n \n RETURN\n END\n", "meta": {"hexsha": "ef59a449f4975d01690251fa14924d06bd917f74", "size": 5127, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/latsph.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/latsph.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/latsph.f", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 26.703125, "max_line_length": 71, "alphanum_fraction": 0.652038229, "num_tokens": 1429, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563335, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6774336912408675}} {"text": " FUNCTION RAN1_b(IDUM)\n implicit none\n integer idum,ia,im,iq,ir,ntab,ndiv\n real ran1_b,am,eps,rnmx\n parameter(ia=16807,im=2147483647,am=1./im,iq=127773,ir=2836, &\n ntab=32,ndiv=1+(im-1)/ntab,eps=1.2e-7,rnmx=1.-eps)\n\n! Minimal random number generator of Park and Miller with Bays-Durham\n! shuffle and added safeguards. Returns a uniform random deviate between\n! 0.0 and 1.0 (exclusive of the endpoint values.) Call with idum a negative\n! integer to initialize; thereafter, do not alter idum between successive\n! deviates in a sequence. tnmx should approximate the largest floating\n! value that is less than 1. From Numerical Recipes.\n\n integer j,k,iv(ntab),iy\n save iv,iy\n data iv /ntab*0/, iy /0/\n if(idum.le.0.or.iy.eq.0)then\n idum=max(-idum,1)\n do j=ntab+8,1,-1\n k=idum/iq\n idum=ia*(idum-k*iq)-ir*k\n if(idum.lt.0) idum=idum+im\n if(j.le.ntab) iv(j)=idum\n end do\n iy=iv(1)\n end if\n k=idum/iq\n idum=ia*(idum-k*iq)-ir*k\n if(idum.lt.0) idum=idum+im\n j=1+iy/ndiv\n iy=iv(j)\n iv(j)=idum\n ran1_b=min(am*iy,rnmx)\n return\n END FUNCTION RAN1_B\n", "meta": {"hexsha": "d368118ccae03e69f510daa051f320c59cb885d2", "size": 1136, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/utilities/RAN1_b.f90", "max_stars_repo_name": "apengsigkarup/OceanWave3D", "max_stars_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 46, "max_stars_repo_stars_event_min_datetime": "2016-01-08T12:36:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T06:56:45.000Z", "max_issues_repo_path": "src/utilities/RAN1_b.f90", "max_issues_repo_name": "apengsigkarup/OceanWave3D", "max_issues_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-10-10T19:45:08.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-07T07:37:11.000Z", "max_forks_repo_path": "src/utilities/RAN1_b.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": 30.7027027027, "max_line_length": 76, "alphanum_fraction": 0.6540492958, "num_tokens": 429, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460332, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6774336865585832}} {"text": " subroutine eemd(LXY,indata,An,Nesb,Nm,idum,rslt)\n!-----------------------------------------------------------------------------\n! This is a subroutine to decompose data(LXY) in terms of its EEMD component.\n! When the added noise amplitude is zero (An=0) and the ensemble number\n! is one (Nesb=0), the code degenerates to standard EMD\n!\n! In this code, the number of the oscillatory components is specified as an\n! input, Nm. For most cases, automatic calculation, Nm can be set to log2(LXY)-2\n!\n! INPUT DATA:\n!\t\tindata(LXY)\t\tinput array with a length of LXY\n! \t\tAn \t\t\tamplitude of added noise\n! \t\tNesb \t\t\tnumber of ensemble members\n! \t\tNm \t\t\tnumber of mode in each decomposition\n! \t\tidum \t\t\tseed for the random number\n! OUTPUT DATA:\n! \t\trslt(LXY, Nm+2) \toutput rseults, which contains Nm+2 columns\n!\t\t\t\t\tThe first column is the origninal indata;\n!\t\t\t\t\tThe second column is the first component;\n!\t\t\t\t\tThe third column is the second component;\n!\t\t\t\t\tand so on\n!\t\t\t\t\tThe last column is the residue\n!-------------------------------------------------------------------------------\n implicit none\n INCLUDE 'eemd.common'\n real :: An\t\t\t\t! noise amplitude\n integer, intent(in) :: LXY, Nesb, Nm\n integer, intent(inout):: idum\n real, dimension(LXY), intent(in) :: indata\n real, dimension(LXY) :: ximf\t\t! data for sifting\n real, dimension(LXY) :: spmax\t\t! upper envelope, cubic spline\n real, dimension(LXY) :: spmin\t\t! lower envelope, cubic spline\n real, dimension(LXY) :: ave\t\t! the average of spmax and spmin\n real, dimension(LXY) :: remp\t\t! the input data for sifting\n real, dimension(LXY) :: rem\t\t! the remainder (remp-ximf)\n\n real, dimension(LXY,Nm+2) :: rslt\t\t! the final output data\n real, dimension(LXY,Nm+2) :: allmode\t! the results of a single EMD decomposition\n\n integer :: nmax, nmin\t\t\t! numbers of maximum and minimum\n real, dimension(LXY) :: trend\t\t! linear trend of indata\n real :: std\t\t! standard deviation of the linearly detrended indata\n integer:: i,j,IE,im,ii\n real :: fNesb, gasdev\n\n\n! initialize the output\n rslt=0.0\n\n!\n! ensemble EMD\n!\n! *******************************************************\n do IE=1,Nesb\n! *******************************************************\n!\n call standev(LXY,indata,trend, std)\n\n! inputted data + noise\n if(Nesb.eq.1) then\n ximf=indata\n else\n do i=1,LXY\n ximf(i)=indata(i)+An*std*gasdev(idum)\n enddo\n endif\n\n! save modified data\n do i=1,LXY\n allmode(i,1)=ximf(i)\n enddo\n\n! calculate modes\n! =======================================================\n do im=1,Nm\n! =======================================================\n!\n! leave a copy of the input data before IMF is calculated\n remp=ximf\n!\n! Sifting\n! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n do ii=1,10\n! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n call min_max(LXY,ximf,spmax,spmin,nmax,nmin)\n call natural_spline(spmax,LXY,nmax)\n call natural_spline(spmin,LXY,nmin)\n\n ave=(spmax+spmin)/2.0\n ximf=ximf-ave\n\n! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n enddo\n! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \n\n rem=remp-ximf\n\n do i=1,LXY\n allmode(i,im+1)=ximf(i)\n enddo\n\n ximf=rem\n\n! =======================================================\n enddo\n! =======================================================\n\n do i=1,LXY\n allmode(i,Nm+2)=ximf(i)\n enddo\n\n do j=1,Nm+2\n do i=1,LXY\n rslt(i,j)=rslt(i,j)+allmode(i,j)\n enddo\n enddo\n\n! ---------------------------------------------------------\n enddo\n! ---------------------------------------------------------\n \n fNesb=real(Nesb)\n rslt=rslt/fNesb\n\n end subroutine eemd\n\n", "meta": {"hexsha": "1b67b8dce0f29015c832123259de2b4cf88e69d8", "size": 4062, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "eemdf90/test/eemd.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/eemd.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/eemd.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": 31.734375, "max_line_length": 86, "alphanum_fraction": 0.4643032989, "num_tokens": 1049, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460333, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.677433681840263}} {"text": "module mat_lib\n interface matinv\n module procedure matinv_d,matinv_z\n end interface\n private :: matinv_d,matinv_z,matinv_svd_d,matinv_svd_z\n\n interface eye\n module procedure eye_d1, eye_z1, eye_d2,eye_z2\n end interface\n interface laplace\n module procedure laplace_d2,laplace_z2\n end interface\n\ncontains\n subroutine matinv_d(a,ainv,alg,tol)\n implicit none\n double precision,intent(inout) :: a(:,:)\n double precision,intent(out),optional :: ainv(size(a,2),size(a,1))\n character(len=1),intent(in),optional :: alg\n double precision,intent(in),optional :: tol\n character(len=*),parameter :: subnam='matinv_d'\n if(.not.present(alg) .or. size(a,1).ne.size(a,2))then\n call matinv_svd_d(a,ainv,tol)\n else\n select case(alg)\n case('s','S')\n call matinv_svd_d(a,ainv,tol)\n case('t','T')\n call matinv_lu_d(a,ainv)\n case default\n write(*,'(3a)')subnam,': unknown alg: ',alg\n stop\n end select\n end if\n return\n end subroutine \n subroutine matinv_z(a,ainv,alg,tol)\n implicit none\n complex(8),intent(inout) :: a(:,:)\n complex(8),intent(out),optional :: ainv(size(a,2),size(a,1))\n character(len=1),intent(in),optional :: alg\n double precision,intent(in),optional :: tol\n character(len=*),parameter :: subnam='matinv_z'\n if(.not.present(alg) .or. size(a,1).ne.size(a,2))then\n call matinv_svd_z(a,ainv,tol)\n else\n select case(alg)\n case('s','S')\n call matinv_svd_z(a,ainv,tol)\n case('t','T')\n call matinv_lu_z(a,ainv)\n case default\n write(*,'(3a)')subnam,': unknown alg: ',alg\n stop\n end select\n end if\n return\n end subroutine \n\n subroutine matinv_svd_d(a,ainv,tol)\n implicit none\n double precision,intent(inout) :: a(:,:)\n double precision,intent(out),optional :: ainv(size(a,2),size(a,1))\n double precision,intent(in),optional :: tol\n character(len=*),parameter :: subnam='matinv_svd_d'\n double precision,allocatable :: b(:,:),u(:,:),v(:,:),s(:),work(:)\n integer :: r,lwork,info,i,ntrunc,m,n\n double precision :: si,s1,small\n character(len=180) :: str\n \n m=size(a,1); n=size(a,2)\n if(present(tol))then;small=tol;else;small=1.d-14;endif\n write(str,'(a,a,i8,1x,i8)')subnam,': m,n:',m,n \n !call plog(2,str)\n r=min(m,n); lwork=64*max(m,n)\n allocate(b(m,n),u(m,r),v(r,n),s(r),work(lwork))\n b=a\n call dgesvd('s','s',m,n,b,m,s,u,m,v,r, work,lwork,info)\n if(info.ne.0)then\n write(*,'(a,a,i10)')subnam,': dgesvd info: ',info\n stop\n end if\n \n s1=s(1)\n !write(str,'(a,80(e9.3,1x))')'sv:',(fmem(s+i)/s1,i=1,r)\n !call plog(1,str)\n\n ntrunc=0\n do i=1,r\n si=s(i)\n if(si.lt.small*s1)then\n s(i)=0.d0; ntrunc=ntrunc+1\n else\n s(i)=1.d0/s(i)\n end if\n end do\n \n forall(i=1:r)u(:,i)=u(:,i)*s(i)\n if(present(ainv))then\n call dgemm('t','t',n,m,r,1.d0,v,r,u,m,0.d0,ainv,n)\n else\n call dgemm('t','t',n,m,r,1.d0,v,r,u,m,0.d0,a,n)\n end if \n if(ntrunc.gt.0)then\n write(*,'(a,a,i5,a,i5)')subnam,': truncate: ',ntrunc,' of: ',r\n !call plog(1,str)\n end if\n\n deallocate(b,u,v,s,work)\n return\n end subroutine\n subroutine matinv_svd_z(a,ainv,tol)\n implicit none\n complex(8),intent(in) :: a(:,:)\n complex(8),intent(out) :: ainv(size(a,2),size(a,1))\n double precision,intent(in),optional :: tol\n character(len=*),parameter :: subnam='matinv_svd_z'\n complex(8),allocatable :: b(:,:),u(:,:),v(:,:),work(:)\n double precision,allocatable :: s(:),rwork(:)\n integer :: r,lwork,lrwork,info,i,ntrunc,m,n\n double precision :: small=1.d-14\n double precision :: si,s1\n character(len=180) :: str\n \n m=size(a,1); n=size(a,2)\n if(present(tol))small=tol\n write(str,'(a,a,i8,1x,i8)')subnam,': m,n:',m,n \n !call plog(2,str)\n r=min(m,n); lwork=64*max(m,n); lrwork=5*min(m,n)\n allocate(b(m,n),u(m,r),v(n,r),s(r),work(lwork),rwork(lrwork))\n b=a\n call zgesvd('s','s',m,n,b,m,s,u,m,v,n,work,lwork,rwork,info)\n if(info.ne.0)then\n write(*,'(a,a,i10)')subnam,': zgesvd info: ',info\n stop\n end if\n \n s1=s(1)\n !write(str,'(a,80(e9.3,1x))')'sv:',(fmem(s+i)/s1,i=1,r)\n !call plog(1,str)\n\n ntrunc=0\n do i=1,r\n si=s(i)\n if(si.lt.small*s1)then\n s(i)=0.d0; ntrunc=ntrunc+1\n else\n s(i)=1.d0/s(i)\n end if\n end do\n \n forall(i=1:r)u(:,i)=u(:,i)*s(i)\n call zgemm('c','c',n,m,r,(1.d0,0.d0),v,r,u,m,(0.d0,0.d0),ainv,n)\n if(ntrunc.gt.0)then\n write(str,'(a,a,i5,a,i5)')subnam,': truncate: ',ntrunc,' of: ',r\n !call plog(1,str)\n end if\n\n deallocate(b,u,v,s,work,rwork)\n return\n end subroutine\n\n subroutine matinv_lu_d(a,ainv)\n implicit none\n double precision,intent(inout) :: a(:,:)\n double precision,intent(out),optional :: ainv(size(a,2),size(a,1))\n character(len=*),parameter :: subnam='matinv_lu_d'\n double precision,allocatable :: work(:)\n double precision,dimension(:,:),pointer :: aa\n target :: a,ainv\n integer :: lwork,m,n,info\n integer,allocatable :: piv(:)\n m=size(a,1); n=size(a,2)\n if(m.ne.n)then\n write(*,*)subnam,': matrix not square: ',m,n\n stop\n end if \n if(present(ainv))then\n aa=>ainv; ainv=a\n else\n aa=>a\n end if\n\n lwork=64*n\n allocate(work(lwork),piv(n))\n call dgetrf(n,n,aa,n,piv,info)\n if(info.ne.0)then; write(*,*)subnam,': dgertf: info: ',info; stop; end if\n call dgetri(n,aa,n,piv,work,lwork,info)\n if(info.ne.0)then; write(*,*)subnam,': dgerti: info: ',info; stop; end if\n\n nullify(aa)\n deallocate(work,piv)\n return\n end subroutine\n subroutine matinv_lu_z(a,ainv)\n implicit none\n complex(8),intent(inout) :: a(:,:)\n complex(8),intent(out),optional :: ainv(size(a,2),size(a,1))\n character(len=*),parameter :: subnam='matinv_lu_z'\n complex(8),allocatable :: work(:)\n complex(8),dimension(:,:),pointer :: aa\n target :: a,ainv\n integer :: lwork,m,n,info\n integer,allocatable :: piv(:)\n m=size(a,1); n=size(a,2)\n if(m.ne.n)then\n write(*,*)subnam,': matrix not square: ',m,n\n stop\n end if \n if(present(ainv))then\n aa=>ainv; ainv=a\n else\n aa=>a\n end if\n\n lwork=64*n\n allocate(work(lwork),piv(n))\n call zgetrf(n,n,aa,n,piv,info)\n if(info.ne.0)then; write(*,*)subnam,': dgertf: info: ',info; stop; end if\n call zgetri(n,aa,n,piv,work,lwork,info)\n if(info.ne.0)then; write(*,*)subnam,': dgerti: info: ',info; stop; end if\n\n deallocate(work,piv)\n return\n end subroutine\n\n subroutine eye_d2(a)\n implicit none\n double precision,intent(out) :: a(:,:)\n integer :: m,n,i\n m=size(a,1); n=size(a,2)\n a=0.d0\n forall(i=1:min(m,n))a(i,i)=1.d0\n return\n end subroutine \n \n subroutine eye_d1(a,n)\n implicit none\n integer, intent(in) :: n\n real(8), intent(out) :: a(:)\n integer :: i\n a(1:n*n) = 0d0\n forall(i = 1:n) a(i+(i-1)*n) = 1d0\n end subroutine eye_d1\n \n subroutine eye_z1(a,n)\n implicit none\n integer, intent(in) :: n\n complex(8), intent(out) :: a(:)\n integer :: i\n a(1:n*n) = (0d0,0d0)\n forall(i = 1:n) a(i+(i-1)*n) = (1d0,0d0)\n end subroutine eye_z1\n\n\n\n subroutine eye_z2(a)\n implicit none\n complex(8),intent(out) :: a(:,:)\n integer :: m,n,i\n m=size(a,1); n=size(a,2)\n a=(0.d0,0.d0)\n forall(i=1:min(m,n))a(i,i)=(1.d0,0.d0)\n return\n end subroutine \n \n\n\n subroutine d2eye(n,a)\n implicit none\n integer,intent(in) :: n\n double precision,intent(out) :: a(n,n)\n integer :: i\n call dscal(n*n,0.d0,a,1)\n forall(i=1:n)a(i,i)=1.d0\n end subroutine \n \n subroutine z2eye(n,a)\n implicit none\n integer,intent(in) :: n\n complex(8),intent(out) :: a(n,n)\n integer :: i\n call zdscal(n*n,0.d0,a,1)\n forall(i=1:n)a(i,i)=(1.d0,0.d0)\n end subroutine \n\n subroutine laplace_d2(a)\n implicit none\n double precision,intent(out) :: a(:,:)\n integer :: m,n,i\n m=size(a,1); n=size(a,2)\n call dscal(m*n,0.d0,a,1)\n forall(i=1:min(m,n))a(i,i)=2.d0\n forall(i=1:min(m-1,n))a(i+1,i)=-1.d0\n forall(i=1:min(m,n-1))a(i,i+1)=-1.d0\n return\n end subroutine \n subroutine laplace_z2(a)\n implicit none\n double complex,intent(out) :: a(:,:)\n integer :: m,n,i\n m=size(a,1); n=size(a,2)\n call zdscal(m*n,0.d0,a,1)\n forall(i=1:min(m,n))a(i,i)=(2.d0,0.d0)\n forall(i=1:min(m-1,n))a(i+1,i)=-(1.d0,0.d0)\n forall(i=1:min(m,n-1))a(i,i+1)=-(1.d0,0.d0)\n return\n end subroutine \n \n subroutine d2submat(m,n,a,lda,b)\n implicit none\n integer,intent(in) :: m,n,lda\n double precision,intent(in) :: a(lda,n)\n double precision,intent(out) :: b(m,n)\n integer :: i,j\n if(m.gt.lda)then;write(*,*)'d2submat: lda,m: ',lda,m;stop;endif\n if(m.eq.lda)then;call dcopy(m*n,a,1,b,1);return;endif\n forall(i=1:m,j=1:n)b(i,j)=a(i,j)\n end subroutine\n subroutine z2submat(m,n,a,lda,b)\n implicit none\n integer,intent(in) :: m,n,lda\n complex(8),intent(in) :: a(lda,n)\n complex(8),intent(out) :: b(m,n)\n integer :: i,j\n if(m.gt.lda)then;write(*,*)'d2submat: lda,m: ',lda,m;stop;endif\n if(m.eq.lda)then;call zcopy(m*n,a,1,b,1);return;endif\n forall(i=1:m,j=1:n)b(i,j)=a(i,j)\n end subroutine\nend module \n", "meta": {"hexsha": "5c2201e848631d301356bc9bc824bf08981a0e3d", "size": 8726, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mat.f90", "max_stars_repo_name": "dimpase/tt-fort", "max_stars_repo_head_hexsha": "2feceda8df2f7c6c84a473759a9c502c3c5a3ded", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2017-12-07T12:51:46.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-02T11:27:41.000Z", "max_issues_repo_path": "mat.f90", "max_issues_repo_name": "dimpase/tt-fort", "max_issues_repo_head_hexsha": "2feceda8df2f7c6c84a473759a9c502c3c5a3ded", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-06-18T09:31:01.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-21T13:15:30.000Z", "max_forks_repo_path": "mat.f90", "max_forks_repo_name": "dimpase/tt-fort", "max_forks_repo_head_hexsha": "2feceda8df2f7c6c84a473759a9c502c3c5a3ded", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2015-03-30T10:53:25.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-21T03:58:11.000Z", "avg_line_length": 26.3625377644, "max_line_length": 75, "alphanum_fraction": 0.6214760486, "num_tokens": 3346, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357327, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.6774336724396581}} {"text": " SUBROUTINE MATRF2(M,N,C,INDEX,ALPHA,NN,NZ,A,SNR,RNR,FEJLM)\nC--------------------------------------------------------------------\nC\nC PURPOSE\nC -------\nC The subroutine generates sparse (rectangular or square) matrices.\nC The dimensions of the matrix and the average number of nonzero\nC elements per row can be specified by the user. Moreover, the user\nC can also change the sparsity pattern and the condition number of the\nC matrix. The non-zero elements of the desired matrix will be\nC accumulated (in an arbitrary order) in the first NZ positions of\nC array A. The column and the row numbers of the non-zero element\nC stored in A(I), I=1,...,NZ, will be found in SNR(I) and RNR(I),\nC respectively. The matrix generated by this subroutine is of the\nC class F(M,N,C,R,ALPHA) (see reference).\nC\nC Note: If A is the sparse matrix of type F(M,N,C,R,ALPHA), then\nC\nC min|A(i,j)| = 1/ALPHA,\nC\nC max|A(i,j)| = max(INDEX*N - N,10*ALPHA).\nC\nC\nC CONTRIBUTOR: Ernest E. Rothman\nC Cornell Theory Center/Cornell National Supercomputer\nC Facility.\nC e-mail address: BITNET: eer@cornellf\nC INTERNET: eer@cornellf.tn.cornell.edu\nC\nC minor modifications by Y. Saad. April 26, 1990.\nC\nC Note: This subroutine has been copied from the following reference.\nC The allowable array sizes have been changed.\nC\nC REFERENCE: Zlatev, Zahari; Schaumburg, Kjeld; Wasniewski, Jerzy;\nC \"A testing Scheme for Subroutines Solving Large Linear Problems\",\nC Computers and Chemistry, Vol. 5, No. 2-3, pp. 91-100, 1981.\nC\nC\nC INPUT PARAMETERS\nC ----------------\nC M - Integer. The number of rows in the desired matrix.\nC N < M+1 < 9000001 must be specified.\nC\nC N - Integer. The number of columns in the desired matrix.\nC 21 < N < 9000001 must be specified.\nC\nC C - Integer. The sparsity pattern can be changed by means of this\nC parameter. 10 < C < N-10 must be specified.\nC\nC INDEX - Integer. The average number of non-zero elements per row in\nC the matrix will be equal to INDEX.\nC 1 < INDEX < N-C-8 must be specified.\nC\nC ALPHA - Real. The condition number of the matrix can be changed\nC BY THIS PARAMETER. ALPHA > 0.0 MUST BE SPECIFIED.\nC If ALPHA is approximately equal to 1.0 then the generated\nC matrix is well-conditioned. Large values of ALPHA will\nC usually produce ill-conditioned matrices. Note that no\nC round-off errors during the computations in this subroutine\nC are made if ALPHA = 2**I (where I is an arbitrary integer\nC which produces numbers in the machine range).\nC\nC NN - Integer. The length of arrays A, RNR, and SNR (see below).\nC INDEX*M+109 < NN < 9000001 must be specified.\nC\nC\nC OUTPUT PARAMETERS\nC -----------------\nC NZ - Integer. The number of non-zero elements in the matrix.\nC\nC A(NN) - Real array. The non-zero elements of the matrix generated\nC are accumulated in the first NZ locations of array A.\nC\nC SNR(NN) - INTEGER array. The column number of the non-zero element\nC kept in A(I), I=1,...NZ, is stored in SNR(I).\nC\nC RNR(NN) - Integer array. The row number of the non-zero element\nC kept in A(I), I=1,...NZ, is stored in RNR(I).\nC\nC FEJLM - Integer. FEJLM=0 indicates that the call is successful.\nC Error diagnostics are given by means of positive values of\nC this parameter as follows:\nC FEJLM = 1 - N is out of range.\nC FEJLM = 2 - M is out of range.\nC FEJLM = 3 - C is out of range.\nC FEJLM = 4 - INDEX is out of range.\nC FEJLM = 5 - NN is out of range.\nC FEJLM = 7 - ALPHA is out of range.\nC\nC\nC\nC\n REAL*8 A, ALPHA, ALPHA1\n INTEGER M, N, NZ, C, NN, FEJLM, M1, NZ1, RR1, RR2, RR3, K\n INTEGER M2, N2\n INTEGER SNR, RNR\n DIMENSION A(NN), SNR(NN), RNR(NN)\n M1 = M\n FEJLM = 0\n NZ1 = INDEX*M + 110\n K = 1\n ALPHA1 = ALPHA\n INDEX1 = INDEX - 1\nC\nC Check the parameters.\nC\n IF(N.GE.22) GO TO 1\n2 FEJLM = 1\n RETURN\n1 IF(N.GT.9000000) GO TO 2\n IF(M.GE.N) GO TO 3\n4 FEJLM = 2\n RETURN\n3 IF(M.GT.9000000) GO TO 4\n IF(C.LT.11)GO TO 6\n IF(N-C.GE.11)GO TO 5\n6 FEJLM = 3\n RETURN\n5 IF(INDEX.LT.1) GO TO 12\n IF(N-C-INDEX.GE.9)GO TO 13\n12 FEJLM = 4\n13 IF(NN.GE.NZ1)GO TO 7\n8 FEJLM = 5\n RETURN\n7 IF(NN.GT.9000000)GO TO 8\n IF(ALPHA.GT.0.0)GO TO 9\n FEJLM = 6\n RETURN\n9 CONTINUE\nC\nC End of the error check. Begin to generate the non-zero elements of\nC the required matrix.\nC\n DO 20 I=1,N\n A(I) = 1.0d0\n SNR(I) = I\n20 RNR(I) = I\n NZ = N\n J1 = 1\n IF(INDEX1.EQ.0) GO TO 81\n DO 21 J = 1,INDEX1\n J1 = -J1\n DO 22 I=1,N\n A(NZ+I) = dfloat(J1*J*I)\n IF(I+C+J-1.LE.N)SNR(NZ+I) = I + C + J - 1\n IF(I+C+J-1.GT.N)SNR(NZ+I) = C + I + J - 1 - N\n22 RNR(NZ + I) = I\n21 NZ = NZ + N\n81 RR1 = 10\n RR2 = NZ\n RR3 = 1\n25 CONTINUE\n DO 26 I=1,RR1\n A(RR2 + I) = ALPHA*dfloat(I)\n SNR(RR2+I) = N - RR1 + I\n RNR(RR2+I) = RR3\n26 CONTINUE\n IF(RR1.EQ.1) GO TO 27\n RR2 = RR2 + RR1\n RR1 = RR1 - 1\n RR3 = RR3 + 1\n GO TO 25\n27 NZ = NZ + 55\n29 M1 = M1 - N\n ALPHA = 1.0d0/ALPHA\n IF(M1.LE.0) GO TO 28\n N2 = K*N\n IF(M1.GE.N)M2 = N\n IF(M1.LT.N)M2 = M1\n DO 30 I=1,M2\n A(NZ+I) = ALPHA*dfloat(K+1)\n SNR(NZ + I) = I\n30 RNR(NZ + I) = N2 + I\n NZ = NZ + M2\n IF(INDEX1.EQ.0) GO TO 82\n J1 = 1\n DO 41 J = 1,INDEX1\n J1 = -J1\n DO 42 I = 1,M2\n A(NZ+I) = ALPHA*dFLOAT(J*J1)*(dfloat((K+1)*I)+1.0d0)\n IF(I+C+J-1.LE.N)SNR(NZ+I) = I + C + J - 1\n IF(I+C+J-1.GT.N)SNR(NZ+I) = C + I + J - 1 - N\n42 RNR(NZ + I) = N2 + I\n41 NZ = NZ +M2\n82 K = K + 1\n GO TO 29\n28 CONTINUE\n ALPHA = 1.0d0/ALPHA1\n RR1 = 1\n RR2 = NZ\n35 CONTINUE\n DO 36 I = 1,RR1\n A(RR2+I) = ALPHA*dfloat(RR1+1-I)\n SNR(RR2+I) = I\n RNR(RR2+I) = N - 10 + RR1\n36 CONTINUE\n IF(RR1.EQ.10) GO TO 34\n RR2 = RR2 + RR1\n RR1 = RR1 + 1\n GO TO 35\n34 NZ = NZ + 55\n ALPHA = ALPHA1\n RETURN\n END\n SUBROUTINE DCN(AR,IA,JA,N,NE,IC,NN,IERR)\nC-----------------------------------------------------------------------\nC\nC PURPOSE\nC -------\nC The subroutine generates sparse (square) matrices of the type\nC D(N,C). This type of matrix has the following characteristics:\nC 1's in the diagonal, three bands at the distance C above the\nC diagonal (and reappearing cyclicly under it), and a 10 x 10\nC triangle of elements in the upper right-hand corner.\nC Different software libraries require different storage schemes.\nC This subroutine generates the matrix in the storage by\nC indices mode.\nC\nC\nC Note: If A is the sparse matrix of type D(N,C), then\nC\nC min|A(i,j)| = 1, max|A(i,j)| = max(1000,N + 1)\nC\nC\nC\nC CONTRIBUTOR: Ernest E. Rothman\nC Cornell Theory Center/Cornell National Supercomputer\nC Facility.\nC e-mail address: BITNET: eer@cornellf\nC INTERNET: eer@cornellf.tn.cornell.edu\nC\nC\nC REFERENCE\nC ---------\nC 1) Zlatev, Zahari; Schaumburg, Kjeld; Wasniewski, Jerzy;\nC \"A Testing Scheme for Subroutines Solving Large Linear Problems\",\nC Computers and Chemistry, Vol. 5, No. 2-3, pp. 91-100, 1981.\nC 2) Osterby, Ole and Zletev, Zahari;\nC \"Direct Methods for Sparse Matrices\";\nC Springer-Verlag 1983.\nC\nC\nC\nC INPUT PARAMETERS\nC ----------------\nC N - Integer. The size of the square matrix.\nC N > 13 must be specified.\nC\nC NN - Integer. The dimension of integer arrays IA and JA and \nC real array AR. Must be at least NE.\nC\nC IC - Integer. The sparsity pattern can be changed by means of this\nC parameter. 0 < IC < N-12 must be specified.\nC\nC\nC OUTPUT PARAMETERS\nC -----------------\nC NE - Integer. The number of nonzero elements in the sparse matrix\nC of the type D(N,C). NE = 4*N + 55.\nC\nC AR(NN) - Real array. (Double precision)\nC Stored entries of a sparse matrix to be generated by this\nC subroutine.\nC NN is greater then or equal to, NE, the number of\nC nonzeros including a mandatory diagonal entry for\nC each row. Entries are stored by indices.\nC\nC IA(NN) - Integer array.\nC Pointers to specify rows for the stored nonzero entries\nC in AR.\nC\nC JA(NN) - Integer array.\nC Pointers to specify columns for the stored nonzero entries\nC in AR.\nC\nC IERR - Error parameter is returned as zero on successful\nC execution of the subroutine.\nC Error diagnostics are given by means of positive values\nC of this parameter as follows:\nC IERR = 1 - N is out of range.\nC IERR = 2 - IC is out of range.\nC IERR = 3 - NN is out of range.\nC\nC----------------------------------------------------------------------\nC\n real*8 ar(nn)\n integer ia(nn), ja(nn), ierr\n ierr = 0\nc\nc\nc - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\nCheck the input parameters:\nc\n if(n.le.13)then\n ierr = 1\n return\n endif\n if(ic .le. 0 .or. ic .ge. n-12)then\n ierr = 2\n return\n endif\n ne = 4*n+55 \n if(nn.lt.ne)then\n ierr = 3\n return\n endif\nc\nc - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\nc\nc Begin to generate the nonzero elements as well as the row and column\nc pointers:\nc\n do 20 i=1,n\n ar(i) = 1.0d0\n ia(i) = i\n ja(i) = i\n20 continue\n ilast = n\n do 30 i=1,n-ic\n it = ilast + i\n ar(it) = 1.0 + dfloat(i)\n ia(it) = i\n ja(it) = i+ic\n30 continue\n ilast = ilast + n-ic\n do 40 i=1,n-ic-1\n it = ilast + i\n ar(it) = -dfloat(i)\n ia(it) = i\n ja(it) = i+ic+1\n40 continue\n ilast = ilast + n-ic-1\n do 50 i=1,n-ic-2\n it = ilast + i\n ar(it) = 16.0d0\n ia(it) = i\n ja(it) = i+ic+2\n50 continue\n ilast = ilast + n-ic-2\n icount = 0\n do 70 j=1,10\n do 60 i=1,11-j\n icount = icount + 1\n it = ilast + icount\n ar(it) = 100.0d0 * dfloat(j)\n ia(it) = i\n ja(it) = n-11+i+j\n60 continue\n70 continue\n icount = 0\n ilast = 55 + ilast\n do 80 i=n-ic+1,n\n icount = icount + 1\n it = ilast + icount\n ar(it) = 1.0d0 + dfloat(i)\n ia(it) = i\n ja(it) = i-n+ic\n80 continue\n ilast = ilast + ic\n icount = 0\n do 90 i=n-ic,n\n icount = icount + 1\n it = ilast + icount\n ar(it) = -dfloat(i)\n ia(it) = i\n ja(it) = i-n+ic+1\n90 continue\n ilast = ilast + ic + 1\n icount = 0\n do 100 i=n-ic-1,n\n icount = icount + 1\n it = ilast + icount\n ar(it) = 16.0d0\n ia(it) = i\n ja(it) = i-n+ic+2\n100 continue\nc ilast = ilast + ic + 2\nc if(ilast.ne.4*n+55) then\nc write(*,*)' ilast equal to ', ilast\nc write(*,*)' ILAST, the number of nonzeros, should = ', 4*n + 55\nc stop\nc end if\nc\nc - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n return\n end\n SUBROUTINE ECN(N,IC,NE,IA,JA,AR,NN,IERR)\nC----------------------------------------------------------------------\nC\nC PURPOSE\nC -------\nC The subroutine generates sparse (square) matrices of the type\nC E(N,C). This type of matrix has the following characteristics:\nC Symmetric, positive-definite, N x N matrices with 4 in the diagonal\nC and -1 in the two sidediagonal and in the two bands at the distance\nC C from the diagonal. These matrices are similar to matrices obtained\nC from using the five-point formula in the discretization of the\nC elliptic PDE.\nC\nC\nC Note: If A is the sparse matrix of type E(N,C), then\nC\nC min|A(i,j)| = 1, max|A(i,j)| = 4\nC\nC\nC\nC CONTRIBUTOR: Ernest E. Rothman\nC Cornell Theory Center/Cornell National Supercomputer\nC Facility.\nC e-mail address: BITNET: eer@cornellf\nC INTERNET: eer@cornellf.tn.cornell.edu\nC\nC\nC REFERENCE\nC ---------\nC 1) Zlatev, Zahari; Schaumburg, Kjeld; Wasniewski, Jerzy;\nC \"A Testing Scheme for Subroutines Solving Large Linear Problems\",\nC Computers and Chemistry, Vol. 5, No. 2-3, pp. 91-100, 1981.\nC 2) Osterby, Ole and Zletev, Zahari;\nC \"Direct Methods for Sparse Matrices\";\nC Springer-Verlag 1983.\nC\nC\nC\nC INPUT PARAMETERS\nC ----------------\nC N - Integer. The size of the square matrix.\nC N > 2 must be specified.\nC\nC NN - Integer. The dimension of integer arrays IA and JA and \nC real array AR. Must be at least NE.\nC\nC NN - Integer. The dimension of integer array JA. Must be at least\nC NE.\nC\nC IC - Integer. The sparsity pattern can be changed by means of this\nC parameter. 1 < IC < N must be specified.\nC\nC\nC\nC OUTPUT PARAMETERS\nC -----------------\nC NE - Integer. The number of nonzero elements in the sparse matrix\nC of the type E(N,C). NE = 5*N - 2*IC - 2 . \nC\nC AR(NN) - Real array.\nC Stored entries of the sparse matrix A.\nC NE is the number of nonzeros including a mandatory\nC diagonal entry for each row.\nC\nC IA(NN) - Integer array.(Double precision)\nC Pointers to specify rows for the stored nonzero entries\nC in AR.\nC\nC JA(NN) - Integer array.\nC Pointers to specify columns for the stored nonzero entries\nC in AR.\nC\nC IERR - Error parameter is returned as zero on successful\nC execution of the subroutine.\nC Error diagnostics are given by means of positive values\nC of this parameter as follows:\nC IERR = 1 - N is out of range.\nC IERR = 2 - IC is out of range.\nC IERR = 3 - NN is out of range.\nC\nC---------------------------------------------------------------------\nC\nC\n real*8 ar(nn)\n integer ia(nn), ja(nn), n, ne, ierr\n ierr = 0\nc\nc - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\nc\nCheck the input parameters:\nc\n if(n.le.2)then\n ierr = 1\n return\n endif\n if(ic.le.1.or.ic.ge.n)then\n ierr = 2\n return\n endif\nc\n ne = 5*n-2*ic-2 \n if(nn.lt.ne)then\n ierr = 3\n return\n endif\nc\nc - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\nc\nc Begin to generate the nonzero elements as well as the row and column\nc pointers:\nc\n do 20 i=1,n\n ar(i) = 4.0d0\n ia(i) = i\n ja(i) = i\n20 continue\n ilast = n\n do 30 i=1,n-1\n it = ilast + i\n ar(it) = -1.0d0\n ia(it) = i+1\n ja(it) = i\n30 continue\n ilast = ilast + n - 1\n do 40 i=1,n-1\n it = ilast + i\n ar(it) = -1.0d0\n ia(it) = i\n ja(it) = i+1\n40 continue\n ilast = ilast + n-1\n do 50 i=1,n-ic\n it = ilast + i\n ar(it) = -1.0d0\n ia(it) = i+ic\n ja(it) = i\n50 continue\n ilast = ilast + n-ic\n do 60 I=1,n-ic\n it = ilast + i\n ar(it) = -1.0d0\n ia(it) = i\n ja(it) = i+ic\n60 continue\nc ilast = ilast + n-ic\nc if(ilast.ne.5*n-2*ic-2) then\nc write(*,*)' ilast equal to ', ilast\nc write(*,*)' ILAST, the no. of nonzeros, should = ', 5*n-2*ic-2\nc stop\nc end if\nc\nc - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n return\n end\n\n", "meta": {"hexsha": "d20a7fd57d9fe358e08abf4dca4b7791aa13cf44", "size": 16078, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/latools/SPARSKIT2/MATGEN/MISC/zlatev.f", "max_stars_repo_name": "xywei/Mirana", "max_stars_repo_head_hexsha": "81d0ed67fad20cd3be8880ed672c12feff3c22c9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-03-11T15:22:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-22T16:26:18.000Z", "max_issues_repo_path": "src/latools/SPARSKIT2/MATGEN/MISC/zlatev.f", "max_issues_repo_name": "xywei/Mirana", "max_issues_repo_head_hexsha": "81d0ed67fad20cd3be8880ed672c12feff3c22c9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2021-06-30T20:39:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-15T12:42:50.000Z", "max_forks_repo_path": "src/latools/SPARSKIT2/MATGEN/MISC/zlatev.f", "max_forks_repo_name": "xywei/Mirana", "max_forks_repo_head_hexsha": "81d0ed67fad20cd3be8880ed672c12feff3c22c9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-03-13T17:09:10.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-22T00:30:19.000Z", "avg_line_length": 29.6095764273, "max_line_length": 72, "alphanum_fraction": 0.5332130862, "num_tokens": 5391, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6774036303554195}} {"text": "use ArrayClass\nuse IOClass\n\nreal(real64),allocatable :: x(:), fx(:),dfdx(:),I_f_dx(:)\ntype(IO_) :: f\n\nx = linspace([0.0d0,20.0d0],10000)\nfx = zeros(10000)\nfx = sin(x)\ndfdx = d_dx(x=x,fx=fx)\nI_f_dx = I_dx(x=x,fx=fx)\n\ncall f%open(\"fx.txt\")\ncall f%write(x,fx)\ncall f%close()\ncall f%plot()\n\n\ncall f%open(\"dfdx.txt\")\ncall f%write(x,dfdx)\ncall f%close()\ncall f%plot()\n\n\ncall f%open(\"I_f_dx.txt\")\ncall f%write(x,I_f_dx)\ncall f%close()\ncall f%plot()\n\n\n\n\n\nend", "meta": {"hexsha": "32af5424fe41742b5a0d1a51bdd27a6bbcdb39be", "size": 450, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/IntegralAndDerivativeCN.f90", "max_stars_repo_name": "kazulagi/faba", "max_stars_repo_head_hexsha": "7ef140f1ebea0e0ca496d14fdb94a3c024393cfa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-05T06:04:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:04:25.000Z", "max_issues_repo_path": "Tutorial/std/IntegralAndDerivativeCN.f90", "max_issues_repo_name": "kazulagi/plantFEM_binary", "max_issues_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Tutorial/std/IntegralAndDerivativeCN.f90", "max_forks_repo_name": "kazulagi/plantFEM_binary", "max_forks_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 13.2352941176, "max_line_length": 57, "alphanum_fraction": 0.6422222222, "num_tokens": 177, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8807970779778824, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.6774036302042891}} {"text": "MODULE nrtype\r\n!\tSymbolic names for kind types of 4-, 2-, and 1-byte integers:\r\n\tINTEGER, PARAMETER :: I4B = SELECTED_INT_KIND(9)\r\n\tINTEGER, PARAMETER :: I2B = SELECTED_INT_KIND(4)\r\n\tINTEGER, PARAMETER :: I1B = SELECTED_INT_KIND(2)\r\n!\tSymbolic names for kind types of single- and double-precision reals:\r\n\tINTEGER, PARAMETER :: SP = KIND(1.0)\r\n\tINTEGER, PARAMETER :: DP = KIND(1.0D0)\r\n!\tSymbolic names for kind types of single- and double-precision complex:\r\n\tINTEGER, PARAMETER :: SPC = KIND((1.0,1.0))\r\n\tINTEGER, PARAMETER :: DPC = KIND((1.0D0,1.0D0))\r\n!\tSymbolic name for kind type of default logical:\r\n\tINTEGER, PARAMETER :: LGT = KIND(.true.)\r\n!\tFrequently used mathematical constants (with precision to spare):\r\n\tREAL(DP), PARAMETER :: PI = 3.141592653589793238462643383279502884197_dp\r\n\tREAL(DP), PARAMETER :: TWOPI = 6.283185307179586476925286766559005768394_dp\r\n\tREAL(DP), PARAMETER :: ZERO = 0.0_dp\r\n\tREAL(DP), PARAMETER :: ONE = 1.0_dp\r\n REAL(DP), PARAMETER :: TWO = 2.0_dp\r\n REAL(DP), PARAMETER :: THREE = 3.0_dp\r\n REAL(DP), PARAMETER :: FOUR = 4.0_dp\r\n REAL(DP), PARAMETER :: FIVE = 5.0_dp\r\n REAL(DP), PARAMETER :: SIX = 6.0_dp\r\n REAL(DP), PARAMETER :: EIGHT = 8.0_dp\r\n REAL(DP), PARAMETER :: NINE = 9.0_dp\r\n REAL(DP), PARAMETER :: TEN = 10.0_dp\r\n REAL(DP), PARAMETER :: DOZEN = 12.0_dp\r\n REAL(DP), PARAMETER :: TWFOUR = 24.0_dp\r\n\r\n REAL(DP), PARAMETER :: HALF = 0.5_dp\r\n REAL(DP), PARAMETER :: ONEHALF = 1.5_dp\r\n REAL(DP), PARAMETER :: QUARTER = 0.25_dp\r\n REAL(DP), PARAMETER :: RAD_TO_DEGREES = 180.0_dp / PI\r\n REAL(DP), PARAMETER :: DEGREES_TO_RAD = PI / 180.0_dp\r\nEND MODULE nrtype\r\n", "meta": {"hexsha": "cf1dde4601925828679182c2e51b447b46bc795e", "size": 1708, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "nrtype.f90", "max_stars_repo_name": "skourno/dielectric_AMMF", "max_stars_repo_head_hexsha": "610ef5ac762f83b9272719c0f952fc01a0d9deb1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "nrtype.f90", "max_issues_repo_name": "skourno/dielectric_AMMF", "max_issues_repo_head_hexsha": "610ef5ac762f83b9272719c0f952fc01a0d9deb1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "nrtype.f90", "max_forks_repo_name": "skourno/dielectric_AMMF", "max_forks_repo_head_hexsha": "610ef5ac762f83b9272719c0f952fc01a0d9deb1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.4444444444, "max_line_length": 79, "alphanum_fraction": 0.6416861827, "num_tokens": 605, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970685907242, "lm_q2_score": 0.7690802264851919, "lm_q1q2_score": 0.6774036089992472}} {"text": "module types\n\n !! In this module we define so-called \"kind\"-parameters, which can be used\n !! to control the precision of the floating point reals in the program. \n !!\n !! Also we define the value of some constants\n !!\n !! ** Note: It is not necessary to alter in this module **\n \n ! Get \"kind\" parameters for single, double, and quad precision floating-point reals\n ! (ref: http://fortranwiki.org/fortran/show/Real+precision)\n integer, parameter :: &\n sp = kind(1.0), &\n dp = selected_real_kind(2*precision(1.0_sp)), &\n qp = selected_real_kind(2*precision(1.0_dp))\n ! \n ! Select working precision\n integer, parameter :: wp = dp\n \n ! Constants\n! real(wp), parameter :: pi = 4*atan(1.0_wp) ! Fortran 2003+\n real(wp), parameter :: pi = 3.14159265358979323848_wp ! Fortran 90/95\n \nend module types\n", "meta": {"hexsha": "73de9049ee38f8461486b2a663432ba8c0290d48", "size": 938, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/types.f90", "max_stars_repo_name": "Sebastian-dm/finite-element", "max_stars_repo_head_hexsha": "aba1e152b85e579d04e35bdcf50205ee2639dcf2", "max_stars_repo_licenses": ["MIT"], "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/types.f90", "max_issues_repo_name": "Sebastian-dm/finite-element", "max_issues_repo_head_hexsha": "aba1e152b85e579d04e35bdcf50205ee2639dcf2", "max_issues_repo_licenses": ["MIT"], "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/types.f90", "max_forks_repo_name": "Sebastian-dm/finite-element", "max_forks_repo_head_hexsha": "aba1e152b85e579d04e35bdcf50205ee2639dcf2", "max_forks_repo_licenses": ["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.52, "max_line_length": 87, "alphanum_fraction": 0.5938166311, "num_tokens": 246, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673087708699, "lm_q2_score": 0.8333246015211009, "lm_q1q2_score": 0.6773823261710148}} {"text": "include 'header.h'\nprogram fft_lc\n use dyn_lc\n use rand_fun\n implicit none\n\n integer :: i\n real :: sum, mean \n real , allocatable :: datah(:), re(:), im(:)\n \n character (len = 200) :: filename \n\n filename = '/Users/gullo/Work/BHB_project/CygX1_Ole/fft_test_lc.txt'\n open(10, file = filename)\n\n dim_lc = 8\n allocate(lc(dim_lc))\n\n do i = 1, dim_lc\n read(10,*) lc(i)\n enddo\n\n write(*,*) '-----------------------------------'\n sum = 0.0\n do i = 1, dim_lc\n write(*,*) lc(i)\n sum = sum + lc(i)\n enddo\n mean = sum / real(dim_lc)\n write(*,*) 'sum of the time series', sum \n write(*,*) 'mean of the time series', mean \n write(*,*) '-----------------------------------'\n \n \n ! allocate(datah(2 * dim_lc))\n ! do i = 1, dim_lc\n ! datah(2 * i - 1) = lc(i)\n ! datah(2 * i) = 0.0\n ! end do\n\n ! call four1(datah, dim_lc, 1)\n ! do i = 1, dim_lc\n ! write(*,*) i, datah(2 * i - 1), datah(2 * i)\n ! enddo\n\n allocate(re(dim_lc / 2))\n allocate(im(dim_lc / 2))\n call FT_not_fast(lc, re, im, dim_lc)\n\n do i = 1, dim_lc / 2\n write(*,*) i, re(i), im(i)\n enddo\n \n ! call periodogram_frac_rms(lc, pds, dim_lc)\n\n \n \nend program fft_lc\n", "meta": {"hexsha": "4f6b1fd8bf04a64567c7e0f794fd368d0ab3c0d7", "size": 1211, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "main_lc.f90", "max_stars_repo_name": "mgullik/data_analysis", "max_stars_repo_head_hexsha": "b91ae014bfa280ba7e7fa3a48600b18eeb74eafe", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "main_lc.f90", "max_issues_repo_name": "mgullik/data_analysis", "max_issues_repo_head_hexsha": "b91ae014bfa280ba7e7fa3a48600b18eeb74eafe", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "main_lc.f90", "max_forks_repo_name": "mgullik/data_analysis", "max_forks_repo_head_hexsha": "b91ae014bfa280ba7e7fa3a48600b18eeb74eafe", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.5254237288, "max_line_length": 70, "alphanum_fraction": 0.5086705202, "num_tokens": 434, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007394, "lm_q2_score": 0.78793120560257, "lm_q1q2_score": 0.6773559010179793}} {"text": " double precision function randlc(x, a)\n\nc---------------------------------------------------------------------\nc\nc This routine returns a uniform pseudorandom double precision number in the\nc range (0, 1) by using the linear congruential generator\nc\nc x_{k+1} = a x_k (mod 2^46)\nc\nc where 0 < x_k < 2^46 and 0 < a < 2^46. This scheme generates 2^44 numbers\nc before repeating. The argument A is the same as 'a' in the above formula,\nc and X is the same as x_0. A and X must be odd double precision integers\nc in the range (1, 2^46). The returned value RANDLC is normalized to be\nc between 0 and 1, i.e. RANDLC = 2^(-46) * x_1. X is updated to contain\nc the new seed x_1, so that subsequent calls to RANDLC using the same\nc arguments will generate a continuous sequence.\n\n implicit none\n double precision x, a\n integer*8 Lx, La, a1, a2, x1, x2, xa\n double precision d2m46\n parameter(d2m46=0.5d0**46)\n\n Lx = x\n La = A\n a1 = ibits(La, 23, 23)\n a2 = ibits(La, 0, 23)\n x1 = ibits(Lx, 23, 23)\n x2 = ibits(Lx, 0, 23)\n xa = ishft(ibits(a1*x2+a2*x1, 0, 23), 23) + a2*x2\n Lx = ibits(xa,0, 46)\n x = dble(Lx)\n randlc = d2m46*x\n return\n end\n\n\nc---------------------------------------------------------------------\nc---------------------------------------------------------------------\n\n\n SUBROUTINE VRANLC (N, X, A, Y)\n implicit none\n integer n, i\n double precision x, a, y(*)\n integer*8 Lx, La, a1, a2, x1, x2, xa\n double precision d2m46\n parameter(d2m46=0.5d0**46)\n\n Lx = X\n La = A\n a1 = ibits(La, 23, 23)\n a2 = ibits(La, 0, 23)\n do i = 1, N\n x1 = ibits(Lx, 23, 23)\n x2 = ibits(Lx, 0, 23)\n xa = ishft(ibits(a1*x2+a2*x1, 0, 23), 23) + a2*x2\n Lx = ibits(xa,0, 46)\n y(i) = d2m46*dble(Lx)\n end do\n x = dble(Lx)\n return\n end\n\n", "meta": {"hexsha": "f725b6a1fb95d8dfb007900416b0a3184013bde6", "size": 1954, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/NPB3.1/common/randi8_safe.f", "max_stars_repo_name": "brugger1/testsuite", "max_stars_repo_head_hexsha": "9b504db668cdeaf7c561f15b76c95d05bfdd1517", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 144, "max_stars_repo_stars_event_min_datetime": "2015-01-16T01:53:24.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-27T21:59:09.000Z", "max_issues_repo_path": "validation_tests/NPB3.1/common/randi8_safe.f", "max_issues_repo_name": "brugger1/testsuite", "max_issues_repo_head_hexsha": "9b504db668cdeaf7c561f15b76c95d05bfdd1517", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 79, "max_issues_repo_issues_event_min_datetime": "2015-01-01T00:32:30.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-06T12:26:08.000Z", "max_forks_repo_path": "validation_tests/NPB3.1/common/randi8_safe.f", "max_forks_repo_name": "brugger1/testsuite", "max_forks_repo_head_hexsha": "9b504db668cdeaf7c561f15b76c95d05bfdd1517", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 53, "max_forks_repo_forks_event_min_datetime": "2015-02-02T17:55:46.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-08T09:35:16.000Z", "avg_line_length": 30.0615384615, "max_line_length": 78, "alphanum_fraction": 0.5081883316, "num_tokens": 685, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007393, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.6773558924560072}} {"text": "program main\n implicit none\n integer :: clock, n\n integer, allocatable :: seed(:)\n integer(4) :: i, n_tot = 100000000\n real(8), parameter :: l = 0.d0, r = 1.d0, b = 0.d0, t = 1.d0\n real(8) :: x, y, z, H\n real(8) :: integral = 0.d0\n\n call SYSTEM_CLOCK(clock)\n call RANDOM_SEED(size = n)\n allocate(seed(n))\n do i = 1, n\n seed(i) = clock + 37 * i\n end do\n call RANDOM_SEED(put = seed)\n do i = 1, n_tot\n call RANDOM_NUMBER(x)\n x = x * (r - l) + l\n call RANDOM_NUMBER(y)\n y = y * (t - b) + b\n call func(x, y, z)\n call inArea(x, y, H)\n integral = integral + z * H\n end do\n integral = (r - l) * (t - b) / n_tot * integral\n write(*,'(f10.5)') integral\nend program main\n\nsubroutine func(x, y, z)\n ! the function to be integrated\n implicit none\n real(8), intent(in) :: x, y\n real(8), intent(out) :: z\n\n z = x * y\nend subroutine func\n\nsubroutine inArea(x, y, H)\n ! judge whether the dot is in the integral area\n real(8), intent(in) :: x, y\n real(8), intent(out) :: H\n\n H = 1.d0\nend subroutine inArea\n", "meta": {"hexsha": "e78ffd76fe31c1f5b33fc1e6a6c7cd9c45071bf6", "size": 1123, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Week-11-Assignment-3/Exercises/sample-mean-high-dim.f90", "max_stars_repo_name": "Chen-Jialin/Computational-Physics-Exercises-and-Assignments", "max_stars_repo_head_hexsha": "592407af2e999b539473f473ca99186a12418b99", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-04-15T10:30:01.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T08:22:51.000Z", "max_issues_repo_path": "Week-11-Assignment-3/Exercises/sample-mean-high-dim.f90", "max_issues_repo_name": "Chen-Jialin/Computational-Physics-Exercises-and-Assignments", "max_issues_repo_head_hexsha": "592407af2e999b539473f473ca99186a12418b99", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Week-11-Assignment-3/Exercises/sample-mean-high-dim.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": 24.4130434783, "max_line_length": 64, "alphanum_fraction": 0.5396260018, "num_tokens": 388, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190939, "lm_q2_score": 0.7879312031126512, "lm_q1q2_score": 0.677355887545739}} {"text": "!!# FUNCTION MODULE <>\nMODULE FUN_xyAREA\n\n\n!!## PURPOSE\n!! Calculate the unsigned AREA of various shapes.\n\n\n!!## DETAILS\n!! The current shapes supported are\n!! @ ellipse \n!! @ slices \n\n\n!!## DEPENDENCIES\nUSE FUN_xySAREA !!((03-A-FUN_xySAREA.f90))\n\n\n\n!!## DEFAULT IMPLICIT\nIMPLICIT NONE\n\n\n!!## DEFAULT ACCESS\nPRIVATE\n\n\n!!## PROCEDURE OVERLOADING\nINTERFACE xyAREA_El\n MODULE PROCEDURE xyAREA_El_Rsp\n MODULE PROCEDURE xyAREA_El_Rdp\nEND INTERFACE\nINTERFACE xyAREA_Sli\n MODULE PROCEDURE xyAREA_Sli_Rsp\n MODULE PROCEDURE xyAREA_Sli_Rdp\nEND INTERFACE\n\n\n!!## PUBLIC ACCESS LIST\nPUBLIC :: xyAREA_El\nPUBLIC :: xyAREA_El_Rsp\nPUBLIC :: xyAREA_El_Rdp\nPUBLIC :: xyAREA_Sli\nPUBLIC :: xyAREA_Sli_Rsp\nPUBLIC :: xyAREA_Sli_Rdp\n\n\n!!## MODULE PROCEDURES\nCONTAINS\n\n\n\n!!### FUNCTION <>\nFUNCTION xyAREA_El_Rsp( El ) RESULT(AREA)\n\n!!#### LOCAL MAPPINGS\nUSE KND_IntrinsicTypes,ONLY: KIND_R=>KIND_Rsp !!((01-A-KND_IntrinsicTypes.f90))\nUSE PAR_Constants_Rsp ,ONLY: c_PI !!((02-A-PAR_Constants_Rsp.f90))\n\nINCLUDE \"04-B-FUN_xyAREA_El.f90.hdr\"\n!!--begin--\nINCLUDE \"04-B-FUN_xyAREA_El.f90.bdy\"\n!!--end--\nEND FUNCTION\n\n\n\n!!### FUNCTION <>\nFUNCTION xyAREA_El_Rdp( El ) RESULT(AREA)\n\n!!#### LOCAL MAPPINGS\nUSE KND_IntrinsicTypes,ONLY: KIND_R=>KIND_Rdp !!((01-A-KND_IntrinsicTypes.f90))\nUSE PAR_Constants_Rdp ,ONLY: c_PI !!((02-A-PAR_Constants_Rdp.f90))\n\nINCLUDE \"04-B-FUN_xyAREA_El.f90.hdr\"\n!!--begin--\nINCLUDE \"04-B-FUN_xyAREA_El.f90.bdy\"\n!!--end--\nEND FUNCTION\n\n\n\n\n\n!!### FUNCTION <>\nFUNCTION xyAREA_Sli_Rsp( N , Sli ) RESULT(AREA)\n\n!!#### LOCAL MAPPINGS\nUSE KND_IntrinsicTypes,ONLY: KIND_R=>KIND_Rsp !!((01-A-KND_IntrinsicTypes.f90))\nUSE PAR_Constants_Rsp ,ONLY: c_PI !!((02-A-PAR_Constants_Rsp.f90))\n\nINCLUDE \"04-B-FUN_xyAREA_Sli.f90.hdr\"\n!!--begin--\nINCLUDE \"04-B-FUN_xyAREA_Sli.f90.bdy\"\n!!--end--\nEND FUNCTION\n\n\n\n!!### FUNCTION <>\nFUNCTION xyAREA_Sli_Rdp( N , Sli ) RESULT(AREA)\n\n!!#### LOCAL MAPPINGS\nUSE KND_IntrinsicTypes,ONLY: KIND_R=>KIND_Rdp !!((01-A-KND_IntrinsicTypes.f90))\nUSE PAR_Constants_Rdp ,ONLY: c_PI !!((02-A-PAR_Constants_Rdp.f90))\n\nINCLUDE \"04-B-FUN_xyAREA_Sli.f90.hdr\"\n!!--begin--\nINCLUDE \"04-B-FUN_xyAREA_Sli.f90.bdy\"\n!!--end--\nEND FUNCTION\n\n\n\nEND MODULE\n", "meta": {"hexsha": "bcb1ad262b2c199d12c332e048d6fd615d209e41", "size": 2308, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/04-B-FUN_xyAREA.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/04-B-FUN_xyAREA.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/04-B-FUN_xyAREA.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": 19.8965517241, "max_line_length": 79, "alphanum_fraction": 0.7045060659, "num_tokens": 738, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637541053281, "lm_q2_score": 0.787931185683219, "lm_q1q2_score": 0.6773558810610983}} {"text": "! cooling_Dalgarno.f90 $Id: 96606cd7f07380a2be60ac88d2c80a5209c1785f $\n!***********************************************************************\nFUNCTION cooling_Dalgarno (self, temp)\n!\n! Fit to cooling profile, merged between Dalgarno & McCray(1972)\n! for low temp, and Raymond, Cox & Smith(1976) for high temp.\n! C4/H4 corrected relative to sncool.pro to make it smooth at T=1e5.\n\n implicit none\n class(cooling_t):: self\n real(kind=dp) cooling_Dalgarno, temp, qq \n real(kind=dp), parameter:: &\n TE1=10.0, &\n TE2=2000.0, &\n TE3=8000.0, &\n TE4=2.5e4, &\n TE5=1.0e5, &\n TE6=2.5e5, &\n TE7=4.0e5, &\n TE8=4.5e7, &\n C1=2.0, &\n C2=1.5, &\n C3=5.0, &\n C4=0.83, &\n C5=0.0, &\n C6=-2.54, &\n C7=-0.49, &\n C8=0.5, &\n H1=8.00e15, &\n H2=3.58e17, &\n H3=7.79e03, &\n H4=1.70e22, &\n H5=2.38e26, &\n H6=1.22e20, &\n H7=4.00e28, &\n H8=1.07e21\n\n if (temp .le. T_MC) then\n qq=0.\n else if (temp .le. TE2) then\n qq=H1*temp**C1\n else if (temp .le. TE3) then\n qq=H2*temp**C2\n else if (temp .le. TE4) then\n qq=H3*temp**C3\n else if (temp .le. TE5) then\n qq=H4*temp**C4\n else if (temp .le. TE6) then\n qq=H5*temp**C5\n else if (temp .le. TE7) then\n qq=H6*temp**C6*1e20\n else if (temp .le. TE8) then\n qq=H7*temp**C7\n else\n qq=H8*temp**C8\n end if\n cooling_Dalgarno=qq*4e-28\nEND FUNCTION\n", "meta": {"hexsha": "96606cd7f07380a2be60ac88d2c80a5209c1785f", "size": 1409, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "extras/cooling/simple/cooling_Dalgarno.f90", "max_stars_repo_name": "applejwjcat/dispatch", "max_stars_repo_head_hexsha": "4fad06ee952de181f6c51b91f179d6396bdfb333", "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": "extras/cooling/simple/cooling_Dalgarno.f90", "max_issues_repo_name": "applejwjcat/dispatch", "max_issues_repo_head_hexsha": "4fad06ee952de181f6c51b91f179d6396bdfb333", "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": "extras/cooling/simple/cooling_Dalgarno.f90", "max_forks_repo_name": "applejwjcat/dispatch", "max_forks_repo_head_hexsha": "4fad06ee952de181f6c51b91f179d6396bdfb333", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.8813559322, "max_line_length": 72, "alphanum_fraction": 0.5344215756, "num_tokens": 617, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191284552528, "lm_q2_score": 0.7090191276365462, "lm_q1q2_score": 0.677339535071849}} {"text": "! As the derivative of the object function is not available, the optimiser must need only\n! evaluations of the function to be minimized. this makes selection of an algorithm simpler,\n! although potential benefits of methods that use the derivative are not available.\n! The downhill simplex method is robust but potentially slow. Given that the optimization of this\n! particular object function does not involve lots of variables it is unlikely a faster or more complicated\n! (i.e. direction set method or PSO) algorithm is needed. It is short and self-contained.\n\nMODULE DownhillSimplex\n\n IMPLICIT NONE\n\n PRIVATE\n PUBLIC :: RunNelderMead\n\n NAMELIST /opt/ c_reflect, c_expand, c_contract, c_shrink, threshold, maxSteps\n REAL(8) :: c_reflect, c_expand, c_contract, c_shrink, threshold\n INTEGER :: maxSteps\n\n CONTAINS\n\n!*\n\n ! needs to take an object function as an argument to pass to the nelder-mead optimizer\n ! right now is just importing a fixed object function from module ObjectFunctions\n SUBROUTINE RunNelderMead(guess,lambda,logUnit,printDetails)\n\n ! #DES: Driver for Nelder-Mead optimizer, checks sanity of input, creates guess and informs the log.\n ! guess is the point around which the simplex should be built\n ! lambda is the characteristic length scale in each dimension\n IMPLICIT NONE\n\n REAL(8), INTENT(IN) :: guess(:), lambda(:)\n INTEGER, INTENT(IN) :: logUnit\n LOGICAL, INTENT(IN) :: printDetails\n REAL(8) :: simplex(SIZE(guess)+1,SIZE(guess))\n REAL(8) :: optimum(SIZE(guess)), optValue\n LOGICAL :: converged = .FALSE.\n INTEGER :: i\n\n WRITE(logUnit,'(A)') \"* Initializing Nelder-Mead Downhill Simplex *\"\n WRITE(logUnit,*)\n WRITE(logUnit,'(A24,I6)') \"Parameter Space Size = \", SIZE(guess)\n WRITE(logUnit,'(A24,I6)') \"Points in Simplex = \", SIZE(guess) + 1\n\n CALL ProcessNameList(logUnit)\n CALL GenerateSimplex(guess,lambda,logUnit,simplex)\n CALL NelderMead(simplex,logUnit,printDetails,optimum,optValue,converged)\n\n IF (converged .EQV. .TRUE.) THEN\n WRITE(logUnit,'(A)') \"Downhill Simplex Converged\"\n ELSE\n WRITE(logUnit,'(A)') \"Downhill Simplex Not Converged\"\n ENDIF\n\n WRITE(logUnit,'(A,F15.8,A)',ADVANCE=\"NO\") \"Best value located = \", optValue, \" at:\"\n DO i = 1, SIZE(optimum)\n WRITE(logUnit,'(F15.8,1X)',ADVANCE='NO') optimum(i)\n ENDDO\n WRITE(logUnit,*)\n WRITE(logUnit,*)\n\n END SUBROUTINE RunNelderMead\n\n!*\n\n SUBROUTINE GenerateSimplex(guess,lambda,logUnit,simplex)\n\n USE EVBParameters, ONLY : objectFunction\n IMPLICIT NONE\n\n REAL(8), INTENT(IN) :: guess(:), lambda(:)\n INTEGER, INTENT(IN) :: logUnit\n REAL(8), INTENT(OUT) :: simplex(SIZE(guess)+1,SIZE(guess))\n REAL(8) :: functionValues(SIZE(simplex,1)+1) ! object function evaluated at each point\n INTEGER :: m, n, i\n\n n = SIZE(guess)\n m = n + 1\n\n !generate a simplex from the input point - should be done in own routine/function\n simplex(:,:) = 0.0d0\n functionValues(:) = 0.0d0\n simplex(1,:) = guess(:)\n functionValues(1) = objectFunction(simplex(1,:))\n\n DO i = 2, m\n simplex(i,:) = guess(:)\n simplex(i,i-1) = simplex(i,i-1) + lambda(i-1)\n functionValues(i) = objectFunction(simplex(i,:))\n ENDDO\n\n WRITE(logUnit,'(A16)') \"Initial simplex:\"\n CALL WriteSimplex(simplex,functionValues,logUnit)\n\n END SUBROUTINE GenerateSimplex\n\n!*\n\n SUBROUTINE NelderMead(initialSimplex,logUnit,debug,optimum,optValue,converged)\n\n USE EVBParameters, ONLY : objectFunction\n IMPLICIT NONE\n\n REAL(8), INTENT(IN) :: initialSimplex(:,:) ! m x n, each row is an n-dimensional vector\n INTEGER, INTENT(IN) :: logUnit\n LOGICAL, INTENT(IN) :: debug\n REAL(8), INTENT(OUT) :: optimum(SIZE(initialSimplex,2))\n REAL(8), INTENT(OUT) :: optValue\n LOGICAL, INTENT(OUT) :: converged\n\n REAL(8) :: simplex(SIZE(initialSimplex,1),SIZE(initialSimplex,2))\n REAL(8) :: functionValues(SIZE(initialSimplex,1)+1) ! object function evaluated at each point\n INTEGER :: step, n, m, i\n REAL(8) :: f_reflect, f_expand, f_contract\n REAL(8) :: reflectedPoint(SIZE(initialSimplex,2)), expandedPoint(SIZE(initialSimplex,2))\n REAL(8) :: contractedPoint(SIZE(initialSimplex,2)), centroidPoint(SIZE(initialSimplex,2))\n\n converged = .FALSE.\n optimum(:) = 0.0d0\n optValue = 0.0d0\n simplex(:,:) = initialSimplex(:,:)\n n = SIZE(simplex,2)\n m = n + 1\n\n DO i = 1, m\n functionValues(i) = objectFunction(simplex(i,:))\n ENDDO\n\n !repeat until convergence or excessive compute time\n DO step = 1, maxSteps\n\n CALL BubbleSort(simplex,functionValues) ! sort ascending (f(x1) smallest, f(n+1) largest)\n IF (debug .EQV. .TRUE.) WRITE(logUnit,'(A5,I0.4,A8,F10.4)') \"STEP \", step, \" f(x) = \", functionValues(1)\n\n IF (functionValues(1) < threshold) THEN ! convergence test\n\n converged = .TRUE.\n optimum(:) = simplex(1,:)\n optValue = functionValues(1)\n RETURN\n\n ENDIF\n\n centroidPoint(:) = centroid(simplex(1:n,:))\n\n !reflect\n reflectedPoint(:) = centroidPoint(:) + (c_reflect * (centroidPoint(:)-simplex(m,:)))\n f_reflect = objectFunction(reflectedPoint)\n\n IF ((f_reflect >= functionValues(1)) .AND. (f_reflect < functionValues(n))) THEN\n\n IF (debug .EQV. .TRUE.) WRITE(logUnit,*) \"REFLECTING\"\n simplex(m,:) = reflectedPoint(:)\n functionValues(m) = f_reflect\n CYCLE\n\n ELSE IF (f_reflect < functionValues(1)) THEN\n\n !expand\n expandedPoint(:) = centroidPoint(:) + (c_expand * (reflectedPoint(:) - centroidPoint(:)))\n f_expand = objectFunction(expandedPoint)\n IF (f_expand < f_reflect) THEN\n IF (debug .EQV. .TRUE.) WRITE(logUnit,*) \"EXPANDING\"\n simplex(m,:) = expandedPoint(:)\n functionValues(m) = f_expand\n ELSE\n IF (debug .EQV. .TRUE.) WRITE(logUnit,*) \"REFLECTING\"\n simplex(m,:) = reflectedPoint(:)\n functionValues(m) = f_reflect\n ENDIF\n CYCLE\n\n ELSE\n !contract\n contractedPoint(:) = centroidPoint(:) + (c_contract * (simplex(m,:) - centroidPoint(:)))\n f_contract = objectFunction(contractedPoint)\n IF (f_contract < functionValues(m)) THEN\n IF (debug .EQV. .TRUE.) WRITE(logUnit,*) \"CONTRACTING\"\n simplex(m,:) = contractedPoint(:)\n functionValues(m) = f_contract\n CYCLE\n ELSE\n !shrink\n IF (debug .EQV. .TRUE.) WRITE(logUnit,*) \"SHRINKING\"\n DO i = 2, m\n simplex(i,:) = simplex(1,:) + c_shrink * (simplex(i,:) - simplex(1,:))\n ENDDO\n ENDIF\n\n ENDIF\n\n ENDDO\n\n ! If optimization fails, return best value located\n optimum(:) = simplex(1,:)\n optValue = functionValues(1)\n RETURN\n\nEND SUBROUTINE NelderMead\n\n!*\n\n SUBROUTINE BubbleSort(simplex,functionValues)\n\n ! #DES: Basic bubble sort algorithm, can be replaced if necessary.\n\n IMPLICIT NONE\n REAL(8) :: simplex(:,:), functionValues(:)\n reaL(8) :: f_temp, x_temp(SIZE(simplex,2))\n INTEGER :: i, j, m\n\n m = SIZE(simplex,1)\n DO i = 1, m !loop over vectors\n DO j = m, i+1, -1\n IF (functionValues(j-1) > functionValues(j)) THEN\n\n f_temp = functionValues(j-1)\n functionValues(j-1) = functionValues(j)\n functionValues(j) = f_temp\n\n x_temp(:) = simplex(j-1,:)\n simplex(j-1,:) = simplex(j,:)\n simplex(j,:) = x_temp(:)\n\n ENDIF\n ENDDO\n ENDDO \n \n END SUBROUTINE BubbleSort\n\n!*\n\n FUNCTION centroid(input)\n\n IMPLICIT NONE\n REAL(8), INTENT(IN) :: input(:,:) !each row a vector\n REAL(8) :: centroid(SIZE(input,2))\n INTEGER :: i, j, m, n\n\n m = SIZE(input,1)\n n = SIZE(input,2)\n\n centroid(:) = 0.0d0\n DO i = 1, m\n DO j = 1, n\n centroid(j) = centroid(j) + input(i,j)\n ENDDO\n ENDDO\n\n centroid(:) = centroid(:) / SIZE(input,2)\n\n END FUNCTION centroid\n\n!*\n\n SUBROUTINE WriteSimplex(simplex,functionValues,unit)\n\n ! #DES: Write the provided simplex coords/values to unit.\n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: unit\n REAL(8), INTENT(IN) :: simplex(:,:), functionValues(:)\n INTEGER :: i, j\n\n DO i = 1, SIZE(simplex,1)\n WRITE(unit,'(I0.3,1X)',ADVANCE='NO') i\n DO j = 1, SIZE(simplex,2)\n WRITE(unit,'(F10.3,1X)',ADVANCE='NO') simplex(i,j)\n ENDDO\n WRITE(unit,'(F10.3)') functionValues(i)\n ENDDO\n WRITE(unit,*)\n\n END SUBROUTINE WriteSimplex\n\n!*\n\n SUBROUTINE ProcessNameList(logUnit)\n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: logUnit\n\n CALL ReadNameList(logUnit)\n CALL CheckNameList()\n CALL PrintNameList(logUnit)\n\n END SUBROUTINE ProcessNameList\n\n!*\n\n SUBROUTINE ReadNameList(logUnit)\n\n ! #DES: Open, read and close the namelist file opt.nml\n\n USE FileIO, ONLY : OpenFile, CloseFile\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: logUnit\n INTEGER, PARAMETER :: nmlUnit = 20\n LOGICAL :: fileRead\n\n CALL OpenFile(nmlUnit,\"opt.nml\",\"read\",success=fileRead)\n\n !standard algorithm parameter values\n c_reflect = 1.0d0\n c_expand = 2.0d0\n c_contract = 0.5d0\n c_shrink = 0.5d0\n threshold = 1.0d-10\n maxSteps = 100\n\n IF (fileRead .EQV. .TRUE.) THEN\n WRITE(logUnit,'(A)') \"Optimization parameters will be read from opt.nml\"\n READ(nmlUnit,NML=opt)\n CALL CloseFile(nmlUnit)\n ELSE\n WRITE(logUnit,'(A)') \"Namelist opt.nml could not be read - default optimization parameters will be used\"\n ENDIF\n\n END SUBROUTINE ReadNameList\n\n!*\n\n SUBROUTINE CheckNameList()\n\n ! There must be additional constraints on these values - expand > 1, 0 < contract < 1 CHECK \n\n IMPLICIT NONE\n\n IF (threshold < 0.0d0) STOP \"Illegal (-ve) value of threshold in DownhillSimplex:CheckNameList\"\n IF (c_reflect < 0.0d0) STOP \"Illegal (-ve) value of c_reflect in DownhillSimplex:CheckNameList\"\n IF (c_expand < 0.0d0) STOP \"Illegal (-ve) value of c_expand in DownhillSimplex:CheckNameList\"\n IF (c_contract < 0.0d0) STOP \"Illegal (-ve) value of c_contract in DownhillSimplex:CheckNameList\"\n IF (c_shrink < 0.0d0) STOP \"Illegal (-ve) value of c_shrink in DownhillSimplex:CheckNameList\"\n IF (maxSteps < 1) STOP \"Illegal (-ve) value of maxSteps in DownhillSimplex:CheckNameList\"\n\n END SUBROUTINE CheckNameList\n\n!*\n\n SUBROUTINE PrintNameList(logUnit)\n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: logUnit\n\n WRITE(logUnit,'(A)') \"* Optimization Parameters *\"\n WRITE(logUnit,*) \"\"\n WRITE(logUnit,'(A,F6.2)') \"Reflection Coefficient (alpha) = \", c_reflect\n WRITE(logUnit,'(A,F6.2)') \"Expansion Coefficient (beta) = \", c_expand\n WRITE(logUnit,'(A,F6.2)') \"Contraction Coefficient (gamma) = \", c_contract\n WRITE(logUnit,'(A,F6.2)') \"Shrinking Coefficient (sigma) = \", c_shrink\n WRITE(logUnit,'(A,F6.2)') \"Convergence Threshold = \", threshold\n WRITE(logUnit,'(A,I6)') \"Maximum Steps = \", maxSteps\n WRITE(logUnit,*)\n\n END SUBROUTINE PrintNameList\n\nEND MODULE DownhillSimplex\n\n\n\n\n\n! SUBROUTINE WriteVector(input,unit)\n! ! #DES: Print a vector to a single line on the provided unit.\n! IMPLICIT NONE\n! INTEGER, INTENT(IN) :: unit\n! REAL(8), INTENT(IN) :: input(:)\n! INTEGER :: i\n! DO i = 1, SIZE(input)\n! WRITE(unit,'(F6.2)',ADVANCE='NO') input(i)\n! ENDDO\n! WRITE(unit,*)\n! END SUBROUTINE WriteVector\n\n", "meta": {"hexsha": "6c3c156dbd74028dbe967fb47e0497c84718e98d", "size": 11487, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "DownhillSimplex.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": "DownhillSimplex.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": "DownhillSimplex.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": 30.632, "max_line_length": 110, "alphanum_fraction": 0.6374162096, "num_tokens": 3429, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424528443251, "lm_q2_score": 0.8006919949619793, "lm_q1q2_score": 0.6773393501909528}} {"text": "C Copyright (C) 2002, 2004, 2005, 2006 Carnegie Mellon University and others.\nC All Rights Reserved.\nC This code is published under the Common Public License.\nC\nC $Id: hs071_f.f.in 661 2006-03-12 23:19:03Z andreasw $\nC\nC =============================================================================\nC\nC This is an example for the usage of IPOPT.\nC It implements problem 71 from the Hock-Schittkowsky test suite:\nC\nC min x1*x4*(x1 + x2 + x3) + x3\nC s.t. x1*x2*x3*x4 >= 25\nC x1**2 + x2**2 + x3**2 + x4**2 = 40\nC 1 <= x1,x2,x3,x4 <= 5\nC\nC Starting point:\nC x = (1, 5, 5, 1)\nC\nC Optimal solution:\nC x = (1.00000000, 4.74299963, 3.82114998, 1.37940829)\nC\nC =============================================================================\nC\nC\nC =============================================================================\nC\nC Main driver program\nC\nC =============================================================================\nC\n program example\nC\n implicit none\nC\nC include the Ipopt return codes\nC\n include 'IpReturnCodes.inc'\nC\nC Size of the problem (number of variables and equality constraints)\nC\n integer N, M, NELE_JAC, NELE_HESS, IDX_STY\n parameter (N = 4, M = 2, NELE_JAC = 8, NELE_HESS = 10)\n parameter (IDX_STY = 1 )\nC\nC Space for multipliers and constraints\nC\n double precision LAM(M)\n double precision G(M)\nC\nC Vector of variables\nC\n double precision X(N)\nC\nC Vector of lower and upper bounds\nC\n double precision X_L(N), X_U(N), Z_L(N), Z_U(N)\n double precision G_L(M), G_U(M)\nC\nC Private data for evaluation routines\nC This could be used to pass double precision and integer arrays untouched\nC to the evaluation subroutines EVAL_*\nC\n double precision DAT(2)\n integer IDAT(1)\nC\nC Place for storing the Ipopt Problem Handle\nC\nC for 32 bit platforms\n integer IPROBLEM\n integer IPCREATE\nCC for 64 bit platforms:\nC integer*8 IPROBLEM\nC integer*8 IPCREATE\nC\n integer IERR\n integer IPSOLVE, IPADDSTROPTION\n integer IPADDNUMOPTION, IPADDINTOPTION\n integer IPOPENOUTPUTFILE\nC\n double precision f\n integer i\nC\nC Set initial point and bounds:\nC\n data X / 1d0, 5d0, 5d0, 1d0/\n data X_L / 1d0, 1d0, 1d0, 1d0 /\n data X_U / 5d0, 5d0, 5d0, 5d0 /\nC\nC Set bounds for the constraints\nC\n data G_L / 25d0, 40d0 /\n data G_U / 1d40, 40d0 /\nC\nC The following are the Fortran routines for computing the model\nC functions and their derivatives - their code can be found furhter\nC down in this file.\nC\n external EV_F, EV_G, EV_GRAD_F, EV_JAC_G, EV_HESS\nC\nC First create a handle for the Ipopt problem (and read the options\nC file)\nC\n IPROBLEM = IPCREATE(N, X_L, X_U, M, G_L, G_U, NELE_JAC, NELE_HESS,\n 1 IDX_STY, EV_F, EV_G, EV_GRAD_F, EV_JAC_G, EV_HESS)\n if (IPROBLEM.eq.0) then\n write(*,*) 'Error creating an Ipopt Problem handle.'\n stop\n endif\nC\nC Open an output file\nC\n IERR = IPOPENOUTPUTFILE(IPROBLEM, 'IPOPT.OUT', 5)\n if (IERR.ne.0 ) then\n write(*,*) 'Error opening the Ipopt output file.'\n goto 9000\n endif\nC\nC Note: The following options are only examples, they might not be\nC suitable for your optimization problem.\nC\nC Set a string option\nC\n IERR = IPADDSTROPTION(IPROBLEM, 'mu_strategy', 'adaptive')\n if (IERR.ne.0 ) goto 9990\nC\nC Set an integer option\nC\n IERR = IPADDINTOPTION(IPROBLEM, 'max_iter', 3000)\n if (IERR.ne.0 ) goto 9990\nC\nC Set a double precision option\nC\n IERR = IPADDNUMOPTION(IPROBLEM, 'tol', 1.d-7)\n if (IERR.ne.0 ) goto 9990\nC\nC As a simple example, we pass the constants in the constraints to\nC the EVAL_C routine via the \"private\" DAT array.\nC\n DAT(1) = 0.d0\n DAT(2) = 0.d0\nC\nC Call optimization routine\nC\n IERR = IPSOLVE(IPROBLEM, X, G, F, LAM, Z_L, Z_U, IDAT, DAT)\nC\nC Output:\nC\n if( IERR.eq.IP_SOLVE_SUCCEEDED ) then\n write(*,*)\n write(*,*) 'The solution was found.'\n write(*,*)\n write(*,*) 'The final value of the objective function is ',f\n write(*,*)\n write(*,*) 'The optimal values of X are:'\n write(*,*)\n do i = 1, N\n write(*,*) 'X (',i,') = ',X(i)\n enddo\n write(*,*)\n write(*,*) 'The multipliers for the lower bounds are:'\n write(*,*)\n do i = 1, N\n write(*,*) 'Z_L(',i,') = ',Z_L(i)\n enddo\n write(*,*)\n write(*,*) 'The multipliers for the upper bounds are:'\n write(*,*)\n do i = 1, N\n write(*,*) 'Z_U(',i,') = ',Z_U(i)\n enddo\n write(*,*)\n write(*,*) 'The multipliers for the equality constraints are:'\n write(*,*)\n do i = 1, M\n write(*,*) 'LAM(',i,') = ',LAM(i)\n enddo\n write(*,*)\n else\n write(*,*)\n write(*,*) 'An error occoured.'\n write(*,*) 'The error code is ',IERR\n write(*,*)\n endif\nC\n 9000 continue\nC\nC Clean up\nC\n call IPFREE(IPROBLEM)\n stop\nC\n 9990 continue\n write(*,*) 'Error setting an option'\n goto 9000\n end\nC\nC =============================================================================\nC\nC Computation of objective function\nC\nC =============================================================================\nC\n subroutine EV_F(N, X, NEW_X, F, IDAT, DAT, IERR)\n implicit none\n integer N, NEW_X\n double precision F, X(N)\n double precision DAT(*)\n integer IDAT(*)\n integer IERR\n F = X(1)*X(4)*(X(1)+X(2)+X(3)) + X(3)\n IERR = 0\n return\n end\nC\nC =============================================================================\nC\nC Computation of gradient of objective function\nC\nC =============================================================================\nC\n subroutine EV_GRAD_F(N, X, NEW_X, GRAD, IDAT, DAT, IERR)\n implicit none\n integer N, NEW_X\n double precision GRAD(N), X(N)\n double precision DAT(*)\n integer IDAT(*)\n integer IERR\n GRAD(1) = X(4)*(2d0*X(1)+X(2)+X(3))\n GRAD(2) = X(1)*X(4)\n GRAD(3) = X(1)*X(4) + 1d0\n GRAD(4) = X(1)*(X(1)+X(2)+X(3))\n IERR = 0\n return\n end\nC\nC =============================================================================\nC\nC Computation of equality constraints\nC\nC =============================================================================\nC\n subroutine EV_G(N, X, NEW_X, M, G, IDAT, DAT, IERR)\n implicit none\n integer N, NEW_X, M\n double precision G(M), X(N)\n double precision DAT(*)\n integer IDAT(*)\n integer IERR\n G(1) = X(1)*X(2)*X(3)*X(4) - DAT(1)\n G(2) = X(1)**2 + X(2)**2 + X(3)**2 + X(4)**2 - DAT(2)\n IERR = 0\n return\n end\nC\nC =============================================================================\nC\nC Computation of Jacobian of equality constraints\nC\nC =============================================================================\nC\n subroutine EV_JAC_G(TASK, N, X, NEW_X, M, NZ, ACON, AVAR, A,\n 1 IDAT, DAT, IERR)\n integer TASK, N, NEW_X, M, NZ\n double precision X(N), A(NZ)\n integer ACON(NZ), AVAR(NZ), I\n double precision DAT(*)\n integer IDAT(*)\n integer IERR\nC\nC structure of Jacobian:\nC\n integer AVAR1(8), ACON1(8)\n data AVAR1 /1, 2, 3, 4, 1, 2, 3, 4/\n data ACON1 /1, 1, 1, 1, 2, 2, 2, 2/\n save AVAR1, ACON1\nC\n if( TASK.eq.0 ) then\n do I = 1, 8\n AVAR(I) = AVAR1(I)\n ACON(I) = ACON1(I)\n enddo\n else\n A(1) = X(2)*X(3)*X(4)\n A(2) = X(1)*X(3)*X(4)\n A(3) = X(1)*X(2)*X(4)\n A(4) = X(1)*X(2)*X(3)\n A(5) = 2d0*X(1)\n A(6) = 2d0*X(2)\n A(7) = 2d0*X(3)\n A(8) = 2d0*X(4)\n endif\n IERR = 0\n return\n end\nC\nC =============================================================================\nC\nC Computation of Hessian of Lagrangian\nC\nC =============================================================================\nC\n subroutine EV_HESS(TASK, N, X, NEW_X, OBJFACT, M, LAM, NEW_LAM,\n 1 NNZH, IRNH, ICNH, HESS, IDAT, DAT, IERR)\n implicit none\n integer TASK, N, NEW_X, M, NEW_LAM, NNZH, i\n double precision X(N), OBJFACT, LAM(M), HESS(NNZH)\n integer IRNH(NNZH), ICNH(NNZH)\n double precision DAT(*)\n integer IDAT(*)\n integer IERR\nC\nC structure of Hessian:\nC\n integer IRNH1(10), ICNH1(10)\n data IRNH1 /1, 2, 2, 3, 3, 3, 4, 4, 4, 4/\n data ICNH1 /1, 1, 2, 1, 2, 3, 1, 2, 3, 4/\n save IRNH1, ICNH1\n\n if( TASK.eq.0 ) then\n do i = 1, 10\n IRNH(i) = IRNH1(i)\n ICNH(i) = ICNH1(i)\n enddo\n else\n do i = 1, 10\n HESS(i) = 0d0\n enddo\nC\nC objective function\nC\n HESS(1) = OBJFACT * 2d0*X(4)\n HESS(2) = OBJFACT * X(4)\n HESS(4) = OBJFACT * X(4)\n HESS(7) = OBJFACT * (2d0*X(1) + X(2) + X(3))\n HESS(8) = OBJFACT * X(1)\n HESS(9) = OBJFACT * X(1)\nC\nC first constraint\nC\n HESS(2) = HESS(2) + LAM(1) * X(3)*X(4)\n HESS(4) = HESS(4) + LAM(1) * X(2)*X(4)\n HESS(5) = HESS(5) + LAM(1) * X(1)*X(4)\n HESS(7) = HESS(7) + LAM(1) * X(2)*X(3)\n HESS(8) = HESS(8) + LAM(1) * X(1)*X(3)\n HESS(9) = HESS(9) + LAM(1) * X(1)*X(2)\nC\nC second constraint\nC\n HESS(1) = HESS(1) + LAM(2) * 2d0\n HESS(3) = HESS(3) + LAM(2) * 2d0\n HESS(6) = HESS(6) + LAM(2) * 2d0\n HESS(10)= HESS(10)+ LAM(2) * 2d0\n endif\n IERR = 0\n return\n end\n", "meta": {"hexsha": "31cff3dd59814654094a4c376c141def96be276c", "size": 9950, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Ipopt-3.2.1/Ipopt/Windows/VisualStudio_dotNET/hs071_f/hs071_f.f", "max_stars_repo_name": "FredericLiu/CarND-MPC-P5", "max_stars_repo_head_hexsha": "e4c68920edd0468ae73357864dde6d61bc1c4205", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Ipopt-3.2.1/Ipopt/Windows/VisualStudio_dotNET/hs071_f/hs071_f.f", "max_issues_repo_name": "FredericLiu/CarND-MPC-P5", "max_issues_repo_head_hexsha": "e4c68920edd0468ae73357864dde6d61bc1c4205", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Ipopt-3.2.1/Ipopt/Windows/VisualStudio_dotNET/hs071_f/hs071_f.f", "max_forks_repo_name": "FredericLiu/CarND-MPC-P5", "max_forks_repo_head_hexsha": "e4c68920edd0468ae73357864dde6d61bc1c4205", "max_forks_repo_licenses": ["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.7932960894, "max_line_length": 79, "alphanum_fraction": 0.4769849246, "num_tokens": 3266, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424295406088, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.6773393355551418}} {"text": " real*8 function thetaq(iwhere) \n character*100 id,revision,revdate\n data id/'$RCSfile: thetaq.f,v $'/\n data revision/'$Revision: 1.3 $'/\n data revdate/'$Date: 1994/03/12 17:59:03 $'/\n real*8 factor\n real*8 tl,tsat,ppow,tpow,alph,fq,theta,pfac\n integer iwhere\n \nc \n include \"const.h\"\n include \"sendit.h\"\nc \n if(iwhere.eq.1) then \n alph=cpd+(cw*qtota) \n tpow=rd/alph \n factor=dexp(qsa*lv/(tea*alph)) \n thetaq=tea*((1000./pda)**tpow)*factor \n else \n alph=cpd+(cw*qtota) \n tl=tsat(pda,tea,qtota) \n tpow=con2*fq(qtota) \n theta=tea*((1000./pda)**tpow) \n ppow=1./tpow \n pfac=(theta/tl)**ppow \n factor=(pfac**(-1.12*qtota))*dexp(qtota*lv/(tl*alph)) \n thetaq=factor*theta \n end if \nc \n return \n end \n\n\n\n\n", "meta": {"hexsha": "7e5707eeca001b6b9c9b45807065f0b363d4ff4e", "size": 1692, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/thetaq.f", "max_stars_repo_name": "phaustin/empm", "max_stars_repo_head_hexsha": "13bbb7c6568e374c973ea570b064f34a48c6cd8e", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/thetaq.f", "max_issues_repo_name": "phaustin/empm", "max_issues_repo_head_hexsha": "13bbb7c6568e374c973ea570b064f34a48c6cd8e", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/thetaq.f", "max_forks_repo_name": "phaustin/empm", "max_forks_repo_head_hexsha": "13bbb7c6568e374c973ea570b064f34a48c6cd8e", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2015-08-24T14:59:46.000Z", "max_forks_repo_forks_event_max_datetime": "2015-08-24T14:59:46.000Z", "avg_line_length": 47.0, "max_line_length": 79, "alphanum_fraction": 0.2718676123, "num_tokens": 325, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951680216529, "lm_q2_score": 0.7248702880639791, "lm_q1q2_score": 0.6773152946094457}} {"text": "\tFUNCTION PR_TMCK ( tmpc )\nC************************************************************************\nC* PR_TMCK\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes TMPK from TMPC. The following equation is\t*\nC* used:\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* TMPK = TMPC + TMCK\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PR_TMCK ( 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\t\tTemperature in Celsius\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPR_TMCK\t\tREAL\t\tTemperature in Kelvin\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* M. Goodman/RDS\t 3/84\tOriginal source code\t\t\t*\nC* G. Huffman/GSC\t 8/88\tModified documentation\t\t\t*\nC* G. Krueger/EAI 4/96 Replaced C->K constant with TMCK\t*\nC************************************************************************\n INCLUDE 'GEMPRM.PRM'\n INCLUDE 'ERMISS.FNC'\nC------------------------------------------------------------------------\n\tIF ( ERMISS ( tmpc ) ) THEN\n\t PR_TMCK = RMISSD\n\t ELSE\n\t PR_TMCK = tmpc + TMCK\n\tEND IF\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "020f5fa05049f4e6cc4ed320759789319ab3e745", "size": 1019, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/pr/prtmck.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/prtmck.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/prtmck.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.9705882353, "max_line_length": 73, "alphanum_fraction": 0.4190382728, "num_tokens": 297, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476793890012, "lm_q2_score": 0.7718435083355187, "lm_q1q2_score": 0.6772747670790698}} {"text": "! =============================================================================\n! Test ellipse reflection\n!\n! This unit test checks the reflection of parcels which is\n! applied after splitting to ensure the centres of the child\n! parcels are within the domain.\n! =============================================================================\nprogram test_ellipse_reflection\n use unit_test\n use constants, only : pi, zero, one, two, three, four, f12, f14\n use parcel_container\n use parcel_bc, only : apply_reflective_bc\n use parcel_ellipse, only : get_ab, get_angle\n use parameters, only : update_parameters, lower, dx, vcell, extent, nx, nz\n implicit none\n\n integer :: iter\n double precision :: angle, ab, B11, B12, error, a2, b2\n\n nx = 10\n nz = 10\n extent = (/one, one/)\n lower = (/zero, zero/)\n\n call update_parameters\n\n n_parcels = 1\n call parcel_alloc(1)\n\n error = zero\n\n parcels%volume(1) = f14 * vcell\n\n ab = get_ab(parcels%volume(1))\n a2 = four * ab\n b2 = f14 * ab\n\n do iter = 0, 360\n angle = dble(iter) * pi / 180.0d0\n\n !\n ! lower boundary check\n !\n\n parcels%position(:, 1) = (/f12, - f12 * dx(2)/)\n B11 = a2 * dcos(angle) ** 2 + b2 * dsin(angle) ** 2\n B12 = f12 * (a2 - b2) * dsin(two * angle)\n parcels%B(1, 1) = B11\n parcels%B(2, 1) = B12\n\n call apply_reflective_bc(parcels%position(:, 1), parcels%B(:, 1))\n\n call check_result('lower')\n\n !\n ! upper boundary check\n !\n\n angle = dble(iter) * pi / 180.0d0\n\n parcels%position(:, 1) = (/f12, one + f12 * dx(2)/)\n B11 = a2 * dcos(angle) ** 2 + b2 * dsin(angle) ** 2\n B12 = f12 * (a2 - b2) * dsin(two * angle)\n parcels%B(1, 1) = B11\n parcels%B(2, 1) = B12\n\n call apply_reflective_bc(parcels%position(:, 1), parcels%B(:, 1))\n\n call check_result('upper')\n enddo\n\n call print_result_dp('Test ellipse reflection', error, atol=1.0e-14)\n\n call parcel_dealloc\n\n\n contains\n\n subroutine check_result(bc)\n character(*), intent(in) :: bc\n\n ! get_angle computes the angle in the first and fourth quadrant, i.e.,\n ! -pi/2 <= get_angle <= pi/2\n if (angle > pi / two .and. angle <= three * pi / two) then\n angle = angle - pi\n else if (angle > three * pi / two) then\n angle = angle - two * pi\n endif\n\n error = max(error, abs(parcels%B(1, 1) - B11))\n error = max(error, abs(parcels%B(2, 1) + B12))\n error = max(error, abs(angle + get_angle(parcels%B(1, 1), parcels%B(2, 1), &\n parcels%volume(1))))\n error = max(error, abs(f12 - parcels%position(1, 1)))\n\n if (bc == 'lower') then\n error = max(error, abs(f12 * dx(2) - parcels%position(2, 1)))\n else\n error = max(error, abs(one - f12 * dx(2) - parcels%position(2, 1)))\n endif\n end subroutine check_result\n\n\nend program test_ellipse_reflection\n", "meta": {"hexsha": "d35d56a99b9bf76b78aa352c34a1fd81f8e961e4", "size": 3174, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "unit-tests/2d/test_ellipse_reflection.f90", "max_stars_repo_name": "matt-frey/epic", "max_stars_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2021-11-11T10:50:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T00:11:41.000Z", "max_issues_repo_path": "unit-tests/2d/test_ellipse_reflection.f90", "max_issues_repo_name": "matt-frey/epic", "max_issues_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 47, "max_issues_repo_issues_event_min_datetime": "2021-11-12T17:09:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-24T16:50:58.000Z", "max_forks_repo_path": "unit-tests/2d/test_ellipse_reflection.f90", "max_forks_repo_name": "matt-frey/epic", "max_forks_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.2285714286, "max_line_length": 88, "alphanum_fraction": 0.5097668557, "num_tokens": 894, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774768002981829, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6772747628147887}} {"text": "!---------------------------------------------------------------------- \n!---------------------------------------------------------------------- \n! chu : Chua's circuit\n!---------------------------------------------------------------------- \n!---------------------------------------------------------------------- \n\n SUBROUTINE FUNC(NDIM,U,ICP,PAR,IJAC,F,DFDU,DFDP) \n! ---------- ---- \n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: NDIM, ICP(*), IJAC\n DOUBLE PRECISION, INTENT(IN) :: U(NDIM), PAR(*)\n DOUBLE PRECISION, INTENT(OUT) :: F(NDIM)\n DOUBLE PRECISION, INTENT(INOUT) :: DFDU(NDIM,NDIM), DFDP(NDIM,*)\n\n DOUBLE PRECISION ab,h,pi,alpha,beta,RK,a0,a1,x,y,z\n\n ab(x)=2*x*DATAN(RK*x)/pi\n h(x)=a1*x + 0.5*(a0-a1) * ( ab(x+1) - ab(x-1) ) \n\n pi=4*DATAN(1.d0)\n alpha=PAR(1)\n beta =PAR(2)\n RK =PAR(3)\n a0 =PAR(4)\n a1 =PAR(5) \n\n x=U(1)\n y=U(2)\n z=U(3) \n\n F(1)= alpha * ( y - h(x) )\n F(2)= x - y + z\n F(3)= -beta * y\n\n END SUBROUTINE FUNC\n\n SUBROUTINE STPNT(NDIM,U,PAR,T)\n! ---------- ----- \n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: NDIM\n DOUBLE PRECISION, INTENT(INOUT) :: U(NDIM),PAR(*)\n DOUBLE PRECISION, INTENT(IN) :: T\n\n PAR(1)=-1\n PAR(2)= 14.3 \n PAR(3)= 10.\n PAR(4)= -1./7.\n PAR(5)= 2./7.\n\n U(1)=0.\n U(2)=0.\n U(3)=0.\n\n END SUBROUTINE STPNT\n\n SUBROUTINE BCND \n END SUBROUTINE BCND\n\n SUBROUTINE ICND \n END SUBROUTINE ICND\n\n SUBROUTINE FOPT \n END SUBROUTINE FOPT\n\n SUBROUTINE PVLS\n END SUBROUTINE PVLS\n", "meta": {"hexsha": "5069f7f9f7957a7c03e0a28566a5d9ea3ef37e79", "size": 1671, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "07p/demos/chu/chu.f90", "max_stars_repo_name": "st970703/AUTO07P-Update-to-Python-3.0", "max_stars_repo_head_hexsha": "fb2d2aebf2127fa914064d01ed62c0acb5f6421c", "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": "07p/demos/chu/chu.f90", "max_issues_repo_name": "st970703/AUTO07P-Update-to-Python-3.0", "max_issues_repo_head_hexsha": "fb2d2aebf2127fa914064d01ed62c0acb5f6421c", "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": "07p/demos/chu/chu.f90", "max_forks_repo_name": "st970703/AUTO07P-Update-to-Python-3.0", "max_forks_repo_head_hexsha": "fb2d2aebf2127fa914064d01ed62c0acb5f6421c", "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.2173913043, "max_line_length": 72, "alphanum_fraction": 0.3931777379, "num_tokens": 529, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767970940975, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6772747603417363}} {"text": "program euler_056\n use EulerCommon\n integer(int64), dimension(200) :: ab\n integer(int64) :: a,b, s, max_s ,max_a, max_b\n \n max_s = 0\n do a=90,99\n do b=90,99\n call powers(a,b,ab)\n s = sum(ab)\n if (s > max_s) then\n max_s = s\n max_a = a\n max_b = b\n end if\n end do\n end do\n print *,max_a, max_b, max_s\n \ncontains\n subroutine powers(a,b,ab)\n integer(int64), intent(in) :: a,b\n integer(int64), intent(out) :: ab(200)\n integer(int64) :: i, max_n\n \n ab(:) = 0\n ab(1) = a\n max_n = max(200_int64,b*int(log10(real(a)),int64)+3_int64)\n call checkTensInArray(max_n,ab)\n do i=2,b\n ab(:) = ab(:)*a\n call checkTensInArray(max_n,ab)\n end do !- i\n end subroutine powers\n\nend program euler_056\n", "meta": {"hexsha": "c29e94e2b624fdcbe71d21281d6616cab46181c0", "size": 838, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "euler_056.f90", "max_stars_repo_name": "kylekanos/ProjectEuler", "max_stars_repo_head_hexsha": "bfdbda0a9a83af45b92c47439f657d11df785527", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-05-13T03:36:23.000Z", "max_stars_repo_stars_event_max_datetime": "2016-05-13T03:36:23.000Z", "max_issues_repo_path": "euler_056.f90", "max_issues_repo_name": "kylekanos/ProjectEuler", "max_issues_repo_head_hexsha": "bfdbda0a9a83af45b92c47439f657d11df785527", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "euler_056.f90", "max_forks_repo_name": "kylekanos/ProjectEuler", "max_forks_repo_head_hexsha": "bfdbda0a9a83af45b92c47439f657d11df785527", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.6486486486, "max_line_length": 64, "alphanum_fraction": 0.5286396181, "num_tokens": 276, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476800298183, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6772747582095956}} {"text": "!projection on the simplex splace\n! update project method on 2019-Aug-3: based on the paper\n! Fast projection onto the simplex and the l1 ball\n! Laurent Condat, 2016\n subroutine simplex_projection(x,z,d,n)\n implicit none\n integer,intent(in)::n\n real*8,parameter::project_eps = 0.0\n real*8,intent(in)::d\n integer,dimension(n)::isSelect\n real*8,dimension(n),intent(in)::z\n real*8,dimension(n),intent(out)::x\n real*8::pivot\n real*8:: sum_k,get_sum\n real*8,dimension(n)::tempz\n integer::i,now,pre,counter\n logical st,loop\n real*8 dnor\n integer,dimension(n)::set_i\n x=0.0\n pivot=(sum(z)-d)/n\n loop = .true.\n isSelect = 1\n counter = 0\n do while(loop)\n pre = sum(isSelect)\n isSelect = 0\n tempz=0\n do i=1,n\n if(z(i)>pivot+project_eps) then \n isSelect(i) = 1\n tempz(i) = z(i)\n end if\n end do\n pivot = (sum(tempz)-1+(n-sum(isSelect))*project_eps)/sum(isSelect)\n if (sum(isSelect).eq.pre) then \n loop = .false.\n else\n loop = .true.\n end if\n counter=counter+1\n if (counter>100) then \n write(*,*) \"Warning: the projection method and can not get of loop\"\n pause\n end if \n end do \n do i =1, n\n x(i) = max(z(i)-pivot,project_eps)\n end do\n return \n\n! do i=1,n\n! !\tx(i)=z(i)+(d-sum(z(:)))/(n*1.0)\n! x(i)=z(i)+(d-get_sum(z(1:n),n))/(n*1.0)\n! end do \n\t\t\n! 10\tset_i=0\n! st=.true.\n! sum_k=0.0\n! do i=1,n\n! !if (x(i)>0.0) then\n! if (x(i) > project_eps) then\n! set_i(i) = 1\n! sum_k = sum_k + x(i)\n! endif \n! !if (x(i)<0.0) then \n! if (x(i) < project_eps) then \n! st =.false.\n! sum_k = sum_k + project_eps\n! end if \n! end do\n! if (st) then\n! return\n! end if \n! dnor = (sum(set_i(:))*1d0)\n! do i = 1,n\n! if (set_i(i)==0) then \n! !x(i)=0.0\n! x(i) = project_eps\n! else if (set_i(i) == 1) then \n! x(i) = x(i) + (d-sum_k)/dnor\n! end if \n! end do \n! go to 10 \n\n end subroutine\n\n\n\n\t\treal*8 function get_sum(x,n)\n\t\timplicit none \n\t\tinteger n\n\t\treal*8 x(n)\n\t\tinteger i\n\t\tget_sum=0.0\n\t\tdo i=1,n\n\t\t\tget_sum=get_sum+x(i)\n\t\tend do \n\t\treturn \n\t\tend \n", "meta": {"hexsha": "11be02f880f5e8ef1493f1abded8508654b5d746", "size": 2403, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "RTND/RTND/genetic_simplexprojection.f90", "max_stars_repo_name": "hkujy/BTNDP", "max_stars_repo_head_hexsha": "06a1555c4a32b91d315649a0abf7378a86aa59f8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "RTND/RTND/genetic_simplexprojection.f90", "max_issues_repo_name": "hkujy/BTNDP", "max_issues_repo_head_hexsha": "06a1555c4a32b91d315649a0abf7378a86aa59f8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2019-12-09T18:51:54.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-08T20:34:12.000Z", "max_forks_repo_path": "RTND/RTND/genetic_simplexprojection.f90", "max_forks_repo_name": "hkujy/BTNDP", "max_forks_repo_head_hexsha": "06a1555c4a32b91d315649a0abf7378a86aa59f8", "max_forks_repo_licenses": ["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.7920792079, "max_line_length": 80, "alphanum_fraction": 0.4989596338, "num_tokens": 810, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767938900121, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6772747578686837}} {"text": "!*****************************************************************************************\n!>\n! Test of the object-oriented interface.\n\nprogram root_tests_oo\n\n use root_module, wp => root_module_rk\n use iso_fortran_env, only: output_unit\n\n implicit none\n\n real(wp) :: root,ax,bx,xzero,fzero,error\n integer :: iflag\n character(len=1000) :: line\n\n real(wp),parameter :: ftol = 1.0e-15_wp\n real(wp),parameter :: rtol = 1.0e-13_wp\n real(wp),parameter :: atol = 1.0e-16_wp\n integer,parameter :: maxiter = 1000\n\n character(len=*),parameter :: fmt = '(A25, 1X,A25, 1X,A25, 1X,A5,1X,A5)' !! format for header\n character(len=*),parameter :: dfmt = '(E25.10,1X,E25.10,1X,E25.6,1X,I5,1X,I5)' !! format for results\n\n type,extends(muller_solver) :: my_solver\n integer :: ifunc = 0\n integer :: n = 1\n end type my_solver\n type(my_solver) :: solver\n\n ! case 19\n ax = 0.0_wp\n bx = 1.0_wp\n root = 0.22370545765466_wp\n\n call solver%initialize(f,ftol,rtol,atol,maxiter); solver%n = 3\n call solver%solve(ax,bx,xzero,fzero,iflag)\n\n error = xzero-root\n\n write(output_unit,fmt) repeat('-',25),repeat('-',25),repeat('-',25),repeat('-',5),repeat('-',5)\n write(output_unit,fmt) 'error','x','f','evals','iflag'\n write(output_unit,fmt) repeat('-',25),repeat('-',25),repeat('-',25),repeat('-',5),repeat('-',5)\n\n write(line, dfmt) error,xzero,fzero,solver%ifunc,iflag\n write(output_unit, '(A)') trim(line)\n\n contains\n\n function f(me,x)\n\n !! function to find the root of.\n\n class(root_solver),intent(inout) :: me\n real(wp),intent(in) :: x\n real(wp) :: f\n\n real(wp) :: dn\n\n select type(me)\n class is (my_solver)\n\n me%ifunc = me%ifunc + 1\n\n dn = real(me%n, wp)\n f = 2.0_wp*x*exp(-dn) - 2.0_wp*exp(-dn*x) + 1.0_wp\n\n end select\n\n end function f\n\n end program root_tests_oo\n!*****************************************************************************************\n", "meta": {"hexsha": "442814a79cef9e0bc24cba960a1ffcae15792d88", "size": 2032, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/root_tests_oo.f90", "max_stars_repo_name": "jacobwilliams/roots-fortran", "max_stars_repo_head_hexsha": "372f43af2a79d2068eaa9a9b151cd83a7237833b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2021-09-01T18:18:12.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T18:54:44.000Z", "max_issues_repo_path": "tests/root_tests_oo.f90", "max_issues_repo_name": "jacobwilliams/roots-fortran", "max_issues_repo_head_hexsha": "372f43af2a79d2068eaa9a9b151cd83a7237833b", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2021-09-01T10:22:49.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T22:58:52.000Z", "max_forks_repo_path": "tests/root_tests_oo.f90", "max_forks_repo_name": "jacobwilliams/opt-lib", "max_forks_repo_head_hexsha": "372f43af2a79d2068eaa9a9b151cd83a7237833b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-09-28T12:41:40.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-28T12:41:40.000Z", "avg_line_length": 27.8356164384, "max_line_length": 104, "alphanum_fraction": 0.5403543307, "num_tokens": 616, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767970940974, "lm_q2_score": 0.7718434873426303, "lm_q1q2_score": 0.6772747511313497}} {"text": "program ieee_tricks\n implicit none\n real, parameter :: infinity = huge(real(0.0))\n real :: result, r\n\n call random_number(r) \n result = 1.0/min(0.0, r)\n print '(A, E10.5)', '1.0/0.0 =', result\n if (result < -infinity .or. infinity < result) then\n print '(A)', 'Infinity found'\n end if\n\n result = 0.0/min(0.0, r)\n print '(A, E10.5)', '1.0/0.0 =', result\n if (result /= result) then\n print '(A)', 'NaN found'\n end if\nend program ieee_tricks\n", "meta": {"hexsha": "a0c3fba14031be2aed49a34461b1db85e610f4d4", "size": 490, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Debugging/ErrorHandling/ieee_tricks.f90", "max_stars_repo_name": "Gjacquenot/training-material", "max_stars_repo_head_hexsha": "16b29962bf5683f97a1072d961dd9f31e7468b8d", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 115, "max_stars_repo_stars_event_min_datetime": "2015-03-23T13:34:42.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T00:27:21.000Z", "max_issues_repo_path": "Debugging/ErrorHandling/ieee_tricks.f90", "max_issues_repo_name": "Gjacquenot/training-material", "max_issues_repo_head_hexsha": "16b29962bf5683f97a1072d961dd9f31e7468b8d", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 56, "max_issues_repo_issues_event_min_datetime": "2015-02-25T15:04:26.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-03T07:42:48.000Z", "max_forks_repo_path": "Debugging/ErrorHandling/ieee_tricks.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": 25.7894736842, "max_line_length": 55, "alphanum_fraction": 0.5632653061, "num_tokens": 168, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127678225575, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.6772433042159123}} {"text": " subroutine caxpy ( n, ca, cx, incx, cy, incy )\n\nc*********************************************************************72\nc\ncc CAXPY computes constant times a vector plus a vector.\nc\nc Discussion:\nc\nc This routine uses single precision complex arithmetic.\nc\nc Modified:\nc\nc 07 July 2007\nc\nc Author:\nc\nc Jack Dongarra\nc\nc Reference:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\nc LINPACK User's Guide,\nc SIAM, 1979,\nc ISBN13: 978-0-898711-72-1,\nc LC: QA214.L56.\nc\nc Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,\nc Basic Linear Algebra Subprograms for FORTRAN usage,\nc ACM Transactions on Mathematical Software,\nc Volume 5, Number 3, pages 308-323, 1979.\nc\nc Parameters:\nc\nc Input, integer N, the number of elements in CX and CY.\nc\nc Input, complex CA, the multiplier of CX.\nc\nc Input, complex CX(*), the first vector.\nc\nc Input, integer INCX, the increment between successive entries of CX.\nc\nc Input/output, complex CY(*), the second vector.\nc On output, CY(*) has been replaced by CY(*) + CA * CX(*).\nc\nc Input, integer INCY, the increment between successive entries of CY.\nc\n implicit none\n\n complex ca\n complex cx(*)\n complex cy(*)\n integer i\n integer incx\n integer incy\n integer ix\n integer iy\n integer n\n\n if ( n .le. 0 ) then\n return\n end if\n\n if ( abs ( real ( ca ) ) + abs ( aimag ( ca ) ) .eq. 0.0 ) then\n return\n end if\nc\nc Code for both increments equal to 1.\nc\n if ( incx .eq. 1 .and. incy .eq. 1 ) then\n\n do i = 1, n\n cy(i) = cy(i) + ca * cx(i)\n end do\nc\nc Code for unequal increments or equal increments\nc not equal to 1.\nc\n else\n\n if ( incx .lt. 0 ) then\n ix = ( - n + 1 ) * incx + 1\n else\n ix = 1\n end if\n\n if ( incy .lt. 0 ) then\n iy = ( - n + 1 ) * incy + 1\n else\n iy = 1\n end if\n\n do i = 1, n\n cy(iy) = cy(iy) + ca * cx(ix)\n ix = ix + incx\n iy = iy + incy\n end do\n\n end if\n\n return\n end\n subroutine ccopy ( n, cx, incx, cy, incy )\n\nc*********************************************************************72\nc\ncc CCOPY copies a vector, x, to a vector, y.\nc\nc Discussion:\nc\nc This routine uses single precision complex arithmetic.\nc\nc Modified:\nc\nc 07 July 2007\nc\nc Author:\nc\nc Jack Dongarra\nc\nc Reference:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\nc LINPACK User's Guide,\nc SIAM, 1979,\nc ISBN13: 978-0-898711-72-1,\nc LC: QA214.L56.\nc\nc Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,\nc Basic Linear Algebra Subprograms for FORTRAN usage,\nc ACM Transactions on Mathematical Software,\nc Volume 5, Number 3, pages 308-323, 1979.\nc\nc Parameters:\nc\nc Input, integer N, the number of elements in CX and CY.\nc\nc Input, complex CX(*), the first vector.\nc\nc Input, integer INCX, the increment between successive entries of CX.\nc\nc Output, complex CY(*), the second vector.\nc\nc Input, integer INCY, the increment between successive entries of CY.\nc\n implicit none\n\n complex cx(*),cy(*)\n integer i,incx,incy,ix,iy,n\n\n if(n.le.0)return\n if(incx.eq.1.and.incy.eq.1)go to 20\nc\nc code for unequal increments or equal increments\nc not equal to 1\nc\n ix = 1\n iy = 1\n if(incx.lt.0)ix = (-n+1)*incx + 1\n if(incy.lt.0)iy = (-n+1)*incy + 1\n do i = 1,n\n cy(iy) = cx(ix)\n ix = ix + incx\n iy = iy + incy\n end do\n return\nc\nc code for both increments equal to 1\nc\n 20 do i = 1,n\n cy(i) = cx(i)\n end do\n\n return\n end\n function cdotc ( n, cx, incx, cy, incy )\n\nc*********************************************************************72\nc\ncc CDOTC forms the conjugated dot product of two vectors.\nc\nc Discussion:\nc\nc This routine uses single precision complex arithmetic.\nc\nc Modified:\nc\nc 07 July 2007\nc\nc Author:\nc\nc Jack Dongarra\nc\nc Reference:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\nc LINPACK User's Guide,\nc SIAM, 1979,\nc ISBN13: 978-0-898711-72-1,\nc LC: QA214.L56.\nc\nc Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,\nc Basic Linear Algebra Subprograms for FORTRAN usage,\nc ACM Transactions on Mathematical Software,\nc Volume 5, Number 3, pages 308-323, 1979.\nc\nc Parameters:\nc\nc Input, integer N, the number of entries in the vectors.\nc\nc Input, complex CX(*), the first vector.\nc\nc Input, integer INCX, the increment between successive entries in CX.\nc\nc Input, complex CY(*), the second vector.\nc\nc Input, integer INCY, the increment between successive entries in CY.\nc\nc Output, complex CDOTC, the conjugated dot product of \nc the corresponding entries of CX and CY.\nc\n implicit none\n\n complex cdotc\n complex cx(*),cy(*),ctemp\n integer i,incx,incy,ix,iy,n\n\n ctemp = (0.0,0.0)\n cdotc = (0.0,0.0)\n if(n.le.0)return\n if(incx.eq.1.and.incy.eq.1)go to 20\nc\nc code for unequal increments or equal increments\nc not equal to 1\nc\n ix = 1\n iy = 1\n if(incx.lt.0)ix = (-n+1)*incx + 1\n if(incy.lt.0)iy = (-n+1)*incy + 1\n do i = 1,n\n ctemp = ctemp + conjg(cx(ix))*cy(iy)\n ix = ix + incx\n iy = iy + incy\n end do\n cdotc = ctemp\n return\nc\nc code for both increments equal to 1\nc\n 20 do i = 1,n\n ctemp = ctemp + conjg(cx(i))*cy(i)\n end do\n\n cdotc = ctemp\n return\n end\n function cdotu ( n, cx, incx, cy, incy )\n\nc*********************************************************************72\nc\ncc CDOTU forms the dot product of two vectors.\nc\nc Discussion:\nc\nc This routine uses single precision complex arithmetic.\nc\nc Modified:\nc\nc 07 July 2007\nc\nc Author:\nc\nc Jack Dongarra\nc\nc Reference:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\nc LINPACK User's Guide,\nc SIAM, 1979,\nc ISBN13: 978-0-898711-72-1,\nc LC: QA214.L56.\nc\nc Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,\nc Basic Linear Algebra Subprograms for FORTRAN usage,\nc ACM Transactions on Mathematical Software,\nc Volume 5, Number 3, pages 308-323, 1979.\nc\nc Parameters:\nc\nc Input, integer N, the number of entries in the vectors.\nc\nc Input, complex CX(*), the first vector.\nc\nc Input, integer INCX, the increment between successive entries in CX.\nc\nc Input, complex CY(*), the second vector.\nc\nc Input, integer INCY, the increment between successive entries in CY.\nc\nc Output, complex CDOTU, the unconjugated dot product of \nc the corresponding entries of CX and CY.\nc\n implicit none\n\n complex cdotu\n complex cx(*),cy(*),ctemp\n integer i,incx,incy,ix,iy,n\n\n ctemp = (0.0,0.0)\n cdotu = (0.0,0.0)\n if(n.le.0)return\n if(incx.eq.1.and.incy.eq.1)go to 20\nc\nc code for unequal increments or equal increments\nc not equal to 1\nc\n ix = 1\n iy = 1\n if(incx.lt.0)ix = (-n+1)*incx + 1\n if(incy.lt.0)iy = (-n+1)*incy + 1\n do i = 1,n\n ctemp = ctemp + cx(ix)*cy(iy)\n ix = ix + incx\n iy = iy + incy\n end do\n cdotu = ctemp\n return\nc\nc code for both increments equal to 1\nc\n 20 do i = 1,n\n ctemp = ctemp + cx(i)*cy(i)\n end do\n\n cdotu = ctemp\n\n return\n end\n subroutine crotg ( ca, cb, c, s )\n\nc*********************************************************************72\nc\ncc CROTG generates a Givens rotation.\nc\nc Discussion:\nc\nc This routine uses single precision complex arithmetic.\nc\nc Given values A and B, this routine computes:\nc\nc If A = 0:\nc\nc R = B\nc C = 0\nc S = (1,0).\nc\nc If A /= 0:\nc\nc ALPHA = A / abs ( A )\nc NORM = sqrt ( ( abs ( A ) )^2 + ( abs ( B ) )^2 )\nc R = ALPHA * NORM\nc C = abs ( A ) / NORM\nc S = ALPHA * conj ( B ) / NORM\nc\nc In either case, the computed numbers satisfy the equation:\nc\nc ( C S ) * ( A ) = ( R )\nc ( -conj ( S ) C ) ( B ) = ( 0 )\nc\nc Modified:\nc\nc 07 July 2007\nc\nc Author:\nc\nc Jack Dongarra\nc\nc Reference:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\nc LINPACK User's Guide,\nc SIAM, 1979,\nc ISBN13: 978-0-898711-72-1,\nc LC: QA214.L56.\nc\nc Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,\nc Basic Linear Algebra Subprograms for FORTRAN usage,\nc ACM Transactions on Mathematical Software,\nc Volume 5, Number 3, pages 308-323, 1979.\nc\nc Parameters:\nc\nc Input/output, complex CA; on input, the value A. On output,\nc the value R.\nc\nc Input, complex CB, the value B.\nc\nc Output, real C, the cosine of the Givens rotation.\nc\nc Output, complex S, the sine of the Givens rotation.\nc\n implicit none\n\n complex ca,cb,s\n real c\n real norm,scale\n complex alpha\n\n if ( cabs(ca) .eq. 0.0 ) then\n c = 0.\n s = (1.,0.)\n ca = cb\n else\n scale = cabs(ca) + cabs(cb)\n norm = scale * sqrt((cabs(ca/scale))**2 + (cabs(cb/scale))**2)\n alpha = ca /cabs(ca)\n c = cabs(ca) / norm\n s = alpha * conjg(cb) / norm\n ca = alpha * norm\n end if\n\n return\n end\n subroutine cscal ( n, ca, cx, incx )\n\nc*********************************************************************72\nc\ncc CSCAL scales a vector by a constant.\nc\nc Discussion:\nc\nc This routine uses single precision complex arithmetic.\nc\nc Modified:\nc\nc 07 July 2007\nc\nc Author:\nc\nc Jack Dongarra\nc\nc Reference:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\nc LINPACK User's Guide,\nc SIAM, 1979,\nc ISBN13: 978-0-898711-72-1,\nc LC: QA214.L56.\nc\nc Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,\nc Basic Linear Algebra Subprograms for FORTRAN usage,\nc ACM Transactions on Mathematical Software,\nc Volume 5, Number 3, pages 308-323, 1979.\nc\nc Parameters:\nc\nc Input, integer N, the number of entries in the vector.\nc\nc Input, complex CA, the multiplier.\nc\nc Input/output, complex CX(*), the vector to be scaled.\nc\nc Input, integer INCX, the increment between successive entries of CX.\nc\n implicit none\n\n complex ca,cx(*)\n integer i,incx,n,nincx\n\n if( n.le.0 .or. incx.le.0 )return\n if(incx.eq.1)go to 20\nc\nc code for increment not equal to 1\nc\n nincx = n*incx\n do i = 1,nincx,incx\n cx(i) = ca*cx(i)\n end do\n return\nc\nc code for increment equal to 1\nc\n 20 do i = 1,n\n cx(i) = ca*cx(i)\n end do\n\n return\n end\n subroutine csrot ( n, cx, incx, cy, incy, c, s )\n\nc*********************************************************************72\nc\ncc CSROT applies a plane rotation.\nc\nc Discussion:\nc\nc The cos and sin (c and s) are real and the vectors cx and cy are complex.\nc\nc Modified:\nc\nc 07 July 2007\nc\nc Author:\nc\nc Jack Dongarra\nc\nc Reference:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\nc LINPACK User's Guide,\nc SIAM, 1979,\nc ISBN13: 978-0-898711-72-1,\nc LC: QA214.L56.\nc\nc Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,\nc Basic Linear Algebra Subprograms for FORTRAN usage,\nc ACM Transactions on Mathematical Software,\nc Volume 5, Number 3, pages 308-323, 1979.\nc\nc Parameters:\nc\nc Input, integer N, the number of entries in the vectors.\nc\nc Input/output, complex CX(*), one of the vectors to be rotated.\nc\nc Input, integer INCX, the increment between successive entries of CX.\nc\nc Input/output, complex CY(*), one of the vectors to be rotated.\nc\nc Input, integer INCY, the increment between successive elements of CY.\nc\nc Input, real C, S, parameters (presumably the cosine and sine of\nc some angle) that define a plane rotation.\nc\n implicit none\n\n complex cx(1),cy(1),ctemp\n real c,s\n integer i,incx,incy,ix,iy,n\n\n if(n.le.0)return\n if(incx.eq.1.and.incy.eq.1)go to 20\nc\nc code for unequal increments or equal increments not equal\nc to 1\nc\n ix = 1\n iy = 1\n if(incx.lt.0)ix = (-n+1)*incx + 1\n if(incy.lt.0)iy = (-n+1)*incy + 1\n do i = 1,n\n ctemp = c*cx(ix) + s*cy(iy)\n cy(iy) = c*cy(iy) - s*cx(ix)\n cx(ix) = ctemp\n ix = ix + incx\n iy = iy + incy\n end do\n\n return\nc\nc code for both increments equal to 1\nc\n 20 do i = 1,n\n ctemp = c*cx(i) + s*cy(i)\n cy(i) = c*cy(i) - s*cx(i)\n cx(i) = ctemp\n end do\n return\n end\n subroutine csscal ( n, sa, cx, incx )\n\nc*********************************************************************72\nc\ncc CSSCAL scales a complex vector by a real constant.\nc\nc Discussion:\nc\nc This routine uses single precision complex arithmetic.\nc\nc Modified:\nc\nc 07 July 2007\nc\nc Author:\nc\nc Jack Dongarra\nc\nc Reference:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\nc LINPACK User's Guide,\nc SIAM, 1979,\nc ISBN13: 978-0-898711-72-1,\nc LC: QA214.L56.\nc\nc Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,\nc Basic Linear Algebra Subprograms for FORTRAN usage,\nc ACM Transactions on Mathematical Software,\nc Volume 5, Number 3, pages 308-323, 1979.\nc\nc Parameters:\nc\nc Input, integer N, the number of entries in the vector.\nc\nc Input, real SA, the multiplier.\nc\nc Input/output, complex CX(*), the vector to be scaled.\nc\nc Input, integer INCX, the increment between successive entries of \nc the vector CX.\nc\n implicit none\n\n complex cx(*)\n real sa\n integer i,incx,n,nincx\n\n if( n.le.0 .or. incx.le.0 )return\n\n if(incx.eq.1)go to 20\nc\nc code for increment not equal to 1\nc\n nincx = n*incx\n do i = 1,nincx,incx\n cx(i) = cmplx ( sa*real(cx(i)), sa*aimag(cx(i)) )\n end do\n return\nc\nc code for increment equal to 1\nc\n 20 do i = 1,n\n cx(i) = cmplx ( sa*real(cx(i)), sa*aimag(cx(i)) )\n end do\n\n return\n end\n subroutine cswap ( n, cx, incx, cy, incy )\n\nc*********************************************************************72\nc\ncc CSWAP interchanges two vectors.\nc\nc Discussion:\nc\nc This routine uses single precision complex arithmetic.\nc\nc Modified:\nc\nc 07 July 2007\nc\nc Author:\nc\nc Jack Dongarra\nc\nc Reference:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\nc LINPACK User's Guide,\nc SIAM, 1979,\nc ISBN13: 978-0-898711-72-1,\nc LC: QA214.L56.\nc\nc Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,\nc Basic Linear Algebra Subprograms for FORTRAN usage,\nc ACM Transactions on Mathematical Software,\nc Volume 5, Number 3, pages 308-323, 1979.\nc\nc Parameters:\nc\nc Input, integer N, the number of entries in the vectors.\nc\nc Input/output, complex CX(*), one of the vectors to swap.\nc\nc Input, integer INCX, the increment between successive entries of CX.\nc\nc Input/output, complex CY(*), one of the vectors to swap.\nc\nc Input, integer INCY, the increment between successive elements of CY.\nc\n implicit none\n\n complex cx(*),cy(*),ctemp\n integer i,incx,incy,ix,iy,n\n\n if(n.le.0)return\n if(incx.eq.1.and.incy.eq.1)go to 20\nc\nc code for unequal increments or equal increments not equal\nc to 1\nc\n ix = 1\n iy = 1\n if(incx.lt.0)ix = (-n+1)*incx + 1\n if(incy.lt.0)iy = (-n+1)*incy + 1\n do i = 1,n\n ctemp = cx(ix)\n cx(ix) = cy(iy)\n cy(iy) = ctemp\n ix = ix + incx\n iy = iy + incy\n end do\n return\nc\nc code for both increments equal to 1\nc\n 20 do i = 1,n\n ctemp = cx(i)\n cx(i) = cy(i)\n cy(i) = ctemp\n end do\n\n return\n end\n function icamax ( n, cx, incx )\n\nc*********************************************************************72\nc\ncc ICAMAX finds the index of element having maximum absolute value.\nc\nc Discussion:\nc\nc This routine uses single precision complex arithmetic.\nc\nc Modified:\nc\nc 07 July 2007\nc\nc Author:\nc\nc Jack Dongarra\nc\nc Reference:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\nc LINPACK User's Guide,\nc SIAM, 1979,\nc ISBN13: 978-0-898711-72-1,\nc LC: QA214.L56.\nc\nc Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,\nc Basic Linear Algebra Subprograms for FORTRAN usage,\nc ACM Transactions on Mathematical Software,\nc Volume 5, Number 3, pages 308-323, 1979.\nc\nc Parameters:\nc\nc Input, integer N, the number of entries in the vector.\nc\nc Input, complex X(*), the vector.\nc\nc Input, integer INCX, the increment between successive entries of X.\nc\nc Output, integer ICAMAX, the index of the element of maximum\nc absolute value.\nc\n implicit none\n\n complex cx(*)\n integer icamax\n real smax\n integer i,incx,ix,n\n complex zdum\n real cabs1\n cabs1(zdum) = abs(real(zdum)) + abs(aimag(zdum))\n\n icamax = 0\n if( n.lt.1 .or. incx.le.0 ) return\n icamax = 1\n if(n.eq.1)return\n if(incx.eq.1)go to 20\nc\nc code for increment not equal to 1\nc\n ix = 1\n smax = cabs1(cx(1))\n ix = ix + incx\n do i = 2,n\n if(cabs1(cx(ix)).le.smax) go to 5\n icamax = i\n smax = cabs1(cx(ix))\n 5 ix = ix + incx\n end do\n\n return\nc\nc code for increment equal to 1\nc\n 20 smax = cabs1(cx(1))\n do i = 2,n\n if ( smax .lt. cabs1(cx(i)) ) then\n icamax = i\n smax = cabs1(cx(i))\n end if\n end do\n\n return\n end\n function scasum ( n, cx, incx )\n\nc*********************************************************************72\nc\ncc SCASUM takes the sum of the absolute values of a complex vector.\nc\nc Discussion:\nc\nc This routine uses single precision complex arithmetic.\nc\nc Modified:\nc\nc 07 July 2007\nc\nc Author:\nc\nc Jack Dongarra\nc\nc Reference:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\nc LINPACK User's Guide,\nc SIAM, 1979,\nc ISBN13: 978-0-898711-72-1,\nc LC: QA214.L56.\nc\nc Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,\nc Basic Linear Algebra Subprograms for FORTRAN usage,\nc ACM Transactions on Mathematical Software,\nc Volume 5, Number 3, pages 308-323, 1979.\nc\nc Parameters:\nc\nc Input, integer N, the number of entries in the vector.\nc\nc Input, complex X(*), the vector.\nc\nc Input, integer INCX, the increment between successive entries of X.\nc\nc Output, real SCASUM, the sum of the absolute values.\nc\n implicit none\n\n complex cx(*)\n real scasum\n real stemp\n integer i,incx,n,nincx\n\n scasum = 0.0e0\n stemp = 0.0e0\n if( n.le.0 .or. incx.le.0 )return\n if(incx.eq.1)go to 20\nc\nc code for increment not equal to 1\nc\n nincx = n*incx\n do i = 1,nincx,incx\n stemp = stemp + abs(real(cx(i))) + abs(aimag(cx(i)))\n end do\n scasum = stemp\n return\nc\nc code for increment equal to 1\nc\n 20 do i = 1,n\n stemp = stemp + abs(real(cx(i))) + abs(aimag(cx(i)))\n end do\n\n scasum = stemp\n\n return\n end\n function scnrm2 ( n, x, incx )\n\nc*********************************************************************72\nc\ncc SCNRM2 returns the euclidean norm of a complex vector.\nc\nc Discussion:\nc\nc This routine uses single precision complex arithmetic.\nc\nc SCNRM2 := sqrt ( sum ( conjg ( x(1:n) ) * x(1:n) ) )\nc = sqrt ( dot_product ( x(1:n), x(1:n) ) )\nc\nc Modified:\nc\nc 07 July 2007\nc\nc Author:\nc\nc Sven Hammarling\nc\nc Reference:\nc\nc Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,\nc LINPACK User's Guide,\nc SIAM, 1979,\nc ISBN13: 978-0-898711-72-1,\nc LC: QA214.L56.\nc\nc Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh,\nc Basic Linear Algebra Subprograms for FORTRAN usage,\nc ACM Transactions on Mathematical Software,\nc Volume 5, Number 3, pages 308-323, 1979.\nc\nc Parameters:\nc\nc Input, integer N, the number of entries in the vector.\nc\nc Input, complex X(*), the vector.\nc\nc Input, integer INCX, the increment between successive entries of X.\nc\nc Output, real SCNRM2, the norm of the vector.\nc\n implicit none\n\n integer incx\n integer ix\n integer n\n real one\n parameter ( one = 1.0e+0 )\n real scnrm2\n complex x( * )\n real zero\n parameter ( zero = 0.0e+0 )\n\n\n real norm, scale, ssq, temp\n intrinsic abs, aimag, real, sqrt\n\n if( n.lt.1 .or. incx.lt.1 )then\n norm = zero\n else\n scale = zero\n ssq = one\nc The following loop is equivalent to this call to the LAPACK\nc auxiliary routine:\nc CALL CLASSQ( N, X, INCX, SCALE, SSQ )\nc\n do ix = 1, 1 + ( n - 1 )*incx, incx\n if( real( x( ix ) ).ne.zero )then\n temp = abs( real( x( ix ) ) )\n if( scale.lt.temp )then\n ssq = one + ssq*( scale/temp )**2\n scale = temp\n else\n ssq = ssq + ( temp/scale )**2\n end if\n end if\n if( aimag( x( ix ) ).ne.zero )then\n temp = abs( aimag( x( ix ) ) )\n if( scale.lt.temp )then\n ssq = one + ssq*( scale/temp )**2\n scale = temp\n else\n ssq = ssq + ( temp/scale )**2\n end if\n end if\n end do\n norm = scale * sqrt( ssq )\n end if\n\n scnrm2 = norm\n\n return\n end\n", "meta": {"hexsha": "a6961c151637b78cc382e81ba9d6d6dcf5286c67", "size": 21706, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "blas1_c/blas1_c.f", "max_stars_repo_name": "SourangshuGhosh/Basic-Linear-Algebra-Subprograms", "max_stars_repo_head_hexsha": "5b8b011a1acac19193203c54a97ebeed56fed6d3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-07-29T09:14:47.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-14T17:38:52.000Z", "max_issues_repo_path": "blas1_c/blas1_c.f", "max_issues_repo_name": "SourangshuGhosh/Basic-Linear-Algebra-Subprograms", "max_issues_repo_head_hexsha": "5b8b011a1acac19193203c54a97ebeed56fed6d3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "blas1_c/blas1_c.f", "max_forks_repo_name": "SourangshuGhosh/Basic-Linear-Algebra-Subprograms", "max_forks_repo_head_hexsha": "5b8b011a1acac19193203c54a97ebeed56fed6d3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.4699792961, "max_line_length": 78, "alphanum_fraction": 0.5768911822, "num_tokens": 6966, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.8539127566694178, "lm_q1q2_score": 0.6772432891065456}} {"text": "program euler_method\nuse iso_fortran_env, only: real64\nimplicit none\n\nabstract interface\n ! a derivative dy/dt as function of y and t\n function derivative(y, t)\n use iso_fortran_env, only: real64\n real(real64) :: derivative\n real(real64), intent(in) :: t, y\n end function\nend interface\n\nreal(real64), parameter :: T_0 = 100, T_room = 20, k = 0.07, a = 0, b = 100, &\n h(3) = [2.0, 5.0, 10.0]\n\ninteger :: i\n\n! loop over all step sizes\ndo i = 1, 3\n call euler(newton_cooling, T_0, a, b, h(i))\nend do\n\ncontains\n\n! Approximates y(t) in y'(t) = f(y, t) with y(a) = y0 and t = a..b and the\n! step size h.\nsubroutine euler(f, y0, a, b, h)\n procedure(derivative) :: f\n real(real64), intent(in) :: y0, a, b, h\n real(real64) :: t, y\n\n if (a > b) return\n if (h <= 0) stop \"negative step size\"\n\n print '(\"# h = \", F0.3)', h\n\n y = y0\n t = a\n\n do\n print *, t, y\n t = t + h\n if (t > b) return\n y = y + h * f(y, t)\n end do\nend subroutine\n\n\n! Example: Newton's cooling law, f(T, _) = -k*(T - T_room)\nfunction newton_cooling(T, unused) result(dTdt)\n real(real64) :: dTdt\n real(real64), intent(in) :: T, unused\n dTdt = -k * (T - T_room)\nend function\n\nend program\n", "meta": {"hexsha": "71c1352aff7b5a132aa9cee17ca08d0de43a9534", "size": 1184, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Euler-method/Fortran/euler-method.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/Euler-method/Fortran/euler-method.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/Euler-method/Fortran/euler-method.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 20.4137931034, "max_line_length": 78, "alphanum_fraction": 0.6030405405, "num_tokens": 448, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517043, "lm_q2_score": 0.7931059536292271, "lm_q1q2_score": 0.6772432882459201}} {"text": "!---------------------------------------------------------------------!\n! PHAML !\n! !\n! The Parallel Hierarchical Adaptive MultiLevel code for solving !\n! linear elliptic partial differential equations of the form !\n! (PUx)x + (QUy)y + RU = F on 2D polygonal domains with mixed !\n! boundary conditions, and eigenvalue problems where F is lambda*U. !\n! !\n! PHAML is public domain software. It was produced as part of work !\n! done by the U.S. Government, and is not subject to copyright in !\n! the United States. !\n! !\n! William F. Mitchell !\n! Applied and Computational Mathematics Division !\n! National Institute of Standards and Technology !\n! william.mitchell@nist.gov !\n! http://math.nist.gov/phaml !\n! !\n!---------------------------------------------------------------------!\n\n!----------------------------------------------------\n! This file contains the user supplied module phaml_user_mod\n!----------------------------------------------------\n\nmodule phaml_user_mod\n\n!----------------------------------------------------\n! This module contains user global data.\n!\n! This version illustrates eigenvalue problems via the Schroedinger Equation\n! for a simple harmonic oscillator where the cross section of the well is an\n! ellipse with axes determined by prob_param.\n! -uxx -uyy + prob_param*(x^2+3*y^2)/2 * u = lambda * u\n! prob_param must be positive.\n!\n! For num_eval=1 and lambda0=-huge(0.), the eigenvalue is\n! sqrt(prob_param*(2+sqrt(3)))\n! and the solution (wave function) is\n! exp(-sqrt(prob_param/8)*(x^2+sqrt(3)*y^2).\n!\n!----------------------------------------------------\n\n!----------------------------------------------------\n! Other modules used are:\n\nuse phaml\n!----------------------------------------------------\n\nimplicit none\n\n!----------------------------------------------------\n! Global variables\n\nreal(my_real), save :: prob_param\n!----------------------------------------------------\n\nend module phaml_user_mod\n", "meta": {"hexsha": "f547942e65dcb8740af273da52e4d63bcc6808b9", "size": 2527, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/eigenvalue/usermod.f90", "max_stars_repo_name": "qsnake/phaml", "max_stars_repo_head_hexsha": "8925b4c32657bbd9f81cd5f8f9d6739151c66fec", "max_stars_repo_licenses": ["mpich2"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-09-07T15:46:34.000Z", "max_stars_repo_stars_event_max_datetime": "2018-09-07T15:46:34.000Z", "max_issues_repo_path": "examples/eigenvalue/usermod.f90", "max_issues_repo_name": "qsnake/phaml", "max_issues_repo_head_hexsha": "8925b4c32657bbd9f81cd5f8f9d6739151c66fec", "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/eigenvalue/usermod.f90", "max_forks_repo_name": "qsnake/phaml", "max_forks_repo_head_hexsha": "8925b4c32657bbd9f81cd5f8f9d6739151c66fec", "max_forks_repo_licenses": ["mpich2"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.5689655172, "max_line_length": 76, "alphanum_fraction": 0.3965176098, "num_tokens": 409, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127455162772, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.6772432739971784}} {"text": "\n! ----------------------------------------------------------------------\n real function AScurv(df,x,min,max,shp,mid,asy)\n! ----------------------------------------------------------------------\n \n implicit none\n integer df ! Equation form: 1 = integral, 2 = 1st derivative\n real x ! X Value\n real min ! Minimum Value\n real max ! Maximum Value\n real shp ! Function Shape\n real mid ! X Value in which y = (max - min) / 2.\n real asy ! Asymetry\n \n select case(df)\n case(1)\n !Integral form\n AScurv = max + ((min - max) / ((1.d0 + (x/mid)**shp)**asy))\n \n case(2)\n !1st derivative\n AScurv = -asy * (min-max) * ((1.d0+(x/mid)**shp)**(-asy-1.d0)) * (shp*(x/mid)**(shp-1.d0)) * (1.d0/mid)\n \n end select \n return\n end\n!-----------------------------------------------------------------------", "meta": {"hexsha": "cbdeff0996098372415fe71c3a5d16724f0d367d", "size": 954, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "code/Functions_SAMUCA.f90", "max_stars_repo_name": "Murilodsv/sw_sc", "max_stars_repo_head_hexsha": "fcf8642431b838c8ae724f281fc0d265327941f3", "max_stars_repo_licenses": ["MIT"], "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/Functions_SAMUCA.f90", "max_issues_repo_name": "Murilodsv/sw_sc", "max_issues_repo_head_hexsha": "fcf8642431b838c8ae724f281fc0d265327941f3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-08-14T14:00:44.000Z", "max_issues_repo_issues_event_max_datetime": "2019-08-14T20:52:11.000Z", "max_forks_repo_path": "code/Functions_SAMUCA.f90", "max_forks_repo_name": "Murilodsv/sw_sc", "max_forks_repo_head_hexsha": "fcf8642431b838c8ae724f281fc0d265327941f3", "max_forks_repo_licenses": ["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.3333333333, "max_line_length": 113, "alphanum_fraction": 0.3637316562, "num_tokens": 243, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966732132747, "lm_q2_score": 0.7154239897159439, "lm_q1q2_score": 0.6772179686020805}} {"text": "module ZerowithRidders\n\n use iso_fortran_env\n implicit none\n\n INTEGER, parameter :: qp = REAL64\n INTEGER, parameter :: maxi = 2000\n REAL(qp), parameter :: tol = 1.E-6\n\n abstract interface\n pure function ResidualFunction(x,parameters)\n Double precision, intent(in) :: x\n Double precision, intent(in), optional :: parameters(:)\n Double precision :: ResidualFunction\n end function ResidualFunction\n end interface\n\ncontains\n pure function FINDZEROWITHRIDDERS( ResidualFuncao, parameters, x_min, x_max )\n\n !use iso_fortran_env\n implicit none\n\n !!! declara\u00e7\u00f5es\n\n !maxi = < Maximum iterations number >\n !\u03b5 := < Tolerance value for the residual >\n ! varin := < variable value at left boundary >\n ! varout := < variable value at right boundary >\n ! resin :=ResidualFunction(varin;...)\n ! resout :=ResidualFunction(varout;...)\n !INTEGER, parameter :: maxi = 2000\n !REAL(REAL64), parameter :: tol = 1.E-6\n REAL(qp) :: varin, varout, resin, resout, vartemp,restemp,varguess,res\n procedure(ResidualFunction) :: ResidualFuncao\n REAL(qp), intent(in) :: parameters(:)\n REAL(qp), intent(in) :: x_min, x_max\n REAL(qp) :: FINDZEROWITHRIDDERS\n INTEGER :: i\n\n varin = x_min\n varout = x_max\n resin = ResidualFuncao(varin, parameters)\n resout = ResidualFuncao(varout, parameters)\n res = 1000.\n i=0\n !restemp = 1000.\n !print *, \"inside 1\", varin, varout, resin, resout\n !print *, maxi, res, tol\n\n DO WHILE ( (i .LT. maxi) .AND. (abs(res) .GE. tol) )\n varguess = (varin + varout)/2.\n res = ResidualFuncao(varguess, parameters)\n !print *, varguess, res\n vartemp=varguess+(varguess-varin)*sign(res,resin-resout)/(sqrt(res**2 - resin*resout))\n restemp = ResidualFuncao(vartemp, parameters)\n !print *, vartemp, restemp\n if (res*restemp < 0) then\n varin = varguess\n resin = res\n varout = vartemp\n resout = restemp\n else\n if (restemp*resin < 0) then\n varout = vartemp\n resout = restemp\n else\n varin = vartemp\n resin = restemp\n end if\n end if\n i = i + 1\n !print *, i\n END DO\n !FINDZEROWITHRIDDERS = vartemp\n if (abs(res) eps .OR. (ndf > 20.d0 - eps .AND. ndf > t2) &\r\n .OR. ndf > 200.d0 ) THEN\r\n \r\n! Asymptotic series for large or non-integer ndf\r\n \r\n IF (y > 1.d-06) y = LOG(b)\r\n a = ndf - 0.5D0\r\n b = 48.d0 * a**2\r\n y = a * y\r\n y = (((((-0.4D0*y - 3.3D0)*y - 24.d0)*y - 85.5D0) / &\r\n (0.8D0*y**2 + 100.d0 + b) + y +3.d0) / b + one) * SQRT(y)\r\n fn_val = 2.d0 * normal(-y)\r\n RETURN\r\n \r\nELSE IF ( ndf < 20.d0 .AND. t2 < 4.d0) THEN\r\n \r\n! Nested summation of cosine series\r\n \r\n y = SQRT(y)\r\n a = y\r\n IF (ndf == one) a = 0.d0\r\n n = ndf\r\n \r\n! Tail series expansion for large t-values\r\n \r\nELSE\r\n a = SQRT(b)\r\n y = a * ndf\r\n j = 0\r\n 10 j = j + 2\r\n IF (ABS(a-z) > eps) THEN\r\n z = a\r\n y = y * (j - 1) / (b * j)\r\n a = a + y / (ndf + j)\r\n GO TO 10\r\n END IF\r\n n = ndf + 2.d0\r\n z = 0.d0\r\n y = 0.d0\r\n a = - a\r\nEND IF\r\n\r\n! This is the `loop' from the Algol code.\r\n! It required jumping between different parts of an IF () THEN\r\n! ELSE IF () .. block.\r\n\r\n20 n = n - 2.d0\r\nIF (n > 1.d0) THEN\r\n a = (n - 1.d0) * a / (b * n) + y\r\n GO TO 20\r\nEND IF\r\n\r\nIF ( ABS(n) < eps ) THEN\r\n a = a / SQRT(b)\r\nELSE\r\n a = (ATAN(y) + a/b) * twoonpi\r\nEND IF\r\nfn_val = z - a\r\n\r\nRETURN\r\nEND FUNCTION student\r\n", "meta": {"hexsha": "37c5657fbf0db0cd8f5a6dc5d55bbc623f3585d1", "size": 3014, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/cacm395.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/cacm395.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/cacm395.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": 25.7606837607, "max_line_length": 79, "alphanum_fraction": 0.5510948905, "num_tokens": 1041, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.7606506635289836, "lm_q1q2_score": 0.6772028938357445}} {"text": "! Build\n! Windows: ifort /I \"%IFORT_COMPILER11%\\mkl\\include\\ia32\" deconv1d.f90 \"%IFORT_COMPILER11%\\mkl\\ia32\\lib\\*.lib\"\n! Linux:\n\nprogram deconv\n ! Use gelsd from LAPACK95.\n use mkl95_lapack, only : gelsd\n\n implicit none\n real(8), allocatable :: g(:), href(:), A(:,:), f(:)\n real(8), pointer :: h(:), r(:)\n integer :: N\n character(len=16) :: cbuff\n integer :: i\n intrinsic :: nint\n\n ! Allocate data arrays\n allocate(g(21),f(16))\n g = [24,75,71,-34,3,22,-45,23,245,25,52,25,-67,-96,96,31,55,36,29,-43,-7]\n f = [-3,-6,-1,8,-6,3,-1,-9,-9,3,-2,5,2,-2,-7,-1]\n\n ! Calculate deconvolution\n h => deco(f, g)\n\n ! Check result against reference\n N = size(h)\n allocate(href(N))\n href = [-8,-9,-3,-1,-6,7]\n cbuff = ' '\n write(cbuff,'(a,i0,a)') '(a,',N,'(i0,a),i0)'\n if (any(abs(h-href) > 1.0d-4)) then\n write(*,'(a)') 'deconv(f, g) - FAILED'\n else\n write(*,cbuff) 'deconv(f, g) = ',(nint(h(i)),', ',i=1,N-1),nint(h(N))\n end if\n\n ! Calculate deconvolution\n r => deco(h, g)\n\n cbuff = ' '\n N = size(r)\n write(cbuff,'(a,i0,a)') '(a,',N,'(i0,a),i0)'\n if (any(abs(r-f) > 1.0d-4)) then\n write(*,'(a)') 'deconv(h, g) - FAILED'\n else\n write(*,cbuff) 'deconv(h, g) = ',(nint(r(i)),', ',i=1,N-1),nint(r(N))\n end if\n\ncontains\n function deco(p, q)\n real(8), pointer :: deco(:)\n real(8), intent(in) :: p(:), q(:)\n\n real(8), allocatable, target :: r(:)\n real(8), allocatable :: A(:,:)\n integer :: N\n\n ! Construct derived arrays\n N = size(q) - size(p) + 1\n allocate(A(size(q),N),r(size(q)))\n A = 0.0d0\n do i=1,N\n A(i:i+size(p)-1,i) = p\n end do\n\n ! Invoke the LAPACK routine to do the work\n r = q\n call gelsd(A, r)\n\n deco => r(1:N)\n end function deco\n\nend program deconv\n", "meta": {"hexsha": "5d0080e76edad9213a28082c74b5d5f570caa3b5", "size": 1796, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Deconvolution-1D/Fortran/deconvolution-1d-1.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Deconvolution-1D/Fortran/deconvolution-1d-1.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Deconvolution-1D/Fortran/deconvolution-1d-1.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 24.2702702703, "max_line_length": 110, "alphanum_fraction": 0.5239420935, "num_tokens": 716, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942377652497, "lm_q2_score": 0.7606506526772883, "lm_q1q2_score": 0.677202893030966}} {"text": "* Note: The test program has been removed and a utlity routine mvnun has been\n* added. RTK 2004-08-10\n*\n* Copyright 2000 by Alan Genz.\n* Copyright 2004-2005 by Enthought, Inc.\n*\n* The subroutine MVNUN is copyrighted by Enthought, Inc.\n* The rest of the file is copyrighted by Alan Genz and has kindly been offered\n* to the Scipy project under it's BSD-style license.\n*\n* This file contains a short test program and MVNDST, a subroutine\n* for computing multivariate normal distribution function values.\n* The file is self contained and should compile without errors on (77) \n* standard Fortran compilers. The test program demonstrates the use of\n* MVNDST for computing MVN distribution values for a five dimensional \n* example problem, with three different integration limit combinations.\n*\n* Alan Genz\n* Department of Mathematics\n* Washington State University\n* Pullman, WA 99164-3113\n* Email : alangenz@wsu.edu\n*\n SUBROUTINE mvnun(d, n, lower, upper, means, covar, maxpts, \n & abseps, releps, value, inform)\n* Parameters\n*\n* d integer, dimensionality of the data\n* n integer, the number of data points\n* lower double(2), the lower integration limits\n* upper double(2), the upper integration limits\n* means double(n), the mean of each kernel\n* covar double(2,2), the covariance matrix\n* maxpts integer, the maximum number of points to evaluate at\n* abseps double, absolute error tolerance\n* releps double, relative error tolerance\n* value double intent(out), integral value\n* inform integer intent(out), \n* if inform == 0: error < eps\n* elif inform == 1: error > eps, all maxpts used\n integer n, d, infin(d), maxpts, inform, tmpinf\n double precision lower(d), upper(d), releps, abseps,\n & error, value, stdev(d), rho(d*(d-1)/2), \n & covar(d,d),\n & nlower(d), nupper(d), means(d,n), tmpval\n integer i, j\n\n do i=1,d\n stdev(i) = dsqrt(covar(i,i))\n infin(i) = 2\n end do\n do i=1,d\n do j=1,i-1\n rho(j+(i-2)*(i-1)/2) = covar(i,j)/stdev(i)/stdev(j)\n end do\n end do\n value = 0d0\n\n inform = 0\n\n do i=1,n\n do j=1,d\n nlower(j) = (lower(j) - means(j,i))/stdev(j)\n nupper(j) = (upper(j) - means(j,i))/stdev(j)\n end do\n call mvndst(d,nlower,nupper,infin,rho,maxpts,abseps,releps,\n & error,tmpval,tmpinf)\n value = value + tmpval\n if (tmpinf .eq. 1) then\n inform = 1\n end if\n end do\n\n value = value / n\n \n END \n\n SUBROUTINE MVNDST( N, LOWER, UPPER, INFIN, CORREL, MAXPTS,\n & ABSEPS, RELEPS, ERROR, VALUE, INFORM )\n*\n* A subroutine for computing multivariate normal probabilities.\n* This subroutine uses an algorithm given in the paper\n* \"Numerical Computation of Multivariate Normal Probabilities\", in\n* J. of Computational and Graphical Stat., 1(1992), pp. 141-149, by\n* Alan Genz \n* Department of Mathematics\n* Washington State University \n* Pullman, WA 99164-3113\n* Email : AlanGenz@wsu.edu\n*\n* Parameters\n*\n* N INTEGER, the number of variables.\n* LOWER REAL, array of lower integration limits.\n* UPPER REAL, array of upper integration limits.\n* INFIN INTEGER, array of integration limits flags:\n* if INFIN(I) < 0, Ith limits are (-infinity, infinity);\n* if INFIN(I) = 0, Ith limits are (-infinity, UPPER(I)];\n* if INFIN(I) = 1, Ith limits are [LOWER(I), infinity);\n* if INFIN(I) = 2, Ith limits are [LOWER(I), UPPER(I)].\n* CORREL REAL, array of correlation coefficients; the correlation\n* coefficient in row I column J of the correlation matrix\n* should be stored in CORREL( J + ((I-2)*(I-1))/2 ), for J < I.\n* THe correlation matrix must be positive semidefinite.\n* MAXPTS INTEGER, maximum number of function values allowed. This \n* parameter can be used to limit the time. A sensible \n* strategy is to start with MAXPTS = 1000*N, and then\n* increase MAXPTS if ERROR is too large.\n* ABSEPS REAL absolute error tolerance.\n* RELEPS REAL relative error tolerance.\n* ERROR REAL estimated absolute error, with 99% confidence level.\n* VALUE REAL estimated value for the integral\n* INFORM INTEGER, termination status parameter:\n* if INFORM = 0, normal completion with ERROR < EPS;\n* if INFORM = 1, completion with ERROR > EPS and MAXPTS \n* function vaules used; increase MAXPTS to \n* decrease ERROR;\n* if INFORM = 2, N > 500 or N < 1.\n*\n EXTERNAL MVNDFN\n INTEGER N, INFIN(*), MAXPTS, INFORM, INFIS, IVLS\n DOUBLE PRECISION CORREL(*), LOWER(*), UPPER(*), RELEPS, ABSEPS,\n & ERROR, VALUE, E, D, MVNDNT, MVNDFN\n COMMON /DKBLCK/IVLS\n IF ( N .GT. 500 .OR. N .LT. 1 ) THEN\n INFORM = 2\n VALUE = 0\n ERROR = 1\n ELSE\n INFORM = MVNDNT(N, CORREL, LOWER, UPPER, INFIN, INFIS, D, E)\n IF ( N-INFIS .EQ. 0 ) THEN\n VALUE = 1\n ERROR = 0\n ELSE IF ( N-INFIS .EQ. 1 ) THEN\n VALUE = E - D\n ERROR = 2D-16\n ELSE\n*\n* Call the lattice rule integration subroutine\n*\n IVLS = 0\n CALL DKBVRC( N-INFIS-1, IVLS, MAXPTS, MVNDFN, \n & ABSEPS, RELEPS, ERROR, VALUE, INFORM )\n ENDIF\n ENDIF\n END\n DOUBLE PRECISION FUNCTION MVNDFN( N, W )\n* \n* Integrand subroutine\n*\n INTEGER N, INFIN(*), INFIS, NL\n DOUBLE PRECISION W(*), LOWER(*), UPPER(*), CORREL(*), D, E\n PARAMETER ( NL = 500 )\n DOUBLE PRECISION COV(NL*(NL+1)/2), A(NL), B(NL), Y(NL)\n INTEGER INFI(NL), I, J, IJ, IK, INFA, INFB\n DOUBLE PRECISION SUM, AI, BI, DI, EI, PHINVS, BVNMVN, MVNDNT\n SAVE A, B, INFI, COV\n MVNDFN = 1\n INFA = 0\n INFB = 0\n IK = 1\n IJ = 0\n DO I = 1, N+1\n SUM = 0\n DO J = 1, I-1\n IJ = IJ + 1\n IF ( J .LT. IK ) SUM = SUM + COV(IJ)*Y(J)\n END DO\n IF ( INFI(I) .NE. 0 ) THEN\n IF ( INFA .EQ. 1 ) THEN\n AI = MAX( AI, A(I) - SUM )\n ELSE\n AI = A(I) - SUM \n INFA = 1\n END IF\n END IF\n IF ( INFI(I) .NE. 1 ) THEN\n IF ( INFB .EQ. 1 ) THEN\n BI = MIN( BI, B(I) - SUM )\n ELSE\n BI = B(I) - SUM \n INFB = 1\n END IF\n END IF\n IJ = IJ + 1\n IF ( I .EQ. N+1 .OR. COV(IJ+IK+1) .GT. 0 ) THEN \n CALL MVNLMS( AI, BI, 2*INFA+INFB-1, DI, EI )\n IF ( DI .GE. EI ) THEN\n MVNDFN = 0\n RETURN\n ELSE\n MVNDFN = MVNDFN*( EI - DI )\n IF ( I .LE. N ) Y(IK) = PHINVS( DI + W(IK)*( EI - DI ) )\n IK = IK + 1\n INFA = 0\n INFB = 0\n END IF\n END IF\n END DO\n RETURN\n*\n* Entry point for intialization.\n*\n ENTRY MVNDNT( N, CORREL, LOWER, UPPER, INFIN, INFIS, D, E )\n MVNDNT = 0\n*\n* Initialization and computation of covariance Cholesky factor.\n*\n CALL COVSRT( N, LOWER,UPPER,CORREL,INFIN,Y, INFIS,A,B,COV,INFI )\n IF ( N - INFIS .EQ. 1 ) THEN\n CALL MVNLMS( A(1), B(1), INFI(1), D, E ) \n ELSE IF ( N - INFIS .EQ. 2 ) THEN\n IF ( ABS( COV(3) ) .GT. 0 ) THEN\n D = SQRT( 1 + COV(2)**2 )\n IF ( INFI(2) .NE. 0 ) A(2) = A(2)/D\n IF ( INFI(2) .NE. 1 ) B(2) = B(2)/D\n E = BVNMVN( A, B, INFI, COV(2)/D )\n D = 0\n ELSE\n IF ( INFI(1) .NE. 0 ) THEN\n IF ( INFI(2) .NE. 0 ) A(1) = MAX( A(1), A(2) )\n ELSE\n IF ( INFI(2) .NE. 0 ) A(1) = A(2) \n END IF\n IF ( INFI(1) .NE. 1 ) THEN\n IF ( INFI(2) .NE. 1 ) B(1) = MIN( B(1), B(2) ) \n ELSE\n IF ( INFI(2) .NE. 1 ) B(1) = B(2)\n END IF\n IF ( INFI(1) .NE. INFI(2) ) INFI(1) = 2\n CALL MVNLMS( A(1), B(1), INFI(1), D, E ) \n END IF\n INFIS = INFIS + 1 \n END IF\n END\n SUBROUTINE MVNLMS( A, B, INFIN, LOWER, UPPER )\n DOUBLE PRECISION A, B, LOWER, UPPER, MVNPHI\n INTEGER INFIN\n LOWER = 0\n UPPER = 1\n IF ( INFIN .GE. 0 ) THEN\n IF ( INFIN .NE. 0 ) LOWER = MVNPHI(A)\n IF ( INFIN .NE. 1 ) UPPER = MVNPHI(B)\n ENDIF\n UPPER = MAX( UPPER, LOWER )\n END \n SUBROUTINE COVSRT( N, LOWER, UPPER, CORREL, INFIN, Y, \n & INFIS, A, B, COV, INFI )\n*\n* Subroutine to sort integration limits and determine Cholesky factor.\n*\n INTEGER N, INFI(*), INFIN(*), INFIS\n DOUBLE PRECISION \n & A(*), B(*), COV(*), LOWER(*), UPPER(*), CORREL(*), Y(*)\n INTEGER I, J, K, L, M, II, IJ, IL, JMIN\n DOUBLE PRECISION SUMSQ, AJ, BJ, SUM, SQTWPI, EPS, D, E\n DOUBLE PRECISION CVDIAG, AMIN, BMIN, DMIN, EMIN, YL, YU\n PARAMETER ( SQTWPI = 2.506628274631001D0, EPS = 1D-10 )\n IJ = 0\n II = 0\n INFIS = 0\n DO I = 1, N\n A(I) = 0\n B(I) = 0\n INFI(I) = INFIN(I) \n IF ( INFI(I) .LT. 0 ) THEN\n INFIS = INFIS + 1\n ELSE \n IF ( INFI(I) .NE. 0 ) A(I) = LOWER(I)\n IF ( INFI(I) .NE. 1 ) B(I) = UPPER(I)\n ENDIF\n DO J = 1, I-1\n IJ = IJ + 1\n II = II + 1\n COV(IJ) = CORREL(II)\n END DO\n IJ = IJ + 1\n COV(IJ) = 1\n END DO\n*\n* First move any doubly infinite limits to innermost positions.\n*\n IF ( INFIS .LT. N ) THEN\n DO I = N, N-INFIS+1, -1\n IF ( INFI(I) .GE. 0 ) THEN \n DO J = 1,I-1\n IF ( INFI(J) .LT. 0 ) THEN\n CALL RCSWP( J, I, A, B, INFI, N, COV )\n GO TO 10\n ENDIF\n END DO\n ENDIF\n 10 END DO\n*\n* Sort remaining limits and determine Cholesky factor.\n*\n II = 0\n DO I = 1, N-INFIS\n*\n* Determine the integration limits for variable with minimum\n* expected probability and interchange that variable with Ith.\n*\n DMIN = 0\n EMIN = 1\n JMIN = I\n CVDIAG = 0\n IJ = II\n DO J = I, N-INFIS\n IF ( COV(IJ+J) .GT. EPS ) THEN\n SUMSQ = SQRT( COV(IJ+J) )\n SUM = 0\n DO K = 1, I-1\n SUM = SUM + COV(IJ+K)*Y(K)\n END DO\n AJ = ( A(J) - SUM )/SUMSQ\n BJ = ( B(J) - SUM )/SUMSQ\n CALL MVNLMS( AJ, BJ, INFI(J), D, E )\n IF ( EMIN + D .GE. E + DMIN ) THEN\n JMIN = J\n AMIN = AJ\n BMIN = BJ\n DMIN = D\n EMIN = E\n CVDIAG = SUMSQ\n ENDIF\n ENDIF\n IJ = IJ + J \n END DO\n IF ( JMIN .GT. I ) CALL RCSWP( I, JMIN, A,B, INFI, N, COV )\n COV(II+I) = CVDIAG\n*\n* Compute Ith column of Cholesky factor.\n* Compute expected value for Ith integration variable and\n* scale Ith covariance matrix row and limits.\n*\n IF ( CVDIAG .GT. 0 ) THEN\n IL = II + I\n DO L = I+1, N-INFIS \n COV(IL+I) = COV(IL+I)/CVDIAG\n IJ = II + I\n DO J = I+1, L\n COV(IL+J) = COV(IL+J) - COV(IL+I)*COV(IJ+I)\n IJ = IJ + J\n END DO\n IL = IL + L\n END DO\n IF ( EMIN .GT. DMIN + EPS ) THEN\n YL = 0\n YU = 0\n IF ( INFI(I) .NE. 0 ) YL = -EXP( -AMIN**2/2 )/SQTWPI\n IF ( INFI(I) .NE. 1 ) YU = -EXP( -BMIN**2/2 )/SQTWPI\n Y(I) = ( YU - YL )/( EMIN - DMIN )\n ELSE\n IF ( INFI(I) .EQ. 0 ) Y(I) = BMIN\n IF ( INFI(I) .EQ. 1 ) Y(I) = AMIN\n IF ( INFI(I) .EQ. 2 ) Y(I) = ( AMIN + BMIN )/2\n END IF\n DO J = 1, I\n II = II + 1\n COV(II) = COV(II)/CVDIAG\n END DO\n A(I) = A(I)/CVDIAG\n B(I) = B(I)/CVDIAG\n ELSE\n IL = II + I\n DO L = I+1, N-INFIS \n COV(IL+I) = 0\n IL = IL + L\n END DO\n*\n* If the covariance matrix diagonal entry is zero, \n* permute limits and/or rows, if necessary.\n*\n*\n DO J = I-1, 1, -1\n IF ( ABS( COV(II+J) ) .GT. EPS ) THEN\n A(I) = A(I)/COV(II+J)\n B(I) = B(I)/COV(II+J)\n IF ( COV(II+J) .LT. 0 ) THEN\n CALL DKSWAP( A(I), B(I) ) \n IF ( INFI(I) .NE. 2 ) INFI(I) = 1 - INFI(I)\n END IF\n DO L = 1, J\n COV(II+L) = COV(II+L)/COV(II+J)\n END DO\n DO L = J+1, I-1 \n IF( COV((L-1)*L/2+J+1) .GT. 0 ) THEN\n IJ = II\n DO K = I-1, L, -1 \n DO M = 1, K\n CALL DKSWAP( COV(IJ-K+M), COV(IJ+M) )\n END DO\n CALL DKSWAP( A(K), A(K+1) ) \n CALL DKSWAP( B(K), B(K+1) ) \n M = INFI(K)\n INFI(K) = INFI(K+1)\n INFI(K+1) = M\n IJ = IJ - K \n END DO\n GO TO 20\n END IF\n END DO\n GO TO 20\n END IF\n COV(II+J) = 0\n END DO\n 20 II = II + I\n Y(I) = 0\n END IF\n END DO\n ENDIF\n END\n*\n SUBROUTINE DKSWAP( X, Y )\n DOUBLE PRECISION X, Y, T\n T = X\n X = Y\n Y = T\n END\n*\n SUBROUTINE RCSWP( P, Q, A, B, INFIN, N, C )\n*\n* Swaps rows and columns P and Q in situ, with P <= Q.\n*\n DOUBLE PRECISION A(*), B(*), C(*)\n INTEGER INFIN(*), P, Q, N, I, J, II, JJ\n CALL DKSWAP( A(P), A(Q) )\n CALL DKSWAP( B(P), B(Q) )\n J = INFIN(P)\n INFIN(P) = INFIN(Q)\n INFIN(Q) = J\n JJ = ( P*( P - 1 ) )/2\n II = ( Q*( Q - 1 ) )/2\n CALL DKSWAP( C(JJ+P), C(II+Q) )\n DO J = 1, P-1\n CALL DKSWAP( C(JJ+J), C(II+J) )\n END DO\n JJ = JJ + P\n DO I = P+1, Q-1\n CALL DKSWAP( C(JJ+P), C(II+I) )\n JJ = JJ + I\n END DO\n II = II + Q\n DO I = Q+1, N\n CALL DKSWAP( C(II+P), C(II+Q) )\n II = II + I\n END DO\n END\n*\n SUBROUTINE DKBVRC( NDIM, MINVLS, MAXVLS, FUNCTN, ABSEPS, RELEPS,\n & ABSERR, FINEST, INFORM )\n*\n* Automatic Multidimensional Integration Subroutine\n* \n* AUTHOR: Alan Genz\n* Department of Mathematics\n* Washington State University\n* Pulman, WA 99164-3113\n* Email: AlanGenz@wsu.edu\n*\n* Last Change: 1/15/03\n*\n* KRBVRC computes an approximation to the integral\n*\n* 1 1 1\n* I I ... I F(X) dx(NDIM)...dx(2)dx(1)\n* 0 0 0\n*\n*\n* DKBVRC uses randomized Korobov rules for the first 100 variables. \n* The primary references are\n* \"Randomization of Number Theoretic Methods for Multiple Integration\"\n* R. Cranley and T.N.L. Patterson, SIAM J Numer Anal, 13, pp. 904-14,\n* and \n* \"Optimal Parameters for Multidimensional Integration\", \n* P. Keast, SIAM J Numer Anal, 10, pp.831-838.\n* If there are more than 100 variables, the remaining variables are\n* integrated using the rules described in the reference\n* \"On a Number-Theoretical Integration Method\"\n* H. Niederreiter, Aequationes Mathematicae, 8(1972), pp. 304-11.\n* \n*************** Parameters ********************************************\n****** Input parameters\n* NDIM Number of variables, must exceed 1, but not exceed 40\n* MINVLS Integer minimum number of function evaluations allowed.\n* MINVLS must not exceed MAXVLS. If MINVLS < 0 then the\n* routine assumes a previous call has been made with \n* the same integrand and continues that calculation.\n* MAXVLS Integer maximum number of function evaluations allowed.\n* FUNCTN EXTERNALly declared user defined function to be integrated.\n* It must have parameters (NDIM,Z), where Z is a real array\n* of dimension NDIM.\n* \n* ABSEPS Required absolute accuracy.\n* RELEPS Required relative accuracy.\n****** Output parameters\n* MINVLS Actual number of function evaluations used.\n* ABSERR Estimated absolute accuracy of FINEST.\n* FINEST Estimated value of integral.\n* INFORM INFORM = 0 for normal exit, when \n* ABSERR <= MAX(ABSEPS, RELEPS*ABS(FINEST))\n* and \n* INTVLS <= MAXCLS.\n* INFORM = 1 If MAXVLS was too small to obtain the required \n* accuracy. In this case a value FINEST is returned with \n* estimated absolute accuracy ABSERR.\n************************************************************************\n EXTERNAL FUNCTN\n INTEGER NDIM, MINVLS, MAXVLS, INFORM, NP, PLIM, NLIM, KLIM, KLIMI,\n & SAMPLS, I, INTVLS, MINSMP\n PARAMETER ( PLIM = 28, NLIM = 1000, KLIM = 100, MINSMP = 8 )\n INTEGER P(PLIM), C(PLIM,KLIM-1) \n DOUBLE PRECISION FUNCTN, ABSEPS, RELEPS, FINEST, ABSERR, DIFINT, \n & FINVAL, VARSQR, VAREST, VARPRD, VALUE\n DOUBLE PRECISION X(2*NLIM), VK(NLIM), ONE\n PARAMETER ( ONE = 1 )\n SAVE P, C, SAMPLS, NP, VAREST\n INFORM = 1\n INTVLS = 0\n KLIMI = KLIM\n IF ( MINVLS .GE. 0 ) THEN\n FINEST = 0\n VAREST = 0\n SAMPLS = MINSMP \n DO I = MIN( NDIM, 10), PLIM\n NP = I\n IF ( MINVLS .LT. 2*SAMPLS*P(I) ) GO TO 10\n END DO\n SAMPLS = MAX( MINSMP, MINVLS/( 2*P(NP) ) )\n ENDIF\n 10 VK(1) = ONE/P(NP)\n DO I = 2, NDIM\n IF ( I .LE. KLIM ) THEN\n VK(I) = MOD( C(NP, MIN(NDIM-1,KLIM-1))*VK(I-1), ONE )\n ELSE\n VK(I) = INT( P(NP)*2**(DBLE(I-KLIM)/(NDIM-KLIM+1)) ) \n VK(I) = MOD( VK(I)/P(NP), ONE ) \n END IF\n END DO\n FINVAL = 0\n VARSQR = 0\n DO I = 1, SAMPLS\n CALL DKSMRC( NDIM, KLIMI, VALUE, P(NP), VK, FUNCTN, X )\n DIFINT = ( VALUE - FINVAL )/I\n FINVAL = FINVAL + DIFINT\n VARSQR = ( I - 2 )*VARSQR/I + DIFINT**2\n END DO\n INTVLS = INTVLS + 2*SAMPLS*P(NP)\n VARPRD = VAREST*VARSQR\n FINEST = FINEST + ( FINVAL - FINEST )/( 1 + VARPRD )\n IF ( VARSQR .GT. 0 ) VAREST = ( 1 + VARPRD )/VARSQR\n ABSERR = 7*SQRT( VARSQR/( 1 + VARPRD ) )/2\n IF ( ABSERR .GT. MAX( ABSEPS, ABS(FINEST)*RELEPS ) ) THEN\n IF ( NP .LT. PLIM ) THEN\n NP = NP + 1\n ELSE\n SAMPLS = MIN( 3*SAMPLS/2, ( MAXVLS - INTVLS )/( 2*P(NP) ) ) \n SAMPLS = MAX( MINSMP, SAMPLS )\n ENDIF\n IF ( INTVLS + 2*SAMPLS*P(NP) .LE. MAXVLS ) GO TO 10\n ELSE\n INFORM = 0\n ENDIF\n MINVLS = INTVLS\n*\n* Optimal Parameters for Lattice Rules\n*\n DATA P( 1),(C( 1,I),I = 1,99)/ 31, 12, 2*9, 13, 8*12, 3*3, 12,\n & 2*7, 9*12, 3*3, 12, 2*7, 9*12, 3*3, 12, 2*7, 9*12, 3*3, 12, 2*7,\n & 8*12, 7, 3*3, 3*7, 21*3/\n DATA P( 2),(C( 2,I),I = 1,99)/ 47, 13, 11, 17, 10, 6*15,\n & 22, 2*15, 3*6, 2*15, 9, 13, 3*2, 13, 2*11, 10, 9*15, 3*6, 2*15,\n & 9, 13, 3*2, 13, 2*11, 10, 9*15, 3*6, 2*15, 9, 13, 3*2, 13, 2*11,\n & 2*10, 8*15, 6, 2, 3, 2, 3, 12*2/\n DATA P( 3),(C( 3,I),I = 1,99)/ 73, 27, 28, 10, 2*11, 20,\n & 2*11, 28, 2*13, 28, 3*13, 16*14, 2*31, 3*5, 31, 13, 6*11, 7*13,\n & 16*14, 2*31, 3*5, 11, 13, 7*11, 2*13, 11, 13, 4*5, 14, 13, 8*5/\n DATA P( 4),(C( 4,I),I = 1,99)/ 113, 35, 2*27, 36, 22, 2*29,\n & 20, 45, 3*5, 16*21, 29, 10*17, 12*23, 21, 27, 3*3, 24, 2*27,\n & 17, 3*29, 17, 4*5, 16*21, 3*17, 6, 2*17, 6, 3, 2*6, 5*3/\n DATA P( 5),(C( 5,I),I = 1,99)/ 173, 64, 66, 2*28, 2*44, 55,\n & 67, 6*10, 2*38, 5*10, 12*49, 2*38, 31, 2*4, 31, 64, 3*4, 64,\n & 6*45, 19*66, 11, 9*66, 45, 11, 7, 3, 3*2, 27, 5, 2*3, 2*5, 7*2/\n DATA P( 6),(C( 6,I),I = 1,99)/ 263, 111, 42, 54, 118, 20,\n & 2*31, 72, 17, 94, 2*14, 11, 3*14, 94, 4*10, 7*14, 3*11, 7*8,\n & 5*18, 113, 2*62, 2*45, 17*113, 2*63, 53, 63, 15*67, 5*51, 12,\n & 51, 12, 51, 5, 2*3, 2*2, 5/\n DATA P( 7),(C( 7,I),I = 1,99)/ 397, 163, 154, 83, 43, 82,\n & 92, 150, 59, 2*76, 47, 2*11, 100, 131, 6*116, 9*138, 21*101,\n & 6*116, 5*100, 5*138, 19*101, 8*38, 5*3/\n DATA P( 8),(C( 8,I),I = 1,99)/ 593, 246, 189, 242, 102,\n & 2*250, 102, 250, 280, 118, 196, 118, 191, 215, 2*121,\n & 12*49, 34*171, 8*161, 17*14, 6*10, 103, 4*10, 5/\n DATA P( 9),(C( 9,I),I = 1,99)/ 907, 347, 402, 322, 418,\n & 215, 220, 3*339, 337, 218, 4*315, 4*167, 361, 201, 11*124,\n & 2*231, 14*90, 4*48, 23*90, 10*243, 9*283, 16, 283, 16, 2*283/\n DATA P(10),(C(10,I),I = 1,99)/ 1361, 505, 220, 601, 644,\n & 612, 160, 3*206, 422, 134, 518, 2*134, 518, 652, 382,\n & 206, 158, 441, 179, 441, 56, 2*559, 14*56, 2*101, 56,\n & 8*101, 7*193, 21*101, 17*122, 4*101/\n DATA P(11),(C(11,I),I = 1,99)/ 2053, 794, 325, 960, 528,\n & 2*247, 338, 366, 847, 2*753, 236, 2*334, 461, 711, 652,\n & 3*381, 652, 7*381, 226, 7*326, 126, 10*326, 2*195, 19*55,\n & 7*195, 11*132, 13*387/\n DATA P(12),(C(12,I),I = 1,99)/ 3079, 1189, 888, 259, 1082, 725, \n & 811, 636, 965, 2*497, 2*1490, 392, 1291, 2*508, 2*1291, 508,\n & 1291, 2*508, 4*867, 934, 7*867, 9*1284, 4*563, 3*1010, 208,\n & 838, 3*563, 2*759, 564, 2*759, 4*801, 5*759, 8*563, 22*226/\n DATA P(13),(C(13,I),I = 1,99)/ 4621, 1763, 1018, 1500, 432,\n & 1332, 2203, 126, 2240, 1719, 1284, 878, 1983, 4*266,\n & 2*747, 2*127, 2074, 127, 2074, 1400, 10*1383, 1400, 7*1383,\n & 507, 4*1073, 5*1990, 9*507, 17*1073, 6*22, 1073, 6*452, 318,\n & 4*301, 2*86, 15/\n DATA P(14),(C(14,I),I = 1,99)/ 6947, 2872, 3233, 1534, 2941,\n & 2910, 393, 1796, 919, 446, 2*919, 1117, 7*103, 2311, 3117, 1101,\n & 2*3117, 5*1101, 8*2503, 7*429, 3*1702, 5*184, 34*105, 13*784/\n DATA P(15),(C(15,I),I = 1,99)/ 10427, 4309, 3758, 4034, 1963,\n & 730, 642, 1502, 2246, 3834, 1511, 2*1102, 2*1522, 2*3427,\n & 3928, 2*915, 4*3818, 3*4782, 3818, 4782, 2*3818, 7*1327, 9*1387,\n & 13*2339, 18*3148, 3*1776, 3*3354, 925, 2*3354, 5*925, 8*2133/\n DATA P(16),(C(16,I),I = 1,99)/ 15641, 6610, 6977, 1686, 3819,\n & 2314, 5647, 3953, 3614, 5115, 2*423, 5408, 7426, 2*423,\n & 487, 6227, 2660, 6227, 1221, 3811, 197, 4367, 351,\n & 1281, 1221, 3*351, 7245, 1984, 6*2999, 3995, 4*2063, 1644,\n & 2063, 2077, 3*2512, 4*2077, 19*754, 2*1097, 4*754, 248, 754,\n & 4*1097, 4*222, 754,11*1982/\n DATA P(17),(C(17,I),I = 1,99)/ 23473, 9861, 3647, 4073, 2535,\n & 3430, 9865, 2830, 9328, 4320, 5913, 10365, 8272, 3706, 6186,\n & 3*7806, 8610, 2563, 2*11558, 9421, 1181, 9421, 3*1181, 9421,\n & 2*1181, 2*10574, 5*3534, 3*2898, 3450, 7*2141, 15*7055, 2831,\n & 24*8204, 3*4688, 8*2831/\n DATA P(18),(C(18,I),I = 1,99)/ 35221, 10327, 7582, 7124, 8214,\n & 9600, 10271, 10193, 10800, 9086, 2365, 4409, 13812,\n & 5661, 2*9344, 10362, 2*9344, 8585, 11114, 3*13080, 6949,\n & 3*3436, 13213, 2*6130, 2*8159, 11595, 8159, 3436, 18*7096,\n & 4377, 7096, 5*4377, 2*5410, 32*4377, 2*440, 3*1199/\n DATA P(19),(C(19,I),I = 1,99)/ 52837, 19540, 19926, 11582,\n & 11113, 24585, 8726, 17218, 419, 3*4918, 15701, 17710,\n & 2*4037, 15808, 11401, 19398, 2*25950, 4454, 24987, 11719,\n & 8697, 5*1452, 2*8697, 6436, 21475, 6436, 22913, 6434, 18497,\n & 4*11089, 2*3036, 4*14208, 8*12906, 4*7614, 6*5021, 24*10145,\n & 6*4544, 4*8394/ \n DATA P(20),(C(20,I),I = 1,99)/ 79259, 34566, 9579, 12654,\n & 26856, 37873, 38806, 29501, 17271, 3663, 10763, 18955,\n & 1298, 26560, 2*17132, 2*4753, 8713, 18624, 13082, 6791,\n & 1122, 19363, 34695, 4*18770, 15628, 4*18770, 33766, 6*20837,\n & 5*6545, 14*12138, 5*30483, 19*12138, 9305, 13*11107, 2*9305/\n DATA P(21),(C(21,I),I = 1,99)/118891, 31929, 49367, 10982, 3527,\n & 27066, 13226, 56010, 18911, 40574, 2*20767, 9686, 2*47603, \n & 2*11736, 41601, 12888, 32948, 30801, 44243, 2*53351, 16016, \n & 2*35086, 32581, 2*2464, 49554, 2*2464, 2*49554, 2464, 81, 27260, \n & 10681, 7*2185, 5*18086, 2*17631, 3*18086, 37335, 3*37774, \n & 13*26401, 12982, 6*40398, 3*3518, 9*37799, 4*4721, 4*7067/\n DATA P(22),(C(22,I),I = 1,99)/178349, 40701, 69087, 77576, 64590, \n & 39397, 33179, 10858, 38935, 43129, 2*35468, 5279, 2*61518, 27945,\n & 2*70975, 2*86478, 2*20514, 2*73178, 2*43098, 4701,\n & 2*59979, 58556, 69916, 2*15170, 2*4832, 43064, 71685, 4832,\n & 3*15170, 3*27679, 2*60826, 2*6187, 5*4264, 45567, 4*32269,\n & 9*62060, 13*1803, 12*51108, 2*55315, 5*54140, 13134/\n DATA P(23),(C(23,I),I = 1,99)/267523, 103650, 125480, 59978,\n & 46875, 77172, 83021, 126904, 14541, 56299, 43636, 11655,\n & 52680, 88549, 29804, 101894, 113675, 48040, 113675,\n & 34987, 48308, 97926, 5475, 49449, 6850, 2*62545, 9440,\n & 33242, 9440, 33242, 9440, 33242, 9440, 62850, 3*9440,\n & 3*90308, 9*47904, 7*41143, 5*36114, 24997, 14*65162, 7*47650,\n & 7*40586, 4*38725, 5*88329/\n DATA P(24),(C(24,I),I = 1,99)/401287, 165843, 90647, 59925,\n & 189541, 67647, 74795, 68365, 167485, 143918, 74912,\n & 167289, 75517, 8148, 172106, 126159,3*35867, 121694,\n & 52171, 95354, 2*113969, 76304, 2*123709, 144615, 123709,\n & 2*64958, 32377, 2*193002, 25023, 40017, 141605, 2*189165,\n & 141605, 2*189165, 3*141605, 189165, 20*127047, 10*127785,\n & 6*80822, 16*131661, 7114, 131661/\n DATA P(25),(C(25,I),I = 1,99)/601942, 130365, 236711, 110235,\n & 125699, 56483, 93735, 234469, 60549, 1291, 93937,\n & 245291, 196061, 258647, 162489, 176631, 204895, 73353,\n & 172319, 28881, 136787,2*122081, 275993, 64673, 3*211587,\n & 2*282859, 211587, 242821, 3*256865, 122203, 291915, 122203,\n & 2*291915, 122203, 2*25639, 291803, 245397, 284047,\n & 7*245397, 94241, 2*66575, 19*217673, 10*210249, 15*94453/\n DATA P(26),(C(26,I),I = 1,99)/902933, 333459, 375354, 102417, \n & 383544, 292630, 41147, 374614, 48032, 435453, 281493, 358168, \n & 114121, 346892, 238990, 317313, 164158, 35497, 2*70530, 434839, \n & 3*24754, 393656, 2*118711, 148227, 271087, 355831, 91034, \n & 2*417029, 2*91034, 417029, 91034, 2*299843, 2*413548, 308300, \n & 3*413548, 3*308300, 413548, 5*308300, 4*15311, 2*176255, 6*23613, \n & 172210, 4* 204328, 5*121626, 5*200187, 2*121551, 12*248492, \n & 5*13942/\n DATA P(27), (C(27,I), I = 1,99)/ 1354471, 500884, 566009, 399251,\n & 652979, 355008, 430235, 328722, 670680, 2*405585, 424646, \n & 2*670180, 641587, 215580, 59048, 633320, 81010, 20789, 2*389250, \n & 2*638764, 2*389250, 398094, 80846, 2*147776, 296177, 2*398094, \n & 2*147776, 396313, 3*578233, 19482, 620706, 187095, 620706, \n & 187095, 126467, 12*241663, 321632, 2*23210, 3*394484, 3*78101, \n & 19*542095, 3*277743, 12*457259/\n DATA P(28), (C(28,I), I = 1, 99)/ 2031713, 858339, 918142, 501970, \n & 234813, 460565, 31996, 753018, 256150, 199809, 993599, 245149, \n & 794183, 121349, 150619, 376952, 2*809123, 804319, 67352, 969594, \n & 434796, 969594, 804319, 391368, 761041, 754049, 466264, 2*754049,\n & 466264, 2*754049, 282852, 429907, 390017, 276645, 994856, 250142, \n & 144595, 907454, 689648, 4*687580, 978368, 687580, 552742, 105195, \n & 942843, 768249, 4*307142, 7*880619, 11*117185, 11*60731, \n & 4*178309, 8*74373, 3*214965/\n*\n END\n*\n SUBROUTINE DKSMRC( NDIM, KLIM, SUMKRO, PRIME, VK, FUNCTN, X )\n EXTERNAL FUNCTN\n INTEGER NDIM, NK, KLIM, PRIME, K, J, JP\n DOUBLE PRECISION SUMKRO, VK(*), FUNCTN, X(*), ONE, XT, MVNUNI\n PARAMETER ( ONE = 1 )\n SUMKRO = 0\n NK = MIN( NDIM, KLIM )\n DO J = 1, NK - 1\n JP = J + MVNUNI()*( NK + 1 - J ) \n XT = VK(J)\n VK(J) = VK(JP)\n VK(JP) = XT\n END DO\n DO J = 1, NDIM\n X(NDIM+J) = MVNUNI()\n END DO\n DO K = 1, PRIME\n DO J = 1, NDIM\n X(J) = ABS( 2*MOD( K*VK(J) + X(NDIM+J), ONE ) - 1 )\n END DO\n SUMKRO = SUMKRO + ( FUNCTN(NDIM,X) - SUMKRO )/( 2*K - 1 )\n DO J = 1, NDIM\n X(J) = 1 - X(J)\n END DO\n SUMKRO = SUMKRO + ( FUNCTN(NDIM,X) - SUMKRO )/( 2*K )\n END DO\n END\n*\n DOUBLE PRECISION FUNCTION MVNPHI( Z )\n* \n* Normal distribution probabilities accurate to 1.e-15.\n* Z = no. of standard deviations from the mean.\n* \n* Based upon algorithm 5666 for the error function, from:\n* Hart, J.F. et al, 'Computer Approximations', Wiley 1968\n* \n* Programmer: Alan Miller\n* \n* Latest revision - 30 March 1986\n* \n DOUBLE PRECISION P0, P1, P2, P3, P4, P5, P6, \n * Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7,\n * Z, P, EXPNTL, CUTOFF, ROOTPI, ZABS\n PARAMETER(\n * P0 = 220.20 68679 12376 1D0,\n * P1 = 221.21 35961 69931 1D0, \n * P2 = 112.07 92914 97870 9D0,\n * P3 = 33.912 86607 83830 0D0,\n * P4 = 6.3739 62203 53165 0D0,\n * P5 = .70038 30644 43688 1D0, \n * P6 = .035262 49659 98910 9D0 )\n PARAMETER(\n * Q0 = 440.41 37358 24752 2D0,\n * Q1 = 793.82 65125 19948 4D0, \n * Q2 = 637.33 36333 78831 1D0,\n * Q3 = 296.56 42487 79673 7D0, \n * Q4 = 86.780 73220 29460 8D0,\n * Q5 = 16.064 17757 92069 5D0, \n * Q6 = 1.7556 67163 18264 2D0,\n * Q7 = .088388 34764 83184 4D0 )\n PARAMETER( ROOTPI = 2.5066 28274 63100 1D0 )\n PARAMETER( CUTOFF = 7.0710 67811 86547 5D0 )\n* \n ZABS = ABS(Z)\n* \n* |Z| > 37\n* \n IF ( ZABS .GT. 37 ) THEN\n P = 0\n ELSE\n* \n* |Z| <= 37\n* \n EXPNTL = EXP( -ZABS**2/2 )\n* \n* |Z| < CUTOFF = 10/SQRT(2)\n* \n IF ( ZABS .LT. CUTOFF ) THEN\n P = EXPNTL*( (((((P6*ZABS + P5)*ZABS + P4)*ZABS + P3)*ZABS\n * + P2)*ZABS + P1)*ZABS + P0)/(((((((Q7*ZABS + Q6)*ZABS\n * + Q5)*ZABS + Q4)*ZABS + Q3)*ZABS + Q2)*ZABS + Q1)*ZABS\n * + Q0 )\n* \n* |Z| >= CUTOFF.\n* \n ELSE\n P = EXPNTL/( ZABS + 1/( ZABS + 2/( ZABS + 3/( ZABS \n * + 4/( ZABS + 0.65D0 ) ) ) ) )/ROOTPI\n END IF\n END IF\n IF ( Z .GT. 0 ) P = 1 - P\n MVNPHI = P\n END\n DOUBLE PRECISION FUNCTION PHINVS(P)\n*\n*\tALGORITHM AS241 APPL. STATIST. (1988) VOL. 37, NO. 3\n*\n*\tProduces the normal deviate Z corresponding to a given lower\n*\ttail area of P.\n*\n*\tThe hash sums below are the sums of the mantissas of the\n*\tcoefficients. They are included for use in checking\n*\ttranscription.\n*\n DOUBLE PRECISION SPLIT1, SPLIT2, CONST1, CONST2, \n * A0, A1, A2, A3, A4, A5, A6, A7, B1, B2, B3, B4, B5, B6, B7, \n * C0, C1, C2, C3, C4, C5, C6, C7, D1, D2, D3, D4, D5, D6, D7, \n * E0, E1, E2, E3, E4, E5, E6, E7, F1, F2, F3, F4, F5, F6, F7, \n * P, Q, R\n PARAMETER ( SPLIT1 = 0.425, SPLIT2 = 5,\n * CONST1 = 0.180625D0, CONST2 = 1.6D0 )\n* \n* Coefficients for P close to 0.5\n* \n PARAMETER (\n * A0 = 3.38713 28727 96366 6080D0,\n * A1 = 1.33141 66789 17843 7745D+2,\n * A2 = 1.97159 09503 06551 4427D+3,\n * A3 = 1.37316 93765 50946 1125D+4,\n * A4 = 4.59219 53931 54987 1457D+4,\n * A5 = 6.72657 70927 00870 0853D+4,\n * A6 = 3.34305 75583 58812 8105D+4,\n * A7 = 2.50908 09287 30122 6727D+3,\n * B1 = 4.23133 30701 60091 1252D+1,\n * B2 = 6.87187 00749 20579 0830D+2,\n * B3 = 5.39419 60214 24751 1077D+3,\n * B4 = 2.12137 94301 58659 5867D+4,\n * B5 = 3.93078 95800 09271 0610D+4,\n * B6 = 2.87290 85735 72194 2674D+4,\n * B7 = 5.22649 52788 52854 5610D+3 )\n* HASH SUM AB 55.88319 28806 14901 4439\n* \n* Coefficients for P not close to 0, 0.5 or 1.\n* \n PARAMETER (\n * C0 = 1.42343 71107 49683 57734D0,\n * C1 = 4.63033 78461 56545 29590D0,\n * C2 = 5.76949 72214 60691 40550D0,\n * C3 = 3.64784 83247 63204 60504D0,\n * C4 = 1.27045 82524 52368 38258D0,\n * C5 = 2.41780 72517 74506 11770D-1,\n * C6 = 2.27238 44989 26918 45833D-2,\n * C7 = 7.74545 01427 83414 07640D-4,\n * D1 = 2.05319 16266 37758 82187D0,\n * D2 = 1.67638 48301 83803 84940D0,\n * D3 = 6.89767 33498 51000 04550D-1,\n * D4 = 1.48103 97642 74800 74590D-1,\n * D5 = 1.51986 66563 61645 71966D-2,\n * D6 = 5.47593 80849 95344 94600D-4,\n * D7 = 1.05075 00716 44416 84324D-9 )\n* HASH SUM CD 49.33206 50330 16102 89036\n*\n*\tCoefficients for P near 0 or 1.\n*\n PARAMETER (\n * E0 = 6.65790 46435 01103 77720D0,\n * E1 = 5.46378 49111 64114 36990D0,\n * E2 = 1.78482 65399 17291 33580D0,\n * E3 = 2.96560 57182 85048 91230D-1,\n * E4 = 2.65321 89526 57612 30930D-2,\n * E5 = 1.24266 09473 88078 43860D-3,\n * E6 = 2.71155 55687 43487 57815D-5,\n * E7 = 2.01033 43992 92288 13265D-7,\n * F1 = 5.99832 20655 58879 37690D-1,\n * F2 = 1.36929 88092 27358 05310D-1,\n * F3 = 1.48753 61290 85061 48525D-2,\n * F4 = 7.86869 13114 56132 59100D-4,\n * F5 = 1.84631 83175 10054 68180D-5,\n * F6 = 1.42151 17583 16445 88870D-7,\n * F7 = 2.04426 31033 89939 78564D-15 )\n* HASH SUM EF 47.52583 31754 92896 71629\n* \n Q = ( 2*P - 1 )/2\n IF ( ABS(Q) .LE. SPLIT1 ) THEN\n R = CONST1 - Q*Q\n PHINVS = Q*( ( ( ((((A7*R + A6)*R + A5)*R + A4)*R + A3)\n * *R + A2 )*R + A1 )*R + A0 )\n * /( ( ( ((((B7*R + B6)*R + B5)*R + B4)*R + B3)\n * *R + B2 )*R + B1 )*R + 1 )\n ELSE\n R = MIN( P, 1 - P )\n IF ( R .GT. 0 ) THEN\n R = SQRT( -LOG(R) )\n IF ( R .LE. SPLIT2 ) THEN\n R = R - CONST2\n PHINVS = ( ( ( ((((C7*R + C6)*R + C5)*R + C4)*R + C3)\n * *R + C2 )*R + C1 )*R + C0 ) \n * /( ( ( ((((D7*R + D6)*R + D5)*R + D4)*R + D3)\n * *R + D2 )*R + D1 )*R + 1 )\n ELSE\n R = R - SPLIT2\n PHINVS = ( ( ( ((((E7*R + E6)*R + E5)*R + E4)*R + E3)\n * *R + E2 )*R + E1 )*R + E0 )\n * /( ( ( ((((F7*R + F6)*R + F5)*R + F4)*R + F3)\n * *R + F2 )*R + F1 )*R + 1 )\n END IF\n ELSE\n PHINVS = 9\n END IF\n IF ( Q .LT. 0 ) PHINVS = - PHINVS\n END IF\n END\n DOUBLE PRECISION FUNCTION BVNMVN( LOWER, UPPER, INFIN, CORREL )\n*\n* A function for computing bivariate normal probabilities.\n*\n* Parameters\n*\n* LOWER REAL, array of lower integration limits.\n* UPPER REAL, array of upper integration limits.\n* INFIN INTEGER, array of integration limits flags:\n* if INFIN(I) = 0, Ith limits are (-infinity, UPPER(I)];\n* if INFIN(I) = 1, Ith limits are [LOWER(I), infinity);\n* if INFIN(I) = 2, Ith limits are [LOWER(I), UPPER(I)].\n* CORREL REAL, correlation coefficient.\n*\n DOUBLE PRECISION LOWER(*), UPPER(*), CORREL, BVU\n INTEGER INFIN(*)\n IF ( INFIN(1) .EQ. 2 .AND. INFIN(2) .EQ. 2 ) THEN\n BVNMVN = BVU ( LOWER(1), LOWER(2), CORREL )\n + - BVU ( UPPER(1), LOWER(2), CORREL )\n + - BVU ( LOWER(1), UPPER(2), CORREL )\n + + BVU ( UPPER(1), UPPER(2), CORREL )\n ELSE IF ( INFIN(1) .EQ. 2 .AND. INFIN(2) .EQ. 1 ) THEN\n BVNMVN = BVU ( LOWER(1), LOWER(2), CORREL )\n + - BVU ( UPPER(1), LOWER(2), CORREL )\n ELSE IF ( INFIN(1) .EQ. 1 .AND. INFIN(2) .EQ. 2 ) THEN\n BVNMVN = BVU ( LOWER(1), LOWER(2), CORREL )\n + - BVU ( LOWER(1), UPPER(2), CORREL )\n ELSE IF ( INFIN(1) .EQ. 2 .AND. INFIN(2) .EQ. 0 ) THEN\n BVNMVN = BVU ( -UPPER(1), -UPPER(2), CORREL )\n + - BVU ( -LOWER(1), -UPPER(2), CORREL )\n ELSE IF ( INFIN(1) .EQ. 0 .AND. INFIN(2) .EQ. 2 ) THEN\n BVNMVN = BVU ( -UPPER(1), -UPPER(2), CORREL )\n + - BVU ( -UPPER(1), -LOWER(2), CORREL )\n ELSE IF ( INFIN(1) .EQ. 1 .AND. INFIN(2) .EQ. 0 ) THEN\n BVNMVN = BVU ( LOWER(1), -UPPER(2), -CORREL )\n ELSE IF ( INFIN(1) .EQ. 0 .AND. INFIN(2) .EQ. 1 ) THEN\n BVNMVN = BVU ( -UPPER(1), LOWER(2), -CORREL )\n ELSE IF ( INFIN(1) .EQ. 1 .AND. INFIN(2) .EQ. 1 ) THEN\n BVNMVN = BVU ( LOWER(1), LOWER(2), CORREL )\n ELSE IF ( INFIN(1) .EQ. 0 .AND. INFIN(2) .EQ. 0 ) THEN\n BVNMVN = BVU ( -UPPER(1), -UPPER(2), CORREL )\n END IF\n END \n DOUBLE PRECISION FUNCTION BVU( SH, SK, R )\n*\n* A function for computing bivariate normal probabilities.\n*\n* Yihong Ge\n* Department of Computer Science and Electrical Engineering\n* Washington State University\n* Pullman, WA 99164-2752\n* and\n* Alan Genz\n* Department of Mathematics\n* Washington State University\n* Pullman, WA 99164-3113\n* Email : alangenz@wsu.edu\n*\n* BVN - calculate the probability that X is larger than SH and Y is\n* larger than SK.\n*\n* Parameters\n*\n* SH REAL, integration limit\n* SK REAL, integration limit\n* R REAL, correlation coefficient\n* LG INTEGER, number of Gauss Rule Points and Weights\n*\n DOUBLE PRECISION BVN, SH, SK, R, ZERO, TWOPI \n INTEGER I, LG, NG\n PARAMETER ( ZERO = 0, TWOPI = 6.283185307179586D0 ) \n DOUBLE PRECISION X(10,3), W(10,3), AS, A, B, C, D, RS, XS\n DOUBLE PRECISION MVNPHI, SN, ASR, H, K, BS, HS, HK\n SAVE X, W\n* Gauss Legendre Points and Weights, N = 6\n DATA ( W(I,1), X(I,1), I = 1,3) /\n * 0.1713244923791705D+00,-0.9324695142031522D+00,\n * 0.3607615730481384D+00,-0.6612093864662647D+00,\n * 0.4679139345726904D+00,-0.2386191860831970D+00/\n* Gauss Legendre Points and Weights, N = 12\n DATA ( W(I,2), X(I,2), I = 1,6) /\n * 0.4717533638651177D-01,-0.9815606342467191D+00,\n * 0.1069393259953183D+00,-0.9041172563704750D+00,\n * 0.1600783285433464D+00,-0.7699026741943050D+00,\n * 0.2031674267230659D+00,-0.5873179542866171D+00,\n * 0.2334925365383547D+00,-0.3678314989981802D+00,\n * 0.2491470458134029D+00,-0.1252334085114692D+00/\n* Gauss Legendre Points and Weights, N = 20\n DATA ( W(I,3), X(I,3), I = 1,10) /\n * 0.1761400713915212D-01,-0.9931285991850949D+00,\n * 0.4060142980038694D-01,-0.9639719272779138D+00,\n * 0.6267204833410906D-01,-0.9122344282513259D+00,\n * 0.8327674157670475D-01,-0.8391169718222188D+00,\n * 0.1019301198172404D+00,-0.7463319064601508D+00,\n * 0.1181945319615184D+00,-0.6360536807265150D+00,\n * 0.1316886384491766D+00,-0.5108670019508271D+00,\n * 0.1420961093183821D+00,-0.3737060887154196D+00,\n * 0.1491729864726037D+00,-0.2277858511416451D+00,\n * 0.1527533871307259D+00,-0.7652652113349733D-01/\n IF ( ABS(R) .LT. 0.3 ) THEN\n NG = 1\n LG = 3\n ELSE IF ( ABS(R) .LT. 0.75 ) THEN\n NG = 2\n LG = 6\n ELSE \n NG = 3\n LG = 10\n ENDIF\n H = SH\n K = SK \n HK = H*K\n BVN = 0\n IF ( ABS(R) .LT. 0.925 ) THEN\n HS = ( H*H + K*K )/2\n ASR = ASIN(R)\n DO I = 1, LG\n SN = SIN(ASR*( X(I,NG)+1 )/2)\n BVN = BVN + W(I,NG)*EXP( ( SN*HK - HS )/( 1 - SN*SN ) )\n SN = SIN(ASR*(-X(I,NG)+1 )/2)\n BVN = BVN + W(I,NG)*EXP( ( SN*HK - HS )/( 1 - SN*SN ) )\n END DO\n BVN = BVN*ASR/(2*TWOPI) + MVNPHI(-H)*MVNPHI(-K) \n ELSE\n IF ( R .LT. 0 ) THEN\n K = -K\n HK = -HK\n ENDIF\n IF ( ABS(R) .LT. 1 ) THEN\n AS = ( 1 - R )*( 1 + R )\n A = SQRT(AS)\n BS = ( H - K )**2\n C = ( 4 - HK )/8 \n D = ( 12 - HK )/16\n BVN = A*EXP( -(BS/AS + HK)/2 )\n + *( 1 - C*(BS - AS)*(1 - D*BS/5)/3 + C*D*AS*AS/5 )\n IF ( HK .GT. -160 ) THEN\n B = SQRT(BS)\n BVN = BVN - EXP(-HK/2)*SQRT(TWOPI)*MVNPHI(-B/A)*B\n + *( 1 - C*BS*( 1 - D*BS/5 )/3 ) \n ENDIF\n A = A/2\n DO I = 1, LG\n XS = ( A*(X(I,NG)+1) )**2\n RS = SQRT( 1 - XS )\n BVN = BVN + A*W(I,NG)*\n + ( EXP( -BS/(2*XS) - HK/(1+RS) )/RS \n + - EXP( -(BS/XS+HK)/2 )*( 1 + C*XS*( 1 + D*XS ) ) )\n XS = AS*(-X(I,NG)+1)**2/4\n RS = SQRT( 1 - XS )\n BVN = BVN + A*W(I,NG)*EXP( -(BS/XS + HK)/2 )\n + *( EXP( -HK*(1-RS)/(2*(1+RS)) )/RS \n + - ( 1 + C*XS*( 1 + D*XS ) ) )\n END DO\n BVN = -BVN/TWOPI\n ENDIF\n IF ( R .GT. 0 ) BVN = BVN + MVNPHI( -MAX( H, K ) )\n IF ( R .LT. 0 ) BVN = -BVN + MAX( ZERO, MVNPHI(-H)-MVNPHI(-K) ) \n ENDIF\n BVU = BVN\n END\n DOUBLE PRECISION FUNCTION MVNUNI()\n*\n* Uniform (0,1) random number generator\n*\n* Reference:\n* L'Ecuyer, Pierre (1996), \n* \"Combined Multiple Recursive Random Number Generators\"\n* Operations Research 44, pp. 816-822.\n*\n*\n INTEGER A12, A13, A21, A23, P12, P13, P21, P23\n INTEGER Q12, Q13, Q21, Q23, R12, R13, R21, R23\n INTEGER X10, X11, X12, X20, X21, X22, Z, M1, M2, H \n DOUBLE PRECISION INVMP1\n PARAMETER ( M1 = 2147483647, M2 = 2145483479 )\n PARAMETER ( A12 = 63308, Q12 = 33921, R12 = 12979 )\n PARAMETER ( A13 = -183326, Q13 = 11714, R13 = 2883 )\n PARAMETER ( A21 = 86098, Q21 = 24919, R21 = 7417 )\n PARAMETER ( A23 = -539608, Q23 = 3976, R23 = 2071 )\n PARAMETER ( INVMP1 = 4.656612873077392578125D-10 ) \n* INVMP1 = 1/(M1+1)\n SAVE X10, X11, X12, X20, X21, X22\n DATA X10, X11, X12, X20, X21, X22 \n & / 15485857, 17329489, 36312197, 55911127, 75906931, 96210113 / \n*\n* Component 1\n*\n H = X10/Q13\n P13 = -A13*( X10 - H*Q13 ) - H*R13\n H = X11/Q12\n P12 = A12*( X11 - H*Q12 ) - H*R12\n IF ( P13 .LT. 0 ) P13 = P13 + M1\n IF ( P12 .LT. 0 ) P12 = P12 + M1\n X10 = X11 \n X11 = X12\n X12 = P12 - P13\n IF ( X12 .LT. 0 ) X12 = X12 + M1\n*\n* Component 2\n*\n H = X20/Q23\n P23 = -A23*( X20 - H*Q23 ) - H*R23\n H = X22/Q21\n P21 = A21*( X22 - H*Q21 ) - H*R21\n IF ( P23 .LT. 0 ) P23 = P23 + M2\n IF ( P21 .LT. 0 ) P21 = P21 + M2\n X20 = X21 \n X21 = X22\n X22 = P21 - P23\n IF ( X22 .LT. 0 ) X22 = X22 + M2\n*\n* Combination\n*\n Z = X12 - X22\n IF ( Z .LE. 0 ) Z = Z + M1\n MVNUNI = Z*INVMP1\n END\n", "meta": {"hexsha": "a7851e3d2ab401d2c71737d75a7d9475fbe8ec5e", "size": 43940, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "scipy/stats/mvndst.f", "max_stars_repo_name": "lesserwhirls/scipy-cwt", "max_stars_repo_head_hexsha": "ee673656d879d9356892621e23ed0ced3d358621", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2015-10-07T00:37:32.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-21T17:02:33.000Z", "max_issues_repo_path": "scipy/stats/mvndst.f", "max_issues_repo_name": "lesserwhirls/scipy-cwt", "max_issues_repo_head_hexsha": "ee673656d879d9356892621e23ed0ced3d358621", "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": "scipy/stats/mvndst.f", "max_forks_repo_name": "lesserwhirls/scipy-cwt", "max_forks_repo_head_hexsha": "ee673656d879d9356892621e23ed0ced3d358621", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2015-05-09T14:23:57.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-15T05:56:00.000Z", "avg_line_length": 38.9884649512, "max_line_length": 79, "alphanum_fraction": 0.4917614929, "num_tokens": 17960, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.7606506635289835, "lm_q1q2_score": 0.6772028894075324}} {"text": "\n PROGRAM CBEX01\nC\nC LATEST REVISION September, 1989\nC\nC PURPOSE To provide a simple demonstration of the\nC use of BIVAR and CONPACK together as a\nC temporary replacement for CONRAN.\nC\nC PRECISION Single.\nC\nC REQUIRED LIBRARY BIVAR, CONPACK.\nC FILES\nC\nC LANGUAGE FORTRAN.\nC\nC HISTORY Written September, 1989, by Dave Kennison.\nC\nC ALGORITHM At each of nine points scattered \"at random\"\nC in a portion of the x/y plane, a mathematical\nC function is evaluated to obtain a value of z.\nC The resulting triplets approximately describe\nC the surface which is defined exactly by the\nC function. The routine BIVAR is then called to\nC obtain an array of interpolated values of z on\nC a regular grid, approximating the same surface,\nC and this data is used as input to CONPACK to\nC draw two different contour plots.\nC\nC On the first plot, contours are shown in a\nC rectangular area containing the x/y positions\nC of the original nine data points and those\nC positions are marked on the plot.\nC\nC On the second plot, capabilities of CONPACK\nC and AREAS are used to limit the drawing of\nC contours to the convex hull of the original\nC nine x/y positions.\nC\nC PORTABILITY ANSI standard.\nC\nC\nC Define the error file, the Fortran unit number, the workstation type,\nC and the workstation ID to be used in calls to GKS routines.\nC\nC PARAMETER (IERRF=6, LUNIT=2, IWTYPE=1, IWKID=1) ! NCGM\nC PARAMETER (IERRF=6, LUNIT=2, IWTYPE=8, IWKID=1) ! X Windows\nC PARAMETER (IERRF=6, LUNIT=2, IWTYPE=11, IWKID=1) ! PDF\nC PARAMETER (IERRF=6, LUNIT=2, IWTYPE=20, IWKID=1) ! PostScript\nC\n PARAMETER (IERRF=6, LUNIT=2, IWTYPE=1, IWKID=1)\nC\nC Define arrays to be used below. XRAN, YRAN, and ZRAN are used for\nC the \"random data\". XCNV and YCNV are used to define the convex hull\nC of the x/y positions of this data. XDAT, YDAT, and ZDAT are used for\nC the regular grid of data returned by BIVAR. IWRK and RWRK are used\nC as integer and real workspace arrays, both in calls to BIVAR and in\nC calls to CONPACK.\nC\n DIMENSION XRAN(9),YRAN(9),ZRAN(9),XCNV(7),YCNV(7)\n DIMENSION XDAT(11),YDAT(12),ZDAT(11,12)\n DIMENSION IWRK(1000),RWRK(1000)\nC\nC Define, in a labelled common block, quantities which must be available\nC to the routines CPCHHL and CPCHLL. The flag ICLL is used to turn\nC on and off the culling of labels which these routines do (it is off\nC while drawing the first plot and on while drawing the second). The\nC array IAMA is the area map array.\nC\n COMMON /AMAPRA/ ICLL,IAMA(10000)\nC\nC Define a temporary character variable for use below.\nC\n CHARACTER*1 ICHR\nC\nC Declare the routine which will draw contour lines, avoiding labels.\nC\n EXTERNAL CPDRPL\nC\nC Specify the X and Y input data values.\nC\n DATA XRAN / 0.4, 2.0, 2.8, 5.0, 4.8, 8.8, 5.1, 6.2, 9.1 /\n DATA YRAN / 5.4, 1.1, 3.7, 6.8, 9.5, 9.8, 0.7, 2.7, 3.0 /\nC\nC Specify the Z input data values.\nC\n DO 101 I=1,9\nC ZRAN(I)=0.2+0.4*XRAN(I)*XRAN(I)+.6*YRAN(I)*YRAN(I)\n ZRAN(I)=EXP(-(XRAN(I)-3.)**2/9.-(YRAN(I)-5.)**2/25.)-\n + EXP(-(XRAN(I)-6.)**2/9.-(YRAN(I)-5.)**2/25.)\n 101 CONTINUE\nC\nC Specify the points defining the convex hull.\nC\n XCNV(1)=XRAN(1)\n YCNV(1)=YRAN(1)\n XCNV(2)=XRAN(2)\n YCNV(2)=YRAN(2)\n XCNV(3)=XRAN(7)\n YCNV(3)=YRAN(7)\n XCNV(4)=XRAN(9)\n YCNV(4)=YRAN(9)\n XCNV(5)=XRAN(6)\n YCNV(5)=YRAN(6)\n XCNV(6)=XRAN(5)\n YCNV(6)=YRAN(5)\n XCNV(7)=XRAN(1)\n YCNV(7)=YRAN(1)\nC\nC Specify the X and Y coordinates of the points on the regular grid.\nC\n DO 102 I=1,11\n XDAT(I)=REAL(I-1)\n 102 CONTINUE\nC\n DO 103 J=1,12\n YDAT(J)=REAL(J-1)\n 103 CONTINUE\nC\nC Call IDSFFT to obtain a regular grid of values on the fitted surface.\nC\n CALL IDSFFT (1,9,XRAN,YRAN,ZRAN,11,12,11,XDAT,YDAT,ZDAT,IWRK,\n + RWRK)\nC\nC Open GKS.\nC\n CALL GOPKS (IERRF, ISZDM)\n CALL GOPWK (IWKID, LUNIT, IWTYPE)\n CALL GACWK (IWKID)\nC\nC Turn off clipping.\nC\n CALL GSCLIP (0)\nC\nC Define a set of colors to use.\nC\n CALL DFCLRS(IWKID)\nC\nC Tell CONPACK to position labels using the \"regular\" scheme.\nC\n CALL CPSETI ('LLP - LINE LABEL POSITIONING',2)\nC\nC Tell CONPACK to put the informational label in a different place.\nC\n CALL CPSETI ('ILP - INFORMATIONAL LABEL POSITIONING',-2)\n CALL CPSETR ('ILX - INFORMATIONAL LABEL X COORDINATE',.98)\n CALL CPSETR ('ILY - INFORMATIONAL LABEL Y COORDINATE',.02)\nC\nC Provide a little more room below the viewport; otherwise, the labels\nC on AUTOGRAPH's X axis get squashed.\nC\n CALL CPSETR ('VPB - VIEWPORT BOTTOM EDGE',.08)\nC\nC Tell CONPACK in what ranges to generate X and Y coordinates.\nC\n CALL CPSETR ('XC1 - X COORDINATE AT I=1',0.)\n CALL CPSETR ('XCM - X COORDINATE AT I=M',10.)\n CALL CPSETR ('YC1 - Y COORDINATE AT J=1',0.)\n CALL CPSETR ('YCN - Y COORDINATE AT J=N',11.)\nC\nC Turn off the culling of labels by CPCHHL and CPCHLL.\nC\n ICLL=0\nC\nC Dump the polyline buffer and change the polyline color to white.\nC Change the text color to orange. CONPACK will use these colors.\nC\n CALL PLOTIF (0.,0.,2)\n CALL GSPLCI (1)\n CALL GSTXCI (12)\nC\nC Initialize the drawing of the first contour plot.\nC\n CALL CPRECT (ZDAT,11,11,12,RWRK,1000,IWRK,1000)\nC\nC Initialize the area map which will be used to keep contour lines from\nC passing through labels.\nC\n CALL ARINAM (IAMA,10000)\nC\nC Put label boxes in the area map.\nC\n CALL CPLBAM (ZDAT,RWRK,IWRK,IAMA)\nC\nC Draw the contour lines, masked by the area map.\nC\n CALL CPCLDM (ZDAT,RWRK,IWRK,IAMA,CPDRPL)\nC\nC Draw all the labels.\nC\n CALL CPLBDR (ZDAT,RWRK,IWRK)\nC\nC Dump the polyline buffer and change the polyline color to orange.\nC Change the text color to orange, too, so that the AUTOGRAPH background\nC will come out entirely in that color.\nC\n CALL PLOTIF (0.,0.,2)\n CALL GSPLCI (12)\n CALL GSTXCI (12)\nC\nC Use AUTOGRAPH to produce a background for the contour plot, forcing\nC it to pick up appropriate values from CONPACK's SET call.\nC\n CALL AGSETI ('SET.',4)\n CALL AGSTUP (DUMI,1,1,1,1,DUMI,1,1,1,1)\n CALL AGBACK\nC\nC Dump the polyline buffer and change the polyline color to green.\nC\n CALL PLOTIF (0.,0.,2)\n CALL GSPLCI (9)\nC\nC Change the aspect ratio of the characters drawn by PLCHMQ to make\nC them approximately square.\nC\n CALL PCSETR ('HW',1.)\nC\nC At each of the \"random\" data positions, put the index of the point\nC and a starburst to set it off.\nC\n DO 104 I=1,9\n ICHR=CHAR(ICHAR('0')+I)\n CALL PLCHMQ (XRAN(I),YRAN(I),ICHR,.0175,0.,0.)\n CALL LINE (CFUX(CUFX(XRAN(I))-.02),CFUY(CUFY(YRAN(I))-.02),\n + CFUX(CUFX(XRAN(I))-.01),CFUY(CUFY(YRAN(I))-.01))\n CALL LINE (CFUX(CUFX(XRAN(I))+.01),CFUY(CUFY(YRAN(I))+.01),\n + CFUX(CUFX(XRAN(I))+.02),CFUY(CUFY(YRAN(I))+.02))\n CALL LINE (CFUX(CUFX(XRAN(I))-.02),CFUY(CUFY(YRAN(I))+.02),\n + CFUX(CUFX(XRAN(I))-.01),CFUY(CUFY(YRAN(I))+.01))\n CALL LINE (CFUX(CUFX(XRAN(I))+.01),CFUY(CUFY(YRAN(I))-.01),\n + CFUX(CUFX(XRAN(I))+.02),CFUY(CUFY(YRAN(I))-.02))\n CALL LINE (CFUX(CUFX(XRAN(I))-.02828),CFUY(CUFY(YRAN(I))),\n + CFUX(CUFX(XRAN(I))-.01414),CFUY(CUFY(YRAN(I))))\n CALL LINE (CFUX(CUFX(XRAN(I))+.01414),CFUY(CUFY(YRAN(I))),\n + CFUX(CUFX(XRAN(I))+.02828),CFUY(CUFY(YRAN(I))))\n CALL LINE (CFUX(CUFX(XRAN(I))),CFUY(CUFY(YRAN(I))-.02828),\n + CFUX(CUFX(XRAN(I))),CFUY(CUFY(YRAN(I))-.01414))\n CALL LINE (CFUX(CUFX(XRAN(I))),CFUY(CUFY(YRAN(I))+.01414),\n + CFUX(CUFX(XRAN(I))),CFUY(CUFY(YRAN(I))+.02828))\n 104 CONTINUE\nC\nC Dump the polyline buffer and switch the polyline color to yellow.\nC\n CALL PLOTIF (0.,0.,2)\n CALL GSPLCI (11)\nC\nC Put a label at the top of the plot.\nC\n CALL SET (0.,1.,0.,1.,0.,1.,0.,1.,1)\n CALL PLCHHQ (.5,.975,\n + 'DEMONSTRATING THE USE OF BIVAR AND CONPACK',\n + .012,0.,0.)\nC\nC Advance the frame.\nC\n CALL FRAME\nC\nC Do another frame. First, turn on the culling of labels by the\nC routines CPCHHL and CPCHLL (which see, below).\nC\n ICLL=1\nC\nC Dump the polyline buffer and switch the polyline color back to white.\nC Force the text color index to orange.\nC\n CALL PLOTIF (0.,0.,2)\n CALL GSPLCI (1)\n CALL GSTXCI (12)\nC\nC Initialize the drawing of the second contour plot.\nC\n CALL CPRECT (ZDAT,11,11,12,RWRK,1000,IWRK,1000)\nC\nC Initialize the area map.\nC\n CALL ARINAM (IAMA,10000)\nC\nC Put the convex hull of the \"random\" data in the area map, using group\nC identifier 4, an area identifier of 0 inside the hull, and an area\nC identifier of -1 outside the hull.\nC\n CALL AREDAM (IAMA,XCNV,YCNV,7,4,0,-1)\nC\nC Put label boxes in the area map.\nC\n CALL CPLBAM (ZDAT,RWRK,IWRK,IAMA)\nC\nC Draw contour lines, masked by the area map.\n\n CALL CPCLDM (ZDAT,RWRK,IWRK,IAMA,CPDRPL)\nC\nC Draw labels.\nC\n CALL CPLBDR (ZDAT,RWRK,IWRK)\nC\nC Dump the polyline buffer and switch the polyline color to orange.\nC\n CALL PLOTIF (0.,0.,2)\n CALL GSPLCI (12)\nC\nC Use AUTOGRAPH to draw a background.\nC\n CALL AGSETI ('SET.',4)\n CALL AGSTUP (DUMI,1,1,1,1,DUMI,1,1,1,1)\n CALL AGBACK\nC\nC Dump the polyline buffer and switch the polyline color to yellow.\nC\n CALL PLOTIF (0.,0.,2)\n CALL GSPLCI (11)\nC\nC Draw a label at the top of the plot.\nC\n CALL SET (0.,1.,0.,1.,0.,1.,0.,1.,1)\n CALL PLCHHQ (.5,.975,\n + 'DEMONSTRATING THE USE OF BIVAR AND CONPACK',\n + .012,0.,0.)\nC\nC Advance the frame.\nC\n CALL FRAME\nC\nC Close GKS.\nC\n CALL GDAWK (IWKID)\n CALL GCLWK (IWKID)\n CALL GCLKS\nC\nC Done.\nC\n STOP\nC\n END\n SUBROUTINE DFCLRS(IWKID)\nC\nC Define a set of RGB color triples for colors 1 through 15 on\nC workstation 1.\nC\n DIMENSION RGBV(3,15)\nC\nC Define the RGB color triples needed below.\nC\n DATA RGBV / 1.00 , 1.00 , 1.00 ,\n + 0.70 , 0.70 , 0.70 ,\n + 0.75 , 0.50 , 1.00 ,\n + 0.50 , 0.00 , 1.00 ,\n + 0.00 , 0.00 , 1.00 ,\n + 0.00 , 0.50 , 1.00 ,\n + 0.00 , 1.00 , 1.00 ,\n + 0.00 , 1.00 , 0.60 ,\n + 0.00 , 1.00 , 0.00 ,\n + 0.70 , 1.00 , 0.00 ,\n + 1.00 , 1.00 , 0.00 ,\n + 1.00 , 0.75 , 0.00 ,\n + 1.00 , 0.38 , 0.38 ,\n + 1.00 , 0.00 , 0.38 ,\n + 1.00 , 0.00 , 0.00 /\nC\nC Define 16 different color indices, for indices 0 through 15. The\nC color corresponding to index 0 is black and the color corresponding\nC to index 1 is white.\nC\n CALL GSCR (IWKID,0,0.,0.,0.)\nC\n DO 101 I=1,15\n CALL GSCR (IWKID,I,RGBV(1,I),RGBV(2,I),RGBV(3,I))\n 101 CONTINUE\nC\nC Done.\nC\n RETURN\nC\n END\n SUBROUTINE CPCHHL (IFLG)\nC\nC This version of CPCHHL, if and only if ICLL is non-zero, examines a\nC high/low label which is about to be drawn. If that label would fall\nC in an area outside the convex hull defined by edge group 4, the text\nC of the label is changed to a blank, so that the label is effectively\nC deleted.\nC\n COMMON /AMAPRA/ ICLL,IAMA(10000)\n DIMENSION IAAI(10),IAGI(10)\n IF (ICLL.EQ.0) RETURN\n IF ((IFLG.GE.2.AND.IFLG.LE.4).OR.\n + (IFLG.GE.6.AND.IFLG.LE.8)) THEN\n CALL CPGETR ('LBX',XPOS)\n CALL CPGETR ('LBY',YPOS)\n CALL ARGTAI (IAMA,XPOS,YPOS,IAAI,IAGI,10,NAIR,1)\n IVIS=1\n DO 101 I=1,NAIR\n IF (IAGI(I).EQ.4.AND.IAAI(I).LT.0) IVIS=0\n 101 CONTINUE\n IF (IVIS.EQ.0) THEN\n CALL CPSETC ('CTM',' ')\n END IF\n END IF\n RETURN\n END\n SUBROUTINE CPCHLL (IFLG)\nC\nC This version of CPCHLL, if and only if ICLL is non-zero, examines a\nC contour-line label which is about to be drawn. If that label would\nC fall in an area outside the convex hull defined by edge group 4, the\nC text of the label is changed to a blank, so that it is effectively\nC deleted.\nC\n COMMON /AMAPRA/ ICLL,IAMA(10000)\n DIMENSION IAAI(10),IAGI(10)\n IF (ICLL.EQ.0) RETURN\n IF (IFLG.GE.2.AND.IFLG.LE.4) THEN\n CALL CPGETR ('LBX',XPOS)\n CALL CPGETR ('LBY',YPOS)\n CALL ARGTAI (IAMA,XPOS,YPOS,IAAI,IAGI,10,NAIR,1)\n IVIS=1\n DO 101 I=1,NAIR\n IF (IAGI(I).EQ.4.AND.IAAI(I).LT.0) IVIS=0\n 101 CONTINUE\n IF (IVIS.EQ.0) THEN\n CALL CPSETC ('CTM',' ')\n END IF\n END IF\n RETURN\n END\n", "meta": {"hexsha": "dbc821d4d25ecf5a8367906bd8053363c785af87", "size": 13489, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ncarg2d/src/examples/econpa/cbex01.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "ncarg2d/src/examples/econpa/cbex01.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "ncarg2d/src/examples/econpa/cbex01.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 31.7388235294, "max_line_length": 72, "alphanum_fraction": 0.5861813329, "num_tokens": 4572, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436395, "lm_q2_score": 0.7606506526772883, "lm_q1q2_score": 0.6772028886027545}} {"text": "!***********************************************************************\n! *\n SUBROUTINE INTERP(XARR, YARR, NARR, XVAL, YVAL, ACCY)\n! *\n! This routine returns YVAL given a value XVAL by interpolating *\n! using a pair of arrays XARR(1:NARR), YARR(1:NARR), that tabulate *\n! a function. ACCY is the desired accuracy of the estimate: a *\n! warning message is issued if this is not achieved. A warning is *\n! also issued when the routine is extrapolating. Aitken's algori- *\n! thm is used. See, for instance, F B Hildebrand, Introduction to *\n! Numerical Analysis, 2nd ed., McGraw-Hill, New York, NY, 1974. *\n! *\n! Written by Farid A Parpia, at Oxford Last update: 06 Oct 1992 *\n! *\n!***********************************************************************\n!...Translated by Pacific-Sierra Research 77to90 4.3E 10:48:32 2/14/04\n!...Modified by Charlotte Froese Fischer\n! Gediminas Gaigalas 10/05/17\n!-----------------------------------------------\n! M o d u l e s\n!-----------------------------------------------\n USE vast_kind_param, ONLY: DOUBLE\n IMPLICIT NONE\n!-----------------------------------------------\n! D u m m y A r g u m e n t s\n!-----------------------------------------------\n INTEGER, INTENT(IN) :: NARR\n REAL(DOUBLE), INTENT(IN) :: XVAL\n REAL(DOUBLE), INTENT(OUT) :: YVAL\n REAL(DOUBLE), INTENT(IN) :: ACCY\n REAL(DOUBLE), DIMENSION(NARR), INTENT(IN) :: XARR\n REAL(DOUBLE), DIMENSION(NARR), INTENT(IN) :: YARR\n!-----------------------------------------------\n! L o c a l P a r a m e t e r s\n!-----------------------------------------------\n INTEGER, PARAMETER :: MXORD = 11\n!-----------------------------------------------\n! L o c a l V a r i a b l e s\n!-----------------------------------------------\n INTEGER :: NRSTLO, NRSTHI, K, LLO, LHI, LLR, IROW, LOCNXT, ILIROK, ILDIAG&\n , ILOTHR, IBEST\n REAL(DOUBLE), DIMENSION(MXORD) :: DX, X, EST\n REAL(DOUBLE), DIMENSION((MXORD*(MXORD + 1))/2) :: POLY\n REAL(DOUBLE) :: DIFF, DIFFT, DEBEB, DEBE\n LOGICAL :: SET\n LOGICAL, DIMENSION(2*MXORD + 2) :: USED\n!-----------------------------------------------\n!\n!\n! MXORD is the maximum order of the interpolation\n!\n!\n! This function dispenses with the need for a two-dimensional\n! array for the Aitken lower triangle matrix\n!\n!\n! Determine the nearest two XARR entries bounding XVAL\n!\n IF (XVAL < XARR(1)) THEN\n NRSTLO = 1\n NRSTHI = 1\n WRITE (*, 300)\n ELSE IF (XVAL > XARR(NARR)) THEN\n NRSTLO = NARR\n NRSTHI = NARR\n WRITE (*, 300)\n ELSE\n K = 0\n 1 CONTINUE\n K = K + 1\n IF (XARR(K) < XVAL) THEN\n NRSTLO = K\n GO TO 1\n ELSE\n NRSTHI = K\n ENDIF\n ENDIF\n!\n! Clear relevant piece of use-indicator array\n!\n LLO = MAX(NRSTLO - MXORD,1)\n LHI = MIN(NRSTHI + MXORD,NARR)\n LLR = LLO - 1\n USED(LLO-LLR:LHI-LLR) = .FALSE.\n!\n! Determine next-nearest XARR entry\n!\n DO IROW = 1, MXORD\n LLO = MAX(NRSTLO - IROW + 1,1)\n LHI = MIN(NRSTHI + IROW - 1,NARR)\n SET = .FALSE.\n DO K = LLO, LHI\n IF (USED(K-LLR)) CYCLE\n IF (.NOT.SET) THEN\n DIFF = XARR(K) - XVAL\n LOCNXT = K\n SET = .TRUE.\n ELSE\n DIFFT = XARR(K) - XVAL\n IF (ABS(DIFFT) < ABS(DIFF)) THEN\n DIFF = DIFFT\n LOCNXT = K\n ENDIF\n ENDIF\n END DO\n USED(LOCNXT-LLR) = .TRUE.\n X(IROW) = XARR(LOCNXT)\n DX(IROW) = DIFF\n!\n! Fill table for this row\n!\n DO K = 1, IROW\n ILIROK = ILOC(IROW,K)\n IF (K == 1) THEN\n POLY(ILIROK) = YARR(LOCNXT)\n ELSE\n ILDIAG = ILOC(K - 1,K - 1)\n ILOTHR = ILOC(IROW,K - 1)\n POLY(ILIROK) = (POLY(ILDIAG)*DX(IROW)-POLY(ILOTHR)*DX(K-1))/(X(&\n IROW)-X(K-1))\n ENDIF\n END DO\n!\n! Pick off the diagonal element\n!\n ILDIAG = ILOC(IROW,IROW)\n EST(IROW) = POLY(ILDIAG)\n!\n END DO\n!\n! Now the estimate vector is filled in, so obtain the\n! best estimate\n!\n DEBEB = ABS((EST(2)-EST(1))/EST(2))\n\n IBEST = 2\n DO IROW = 3, MXORD\n DEBE = ABS((EST(IROW)-EST(IROW-1))/EST(IROW))\n\n!ps 13/12/2017\n!ps If NARR is small, the EST array sometimes contains the NaN values.\n!ps In a consequence, DEBE becomes NaN, and in that case the condition\n!ps in the CYCLE statement (NaN >= number) is then evaluated to \"false\".\n!ps So, the CYCLE is not performed, what is incorrect.\n!ps To avoid this, the CYCLE was replaced with the IF / THEN / END IF\n!ps (the condition was reversed).\n !ps IF (DEBE >= DEBEB) CYCLE\n !ps DEBEB = DEBE\n !ps IBEST = IROW\n IF (DEBE < DEBEB) THEN\n DEBEB = DEBE\n IBEST = IROW\n END IF\n\n END DO\n YVAL = EST(IBEST)\n!\n IF (DEBEB > ACCY) WRITE (*, 301) DEBEB, ACCY\n!\n RETURN\n!\n 300 FORMAT('INTERP: Extrapolating, not interpolating.')\n 301 FORMAT('INTERP: Accuracy of interpolation (',1P,1D10.3,') is',&\n ' below input criterion (',1D10.3,').')\n RETURN\n CONTAINS\n\n\n INTEGER FUNCTION ILOC (IND1, IND2)\n INTEGER, INTENT(IN) :: IND1\n INTEGER, INTENT(IN) :: IND2\n ILOC = (IND1*(IND1 - 1))/2 + IND2\n RETURN\n END FUNCTION ILOC\n!\n END SUBROUTINE INTERP\n", "meta": {"hexsha": "659765e48583753373df7ec8b88d0098b1cf6743", "size": 5846, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/lib/lib9290/interp.f90", "max_stars_repo_name": "sylas/grasp-continuum", "max_stars_repo_head_hexsha": "f5e2fb18bb2bca4f715072190bf455fba889320f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 33, "max_stars_repo_stars_event_min_datetime": "2019-03-10T04:00:32.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T22:01:15.000Z", "max_issues_repo_path": "src/lib/lib9290/interp.f90", "max_issues_repo_name": "sylas/grasp-continuum", "max_issues_repo_head_hexsha": "f5e2fb18bb2bca4f715072190bf455fba889320f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 65, "max_issues_repo_issues_event_min_datetime": "2019-03-07T17:56:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-16T16:45:24.000Z", "max_forks_repo_path": "src/lib/lib9290/interp.f90", "max_forks_repo_name": "sylas/grasp-continuum", "max_forks_repo_head_hexsha": "f5e2fb18bb2bca4f715072190bf455fba889320f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2019-03-10T04:00:43.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-23T02:06:40.000Z", "avg_line_length": 33.0282485876, "max_line_length": 80, "alphanum_fraction": 0.4632227164, "num_tokens": 1713, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.677202879343942}} {"text": "program navier\n use init_mod\n use helpers_mod\n use boundary_mod\n use simulation_mod\n use output_mod\n\n ! by D. Orchard (2012) based on the classic code from:\n !\n ! Michael Griebel, Thomas Dornseifer, Tilman Neunhoeffer,\n ! Numerical Simulation in Fluid Dynamics,\n ! SIAM, 1998.\n !\n ! http://people.sc.fsu.edu/~jburkardt/cpp_src/nast2d/nast2d.html\n\n implicit none\n\n character(10) :: outname = \"output\"\n\n real :: t = 0, res = 0, del_t = 0.003, t_count = 0.0\n integer :: i, j, itersor = 0, ifluid = 0, ibound = 0, init_case, iters = 0\n integer :: output_counter = 0\n\n real u(0:imax+1, 0:jmax+1), v(0:imax+1, 0:jmax+1), p(0:imax+1, 0:jmax+1)\n real rhs(0:imax+1, 0:jmax+1), f(0:imax+1, 0:jmax+1), g(0:imax+1, 0:jmax+1)\n integer flag(0:imax+1, 0:jmax+1)\n\n u = ui\n v = vi\n p = 0.0\n\n ! init flags\n call init_flag(delx, dely, flag, ibound)\n\n call apply_boundary_conditions(u, v, flag, 0.0)\n\n !do t = 0.0, t_end, del_t\n do while (t < t_end)\n del_t = set_timestep_interval(u, v, del_t)\n ifluid = (imax * jmax) - ibound\n\n call compute_tentative_velocity(u, v, f, g, flag, del_t)\n\n call compute_rhs(f, g, rhs, flag, del_t)\n\n if (ifluid > 0) then\n itersor = poisson(p, rhs, flag, res, ifluid)\n else\n itersor = 0\n end if\n\n print '(i0.1, \" t:\", f0.7, \", del_t:\", f0.7, \", SOR iters:\", i3.3, \", res:\", f0.7, \", &\n bcells:\", i0)', iters, t+del_t, del_t, itersor, res, ibound\n\n !(\"%d t:%g, del_t:%g, SOR iters:%3d, res:%e, bcells:%d\\n\",\n ! iters, t+del_t, del_t, itersor, res, ibound);\n\n call update_velocity(u, v, f, g ,p, flag, del_t)\n\n call apply_boundary_conditions(u, v, flag, t)\n\n ! An alternate way to print output using the simulation time\n !if (toLogical(outputFlag) .and. (t >= t_count)) then\n ! call write_ppm(u, v, p, flag, output_counter, outname)\n ! output_counter = output_counter + 1\n ! t_count = t_count + output_freqt\n !end if\n\n if (toLogical(outputFlag) .and. (mod(iters, output_freq) == 0)) then\n call write_ppm(u, v, p, flag, iters, outname)\n output_counter = output_counter + 1\n t_count = t_count + output_freqt\n end if\n\n t = t + del_t\n iters = iters + 1\n end do\nend program navier\n", "meta": {"hexsha": "30c6a97b2413420e64613a392a83e6af8f214780", "size": 2240, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/navier.f90", "max_stars_repo_name": "raehik/navier", "max_stars_repo_head_hexsha": "7e22a09fcde3993864a61d2855ff73ddbb096458", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 49, "max_stars_repo_stars_event_min_datetime": "2015-02-19T07:15:32.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-01T16:53:40.000Z", "max_issues_repo_path": "fortran/navier.f90", "max_issues_repo_name": "raehik/navier", "max_issues_repo_head_hexsha": "7e22a09fcde3993864a61d2855ff73ddbb096458", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2016-09-29T01:26:51.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-19T05:18:40.000Z", "max_forks_repo_path": "fortran/navier.f90", "max_forks_repo_name": "raehik/navier", "max_forks_repo_head_hexsha": "7e22a09fcde3993864a61d2855ff73ddbb096458", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2015-05-19T01:42:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-10T16:48:34.000Z", "avg_line_length": 28.3544303797, "max_line_length": 91, "alphanum_fraction": 0.6151785714, "num_tokens": 845, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.677202879343942}} {"text": "module omp\ninterface\n double precision function omp_get_wtime()\n endfunction\nendinterface\nendmodule\n\nprogram test\nuse omp\ncomplex(kind=8), allocatable :: A(:, :)\ninteger :: N\nreal(kind=8) :: time1, time2\n\ndo N = 1000, 10000, 1000\n time1 = omp_get_wtime()\n A = eval_exp(N)\n time2 = omp_get_wtime()\n print *, time2 - time1\nenddo\n\ncontains\n\nfunction eval_exp(n) result(M)\n implicit none\n\n integer, intent(in) :: n\n complex(kind=8) :: M(n, n)\n\n ! Local\n real(kind=8) :: a(n)\n complex(kind=8) :: k\n integer :: i, j\n\n k = (100., 1.)\n\n do i = 1, n\n a(i) = (i - 1)*2*3.14159/(n - 1)\n enddo\n\n !$omp PARALLEL DO PRIVATE(J)\n do j = 1, n\n do i = 1, n\n\n ! A[i,j] = exp((100+im)*im*sqrt(a[i]^2 + a[j]^2))\n M(i, j) = exp(k*(0., 1.)*sqrt(a(i)**2 + a(j)**2))\n\n enddo\n enddo\n !$omp END PARALLEL DO\n\nendfunction eval_exp\n\nendprogram\n", "meta": {"hexsha": "3414dca7062616d651675bb6989f6daadf2168e6", "size": 885, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran_standalone.f90", "max_stars_repo_name": "clavigne/julia-numpy-fortran-test", "max_stars_repo_head_hexsha": "1d56454c411eb7d25e29c3dab263c890a156bec3", "max_stars_repo_licenses": ["MIT"], "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_standalone.f90", "max_issues_repo_name": "clavigne/julia-numpy-fortran-test", "max_issues_repo_head_hexsha": "1d56454c411eb7d25e29c3dab263c890a156bec3", "max_issues_repo_licenses": ["MIT"], "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_standalone.f90", "max_forks_repo_name": "clavigne/julia-numpy-fortran-test", "max_forks_repo_head_hexsha": "1d56454c411eb7d25e29c3dab263c890a156bec3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.3888888889, "max_line_length": 58, "alphanum_fraction": 0.5706214689, "num_tokens": 323, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004185, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.67720287491573}} {"text": " SUBROUTINE SCFT (A, MODE, M, ND, MS, S)\nc>> 1997-03-31 SCFT Krogh Increased KEDIM, more sine table checks.\nC>> 1994-10-20 SCFT Krogh Change CERROR to simplify conversion to C.\nC>> 1994-10-20 SCFT Krogh Changes to use M77CON\nC>> 1994-04-19 SCFT CLL Edited to make DP & SP files similar.\nc>> 1989-06-16 FTK Fix error message on MODE.\nc>> 1989-06-05 WVS Change length of MODE from *(ND) to *(*).\nc>> 1989-05-07 FTK & CLL\nc>> 1989-04-21 FTK & CLL\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc\nc This subroutine computes complex Fourier transforms in up to 6\nc dimensions using the Cooley-Tukey fast Fourier transform.\nc\nc Variables in the calling sequence have the following types.\n REAL A(*), S(*)\n INTEGER ND, M(ND), MS\n CHARACTER MODE*(*)\nc\nc Programmed by Fred T. Krogh at the Jet Propulsion Laboratory,\nc Pasadena, Calif. August 1, 1969.\nc\nc Values for A, MODE, M, ND, and MS must be specified before\nc calling the subroutine.\nc\nc In describing the usage the following notation is used\nc N(K) = 2**M(K)\nc WK = EXP(2*PI*I/N(K)), where I = sqrt(-1) and PI = 3.14159...\nc MA = M(1) + M(2) + ... + M(ND)\nc NA = 2**MA\nc MX = MAX(M(1), M(2), ..., M(ND))\nc NX = 2**MX\nc\nc The usage is as follows\nc\nc A() on input is an array of function values, X, if one is doing\nc Fourier analysis,\nc and is an array of Fourier coefficients, C, if one is\nc doing Fourier synthesis. On output, A contains C if doing analysis,\nc and contains X if doing synthesis. In our description here, we\nc assume that A has been declared by the user as a complex array with\nc dimension A(N(1),N(2),...,N(ND)). (Of course this is not necessary\nc as long as one declares enough storage for A, and keeps in mind that\nc the array is treated in this subroutine as if it had been specified\nc in this way.) It is assumed that the imaginary part of a complex\nc number is stored in the cell immediately following its real part.\nc\nc MODE A character variable of length at least ND.\nc The k-th character must be 'A' or 'a' to select Analysis in the\nc k-th dimension, or 'S' or 's' to select Synthesis in the\nc k-th dimension.\nc The subroutine sets A(j1+1, j2+1, ..., jND+1) to the sum\nc over 0 .le. k1 .le. N(1)-1, 0 .le. k2 .le. N(2)-1, ...,\nc 0 .le. kND .le. N(ND)-1 of A(k1+1, k2+1, ..., kND+1) * T(1,j1,k1) *\nc T(2,j2,k2) * ... * T(ND,jND,kND), 0 .le. j1 .le. N(1)-1, ...,\nc 0 .le. jnd .le. N(ND)-1\nc with T(L,j,k) =\nc WL ** (j*k) if MODE(L:L) = 'S' or 's'\nc (1/N(L)) * WL ** (-j*k) if MODE(L:L) = 'A' or 'a'\nc\nc M() is a vector used to indicate N(k) = 2**M(k), the number of\nc complex points in the k-th variable. M must be such that MX < 21.\nc If M(L)=0, no change is made with respect to the L-th dimension.\nc\nc ND is the dimension of (i.e. the number of subscripts in) the\nc array A. ND must satisfy 1 .le. ND .le. 6\nc\nc MS gives the state of the sine table. If MS > 0, there are NT =\nc 2 ** (MS-2) good entries in the sine table. On the initial call,\nc MS must be set to 0, and when the return is made, it will be set\nc to MX, which is the value of MS required for computing a\nc transform of size NX. If MS = -1, the sine table will be computed\nc as for the case MS = 0, and then a return to the user will be made\nc with MS set as before, but no transform will be computed. This\nc option is useful if the user would like access to the sine table\nc before computing the FFT.\nc\nc S is a vector, S(j) = sin(pi*j/(2*NT)), j = 1, 2, ..., NT-1, where\nc NT is defined in the description of MS above. S is computed by the\nc subroutine if MX .gt. MS. (If S is altered, set MS=0 so that S\nc is recomputed.)\nc ------------------------------------------------------------------\nc Notes on COMMON, PARAMETER's, and local variables\nC\nc NDMAX = the maximum value for ND, and MAXM = the maximum\nc permitted for M(1), ..., M(ND)\nc The dimension of KE must be at least as large as MAXM.\nc The named common CSFFTC is used for communication between this\nc subroutine and the subroutine SFFT which computes a one\nc dimensional complex Fourier transform and computes the sine table.\nc The use of the variables in CSFFTC is contained in the listing\nc of SFFT.\nc\nc NF(1) = 2, NF(K+1) = 2**(1+M(1)+...+M(K)), K = 1,..., ND\nc ------------------------------------------------------------------\nc--S replaces \"?\": ?CFT, ?FFT, C?FFTC\nc Both versions use IERM1\nc ------------------------------------------------------------------\n INTEGER MAXM, NDMAX\n PARAMETER (NDMAX = 6)\n\n INTEGER I, II, IIC, IR, IRC\n INTEGER J, JL\n INTEGER K, KEDIM, KSM\n INTEGER L\n INTEGER MA, MMAX, MSI\n INTEGER NDD, NF(NDMAX+1), NTOT2\n\n CHARACTER*13 CERROR\n\n REAL FN, ONE, SPI4\n\n PARAMETER (ONE = 1.E0)\n PARAMETER (SPI4 = .70710 67811 86547 52440 08443 62104 8490E0)\n\nc Common variables\n PARAMETER (KEDIM=30)\n LOGICAL NEEDST\n INTEGER MT, NT, MM, KS, ILAST, KE(KEDIM), KEE(KEDIM+1)\nc Note that KEE(1) is equivalent to ILAST.\n EQUIVALENCE (KE(1), KEE(2))\n COMMON /CSFFTC/ NEEDST, MT, NT, MM, KS, ILAST, KE\n SAVE /CSFFTC/\n PARAMETER (MAXM = KEDIM)\n DATA CERROR / 'MODE(K:K) = ' /\nc ------------------------------------------------------------------\nc\n NDD = ND\n IF ((NDD .LE. 0) .OR. (NDD .GT. NDMAX)) THEN\nc Fatal error, default is to stop in IERM1\n CALL IERM1 ('SCFT', 1, 2, 'BAD ND', 'ND', ND, '.')\n MS = -2\n RETURN\n END IF\n NF(1) = 2\n MA = 0\n MMAX = 0\n FN = ONE\n DO 10 K = 1, NDD\n MM = M(K)\n MMAX = MAX(MM, MMAX)\n MA = MA + MM\n I = 2**MM\n IF ((MM .LT. 0) .OR. (MM .GT. MAXM)) THEN\nc Fatal error, default is to stop in IERM1\n CALL IERM1('SCFT',2,2,'Need 0 .le. M(K) .le. 30','M(K)',MM,'.')\n MS = -2\n RETURN\n END IF\n NF(K+1) = NF(K) * I\n if (MODE(K:K) .eq. 'A' .or. MODE(K:K) .eq. 'a') then\n FN = FN / I\n else if (MODE(K:K) .ne. 'S' .and. MODE(K:K) .ne. 's') then\n CERROR(13:13) = MODE(K:K)\n CALL IERM1 ('SCFT',3,2,CERROR, 'for K =',K,'.')\n MS = -2\n RETURN\n end if\n 10 CONTINUE\n MSI = MS\n NEEDST = MMAX .GT. MSI\n if (.NOT. NEEDST) then\nc Check internal parameters to catch certain user errors.\n if (MT .lt. KEDIM) then\n if (MMAX .le. MT + 2) then\nc Skip sine table computation if all appears O.K.\n if (MT .le. 0) go to 20\n if (abs(S(NT/2) - SPI4) .le. 1.E-7) go to 20\n end if\n end if\n NEEDST = .true.\n call ERMSG('DRFT1', 3, 1,\n 1 'Invalid sine table (re)computed', '.')\n end if\n MS = MMAX\n MT = MMAX - 2\n CALL SFFT (A, A, S)\n IF (MSI .EQ. -1) RETURN\nc All setup for computation now\n 20 NTOT2 = NF(NDD+1)\n IF (FN .NE. ONE) THEN\n DO 30 I = 1, NTOT2\n A(I) = A(I) * FN\n 30 CONTINUE\n END IF\nc Beginning of loop for computing multiple sum\n DO 70 K = 1, NDD\n if(MODE(K:K) .eq. 'A' .or. MODE(K:K) .eq. 'a') then\n IRC = 1\n IIC = 0\n ELSE\n IRC = 0\n IIC = 1\n END IF\n MM = M(K)\n KS = NF(K)\n KSM = KS - 1\n ILAST = NF(K+1)\n DO 40 L = 1, MM\n KEE(L+1) = KEE(L) / 2\n 40 CONTINUE\n DO 60 J = 1, NTOT2, ILAST\n JL = J + KSM\n DO 50 I = J, JL, 2\n IR = I + IRC\n II = I + IIC\n CALL SFFT (A(IR), A(II), S)\n 50 CONTINUE\n 60 CONTINUE\n 70 CONTINUE\n RETURN\nc End of loop for computing multiple sum\nc\n END\n", "meta": {"hexsha": "d758abd8ad95146cd349663ebd06c564b0019c28", "size": 8093, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/scft.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/scft.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/scft.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": 37.2949308756, "max_line_length": 72, "alphanum_fraction": 0.5470159397, "num_tokens": 2678, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.7606506418255928, "lm_q1q2_score": 0.677202874513341}} {"text": "! Single precision function to calculate Julian date\n FUNCTION julian_date(YYYY,MM,DD)\n! IMPLICIT NONE\n INTEGER, INTENT(IN) :: YYYY,MM,DD\n! DATE ROUTINE julian_date(YYYY,MM,DD) CONVERTS CALENDER DATE TO\n! JULIAN DATE. SEE CACM 1968 11(10):657, LETTER TO THE\n! EDITOR BY HENRY F. FLIEGEL AND THOMAS C. VAN FLANDERN.\n! EXAMPLE julian_date(1970,1,1)=2440588\n INTEGER :: julian_date\n\n julian_date=DD-32075+1461*(YYYY+4800+(MM-14)/12)/4 & !days\n & +367*(MM-2-((MM-14)/12)*12)/12-3* &\n & ((YYYY+4900+(MM-14)/12)/100)/4\n RETURN\n END\n\n", "meta": {"hexsha": "8102bdf1e1d6f7101ee83c7faf131e1554262883", "size": 630, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/Utility/UtilLib/julian_date.f90", "max_stars_repo_name": "rustychris/schism", "max_stars_repo_head_hexsha": "3754530ef57b3a058906432b4a9fca4a670f395e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2019-08-12T21:48:24.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-03T03:08:10.000Z", "max_issues_repo_path": "src/Utility/UtilLib/julian_date.f90", "max_issues_repo_name": "rustychris/schism", "max_issues_repo_head_hexsha": "3754530ef57b3a058906432b4a9fca4a670f395e", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 42, "max_issues_repo_issues_event_min_datetime": "2019-08-19T21:57:12.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-03T17:42:01.000Z", "max_forks_repo_path": "src/Utility/UtilLib/julian_date.f90", "max_forks_repo_name": "rustychris/schism", "max_forks_repo_head_hexsha": "3754530ef57b3a058906432b4a9fca4a670f395e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 51, "max_forks_repo_forks_event_min_datetime": "2019-08-09T20:59:07.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T15:48:43.000Z", "avg_line_length": 37.0588235294, "max_line_length": 77, "alphanum_fraction": 0.5920634921, "num_tokens": 218, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9149009573133051, "lm_q2_score": 0.7401743735019594, "lm_q1q2_score": 0.6771862428957185}} {"text": "module DISORT_solver\n\n\timplicit none\n\t\n\tprivate\n\t\n\tinteger, parameter :: MAXIT = 1000, MXSQT = 1000\n\treal*8, parameter :: one= 1.0d0, two = 2.0d0, zero = 0.0d0\n\tlogical, parameter :: DELTAM = .true., CORINT = .false.\n\n\treal*8 :: TOL\n\tINTEGER, parameter :: MXCLY = 26, MXULV = 27, MXCMU = 64, MXUMU = 5, & ! MXCMU was 16 and 32\n MXPHI = 5, MI = MXCMU / 2, MI9M2 = 9*MI - 2, &\n NNLYRI = MXCMU*MXCLY \n\n\treal, parameter :: approx_limit = 0.3, approx_limit_tan = 0.2\n\t\n\treal :: TINY, HUGE, PI, PLKAVG_SIGDPI, PLKAVG_CONC, DITHER, PIMYPI\n\treal :: RPD\n\treal :: SQT(MXSQT)\n\tREAL :: CMU_S(MXCMU),CWT_S(MXCMU), PHIRAD( MXPHI )\n\t\t\n\tinteger :: NN\n\n\t\n\tDOUBLE PRECISION :: COSPHI_S(0:MXCMU-1,1:MXPHI)\n\t\n\n\tpublic :: DISORT_DP_GC, init_solver\n\ncontains\n\n\tsubroutine init_solver\n\t\n \t\t USE RDI1MACH_f90, ONLY : R1MACH, D1MACH\n\t\t\n\t\t real, parameter :: SIGMA = 5.67032E-8 \n! number of streams\n\t\t integer, parameter :: NSTR = 64\n\n\n\t\t integer :: NS, IQ\n\n\n\t\t\n TINY = D1MACH( 1 )\n HUGE = D1MACH( 2 )\n\t\t TOL = D1MACH(4)\n\t\t \n\t\t PI = acos(-1.0)\n\t\t \n PLKAVG_SIGDPI = SIGMA / PI\n PLKAVG_CONC = 15. / PI**4\n\t\t \n DO NS = 1, MXSQT\n SQT( NS ) = SQRT( FLOAT( NS ) )\n\t\t end do\n\t\t\n IF( DITHER.LT.1.E-10 ) DITHER = 10.*DITHER\n\n RPD = PI / 180.0\n\n\t\t \n\t\t PIMYPI = PI * 1.0d0\n\t\t \n \n\t\t NN = NSTR / 2\n\t\tCMU_S(:) = 0.0\n\t\tCWT_S(:) = 0.0\n\n CALL QGAUSN( NN, CMU_S, CWT_S )\n!c ** Downward (neg) angles and weights\n DO IQ = 1, NN\n CMU_S( IQ + NN ) = -CMU_S( IQ )\n CWT_S( IQ + NN ) = CWT_S( IQ )\n ENDDO\n\t\n\t\n\tend subroutine init_solver\n\n\n SUBROUTINE DISORT_DP_GC( NLYR, DTAUC, SSALB, NMOM, PMOM, TEMPER, &\n WVNMLO,WVNMHI, USRTAU, NTAU, UTAU, NSTR, USRANG, NUMU, &\n UMU, NPHI, PHI, IBCND, FBEAM, UMU0, PHI0, &\n FISOT, LAMBER, ALBEDO, BTEMP, TTEMP, TEMIS, &\n PLANK, ONLYFL, ACCUR, PRNT, HEADER, MAXCLY, &\n MAXULV, MAXUMU, MAXPHI, MAXMOM, UU,UUS)\n \n\t\t\n\t \n \tUSE RDI1MACH_f90, ONLY : R1MACH, D1MACH\n\n\t\timplicit none\n\n!c\n!c I N T E R N A L V A R I A B L E S\n!c\n!c AMB(IQ/2,IQ/2) First matrix factor in reduced eigenvalue problem\n!c of Eqs. SS(12), STWJ(8E), STWL(23f)\n!c (used only in SOLEIG)\n!c\n!c APB(IQ/2,IQ/2) Second matrix factor in reduced eigenvalue problem\n!c of Eqs. SS(12), STWJ(8E), STWL(23f)\n!c (used only in SOLEIG)\n!c\n!c ARRAY(IQ,IQ) Scratch matrix for SOLEIG, UPBEAM and UPISOT\n!c (see each subroutine for definition)\n!c\n!c B() Right-hand side vector of Eq. SC(5) going into\n!c SOLVE0,1; returns as solution vector\n!c vector L, the constants of integration\n!c\n!c BDR(IQ/2,0:IQ/2) Bottom-boundary bidirectional reflectivity for a\n!c given azimuthal component. First index always\n!c refers to a computational angle. Second index:\n!c if zero, refers to incident beam angle UMU0;\n!c if non-zero, refers to a computational angle.\n!c\n!c BEM(IQ/2) Bottom-boundary directional emissivity at compu-\n!c tational angles.\n!c\n!c BPLANK Intensity emitted from bottom boundary\n!c\n!c CBAND() Matrix of left-hand side of the linear system\n!c Eq. SC(5), scaled by Eq. SC(12); in banded\n!c form required by LINPACK solution routines\n!c\n!c CC(IQ,IQ) C-sub-IJ in Eq. SS(5)\n!c\n!c CMU(IQ) Computational polar angles (Gaussian)\n!c\n!c CWT(IQ) Quadrature weights corresponding to CMU\n!c\n!c CORINT When set TRUE, correct intensities for\n!c delta-scaling effects (see Nakajima and Tanaka,\n!c 1988). When FALSE, intensities are not corrected.\n!c In general, CORINT should be set true when beam\n!c source is present (FBEAM is not zero) and DELTAM\n!c is TRUE in a problem including scattering.\n!c However, execution is faster when CORINT is FALSE,\n!c and intensities outside the aureole may still be\n!c accurate enough. When CORINT is TRUE, it is\n!c important to have a sufficiently high order of\n!c Legendre approximation of the phase function. This\n!c is because the intensities are corrected by\n!c calculating the single-scattered radiation, for\n!c which an adequate representation of the phase\n!c function is crucial. In case of a low order\n!c Legendre approximation of an otherwise highly\n!c anisotropic phase function, the intensities might\n!c actually be more accurate when CORINT is FALSE.\n!c When only fluxes are calculated (ONLYFL is TRUE),\n!c or there is no beam source (FBEAM=0.0), or there\n!c is no scattering (SSALB=0.0 for all layers) CORINT\n!c is set FALSE by the code.\n!c\n!c DELM0 Kronecker delta, delta-sub-M0, where M = MAZIM\n!c is the number of the Fourier component in the\n!c azimuth cosine expansion\n!c\n!c DELTAM TRUE, use delta-M method ( see Wiscombe, 1977 );\n!c FALSE, do not use delta-M method. In general, for\n!c a given number of streams, intensities and\n!c fluxes will be more accurate for phase functions\n!c with a large forward peak if DELTAM is set true.\n!c Intensities close to the forward scattering\n!c direction are often less accurate, however, when\n!c the delta-M method is applied. The intensity\n!c correction of Nakajima and Tanaka is used to\n!c improve the accuracy of the intensities.\n!c\n!c DITHER Small quantity subtracted from single-scattering\n!c albedos of unity, in order to avoid using special\n!c case formulas; prevents an eigenvalue of exactly\n!c zero from occurring, which would cause an\n!c immediate overflow\n!c\n!c DTAUCP(LC) Computational-layer optical depths (delta-M-scaled\n!c if DELTAM = TRUE, otherwise equal to DTAUC)\n!c\n!c EMU(IU) Bottom-boundary directional emissivity at user\n!c angles.\n!c\n!c EVAL(IQ) Temporary storage for eigenvalues of Eq. SS(12)\n!c\n!c EVECC(IQ,IQ) Complete eigenvectors of SS(7) on return from\n!c SOLEIG; stored permanently in GC\n!c\n!c EXPBEA(LC) Transmission of direct beam in delta-M optical\n!c depth coordinates\n!c\n!c FLYR(LC) Separated fraction in delta-M method\n!c\n!c GL(K,LC) Phase function Legendre polynomial expansion\n!c coefficients, calculated from PMOM by\n!c including single-scattering albedo, factor\n!c 2K+1, and (if DELTAM=TRUE) the delta-M\n!c scaling\n!c\n!c GC(IQ,IQ,LC) Eigenvectors at polar quadrature angles,\n!c g in Eq. SC(1)\n!c\n!c GU(IU,IQ,LC) Eigenvectors interpolated to user polar angles\n!c ( g in Eqs. SC(3) and S1(8-9), i.e.\n!c G without the L factor )\n!c\n!c IPVT(LC*IQ) Integer vector of pivot indices for LINPACK\n!c routines\n!c\n!c KK(IQ,LC) Eigenvalues of coeff. matrix in Eq. SS(7)\n!c\n!c KCONV Counter in azimuth convergence test\n!c\n!c LAYRU(LU) Computational layer in which user output level\n!c UTAU(LU) is located\n!c\n!c LL(IQ,LC) Constants of integration L in Eq. SC(1),\n!c obtained by solving scaled version of Eq. SC(5)\n!c\n!c LYRCUT TRUE, radiation is assumed zero below layer\n!c NCUT because of almost complete absorption\n!c\n!c NAZ Number of azimuthal components considered\n!c\n!c NCUT Computational layer number in which absorption\n!c optical depth first exceeds ABSCUT\n!c\n!c OPRIM(LC) Single scattering albedo after delta-M scaling\n!c\n!c PASS1 TRUE on first entry, FALSE thereafter\n!c\n!c PKAG(0:LC) Integrated Planck function for internal emission\n!c\n!c PRNTU0(L) logical flag to trigger printing of azimuthally-\n!c averaged intensities:\n!c L quantities printed\n!c -- ------------------\n!c 1 azimuthally-averaged intensities at user\n!c levels and computational polar angles\n!c 2 azimuthally-averaged intensities at user\n!c levels and user polar angles\n!c\n!c PSI0(IQ) Sum just after square bracket in Eq. SD(9)\n!c\n!c PSI1(IQ) Sum in Eq. STWL(31d)\n!c\n!c RMU(IU,0:IQ) Bottom-boundary bidirectional reflectivity for a\n!c given azimuthal component. First index always\n!c refers to a user angle. Second index:\n!c if zero, refers to incident beam angle UMU0;\n!c if non-zero, refers to a computational angle.\n!c\n!c SQT(k) Square root of k (used only in LEPOLY for\n!c computing associated Legendre polynomials)\n!c\n!c TAUC(0:LC) Cumulative optical depth (un-delta-M-scaled)\n!c\n!c TAUCPR(0:LC) Cumulative optical depth (delta-M-scaled if\n!c DELTAM = TRUE, otherwise equal to TAUC)\n!c\n!c TPLANK Intensity emitted from top boundary\n!c\n!c UUM(IU,LU) Expansion coefficients when the intensity\n!c (u-super-M) is expanded in Fourier cosine series\n!c in azimuth angle\n!c\n!c U0C(IQ,LU) Azimuthally-averaged intensity at quadrature\n!c angle\n!c\n!c U0U(IU,LU) If ONLYFL = FALSE, azimuthally-averaged intensity\n!c at user angles and user levels\n!c\n!c If ONLYFL = TRUE and MAXUMU.GE.NSTR,\n!c azimuthally-averaged intensity at computational\n!c (Gaussian quadrature) angles and user levels;\n!c the corresponding quadrature angle cosines are\n!c returned in UMU. If MAXUMU.LT.NSTR, U0U will be\n!c zeroed, and UMU, NUMU will not be set.\n!c\n!c UTAUPR(LU) Optical depths of user output levels in delta-M\n!c coordinates; equal to UTAU(LU) if no delta-M\n!c\n!c WK() scratch array\n!c\n!c XR0(LC) X-sub-zero in expansion of thermal source func-\n!c tion preceding Eq. SS(14)(has no mu-dependence);\n!c b-sub-zero in Eq. STWL(24d)\n!c\n!c XR1(LC) X-sub-one in expansion of thermal source func-\n!c tion; see Eqs. SS(14-16); b-sub-one in STWL(24d)\n!c\n!c YLM0(L) Normalized associated Legendre polynomial\n!c of subscript L at the beam angle (not saved\n!c as function of superscipt M)\n!c\n!c YLMC(L,IQ) Normalized associated Legendre polynomial\n!c of subscript L at the computational angles\n!c (not saved as function of superscipt M)\n!c\n!c YLMU(L,IU) Normalized associated Legendre polynomial\n!c of subscript L at the user angles\n!c (not saved as function of superscipt M)\n!c\n!c Z() scratch array used in SOLVE0, ALBTRN to solve\n!c a linear system for the constants of integration\n!c\n!c Z0(IQ) Solution vectors Z-sub-zero of Eq. SS(16)\n!c\n!c Z0U(IU,LC) Z-sub-zero in Eq. SS(16) interpolated to user\n!c angles from an equation derived from SS(16)\n!c\n!c Z1(IQ) Solution vectors Z-sub-one of Eq. SS(16)\n!c\n!c Z1U(IU,LC) Z-sub-one in Eq. SS(16) interpolated to user\n!c angles from an equation derived from SS(16)\n!c\n!c ZBEAM(IU,LC) Particular solution for beam source\n!c\n!c ZJ(IQ) Right-hand side vector X-sub-zero in\n!c Eq. SS(19), also the solution vector\n!c Z-sub-zero after solving that system\n!c\n!c ZZ(IQ,LC) Permanent storage for the beam source vectors ZJ\n!c\n!c ZPLK0(IQ,LC) Permanent storage for the thermal source\n!c vectors Z0 obtained by solving Eq. SS(16)\n!c\n!c ZPLK1(IQ,LC) Permanent storage for the thermal source\n!c vectors Z1 obtained by solving Eq. SS(16)\n!c\n!c +-------------------------------------------------------------------+\n!c\n!c LOCAL SYMBOLIC DIMENSIONS (have big effect on storage requirements):\n!c\n!c MXCLY = Max no. of computational layers\n!c MXULV = Max no. of output levels\n!c MXCMU = Max no. of computation polar angles\n!c MXUMU = Max no. of output polar angles\n!c MXPHI = Max no. of output azimuthal angles\n!c MXSQT = Max no. of square roots of integers (for LEPOLY)\n\n!c +-------------------------------------------------------------------+\n\n!c .. Parameters ..\n\n!c ..\n!c .. Scalar Arguments ..\n\n CHARACTER, intent(in) :: HEADER*127\n LOGICAL, intent(in) :: LAMBER, ONLYFL, PLANK, USRANG, USRTAU\n INTEGER, intent(in) :: IBCND, MAXCLY, MAXMOM, MAXPHI, MAXULV, MAXUMU, NLYR, NMOM, NPHI, NSTR, NTAU, NUMU\n REAL, intent(in) :: ACCUR, ALBEDO, BTEMP, FBEAM, FISOT, PHI0, TEMIS, TTEMP,UMU0, WVNMHI, WVNMLO\n \n !c ..\n!c .. Array Arguments ..\n\n LOGICAL, intent(inout) :: PRNT( 5 )\n REAL, intent(inout) :: DTAUC( : ), &\n PHI( : ), PMOM( 0:, : ), &\n SSALB( : ), &\n TEMPER( 0: ), &\n UMU( : ), UTAU( : ), &\n UU( :,:,: ),UUS(:,:,:)\n \n!c ..\n!c .. Local Scalars ..\n\n LOGICAL LYRCUT \n INTEGER IQ, IU, J, KCONV, L, LC, LEV, LU, MAZIM, NAZ, NCOL, NCOS, NCUT, NS\n\t integer :: iazm, ier, istr\n REAL AZERR, AZTERM, BPLANK, COSPHI, DELM0, DUM, SGN, TPLANK\n REAL ANGCOS(1)\n\n!c ..\n!c .. Local Arrays ..\n\n LOGICAL PRNTU0( 2 )\n INTEGER IPVT( NNLYRI ), LAYRU( MXULV )\n\n REAL AMB( MI, MI ), APB( MI, MI ), ARRAY( MXCMU, MXCMU ), &\n B( NNLYRI ), BDR( MI, 0:MI ), BEM( MI ), &\n CBAND( MI9M2, NNLYRI ), CC( MXCMU, MXCMU ), &\n\t CMU( MXCMU ), CWT( MXCMU ), DTAUCP( MXCLY ), &\n EMU( MXUMU ), EVAL( MI ), EVECC( MXCMU, MXCMU ), &\n EXPBEA( 0:MXCLY ), FLDIR( MXULV ), FLDN( MXULV ), &\n FLYR( MXCLY ), GC( MXCMU, MXCMU, MXCLY ), &\n GL( 0:MXCMU, MXCLY ), GU( MXUMU, MXCMU, MXCLY ), &\n KK( MXCMU, MXCLY ), LL( MXCMU, MXCLY ), OPRIM( MXCLY ), &\n PHASA( MXCLY ), PHAST( MXCLY ), PHASM( MXCLY ), &\n PKAG( 0:MXCLY ), PSI0( MXCMU ), &\n PSI1( MXCMU ), RMU( MXUMU, 0:MI ), &\n TAUC( 0:MXCLY ), TAUCPR( 0:MXCLY ), U0C( MXCMU, MXULV ), &\n U0U( MXUMU, MXULV ), UTAUPR( MXULV ), &\n UUM( MXUMU, MXULV ), WK( MXCMU ), XR0( MXCLY ), &\n XR1( MXCLY ), YLM0( 0:MXCMU ), YLMC( 0:MXCMU, MXCMU ), &\n YLMU( 0:MXCMU, MXUMU ), Z( NNLYRI ), Z0( MXCMU ), &\n Z0U( MXUMU, MXCLY ), Z1( MXCMU ), Z1U( MXUMU, MXCLY ), &\n ZBEAM( MXUMU, MXCLY )\n REAL ZJ( MXCMU ), ZPLK0( MXCMU, MXCLY ),ZPLK1( MXCMU, MXCLY ), ZZ( MXCMU, MXCLY )\n\n\t\treal :: mazim_phirad\n\n DOUBLE PRECISION AAD( MI, MI ), EVALD( MI ), EVECCD( MI, MI ), WKD( MXCMU )\n \n!c ..\n\n\n\t\tinteger :: start_time, end_time, crate, cmax\n\n \n\t\tTAUC = 0.0\n\t\n\n DO 30 LC = 1, NLYR\n\n IF( SSALB( LC ).EQ.1.0 ) SSALB( LC ) = 1.0 - DITHER\n TAUC( LC ) = TAUC( LC - 1 ) + DTAUC( LC )\n!c \t\tprint*,SSALB(LC)\n\n 30 CONTINUE\n\n\n!c ** Check input dimensions and variables\n\n!c ** Zero internal and output arrays\n\n\n\t\t\tiazm = 1\n!c DO iazm = 1,NPHI \n \tPHIRAD(iazm) = (PHI(iazm) - PHI0) * PIMYPI/180.d0\n \tCOSPHI_S(0,iazm) = 1.d0\n \tif (PHIRAD(iazm) < approx_limit) then \n \t\tCOSPHI_S(1,iazm) = 1. - PHIRAD(iazm)*PHIRAD(iazm)/2.\n\t\t\t\telse\n\t \tCOSPHI_S(1,iazm) = COS(PHIRAD(iazm))\n\t\t\t\tendif\n \n DO istr = 2,NSTR-1\n \t\tCOSPHI_S(istr,iazm) = 2.d0 * COSPHI_S(istr-1,iazm) * COSPHI_S(1,iazm) - COSPHI_S(istr-2,iazm) \n ENDDO\n!c ENDDO\n\n\n!c ** Perform various setup operations\n\n CALL SETDIS( CMU_S, DELTAM, DTAUC, DTAUCP, &\n EXPBEA, FBEAM, FLYR, &\n GL, IBCND, LAYRU, LYRCUT, MAXMOM, MAXUMU, MXCMU, &\n NCUT, NLYR, NTAU, NN, NSTR, PLANK, NUMU, ONLYFL, &\n CORINT, OPRIM, PMOM, SSALB, TAUC, TAUCPR, UTAU, &\n UTAUPR, UMU, UMU0, USRTAU, USRANG )\n\n\n!c ** Handle special case for getting albedo\n!c ** and transmissivity of medium for many\n!c ** beam angles at once\n\n!c ** Calculate Planck functions\n IF( .NOT.PLANK ) THEN\n\n BPLANK = 0.0\n TPLANK = 0.0\n\t\t PKAG = 0.0\n\n ELSE\n\n TPLANK = 0.0\n BPLANK = PLKAVG( WVNMLO, WVNMHI, BTEMP )\n\n DO 40 LEV = 0, NLYR\n PKAG( LEV ) = PLKAVG( WVNMLO, WVNMHI, TEMPER( LEV ) )\n 40 CONTINUE\n\n END IF\n\t\t\n!c ======== BEGIN LOOP TO SUM AZIMUTHAL COMPONENTS OF INTENSITY =======\n!c (EQ STWJ 5, STWL 6)\n\n KCONV = 0\n NAZ = NSTR - 1\n!c ** Azimuth-independent case\n\n IF( FBEAM.EQ.0.0 .OR. ABS(1.-UMU0).LT.1.E-5 .OR. ( ABS(1.-UMU(1)).LT.1.E-5 ) ) NAZ = 0\n\n\n\n\n DO 180 MAZIM = 0, NAZ\n\n IF( MAZIM.EQ.0 ) DELM0 = 1.0\n IF( MAZIM.GT.0 ) DELM0 = 0.0\n\n!c ** Get normalized associated Legendre\n!c ** polynomials for\n!c ** (a) incident beam angle cosine\n!c ** (b) computational and user polar angle\n!c ** cosines\n\n\n IF( FBEAM.GT.0.0 ) THEN\n\n NCOS = 1\n ANGCOS = -UMU0\n\n CALL LEPOLY( NCOS, MAZIM, MXCMU, NSTR-1, ANGCOS, SQT, YLM0 )\n\n\t\t\t\n END IF\n\n\n\t\t CALL LEPOLY( NUMU, MAZIM, MXCMU, NSTR-1, UMU, SQT, YLMU )\n\n CALL LEPOLY( NN, MAZIM, MXCMU, NSTR-1, CMU_S, SQT, YLMC )\n\n\n!c ** Get normalized associated Legendre polys.\n!c ** with negative arguments from those with\n!c ** positive arguments; Dave/Armstrong Eq. (15),\n!c ** STWL(59)\n\n\n SGN = -1.0\n\n DO 70 L = MAZIM, NSTR - 1\n\n SGN = -SGN\n\n DO 60 IQ = NN + 1, NSTR\n YLMC( L, IQ ) = SGN*YLMC( L, IQ - NN )\n 60 CONTINUE\n\n 70 CONTINUE\n!c ** Specify users bottom reflectivity\n!c ** and emissivity properties\n IF( .NOT.LYRCUT )THEN\t\t \n CALL SURFAC( ALBEDO, LAMBER, MI, MAZIM, MXUMU, NN, BDR, EMU, BEM, RMU )\n\n\t\tENDIF\n\n\n\n!c =================== BEGIN LOOP ON COMPUTATIONAL LAYERS =============\n\n DO 80 LC = 1, NCUT\n\n!c ** Solve eigenfunction problem in Eq. STWJ(8B),\n!c ** STWL(23f); return eigenvalues and eigenvectors\n\n CALL SOLEIG( AMB, APB, ARRAY, CMU_S, CWT_S, GL( 0,LC ), MI, &\n MAZIM, MXCMU, NN, NSTR, YLMC, CC, EVECC, EVAL, &\n KK( 1,LC ), GC( 1,1,LC ), AAD, EVECCD, EVALD, &\n WKD )\n!c ** Calculate particular solutions of\n!c ** Eq. SS(18), STWL(24a) for incident\n!c ** beam source\n IF( FBEAM.GT.0.0 ) &\n CALL UPBEAM( ARRAY, CC, CMU_S, DELM0, FBEAM, GL( 0,LC ), &\n IPVT, MAZIM, MXCMU, NN, NSTR, PI, UMU0, WK, &\n YLM0, YLMC, ZJ, ZZ( 1,LC ) )\n\n\n!c ** Calculate particular solutions of Eq.\n!c ** SS(15), STWL(25) for thermal emission\n!c ** source\n!c\n\t\t\t\n IF( PLANK .AND. MAZIM.EQ.0 ) THEN\n\n XR1( LC ) = 0.0\n\n IF( DTAUCP( LC ).GT.0.0 ) XR1( LC ) = ( PKAG( LC ) - PKAG( LC-1 ) ) / DTAUCP( LC )\n\n XR0( LC ) = PKAG( LC-1 ) - XR1( LC )*TAUCPR( LC-1 )\n\n CALL UPISOT( ARRAY, CC, CMU_S, IPVT, MXCMU, NN, NSTR, &\n OPRIM( LC ), WK, XR0( LC ), XR1( LC ), &\n Z0, Z1, ZPLK0( 1,LC ), ZPLK1( 1,LC ) )\n\n\t\t\telse\n\t\t\t\tZ0 = 0.\n\t\t\t\tZ1 = 0.\n END IF\n\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\n\n IF( .NOT.ONLYFL .AND. USRANG ) THEN\n\n!c ** Interpolate eigenvectors\n!c ** to user angles\n\n CALL TERPEV( CWT_S, EVECC, GL( 0,LC ), GU( 1,1,LC ), MAZIM, &\n MXCMU, MXUMU, NN, NSTR, NUMU, WK, YLMC, &\n YLMU )\n!c ** Interpolate source terms\n!c ** to user angles\n\n CALL TERPSO( CWT_S, DELM0, FBEAM, GL( 0,LC ), MAZIM, MXCMU, &\n PLANK, NUMU, NSTR, OPRIM( LC ), PI, YLM0, &\n YLMC, YLMU, PSI0, PSI1, XR0( LC ), &\n XR1( LC ), Z0, Z1, ZJ, ZBEAM( 1,LC ), &\n Z0U( 1,LC ), Z1U( 1,LC ) )\n\n END IF\n\n 80 CONTINUE\n\n!c =================== END LOOP ON COMPUTATIONAL LAYERS ===============\n\n\n!c ** Set coefficient matrix of equations combining\n!c ** boundary and layer interface conditions\n\n CALL SETMTX( BDR, CBAND, CMU_S, CWT_S, DELM0, DTAUCP, GC, KK, &\n LAMBER, LYRCUT, MI, MI9M2, MXCMU, NCOL, NCUT, &\n NNLYRI, NN, NSTR, TAUCPR, WK )\n\n!c ** Solve for constants of integration in homo-\n!c ** geneous solution (general boundary conditions)\n\n\t\tif ( .NOT. (PLANK .and. MAZIM .eq. 0)) then \n\t\t\tZPLK0 = 0.\n\t\t\tZPLK1 = 0.\n\t\tendif\n\n CALL SOLVE0( B, BDR, BEM, BPLANK, CBAND, CMU_S, CWT_S, EXPBEA, &\n FBEAM, FISOT, IPVT, LAMBER, LL, LYRCUT, MAZIM, MI, &\n MI9M2, MXCMU, NCOL, NCUT, NN, NSTR, NNLYRI, PI, &\n TPLANK, TAUCPR, UMU0, Z, ZZ, ZPLK0, ZPLK1 )\n\n!c ** Compute upward and downward fluxes\n\n\n UUM = 0.0\n\n!c ! USRANG is always true\n!c ** Compute azimuthal intensity\n!c ** components at user angles\n\n CALL USRINT( BPLANK, CMU_S, CWT_S, DELM0, DTAUCP, EMU, EXPBEA, &\n FBEAM, FISOT, GC, GU, KK, LAMBER, LAYRU, LL, &\n LYRCUT, MAZIM, MXCMU, MXULV, MXUMU, NCUT, NLYR, &\n NN, NSTR, PLANK, NUMU, NTAU, PI, RMU, TAUCPR, &\n TPLANK, UMU, UMU0, UTAUPR, WK, ZBEAM, Z0U, Z1U, &\n ZZ, ZPLK0, ZPLK1, UUM )\n\n\n\n IF( MAZIM.EQ.0 ) THEN\n!c ** Save azimuthally averaged intensities\n\n!C we only ever have one angle set\n\t\t\tIU = 1\n\t\t\tJ = 1\n\n DO 130 LU = 1, NTAU\n\n\t\t\t\tU0U( IU, LU ) = UUM( IU, LU )\n\t\t\t\tUU( IU, LU, J ) = UUM( IU, LU )\n\n 130 CONTINUE\n!c ** Print azimuthally averaged intensities\n!c ** at user angles\n\n\n\n ELSE\n!c ** Increment intensity by current\n!c ** azimuthal component (Fourier\n!c ** cosine series); Eq SD(2), STWL(6)\n AZERR = 0.0\n\n!C We can get away with this because we ever only run one angle. \n\t\t\tJ=1\n\t\t\tIU = 1\n\n \n\t\t\t IF(NSTR <= 16)THEN\t\n\t\t\t \tmazim_phirad = MAZIM*PHIRAD( J )\n\t\t\t \tif (mazim_phirad < approx_limit) then \n\t\t\t \t\tCOSPHI = 1. - mazim_phirad*mazim_phirad/2.0\n\t\t\t \telse\n \tCOSPHI = COS( mazim_phirad )\n endif\n \t\tELSE\n COSPHI = COSPHI_S(MAZIM,J)\n ENDIF \n\n DO 160 LU = 1, NTAU\n\n AZTERM = UUM( IU, LU )*COSPHI\n UU( IU, LU, J ) = UU( IU, LU, J ) + AZTERM\n AZERR = MAX( AZERR, RATIO( ABS(AZTERM), ABS(UU(IU,LU,J)) ) )\n\n 160 CONTINUE\n\n IF( AZERR.LE.ACCUR ) KCONV = KCONV + 1\n\n\t\tIF( (KCONV.GE. 2) ) then \n\t\t\tGO TO 190\n\t\t endif\n\n END IF\n\n 180 CONTINUE\n\n!c =================== END LOOP ON AZIMUTHAL COMPONENTS ===============\n\n\n 190 CONTINUE\n \n\n!c ** Apply Nakajima/Tanaka intensity\n!c ** corrections\n\n\n!c ** Print intensities\n\n END subroutine DISORT_DP_GC\n\n\n\n\n\n\n SUBROUTINE ASYMTX( AA, EVEC, EVAL, M, IA, IEVEC, IER, WKD, AAD, &\n EVECD, EVALD )\n\n!c ======= D O U B L E P R E C I S I O N V E R S I O N ======\n\n!c Solves eigenfunction problem for real asymmetric matrix\n!c for which it is known a priori that the eigenvalues are real.\n\n!c This is an adaptation of a subroutine EIGRF in the IMSL\n!c library to use real instead of complex arithmetic, accounting\n!c for the known fact that the eigenvalues and eigenvectors in\n!c the discrete ordinate solution are real. Other changes include\n!c putting all the called subroutines in-line, deleting the\n!c performance index calculation, updating many DO-loops\n!c to Fortran77, and in calculating the machine precision\n!c TOL instead of specifying it in a data statement.\n\n!c EIGRF is based primarily on EISPACK routines. The matrix is\n!c first balanced using the Parlett-Reinsch algorithm. Then\n!c the Martin-Wilkinson algorithm is applied.\n\n!c There is a statement 'J = WKD( I )' that converts a double\n!c precision variable to an integer variable, that seems dangerous\n!c to us in principle, but seems to work fine in practice.\n\n!c References:\n!c Dongarra, J. and C. Moler, EISPACK -- A Package for Solving\n!c Matrix Eigenvalue Problems, in Cowell, ed., 1984:\n!c Sources and Development of Mathematical Software,\n!c Prentice-Hall, Englewood Cliffs, NJ\n!c Parlett and Reinsch, 1969: Balancing a Matrix for Calculation\n!c of Eigenvalues and Eigenvectors, Num. Math. 13, 293-304\n!c Wilkinson, J., 1965: The Algebraic Eigenvalue Problem,\n!c Clarendon Press, Oxford\n\n\n!c .. Scalar Arguments ..\n\n INTEGER, intent(in) :: IA, IEVEC, M\n\t integer, intent(inout) :: IER\n!c ..\n!c .. Array Arguments ..\n\n REAL, intent(inout) :: AA( IA, M ), EVAL( M ), EVEC( IEVEC, M )\n DOUBLE PRECISION, intent(inout) :: AAD( IA, M ), EVALD( M ), EVECD( IA, M ), &\n WKD( * )\n!c ..\n!c .. Local Scalars ..\n\n LOGICAL NOCONV, NOTLAS\n INTEGER I, II, IN, J, K, KA, KKK, L, LB, LLL, N, N1, N2\n DOUBLE PRECISION COL, DISCRI, F, G, H, &\n P, Q, R, REPL, RNORM, ROW, S, SCALE, SGN, T, &\n UU, VV, W, X, Y, Z, sqrt_discri\n!c ..\n!c .. External Functions ..\n\n!c ..\n real*8, parameter :: C1 = 0.4375D0, C2=0.5D0, C3=0.75D0 , &\n C4=0.95D0, C5=16.D0, C6=256.D0\n \n\n\n IER = 0\n\n\n!c ** Handle 1x1 and 2x2 special cases\n IF( M.EQ.1 ) THEN\n\n EVAL( 1 ) = AA( 1,1 )\n EVEC( 1,1 ) = 1.0\n RETURN\n\n ELSE IF( M.EQ.2 ) THEN\n\n DISCRI = ( AA( 1,1 ) - AA( 2,2 ) )**2 + 4.*AA( 1,2 )*AA( 2,1 )\n\n\n SGN = ONE\n\n IF( AA( 1,1 ) .LT. AA( 2,2 ) ) SGN = - ONE\n\t\t\tsqrt_discri = SQRT( DISCRI )\n EVAL( 1 ) = 0.5*( AA( 1,1 ) + AA( 2,2 ) + SGN*sqrt_discri )\n EVAL( 2 ) = 0.5*( AA( 1,1 ) + AA( 2,2 ) - SGN*sqrt_discri )\n EVEC( 1,1 ) = 1.0\n EVEC( 2,2 ) = 1.0\n\n IF( AA( 1,1 ) .EQ. AA( 2,2 ) .AND. &\n ( AA( 2,1 ).EQ.0.0 .OR. AA( 1,2 ).EQ.0.0 ) ) THEN\n\n RNORM = ABS( AA( 1,1 ) ) + ABS( AA( 1,2 ) ) + ABS( AA( 2,1 ) ) + ABS( AA( 2,2 ) )\n W = TOL * RNORM\n EVEC( 2,1 ) = AA( 2,1 ) / W\n EVEC( 1,2 ) = - AA( 1,2 ) / W\n\n ELSE\n\n EVEC( 2,1 ) = AA( 2,1 ) / ( EVAL( 1 ) - AA( 2,2 ) )\n EVEC( 1,2 ) = AA( 1,2 ) / ( EVAL( 2 ) - AA( 1,1 ) )\n\n END IF\n\n RETURN\n\n END IF\n\n AAD(1:M,1:M) = 1.d0 * AA(1:M,1:M)\n\n\n!c ** Initialize output variables\n IER = 0\n EVALD(1:M) = 0.d0\n EVECD(:,:) = 0.d0\n\n\t\n DO 40 I = 1, M\n\n EVECD( I, I ) = ONE\n\n 40 CONTINUE\n\n!c ** Balance the input matrix and reduce its norm by\n!c ** diagonal similarity transformation stored in WK;\n!c ** then search for rows isolating an eigenvalue\n!c ** and push them down\n RNORM = ZERO\n L = 1\n K = M\n\n 50 CONTINUE\n KKK = K\n\n DO 90 J = KKK, 1, -1\n\n ROW = ZERO\n\n DO 60 I = 1, K\n IF( I.NE.J ) ROW = ROW + ABS( AAD( J,I ) )\n 60 CONTINUE\n\n IF( ROW.EQ.ZERO ) THEN\n\n WKD( K ) = J\n\n IF( J.NE.K ) THEN\n\n DO 70 I = 1, K\n REPL = AAD( I, J )\n AAD( I, J ) = AAD( I, K )\n AAD( I, K ) = REPL\n 70 CONTINUE\n\n DO 80 I = L, M\n REPL = AAD( J, I )\n AAD( J, I ) = AAD( K, I )\n AAD( K, I ) = REPL\n 80 CONTINUE\n\n END IF\n\n K = K - 1\n GO TO 50\n\n END IF\n\n 90 CONTINUE\n!c ** Search for columns isolating an\n!c ** eigenvalue and push them left\n 100 CONTINUE\n LLL = L\n\n DO 140 J = LLL, K\n\n COL = ZERO\n\n DO 110 I = L, K\n IF( I.NE.J ) COL = COL + ABS( AAD( I,J ) )\n 110 CONTINUE\n\n IF( COL.EQ.ZERO ) THEN\n\n WKD( L ) = J\n\n IF( J.NE.L ) THEN\n\n DO 120 I = 1, K\n REPL = AAD( I, J )\n AAD( I, J ) = AAD( I, L )\n AAD( I, L ) = REPL\n 120 CONTINUE\n\n DO 130 I = L, M\n REPL = AAD( J, I )\n AAD( J, I ) = AAD( L, I )\n AAD( L, I ) = REPL\n 130 CONTINUE\n\n END IF\n\n L = L + 1\n GO TO 100\n\n END IF\n\n 140 CONTINUE\n\n!c ** Balance the submatrix in rows L through K\n \n WKD(L:K) = ONE\n\n 160 CONTINUE\n NOCONV = .FALSE.\n\n DO 220 I = L, K\n\n COL = ZERO\n ROW = ZERO\n\n DO 170 J = L, K\n\n IF( J.NE.I ) THEN\n COL = COL + ABS( AAD( J,I ) )\n ROW = ROW + ABS( AAD( I,J ) )\n END IF\n\n 170 CONTINUE\n\n F = ONE\n G = ROW / C5\n H = COL + ROW\n\n 180 CONTINUE\n IF( COL.LT.G ) THEN\n\n F = F*C5\n COL = COL*C6\n GO TO 180\n\n END IF\n\n G = ROW*C5\n\n 190 CONTINUE\n IF( COL.GE.G ) THEN\n\n F = F / C5\n COL = COL / C6\n GO TO 190\n\n END IF\n!c ** Now balance\n IF( ( COL + ROW ) / F.LT.C4*H ) THEN\n\n WKD( I ) = WKD( I )*F\n NOCONV = .TRUE.\n\n DO 200 J = L, M\n AAD( I, J ) = AAD( I, J ) / F\n 200 CONTINUE\n\n \n \t\t\t AAD(1:K,I) = AAD(1:K,I) * F\n\n END IF\n\n 220 CONTINUE\n\n\n IF( NOCONV ) GO TO 160\n!c ** Is A already in Hessenberg form?\n IF( K-1 .LT. L+1 ) GO TO 370\n\n!c ** Transfer A to a Hessenberg form\n DO 310 N = L + 1, K - 1\n\n H = ZERO\n WKD( N + M ) = ZERO\n SCALE = ZERO\n!c ** Scale column\n DO 230 I = N, K\n SCALE = SCALE + ABS( AAD( I,N - 1 ) )\n 230 CONTINUE\n\n IF( SCALE.NE.ZERO ) THEN\n\n DO 240 I = K, N, -1\n WKD( I + M ) = AAD( I, N - 1 ) / SCALE\n H = H + WKD( I + M )**2\n 240 CONTINUE\n\n G = - SIGN( SQRT( H ), WKD( N + M ) )\n H = H - WKD( N + M )*G\n WKD( N + M ) = WKD( N + M ) - G\n!c ** Form (I-(U*UT)/H)*A\n DO 270 J = N, M\n\n F = ZERO\n\n DO 250 I = K, N, -1\n F = F + WKD( I + M )*AAD( I, J )\n 250 CONTINUE\n\n DO 260 I = N, K\n AAD( I, J ) = AAD( I, J ) - WKD( I + M )*F / H\n 260 CONTINUE\n\n 270 CONTINUE\n!c ** Form (I-(U*UT)/H)*A*(I-(U*UT)/H)\n DO 300 I = 1, K\n\n F = ZERO\n\n DO 280 J = K, N, -1\n F = F + WKD( J + M )*AAD( I, J )\n 280 CONTINUE\n\n DO 290 J = N, K\n AAD( I, J ) = AAD( I, J ) - WKD( J + M )*F / H\n 290 CONTINUE\n\n 300 CONTINUE\n\n WKD( N + M ) = SCALE*WKD( N + M )\n AAD( N, N - 1 ) = SCALE*G\n\n END IF\n\n 310 CONTINUE\n\n\n DO 360 N = K - 2, L, -1\n\n N1 = N + 1\n N2 = N + 2\n F = AAD( N + 1, N )\n\n IF( F.NE.ZERO ) THEN\n\n F = F*WKD( N + 1 + M )\n\n DO 320 I = N + 2, K\n WKD( I + M ) = AAD( I, N )\n 320 CONTINUE\n\n IF( N + 1.LE.K ) THEN\n\n DO 350 J = 1, M\n\n G = ZERO\n\n DO 330 I = N + 1, K\n G = G + WKD( I + M )*EVECD( I, J )\n 330 CONTINUE\n\n G = G / F\n\n DO 340 I = N + 1, K\n EVECD( I, J ) = EVECD( I, J ) + G*WKD( I + M )\n 340 CONTINUE\n\n 350 CONTINUE\n\n END IF\n\n END IF\n\n 360 CONTINUE\n\n\n 370 CONTINUE\n\n N = 1\n\n DO 390 I = 1, M\n\n DO 380 J = N, M\n RNORM = RNORM + ABS( AAD( I,J ) )\n 380 CONTINUE\n\n N = I\n\n IF( I.LT.L .OR. I.GT.K ) EVALD( I ) = AAD( I, I )\n\n 390 CONTINUE\n\n N = K\n T = ZERO\n\n!c ** Search for next eigenvalues\n 400 CONTINUE\n IF( N.LT.L ) GO TO 550\n\n IN = 0\n N1 = N - 1\n N2 = N - 2\n!c ** Look for single small sub-diagonal element\n 410 CONTINUE\n\n DO 420 I = L, N\n\n LB = N + L - I\n\n IF( LB.EQ.L ) GO TO 430\n\n S = ABS( AAD( LB - 1,LB - 1 ) ) + ABS( AAD( LB,LB ) )\n\n IF( S.EQ.ZERO ) S = RNORM\n\n IF( ABS( AAD( LB, LB-1 ) ).LE. TOL*S ) GO TO 430\n\n 420 CONTINUE\n\n\n 430 CONTINUE\n X = AAD( N, N )\n\n IF( LB.EQ.N ) THEN\n!c ** One eigenvalue found\n AAD( N, N ) = X + T\n EVALD( N ) = AAD( N, N )\n N = N1\n GO TO 400\n\n END IF\n\n Y = AAD( N1, N1 )\n W = AAD( N, N1 )*AAD( N1, N )\n\n IF( LB.EQ.N1 ) THEN\n!c ** Two eigenvalues found\n P = ( Y - X )*C2\n Q = P**2 + W\n Z = SQRT( ABS( Q ) )\n AAD( N, N ) = X + T\n X = AAD( N, N )\n AAD( N1, N1 ) = Y + T\n!c ** Real pair\n Z = P + SIGN( Z, P )\n EVALD( N1 ) = X + Z\n EVALD( N ) = EVALD( N1 )\n\n IF( Z.NE.ZERO ) EVALD( N ) = X - W / Z\n\n X = AAD( N, N1 )\n!c ** Employ scale factor in case\n!c ** X and Z are very small\n R = SQRT( X*X + Z*Z )\n P = X / R\n Q = Z / R\n!c ** Row modification\n DO 440 J = N1, M\n Z = AAD( N1, J )\n AAD( N1, J ) = Q*Z + P*AAD( N, J )\n AAD( N, J ) = Q*AAD( N, J ) - P*Z\n 440 CONTINUE\n!c ** Column modification\n DO 450 I = 1, N\n Z = AAD( I, N1 )\n AAD( I, N1 ) = Q*Z + P*AAD( I, N )\n AAD( I, N ) = Q*AAD( I, N ) - P*Z\n 450 CONTINUE\n!c ** Accumulate transformations\n DO 460 I = L, K\n Z = EVECD( I, N1 )\n EVECD( I, N1 ) = Q*Z + P*EVECD( I, N )\n EVECD( I, N ) = Q*EVECD( I, N ) - P*Z\n 460 CONTINUE\n\n N = N2\n GO TO 400\n\n END IF\n\n\n IF( IN.EQ.30 ) THEN\n\n!c ** No convergence after 30 iterations; set error\n!c ** indicator to the index of the current eigenvalue\n IER = N\n GO TO 700\n\n END IF\n!c ** Form shift\n IF( IN.EQ.10 .OR. IN.EQ.20 ) THEN\n\n T = T + X\n\n DO 470 I = L, N\n AAD( I, I ) = AAD( I, I ) - X\n 470 CONTINUE\n\n S = ABS( AAD( N,N1 ) ) + ABS( AAD( N1,N2 ) )\n X = C3*S\n Y = X\n W = -C1*S**2\n\n END IF\n\n\n IN = IN + 1\n\n!c ** Look for two consecutive small sub-diagonal elements\n\n DO 480 J = LB, N2\n I = N2 + LB - J\n Z = AAD( I, I )\n R = X - Z\n S = Y - Z\n P = ( R*S - W ) / AAD( I + 1, I ) + AAD( I, I + 1 )\n Q = AAD( I + 1, I + 1 ) - Z - R - S\n R = AAD( I + 2, I + 1 )\n S = ABS( P ) + ABS( Q ) + ABS( R )\n P = P / S\n Q = Q / S\n R = R / S\n\n IF( I.EQ.LB ) GO TO 490\n\n UU = ABS( AAD( I, I-1 ) )*( ABS( Q ) + ABS( R ) )\n VV = ABS( P ) * ( ABS( AAD( I-1, I-1 ) ) + ABS( Z ) + ABS( AAD( I+1, I+1 ) ) )\n\n IF( UU .LE. TOL*VV ) GO TO 490\n\n 480 CONTINUE\n\n 490 CONTINUE\n AAD( I+2, I ) = ZERO\n\n DO 500 J = I + 3, N\n AAD( J, J - 2 ) = ZERO\n AAD( J, J - 3 ) = ZERO\n 500 CONTINUE\n\n!c ** Double QR step involving rows K to N and columns M to N\n\n DO 540 KA = I, N1\n\n NOTLAS = KA.NE.N1\n\n IF( KA.EQ.I ) THEN\n\n S = SIGN( SQRT( P*P + Q*Q + R*R ), P )\n\n IF( LB.NE.I ) AAD( KA, KA - 1 ) = -AAD( KA, KA - 1 )\n\n ELSE\n\n P = AAD( KA, KA - 1 )\n Q = AAD( KA + 1, KA - 1 )\n R = ZERO\n\n IF( NOTLAS ) R = AAD( KA + 2, KA - 1 )\n\n X = ABS( P ) + ABS( Q ) + ABS( R )\n\n IF( X.EQ.ZERO ) GO TO 540\n\n P = P / X\n Q = Q / X\n R = R / X\n S = SIGN( SQRT( P*P + Q*Q + R*R ), P )\n AAD( KA, KA - 1 ) = -S*X\n\n END IF\n\n P = P + S\n X = P / S\n Y = Q / S\n Z = R / S\n Q = Q / P\n R = R / P\n!c ** Row modification\n DO 510 J = KA, M\n\n P = AAD( KA, J ) + Q*AAD( KA + 1, J )\n\n IF( NOTLAS ) THEN\n\n P = P + R*AAD( KA + 2, J )\n AAD( KA + 2, J ) = AAD( KA + 2, J ) - P*Z\n\n END IF\n\n AAD( KA + 1, J ) = AAD( KA + 1, J ) - P*Y\n AAD( KA, J ) = AAD( KA, J ) - P*X\n\n 510 CONTINUE\n!c ** Column modification\n DO 520 II = 1, MIN( N, KA + 3 )\n\n P = X*AAD( II, KA ) + Y*AAD( II, KA + 1 )\n\n IF( NOTLAS ) THEN\n\n P = P + Z*AAD( II, KA + 2 )\n AAD( II, KA + 2 ) = AAD( II, KA + 2 ) - P*R\n\n END IF\n\n AAD( II, KA + 1 ) = AAD( II, KA + 1 ) - P*Q\n AAD( II, KA ) = AAD( II, KA ) - P\n\n 520 CONTINUE\n!c ** Accumulate transformations\n DO 530 II = L, K\n\n P = X*EVECD( II, KA ) + Y*EVECD( II, KA + 1 )\n\n IF( NOTLAS ) THEN\n\n P = P + Z*EVECD( II, KA + 2 )\n EVECD( II, KA + 2 ) = EVECD( II, KA + 2 ) - P*R\n\n END IF\n\n EVECD( II, KA + 1 ) = EVECD( II, KA + 1 ) - P*Q\n EVECD( II, KA ) = EVECD( II, KA ) - P\n\n 530 CONTINUE\n\n 540 CONTINUE\n\n GO TO 410\n!c ** All evals found, now backsubstitute real vector\n 550 CONTINUE\n\n IF( RNORM.NE.ZERO ) THEN\n\n DO 580 N = M, 1, -1\n\n N2 = N\n AAD( N, N ) = ONE\n\n DO 570 I = N - 1, 1, -1\n\n W = AAD( I, I ) - EVALD( N )\n\n IF( W.EQ.ZERO ) W = TOL*RNORM\n\n R = AAD( I, N )\n\n DO 560 J = N2, N - 1\n R = R + AAD( I, J )*AAD( J, N )\n 560 CONTINUE\n\n AAD( I, N ) = -R / W\n N2 = I\n\n 570 CONTINUE\n\n 580 CONTINUE\n!c ** End backsubstitution vectors of isolated evals\n DO 600 I = 1, M\n\n IF( I.LT.L .OR. I.GT.K ) THEN\n\n DO 590 J = I, M\n EVECD( I, J ) = AAD( I, J )\n 590 CONTINUE\n\n END IF\n\n 600 CONTINUE\n!c ** Multiply by transformation matrix\n IF( K.NE.0 ) THEN\n\n DO 630 J = M, L, -1\n\n DO 620 I = L, K\n\n Z = ZERO\n\n DO 610 N = L, MIN( J, K )\n Z = Z + EVECD( I, N )*AAD( N, J )\n 610 CONTINUE\n\n EVECD( I, J ) = Z\n\n 620 CONTINUE\n\n 630 CONTINUE\n\n END IF\n\n END IF\n\n\n DO 650 I = L, K\n\n DO 640 J = 1, M\n EVECD( I, J ) = EVECD( I, J ) * WKD( I )\n 640 CONTINUE\n\n 650 CONTINUE\n\n!c ** Interchange rows if permutations occurred\n DO 670 I = L-1, 1, -1\n\n J = WKD( I )\n\n IF( I.NE.J ) THEN\n\n DO 660 N = 1, M\n REPL = EVECD( I, N )\n EVECD( I, N ) = EVECD( J, N )\n EVECD( J, N ) = REPL\n 660 CONTINUE\n\n END IF\n\n 670 CONTINUE\n\n\n DO 690 I = K + 1, M\n\n J = WKD( I )\n\n IF( I.NE.J ) THEN\n\n DO 680 N = 1, M\n REPL = EVECD( I, N )\n EVECD( I, N ) = EVECD( J, N )\n EVECD( J, N ) = REPL\n 680 CONTINUE\n\n END IF\n\n 690 CONTINUE\n\n!c ** Put results into output arrays\n 700 CONTINUE\n\n DO 720 J = 1, M\n\n EVAL( J ) = EVALD( J )\n\n DO 710 K = 1, M\n EVEC( J, K ) = EVECD( J, K )\n 710 CONTINUE\n\n 720 CONTINUE\n\n END SUBROUTINE ASYMTX\n\n\n\n SUBROUTINE SETDIS( CMU, DELTAM, DTAUC, DTAUCP, EXPBEA, FBEAM, &\n FLYR, GL, IBCND, LAYRU, LYRCUT, MAXMOM, MAXUMU, &\n MXCMU, NCUT, NLYR, NTAU, NN, NSTR, PLANK, NUMU, &\n ONLYFL, CORINT, OPRIM, PMOM, SSALB, TAUC, &\n TAUCPR, UTAU, UTAUPR, UMU, UMU0, USRTAU, &\n USRANG )\n\n!c Perform miscellaneous setting-up operations\n!c\n!c INPUT : all are DISORT input variables (see DOC file)\n!c\n!c\n!c O U T P U T V A R I A B L E S:\n!c\n!c NTAU,UTAU if USRTAU = FALSE (defined in DISORT.doc)\n!c NUMU,UMU if USRANG = FALSE (defined in DISORT.doc)\n!c\n!c EXPBEA transmission of direct beam\n!c\n!c FLYR separated fraction in delta-M method\n!c\n!c GL phase function Legendre coefficients multiplied\n!c by (2L+1) and single-scatter albedo\n!c\n!c LAYRU Computational layer in which UTAU falls\n!c\n!c LYRCUT flag as to whether radiation will be zeroed\n!c below layer NCUT\n!c\n!c NCUT computational layer where absorption\n!c optical depth first exceeds ABSCUT\n!c\n!c NN NSTR / 2\n!c\n!c OPRIM delta-M-scaled single-scatter albedo\n!c\n!c TAUCPR delta-M-scaled optical depth\n!c\n!c UTAUPR delta-M-scaled version of UTAU\n!c\n!c Called by- DISORT\n!c Calls- QGAUSN, ERRMSG\n!c ---------------------------------------------------------------------\n\n!c .. Scalar Arguments ..\n\n LOGICAL, intent(in) :: CORINT, DELTAM, ONLYFL, PLANK, USRANG, USRTAU\n INTEGER, intent(in) :: IBCND, MAXMOM, MAXUMU, MXCMU, NLYR, NN, NSTR, &\n NTAU, NUMU\n REAL, intent(in) :: FBEAM, UMU0\n\t integer, intent(inout) :: NCUT\n\t logical, intent(inout) :: LYRCUT\n!c ..\n!c .. Array Arguments ..\n\n INTEGER, intent(inout):: LAYRU( * )\n REAL, intent(inout):: CMU( : ), DTAUC( * ), DTAUCP( * ), &\n EXPBEA( 0:* ), FLYR( * ), GL( 0:MXCMU, * ), OPRIM( * ), &\n PMOM( 0:MAXMOM, * ), SSALB( * ), TAUC( 0:* ), &\n TAUCPR( 0:* ), UMU( MAXUMU ), UTAU( * ), UTAUPR( * )\n!c ..\n!c .. Local Scalars ..\n\n INTEGER IQ, IU, K, LC, LU\n REAL ABSTAU, F, YESSCT\n\n!c ..\n real, parameter :: ABSCUT = 10. \n\n\n!c ** Apply delta-M scaling and move description\n!c ** of computational layers to local variables\n EXPBEA( 0 ) = 1.0\n TAUCPR( 0 ) = 0.0\n ABSTAU = 0.0\n YESSCT = 0.0\n\n DO 40 LC = 1, NLYR\n\n YESSCT = YESSCT + SSALB( LC )\n\n!c PMOM( 0, LC ) = 1.0\n\n IF( ABSTAU.LT.ABSCUT ) NCUT = LC\n\n ABSTAU = ABSTAU + ( 1. - SSALB( LC ) )*DTAUC( LC )\n\n\n F = PMOM( NSTR, LC )\n\t\t\n\t\t\tif (F == 0.) then \n\t\t\t\tOPRIM( LC ) = SSALB( LC )\n\t\t\t\tDTAUCP( LC ) = DTAUC( LC )\n\t\t\t\tTAUCPR( LC ) = TAUCPR( LC - 1 ) + DTAUC( LC )\n\n DO K = 0, NSTR - 1\n\t\t\t\t\tGL(K, LC) = 0.\n\t\t\t\t\tif (PMOM(K, LC) .ne. 0.) GL( K, LC ) = ( 2*K + 1 )*SSALB( LC )* PMOM( K,LC ) \n\t\t\t\tend do\n\n\t\t\telse \n\t\t\t\tOPRIM( LC ) = SSALB( LC )*( 1. - F ) / ( 1. - F*SSALB(LC) )\n\t\t\t\tDTAUCP( LC ) = ( 1. - F*SSALB( LC ) )*DTAUC( LC )\n\t\t\t\tTAUCPR( LC ) = TAUCPR( LC - 1 ) + DTAUCP( LC )\n\n\t\t\t\tDO 30 K = 0, NSTR - 1\n\t\t\t\t\tGL(K, LC) = 0.\n\t\t\t\t\tif (PMOM(K, LC) .ne. 0.) GL( K, LC ) = ( 2*K + 1 )*OPRIM( LC )* &\n ( PMOM( K,LC ) - F ) / ( 1. - F )\n 30\t\t\tCONTINUE\n\t\t\tendif\n\n\n FLYR( LC ) = F\n EXPBEA( LC ) = 0.0\n\n IF( FBEAM.GT.0.0 ) EXPBEA( LC ) = EXP( -TAUCPR( LC )/UMU0 )\n\n 40 CONTINUE\n!c ** If no thermal emission, cut off medium below\n!c ** absorption optical depth = ABSCUT ( note that\n!c ** delta-M transformation leaves absorption\n!c ** optical depth invariant ). Not worth the\n!c ** trouble for one-layer problems, though.\n LYRCUT = .FALSE.\n IF( ABSTAU.GE.ABSCUT .AND. .NOT.PLANK ) LYRCUT = .TRUE.\n IF( .NOT.LYRCUT ) NCUT = NLYR\n\n!c ** Set arrays defining location of user\n!c ** output levels within delta-M-scaled\n!c ** computational mesh\n DO 70 LU = 1, NTAU\n\n DO 50 LC = 1, NLYR\n\n IF( UTAU( LU ).GE.TAUC( LC-1 ) .AND. &\n UTAU( LU ).LE.TAUC( LC ) ) GO TO 60\n\n 50 CONTINUE\n LC = NLYR\n\n 60 CONTINUE\n UTAUPR( LU ) = TAUCPR( LC - 1 ) + &\n ( 1. - SSALB( LC )*FLYR( LC ) )* &\n ( UTAU( LU ) - TAUC( LC-1 ) )\n LAYRU( LU ) = LC\n\n 70 CONTINUE\n\n END SUBROUTINE SETDIS\n\n\n\n SUBROUTINE SETMTX( BDR, CBAND, CMU, CWT, DELM0, DTAUCP, GC, KK, &\n LAMBER, LYRCUT, MI, MI9M2, MXCMU, NCOL, NCUT, &\n NNLYRI, NN, NSTR, TAUCPR, WK )\n\n!c Calculate coefficient matrix for the set of equations\n!c obtained from the boundary conditions and the continuity-\n!c of-intensity-at-layer-interface equations; store in the\n!c special banded-matrix format required by LINPACK routines\n!c\n!c\n!c\n!c BAND STORAGE\n!c\n!c LINPACK requires band matrices to be input in a special\n!c form where the elements of each diagonal are moved up or\n!c down (in their column) so that each diagonal becomes a row.\n!c (The column locations of diagonal elements are unchanged.)\n!c\n!c Example: if the original matrix is\n!c\n!c 11 12 13 0 0 0\n!c 21 22 23 24 0 0\n!c 0 32 33 34 35 0\n!c 0 0 43 44 45 46\n!c 0 0 0 54 55 56\n!c 0 0 0 0 65 66\n!c\n!c then its LINPACK input form would be:\n!c\n!c * * * + + + , * = not used\n!c * * 13 24 35 46 , + = used for pivoting\n!c * 12 23 34 45 56\n!c 11 22 33 44 55 66\n!c 21 32 43 54 65 *\n!c\n!c If A is a band matrix, the following program segment\n!c will convert it to the form (ABD) required by LINPACK\n!c band-matrix routines:\n!c\n!c N = (column dimension of A, ABD)\n!c ML = (band width below the diagonal)\n!c MU = (band width above the diagonal)\n!c M = ML + MU + 1\n!c DO J = 1, N\n!c I1 = MAX(1, J-MU)\n!c I2 = MIN(N, J+ML)\n!c DO I = I1, I2\n!c K = I - J + M\n!c ABD(K,J) = A(I,J)\n!c END DO\n!c END DO\n!c\n!c This uses rows ML+1 through 2*ML+MU+1 of ABD.\n!c The total number of rows needed in ABD is 2*ML+MU+1 .\n!c In the example above, N = 6, ML = 1, MU = 2, and the\n!c row dimension of ABD must be >= 5.\n!c\n\n!c .. Scalar Arguments ..\n\n LOGICAL, intent(in) :: LAMBER, LYRCUT\n INTEGER, intent(in) :: MI, MI9M2, MXCMU, NCUT, NN, NNLYRI, NSTR\n\t integer, intent(inout) :: NCOL\n REAL, intent(in) :: DELM0\n!c ..\n!c .. Array Arguments ..\n\n REAL, intent(inout) :: BDR( MI, 0:MI ), CBAND( MI9M2, NNLYRI ), CMU( MXCMU ), &\n CWT( MXCMU ), DTAUCP( * ), GC( MXCMU, MXCMU, * ), &\n KK( MXCMU, * ), TAUCPR( 0:* ), WK( MXCMU )\n!c ..\n!c .. Local Scalars ..\n\n INTEGER IQ, IROW, JCOL, JQ, K, LC, LDA, NCD, NNCOL, NSHIFT\n REAL EXPA, SUM\n\n\n CBAND = 0.0\n\n NCD = 3*NN - 1\n LDA = 3*NCD + 1\n NSHIFT = LDA - 2*NSTR + 1\n NCOL = 0\n\t \n!c ** Use continuity conditions of Eq. STWJ(17)\n!c ** to form coefficient matrix in STWJ(20);\n!c ** employ scaling transformation STWJ(22)\n DO 60 LC = 1, NCUT\n\n DO 10 IQ = 1, NN\n WK( IQ ) = EXP( KK( IQ,LC )*DTAUCP( LC ) )\n 10 CONTINUE\n\n JCOL = 0\n\n DO 30 IQ = 1, NN\n\n NCOL = NCOL + 1\n IROW = NSHIFT - JCOL\n\n DO 20 JQ = 1, NSTR\n CBAND( IROW + NSTR, NCOL ) = GC( JQ, IQ, LC )\n CBAND( IROW, NCOL ) = - GC( JQ, IQ, LC )*WK( IQ )\n IROW = IROW + 1\n 20 CONTINUE\n\n JCOL = JCOL + 1\n\n 30 CONTINUE\n\n\n DO 50 IQ = NN + 1, NSTR\n\n NCOL = NCOL + 1\n IROW = NSHIFT - JCOL\n\n\n DO 40 JQ = 1, NSTR\n CBAND( IROW + NSTR, NCOL ) = GC( JQ, IQ, LC )* &\n WK( NSTR + 1 - IQ )\n CBAND( IROW, NCOL ) = - GC( JQ, IQ, LC )\n IROW = IROW + 1\n 40 CONTINUE\n\n JCOL = JCOL + 1\n\n 50 CONTINUE\n\n 60 CONTINUE\n!c ** Use top boundary condition of STWJ(20a) for\n!c ** first layer\n JCOL = 0\n\n DO 80 IQ = 1, NN\n\n EXPA = EXP( KK( IQ,1 )*TAUCPR( 1 ) )\n IROW = NSHIFT - JCOL + NN\n\n DO 70 JQ = NN, 1, -1\n CBAND( IROW, JCOL + 1 ) = GC( JQ, IQ, 1 )*EXPA\n IROW = IROW + 1\n 70 CONTINUE\n\n JCOL = JCOL + 1\n\n 80 CONTINUE\n\n\n DO 100 IQ = NN + 1, NSTR\n\n IROW = NSHIFT - JCOL + NN\n\n DO 90 JQ = NN, 1, -1\n CBAND( IROW, JCOL + 1 ) = GC( JQ, IQ, 1 )\n IROW = IROW + 1\n 90 CONTINUE\n\n JCOL = JCOL + 1\n\n 100 CONTINUE\n!c ** Use bottom boundary condition of\n!c ** STWJ(20c) for last layer\n\n NNCOL = NCOL - NSTR\n JCOL = 0\n\n DO 130 IQ = 1, NN\n\n NNCOL = NNCOL + 1\n IROW = NSHIFT - JCOL + NSTR\n\n DO 120 JQ = NN + 1, NSTR\n\n IF( LYRCUT .OR. ( LAMBER .AND. DELM0.EQ.0 ) ) THEN\n\n!c ** No azimuthal-dependent intensity if Lam-\n!c ** bert surface; no intensity component if\n!c ** truncated bottom layer\n\n CBAND( IROW, NNCOL ) = GC( JQ, IQ, NCUT )\n\n ELSE\n\n SUM = 0.0\n\n DO 110 K = 1, NN\n SUM = SUM + CWT( K )*CMU( K )*BDR( JQ - NN, K )* &\n GC( NN + 1 - K, IQ, NCUT )\n 110 CONTINUE\n\n CBAND( IROW, NNCOL ) = GC( JQ, IQ, NCUT ) - &\n ( 1.+ DELM0 )*SUM\n END IF\n\n IROW = IROW + 1\n\n 120 CONTINUE\n\n JCOL = JCOL + 1\n\n 130 CONTINUE\n\n\n DO 160 IQ = NN + 1, NSTR\n\n NNCOL = NNCOL + 1\n IROW = NSHIFT - JCOL + NSTR\n EXPA = WK( NSTR + 1 - IQ )\n\n DO 150 JQ = NN + 1, NSTR\n\n IF( LYRCUT .OR. ( LAMBER .AND. DELM0.EQ.0 ) ) THEN\n\n CBAND( IROW, NNCOL ) = GC( JQ, IQ, NCUT )*EXPA\n\n ELSE\n\n SUM = 0.0\n\n DO 140 K = 1, NN\n SUM = SUM + CWT( K )*CMU( K )*BDR( JQ - NN, K )* &\n GC( NN + 1 - K, IQ, NCUT )\n 140 CONTINUE\n\n CBAND( IROW, NNCOL ) = ( GC( JQ,IQ,NCUT ) - &\n ( 1.+ DELM0 )*SUM )*EXPA\n END IF\n\n IROW = IROW + 1\n\n 150 CONTINUE\n\n JCOL = JCOL + 1\n\n 160 CONTINUE\n\n END SUBROUTINE SETMTX\n\n\t\n\n SUBROUTINE SOLEIG( AMB, APB, ARRAY, CMU, CWT, GL, MI, MAZIM, &\n MXCMU, NN, NSTR, YLMC, CC, EVECC, EVAL, KK, GC, &\n AAD, EVECCD, EVALD, WKD )\n\n!c Solves eigenvalue/vector problem necessary to construct\n!c homogeneous part of discrete ordinate solution; STWJ(8b),\n!c STWL(23f)\n!c ** NOTE ** Eigenvalue problem is degenerate when single\n!c scattering albedo = 1; present way of doing it\n!c seems numerically more stable than alternative\n!c methods that we tried\n!c\n\n!c .. Scalar Arguments ..\n\n INTEGER, intent(in):: MAZIM, MI, MXCMU, NN, NSTR\n!c ..\n!c .. Array Arguments ..\n\n REAL, intent(inout) :: AMB( MI, MI ), APB( MI, MI ), ARRAY( MI, * ), &\n CC( MXCMU, MXCMU ), CMU( MXCMU ), CWT( MXCMU ), &\n EVAL( MI ), EVECC( MXCMU, MXCMU ), GC( MXCMU, MXCMU ), &\n GL( 0:MXCMU ), KK( MXCMU ), YLMC( 0:MXCMU, MXCMU )\n DOUBLE PRECISION, intent(inout) :: AAD( MI, MI ), EVALD( MI ), EVECCD( MI, MI ), &\n WKD( MXCMU )\n!c ..\n!c .. Local Scalars ..\n\n INTEGER IER, IQ, JQ, KQ, L\n REAL ALPHA, BETA, GPMIGM, GPPLGM, SUM\n\n!c ** Calculate quantities in Eqs. SS(5-6),\n!c ** STWL(8b,15,23f)\n DO 40 IQ = 1, NN\n\n DO 20 JQ = 1, NSTR\n\n SUM = 0.0\n DO 10 L = MAZIM, NSTR - 1\n SUM = SUM + GL( L )*YLMC( L, IQ )*YLMC( L, JQ )\n 10 CONTINUE\n\n CC( IQ, JQ ) = 0.5*SUM*CWT( JQ )\n\n 20 CONTINUE\n\n DO 30 JQ = 1, NN\n!c ** Fill remainder of array using symmetry\n!c ** relations C(-mui,muj) = C(mui,-muj)\n!c ** and C(-mui,-muj) = C(mui,muj)\n\n CC( IQ + NN, JQ ) = CC( IQ, JQ + NN )\n CC( IQ + NN, JQ + NN ) = CC( IQ, JQ )\n\n!c ** Get factors of coeff. matrix\n!c ** of reduced eigenvalue problem\n\n ALPHA = CC( IQ, JQ ) / CMU( IQ )\n BETA = CC( IQ, JQ + NN ) / CMU( IQ )\n AMB( IQ, JQ ) = ALPHA - BETA\n APB( IQ, JQ ) = ALPHA + BETA\n\n 30 CONTINUE\n\n AMB( IQ, IQ ) = AMB( IQ, IQ ) - 1.0 / CMU( IQ )\n APB( IQ, IQ ) = APB( IQ, IQ ) - 1.0 / CMU( IQ )\n\n 40 CONTINUE\n!c ** Finish calculation of coefficient matrix of\n!c ** reduced eigenvalue problem: get matrix\n!c ** product (alfa+beta)*(alfa-beta); SS(12),\n!c ** STWL(23f)\n DO 70 IQ = 1, NN\n\n DO 60 JQ = 1, NN\n\n SUM = 0.\n DO 50 KQ = 1, NN\n SUM = SUM + APB( IQ, KQ )*AMB( KQ, JQ )\n 50 CONTINUE\n\n ARRAY( IQ, JQ ) = SUM\n\n 60 CONTINUE\n\n 70 CONTINUE\n!c ** Find (real) eigenvalues and eigenvectors\n\n CALL ASYMTX( ARRAY, EVECC, EVAL, NN, MI, MXCMU, IER, WKD, AAD, &\n EVECCD, EVALD )\n\n\n DO 80 IQ = 1, NN\n EVAL( IQ ) = SQRT( ABS( EVAL( IQ ) ) )\n KK( IQ + NN ) = EVAL( IQ )\n!c ** Add negative eigenvalue\n KK( NN + 1 - IQ ) = -EVAL( IQ )\n 80 CONTINUE\n\n!c ** Find eigenvectors (G+) + (G-) from SS(10)\n!c ** and store temporarily in APB array\n DO 110 JQ = 1, NN\n\n DO 100 IQ = 1, NN\n\n SUM = 0.\n DO 90 KQ = 1, NN\n SUM = SUM + AMB( IQ, KQ )*EVECC( KQ, JQ )\n 90 CONTINUE\n\n APB( IQ, JQ ) = SUM / EVAL( JQ )\n\n 100 CONTINUE\n\n 110 CONTINUE\n\n\n DO 130 JQ = 1, NN\n\n DO 120 IQ = 1, NN\n\n GPPLGM = APB( IQ, JQ )\n GPMIGM = EVECC( IQ, JQ )\n!c ** Recover eigenvectors G+,G- from\n!c ** their sum and difference; stack them\n!c ** to get eigenvectors of full system\n!c ** SS(7) (JQ = eigenvector number)\n\n EVECC( IQ, JQ ) = 0.5*( GPPLGM + GPMIGM )\n EVECC( IQ + NN, JQ ) = 0.5*( GPPLGM - GPMIGM )\n\n!c ** Eigenvectors corresponding to\n!c ** negative eigenvalues (corresp. to\n!c ** reversing sign of 'k' in SS(10) )\n GPPLGM = - GPPLGM\n EVECC(IQ, JQ+NN) = 0.5 * ( GPPLGM + GPMIGM )\n EVECC(IQ+NN,JQ+NN) = 0.5 * ( GPPLGM - GPMIGM )\n GC( IQ+NN, JQ+NN ) = EVECC( IQ, JQ )\n GC( NN+1-IQ, JQ+NN ) = EVECC( IQ+NN, JQ )\n GC( IQ+NN, NN+1-JQ ) = EVECC( IQ, JQ+NN )\n GC( NN+1-IQ, NN+1-JQ ) = EVECC( IQ+NN, JQ+NN )\n\n 120 CONTINUE\n\n 130 CONTINUE\n\n END SUBROUTINE SOLEIG\n\n\t\n SUBROUTINE SOLVE0( B, BDR, BEM, BPLANK, CBAND, CMU, CWT, EXPBEA, &\n FBEAM, FISOT, IPVT, LAMBER, LL, LYRCUT, MAZIM, &\n MI, MI9M2, MXCMU, NCOL, NCUT, NN, NSTR, NNLYRI, &\n PI, TPLANK, TAUCPR, UMU0, Z, ZZ, ZPLK0, ZPLK1 )\n\n\n!c .. Scalar Arguments ..\n\n LOGICAL, intent(in) :: LAMBER, LYRCUT\n INTEGER, intent(in) :: MAZIM, MI, MI9M2, MXCMU, NCOL, NCUT, NN, NNLYRI, NSTR\n REAL, intent(in) :: BPLANK, FBEAM, FISOT, PI, TPLANK, UMU0\n!c ..\n!c .. Array Arguments ..\n\n INTEGER, intent(inout) :: IPVT( * )\n REAL, intent(inout) :: B( NNLYRI ), BDR( MI, 0:MI ), BEM( MI ), &\n CBAND( MI9M2, NNLYRI ), CMU( MXCMU ), CWT( MXCMU ), &\n EXPBEA( 0:* ), LL( MXCMU, * ), TAUCPR( 0:* ), &\n Z( NNLYRI ), ZPLK0( MXCMU, * ), ZPLK1( MXCMU, * ), &\n ZZ( MXCMU, * )\n!c ..\n!c .. Local Scalars ..\n\n INTEGER IPNT, IQ, IT, JQ, LC, NCD\n REAL RCOND, SUM\n!c ..\n!c .. External Subroutines ..\n\n EXTERNAL SGBCO, SGBSL\n\n\t\tB(1:NNLYRI) = 0.0\n \n!c ** Construct B, STWJ(20a,c) for\n!c ** parallel beam + bottom reflection +\n!c ** thermal emission at top and/or bottom\n\n IF( MAZIM.GT.0 .AND. FBEAM.GT.0.0 ) THEN\n\n!c ** Azimuth-dependent case\n!c ** (never called if FBEAM = 0)\n IF( LYRCUT .OR. LAMBER ) THEN\n\n!c ** No azimuthal-dependent intensity for Lambert surface;\n!c ** no intensity component for truncated bottom layer\n\n DO 10 IQ = 1, NN\n!c ** Top boundary\n B( IQ ) = -ZZ( NN + 1 - IQ, 1 )\n!c ** Bottom boundary\n\n B( NCOL - NN + IQ ) = -ZZ( IQ + NN, NCUT )*EXPBEA( NCUT )\n\n 10 CONTINUE\n\n\n ELSE\n\n DO 30 IQ = 1, NN\n\n B( IQ ) = -ZZ( NN + 1 - IQ, 1 )\n\n SUM = 0.\n DO 20 JQ = 1, NN\n SUM = SUM + CWT( JQ )*CMU( JQ )*BDR( IQ, JQ )* &\n ZZ( NN + 1 - JQ, NCUT )*EXPBEA( NCUT )\n 20 CONTINUE\n\n B( NCOL - NN + IQ ) = SUM\n IF( FBEAM.GT.0.0 ) B( NCOL - NN + IQ ) = SUM + &\n ( BDR( IQ,0 )*UMU0*FBEAM/PI - ZZ( IQ+NN,NCUT ) )* &\n EXPBEA( NCUT )\n\n 30 CONTINUE\n\n END IF\n!c ** Continuity condition for layer\n!c ** interfaces of Eq. STWJ(20b)\n IT = NN\n\n DO 50 LC = 1, NCUT - 1\n\n DO 40 IQ = 1, NSTR\n IT = IT + 1\n B( IT ) = ( ZZ( IQ,LC+1 ) - ZZ( IQ,LC ) )*EXPBEA( LC )\n 40 CONTINUE\n\n 50 CONTINUE\n\n\n ELSE\n!c ** Azimuth-independent case\n\n IF( FBEAM.EQ.0.0 ) THEN\n\n DO 60 IQ = 1, NN\n!c ** Top boundary\n\n B( IQ ) = -ZPLK0( NN + 1 - IQ, 1 ) + FISOT + TPLANK\n\n 60 CONTINUE\n\n\n IF( LYRCUT ) THEN\n!c ** No intensity component for truncated\n!c ** bottom layer\n DO 70 IQ = 1, NN\n!c ** Bottom boundary\n\n B( NCOL - NN + IQ ) = - ZPLK0( IQ + NN, NCUT ) - &\n ZPLK1( IQ + NN, NCUT ) * &\n TAUCPR( NCUT )\n 70 CONTINUE\n\n\n ELSE\n\n DO 90 IQ = 1, NN\n\n SUM = 0.\n DO 80 JQ = 1, NN\n SUM = SUM + CWT( JQ )*CMU( JQ )*BDR( IQ, JQ )* &\n ( ZPLK0( NN+1-JQ, NCUT ) + &\n ZPLK1( NN+1-JQ, NCUT ) *TAUCPR( NCUT ) )\n 80 CONTINUE\n\n B( NCOL - NN + IQ ) = 2.*SUM + BEM( IQ )*BPLANK - &\n ZPLK0( IQ + NN, NCUT ) - &\n ZPLK1( IQ + NN, NCUT ) * &\n TAUCPR( NCUT )\n 90 CONTINUE\n\n END IF ! if LYRCUT\n!c ** Continuity condition for layer\n!c ** interfaces, STWJ(20b)\n IT = NN\n DO 110 LC = 1, NCUT - 1\n\n DO 100 IQ = 1, NSTR\n IT = IT + 1\n B( IT ) = ZPLK0( IQ, LC + 1 ) - ZPLK0( IQ, LC ) + &\n ( ZPLK1( IQ, LC + 1 ) - ZPLK1( IQ, LC ) )* &\n TAUCPR( LC )\n 100 CONTINUE\n\n 110 CONTINUE\n\n\n ELSE ! if FBEAM is not 0.0\n\n\n DO 120 IQ = 1, NN\n B( IQ ) = -ZZ( NN + 1 - IQ, 1 ) - &\n ZPLK0( NN + 1 - IQ, 1 ) + FISOT + TPLANK\n 120 CONTINUE\n\n IF( LYRCUT ) THEN\n\n DO 130 IQ = 1, NN\n B( NCOL-NN+IQ ) = - ZZ(IQ+NN, NCUT) * EXPBEA(NCUT) &\n - ZPLK0(IQ+NN, NCUT) &\n - ZPLK1(IQ+NN, NCUT) * TAUCPR(NCUT)\n 130 CONTINUE\n\n\n ELSE\n\n DO 150 IQ = 1, NN\n\n SUM = 0.\n DO 140 JQ = 1, NN\n SUM = SUM + CWT(JQ) * CMU(JQ) * BDR(IQ,JQ) &\n * ( ZZ(NN+1-JQ, NCUT) * EXPBEA(NCUT) &\n + ZPLK0(NN+1-JQ, NCUT) &\n + ZPLK1(NN+1-JQ, NCUT) * TAUCPR(NCUT))\n 140 CONTINUE\n\n B(NCOL-NN+IQ) = 2.*SUM + ( BDR(IQ,0) * UMU0*FBEAM/PI &\n - ZZ(IQ+NN, NCUT) ) * EXPBEA(NCUT) &\n + BEM(IQ) * BPLANK &\n\t\t\t\t\t\t\t\t - ZPLK0(IQ+NN, NCUT) &\n - ZPLK1(IQ+NN, NCUT) * TAUCPR(NCUT)\n 150 CONTINUE\n\n END IF ! if LYRCUT\n\n\n IT = NN\n\n DO 170 LC = 1, NCUT - 1\n\n DO 160 IQ = 1, NSTR\n\n IT = IT + 1\n B(IT) = ( ZZ(IQ,LC+1) - ZZ(IQ,LC) ) * EXPBEA(LC) &\n + ZPLK0(IQ,LC+1) - ZPLK0(IQ,LC) + &\n ( ZPLK1(IQ,LC+1) - ZPLK1(IQ,LC) ) * TAUCPR(LC)\n 160 CONTINUE\n\n 170 CONTINUE\n\n END IF ! if FBEAM check\n \n END IF\n!c ** Find L-U (lower/upper triangular) decomposition\n!c ** of band matrix CBAND and test if it is nearly\n!c ** singular (note: CBAND is destroyed)\n!c ** (CBAND is in LINPACK packed format)\n RCOND = 0.0\n NCD = 3*NN - 1\n\n CALL SGBCO( CBAND, MI9M2, NCOL, NCD, NCD, IPVT, RCOND, Z )\n\n\n!c ** Solve linear system with coeff matrix CBAND\n!c ** and R.H. side(s) B after CBAND has been L-U\n!c ** decomposed. Solution is returned in B.\n\n CALL SGBSL( CBAND, MI9M2, NCOL, NCD, NCD, IPVT, B, 0 )\n\n!c ** Zero CBAND (it may contain 'foreign'\n!c ** elements upon returning from LINPACK);\n!c ** necessary to prevent errors\n\n CBAND = 0.0\n\n DO 190 LC = 1, NCUT\n\n IPNT = LC*NSTR - NN\n\n DO 180 IQ = 1, NN\n LL( NN + 1 - IQ, LC ) = B( IPNT + 1 - IQ )\n LL( IQ + NN, LC ) = B( IQ + IPNT )\n 180 CONTINUE\n\n 190 CONTINUE\n\n END SUBROUTINE SOLVE0\n\t\n\n SUBROUTINE SURFAC( ALBEDO, LAMBER, MI, MAZIM, &\n MXUMU, NN, BDR, EMU, BEM, RMU )\n\n!c Computes user's surface bidirectional properties, STWL(41)\n\n!c .. Parameters ..\n!c ..\n!c .. Scalar Arguments ..\n\n LOGICAL, intent(in) :: LAMBER\n INTEGER, intent(in) :: MAZIM, MI, MXUMU, NN\n REAL, intent(in) :: ALBEDO\n!c ..\n!c .. Array Arguments ..\n REAL, intent(inout) :: BDR( MI, 0:MI ), BEM( MI ), EMU( MXUMU ), &\n RMU( MXUMU, 0:MI )\n!c ..\n!c .. Local Scalars ..\n\n INTEGER IU\n \n!c We're only ever doing lambertian calculations here, so this subroutine has been \n!c summarily gutted. \n\n IF( LAMBER .AND. MAZIM.EQ.0 ) THEN !outer IF\n \n \t BEM(1:NN) \t = 1.0 - ALBEDO\n \t BDR(1:NN,0:NN) = ALBEDO\n\n\t\t IU = 1\n \n\t\t RMU(IU,0:NN) = ALBEDO\n\t\t EMU( IU ) = 1.0 - ALBEDO\n\t\t\t\t\n\n\n\t ELSE\n\t \n\t\t\tBDR = 0.0\n\t\t\tBEM=0.0\n\n\t\t\tEMU = 0.0\n\t\t\tRMU = 0.0\n\n\n END IF\n \n\n END SUBROUTINE SURFAC \n\n\n SUBROUTINE TERPEV( CWT, EVECC, GL, GU, MAZIM, MXCMU, MXUMU, NN, &\n NSTR, NUMU, WK, YLMC, YLMU )\n\n!c Interpolate eigenvectors to user angles; Eq SD(8)\n\n!c Called by- DISORT, ALBTRN\n!c --------------------------------------------------------------------+\n\n!c .. Scalar Arguments ..\n\n INTEGER MAZIM, MXCMU, MXUMU, NN, NSTR, NUMU\n!c ..\n!c .. Array Arguments ..\n\n REAL CWT( MXCMU ), EVECC( MXCMU, MXCMU ), GL( 0:MXCMU ), &\n GU( MXUMU, MXCMU ), WK( MXCMU ), YLMC( 0:MXCMU, MXCMU ), &\n YLMU( 0:MXCMU, MXUMU )\n!c ..\n!c .. Local Scalars ..\n\n INTEGER IQ, IU, JQ, L\n REAL SUM\n!c ..\n\n\n DO 50 IQ = 1, NSTR\n\n DO 20 L = MAZIM, NSTR - 1\n!c ** Inner sum in SD(8) times all\n!c ** factors in outer sum but PLM(mu)\n SUM = 0.0\n DO 10 JQ = 1, NSTR\n SUM = SUM + CWT( JQ )*YLMC( L, JQ )*EVECC( JQ, IQ )\n 10 CONTINUE\n\n WK( L + 1 ) = 0.5*GL( L )*SUM\n\n 20 CONTINUE\n!c ** Finish outer sum in SD(8)\n!c ** and store eigenvectors\n\t\t\tIU = 1\n!c DO 40 IU = 1, NUMU\n\t\t\t\n\n SUM = 0.\n DO 30 L = MAZIM, NSTR - 1\n SUM = SUM + WK( L + 1 )*YLMU( L, IU )\n 30 CONTINUE\n\n IF( IQ.LE.NN ) GU( IU, IQ + NN ) = SUM\n IF( IQ.GT.NN ) GU( IU, NSTR + 1 - IQ ) = SUM\n\n!c 40 CONTINUE\n\n 50 CONTINUE\n\n END SUBROUTINE TERPEV\n\n\n SUBROUTINE TERPSO( CWT, DELM0, FBEAM, GL, MAZIM, MXCMU, PLANK, &\n NUMU, NSTR, OPRIM, PI, YLM0, YLMC, YLMU, PSI0, &\n PSI1, XR0, XR1, Z0, Z1, ZJ, ZBEAM, Z0U, Z1U )\n\n!c Interpolates source functions to user angles, Eq. STWL(30)\n!c\n!c\n!c I N P U T V A R I A B L E S:\n!c\n!c CWT : Weights for Gauss quadrature over angle cosine\n!c\n!c DELM0 : Kronecker delta, delta-sub-m0\n!c\n!c GL : Delta-M scaled Legendre coefficients of phase function\n!c (including factors 2L+1 and single-scatter albedo)\n!c\n!c MAZIM : Order of azimuthal component\n!c\n!c OPRIM : Single scattering albedo\n!c\n!c XR0 : Expansion of thermal source function, Eq. STWL(24d)\n!c\n!c XR1 : Expansion of thermal source function Eq. STWL(24d)\n!c\n!c YLM0 : Normalized associated Legendre polynomial\n!c at the beam angle\n!c\n!c YLMC : Normalized associated Legendre polynomial\n!c at the quadrature angles\n!c\n!c YLMU : Normalized associated Legendre polynomial\n!c at the user angles\n!c\n!c Z0 : Solution vectors Z-sub-zero of Eq. SS(16), STWL(26a)\n!c\n!c Z1 : Solution vectors Z-sub-one of Eq. SS(16), STWL(26b)\n!c\n!c ZJ : Solution vector Z-sub-zero after solving Eq. SS(19),\n!c STWL(24b)\n!c\n!c (remainder are DISORT input variables)\n!c\n!c\n!c O U T P U T V A R I A B L E S:\n!c\n!c ZBEAM : Incident-beam source function at user angles\n!c\n!c Z0U,Z1U: Components of a linear-in-optical-depth-dependent\n!c source (approximating the Planck emission source)\n!c\n!c\n!c I N T E R N A L V A R I A B L E S:\n!c\n!c PSI0 : Sum just after square bracket in Eq. SD(9)\n!c PSI1 : Sum in Eq. STWL(31d)\n!c\n!c Called by- DISORT\n!c +-------------------------------------------------------------------+\n\n!c .. Scalar Arguments ..\n\n LOGICAL, intent(in):: PLANK\n INTEGER, intent(in):: MAZIM, MXCMU, NSTR, NUMU\n REAL , intent(in):: DELM0, FBEAM, OPRIM, PI, XR0, XR1\n!c ..\n!c .. Array Arguments ..\n\n REAL, intent(inout) :: CWT( MXCMU ), GL( 0:MXCMU ), PSI0( MXCMU ), &\n PSI1( MXCMU ), YLM0( 0:MXCMU ), YLMC( 0:MXCMU, MXCMU ), &\n YLMU( 0:MXCMU, * ), Z0( MXCMU ), Z0U( * ), Z1( MXCMU ), &\n Z1U( * ), ZBEAM( * ), ZJ( MXCMU )\n!c ..\n!c .. Local Scalars ..\n\n INTEGER IQ, IU, JQ\n REAL FACT, PSUM, PSUM0, PSUM1, SUM, SUM0, SUM1\n!c ..\n\n\n IF( FBEAM.GT.0.0 ) THEN\n!c ** Beam source terms; Eq. SD(9)\n\n DO 20 IQ = MAZIM, NSTR - 1\n\n PSUM = 0.\n DO 10 JQ = 1, NSTR\n PSUM = PSUM + CWT( JQ )*YLMC( IQ, JQ )*ZJ( JQ )\n 10 CONTINUE\n\n PSI0( IQ + 1 ) = 0.5*GL( IQ )*PSUM\n\n 20 CONTINUE\n\n FACT = ( 2. - DELM0 )*FBEAM / ( 4.0*PI )\n\n\t\t\tIU = 1\n!c DO 40 IU = 1, NUMU\n\n SUM = 0.\n DO 30 IQ = MAZIM, NSTR - 1\n SUM = SUM + YLMU( IQ, IU )* &\n ( PSI0( IQ+1 ) + FACT*GL( IQ )*YLM0( IQ ) )\n 30 CONTINUE\n\n ZBEAM( IU ) = SUM\n\n!c 40 CONTINUE\n\n END IF\n\n\n IF( PLANK .AND. MAZIM.EQ.0 ) THEN\n\n!c ** Thermal source terms, STWJ(27c), STWL(31c)\n!c\n\n DO 60 IQ = MAZIM, NSTR - 1\n\n PSUM0 = 0.0\n PSUM1 = 0.0\n DO 50 JQ = 1, NSTR\n PSUM0 = PSUM0 + CWT( JQ )*YLMC( IQ, JQ )*Z0( JQ )\n PSUM1 = PSUM1 + CWT( JQ )*YLMC( IQ, JQ )*Z1( JQ )\n 50 CONTINUE\n\n PSI0( IQ + 1 ) = 0.5*GL( IQ ) * PSUM0\n PSI1( IQ + 1 ) = 0.5*GL( IQ ) * PSUM1\n\n 60 CONTINUE\n\n\t\t\tIU = 1\n!c DO 80 IU = 1, NUMU\n\n SUM0 = 0.0\n SUM1 = 0.0\n DO 70 IQ = MAZIM, NSTR - 1\n SUM0 = SUM0 + YLMU( IQ, IU ) * PSI0( IQ + 1 )\n SUM1 = SUM1 + YLMU( IQ, IU ) * PSI1( IQ + 1 )\n 70 CONTINUE\n\n Z0U( IU ) = SUM0 + ( 1. - OPRIM ) * XR0\n Z1U( IU ) = SUM1 + ( 1. - OPRIM ) * XR1\n\n!c 80 CONTINUE\n\n END IF\n\n END SUBROUTINE TERPSO\n\n\n\n SUBROUTINE UPBEAM( ARRAY, CC, CMU, DELM0, FBEAM, GL, IPVT, MAZIM, &\n MXCMU, NN, NSTR, PI, UMU0, WK, YLM0, YLMC, ZJ, &\n ZZ )\n\n!c Finds the incident-beam particular solution of SS(18),\n!c STWL(24a)\n!c\n!c I N P U T V A R I A B L E S:\n!c\n!c CC : C-sub-ij in Eq. SS(5)\n!c\n!c CMU : Abscissae for Gauss quadrature over angle cosine\n!c\n!c DELM0 : Kronecker delta, delta-sub-m0\n!c\n!c GL : Delta-M scaled Legendre coefficients of phase function\n!c (including factors 2L+1 and single-scatter albedo)\n!c\n!c MAZIM : Order of azimuthal component\n!c\n!c YLM0 : Normalized associated Legendre polynomial\n!c at the beam angle\n!c\n!c YLMC : Normalized associated Legendre polynomial\n!c at the quadrature angles\n!c\n!c (remainder are DISORT input variables)\n!c\n!c\n!c O U T P U T V A R I A B L E S:\n!c\n!c ZJ : Right-hand side vector X-sub-zero in SS(19),STWL(24b);\n!c also the solution vector Z-sub-zero after solving\n!c that system\n!c\n!c ZZ : Permanent storage for ZJ, but re-ordered\n!c\n!c\n!c I N T E R N A L V A R I A B L E S:\n!c\n!c ARRAY : Coefficient matrix in left-hand side of Eq. SS(19),\n!c STWL(24b)\n!c IPVT : Integer vector of pivot indices required by LINPACK\n!c WK : Scratch array required by LINPACK\n!c\n!c Called by- DISORT\n!c Calls- SGECO, SGESL\n!c +-------------------------------------------------------------------+\n\n!c .. Scalar Arguments ..\n\n INTEGER, intent(in) :: MAZIM, MXCMU, NN, NSTR\n REAL, intent(in) :: DELM0, FBEAM, PI, UMU0\n!c ..\n!c .. Array Arguments ..\n\n INTEGER , intent(inout) :: IPVT( * )\n REAL, intent(inout) :: ARRAY( MXCMU, MXCMU ), CC( MXCMU, MXCMU ), CMU( MXCMU ), &\n GL( 0:MXCMU ), WK( MXCMU ), YLM0( 0:MXCMU ), &\n YLMC( 0:MXCMU, * ), ZJ( MXCMU ), ZZ( MXCMU )\n!c ..\n!c .. Local Scalars ..\n\n INTEGER IQ, JOB, JQ, K\n REAL RCOND, SUM\n!c ..\n!c .. External Subroutines ..\n\n EXTERNAL SGECO, SGESL\n!c ..\n\n\n DO 30 IQ = 1, NSTR\n\n DO 10 JQ = 1, NSTR\n ARRAY( IQ, JQ ) = -CC( IQ, JQ )\n 10 CONTINUE\n\n ARRAY( IQ, IQ ) = 1.+ CMU( IQ ) / UMU0 + ARRAY( IQ, IQ )\n\n SUM = 0.\n DO 20 K = MAZIM, NSTR - 1\n SUM = SUM + GL( K )*YLMC( K, IQ )*YLM0( K )\n 20 CONTINUE\n\n ZJ( IQ ) = ( 2.- DELM0 )*FBEAM*SUM / ( 4.*PI )\n 30 CONTINUE\n\n\n!c ** Find L-U (lower/upper triangular) decomposition\n!c ** of ARRAY and see if it is nearly singular\n!c ** (NOTE: ARRAY is altered)\n RCOND = 0.0\n\n CALL SGECO( ARRAY, MXCMU, NSTR, IPVT, RCOND, WK )\n\n\n!c ** Solve linear system with coeff matrix ARRAY\n!c ** (assumed already L-U decomposed) and R.H. side(s)\n!c ** ZJ; return solution(s) in ZJ\n JOB = 0\n\n CALL SGESL( ARRAY, MXCMU, NSTR, IPVT, ZJ, JOB )\n\n\n DO 40 IQ = 1, NN\n ZZ( IQ + NN ) = ZJ( IQ )\n ZZ( NN + 1 - IQ ) = ZJ( IQ + NN )\n 40 CONTINUE\n\n END SUBROUTINE UPBEAM\n\n\n SUBROUTINE UPISOT( ARRAY, CC, CMU, IPVT, MXCMU, NN, NSTR, OPRIM, &\n WK, XR0, XR1, Z0, Z1, ZPLK0, ZPLK1 )\n\n!c Finds the particular solution of thermal radiation of STWL(25)\n!c\n!c\n!c\n!c I N P U T V A R I A B L E S:\n!c\n!c CC : C-sub-ij in Eq. SS(5), STWL(8b)\n!c\n!c CMU : Abscissae for Gauss quadrature over angle cosine\n!c\n!c OPRIM : Delta-M scaled single scattering albedo\n!c\n!c XR0 : Expansion coefficient b-sub-zero of thermal source\n!c function, Eq. STWL(24c)\n!c\n!c XR1 : Expansion coefficient b-sub-one of thermal source\n!c function Eq. STWL(24c)\n!c\n!c (remainder are DISORT input variables)\n!c\n!c\n!c O U T P U T V A R I A B L E S:\n!c\n!c Z0 : Solution vectors Z-sub-zero of Eq. SS(16), STWL(26a)\n!c\n!c Z1 : Solution vectors Z-sub-one of Eq. SS(16), STWL(26b)\n!c\n!c ZPLK0, : Permanent storage for Z0,Z1, but re-ordered\n!c ZPLK1\n!c\n!c\n!c I N T E R N A L V A R I A B L E S:\n!c\n!c ARRAY : Coefficient matrix in left-hand side of EQ. SS(16)\n!c IPVT : Integer vector of pivot indices required by LINPACK\n!c WK : Scratch array required by LINPACK\n!c\n!c Called by- DISORT\n!c Calls- SGECO, ERRMSG, SGESL\n!c +-------------------------------------------------------------------+\n\n!c .. Scalar Arguments ..\n\n INTEGER MXCMU, NN, NSTR\n REAL OPRIM, XR0, XR1\n!c ..\n!c .. Array Arguments ..\n\n INTEGER IPVT( * )\n REAL ARRAY( MXCMU, MXCMU ), CC( MXCMU, MXCMU ), CMU( MXCMU ), &\n WK( MXCMU ), Z0( MXCMU ), Z1( MXCMU ), ZPLK0( MXCMU ), &\n ZPLK1( MXCMU )\n!c ..\n!c .. Local Scalars ..\n\n INTEGER IQ, JQ\n REAL RCOND\n!c ..\n!c .. External Subroutines ..\n\n EXTERNAL SGECO, SGESL\n!c ..\n\t \n DO 20 IQ = 1, NSTR\n\n DO 10 JQ = 1, NSTR\n ARRAY( IQ, JQ ) = -CC( IQ, JQ )\n 10 CONTINUE\n\n ARRAY( IQ, IQ ) = 1.0 + ARRAY( IQ, IQ )\n\n Z1( IQ ) = ( 1. - OPRIM ) * XR1\n\n 20 CONTINUE\n \n!c ** Solve linear equations: same as in UPBEAM,\n!c ** except ZJ replaced by Z1 and Z0\n RCOND = 0.0\n\n CALL SGECO( ARRAY, MXCMU, NSTR, IPVT, RCOND, WK )\n\n CALL SGESL( ARRAY, MXCMU, NSTR, IPVT, Z1, 0 )\n\n DO 30 IQ = 1, NSTR\n Z0( IQ ) = ( 1. - OPRIM ) * XR0 + CMU( IQ ) * Z1( IQ )\n 30 CONTINUE\n\n CALL SGESL( ARRAY, MXCMU, NSTR, IPVT, Z0, 0 )\n\n DO 40 IQ = 1, NN\n\t\t \n ZPLK0( IQ + NN ) = Z0( IQ )\n ZPLK1( IQ + NN ) = Z1( IQ )\n ZPLK0( NN + 1 - IQ ) = Z0( IQ + NN )\n ZPLK1( NN + 1 - IQ ) = Z1( IQ + NN )\n 40 CONTINUE\n\t\t\n END SUBROUTINE UPISOT\n\n\n\n SUBROUTINE USRINT( BPLANK, CMU, CWT, DELM0, DTAUCP, EMU, EXPBEA, &\n FBEAM, FISOT, GC, GU, KK, LAMBER, LAYRU, LL, &\n LYRCUT, MAZIM, MXCMU, MXULV, MXUMU, NCUT, NLYR, &\n NN, NSTR, PLANK, NUMU, NTAU, PI, RMU, TAUCPR, &\n TPLANK, UMU, UMU0, UTAUPR, WK, ZBEAM, Z0U, Z1U, &\n ZZ, ZPLK0, ZPLK1, UUM )\n\n!c Computes intensity components at user output angles\n!c for azimuthal expansion terms in Eq. SD(2), STWL(6)\n!c\n!c\n!c I N P U T V A R I A B L E S:\n!c\n!c BPLANK : Integrated Planck function for emission from\n!c bottom boundary\n!c\n!c CMU : Abscissae for Gauss quadrature over angle cosine\n!c\n!c CWT : Weights for Gauss quadrature over angle cosine\n!c\n!c DELM0 : Kronecker delta, delta-sub-M0\n!c\n!c EMU : Surface directional emissivity (user angles)\n!c\n!c EXPBEA : Transmission of incident beam, EXP(-TAUCPR/UMU0)\n!c\n!c GC : Eigenvectors at polar quadrature angles, SC(1)\n!c\n!c GU : Eigenvectors interpolated to user polar angles\n!c (i.e., G in Eq. SC(1) )\n!c\n!c KK : Eigenvalues of coeff. matrix in Eq. SS(7), STWL(23b)\n!c\n!c LAYRU : Layer number of user level UTAU\n!c\n!c LL : Constants of integration in Eq. SC(1), obtained\n!c by solving scaled version of Eq. SC(5);\n!c exponential term of Eq. SC(12) not included\n!c\n!c LYRCUT : Logical flag for truncation of computational layer\n!c\n!c MAZIM : Order of azimuthal component\n!c\n!c NCUT : Total number of computational layers considered\n!c\n!c NN : Order of double-Gauss quadrature (NSTR/2)\n!c\n!c RMU : Surface bidirectional reflectivity (user angles)\n!c\n!c TAUCPR : Cumulative optical depth (delta-M-Scaled)\n!c\n!c TPLANK : Integrated Planck function for emission from\n!c top boundary\n!c\n!c UTAUPR : Optical depths of user output levels in delta-M\n!c coordinates; equal to UTAU if no delta-M\n!c\n!c Z0U : Z-sub-zero in Eq. SS(16) interpolated to user\n!c angles from an equation derived from SS(16),\n!c Y-sub-zero on STWL(26b)\n!c\n!c Z1U : Z-sub-one in Eq. SS(16) interpolated to user\n!c angles from an equation derived from SS(16),\n!c Y-sub-one in STWL(26a)\n!c\n!c ZZ : Beam source vectors in Eq. SS(19), STWL(24b)\n!c\n!c ZPLK0 : Thermal source vectors Z0, by solving Eq. SS(16),\n!c Y-sub-zero in STWL(26)\n!c\n!c ZPLK1 : Thermal source vectors Z1, by solving Eq. SS(16),\n!c Y-sub-one in STWL(26)\n!c\n!c ZBEAM : Incident-beam source vectors\n!c\n!c (Remainder are DISORT input variables)\n!c\n!c\n!c O U T P U T V A R I A B L E S:\n!c\n!c UUM : Azimuthal components of the intensity in EQ. STWJ(5),\n!c STWL(6)\n!c\n!c\n!c I N T E R N A L V A R I A B L E S:\n!c\n!c BNDDIR : Direct intensity down at the bottom boundary\n!c BNDDFU : Diffuse intensity down at the bottom boundary\n!c BNDINT : Intensity attenuated at both boundaries, STWJ(25-6)\n!c DTAU : Optical depth of a computational layer\n!c LYREND : End layer of integration\n!c LYRSTR : Start layer of integration\n!c PALINT : Intensity component from parallel beam\n!c PLKINT : Intensity component from planck source\n!c WK : Scratch vector for saving EXP evaluations\n!c\n!c All the exponential factors ( EXP1, EXPN,... etc.)\n!c come from the substitution of constants of integration in\n!c Eq. SC(12) into Eqs. S1(8-9). They all have negative\n!c arguments so there should never be overflow problems.\n!c\n!c Called by- DISORT\n!c +-------------------------------------------------------------------+\n\n!c .. Scalar Arguments ..\n\n LOGICAL, intent(in) :: LAMBER, LYRCUT, PLANK\n INTEGER, intent(in) :: MAZIM, MXCMU, MXULV, MXUMU, NCUT, NLYR, NN, NSTR, NTAU, NUMU\n REAL, intent(in) :: BPLANK, DELM0, FBEAM, FISOT, PI, TPLANK, UMU0\n!c ..\n!c .. Array Arguments ..\n\n INTEGER, intent(inout) :: LAYRU( * )\n REAL, intent(inout) :: CMU( MXCMU ), CWT( MXCMU ), DTAUCP( * ), EMU( MXUMU ), &\n EXPBEA( 0:* ), GC( MXCMU, MXCMU, * ), &\n GU( MXUMU, MXCMU, * ), KK( MXCMU, * ), LL( MXCMU, * ), &\n RMU( MXUMU, 0:* ), TAUCPR( 0:* ), UMU( * ), &\n UTAUPR( MXULV ), UUM( MXUMU, MXULV ), WK( MXCMU ), &\n Z0U( MXUMU, * ), Z1U( MXUMU, * ), ZBEAM( MXUMU, * ), &\n ZPLK0( MXCMU, * ), ZPLK1( MXCMU, * ), ZZ( MXCMU, * )\n!c ..\n!c .. Local Scalars ..\n\n LOGICAL NEGUMU\n INTEGER IQ, IU, JQ, LC, LU, LYREND, LYRSTR, LYU\n REAL BNDDFU, BNDDIR, BNDINT, DENOM, DFUINT, DTAU, DTAU1, &\n DTAU2, EXP0, EXP1, EXP2, EXPN, F0N, F1N, FACT, PALINT, &\n PLKINT, SGN\n\n!c ** Incorporate constants of integration into\n!c ** interpolated eigenvectors\n\n\t EXP0 = 0.0\n\t EXP1=0.0\n\t EXP2=0.0\n DO 30 LC = 1, NCUT\n\n DO 20 IQ = 1, NSTR\n\n\t\t\tIU = 1\n GU( IU, IQ, LC ) = GU( IU, IQ, LC ) * LL( IQ, LC )\n\n 20 CONTINUE\n\n 30 CONTINUE\n!c ** Loop over levels at which intensities\n!c ** are desired ('user output levels')\n DO 160 LU = 1, NTAU\n\n IF( FBEAM.GT.0.0 ) EXP0 = EXP( -UTAUPR( LU ) / UMU0 )\n LYU = LAYRU( LU )\n!c ** Loop over polar angles at which\n!c ** intensities are desired\n\t\t\tIU = 1\n\n IF( LYRCUT .AND. LYU.GT.NCUT ) GO TO 150\n\n\n LYRSTR = LYU + 1\n LYREND = NCUT\n SGN = 1.0\n\n!c ** For downward intensity, integrate from top\n!c ** to LYU-1 in Eq. S1(8); for upward,\n!c ** integrate from bottom to LYU+1 in S1(9)\n PALINT = 0.0\n PLKINT = 0.0\n\n DO 60 LC = LYRSTR, LYREND\n\n DTAU = DTAUCP( LC )\n EXP1 = EXP( ( UTAUPR(LU) - TAUCPR(LC-1) ) / UMU( IU ) )\n EXP2 = EXP( ( UTAUPR(LU) - TAUCPR(LC) ) / UMU( IU ) )\n\n IF( PLANK .AND. MAZIM.EQ.0 ) THEN\n\n!c ** Eqs. STWL(36b,c, 37b,c)\n!c\n F0N = SGN * ( EXP1 - EXP2 )\n\n F1N = SGN * ( ( TAUCPR( LC-1 ) + UMU( IU ) ) * EXP1 - &\n ( TAUCPR( LC ) + UMU( IU ) ) * EXP2 )\n\n PLKINT = PLKINT + Z0U( IU,LC )*F0N + Z1U( IU,LC )*F1N\n\n END IF\n\n\n IF( FBEAM.GT.0.0 ) THEN\n\n DENOM = 1. + UMU( IU ) / UMU0\n\n IF( ABS( DENOM ).LT.0.0001 ) THEN\n!c ** L'Hospital limit\n EXPN = ( DTAU / UMU0 )*EXP0\n\n ELSE\n\n EXPN = ( EXP1*EXPBEA( LC-1 ) - &\n EXP2*EXPBEA( LC ) ) * SGN / DENOM\n\n END IF\n\n PALINT = PALINT + ZBEAM( IU, LC )*EXPN\n\n END IF\n\n!c ** KK is negative\n DO 40 IQ = 1, NN\n\n WK( IQ ) = EXP( KK( IQ,LC )*DTAU )\n DENOM = 1.0 + UMU( IU )*KK( IQ, LC )\n\n IF( ABS( DENOM ).LT.0.0001 ) THEN\n!c ** L'Hospital limit\n EXPN = DTAU / UMU( IU )*EXP2\n\n ELSE\n\n EXPN = SGN*( EXP1*WK( IQ ) - EXP2 ) / DENOM\n\n END IF\n\n PALINT = PALINT + GU( IU, IQ, LC )*EXPN\n\n 40 CONTINUE\n\n!c ** KK is positive\n DO 50 IQ = NN + 1, NSTR\n\n DENOM = 1.0 + UMU( IU )*KK( IQ, LC )\n\n IF( ABS( DENOM ).LT.0.0001 ) THEN\n!c ** L'Hospital limit\n EXPN = -DTAU / UMU( IU )*EXP1\n\n ELSE\n\n EXPN = SGN*( EXP1 - EXP2*WK( NSTR+1-IQ ) ) / DENOM\n\n END IF\n\n PALINT = PALINT + GU( IU, IQ, LC )*EXPN\n\n 50 CONTINUE\n\n\n 60 CONTINUE\n!c ** Calculate contribution from user\n!c ** output level to next computational level\n\n DTAU1 = UTAUPR( LU ) - TAUCPR( LYU - 1 )\n DTAU2 = UTAUPR( LU ) - TAUCPR( LYU )\n\n IF( ABS( DTAU2 ).LT.1.E-6 ) GO TO 90\n\n\t\t\tEXP2 = EXP( DTAU2/UMU( IU ) )\n\n IF( FBEAM.GT.0.0 ) THEN\n\n DENOM = 1. + UMU( IU ) / UMU0\n\n IF( ABS( DENOM ).LT.0.0001 ) THEN\n\n EXPN = ( DTAU1 / UMU0 )*EXP0\n\n ELSE\n\n EXPN = ( EXP0 - EXPBEA( LYU )*EXP2 ) / DENOM\n\n END IF\n\n PALINT = PALINT + ZBEAM( IU, LYU )*EXPN\n\n END IF\n\n!c ** KK is negative\n DTAU = DTAUCP( LYU )\n\n DO 70 IQ = 1, NN\n\n DENOM = 1. + UMU( IU )*KK( IQ, LYU )\n\n IF( ABS( DENOM ).LT.0.0001 ) THEN\n\n EXPN = -DTAU2 / UMU( IU )*EXP2\n\n ELSE\n\n EXPN = ( EXP( -KK( IQ,LYU ) * DTAU2 ) - EXP2 ) / DENOM\n\n END IF\n\n PALINT = PALINT + GU( IU, IQ, LYU )*EXPN\n\n 70 CONTINUE\n\n!c ** KK is positive\n DO 80 IQ = NN + 1, NSTR\n\n DENOM = 1. + UMU( IU )*KK( IQ, LYU )\n\n IF( ABS( DENOM ).LT.0.0001 ) THEN\n\n EXPN = -DTAU1 / UMU( IU )*EXP1\n\n ELSE\n\n EXPN = ( EXP( -KK( IQ,LYU ) * DTAU1 ) - &\n\t EXP( -KK( IQ,LYU ) * DTAU ) * EXP2 ) / DENOM\n\n END IF\n\n PALINT = PALINT + GU( IU, IQ, LYU )*EXPN\n\n 80 CONTINUE\n\n\n IF( PLANK .AND. MAZIM.EQ.0 ) THEN\n\n!c ** Eqs. STWL (35-37) with tau-sub-n-1\n!c ** replaced by tau for upward, and\n!c ** tau-sub-n replaced by tau for downward\n!c ** directions\n\n\n EXPN = EXP2\n FACT = TAUCPR( LYU ) + UMU( IU )\n\n\n F0N = 1. - EXPN\n F1N = UTAUPR( LU ) + UMU( IU ) - FACT * EXPN\n\n PLKINT = PLKINT + Z0U( IU, LYU )*F0N + Z1U( IU, LYU )*F1N\n\n END IF\n\n!c ** Calculate intensity components\n!c ** attenuated at both boundaries.\n!c ** NOTE: no azimuthal intensity\n!c ** component for isotropic surface\n 90 CONTINUE\n BNDINT = 0.0\n\n\n IF( LYRCUT .OR. ( LAMBER.AND.MAZIM.GT.0 ) ) GO TO 140\n\n DO 100 JQ = NN + 1, NSTR\n WK( JQ ) = EXP( -KK( JQ,NLYR )*DTAUCP( NLYR ) )\n 100 CONTINUE\n\n BNDDFU = 0.0\n\n DO 130 IQ = NN, 1, -1\n\n DFUINT = 0.0\n DO 110 JQ = 1, NN\n DFUINT = DFUINT + GC( IQ, JQ, NLYR )*LL( JQ, NLYR )\n 110 CONTINUE\n\n DO 120 JQ = NN + 1, NSTR\n DFUINT = DFUINT + GC( IQ, JQ, NLYR )* &\n LL( JQ, NLYR )*WK( JQ )\n 120 CONTINUE\n\n IF( FBEAM.GT.0.0 ) DFUINT = DFUINT + &\n ZZ( IQ, NLYR )*EXPBEA( NLYR )\n\n DFUINT = DFUINT + DELM0 * ( ZPLK0( IQ, NLYR ) + &\n ZPLK1( IQ,NLYR ) *TAUCPR( NLYR ) )\n BNDDFU = BNDDFU + ( 1.+DELM0 ) * RMU(IU,NN+1-IQ) &\n * CMU(NN+1-IQ) * CWT(NN+1-IQ)* DFUINT\n 130 CONTINUE\n\n BNDDIR = 0.0\n IF( FBEAM.GT.0.0 ) BNDDIR = UMU0*FBEAM / PI*RMU( IU, 0 )* &\n EXPBEA( NLYR )\n\n BNDINT = ( BNDDFU + BNDDIR + DELM0 * EMU(IU) * BPLANK ) &\n * EXP( (UTAUPR(LU)-TAUCPR(NLYR)) / UMU(IU) )\n\n\n 140 CONTINUE\n\n UUM( IU, LU ) = PALINT + PLKINT + BNDINT\n\n 150 CONTINUE\n\n 160 CONTINUE\n\n\n END SUBROUTINE USRINT\n\n\n\n\n!c ******************************************************************\n!c ********** DISORT service routines ************************\n!c ******************************************************************\n\n \n SUBROUTINE LEPOLY( NMU, M, MAXMU, TWONM1, MU, SQT, YLM )\n\n!c Computes the normalized associated Legendre polynomial,\n!c defined in terms of the associated Legendre polynomial\n!c Plm = P-sub-l-super-m as\n!c\n!c Ylm(MU) = sqrt( (l-m)!/(l+m)! ) * Plm(MU)\n!c\n!c for fixed order m and all degrees from l = m to TWONM1.\n!c When m.GT.0, assumes that Y-sub(m-1)-super(m-1) is available\n!c from a prior call to the routine.\n!c\n!c REFERENCE: Dave, J.V. and B.H. Armstrong, Computations of\n!c High-Order Associated Legendre Polynomials,\n!c J. Quant. Spectrosc. Radiat. Transfer 10,\n!c 557-562, 1970. (hereafter D/A)\n!c\n!c METHOD: Varying degree recurrence relationship.\n!c\n!c NOTES:\n!c (1) The D/A formulas are transformed by setting M=n-1; L=k-1.\n!c (2) Assumes that routine is called first with M = 0, then with\n!c M = 1, etc. up to M = TWONM1.\n!c\n!c\n!c I N P U T V A R I A B L E S:\n!c\n!c NMU : Number of arguments of YLM\n!c\n!c M : Order of YLM\n!c\n!c MAXMU : First dimension of YLM\n!c\n!c TWONM1 : Max degree of YLM\n!c\n!c MU(i) : Arguments of YLM (i = 1 to NMU)\n!c\n!c SQT(k) : Square root of k\n!c\n!c If M.GT.0, YLM(M-1,i) for i = 1 to NMU is assumed to exist\n!c from a prior call.\n!c\n!c\n!c O U T P U T V A R I A B L E:\n!c\n!c YLM(l,i) : l = M to TWONM1, normalized associated Legendre\n!c polynomials evaluated at argument MU(i)\n!c\n!c Called by- DISORT, ALBTRN\n!c +-------------------------------------------------------------------+\n\n!c .. Scalar Arguments ..\n\n INTEGER, intent(in) :: M, MAXMU, NMU, TWONM1\n!c ..\n!c .. Array Arguments ..\n\n REAL, intent(inout) :: MU( * ), YLM( 0:MAXMU, * ), SQT( * )\n!c ..\n!c .. Local Scalars ..\n\n INTEGER I, L\n REAL TMP1, TMP2\n!c ..\n\n IF( M.EQ.0 ) THEN\n!c ** Upward recurrence for ordinary\n!c ** Legendre polynomials\n DO 20 I = 1, NMU\n YLM( 0, I ) = 1.0\n YLM( 1, I ) = MU( I )\n 20 CONTINUE\n\n\n DO 40 L = 2, TWONM1\n\n DO 30 I = 1, NMU\n YLM( L, I ) = ( ( 2*L - 1 )*MU( I )*YLM( L-1, I ) - &\n ( L - 1 )*YLM( L-2, I ) ) / L\n 30 CONTINUE\n\n 40 CONTINUE\n\n\n ELSE\n\n DO 50 I = 1, NMU\n!c ** Y-sub-m-super-m; derived from\n!c ** D/A Eqs. (11,12), STWL(58c)\n\n YLM( M, I ) = - SQT( 2*M - 1 ) / SQT( 2*M )* &\n SQRT( 1.- MU(I)**2 )*YLM( M-1, I )\n\n!c ** Y-sub-(m+1)-super-m; derived from\n!c ** D/A Eqs.(13,14) using Eqs.(11,12),\n!c ** STWL(58f)\n\n YLM( M+1, I ) = SQT( 2*M + 1 )*MU( I )*YLM( M, I )\n\n 50 CONTINUE\n\n!c ** Upward recurrence; D/A EQ.(10),\n!c ** STWL(58a)\n DO 70 L = M + 2, TWONM1\n\n TMP1 = SQT( L - M )*SQT( L + M )\n TMP2 = SQT( L - M - 1 )*SQT( L + M - 1 )\n\n DO 60 I = 1, NMU\n YLM( L, I ) = ( ( 2*L - 1 )*MU( I )*YLM( L-1, I ) - &\n TMP2*YLM( L-2, I ) ) / TMP1\n 60 CONTINUE\n\n 70 CONTINUE\n\n END IF\n\n END subroutine LEPOLY\n\n\n\n REAL FUNCTION PLKAVG( WNUMLO, WNUMHI, T )\n\n!c Computes Planck function integrated between two wavenumbers\n!c\n!c INPUT : WNUMLO : Lower wavenumber (inv cm) of spectral interval\n!c\n!c WNUMHI : Upper wavenumber\n!c\n!c T : Temperature (K)\n!c\n!c OUTPUT : PLKAVG : Integrated Planck function ( Watts/sq m )\n!c = Integral (WNUMLO to WNUMHI) of\n!c 2h c**2 nu**3 / ( EXP(hc nu/kT) - 1)\n!c (where h=Plancks constant, c=speed of\n!c light, nu=wavenumber, T=temperature,\n!c and k = Boltzmann constant)\n!c\n!c Reference : Specifications of the Physical World: New Value\n!c of the Fundamental Constants, Dimensions/N.B.S.,\n!c Jan. 1974\n!c\n\n\t REAL, parameter :: C2 = 1.438786 , SIGMA = 5.67032E-8 , &\n\t\t\t\tVCP(7) = (/ 10.25, 5.7, 3.9, 2.9, 2.3, 1.9, 0.0 /)\n\t \n REAL, intent(in) :: T, WNUMHI, WNUMLO\n\n INTEGER I, MMAX, M \n REAL EX, EXM, MV\n\n\n REAL D( 2 ), V( 2 )\n\n V( 1 ) = C2*WNUMLO / T\n V( 2 ) = C2*WNUMHI / T\n\n! the code for close wavenumbers has been deleted because in our particular case they are never that close\n\n DO 60 I = 1, 2\n\n!c ** Use exponential series\n MMAX = 0\n!c ** Find upper limit of series\n 40 CONTINUE\n MMAX = MMAX + 1\n\n IF( V(I) .LT. VCP( MMAX ) ) GO TO 40\n\n EX = EXP( - V(I) )\n EXM = 1.0\n D( I ) = 0.0\n\n DO 50 M = 1, MMAX\n MV = M*V( I )\n EXM = EX*EXM\n D( I ) = D( I ) + EXM*( 6.+ MV*( 6.+ MV*( 3.+ MV ) ) ) / M**4\n 50 CONTINUE\n\n D( I ) = PLKAVG_CONC*D( I )\n\n\n 60 CONTINUE\n\n PLKAVG = PLKAVG_SIGDPI * T**4 * (D( 1 ) - D( 2 ))\n\n END function PLKAVG\n\n\n\n\n SUBROUTINE QGAUSN( M, GMU, GWT )\n\n!c Compute weights and abscissae for ordinary Gaussian quadrature\n!c on the interval (0,1); that is, such that\n\n!c sum(i=1 to M) ( GWT(i) f(GMU(i)) )\n\n!c is a good approximation to\n\n!c integral(0 to 1) ( f(x) dx )\n\n!c INPUT : M order of quadrature rule\n\n!c OUTPUT : GMU(I) array of abscissae (I = 1 TO M)\n!c GWT(I) array of weights (I = 1 TO M)\n\n!c REFERENCE: Davis, P.J. and P. Rabinowitz, Methods of Numerical\n!c Integration, Academic Press, New York, pp. 87, 1975\n\n!c METHOD: Compute the abscissae as roots of the Legendre\n!c polynomial P-sub-M using a cubically convergent\n!c refinement of Newton's method. Compute the\n!c weights from EQ. 2.7.3.8 of Davis/Rabinowitz. Note\n!c that Newton's method can very easily diverge; only a\n!c very good initial guess can guarantee convergence.\n!c The initial guess used here has never led to divergence\n!c even for M up to 1000.\n\n!c ACCURACY: relative error no better than TOL or computer\n!c precision (machine epsilon), whichever is larger\n\n!c INTERNAL VARIABLES:\n\n!c ITER : number of Newton Method iterations\n!c MAXIT : maximum allowed iterations of Newton Method\n!c PM2,PM1,P : 3 successive Legendre polynomials\n!c PPR : derivative of Legendre polynomial\n!c P2PRI : 2nd derivative of Legendre polynomial\n!c TOL : convergence criterion for Legendre poly root iteration\n!c X,XI : successive iterates in cubically-convergent version\n!c of Newtons Method (seeking roots of Legendre poly.)\n\n!c Called by- DREF, SETDIS, SURFAC\n!c Calls- D1MACH, ERRMSG\n!c +-------------------------------------------------------------------+\n\n!c .. Scalar Arguments ..\n\n INTEGER, intent(in) :: M\n REAL, intent(inout) :: GMU(:), GWT(:)\n\n\n INTEGER ITER, K, LIM, NN, NP1\n REAL CONA, T\n DOUBLE PRECISION EN, NNP1, P, P2PRI, PM1, PM2, PPR, PROD, &\n TMP, X, XI\n\t\tdouble precision :: tan_t, xang\n\n\t P=0.0d0\n\t \n\n EN = M\n NP1 = M + 1\n NNP1 = M*NP1\n CONA = FLOAT( M - 1 ) / ( 8*M**3 )\n\n LIM = M / 2\n\n DO K = 1, LIM\n!c ** Initial guess for k-th root\n!c ** of Legendre polynomial, from\n!c ** Davis/Rabinowitz (2.7.3.3a)\n T = ( 4*K - 1 )*PI / ( 4*M + 2 )\n\t\t\tif (t < approx_limit_tan) then \n\t\t\t\ttan_t = t\n\t\t\telse\n\t\t\t\ttan_t = TAN(T)\n\t\t\tendif\n\t\t\txang = T + CONA / tan_t\n\t\t\tif (xang < approx_limit) then \n\t\t\t\tx = 1. - xang*xang/2.\n\t\t\telse\n\t\t\t\tx = cos(xang)\n\t\t\tendif\n\t\t\t\n! X = COS( T + CONA / TAN( T ) )\n ITER = 0\n\n!c ** Upward recurrence for\n!c ** Legendre polynomials\n 10 CONTINUE\n ITER = ITER + 1\n PM2 = ONE\n PM1 = X\n\n DO 20 NN = 2, M\n P = ( ( 2*NN - 1 )*X*PM1 - ( NN - 1 )*PM2 ) / NN\n PM2 = PM1\n PM1 = P\n 20 CONTINUE\n!c ** Newton Method\n TMP = ONE / ( ONE - X**2 )\n PPR = EN*( PM2 - X*P )*TMP\n P2PRI = ( TWO*X*PPR - NNP1*P )*TMP\n XI = X - ( P / PPR )*( ONE + &\n ( P / PPR )*P2PRI / ( TWO*PPR ) )\n\n!c ** Check for convergence\n IF( ABS( XI - X ).GT.TOL ) THEN\n\n X = XI\n GO TO 10\n\n END IF\n\t\t \t\t \n!c ** Iteration finished--calculate weights,\n!c ** abscissae for (-1,1)\n GMU( K ) = -X\n GWT( K ) = TWO / ( TMP*( EN*PM2 )**2 )\n GMU( NP1 - K ) = -GMU( K )\n GWT( NP1 - K ) = GWT( K )\n\t end do\n!c ** Convert from (-1,1) to (0,1)\n DO K = 1, M\n GMU( K ) = 0.5*GMU( K ) + 0.5\n GWT( K ) = 0.5*GWT( K )\n\t end do\n\n END subroutine QGAUSN\n\n\n REAL FUNCTION RATIO( A, B )\n\n!c Calculate ratio A/B with over- and under-flow protection\n!c (thanks to Prof. Jeff Dozier for some suggestions here).\n!c Since this routine takes two logs, it is no speed demon,\n!!c but it is invaluable for comparing results from two runs\n!c of a program under development.\n!c\n!c NOTE: In Fortran90, built-in functions TINY and HUGE\n!c can replace the R1MACH calls.\n!c\n!c Called by- DISORT\n!c Calls- R1MACH\n!c +-------------------------------------------------------------------+\n\n REAL, intent(in) :: A, B\n REAL :: ABSA, ABSB\n\n\n IF( A == 0.0 ) THEN\n IF( B == 0.0 ) THEN\n RATIO = 1.0\n ELSE\n RATIO = 0.0\n END IF\n ELSE IF( B == 0.0 ) THEN\n RATIO = SIGN( HUGE, A )\n ELSE\n ABSA = ABS( A )\n ABSB = ABS( B )\n!c the chances of over/underflow like described here in our \n!c particular problem are pretty much zero. So...\n IF( ABSA < TINY .AND. ABSB < TINY ) THEN\n RATIO = 1.0\n ELSE\n RATIO = ABSA / ABSB\n END IF\n!c ** DONT use old trick of determining sign\n!c ** from A*B because A*B may (over/under)flow\n IF( ( A > 0.0 .AND. B < 0.0 ) .OR. &\n ( A < 0.0 .AND. B > 0.0 ) ) RATIO = -RATIO\n\n END IF\n END function ratio\n\n\n\n\nend module DISORT_solver\n", "meta": {"hexsha": "dc51f0ef76acfae205998f06f2d73addb7104683", "size": 104514, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/Components/MCARS/DISORT_setup_app/DISORT_solver.f90", "max_stars_repo_name": "GEOS-ESM/AeroApps", "max_stars_repo_head_hexsha": "874dad6f34420c014d98eccbe81a061bdc0110cf", "max_stars_repo_licenses": ["NASA-1.3", "ECL-2.0", "Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-12-02T14:23:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-31T15:39:30.000Z", "max_issues_repo_path": "src/Components/MCARS/DISORT_setup_app/DISORT_solver.f90", "max_issues_repo_name": "GEOS-ESM/AeroApps", "max_issues_repo_head_hexsha": "874dad6f34420c014d98eccbe81a061bdc0110cf", "max_issues_repo_licenses": ["NASA-1.3", "ECL-2.0", "Apache-2.0"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2020-04-15T16:22:14.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-24T13:59:25.000Z", "max_forks_repo_path": "src/Components/MCARS/DISORT_setup_app/DISORT_solver.f90", "max_forks_repo_name": "GEOS-ESM/AeroApps", "max_forks_repo_head_hexsha": "874dad6f34420c014d98eccbe81a061bdc0110cf", "max_forks_repo_licenses": ["NASA-1.3", "ECL-2.0", "Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.8100399315, "max_line_length": 112, "alphanum_fraction": 0.4433664389, "num_tokens": 34218, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009457116781, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.6771862290647629}} {"text": "SUBROUTINE comsub(bk,loads)\n! performs the complete gaussian backsubstitution : complex version\nIMPLICIT NONE\n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15) \nCOMPLEX(iwp),INTENT(IN)::bk(:);COMPLEX(iwp),INTENT(IN OUT)::loads(0:)\nINTEGER::nkb,k,i,jn,jj,i1,n,iw; COMPLEX::sum\nn = UBOUND(loads,1); iw = UBOUND(bk,1)/n - 1\nloads(1)=loads(1)/bk(1)\n DO i=2,n\n sum=loads(i);i1=i-1 ; nkb=i-iw\n IF(nkb<=0)nkb=1\n DO k=nkb,i1\n jn=(i-k)*n+k;sum=sum-bk(jn)*loads(k)\n END DO\n loads(i)=sum/bk(i)\n END DO\n DO jj=2,n\n i=n-jj+1;sum=.0;i1=i+1;nkb=i+iw\n if(nkb-n>0)nkb=n\n DO k=i1,nkb\n jn=(k-i)*n+i ; sum=sum+bk(jn)*loads(k)\n END DO\n loads(i)=loads(i)-sum/bk(i)\n END DO\nRETURN\nEND SUBROUTINE comsub\n", "meta": {"hexsha": "404652793a9bfb599b34aca558322a0cc65bed82", "size": 756, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "main/comsub.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/comsub.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/comsub.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.0, "max_line_length": 69, "alphanum_fraction": 0.6018518519, "num_tokens": 304, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009526726545, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6771862289733703}} {"text": "! =========================================================\nsubroutine rp1(maxmx,meqn,mwaves,maux,mbc,mx,ql,qr,auxl,auxr,wave,s,amdq,apdq)\n! =========================================================\n\n! solve Riemann problem for the 1D shallow water equations using the HLLE\n! approximate Riemann solver.\n\n! waves: 2\n! equations: 2\n\n! Conserved quantities:\n! 1 depth (h)\n! 2 momentum (hu)\n\n implicit none\n\n integer, intent(in) :: maxmx, meqn, mwaves, mbc, mx, maux\n double precision, dimension(meqn,1-mbc:maxmx+mbc), intent(in) :: ql, qr\n double precision, dimension(maux,1-mbc:maxmx+mbc), intent(in) :: auxl, auxr\n double precision, dimension(meqn, mwaves, 1-mbc:maxmx+mbc), intent(out) :: wave\n double precision, dimension(meqn, 1-mbc:maxmx+mbc), intent(out) :: amdq, apdq\n double precision, dimension(mwaves, 1-mbc:maxmx+mbc), intent(out) :: s\n\n double precision :: u_l, u_r, h_l, h_r, c_l, c_r\n double precision :: hsqrt_l, hsqrt_r, u_hat, h_hat, c_hat, grav\n double precision :: h_m, hu_m\n double precision :: rho_m, rhou_m, E_m, s1, s2\n integer :: m, i, mw\n\n common /cparam/ grav\n\n do i=2-mbc,mx+mbc\n h_l = qr(1,i-1)\n h_r = ql(1,i)\n u_l = qr(2,i-1) / qr(1,i-1)\n u_r = ql(2,i ) / ql(1,i )\n c_l = dsqrt(grav*h_l)\n c_r = dsqrt(grav*h_r)\n \n if (h_l<1.e-14 .AND. h_r<1.e-14) then\n wave(1,1,i) =0.\n wave(2,1,i) =0.\n s(1,i) = 0.\n \n wave(1,2,i) = 0.\n wave(2,2,i) = 0.\n s(2,i) = 0.\n \n else\n ! Roe averages\n hsqrt_l = dsqrt(qr(1,i-1))\n hsqrt_r = dsqrt(ql(1,i))\n h_hat = 0.5*(h_l + h_r)\n u_hat = (hsqrt_l*u_l + hsqrt_r*u_r) / (hsqrt_l + hsqrt_r)\n c_hat = dsqrt(grav*h_hat)\n\n s1 = min(u_l - c_l, u_hat - c_hat)\n s2 = max(u_r + c_r, u_hat + c_hat)\n\n ! Middle state\n h_m = (ql(2,i) - qr(2,i-1) - s2*h_r + s1*h_l) / (s1-s2)\n hu_m = (ql(2,i)*(u_r-s2) - qr(2,i-1)*(u_l-s1) + 0.5*grav*(h_r**2-h_l**2)) / (s1-s2)\n \n wave(1,1,i) = h_m - h_l\n wave(2,1,i) = hu_m - qr(2,i-1)\n s(1,i) = s1\n \n wave(1,2,i) = h_r - h_m\n wave(2,2,i) = ql(2,i) - hu_m\n s(2,i) = s2\n end if\n\n end do \n\n do m=1, meqn\n do i=2-mbc, mx+mbc\n amdq(m,i) = 0.d0\n apdq(m,i) = 0.d0\n do mw=1, mwaves\n if (s(mw,i) < 0.d0) then\n amdq(m,i) = amdq(m,i) + s(mw,i)*wave(m,mw,i)\n else\n apdq(m,i) = apdq(m,i) + s(mw,i)*wave(m,mw,i)\n endif\n end do\n end do\n end do\n\nend subroutine rp1\n", "meta": {"hexsha": "60cb7107d8c0f57356886c563741dbf353153fce", "size": 2787, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/rp1_shallow_hlle.f90", "max_stars_repo_name": "donnaaboise/riemann", "max_stars_repo_head_hexsha": "d177660f5e7ac7a966958708780717918d91aff6", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 27, "max_stars_repo_stars_event_min_datetime": "2015-03-08T03:42:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-21T01:46:12.000Z", "max_issues_repo_path": "src/rp1_shallow_hlle.f90", "max_issues_repo_name": "donnaaboise/riemann", "max_issues_repo_head_hexsha": "d177660f5e7ac7a966958708780717918d91aff6", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 47, "max_issues_repo_issues_event_min_datetime": "2015-02-11T15:39:22.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-25T01:56:46.000Z", "max_forks_repo_path": "src/rp1_shallow_hlle.f90", "max_forks_repo_name": "donnaaboise/riemann", "max_forks_repo_head_hexsha": "d177660f5e7ac7a966958708780717918d91aff6", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 37, "max_forks_repo_forks_event_min_datetime": "2015-01-09T21:44:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-21T12:53:04.000Z", "avg_line_length": 30.9666666667, "max_line_length": 95, "alphanum_fraction": 0.4660925727, "num_tokens": 997, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037282594921, "lm_q2_score": 0.7310585903489892, "lm_q1q2_score": 0.6771822978163975}} {"text": "C\tWRITTEN BY: THEODORE E. FESSLER, NASA TM X-3572, AUGUST 1977\nC\tREWRITTEN BY: LT. MARK D. KLEM & MARGARET P. PROCTOR, JANUARY 1986\nC\nC\tTHE ORIGINAL PROGRAM WAS WRITTEN IN SFTRAN, BUT THIS PROGRAM IS\nC\tREWRITTEN IN STANDARD FORTRAN 77 TO RUN PRIMARILY ON PERSONAL\nC\tCOMPUTERS AND CAN ALSO RUN ON MAINFRAMES. MUCH OF THE OLD CODE WAS\nC\tCOMMENTED OUT BUT LEFT INTACT FOR DOCUMENTATION AND REFERENCE\nC\tPURPOSES.\nC\n SUBROUTINE CUBIC (T,P,ROOTS,NROOTS) \nC.....SOLVES FOR DENSITY IN REDUCED VAN DER WAALS GAS: \n \nC D**3 -3*D**2 +((8*T+P)/3)*D -P = 0 \n \nC IF MORE THAN ONE DISTINCT ROOT EXISTS, ONLY THE MINIMUM AND \nC MAXIMUM ONES ARE RETURNED AND NROOTS=2. \n \n IMPLICIT REAL*8 (A-H,O-Z) \n REAL*8 K1,K2 \n REAL*4 T,P,ROOTS(2) \n DATA K1,K2,THIRD / 2.094395102393195D+0, 4.188790204786391D+0, \n * 3.333333333333333D-1 / \n \nC.....FUNCTION DEFINITION. \n QRT(ARG)=DSIGN(DABS(ARG)**THIRD,ARG) \n \nC.....MAIN PROGRAM FLOW. \nC PROCEDURE (REDUCE TO NORMAL FORM)\n Q=(8.0D0*T+P)/3.0D0 \n A=Q/3.0D0-1.0D0 \n A3=A*A*A \n B=(Q-P)/2.0D0-1.0D0 \n B2=B*B \n RAD=A3+B2 \n IF (RAD.LT.0.0D0) THEN\nC PROCEDURE (CASE FOR 3 DISTINCT REAL ROOTS)\n PHI=DACOS(DSIGN(DSQRT(-B2/A3),-B))/3.0D0\n CR=2.0D0*DSQRT(-A)\n R1=CR*DCOS(PHI)\n R2=CR*DCOS(PHI+K1)\n R3=CR*DCOS(PHI+K2)\n ROOTS(1)=DMIN1(R1,R2,R3)+1.0D0\n ROOTS(2)=DMAX1(R1,R2,R3)+1.0D0\n NROOTS=2\n ELSE\n IF (RAD.EQ.0.0D0) THEN\n IF (B.EQ.0.0D0) THEN\nC PROCEDURE (CASE FOR ONLY ONE REAL ROOT)\n IF (RAD.NE.0.0D0) RAD=DSQRT(RAD)\n AA=-B+RAD\n BB=-B-RAD\n IF (AA.NE.0.0D0) AA=QRT(AA)\n IF (BB.NE.0.0D0) BB=QRT(BB)\n ROOTS(1)=AA+BB+1.0D0\n NROOTS=1\n ELSE\nC PROCEDURE (CASE FOR 3 REAL ROOTS BUT TWO ARE EQUAL)\n R1=QRT(B)\n R2=-2.0D0*R1\n ROOTS(1)=DMIN1(R1,R2)+1.0D0\n ROOTS(2)=DMAX1(R1,R2)+1.0D0\n NROOTS=2\n ENDIF\n ELSE\nC PROCEDURE (CASE FOR ONLY ONE REAL ROOT)\n IF (RAD.NE.0.0D0) RAD=DSQRT(RAD)\n AA=-B+RAD\n BB=-B-RAD\n IF (AA.NE.0.0D0) AA=QRT(AA)\n IF (BB.NE.0.0D0) BB=QRT(BB)\n ROOTS(1)=AA+BB+1.0D0\n NROOTS=1\n ENDIF\n ENDIF\n END \n\u001a", "meta": {"hexsha": "5898a168dc9c72adaa4bade86f1c31e50e39d8ab", "size": 3571, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "lew-14418/cubic.for", "max_stars_repo_name": "SteveDoyle2/nasa-cosmic", "max_stars_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_stars_repo_licenses": ["BSD-Source-Code"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2015-03-14T07:26:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-16T12:23:17.000Z", "max_issues_repo_path": "lew-14418/cubic.for", "max_issues_repo_name": "SteveDoyle2/nasa-cosmic", "max_issues_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_issues_repo_licenses": ["BSD-Source-Code"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lew-14418/cubic.for", "max_forks_repo_name": "SteveDoyle2/nasa-cosmic", "max_forks_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_forks_repo_licenses": ["BSD-Source-Code"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2016-02-12T22:18:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-08T17:46:54.000Z", "avg_line_length": 46.9868421053, "max_line_length": 72, "alphanum_fraction": 0.3648837861, "num_tokens": 983, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037343628703, "lm_q2_score": 0.731058584489497, "lm_q1q2_score": 0.677182296850655}} {"text": "*> \\brief SSYSV computes the solution to system of linear equations A * X = B for SY matrices\n*\n* =========== DOCUMENTATION ===========\n*\n* Online html documentation available at\n* http://www.netlib.org/lapack/explore-html/\n*\n*> \\htmlonly\n*> Download SSYSV + dependencies\n*> \n*> [TGZ]\n*> \n*> [ZIP]\n*> \n*> [TXT]\n*> \\endhtmlonly\n*\n* Definition:\n* ===========\n*\n* SUBROUTINE SSYSV( UPLO, N, NRHS, A, LDA, IPIV, B, LDB, WORK,\n* LWORK, INFO )\n*\n* .. Scalar Arguments ..\n* CHARACTER UPLO\n* INTEGER INFO, LDA, LDB, LWORK, N, NRHS\n* ..\n* .. Array Arguments ..\n* INTEGER IPIV( * )\n* REAL A( LDA, * ), B( LDB, * ), WORK( * )\n* ..\n*\n*\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*>\n*> SSYSV computes the solution to a real system of linear equations\n*> A * X = B,\n*> where A is an N-by-N symmetric matrix and X and B are N-by-NRHS\n*> matrices.\n*>\n*> The diagonal pivoting method is used to factor A as\n*> A = U * D * U**T, if UPLO = 'U', or\n*> A = L * D * L**T, if UPLO = 'L',\n*> where U (or L) is a product of permutation and unit upper (lower)\n*> triangular matrices, and D is symmetric and block diagonal with\n*> 1-by-1 and 2-by-2 diagonal blocks. The factored form of A is then\n*> used to solve the system of equations A * X = B.\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in] UPLO\n*> \\verbatim\n*> UPLO is CHARACTER*1\n*> = 'U': Upper triangle of A is stored;\n*> = 'L': Lower triangle of A is stored.\n*> \\endverbatim\n*>\n*> \\param[in] N\n*> \\verbatim\n*> N is INTEGER\n*> The number of linear equations, i.e., the order of the\n*> matrix A. N >= 0.\n*> \\endverbatim\n*>\n*> \\param[in] NRHS\n*> \\verbatim\n*> NRHS is INTEGER\n*> The number of right hand sides, i.e., the number of columns\n*> of the matrix B. NRHS >= 0.\n*> \\endverbatim\n*>\n*> \\param[in,out] A\n*> \\verbatim\n*> A is REAL array, dimension (LDA,N)\n*> On entry, the symmetric matrix A. If UPLO = 'U', the leading\n*> N-by-N upper triangular part of A contains the upper\n*> triangular part of the matrix A, and the strictly lower\n*> triangular part of A is not referenced. If UPLO = 'L', the\n*> leading N-by-N lower triangular part of A contains the lower\n*> triangular part of the matrix A, and the strictly upper\n*> triangular part of A is not referenced.\n*>\n*> On exit, if INFO = 0, the block diagonal matrix D and the\n*> multipliers used to obtain the factor U or L from the\n*> factorization A = U*D*U**T or A = L*D*L**T as computed by\n*> SSYTRF.\n*> \\endverbatim\n*>\n*> \\param[in] LDA\n*> \\verbatim\n*> LDA is INTEGER\n*> The leading dimension of the array A. LDA >= max(1,N).\n*> \\endverbatim\n*>\n*> \\param[out] IPIV\n*> \\verbatim\n*> IPIV is INTEGER array, dimension (N)\n*> Details of the interchanges and the block structure of D, as\n*> determined by SSYTRF. If IPIV(k) > 0, then rows and columns\n*> k and IPIV(k) were interchanged, and D(k,k) is a 1-by-1\n*> diagonal block. If UPLO = 'U' and IPIV(k) = IPIV(k-1) < 0,\n*> then rows and columns k-1 and -IPIV(k) were interchanged and\n*> D(k-1:k,k-1:k) is a 2-by-2 diagonal block. If UPLO = 'L' and\n*> IPIV(k) = IPIV(k+1) < 0, then rows and columns k+1 and\n*> -IPIV(k) were interchanged and D(k:k+1,k:k+1) is a 2-by-2\n*> diagonal block.\n*> \\endverbatim\n*>\n*> \\param[in,out] B\n*> \\verbatim\n*> B is REAL array, dimension (LDB,NRHS)\n*> On entry, the N-by-NRHS right hand side matrix B.\n*> On exit, if INFO = 0, the N-by-NRHS solution matrix X.\n*> \\endverbatim\n*>\n*> \\param[in] LDB\n*> \\verbatim\n*> LDB is INTEGER\n*> The leading dimension of the array B. LDB >= max(1,N).\n*> \\endverbatim\n*>\n*> \\param[out] WORK\n*> \\verbatim\n*> WORK is REAL array, dimension (MAX(1,LWORK))\n*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.\n*> \\endverbatim\n*>\n*> \\param[in] LWORK\n*> \\verbatim\n*> LWORK is INTEGER\n*> The length of WORK. LWORK >= 1, and for best performance\n*> LWORK >= max(1,N*NB), where NB is the optimal blocksize for\n*> SSYTRF.\n*> for LWORK < N, TRS will be done with Level BLAS 2\n*> for LWORK >= N, TRS will be done with Level BLAS 3\n*>\n*> If LWORK = -1, then a workspace query is assumed; the routine\n*> only calculates the optimal size of the WORK array, returns\n*> this value as the first entry of the WORK array, and no error\n*> message related to LWORK is issued by XERBLA.\n*> \\endverbatim\n*>\n*> \\param[out] INFO\n*> \\verbatim\n*> INFO is INTEGER\n*> = 0: successful exit\n*> < 0: if INFO = -i, the i-th argument had an illegal value\n*> > 0: if INFO = i, D(i,i) is exactly zero. The factorization\n*> has been completed, but the block diagonal matrix D is\n*> exactly singular, so the solution could not be computed.\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee\n*> \\author Univ. of California Berkeley\n*> \\author Univ. of Colorado Denver\n*> \\author NAG Ltd.\n*\n*> \\ingroup realSYsolve\n*\n* =====================================================================\n SUBROUTINE SSYSV( UPLO, N, NRHS, A, LDA, IPIV, B, LDB, WORK,\n $ LWORK, INFO )\n*\n* -- LAPACK driver routine --\n* -- LAPACK is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n*\n* .. Scalar Arguments ..\n CHARACTER UPLO\n INTEGER INFO, LDA, LDB, LWORK, N, NRHS\n* ..\n* .. Array Arguments ..\n INTEGER IPIV( * )\n REAL A( LDA, * ), B( LDB, * ), WORK( * )\n* ..\n*\n* =====================================================================\n*\n* .. Local Scalars ..\n LOGICAL LQUERY\n INTEGER LWKOPT\n* ..\n* .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\n* ..\n* .. External Subroutines ..\n EXTERNAL XERBLA, SSYTRF, SSYTRS, SSYTRS2\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC MAX\n* ..\n* .. Executable Statements ..\n*\n* Test the input parameters.\n*\n INFO = 0\n LQUERY = ( LWORK.EQ.-1 )\n IF( .NOT.LSAME( UPLO, 'U' ) .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN\n INFO = -1\n ELSE IF( N.LT.0 ) THEN\n INFO = -2\n ELSE IF( NRHS.LT.0 ) THEN\n INFO = -3\n ELSE IF( LDA.LT.MAX( 1, N ) ) THEN\n INFO = -5\n ELSE IF( LDB.LT.MAX( 1, N ) ) THEN\n INFO = -8\n ELSE IF( LWORK.LT.1 .AND. .NOT.LQUERY ) THEN\n INFO = -10\n END IF\n*\n IF( INFO.EQ.0 ) THEN\n IF( N.EQ.0 ) THEN\n LWKOPT = 1\n ELSE\n CALL SSYTRF( UPLO, N, A, LDA, IPIV, WORK, -1, INFO )\n LWKOPT = WORK(1)\n END IF\n WORK( 1 ) = LWKOPT\n END IF\n*\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'SSYSV ', -INFO )\n RETURN\n ELSE IF( LQUERY ) THEN\n RETURN\n END IF\n*\n* Compute the factorization A = U*D*U**T or A = L*D*L**T.\n*\n CALL SSYTRF( UPLO, N, A, LDA, IPIV, WORK, LWORK, INFO )\n IF( INFO.EQ.0 ) THEN\n*\n* Solve the system A*X = B, overwriting B with X.\n*\n IF ( LWORK.LT.N ) THEN\n*\n* Solve with TRS ( Use Level BLAS 2)\n*\n CALL SSYTRS( UPLO, N, NRHS, A, LDA, IPIV, B, LDB, INFO )\n*\n ELSE\n*\n* Solve with TRS2 ( Use Level BLAS 3)\n*\n CALL SSYTRS2( UPLO,N,NRHS,A,LDA,IPIV,B,LDB,WORK,INFO )\n*\n END IF\n*\n END IF\n*\n WORK( 1 ) = LWKOPT\n*\n RETURN\n*\n* End of SSYSV\n*\n END\n", "meta": {"hexsha": "5f4062e9aec09b333191b36969d9f03c9ba5d653", "size": 8312, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "SRC/ssysv.f", "max_stars_repo_name": "sergey-v-kuznetsov/lapack", "max_stars_repo_head_hexsha": "799ef93faa5878aa8702f7cf9980cfc649cc39cc", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 998, "max_stars_repo_stars_event_min_datetime": "2016-05-04T20:50:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T17:43:13.000Z", "max_issues_repo_path": "SRC/ssysv.f", "max_issues_repo_name": "sergey-v-kuznetsov/lapack", "max_issues_repo_head_hexsha": "799ef93faa5878aa8702f7cf9980cfc649cc39cc", "max_issues_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_issues_count": 603, "max_issues_repo_issues_event_min_datetime": "2016-06-04T07:28:21.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T21:16:50.000Z", "max_forks_repo_path": "SRC/ssysv.f", "max_forks_repo_name": "sergey-v-kuznetsov/lapack", "max_forks_repo_head_hexsha": "799ef93faa5878aa8702f7cf9980cfc649cc39cc", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 373, "max_forks_repo_forks_event_min_datetime": "2016-06-04T06:05:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T17:25:45.000Z", "avg_line_length": 31.0149253731, "max_line_length": 110, "alphanum_fraction": 0.5333253128, "num_tokens": 2532, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037343628703, "lm_q2_score": 0.7310585727705126, "lm_q1q2_score": 0.6771822859953159}} {"text": "subroutine vecres(norm,n,v1,v2,redif,zero)\n\n!-----------------------------------------------------------------------\n!\n! Compute the relative difference between two vectors:\n! \n! redif = 1*||v1 - v2|| / ||v1|| \n!\n!-----------------------------------------------------------------------\n use typre\n implicit none\n integer(ip), intent(in) :: n,norm\n real(rp), intent(in) :: v1(n),v2(n),zero\n real(rp), intent(out) :: redif\n integer(ip) :: i\n real(rp) :: numer,denom,va,vo\n\n redif = 0.0_rp\n numer = 0.0_rp\n denom = 0.0_rp\n\n select case(norm)\n\n case(0)\n do i = 1,n\n va = v1(i)\n vo = v2(i)\n numer = max(numer,abs(va-vo))\n denom = max(denom,abs(va))\n end do\n if(denom.gt.zero) redif = 1.0_rp*numer/denom\n\n case(1)\n do i = 1,n\n va = v1(i)\n vo = v2(i)\n numer = numer + abs(va-vo)\n denom = denom + abs(va)\n end do\n if(denom>zero) redif = 1.0_rp*numer/denom\n\n case(2)\n do i = 1,n\n va = v1(i)\n vo = v2(i)\n numer = numer + (va-vo)*(va-vo)\n denom = denom + va*va\n end do\n if(denom>zero) redif = 1.0_rp*sqrt(numer/denom)\n\n end select\n\nend subroutine vecres\n\n\nsubroutine vecresMPI(norm,n,v1,v2,redif,zero,kfl_MPIComType,MPIcomm,MPIroot,MPIrank,MPIsize)\n\n!-----------------------------------------------------------------------\n!\n! Compute the relative difference between two vectors:\n! \n! redif = 100*||v1 - v2|| / ||v1|| \n!\n!-----------------------------------------------------------------------\n use typre\n use MPI\n implicit none\n integer(ip), intent(in) :: n,norm\n real(rp), intent(in) :: v1(n),v2(n),zero\n real(rp), intent(out) :: redif\n integer(ip), intent(in) :: kfl_MPIComType,MPIcomm,MPIroot,MPIrank,MPIsize\n integer(ip) :: i\n real(rp) :: numer,denom,va,vo,rwa(2),rwa2(2)\n integer :: ierr\n\n redif = 0.0_rp\n numer = 0.0_rp\n denom = 0.0_rp\n\n select case(norm)\n\n case(0)\n do i = 1,n\n va = v1(i)\n vo = v2(i)\n numer = max(numer,abs(va-vo))\n denom = max(denom,abs(va))\n end do\n \n rwa(1) = numer\n rwa(2) = denom\n call MPI_REDUCE_Implementation(2_ip,rwa,rwa2,kfl_MPIComType,MPIcomm,MPIrank,MPIroot,MPIsize)\n numer = rwa2(1)\n denom = rwa2(2)\n \n if(denom.gt.zero) redif = 1.0_rp*numer/denom\n case(1)\n do i = 1,n\n va = v1(i)\n vo = v2(i)\n numer = numer + abs(va-vo)\n denom = denom + abs(va)\n end do\n \n rwa(1) = numer\n rwa(2) = denom\n call MPI_REDUCE_Implementation(2_ip,rwa,rwa2,kfl_MPIComType,MPIcomm,MPIrank,MPIroot,MPIsize)\n numer = rwa2(1)\n denom = rwa2(2)\n \n if(denom>zero) redif = 1.0_rp*numer/denom\n case(2)\n do i = 1,n\n va = v1(i)\n vo = v2(i)\n numer = numer + (va-vo)*(va-vo)\n denom = denom + va*va\n end do\n \n rwa(1) = numer\n rwa(2) = denom\n call MPI_REDUCE_Implementation(2_ip,rwa,rwa2,kfl_MPIComType,MPIcomm,MPIrank,MPIroot,MPIsize)\n numer = rwa2(1)\n denom = rwa2(2)\n \n if(denom>zero) redif = 1.0_rp*sqrt(numer/denom)\n end select\n\ncontains\n \n \nend subroutine vecresMPI\n\nsubroutine MPI_REDUCE_Implementation(rwasize,rwa,rwa2,kfl_MPIComType,MPIcomm,MPIrank,MPIroot,MPIsize)\n use typre\n use MPI\n implicit none\n integer(ip) :: rwasize, MPIcomm,MPIrank,MPIroot,MPIsize,kfl_MPIComType\n real(rp) :: rwa(rwasize),rwa2(rwasize)\n \n real(rp) :: auxrwa2(2,MPIsize)\n integer(ip) :: irank,isize\n \n !MPI\n integer, parameter :: mtag1 = 1, mtag2 = 2\n integer :: irequest, irequest01(MPIsize)\n integer status(MPI_STATUS_SIZE)\n integer :: ierr\n \n !Blocking\n if (kfl_MPIComType == 0) then\n call MPI_REDUCE( rwa, rwa2, rwasize, MPI_REAL8, MPI_SUM, MPIroot,MPIcomm, ierr )\n !Non-Blocking\n else\n !Everybody sends to root\n call MPI_ISEND(rwa,rwasize,MPI_REAL8, MPIroot, mtag1, MPIcomm,irequest, ierr)\n \n !Root receives\n if (MPIrank == MPIroot) then\n do irank = 0,MPIsize-1\n call MPI_IRECV(auxrwa2(:,irank+1), rwasize, MPI_REAL8, irank, mtag1, MPIcomm,irequest01(irank+1), ierr)\n enddo\n do irank = 0,MPIsize-1\n call MPI_WAIT(irequest01(irank+1), status,ierr)\n enddo\n do isize = 1,rwasize\n rwa2(isize) = sum(auxrwa2(isize,:))\n enddo\n endif \n call MPI_WAIT(irequest, status, ierr)\n endif\nend subroutine\n\n\n\nsubroutine vecresMPIHeterogeneous(norm,ndime1,ndime2,npoinLocal,startcomp1,startcomp2,ncomp,v1,v2,redif,zero,MPIcomm,MPIroot)\n\n!-----------------------------------------------------------------------\n!\n! Compute the relative difference between two vectors:\n! \n! redif = 100*||v1 - v2|| / ||v1|| \n!\n!-----------------------------------------------------------------------\n use typre\n use MPI\n implicit none\n integer(ip), intent(in) :: ndime1,ndime2,ncomp,startcomp1,startcomp2,norm,npoinLocal\n real(rp), intent(in) :: v1(ndime1,npoinLocal),v2(ndime2,npoinLocal),zero\n real(rp), intent(out) :: redif\n integer(ip) :: i,MPIcomm,MPIroot,idime\n real(rp) :: numer,denom,va,vo,rwa(2),rwa2(2)\n integer :: ierr\n\n redif = 0.0_rp\n numer = 0.0_rp\n denom = 0.0_rp\n\n select case(norm)\n\n case(0)\n do i = 1,npoinLocal\n do idime = 0,ncomp-1\n va = v1(startcomp1+idime,i)\n vo = v2(startcomp2+idime,i)\n numer = max(numer,abs(va-vo))\n denom = max(denom,abs(va))\n enddo\n end do\n \n rwa(1) = numer\n rwa(2) = denom\n call MPI_REDUCE( rwa, rwa2, 2, MPI_REAL8, MPI_SUM, MPIroot,MPIcomm, ierr )\n numer = rwa2(1)\n denom = rwa2(2)\n \n if(denom.gt.zero) redif = 1.0_rp*numer/denom\n\n case(1)\n do i = 1,npoinLocal\n do idime = 0,ncomp-1\n va = v1(startcomp1+idime,i)\n vo = v2(startcomp2+idime,i)\n numer = numer + abs(va-vo)\n denom = denom + abs(va)\n enddo\n end do\n \n rwa(1) = numer\n rwa(2) = denom\n call MPI_REDUCE( rwa, rwa2, 2, MPI_REAL8, MPI_SUM, MPIroot,MPIcomm, ierr )\n numer = rwa2(1)\n denom = rwa2(2)\n \n if(denom>zero) redif = 1.0_rp*numer/denom\n\n case(2)\n do i = 1,npoinLocal\n do idime = 0,ncomp-1\n va = v1(startcomp1+idime,i)\n vo = v2(startcomp2+idime,i)\n numer = numer + (va-vo)*(va-vo)\n denom = denom + va*va\n enddo\n end do\n \n rwa(1) = numer\n rwa(2) = denom\n call MPI_REDUCE( rwa, rwa2, 2, MPI_REAL8, MPI_SUM, MPIroot,MPIcomm, ierr )\n numer = rwa2(1)\n denom = rwa2(2)\n \n if(denom>zero) redif = 1.0_rp*sqrt(numer/denom)\n\n end select\n\nend subroutine vecresMPIHeterogeneous\n", "meta": {"hexsha": "ddaa994f4f81880e14a8f09998ae891c44f38a3c", "size": 6780, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Sources/mathru/vecres.f90", "max_stars_repo_name": "ciaid-colombia/InsFEM", "max_stars_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-24T08:19:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-24T08:19:54.000Z", "max_issues_repo_path": "Sources/mathru/vecres.f90", "max_issues_repo_name": "ciaid-colombia/InsFEM", "max_issues_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Sources/mathru/vecres.f90", "max_forks_repo_name": "ciaid-colombia/InsFEM", "max_forks_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.2790697674, "max_line_length": 125, "alphanum_fraction": 0.5398230088, "num_tokens": 2293, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.6771784307594872}} {"text": "program array_arithmetic\n implicit none\n real, dimension(5) :: A = [ 1.2, 2.3, 3.4, 4.5, 5.6 ], &\n B = [ -1.0, -0.5, 0.0, 0.5, 1.0], &\n C\n\n C = A + 2.0*B\n print *, C\nend program array_arithmetic\n", "meta": {"hexsha": "7425fd5210473b3914f888a697027d8a0355c183", "size": 257, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source_code/arrays/array_arithmetic.f90", "max_stars_repo_name": "caguerra/Fortran-MOOC", "max_stars_repo_head_hexsha": "fb8a9c24e62ce5f388deb06b21e3009aea6b78d4", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2021-05-20T12:03:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-16T19:46:26.000Z", "max_issues_repo_path": "source_code/arrays/array_arithmetic.f90", "max_issues_repo_name": "caguerra/Fortran-MOOC", "max_issues_repo_head_hexsha": "fb8a9c24e62ce5f388deb06b21e3009aea6b78d4", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-09-30T04:25:50.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-06T08:21:30.000Z", "max_forks_repo_path": "source_code/arrays/array_arithmetic.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": 25.7, "max_line_length": 61, "alphanum_fraction": 0.4241245136, "num_tokens": 101, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240756264638, "lm_q2_score": 0.782662489091802, "lm_q1q2_score": 0.6771784286519617}} {"text": "! { dg-do run }\n! Test assorted intrinsics for integer kinds 1 and 2\nprogram main\n integer(kind=1), dimension(2,2) :: a\n integer(kind=2), dimension(2,2) :: b\n integer(kind=1), dimension(2) :: r1\n integer(kind=2), dimension(2) :: r2\n logical, dimension(2,2) :: ma\n ma = .false.\n a = reshape((/ 1_1, 2_1, 3_1, 4_1/), shape(a))\n b = reshape((/ 1_2, 2_2, 3_2, 4_2/), shape(b))\n if (any(sum(a,dim=2) /= (/ 4, 6 /))) STOP 1\n if (any(sum(b,dim=2) /= (/ 4, 6 /))) STOP 2\n if (any(product(a,dim=2) /= (/ 3, 8 /))) STOP 3\n if (any(product(b,dim=2) /= (/ 3, 8 /))) STOP 4\n if (any(matmul(a,a) /= reshape ( (/ 7, 10, 15, 22 /), shape(a)))) STOP 5\n if (any(matmul(b,b) /= reshape ( (/ 7, 10, 15, 22 /), shape(b)))) STOP 6\n if (any(maxval(a,dim=2,mask=ma) /= -128)) STOP 7\n if (any(maxval(b,dim=2,mask=ma) /= -32768)) STOP 8\nend program main\n", "meta": {"hexsha": "cd35a80eaf07aec987bfb368bfd18bc43307851b", "size": 844, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/intrinsic_intkinds_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/intrinsic_intkinds_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/intrinsic_intkinds_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": 40.1904761905, "max_line_length": 74, "alphanum_fraction": 0.5627962085, "num_tokens": 368, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240791017536, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6771784269857458}} {"text": "program main\n use ArrayClass\n implicit none\n\n type(Array_) :: A, B, C, I, str_array\n real(real64),allocatable :: vector(:),small_vector(:)\n integer(int32),allocatable :: vector_int(:)\n real(real64),allocatable :: matrix(:,:)\n integer(int32),allocatable :: matrix_int(:,:)\n\n print *, \" \"\n call A%random(3,3)\n call B%zeros(3,3)\n call I%unit(3,3)\n\n C = A * B ! A_ij B_jk\n\n C = A + B ! A_ij + B_ij\n\n call A%print()\n call B%print()\n call C%print()\n call I%print()\n\n print *, dot(C, C)\n\n ! create vectors\n print *, \"zeros\"\n vector = zeros(5) ! Five 0\n call print(vector)\n\n ! hstack\n print *, \"hstack\"\n small_vector = [10.0d0, 20.0d0, 30.0d0, 40.0d0]\n call print( hstack(vector, small_vector) )\n\n ! np.arange\n print *, \"arange\"\n vector = arange(5) ! 1, 2, 3 , 4, 5\n call print(vector)\n \n ! np.arange\n print *, \"arange : start, stop, step\"\n vector = arange(10, 50, 5) ! 1, 2, 3 , 4, 5\n call print(vector)\n \n ! np.arange\n print *, \"arange : start, stop, step\"\n vector_int = int(arange(10, 50, 5)) ! 1, 2, 3 , 4, 5\n call print(vector_int)\n\n ! reshape\n print *, \"arange : start, stop, step\"\n matrix = reshape(vector, 7, 3 )\n call print(matrix)\n\n ! reshape int\n print *, \"arange : start, stop, step\"\n matrix_int = reshape(vector_int, 7, 3 )\n call print(matrix_int)\n\n ! allocate string-array\n allocate(str_array%list(4,4) )\n str_array%list(1,1)%string = \"hello\"\n str_array%list(1,2)%string = \"hello\"\n str_array%list(1,3)%string = \"hello\"\n str_array%list(1,4)%string = \"hello\"\n str_array%list(1,2)%string = \"oka\"\n str_array%list(3,1)%string = \"hoge\"\n str_array%list(1,4)%string = \"piyo\"\n call str_array%print()\n\n\nend program", "meta": {"hexsha": "269212c1438e8dedc52f164de335f2f99a9e836c", "size": 1785, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/playon_std/ArrayObject.f90", "max_stars_repo_name": "kazulagi/plantfem_min", "max_stars_repo_head_hexsha": "ba7398c031636644aef8acb5a0dad7f9b99fcb92", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2020-06-21T08:21:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-13T04:28:30.000Z", "max_issues_repo_path": "Tutorial/std/ArrayObject.f90", "max_issues_repo_name": "kazulagi/plantFEM_binary", "max_issues_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-05-08T05:20:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T05:39:29.000Z", "max_forks_repo_path": "Tutorial/std/ArrayObject.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": 24.1216216216, "max_line_length": 57, "alphanum_fraction": 0.5820728291, "num_tokens": 616, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.6771784253195298}} {"text": " program demo_M_display\n use M_display\n implicit none\n integer, parameter :: rk = selected_real_kind(6), n = 3\n real(rk) :: a(n,n), b(n,n), x\n integer i, j, k(5)\n call disp_set(advance = 'double')\n forall(i=1:n, j=1:n)\n a(i,j) = exp(real(i+j-1, rk))\n b(i,j) = exp(real(i**j, rk))\n end forall\n call disp('A = ', a)\n call disp(b)\n call disp(a(1:2,:),'f0.5')\n call disp('MATRIX', a, style='UNDERLINE & NUMBER', unit=-3, digmax=4)\n k = [-3,0,12,14,0]\n call disp('K', k, style='pad', orient='row', sep=' ', zeroas='.')\n x = 1.5\n call disp('The square of '//tostring(x)//' is '//tostring(x*x))\n call disp_set(matsep = ' | ')\n call disp([11,12,13], advance='no')\n call disp([.true., .false., .true.], advance='no')\n call disp(['A','B','C'])\n end program demo_M_display\n", "meta": {"hexsha": "403bb21d021146b974733ff3fa5920575c2f836d", "size": 896, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "docs/fpm-ford/src/demo_M_display.f90", "max_stars_repo_name": "urbanjost/M_display", "max_stars_repo_head_hexsha": "57fde3f51b0f877d03eae36d3d593f0c414d8b55", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-12-09T08:29:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-09T08:29:48.000Z", "max_issues_repo_path": "example/demo_M_display.f90", "max_issues_repo_name": "urbanjost/M_display", "max_issues_repo_head_hexsha": "57fde3f51b0f877d03eae36d3d593f0c414d8b55", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "example/demo_M_display.f90", "max_forks_repo_name": "urbanjost/M_display", "max_forks_repo_head_hexsha": "57fde3f51b0f877d03eae36d3d593f0c414d8b55", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-10-02T16:32:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-16T07:59:19.000Z", "avg_line_length": 35.84, "max_line_length": 76, "alphanum_fraction": 0.5089285714, "num_tokens": 291, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.865224068675884, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.6771784100534192}} {"text": "MODULE Bivariate_Trivariate_Normal\r\n\r\n! Appendix: Fortran Source Code\r\n \r\n! Code converted using TO_F90 by Alan Miller\r\n! Date: 2001-02-25 Time: 11:57:13\r\n! Latest revision - 25 February 2001\r\n! amiller @ bigpond.net.au\r\n \r\n! Code from Alan Genz's web site for bivariate & trivariate\r\n! normal integrals, adapted by Alan Miller.\r\n\r\n! http://www.sci.wsu.edu/math/faculty/genz/papers/\r\n\r\n! Alan C Genz\r\n! 2001-01-22\r\n\r\n\r\nIMPLICIT NONE\r\nINTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(12, 60)\r\n\r\n! COMMON /trvbkd/b2p, b3p, rho21, rho31, rho\r\nREAL (dp), SAVE :: b2p, b3p, rho21, rho31, rho\r\n\r\n\r\nCONTAINS\r\n\r\n\r\nFUNCTION bvn( sh, sk, r ) RESULT(fn_val)\r\n\r\n! A function for computing bivariate normal probabilities.\r\n! This function uses an algorithm given in the paper\r\n! \"Numerical Computation of Bivariate and\r\n! Trivariate Normal Probabilities\", by\r\n! Alan Genz\r\n! Department of Mathematics\r\n! Washington State University\r\n! Pullman, WA 99164-3113\r\n! Email : alangenz@wsu.edu\r\n\r\n! BVN - calculate the probability that X is larger than SH, and Y is\r\n! larger than SK.\r\n\r\n! Parameters\r\n\r\n! SH REAL, integration limit\r\n! SK REAL, integration limit\r\n! R REAL, correlation coefficient\r\n! LG INTEGER, number of Gauss Rule Points and Weights\r\n\r\n\r\nREAL, INTENT(IN) :: sh, sk, r\r\nREAL :: fn_val\r\n\r\nREAL, PARAMETER :: zero = 0, twopi = 6.283185\r\nINTEGER, PARAMETER :: lg = 5\r\nREAL, PARAMETER :: x(lg) = &\r\n (/ -0.9061798, -0.5384693, 0.0, 0.5384693, 0.9061798 /)\r\n! X(I) = +-SQRT((5+-SQRT(10/7))/9), 0\r\nREAL, PARAMETER :: w(lg) = &\r\n (/ 0.2369269, 0.4786287, 0.5688889, 0.4786287, 0.2369269 /)\r\n\r\nINTEGER :: i\r\nREAL :: as, a, b, c, rs, xs\r\nREAL :: sn, asr, h, k, bs, hs, hk\r\n\r\nh = sh\r\nk = sk\r\nhk = h*k\r\nfn_val = 0\r\n\r\n! Absolute value of the correlation coefficient is less than 0.8\r\n\r\nIF ( ABS(r) < 0.8 ) THEN\r\n hs = ( h*h + k*k )/2\r\n asr = ASIN( r )/2\r\n DO i = 1, lg\r\n sn = SIN( asr*(x(i)+1) )\r\n fn_val = fn_val + w(i)*EXP( ( sn*hk - hs )/( 1 - sn*sn ) )\r\n END DO\r\n fn_val = asr*fn_val/twopi + phi(-h)*phi(-k)\r\nELSE\r\n \r\n! For larger correlation coefficient\r\n \r\n IF ( r < 0 ) THEN\r\n k = -k\r\n hk = -hk\r\n END IF\r\n IF ( ABS(r) < 1 ) THEN\r\n as = ( 1 - r )*( 1 + r )\r\n a = SQRT( as )\r\n bs = ( h - k )**2\r\n c = ( 4 - hk )/8\r\n fn_val = a*EXP( -(bs/as + hk)/2 )*( 1 - c*(bs - as)/3 )\r\n IF ( -hk < 100 ) THEN\r\n b = SQRT(bs)\r\n fn_val = fn_val - EXP(-hk/2)*SQRT(twopi)*phi(-b/a)*b*(1-c*bs/3)\r\n END IF\r\n a = a/2\r\n DO i = 1, lg\r\n xs = ( a*( x(i) + 1 ) )**2\r\n rs = SQRT( 1 - xs )\r\n asr = -( bs/xs + hk )/2\r\n IF ( asr > -100 ) fn_val = fn_val + a*w(i)* &\r\n ( EXP(-bs/(2*xs) - hk/(1+rs))/rs - EXP(asr)*(1+c*xs) )\r\n END DO\r\n fn_val = -fn_val/twopi\r\n END IF\r\n IF ( r > 0 ) fn_val = fn_val + phi( -MAX( h, k ) )\r\n IF ( r < 0 ) fn_val = -fn_val + MAX( zero, phi(-h) - phi(-k) )\r\nEND IF\r\n\r\nRETURN\r\nEND FUNCTION bvn\r\n\r\n\r\n\r\nFUNCTION phi(x) RESULT(fn_val)\r\n\r\nREAL, INTENT(IN) :: x\r\nREAL :: fn_val\r\n\r\nfn_val = phid( REAL(x, KIND=dp) )\r\nRETURN\r\nEND FUNCTION phi\r\n\r\n\r\n\r\nFUNCTION bvnd( dh, dk, r ) RESULT(fn_val)\r\n\r\n! A function for computing bivariate normal probabilities.\r\n\r\n! Alan Genz\r\n! Department of Mathematics\r\n! Washington State University\r\n! Pullman, WA 99164-3113\r\n! Email : alangenz@wsu.edu\r\n\r\n! This function is based on the method described by\r\n! Drezner, Z and G.O. Wesolowsky, (1989),\r\n! On the computation of the bivariate normal inegral,\r\n! Journal of Statist. Comput. Simul. 35, pp. 101-107,\r\n! with major modifications for REAL (dp), and for |R| close to 1.\r\n\r\n! BVND - calculate the probability that X is larger than DH, and Y is\r\n! larger than DK.\r\n\r\n! Parameters\r\n\r\n! DH REAL (dp), integration limit\r\n! DK REAL (dp), integration limit\r\n! R REAL (dp), correlation coefficient\r\n\r\n\r\nREAL (dp), INTENT(IN) :: dh, dk, r\r\nREAL (dp) :: fn_val\r\n\r\nREAL (dp), PARAMETER :: zero = 0.0_dp, twopi = 6.283185307179586_dp\r\n\r\nREAL (dp), PARAMETER :: x(10,3) = RESHAPE( &\r\n ! Gauss Legendre Points, N = 6\r\n (/ -0.9324695142031522_dp, -0.6612093864662647_dp, &\r\n -0.2386191860831970_dp, 0.0_dp, 0.0_dp, 0.0_dp, &\r\n 0.0_dp, 0.0_dp, 0.0_dp, 0.0_dp, &\r\n ! Gauss Legendre Points, N = 12\r\n -0.9815606342467191_dp, -0.9041172563704750_dp, &\r\n -0.7699026741943050_dp, -0.5873179542866171_dp, &\r\n -0.3678314989981802_dp, -0.1252334085114692_dp, &\r\n 0.0_dp, 0.0_dp, 0.0_dp, 0.0_dp, &\r\n ! Gauss Legendre Points, N = 20\r\n -0.9931285991850949_dp, -0.9639719272779138_dp, &\r\n -0.9122344282513259_dp, -0.8391169718222188_dp, &\r\n -0.7463319064601508_dp, -0.6360536807265150_dp, &\r\n -0.5108670019508271_dp, -0.3737060887154196_dp, &\r\n -0.2277858511416451_dp, -0.07652652113349733_dp /), (/ 10, 3 /) )\r\nREAL (dp), PARAMETER :: w(10,3) = RESHAPE( &\r\n ! Gauss Legendre Weights, N = 6\r\n (/ 0.1713244923791705_dp, 0.3607615730481384_dp, 0.4679139345726904_dp, &\r\n 0.0_dp, 0.0_dp, 0.0_dp, 0.0_dp, 0.0_dp, 0.0_dp, 0.0_dp, &\r\n ! Gauss Legendre Weights, N = 12\r\n 0.04717533638651177_dp, 0.1069393259953183_dp, 0.1600783285433464_dp, &\r\n 0.2031674267230659_dp, 0.2334925365383547_dp, 0.2491470458134029_dp, &\r\n 0.0_dp, 0.0_dp, 0.0_dp, 0.0_dp, &\r\n ! Gauss Legendre Weights, N = 20\r\n 0.01761400713915212_dp, 0.04060142980038694_dp, 0.06267204833410906_dp, &\r\n 0.08327674157670475_dp, 0.1019301198172404_dp, 0.1181945319615184_dp, &\r\n 0.1316886384491766_dp, 0.1420961093183821_dp, 0.1491729864726037_dp, &\r\n 0.1527533871307259_dp /), (/ 10, 3 /) )\r\n\r\nINTEGER :: i, is, lg, ng\r\nREAL (dp) :: as, a, b, c, d, rs, xs, bvn\r\nREAL (dp) :: sn, asr, h, k, bs, hs, hk\r\n\r\nIF ( ABS(r) < 0.3_dp ) THEN\r\n ng = 1\r\n lg = 3\r\nELSE IF ( ABS(r) < 0.75_dp ) THEN\r\n ng = 2\r\n lg = 6\r\nELSE\r\n ng = 3\r\n lg = 10\r\nEND IF\r\nh = dh\r\nk = dk\r\nhk = h*k\r\nbvn = 0\r\nIF ( ABS(r) < 0.925_dp ) THEN\r\n hs = ( h*h + k*k )/2\r\n asr = ASIN(r)\r\n DO i = 1, lg\r\n DO is = -1, 1, 2\r\n sn = SIN( asr*( is*x(i,ng) + 1 )/2 )\r\n bvn = bvn + w(i,ng)*EXP( ( sn*hk - hs )/( 1 - sn*sn ) )\r\n END DO\r\n END DO\r\n bvn = bvn*asr/( 2*twopi ) + phid(-h)*phid(-k)\r\nELSE\r\n IF ( r < 0 ) THEN\r\n k = -k\r\n hk = -hk\r\n END IF\r\n IF ( ABS(r) < 1 ) THEN\r\n as = ( 1 - r )*( 1 + r )\r\n a = SQRT(as)\r\n bs = ( h - k )**2\r\n c = ( 4 - hk )/8\r\n d = ( 12 - hk )/16\r\n asr = -( bs/as + hk )/2\r\n IF ( asr > -100 ) bvn = a*EXP(asr) &\r\n *( 1 - c*( bs - as )*( 1 - d*bs/5 )/3 + c*d*as*as/5 )\r\n IF ( -hk < 100 ) THEN\r\n b = SQRT(bs)\r\n bvn = bvn - EXP( -hk/2 )*SQRT(twopi)*phid(-b/a)*b &\r\n *( 1 - c*bs*( 1 - d*bs/5 )/3 )\r\n END IF\r\n a = a/2\r\n DO i = 1, lg\r\n DO is = -1, 1, 2\r\n xs = ( a*( is*x(i,ng) + 1 ) )**2\r\n rs = SQRT( 1 - xs )\r\n asr = -( bs/xs + hk )/2\r\n IF ( asr > -100 ) THEN\r\n bvn = bvn + a*w(i,ng)*EXP( asr ) &\r\n *( EXP( -hk*( 1 - rs )/( 2*( 1 + rs ) ) )/rs &\r\n - ( 1 + c*xs*( 1 + d*xs ) ) )\r\n END IF\r\n END DO\r\n END DO\r\n bvn = -bvn/twopi\r\n END IF\r\n IF ( r > 0 ) bvn = bvn + phid( -MAX( h, k ) )\r\n IF ( r < 0 ) bvn = -bvn + MAX( zero, phid(-h) - phid(-k) )\r\nEND IF\r\n\r\nfn_val = bvn\r\nRETURN\r\nEND FUNCTION bvnd\r\n\r\n\r\n\r\nFUNCTION tvnd( limit, sigma ) RESULT(fn_val)\r\n\r\n! A function for computing trivariate normal probabilities.\r\n! This function uses an algorithm given in the paper\r\n! \"Numerical Computation of Bivariate and\r\n! Trivariate Normal Probabilities\",\r\n! by\r\n! Alan Genz\r\n! Department of Mathematics\r\n! Washington State University\r\n! Pullman, WA 99164-3113\r\n! Email : alangenz@wsu.edu\r\n\r\n! TVND calculates the probability that X(I) < LIMIT(I), I = 1, 2, 3.\r\n\r\n! Bivariate normal distribution function BVND is required.\r\n\r\n! Parameters\r\n\r\n! LIMIT REAL (dp) array of three upper integration limits.\r\n! SIGMA REAL (dp) array of three correlation coefficients,\r\n! SIGMA should contain the lower left portion of the\r\n! correlation matrix R.\r\n! SIGMA(1) = R(2,1), SIGMA(2) = R(3,1), SIGMA(3) = R(3,2).\r\n\r\n! TVND cuts the outer integral over -infinity to B1 to an integral\r\n! from -8.5 to B1 and then uses an adaptive integration method to\r\n! compute the integral of a bivariate normal distribution function.\r\n\r\n\r\nREAL (dp), INTENT(IN) :: limit(3), sigma(3)\r\nREAL (dp) :: fn_val\r\n\r\n! EXTERNAL trvfnd\r\n! COMMON /trvbkd/b2p, b3p, rho21, rho31, rho\r\n\r\nLOGICAL :: tail\r\nREAL (dp) :: sq21, sq31\r\nREAL (dp) :: b1, b2, b3, rho32\r\nREAL (dp), PARAMETER :: sqtwpi = 2.506628274631000_dp, xcut = -8.5_dp, &\r\n eps = 5D-16\r\n\r\nb1 = limit(1)\r\nb2 = limit(2)\r\nb3 = limit(3)\r\nrho21 = sigma(1)\r\nrho31 = sigma(2)\r\nrho32 = sigma(3)\r\nIF ( ABS(b2) >= MAX( ABS(b1), ABS(b3) ) ) THEN\r\n b1 = b2\r\n b2 = limit(1)\r\n rho31 = rho32\r\n rho32 = sigma(2)\r\nELSE IF ( ABS(b3) >= MAX( ABS(b1), ABS(b2) ) ) THEN\r\n b1 = b3\r\n b3 = limit(1)\r\n rho21 = rho32\r\n rho32 = sigma(1)\r\nEND IF\r\ntail = .false.\r\nIF ( b1 > 0 ) THEN\r\n tail = .true.\r\n b1 = -b1\r\n rho21 = -rho21\r\n rho31 = -rho31\r\nEND IF\r\nIF ( b1 > xcut ) THEN\r\n IF ( 2*ABS(rho21) < 1 ) THEN\r\n sq21 = SQRT( 1 - rho21**2 )\r\n ELSE\r\n sq21 = SQRT( ( 1 - rho21 )*( 1 + rho21 ) )\r\n END IF\r\n IF ( 2*ABS(rho31) < 1 ) THEN\r\n sq31 = SQRT( 1 - rho31**2 )\r\n ELSE\r\n sq31 = SQRT( ( 1 - rho31 )*( 1 + rho31 ) )\r\n END IF\r\n rho = ( rho32 - rho21*rho31 )/(sq21*sq31)\r\n b2p = b2/sq21\r\n rho21 = rho21/sq21\r\n b3p = b3/sq31\r\n rho31 = rho31/sq31\r\n fn_val = adoned( trvfnd, xcut, b1, eps )/sqtwpi\r\nELSE\r\n fn_val = 0\r\nEND IF\r\nIF ( tail ) fn_val = bvnd( -b2, -b3, rho32 ) - fn_val\r\n\r\nRETURN\r\nEND FUNCTION tvnd\r\n\r\n\r\n\r\nFUNCTION trvfnd(t) RESULT(fn_val)\r\n\r\nREAL (dp), INTENT(IN) :: t\r\nREAL (dp) :: fn_val\r\n\r\n! COMMON /trvbkd/b2, b3, rho21, rho31, rho\r\n\r\nfn_val = EXP( -t*t/2 )*bvnd(t*rho21 - b2p, t*rho31 - b3p, rho)\r\nRETURN\r\nEND FUNCTION trvfnd\r\n\r\n\r\n\r\nFUNCTION adoned( f, a, b, tol ) RESULT(fin)\r\n\r\n! One Dimensional Globally Adaptive Integration Function\r\n\r\nREAL (dp), INTENT(IN) :: a, b, tol\r\nREAL (dp) :: fin\r\n\r\n! EXTERNAL f\r\n\r\nINTERFACE\r\n FUNCTION f(x) RESULT(fn_val)\r\n IMPLICIT NONE\r\n INTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(12, 60)\r\n REAL (dp), INTENT(IN) :: x\r\n REAL (dp) :: fn_val\r\n END FUNCTION f\r\nEND INTERFACE\r\n\r\nINTEGER, PARAMETER :: nl = 100\r\nREAL (dp) :: ei(nl), ai(nl), bi(nl), fi(nl), ERR\r\nINTEGER :: i, im, ip\r\n\r\nip = 1\r\nai(ip) = a\r\nbi(ip) = b\r\nCALL krnrdd( ai(ip), bi(ip), f, ei(ip), fi(ip) )\r\nim = 1\r\n10 im = im + 1\r\nbi(im) = bi(ip)\r\nai(im) = (ai(ip) + bi(ip))/2\r\nbi(ip) = ai(im)\r\nfin = fi(ip)\r\nCALL krnrdd( ai(ip), bi(ip), f, ei(ip), fi(ip) )\r\nCALL krnrdd( ai(im), bi(im), f, ei(im), fi(im) )\r\nERR = ABS( fin - fi(ip) - fi(im) )/2\r\nei(ip) = ei(ip) + ERR\r\nei(im) = ei(im) + ERR\r\nip = 1\r\nERR = 0\r\nfin = 0\r\nDO i = 1, im\r\n IF ( ei(i) > ei(ip) ) ip = i\r\n fin = fin + fi(i)\r\n ERR = ERR + ei(i)\r\nEND DO\r\nIF ( ERR > tol .AND. im < nl ) GO TO 10\r\n\r\nRETURN\r\nEND FUNCTION adoned\r\n\r\n\r\n\r\nSUBROUTINE krnrdd( a, b, f, abserr, fn_val)\r\n\r\n! Kronrod Rule\r\n\r\nREAL (dp), INTENT(IN) :: a, b\r\nREAL (dp), INTENT(OUT) :: abserr, fn_val\r\n\r\n! EXTERNAL f\r\n\r\nINTERFACE\r\n FUNCTION f(x) RESULT(fn_val)\r\n IMPLICIT NONE\r\n INTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(12, 60)\r\n REAL (dp), INTENT(IN) :: x\r\n REAL (dp) :: fn_val\r\n END FUNCTION f\r\nEND INTERFACE\r\n\r\nREAL (dp) :: abscis, center, fc, funsum, hflgth, resltg, resltk\r\n\r\n! The abscissae and weights are given for the interval (-1,1)\r\n! because of symmetry only the positive abscisae and their\r\n! corresponding weights are given.\r\n\r\n! XGK - abscissae of the 2N+1-point Kronrod rule:\r\n! XGK(2), XGK(4), ... N-point Gauss rule abscissae;\r\n! XGK(1), XGK(3), ... abscissae optimally added\r\n! to the N-point Gauss rule.\r\n\r\n! WGK - weights of the 2N+1-point Kronrod rule.\r\n\r\n! WG - weights of the N-point Gauss rule.\r\n\r\nINTEGER :: j\r\nINTEGER, PARAMETER :: n = 11\r\n\r\nREAL (dp), PARAMETER :: wg(0:n/2) = (/ &\r\n 0.2729250867779007_dp, 0.05566856711617449_dp, 0.1255803694649048_dp, &\r\n 0.1862902109277352_dp, 0.2331937645919914_dp, 0.2628045445102478_dp /)\r\nREAL (dp), PARAMETER :: xgk(0:n) = (/ &\r\n 0.0000000000000000_dp, 0.9963696138895427_dp, 0.9782286581460570_dp, &\r\n 0.9416771085780681_dp, 0.8870625997680953_dp, 0.8160574566562211_dp, &\r\n 0.7301520055740492_dp, 0.6305995201619651_dp, 0.5190961292068118_dp, &\r\n 0.3979441409523776_dp, 0.2695431559523450_dp, 0.1361130007993617_dp /)\r\nREAL (dp), PARAMETER :: wgk(0:n) = (/ &\r\n 0.1365777947111183_dp, 0.9765441045961290D-02, 0.2715655468210443D-01, &\r\n 0.4582937856442671D-01, 0.6309742475037484D-01, 0.7866457193222764D-01, &\r\n 0.9295309859690074D-01, 0.1058720744813894_dp, 0.1167395024610472_dp, &\r\n 0.1251587991003195_dp, 0.1312806842298057_dp, 0.1351935727998845_dp /)\r\n\r\n! List of major variables\r\n\r\n! CENTER - mid point of the interval\r\n! HFLGTH - half-length of the interval\r\n! ABSCIS - abscissae\r\n! RESLTG - result of the N-point Gauss formula\r\n! RESLTK - result of the 2N+1-point Kronrod formula\r\n\r\nhflgth = ( b - a )/2\r\ncenter = ( b + a )/2\r\n\r\n! compute the 2N+1-point Kronrod approximation to\r\n! the integral, and estimate the absolute error.\r\n\r\nfc = f(center)\r\nresltg = fc*wg(0)\r\nresltk = fc*wgk(0)\r\nDO j = 1, n\r\n abscis = hflgth*xgk(j)\r\n funsum = f( center - abscis ) + f( center + abscis )\r\n resltk = resltk + wgk(j)*funsum\r\n IF( MOD( j, 2 ) == 0 ) resltg = resltg + wg(j/2)*funsum\r\nEND DO\r\nfn_val = resltk*hflgth\r\nabserr = 3*ABS( ( resltk - resltg )*hflgth )\r\n\r\nRETURN\r\nEND SUBROUTINE krnrdd\r\n\r\n\r\n\r\nFUNCTION phid(z) RESULT(fn_val)\r\n\r\n! Normal distribution probabilities accurate to 1.e-15.\r\n! Z = no. of standard deviations from the mean.\r\n! P, Q = probabilities to the left & right of Z. P + Q = 1.\r\n! PDF = the probability density.\r\n\r\n! Based upon algorithm 5666 for the error function, from:\r\n! Hart, J.F. et al, 'Computer Approximations', Wiley 1968\r\n\r\n! Programmer: Alan Miller, modified by Alan Genz\r\n\r\n! Latest revision of Fortran 77 version - 30 March 1986\r\n! Latest revision of Fortran 90 version - 23 June 1997\r\n\r\nIMPLICIT NONE\r\nINTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(12, 60)\r\nREAL (dp), INTENT(IN) :: z\r\nREAL (dp) :: fn_val\r\n\r\n! Local variables\r\nREAL (dp), PARAMETER :: p0 = 220.2068679123761_dp, p1 = 221.2135961699311_dp, &\r\n p2 = 112.0792914978709_dp, p3 = 33.91286607838300_dp, &\r\n p4 = 6.373962203531650_dp, p5 = .7003830644436881_dp, &\r\n p6 = 0.03526249659989109_dp, &\r\n q0 = 440.4137358247522_dp, q1 = 793.8265125199484_dp, &\r\n q2 = 637.3336333788311_dp, q3 = 296.5642487796737_dp, &\r\n q4 = 86.78073220294608_dp, q5 = 16.06417757920695_dp, &\r\n q6 = 1.755667163182642_dp, q7 = .8838834764831844D-1, &\r\n cutoff = 7.071067811865475_dp\r\n\r\nREAL (dp) :: zabs, expntl\r\n\r\nzabs = ABS(z)\r\n\r\n! |Z| > 37.\r\n\r\nIF (zabs > 37._dp) THEN\r\n fn_val = 0._dp\r\n ELSE\r\n\r\n! |Z| <= 37.\r\n\r\n expntl = EXP(-0.5_dp*zabs**2)\r\n\r\n! |Z| < CUTOFF = 10/sqrt(2).\r\n\r\n IF (zabs < cutoff) THEN\r\n fn_val = expntl*((((((p6*zabs + p5)*zabs + p4)*zabs + p3)*zabs + p2)*zabs &\r\n + p1)*zabs + p0) / (((((((q7*zabs + q6)*zabs + q5)*zabs &\r\n + q4)*zabs + q3)*zabs + q2)*zabs + q1)*zabs +q0)\r\n \r\n! |Z| >= CUTOFF.\r\n \r\n ELSE\r\n fn_val = expntl/(zabs + 1._dp/(zabs + 2._dp/(zabs + 3._dp/(zabs + &\r\n 4._dp/(zabs + 0.65_dp)))))\r\n END IF\r\nEND IF\r\n\r\nIF (z > 0.0_dp) fn_val = 1.0_dp - fn_val\r\n\r\nRETURN\r\nEND FUNCTION phid\r\n\r\nEND MODULE Bivariate_Trivariate_Normal\r\n", "meta": {"hexsha": "c7c492bdf799f21077eb78f51bec2554c0fc577c", "size": 16431, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/genz2d3d.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/genz2d3d.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/genz2d3d.f90", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 28.9278169014, "max_line_length": 86, "alphanum_fraction": 0.5551701053, "num_tokens": 6135, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797051879431, "lm_q2_score": 0.7431679972357831, "lm_q1q2_score": 0.677159596626415}} {"text": "MODULE group_theory\nuse utilities, only : ralloc\nimplicit none\nprivate\npublic grouper\n\nCONTAINS\n\n !!Generates a group from a list of generators\n !!Pass in 2D array where the rows are the permutations. The\n !!permutations will be taken in all possible pairs to generate new\n !!group elements. The array of elements will be added to until the\n !!list of permutations has closure and constitutes a group.\n !!Permutations are indexed 1..n, not 0..n-1\n !!On entry contains the\n !!generators, on exit contains the whole group \n subroutine grouper(g)\n integer, pointer:: g(:,:) \n\n integer :: nG ! Number of elements in the group (on exit)\n logical :: growing, new ! Flags: group is still being added to,\n ! new group element was found\n integer :: mG ! Number of elements already checked (don't need to be re-checked)\n integer :: ig, jg, kg, cg ! Generic loop variables\n integer :: n ! Number of permutation elements\n integer,allocatable :: newg(:), vs(:) ! permuted group element, vector subscript\n\n n = size(g,2) ! Number of permutation elements\n if (n<1) stop \"ERROR: Empty list passed to 'grouper' subroutine in 'group_theory' module (celib)\"\n allocate(newg(n),vs(n))\n if(any(g>n) .or. any(g<1)) then\n write(*,'(\"n: \",i4)') n\n write(*,'(\"g: \",5000(i3,1x))') \n stop \"ERROR: generators passed to 'grouper' (group_theory in celib) contain indices outside of 1..n\"\n endif\n growing = .true.\n mG = 0\n nG = size(g,1)\n do while (growing)\n growing = .false.\n g => ralloc(g,nG+nG**2,n) ! Make room for possible new elements\n ! when the existing elements are combined\n ! Loop over each pair of group elements...\n cg = 0 ! Keep track of the number of new elements of the group\n ! that have been found in this iteration\n do ig = 1, nG\n do jg = 1, nG\n if (ig <= mG .and. jg <= mG) cycle !...but skip those\n !already tested in a previous iteration\n ! Construct a permuted element, that is, multiply two group elements\n vs = g(jg,:) ! Make a vector subscript for the permuted element\n newg = g(ig,vs) ! Permute the element\n ! Is this new g unique in the list of existing group elements?\n new = .true.\n newcheck: do kg = 1, nG+cg\n if (all(newg == g(kg,:))) then\n new = .false.\n exit newcheck\n endif\n enddo newcheck\n if (new) then\n growing = .true.\n cg = cg + 1\n g(nG+cg,:) = newg\n end if\n end do\n end do ! Loops over pairs\n mG = nG\n nG = nG + cg\n end do ! Loop for group still growing\n g => ralloc(g,nG,n)\n end subroutine grouper\nEND MODULE group_theory\n", "meta": {"hexsha": "4a56750b64eab96e083b53b735913ccb8a71fcc7", "size": 2941, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/group_theory.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/group_theory.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/group_theory.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": 39.7432432432, "max_line_length": 107, "alphanum_fraction": 0.602516151, "num_tokens": 794, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835452961425, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.6771417939159351}} {"text": "!>\nmodule m_integrate\n\n implicit none\n\ncontains\n\n function integrate_trapezoid (n, x, f) result (integral)\n integer , intent(in) :: n\n double precision , intent(in) :: x(n), f(n)\n double precision :: w(n)\n double precision :: integral\n integer :: ii\n integer :: status\n\n ! check if arguments are valid\n status = 0\n\n if (n < 2) then\n status = 1\n end if\n\n ! terminate subroutine if arguments are invalid, otherwise, proceed\n if (status /= 0) then\n integral = 0.0d0\n return\n end if\n\n ! calculate weights\n w(1) = (x(2) - x(1)) / 2.0d0\n\n do ii = 2, n-1\n w(ii) = (x(ii+1) - x(ii-1)) / 2.0d0\n end do\n\n w(n) = (x(n) - x(n-1)) / 2.0d0\n\n ! calculate integral\n integral = 0.0d0\n\n do ii = 1, n\n integral = integral + (w(ii) * f(ii))\n end do\n\n end function integrate_trapezoid\n\nend module m_integrate\n", "meta": {"hexsha": "ae7ea6d367cc6a1cf393a2d21cda2a09062bda13", "size": 882, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "src/m_integrate.f08", "max_stars_repo_name": "dgsaf/acqm-workshop-3", "max_stars_repo_head_hexsha": "07e1691710778f4225e5e058ad2d5cf6c0b89758", "max_stars_repo_licenses": ["MIT"], "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/m_integrate.f08", "max_issues_repo_name": "dgsaf/acqm-workshop-3", "max_issues_repo_head_hexsha": "07e1691710778f4225e5e058ad2d5cf6c0b89758", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/m_integrate.f08", "max_forks_repo_name": "dgsaf/acqm-workshop-3", "max_forks_repo_head_hexsha": "07e1691710778f4225e5e058ad2d5cf6c0b89758", "max_forks_repo_licenses": ["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.375, "max_line_length": 71, "alphanum_fraction": 0.5725623583, "num_tokens": 299, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835289107307, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.6771417825482098}} {"text": "program test_dot_product\n\n write (*, '(i0)') dot_product ((/1, 3, -5/), (/4, -2, -1/))\n\nend program test_dot_product\n", "meta": {"hexsha": "09d9c4fcea27e04ee6e2165b34e61013aef32ca5", "size": 118, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Dot-product/Fortran/dot-product.f", "max_stars_repo_name": "djgoku/RosettaCodeData", "max_stars_repo_head_hexsha": "91df62d46142e921b3eacdb52b0316c39ee236bc", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Dot-product/Fortran/dot-product.f", "max_issues_repo_name": "djgoku/RosettaCodeData", "max_issues_repo_head_hexsha": "91df62d46142e921b3eacdb52b0316c39ee236bc", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Dot-product/Fortran/dot-product.f", "max_forks_repo_name": "djgoku/RosettaCodeData", "max_forks_repo_head_hexsha": "91df62d46142e921b3eacdb52b0316c39ee236bc", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 19.6666666667, "max_line_length": 61, "alphanum_fraction": 0.6186440678, "num_tokens": 43, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9381240090865197, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6770846358377204}} {"text": " subroutine clawpack46_src2(maxmx,maxmy,meqn,mbc,mx,my,\n & xlower,ylower,dx,dy,q,maux,aux,t,dt)\nc =========================================================\n implicit double precision(a-h,o-z)\n dimension q(1-mbc:maxmx+mbc, 1-mbc:maxmy+mbc, meqn)\n dimension aux(1-mbc:maxmx+mbc, 1-mbc:maxmy+mbc, maux)\nc\nc # source terms for cylindrical symmetry in 2d Euler equations\nc # about y = 0, so radius = y\nc # y value at cell center is stored in aux(i,j,1)\nc\n dimension qstar(4)\n common /cparam/ gamma,gamma1\nc\nc # 2-stage Runge-Kutta method\nc\n dt2 = dt/2.d0\n press = 0.d0\n ndim = 2\n\n do 10 i=1,mx\n do 10 j=1,my\n rad = aux(i,j,1)\n rho = q(i,j,1)\n u = q(i,j,2)/q(i,j,1)\n v = q(i,j,3)/q(i,j,1)\n press = gamma1*(q(i,j,4) - 0.5d0*rho*(u**2 + v**2))\n\n if (rad.eq.0.d0) write(6,*) 'rad = 0 in src2'\n if (rho.eq.0.d0) write(6,*) 'rho = 0 in q'\n\n qstar(1) = q(i,j,1) - dt2*(ndim-1)/rad * q(i,j,3)\n qstar(2) = q(i,j,2) - dt2*(ndim-1)/rad *\n & (rho*u*v)\n qstar(3) = q(i,j,3) - dt2*(ndim-1)/rad *\n & (rho*v*v)\n qstar(4) = q(i,j,4) - dt2*(ndim-1)/rad *\n & v*(q(i,j,4) + press)\nc\nc # second stage\nc\n rho = qstar(1)\n u = qstar(2)/qstar(1)\n v = qstar(3)/qstar(1)\n press = gamma1*(qstar(4) - 0.5d0*rho*(u**2 + v**2))\n if (rho.eq.0.d0) write(6,*) 'rho = 0 in qstar'\n\n q(i,j,1) = q(i,j,1) - dt*(ndim-1)/rad * qstar(3)\n q(i,j,2) = q(i,j,2) - dt*(ndim-1)/rad *\n & (rho*u*v)\n q(i,j,3) = q(i,j,3) - dt*(ndim-1)/rad *\n & (rho*v*v)\n q(i,j,4) = q(i,j,4) - dt*(ndim-1)/rad *\n & v*(qstar(4) + press)\n 10 continue\n\n return\n end\n", "meta": {"hexsha": "08e6a6ffcf875ac7ee071b056809942c8f7ee1da", "size": 1988, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "applications/clawpack/euler/2d/shockbubble/user_4.6/src2.f", "max_stars_repo_name": "scivision/forestclaw", "max_stars_repo_head_hexsha": "4dae847a8abd1055e70acda9c2973cd3dd77d3f1", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-09T23:06:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-09T23:06:42.000Z", "max_issues_repo_path": "applications/clawpack/euler/2d/shockbubble/user_4.6/src2.f", "max_issues_repo_name": "scottaiton/forestclaw", "max_issues_repo_head_hexsha": "2abaab636e6e93f5507a6f231490144a3f805b59", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "applications/clawpack/euler/2d/shockbubble/user_4.6/src2.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": 33.6949152542, "max_line_length": 67, "alphanum_fraction": 0.4149899396, "num_tokens": 748, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802484881361, "lm_q2_score": 0.7371581626286833, "lm_q1q2_score": 0.6770652123862508}} {"text": "!*********************************************************************\t\r\n SUBROUTINE mass_bal(var,outflow,conc)\r\n!*********************************************************************\t\r\n\t! jday - julian day of the mass ballance calculation\r\n\t! lakemass - mass of variable in the lake\r\n\t! inmass - mass of variable in the inflow stack\r\n\t! outmass - mass of variable in the outflow\r\n!*********************************************************************\t\r\n USE DLMWQ_VARIABLES \r\n USE DLMWQ_SERVICES\r\n\t\tIMPLICIT NONE\r\n SAVE\r\n\r\n\t\tINTEGER*4:: i,var,k,ntot\r\n\t\tREAL*8:: lakemass, inmass, outmass, massbal, outflow, conc\r\n\r\n\t! calculate the mass in the lake\r\n\t\tlakemass=0.0d0\r\n\t\tDO i=1,ns\r\n\t\t\tlakemass=lakemass+wqual(i,var)*vol(i)\t\t! integrate lake mass\r\n\t\tENDDO\r\n\r\n\t!Calculate the mass in the inflow stack\r\n\t\tDO i=1,numinf\r\n!\t\tinmass = inmass+floinf(i)*wqual(i,var)\t\t! add in the inflow masses\r\n\t\t\tDO k=1,icnt(i)\r\n\t\t\t\tinmass = qdown(i,k)*wqdown(i,var,k)\t\t! add in inlfow masses including stacks\r\n\t\t\tENDDO\r\n\t\tENDDO\r\n\r\n!Calculate the mass in the outflow\r\n\t\toutmass = outflow*conc\t\t\t\t\t\t\t! add up outflow masses\r\n\r\n\t\tmassbal = lakemass-outmass+inmass\t\t\t\t! total the mass balance for the step\r\n\r\n\r\n!\t\tWRITE(83,94)jday,nosecs,lakemass,outmass,massbal\r\n94\t\tFORMAT(2I10,3F16.4)\r\n\r\n\t\tEND SUBROUTINE mass_bal\r\n\t\r\n!*********************************************************************\t\r\n SUBROUTINE h2o_bal(outflow)\r\n!*********************************************************************\t\r\n\t! jday - julian day of the mass ballance calculation\r\n\t! lakemass - mass of variable in the lake\r\n\t! inmass - mass of variable in the inflow stack\r\n\t! outmass - mass of variable in the outflow\r\n!*********************************************************************\t\r\n USE DLMWQ_VARIABLES \r\n USE DLMWQ_SERVICES\r\n\t\tIMPLICIT NONE\r\n SAVE\r\n\r\n\t\tINTEGER*4:: i,k,ntot\r\n\t\tREAL*8:: lakemass, inmass, outmass, massbal, outflow\r\n\r\n!\t\tcalculate the mass in the lake\r\n\t\tlakemass=0.0d0\r\n\t\tDO i=1,ns\r\n\t\t\tlakemass=lakemass+vol(i)\t\t! integrate lake mass\r\n\t\tENDDO\r\n\r\n!\t\tCalculate the mass in the inflow stack\r\n\t\tDO i=1,numinf\r\n!\t\tinmass = inmass+floinf(i)*wqual(i,var)\t\t! add in the inflow masses\r\n\t\t\tinmass=0.0d0\r\n\t\t\tDO k=1,icnt(i)\r\n\t\t\t\tinmass = inmass+qdown(i,k)\t\t! add in inlfow masses including stacks\r\n\t\t\tENDDO\r\n\t\tENDDO\r\n\r\n!\t\tCalculate the mass in the outflow\r\n\r\n\t\toutmass=outflow\r\n\t\tmassbal = lakemass-outmass+inmass\t\t\t\t! total the mass balance for the step\r\n\r\n\r\n!\t\tWRITE(83,94)jday,lakemass,inmass,outmass,massbal\r\n94\t\tFORMAT(I10,4F16.4)\r\n\t\tEND SUBROUTINE h2o_bal\r\n!*********************************************************************\t\r\n!*********************************************************************\t\r\n\t\tSUBROUTINE injection(var,conc,top,bottom)\r\n!*********************************************************************\t\r\n\t! var - variable to inject\r\n\t! conc - concentration of variable to inject\r\n\t! top - depth from surface of top of injection layer\r\n\t! bottom - depth from surface of bottom of injection layer\r\n!*********************************************************************\t\r\n USE DLMWQ_VARIABLES \r\n USE DLMWQ_SERVICES\r\n\t\tIMPLICIT NONE\r\n SAVE\r\n\r\n\t\tINTEGER*4:: i,var,ntop,nbottom\r\n\t\tREAL*8:: conc,top,bottom\r\n\r\n!find layers where top and bottom of injection occur\r\n\t\tnbottom=0\t\t\t\t\t\t\t! start with finding the bottom layer\r\n\t\tIF (bottom == depth(ns)) THEN\r\n\t\t\tnbottom = 1\t\t\t\t\t\t! nbottom is the bottom layer\r\n\t\tELSE\r\n\t\t\tDO WHILE ((depth(ns)-depth(ns-nbottom-1))\n ! Utilities for Gaussian quadrature.\n ! This module provides subroutines to obtain zeros and weights of\n ! Gauss-Legendre and Gauss-Laguerre quadrature rules.\n ! \n\n implicit none\n\n public :: get_legendre_grids_from_cheb\n public :: get_laguerre_grids\n\n private\n\n logical :: debug = .false.\n logical :: weight_roundoff_correction = .false.\n\n integer, parameter :: qp = selected_real_kind(33, 4931)\n\ncontains\n\n subroutine get_legendre_grids_from_cheb(x1, x2, zero, wgt)\n\n ! \n ! returns Legendre zeros and weights in the given interval [x1,x2].\n ! The order is determined from the size of the array 'zero'.\n ! \n\n use constants, only: pi => dpi\n real, intent(in) :: x1, x2\n real, dimension(:), intent(out) :: zero, wgt\n integer :: i, nn, nh\n double precision :: xold, xnew, pold, pnew\n double precision, dimension(:), allocatable :: zz, ww\n\n nn = size(zero)\n nh = (nn + 1) / 2\n allocate (zz(nh))\n allocate (ww(nh))\n\n ! search zero from 1 to 0 using chebyshev grid points\n ! this is O(nn^2) operations\n xold = cos(pi / (2 * (nn + 1)))\n pold = legendre_p(nn, xold)\n do i = 1, nh\n xnew = cos(pi * (2 * i + 1) / (2 * (nn + 1)))\n pnew = legendre_p(nn, xnew)\n call find_zero_bisect_newton(nn, xold, xnew, pold, pnew, zz(i))\n xold = xnew\n pold = pnew\n end do\n ! invert them to give zeros in (-1,0]\n zz(1:nn / 2) = -zz(1:nn / 2)\n\n ! weight from formula\n! ww = dble(2.0) / (dble(1.0) - zz**2) / legendre_pp(nn,zz,dble(0.0))**2\n ww = dble(2.0) / (dble(1.0) - zz**2) / legendre_pp(nn, zz)**2\n\n ! rescale (x2 may be smaller than x1)\n zero(1:nh) = real(zz * (x2 - x1) + (x1 + x2)) / 2.0\n zero(nh + 1:nn) = real(zz(nn / 2:1:-1) * (x1 - x2) + (x1 + x2)) / 2.0\n wgt(1:nh) = real(ww * abs(x2 - x1) / 2.0)\n wgt(nh + 1:nn) = wgt(nn / 2:1:-1)\n\n deallocate (zz)\n deallocate (ww)\n\n ! roundoff correction\n!!$ if (abs(sum(wgt)/abs(x2-x1)) - 1.0 > epsilon(wgt)) then\n!!$ print *, 'roundoff correction occurred'\n if (weight_roundoff_correction) then\n if (mod(nn, 2) == 0) then\n wgt(nh) = abs(x2 - x1) / 2.0 - sum(wgt(1:nh - 1))\n wgt(nh + 1) = wgt(nh)\n else\n wgt(nh) = abs(x2 - x1) - sum(wgt(1:nh - 1)) * 2.0\n end if\n end if\n\n call check_legendre_zero(x1, x2, zero)\n call check_legendre_weights(abs(x2 - x1), wgt)\n\n if (debug) then\n print *, 'get_legendre_grids_from_cheb: sum of weights = ', sum(wgt)\n print *, 'get_legendre_grids_from_cheb: section length = ', abs(x2 - x1)\n end if\n\n end subroutine get_legendre_grids_from_cheb\n\n subroutine find_zero_bisect_newton(n, xold, xnew, pold, pnew, zz)\n\n use file_utils, only: error_unit\n integer, intent(in) :: n\n double precision, intent(in) :: xold, xnew, pold, pnew\n! real, intent (in) :: eps\n double precision, intent(out) :: zz\n integer :: i, maxit = 100\n real :: eps\n double precision :: x1, x2, p1, p2, pz\n\n ! \n ! eps is declared as real on purpose.\n ! We don't require higher order precision for convergence test\n ! because of a performance reason. The following definition means\n ! eps is a geometric mean of the machine-epsilons in real and double\n ! precisions.\n ! (note that real/double are promoted to double/double or double/quad\n ! depending on the compiler.)\n !\n ! [same applies to eps in find_zero below.]\n ! \n\n eps = sqrt(epsilon(eps) * epsilon(x1)) * 2.0\n i = 0\n x1 = xold\n x2 = xnew\n p1 = pold\n p2 = pnew\n\n if (debug) write (*, '(4f10.5)') x1, p1, x2, p2\n\n ! bisection\n do i = 1, 5\n zz = (x1 + x2) * dble(.5)\n pz = legendre_p(n, zz)\n if (abs(pz) <= epsilon(pz)) return\n if (pz * p1 < 0.0) then\n p2 = pz; x2 = zz\n else\n p1 = pz; x1 = zz\n end if\n if (debug) write (*, '(4f10.5)') x1, p1, x2, p2\n end do\n\n if (debug) print *, 'finished bisection'\n\n ! newton-raphson\n if (zz == x1) x1 = x2\n! do while (abs(zz/x1-1.0) > eps)\n do i = 1, maxit\n x1 = zz\n p1 = legendre_p(n, x1)\n! zz = x1 - p1 / legendre_pp(n,x1,p1)\n zz = x1 - p1 / legendre_pp(n, x1)\n pz = legendre_p(n, zz)\n if (debug) write (*, '(4f10.5)') zz, pz, x1, p1\n if (min(abs(zz / x1 - 1.0), abs(pz)) < eps) exit\n end do\n\n if (i == maxit + 1) write (error_unit(), *) &\n & 'WARNING: too many iterations in get_legendre_grids'\n\n if (debug) stop\n\n end subroutine find_zero_bisect_newton\n\n elemental function legendre_p(n, x)\n\n integer, intent(in) :: n\n double precision, intent(in) :: x\n integer :: k\n double precision :: p, p1, p2, legendre_p\n\n select case (n)\n case (0)\n legendre_p = dble(1.0)\n case (1)\n legendre_p = x\n case default\n p1 = x\n p2 = dble(1.0)\n do k = 2, n\n p = ((2 * k - 1) * x * p1 - (k - 1) * p2) / k\n p2 = p1\n p1 = p\n end do\n legendre_p = p\n end select\n\n end function legendre_p\n\n! elemental function legendre_pp (n, x, p1)\n elemental function legendre_pp(n, x)\n\n integer, intent(in) :: n\n double precision, intent(in) :: x\n! double precision, intent (in), optional :: p1\n double precision :: legendre_pp\n\n! if (present(p1)) then\n! legendre_pp = n * ( x * p1 - legendre_p(n-1,x) ) &\n! / (x**2 - dble(1.0))\n! else\n legendre_pp = n * (x * legendre_p(n, x) - legendre_p(n - 1, x)) &\n / (x**2 - dble(1.0))\n! end if\n\n end function legendre_pp\n\n subroutine check_legendre_zero(x0, x1, zero)\n\n use mp, only: mp_abort\n use file_utils, only: error_unit\n real, intent(in) :: x0, x1\n real, dimension(:), intent(in) :: zero\n logical :: error = .false.\n integer :: nn, nh\n real :: xx, xmin, xmax\n real, dimension(:), allocatable :: zz\n\n nn = size(zero)\n nh = (nn + 1) / 2\n error = .false.\n xmin = min(x0, x1)\n xmax = max(x0, x1)\n allocate (zz(nn))\n zz = zero\n if (zz(1) > zz(nn)) zz(1:nn) = zero(nn:1:-1)\n if (zz(1) < xmin .or. zz(nn) > xmax) then\n write (error_unit(), *) 'ERROR in legendre: grid out of range'\n error = .true.\n end if\n\n if (nn == 1) then\n if (abs(2.0 * zz(1) / (xmin + xmax) - 1.0) > epsilon(0.0)) then\n write (error_unit(), '(\"ERROR in legendre: zz(1)= \", f20.15)') zz(1)\n error = .true.\n end if\n else\n ! check if distances at the edge: This suffices for nn<=3\n if (zz(2) - zz(1) <= zz(1) - xmin .or. zz(nn) - zz(nn - 1) <= xmax - zz(nn)) then\n write (error_unit(), *) 'ERROR in legendre: wrong distance at edge'\n error = .true.\n end if\n ! check distances at the center: The above and this suffices for nn=4\n if (mod(nn, 2) == 0 .and. nn >= 4) then\n if (zz(nh + 1) - zz(nh) <= zz(nh) - zz(nh - 1) .or. &\n zz(nh + 1) - zz(nh) <= zz(nh + 2) - zz(nh + 1)) then\n write (error_unit(), *) &\n & 'ERROR in legendre: wrong distance at center'\n error = .true.\n end if\n end if\n if (nn >= 5) then\n ! check if distances are increasing toward center\n ! lower half\n if (any(zz(3:nh) - zz(2:nh - 1) <= zz(2:nh - 1) - zz(1:nh - 2))) then\n write (error_unit(), *) 'ERROR in legendre: distance decreasing toward center'\n error = .true.\n end if\n ! upper half\n ! The separate use of nh and nn/2 are intentionally so that they\n ! both work for even and odd cases\n if (any(zz(nn / 2 + 2:nn - 1) - zz(nn / 2 + 1:nn - 2) &\n & <= zz(nn / 2 + 3:nn) - zz(nn / 2 + 2:nn - 1))) then\n write (error_unit(), *) 'ERROR in legendre: distance decreasing toward center'\n error = .true.\n end if\n end if\n\n end if\n\n ! check if legendre_p(n, zero(i)) are close enough to zero\n if (debug) then\n xx = maxval(abs(real(legendre_p(nn, &\n dble((zz(:) - xmin) / (xmax - xmin) * 2.0 - 1.0)))))\n if (xx / nn**2 > epsilon(xx)) then\n write (error_unit(), *) 'WARNING in legendre: maxval(n,zz(:))= ', xx\n ! Do not stop as it is mostly a minor issue\n end if\n end if\n\n if (error) call mp_abort('STOP in check_legendre_zero')\n\n end subroutine check_legendre_zero\n\n! subroutine check_legendre_weights (norm, wgt, eps)\n subroutine check_legendre_weights(norm, wgt)\n\n use mp, only: mp_abort\n use file_utils, only: error_unit\n real, intent(in) :: norm!, eps\n real, dimension(:), intent(in) :: wgt\n logical :: error = .false.\n integer :: n, nh\n real :: s\n\n n = size(wgt)\n error = .false.\n nh = (n + 1) / 2\n\n ! check if weights are all positive\n if (any(wgt < 0.)) then\n write (error_unit(), *) 'ERROR in legendre: weights got negative'\n error = .true.\n end if\n\n if (n >= 2) then\n ! check symmetry of weights\n if (any(abs(wgt(n:n + 1 - n / 2:-1) / wgt(1:n / 2) - 1.0) > epsilon(wgt))) then\n write (error_unit(), *) 'WARNING in legendre: symmetry of weights broken'\n error = .true.\n end if\n\n ! check if weights are increasing toward center\n if (n >= 3) then\n if (any(wgt(2:nh) <= wgt(1:nh - 1))) then\n write (error_unit(), *) 'ERROR in legendre: weights decreasing toward center'\n error = .true.\n end if\n end if\n end if\n\n ! check if their sum is close enough to normalized value\n if (debug) then\n! s = sum(wgt)\n s = sum(dble(wgt)) ! ignore roundoff error arising from 8-byte summation\n if (abs(norm / s - 1.0) > epsilon(s)) then\n write (error_unit(), *) 'WARNING in legendre: weights summation incorrect:', &\n & size(wgt), s / norm - 1.0\n ! Do not stop as it is mostly a minor issue\n end if\n end if\n\n if (error) call mp_abort('STOP in check_legendre_weights')\n\n end subroutine check_legendre_weights\n\n subroutine get_laguerre_grids(zero, wgt)\n\n ! \n ! returns Laguerre zeros and weights.\n ! The order is determined from the size of the array 'zero'.\n ! \n\n use mp, only: mp_abort\n use file_utils, only: error_unit\n real, dimension(:), intent(out) :: zero\n real, dimension(:), intent(out) :: wgt\n logical :: error = .false.\n integer :: i, j, n, nzero\n real(kind=qp) :: x, delx, pold, pnew\n !double precision, dimension (:), allocatable :: zz\n real(kind=qp), dimension(:), allocatable :: zz\n double precision :: eps\n\n n = size(zero)\n allocate (zz(n))\n zz = 0.0\n\n eps = epsilon(zero(1)) * dble(4.0)\n\n if (n > 180) then\n write (error_unit(), *) 'ERROR: can''t get so many laguerre grid points'\n write (error_unit(), *) 'ERROR: size(zero)= ', n\n error = .true.\n end if\n\n ! search zero from 0 to xmax using evenly spaced grid points\n if (n == 1) then\n\n zero(1) = 1.0\n wgt(1) = 1.0\n return\n\n else\n\n nzero = 0\n pold = real(laguerre_l(n, real(0.0, qp)), qp)\n delx = 0.001\n do i = 1, 1000 ! up to x=1\n x = delx * i\n! print*, x\n pnew = real(laguerre_l(n, x), qp)\n! if (pold*pnew < epsilon(0.0)) then\n if (pold * pnew < 0.0) then\n nzero = nzero + 1\n call find_zero(n, eps, x - delx, x, pold, pnew, zz(nzero))\n end if\n pold = pnew\n end do\n\n do j = 0, 3\n delx = delx * 10.\n do i = 1, 900\n x = delx * (i + 100)\n! print*, x\n pnew = laguerre_l(n, x)\n if (pold * pnew < 0.0) then\n nzero = nzero + 1\n call find_zero(n, eps, x - delx, x, pold, pnew, zz(nzero))\n end if\n if (nzero == n) exit\n pold = pnew\n end do\n if (nzero == n) exit\n end do\n\n end if\n\n zero = real(zz, kind(zero(1)))\n wgt = real(zz / (n + 1)**2 / laguerre_l(n + 1, zz)**2, kind(wgt(1)))\n\n deallocate (zz)\n\n ! roundoff correction\n if (weight_roundoff_correction) then\n i = sum(maxloc(wgt))\n wgt(i) = 1.0 - sum(wgt(1:i - 1)) - sum(wgt(i + 1:n))\n end if\n\n ! check number of found zeros\n if (nzero < n) then\n write (error_unit(), *) 'ERROR in laguerre: didn''t find all zeros'\n do i = 1, n\n write (error_unit(), *) i, zero(i)\n end do\n stop\n end if\n\n call check_laguerre_zeros(zero)\n call check_laguerre_weights(wgt, eps=1.0e-7)\n\n if (error) call mp_abort('STOP in get_laguerre_grids')\n\n end subroutine get_laguerre_grids\n\n subroutine find_zero(n, eps, xold, xnew, pold, pnew, zz)\n\n use file_utils, only: error_unit\n integer, intent(in) :: n\n double precision, intent(in) :: eps\n real(kind=qp), intent(in) :: xold, xnew, pold, pnew\n !double precision, intent (out) :: zz\n real(kind=qp), intent(out) :: zz\n integer :: i, maxit = 100\n real(kind=qp) :: x1, x2, p1, p2, pz\n\n ! \n ! eps is declared as real on purpose.\n ! [see comment in find_zero_bisect_newton above.]\n ! \n\n x1 = xold\n x2 = xnew\n p1 = pold\n p2 = pnew\n\n if (debug) write (*, '(a,4es15.5e3)') 'initial ', x1, p1, x2, p2\n\n ! bisection\n do i = 1, maxit\n zz = (x1 + x2) * 0.5\n pz = laguerre_l(n, zz)\n if (abs(pz) <= eps) return\n if (pz * p1 < 0.) then\n p2 = pz; x2 = zz\n else\n p1 = pz; x1 = zz\n end if\n if (debug) write (*, '(a,6es25.15e3)') 'bisection ', x1, p1, x2, p2, pz, eps\n end do\n\n if (i == maxit + 1) then\n ! newton-raphson\n if (zz == x1) x1 = x2\n do i = 1, maxit\n x1 = zz\n p1 = dble(laguerre_l(n, x1))\n zz = x1 - p1 / dble(laguerre_lp(n, x1))\n pz = dble(laguerre_l(n, zz))\n if (debug) write (*, '(a,5es25.15e3)') &\n 'newton ', zz, pz, x1, p1, eps\n if (min(abs(zz / x1 - dble(1.0)), abs(pz)) < eps) exit\n end do\n\n if (i == maxit + 1) then\n write (error_unit(), *) &\n & 'WARNING: too many iterations in get_laguerre_grids'\n\n stop 11\n end if\n end if\n\n end subroutine find_zero\n\n elemental function laguerre_l(n, x)\n\n integer, intent(in) :: n\n real(kind=qp), intent(in) :: x\n integer :: k\n! double precision :: laguerre_l, p, p1, p2\n real(kind=qp) :: laguerre_l, p, p1, p2\n\n p1 = dble(1.0) - x\n p2 = dble(1.0)\n\n if (n == 0) then\n laguerre_l = p2\n return\n else if (n == 1) then\n laguerre_l = p1\n return\n end if\n\n do k = 2, n\n p = ((dble(2.0) * k - dble(1.0) - x) * p1 - (k - dble(1.0)) * p2) / k\n p2 = p1\n p1 = p\n end do\n\n laguerre_l = p\n\n end function laguerre_l\n\n elemental function laguerre_lp(n, x)\n\n integer, intent(in) :: n\n real(kind=qp), intent(in) :: x\n real(kind=qp) :: laguerre_lp\n\n laguerre_lp = n * (laguerre_l(n, x) - laguerre_l(n - 1, x)) / x\n\n end function laguerre_lp\n\n subroutine check_laguerre_zeros(zero)\n\n use file_utils, only: error_unit\n use mp, only: mp_abort\n real, dimension(:), intent(in) :: zero\n logical :: error = .false.\n integer :: i, n\n\n n = size(zero)\n\n ! check positiveness\n if (any(zero <= 0.0)) then\n write (error_unit(), *) 'ERROR in laguerre: grid not positive'\n error = .true.\n end if\n\n ! check alignment\n if (any(zero(2:n) - zero(1:n - 1) < 0.0)) then\n write (error_unit(), *) 'ERROR in laguerre: wrong alignment'\n error = .true.\n end if\n\n ! check distances are increasing\n do i = 1, n - 2\n if (zero(i + 1) - zero(i) > zero(i + 2) - zero(i + 1)) then\n write (error_unit(), *) 'ERROR in laguerre: distances are decreasing at i= ', i\n error = .true.\n end if\n end do\n\n if (error) call mp_abort('STOP in check_laguerre_zeros')\n\n end subroutine check_laguerre_zeros\n\n subroutine check_laguerre_weights(wgt, eps)\n\n use file_utils, only: error_unit\n use mp, only: mp_abort\n real, intent(in) :: eps\n real, dimension(:), intent(in) :: wgt\n logical :: error = .false.\n integer :: imax, n\n real :: s\n\n n = size(wgt)\n\n ! check if weights are all positive\n if (any(wgt <= 0.0)) then\n write (error_unit(), *) 'ERROR in laguerre: weights are not positive at n =', n\n error = .true.\n end if\n\n ! check if there is a single maximum\n imax = sum(maxloc(wgt))\n if (any(wgt(1:imax - 1) > wgt(2:imax))) then\n write (error_unit(), *) 'ERROR in laguerre: weights decreasing before maximum'\n error = .true.\n end if\n if (any(wgt(imax:n - 1) < wgt(imax + 1:n))) then\n write (error_unit(), *) 'ERROR in laguerre: weights increasing after maximum'\n error = .true.\n end if\n\n ! check if their sum is close enough to normalized value\n if (debug) then\n s = sum(dble(wgt))\n if (abs(s - 1.0) > eps) then\n write (error_unit(), *) 'WARNING in laguerre: weights summation incorrect:', &\n size(wgt), s\n ! Do not stop as it is mostly a minor issue\n end if\n end if\n\n if (error) call mp_abort('STOP error in check_laguerre_weights')\n\n end subroutine check_laguerre_weights\n\nend module gauss_quad\n", "meta": {"hexsha": "3ccbbf9566fcce70e15f6588fd4a5e437aacbf1f", "size": 18337, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "utils/gauss_quad.f90", "max_stars_repo_name": "AntonioG-Jerez/stella", "max_stars_repo_head_hexsha": "b9d0257ea3639218b7546116c1235ebd4a8e0752", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-12-15T08:23:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T15:14:42.000Z", "max_issues_repo_path": "utils/gauss_quad.f90", "max_issues_repo_name": "AntonioG-Jerez/stella", "max_issues_repo_head_hexsha": "b9d0257ea3639218b7546116c1235ebd4a8e0752", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 37, "max_issues_repo_issues_event_min_datetime": "2021-07-05T16:41:33.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T15:58:05.000Z", "max_forks_repo_path": "utils/gauss_quad.f90", "max_forks_repo_name": "AntonioG-Jerez/stella", "max_forks_repo_head_hexsha": "b9d0257ea3639218b7546116c1235ebd4a8e0752", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2021-07-05T15:35:55.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-09T09:23:42.000Z", "avg_line_length": 30.3090909091, "max_line_length": 93, "alphanum_fraction": 0.5197687735, "num_tokens": 5889, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778257, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.6768366486158505}} {"text": "*DECK C9LN2R\n COMPLEX FUNCTION C9LN2R (Z)\nC***BEGIN PROLOGUE C9LN2R\nC***SUBSIDIARY\nC***PURPOSE Evaluate LOG(1+Z) from second order relative accuracy so\nC that LOG(1+Z) = Z - Z**2/2 + Z**3*C9LN2R(Z).\nC***LIBRARY SLATEC (FNLIB)\nC***CATEGORY C4B\nC***TYPE COMPLEX (R9LN2R-S, D9LN2R-D, C9LN2R-C)\nC***KEYWORDS ELEMENTARY FUNCTIONS, FNLIB, LOGARITHM, SECOND ORDER\nC***AUTHOR Fullerton, W., (LANL)\nC***DESCRIPTION\nC\nC Evaluate LOG(1+Z) from 2-nd order with relative error accuracy so\nC that LOG(1+Z) = Z - Z**2/2 + Z**3*C9LN2R(Z).\nC\nC Now LOG(1+Z) = 0.5*LOG(1+2*X+ABS(Z)**2) + I*CARG(1+Z),\nC where X = REAL(Z) and Y = AIMAG(Z).\nC We find\nC Z**3 * C9LN2R(Z) = -X*ABS(Z)**2 - 0.25*ABS(Z)**4\nC + (2*X+ABS(Z)**2)**3 * R9LN2R(2*X+ABS(Z)**2)\nC + I * (CARG(1+Z) + (X-1)*Y)\nC The imaginary part must be evaluated carefully as\nC (ATAN(Y/(1+X)) - Y/(1+X)) + Y/(1+X) - (1-X)*Y\nC = (Y/(1+X))**3 * R9ATN1(Y/(1+X)) + X**2*Y/(1+X)\nC\nC Now we divide through by Z**3 carefully. Write\nC 1/Z**3 = (X-I*Y)/ABS(Z)**3 * (1/ABS(Z)**3)\nC then C9LN2R(Z) = ((X-I*Y)/ABS(Z))**3 * (-X/ABS(Z) - ABS(Z)/4\nC + 0.5*((2*X+ABS(Z)**2)/ABS(Z))**3 * R9LN2R(2*X+ABS(Z)**2)\nC + I*Y/(ABS(Z)*(1+X)) * ((X/ABS(Z))**2 +\nC + (Y/(ABS(Z)*(1+X)))**2 * R9ATN1(Y/(1+X)) ) )\nC\nC If we let XZ = X/ABS(Z) and YZ = Y/ABS(Z) we may write\nC C9LN2R(Z) = (XZ-I*YZ)**3 * (-XZ - ABS(Z)/4\nC + 0.5*(2*XZ+ABS(Z))**3 * R9LN2R(2*X+ABS(Z)**2)\nC + I*YZ/(1+X) * (XZ**2 + (YZ/(1+X))**2*R9ATN1(Y/(1+X)) ))\nC\nC***REFERENCES (NONE)\nC***ROUTINES CALLED R9ATN1, R9LN2R\nC***REVISION HISTORY (YYMMDD)\nC 780401 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890531 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900720 Routine changed from user-callable to subsidiary. (WRB)\nC***END PROLOGUE C9LN2R\n COMPLEX Z\nC***FIRST EXECUTABLE STATEMENT C9LN2R\n X = REAL (Z)\n Y = AIMAG (Z)\nC\n CABSZ = ABS(Z)\n IF (CABSZ.GT.0.8125) GO TO 20\nC\n C9LN2R = CMPLX (1.0/3.0, 0.0)\n IF (CABSZ.EQ.0.0) RETURN\nC\n XZ = X/CABSZ\n YZ = Y/CABSZ\nC\n ARG = 2.0*XZ + CABSZ\n RPART = 0.5*ARG**3*R9LN2R(CABSZ*ARG) - XZ - 0.25*CABSZ\n Y1X = YZ/(1.0+X)\n AIPART = Y1X * (XZ**2 + Y1X**2*R9ATN1(CABSZ*Y1X) )\nC\n C9LN2R = CMPLX(XZ,-YZ)**3 * CMPLX(RPART,AIPART)\n RETURN\nC\n 20 C9LN2R = (LOG(1.0+Z) - Z*(1.0-0.5*Z)) / Z**3\n RETURN\nC\n END\n", "meta": {"hexsha": "18cda4ddb30c5a2a38800194bfc3b4a7e06893b9", "size": 2504, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/c9ln2r.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/c9ln2r.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/c9ln2r.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.8378378378, "max_line_length": 69, "alphanum_fraction": 0.5515175719, "num_tokens": 1180, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218262741298, "lm_q2_score": 0.734119526900183, "lm_q1q2_score": 0.6768008149433169}} {"text": "c\nc-----------------------------------------------------------------------\nc\n subroutine channelPtInit(xcen,ycen,rho,u,v,p)\n implicit double precision(a-h,o-z)\nc\nc # For the point (x,y), compute the true solution at this point \nc\n\n rho = ycen**2 \n !rho = ycen**2 - 0.1d0*xcen**2 + 5.d0 + 2.d0*xcen*ycen\n !rho = ycen - 0.1d0*xcen + 0.5d0\n !rho = ycen + 0.5d0\n u = 0.d0\n v = 0.d0\n p = 1.d0\n\n return\n end\nc\nc-----------------------------------------------------------------------\nc\n subroutine channelAvgInit(poly,xcen,ycen,rho,u,v,p)\n\n implicit double precision(a-h,o-z)\n dimension poly(10,2)\n dimension q(4,3), qcent(20,4), area(20), celltot(4)\nc\nc # For the centroid (x,y), compute the true cell avg. To\nc compute cell average (to 3rd order). decompose\nc polygon into triangles, with centroid always\nc a vertex. use approx. that cell avg. is\nc average of the function values on the 3 sides\n\n do 10 kside = 2, 20\n if (poly(kside,1) .eq. -11) then\n kend = kside - 2\n go to 99\n endif\n\n xst = poly(kside-1,1)\n yst = poly(kside-1,2)\n\n xend = poly(kside,1)\n yend = poly(kside,2)\n\n xavg = (xst+xend)/2.d0\n yavg = (yst+yend)/2.d0\n call channelPtInit(xavg,yavg,rho1,u1,v1,p1)\n\n xavg = (xend+xcen)/2.d0\n yavg = (yend+ycen)/2.d0\n call channelPtInit(xavg,yavg,rho2,u2,v2,p2)\n\n xavg = (xst+xcen)/2.d0\n yavg = (yst+ycen)/2.d0\n call channelPtInit(xavg,yavg,rho3,u3,v3,p3)\nc \nc compute area of triangle\n area(kside-1) = .5d0*((yst+ycen)*(xcen-xst) +\n & (ycen+yend)*(xend-xcen)+(yend+yst)*(xst-xend))\n qcent(kside-1,1) = (rho1+rho2+rho3)/3.d0\n qcent(kside-1,2) = (u1+u2+u3)/3.d0\n qcent(kside-1,3) = (v1+v2+v3)/3.d0\n qcent(kside-1,4) = (p1+p2+p3)/3.d0\n\n 11 continue\n 10 continue\n\n 99 continue\n\n totar = 0.d0\n celltot = 0.d0\n do 12 k = 1, kend\n celltot(1) = area(k)*qcent(k,1) + celltot(1)\n celltot(2) = area(k)*qcent(k,2) + celltot(2)\n celltot(3) = area(k)*qcent(k,3) + celltot(3)\n celltot(4) = area(k)*qcent(k,4) + celltot(4)\n totar = totar + area(k)\n 12 continue\n\n rho = celltot(1) / totar\n u = celltot(2) / totar\n v = celltot(3) / totar\n p = celltot(4) / totar\n\n return\n end\n\n", "meta": {"hexsha": "998275fb6e0b4d14194ef43813f0cbf9c61f952e", "size": 2526, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "examples/channel_quadratic/channelInit.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": "examples/channel_quadratic/channelInit.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": "examples/channel_quadratic/channelInit.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": 28.0666666667, "max_line_length": 72, "alphanum_fraction": 0.4932699921, "num_tokens": 911, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972818382005, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.6767151552945881}} {"text": "module make_analytic_solution_module\n\n use amrex_error_module\n use amrex_constants_module\n use base_state_geometry_module, only: center\n use probin_module, only: ambient_h, ambient_dens, &\n t0, peak_h, diffusion_coefficient\n use meth_params_module, only: prob_lo\n\n implicit none\n\n private\n\ncontains\n\n subroutine make_analytic_solution(lo, hi, solution, s_lo, s_hi, dx, time) &\n bind(C, name=\"make_analytic_solution\")\n\n integer, intent(in) :: lo(3), hi(3), s_lo(3), s_hi(3)\n double precision, intent(inout) :: solution(s_lo(1):s_hi(1),s_lo(2):s_hi(2),s_lo(3):s_hi(3))\n double precision, intent(in ) :: dx(3)\n double precision, intent(in ), value :: time\n\n integer :: n, i, j, k\n double precision :: x, y, dist2\n\n solution(s_lo(1):s_hi(1),s_lo(2):s_hi(2),s_lo(3):s_hi(3)) = ZERO\n\n do k = lo(3), hi(3)\n\n do j = lo(2), hi(2)\n\n y = prob_lo(2) + (dble(j)+HALF) * dx(2) - center(2)\n\n do i = lo(1), hi(1)\n\n x = prob_lo(1) + (dble(i)+HALF) * dx(1) - center(1)\n\n dist2 = x**2 + y**2\n\n solution(i,j,k) = f(time,dist2)\n\n enddo\n enddo\n enddo\n\n end subroutine make_analytic_solution\n\n function f(t,x) result(r)\n double precision :: t, x\n double precision :: r\n\n r = (peak_h - ambient_h) * (t0 / (t+t0)) * &\n dexp(-x / (FOUR * diffusion_coefficient * (t+t0))) + ambient_h\n\n end function f\n\nend module make_analytic_solution_module\n", "meta": {"hexsha": "4e03e90e9e2c373e7080400374345671d6cf060e", "size": 1462, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Exec/UNIT_TESTS/test_diffusion/make_analytic_solution.f90", "max_stars_repo_name": "pgrete/MAESTROeX", "max_stars_repo_head_hexsha": "1d7e89365379eea57680f738f271c93d7f28e513", "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": "Exec/UNIT_TESTS/test_diffusion/make_analytic_solution.f90", "max_issues_repo_name": "pgrete/MAESTROeX", "max_issues_repo_head_hexsha": "1d7e89365379eea57680f738f271c93d7f28e513", "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": "Exec/UNIT_TESTS/test_diffusion/make_analytic_solution.f90", "max_forks_repo_name": "pgrete/MAESTROeX", "max_forks_repo_head_hexsha": "1d7e89365379eea57680f738f271c93d7f28e513", "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.7796610169, "max_line_length": 96, "alphanum_fraction": 0.6108071135, "num_tokens": 481, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972684083609, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.6767151448555756}} {"text": "! DART software - Copyright UCAR. This open source software is provided\n! by UCAR, \"as is\", without charge, subject to all terms of use at\n! http://www.image.ucar.edu/DAReS/DART/DART_download\n!\n! $Id$\n\nprogram test_corr\n\n! test of twod_gaussian distribution, and two different numerical\n! methods of computing the variance and correlation. one is more\n! stable in the face of 8 byte reals being redefined as 4 byte values.\n\nuse types_mod, only : r8\nuse utilities_mod, only : check_namelist_read, find_namelist_in_file, &\n register_module, error_handler, E_ERR, &\n nmlfileunit, do_nml_file, do_nml_term, &\n initialize_utilities, finalize_utilities\nuse random_seq_mod, only : random_seq_type, init_random_seq, twod_gaussians\n\nimplicit none\n\n! version controlled file description for error handling, do not edit\ncharacter(len=256), parameter :: source = &\n \"$URL$\"\ncharacter(len=32 ), parameter :: revision = \"$Revision$\"\ncharacter(len=128), parameter :: revdate = \"$Date$\"\n\ntype (random_seq_type) :: r\nreal(r8), allocatable :: rnum(:, :)\nreal(r8) :: c(2, 2), mean(2)\ninteger :: i, j, iunit, io\n\nreal(r8) :: mean_correlA, varA, meanA, meanc_2A, sample_correlA\nreal(r8) :: mean_correlB, varB, meanB, meanc_2B, sample_correlB\n\n! namelist variables\ninteger :: n_pairs = 10\ninteger :: n_cycles = 100\nreal(r8) :: desired_correl = 0.75_r8\n\nnamelist /test_corr_nml/ n_pairs, desired_correl, n_cycles\n\n\n! start of program\n\ncall initialize_utilities('test_corr')\ncall register_module(source, revision, revdate)\n\n! Read the namelist entry\ncall find_namelist_in_file(\"input.nml\", \"test_corr_nml\", iunit)\nread(iunit, nml = test_corr_nml, iostat = io)\ncall check_namelist_read(iunit, io, \"test_corr_nml\")\n\n! Write the namelist values to the log file\nif (do_nml_file()) write(nmlfileunit, nml=test_corr_nml)\nif (do_nml_term()) write( * , nml=test_corr_nml)\n\n\nif (n_cycles < 2 .or. n_pairs < 2) then\n call error_handler(E_ERR, 'test_corr', 'both n_pairs and n_cycles must be >= 2', &\n source, revision, revdate)\nendif\n\nmean_correlA = 0.0\nmean_correlB = 0.0\nvarA = 0.0\nvarB = 0.0\n\n! Allocate space for the pairs of data\nallocate(rnum(2, n_pairs))\n\ncall init_random_seq(r)\n\n! Mean for generated\nmean = 0.0\nmeanc_2A = 0.0\nmeanc_2B = 0.0\n\n! Generate the covariance matrix\nc(1, 1) = 1.0\nc(2, 2) = 1.0\nc(1, 2) = desired_correl\nc(2, 1) = desired_correl\n\ndo j = 1, n_cycles\n \n do i = 1, n_pairs\n call twod_gaussians(r, mean, c, rnum(:, i))\n end do\n\n ! Compute the correlation of the random numbers two different ways\n call comp_correlA(rnum, n_pairs, sample_correlA)\n call comp_correlB(rnum, n_pairs, sample_correlB)\n\n mean_correlA = mean_correlA + sample_correlA\n meanc_2A = meanc_2A + sample_correlA**2\n varA = varA + (sample_correlA - desired_correl) ** 2\n\n mean_correlB = mean_correlB + sample_correlB\n meanc_2B = meanc_2B + sample_correlB**2\n varB = varB + (sample_correlB - desired_correl) ** 2\nend do\n\nmean_correlA = mean_correlA / n_cycles\nmean_correlB = mean_correlB / n_cycles\n\nwrite(*, *) ''\nwrite(*, *) 'target mean correl is ', desired_correl\nwrite(*, *) 'computed mean correl, version A, is ', mean_correlA\nwrite(*, *) 'computed mean correl, version B, is ', mean_correlB\n\nwrite(*, *) ''\nwrite(*, *) 'predicted variance is ', (1.0_r8 - desired_correl**2)**2 / (n_pairs - 1._r8)\nwrite(*, *) 'computed variance, version A, is ', (meanc_2A - n_cycles * mean_correlA**2) / (n_cycles - 1._r8)\nwrite(*, *) 'computed variance, version B, is ', (meanc_2B - n_cycles * mean_correlB**2) / (n_cycles - 1._r8)\n\ncall finalize_utilities('test_corr')\n\ncontains\n\n!-----------------------------------------------------\n \nsubroutine comp_correlA(ens, n, correl)\n \ninteger, intent(in) :: n\nreal(r8), intent(in) :: ens(2, n)\nreal(r8), intent(out) :: correl\n\nreal(r8) :: sum_x, sum_y, sum_xy, sum_x2, sum_y2\n\nsum_x = sum(ens(2, :))\nsum_y = sum(ens(1, :))\nsum_xy = sum(ens(2, :) * ens(1, :))\nsum_x2 = sum(ens(2, :) * ens(2, :))\n \n! Computation of correlation \nsum_y2 = sum(ens(1, :) * ens(1, :))\n\n! debug:\n!print *, 'x,y,xy,x2,y2: ', sum_x, sum_y, sum_xy, sum_x2, sum_y2\n\ncorrel = (n * sum_xy - sum_x * sum_y) / &\n sqrt((n * sum_x2 - sum_x**2) * (n * sum_y2 - sum_y**2))\n \nend subroutine comp_correlA\n\n!-----------------------------------------------------\n \nsubroutine comp_correlB(ens, n, correl)\n \n! alternative way to comput covariance and variance - more numerically\n! stable in the face of 4 byte floats:\n\ninteger, intent(in) :: n\nreal(r8), intent(in) :: ens(2, n)\nreal(r8), intent(out) :: correl\n\nreal(r8) :: sum_x, sum_y\nreal(r8) :: x_mean, y_mean, x_var, y_var, cov\n\nsum_x = sum(ens(2, :))\nsum_y = sum(ens(1, :))\n \nx_mean = sum_x / n\ny_mean = sum_y / n\nx_var = sum((ens(2, :) - x_mean)**2) / (n - 1)\ny_var = sum((ens(1, :) - y_mean)**2) / (n - 1)\ncov = sum((ens(2, :) - x_mean) * (ens(1, :) - y_mean)) / (n - 1)\ncorrel = cov / sqrt(x_var * y_var)\n\n! debug:\n!print *, x_mean, y_mean, x_var, y_var, cov, abs(x_var * y_var), sqrt(x_var*y_var), correl\n\nend subroutine comp_correlB\n\n!-----------------------------------------------------\n \nend program test_corr\n\n! \n! $URL$\n! $Id$\n! $Revision$\n! $Date$\n", "meta": {"hexsha": "f277ae1180658d7498abd0df5354972ad0acc731", "size": 5318, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "developer_tests/random_seq/test_corr.f90", "max_stars_repo_name": "hkershaw-brown/feature-preprocess", "max_stars_repo_head_hexsha": "fe2bd77b38c63fa0566c83ebc4d2fac1623aef66", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 65, "max_stars_repo_stars_event_min_datetime": "2019-10-16T13:31:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-14T11:52:58.000Z", "max_issues_repo_path": "developer_tests/random_seq/test_corr.f90", "max_issues_repo_name": "hkershaw-brown/feature-preprocess", "max_issues_repo_head_hexsha": "fe2bd77b38c63fa0566c83ebc4d2fac1623aef66", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 283, "max_issues_repo_issues_event_min_datetime": "2019-09-23T15:48:34.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:44:41.000Z", "max_forks_repo_path": "developer_tests/random_seq/test_corr.f90", "max_forks_repo_name": "hkershaw-brown/feature-preprocess", "max_forks_repo_head_hexsha": "fe2bd77b38c63fa0566c83ebc4d2fac1623aef66", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 67, "max_forks_repo_forks_event_min_datetime": "2019-09-19T22:13:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-20T15:58:26.000Z", "avg_line_length": 28.7459459459, "max_line_length": 113, "alphanum_fraction": 0.6489281685, "num_tokens": 1739, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972784807408, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.676715139210798}} {"text": " PROGRAM xrlft3\r\nC driver for routine rlft3\r\n INTEGER NX,NY,NZ\r\n REAL EPS\r\n PARAMETER(NX=16,NY=8,NZ=32,EPS=0.0008)\r\n INTEGER icompare,idum,i,j,k,ierr\r\n REAL data1(NX,NY,NZ),data2(NX,NY,NZ),fnorm,ran1\r\n COMPLEX speq1(NY,NZ)\r\n INTEGER nn1,nn2,nn3\r\n idum=-3\r\n nn1=NX\r\n nn2=NY\r\n nn3=NZ\r\n fnorm=float(nn1)*float(nn2)*float(nn3)/2.\r\n do 13 i=1,nn1\r\n do 12 j=1,nn2\r\n do 11 k=1,nn3\r\n data1(i,j,k)=2.*ran1(idum)-1.\r\n data2(i,j,k)=data1(i,j,k)*fnorm\r\n11 continue\r\n12 continue\r\n13 continue\r\n call rlft3(data1,speq1,nn1,nn2,nn3,1)\r\nC here would be any processing in Fourier space\r\n call rlft3(data1,speq1,nn1,nn2,nn3,-1)\r\n ierr=icompare('data',data1,data2,nn1*nn2*nn3,EPS)\r\n if (ierr.eq.0) then\r\n write(*,*) 'Data compares OK to tolerance',EPS\r\n else\r\n write(*,*) 'Comparison errors occured at tolerance',EPS\r\n write(*,*) 'Total number of errors is',ierr\r\n endif\r\n END\r\n INTEGER FUNCTION icompare(string,arr1,arr2,len,eps)\r\n INTEGER IPRNT\r\n PARAMETER(IPRNT=20)\r\n CHARACTER*(*) string\r\n INTEGER j,len\r\n REAL eps,arr1(len),arr2(len)\r\n write(*,*) string\r\n icompare=0\r\n do 11 j=1,len\r\n if ((arr2(j).eq.0.and.abs(arr1(j)-arr2(j)).gt.eps).or.\r\n * (abs((arr1(j)-arr2(j))/arr2(j)).gt.eps)) then\r\n icompare=icompare+1\r\n if (icompare.le.IPRNT) write(*,*) j,arr1(j),arr2(j)\r\n endif\r\n11 continue\r\n return\r\n END\r\n", "meta": {"hexsha": "1452197525dc78ab95737fabc5e881aa6ef3a01c", "size": 1575, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xrlft3.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xrlft3.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xrlft3.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": 30.8823529412, "max_line_length": 64, "alphanum_fraction": 0.5511111111, "num_tokens": 541, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972818382005, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.676715137329205}} {"text": "SUBROUTINE clawpack5_qinit(meqn,mbc,mx,my, &\n xlower,ylower,dx,dy,q,maux,aux)\n !! =====================================================\n !!\n !! # Set initial conditions for q.\n !!\n !! # Data is piecewise constant with 4 values in 4 quadrants\n !! # 2D Riemann problem from Figure 4 of\n !! @article{csr-col-glaz,\n !! author=\"C. W. Schulz-Rinne and J. P. Collins and H. M. Glaz\",\n !! title=\"Numerical Solution of the {R}iemann Problem for\n !! Two-Dimensional Gas Dynamics\",\n !! journal=\"SIAM J. Sci. Comput.\",\n !! volume=\"14\",\n !! year=\"1993\",\n !! pages=\"1394-1414\" }\n\n\n IMPLICIT DOUBLE PRECISION (a-h,o-z)\n DIMENSION q(meqn,1-mbc:mx+mbc, 1-mbc:my+mbc)\n DIMENSION rpp(4),rpr(4),rpu(4),rpv(4)\n COMMON /cparam/ gamma,gamma1\n\n\n !! # First quadrant:\n rpp(1) = 1.5d0\n rpr(1) = 1.5d0\n rpu(1) = 0.d0\n rpv(1) = 0.d0\n\n !! # Second quadrant:\n rpp(2) = 0.3d0\n rpr(2) = 0.532258064516129d0\n rpu(2) = 1.206045378311055d0\n rpv(2) = 0.0d0\n\n !! # Third quadrant:\n rpp(3) = 0.029032258064516d0\n rpr(3) = 0.137992831541219d0\n rpu(3) = 1.206045378311055d0\n rpv(3) = 1.206045378311055d0\n\n !! # Fourth quadrant:\n rpp(4) = 0.3d0\n rpr(4) = 0.532258064516129d0\n rpu(4) = 0.0d0\n rpv(4) = 1.206045378311055d0\n\n!! # location of four corners:\n xs = .8d0\n ys = .8d0\n\n DO i = 1-mbc,mx+mbc\n xcell = xlower + (i-0.5d0)*dx\n DO j = 1-mbc,my+mbc\n ycell = ylower + (j-0.5d0)*dy\n IF (xcell.GE.xs .AND. ycell.GE.ys) iq = 1\n IF (xcell.LT.xs .AND. ycell.GE.ys) iq = 2\n IF (xcell.LT.xs .AND. ycell.LT.ys) iq = 3\n IF (xcell.GE.xs .AND. ycell.LT.ys) iq = 4\n q(1,i,j) = rpr(iq)\n q(2,i,j) = rpr(iq)*rpu(iq)\n q(3,i,j) = rpr(iq)*rpv(iq)\n q(4,i,j) = rpp(iq)/gamma1 + 0.5d0*rpr(iq)*(rpu(iq)**2 + &\n rpv(iq)**2)\n ENDDO\n ENDDO\n RETURN\nEND SUBROUTINE clawpack5_qinit\n", "meta": {"hexsha": "4c65326cded57f770b53f12b4f3a9f3c56944e1a", "size": 1942, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "applications/clawpack/euler/2d/quadrants/user_5.0/qinit.f90", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2017-09-26T13:39:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:56:23.000Z", "max_issues_repo_path": "applications/clawpack/euler/2d/quadrants/user_5.0/qinit.f90", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 75, "max_issues_repo_issues_event_min_datetime": "2017-08-02T19:56:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T12:36:32.000Z", "max_forks_repo_path": "applications/clawpack/euler/2d/quadrants/user_5.0/qinit.f90", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-02-21T00:10:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T19:08:36.000Z", "avg_line_length": 27.7428571429, "max_line_length": 75, "alphanum_fraction": 0.5386199794, "num_tokens": 847, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972650509007, "lm_q2_score": 0.7772998611746911, "lm_q1q2_score": 0.6767151332631308}} {"text": " PROGRAM LA_SGELSY_EXAMPLE\n\n! -- LAPACK95 EXAMPLE DRIVER ROUTINE (VERSION 1.0) --\n! UNI-C, DENMARK\n! DECEMBER, 1999\n!\n! .. \"Use Statements\" ..\n USE LA_PRECISION, ONLY: WP => SP\n USE F95_LAPACK, ONLY: LA_GELSY\n ! USE F77_LAPACK, ONLY: GEESX_F77 => LA_GEESX\n! .. \"Implicit Statement\" ..\n IMPLICIT NONE\n! .. \"Local Scalars\" ..\n INTEGER :: I, J, M, N, NRHS, RANK\n! .. \"Local Arrays\" ..\n INTEGER, ALLOCATABLE :: JPVT(:)\n REAL(WP), ALLOCATABLE :: A(:,:), AA(:,:), B(:,:), BB(:,:)\n! .. \"Executable Statements\" ..\n WRITE (*,*) 'LA_GELSY Example Program Results'\n M=6; N = 4; NRHS = 3\n WRITE(*,'(5H M = , I4, 5H N = , I4, 9H; NRHS = , I4)') M, N, NRHS\n ALLOCATE( A(M,N), AA(M,N), B(MAX(M,N),NRHS), BB(MAX(M,N),NRHS), JPVT(N) )\n\n OPEN(UNIT=21,FILE='gelss.ma',STATUS='UNKNOWN')\n DO I=1,M\n DO J=1,N \n READ(21,'(F2.0)') A(I,J)\n ENDDO\n ENDDO\n CLOSE(21)\n\n WRITE(*,*)'Matrix A :'\n DO I=1,M;\n WRITE(*,\"(24(F9.5))\") A(I,:);\n ENDDO\n\n OPEN(UNIT=22,FILE='gelss.mb',STATUS='UNKNOWN')\n DO I=1,MAX(M,N)\n DO J=1,NRHS\n READ(22,'(F3.0)') B(I,J)\n ENDDO\n ENDDO\n CLOSE(22)\n \n WRITE(*,*)'Matrix B :'\n DO I=1,M; \n WRITE(*,\"(3(F9.5))\") B(I,:); \n ENDDO\n \n AA=A\n BB=B\n \n JPVT(1)=0; JPVT(2)=0; JPVT(3)=1; JPVT(4)=0;\n\n WRITE(*,*) 'CALL LA_GELSY( A, B, RANK, JPVT, 1.0E-5_WP )'\n \n CALL LA_GELSY( A, B, RANK, JPVT, 1.0E-5_WP )\n \n WRITE(*,*) 'The matrix B on exit :'\n DO I=1,M; \n WRITE(*,\"(3(E15.7),1X)\") B(I,:); \n ENDDO\n \n \n WRITE(*,*)'RANK = ', RANK\n WRITE(*,*)'JPVT = ', JPVT\n \n END PROGRAM LA_SGELSY_EXAMPLE\n", "meta": {"hexsha": "e5ca80df8e9aa10363c26b416511ef9163e41812", "size": 1786, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "EXAMPLES1/la_gelsy_example.f90", "max_stars_repo_name": "MattBurn/LAPACK95", "max_stars_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-12-29T15:07:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T10:09:22.000Z", "max_issues_repo_path": "EXAMPLES1/la_gelsy_example.f90", "max_issues_repo_name": "MattBurn/LAPACK95", "max_issues_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-12-30T15:38:47.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-31T06:45:11.000Z", "max_forks_repo_path": "EXAMPLES1/la_gelsy_example.f90", "max_forks_repo_name": "MattBurn/LAPACK95", "max_forks_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-12-29T15:34:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-15T07:12:40.000Z", "avg_line_length": 25.884057971, "max_line_length": 79, "alphanum_fraction": 0.4697648376, "num_tokens": 688, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972684083609, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6767151313815385}} {"text": "! Copyright 2018 Timothy Hume\n!\n! Permission to use, copy, modify, and/or distribute this software for any\n! purpose with or without fee is hereby granted, provided that the above\n! copyright notice and this permission notice appear in all copies.\n!\n! THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n! REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND\n! FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n! INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n! LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n! OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n! PERFORMANCE OF THIS SOFTWARE.\n\nprogram mandelbrot\n use, intrinsic :: iso_fortran_env\n use mbtypes\n use setup\n use image\n use mbmath\n implicit none\n\n !\n ! Variables read from the command line.\n !\n character(len=1024) :: imgfile ! Name of image file to create\n character(len=128) :: cpt ! Name of colour palette to use\n integer(int32) :: nx ! Width of image\n integer(int32) :: ny ! Height of image\n integer(int64) :: itermax ! Maximimum number of iterations\n real(real128) :: zoom ! Zoom factor\n real(real128) :: cr ! Real part of centre point\n real(real128) :: ci ! Imaginary part of centre point\n\n real(real64), allocatable :: niter(:,:) ! Results array\n\n !\n ! Read the command line.\n !\n call read_cmd(cr, ci, nx, ny, zoom, itermax, cpt, imgfile)\n\n !\n ! Allocate memory for the niter array.\n !\n allocate(niter(nx, ny))\n\n !\n ! Compute the Mandelbrot set for the points of interest.\n !\n call fillplane(real(cr, realmb), real(ci, realmb), nx, ny, real(zoom, realmb), itermax, niter)\n !call mbplane(cr, ci, nx, ny, zoom, itermax, niter)\n\n !\n ! Colorise the set.\n !\n call colourise(niter, nx, ny, cpt, imgfile)\n\n deallocate(niter)\n\nend program\n", "meta": {"hexsha": "4cdb47b720a16e69209e1ccc36921bad34c0b779", "size": 2103, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/mandelbrot.f90", "max_stars_repo_name": "timo007/mandelbrot", "max_stars_repo_head_hexsha": "22c7a36a9950050b04f7bc6c9a258825a470ef51", "max_stars_repo_licenses": ["0BSD"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/mandelbrot.f90", "max_issues_repo_name": "timo007/mandelbrot", "max_issues_repo_head_hexsha": "22c7a36a9950050b04f7bc6c9a258825a470ef51", "max_issues_repo_licenses": ["0BSD"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/mandelbrot.f90", "max_forks_repo_name": "timo007/mandelbrot", "max_forks_repo_head_hexsha": "22c7a36a9950050b04f7bc6c9a258825a470ef51", "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.4754098361, "max_line_length": 98, "alphanum_fraction": 0.6471707085, "num_tokens": 521, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972549785201, "lm_q2_score": 0.7772998611746911, "lm_q1q2_score": 0.6767151254338708}} {"text": " double precision function psi(xp,yp,zp,t)\n implicit none\n\n double precision xp,yp,zp,t\n double precision r2, pi2, revs_per_s\n\n double precision pi\n common /compi/ pi\n\n revs_per_s = 0.5d0\n\n pi2 = 2*pi\n\nc # annulus : Solid body rotation\n r2 = xp**2 + yp**2\n psi = 0.5d0*pi2*revs_per_s*r2\n\n psi = -psi\n\n end\n\n subroutine get_psi_vel(xd1,xd2,ds,vn,t)\n implicit none\n\n double precision xd1(3),xd2(3), ds, vn, psi,t\n\n vn = (psi(xd1(1),xd1(2),xd1(3),t) -\n & psi(xd2(1),xd2(2),xd2(3),t))/ds\n\n end\n", "meta": {"hexsha": "63966362e69bdbb6ad971b1f3b0b642d9a8ffc00", "size": 588, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "applications/paper/annulus/user_5.0/psi.f", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2017-09-26T13:39:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:56:23.000Z", "max_issues_repo_path": "applications/paper/annulus/user_5.0/psi.f", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 75, "max_issues_repo_issues_event_min_datetime": "2017-08-02T19:56:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T12:36:32.000Z", "max_forks_repo_path": "applications/paper/annulus/user_5.0/psi.f", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-02-21T00:10:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T19:08:36.000Z", "avg_line_length": 18.9677419355, "max_line_length": 51, "alphanum_fraction": 0.5527210884, "num_tokens": 218, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9416541561135442, "lm_q2_score": 0.7185944046238981, "lm_q1q2_score": 0.6766674076740316}} {"text": " SUBROUTINE MB05MD( BALANC, N, DELTA, A, LDA, V, LDV, Y, LDY, VALR,\n $ VALI, IWORK, DWORK, LDWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute exp(A*delta) where A is a real N-by-N non-defective\nC matrix with real or complex eigenvalues and delta is a scalar\nC value. The routine also returns the eigenvalues and eigenvectors\nC of A as well as (if all eigenvalues are real) the matrix product\nC exp(Lambda*delta) times the inverse of the eigenvector matrix\nC of A, where Lambda is the diagonal matrix of eigenvalues.\nC Optionally, the routine computes a balancing transformation to\nC improve the conditioning of the eigenvalues and eigenvectors.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC BALANC CHARACTER*1\nC Indicates how the input matrix should be diagonally scaled\nC to improve the conditioning of its eigenvalues as follows:\nC = 'N': Do not diagonally scale;\nC = 'S': Diagonally scale the matrix, i.e. replace A by\nC D*A*D**(-1), where D is a diagonal matrix chosen\nC to make the rows and columns of A more equal in\nC norm. Do not permute.\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The order of the matrix A. N >= 0.\nC\nC DELTA (input) DOUBLE PRECISION\nC The scalar value delta of the problem.\nC\nC A (input/output) DOUBLE PRECISION array, dimension (LDA,N)\nC On entry, the leading N-by-N part of this array must\nC contain the matrix A of the problem.\nC On exit, the leading N-by-N part of this array contains\nC the solution matrix exp(A*delta).\nC\nC LDA INTEGER\nC The leading dimension of array A. LDA >= max(1,N).\nC\nC V (output) DOUBLE PRECISION array, dimension (LDV,N)\nC The leading N-by-N part of this array contains the\nC eigenvector matrix for A.\nC If the k-th eigenvalue is real the k-th column of the\nC eigenvector matrix holds the eigenvector corresponding\nC to the k-th eigenvalue.\nC Otherwise, the k-th and (k+1)-th eigenvalues form a\nC complex conjugate pair and the k-th and (k+1)-th columns\nC of the eigenvector matrix hold the real and imaginary\nC parts of the eigenvectors corresponding to these\nC eigenvalues as follows.\nC If p and q denote the k-th and (k+1)-th columns of the\nC eigenvector matrix, respectively, then the eigenvector\nC corresponding to the complex eigenvalue with positive\nC (negative) imaginary value is given by\nC 2\nC p + q*j (p - q*j), where j = -1.\nC\nC LDV INTEGER\nC The leading dimension of array V. LDV >= max(1,N).\nC\nC Y (output) DOUBLE PRECISION array, dimension (LDY,N)\nC The leading N-by-N part of this array contains an\nC intermediate result for computing the matrix exponential.\nC Specifically, exp(A*delta) is obtained as the product V*Y,\nC where V is the matrix stored in the leading N-by-N part of\nC the array V. If all eigenvalues of A are real, then the\nC leading N-by-N part of this array contains the matrix\nC product exp(Lambda*delta) times the inverse of the (right)\nC eigenvector matrix of A, where Lambda is the diagonal\nC matrix of eigenvalues.\nC\nC LDY INTEGER\nC The leading dimension of array Y. LDY >= max(1,N).\nC\nC VALR (output) DOUBLE PRECISION array, dimension (N)\nC VALI (output) DOUBLE PRECISION array, dimension (N)\nC These arrays contain the real and imaginary parts,\nC respectively, of the eigenvalues of the matrix A. The\nC eigenvalues are unordered except that complex conjugate\nC pairs of values appear consecutively with the eigenvalue\nC having positive imaginary part first.\nC\nC Workspace\nC\nC IWORK INTEGER array, dimension (N)\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0, DWORK(1) returns the optimal value\nC of LDWORK, and if N > 0, DWORK(2) returns the reciprocal\nC condition number of the triangular matrix used to obtain\nC the inverse of the eigenvector matrix.\nC\nC LDWORK INTEGER\nC The length of the array DWORK. LDWORK >= max(1,4*N).\nC For good performance, LDWORK must generally be larger.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value;\nC = i: if INFO = i, the QR algorithm failed to compute all\nC the eigenvalues; no eigenvectors have been computed;\nC elements i+1:N of VALR and VALI contain eigenvalues\nC which have converged;\nC = N+1: if the inverse of the eigenvector matrix could not\nC be formed due to an attempt to divide by zero, i.e.,\nC the eigenvector matrix is singular;\nC = N+2: if the matrix A is defective, possibly due to\nC rounding errors.\nC\nC METHOD\nC\nC This routine is an implementation of \"Method 15\" of the set of\nC methods described in reference [1], which uses an eigenvalue/\nC eigenvector decomposition technique. A modification of LAPACK\nC Library routine DGEEV is used for obtaining the right eigenvector\nC matrix. A condition estimate is then employed to determine if the\nC matrix A is near defective and hence the exponential solution is\nC inaccurate. In this case the routine returns with the Error\nC Indicator (INFO) set to N+2, and SLICOT Library routines MB05ND or\nC MB05OD are the preferred alternative routines to be used.\nC\nC REFERENCES\nC\nC [1] Moler, C.B. and Van Loan, C.F.\nC Nineteen dubious ways to compute the exponential of a matrix.\nC SIAM Review, 20, pp. 801-836, 1978.\nC\nC [2] Anderson, E., Bai, Z., Bischof, C., Demmel, J., Dongarra, J.,\nC Du Croz, J., Greenbaum, A., Hammarling, S., McKenney, A.,\nC Ostrouchov, S., and Sorensen, D.\nC LAPACK Users' Guide: Second Edition.\nC SIAM, Philadelphia, 1995.\nC\nC NUMERICAL ASPECTS\nC 3\nC The algorithm requires 0(N ) operations.\nC\nC CONTRIBUTOR\nC\nC Release 3.0: V. Sima, Katholieke Univ. Leuven, Belgium, Apr. 1997.\nC Supersedes Release 2.0 routine MB05AD by M.J. Denham, Kingston\nC Polytechnic, March 1981.\nC\nC REVISIONS\nC\nC V. Sima, June 13, 1997, April 25, 2003, Feb. 15, 2004.\nC\nC KEYWORDS\nC\nC Eigenvalue, eigenvector decomposition, matrix exponential.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, ONE\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )\nC .. Scalar Arguments ..\n CHARACTER BALANC\n INTEGER INFO, LDA, LDV, LDWORK, LDY, N\n DOUBLE PRECISION DELTA\nC .. Array Arguments ..\n INTEGER IWORK(*)\n DOUBLE PRECISION A(LDA,*), DWORK(*), V(LDV,*), VALI(*), VALR(*),\n $ Y(LDY,*)\nC .. Local Scalars ..\n LOGICAL SCALE\n INTEGER I\n DOUBLE PRECISION RCOND, TEMPI, TEMPR, WRKOPT\nC .. Local Arrays ..\n DOUBLE PRECISION TMP(2,2)\nC .. External Functions ..\n LOGICAL LSAME\n DOUBLE PRECISION DLAMCH\n EXTERNAL DLAMCH, LSAME\nC .. External Subroutines ..\n EXTERNAL DGEBAK, DGEMM, DLACPY, DSCAL, DSWAP, DTRCON,\n $ DTRMM, DTRSM, MB05MY, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC COS, EXP, MAX, SIN\nC .. Executable Statements ..\nC\nC Test the input scalar arguments.\nC\n INFO = 0\n SCALE = LSAME( BALANC, 'S' )\n IF( .NOT.( LSAME( BALANC, 'N' ) .OR. SCALE ) ) THEN\n INFO = -1\n ELSE IF( N.LT.0 ) THEN\n INFO = -2\n ELSE IF( LDA.LT.MAX( 1, N ) ) THEN\n INFO = -5\n ELSE IF( LDV.LT.MAX( 1, N ) ) THEN\n INFO = -7\n ELSE IF( LDY.LT.MAX( 1, N ) ) THEN\n INFO = -9\n ELSE IF( LDWORK.LT.MAX( 1, 4*N ) ) THEN\n INFO = -14\n END IF\nC\n IF ( INFO.NE.0 ) THEN\nC\nC Error return.\nC\n CALL XERBLA( 'MB05MD', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF ( N.EQ.0 ) THEN\n DWORK(1) = ONE\n RETURN\n END IF\nC\nC (Note: Comments in the code beginning \"Workspace:\" describe the\nC minimal amount of workspace needed at that point in the code,\nC as well as the preferred amount for good performance.\nC NB refers to the optimal block size for the immediately\nC following subroutine, as returned by ILAENV.)\nC\nC Compute the eigenvalues and right eigenvectors of the real\nC nonsymmetric matrix A; optionally, compute a balancing\nC transformation.\nC Workspace: need: 4*N.\nC\n CALL MB05MY( BALANC, N, A, LDA, VALR, VALI, V, LDV, Y, LDY,\n $ DWORK, LDWORK, INFO )\nC\n IF ( INFO.GT.0 )\n $ RETURN\n WRKOPT = DWORK(1)\n IF ( SCALE ) THEN\n DO 10 I = 1, N\n DWORK(I) = DWORK(I+1)\n 10 CONTINUE\n END IF\nC\nC Exit with INFO = N + 1 if V is exactly singular.\nC\n DO 20 I = 1, N\n IF ( V(I,I).EQ.ZERO ) THEN\n INFO = N + 1\n RETURN\n END IF\n 20 CONTINUE\nC\nC Compute the reciprocal condition number of the triangular matrix.\nC\n CALL DTRCON( '1-norm', 'Upper', 'Non unit', N, V, LDV, RCOND,\n $ DWORK(N+1), IWORK, INFO )\nC\nC Return if the matrix is singular to working precision.\nC\n IF( RCOND.LT.DLAMCH( 'Epsilon' ) ) THEN\n DWORK(2) = RCOND\n INFO = N + 2\n RETURN\n END IF\nC\nC Compute the right eigenvector matrix (temporarily) in A.\nC\n CALL DLACPY( 'Full', N, N, Y, LDY, A, LDA )\n CALL DTRMM( 'Right', 'Upper', 'No transpose', 'Non unit', N, N,\n $ ONE, V, LDV, A, LDA )\n IF ( SCALE )\n $ CALL DGEBAK( BALANC, 'Right', N, 1, N, DWORK, N, A, LDA, INFO )\nC\nC Compute the inverse of the right eigenvector matrix, by solving\nC a set of linear systems, V * X = Y' (if BALANC = 'N').\nC\n DO 40 I = 2, N\n CALL DSWAP( I-1, Y(I,1), LDY, Y(1,I), 1 )\n 40 CONTINUE\nC\n CALL DTRSM( 'Left', 'Upper', 'No transpose', 'Non unit', N, N,\n $ ONE, V, LDV, Y, LDY )\n IF( SCALE ) THEN\nC\n DO 60 I = 1, N\n TEMPR = ONE / DWORK(I)\n CALL DSCAL( N, TEMPR, Y(1,I), 1 )\n 60 CONTINUE\nC\n END IF\nC\nC Save the right eigenvector matrix in V.\nC\n CALL DLACPY( 'Full', N, N, A, LDA, V, LDV )\nC\nC Premultiply the inverse eigenvector matrix by the exponential of\nC quasi-diagonal matrix Lambda * DELTA, where Lambda is the matrix\nC of eigenvalues.\nC Note that only real arithmetic is used, taking the special storing\nC of eigenvalues/eigenvectors into account.\nC\n I = 0\nC REPEAT\n 80 CONTINUE\n I = I + 1\n IF ( VALI(I).EQ.ZERO ) THEN\n TEMPR = EXP( VALR(I)*DELTA )\n CALL DSCAL( N, TEMPR, Y(I,1), LDY )\n ELSE\n TEMPR = VALR(I)*DELTA\n TEMPI = VALI(I)*DELTA\n TMP(1,1) = COS( TEMPI )*EXP( TEMPR )\n TMP(1,2) = SIN( TEMPI )*EXP( TEMPR )\n TMP(2,1) = -TMP(1,2)\n TMP(2,2) = TMP(1,1)\n CALL DLACPY( 'Full', 2, N, Y(I,1), LDY, DWORK, 2 )\n CALL DGEMM( 'No transpose', 'No transpose', 2, N, 2, ONE,\n $ TMP, 2, DWORK, 2, ZERO, Y(I,1), LDY )\n I = I + 1\n END IF\n IF ( I.LT.N ) GO TO 80\nC UNTIL I = N.\nC\nC Compute the matrix exponential as the product V * Y.\nC\n CALL DGEMM( 'No transpose', 'No transpose', N, N, N, ONE, V, LDV,\n $ Y, LDY, ZERO, A, LDA )\nC\nC Set optimal workspace dimension and reciprocal condition number.\nC\n DWORK(1) = WRKOPT\n DWORK(2) = RCOND\nC\n RETURN\nC *** Last line of MB05MD ***\n END\n", "meta": {"hexsha": "dd047f055295aad27a119736815c4b386ac9d5d8", "size": 12414, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB05MD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB05MD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB05MD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 36.1924198251, "max_line_length": 72, "alphanum_fraction": 0.581681972, "num_tokens": 3610, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541544761565, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6766674008225154}} {"text": "C\nC\n real*4 function ct_standard( rgb, ci, cimin, cimax )\nC ----------------------------------------------------\nC\nC Function defining an standard colour-scale.\nC\nC defining:\nC x = (ci-cimin)/(cimax-cimin)\nC then:\nC red = sin(power(red)*x)**2,\nC green = sin(power(green)*x)**2,\nC blue = sin(power(blue)*x)**2\n*-\n\n include '../include/tv_modify.inc'\n\n integer rgb, ci, cimin, cimax\n real*4 x\n\n x = (float(ci-cimin)/float(cimax-cimin))\n ct_standard = (sin( col_index(rgb)*x ))**2\n end\n", "meta": {"hexsha": "4326ebb85a638053a72fcba507d68c19a24cd188", "size": 606, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "graphic_lib/ct_standard.f", "max_stars_repo_name": "CavendishAstrophysics/anmap", "max_stars_repo_head_hexsha": "efb611d7f80a3d14dc55e46cd01e8a622f6fd294", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-09-01T12:40:45.000Z", "max_stars_repo_stars_event_max_datetime": "2015-09-01T12:40:45.000Z", "max_issues_repo_path": "graphic_lib/ct_standard.f", "max_issues_repo_name": "CavendishAstrophysics/anmap", "max_issues_repo_head_hexsha": "efb611d7f80a3d14dc55e46cd01e8a622f6fd294", "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": "graphic_lib/ct_standard.f", "max_forks_repo_name": "CavendishAstrophysics/anmap", "max_forks_repo_head_hexsha": "efb611d7f80a3d14dc55e46cd01e8a622f6fd294", "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.25, "max_line_length": 59, "alphanum_fraction": 0.4702970297, "num_tokens": 164, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.941654159388319, "lm_q2_score": 0.7185943805178139, "lm_q1q2_score": 0.6766673873276718}} {"text": " SUBROUTINE rotate(r,qt,n,np,i,a,b)\r\n INTEGER n,np,i\r\n REAL a,b,r(np,np),qt(np,np)\r\n INTEGER j\r\n REAL c,fact,s,w,y\r\n if(a.eq.0.)then\r\n c=0.\r\n s=sign(1.,b)\r\n else if(abs(a).gt.abs(b))then\r\n fact=b/a\r\n c=sign(1./sqrt(1.+fact**2),a)\r\n s=fact*c\r\n else\r\n fact=a/b\r\n s=sign(1./sqrt(1.+fact**2),b)\r\n c=fact*s\r\n endif\r\n do 11 j=i,n\r\n y=r(i,j)\r\n w=r(i+1,j)\r\n r(i,j)=c*y-s*w\r\n r(i+1,j)=s*y+c*w\r\n11 continue\r\n do 12 j=1,n\r\n y=qt(i,j)\r\n w=qt(i+1,j)\r\n qt(i,j)=c*y-s*w\r\n qt(i+1,j)=s*y+c*w\r\n12 continue\r\n return\r\n END\r\n", "meta": {"hexsha": "face4419fcea2e761a41f377418d2ffa52254dd1", "size": 687, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/rotate.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/rotate.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/rotate.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": 21.46875, "max_line_length": 41, "alphanum_fraction": 0.3988355167, "num_tokens": 247, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942171172602, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.676646147723018}} {"text": " PROGRAM TB2D\n\nC This program computes the pressure distribution and several derived\nC quantities for a finite tilting thrust bearing of rectangular shape. \nC Calculations can be performed for different L/B ratios.\n\nC X(I) = position along x-axis (ie. x coordinate)\nC Y(J) = position along y-axis (ie. y coordinate)\nC NX = number of mesh points along x-axis\nC NY = number of mesh points along y-axis \nC P(I,J) = Pressure at node i,j at latest iteration level\nC PPI(I,J) = Pressure at node i,j at the previous iteration\nC H(I) = film thickness at node i,j\nC LB = L/B ratio\nC K = H1/H0-1 \nC H1 = leading edge (maximum) film thickness\nC H0 = trailing edge (minimum) film thickness\nC NDLOAD = Non-dimensional load capacity\nC QX = Flow-rate per unit length in the x-direction\nC QY = Flow-rate per unit breadth in the y-directon\nC QE = End-leakage (evaluated at the trailing edge)\nC QS = Side-leakage (evaluated at y* = 0.0)\nC DPDX = Pressure gradient in the x-direction\nC DPDY = Pressure gradient in the y-direction\nC TORX0 = Shear stress on the lower surface in the x-direction\nC TORXH = Shear stress on the upper surface in the x-direction\nC FF0 = Friction force on the lower surface\nC FFH = Friction force on the upper surface\nC XBAR = Location of the pivot point \nC FOR = Successive over-relaxation factor\n\nC Declaration of variables\n PARAMETER (N = 501, NTOTAL=N*N, PI=3.141592654, FOR=1.5)\n DOUBLE PRECISION K, LB, DX, DY, DX2, DY2, BL2\n DOUBLE PRECISION X(N), Y(N), H(N), PPI(N,N), P(N,N)\n DOUBLE PRECISION A(N), B(N), C(N), D(N)\n DOUBLE PRECISION NDLOAD, SGLINT, DBLINT\n DOUBLE PRECISION QX(N), QY(N), QE, QS \n DOUBLE PRECISION DPDX(N,N), DPDY(N,N), TORX0(N,N), TORXH(N,N) \n DOUBLE PRECISION XP(N,N), XBAR, FF0, FFH\n INTEGER NX, NXM1, NXM2, NY, NYM1, NYM2, ITER\n LOGICAL FLAG\n\nC Initialise variables\n DATA P /NTOTAL*0.0D0/, PPI /NTOTAL*0.0D0/\n DATA FLAG /.FALSE./, ITER /1/\n\nC Open results file\n OPEN (UNIT=1, FILE='tb2d_output.dat', STATUS='UNKNOWN')\n OPEN (UNIT=2, FILE='tb2d_plot.dat', STATUS='UNKNOWN')\n OPEN (UNIT=3, FILE='tb2d_script.m', STATUS='UNKNOWN')\n\nC Prompt user for input values\n WRITE(*,*) 'Enter value of L/B ratio'\n READ (*,*) LB\n WRITE(*,*) 'Enter value of K=(h1/h0)-1'\n READ (*,*) K\n WRITE(*,*) 'Enter value of NX'\n READ (*,*) NX\n WRITE(*,*) 'Enter value of NY'\n READ (*,*) NY\n\nC Dependent variables\n NXM1 = NX-1\n NXM2 = NX-2\n NYM1 = NY-1\n NYM2 = NY-2\n DX = 1.0/NXM1\n DY = 1.0/NYM1\n DX2 = DX**2\n DY2 = DY**2\n BL2 = (1/LB)**2\n\nC Initialise discrete grid points in the\nC (a) x-direction\n X(1)=0.0\n DO 5,I=2,NX\n X(I)=X(I-1)+DX\n 5 CONTINUE\n\nC (b) y-direction\n Y(1)=0.0\n DO 10,J=2,NY\n Y(J)=Y(J-1)+DY\n 10 CONTINUE\n\nC Initialise film thickness\n DO 15,I=1,NX\n H(I) = 1.0+K*(1-X(I))\n 15 CONTINUE\n\n \nC --------------- ITERATION PROCESS ---------------\n\n\n DO WHILE(FLAG .EQV. (.FALSE.))\n \nC Provide user feedback during iteration process\n WRITE(*,'(10X,A12,I5)') 'Iteration = ', ITER\n ITER = ITER + 1\n\nC Sweep all rows j=2,3,...,J-1\n DO 50,J=2,NYM1\n DO 35,I=2, NXM1\n A(I-1) = (1.0/DX2)+(1.5*K)/(DX*H(I))\n B(I-1) = -2.0*((1.0/DX2)+(BL2/DY2))\n C(I-1) = (1.0/DX2)-(1.5*K)/(DX*H(I))\n D(I-1) = -K/(H(I)**3)-(BL2/DY2)*(P(I,J-1)+P(I,J+1))\n 35 CONTINUE\n \nC Use Thomas algorithm to solve tridiagonal system of algebraic equations \n CALL THOMAS(NXM2,A,B,C,D,N) \n \nC Capture solution from Thomas and apply SOR factor, For\n DO 40,I=2,NXM1 \n P(I,J) = PPI(I,J)+FOR*(D(I-1)-PPI(I,J)) \n PPI(I,J) = P(I,J)\n 40 CONTINUE \n\n 50 CONTINUE \n \nC Sweep all columns i=2,3,...,I-1\n DO 65,I=2,NXM1 \n DO 55,J=2, NYM1 \n A(J-1) = (BL2/DY2) \n B(J-1) = -2.0*((1.0/DX2)+(BL2/DY2)) \n C(J-1) = (BL2/DY2) \n D(J-1) = -K/(H(I)**3)\n + -((1.0/DX2)+(1.5*K)/(DX*H(I)))*P(I-1,J)\n + -((1.0/DX2)-(1.5*K)/(DX*H(I)))*P(I+1,J) \n 55 CONTINUE \n \nC Use Thomas algorithm to solve tridiagonal system of algebraic equations\n CALL THOMAS(NYM2,A,B,C,D,N)\n \nC Capture solution from Thomas and apply SOR factor, For\n DO 60,J=2,NYM1\n P(I,J) = PPI(I,J)+FOR*(D(J-1)-PPI(I,J))\n 60 CONTINUE\n\n 65 CONTINUE\n\nC Convergence test\n CALL CVERGE(NX,NY,P,PPI,FLAG,N)\n \n END DO\n\nC --------------- END ITERATION PROCESS --------------- \n\n\nC Calculate the non-dimensional load\n NDLOAD = DBLINT(P,DX,DY,NXM1,NYM1,N)\n\nC Calculate location of the pivot point, XBAR\n DO 75,J=1,NY\n DO 70,I=1,NX\n XP(I,J)=X(I)*P(I,J)\n 70 CONTINUE\n 75 CONTINUE\n XBAR = DBLINT(XP,DX,DY,NXM1,NYM1,N)/NDLOAD\n\nC Calculate the pressure gradients\nC (a) in the x-direction\n DO 85,J=1,NY\n DPDX(1,J) = (-3.0*P(1,J)+4.0*P(2,J)-P(3,J))/(2.0*DX)\n DPDX(NX,J) = (3.0*P(NX,J)-4.0*P(NXM1,J)+P(NXM2,J))/(2.0*DX)\n DO 80,I=2,NXM1\n DPDX(I,J) = (P(I+1,J)-P(I-1,J))/(2.0*DX)\n 80 CONTINUE\n 85 CONTINUE\n \nC (b) in the y-direction\n DO 90,I=1,NX\n DPDY(I,1) = (-3.0*P(I,1)+4.0*P(I,2)-P(I,3))/(2.0*DY)\n 90 CONTINUE\n \nC Calculate the friction force by integration of the shear \nC stress over the bearing area. The friction force on the\nC lower surface is FFH, whereas that on the lower surface is FF0\n DO 100,J=1,NY\n DO 95,I=1,NX\n TORX0(I,J) = -3.0*H(I)*DPDX(I,J)-1.0/H(I)\n TORXH(I,J) = 3.0*H(I)*DPDX(I,J)-1.0/H(I)\n 95 CONTINUE\n 100 CONTINUE \n FF0 = DBLINT(TORX0,DX,DY,NXM1,NYM1,N)\n FFH = DBLINT(TORXH,DX,DY,NXM1,NYM1,N)\n\nC Calculate the side leakage, Qs\n DO 105,I=1,NX\n QY(I) = -H(I)**3/LB*DPDY(I,1)\n 105 CONTINUE\n QS = -SGLINT(QY,DX,NXM1,N)\n\nC Calculate the end leakage, Qe\n DO 110,J=1,NY\n QX(J) = 0.5*LB*(H(NX)-(H(NX)**3)*DPDX(NX,J))\n 110 CONTINUE\n QE = SGLINT(QX,DY,NYM1,N) \n\n\nC --------------- PRINT RESULTS ---------------\n\n\nC Write results to end of existing results file \n 115 READ(1,*,END=120)\n GO TO 115\n 120 CONTINUE\n WRITE(1,125) LB,K,6*NDLOAD,XBAR,FF0,FFH,QS,QE\n 125 FORMAT(2F10.2,6F10.5)\n\nC Write the pressure profile and pressure gradient \nC along the midplane to results file\n J=(NY+1)/2\n DO 130,I=1,NX \n WRITE(2,'(3F10.6)') X(I), P(I,J), DPDX(I,J) \n 130 CONTINUE\n\nC Create Matlab script file to plot the non-dimensional film\nC thickness and the pressure distribution over the bearing\n WRITE(3,140) 'x=['\n DO 135,J=1,NY\n WRITE(3,145) (X(I),I=1,NX)\n 135 CONTINUE\n 140 FORMAT(A3)\n 145 FORMAT(101F10.5)\n WRITE(3,*) '];'\n WRITE(3,*)\n\n WRITE(3,140) 'y=['\n DO 150,J=1,NY\n WRITE(3,145) (Y(J),I=1,NX)\n 150 CONTINUE\n WRITE(3,*) '];'\n WRITE(3,*)\n\n WRITE(3,140) 'h=['\n DO 155,J=1,NY\n WRITE(3,145) (H(I),I=1,NX)\n 155 CONTINUE\n WRITE(3,*) '];'\n WRITE(3,*)\n\n WRITE(3,140) 'p=['\n DO 160,J=1,NY\n WRITE(3,145) (P(I,J),I=1,NX)\n 160 CONTINUE\n WRITE(3,*) '];'\n WRITE(3,*)\n\nC 3D plot of the film thickness\n WRITE(3,*) 'figure(1);'\n WRITE(3,*) 'hold on;'\n WRITE(3,*) 'surf(x,y,h);'\n WRITE(3,*) 'view(-30,30);'\n WRITE(3,*) 'grid on;'\n WRITE(3,*) 'box on;'\n WRITE(3,*) 'axis([-Inf Inf -Inf Inf 0 Inf]);'\n WRITE(3,*) 'xlabel(''x^*'');'\n WRITE(3,*) 'ylabel(''y^*'');'\n WRITE(3,*) 'zlabel(''h^*'');'\n\nC 3D plot of the pressure distribution\n WRITE(3,*) 'figure(2);'\n WRITE(3,*) 'hold on;'\n WRITE(3,*) 'surf(x,y,p);'\n WRITE(3,*) 'view(30,30);'\n WRITE(3,*) 'grid on;'\n WRITE(3,*) 'box on;'\n WRITE(3,*) 'xlabel(''x^*'');'\n WRITE(3,*) 'ylabel(''y^*'');'\n WRITE(3,*) 'zlabel(''p^*'');'\n\nC Contour plot of the pressure distribution\n WRITE(3,*) 'figure(3);'\n WRITE(3,*) 'hold on;'\n WRITE(3,*) 'contourf(x,y,p,10,''k'');'\n WRITE(3,*) 'box on;'\n WRITE(3,*) 'xlabel(''x^*'');'\n WRITE(3,*) 'ylabel(''y^*'');'\n\nC Close results files\n END FILE (UNIT=1)\n END FILE (UNIT=2)\n END FILE (UNIT=3)\n CLOSE (UNIT=1)\n CLOSE (UNIT=2)\n CLOSE (UNIT=3)\n\n STOP\n END\n\n\nC ====================================================================== \n \n SUBROUTINE THOMAS(NN,A,B,C,D,N) \n\nC This subroutine uses the Thomas algorithm for solving tri-diagonal\nC systems of algebraic equations with Dirichlet boundary conditions. \nC It is used in iterative line-by-line sweeps to determine the pressure\nC distribution over the bearing surfaces. \n \n DOUBLE PRECISION A(N),B(N),C(N),D(N) \n INTEGER N, NN\n\n B(1)=1.0/B(1) \n\n DO 5,I=2,NN \n B(I)=1.0/( B(I)-A(I)*B(I-1)*C(I-1) ) \n D(I)=D(I)-A(I)*B(I-1)*D(I-1) \n 5 CONTINUE \n\n D(NN)=D(NN)*B(NN) \n\n DO 10,I=NN-1,1,-1 \n D(I)=( D(I)-D(I+1)*C(I) )*B(I) \n 10 CONTINUE \n \n RETURN \n END \n\n\nC ======================================================================\n\n SUBROUTINE CVERGE(NX,NY,P,PPI,FLAG,N)\n\nC This subroutine tests for convergence of the solution. If the \nC residual is less than or equal to RESLIM then the solution is \nC converged. If the residual is greater than RESMAX, the solution \nC is diverging and the program is stopped. Otherwise, an over -\nC relaxation factor is applied to speed up the iterative process \nC (This is performed in subroutines TB and CJB)\n\n PARAMETER (RESLIM=1.0D-6, RESMAX=1.0D2)\n DOUBLE PRECISION P(N,N), PPI(N,N), RESID\n LOGICAL FLAG\n\n RESID=0.0D0\n DO 10,J=1,NY\n DO 5,I=1,NX\n RESID = MAX(RESID,ABS(P(I,J)-PPI(I,J)))\n 5 CONTINUE\n 10 CONTINUE\n IF (RESID .LE. RESLIM) THEN\n FLAG = .TRUE.\n ELSE IF (RESID .GE. RESMAX) THEN\n STOP 'Solution not converging'\n ELSE\n DO 20,J=2,NY-1\n DO 15,I=2,NX-1\n PPI(I,J) = P(I,J) \n 15 CONTINUE\n 20 CONTINUE\n END IF\n\n RETURN\n END\n\n\nC ====================================================================== \n\n DOUBLE PRECISION FUNCTION SGLINT(FX,DX,NXM1,N)\n\nC This subroutine performs a single integration using the\nC trapezoidal rule of integration.\n\n DOUBLE PRECISION SUM, DX, FX(N)\n INTEGER I, NXM1, N\n\n SUM = 0.0\n DO 5,I=1,NXM1\n SUM = SUM + FX(I) + FX(I+1)\n 5 CONTINUE\n\n SGLINT = 0.5*DX*SUM\n END\n\n\nC ====================================================================== \n\n DOUBLE PRECISION FUNCTION DBLINT(FXY,DX,DY,NXM1,NYM1,N) \n \nC This subroutine performs a double integration using the\nC trapezoidal rule of integration.\n\n DOUBLE PRECISION SUM, DX, DY, FXY(N,N) \n INTEGER NXM1, NYM1, N \n\n SUM=0.0 \n DO 10,J=1,NYM1 \n DO 5,I=1,NXM1 \n SUM = SUM + FXY(I,J) + FXY(I,J+1) + \n + FXY(I+1,J) + FXY(I+1,J+1) \n 5 CONTINUE \n 10 CONTINUE \n\n DBLINT = 0.25*DX*DY*SUM \n END\n", "meta": {"hexsha": "9531868e7051232d2d5b4264a49f7bbcc1497b24", "size": 11735, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tb2D.f", "max_stars_repo_name": "mhogg/orbit3d", "max_stars_repo_head_hexsha": "ae9a7e8f33bab3bbd4f34b9115fcb785e3c3de19", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tb2D.f", "max_issues_repo_name": "mhogg/orbit3d", "max_issues_repo_head_hexsha": "ae9a7e8f33bab3bbd4f34b9115fcb785e3c3de19", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tb2D.f", "max_forks_repo_name": "mhogg/orbit3d", "max_forks_repo_head_hexsha": "ae9a7e8f33bab3bbd4f34b9115fcb785e3c3de19", "max_forks_repo_licenses": ["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.4110275689, "max_line_length": 91, "alphanum_fraction": 0.5143587559, "num_tokens": 3993, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971871, "lm_q2_score": 0.7490872131147276, "lm_q1q2_score": 0.6766461360222211}} {"text": "module module_random\n\nuse module_types, only: dp\nuse module_constants\n\nimplicit none\n\ninterface randn\n module procedure randn_r,randn_v,randn_a\nend interface randn\n\ncontains\n! ...\n! =====================================================================\n! ...\nfunction randn_r () result(ff)\n\n real(dp) :: ff\n\n ! ... Local variables\n ! ...\n real(dp), parameter :: s = 0.449871D0\n real(dp), parameter :: t = -0.386595D0\n real(dp), parameter :: a = 0.19600D0\n real(dp), parameter :: b = 0.25472D0\n real(dp), parameter :: r1 = 0.27597D0\n real(dp), parameter :: r2 = 0.27846D0\n real(dp) u,v,x,y,q\n\n do\n call RANDOM_NUMBER(u) ! GNU RANDOM GENERATOR\n call RANDOM_NUMBER(v) ! GNU RANDOM GENERATOR\n v = 1.7156D0 * (v - 0.5D0)\n\n ! ... Evaluate the quadratic form\n ! ...\n x = u - s\n y = ABS(v) - t\n q = x*x + y*(a*y - b*x)\n\n if (q .lt. r1) exit\n if (q .gt. r2) cycle\n if (v**2 .LT. -4D0*LOG(u)*u*u) exit\n enddo\n ff = v/u\n\nend function randn_r\n! ...\n! =====================================================================\n! ...\nfunction randn_v (m) result(ff)\n\n integer, intent(in) :: m\n real(dp), dimension(m) :: ff\n\n ! ... Local variables\n ! ...\n integer i\n real(dp), parameter :: s = 0.449871D0\n real(dp), parameter :: t = -0.386595D0\n real(dp), parameter :: a = 0.19600D0\n real(dp), parameter :: b = 0.25472D0\n real(dp), parameter :: r1 = 0.27597D0\n real(dp), parameter :: r2 = 0.27846D0\n real(dp) u,v,x,y,q\n\n do i=1,m\n do\n call RANDOM_NUMBER(u) ! GNU RANDOM GENERATOR\n call RANDOM_NUMBER(v) ! GNU RANDOM GENERATOR\n v = 1.7156D0 * (v - 0.5D0)\n\n ! ... Evaluate the quadratic form\n ! ...\n x = u - s\n y = ABS(v) - t\n q = x*x + y*(a*y - b*x)\n\n if (q .lt. r1) exit\n if (q .gt. r2) cycle\n if (v**2 .LT. -4D0*LOG(u)*u*u) exit\n enddo\n ff(i) = v/u\n enddo\n\nend function randn_v\n! ...\n! =====================================================================\n! ...\nfunction randn_a (m,n) result(ff)\n\n integer, intent(in) :: m\n integer, intent(in) :: n\n real(dp), dimension(:,:), pointer :: ff\n\n ! ... Local variables\n ! ...\n integer i,j\n real(dp), parameter :: s = 0.449871D0\n real(dp), parameter :: t = -0.386595D0\n real(dp), parameter :: a = 0.19600D0\n real(dp), parameter :: b = 0.25472D0\n real(dp), parameter :: r1 = 0.27597D0\n real(dp), parameter :: r2 = 0.27846D0\n real(dp) u,v,x,y,q\n\n if (.not.associated(ff)) allocate(ff(m,n))\n\n do j=1,n\n do i=1,m\n do\n call RANDOM_NUMBER(u) ! GNU RANDOM GENERATOR\n call RANDOM_NUMBER(v) ! GNU RANDOM GENERATOR\n v = 1.7156D0 * (v - 0.5D0)\n\n ! ... Evaluate the quadratic form\n ! ...\n x = u - s\n y = ABS(v) - t\n q = x*x + y*(a*y - b*x)\n\n if (q .lt. r1) exit\n if (q .gt. r2) cycle\n if (v**2 .LT. -4D0*LOG(u)*u*u) exit\n enddo\n ff(i,j) = v/u\n enddo\n enddo\n\nend function randn_a\n! ...\n! =====================================================================\n! ...\nfunction rndname(len,iseed) result(name)\n\ninteger, intent(in) :: len\ninteger, optional :: iseed\ncharacter(len=len) :: name\n\n! ... Local variables\ninteger i,io,il,j,n\ninteger, dimension(:), allocatable :: seed\nreal(dp) r\n\nif (present(iseed)) then\n call random_seed(size=n)\n allocate(seed(n))\n seed(:) = iseed\n call random_seed(put=seed)\nendif\n\nio = ichar('A')\nil = ichar('Z') - io\n\ndo i=1,len\n call random_number(r)\n j = int(io + il*r)\n name(i:i) = char(j)\nenddo\n\nreturn\nend function rndname\n! ...\n! =====================================================================\n! ...\nfunction randseries(n,dlag,periodic) result(g)\n\ninteger, intent(in) :: n\ninteger, intent(in), optional :: dlag\nlogical, intent(in), optional :: periodic\nreal(dp), dimension(n) :: g\n\n! ... Local variables\n! ...\nlogical lper\ninteger nn,i,iter,im,ip\nreal(dp) xsum\nreal(dp), dimension(:), allocatable :: v,f\n\nlper = .false.\nif (present(periodic)) then\n if (periodic) lper = .true.\nendif\n\nif (lper) then\n\n if (present(dlag)) then\n allocate(f(n))\n\n g = randn(n)\n g(n) = g(1)\n\n print*, dlag, g(n), g(1)\n do iter=1,6*abs(dlag)\n do i=1,n\n im = i - 1\n if (im.eq.0) im = n\n ip = i + 1\n if (ip.gt.n) ip = 1\n f(i) = 0.25D0*(g(im)+2*g(i)+g(ip))\n enddo\n g(:) = f(:)\n enddo\n deallocate(f)\n xsum = SUM(g)/n\n g(:) = g(:) - xsum\n xsum = sqrt(DOT_PRODUCT(g,g)/n)\n g(:) = g(:) / xsum\n\n\n else\n g = randn(n)\n g(n) = g(1)\n endif\nelse\n if (present(dlag)) then\n\n ! ... Buffering time series\n ! ...\n nn = n + 20*abs(dlag)\n allocate(v(nn))\n allocate(f(nn))\n\n v = randn(nn)\n do iter=1,6*abs(dlag)\n f(1) = v(1)\n f(nn) = v(nn)\n do i=2,nn-1\n f(i) = 0.25D0*(v(i-1)+2*v(i)+v(i+1))\n enddo\n v = f\n enddo\n\n ! ... Extracting far from boundary\n ! ...\n i = 10*abs(dlag)\n g(:) = f(i+1:i+n)\n\n xsum = SUM(g)/n\n g(:) = g(:) - xsum\n xsum = sqrt(DOT_PRODUCT(g,g)/n)\n g(:) = g(:) / xsum\n\n deallocate(f)\n deallocate(v)\n\n else\n\n g = randn(n)\n\n endif\nendif\n\nend function randseries\n! ...\n! =====================================================================\n! ...\nend module module_random\n", "meta": {"hexsha": "a487a2e2b1dec404b402ee647745aa3ba71f663f", "size": 5759, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/lib/random.f90", "max_stars_repo_name": "quimbp/cosmo", "max_stars_repo_head_hexsha": "d0ca43fcb493c9f630719b8015be095d775a781f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-26T15:02:37.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-25T23:11:04.000Z", "max_issues_repo_path": "src/lib/random.f90", "max_issues_repo_name": "quimbp/cosmo", "max_issues_repo_head_hexsha": "d0ca43fcb493c9f630719b8015be095d775a781f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2018-06-25T10:13:31.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-16T11:15:20.000Z", "max_forks_repo_path": "src/lib/random.f90", "max_forks_repo_name": "quimbp/cosmo", "max_forks_repo_head_hexsha": "d0ca43fcb493c9f630719b8015be095d775a781f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-07-02T16:21:42.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-02T16:21:42.000Z", "avg_line_length": 22.2355212355, "max_line_length": 71, "alphanum_fraction": 0.4559819413, "num_tokens": 1841, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942067038785, "lm_q2_score": 0.7490872075132152, "lm_q1q2_score": 0.6766461348626733}} {"text": " subroutine shapefunctions(psi,eta,N,ShpFcnDeriv,maxint)\n integer maxint\n real*8 eta(maxint),psi(maxint)\n real*8 N(maxint,4), ShpFcnDeriv(maxint,2,4)\n\n do i=1,maxint\n N(i,1)=1./4.*(1.-psi(i))*(1.-eta(i))\n N(i,2)=1./4.*(1.+psi(i))*(1.-eta(i))\n N(i,3)=1./4.*(1.+psi(i))*(1.+eta(i))\n N(i,4)=1./4.*(1.-psi(i))*(1.+eta(i))\n ShpFcnDeriv(i,1,1)=-(1-eta(i))/4.\n ShpFcnDeriv(i,1,2)=(1-eta(i))/4.\n ShpFcnDeriv(i,1,3)=(1+eta(i))/4.\n ShpFcnDeriv(i,1,4)=-(1+eta(i))/4.\n ShpFcnDeriv(i,2,1)=-(1-psi(i))/4.\n ShpFcnDeriv(i,2,2)=-(1+psi(i))/4.\n ShpFcnDeriv(i,2,3)=(1+psi(i))/4.\n ShpFcnDeriv(i,2,4)=(1-psi(i))/4.\n enddo\n\n return\n end", "meta": {"hexsha": "20f2a7b86f2994063b69ce17f8623ca67c671d44", "size": 714, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/shapefunctions.f", "max_stars_repo_name": "imohame/LabCode", "max_stars_repo_head_hexsha": "b7fca6e58f6c26917ff4a8862ab473da282d027d", "max_stars_repo_licenses": ["MIT"], "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/shapefunctions.f", "max_issues_repo_name": "imohame/LabCode", "max_issues_repo_head_hexsha": "b7fca6e58f6c26917ff4a8862ab473da282d027d", "max_issues_repo_licenses": ["MIT"], "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/shapefunctions.f", "max_forks_repo_name": "imohame/LabCode", "max_forks_repo_head_hexsha": "b7fca6e58f6c26917ff4a8862ab473da282d027d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-04-19T08:21:42.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-18T02:43:24.000Z", "avg_line_length": 32.4545454545, "max_line_length": 61, "alphanum_fraction": 0.5042016807, "num_tokens": 310, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308147331957, "lm_q2_score": 0.7248702761768248, "lm_q1q2_score": 0.67661625246761}} {"text": " PROGRAM main\n IMPLICIT none\n REAL*8 pi,d2r,pi2,const\n PARAMETER (pi=4.0d0*datan(1.0d0),d2r=pi/1.8d2,pi2=pi*0.5d0,\n 1 const=1.0d0/dsqrt(2.0d0))\n REAL*8 s,d,r\n REAL*8 normal(3),slip(3),tmp(3),alpha\n REAL*8 p(3),n(3),t(3),fth,fss,fno\n INTEGER i\n 101 read (*,*,END=102) s,d,r\n s = s*d2r\n d = d*d2r\n r = r*d2r\n normal(1) = 0.0d0\n normal(2) = -dsin(d)\n normal(3) = dcos(d)\n alpha = pi2 - s\n tmp(1) = dcos(alpha)*normal(1) - dsin(alpha)*normal(2)\n tmp(2) = dsin(alpha)*normal(1) + dcos(alpha)*normal(2)\n normal(1) = tmp(1)\n normal(2) = tmp(2)\n slip(1) = dcos(r)\n slip(2) = dsin(r)*dcos(d)\n slip(3) = dsin(r)*dsin(d)\n tmp(1) = dcos(alpha)*slip(1) - dsin(alpha)*slip(2)\n tmp(2) = dsin(alpha)*slip(1) + dcos(alpha)*slip(2)\n slip(1) = tmp(1)\n slip(2) = tmp(2)\n do 103 i = 1,3\n t(i) = const*(normal(i)+slip(i))\n p(i) = const*(normal(i)-slip(i))\n 103 continue\n n(1) = normal(2)*slip(3) - normal(3)*slip(2)\n n(2) = normal(3)*slip(1) - normal(1)*slip(3)\n n(3) = normal(1)*slip(2) - normal(2)*slip(1)\n !print *,'p',p(1),p(2),p(3)\n !print *,'n',n(1),n(2),n(3)\n !print *,'t',t(1),t(2),t(3)\n fno = datan(p(3)/dsqrt(p(1)*p(1)+p(2)*p(2)))\n fss = datan(n(3)/dsqrt(n(1)*n(1)+n(2)*n(2)))\n fth = datan(t(3)/dsqrt(t(1)*t(1)+t(2)*t(2)))\n fno = dsin(fno)*dsin(fno)\n fss = dsin(fss)*dsin(fss)\n fth = dsin(fth)*dsin(fth)\n write(*,'(3F10.4)') fno,fss,fth\n goto 101\n 102 continue\n END\n", "meta": {"hexsha": "87b8b1325e21daddc3a049ce158e5418dedb822f", "size": 1742, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/dc2ptn.f", "max_stars_repo_name": "mherman09/src", "max_stars_repo_head_hexsha": "98667f7a2f2e724f2544b6aa1fe7ff278cbf4801", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/dc2ptn.f", "max_issues_repo_name": "mherman09/src", "max_issues_repo_head_hexsha": "98667f7a2f2e724f2544b6aa1fe7ff278cbf4801", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2017-06-27T16:35:46.000Z", "max_issues_repo_issues_event_max_datetime": "2017-07-16T14:55:39.000Z", "max_forks_repo_path": "src/dc2ptn.f", "max_forks_repo_name": "mherman09/src", "max_forks_repo_head_hexsha": "98667f7a2f2e724f2544b6aa1fe7ff278cbf4801", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.5510204082, "max_line_length": 65, "alphanum_fraction": 0.4512055109, "num_tokens": 732, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294983, "lm_q2_score": 0.7248702702332476, "lm_q1q2_score": 0.6766162442349919}} {"text": "! TO FIND THE MAXIMA AND MINIMA OF AN ALGEBRIC FUNCTION USING SECOND DERIVATIVE TEST FROM THE GIVEN VALUES\r\n\r\nprogram maxima_minima\r\n implicit none\r\n real::ddy\r\n integer::i\r\n real,dimension(2)::x\r\n x(1)=-0.6\r\n x(2)=0.3\r\n do i=1,2\r\n if(ddy(x(i)) > 0) then\r\n print*,x(i),\"is the Local Minimum\"\r\n end if\r\n if(ddy(x(i)) < 0) then\r\n print*,x(i),\"is the Local Maximum\"\n end if\n end do\r\nend program\r\n\r\nfunction y(x) !Defining Algebric Function\r\n implicit none\r\n real :: y !Dummy Argument\r\n real :: x !Local Variable\r\n y=5*(x**3)+2*(x**2)-3*x\nend function\r\n\r\nfunction ddy(x) !Second Derivative of above Algebric function\r\n implicit none\r\n real :: ddy !Dummy Argument\r\n real :: x !Local Variable\r\n ddy=30*x+4\nend function\r\n", "meta": {"hexsha": "f455169768959399e928b3c6b2c94ec4e1a2344d", "size": 822, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "8_Maxima_and_Minima_using_second_derivative.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": "8_Maxima_and_Minima_using_second_derivative.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": "8_Maxima_and_Minima_using_second_derivative.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": 24.9090909091, "max_line_length": 107, "alphanum_fraction": 0.5839416058, "num_tokens": 255, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403959948495, "lm_q2_score": 0.7279754607093178, "lm_q1q2_score": 0.6766098004762013}} {"text": "! Objetivo: Gerar um grafico da posicao media, da dispersao e do logaritmo\n! da dispers\u00e3o versus logaritmo de N.\n\nPROGRAM caminhadas_aleatorias2\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 = 200, total_caminhantes = 100000\n INTEGER :: passo, caminhante_n, posicao, passos_validos, posi_array\n INTEGER, PARAMETER :: dados_caminhada_aleatoria = 7\n REAL :: aleatorio\n INTEGER, PARAMETER :: dados_media = 7, dados_dispersao = 8, dados_log = 9\n INTEGER, PARAMETER :: num_pontos = 20, intervalo_passo = 10\n INTEGER, DIMENSION( num_pontos ) :: soma_posicao=0, soma_posicao_quad = 0\n REAL media, dispersao\n REAL, PARAMETER :: caminhantes_real = REAL(total_caminhantes)\n! Iniciar semente\n CALL RAN_SEED (SEQUENCE = iseed)\n DO caminhante_n = 1, total_caminhantes\n posicao = 0\n DO passo = 1, num_pontos\n passos_validos = 0\n DO\n IF (passos_validos==intervalo_passo)EXIT\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\n! (direita e esquerda) assumimos que para aleatorio menor que 0.5 (passo para\n! esquerda) para aleatorio maior que 0.5 (passo para direita) e para 0.5\n! (nao anda).\n IF(aleatorio < 0.5)THEN\n posicao = posicao-1\n passos_validos = passos_validos+1\n ELSE\n IF(aleatorio > 0.5) THEN\n posicao = posicao+1\n passos_validos = passos_validos+1\n END IF\n END IF\n END DO\n soma_posicao(passo) = soma_posicao(passo) + posicao\n soma_posicao_quad(passo) = soma_posicao_quad(passo) + &\n posicao*posicao\n END DO\n END DO\n\n OPEN(dados_media, file=\"dados_media.dat\")\n OPEN(dados_dispersao, file=\"dados_dispersao.dat\")\n OPEN(dados_log, file=\"dados_log.dat\")\n DO passo=10, passos_total, intervalo_passo\n posi_array = passo/intervalo_passo\n media = soma_posicao(posi_array)/caminhantes_real\n dispersao = sqrt(soma_posicao_quad(posi_array)/&\n caminhantes_real - media*media)\n WRITE(dados_media, *) passo, media\n WRITE(dados_dispersao, *) passo, dispersao\n WRITE(dados_log, *) log(REAL(passo)), log(dispersao)\n END DO\n CLOSE(dados_media)\n CLOSE(dados_dispersao)\n CLOSE(dados_log)\n\nEND PROGRAM caminhadas_aleatorias2", "meta": {"hexsha": "5170b34b9d8ed632949e2d2a165959740df36a8c", "size": 2823, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Caminhadas_Aleatorias/caminhada_aleatoria2.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_aleatoria2.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_aleatoria2.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": 40.9130434783, "max_line_length": 78, "alphanum_fraction": 0.6280552604, "num_tokens": 798, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404057671712, "lm_q2_score": 0.7279754489059775, "lm_q1q2_score": 0.6766097966197104}} {"text": "MODULE Phys_consts\n Use nrtype\n !Frequently used mathematical constants (with precision to spare):\n REAL(DP), PARAMETER :: k_B = 1.38064852D-23 ! Boltzman constant (SI units)\n REAL(DP), PARAMETER :: AvogNu = 6.02214086D+23 ! Avogadro's number\n REAL(DP), PARAMETER :: perm0 = 8.85418782D-12 ! permittivity of free space (SI units)\n REAL(DP), PARAMETER :: perm0x4pi = 1.11265006D-10 ! permittivity of free space times 4pi (SI units)\n\n REAL(DP), PARAMETER :: Debye_to_Cm = 3.33564D-30 ! convert Debye units to Coulomb times meter\n REAL(DP), PARAMETER :: Ang_to_m = 1.D-10 ! convert Angstrom units to meters\nEND MODULE Phys_consts\n", "meta": {"hexsha": "b90cb6c6f3086d901d7d5132518daa94726745d4", "size": 692, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "phys_consts.f90", "max_stars_repo_name": "skourno/dielectric_AMMF", "max_stars_repo_head_hexsha": "610ef5ac762f83b9272719c0f952fc01a0d9deb1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "phys_consts.f90", "max_issues_repo_name": "skourno/dielectric_AMMF", "max_issues_repo_head_hexsha": "610ef5ac762f83b9272719c0f952fc01a0d9deb1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "phys_consts.f90", "max_forks_repo_name": "skourno/dielectric_AMMF", "max_forks_repo_head_hexsha": "610ef5ac762f83b9272719c0f952fc01a0d9deb1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.6666666667, "max_line_length": 106, "alphanum_fraction": 0.6705202312, "num_tokens": 221, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403979493139, "lm_q2_score": 0.7279754548076477, "lm_q1q2_score": 0.6766097964137529}} {"text": " subroutine sols33(a,b)\n implicit none\n real*8 ,intent(in):: a(3,3)\n real*8 ,intent(out):: b(3,3)\n real*8 r,c,s,a11,a12,a32,a13,a33,a22,a23,rr\n r=hypot(a(1,1),a(3,1))\n c=a(1,1)/r\n s=a(3,1)/r\n a11=r\n a12= a(2,1)*c+a(3,2)*s\n a32=-a(2,1)*s+a(3,2)*c\n a13= a(3,1)*c+a(3,3)*s\n a33=-a(3,1)*s+a(3,3)*c\n rr=b(1,1)\n b(1,1)= rr*c+b(3,1)*s\n b(3,1)=-rr*s+b(3,1)*c\n rr=b(1,2)\n b(1,2)= rr*c+b(3,2)*s\n b(3,2)=-rr*s+b(3,2)*c\n rr=b(1,3)\n b(1,3)= rr*c+b(3,3)*s\n b(3,3)=-rr*s+b(3,3)*c\n r=hypot(a11,a(2,1))\n c=a11/r\n s=a(2,1)/r\n a11=r\n rr=a12\n a12= rr*c+a(2,2)*s\n a22=-rr*s+a(2,2)*c\n rr=a13\n a13= rr*c+a(3,2)*s\n a23=-rr*s+a(3,2)*c\n rr=b(1,1)\n b(1,1)= rr*c+b(2,1)*s\n b(2,1)=-rr*s+b(2,1)*c\n rr=b(1,2)\n b(1,2)= rr*c+b(2,2)*s\n b(2,2)=-rr*s+b(2,2)*c\n rr=b(1,3)\n b(1,3)= rr*c+b(2,3)*s\n b(2,3)=-rr*s+b(2,3)*c\n r=hypot(a22,a32)\n c=a22/r\n s=a32/r\n a22=r\n rr=a23\n a23= rr*c+a33*s\n a33=-rr*s+a33*c\n rr=b(2,1)\n b(2,1)= rr*c+b(3,1)*s\n b(3,1)=-rr*s+b(3,1)*c\n rr=b(2,2)\n b(2,2)= rr*c+b(3,2)*s\n b(3,2)=-rr*s+b(3,2)*c\n rr=b(2,3)\n b(2,3)= rr*c+b(3,3)*s\n b(3,3)=-rr*s+b(3,3)*c\n b(3,1)=b(3,1)/a33\n b(3,2)=b(3,2)/a33\n b(3,3)=b(3,3)/a33\n b(2,1)=(b(2,1)-a23*b(3,1))/a22\n b(2,2)=(b(2,2)-a23*b(3,2))/a22\n b(2,3)=(b(2,3)-a23*b(3,3))/a22\n b(1,1)=(b(1,1)-a13*b(3,1)-a12*b(2,1))/a11\n b(1,2)=(b(1,2)-a13*b(3,2)-a12*b(2,2))/a11\n b(1,3)=(b(1,3)-a13*b(3,3)-a12*b(2,3))/a11\n return\n end\n", "meta": {"hexsha": "ecee4b693140d4bdeaef426ebb299d07f3d97f9b", "size": 1672, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/sols33.f", "max_stars_repo_name": "noboruatkek/SAD", "max_stars_repo_head_hexsha": "3881a190af8903537774c57b56963ffc94cfc039", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2019-04-01T15:54:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-09T16:47:20.000Z", "max_issues_repo_path": "src/sols33.f", "max_issues_repo_name": "noboruatkek/SAD", "max_issues_repo_head_hexsha": "3881a190af8903537774c57b56963ffc94cfc039", "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/sols33.f", "max_forks_repo_name": "noboruatkek/SAD", "max_forks_repo_head_hexsha": "3881a190af8903537774c57b56963ffc94cfc039", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2017-03-15T08:52:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-19T08:06:40.000Z", "avg_line_length": 24.231884058, "max_line_length": 49, "alphanum_fraction": 0.3947368421, "num_tokens": 943, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403999037782, "lm_q2_score": 0.7279754430043072, "lm_q1q2_score": 0.6766097868660533}} {"text": " subroutine dtblok ( bloks, integs, nbloks, ipivot, iflag,\n *\t\t\t detsgn, detlog )\nc computes the determinant of an almost block diagonal matrix whose\nc plu factorization has been obtained previously in fcblok.\nc *** the logarithm of the determinant is computed instead of the\nc determinant itself to avoid the danger of overflow or underflow\nc inherent in this calculation.\nc\nc parameters\nc bloks, integs, nbloks, ipivot, iflag are as on return from fcblok.\nc\t in particular, iflag = (-1)**(number of interchanges dur-\nc\t ing factorization) if successful, otherwise iflag = 0.\nc detsgn on output, contains the sign of the determinant.\nc detlog on output, contains the natural logarithm of the determi-\nc\t nant if determinant is not zero. otherwise contains 0.\nc\n integer nbloks, index, nrow\n integer integs(3,nbloks),ipivot(1),iflag, i,indexp,ip,k,last\n real bloks(1),detsgn,detlog\nc\n detsgn = iflag\n detlog = 0.\n if (iflag .eq. 0) \t\treturn\n index = 0\n indexp = 0\n do 2 i=1,nbloks\n\t nrow = integs(1,i)\n\t last = integs(3,i)\n\t do 1 k=1,last\n\t ip = index + nrow*(k-1) + ipivot(indexp+k)\n\t detlog = detlog + alog(abs(bloks(ip)))\n 1\t detsgn = detsgn*sign(1.,bloks(ip))\n\t index = nrow*integs(2,i) + index\n 2\t indexp = indexp + nrow\n\t\t\t\t\treturn\n end\n", "meta": {"hexsha": "57e67ae68cbe2d6d26fdd0ccb97a408b754c9552", "size": 1347, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iraf.v2161/math/deboor/dtblok.f", "max_stars_repo_name": "ysBach/irafdocgen", "max_stars_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:19:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T16:48:42.000Z", "max_issues_repo_path": "math/deboor/dtblok.f", "max_issues_repo_name": "kirxkirx/iraf", "max_issues_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-30T13:48:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-02T19:40:25.000Z", "max_forks_repo_path": "math/deboor/dtblok.f", "max_forks_repo_name": "kirxkirx/iraf", "max_forks_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.4054054054, "max_line_length": 72, "alphanum_fraction": 0.6666666667, "num_tokens": 436, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513842182775, "lm_q2_score": 0.7549149978955811, "lm_q1q2_score": 0.6765936118310527}} {"text": " FUNCTION dfridr(func,x,h,err)\r\n INTEGER NTAB\r\n REAL dfridr,err,h,x,func,CON,CON2,BIG,SAFE\r\n PARAMETER (CON=1.4,CON2=CON*CON,BIG=1.E30,NTAB=10,SAFE=2.)\r\n EXTERNAL func\r\nCU USES func\r\n INTEGER i,j\r\n REAL errt,fac,hh,a(NTAB,NTAB)\r\n if(h.eq.0.) pause 'h must be nonzero in dfridr'\r\n hh=h\r\n a(1,1)=(func(x+hh)-func(x-hh))/(2.0*hh)\r\n err=BIG\r\n do 12 i=2,NTAB\r\n hh=hh/CON\r\n a(1,i)=(func(x+hh)-func(x-hh))/(2.0*hh)\r\n fac=CON2\r\n do 11 j=2,i\r\n a(j,i)=(a(j-1,i)*fac-a(j-1,i-1))/(fac-1.)\r\n fac=CON2*fac\r\n errt=max(abs(a(j,i)-a(j-1,i)),abs(a(j,i)-a(j-1,i-1)))\r\n if (errt.le.err) then\r\n err=errt\r\n dfridr=a(j,i)\r\n endif\r\n11 continue\r\n if(abs(a(i,i)-a(i-1,i-1)).ge.SAFE*err)return\r\n12 continue\r\n return\r\n END\r\n", "meta": {"hexsha": "08bd980c0c36936e89f8bca4c38d2fe46cf63389", "size": 879, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/dfridr.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/dfridr.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/dfridr.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.3, "max_line_length": 65, "alphanum_fraction": 0.4857792947, "num_tokens": 333, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336204, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6765935935792609}} {"text": "!\n! Copyright (C) 2001-2007 Quantum ESPRESSO group\n! This file is distributed under the terms of the\n! GNU General Public License. See the file `License'\n! in the root directory of the present distribution,\n! or http://www.gnu.org/copyleft/gpl.txt .\n!\n!-----------------------------------------------------------------------\nsubroutine ylmr2 (lmax2, ng, g, gg, ylm)\n !-----------------------------------------------------------------------\n !\n ! Real spherical harmonics ylm(G) up to l=lmax\n ! lmax2 = (lmax+1)^2 is the total number of spherical harmonics\n ! Numerical recursive algorithm based on the one given in Numerical \n ! Recipes but avoiding the calculation of factorials that generate \n ! overflow for lmax > 11\n !\n USE kinds, ONLY : DP\n USE constants, ONLY : pi, fpi\n implicit none\n !\n integer, intent(in) :: lmax2, ng\n real(DP), intent(in) :: g (3, ng), gg (ng)\n !\n ! BEWARE: gg = g(1)^2 + g(2)^2 +g(3)^2 is not checked on input\n ! incorrect results will ensue if the above does not hold\n !\n real(DP), intent(out) :: ylm (ng,lmax2)\n !\n ! local variables\n !\n real(DP), parameter :: eps = 1.0d-9\n real(DP), allocatable :: cost (:), sent(:), phi (:), Q(:,:,:)\n real(DP) :: c, gmod\n integer :: lmax, ig, l, m, lm\n !\n if (ng < 1 .or. lmax2 < 1) return\n do lmax = 0, 25\n if ((lmax+1)**2 == lmax2) go to 10\n end do\n call errore (' ylmr', 'l > 25 or wrong number of Ylm required',lmax2)\n10 continue\n\n !\n if (lmax == 0) then\n ylm(:,1) = sqrt (1.d0 / fpi)\n return\n end if\n !\n ! theta and phi are polar angles, cost = cos(theta)\n !\n allocate(cost(ng), sent(ng), phi(ng), Q(ng,0:lmax,0:lmax) )\n !\n!$omp parallel default(shared), private(ig,gmod,lm,l,c,m)\n\n!$omp do\n do ig = 1, ng\n gmod = sqrt (gg (ig) )\n if (gmod < eps) then\n cost(ig) = 0.d0\n else\n cost(ig) = g(3,ig)/gmod\n endif\n !\n ! beware the arc tan, it is defined modulo pi\n !\n if (g(1,ig) > eps) then\n phi (ig) = atan( g(2,ig)/g(1,ig) )\n else if (g(1,ig) < -eps) then\n phi (ig) = atan( g(2,ig)/g(1,ig) ) + pi\n else\n phi (ig) = sign( pi/2.d0,g(2,ig) )\n end if\n sent(ig) = sqrt(max(0d0,1.d0-cost(ig)**2))\n enddo\n !\n ! Q(:,l,m) are defined as sqrt ((l-m)!/(l+m)!) * P(:,l,m) where\n ! P(:,l,m) are the Legendre Polynomials (0 <= m <= l)\n !\n lm = 0\n do l = 0, lmax\n c = sqrt (DBLE(2*l+1) / fpi)\n if ( l == 0 ) then\n!$omp do\n do ig = 1, ng\n Q (ig,0,0) = 1.d0\n end do\n else if ( l == 1 ) then\n!$omp do\n do ig = 1, ng\n Q (ig,1,0) = cost(ig)\n Q (ig,1,1) =-sent(ig)/sqrt(2.d0)\n end do\n else\n !\n ! recursion on l for Q(:,l,m)\n !\n do m = 0, l - 2\n!$omp do\n do ig = 1, ng\n Q(ig,l,m) = cost(ig)*(2*l-1)/sqrt(DBLE(l*l-m*m))*Q(ig,l-1,m) &\n - sqrt(DBLE((l-1)*(l-1)-m*m))/sqrt(DBLE(l*l-m*m))*Q(ig,l-2,m)\n end do\n end do\n!$omp do\n do ig = 1, ng\n Q(ig,l,l-1) = cost(ig) * sqrt(DBLE(2*l-1)) * Q(ig,l-1,l-1)\n end do\n!$omp do\n do ig = 1, ng\n Q(ig,l,l) = - sqrt(DBLE(2*l-1))/sqrt(DBLE(2*l))*sent(ig)*Q(ig,l-1,l-1) \n end do\n end if\n !\n ! Y_lm, m = 0\n !\n lm = lm + 1\n!$omp do\n do ig = 1, ng\n ylm(ig, lm) = c * Q(ig,l,0)\n end do\n !\n do m = 1, l\n !\n ! Y_lm, m > 0\n !\n lm = lm + 1\n!$omp do\n do ig = 1, ng\n ylm(ig, lm) = c * sqrt(2.d0) * Q(ig,l,m) * cos (m*phi(ig))\n end do\n !\n ! Y_lm, m < 0\n !\n lm = lm + 1\n!$omp do\n do ig = 1, ng\n ylm(ig, lm) = c * sqrt(2.d0) * Q(ig,l,m) * sin (m*phi(ig))\n end do\n end do\n end do\n !\n!$omp end parallel\n !\n deallocate(cost, sent, phi, Q)\n !\n return\nend subroutine ylmr2\n\n", "meta": {"hexsha": "ca9688da009abaf00ab8ef1f0c41a4f0ea160cd1", "size": 3881, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/apps/miniDFT/tests/src/ylmr2.f90", "max_stars_repo_name": "utdsimmons/ohpc", "max_stars_repo_head_hexsha": "70dc728926a835ba049ddd3f4627ef08db7c95a0", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 692, "max_stars_repo_stars_event_min_datetime": "2015-11-12T13:56:43.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T03:45:59.000Z", "max_issues_repo_path": "tests/apps/miniDFT/tests/src/ylmr2.f90", "max_issues_repo_name": "utdsimmons/ohpc", "max_issues_repo_head_hexsha": "70dc728926a835ba049ddd3f4627ef08db7c95a0", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1096, "max_issues_repo_issues_event_min_datetime": "2015-11-12T09:08:22.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:48:41.000Z", "max_forks_repo_path": "tests/apps/miniDFT/tests/src/ylmr2.f90", "max_forks_repo_name": "utdsimmons/ohpc", "max_forks_repo_head_hexsha": "70dc728926a835ba049ddd3f4627ef08db7c95a0", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 224, "max_forks_repo_forks_event_min_datetime": "2015-11-12T21:17:03.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T00:57:48.000Z", "avg_line_length": 25.8733333333, "max_line_length": 84, "alphanum_fraction": 0.4738469467, "num_tokens": 1457, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513703624558, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6765935865453582}} {"text": "module utils_mod\n\nuse constants_mod\n\ninterface kronproduct\n procedure kronproduct_matmat\n procedure kronproduct_diagMat\nend interface\n\ninterface pp\n procedure vp\n procedure mp\n procedure bp\n procedure tp\n procedure tp5\nend interface\n\ncontains\n\n!! pure elemental function logmean(uL,uR) result(r)\n!! real(dp), intent(in) :: uL,uR\n!! real(dp) :: r\n!! \n!! r = (uL-uR+TOL)/(log(uL)-log(uR)+TOL)\n!! end function\n\npure function calc_dist(a,b) result(dist)\n \n real(dp), intent(in) :: a(N_DIMS),b(N_DIMS)\n real(dp) :: dist\n real(dp) :: v(N_DIMS)\n\n v = b-a\n dist = SQRT(SUM(v*v))\n\nend function\n\npure elemental function logmean(aL,aR) result(r)\n\n real, intent(in) :: aL, aR\n real(dp) :: x,u,r\n real(dp),parameter :: eps = 1.0e-02_dp\n\n x = al/ar\n u = (x*(x-2.0_dp)+1.0_dp)/(x*(x+2.0_dp)+1.0_dp)\n r = merge((aL+aR)*52.50_dp/(105.0_dp + u*(35.0_dp + u*(21.0_dp +u*15.0_dp))), (aL-aR)/log(x), u < eps)\n\nend function\n\n!! subroutine write_headers(outputfp, buflen, buffer)\n!! \n!! character(len=*), intent(in) :: outputfp\n!! integer,intent(in) :: buflen\n!! character(len=*), intent(in) :: buffer(:)\n!! \n!! integer :: ioUnit\n!! integer :: openStat\n!! \n!! character(range(buflen)+2) :: countStr\n!! \n!! OPEN(NEWUNIT = ioUnit , &\n!! FILE = TRIM(outputfp) , &\n!! FORM = 'FORMATTED' , &\n!! STATUS = 'UNKNOWN' , &\n!! POSITION = 'REWIND' , &\n!! RECL = 50000 , &\n!! IOSTAT = openStat )\n!! \n!! IF(openStat.NE.0) THEN\n!! CALL abort('ERROR: cannot open '// TRIM(outputfp))\n!! END IF\n!! \n!! !! write nr. of columns to string\n!! write(countStr,'(i0)') buflen+1\n!! WRITE(ioUnit, '('// trim(countStr) //'(A))') \"# \", buffer(1:buflen)\n!! CLOSE(ioUnit)\n!! \n!! end subroutine\n!! \n\n! This is a simple function to search for an available unit.\n! LUN_MIN and LUN_MAX define the range of possible LUNs to check.\n! The UNIT value is returned by the function, and also by the optional\n! argument. This allows the function to be used directly in an OPEN\n! statement, and optionally save the result in a local variable.\n! If no units are available, -1 is returned.\nfunction utils_get_newunit(unit) result(newunit)\n\n integer, intent(out), optional :: unit\n\n integer, parameter :: LUN_MIN=10, LUN_MAX=1000\n logical :: opened\n integer :: lun\n\n integer :: newunit\n\n newunit=-1\n\n do lun=LUN_MIN,LUN_MAX\n inquire(unit=lun,opened=opened)\n if (.not. opened) then\n newunit=lun\n exit\n end if\n end do\n\n if (present(unit)) unit = newunit\n\nend function\n\nsubroutine write2file(outputfp, buflen, buffer)\n\n character(len=*), intent(in) :: outputfp\n integer,intent(in) :: buflen\n real(dp),intent(in) :: buffer(:)\n\n integer :: ioUnit\n integer :: openStat\n\n character(range(buflen)+2) :: countStr\n\n !OPEN(NEWUNIT = ioUnit , &\n OPEN(UNIT = utils_get_newunit(ioUnit), &\n FILE = TRIM(outputfp) , &\n FORM = 'FORMATTED' , &\n STATUS = 'UNKNOWN' , &\n POSITION = 'APPEND' , &\n RECL = 50000 , &\n IOSTAT = openStat )\n\n IF(openStat.NE.0) THEN\n !CALL abort('ERROR: cannot open '// TRIM(outputfp))\n write (*,*) 'ERROR: cannot open '// TRIM(outputfp)\n return\n END IF\n\n !! write nr. of columns to string\n write(countStr,'(i0)') buflen\n WRITE(ioUnit, '('// trim(countStr) //'(ES32.23,1x))') buffer(1:buflen)\n CLOSE(ioUnit)\n\nend subroutine write2file\n\nfunction incr(n)\n\n implicit none\n\n integer, intent(inout) :: n\n integer :: incr\n\n n = n + 1\n incr = n\n\nend function\n\npure function krondelta(i,j) result(k)\n\n integer, intent(in) :: i,j\n integer :: k\n\n if (i == j) then\n k = 1\n else\n k = 0\n end if\n\nend function\n\npure function isintegerdivisible(a,b) result(c)\n\n integer, intent(in) :: a,b\n integer :: c\n\n if (mod(a,b) == 0) then\n c = 1\n else\n c = 0\n end if\n\nend function\n\nfunction kronproduct_matmat(A,B) result(C)\n\n real(dp), intent(in) :: A(:,:)\n real(dp), intent(in) :: B(:,:)\n\n real(dp) :: C(size(A,1)*size(B,1),size(A,2)*size(B,2))\n\n integer :: i,j\n integer :: bn(2),cn(2)\n\n bn = shape(B)\n cn = shape(A)*shape(B)\n\n do i = 1,cn(1); do j = 1,cn(2)\n C(i,j) = A((i-1)/bn(1)+1,(j-1)/bn(2)+1) * B(mod(i-1,bn(1))+1, mod(j-1,bn(2))+1)\n end do; end do\n\nend function\n\nfunction kronproduct_diagMat(A,B) result(C)\n\n real(dp), intent(in) :: A(:)\n real(dp), intent(in) :: B(:,:)\n\n real(dp) :: C(size(A)*size(B,1),size(A)*size(B,2))\n\n integer :: i,j, iA, jA\n integer :: bn(2),cn(2)\n\n bn = shape(B)\n cn = size(A)*shape(B)\n\n do i = 1,cn(1); do j = 1,cn(2)\n iA = (i-1)/bn(1)+1\n jA = (j-1)/bn(2)+1\n\n if (iA == jA) then\n C(i,j) = A(iA) * B(mod(i-1,bn(1))+1, mod(j-1,bn(2))+1)\n else\n C(i,j) = 0.0_dp\n end if\n end do; end do\n\nend function\n\nfunction eyeproduct(N,B) result(C)\n\n integer, intent(in) :: N\n real(dp), intent(in) :: B(:,:)\n\n real(dp) :: C(N*size(B,1),N*size(B,2))\n\n integer :: i,j, iA, jA\n integer :: bn(2),cn(2)\n\n bn = shape(B)\n cn = N*shape(B)\n\n C = 0.0_dp\n\n do i = 1,cn(1); do j = 1,cn(2)\n iA = (i-1)/bn(1)+1\n jA = (j-1)/bn(2)+1\n\n if (iA == jA) then\n C(i,j) = B(mod(i-1,bn(1))+1, mod(j-1,bn(2))+1)\n end if\n end do; end do\n\nend function\n\npure function calc_index_window(nelems,nranks,rankid) result(window)\n\n integer(kind=8), intent(in) :: nelems\n integer(kind=4), intent(in) :: nranks,rankid\n integer(kind=8) :: window(2)\n\n integer(kind=8) :: a,b,NelemsPerRank,NelemsResidual\n\n NelemsPerRank = nelems / nranks\n NelemsResidual = mod(nelems,INT(nranks,kind=8))\n\n if (rankid < NelemsResidual) then\n a = rankid * NelemsPerRank + mod(INT(rankid,kind=8),NelemsResidual) + 1\n b = a + NelemsPerRank\n else\n a = rankid * NelemsPerRank + NelemsResidual + 1\n b = a + NelemsPerRank - 1\n end if\n\n window = (/a,b/)\n\nend function\n\npure elemental function vmin(a,b) result(c)\n\n real(dp), intent(in) :: a,b\n real(dp) :: c\n\n c = min(a,b)\n\nend function\n\npure elemental function vmax(a,b) result(c)\n\n real(dp), intent(in) :: a,b\n real(dp) :: c\n\n c = max(a,b)\n\nend function\n\nfunction tostr(num) result(str)\n\n integer, intent(in) :: num\n character(len=16) :: str\n\n write(str,'(i0)') num\n\nend function\n\nsubroutine tp5(title,blk)\n\n character(len=*), intent(in) :: title\n real(dp), intent(in) :: blk(:,:,:,:,:)\n\n integer :: i,k,l,q\n\n do q = 1,size(blk,5)\n do l = 1,size(blk,4)\n do k = 1,size(blk,3)\n write (*,'((a12),(a6),(i3),(a6),(i3),(a6),(i3))') trim(title),' | q = ', q, ' | w = ', l, ' | z = ', k\n do i = 1,size(blk,1)\n write (*,'(99(ES12.4))') blk(i,:,k,l,q)\n end do\n write (*,*)\n end do\n write (*,*)\n end do\n write (*,*)\n end do\n write (*,*)\n\nend subroutine\n\nsubroutine tp(title,blk)\n\n character(len=*), intent(in) :: title\n real(dp), intent(in) :: blk(:,:,:,:)\n\n integer :: i,k,l\n\n do l = 1,size(blk,4)\n do k = 1,size(blk,3)\n write (*,'((a12),(a6),(i3),(a6),(i3))') trim(title),' | w = ', l, ' | z = ', k\n do i = 1,size(blk,1)\n write (*,'(99(ES12.4))') blk(i,:,k,l)\n end do\n write (*,*)\n end do\n write (*,*)\n end do\n write (*,*)\n\nend subroutine\n\nsubroutine bp(title,blk)\n\n character(len=*), intent(in) :: title\n real(dp), intent(in) :: blk(:,:,:)\n\n integer :: i,k\n\n do k = 1,size(blk,3)\n write (*,*) trim(title) // ' | z = ' // tostr(k)\n do i = 1,size(blk,1)\n write (*,'(99(ES12.4))') blk(i,:,k)\n end do\n write (*,*)\n end do\n write (*,*)\n\nend subroutine\n\nsubroutine mp(title,mat)\n\n character(len=*), intent(in) :: title\n real(dp), intent(in) :: mat(:,:)\n\n integer :: i\n\n write (*,*) trim(title)\n do i = 1,size(mat,1)\n write (*,'(99(ES12.4))') mat(i,:)\n end do\n write (*,*)\n\nend subroutine\n\nsubroutine vp(title,vec)\n\n character(len=*), intent(in) :: title\n real(dp), intent(in) :: vec(:)\n\n integer :: i\n\n write (*,*) trim(title)\n write (*,'(99(ES12.4))') vec\n write (*,*)\n\nend subroutine\n\nend module\n", "meta": {"hexsha": "71a734d36b77b8ff7fb2aec1c2bb306e914c2ba2", "size": 8906, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/utils/utils_mod.f90", "max_stars_repo_name": "jmark/nemo", "max_stars_repo_head_hexsha": "cf8a6a8bed5c54626f5e300c701b9c278fd5e0cd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source/utils/utils_mod.f90", "max_issues_repo_name": "jmark/nemo", "max_issues_repo_head_hexsha": "cf8a6a8bed5c54626f5e300c701b9c278fd5e0cd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/utils/utils_mod.f90", "max_forks_repo_name": "jmark/nemo", "max_forks_repo_head_hexsha": "cf8a6a8bed5c54626f5e300c701b9c278fd5e0cd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.546835443, "max_line_length": 118, "alphanum_fraction": 0.5094318437, "num_tokens": 2827, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511616741042, "lm_q2_score": 0.7905303087996143, "lm_q1q2_score": 0.6765762831247383}} {"text": "MODULE evaluate\r\nIMPLICIT NONE\r\nPRIVATE\r\nPUBLIC eval3, initl\r\n\r\n! Declare shared data.\r\nREAL, SAVE :: a, b, c, d\r\n\r\n! Declare procedures\r\nCONTAINS\r\n SUBROUTINE eval3 ( x, result )\r\n !\r\n ! Evaluates a third order polynomial of the form:\r\n ! RESULT = A + B*X + C*X**2 + D*X**3\r\n !\r\n ! Declare calling arguments\r\n REAL, INTENT(IN) :: x\r\n REAL, INTENT(OUT) :: result\r\n \r\n ! Calculate result\r\n result = a + b**x + c*x**2 + d*x**3 \r\n \r\n END SUBROUTINE eval3\r\n \r\n SUBROUTINE initl (a1, b1, c1, d1 )\r\n !\r\n ! Subroutine INITL specifies the values of a, b, c, and d\r\n ! to be used when evaluating the polynomial.\r\n !\r\n REAL, INTENT(IN) :: a1, b1, c1, d1\r\n a = a1\r\n b = b1\r\n c = c1\r\n d = d1\r\n END SUBROUTINE initl\r\nEND MODULE evaluate\r\n\r\nPROGRAM test\r\nUSE evaluate\r\nREAL :: a = 1., b = 2., c = 1., d = 2.\r\nCALL initl ( a, b, c, d )\r\nDO i = 1, 10\r\n CALL eval3 ( REAL(i), result )\r\n WRITE (*,*) 'EVAL3(', i, ') = ', result\r\nEND DO\r\nEND PROGRAM test_noentry\r\n", "meta": {"hexsha": "170f22c442d03b42a52173a5062606e24172080a", "size": 1010, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap17/test_noentry.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/chap17/test_noentry.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/chap17/test_noentry.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": 21.4893617021, "max_line_length": 61, "alphanum_fraction": 0.5603960396, "num_tokens": 347, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672593, "lm_q2_score": 0.7905303186696748, "lm_q1q2_score": 0.6765762799458341}} {"text": "program hilbert2\n\n implicit none\n integer :: n\n real(kind=8) :: cond\n\n open(21, file='cond.txt',status='unknown')\n\n do n=2,20\n cond = hilbert_condition(n)\n !print *, \"cond = \",cond\n write(21, 210) n,cond\n 210 format(i4,e16.6)\n enddo\n\n print *, \"Created cond.txt\"\n\n\ncontains\n\n real(kind=8) function hilbert_condition(n)\n\n implicit none\n integer, intent(in) :: n\n real(kind=8), dimension(:),allocatable :: x,b,work\n real(kind=8), dimension(:,:),allocatable :: a\n real(kind=8) :: errnorm, xnorm, rcond, anorm, colsum\n integer :: i, info, lda, ldb, nrhs, j\n integer, dimension(:), allocatable :: ipiv\n integer, allocatable, dimension(:) :: iwork\n character, dimension(1) :: norm\n\n allocate(a(n,n))\n allocate(b(n))\n allocate(x(n))\n allocate(ipiv(n))\n\n nrhs = 1 ! number of right hand sides in b\n lda = n ! leading dimension of a\n ldb = n ! leading dimension of b\n\n do j=1,n\n do i=1,n\n a(i,j) = 1.d0 / (i+j-1.d0)\n enddo\n enddo\n\n x = 1.d0\n b = matmul(a,x)\n\n ! do not need to solve a system, but do need to do factorization:\n call dgetrf(n, n, a, lda, ipiv, info)\n\n ! compute 1-norm needed for condition number\n\n anorm = 0.d0\n do j=1,n\n colsum = 0.d0\n do i=1,n\n colsum = colsum + abs(a(i,j))\n enddo\n anorm = max(anorm, colsum)\n enddo\n\n ! compute condition number of matrix:\n ! note: uses A returned from dgesv with L,U factors:\n\n allocate(work(4*n))\n allocate(iwork(n))\n norm = '1' ! use 1-norm\n call dgecon(norm,n,a,lda,anorm,rcond,work,iwork,info)\n\n if (info /= 0) then\n print *, \"*** Error in dgecon: info = \",info\n endif\n\n hilbert_condition = 1.d0 / rcond\n\n deallocate(a,b,ipiv)\n deallocate(work,iwork)\n\n end function hilbert_condition\n\nend program hilbert2\n", "meta": {"hexsha": "4c740f4c0899b194c415e66d7af9e57021a478ed", "size": 1914, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/labs/lab16/hilbert2.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/lab16/hilbert2.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/lab16/hilbert2.f90", "max_forks_repo_name": "philipwangdk/HPC", "max_forks_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.5176470588, "max_line_length": 69, "alphanum_fraction": 0.5757575758, "num_tokens": 599, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.6765762799458341}} {"text": "program vin\n print *, mod(10,3)\nend program vin\n", "meta": {"hexsha": "5e5df025bc09b263a47a1eb13150b38516742d77", "size": 49, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/output_tests/intrin_mod_integer.f90", "max_stars_repo_name": "clementval/fc", "max_stars_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/output_tests/intrin_mod_integer.f90", "max_issues_repo_name": "clementval/fc", "max_issues_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/output_tests/intrin_mod_integer.f90", "max_forks_repo_name": "clementval/fc", "max_forks_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "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": 12.25, "max_line_length": 20, "alphanum_fraction": 0.693877551, "num_tokens": 16, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8558511396138365, "lm_q2_score": 0.7905303087996143, "lm_q1q2_score": 0.676576265685428}} {"text": "program Example\n implicit none\n\n integer :: num\n character(32) :: str\n\n str = \"0123459\"\n read(str, \"(i10)\") num ! Decimal\n write(*,*) num ! Prints 123459\n\n str = \"abcf123\"\n read(str, \"(z8)\") num ! Hexadecimal\n write(*,*) num ! Prints 180154659\n\n str = \"7651\"\n read(str, \"(o11)\") num ! Octal\n write(*,*) num ! Prints 4009\n\n str = \"1010011010\"\n read(str, \"(b32)\") num ! Binary\n write(*,*) num ! Prints 666\n\nend program\n", "meta": {"hexsha": "472b9f0b1fa4cc64f7284ed5d0dd5f47c8a79393", "size": 481, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Non-decimal-radices-Input/Fortran/non-decimal-radices-input.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Non-decimal-radices-Input/Fortran/non-decimal-radices-input.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Non-decimal-radices-Input/Fortran/non-decimal-radices-input.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 20.0416666667, "max_line_length": 45, "alphanum_fraction": 0.5363825364, "num_tokens": 161, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382236515258, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.6765733597963396}} {"text": "program ASA\n\nimplicit none\nreal,allocatable,dimension(:,:)::A,L,U,C,inv\nreal,allocatable,dimension(:)::sol,B,D,X\nreal:: det\ninteger::n,m,f,i\n\n\n\ncall matriz(A,n,n) !ingresar una matriz nxm\ncall matcof(A,n,C,inv) !matriz de cofactores\n\nallocate(B(n))\n\n\nwrite(*,*) 'hoa'\n\ndo i=1,n\nread(*,*) B(i)\nend do\ncall solcof(B,A,n,D)\n\n\n write(*,*) 'yea'\ndo i=1,n\n write(*,*) D(i)\nend do\n\n write(*,*) 'yea'\n\ncall kramer(A,n,B,X)\ndo i=1,n\nwrite(*,*) X(i)\nend do\n!-----------------------------------------------------------------------\ncontains\n! ----------------------------------------------------------------------\nsubroutine matlu(A,n,m,L,U)\n\n! esta subrutina come una matriz A con n filas y m columnas y devuelve una matriz L y una matriz U\n\nimplicit none\nreal,allocatable,dimension(:,:)::A,L,U,D\ninteger:: k,h,j,n,m\n\t\nallocate(L(n,m),U(n,m),D(n,m))\nD=A\t\nU=A\ndo h= 1,m\n do j= 1,n\n! j filas, h columnas\nif (j>h) then\n do k=1,m\n \tU(j,k)=A(j,k)-(A(j,h)/A(h,h))*A(h,k)\n end do\n L(j,h)=(A(j,h)*(1/A(h,h)))\nelse if (j==h) then\n L(j,h)=1\nelse \n L(j,h)=0\nend if\n end do \nA=U\nend do\t\nA=D\nreturn\nend subroutine\n!--------------------------------------------------------------\n\nsubroutine matdet(A,n,det)\n! esta matriz calcula determinante de una matriz A nxn\n \nimplicit none\nreal,allocatable,dimension(:,:)::A,L,U\ninteger:: i,n\nreal::det\n\n\nif (n==1) then\n det=A(1,1)\nelse \ncall matlu(A,n,n,L,U)\ndet=1\ndo i=1,n\ndet=U(i,i)*det\nend do\nend if\nreturn\nend subroutine\n\n!--------------------------------------------------------------\n\n\nsubroutine matcof(A,n,C,inv)\n! esta subrutina come una matriz A con n filas y m columnas y devuelve una matriz C de cofactores\n\nimplicit none\nreal,allocatable,dimension(:,:)::A,C,L,U,C2,inv\ninteger:: k,h,j,n,i,z\nreal::det\nallocate(C(n,n),C2(n-1,n-1))\n\n!h=f,k=c,i=f,j=c\ndo h=1,n\ndo k=1,n\n\ndo i=1,n\ndo j=1,n\n\n!ME ARMO UNA MATRIZ SIN ESA FILA Y COLUMNA Y LE HAGO EL DETERMINANTE\nif (j/=k.and.i/=h) then\n\n if (ik) then\n C2(i,j-1)=A(i,j)\n else if (i>h.and.jh.and.j>k) then\n C2(i-1,j-1)=A(i,j)\n else\n end if\n \nend if\n \nend do\nend do\n call matdet(C2,(n-1),det)\n C(h,k)=det*((-1)**(h+k)) \nend do\n \nend do\n\ncall matdet(A,n,det)\n\nallocate(inv(n,n))\n\ndo i=1,n\ndo j=1,n\n inv(i,j)=C(j,i)/det\nend do\nend do\n\ndeallocate(C2)\nreturn\n\nend subroutine\n!--------------------------------------------------------------\nsubroutine matriz(mat,fila,colum)\n!esta subrutina te genera una matriz mat de fila y columna ingresada\nreal,allocatable,dimension(:,:)::mat\ninteger:: fila,colum,fila2,colum2,i\n\nWrite(*,*) \"Ingrese las dimenciones de la matriz\"\nWrite(*,*) \"Filas\"\nread(*,*) fila\nWrite(*,*) \"Columnas\"\nread(*,*) colum\n\nallocate(mat(fila,colum))\n\nwrite(*,*) \"Ingrese los elementos de la matriz\"\nfila2=1\ncolum2=1\n\ndo while(fila2<=fila)\n do while(fila2<=fila.and.colum2<=colum)\n Write(*,*)\"Ingrese el elemento de la matriz\",fila2,\",\",colum2\n read(*,*)mat(fila2,colum2)\n colum2=colum2+1\nend do\nfila2=fila2+1\ncolum2=1\nenddo\nWrite(*,*)\"La matriz ingresada fue :\"\ndo i=1,fila,1\nwrite(*,*) mat(i,:)\nend do \nreturn\nend subroutine\n\n!---------------------------------------------\n!error en la division. reveer\nsubroutine solveLU(L,U,n,B,solu)\n! esta subrutina come una matriz L y U de la descomposicion LU, un vector B\n! que es el resultado, donde todas tiene n filas y devuelve el vector solucion\n\n\nimplicit none\nreal,allocatable,dimension(:,:)::L,U\nreal,allocatable,dimension(:)::solu,B,sol2\ninteger:: j,i,n,k\nreal::suma,suma2\n\nallocate(sol2(n),solu(n))\nsol2(:)=1.0d0\nsolu(:)=1.0d0\n\ndo i=1,n\n\nif (i==1) then\n sol2(1)=B(1)/L(1,1)\nelse\nsuma=0\ndo k=1,(i-1)\nsuma=L(i,k)*sol2(k)+suma\nend do \nsol2(i)=(1./(L(i,i)))*(B(i)-suma)\nend if\n\nend do\n\nsolu(n)=sol2(n)/U(n,n)\n\ndo i=1,(n-1)\nsuma2=0\ndo k=(n-i+1),n\nsuma2=U(n-i,k)*solu(k)+suma2\nend do\nsolu(n-i)=(1./(U(n-i,n-i)))*(sol2(n-i)-suma2)\nend do\n\ndeallocate (sol2)\nreturn\nend subroutine\n!------------------------------\nsubroutine solcof(B,A,n,D)\n\nimplicit none\nreal,allocatable,dimension(:,:)::A,inv,C\nreal,allocatable,dimension(:)::D,B\ninteger:: n\n\ncall matcof(A,n,C,inv)\nallocate(D(n))\nD=matmul(inv,B)\n\nreturn\nend subroutine\n!----------------------------\nsubroutine kramer(A,n,B,X)\nimplicit none\nreal, allocatable, dimension(:,:)::A,G,F\nreal, allocatable, dimension(:)::B,X\ninteger:: n,k,j,i\nreal:: det,deter\n\ncall matdet(A,n,det)\n\nallocate(X(n))\n\ndo k=1,n\nallocate(F(n,n))\n\ndo i=1,n\ndo j=1,n\n\nif (k==j) then\nF(i,j)=B(i)\nelse\nF(i,j)=A(i,j)\nend if\nend do\nend do\ndeter=0\ncall matdet(F,n,deter)\nX(k)=deter/det\ndeallocate(F)\n\nend do\nreturn\nend subroutine\n\n!--------------------------------\nend program\n", "meta": {"hexsha": "ac88cb65f80cb775bb5861303686c300d5d2ae2b", "size": 4654, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fedora/DIVIDIR.f90", "max_stars_repo_name": "patricio-c/fortran", "max_stars_repo_head_hexsha": "da11f9e06010399703e8d8e51f57c44a7663857f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fedora/DIVIDIR.f90", "max_issues_repo_name": "patricio-c/fortran", "max_issues_repo_head_hexsha": "da11f9e06010399703e8d8e51f57c44a7663857f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fedora/DIVIDIR.f90", "max_forks_repo_name": "patricio-c/fortran", "max_forks_repo_head_hexsha": "da11f9e06010399703e8d8e51f57c44a7663857f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.8014440433, "max_line_length": 98, "alphanum_fraction": 0.5863773098, "num_tokens": 1632, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382236515259, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.6765733554674184}} {"text": "#include \"macros.h\"\nprogram main\n ! modules:\n use numbers\n use openmpi\n use io\n use parameters\n use fftw\n use diffops \n use vfield\n use rhs\n use timestep\n use run\n \n integer(i4) :: d, iter\n real(dp) :: local_error, relative_error, norm_velfield, norm_test_fieldk, max_error\n complex(dpc), allocatable :: velfieldk(:, :, :, :), div_velfield(:, :, :), test_fieldk(:, :, :, :)\n real(dp), allocatable :: test_fieldxx(:, :, :, :)\n \n _indices\n\n ! initialization:\n call openmpi_init\n call io_init\n call parameters_init\n call fftw_init\n\n write(out, '(79(''=''))')\n write(out, *) \"# Tests begin.\"\n \n allocate(div_velfield(nx_perproc, ny_half, nz), stat=ierr)\n allocate(velfieldk(nx_perproc, ny_half, nz, 3), stat=ierr)\n allocate(test_fieldk(nx_perproc, ny_half, nz, 3), stat=ierr)\n allocate(test_fieldxx(nyy, nzz_perproc, nxx, 3), stat=ierr)\n\n if (ierr/=0) then\n write(out,*) \"Cannot allocate test variables, stopping.\"\n flush(out)\n error stop\n end if\n\n relative_error = 0\n test_fieldxx = 0\n test_fieldk = 0\n\n ! initialize from a random field with no symmetries [gokhan 21-06-24]\n call vfield_random(velfieldk, .false.)\n\n call vfield_norm(velfieldk, norm_velfield, .true.)\n \n ! write(out, *) \"Random state generator relative_error = \", relative_error / norm_velfield\n \n write(out, '(79(''=''))')\n write(out, *) \"Testing forward-backward Fourier transforms ...\"\n\n call fftw_vk2x(velfieldk, test_fieldxx)\n call fftw_vx2k(test_fieldxx, test_fieldk)\n call vfield_norm(test_fieldk, norm_test_fieldk, .true.)\n call vfield_norm(velfieldk - test_fieldk, relative_error, .true.)\n relative_error = relative_error / norm_velfield\n\n write(out, *) \"norm_velfield = \", norm_velfield\n write(out, *) \"norm_test_fieldk = \", norm_test_fieldk \n write(out, *) \"Relative error after k2x and x2k transforms = \", relative_error\n\n if(relative_error < epsilon) then\n write(out, *) \"forward-backward Fourier transform -- Pass\"\n else\n write(out, *) \"forward-backward Fourier transform -- Fail\"\n flush(out)\n error stop\n end if\n\n write(out, '(79(''=''))')\n write(out, *) \"Computing the velocity field's divergence ...\"\n\n call diffops_div(velfieldk, div_velfield)\n max_error = maxval(abs(div_velfield))\n write(out, *) \"max_error = \", max_error\n\n if(max_error < epsilon) then\n write(out, *) \"divergence test -- Pass\"\n else\n write(out, *) \"divergence test -- Fail\"\n flush(out)\n error stop\n end if\n\n \n write(out, '(79(''=''))')\n write(out, *) \"# Tests over. -- Passed all.\"\n write(out, '(79(''=''))')\n call run_exit\n \nend program main", "meta": {"hexsha": "1bedc72c681a25aa6d3be1ecf0e7ffb784cc3957", "size": 2774, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test.f90", "max_stars_repo_name": "gokhanyalniz/dnsbox", "max_stars_repo_head_hexsha": "4c5d6d5d2cd98dbd5b86423f9457b0df8f7ac947", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-18T08:11:15.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T08:11:15.000Z", "max_issues_repo_path": "test.f90", "max_issues_repo_name": "gokhanyalniz/dnsbox", "max_issues_repo_head_hexsha": "4c5d6d5d2cd98dbd5b86423f9457b0df8f7ac947", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-07-20T12:19:11.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-21T20:29:59.000Z", "max_forks_repo_path": "test.f90", "max_forks_repo_name": "gokhanyalniz/dnsbox", "max_forks_repo_head_hexsha": "4c5d6d5d2cd98dbd5b86423f9457b0df8f7ac947", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-12-12T08:18:37.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-03T14:52:53.000Z", "avg_line_length": 29.2, "max_line_length": 102, "alphanum_fraction": 0.6294160058, "num_tokens": 780, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382236515258, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.6765733554674183}} {"text": "MODULE MATLIB\n USE NRTYPE\n IMPLICIT NONE\n CONTAINS\n !-----------------------------------------------------------\n SUBROUTINE FLIP(X)\n IMPLICIT NONE\n COMPLEX(DP), DIMENSION(:) :: X\n X = X(UBOUND(X,1):LBOUND(X,1):-1)\n END SUBROUTINE\n !-----------------------------------------------------------\n FUNCTION EYE(N) RESULT(M)\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: N\n COMPLEX(DP), DIMENSION(N,N) :: M\n INTEGER :: I,J\n DO I = 1,N\n DO J = 1,N\n IF (I.EQ.J) THEN\n M(I,J) = 1._DP\n ELSE\n M(I,J) = 0._DP\n END IF\n END DO\n END DO\n END FUNCTION\n !-----------------------------------------------------------\n FUNCTION ONES(N) RESULT(X)\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: N\n COMPLEX(DP), DIMENSION(N) :: X\n INTEGER :: I\n DO I = 1,N\n X(I) = 1._DP\n END DO\n END FUNCTION\n !-----------------------------------------------------------\n FUNCTION DIAG(X,N) RESULT(M)\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: N\n COMPLEX(DP), DIMENSION(:) :: X\n COMPLEX(DP), DIMENSION(N,N) :: M\n INTEGER :: I\n M = 0._DP\n DO I = 1,N\n M(I,I) = X(I)\n END DO\n END FUNCTION\n !-----------------------------------------------------------\n FUNCTION BAND(E,N,KL,KU) RESULT(M)\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: N, KL, KU\n COMPLEX(DP), INTENT(IN), DIMENSION(:) :: E\n COMPLEX(DP), DIMENSION(N,N) :: M\n INTEGER :: I, J\n M = 0._DP\n DO J = 1,N\n DO I = MAX(1,J-KU),MIN(N,J+KL)\n M(I,J) = E(I)\n END DO\n END DO\n END FUNCTION\n !-----------------------------------------------------------\n FUNCTION DENSE2BAND(M,N,KL,KU) RESULT(MB)\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: N, KL, KU\n COMPLEX(DP), INTENT(IN), DIMENSION(:,:) :: M\n COMPLEX(DP), DIMENSION(KL+KU+1,N) :: MB\n INTEGER :: I, J\n DO J = 1,N\n DO I = MAX(1,J-KU),MIN(N,J+KL)\n MB(KU+1+I-J,J) = M(I,J)\n END DO\n END DO\n END FUNCTION\n !-----------------------------------------------------------\n !SUBROUTINE D2SP(M,N)\n !END SUBROUTINE \n !-----------------------------------------------------------\n FUNCTION INV(A) RESULT(M)\n IMPLICIT NONE\n COMPLEX(DP), DIMENSION(:,:), INTENT(IN) :: A\n COMPLEX(DP), DIMENSION(SIZE(A,1), SIZE(A,2)) :: M\n COMPLEX(DP), DIMENSION(SIZE(A,1)) :: WORK\n COMPLEX(DP), DIMENSION(SIZE(A,1)) :: IPIV\n INTEGER :: N, INFO\n M = A\n N = SIZE(A,1)\n CALL ZGETRF(N,N,M,N,IPIV,INFO) !LAPACK ROUTINE FOR LU FACTORIZATION\n IF (INFO/= 0) THEN\n STOP \"WARNING : Input Matrix is singular !\"\n END IF\n CALL ZGETRI(N,M,N,IPIV,WORK,N,INFO) !INVERSE OF LU\n IF (INFO/= 0) THEN\n STOP \"WARNING : Input Matrix is singular !\"\n END IF\n END FUNCTION\n !-----------------------------------------------------------\nEND MODULE\n", "meta": {"hexsha": "872d37f66d20f0a14ba26813b47aef0550a426fd", "size": 2551, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "Parabolic_Equation/2DPE/.archives/matlib.f03", "max_stars_repo_name": "codorkh/AcousticPE", "max_stars_repo_head_hexsha": "a787496a7800d56743fc606a43acbe9e32de35e0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-03-30T14:02:10.000Z", "max_stars_repo_stars_event_max_datetime": "2017-03-30T14:02:10.000Z", "max_issues_repo_path": "Parabolic_Equation/2DPE/.archives/matlib.f03", "max_issues_repo_name": "codorkh/infratopo", "max_issues_repo_head_hexsha": "a787496a7800d56743fc606a43acbe9e32de35e0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Parabolic_Equation/2DPE/.archives/matlib.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": 25.51, "max_line_length": 77, "alphanum_fraction": 0.4856918855, "num_tokens": 789, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339756938818, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.6765167190407947}} {"text": "! { dg-do run }\n! Test constructors of nested derived types with allocatable components(PR 20541).\n!\n! Contributed by Erik Edelmann \n! and Paul Thomas \n!\n type :: thytype\n integer(4), allocatable :: h(:)\n end type thytype\n\n type :: mytype\n type(thytype), allocatable :: q(:)\n end type mytype\n\n type (mytype) :: x\n type (thytype) :: w(2)\n integer :: y(2) =(/1,2/)\n\n w = (/thytype(y), thytype (2*y)/)\n x = mytype (w)\n if (any ((/((x%q(j)%h(i),j=1,2),i=1,2)/) .ne. (/1,2,2,4/))) call abort ()\n\n x = mytype ((/thytype(3*y), thytype (4*y)/))\n if (any ((/((x%q(j)%h(i),j=1,2),i=1,2)/) .ne. (/3,4,6,8/))) call abort ()\n\nend\n", "meta": {"hexsha": "08c3bdf696ebdfaec0eac3dd6ac4b3f471e0f525", "size": 690, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/alloc_comp_constructor_2.f90", "max_stars_repo_name": "maurizioabba/rose", "max_stars_repo_head_hexsha": "7597292cf14da292bdb9a4ef573001b6c5b9b6c0", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/alloc_comp_constructor_2.f90", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/alloc_comp_constructor_2.f90", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 25.5555555556, "max_line_length": 82, "alphanum_fraction": 0.5608695652, "num_tokens": 270, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339596505965, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.6765167080752071}} {"text": "! Module for performing an anti-transpose.\n! An anti-transpose is a transpose along the anti-diagonal.\nmodule antitr_module\n implicit none\n\n public :: antitr\n\ncontains\n\n ! Performs anti-transpose.\n function antitr (a, n) result (at)\n ! a is input matrix, at is anti-transposed matrix.\n integer, dimension (n, n), intent (in) :: a\n integer, intent (in) :: n\n integer, dimension (n, n) :: at\n\n integer :: i\n\n do i = 1, n\n at(:, n - i + 1) = a(i, n:1:-1)\n end do\n\n end function antitr\n \nend module antitr_module\n\n! Driver code.\nprogram main\n use antitr_module\n implicit none\n\n ! Size of the matrix.\n integer, parameter :: n = 5\n\n ! Declarations.\n integer, dimension (n, n) :: a\n integer, dimension (n) :: temp\n integer :: i\n\n ! Constructing the matrix to anti-transpose.\n ! Just filling out the values to be 1 through n^2.\n do i = 1, n\n temp(i) = i\n end do\n\n do i = 1, n\n a(i, :) = temp\n temp = temp + n\n end do\n\n ! Perform anti-transposes and prints results.\n print '(a)', 'Perform an anti-traspose.'\n print '(a)', 'Before:'\n call print_mat(a, n)\n \n a = antitr(a, n)\n\n print '(2a)', new_line('a'), 'After:'\n call print_mat(a, n)\n\ncontains\n\n ! Helper subroutine for printing the matrix nicely.\n subroutine print_mat (a, n)\n integer, dimension (n, n), intent (in) :: a\n integer, intent (in) :: n\n integer :: i, j\n\n do i = 1, n\n do j = 1, n\n write (*, '(i3, x)', advance='no') a(i, j)\n end do\n print *, ''\n end do\n\n end subroutine print_mat\n\nend program main", "meta": {"hexsha": "ab66326e8206284c99f670e94408758736b8579c", "size": 1710, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "antitranspose.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": "antitranspose.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": "antitranspose.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": 21.9230769231, "max_line_length": 59, "alphanum_fraction": 0.5502923977, "num_tokens": 485, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339596505965, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.6765167021970088}} {"text": "program problem45\n implicit none\n integer*8 :: n,temp\n\n do n=286,huge(n)\n temp=T(n)\n if (is_P(temp) .and. is_H(temp)) exit\n end do\n\n print *, n, T(n)\n\ncontains\n\n pure function T(n)\n implicit none\n integer*8, intent(in) :: n\n integer :: T\n T=n*(n+1)/2\n end function T\n\n pure function is_P(P)\n implicit none\n integer*8, intent(in) :: P\n double precision :: n\n logical :: is_P\n n = (sqrt(dble(24*P + 1)) + 1)/6\n is_P = (whole(n))\n end function is_P\n\n pure function is_H(H)\n implicit none\n integer*8, intent(in) :: H\n double precision :: n\n logical :: is_H\n n = (sqrt(dble(8*H + 1)) + 1)/4\n is_H = (whole(n))\n end function is_H\n\n pure function whole(x)\n implicit none\n double precision, intent(in) :: x\n logical :: whole\n whole = (mod(x,1.0) == 0.0)\n end function whole\n\nend program problem45\n", "meta": {"hexsha": "af0bebb7ec273bed2ddf58c696468c9d138cad66", "size": 943, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "problem45.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": "problem45.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": "problem45.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": 20.0638297872, "max_line_length": 42, "alphanum_fraction": 0.5418875928, "num_tokens": 297, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299653388754, "lm_q2_score": 0.731058584489497, "lm_q1q2_score": 0.6763973087879046}} {"text": "C$Procedure M2Q ( Matrix to quaternion )\n\n SUBROUTINE M2Q ( R, Q )\n\nC$ Abstract\nC\nC Find a unit quaternion corresponding to a specified rotation\nC matrix.\nC\nC$ Disclaimer\nC\nC THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE\nC CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.\nC GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE\nC ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE\nC PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED \"AS-IS\"\nC TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY\nC WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A\nC PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC\nC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE\nC SOFTWARE AND RELATED MATERIALS, HOWEVER USED.\nC\nC IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA\nC BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT\nC LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,\nC INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,\nC REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE\nC REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.\nC\nC RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF\nC THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY\nC CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE\nC ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.\nC\nC$ Required_Reading\nC\nC ROTATION\nC\nC$ Keywords\nC\nC MATH\nC MATRIX\nC ROTATION\nC\nC$ Declarations\n \n DOUBLE PRECISION R ( 3, 3 )\n DOUBLE PRECISION Q ( 0 : 3 )\n \nC$ Brief_I/O\nC\nC Variable I/O Description\nC -------- --- --------------------------------------------------\nC R I A rotation matrix.\nC Q O A unit quaternion representing R.\nC\nC$ Detailed_Input\nC\nC R is a rotation matrix.\nC\nC$ Detailed_Output\nC\nC Q is a unit-length SPICE-style quaternion\nC representing R. See the discussion of quaternion\nC styles in Particulars below.\nC\nC Q is a 4-dimensional vector. If R rotates vectors\nC in the counterclockwise sense by an angle of theta\nC radians about a unit vector A, where \nC\nC 0 < theta < pi\nC - -\nC\nC then letting h = theta/2,\nC\nC Q = ( cos(h), sin(h)A , sin(h)A , sin(h)A ).\nC 1 2 3\nC\nC The restriction that theta must be in the range\nC [0, pi] determines the output quaternion Q\nC uniquely except when theta = pi; in this special\nC case, both of the quaternions\nC\nC Q = ( 0, A , A , A )\nC 1 2 3\nC and\nC\nC Q = ( 0, -A , -A , -A )\nC 1 2 3\nC\nC are possible outputs.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC 1) If R is not a rotation matrix, the error SPICE(NOTAROTATION)\nC is signaled.\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC A unit quaternion is a 4-dimensional vector for which the sum of\nC the squares of the components is 1. Unit quaternions can be used\nC to represent rotations in the following way: given a rotation\nC angle theta, where\nC\nC 0 < theta < pi\nC - -\nC\nC and a unit vector A, we can represent the transformation that\nC rotates vectors in the counterclockwise sense by theta radians\nC about A using the quaternion Q, where\nC\nC Q = \nC\nC ( cos(theta/2), sin(theta/2)a , sin(theta/2)a , sin(theta/2)a )\nC 1 2 3\nC\nC As mentioned in Detailed Output, our restriction on the range of\nC theta determines Q uniquely, except when theta = pi.\nC\nC The SPICELIB routine Q2M is an one-sided inverse of this routine:\nC given any rotation matrix R, the calls\nC\nC CALL M2Q ( R, Q )\nC CALL Q2M ( Q, R )\nC\nC leave R unchanged, except for round-off error. However, the\nC calls\nC\nC CALL Q2M ( Q, R )\nC CALL M2Q ( R, Q )\nC\nC might preserve Q or convert Q to -Q.\nC\nC\nC\nC Quaternion Styles\nC -----------------\nC\nC There are different \"styles\" of quaternions used in \nC science and engineering applications. Quaternion styles\nC are characterized by \nC\nC - The order of quaternion elements\nC\nC - The quaternion multiplication formula\nC\nC - The convention for associating quaternions\nC with rotation matrices\nC\nC Two of the commonly used styles are\nC\nC - \"SPICE\"\nC\nC > Invented by Sir William Rowan Hamilton\nC > Frequently used in mathematics and physics textbooks\nC\nC - \"Engineering\"\nC\nC > Widely used in aerospace engineering applications\nC\nC\nC SPICELIB subroutine interfaces ALWAYS use SPICE quaternions.\nC Quaternions of any other style must be converted to SPICE\nC quaternions before they are passed to SPICELIB routines.\nC \nC\nC Relationship between SPICE and Engineering Quaternions\nC ------------------------------------------------------\nC\nC Let M be a rotation matrix such that for any vector V, \nC\nC M*V\nC\nC is the result of rotating V by theta radians in the \nC counterclockwise direction about unit rotation axis vector A.\nC Then the SPICE quaternions representing M are\nC\nC (+/-) ( cos(theta/2), \nC sin(theta/2) A(1), \nC sin(theta/2) A(2), \nC sin(theta/2) A(3) ) \nC\nC while the engineering quaternions representing M are \nC\nC (+/-) ( -sin(theta/2) A(1), \nC -sin(theta/2) A(2), \nC -sin(theta/2) A(3),\nC cos(theta/2) )\nC\nC For both styles of quaternions, if a quaternion q represents\nC a rotation matrix M, then -q represents M as well.\nC\nC Given an engineering quaternion\nC\nC QENG = ( q0, q1, q2, q3 )\nC\nC the equivalent SPICE quaternion is\nC\nC QSPICE = ( q3, -q0, -q1, -q2 )\nC\nC\nC Associating SPICE Quaternions with Rotation Matrices\nC ----------------------------------------------------\nC\nC Let FROM and TO be two right-handed reference frames, for\nC example, an inertial frame and a spacecraft-fixed frame. Let the\nC symbols\nC\nC V , V\nC FROM TO\nC\nC denote, respectively, an arbitrary vector expressed relative to\nC the FROM and TO frames. Let M denote the transformation matrix\nC that transforms vectors from frame FROM to frame TO; then\nC\nC V = M * V\nC TO FROM\nC\nC where the expression on the right hand side represents left\nC multiplication of the vector by the matrix.\nC\nC Then if the unit-length SPICE quaternion q represents M, where\nC\nC q = (q0, q1, q2, q3)\nC\nC the elements of M are derived from the elements of q as follows:\nC\nC +- -+\nC | 2 2 |\nC | 1 - 2*( q2 + q3 ) 2*(q1*q2 - q0*q3) 2*(q1*q3 + q0*q2) |\nC | |\nC | |\nC | 2 2 |\nC M = | 2*(q1*q2 + q0*q3) 1 - 2*( q1 + q3 ) 2*(q2*q3 - q0*q1) |\nC | |\nC | |\nC | 2 2 |\nC | 2*(q1*q3 - q0*q2) 2*(q2*q3 + q0*q1) 1 - 2*( q1 + q2 ) |\nC | |\nC +- -+\nC\nC Note that substituting the elements of -q for those of q in the\nC right hand side leaves each element of M unchanged; this shows\nC that if a quaternion q represents a matrix M, then so does the\nC quaternion -q.\nC\nC To map the rotation matrix M to a unit quaternion, we start by\nC decomposing the rotation matrix as a sum of symmetric\nC and skew-symmetric parts:\nC\nC 2\nC M = [ I + (1-cos(theta)) OMEGA ] + [ sin(theta) OMEGA ]\nC\nC symmetric skew-symmetric\nC\nC\nC OMEGA is a skew-symmetric matrix of the form\nC\nC +- -+\nC | 0 -n3 n2 |\nC | |\nC OMEGA = | n3 0 -n1 |\nC | |\nC | -n2 n1 0 |\nC +- -+\nC\nC The vector N of matrix entries (n1, n2, n3) is the rotation axis\nC of M and theta is M's rotation angle. Note that N and theta\nC are not unique.\nC\nC Let\nC\nC C = cos(theta/2)\nC S = sin(theta/2)\nC\nC Then the unit quaternions Q corresponding to M are\nC\nC Q = +/- ( C, S*n1, S*n2, S*n3 )\nC\nC The mappings between quaternions and the corresponding rotations\nC are carried out by the SPICELIB routines\nC\nC Q2M {quaternion to matrix}\nC M2Q {matrix to quaternion}\nC\nC M2Q always returns a quaternion with scalar part greater than\nC or equal to zero.\nC\nC\nC SPICE Quaternion Multiplication Formula\nC ---------------------------------------\nC\nC Given a SPICE quaternion \nC\nC Q = ( q0, q1, q2, q3 )\nC\nC corresponding to rotation axis A and angle theta as above, we can\nC represent Q using \"scalar + vector\" notation as follows:\nC\nC s = q0 = cos(theta/2)\nC\nC v = ( q1, q2, q3 ) = sin(theta/2) * A\nC\nC Q = s + v\nC\nC Let Q1 and Q2 be SPICE quaternions with respective scalar\nC and vector parts s1, s2 and v1, v2:\nC \nC Q1 = s1 + v1\nC Q2 = s2 + v2\nC\nC We represent the dot product of v1 and v2 by\nC\nC \nC\nC and the cross product of v1 and v2 by\nC\nC v1 x v2\nC\nC Then the SPICE quaternion product is\nC\nC Q1*Q2 = s1*s2 - + s1*v2 + s2*v1 + (v1 x v2) \nC\nC If Q1 and Q2 represent the rotation matrices M1 and M2 \nC respectively, then the quaternion product\nC\nC Q1*Q2\nC\nC represents the matrix product\nC\nC M1*M2\nC\nC\nC$ Examples\nC\nC 1) A case amenable to checking by hand calculation:\nC\nC To convert the rotation matrix\nC\nC +- -+\nC | 0 1 0 |\nC | |\nC R = | -1 0 0 |\nC | |\nC | 0 0 1 |\nC +- -+\nC\nC also represented as\nC\nC [ pi/2 ]\nC 3\nC\nC to a quaternion, we can use the code fragment\nC\nC CALL ROTATE ( HALFPI(), 3, R )\nC CALL M2Q ( R, Q )\nC\nC M2Q will return Q as\nC\nC ( sqrt(2)/2, 0, 0, -sqrt(2)/2 )\nC\nC Why? Well, R is a reference frame transformation that\nC rotates vectors by -pi/2 radians about the axis vector\nC\nC A = ( 0, 0, 1 )\nC\nC Equivalently, R rotates vectors by pi/2 radians in\nC the counterclockwise sense about the axis vector \nC\nC -A = ( 0, 0, -1 ) \nC\nC so our definition of Q,\nC\nC h = theta/2\nC\nC Q = ( cos(h), sin(h)A , sin(h)A , sin(h)A )\nC 1 2 3\nC\nC implies that in this case,\nC\nC Q = ( cos(pi/4), 0, 0, -sin(pi/4) )\nC\nC = ( sqrt(2)/2, 0, 0, -sqrt(2)/2 )\nC\nC\nC 2) Finding a quaternion that represents a rotation specified by\nC a set of Euler angles:\nC\nC Suppose our original rotation R is the product\nC\nC [ TAU ] [ pi/2 - DELTA ] [ ALPHA ] \nC 3 2 3\nC\nC The code fragment\nC\nC CALL EUL2M ( TAU, HALFPI() - DELTA, ALPHA,\nC . 3, 2, 3, R )\nC\nC CALL M2Q ( R, Q )\nC\nC yields a quaternion Q that represents R.\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC N.J. Bachman (JPL)\nC W.L. Taber (JPL)\nC \nC$ Version\nC\nC- SPICELIB Version 2.0.1, 27-FEB-2008 (NJB)\nC\nC Updated header; added information about SPICE \nC quaternion conventions. Made various minor edits\nC throughout header.\nC\nC- SPICELIB Version 2.0.0, 17-SEP-1999 (WLT)\nC\nC The routine was re-implemented to sharpen the numerical\nC stability of the routine and eliminate calls to SIN\nC and COS functions.\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, 30-AUG-1990 (NJB)\nC\nC-&\n \nC$ Index_Entries\nC\nC matrix to quaternion\nC\nC-&\n \nC\nC SPICELIB functions\nC\n LOGICAL ISROT\n \nC\nC Local parameters\nC\n \nC\nC NTOL and DETOL are used to determine whether R is a rotation\nC matrix.\nC\nC NTOL is the tolerance for the norms of the columns of R.\nC\nC DTOL is the tolerance for the determinant of a matrix whose\nC columns are the unitized columns of R.\nC\nC\n DOUBLE PRECISION NTOL\n PARAMETER ( NTOL = 0.1D0 )\n \n DOUBLE PRECISION DTOL\n PARAMETER ( DTOL = 0.1D0 )\n \nC\nC Local Variables\nC\n DOUBLE PRECISION C\n DOUBLE PRECISION CC4\n DOUBLE PRECISION FACTOR\n DOUBLE PRECISION L2\n DOUBLE PRECISION MTRACE\n DOUBLE PRECISION POLISH\n DOUBLE PRECISION S(3)\n DOUBLE PRECISION S114\n DOUBLE PRECISION S224\n DOUBLE PRECISION S334\n DOUBLE PRECISION TRACE\n \n \nC\nC If R is not a rotation matrix, we can't proceed.\nC\n IF ( .NOT. ISROT ( R, NTOL, DTOL ) ) THEN\n CALL CHKIN ( 'M2Q' )\n CALL SETMSG ( 'Input matrix was not a rotation.' )\n CALL SIGERR ( 'SPICE(NOTAROTATION)' )\n CALL CHKOUT ( 'M2Q' )\n RETURN\n \n END IF\nC\nC\nC If our quaternion is C, S1, S2, S3 (the S's being the imaginary\nC part) and we let\nC\nC CSi = C * Si\nC Sij = Si * Sj\nC\nC then the rotation matrix corresponding to our quaternion is:\nC\nC R(1,1) = 1.0D0 - 2*S22 - 2*S33\nC R(2,1) = 2*S12 + 2*CS3\nC R(3,1) = 2*S13 - 2*CS2\nC\nC R(1,2) = 2*S12 - 2*CS3\nC R(2,2) = 1.0D0 - 2*S11 - 2*S33\nC R(3,2) = 2*S23 + 2*CS1\nC\nC R(1,3) = 2*S13 + 2*CS2\nC R(2,3) = 2*S23 - 2*CS1\nC R(3,3) = 1.0D0 - 2*S11 - 2*S22\nC\nC From the above we can see that\nC\nC TRACE = 3 - 4*(S11 + S22 + S33)\nC\nC so that\nC\nC\nC 1.0D0 + TRACE = 4 - 4*(S11 + S22 + S33)\nC = 4*(CC + S11 + S22 + S33)\nC - 4*(S11 + S22 + S33)\nC = 4*CC\nC\nC Thus up to sign\nC\nC C = 0.5D0 * DSQRT( 1.0D0 + TRACE )\nC\nC But we also have\nC\nC 1.0D0 + TRACE - 2.0D0*R(i,i) = 4.0D0 - 4.0D0(Sii + Sjj + Skk)\nC - 2.0D0 + 4.0D0(Sjj + Skk )\nC\nC = 2.0D0 - 4.0D0*Sii\nC\nC So that\nC\nC 1.0D0 - TRACE + 2.0D0*R(i,i) = 4.0D0*Sii\nC\nC and so up to sign\nC\nC Si = 0.5D0*DSQRT( 1.0D0 - TRACE + 2.0D0*R(i,i) )\nC\nC in addition to this observation, we note that all of the\nC product pairs can easily be computed\nC\nC CS1 = (R(3,2) - R(2,3))/4.0D0\nC CS2 = (R(1,3) - R(3,1))/4.0D0\nC CS3 = (R(2,1) - R(1,2))/4.0D0\nC S12 = (R(2,1) + R(1,2))/4.0D0\nC S13 = (R(3,1) + R(1,3))/4.0D0\nC S23 = (R(2,3) + R(3,2))/4.0D0\nC\nC But taking sums or differences of numbers that are nearly equal\nC or nearly opposite results in a loss of precision. As a result\nC we should take some care in which terms to select when computing\nC C, S1, S2, S3. However, by simply starting with one of the\nC large quantities cc, S11, S22, or S33 we can make sure that we\nC use the best of the 6 quantities above when computing the\nC remaining components of the quaternion.\nC\n \n TRACE = R(1,1) + R(2,2) + R(3,3)\n MTRACE = 1.0D0 - TRACE\n \n CC4 = 1.0D0 + TRACE\n S114 = MTRACE + 2.0D0*R(1,1)\n S224 = MTRACE + 2.0D0*R(2,2)\n S334 = MTRACE + 2.0D0*R(3,3)\n \nC\nC Note that if you simply add CC4 + S114 + S224 + S334\nC you get four. Thus at least one of the 4 terms is greater than 1.\nC\n IF ( 1.0D0 .LE. CC4 ) THEN\n C = DSQRT ( CC4 * 0.25D0 )\n FACTOR = 1.0D0 /( C * 4.0D0 )\n \n S(1) = ( R(3,2) - R(2,3) )*FACTOR\n S(2) = ( R(1,3) - R(3,1) )*FACTOR\n S(3) = ( R(2,1) - R(1,2) )*FACTOR\n \n ELSE IF ( 1.0D0 .LE. S114 ) THEN\n \n S(1) = DSQRT ( S114 * 0.25D0 )\n FACTOR = 1.0D0 /( S(1) * 4.0D0 )\n \n C = ( R(3,2) - R(2,3) ) * FACTOR\n S(2) = ( R(1,2) + R(2,1) ) * FACTOR\n S(3) = ( R(1,3) + R(3,1) ) * FACTOR\n \n \n ELSE IF ( 1.0D0 .LE. S224 ) THEN\n \n S(2) = DSQRT ( S224 * 0.25D0 )\n FACTOR = 1.0D0 /( S(2) * 4.0D0 )\n \n C = ( R(1,3) - R(3,1) ) * FACTOR\n S(1) = ( R(1,2) + R(2,1) ) * FACTOR\n S(3) = ( R(2,3) + R(3,2) ) * FACTOR\n \n ELSE\n \n S(3) = DSQRT ( S334 * 0.25D0 )\n FACTOR = 1.0D0 /( S(3) * 4.0D0 )\n \n C = ( R(2,1) - R(1,2) ) * FACTOR\n S(1) = ( R(1,3) + R(3,1) ) * FACTOR\n S(2) = ( R(2,3) + R(3,2) ) * FACTOR\n \n END IF\nC\nC If the magnitude of this quaternion is not one, we polish it\nC up a bit.\nC\n L2 = C*C + S(1)*S(1) + S(2)*S(2) + S(3)*S(3)\n \n IF ( L2 .NE. 1.0D0 ) THEN\n POLISH = 1.0D0/DSQRT(L2)\n C = C*POLISH\n S(1) = S(1)*POLISH\n S(2) = S(2)*POLISH\n S(3) = S(3)*POLISH\n END IF\n \n IF ( C .GT. 0.0D0 ) THEN\n Q(0) = C\n Q(1) = S(1)\n Q(2) = S(2)\n Q(3) = S(3)\n ELSE\n Q(0) = -C\n Q(1) = -S(1)\n Q(2) = -S(2)\n Q(3) = -S(3)\n END IF\n \n RETURN\n END\n", "meta": {"hexsha": "a8ed7bccd58075e497d1e64da6ea2dc94c0388d3", "size": 19056, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/m2q.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/m2q.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/m2q.f", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 29.1376146789, "max_line_length": 72, "alphanum_fraction": 0.5044605374, "num_tokens": 6020, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299570920386, "lm_q2_score": 0.731058584489497, "lm_q1q2_score": 0.6763973027589838}} {"text": "C\nC\t$Id$\nC\n SUBROUTINE CSSMSURF (N,X,Y,Z,U,LIST,LPTR,LEND,IFLGS,\n . SIGMA,W,SM,SMTOL,GSTOL,LPRNT, F,\n . GRAD,IER)\n INTEGER N, LIST(*), LPTR(*), LEND(N), IFLGS, LPRNT,\n . IER\n DOUBLE PRECISION X(N), Y(N), Z(N), U(N), SIGMA(*),\n . W(N), SM, SMTOL, GSTOL, F(N),\n . GRAD(3,N)\nC\nC***********************************************************\nC\nC From SSRFPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 07/21/98\nC\nC Given a triangulation of N nodes on the unit sphere with\nC data values U at the nodes and tension factors SIGMA\nC associated with the arcs, this routine determines a set of\nC nodal function values F and gradients GRAD = (FX,FY,FZ)\nC such that a quadratic functional Q1(F,GRAD) is minimized\nC subject to the constraint Q2(F) .LE. SM for Q2(F) =\nC (U-F)**T*W*(U-F), where W is a diagonal matrix of positive\nC weights. The functional Q1 is an approximation to the\nC linearized curvature over the triangulation of a C-1 fun-\nC ction F(V), V a unit vector, which interpolates the nodal\nC values and gradients. Subroutines CSINTRC1 and CSUNIF may be\nC called to evaluate F at arbitrary points.\nC\nC The smoothing procedure is an extension of the method\nC for cubic spline smoothing due to C. Reinsch -- Numer.\nC Math., 10 (1967) and 16 (1971). Refer to Function CSFVAL\nC for a further description of the interpolant F. Letting\nC D1F(T) and D2F(T) denote first and second derivatives of F\nC with respect to a parameter T varying along a triangula-\nC tion arc, Q1 is the sum of integrals over the arcs of\nC D2F(T)**2 + ((SIGMA/L)*(D1F(T)-S))**2 where L denotes arc-\nC length, SIGMA is the appropriate tension factor, and S is\nC the slope of the linear function of T which interpolates\nC the values of F at the endpoints of the arc. Introducing\nC a smoothing parameter P, and assuming the constraint is\nC active, the problem is equivalent to minimizing Q(P,F,\nC GRAD) = Q1(F,GRAD) + P*(Q2(F)-SM). The secant method is\nC used to find a zero of G(P) = 1/SQRT(Q2) - 1/SQRT(SM)\nC where F(P) satisfies the order-3N symmetric positive def-\nC inite linear system obtained by setting the gradient of Q\nC (treated as a function of F and GRAD with GRAD tangent to\nC the sphere surface) to zero. The linear system is solved\nC by the block Gauss-Seidel method (refer to CSSMSGS).\nC\nC Note that the method can also be used to select grad-\nC ients for the interpolation problem (F = U, SM = 0, and P\nC infinite). This is achieved by a call to Subroutine\nC CSGRADG.\nC\nC On input:\nC\nC N = Number of nodes in the triangulation. N .GE. 3.\nC\nC X,Y,Z = Arrays of length N containing Cartesian\nC coordinates of the nodes.\nC\nC U = Array of length N containing data values at the\nC nodes.\nC\nC LIST,LPTR,LEND = Data structure defining the trian-\nC gulation. Refer to STRIPACK\nC Subroutine CSTRMESH.\nC\nC IFLGS = Tension factor option:\nC IFLGS .LE. 0 if a single uniform tension\nC factor is to be used.\nC IFLGS .GE. 1 if variable tension is desired.\nC\nC SIGMA = Uniform tension factor (IFLGS .LE. 0), or\nC array containing tension factors associated\nC with arcs in one-to-one correspondence with\nC LIST entries (IFLGS .GE. 1). Refer to Sub-\nC programs CSGETSIG, CSSIG0, CSSIG1, and CSSIG2.\nC\nC W = Array of length N containing positive weights\nC associated with the data values. The recommend-\nC ed value of W(I) is 1/DU**2 where DU is the\nC standard deviation associated with U(I). DU**2\nC is the expected value of the squared error in\nC the measurement of U(I). (The mean error is\nC assumed to be zero.)\nC\nC SM = Positive parameter specifying an upper bound on\nC Q2(F). Note that F is constant (and Q2(F)\nC is minimized) if SM is sufficiently large that\nC the constraint is not active. It is recommend-\nC ed that SM satisfy N-SQRT(2N) .LE. SM .LE. N+\nC SQRT(2N).\nC\nC SMTOL = Parameter in the open interval (0,1) speci-\nC fying the relative error allowed in satisfy-\nC ing the constraint -- the constraint is\nC assumed to be satisfied if SM*(1-SMTOL) .LE.\nC Q2 .LE. SM*(1+SMTOL). A reasonable value\nC for SMTOL is SQRT(2/N).\nC\nC GSTOL = Nonnegative tolerance defining the conver-\nC gence criterion for the Gauss-Seidel method.\nC Refer to parameter DFMAX in Subroutine\nC CSSMSGS. A recommended value is .05*DU**2,\nC where DU is an average standard deviation\nC in the data values.\nC\nC LPRNT = Logical unit on which diagnostic messages\nC are printed, or negative integer specifying\nC no diagnostics. For each secant iteration,\nC the following values are printed: P, G(P),\nC NIT, DFMAX, and DP, where NIT denotes the\nC number of Gauss-Seidel iterations used in\nC the computation of G, DFMAX denotes the max-\nC imum relative change in a solution component\nC in the last Gauss-Seidel iteration, and DP\nC is the change in P computed by linear inter-\nC polation between the current point (P,G) and\nC a previous point.\nC\nC Input parameters are not altered by this routine.\nC\nC On output:\nC\nC F = Array of length N containing nodal function val-\nC ues unless IER < 0.\nC\nC GRAD = 3 by N array whose columns contain gradients\nC of F at the nodes unless IER < 0.\nC\nC IER = Error indicator and information flag:\nC IER = 0 if no errors were encountered and the\nC constraint is active -- Q2(F) is ap-\nC proximately equal to SM.\nC IER = 1 if no errors were encountered but the\nC constraint is not active -- F and GRAD\nC are the values and gradients of a con-\nC stant function which minimizes Q2(F),\nC and Q1 = 0.\nC IER = 2 if the constraint could not be satis-\nC fied to within SMTOL due to\nC ill-conditioned linear systems.\nC IER = -1 if N, W, SM, SMTOL, or GSTOL is out-\nC side its valid range on input.\nC IER = -2 if all nodes are collinear or the\nC triangulation is invalid.\nC IER = -3 if duplicate nodes were encountered.\nC\nC SSRFPACK modules required by CSSMSURF: CSAPLYRT, CSCONSTR,\nC CSGRCOEF, CSSMSGS,\nC CSSNHCSH\nC\nC Intrinsic functions called by CSSMSURF: ABS, SQRT\nC\nC***********************************************************\nC\n INTEGER I, IERR, ITER, ITMAX, LUN, NIT, NITMAX, NN\n DOUBLE PRECISION C, DFMAX, DMAX, DP, G, G0, GNEG, P,\n . Q2, Q2MAX, Q2MIN, S, SUMW, TOL, WI\nC\nC Local parameters:\nC\nC ITMAX = Maximum number of secant iterations.\nC LUN = Local copy of LPRNT.\nC NITMAX = Maximum number of Gauss-Seidel iterations for\nC each secant iteration.\nC NN = Local copy of N.\nC TOL = Local copy of GSTOL.\nC\n DATA ITMAX/50/, NITMAX/40/\nC\n NN = N\n TOL = GSTOL\n LUN = LPRNT\n IF (LUN .GT. 99) LUN = -1\nC\nC Test for errors and initialize F to the weighted least\nC squares fit of a constant function to the data.\nC\n IER = -1\n IF (NN .LT. 3 .OR. SM .LE. 0. .OR. SMTOL .LE. 0.\n . .OR. SMTOL .GE. 1. .OR. TOL .LE. 0.) RETURN\n C = 0.\n SUMW = 0.\n DO 1 I = 1,NN\n WI = W(I)\n IF (WI .LE. 0.) RETURN\n C = C + WI*U(I)\n SUMW = SUMW + WI\n 1 CONTINUE\n C = C/SUMW\nC\nC Compute nodal values and gradients, and accumulate Q2 =\nC (U-F)**T*W*(U-F).\nC\n Q2 = 0.\n DO 2 I = 1,NN\n F(I) = C\n GRAD(1,I) = 0.\n GRAD(2,I) = 0.\n GRAD(3,I) = 0.\n Q2 = Q2 + W(I)*(U(I)-F(I))**2\n 2 CONTINUE\nC\nC Compute bounds on Q2 defined by SMTOL, and test for the\nC constraint satisfied by the constant fit.\nC\n Q2MIN = SM*(1.-SMTOL)\n Q2MAX = SM*(1.+SMTOL)\n IF (Q2 .LE. Q2MAX) THEN\nC\nC The constraint is satisfied by a constant function.\nC\n IER = 1\n IF (LUN .GE. 0) WRITE (LUN,100)\n 100 FORMAT (///1X,'CSSMSURF -- THE CSCONSTRAINT IS NOT ',\n . 'ACTIVE AND THE FITTING FCN IS CONSTANT.')\n RETURN\n ENDIF\nC\nC Compute G0 = G(0) and print a heading.\nC\n IER = 0\n S = 1./SQRT(SM)\n G0 = 1./SQRT(Q2) - S\n IF (LUN .GE. 0) WRITE (LUN,110) SM, TOL, NITMAX, G0\n 110 FORMAT (///1X,'CSSMSURF -- SM = ',E10.4,', GSTOL = ',\n . E7.1,', NITMAX = ',I2,', G(0) = ',E15.8)\nC\nC G(P) is strictly increasing and concave, and G(0) .LT. 0.\nC Initialize parameters for the secant method. The method\nC uses three points -- (P0,G0), (P,G), and (PNEG,GNEG)\nC where P0 and PNEG are defined implicitly by DP = P - P0\nC and DMAX = P - PNEG.\nC\n P = 10.*SM\n DP = P\n DMAX = 0.\n ITER = 0\nC\nC Top of loop -- compute G.\nC\n 3 NIT = NITMAX\n DFMAX = TOL\n CALL CSSMSGS (NN,X,Y,Z,U,LIST,LPTR,LEND,IFLGS,SIGMA,W,\n . P, NIT,DFMAX,F,GRAD, IERR)\n IF (IERR .LT. 0) IER = IERR\nC\nC IERR = -1 in CSSMSGS could be caused by P = 0 as a result\nC of inaccurate solutions to ill-conditioned systems.\nC\n IF (IERR .EQ. -1) IER = 2\n IF (IERR .LT. 0) RETURN\n Q2 = 0.\n DO 4 I = 1,NN\n Q2 = Q2 + W(I)*(U(I)-F(I))**2\n 4 CONTINUE\n G = 1./SQRT(Q2) - S\n ITER = ITER + 1\n IF (LUN .GE. 0) WRITE (LUN,120) ITER, P, G, NIT, DFMAX\n 120 FORMAT (/1X,I2,' -- P = ',E15.8,', G = ',E15.8,\n . ', NIT = ',I2,', DFMAX = ',E12.6)\nC\nC Test for convergence.\nC\n IF (Q2MIN .LE. Q2 .AND. Q2 .LE. Q2MAX) RETURN\n IF (ITER .GE. ITMAX) THEN\n IER = 2\n RETURN\n ENDIF\n IF (DMAX .EQ. 0. .AND. G .LE. 0.) THEN\nC\nC Increase P until G(P) > 0.\nC\n P = 10.*P\n DP = P\n GO TO 3\n ENDIF\nC\nC A bracketing interval [P0,P] has been found.\nC\n IF (G0*G .LE. 0.) THEN\nC\nC G0*G < 0. Update (PNEG,GNEG) to (P0,G0) so that G\nC and GNEG always have opposite signs.\nC\n DMAX = DP\n GNEG = G0\n ENDIF\nC\nC Compute the change in P by linear interpolation between\nC (P0,G0) and (P,G).\nC\n 5 DP = -G*DP/(G-G0)\n IF (LUN .GE. 0) WRITE (LUN,130) DP\n 130 FORMAT (1X,5X,'DP = ',E15.8)\n IF (ABS(DP) .GT. ABS(DMAX)) THEN\nC\nC G0*G .GT. 0 and the new estimate would be outside of the\nC bracketing interval of length ABS(DMAX). Reset\nC (P0,G0) to (PNEG,GNEG).\nC\n DP = DMAX\n G0 = GNEG\n GO TO 5\n ENDIF\nC\nC Bottom of loop -- update P, DMAX, and G0.\nC\n P = P + DP\n DMAX = DMAX + DP\n G0 = G\n GO TO 3\n END\n", "meta": {"hexsha": "dd55adcf25bd3ed0ec0b03d424fbbd22f4fd962c", "size": 11468, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "contrib/cssgrid/Src/cssmsurf.f", "max_stars_repo_name": "xylar/cdat", "max_stars_repo_head_hexsha": "8a5080cb18febfde365efc96147e25f51494a2bf", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 62, "max_stars_repo_stars_event_min_datetime": "2018-03-30T15:46:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-08T23:30:24.000Z", "max_issues_repo_path": "contrib/cssgrid/Src/cssmsurf.f", "max_issues_repo_name": "xylar/cdat", "max_issues_repo_head_hexsha": "8a5080cb18febfde365efc96147e25f51494a2bf", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 114, "max_issues_repo_issues_event_min_datetime": "2018-03-21T01:12:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-05T12:29:54.000Z", "max_forks_repo_path": "contrib/cssgrid/Src/cssmsurf.f", "max_forks_repo_name": "CDAT/uvcdat", "max_forks_repo_head_hexsha": "5133560c0c049b5c93ee321ba0af494253b44f91", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2018-06-06T02:42:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-26T03:27:00.000Z", "avg_line_length": 35.6149068323, "max_line_length": 63, "alphanum_fraction": 0.5662713638, "num_tokens": 3529, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92522995296862, "lm_q2_score": 0.731058584489497, "lm_q1q2_score": 0.6763972997445232}} {"text": "MODULE FUN_xyzSDIST\n!!#### PURPOSE\n!! Compute the signed distance from a plane to a point.\n\n!!#### EXTERNAL KINDS\nUSE KND_IntrinsicTypes,ONLY: KIND_Rsp,KIND_Rdp !!((01-A-KND_IntrinsicTypes.f90))\n\n!!#### EXTERNAL PROCEDURES\nUSE FUN_xyzDOT,ONLY: xyzDOT_VV !!((05-B-FUN_xyzDOT.f90))\n\n!!#### DEFAULT IMPLICIT\nIMPLICIT NONE\n\n!!#### DEFAULT ACCESS\nPRIVATE\n\n!!#### PROCEDURE OVERLOADING\nINTERFACE xyzSDIST_PnP\n MODULE PROCEDURE xyzSDIST_PnP_Rsp\n MODULE PROCEDURE xyzSDIST_PnP_Rdp\nEND INTERFACE\n\n!!#### PUBLIC ACCESS LIST\nPUBLIC :: xyzSDIST_PnP\n\n\nCONTAINS\n\n\nPURE FUNCTION xyzSDIST_PnP_Rsp( Pn , P ) RESULT( SDIST )\n!!#### LOCAL KINDS\nUSE KND_IntrinsicTypes,ONLY: KIND_R=>KIND_Rsp !!((01-A-KND_IntrinsicTypes.f90))\nINCLUDE \"06-B-FUN_xyzSDIST_PnP.f90.hdr\"\n!!--begin--\nINCLUDE \"06-B-FUN_xyzSDIST_PnP.f90.bdy\"\n!!--end--\nEND FUNCTION\n\nPURE FUNCTION xyzSDIST_PnP_Rdp( Pn , P ) RESULT( SDIST )\n!!#### LOCAL KINDS\nUSE KND_IntrinsicTypes,ONLY: KIND_R=>KIND_Rdp !!((01-A-KND_IntrinsicTypes.f90))\nINCLUDE \"06-B-FUN_xyzSDIST_PnP.f90.hdr\"\n!!--begin--\nINCLUDE \"06-B-FUN_xyzSDIST_PnP.f90.bdy\"\n!!--end--\nEND FUNCTION\n\n\nEND MODULE\n", "meta": {"hexsha": "427707ced2d37750b97c579ffe777ecf6cf1cf6b", "size": 1124, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/06-B-FUN_xyzSDIST.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/06-B-FUN_xyzSDIST.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/06-B-FUN_xyzSDIST.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": 22.48, "max_line_length": 80, "alphanum_fraction": 0.7241992883, "num_tokens": 361, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711908591638, "lm_q2_score": 0.7956581000631542, "lm_q1q2_score": 0.6762864628274189}} {"text": "!=====================================================================!\n! \n!=====================================================================!\n\nprogram test\n\n use iso_fortran_env , only : dp => REAL64\n use matrix_utils , only : toepliz\n use direct_linear_solve , only : mgs_qrfactor, cgs_qrfactor, &\n & householder, banded_householder, householder_factorization\n use direct_linear_solve , only : givens_factorization, givens\n use linear_algebra , only : eigvals, svdvals\n\n implicit none\n\n call test_givens_factorization()\n\ncontains\n \n subroutine test_givens_factorization\n\n real(dp), allocatable :: A(:,:), Q(:,:), R(:,:), D(:,:)\n integer , parameter :: matsize = 800\n integer :: i\n\n allocate(Q(matsize, matsize))\n allocate(R(matsize, matsize))\n allocate(D(matsize, matsize))\n allocate(A(matsize, matsize))\n\n call matrix(A)\n\n!!$ A(1,:) = [6.0d0, 5.0d0, 0.0d0]\n!!$ A(2,:) = [5.0d0, 1.0d0, 4.0d0]\n!!$ A(3,:) = [0.0d0, 4.0d0, 3.0d0]\n!!$ print *, 'matrix'\n!!$ do i = 1, matsize\n!!$ print *, A(i,:)\n!!$ end do\n \n print *, 'Performing Givens Transformation'\n Q = 0\n R = 0\n call givens_factorization(A, Q, R)\n\n ! Check similarity with A\n print *, 'consistency A' \n D = matmul(Q, R)\n print *, norm2(A - D)\n\n ! Check Orthogonality\n D = matmul(Q,transpose(Q))\n print *, 'orthogonality Q'\n do i = 1, matsize \n D(i,i) = 1.0d0 - D(i,i)\n end do\n print *, norm2(D)\n\n!!$ print *, 'Upper Triangular Matrix R'\n!!$ do i = 1, matsize\n!!$ print *, R(i,:)\n!!$ end do\n\n deallocate(A,Q,R,D)\n \n stop\n\n test_givens: block\n\n real(dp) :: x(2), y(2)\n\n call random_number(x)\n x(1) = 1.0d0\n x(2) = 0.0d0\n\n !x(2) = tiny(1.0d0)\n print *,x\n call givens(x)\n print *,x\n end block test_givens\n\n end subroutine test_givens_factorization\n\n !===================================================================!\n ! Setup Toepliz matrix with supplied columns\n !===================================================================!\n \n subroutine matrix(A)\n\n real(8), allocatable :: A(:,:)\n real(8), allocatable :: diag(:)\n integer :: m, j\n\n A = 0\n call random_number(A(:,1))\n call random_number(A(1,:))\n m = size(A, 1)\n\n allocate(diag(m))\n call random_number(diag) \n do concurrent(j=1:m)\n A(j,j) = diag(j)\n end do\n deallocate(diag)\n\n end subroutine matrix\n \n subroutine test_cgs_mgs_householder\n\n integer, parameter :: n = 200\n\n ! integer, parameter :: sizes(10) = [100,200,300,400,500,600,700,800,900,1000]\n ! integer, parameter :: sizes(7) = [100,200,400,800,1600,3200,6400]\n\n real(8), allocatable :: A(:,:), B(:,:)\n real(8), allocatable :: Q(:,:), R(:,:)\n real(8), allocatable :: U(:,:), V(:,:), S(:,:), RC(:,:), RM(:,:)\n real(8), allocatable :: svda(:)\n\n real(8) :: walltime1, walltime2, time_end, time_Start\n integer :: i, info\n\n ! Allocte matrices\n allocate(A(n,n), B(n,n), Q(n,n), R(n,n))\n allocate(U(n,n), V(n,n), S(n,n), RC(n,n), RM(n,n))\n U = 0\n V = 0\n S = 0\n allocate(svda(n))\n\n ! Form a matrix with required singular values\n call random_number(A)\n call mgs_qrfactor(A, U, R, info)\n\n call random_number(A)\n call mgs_qrfactor(A, V, R, info)\n do i = 1, n\n S(i,i) = 3.0d0**dble(-i)\n end do\n A = matmul(U,matmul(S,V))\n\n print *, 'performing classical GS on A'\n call cgs_qrfactor(A, Q, RC, info)\n S = matmul(Q,transpose(Q))\n do i = 1, n\n S(i,i) = 1.0d0 - S(i,i)\n print *, S(i,i)\n end do\n\n ! Perform orthogonality check\n print *, n, norm2(S), norm2(A-matmul(Q,RC))\n\n print *, 'performing modified GS on A'\n call mgs_qrfactor(A, Q, RM, info)\n S = matmul(Q,transpose(Q))\n do i = 1, n\n S(i,i) = 1.0d0 - S(i,i)\n print *, S(i,i)\n end do\n\n ! Perform orthogonality check\n print *, n, norm2(S), norm2(A-matmul(Q,RM))\n\n print *, 'Householder'\n Q = 0\n R = 0\n !call householder(A)\n call householder_factorization(A, Q, R)\n S = matmul(Q,transpose(Q))\n do i = 1, n\n S(i,i) = 1.0d0 - S(i,i)\n print *, S(i,i)\n end do\n\n print *, \"index \", \"cgs \", \"mgs \", \"householder\"\n do i = 1, n\n print *, i, RC(i,i), RM(i,i), abs(R(i,i))\n end do\n\n stop\n\n ! system 2\n!!$\n!!$ print *, \"npts \", \"walltime1 \", \"walltime2\"\n!!$ \n!!$ do i = 1, size(sizes)\n!!$\n!!$ n = sizes(i)\n!!$\n!!$ allocate(svda(n))\n!!$ allocate(A(n,n), Q(n,n), R(n,n))\n!!$ svda = 0\n!!$ A = 0\n!!$ Q = 0\n!!$ R = 0\n!!$\n!!$ svda(1) = 10.0d0\n!!$ svda(2) = 3.0d0\n!!$ svda(3) = 2.0d0\n!!$ svda(4) = 1.0d0\n!!$\n!!$ call toepliz(svda, A)\n!!$\n!!$ call cpu_time(time_start) \n!!$ call householder(A)\n!!$ call cpu_time(time_end)\n!!$ walltime1 = time_end - time_start\n!!$\n!!$ A = 0 \n!!$ call toepliz(svda, A)\n!!$\n!!$ call cpu_time(time_start) \n!!$ call banded_householder(A,3,3)\n!!$ call cpu_time(time_end)\n!!$ walltime2 = time_end - time_start\n!!$\n!!$ print *, n, walltime1, walltime2\n!!$\n!!$ \n!!$ deallocate(svda, A, Q, R)\n!!$ \n!!$ end do\n!!$\n!!$ !do i = 1, n\n!!$ ! write(*,*) i, A(i,:)\n!!$ !end do\n!!$\n!!$ stop\n!!$ print *, 'performing classical GS on A'\n!!$\n!!$ !call mgs_qrfactor(A, Q, R, info)\n!!$ !call banded_householder(A, 2, 2)\n!!$\n!!$ !print *, A- matmul(Q,R)\n!!$ do i = 1, n\n!!$ print *, i, A(i,i)\n!!$ end do\n!!$ \n\n end subroutine test_cgs_mgs_householder\n\nend program test\n", "meta": {"hexsha": "f370a69a1d6867d0016cf4b6842cc4fc267260c2", "size": 5585, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/orthogonalize/test.f90", "max_stars_repo_name": "komahanb/math6644-iterative-methods", "max_stars_repo_head_hexsha": "59dfd0fd8bbcb16d5f5b6d96d2565f87541803c9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-03-19T16:36:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-14T21:29:38.000Z", "max_issues_repo_path": "test/orthogonalize/test.f90", "max_issues_repo_name": "komahanb/math6644-iterative-methods", "max_issues_repo_head_hexsha": "59dfd0fd8bbcb16d5f5b6d96d2565f87541803c9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/orthogonalize/test.f90", "max_forks_repo_name": "komahanb/math6644-iterative-methods", "max_forks_repo_head_hexsha": "59dfd0fd8bbcb16d5f5b6d96d2565f87541803c9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-23T02:14:36.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-23T02:14:36.000Z", "avg_line_length": 22.9835390947, "max_line_length": 82, "alphanum_fraction": 0.5049239033, "num_tokens": 1948, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736772, "lm_q2_score": 0.7799929104825006, "lm_q1q2_score": 0.6762817511402278}} {"text": " double precision function dmach(job)\n integer job\nc\nc smach computes machine parameters of floating point\nc arithmetic for use in testing only. not required by\nc linpack proper.\nc\nc if trouble with automatic computation of these quantities,\nc they can be set by direct assignment statements.\nc assume the computer has\nc\nc b = base of arithmetic\nc t = number of base b digits\nc l = smallest possible exponent\nc u = largest possible exponent\nc\nc then\nc\nc eps = b**(1-t)\nc tiny = 100.0*b**(-l+t)\nc huge = 0.01*b**(u-t)\nc\nc dmach same as smach except t, l, u apply to\nc double precision.\nc\nc cmach same as smach except if complex division\nc is done by\nc\nc 1/(x+i*y) = (x-i*y)/(x**2+y**2)\nc\nc then\nc\nc tiny = sqrt(tiny)\nc huge = sqrt(huge)\nc\nc\nc job is 1, 2 or 3 for epsilon, tiny and huge, respectively.\nc\n double precision eps,tiny,huge,s\nc\n eps = 1.0d0\n 10 eps = eps/2.0d0\n s = 1.0d0 + eps\n if (s .gt. 1.0d0) go to 10\n eps = 2.0d0*eps\nc\n s = 1.0d0\n 20 tiny = s\n s = s/16.0d0\n if (s*1.0 .ne. 0.0d0) go to 20\n tiny = (tiny/eps)*100.0\n huge = 1.0d0/tiny\nc\n if (job .eq. 1) dmach = eps\n if (job .eq. 2) dmach = tiny\n if (job .eq. 3) dmach = huge\n return\n end\n", "meta": {"hexsha": "f3db42dc6e486dee015feb426ade26913dc5431a", "size": 1368, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "blas-www/dmach.f", "max_stars_repo_name": "NetlibRepository/lapack-www", "max_stars_repo_head_hexsha": "e3253f69893da6930057896e48ebfb9e7ae30473", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2016-05-26T03:44:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-19T19:11:09.000Z", "max_issues_repo_path": "blas-www/dmach.f", "max_issues_repo_name": "NetlibRepository/lapack-www", "max_issues_repo_head_hexsha": "e3253f69893da6930057896e48ebfb9e7ae30473", "max_issues_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-12-13T10:51:03.000Z", "max_issues_repo_issues_event_max_datetime": "2017-12-13T10:51:03.000Z", "max_forks_repo_path": "blas-www/dmach.f", "max_forks_repo_name": "NetlibRepository/lapack-www", "max_forks_repo_head_hexsha": "e3253f69893da6930057896e48ebfb9e7ae30473", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2016-12-13T09:04:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-23T17:34:31.000Z", "avg_line_length": 23.186440678, "max_line_length": 64, "alphanum_fraction": 0.5730994152, "num_tokens": 485, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.867035763237924, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.6762817440261731}} {"text": "program cinematica\n\nimplicit none\n\nreal, dimension (1:100) :: x, t, v\nreal :: xo, c, vo, a\ninteger :: i\n\nxo = 1\nvo = 5\na = 2\n\nc = 0\ndo i = 1,100\n c = c + 0.5\n t(i) = c\n v(i) = vo + a*t(i)\n x(i) = xo + vo*t(i) + (1d0/2d0)*a*t(i)**2\nend do\n\ndo i = 1,100\n write(*,*) t(i), x(i), v(i)\nend do\n\nopen(1,FILE = \"dados.txt\")\n\ndo i = 1,100\n write(1,*) t(i), x(i), v(i)\nend do\n\nclose(1)\n\nend program cinematica", "meta": {"hexsha": "8a2feb08adbd9eb0a2b35249d6dee308a79b9941", "size": 417, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "aula05/prog1.f90", "max_stars_repo_name": "j-rheinheimer/Fisica-Computacional-I", "max_stars_repo_head_hexsha": "9d3d434cfb787391db5b57829e93d1461cc65f1c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "aula05/prog1.f90", "max_issues_repo_name": "j-rheinheimer/Fisica-Computacional-I", "max_issues_repo_head_hexsha": "9d3d434cfb787391db5b57829e93d1461cc65f1c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "aula05/prog1.f90", "max_forks_repo_name": "j-rheinheimer/Fisica-Computacional-I", "max_forks_repo_head_hexsha": "9d3d434cfb787391db5b57829e93d1461cc65f1c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 12.6363636364, "max_line_length": 45, "alphanum_fraction": 0.5059952038, "num_tokens": 191, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6762817369121182}} {"text": "PROGRAM test_ave_value2\r\n!\r\n! Purpose:\r\n! To test function ave_value by calling it with the intrinsic \r\n! function sin. \r\n!\r\n! Record of revisions:\r\n! Date Programmer Description of change\r\n! ==== ========== =====================\r\n! 12/31/06 S. J. Chapman Original code\r\n!\r\nIMPLICIT NONE\r\n\r\n! Declare functions:\r\nREAL :: ave_value ! Average value of function\r\nINTRINSIC sin ! Function to evaluate\r\n\r\n! Declare parameters:\r\nREAL, PARAMETER :: TWOPI = 6.283185 ! 2 * Pi\r\n\r\n! Declare local variables:\r\nREAL :: ave ! Average of my_function\r\n\r\n! Call function with func=sin.\r\nave = ave_value ( sin, 0., TWOPI, 101 )\r\nWRITE (*,1000) 'SIN', ave\r\n1000 FORMAT (1X,'The average value of ',A,' between 0. and twopi is ', &\r\n F16.6,'.')\r\n \r\nEND PROGRAM test_ave_value2\r\n", "meta": {"hexsha": "32ffcf77826c9cf80d10d67fb4a359ada9969d84", "size": 881, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap17/test_ave_value2.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/chap17/test_ave_value2.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/chap17/test_ave_value2.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.4193548387, "max_line_length": 73, "alphanum_fraction": 0.5584562997, "num_tokens": 222, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357529306639, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.6762817359865834}} {"text": "\n program analytical_solution\n\n! This program implements the analytical solution for the displacement vector in a 3D viscoelastic medium\n! with a vertical force source located in (0,0,0).\n! Implemented by Dimitri Komatitsch from the 2D plane-strain viscoelastic medium analytical solution\n! of Appendix B of Carcione et al., Wave propagation simulation in a linear viscoelastic medium, GJI, vol. 95, p. 597-611 (1988)\n! (note that that Appendix contains two typos, fixed in this code).\n! The amplitude of the force is called F and is defined below.\n\n!! DK DK Dimitri Komatitsch, CNRS Marseille, France, May 2018.\n\n implicit none\n\n!! DK DK May 2018: the missing 1/L factor in older Carcione papers\n!! DK DK May 2018: has been added to this code by Quentin Brissaud and by Etienne Bachmann\n!! DK DK for the viscoacoustic code in directory EXAMPLES/attenuation/viscoacoustic,\n!! DK DK it would be very easy to copy the changes from there to this viscoelastic version;\n!! DK DK but then all the values of the tau_epsilon in the code below would need to change.\n\n!! DK DK Dimitri Komatitsch, CNRS Marseille, France, April 2017: added the elastic reference calculation.\n\n! compute the non-viscoacoustic case as a reference if needed, i.e. turn attenuation off\n logical, parameter :: TURN_ATTENUATION_OFF = .true.\n\n! to see how small the contribution of the near-field term is,\n! here the user can ask not to include it, to then compare with the full result obtained with this flag set to false\n logical, parameter :: DO_NOT_COMPUTE_THE_NEAR_FIELD = .false.\n\n integer, parameter :: iratio = 32\n\n integer, parameter :: nfreq = 524288\n integer, parameter :: nt = iratio * nfreq\n\n double precision, parameter :: freqmax = 80.d0\n!! DK DK to print the velocity if we want to display the curve of how velocity varies with frequency\n!! DK DK for instance to compute the unrelaxed velocity in the Zener model\n! double precision, parameter :: freqmax = 20000.d0\n\n double precision, parameter :: freqseuil = 0.00005d0\n\n double precision, parameter :: pi = 3.141592653589793d0\n\n! for the solution in time domain\n integer it,i\n real wsave(4*nt+15)\n complex c(nt)\n\n!! DK DK for my slow inverse Discrete Fourier Transform using a double loop\n complex :: input(nt), i_imaginary_constant\n integer :: j,m\n\n! density of the medium\n double precision, parameter :: rho = 2000.d0\n\n! amplitude of the force source\n double precision, parameter :: F = 1.d0\n\n! spatial dimension of the problem (this analytical code is valid only in three dimensions, thus do not change this)\n integer, parameter :: NDIM = 3\n\n! definition position recepteur Carcione\n double precision, dimension(NDIM) :: x\n\n! Definition source Dimitri\n double precision, parameter :: f0 = 18.d0\n double precision, parameter :: t0 = 1.2d0 / f0\n\n! Definition source Carcione\n! double precision f0,t0,eta,epsil\n! parameter(f0 = 50.d0)\n! parameter(t0 = 0.075d0)\n! parameter(epsil = 1.d0)\n! parameter(eta = 0.5d0)\n\n! number of Zener standard linear solids in parallel\n integer, parameter :: Lnu = 3\n\n! DK DK I implemented a very simple and slow inverse Discrete Fourier Transform\n! DK DK at some point, for verification, using a double loop. I keep it just in case.\n! DK DK For large number of points it is extremely slow because of the double loop.\n! DK DK Thus there is no reason to turn this flag on.\n logical, parameter :: USE_SLOW_FOURIER_TRANSFORM = .false.\n\n!! DK DK March 2018: this missing 1/L factor has been added to this code by Quentin Brissaud\n!! DK DK for the viscoacoustic code in directory EXAMPLES/attenuation/viscoacoustic,\n!! DK DK it would be very easy to copy the changes from there to this viscoelastic version;\n!! DK DK but then all the values of the tau_epsilon below would need to change.\n\n double precision, dimension(Lnu) :: tau_sigma_kappa,tau_sigma_mu,tau_epsilon_kappa,tau_epsilon_mu\n\n integer :: ifreq\n double precision :: deltafreq,freq,omega,omega0,deltat,time,a\n double complex :: comparg\n\n! Fourier transform of the Ricker wavelet source\n double complex fomega(0:nfreq)\n\n! real and imaginary parts\n double precision ra(0:nfreq),rb(0:nfreq)\n\n! spectral amplitude\n double precision ampli(0:nfreq)\n\n! analytical solution for the three components\n double complex phi1(-nfreq:nfreq)\n double complex phi2(-nfreq:nfreq)\n double complex phi3(-nfreq:nfreq)\n\n! external function\n double complex, external :: ui\n\n! modules elastiques\n double complex :: Kappa_omega, Mu_omega, Vp_omega, Vs_omega, temp, Mu_relaxed, Kappa_relaxed\n\n! ********** end of variable declarations ************\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! Below are all the variables that need to be obtained from Specfem3D\n! These default values match the following simulation:\n!\n! Vp(f0_ref) = 3297.849 m/s\n! Vs(f0_ref) = 2222.536 m/s\n! f0_ref = 18 Hz\n! QKappa = 9000\n! QMu = 10\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n! We use Kappa_ref and Mu_ref to compute the case without attenuation\n! They are chosen such that Kappa_ref = Kappa(2*pi*f0_ref) when there is\n! attenuation\n double precision, parameter :: Vp_ref = 3297.849\n double precision, parameter :: Vs_ref = 2222.536\n\n double precision, parameter :: Mu_ref = rho * Vs_ref * Vs_ref\n double precision, parameter :: Kappa_ref = rho * ( Vp_ref * Vp_ref - 4.d0/3 * Vs_ref * Vs_ref)\n\n! add this for the case of an elastic medium, with viscoelasticity turned off\n double precision, parameter :: Mu_unrelaxed = Mu_ref\n double precision, parameter :: Kappa_unrelaxed = Kappa_ref\n\n! tau constants mimicking constant QKappa and KMu\n tau_epsilon_mu = (/ 0.281966668348107 , 3.607809663879573E-002 , 5.638875613224542E-003/)\n tau_sigma_mu = (/ 0.186873539567019 , 2.491998701168405E-002 , 3.323133676931235E-003/)\n tau_epsilon_kappa = (/ 0.186973292921151 , 2.492998179955646E-002 , 3.324907855424433E-003/)\n tau_sigma_kappa = (/ 0.186873539567019 , 2.491998701168405E-002 , 3.323133676931235E-003/)\n\n! Eq (32) of Jeroen's note, eq (2.199) of Carcione's book from 2014, third edition\n Kappa_relaxed = (Kappa_unrelaxed /(sum(tau_epsilon_kappa(:)/tau_sigma_kappa(:))/Lnu))\n Mu_relaxed = (Mu_unrelaxed /(sum(tau_epsilon_mu(:)/tau_sigma_mu(:))/Lnu))\n\n! position of the receiver\n x(1) = +500.\n x(2) = +500.\n x(3) = +500.\n\n print *,'Force source located at the origin (0,0,0)'\n print *,'Receiver located in (x,y,z) = ',x(1),x(2),x(3)\n\n if (TURN_ATTENUATION_OFF) then\n print *,'BEWARE: computing the elastic reference solution (i.e., without attenuation) instead of the viscoelastic solution'\n else\n print *,'Computing the viscoelastic solution'\n endif\n\n if (DO_NOT_COMPUTE_THE_NEAR_FIELD) then\n print *,'BEWARE: computing the far-field solution only, rather than the full Green function'\n else\n print *,'Computing the full solution, including the near-field term of the Green function'\n endif\n\n! step in frequency\n deltafreq = freqmax / dble(nfreq)\n\n! define parameters for the Ricker source\n omega0 = 2.d0 * pi * f0\n a = pi**2 * f0**2\n\n deltat = 1.d0 / (freqmax*dble(iratio))\n\n! define the spectrum of the source\n do ifreq=0,nfreq\n freq = deltafreq * dble(ifreq)\n omega = 2.d0 * pi * freq\n\n! typo in equation (B7) of Carcione et al., Wave propagation simulation in a linear viscoelastic medium,\n! Geophysical Journal, vol. 95, p. 597-611 (1988), the exponential should be of -i omega t0,\n! fixed here by adding the minus sign\n comparg = dcmplx(0.d0,-omega*t0)\n\n! definir le spectre du Ricker de Carcione avec cos()\n! equation (B7) of Carcione et al., Wave propagation simulation in a linear viscoelastic medium,\n! Geophysical Journal, vol. 95, p. 597-611 (1988)\n! fomega(ifreq) = pi * dsqrt(pi/eta) * (1.d0/omega0) * cdexp(comparg) * ( dexp(- (pi*pi/eta) * (epsil/2 - omega/omega0)**2) &\n! + dexp(- (pi*pi/eta) * (epsil/2 + omega/omega0)**2) )\n\n! definir le spectre d'un Ricker classique (centre en t0)\n fomega(ifreq) = dsqrt(pi) * cdexp(comparg) * omega**2 * dexp(-omega**2/(4.d0*a)) / (2.d0 * dsqrt(a**3))\n\n ra(ifreq) = dreal(fomega(ifreq))\n rb(ifreq) = dimag(fomega(ifreq))\n! prendre le module de l'amplitude spectrale\n ampli(ifreq) = dsqrt(ra(ifreq)**2 + rb(ifreq)**2)\n enddo\n\n! sauvegarde du spectre d'amplitude de la source en Hz au format Gnuplot\n open(unit=10,file='spectrum_of_the_source_used.gnu',status='unknown')\n do ifreq = 0,nfreq\n freq = deltafreq * dble(ifreq)\n write(10,*) sngl(freq),sngl(ampli(ifreq))\n enddo\n close(10)\n\n! ************** calcul solution analytique ****************\n\n! d'apres Carcione GJI vol 95 p 611 (1988)\n do ifreq=0,nfreq\n freq = deltafreq * dble(ifreq)\n omega = 2.d0 * pi * freq\n\n! critere ad-hoc pour eviter singularite en zero\n if (freq < freqseuil) omega = 2.d0 * pi * freqseuil\n\n! use standard infinite frequency (unrelaxed) reference,\n! in which waves slow down when attenuation is turned on.\n temp = dcmplx(0.d0,0.d0)\n do i=1,Lnu\n temp = temp + (1./Lnu)*dcmplx(1.d0,omega*tau_epsilon_kappa(i)) / dcmplx(1.d0,omega*tau_sigma_kappa(i))\n enddo\n\n! Eq(31) of Jeroen's note\n Kappa_omega = Kappa_relaxed * temp\n\n temp = dcmplx(0.d0,0.d0)\n do i=1,Lnu\n temp = temp + (1./Lnu)*dcmplx(1.d0,omega*tau_epsilon_mu(i)) / dcmplx(1.d0,omega*tau_sigma_mu(i))\n enddo\n\n! Eq (31) of Jeroen's note\n Mu_omega = Mu_relaxed * temp\n\n if (TURN_ATTENUATION_OFF) then\n! wave speeds and moduli are the same for all omega when there is no attenuation\n Kappa_omega = Kappa_ref\n Mu_omega = Mu_ref\n endif\n\n Vs_omega = cdsqrt( Mu_omega / rho)\n Vp_omega = cdsqrt( Kappa_omega / rho + (4.d0/3)*Vs_omega*Vs_omega )\n\n!! DK DK print the velocity if we want to display the curve of how velocity varies with frequency\n!! DK DK for instance to compute the unrelaxed velocity in the Zener model\n! print *,freq,dsqrt(real(Vp_omega)**2 + imag(Vp_omega)**2)\n!! DK DK print the velocity if we want to display the curve of how velocity varies with frequency\n!! DK DK for instance to compute the unrelaxed velocity in the Zener model\n! print *,freq,dsqrt(real(Vs_omega)**2 + imag(Vs_omega)**2)\n\n! calcul de la solution analytique en frequence\n phi1(ifreq) = ui(1,omega,Vp_omega,Vs_omega,x,rho,NDIM,F,DO_NOT_COMPUTE_THE_NEAR_FIELD) * fomega(ifreq)\n phi2(ifreq) = ui(2,omega,Vp_omega,Vs_omega,x,rho,NDIM,F,DO_NOT_COMPUTE_THE_NEAR_FIELD) * fomega(ifreq)\n phi3(ifreq) = ui(3,omega,Vp_omega,Vs_omega,x,rho,NDIM,F,DO_NOT_COMPUTE_THE_NEAR_FIELD) * fomega(ifreq)\n\n enddo\n\n! take the conjugate value for negative frequencies\n do ifreq=-nfreq,-1\n phi1(ifreq) = dconjg(phi1(-ifreq))\n phi2(ifreq) = dconjg(phi2(-ifreq))\n phi3(ifreq) = dconjg(phi3(-ifreq))\n enddo\n\n! ***************************************************************************\n! Calculation of the time domain solution (using routine \"cfftb\" from Netlib)\n! ***************************************************************************\n\n! **********\n! Compute Ux\n! **********\n\n! initialize FFT arrays\n call cffti(nt,wsave)\n\n! clear array of Fourier coefficients\n do it = 1,nt\n c(it) = cmplx(0.,0.)\n enddo\n\n! use the Fourier values for Ux\n c(1) = cmplx(phi1(0))\n do ifreq=1,nfreq-2\n c(ifreq+1) = cmplx(phi1(ifreq))\n c(nt+1-ifreq) = conjg(cmplx(phi1(ifreq)))\n enddo\n\n! perform the inverse FFT for Ux\n if (.not. USE_SLOW_FOURIER_TRANSFORM) then\n call cfftb(nt,c,wsave)\n else\n! DK DK I implemented a very simple and slow inverse Discrete Fourier Transform here\n! DK DK at some point, for verification, using a double loop. I keep it just in case.\n! DK DK For large number of points it is extremely slow because of the double loop.\n input(:) = c(:)\n! imaginary constant \"i\"\n i_imaginary_constant = (0.,1.)\n do it = 1,nt\n if (mod(it,1000) == 0) print *,'FFT inverse it = ',it,' out of ',nt\n j = it\n c(j) = cmplx(0.,0.)\n do m = 1,nt\n c(j) = c(j) + input(m) * exp(2.d0 * PI * i_imaginary_constant * dble((m-1) * (j-1)) / nt)\n enddo\n enddo\n endif\n\n! in the inverse Discrete Fourier transform one needs to divide by N, the number of samples (number of time steps here)\n c(:) = c(:) / nt\n\n! value of a time step\n deltat = 1.d0 / (freqmax*dble(iratio))\n\n! to get the amplitude right, we need to divide by the time step\n c(:) = c(:) / deltat\n\n! save time result inverse FFT for Ux\n\n if (TURN_ATTENUATION_OFF) then\n if (DO_NOT_COMPUTE_THE_NEAR_FIELD) then\n open(unit=11,file='Ux_time_analytical_solution_elastic_without_near_field.dat',status='unknown')\n else\n open(unit=11,file='Ux_time_analytical_solution_elastic.dat',status='unknown')\n endif\n else\n if (DO_NOT_COMPUTE_THE_NEAR_FIELD) then\n open(unit=11,file='Ux_time_analytical_solution_viscoelastic_without_near_field.dat',status='unknown')\n else\n open(unit=11,file='Ux_time_analytical_solution_viscoelastic.dat',status='unknown')\n endif\n endif\n do it=1,nt\n! DK DK Dec 2011: subtract t0 to be consistent with the SPECFEM2D code\n time = dble(it-1)*deltat - t0\n! the seismograms are very long due to the very large number of FFT points used,\n! thus keeping the useful part of the signal only (the first six seconds of the seismogram)\n if (time >= 0.d0 .and. time <= 6.d0) write(11,*) sngl(time),real(c(it))\n enddo\n close(11)\n\n! **********\n! Compute Uy\n! **********\n\n! clear array of Fourier coefficients\n do it = 1,nt\n c(it) = cmplx(0.,0.)\n enddo\n\n! use the Fourier values for Uy\n c(1) = cmplx(phi2(0))\n do ifreq=1,nfreq-2\n c(ifreq+1) = cmplx(phi2(ifreq))\n c(nt+1-ifreq) = conjg(cmplx(phi2(ifreq)))\n enddo\n\n! perform the inverse FFT for Uy\n if (.not. USE_SLOW_FOURIER_TRANSFORM) then\n call cfftb(nt,c,wsave)\n else\n! DK DK I implemented a very simple and slow inverse Discrete Fourier Transform here\n! DK DK at some point, for verification, using a double loop. I keep it just in case.\n! DK DK For large number of points it is extremely slow because of the double loop.\n input(:) = c(:)\n! imaginary constant \"i\"\n i_imaginary_constant = (0.,1.)\n do it = 1,nt\n if (mod(it,1000) == 0) print *,'FFT inverse it = ',it,' out of ',nt\n j = it\n c(j) = cmplx(0.,0.)\n do m = 1,nt\n c(j) = c(j) + input(m) * exp(2.d0 * PI * i_imaginary_constant * dble((m-1) * (j-1)) / nt)\n enddo\n enddo\n endif\n\n! in the inverse Discrete Fourier transform one needs to divide by N, the number of samples (number of time steps here)\n c(:) = c(:) / nt\n\n! value of a time step\n deltat = 1.d0 / (freqmax*dble(iratio))\n\n! to get the amplitude right, we need to divide by the time step\n c(:) = c(:) / deltat\n\n! save time result inverse FFT for Uy\n if (TURN_ATTENUATION_OFF) then\n if (DO_NOT_COMPUTE_THE_NEAR_FIELD) then\n open(unit=11,file='Uy_time_analytical_solution_elastic_without_near_field.dat',status='unknown')\n else\n open(unit=11,file='Uy_time_analytical_solution_elastic.dat',status='unknown')\n endif\n else\n if (DO_NOT_COMPUTE_THE_NEAR_FIELD) then\n open(unit=11,file='Uy_time_analytical_solution_viscoelastic_without_near_field.dat',status='unknown')\n else\n open(unit=11,file='Uy_time_analytical_solution_viscoelastic.dat',status='unknown')\n endif\n endif\n do it=1,nt\n! DK DK Dec 2011: subtract t0 to be consistent with the SPECFEM2D code\n time = dble(it-1)*deltat - t0\n! the seismograms are very long due to the very large number of FFT points used,\n! thus keeping the useful part of the signal only (the first six seconds of the seismogram)\n if (time >= 0.d0 .and. time <= 6.d0) write(11,*) sngl(time),real(c(it))\n enddo\n close(11)\n\n! **********\n! Compute Uz\n! **********\n\n! clear array of Fourier coefficients\n do it = 1,nt\n c(it) = cmplx(0.,0.)\n enddo\n\n! use the Fourier values for Uz\n c(1) = cmplx(phi3(0))\n do ifreq=1,nfreq-2\n c(ifreq+1) = cmplx(phi3(ifreq))\n c(nt+1-ifreq) = conjg(cmplx(phi3(ifreq)))\n enddo\n\n! perform the inverse FFT for Uz\n if (.not. USE_SLOW_FOURIER_TRANSFORM) then\n call cfftb(nt,c,wsave)\n else\n! DK DK I implemented a very simple and slow inverse Discrete Fourier Transform here\n! DK DK at some point, for verification, using a double loop. I keep it just in case.\n! DK DK For large number of points it is extremely slow because of the double loop.\n input(:) = c(:)\n! imaginary constant \"i\"\n i_imaginary_constant = (0.,1.)\n do it = 1,nt\n if (mod(it,1000) == 0) print *,'FFT inverse it = ',it,' out of ',nt\n j = it\n c(j) = cmplx(0.,0.)\n do m = 1,nt\n c(j) = c(j) + input(m) * exp(2.d0 * PI * i_imaginary_constant * dble((m-1) * (j-1)) / nt)\n enddo\n enddo\n endif\n\n! in the inverse Discrete Fourier transform one needs to divide by N, the number of samples (number of time steps here)\n c(:) = c(:) / nt\n\n! value of a time step\n deltat = 1.d0 / (freqmax*dble(iratio))\n\n! to get the amplitude right, we need to divide by the time step\n c(:) = c(:) / deltat\n\n! save time result inverse FFT for Uz\n if (TURN_ATTENUATION_OFF) then\n if (DO_NOT_COMPUTE_THE_NEAR_FIELD) then\n open(unit=11,file='Uz_time_analytical_solution_elastic_without_near_field.dat',status='unknown')\n else\n open(unit=11,file='Uz_time_analytical_solution_elastic.dat',status='unknown')\n endif\n else\n if (DO_NOT_COMPUTE_THE_NEAR_FIELD) then\n open(unit=11,file='Uz_time_analytical_solution_viscoelastic_without_near_field.dat',status='unknown')\n else\n open(unit=11,file='Uz_time_analytical_solution_viscoelastic.dat',status='unknown')\n endif\n endif\n do it=1,nt\n! DK DK Dec 2011: subtract t0 to be consistent with the SPECFEM2D code\n time = dble(it-1)*deltat - t0\n! the seismograms are very long due to the very large number of FFT points used,\n! thus keeping the useful part of the signal only (the first six seconds of the seismogram)\n if (time >= 0.d0 .and. time <= 6.d0) write(11,*) sngl(time),real(c(it))\n enddo\n close(11)\n\n end\n\n! -----------\n\n double complex function ui(i,omega,v1,v2,x,rho,NDIM,F,DO_NOT_COMPUTE_THE_NEAR_FIELD)\n\n implicit none\n\n double precision, parameter :: pi = 3.141592653589793d0\n\n integer i,j\n double precision omega,F\n double complex :: v1,v2,Up_far_field,Us_far_field,near_field,i_imaginary_constant\n double complex :: fourier_transform_of_Heaviside_times_t_for_Vp,fourier_transform_of_Heaviside_times_t_for_Vs\n logical :: DO_NOT_COMPUTE_THE_NEAR_FIELD\n\n integer :: NDIM,kronecker_delta_symbol\n double precision, dimension(NDIM) :: x,gamma_vector\n double precision :: r,rho\n\n! source-receiver distance\n r = dsqrt(x(1)**2 + x(2)**2 + x(3)**2)\n\n! define the gamma vector of Aki and Richards (1980), which is the unit vector from the source to the receiver\n! see Aki and Richards (1980) below Box 4.3 (continued) and above equation (4.23)\n gamma_vector(:) = x(:) / r\n\n! the force is vertical in this analytical code, thus the j direction of the force is Z\n j = 3\n\n! imaginary constant \"i\"\n i_imaginary_constant = (0.d0,1.d0)\n\n! Kronecker delta symbol\n if (i == j) then\n kronecker_delta_symbol = 1\n else\n kronecker_delta_symbol = 0\n endif\n\n! far-field P wave term\n! see e.g. Aki and Richards (1980), equation (4.24) in the time domain; here we use the same equation but in the frequency domain\n Up_far_field = gamma_vector(i) * gamma_vector(j) * exp(-i_imaginary_constant*omega*r/v1) / (4.d0 * pi * rho * v1**2 * r)\n\n! far-field S wave term\n! see e.g. Aki and Richards (1980), equation (4.25) in the time domain; here we use the same equation but in the frequency domain\n! note that Aki and Richards (1980) has a typo in equation (4.25), a term 1/r is missing; fixed here.\n! The corrected equation is for instance in Jose Pujol, Elastic wave propagation and generation in seismology, equation (9.6.1)\n Us_far_field = (kronecker_delta_symbol - gamma_vector(i) * gamma_vector(j)) * exp(-i_imaginary_constant*omega*r/v2) &\n / (4.d0 * pi * rho * v2**2 * r)\n\n! near field term (see e.g. Jose Pujol, Elastic wave propagation and generation in seismology, equation (9.6.1) in the time domain;\n! here we use the same equation but in the frequency domain)\n fourier_transform_of_Heaviside_times_t_for_Vp = i_imaginary_constant * (-omega*r + i_imaginary_constant*v1) * &\n exp(-i_imaginary_constant*omega*r/v1) / (v1 * omega**2)\n\n fourier_transform_of_Heaviside_times_t_for_Vs = i_imaginary_constant * (-omega*r + i_imaginary_constant*v2) * &\n exp(-i_imaginary_constant*omega*r/v2) / (v2 * omega**2)\n\n near_field = (3 * gamma_vector(i) * gamma_vector(j) - kronecker_delta_symbol) * &\n (fourier_transform_of_Heaviside_times_t_for_Vp - fourier_transform_of_Heaviside_times_t_for_Vs) / (4.d0 * pi * rho * r**3)\n\n if (DO_NOT_COMPUTE_THE_NEAR_FIELD) near_field = dcmplx(0.d0,0.d0)\n\n! the result is the sum of the three terms; we also multiply by the amplitude of the force\n ui = F * (Up_far_field + Us_far_field + near_field)\n\n end\n\n! ***************** routine de FFT pour signal en temps ****************\n\n! FFT routine taken from Netlib\n\n subroutine CFFTB (N,C,WSAVE)\n DIMENSION C(1) ,WSAVE(1)\n if (N == 1) return\n IW1 = N+N+1\n IW2 = IW1+N+N\n CALL CFFTB1 (N,C,WSAVE,WSAVE(IW1),WSAVE(IW2))\n return\n END\n subroutine CFFTB1 (N,C,CH,WA,IFAC)\n DIMENSION CH(1) ,C(1) ,WA(1) ,IFAC(1)\n NF = IFAC(2)\n NA = 0\n L1 = 1\n IW = 1\n DO 116 K1=1,NF\n IP = IFAC(K1+2)\n L2 = IP*L1\n IDO = N/L2\n IDOT = IDO+IDO\n IDL1 = IDOT*L1\n if (IP /= 4) goto 103\n IX2 = IW+IDOT\n IX3 = IX2+IDOT\n if (NA /= 0) goto 101\n CALL PASSB4 (IDOT,L1,C,CH,WA(IW),WA(IX2),WA(IX3))\n goto 102\n 101 CALL PASSB4 (IDOT,L1,CH,C,WA(IW),WA(IX2),WA(IX3))\n 102 NA = 1-NA\n goto 115\n 103 if (IP /= 2) goto 106\n if (NA /= 0) goto 104\n CALL PASSB2 (IDOT,L1,C,CH,WA(IW))\n goto 105\n 104 CALL PASSB2 (IDOT,L1,CH,C,WA(IW))\n 105 NA = 1-NA\n goto 115\n 106 if (IP /= 3) goto 109\n IX2 = IW+IDOT\n if (NA /= 0) goto 107\n CALL PASSB3 (IDOT,L1,C,CH,WA(IW),WA(IX2))\n goto 108\n 107 CALL PASSB3 (IDOT,L1,CH,C,WA(IW),WA(IX2))\n 108 NA = 1-NA\n goto 115\n 109 if (IP /= 5) goto 112\n IX2 = IW+IDOT\n IX3 = IX2+IDOT\n IX4 = IX3+IDOT\n if (NA /= 0) goto 110\n CALL PASSB5 (IDOT,L1,C,CH,WA(IW),WA(IX2),WA(IX3),WA(IX4))\n goto 111\n 110 CALL PASSB5 (IDOT,L1,CH,C,WA(IW),WA(IX2),WA(IX3),WA(IX4))\n 111 NA = 1-NA\n goto 115\n 112 if (NA /= 0) goto 113\n CALL PASSB (NAC,IDOT,IP,L1,IDL1,C,C,C,CH,CH,WA(IW))\n goto 114\n 113 CALL PASSB (NAC,IDOT,IP,L1,IDL1,CH,CH,CH,C,C,WA(IW))\n 114 if (NAC /= 0) NA = 1-NA\n 115 L1 = L2\n IW = IW+(IP-1)*IDOT\n 116 continue\n if (NA == 0) return\n N2 = N+N\n DO 117 I=1,N2\n C(I) = CH(I)\n 117 continue\n return\n END\n subroutine PASSB (NAC,IDO,IP,L1,IDL1,CC,C1,C2,CH,CH2,WA)\n DIMENSION CH(IDO,L1,IP) ,CC(IDO,IP,L1), &\n C1(IDO,L1,IP) ,WA(1) ,C2(IDL1,IP), &\n CH2(IDL1,IP)\n IDOT = IDO/2\n NT = IP*IDL1\n IPP2 = IP+2\n IPPH = (IP+1)/2\n IDP = IP*IDO\n!\n if (IDO < L1) goto 106\n DO 103 J=2,IPPH\n JC = IPP2-J\n DO 102 K=1,L1\n DO 101 I=1,IDO\n CH(I,K,J) = CC(I,J,K)+CC(I,JC,K)\n CH(I,K,JC) = CC(I,J,K)-CC(I,JC,K)\n 101 continue\n 102 continue\n 103 continue\n DO 105 K=1,L1\n DO 104 I=1,IDO\n CH(I,K,1) = CC(I,1,K)\n 104 continue\n 105 continue\n goto 112\n 106 DO 109 J=2,IPPH\n JC = IPP2-J\n DO 108 I=1,IDO\n DO 107 K=1,L1\n CH(I,K,J) = CC(I,J,K)+CC(I,JC,K)\n CH(I,K,JC) = CC(I,J,K)-CC(I,JC,K)\n 107 continue\n 108 continue\n 109 continue\n DO 111 I=1,IDO\n DO 110 K=1,L1\n CH(I,K,1) = CC(I,1,K)\n 110 continue\n 111 continue\n 112 IDL = 2-IDO\n INC = 0\n DO 116 L=2,IPPH\n LC = IPP2-L\n IDL = IDL+IDO\n DO 113 IK=1,IDL1\n C2(IK,L) = CH2(IK,1)+WA(IDL-1)*CH2(IK,2)\n C2(IK,LC) = WA(IDL)*CH2(IK,IP)\n 113 continue\n IDLJ = IDL\n INC = INC+IDO\n DO 115 J=3,IPPH\n JC = IPP2-J\n IDLJ = IDLJ+INC\n if (IDLJ > IDP) IDLJ = IDLJ-IDP\n WAR = WA(IDLJ-1)\n WAI = WA(IDLJ)\n DO 114 IK=1,IDL1\n C2(IK,L) = C2(IK,L)+WAR*CH2(IK,J)\n C2(IK,LC) = C2(IK,LC)+WAI*CH2(IK,JC)\n 114 continue\n 115 continue\n 116 continue\n DO 118 J=2,IPPH\n DO 117 IK=1,IDL1\n CH2(IK,1) = CH2(IK,1)+CH2(IK,J)\n 117 continue\n 118 continue\n DO 120 J=2,IPPH\n JC = IPP2-J\n DO 119 IK=2,IDL1,2\n CH2(IK-1,J) = C2(IK-1,J)-C2(IK,JC)\n CH2(IK-1,JC) = C2(IK-1,J)+C2(IK,JC)\n CH2(IK,J) = C2(IK,J)+C2(IK-1,JC)\n CH2(IK,JC) = C2(IK,J)-C2(IK-1,JC)\n 119 continue\n 120 continue\n NAC = 1\n if (IDO == 2) return\n NAC = 0\n DO 121 IK=1,IDL1\n C2(IK,1) = CH2(IK,1)\n 121 continue\n DO 123 J=2,IP\n DO 122 K=1,L1\n C1(1,K,J) = CH(1,K,J)\n C1(2,K,J) = CH(2,K,J)\n 122 continue\n 123 continue\n if (IDOT > L1) goto 127\n IDIJ = 0\n DO 126 J=2,IP\n IDIJ = IDIJ+2\n DO 125 I=4,IDO,2\n IDIJ = IDIJ+2\n DO 124 K=1,L1\n C1(I-1,K,J) = WA(IDIJ-1)*CH(I-1,K,J)-WA(IDIJ)*CH(I,K,J)\n C1(I,K,J) = WA(IDIJ-1)*CH(I,K,J)+WA(IDIJ)*CH(I-1,K,J)\n 124 continue\n 125 continue\n 126 continue\n return\n 127 IDJ = 2-IDO\n DO 130 J=2,IP\n IDJ = IDJ+IDO\n DO 129 K=1,L1\n IDIJ = IDJ\n DO 128 I=4,IDO,2\n IDIJ = IDIJ+2\n C1(I-1,K,J) = WA(IDIJ-1)*CH(I-1,K,J)-WA(IDIJ)*CH(I,K,J)\n C1(I,K,J) = WA(IDIJ-1)*CH(I,K,J)+WA(IDIJ)*CH(I-1,K,J)\n 128 continue\n 129 continue\n 130 continue\n return\n END\n subroutine PASSB2 (IDO,L1,CC,CH,WA1)\n DIMENSION CC(IDO,2,L1) ,CH(IDO,L1,2), &\n WA1(1)\n if (IDO > 2) goto 102\n DO 101 K=1,L1\n CH(1,K,1) = CC(1,1,K)+CC(1,2,K)\n CH(1,K,2) = CC(1,1,K)-CC(1,2,K)\n CH(2,K,1) = CC(2,1,K)+CC(2,2,K)\n CH(2,K,2) = CC(2,1,K)-CC(2,2,K)\n 101 continue\n return\n 102 DO 104 K=1,L1\n DO 103 I=2,IDO,2\n CH(I-1,K,1) = CC(I-1,1,K)+CC(I-1,2,K)\n TR2 = CC(I-1,1,K)-CC(I-1,2,K)\n CH(I,K,1) = CC(I,1,K)+CC(I,2,K)\n TI2 = CC(I,1,K)-CC(I,2,K)\n CH(I,K,2) = WA1(I-1)*TI2+WA1(I)*TR2\n CH(I-1,K,2) = WA1(I-1)*TR2-WA1(I)*TI2\n 103 continue\n 104 continue\n return\n END\n subroutine PASSB3 (IDO,L1,CC,CH,WA1,WA2)\n DIMENSION CC(IDO,3,L1) ,CH(IDO,L1,3), &\n WA1(1) ,WA2(1)\n DATA TAUR,TAUI /-.5,.866025403784439/\n if (IDO /= 2) goto 102\n DO 101 K=1,L1\n TR2 = CC(1,2,K)+CC(1,3,K)\n CR2 = CC(1,1,K)+TAUR*TR2\n CH(1,K,1) = CC(1,1,K)+TR2\n TI2 = CC(2,2,K)+CC(2,3,K)\n CI2 = CC(2,1,K)+TAUR*TI2\n CH(2,K,1) = CC(2,1,K)+TI2\n CR3 = TAUI*(CC(1,2,K)-CC(1,3,K))\n CI3 = TAUI*(CC(2,2,K)-CC(2,3,K))\n CH(1,K,2) = CR2-CI3\n CH(1,K,3) = CR2+CI3\n CH(2,K,2) = CI2+CR3\n CH(2,K,3) = CI2-CR3\n 101 continue\n return\n 102 DO 104 K=1,L1\n DO 103 I=2,IDO,2\n TR2 = CC(I-1,2,K)+CC(I-1,3,K)\n CR2 = CC(I-1,1,K)+TAUR*TR2\n CH(I-1,K,1) = CC(I-1,1,K)+TR2\n TI2 = CC(I,2,K)+CC(I,3,K)\n CI2 = CC(I,1,K)+TAUR*TI2\n CH(I,K,1) = CC(I,1,K)+TI2\n CR3 = TAUI*(CC(I-1,2,K)-CC(I-1,3,K))\n CI3 = TAUI*(CC(I,2,K)-CC(I,3,K))\n DR2 = CR2-CI3\n DR3 = CR2+CI3\n DI2 = CI2+CR3\n DI3 = CI2-CR3\n CH(I,K,2) = WA1(I-1)*DI2+WA1(I)*DR2\n CH(I-1,K,2) = WA1(I-1)*DR2-WA1(I)*DI2\n CH(I,K,3) = WA2(I-1)*DI3+WA2(I)*DR3\n CH(I-1,K,3) = WA2(I-1)*DR3-WA2(I)*DI3\n 103 continue\n 104 continue\n return\n END\n subroutine PASSB4 (IDO,L1,CC,CH,WA1,WA2,WA3)\n DIMENSION CC(IDO,4,L1) ,CH(IDO,L1,4), &\n WA1(1) ,WA2(1) ,WA3(1)\n if (IDO /= 2) goto 102\n DO 101 K=1,L1\n TI1 = CC(2,1,K)-CC(2,3,K)\n TI2 = CC(2,1,K)+CC(2,3,K)\n TR4 = CC(2,4,K)-CC(2,2,K)\n TI3 = CC(2,2,K)+CC(2,4,K)\n TR1 = CC(1,1,K)-CC(1,3,K)\n TR2 = CC(1,1,K)+CC(1,3,K)\n TI4 = CC(1,2,K)-CC(1,4,K)\n TR3 = CC(1,2,K)+CC(1,4,K)\n CH(1,K,1) = TR2+TR3\n CH(1,K,3) = TR2-TR3\n CH(2,K,1) = TI2+TI3\n CH(2,K,3) = TI2-TI3\n CH(1,K,2) = TR1+TR4\n CH(1,K,4) = TR1-TR4\n CH(2,K,2) = TI1+TI4\n CH(2,K,4) = TI1-TI4\n 101 continue\n return\n 102 DO 104 K=1,L1\n DO 103 I=2,IDO,2\n TI1 = CC(I,1,K)-CC(I,3,K)\n TI2 = CC(I,1,K)+CC(I,3,K)\n TI3 = CC(I,2,K)+CC(I,4,K)\n TR4 = CC(I,4,K)-CC(I,2,K)\n TR1 = CC(I-1,1,K)-CC(I-1,3,K)\n TR2 = CC(I-1,1,K)+CC(I-1,3,K)\n TI4 = CC(I-1,2,K)-CC(I-1,4,K)\n TR3 = CC(I-1,2,K)+CC(I-1,4,K)\n CH(I-1,K,1) = TR2+TR3\n CR3 = TR2-TR3\n CH(I,K,1) = TI2+TI3\n CI3 = TI2-TI3\n CR2 = TR1+TR4\n CR4 = TR1-TR4\n CI2 = TI1+TI4\n CI4 = TI1-TI4\n CH(I-1,K,2) = WA1(I-1)*CR2-WA1(I)*CI2\n CH(I,K,2) = WA1(I-1)*CI2+WA1(I)*CR2\n CH(I-1,K,3) = WA2(I-1)*CR3-WA2(I)*CI3\n CH(I,K,3) = WA2(I-1)*CI3+WA2(I)*CR3\n CH(I-1,K,4) = WA3(I-1)*CR4-WA3(I)*CI4\n CH(I,K,4) = WA3(I-1)*CI4+WA3(I)*CR4\n 103 continue\n 104 continue\n return\n END\n subroutine PASSB5 (IDO,L1,CC,CH,WA1,WA2,WA3,WA4)\n DIMENSION CC(IDO,5,L1) ,CH(IDO,L1,5), &\n WA1(1) ,WA2(1) ,WA3(1) ,WA4(1)\n DATA TR11,TI11,TR12,TI12 /.309016994374947,.951056516295154, &\n -.809016994374947,.587785252292473/\n if (IDO /= 2) goto 102\n DO 101 K=1,L1\n TI5 = CC(2,2,K)-CC(2,5,K)\n TI2 = CC(2,2,K)+CC(2,5,K)\n TI4 = CC(2,3,K)-CC(2,4,K)\n TI3 = CC(2,3,K)+CC(2,4,K)\n TR5 = CC(1,2,K)-CC(1,5,K)\n TR2 = CC(1,2,K)+CC(1,5,K)\n TR4 = CC(1,3,K)-CC(1,4,K)\n TR3 = CC(1,3,K)+CC(1,4,K)\n CH(1,K,1) = CC(1,1,K)+TR2+TR3\n CH(2,K,1) = CC(2,1,K)+TI2+TI3\n CR2 = CC(1,1,K)+TR11*TR2+TR12*TR3\n CI2 = CC(2,1,K)+TR11*TI2+TR12*TI3\n CR3 = CC(1,1,K)+TR12*TR2+TR11*TR3\n CI3 = CC(2,1,K)+TR12*TI2+TR11*TI3\n CR5 = TI11*TR5+TI12*TR4\n CI5 = TI11*TI5+TI12*TI4\n CR4 = TI12*TR5-TI11*TR4\n CI4 = TI12*TI5-TI11*TI4\n CH(1,K,2) = CR2-CI5\n CH(1,K,5) = CR2+CI5\n CH(2,K,2) = CI2+CR5\n CH(2,K,3) = CI3+CR4\n CH(1,K,3) = CR3-CI4\n CH(1,K,4) = CR3+CI4\n CH(2,K,4) = CI3-CR4\n CH(2,K,5) = CI2-CR5\n 101 continue\n return\n 102 DO 104 K=1,L1\n DO 103 I=2,IDO,2\n TI5 = CC(I,2,K)-CC(I,5,K)\n TI2 = CC(I,2,K)+CC(I,5,K)\n TI4 = CC(I,3,K)-CC(I,4,K)\n TI3 = CC(I,3,K)+CC(I,4,K)\n TR5 = CC(I-1,2,K)-CC(I-1,5,K)\n TR2 = CC(I-1,2,K)+CC(I-1,5,K)\n TR4 = CC(I-1,3,K)-CC(I-1,4,K)\n TR3 = CC(I-1,3,K)+CC(I-1,4,K)\n CH(I-1,K,1) = CC(I-1,1,K)+TR2+TR3\n CH(I,K,1) = CC(I,1,K)+TI2+TI3\n CR2 = CC(I-1,1,K)+TR11*TR2+TR12*TR3\n CI2 = CC(I,1,K)+TR11*TI2+TR12*TI3\n CR3 = CC(I-1,1,K)+TR12*TR2+TR11*TR3\n CI3 = CC(I,1,K)+TR12*TI2+TR11*TI3\n CR5 = TI11*TR5+TI12*TR4\n CI5 = TI11*TI5+TI12*TI4\n CR4 = TI12*TR5-TI11*TR4\n CI4 = TI12*TI5-TI11*TI4\n DR3 = CR3-CI4\n DR4 = CR3+CI4\n DI3 = CI3+CR4\n DI4 = CI3-CR4\n DR5 = CR2+CI5\n DR2 = CR2-CI5\n DI5 = CI2-CR5\n DI2 = CI2+CR5\n CH(I-1,K,2) = WA1(I-1)*DR2-WA1(I)*DI2\n CH(I,K,2) = WA1(I-1)*DI2+WA1(I)*DR2\n CH(I-1,K,3) = WA2(I-1)*DR3-WA2(I)*DI3\n CH(I,K,3) = WA2(I-1)*DI3+WA2(I)*DR3\n CH(I-1,K,4) = WA3(I-1)*DR4-WA3(I)*DI4\n CH(I,K,4) = WA3(I-1)*DI4+WA3(I)*DR4\n CH(I-1,K,5) = WA4(I-1)*DR5-WA4(I)*DI5\n CH(I,K,5) = WA4(I-1)*DI5+WA4(I)*DR5\n 103 continue\n 104 continue\n return\n END\n\n\n\n subroutine CFFTI (N,WSAVE)\n DIMENSION WSAVE(1)\n if (N == 1) return\n IW1 = N+N+1\n IW2 = IW1+N+N\n CALL CFFTI1 (N,WSAVE(IW1),WSAVE(IW2))\n return\n END\n subroutine CFFTI1 (N,WA,IFAC)\n DIMENSION WA(1) ,IFAC(1) ,NTRYH(4)\n DATA NTRYH(1),NTRYH(2),NTRYH(3),NTRYH(4)/3,4,2,5/\n NL = N\n NF = 0\n J = 0\n 101 J = J+1\n if (J-4) 102,102,103\n 102 NTRY = NTRYH(J)\n goto 104\n 103 NTRY = NTRY+2\n 104 NQ = NL/NTRY\n NR = NL-NTRY*NQ\n if (NR) 101,105,101\n 105 NF = NF+1\n IFAC(NF+2) = NTRY\n NL = NQ\n if (NTRY /= 2) goto 107\n if (NF == 1) goto 107\n DO 106 I=2,NF\n IB = NF-I+2\n IFAC(IB+2) = IFAC(IB+1)\n 106 continue\n IFAC(3) = 2\n 107 if (NL /= 1) goto 104\n IFAC(1) = N\n IFAC(2) = NF\n TPI = 6.28318530717959\n ARGH = TPI/FLOAT(N)\n I = 2\n L1 = 1\n DO 110 K1=1,NF\n IP = IFAC(K1+2)\n LD = 0\n L2 = L1*IP\n IDO = N/L2\n IDOT = IDO+IDO+2\n IPM = IP-1\n DO 109 J=1,IPM\n I1 = I\n WA(I-1) = 1.\n WA(I) = 0.\n LD = LD+L1\n FI = 0.\n ARGLD = FLOAT(LD)*ARGH\n DO 108 II=4,IDOT,2\n I = I+2\n FI = FI+1.\n ARG = FI*ARGLD\n WA(I-1) = COS(ARG)\n WA(I) = SIN(ARG)\n 108 continue\n if (IP <= 5) goto 109\n WA(I1-1) = WA(I-1)\n WA(I1) = WA(I)\n 109 continue\n L1 = L2\n 110 continue\n return\n END\n\n\n\n\n\n subroutine CFFTF (N,C,WSAVE)\n DIMENSION C(1) ,WSAVE(1)\n if (N == 1) return\n IW1 = N+N+1\n IW2 = IW1+N+N\n CALL CFFTF1 (N,C,WSAVE,WSAVE(IW1),WSAVE(IW2))\n return\n END\n subroutine CFFTF1 (N,C,CH,WA,IFAC)\n DIMENSION CH(1) ,C(1) ,WA(1) ,IFAC(1)\n NF = IFAC(2)\n NA = 0\n L1 = 1\n IW = 1\n DO 116 K1=1,NF\n IP = IFAC(K1+2)\n L2 = IP*L1\n IDO = N/L2\n IDOT = IDO+IDO\n IDL1 = IDOT*L1\n if (IP /= 4) goto 103\n IX2 = IW+IDOT\n IX3 = IX2+IDOT\n if (NA /= 0) goto 101\n CALL PASSF4 (IDOT,L1,C,CH,WA(IW),WA(IX2),WA(IX3))\n goto 102\n 101 CALL PASSF4 (IDOT,L1,CH,C,WA(IW),WA(IX2),WA(IX3))\n 102 NA = 1-NA\n goto 115\n 103 if (IP /= 2) goto 106\n if (NA /= 0) goto 104\n CALL PASSF2 (IDOT,L1,C,CH,WA(IW))\n goto 105\n 104 CALL PASSF2 (IDOT,L1,CH,C,WA(IW))\n 105 NA = 1-NA\n goto 115\n 106 if (IP /= 3) goto 109\n IX2 = IW+IDOT\n if (NA /= 0) goto 107\n CALL PASSF3 (IDOT,L1,C,CH,WA(IW),WA(IX2))\n goto 108\n 107 CALL PASSF3 (IDOT,L1,CH,C,WA(IW),WA(IX2))\n 108 NA = 1-NA\n goto 115\n 109 if (IP /= 5) goto 112\n IX2 = IW+IDOT\n IX3 = IX2+IDOT\n IX4 = IX3+IDOT\n if (NA /= 0) goto 110\n CALL PASSF5 (IDOT,L1,C,CH,WA(IW),WA(IX2),WA(IX3),WA(IX4))\n goto 111\n 110 CALL PASSF5 (IDOT,L1,CH,C,WA(IW),WA(IX2),WA(IX3),WA(IX4))\n 111 NA = 1-NA\n goto 115\n 112 if (NA /= 0) goto 113\n CALL PASSF (NAC,IDOT,IP,L1,IDL1,C,C,C,CH,CH,WA(IW))\n goto 114\n 113 CALL PASSF (NAC,IDOT,IP,L1,IDL1,CH,CH,CH,C,C,WA(IW))\n 114 if (NAC /= 0) NA = 1-NA\n 115 L1 = L2\n IW = IW+(IP-1)*IDOT\n 116 continue\n if (NA == 0) return\n N2 = N+N\n DO 117 I=1,N2\n C(I) = CH(I)\n 117 continue\n return\n END\n subroutine PASSF (NAC,IDO,IP,L1,IDL1,CC,C1,C2,CH,CH2,WA)\n DIMENSION CH(IDO,L1,IP) ,CC(IDO,IP,L1), &\n C1(IDO,L1,IP) ,WA(1) ,C2(IDL1,IP), &\n CH2(IDL1,IP)\n IDOT = IDO/2\n NT = IP*IDL1\n IPP2 = IP+2\n IPPH = (IP+1)/2\n IDP = IP*IDO\n!\n if (IDO < L1) goto 106\n DO 103 J=2,IPPH\n JC = IPP2-J\n DO 102 K=1,L1\n DO 101 I=1,IDO\n CH(I,K,J) = CC(I,J,K)+CC(I,JC,K)\n CH(I,K,JC) = CC(I,J,K)-CC(I,JC,K)\n 101 continue\n 102 continue\n 103 continue\n DO 105 K=1,L1\n DO 104 I=1,IDO\n CH(I,K,1) = CC(I,1,K)\n 104 continue\n 105 continue\n goto 112\n 106 DO 109 J=2,IPPH\n JC = IPP2-J\n DO 108 I=1,IDO\n DO 107 K=1,L1\n CH(I,K,J) = CC(I,J,K)+CC(I,JC,K)\n CH(I,K,JC) = CC(I,J,K)-CC(I,JC,K)\n 107 continue\n 108 continue\n 109 continue\n DO 111 I=1,IDO\n DO 110 K=1,L1\n CH(I,K,1) = CC(I,1,K)\n 110 continue\n 111 continue\n 112 IDL = 2-IDO\n INC = 0\n DO 116 L=2,IPPH\n LC = IPP2-L\n IDL = IDL+IDO\n DO 113 IK=1,IDL1\n C2(IK,L) = CH2(IK,1)+WA(IDL-1)*CH2(IK,2)\n C2(IK,LC) = -WA(IDL)*CH2(IK,IP)\n 113 continue\n IDLJ = IDL\n INC = INC+IDO\n DO 115 J=3,IPPH\n JC = IPP2-J\n IDLJ = IDLJ+INC\n if (IDLJ > IDP) IDLJ = IDLJ-IDP\n WAR = WA(IDLJ-1)\n WAI = WA(IDLJ)\n DO 114 IK=1,IDL1\n C2(IK,L) = C2(IK,L)+WAR*CH2(IK,J)\n C2(IK,LC) = C2(IK,LC)-WAI*CH2(IK,JC)\n 114 continue\n 115 continue\n 116 continue\n DO 118 J=2,IPPH\n DO 117 IK=1,IDL1\n CH2(IK,1) = CH2(IK,1)+CH2(IK,J)\n 117 continue\n 118 continue\n DO 120 J=2,IPPH\n JC = IPP2-J\n DO 119 IK=2,IDL1,2\n CH2(IK-1,J) = C2(IK-1,J)-C2(IK,JC)\n CH2(IK-1,JC) = C2(IK-1,J)+C2(IK,JC)\n CH2(IK,J) = C2(IK,J)+C2(IK-1,JC)\n CH2(IK,JC) = C2(IK,J)-C2(IK-1,JC)\n 119 continue\n 120 continue\n NAC = 1\n if (IDO == 2) return\n NAC = 0\n DO 121 IK=1,IDL1\n C2(IK,1) = CH2(IK,1)\n 121 continue\n DO 123 J=2,IP\n DO 122 K=1,L1\n C1(1,K,J) = CH(1,K,J)\n C1(2,K,J) = CH(2,K,J)\n 122 continue\n 123 continue\n if (IDOT > L1) goto 127\n IDIJ = 0\n DO 126 J=2,IP\n IDIJ = IDIJ+2\n DO 125 I=4,IDO,2\n IDIJ = IDIJ+2\n DO 124 K=1,L1\n C1(I-1,K,J) = WA(IDIJ-1)*CH(I-1,K,J)+WA(IDIJ)*CH(I,K,J)\n C1(I,K,J) = WA(IDIJ-1)*CH(I,K,J)-WA(IDIJ)*CH(I-1,K,J)\n 124 continue\n 125 continue\n 126 continue\n return\n 127 IDJ = 2-IDO\n DO 130 J=2,IP\n IDJ = IDJ+IDO\n DO 129 K=1,L1\n IDIJ = IDJ\n DO 128 I=4,IDO,2\n IDIJ = IDIJ+2\n C1(I-1,K,J) = WA(IDIJ-1)*CH(I-1,K,J)+WA(IDIJ)*CH(I,K,J)\n C1(I,K,J) = WA(IDIJ-1)*CH(I,K,J)-WA(IDIJ)*CH(I-1,K,J)\n 128 continue\n 129 continue\n 130 continue\n return\n END\n subroutine PASSF2 (IDO,L1,CC,CH,WA1)\n DIMENSION CC(IDO,2,L1) ,CH(IDO,L1,2), &\n WA1(1)\n if (IDO > 2) goto 102\n DO 101 K=1,L1\n CH(1,K,1) = CC(1,1,K)+CC(1,2,K)\n CH(1,K,2) = CC(1,1,K)-CC(1,2,K)\n CH(2,K,1) = CC(2,1,K)+CC(2,2,K)\n CH(2,K,2) = CC(2,1,K)-CC(2,2,K)\n 101 continue\n return\n 102 DO 104 K=1,L1\n DO 103 I=2,IDO,2\n CH(I-1,K,1) = CC(I-1,1,K)+CC(I-1,2,K)\n TR2 = CC(I-1,1,K)-CC(I-1,2,K)\n CH(I,K,1) = CC(I,1,K)+CC(I,2,K)\n TI2 = CC(I,1,K)-CC(I,2,K)\n CH(I,K,2) = WA1(I-1)*TI2-WA1(I)*TR2\n CH(I-1,K,2) = WA1(I-1)*TR2+WA1(I)*TI2\n 103 continue\n 104 continue\n return\n END\n subroutine PASSF3 (IDO,L1,CC,CH,WA1,WA2)\n DIMENSION CC(IDO,3,L1) ,CH(IDO,L1,3), &\n WA1(1) ,WA2(1)\n DATA TAUR,TAUI /-.5,-.866025403784439/\n if (IDO /= 2) goto 102\n DO 101 K=1,L1\n TR2 = CC(1,2,K)+CC(1,3,K)\n CR2 = CC(1,1,K)+TAUR*TR2\n CH(1,K,1) = CC(1,1,K)+TR2\n TI2 = CC(2,2,K)+CC(2,3,K)\n CI2 = CC(2,1,K)+TAUR*TI2\n CH(2,K,1) = CC(2,1,K)+TI2\n CR3 = TAUI*(CC(1,2,K)-CC(1,3,K))\n CI3 = TAUI*(CC(2,2,K)-CC(2,3,K))\n CH(1,K,2) = CR2-CI3\n CH(1,K,3) = CR2+CI3\n CH(2,K,2) = CI2+CR3\n CH(2,K,3) = CI2-CR3\n 101 continue\n return\n 102 DO 104 K=1,L1\n DO 103 I=2,IDO,2\n TR2 = CC(I-1,2,K)+CC(I-1,3,K)\n CR2 = CC(I-1,1,K)+TAUR*TR2\n CH(I-1,K,1) = CC(I-1,1,K)+TR2\n TI2 = CC(I,2,K)+CC(I,3,K)\n CI2 = CC(I,1,K)+TAUR*TI2\n CH(I,K,1) = CC(I,1,K)+TI2\n CR3 = TAUI*(CC(I-1,2,K)-CC(I-1,3,K))\n CI3 = TAUI*(CC(I,2,K)-CC(I,3,K))\n DR2 = CR2-CI3\n DR3 = CR2+CI3\n DI2 = CI2+CR3\n DI3 = CI2-CR3\n CH(I,K,2) = WA1(I-1)*DI2-WA1(I)*DR2\n CH(I-1,K,2) = WA1(I-1)*DR2+WA1(I)*DI2\n CH(I,K,3) = WA2(I-1)*DI3-WA2(I)*DR3\n CH(I-1,K,3) = WA2(I-1)*DR3+WA2(I)*DI3\n 103 continue\n 104 continue\n return\n END\n subroutine PASSF4 (IDO,L1,CC,CH,WA1,WA2,WA3)\n DIMENSION CC(IDO,4,L1) ,CH(IDO,L1,4), &\n WA1(1) ,WA2(1) ,WA3(1)\n if (IDO /= 2) goto 102\n DO 101 K=1,L1\n TI1 = CC(2,1,K)-CC(2,3,K)\n TI2 = CC(2,1,K)+CC(2,3,K)\n TR4 = CC(2,2,K)-CC(2,4,K)\n TI3 = CC(2,2,K)+CC(2,4,K)\n TR1 = CC(1,1,K)-CC(1,3,K)\n TR2 = CC(1,1,K)+CC(1,3,K)\n TI4 = CC(1,4,K)-CC(1,2,K)\n TR3 = CC(1,2,K)+CC(1,4,K)\n CH(1,K,1) = TR2+TR3\n CH(1,K,3) = TR2-TR3\n CH(2,K,1) = TI2+TI3\n CH(2,K,3) = TI2-TI3\n CH(1,K,2) = TR1+TR4\n CH(1,K,4) = TR1-TR4\n CH(2,K,2) = TI1+TI4\n CH(2,K,4) = TI1-TI4\n 101 continue\n return\n 102 DO 104 K=1,L1\n DO 103 I=2,IDO,2\n TI1 = CC(I,1,K)-CC(I,3,K)\n TI2 = CC(I,1,K)+CC(I,3,K)\n TI3 = CC(I,2,K)+CC(I,4,K)\n TR4 = CC(I,2,K)-CC(I,4,K)\n TR1 = CC(I-1,1,K)-CC(I-1,3,K)\n TR2 = CC(I-1,1,K)+CC(I-1,3,K)\n TI4 = CC(I-1,4,K)-CC(I-1,2,K)\n TR3 = CC(I-1,2,K)+CC(I-1,4,K)\n CH(I-1,K,1) = TR2+TR3\n CR3 = TR2-TR3\n CH(I,K,1) = TI2+TI3\n CI3 = TI2-TI3\n CR2 = TR1+TR4\n CR4 = TR1-TR4\n CI2 = TI1+TI4\n CI4 = TI1-TI4\n CH(I-1,K,2) = WA1(I-1)*CR2+WA1(I)*CI2\n CH(I,K,2) = WA1(I-1)*CI2-WA1(I)*CR2\n CH(I-1,K,3) = WA2(I-1)*CR3+WA2(I)*CI3\n CH(I,K,3) = WA2(I-1)*CI3-WA2(I)*CR3\n CH(I-1,K,4) = WA3(I-1)*CR4+WA3(I)*CI4\n CH(I,K,4) = WA3(I-1)*CI4-WA3(I)*CR4\n 103 continue\n 104 continue\n return\n END\n subroutine PASSF5 (IDO,L1,CC,CH,WA1,WA2,WA3,WA4)\n DIMENSION CC(IDO,5,L1) ,CH(IDO,L1,5), &\n WA1(1) ,WA2(1) ,WA3(1) ,WA4(1)\n DATA TR11,TI11,TR12,TI12 /.309016994374947,-.951056516295154, &\n -.809016994374947,-.587785252292473/\n if (IDO /= 2) goto 102\n DO 101 K=1,L1\n TI5 = CC(2,2,K)-CC(2,5,K)\n TI2 = CC(2,2,K)+CC(2,5,K)\n TI4 = CC(2,3,K)-CC(2,4,K)\n TI3 = CC(2,3,K)+CC(2,4,K)\n TR5 = CC(1,2,K)-CC(1,5,K)\n TR2 = CC(1,2,K)+CC(1,5,K)\n TR4 = CC(1,3,K)-CC(1,4,K)\n TR3 = CC(1,3,K)+CC(1,4,K)\n CH(1,K,1) = CC(1,1,K)+TR2+TR3\n CH(2,K,1) = CC(2,1,K)+TI2+TI3\n CR2 = CC(1,1,K)+TR11*TR2+TR12*TR3\n CI2 = CC(2,1,K)+TR11*TI2+TR12*TI3\n CR3 = CC(1,1,K)+TR12*TR2+TR11*TR3\n CI3 = CC(2,1,K)+TR12*TI2+TR11*TI3\n CR5 = TI11*TR5+TI12*TR4\n CI5 = TI11*TI5+TI12*TI4\n CR4 = TI12*TR5-TI11*TR4\n CI4 = TI12*TI5-TI11*TI4\n CH(1,K,2) = CR2-CI5\n CH(1,K,5) = CR2+CI5\n CH(2,K,2) = CI2+CR5\n CH(2,K,3) = CI3+CR4\n CH(1,K,3) = CR3-CI4\n CH(1,K,4) = CR3+CI4\n CH(2,K,4) = CI3-CR4\n CH(2,K,5) = CI2-CR5\n 101 continue\n return\n 102 DO 104 K=1,L1\n DO 103 I=2,IDO,2\n TI5 = CC(I,2,K)-CC(I,5,K)\n TI2 = CC(I,2,K)+CC(I,5,K)\n TI4 = CC(I,3,K)-CC(I,4,K)\n TI3 = CC(I,3,K)+CC(I,4,K)\n TR5 = CC(I-1,2,K)-CC(I-1,5,K)\n TR2 = CC(I-1,2,K)+CC(I-1,5,K)\n TR4 = CC(I-1,3,K)-CC(I-1,4,K)\n TR3 = CC(I-1,3,K)+CC(I-1,4,K)\n CH(I-1,K,1) = CC(I-1,1,K)+TR2+TR3\n CH(I,K,1) = CC(I,1,K)+TI2+TI3\n CR2 = CC(I-1,1,K)+TR11*TR2+TR12*TR3\n CI2 = CC(I,1,K)+TR11*TI2+TR12*TI3\n CR3 = CC(I-1,1,K)+TR12*TR2+TR11*TR3\n CI3 = CC(I,1,K)+TR12*TI2+TR11*TI3\n CR5 = TI11*TR5+TI12*TR4\n CI5 = TI11*TI5+TI12*TI4\n CR4 = TI12*TR5-TI11*TR4\n CI4 = TI12*TI5-TI11*TI4\n DR3 = CR3-CI4\n DR4 = CR3+CI4\n DI3 = CI3+CR4\n DI4 = CI3-CR4\n DR5 = CR2+CI5\n DR2 = CR2-CI5\n DI5 = CI2-CR5\n DI2 = CI2+CR5\n CH(I-1,K,2) = WA1(I-1)*DR2+WA1(I)*DI2\n CH(I,K,2) = WA1(I-1)*DI2-WA1(I)*DR2\n CH(I-1,K,3) = WA2(I-1)*DR3+WA2(I)*DI3\n CH(I,K,3) = WA2(I-1)*DI3-WA2(I)*DR3\n CH(I-1,K,4) = WA3(I-1)*DR4+WA3(I)*DI4\n CH(I,K,4) = WA3(I-1)*DI4-WA3(I)*DR4\n CH(I-1,K,5) = WA4(I-1)*DR5+WA4(I)*DI5\n CH(I,K,5) = WA4(I-1)*DI5-WA4(I)*DR5\n 103 continue\n 104 continue\n return\n END\n\n", "meta": {"hexsha": "9df0688f8c375b53b9f6a0be16a0b29c913fdff2", "size": 42330, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/example2/reference/analytical_solution_viscoelastic_3D_Carcione_and_Komatitsch_correct_with_1_over_L.f90", "max_stars_repo_name": "batearedcollie/specfem3d-docker", "max_stars_repo_head_hexsha": "e58385aac717eea2722b85ae1113778f21c7585d", "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": "example/example2/reference/analytical_solution_viscoelastic_3D_Carcione_and_Komatitsch_correct_with_1_over_L.f90", "max_issues_repo_name": "batearedcollie/specfem3d-docker", "max_issues_repo_head_hexsha": "e58385aac717eea2722b85ae1113778f21c7585d", "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": "example/example2/reference/analytical_solution_viscoelastic_3D_Carcione_and_Komatitsch_correct_with_1_over_L.f90", "max_forks_repo_name": "batearedcollie/specfem3d-docker", "max_forks_repo_head_hexsha": "e58385aac717eea2722b85ae1113778f21c7585d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.4971181556, "max_line_length": 131, "alphanum_fraction": 0.5971178833, "num_tokens": 17463, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765328159727, "lm_q2_score": 0.7401743735019595, "lm_q1q2_score": 0.6762799552605051}} {"text": "!-------------------------------------------------------------------------------\n! Copyright (c) 2016 The University of Tokyo\n! This software is released under the MIT License, see LICENSE.txt\n!-------------------------------------------------------------------------------\n!> \\brief This module contains functions for interpolation in 9 node\n!! quadrilateral element\nmodule shape_quad9n\n !####################################################################\n\n implicit none\n\n !--------------------------------------------------------------------\n\n integer, parameter, private :: kreal = kind( 0.0D0 )\n\n !--------------------------------------------------------------------\n\ncontains\n\n\n !####################################################################\n subroutine ShapeFunc_quad9n(lcoord, func)\n !####################################################################\n\n real(kind = kreal), intent(in) :: lcoord(2)\n real(kind = kreal), intent(out) :: func(9)\n\n !--------------------------------------------------------------------\n\n real(kind = kreal) :: xi(9), eta(9)\n real(kind = kreal) :: n_xi(9), n_eta(9)\n\n integer :: na\n\n !--------------------------------------------------------------------\n\n ! xi-coordinate at a node in a local element\n xi(1) = -1.0D0\n xi(2) = 1.0D0\n xi(3) = 1.0D0\n xi(4) = -1.0D0\n xi(5) = 0.0D0\n xi(6) = 1.0D0\n xi(7) = 0.0D0\n xi(8) = -1.0D0\n xi(9) = 0.0D0\n ! eta-coordinate at a node in a local element\n eta(1) = -1.0D0\n eta(2) = -1.0D0\n eta(3) = 1.0D0\n eta(4) = 1.0D0\n eta(5) = -1.0D0\n eta(6) = 0.0D0\n eta(7) = 1.0D0\n eta(8) = 0.0D0\n eta(9) = 0.0D0\n\n !--------------------------------------------------------------------\n\n do na = 1, 9\n\n n_xi(na) = ( 0.5D0*xi(na) *lcoord(1) ) &\n *( 1.0D0+xi(na) *lcoord(1) ) &\n +( 1.0D0-xi(na) *xi(na) ) &\n *( 1.0D0-lcoord(1)*lcoord(1) )\n n_eta(na) = ( 0.5D0*eta(na)*lcoord(2) ) &\n *( 1.0D0+eta(na)*lcoord(2) ) &\n +( 1.0D0-eta(na)*eta(na) ) &\n *( 1.0D0-lcoord(2)*lcoord(2) )\n\n end do\n\n !--------------------------------------------------------------------\n\n do na = 1, 9\n\n func(na) = n_xi(na)*n_eta(na)\n\n end do\n\n !--------------------------------------------------------------------\n\n return\n\n !####################################################################\n end subroutine ShapeFunc_quad9n\n !####################################################################\n\n !####################################################################\n subroutine ShapeDeriv_quad9n(lcoord, func)\n !####################################################################\n\n real(kind = kreal), intent(in) :: lcoord(2)\n real(kind = kreal), intent(out) :: func(9, 2)\n\n !--------------------------------------------------------------------\n\n real(kind = kreal) :: xi(9), eta(9)\n real(kind = kreal) :: n_xi(9), n_eta(9)\n real(kind = kreal) :: dn_xi(9), dn_eta(9)\n\n integer :: na\n\n !--------------------------------------------------------------------\n\n ! xi-coordinate at a node in a local element\n xi(1) = -1.0D0\n xi(2) = 1.0D0\n xi(3) = 1.0D0\n xi(4) = -1.0D0\n xi(5) = 0.0D0\n xi(6) = 1.0D0\n xi(7) = 0.0D0\n xi(8) = -1.0D0\n xi(9) = 0.0D0\n ! eta-coordinate at a node in a local element\n eta(1) = -1.0D0\n eta(2) = -1.0D0\n eta(3) = 1.0D0\n eta(4) = 1.0D0\n eta(5) = -1.0D0\n eta(6) = 0.0D0\n eta(7) = 1.0D0\n eta(8) = 0.0D0\n eta(9) = 0.0D0\n\n !--------------------------------------------------------------------\n\n do na = 1, 9\n\n n_xi(na) = ( 0.5D0*xi(na) *lcoord(1) ) &\n *( 1.0D0+xi(na) *lcoord(1) ) &\n +( 1.0D0-xi(na) *xi(na) ) &\n *( 1.0D0-lcoord(1)*lcoord(1) )\n n_eta(na) = ( 0.5D0*eta(na)*lcoord(2) ) &\n *( 1.0D0+eta(na)*lcoord(2) ) &\n +( 1.0D0-eta(na)*eta(na) ) &\n *( 1.0D0-lcoord(2)*lcoord(2) )\n\n dn_xi(na) = ( 0.5D0*xi(na) ) &\n *( 1.0D0+xi(na) *lcoord(1) ) &\n +( 0.5D0*xi(na) *lcoord(1) ) &\n *xi(na) &\n +( 1.0D0-xi(na) *xi(na) ) &\n *( -2.0D0*lcoord(1) )\n dn_eta(na) = ( 0.5D0*eta(na) ) &\n *( 1.0D0+eta(na)*lcoord(2) ) &\n +( 0.5D0*eta(na)*lcoord(2) ) &\n *eta(na) &\n +( 1.0D0-eta(na)*eta(na) ) &\n *( -2.0D0*lcoord(2) )\n\n end do\n\n !--------------------------------------------------------------------\n\n do na = 1, 9\n\n func(na, 1) = dn_xi(na)*n_eta(na)\n func(na, 2) = n_xi(na) *dn_eta(na)\n\n end do\n\n !--------------------------------------------------------------------\n\n return\n\n !####################################################################\n end subroutine ShapeDeriv_quad9n\n !####################################################################\n\n !####################################################################\n subroutine NodalNaturalCoord_quad9n(nncoord)\n !####################################################################\n\n real(kind = kreal), intent(out) :: nncoord(9, 2)\n\n !--------------------------------------------------------------------\n\n ! xi-coordinate at a node in a local element\n nncoord(1, 1) = -1.0D0\n nncoord(2, 1) = 1.0D0\n nncoord(3, 1) = 1.0D0\n nncoord(4, 1) = -1.0D0\n nncoord(5, 1) = 0.0D0\n nncoord(6, 1) = 1.0D0\n nncoord(7, 1) = 0.0D0\n nncoord(8, 1) = -1.0D0\n nncoord(9, 1) = 0.0D0\n ! eta-coordinate at a node in a local element\n nncoord(1, 2) = -1.0D0\n nncoord(2, 2) = -1.0D0\n nncoord(3, 2) = 1.0D0\n nncoord(4, 2) = 1.0D0\n nncoord(5, 2) = -1.0D0\n nncoord(6, 2) = 0.0D0\n nncoord(7, 2) = 1.0D0\n nncoord(8, 2) = 0.0D0\n nncoord(9, 2) = 0.0D0\n\n !--------------------------------------------------------------------\n\n return\n\n !####################################################################\n end subroutine NodalNaturalCoord_quad9n\n !####################################################################\n\nend module shape_quad9n\n", "meta": {"hexsha": "d2d0b867fdedaf067a00af96748c462be2de8d76", "size": 6213, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fistr1/src/lib/element/quad9n.f90", "max_stars_repo_name": "tkoyama010/FrontISTR", "max_stars_repo_head_hexsha": "2ce1f0425b87df76261c86ddb93bb4b588f72718", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fistr1/src/lib/element/quad9n.f90", "max_issues_repo_name": "tkoyama010/FrontISTR", "max_issues_repo_head_hexsha": "2ce1f0425b87df76261c86ddb93bb4b588f72718", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fistr1/src/lib/element/quad9n.f90", "max_forks_repo_name": "tkoyama010/FrontISTR", "max_forks_repo_head_hexsha": "2ce1f0425b87df76261c86ddb93bb4b588f72718", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.5857142857, "max_line_length": 80, "alphanum_fraction": 0.3219056816, "num_tokens": 2069, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.913676530465412, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.676279937810547}} {"text": "program sail_gen\n!-------------------------------------------------------!\n!\tPROGRAM TO GENERATE DARPA SUBOFF SAIL\t\t!\n!\tFULL/MODEL RATIO = 24\t\t\t\t!\n!\tPOINTS CALCULATED BY EQUATIONS:\tUNIT = FEET\t!\n! SAIL FOREBODY EQ. FOR 3.032986 <= X <= 3.358507\t!\n!\t\t\t 0.833333 <= Z <= 1.507813\t!\n! SAIL MID-BODY EQ. FOR 3.358507 <= X <= 3.559028\t!\n!\t\t\t 0.833333 <= Z <= 1.507813 !\n! SAIL AFTERBODY EQ. FOR 3.559028 <= X <= 4.241319\t!\n!\t\t\t 0.833333 <= Z <= 1.507813 !\n! SAIL CAP EQ.\t FOR 3.032986 <= X <= 4.241319\t!\n!\t\t\t 1.507813 <= Z <= 1.562501 !\n! \tOFFSETS ARE COMPUTED EVERY 0.005 FT\t\t!\n!\t\t\t\t\t\t\t!\n!\t\tXiaolong Tang: tangxl@buaa.edu.cn\t!\n!\t\t\t\t 01/26/2018\t!\n!\t\t \tBEIHANG UNIVERSITY\t!\n!-------------------------------------------------------!\nIMPLICIT NONE\nREAL(8) A1,B1,A3,B3,C3,D3,E3,HMAX,DX,DX0,XXCST,XXAFN,XXFFN,XXMFN,XZST,XZEND\nREAL(8) XZ,XX,ADUM\nREAL(8) X,DM1,A,B,C,D,E,F,G,H,P\nINTEGER I,J,NI,NP,ICON1,N_OMIT\nDIMENSION NP(300),X(300,50,3)\nCHARACTER(LEN=20) FILENAME\n!-------------------------------!\n!\tDEFINE CONSTANTS\t!\n!-------------------------------!\nA1 = 2.094759\nB1 = 0.207178\nA3 = 2.908891\nB3 = 1.234491\nC3 = 3.444817\nD3 = 3.850435\nE3 = 2.080019\nHMAX = 0.109375\n!MAX HALF THICKNESS OF SAIL\nDX = 0.005\nDX0 = 0.005\nXXCST = 3.032986\nXXAFN = 4.241319\nXXFFN = 3.358507\nXXMFN = 3.559028\nXZST = 1.507813\nXX=XXCST-DX\nDO 1000 I=1,300\n XZ=XZST\n X(I,1,3)=XZ\n ! (I,1,3) = (POINT I, LAYER 1, AXIS 1/2/3)\n ! AXIS 1 = XX = LENGTH, 2 = XY = WIDTH, 3 = XZ = HEIGHT\n J=1\n XX=XX+DX\n X(I,1,1)=XX\n IF(XX.GT.XXAFN) THEN\n ! XX REACHED THE ENDPOINT\n ! NI = NUMBER OF EFFECTIVE POINTS\n NI=I-1\n GOTO 1014\n ENDIF\n IF(XX.GT.XXFFN) GOTO 1002\n!-------------------------------!\n! SAIL FOREBODY EQUATION !\n!-------------------------------!\n D=3.072000*(XX-3.032986)\n DM1=D-1\n A=2*D*(DM1**4)\n B=D*D*(DM1**3)/3\n C=1- ((DM1**4)*(4*D+1))\n X(I,1,2)=HMAX*(SQRT(A1*A+B1*B+C))\n GOTO 1004\n!-------------------------------!\n! SAIL MID-BODY EQUATION !\n!-------------------------------!\n1002 CONTINUE\n IF(XX.GT.XXMFN) GOTO 1003\n X(I,1,2)=HMAX\n GOTO 1004\n!-------------------------------!\n! SAIL AFTER-BODY EQUATION !\n!-------------------------------!\n1003 CONTINUE\n E=(4.241319-XX)/0.6822917\n F=E-1\n G=2.238361*E*F**4\n H=3.106529*(E**2)*(F**3)\n P=1-(F**4)*(4*E+1)\n X(I,1,2)=0.1093750*(G+H+P)\n!-------------------------------!\n! SAIL CAP EQUATION !\n!-------------------------------!\n1004 CONTINUE\n XZEND=(X(I,1,2)/2)+1.507813\n NP(I)=1\n DO 1008 J=2,50\n ICON1=0\n1005 XZ=XZ+DX\n X(I,J,3)=XZ\n IF(XZ.GT.XZEND) THEN\n ICON1=ICON1+1\n IF(ICON1.EQ.1) THEN\n XZ=XZ-DX\n DX=0.0005\n GOTO 1005\n ENDIF\n IF(ICON1.EQ.2) THEN\n X(I,J,2)=0.0\n X(I,J,3)=XZEND\n NP(I)=J\n ICON1=0\n DX=DX0\n GOTO 1000\n ENDIF\n ENDIF\n ADUM=(X(I,1,2)**2)-((2*(XZ-XZST))**2)\n X(I,J,2)=SQRT(ADUM)\n1008 CONTINUE\n1000 CONTINUE\n!-------------------------------!\n! WRITE OFFSETS TO FILE !\n!-------------------------------!\n1014 OPEN (10,FILE=\"sail-parallel-top.dat\",STATUS=\"UNKNOWN\")\nWRITE(10,*) NI,1\nDO I=1,NI\n WRITE(10,4) X(I,1,1),X(I,1,2),X(I,1,3)\nENDDO\nCLOSE(10)\nOPEN (20,FILE=\"sail-parallel-bottom.dat\",STATUS=\"UNKNOWN\")\nWRITE(20,*) NI,1\nDO I=1,NI\n WRITE(20,4) X(I,1,1),X(I,1,2),0.0\nENDDO\nCLOSE(20)\nOPEN (30,FILE=\"sail-cap.dat\",STATUS=\"UNKNOWN\")\n! OMIT OUTPUT EVERY 8 STEPS\nN_OMIT=8\nDO 1013 I=1,NI,N_OMIT\n ! THE LINE BELOW IS FORMAT DATA FOR ICEMCFD INPUT\n WRITE(30,*) NP(I)+1,1\n! WRITE(30,'(I3)') I\n! WRITE(30,'(A2,F7.3,A4)') \"X=\",X(I,1,1),\"FEET\"\n! WRITE(30,'(I5)') NP(I)+1\n WRITE(30,4) X(I,1,1),X(I,1,2),1.507813\n DO J=1,NP(I)\n WRITE(30,4) X(I,1,1),X(I,J,2),X(I,J,3)\n ENDDO\n4 FORMAT(3F16.12)\n1013 CONTINUE\nCLOSE(30)\nSTOP\nEND\n\n", "meta": {"hexsha": "678996e3c537af823d92644a6421a9a0dde2f70d", "size": 3777, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "sail.f90", "max_stars_repo_name": "oldFarmerBuaa/darpa_suboff_geom_gen", "max_stars_repo_head_hexsha": "ecf7fef53023f52105a7a3c363a2b1a64dab5b94", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-09-01T04:03:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-16T11:09:38.000Z", "max_issues_repo_path": "sail.f90", "max_issues_repo_name": "oldFarmerBuaa/darpa_suboff_geom_gen", "max_issues_repo_head_hexsha": "ecf7fef53023f52105a7a3c363a2b1a64dab5b94", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sail.f90", "max_forks_repo_name": "oldFarmerBuaa/darpa_suboff_geom_gen", "max_forks_repo_head_hexsha": "ecf7fef53023f52105a7a3c363a2b1a64dab5b94", "max_forks_repo_licenses": ["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.6862745098, "max_line_length": 75, "alphanum_fraction": 0.5014561822, "num_tokens": 1681, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.913676514011486, "lm_q2_score": 0.7401743677704878, "lm_q1q2_score": 0.6762799361051949}} {"text": "program problem69\n implicit none\n integer, parameter :: n=78498,limit=1000000\n integer, dimension(n) :: primes\n integer :: i,temp\n\n ! https://primes.utm.edu/lists/small/100000.txt\n open(33,file='./data/problem69.dat')\n read(33,*) primes\n\n ! https://en.wikipedia.org/wiki/Euler%27s_totient_function\n ! $\\frac{n}{\\phi(n)} = \\prod_{p|n}(\\frac{p}{p-1})$\n ! Factors with powers greater than one increase n but not n/phi(n).\n ! Small factors are preferable to large ones, so greedily multiply.\n temp=1\n do i=1,n\n temp=temp*primes(i)\n if (temp>limit) then\n temp=temp/primes(i)\n go to 100\n end if\n end do\n\n100 continue\n print *, temp\n\nend program problem69\n", "meta": {"hexsha": "7d8c761dd17025c1340c5cee3450084461e676e3", "size": 707, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "problem69.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": "problem69.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": "problem69.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": 25.25, "max_line_length": 69, "alphanum_fraction": 0.6478076379, "num_tokens": 216, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148513, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6762799360707222}} {"text": " subroutine spline (n, x, y, b, c, d)\n integer n\n real x(n), y(n), b(n), c(n), d(n)\nc\nc the coefficients b(i), c(i), and d(i), i=1,2,...,n are computed\nc for a cubic interpolating spline\nc\nc s(x) = y(i) + b(i)*(x-x(i)) + c(i)*(x-x(i))**2 + d(i)*(x-x(i))**3\nc\nc for x(i) .le. x .le. x(i+1)\nc\nc input..\nc\nc n = the number of data points or knots (n.ge.2)\nc x = the abscissas of the knots in strictly increasing order\nc y = the ordinates of the knots\nc\nc output..\nc\nc b, c, d = arrays of spline coefficients as defined above.\nc\nc using p to denote differentiation,\nc\nc y(i) = s(x(i))\nc b(i) = sp(x(i))\nc c(i) = spp(x(i))/2\nc d(i) = sppp(x(i))/6 (derivative from the right)\nc\nc the accompanying function subprogram seval can be used\nc to evaluate the spline.\nc\nc\n integer nm1, ib, i\n real t\nc\n nm1 = n-1\n if ( n .lt. 2 ) return\n if ( n .lt. 3 ) go to 50\nc\nc set up tridiagonal system\nc\nc b = diagonal, d = offdiagonal, c = right hand side.\nc\n d(1) = x(2) - x(1)\n c(2) = (y(2) - y(1))/d(1)\n do 10 i = 2, nm1\n d(i) = x(i+1) - x(i)\n b(i) = 2.*(d(i-1) + d(i))\n c(i+1) = (y(i+1) - y(i))/d(i)\n c(i) = c(i+1) - c(i)\n 10 continue\nc\nc end conditions. third derivatives at x(1) and x(n)\nc obtained from divided differences\nc\n b(1) = -d(1)\n b(n) = -d(n-1)\n c(1) = 0.\n c(n) = 0.\n if ( n .eq. 3 ) go to 15\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))\nc\nc forward elimination\nc\n 15 do 20 i = 2, n\n t = d(i-1)/b(i-1)\n b(i) = b(i) - t*d(i-1)\n c(i) = c(i) - t*c(i-1)\n 20 continue\nc\nc back substitution\nc\n c(n) = c(n)/b(n)\n do 30 ib = 1, nm1\n i = n-ib\n c(i) = (c(i) - d(i)*c(i+1))/b(i)\n 30 continue\nc\nc c(i) is now the sigma(i) of the text\nc\nc compute polynomial coefficients\nc\n b(n) = (y(n) - y(nm1))/d(nm1) + d(nm1)*(c(nm1) + 2.*c(n))\n do 40 i = 1, nm1\n b(i) = (y(i+1) - y(i))/d(i) - d(i)*(c(i+1) + 2.*c(i))\n d(i) = (c(i+1) - c(i))/d(i)\n c(i) = 3.*c(i)\n 40 continue\n c(n) = 3.*c(n)\n d(n) = d(n-1)\n return\nc\n 50 b(1) = (y(2)-y(1))/(x(2)-x(1))\n c(1) = 0.\n d(1) = 0.\n b(2) = b(1)\n c(2) = 0.\n d(2) = 0.\n return\n end\n", "meta": {"hexsha": "95b42279557a78b509e9e4bf2007117eda1483f6", "size": 2450, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Resources/netlib.org/sfmm/spline.f", "max_stars_repo_name": "RobinSchmidt/LAPackCPP", "max_stars_repo_head_hexsha": "e0a47c2f93f1af54afc6c60f3330ce81260e2a2b", "max_stars_repo_licenses": ["Intel"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Resources/netlib.org/sfmm/spline.f", "max_issues_repo_name": "RobinSchmidt/LAPackCPP", "max_issues_repo_head_hexsha": "e0a47c2f93f1af54afc6c60f3330ce81260e2a2b", "max_issues_repo_licenses": ["Intel"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Resources/netlib.org/sfmm/spline.f", "max_forks_repo_name": "RobinSchmidt/LAPackCPP", "max_forks_repo_head_hexsha": "e0a47c2f93f1af54afc6c60f3330ce81260e2a2b", "max_forks_repo_licenses": ["Intel"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.5576923077, "max_line_length": 70, "alphanum_fraction": 0.4559183673, "num_tokens": 1087, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765163620469, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6762799273715978}} {"text": "\tsubroutine cor(ni,nj,psi0,psi,auto,au_x,au_y)\n\timplicit none\n\tinteger*4 i,j,ni,nj\n\treal*8 :: xmin,ymin,xmax,ymax,dx,dy,x,y,wx,wy \n\tcomplex*16,intent(IN) :: psi0(ni,nj),psi(ni,nj)\n\tcomplex*16 :: im\n\treal*8,intent(out) :: auto\n\treal*8 :: qx0,qy0,ax,ay,au_x,au_y,px0,py0\n real*8 cor_d\n\n\tcommon /grid/ xmin,ymin,xmax,ymax,dx,dy\n\tcommon /para1/ wx,wy\n common /ini/ qx0,qy0,px0,py0\n common /wav/ ax,ay\n common /correlation/ cor_d\nccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\n\tauto=0d0\n\tau_x=0d0\n\tau_y=0d0\n\tim=(0d0,1d0)\n cor_d=0d0\nc------correlation function-------------------------------\n do j=1,nj\n y=ymin+(j-1)*dy\n do i=1,ni\n x=xmin+(i-1)*dx\n auto=auto+conjg(psi(i,j))*psi0(i,j)*dx*dy\n\tau_x=au_x+conjg(psi(i,j))*exp(-ax*x**2+im*px0*(x-qx0))*dx*dy\n au_y=au_y+conjg(psi(i,j))*exp(-ay*y**2+im*py0*(x-qy0))*dx*dy\n cor_d=cor_d+abs(psi0(i,j))**2*abs(psi(i,j))**2*dx*dy\n enddo\n\tenddo\nc yy=yy+abs(psi(i,j))**2*dx*dy*y**2\nc\tex=ex+abs(psi(i,j))**2*dx*dy*(x**2*y-y**3/3d0)\n\n\tend subroutine\n\t\n\t\n", "meta": {"hexsha": "0a75e8f09bd4ecbd76a9169b8c26e6e436b07633", "size": 1089, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "SPO/spo_2d/1.0.0/cor.f", "max_stars_repo_name": "binggu56/qmd", "max_stars_repo_head_hexsha": "e2628710de15f8a8b9a1280fcf92f9e87559414c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "SPO/spo_2d/1.0.0/cor.f", "max_issues_repo_name": "binggu56/qmd", "max_issues_repo_head_hexsha": "e2628710de15f8a8b9a1280fcf92f9e87559414c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SPO/spo_2d/1.0.0/cor.f", "max_forks_repo_name": "binggu56/qmd", "max_forks_repo_head_hexsha": "e2628710de15f8a8b9a1280fcf92f9e87559414c", "max_forks_repo_licenses": ["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.9230769231, "max_line_length": 66, "alphanum_fraction": 0.5913682277, "num_tokens": 472, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765234137296, "lm_q2_score": 0.7401743505760728, "lm_q1q2_score": 0.6762799273543614}} {"text": "!--------------------------------------------------------------------------------------------------!\n! CP2K: A general program to perform molecular dynamics simulations !\n! Copyright (C) 2000 - 2018 CP2K developers group !\n!--------------------------------------------------------------------------------------------------!\n\n! **************************************************************************************************\n!> \\brief Collection of simple mathematical functions and subroutines\n!> \\par History\n!> FUNCTION angle updated and FUNCTION dihedral angle added; cleaned\n!> (13.03.2004,MK)\n!> \\author MK (15.11.1998)\n! **************************************************************************************************\nMODULE mathlib\n\n USE kinds, ONLY: default_string_length,&\n dp\n USE mathconstants, ONLY: euler,&\n fac\n IMPLICIT NONE\n\n PRIVATE\n\n REAL(KIND=dp), PARAMETER :: eps_geo = 1.0E-6_dp\n\n ! Public functions\n\n PUBLIC :: angle, &\n det_3x3, &\n inv_3x3\n\n INTERFACE det_3x3\n MODULE PROCEDURE det_3x3_1, det_3x3_2\n END INTERFACE\n\n\nCONTAINS\n\n\n! **************************************************************************************************\n!> \\brief Calculation of the angle between the vectors a and b.\n!> The angle is returned in radians.\n!> \\param a ...\n!> \\param b ...\n!> \\return ...\n!> \\date 14.10.1998\n!> \\author MK\n!> \\version 1.0\n! **************************************************************************************************\n FUNCTION angle(a, b) RESULT(angle_ab)\n\n REAL(KIND=dp), DIMENSION(:), INTENT(IN) :: a, b\n REAL(KIND=dp) :: angle_ab\n\n REAL(KIND=dp) :: length_of_a, length_of_b\n REAL(KIND=dp), DIMENSION(SIZE(a, 1)) :: a_norm, b_norm\n\n length_of_a = SQRT(DOT_PRODUCT(a, a))\n length_of_b = SQRT(DOT_PRODUCT(b, b))\n\n IF ((length_of_a > eps_geo) .AND. (length_of_b > eps_geo)) THEN\n a_norm(:) = a(:)/length_of_a\n b_norm(:) = b(:)/length_of_b\n angle_ab = ACOS(MIN(MAX(DOT_PRODUCT(a_norm, b_norm), -1.0_dp), 1.0_dp))\n ELSE\n angle_ab = 0.0_dp\n END IF\n\n END FUNCTION angle\n\n! **************************************************************************************************\n!> \\brief Returns the determinante of the 3x3 matrix a.\n!> \\param a ...\n!> \\return ...\n!> \\date 13.03.2004\n!> \\author MK\n!> \\version 1.0\n! **************************************************************************************************\n FUNCTION det_3x3_1(a) RESULT(det_a)\n REAL(KIND=dp), DIMENSION(3, 3), INTENT(IN) :: a\n REAL(KIND=dp) :: det_a\n\n det_a = a(1, 1)*(a(2, 2)*a(3, 3)-a(2, 3)*a(3, 2))+ &\n a(1, 2)*(a(2, 3)*a(3, 1)-a(2, 1)*a(3, 3))+ &\n a(1, 3)*(a(2, 1)*a(3, 2)-a(2, 2)*a(3, 1))\n\n END FUNCTION det_3x3_1\n\n! **************************************************************************************************\n!> \\brief Returns the determinante of the 3x3 matrix a given by its columns.\n!> \\param a1 ...\n!> \\param a2 ...\n!> \\param a3 ...\n!> \\return ...\n!> \\date 13.03.2004\n!> \\author MK\n!> \\version 1.0\n! **************************************************************************************************\n FUNCTION det_3x3_2(a1, a2, a3) RESULT(det_a)\n REAL(KIND=dp), DIMENSION(3), INTENT(IN) :: a1, a2, a3\n REAL(KIND=dp) :: det_a\n\n det_a = a1(1)*(a2(2)*a3(3)-a3(2)*a2(3))+ &\n a2(1)*(a3(2)*a1(3)-a1(2)*a3(3))+ &\n a3(1)*(a1(2)*a2(3)-a2(2)*a1(3))\n\n END FUNCTION det_3x3_2\n\n\n! **************************************************************************************************\n!> \\brief Returns the inverse of the 3 x 3 matrix a.\n!> \\param a ...\n!> \\return ...\n!> \\date 13.03.2004\n!> \\author MK\n!> \\version 1.0\n! **************************************************************************************************\n FUNCTION inv_3x3(a) RESULT(a_inv)\n\n REAL(KIND=dp), DIMENSION(3, 3), INTENT(IN) :: a\n REAL(KIND=dp), DIMENSION(3, 3) :: a_inv\n\n REAL(KIND=dp) :: det_a\n\n det_a = 1.0_dp/det_3x3(a)\n\n a_inv(1, 1) = (a(2, 2)*a(3, 3)-a(3, 2)*a(2, 3))*det_a\n a_inv(2, 1) = (a(2, 3)*a(3, 1)-a(3, 3)*a(2, 1))*det_a\n a_inv(3, 1) = (a(2, 1)*a(3, 2)-a(3, 1)*a(2, 2))*det_a\n\n a_inv(1, 2) = (a(1, 3)*a(3, 2)-a(3, 3)*a(1, 2))*det_a\n a_inv(2, 2) = (a(1, 1)*a(3, 3)-a(3, 1)*a(1, 3))*det_a\n a_inv(3, 2) = (a(1, 2)*a(3, 1)-a(3, 2)*a(1, 1))*det_a\n\n a_inv(1, 3) = (a(1, 2)*a(2, 3)-a(2, 2)*a(1, 3))*det_a\n a_inv(2, 3) = (a(1, 3)*a(2, 1)-a(2, 3)*a(1, 1))*det_a\n a_inv(3, 3) = (a(1, 1)*a(2, 2)-a(2, 1)*a(1, 2))*det_a\n\n END FUNCTION inv_3x3\n\nEND MODULE mathlib\n", "meta": {"hexsha": "e7bb183d59418e1f2c777479f13405ed338ffaf8", "size": 5150, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "CP2K/kernel-benchmark/src/dependencies/common/mathlib.f90", "max_stars_repo_name": "berkhess/bioexcel-exascale-co-design-benchmarks", "max_stars_repo_head_hexsha": "c32f811d41a93fb69e49b3e7374f6028e37970d2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-04-20T04:33:11.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-20T04:33:11.000Z", "max_issues_repo_path": "CP2K/kernel-benchmark/src/dependencies/common/mathlib.f90", "max_issues_repo_name": "berkhess/bioexcel-exascale-co-design-benchmarks", "max_issues_repo_head_hexsha": "c32f811d41a93fb69e49b3e7374f6028e37970d2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2019-07-10T15:18:21.000Z", "max_issues_repo_issues_event_max_datetime": "2019-07-31T13:38:09.000Z", "max_forks_repo_path": "CP2K/kernel-benchmark/src/dependencies/common/mathlib.f90", "max_forks_repo_name": "berkhess/bioexcel-exascale-co-design-benchmarks", "max_forks_repo_head_hexsha": "c32f811d41a93fb69e49b3e7374f6028e37970d2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-07-10T10:50:25.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-08T13:42:52.000Z", "avg_line_length": 36.524822695, "max_line_length": 100, "alphanum_fraction": 0.3712621359, "num_tokens": 1557, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6762137813310826}} {"text": "*> \\brief \\b SGETSLS\n*\n* Definition:\n* ===========\n*\n* SUBROUTINE SGETSLS( TRANS, M, N, NRHS, A, LDA, B, LDB,\n* $ WORK, LWORK, INFO )\n*\n* .. Scalar Arguments ..\n* CHARACTER TRANS\n* INTEGER INFO, LDA, LDB, LWORK, M, N, NRHS\n* ..\n* .. Array Arguments ..\n* REAL A( LDA, * ), B( LDB, * ), WORK( * )\n* ..\n*\n*\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*>\n*> SGETSLS solves overdetermined or underdetermined real linear systems\n*> involving an M-by-N matrix A, using a tall skinny QR or short wide LQ\n*> factorization of A. It is assumed that A has full rank.\n*>\n*>\n*>\n*> The following options are provided:\n*>\n*> 1. If TRANS = 'N' and m >= n: find the least squares solution of\n*> an overdetermined system, i.e., solve the least squares problem\n*> minimize || B - A*X ||.\n*>\n*> 2. If TRANS = 'N' and m < n: find the minimum norm solution of\n*> an underdetermined system A * X = B.\n*>\n*> 3. If TRANS = 'T' and m >= n: find the minimum norm solution of\n*> an undetermined system A**T * X = B.\n*>\n*> 4. If TRANS = 'T' and m < n: find the least squares solution of\n*> an overdetermined system, i.e., solve the least squares problem\n*> minimize || B - A**T * X ||.\n*>\n*> Several right hand side vectors b and solution vectors x can be\n*> handled in a single call; they are stored as the columns of the\n*> M-by-NRHS right hand side matrix B and the N-by-NRHS solution\n*> matrix X.\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in] TRANS\n*> \\verbatim\n*> TRANS is CHARACTER*1\n*> = 'N': the linear system involves A;\n*> = 'T': the linear system involves A**T.\n*> \\endverbatim\n*>\n*> \\param[in] M\n*> \\verbatim\n*> M is INTEGER\n*> The number of rows of the matrix A. M >= 0.\n*> \\endverbatim\n*>\n*> \\param[in] N\n*> \\verbatim\n*> N is INTEGER\n*> The number of columns of the matrix A. N >= 0.\n*> \\endverbatim\n*>\n*> \\param[in] NRHS\n*> \\verbatim\n*> NRHS is INTEGER\n*> The number of right hand sides, i.e., the number of\n*> columns of the matrices B and X. NRHS >=0.\n*> \\endverbatim\n*>\n*> \\param[in,out] A\n*> \\verbatim\n*> A is REAL array, dimension (LDA,N)\n*> On entry, the M-by-N matrix A.\n*> On exit,\n*> A is overwritten by details of its QR or LQ\n*> factorization as returned by SGEQR or SGELQ.\n*> \\endverbatim\n*>\n*> \\param[in] LDA\n*> \\verbatim\n*> LDA is INTEGER\n*> The leading dimension of the array A. LDA >= max(1,M).\n*> \\endverbatim\n*>\n*> \\param[in,out] B\n*> \\verbatim\n*> B is REAL array, dimension (LDB,NRHS)\n*> On entry, the matrix B of right hand side vectors, stored\n*> columnwise; B is M-by-NRHS if TRANS = 'N', or N-by-NRHS\n*> if TRANS = 'T'.\n*> On exit, if INFO = 0, B is overwritten by the solution\n*> vectors, stored columnwise:\n*> if TRANS = 'N' and m >= n, rows 1 to n of B contain the least\n*> squares solution vectors.\n*> if TRANS = 'N' and m < n, rows 1 to N of B contain the\n*> minimum norm solution vectors;\n*> if TRANS = 'T' and m >= n, rows 1 to M of B contain the\n*> minimum norm solution vectors;\n*> if TRANS = 'T' and m < n, rows 1 to M of B contain the\n*> least squares solution vectors.\n*> \\endverbatim\n*>\n*> \\param[in] LDB\n*> \\verbatim\n*> LDB is INTEGER\n*> The leading dimension of the array B. LDB >= MAX(1,M,N).\n*> \\endverbatim\n*>\n*> \\param[out] WORK\n*> \\verbatim\n*> (workspace) REAL array, dimension (MAX(1,LWORK))\n*> On exit, if INFO = 0, WORK(1) contains optimal (or either minimal\n*> or optimal, if query was assumed) LWORK.\n*> See LWORK for details.\n*> \\endverbatim\n*>\n*> \\param[in] LWORK\n*> \\verbatim\n*> LWORK is INTEGER\n*> The dimension of the array WORK.\n*> If LWORK = -1 or -2, then a workspace query is assumed.\n*> If LWORK = -1, the routine calculates optimal size of WORK for the\n*> optimal performance and returns this value in WORK(1).\n*> If LWORK = -2, the routine calculates minimal size of WORK and \n*> returns this value in WORK(1).\n*> \\endverbatim\n*>\n*> \\param[out] INFO\n*> \\verbatim\n*> INFO is INTEGER\n*> = 0: successful exit\n*> < 0: if INFO = -i, the i-th argument had an illegal value\n*> > 0: if INFO = i, the i-th diagonal element of the\n*> triangular factor of A is zero, so that A does not have\n*> full rank; the least squares solution could not be\n*> computed.\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee\n*> \\author Univ. of California Berkeley\n*> \\author Univ. of Colorado Denver\n*> \\author NAG Ltd.\n*\n*> \\date June 2017\n*\n*> \\ingroup realGEsolve\n*\n* =====================================================================\n SUBROUTINE SGETSLS( TRANS, M, N, NRHS, A, LDA, B, LDB,\n $ WORK, LWORK, INFO )\n*\n* -- LAPACK driver routine (version 3.7.1) --\n* -- LAPACK is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n* June 2017\n*\n* .. Scalar Arguments ..\n CHARACTER TRANS\n INTEGER INFO, LDA, LDB, LWORK, M, N, NRHS\n* ..\n* .. Array Arguments ..\n REAL A( LDA, * ), B( LDB, * ), WORK( * )\n*\n* ..\n*\n* =====================================================================\n*\n* .. Parameters ..\n REAL ZERO, ONE\n PARAMETER ( ZERO = 0.0E0, ONE = 1.0E0 )\n* ..\n* .. Local Scalars ..\n LOGICAL LQUERY, TRAN\n INTEGER I, IASCL, IBSCL, J, MINMN, MAXMN, BROW,\n $ SCLLEN, MNK, TSZO, TSZM, LWO, LWM, LW1, LW2,\n $ WSIZEO, WSIZEM, INFO2\n REAL ANRM, BIGNUM, BNRM, SMLNUM, TQ( 5 ), WORKQ( 1 )\n* ..\n* .. External Functions ..\n LOGICAL LSAME\n INTEGER ILAENV\n REAL SLAMCH, SLANGE\n EXTERNAL LSAME, ILAENV, SLABAD, SLAMCH, SLANGE\n* ..\n* .. External Subroutines ..\n EXTERNAL SGEQR, SGEMQR, SLASCL, SLASET,\n $ STRTRS, XERBLA, SGELQ, SGEMLQ\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC REAL, MAX, MIN, INT\n* ..\n* .. Executable Statements ..\n*\n* Test the input arguments.\n*\n INFO = 0\n MINMN = MIN( M, N )\n MAXMN = MAX( M, N )\n MNK = MAX( MINMN, NRHS )\n TRAN = LSAME( TRANS, 'T' )\n*\n LQUERY = ( LWORK.EQ.-1 .OR. LWORK.EQ.-2 )\n IF( .NOT.( LSAME( TRANS, 'N' ) .OR.\n $ LSAME( TRANS, 'T' ) ) ) THEN\n INFO = -1\n ELSE IF( M.LT.0 ) THEN\n INFO = -2\n ELSE IF( N.LT.0 ) THEN\n INFO = -3\n ELSE IF( NRHS.LT.0 ) THEN\n INFO = -4\n ELSE IF( LDA.LT.MAX( 1, M ) ) THEN\n INFO = -6\n ELSE IF( LDB.LT.MAX( 1, M, N ) ) THEN\n INFO = -8\n END IF\n*\n IF( INFO.EQ.0 ) THEN\n*\n* Determine the block size and minimum LWORK\n*\n IF( M.GE.N ) THEN\n CALL SGEQR( M, N, A, LDA, TQ, -1, WORKQ, -1, INFO2 )\n TSZO = INT( TQ( 1 ) )\n LWO = INT( WORKQ( 1 ) )\n CALL SGEMQR( 'L', TRANS, M, NRHS, N, A, LDA, TQ,\n $ TSZO, B, LDB, WORKQ, -1, INFO2 )\n LWO = MAX( LWO, INT( WORKQ( 1 ) ) )\n CALL SGEQR( M, N, A, LDA, TQ, -2, WORKQ, -2, INFO2 )\n TSZM = INT( TQ( 1 ) )\n LWM = INT( WORKQ( 1 ) )\n CALL SGEMQR( 'L', TRANS, M, NRHS, N, A, LDA, TQ,\n $ TSZM, B, LDB, WORKQ, -1, INFO2 )\n LWM = MAX( LWM, INT( WORKQ( 1 ) ) )\n WSIZEO = TSZO + LWO\n WSIZEM = TSZM + LWM\n ELSE\n CALL SGELQ( M, N, A, LDA, TQ, -1, WORKQ, -1, INFO2 )\n TSZO = INT( TQ( 1 ) )\n LWO = INT( WORKQ( 1 ) )\n CALL SGEMLQ( 'L', TRANS, N, NRHS, M, A, LDA, TQ,\n $ TSZO, B, LDB, WORKQ, -1, INFO2 )\n LWO = MAX( LWO, INT( WORKQ( 1 ) ) )\n CALL SGELQ( M, N, A, LDA, TQ, -2, WORKQ, -2, INFO2 )\n TSZM = INT( TQ( 1 ) )\n LWM = INT( WORKQ( 1 ) )\n CALL SGEMLQ( 'L', TRANS, N, NRHS, M, A, LDA, TQ,\n $ TSZM, B, LDB, WORKQ, -1, INFO2 )\n LWM = MAX( LWM, INT( WORKQ( 1 ) ) )\n WSIZEO = TSZO + LWO\n WSIZEM = TSZM + LWM\n END IF\n*\n IF( ( LWORK.LT.WSIZEM ).AND.( .NOT.LQUERY ) ) THEN\n INFO = -10\n END IF\n*\n END IF\n*\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'SGETSLS', -INFO )\n WORK( 1 ) = REAL( WSIZEO )\n RETURN\n END IF\n IF( LQUERY ) THEN\n IF( LWORK.EQ.-1 ) WORK( 1 ) = REAL( WSIZEO )\n IF( LWORK.EQ.-2 ) WORK( 1 ) = REAL( WSIZEM )\n RETURN\n END IF\n IF( LWORK.LT.WSIZEO ) THEN\n LW1 = TSZM\n LW2 = LWM\n ELSE\n LW1 = TSZO\n LW2 = LWO\n END IF\n*\n* Quick return if possible\n*\n IF( MIN( M, N, NRHS ).EQ.0 ) THEN\n CALL SLASET( 'FULL', MAX( M, N ), NRHS, ZERO, ZERO,\n $ B, LDB )\n RETURN\n END IF\n*\n* Get machine parameters\n*\n SMLNUM = SLAMCH( 'S' ) / SLAMCH( 'P' )\n BIGNUM = ONE / SMLNUM\n CALL SLABAD( SMLNUM, BIGNUM )\n*\n* Scale A, B if max element outside range [SMLNUM,BIGNUM]\n*\n ANRM = SLANGE( 'M', M, N, A, LDA, WORK )\n IASCL = 0\n IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN\n*\n* Scale matrix norm up to SMLNUM\n*\n CALL SLASCL( 'G', 0, 0, ANRM, SMLNUM, M, N, A, LDA, INFO )\n IASCL = 1\n ELSE IF( ANRM.GT.BIGNUM ) THEN\n*\n* Scale matrix norm down to BIGNUM\n*\n CALL SLASCL( 'G', 0, 0, ANRM, BIGNUM, M, N, A, LDA, INFO )\n IASCL = 2\n ELSE IF( ANRM.EQ.ZERO ) THEN\n*\n* Matrix all zero. Return zero solution.\n*\n CALL SLASET( 'F', MAXMN, NRHS, ZERO, ZERO, B, LDB )\n GO TO 50\n END IF\n*\n BROW = M\n IF ( TRAN ) THEN\n BROW = N\n END IF\n BNRM = SLANGE( 'M', BROW, NRHS, B, LDB, WORK )\n IBSCL = 0\n IF( BNRM.GT.ZERO .AND. BNRM.LT.SMLNUM ) THEN\n*\n* Scale matrix norm up to SMLNUM\n*\n CALL SLASCL( 'G', 0, 0, BNRM, SMLNUM, BROW, NRHS, B, LDB,\n $ INFO )\n IBSCL = 1\n ELSE IF( BNRM.GT.BIGNUM ) THEN\n*\n* Scale matrix norm down to BIGNUM\n*\n CALL SLASCL( 'G', 0, 0, BNRM, BIGNUM, BROW, NRHS, B, LDB,\n $ INFO )\n IBSCL = 2\n END IF\n*\n IF ( M.GE.N ) THEN\n*\n* compute QR factorization of A\n*\n CALL SGEQR( M, N, A, LDA, WORK( LW2+1 ), LW1,\n $ WORK( 1 ), LW2, INFO )\n IF ( .NOT.TRAN ) THEN\n*\n* Least-Squares Problem min || A * X - B ||\n*\n* B(1:M,1:NRHS) := Q**T * B(1:M,1:NRHS)\n*\n CALL SGEMQR( 'L' , 'T', M, NRHS, N, A, LDA,\n $ WORK( LW2+1 ), LW1, B, LDB, WORK( 1 ), LW2,\n $ INFO )\n*\n* B(1:N,1:NRHS) := inv(R) * B(1:N,1:NRHS)\n*\n CALL STRTRS( 'U', 'N', 'N', N, NRHS,\n $ A, LDA, B, LDB, INFO )\n IF( INFO.GT.0 ) THEN\n RETURN\n END IF\n SCLLEN = N\n ELSE\n*\n* Overdetermined system of equations A**T * X = B\n*\n* B(1:N,1:NRHS) := inv(R**T) * B(1:N,1:NRHS)\n*\n CALL STRTRS( 'U', 'T', 'N', N, NRHS,\n $ A, LDA, B, LDB, INFO )\n*\n IF( INFO.GT.0 ) THEN\n RETURN\n END IF\n*\n* B(N+1:M,1:NRHS) = ZERO\n*\n DO 20 J = 1, NRHS\n DO 10 I = N + 1, M\n B( I, J ) = ZERO\n 10 CONTINUE\n 20 CONTINUE\n*\n* B(1:M,1:NRHS) := Q(1:N,:) * B(1:N,1:NRHS)\n*\n CALL SGEMQR( 'L', 'N', M, NRHS, N, A, LDA,\n $ WORK( LW2+1 ), LW1, B, LDB, WORK( 1 ), LW2,\n $ INFO )\n*\n SCLLEN = M\n*\n END IF\n*\n ELSE\n*\n* Compute LQ factorization of A\n*\n CALL SGELQ( M, N, A, LDA, WORK( LW2+1 ), LW1,\n $ WORK( 1 ), LW2, INFO )\n*\n* workspace at least M, optimally M*NB.\n*\n IF( .NOT.TRAN ) THEN\n*\n* underdetermined system of equations A * X = B\n*\n* B(1:M,1:NRHS) := inv(L) * B(1:M,1:NRHS)\n*\n CALL STRTRS( 'L', 'N', 'N', M, NRHS,\n $ A, LDA, B, LDB, INFO )\n*\n IF( INFO.GT.0 ) THEN\n RETURN\n END IF\n*\n* B(M+1:N,1:NRHS) = 0\n*\n DO 40 J = 1, NRHS\n DO 30 I = M + 1, N\n B( I, J ) = ZERO\n 30 CONTINUE\n 40 CONTINUE\n*\n* B(1:N,1:NRHS) := Q(1:N,:)**T * B(1:M,1:NRHS)\n*\n CALL SGEMLQ( 'L', 'T', N, NRHS, M, A, LDA,\n $ WORK( LW2+1 ), LW1, B, LDB, WORK( 1 ), LW2,\n $ INFO )\n*\n* workspace at least NRHS, optimally NRHS*NB\n*\n SCLLEN = N\n*\n ELSE\n*\n* overdetermined system min || A**T * X - B ||\n*\n* B(1:N,1:NRHS) := Q * B(1:N,1:NRHS)\n*\n CALL SGEMLQ( 'L', 'N', N, NRHS, M, A, LDA,\n $ WORK( LW2+1 ), LW1, B, LDB, WORK( 1 ), LW2,\n $ INFO )\n*\n* workspace at least NRHS, optimally NRHS*NB\n*\n* B(1:M,1:NRHS) := inv(L**T) * B(1:M,1:NRHS)\n*\n CALL STRTRS( 'Lower', 'Transpose', 'Non-unit', M, NRHS,\n $ A, LDA, B, LDB, INFO )\n*\n IF( INFO.GT.0 ) THEN\n RETURN\n END IF\n*\n SCLLEN = M\n*\n END IF\n*\n END IF\n*\n* Undo scaling\n*\n IF( IASCL.EQ.1 ) THEN\n CALL SLASCL( 'G', 0, 0, ANRM, SMLNUM, SCLLEN, NRHS, B, LDB,\n $ INFO )\n ELSE IF( IASCL.EQ.2 ) THEN\n CALL SLASCL( 'G', 0, 0, ANRM, BIGNUM, SCLLEN, NRHS, B, LDB,\n $ INFO )\n END IF\n IF( IBSCL.EQ.1 ) THEN\n CALL SLASCL( 'G', 0, 0, SMLNUM, BNRM, SCLLEN, NRHS, B, LDB,\n $ INFO )\n ELSE IF( IBSCL.EQ.2 ) THEN\n CALL SLASCL( 'G', 0, 0, BIGNUM, BNRM, SCLLEN, NRHS, B, LDB,\n $ INFO )\n END IF\n*\n 50 CONTINUE\n WORK( 1 ) = REAL( TSZO + LWO )\n RETURN\n*\n* End of SGETSLS\n*\n END\n", "meta": {"hexsha": "3bf084515f63ffd792466d5210084980de7e9c1a", "size": 14450, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "lapack-netlib/SRC/sgetsls.f", "max_stars_repo_name": "dnoan/OpenBLAS", "max_stars_repo_head_hexsha": "b54b50fe3a5ec921d18ddf5fbdb80092d1b23893", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 4392, "max_stars_repo_stars_event_min_datetime": "2015-01-02T18:15:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T12:14:38.000Z", "max_issues_repo_path": "lapack-netlib/SRC/sgetsls.f", "max_issues_repo_name": "dnoan/OpenBLAS", "max_issues_repo_head_hexsha": "b54b50fe3a5ec921d18ddf5fbdb80092d1b23893", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2067, "max_issues_repo_issues_event_min_datetime": "2015-01-01T03:50:01.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T18:59:43.000Z", "max_forks_repo_path": "lapack-netlib/SRC/sgetsls.f", "max_forks_repo_name": "dnoan/OpenBLAS", "max_forks_repo_head_hexsha": "b54b50fe3a5ec921d18ddf5fbdb80092d1b23893", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1564, "max_forks_repo_forks_event_min_datetime": "2015-01-01T01:32:27.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T07:12:54.000Z", "avg_line_length": 29.0744466801, "max_line_length": 78, "alphanum_fraction": 0.4669204152, "num_tokens": 4841, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9099070035949657, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6762137810600889}} {"text": "\nc===========================================================================\n function topointegral(xim,xcell,xip,yjm,ycell,yjp,\n & xxlow,yylow,dxx,dyy,mxx,myy,zz,intmethod)\nc===========================================================================\n\nc###########################################################################\nc topointegral integrates a surface over a rectangular region\nc that is the intersection with a Cartesion grid (of topography data)\nc the surface integrated is defined by a piecewise bilinear through the\nc nodes of the Cartesian grid.\n\nc The rectangular intersection has coords:\nc xim <= x <= xip, yjm <= y <= yjp, with center (x,y) = (xcell, ycell)\nc\nc The Cartesian grid has coords:\nc xxlow <= x <= xxhi, yylow <= y <= yyhi, with grid cell size dxx by dyy\nc and mxx by myy cells.\nc\nc written by David L. George\nc Seattle, WA 7/16/08\nc###########################################################################\n\n use geoclaw_module\n\n implicit double precision (a-h,o-z)\n double precision zz(1:mxx,1:myy)\n\nc # initialize:\n theintegral = 0.d0\n\n xxhi=xxlow+(mxx-1)*dxx\n yyhi=yylow+(myy-1)*dyy\n\nc========TEST FOR SMALL ROUNDING ERROR==========\n if ((xim-xxlow).lt.0.d0.or.(xip-xxhi).gt.0.d0) then\n xim=dmax1(xxlow,xim)\n xip=dmin1(xxhi,xip)\n endif\n\n if ((yjm-yylow).lt.0.d0.or.(yjp-yyhi).gt.0.d0) then\n yjm=dmax1(yylow,yjm)\n yjp=dmin1(yyhi,yjp)\n endif\nc=========================================\n\n dx=xip-xim\n dy=yjp-yjm\n\nc=============INTEGRATE PIECEWISE BILINEAR OVER RECTANGULAR REGION====\n if (intmethod.eq.1) then !use bilinear method\n\nc don't waste time looping through the entire grid\nc just find indices that include the rectangular region\n\n djjstart=(yjm-yylow)/dyy\n jjstart=idint(djjstart)+1\n\n diistart=(xim-xxlow)/dxx\n iistart=idint(diistart)+1\n\n diiend=(xip-xxlow)/dxx\n iiend=ceiling(diiend) + 1\n\n djjend=(yjp-yylow)/dyy\n jjend=ceiling(djjend)+1\n\n iistart=max(iistart,1)\n jjstart=max(jjstart,1)\n iiend=min(mxx,iiend)\n jjend=min(myy,jjend)\n\n\n do jj=jjstart,jjend-1\n y1=yylow + (jj-1.d0)*dyy\n y2=yylow + (jj)*dyy\nc # the array zz is indexed from north to south: jjz is the actual index\nc # of interest in the array zz\n jjz1= myy-jj+1\n jjz2= jjz1-1\n\n do ii=iistart,iiend-1\n x1=xxlow + (ii-1.d0)*dxx\n x2=xxlow + (ii)*dxx\n\n z11 = zz(ii,jjz1)\n z12 = zz(ii,jjz2)\n z21 = zz(ii+1,jjz1)\n z22 = zz(ii+1,jjz2)\n\n if (icoordsys.eq.1) then !cartesian rectangle\n theintegral = theintegral + bilinearintegral(\n & xim,xip,yjm,yjp,\n & x1,x2,y1,y2,\n & dxx,dyy,\n & z11,z12,z21,z22)\n elseif (icoordsys.eq.2) then !integrate on surface of sphere\n theintegral = theintegral + bilinearintegral_s(\n & xim,xip,yjm,yjp,\n & x1,x2,y1,y2,\n & dxx,dyy,\n & z11,z12,z21,z22,\n & Rearth,pi)\n else\n write(*,*) 'TOPOINTEGRAL: icoordsys error'\n endif\n enddo\n enddo\n\n else\n write(*,*) 'TOPOINTEGRAL: only intmethod = 1,2 is supported'\n endif\n\n topointegral= theintegral\n return\n end function\n", "meta": {"hexsha": "e65d5f034868002fff0e8f7bf927f8c515d9d1fd", "size": 4007, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "geoclaw/2d/lib/topointegral_geo.f", "max_stars_repo_name": "geoflows/geoclaw-4.x", "max_stars_repo_head_hexsha": "c8879d25405017b38392aa3b1ea422ff3e3604ea", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2016-11-13T03:11:51.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-07T18:59:48.000Z", "max_issues_repo_path": "geoclaw/2d/lib/topointegral_geo.f", "max_issues_repo_name": "che-wenchao/D-Claw", "max_issues_repo_head_hexsha": "8ab5d971c9a7a7130e03a447a4b8642e292f4e88", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2020-01-14T18:00:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T14:25:24.000Z", "max_forks_repo_path": "geoclaw/2d/lib/topointegral_geo.f", "max_forks_repo_name": "che-wenchao/D-Claw", "max_forks_repo_head_hexsha": "8ab5d971c9a7a7130e03a447a4b8642e292f4e88", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-01-14T17:15:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-03T17:28:44.000Z", "avg_line_length": 34.2478632479, "max_line_length": 82, "alphanum_fraction": 0.4464686798, "num_tokens": 1051, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070084811306, "lm_q2_score": 0.7431680086124812, "lm_q1q2_score": 0.6762137795154619}} {"text": "! =================================================\n! Initialize global variables.\n! =================================================\n\nsubroutine init_global_vars()\n\n use physical_def\n use coordinates\n implicit none\n\n real*8 :: L\n integer*4 :: I, J\n\n ! Init coordinates\n dx = Lx/Nx\n dy = Ly/Ny\n do I = 1, Nx\n do J = 1, Ny\n x(I,J) = (I - 0.5)*dx\n y(I,J) = (J - 0.5)*dy\n end do\n end do\n\n ! Non-dimensionalize scalars\n L = .5*(Lx + Ly)\n dx_ = dx/L\n dy_ = dy/L\n x_ = x/L\n y_ = y/L\n Lx_ = Lx/L\n Ly_ = Ly/L\n qw_ = qw*L/lbd/(Tn - Ts)\n qe_ = qe*L/lbd/(Tn - Ts)\n\nend subroutine", "meta": {"hexsha": "bad4fba13034f8d2d097bd843c94ad5508e84abc", "size": 674, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "initvars.f90", "max_stars_repo_name": "aviruch/unsteady-conduction-2d", "max_stars_repo_head_hexsha": "d154b0128bcd5be072cfcd75c66bb9ba268e0e68", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "initvars.f90", "max_issues_repo_name": "aviruch/unsteady-conduction-2d", "max_issues_repo_head_hexsha": "d154b0128bcd5be072cfcd75c66bb9ba268e0e68", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "initvars.f90", "max_forks_repo_name": "aviruch/unsteady-conduction-2d", "max_forks_repo_head_hexsha": "d154b0128bcd5be072cfcd75c66bb9ba268e0e68", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-27T15:02:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-27T15:02:18.000Z", "avg_line_length": 19.2571428571, "max_line_length": 51, "alphanum_fraction": 0.4065281899, "num_tokens": 224, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.882427872638409, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6761988739943996}} {"text": "FUNCTION AIRTOVAC(lam)\n \n !convert wavelengths from air to vac\n !see Morton (1991 Ap.J. Suppl. 77, 119)\n !this code was adapted from the IDL routine airtovac.pro\n\n USE sps_vars; USE sps_utils, ONLY : locate\n IMPLICIT NONE\n\n INTEGER :: vv,nn\n REAL(SP), DIMENSION(:), INTENT(in) :: lam\n REAL(SP), DIMENSION(SIZE(lam)) :: airtovac,fact,sigma2\n\n !------------------------------------------------------!\n\n nn = SIZE(lam)\n\n !Convert to wavenumber squared\n sigma2(1:nn) = (1E4/lam(1:nn) )**2. \n\n !Compute conversion factor\n fact(1:nn) = 1.D0 + 6.4328D-5 + 2.94981D-2/(146.d0 - sigma2(1:nn)) + &\n 2.5540D-4/( 41.d0 - sigma2(1:nn))\n \n !no conversion for wavelengths <2000A\n IF (lam(1).LT.2000.D0) THEN\n vv = MIN(MAX(locate(lam(1:nn),2000.D0),1),nn)\n fact(1:vv) = 1.0\n ENDIF\n\n !Convert wavelength\n airtovac(1:nn) = lam(1:nn)*fact(1:nn)\n\nEND FUNCTION AIRTOVAC\n\n!---------------------------------------------------------------!\n!---------------------------------------------------------------!\n!---------------------------------------------------------------!\n\nFUNCTION VACTOAIR(lam)\n\n !convert wavelengths from air to vac\n !see Morton (1991 Ap.J. Suppl. 77, 119)\n !this code was adapted from the IDL routine vactoair.pro\n\n USE sps_vars; USE sps_utils, ONLY : locate\n IMPLICIT NONE\n\n INTEGER :: vv,nn\n REAL(SP), DIMENSION(:), INTENT(in) :: lam\n REAL(SP), DIMENSION(SIZE(lam)) :: vactoair,fact\n\n !------------------------------------------------------!\n\n nn = SIZE(lam)\n\n fact(1:nn) = 1.D0 + 2.735182D-4 + 131.4182/lam(1:nn)**2 + &\n 2.76249D8/lam(1:nn)**4\n\n !no conversion for wavelengths <2000A\n IF (lam(1).LT.2000.D0) THEN\n vv = MIN(MAX(locate(lam(1:nn),2000.D0),1),nn)\n fact(1:vv) = 1.0\n ENDIF\n\n !Convert wavelengths\n vactoair(1:nn) = lam(1:nn)/fact(1:nn)\n\nEND FUNCTION VACTOAIR\n", "meta": {"hexsha": "0b5a43ff02dfd7df1d80517c21bd811da3b69f77", "size": 1837, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/vacairconv.f90", "max_stars_repo_name": "christopherlovell/fsps", "max_stars_repo_head_hexsha": "1c09a47d7b0fb15a7f245ee3e9b2a7c54122ffdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 55, "max_stars_repo_stars_event_min_datetime": "2015-04-17T18:36:36.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-15T01:47:28.000Z", "max_issues_repo_path": "src/vacairconv.f90", "max_issues_repo_name": "christopherlovell/fsps", "max_issues_repo_head_hexsha": "1c09a47d7b0fb15a7f245ee3e9b2a7c54122ffdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 27, "max_issues_repo_issues_event_min_datetime": "2015-11-04T03:19:44.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-15T22:03:19.000Z", "max_forks_repo_path": "src/vacairconv.f90", "max_forks_repo_name": "christopherlovell/fsps", "max_forks_repo_head_hexsha": "1c09a47d7b0fb15a7f245ee3e9b2a7c54122ffdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 43, "max_forks_repo_forks_event_min_datetime": "2015-04-29T09:24:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T19:31:46.000Z", "avg_line_length": 26.2428571429, "max_line_length": 72, "alphanum_fraction": 0.5323897659, "num_tokens": 633, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278726384089, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6761988739943995}} {"text": "!file: glasso_p.f90\nsubroutine glasso_p(Omega, Sigma, & !output\n Sigma_pre, lambda, & !inputs :: data and parameter\n ths_lasso, max_iter_lasso, &\n p, dim_Sigma, dim_dep) !inputs :: dimensions\n implicit none\n \n !inputs :: dimensions\n integer, intent(in) :: p, dim_Sigma, dim_dep\n \n !inputs :: data and parameter\n real(8), dimension(dim_Sigma, dim_Sigma), intent(in) :: Sigma_pre, lambda\n \n !inputs :: opt. parameters\n integer, intent(in) :: max_iter_lasso\n real(8), intent(in) :: ths_lasso\n \n!f2py integer optional, intent(in) :: max_iter = 100\n!f2py real(8) optional, intent(in) :: ths = 0.001\n\n !in/outputs\n real(8), dimension(dim_Sigma, dim_Sigma) :: Omega, Sigma\n \n!f2py intent(inplace) Omega\n!f2py intent(inplace) Sigma\n\n ! local variables\n integer :: q\n integer, dimension(dim_Sigma-1) :: notp\n integer, dimension(dim_dep) :: depp\n real(8), dimension(dim_dep) :: beta\n real(8), dimension(dim_Sigma, dim_Sigma) :: IOmega_notp\n \n notp = pack((/(q,q=1,dim_Sigma)/), (/(q,q=1,dim_Sigma)/)/=p)\n depp = pack((/(q,q=1,dim_Sigma)/), &\n (lambda(p,:)>=0) .and. ((/(q,q=1,dim_Sigma)/)/=p))\n \n IOmega_notp = 0\n IOmega_notp(notp,notp) = &\n Sigma(notp,notp) - matmul(reshape(Sigma(notp,p), (/dim_Sigma-1,1/)), &\n reshape(Sigma(p,notp), (/1,dim_Sigma-1/)) / Sigma(p,p))\n \n Sigma(p,p) = Sigma_pre(p,p) + lambda(p,p)\n\n beta = Omega(p,depp) \n call lasso(beta, Sigma(p,p) * IOmega_notp(depp,depp), - Sigma_pre(p,depp), &\n lambda(p,depp), ths_lasso, max_iter_lasso, dim_dep)\n\n Omega(p,:) = 0\n Omega(:,p) = 0\n Omega(p,depp) = beta\n Omega(depp,p) = beta\n\n Sigma(notp,p) = matmul(IOmega_notp(notp, depp), - beta * Sigma(p,p))\n Sigma(p,notp) = Sigma(notp, p)\n\n Omega(p,p) = (1 - dot_product(Omega(p, depp), Sigma(p, depp))) / Sigma(p,p)\n\n Sigma(notp,notp) = IOmega_notp(notp,notp) &\n + matmul(reshape(Sigma(notp,p), (/dim_Sigma-1,1/)), &\n reshape(Sigma(p,notp), (/1,dim_Sigma-1/)) / Sigma(p,p)) \n\nend subroutine glasso_p", "meta": {"hexsha": "cb113def0fff65d72925d75fa5182e8bc7c646ea", "size": 2214, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ldfa/optimize/glasso_p.f90", "max_stars_repo_name": "HeejongBong/ldfa", "max_stars_repo_head_hexsha": "0fef004995a39fb6d88bfaf81390b052efa38144", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-28T19:57:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T19:57:44.000Z", "max_issues_repo_path": "ldfa/optimize/glasso_p.f90", "max_issues_repo_name": "HeejongBong/ldfa", "max_issues_repo_head_hexsha": "0fef004995a39fb6d88bfaf81390b052efa38144", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ldfa/optimize/glasso_p.f90", "max_forks_repo_name": "HeejongBong/ldfa", "max_forks_repo_head_hexsha": "0fef004995a39fb6d88bfaf81390b052efa38144", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-14T23:15:57.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-14T23:15:57.000Z", "avg_line_length": 35.1428571429, "max_line_length": 89, "alphanum_fraction": 0.5695573622, "num_tokens": 713, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278633625322, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.676198866886354}} {"text": "C$Procedure DLATDR ( Derivative of latitudinal w.r.t. rectangular )\n \n SUBROUTINE DLATDR ( X, Y, Z, JACOBI )\n IMPLICIT NONE\n \nC$ Abstract\nC\nC This routine computes the Jacobian of the transformation from\nC rectangular to latitudinal coordinates.\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 COORDINATES\nC DERIVATIVES\nC MATRIX\nC\nC$ Declarations\n \n DOUBLE PRECISION X\n DOUBLE PRECISION Y\n DOUBLE PRECISION Z\n DOUBLE PRECISION JACOBI ( 3, 3 )\n \nC$ Brief_I/O\nC\nC Variable I/O Description\nC -------- --- --------------------------------------------------\nC X I X-coordinate of point.\nC Y I Y-coordinate of point.\nC Z I Z-coordinate of point.\nC JACOBI O Matrix of partial derivatives.\nC\nC$ Detailed_Input\nC\nC X,\nC Y,\nC Z are the rectangular coordinates of the point at\nC which the Jacobian of the map from rectangular\nC to latitudinal coordinates is desired.\nC\nC$ Detailed_Output\nC\nC JACOBI is the matrix of partial derivatives of the conversion\nC between rectangular and latitudinal coordinates. It\nC has the form\nC\nC .- -.\nC | dr/dx dr/dy dr/dz |\nC | dlong/dx dlong/dy dlong/dz |\nC | dlat/dx dlat/dy dlat/dz |\nC `- -'\nC\nC evaluated at the input values of X, Y, and Z.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC 1) If the input point is on the z-axis ( X and Y = 0 ), the\nC Jacobian is undefined. The error SPICE(POINTONZAXIS)\nC will be signaled.\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC When performing vector calculations with velocities it is\nC usually most convenient to work in rectangular coordinates.\nC However, once the vector manipulations have been performed\nC it is often desirable to convert the rectangular representations\nC into latitudinal coordinates to gain insights about phenomena\nC in this coordinate frame.\nC\nC To transform rectangular velocities to derivatives of coordinates\nC in a latitudinal system, one uses the Jacobian of the\nC transformation between the two systems.\nC\nC Given a state in rectangular coordinates\nC\nC ( x, y, z, dx, dy, dz )\nC\nC the corresponding latitudinal coordinate derivatives are given by\nC the matrix equation:\nC\nC t | t\nC (dr, dlong, dlat) = JACOBI| * (dx, dy, dz)\nC |(x,y,z)\nC\nC This routine computes the matrix \nC\nC |\nC JACOBI|\nC |(x, y, z)\nC\nC$ Examples\nC\nC Suppose one is given the bodyfixed rectangular state of an object\nC ( x(t), y(t), z(t), dx(t), dy(t), dz(t) ) as a function of time t.\nC\nC To find the derivatives of the coordinates of the object in\nC bodyfixed latitudinal coordinates, one simply multiplies the\nC Jacobian of the transformation from rectangular to latitudinal\nC (evaluated at x(t), y(t), z(t) ) by the rectangular velocity\nC vector of the object at time t.\nC\nC In code this looks like:\nC\nC C\nC C Load the rectangular velocity vector vector RECV.\nC C\nC RECV(1) = DX_DT ( T )\nC RECV(3) = DY_DT ( T )\nC RECV(2) = DZ_DT ( T )\nC\nC C\nC C Determine the Jacobian of the transformation from\nC C rectangular to latitudinal at the rectangular \nC C coordinates at time T.\nC C\nC CALL DLATDR ( X(T), Y(T), Z(T), JACOBI )\nC\nC C\nC C Multiply the Jacobian on the right by the rectangular\nC C velocity to obtain the latitudinal coordinate \nC C derivatives LATV.\nC C\nC CALL MXV ( JACOBI, RECV, LATV )\nC\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC W.L. Taber (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.0, 16-JUL-2001 (WLT)\nC\nC-&\n \nC$ Index_Entries\nC\nC Jacobian of latitudinal w.r.t. rectangular coordinates\nC\nC-&\n \nC$ Revisions\nC\nC None.\nC\nC-&\n \n \nC\nC SPICELIB functions\nC\n LOGICAL RETURN\n \nC\nC Local variables\nC\n DOUBLE PRECISION RECTAN ( 3 )\n DOUBLE PRECISION R\n DOUBLE PRECISION LONG\n DOUBLE PRECISION LAT\n DOUBLE PRECISION INJACB ( 3, 3 ) \n \n \nC\nC Standard SPICE error handling.\nC\n IF ( RETURN () ) THEN\n RETURN\n ELSE\n CALL CHKIN ( 'DLATDR' )\n END IF\n \nC\nC There is a singularity of the Jacobian for points on the z-axis.\nC\n IF ( ( X .EQ. 0 ) .AND. ( Y .EQ. 0 ) ) THEN\n\n CALL SETMSG ( 'The Jacobian of the transformation from ' //\n . 'rectangular to latitudinal coordinates ' //\n . 'is not defined for points on the z-axis.' )\n CALL SIGERR ( 'SPICE(POINTONZAXIS)' )\n CALL CHKOUT ( 'DLATDR' )\n RETURN\n\n END IF\n \nC\nC We will get the Jacobian of the transformation from rectangular \nC to latitudinal coordinates by implicit differentiation.\nC\nC First move the X,Y and Z coordinates into a vector.\nC\n CALL VPACK ( X, Y, Z, RECTAN )\n \nC\nC Convert from rectangular to latitudinal coordinates.\nC\n CALL RECLAT ( RECTAN, R, LONG, LAT )\n \nC\nC Get the Jacobian of the transformation from latitudinal to \nC rectangular coordinates at R, LONG, LAT.\nC\n CALL DRDLAT ( R, LONG, LAT, INJACB )\n \nC\nC Now invert INJACB to get the Jacobian of the transformation from \nC rectangular to latitudinal coordinates.\nC\n CALL INVORT ( INJACB, JACOBI )\n \n CALL CHKOUT ( 'DLATDR' )\n RETURN\n END\n", "meta": {"hexsha": "acc65ea8987e6ce9b3df7a0bc74716f1c06c9ca4", "size": 7375, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/dlatdr.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/dlatdr.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/dlatdr.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.3653846154, "max_line_length": 72, "alphanum_fraction": 0.6085423729, "num_tokens": 2017, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026505426831, "lm_q2_score": 0.737158174177441, "lm_q1q2_score": 0.6761971470421715}} {"text": "subroutine dgemv(trans, m, n, alpha, A, lda, x, incx, beta, y, incy)\n! Simplified DGEMV that does\n! y := A*x\n! We follow the BLAS signature for compatibility. For more,\n! see http://netlib.org/blas/.\n implicit none\n ! input/output\n character*1, intent(in) :: trans\n integer, intent(in) :: m, n, lda, incx, incy\n double precision, intent(in) :: alpha, beta\n double precision, intent(in) :: A(m, n)\n double precision, intent(in) :: x(n)\n double precision, intent(inout) :: y(m)\n ! local\n integer :: i, j\n ! do y = A*x\n do i = 1, n\n do j = 1, n\n y(i) = y(i) + A(i, j) * x(j)\n end do\n end do\nend subroutine dgemv\n", "meta": {"hexsha": "7f54f0f13ce8ecee15c72a6611d3948b85813b40", "size": 667, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/matrix_vector_rm.f90", "max_stars_repo_name": "me701/hpc", "max_stars_repo_head_hexsha": "12dd6143184d798c5527855698bcb2b97e393242", "max_stars_repo_licenses": ["MIT"], "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/matrix_vector_rm.f90", "max_issues_repo_name": "me701/hpc", "max_issues_repo_head_hexsha": "12dd6143184d798c5527855698bcb2b97e393242", "max_issues_repo_licenses": ["MIT"], "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/matrix_vector_rm.f90", "max_forks_repo_name": "me701/hpc", "max_forks_repo_head_hexsha": "12dd6143184d798c5527855698bcb2b97e393242", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-05T18:11:05.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-05T18:11:05.000Z", "avg_line_length": 29.0, "max_line_length": 68, "alphanum_fraction": 0.5832083958, "num_tokens": 230, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026618464795, "lm_q2_score": 0.7371581626286833, "lm_q1q2_score": 0.6761971447811511}} {"text": "! Check that parameters are correct intercepted.\r\n! Constants with comma separations are commonly\r\n! used, for instance Pi = 3._dp\r\nsubroutine foo_compound_int(x)\r\n implicit none\r\n integer, parameter :: ii = selected_int_kind(9)\r\n integer(ii), intent(inout) :: x\r\n dimension x(3)\r\n integer(ii), parameter :: three = 3_ii\r\n integer(ii), parameter :: two = 2_ii\r\n integer(ii), parameter :: six = three * 1_ii * two\r\n\r\n x(1) = x(1) + x(2) + x(3) * six\r\n return\r\nend subroutine\r\n", "meta": {"hexsha": "8dbe74de4c1fafb66ca5ed08fbeebc4b36c4926b", "size": 484, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "libs/numpy/f2py/tests/src/parameter/constant_compound.f90", "max_stars_repo_name": "rocketbot-cl/recognition", "max_stars_repo_head_hexsha": "cca8a87070ccaca3a26e37345c36ab1bf836e258", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 353, "max_stars_repo_stars_event_min_datetime": "2020-12-10T10:47:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:08:29.000Z", "max_issues_repo_path": "libs/numpy/f2py/tests/src/parameter/constant_compound.f90", "max_issues_repo_name": "rocketbot-cl/recognition", "max_issues_repo_head_hexsha": "cca8a87070ccaca3a26e37345c36ab1bf836e258", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 80, "max_issues_repo_issues_event_min_datetime": "2020-12-10T09:54:22.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T22:08:45.000Z", "max_forks_repo_path": "libs/numpy/f2py/tests/src/parameter/constant_compound.f90", "max_forks_repo_name": "rocketbot-cl/recognition", "max_forks_repo_head_hexsha": "cca8a87070ccaca3a26e37345c36ab1bf836e258", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 63, "max_forks_repo_forks_event_min_datetime": "2020-12-10T17:10:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-28T16:27:07.000Z", "avg_line_length": 30.25, "max_line_length": 53, "alphanum_fraction": 0.6673553719, "num_tokens": 143, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. Yes\n2. Yes", "lm_q1_score": 0.7371581626286834, "lm_q2_score": 0.9173026584553408, "lm_q1q2_score": 0.6761971422813456}} {"text": "! Copyright (C) 2017-2019 Matthieu Ancellin\n! See LICENSE file at \nMODULE INITIALIZE_GREEN_WAVE\n\n USE CONSTANTS\n\n IMPLICIT NONE\n\n PUBLIC :: EXP_E1\n PUBLIC :: INITIALIZE_TABULATED_INTEGRALS\n PUBLIC :: FF\n\nCONTAINS\n\n!------------------------------------------------------------------------------\n\n FUNCTION EXP_E1(ZZ)\n ! Estimation of exp(z)\u00b7E1(z) where E1(z) = \u222b_z^\u221e exp(-t)/t dt\n ! See p.367 of G. Delhommeau thesis (referenced as [Del]).\n\n ! This routine is only used in the following subroutine to compute the tabulated integrals\n\n ! The computation is done is single precision.\n\n COMPLEX(KIND=PRE), INTENT(IN) :: ZZ\n COMPLEX(KIND=PRE) :: EXP_E1\n COMPLEX(KIND=KIND(1e0)) :: G, Y, Z\n\n Z = CMPLX(ZZ, KIND=KIND(1e0))\n IF (REAL(Z) < -16.0) THEN ! Case 1 p. 368 in [Del]\n Y = 1./Z\n G = Y*(1.+Y*(-1.+Y*(2.+Y*(-6.+Y*(24.+Y*(-120.))))))\n ELSE IF (ABS(AIMAG(Z)) > 10.0) THEN ! Case 3 p. 368 in [Del]\n G = 0.711093/(Z+0.415775)+0.278518/(Z+2.29428)+0.010389/(Z+6.2900)\n ELSE IF (REAL(Z) > -0.5) THEN ! Case 2 p. 368 in [Del]\n G = -(LOG(Z)*(.1E+01+Z*(0.23721365E+00+Z*(0.206543E-01+Z*(0.763297E-03+ &\n Z*0.97087007E-05))))+0.5772156649E+00*(0.99999207E+00+ &\n Z*(-0.149545886E+01+Z*(0.41806426E-01+Z*(-0.3000591E-01+ &\n Z*(0.19387339E-02+Z*(-0.51801555E-03)))))))/(0.1E+01+ &\n Z*(-0.76273617E+00+Z*(0.28388363E+00+Z*(-0.66786033E-01+Z*(0.12982719E-01 &\n +Z*(-0.8700861E-03+Z*0.2989204E-03))))))\n ELSE ! Case 4 p. 369 in [Del]\n IF (AIMAG(Z) < 0) THEN\n G = ((((((( (1.000000, 1.3935496E-06)*Z+ (15.82958, -20.14222)) &\n *Z+ (-70.52863, -227.9511))*Z+ (-985.4221, -226.6272))*Z &\n + (-1202.318, 1580.907))*Z+ (953.2441, 1342.447))*Z &\n + (417.3716, -196.6665))*Z+ (-9.881266, -24.24952))/ &\n (((((((( (1.000000, 0.0000000E+00)*Z+ (16.83184, -20.14481))*Z &\n + (-55.66969, -248.1167))*Z+ (-1068.640, -434.4707))*Z &\n + (-2082.250, 1522.471))*Z+ (383.3455, 2730.378))*Z &\n + (1216.791, 351.7189))*Z+ (115.3926, -161.2647))*Z &\n + (-3.777369, -4.510900))\n ELSE\n G = ((((((( (1.000000, -1.3935496E-06)*Z+ (15.82958, 20.14222)) &\n *Z+ (-70.52863, 227.9511))*Z+ (-985.4221, 226.6272))*Z &\n + (-1202.318, -1580.907))*Z+ (953.2441, -1342.447))*Z &\n + (417.3716, 196.6665))*Z+ (-9.881266, 24.24952))/ &\n (((((((( (1.000000, 0.0000000E+00)*Z+ (16.83184, 20.14481))*Z &\n + (-55.66969, 248.1167))*Z+ (-1068.640, 434.4707))*Z &\n + (-2082.250, -1522.471))*Z+ (383.3455, -2730.378))*Z &\n + (1216.791, -351.7189))*Z+ (115.3926, 161.2647))*Z &\n + (-3.777369, 4.510900))\n END IF\n END IF\n EXP_E1 = CMPLX(G, KIND=PRE)\n\n END FUNCTION EXP_E1\n\n!------------------------------------------------------------------------------\n\n SUBROUTINE INITIALIZE_TABULATED_INTEGRALS(NB_POINTS_X, NB_POINTS_Z, NB_INTEGRATION_POINTS, X, Z, TABULATION)\n ! Compute the tabulated integrals for the wave part of the Green function.\n ! These tables are independant of the mesh and of the frequency.\n ! They are only initialised once at the beginning of the program.\n\n ! References:\n ! [1] Delhommeau, Am\u00e9lioration des codes de calcul de diffraction-radiation, 2\u00e8mes journ\u00e9es de l'hydrodynamique, 1989\n ! [2] Babarit and Delhommeau, Theoretical and numerical aspects of the open source BEM solver NEMOH, EWTEC 2015\n ! [3] Xie et al., Comparison of existing methods for the calculation of the infinite water depth free-surface Green\n ! function for the wave-structure interaction problem, Applied Ocean Research, 2018\n\n ! Inputs\n INTEGER, INTENT(IN) :: NB_POINTS_X != 328\n INTEGER, INTENT(IN) :: NB_POINTS_Z != 46\n INTEGER, INTENT(IN) :: NB_INTEGRATION_POINTS\n\n ! Outputs\n REAL(KIND=PRE), DIMENSION(NB_POINTS_X), INTENT(OUT) :: X\n REAL(KIND=PRE), DIMENSION(NB_POINTS_Z), INTENT(OUT) :: Z\n REAL(KIND=PRE), DIMENSION(NB_POINTS_X, NB_POINTS_Z, 2, 2), INTENT(OUT) :: TABULATION\n\n ! Local variables\n INTEGER :: I, J, K\n REAL(KIND=PRE) :: THETA(NB_INTEGRATION_POINTS), CQT(NB_INTEGRATION_POINTS)\n REAL(KIND=PRE) :: COSTHETA\n COMPLEX(KIND=PRE) :: JZETA, ZETA, EXPZETA\n\n ! Initialize Z axis\n DO J = 1, NB_POINTS_Z\n Z(J) = -AMIN1(10**(J/5.0-6), 10**(J/8.0-4.5), 16.)\n END DO\n\n ! Initialize X axis\n X(1) = 0.0\n DO I = 2, NB_POINTS_X\n IF (I < 40) THEN\n X(I) = AMIN1(10**((I-1.0)/5-6), 4.0/3.0 + ABS(I-32)/3.0)\n ELSE\n X(I) = 4.0/3.0 + ABS(I-32)/3.0\n ENDIF\n END DO\n\n ! Initialize THETA and CQT for the integration between -pi/2 and pi/2 with the Simpson rule.\n DO K = 1, NB_INTEGRATION_POINTS\n THETA(K) = -PI/2 + (K-1.0)/(NB_INTEGRATION_POINTS-1.0)*PI ! The 1.0 are here on purpose to force the recasting of K and NB_INTEGRATION_POINTS as floats.\n IF ((K == 1) .OR. (K == NB_INTEGRATION_POINTS)) THEN\n CQT(K) = PI/(3*(NB_INTEGRATION_POINTS-1))\n ELSEIF (MOD(K,2)==0) THEN\n CQT(K) = 4.0/(3*(NB_INTEGRATION_POINTS-1))*PI\n ELSE\n CQT(K) = 2.0/(3*(NB_INTEGRATION_POINTS-1))*PI\n ENDIF\n ENDDO\n\n ! Compute tabulation\n TABULATION(:, :, :, :) = 0.0\n DO I = 1, NB_POINTS_X\n DO J = 1, NB_POINTS_Z\n DO K = 1, NB_INTEGRATION_POINTS\n COSTHETA = COS(THETA(K))\n ZETA = CMPLX(Z(J), X(I)*COSTHETA, KIND=PRE)\n IF (REAL(ZETA) <= -30.0) THEN\n EXPZETA = (0.0, 0.0)\n ELSE\n EXPZETA = EXP(ZETA)\n ENDIF\n IF (AIMAG(ZETA) < 0) THEN\n JZETA = EXP_E1(ZETA) - II*PI*EXPZETA\n ELSE\n JZETA = EXP_E1(ZETA) + II*PI*EXPZETA\n END IF\n TABULATION(I, J, 1, 1) = TABULATION(I, J, 1, 1) + CQT(K)*COSTHETA*AIMAG(JZETA - 1.0/ZETA) ! D_1 in [1, 2, 3]\n TABULATION(I, J, 2, 1) = TABULATION(I, J, 2, 1) + CQT(K)*COSTHETA*AIMAG(EXPZETA) ! D_2 in [1, 2, 3]\n#ifdef XIE_CORRECTION\n TABULATION(I, J, 1, 2) = TABULATION(I, J, 1, 2) + CQT(K)*REAL(JZETA) ! Z_1 in [3]\n#else\n TABULATION(I, J, 1, 2) = TABULATION(I, J, 1, 2) + CQT(K)*REAL(JZETA - 1.0/ZETA) ! Z_1 in [1, 2]\n#endif\n TABULATION(I, J, 2, 2) = TABULATION(I, J, 2, 2) + CQT(K)*REAL(EXPZETA) ! Z_2 in [1, 2, 3]\n END DO\n END DO\n END DO\n\n RETURN\n\n END SUBROUTINE INITIALIZE_TABULATED_INTEGRALS\n\n!-------------------------------------------------------------------------------!\n\n FUNCTION FF(XTT, AK, AM)\n ! A function that will be Prony-decomposed for the finite-depth Green function.\n ! See the method \"find_best_exponential_decomposition\" in green_functions/delhommeau.py.\n\n ! Input\n REAL(KIND=PRE), INTENT(IN) :: XTT, AK, AM\n\n ! Local variables\n REAL(KIND=PRE) :: COEF, TOL, A, B, C, D, E, F, FF\n\n COEF = (AM+AK)**2/(AM**2-AK**2+AK)\n\n TOL = MAX(0.1, 0.1*AM)\n IF (ABS(XTT-AM) > TOL) THEN\n FF = (XTT+AK)*EXP(XTT)/(XTT*SINH(XTT)-AK*COSH(XTT)) - COEF/(XTT-AM) - 2\n ELSE\n A = AM - TOL\n B = AM\n C = AM + TOL\n D = (A+AK)*EXP(A)/(A*SINH(A)-AK*COSH(A)) - COEF/(A-AM) - 2\n E = COEF/(AM+AK)*(AM+AK+1) - (COEF/(AM+AK))**2*AM - 2\n F = (C+AK)*EXP(C)/(C*SINH(C)-AK*COSH(C)) - COEF/(C-AM) - 2\n FF = D*(XTT-B)*(XTT-C)/((A-B)*(A-C)) + &\n E*(XTT-C)*(XTT-A)/((B-C)*(B-A)) + &\n F*(XTT-A)*(XTT-B)/((C-A)*(C-B))\n ENDIF\n \n RETURN\n END FUNCTION FF\n\n!----------------------------------------------------------------\n\nEND MODULE INITIALIZE_GREEN_WAVE\n", "meta": {"hexsha": "e75b6add7d01477ca1872c9f8068e5554f3f0c8b", "size": 8070, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/Initialize_Green_wave.f90", "max_stars_repo_name": "mancellin/libDelhommeau", "max_stars_repo_head_hexsha": "73d3040d60c866da538b83bb8790456caff47a92", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-04T16:01:25.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-04T16:01:25.000Z", "max_issues_repo_path": "src/Initialize_Green_wave.f90", "max_issues_repo_name": "mancellin/libDelhommeau", "max_issues_repo_head_hexsha": "73d3040d60c866da538b83bb8790456caff47a92", "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/Initialize_Green_wave.f90", "max_forks_repo_name": "mancellin/libDelhommeau", "max_forks_repo_head_hexsha": "73d3040d60c866da538b83bb8790456caff47a92", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-09-04T20:19:49.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-17T19:58:41.000Z", "avg_line_length": 41.8134715026, "max_line_length": 159, "alphanum_fraction": 0.5121437423, "num_tokens": 2941, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072386, "lm_q2_score": 0.7371581568543043, "lm_q1q2_score": 0.676197141150835}} {"text": "C++--------------------------------------------------------------------\nC COORD_SCHMIDT\nC Quick program to obtain the approximative (very approximative...)\nC coordinates from a schmidt plate when the centre is known.\nC--------------------------------------------------------------------\n\tPROGRAM COORD_SCHMIDT\n\tPRINT *,' X AND Y IN MM FROM THE BOTTOM LEFT HAND CORNER ?'\n\tPRINT *,' (REALS)'\n\tREAD(5,*) X,Y\n\tPRINT *,' R.A. AND DEC. OF THE CENTER OF THE PLATE ?'\n\tPRINT *,' (FORMAT: H,MN,S,D,MN,S ...INTEGERS)'\n\tREAD(5,*) IRAC0,IRAC1,IRAC2,IDEC0,IDEC1,IDEC2\n\tRAC0=FLOAT(IRAC0)\n\tRAC1=FLOAT(IRAC1)\n\tRAC2=FLOAT(IRAC2)\n\tDEC0=FLOAT(IDEC0)\n\tDEC1=FLOAT(IDEC1)\n\tDEC2=FLOAT(IDEC2)\n \nC Conversion into arcseconds\n\tRAC00=((RAC0*60.+RAC1)*60.+RAC2)*15.\n\tDEC00=(DEC0*60.+DEC1)*60.+DEC2\n\tWORK=DEC00/3600.\n\tSCALEX=67.1/COSD(WORK)\n\tIF(SCALEX.LT.0.)SCALEX=-1.*SCALEX\n\tPRINT *,' SCALE IN X:',SCALEX\n\tSCALEY=67.1\n\tDELTAX=(X-172.5)*SCALEX\n\tDELTAY=(Y-172.5)*SCALEY\n\tPRINT *,' OFFSET IN X AND Y:',DELTAX,DELTAY\n\tPRINT *,'(IN ARCSECONDS)'\nC\n\tRA00=RAC00-DELTAX\n\tDE00=DEC00+DELTAY\n\tPRINT *,' VALUES OF RA00 AND DE00:',RA00,DE00\nC Output: conversion to hours, mn, sec\n\tRA00=RA00/15.\n\tWORK1=RA00/3600.\n\tIRA0=IFIX(WORK1)\n\tWORK2=(WORK1-FLOAT(IFIX(WORK1)))*60.\n\tIRA1=IFIX(WORK2)\n\tRA2=(WORK2-FLOAT(IFIX(WORK2)))*60.\nC Output: conversion to degrees ' \"\n\tWORK1=DE00/3600.\n\tIF(DE00.LT.0.)WORK1=-1.*WORK1\n\tIDE0=IFIX(WORK1)\n\tIF(DE00.LT.0.)IDE0=-1*IDE0\n\tWORK2=(WORK1-FLOAT(IFIX(WORK1)))*60.\n\tIDE1=IFIX(WORK2)\n\tDE2=(WORK2-FLOAT(IFIX(WORK2)))*60.\nC\n\tPRINT 100,IRA0,IRA1,RA2,IDE0,IDE1,DE2\n100\tFORMAT(' RIGHT ASCENSION :',4X,I3,' H ',2X,I3,' MN ',\n 1\tF5.2,' S',/,\n 1\t' DECLINATION :',8X,I3,' DEG',X,I3,' MN ',\n 1\tF5.2,' S')\n\tSTOP\n\tEND\n \n", "meta": {"hexsha": "659cf0c4bfc6b5e2e5ad0da179823a9d13b2a161", "size": 1729, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "source/maths/coord_schmidt.for", "max_stars_repo_name": "jlprieur/shell_galaxies", "max_stars_repo_head_hexsha": "1dde87ef33b3c33b3a892e9ad0d642ae02ac6d9e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source/maths/coord_schmidt.for", "max_issues_repo_name": "jlprieur/shell_galaxies", "max_issues_repo_head_hexsha": "1dde87ef33b3c33b3a892e9ad0d642ae02ac6d9e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/maths/coord_schmidt.for", "max_forks_repo_name": "jlprieur/shell_galaxies", "max_forks_repo_head_hexsha": "1dde87ef33b3c33b3a892e9ad0d642ae02ac6d9e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.8166666667, "max_line_length": 71, "alphanum_fraction": 0.6124927704, "num_tokens": 706, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026505426831, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6761971364484656}} {"text": "c$Header: /data/petsun4/data1/src_solaris/librms/RCS/determ12.f,v 1.1 2007/06/19 22:34:50 avi Exp $\nc$Log: determ12.f,v $\nc Revision 1.1 2007/06/19 22:34:50 avi\nc Initial revision\nc\n real*4 function determ12(a,det)\n real*4 a(4,4)\n\n det=+a(1,1)*(a(2,2)*a(3,3)-a(2,3)*a(3,2))\n & -a(1,2)*(a(2,1)*a(3,3)-a(2,3)*a(3,1))\n & +a(1,3)*(a(2,1)*a(3,2)-a(2,2)*a(3,1))\n\n determ12 = det\n return\n end\n", "meta": {"hexsha": "310f4c6470ad1235474cab117b37d732a71e27ab", "size": 433, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "4dfp/librms/determ12.f", "max_stars_repo_name": "llevitis/PUP", "max_stars_repo_head_hexsha": "850cf50dc29672db9d0d6781f7fe467f77f94204", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2015-08-17T16:20:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-31T08:59:07.000Z", "max_issues_repo_path": "4dfp/librms/determ12.f", "max_issues_repo_name": "llevitis/PUP", "max_issues_repo_head_hexsha": "850cf50dc29672db9d0d6781f7fe467f77f94204", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-08-02T18:47:38.000Z", "max_issues_repo_issues_event_max_datetime": "2019-08-13T21:24:00.000Z", "max_forks_repo_path": "4dfp/librms/determ12.f", "max_forks_repo_name": "llevitis/PUP", "max_forks_repo_head_hexsha": "850cf50dc29672db9d0d6781f7fe467f77f94204", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2016-09-01T18:52:16.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-31T08:59:14.000Z", "avg_line_length": 27.0625, "max_line_length": 99, "alphanum_fraction": 0.5427251732, "num_tokens": 223, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9173026573249611, "lm_q2_score": 0.7371581568543044, "lm_q1q2_score": 0.6761971361512239}} {"text": " REAL FUNCTION INTG8(F,A,B,DX)\t!Integrate function F.\n EXTERNAL F\t!Some function of one parameter.\n REAL A,B\t\t!Bounds.\n REAL DX\t\t!Step.\n INTEGER N\t!A counter.\n INTG8 = F(A) + F(B)\t!Get the ends exactly.\n N = (B - A)/DX\t\t!Truncates. Ignore A + N*DX = B chances.\n DO I = 1,N\t\t!Step along the interior.\n INTG8 = INTG8 + F(A + I*DX)\t!Evaluate the function.\n END DO\t\t\t!On to the next.\n INTG8 = INTG8/(N + 2)*(B - A)\t!Average value times interval width.\n END FUNCTION INTG8\t!This is not a good calculation!\n\n FUNCTION TRIAL(X)\t\t!Some user-written function.\n REAL X\n TRIAL = 1 + X\t\t!This will do.\n END FUNCTION TRIAL\t!Not the name of a library function.\n\n PROGRAM POKE\n INTRINSIC SIN\t!Thus, not an (undeclared) ordinary variable.\n EXTERNAL TRIAL\t!Likewise, but also, not an intrinsic function.\n REAL INTG8\t!Don't look for the result in an integer place.\n WRITE (6,*) \"Result=\",INTG8(SIN, 0.0,8*ATAN(1.0),0.01)\n WRITE (6,*) \"Linear=\",INTG8(TRIAL,0.0,1.0, 0.01)\n END\n", "meta": {"hexsha": "dadd38ceff5554c623e43d9aaf48a9945e530d63", "size": 1104, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Call-a-function/Fortran/call-a-function-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/Call-a-function/Fortran/call-a-function-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/Call-a-function/Fortran/call-a-function-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": 42.4615384615, "max_line_length": 74, "alphanum_fraction": 0.589673913, "num_tokens": 364, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026482819236, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6761971347819282}} {"text": "! -*- mode: F90; mode: font-lock; column-number-mode: true -*-\n! ------------------------------------------------------------------------------\n! $Id$\n! ------------------------------------------------------------------------------\n! Module functions\n! ------------------------------------------------------------------------------\n! Code area 9: general\n! ------------------------------------------------------------------------------\n\n!!****h* Conquest/functions *\n!! NAME\n!! functions\n!! PURPOSE\n!! Collects mathematical functions in one module\n!! AUTHOR\n!! D.R.Bowler\n!! CREATION DATE\n!! 2016/02/09\n!! MODIFICATION HISTORY\n!! SOURCE\n!!\nmodule functions\n\n implicit none\n\n ! -------------------------------------------------------\n ! RCS ident string for object file id\n ! -------------------------------------------------------\n character(len=80), private :: RCSid = \"$Id$\"\n !!***\n\ncontains\n\n ! -----------------------------------------------------------\n ! Function erfc\n ! -----------------------------------------------------------\n\n !!****f* DiagModle/erfc *\n !!\n !! NAME\n !! erfc\n !! USAGE\n !! erfc(x)\n !! PURPOSE\n !! Calculated the complementary error function to rounding-error\n !! based on erfc() in ewald_module\n !! accuracy\n !! INPUTS\n !! real(double) :: x, argument of complementary error function\n !! AUTHOR\n !! Iain Chapman/Lianeng Tong\n !! CREATION DATE\n !! 2001 sometime/2010/07/26\n !! MODIFICATION HISTORY\n !! 2016/02/09 08:14 dave\n !! Moved to functions module from DiagModule\n !! SOURCE\n !!\n real(double) function erfc(x)\n\n use datatypes\n use numbers, only: RD_ERR, one, zero, half, two\n use GenComms, only: cq_abort\n\n implicit none\n \n real(double), parameter :: erfc_delta = 1.0e-12_double, &\n erfc_gln = 0.5723649429247447e0_double, &\n erfc_fpmax = 1.e30_double\n integer, parameter:: erfc_iterations = 10000\n\n real(double), intent(in) :: x\n\n ! local variables\n real(double) :: y, y2\n real(double) :: ap, sum, del\n real(double) :: an, b, c, d, h\n integer :: i\n\n if(x < zero) then\n y = -x\n else\n y = x\n end if\n ! This expects y^2\n y2 = y*y\n if(y get_elemental_data, get_array_data\n!\n Generic :: get_median => Statistical_Median\n Generic :: get_mean => Statistical_Mean\n Generic :: get_variance => Statistical_Variance\n Generic :: get_std_dev => Statistical_Std_Dev\n Generic :: get_skewness => Statistical_Skewness\n Generic :: get_kurtosis => Statistical_Kurtosis\n!\n End Type Statistical_Data\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n Interface\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n Module Function Statistical_Median ( this ) Result ( median )\n Implicit None\n Class ( Statistical_Data ) ,Intent(inout) :: this\n Real(KIND=rkind) :: median\n End Function Statistical_Median\n!\n Module Function Statistical_Mean ( this ) Result ( mean )\n Implicit None\n Class ( Statistical_Data ) ,Intent(inout) :: this\n Real(KIND=rkind) :: mean\n End Function Statistical_Mean\n!\n Module Function Statistical_Variance ( this, mean ) Result ( variance )\n Implicit None\n Class ( Statistical_Data ), Intent(inout) :: this\n Real(KIND=rkind), Optional, Intent(in) :: mean\n Real(KIND=rkind) :: variance\n End Function Statistical_Variance\n!\n Module Function Statistical_Std_Dev ( this, mean ) Result ( std_dev )\n Implicit None\n Class ( Statistical_Data ), Intent(inout) :: this\n Real(KIND=rkind), Optional, Intent(in) :: mean\n Real(KIND=rkind) :: std_dev\n End Function Statistical_Std_Dev\n!\n Module Function Statistical_Skewness ( this, mean, std_dev ) Result ( skewness )\n Implicit None\n Class ( Statistical_Data ), Intent(inout) :: this\n Real(KIND=rkind), Optional, Intent(in) :: mean\n Real(KIND=rkind), Optional, Intent(in) :: std_dev\n Real(KIND=rkind) :: skewness\n End Function Statistical_Skewness\n!\n Module Function Statistical_Kurtosis ( this, mean, std_dev ) Result ( kurtosis )\n Implicit None\n Class ( Statistical_Data ), Intent(inout) :: this\n Real(KIND=rkind), Optional, Intent(in) :: mean\n Real(KIND=rkind), Optional, Intent(in) :: std_dev\n Real(KIND=rkind) :: kurtosis\n End Function Statistical_Kurtosis\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n Module Subroutine set_data ( this, array )\n Implicit None\n Class ( Statistical_Data ), Intent(inout) :: this\n Real(KIND=rkind), Dimension(:), Intent(in) :: array\n End Subroutine set_data\n!\n Module Subroutine clear_data ( this )\n Implicit None\n Class ( Statistical_Data ), Intent(inout) :: this\n End Subroutine clear_data\n!\n Module Function get_elemental_data ( this, d ) Result ( data )\n Implicit None\n Class ( Statistical_Data ), Intent(inout) :: this\n Integer(KIND=ikind), Intent(in) :: d\n Real (KIND=rkind) :: data\n End Function get_elemental_data\n!\n Module Function get_array_data ( this ) Result ( data )\n Implicit None\n Class ( Statistical_Data ), Intent(inout) :: this\n Real(KIND=rkind), Allocatable, Dimension(:) :: data\n End Function get_array_data\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n End Interface\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\nEnd Module statistical_data_mod\n", "meta": {"hexsha": "223a91eafd5b7a8569e3f5a69a197db8cf22e45e", "size": 4501, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/modules/statistical_data_mod.f90", "max_stars_repo_name": "rouson/statistics", "max_stars_repo_head_hexsha": "f73be960f2575940379b70df0a2ff62a84953ff6", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/modules/statistical_data_mod.f90", "max_issues_repo_name": "rouson/statistics", "max_issues_repo_head_hexsha": "f73be960f2575940379b70df0a2ff62a84953ff6", "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/modules/statistical_data_mod.f90", "max_forks_repo_name": "rouson/statistics", "max_forks_repo_head_hexsha": "f73be960f2575940379b70df0a2ff62a84953ff6", "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": 36.593495935, "max_line_length": 157, "alphanum_fraction": 0.5754276827, "num_tokens": 1017, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6761652413773883}} {"text": "!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 1998 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Spherepack *\n! * *\n! * A Package of Fortran Subroutines and Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams and Paul Swarztrauber *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\n!\n! This file contains code and documentation for subroutines\n! shpei and shpe.\n!\nsubmodule(scalar_projection_routines) scalar_projection_regular_grid\n\ncontains\n\n ! Purpose:\n !\n ! the n**2 projection with complement, odd/even\n ! factorization and zero truncation on an\n ! equally spaced grid as defined in the JCP paper\n ! \"Generalized discrete spherical harmonic transforms\"\n ! by Paul N. Swarztrauber and William F. Spotz\n ! It is equivalent to a harmonic analysis followed\n ! by a synthesis except faster and requires less memory.\n !\n ! subroutine shpe(nlat, nlon, isym, mtrunc, x, y, idxy, &\n ! wshp, lwshp, iwshp, liwshp, work, lwork, ierror)\n !\n ! shpe projects the array x onto the set of functions represented\n ! by a discrete set of spherical harmonics.\n !\n ! input parameters\n !\n ! nlat the number of colatitudes on the full sphere including the\n ! poles. for example, nlat = 37 for a five degree grid.\n ! nlat determines the grid increment in colatitude as\n ! pi/(nlat-1). if nlat is odd the equator is located at\n ! grid point i=(nlat + 1)/2. if nlat is even the equator is\n ! located half way between points i=nlat/2 and i=nlat/2+1.\n ! nlat must be at least 3.\n !\n ! nlon the number of distinct londitude points. nlon determines\n ! the grid increment in longitude as 2*pi/nlon. for example\n ! nlon = 72 for a five degree grid. nlon must be greater\n ! than or equal to 4. the efficiency of the computation is\n ! improved when nlon is a product of small prime numbers.\n ! nlon must beat least 4.\n !\n ! isym currently not used.\n !\n ! mtrunc the highest longitudinal wave number retained in the\n ! projection. It must be less than or equal to\n ! the minimum of nlat-1 and nlon/2. The first wave\n ! number is zero. For example, if wave numbers 0 and\n ! 1 are desired then mtrunc = 1.\n\n ! zero.\n !\n ! x a two dimensional array that contains the the nlat\n ! by nlon array x(i, j) defined at the colatitude point\n ! theta(i) = (i-1)*pi/(nlat-1) and longitude point phi(j) =\n ! (j-1)*2*pi/nlon.\n !\n ! idxy the first dimension of the arrays x and y as they\n ! appear in the program that calls shpe. It must be\n ! at least nlat.\n !\n ! wshp a single precision array that must be saved for\n ! repeated use by subroutine shpe.\n !\n ! lwshp the dimension of the array wshp as it appears in the\n ! program that calls shpei. It must be at least\n ! 2*(nlat + 1)**2+nlon+log2(nlon)\n !\n ! iwshp an integer array that must be saved for repeated\n ! use by subroutine shpe.\n !\n !\n ! liwshp the dimension of the array iwshp as it appears in the\n ! program that calls shpei. It must be at least\n ! 4*(nlat + 1).\n !\n ! work a single precision work array that does\n ! not have to be saved.\n !\n ! lwork the dimension of the array work as it appears in the\n ! program that calls shpe. It must be at least\n ! max(nlat*nlon, 4*(nlat + 1)).\n !\n ! **************************************************************\n !\n ! output parameters\n !\n ! y an nlat by nlon single precision array that contains\n ! the projection of x onto the set of functions that\n ! can be represented by the discrete set of spherical\n ! harmonics. The arrays x(i, j) and y(i, j) are located\n ! at colatitude point theta(i) = (i-1)*pi/(nlat-1) and\n ! longitude point phi(j) = (j-1)*2*pi/nlon.\n !\n ! ierror = 0 no errors\n ! = 1 error in the specification of nlat\n ! = 2 error in the specification of nlon\n ! = 3 error in the specification of isym\n ! = 4 error in the specification of mtrunc\n ! = 5 error in the specification of lwshp\n ! = 6 error in the specification of liwshp\n ! = 7 error in the specification of lwork\n !\n module subroutine shpe(nlat, nlon, isym, mtrunc, x, y, idxy, &\n wshp, lwshp, iwshp, liwshp, work, lwork, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n integer(ip), intent(in) :: isym\n integer(ip), intent(in) :: mtrunc\n real(wp), intent(in) :: x(idxy, nlon)\n real(wp), intent(out) :: y(idxy, nlon)\n integer(ip), intent(in) :: idxy\n real(wp), intent(in) :: wshp(lwshp)\n integer(ip), intent(in) :: lwshp\n integer(ip), intent(in) :: iwshp(liwshp)\n integer(ip), intent(in) :: liwshp\n real(wp), intent(out) :: work(lwork)\n integer(ip), intent(in) :: lwork\n integer(ip), intent(out) :: ierror\n\n ! Local variables\n integer(ip) :: iw1\n integer(ip) :: iw2\n integer(ip) :: iw3\n integer(ip) :: iw4\n integer(ip) :: jw1\n integer(ip) :: jw2\n integer(ip) :: jw3\n integer(ip) :: jw4\n integer(ip) :: log2n\n integer(ip) :: lw1\n integer(ip) :: mmax\n integer(ip) :: mwrk\n integer(ip) :: nloc1\n integer(ip) :: nloc2\n integer(ip) :: nte\n type(SpherepackUtility) :: util\n\n ! Check calling arguments\n ierror = 1\n if (nlat < 3) return\n ierror = 2\n if (nlon < 4) return\n ierror = 3\n if (isym < 0 .or. isym > 2) return\n ierror = 4\n mmax = min(nlat-1, nlon/2)\n if (mtrunc < 0 .or. mtrunc > mmax) return\n ierror = 5\n log2n = int(log(real(nlon, kind=wp))/log(TWO), kind=ip)\n lw1 = 2*(nlat + 1)**2\n if (lwshp 2) then\n ierror = 3\n else if (mtrunc < 0 .or. mtrunc > mmax) then\n ierror = 4\n else if (lwshp < lw1+nlon+log2n) then\n ierror = 5\n else if (liwshp < 4*(nlat + 1)) then\n ierror = 6\n else if (lwork < mlwk) then\n ierror = 7\n else\n ierror = 0\n end if\n\n ! Check error flag\n if (ierror /= 0) return\n\n call util%hfft%initialize(nlon, wshp(lw1+1))\n\n ! Set workspace index pointers\n nte = (nlat + 1)/2\n nloc1 = 2*nte*nte\n nloc2 = nlat+1\n lw1 = 2*(nlat + 1)**2\n iw1 = 1\n iw2 = iw1+nloc1\n iw3 = iw2+nloc1\n iw4 = iw3+nloc1\n jw1 = 1\n jw2 = jw1+nloc2\n jw3 = jw2+nloc2\n jw4 = jw3+nloc2\n kw1 = 1\n kw2 = kw1+nte\n kw3 = kw2+nte\n kw4 = kw3+nte\n kw5 = kw4+nte+1\n kw6 = kw5+nte\n kw7 = kw6+nte\n kw8 = kw7+nte\n kw9 = kw8+nte\n kw10 = kw9+nloc2+nloc2\n kw11 = kw10+nloc2\n kw12 = kw11+nloc1\n kw13 = kw12+nloc1\n\n call shpei_lower_utility_routine(nlat, nlon, isym, mtrunc, nte, ierror, wshp(iw1), wshp(iw2), &\n wshp(iw3), wshp(iw4), iwshp(jw1), iwshp(jw2), iwshp(jw3), &\n iwshp(jw4), work(kw1), work(kw2), work(kw3), work(kw4), work(kw5), &\n work(kw6), work(kw7), work(kw8), work(kw9), work(kw10), work(kw11), &\n work(kw12), work(kw11), work(kw12), work(kw13))\n\n end subroutine shpei\n\n subroutine shpei_lower_utility_routine(nlat, nlon, isym, mtrunc, idp, ierror, &\n pe, po, ze, zo, ipse, jzse, ipso, jzso, &\n cp, work, wx, s, e, thet, xx, z, a, b, we, ped, wo, pod, u)\n\n real(wp) :: dfn\n integer(ip) :: i\n integer(ip) :: idp\n integer(ip) :: ierror\n integer(ip) :: info\n integer(ip) :: iip\n integer(ip) :: ipse\n integer(ip) :: ipso\n integer(ip) :: isym\n integer(ip) :: it\n integer(ip) :: j\n integer(ip) :: js\n integer(ip) :: jzse\n integer(ip) :: jzso\n integer(ip) :: k\n integer(ip) :: lock\n integer(ip) :: m\n integer(ip) :: modn\n integer(ip) :: mp1\n integer(ip) :: mrank\n integer(ip) :: ms2\n integer(ip) :: mtrunc\n integer(ip) :: mxtr\n integer(ip) :: n\n integer(ip) :: nem\n integer(ip) :: nlat\n integer(ip) :: nlon\n integer(ip) :: nom\n integer(ip) :: nrank\n integer(ip) :: ns2\n integer(ip) :: nshe\n integer(ip) :: nsho\n integer(ip) :: nte\n integer(ip) :: nto\n real(wp) :: pe\n real(wp) :: po\n real(wp) :: toe\n real(wp) :: tusl\n real(wp) :: ze\n real(wp) :: zo\n real(wp) :: summation, dtheta, v(1, 1), a1, b1, c1\n real(wp) :: cp(idp), work(idp), wx(idp), s(idp+1), &\n e(idp), thet(idp), xx(idp), z(idp), u(idp, idp), &\n we(idp, idp, 2), ped(idp, idp, 2), a(4*idp), b(2*idp), &\n wo(idp, idp, 2), pod(idp, idp, 2)\n\n dimension pe(idp, idp, 2), po(idp, idp, 2), ze(idp, idp, 2), &\n zo(idp, idp, 2), &\n ipse(idp, 2), jzse(idp, 2), ipso(idp, 2), jzso(idp, 2), &\n nshe(2), nsho(2)\n\n type(SpherepackUtility) :: util\n\n ns2 = nlat/2\n modn = nlat-ns2-ns2\n nte = (nlat + 1)/2\n nto = nlat-nte\n tusl = ZERO\n toe = ZERO\n\n ! Compute grid distribution\n dtheta = pi/(nlat-1)\n do i=1, nte\n thet(i) = real(i-1, kind=wp)*dtheta\n end do\n\n ! Compute weight matrices for even functions\n do mp1=1, 2\n m = mp1-1\n mrank = nlat-m-m\n nem = (mrank+1)/2\n do j=1, nem\n n = 2*j+m-2\n call util%compute_fourier_coefficients(m, n, cp)\n do i=1, nte\n call util%compute_legendre_polys_from_fourier_coeff(m, n, thet(i), cp, ped(i, j, mp1))\n end do\n if (m>0) ped(1, j, mp1) = ZERO\n end do\n\n call singular_value_decomposition(ped(m+1, 1, mp1), idp, nem, nem, s, e, u, &\n idp, v(1, 1), idp, work, 10, info)\n\n do j=1, nem\n s(j) = ONE/(s(j)**2)\n end do\n\n ! Compute weight matrix as u s sup -2 u transpose\n do j=1, nte\n do i=1, nte\n we(i, j, mp1) = ZERO\n end do\n end do\n do i=1, nem\n do j=1, nem\n summation = ZERO\n do k=1, nem\n summation = summation+s(k)*u(i, k)*u(j, k)\n end do\n we(i+m, j+m, mp1) = summation\n end do\n end do\n end do\n\n we(1, 1, 2) = ONE\n\n ! Compute n**2 basis (even functions)\n do n=1, nlat+nlat-2\n dfn = n\n a(n) = sqrt(dfn*(dfn+ONE))\n end do\n do n=1, nlat-1\n dfn = n\n b(n) = sqrt((dfn+dfn+3.0)/(dfn+dfn-ONE))\n end do\n !\n mxtr = min(nlat-1, nlon/2, mtrunc)\n iip = 2\n do mp1=1, mxtr+1\n m = mp1-1\n iip = 3-iip\n ms2 = mp1/2\n nrank = ms2+ms2\n mrank = nlat-nrank\n nem = (mrank+1)/2\n\n ! Compute associated legendre functions\n if (m <= 1) then\n do j=1, nem\n n = 2*j+m-2\n call util%compute_fourier_coefficients(m, n, cp)\n do i=1, nte\n call util%compute_legendre_polys_from_fourier_coeff(m, n, thet(i), cp, ped(i, j+ms2, iip))\n end do\n if (m > 0) ped(1, j+ms2, iip) = ZERO\n end do\n else\n do j=1, nem\n n = 2*j+m-2\n if (m > 1 .and. n > mxtr) then\n do i=1, nte\n u(i, j+ms2) = ped(i, j+ms2, iip)\n end do\n else\n a1 = b(n-1)*a(n+m-3)/a(n+m-1)\n b1 = a(n-m+1)/a(n+m-1)\n if (n-m <= 1) then\n do i=1, nte\n u(i, j+ms2) = a1*ped(i, j+ms2-1, iip) &\n - b1*ped(i, j+ms2, iip)\n end do\n else\n c1 = b(n-1)*a(n-m-1)/a(n+m-1)\n do i=1, nte\n u(i, j+ms2) = a1*ped(i, j+ms2-1, iip) &\n - b1*ped(i, j+ms2, iip) + c1*u(i, j+ms2-1)\n end do\n end if\n end if\n end do\n do j=1, nem\n do i=1, nte\n ped(i, j+ms2, iip) = u(i, j+ms2)\n end do\n end do\n end if\n\n if (.not.(ms2 <= 0. .or. nte <= ms2)) then\n\n ! initialize array with random numbers\n call random_seed()\n call random_number(xx(1:nte))\n it = 0\n even_iteration: do\n do i=1, nte\n z(i) = ZERO\n wx(i) = ZERO\n do j=1, nte\n wx(i) = wx(i)+we(i, j, iip)*xx(j)\n end do\n end do\n\n do j=1, nte\n if (j == ms2) cycle\n call accumulate_inner_products(nte, wx, ped(1, j, iip), z)\n end do\n\n do i=1, nte\n xx(i) = xx(i)-z(i)\n end do\n\n call compute_normal_regular_grid(nte, xx, idp, we(1, 1, iip))\n\n it = it+1\n if (it > 2) exit even_iteration\n end do even_iteration\n do i=1, nte\n ped(i, ms2, iip) = xx(i)\n end do\n end if\n end do\n\n ! Reorder if mtrunc is less than nlat-1\n ! case of even functions\n if (modn == 0) then\n nshe(1) = (nlat-mtrunc-1)/2\n nshe(2) = (nlat-mtrunc-2)/2\n else\n nshe(1) = (nlat-mtrunc)/2\n nshe(2) = (nlat-mtrunc-1)/2\n end if\n\n do mp1=1, 2\n do j=1, nte\n js = j+nshe(mp1)\n if (js>nte) js = js-nte\n do i=1, nte\n u(i, js) = ped(i, j, mp1)\n end do\n end do\n do j=1, nte\n do i=1, nte\n ped(i, j, mp1) = u(i, j)\n end do\n end do\n end do\n\n call truncate(0, nte, idp, ped(1, 1, 1), nte, ipse(1, 1))\n call truncate(0, nte, idp, ped(1, 1, 2), nte, ipse(1, 2))\n\n ! Compute the analysis matrices\n do iip=1, 2\n do i=1, nte\n lock = 0\n do j=1, nte\n summation = ZERO\n do k=1, nte\n summation = summation+ped(k, i, iip)*we(k, j, iip)\n end do\n pe(i, j, iip) = ped(i, j, iip)\n ze(j, i, iip) = summation\n if (abs(summation)>MACHINE_EPSILON .and. lock == 0) then\n lock = 1\n jzse(i, iip) = j\n end if\n end do\n end do\n end do\n\n ! Compute weight matrices for odd functions\n do mp1=1, 2\n m = mp1-1\n mrank = nlat-m-m\n nem = (mrank+1)/2\n nom = mrank-nem\n do j=1, nom\n n = 2*j+m-1\n call util%compute_fourier_coefficients(m, n, cp)\n do i=1, nte\n call util%compute_legendre_polys_from_fourier_coeff(m, n, thet(i), cp, pod(i, j, mp1))\n end do\n if (modn == 1) pod(nte, j, mp1) = ZERO\n end do\n call singular_value_decomposition(pod(m+1, 1, mp1), idp, nom, nom, s, e, u, &\n idp, v(1, 1), idp, work, 10, info)\n\n do j=1, nom\n s(j) = ONE/(s(j)**2)\n end do\n\n ! Compute weight matrix as u s sup -2 u transpose\n do j=1, nte\n do i=1, nte\n wo(i, j, mp1) = ZERO\n end do\n end do\n do i=1, nom\n do j=1, nom\n summation = ZERO\n do k=1, nom\n summation = summation+s(k)*u(i, k)*u(j, k)\n end do\n wo(i+m, j+m, mp1) = summation\n end do\n end do\n end do\n\n wo(1, 1, 2) = ONE\n if (modn == 1) then\n wo(nte, nte, 1) = ONE\n wo(nte, nte, 2) = ONE\n end if\n\n ! Compute n**2 basis (odd functions)\n iip = 2\n do mp1=1, mxtr+1\n iip = 3-iip\n m = mp1-1\n ms2 = mp1/2\n nrank = ms2+ms2\n mrank = nlat-nrank\n nem = (mrank+1)/2\n nom = mrank-nem\n\n ! Compute associated legendre functions\n if (m <= 1) then\n do j=1, nom\n n = 2*j+m-1\n call util%compute_fourier_coefficients(m, n, cp)\n do i=1, nte\n call util%compute_legendre_polys_from_fourier_coeff(m, n, thet(i), cp, pod(i, j+ms2, iip))\n end do\n if (modn == 1) pod(nte, j+ms2, iip) = ZERO\n if (m>0) pod(1, j+ms2, iip) = ZERO\n end do\n else\n do j=1, nom\n n = 2*j+m-1\n if (m > 1 .and. n > mxtr) then\n do i=1, nte\n u(i, j+ms2) = pod(i, j+ms2, iip)\n end do\n else\n a1 = b(n-1)*a(n+m-3)/a(n+m-1)\n b1 = a(n-m+1)/a(n+m-1)\n if (n-m <= 1) then\n do i=1, nte\n u(i, j+ms2) = a1*pod(i, j+ms2-1, iip) &\n - b1*pod(i, j+ms2, iip)\n end do\n else\n c1 = b(n-1)*a(n-m-1)/a(n+m-1)\n do i=1, nte\n u(i, j+ms2) = a1*pod(i, j+ms2-1, iip) &\n - b1*pod(i, j+ms2, iip) + c1*u(i, j+ms2-1)\n end do\n end if\n end if\n if (modn == 1) u(nte, j+ms2) = ZERO\n end do\n do j=1, nom\n do i=1, nte\n pod(i, j+ms2, iip) = u(i, j+ms2)\n end do\n end do\n end if\n\n if (.not.(ms2 <= 0. .or. nto <= ms2)) then\n\n ! initialize array with random numbers\n call random_number(xx(1:nte))\n\n if (modn == 1) xx(nte) = ZERO\n\n it = 0\n odd_iteration: do\n do i=1, nte\n z(i) = ZERO\n wx(i) = ZERO\n do j=1, nto\n wx(i) = wx(i)+wo(i, j, iip)*xx(j)\n end do\n end do\n\n do j=1, nto\n if (j == ms2) cycle\n call accumulate_inner_products(nte, wx, pod(1, j, iip), z(1))\n end do\n\n do i=1, nte\n xx(i) = xx(i)-z(i)\n end do\n\n call compute_normal_regular_grid(nte, xx, idp, wo(1, 1, iip))\n\n it = it+1\n if (it > 2) exit odd_iteration\n end do odd_iteration\n\n do i=1, nte\n pod(i, ms2, iip) = xx(i)\n end do\n\n if (modn == 1) pod(nte, ms2, iip) = ZERO\n end if\n end do\n\n ! Reorder if mtrunc is less than nlat-1\n ! case of odd functions\n if (modn == 0) then\n nsho(1) = (nlat-mtrunc)/2\n nsho(2) = (nlat-mtrunc-1)/2\n else\n nsho(1) = (nlat-mtrunc-1)/2\n nsho(2) = (nlat-mtrunc-2)/2\n end if\n\n do mp1=1, 2\n do j=1, nto\n js = j+nsho(mp1)\n if (js>nto) js = js-nto\n do i=1, nte\n u(i, js) = pod(i, j, mp1)\n end do\n end do\n do j=1, nto\n do i=1, nte\n pod(i, j, mp1) = u(i, j)\n end do\n end do\n end do\n\n call truncate(0, nte, idp, pod(1, 1, 1), nto, ipso(1, 1))\n call truncate(0, nte, idp, pod(1, 1, 2), nto, ipso(1, 2))\n\n ! Compute the analysis matrices (odd functions)\n do iip=1, 2\n do i=1, nto\n lock = 0\n do j=1, nto\n summation = ZERO\n do k=1, nte\n summation = summation+pod(k, i, iip)*wo(k, j, iip)\n end do\n po(i, j, iip) = pod(i, j, iip)\n zo(j, i, iip) = summation\n if (abs(summation)>MACHINE_EPSILON .and. lock == 0) then\n lock = 1\n jzso(i, iip) = j\n end if\n end do\n end do\n end do\n\n end subroutine shpei_lower_utility_routine\n\n subroutine shpe_lower_utility_routine(nlat, nlon, isym, mtrunc, sx, sy, idxy, ierror, &\n idp, pe, po, ze, zo, ipse, jzse, ipso, jzso, xe, xo, ye, yo)\n\n integer(ip) :: i\n integer(ip) :: idp\n integer(ip) :: idxy\n integer(ip) :: ierror\n integer(ip) :: iip\n integer(ip) :: ipse\n integer(ip) :: ipso\n integer(ip) :: isym\n integer(ip) :: j\n integer(ip) :: js\n integer(ip) :: jzse\n integer(ip) :: jzso\n integer(ip) :: m\n integer(ip) :: modn\n integer(ip) :: mp1\n integer(ip) :: mpm\n integer(ip) :: mrank\n integer(ip) :: ms2\n integer(ip) :: mtrunc\n integer(ip) :: mxtr\n integer(ip) :: nec\n integer(ip) :: nem\n integer(ip) :: nlat\n integer(ip) :: nlon\n integer(ip) :: noc\n integer(ip) :: nom\n integer(ip) :: nrank\n integer(ip) :: ns2\n integer(ip) :: nshe\n integer(ip) :: nsho\n integer(ip) :: nte\n integer(ip) :: nto\n real(wp) :: pe\n real(wp) :: po\n real(wp) :: sx\n real(wp) :: sy\n real(wp) :: xe\n real(wp) :: xo\n real(wp) :: ye\n real(wp) :: yo\n real(wp) :: ze\n real(wp) :: zo\n\n dimension sx(idxy, nlon), sy(idxy, nlon), nshe(2), nsho(2), &\n pe(idp, idp, 2), po(idp, idp, 2), ze(idp, idp, 2), zo(idp, idp, 2), &\n ipse(idp, 2), jzse(idp, 2), ipso(idp, 2), jzso(idp, 2), &\n xe(idp, 2), xo(idp, 2), ye(idp, 2), yo(idp, 2)\n\n ns2 = nlat/2\n modn = nlat-ns2-ns2\n nte = (nlat + 1)/2\n nto = nlat-nte\n\n if (modn == 0) then\n nshe(1) = (nlat-mtrunc-1)/2\n nshe(2) = (nlat-mtrunc-2)/2\n nsho(1) = (nlat-mtrunc)/2\n nsho(2) = (nlat-mtrunc-1)/2\n else\n nshe(1) = (nlat-mtrunc)/2\n nshe(2) = (nlat-mtrunc-1)/2\n nsho(1) = (nlat-mtrunc-1)/2\n nsho(2) = (nlat-mtrunc-2)/2\n end if\n mxtr = min(nlat-1, nlon/2, mtrunc)\n iip = 2\n\n main_loop: do mp1=1, mxtr+1\n iip = 3-iip\n if (mxtr == nlat-1 .and. mp1 <= 2) then\n do i=1, nlat\n sy(i, mp1) = sx(i, mp1)\n end do\n if (mp1 == 2) then\n sy(1, 2) = ZERO\n sy(nlat, 2) = ZERO\n end if\n if (3 <= nlon) then\n sy(1, 3) = ZERO\n sy(nlat, 3) = ZERO\n do i=2, nlat-1\n sy(i, 3) = sx(i, 3)\n end do\n end if\n cycle main_loop\n end if\n\n m = mp1-1\n mpm = max(1, m+m)\n ms2 = mp1/2\n mrank = min(nlat-m, nlat-ms2-ms2)\n nrank = nlat-mrank\n nem = (mrank+1)/2-nshe(iip)\n nom = mrank-(mrank+1)/2-nsho(iip)\n nec = nte-nem\n noc = nto-nom\n\n do i=1, nte\n xe(i, 1) = HALF * (sx(i, mpm)+sx(nlat+1-i, mpm))\n xo(i, 1) = HALF * (sx(i, mpm)-sx(nlat+1-i, mpm))\n end do\n\n if (mpm 0) then\n do i=1, lc\n sum1 = ZERO\n sum2 = ZERO\n do j=js(i), mc\n sum1 = sum1 + b(j, i)*x(j, 1)\n sum2 = sum2 + b(j, i)*x(j, 2)\n end do\n do k=is(i), lr\n y(k, 1) = y(k, 1)+sum1*a(k, i)\n y(k, 2) = y(k, 2)+sum2*a(k, i)\n end do\n end do\n end if\n\n end subroutine matrix_multiplication\n\n subroutine compute_normal_regular_grid(n, x, id, q)\n\n ! Dummy arguments\n integer(ip), intent(in) :: n\n real(wp), intent(inout) :: x(n)\n integer(ip), intent(in) :: id\n real(wp), intent(in) :: q(id, n)\n\n ! Local variables\n integer(ip) :: i, j\n real(wp) :: summation, sqs\n\n ! Normalize x\n sqs = ZERO\n do i=1, n\n summation = ZERO\n do j=1, n\n summation = summation + q(i, j)*x(j)\n end do\n sqs = sqs+summation*x(i)\n end do\n\n x = x/sqrt(sqs)\n\n end subroutine compute_normal_regular_grid\n\n ! Purpose:\n !\n ! Performs the singular value decomposition of a real rectangular matrix.\n !\n ! This routine reduces an m by n matrix a to diagonal form by orthogonal\n ! transformations u and v. The diagonal elements s(i) are the singular\n ! values of a. The columns of u are the corresponding left singular\n ! vectors, and the columns of v the right singular vectors.\n !\n ! The form of the singular value decomposition is then\n !\n ! a(mxn) = u(mxm) * s(mxn) * transpose(v(nxn))\n !\n ! Reference:\n !\n ! Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart, \n ! LINPACK User's Guide, \n ! SIAM, 1979, \n ! ISBN13: 978-0-898711-72-1, \n ! LC: QA214.L56.\n !\n ! Parameters:\n !\n ! Input/output, real(wp) a(lda, n). on input, the m by n\n ! matrix whose singular value decomposition is to be computed.\n ! on output, the matrix has been destroyed. depending on the user's\n ! requests, the matrix may contain other useful information.\n !\n ! input, integer(ip) lda, the leading dimension of the array a.\n ! lda must be at least n.\n !\n ! input, integer(ip) m, the number of rows of the matrix.\n !\n ! input, integer(ip) n, the number of columns of the matrix a.\n !\n ! output, real(wp) s(mm), where mm = max(m+1, n). the first\n ! min(m, n) entries of s contain the singular values of a arranged in\n ! descending order of magnitude.\n !\n ! output, real(wp) e(mm), where mm = max(m+1, n). ordinarily\n ! contains zeros. however see the discussion of info for exceptions.\n !\n ! output, real(wp) u(ldu, k). if joba = 1 then k = m;\n ! if 2 <= joba, then k = min(m, n). u contains the m by m matrix of\n ! left singular vectors. u is not referenced if joba = 0. if m <= n\n ! or if joba = 2, then u may be identified with a in the subroutine call.\n !\n ! input, integer(ip) ldu, the leading dimension of the array u.\n ! ldu must be at least m.\n !\n ! output, real(wp) v(ldv, n), the n by n matrix of right singular\n ! vectors. v is not referenced if job is 0. if n <= m, then v may be\n ! identified with a in the subroutine call.\n !\n ! input, integer(ip) ldv, the leading dimension of the array v.\n ! ldv must be at least n.\n !\n ! workspace, real(wp) work(m).\n !\n ! input, integer(ip) job, controls the computation of the singular\n ! vectors. it has the decimal expansion ab with the following meaning:\n ! a = 0, do not compute the left singular vectors.\n ! a = 1, return the m left singular vectors in u.\n ! a >= 2, return the first min(m, n) singular vectors in u.\n ! b = 0, do not compute the right singular vectors.\n ! b = 1, return the right singular vectors in v.\n !\n ! output, integer(ip) info, status indicator.\n ! the singular values (and their corresponding singular vectors)\n ! s(info+1), s(info+2), ..., s(mn) are correct. here mn = min(m, n).\n ! thus if info is 0, all the singular values and their vectors are\n ! correct. in any event, the matrix b = u' * a * v is the bidiagonal\n ! matrix with the elements of s on its diagonal and the elements of e on\n ! its superdiagonal. thus the singular values of a and b are the same.\n !\n subroutine singular_value_decomposition(a, lda, m, n, s, e, u, ldu, v, ldv, work, job, info)\n\n ! Dummy arguments\n real(wp), intent(inout) :: a(lda, n)\n integer(ip), intent(in) :: lda\n integer(ip), intent(in) :: m\n integer(ip), intent(in) :: n\n real(wp), intent(out) :: s(*)\n real(wp), intent(out) :: e(*)\n real(wp), intent(out) :: u(ldu, m)\n integer(ip), intent(in) :: ldu\n real(wp), intent(out) :: v(ldv, n)\n integer(ip), intent(in) :: ldv\n real(wp), intent(out) :: work(m)\n integer(ip), intent(in) :: job\n integer(ip), intent(out) :: info\n\n ! Local variables\n real(wp) b\n real(wp) c\n real(wp) cs\n real(wp) el\n real(wp) emm1\n real(wp) f\n real(wp) g\n integer(ip) iter\n integer(ip) j\n integer(ip) job_u\n integer(ip) k\n integer(ip) k_case\n integer(ip) kk\n integer(ip) l\n integer(ip) ll\n integer(ip) lls\n integer(ip) ls\n integer(ip) lu\n integer(ip), parameter :: MAX_ITER = 30\n integer(ip) mm\n integer(ip) mm1\n integer(ip) mn\n integer(ip) nct\n integer(ip) nctp1\n integer(ip) ncu\n integer(ip) nrt\n integer(ip) nrtp1\n real(wp) scale_factor\n real(wp) shift\n real(wp) sl\n real(wp) sm\n real(wp) smm1\n real(wp) sn\n real(wp) t\n real(wp) t1\n real(wp) test\n real(wp) ztest\n logical :: u_desired, v_desired\n\n ! Determine what is to be computed.\n u_desired = .false.\n v_desired = .false.\n job_u = mod(job, 100)/10\n\n if (1 < job_u) then\n ncu = min(m, n)\n else\n ncu = m\n end if\n\n if (job_u /= 0) u_desired = .true.\n\n if (mod(job, 10) /= 0) v_desired = .true.\n\n ! Reduce a to bidiagonal form, storing the diagonal elements\n ! in s and the super-diagonal elements in e.\n info = 0\n nct = min(m - 1, n)\n nrt = max(0, min(m, n - 2))\n lu = max(nct, nrt)\n\n do l = 1, lu\n\n ! Compute the transformation for the l-th column and\n ! place the l-th diagonal in s(l).\n if (l <= nct) then\n s(l) = get_norm2(m-l+1, a(l, l), 1)\n if (s(l) /= ZERO) then\n if (a(l, l) /= ZERO) s(l) = sign(s(l), a(l, l))\n call scale_vector_by_constant( m-l+1, ONE / s(l), a(l, l), 1)\n a(l, l) = ONE + a(l, l)\n end if\n s(l) = -s(l)\n end if\n\n do j = l + 1, n\n\n ! Apply the transformation.\n if (l <= nct .and. s(l) /= ZERO) then\n t = -get_dot_product( m-l+1, a(l, l), 1, a(l, j), 1) / a(l, l)\n call daxpy(m-l+1, t, a(l, l), 1, a(l, j), 1)\n end if\n\n ! Place the l-th row of a into e for the\n ! subsequent calculation of the row transformation.\n e(j) = a(l, j)\n end do\n\n ! Place the transformation in u for subsequent back multiplication.\n if (u_desired .and. l <= nct) u(l:m, l) = a(l:m, l)\n\n ! Compute the l-th row transformation and place the\n ! l-th superdiagonal in e(l).\n !\n if (l <= nrt) then\n e(l) = get_norm2(n - l, e(l+1), 1)\n if (e(l) /= ZERO) then\n if (e(l+1) /= ZERO) then\n e(l) = sign(e(l), e(l+1))\n end if\n call scale_vector_by_constant( n-l, ONE / e(l), e(l+1), 1)\n e(l+1) = ONE + e(l+1)\n end if\n\n e(l) = -e(l)\n !\n ! Apply the transformation.\n !\n if (l + 1 <= m .and. e(l) /= ZERO) then\n\n work(l+1:m) = ZERO\n\n do j = l + 1, n\n call daxpy(m-l, e(j), a(l+1, j), 1, work(l+1), 1)\n end do\n\n do j = l + 1, n\n call daxpy(m-l, -e(j)/e(l+1), work(l+1), 1, a(l+1, j), 1)\n end do\n\n end if\n\n ! Place the transformation in v for subsequent back multiplication.\n if (v_desired) v(l+1:n, l) = e(l+1:n)\n end if\n end do\n\n ! Set up the final bidiagonal matrix of order mn.\n mn = min(m + 1, n)\n nctp1 = nct + 1\n nrtp1 = nrt + 1\n\n if (nct < n) s(nctp1) = a(nctp1, nctp1)\n\n if (m < mn) s(mn) = ZERO\n\n if (nrtp1 < mn) e(nrtp1) = a(nrtp1, mn)\n\n e(mn) = ZERO\n\n ! If required, generate u.\n if (u_desired) then\n\n u(1:m, nctp1:ncu) = ZERO\n\n do j = nctp1, ncu\n u(j, j) = ONE\n end do\n\n do ll = 1, nct\n\n l = nct - ll + 1\n\n if (s(l) /= ZERO) then\n\n do j = l + 1, ncu\n t = -get_dot_product( m-l+1, u(l, l), 1, u(l, j), 1) / u(l, l)\n call daxpy(m-l+1, t, u(l, l), 1, u(l, j), 1)\n end do\n\n u(l:m, l) = -u(l:m, l)\n u(l, l) = ONE + u(l, l)\n u(1:l-1, l) = ZERO\n\n else\n u(1:m, l) = ZERO\n u(l, l) = ONE\n end if\n end do\n end if\n\n ! If it is required, generate v.\n if (v_desired) then\n\n do ll = 1, n\n l = n - ll + 1\n if (l <= nrt .and. e(l) /= ZERO) then\n do j = l + 1, n\n t = -get_dot_product( n-l, v(l+1, l), 1, v(l+1, j), 1) / v(l+1, l)\n call daxpy(n-l, t, v(l+1, l), 1, v(l+1, j), 1)\n end do\n end if\n v(1:n, l) = ZERO\n v(l, l) = ONE\n end do\n end if\n\n ! Main iteration loop for the singular values.\n mm = mn\n iter = 0\n main_iteration_loop: do\n\n if (mn <= 0) exit main_iteration_loop\n\n ! If too many iterations have been performed, set flag and return.\n\n if (MAX_ITER <= iter) then\n info = mn\n return\n end if\n !\n ! This section of the program inspects for\n ! negligible elements in the s and e arrays.\n !\n ! On completion the variables k_case and l are set as follows:\n !\n ! k_case = 1 if s(mn) and e(l-1) are negligible and l < mn\n ! k_case = 2 if s(l) is negligible and l < mn\n ! k_case = 3 if e(l-1) is negligible, l < mn, and\n ! s(l), ..., s(mn) are not negligible (qr step).\n ! k_case = 4 if e(mn-1) is negligible (convergence).\n !\n do ll = 1, mn\n l = mn - ll\n if (l == 0) exit\n test = abs(s(l)) + abs(s(l+1))\n ztest = test + abs(e(l))\n if (ztest == test) then\n e(l) = ZERO\n exit\n end if\n end do\n\n if (l == mn - 1) then\n k_case = 4\n else\n do lls = l + 1, mn + 1\n ls = mn - lls + l + 1\n\n if (ls == l) exit\n\n test = ZERO\n\n if (ls /= mn) test = test + abs(e(ls))\n\n if (ls /= l + 1) test = test + abs(e(ls-1))\n\n ztest = test + abs(s(ls))\n\n if (ztest == test) then\n s(ls) = ZERO\n exit\n end if\n end do\n\n if (ls == l) then\n k_case = 3\n else if (ls == mn) then\n k_case = 1\n else\n k_case = 2\n l = ls\n end if\n end if\n\n l = l + 1\n\n ! Deflate negligible s(mn).\n select case (k_case)\n case (1)\n \t\t\n mm1 = mn - 1\n f = e(mn-1)\n e(mn-1) = ZERO\n \t\t\n do kk = l, mm1\n \t\t\n k = mm1 - kk + l\n t1 = s(k)\n call construct_givens_plane_rotation(t1, f, cs, sn)\n s(k) = t1\n \t\t\n if (k /= l) then\n f = -sn * e(k-1)\n e(k-1) = cs * e(k-1)\n end if\n \t\t\n if (v_desired) call apply_plane_rotation(n, v(1, k), 1, v(1, mn), 1, cs, sn)\n end do\n case (2)\n \t\t\n f = e(l-1)\n e(l-1) = ZERO\n \t\t\n do k = l, mn\n t1 = s(k)\n call construct_givens_plane_rotation(t1, f, cs, sn)\n s(k) = t1\n f = -sn * e(k)\n e(k) = cs * e(k)\n if (u_desired) call apply_plane_rotation(m, u(1, k), 1, u(1, l-1), 1, cs, sn)\n end do\n case (3)\n\n ! Calculate the shift.\n scale_factor = max(abs(s(mn)), abs(s(mn - 1)), abs(e(mn - 1)), &\n abs(s(l)), abs(e(l)))\n \t\t\n sm = s(mn)/scale_factor\n smm1 = s(mn-1)/scale_factor\n emm1 = e(mn-1)/scale_factor\n sl = s(l)/scale_factor\n el = e(l)/scale_factor\n b = ((smm1 + sm) * (smm1 - sm) + emm1**2)/TWO\n c = (sm**2) * (emm1**2)\n shift = ZERO\n \t\t\n if (b /= ZERO .or. c /= ZERO) then\n shift = sqrt(b**2 + c)\n if (b < ZERO) shift = -shift\n shift = c / (b + shift)\n end if\n \t\t\n f = ( sl + sm) * ( sl - sm) + shift\n g = sl * el\n\n ! Chase zeros.\n mm1 = mn - 1\n \t\t\n do k = l, mm1\n \t\t\n call construct_givens_plane_rotation(f, g, cs, sn)\n \t\t\n if (k /= l) e(k-1) = f\n \t\t\n f = cs * s(k) + sn * e(k)\n e(k) = cs * e(k) - sn * s(k)\n g = sn * s(k+1)\n s(k+1) = cs * s(k+1)\n \t\t\n if (v_desired) call apply_plane_rotation(n, v(1, k), 1, v(1, k+1), 1, cs, sn)\n\n call construct_givens_plane_rotation(f, g, cs, sn)\n\n s(k) = f\n f = cs * e(k) + sn * s(k+1)\n s(k+1) = -sn * e(k) + cs * s(k+1)\n g = sn * e(k+1)\n e(k+1) = cs * e(k+1)\n \t\t\n if (u_desired .and. k < m) call apply_plane_rotation(m, u(1, k), 1, u(1, k+1), 1, cs, sn)\n\n end do\n \t\t\n e(mn-1) = f\n iter = iter + 1\n case (4)\n\n ! Make the singular value nonnegative.\n if (s(l) < ZERO) then\n s(l) = -s(l)\n if (v_desired) v(1:n, l) = -v(1:n, l)\n end if\n\n ! Order the singular value.\n do\n \t\t\n if (l == mm) exit\n \t\t\n if (s(l+1) <= s(l)) exit\n \t\t\n t = s(l)\n s(l) = s(l+1)\n s(l+1) = t\n \t\t\n if (v_desired .and. l < n) call swap_vectors( n, v(1, l), 1, v(1, l+1), 1)\n\n if (u_desired .and. l < m) call swap_vectors(m, u(1, l), 1, u(1, l+1), 1)\n l = l + 1\n end do\n iter = 0\n mn = mn - 1\n end select\n end do main_iteration_loop\n\n end subroutine singular_value_decomposition\n\n ! Purpose:\n !\n ! Computes constant times a vector plus a vector.\n !\n ! Jack dongarra, linpack, 3/11/78.\n ! Modified 12/3/93, array(1) declarations changed to array(*)\n ! Modified 01/27/17, whole array operations to aid compiler optimization\n !\n subroutine daxpy(n, da, dx, incx, dy, incy)\n\n ! Dummy arguments\n integer(ip), intent(in) :: n\n real(wp), intent(in) :: da\n real(wp), intent(in) :: dx(*)\n integer(ip), intent(in) :: incx\n real(wp), intent(inout) :: dy(*)\n integer(ip), intent(in) :: incy\n\n ! Local variables\n integer(ip) :: i, ix, iy, m\n\n if (n <= 0) then\n return\n else if (da == ZERO) then\n return\n else if (incx /= 1 .or. incy /= 1) then\n\n ! Code for unequal increments or equal increments\n ! not equal to 1.\n if (0 <= incx) then\n ix = 1\n else\n ix = (-n + 1) * incx + 1\n end if\n\n if (0 <= incy) then\n iy = 1\n else\n iy = (-n + 1) * incy + 1\n end if\n\n do i = 1, n\n dy(iy) = dy(iy) + da * dx(ix)\n ix = ix + incx\n iy = iy + incy\n end do\n else\n ! Code for both increments equal to 1.\n m = mod(n, 4)\n\n dy(1:m) = dy(1:m) + da * dx(1:m)\n\n do i = m + 1, n, 4\n dy(i) = dy(i) + da * dx(i)\n dy(i+1) = dy(i+1) + da * dx(i+1)\n dy(i+2) = dy(i+2) + da * dx(i+2)\n dy(i+3) = dy(i+3) + da * dx(i+3)\n end do\n end if\n\n end subroutine daxpy\n\n ! Purpose:\n !\n ! Forms the dot product of two vectors.\n ! Jack dongarra, linpack, 3/11/78.\n ! Modified 12/3/93, array(1) declarations changed to array(*)\n ! Modified 01/27/17, the function now wraps around the intrinsic dot_product\n !\n pure function get_dot_product(n, dx, incx, dy, incy) &\n result (return_value)\n\n ! Dummy arguments\n integer(ip), intent(in) :: n\n real(wp), intent(in) :: dx(*)\n integer(ip), intent(in) :: incx\n real(wp), intent(in) :: dy(*)\n integer(ip), intent(in) :: incy\n real(wp) :: return_value\n\n ! Local variables\n integer(ip) :: x1, xn, xi\n integer(ip) :: y1, yn, yi\n\n if (0 < incx) then\n x1 = 1\n xn = 1 + (n - 1) * incx\n xi = incx\n else\n x1 = 1 + (n - 1) * incx\n xn = 1\n xi = - incx\n end if\n\n if (0 < incy) then\n y1 = 1\n yn = 1 + (n - 1) * incy\n yi = incy\n else\n y1 = 1 + (n - 1) * incy\n yn = 1\n yi = - incy\n end if\n\n ! Let the intrinsic function dot_product take care of optimization.\n return_value = dot_product(dx(x1:xn:xi), dy(y1:yn:yi))\n\n end function get_dot_product\n\n ! Purpose:\n !\n ! Returns the euclidean norm of a vector via the function\n ! name, so that\n !\n ! return_value := sqrt( transpose(x) * x)\n !\n ! This version written on 25-October-1982.\n ! Modified on 14-October-1993 to inline the call to DLASSQ.\n ! Sven Hammarling, Nag Ltd.\n !\n ! Modified 01/27/17, function now wraps around the intrinsic norm2\n !\n pure function get_norm2(n, x, incx) &\n result (return_value)\n\n ! Dummy arguments\n integer(ip), intent(in) :: n\n real(wp), intent(in) :: x(*)\n integer(ip), intent(in) :: incx\n real(wp) :: return_value\n\n ! Local variables\n integer(ip) :: x1, xn, xi\n\n if (0 < incx) then\n x1 = 1\n xn = 1 + (n - 1) * incx\n xi = incx\n else\n x1 = 1 + (n - 1) * incx\n xn = 1\n xi = -incx\n end if\n\n ! Let the intrinsic function norm2 take care of optimization.\n return_value = norm2(x(x1:xn:xi))\n\n end function get_norm2\n\n ! Purpose:\n !\n ! Applies a plane rotation.\n ! Jack dongarra, linpack, 3/11/78.\n ! Modified 12/3/93, array(1) declarations changed to array(*)\n !\n subroutine apply_plane_rotation(n, x, incx, y, incy, c, s)\n\n ! Dummy arguments\n integer(ip), intent(in) :: n\n real(wp), intent(inout) :: x(*)\n integer(ip), intent(in) :: incx\n real(wp), intent(inout) :: y(*)\n integer(ip), intent(in) :: incy\n real(wp), intent(in) :: c\n real(wp), intent(in) :: s\n\n ! Local variables\n integer(ip) :: i, ix, iy\n real(wp) :: temp\n\n if (n <= 0) then\n return\n else if (incx == 1 .and. incy == 1) then\n do i = 1, n\n temp = c * x(i) + s * y(i)\n y(i) = c * y(i) - s * x(i)\n x(i) = temp\n end do\n else\n if (0 <= incx) then\n ix = 1\n else\n ix = (-n + 1) * incx + 1\n end if\n\n if (0 <= incy) then\n iy = 1\n else\n iy = (-n + 1) * incy + 1\n end if\n\n do i = 1, n\n temp = c * x(ix) + s * y(iy)\n y(iy) = c * y(iy) - s * x(ix)\n x(ix) = temp\n ix = ix + incx\n iy = iy + incy\n end do\n end if\n\n end subroutine apply_plane_rotation\n\n ! Purpose:\n !\n ! Constructs a Givens plane rotation.\n !\n ! Given values a and b, this routine computes\n !\n ! sigma = sign(a) if abs(a) > abs(b)\n ! = sign(b) if abs(a) <= abs(b);\n !\n ! r = sigma * (a**2 + b**2);\n !\n ! c = a / r if r is not 0\n ! = 1 if r is 0;\n !\n ! s = b / r if r is not 0, \n ! 0 if r is 0.\n !\n ! The computed numbers then satisfy the equation\n !\n ! ( c s) ( a) = ( r)\n ! ( -s c) ( b) = ( 0)\n !\n ! The routine also computes\n !\n ! z = s if abs(a) > abs(b), \n ! = 1 / c if abs(a) <= abs(b) and c is not 0, \n ! = 1 if c is 0.\n !\n ! The single value z encodes c and s, and hence the rotation:\n !\n ! if z = 1, set c = 0 and s = 1;\n ! if abs(z) < 1, set c = sqrt(1 - z**2) and s = z;\n ! if abs(z) > 1, set c = 1/ z and s = sqrt(1 - c**2);\n !\n ! Reference:\n !\n ! Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart, \n ! LINPACK User's Guide, \n ! SIAM, 1979, \n ! ISBN13: 978-0-898711-72-1, \n ! LC: QA214.L56.\n !\n ! Charles Lawson, Richard Hanson, David Kincaid, Fred Krogh, \n ! Algorithm 539, \n ! Basic Linear Algebra Subprograms for Fortran Usage, \n ! ACM Transactions on Mathematical Software, \n ! Volume 5, Number 3, September 1979, pages 308-323.\n !\n ! Dummy arguments:\n !\n ! input/output, real sa, sb. on input, sa and sb are the values\n ! a and b. on output, sa is overwritten with r, and sb is\n ! overwritten with z.\n !\n ! Output, real c, s, the cosine and sine of the\n ! Givens rotation.\n !\n subroutine construct_givens_plane_rotation(sa, sb, c, s)\n\n ! Dummy arguments\n real(wp), intent(inout) :: sa\n real(wp), intent(inout) :: sb\n real(wp), intent(out) :: s\n real(wp), intent(out) :: c\n\n ! Local variables\n real(wp) :: scale_factor, r, z, roe\n\n if (abs(sb) < abs(sa)) then\n roe = sa\n else\n roe = sb\n end if\n\n scale_factor = abs(sa) + abs(sb)\n\n if (scale_factor == ZERO) then\n c = ONE\n s = ZERO\n r = ZERO\n else\n r = scale_factor * hypot((sa/scale_factor), (sb/scale_factor))\n r = sign(ONE, roe) * r\n c = sa/r\n s = sb/r\n end if\n\n if (ZERO < abs(c) .and. abs(c) <= s) then\n z = ONE/c\n else\n z = s\n end if\n\n sa = r\n sb = z\n\n end subroutine construct_givens_plane_rotation\n\n ! Purpose:\n !\n ! Scales a vector by a constant.\n !\n ! Jack dongarra, linpack, 3/11/78.\n ! Modified 3/93 to return if incx <= 0.0\n ! Modified 12/3/93, array(1) declarations changed to array(*)\n ! Modified 01/27/17, uses array operations to aid compiler optimization\n !\n subroutine scale_vector_by_constant(n, sa, x, incx)\n\n ! Dummy arguments\n integer(ip), intent(in) :: n\n real(wp), intent(in) :: sa\n real(wp), intent(inout) :: x(*)\n integer(ip), intent(in) :: incx\n\n ! Local variables\n integer(ip) :: i, ix, m\n\n if (n <= 0) then\n return\n else if (incx == 1) then\n\n m = mod(n, 5)\n\n x(1:m) = sa * x(1:m)\n\n do i = m+1, n, 5\n x(i) = sa * x(i)\n x(i+1) = sa * x(i+1)\n x(i+2) = sa * x(i+2)\n x(i+3) = sa * x(i+3)\n x(i+4) = sa * x(i+4)\n end do\n else\n if (0 <= incx) then\n ix = 1\n else\n ix = (-n + 1) * incx + 1\n end if\n\n do i = 1, n\n x(ix) = sa * x(ix)\n ix = ix + incx\n end do\n\n end if\n\n end subroutine scale_vector_by_constant\n\n ! Purpose:\n !\n ! Interchanges two vectors.\n ! uses unrolled loops for increments equal one.\n ! Jack dongarra, linpack, 3/11/78.\n ! Modified 12/3/93, array(1) declarations changed to array(*)\n ! Modified 01/27/17, whole array operations to improve compiler optimization\n !\n subroutine swap_vectors(n, x, incx, y, incy)\n\n ! Dummy arguments\n integer(ip), intent(in) :: n\n real(wp), intent(inout) :: x(*)\n integer(ip), intent(in) :: incx\n real(wp), intent(inout) :: y(*)\n integer(ip), intent(in) :: incy\n\n ! Local variables\n integer(ip) :: m, i, ix, iy\n real(wp) :: temp\n\n if (n <= 0) then\n return\n else if (incx == 1 .and. incy == 1) then\n m = mod(n, 3)\n do i = 1, m\n temp = x(i)\n x(i) = y(i)\n y(i) = temp\n end do\n\n do i = m + 1, n, 3\n temp = x(i)\n x(i) = y(i)\n y(i) = temp\n\n temp = x(i+1)\n x(i+1) = y(i+1)\n y(i+1) = temp\n\n temp = x(i+2)\n x(i+2) = y(i+2)\n y(i+2) = temp\n end do\n else\n\n if (0 <= incx) then\n ix = 1\n else\n ix = (-n + 1) * incx + 1\n end if\n\n if (0 <= incy) then\n iy = 1\n else\n iy = (-n + 1) * incy + 1\n end if\n\n do i = 1, n\n temp = x(ix)\n x(ix) = y(iy)\n y(iy) = temp\n ix = ix + incx\n iy = iy + incy\n end do\n end if\n\n end subroutine swap_vectors\n\nend submodule scalar_projection_regular_grid\n", "meta": {"hexsha": "76ade0d49f327cdda0261c02911b4d57e30e8286", "size": 64721, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/scalar_projection_regular_grid.f90", "max_stars_repo_name": "jlokimlin/spherepack4.1", "max_stars_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-06-28T14:01:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T21:59:28.000Z", "max_issues_repo_path": "src/scalar_projection_regular_grid.f90", "max_issues_repo_name": "jlokimlin/spherepack4.1", "max_issues_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2016-05-07T23:00:35.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-22T23:52:30.000Z", "max_forks_repo_path": "src/scalar_projection_regular_grid.f90", "max_forks_repo_name": "jlokimlin/spherepack4.1", "max_forks_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-06-28T14:03:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T12:53:54.000Z", "avg_line_length": 32.9368956743, "max_line_length": 114, "alphanum_fraction": 0.4164645169, "num_tokens": 19065, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.7520125848754472, "lm_q1q2_score": 0.6761505951031238}} {"text": "SUBROUTINE fsparv(kv,km,g,kdiag)\n!\n! This subroutine assembles element matrices into a symmetric skyline\n! global matrix.\n!\n IMPLICIT NONE\n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\n INTEGER,INTENT(IN)::g(:),kdiag(:)\n REAL(iwp),INTENT(IN)::km(:,:)\n REAL(iwp),INTENT(OUT)::kv(:) \n INTEGER::i,idof,k,j,iw,ival\n idof=UBOUND(g,1)\n DO i=1,idof\n k=g(i)\n IF(k/=0)THEN\n DO j=1,idof\n IF(g(j)/=0)THEN\n iw=k-g(j)\n IF(iw>=0)THEN\n ival=kdiag(k)-iw\n kv(ival)=kv(ival)+km(i,j) \n END IF\n END IF\n END DO\n END IF\n END DO\nRETURN\nEND SUBROUTINE fsparv", "meta": {"hexsha": "2849fd9b10c3bf197feec150877d237cd63932cc", "size": 605, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "main/fsparv.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/fsparv.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/fsparv.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": 21.6071428571, "max_line_length": 69, "alphanum_fraction": 0.6016528926, "num_tokens": 213, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6761505901059646}} {"text": "module Mod_plcd_SimoJU\n use typre\n use Mod_plcd_ComparisonCriteria\n use Mod_Plcd_ConstitutiveTensor\n implicit none\n \n type, extends(ComparisonCriteria) :: SimoJu\n\n \n contains\n procedure :: Evaluate => SimoJuEvaluate\n procedure :: ComputeTauValueFromUniaxialStressTest => SimoJuComputeTauValueFromUniaxialStressTest\n end type\ncontains\n subroutine SimoJuComputeTauValueFromUniaxialStressTest(a,UniaxialStressLimit,CT,tau)\n class(SimoJu) :: a\n real(rp) :: UniaxialStressLimit,tau\n class(ConstitutiveTensor) :: CT\n \n real(rp) :: Cnorm\n real(rp) :: Direction(3), E0\n \n Direction = (/1.0_rp, 0.0_rp, 0.0_rp/)\n call CT%GetYoungModulusForDirection(Direction,E0)\n! \n call CT%GetCNorm(Cnorm)\n \n Tau = UniaxialStressLimit*sqrt(1.5_rp*Cnorm/E0)\n\n end subroutine \n \n subroutine SimoJuEvaluate(a,Stress,Strain,CT,tau)\n class(SimoJU) :: a\n real(rp) :: Stress(:), Strain(:), tau\n class(ConstitutiveTensor) :: CT\n\n real(rp) :: Cnorm\n \n call CT%GetCNorm(Cnorm)\n \n Tau = sqrt(dot_product(Stress,strain))*sqrt(1.5_rp*Cnorm)\n \n end subroutine\n \n \nend module\n\n\nmodule Mod_plcd_VonMises\n use typre\n use Mod_plcd_ComparisonCriteria\n use Mod_Plcd_ConstitutiveTensor\n implicit none\n \n type, extends(ComparisonCriteria) :: VonMises\n contains\n procedure :: Evaluate => VonMisesEvaluate\n procedure :: ComputeTauValueFromUniaxialStressTest => VonMisesComputeTauValueFromUniaxialStressTest\n end type\ncontains\n\n subroutine VonMisesComputeTauValueFromUniaxialStressTest(a,UniaxialStressLimit,CT,tau)\n class(VonMises) :: a\n real(rp) :: UniaxialStressLimit,tau\n class(ConstitutiveTensor) :: CT\n \n Tau = UniaxialStressLimit\n end subroutine\n\n\n\n subroutine VonMisesEvaluate(a,Stress,Strain,CT,tau)\n class(VonMises) :: a\n real(rp) :: Stress(:),Strain(:),tau\n class(ConstitutiveTensor) :: CT\n \n real(rp) :: deviatoricStress(size(Stress,1)),DeviatoricStressNorm,meanStress\n \n call CT%ComputeMeanStress(stress,meanstress)\n \n deviatoricStress = stress\n call CT%AddSphericalComponent(-meanstress,DeviatoricStress)\n \n call CT%ComputeStressNorm(DeviatoricStress,DeviatoricStressNorm)\n \n Tau = sqrt(3.0_rp/2.0_rp)*DeviatoricStressNorm\n end subroutine\n\nend module", "meta": {"hexsha": "af6190d4726760692784fa27fab17d7631d0b0f8", "size": 2403, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Sources/modules/plcd/Materials/ComparisonCriteria/Mod_plcd_ComparisonCriteriaImplementations.f90", "max_stars_repo_name": "ciaid-colombia/InsFEM", "max_stars_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-24T08:19:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-24T08:19:54.000Z", "max_issues_repo_path": "Sources/modules/plcd/Materials/ComparisonCriteria/Mod_plcd_ComparisonCriteriaImplementations.f90", "max_issues_repo_name": "ciaid-colombia/InsFEM", "max_issues_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Sources/modules/plcd/Materials/ComparisonCriteria/Mod_plcd_ComparisonCriteriaImplementations.f90", "max_forks_repo_name": "ciaid-colombia/InsFEM", "max_forks_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.0, "max_line_length": 105, "alphanum_fraction": 0.6878901373, "num_tokens": 723, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213799730775, "lm_q2_score": 0.7520125793176223, "lm_q1q2_score": 0.676150588073174}} {"text": " program test\n USE, INTRINSIC :: ISO_C_BINDING\n USE OPENST\n use omp_lib\n REAL (C_DOUBLE), TARGET, ALLOCATABLE :: U(:,:,:), V(:,:,:)\n CHARACTER (C_CHAR), TARGET, ALLOCATABLE :: LSM_UNLOCKED(:,:,:)\n INTEGER (C_SIZE_T) :: NI , NJ, NK\n REAL (C_DOUBLE) :: HI, HJ, HK, SRCI, SRCJ, SRCK\n TYPE (C_PTR) :: U_PTR, V_PTR, LSM_UNLOCKED_PTR, converged_ptr, it_ptr\n REAL (C_DOUBLE) :: EPS, CHECK, di, dj, dk, dist\n REAL (C_DOUBLE) :: L1, L2, LINF, Umin, Umean, Umax\n INTEGER (C_INT) :: max_iter, errcode\n INTEGER (C_INT), TARGET :: it, converged\n INTEGER (C_SIZE_T):: i,j,k\n double precision :: start, finish\n\n NI = 50\n NJ = 50\n NK = 50\n\n SRCI = 0.5\n SRCJ = 0.5\n SRCK = 0.5\n HI = 1.0 / (NI - 1)\n HJ = 1.0 / (NJ - 1)\n HK = 1.0 / (NK - 1)\n max_iter = 10\n EPS = 0.01 * MIN(HI,HJ,HK);\n print '(\"GRID: \",i3,\" x \",i3,\" x \",i3)',NI,NJ,NK\n print '(\"GRID STEP: \",E15.6,\" x \",E15.6,\" x \",E15.6)',HI,HJ,HK\n print '(\"EPS: \",E15.6)',EPS\n\n ALLOCATE ( U (NI, NJ, NK) )\n ALLOCATE ( V (NI, NJ, NK) )\n ALLOCATE ( LSM_UNLOCKED (NI, NJ, NK) )\n\n U_PTR = C_LOC(U)\n V_PTR = C_LOC(V)\n LSM_UNLOCKED_PTR = C_LOC(LSM_UNLOCKED)\n it_ptr = C_LOC(it)\n converged_ptr = C_LOC(converged)\n\n do k = 1,NK\n do j = 1,NJ\n do i = 1,NI\n V(i,j,k) = 1.0\n end do\n end do\n end do\n\n start = omp_get_wtime()\n V = RESHAPE( V, [NI,NJ,NK], order=[3,2,1])\n finish = omp_get_wtime()\n print '(\"RESHAPE C INPUT: \",f12.6,\" seconds.\")',finish-start\n\n start = omp_get_wtime()\n errcode = OpenST_LSM3D(U_PTR,LSM_UNLOCKED_PTR,V_PTR,NI,NJ,NK,HI,HJ,HK,SRCI,SRCJ,SRCK,EPS,max_iter,it_ptr,converged_ptr)\n finish = omp_get_wtime()\n print '(\"LSM3D: \",f12.6,\" seconds, \",i3,\" iterations, converged \",i1)',finish-start,it,converged\n\n if (errcode.NE.0) then\n print '(\"OPENST_ERROR: code \",i2)',errcode\n STOP 1\n end if\n\n start = omp_get_wtime()\n U = RESHAPE( U, [NI,NJ,NK], order=[3,2,1])\n finish = omp_get_wtime()\n print '(\"RESHAPE C OUTPUT: \",f12.6,\" seconds.\")',finish-start\n\n it = 0\n L1 = 0.0\n L2 = 0.0\n Umean = 0.0\n do k = 1,NK\n do j = 1,NJ\n do i = 1,NI\n di = SRCI - DBLE(i - 1) * HI\n dj = SRCJ - DBLE(j - 1) * HJ\n dk = SRCK - DBLE(k - 1) * HK\n dist = SQRT(di * di + dj * dj + dk * dk)\n CHECK = ABS(U(i,j,k) - dist)\n L1 = L1 + CHECK\n L2 = L2 + CHECK * CHECK\n Umean = Umean + U(i,j,k)\n if (it > 0) then\n LINF = MAX(CHECK,LINF)\n Umin = MIN(U(i,j,k),Umin)\n Umax = MAX(U(i,j,k),Umax)\n else\n LINF = CHECK\n Umin = U(i,j,k)\n Umax = U(i,j,k)\n end if\n it = it + 1\n end do\n end do\n end do\n L1 = L1 / DBLE(NI * NJ * NK)\n L2 = L2 / DBLE(NI * NJ * NK)\n Umean = Umean / DBLE(NI * NJ * NK)\n\n print '(A, T10, E15.6)', \"L1:\", L1, \"L2:\", L2, \"LINF:\", LINF\n print '(A, T10, E15.6)', \"Umin:\", Umin, \"Umean:\", Umean, \"Umax:\", Umax\n\n end program\n", "meta": {"hexsha": "7c8564598f818c8e4e9bcf26f84dc75786a4b510", "size": 3234, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "wrappers/fortran/EIKONAL_EX1.f90", "max_stars_repo_name": "aanikitin/seis-eikonal", "max_stars_repo_head_hexsha": "e53dd9e312284dc2e96e89bbf0ca05aca4f0d10f", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2016-01-29T22:35:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-14T11:54:01.000Z", "max_issues_repo_path": "wrappers/fortran/EIKONAL_EX1.f90", "max_issues_repo_name": "aanikitin/seis-eikonal", "max_issues_repo_head_hexsha": "e53dd9e312284dc2e96e89bbf0ca05aca4f0d10f", "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": "wrappers/fortran/EIKONAL_EX1.f90", "max_forks_repo_name": "aanikitin/seis-eikonal", "max_forks_repo_head_hexsha": "e53dd9e312284dc2e96e89bbf0ca05aca4f0d10f", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.2242990654, "max_line_length": 123, "alphanum_fraction": 0.48855906, "num_tokens": 1194, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146780175245, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.6761344187702647}} {"text": "! cfd_upwind.f90 \r\n!\r\n! FUNCTIONS:\r\n! cfd_upwind - Entry point of console application.\r\n!\r\n\r\n!****************************************************************************\r\n!\r\n! PROGRAM: cfd_upwind\r\n! by mehrdad baba hoseinpour \r\n! PURPOSE: Entry point for the console application.\r\n! beyond sky!\r\n!****************************************************************************\r\n\r\nprogram wave_upwind\r\nimplicit none\r\ninteger::i,n\r\ninteger,parameter:: ix=201,nt=400\r\nreal::u(nt,ix),a,dt,dx,l,pi,u1(nt,ix)\r\npi=2*asin(1.d0)\r\na=0.01\r\ndt=0.04\r\nl=1\r\ndx=l/(ix-1)\r\nprint*,'qourant number is = ',a*dt/dx\r\n\r\n!exact_solution\r\ndo n=1,nt\r\n do i=1,ix\r\n u1(n,i)= sin(2*pi*(i-1)*(dx-a*dt)*5) \r\n end do\r\nend do\r\n\r\n!initial condition\r\ndo i=1,ix\r\n u(1,i)=sin(2*pi*(i-1)*dx*5) ! 1,nt u(n,i) -a*n\r\nend do\r\ndo n=1,nt-1\r\n do i=2,ix-1\r\n u(n+1,i)=u(n,i)-a*dt/dx*(u(n,i)-u(n,i-1))\r\n end do\r\n !periodic condition\r\n u(n+1,1)=u(n,1)-a*dt/dx*(u(n,1)-u(n,ix))\r\n u(n+1,ix)=u(n+1,1)\r\nend do\r\nopen (1,file='analysis_result_upwind.plt') ! result analysis\r\ndo n=1,nt\r\n write(1,*)'variables=\"x\",\"u\"'\r\n write(1,*)'zone'\r\n do i=1,ix\r\n write(1,*) dx*(i-1),u1(n,i)\r\n end do\r\nend do\r\nopen (1,file='computational_result_upwind.plt') ! result computational\r\ndo n=1,nt\r\n write(1,*)'variables=\"x\",\"u\"'\r\n write(1,*)'zone'\r\n do i=1,ix\r\n write(1,*) dx*(i-1),u(n,i)\r\n end do\r\nend do\r\nprint*,\">>> please Inter <<<\"\r\npause\r\n end program wave_upwind\r\n\r\n\r\n", "meta": {"hexsha": "5df12fb9eb39496198de99db47548d42c56c463a", "size": 1486, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "cfd_upwind.f90", "max_stars_repo_name": "mehrdadBHP1997/1D-conduction-upwind", "max_stars_repo_head_hexsha": "7e551a489f8060e326b3fa7bdaa3c87cf7d08dbd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-27T11:33:19.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-27T11:33:19.000Z", "max_issues_repo_path": "cfd_upwind.f90", "max_issues_repo_name": "mehrdadBHP1997/1D-conduction-upwind", "max_issues_repo_head_hexsha": "7e551a489f8060e326b3fa7bdaa3c87cf7d08dbd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cfd_upwind.f90", "max_forks_repo_name": "mehrdadBHP1997/1D-conduction-upwind", "max_forks_repo_head_hexsha": "7e551a489f8060e326b3fa7bdaa3c87cf7d08dbd", "max_forks_repo_licenses": ["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.1791044776, "max_line_length": 78, "alphanum_fraction": 0.5087483176, "num_tokens": 539, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095294, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.6761344090293131}} {"text": "program Example\n implicit none\n\n real :: r\n integer :: a, b\n\n do\n call random_number(r)\n a = int(r * 20)\n write(*,*) a\n if (a == 10) exit\n call random_number(r)\n b = int(r * 20)\n write(*,*) b\n end do\n\nend program Example\n", "meta": {"hexsha": "1881c184b08665949dd55007585370620962003b", "size": 254, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Loops-Break/Fortran/loops-break-1.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Loops-Break/Fortran/loops-break-1.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Loops-Break/Fortran/loops-break-1.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 14.1111111111, "max_line_length": 26, "alphanum_fraction": 0.531496063, "num_tokens": 84, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467738423873, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.676134404593549}} {"text": "c\nc * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nc * *\nc * copyright (c) 1998 by UCAR *\nc * *\nc * University Corporation for Atmospheric Research *\nc * *\nc * all rights reserved *\nc * *\nc * SPHEREPACK version 3.2 *\nc * *\nc * A Package of Fortran77 Subroutines and Programs *\nc * *\nc * for Modeling Geophysical Processes *\nc * *\nc * by *\nc * *\nc * John Adams and Paul Swarztrauber *\nc * *\nc * of *\nc * *\nc * the National Center for Atmospheric Research *\nc * *\nc * Boulder, Colorado (80307) U.S.A. *\nc * *\nc * which is sponsored by *\nc * *\nc * the National Science Foundation *\nc * *\nc * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nc\nc\nc\nc\nc 1/976\nc\nc a program for testing all vector laplacian and its inverse\nc\nc (1) first set the vector function (rotation about equator) using\nc v = cos(phi) and w = -cos(theta)*sin(phi)\nc\nc (2) set vector laplacian ananlytically\nc vlap = -2.*cos(phi)=-2.*v, wlap = -2.*w\nc (i.e., L(v,w) = -2.*(v,w) so (v,w) is an eigenfunction for the\nc vector Laplacian with eigenvalue -2.\nc\nc (3) compute the coefficients br,bi,cr,ci of (v,w) using vector analysis\nc\nc (3) compute the vector laplacian of (v,w) using vlapec,vlapes,vlapgc,vlapgs\nc\nc (4) compare (3) with (2)\nc\nc (5) invert (4) and compare with (v,w)\nc\n program tvlap\nc\nc set dimensions with parameter statements\nc\n parameter(nnlat=29 ,nnlon= 16, nnt = 1)\n parameter (mmdbc = (nnlon+2)/2)\n parameter (lleng= 5*nnlat*nnlat*nnlon,llsav=15*nnlat*nnlat*nnlon)\n parameter (lldwork = 4*nnlat*nnlat )\n double precision dwork(lldwork)\n dimension work(lleng),wsave(llsav)\n dimension br(mmdbc,nnlat,nnt),bi(mmdbc,nnlat,nnt)\n dimension cr(mmdbc,nnlat,nnt),ci(mmdbc,nnlat,nnt)\n dimension thetag(nnlat),dtheta(nnlat),dwts(nnlat)\n dimension v(nnlat,nnlon,nnt),w(nnlat,nnlon,nnt)\n dimension vlap(nnlat,nnlon,nnt),wlap(nnlat,nnlon,nnt)\n\n double precision dtheta, dwts\nc\nc set dimension variables\nc\n nlat = nnlat\n nlon = nnlon\n nmax = max0(nlat,nlon)\n mdbc = mmdbc\n\n lwork = lleng\n lsave = llsav\n nt = nnt\n call iout(nlat,\"nlat\")\n call iout(nlon,\"nlon\")\n call iout(nt,\" nt\")\n isym = 0\n ityp = 0\nc\nc set equally spaced colatitude and longitude increments\nc\n pi = 4.0*atan(1.0)\n dphi = (pi+pi)/nlon\n dlat = pi/(nlat-1)\nc\nc compute nlat gaussian points in thetag\nc\n ldwork = lldwork\n call gaqd(nlat,dtheta,dwts,dwork,ldwork,ier)\n do i=1,nlat\n\tthetag(i) = dtheta(i)\n end do\n call name(\"gaqd\")\n call iout(ier,\" ier\")\n call vecout(thetag,\"thtg\",nlat)\nc\nc test all divergence and inverse divergence subroutines\nc\n do icase=1,4\n call name(\"****\")\n call name(\"****\")\n call iout(icase,\"icas\")\nc\nc set vector field v,w\nc\n do k=1,nt\n\tdo j=1,nlon\n\t phi = (j-1)*dphi\n\t sinp = sin(phi)\n\t cosp = cos(phi)\n\t do i=1,nlat\n\t theta = (i-1)*dlat\n\t if (icase.gt.2) theta=thetag(i)\n\t cost = cos(theta)\n\t sint = sin(theta)\n\t if (k.eq.1) then\n\t v(i,j,k) = cosp\n\t w(i,j,k) = -cost*sinp\n\t vlap(i,j,k) = -2.0*v(i,j,k)\n\t wlap(i,j,k) = -2.0*w(i,j,k)\n\t end if\n\t end do\n\tend do\n end do\n\n if (nmax.lt.10) then\n do kk=1,nt\n call iout(kk,\"**kk\")\nc call aout(v(1,1,kk),\" v\",nlat,nlon)\nc call aout(w(1,1,kk),\" w\",nlat,nlon)\nc call aout(vlap(1,1,kk),\"vlap\",nlat,nlon)\nc call aout(wlap(1,1,kk),\"wlap\",nlat,nlon)\n end do\n end if\n\n if (icase.eq.1) then\n\n call name(\"**ec\")\nc\nc analyze vector field\nc\n call vhaeci(nlat,nlon,wsave,lsave,dwork,ldwork,ierror)\n call name(\"vhai\")\n call iout(ierror,\"ierr\")\n\n call vhaec(nlat,nlon,ityp,nt,v,w,nlat,nlon,br,bi,cr,ci,mdbc,\n +nlat,wsave,lsave,work,lwork,ierror)\n call name(\"vha \")\n call iout(ierror,\"ierr\")\n\nc if (nmax.lt.10) then\nc do kk=1,nt\nc call iout(kk,\"**kk\")\nc call aout(br(1,1,kk),\" br\",nlat,nlat)\nc call aout(bi(1,1,kk),\" bi\",nlat,nlat)\nc call aout(cr(1,1,kk),\" cr\",nlat,nlat)\nc call aout(ci(1,1,kk),\" ci\",nlat,nlat)\nc end do\nc end if\nc\nc compute vector laplacian\nc\n\n call vhseci(nlat,nlon,wsave,lsave,dwork,ldwork,ierror)\n call name(\"vhsi\")\n call iout(ierror,\"ierr\")\n\n call vlapec(nlat,nlon,ityp,nt,vlap,wlap,nlat,nlon,br,bi,\n +cr,ci,mdbc,nlat,wsave,lsave,work,lwork,ierror)\n call name(\"vlap\")\n call iout(ierror,\"ierr\")\n\n\n else if (icase.eq.2) then\n\n call name(\"**es\")\nc\nc analyze vector field\nc\n call vhaesi(nlat,nlon,wsave,lsave,work,lwork,dwork,ldwork,ierror)\n call name(\"vhai\")\n call iout(ierror,\"ierr\")\n\n call vhaes(nlat,nlon,isym,nt,v,w,nlat,nlon,br,bi,cr,ci,mdbc,\n +nlat,wsave,lsave,work,lwork,ierror)\n call name(\"vhae\")\n call iout(ierror,\"ierr\")\n\n call vhsesi(nlat,nlon,wsave,lsave,work,lwork,dwork,ldwork,ierror)\n call name(\"vhsi\")\n call iout(ierror,\"ierr\")\n\n call vlapes(nlat,nlon,isym,nt,vlap,wlap,nlat,nlon,br,bi,\n +cr,ci,mdbc,nlat,wsave,lsave,work,lwork,ierror)\n call name(\"vlap\")\n call iout(ierror,\"ierr\")\n\n else if (icase .eq.3 ) then\n\n call name(\"**gc\")\nc\nc analyze vector field\nc\n call vhagci(nlat,nlon,wsave,lsave,dwork,ldwork,ierror)\n call name(\"vhai\")\n call iout(ierror,\"ierr\")\n\n call vhagc(nlat,nlon,ityp,nt,v,w,nlat,nlon,br,bi,cr,ci,mdbc,\n +nlat,wsave,lsave,work,lwork,ierror)\n call name(\"vha \")\n call iout(ierror,\"ierr\")\n\nc if (nmax.lt.10) then\nc do kk=1,nt\nc call iout(kk,\"**kk\")\nc call aout(br(1,1,kk),\" br\",nlat,nlat)\nc call aout(bi(1,1,kk),\" bi\",nlat,nlat)\nc call aout(cr(1,1,kk),\" cr\",nlat,nlat)\nc call aout(ci(1,1,kk),\" ci\",nlat,nlat)\nc end do\nc end if\nc\nc compute vector laplacian\nc\n\n call vhsgci(nlat,nlon,wsave,lsave,dwork,ldwork,ierror)\n call name(\"vhsi\")\n call iout(ierror,\"ierr\")\n\n call vlapgc(nlat,nlon,ityp,nt,vlap,wlap,nlat,nlon,br,bi,\n +cr,ci,mdbc,nlat,wsave,lsave,work,lwork,ierror)\n call name(\"vlap\")\n call iout(ierror,\"ierr\")\n\n else if (icase .eq. 4) then\n\n call name(\"**gs\")\nc\nc analyze vector field\nc\n call vhagsi(nlat,nlon,wsave,lsave,work,lwork,dwork,ldwork,ierror)\n call name(\"vhai\")\n call iout(ierror,\"ierr\")\n\n call vhags(nlat,nlon,ityp,nt,v,w,nlat,nlon,br,bi,cr,ci,mdbc,\n +nlat,wsave,lsave,work,lwork,ierror)\n call name(\"vha \")\n call iout(ierror,\"ierr\")\n\nc if (nmax.lt.10) then\nc do kk=1,nt\nc call iout(kk,\"**kk\")\nc call aout(br(1,1,kk),\" br\",nlat,nlat)\nc call aout(bi(1,1,kk),\" bi\",nlat,nlat)\nc call aout(cr(1,1,kk),\" cr\",nlat,nlat)\nc call aout(ci(1,1,kk),\" ci\",nlat,nlat)\nc end do\nc end if\nc\nc compute vector laplacian\nc\n\n call vhsgsi(nlat,nlon,wsave,lsave,work,lwork,dwork,ldwork,ierror)\n call name(\"vhsi\")\n call iout(ierror,\"ierr\")\n\n call vlapgs(nlat,nlon,ityp,nt,vlap,wlap,nlat,nlon,br,bi,\n +cr,ci,mdbc,nlat,wsave,lsave,work,lwork,ierror)\n call name(\"vlap\")\n call iout(ierror,\"ierr\")\n\n end if\n\n if (nmax.lt.10) then\n do kk=1,nt\n call iout(kk,\"**kk\")\nc call aout(vlap(1,1,kk),\"vlap\",nlat,nlon)\nc call aout(wlap(1,1,kk),\"wlap\",nlat,nlon)\n end do\n end if\nc\nc compute \"error\" in vlap,wlap\nc\n err2v = 0.0\n err2w =0.0\n do k=1,nt\n\tdo j=1,nlon\n\t do i=1,nlat\n\t if (k.eq.1) then\n\t err2v = err2v+(vlap(i,j,k)+2.*v(i,j,k))**2\n\t err2w = err2w+(wlap(i,j,k)+2.*w(i,j,k))**2\n\t end if\n\t end do\n\tend do\n end do\nc\nc set and print least squares error in vlap,wlap\nc\n err2v = sqrt(err2v/(nt*nlat*nlon))\n err2w = sqrt(err2w/(nt*nlon*nlat))\n call vout(err2v,\"errv\")\n call vout(err2w,\"errw\")\nc\nc now recompute (v,w) inverting (vlap,wlap) ivlap codes\nc\n do kk=1,nt\n do j=1,nlon\n do i=1,nlat\n v(i,j,kk) = 0.0\n w(i,j,kk) = 0.0\n end do\n end do\n end do\n\n\n if (icase.eq.1) then\n\n call name(\"**ec\")\nc\nc analyze vector field (vlap,wlap)\nc\n call vhaeci(nlat,nlon,wsave,lsave,dwork,ldwork,ierror)\n call name(\"vhai\")\n call iout(ierror,\"ierr\")\n\n call vhaec(nlat,nlon,ityp,nt,vlap,wlap,nlat,nlon,\n +br,bi,cr,ci,mdbc,nlat,wsave,lsave,work,lwork,ierror)\n call name(\"vha \")\n call iout(ierror,\"ierr\")\n\n call vhseci(nlat,nlon,wsave,lsave,dwork,ldwork,ierror)\n call name(\"vhsi\")\n call iout(ierror,\"ierr\")\n\n call ivlapec(nlat,nlon,isym,nt,v,w,nlat,nlon,br,bi,\n +cr,ci,mdbc,nlat,wsave,lsave,work,lwork,ierror)\n call name(\"ivlp\")\n call iout(ierror,\"ierr\")\n\n else if (icase.eq.2) then\n\n call name(\"**es\")\nc\nc analyze vector field (vlap,wlap)\nc\n call vhaesi(nlat,nlon,wsave,lsave,work,lwork,dwork,ldwork,ierror)\n call name(\"vhai\")\n call iout(ierror,\"ierr\")\n\n call vhaes(nlat,nlon,isym,nt,vlap,wlap,nlat,nlon,\n +br,bi,cr,ci,mdbc,nlat,wsave,lsave,work,lwork,ierror)\n call name(\"vha \")\n call iout(ierror,\"ierr\")\n\n call vhsesi(nlat,nlon,wsave,lsave,work,lwork,dwork,ldwork,ierror)\n call name(\"vhsi\")\n call iout(ierror,\"ierr\")\n\n call ivlapes(nlat,nlon,isym,nt,v,w,nlat,nlon,br,bi,\n +cr,ci,mdbc,nlat,wsave,lsave,work,lwork,pertrb,ierror)\n call name(\"ivlp\")\n call iout(ierror,\"ierr\")\n\n else if (icase .eq. 3) then\n\n call name(\"**gc\")\n\nc\nc analyze vector field (vlap,wlap)\nc\n call vhagci(nlat,nlon,wsave,lsave,dwork,ldwork,ierror)\n call name(\"vhai\")\n call iout(ierror,\"ierr\")\n\n call vhagc(nlat,nlon,ityp,nt,vlap,wlap,nlat,nlon,\n +br,bi,cr,ci,mdbc,nlat,wsave,lsave,work,lwork,ierror)\n call name(\"vha \")\n call iout(ierror,\"ierr\")\n\n call vhsgci(nlat,nlon,wsave,lsave,work,ldwork,ierror)\n call name(\"vhsi\")\n call iout(ierror,\"ierr\")\n\n call ivlapgc(nlat,nlon,isym,nt,v,w,nlat,nlon,br,bi,\n +cr,ci,mdbc,nlat,wsave,lsave,work,lwork,ierror)\n call name(\"ivlp\")\n call iout(ierror,\"ierr\")\n\n else if (icase .eq. 4) then\n\n call name(\"**gs\")\n\nc\nc analyze vector field (vlap,wlap)\nc\n call vhagsi(nlat,nlon,wsave,lsave,work,lwork,dwork,ldwork,ierror)\n call name(\"vhai\")\n call iout(ierror,\"ierr\")\n\n call vhags(nlat,nlon,ityp,nt,vlap,wlap,nlat,nlon,\n +br,bi,cr,ci,mdbc,nlat,wsave,lsave,work,lwork,ierror)\n call name(\"vha \")\n call iout(ierror,\"ierr\")\n\n call vhsgsi(nlat,nlon,wsave,lsave,work,lwork,dwork,ldwork,ierror)\n call name(\"vhsi\")\n call iout(ierror,\"ierr\")\n\n call ivlapgs(nlat,nlon,isym,nt,v,w,nlat,nlon,br,bi,\n +cr,ci,mdbc,nlat,wsave,lsave,work,lwork,ierror)\n call name(\"ivlp\")\n call iout(ierror,\"ierr\")\n\n end if\n\n\n if (nmax.lt.10) then\n do kk=1,nt\n call iout(kk,\"**kk\")\nc call aout(v(1,1,kk),\" v\",nlat,nlon)\nc call aout(w(1,1,kk),\" w\",nlat,nlon)\n end do\n end if\n\nc\nc compare this v,w with original\nc\n err2v = 0.0\n err2w = 0.0\n do k=1,nt\n\tdo j=1,nlon\n\t phi = (j-1)*dphi\n\t sinp = sin(phi)\n\t cosp = cos(phi)\n\t do i=1,nlat\n\t theta = (i-1)*dlat\n\t if (icase.gt.2) theta=thetag(i)\n\t cost = cos(theta)\n\t sint = sin(theta)\n\t if (k.eq.1) then\n\t ve = cosp\n\t we = -cost*sinp\n\t end if\n\t err2v = err2v + (v(i,j,k)-ve)**2\n\t err2w = err2w + (w(i,j,k)-we)**2\n\t end do\n\tend do\n end do\n err2v = sqrt(err2v/(nlat*nlon*nt))\n err2w = sqrt(err2w/(nlat*nlon*nt))\n call vout(err2v,\"errv\")\n call vout(err2w,\"errw\")\n\nc\nc end of icase loop\nc\n end do\n end\nc\n subroutine iout(ivar,nam)\n real nam\n write(6,10) nam , ivar\n 10 format(1h a4, 3h = ,i8)\n return\n end\nc\n subroutine vout(var,nam)\n real nam\n write(6,10) nam , var\n 10 format(1h a4,3h = ,e12.5)\n return\n end\nc\n subroutine name(nam)\n real nam\n write(6,100) nam\n 100 format(1h a8)\n return\n end\nc\n subroutine vecout(vec,nam,len)\n dimension vec(len)\n real nam\n write(6,109) nam, (vec(l),l=1,len)\n 109 format(1h a4,/(1h 8e11.4))\n return\n end\n", "meta": {"hexsha": "2105a5bddd56e401440faa06b5bb78e7aab11545", "size": 13651, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "install/spherepack3.2/test/tvlap.f", "max_stars_repo_name": "comp-physics/RBC3D", "max_stars_repo_head_hexsha": "2891a1e3b356e2cff0cfa74ba26d4aef3336641d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "install/spherepack3.2/test/tvlap.f", "max_issues_repo_name": "comp-physics/RBC3D", "max_issues_repo_head_hexsha": "2891a1e3b356e2cff0cfa74ba26d4aef3336641d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "install/spherepack3.2/test/tvlap.f", "max_forks_repo_name": "comp-physics/RBC3D", "max_forks_repo_head_hexsha": "2891a1e3b356e2cff0cfa74ba26d4aef3336641d", "max_forks_repo_licenses": ["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.4668008048, "max_line_length": 81, "alphanum_fraction": 0.5251629917, "num_tokens": 4647, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467611766711, "lm_q2_score": 0.7690802317779601, "lm_q1q2_score": 0.6761343948525972}} {"text": "\n! .................................................................\n SUBROUTINE LAGRANGE_MULT(NCONS,H20,ACON20,alagCON_0,alagCON,NDIM)\n! .................................................................\n! INPUTS: NCONS,H20,ACON20\n! .................................................................\n USE VAPHFB_PAR \n implicit real*8 (a-h,o-z)\n \n DIMENSION alagCON_0(NCONSMAX)\n DIMENSION alagCON(NCONSMAX)\n! ...................................\n DIMENSION ACON20(NCONS*NDIM*NDIM)\n DIMENSION H20(NDIM,NDIM)\n DIMENSION AUX1(((NCONS+1)*NCONS/2)*NDIM*NDIM)\n DIMENSION AUX2(NCONS*NDIM*NDIM)\n DIMENSION Amatrix(NCONS,NCONS),Bmatrix(NCONS)\n DIMENSION IPIV(NCONS)\n \n ll=0\n do ii=1,NCONS\n indi=(ii-1)*NDIM*NDIM+1\n\n! ............ number of constraint terms\n do jj=ii,NCONS\n indj=(jj-1)*NDIM*NDIM+1\n ll=ll+1\n indl=(ll-1)*NDIM*NDIM+1\n\n! ............ AUX1 = ACON20 * ACON20\n call DGEMM ('n','t',NDIM,NDIM,NDIM,1.d0,ACON20(indi), &\n & NDIM,ACON20(indj),NDIM,0.d0,AUX1(indl),NDIM) \n \n end do\n\n! ............ AUX2 = H20 * ACON20\n call DGEMM ('n','t',NDIM,NDIM,NDIM,1.d0, &\n & H20,NDIM,ACON20(indi),NDIM,0.d0,AUX2(indi),NDIM)\n\n end do\n \n \n ll=0\n do ii=1,NCONS\n indi=(ii-1)*NDIM*NDIM+1\n do jj=ii,NCONS\n ll=ll+1\n indl=(ll-1)*NDIM*NDIM+1\n\n Amatrix(jj,ii)=zero \n do mm=1,NDIM\n idig=(mm-1)*NDIM+mm-1\n Amatrix(jj,ii)=Amatrix(jj,ii)+AUX1(indl+idig) \n end do\n Amatrix(ii,jj)=Amatrix(jj,ii) \n end do\n\n Bmatrix(ii)=zero\n do mm=1,NDIM\n idig=(mm-1)*NDIM+mm-1\n Bmatrix(ii)=Bmatrix(ii)+AUX2(indi+idig)\t \n end do\n \n end do\n\n\n call DGESV(NCONS,1,Amatrix,NCONS,IPIV,Bmatrix,NCONS,INFO)\n \n do ii=1,NCONS\n alagCON(ii)=Bmatrix(ii)\n end do\n \n if (INFO.ne.0) then\n do ii=1,NCONS\n alagCON(ii)=alagCON_0(ii)\n end do\n end if\n\n do ii=1,NCONS\n alagCON_0(ii)=alagCON(ii)\n end do\n\n \n END SUBROUTINE \n\n\n\n\n\n\n\n\n \n", "meta": {"hexsha": "0d064f308eb04c8b55414a8f83494a09898df1ed", "size": 2399, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Codes/HFB/VAPHFB_Lagrange.f90", "max_stars_repo_name": "jmyao17/SCCM", "max_stars_repo_head_hexsha": "16e31afa313bf70741c152d859aa837935110776", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Codes/HFB/VAPHFB_Lagrange.f90", "max_issues_repo_name": "jmyao17/SCCM", "max_issues_repo_head_hexsha": "16e31afa313bf70741c152d859aa837935110776", "max_issues_repo_licenses": ["MIT"], "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/HFB/VAPHFB_Lagrange.f90", "max_forks_repo_name": "jmyao17/SCCM", "max_forks_repo_head_hexsha": "16e31afa313bf70741c152d859aa837935110776", "max_forks_repo_licenses": ["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.5212765957, "max_line_length": 72, "alphanum_fraction": 0.4218424343, "num_tokens": 745, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853655, "lm_q2_score": 0.760650658103136, "lm_q1q2_score": 0.6760349656474314}} {"text": "*DECK SVD\n SUBROUTINE SVD (NM, M, N, A, W, MATU, U, MATV, V, IERR, RV1)\nC***BEGIN PROLOGUE SVD\nC***SUBSIDIARY\nC***PURPOSE Perform the singular value decomposition of a rectangular\nC matrix.\nC***LIBRARY SLATEC\nC***TYPE SINGLE PRECISION (SVD-S)\nC***AUTHOR (UNKNOWN)\nC***DESCRIPTION\nC\nC This subroutine is a translation of the ALGOL procedure SVD,\nC NUM. MATH. 14, 403-420(1970) by Golub and Reinsch.\nC HANDBOOK FOR AUTO. COMP., VOL II-LINEAR ALGEBRA, 134-151(1971).\nC\nC This subroutine determines the singular value decomposition\nC T\nC A=USV of a REAL M by N rectangular matrix. Householder\nC bidiagonalization and a variant of the QR algorithm are used.\nC\nC On Input\nC\nC NM must be set to the row dimension of the two-dimensional\nC array parameters, A, U and V, as declared in the calling\nC program dimension statement. NM is an INTEGER variable.\nC Note that NM must be at least as large as the maximum\nC of M and N.\nC\nC M is the number of rows of A and U.\nC\nC N is the number of columns of A and U and the order of V.\nC\nC A contains the rectangular input matrix to be decomposed. A is\nC a two-dimensional REAL array, dimensioned A(NM,N).\nC\nC MATU should be set to .TRUE. if the U matrix in the\nC decomposition is desired, and to .FALSE. otherwise.\nC MATU is a LOGICAL variable.\nC\nC MATV should be set to .TRUE. if the V matrix in the\nC decomposition is desired, and to .FALSE. otherwise.\nC MATV is a LOGICAL variable.\nC\nC On Output\nC\nC A is unaltered (unless overwritten by U or V).\nC\nC W contains the N (non-negative) singular values of A (the\nC diagonal elements of S). They are unordered. If an\nC error exit is made, the singular values should be correct\nC for indices IERR+1, IERR+2, ..., N. W is a one-dimensional\nC REAL array, dimensioned W(N).\nC\nC U contains the matrix U (orthogonal column vectors) of the\nC decomposition if MATU has been set to .TRUE. Otherwise,\nC U is used as a temporary array. U may coincide with A.\nC If an error exit is made, the columns of U corresponding\nC to indices of correct singular values should be correct.\nC U is a two-dimensional REAL array, dimensioned U(NM,N).\nC\nC V contains the matrix V (orthogonal) of the decomposition if\nC MATV has been set to .TRUE. Otherwise, V is not referenced.\nC V may also coincide with A if U does not. If an error\nC exit is made, the columns of V corresponding to indices of\nC correct singular values should be correct. V is a two-\nC dimensional REAL array, dimensioned V(NM,N).\nC\nC IERR is an INTEGER flag set to\nC Zero for normal return,\nC K if the K-th singular value has not been\nC determined after 30 iterations.\nC\nC RV1 is a one-dimensional REAL array used for temporary storage,\nC dimensioned RV1(N).\nC\nC CALLS PYTHAG(A,B) for sqrt(A**2 + B**2).\nC\nC Questions and comments should be directed to B. S. Garbow,\nC APPLIED MATHEMATICS DIVISION, ARGONNE NATIONAL LABORATORY\nC ------------------------------------------------------------------\nC\nC***SEE ALSO EISDOC\nC***ROUTINES CALLED PYTHAG\nC***REVISION HISTORY (YYMMDD)\nC 811101 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890831 Modified array declarations. (WRB)\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900402 Added TYPE section. (WRB)\nC***END PROLOGUE SVD\nC\n INTEGER I,J,K,L,M,N,II,I1,KK,K1,LL,L1,MN,NM,ITS,IERR\n REAL A(NM,*),W(*),U(NM,*),V(NM,*),RV1(*)\n REAL C,F,G,H,S,X,Y,Z,SCALE,S1\n REAL PYTHAG\n LOGICAL MATU,MATV\nC\nC***FIRST EXECUTABLE STATEMENT SVD\n IERR = 0\nC\n DO 100 I = 1, M\nC\n DO 100 J = 1, N\n U(I,J) = A(I,J)\n 100 CONTINUE\nC .......... HOUSEHOLDER REDUCTION TO BIDIAGONAL FORM ..........\n G = 0.0E0\n SCALE = 0.0E0\n S1 = 0.0E0\nC\n DO 300 I = 1, N\n L = I + 1\n RV1(I) = SCALE * G\n G = 0.0E0\n S = 0.0E0\n SCALE = 0.0E0\n IF (I .GT. M) GO TO 210\nC\n DO 120 K = I, M\n 120 SCALE = SCALE + ABS(U(K,I))\nC\n IF (SCALE .EQ. 0.0E0) GO TO 210\nC\n DO 130 K = I, M\n U(K,I) = U(K,I) / SCALE\n S = S + U(K,I)**2\n 130 CONTINUE\nC\n F = U(I,I)\n G = -SIGN(SQRT(S),F)\n H = F * G - S\n U(I,I) = F - G\n IF (I .EQ. N) GO TO 190\nC\n DO 150 J = L, N\n S = 0.0E0\nC\n DO 140 K = I, M\n 140 S = S + U(K,I) * U(K,J)\nC\n F = S / H\nC\n DO 150 K = I, M\n U(K,J) = U(K,J) + F * U(K,I)\n 150 CONTINUE\nC\n 190 DO 200 K = I, M\n 200 U(K,I) = SCALE * U(K,I)\nC\n 210 W(I) = SCALE * G\n G = 0.0E0\n S = 0.0E0\n SCALE = 0.0E0\n IF (I .GT. M .OR. I .EQ. N) GO TO 290\nC\n DO 220 K = L, N\n 220 SCALE = SCALE + ABS(U(I,K))\nC\n IF (SCALE .EQ. 0.0E0) GO TO 290\nC\n DO 230 K = L, N\n U(I,K) = U(I,K) / SCALE\n S = S + U(I,K)**2\n 230 CONTINUE\nC\n F = U(I,L)\n G = -SIGN(SQRT(S),F)\n H = F * G - S\n U(I,L) = F - G\nC\n DO 240 K = L, N\n 240 RV1(K) = U(I,K) / H\nC\n IF (I .EQ. M) GO TO 270\nC\n DO 260 J = L, M\n S = 0.0E0\nC\n DO 250 K = L, N\n 250 S = S + U(J,K) * U(I,K)\nC\n DO 260 K = L, N\n U(J,K) = U(J,K) + S * RV1(K)\n 260 CONTINUE\nC\n 270 DO 280 K = L, N\n 280 U(I,K) = SCALE * U(I,K)\nC\n 290 S1 = MAX(S1,ABS(W(I))+ABS(RV1(I)))\n 300 CONTINUE\nC .......... ACCUMULATION OF RIGHT-HAND TRANSFORMATIONS ..........\n IF (.NOT. MATV) GO TO 410\nC .......... FOR I=N STEP -1 UNTIL 1 DO -- ..........\n DO 400 II = 1, N\n I = N + 1 - II\n IF (I .EQ. N) GO TO 390\n IF (G .EQ. 0.0E0) GO TO 360\nC\n DO 320 J = L, N\nC .......... DOUBLE DIVISION AVOIDS POSSIBLE UNDERFLOW ..........\n 320 V(J,I) = (U(I,J) / U(I,L)) / G\nC\n DO 350 J = L, N\n S = 0.0E0\nC\n DO 340 K = L, N\n 340 S = S + U(I,K) * V(K,J)\nC\n DO 350 K = L, N\n V(K,J) = V(K,J) + S * V(K,I)\n 350 CONTINUE\nC\n 360 DO 380 J = L, N\n V(I,J) = 0.0E0\n V(J,I) = 0.0E0\n 380 CONTINUE\nC\n 390 V(I,I) = 1.0E0\n G = RV1(I)\n L = I\n 400 CONTINUE\nC .......... ACCUMULATION OF LEFT-HAND TRANSFORMATIONS ..........\n 410 IF (.NOT. MATU) GO TO 510\nC ..........FOR I=MIN(M,N) STEP -1 UNTIL 1 DO -- ..........\n MN = N\n IF (M .LT. N) MN = M\nC\n DO 500 II = 1, MN\n I = MN + 1 - II\n L = I + 1\n G = W(I)\n IF (I .EQ. N) GO TO 430\nC\n DO 420 J = L, N\n 420 U(I,J) = 0.0E0\nC\n 430 IF (G .EQ. 0.0E0) GO TO 475\n IF (I .EQ. MN) GO TO 460\nC\n DO 450 J = L, N\n S = 0.0E0\nC\n DO 440 K = L, M\n 440 S = S + U(K,I) * U(K,J)\nC .......... DOUBLE DIVISION AVOIDS POSSIBLE UNDERFLOW ..........\n F = (S / U(I,I)) / G\nC\n DO 450 K = I, M\n U(K,J) = U(K,J) + F * U(K,I)\n 450 CONTINUE\nC\n 460 DO 470 J = I, M\n 470 U(J,I) = U(J,I) / G\nC\n GO TO 490\nC\n 475 DO 480 J = I, M\n 480 U(J,I) = 0.0E0\nC\n 490 U(I,I) = U(I,I) + 1.0E0\n 500 CONTINUE\nC .......... DIAGONALIZATION OF THE BIDIAGONAL FORM ..........\n 510 CONTINUE\nC .......... FOR K=N STEP -1 UNTIL 1 DO -- ..........\n DO 700 KK = 1, N\n K1 = N - KK\n K = K1 + 1\n ITS = 0\nC .......... TEST FOR SPLITTING.\nC FOR L=K STEP -1 UNTIL 1 DO -- ..........\n 520 DO 530 LL = 1, K\n L1 = K - LL\n L = L1 + 1\n IF (S1 + ABS(RV1(L)) .EQ. S1) GO TO 565\nC .......... RV1(1) IS ALWAYS ZERO, SO THERE IS NO EXIT\nC THROUGH THE BOTTOM OF THE LOOP ..........\n IF (S1 + ABS(W(L1)) .EQ. S1) GO TO 540\n 530 CONTINUE\nC .......... CANCELLATION OF RV1(L) IF L GREATER THAN 1 ..........\n 540 C = 0.0E0\n S = 1.0E0\nC\n DO 560 I = L, K\n F = S * RV1(I)\n RV1(I) = C * RV1(I)\n IF (S1 + ABS(F) .EQ. S1) GO TO 565\n G = W(I)\n H = PYTHAG(F,G)\n W(I) = H\n C = G / H\n S = -F / H\n IF (.NOT. MATU) GO TO 560\nC\n DO 550 J = 1, M\n Y = U(J,L1)\n Z = U(J,I)\n U(J,L1) = Y * C + Z * S\n U(J,I) = -Y * S + Z * C\n 550 CONTINUE\nC\n 560 CONTINUE\nC .......... TEST FOR CONVERGENCE ..........\n 565 Z = W(K)\n IF (L .EQ. K) GO TO 650\nC .......... SHIFT FROM BOTTOM 2 BY 2 MINOR ..........\n IF (ITS .EQ. 30) GO TO 1000\n ITS = ITS + 1\n X = W(L)\n Y = W(K1)\n G = RV1(K1)\n H = RV1(K)\n F = 0.5E0 * (((G + Z) / H) * ((G - Z) / Y) + Y / H - H / Y)\n G = PYTHAG(F,1.0E0)\n F = X - (Z / X) * Z + (H / X) * (Y / (F + SIGN(G,F)) - H)\nC .......... NEXT QR TRANSFORMATION ..........\n C = 1.0E0\n S = 1.0E0\nC\n DO 600 I1 = L, K1\n I = I1 + 1\n G = RV1(I)\n Y = W(I)\n H = S * G\n G = C * G\n Z = PYTHAG(F,H)\n RV1(I1) = Z\n C = F / Z\n S = H / Z\n F = X * C + G * S\n G = -X * S + G * C\n H = Y * S\n Y = Y * C\n IF (.NOT. MATV) GO TO 575\nC\n DO 570 J = 1, N\n X = V(J,I1)\n Z = V(J,I)\n V(J,I1) = X * C + Z * S\n V(J,I) = -X * S + Z * C\n 570 CONTINUE\nC\n 575 Z = PYTHAG(F,H)\n W(I1) = Z\nC .......... ROTATION CAN BE ARBITRARY IF Z IS ZERO ..........\n IF (Z .EQ. 0.0E0) GO TO 580\n C = F / Z\n S = H / Z\n 580 F = C * G + S * Y\n X = -S * G + C * Y\n IF (.NOT. MATU) GO TO 600\nC\n DO 590 J = 1, M\n Y = U(J,I1)\n Z = U(J,I)\n U(J,I1) = Y * C + Z * S\n U(J,I) = -Y * S + Z * C\n 590 CONTINUE\nC\n 600 CONTINUE\nC\n RV1(L) = 0.0E0\n RV1(K) = F\n W(K) = X\n GO TO 520\nC .......... CONVERGENCE ..........\n 650 IF (Z .GE. 0.0E0) GO TO 700\nC .......... W(K) IS MADE NON-NEGATIVE ..........\n W(K) = -Z\n IF (.NOT. MATV) GO TO 700\nC\n DO 690 J = 1, N\n 690 V(J,K) = -V(J,K)\nC\n 700 CONTINUE\nC\n GO TO 1001\nC .......... SET ERROR -- NO CONVERGENCE TO A\nC SINGULAR VALUE AFTER 30 ITERATIONS ..........\n 1000 IERR = K\n 1001 RETURN\n END\n", "meta": {"hexsha": "d027aa1f4a8515a2d2f3b108cd9cb0344679829f", "size": 10926, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/svd.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/svd.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/svd.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.6020942408, "max_line_length": 72, "alphanum_fraction": 0.4570748673, "num_tokens": 3877, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853655, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6760349608251615}} {"text": "module integrators\n implicit none\n contains\n\n\n function vec_mag(n_dim, rel_vec)\n integer, intent(in) :: n_dim\n real(8), dimension(n_dim), intent(in) :: rel_vec\n real(8) :: vec_mag\n vec_mag = sqrt(sum(rel_vec**2))\n end function vec_mag\n\n subroutine euler_forward(n, masses, positions, velocities, dt, g, poses, vels)\n implicit none\n integer(8), intent(in) :: n\n real(8), dimension(n), intent(in) :: masses\n real(8), dimension(3) :: rel\n real(8), dimension(n, 3), intent(in) :: positions, velocities\n real(8), intent(in) :: g\n real(8), dimension(n, 3) :: accels\n real(8), dimension(n, 3), intent(out):: poses, vels\n real(8), intent(in) :: dt\n integer(8) :: i, j\n real(8) :: rel_mag\n accels = 0.\n poses = 0.\n vels = 0.\n ! f2py intent(in) n, masses, positions, velocities, dt\n ! f2py intent(out) poses, vels\n do i=1, n\n do j=1, n\n if (i /= j) then\n if (masses(j) /= 0.) then\n rel = positions(j, :) - positions(i, :)\n rel_mag = vec_mag(3, rel)\n accels(i, :) = accels(i, :) + g * masses(j) / rel_mag**3 * rel(:)\n end if\n end if\n end do\n poses(i, :) = positions(i, :) + velocities(i, :) * dt\n vels(i, :) = velocities(i, :) + accels(i, :) * dt\n end do\n! print *, \"Accels\"\n! print *, velocities(2, :) + accels(2, :) * dt\n! poses(:, :) = positions + velocities * dt\n! vels(:, :) = velocities(:, :) + accels(:, :) * dt\n end subroutine euler_forward\n\n\n subroutine kdk(n, masses, positions, velocities, dt, g, poses, vels)\n implicit none\n integer(8), intent(in) :: n\n real(8), dimension(n), intent(in) :: masses\n real(8), dimension(3) :: rel\n real(8), dimension(n, 3), intent(in) :: positions, velocities\n real(8), dimension(n, 3) :: accels\n real(8), intent(in) :: g\n real(8), dimension(n, 3), intent(out) :: poses, vels\n integer(8) :: i, j\n real(8), intent(in) :: dt\n real(8) :: rel_mag\n rel = 0.\n rel_mag = 0.\n accels = 0.\n do i=1, n\n do j=1, n\n if (i /= j) then\n if (masses(j) /= 0) then\n rel = positions(j, :) - positions(i, :)\n rel_mag = vec_mag(3, rel)\n accels(i, :) = accels(i, :) + g * masses(j) / rel_mag**3 * rel(:)\n end if\n end if\n end do\n vels(i, :) = velocities(i, :) + accels(i, :) * dt / 2. ! Kick\n poses(i, :) = positions(i, :) + vels(i, :) * dt ! Drift\n end do\n accels = 0. ! Reset accels for second kick\n\n do i=1, n\n do j=1, n\n if (i /= j) then\n if (masses(j) /= 0) then\n rel = poses(j, :) - poses(i, :)\n rel_mag = vec_mag(3, rel)\n accels(i, :) = accels(i, :) + g * masses(j) / rel_mag**3 * rel(:)\n end if\n end if\n end do\n vels(i, :) = vels(i, :) + accels(i, :) * dt / 2. ! Kick 2\n end do\n\n end subroutine kdk\n\n\n subroutine kdk_gal(n, masses, positions, velocities, dt, g, poses, vels)\n implicit none\n integer(8), intent(in) :: n\n real(8), dimension(n), intent(in) :: masses\n real(8), dimension(3) :: rel\n real(8), dimension(n, 3), intent(in) :: positions, velocities\n real(8), intent(in) :: g\n real(8), dimension(n, 3) :: accels\n real(8), dimension(n, 3), intent(out) :: poses, vels\n integer(8) :: i\n real(8), intent(in) :: dt\n real(8) :: rel_mag\n rel = 0.\n accels = 0.\n rel_mag = 1.\n do i=1, n\n rel = positions(i, :)\n rel_mag = vec_mag(3, rel)\n accels(i, :) = (-log(1 + rel_mag) / rel_mag ** 2 + 1 / rel_mag / (1 + rel_mag)) * rel(:) / rel_mag\n! print*, accels(i, :)\n vels(i, :) = velocities(i, :) + accels(i, :) * dt / 2. ! Kick\n! print *, vels(i, :)\n poses(i, :) = positions(i, :) + vels(i, :) * dt ! Drift\n end do\n accels = 0. ! Reset accels for second kick\n\n do i=1, n\n rel = poses(i, :)\n rel_mag = vec_mag(3, rel)\n accels(i, :) = (-log(1 + rel_mag) / rel_mag ** 2 + 1 / rel_mag / (1 + rel_mag)) * rel(:) / rel_mag\n vels(i, :) = vels(i, :) + accels(i, :) * dt / 2. ! Kick 2\n end do\n\n end subroutine kdk_gal\n\n\n subroutine rk_pde(n, masses, positions, velocities, g, vels, accels)\n implicit none\n integer(8), intent(in) :: n\n real(8), dimension(n), intent(in) :: masses\n real(8), intent(in) :: g\n real(8), dimension(3) :: rel\n real(8), dimension(n, 3), intent(in) :: positions, velocities\n real(8), dimension(n, 3), intent(out) :: vels, accels\n integer(8) :: i, j\n real(8) :: rel_mag\n ! f2py intent(in) masses, positions, velocities, dt\n ! f2py intent(out) poses, vels\n vels = 0.\n accels = 0.\n\n do i=1, n\n do j=1, n\n if (i /= j) then\n if (masses(j) /= 0.) then\n rel = positions(j, :) - positions(i, :)\n! print *, \"rel and accels\", rel, accels(i, :)\n rel_mag = vec_mag(3, rel)\n accels(i, :) = accels(i, :) + g * masses(j) / rel_mag**3 * rel(:)\n! print *, \"masse and accels\", masses(i), accels(i, :)\n end if\n end if\n end do\n end do\n vels = velocities\n\n end subroutine rk_pde\n\n\n subroutine rk3_classic(n, masses, positions, velocities, dt, g, poses, vels)\n implicit none\n integer(8), intent(in) :: n\n real(8), dimension(n), intent(in) :: masses\n real(8), dimension(3) :: rel\n real(8), dimension(n, 3), intent(in) :: positions, velocities\n real(8), dimension(n, 3), intent(out) :: poses, vels\n real(8), intent(in) :: g\n integer(8) :: i, j, k, l\n real(8), intent(in) :: dt\n real(8), dimension(3, 3) :: coefficients\n real(8), dimension(4) :: weights\n real(8), dimension(4, n, 3) :: k_poses, k_vels\n real(8), dimension(n, 3) :: temp_p, temp_v\n k_poses = 0.\n k_vels = 0.\n temp_p = 0.\n temp_v = 0.\n coefficients(1, :) = (/0.5, 0., 0./)\n coefficients(2, :) = (/0., 0.5, 0./)\n coefficients(3, :) = (/0., 0., 1./)\n weights(:) = (/1., 2., 2., 1./) / 6.\n temp_p = 0.\n temp_v = 0.\n\n call rk_pde(n, masses, positions, velocities, g, &\n k_poses(1, :, :), k_vels(1, :, :))\n do i=1, 3\n temp_p = positions\n temp_v = velocities\n do l=1, i\n temp_p = temp_p + k_poses(i, :, :) * coefficients(i, l) * dt\n temp_v = temp_v + k_vels(i, :, :) * coefficients(i, l) * dt\n end do\n call rk_pde(n, masses, temp_p, temp_v, g, &\n k_poses(i + 1, :, :), k_vels(i + 1, :, :))\n end do\n\n poses = positions\n vels = velocities\n do i=1, 4\n! print \"(e22.16)\", k_poses(i, :, :)\n! print *, k_poses(i, 2, 2)\n poses(:, :) = poses(:, :) + dt * weights(i) * k_poses(i, :, :)\n vels(:, :) = vels(:, :) + dt * weights(i) * k_vels(i, :, :)\n end do\n\n end subroutine rk3_classic\n\n\n subroutine kdkrk3(n, masses, positions, velocities, dt, g, poses_low, &\n vels_low, poses_high, vels_high)\n implicit none\n integer(8), intent(in) :: n\n real(8), dimension(n), intent(in) :: masses\n real(8), dimension(3) :: rel\n real(8), dimension(n, 3), intent(in) :: positions, velocities\n ! real(8), dimension(n, 3) :: accels\n real(8), dimension(n, 3), intent(out) :: poses_low, vels_low, poses_high, &\n vels_high\n real(8), intent(in) :: g\n integer(8) :: i, j, k, l\n real(8), intent(in) :: dt\n real(8) :: rel_mag\n real(8), dimension(3, 3) :: coefficients\n real(8), dimension(4) :: weights\n real(8), dimension(4, n, 3) :: k_poses, k_vels\n real(8), dimension(n, 3) :: temp_p, temp_v\n k_poses = 0.\n k_vels = 0.\n temp_p = 0.\n temp_v = 0.\n\n coefficients(1, :) = (/0.5, 0., 0./)\n coefficients(2, :) = (/0., 0.5, 0./)\n coefficients(3, :) = (/0., 0., 1./)\n weights(:) = (/1., 2., 2., 1./) / 6.\n\n! call rk_pde(n, masses, positions, velocities, &\n! k_poses(1, :, :), k_vels(1, :, :))\n! do i=1, 5\n! temp_p = positions\n! temp_v = velocities\n! do l=1, i\n! temp_p = temp_p + k_poses(i, :, :) * coefficients(i, l) * dt\n! temp_v = temp_v + k_vels(i, :, :) * coefficients(i, l) * dt\n! end do\n! call rk_pde(n, masses, temp_p, temp_v, &\n! k_poses(i + 1, :, :), k_vels(i + 1, :, :))\n! end do\n!\n! poses_low = positions\n! vels_low = velocities\n! poses_high = positions\n! vels_high = velocities\n!\n! do i=1, 6\n! poses_low(:, :) = poses_low(:, :) + dt * weights_4(i) * k_poses(i, :, :)\n! vels_low(:, :) = vels_low(:, :) + dt * weights_4(i) * k_vels(i, :, :)\n! poses_high(:, :) = poses_high(:, :) + dt * weights_5(i) * k_poses(i, :, :)\n! vels_high(:, :) = vels_high(:, :) + dt * weights_5(i) * k_vels(i, :, :)\n! end do\n\n end subroutine kdkrk3\n\n\n subroutine rkf45(n, masses, positions, velocities, dt, g, poses_low, &\n vels_low, poses_high, vels_high)\n implicit none\n integer(8), intent(in) :: n\n real(8), dimension(n), intent(in) :: masses\n real(8), dimension(3) :: rel\n real(8), dimension(n, 3), intent(in) :: positions, velocities\n real(8), intent(in) :: g\n! real(8), dimension(n, 3) :: accels\n real(8), dimension(n, 3), intent(out) :: poses_low, vels_low, poses_high, &\n vels_high\n integer(8) :: i, j, k, l\n real(8), intent(in) :: dt\n real(8) :: rel_mag\n real(8), dimension(5, 5) :: coefficients\n real(8), dimension(6) :: weights_4, weights_5\n real(8), dimension(6, n, 3) :: k_poses, k_vels\n real(8), dimension(n, 3) :: temp_p, temp_v\n k_poses = 0.\n k_vels = 0.\n temp_p = 0.\n temp_v = 0.\n\n coefficients(1, :) = (/1. / 4., 0., 0., 0., 0./)\n coefficients(2, :) = (/3. / 32., 9. / 32., 0., 0., 0./)\n coefficients(3, :) = (/1932. / 2197., -7200. / 2197., 7296. / 2197., &\n 0., 0./)\n coefficients(4, :) = (/439. / 216., -8., 3680. / 513., -845. / 4104., &\n 0./)\n coefficients(5, :) = (/-8. / 27., 2., -3544. / 2565., 1859. / 4104., &\n -11. / 40./)\n weights_4(:) = (/25. / 216., 0., 1408. / 2565., 2197. / 4104., &\n -1. / 5., 0./)\n weights_5(:) = (/16. / 135., 0., 6656. / 12825., 28561. / 56430.,&\n -9 / 50., 2. / 55./)\n\n temp_p = 0.\n temp_v = 0.\n\n call rk_pde(n, masses, positions, velocities, g, &\n k_poses(1, :, :), k_vels(1, :, :))\n do i=1, 5\n temp_p = positions\n temp_v = velocities\n do l=1, i\n temp_p = temp_p + k_poses(i, :, :) * coefficients(i, l) * dt\n temp_v = temp_v + k_vels(i, :, :) * coefficients(i, l) * dt\n end do\n call rk_pde(n, masses, temp_p, temp_v, g, &\n k_poses(i + 1, :, :), k_vels(i + 1, :, :))\n end do\n\n poses_low = positions\n vels_low = velocities\n poses_high = positions\n vels_high = velocities\n\n do i=1, 6\n poses_low(:, :) = poses_low(:, :) + dt * weights_4(i) * k_poses(i, :, :)\n vels_low(:, :) = vels_low(:, :) + dt * weights_4(i) * k_vels(i, :, :)\n poses_high(:, :) = poses_high(:, :) + dt * weights_5(i) * k_poses(i, :, :)\n vels_high(:, :) = vels_high(:, :) + dt * weights_5(i) * k_vels(i, :, :)\n end do\n\n end subroutine rkf45\n\nend module integrators\n", "meta": {"hexsha": "d4a137460050f101924e8ed7d39a6f713f8daac9", "size": 12666, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "integrators.f90", "max_stars_repo_name": "StarkillerX42/ASTR506", "max_stars_repo_head_hexsha": "e18288e52cffde8e1611a6185cc0d797382fb559", "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": "integrators.f90", "max_issues_repo_name": "StarkillerX42/ASTR506", "max_issues_repo_head_hexsha": "e18288e52cffde8e1611a6185cc0d797382fb559", "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": "integrators.f90", "max_forks_repo_name": "StarkillerX42/ASTR506", "max_forks_repo_head_hexsha": "e18288e52cffde8e1611a6185cc0d797382fb559", "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": 37.4733727811, "max_line_length": 110, "alphanum_fraction": 0.4521553766, "num_tokens": 3945, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587934924569, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6760349563427167}} {"text": "!--------------------------------------------------------------------------------\n! Copyright (c) 2016 Peter Gr\u00fcnberg Institut, Forschungszentrum J\u00fclich, 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\n MODULE m_cylbes \n use m_juDFT\nc********************************************************************\nc generates cylindrical Bessel functions for a given x and for the orders \nc from mmax to -mmax\nc Y. Mokrousov\nc********************************************************************\n CONTAINS\n SUBROUTINE cylbes(\n > mmax,x,\n < fJ) \n\n IMPLICIT NONE\n! ..\n! ..Arguments ..\n INTEGER, INTENT (IN) :: mmax\n REAL, INTENT (IN) :: x\n REAL, INTENT (OUT) :: fJ(-mmax:mmax)\n!\n! .. Parameters ..\n REAL, PARAMETER :: zero = 0.0\n! ..Locals ..\n INTEGER :: m,i,mass\n REAL :: quot\n REAL, ALLOCATABLE :: aux(:)\n! ..\n\n IF (x.LT.zero) CALL juDFT_error(\"cylbes2\",calledby=\"cylbes\")\n\n IF (x.EQ.zero) THEN\n fJ(0) = 1.\n\n DO m=1,mmax\n fJ(m) = 0.\n fJ(-m) = 0.\n END DO\n RETURN\n END IF \n\n mass = INT( mmax + 50 + x )\n ALLOCATE ( aux(0:mass) ) \n aux(mass) = 0.0\n aux(mass-1) = 1.0e-22 \n \n DO i=mass-2,0,-1\n aux(i) = 2*(i+1)*aux(i+1)/x - aux(i+2)\n END DO\n\n quot = aux(0)\n\n DO i=1,INT( mass/2. )\n quot = quot + 2*aux(2*i)\n END DO \n\n fJ(0) = aux(0)/quot\n\n DO m=1,mmax\n fJ(m) = aux(m)/quot\n fJ(-m) = ((-1)**m)*fJ(m)\n END DO\n\n DEALLOCATE ( aux )\n\n RETURN\n END SUBROUTINE cylbes\n END MODULE m_cylbes \n \n\n\n\n\n\n", "meta": {"hexsha": "cd79c9384f1c954ac9b0ddf2054d1f3942cc74ec", "size": 1918, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "math/cylbes.f", "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/cylbes.f", "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/cylbes.f", "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": 24.2784810127, "max_line_length": 81, "alphanum_fraction": 0.4139728884, "num_tokens": 550, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853654, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6760349560028914}} {"text": " REAL FUNCTION SLAPY3( X, Y, Z )\n*\n* -- LAPACK auxiliary routine (version 3.2) --\n* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..\n* November 2006\n*\n* .. Scalar Arguments ..\n REAL X, Y, Z\n* ..\n*\n* Purpose\n* =======\n*\n* SLAPY3 returns sqrt(x**2+y**2+z**2), taking care not to cause\n* unnecessary overflow.\n*\n* Arguments\n* =========\n*\n* X (input) REAL\n* Y (input) REAL\n* Z (input) REAL\n* X, Y and Z specify the values x, y and z.\n*\n* =====================================================================\n*\n* .. Parameters ..\n REAL ZERO\n PARAMETER ( ZERO = 0.0E0 )\n* ..\n* .. Local Scalars ..\n REAL W, XABS, YABS, ZABS\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC ABS, MAX, SQRT\n* ..\n* .. Executable Statements ..\n*\n XABS = ABS( X )\n YABS = ABS( Y )\n ZABS = ABS( Z )\n W = MAX( XABS, YABS, ZABS )\n IF( W.EQ.ZERO ) THEN\n* W can be zero for max(0,nan,0)\n* adding all three entries together will make sure\n* NaN will not disappear.\n SLAPY3 = XABS + YABS + ZABS\n ELSE\n SLAPY3 = W*SQRT( ( XABS / W )**2+( YABS / W )**2+\n $ ( ZABS / W )**2 )\n END IF\n RETURN\n*\n* End of SLAPY3\n*\n END\n", "meta": {"hexsha": "309fdb7da80c4a6e94ba34fec93f0fc70a481d5f", "size": 1364, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "code_1D/couplage_1D/fortran90_source/liblapack/SRC/slapy3.f", "max_stars_repo_name": "IRFM/ALOHA", "max_stars_repo_head_hexsha": "e8e7a47a70c7095b339b3dea25dcd4b95f382959", "max_stars_repo_licenses": ["CECILL-B"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-11-12T08:42:36.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-12T08:42:41.000Z", "max_issues_repo_path": "code_1D/couplage_1D/fortran90_source/liblapack/SRC/slapy3.f", "max_issues_repo_name": "IRFM/ALOHA", "max_issues_repo_head_hexsha": "e8e7a47a70c7095b339b3dea25dcd4b95f382959", "max_issues_repo_licenses": ["CECILL-B"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-02-21T10:46:38.000Z", "max_issues_repo_issues_event_max_datetime": "2017-10-20T17:03:14.000Z", "max_forks_repo_path": "code_1D/couplage_1D/fortran90_source/liblapack/SRC/slapy3.f", "max_forks_repo_name": "IRFM/ALOHA", "max_forks_repo_head_hexsha": "e8e7a47a70c7095b339b3dea25dcd4b95f382959", "max_forks_repo_licenses": ["CECILL-B"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-10-05T12:40:02.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-12T08:41:20.000Z", "avg_line_length": 23.9298245614, "max_line_length": 72, "alphanum_fraction": 0.4406158358, "num_tokens": 414, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853654, "lm_q2_score": 0.7606506418255928, "lm_q1q2_score": 0.6760349511806215}} {"text": "datatype Pair (X:*) (Y:*) = \n Pcons of (x:X) (y:Y);;\n\nlet LTInt (hi:Int) :* = (x:Int. (x <= hi));;\n\nlet RInt (hi:Int) (lo:(LTInt hi)):* = (x:Int. (and (lo<=x) (x l2)\n (fn x y => SCons ub lb x (sortAppend ub mid x y l2));;\n\nlet rec partition (ub:Int) (lb:(LTInt ub)) (pivot:(RInt ub lb)) \n (l:(RangeList ub lb)) (l1:(RangeList pivot (lb+0)))\n (l2:(RangeList ub pivot)):\n (Pair (RangeList pivot (lb+0)) (RangeList ub pivot)) =\n caseRangeList ub lb l \n (Pair (RangeList pivot (lb+0)) (RangeList ub pivot))\n (fn u => (Pcons (RangeList pivot (lb+0)) (RangeList ub pivot) l1 l2))\n (fn x y =>\n if [(Pair (RangeList pivot (lb+0)) (RangeList ub pivot))] x >= pivot\n then (partition ub lb pivot y l1 (RCons ub pivot (x+0) l2))\n else (partition ub lb pivot y (RCons pivot (lb+0) (x+0) l1) l2));;\n\nlet rec quicksort (ub:Int) (lb:(LTInt ub)) (l:(RangeList ub lb)): \n (SortedList ub lb) =\n caseRangeList ub lb l (SortedList ub lb)\n (fn u1 => (SNull ub lb unit))\n (fn x1 y1 => \n (caseRangeList ub lb y1 (SortedList ub lb)\n (fn u2 => (SCons ub lb x1 (SNull ub x1 unit)))\n (fn x2 y2 =>\n (let pivot = x1 in \n (let pairLists = \n (partition ub lb pivot y1\n (RNull pivot (lb+0) unit) (RNull ub pivot unit)) in\n (casePair (RangeList pivot (lb+0)) (RangeList ub pivot)\n pairLists (SortedList ub lb)\n (fn x y => (sortAppend ub pivot (lb+0) \n /* BUG: switched lb and pivot */\n (quicksort (lb+0) pivot x)\n (SCons ub pivot (pivot+0) (quicksort ub pivot y))))\n ))))));;\n\n", "meta": {"hexsha": "576ddcfa7a1241c7e53c1e8cca2e628d10cafe05", "size": 2350, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/bad/quicksort.7.f", "max_stars_repo_name": "ucsc-proglang/sage", "max_stars_repo_head_hexsha": "c62165999833fb044d2d86ffb0710b917b1ddacd", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2015-01-18T14:34:40.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-11T02:06:09.000Z", "max_issues_repo_path": "tests/bad/quicksort.7.f", "max_issues_repo_name": "ucsc-proglang/sage", "max_issues_repo_head_hexsha": "c62165999833fb044d2d86ffb0710b917b1ddacd", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/bad/quicksort.7.f", "max_forks_repo_name": "ucsc-proglang/sage", "max_forks_repo_head_hexsha": "c62165999833fb044d2d86ffb0710b917b1ddacd", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.5172413793, "max_line_length": 79, "alphanum_fraction": 0.5208510638, "num_tokens": 763, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587817066391, "lm_q2_score": 0.7606506418255928, "lm_q1q2_score": 0.676034937733287}} {"text": "\nsubroutine array_division(x, a, nrow, ncol, y)\n use env_precision\n implicit none\n integer, intent(in) :: ncol, nrow\n real(r8k), intent(in) :: x(nrow, ncol)\n real(r8k), intent(in) :: a\n real(r8k), intent(out) :: y(nrow, ncol)\n integer :: i, j\n character(len=100) :: fmt1, fmt2\n\n write(6, *) \"(array_division) Input array = \"\n call print_array2d(x, nrow, ncol)\n\n do j = 1, ncol\n do i = 1, nrow\n y(i, j) = x(i, j) / a\n end do\n end do\n\nend subroutine\n\nsubroutine sub_dgemv(A, x, y, alpha, beta, nrow, ncol, res)\n implicit none\n external :: dgemv\n integer, parameter :: dp = kind(1.0d0)\n integer, intent(in) :: ncol, nrow\n real(dp), intent(in) :: alpha, beta\n real(dp), intent(in) :: A(nrow, ncol)\n real(dp), intent(in) :: x(ncol), y(nrow)\n real(dp), intent(out) :: res(nrow)\n integer :: i, j\n do i = 1, nrow\n res(i) = y(i)\n end do\n call dgemv('N', nrow, ncol, alpha, A, nrow, x, 1, beta, res, 1)\nend subroutine\n\nsubroutine sub_dgesvd(A, k, nrow, ncol, U, S, VT)\n implicit none\n external :: dgesvd\n integer, parameter :: dp = kind(1.0d0)\n integer, intent(in) :: nrow, ncol, k\n real(dp), intent(in) :: A(nrow, ncol)\n real(dp), intent(out) :: U(nrow, k), S(k), VT(k, ncol)\n\n! local variables\n integer(kind = 4) :: ldmax, lwork, info, i, j\n real(dp), allocatable :: work(:)\n real(dp) :: Acopy(nrow, ncol)\n\n do j = 1, ncol\n do i = 1, nrow\n Acopy(i, j) = A(i, j)\n end do\n end do\n\n ldmax = max(nrow, ncol)\n lwork = max(1, 3 * k + ldmax, 5 * k)\n allocate(work(lwork))\n call dgesvd('S', 'S', nrow, ncol, Acopy, nrow, S, U, nrow, VT, k, work, lwork, info) \nend subroutine\n\n\nsubroutine print_array2d(x, m, n)\n!\n! x is an input array of size (m, n)\n!\n implicit none\n integer, parameter :: dp = kind(1.0d0)\n integer, intent(in) :: m, n\n real(dp), dimension(m, n), intent(in) :: x\n character(len=100) :: fmt1\n!\n! Format for each row should be:\n! fmt1 = '(n(2X,F7.2))'\n!\n write (fmt1, '(A,I0,A)') '(', n, '(2X, F7.3))'\n write (6, fmt1) transpose(x)\n!\nend subroutine print_array2d\n\nsubroutine print_vector(x, m)\n implicit none\n integer, parameter :: dp = kind(1.0d0)\n integer, intent(in) :: m\n real(dp), dimension(m), intent(in) :: x\n character(len=100) :: fmt1\n!\n! Format for each row should be:\n! fmt1 = '(m(2X,F7.2))'\n!\n write (fmt1, '(A,I0,A)') '(', m, '(2X, F7.3))'\n write (6, fmt1) x\n!\nend subroutine print_vector\n", "meta": {"hexsha": "1ea3949b29141afdce3d4e24810dd0e5bc39422a", "size": 2582, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/fpydemo/flibs/array_handler.f95", "max_stars_repo_name": "banskt/fpydemo", "max_stars_repo_head_hexsha": "786802ea280afb9945772f656da9d139b431b2ac", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/fpydemo/flibs/array_handler.f95", "max_issues_repo_name": "banskt/fpydemo", "max_issues_repo_head_hexsha": "786802ea280afb9945772f656da9d139b431b2ac", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/fpydemo/flibs/array_handler.f95", "max_forks_repo_name": "banskt/fpydemo", "max_forks_repo_head_hexsha": "786802ea280afb9945772f656da9d139b431b2ac", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-02-03T05:40:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-03T05:40:24.000Z", "avg_line_length": 26.618556701, "max_line_length": 89, "alphanum_fraction": 0.552672347, "num_tokens": 943, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891479496521, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.6759949788861992}} {"text": "C a functional parameter is used. See the calls to relax in the main.\nc------------------------------------------------------------------------------\n subroutine init\n parameter (l=2, m=3, n=4)\nc\n real*8 a(l,m), b(m,n)\nc\n common /d/ a, b\nc\n real*8 drand\nc\n do i = 1, l\n do j = 1, m\n a(i,j) = srand(0)\n enddo\n enddo\nc\n do i = 1, m\n do j = 1, n\n b(i,j) = drand(0)\n enddo\n enddo\nc\n return\n end\nc------------------------------------------------------------------------------\n program linear\nc\n parameter (l=2, m=3, n=4)\n parameter (niter=100)\nc\n real*8 a(l,m), b(m,n)\n real*8 c(l,n)\nc\n common /d/ a, b\n common /r/ c\nc\n real*8 mean1, mean2\n external mean1, mean2\nc\n call init\nc\n call prmat(a, l, m)\n call prmat(b, m, n)\nc\n call matmul(a, b, c, l, m, n)\nc\n call prmat(c, l, n)\nc\n call relax(c, l, n, niter, mean1)\n call relax(c, l, n, niter, mean2)\nc\n call prmat(c, l, n)\nc\n stop 'end of program'\n end\nc------------------------------------------------------------------------------\n subroutine matmul(a, b, c, l, m, n)\nc\n integer l, m, n\n real*8 a(l,m), b(m,n)\n real*8 c(l,n)\n real*8 t\nc\n do i = 1, l\n do j = 1, n\n t = 0.0\n do k = 1, m\n t = t + a(i,k)*b(k,j)\n enddo\n c(i,j) = t\n enddo\n enddo\nc\n return\n end\n\nc------------------------------------------------------------------------------\n real*8 function mean1(q1, q2)\nc\n real*8 q1, q2\nc\n mean1 = 0.5*(q1+q2)\nc\n return\n end\n\nc------------------------------------------------------------------------------\n real*8 function mean2(q1, q2)\nc\n real*8 q1, q2\nc\n mean2 = 0.75*q1 + .25*q2\nc\n return\n end\n\nc------------------------------------------------------------------------------\n subroutine prmat(mat, d1, d2)\nc\n real*8 mat(d1, d2)\n integer d1, d2\nc\n do i = 1, d1\n do j = 1, d2\n write (6, 1000) i, j, mat(i,j)\n enddo\n enddo\nc\n 1000 format('i = ', i3, ' j = ', i3, ' mat(i,j) = ', e18.7)\nc\n return\n end\n\nc------------------------------------------------------------------------------\n subroutine relax(mat, d1, d2, n, f)\nc\n integer d1, d2\n real*8 mat(d1, d2)\n real*8 f\nc\n if (n .le. 0) stop 'nombre d iterations incorrect'\nc\n do iter = 1, n\n do i = 2, d1-1\n do j = 2, d2-1\n q = (mat(i-1,j)+mat(i+1,j)+mat(i,j-1)+mat(i,j+1))/4.0\n mat(i,j) = f(mat(i,j), q)\n enddo\n enddo\n enddo\nc\n return\n end\n", "meta": {"hexsha": "b6077b4ddf44e6d9966e2edf3bc9d7f067f6c32e", "size": 2786, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "packages/PIPS/validation/Syntax/linear.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/Syntax/linear.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/Syntax/linear.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.637037037, "max_line_length": 79, "alphanum_fraction": 0.3510409189, "num_tokens": 893, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891479496521, "lm_q2_score": 0.8221891261650247, "lm_q1q2_score": 0.6759949770950907}} {"text": " subroutine tmpcft\r\nc\r\nc + + + PURPOSE + + +\r\nc\r\nc Fit an air temperature curve form longterm monthly temperature data\r\nc Codes of Newton method was adapted from Li Wang\r\nc\r\nc Called from: SR WINIT\r\nc Author(s): Li Wang, Shuhui Dun, WSU\r\nc Reference in User Guide: choose minimum square root error\r\nc\r\nc Version: 2008.\r\nc Date recoded: January 07, 2008\r\nc Verified by : Joan Wu, WSU\r\nc\r\n\r\nc\r\nc\r\nc + + + KEYWORDS + + +\r\nc\r\nc + + + PARAMETERS + + +\r\n include 'pmxpln.inc'\r\nc\r\nc + + + ARGUMENT DECLARATIONS + + +\r\nc\r\nc\r\nc + + + ARGUMENT DEFINITIONS + + +\r\nc\r\nc\r\nc + + + COMMON BLOCKS + + +\r\nc\r\n include 'cobclim.inc'\r\nc Read: obmaxt, obmint\r\nc\r\n include 'ctcurv.inc'\r\nc Modify: YavgT,YampT,YpshfT,obavgT\r\nc\r\nc + + + LOCAL VARIABLES + + +\r\nc\r\n integer i,nir\r\n real Fpcal,Fmin,Mmaxt,Mmint,tol,dpshft,fsdsqe,sddsqe,ThetaT,pai\r\n real tmpfun,tday\r\nc\r\nc + + + LOCAL DEFINITIONS + + +\r\nc\r\nc Fp0, Fp1,Fpcal: function value (mean square error) of corresponding points\r\nc Fmin: minimum mean square error\r\nc tol: tolerance\r\nc Mmaxt: Maximum monthly temperature\r\nc Mmint: Minimum monthly temperature\r\nc dpshft: Delta phase shift\r\nc fsdsqe: First order derivative of the square error\r\nc sddsqe: second order derivative of the square error\r\nc\r\nc + + + SAVES + + +\r\nc\r\nc + + + SUBROUTINES CALLED + + +\r\nc\r\nc\r\nc + + + DATA INITIALIZATIONS + + +\r\n tol = 0.00001\r\n Mmaxt = -100\r\n Mmint = 100\r\n pai=acos(-1.0)\r\nc \r\nc + + + END SPECIFICATIONS + + +\r\nc\r\ncd Added by S. Dun, Jan 05, 2008\r\nc For a long term yearly average temperature in frost simulation\r\n yavgt = 0\r\nc\r\n do 10 i = 1, 12\r\n obavgt(i) = (obmaxt(i) + obmint(i))/2.0\r\n if (Mmaxt.lt.obavgt(i)) Mmaxt = obavgt(i)\r\n if (Mmint.gt.obavgt(i)) Mmint = obavgt(i)\r\n yavgt = yavgt + obavgt(i)\r\n10 continue\r\nc\r\n yavgt = yavgt/12.\r\n YampT = (Mmaxt - Mmint)/2.0\r\nc\r\n if (YpshfT.gt. 0) then\r\nc check if the Ypshft could be directly used\r\n if (tmpfun(YpshfT) .lt. 2.0) return\r\n endif\r\nc\r\nc Newton method\r\n dpshft = 1\r\n nir = 0\r\n YpshfT = 0\r\n\r\n Do while ((abs(dpshft).gt. tol).and. (nir.lt.20))\r\n\r\n fsdsqe = 0.0\r\n sddsqe = 0.0\r\n nir = nir +1\r\n\r\n Do 30 i = 1, 12\r\n tday = 15. + (i-1)* 30.5\r\n ThetaT = 2.*pai/365. *(tday-YpshfT)\r\n \r\n fsdsqe = fsdsqe -(YavgT + YampT * sin(thetaT) -obavgt(i))\r\n 1 * cos(thetaT)\r\nc\r\n sddsqe = sddsqe - 2.*pai/365.* \r\n 1 ((YavgT - obavgt(i))*sin(thetaT) - YampT*cos(2.*thetaT))\r\n30 continue\r\nc\r\n if(sddsqe .lt. 0.) then\r\n YpshfT = YpshfT + 365.0/2.0\r\n else\r\nc\r\n dpshft = - fsdsqe/sddsqe\r\n Ypshft = ypshft + dpshft\r\nc\r\n Ypshft = mod(Ypshft,365.0)\r\n if (Ypshft.lt.0) Ypshft = Ypshft + 365.0\r\n endif\r\nc \r\n40 enddo \r\nc\r\ncd The alternative method if Newton Mehtod would not converge after 20 iterations\r\n if(nir.ge.20) then\r\nc chose minimum square root error\r\n Fmin = tmpfun(0.)\r\n YpshfT = 0\r\nc\r\n do 20 i = 1, 365\r\n Fpcal = tmpfun(float(i))\r\n if (Fpcal.lt.Fmin) then\r\n Fmin = Fpcal\r\n YpshfT = i\r\n endif\r\n20 continue\r\n endif\r\n\r\n return\r\n end", "meta": {"hexsha": "c05083a0f39d459dce2982595e3b81eb3d41cb35", "size": 3585, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/wepp2010.1/tmpcft.for", "max_stars_repo_name": "jarad/dep", "max_stars_repo_head_hexsha": "fe73982f4c70039e1a31b9e8e2d9aac31502f803", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-11-26T17:49:19.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-26T17:49:19.000Z", "max_issues_repo_path": "src/wepp2010.1/tmpcft.for", "max_issues_repo_name": "jarad/dep", "max_issues_repo_head_hexsha": "fe73982f4c70039e1a31b9e8e2d9aac31502f803", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 54, "max_issues_repo_issues_event_min_datetime": "2018-12-12T18:02:31.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T19:14:25.000Z", "max_forks_repo_path": "src/wepp2010.1/tmpcft.for", "max_forks_repo_name": "akrherz/idep", "max_forks_repo_head_hexsha": "7189a26fbcec3d8c3cc7d7015107b8fb6c5f6a45", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-03-02T22:59:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-09T15:49:00.000Z", "avg_line_length": 25.9782608696, "max_line_length": 85, "alphanum_fraction": 0.5157601116, "num_tokens": 1210, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898305367525, "lm_q2_score": 0.7461390043208003, "lm_q1q2_score": 0.6759943500814631}} {"text": "FUNCTION getAccumulation( Model, Node, InputArray) RESULT(accum)\n ! provides you with most Elmer functionality\n USE DefUtils\n ! saves you from stupid errors\n IMPLICIT NONE\n ! the external variables\n !----------------------------------------------------------------------------\n TYPE(Model_t) :: Model ! the access point to everything about the model\n INTEGER :: Node ! the current Node number\n REAL(KIND=dp) :: InputArray(2) ! Contains the arguments passed to the function\n REAL(KIND=dp) :: accum ! the result \n !----------------------------------------------------------------------------\n ! internal variables\n !----------------------------------------------------------------------------\n REAL(KIND=dp) :: lapserate, ela0, dElaDt, elaT, accumulationAtSl,&\n inittime, time, elevation, cutoff, offset\n LOGICAL :: FirstTime=.TRUE.\n ! Remember this value\n SAVE FirstTime, inittime\n\n ! lets hard-code our values (if we have time we can later make them being read from SIF)\n lapserate = 11.0_dp/2750.0_dp\n ela0 = 400.0_dp\n dElaDt = -0.05_dp\n cutoff = 600.0_dp\n offset = 1500.0\n\n ! copy input (should match the arguments!)\n elevation = InputArray(1)\n time = InputArray(2)\n WRITE (Message, '(A,E10.2,A,E10.2)') \"elevation=\", elevation, \"time=\", time\n CALL INFO(\"getAccumulation\", Message, Level=9)\n\n ! store the initial time, to be sure to have relative times\n IF (FirstTime) THEN\n inittime = time\n FirstTime = .FALSE.\n END IF\n\n\n ! get change of ELA with time\n IF (time > offset) THEN\n elaT = ela0 - dElaDt * (time - offset)\n ELSE\n elaT = ela0\n END IF\n \n ! lets do the math\n accumulationAtSl = -elaT*lapserate\n IF (elevation > cutoff) elevation = cutoff\n accum = lapserate*elevation + accumulationAtSl\n\n RETURN\n\nEND FUNCTION getAccumulation\n", "meta": {"hexsha": "090c9bc26fbbbc5f0ce3e3768e67eb78e29c9a97", "size": 1820, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Testglacier-flowline/accumulation.f90", "max_stars_repo_name": "ElmerCSC/ElmerIceCourses", "max_stars_repo_head_hexsha": "6ff1011f3a1311d84699a30da9f8fc56cb984a08", "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": "Testglacier-flowline/accumulation.f90", "max_issues_repo_name": "ElmerCSC/ElmerIceCourses", "max_issues_repo_head_hexsha": "6ff1011f3a1311d84699a30da9f8fc56cb984a08", "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": "Testglacier-flowline/accumulation.f90", "max_forks_repo_name": "ElmerCSC/ElmerIceCourses", "max_forks_repo_head_hexsha": "6ff1011f3a1311d84699a30da9f8fc56cb984a08", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2022-01-30T16:26:25.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-26T14:04:56.000Z", "avg_line_length": 32.5, "max_line_length": 90, "alphanum_fraction": 0.5978021978, "num_tokens": 496, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898305367525, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6759943449671283}} {"text": " SUBROUTINE MB03QX( N, T, LDT, WR, WI, INFO )\r\nC\r\nC SLICOT RELEASE 5.5.\r\nC\r\nC Copyright (c) 2002-2012 NICONET e.V.\r\nC\r\nC PURPOSE\r\nC\r\nC To compute the eigenvalues of an upper quasi-triangular matrix.\r\nC\r\nC ARGUMENTS\r\nC\r\nC Input/Output Parameters\r\nC\r\nC N (input) INTEGER\r\nC The order of the matrix T. N >= 0.\r\nC\r\nC T (input) DOUBLE PRECISION array, dimension(LDT,N)\r\nC The upper quasi-triangular matrix T.\r\nC\r\nC LDT INTEGER\r\nC The leading dimension of the array T. LDT >= max(1,N).\r\nC\r\nC WR, WI (output) DOUBLE PRECISION arrays, dimension (N)\r\nC The real and imaginary parts, respectively, of the\r\nC eigenvalues of T. The eigenvalues are stored in the same\r\nC order as on the diagonal of T. If T(i:i+1,i:i+1) is a\r\nC 2-by-2 diagonal block with complex conjugated eigenvalues\r\nC then WI(i) > 0 and WI(i+1) = -WI(i).\r\nC\r\nC Error Indicator\r\nC\r\nC INFO INTEGER\r\nC = 0: successful exit;\r\nC < 0: if INFO = -i, the i-th argument had an illegal\r\nC value.\r\nC\r\nC CONTRIBUTOR\r\nC\r\nC A. Varga, German Aerospace Center, DLR Oberpfaffenhofen,\r\nC March 1998. Based on the RASP routine SEIG.\r\nC\r\nC ******************************************************************\r\nC .. Parameters ..\r\n DOUBLE PRECISION ZERO\r\n PARAMETER ( ZERO = 0.0D0 )\r\nC .. Scalar Arguments ..\r\n INTEGER INFO, LDT, N\r\nC .. Array Arguments ..\r\n DOUBLE PRECISION T(LDT, *), WI(*), WR(*)\r\nC .. Local Scalars ..\r\n INTEGER I, I1, INEXT\r\n DOUBLE PRECISION A11, A12, A21, A22, CS, SN\r\nC .. External Subroutines ..\r\n EXTERNAL DLANV2, XERBLA\r\nC .. Intrinsic Functions ..\r\n INTRINSIC MAX\r\nC .. Executable Statements ..\r\nC\r\n INFO = 0\r\nC\r\nC Test the input scalar arguments.\r\nC\r\n IF( N.LT.0 ) THEN\r\n INFO = -1\r\n ELSE IF( LDT.LT.MAX( 1, N ) ) THEN\r\n INFO = -3\r\n END IF\r\nC\r\n IF( INFO.NE.0 ) THEN\r\nC\r\nC Error return.\r\nC\r\n CALL XERBLA( 'MB03QX', -INFO )\r\n RETURN\r\n END IF\r\nC\r\n INEXT = 1\r\n DO 10 I = 1, N\r\n IF( I.LT.INEXT )\r\n $ GO TO 10\r\n IF( I.NE.N ) THEN\r\n IF( T(I+1,I).NE.ZERO ) THEN\r\nC\r\nC A pair of eigenvalues.\r\nC\r\n INEXT = I + 2\r\n I1 = I + 1\r\n A11 = T(I,I)\r\n A12 = T(I,I1)\r\n A21 = T(I1,I)\r\n A22 = T(I1,I1)\r\n CALL DLANV2( A11, A12, A21, A22, WR(I), WI(I), WR(I1),\r\n $ WI(I1), CS, SN )\r\n GO TO 10\r\n END IF\r\n END IF\r\nC\r\nC Simple eigenvalue.\r\nC\r\n INEXT = I + 1\r\n WR(I) = T(I,I)\r\n WI(I) = ZERO\r\n 10 CONTINUE\r\nC\r\n RETURN\r\nC *** Last line of MB03QX ***\r\n END\r\n", "meta": {"hexsha": "9707538f4d9de5d4683a4397583f98f5c93df688", "size": 2961, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "External/SLICOT/MB03QX.f", "max_stars_repo_name": "bgin/MissileSimulation", "max_stars_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2016-08-28T23:20:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-15T14:43:58.000Z", "max_issues_repo_path": "External/SLICOT/MB03QX.f", "max_issues_repo_name": "bgin/MissileSimulation", "max_issues_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-06-02T21:29:51.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-05T05:59:31.000Z", "max_forks_repo_path": "External/SLICOT/MB03QX.f", "max_forks_repo_name": "bgin/MissileSimulation", "max_forks_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-07-04T22:38:22.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-04T22:38:22.000Z", "avg_line_length": 27.1651376147, "max_line_length": 73, "alphanum_fraction": 0.4761904762, "num_tokens": 892, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898254600902, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6759943411792325}} {"text": "MODULE WAVELENGTH\n !Author: Dang Huu Chung\n\n USE GLOBAL,ONLY:RKD\n IMPLICIT NONE\n\n REAL(RKD),PRIVATE,PARAMETER :: G=9.81\n REAL(RKD),PRIVATE,PARAMETER :: PI=3.14159265358979\n\n CONTAINS\n\n FUNCTION DISRELATION(RLS,TP,HD,U,PHI) RESULT(FWL)\n !Dispersion Relation: FWL=0\n !RLS: Wave length [m]\n !TP : Wave period [s]\n !HD : Water depth [m]\n !U : Depth-average velocity [m/s]\n !PHI: Angle of (wave,current) [Rad]\n REAL(RKD) :: FWL,RLS,TP,HD,U,PHI\n FWL=(RLS/TP-U*COS(PHI))-SQRT(G*RLS/2._8/PI*TANH(2._8*PI*HD/RLS))\n END FUNCTION\n\n RECURSIVE SUBROUTINE BISEC(FUN,A0,B0,TOL,TP,HD,U,PHI,X)\n REAL(RKD),INTENT(IN) :: A0,B0,TOL,TP,HD,U,PHI\n REAL(RKD),EXTERNAL :: FUN\n REAL(RKD),INTENT(OUT) :: X\n INTEGER :: IST\n REAL(RKD) :: A,B,FA,FB,FX\n A=A0\n B=B0\n IST=1\n FA=FUN(A,TP,HD,U,PHI)\n FB=FUN(B,TP,HD,U,PHI)\n IF( FA*FB < 0 )THEN\n X=0.5*(A+B)\n FX=FUN(X,TP,HD,U,PHI)\n IF( FA*FX < 0 )THEN\n B=X\n ELSE\n A=X\n ENDIF\n IF( ABS(A-B) <= TOL )THEN\n RETURN\n ELSE\n CALL BISEC(FUN,A,B,TOL,TP,HD,U,PHI,X)\n ENDIF\n ELSEIF (FA == 0 )THEN\n X=A\n ELSEIF (FB == 0 )THEN\n X=B\n ELSE\n IST=-1\n STOP 'DISPERSION RELATION: FA.FB>0' \n ENDIF\n END SUBROUTINE BISEC\n \n FUNCTION RTBIS(FUNC,X1,X2,XACC,TP,HD,U,PHI)\n REAL(RKD) :: RTBIS,X1,X2,XACC,TP,HD,U,PHI\n REAL(RKD),EXTERNAL :: FUNC\n INTEGER :: J,JMAX\n REAL(RKD) :: DX,F,FMID,XMID\n PARAMETER (JMAX=40)\n \n FMID=FUNC(X2,TP,HD,U,PHI)\n F=FUNC(X1,TP,HD,U,PHI)\n IF( F*FMID >= 0.) PAUSE 'ROOT MUST BE BRACKETED IN RTBIS'\n IF( F<0. )THEN\n RTBIS=X1\n DX=X2-X1\n ELSE\n RTBIS=X2\n DX=X1-X2\n ENDIF\n DO J=1,JMAX\n DX=DX*.5\n XMID=RTBIS+DX\n FMID=FUNC(XMID,TP,HD,U,PHI)\n IF( FMID <= 0.)RTBIS=XMID\n IF( ABS(DX) This module contains a function to perform unit conversions\nMODULE unit_conversions\n IMPLICIT NONE\n PRIVATE\n PUBLIC convert\n\nCONTAINS\n\n !> Function that converts units from \"a\" to \"b\"\n FUNCTION convert(a,b) RESULT(res)\n USE parameters\n USE input_output\n IMPLICIT NONE\n CHARACTER(len=*), INTENT(in) :: a,b\n REAL(dp) :: res\n \n ! Femtoseconds converted to atomic units of time\n IF ( a == 'fs' .AND. b == 'au_time' ) THEN\n res = fs2s * s2autime\n ELSE IF ( a == 'au_time' .AND. b == 'fs' ) THEN\n res = 1.0_dp / ( fs2s * s2autime )\n\n ! Kelvin converted to atomic units of energy\n ELSE IF ( a == 'kelvin' .AND. b == 'au_energy' ) THEN\n res = kb * joules2au\n ELSE IF ( a == 'au_energy' .AND. b == 'kelvin' ) THEN\n res = 1.0_dp / ( kb * joules2au )\n\n ! Wavenumbers converted to atomic units of angular frequency\n ELSE IF ( a == 'wvnbr' .AND. b == 'au_ang_freq' ) THEN\n res = wvnbr2Hz/s2autime*2.0_dp*pi\n ELSE IF ( a == 'au_ang_freq' .AND. b == 'wvnbr' ) THEN\n res = 1.0_dp/(wvnbr2Hz/s2autime*2.0_dp*pi)\n\n ! Wavenumbers converted to atomic units of energy\n ELSE IF ( a == 'wvnbr' .AND. b == 'au_energy' ) THEN\n res = wvnbr2joules*joules2au\n ELSE IF ( a == 'au_energy' .AND. b == 'wvnbr' ) THEN\n res = 1.0_dp/(wvnbr2joules*joules2au)\n \n ELSE\n OPEN(UNIT=10, FILE=ERRORLOG)\n WRITE(10,*) 'Undefined unit conversion attempted, see file unit_conversions.f90'\n CLOSE(10)\n END IF\n\n END FUNCTION convert\n \nEND MODULE unit_conversions\n", "meta": {"hexsha": "fe2e178184a2ec110f5ad4085762f5453e4e2f27", "size": 1558, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mqds/src/general_src/unit_conversions.f90", "max_stars_repo_name": "jprov410/mqds", "max_stars_repo_head_hexsha": "beead5c30aac77a7ae2d07e808d8c587cdd1c3ce", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-02-08T20:58:49.000Z", "max_stars_repo_stars_event_max_datetime": "2018-08-23T02:07:17.000Z", "max_issues_repo_path": "mqds/src/general_src/unit_conversions.f90", "max_issues_repo_name": "jprov410/MQDS", "max_issues_repo_head_hexsha": "beead5c30aac77a7ae2d07e808d8c587cdd1c3ce", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-02-21T18:41:21.000Z", "max_issues_repo_issues_event_max_datetime": "2018-03-21T21:27:48.000Z", "max_forks_repo_path": "mqds/src/general_src/unit_conversions.f90", "max_forks_repo_name": "jprov410/MQDS", "max_forks_repo_head_hexsha": "beead5c30aac77a7ae2d07e808d8c587cdd1c3ce", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-02-07T20:12:07.000Z", "max_forks_repo_forks_event_max_datetime": "2019-10-01T02:33:09.000Z", "avg_line_length": 31.16, "max_line_length": 87, "alphanum_fraction": 0.6155327343, "num_tokens": 514, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869884059266, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6759704924931795}} {"text": "C LAST UPDATE 10/12/92\nC+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\nC\n SUBROUTINE SVDVAR(V,MA,NP,W,CVM,NCVM)\n IMPLICIT NONE\nC\nC Purpose: Evaluates the covariancs matrix CVM of the fit for MA\nC parameters obtained by SVDFIT. Call this routine with\nC matrices V,W as returned from SVDFIT. NP,NCVM give the\nC physical dimensions of V,W,CVM.\nC\n INTEGER MA,NP,NCVM\n REAL V(NP,NP),W(NP),CVM(NCVM,NCVM)\nC\nC Calls 0:\nC Called by: \nC\nC-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-\nC Local variables:\nC\n INTEGER MMAX\n PARAMETER(MMAX=5000)\n REAL WTI(MMAX)\n REAL SUM \n INTEGER I,J,K\nC\nC---------------------------------------------------------------------\n DO 10 I=1,MA\n WTI(I) = 0.0\n IF(W(I).NE.0.0)WTI(I) = 1.0/(W(I)*W(I))\n 10 CONTINUE\n DO 40 I=1,MA\n DO 30 J=1,I\n SUM = 0.0\n DO 20 K=1,MA\n SUM = SUM + V(I,K)*V(J,K)*WTI(K)\n 20 CONTINUE\n CVM(I,J) = SUM\n CVM(J,I) = SUM\n 30 CONTINUE\n 40 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "fae1b1e8c68c679b33671aa0e15cc3ab481a510d", "size": 1145, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "software/libs/mlib/svdvar.f", "max_stars_repo_name": "scattering-central/CCP13", "max_stars_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "software/libs/mlib/svdvar.f", "max_issues_repo_name": "scattering-central/CCP13", "max_issues_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "software/libs/mlib/svdvar.f", "max_forks_repo_name": "scattering-central/CCP13", "max_forks_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-09-05T15:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-15T11:13:45.000Z", "avg_line_length": 26.0227272727, "max_line_length": 72, "alphanum_fraction": 0.4384279476, "num_tokens": 354, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.920789673717312, "lm_q2_score": 0.7341195385342971, "lm_q1q2_score": 0.6759696903564991}} {"text": "\tSUBROUTINE OAGSPC ( gltln, slat, slon, number, dscomp, dsunif, \n +\t\t\t iret )\nC************************************************************************\nC* OAGSPC\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This subroutine computes the average minimum station spacing\t\t*\nC* and the uniform station spacing.\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* OAGSPC ( GLTLN, SLAT, SLON, NUMBER, DSCOMP, DSUNIF, IRET )\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tGLTLN (4)\tREAL\t\tGrid bounds\t\t\t*\nC*\tSLAT (NUMBER)\tREAL\t\tStation latitudes\t\t*\nC*\tSLON (NUMBER)\tREAL\t\tStation longitudes\t\t*\nC*\tNUMBER\t\tINTEGER\t\tNumber of stations\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tDSCOMP\t\tREAL\t\tAverage min station spacing\t*\nC*\tDSUNIF\t\tREAL\t\tUniform station spacing\t\t*\nC*\tIRET\t\tINTEGER\t\tReturn code\t\t\t*\nC*\t\t\t\t\t 0 = normal return\t\t*\nC*\t\t\t\t\t -9 = insufficient stations\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* M. desJardins/GSFC\t 8/85\t\t\t\t\t\t*\nC* M. desJardins/GSFC\t11/88\tGEMPAK 4.1\t\t\t\t*\nC************************************************************************\n\tINCLUDE\t\t'GEMPRM.PRM'\n\tINCLUDE\t\t'oagcmn.cmn' \nC*\n\tREAL\t\tslat (*), slon (*), gltln (*)\nC*\n\tPARAMETER\t( EPS = 1.E-10, DIST = 8., BIG = 100000. )\nC*\nC------------------------------------------------------------------------\n\tiret = 0\nC\nC*\tCheck for insufficient stations.\nC\n\tIF ( number .lt. 4 ) THEN\n\t iret = -9\n\t CALL ER_WMSG ( 'OAGRID', iret, ' ', ier )\n\t RETURN\n\tEND IF\nC\nC*\tCheck each station and find the closest station.\nC\n\tns = 0\n\tdsum = 0.\nC*\n\tDO i = 1, number\n\t tlat = slat (i)\n\t tlon = slon (i)\n\t amind = big\n\t tlatp = tlat + DIST\n\t tlatm = tlat - DIST\n\t tlonp = tlon + DIST\n\t tlonm = tlon - DIST\n\t DO j = 1, number\n\t\tIF ( i .ne. j ) THEN\n\t\t ulat = slat (j)\n\t\t ulon = slon (j)\n\t IF ( ( ulat .gt. tlatm ) .and. ( ulat .lt. tlatp ) \n +\t\t\t .and. ( ulon .gt. tlonm ) .and. \n + ( ulon .lt. tlonp ) ) THEN\n\t\t dc = COS ( ( ( tlat + ulat ) / 2. ) * DTR )\n\t\t d = ( tlat - ulat ) ** 2 + \n + ( dc * ( tlon - ulon ) ) ** 2\n\t \t IF ( ( d .lt. amind ) .and. \n + ( d .gt. EPS ) ) amind = d\n\t END IF\n\t\tEND IF\n\t END DO\nC\nC*\t Check that information is not missing.\nC\n\t IF ( amind .lt. BIG ) THEN\n\t dsum = dsum + SQRT ( amind )\n\t ns = ns + 1\n\t END IF\n\tEND DO\nC\nC*\tCheck that there are enough stations.\nC\n\tIF ( ns .lt. 2 ) THEN\n\t iret = -9\n\t CALL ER_WMSG ( 'OAGRID', iret, ' ', ier )\n\t ELSE\nC\nC*\t Compute the computed station spacing.\nC\n\t dscomp = dsum / ns\nC\nC*\t Compute the uniform station spacing.\nC\n\t dn = COS ( ( gltln (3) + gltln (1) ) * DTR / 2. )\n\t d1 = gltln (3) - gltln (1)\n\t d2 = ( gltln (4) - gltln (2) ) * dn\n\t a = 1 - number\n\t b = d1 + d2\n\t c = d1 * d2\n\t ds = SQRT ( b**2 - 4.*a*c )\n\t dsunif = ( -b - ds ) / ( 2. * a )\n\tEND IF\nC*\n\tRETURN\n\tEND\n\n", "meta": {"hexsha": "042115b2b903b3b3ab0a6fc549d2d62142cbc9f2", "size": 2936, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/programs/oa/oagrid/oagspc.f", "max_stars_repo_name": "oxelson/gempak", "max_stars_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2015-06-03T15:26:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T22:36:03.000Z", "max_issues_repo_path": "gempak/source/programs/oa/oagrid/oagspc.f", "max_issues_repo_name": "oxelson/gempak", "max_issues_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 60, "max_issues_repo_issues_event_min_datetime": "2015-05-11T21:36:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T16:22:42.000Z", "max_forks_repo_path": "gempak/source/programs/oa/oagrid/oagspc.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": 26.9357798165, "max_line_length": 73, "alphanum_fraction": 0.4594686649, "num_tokens": 1084, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896758909757, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6759696758833699}} {"text": "********************************************************************************\n! Input Variables:\n! S Amount of susceptible members at the current timestep\n! I Amount of infected members at the current timestep\n! R Amount of recovered members at the current timestep\n! beta Rate of transmission via contact\n! gamma Rate of recovery from infection\n! dt Next inter-event time\n!\n! State Variables:\n! infected Increase in infected at the current timestep\n! recovered Increase in recovered at the current timestep\n********************************************************************************\n subroutine sir(S, I, R, beta, gamma, dt)\n implicit none\n double precision S, I, R, beta, gamma, dt\n double precision infected, recovered\n\n infected = (-(beta*S*I) / (S + I + R)) * dt\n recovered = (gamma*I) * dt\n\n S = S - infected\n I = I + infected - recovered\n R = R + recovered\n end subroutine sir\n", "meta": {"hexsha": "4a9991ce1a7de15e4c550ae1a16bd4af5476ac42", "size": 1037, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/data/program_analysis/SIR-simple.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": "tests/data/program_analysis/SIR-simple.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": "tests/data/program_analysis/SIR-simple.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": 39.8846153846, "max_line_length": 80, "alphanum_fraction": 0.5149469624, "num_tokens": 206, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533126145179, "lm_q2_score": 0.7248702821204019, "lm_q1q2_score": 0.6759076957789889}} {"text": "! { dg-do run }\n! { dg-options \"-fcheck=recursion\" }\n!\n! PR fortran/39577\n!\n! Recursive but valid program\n! Contributed by Dominique Dhumieres\n!\nrecursive function fac(i) result (res)\n integer :: i, j, k, res\n k = 1\n goto 100\nentry bifac(i,j) result (res)\n k = j\n100 continue\n if (i < k) then\n res = 1\n else\n res = i * bifac(i-k,k)\n end if\nend function\n\nprogram test\ninterface\n recursive function fac(n) result (res)\n integer :: res\n integer :: n\n end function fac\n recursive function bifac(m,n) result (res)\n integer :: m, n, res\n end function bifac\nend interface\n\n print *, fac(5)\n print *, bifac(5,2)\n print*, fac(6)\n print *, bifac(6,2)\n print*, fac(0)\n print *, bifac(1,2)\nend program test\n", "meta": {"hexsha": "e68e5fc566b1b39aa5901370cb1719efb2de1de4", "size": 728, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/recursive_check_14.f90", "max_stars_repo_name": "brugger1/testsuite", "max_stars_repo_head_hexsha": "9b504db668cdeaf7c561f15b76c95d05bfdd1517", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/recursive_check_14.f90", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/recursive_check_14.f90", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 17.756097561, "max_line_length": 44, "alphanum_fraction": 0.6346153846, "num_tokens": 246, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.826711776992821, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.6758984535500118}} {"text": " SUBROUTINE MATRIX_MUL_UNROLLED (A, B, C, L, M, N)\n DIMENSION A(L,M), B(M,N), C(L,N)\n\n DO 100 K = 1, N\n DO 100 I = 1, L\n C(I,K) = 0.\n100 CONTINUE\n DO 110 J = 1, M, 4\n DO 110 K = 1, N\n DO 110 I = 1, L\n C(I,K) = C(I,K) + A(I,J) * B(J,K)\n $ + A(I,J+1) * B(J+1,K) + A(I,J+2) * B(J+2,K)\n $ + A(I,J+3) * B(J+3,K)\n110 CONTINUE\n\n RETURN\n END\n\n! Disabled for now as it requires delinearization.\n! { dg-final { scan-tree-dump-times \"number of SCoPs: 2\" 1 \"graphite\" { xfail *-*-* } } }\n", "meta": {"hexsha": "1789af5cf6b59e165484cf1ad9397866788c52f4", "size": 587, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/graphite/block-2.f", "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/graphite/block-2.f", "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/graphite/block-2.f", "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": 27.9523809524, "max_line_length": 89, "alphanum_fraction": 0.4395229983, "num_tokens": 234, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681195338728, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.6758622642802278}} {"text": "! Program to solve the two-dimensional Ising model \n! with zero external field using MPI\n! The coupling constant J = 1\n! Boltzmann's constant = 1, temperature has thus dimension energy\n! Metropolis sampling is used. Periodic boundary conditions.\n!\n! The program uses a single pseudorandom number or an array of pseudorandom\n! numbers from the uniform distribution over the range 0 \\leq x < 1.\n! The runtime-library implements the xorshift1024* random number\n! generator (RNG). This generator has a period of 2^1024 - 1, and when\n! using multiple threads up to 2^512 threads can each generate 2^512\n! random numbers before any aliasing occurs.\n! Note that in a multi-threaded program (e.g. using OpenMP directives),\n! each thread will have its own random number state. For details of the\n! seeding procedure, see the documentation for the RANDOM_SEED\n! intrinsic.\n\n\n! This module contains all constants and declarations \n! of variables read in by the function read_data. These\n! variables are used by many functions.\n\nMODULE constants\n INTEGER, PARAMETER :: dp = KIND(1.0D0)\n INTEGER, PARAMETER :: dpc = KIND((1.0D0,1.0D0))\nEND MODULE constants\n\n!\n! definition of MPI constants\n!\nMODULE mpi_constants\n INCLUDE 'mpif.h'\n INTEGER, PUBLIC :: no_intervalls, my_rank, myloop_begin, myloop_end, numprocs, ierror\n\nEND MODULE mpi_constants\n\n!\n! Main program starts here, standard Metropolis algorithm\n!\n\nPROGRAM ising2dim\n USE constants\n USE mpi_constants\n INTEGER :: n_spins, de, t, tstep, i\n INTEGER, ALLOCATABLE, DIMENSION(:,:) :: spin_matrix\n REAL(dp) :: w(-8:8), local_average(5), total_average(5)\n REAL(DP) :: initial_temp, final_temp, E, M, temp_step, temperature\n REAL(DP) :: time_start, time_end\n\n ! initialize mpi\n !\n CALL MPI_INIT(ierror)\n CALL MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, ierror )\n CALL MPI_COMM_RANK( MPI_COMM_WORLD, my_rank, ierror )\n ! Only master writes and reads to file\n IF ( my_rank == 0 ) THEN\n OPEN(UNIT=6,FILE='mc_calc.dat')\n OPEN(UNIT=5,FILE='input.dat')\n CALL read_input(n_spins, mcs, initial_temp, final_temp, temp_step)\n ENDIF\n ! Broadcats to all processes common values\n CALL MPI_Bcast(mcs, 1, MPI_INT, 0, MPI_COMM_WORLD,ierror)\n CALL MPI_Bcast(n_spins, 1, MPI_INT, 0, MPI_COMM_WORLD,ierror)\n CALL MPI_Bcast(initial_temp, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD, ierror)\n CALL MPI_Bcast(final_temp, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD, ierror)\n CALL MPI_Bcast(temp_step, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD, ierror)\n ! Find temperature step\n tstep = INT((final_temp-initial_temp)/temp_step); temperature = initial_temp\n ! Start look over time steps\n ALLOCATE(spin_matrix(n_spins,n_spins))\n ! All spins point up, cold start, we don't use temp here\n spin_matrix = 1\n time_start = MPI_Wtime()\n DO t = 1, tstep\n ! initialise energy, magnetization and array for energy changes \n w = 0.0_dp\n DO de =-8, 8, 4 \n w(de) = EXP(-de/temperature)\n ENDDO\n ! initialise array for expectation values\n total_average = 0.0_dp; local_average =0.0_dp\n CALL Metropolis(mcs, n_spins, my_rank, w, local_average, spin_matrix)\n ! collect all results\n CALL MPI_REDUCE(local_average, total_average, 5, MPI_DOUBLE_PRECISION, MPI_SUM, 0, MPI_COMM_WORLD, ierror)\n ! print results\n IF (my_rank == 0) THEN\n CALL WritetoFile(n_spins, mcs*numprocs, temperature, total_average)\n ENDIF\n ! update temp\n temperature = temperature + temp_step\n ENDDO\n DEALLOCATE(spin_matrix)\n time_end = MPI_Wtime()\n IF (my_rank == 0) THEN\n WRITE(*,*) 'Total time =', time_end-time_start,' in seconds used on number of processes = ', numprocs\n ENDIF \n CALL MPI_FINALIZE(ierror)\n\nEND PROGRAM ising2dim\n\n! read in input data\n!\nSUBROUTINE read_input(n_spins, mcs, initial_temp, final_temp, temp_step)\n USE constants\n IMPLICIT NONE\n INTEGER, INTENT(inout) :: n_spins, mcs\n REAL(dp), INTENT(inout) :: initial_temp, final_temp, temp_step\n\n ! 'Number of Monte Carlo trials, lattice, init temp, final temp and temp step\n READ(5,*) mcs, n_spins, initial_temp, final_temp, temp_step\n\nEND SUBROUTINE read_input\n!\n! function to initialise energy and magnetization\n!\nSUBROUTINE initialize(n_spins, spin_matrix, E, M)\n USE constants\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: n_spins\n INTEGER, INTENT(IN) :: spin_matrix(n_spins, n_spins)\n REAL(dp), INTENT(INOUT) :: E, M\n INTEGER :: x, y, right, left, up, down\n\n ! setup initial energy and magnetization\n DO y =1, n_spins\n DO x= 1, n_spins\n right = x+1 ; IF(x == n_spins ) right = 1 \n left = x-1 ; IF(x == 1 ) left = n_spins \n up = y+1 ; IF(y == n_spins ) up = 1 \n down = y-1 ; IF(y == 1 ) down = n_spins \n e= e-spin_matrix(x,y)*(spin_matrix(right,y)+&\n spin_matrix(left,y)+spin_matrix(x,up)+ &\n spin_matrix(x,down) )\n m = m + spin_matrix(x,y) \n ENDDO\n ENDDO\n \n e = e*0.5_dp\n\nEND SUBROUTINE initialize\n!\n! Here we perform the sampling\n!\nSUBROUTINE Metropolis(mcs, n_spins, my_rank, w, average, spin_matrix)\n USE constants\n IMPLICIT NONE\n INTEGER, INTENT(in) :: n_spins, my_rank, mcs\n INTEGER :: spins, ix, iy, deltae, right, left, up, down, allspins, cycles\n REAL(dp) :: e, m\n REAL(dp), INTENT(IN) :: w(-8:8)\n REAL(dp), INTENT(INOUT) :: average(5)\n INTEGER, INTENT(INOUT) :: spin_matrix(n_spins,n_spins)\n REAL(DP) :: RandomNumber(3)\n INTEGER :: i, n, clock\n INTEGER, DIMENSION(:), ALLOCATABLE :: seed\n INTEGER :: idum\n\n ! Initialize RNG\n CALL RANDOM_SEED(size = n)\n ALLOCATE(seed(n))\n CALL SYSTEM_CLOCK(COUNT=clock)\n seed = clock + 37 * (/ (i - 1, i = 1, n) /)-my_rank\n CALL RANDOM_SEED(PUT = seed)\n ! initialize energy, magnetic moment\n e = 0.0_dp; m = 0.0_dp\n CALL initialize(n_spins, spin_matrix, e, m)\n ! start Monte Carlo computation\n allspins = n_spins*n_spins\n DO cycles = 1, mcs\n ! loop over all spins, that is a sweep over the lattice\n DO spins =1, allspins\n CALL RANDOM_NUMBER(RandomNumber)\n ix = INT(RandomNumber(1)*n_spins)+1\n iy = INT(RandomNumber(2)*n_spins)+1\n right = ix+1 ; IF(ix == n_spins ) right = 1 \n left = ix-1 ; IF(ix == 1 ) left = n_spins \n up = iy+1 ; IF(iy == n_spins ) up = 1 \n down = iy-1 ; IF(iy == 1 ) down = n_spins \n deltae = 2*spin_matrix(ix,iy)*(spin_matrix(right,iy)+&\n spin_matrix(left,iy)+spin_matrix(ix,up)+ &\n spin_matrix(ix,down) )\n IF ( RandomNumber(3) <= w(deltae) ) THEN\n spin_matrix(ix,iy) = -spin_matrix(ix,iy) !flip one spin and accept new spin config\n m = m+2*spin_matrix(ix,iy)\n e = e+deltaE\n ENDIF\n ENDDO\n ! update expectation values\n average(1) = average(1) + e; average(2) = average(2) + e*e\n average(3) = average(3)+m; average(4) = average(4)+m*m \n average(5) = average(5)+ABS(m)\n ENDDO\n DEALLOCATE(seed)\n\nEND SUBROUTINE metropolis\n!\n! Write out , , Heat capacity and susceptibility.\n!\nSUBROUTINE WritetoFile(n_spins, mcs, temperature, average)\n USE constants\n IMPLICIT NONE\n INTEGER, INTENT(in) :: n_spins, mcs\n REAL(dp), INTENT(in) :: temperature, average(5)\n REAL(dp) :: norm, Eaverage, E2average, Maverage, M2average, Mabsaverage, &\n Evariance, Mvariance\n\n norm = 1.0_dp/mcs ! divided by total number of cycles \n Eaverage = average(1)*norm\n E2average = average(2)*norm\n Maverage = average(3)*norm\n M2average = average(4)*norm\n Mabsaverage = average(5)*norm\n ! all expectation values are per spin, divide by 1/n_spins/n_spins\n Evariance = (E2average- Eaverage*Eaverage)/n_spins/n_spins\n Mvariance = (M2average - Maverage*Maverage)/n_spins/n_spins\n WRITE(6,'(6F12.6)')temperature, Eaverage/n_spins/n_spins, Evariance/temperature/temperature, &\n Maverage/n_spins/n_spins, Mvariance/temperature, Mabsaverage/n_spins/n_spins\n\nEND SUBROUTINE WritetoFile\n\n\n\n\n\n\n\n", "meta": {"hexsha": "b81ec441bd9aacc7f3a274ca79733be0ad4dd17f", "size": 7908, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "doc/Programs/ParallelizationMPI/MPIising.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/ParallelizationMPI/MPIising.f90", "max_issues_repo_name": "dnhdang94/ComputationalPhysicsMSU", "max_issues_repo_head_hexsha": "16990c74cf06eb5b933982137f0536d669567259", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-12-04T12:55:10.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-04T12:55:10.000Z", "max_forks_repo_path": "doc/Programs/ParallelizationMPI/MPIising.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.8370044053, "max_line_length": 112, "alphanum_fraction": 0.6819676277, "num_tokens": 2458, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182186, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.6758622470909932}} {"text": " module funcs58\n\n contains\n\n function arctanII(x)\n\n real :: prevxp, presxp, pi \n \n pi = 3.1415927\n\n if (x) 2,3,3\n\n!2 stop ! instead, return a value outside plausible range (common Fortran trick)\n2 arctanII=-99\n return \n\n3 arctanII = 0.\n\n if (x - 1.) 10, 10, 5\n\n5 term = -1. / x\n arctanII = pi / 2\n goto 11\n\n10 term = x\n11 prevxp = 1.\n y = term ** 2.\n\n12 arctanII = arctanII + term\n presxp = prevxp + 2.\n\n term = -prevxp / presxp * y * term\n prevxp = presxp\n\n if(term - 0.00005) 15, 12, 12\n15 if(-term - 0.00005) 16, 12, 12\n\n16 end\n\n end module funcs58\n", "meta": {"hexsha": "dd47bee7784c8343e5a9308ee62b3f11f43a1c63", "size": 669, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "funcs58.f", "max_stars_repo_name": "ElliotAlexander/fortran-II-examples", "max_stars_repo_head_hexsha": "52ded76fb769dff056a2db59c0375d21ed13c6ce", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2018-07-24T21:48:21.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T23:58:19.000Z", "max_issues_repo_path": "funcs58.f", "max_issues_repo_name": "ElliotAlexander/fortran-II-examples", "max_issues_repo_head_hexsha": "52ded76fb769dff056a2db59c0375d21ed13c6ce", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "funcs58.f", "max_forks_repo_name": "ElliotAlexander/fortran-II-examples", "max_forks_repo_head_hexsha": "52ded76fb769dff056a2db59c0375d21ed13c6ce", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-02-18T12:28:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T12:28:24.000Z", "avg_line_length": 16.3170731707, "max_line_length": 85, "alphanum_fraction": 0.514200299, "num_tokens": 252, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680904463333, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.6758622370897021}} {"text": "program stock_volatility\n\n use mod_arrays, only: average, std, moving_average, moving_std, reverse\n use mod_io, only: read_stock, write_stock\n\n implicit none\n\n character(len=4), allocatable :: symbols(:)\n character(len=:), allocatable :: time(:)\n real, allocatable :: open(:), high(:), low(:), close(:), adjclose(:), volume(:)\n integer :: i, im, n\n\n symbols = ['AAPL', 'AMZN', 'CRAY', 'CSCO', 'HPQ ',&\n 'IBM ', 'INTC', 'MSFT', 'NVDA', 'ORCL']\n\n do n = 1, size(symbols)\n\n call read_stock('data/' // trim(symbols(n)) // '.csv', time,&\n open, high, low, close, adjclose, volume)\n\n im = size(time)\n adjclose = reverse(adjclose)\n\n if (n == 1) then\n print *, time(im) // ' through ' // time(1)\n print *, 'Symbol, Average (USD), Volatility (USD), Relative Volatility (%)'\n print *, '----------------------------------------------------------------'\n end if\n\n print *, symbols(n), average(adjclose), std(adjclose),&\n nint(std(adjclose) / average(adjclose) * 100)\n\n time = time(im:1:-1)\n\n call write_stock(trim(symbols(n)) // '_volatility.txt', time, adjclose,&\n moving_average(adjclose, 30), moving_std(adjclose, 30))\n\n end do\n\nend program stock_volatility\n", "meta": {"hexsha": "54f20b07896d74a8e74465b6d50f924cac33f95e", "size": 1226, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/stock_volatility.f90", "max_stars_repo_name": "Verolop/stock-prices", "max_stars_repo_head_hexsha": "3c5a3adb2e4ce0fba159aa98f064c2a8e3342bba", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 27, "max_stars_repo_stars_event_min_datetime": "2018-05-14T22:28:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T07:30:14.000Z", "max_issues_repo_path": "src/stock_volatility.f90", "max_issues_repo_name": "Verolop/stock-prices", "max_issues_repo_head_hexsha": "3c5a3adb2e4ce0fba159aa98f064c2a8e3342bba", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2018-05-25T17:07:00.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-06T23:49:04.000Z", "max_forks_repo_path": "src/stock_volatility.f90", "max_forks_repo_name": "Verolop/stock-prices", "max_forks_repo_head_hexsha": "3c5a3adb2e4ce0fba159aa98f064c2a8e3342bba", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2020-02-03T17:24:56.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-30T23:30:41.000Z", "avg_line_length": 29.9024390244, "max_line_length": 81, "alphanum_fraction": 0.5758564437, "num_tokens": 346, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088005554475, "lm_q2_score": 0.7279754548076478, "lm_q1q2_score": 0.6758588188317747}} {"text": "Subroutine polyleg(x,pn,dpn)\n\nimplicit none\n\ninteger,parameter :: npt=100000\ninteger\t:: n,i,nb_point,ndeg\nreal*8 :: x(:),pn(:,0:),dpn(:,0:),xm\nreal*8\t:: x2(npt),x3(npt),x4(npt),x5(npt)\nreal*8\t:: pn_1(npt),pn_2(npt),dpn_1(npt),dpn_2(npt)\n\n\nndeg=size(pn,2)-1\nnb_point=size(x)\ndo n=0,ndeg\n select case (n)\n case(0)\n pn (1:nb_point,n)= 1.d0\n dpn(1:nb_point,n)= 0.d0\n case(1)\n pn (1:nb_point,n) = x(:)\n dpn(1:nb_point,n) = 1.d0\n case(2)\n x2(1:nb_point)=x(:)*x(:)\n pn (1:nb_point,n)=1.5d0*x2(1:nb_point)-.5d0\n dpn(1:nb_point,n)=3.d0*x(:)\n case(3)\n x2(1:nb_point)=x(:)*x(:)\n x3(1:nb_point)=x2(1:nb_point)*x(:)\n pn(1:nb_point,n)=2.5d0*x3(1:nb_point)-1.5d0*x(:)\n dpn(1:nb_point,n)=7.5d0*x2(1:nb_point)-1.5d0\n case(4)\n x2(1:nb_point)=x(:)*x(:)\n x3(1:nb_point)=x2(1:nb_point)*x(:)\n x4(1:nb_point)=x3(1:nb_point)*x(:)\n pn (1:nb_point,n)=4.375d0*x4(1:nb_point)-3.75d0*x2(1:nb_point)+.375d0\n dpn(1:nb_point,n)=17.5d0*x3(1:nb_point)-7.5d0*x(:)\n case(5)\n x2(1:nb_point)=x(:)*x(:)\n x3(1:nb_point)=x2(1:nb_point)*x(:)\n x4(1:nb_point)=x3(1:nb_point)*x(:)\n x5(1:nb_point)=x4(1:nb_point)*x(:)\n pn (1:nb_point,n)=7.875d0*x5(1:nb_point) - 8.75d0*x3(1:nb_point)+1.875d0*x(:)\n dpn(1:nb_point,n)=39.375d0*x4(1:nb_point)-26.25d0*x2(1:nb_point)+1.875d0\n case default\n x2(1:nb_point)=x(:)*x(:)\n x3(1:nb_point)=x2(1:nb_point)*x(:)\n x4(1:nb_point)=x3(1:nb_point)*x(:)\n x5(1:nb_point)=x4(1:nb_point)*x(:)\n pn_2 (1:nb_point)=4.375d0*x4(1:nb_point)-3.75d0*x2(1:nb_point)+.375d0\n dpn_2(1:nb_point)=17.5d0*x3(1:nb_point)-7.5d0*x(:)\n pn_1 (1:nb_point)=7.875d0*x5(1:nb_point) - 8.75d0*x3(1:nb_point)+1.875d0*x(:)\n dpn_1(1:nb_point)=39.375d0*x4(1:nb_point)-26.25d0*x2(1:nb_point)+1.875d0\n xm=5.d0\n do i=1,n-5\n xm=xm+1.d0\n pn (1:nb_point,n)=(2.d0-1.d0/xm)*x(:)*pn_1(1:nb_point)-(1.d0-1.d0/xm)*pn_2(1:nb_point)\n dpn(1:nb_point,n)=(2.d0-1.d0/xm)*(pn_1(1:nb_point)+x(:)*dpn_1(1:nb_point))-(1.d0-1.d0/xm)*dpn_2(1:nb_point)\n pn_2 (1:nb_point)=pn_1 (1:nb_point)\n dpn_2(1:nb_point)=dpn_1(1:nb_point,n)\n pn_1 (1:nb_point)=pn (1:nb_point)\n dpn_1(1:nb_point)=dpn (1:nb_point,n)\n enddo\n end select\nenddo\n\nend subroutine polyleg\n", "meta": {"hexsha": "c02eef5f564c2e7d25f89c7e99ad83a307146e02", "size": 2318, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "dir.source/dir.imm/plegendre.f90", "max_stars_repo_name": "space-physics/transcar", "max_stars_repo_head_hexsha": "a9305bd29723beb45004a8882627fa518d8a1bb6", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-06-13T11:32:22.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-02T10:31:46.000Z", "max_issues_repo_path": "dir.source/dir.imm/plegendre.f90", "max_issues_repo_name": "scivision/transcar", "max_issues_repo_head_hexsha": "a9305bd29723beb45004a8882627fa518d8a1bb6", "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": "dir.source/dir.imm/plegendre.f90", "max_forks_repo_name": "scivision/transcar", "max_forks_repo_head_hexsha": "a9305bd29723beb45004a8882627fa518d8a1bb6", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-07-08T19:03:24.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-08T19:03:24.000Z", "avg_line_length": 34.5970149254, "max_line_length": 115, "alphanum_fraction": 0.5854184642, "num_tokens": 1147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087965937711, "lm_q2_score": 0.727975443004307, "lm_q1q2_score": 0.6758588049894461}} {"text": " SUBROUTINE TB01UD( JOBZ, N, M, P, A, LDA, B, LDB, C, LDC, NCONT,\n $ INDCON, NBLK, Z, LDZ, TAU, TOL, IWORK, DWORK,\n $ LDWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To find a controllable realization for the linear time-invariant\nC multi-input system\nC\nC dX/dt = A * X + B * U,\nC Y = C * X,\nC\nC where A, B, and C are N-by-N, N-by-M, and P-by-N matrices,\nC respectively, and A and B are reduced by this routine to\nC orthogonal canonical form using (and optionally accumulating)\nC orthogonal similarity transformations, which are also applied\nC to C. Specifically, the system (A, B, C) is reduced to the\nC triplet (Ac, Bc, Cc), where Ac = Z' * A * Z, Bc = Z' * B,\nC Cc = C * Z, with\nC\nC [ Acont * ] [ Bcont ]\nC Ac = [ ], Bc = [ ],\nC [ 0 Auncont ] [ 0 ]\nC\nC and\nC\nC [ A11 A12 . . . A1,p-1 A1p ] [ B1 ]\nC [ A21 A22 . . . A2,p-1 A2p ] [ 0 ]\nC [ 0 A32 . . . A3,p-1 A3p ] [ 0 ]\nC Acont = [ . . . . . . . ], Bc = [ . ],\nC [ . . . . . . ] [ . ]\nC [ . . . . . ] [ . ]\nC [ 0 0 . . . Ap,p-1 App ] [ 0 ]\nC\nC where the blocks B1, A21, ..., Ap,p-1 have full row ranks and\nC p is the controllability index of the pair. The size of the\nC block Auncont is equal to the dimension of the uncontrollable\nC subspace of the pair (A, B).\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC JOBZ CHARACTER*1\nC Indicates whether the user wishes to accumulate in a\nC matrix Z the orthogonal similarity transformations for\nC reducing the system, as follows:\nC = 'N': Do not form Z and do not store the orthogonal\nC transformations;\nC = 'F': Do not form Z, but store the orthogonal\nC transformations in the factored form;\nC = 'I': Z is initialized to the unit matrix and the\nC orthogonal transformation matrix Z is returned.\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The order of the original state-space representation,\nC i.e. the order of the matrix A. N >= 0.\nC\nC M (input) INTEGER\nC The number of system inputs, or of columns of B. M >= 0.\nC\nC P (input) INTEGER\nC The number of system outputs, or of rows of C. P >= 0.\nC\nC A (input/output) DOUBLE PRECISION array, dimension (LDA,N)\nC On entry, the leading N-by-N part of this array must\nC contain the original state dynamics matrix A.\nC On exit, the leading NCONT-by-NCONT part contains the\nC upper block Hessenberg state dynamics matrix Acont in Ac,\nC given by Z' * A * Z, of a controllable realization for\nC the original system. The elements below the first block-\nC subdiagonal are set to zero. The leading N-by-N part\nC contains the matrix Ac.\nC\nC LDA INTEGER\nC The leading dimension of array A. LDA >= MAX(1,N).\nC\nC B (input/output) DOUBLE PRECISION array, dimension (LDB,M)\nC On entry, the leading N-by-M part of this array must\nC contain the input matrix B.\nC On exit, the leading NCONT-by-M part of this array\nC contains the transformed input matrix Bcont in Bc, given\nC by Z' * B, with all elements but the first block set to\nC zero. The leading N-by-M part contains the matrix Bc.\nC\nC LDB INTEGER\nC The leading dimension of array B. LDB >= MAX(1,N).\nC\nC C (input/output) DOUBLE PRECISION array, dimension (LDC,N)\nC On entry, the leading P-by-N part of this array must\nC contain the output matrix C.\nC On exit, the leading P-by-N part of this array contains\nC the transformed output matrix Cc, given by C * Z.\nC\nC LDC INTEGER\nC The leading dimension of array C. LDC >= MAX(1,P).\nC\nC NCONT (output) INTEGER\nC The order of the controllable state-space representation.\nC\nC INDCON (output) INTEGER\nC The controllability index of the controllable part of the\nC system representation.\nC\nC NBLK (output) INTEGER array, dimension (N)\nC The leading INDCON elements of this array contain the\nC the orders of the diagonal blocks of Acont.\nC\nC Z (output) DOUBLE PRECISION array, dimension (LDZ,N)\nC If JOBZ = 'I', then the leading N-by-N part of this\nC array contains the matrix of accumulated orthogonal\nC similarity transformations which reduces the given system\nC to orthogonal canonical form.\nC If JOBZ = 'F', the elements below the diagonal, with the\nC array TAU, represent the orthogonal transformation matrix\nC as a product of elementary reflectors. The transformation\nC matrix can then be obtained by calling the LAPACK Library\nC routine DORGQR.\nC If JOBZ = 'N', the array Z is not referenced and can be\nC supplied as a dummy array (i.e. set parameter LDZ = 1 and\nC declare this array to be Z(1,1) in the calling program).\nC\nC LDZ INTEGER\nC The leading dimension of array Z. If JOBZ = 'I' or\nC JOBZ = 'F', LDZ >= MAX(1,N); if JOBZ = 'N', LDZ >= 1.\nC\nC TAU (output) DOUBLE PRECISION array, dimension (N)\nC The elements of TAU contain the scalar factors of the\nC elementary reflectors used in the reduction of B and A.\nC\nC Tolerances\nC\nC TOL DOUBLE PRECISION\nC The tolerance to be used in rank determination when\nC transforming (A, B). If the user sets TOL > 0, then\nC the given value of TOL is used as a lower bound for the\nC reciprocal condition number (see the description of the\nC argument RCOND in the SLICOT routine MB03OD); a\nC (sub)matrix whose estimated condition number is less than\nC 1/TOL is considered to be of full rank. If the user sets\nC TOL <= 0, then an implicitly computed, default tolerance,\nC defined by TOLDEF = N*N*EPS, is used instead, where EPS\nC is the machine precision (see LAPACK Library routine\nC DLAMCH).\nC\nC Workspace\nC\nC IWORK INTEGER array, dimension (M)\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0, DWORK(1) returns the optimal value\nC of LDWORK.\nC\nC LDWORK INTEGER\nC The length of the array DWORK.\nC LDWORK >= MAX(1, N, 3*M, P).\nC For optimum performance LDWORK should be larger.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value.\nC\nC METHOD\nC\nC Matrix B is first QR-decomposed and the appropriate orthogonal\nC similarity transformation applied to the matrix A. Leaving the\nC first rank(B) states unchanged, the remaining lower left block\nC of A is then QR-decomposed and the new orthogonal matrix, Q1,\nC is also applied to the right of A to complete the similarity\nC transformation. By continuing in this manner, a completely\nC controllable state-space pair (Acont, Bcont) is found for the\nC given (A, B), where Acont is upper block Hessenberg with each\nC subdiagonal block of full row rank, and Bcont is zero apart from\nC its (independent) first rank(B) rows.\nC All orthogonal transformations determined in this process are also\nC applied to the matrix C, from the right.\nC NOTE that the system controllability indices are easily\nC calculated from the dimensions of the blocks of Acont.\nC\nC REFERENCES\nC\nC [1] Konstantinov, M.M., Petkov, P.Hr. and Christov, N.D.\nC Orthogonal Invariants and Canonical Forms for Linear\nC Controllable Systems.\nC Proc. 8th IFAC World Congress, Kyoto, 1, pp. 49-54, 1981.\nC\nC [2] Paige, C.C.\nC Properties of numerical algorithms related to computing\nC controllablity.\nC IEEE Trans. Auto. Contr., AC-26, pp. 130-138, 1981.\nC\nC [3] Petkov, P.Hr., Konstantinov, M.M., Gu, D.W. and\nC Postlethwaite, I.\nC Optimal Pole Assignment Design of Linear Multi-Input Systems.\nC Leicester University, Report 99-11, May 1996.\nC\nC NUMERICAL ASPECTS\nC 3\nC The algorithm requires 0(N ) operations and is backward stable.\nC\nC FURTHER COMMENTS\nC\nC If the system matrices A and B are badly scaled, it would be\nC useful to scale them with SLICOT routine TB01ID, before calling\nC the routine.\nC\nC CONTRIBUTOR\nC\nC V. Sima, Katholieke Univ. Leuven, Belgium, Feb. 1998.\nC\nC REVISIONS\nC\nC V. Sima, Katholieke Univ. Leuven, Belgium, May 1999, Nov. 2003,\nC Mar. 2017.\nC A. Varga, DLR Oberpfaffenhofen, March 2002, Nov. 2003.\nC\nC KEYWORDS\nC\nC Controllability, minimal realization, orthogonal canonical form,\nC orthogonal transformation.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, ONE\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )\nC .. Scalar Arguments ..\n CHARACTER JOBZ\n INTEGER INDCON, INFO, LDA, LDB, LDC, LDWORK, LDZ, M, N,\n $ NCONT, P\n DOUBLE PRECISION TOL\nC .. Array Arguments ..\n DOUBLE PRECISION A(LDA,*), B(LDB,*), C(LDC,*), DWORK(*), TAU(*),\n $ Z(LDZ,*)\n INTEGER IWORK(*), NBLK(*)\nC .. Local Scalars ..\n LOGICAL LJOBF, LJOBI, LJOBZ\n INTEGER IQR, ITAU, J, MCRT, NBL, NCRT, NI, NJ, RANK,\n $ WRKOPT\n DOUBLE PRECISION ANORM, BNORM, FNRM, TOLDEF\nC .. Local Arrays ..\n DOUBLE PRECISION SVAL(3)\nC .. External Functions ..\n LOGICAL LSAME\n DOUBLE PRECISION DLAMCH, DLANGE\n EXTERNAL DLAMCH, DLANGE, LSAME\nC .. External Subroutines ..\n EXTERNAL DCOPY, DLACPY, DLAPMT, DLASET, DORGQR, DORMQR,\n $ MB01PD, MB03OY, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC DBLE, INT, MAX, MIN\nC ..\nC .. Executable Statements ..\nC\n INFO = 0\n LJOBF = LSAME( JOBZ, 'F' )\n LJOBI = LSAME( JOBZ, 'I' )\n LJOBZ = LJOBF.OR.LJOBI\nC\nC Test the input scalar arguments.\nC\n IF( .NOT.LJOBZ .AND. .NOT.LSAME( JOBZ, 'N' ) ) THEN\n INFO = -1\n ELSE IF( N.LT.0 ) THEN\n INFO = -2\n ELSE IF( M.LT.0 ) THEN\n INFO = -3\n ELSE IF( P.LT.0 ) THEN\n INFO = -4\n ELSE IF( LDA.LT.MAX( 1, N ) ) THEN\n INFO = -6\n ELSE IF( LDB.LT.MAX( 1, N ) ) THEN\n INFO = -8\n ELSE IF( LDC.LT.MAX( 1, P ) ) THEN\n INFO = -10\n ELSE IF( .NOT.LJOBZ .AND. LDZ.LT.1 .OR.\n $ LJOBZ .AND. LDZ.LT.MAX( 1, N ) ) THEN\n INFO = -15\n ELSE IF( LDWORK.LT.MAX( 1, N, 3*M, P ) ) THEN\n INFO = -20\n END IF\nC\n IF ( INFO.NE.0 ) THEN\nC\nC Error return.\nC\n CALL XERBLA( 'TB01UD', -INFO )\n RETURN\n END IF\nC\n NCONT = 0\n INDCON = 0\nC\nC Calculate the absolute norms of A and B (used for scaling).\nC\n ANORM = DLANGE( 'M', N, N, A, LDA, DWORK )\n BNORM = DLANGE( 'M', N, M, B, LDB, DWORK )\nC\nC Quick return if possible.\nC\n IF ( MIN( N, M ).EQ.0 .OR. BNORM.EQ.ZERO ) THEN\n IF( N.GT.0 ) THEN\n IF ( LJOBI ) THEN\n CALL DLASET( 'Full', N, N, ZERO, ONE, Z, LDZ )\n ELSE IF ( LJOBF ) THEN\n CALL DLASET( 'Full', N, N, ZERO, ZERO, Z, LDZ )\n CALL DLASET( 'Full', N, 1, ZERO, ZERO, TAU, N )\n END IF\n END IF\n DWORK(1) = ONE\n RETURN\n END IF\nC\nC Scale (if needed) the matrices A and B.\nC\n CALL MB01PD( 'S', 'G', N, N, 0, 0, ANORM, 0, NBLK, A, LDA, INFO )\n CALL MB01PD( 'S', 'G', N, M, 0, 0, BNORM, 0, NBLK, B, LDB, INFO )\nC\nC Compute the Frobenius norm of [ B A ] (used for rank estimation).\nC\n FNRM = DLANGE( 'F', N, M, B, LDB, DWORK )\nC\n TOLDEF = TOL\n IF ( TOLDEF.LE.ZERO ) THEN\nC\nC Use the default tolerance in controllability determination.\nC\n TOLDEF = DBLE( N*N )*DLAMCH( 'Precision' )\n END IF\nC\n IF ( FNRM.LT.TOLDEF )\n $ FNRM = ONE\nC\n WRKOPT = 1\n NI = 0\n ITAU = 1\n NCRT = N\n MCRT = M\n IQR = 1\nC\nC (Note: Comments in the code beginning \"Workspace:\" describe the\nC minimal amount of real workspace needed at that point in the\nC code, as well as the preferred amount for good performance.\nC NB refers to the optimal block size for the immediately\nC following subroutine, as returned by ILAENV.)\nC\n 10 CONTINUE\nC\nC Rank-revealing QR decomposition with column pivoting.\nC The calculation is performed in NCRT rows of B starting from\nC the row IQR (initialized to 1 and then set to rank(B)+1).\nC Workspace: 3*MCRT.\nC\n CALL MB03OY( NCRT, MCRT, B(IQR,1), LDB, TOLDEF, FNRM, RANK,\n $ SVAL, IWORK, TAU(ITAU), DWORK, INFO )\nC\n IF ( RANK.NE.0 ) THEN\n NJ = NI\n NI = NCONT\n NCONT = NCONT + RANK\n INDCON = INDCON + 1\n NBLK(INDCON) = RANK\nC\nC Premultiply and postmultiply the appropriate block row\nC and block column of A by Q' and Q, respectively.\nC Workspace: need NCRT;\nC prefer NCRT*NB.\nC\n CALL DORMQR( 'Left', 'Transpose', NCRT, NCRT, RANK,\n $ B(IQR,1), LDB, TAU(ITAU), A(NI+1,NI+1), LDA,\n $ DWORK, LDWORK, INFO )\n WRKOPT = MAX( WRKOPT, INT( DWORK(1) ) )\nC\nC Workspace: need N;\nC prefer N*NB.\nC\n CALL DORMQR( 'Right', 'No transpose', N, NCRT, RANK,\n $ B(IQR,1), LDB, TAU(ITAU), A(1,NI+1), LDA,\n $ DWORK, LDWORK, INFO )\n WRKOPT = MAX( WRKOPT, INT( DWORK(1) ) )\nC\nC Postmultiply the appropriate block column of C by Q.\nC Workspace: need P;\nC prefer P*NB.\nC\n CALL DORMQR( 'Right', 'No transpose', P, NCRT, RANK,\n $ B(IQR,1), LDB, TAU(ITAU), C(1,NI+1), LDC,\n $ DWORK, LDWORK, INFO )\n WRKOPT = MAX( WRKOPT, INT( DWORK(1) ) )\nC\nC If required, save transformations.\nC\n IF ( LJOBZ.AND.NCRT.GT.1 ) THEN\n CALL DLACPY( 'L', NCRT-1, MIN( RANK, NCRT-1 ),\n $ B(IQR+1,1), LDB, Z(NI+2,ITAU), LDZ )\n END IF\nC\nC Zero the subdiagonal elements of the current matrix.\nC\n IF ( RANK.GT.1 )\n $ CALL DLASET( 'L', RANK-1, RANK-1, ZERO, ZERO, B(IQR+1,1),\n $ LDB )\nC\nC Backward permutation of the columns of B or A.\nC\n IF ( INDCON.EQ.1 ) THEN\n CALL DLAPMT( .FALSE., RANK, M, B(IQR,1), LDB, IWORK )\n IQR = RANK + 1\n FNRM = DLANGE( 'F', N, N, A, LDA, DWORK )\n ELSE\n DO 20 J = 1, MCRT\n CALL DCOPY( RANK, B(IQR,J), 1, A(NI+1,NJ+IWORK(J)),\n $ 1 )\n 20 CONTINUE\n END IF\nC\n ITAU = ITAU + RANK\n IF ( RANK.NE.NCRT ) THEN\n MCRT = RANK\n NCRT = NCRT - RANK\n CALL DLACPY( 'G', NCRT, MCRT, A(NCONT+1,NI+1), LDA,\n $ B(IQR,1), LDB )\n CALL DLASET( 'G', NCRT, MCRT, ZERO, ZERO,\n $ A(NCONT+1,NI+1), LDA )\n GO TO 10\n END IF\n END IF\nC\nC If required, accumulate transformations.\nC Workspace: need N; prefer N*NB.\nC\n IF ( LJOBI ) THEN\n CALL DORGQR( N, N, ITAU-1, Z, LDZ, TAU, DWORK,\n $ LDWORK, INFO )\n WRKOPT = MAX( WRKOPT, INT( DWORK(1) ) )\n END IF\nC\nC Annihilate the trailing blocks of B.\nC\n IF( IQR.LE.N )\n $ CALL DLASET( 'G', N-IQR+1, M, ZERO, ZERO, B(IQR,1), LDB )\nC\nC Annihilate the trailing elements of TAU, if JOBZ = 'F'.\nC\n IF ( LJOBF ) THEN\n DO 30 J = ITAU, N\n TAU(J) = ZERO\n 30 CONTINUE\n END IF\nC\nC Undo scaling of A and B.\nC\n IF ( INDCON.LT.N ) THEN\n NBL = INDCON + 1\n NBLK(NBL) = N - NCONT\n ELSE\n NBL = 0\n END IF\n CALL MB01PD( 'U', 'H', N, N, 0, 0, ANORM, NBL, NBLK, A, LDA,\n $ INFO )\n CALL MB01PD( 'U', 'G', NBLK(1), M, 0, 0, BNORM, 0, NBLK, B, LDB,\n $ INFO )\nC\nC Set optimal workspace dimension.\nC\n DWORK(1) = WRKOPT\n RETURN\nC *** Last line of TB01UD ***\n END\n", "meta": {"hexsha": "ac9f5b1bce21ade8f0d6a19a09460ddce152fdc1", "size": 17363, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/TB01UD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/TB01UD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/TB01UD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 36.248434238, "max_line_length": 72, "alphanum_fraction": 0.5420722225, "num_tokens": 5241, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9489172587090974, "lm_q2_score": 0.7122321842389469, "lm_q1q2_score": 0.6758494118324142}} {"text": "! Copyright (C) 2002 Regents of the University of Michigan, portions used with permission \n! For more information, see http://csem.engin.umich.edu/tools/swmf\nmodule ModConstants\n\n!-------------------------------------------------------------------\n! Useful physical constants\n!-------------------------------------------------------------------\n\n real, parameter :: Avogadros_Number = 6.02e23 ! mol./mole\n real, parameter :: AMU = 1.6726e-27 ! Kg\n real, parameter :: Mass_Ion = 1.6726e-27 ! Kg\n real, parameter :: Mass_Proton = Mass_Ion ! Kg\n real, parameter :: Mass_Electron = 9.1094e-31 ! Kg\n real, parameter :: Boltzmanns_Constant = 1.3807e-23 ! J/K\n real, parameter :: Planck_Constant = 6.6261e-34 ! Js\n real, parameter :: Element_Charge = 1.6022e-19 ! C (J/eV)\n real, parameter :: Speed_Light = 2.9979e8 ! m/s\n real, parameter :: Univ_Gas_Constant = Avogadros_Number* &\n Boltzmanns_Constant ! J/(moleK)\n real, parameter :: RGAS = Univ_Gas_Constant* &\n 1.0E+07 !erg/(moleK)\n real, parameter :: pi = 3.141592653589793\n real, parameter :: twopi = 2*pi\n\n real, parameter :: P00 = 1.0e5 ! Pa\n real, parameter :: T00 = 273.0 ! K\n\n real, parameter :: SpecificHeatVolume = 3./2.\n real, parameter :: SpecificHeatPressure = SpecificHeatVolume + 1.0\n real, parameter :: Gamma_const = &\n SpecificHeatPressure/SpecificHeatVolume\n\nend module ModConstants\n", "meta": {"hexsha": "df56066e61f205f758c5c1c5dcc499344d1e73d3", "size": 1816, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "models/gitm/GITM2/src/ModConstants.f90", "max_stars_repo_name": "hkershaw-brown/feature-preprocess", "max_stars_repo_head_hexsha": "fe2bd77b38c63fa0566c83ebc4d2fac1623aef66", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 65, "max_stars_repo_stars_event_min_datetime": "2019-10-16T13:31:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-14T11:52:58.000Z", "max_issues_repo_path": "models/gitm/GITM2/src/ModConstants.f90", "max_issues_repo_name": "hkershaw-brown/feature-preprocess", "max_issues_repo_head_hexsha": "fe2bd77b38c63fa0566c83ebc4d2fac1623aef66", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 283, "max_issues_repo_issues_event_min_datetime": "2019-09-23T15:48:34.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:44:41.000Z", "max_forks_repo_path": "models/gitm/GITM2/src/ModConstants.f90", "max_forks_repo_name": "hkershaw-brown/feature-preprocess", "max_forks_repo_head_hexsha": "fe2bd77b38c63fa0566c83ebc4d2fac1623aef66", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 67, "max_forks_repo_forks_event_min_datetime": "2019-09-19T22:13:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-20T15:58:26.000Z", "avg_line_length": 53.4117647059, "max_line_length": 91, "alphanum_fraction": 0.4774229075, "num_tokens": 451, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110396870287, "lm_q2_score": 0.7577943822145998, "lm_q1q2_score": 0.6758093958717919}} {"text": "MODULE volterra \n\n! Subroutines for volterra integral equations using dsplines \n\nUSE dspline\n\nUSE SpecFuns \n\nIMPLICIT NONE \n\nCONTAINS\n\n SUBROUTINE buildcofs(q,nnodes,tspan,Ker,m,dt,c)\n!\n! Build the coefficients of the dspline implicit time stepping\n! scheme for the Volterra equation\n!\n! u(t)+int_0^tspan Ker(s)*u(t-s) ds = f(t)\n!\n! Assuming u,f=0 t <= -tspan\n!\n! Time integral using Gaussian quadrature with nnodes \n!\n INTEGER, INTENT(IN) :: q,nnodes,m ! Choose (m-q-1)*dt = tspan\n DOUBLE PRECISION, INTENT(IN) :: tspan \n DOUBLE PRECISION, DIMENSION(0:m), INTENT(OUT) :: c\n DOUBLE PRECISION, INTENT(OUT) :: dt\n INTERFACE\n DOUBLE PRECISION FUNCTION Ker(t)\n DOUBLE PRECISION, INTENT(IN) :: t\n END FUNCTION Ker\n END INTERFACE \n!\n DOUBLE PRECISION, DIMENSION(0:nnodes) :: s,w,uwgts\n DOUBLE PRECISION, DIMENSION(nnodes+1) :: z\n DOUBLE PRECISION, DIMENSION(:,:), ALLOCATABLE :: umat,upmat\n INTEGER :: jmax,jmin,j,jr,k \n!\n dt=tspan/DBLE(m-q-1)\n CALL GaussQCofs(s,w,nnodes) \n s=.5d0*tspan*(s+1.d0)\n w=.5d0*tspan*w \n!\n! Compute weights\n!\n DO j=0,nnodes\n jr=nnodes-j\n uwgts(jr)=Ker(s(j))*w(j)\n z(jr+1)=-s(j)\n END DO\n!\n! Compute interpolation matrix\n!\n CALL InterpMat(nnodes+1,z,dt,2*q,jmax,jmin,umat,upmat)\n!\n c=0.d0\n DO j=1,jmax-jmin+1\n jr=j+m+jmin-jmax-1\n DO k=0,nnodes\n c(jr)=c(jr)+umat(k+1,j)*uwgts(k)\n END DO\n END DO\n c(m)=c(m)+1.d0 \n!\n! DO j=0,m\n! PRINT *,j,c(j) \n! END DO \n DEALLOCATE(umat,upmat)\n!\n END SUBROUTINE BuildCofs\n!\nEND MODULE volterra \n\n\n", "meta": {"hexsha": "3f1005cc69c42b6c60b0ad127dfec2166573d86f", "size": 1513, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "timedomainwaveeqn/timeinterp/volterra.f90", "max_stars_repo_name": "ahbarnett/BIE3D", "max_stars_repo_head_hexsha": "12f35cecc97d6a106540e54a2a875b66ea6eebc7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2018-12-06T03:34:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-30T01:40:08.000Z", "max_issues_repo_path": "timedomainwaveeqn/timeinterp/volterra.f90", "max_issues_repo_name": "ahbarnett/BIE3D", "max_issues_repo_head_hexsha": "12f35cecc97d6a106540e54a2a875b66ea6eebc7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "timedomainwaveeqn/timeinterp/volterra.f90", "max_forks_repo_name": "ahbarnett/BIE3D", "max_forks_repo_head_hexsha": "12f35cecc97d6a106540e54a2a875b66ea6eebc7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2019-03-03T22:57:27.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-08T19:56:33.000Z", "avg_line_length": 20.1733333333, "max_line_length": 64, "alphanum_fraction": 0.6576338401, "num_tokens": 558, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379296, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.675809395351604}} {"text": " PROGRAM xqrsolv\r\nC driver for routine qrsolv\r\n INTEGER NP\r\n PARAMETER (NP=20)\r\n REAL a(NP,NP),ai(NP,NP),b(NP,NP),c(NP),d(NP),x(NP)\r\n INTEGER j,k,l,m,n\r\n CHARACTER txt*3\r\n LOGICAL sing\r\n open(7,file='MATRX1.DAT',status='old')\r\n read(7,*)\r\n10 read(7,*)\r\n read(7,*) n,m\r\n read(7,*)\r\n read(7,*) ((a(k,l), l=1,n), k=1,n)\r\n read(7,*)\r\n read(7,*) ((b(k,l), k=1,n), l=1,m)\r\nC save matrix a for later testing\r\n do 12 l=1,n\r\n do 11 k=1,n\r\n ai(k,l)=a(k,l)\r\n11 continue\r\n12 continue\r\nC do qr decomposition\r\n call qrdcmp(a,n,NP,c,d,sing)\r\n if (sing) write(*,*) 'Singularity in QR decomposition.'\r\nC solve equations for each right-hand vector\r\n do 16 k=1,m\r\n do 13 l=1,n\r\n x(l)=b(l,k)\r\n13 continue\r\n call qrsolv(a,n,NP,c,d,x)\r\nC test results with original matrix\r\n write(*,*) 'Right-hand side vector:'\r\n write(*,'(1x,6f12.6)') (b(l,k), l=1,n)\r\n write(*,*) 'Result of matrix applied to sol''n vector'\r\n do 15 l=1,n\r\n b(l,k)=0.0\r\n do 14 j=1,n\r\n b(l,k)=b(l,k)+ai(l,j)*x(j)\r\n14 continue\r\n15 continue\r\n write(*,'(1x,6f12.6)') (b(l,k), l=1,n)\r\n write(*,*) '***********************************'\r\n16 continue\r\n write(*,*) 'Press RETURN for next problem:'\r\n read(*,*)\r\n read(7,'(a3)') txt\r\n if (txt.ne.'END') goto 10\r\n close(7)\r\n END\r\n", "meta": {"hexsha": "26276cb181bd04e8ba5599dda4afbf63cdafb7d4", "size": 1494, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xqrsolv.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xqrsolv.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xqrsolv.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.2941176471, "max_line_length": 63, "alphanum_fraction": 0.4678714859, "num_tokens": 505, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.675809394831416}} {"text": "! fortran_free_source\n!\n! This module is part of Perfcode, written by Bradley J Eck\n!\nMODULE geom_funcs\nimplicit none\ncontains\n!\n! 1. Function F_L_xi\n! 2. Function unmap_x\n! 3. Function unmap_y\n\n!===========================================================================\n! \\\\\\\\\\\\\\\\\\\\ B E G I N F U N C T I O N //////////\n! ////////// F _ L _ X I \\\\\\\\\\\\\\\\\\\\\n!===========================================================================\nFunction F_L_xi(xi, eta, seg) Result(L_xi) \n! Computes the METRIC COEFFICIENT for the length mapping.\n!Function F_length_xi(xi, eta, xcc1, ycc1, dx, dy, R1, dR, W, theta1, dtheta)\n! GEOMETRY MAPPING FUNCTIONS from Geometry.xlsb\nuse shared, only: CLSEG\nimplicit none\n! Arguments\nreal xi, eta \ntype(CLSEG) :: seg\n! Result\nreal L_xi\n! Internal Variables\nreal angle, dx_dxi, dy_dxi\nreal xcc1, ycc1, dx, dy, R1, dR, W, theta1, dtheta\n!------------------------------------------------------------------------\n! Assign parts of the derived type to local variables\n! to keep the formulas cleaner\nxcc1 = seg%xcc1\nycc1 = seg%ycc1\ndx = seg%dx\ndy = seg%dy\nR1 = seg%R1\ndR = seg%dR\nW = seg%W\ntheta1 = seg%theta1\ndtheta = seg%dtheta\n\n! compute intermediate variables\nAngle = theta1 + xi * dtheta\n\ndx_dxi = dx + dR * Cos(Angle) - dtheta * Sin(Angle) * &\n (R1 + W * (eta - 0.5) + xi * dR)\n\ndy_dxi = dx + dR * Sin(Angle) + dtheta * Cos(Angle) * &\n (R1 + W * (eta - 0.5) + xi * dR)\n \n! Calculate metric coefficient\nL_xi = sqrt( (dx_dxi ** 2 + dy_dxi ** 2) )\n!---------------------------------------------------------------------------\nEnd Function F_L_xi\n!===========================================================================\n! \\\\\\\\\\\\\\\\\\\\ E N D F U N C T I O N //////////\n! ////////// F _ L _ X I \\\\\\\\\\\\\\\\\\\\\n!===========================================================================\n\n\n!===========================================================================\n! \\\\\\\\\\\\\\\\\\\\ B E G I N F U N C T I O N //////////\n! ////////// U N M A P _ X \\\\\\\\\\\\\\\\\\\\\n!===========================================================================\nFunction unmap_x(xi, eta, seg) Result( X )\n! Calculates the physical X coordinate of a point in the grid based on \n! its xi and eta coordinates.\nuse shared, only: CLSEG\nimplicit none\n! Arguments\nreal xi, eta \ntype(CLSEG) :: seg\n! Result\nreal X\n! Internal Variables\nreal xcc1, dx, R1, dR, W, theta1, dtheta\n!------------------------------------------------------------------------\n! Assign parts of the derived type to local variables\n! to keep the formulas cleaner\nxcc1 = seg%xcc1\ndx = seg%dx\nR1 = seg%R1\ndR = seg%dR\nW = seg%W\ntheta1 = seg%theta1\ndtheta = seg%dtheta\n\n! Compute the X coordinate\nX = (xcc1 + xi * dx) + &\n (R1 + xi * dR + (eta - 0.5) * W) * Cos(theta1 + xi * dtheta)\n\n!------------------------------------------------------------------------\nend function unmap_x\n!===========================================================================\n! \\\\\\\\\\\\\\\\\\\\ E N D F U N C T I O N //////////\n! ////////// U N M A P _ X \\\\\\\\\\\\\\\\\\\\\n!===========================================================================\n\n\n!===========================================================================\n! \\\\\\\\\\\\\\\\\\\\ B E G I N F U N C T I O N //////////\n! ////////// U N M A P _ Y \\\\\\\\\\\\\\\\\\\\\n!===========================================================================\nFunction unmap_y(xi, eta, seg) result( Y )\n! Calculates the physical Y coordinate of a point on the grid\n! from its computational xi,eta coordinate\nuse shared, only: CLSEG\nimplicit none\nreal xi, eta \ntype(CLSEG) :: seg\n! Result\nreal Y\n! Internal Variables\nreal ycc1, dy, R1, dR, W, theta1, dtheta\n!------------------------------------------------------------------------\n! Assign parts of the derived type to local variables\n! to keep the formulas cleaner\nycc1 = seg%ycc1\ndy = seg%dy\nR1 = seg%R1\ndR = seg%dR\nW = seg%W\ntheta1 = seg%theta1\ndtheta = seg%dtheta\n\n\nY = (ycc1 + xi * dy) + &\n (R1 + xi * dR + (eta - 0.5) * W) * Sin(theta1 + xi * dtheta)\n\n!------------------------------------------------------------------------\nend function unmap_y\n!===========================================================================\n! \\\\\\\\\\\\\\\\\\\\ E N D F U N C T I O N //////////\n! ////////// U N M A P _ Y \\\\\\\\\\\\\\\\\\\\\n!===========================================================================\n\n\nEND MODULE geom_funcs\n", "meta": {"hexsha": "f672e2ad54e0a529ca1680fabf8199edc93d490a", "size": 4774, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/geom_funcs.f95", "max_stars_repo_name": "bradleyjeck/Perfcode", "max_stars_repo_head_hexsha": "13495f27f8492467f07caaa0c26ee3aee1f1c817", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/geom_funcs.f95", "max_issues_repo_name": "bradleyjeck/Perfcode", "max_issues_repo_head_hexsha": "13495f27f8492467f07caaa0c26ee3aee1f1c817", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/geom_funcs.f95", "max_forks_repo_name": "bradleyjeck/Perfcode", "max_forks_repo_head_hexsha": "13495f27f8492467f07caaa0c26ee3aee1f1c817", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.8581560284, "max_line_length": 77, "alphanum_fraction": 0.3753665689, "num_tokens": 1194, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850093037731, "lm_q2_score": 0.7217432182679956, "lm_q1q2_score": 0.6757573558309854}} {"text": "! ----------------------------------------------------------------------\n!\n! this subroutine computes the local energy and potential energy\n! of a configuration.\n!\n! ----------------------------------------------------------------------\n\n subroutine local(ndim,ntraj,x, env, dv)\n\n implicit double precision (a-h, o-z)\n\n real (kind = 8) x(ndim,ntraj) \n\n real*8, intent(out) :: env(ntraj),dv(ndim,ntraj)\n \n ak1 = 5.0 \n ak2 = 15.0 \n b = 0.5d0 \n v0 = 16d0 \n g = 1.3624d0 \n \n do i=1,ntraj \n\n ak = 0.5*(ak1+ak2)+0.5*(ak2-ak1)*tanh(b*x(2,i))\n\n env(i) = 0.5*ak*x(1,i)**2 + v0/cosh(g*x(2,i))**2 \n \n dv(1,i) = ak*x(1,i) \n dv(2,i) = x(1,i)**2*(ak2-ak1)*(1d0-tanh(b*x(2,i))**2)*b/4d0- & \n 2d0*v0*g*sinh(g*x(2,i))/cosh(g*x(2,i))**3\n enddo \n \n \n return\n end subroutine\n\n", "meta": {"hexsha": "4176f06ebd29337753506c37c437ef04751e0c9c", "size": 898, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "QTM/MixQC/1.0.7/dom8_3000_0.05/derivs.f90", "max_stars_repo_name": "binggu56/qmd", "max_stars_repo_head_hexsha": "e2628710de15f8a8b9a1280fcf92f9e87559414c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "QTM/MixQC/1.0.7/dom8_3000_0.05/derivs.f90", "max_issues_repo_name": "binggu56/qmd", "max_issues_repo_head_hexsha": "e2628710de15f8a8b9a1280fcf92f9e87559414c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "QTM/MixQC/1.0.7/dom8_3000_0.05/derivs.f90", "max_forks_repo_name": "binggu56/qmd", "max_forks_repo_head_hexsha": "e2628710de15f8a8b9a1280fcf92f9e87559414c", "max_forks_repo_licenses": ["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.2702702703, "max_line_length": 72, "alphanum_fraction": 0.3930957684, "num_tokens": 306, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362849986365571, "lm_q2_score": 0.7217431943271999, "lm_q1q2_score": 0.6757573257165868}} {"text": "!->Copyright by The University of Michigan, Aerospace Department. 2003\n!\n!->Module LIB_LU. Rafa Palacios. 22Jun2003\n!\n!->Description.-\n!\n! Matrix operations using LU decomposition.\n!\n!->Subroutines.-\n!\n! lu_bksubs: LU back-substitution.\n! lu_decomp: LU decomposition of a general square matrix.\n! lu_determ: Determinant of a square matrix.\n! lu_invers: Inversion of a square matrix.\n! lu_sparse: Inverse of Sparse matrix/vector product\n!\n!-> Modifications.-\n! 20120317 A.Da Ronch Subroutine lu_sparse added\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nmodule lib_lu\n implicit none\n!\n! (There are no public variables in this module).\n!\n contains\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!->Subroutine LU_BKSUBS.\n!\n!->Description.-\n!\n! Solves the set of N linear equations A\ufffdX=B. A is given by its LU decomposition.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n subroutine lu_bksubs (A, INDX, B)\n!\n!-> I/O Variables.\n!\n real(8), intent(in) :: A(:,:)\n integer, intent(in) :: INDX(:)\n real(8), intent(inout):: B(:)\n!\n!-> Local Variables.\n!\n integer :: N ! Size of the matrices.\n integer :: I, II, LL, J\n real(8) :: Sum\n!\n n= size(A,1)\n!\n II = 0\n DO I = 1, N\n LL = INDX(I)\n SUM = B(LL)\n B(LL) = B(I)\n IF(II.NE.0)THEN\n DO J = II, I-1\n SUM = SUM - A(I, J)*B(J)\n END DO\n ELSEIF(abs(SUM)>1e-20)THEN\n II = I\n ENDIF\n B(I) = SUM\n END DO\n!\n DO I = N, 1, -1\n SUM = B(I)\n IF(I.LT.N)THEN\n DO J = I+1, N\n SUM = SUM - A(I, J)*B(J)\n END DO\n ENDIF\n B(I) = SUM/A(I, I)\n END DO\n!\n return\n end subroutine lu_bksubs\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!->Subroutine LU_DECOMP.\n!\n!->Description.-\n!\n! LU Decomposition of a NxN Matrix.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n subroutine lu_decomp (A, INDX, D)\n!\n!-> I/O Variables.\n!\n real(8), intent(inout):: A(:,:)\n integer, intent(out) :: INDX(:)\n real(8), intent(out) :: D\n!\n!-> Local Variables.\n!\n integer :: i,j,k ! Counters.\n integer :: imax ! Max Counter.\n integer :: N ! Size of the matrices.\n real(8) :: Aamax, Sum, Dum\n real(8), allocatable :: VV (:) ! Stores the implicit scaling of each row.\n!\n real(8), parameter :: Tiny=1.0d-20 ! Small number.\n!\n!\n n= size(A,1)\n allocate (VV(N))\n imax = 0\n!\n D = 1.0\n DO I = 1, N\n AAMAX = 0.0\n DO J = 1, N\n IF(ABS(A(I,J)).GT.AAMAX) AAMAX=ABS(A(I,J))\n END DO\n IF(abs(AAMAX) 1e12) then\n ! open(unit=2, file='matrix.txt', ACTION=\"write\", STATUS=\"replace\")\n ! print*, 'UPPPSSSSS'\n ! do i=1, n\n ! write(2, '(*(2X e18.7))')((A(i,j)) ,j=1,M)\n ! end do\n ! close(2)\n ! read(*,*)\n ! end if\n ! DGETRF computes an LU factorization of a general M-by-N matrix A\n ! using partial pivoting with row interchanges.\n call DGETRF(n, n, Ainv, n, ipiv, info)\n\n if (info /= 0) then\n stop 'Matrix is numerically singular!'\n end if\n\n ! DGETRI computes the inverse of a matrix using the LU factorization\n ! computed by DGETRF.\n call DGETRI(n, Ainv, n, ipiv, work, n, info)\n\n if (info /= 0) then\n stop 'Matrix inversion failed!'\n end if\nend function inv\n\n\n\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!->Subroutine LU_INVERS.\n!\n!->Description.-\n!\n! Invert a matrix using LU Decomposition. It can also return the determinant.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n subroutine lu_invers (Matrix, InvMatrix, Det)\n!\n!-> I/O Variable.\n!\n real(8),intent(in) :: Matrix(:,:)\n real(8),intent(out):: InvMatrix(:,:)\n real(8),optional,intent(out):: Det\n\n!-> Local variables.\n!\n integer::i,N\n real(8) :: D\n real(8), allocatable :: MatrixLU(:,:)\n integer, allocatable :: Indexes(:)\n!\n! Set dimension and the auxiliary vector.\n!\n N= size(Matrix,1)\n allocate (Indexes(N)); Indexes = 0\n allocate (MatrixLU(N,N))\n!\n! Initialize InvMatrix as the identity matrix and MatrixLU as Matrix.\n!\n MatrixLU=Matrix\n!\n InvMatrix=0.d0\n do i=1,N\n InvMatrix(i,i)=1.d0\n end do\n!\n! LU Decomposition.\n!\n call lu_decomp (MatrixLU,Indexes,D)\n!\n! The inverse is the solution to units vectors.\n!\n do i=1,N\n call lu_bksubs (MatrixLU,Indexes,InvMatrix(:,i))\n end do\n!\n! Return the determinant of the matrix.\n!\n if (present(Det)) then\n Det=D\n do i=1,N\n Det=Det*MatrixLU(i,i)\n end do\n end if\n!\n return\n end subroutine lu_invers\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!->Subroutine LU_DETERM.\n!\n!->Description.-\n!\n! Invert a matrix using LU Decomposition.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n subroutine lu_determ (Matrix, Det)\n!\n!-> I/O Variable.\n!\n real(8), intent(in) :: Matrix(:,:)\n real(8), intent(out):: Det\n!\n!-> Local variables.\n!\n integer::i,N\n real(8), allocatable :: MatrixLU(:,:)\n integer, allocatable :: Indexes(:)\n!\n! Set dimension and the auxiliary vector.\n!\n N= size(Matrix,1)\n allocate (Indexes(N))\n allocate (MatrixLU(N,N)); MatrixLU=Matrix\n!\n! LU Decomposition.\n!\n call lu_decomp (MatrixLU,Indexes,Det)\n!\n! The determinant of a LU decomposed matrix is just the product of the\n! diagonal elements.\n!\n do i=1,N\n Det=Det*MatrixLU(i,i)\n end do\n\n deallocate(MatrixLU)\n deallocate(Indexes)\n!\n return\n end subroutine lu_determ\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!->Subroutine LU_SPARSE\n!\n!->Description.-\n!\n! Inverse of sparse matrix/vector product.\n!\n!-> Modifications.-\n! 20120317 A.Da Ronch Subroutine added for NOLAPACK conditional compilation\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n subroutine lu_sparse(dimSprMat, SprMat, b, X)\n use lib_sparse\n integer, intent(in) :: dimSprMat ! Current storage dimension\n type(sparse),intent(in) :: SprMat(:) ! Sparse matrix\n real(8), intent(in) :: b(:) ! Forcing vector\n real(8), intent(out):: X(:) ! Solution vector\n real(8),allocatable :: FulMat(:,:) ! Full matrix\n real(8),allocatable :: invFulMat(:,:)! Full matrix\n integer:: dimb\n\n dimb=size(b)\n\n ! allocate(invFulMat(dimb,dimb))\n !\n ! ! Calculate the inverse\n ! ! call lu_invers(FulMat, invFulMat)\n ! invFulMat = inv(SprMat(1)%a)\n !\n ! ! Calculate matrix-vector product\n ! ! X=0.0d0\n ! ! do i1=1,dimb\n ! ! ! do i2=1,dimb\n ! ! ! original\n ! ! X(i1) = X(i1) + dot_product(invFulMat(i1,:), b(:))\n ! ! ! end do\n ! ! end do\n ! X = MATMUL(invFulMat, b)\n !\n ! deallocate(invFulMat)\n call lu_solve(size(SprMat(1)%a, dim=1), SprMat(1)%a, b, X)\n return\n end subroutine lu_sparse\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n subroutine lu_solve(numdof,A, b, X, balancing)\n !use, intrinsic :: IEEE_ARITHMETIC\n use, intrinsic :: ISO_C_BINDING\n integer, intent(IN) :: numdof\n real(8), intent(IN) :: A(numdof, numdof)\n real(8), intent(in) :: b(numdof) ! Forcing vector\n real(8), intent(out) :: X(numdof) ! Solution vector\n ! real(8),allocatable :: invFulMat(:,:)! Full matrix\n logical(c_bool), optional :: balancing\n integer:: dimb\n real(8) :: r(numdof)\n real(8) :: c(numdof)\n real(8) :: rcond\n real(8) :: ferr(1)\n real(8) :: berr(1)\n real(8) :: work(4*numdof)\n integer :: iwork(numdof)\n integer :: info\n integer :: ipivot(numdof)\n character :: equed\n character :: fact\n character :: trans\n integer :: unit\n integer :: i\n\n ! real(8),allocatable :: A_copy(:,:)\n real(8) :: A_copy(numdof, numdof)\n real(8) :: b_copy(numdof)\n real(8) :: AF(numdof, numdof)\n ! real(8) :: work(size(A, dim=1)*4)\n ! integer :: iwork(size(A, dim=1))\n integer :: nrows\n logical :: with_balancing\n\n !if (any(ieee_is_nan(A))) then\n !open(newunit=unit, file='debug_failed_Asys.txt')\n !do i=1, size(A(:,1))\n !write(unit,*)A(i, :)\n !end do\n !close(unit)\n !STOP 'NaN in lu_solve'\n !end if\n\n A_copy = A\n X = b\n b_copy = b\n nrows = size(b)\n\n ! solve system\n with_balancing = .FALSE.\n if (present(balancing)) then\n if (balancing) then\n with_balancing = .TRUE.\n end if\n end if\n if (.NOT. with_balancing) then\n call dgesv(numdof,&\n 1,&\n A_copy,&\n numdof,&\n ipivot,&\n x,&\n numdof,&\n info)\n else\n fact = 'E'\n trans = 'N'\n call dgesvx(fact,&\n trans,&\n numdof,&\n 1,&\n A_copy,&\n numdof,&\n AF,&\n numdof,&\n ipivot,&\n equed,&\n r,&\n c,&\n b_copy,&\n numdof,&\n x,&\n numdof,&\n rcond,&\n ferr,&\n berr,&\n work,&\n iwork,&\n info)\n end if\n\n if (info /= 0) then\n print*, 'Info in DGESV = ', info\n open(newunit=unit, file='debug_failed_Asys.txt')\n do i=1, size(A(:,1))\n write(unit,*)A(i, :)\n end do\n close(unit)\n stop\n end if\n ! deallocate(A_copy)\n return\n end subroutine lu_solve\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\nend module lib_lu\n", "meta": {"hexsha": "fd858c216ba5afd5b9f865b150c75606bd281a5f", "size": 12577, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/xbeam_base/lib_lu.f90", "max_stars_repo_name": "fonsocarre/xbeam", "max_stars_repo_head_hexsha": "56d933b8f0de6e03615bfc73003c524dfdafc00b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-12-03T16:06:06.000Z", "max_stars_repo_stars_event_max_datetime": "2017-12-03T16:06:06.000Z", "max_issues_repo_path": "src/xbeam_base/lib_lu.f90", "max_issues_repo_name": "ImperialCollegeLondon/xbeam", "max_issues_repo_head_hexsha": "56d933b8f0de6e03615bfc73003c524dfdafc00b", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2018-05-20T23:38:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-10T08:16:30.000Z", "max_forks_repo_path": "src/xbeam_base/lib_lu.f90", "max_forks_repo_name": "fonsocarre/xbeam", "max_forks_repo_head_hexsha": "56d933b8f0de6e03615bfc73003c524dfdafc00b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-02-16T04:17:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-16T04:17:45.000Z", "avg_line_length": 26.3668763103, "max_line_length": 83, "alphanum_fraction": 0.443587501, "num_tokens": 3530, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.6757442232714904}} {"text": "*\n* gradepretty - Calculate student grades based on partial scores\n*\n* The program will prompt for student grades until EOF is entered\n*\n* The final grade is 30% programs, 50% tests and 20% homework\n*\n* Grades are assigned based on the following scale:\n*\n* >0.90 4.0\n* >0.80 3.0\n* >0.70 2.0\n* <0.60 0.0\n*\n* Written by: C. Severance 16Mar92\n*\n REAL PPER,TPER,HPER,PERCENT,TOTPER,AVEPER,GPA,TOTGPA,AVEGPA\n INTEGER STUDENT,COUNT\n*\n* Initialization and headings\n*\n TOTPER = 0\n TOTGPA=0\n COUNT = 0\n PRINT 80\n80 FORMAT(/'Grade program - written by Charles Severance'/)\n*\n* Read the three percentages. Note that data is expected from\n* a file so there is no prompt.\n*\n10 READ(*,*,END=20)STUDENT,PPER,TPER,HPER\n*\n COUNT = COUNT + 1\n*\n PERCENT = PPER * 0.30 + TPER * 0.50 + HPER * 0.20\n TOTPER = TOTPER + PERCENT\n*\n* Determine the final grade and add it to the running total for GPA\n*\n GPA = 0.0\n IF ( PERCENT .GE. 0.90 ) THEN\n GPA = 4.0\n ELSE IF ( PERCENT .GE. 0.80 ) THEN\n GPA = 3.0\n ELSE IF ( PERCENT .GE. 0.70 ) THEN\n GPA = 2.0\n ENDIF\n*\n TOTGPA = TOTGPA + GPA\n*\n* Print out the student information\n*\n PRINT 100,STUDENT,PPER,TPER,HPER,PERCENT,GPA\n100 FORMAT(1X,I9,3X,F7.2,3X,F7.2,3X,F7.2,3X,F7.2,3X,F5.2)\n GOTO 10\n*\n20 CONTINUE\n*\n* Calculate the averages\n*\n IF ( COUNT.EQ.0 ) THEN\n AVEGPA = 0.0\n AVEPER = 0.0\n ELSE\n AVEGPA = TOTGPA/COUNT\n AVEPER = TOTPER/COUNT\n ENDIF\n*\n* Print them out\n*\n PRINT 200,AVEPER,AVEGPA\n200 FORMAT(/'Average',36X,F7.2,3X,F5.2)\n END\n", "meta": {"hexsha": "1925324144cc036de7005e90bc7157804ce85990", "size": 1639, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "archive/2000-eecs280/examples/examples.ftn/programs/gradepretty.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/gradepretty.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/gradepretty.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": 22.1486486486, "max_line_length": 67, "alphanum_fraction": 0.60585723, "num_tokens": 616, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.675744218894585}} {"text": "chapter xii, example 2. cubic spline interpolation with good knots\nc from * a practical guide to splines * by c. de boor\ncalls cubspl, newnot\nc parameter nmax=20\n integer i,istep,iter,itermx,j,n,nhigh,nlow,nm1\nc real algerp,aloger,decay,dx,errmax,c(4,nmax),g,h,pnatx\nc *\t ,scrtch(2,nmax),step,tau(nmax),taunew(nmax)\n real algerp,aloger,decay,dx,errmax,c(4,20),g,h,pnatx\n *\t ,scrtch(2,20),step,tau(20),taunew(20),x\nc istep and step = float(istep) specify point density for error det-\nc ermination.\n data step, istep /20., 20/\nc\t\t\t\tthe function g is to be interpolated .\n g(x) = sqrt(x+1.)\n decay = 0.\nc read in the number of iterations to be carried out and the lower\nc and upper limit for the number n of data points to be used.\n read 500,itermx,nlow,nhigh\n 500 format(3i3)\n print 600, itermx\n 600 format(i4,22h cycles through newnot//\n *\t 28h n max.error\t decay exp./)\nc\t\t\t\t loop over n = number of data points .\n do 40 n=nlow,nhigh,2\nc\t\t\t\t\t knots are initially equispaced.\n\t nm1 = n-1\n\t h = 2./float(nm1)\n\t do 10 i=1,n\n 10\t tau(i) = float(i-1)*h - 1.\n\t iter = 1\nc\t\tconstruct cubic spline interpolant. then, itermx times,\nc\t\t determine new knots from it and find a new interpolant.\n 11\t do 15 i=1,n\n 15\t c(1,i) = g(tau(i))\n\t call cubspl ( tau, c, n, 0, 0 )\n\t if (iter .gt. itermx)\tgo to 19\n\t iter = iter+1\n\t call newnot(tau,c,nm1,4,taunew,nm1,scrtch)\n\t do 18 i=1,n\n 18\t tau(i) = taunew(i)\n\t\t\t\t\tgo to 11\n 19\t continue\nc\t\t\t estimate max.interpolation error on (-1,1).\n\t errmax = 0.\nc\t\t\t loop over polynomial pieces of interpolant .\n\t do 30 i=1,nm1\n\t dx = (tau(i+1)-tau(i))/step\nc\t\t interpolation error is calculated at istep points per\nc\t\t polynomial piece .\n\t do 30 j=1,istep\n\t h = float(j)*dx\n\t pnatx = c(1,i)+h*(c(2,i)+h*(c(3,i)+h*c(4,i)/3.)/2.)\n 30\t errmax = amax1(errmax,abs(g(tau(i)+h)-pnatx))\nc\t\t\t\t\t calculate decay exponent .\n\t aloger = alog(errmax)\n\t if (n .gt. nlow) decay =\n *\t (aloger - algerp)/alog(float(n)/float(n-2))\n\t algerp = aloger\nc\n 40\t print 640,n,errmax,decay\n 640 format(i3,e12.4,f11.2)\n\t\t\t\t\tstop\n end\n", "meta": {"hexsha": "197f56f3a3d0211fcb59f6ba3491c7b6fb460148", "size": 2224, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iraf.v2161/math/deboor/progs/prog8.f", "max_stars_repo_name": "ysBach/irafdocgen", "max_stars_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:19:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T16:48:42.000Z", "max_issues_repo_path": "math/deboor/progs/prog8.f", "max_issues_repo_name": "kirxkirx/iraf", "max_issues_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-30T13:48:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-02T19:40:25.000Z", "max_forks_repo_path": "math/deboor/progs/prog8.f", "max_forks_repo_name": "kirxkirx/iraf", "max_forks_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.75, "max_line_length": 72, "alphanum_fraction": 0.6101618705, "num_tokens": 824, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916029436189, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6757442166439084}} {"text": "submodule (stdlib_stats) stdlib_stats_cov\n\n use, intrinsic:: ieee_arithmetic, only: ieee_value, ieee_quiet_nan\n use stdlib_error, only: error_stop\n use stdlib_optval, only: optval\n implicit none\n\ncontains\n\n module function cov_1_rdp_rdp(x, dim, mask, corrected) result(res)\n real(dp), intent(in) :: x(:)\n integer, intent(in) :: dim\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n res = var(x, dim, corrected = optval(corrected, .true.))\n\n end function cov_1_rdp_rdp\n module function cov_1_cdp_cdp(x, dim, mask, corrected) result(res)\n complex(dp), intent(in) :: x(:)\n integer, intent(in) :: dim\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n res = var(x, dim, corrected = optval(corrected, .true.))\n\n end function cov_1_cdp_cdp\n\n\n module function cov_1_iint32_dp(x, dim, mask, corrected) result(res)\n integer(int32), intent(in) :: x(:)\n integer, intent(in) :: dim\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n res = var(x, dim, corrected = optval(corrected, .true.))\n\n end function cov_1_iint32_dp\n\n\n module function cov_mask_1_rdp_rdp(x, dim, mask, corrected) result(res)\n real(dp), intent(in) :: x(:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:)\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n res = var(x, dim, mask, corrected = optval(corrected, .true.))\n\n end function cov_mask_1_rdp_rdp\n module function cov_mask_1_cdp_cdp(x, dim, mask, corrected) result(res)\n complex(dp), intent(in) :: x(:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:)\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n res = var(x, dim, mask, corrected = optval(corrected, .true.))\n\n end function cov_mask_1_cdp_cdp\n\n\n module function cov_mask_1_iint32_dp(x, dim, mask, corrected) result(res)\n integer(int32), intent(in) :: x(:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:)\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n res = var(x, dim, mask, corrected = optval(corrected, .true.))\n\n end function cov_mask_1_iint32_dp\n\n\n module function cov_2_rdp_rdp(x, dim, mask, corrected) result(res)\n real(dp), intent(in) :: x(:, :)\n integer, intent(in) :: dim\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(dp) :: res(merge(size(x, 1), size(x, 2), mask = 1 0))\n end do\n end do\n case(2)\n do i = 1, size(res, 2)\n do j = 1, size(res, 1)\n mask_ = merge(.true., .false., mask(i, :) .and. mask(j, :))\n centeri_ = merge( x(i, :) - mean(x(i, :), mask = mask_),&\n 0._dp,&\n mask_)\n centerj_ = merge( x(j, :) - mean(x(j, :), mask = mask_),&\n 0._dp,&\n mask_)\n\n n = count(mask_)\n res(j, i) = dot_product( centeri_, centerj_)&\n / (n - merge(1, 0,&\n optval(corrected, .true.) .and. n > 0))\n end do\n end do\n case default\n call error_stop(\"ERROR (cov): wrong dimension\")\n end select\n\n end function cov_mask_2_rdp_rdp\n module function cov_mask_2_cdp_cdp(x, dim, mask, corrected) result(res)\n complex(dp), intent(in) :: x(:, :)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:,:)\n logical, intent(in), optional :: corrected\n complex(dp) :: res(merge(size(x, 1), size(x, 2), mask = 1 0))\n end do\n end do\n case(2)\n do i = 1, size(res, 2)\n do j = 1, size(res, 1)\n mask_ = merge(.true., .false., mask(i, :) .and. mask(j, :))\n centeri_ = merge( x(i, :) - mean(x(i, :), mask = mask_),&\n cmplx(0,0,kind=dp),&\n mask_)\n centerj_ = merge( x(j, :) - mean(x(j, :), mask = mask_),&\n cmplx(0,0,kind=dp),&\n mask_)\n\n n = count(mask_)\n res(j, i) = dot_product( centeri_, centerj_)&\n / (n - merge(1, 0,&\n optval(corrected, .true.) .and. n > 0))\n end do\n end do\n case default\n call error_stop(\"ERROR (cov): wrong dimension\")\n end select\n\n end function cov_mask_2_cdp_cdp\n\n\n module function cov_mask_2_iint32_dp(x, dim, mask, corrected) result(res)\n integer(int32), intent(in) :: x(:, :)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res(merge(size(x, 1), size(x, 2), mask = 1 0))\n end do\n end do\n case(2)\n do i = 1, size(res, 2)\n do j = 1, size(res, 1)\n mask_ = merge(.true., .false., mask(i, :) .and. mask(j, :))\n centeri_ = merge( x(i, :) - mean(x(i, :), mask = mask_),&\n 0._dp, mask_)\n centerj_ = merge( x(j, :) - mean(x(j, :), mask = mask_),&\n 0._dp, mask_)\n\n n = count(mask_)\n res(j, i) = dot_product( centeri_, centerj_)&\n / (n - merge(1, 0,&\n optval(corrected, .true.) .and. n > 0))\n end do\n end do\n case default\n call error_stop(\"ERROR (cov): wrong dimension\")\n end select\n\n end function cov_mask_2_iint32_dp\n\n\nend submodule\n", "meta": {"hexsha": "b1642937ec271c80f34045ccba83a609e27ef616", "size": 12552, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/stdlib_stats_cov.f90", "max_stars_repo_name": "zoziha/dp-stdlib", "max_stars_repo_head_hexsha": "d317f4d273cb0fcabf532578a7ec0e4687e18700", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-12-08T04:45:43.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-09T11:42:41.000Z", "max_issues_repo_path": "src/stdlib_stats_cov.f90", "max_issues_repo_name": "zoziha/dp-stdlib", "max_issues_repo_head_hexsha": "d317f4d273cb0fcabf532578a7ec0e4687e18700", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2021-12-08T12:35:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-17T02:33:12.000Z", "max_forks_repo_path": "src/stdlib_stats_cov.f90", "max_forks_repo_name": "zoziha/dp-stdlib", "max_forks_repo_head_hexsha": "d317f4d273cb0fcabf532578a7ec0e4687e18700", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-09T01:54:34.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-09T01:54:34.000Z", "avg_line_length": 34.6740331492, "max_line_length": 77, "alphanum_fraction": 0.4991236456, "num_tokens": 3674, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916029436189, "lm_q2_score": 0.7826624789529376, "lm_q1q2_score": 0.6757442122670032}} {"text": "module array_utils\n\n\timplicit none\n\n\tinterface ones_like\n\t\tprocedure ones_like_1d\n\t\tprocedure ones_like_2d\n\tend interface ones_like\n\ncontains\n\n\nsubroutine fill_matrix_with_value(A, val)\n\t! Set all the elements of matrix A[m x n] to be val\n\timplicit none\n\treal(kind=8), dimension(:,:), intent(inout) :: A\n\treal(kind=8), intent(in) :: val\n\n\tA = val\n\nend subroutine fill_matrix_with_value\n\nsubroutine set_diagonal_to(A, val)\n\t! Set diagonal elements of matrix A[m x n] to be val\n\timplicit none\n\treal(kind=8), dimension(:,:), intent(inout) :: A\n\treal(kind=8), intent(in) :: val\n\n\t! local variable\n\tinteger :: i \n\n\tFORALL (i=1:minval(shape(A))) A(i, i) = val\n\nend subroutine set_diagonal_to\n\n\nsubroutine add_value_to_diagonal(A, val)\n\t! Add value val to diagonal elements of matrix A[m x n]\n\timplicit none\n\treal(kind=8), dimension(:,:), intent(inout) :: A\n\treal(kind=8), intent(in) :: val\n\n\t! local variable\n\tinteger :: i \n\n\tFORALL (i=1:minval(shape(A))) A(i,i) = A(i,i) + val\n\nend subroutine add_value_to_diagonal\n\n\nsubroutine add_array_to_diagonal(A, arr)\n\t! Add value val to diagonal elements of matrix A[m x n]\n\timplicit none\n\treal(kind=8), dimension(:,:), intent(inout) :: A\n\treal(kind=8), dimension(:), intent(in) :: arr\n\n\t! local variable\n\tinteger :: i \n\n\tif (size(arr) /= minval(shape(A))) stop 'Size mismatch in add_array_to_diagonal'\n\n\tFORALL (i=1:minval(shape(A))) A(i,i) = A(i,i) + arr(i)\n\nend subroutine add_array_to_diagonal\n\n\n\nfunction get_diagonal(A) result(diag)\n\t! Get diagonal elements of matrix A (general [m x n] dimensions)\n\timplicit none\n\treal(kind=8), dimension(:,:), intent(in) :: A\n\treal(kind=8), dimension(minval(shape(a))) :: diag\n\t! local variables\n\tinteger :: i\n\n\tFORALL (i=1:size(diag)) diag(i) = A(i,i)\n\nend function get_diagonal\n\n\nfunction eye(n) result(A)\n\t! Create an [n x n] identity matrix\n\timplicit none\n\tinteger, intent(in) :: n\n\treal(kind=8), dimension(n,n) :: A\n\n\tA = 0.d0\n\tcall set_diagonal_to(A, 1.d0)\n\treturn\n\t\nend function eye\n\n\nfunction ones_like_1d(arr) result(ones)\n\timplicit none\n\treal(kind=8), dimension(:), intent(in) :: arr\n\treal(kind=8), dimension(:), allocatable :: ones\n\n\tallocate(ones(size(arr)))\n\tones = 1.d0\nend function ones_like_1d\n\nfunction ones_like_2d(arr) result(ones)\n\timplicit none\n\treal(kind=8), dimension(:,:), intent(in) :: arr\n\treal(kind=8), dimension(:,:), allocatable :: ones\n\tinteger, dimension(2) :: dims\n\n\tdims = shape(arr)\n\tallocate(ones(dims(1), dims(2)))\n\tones = 1.d0\nend function ones_like_2d\n\n\nfunction linspace(xmin, xmax, num) result(x)\n implicit none\n real(kind=8), intent(in) :: xmin, xmax\n integer, intent(in) :: num\n real(kind=8), dimension(num) :: x\n integer :: i\n if (num == 1) then\n if(xmin /= xmax) then\n write(0,'(\"ERROR: Cannot call linspace with n=1 and xmin /= xmax\")')\n stop\n else\n x = xmin\n end if\n else\n do i=1,num\n x(i) = (xmax-xmin) * real(i-1, kind=8) / real(num-1, kind=8) + xmin\n end do\n end if\nend function linspace\n\nsubroutine sort(A, N)\n\t! arguments\n\tinteger, intent(in) :: N\n\treal(kind=8), dimension(N), intent(inout) :: A\n\t! local variables\n\treal(kind=8), dimension((N+1)/2) :: T\n\n\tcall MergeSort(A,N,T)\n\n\tcontains \n\t\tsubroutine Merge(A,NA,B,NB,C,NC)\n\t\t\n\t\t\tinteger, intent(in) :: NA,NB,NC ! Normal usage: NA+NB = NC\n\t\t\treal(kind=8), intent(in out) :: A(NA) ! B overlays C(NA+1:NC)\n\t\t\treal(kind=8), intent(in) :: B(NB)\n\t\t\treal(kind=8), intent(in out) :: C(NC)\n\n\t\t\tinteger :: I,J,K\n\t\t \n\t\t\tI = 1; J = 1; K = 1;\n\t\t\tdo while(I <= NA .and. J <= NB)\n\t\t\t\tif (A(I) <= B(J)) then\n\t\t\t\t\tC(K) = A(I)\n\t\t\t\t\tI = I+1\n\t\t\t\telse\n\t\t\t \t\tC(K) = B(J)\n\t\t\t\t\tJ = J+1\n\t\t\t\tendif\n\t\t\t\tK = K + 1\n\t\t\tenddo\n\t\t\tdo while (I <= NA)\n\t\t\t\tC(K) = A(I)\n\t\t\t\tI = I + 1\n\t\t\t\tK = K + 1\n\t\t\tenddo\n\t\t\treturn\n\t\tend subroutine merge\n \n\t\trecursive subroutine MergeSort(A,N,T)\n\t\t\tinteger, intent(in) :: N\n\t\t\treal(kind=8), dimension(N), intent(in out) :: A\n\t\t\treal(kind=8), dimension((N+1)/2), intent (out) :: T\n\n\t\t\tinteger :: NA, NB\n\t\t\treal(kind=8) :: V\n\t\t \n\t\t\tif (N < 2) return\n\t\t\tif (N == 2) then\n\t\t\t\tif (A(1) > A(2)) then\n\t\t\t\t\tV = A(1)\n\t\t\t\t\tA(1) = A(2)\n\t\t\t\t\tA(2) = V\n\t\t\t\tendif\n\t\t\t\treturn\n\t\t\tendif \n\t\t\tNA=(N+1)/2\n\t\t\tNB=N-NA\n\n\t\t\tcall MergeSort(A,NA,T)\n\t\t\tcall MergeSort(A(NA+1),NB,T)\n\n\t\t\tif (A(NA) > A(NA+1)) then\n\t\t\t\tT(1:NA)=A(1:NA)\n\t\t\t\tcall Merge(T,NA,A(NA+1),NB,A,N)\n\t\t\tendif\n\t\t\treturn\n\t\tend subroutine MergeSort\n \nend subroutine sort\n\n\n\nend module array_utils", "meta": {"hexsha": "4e6377719f05e79c7837dae237d95986843dea26", "size": 4429, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "array_utils.f90", "max_stars_repo_name": "j-faria/GP-utils", "max_stars_repo_head_hexsha": "3784c4bbc9d36e98cd7c163e5e6d952bac6c041d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "array_utils.f90", "max_issues_repo_name": "j-faria/GP-utils", "max_issues_repo_head_hexsha": "3784c4bbc9d36e98cd7c163e5e6d952bac6c041d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "array_utils.f90", "max_forks_repo_name": "j-faria/GP-utils", "max_forks_repo_head_hexsha": "3784c4bbc9d36e98cd7c163e5e6d952bac6c041d", "max_forks_repo_licenses": ["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.3961352657, "max_line_length": 81, "alphanum_fraction": 0.6191013773, "num_tokens": 1455, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833945721304, "lm_q2_score": 0.8723473630627235, "lm_q1q2_score": 0.6757057817271711}} {"text": "\nsubmodule(forlab_linalg) forlab_linalg_linspace\n\n implicit none\n\ncontains\n\n module procedure linspace_sp\n integer :: i, n\n real(sp) :: by\n n = size(X)\n by = (to - from)/real(n - 1, sp)\n X = from + by*real([(i - 1, i=1, n)], sp)\n return\n end procedure linspace_sp\n\n module procedure logspace_sp\n call linspace(X, log10(from), log10(to))\n X = 10._sp**X\n return\n end procedure logspace_sp\n module procedure linspace_dp\n integer :: i, n\n real(dp) :: by\n n = size(X)\n by = (to - from)/real(n - 1, dp)\n X = from + by*real([(i - 1, i=1, n)], dp)\n return\n end procedure linspace_dp\n\n module procedure logspace_dp\n call linspace(X, log10(from), log10(to))\n X = 10._dp**X\n return\n end procedure logspace_dp\n\nend submodule forlab_linalg_linspace\n", "meta": {"hexsha": "1367d9a7055f6b589f92fa1376415d8a9df85a9d", "size": 817, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/forlab_linalg_linspace.f90", "max_stars_repo_name": "zoziha/forlab_z", "max_stars_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2021-08-31T15:23:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T02:44:46.000Z", "max_issues_repo_path": "src/forlab_linalg_linspace.f90", "max_issues_repo_name": "zoziha/forlab_z", "max_issues_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-08-22T11:47:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-31T00:57:16.000Z", "max_forks_repo_path": "src/forlab_linalg_linspace.f90", "max_forks_repo_name": "zoziha/forlab_z", "max_forks_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-07-16T03:16:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-31T13:09:42.000Z", "avg_line_length": 21.5, "max_line_length": 47, "alphanum_fraction": 0.6168910649, "num_tokens": 256, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951182587158, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.6757000677840221}} {"text": "program parallel_pi\n include \"mpif.h\"\n integer, parameter:: dp = kind(1.0d0)\n real(dp), parameter :: pi25 = 3.141592653589793238462643_dp\n integer :: n, i\n real(dp) :: pi, h, sum, x\n logical :: done\n\n integer :: myid, numprocs, ierr\n real(dp) :: mypi\n\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 done = .false.\n\n do while ( .not.done)\n if (myid == 0) then\n write(*,'(\"Enter the number of intervals: (0 quits) \")')\n read(*,*) n\n endif\n\n call MPI_Bcast(n, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr)\n\n if (n == 0) exit\n\n h = 1.0_dp/dble(n)\n sum = 0.0_dp\n\n do i = myid+1, n, numprocs\n x = h * (i - 0.5_dp)\n sum = sum + 4.0_dp/(1.0_dp + x*x)\n enddo\n\n mypi = h * sum\n\n call MPI_Reduce(mypi, pi, 1, MPI_DOUBLE_PRECISION, MPI_SUM, 0, &\n MPI_COMM_WORLD, ierr)\n\n if (myid == 0) then\n write(*,'(\" pi is approximately \",f16.13,\" Error is \",f16.13)') &\n pi, abs(pi - pi25)\n end if\n end do\n\n call MPI_Finalize(ierr)\n\nend program parallel_pi\n", "meta": {"hexsha": "1ebae10a64a82a605ad6601c827a1a06a8bb8be7", "size": 1125, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lectures5and6/example/src/mpipi.f90", "max_stars_repo_name": "sdm900/fortran_course", "max_stars_repo_head_hexsha": "6f2db3fcc7b616b94c4e1fe8875a3158a01117b2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lectures5and6/example/src/mpipi.f90", "max_issues_repo_name": "sdm900/fortran_course", "max_issues_repo_head_hexsha": "6f2db3fcc7b616b94c4e1fe8875a3158a01117b2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lectures5and6/example/src/mpipi.f90", "max_forks_repo_name": "sdm900/fortran_course", "max_forks_repo_head_hexsha": "6f2db3fcc7b616b94c4e1fe8875a3158a01117b2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.5, "max_line_length": 73, "alphanum_fraction": 0.5813333333, "num_tokens": 387, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528170040852, "lm_q2_score": 0.7931059487389968, "lm_q1q2_score": 0.6756888472108858}} {"text": "!##############################################################################\n! PROGRAM SummingUp\n!\n! ## Use do loops to sum up integer numbers successively\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 SummingUp\n\n implicit none\n integer :: i, j, sum\n\n ! read the variable\n write(*,'(a)')'Type an integer variable that is > 0'\n read(*,*)i\n\n ! check whether i > 0\n if(i > 0)then\n\n ! initialize sum at 0\n sum = 0\n\n ! do the summing up\n do j = 1, i\n sum = sum + j\n enddo\n\n ! write the result to the console\n write(*,'(a,i3,a,i10)')'The sum of 1 to ',i,' is ',sum\n\n else\n\n ! write the error message\n write(*,'(a)')'Error: i should be greater than 0'\n endif\n\nend program\n", "meta": {"hexsha": "f23028ffa70a3b71fc37a744ef5eed9a63e86980", "size": 1073, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "complete/prog01/prog01_09/prog01_09.f90", "max_stars_repo_name": "aswinvk28/modflow_fortran", "max_stars_repo_head_hexsha": "0c8dd5da8fe08f0abcc6b677503e96cdcdb7ee1e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "complete/prog01/prog01_09/prog01_09.f90", "max_issues_repo_name": "aswinvk28/modflow_fortran", "max_issues_repo_head_hexsha": "0c8dd5da8fe08f0abcc6b677503e96cdcdb7ee1e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "complete/prog01/prog01_09/prog01_09.f90", "max_forks_repo_name": "aswinvk28/modflow_fortran", "max_forks_repo_head_hexsha": "0c8dd5da8fe08f0abcc6b677503e96cdcdb7ee1e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-04-07T12:27:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-07T12:27:47.000Z", "avg_line_length": 23.8444444444, "max_line_length": 79, "alphanum_fraction": 0.4790307549, "num_tokens": 282, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528094861981, "lm_q2_score": 0.7931059511841119, "lm_q1q2_score": 0.6756888433315276}} {"text": "\n*\n* Homework 5\n* CPSC 4399-11; Special Topics: Monte Carlo Simulation\n* Professor Minsker\n* Connor P. Taffe\n* T no. 00563742\n*\n\n program main\n double precision sim\n print *, 'Simulated: ', sim()\n end\n\n*\n* Generates n random numbers on the range [1,n].\n* returns the cardinality of the set of unique\n* numbers generated.\n*\n integer function unique(n)\n integer n, rnd\n logical seen(n)\n external rand\n double precision rand\n\n* Intialize local variables.\n unique = 0\n do 10 i=1, n\n seen(i) = .false.\n10 continue\n\n\n*\n* Loop n times, generating n random numbers\n* on the range [1, n]. Returns the number of unique\n* numbers (numbers only generated once).\n*\n do 20 i=1, n\n*\n* Random number on range [1, 365].\n* The rand function is implemented in C code using the C\n* standard library's rand function, which returns\n* on the range [0, RAND_MAX].\n* The rand function divides that by RAND_MAX cast to a double\n* to get a double precision floating point on the\n* range [0, 1].\n* Multiply with integer truncation yilds equal probablility\n* of 0-n-1 and almost 0 proability of n. Thusly\n* ([0, 1] * n)+1 => [1,n].\n* Loop to avoid n's\n*\n rnd = n+1\n do 30 while (rnd .eq. n+1)\n rnd = int(rand() * n)+1\n30 continue\n\n*\n* \"dist\" is an array of size n, indexed on\n* the range [1, n]. For each index, the corresponding\n* entry is the number of times that index has been generated\n* by this loop.\n* On no previous generations, it is a unique value,\n* so the unique count is incremented.\n* On one previous generation, it is no longer unique,\n* so the unique count is decremented.\n*\n if (.not. seen(rnd)) then\n unique = unique+1\n seen(rnd) = .true.\n end if\n20 continue\n return\n end\n\n* Simulation function, returns mean.\n double precision function sim()\n integer n, m, unique\n parameter(m = 365, n = 100000)\n sim = 0\n*\n* Loop over n simulations.\n* Sums unique values out of m trials.\n*\n do 10 j=1, n\n sim = sim + unique(m)\n10 continue\n*\n* Value of the simulation is the number of trails\n* minus the total uniques out of the total simulations.\n*\n sim = sim/n\n return\n end\n", "meta": {"hexsha": "998c0ab30ff618979e14216d3b3524de7d5af11a", "size": 2384, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "sim/hw5/f77/main.f", "max_stars_repo_name": "cptaffe/os_hw", "max_stars_repo_head_hexsha": "c11949646ec2dd7a30581cd2108a183ec3e65403", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "sim/hw5/f77/main.f", "max_issues_repo_name": "cptaffe/os_hw", "max_issues_repo_head_hexsha": "c11949646ec2dd7a30581cd2108a183ec3e65403", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2015-03-16T20:54:08.000Z", "max_issues_repo_issues_event_max_datetime": "2015-03-16T20:54:08.000Z", "max_forks_repo_path": "sim/hw5/f77/main.f", "max_forks_repo_name": "cptaffe/hw", "max_forks_repo_head_hexsha": "c11949646ec2dd7a30581cd2108a183ec3e65403", "max_forks_repo_licenses": ["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.3617021277, "max_line_length": 61, "alphanum_fraction": 0.6019295302, "num_tokens": 622, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527869325346, "lm_q2_score": 0.7931059414036511, "lm_q1q2_score": 0.675688817111592}} {"text": "! =====================================================================\n! function ALAGUERRE\n!\n! alaguerre is an function that recursively computes the value of the \n! associated Laguerre polynomial of degree n and order k at the point x.\n! --------------------------------------------------------------------- \n DOUBLE PRECISION RECURSIVE FUNCTION alaguerre ( n , k , x ) RESULT ( alaguerreNK ) \n\n IMPLICIT NONE\n\n INTEGER, INTENT ( IN ) :: n\n INTEGER, INTENT ( IN ) :: k\n\n DOUBLE PRECISION, INTENT ( IN ) :: x\n\n alaguerreNK = 0.0\n\n IF ( k > -1 ) THEN\n\n IF ( n == 0 ) THEN\n\n alaguerreNK = 1.0\n\n ELSE IF ( n == 1 ) THEN\n\n alaguerreNK = 1.0 + REAL ( k ) - x\n\n ELSE IF ( n >= 2 ) THEN\n\n alaguerreNK = ( ( 2.0 * REAL ( n ) + REAL ( k ) - 1.0 - x ) * alaguerre ( n - 1 , k , x ) - & \n & ( REAL ( n ) + REAL ( k ) - 1.0 ) * alaguerre ( n - 2 , k , x ) ) / REAL ( n )\n\n ELSE\n\n ! ERROR\n\n END IF\n \n ELSE\n\n ! ERROR \n\n END IF\n\n RETURN \n END FUNCTION\n! =====================================================================\n\n", "meta": {"hexsha": "b6d6ab771b0df729426d688cc385156672e5acb5", "size": 1184, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/alaguerre.f", "max_stars_repo_name": "mkandes/itpprp", "max_stars_repo_head_hexsha": "d30f4fc0b05822a34fef187688ab12245cbbf93a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source/alaguerre.f", "max_issues_repo_name": "mkandes/itpprp", "max_issues_repo_head_hexsha": "d30f4fc0b05822a34fef187688ab12245cbbf93a", "max_issues_repo_licenses": ["MIT"], "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/alaguerre.f", "max_forks_repo_name": "mkandes/itpprp", "max_forks_repo_head_hexsha": "d30f4fc0b05822a34fef187688ab12245cbbf93a", "max_forks_repo_licenses": ["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.1632653061, "max_line_length": 106, "alphanum_fraction": 0.3876689189, "num_tokens": 324, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206738932334, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6756172440572391}} {"text": "program main\n implicit none\n \n integer :: number\n integer, dimension(3) :: arr\n\n number = 1000\n\n arr = triplet(number)\n print *, arr\n\n print *, product(arr)\n\ncontains\nfunction triplet(number)\n implicit none\n integer, intent(in) :: number\n integer, dimension(3) :: triplet\n integer :: a, b, c\n\n loopa: do a = 1, number\n do b = a, number\n c = number - a - b\n if (a*a + b*b == c*c) then\n exit loopa\n end if\n end do\n end do loopa\n \n triplet(1) = a\n triplet(2) = b\n triplet(3) = c\n \nend function triplet\n\nend program main", "meta": {"hexsha": "24e12e3df470641353c01a03980a1e5b2966d20c", "size": 635, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Problem_9/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_9/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_9/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": 17.6388888889, "max_line_length": 38, "alphanum_fraction": 0.5275590551, "num_tokens": 177, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206659843131, "lm_q2_score": 0.7490872131147276, "lm_q1q2_score": 0.6756172381327682}} {"text": "module functions\n contains\n \nsubroutine spaceevenly(start, finish, number, arrayout)\n implicit none\n \n integer, intent(in) :: start, finish\n real(kind=8), intent(in) :: number\n real(kind=8) :: div\n real(kind=8), dimension(0:finish), intent(out) :: arrayout\n integer :: i\n \n div = number / ((finish-1) - (start-1))\n \n do i=start, finish\n arrayout(i) = div * i\n end do\n\nend subroutine spaceevenly\n\n\nsubroutine laplace2d(p, y, dx, dy, l1nom_target, nx, ny)\n implicit none\n integer, intent(in) :: nx, ny\n real(kind=8), intent(in) :: dx, dy, l1nom_target\n real(kind=8), intent(in), dimension(nx) :: y\n real(kind=8), intent(out), dimension(nx, ny) :: p\n real(kind=8), dimension(nx, ny) :: pn\n integer :: i, j, l1norm = 1, whilecounter =1\n real(kind=8) :: derivYpow2, derivXpow2, F1term, S2term, numerator, denominator\n real(kind=8) :: lnorm_last, psum, pnsum\n \n derivYpow2 = dy**2\n\tderivXpow2 = dx**2\n \n ! Counter still not working with the l1norm condition\n do while (whilecounter < 708)! (l1norm > l1nom_target)\n pn = p\n do i = 2, nx-1\n do j = 2, ny-1\n F1term = p(j, i + 1) + p(j, i - 1)\n S2term = p(j + 1, i) + p(j - 1, i)\n numerator = (derivYpow2 * F1term) + (derivXpow2 * S2term)\n denominator = 2 * (derivXpow2 + derivYpow2)\n \n p(j,i) = numerator / denominator\n \n !print*, \"in main while loop -> iteration:)\", i, \" - \", j\n end do \n end do\n \n ! Reset Boundary conditions\n call boundary_conditions(p, y, nx, ny)\n \n ! calculate l1norm\n do i = 1, nx\n do j = 1, ny\n psum = psum + abs(p(j,i))\n\t\t\t\tpnsum = pnsum + abs(pn(j,i))\n end do\n end do\n lnorm_last = l1norm\n\t\tl1norm = (psum - pnsum) / pnsum\n ! print*, \"loop counter: \", whilecounter \n whilecounter = whilecounter +1\n end do\n \nend subroutine\n\nsubroutine boundary_conditions(p, y, nx,ny)\n implicit none\n \n real(kind=8), intent(out), dimension(nx, ny) :: p\n real(kind=8), intent(in), dimension(nx) :: y\n integer, intent(in) :: nx, ny\n integer :: i\n \n do i=1, ny\n p(i,1) = 0\n end do\n \n do i=1, ny\n p(i,ny) = y(i)\n end do\n \n do i=1, nx\n p(1,i) = p(2,i)\n end do\n \n do i=1, nx\n p(nx,i) = p(nx-1,i)\n end do\n\nend subroutine\n\n \nsubroutine diffuse(timesteps, u, nu, dt, dx, dy, nx, ny)\n implicit none\n integer, intent(in) :: nx, ny, timesteps\n real(kind=8), intent(in) :: nu, dt, dx, dy\n real(kind=8), intent(out), dimension(nx,ny) :: u\n real(kind=8), dimension(nx,ny) :: un\n integer :: i, j, time\n real(kind=8) :: Ydisip, Xdisip, Yderiv, Xderiv\n time = timesteps\n\n do time = 1, time\n un = u\n \n do j=2, nx-1\n do i=2, ny-1\n Xderiv = (nu * dt) / (dx**2)\n Yderiv = (nu * dt) / (dy**2)\n Xdisip = un(j,i+1) - (2 * un(j,i)) + un(j,i-1)\n Ydisip = un(j+1,i) - (2 * un(j,i)) + un(j-1,i)\n \n u(j,i) = un(j,i) + (Xderiv * Xdisip) + (Yderiv * Ydisip)\n\n u(1,j) = 1\n u(nx,j) = 1\n u(i,1) = 1\n u(i,ny) = 1\n \n u(1,1) = 1\n u(1,nx) = 1\n u(ny,1) = 1\n u(ny,nx) = 1\n end do\n end do\n end do\nend subroutine \n\nsubroutine write_csv (unit_number, filename, p, nx, ny) \n implicit none\n integer, intent(in) :: unit_number\n character(len = *), intent(in) :: filename\n integer, intent(in) :: nx, ny\n real(kind=8), intent(in), dimension(nx,ny) :: p\n integer :: i, j\n\n10 format (i1)\n15 format (f10.5,\",\")\n20 format (\"\")\n \n open(unit=unit_number, file=filename)\n do i=1, nx\n do j=1, ny\n write(unit=unit_number, fmt=15, advance=\"no\"), p(i,j)\n end do\n write(unit=unit_number,fmt=20)\n end do\n \n close(unit=unit_number)\n\nend subroutine\n\nend module functions", "meta": {"hexsha": "56d400fff14d87468bba8d32aab7932b1756c6db", "size": 4256, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "l9/functions.f90", "max_stars_repo_name": "dominique120/12-steps-navier-stokes", "max_stars_repo_head_hexsha": "3e195bf7f7895f83f5f2248ef48dc13b76e8b5de", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "l9/functions.f90", "max_issues_repo_name": "dominique120/12-steps-navier-stokes", "max_issues_repo_head_hexsha": "3e195bf7f7895f83f5f2248ef48dc13b76e8b5de", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "l9/functions.f90", "max_forks_repo_name": "dominique120/12-steps-navier-stokes", "max_forks_repo_head_hexsha": "3e195bf7f7895f83f5f2248ef48dc13b76e8b5de", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.1082802548, "max_line_length": 82, "alphanum_fraction": 0.4910714286, "num_tokens": 1333, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206659843131, "lm_q2_score": 0.7490872131147276, "lm_q1q2_score": 0.6756172381327682}} {"text": "data Bool = True\n | False\n\ndata Nat = Zero\n | S Nat\n\nand :: Bool -> Bool -> Bool\nand = [, , , ]\n\nisZero :: Nat -> Bool\nisZero = [, ]\n\nbothZero :: Nat -> Nat -> Bool\nbothZero = [, , ]\n\nmain :: Unit\nmain = bothZero (Zero) (Zero)\n", "meta": {"hexsha": "fb39c816c445ff5119d3ff33249d3b9b7b3f4187", "size": 410, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "test/nat_bothZero.f", "max_stars_repo_name": "joeyginorio/learning_sysf", "max_stars_repo_head_hexsha": "8073a928db69ab5729682072be973132aaf4fadc", "max_stars_repo_licenses": ["MIT"], "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/nat_bothZero.f", "max_issues_repo_name": "joeyginorio/learning_sysf", "max_issues_repo_head_hexsha": "8073a928db69ab5729682072be973132aaf4fadc", "max_issues_repo_licenses": ["MIT"], "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/nat_bothZero.f", "max_forks_repo_name": "joeyginorio/learning_sysf", "max_forks_repo_head_hexsha": "8073a928db69ab5729682072be973132aaf4fadc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-07-07T22:47:43.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-07T22:47:43.000Z", "avg_line_length": 22.7777777778, "max_line_length": 85, "alphanum_fraction": 0.5804878049, "num_tokens": 126, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9019206659843132, "lm_q2_score": 0.7490872075132152, "lm_q1q2_score": 0.6756172330806485}} {"text": "program trace_nan\n use, intrinsic :: iso_fortran_env, only : dp => REAL64\n implicit none\n integer, parameter :: n = 4\n integer :: i\n real(kind=dp), parameter, dimension(n) :: a = [ 1.0_dp, 3.0_dp, &\n -3.0_dp, 5.3_dp ]\n real(kind=dp), dimension(n) :: b\n\n do i = 1, n\n b(i) = sqrt(a(i))\n end do\n do i = 1, n\n print '(2F10.3)', a(i), b(i)\n end do\n\nend program trace_nan\n", "meta": {"hexsha": "1107096c498f987c85425ec8a5e6740a0136a15c", "size": 462, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Debugging/Arithmetic/trace_nan.f90", "max_stars_repo_name": "Gjacquenot/training-material", "max_stars_repo_head_hexsha": "16b29962bf5683f97a1072d961dd9f31e7468b8d", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 115, "max_stars_repo_stars_event_min_datetime": "2015-03-23T13:34:42.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T00:27:21.000Z", "max_issues_repo_path": "Debugging/Arithmetic/trace_nan.f90", "max_issues_repo_name": "Gjacquenot/training-material", "max_issues_repo_head_hexsha": "16b29962bf5683f97a1072d961dd9f31e7468b8d", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 56, "max_issues_repo_issues_event_min_datetime": "2015-02-25T15:04:26.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-03T07:42:48.000Z", "max_forks_repo_path": "Debugging/Arithmetic/trace_nan.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": 25.6666666667, "max_line_length": 69, "alphanum_fraction": 0.487012987, "num_tokens": 149, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8128672997041659, "lm_q2_score": 0.8311430478583169, "lm_q1q2_score": 0.6756090049804805}} {"text": "subroutine qinit(maxmx,meqn,mbc,mx,xlower,dx,q,maux,aux)\n\n use parameters_module\n\n implicit none\n \n ! Input arguments\n integer, intent(in) :: maxmx,meqn,mbc,mx,maux\n double precision, intent(in) :: xlower,dx\n \n double precision, intent(inout) :: q(1-mbc:maxmx+mbc,meqn)\n double precision, intent(inout) :: aux(1-mbc:maxmx+mbc,maux)\n\n ! Locals\n integer :: i\n double precision :: x,xmid,eigen_vector(4),gamma,lambda,alpha,h_1,h_2,deta\n\n if (.not.((0 <= init_type).and.(init_type <= 5))) then\n print \"(a,i2)\",\"Invalid initialization type requested, init_type = \",init_type\n endif\n \n do i=1,mx\n x = xlower+(i-0.5)*dx\n\n ! Set initial perturbation to zero and constant depths\n q(i,1) = aux(i,3) * rho(1)\n q(i,3) = aux(i,4) * rho(2)\n q(i,2) = 0.d0\n q(i,4) = 0.d0\n \n ! Simple Riemann problem specification\n if (init_type == 0) then\n ! Depth is already set above appropriately\n ! Need to set momentum though\n if (x < init_location) then\n q(i,2) = u_left(1) * q(i,1)\n q(i,4) = u_left(2) * q(i,3)\n else\n q(i,2) = u_right(1) * q(i,1)\n q(i,4) = u_right(2) * q(i,3)\n endif\n\n ! Riemann problem in one wave family\n else if (init_type == 1) then\n ! Calculate wave family for perturbation\n gamma = aux(i,4) / aux(i,3)\n select case(wave_family)\n case(1) ! Shallow water, left-going\n alpha = 0.5d0 * (gamma - 1.d0 + sqrt((gamma-1.d0)**2+4.d0*r*gamma))\n lambda = -sqrt(g*aux(i,3)*(1.d0+alpha))\n case(2) ! Internal wave, left-going\n alpha = 0.5d0 * (gamma - 1.d0 - sqrt((gamma-1.d0)**2+4.d0*r*gamma))\n lambda = -sqrt(g*aux(i,3)*(1.d0+alpha))\n case(3) ! Internal wave, right-going\n alpha = 0.5d0 * (gamma - 1.d0 - sqrt((gamma-1.d0)**2+4.d0*r*gamma))\n lambda = sqrt(g*aux(i,3)*(1.d0+alpha))\n case(4) ! Shallow water, right-going\n alpha = 0.5d0 * (gamma - 1.d0 + sqrt((gamma-1.d0)**2+4.d0*r*gamma))\n lambda = sqrt(g*aux(i,3)*(1.d0+alpha))\n end select\n eigen_vector = [1.d0,lambda,alpha,lambda*alpha]\n \n ! Add perturbation\n if ((x < init_location).and.(wave_family >= 3)) then\n q(i,1:2) = q(i,1:2) + rho(1) * epsilon * eigen_vector(1:2)\n q(i,3:4) = q(i,3:4) + rho(2) * epsilon * eigen_vector(3:4)\n else if ((x > init_location).and.(wave_family < 3)) then\n q(i,1:2) = q(i,1:2) + rho(1) * epsilon * eigen_vector(1:2)\n q(i,3:4) = q(i,3:4) + rho(2) * epsilon * eigen_vector(3:4)\n endif\n ! Gaussian hump of water, shallow water style\n else if (init_type == 2) then\n gamma = aux(i,4) / aux(i,3)\n alpha = 0.5d0 * (gamma - 1.d0 + sqrt((gamma-1.d0)**2+4.d0*r*gamma))\n deta = epsilon * exp(-((x-init_location)/sigma)**2)\n q(i,1) = q(i,1) + rho(1) * deta\n q(i,3) = q(i,3) + rho(2) * alpha * deta\n ! Gaussian on internal layer only\n else if (init_type == 3) then\n deta = epsilon * exp(-((x-init_location)/sigma)**2)\n q(i,1) = q(i,1) - rho(1) * deta\n q(i,3) = q(i,3) + rho(2) * deta\n ! Shelf initial condition from AN paper\n else if (init_type == 4) then\n gamma = aux(i,4) / aux(i,3)\n! alpha = 0.5d0 * (gamma - 1.d0 + sqrt((gamma-1.d0)**2+4.d0*r*gamma))\n alpha = 0.d0\n xmid = 0.5d0*(-180.e3-80.e3)\n if ((x > -130.e3).and.(x < -80.e3)) then\n deta = epsilon * sin((x-xmid)*PI/(-80.e3-xmid))\n q(i,3) = q(i,3) + rho(2) * alpha * deta\n q(i,1) = q(i,1) + rho(1) * deta * (1.d0 - alpha)\n endif\n endif\n enddo\n \nend subroutine qinit", "meta": {"hexsha": "dbf85537500759f15a6dc1ac0e0dfbc704e3a2f9", "size": 4068, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/1d/multilayer/qinit.f90", "max_stars_repo_name": "AsianHam/geoclaw", "max_stars_repo_head_hexsha": "b5f9ee8cd6e64d107ba8bba1e6d588aa7bf6d417", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 51, "max_stars_repo_stars_event_min_datetime": "2015-07-01T13:39:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T16:13:17.000Z", "max_issues_repo_path": "src/1d/multilayer/qinit.f90", "max_issues_repo_name": "AsianHam/geoclaw", "max_issues_repo_head_hexsha": "b5f9ee8cd6e64d107ba8bba1e6d588aa7bf6d417", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 274, "max_issues_repo_issues_event_min_datetime": "2015-02-20T18:25:04.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-09T23:51:47.000Z", "max_forks_repo_path": "src/1d/multilayer/qinit.f90", "max_forks_repo_name": "BrisaDavis/geoclaw", "max_forks_repo_head_hexsha": "ccab58669bc2950de13cf0f35c10b3cd1cb1cda6", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 66, "max_forks_repo_forks_event_min_datetime": "2015-01-10T00:05:00.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-24T22:05:16.000Z", "avg_line_length": 41.9381443299, "max_line_length": 87, "alphanum_fraction": 0.4894296952, "num_tokens": 1337, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418137109956, "lm_q2_score": 0.7310585727705126, "lm_q1q2_score": 0.6756017953691134}} {"text": "use ArrayClass\nimplicit none\n\ntype(Array_) :: array1, array2\n\narray1 = to_array([1,2,3],[4,5,6],[7,8,9],dtype=\"float\")\narray2 = to_array([0,0,1],dtype=\"float\")\n\n! matrix-vector multiplication\narray1 = matmul(array1, array2)\n\n!array1 = array1%T() ! transpose\n! or\n!array1 = transpose(array1)\n\nprint *, array1%dtype\ncall print(array1)\n\nend", "meta": {"hexsha": "62a7df4d1908960b518af1d1b620eee956c7532e", "size": 337, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/simple_array_example.f90", "max_stars_repo_name": "kazulagi/faba", "max_stars_repo_head_hexsha": "7ef140f1ebea0e0ca496d14fdb94a3c024393cfa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-05T06:04:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:04:25.000Z", "max_issues_repo_path": "Tutorial/simple_array_example.f90", "max_issues_repo_name": "kazulagi/faba", "max_issues_repo_head_hexsha": "7ef140f1ebea0e0ca496d14fdb94a3c024393cfa", "max_issues_repo_licenses": ["MIT"], "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/simple_array_example.f90", "max_forks_repo_name": "kazulagi/faba", "max_forks_repo_head_hexsha": "7ef140f1ebea0e0ca496d14fdb94a3c024393cfa", "max_forks_repo_licenses": ["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.7368421053, "max_line_length": 56, "alphanum_fraction": 0.7002967359, "num_tokens": 113, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8947894745194283, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6754899893399743}} {"text": " subroutine sft(x,n,om,ct,st)\nc\nc calculates fourier transform of real sequence x(i),i=1,...n\nc at angular frequency om normalized so that nyquist=pi. the sine\nc transform is returned in st and the cosine transform in ct.\nc algorithm is that of goertzal with modifications by\nc gentleman, comp.j. 1969\nc transform is not normalized\nc to normalize one-sided ft, divide by sqrt(data length)\nc for positive om, the ft is defined as ct-(0.,1.)st or like slatec\nc cfftf\nc\n implicit double precision (a-h,o-z)\n parameter (pi=3.141592653589793238d0,tp=2.d0*pi)\n dimension x(n)\n np1=n+1\n l=6.d0*om/tp\n s=sin(om)\n a=0.d0\n c=0.d0\n d=0.d0\n e=0.d0\n if(l.eq.0)then\nc recursion for low frequencies (.lt. nyq/3)\n b=-4.d0*sin(om/2.d0)**2\n do 10 k=1,n\n c=a\n d=e\n a=x(np1-k)+b*d+c\n 10 e=a+d\n elseif(l.eq.1)then\nc regular goertzal algorithm for intermediate frequencies\n b=2.d0*cos(om)\n do 20 k=1,n\n a=x(np1-k)+b*e-d\n d=e\n 20 e=a\n else\nc recursion for high frequencies (.gt. 2*nyq/3)\n b=4.d0*cos(om/2.d0)**2\n do 30 k=1,n\n c=a\n d=e\n a=x(np1-k)+b*d-c\n 30 e=a-d\n endif\n st=-s*d\n ct=a-b*d/2.d0\n return\n end\n\nc $Id$ \n", "meta": {"hexsha": "22f5d610729d66e75d67d49575ca20cbc4380e75", "size": 1332, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "lib/dataformat/mw/sft.f", "max_stars_repo_name": "jreyes1108/antelope_contrib", "max_stars_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_stars_repo_licenses": ["BSD-2-Clause", "MIT"], "max_stars_count": 30, "max_stars_repo_stars_event_min_datetime": "2015-02-20T21:44:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-27T02:53:14.000Z", "max_issues_repo_path": "lib/dataformat/mw/sft.f", "max_issues_repo_name": "jreyes1108/antelope_contrib", "max_issues_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_issues_repo_licenses": ["BSD-2-Clause", "MIT"], "max_issues_count": 14, "max_issues_repo_issues_event_min_datetime": "2015-07-07T19:17:24.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-19T19:18:53.000Z", "max_forks_repo_path": "lib/dataformat/mw/sft.f", "max_forks_repo_name": "jreyes1108/antelope_contrib", "max_forks_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_forks_repo_licenses": ["BSD-2-Clause", "MIT"], "max_forks_count": 46, "max_forks_repo_forks_event_min_datetime": "2015-02-06T16:22:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T11:46:37.000Z", "avg_line_length": 25.1320754717, "max_line_length": 68, "alphanum_fraction": 0.5653153153, "num_tokens": 467, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969137, "lm_q2_score": 0.7549149978955811, "lm_q1q2_score": 0.6754899858017778}} {"text": "!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 1998 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Spherepack *\n! * *\n! * A Package of Fortran Subroutines and Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams and Paul Swarztrauber *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\nsubmodule(vorticity_routines) vorticity_gaussian_grid\n\ncontains\n\n ! subroutine vrtgc(nlat, nlon, isym, nt, vort, ivrt, jvrt, cr, ci, mdc, ndc, &\n ! wshsgc, ierror)\n !\n ! given the vector spherical harmonic coefficients cr and ci, precomputed\n ! by subroutine vhagc for a vector field (v, w), subroutine vrtgc\n ! computes the vorticity of the vector field in the scalar array\n ! vort. vort(i, j) is the vorticity at the gaussian colatitude\n ! theta(i) (see nlat as input parameter) and longitude\n ! lambda(j) = (j-1)*2*pi/nlon on the sphere. i.e.,\n !\n ! vort(i, j) = [-dv/dlambda + d(sint*w)/dtheta]/sint\n !\n ! where sint = sin(theta(i)). w is the east longitudinal and v\n ! is the colatitudinal component of the vector field from which\n ! cr, ci were precomputed. required associated legendre polynomials\n ! are recomputed rather than stored as they are in subroutine vrtgs.\n !\n !\n ! input parameters\n !\n ! nlat the number of points in the gaussian colatitude grid on the\n ! full sphere. these lie in the interval (0, pi) and are computed\n ! in radians in theta(1) <...< theta(nlat) by subroutine compute_gaussian_latitudes_and_weights.\n ! if nlat is odd the equator will be included as the grid point\n ! theta((nlat + 1)/2). if nlat is even the equator will be\n ! excluded as a grid point and will lie half way between\n ! theta(nlat/2) and theta(nlat/2+1). nlat must be at least 3.\n ! note: on the half sphere, the number of grid points in the\n ! colatitudinal direction is nlat/2 if nlat is even or\n ! (nlat + 1)/2 if nlat is odd.\n !\n ! nlon the number of distinct londitude points. nlon determines\n ! the grid increment in longitude as 2*pi/nlon. for example\n ! nlon = 72 for a five degree grid. nlon must be greater\n ! than 3. the axisymmetric case corresponds to nlon=1.\n ! the efficiency of the computation is improved when nlon\n ! is a product of small prime numbers.\n !\n !\n ! isym a parameter which determines whether the vorticity is\n ! computed on the full or half sphere as follows:\n !\n ! = 0\n ! the symmetries/antsymmetries described in isym=1, 2 below\n ! do not exist in (v, w) about the equator. in this case the\n ! vorticity is neither symmetric nor antisymmetric about\n ! the equator. the vorticity is computed on the entire\n ! sphere. i.e., in the array vort(i, j) for i=1, ..., nlat and\n ! j=1, ..., nlon.\n !\n ! = 1\n ! w is antisymmetric and v is symmetric about the equator.\n ! in this case the vorticity is symmetyric about the\n ! equator and is computed for the northern hemisphere\n ! only. i.e., if nlat is odd the vorticity is computed\n ! in the array vort(i, j) for i=1, ..., (nlat + 1)/2 and for\n ! j=1, ..., nlon. if nlat is even the vorticity is computed\n ! in the array vort(i, j) for i=1, ..., nlat/2 and j=1, ..., nlon.\n !\n ! = 2\n ! w is symmetric and v is antisymmetric about the equator\n ! in this case the vorticity is antisymmetric about the\n ! equator and is computed for the northern hemisphere\n ! only. i.e., if nlat is odd the vorticity is computed\n ! in the array vort(i, j) for i=1, ..., (nlat + 1)/2 and for\n ! j=1, ..., nlon. if nlat is even the vorticity is computed\n ! in the array vort(i, j) for i=1, ..., nlat/2 and j=1, ..., nlon.\n !\n !\n ! nt nt is the number of scalar and vector fields. some\n ! computational efficiency is obtained for multiple fields.\n ! in the program that calls vrtgc, the arrays cr, ci, and vort\n ! can be three dimensional corresponding to an indexed multiple\n ! vector field. in this case multiple scalar synthesis will\n ! be performed to compute the vorticity for each field. the\n ! third index is the synthesis index which assumes the values\n ! k=1, ..., nt. for a single synthesis set nt = 1. the\n ! description of the remaining parameters is simplified by\n ! assuming that nt=1 or that all the arrays are two dimensional.\n !\n ! ivrt the first dimension of the array vort as it appears in\n ! the program that calls vrtgc. if isym = 0 then ivrt\n ! must be at least nlat. if isym = 1 or 2 and nlat is\n ! even then ivrt must be at least nlat/2. if isym = 1 or 2\n ! and nlat is odd then ivrt must be at least (nlat + 1)/2.\n !\n ! jvrt the second dimension of the array vort as it appears in\n ! the program that calls vrtgc. jvrt must be at least nlon.\n !\n ! cr, ci two or three dimensional arrays (see input parameter nt)\n ! that contain vector spherical harmonic coefficients\n ! of the vector field (v, w) as computed by subroutine vhagc.\n ! *** cr and ci must be computed by vhagc prior to calling\n ! vrtgc.\n !\n ! mdc the first dimension of the arrays cr and ci as it\n ! appears in the program that calls vrtgc. mdc must be at\n ! least min(nlat, nlon/2) if nlon is even or at least\n ! min(nlat, (nlon + 1)/2) if nlon is odd.\n !\n ! ndc the second dimension of the arrays cr and ci as it\n ! appears in the program that calls vrtgc. ndc must be at\n ! least nlat.\n !\n ! wshsgc an array which must be initialized by subroutine shsgci.\n ! once initialized,\n ! wshsgc can be used repeatedly by vrtgc as long as nlon\n ! and nlat remain unchanged. wshsgc must not be altered\n ! between calls of vrtgc\n !\n ! lshsgc the dimension of the array wshsgc as it appears in the\n ! program that calls vrtgc. define\n !\n ! l1 = min(nlat, (nlon+2)/2) if nlon is even or\n ! l1 = min(nlat, (nlon + 1)/2) if nlon is odd\n !\n ! and\n !\n ! l2 = nlat/2 if nlat is even or\n ! l2 = (nlat + 1)/2 if nlat is odd\n !\n ! then lshsgc must be at least\n !\n ! nlat*(2*l2+3*l1-2)+3*l1*(1-l1)/2+nlon+15\n !\n ! output parameters\n !\n !\n ! vort a two or three dimensional array (see input parameter nt)\n ! that contains the vorticity of the vector field (v, w)\n ! whose coefficients cr, ci where computed by subroutine vhagc.\n ! vort(i, j) is the vorticity at the gaussian colatitude point\n ! theta(i) and longitude point lambda(j) = (j-1)*2*pi/nlon.\n ! the index ranges are defined above at the input parameter\n ! isym.\n !\n !\n ! ierror an error parameter which indicates fatal errors with input\n ! parameters when returned positive.\n ! = 0 no errors\n ! = 1 error in the specification of nlat\n ! = 2 error in the specification of nlon\n ! = 3 error in the specification of isym\n ! = 4 error in the specification of nt\n ! = 5 error in the specification of ivrt\n ! = 6 error in the specification of jvrt\n ! = 7 error in the specification of mdc\n ! = 8 error in the specification of ndc\n ! = 9 error in the specification of lshsgc\n !\n module subroutine vrtgc(nlat, nlon, isym, nt, vort, ivrt, jvrt, &\n cr, ci, mdc, ndc, wshsgc, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n integer(ip), intent(in) :: isym\n integer(ip), intent(in) :: nt\n real(wp), intent(out) :: vort(ivrt, jvrt, nt)\n integer(ip), intent(in) :: ivrt\n integer(ip), intent(in) :: jvrt\n real(wp), intent(in) :: cr(mdc, ndc, nt)\n real(wp), intent(in) :: ci(mdc, ndc, nt)\n integer(ip), intent(in) :: mdc\n integer(ip), intent(in) :: ndc\n real(wp), intent(in) :: wshsgc(:)\n integer(ip), intent(out) :: ierror\n\n ! Local variables\n integer(ip) :: required_wavetable_size\n type(ScalarSynthesisUtility) :: util\n\n ! Check input arguments\n required_wavetable_size = util%get_lshsgc(nlat, nlon)\n\n call util%check_vector_transform_inputs(isym, ivrt, jvrt, &\n mdc, ndc, nlat, nlon, nt, required_wavetable_size, &\n wshsgc, ierror)\n\n ! Check error flag\n if (ierror /= 0) return\n\n call vorticity_lower_utility_routine(nlat, nlon, isym, nt, vort, &\n cr, ci, wshsgc, shsgc, ierror)\n\n end subroutine vrtgc\n\nend submodule vorticity_gaussian_grid\n", "meta": {"hexsha": "e459be65754195761ca531e0638890312685e43b", "size": 11414, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/vorticity_gaussian_grid.f90", "max_stars_repo_name": "jlokimlin/spherepack4.1", "max_stars_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-06-28T14:01:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T21:59:28.000Z", "max_issues_repo_path": "src/vorticity_gaussian_grid.f90", "max_issues_repo_name": "jlokimlin/spherepack4.1", "max_issues_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2016-05-07T23:00:35.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-22T23:52:30.000Z", "max_forks_repo_path": "src/vorticity_gaussian_grid.f90", "max_forks_repo_name": "jlokimlin/spherepack4.1", "max_forks_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-06-28T14:03:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T12:53:54.000Z", "avg_line_length": 50.9553571429, "max_line_length": 111, "alphanum_fraction": 0.486945856, "num_tokens": 2900, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969137, "lm_q2_score": 0.7549149758396752, "lm_q1q2_score": 0.6754899660663854}} {"text": "SUBROUTINE random_wave_signal(i_spec, nt, nx, x0, x, dt, Tp, Hs, depth, &\n grav, inc_wave_file, kh_max, seed, seed2, eta, phiS, eta0, n_cut, time0)\n !-----------------------------------------------------------------------\n !\n ! Generate a pseudo-random long crested wave with direction beta to the \n ! x-axis, over NT time steps at NX points over the 1D computational\n ! free-surface which has a total of NF points. \n ! The x-positions of the points in the wave generation zone are given by x(1:nx) \n ! and the time-step dt is uniform. The water depth at the wavemaker (x0) \n ! is depth. The wave can be based on a P-M (i_spec=0) or JONSWAP (ispec=1) \n ! spectrum, or an input time series read from inc_wave_file (i_spec=2). \n ! The wave is moved around in space using linear theory in the frequency \n ! domain. eta & phiS are returned with the time series\n ! of elevation and potential at z=0 in the wavemaker zone (j=1,nx).\n ! etat0 & phiSt0 hold the initial conditions over the entire domain for the P-M or\n ! JONSWAP case but not for an input wave (this is not implemented yet !HBB). \n ! \n ! When i_spec=-1, a mono-chromatic wave is generated with period Tp and \n ! height Hs. \n !\n !----------------------------------------------------------------------\n IMPLICIT none\n CHARACTER(len=30) inc_wave_file, header\n integer, parameter :: long=selected_real_kind(12,99)\n integer i_spec, seed, seed2, nt, nx, n_cut\n real(kind=long) :: Tp, Hs, dt, depth, time0, x0, grav\n real(kind=long) :: x(nx), phiS(nx,nt), eta(nx,nt), eta0(nt)\n\n ! Local variables\n INTEGER :: i, j\n real(kind=long) :: cosb, sinb, factor, domega, realpt, beta, dx, &\n imagpt, spec, phase, nu, coslnu, sinlnu, magx2, x2(3), x1(2), &\n kinf, omega, dist, realarg, imagarg, reala, imaga, &\n zero=0._long, one=1._long, two=2._long, pi,twopi,udum=1.0_long, &\n velfact, tanhkhi, dt_inc, dum, kh_max, phifact, kh, t, amp\n !\n ! Local workspace\n !\n real(kind=long),Allocatable :: work_eta(:), work_vel(:)\n allocate( work_eta(nt), work_vel(nt) )\n !\n !\n ! Some parameters \n !\n pi=acos(-one)\n twopi=two*pi\n !\n IF(i_spec >= 0)THEN\n ! \n ! Generate the random wave.\n !\n ! The FT factor. \n !\n factor = two/nt\n !\n ! The Fourier coefficients are built based on SI dimensional numbers. Omega is\n ! radian frequency.\n !\n domega = twopi / (nt * dt)\n !\n ! Only waves in the x-direction are implemented at this point -hbb\n !\n beta=zero\n cosb = cos (beta )\n sinb = sin (beta )\n !\n !\n ! Translate the Fourier amplitudes around in space to generate the\n ! eta and phiS coefficients over some portion of the free-surface.\n !\n DO j = 1, nx\n !\n ! Compute the distance (dist) from the origin of the coordinates (x0) to\n ! the point where the wave elevation is to be obtained, measured along\n ! the direction of wave propogation.\n !\n x1 (1) = cos (beta)\n x1 (2) = sin (beta)\n x2 (1) = x(j)-x0\n x2 (2) = zero\n !\n ! Beta is the angle between the (positive sense of the) incident wave\n ! vector and the (positive sense of the) (x,y) point vector.\n !\n dist = x1 (1) * x2 (1) + x1 (2) * x2 (2)\n !\n ! Take care of omega=0 and the Nyquist frequency.\n !\n work_eta(1) = zero\n work_eta(2) = zero\n work_vel(1) = zero\n work_vel(2) = zero\n !\n ! The rest of frequency space.\n !\n DO i = 2, n_cut\n omega = (i - 1) * domega\n kinf = omega * omega / grav\n IF (depth.gt.zero) then\n ! Calling this routine with udum=1. gives the SI dimensional wavenumber.\n CALL fdwvnum (depth, omega, kinf, udum, grav, nu)\n ELSE\n nu = kinf\n ENDIF\n !\n ! Multiply each Fourier coefficient\n ! by e^-i*nu*l to shift it to the point (x,y). The coefficients are defined\n ! such that eta(t) = Re B(omega) e^(omega t - k theta).\n !\n if(nu*depth > 15.0)then\n ! this wave component is in infinite depth (to double-precision).\n velfact = omega\n else\n ! this wave component is in finite depth.\n tanhkhi = cosh(nu*depth)/sinh(nu*depth)\n velfact = omega * tanhkhi\n end if\n phifact=grav/omega\n !\n coslnu = cos (nu * dist)\n sinlnu = sin (nu * dist)\n reala = eta0(2*i-1)\n imaga = eta0(2*i)\n realarg = (reala * coslnu - imaga * sinlnu)\n imagarg = (coslnu * imaga + sinlnu * reala)\n work_eta(2*i-1) = realarg\n work_eta(2*i) = imagarg\n !\n ! The horizontal surface velocity\n !\n ! work_vel(2*i-1) = x1(1) * velfact * realarg\n ! work_vel(2*i) = x1(1) * velfact * imagarg\n !\n ! The surface velocity potential\n !\n work_vel(2*i-1) = phifact * imagarg\n work_vel(2*i) = -phifact * realarg\n enddo\n do i=n_cut+1,nt/2\n work_eta(2*i-1)=zero\n work_eta(2*i) = zero\n work_vel(2*i-1) = zero\n work_vel(2*i) = zero\n end do\n ! Inverse transform to get the time-series at this j-point.\n CALL drealft (work_eta, nt, -1)\n CALL drealft (work_vel, nt, -1)\n eta(j,:)=work_eta(:)\n phiS(j,:)=work_vel(:)\n enddo\n ELSE\n !\n ! For the monochromatic case things are much simpler.\n !\n omega=twopi/Tp\n kinf=omega**2/grav; \n ! Get the wavenumber nu\n CALL fdwvnum(depth,omega,kinf,one,grav,nu)\n amp=Hs/two\n phifact=grav/omega\n !\n do i=1,nt\n t=time0+(i-1)*dt\n eta0(i)=amp*cos(-omega*t)\n do j=1,nx\n dist=x(j)-x0\n eta(j,i)=amp*cos(nu*dist-omega*t)\n phiS(j,i)=phifact*amp*sin(nu*dist-omega*t)\n end do\n end do\n !\n ! Write the wavemaker signal.\n !\n open(21,file='eta0_irregular',status='unknown')\n write(21,36)Hs,Tp,depth\n36 format('% Mono-chromatic wave with H=',e12.4,' T=',e12.4,' at x=',e12.4,'.')\n do i=1,nt\n write(21,*)(i-1)*dt,eta0(i)\n end do\n close(21)\n END IF\n\n DEALLOCATE(work_eta, work_vel)\n444 FORMAT ()\n445 FORMAT(3e12.5)\n RETURN\nEND SUBROUTINE random_wave_signal\n", "meta": {"hexsha": "7b337ca42fbf3cc0bb55a201dab1963290e5c1b5", "size": 6491, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/utilities/random_wave_signal.f90", "max_stars_repo_name": "apengsigkarup/OceanWave3D", "max_stars_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 46, "max_stars_repo_stars_event_min_datetime": "2016-01-08T12:36:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T06:56:45.000Z", "max_issues_repo_path": "src/utilities/random_wave_signal.f90", "max_issues_repo_name": "apengsigkarup/OceanWave3D", "max_issues_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-10-10T19:45:08.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-07T07:37:11.000Z", "max_forks_repo_path": "src/utilities/random_wave_signal.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": 34.5265957447, "max_line_length": 87, "alphanum_fraction": 0.5487598213, "num_tokens": 1963, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133481428692, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6754164671423722}} {"text": "!-----------------------------------------------------------------------------------\n!-----------------------------------------------------------------------------------\n!-----------------------BIVARIATE B-SPLINE EVALUATION ROUTINE-----------------------\n!-----------------------------------------------------------------------------------\n!--------------------------------Benjamin D. Donovan--------------------------------\n!-----------------------------------------------------------------------------------\n!-----------------------------------------------------------------------------------\n!\n!\n!-----------------------------------------------------------------------------------\n!BIVARIATEBSPLINEEV\n!\n!A subroutine to return the value of the interpolation at the coordinate (x,y).\n!\n!Parameters:\n!-----------\n!x : The x-coordinate of the point of interest.\n!y : The y-coordinate of the point of interest.\n!u : The knot vector for the x variable.\n! Comes from scipy.interpolate.SmoothBivariateSpline().get_knots()\n!v : The knot vector for the y variable.\n! Comes from scipy.interpolate.SmoothBivariateSpline().get_knots()\n!coeff : The 4x4 array of the coefficients.\n! Comes from scipy.interpolate.SmoothBivariateSpline().get_coeffs()\n!dx : The derivative with respect to x. \n!dy : The derivative with respect to y.\n!summ : The z-value at the coordinate (x,y).\n!\n!Notes:\n!------\n!1. For interfacing with scipy.interpolate.SmoothBivariateSpline, the array of\n! coefficients must be reshaped from a 1D array with 16 elements to a 2D with\n! 4 rows and 4 columns.\n!2. If you make the value of 'dx' or 'dy' anything other than 0 or 1, your value\n! from the subroutine will be zero.\n!3. Information on the summation performed in this subroutine can be found at:\n! http://www.cs.mtu.edu/~shene/COURSES/cs3621/NOTES/surface/bspline-construct.html\n!-----------------------------------------------------------------------------------\n\nsubroutine bivariateBSplineEv(x, y, u, v, coeff, dx, dy, summ)\n\n !Declaration of all variables used in the subroutine.\n implicit none\n real, intent(in) :: x, y\n real, dimension(0:7) :: u, v\n integer, intent(in) :: dx, dy\n real, dimension(0:3,0:3) :: coeff\n integer :: i, j\n real :: bSplineBasisDerivative, bSplineBasisFcn\n real, intent(out) :: summ\n \n !Define the summ value to be zero.\n summ = 0.\n \n !Perform the summation. Information about the summation can be found in the link above.\n do i=0,3\n do j=0,3\n if ((dx==0) .and. (dy==0)) then\n summ = summ + bSplineBasisFcn(i, 3, u, x) * bSplineBasisFcn(j, 3, v, y) * coeff(i, j)\n else if ((dx==1) .and. (dy==0)) then\n summ = summ + bSplineBasisDerivative(i, 3, u, x) * bSplineBasisFcn(j, 3, v, y) * coeff(i, j)\n else if ((dx==0) .and. (dy==1)) then\n summ = summ + bSplineBasisFcn(i, 3, u, x) * bSplineBasisDerivative(j, 3, v, y) * coeff(i, j)\n end if\n end do\n end do\n\nend subroutine bivariateBSplineEv\n\n!-----------------------------------------------------------------------------------\n!BSPLINEBASISDERIVATIVE\n!\n!A recursive function to evaluate the derivative of the i-th B-spline basis function\n!of degree p.\n!\n!Parameters:\n!-----------\n!i : The i-th B-spline basis function to evaluate.\n!p : The degree of the i-th B-spline basis function.\n!u : The array of knots.\n!x : Point at which to evalute the i-th B-spline basis function derivative of\n! of degree p.\n!\n!Results:\n!--------\n!bSBFD : Value of the specified B-spline basis function derivative at x.\n!-----------------------------------------------------------------------------------\n\nrecursive function bSplineBasisDerivative(i, p, u, x) result(bSBFD)\n\n !Declaration of variables used in the recursive function.\n implicit none\n integer :: i, p\n real, intent(in) :: x\n real, dimension(0:7) :: u\n real :: c, d, e, f, bSBFD1, bSBFD2, bSBFD, bSplineBasisFcn\n\n !If the degree of the B-spline basis function equals zero, the derivative of the\n !B-spline basis function is zero.\n if (p .eq. 0) then\n bSBFD = 0.\n\n !Otherwise, the value needs to be calculated. \n else \n if (u(i+p) - u(i) .eq. 0.) then\n c = 0.\n d = 0.\n else \n c = 1/(u(i+p) - u(i))\n d = (x - u(i))/(u(i+p)-u(i))\n end if\n\n if (u(i+p+1) - u(i+1) .eq. 0.) then\n e = 0.\n f = 0.\n else\n e = 1/(u(i+p+1) - u(i+1))\n f = (u(i+p+1) - x)/(u(i+p+1) - u(i+1))\n end if\n\n !Recursive calculation of the B-spline basis function derivative.\n bSBFD1 = c * bSplineBasisFcn(i,p-1,u,x) + d * bSplineBasisDerivative(i,p-1,u,x)\n bSBFD2 = -e * bSplineBasisFcn(i+1,p-1,u,x) + f * bSplineBasisDerivative(i+1,p-1,u,x)\n bSBFD = bSBFD1 + bSBFD2\n end if\n\nend function bSplineBasisDerivative\n\n!-----------------------------------------------------------------------------------\n!BSPLINEBASISFCN\n!\n!A recursive function to evaluate i-th B-spline basis function of degree p.\n!\n!Parameters:\n!-----------\n!i : The i-th B-spline basis function to evaluate.\n!p : The degree of the i-th B-spline basis function.\n!u : The array of knots.\n!z : Point at which to evalute the i-th B-spline basis function derivative of\n! of degree p.\n!\n!Results:\n!--------\n!bSBF : Value of the specified B-spline basis function derivative at x.\n!-----------------------------------------------------------------------------------\nrecursive function bSplineBasisFcn(i, p, u, z) result(bSBF)\n\n !Declaration of variables used in the recursive function. \n implicit none\n integer :: i, p\n real, intent(in) :: z \n real, dimension(0:7) :: u\n real :: a, b, bSBF\n\n !If the degree of the basis function is zero, the basis function is zero or one,\n !depending on whether or not z is between the i-th and the i-th + 1 knot.\n if (p .eq. 0) then\n if (u(i) .le. z .and. z .lt. u(i+1)) then\n bSBF = 1.\n else\n bSBF = 0.\n end if\n\n !If the degree of the basis function is not zero, it must be calculated.\n else\n if (u(i+p) - u(i) .eq. 0.) then\n a = 0\n else\n a = (z - u(i))/(u(i+p)-u(i))\n end if\n\n if (u(i+p+1) - u(i+1) .eq. 0.) then\n b = 0\n else \n b = (u(i+p+1) - z)/(u(i+p+1) - u(i+1))\n end if\n\n !Recursive calculation of the B-spline basis function.\n bSBF = a * bSplineBasisFcn(i, p-1, u, z) + b * bSplineBasisFcn(i+1, p-1, u, z)\n end if\n\nend function bSplineBasisFcn", "meta": {"hexsha": "0d1947be47096715a3532019c043e25d93d1b42f", "size": 6323, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "bSplineEv.f95", "max_stars_repo_name": "bddonovan/PyXFocus", "max_stars_repo_head_hexsha": "2d6722f0db28c045df35075487f9d4fdfed8b284", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-04-20T15:32:24.000Z", "max_stars_repo_stars_event_max_datetime": "2018-04-20T15:32:24.000Z", "max_issues_repo_path": "bSplineEv.f95", "max_issues_repo_name": "bddonovan/PyXFocus", "max_issues_repo_head_hexsha": "2d6722f0db28c045df35075487f9d4fdfed8b284", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2017-11-03T16:13:46.000Z", "max_issues_repo_issues_event_max_datetime": "2019-04-26T11:13:03.000Z", "max_forks_repo_path": "bSplineEv.f95", "max_forks_repo_name": "bddonovan/PyXFocus", "max_forks_repo_head_hexsha": "2d6722f0db28c045df35075487f9d4fdfed8b284", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-04-13T17:24:54.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-08T15:27:29.000Z", "avg_line_length": 34.7417582418, "max_line_length": 100, "alphanum_fraction": 0.5389846592, "num_tokens": 1825, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133464597458, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6754164659328892}} {"text": "subroutine angle_cdf ( x, n, cdf )\n\n!*****************************************************************************80\n!\n!! ANGLE_CDF evaluates the Angle CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 03 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Reuven Rubinstein,\n! Monte Carlo Optimization, Simulation and Sensitivity of Queueing Networks,\n! Krieger, 1992,\n! ISBN: 0894647644,\n! LC: QA298.R79\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Input, integer ( kind = 4 ) N, the spatial dimension.\n! N must be at least 2.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) cdf\n integer ( kind = 4 ) n\n real ( kind = 8 ) n_real\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) r8_gamma\n real ( kind = 8 ) sin_power_int\n real ( kind = 8 ) x\n real ( kind = 8 ), parameter :: zero = 0.0D+00\n\n if ( n < 2 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'ANGLE_CDF - Fatal error!'\n write ( *, '(a)' ) ' N must be at least 2.'\n write ( *, '(a,i8)' ) ' The input value of N = ', n\n stop 1\n end if\n\n if ( x <= 0.0D+00 ) then\n cdf = 0.0D+00\n else if ( pi <= x ) then\n cdf = 1.0D+00\n else if ( n == 2 ) then\n cdf = x / pi\n else\n n_real = real ( n, kind = 8 )\n cdf = sin_power_int ( zero, x, n - 2 ) * r8_gamma ( n_real / 2.0D+00 ) &\n / ( sqrt ( pi ) * r8_gamma ( ( n_real - 1.0D+00 ) / 2.0D+00 ) )\n end if\n\n return\nend\nsubroutine angle_mean ( n, mean )\n\n!*****************************************************************************80\n!\n!! ANGLE_MEAN returns the mean of the Angle PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the spatial dimension.\n! N must be at least 2.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) mean\n integer ( kind = 4 ) n\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n\n mean = pi / 2.0D+00\n\n return\nend\nsubroutine angle_pdf ( x, n, pdf )\n\n!*****************************************************************************80\n!\n!! ANGLE_PDF evaluates the Angle PDF.\n!\n! Discussion:\n!\n! X is an angle between 0 and PI, corresponding to the angle\n! made in an N-dimensional space, between a fixed line passing\n! through the origin, and an arbitrary line that also passes\n! through the origin, which is specified by a choosing any point\n! on the N-dimensional sphere with uniform probability.\n!\n! The formula is\n!\n! PDF(X) = ( sin ( X ) )^(N-2) * Gamma ( N / 2 )\n! / ( sqrt ( PI ) * Gamma ( ( N - 1 ) / 2 ) )\n!\n! PDF(X) = 1 / PI if N = 2.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Reuven Rubinstein,\n! Monte Carlo Optimization, Simulation and Sensitivity of Queueing Networks,\n! Krieger, 1992,\n! ISBN: 0894647644,\n! LC: QA298.R79\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Input, integer ( kind = 4 ) N, the spatial dimension.\n! N must be at least 2.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) n\n real ( kind = 8 ) pdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) r8_gamma\n real ( kind = 8 ) x\n\n if ( n < 2 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'ANGLE_PDF - Fatal error!'\n write ( *, '(a)' ) ' N must be at least 2.'\n write ( *, '(a,i8)' ) ' The input value of N = ', n\n stop 1\n end if\n\n if ( x < 0.0D+00 .or. pi < x ) then\n pdf = 0.0D+00\n else if ( n == 2 ) then\n pdf = 1.0D+00 / pi\n else\n pdf = &\n ( sin ( x ) )**( n - 2 ) * r8_gamma ( real ( n, kind = 8 ) / 2.0D+00 ) &\n / ( sqrt ( pi ) * r8_gamma ( real ( n - 1, kind = 8 ) / 2.0D+00 ) )\n end if\n\n return\nend\nsubroutine anglit_cdf ( x, cdf )\n\n!*****************************************************************************80\n!\n!! ANGLIT_CDF evaluates the Anglit CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 29 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) cdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) x\n\n if ( x < - 0.25D+00 * pi ) then\n cdf = 0.0D+00\n else if ( x < 0.25D+00 * pi ) then\n cdf = 0.5D+00 - 0.5D+00 * cos ( 2.0D+00 * x + pi / 2.0D+00 )\n else\n cdf = 1.0D+00\n end if\n\n return\nend\nsubroutine anglit_cdf_inv ( cdf, x )\n\n!*****************************************************************************80\n!\n!! ANGLIT_CDF_INV inverts the Anglit CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 29 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument.\n!\n implicit none\n\n real ( kind = 8 ) cdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'ANGLIT_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n x = 0.5D+00 * ( acos ( 1.0D+00 - 2.0D+00 * cdf ) - pi / 2.0D+00 )\n\n return\nend\nsubroutine anglit_mean ( mean )\n\n!*****************************************************************************80\n!\n!! ANGLIT_MEAN returns the mean of the Anglit PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) mean\n\n mean = 0.0D+00\n\n return\nend\nsubroutine anglit_pdf ( x, pdf )\n\n!*****************************************************************************80\n!\n!! ANGLIT_PDF evaluates the Anglit PDF.\n!\n! Discussion:\n!\n! PDF(X) = sin ( 2 * X + PI / 2 ) for -PI/4 <= X <= PI/4\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) pdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) x\n\n if ( x <= - 0.25D+00 * pi .or. 0.25D+00 * pi <= x ) then\n pdf = 0.0D+00\n else\n pdf = sin ( 2.0D+00 * x + 0.25D+00 * pi )\n end if\n\n return\nend\nsubroutine anglit_sample ( seed, x )\n\n!*****************************************************************************80\n!\n!! ANGLIT_SAMPLE samples the Anglit PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random\n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call anglit_cdf_inv ( cdf, x )\n\n return\nend\nsubroutine anglit_variance ( variance )\n\n!*****************************************************************************80\n!\n!! ANGLIT_VARIANCE returns the variance of the Anglit PDF.\n!\n! Discussion:\n!\n! Variance =\n! Integral ( -PI/4 <= X <= PI/4 ) X^2 * sin ( 2 * X + PI / 2 )\n!\n! Antiderivative =\n! 0.5D+00 * X * sin ( 2 * X + PI / 2 )\n! + ( 0.25 - 0.5D+00 * X^2 ) * cos ( 2 * X + PI / 2 )\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 29 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) variance\n\n variance = 0.0625D+00 * pi * pi - 0.5D+00\n\n return\nend\nsubroutine arcsin_cdf ( x, a, cdf )\n\n!*****************************************************************************80\n!\n!! ARCSIN_CDF evaluates the Arcsin CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 March 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n!\n! Input, real ( kind = 8 ) A, the parameter of the CDF.\n! A must be positive.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) cdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) x\n\n if ( x <= -a ) then\n cdf = 0.0D+00\n else if ( x < a ) then\n cdf = 0.5D+00 + asin ( x / a ) / pi\n else\n cdf = 1.0D+00\n end if\n\n return\nend\nsubroutine arcsin_cdf_inv ( cdf, a, x )\n\n!*****************************************************************************80\n!\n!! ARCSIN_CDF_INV inverts the Arcsin CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 March 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Input, real ( kind = 8 ) A, the parameter of the CDF.\n! A must be positive.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) cdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'ARCSIN_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n x = a * sin ( pi * ( cdf - 0.5D+00 ) )\n\n return\nend\nfunction arcsin_check ( a )\n\n!*****************************************************************************80\n!\n!! ARCSIN_CHECK checks the parameter of the Arcsin CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 27 October 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 0.0 < A.\n!\n! Output, logical ARCSIN_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n logical arcsin_check\n\n if ( a <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'ARCSIN_CHECK - Fatal error!'\n write ( *, '(a)' ) ' A <= 0.'\n arcsin_check = .false.\n return\n end if\n\n arcsin_check = .true.\n\n return\nend\nsubroutine arcsin_mean ( a, mean )\n\n!*****************************************************************************80\n!\n!! ARCSIN_MEAN returns the mean of the Arcsin PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 March 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the parameter of the CDF.\n! A must be positive.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) mean\n\n mean = 0.0D+00\n\n return\nend\nsubroutine arcsin_pdf ( x, a, pdf )\n\n!*****************************************************************************80\n!\n!! ARCSIN_PDF evaluates the Arcsin PDF.\n!\n! Discussion:\n!\n! The LOGISTIC EQUATION has the form:\n!\n! X(N+1) = 4 * LAMBDA * ( 1 - X(N) ).\n!\n! where 0 < LAMBDA <= 1. This nonlinear difference equation maps\n! the unit interval into itself, and is a simple example of a system\n! exhibiting chaotic behavior. Ulam and von Neumann studied the\n! logistic equation with LAMBDA = 1, and showed that iterates of the\n! function generated a sequence of pseudorandom numbers with\n! the Arcsin probability density function.\n!\n! The derived sequence\n!\n! Y(N) = ( 2 / PI ) * Arcsin ( SQRT ( X(N) ) )\n!\n! is a pseudorandom sequence with the uniform probability density\n! function on [0,1]. For certain starting values, such as X(0) = 0, 0.75,\n! or 1.0D+00, the sequence degenerates into a constant sequence, and for\n! values very near these, the sequence takes a while before becoming\n! chaotic.\n!\n! The formula is:\n!\n! PDF(X) = 1 / ( pi * sqrt ( A^2 - X^2 ) )\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 March 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Daniel Zwillinger, Stephen Kokoska,\n! CRC Standard Probability and Statistics Tables and Formulae,\n! Chapman and Hall/CRC, 2000, pages 114-115.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n! -A < X < A.\n!\n! Input, real ( kind = 8 ) A, the parameter of the CDF.\n! A must be positive.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) pdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) x\n\n if ( a <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'ARCSIN_PDF - Fatal error!'\n write ( *, '(a)' ) ' Parameter A must be positive.'\n stop 1\n end if\n\n if ( x <= -a .or. a <= x ) then\n pdf = 0.0D+00\n else\n pdf = 1.0D+00 / ( pi * sqrt ( a * a - x * x ) )\n end if\n\n return\nend\nsubroutine arcsin_sample ( a, seed, x )\n\n!*****************************************************************************80\n!\n!! ARCSIN_SAMPLE samples the Arcsin PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 March 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the parameter of the CDF.\n! A must be positive.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random\n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call arcsin_cdf_inv ( cdf, a, x )\n\n return\nend\nsubroutine arcsin_variance ( a, variance )\n\n!*****************************************************************************80\n!\n!! ARCSIN_VARIANCE returns the variance of the Arcsin PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 March 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the parameter of the CDF.\n! A must be positive.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) variance\n\n variance = a * a / 2.0D+00\n\n return\nend\nsubroutine benford_pdf ( x, pdf )\n\n!*****************************************************************************80\n!\n!! BENFORD_PDF returns the Benford PDF.\n!\n! Discussion:\n!\n! Benford's law is an empirical formula explaining the observed\n! distribution of initial digits in lists culled from newspapers,\n! tax forms, stock market prices, and so on. It predicts the observed\n! high frequency of the initial digit 1, for instance.\n!\n! Note that the probabilities of digits 1 through 9 are guaranteed\n! to add up to 1, since\n! LOG10 ( 2/1 ) + LOG10 ( 3/2) + LOG10 ( 4/3 ) + ... + LOG10 ( 10/9 )\n! = LOG10 ( 2/1 * 3/2 * 4/3 * ... * 10/9 ) = LOG10 ( 10 ) = 1.\n!\n! The formula is:\n!\n! PDF(X) = LOG10 ( ( X + 1 ) / X ).\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 13 August 1998\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Frank Benford,\n! The Law of Anomalous Numbers,\n! Proceedings of the American Philosophical Society,\n! Volume 78, pages 551-572, 1938.\n!\n! Ted Hill,\n! The First Digit Phenomenon,\n! American Scientist,\n! Volume 86, July/August 1998, pages 358 - 363.\n!\n! Ralph Raimi,\n! The Peculiar Distribution of First Digits,\n! Scientific American,\n! December 1969, pages 109-119.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X, the string of significant digits to be\n! checked. If X is 1, then we are asking for the Benford probability that\n! a value will have first digit 1. If X is 123, we are asking for\n! the probability that the first three digits will be 123, and so on.\n!\n! Output, real ( kind = 8 ) PDF, the Benford probability that an item taken\n! from a real world distribution will have the initial digits X.\n!\n implicit none\n\n real ( kind = 8 ) pdf\n integer ( kind = 4 ) x\n\n if ( x <= 0 ) then\n pdf = 0.0D+00\n else\n pdf = log10 ( real ( x + 1, kind = 8 ) / real ( x, kind = 8 ) )\n end if\n\n return\nend\nsubroutine bessel_ix_values ( n_data, nu, x, fx )\n\n!*****************************************************************************80\n!\n!! BESSEL_IX_VALUES returns some values of the Ix Bessel function.\n!\n! Discussion:\n!\n! This set of data considers the less common case in which the\n! index of the Bessel function In is actually not an integer.\n! We may suggest this case by occasionally replacing the symbol\n! \"In\" by \"Ix\".\n!\n! The modified Bessel functions In(Z) and Kn(Z) are solutions of\n! the differential equation\n!\n! Z^2 W'' + Z * W' - ( Z^2 + N^2 ) * W = 0.\n!\n! In Mathematica, the function can be evaluated by:\n!\n! BesselI[n,x]\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 March 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Milton Abramowitz, Irene Stegun,\n! Handbook of Mathematical Functions,\n! National Bureau of Standards, 1964,\n! ISBN: 0-486-61272-4,\n! LC: QA47.A34.\n!\n! Stephen Wolfram,\n! The Mathematica Book,\n! Fourth Edition,\n! Cambridge University Press, 1999,\n! ISBN: 0-521-64314-7,\n! LC: QA76.95.W65.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) N_DATA. The user sets N_DATA to 0\n! before the first call. On each call, the routine increments N_DATA by 1,\n! and returns the corresponding data; when there is no more data, the\n! output value of N_DATA will be 0 again.\n!\n! Output, real ( kind = 8 ) NU, the order of the function.\n!\n! Output, real ( kind = 8 ) X, the argument of the function.\n!\n! Output, real ( kind = 8 ) FX, the value of the function.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: n_max = 28\n\n real ( kind = 8 ) fx\n real ( kind = 8 ), save, dimension ( n_max ) :: fx_vec = (/ &\n 0.3592084175833614D+00, &\n 0.9376748882454876D+00, &\n 2.046236863089055D+00, &\n 3.053093538196718D+00, &\n 4.614822903407601D+00, &\n 26.47754749755907D+00, &\n 2778.784603874571D+00, &\n 4.327974627242893D+07, &\n 0.2935253263474798D+00, &\n 1.099473188633110D+00, &\n 21.18444226479414D+00, &\n 2500.906154942118D+00, &\n 2.866653715931464D+20, &\n 0.05709890920304825D+00, &\n 0.3970270801393905D+00, &\n 13.76688213868258D+00, &\n 2028.512757391936D+00, &\n 2.753157630035402D+20, &\n 0.4139416015642352D+00, &\n 1.340196758982897D+00, &\n 22.85715510364670D+00, &\n 2593.006763432002D+00, &\n 2.886630075077766D+20, &\n 0.03590910483251082D+00, &\n 0.2931108636266483D+00, &\n 11.99397010023068D+00, &\n 1894.575731562383D+00, &\n 2.716911375760483D+20 /)\n integer ( kind = 4 ) n_data\n real ( kind = 8 ) nu\n real ( kind = 8 ), save, dimension ( n_max ) :: nu_vec = (/ &\n 0.50D+00, &\n 0.50D+00, &\n 0.50D+00, &\n 0.50D+00, &\n 0.50D+00, &\n 0.50D+00, &\n 0.50D+00, &\n 0.50D+00, &\n 1.50D+00, &\n 1.50D+00, &\n 1.50D+00, &\n 1.50D+00, &\n 1.50D+00, &\n 2.50D+00, &\n 2.50D+00, &\n 2.50D+00, &\n 2.50D+00, &\n 2.50D+00, &\n 1.25D+00, &\n 1.25D+00, &\n 1.25D+00, &\n 1.25D+00, &\n 1.25D+00, &\n 2.75D+00, &\n 2.75D+00, &\n 2.75D+00, &\n 2.75D+00, &\n 2.75D+00 /)\n real ( kind = 8 ) x\n real ( kind = 8 ), save, dimension ( n_max ) :: x_vec = (/ &\n 0.2D+00, &\n 1.0D+00, &\n 2.0D+00, &\n 2.5D+00, &\n 3.0D+00, &\n 5.0D+00, &\n 10.0D+00, &\n 20.0D+00, &\n 1.0D+00, &\n 2.0D+00, &\n 5.0D+00, &\n 10.0D+00, &\n 50.0D+00, &\n 1.0D+00, &\n 2.0D+00, &\n 5.0D+00, &\n 10.0D+00, &\n 50.0D+00, &\n 1.0D+00, &\n 2.0D+00, &\n 5.0D+00, &\n 10.0D+00, &\n 50.0D+00, &\n 1.0D+00, &\n 2.0D+00, &\n 5.0D+00, &\n 10.0D+00, &\n 50.0D+00 /)\n\n if ( n_data < 0 ) then\n n_data = 0\n end if\n\n n_data = n_data + 1\n\n if ( n_max < n_data ) then\n n_data = 0\n nu = 0.0D+00\n x = 0.0D+00\n fx = 0.0D+00\n else\n nu = nu_vec(n_data)\n x = x_vec(n_data)\n fx = fx_vec(n_data)\n end if\n\n return\nend\nsubroutine birthday_cdf ( n, cdf )\n\n!*****************************************************************************80\n!\n!! BIRTHDAY_CDF returns the Birthday Concurrence CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 26 August 2006\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of people whose birthdays have\n! been disclosed.\n!\n! Output, real ( kind = 8 ) CDF, the probability that at least\n! two of the N people have matching birthays.\n!\n implicit none\n\n real ( kind = 8 ) cdf\n integer ( kind = 4 ) i\n integer ( kind = 4 ) n\n\n if ( n < 1 ) then\n cdf = 0.0D+00\n return\n else if ( 365 < n ) then\n cdf = 1.0D+00\n return\n end if\n!\n! Compute the probability that N people have distinct birthdays.\n!\n cdf = 1.0D+00\n do i = 1, n\n cdf = cdf * real ( 365 + 1 - i, kind = 8 ) / 365.0D+00\n end do\n!\n! Compute the probability that it is NOT the case that N people\n! have distinct birthdays. This is the cumulative probability\n! that person 2 matches person 1, or person 3 matches 1 or 2,\n! etc.\n!\n cdf = 1.0D+00 - cdf\n\n return\nend\nsubroutine birthday_cdf_inv ( cdf, n )\n\n!*****************************************************************************80\n!\n!! BIRTHDAY_CDF_INV inverts the Birthday Concurrence CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 26 August 2006\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the probability that at least\n! two of the N people have matching birthays.\n!\n! Output, integer ( kind = 4 ) N, the corresponding number of people whose\n! birthdays need to be disclosed.\n!\n implicit none\n\n real ( kind = 8 ) cdf\n real ( kind = 8 ) cdf_not\n integer ( kind = 4 ) i\n integer ( kind = 4 ) n\n\n if ( cdf <= 0.0D+00 ) then\n n = 0\n return\n else if ( 1.0D+00 <= cdf ) then\n n = 365\n return\n end if\n!\n! Compute the probability that N people have distinct birthdays.\n!\n cdf_not = 1.0D+00\n\n do i = 1, 365\n cdf_not = cdf_not * real ( 365 + 1 - i, kind = 8 ) / 365.0D+00\n if ( cdf <= 1.0D+00 - cdf_not ) then\n n = i\n return\n end if\n end do\n\n n = 365\n\n return\nend\nsubroutine birthday_pdf ( n, pdf )\n\n!*****************************************************************************80\n!\n!! BIRTHDAY_PDF returns the Birthday Concurrence PDF.\n!\n! Discussion:\n!\n! The probability is the probability that the N-th person is the\n! first one to match a birthday with someone earlier.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 26 August 2006\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of people whose birthdays have\n! been disclosed.\n!\n! Output, real ( kind = 8 ) PDF, the probability that the N-th person\n! is the first to match a birthday with someone earlier.\n!\n implicit none\n\n integer ( kind = 4 ) i\n integer ( kind = 4 ) n\n real ( kind = 8 ) pdf\n\n if ( n < 1 .or. 365 < n ) then\n pdf = 0.0D+00\n return\n end if\n\n pdf = 1.0D+00\n!\n! Compute the probability that N-1 people have distinct birthdays.\n!\n do i = 1, n-1\n pdf = pdf * real ( 365 + 1 - i, kind = 8 ) / 365.0D+00\n end do\n!\n! Compute the probability that person N has one of those N-1 birthdays.\n!\n pdf = pdf * real ( n - 1, kind = 8 ) / 365.0D+00\n\n return\nend\nsubroutine bernoulli_cdf ( x, a, cdf )\n\n!*****************************************************************************80\n!\n!! BERNOULLI_CDF evaluates the Bernoulli CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 24 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X, the number of successes on a single trial.\n! X = 0 or 1.\n!\n! Input, real ( kind = 8 ) A, the probability of success on one trial.\n! 0.0D+00 <= A <= 1.0.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) cdf\n integer ( kind = 4 ) x\n\n if ( x < 0 ) then\n cdf = 0.0D+00\n else if ( x == 0 ) then\n cdf = 1.0D+00 - a\n else\n cdf = 1.0D+00\n end if\n\n return\nend\nsubroutine bernoulli_cdf_inv ( cdf, a, x )\n\n!*****************************************************************************80\n!\n!! BERNOULLI_CDF_INV inverts the Bernoulli CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 24 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0 <= CDF <= 1.0.\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 0.0 <= A <= 1.0.\n!\n! Output, integer ( kind = 4 ) X, the corresponding argument.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) cdf\n integer ( kind = 4 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BERNOULLI_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n if ( cdf <= 1.0D+00 - a ) then\n x = 0\n else\n x = 1\n end if\n\n return\nend\nfunction bernoulli_check ( a )\n\n!*****************************************************************************80\n!\n!! BERNOULLI_CHECK checks the parameter of the Bernoulli CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 18 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 0.0 <= A <= 1.0.\n!\n! Output, logical BERNOULLI_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n logical bernoulli_check\n\n if ( a < 0.0D+00 .or. 1.0D+00 < a ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BERNOULLI_CHECK - Fatal error!'\n write ( *, '(a)' ) ' A < 0 or 1 < A.'\n bernoulli_check = .false.\n return\n end if\n\n bernoulli_check = .true.\n\n return\nend\nsubroutine bernoulli_mean ( a, mean )\n\n!*****************************************************************************80\n!\n!! BERNOULLI_MEAN returns the mean of the Bernoulli PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 16 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the probability of success.\n! 0.0 <= A <= 1.0.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) mean\n\n mean = a\n\n return\nend\nsubroutine bernoulli_pdf ( x, a, pdf )\n\n!*****************************************************************************80\n!\n!! BERNOULLI_PDF evaluates the Bernoulli PDF.\n!\n! Discussion:\n!\n! PDF(A;X) = A^X * ( 1 - A )^( X - 1 )\n!\n! X = 0 or 1.\n!\n! The Bernoulli PDF describes the simple case in which a single trial\n! is carried out, with two possible outcomes, called \"success\" and\n! \"failure\"; the probability of success is A.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 24 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X, the number of successes on a single trial.\n! X = 0 or 1.\n!\n! Input, real ( kind = 8 ) A, the probability of success on one trial.\n! 0.0 <= A <= 1.0.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) pdf\n integer ( kind = 4 ) x\n\n if ( x < 0 ) then\n pdf = 0.0D+00\n else if ( x == 0 ) then\n pdf = 1.0D+00 - a\n else if ( x == 1 ) then\n pdf = a\n else\n pdf = 0.0D+00\n end if\n\n return\nend\nsubroutine bernoulli_sample ( a, seed, x )\n\n!*****************************************************************************80\n!\n!! BERNOULLI_SAMPLE samples the Bernoulli PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 23 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the probability of success on one trial.\n! 0.0D+00 <= A <= 1.0.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random\n! number generator.\n!\n! Output, integer ( kind = 4 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n integer ( kind = 4 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call bernoulli_cdf_inv ( cdf, a, x )\n\n return\nend\nsubroutine bernoulli_variance ( a, variance )\n\n!*****************************************************************************80\n!\n!! BERNOULLI_VARIANCE returns the variance of the Bernoulli PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 16 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the probability of success on one trial.\n! 0.0 <= A <= 1.0.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) variance\n\n variance = a * ( 1.0D+00 - a )\n\n return\nend\nfunction bessel_i0 ( arg )\n\n!*****************************************************************************80\n!\n!! BESSEL_I0 evaluates the modified Bessel function I0(X).\n!\n! Discussion:\n!\n! The main computation evaluates slightly modified forms of\n! minimax approximations generated by Blair and Edwards, Chalk\n! River (Atomic Energy of Canada Limited) Report AECL-4928,\n! October, 1974. This transportable program is patterned after\n! the machine dependent FUNPACK packet NATSI0, but cannot match\n! that version for efficiency or accuracy. This version uses\n! rational functions that theoretically approximate I-SUB-0(X)\n! to at least 18 significant decimal digits.\n!\n! Machine dependent constants:\n!\n! beta = Radix for the floating-point system\n! maxexp = Smallest power of beta that overflows\n! XMAX = Largest argument acceptable to BESI0; Solution to\n! equation:\n! W(X) * (1+1/(8*X)+9/(128*X^2) = beta^maxexp\n! where W(X) = EXP(X)/sqrt(2*PI*X)\n!\n! Approximate values for some important machines are:\n!\n! beta maxexp XMAX\n!\n! CRAY-1 (S.P.) 2 8191 5682.810\n! Cyber 180/855\n! under NOS (S.P.) 2 1070 745.893\n! IEEE (IBM/XT,\n! SUN, etc.) (S.P.) 2 128 91.900\n! IEEE (IBM/XT,\n! SUN, etc.) (D.P.) 2 1024 713.986\n! IBM 3033 (D.P.) 16 63 178.182\n! VAX (S.P.) 2 127 91.203\n! VAX D-Format (D.P.) 2 127 91.203\n! VAX G-Format (D.P.) 2 1023 713.293\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 17 October 2008\n!\n! Author:\n!\n! Original FORTRAN77 version by William Cody, Laura Stoltz.\n! FORTRAN90 version by John Burkardt.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) ARG, the argument.\n!\n! Output, real ( kind = 8 ) BESSEL_I0, the value of the modified\n! Bessel function of the first kind.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) arg\n real ( kind = 8 ) b\n real ( kind = 8 ) bessel_i0\n real ( kind = 8 ), parameter :: exp40 = 2.353852668370199854D+17\n integer ( kind = 4 ) i\n real ( kind = 8 ), parameter, dimension ( 15 ) :: p = (/ &\n -5.2487866627945699800D-18, &\n -1.5982226675653184646D-14, &\n -2.6843448573468483278D-11, &\n -3.0517226450451067446D-08, &\n -2.5172644670688975051D-05, &\n -1.5453977791786851041D-02, &\n -7.0935347449210549190D+00, &\n -2.4125195876041896775D+03, &\n -5.9545626019847898221D+05, &\n -1.0313066708737980747D+08, &\n -1.1912746104985237192D+10, &\n -8.4925101247114157499D+11, &\n -3.2940087627407749166D+13, &\n -5.5050369673018427753D+14, &\n -2.2335582639474375249D+15 /)\n real ( kind = 8 ), parameter, dimension ( 8 ) :: pp = (/ &\n -3.9843750000000000000D-01, &\n 2.9205384596336793945D+00, &\n -2.4708469169133954315D+00, &\n 4.7914889422856814203D-01, &\n -3.7384991926068969150D-03, &\n -2.6801520353328635310D-03, &\n 9.9168777670983678974D-05, &\n -2.1877128189032726730D-06 /)\n real ( kind = 8 ), parameter, dimension ( 5 ) :: q = (/ &\n -3.7277560179962773046D+03, &\n 6.5158506418655165707D+06, &\n -6.5626560740833869295D+09, &\n 3.7604188704092954661D+12, &\n -9.7087946179594019126D+14 /)\n real ( kind = 8 ), parameter, dimension ( 7 ) :: qq = (/ &\n -3.1446690275135491500D+01, &\n 8.5539563258012929600D+01, &\n -6.0228002066743340583D+01, &\n 1.3982595353892851542D+01, &\n -1.1151759188741312645D+00, &\n 3.2547697594819615062D-02, &\n -5.5194330231005480228D-04 /)\n real ( kind = 8 ), parameter :: rec15 = 6.6666666666666666666D-02\n real ( kind = 8 ) sump\n real ( kind = 8 ) sumq\n real ( kind = 8 ) value\n real ( kind = 8 ) x\n real ( kind = 8 ), parameter :: xmax = 91.9D+00\n real ( kind = 8 ) xx\n\n x = abs ( arg )\n\n if ( x < epsilon ( arg ) ) then\n value = 1.0D+00\n else if ( x < 15.0D+00 ) then\n!\n! EPSILON ( ARG ) <= ABS(ARG) < 15.0D+00\n!\n xx = x * x\n sump = p(1)\n do i = 2, 15\n sump = sump * xx + p(i)\n end do\n\n xx = xx - 225.0D+00\n sumq = (((( &\n xx + q(1) ) &\n * xx + q(2) ) &\n * xx + q(3) ) &\n * xx + q(4) ) &\n * xx + q(5)\n\n value = sump / sumq\n\n else if ( 15.0D+00 <= x ) then\n\n if ( xmax < x ) then\n value = huge ( value )\n else\n!\n! 15.0D+00 <= ABS(ARG)\n!\n xx = 1.0D+00 / x - rec15\n\n sump = (((((( &\n pp(1) &\n * xx + pp(2) ) &\n * xx + pp(3) ) &\n * xx + pp(4) ) &\n * xx + pp(5) ) &\n * xx + pp(6) ) &\n * xx + pp(7) ) &\n * xx + pp(8)\n\n sumq = (((((( &\n xx + qq(1) ) &\n * xx + qq(2) ) &\n * xx + qq(3) ) &\n * xx + qq(4) ) &\n * xx + qq(5) ) &\n * xx + qq(6) ) &\n * xx + qq(7)\n\n value = sump / sumq\n!\n! Calculation reformulated to avoid premature overflow.\n!\n if ( x <= xmax - 15.0D+00 ) then\n a = exp ( x )\n b = 1.0D+00\n else\n a = exp ( x - 40.0D+00 )\n b = exp40\n end if\n\n value = ( ( value * a - pp(1) * a ) / sqrt ( x ) ) * b\n\n end if\n\n end if\n\n bessel_i0 = value\n\n return\nend\nsubroutine bessel_i0_values ( n_data, x, fx )\n\n!*****************************************************************************80\n!\n!! BESSEL_I0_VALUES returns some values of the I0 Bessel function.\n!\n! Discussion:\n!\n! The modified Bessel functions In(Z) and Kn(Z) are solutions of\n! the differential equation\n!\n! Z^2 W'' + Z * W' - ( Z^2 + N^2 ) * W = 0.\n!\n! The modified Bessel function I0(Z) corresponds to N = 0.\n!\n! In Mathematica, the function can be evaluated by:\n!\n! BesselI[0,x]\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 August 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Milton Abramowitz, Irene Stegun,\n! Handbook of Mathematical Functions,\n! National Bureau of Standards, 1964,\n! LC: QA47.A34,\n! ISBN: 0-486-61272-4.\n!\n! Stephen Wolfram,\n! The Mathematica Book,\n! Fourth Edition,\n! Wolfram Media / Cambridge University Press, 1999.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) N_DATA. The user sets N_DATA to 0\n! before the first call. On each call, the routine increments N_DATA by 1,\n! and returns the corresponding data; when there is no more data, the\n! output value of N_DATA will be 0 again.\n!\n! Output, real ( kind = 8 ) X, the argument of the function.\n!\n! Output, real ( kind = 8 ) FX, the value of the function.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: n_max = 20\n\n real ( kind = 8 ) fx\n real ( kind = 8 ), save, dimension ( n_max ) :: fx_vec = (/ &\n 0.1000000000000000D+01, &\n 0.1010025027795146D+01, &\n 0.1040401782229341D+01, &\n 0.1092045364317340D+01, &\n 0.1166514922869803D+01, &\n 0.1266065877752008D+01, &\n 0.1393725584134064D+01, &\n 0.1553395099731217D+01, &\n 0.1749980639738909D+01, &\n 0.1989559356618051D+01, &\n 0.2279585302336067D+01, &\n 0.3289839144050123D+01, &\n 0.4880792585865024D+01, &\n 0.7378203432225480D+01, &\n 0.1130192195213633D+02, &\n 0.1748117185560928D+02, &\n 0.2723987182360445D+02, &\n 0.6723440697647798D+02, &\n 0.4275641157218048D+03, &\n 0.2815716628466254D+04 /)\n integer ( kind = 4 ) n_data\n real ( kind = 8 ) x\n real ( kind = 8 ), save, dimension ( n_max ) :: x_vec = (/ &\n 0.00D+00, &\n 0.20D+00, &\n 0.40D+00, &\n 0.60D+00, &\n 0.80D+00, &\n 0.10D+01, &\n 0.12D+01, &\n 0.14D+01, &\n 0.16D+01, &\n 0.18D+01, &\n 0.20D+01, &\n 0.25D+01, &\n 0.30D+01, &\n 0.35D+01, &\n 0.40D+01, &\n 0.45D+01, &\n 0.50D+01, &\n 0.60D+01, &\n 0.80D+01, &\n 0.10D+02 /)\n\n if ( n_data < 0 ) then\n n_data = 0\n end if\n\n n_data = n_data + 1\n\n if ( n_max < n_data ) then\n n_data = 0\n x = 0.0D+00\n fx = 0.0D+00\n else\n x = x_vec(n_data)\n fx = fx_vec(n_data)\n end if\n\n return\nend\nfunction bessel_i1 ( arg )\n\n!*****************************************************************************80\n!\n!! BESSEL_I1 evaluates the Bessel I function of order I.\n!\n! Discussion:\n!\n! The main computation evaluates slightly modified forms of\n! minimax approximations generated by Blair and Edwards.\n! This transportable program is patterned after the machine-dependent\n! FUNPACK packet NATSI1, but cannot match that version for efficiency\n! or accuracy. This version uses rational functions that theoretically\n! approximate I-SUB-1(X) to at least 18 significant decimal digits.\n! The accuracy achieved depends on the arithmetic system, the compiler,\n! the intrinsic functions, and proper selection of the machine-dependent\n! constants.\n!\n! Machine-dependent constants:\n!\n! beta = Radix for the floating-point system.\n! maxexp = Smallest power of beta that overflows.\n! XMAX = Largest argument acceptable to BESI1; Solution to\n! equation:\n! EXP(X) * (1-3/(8*X)) / SQRT(2*PI*X) = beta**maxexp\n!\n!\n! Approximate values for some important machines are:\n!\n! beta maxexp XMAX\n!\n! CRAY-1 (S.P.) 2 8191 5682.810\n! Cyber 180/855\n! under NOS (S.P.) 2 1070 745.894\n! IEEE (IBM/XT,\n! SUN, etc.) (S.P.) 2 128 91.906\n! IEEE (IBM/XT,\n! SUN, etc.) (D.P.) 2 1024 713.987\n! IBM 3033 (D.P.) 16 63 178.185\n! VAX (S.P.) 2 127 91.209\n! VAX D-Format (D.P.) 2 127 91.209\n! VAX G-Format (D.P.) 2 1023 713.293\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 27 October 2004\n!\n! Author:\n!\n! Original FORTRAN77 version by William Cody, Laura Stoltz.\n! FORTRAN90 version by John Burkardt.\n!\n! Reference:\n!\n! Blair, Edwards,\n! Chalk River Report AECL-4928,\n! Atomic Energy of Canada, Limited,\n! October, 1974.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) ARG, the argument.\n!\n! Output, real ( kind = 8 ) BESSEL_I1, the value of the Bessel\n! I1 function.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) arg\n real ( kind = 8 ) b\n real ( kind = 8 ) bessel_i1\n real ( kind = 8 ), parameter :: exp40 = 2.353852668370199854D+17\n real ( kind = 8 ), parameter :: forty = 40.0D+00\n real ( kind = 8 ), parameter :: half = 0.5D+00\n integer ( kind = 4 ) j\n real ( kind = 8 ), parameter :: one = 1.0D+00\n real ( kind = 8 ), parameter :: one5 = 15.0D+00\n real ( kind = 8 ), dimension(15) :: p = (/ &\n -1.9705291802535139930D-19, &\n -6.5245515583151902910D-16, &\n -1.1928788903603238754D-12, &\n -1.4831904935994647675D-09, &\n -1.3466829827635152875D-06, &\n -9.1746443287817501309D-04, &\n -4.7207090827310162436D-01, &\n -1.8225946631657315931D+02, &\n -5.1894091982308017540D+04, &\n -1.0588550724769347106D+07, &\n -1.4828267606612366099D+09, &\n -1.3357437682275493024D+11, &\n -6.9876779648010090070D+12, &\n -1.7732037840791591320D+14, &\n -1.4577180278143463643D+15 /)\n real ( kind = 8 ) :: pbar = 3.98437500D-01\n real ( kind = 8 ), dimension(8) :: pp = (/ &\n -6.0437159056137600000D-02, &\n 4.5748122901933459000D-01, &\n -4.2843766903304806403D-01, &\n 9.7356000150886612134D-02, &\n -3.2457723974465568321D-03, &\n -3.6395264712121795296D-04, &\n 1.6258661867440836395D-05, &\n -3.6347578404608223492D-07 /)\n real ( kind = 8 ), dimension(5) :: q = (/ &\n -4.0076864679904189921D+03, &\n 7.4810580356655069138D+06, &\n -8.0059518998619764991D+09, &\n 4.8544714258273622913D+12, &\n -1.3218168307321442305D+15 /)\n real ( kind = 8 ), dimension(6) :: qq = (/ &\n -3.8806586721556593450D+00, &\n 3.2593714889036996297D+00, &\n -8.5017476463217924408D-01, &\n 7.4212010813186530069D-02, &\n -2.2835624489492512649D-03, &\n 3.7510433111922824643D-05 /)\n real ( kind = 8 ), parameter :: rec15 = 6.6666666666666666666D-02\n real ( kind = 8 ) sump\n real ( kind = 8 ) sumq\n real ( kind = 8 ), parameter :: two25 = 225.0D+00\n real ( kind = 8 ) value\n real ( kind = 8 ) x\n real ( kind = 8 ), parameter :: xmax = 713.987D+00\n real ( kind = 8 ) xx\n real ( kind = 8 ), parameter :: zero = 0.0D+00\n\n x = abs ( arg )\n!\n! ABS(ARG) < EPSILON ( ARG )\n!\n if ( x < epsilon ( x ) ) then\n\n value = half * x\n!\n! EPSILON ( ARG ) <= ABS(ARG) < 15.0\n!\n else if ( x < one5 ) then\n\n xx = x * x\n sump = p(1)\n do j = 2, 15\n sump = sump * xx + p(j)\n end do\n\n xx = xx - two25\n\n sumq = (((( &\n xx + q(1) &\n ) * xx + q(2) &\n ) * xx + q(3) &\n ) * xx + q(4) &\n ) * xx + q(5)\n\n value = ( sump / sumq ) * x\n\n else if ( xmax < x ) then\n\n value = huge ( x )\n!\n! 15.0 <= ABS(ARG)\n!\n else\n\n xx = one / x - rec15\n\n sump = (((((( &\n pp(1) &\n * xx + pp(2) &\n ) * xx + pp(3) &\n ) * xx + pp(4) &\n ) * xx + pp(5) &\n ) * xx + pp(6) &\n ) * xx + pp(7) &\n ) * xx + pp(8)\n\n sumq = ((((( &\n xx + qq(1) &\n ) * xx + qq(2) &\n ) * xx + qq(3) &\n ) * xx + qq(4) &\n ) * xx + qq(5) &\n ) * xx + qq(6)\n\n value = sump / sumq\n\n if ( xmax - one5 < x ) then\n a = exp ( x - forty )\n b = exp40\n else\n a = exp ( x )\n b = one\n end if\n\n value = ( ( value * a + pbar * a ) / sqrt ( x ) ) * b\n\n end if\n\n if ( arg < zero ) then\n value = -value\n end if\n\n bessel_i1 = value\n\n return\nend\nsubroutine bessel_i1_values ( n_data, x, fx )\n\n!*****************************************************************************80\n!\n!! BESSEL_I1_VALUES returns some values of the I1 Bessel function.\n!\n! Discussion:\n!\n! The modified Bessel functions In(Z) and Kn(Z) are solutions of\n! the differential equation\n!\n! Z^2 W'' + Z * W' - ( Z^2 + N^2 ) * W = 0.\n!\n! In Mathematica, the function can be evaluated by:\n!\n! BesselI[1,x]\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 August 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Milton Abramowitz, Irene Stegun,\n! Handbook of Mathematical Functions,\n! National Bureau of Standards, 1964,\n! LC: QA47.A34,\n! ISBN: 0-486-61272-4.\n!\n! Stephen Wolfram,\n! The Mathematica Book,\n! Fourth Edition,\n! Wolfram Media / Cambridge University Press, 1999.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) N_DATA. The user sets N_DATA to 0 \n! before the first call. On each call, the routine increments N_DATA by 1, \n! and returns the corresponding data; when there is no more data, the\n! output value of N_DATA will be 0 again.\n!\n! Output, real ( kind = 8 ) X, the argument of the function.\n!\n! Output, real ( kind = 8 ) FX, the value of the function.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: n_max = 20\n\n real ( kind = 8 ) fx\n real ( kind = 8 ), save, dimension ( n_max ) :: fx_vec = (/ &\n 0.0000000000000000D+00, &\n 0.1005008340281251D+00, &\n 0.2040267557335706D+00, &\n 0.3137040256049221D+00, &\n 0.4328648026206398D+00, &\n 0.5651591039924850D+00, &\n 0.7146779415526431D+00, &\n 0.8860919814143274D+00, &\n 0.1084810635129880D+01, &\n 0.1317167230391899D+01, &\n 0.1590636854637329D+01, &\n 0.2516716245288698D+01, &\n 0.3953370217402609D+01, &\n 0.6205834922258365D+01, &\n 0.9759465153704450D+01, &\n 0.1538922275373592D+02, &\n 0.2433564214245053D+02, &\n 0.6134193677764024D+02, &\n 0.3998731367825601D+03, &\n 0.2670988303701255D+04 /)\n integer ( kind = 4 ) n_data\n real ( kind = 8 ) x\n real ( kind = 8 ), save, dimension ( n_max ) :: x_vec = (/ &\n 0.00D+00, &\n 0.20D+00, &\n 0.40D+00, &\n 0.60D+00, &\n 0.80D+00, &\n 0.10D+01, &\n 0.12D+01, &\n 0.14D+01, &\n 0.16D+01, &\n 0.18D+01, &\n 0.20D+01, &\n 0.25D+01, &\n 0.30D+01, &\n 0.35D+01, &\n 0.40D+01, &\n 0.45D+01, &\n 0.50D+01, &\n 0.60D+01, &\n 0.80D+01, &\n 0.10D+02 /)\n\n if ( n_data < 0 ) then\n n_data = 0\n end if\n\n n_data = n_data + 1\n\n if ( n_max < n_data ) then\n n_data = 0\n x = 0.0D+00\n fx = 0.0D+00\n else\n x = x_vec(n_data)\n fx = fx_vec(n_data)\n end if\n\n return\nend\nfunction beta ( a, b )\n\n!*****************************************************************************80\n!\n!! BETA returns the value of the Beta function.\n!\n! Discussion:\n!\n! The Beta function is defined as\n!\n! BETA(A,B) = ( GAMMA ( A ) * GAMMA ( B ) ) / GAMMA ( A + B )\n! = Integral ( 0 <= T <= 1 ) T^(A-1) (1-T)^(B-1) dT.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 10 July 1998\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the function.\n! 0.0D+00 < A,\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) BETA, the value of the function.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) beta\n real ( kind = 8 ) gamma_log\n\n if ( a <= 0.0D+00 .or. b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BETA - Fatal error!'\n write ( *, '(a)' ) ' Both A and B must be greater than 0.'\n stop 1\n end if\n\n beta = exp ( gamma_log ( a ) + gamma_log ( b ) - gamma_log ( a + b ) )\n\n return\nend\nsubroutine beta_binomial_cdf ( x, a, b, c, cdf )\n\n!*****************************************************************************80\n!\n!! BETA_BINOMIAL_CDF evaluates the Beta Binomial CDF.\n!\n! Discussion:\n!\n! A simple summing approach is used.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 07 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X, the argument of the CDF.\n!\n! Input, real ( kind = 8 ) A, B, parameters of the PDF.\n! 0.0D+00 < A,\n! 0.0D+00 < B.\n!\n! Input, integer ( kind = 4 ) C, a parameter of the PDF.\n! 0 <= C.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) beta\n integer ( kind = 4 ) c\n real ( kind = 8 ) cdf\n real ( kind = 8 ) pdf\n integer ( kind = 4 ) x\n integer ( kind = 4 ) y\n\n if ( x < 0 ) then\n\n cdf = 0.0D+00\n\n else if ( x < c ) then\n\n cdf = 0.0D+00\n do y = 0, x\n pdf = beta ( a + real ( y, kind = 8 ), &\n b + real ( c - y, kind = 8 ) ) / ( real ( c + 1, kind = 8 ) &\n * beta ( real ( y + 1, kind = 8 ), &\n real ( c - y + 1, kind = 8 ) ) * beta ( a, b ) )\n cdf = cdf + pdf\n end do\n\n else if ( c <= x ) then\n\n cdf = 1.0D+00\n\n end if\n\n return\nend\nsubroutine beta_binomial_cdf_inv ( cdf, a, b, c, x )\n\n!*****************************************************************************80\n!\n!! BETA_BINOMIAL_CDF_INV inverts the Beta Binomial CDF.\n!\n! Discussion:\n!\n! A simple discrete approach is used.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n!\n! Input, real ( kind = 8 ) A, B, parameters of the PDF.\n! 0.0D+00 < A,\n! 0.0D+00 < B.\n!\n! Input, integer ( kind = 4 ) C, a parameter of the PDF.\n! 0 <= C.\n!\n! Output, integer ( kind = 4 ) X, the smallest X whose cumulative density \n! function is greater than or equal to CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) beta\n integer ( kind = 4 ) c\n real ( kind = 8 ) cdf\n real ( kind = 8 ) cum\n real ( kind = 8 ) pdf\n integer ( kind = 4 ) x\n integer ( kind = 4 ) y\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BETA_BINOMIAL_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n cum = 0.0D+00\n\n do y = 0, c\n\n pdf = beta ( a + real ( y, kind = 8 ), &\n b + real ( c - y, kind = 8 ) ) / ( real ( c + 1, kind = 8 ) &\n * beta ( real ( y + 1, kind = 8 ), &\n real ( c - y + 1, kind = 8 ) ) * beta ( a, b ) )\n\n cum = cum + pdf\n\n if ( cdf <= cum ) then\n x = y\n return\n end if\n\n end do\n\n x = c\n\n return\nend\nfunction beta_binomial_check ( a, b, c )\n\n!*****************************************************************************80\n!\n!! BETA_BINOMIAL_CHECK checks the parameters of the Beta Binomial PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 18 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, parameters of the PDF.\n! 0.0D+00 < A,\n! 0.0D+00 < B.\n!\n! Input, integer ( kind = 4 ) C, a parameter of the PDF.\n! 0 <= C.\n!\n! Output, logical BETA_BINOMIAL_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n logical beta_binomial_check\n integer ( kind = 4 ) c\n\n if ( a <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BETA_BINOMIAL_CHECK - Fatal error!'\n write ( *, '(a)' ) ' A <= 0.'\n beta_binomial_check = .false.\n return\n end if\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BETA_BINOMIAL_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B <= 0.'\n beta_binomial_check = .false.\n return\n end if\n\n if ( c < 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BETA_BINOMIAL_CHECK - Fatal error!'\n write ( *, '(a)' ) ' C < 0.'\n beta_binomial_check = .false.\n return\n end if\n\n beta_binomial_check = .true.\n\n return\nend\nsubroutine beta_binomial_mean ( a, b, c, mean )\n\n!*****************************************************************************80\n!\n!! BETA_BINOMIAL_MEAN returns the mean of the Beta Binomial PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 26 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, parameters of the PDF.\n! 0.0D+00 < A,\n! 0.0D+00 < B.\n!\n! Input, integer ( kind = 4 ) C, a parameter of the PDF.\n! 0 <= N.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n integer ( kind = 4 ) c\n real ( kind = 8 ) mean\n\n mean = real ( c, kind = 8 ) * a / ( a + b )\n\n return\nend\nsubroutine beta_binomial_pdf ( x, a, b, c, pdf )\n\n!*****************************************************************************80\n!\n!! BETA_BINOMIAL_PDF evaluates the Beta Binomial PDF.\n!\n! Discussion:\n!\n! The PDF is defined as:\n!\n! PDF(A,B,C;X) = Beta(A+X,B+C-X)\n! / ( (C+1) * Beta(X+1,C-X+1) * Beta(A,B) ) for 0 <= X <= C.\n!\n! This PDF can be reformulated as:\n!\n! The beta binomial probability density function for X successes\n! out of N trials is\n!\n! PDF2(X)( N, MU, THETA ) =\n! C(N,X) * Product ( 0 <= R <= X - 1 ) ( MU + R * THETA )\n! * Product ( 0 <= R <= N - X - 1 ) ( 1 - MU + R * THETA )\n! / Product ( 0 <= R <= N - 1 ) ( 1 + R * THETA )\n!\n! where\n!\n! C(N,X) is the combinatorial coefficient;\n! MU is the expectation of the underlying Beta distribution;\n! THETA is a shape parameter.\n!\n! A THETA value of 0 ( or A+B --> +oo ) results in the binomial\n! distribution:\n!\n! PDF2(X) ( N, MU, 0 ) = C(N,X) * MU^X * ( 1 - MU )^(N-X)\n!\n! Given A, B, C for PDF, then the equivalent PDF2 has:\n!\n! N = C\n! MU = A / ( A + B )\n! THETA = 1 / ( A + B )\n!\n! Given N, MU, THETA for PDF2, the equivalent PDF has:\n!\n! A = MU / THETA\n! B = ( 1 - MU ) / THETA\n! C = N\n!\n! BETA_BINOMIAL_PDF(1,1,C;X) = UNIFORM_DISCRETE_PDF(0,C-1;X)\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 18 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X, the argument of the PDF.\n!\n! Input, real ( kind = 8 ) A, B, parameters of the PDF.\n! 0.0D+00 < A,\n! 0.0D+00 < B.\n!\n! Input, integer ( kind = 4 ) C, a parameter of the PDF.\n! 0 <= C.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) beta\n integer ( kind = 4 ) c\n real ( kind = 8 ) pdf\n integer ( kind = 4 ) x\n\n if ( x < 0 ) then\n\n pdf = 0.0D+00\n\n else if ( x <= c ) then\n\n pdf = beta ( a + real ( x, kind = 8 ), b + real ( c - x, kind = 8 ) ) &\n / ( real ( c + 1, kind = 8 ) &\n * beta ( real ( x + 1, kind = 8 ), &\n real ( c - x + 1, kind = 8 ) ) * beta ( a, b ) )\n\n else if ( c < x ) then\n\n pdf = 0.0D+00\n\n end if\n\n return\nend\nsubroutine beta_binomial_sample ( a, b, c, seed, x )\n\n!*****************************************************************************80\n!\n!! BETA_BINOMIAL_SAMPLE samples the Beta Binomial CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 07 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, parameters of the PDF.\n! 0.0D+00 < A,\n! 0.0D+00 < B.\n!\n! Input, integer ( kind = 4 ) C, a parameter of the PDF.\n! 0 <= C.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, integer ( kind = 4 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n integer ( kind = 4 ) c\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n integer ( kind = 4 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call beta_binomial_cdf_inv ( cdf, a, b, c, x )\n\n return\nend\nsubroutine beta_binomial_variance ( a, b, c, variance )\n\n!*****************************************************************************80\n!\n!! BETA_BINOMIAL_VARIANCE returns the variance of the Beta Binomial PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 26 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, parameters of the PDF.\n! 0.0D+00 < A,\n! 0.0D+00 < B.\n!\n! Input, integer ( kind = 4 ) C, a parameter of the PDF.\n! 0 <= C.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n integer ( kind = 4 ) c\n real ( kind = 8 ) variance\n\n variance = ( real ( c, kind = 8 ) * a * b ) &\n * ( a + b + real ( c, kind = 8 ) ) &\n / ( ( a + b )**2 * ( a + b + 1.0D+00 ) )\n\n return\nend\nsubroutine beta_cdf ( x, a, b, cdf )\n\n!*****************************************************************************80\n!\n!! BETA_CDF evaluates the Beta CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A,\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) beta_inc\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( x <= 0.0D+00 ) then\n cdf = 0.0D+00\n else if ( x <= 1.0D+00 ) then\n cdf = beta_inc ( a, b, x )\n else\n cdf = 1.0D+00\n end if\n\n return\nend\nsubroutine beta_cdf_inv ( cdf, p, q, x )\n\n!*****************************************************************************80\n!\n!! BETA_CDF_INV computes the inverse of the incomplete Beta function.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 April 2013\n!\n! Author:\n!\n! Original FORTRAN77 version by GW Cran, KJ Martin, GE Thomas.\n! FORTRAN90 version by John Burkardt.\n!\n! Reference:\n!\n! GW Cran, KJ Martin, GE Thomas,\n! Remark AS R19 and Algorithm AS 109:\n! A Remark on Algorithms AS 63: The Incomplete Beta Integral\n! and AS 64: Inverse of the Incomplete Beta Integeral,\n! Applied Statistics,\n! Volume 26, Number 1, 1977, pages 111-114.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the Beta CDF.\n! 0 <= CDF <= 1.\n!\n! Input, real ( kind = 8 ) P, Q, the parameters of the incomplete\n! Beta function.\n!\n! Output, real ( kind = 8 ) X, the argument of the incomplete\n! Beta function which produces the value CDF.\n!\n! Local Parameters:\n!\n! Local, real ( kind = 8 ) SAE, the most negative decimal exponent\n! which does not cause an underflow.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) acu\n real ( kind = 8 ) adj\n real ( kind = 8 ) beta_inc\n real ( kind = 8 ) beta_log\n real ( kind = 8 ) cdf\n real ( kind = 8 ) fpu\n real ( kind = 8 ) g\n real ( kind = 8 ) gamma_log\n real ( kind = 8 ) h\n integer ( kind = 4 ) iex\n logical indx\n real ( kind = 8 ) p\n real ( kind = 8 ) pp\n real ( kind = 8 ) prev\n real ( kind = 8 ) q\n real ( kind = 8 ) qq\n real ( kind = 8 ) r\n real ( kind = 8 ) s\n real ( kind = 8 ), parameter :: sae = -37.0D+00\n real ( kind = 8 ) sq\n real ( kind = 8 ) t\n real ( kind = 8 ) tx\n real ( kind = 8 ) w\n real ( kind = 8 ) x\n real ( kind = 8 ) xin\n real ( kind = 8 ) y\n real ( kind = 8 ) yprev\n\n fpu = 10.0D+00 ** sae\n beta_log = gamma_log ( p ) + gamma_log ( q ) - gamma_log ( p + q )\n!\n! Test for admissibility of parameters.\n!\n if ( p <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BETA_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' P <= 0.0'\n return\n end if\n\n if ( q <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BETA_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' Q <= 0.0'\n return\n end if\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BETA_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0.0 or 1.0 < CDF.'\n return\n end if\n!\n! Return immediately if the answer is easy to determine. \n!\n if ( cdf == 0.0D+00 ) then\n x = 0.0D+00\n return\n else if ( cdf == 1.0D+00 ) then\n x = 1.0D+00\n return\n end if\n!\n! Change tail if necessary.\n!\n if ( 0.5D+00 < cdf ) then\n a = 1.0D+00 - cdf\n pp = q\n qq = p\n indx = .true.\n else\n a = cdf\n pp = p\n qq = q\n indx = .false.\n end if\n!\n! Calculate the initial approximation.\n!\n r = sqrt ( - log ( a * a ) )\n\n y = r - ( 2.30753D+00 + 0.27061D+00 * r ) &\n / ( 1.0D+00 + ( 0.99229D+00 + 0.04481D+00 * r ) * r )\n\n if ( 1.0D+00 < pp .and. 1.0D+00 < qq ) then\n\n r = ( y * y - 3.0D+00 ) / 6.0D+00\n s = 1.0D+00 / ( pp + pp - 1.0D+00 )\n t = 1.0D+00 / ( qq + qq - 1.0D+00 )\n h = 2.0D+00 / ( s + t )\n w = y * sqrt ( h + r ) / h - ( t - s ) &\n * ( r + 5.0D+00 / 6.0D+00 - 2.0D+00 / ( 3.0D+00 * h ) )\n x = pp / ( pp + qq * exp ( w + w ) )\n\n else\n\n r = qq + qq\n t = 1.0D+00 / ( 9.0D+00 * qq )\n t = r * ( 1.0D+00 - t + y * sqrt ( t ) )**3\n\n if ( t <= 0.0D+00 ) then\n x = 1.0D+00 - exp ( ( log ( ( 1.0D+00 - a ) * qq ) &\n + beta_log ) / qq )\n else\n\n t = ( 4.0D+00 * pp + r - 2.0D+00 ) / t\n\n if ( t <= 1.0D+00 ) then\n x = exp ( ( log ( a * pp ) + beta_log ) / pp )\n else\n x = 1.0D+00 - 2.0D+00 / ( t + 1.0D+00 )\n end if\n\n end if\n\n end if\n!\n! Solve for X by a modified Newton-Raphson method.\n!\n r = 1.0D+00 - pp\n t = 1.0D+00 - qq\n yprev = 0.0D+00\n sq = 1.0D+00\n prev = 1.0D+00\n\n if ( x < 0.0001D+00 ) then\n x = 0.0001D+00\n end if\n\n if ( 0.9999D+00 < x ) then\n x = 0.9999D+00\n end if\n\n iex = max ( - 5.0D+00 / pp**2 - 1.0D+00 / a**0.2D+00 - 13.0D+00, sae )\n\n acu = 10.0D+00 ** iex\n\n do\n\n y = beta_inc ( pp, qq, x )\n\n xin = x\n y = ( y - a ) * exp ( beta_log + r * log ( xin ) &\n + t * log ( 1.0D+00 - xin ) )\n\n if ( y * yprev <= 0.0D+00 ) then\n prev = max ( sq, fpu )\n end if\n\n g = 1.0D+00\n\n do\n\n do\n\n adj = g * y\n sq = adj * adj\n\n if ( sq < prev ) then\n\n tx = x - adj\n\n if ( 0.0D+00 <= tx .and. tx <= 1.0D+00 ) then\n exit\n end if\n\n end if\n\n g = g / 3.0D+00\n\n end do\n\n if ( prev <= acu ) then\n if ( indx ) then\n x = 1.0D+00 - x\n end if\n return\n end if\n\n if ( y * y <= acu ) then\n if ( indx ) then\n x = 1.0D+00 - x\n end if\n return\n end if\n\n if ( tx /= 0.0D+00 .and. tx /= 1.0D+00 ) then\n exit\n end if\n\n g = g / 3.0D+00\n\n end do\n\n if ( tx == x ) then\n exit\n end if\n\n x = tx\n yprev = y\n\n end do\n\n if ( indx ) then\n x = 1.0D+00 - x\n end if\n\n return\nend\nsubroutine beta_cdf_inv_old ( cdf, a, b, x )\n\n!*****************************************************************************80\n!\n!! BETA_CDF_INV_OLD inverts the Beta CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 April 2001\n!\n! Author:\n!\n! Original FORTRAN77 version by Roger Abernathy, Robert Smith.\n! FORTRAN90 version by John Burkardt\n!\n! Reference:\n!\n! Roger Abernathy, Robert Smith,\n! Algorithm 724,\n! Program to Calculate F Percentiles,\n! ACM Transactions on Mathematical Software,\n! Volume 19, Number 4, December 1993, pages 481-483.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A,\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) X, the argument of the CDF.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: maxk = 20\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) bcoeff\n real ( kind = 8 ) cdf\n real ( kind = 8 ) cdf_x\n real ( kind = 8 ) d(2:maxk,0:maxk-2)\n real ( kind = 8 ), parameter :: error = 0.0001D+00\n real ( kind = 8 ), parameter :: errapp = 0.01D+00\n integer ( kind = 4 ) i\n integer ( kind = 4 ) j\n integer ( kind = 4 ) k\n integer ( kind = 4 ) loopct\n real ( kind = 8 ) pdf_x\n real ( kind = 8 ) q\n real ( kind = 8 ) s1\n real ( kind = 8 ) s2\n real ( kind = 8 ) sum2\n real ( kind = 8 ) t\n real ( kind = 8 ) tail\n real ( kind = 8 ) x\n real ( kind = 8 ) xold\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BETA_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n!\n! Estimate the solution.\n!\n x = a / ( a + b )\n\n xold = 0.0D+00\n loopct = 2\n\n do while ( errapp <= abs ( ( x - xold ) / x ) .and. loopct /= 0 )\n\n xold = x\n loopct = loopct - 1\n!\n! CDF_X = PROB { BETA(A,B) <= X }.\n! Q = ( CDF - CDF_X ) / PDF_X.\n!\n call beta_cdf ( x, a, b, cdf_x )\n\n call beta_pdf ( x, a, b, pdf_x )\n\n q = ( cdf - cdf_x ) / pdf_x\n!\n! D(N,K) = C(N,K) * Q**(N+K-1) / (N-1)!\n!\n t = 1.0D+00 - x\n s1 = q * ( b - 1.0D+00 ) / t\n s2 = q * ( 1.0D+00 - a ) / x\n d(2,0) = s1 + s2\n tail = d(2,0) * q / 2.0D+00\n x = x + q + tail\n\n k = 3\n\n do while ( error < abs ( tail / x ) .and. k <= maxk )\n!\n! Find D(2,K-2).\n!\n s1 = q * ( real ( k, kind = 8 ) - 2.0D+00 ) * s1 / t\n s2 = q * ( 2.0D+00 - real ( k, kind = 8 ) ) * s2 / x\n d(2,k-2) = s1 + s2\n!\n! Find D(3,K-3), D(4,K-4), D(5,K-5), ... , D(K-1,1).\n!\n do i = 3, k-1\n sum2 = d(2,0) * d(i-1,k-i)\n bcoeff = 1.0D+00\n do j = 1, k-i\n bcoeff = ( bcoeff * real ( k - i - j + 1, kind = 8 ) ) &\n / real ( j, kind = 8 )\n sum2 = sum2 + bcoeff * d(2,j) * d(i-1,k-i-j)\n end do\n d(i,k-i) = sum2 + d(i-1,k-i+1) / real ( i - 1, kind = 8 )\n end do\n!\n! Compute D(K,0) and use it to expand the series.\n!\n d(k,0) = d(2,0) * d(k-1,0) + d(k-1,1) / real ( k - 1, kind = 8 )\n tail = d(k,0) * q / real ( k, kind = 8 )\n x = x + tail\n!\n! Check for divergence.\n!\n if ( x <= 0.0D+00 .or. 1.0D+00 <= x ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BETA_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' The series has diverged.'\n write ( *, '(a,g14.6)' ) ' X = ', x\n x = - 1.0D+00\n return\n end if\n\n k = k + 1\n\n end do\n\n end do\n\n return\nend\nsubroutine beta_cdf_values ( n_data, a, b, x, fx )\n\n!*****************************************************************************80\n!\n!! BETA_CDF_VALUES returns some values of the Beta CDF.\n!\n! Discussion:\n!\n! The incomplete Beta function may be written\n!\n! BETA_INC(A,B,X) = integral (0 <= t <= X) T^(A-1) * (1-T)^(B-1) dT\n! / integral (0 <= t <= 1) T^(A-1) * (1-T)^(B-1) dT\n!\n! Thus,\n!\n! BETA_INC(A,B,0.0) = 0.0\n! BETA_INC(A,B,1.0) = 1.0\n!\n! The incomplete Beta function is also sometimes called the\n! \"modified\" Beta function, or the \"normalized\" Beta function\n! or the Beta CDF (cumulative density function).\n!\n! In Mathematica, the function can be evaluated by:\n!\n! BETA[X,A,B] / BETA[A,B]\n!\n! The function can also be evaluated by using the Statistics package:\n!\n! Needs[\"Statistics`ContinuousDistributions`\"]\n! dist = BetaDistribution [ a, b ]\n! CDF [ dist, x ]\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 April 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Milton Abramowitz, Irene Stegun,\n! Handbook of Mathematical Functions,\n! National Bureau of Standards, 1964,\n! ISBN: 0-486-61272-4,\n! LC: QA47.A34.\n!\n! Karl Pearson,\n! Tables of the Incomplete Beta Function,\n! Cambridge University Press, 1968,\n! LC: QA351.P38.\n!\n! Stephen Wolfram,\n! The Mathematica Book,\n! Fourth Edition,\n! Cambridge University Press, 1999,\n! ISBN: 0-521-64314-7,\n! LC: QA76.95.W65.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) N_DATA. The user sets N_DATA to 0\n! before the first call. On each call, the routine increments N_DATA by 1,\n! and returns the corresponding data; when there is no more data, the\n! output value of N_DATA will be 0 again.\n!\n! Output, real ( kind = 8 ) A, B, the parameters of the function.\n!\n! Output, real ( kind = 8 ) X, the argument of the function.\n!\n! Output, real ( kind = 8 ) FX, the value of the function.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: n_max = 45\n\n real ( kind = 8 ) a\n real ( kind = 8 ), save, dimension ( n_max ) :: a_vec = (/ &\n 0.5D+00, &\n 0.5D+00, &\n 0.5D+00, &\n 1.0D+00, &\n 1.0D+00, &\n 1.0D+00, &\n 1.0D+00, &\n 1.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 5.5D+00, &\n 10.0D+00, &\n 10.0D+00, &\n 10.0D+00, &\n 10.0D+00, &\n 20.0D+00, &\n 20.0D+00, &\n 20.0D+00, &\n 20.0D+00, &\n 20.0D+00, &\n 30.0D+00, &\n 30.0D+00, &\n 40.0D+00, &\n 1.0D+00, &\n 1.0D+00, &\n 1.0D+00, &\n 1.0D+00, &\n 1.0D+00, &\n 1.0D+00, &\n 1.0D+00, &\n 1.0D+00, &\n 2.0D+00, &\n 3.0D+00, &\n 4.0D+00, &\n 5.0D+00, &\n 1.30625D+00, &\n 1.30625D+00, &\n 1.30625D+00 /)\n real ( kind = 8 ) b\n real ( kind = 8 ), save, dimension ( n_max ) :: b_vec = (/ &\n 0.5D+00, &\n 0.5D+00, &\n 0.5D+00, &\n 0.5D+00, &\n 0.5D+00, &\n 0.5D+00, &\n 0.5D+00, &\n 1.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 5.0D+00, &\n 0.5D+00, &\n 5.0D+00, &\n 5.0D+00, &\n 10.0D+00, &\n 5.0D+00, &\n 10.0D+00, &\n 10.0D+00, &\n 20.0D+00, &\n 20.0D+00, &\n 10.0D+00, &\n 10.0D+00, &\n 20.0D+00, &\n 0.5D+00, &\n 0.5D+00, &\n 0.5D+00, &\n 0.5D+00, &\n 2.0D+00, &\n 3.0D+00, &\n 4.0D+00, &\n 5.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 11.7562D+00, &\n 11.7562D+00, & \n 11.7562D+00 /)\n real ( kind = 8 ) fx\n real ( kind = 8 ), save, dimension ( n_max ) :: fx_vec = (/ &\n 0.6376856085851985D-01, &\n 0.2048327646991335D+00, &\n 0.1000000000000000D+01, &\n 0.0000000000000000D+00, &\n 0.5012562893380045D-02, &\n 0.5131670194948620D-01, &\n 0.2928932188134525D+00, &\n 0.5000000000000000D+00, &\n 0.2800000000000000D-01, &\n 0.1040000000000000D+00, &\n 0.2160000000000000D+00, &\n 0.3520000000000000D+00, &\n 0.5000000000000000D+00, &\n 0.6480000000000000D+00, &\n 0.7840000000000000D+00, &\n 0.8960000000000000D+00, &\n 0.9720000000000000D+00, &\n 0.4361908850559777D+00, &\n 0.1516409096347099D+00, &\n 0.8978271484375000D-01, &\n 0.1000000000000000D+01, &\n 0.5000000000000000D+00, &\n 0.4598773297575791D+00, &\n 0.2146816102371739D+00, &\n 0.9507364826957875D+00, &\n 0.5000000000000000D+00, &\n 0.8979413687105918D+00, &\n 0.2241297491808366D+00, &\n 0.7586405487192086D+00, &\n 0.7001783247477069D+00, &\n 0.5131670194948620D-01, &\n 0.1055728090000841D+00, &\n 0.1633399734659245D+00, &\n 0.2254033307585166D+00, &\n 0.3600000000000000D+00, &\n 0.4880000000000000D+00, &\n 0.5904000000000000D+00, &\n 0.6723200000000000D+00, &\n 0.2160000000000000D+00, &\n 0.8370000000000000D-01, &\n 0.3078000000000000D-01, &\n 0.1093500000000000D-01, &\n 0.918884684620518D+00, &\n 0.21052977489419D+00, &\n 0.1824130512500673D+00 /)\n integer ( kind = 4 ) n_data\n real ( kind = 8 ) x\n real ( kind = 8 ), save, dimension ( n_max ) :: x_vec = (/ &\n 0.01D+00, &\n 0.10D+00, &\n 1.00D+00, &\n 0.00D+00, &\n 0.01D+00, &\n 0.10D+00, &\n 0.50D+00, &\n 0.50D+00, &\n 0.10D+00, &\n 0.20D+00, &\n 0.30D+00, &\n 0.40D+00, &\n 0.50D+00, &\n 0.60D+00, &\n 0.70D+00, &\n 0.80D+00, &\n 0.90D+00, &\n 0.50D+00, &\n 0.90D+00, &\n 0.50D+00, &\n 1.00D+00, &\n 0.50D+00, &\n 0.80D+00, &\n 0.60D+00, &\n 0.80D+00, &\n 0.50D+00, &\n 0.60D+00, &\n 0.70D+00, &\n 0.80D+00, &\n 0.70D+00, &\n 0.10D+00, &\n 0.20D+00, &\n 0.30D+00, &\n 0.40D+00, &\n 0.20D+00, &\n 0.20D+00, &\n 0.20D+00, &\n 0.20D+00, &\n 0.30D+00, &\n 0.30D+00, &\n 0.30D+00, &\n 0.30D+00, &\n 0.225609D+00, &\n 0.0335568D+00, &\n 0.0295222D+00 /)\n\n if ( n_data < 0 ) then\n n_data = 0\n end if\n\n n_data = n_data + 1\n\n if ( n_max < n_data ) then\n n_data = 0\n a = 0.0D+00\n b = 0.0D+00\n x = 0.0D+00\n fx = 0.0D+00\n else\n a = a_vec(n_data)\n b = b_vec(n_data)\n x = x_vec(n_data)\n fx = fx_vec(n_data)\n end if\n\n return\nend\nfunction beta_check ( a, b )\n\n!*****************************************************************************80\n!\n!! BETA_CHECK checks the parameters of the Beta PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 08 December 1998\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A,\n! 0.0D+00 < B.\n!\n! Output, logical BETA_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n logical beta_check\n\n if ( a <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BETA_CHECK - Fatal error!'\n write ( *, '(a)' ) ' A <= 0.'\n beta_check = .false.\n return\n end if\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BETA_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B <= 0.'\n beta_check = .false.\n return\n end if\n\n beta_check = .true.\n\n return\nend\nfunction beta_inc ( a, b, x )\n\n!*****************************************************************************80\n!\n!! BETA_INC returns the value of the incomplete Beta function.\n!\n! Discussion:\n!\n! This calculation requires an iteration. In some cases, the iteration\n! may not converge rapidly, or may become inaccurate.\n!\n! The formula is:\n!\n! BETA_INC(A,B,X)\n!\n! = Integral ( 0 <= T <= X ) T^(A-1) (1-T)^(B-1) dT\n! / Integral ( 0 <= T <= 1 ) T^(A-1) (1-T)^(B-1) dT\n!\n! = Integral ( 0 <= T <= X ) T^(A-1) (1-T)^(B-1) dT\n! / BETA(A,B)\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 16 February 2004\n!\n! Author:\n!\n! Original FORTRAN77 version by KL Majumder, GP Bhattacharjee.\n! FORTRAN90 version by John Burkardt\n!\n! Reference:\n!\n! KL Majumder, GP Bhattacharjee,\n! Algorithm AS63,\n! Applied Statistics,\n! 1973, volume 22, number 3.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the function.\n! 0.0D+00 < A,\n! 0.0D+00 < B.\n!\n! Input, real ( kind = 8 ) X, the argument of the function.\n! Normally, 0.0D+00 <= X <= 1.0.\n!\n! Output, real ( kind = 8 ) BETA_INC, the value of the function.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) beta\n real ( kind = 8 ) beta_inc\n real ( kind = 8 ) cx\n integer ( kind = 4 ) i\n integer ( kind = 4 ) it\n integer ( kind = 4 ), parameter :: it_max = 1000\n logical indx\n integer ( kind = 4 ) ns\n real ( kind = 8 ) pp\n real ( kind = 8 ) psq\n real ( kind = 8 ) qq\n real ( kind = 8 ) rx\n real ( kind = 8 ) temp\n real ( kind = 8 ) term\n real ( kind = 8 ), parameter :: tol = 1.0D-07\n real ( kind = 8 ) x\n real ( kind = 8 ) xx\n\n if ( a <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BETA_INC - Fatal error!'\n write ( *, '(a)' ) ' A <= 0.'\n stop 1\n end if\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BETA_INC - Fatal error!'\n write ( *, '(a)' ) ' B <= 0.'\n stop 1\n end if\n\n if ( x <= 0.0D+00 ) then\n beta_inc = 0.0D+00\n return\n else if ( 1.0D+00 <= x ) then\n beta_inc = 1.0D+00\n return\n end if\n!\n! Change tail if necessary and determine S.\n!\n psq = a + b\n\n if ( a < ( a + b ) * x ) then\n xx = 1.0D+00 - x\n cx = x\n pp = b\n qq = a\n indx = .true.\n else\n xx = x\n cx = 1.0D+00 - x\n pp = a\n qq = b\n indx = .false.\n end if\n\n term = 1.0D+00\n i = 1\n beta_inc = 1.0D+00\n\n ns = int ( qq + cx * ( a + b ) )\n!\n! Use Soper's reduction formulas.\n!\n rx = xx / cx\n\n temp = qq - real ( i, kind = 8 )\n if ( ns == 0 ) then\n rx = xx\n end if\n\n it = 0\n\n do\n\n it = it + 1\n\n if ( it_max < it ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BETA_INC - Fatal error!'\n write ( *, '(a)' ) ' Maximum number of iterations exceeded!'\n write ( *, '(a,i8)' ) ' IT_MAX = ', it_max\n stop 1\n end if\n\n term = term * temp * rx / ( pp + real ( i, kind = 8 ) )\n beta_inc = beta_inc + term\n temp = abs ( term )\n\n if ( temp <= tol .and. temp <= tol * beta_inc ) then\n exit\n end if\n\n i = i + 1\n ns = ns - 1\n\n if ( 0 <= ns ) then\n temp = qq - real ( i, kind = 8 )\n if ( ns == 0 ) then\n rx = xx\n end if\n else\n temp = psq\n psq = psq + 1.0D+00\n end if\n\n end do\n!\n! Finish calculation.\n!\n beta_inc = beta_inc * exp ( pp * log ( xx ) &\n + ( qq - 1.0D+00 ) * log ( cx ) ) / ( beta ( a, b ) * pp )\n\n if ( indx ) then\n beta_inc = 1.0D+00 - beta_inc\n end if\n\n return\nend\nsubroutine beta_inc_values ( n_data, a, b, x, fx )\n\n!*****************************************************************************80\n!\n!! BETA_INC_VALUES returns some values of the incomplete Beta function.\n!\n! Discussion:\n!\n! The incomplete Beta function may be written\n!\n! BETA_INC(A,B,X) = integral (0 <= t <= X) T^(A-1) * (1-T)^(B-1) dT\n! / integral (0 <= t <= 1) T^(A-1) * (1-T)^(B-1) dT\n!\n! Thus,\n!\n! BETA_INC(A,B,0.0) = 0.0\n! BETA_INC(A,B,1.0) = 1.0\n!\n! The incomplete Beta function is also sometimes called the\n! \"modified\" Beta function, or the \"normalized\" Beta function\n! or the Beta CDF (cumulative density function).\n!\n! In Mathematica, the function can be evaluated by:\n!\n! BETA[X,A,B] / BETA[A,B]\n!\n! The function can also be evaluated by using the Statistics package:\n!\n! Needs[\"Statistics`ContinuousDistributions`\"]\n! dist = BetaDistribution [ a, b ]\n! CDF [ dist, x ]\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 April 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Milton Abramowitz, Irene Stegun,\n! Handbook of Mathematical Functions,\n! National Bureau of Standards, 1964,\n! ISBN: 0-486-61272-4,\n! LC: QA47.A34.\n!\n! Karl Pearson,\n! Tables of the Incomplete Beta Function,\n! Cambridge University Press, 1968,\n! LC: QA351.P38.\n!\n! Stephen Wolfram,\n! The Mathematica Book,\n! Fourth Edition,\n! Cambridge University Press, 1999,\n! ISBN: 0-521-64314-7,\n! LC: QA76.95.W65.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) N_DATA. The user sets N_DATA to 0\n! before the first call. On each call, the routine increments N_DATA by 1,\n! and returns the corresponding data; when there is no more data, the\n! output value of N_DATA will be 0 again.\n!\n! Output, real ( kind = 8 ) A, B, the parameters of the function.\n!\n! Output, real ( kind = 8 ) X, the argument of the function.\n!\n! Output, real ( kind = 8 ) FX, the value of the function.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: n_max = 45\n\n real ( kind = 8 ) a\n real ( kind = 8 ), save, dimension ( n_max ) :: a_vec = (/ &\n 0.5D+00, &\n 0.5D+00, &\n 0.5D+00, &\n 1.0D+00, &\n 1.0D+00, &\n 1.0D+00, &\n 1.0D+00, &\n 1.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 5.5D+00, &\n 10.0D+00, &\n 10.0D+00, &\n 10.0D+00, &\n 10.0D+00, &\n 20.0D+00, &\n 20.0D+00, &\n 20.0D+00, &\n 20.0D+00, &\n 20.0D+00, &\n 30.0D+00, &\n 30.0D+00, &\n 40.0D+00, &\n 1.0D+00, &\n 1.0D+00, &\n 1.0D+00, &\n 1.0D+00, &\n 1.0D+00, &\n 1.0D+00, &\n 1.0D+00, &\n 1.0D+00, &\n 2.0D+00, &\n 3.0D+00, &\n 4.0D+00, &\n 5.0D+00, &\n 1.30625D+00, &\n 1.30625D+00, &\n 1.30625D+00 /)\n real ( kind = 8 ) b\n real ( kind = 8 ), save, dimension ( n_max ) :: b_vec = (/ &\n 0.5D+00, &\n 0.5D+00, &\n 0.5D+00, &\n 0.5D+00, &\n 0.5D+00, &\n 0.5D+00, &\n 0.5D+00, &\n 1.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 5.0D+00, &\n 0.5D+00, &\n 5.0D+00, &\n 5.0D+00, &\n 10.0D+00, &\n 5.0D+00, &\n 10.0D+00, &\n 10.0D+00, &\n 20.0D+00, &\n 20.0D+00, &\n 10.0D+00, &\n 10.0D+00, &\n 20.0D+00, &\n 0.5D+00, &\n 0.5D+00, &\n 0.5D+00, &\n 0.5D+00, &\n 2.0D+00, &\n 3.0D+00, &\n 4.0D+00, &\n 5.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 11.7562D+00, &\n 11.7562D+00, & \n 11.7562D+00 /)\n real ( kind = 8 ) fx\n real ( kind = 8 ), save, dimension ( n_max ) :: fx_vec = (/ &\n 0.6376856085851985D-01, &\n 0.2048327646991335D+00, &\n 0.1000000000000000D+01, &\n 0.0000000000000000D+00, &\n 0.5012562893380045D-02, &\n 0.5131670194948620D-01, &\n 0.2928932188134525D+00, &\n 0.5000000000000000D+00, &\n 0.2800000000000000D-01, &\n 0.1040000000000000D+00, &\n 0.2160000000000000D+00, &\n 0.3520000000000000D+00, &\n 0.5000000000000000D+00, &\n 0.6480000000000000D+00, &\n 0.7840000000000000D+00, &\n 0.8960000000000000D+00, &\n 0.9720000000000000D+00, &\n 0.4361908850559777D+00, &\n 0.1516409096347099D+00, &\n 0.8978271484375000D-01, &\n 0.1000000000000000D+01, &\n 0.5000000000000000D+00, &\n 0.4598773297575791D+00, &\n 0.2146816102371739D+00, &\n 0.9507364826957875D+00, &\n 0.5000000000000000D+00, &\n 0.8979413687105918D+00, &\n 0.2241297491808366D+00, &\n 0.7586405487192086D+00, &\n 0.7001783247477069D+00, &\n 0.5131670194948620D-01, &\n 0.1055728090000841D+00, &\n 0.1633399734659245D+00, &\n 0.2254033307585166D+00, &\n 0.3600000000000000D+00, &\n 0.4880000000000000D+00, &\n 0.5904000000000000D+00, &\n 0.6723200000000000D+00, &\n 0.2160000000000000D+00, &\n 0.8370000000000000D-01, &\n 0.3078000000000000D-01, &\n 0.1093500000000000D-01, &\n 0.918884684620518D+00, &\n 0.21052977489419D+00, &\n 0.1824130512500673D+00 /)\n integer ( kind = 4 ) n_data\n real ( kind = 8 ) x\n real ( kind = 8 ), save, dimension ( n_max ) :: x_vec = (/ &\n 0.01D+00, &\n 0.10D+00, &\n 1.00D+00, &\n 0.00D+00, &\n 0.01D+00, &\n 0.10D+00, &\n 0.50D+00, &\n 0.50D+00, &\n 0.10D+00, &\n 0.20D+00, &\n 0.30D+00, &\n 0.40D+00, &\n 0.50D+00, &\n 0.60D+00, &\n 0.70D+00, &\n 0.80D+00, &\n 0.90D+00, &\n 0.50D+00, &\n 0.90D+00, &\n 0.50D+00, &\n 1.00D+00, &\n 0.50D+00, &\n 0.80D+00, &\n 0.60D+00, &\n 0.80D+00, &\n 0.50D+00, &\n 0.60D+00, &\n 0.70D+00, &\n 0.80D+00, &\n 0.70D+00, &\n 0.10D+00, &\n 0.20D+00, &\n 0.30D+00, &\n 0.40D+00, &\n 0.20D+00, &\n 0.20D+00, &\n 0.20D+00, &\n 0.20D+00, &\n 0.30D+00, &\n 0.30D+00, &\n 0.30D+00, &\n 0.30D+00, &\n 0.225609D+00, &\n 0.0335568D+00, &\n 0.0295222D+00 /)\n\n if ( n_data < 0 ) then\n n_data = 0\n end if\n\n n_data = n_data + 1\n\n if ( n_max < n_data ) then\n n_data = 0\n a = 0.0D+00\n b = 0.0D+00\n x = 0.0D+00\n fx = 0.0D+00\n else\n a = a_vec(n_data)\n b = b_vec(n_data)\n x = x_vec(n_data)\n fx = fx_vec(n_data)\n end if\n\n return\nend\nsubroutine beta_mean ( a, b, mean )\n\n!*****************************************************************************80\n!\n!! BETA_MEAN returns the mean of the Beta PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A,\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) mean\n\n mean = a / ( a + b )\n\n return\nend\nsubroutine beta_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! BETA_PDF evaluates the Beta PDF.\n!\n! Discussion:\n!\n! The formula for the PDF is:\n!\n! PDF(A,B;X) = X^(A-1) * (1-X)^(B-1) / BETA(A,B).\n!\n! A = B = 1 yields the Uniform distribution on [0,1].\n! A = B = 1/2 yields the Arcsin distribution.\n! B = 1 yields the power function distribution.\n! A = B -> Infinity tends to the Normal distribution.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n! 0.0D+00 <= X <= 1.0.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A,\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) beta\n real ( kind = 8 ) pdf\n real ( kind = 8 ) x\n\n if ( x < 0.0D+00 .or. 1.0D+00 < x ) then\n pdf = 0.0D+00\n else\n pdf = x**( a - 1.0D+00 ) * ( 1.0D+00 - x )**( b - 1.0D+00 ) / beta ( a, b )\n end if\n\n return\nend\nsubroutine beta_sample ( a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! BETA_SAMPLE samples the Beta PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! William Kennedy, James Gentle,\n! Algorithm BN,\n! Statistical Computing,\n! Dekker, 1980.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A,\n! 0.0D+00 < B.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) r8_uniform_01\n real ( kind = 8 ) mu\n integer ( kind = 4 ) seed\n real ( kind = 8 ) stdev\n real ( kind = 8 ) test\n real ( kind = 8 ) u\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n\n mu = ( a - 1.0D+00 ) / ( a + b - 2.0D+00 )\n stdev = 0.5D+00 / sqrt ( a + b - 2.0D+00 )\n\n do\n\n call normal_01_sample ( seed, y )\n\n x = mu + stdev * y\n\n if ( x < 0.0D+00 .or. 1.0D+00 < x ) then\n cycle\n end if\n\n u = r8_uniform_01 ( seed )\n\n test = ( a - 1.0D+00 ) * log ( x / ( a - 1.0D+00 ) ) &\n + ( b - 1.0D+00 ) * log ( ( 1.0D+00 - x ) / ( b - 1.0D+00 ) ) &\n + ( a + b - 2.0D+00 ) * log ( a + b - 2.0D+00 ) + 0.5D+00 * y * y\n\n if ( log ( u ) <= test ) then\n exit\n end if\n\n end do\n\n return\nend\nsubroutine beta_variance ( a, b, variance )\n\n!*****************************************************************************80\n!\n!! BETA_VARIANCE returns the variance of the Beta PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 27 July 1998\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A,\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) variance\n\n variance = ( a * b ) / ( ( a + b )**2 * ( 1.0D+00 + a + b ) )\n\n return\nend\nsubroutine binomial_cdf ( x, a, b, cdf )\n\n!*****************************************************************************80\n!\n!! BINOMIAL_CDF evaluates the Binomial CDF.\n!\n! Discussion:\n!\n! CDF(X)(A,B) is the probability of at most X successes in A trials,\n! given that the probability of success on a single trial is B.\n!\n! A sequence of trials with fixed probability of success on\n! any trial is known as a sequence of Bernoulli trials.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 January 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X, the desired number of successes.\n! 0 <= X <= A.\n!\n! Input, integer ( kind = 4 ) A, the number of trials.\n! 1 <= A.\n!\n! Input, real ( kind = 8 ) B, the probability of success on one trial.\n! 0.0D+00 <= B <= 1.0.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n real ( kind = 8 ) b\n integer ( kind = 4 ) cnk\n real ( kind = 8 ) cdf\n integer ( kind = 4 ) j\n real ( kind = 8 ) pr\n integer ( kind = 4 ) x\n\n if ( x < 0 ) then\n\n cdf = 0.0D+00\n\n else if ( a <= x ) then\n\n cdf = 1.0D+00\n\n else if ( b == 0.0D+00 ) then\n\n cdf = 1.0D+00\n\n else if ( b == 1.0D+00 ) then\n\n cdf = 0.0D+00\n\n else\n\n cdf = 0.0D+00\n\n do j = 0, x\n\n call binomial_coef ( a, j, cnk )\n\n pr = real ( cnk, kind = 8 ) * b**j * ( 1.0D+00 - b )**( a - j )\n\n cdf = cdf + pr\n\n end do\n\n end if\n\n return\nend\nsubroutine binomial_cdf_values ( n_data, a, b, x, fx )\n\n!*****************************************************************************80\n!\n!! BINOMIAL_CDF_VALUES returns some values of the binomial CDF.\n!\n! Discussion:\n!\n! CDF(X)(A,B) is the probability of at most X successes in A trials,\n! given that the probability of success on a single trial is B.\n!\n! In Mathematica, the function can be evaluated by:\n!\n! Needs[\"Statistics`DiscreteDistributions`]\n! dist = BinomialDistribution [ n, p ]\n! CDF [ dist, x ]\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 15 August 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Milton Abramowitz, Irene Stegun,\n! Handbook of Mathematical Functions,\n! National Bureau of Standards, 1964,\n! LC: QA47.A34,\n! ISBN: 0-486-61272-4.\n!\n! Stephen Wolfram,\n! The Mathematica Book,\n! Fourth Edition,\n! Wolfram Media / Cambridge University Press, 1999.\n!\n! Daniel Zwillinger,\n! CRC Standard Mathematical Tables and Formulae,\n! 30th Edition, CRC Press, 1996, pages 651-652.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) N_DATA. The user sets N_DATA to 0 \n! before the first call. On each call, the routine increments N_DATA by 1, \n! and returns the corresponding data; when there is no more data, the\n! output value of N_DATA will be 0 again.\n!\n! Output, integer ( kind = 4 ) A, a parameter of the function.\n!\n! Output, real ( kind = 8 ) B, a parameter of the function.\n!\n! Output, integer ( kind = 4 ) X, the argument of the function.\n!\n! Output, real ( kind = 8 ) FX, the value of the function.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: n_max = 17\n\n integer ( kind = 4 ) a\n integer ( kind = 4 ), save, dimension ( n_max ) :: a_vec = (/ &\n 2, 2, 2, 2, &\n 2, 4, 4, 4, &\n 4, 10, 10, 10, &\n 10, 10, 10, 10, &\n 10 /)\n real ( kind = 8 ) b\n real ( kind = 8 ), save, dimension ( n_max ) :: b_vec = (/ &\n 0.05D+00, &\n 0.05D+00, &\n 0.05D+00, &\n 0.50D+00, &\n 0.50D+00, &\n 0.25D+00, &\n 0.25D+00, &\n 0.25D+00, &\n 0.25D+00, &\n 0.05D+00, &\n 0.10D+00, &\n 0.15D+00, &\n 0.20D+00, &\n 0.25D+00, &\n 0.30D+00, &\n 0.40D+00, &\n 0.50D+00 /)\n real ( kind = 8 ) fx\n real ( kind = 8 ), save, dimension ( n_max ) :: fx_vec = (/ &\n 0.9025000000000000D+00, &\n 0.9975000000000000D+00, &\n 0.1000000000000000D+01, &\n 0.2500000000000000D+00, &\n 0.7500000000000000D+00, &\n 0.3164062500000000D+00, &\n 0.7382812500000000D+00, &\n 0.9492187500000000D+00, &\n 0.9960937500000000D+00, &\n 0.9999363101685547D+00, &\n 0.9983650626000000D+00, &\n 0.9901259090013672D+00, &\n 0.9672065024000000D+00, &\n 0.9218730926513672D+00, &\n 0.8497316674000000D+00, &\n 0.6331032576000000D+00, &\n 0.3769531250000000D+00 /)\n integer ( kind = 4 ) n_data\n integer ( kind = 4 ) x\n integer ( kind = 4 ), save, dimension ( n_max ) :: x_vec = (/ &\n 0, 1, 2, 0, &\n 1, 0, 1, 2, &\n 3, 4, 4, 4, &\n 4, 4, 4, 4, &\n 4 /)\n\n if ( n_data < 0 ) then\n n_data = 0\n end if\n\n n_data = n_data + 1\n\n if ( n_max < n_data ) then\n n_data = 0\n a = 0\n b = 0.0D+00\n x = 0\n fx = 0.0D+00\n else\n a = a_vec(n_data)\n b = b_vec(n_data)\n x = x_vec(n_data)\n fx = fx_vec(n_data)\n end if\n\n return\nend\nsubroutine binomial_cdf_inv ( cdf, a, b, x )\n\n!*****************************************************************************80\n!\n!! BINOMIAL_CDF_INV inverts the Binomial CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 06 March 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Input, integer ( kind = 4 ) A, the number of trials.\n! 1 <= A.\n!\n! Input, real ( kind = 8 ) B, the probability of success on one trial.\n! 0.0D+00 <= B <= 1.0.\n!\n! Output, integer ( kind = 4 ) X, the corresponding argument.\n!\n implicit none\n\n integer ( kind = 4 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) cdf2\n real ( kind = 8 ) pdf\n integer ( kind = 4 ) x\n integer ( kind = 4 ) x2\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BINOMIAL_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n cdf2 = 0.0D+00\n\n do x2 = 0, a\n\n call binomial_pdf ( x2, a, b, pdf )\n\n cdf2 = cdf2 + pdf\n\n if ( cdf <= cdf2 ) then\n x = x2\n return\n end if\n\n end do\n\n return\nend\nfunction binomial_check ( a, b )\n\n!*****************************************************************************80\n!\n!! BINOMIAL_CHECK checks the parameter of the Binomial PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 18 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, the number of trials.\n! 1 <= A.\n!\n! Input, real ( kind = 8 ) B, the probability of success on one trial.\n! 0.0D+00 <= B <= 1.0.\n!\n! Output, logical BINOMIAL_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n integer ( kind = 4 ) a\n real ( kind = 8 ) b\n logical binomial_check\n\n if ( a < 1 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BINOMIAL_CHECK - Fatal error!'\n write ( *, '(a)' ) ' A < 1.'\n binomial_check = .false.\n return\n end if\n\n if ( b < 0.0D+00 .or. 1.0D+00 < b ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BINOMIAL_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B < 0 or 1 < B.'\n binomial_check = .false.\n return\n end if\n\n binomial_check = .true.\n\n return\nend\nsubroutine binomial_coef ( n, k, cnk )\n\n!*****************************************************************************80\n!\n!! BINOMIAL_COEF computes the Binomial coefficient C(N,K).\n!\n! Discussion:\n!\n! The value is calculated in such a way as to avoid overflow and\n! roundoff. The calculation is done in integer arithmetic.\n!\n! The formula is:\n!\n! CNK = C(N,K) = N! / ( K! * (N-K)! )\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 17 January 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! ML Wolfson, HV Wright,\n! Combinatorial of M Things Taken N at a Time,\n! ACM Algorithm 160,\n! Communications of the ACM,\n! April, 1963.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, K, are the values of N and K.\n!\n! Output, integer ( kind = 4 ) CNK, the number of combinations of N\n! things taken K at a time.\n!\n implicit none\n\n integer ( kind = 4 ) cnk\n integer ( kind = 4 ) i\n integer ( kind = 4 ) k\n integer ( kind = 4 ) mn\n integer ( kind = 4 ) mx\n integer ( kind = 4 ) n\n\n mn = min ( k, n - k )\n\n if ( mn < 0 ) then\n\n cnk = 0\n\n else if ( mn == 0 ) then\n\n cnk = 1\n\n else\n\n mx = max ( k, n - k )\n cnk = mx + 1\n\n do i = 2, mn\n cnk = ( cnk * ( mx + i ) ) / i\n end do\n\n end if\n\n return\nend\nsubroutine binomial_coef_log ( n, k, cnk_log )\n\n!*****************************************************************************80\n!\n!! BINOMIAL_COEF_LOG computes the logarithm of the Binomial coefficient.\n!\n! Discussion:\n!\n! The formula is:\n!\n! CNK_LOG = LOG ( C(N,K) ) = LOG ( N! / ( K! * (N-K)! ) ).\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, K, are the values of N and K.\n!\n! Output, real ( kind = 8 ) CNK_LOG, the logarithm of C(N,K).\n!\n implicit none\n\n real ( kind = 8 ) cnk_log\n real ( kind = 8 ) factorial_log\n integer ( kind = 4 ) k\n integer ( kind = 4 ) n\n\n cnk_log = factorial_log ( n ) - factorial_log ( k ) - factorial_log ( n - k )\n\n return\nend\nsubroutine binomial_mean ( a, b, mean )\n\n!*****************************************************************************80\n!\n!! BINOMIAL_MEAN returns the mean of the Binomial PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 January 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, the number of trials.\n! 1 <= A.\n!\n! Input, real ( kind = 8 ) B, the probability of success on one trial.\n! 0.0D+00 <= B <= 1.0.\n!\n! Output, real ( kind = 8 ) MEAN, the expected value of the number of\n! successes in A trials.\n!\n implicit none\n\n integer ( kind = 4 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) mean\n\n mean = real ( a, kind = 8 ) * b\n\n return\nend\nsubroutine binomial_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! BINOMIAL_PDF evaluates the Binomial PDF.\n!\n! Discussion:\n!\n! PDF(A,B;X) is the probability of exactly X successes in A trials,\n! given that the probability of success on a single trial is B.\n!\n! The formula is:\n!\n! PDF(A,B;X) = C(N,X) * B^X * ( 1.0D+00 - B )^( A - X )\n!\n! Binomial_PDF(1,B;X) = Bernoulli_PDF(B;X).\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 January 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X, the desired number of successes.\n! 0 <= X <= A.\n!\n! Input, integer ( kind = 4 ) A, the number of trials.\n! 1 <= A.\n!\n! Input, real ( kind = 8 ) B, the probability of success on one trial.\n! 0.0D+00 <= B <= 1.0.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n real ( kind = 8 ) b\n integer ( kind = 4 ) cnk\n real ( kind = 8 ) pdf\n integer ( kind = 4 ) x\n\n if ( a < 1 ) then\n\n pdf = 0.0D+00\n\n else if ( x < 0 .or. a < x ) then\n\n pdf = 0.0D+00\n\n else if ( b == 0.0D+00 ) then\n\n if ( x == 0 ) then\n pdf = 1.0D+00\n else\n pdf = 0.0D+00\n end if\n\n else if ( b == 1.0D+00 ) then\n\n if ( x == a ) then\n pdf = 1.0D+00\n else\n pdf = 0.0D+00\n end if\n\n else\n\n call binomial_coef ( a, x, cnk )\n\n pdf = real ( cnk, kind = 8 ) * b**x * ( 1.0D+00 - b )**( a - x )\n\n end if\n\n return\nend\nsubroutine binomial_sample ( a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! BINOMIAL_SAMPLE samples the Binomial PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! William Kennedy, James Gentle,\n! Algorithm BU,\n! Statistical Computing,\n! Dekker, 1980.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, the number of trials.\n! 1 <= A.\n!\n! Input, real ( kind = 8 ) B, the probability of success on one trial.\n! 0.0D+00 <= B <= 1.0.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, integer ( kind = 4 ) X, a sample of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) i\n integer ( kind = 4 ) seed\n real ( kind = 8 ) u\n integer ( kind = 4 ) x\n\n x = 0\n\n do i = 1, a\n\n u = r8_uniform_01 ( seed )\n\n if ( u <= b ) then\n x = x + 1\n end if\n\n end do\n\n return\nend\nsubroutine binomial_variance ( a, b, variance )\n\n!*****************************************************************************80\n!\n!! BINOMIAL_VARIANCE returns the variance of the Binomial PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 January 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, the number of trials.\n! 1 <= A.\n!\n! Input, real ( kind = 8 ) B, the probability of success on one trial.\n! 0.0D+00 <= B <= 1.0.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) variance\n\n variance = real ( a, kind = 8 ) * b * ( 1.0D+00 - b )\n\n return\nend\nsubroutine bradford_cdf ( x, a, b, c, cdf )\n\n!*****************************************************************************80\n!\n!! BRADFORD_CDF evaluates the Bradford CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! A < B,\n! 0.0D+00 < C.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( x <= a ) then\n cdf = 0.0D+00\n else if ( x <= b ) then\n cdf = log ( 1.0D+00 + c * ( x - a ) / ( b - a ) ) / log ( c + 1.0D+00 )\n else if ( b < x ) then\n cdf = 1.0D+00\n end if\n\n return\nend\nsubroutine bradford_cdf_inv ( cdf, a, b, c, x )\n\n!*****************************************************************************80\n!\n!! BRADFORD_CDF_INV inverts the Bradford CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! A < B,\n! 0.0D+00 < C.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BRADFORD_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n if ( cdf <= 0.0D+00 ) then\n x = a\n else if ( cdf < 1.0D+00 ) then\n x = a + ( b - a ) * ( ( c + 1.0D+00 )**cdf - 1.0D+00 ) / c\n else if ( 1.0D+00 <= cdf ) then\n x = b\n end if\n\n return\nend\nfunction bradford_check ( a, b, c )\n\n!*****************************************************************************80\n!\n!! BRADFORD_CHECK checks the parameters of the Bradford PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! A < B,\n! 0.0D+00 < C.\n!\n! Output, logical BRADFORD_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n logical bradford_check\n real ( kind = 8 ) c\n\n if ( b <= a ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BRADFORD_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B <= A.'\n bradford_check = .false.\n return\n end if\n\n if ( c <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BRADFORD_CHECK - Fatal error!'\n write ( *, '(a)' ) ' C <= 0.'\n bradford_check = .false.\n return\n end if\n\n bradford_check = .true.\n\n return\nend\nsubroutine bradford_mean ( a, b, c, mean )\n\n!*****************************************************************************80\n!\n!! BRADFORD_MEAN returns the mean of the Bradford PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! A < B,\n! 0.0D+00 < C.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) mean\n\n mean = ( c * ( b - a ) + log ( c + 1.0D+00 ) * ( a * ( c + 1.0D+00 ) - b ) ) &\n / ( c * log ( c + 1.0D+00 ) )\n\n return\nend\nsubroutine bradford_pdf ( x, a, b, c, pdf )\n\n!*****************************************************************************80\n!\n!! BRADFORD_PDF evaluates the Bradford PDF.\n!\n! Discussion:\n!\n! The formula is:\n!\n! PDF(A,B,C;X) =\n! C / ( ( C * ( X - A ) + B - A ) * log ( C + 1 ) )\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n! A <= X\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! A < B,\n! 0.0D+00 < C.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) pdf\n real ( kind = 8 ) x\n\n if ( x <= a ) then\n pdf = 0.0D+00\n else if ( x <= b ) then\n pdf = c / ( ( c * ( x - a ) + b - a ) * log ( c + 1.0D+00 ) )\n else if ( b < x ) then\n pdf = 0.0D+00\n end if\n\n return\nend\nsubroutine bradford_sample ( a, b, c, seed, x )\n\n!*****************************************************************************80\n!\n!! BRADFORD_SAMPLE samples the Bradford PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! A < B,\n! 0.0D+00 < C.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n x = a + ( b - a ) * ( ( c + 1.0D+00 )**cdf - 1.0D+00 ) / c\n\n return\nend\nsubroutine bradford_variance ( a, b, c, variance )\n\n!*****************************************************************************80\n!\n!! BRADFORD_VARIANCE returns the variance of the Bradford PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! A < B,\n! 0.0D+00 < C.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) variance\n\n variance = ( b - a )**2 * &\n ( c * ( log ( c + 1.0D+00 ) - 2.0D+00 ) + 2.0D+00 * log ( c + 1.0D+00 ) ) &\n / ( 2.0D+00 * c * ( log ( c + 1.0D+00 ) )**2 )\n\n return\nend\nsubroutine buffon_laplace_pdf ( a, b, l, pdf )\n\n!*****************************************************************************80\n!\n!! BUFFON_LAPLACE_PDF evaluates the Buffon-Laplace PDF.\n!\n! Discussion:\n!\n! In the Buffon-Laplace needle experiment, we suppose that the plane has been\n! tiled into a grid of rectangles of width A and height B, and that a\n! needle of length L is dropped \"at random\" onto this grid.\n!\n! We may assume that one end, the \"eye\" of the needle falls at the point\n! (X1,Y1), taken uniformly at random in the cell [0,A]x[0,B].\n!\n! ANGLE, the angle that the needle makes is taken to be uniformly random.\n! The point of the needle, (X2,Y2), therefore lies at\n!\n! (X2,Y2) = ( X1+L*cos(ANGLE), Y1+L*sin(ANGLE) )\n!\n! The needle will have crossed at least one grid line if any of the\n! following are true:\n!\n! X2 <= 0, A <= X2, Y2 <= 0, B <= Y2.\n!\n! If L is larger than sqrt ( A*A + B*B ), then the needle will\n! cross every time, and the computation is uninteresting. However, if\n! L is smaller than this limit, then the probability of a crossing on\n! a single trial is\n!\n! P(L,A,B) = ( 2 * L * ( A + B ) - L * L ) / ( PI * A * B )\n!\n! and therefore, a record of the number of hits for a given number of\n! trials can be used as a very roundabout way of estimating PI.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 26 February 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Sudarshan Raghunathan,\n! Making a Supercomputer Do What You Want: High Level Tools for\n! Parallel Programming,\n! Computing in Science and Engineering,\n! Volume 8, Number 5, September/October 2006, pages 70-80.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the horizontal and vertical dimensions\n! of each cell of the grid. 0 <= A, 0 <= B.\n!\n! Input, real ( kind = 8 ) L, the length of the needle.\n! 0 <= L <= min ( A, B ).\n!\n! Output, real ( kind = 8 ) PDF, the Buffon-Laplace PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) l\n real ( kind = 8 ) pdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793238462643D+00\n\n if ( a < 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BUFFON_LAPLACE_PDF - Fatal error!'\n write ( *, '(a)' ) ' Input A < 0.'\n stop 1\n else if ( a == 0.0D+00 ) then\n pdf = 1.0D+00\n return\n end if\n\n if ( b < 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BUFFON_LAPLACE_PDF - Fatal error!'\n write ( *, '(a)' ) ' Input B < 0.'\n stop 1\n else if ( b == 0.0D+00 ) then\n pdf = 1.0D+00\n return\n end if\n\n if ( l < 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BUFFON_LAPLACE_PDF - Fatal error!'\n write ( *, '(a)' ) ' Input L < 0.'\n stop 1\n else if ( l == 0.0D+00 ) then\n pdf = 0.0D+00\n return\n else if ( min ( a, b ) < l ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BUFFON_LAPLACE_PDF - Fatal error!'\n write ( *, '(a)' ) ' min ( A, B ) < L.'\n stop 1\n end if\n\n pdf = l * ( 2.0D+00 * ( a + b ) - l ) / ( pi * a * b )\n\n return\nend\nfunction buffon_laplace_simulate ( a, b, l, trial_num, seed )\n\n!*****************************************************************************80\n!\n!! BUFFON_LAPLACE_SIMULATE simulates a Buffon-Laplace needle experiment.\n!\n! Discussion:\n!\n! In the Buffon-Laplace needle experiment, we suppose that the plane has \n! been tiled into a grid of rectangles of width A and height B, and that a\n! needle of length L is dropped \"at random\" onto this grid.\n!\n! We may assume that one end, the \"eye\" of the needle falls at the point\n! (X1,Y1), taken uniformly at random in the cell [0,A]x[0,B].\n!\n! ANGLE, the angle that the needle makes is taken to be uniformly random.\n! The point of the needle, (X2,Y2), therefore lies at\n!\n! (X2,Y2) = ( X1+L*cos(ANGLE), Y1+L*sin(ANGLE) )\n!\n! The needle will have crossed at least one grid line if any of the\n! following are true:\n!\n! X2 <= 0, A <= X2, Y2 <= 0, B <= Y2.\n!\n! This routine simulates the tossing of the needle, and returns the number\n! of times that the needle crossed at least one grid line.\n!\n! If L is larger than sqrt ( A*A + B*B ), then the needle will\n! cross every time, and the computation is uninteresting. However, if\n! L is smaller than this limit, then the probability of a crossing on\n! a single trial is\n!\n! P(L,A,B) = ( 2 * L * ( A + B ) - L * L ) / ( PI * A * B )\n!\n! and therefore, a record of the number of hits for a given number of\n! trials can be used as a very roundabout way of estimating PI.\n! (Particularly roundabout, since we actually will use a good value of\n! PI in order to pick the random angles!)\n!\n! Note that this routine will try to generate 5 * TRIAL_NUM random\n! double precision values at one time, using automatic arrays.\n! When I tried this with TRIAL_NUM = 1,000,000, the program failed,\n! because of internal system limits on such arrays.\n!\n! Such a problem could be avoided by using a DO loop running through\n! each trial individually, but this tend to run much more slowly than\n! necessary.\n!\n! Since this routine invokes the FORTRAN90 random number generator,\n! the user should initialize the random number generator, particularly\n! if it is desired to control whether the sequence is to be varied\n! or repeated.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 26 February 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Sudarshan Raghunathan,\n! Making a Supercomputer Do What You Want: High Level Tools for\n! Parallel Programming,\n! Computing in Science and Engineering,\n! Volume 8, Number 5, September/October 2006, pages 70-80.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the horizontal and vertical dimensions\n! of each cell of the grid. 0 <= A, 0 <= B.\n!\n! Input, real ( kind = 8 ) L, the length of the needle.\n! 0 <= L <= min ( A, B ).\n!\n! Input, integer ( kind = 4 ) TRIAL_NUM, the number of times the needle is\n! to be dropped onto the grid.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, integer ( kind = 4 ) BUFFON_LAPLACE_SIMULATE, the number of times\n! the needle crossed at least one line of the grid of cells.\n!\n! Local Parameters:\n!\n! Local, integer BATCH_SIZE, specifies the number of trials to be done\n! in a single batch. Setting BATCH_SIZE to 1 will be very slow.\n! Replacing it by TRIAL_NUM would be fine except that your system\n! may have a limit on the size of automatic arrays. We have set a default\n! value of 10,000 here which should be large enough to be efficient\n! but small enough not to annoy the system.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: batch_size = 10000\n integer ( kind = 4 ) trial_num\n\n real ( kind = 8 ) a\n real ( kind = 8 ) angle(batch_size)\n real ( kind = 8 ) b\n integer ( kind = 4 ) batch\n integer ( kind = 4 ) buffon_laplace_simulate\n integer ( kind = 4 ) hits\n real ( kind = 8 ) l\n integer ( kind = 4 ) n\n real ( kind = 8 ), parameter :: pi = 3.141592653589793238462643D+00\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x1(batch_size)\n real ( kind = 8 ) x2(batch_size)\n real ( kind = 8 ) y1(batch_size)\n real ( kind = 8 ) y2(batch_size)\n\n hits = 0\n\n do batch = 1, trial_num, batch_size\n\n n = min ( batch_size, trial_num + 1 - batch )\n!\n! Randomly choose the location of the eye of the needle in [0,0]x[A,B],\n! and the angle the needle makes.\n!\n call random_number ( harvest = x1(1:n) )\n call random_number ( harvest = y1(1:n) )\n call random_number ( harvest = angle(1:n) )\n\n x1(1:n) = a * x1(1:n)\n y1(1:n) = b * y1(1:n)\n angle(1:n) = 2.0D+00 * pi * angle(1:n)\n!\n! Compute the location of the point of the needle.\n!\n x2(1:n) = x1(1:n) + l * cos ( angle(1:n) )\n y2(1:n) = y1(1:n) + l * sin ( angle(1:n) )\n!\n! Count the end locations that lie outside the cell.\n!\n hits = hits + count ( x2(1:n) <= 0.0 .or. &\n a <= x2(1:n) .or. &\n y2(1:n) <= 0.0 .or. &\n b <= y2(1:n) )\n\n end do\n\n buffon_laplace_simulate = hits\n\n return\nend\nsubroutine buffon_pdf ( a, l, pdf )\n\n!*****************************************************************************80\n!\n!! BUFFON_PDF evaluates the Buffon PDF.\n!\n! Discussion:\n!\n! In the Buffon needle experiment, we suppose that the plane has been\n! ruled by vertical lines with a spacing of A units, and that a\n! needle of length L is dropped \"at random\" onto this grid.\n!\n! Because of the various symmetries, we may assume that this eye of\n! this needle lands in the first infinite strip, and we may further\n! assume that its Y coordinate is 0. Thus, we have\n! the eye as (X1,Y1) with 0 <= X1 <= A and Y1 = 0.\n!\n! ANGLE, the angle that the needle makes is taken to be uniformly random.\n! The point of the needle, (X2,Y2), therefore lies at\n!\n! (X2,Y2) = ( X1+L*cos(ANGLE), Y1+L*sin(ANGLE) )\n!\n! The needle will have crossed at least one grid line if any of the\n! following are true:\n!\n! X2 <= 0, A <= X2.\n!\n! The probability of a crossing on a single trial is\n!\n! P(A,L) = ( 2 * L ) / ( PI * A )\n!\n! and therefore, a record of the number of hits for a given number of\n! trials can be used as a very roundabout way of estimating PI.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 March 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the horizontal spacing between the\n! vertical grid lines. 0 <= A.\n!\n! Input, real ( kind = 8 ) L, the length of the needle.\n!\n! Output, real ( kind = 8 ) PDF, the Buffon PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) l\n real ( kind = 8 ) pdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793238462643D+00\n\n if ( a < 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BUFFON_PDF - Fatal error!'\n write ( *, '(a)' ) ' Input A < 0.'\n stop 1\n else if ( a == 0.0D+00 ) then\n pdf = 1.0D+00\n return\n end if\n\n if ( l < 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BUFFON_PDF - Fatal error!'\n write ( *, '(a)' ) ' Input L < 0.'\n stop 1\n else if ( l == 0.0D+00 ) then\n pdf = 0.0D+00\n return\n end if\n\n pdf = ( 2.0D+00 * l ) / ( pi * a )\n\n return\nend\nfunction buffon_simulate ( a, l, trial_num )\n\n!*****************************************************************************80\n!\n!! BUFFON_SIMULATE simulates a Buffon needle experiment.\n!\n! Discussion:\n!\n! In the Buffon needle experiment, we suppose that the plane has been\n! ruled by vertical lines with a spacing of A units, and that a\n! needle of length L is dropped \"at random\" onto this grid.\n!\n! Because of the various symmetries, we may assume that this eye of\n! this needle lands in the first infinite strip, and we may further\n! assume that its Y coordinate is 0. Thus, we have\n! the eye as (X1,Y1) with 0 <= X1 <= A and Y1 = 0.\n!\n! ANGLE, the angle that the needle makes is taken to be uniformly random.\n! The point of the needle, (X2,Y2), therefore lies at\n!\n! (X2,Y2) = ( X1+L*cos(ANGLE), Y1+L*sin(ANGLE) )\n!\n! The needle will have crossed at least one grid line if any of the\n! following are true:\n!\n! X2 <= 0, A <= X2.\n!\n! The probability of a crossing on a single trial is\n!\n! P(A,L) = ( 2 * L ) / ( PI * A )\n!\n! and therefore, a record of the number of hits for a given number of\n! trials can be used as a very roundabout way of estimating PI.\n!\n! Note that this routine will try to generate 4 * TRIAL_NUM random\n! double precision values at one time, using automatic arrays.\n! When I tried this with TRIAL_NUM = 1,000,000, the program failed,\n! because of internal system limits on such arrays.\n!\n! Such a problem could be avoided by using a DO loop running through\n! each trial individually, but this tend to run much more slowly than\n! necessary.\n!\n! Since this routine invokes the FORTRAN90 random number generator,\n! the user should initialize the random number generator, particularly\n! if it is desired to control whether the sequence is to be varied\n! or repeated.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 March 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the horizontal spacing between the\n! vertical grid lines. 0 <= A.\n!\n! Input, real ( kind = 8 ) L, the length of the needle.\n!\n! Input, integer ( kind = 4 ) TRIAL_NUM, the number of times the needle is\n! to be dropped onto the grid.\n!\n! Output, integer ( kind = 4 ) BUFFON_SIMULATE, the number of times the\n! needle crossed at least one line of the grid of cells.\n!\n! Local Parameters:\n!\n! Local, integer BATCH_SIZE, specifies the number of trials to be done\n! in a single batch. Setting BATCH_SIZE to 1 will be very slow.\n! Replacing it by TRIAL_NUM would be fine except that your system\n! may have a limit on the size of automatic arrays. We have set a default\n! value of 10,000 here which should be large enough to be efficient\n! but small enough not to annoy the system.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: batch_size = 10000\n integer ( kind = 4 ) trial_num\n\n real ( kind = 8 ) a\n real ( kind = 8 ) angle(batch_size)\n integer ( kind = 4 ) batch\n integer ( kind = 4 ) buffon_simulate\n integer ( kind = 4 ) hits\n real ( kind = 8 ) l\n integer ( kind = 4 ) n\n real ( kind = 8 ), parameter :: pi = 3.141592653589793238462643D+00\n real ( kind = 8 ) x1(batch_size)\n real ( kind = 8 ) x2(batch_size)\n\n hits = 0\n\n do batch = 1, trial_num, batch_size\n\n n = min ( batch_size, trial_num + 1 - batch )\n!\n! Randomly choose the location (X1,Y1) of the eye of the needle\n! in [0,0]x[A,0], and the angle the needle makes.\n!\n call random_number ( harvest = x1(1:n) )\n call random_number ( harvest = angle(1:n) )\n\n x1(1:n) = a * x1(1:n)\n angle(1:n) = 2.0D+00 * pi * angle(1:n)\n!\n! Compute the location of the point of the needle.\n! We only need to know the value of X2, not Y2!\n!\n x2(1:n) = x1(1:n) + l * cos ( angle(1:n) )\n!\n! Count the end locations that lie outside the cell.\n!\n hits = hits + count ( x2(1:n) <= 0.0 .or. &\n a <= x2(1:n) )\n\n end do\n\n buffon_simulate = hits\n\n return\nend\nsubroutine burr_cdf ( x, a, b, c, d, cdf )\n\n!*****************************************************************************80\n!\n!! BURR_CDF evaluates the Burr CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n!\n! Input, real ( kind = 8 ) A, B, C, D, the parameters of the PDF.\n! 0 < B,\n! 0 < C.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) cdf\n real ( kind = 8 ) d\n real ( kind = 8 ) x\n\n if ( x <= a ) then\n\n cdf = 0.0D+00\n\n else\n\n cdf = 1.0D+00 / ( 1.0D+00 + ( b / ( x - a ) )**c )**d\n\n end if\n\n return\nend\nsubroutine burr_cdf_inv ( cdf, a, b, c, d, x )\n\n!*****************************************************************************80\n!\n!! BURR_CDF_INV inverts the Burr CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Input, real ( kind = 8 ) A, B, C, D, the parameters of the PDF.\n! 0 < B,\n! 0 < C.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) cdf\n real ( kind = 8 ) d\n real ( kind = 8 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BURR_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n x = a + b / ( ( 1.0D+00 / cdf )**(1.0D+00 / d ) - 1.0D+00 )**( 1.0D+00 / c )\n\n return\nend\nfunction burr_check ( a, b, c, d )\n\n!*****************************************************************************80\n!\n!! BURR_CHECK checks the parameters of the Burr CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, D, the parameters of the PDF.\n! 0 < B,\n! 0 < C.\n!\n! Output, logical BURR_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n logical burr_check\n real ( kind = 8 ) c\n real ( kind = 8 ) d\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BURR_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B <= 0.'\n burr_check = .false.\n return\n end if\n\n if ( c <= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BURR_CHECK - Fatal error!'\n write ( *, '(a)' ) ' C <= 0.'\n burr_check = .false.\n return\n end if\n\n burr_check = .true.\n\n return\nend\nsubroutine burr_mean ( a, b, c, d, mean )\n\n!*****************************************************************************80\n!\n!! BURR_MEAN returns the mean of the Burr PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, D, the parameters of the PDF.\n! 0 < B,\n! 0 < C.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) d\n real ( kind = 8 ) mean\n real ( kind = 8 ) r8_gamma\n\n mean = a + b * r8_gamma ( 1.0D+00 - 1.0D+00 / c ) &\n * r8_gamma ( d + 1.0D+00 / c ) / r8_gamma ( d )\n\n return\nend\nsubroutine burr_pdf ( x, a, b, c, d, pdf )\n\n!*****************************************************************************80\n!\n!! BURR_PDF evaluates the Burr PDF.\n!\n! Discussion:\n!\n! The formula is:\n!\n! PDF(A,B,C,D;X) = ( C * D / B ) * ( ( X - A ) / B )^( - C - 1 )\n! * ( 1 + ( ( X - A ) / B )^( - C ) )^( - D - 1 )\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Mark Johnson,\n! Multivariate Statistical Simulation,\n! Wiley, 1987.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n! A <= X\n!\n! Input, real ( kind = 8 ) A, B, C, D, the parameters of the PDF.\n! 0 < B,\n! 0 < C.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) d\n real ( kind = 8 ) pdf\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n\n if ( x <= a ) then\n pdf = 0.0D+00\n else\n\n y = ( x - a ) / b\n\n pdf = ( c * d / b ) * y**( - c - 1.0D+00 ) &\n * ( 1.0D+00 + y**( - c ) )**( - d - 1.0D+00 )\n\n end if\n\n return\nend\nsubroutine burr_sample ( a, b, c, d, seed, x )\n\n!*****************************************************************************80\n!\n!! BURR_SAMPLE samples the Burr PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, D, the parameters of the PDF.\n! 0 < B,\n! 0 < C.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) cdf\n real ( kind = 8 ) d\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call burr_cdf_inv ( cdf, a, b, c, d, x )\n\n return\nend\nsubroutine burr_variance ( a, b, c, d, variance )\n\n!*****************************************************************************80\n!\n!! BURR_VARIANCE returns the variance of the Burr PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, D, the parameters of the PDF.\n! 0 < B,\n! 0 < C.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) d\n real ( kind = 8 ) k\n real ( kind = 8 ) r8_gamma\n real ( kind = 8 ) variance\n\n if ( c <= 2.0D+00 ) then\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BURR_VARIANCE - Warning!'\n write ( *, '(a)' ) ' Variance undefined for C <= 2.'\n variance = huge ( variance )\n\n else\n\n k = r8_gamma ( d ) * r8_gamma ( 1.0D+00 - 2.0D+00 / c ) &\n * r8_gamma ( d + 2.0D+00 / c ) &\n - ( r8_gamma ( 1.0D+00 - 1.0D+00 / c ) * r8_gamma ( d + 1.0D+00 / c ) )**2\n\n variance = k * b * b / ( r8_gamma ( d ) )**2\n\n end if\n\n return\nend\nsubroutine c4_normal_01_sample ( seed, x )\n\n!*****************************************************************************80\n!\n!! C4_NORMAL_01_SAMPLE samples the complex Normal 01 PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 July 2005\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, complex ( kind = 4 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 4 ) r4_uniform_01\n real ( kind = 4 ), parameter :: pi = 3.141592653589793D+00\n integer ( kind = 4 ) seed\n real ( kind = 4 ) v1\n real ( kind = 4 ) v2\n complex ( kind = 4 ) x\n real ( kind = 4 ) x_c\n real ( kind = 4 ) x_r\n\n v1 = r4_uniform_01 ( seed )\n v2 = r4_uniform_01 ( seed )\n\n x_r = sqrt ( - 2.0E+00 * log ( v1 ) ) * cos ( 2.0E+00 * pi * v2 )\n x_c = sqrt ( - 2.0E+00 * log ( v1 ) ) * sin ( 2.0E+00 * pi * v2 )\n\n x = cmplx ( x_r, x_c, kind = 4 )\n\n return\nend\nsubroutine cardioid_cdf ( x, a, b, cdf )\n\n!*****************************************************************************80\n!\n!! CARDIOID_CDF evaluates the Cardioid CDF.\n!\n! Discussion:\n!\n! The angle X is assumed to lie between A - PI and A + PI.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 July 2005\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n! A - PI <= X <= A + PI.\n!\n! Input, real ( kind = 8 ) A, B, the parameters.\n! -0.5 <= B <= 0.5.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) x\n\n if ( x <= a - pi ) then\n cdf = 0.0D+00\n else if ( x < a + pi ) then\n cdf = ( pi + x - a + 2.0D+00 * b * sin ( x - a ) ) / ( 2.0D+00 * pi )\n else\n cdf = 1.0D+00\n end if\n\n return\nend\nsubroutine cardioid_cdf_inv ( cdf, a, b, x )\n\n!*****************************************************************************80\n!\n!! CARDIOID_CDF_INV inverts the Cardioid CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 31 July 2005\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0 <= CDF <= 1.\n!\n! Input, real ( kind = 8 ) A, B, the parameters.\n! -0.5 <= B <= 0.5.\n!\n! Output, real ( kind = 8 ) X, the argument with the given CDF.\n! A - PI <= X <= A + PI.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) fp\n real ( kind = 8 ) fx\n integer ( kind = 4 ) it\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ), parameter :: tol = 0.000001D+00\n real ( kind = 8 ) x\n\n if ( cdf <= 0.0D+00 ) then\n\n x = a - pi\n\n else if ( cdf < 1.0D+00 ) then\n\n x = a\n\n it = 0\n\n do\n\n fx = cdf - ( pi + x - a + 2.0D+00 * b * sin ( x - a ) ) / ( 2.0D+00 * pi )\n\n if ( abs ( fx ) < tol ) then\n exit\n end if\n\n if ( 10 < it ) then\n stop 1\n end if\n\n fp = - ( 1.0D+00 + 2.0D+00 * b * cos ( x - a ) ) / ( 2.0D+00 * pi )\n\n x = x - fx / fp\n x = max ( x, a - pi )\n x = min ( x, a + pi )\n\n it = it + 1\n\n end do\n\n else\n\n x = a + pi\n\n end if\n\n return\nend\nfunction cardioid_check ( a, b )\n\n!*****************************************************************************80\n!\n!! CARDIOID_CHECK checks the parameters of the Cardioid CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 31 July 2005\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! -0.5 <= B <= 0.5.\n!\n! Output, logical CARDIOID_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n logical cardioid_check\n\n if ( b < -0.5D+00 .or. 0.5D+00 < b ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'CARDIOID_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B < -0.5 or 0.5 < B.'\n cardioid_check = .false.\n return\n end if\n\n cardioid_check = .true.\n\n return\nend\nsubroutine cardioid_mean ( a, b, mean )\n\n!*****************************************************************************80\n!\n!! CARDIOID_MEAN returns the mean of the Cardioid PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 July 2005\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! -0.5 <= B <= 0.5.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) mean\n\n mean = a\n\n return\nend\nsubroutine cardioid_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! CARDIOID_PDF evaluates the Cardioid PDF.\n!\n! Discussion:\n!\n! The cardioid PDF can be thought of as being applied to points on\n! a circle. Compare this distribution with the \"Cosine PDF\".\n!\n! PDF(A,B;X) = ( 1 / ( 2 * PI ) ) * ( 1 + 2 * B * COS ( X - A ) )\n! for A - PI <= X <= A + PI, -1/2 <= B <= 1/2.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 July 2005\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Nicholas Fisher,\n! Statistical Analysis of Circular Data,\n! Cambridge, 1993.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n! A - PI <= X <= A + PI.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! -0.5 <= B <= 0.5.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) pdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) x\n\n pdf = ( 1.0D+00 + 2.0D+00 * b * cos ( x - a ) ) / ( 2.0D+00 * pi )\n\n return\nend\nsubroutine cardioid_sample ( a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! CARDIOID_SAMPLE samples the Cardioid PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 July 2005\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! -0.5 <= B <= 0.5.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n! A - PI <= X <= A + PI.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call cardioid_cdf_inv ( cdf, a, b, x )\n\n return\nend\nsubroutine cardioid_variance ( a, b, variance )\n\n!*****************************************************************************80\n!\n!! CARDIOID_VARIANCE returns the variance of the Cardioid PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 31 July 2005\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! -0.5 <= B <= 0.5.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) variance\n\n variance = 0.0D+00\n\n return\nend\nsubroutine cauchy_cdf ( x, a, b, cdf )\n\n!*****************************************************************************80\n!\n!! CAUCHY_CDF evaluates the Cauchy CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n\n cdf = 0.5D+00 + atan2 ( x - a, b ) / PI\n\n return\nend\nsubroutine cauchy_cdf_inv ( cdf, a, b, x )\n\n!*****************************************************************************80\n!\n!! CAUCHY_CDF_INV inverts the Cauchy CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'CAUCHY_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n x = a + b * tan ( pi * ( cdf - 0.5D+00 ) )\n\n return\nend\nsubroutine cauchy_cdf_values ( n_data, mu, sigma, x, fx )\n\n!*****************************************************************************80\n!\n!! CAUCHY_CDF_VALUES returns some values of the Cauchy CDF.\n!\n! Discussion:\n!\n! In Mathematica, the function can be evaluated by:\n!\n! Needs[\"Statistics`ContinuousDistributions`\"]\n! dist = CauchyDistribution [ mu, sigma ]\n! CDF [ dist, x ]\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Milton Abramowitz, Irene Stegun,\n! Handbook of Mathematical Functions,\n! National Bureau of Standards, 1964,\n! LC: QA47.A34,\n! ISBN: 0-486-61272-4.\n!\n! Stephen Wolfram,\n! The Mathematica Book,\n! Fourth Edition,\n! Wolfram Media / Cambridge University Press, 1999.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) N_DATA. The user sets N_DATA to 0 \n! before the first call. On each call, the routine increments N_DATA by 1, \n! and returns the corresponding data; when there is no more data, the\n! output value of N_DATA will be 0 again.\n!\n! Output, real ( kind = 8 ) MU, the mean of the distribution.\n!\n! Output, real ( kind = 8 ) SIGMA, the variance of the distribution.\n!\n! Output, real ( kind = 8 ) X, the argument of the function.\n!\n! Output, real ( kind = 8 ) FX, the value of the function.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: n_max = 12\n\n real ( kind = 8 ) fx\n real ( kind = 8 ), save, dimension ( n_max ) :: fx_vec = (/ &\n 0.5000000000000000D+00, &\n 0.8524163823495667D+00, &\n 0.9220208696226307D+00, &\n 0.9474315432887466D+00, &\n 0.6475836176504333D+00, &\n 0.6024163823495667D+00, &\n 0.5779791303773693D+00, &\n 0.5628329581890012D+00, &\n 0.6475836176504333D+00, &\n 0.5000000000000000D+00, &\n 0.3524163823495667D+00, &\n 0.2500000000000000D+00 /)\n real ( kind = 8 ) mu\n real ( kind = 8 ), save, dimension ( n_max ) :: mu_vec = (/ &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.4000000000000000D+01, &\n 0.5000000000000000D+01 /)\n integer ( kind = 4 ) n_data\n real ( kind = 8 ) sigma\n real ( kind = 8 ), save, dimension ( n_max ) :: sigma_vec = (/ &\n 0.5000000000000000D+00, &\n 0.5000000000000000D+00, &\n 0.5000000000000000D+00, &\n 0.5000000000000000D+00, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.4000000000000000D+01, &\n 0.5000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01 /)\n real ( kind = 8 ) x\n real ( kind = 8 ), save, dimension ( n_max ) :: x_vec = (/ &\n 0.1000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.4000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.3000000000000000D+01 /)\n\n if ( n_data < 0 ) then\n n_data = 0\n end if\n\n n_data = n_data + 1\n\n if ( n_max < n_data ) then\n n_data = 0\n mu = 0.0D+00\n sigma = 0.0D+00\n x = 0.0D+00\n fx = 0.0D+00\n else\n mu = mu_vec(n_data)\n sigma = sigma_vec(n_data)\n x = x_vec(n_data)\n fx = fx_vec(n_data)\n end if\n\n return\nend\nfunction cauchy_check ( a, b )\n\n!*****************************************************************************80\n!\n!! CAUCHY_CHECK checks the parameters of the Cauchy CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 09 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, logical CAUCHY_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n logical cauchy_check\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'CAUCHY_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B <= 0.'\n cauchy_check = .false.\n return\n end if\n\n cauchy_check = .true.\n\n return\nend\nsubroutine cauchy_mean ( a, b, mean )\n\n!*****************************************************************************80\n!\n!! CAUCHY_MEAN returns the mean of the Cauchy PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 12 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) mean\n\n mean = a\n\n return\nend\nsubroutine cauchy_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! CAUCHY_PDF evaluates the Cauchy PDF.\n!\n! Discussion:\n!\n! PDF(A,B;X) = 1 / ( PI * B * ( 1 + ( ( X - A ) / B )^2 ) )\n!\n! The Cauchy PDF is also known as the Breit-Wigner PDF. It\n! has some unusual properties. In particular, the integrals for the\n! expected value and higher order moments are \"singular\", in the\n! sense that the limiting values do not exist. A result can be\n! obtained if the upper and lower limits of integration are set\n! equal to +T and -T, and the limit as T => +oo is taken, but\n! this is a very weak and unreliable sort of limit.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 09 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) pdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n\n y = ( x - a ) / b\n\n pdf = 1.0D+00 / ( pi * b * ( 1.0D+00 + y * y ) )\n\n return\nend\nsubroutine cauchy_sample ( a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! CAUCHY_SAMPLE samples the Cauchy PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 11 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call cauchy_cdf_inv ( cdf, a, b, x )\n\n return\nend\nsubroutine cauchy_variance ( a, b, variance )\n\n!*****************************************************************************80\n!\n!! CAUCHY_VARIANCE returns the variance of the Cauchy PDF.\n!\n! Discussion:\n!\n! The variance of the Cauchy PDF is not well defined. This routine\n! is made available for completeness only, and simply returns\n! a \"very large\" number.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) VARIANCE, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) variance\n\n variance = huge ( variance )\n\n return\nend\nsubroutine chi_cdf ( x, a, b, c, cdf )\n\n!*****************************************************************************80\n!\n!! CHI_CDF evaluates the Chi CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0 < B,\n! 0 < C.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) cdf\n real ( kind = 8 ) gamma_inc\n real ( kind = 8 ) p2\n real ( kind = 8 ) x\n real ( kind = 8 ) x2\n real ( kind = 8 ) y\n\n if ( x <= a ) then\n\n cdf = 0.0D+00\n\n else\n\n y = ( x - a ) / b\n x2 = 0.5D+00 * y * y\n p2 = 0.5D+00 * c\n\n cdf = gamma_inc ( p2, x2 )\n\n end if\n\n return\nend\nsubroutine chi_cdf_inv ( cdf, a, b, c, x )\n\n!*****************************************************************************80\n!\n!! CHI_CDF_INV inverts the Chi CDF.\n!\n! Discussion:\n!\n! A simple bisection method is used.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0 < B,\n! 0 < C.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) cdf\n real ( kind = 8 ) cdf1\n real ( kind = 8 ) cdf2\n real ( kind = 8 ) cdf3\n integer ( kind = 4 ) it\n integer ( kind = 4 ), parameter :: it_max = 100\n real ( kind = 8 ), parameter :: tol = 0.0001D+00\n real ( kind = 8 ) x\n real ( kind = 8 ) x1\n real ( kind = 8 ) x2\n real ( kind = 8 ) x3\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'CHI_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n if ( cdf == 0.0D+00 ) then\n x = a\n return\n else if ( 1.0D+00 == cdf ) then\n x = huge ( x )\n return\n end if\n\n x1 = a\n cdf1 = 0.0D+00\n\n x2 = a + 1.0D+00\n\n do\n\n call chi_cdf ( x2, a, b, c, cdf2 )\n\n if ( cdf < cdf2 ) then\n exit\n end if\n\n x2 = a + 2.0D+00 * ( x2 - a )\n\n end do\n!\n! Now use bisection.\n!\n it = 0\n\n do\n\n it = it + 1\n\n x3 = 0.5D+00 * ( x1 + x2 )\n call chi_cdf ( x3, a, b, c, cdf3 )\n\n if ( abs ( cdf3 - cdf ) < tol ) then\n x = x3\n return\n end if\n\n if ( it_max < it ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'CHI_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' Iteration limit exceeded.'\n return\n end if\n\n if ( sign ( 1.0D+00, cdf3 - cdf ) == sign ( 1.0D+00, cdf1 - cdf ) ) then\n x1 = x3\n cdf1 = cdf3\n else\n x2 = x3\n cdf2 = cdf3\n end if\n\n end do\n\n return\nend\nfunction chi_check ( a, b, c )\n\n!*****************************************************************************80\n!\n!! CHI_CHECK checks the parameters of the Chi CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 31 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0 < B,\n! 0 < C.\n!\n! Output, logical CHI_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n logical chi_check\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'CHI_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B <= 0.0.'\n chi_check = .false.\n return\n end if\n\n if ( c <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'CHI_CHECK - Fatal error!'\n write ( *, '(a)' ) ' C <= 0.0.'\n chi_check = .false.\n return\n end if\n\n chi_check = .true.\n\n return\nend\nsubroutine chi_mean ( a, b, c, mean )\n\n!*****************************************************************************80\n!\n!! CHI_MEAN returns the mean of the Chi PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 31 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0 < B,\n! 0 < C.\n!\n! Output, real ( kind = 8 ) MEAN, the mean value.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) mean\n real ( kind = 8 ) r8_gamma\n\n mean = a + sqrt ( 2.0D+00 ) * b * r8_gamma ( 0.5D+00 * ( c + 1.0D+00 ) ) &\n / r8_gamma ( 0.5D+00 * c )\n\n return\nend\nsubroutine chi_pdf ( x, a, b, c, pdf )\n\n!*****************************************************************************80\n!\n!! CHI_PDF evaluates the Chi PDF.\n!\n! Discussion:\n!\n! PDF(A,B,C;X) = EXP ( - 0.5D+00 * ( ( X - A ) / B )^2 )\n! * ( ( X - A ) / B )^( C - 1 ) /\n! ( 2^( 0.5D+00 * C - 1 ) * B * GAMMA ( 0.5D+00 * C ) )\n!\n! CHI(A,B,1) is the Half Normal PDF;\n! CHI(0,B,2) is the Rayleigh PDF;\n! CHI(0,B,3) is the Maxwell PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 31 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n! A <= X\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0 < B,\n! 0 < C.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) pdf\n real ( kind = 8 ) r8_gamma\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n\n if ( x <= a ) then\n\n pdf = 0.0D+00\n\n else\n\n y = ( x - a ) / b\n\n pdf = exp ( - 0.5D+00 * y * y ) * y**( c - 1.0D+00 ) / &\n ( 2.0D+00**( 0.5D+00 * c - 1.0D+00 ) * b * r8_gamma ( 0.5D+00 * c ) )\n\n end if\n\n return\nend\nsubroutine chi_sample ( a, b, c, seed, x )\n\n!*****************************************************************************80\n!\n!! CHI_SAMPLE samples the Chi PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0 < B,\n! 0 < C.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n call chi_square_sample ( c, seed, x )\n\n x = a + b * sqrt ( x )\n\n return\nend\nsubroutine chi_variance ( a, b, c, variance )\n\n!*****************************************************************************80\n!\n!! CHI_VARIANCE returns the variance of the Chi PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 31 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0 < B,\n! 0 < C.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) r8_gamma\n real ( kind = 8 ) variance\n\n variance = b * b * ( c - 2.0D+00 * &\n ( r8_gamma ( 0.5D+00 * ( c + 1.0D+00 ) ) / r8_gamma ( 0.5D+00 * c ) )**2 )\n\n return\nend\nsubroutine chi_square_cdf ( x, a, cdf )\n\n!*****************************************************************************80\n!\n!! CHI_SQUARE_CDF evaluates the Chi squared CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 10 October 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the value of the random deviate.\n!\n! Input, real ( kind = 8 ) A, the parameter of the distribution, usually\n! the number of degrees of freedom.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) a2\n real ( kind = 8 ) b2\n real ( kind = 8 ) c2\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n real ( kind = 8 ) x2\n\n x2 = 0.5D+00 * x\n\n a2 = 0.0D+00\n b2 = 1.0D+00\n c2 = 0.5D+00 * a\n\n call gamma_cdf ( x2, a2, b2, c2, cdf )\n\n return\nend\nsubroutine chi_square_cdf_inv ( cdf, a, x )\n\n!*****************************************************************************80\n!\n!! CHI_SQUARE_CDF_INV inverts the Chi squared PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 11 October 2004\n!\n! Author:\n!\n! Original FORTAN77 version by Donald Best, Roberts.\n! FORTRAN90 version by John Burkardt\n!\n! Reference:\n!\n! Donald Best, Roberts,\n! The Percentage Points of the Chi-Squared Distribution,\n! Algorithm AS 91,\n! Applied Statistics,\n! Volume 24, Number ?, pages 385-390, 1975.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, a value of the chi-squared cumulative\n! probability density function.\n! 0.000002 <= CDF <= 0.999998.\n!\n! Input, real ( kind = 8 ) A, the parameter of the chi-squared\n! probability density function. 0 < A.\n!\n! Output, real ( kind = 8 ) X, the value of the chi-squared random deviate\n! with the property that the probability that a chi-squared random\n! deviate with parameter A is less than or equal to X is CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) a2\n real ( kind = 8 ), parameter :: aa = 0.6931471806D+00\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ), parameter :: c1 = 0.01D+00\n real ( kind = 8 ), parameter :: c2 = 0.222222D+00\n real ( kind = 8 ), parameter :: c3 = 0.32D+00\n real ( kind = 8 ), parameter :: c4 = 0.4D+00\n real ( kind = 8 ), parameter :: c5 = 1.24D+00\n real ( kind = 8 ), parameter :: c6 = 2.2D+00\n real ( kind = 8 ), parameter :: c7 = 4.67D+00\n real ( kind = 8 ), parameter :: c8 = 6.66D+00\n real ( kind = 8 ), parameter :: c9 = 6.73D+00\n real ( kind = 8 ), parameter :: c10 = 13.32D+00\n real ( kind = 8 ), parameter :: c11 = 60.0D+00\n real ( kind = 8 ), parameter :: c12 = 70.0D+00\n real ( kind = 8 ), parameter :: c13 = 84.0D+00\n real ( kind = 8 ), parameter :: c14 = 105.0D+00\n real ( kind = 8 ), parameter :: c15 = 120.0D+00\n real ( kind = 8 ), parameter :: c16 = 127.0D+00\n real ( kind = 8 ), parameter :: c17 = 140.0D+00\n real ( kind = 8 ), parameter :: c18 = 175.0D+00\n real ( kind = 8 ), parameter :: c19 = 210.0D+00\n real ( kind = 8 ), parameter :: c20 = 252.0D+00\n real ( kind = 8 ), parameter :: c21 = 264.0D+00\n real ( kind = 8 ), parameter :: c22 = 294.0D+00\n real ( kind = 8 ), parameter :: c23 = 346.0D+00\n real ( kind = 8 ), parameter :: c24 = 420.0D+00\n real ( kind = 8 ), parameter :: c25 = 462.0D+00\n real ( kind = 8 ), parameter :: c26 = 606.0D+00\n real ( kind = 8 ), parameter :: c27 = 672.0D+00\n real ( kind = 8 ), parameter :: c28 = 707.0D+00\n real ( kind = 8 ), parameter :: c29 = 735.0D+00\n real ( kind = 8 ), parameter :: c30 = 889.0D+00\n real ( kind = 8 ), parameter :: c31 = 932.0D+00\n real ( kind = 8 ), parameter :: c32 = 966.0D+00\n real ( kind = 8 ), parameter :: c33 = 1141.0D+00\n real ( kind = 8 ), parameter :: c34 = 1182.0D+00\n real ( kind = 8 ), parameter :: c35 = 1278.0D+00\n real ( kind = 8 ), parameter :: c36 = 1740.0D+00\n real ( kind = 8 ), parameter :: c37 = 2520.0D+00\n real ( kind = 8 ), parameter :: c38 = 5040.0D+00\n real ( kind = 8 ) cdf\n real ( kind = 8 ), parameter :: cdf_max = 0.999998D+00\n real ( kind = 8 ), parameter :: cdf_min = 0.000002D+00\n real ( kind = 8 ) ch\n real ( kind = 8 ), parameter :: e = 0.0000005D+00\n real ( kind = 8 ) g\n real ( kind = 8 ) gamma_inc\n real ( kind = 8 ) gamma_log\n integer ( kind = 4 ) i\n integer ( kind = 4 ), parameter :: it_max = 20\n real ( kind = 8 ) p1\n real ( kind = 8 ) p2\n real ( kind = 8 ) q\n real ( kind = 8 ) s1\n real ( kind = 8 ) s2\n real ( kind = 8 ) s3\n real ( kind = 8 ) s4\n real ( kind = 8 ) s5\n real ( kind = 8 ) s6\n real ( kind = 8 ) t\n real ( kind = 8 ) x\n real ( kind = 8 ) x2\n real ( kind = 8 ) xx\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'CHI_SQUARE_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n write ( *, '(a,g14.6)' ) ' CDF = ', cdf\n stop 1\n end if\n\n if ( cdf < cdf_min ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'CHI_SQUARE_CDF_INV - Warning!'\n write ( *, '(a)' ) ' CDF < CDF_MIN.'\n write ( *, '(a,g14.6)' ) ' CDF = ', cdf\n write ( *, '(a,g14.6)' ) ' CDF_MIN = ', cdf_min\n end if\n\n if ( cdf_max < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'CHI_SQUARE_CDF_INV - Warning!'\n write ( *, '(a)' ) ' CDF_MAX < CDF.'\n write ( *, '(a,g14.6)' ) ' CDF = ', cdf\n write ( *, '(a,g14.6)' ) ' CDF_MAX = ', cdf_max\n end if\n\n xx = 0.5D+00 * a\n c = xx - 1.0D+00\n!\n! Compute Log ( Gamma ( A/2 ) ).\n!\n g = gamma_log ( a / 2.0D+00 )\n!\n! Starting approximation for small chi-squared.\n!\n if ( a < - c5 * log ( cdf ) ) then\n\n ch = ( cdf * xx * exp ( g + xx * aa ) ) ** ( 1.0D+00 / xx )\n\n if ( ch < e ) then\n x = ch\n return\n end if\n!\n! Starting approximation for A less than or equal to 0.32.\n!\n else if ( a <= c3 ) then\n\n ch = c4\n a2 = log ( 1.0D+00 - cdf )\n\n do\n\n q = ch\n p1 = 1.0D+00 + ch * ( c7 + ch )\n p2 = ch * ( c9 + ch * ( c8 + ch ) )\n\n t = - 0.5D+00 + ( c7 + 2.0D+00 * ch ) / p1 &\n - ( c9 + ch * ( c10 + 3.0D+00 * ch ) ) / p2\n\n ch = ch - ( 1.0D+00 - exp ( a2 + g + 0.5D+00 * ch + c * aa ) &\n * p2 / p1 ) / t\n\n if ( abs ( q / ch - 1.0D+00 ) <= c1 ) then\n exit\n end if\n\n end do\n!\n! Call to algorithm AS 111.\n! Note that P has been tested above.\n! AS 241 could be used as an alternative.\n!\n else\n\n call normal_01_cdf_inv ( cdf, x2 )\n!\n! Starting approximation using Wilson and Hilferty estimate.\n!\n p1 = c2 / a\n ch = a * ( x2 * sqrt ( p1 ) + 1.0D+00 - p1 ) ** 3\n!\n! Starting approximation for P tending to 1.\n!\n if ( c6 * a + 6.0D+00 < ch ) then\n ch = - 2.0D+00 * ( log ( 1.0D+00 - cdf ) - c * log ( 0.5D+00 * ch ) + g )\n end if\n\n end if\n!\n! Call to algorithm AS 239 and calculation of seven term Taylor series.\n!\n do i = 1, it_max\n\n q = ch\n p1 = 0.5D+00 * ch\n p2 = cdf - gamma_inc ( xx, p1 )\n t = p2 * exp ( xx * aa + g + p1 - c * log ( ch ) )\n b = t / ch\n a2 = 0.5D+00 * t - b * c\n\n s1 = ( c19 + a2 &\n * ( c17 + a2 &\n * ( c14 + a2 &\n * ( c13 + a2 &\n * ( c12 + a2 &\n * c11 ) ) ) ) ) / c24\n\n s2 = ( c24 + a2 &\n * ( c29 + a2 &\n * ( c32 + a2 &\n * ( c33 + a2 &\n * c35 ) ) ) ) / c37\n\n s3 = ( c19 + a2 &\n * ( c25 + a2 &\n * ( c28 + a2 &\n * c31 ) ) ) / c37\n\n s4 = ( c20 + a2 &\n * ( c27 + a2 &\n * c34 ) + c &\n * ( c22 + a2 &\n * ( c30 + a2 &\n * c36 ) ) ) / c38\n\n s5 = ( c13 + c21 * a2 + c * ( c18 + c26 * a2 ) ) / c37\n\n s6 = ( c15 + c * ( c23 + c16 * c ) ) / c38\n\n ch = ch + t * ( 1.0D+00 + 0.5D+00 * t * s1 - b * c &\n * ( s1 - b &\n * ( s2 - b &\n * ( s3 - b &\n * ( s4 - b &\n * ( s5 - b &\n * s6 ) ) ) ) ) )\n\n if ( e < abs ( q / ch - 1.0D+00 ) ) then\n x = ch\n return\n end if\n\n end do\n\n x = ch\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'CHI_SQUARE_CDF_INV - Warning!'\n write ( *, '(a)' ) ' Convergence not reached.'\n\n return\nend\nsubroutine chi_square_cdf_values ( n_data, a, x, fx )\n\n!*****************************************************************************80\n!\n!! CHI_SQUARE_CDF_VALUES returns some values of the Chi-Square CDF.\n!\n! Discussion:\n!\n! In Mathematica, the function can be evaluated by:\n!\n! Needs[\"Statistics`ContinuousDistributions`\"]\n! dist = ChiSquareDistribution [ df ]\n! CDF [ dist, x ]\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 09 August 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Milton Abramowitz, Irene Stegun,\n! Handbook of Mathematical Functions,\n! National Bureau of Standards, 1964,\n! LC: QA47.A34,\n! ISBN: 0-486-61272-4.\n!\n! Stephen Wolfram,\n! The Mathematica Book,\n! Fourth Edition,\n! Wolfram Media / Cambridge University Press, 1999.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) N_DATA. The user sets N_DATA to 0 \n! before the first call. On each call, the routine increments N_DATA by 1, \n! and returns the corresponding data; when there is no more data, the\n! output value of N_DATA will be 0 again.\n!\n! Output, integer ( kind = 4 ) A, the parameter of the function.\n!\n! Output, real ( kind = 8 ) X, the argument of the function.\n!\n! Output, real ( kind = 8 ) FX, the value of the function.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: n_max = 21\n\n integer ( kind = 4 ) a\n integer ( kind = 4 ), save, dimension ( n_max ) :: a_vec = (/ &\n 1, 2, 1, 2, &\n 1, 2, 3, 4, &\n 1, 2, 3, 4, &\n 5, 3, 3, 3, &\n 3, 3, 10, 10, &\n 10 /)\n real ( kind = 8 ) fx\n real ( kind = 8 ), save, dimension ( n_max ) :: fx_vec = (/ &\n 0.7965567455405796D-01, &\n 0.4987520807317687D-02, &\n 0.1124629160182849D+00, &\n 0.9950166250831946D-02, &\n 0.4729107431344619D+00, &\n 0.1812692469220181D+00, &\n 0.5975750516063926D-01, &\n 0.1752309630642177D-01, &\n 0.6826894921370859D+00, &\n 0.3934693402873666D+00, &\n 0.1987480430987992D+00, &\n 0.9020401043104986D-01, &\n 0.3743422675270363D-01, &\n 0.4275932955291202D+00, &\n 0.6083748237289110D+00, &\n 0.7385358700508894D+00, &\n 0.8282028557032669D+00, &\n 0.8883897749052874D+00, &\n 0.1721156299558408D-03, &\n 0.3659846827343712D-02, &\n 0.1857593622214067D-01 /)\n integer ( kind = 4 ) n_data\n real ( kind = 8 ) x\n real ( kind = 8 ), save, dimension ( n_max ) :: x_vec = (/ &\n 0.01D+00, &\n 0.01D+00, &\n 0.02D+00, &\n 0.02D+00, &\n 0.40D+00, &\n 0.40D+00, &\n 0.40D+00, &\n 0.40D+00, &\n 1.00D+00, &\n 1.00D+00, &\n 1.00D+00, &\n 1.00D+00, &\n 1.00D+00, &\n 2.00D+00, &\n 3.00D+00, &\n 4.00D+00, &\n 5.00D+00, &\n 6.00D+00, &\n 1.00D+00, &\n 2.00D+00, &\n 3.00D+00 /)\n\n if ( n_data < 0 ) then\n n_data = 0\n end if\n\n n_data = n_data + 1\n\n if ( n_max < n_data ) then\n n_data = 0\n a = 0\n x = 0.0D+00\n fx = 0.0D+00\n else\n a = a_vec(n_data)\n x = x_vec(n_data)\n fx = fx_vec(n_data)\n end if\n\n return\nend\nfunction chi_square_check ( a )\n\n!*****************************************************************************80\n!\n!! CHI_SQUARE_CHECK checks the parameter of the central Chi squared PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the parameter of the distribution.\n! 1 <= A.\n!\n! Output, logical CHI_SQUARE_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n logical chi_square_check\n\n if ( a < 1.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'CHI_SQUARE_CHECK - Fatal error!'\n write ( *, '(a)' ) ' A < 1.0.'\n chi_square_check = .false.\n return\n end if\n\n chi_square_check = .true.\n\n return\nend\nsubroutine chi_square_mean ( a, mean )\n\n!*****************************************************************************80\n!\n!! CHI_SQUARE_MEAN returns the mean of the central Chi squared PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 November 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the parameter of the distribution.\n! 1 <= A.\n!\n! Output, real ( kind = 8 ) MEAN, the mean value.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) mean\n\n mean = a\n\n return\nend\nsubroutine chi_square_pdf ( x, a, pdf )\n\n!*****************************************************************************80\n!\n!! CHI_SQUARE_PDF evaluates the central Chi squared PDF.\n!\n! Discussion:\n!\n! PDF(A;X) =\n! EXP ( - X / 2 ) * X^((A-2)/2) / ( 2^(A/2) * GAMMA ( A/2 ) )\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 November 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n! 0.0D+00 <= X\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 1 <= A.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) pdf\n real ( kind = 8 ) r8_gamma\n real ( kind = 8 ) x\n\n if ( x < 0.0D+00 ) then\n pdf = 0.0D+00\n else\n b = a / 2.0D+00\n pdf = exp ( - 0.5D+00 * x ) * x**( b - 1.0D+00 ) &\n / ( 2.0D+00**b * r8_gamma ( b ) )\n end if\n\n return\nend\nsubroutine chi_square_sample ( a, seed, x )\n\n!*****************************************************************************80\n!\n!! CHI_SQUARE_SAMPLE samples the central Chi squared PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 November 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 1 <= A.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) a2\n real ( kind = 8 ) b2\n real ( kind = 8 ) c2\n integer ( kind = 4 ) i\n integer ( kind = 4 ), parameter :: it_max = 100\n integer ( kind = 4 ) n\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n real ( kind = 8 ) x2\n\n n = int ( a )\n\n if ( real ( n, kind = 8 ) == a .and. n <= it_max ) then\n\n x = 0.0D+00\n do i = 1, n\n call normal_01_sample ( seed, x2 )\n x = x + x2 * x2\n end do\n\n else\n\n a2 = 0.0D+00\n b2 = 1.0D+00\n c2 = a / 2.0D+00\n\n call gamma_sample ( a2, b2, c2, seed, x )\n\n x = 2.0D+00 * x\n\n end if\n\n return\nend\nsubroutine chi_square_variance ( a, variance )\n\n!*****************************************************************************80\n!\n!! CHI_SQUARE_VARIANCE returns the variance of the central Chi squared PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 10 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the parameter of the distribution.\n! 1 <= A.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) variance\n\n variance = 2.0D+00 * a\n\n return\nend\nfunction chi_square_noncentral_check ( a, b )\n\n!*****************************************************************************80\n!\n!! CHI_SQUARE_NONCENTRAL_CHECK check parameters of noncentral Chi Squared PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, the parameter of the PDF.\n! 1.0D+00 <= A.\n!\n! Input, real ( kind = 8 ) B, the noncentrality parameter of the PDF.\n! 0.0D+00 <= B.\n!\n! Output, logical CHI_SQUARE_NONCENTRAL_CHECK, is true if the parameters\n! are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n logical chi_square_noncentral_check\n\n if ( a < 1.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'CHI_SQUARE_NONCENTRAL_CHECK - Fatal error!'\n write ( *, '(a)' ) ' A < 1.'\n chi_square_noncentral_check = .false.\n return\n end if\n\n if ( b < 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'CHI_SQUARE_NONCENTRAL_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B < 0.'\n chi_square_noncentral_check = .false.\n return\n end if\n\n chi_square_noncentral_check = .true.\n\n return\nend\nsubroutine chi_square_noncentral_cdf_values ( n_data, df, lambda, x, cdf )\n\n!*****************************************************************************80\n!\n!! CHI_SQUARE_NONCENTRAL_CDF_VALUES returns values of the noncentral chi CDF.\n!\n! Discussion:\n!\n! In Mathematica, the function can be evaluated by:\n!\n! Needs[\"Statistics`ContinuousDistributions`\"]\n! dist = NoncentralChiSquareDistribution [ df, lambda ]\n! CDF [ dist, x ]\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 August 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Stephen Wolfram,\n! The Mathematica Book,\n! Fourth Edition,\n! Wolfram Media / Cambridge University Press, 1999.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) N_DATA. The user sets N_DATA to 0\n! before the first call. On each call, the routine increments N_DATA by 1, \n! and returns the corresponding data; when there is no more data, the\n! output value of N_DATA will be 0 again.\n!\n! Output, integer ( kind = 4 ) DF, the number of degrees of freedom.\n!\n! Output, real ( kind = 8 ) LAMBDA, the noncentrality parameter.\n!\n! Output, real ( kind = 8 ) X, the argument of the function.\n!\n! Output, real ( kind = 8 ) CDF, the noncentral chi CDF.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: n_max = 28\n\n real ( kind = 8 ) cdf\n real ( kind = 8 ), save, dimension ( n_max ) :: cdf_vec = (/ &\n 0.8399444269398261D+00, &\n 0.6959060300435139D+00, &\n 0.5350879697078847D+00, &\n 0.7647841496310313D+00, &\n 0.6206436532195436D+00, &\n 0.4691667375373180D+00, &\n 0.3070884345937569D+00, &\n 0.2203818092990903D+00, &\n 0.1500251895581519D+00, &\n 0.3071163194335791D-02, &\n 0.1763982670131894D-02, &\n 0.9816792594625022D-03, &\n 0.1651753140866208D-01, &\n 0.2023419573950451D-03, &\n 0.4984476352854074D-06, &\n 0.1513252400654827D-01, &\n 0.2090414910614367D-02, &\n 0.2465021206048452D-03, &\n 0.2636835050342939D-01, &\n 0.1857983220079215D-01, &\n 0.1305736595486640D-01, &\n 0.5838039534819351D-01, &\n 0.4249784402463712D-01, &\n 0.3082137716021596D-01, &\n 0.1057878223400849D+00, &\n 0.7940842984598509D-01, &\n 0.5932010895599639D-01, &\n 0.2110395656918684D+00 /)\n integer ( kind = 4 ) df\n integer ( kind = 4 ), save, dimension ( n_max ) :: df_vec = (/ &\n 1, 2, 3, &\n 1, 2, 3, &\n 1, 2, 3, &\n 1, 2, 3, &\n 60, 80, 100, &\n 1, 2, 3, &\n 10, 10, 10, &\n 10, 10, 10, &\n 10, 10, 10, &\n 8 /)\n real ( kind = 8 ) lambda\n real ( kind = 8 ), save, dimension ( n_max ) :: lambda_vec = (/ &\n 0.5D+00, &\n 0.5D+00, &\n 0.5D+00, &\n 1.0D+00, &\n 1.0D+00, &\n 1.0D+00, &\n 5.0D+00, &\n 5.0D+00, &\n 5.0D+00, &\n 20.0D+00, &\n 20.0D+00, &\n 20.0D+00, &\n 30.0D+00, &\n 30.0D+00, &\n 30.0D+00, &\n 5.0D+00, &\n 5.0D+00, &\n 5.0D+00, &\n 2.0D+00, &\n 3.0D+00, &\n 4.0D+00, &\n 2.0D+00, &\n 3.0D+00, &\n 4.0D+00, &\n 2.0D+00, &\n 3.0D+00, &\n 4.0D+00, &\n 0.5D+00 /)\n integer ( kind = 4 ) n_data\n real ( kind = 8 ) x\n real ( kind = 8 ), save, dimension ( n_max ) :: x_vec = (/ &\n 3.000D+00, &\n 3.000D+00, &\n 3.000D+00, &\n 3.000D+00, &\n 3.000D+00, &\n 3.000D+00, &\n 3.000D+00, &\n 3.000D+00, &\n 3.000D+00, &\n 3.000D+00, &\n 3.000D+00, &\n 3.000D+00, &\n 60.000D+00, &\n 60.000D+00, &\n 60.000D+00, &\n 0.050D+00, &\n 0.050D+00, &\n 0.050D+00, &\n 4.000D+00, &\n 4.000D+00, &\n 4.000D+00, &\n 5.000D+00, &\n 5.000D+00, &\n 5.000D+00, &\n 6.000D+00, &\n 6.000D+00, &\n 6.000D+00, &\n 5.000D+00 /)\n\n if ( n_data < 0 ) then\n n_data = 0\n end if\n\n n_data = n_data + 1\n\n if ( n_max < n_data ) then\n n_data = 0\n x = 0.0D+00\n lambda = 0.0D+00\n df = 0\n cdf = 0.0D+00\n else\n x = x_vec(n_data)\n lambda = lambda_vec(n_data)\n df = df_vec(n_data)\n cdf = cdf_vec(n_data)\n end if\n\n return\nend\nsubroutine chi_square_noncentral_mean ( a, b, mean )\n\n!*****************************************************************************80\n!\n!! CHI_SQUARE_NONCENTRAL_MEAN: mean of the noncentral Chi squared PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 November 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, the parameter of the PDF.\n! 1.0D+00 <= A.\n!\n! Input, real ( kind = 8 ) B, the noncentrality parameter of the PDF.\n! 0.0D+00 <= B.\n!\n! Output, real ( kind = 8 ) MEAN, the mean value.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) mean\n\n mean = a + b\n\n return\nend\nsubroutine chi_square_noncentral_sample ( a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! CHI_SQUARE_NONCENTRAL_SAMPLE samples the noncentral Chi squared PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 November 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, the parameter of the PDF.\n! 1.0D+00 <= A.\n!\n! Input, real ( kind = 8 ) B, the noncentrality parameter of the PDF.\n! 0.0D+00 <= B.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) a1\n real ( kind = 8 ) a2\n real ( kind = 8 ) b\n real ( kind = 8 ) b2\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n real ( kind = 8 ) x1\n real ( kind = 8 ) x2\n\n a1 = a - 1.0D+00\n\n call chi_square_sample ( a1, seed, x1 )\n\n a2 = sqrt ( b )\n b2 = 1.0D+00\n call normal_sample ( a2, b2, seed, x2 )\n\n x = x1 + x2 * x2\n\n return\nend\nsubroutine chi_square_noncentral_variance ( a, b, variance )\n\n!*****************************************************************************80\n!\n!! CHI_SQUARE_NONCENTRAL_VARIANCE: variance of the noncentral Chi squared PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 November 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 1 <= A.\n!\n! Input, real ( kind = 8 ) B, the noncentrality parameter of the PDF.\n! 0.0D+00 <= B.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance value.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) variance\n\n variance = 2.0D+00 * ( a + 2.0D+00 * b )\n\n return\nend\nsubroutine circle_sample ( a, b, c, seed, x1, x2 )\n\n!*****************************************************************************80\n!\n!! CIRCLE_SAMPLE samples points from a circle.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 03 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the circle.\n! The circle is centered at (A,B) and has radius C.\n! 0.0D+00 < C.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X1, X2, a sampled point of the circle.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) angle\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) r8_uniform_01\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) radius_frac\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x1\n real ( kind = 8 ) x2\n\n radius_frac = r8_uniform_01 ( seed )\n radius_frac = sqrt ( radius_frac )\n\n angle = 2.0D+00 * pi * r8_uniform_01 ( seed )\n\n x1 = a + c * radius_frac * cos ( angle )\n x2 = b + c * radius_frac * sin ( angle )\n\n return\nend\nsubroutine circular_normal_01_mean ( mean )\n\n!*****************************************************************************80\n!\n!! CIRCULAR_NORMAL_01_MEAN returns the mean of the Circular Normal 01 PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 13 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Output, real ( kind = 8 ) MEAN(2), the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) mean(2)\n\n mean(1:2) = 0.0D+00\n\n return\nend\nsubroutine circular_normal_01_pdf ( x, pdf )\n\n!*****************************************************************************80\n!\n!! CIRCULAR_NORMAL_01_PDF evaluates the Circular Normal 01 PDF.\n!\n! Discussion:\n!\n! PDF(X) = EXP ( - 0.5D+00 * ( X(1)^2 + X(2)^2 ) ) / ( 2 * PI )\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 13 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X(2), the argument of the PDF.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) pdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) x(2)\n\n pdf = exp ( - 0.5D+00 * ( x(1)**2 + x(2)**2 ) ) / ( 2.0D+00 * pi )\n\n return\nend\nsubroutine circular_normal_01_sample ( seed, x )\n\n!*****************************************************************************80\n!\n!! CIRCULAR_NORMAL_01_SAMPLE samples the Circular Normal 01 PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 13 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X(2), a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) r8_uniform_01\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n integer ( kind = 4 ) seed\n real ( kind = 8 ) v1\n real ( kind = 8 ) v2\n real ( kind = 8 ) x(2)\n\n v1 = r8_uniform_01 ( seed )\n v2 = r8_uniform_01 ( seed )\n\n x(1) = sqrt ( - 2.0D+00 * log ( v1 ) ) * cos ( 2.0D+00 * pi * v2 )\n x(2) = sqrt ( - 2.0D+00 * log ( v1 ) ) * sin ( 2.0D+00 * pi * v2 )\n\n return\nend\nsubroutine circular_normal_01_variance ( variance )\n\n!*****************************************************************************80\n!\n!! CIRCULAR_NORMAL_01_VARIANCE: variance of the Circular Normal 01 PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 13 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Output, real ( kind = 8 ) VARIANCE(2), the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) variance(2)\n\n variance(1) = 1.0D+00\n variance(2) = 1.0D+00\n\n return\nend\nsubroutine circular_normal_mean ( a, b, mean )\n\n!*****************************************************************************80\n!\n!! CIRCULAR_NORMAL_MEAN returns the mean of the Circular Normal PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 03 January 2011\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A(2), a parameter of the PDF, the mean value.\n!\n! Input, real ( kind = 8 ) B, a parameter of the PDF, the standard deviation.\n!\n! Output, real ( kind = 8 ) MEAN(2), the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a(2)\n real ( kind = 8 ) b\n real ( kind = 8 ) mean(2)\n\n mean(1:2) = a(1:2)\n\n return\nend\nsubroutine circular_normal_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! CIRCULAR_NORMAL_PDF evaluates the Circular Normal PDF.\n!\n! Discussion:\n!\n! PDF(X) = EXP ( - 0.5D+00 * ( ( (X(1)-A(1))^2 + (X(2)-A(2))^2 ) / B^2 ) \n! / ( 2 * PI * B^2 )\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 03 January 2011\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X(2), the argument of the PDF.\n!\n! Input, real ( kind = 8 ) A(2), a parameter of the PDF, the mean value.\n!\n! Input, real ( kind = 8 ) B, a parameter of the PDF, the standard deviation.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a(2)\n real ( kind = 8 ) b\n real ( kind = 8 ) d\n real ( kind = 8 ) pdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) x(2)\n\n d = ( ( x(1) - a(1) )**2 + ( x(2) - a(2) )**2 ) / b**2\n\n pdf = exp ( - 0.5D+00 * d ) / ( 2.0D+00 * b**2 * pi )\n\n return\nend\nsubroutine circular_normal_sample ( a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! CIRCULAR_NORMAL_SAMPLE samples the Circular Normal PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 03 January 2011\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A(2), a parameter of the PDF, the mean value.\n!\n! Input, real ( kind = 8 ) B, a parameter of the PDF, the standard deviation.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X(2), a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a(2)\n real ( kind = 8 ) b\n real ( kind = 8 ) r\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) v1\n real ( kind = 8 ) v2\n real ( kind = 8 ) x(2)\n\n v1 = r8_uniform_01 ( seed )\n v2 = r8_uniform_01 ( seed )\n\n r = sqrt ( - 2.0D+00 * log ( v1 ) )\n\n x(1) = a(1) + b * r * cos ( 2.0D+00 * pi * v2 )\n x(2) = a(2) + b * r * sin ( 2.0D+00 * pi * v2 )\n\n return\nend\nsubroutine circular_normal_variance ( a, b, variance )\n\n!*****************************************************************************80\n!\n!! CIRCULAR_NORMAL_VARIANCE returns the variance of the Circular Normal PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 03 January 2011\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A(2), a parameter of the PDF, the mean value.\n!\n! Input, real ( kind = 8 ) B, a parameter of the PDF, the standard deviation.\n!\n! Output, real ( kind = 8 ) VARIANCE(2), the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a(2)\n real ( kind = 8 ) b\n real ( kind = 8 ) variance(2)\n\n variance(1) = b**2\n variance(2) = b**2\n\n return\nend\nfunction combinatorial ( n, k )\n\n!*****************************************************************************80\n!\n!! COMBINATORIAL computes the binomial coefficient C(N,K).\n!\n! Discussion:\n!\n! The value is calculated in such a way as to avoid overflow and\n! roundoff. The calculation is done in integer arithmetic.\n!\n! The formula used is:\n!\n! C(N,K) = N! / ( K! * (N-K)! )\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 24 January 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! ML Wolfson, HV Wright,\n! Algorithm 160:\n! Combinatorial of M Things Taken N at a Time,\n! Communications of the ACM,\n! April, 1963.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, K, are the values of N and K.\n!\n! Output, integer ( kind = 4 ) COMBINATORIAL, the number of combinations of N\n! things taken K at a time.\n!\n implicit none\n\n integer ( kind = 4 ) combinatorial\n integer ( kind = 4 ) i\n integer ( kind = 4 ) k\n integer ( kind = 4 ) mn\n integer ( kind = 4 ) mx\n integer ( kind = 4 ) n\n integer ( kind = 4 ) value\n\n mn = min ( k, n - k )\n\n if ( mn < 0 ) then\n\n value = 0\n\n else if ( mn == 0 ) then\n\n value = 1\n\n else\n\n mx = max ( k, n - k )\n value = mx + 1\n\n do i = 2, mn\n value = ( value * ( mx + i ) ) / i\n end do\n\n end if\n\n combinatorial = value\n\n return\nend\nsubroutine cosine_cdf ( x, a, b, cdf )\n\n!*****************************************************************************80\n!\n!! COSINE_CDF evaluates the Cosine CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameter of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n\n if ( x <= a - pi * b ) then\n\n cdf = 0.0D+00\n\n else if ( x <= a + pi * b ) then\n\n y = ( x - a ) / b\n\n cdf = 0.5D+00 + ( y + sin ( y ) ) / ( 2.0D+00 * pi )\n\n else if ( a + pi * b < x ) then\n\n cdf = 1.0D+00\n\n end if\n\n return\nend\nsubroutine cosine_cdf_inv ( cdf, a, b, x )\n\n!*****************************************************************************80\n!\n!! COSINE_CDF_INV inverts the Cosine CDF.\n!\n! Discussion:\n!\n! A simple bisection method is used on the interval\n! [ A - PI * B, A + PI * B ].\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) cdf1\n real ( kind = 8 ) cdf2\n real ( kind = 8 ) cdf3\n integer ( kind = 4 ) it\n integer ( kind = 4 ), parameter :: it_max = 100\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ), parameter :: tol = 0.0001D+00\n real ( kind = 8 ) x\n real ( kind = 8 ) x1\n real ( kind = 8 ) x2\n real ( kind = 8 ) x3\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'COSINE_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n if ( cdf == 0.0D+00 ) then\n x = a - pi * b\n return\n else if ( 1.0D+00 == cdf ) then\n x = a + pi * b\n return\n end if\n\n x1 = a - pi * b\n cdf1 = 0.0D+00\n\n x2 = a + pi * b\n cdf2 = 1.0D+00\n!\n! Now use bisection.\n!\n it = 0\n\n do it = 1, it_max\n\n x3 = 0.5D+00 * ( x1 + x2 )\n call cosine_cdf ( x3, a, b, cdf3 )\n\n if ( abs ( cdf3 - cdf ) < tol ) then\n x = x3\n return\n end if\n\n if ( sign ( 1.0D+00, cdf3 - cdf ) == sign ( 1.0D+00, cdf1 - cdf ) ) then\n x1 = x3\n cdf1 = cdf3\n else\n x2 = x3\n cdf2 = cdf3\n end if\n\n end do\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'COSINE_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' Iteration limit exceeded.'\n\n stop 1\nend\nfunction cosine_check ( a, b )\n\n!*****************************************************************************80\n!\n!! COSINE_CHECK checks the parameters of the Cosine CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameter of the PDF.\n! 0.0D+00 < B.\n!\n! Output, logical COSINE_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n logical cosine_check\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'COSINE_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B <= 0.0'\n cosine_check = .false.\n return\n end if\n\n cosine_check = .true.\n\n return\nend\nsubroutine cosine_mean ( a, b, mean )\n\n!*****************************************************************************80\n!\n!! COSINE_MEAN returns the mean of the Cosine PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) mean\n\n mean = a\n\n return\nend\nsubroutine cosine_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! COSINE_PDF evaluates the Cosine PDF.\n!\n! Discussion:\n!\n! The cosine PDF can be thought of as being applied to points on\n! a circle.\n!\n! PDF(A,B;X) = ( 1 / ( 2 * PI * B ) ) * COS ( ( X - A ) / B )\n! for A - PI * B <= X <= A + PI * B\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) pdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n\n if ( x < a - pi * b ) then\n pdf = 0.0D+00\n\n else if ( x <= a + pi * b ) then\n\n y = ( x - a ) / b\n\n pdf = 1.0D+00 / ( 2.0D+00 * pi * b ) * cos ( y )\n\n else if ( a + pi * b < x ) then\n\n pdf = 0.0D+00\n\n end if\n\n return\nend\nsubroutine cosine_sample ( a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! COSINE_SAMPLE samples the Cosine PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call cosine_cdf_inv ( cdf, a, b, x )\n\n return\nend\nsubroutine cosine_variance ( a, b, variance )\n\n!*****************************************************************************80\n!\n!! COSINE_VARIANCE returns the variance of the Cosine PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) variance\n\n variance = ( pi * pi / 3.0D+00 - 2.0D+00 ) * b * b\n\n return\nend\nsubroutine coupon_complete_pdf ( type_num, box_num, pdf )\n\n!*****************************************************************************80\n!\n!! COUPON_COMPLETE_PDF evaluates the Complete Coupon Collection PDF.\n!\n! Discussion:\n!\n! PDF(TYPE_NUM;BOX_NUM) is the probability that, given an inexhaustible\n! supply of boxes, inside each of which there is one of TYPE_NUM distinct\n! coupons, which are uniformly distributed among the boxes, that it will\n! require opening exactly BOX_NUM boxes to achieve at least one of each\n! kind of coupon.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 25 August 2006\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Herbert Wilf,\n! Some New Aspects of the Coupon Collector's Problem,\n! SIAM Review,\n! Volume 48, Number 3, September 2006, pages 549-565.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) BOX_NUM, the number of boxes that had to be\n! opened in order to just get at least one of each coupon.\n! 0 <= BOX_NUM. If BOX_NUM < TYPE_NUM, then PDF is surely 0.\n!\n! Input, integer ( kind = 4 ) TYPE_NUM, the number of distinct coupons.\n! 1 <= TYPE_NUM.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) box_num\n real ( kind = 8 ) factor\n integer ( kind = 4 ) i\n real ( kind = 8 ) pdf\n integer ( kind = 4 ) stirling2_value\n integer ( kind = 4 ) type_num\n!\n! Nonsense cases.\n!\n if ( box_num < 0 ) then\n\n pdf = 0.0D+00\n\n else if ( type_num < 1 ) then\n\n pdf = 0.0D+00\n!\n! Degenerate but meaningful case.\n!\n else if ( type_num == 1 ) then\n\n if ( box_num == 1 ) then\n pdf = 1.0D+00\n else\n pdf = 0.0D+00\n end if\n!\n! Easy cases.\n!\n else if ( box_num < type_num ) then\n\n pdf = 0.0D+00\n!\n! General case.\n!\n else\n\n factor = 1.0D+00\n do i = 1, type_num\n factor = factor * real ( i, kind = 8 ) / real ( type_num, kind = 8 )\n end do\n do i = type_num + 1, box_num\n factor = factor / real ( type_num, kind = 8 )\n end do\n\n pdf = factor * real ( &\n stirling2_value ( box_num - 1, type_num - 1 ), kind = 8 )\n\n end if\n\n return\nend\nsubroutine coupon_mean ( j, type_num, mean )\n\n!*****************************************************************************80\n!\n!! COUPON_MEAN returns the mean of the Coupon PDF.\n!\n! Discussion:\n!\n! In this version of the coupon collector's problem, we assume\n! that each box contains 1 coupon, that there are TYPE_NUM distinct types\n! of coupon, uniformly distributed among an inexhaustible supply\n! of boxes, and that the collector's goal is to get J distinct\n! types of coupons by opening one box after another.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 14 January 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) J, the number of distinct coupons to be\n! collected. J must be between 1 and TYPE_NUM.\n!\n! Input, integer ( kind = 4 ) TYPE_NUM, the number of distinct coupons.\n!\n! Output, real ( kind = 8 ) MEAN, the mean number of boxes that\n! must be opened in order to just get J distinct kinds.\n!\n implicit none\n\n integer ( kind = 4 ) i\n integer ( kind = 4 ) j\n integer ( kind = 4 ) n\n real ( kind = 8 ) mean\n integer ( kind = 4 ) type_num\n\n if ( type_num < j ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'COUPON_MEAN - Fatal error!'\n write ( *, '(a)' ) ' Number of distinct coupons desired must be no more'\n write ( *, '(a)' ) ' than the total number of distinct coupons.'\n stop 1\n end if\n\n mean = 0.0D+00\n do i = 1, j\n mean = mean + 1.0D+00 / real ( type_num - i + 1, kind = 8 )\n end do\n mean = mean * real ( type_num, kind = 8 )\n\n return\nend\nsubroutine coupon_simulate ( type_num, seed, coupon, box_num )\n\n!*****************************************************************************80\n!\n!! COUPON_SIMULATE simulates the coupon collector's problem.\n!\n! Discussion:\n!\n! The coupon collector needs to collect one of each of TYPE_NUM\n! coupons. The collector may draw one coupon (or, in some settings,\n! open one box) on each trial, and takes as many trials as necessary\n! to complete the task. On each trial, the probability of picking\n! any particular type of coupon is always 1 / TYPE_NUM.\n!\n! Interesting questions include;\n!\n! * what is the expected number of drawings necessary to complete\n! the collection?\n!\n! * How does the expected number of drawings necessary to complete\n! the collection vary as TYPE_NUM increases?\n!\n! * What is the distribution of the numbers of each type of coupon\n! in a typical collection when it is just completed?\n!\n! As TYPE_NUM increases, the number of coupons necessary to be\n! collected in order to get a complete set in any simulation\n! strongly tends to the value TYPE_NUM * LOG ( TYPE_NUM ).\n!\n! If TYPE_NUM is 1, the simulation ends with a single drawing.\n!\n! If TYPE_NUM is 2, then we may call the coupon taken on the first drawing\n! a \"Head\", say, and the process then is similar to the question of the\n! length, plus one, of a run of Heads or Tails in coin flipping.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 13 May 2003\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) TYPE_NUM, the number of types of coupons.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random number\n! generator.\n!\n! Output, integer ( kind = 4 ) COUPON(TYPE_NUM), the number of coupons\n! of each type that were collected during the simulation.\n!\n! Output, integer ( kind = 4 ) BOX_NUM, the total number of boxes opened.\n!\n implicit none\n\n integer ( kind = 4 ) type_num\n\n integer ( kind = 4 ), parameter :: box_max = 2000\n integer ( kind = 4 ) box_num\n integer ( kind = 4 ) coupon(type_num)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) i4_uniform_ab\n integer ( kind = 4 ) seed\n integer ( kind = 4 ) straight\n\n coupon(1:type_num) = 0\n\n straight = 0\n box_num = 0\n!\n! Draw another coupon.\n!\n do while ( box_num < box_max )\n\n i = i4_uniform_ab ( 1, type_num, seed )\n!\n! Increment the number of I coupons.\n!\n coupon(i) = coupon(i) + 1\n box_num = box_num + 1\n!\n! If I is the next one we needed, increase STRAIGHT by 1.\n!\n if ( i == straight + 1 ) then\n\n do\n\n straight = straight + 1\n!\n! If STRAIGHT = TYPE_NUM, we have all of them.\n!\n if ( type_num <= straight ) then\n return\n end if\n!\n! If the next coupon has not been collected, our straight is over.\n!\n if ( coupon(straight+1) <= 0 ) then\n exit\n end if\n\n end do\n\n end if\n\n end do\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'COUPON_SIMULATE - Fatal error!'\n write ( *, '(a)' ) ' Maximum number of coupons drawn without success.'\n\n stop 1\nend\nsubroutine coupon_variance ( j, type_num, variance )\n\n!*****************************************************************************80\n!\n!! COUPON_VARIANCE returns the variance of the Coupon PDF.\n!\n! Discussion:\n!\n! In this version of the coupon collector's problem, we assume\n! that each box contains 1 coupon, that there are TYPE_NUM distinct types\n! of coupon, uniformly distributed among an inexhaustible supply\n! of boxes, and that the collector's goal is to get J distinct\n! types of coupons by opening one box after another.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 14 January 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) J, the number of distinct coupons to be\n! collected. 1 <= J <= TYPE_NUM.\n!\n! Input, integer ( kind = 4 ) TYPE_NUM, the number of types of coupons.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the number of\n! boxes that must be opened in order to just get J distinct kinds\n! of coupons.\n!\n implicit none\n\n integer ( kind = 4 ) i\n integer ( kind = 4 ) j\n integer ( kind = 4 ) type_num\n real ( kind = 8 ) variance\n\n if ( type_num < j ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'COUPON_VARIANCE - Fatal error!'\n write ( *, '(a)' ) ' Number of distinct coupons desired must be no more'\n write ( *, '(a)' ) ' than the total number of distinct coupons.'\n stop 1\n end if\n\n variance = 0.0D+00\n do i = 1, j\n variance = variance + real ( i - 1, kind = 8 ) &\n / real ( type_num - i + 1, kind = 8 )**2\n end do\n variance = variance * real ( type_num, kind = 8 )\n\n return\nend\nsubroutine deranged_cdf ( x, a, cdf )\n\n!*****************************************************************************80\n!\n!! DERANGED_CDF evaluates the Deranged CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 06 March 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X, the maximum number of items in\n! their correct places.\n! 0 <= X <= A.\n!\n! Input, integer ( kind = 4 ) A, the number of items.\n! 1 <= A.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n real ( kind = 8 ) cdf\n integer ( kind = 4 ) cnk\n integer ( kind = 4 ) deranged_enum\n integer ( kind = 4 ) dnmk\n real ( kind = 8 ) i4_factorial\n integer ( kind = 4 ) sum2\n integer ( kind = 4 ) x\n integer ( kind = 4 ) x2\n\n if ( x < 0 .or. a < x ) then\n cdf = 0.0D+00\n else\n sum2 = 0\n do x2 = 0, x\n call binomial_coef ( a, x2, cnk )\n dnmk = deranged_enum ( a-x2 )\n sum2 = sum2 + cnk * dnmk\n end do\n cdf = real ( sum2, kind = 8 ) / i4_factorial ( a )\n end if\n\n return\nend\nsubroutine deranged_cdf_inv ( cdf, a, x )\n\n!*****************************************************************************80\n!\n!! DERANGED_CDF_INV inverts the Deranged CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 06 March 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Input, integer ( kind = 4 ) A, the number of items.\n! 1 <= A.\n!\n! Output, integer ( kind = 4 ) X, the corresponding argument.\n!\n implicit none\n\n integer ( kind = 4 ) a\n real ( kind = 8 ) cdf\n real ( kind = 8 ) cdf2\n real ( kind = 8 ) pdf\n integer ( kind = 4 ) x\n integer ( kind = 4 ) x2\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'DERANGED_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n cdf2 = 0.0D+00\n\n do x2 = 0, a\n\n call deranged_pdf ( x2, a, pdf )\n\n cdf2 = cdf2 + pdf\n\n if ( cdf <= cdf2 ) then\n x = x2\n return\n end if\n\n end do\n\n x = a\n\n return\nend\nfunction deranged_check ( a )\n\n!*****************************************************************************80\n!\n!! DERANGED_CHECK checks the parameter of the Deranged PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, the total number of items.\n! 1 <= A.\n!\n! Output, logical DERANGED_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n integer ( kind = 4 ) a\n logical deranged_check\n\n if ( a < 1 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'DERANGED_CHECK - Fatal error!'\n write ( *, '(a)' ) ' A < 1.'\n deranged_check = .false.\n return\n end if\n\n deranged_check = .true.\n\n return\nend\nfunction deranged_enum ( n )\n\n!*****************************************************************************80\n!\n!! DERANGED_ENUM returns the number of derangements of N objects.\n!\n! Discussion:\n!\n! A derangement of N objects is a permutation with no fixed\n! points. If we symbolize the permutation operation by \"P\",\n! then for a derangment, P(I) is never equal to I.\n!\n! D(0) = 1\n! D(1) = 0\n! D(2) = 1\n! D(N) = (N-1) * ( D(N-1) + D(N-2) )\n!\n! or\n!\n! D(0) = 1\n! D(1) = 0\n! D(N) = N * D(N-1) + (-1)^N\n!\n! D(N) = N! * ( 1 - 1/1! + 1/2! - 1/3! ... 1/N! )\n!\n! Based on the inclusion/exclusion law.\n!\n! D(N) is the number of ways of placing N non-attacking rooks on\n! an N by N chessboard with one diagonal deleted.\n!\n! Limit ( N -> Infinity ) D(N)/N! = 1 / e.\n!\n! The number of permutations with exactly K items in the right\n! place is COMB(N,K) * D(N-K).\n!\n! First values:\n!\n! N D(N)\n! 0 1\n! 1 0\n! 2 1\n! 3 2\n! 4 9\n! 5 44\n! 6 265\n! 7 1854\n! 8 14833\n! 9 133496\n! 10 1334961\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of objects to be permuted.\n!\n! Output, integer ( kind = 4 ) DERANGED_ENUM, the number of derangements\n! of N objects.\n!\n implicit none\n\n integer ( kind = 4 ) deranged_enum\n integer ( kind = 4 ) dn\n integer ( kind = 4 ) dnm1\n integer ( kind = 4 ) dnm2\n integer ( kind = 4 ) i\n integer ( kind = 4 ) n\n\n if ( n < 0 ) then\n\n dn = 0\n\n else if ( n == 0 ) then\n\n dn = 1\n\n else if ( n == 1 ) then\n\n dn = 0\n\n else if ( n == 2 ) then\n\n dn = 1\n\n else\n\n dnm1 = 0\n dn = 1\n\n do i = 3, n\n dnm2 = dnm1\n dnm1 = dn\n dn = ( i - 1 ) * ( dnm1 + dnm2 )\n end do\n\n end if\n\n deranged_enum = dn\n\n return\nend\nsubroutine deranged_mean ( a, mean )\n\n!*****************************************************************************80\n!\n!! DERANGED_MEAN returns the mean of the Deranged CDF.\n!\n! Discussion:\n!\n! The mean is computed by straightforward summation.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, the number of items.\n! 1 <= A.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n real ( kind = 8 ) mean\n real ( kind = 8 ) pdf\n integer ( kind = 4 ) x\n\n mean = 0.0D+00\n do x = 1, a\n call deranged_pdf ( x, a, pdf )\n mean = mean + pdf * x\n end do\n\n return\nend\nsubroutine deranged_pdf ( x, a, pdf )\n\n!*****************************************************************************80\n!\n!! DERANGED_PDF evaluates the Deranged PDF.\n!\n! Discussion:\n!\n! PDF(A;X) is the probability that exactly X items will occur in\n! their proper place after a random permutation of A items.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 06 March 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X, the number of items in their\n! correct places. 0 <= X <= A.\n!\n! Input, integer ( kind = 4 ) A, the total number of items.\n! 1 <= A.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n integer ( kind = 4 ) cnk\n integer ( kind = 4 ) deranged_enum\n integer ( kind = 4 ) dnmk\n real ( kind = 8 ) i4_factorial\n real ( kind = 8 ) pdf\n integer ( kind = 4 ) x\n\n if ( x < 0 .or. a < x ) then\n pdf = 0.0D+00\n else\n call binomial_coef ( a, x, cnk )\n dnmk = deranged_enum ( a-x )\n pdf = real ( cnk * dnmk, kind = 8 ) / i4_factorial ( a )\n end if\n\n return\nend\nsubroutine deranged_sample ( a, seed, x )\n\n!*****************************************************************************80\n!\n!! DERANGED_SAMPLE samples the Deranged PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 06 March 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, the number of items.\n! 1 <= A.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random\n! number generator.\n!\n! Output, integer ( kind = 4 ) X, a sample of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n integer ( kind = 4 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call deranged_cdf_inv ( cdf, a, x )\n\n return\nend\nsubroutine deranged_variance ( a, variance )\n\n!*****************************************************************************80\n!\n!! DERANGED_VARIANCE returns the variance of the Deranged CDF.\n!\n! Discussion:\n!\n! The variance is computed by straightforward summation.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 06 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, the number of items.\n! 1 <= A.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n real ( kind = 8 ) mean\n real ( kind = 8 ) pdf\n integer ( kind = 4 ) x\n real ( kind = 8 ) variance\n\n call deranged_mean ( a, mean )\n\n variance = 0.0D+00\n do x = 1, a\n call deranged_pdf ( x, a, pdf )\n variance = variance + pdf * ( x - mean )**2\n end do\n\n return\nend\nfunction digamma ( x )\n\n!*****************************************************************************80\n!\n!! DIGAMMA calculates the digamma or Psi function.\n!\n! Discussion:\n!\n! DiGamma ( X ) = d ( log ( Gamma ( X ) ) ) / dX\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 03 January 2000\n!\n! Author:\n!\n! Original FORTRAN77 version by Jose Bernardo.\n! FORTRAN90 version by John Burkardt.\n!\n! Reference:\n!\n! Jose Bernardo,\n! Algorithm AS 103:\n! Psi ( Digamma ) Function,\n! Applied Statistics,\n! Volume 25, Number 3, pages 315-317, 1976.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the digamma function.\n! 0 < X.\n!\n! Output, real ( kind = 8 ) DIGAMMA, the value of the digamma function at X.\n!\n implicit none\n\n real ( kind = 8 ), parameter :: c = 8.5D+00\n real ( kind = 8 ), parameter :: d1 = -0.5772156649D+00\n real ( kind = 8 ) digamma\n real ( kind = 8 ) r\n real ( kind = 8 ), parameter :: s = 0.00001D+00\n real ( kind = 8 ), parameter :: s3 = 0.08333333333D+00\n real ( kind = 8 ), parameter :: s4 = 0.0083333333333D+00\n real ( kind = 8 ), parameter :: s5 = 0.003968253968D+00\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n!\n! The argument must be positive.\n!\n if ( x <= 0.0D+00 ) then\n\n digamma = 0.0D+00\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'DIGAMMA - Fatal error!'\n write ( *, '(a)' ) ' X <= 0.'\n stop 1\n!\n! Use approximation if argument <= S.\n!\n else if ( x <= s ) then\n\n digamma = d1 - 1.0D+00 / x\n!\n! Reduce the argument to DIGAMMA(X + N) where C <= (X + N).\n!\n else\n\n digamma = 0.0D+00\n y = x\n\n do while ( y < c )\n digamma = digamma - 1.0D+00 / y\n y = y + 1.0D+00\n end do\n!\n! Use Stirling's (actually de Moivre's) expansion if C < argument.\n!\n r = 1.0D+00 / ( y * y )\n digamma = digamma + log ( y ) - 0.5D+00 / y &\n - r * ( s3 - r * ( s4 - r * s5 ) )\n\n end if\n\n return\nend\nsubroutine dipole_cdf ( x, a, b, cdf )\n\n!*****************************************************************************80\n!\n!! DIPOLE_CDF evaluates the Dipole CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! A is arbitrary, but represents an angle, so only 0 <= A <= 2 * PI\n! is interesting, and -1.0D+00 <= B <= 1.0.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) x\n\n cdf = 0.5D+00 + ( 1.0D+00 / pi ) * atan ( x ) &\n + b * b * ( x * cos ( 2.0D+00 * a ) &\n - sin ( 2.0D+00 * a ) ) / ( pi * ( 1.0D+00 + x * x ) )\n\n return\nend\nsubroutine dipole_cdf_inv ( cdf, a, b, x )\n\n!*****************************************************************************80\n!\n!! DIPOLE_CDF_INV inverts the Dipole CDF.\n!\n! Discussion:\n!\n! A simple bisection method is used.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 04 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! -1.0D+00 <= B <= 1.0.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) cdf1\n real ( kind = 8 ) cdf2\n real ( kind = 8 ) cdf3\n integer ( kind = 4 ) it\n integer ( kind = 4 ), parameter :: it_max = 100\n real ( kind = 8 ), parameter :: tol = 0.0001D+00\n real ( kind = 8 ) x\n real ( kind = 8 ) x1\n real ( kind = 8 ) x2\n real ( kind = 8 ) x3\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'DIPOLE_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n if ( cdf == 0.0D+00 ) then\n x = - huge ( x )\n return\n else if ( 1.0D+00 == cdf ) then\n x = huge ( x )\n return\n end if\n!\n! Seek X1 < X < X2.\n!\n x1 = - 1.0D+00\n\n do\n\n call dipole_cdf ( x1, a, b, cdf1 )\n\n if ( cdf1 <= cdf ) then\n exit\n end if\n\n x1 = 2.0D+00 * x1\n\n end do\n\n x2 = 1.0D+00\n\n do\n\n call dipole_cdf ( x2, a, b, cdf2 )\n\n if ( cdf <= cdf2 ) then\n exit\n end if\n\n x2 = 2.0D+00 * x2\n\n end do\n!\n! Now use bisection.\n!\n it = 0\n\n do\n\n it = it + 1\n\n x3 = 0.5D+00 * ( x1 + x2 )\n call dipole_cdf ( x3, a, b, cdf3 )\n\n if ( abs ( cdf3 - cdf ) < tol ) then\n x = x3\n exit\n end if\n\n if ( it_max < it ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'DIPOLE_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' Iteration limit exceeded.'\n stop 1\n end if\n\n if ( sign ( 1.0D+00, cdf3 - cdf ) == sign ( 1.0D+00, cdf1 - cdf ) ) then\n x1 = x3\n cdf1 = cdf3\n else\n x2 = x3\n cdf2 = cdf3\n end if\n\n end do\n\n return\nend\nfunction dipole_check ( a, b )\n\n!*****************************************************************************80\n!\n!! DIPOLE_CHECK checks the parameters of the Dipole CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! A is arbitrary, but represents an angle, so only 0 <= A <= 2 * PI\n! is interesting, and -1.0D+00 <= B <= 1.0.\n!\n! Output, logical DIPOLE_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n logical dipole_check\n\n if ( b < -1.0D+00 .or. 1.0D+00 < b ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'DIPOLE_CHECK - Fatal error!'\n write ( *, '(a)' ) ' -1.0D+00 <= B <= 1.0D+00 is required.'\n write ( *, '(a,g14.6)' ) ' The input B = ', b\n dipole_check = .false.\n return\n end if\n\n dipole_check = .true.\n\n return\nend\nsubroutine dipole_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! DIPOLE_PDF evaluates the Dipole PDF.\n!\n! Discussion:\n!\n! PDF(A,B;X) =\n! 1 / ( PI * ( 1 + X^2 ) )\n! + B^2 * ( ( 1 - X^2 ) * cos ( 2 * A ) + 2 * X * sin ( 2 * A ) )\n! / ( PI * ( 1 + X^2 )^2 )\n!\n! Densities of this kind commonly occur in the analysis of resonant\n! scattering of elementary particles.\n!\n! DIPOLE_PDF(A,0;X) = CAUCHY_PDF(A;X)\n!\n! A = 0, B = 1 yields the single channel dipole distribution.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Robert Knop,\n! Algorithm 441,\n! Random Deviates from the Dipole Distribution,\n! ACM Transactions on Mathematical Software,\n! Volume 16, Number 1, 1973, page 51.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! A is arbitrary, but represents an angle, so only 0 <= A <= 2 * PI\n! is interesting,\n! and -1.0D+00 <= B <= 1.0.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) pdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) x\n\n pdf = 1.0D+00 / ( pi * ( 1.0D+00 + x * x ) ) &\n + b * b * ( ( 1.0D+00 - x * x ) * cos ( 2.0D+00 * a ) &\n + 2.0D+00 * x * sin ( 2.0D+00 * x ) ) / ( pi * ( 1.0D+00 + x * x )**2 )\n\n return\nend\nsubroutine dipole_sample ( a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! DIPOLE_SAMPLE samples the Dipole PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 04 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Robert Knop,\n! Algorithm 441,\n! Random Deviates from the Dipole Distribution,\n! ACM Transactions on Mathematical Software,\n! Volume 16, Number 1, 1973, page 51.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! A is arbitrary, but represents an angle, so only 0 <= A <= 2 * PI\n! is interesting,\n! and -1.0D+00 <= B <= 1.0D+00.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random\n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) a2\n real ( kind = 8 ) b\n real ( kind = 8 ) b2\n real ( kind = 8 ) c2\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n real ( kind = 8 ) x1\n real ( kind = 8 ) x2\n!\n! Find (X1,X2) at random in a circle.\n!\n a2 = b * sin ( a )\n b2 = b * cos ( a )\n c2 = 1.0D+00\n\n call circle_sample ( a2, b2, c2, seed, x1, x2 )\n!\n! The dipole variate is the ratio X1 / X2.\n!\n x = x1 / x2\n\n return\nend\nfunction dirichlet_check ( n, a )\n\n!*****************************************************************************80\n!\n!! DIRICHLET_CHECK checks the parameters of the Dirichlet PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of components.\n!\n! Input, real ( kind = 8 ) A(N), the probabilities for each component.\n! Each A(I) should be positive.\n!\n! Output, logical DIRICHLET_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(n)\n logical dirichlet_check\n integer ( kind = 4 ) i\n logical positive\n\n positive = .false.\n\n do i = 1, n\n\n if ( a(i) <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'DIRICHLET_CHECK - Fatal error!'\n write ( *, '(a)' ) ' A(I) <= 0.'\n write ( *, '(a,i8)' ) ' For I = ', i\n write ( *, '(a,g14.6)' ) ' A(I) = ', a(i)\n dirichlet_check = .false.\n return\n else if ( 0.0D+00 < a(i) ) then\n positive = .true.\n end if\n\n end do\n\n if ( .not. positive ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'DIRICHLET_CHECK - Fatal error!'\n write ( *, '(a)' ) ' All parameters are zero!'\n dirichlet_check = .false.\n return\n end if\n\n dirichlet_check = .true.\n\n return\nend\nsubroutine dirichlet_mean ( n, a, mean )\n\n!*****************************************************************************80\n!\n!! DIRICHLET_MEAN returns the means of the Dirichlet PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 23 November 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of components.\n!\n! Input, real ( kind = 8 ) A(N), the probabilities for each component.\n! Each A(I) should be positive.\n!\n! Output, real ( kind = 8 ) MEAN(N), the means of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(n)\n real ( kind = 8 ) mean(n)\n\n mean(1:n) = a(1:n)\n\n call r8vec_unit_sum ( n, mean )\n\n return\nend\nfunction dirichlet_mix_check ( comp_num, elem_num, a, comp_weight )\n\n!*****************************************************************************80\n!\n!! DIRICHLET_MIX_CHECK checks the parameters of a Dirichlet mixture PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) COMP_NUM, the number of components in the\n! Dirichlet\n! mixture density, that is, the number of distinct Dirichlet PDF's\n! that are mixed together.\n!\n! Input, integer ( kind = 4 ) ELEM_NUM, the number of elements of an\n! observation.\n!\n! Input, real ( kind = 8 ) A(ELEM_NUM,COMP_NUM), the probabilities\n! for element ELEM_NUM in component COMP_NUM.\n! Each A(I,J) should be positive.\n!\n! Input, real ( kind = 8 ) COMP_WEIGHT(COMP_NUM), the mixture weights of\n! the densities. These do not need to be normalized. The weight of a\n! given component is the relative probability that that component will\n! be used to generate the sample.\n!\n! Output, logical DIRICHLET_MIX_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n integer ( kind = 4 ) comp_num\n integer ( kind = 4 ) elem_num\n\n real ( kind = 8 ) a(elem_num,comp_num)\n integer ( kind = 4 ) comp_i\n real ( kind = 8 ) comp_weight(comp_num)\n logical dirichlet_mix_check\n integer ( kind = 4 ) elem_i\n logical positive\n\n do comp_i = 1, comp_num\n\n do elem_i = 1, elem_num\n if ( a(elem_i,comp_i) <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'DIRICHLET_MIX_CHECK - Fatal error!'\n write ( *, '(a)' ) ' A(ELEM,COMP) <= 0.'\n write ( *, '(a,i8)' ) ' COMP = ', comp_i\n write ( *, '(a,i8)' ) ' ELEM = ', elem_i\n write ( *, '(a,g14.6)' ) ' A(COMP,ELEM) = ', a(elem_i,comp_i)\n dirichlet_mix_check = .false.\n return\n end if\n end do\n\n end do\n\n positive = .false.\n\n do comp_i = 1, comp_num\n\n if ( comp_weight(comp_i) < 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'DIRICHLET_MIX_CHECK - Fatal error!'\n write ( *, '(a)' ) ' COMP_WEIGHT(COMP) < 0.'\n write ( *, '(a,i8)' ) ' COMP = ', comp_i\n write ( *, '(a,g14.6)' ) ' COMP_WEIGHT(COMP) = ', comp_weight(comp_i)\n dirichlet_mix_check = .false.\n return\n else if ( 0.0D+00 < comp_weight(comp_i) ) then\n positive = .true.\n end if\n\n end do\n\n if ( .not. positive ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'DIRICHLET_MIX_CHECK - Fatal error!'\n write ( *, '(a)' ) ' All component weights are zero.'\n dirichlet_mix_check = .false.\n return\n end if\n\n dirichlet_mix_check = .true.\n\n return\nend\nsubroutine dirichlet_mix_mean ( comp_num, elem_num, a, comp_weight, &\n mean )\n\n!*****************************************************************************80\n!\n!! DIRICHLET_MIX_MEAN returns the means of a Dirichlet mixture PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 08 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) COMP_NUM, the number of components in the\n! Dirichlet mixture density, that is, the number of distinct Dirichlet PDF's\n! that are mixed together.\n!\n! Input, integer ( kind = 4 ) ELEM_NUM, the number of elements of an\n! observation.\n!\n! Input, real ( kind = 8 ) A(ELEM_NUM,COMP_NUM), the probabilities for\n! element ELEM_NUM in component COMP_NUM.\n! Each A(I,J) should be positive.\n!\n! Input, real ( kind = 8 ) COMP_WEIGHT(COMP_NUM), the mixture weights of\n! the densities. These do not need to be normalized. The weight of a\n! given component is the relative probability that that component will\n! be used to generate the sample.\n!\n! Output, real ( kind = 8 ) MEAN(ELEM_NUM), the means for each element.\n!\n implicit none\n\n integer ( kind = 4 ) comp_num\n integer ( kind = 4 ) elem_num\n\n real ( kind = 8 ) a(elem_num,comp_num)\n integer ( kind = 4 ) comp_i\n real ( kind = 8 ) comp_mean(elem_num)\n real ( kind = 8 ) comp_weight(comp_num)\n real ( kind = 8 ) comp_weight_sum\n real ( kind = 8 ) mean(elem_num)\n\n comp_weight_sum = sum ( comp_weight )\n\n mean(1:elem_num) = 0.0D+00\n\n do comp_i = 1, comp_num\n call dirichlet_mean ( elem_num, a(1,comp_i), comp_mean )\n mean(1:elem_num) = mean(1:elem_num) &\n + comp_weight(comp_i) * comp_mean(1:elem_num)\n end do\n\n mean(1:elem_num) = mean(1:elem_num) / comp_weight_sum\n\n return\nend\nsubroutine dirichlet_mix_pdf ( x, comp_num, elem_num, a, &\n comp_weight, pdf )\n\n!*****************************************************************************80\n!\n!! DIRICHLET_MIX_PDF evaluates a Dirichlet mixture PDF.\n!\n! Discussion:\n!\n! The PDF is a weighted sum of Dirichlet PDF's. Each PDF is a\n! \"component\", with an associated weight.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 08 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X(ELEM_NUM), the argument of the PDF.\n!\n! Input, integer ( kind = 4 ) COMP_NUM, the number of components in the\n! Dirichlet mixture density, that is, the number of distinct Dirichlet PDF's\n! that are mixed together.\n!\n! Input, integer ( kind = 4 ) ELEM_NUM, the number of elements of an\n! observation.\n!\n! Input, real ( kind = 8 ) A(ELEM_NUM,COMP_NUM), the probabilities for\n! element ELEM_NUM in component COMP_NUM.\n! Each A(I,J) should be positive.\n!\n! Input, real ( kind = 8 ) COMP_WEIGHT(COMP_NUM), the mixture weights of\n! the densities. These do not need to be normalized. The weight of a\n! given component is the relative probability that that component will\n! be used to generate the sample.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) comp_num\n integer ( kind = 4 ) elem_num\n\n real ( kind = 8 ) a(elem_num,comp_num)\n integer ( kind = 4 ) comp_i\n real ( kind = 8 ) comp_pdf\n real ( kind = 8 ) comp_weight(comp_num)\n real ( kind = 8 ) comp_weight_sum\n real ( kind = 8 ) pdf\n real ( kind = 8 ) x(elem_num)\n\n comp_weight_sum = sum ( comp_weight )\n\n pdf = 0.0D+00\n do comp_i = 1, comp_num\n\n call dirichlet_pdf ( x, elem_num, a(1,comp_i), comp_pdf )\n\n pdf = pdf + comp_weight(comp_i) * comp_pdf / comp_weight_sum\n\n end do\n\n return\nend\nsubroutine dirichlet_mix_sample ( comp_num, elem_num, a, &\n comp_weight, seed, comp, x )\n\n!*****************************************************************************80\n!\n!! DIRICHLET_MIX_SAMPLE samples a Dirichlet mixture PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 08 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) COMP_NUM, the number of components in the \n! Dirichlet mixture density, that is, the number of distinct Dirichlet PDF's\n! that are mixed together.\n!\n! Input, integer ( kind = 4 ) ELEM_NUM, the number of elements of \n! an observation.\n!\n! Input, real ( kind = 8 ) A(ELEM_NUM,COMP_NUM), the probabilities for\n! element ELEM_NUM in component COMP_NUM.\n! Each A(I,J) should be positive.\n!\n! Input, real ( kind = 8 ) COMP_WEIGHT(COMP_NUM), the mixture weights of\n! the densities. These do not need to be normalized. The weight of a\n! given component is the relative probability that that component will\n! be used to generate the sample.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, integer ( kind = 4 ) COMP, the index of the component of the \n! Dirichlet mixture that was chosen to generate the sample.\n!\n! Output, real ( kind = 8 ) X(ELEM_NUM), a sample of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) comp_num\n integer ( kind = 4 ) elem_num\n\n real ( kind = 8 ) a(elem_num,comp_num)\n integer ( kind = 4 ) comp\n real ( kind = 8 ) comp_weight(comp_num)\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x(elem_num)\n!\n! Choose a particular density component COMP.\n!\n call discrete_sample ( comp_num, comp_weight, seed, comp )\n!\n! Sample the density number COMP.\n!\n call dirichlet_sample ( elem_num, a(1,comp), seed, x )\n\n return\nend\nsubroutine dirichlet_moment2 ( n, a, m2 )\n\n!*****************************************************************************80\n!\n!! DIRICHLET_MOMENT2 returns the second moments of the Dirichlet PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 23 November 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of components.\n!\n! Input, real ( kind = 8 ) A(N), the probabilities for each component.\n! Each A(I) should be positive.\n!\n! Output, real ( kind = 8 ) M2(N,N), the second moments of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(n)\n real ( kind = 8 ) a_sum\n real ( kind = 8 ) m2(n,n)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) j\n\n a_sum = sum ( a(1:n) )\n\n do i = 1, n\n do j = 1, n\n if ( i == j ) then\n m2(i,j) = a(i) * ( a(i) + 1.0D+00 ) / ( a_sum * ( a_sum + 1.0D+00 ) )\n else\n m2(i,j) = a(i) * a(j) / ( a_sum * ( a_sum + 1.0D+00 ) )\n end if\n end do\n end do\n\n return\nend\nsubroutine dirichlet_multinomial_pdf ( x, a, b, c, pdf )\n\n!*****************************************************************************80\n!\n!! DIRICHLET_MULTINOMIAL_PDF evaluates a Dirichlet Multinomial PDF.\n!\n! Discussion:\n!\n! PDF(A,B,C;X) = Comb(A,B,X) * ( Gamma(C_Sum) / Gamma(C_Sum+A) )\n! Product ( 1 <= I <= B ) Gamma(C(I)+X(I)) / Gamma(C(I))\n!\n! where:\n!\n! Comb(A,B,X) is the multinomial coefficient C( A; X(1), X(2), ..., X(B) ),\n! C_Sum = Sum ( 1 <= I <= B ) C(I)\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 17 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Kenneth Lange,\n! Mathematical and Statistical Methods for Genetic Analysis,\n! Springer, 1997, page 45.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X(B); X(I) counts the number of occurrences of\n! outcome I, out of the total of A trials.\n!\n! Input, integer ( kind = 4 ) A, the total number of trials.\n!\n! Input, integer ( kind = 4 ) B, the number of different possible outcomes on\n! one trial.\n!\n! Input, real ( kind = 8 ) C(B); C(I) is the Dirichlet parameter associated\n! with outcome I.\n!\n! Output, real ( kind = 8 ) PDF, the value of the Dirichlet multinomial PDF.\n!\n implicit none\n\n integer ( kind = 4 ) b\n\n integer ( kind = 4 ) a\n real ( kind = 8 ) c(b)\n real ( kind = 8 ) c_sum\n real ( kind = 8 ) gamma_log\n integer ( kind = 4 ) i\n real ( kind = 8 ) pdf\n real ( kind = 8 ) pdf_log\n integer ( kind = 4 ) x(b)\n\n c_sum = sum ( c(1:b) )\n\n pdf_log = - gamma_log ( c_sum + real ( a, kind = 8 ) ) + gamma_log ( c_sum ) &\n + gamma_log ( real ( a + 1, kind = 8 ) )\n\n do i = 1, b\n pdf_log = pdf_log + gamma_log ( c(i) + real ( x(i), kind = 8 ) ) &\n - gamma_log ( c(i) ) - gamma_log ( real ( x(i) + 1, kind = 8 ) )\n end do\n\n pdf = exp ( pdf_log )\n\n return\nend\nsubroutine dirichlet_pdf ( x, n, a, pdf )\n\n!*****************************************************************************80\n!\n!! DIRICHLET_PDF evaluates the Dirichlet PDF.\n!\n! Discussion:\n!\n! PDF(N,A;X) = Product ( 1 <= I <= N ) X(I)^( A(I) - 1 )\n! * Gamma ( A_SUM ) / A_PROD\n!\n! where\n!\n! 0 <= A(I) for all I;\n! 0 <= X(I) for all I;\n! Sum ( 1 <= I <= N ) X(I) = 1;\n! A_SUM = Sum ( 1 <= I <= N ) A(I).\n! A_PROD = Product ( 1 <= I <= N ) Gamma ( A(I) )\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 06 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X(N), the argument of the PDF. Each X(I) should\n! be greater than 0.0D+00, and the X(I)'s must add up to 1.0.\n!\n! Input, integer ( kind = 4 ) N, the number of components.\n!\n! Input, real ( kind = 8 ) A(N), the probabilities for each component.\n! Each A(I) should be nonnegative, and at least one should be\n! positive.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(n)\n real ( kind = 8 ) a_prod\n real ( kind = 8 ) a_sum\n integer ( kind = 4 ) i\n real ( kind = 8 ) pdf\n real ( kind = 8 ) r8_gamma\n real ( kind = 8 ), parameter :: tol = 0.0001D+00\n real ( kind = 8 ) x(n)\n real ( kind = 8 ) x_sum\n\n do i = 1, n\n if ( x(i) <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'DIRICHLET_PDF - Fatal error!'\n write ( *, '(a)' ) ' X(I) <= 0.'\n end if\n end do\n\n x_sum = sum ( x(1:n) )\n\n if ( tol < abs ( x_sum - 1.0D+00 ) ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'DIRICHLET_PDF - Fatal error!'\n write ( *, '(a)' ) ' SUM X(I) =/= 1.'\n end if\n\n a_sum = sum ( a(1:n) )\n\n a_prod = 1.0D+00\n do i = 1, n\n a_prod = a_prod * r8_gamma ( a(i) )\n end do\n\n pdf = r8_gamma ( a_sum ) / a_prod\n do i = 1, n\n pdf = pdf * x(i)**( a(i) - 1.0D+00 )\n end do\n\n return\nend\nsubroutine dirichlet_sample ( n, a, seed, x )\n\n!*****************************************************************************80\n!\n!! DIRICHLET_SAMPLE samples the Dirichlet PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 23 November 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Jerry Banks, editor,\n! Handbook of Simulation,\n! Engineering and Management Press Books, 1998, page 169.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of components.\n!\n! Input, real ( kind = 8 ) A(N), the probabilities for each component.\n! Each A(I) should be nonnegative, and at least one should be\n! positive.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X(N), a sample of the PDF. The entries\n! of X should sum to 1.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(n)\n real ( kind = 8 ) a2\n real ( kind = 8 ) b2\n real ( kind = 8 ) c2\n integer ( kind = 4 ) i\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x(n)\n\n a2 = 0.0D+00\n b2 = 1.0D+00\n\n do i = 1, n\n c2 = a(i)\n call gamma_sample ( a2, b2, c2, seed, x(i) )\n end do\n!\n! Rescale the vector to have unit sum.\n!\n call r8vec_unit_sum ( n, x )\n\n return\nend\nsubroutine dirichlet_variance ( n, a, variance )\n\n!*****************************************************************************80\n!\n!! DIRICHLET_VARIANCE returns the variances of the Dirichlet PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 03 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of components.\n!\n! Input, real ( kind = 8 ) A(N), the probabilities for each component.\n! Each A(I) should be nonnegative, and at least one should be positive.\n!\n! Output, real ( kind = 8 ) VARIANCE(N), the variances of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(n)\n real ( kind = 8 ) a_sum\n integer ( kind = 4 ) i\n real ( kind = 8 ) variance(n)\n\n a_sum = sum ( a(1:n) )\n\n do i = 1, n\n variance(i) = a(i) * ( a_sum - a(i) ) / ( a_sum**2 * ( a_sum + 1.0D+00 ) )\n end do\n\n return\nend\nsubroutine discrete_cdf ( x, a, b, cdf )\n\n!*****************************************************************************80\n!\n!! DISCRETE_CDF evaluates the Discrete CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X, the item whose probability is desired.\n!\n! Input, integer ( kind = 4 ) A, the number of probabilities assigned.\n!\n! Input, real ( kind = 8 ) B(A), the relative probabilities of outcomes\n! 1 through A. Each entry must be nonnegative.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n\n real ( kind = 8 ) b(a)\n real ( kind = 8 ) cdf\n integer ( kind = 4 ) x\n\n if ( x < 1 ) then\n cdf = 0.0D+00\n else if ( x < a ) then\n cdf = sum ( b(1:x) ) / sum ( b(1:a) )\n else if ( a <= x ) then\n cdf = 1.0D+00\n end if\n\n return\nend\nsubroutine discrete_cdf_inv ( cdf, a, b, x )\n\n!*****************************************************************************80\n!\n!! DISCRETE_CDF_INV inverts the Discrete CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Input, integer ( kind = 4 ) A, the number of probabilities assigned.\n!\n! Input, real ( kind = 8 ) B(A), the relative probabilities of outcomes\n! 1 through A. Each entry must be nonnegative.\n!\n! Output, integer ( kind = 4 ) X, the corresponding argument for which\n! CDF(X-1) < CDF <= CDF(X)\n!\n implicit none\n\n integer ( kind = 4 ) a\n\n real ( kind = 8 ) b(a)\n real ( kind = 8 ) b_sum\n real ( kind = 8 ) cdf\n real ( kind = 8 ) cum\n integer ( kind = 4 ) j\n integer ( kind = 4 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'DISCRETE_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n b_sum = sum ( b(1:a) )\n\n cum = 0.0D+00\n\n do j = 1, a\n\n cum = cum + b(j) / b_sum\n\n if ( cdf <= cum ) then\n x = j\n return\n end if\n\n end do\n\n x = a\n\n return\nend\nfunction discrete_check ( a, b )\n\n!*****************************************************************************80\n!\n!! DISCRETE_CHECK checks the parameters of the Discrete CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, the number of probabilities assigned.\n!\n! Input, real ( kind = 8 ) B(A), the relative probabilities of\n! outcomes 1 through A. Each entry must be nonnegative.\n!\n! Output, logical DISCRETE_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n integer ( kind = 4 ) a\n\n real ( kind = 8 ) b(a)\n real ( kind = 8 ) b_sum\n logical discrete_check\n integer ( kind = 4 ) j\n\n do j = 1, a\n if ( b(j) < 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'DISCRETE_CHECK - Fatal error!'\n write ( *, '(a)' ) ' Negative probabilities not allowed.'\n discrete_check = .false.\n return\n end if\n end do\n\n b_sum = sum ( b(1:a) )\n\n if ( b_sum == 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'DISCRETE_CHECK - Fatal error!'\n write ( *, '(a)' ) ' Total probablity is zero.'\n discrete_check = .false.\n return\n end if\n\n discrete_check = .true.\n\n return\nend\nsubroutine discrete_mean ( a, b, mean )\n\n!*****************************************************************************80\n!\n!! DISCRETE_MEAN evaluates the mean of the Discrete PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, the number of probabilities assigned.\n!\n! Input, real ( kind = 8 ) B(A), the relative probabilities of\n! outcomes 1 through A. Each entry must be nonnegative.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n\n real ( kind = 8 ) b(a)\n real ( kind = 8 ) b_sum\n integer ( kind = 4 ) j\n real ( kind = 8 ) mean\n\n b_sum = sum ( b(1:a) )\n\n mean = 0.0D+00\n do j = 1, a\n mean = mean + real ( j, kind = 8 ) * b(j)\n end do\n\n mean = mean / b_sum\n\n return\nend\nsubroutine discrete_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! DISCRETE_PDF evaluates the Discrete PDF.\n!\n! Discussion:\n!\n! PDF(A,B;X) = B(X) if 1 <= X <= A\n! = 0 otherwise\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X, the item whose probability is desired.\n!\n! Input, integer ( kind = 4 ) A, the number of probabilities assigned.\n!\n! Input, real ( kind = 8 ) B(A), the relative probabilities of\n! outcomes 1 through A. Each entry must be nonnegative.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n\n real ( kind = 8 ) b(a)\n real ( kind = 8 ) b_sum\n real ( kind = 8 ) pdf\n integer ( kind = 4 ) x\n\n b_sum = sum ( b(1:a) )\n\n if ( 1 <= x .and. x <= a ) then\n pdf = b(x) / b_sum\n else\n pdf = 0.0D+00\n end if\n\n return\nend\nsubroutine discrete_sample ( a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! DISCRETE_SAMPLE samples the Discrete PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, the number of probabilities assigned.\n!\n! Input, real ( kind = 8 ) B(A), the relative probabilities of\n! outcomes 1 through A. Each entry must be nonnegative.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, integer ( kind = 4 ) X, a sample of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n\n real ( kind = 8 ) b(a)\n real ( kind = 8 ) b_sum\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n integer ( kind = 4 ) x\n\n b_sum = sum ( b(1:a) )\n\n cdf = r8_uniform_01 ( seed )\n\n call discrete_cdf_inv ( cdf, a, b, x )\n\n return\nend\nsubroutine discrete_variance ( a, b, variance )\n\n!*****************************************************************************80\n!\n!! DISCRETE_VARIANCE evaluates the variance of the Discrete PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, the number of probabilities assigned.\n!\n! Input, real ( kind = 8 ) B(A), the relative probabilities of\n! outcomes 1 through A. Each entry must be nonnegative.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n\n real ( kind = 8 ) b(a)\n real ( kind = 8 ) b_sum\n integer ( kind = 4 ) j\n real ( kind = 8 ) mean\n real ( kind = 8 ) variance\n\n b_sum = sum ( b(1:a) )\n\n mean = 0.0D+00\n do j = 1, a\n mean = mean + real ( j, kind = 8 ) * b(j)\n end do\n\n mean = mean / b_sum\n\n variance = 0.0D+00\n do j = 1, a\n variance = variance + b(j) * ( j - mean )**2\n end do\n\n variance = variance / b_sum\n\n return\nend\nfunction e_constant ( )\n\n!*****************************************************************************80\n!\n!! E_CONSTANT returns the value of E.\n!\n! Discussion:\n!\n! \"E\" was named in honor of Euler.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 January 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Output, real ( kind = 8 ) E_CONSTANT, the base of the natural\n! logarithm system.\n!\n implicit none\n\n real ( kind = 8 ) e_constant\n\n e_constant = 2.71828182845904523536028747135266249775724709369995D+00\n\n return\nend\nsubroutine empirical_discrete_cdf ( x, a, b, c, cdf )\n\n!*****************************************************************************80\n!\n!! EMPIRICAL_DISCRETE_CDF evaluates the Empirical Discrete CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 June 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n!\n! Input, integer ( kind = 4 ) A, the number of values.\n! 0 < A.\n!\n! Input, real ( kind = 8 ) B(A), the weights of each value.\n! 0 <= B(1:A) and at least one value is nonzero.\n!\n! Input, real ( kind = 8 ) C(A), the values.\n! The values must be distinct and in ascending order.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n\n real ( kind = 8 ) b(a)\n real ( kind = 8 ) bsum\n real ( kind = 8 ) c(a)\n real ( kind = 8 ) cdf\n integer ( kind = 4 ) i\n real ( kind = 8 ) x\n\n cdf = 0.0D+00\n\n bsum = sum ( b(1:a) )\n\n do i = 1, a\n\n if ( x < c(i) ) then\n return\n end if\n\n cdf = cdf + b(i) / bsum\n\n end do\n\n return\nend\nsubroutine empirical_discrete_cdf_inv ( cdf, a, b, c, x )\n\n!*****************************************************************************80\n!\n!! EMPIRICAL_DISCRETE_CDF_INV inverts the Empirical Discrete CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 June 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Input, integer ( kind = 4 ) A, the number of values.\n! 0 < A.\n!\n! Input, real ( kind = 8 ) B(A), the weights of each value.\n! 0 <= B(1:A) and at least one value is nonzero.\n!\n! Input, real ( kind = 8 ) C(A), the values.\n! The values must be distinct and in ascending order.\n!\n! Output, real ( kind = 8 ) X, the smallest argument whose CDF is greater\n! than or equal to CDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n\n real ( kind = 8 ) b(a)\n real ( kind = 8 ) bsum\n real ( kind = 8 ) c(a)\n real ( kind = 8 ) cdf\n real ( kind = 8 ) cdf2\n integer ( kind = 4 ) i\n real ( kind = 8 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'EMPIRICAL_DISCRETE_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n bsum = sum ( b(1:a) )\n\n x = c(1)\n cdf2 = b(1) / bsum\n\n do i = 2, a\n\n if ( cdf <= cdf2 ) then\n return\n end if\n\n x = c(i)\n cdf2 = cdf2 + b(i) / bsum\n\n end do\n\n return\nend\nfunction empirical_discrete_check ( a, b, c )\n\n!*****************************************************************************80\n!\n!! EMPIRICAL_DISCRETE_CHECK checks the parameters of the Empirical Discrete CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, the number of values.\n! 0 < A.\n!\n! Input, real ( kind = 8 ) B(A), the weights of each value.\n! 0 <= B(1:A) and at least one value is nonzero.\n!\n! Input, real ( kind = 8 ) C(A), the values.\n! The values must be distinct and in ascending order.\n!\n! Output, logical EMPIRICAL_DISCRETE_CHECK, is true if the parameters\n! are legal.\n!\n implicit none\n\n integer ( kind = 4 ) a\n\n real ( kind = 8 ) b(a)\n real ( kind = 8 ) c(a)\n logical empirical_discrete_check\n integer ( kind = 4 ) i\n integer ( kind = 4 ) j\n\n if ( a <= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'EMPIRICAL_DISCRETE_CHECK - Fatal error!'\n write ( *, '(a)' ) ' A must be positive.'\n write ( *, '(a,i12)' ) ' Input A = ', a\n write ( *, '(a)' ) ' A is the number of weights.'\n empirical_discrete_check = .false.\n return\n end if\n\n if ( any ( b(1:a) < 0.0D+00 ) ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'EMPIRICAL_DISCRETE_CHECK - Fatal error!'\n write ( *, '(a)' ) ' Some B(*) < 0.'\n write ( *, '(a)' ) ' But all B values must be nonnegative.'\n empirical_discrete_check = .false.\n return\n end if\n\n if ( all ( b(1:a) == 0.0D+00 ) ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'EMPIRICAL_DISCRETE_CHECK - Fatal error!'\n write ( *, '(a)' ) ' All B(*) = 0.'\n write ( *, '(a)' ) ' But at least one B values must be nonzero.'\n empirical_discrete_check = .false.\n return\n end if\n\n do i = 1, a\n do j = i+1, a\n if ( c(i) == c(j) ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'EMPIRICAL_DISCRETE_CHECK - Fatal error!'\n write ( *, '(a)' ) ' All values C must be unique.'\n write ( *, '(a)' ) ' But at least two values are identical.'\n empirical_discrete_check = .false.\n return\n end if\n end do\n end do\n\n do i = 1, a-1\n if ( c(i+1) < c(i) ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'EMPIRICAL_DISCRETE_CHECK - Fatal error!'\n write ( *, '(a)' ) ' The values in C must be in ascending order.'\n empirical_discrete_check = .false.\n return\n end if\n end do\n\n empirical_discrete_check = .true.\n\n return\nend\nsubroutine empirical_discrete_mean ( a, b, c, mean )\n\n!*****************************************************************************80\n!\n!! EMPIRICAL_DISCRETE_MEAN returns the mean of the Empirical Discrete PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 June 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, the number of values.\n! 0 < A.\n!\n! Input, real ( kind = 8 ) B(A), the weights of each value.\n! 0 <= B(1:A) and at least one value is nonzero.\n!\n! Input, real ( kind = 8 ) C(A), the values.\n! The values must be distinct and in ascending order.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n\n real ( kind = 8 ) b(a)\n real ( kind = 8 ) c(a)\n real ( kind = 8 ) mean\n\n mean = dot_product ( b(1:a), c(1:a) ) / sum ( b(1:a) )\n\n return\nend\nsubroutine empirical_discrete_pdf ( x, a, b, c, pdf )\n\n!*****************************************************************************80\n!\n!! EMPIRICAL_DISCRETE_PDF evaluates the Empirical Discrete PDF.\n!\n! Discussion:\n!\n! A set of A values C(1:A) are assigned nonnegative weights B(1:A),\n! with at least one B nonzero. The probability of C(I) is the\n! value of B(I) divided by the sum of the weights.\n!\n! The C's must be distinct, and given in ascending order.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 June 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Input, integer ( kind = 4 ) A, the number of values.\n! 0 < A.\n!\n! Input, real ( kind = 8 ) B(A), the weights of each value.\n! 0 <= B(1:A) and at least one value is nonzero.\n!\n! Input, real ( kind = 8 ) C(A), the values.\n! The values must be distinct and in ascending order.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n\n real ( kind = 8 ) b(a)\n real ( kind = 8 ) c(a)\n integer ( kind = 4 ) i\n real ( kind = 8 ) pdf\n real ( kind = 8 ) x\n\n do i = 1, a\n if ( x == c(i) ) then\n pdf = b(i) / sum ( b(1:a) )\n return\n end if\n end do\n\n pdf = 0.0D+00\n\n return\nend\nsubroutine empirical_discrete_sample ( a, b, c, seed, x )\n\n!*****************************************************************************80\n!\n!! EMPIRICAL_DISCRETE_SAMPLE samples the Empirical Discrete PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 June 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, the number of values.\n! 0 < A.\n!\n! Input, real ( kind = 8 ) B(A), the weights of each value.\n! 0 <= B(1:A) and at least one value is nonzero.\n!\n! Input, real ( kind = 8 ) C(A), the values.\n! The values must be distinct and in ascending order.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n\n real ( kind = 8 ) b(a)\n real ( kind = 8 ) c(a)\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call empirical_discrete_cdf_inv ( cdf, a, b, c, x )\n\n return\nend\nsubroutine empirical_discrete_variance ( a, b, c, variance )\n\n!*****************************************************************************80\n!\n!! EMPIRICAL_DISCRETE_VARIANCE: variance of the Empirical Discrete PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 June 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, the number of values.\n! 0 < A.\n!\n! Input, real ( kind = 8 ) B(A), the weights of each value.\n! 0 <= B(1:A) and at least one value is nonzero.\n!\n! Input, real ( kind = 8 ) C(A), the values.\n! The values must be distinct and in ascending order.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n\n real ( kind = 8 ) b(a)\n real ( kind = 8 ) bsum\n real ( kind = 8 ) c(a)\n integer ( kind = 4 ) i\n real ( kind = 8 ) mean\n real ( kind = 8 ) variance\n\n bsum = sum ( b(1:a) )\n\n call empirical_discrete_mean ( a, b, c, mean )\n\n variance = 0.0D+00\n\n do i = 1, a\n variance = variance + ( b(i) / bsum ) * ( c(i) - mean )**2\n end do\n\n return\nend\nsubroutine english_sentence_length_cdf ( x, cdf )\n\n!*****************************************************************************80\n!\n!! ENGLISH_SENTENCE_LENGTH_CDF evaluates the English Sentence Length CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 31 July 2006\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Henry Kucera, Winthrop Francis,\n! Computational Analysis of Present-Day American English,\n! Brown University Press, 1967.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X, the sentence length whose CDF is desired.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: sentence_length_max = 79\n\n real ( kind = 8 ) cdf\n real ( kind = 8 ), dimension ( sentence_length_max ) :: pdf_vec = (/ &\n 0.00806D+00, &\n 0.01370D+00, &\n 0.01862D+00, &\n 0.02547D+00, &\n 0.03043D+00, &\n 0.03189D+00, &\n 0.03516D+00, &\n 0.03545D+00, &\n 0.03286D+00, &\n 0.03533D+00, &\n 0.03562D+00, &\n 0.03788D+00, &\n 0.03669D+00, &\n 0.03751D+00, &\n 0.03518D+00, &\n 0.03541D+00, &\n 0.03434D+00, &\n 0.03305D+00, &\n 0.03329D+00, &\n 0.03103D+00, &\n 0.02867D+00, &\n 0.02724D+00, &\n 0.02647D+00, &\n 0.02526D+00, &\n 0.02086D+00, &\n 0.02178D+00, &\n 0.02128D+00, &\n 0.01801D+00, &\n 0.01690D+00, &\n 0.01556D+00, &\n 0.01512D+00, &\n 0.01326D+00, &\n 0.01277D+00, &\n 0.01062D+00, &\n 0.01051D+00, &\n 0.00901D+00, &\n 0.00838D+00, &\n 0.00764D+00, &\n 0.00683D+00, &\n 0.00589D+00, &\n 0.00624D+00, &\n 0.00488D+00, &\n 0.00477D+00, &\n 0.00406D+00, &\n 0.00390D+00, &\n 0.00350D+00, &\n 0.00318D+00, &\n 0.00241D+00, &\n 0.00224D+00, &\n 0.00220D+00, &\n 0.00262D+00, &\n 0.00207D+00, &\n 0.00174D+00, &\n 0.00174D+00, &\n 0.00128D+00, &\n 0.00121D+00, &\n 0.00103D+00, &\n 0.00117D+00, &\n 0.00124D+00, &\n 0.00082D+00, &\n 0.00088D+00, &\n 0.00061D+00, &\n 0.00061D+00, &\n 0.00075D+00, &\n 0.00063D+00, &\n 0.00056D+00, &\n 0.00052D+00, &\n 0.00057D+00, &\n 0.00031D+00, &\n 0.00029D+00, &\n 0.00021D+00, &\n 0.00017D+00, &\n 0.00021D+00, &\n 0.00034D+00, &\n 0.00031D+00, &\n 0.00011D+00, &\n 0.00011D+00, &\n 0.00008D+00, &\n 0.00006D+00 /)\n real ( kind = 8 ), parameter :: pdf_sum = 0.99768D+00\n integer ( kind = 4 ) x\n\n if ( x < 1 ) then\n cdf = 0.0D+00\n else if ( x < sentence_length_max ) then\n cdf = sum ( pdf_vec(1:x) ) / pdf_sum\n else if ( sentence_length_max <= x ) then\n cdf = 1.0D+00\n end if\n\n return\nend\nsubroutine english_sentence_length_cdf_inv ( cdf, x )\n\n!*****************************************************************************80\n!\n!! ENGLISH_SENTENCE_LENGTH_CDF_INV inverts the English Sentence Length CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 31 July 2006\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Henry Kucera, Winthrop Francis,\n! Computational Analysis of Present-Day American English,\n! Brown University Press, 1967.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0 <= CDF <= 1.0.\n!\n! Output, integer ( kind = 4 ) X, the corresponding sentence length for which\n! CDF(X-1) < CDF <= CDF(X)\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: sentence_length_max = 79\n\n real ( kind = 8 ) cdf\n real ( kind = 8 ) cum\n integer ( kind = 4 ) j\n real ( kind = 8 ), dimension ( sentence_length_max ) :: pdf_vec = (/ &\n 0.00806D+00, &\n 0.01370D+00, &\n 0.01862D+00, &\n 0.02547D+00, &\n 0.03043D+00, &\n 0.03189D+00, &\n 0.03516D+00, &\n 0.03545D+00, &\n 0.03286D+00, &\n 0.03533D+00, &\n 0.03562D+00, &\n 0.03788D+00, &\n 0.03669D+00, &\n 0.03751D+00, &\n 0.03518D+00, &\n 0.03541D+00, &\n 0.03434D+00, &\n 0.03305D+00, &\n 0.03329D+00, &\n 0.03103D+00, &\n 0.02867D+00, &\n 0.02724D+00, &\n 0.02647D+00, &\n 0.02526D+00, &\n 0.02086D+00, &\n 0.02178D+00, &\n 0.02128D+00, &\n 0.01801D+00, &\n 0.01690D+00, &\n 0.01556D+00, &\n 0.01512D+00, &\n 0.01326D+00, &\n 0.01277D+00, &\n 0.01062D+00, &\n 0.01051D+00, &\n 0.00901D+00, &\n 0.00838D+00, &\n 0.00764D+00, &\n 0.00683D+00, &\n 0.00589D+00, &\n 0.00624D+00, &\n 0.00488D+00, &\n 0.00477D+00, &\n 0.00406D+00, &\n 0.00390D+00, &\n 0.00350D+00, &\n 0.00318D+00, &\n 0.00241D+00, &\n 0.00224D+00, &\n 0.00220D+00, &\n 0.00262D+00, &\n 0.00207D+00, &\n 0.00174D+00, &\n 0.00174D+00, &\n 0.00128D+00, &\n 0.00121D+00, &\n 0.00103D+00, &\n 0.00117D+00, &\n 0.00124D+00, &\n 0.00082D+00, &\n 0.00088D+00, &\n 0.00061D+00, &\n 0.00061D+00, &\n 0.00075D+00, &\n 0.00063D+00, &\n 0.00056D+00, &\n 0.00052D+00, &\n 0.00057D+00, &\n 0.00031D+00, &\n 0.00029D+00, &\n 0.00021D+00, &\n 0.00017D+00, &\n 0.00021D+00, &\n 0.00034D+00, &\n 0.00031D+00, &\n 0.00011D+00, &\n 0.00011D+00, &\n 0.00008D+00, &\n 0.00006D+00 /)\n real ( kind = 8 ), parameter :: pdf_sum = 0.99768D+00\n integer ( kind = 4 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'ENGLISH_SENTENCE_LENGTH_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n cum = 0.0D+00\n\n do j = 1, sentence_length_max\n\n cum = cum + pdf_vec(j)\n\n if ( cdf <= cum / pdf_sum ) then\n x = j\n return\n end if\n\n end do\n\n x = sentence_length_max\n\n return\nend\nsubroutine english_sentence_length_mean ( mean )\n\n!*****************************************************************************80\n!\n!! ENGLISH_SENTENCE_LENGTH_MEAN: mean of the English Sentence Length PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 31 July 2006\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Henry Kucera, Winthrop Francis,\n! Computational Analysis of Present-Day American English,\n! Brown University Press, 1967.\n!\n! Parameters:\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: sentence_length_max = 79\n\n integer ( kind = 4 ) j\n real ( kind = 8 ) mean\n real ( kind = 8 ), dimension ( sentence_length_max ) :: pdf_vec = (/ &\n 0.00806D+00, &\n 0.01370D+00, &\n 0.01862D+00, &\n 0.02547D+00, &\n 0.03043D+00, &\n 0.03189D+00, &\n 0.03516D+00, &\n 0.03545D+00, &\n 0.03286D+00, &\n 0.03533D+00, &\n 0.03562D+00, &\n 0.03788D+00, &\n 0.03669D+00, &\n 0.03751D+00, &\n 0.03518D+00, &\n 0.03541D+00, &\n 0.03434D+00, &\n 0.03305D+00, &\n 0.03329D+00, &\n 0.03103D+00, &\n 0.02867D+00, &\n 0.02724D+00, &\n 0.02647D+00, &\n 0.02526D+00, &\n 0.02086D+00, &\n 0.02178D+00, &\n 0.02128D+00, &\n 0.01801D+00, &\n 0.01690D+00, &\n 0.01556D+00, &\n 0.01512D+00, &\n 0.01326D+00, &\n 0.01277D+00, &\n 0.01062D+00, &\n 0.01051D+00, &\n 0.00901D+00, &\n 0.00838D+00, &\n 0.00764D+00, &\n 0.00683D+00, &\n 0.00589D+00, &\n 0.00624D+00, &\n 0.00488D+00, &\n 0.00477D+00, &\n 0.00406D+00, &\n 0.00390D+00, &\n 0.00350D+00, &\n 0.00318D+00, &\n 0.00241D+00, &\n 0.00224D+00, &\n 0.00220D+00, &\n 0.00262D+00, &\n 0.00207D+00, &\n 0.00174D+00, &\n 0.00174D+00, &\n 0.00128D+00, &\n 0.00121D+00, &\n 0.00103D+00, &\n 0.00117D+00, &\n 0.00124D+00, &\n 0.00082D+00, &\n 0.00088D+00, &\n 0.00061D+00, &\n 0.00061D+00, &\n 0.00075D+00, &\n 0.00063D+00, &\n 0.00056D+00, &\n 0.00052D+00, &\n 0.00057D+00, &\n 0.00031D+00, &\n 0.00029D+00, &\n 0.00021D+00, &\n 0.00017D+00, &\n 0.00021D+00, &\n 0.00034D+00, &\n 0.00031D+00, &\n 0.00011D+00, &\n 0.00011D+00, &\n 0.00008D+00, &\n 0.00006D+00 /)\n real ( kind = 8 ), parameter :: pdf_sum = 0.99768D+00\n\n mean = 0.0D+00\n do j = 1, sentence_length_max\n mean = mean + real ( j, kind = 8 ) * pdf_vec(j)\n end do\n\n mean = mean / pdf_sum\n\n return\nend\nsubroutine english_sentence_length_pdf ( x, pdf )\n\n!*****************************************************************************80\n!\n!! ENGLISH_SENTENCE_LENGTH_PDF evaluates the English Sentence Length PDF.\n!\n! Discussion:\n!\n! PDF(A,B;X) = B(X) if 1 <= X <= A\n! = 0 otherwise\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 31 July 2006\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Henry Kucera, Winthrop Francis,\n! Computational Analysis of Present-Day American English,\n! Brown University Press, 1967.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X, the sentence length whose probability \n! is desired.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: sentence_length_max = 79\n\n real ( kind = 8 ) pdf\n real ( kind = 8 ), dimension ( sentence_length_max ) :: pdf_vec = (/ &\n 0.00806D+00, &\n 0.01370D+00, &\n 0.01862D+00, &\n 0.02547D+00, &\n 0.03043D+00, &\n 0.03189D+00, &\n 0.03516D+00, &\n 0.03545D+00, &\n 0.03286D+00, &\n 0.03533D+00, &\n 0.03562D+00, &\n 0.03788D+00, &\n 0.03669D+00, &\n 0.03751D+00, &\n 0.03518D+00, &\n 0.03541D+00, &\n 0.03434D+00, &\n 0.03305D+00, &\n 0.03329D+00, &\n 0.03103D+00, &\n 0.02867D+00, &\n 0.02724D+00, &\n 0.02647D+00, &\n 0.02526D+00, &\n 0.02086D+00, &\n 0.02178D+00, &\n 0.02128D+00, &\n 0.01801D+00, &\n 0.01690D+00, &\n 0.01556D+00, &\n 0.01512D+00, &\n 0.01326D+00, &\n 0.01277D+00, &\n 0.01062D+00, &\n 0.01051D+00, &\n 0.00901D+00, &\n 0.00838D+00, &\n 0.00764D+00, &\n 0.00683D+00, &\n 0.00589D+00, &\n 0.00624D+00, &\n 0.00488D+00, &\n 0.00477D+00, &\n 0.00406D+00, &\n 0.00390D+00, &\n 0.00350D+00, &\n 0.00318D+00, &\n 0.00241D+00, &\n 0.00224D+00, &\n 0.00220D+00, &\n 0.00262D+00, &\n 0.00207D+00, &\n 0.00174D+00, &\n 0.00174D+00, &\n 0.00128D+00, &\n 0.00121D+00, &\n 0.00103D+00, &\n 0.00117D+00, &\n 0.00124D+00, &\n 0.00082D+00, &\n 0.00088D+00, &\n 0.00061D+00, &\n 0.00061D+00, &\n 0.00075D+00, &\n 0.00063D+00, &\n 0.00056D+00, &\n 0.00052D+00, &\n 0.00057D+00, &\n 0.00031D+00, &\n 0.00029D+00, &\n 0.00021D+00, &\n 0.00017D+00, &\n 0.00021D+00, &\n 0.00034D+00, &\n 0.00031D+00, &\n 0.00011D+00, &\n 0.00011D+00, &\n 0.00008D+00, &\n 0.00006D+00 /)\n real ( kind = 8 ), parameter :: pdf_sum = 0.99768D+00\n integer ( kind = 4 ) x\n\n if ( 1 <= x .and. x <= sentence_length_max ) then\n pdf = pdf_vec(x) / pdf_sum\n else\n pdf = 0.0D+00\n end if\n\n return\nend\nsubroutine english_sentence_length_sample ( seed, x )\n\n!*****************************************************************************80\n!\n!! ENGLISH_SENTENCE_LENGTH_SAMPLE samples the English Sentence Length PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 31 July 2006\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Henry Kucera, Winthrop Francis,\n! Computational Analysis of Present-Day American English,\n! Brown University Press, 1967.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, integer ( kind = 4 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n integer ( kind = 4 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call english_sentence_length_cdf_inv ( cdf, x )\n\n return\nend\nsubroutine english_sentence_length_variance ( variance )\n\n!*****************************************************************************80\n!\n!! ENGLISH_SENTENCE_LENGTH_VARIANCE: variance of English Sentence Length PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 31 July 2006\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Henry Kucera, Winthrop Francis,\n! Computational Analysis of Present-Day American English,\n! Brown University Press, 1967.\n!\n! Parameters:\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: sentence_length_max = 79\n\n integer ( kind = 4 ) j\n real ( kind = 8 ) mean\n real ( kind = 8 ), dimension ( sentence_length_max ) :: pdf_vec = (/ &\n 0.00806D+00, &\n 0.01370D+00, &\n 0.01862D+00, &\n 0.02547D+00, &\n 0.03043D+00, &\n 0.03189D+00, &\n 0.03516D+00, &\n 0.03545D+00, &\n 0.03286D+00, &\n 0.03533D+00, &\n 0.03562D+00, &\n 0.03788D+00, &\n 0.03669D+00, &\n 0.03751D+00, &\n 0.03518D+00, &\n 0.03541D+00, &\n 0.03434D+00, &\n 0.03305D+00, &\n 0.03329D+00, &\n 0.03103D+00, &\n 0.02867D+00, &\n 0.02724D+00, &\n 0.02647D+00, &\n 0.02526D+00, &\n 0.02086D+00, &\n 0.02178D+00, &\n 0.02128D+00, &\n 0.01801D+00, &\n 0.01690D+00, &\n 0.01556D+00, &\n 0.01512D+00, &\n 0.01326D+00, &\n 0.01277D+00, &\n 0.01062D+00, &\n 0.01051D+00, &\n 0.00901D+00, &\n 0.00838D+00, &\n 0.00764D+00, &\n 0.00683D+00, &\n 0.00589D+00, &\n 0.00624D+00, &\n 0.00488D+00, &\n 0.00477D+00, &\n 0.00406D+00, &\n 0.00390D+00, &\n 0.00350D+00, &\n 0.00318D+00, &\n 0.00241D+00, &\n 0.00224D+00, &\n 0.00220D+00, &\n 0.00262D+00, &\n 0.00207D+00, &\n 0.00174D+00, &\n 0.00174D+00, &\n 0.00128D+00, &\n 0.00121D+00, &\n 0.00103D+00, &\n 0.00117D+00, &\n 0.00124D+00, &\n 0.00082D+00, &\n 0.00088D+00, &\n 0.00061D+00, &\n 0.00061D+00, &\n 0.00075D+00, &\n 0.00063D+00, &\n 0.00056D+00, &\n 0.00052D+00, &\n 0.00057D+00, &\n 0.00031D+00, &\n 0.00029D+00, &\n 0.00021D+00, &\n 0.00017D+00, &\n 0.00021D+00, &\n 0.00034D+00, &\n 0.00031D+00, &\n 0.00011D+00, &\n 0.00011D+00, &\n 0.00008D+00, &\n 0.00006D+00 /)\n real ( kind = 8 ), parameter :: pdf_sum = 0.99768D+00\n real ( kind = 8 ) variance\n\n mean = 0.0D+00\n do j = 1, sentence_length_max\n mean = mean + real ( j, kind = 8 ) * pdf_vec(j)\n end do\n\n mean = mean / pdf_sum\n\n variance = 0.0D+00\n do j = 1, sentence_length_max\n variance = variance + pdf_vec(j) * ( j - mean )**2\n end do\n\n variance = variance / pdf_sum\n\n return\nend\nsubroutine english_word_length_cdf ( x, cdf )\n\n!*****************************************************************************80\n!\n!! ENGLISH_WORD_LENGTH_CDF evaluates the English Word Length CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 29 July 2006\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Henry Kucera, Winthrop Francis,\n! Computational Analysis of Present-Day American English,\n! Brown University Press, 1967.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X, the word length whose CDF is desired.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: word_length_max = 27\n\n real ( kind = 8 ) cdf\n real ( kind = 8 ), dimension ( word_length_max ) :: pdf_vec = (/ &\n 0.03160D+00, &\n 0.16975D+00, &\n 0.21192D+00, &\n 0.15678D+00, &\n 0.10852D+00, &\n 0.08524D+00, &\n 0.07724D+00, &\n 0.05623D+00, &\n 0.04032D+00, &\n 0.02766D+00, &\n 0.01582D+00, &\n 0.00917D+00, &\n 0.00483D+00, &\n 0.00262D+00, &\n 0.00099D+00, &\n 0.00050D+00, &\n 0.00027D+00, &\n 0.00022D+00, &\n 0.00011D+00, &\n 0.00006D+00, &\n 0.00005D+00, &\n 0.00002D+00, &\n 0.00001D+00, &\n 0.00001D+00, &\n 0.00001D+00, &\n 0.00001D+00, &\n 0.00001D+00 /)\n real ( kind = 8 ), parameter :: pdf_sum = 0.99997D+00\n integer ( kind = 4 ) x\n\n if ( x < 1 ) then\n cdf = 0.0D+00\n else if ( x < word_length_max ) then\n cdf = sum ( pdf_vec(1:x) ) / pdf_sum\n else if ( word_length_max <= x ) then\n cdf = 1.0D+00\n end if\n\n return\nend\nsubroutine english_word_length_cdf_inv ( cdf, x )\n\n!*****************************************************************************80\n!\n!! ENGLISH_WORD_LENGTH_CDF_INV inverts the English Word Length CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 29 July 2006\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Henry Kucera, Winthrop Francis,\n! Computational Analysis of Present-Day American English,\n! Brown University Press, 1967.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0 <= CDF <= 1.0.\n!\n! Output, integer ( kind = 4 ) X, the corresponding word length for which\n! CDF(X-1) < CDF <= CDF(X)\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: word_length_max = 27\n\n real ( kind = 8 ) cdf\n real ( kind = 8 ) cum\n integer ( kind = 4 ) j\n real ( kind = 8 ), dimension ( word_length_max ) :: pdf_vec = (/ &\n 0.03160D+00, &\n 0.16975D+00, &\n 0.21192D+00, &\n 0.15678D+00, &\n 0.10852D+00, &\n 0.08524D+00, &\n 0.07724D+00, &\n 0.05623D+00, &\n 0.04032D+00, &\n 0.02766D+00, &\n 0.01582D+00, &\n 0.00917D+00, &\n 0.00483D+00, &\n 0.00262D+00, &\n 0.00099D+00, &\n 0.00050D+00, &\n 0.00027D+00, &\n 0.00022D+00, &\n 0.00011D+00, &\n 0.00006D+00, &\n 0.00005D+00, &\n 0.00002D+00, &\n 0.00001D+00, &\n 0.00001D+00, &\n 0.00001D+00, &\n 0.00001D+00, &\n 0.00001D+00 /)\n real ( kind = 8 ), parameter :: pdf_sum = 0.99997D+00\n integer ( kind = 4 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'ENGLISH_WORD_LENGTH_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n cum = 0.0D+00\n\n do j = 1, word_length_max\n\n cum = cum + pdf_vec(j)\n\n if ( cdf <= cum / pdf_sum ) then\n x = j\n return\n end if\n\n end do\n\n x = word_length_max\n\n return\nend\nsubroutine english_word_length_mean ( mean )\n\n!*****************************************************************************80\n!\n!! ENGLISH_WORD_LENGTH_MEAN evaluates the mean of the English Word Length PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 29 July 2006\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Henry Kucera, Winthrop Francis,\n! Computational Analysis of Present-Day American English,\n! Brown University Press, 1967.\n!\n! Parameters:\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: word_length_max = 27\n\n integer ( kind = 4 ) j\n real ( kind = 8 ) mean\n real ( kind = 8 ), dimension ( word_length_max ) :: pdf_vec = (/ &\n 0.03160D+00, &\n 0.16975D+00, &\n 0.21192D+00, &\n 0.15678D+00, &\n 0.10852D+00, &\n 0.08524D+00, &\n 0.07724D+00, &\n 0.05623D+00, &\n 0.04032D+00, &\n 0.02766D+00, &\n 0.01582D+00, &\n 0.00917D+00, &\n 0.00483D+00, &\n 0.00262D+00, &\n 0.00099D+00, &\n 0.00050D+00, &\n 0.00027D+00, &\n 0.00022D+00, &\n 0.00011D+00, &\n 0.00006D+00, &\n 0.00005D+00, &\n 0.00002D+00, &\n 0.00001D+00, &\n 0.00001D+00, &\n 0.00001D+00, &\n 0.00001D+00, &\n 0.00001D+00 /)\n real ( kind = 8 ), parameter :: pdf_sum = 0.99997D+00\n\n mean = 0.0D+00\n do j = 1, word_length_max\n mean = mean + real ( j, kind = 8 ) * pdf_vec(j)\n end do\n\n mean = mean / pdf_sum\n\n return\nend\nsubroutine english_word_length_pdf ( x, pdf )\n\n!*****************************************************************************80\n!\n!! ENGLISH_WORD_LENGTH_PDF evaluates the English Word Length PDF.\n!\n! Discussion:\n!\n! PDF(A,B;X) = B(X) if 1 <= X <= A\n! = 0 otherwise\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 29 July 2006\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Henry Kucera, Winthrop Francis,\n! Computational Analysis of Present-Day American English,\n! Brown University Press, 1967.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X, the word length whose probability \n! is desired.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: word_length_max = 27\n\n real ( kind = 8 ) pdf\n real ( kind = 8 ), dimension ( word_length_max ) :: pdf_vec = (/ &\n 0.03160D+00, &\n 0.16975D+00, &\n 0.21192D+00, &\n 0.15678D+00, &\n 0.10852D+00, &\n 0.08524D+00, &\n 0.07724D+00, &\n 0.05623D+00, &\n 0.04032D+00, &\n 0.02766D+00, &\n 0.01582D+00, &\n 0.00917D+00, &\n 0.00483D+00, &\n 0.00262D+00, &\n 0.00099D+00, &\n 0.00050D+00, &\n 0.00027D+00, &\n 0.00022D+00, &\n 0.00011D+00, &\n 0.00006D+00, &\n 0.00005D+00, &\n 0.00002D+00, &\n 0.00001D+00, &\n 0.00001D+00, &\n 0.00001D+00, &\n 0.00001D+00, &\n 0.00001D+00 /)\n real ( kind = 8 ), parameter :: pdf_sum = 0.99997D+00\n integer ( kind = 4 ) x\n\n if ( 1 <= x .and. x <= word_length_max ) then\n pdf = pdf_vec(x) / pdf_sum\n else\n pdf = 0.0D+00\n end if\n\n return\nend\nsubroutine english_word_length_sample ( seed, x )\n\n!*****************************************************************************80\n!\n!! ENGLISH_WORD_LENGTH_SAMPLE samples the English Word Length PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 29 July 2006\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Henry Kucera, Winthrop Francis,\n! Computational Analysis of Present-Day American English,\n! Brown University Press, 1967.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, integer ( kind = 4 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n integer ( kind = 4 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call english_word_length_cdf_inv ( cdf, x )\n\n return\nend\nsubroutine english_word_length_variance ( variance )\n\n!*****************************************************************************80\n!\n!! ENGLISH_WORD_LENGTH_VARIANCE: variance of the English Word Length PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 29 July 2006\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Henry Kucera, Winthrop Francis,\n! Computational Analysis of Present-Day American English,\n! Brown University Press, 1967.\n!\n! Parameters:\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: word_length_max = 27\n\n integer ( kind = 4 ) j\n real ( kind = 8 ) mean\n real ( kind = 8 ), dimension ( word_length_max ) :: pdf_vec = (/ &\n 0.03160D+00, &\n 0.16975D+00, &\n 0.21192D+00, &\n 0.15678D+00, &\n 0.10852D+00, &\n 0.08524D+00, &\n 0.07724D+00, &\n 0.05623D+00, &\n 0.04032D+00, &\n 0.02766D+00, &\n 0.01582D+00, &\n 0.00917D+00, &\n 0.00483D+00, &\n 0.00262D+00, &\n 0.00099D+00, &\n 0.00050D+00, &\n 0.00027D+00, &\n 0.00022D+00, &\n 0.00011D+00, &\n 0.00006D+00, &\n 0.00005D+00, &\n 0.00002D+00, &\n 0.00001D+00, &\n 0.00001D+00, &\n 0.00001D+00, &\n 0.00001D+00, &\n 0.00001D+00 /)\n real ( kind = 8 ), parameter :: pdf_sum = 0.99997D+00\n real ( kind = 8 ) variance\n\n mean = 0.0D+00\n do j = 1, word_length_max\n mean = mean + real ( j, kind = 8 ) * pdf_vec(j)\n end do\n\n mean = mean / pdf_sum\n\n variance = 0.0D+00\n do j = 1, word_length_max\n variance = variance + pdf_vec(j) * ( j - mean )**2\n end do\n\n variance = variance / pdf_sum\n\n return\nend\nfunction error_f ( x )\n\n!*****************************************************************************80\n!\n!! ERROR_F evaluates the error function ERF.\n!\n! Discussion:\n!\n! Since some compilers already supply a routine named ERF which evaluates\n! the error function, this routine has been given a distinct, if\n! somewhat unnatural, name.\n!\n! The function is defined by:\n!\n! ERF(X) = ( 2 / sqrt ( PI ) ) * Integral ( 0 <= T <= X ) EXP ( - T^2 ) dT.\n!\n! Properties of the function include:\n!\n! Limit ( X -> -Infinity ) ERF(X) = -1.0;\n! ERF(0) = 0.0;\n! ERF(0.476936...) = 0.5;\n! Limit ( X -> +Infinity ) ERF(X) = +1.0.\n!\n! 0.5D+00 * ( ERF(X/sqrt(2)) + 1 ) = Normal_01_CDF(X)\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 17 November 2006\n!\n! Author:\n!\n! Original FORTRAN77 version by William Cody.\n! FORTRAN90 version by John Burkardt.\n!\n! Reference:\n!\n! William Cody,\n! Rational Chebyshev Approximations for the Error Function,\n! Mathematics of Computation,\n! 1969, pages 631-638.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the error function.\n!\n! Output, real ( kind = 8 ) ERROR_F, the value of the error function.\n!\n implicit none\n\n real ( kind = 8 ), parameter, dimension ( 5 ) :: a = (/ &\n 3.16112374387056560D+00, &\n 1.13864154151050156D+02, &\n 3.77485237685302021D+02, &\n 3.20937758913846947D+03, &\n 1.85777706184603153D-01 /)\n real ( kind = 8 ), parameter, dimension ( 4 ) :: b = (/ &\n 2.36012909523441209D+01, &\n 2.44024637934444173D+02, &\n 1.28261652607737228D+03, &\n 2.84423683343917062D+03 /)\n real ( kind = 8 ), parameter, dimension ( 9 ) :: c = (/ &\n 5.64188496988670089D-01, &\n 8.88314979438837594D+00, &\n 6.61191906371416295D+01, &\n 2.98635138197400131D+02, &\n 8.81952221241769090D+02, &\n 1.71204761263407058D+03, &\n 2.05107837782607147D+03, &\n 1.23033935479799725D+03, &\n 2.15311535474403846D-08 /)\n real ( kind = 8 ), parameter, dimension ( 8 ) :: d = (/ &\n 1.57449261107098347D+01, &\n 1.17693950891312499D+02, &\n 5.37181101862009858D+02, &\n 1.62138957456669019D+03, &\n 3.29079923573345963D+03, &\n 4.36261909014324716D+03, &\n 3.43936767414372164D+03, &\n 1.23033935480374942D+03 /)\n real ( kind = 8 ) del\n real ( kind = 8 ) error_f\n integer ( kind = 4 ) i\n real ( kind = 8 ), parameter, dimension ( 6 ) :: p = (/ &\n 3.05326634961232344D-01, &\n 3.60344899949804439D-01, &\n 1.25781726111229246D-01, &\n 1.60837851487422766D-02, &\n 6.58749161529837803D-04, &\n 1.63153871373020978D-02 /)\n real ( kind = 8 ), parameter, dimension ( 5 ) :: q = (/ &\n 2.56852019228982242D+00, &\n 1.87295284992346047D+00, &\n 5.27905102951428412D-01, &\n 6.05183413124413191D-02, &\n 2.33520497626869185D-03 /)\n real ( kind = 8 ), parameter :: sqrpi = 0.56418958354775628695D+00\n real ( kind = 8 ), parameter :: thresh = 0.46875D+00\n real ( kind = 8 ) x\n real ( kind = 8 ) xabs\n real ( kind = 8 ), parameter :: xbig = 26.543D+00\n real ( kind = 8 ) xden\n real ( kind = 8 ) xnum\n real ( kind = 8 ) xsq\n\n xabs = abs ( ( x ) )\n!\n! Evaluate ERF(X) for |X| <= 0.46875.\n!\n if ( xabs <= thresh ) then\n\n if ( epsilon ( xabs ) < xabs ) then\n xsq = xabs * xabs\n else\n xsq = 0.0D+00\n end if\n\n xnum = a(5) * xsq\n xden = xsq\n do i = 1, 3\n xnum = ( xnum + a(i) ) * xsq\n xden = ( xden + b(i) ) * xsq\n end do\n\n error_f = x * ( xnum + a(4) ) / ( xden + b(4) )\n!\n! Evaluate ERFC(X) for 0.46875 <= |X| <= 4.0.\n!\n else if ( xabs <= 4.0D+00 ) then\n\n xnum = c(9) * xabs\n xden = xabs\n do i = 1, 7\n xnum = ( xnum + c(i) ) * xabs\n xden = ( xden + d(i) ) * xabs\n end do\n\n error_f = ( xnum + c(8) ) / ( xden + d(8) )\n xsq = real ( int ( xabs * 16.0D+00 ), kind = 8 ) / 16.0D+00\n del = ( xabs - xsq ) * ( xabs + xsq )\n error_f = exp ( - xsq * xsq ) * exp ( - del ) * error_f\n\n error_f = ( 0.5D+00 - error_f ) + 0.5D+00\n\n if ( x < 0.0D+00 ) then\n error_f = - error_f\n end if\n!\n! Evaluate ERFC(X) for 4.0D+00 < |X|.\n!\n else\n\n if ( xbig <= xabs ) then\n\n if ( 0.0D+00 < x ) then\n error_f = 1.0D+00\n else\n error_f = - 1.0D+00\n end if\n\n else\n\n xsq = 1.0D+00 / ( xabs * xabs )\n\n xnum = p(6) * xsq\n xden = xsq\n do i = 1, 4\n xnum = ( xnum + p(i) ) * xsq\n xden = ( xden + q(i) ) * xsq\n end do\n\n error_f = xsq * ( xnum + p(5) ) / ( xden + q(5) )\n error_f = ( sqrpi - error_f ) / xabs\n xsq = real ( int ( xabs * 16.0D+00 ), kind = 8 ) / 16.0D+00\n del = ( xabs - xsq ) * ( xabs + xsq )\n error_f = exp ( - xsq * xsq ) * exp ( - del ) * error_f\n\n error_f = ( 0.5D+00 - error_f ) + 0.5D+00\n\n if ( x < 0.0D+00 ) then\n error_f = - error_f\n end if\n\n end if\n\n end if\n\n return\nend\nfunction error_f_inverse ( y )\n\n!*****************************************************************************80\n!\n!! ERROR_F_INVERSE inverts the error function ERF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 August 2010\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) Y, the value of the error function.\n!\n! Output, real ( kind = 8 ) ERROR_F_INVERSE, the value X such that\n! ERROR_F(X) = Y.\n!\n implicit none\n\n real ( kind = 8 ) error_f_inverse\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n real ( kind = 8 ) z\n\n z = ( y + 1.0D+00 ) / 2.0D+00\n\n call normal_01_cdf_inv ( z, x )\n\n error_f_inverse = x / sqrt ( 2.0D+00 )\n\n return\nend\nsubroutine erlang_cdf ( x, a, b, c, cdf )\n\n!*****************************************************************************80\n!\n!! ERLANG_CDF evaluates the Erlang CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 31 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n!\n! Input, real ( kind = 8 ) A, B, integer C, the parameters of the PDF.\n! 0.0D+00 < B.\n! 0 < C.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n integer ( kind = 4 ) c\n real ( kind = 8 ) cdf\n real ( kind = 8 ) gamma_inc\n real ( kind = 8 ) p2\n real ( kind = 8 ) x\n real ( kind = 8 ) x2\n\n if ( x < a ) then\n\n cdf = 0.0D+00\n\n else\n\n x2 = ( x - a ) / b\n p2 = real ( c, kind = 8 )\n\n cdf = gamma_inc ( p2, x2 )\n\n end if\n\n return\nend\nsubroutine erlang_cdf_inv ( cdf, a, b, c, x )\n\n!*****************************************************************************80\n!\n!! ERLANG_CDF_INV inverts the Erlang CDF.\n!\n! Discussion:\n!\n! A simple bisection method is used.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n!\n! Input, real ( kind = 8 ) A, B, integer C, the parameters of the PDF.\n! 0.0D+00 < B.\n! 0 < C.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n integer ( kind = 4 ) c\n real ( kind = 8 ) cdf\n real ( kind = 8 ) cdf1\n real ( kind = 8 ) cdf2\n real ( kind = 8 ) cdf3\n integer ( kind = 4 ) it\n integer ( kind = 4 ), parameter :: it_max = 100\n real ( kind = 8 ), parameter :: tol = 0.0001D+00\n real ( kind = 8 ) x\n real ( kind = 8 ) x1\n real ( kind = 8 ) x2\n real ( kind = 8 ) x3\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'ERLANG_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n if ( cdf == 0.0D+00 ) then\n x = a\n return\n else if ( 1.0D+00 == cdf ) then\n x = huge ( x )\n return\n end if\n\n x1 = a\n cdf1 = 0.0D+00\n\n x2 = a + 1.0D+00\n\n do\n\n call erlang_cdf ( x2, a, b, c, cdf2 )\n\n if ( cdf < cdf2 ) then\n exit\n end if\n\n x2 = a + 2.0D+00 * ( x2 - a )\n\n end do\n!\n! Now use bisection.\n!\n it = 0\n\n do\n\n it = it + 1\n\n x3 = 0.5D+00 * ( x1 + x2 )\n call erlang_cdf ( x3, a, b, c, cdf3 )\n\n if ( abs ( cdf3 - cdf ) < tol ) then\n x = x3\n exit\n end if\n\n if ( it_max < it ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'ERLANG_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' Iteration limit exceeded.'\n return\n end if\n\n if ( sign ( 1.0D+00, cdf3 - cdf ) == sign ( 1.0D+00, cdf1 - cdf ) ) then\n x1 = x3\n cdf1 = cdf3\n else\n x2 = x3\n cdf2 = cdf3\n end if\n\n end do\n\n return\nend\nfunction erlang_check ( a, b, c )\n\n!*****************************************************************************80\n!\n!! ERLANG_CHECK checks the parameters of the Erlang PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, integer C, the parameters of the PDF.\n! 0.0D+00 < B.\n! 0 < C.\n!\n! Output, logical ERLANG_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n integer ( kind = 4 ) c\n logical erlang_check\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'ERLANG_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B <= 0.0'\n erlang_check = .false.\n return\n end if\n\n if ( c <= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'ERLANG_CHECK - Fatal error!'\n write ( *, '(a)' ) ' C <= 0.'\n erlang_check = .false.\n return\n end if\n\n erlang_check = .true.\n\n return\nend\nsubroutine erlang_mean ( a, b, c, mean )\n\n!*****************************************************************************80\n!\n!! ERLANG_MEAN returns the mean of the Erlang PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 31 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, integer C, the parameters of the PDF.\n! 0.0D+00 < B.\n! 0 < C.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n integer ( kind = 4 ) c\n real ( kind = 8 ) mean\n\n mean = a + b * real ( c, kind = 8 )\n\n return\nend\nsubroutine erlang_pdf ( x, a, b, c, pdf )\n\n!*****************************************************************************80\n!\n!! ERLANG_PDF evaluates the Erlang PDF.\n!\n! Discussion:\n!\n! PDF(A,B,C;X) = ( ( X - A ) / B )^( C - 1 )\n! / ( B * Gamma ( C ) * EXP ( ( X - A ) / B ) )\n!\n! for 0 < B, 0 < C integer, A <= X.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 31 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Input, real ( kind = 8 ) A, B, integer C, the parameters of the PDF.\n! 0.0D+00 < B.\n! 0 < C.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n integer ( kind = 4 ) c\n real ( kind = 8 ) i4_factorial\n real ( kind = 8 ) pdf\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n\n if ( x <= a ) then\n\n pdf = 0.0D+00\n\n else\n\n y = ( x - a ) / b\n\n pdf = y**( c - 1 ) / ( b * i4_factorial ( c - 1 ) * exp ( y ) )\n\n end if\n\n return\nend\nsubroutine erlang_sample ( a, b, c, seed, x )\n\n!*****************************************************************************80\n!\n!! ERLANG_SAMPLE samples the Erlang PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 31 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, integer C, the parameters of the PDF.\n! 0.0D+00 < B.\n! 0 < C.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) a2\n real ( kind = 8 ) b\n real ( kind = 8 ) b2\n integer ( kind = 4 ) c\n integer ( kind = 4 ) i\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n real ( kind = 8 ) x2\n\n a2 = 0.0D+00\n b2 = b\n x = a\n do i = 1, c\n call exponential_sample ( a2, b2, seed, x2 )\n x = x + x2\n end do\n\n return\nend\nsubroutine erlang_variance ( a, b, c, variance )\n\n!*****************************************************************************80\n!\n!! ERLANG_VARIANCE returns the variance of the Erlang PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 31 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, integer C, the parameters of the PDF.\n! 0.0D+00 < B.\n! 0 < C.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n integer ( kind = 4 ) c\n real ( kind = 8 ) variance\n\n variance = b * b * real ( c )\n\n return\nend\nfunction euler_constant ( )\n\n!*****************************************************************************80\n!\n!! EULER_CONSTANT returns the value of the Euler-Mascheroni constant.\n!\n! Discussion:\n!\n! The Euler-Mascheroni constant is often denoted by a lower-case\n! Gamma. Gamma is defined as\n!\n! Gamma = limit ( M -> Infinity )\n! ( Sum ( 1 <= N <= M ) 1 / N ) - Log ( M )\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 27 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Output, real ( kind = 8 ) EULER_CONSTANT, the value of the\n! Euler-Mascheroni constant.\n!\n implicit none\n\n real ( kind = 8 ) euler_constant\n\n euler_constant = 0.577215664901532860606512090082402431042D+00\n\n return\nend\nsubroutine exponential_01_cdf ( x, cdf )\n\n!*****************************************************************************80\n!\n!! EXPONENTIAL_01_CDF evaluates the Exponential 01 CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 09 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( x <= 0.0D+00 ) then\n cdf = 0.0D+00\n else\n cdf = 1.0D+00 - exp ( - x )\n end if\n\n return\nend\nsubroutine exponential_01_cdf_inv ( cdf, x )\n\n!*****************************************************************************80\n!\n!! EXPONENTIAL_01_CDF_INV inverts the Exponential 01 CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 09 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument.\n!\n implicit none\n\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'EXPONENTIAL_01_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n x = - log ( 1.0D+00 - cdf )\n\n return\nend\nsubroutine exponential_01_mean ( mean )\n\n!*****************************************************************************80\n!\n!! EXPONENTIAL_01_MEAN returns the mean of the Exponential 01 PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 09 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) mean\n\n mean = 1.0D+00\n\n return\nend\nsubroutine exponential_01_pdf ( x, pdf )\n\n!*****************************************************************************80\n!\n!! EXPONENTIAL_01_PDF evaluates the Exponential 01 PDF.\n!\n! Discussion:\n!\n! PDF(X) = EXP ( - X )\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 09 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n! 0.0D+00 <= X\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) pdf\n real ( kind = 8 ) x\n\n if ( x < 0.0D+00 ) then\n pdf = 0.0D+00\n else\n pdf = exp ( - x )\n end if\n\n return\nend\nsubroutine exponential_01_sample ( seed, x )\n\n!*****************************************************************************80\n!\n!! EXPONENTIAL_01_SAMPLE samples the Exponential PDF with parameter 1.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 March 2003\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n x = - log ( 1.0D+00 - cdf )\n\n return\nend\nsubroutine exponential_01_variance ( variance )\n\n!*****************************************************************************80\n!\n!! EXPONENTIAL_01_VARIANCE returns the variance of the Exponential 01 PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 09 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) variance\n\n variance = 1.0D+00\n\n return\nend\nsubroutine exponential_cdf ( x, a, b, cdf )\n\n!*****************************************************************************80\n!\n!! EXPONENTIAL_CDF evaluates the Exponential CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 May 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameter of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( x <= a ) then\n cdf = 0.0D+00\n else\n cdf = 1.0D+00 - exp ( ( a - x ) / b )\n end if\n\n return\nend\nsubroutine exponential_cdf_inv ( cdf, a, b, x )\n\n!*****************************************************************************80\n!\n!! EXPONENTIAL_CDF_INV inverts the Exponential CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 May 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'EXPONENTIAL_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n x = a - b * log ( 1.0D+00 - cdf )\n\n return\nend\nsubroutine exponential_cdf_values ( n_data, lambda, x, fx )\n\n!*****************************************************************************80\n!\n!! EXPONENTIAL_CDF_VALUES returns some values of the Exponential CDF.\n!\n! Discussion:\n!\n! In Mathematica, the function can be evaluated by:\n!\n! Needs[\"Statistics`ContinuousDistributions`\"]\n! dist = ExponentialDistribution [ lambda ]\n! CDF [ dist, x ]\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 29 August 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Milton Abramowitz, Irene Stegun,\n! Handbook of Mathematical Functions,\n! National Bureau of Standards, 1964,\n! LC: QA47.A34,\n! ISBN: 0-486-61272-4.\n!\n! Stephen Wolfram,\n! The Mathematica Book,\n! Fourth Edition,\n! Wolfram Media / Cambridge University Press, 1999.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) N_DATA. The user sets N_DATA to 0 \n! before the first call. On each call, the routine increments N_DATA by 1, \n! and returns the corresponding data; when there is no more data, the\n! output value of N_DATA will be 0 again.\n!\n! Output, real ( kind = 8 ) LAMBDA, the parameter of the distribution.\n!\n! Output, real ( kind = 8 ) X, the argument of the function.\n!\n! Output, real ( kind = 8 ) FX, the value of the function.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: n_max = 9\n\n real ( kind = 8 ) fx\n real ( kind = 8 ), save, dimension ( n_max ) :: fx_vec = (/ &\n 0.3934693402873666D+00, &\n 0.6321205588285577D+00, &\n 0.7768698398515702D+00, &\n 0.8646647167633873D+00, &\n 0.8646647167633873D+00, &\n 0.9816843611112658D+00, &\n 0.9975212478233336D+00, &\n 0.9996645373720975D+00, &\n 0.9999546000702375D+00 /)\n real ( kind = 8 ) lambda\n real ( kind = 8 ), save, dimension ( n_max ) :: lambda_vec = (/ &\n 0.5000000000000000D+00, &\n 0.5000000000000000D+00, &\n 0.5000000000000000D+00, &\n 0.5000000000000000D+00, &\n 0.1000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.4000000000000000D+01, &\n 0.5000000000000000D+01 /)\n integer ( kind = 4 ) n_data\n real ( kind = 8 ) x\n real ( kind = 8 ), save, dimension ( n_max ) :: x_vec = (/ &\n 0.1000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.4000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01 /)\n\n if ( n_data < 0 ) then\n n_data = 0\n end if\n\n n_data = n_data + 1\n\n if ( n_max < n_data ) then\n n_data = 0\n lambda = 0.0D+00\n x = 0.0D+00\n fx = 0.0D+00\n else\n lambda = lambda_vec(n_data)\n x = x_vec(n_data)\n fx = fx_vec(n_data)\n end if\n\n return\nend\nfunction exponential_check ( a, b )\n\n!*****************************************************************************80\n!\n!! EXPONENTIAL_CHECK checks the parameters of the Exponential CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameter of the PDF.\n! 0.0D+00 < B.\n!\n! Output, logical EXPONENTIAL_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n logical exponential_check\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'EXPONENTIAL_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B <= 0.0'\n exponential_check = .false.\n return\n end if\n\n exponential_check = .true.\n\n return\nend\nsubroutine exponential_mean ( a, b, mean )\n\n!*****************************************************************************80\n!\n!! EXPONENTIAL_MEAN returns the mean of the Exponential PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 May 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) mean\n\n mean = a + b\n\n return\nend\nsubroutine exponential_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! EXPONENTIAL_PDF evaluates the Exponential PDF.\n!\n! Discussion:\n!\n! PDF(A,B;X) = ( 1 / B ) * EXP ( ( A - X ) / B )\n!\n! The time interval between two Poisson events is a random\n! variable with the Exponential PDF. The parameter B is the\n! average interval between events.\n!\n! In another context, the Exponential PDF is related to\n! the Boltzmann distribution, which describes the relative\n! probability of finding a system, which is in thermal equilibrium\n! at absolute temperature T, in a given state having energy E.\n! The relative probability is\n!\n! Boltzmann_Relative_Probability(E,T) = exp ( - E / ( k * T ) ),\n!\n! where k is the Boltzmann constant,\n!\n! k = 1.38 * 10**(-23) joules / degree Kelvin\n!\n! and normalization requires a determination of the possible\n! energy states of the system.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 May 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n! A <= X\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) pdf\n real ( kind = 8 ) x\n\n if ( x < a ) then\n pdf = 0.0D+00\n else\n pdf = ( 1.0D+00 / b ) * exp ( ( a - x ) / b )\n end if\n\n return\nend\nsubroutine exponential_sample ( a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! EXPONENTIAL_SAMPLE samples the Exponential PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 May 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call exponential_cdf_inv ( cdf, a, b, x )\n\n return\nend\nsubroutine exponential_variance ( a, b, variance )\n\n!*****************************************************************************80\n!\n!! EXPONENTIAL_VARIANCE returns the variance of the Exponential PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 May 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) variance\n\n variance = b * b\n\n return\nend\nsubroutine extreme_values_cdf ( x, a, b, cdf )\n\n!*****************************************************************************80\n!\n!! EXTREME_VALUES_CDF evaluates the Extreme Values CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 15 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n\n y = ( x - a ) / b\n\n cdf = exp ( - exp ( - y ) )\n\n return\nend\nsubroutine extreme_values_cdf_inv ( cdf, a, b, x )\n\n!*****************************************************************************80\n!\n!! EXTREME_VALUES_CDF_INV inverts the Extreme Values CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 15 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'EXTREME_VALUES_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n x = a - b * log ( - log ( cdf ) )\n\n return\nend\nsubroutine extreme_values_cdf_values ( n_data, alpha, beta, x, fx )\n\n!*****************************************************************************80\n!\n!! EXTREME_VALUES_CDF_VALUES returns some values of the Extreme Values CDF.\n!\n! Discussion:\n!\n! In Mathematica, the function can be evaluated by:\n!\n! Needs[\"Statistics`ContinuousDistributions`\"]\n! dist = ExtremeValuesDistribution [ alpha, beta ]\n! CDF [ dist, x ]\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Milton Abramowitz, Irene Stegun,\n! Handbook of Mathematical Functions,\n! National Bureau of Standards, 1964,\n! LC: QA47.A34,\n! ISBN: 0-486-61272-4.\n!\n! Stephen Wolfram,\n! The Mathematica Book,\n! Fourth Edition,\n! Wolfram Media / Cambridge University Press, 1999.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) N_DATA. The user sets N_DATA to 0\n! before the first call. On each call, the routine increments N_DATA by 1,\n! and returns the corresponding data; when there is no more data, the\n! output value of N_DATA will be 0 again.\n!\n! Output, real ( kind = 8 ) ALPHA, the first parameter of the distribution.\n!\n! Output, real ( kind = 8 ) BETA, the second parameter of the distribution.\n!\n! Output, real ( kind = 8 ) X, the argument of the function.\n!\n! Output, real ( kind = 8 ) FX, the value of the function.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: n_max = 12\n\n real ( kind = 8 ) alpha\n real ( kind = 8 ), save, dimension ( n_max ) :: alpha_vec = (/ &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.4000000000000000D+01, &\n 0.5000000000000000D+01 /)\n real ( kind = 8 ) beta\n real ( kind = 8 ), save, dimension ( n_max ) :: beta_vec = (/ &\n 0.5000000000000000D+00, &\n 0.5000000000000000D+00, &\n 0.5000000000000000D+00, &\n 0.5000000000000000D+00, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.4000000000000000D+01, &\n 0.5000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01 /)\n real ( kind = 8 ) fx\n real ( kind = 8 ), save, dimension ( n_max ) :: fx_vec = (/ &\n 0.3678794411714423D+00, &\n 0.8734230184931166D+00, &\n 0.9818510730616665D+00, &\n 0.9975243173927525D+00, &\n 0.5452392118926051D+00, &\n 0.4884435800065159D+00, &\n 0.4589560693076638D+00, &\n 0.4409910259429826D+00, &\n 0.5452392118926051D+00, &\n 0.3678794411714423D+00, &\n 0.1922956455479649D+00, &\n 0.6598803584531254D-01 /)\n integer ( kind = 4 ) n_data\n real ( kind = 8 ) x\n real ( kind = 8 ), save, dimension ( n_max ) :: x_vec = (/ &\n 0.1000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.4000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.3000000000000000D+01 /)\n\n if ( n_data < 0 ) then\n n_data = 0\n end if\n\n n_data = n_data + 1\n\n if ( n_max < n_data ) then\n n_data = 0\n alpha = 0.0D+00\n beta = 0.0D+00\n x = 0.0D+00\n fx = 0.0D+00\n else\n alpha = alpha_vec(n_data)\n beta = beta_vec(n_data)\n x = x_vec(n_data)\n fx = fx_vec(n_data)\n end if\n\n return\nend\nfunction extreme_values_check ( a, b )\n\n!*****************************************************************************80\n!\n!! EXTREME_VALUES_CHECK checks the parameters of the Extreme Values CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, logical EXTREME_VALUES_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n logical extreme_values_check\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'EXTREME_VALUES_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B <= 0.'\n extreme_values_check = .false.\n return\n end if\n\n extreme_values_check = .true.\n\n return\nend\nsubroutine extreme_values_mean ( a, b, mean )\n\n!*****************************************************************************80\n!\n!! EXTREME_VALUES_MEAN returns the mean of the Extreme Values PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 16 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) euler_constant\n real ( kind = 8 ) mean\n\n mean = a + b * euler_constant ( )\n\n return\nend\nsubroutine extreme_values_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! EXTREME_VALUES_PDF evaluates the Extreme Values PDF.\n!\n! Discussion:\n!\n! PDF(A,B;X) =\n! ( 1 / B ) * exp ( ( A - X ) / B ) * exp ( - exp ( ( A - X ) / B ) ).\n!\n! The Extreme Values PDF is also known as the Fisher-Tippet PDF\n! and the Log-Weibull PDF.\n!\n! The special case A = 0 and B = 1 is the Gumbel PDF.\n!\n! The Extreme Values PDF is the limiting distribution for the\n! smallest or largest value in a large sample drawn from\n! any of a great variety of distributions.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 15 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Eric Weisstein, editor,\n! CRC Concise Encylopedia of Mathematics,\n! CRC Press, 1998.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) pdf\n real ( kind = 8 ) x\n\n pdf = ( 1.0D+00 / b ) * exp ( ( a - x ) / b - exp ( ( a - x ) / b ) )\n\n return\nend\nsubroutine extreme_values_sample ( a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! EXTREME_VALUES_SAMPLE samples the Extreme Values PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 15 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call extreme_values_cdf_inv ( cdf, a, b, x )\n\n return\nend\nsubroutine extreme_values_variance ( a, b, variance )\n\n!*****************************************************************************80\n!\n!! EXTREME_VALUES_VARIANCE returns the variance of the Extreme Values PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 15 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) variance\n\n variance = pi * pi * b * b / 6.0D+00\n\n return\nend\nsubroutine f_cdf ( x, m, n, cdf )\n\n!*****************************************************************************80\n!\n!! F_CDF evaluates the F central CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 31 May 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Milton Abramowitz, Irene Stegun,\n! Handbook of Mathematical Functions,\n! National Bureau of Standards, 1964,\n! LC: QA47.A34,\n! ISBN: 0-486-61272-4.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n!\n! Input, integer ( kind = 4 ) M, N, the parameters of the PDF.\n! 1 <= M,\n! 1 <= N.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) arg1\n real ( kind = 8 ) arg2\n real ( kind = 8 ) arg3\n real ( kind = 8 ) beta_inc\n real ( kind = 8 ) cdf\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n real ( kind = 8 ) x\n\n if ( x <= 0.0D+00 ) then\n\n cdf = 0.0D+00\n\n else\n\n arg1 = 0.5D+00 * real ( n, kind = 8 )\n arg2 = 0.5D+00 * real ( m, kind = 8 )\n arg3 = real ( n, kind = 8 ) &\n / ( real ( n, kind = 8 ) + real ( m, kind = 8 ) * x )\n\n cdf = 1.0D+00 - beta_inc ( arg1, arg2, arg3 )\n\n end if\n\n return\nend\nsubroutine f_cdf_values ( n_data, a, b, x, fx )\n\n!*****************************************************************************80\n!\n!! F_CDF_VALUES returns some values of the F CDF test function.\n!\n! Discussion:\n!\n! In Mathematica, the function can be evaluated by:\n!\n! Needs[\"Statistics`ContinuousDistributions`\"]\n! dist = FRatioDistribution [ dfn, dfd ]\n! CDF [ dist, x ]\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 11 August 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Milton Abramowitz, Irene Stegun,\n! Handbook of Mathematical Functions,\n! National Bureau of Standards, 1964,\n! LC: QA47.A34,\n! ISBN: 0-486-61272-4.\n!\n! Stephen Wolfram,\n! The Mathematica Book,\n! Fourth Edition,\n! Wolfram Media / Cambridge University Press, 1999.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) N_DATA. The user sets N_DATA to 0\n! before the first call. On each call, the routine increments N_DATA by 1,\n! and returns the corresponding data; when there is no more data, the\n! output value of N_DATA will be 0 again.\n!\n! Output, integer ( kind = 4 ) A, integer B, the parameters of the function.\n!\n! Output, real ( kind = 8 ) X, the argument of the function.\n!\n! Output, real ( kind = 8 ) FX, the value of the function.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: n_max = 20\n\n integer ( kind = 4 ) a\n integer ( kind = 4 ), save, dimension ( n_max ) :: a_vec = (/ &\n 1, &\n 1, &\n 5, &\n 1, &\n 2, &\n 4, &\n 1, &\n 6, &\n 8, &\n 1, &\n 3, &\n 6, &\n 1, &\n 1, &\n 1, &\n 1, &\n 2, &\n 3, &\n 4, &\n 5 /)\n integer ( kind = 4 ) b\n integer ( kind = 4 ), save, dimension ( n_max ) :: b_vec = (/ &\n 1, &\n 5, &\n 1, &\n 5, &\n 10, &\n 20, &\n 5, &\n 6, &\n 16, &\n 5, &\n 10, &\n 12, &\n 5, &\n 5, &\n 5, &\n 5, &\n 5, &\n 5, &\n 5, &\n 5 /)\n real ( kind = 8 ) fx\n real ( kind = 8 ), save, dimension ( n_max ) :: fx_vec = (/ &\n 0.5000000000000000D+00, &\n 0.4999714850534485D+00, &\n 0.4996034370170990D+00, &\n 0.7496993658293228D+00, &\n 0.7504656462757382D+00, &\n 0.7514156325324275D+00, &\n 0.8999867031372156D+00, &\n 0.8997127554259699D+00, &\n 0.9002845660853669D+00, &\n 0.9500248817817622D+00, &\n 0.9500574946122442D+00, &\n 0.9501926400000000D+00, &\n 0.9750133887312993D+00, &\n 0.9900022327445249D+00, &\n 0.9949977837872073D+00, &\n 0.9989999621122122D+00, &\n 0.5687988496283079D+00, &\n 0.5351452100063650D+00, &\n 0.5143428032407864D+00, &\n 0.5000000000000000D+00 /)\n integer ( kind = 4 ) n_data\n real ( kind = 8 ) x\n real ( kind = 8 ), save, dimension ( n_max ) :: x_vec = (/ &\n 1.00D+00, &\n 0.528D+00, &\n 1.89D+00, &\n 1.69D+00, &\n 1.60D+00, &\n 1.47D+00, &\n 4.06D+00, &\n 3.05D+00, &\n 2.09D+00, &\n 6.61D+00, &\n 3.71D+00, &\n 3.00D+00, &\n 10.01D+00, &\n 16.26D+00, &\n 22.78D+00, &\n 47.18D+00, &\n 1.00D+00, &\n 1.00D+00, &\n 1.00D+00, &\n 1.00D+00 /)\n\n if ( n_data < 0 ) then\n n_data = 0\n end if\n\n n_data = n_data + 1\n\n if ( n_max < n_data ) then\n n_data = 0\n a = 0\n b = 0\n x = 0.0D+00\n fx = 0.0D+00\n else\n a = a_vec(n_data)\n b = b_vec(n_data)\n x = x_vec(n_data)\n fx = fx_vec(n_data)\n end if\n\n return\nend\nfunction f_check ( m, n )\n\n!*****************************************************************************80\n!\n!! F_CHECK checks the parameters of the F PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 25 October 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, N, the parameters of the PDF.\n! 1 <= M,\n! 1 <= N.\n!\n! Output, logical F_CHECK, is TRUE if the parameters are legal.\n!\n implicit none\n\n logical f_check\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n\n if ( m < 1 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'F_CHECK - Fatal error!'\n write ( *, '(a)' ) ' M < 1.'\n f_check = .false.\n return\n end if\n\n if ( n < 1 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'F_CHECK - Fatal error!'\n write ( *, '(a)' ) ' N < 1.'\n f_check = .false.\n return\n end if\n\n f_check = .true.\n\n return\nend\nsubroutine f_mean ( m, n, mean )\n\n!*****************************************************************************80\n!\n!! F_MEAN returns the mean of the F central PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 10 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, N, the parameters of the PDF.\n! 1 <= M,\n! 1 <= N.\n! Note, however, that the mean is not defined unless 3 <= N.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) m\n real ( kind = 8 ) mean\n integer ( kind = 4 ) n\n\n if ( n < 3 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'F_MEAN - Fatal error!'\n write ( *, '(a)' ) ' The mean is not defined for N < 3.'\n stop 1\n end if\n\n mean = real ( n, kind = 8 ) / real ( n - 2, kind = 8 )\n\n return\nend\nsubroutine f_pdf ( x, m, n, pdf )\n\n!*****************************************************************************80\n!\n!! F_PDF evaluates the F central PDF.\n!\n! Discussion:\n!\n! PDF(M,N;X) = M^(M/2) * X^((M-2)/2)\n! / ( Beta(M/2,N/2) * N^(M/2) * ( 1 + (M/N) * X )^((M+N)/2)\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 13 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n! 0.0D+00 <= X\n!\n! Input, integer ( kind = 4 ) M, N, the parameters of the PDF.\n! 1 <= M,\n! 1 <= N.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) beta\n real ( kind = 8 ) bot1\n real ( kind = 8 ) bot2\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n real ( kind = 8 ) pdf\n real ( kind = 8 ) top\n real ( kind = 8 ) x\n\n if ( x < 0.0D+00 ) then\n\n pdf = 0.0D+00\n\n else\n\n a = real ( m, kind = 8 )\n b = real ( n, kind = 8 )\n\n top = sqrt ( a**m * b**n * x**( m - 2 ) )\n bot1 = beta ( a / 2.0D+00, b / 2.0D+00 )\n bot2 = sqrt ( ( b + a * x ) ** ( m + n ) )\n\n pdf = top / ( bot1 * bot2 )\n\n end if\n\n return\nend\nsubroutine f_sample ( m, n, seed, x )\n\n!*****************************************************************************80\n!\n!! F_SAMPLE samples the F central PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 18 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, N, the parameters of the PDF.\n! 1 <= M,\n! 1 <= N.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n real ( kind = 8 ) xm\n real ( kind = 8 ) xn\n\n a = real ( m, kind = 8 )\n call chi_square_sample ( a, seed, xm )\n\n a = real ( n, kind = 8 )\n call chi_square_sample ( a, seed, xn )\n\n x = real ( n, kind = 8 ) * xm / ( real ( m, kind = 8 ) * xn )\n\n return\nend\nsubroutine f_variance ( m, n, variance )\n\n!*****************************************************************************80\n!\n!! F_VARIANCE returns the variance of the F central PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 10 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, N, the parameters of the PDF.\n! 1 <= M,\n! 1 <= N.\n! Note, however, that the variance is not defined unless 5 <= N.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n real ( kind = 8 ) variance\n\n if ( n < 5 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'F_VARIANCE - Fatal error!'\n write ( *, '(a)' ) ' The variance is not defined for N < 5.'\n stop 1\n end if\n\n variance = real ( 2 * n * n * ( m + n - 2 ), kind = 8 ) / &\n real ( m * ( n - 2 )**2 * ( n - 4 ), kind = 8 )\n\n return\nend\nsubroutine f_noncentral_cdf_values ( n_data, n1, n2, lambda, x, fx )\n\n!*****************************************************************************80\n!\n!! F_NONCENTRAL_CDF_VALUES returns some values of the F CDF test function.\n!\n! Discussion:\n!\n! In Mathematica, the function can be evaluated by:\n!\n! Needs[\"Statistics`ContinuousDistributions`\"]\n! dist = NoncentralFRatioDistribution [ n1, n2, lambda ]\n! CDF [ dist, x ]\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 August 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Milton Abramowitz, Irene Stegun,\n! Handbook of Mathematical Functions,\n! National Bureau of Standards, 1964,\n! LC: QA47.A34,\n! ISBN: 0-486-61272-4.\n!\n! Stephen Wolfram,\n! The Mathematica Book,\n! Fourth Edition,\n! Wolfram Media / Cambridge University Press, 1999.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) N_DATA. The user sets N_DATA to 0\n! before the first call. On each call, the routine increments N_DATA by 1,\n! and returns the corresponding data; when there is no more data, the\n! output value of N_DATA will be 0 again.\n!\n! Output, integer ( kind = 4 ) N1, integer N2, the numerator and denominator\n! degrees of freedom.\n!\n! Output, real ( kind = 8 ) LAMBDA, the noncentrality parameter.\n!\n! Output, real ( kind = 8 ) X, the argument of the function.\n!\n! Output, real ( kind = 8 ) FX, the value of the function.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: n_max = 22\n\n real ( kind = 8 ) fx\n real ( kind = 8 ), save, dimension ( n_max ) :: fx_vec = (/ &\n 0.5000000000000000D+00, &\n 0.6367825323508774D+00, &\n 0.5840916116305482D+00, &\n 0.3234431872392788D+00, &\n 0.4501187879813550D+00, &\n 0.6078881441188312D+00, &\n 0.7059275551414605D+00, &\n 0.7721782003263727D+00, &\n 0.8191049017635072D+00, &\n 0.3170348430749965D+00, &\n 0.4327218008454471D+00, &\n 0.4502696915707327D+00, &\n 0.4261881186594096D+00, &\n 0.6753687206341544D+00, &\n 0.4229108778879005D+00, &\n 0.6927667261228938D+00, &\n 0.3632174676491226D+00, &\n 0.4210054012695865D+00, &\n 0.4266672258818927D+00, &\n 0.4464016600524644D+00, &\n 0.8445888579504827D+00, &\n 0.4339300273343604D+00 /)\n real ( kind = 8 ) lambda\n real ( kind = 8 ), save, dimension ( n_max ) :: lambda_vec = (/ &\n 0.00D+00, &\n 0.00D+00, &\n 0.25D+00, &\n 1.00D+00, &\n 1.00D+00, &\n 1.00D+00, &\n 1.00D+00, &\n 1.00D+00, &\n 1.00D+00, &\n 2.00D+00, &\n 1.00D+00, &\n 1.00D+00, &\n 1.00D+00, &\n 2.00D+00, &\n 1.00D+00, &\n 1.00D+00, &\n 0.00D+00, &\n 1.00D+00, &\n 1.00D+00, &\n 1.00D+00, &\n 1.00D+00, &\n 1.00D+00 /)\n integer ( kind = 4 ) n_data\n integer ( kind = 4 ) n1\n integer ( kind = 4 ), save, dimension ( n_max ) :: n1_vec = (/ &\n 1, 1, 1, 1, &\n 1, 1, 1, 1, &\n 1, 1, 2, 2, &\n 3, 3, 4, 4, &\n 5, 5, 6, 6, &\n 8, 16 /)\n integer ( kind = 4 ) n2\n integer ( kind = 4 ), save, dimension ( n_max ) :: n2_vec = (/ &\n 1, 5, 5, 5, &\n 5, 5, 5, 5, &\n 5, 5, 5, 10, &\n 5, 5, 5, 5, &\n 1, 5, 6, 12, &\n 16, 8 /)\n real ( kind = 8 ) x\n real ( kind = 8 ), save, dimension ( n_max ) :: x_vec = (/ &\n 1.00D+00, &\n 1.00D+00, &\n 1.00D+00, &\n 0.50D+00, &\n 1.00D+00, &\n 2.00D+00, &\n 3.00D+00, &\n 4.00D+00, &\n 5.00D+00, &\n 1.00D+00, &\n 1.00D+00, &\n 1.00D+00, &\n 1.00D+00, &\n 1.00D+00, &\n 1.00D+00, &\n 2.00D+00, &\n 1.00D+00, &\n 1.00D+00, &\n 1.00D+00, &\n 1.00D+00, &\n 2.00D+00, &\n 2.00D+00 /)\n\n if ( n_data < 0 ) then\n n_data = 0\n end if\n\n n_data = n_data + 1\n\n if ( n_max < n_data ) then\n n_data = 0\n n1 = 0\n n2 = 0\n lambda = 0.0D+00\n x = 0.0D+00\n fx = 0.0D+00\n else\n n1 = n1_vec(n_data)\n n2 = n2_vec(n_data)\n lambda = lambda_vec(n_data)\n x = x_vec(n_data)\n fx = fx_vec(n_data)\n end if\n\n return\nend\nfunction f_noncentral_check ( a, m, n )\n\n!*****************************************************************************80\n!\n!! F_NONCENTRAL_CHECK checks the parameters of the F noncentral PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 October 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, a parameter of the PDF.\n!\n! Input, integer ( kind = 4 ) M, N, the parameters of the PDF.\n! 1 <= M,\n! 1 <= N.\n!\n! Output, logical F_NONCENTRAL_CHECK, is TRUE if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n logical f_noncentral_check\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n\n if ( a <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'F_NONCENTRAL_CHECK - Fatal error!'\n write ( *, '(a)' ) ' A <= 0.'\n f_noncentral_check = .false.\n return\n end if\n\n if ( m < 1 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'F_NONCENTRAL_CHECK - Fatal error!'\n write ( *, '(a)' ) ' M < 1.'\n f_noncentral_check = .false.\n return\n end if\n\n if ( n < 1 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'F_NONCENTRAL_CHECK - Fatal error!'\n write ( *, '(a)' ) ' N < 1.'\n f_noncentral_check = .false.\n return\n end if\n\n f_noncentral_check = .true.\n\n return\nend\nsubroutine f_noncentral_mean ( a, m, n, mean )\n\n!*****************************************************************************80\n!\n!! F_NONCENTRAL_MEAN returns the mean of the F noncentral PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 26 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, a parameter of the PDF.\n!\n! Input, integer ( kind = 4 ) M, N, parameters of the PDF.\n! 1 <= M,\n! 1 <= N.\n! Note, however, that the mean is not defined unless 3 <= N.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n integer ( kind = 4 ) m\n real ( kind = 8 ) mean\n integer ( kind = 4 ) n\n\n if ( n < 3 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'F_NONCENTRAL_MEAN - Fatal error!'\n write ( *, '(a)' ) ' The mean is not defined for N < 3.'\n stop 1\n end if\n\n mean = ( real ( m, kind = 8 ) + a ) * real ( n, kind = 8 ) &\n / ( real ( m, kind = 8 ) * real ( n - 2, kind = 8 ) )\n\n return\nend\nsubroutine f_noncentral_variance ( a, m, n, variance )\n\n!*****************************************************************************80\n!\n!! F_NONCENTRAL_VARIANCE returns the variance of the F noncentral PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 26 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, a parameter of the PDF.\n!\n! Input, integer ( kind = 4 ) M, N, parameters of the PDF.\n! 1 <= M,\n! 1 <= N.\n! Note, however, that the variance is not defined unless 5 <= N.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n integer ( kind = 4 ) m\n real ( kind = 8 ) mr\n integer ( kind = 4 ) n\n real ( kind = 8 ) nr\n real ( kind = 8 ) variance\n\n if ( n < 5 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'F_NONCENTRAL_VARIANCE - Fatal error!'\n write ( *, '(a)' ) ' The variance is not defined for N < 5.'\n stop 1\n end if\n\n mr = real ( m, kind = 8 )\n nr = real ( n, kind = 8 )\n\n variance = ( ( mr + a )**2 + 2.0D+00 * ( mr + a ) * nr**2 ) &\n / ( ( nr - 2.0D+00 ) * ( nr - 4.0D+00 ) * mr**2 ) - &\n ( mr + a )**2 * nr**2 / ( ( nr - 2.0D+00 )**2 * mr**2 )\n\n return\nend\nfunction factorial_log ( n )\n\n!*****************************************************************************80\n!\n!! FACTORIAL_LOG returns the logarithm of N factorial.\n!\n! Discussion:\n!\n! N! = Product ( 1 <= I <= N ) I\n!\n! N! = Gamma(N+1).\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the argument of the function.\n! 0 <= N.\n!\n! Output, real ( kind = 8 ) FACTORIAL_LOG, the logarithm of N!.\n!\n implicit none\n\n real ( kind = 8 ) factorial_log\n integer ( kind = 4 ) i\n integer ( kind = 4 ) n\n\n if ( n < 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'FACTORIAL_LOG - Fatal error!'\n write ( *, '(a)' ) ' N < 0.'\n stop 1\n end if\n\n factorial_log = 0.0D+00\n\n do i = 2, n\n factorial_log = factorial_log + log ( real ( i, kind = 8 ) )\n end do\n\n return\nend\nfunction factorial_stirling ( n )\n\n!*****************************************************************************80\n!\n!! FACTORIAL_STIRLING computes Stirling's approximation to N!.\n!\n! Discussion:\n!\n! This routine returns the raw approximation for all nonnegative\n! values of N. If N is less than 0, the value is returned as 0,\n! and if N is 0, the value of 1 is returned. In all other cases,\n! Stirling's formula is used.\n!\n! The factorial function N! is defined by\n!\n! N! = Product ( 1 <= I <= N ) I\n!\n! Stirling's approximation to N! is\n!\n! Stirling ( N ) = sqrt ( 2 * PI * N ) * ( N / E )^N * E^(1/(12*N) )\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the argument of the function.\n!\n! Output, real ( kind = 8 ) FACTORIAL_STIRLING, an approximation to N!.\n!\n implicit none\n\n real ( kind = 8 ), parameter :: e_natural = &\n 2.71828182845904523536028747135266249775724709369995\n real ( kind = 8 ) factorial_stirling\n integer ( kind = 4 ) n\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) value\n\n if ( n < 0 ) then\n\n value = 0.0D+00\n\n else if ( n == 0 ) then\n\n value = 1.0D+00\n\n else\n\n value = sqrt ( 2.0D+00 * pi * real ( n, kind = 8 ) ) &\n * ( real ( n, kind = 8 ) / e_natural )**n &\n * exp ( 1.0D+00 / real ( 12 * n, kind = 8 ) )\n\n end if\n\n factorial_stirling = value\n\n return\nend\nsubroutine fermi_dirac_sample ( u, v, seed, z )\n\n!*****************************************************************************80\n!\n!! FERMI_DIRAC_SAMPLE samples a (continuous) Fermi-Dirac distribution.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 25 January 2008\n!\n! Author:\n!\n! Original BASIC version by Frederick Ruckdeschel.\n! FORTRAN90 version by John Burkardt\n!\n! Reference:\n!\n! Frederick Ruckdeschel,\n! BASIC Scientific Subroutines,\n! Volume I,\n! McGraw Hill, 1980,\n! ISBN: 0-07-054201-5,\n! LC: QA76.95.R82.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) U, V, the parameters of the distribution.\n! The value of U represents the halfway point for the distribution.\n! Half the probability is to the left, and half to the right, of\n! the value U. The value of V controls the shape of the distribution.\n! The ratio U/V determines the relative shape of the distribution.\n! Values of U/V in excess of 100 will risk overflow.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random\n! number generator.\n!\n! Output, real ( kind = 8 ) Z, a sample from the Fermi-Dirac distribution.\n! Output values will be nonnegative, and roughly half of them should\n! be less than or equal to U.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n integer ( kind = 4 ), parameter :: iter_max = 1000\n integer ( kind = 4 ) iter_num\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) u\n real ( kind = 8 ) v\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n real ( kind = 8 ) y1\n real ( kind = 8 ) z\n\n x = r8_uniform_01 ( seed )\n y = 1.0D+00\n a = exp ( 4.0D+00 * u / v )\n b = ( x - 1.0D+00 ) * log ( 1.0D+00 + a )\n\n iter_num = 0\n\n do\n\n y1 = b + log ( a + exp ( y ) )\n\n if ( abs ( y - y1 ) < 0.001D+00 ) then\n exit\n end if\n\n y = y1\n\n iter_num = iter_num + 1\n\n if ( iter_max < iter_num ) then\n exit\n end if\n\n end do\n\n z = v * y1 / 4.0D+00\n\n return\nend\nsubroutine fisher_pdf ( x, kappa, mu, pdf )\n\n!*****************************************************************************80\n!\n!! FISHER_PDF evaluates the Fisher PDF.\n!\n! Discussion:\n!\n! The formula for the PDF is:\n!\n! PDF(KAPPA,MU;X) = C(KAPPA) * exp ( KAPPA * MU' * X )\n!\n! where:\n!\n! 0 <= KAPPA is the concentration parameter,\n! MU is a point on the unit sphere, the mean direction,\n! X is any point on the unit sphere,\n! and C(KAPPA) is a normalization factor:\n!\n! C(KAPPA) = sqrt ( KAPPA ) / ( ( 2 * pi )^(3/2) * I(0.5,KAPPA) )\n!\n! where\n!\n! I(nu,X) is the Bessel function of order NU and argument X.\n!\n! For a fixed value of MU, the value of KAPPA determines the\n! tendency of sample points to tend to be near MU. In particular,\n! KAPPA = 0 corresponds to a uniform distribution of points on the\n! sphere, but as KAPPA increases, the sample points will tend to\n! cluster more closely to MU.\n!\n! The Fisher distribution for points on the unit sphere is\n! analogous to the normal distribution of points on a line,\n! and, more precisely, to the von Mises distribution on a circle.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 07 January 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Kanti Mardia, Peter Jupp,\n! Directional Statistics,\n! Wiley, 2000,\n! LC: QA276.M335\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X(3), the argument of the PDF.\n! X should have unit Euclidean norm, but this routine will\n! automatically work with a normalized version of X.\n!\n! Input, real ( kind = 8 ) KAPPA, the concentration parameter.\n! 0 <= KAPPA is required.\n!\n! Input, real ( kind = 8 ) MU(3), the mean direction.\n! MU should have unit Euclidean norm, but this routine will\n! automatically work with a normalized version of MU.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: nb = 1\n\n real ( kind = 8 ) alpha\n real ( kind = 8 ) arg\n real ( kind = 8 ) b(nb)\n real ( kind = 8 ) cf\n integer ( kind = 4 ) ize\n real ( kind = 8 ) kappa\n real ( kind = 8 ) mu(3)\n real ( kind = 8 ) mu_norm\n integer ( kind = 4 ) ncalc\n real ( kind = 8 ) pdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) x(3)\n real ( kind = 8 ) x_norm\n\n if ( kappa < 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'FISHER_PDF - Fatal error!'\n write ( *, '(a)' ) ' KAPPA must be nonnegative.'\n write ( *, '(a,g14.6)' ) ' Input KAPPA = ', kappa\n stop 1\n end if\n\n if ( kappa == 0.0D+00 ) then\n pdf = 1.0D+00 / ( 4.0D+00 * pi )\n return\n end if\n!\n! Compute the normalization factor CF.\n!\n alpha = 0.5D+00\n ize = 1\n\n call ribesl ( kappa, alpha, nb, ize, b, ncalc )\n\n cf = sqrt ( kappa ) / ( sqrt ( ( 2.0D+00 * pi )**3 ) * b(1) )\n!\n! Normalize MU.\n!\n mu_norm = sqrt ( sum ( mu(1:3)**2 ) )\n\n if ( mu_norm == 0.0D+00 ) then\n pdf = cf\n return\n end if\n!\n! Normalize X.\n!\n x_norm = sqrt ( sum ( x(1:3)**2 ) )\n\n if ( x_norm == 0.0D+00 ) then\n pdf = cf\n return\n end if\n!\n! Evaluate the PDF.\n!\n arg = kappa * dot_product ( x(1:3), mu(1:3) ) / ( x_norm * mu_norm )\n\n pdf = cf * exp ( arg )\n\n return\nend\nsubroutine fisher_sample ( kappa, mu, n, seed, xyz )\n\n!*****************************************************************************80\n!\n!! FISHER_SAMPLE samples the Fisher distribution.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 06 March 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Nicholas Fisher, Toby Lewis, Brian Embleton,\n! Statistical Analysis of Spherical Data,\n! Cambridge, 2003,\n! ISBN13: 978-0521456999,\n! LC: QA276.F489.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) KAPPA, the concentration parameter.\n!\n! Input, real ( kind = 8 ) MU(3), the mean direction.\n! MU should have unit Euclidean norm, but this routine will\n! automatically work with a normalized version of MU.\n!\n! Input, integer ( kind = 4 ) N, the number of samples to choose.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) XYZ(3,N), a sample of the Fisher distribution.\n!\n! Local Parameters:\n!\n! Local, real ( kind = 8 ) ALPHA, BETA, the colatitude (theta) and\n! longitude (phi) of the mean direction.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(3,3)\n real ( kind = 8 ) alpha\n real ( kind = 8 ) beta\n real ( kind = 8 ) kappa\n real ( kind = 8 ) lambda\n real ( kind = 8 ) mu(3)\n real ( kind = 8 ) mu_norm\n real ( kind = 8 ) phi(1:n)\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n integer ( kind = 4 ) seed\n real ( kind = 8 ) theta(1:n)\n real ( kind = 8 ) xyz(3,n)\n\n mu_norm = sqrt ( sum ( mu(1:3)**2 ) )\n\n if ( mu_norm == 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'FISHER_SAMPLE - Fatal error!'\n write ( *, '(a)' ) ' MU(1:3) = 0.'\n stop 1\n end if\n\n alpha = - acos ( mu(3) / mu_norm )\n beta = atan2 ( mu(2), mu(1) )\n\n lambda = exp ( - 2.0D+00 * kappa )\n\n call r8vec_uniform_01 ( n, seed, theta )\n\n if ( kappa == 0.0D+00 ) then\n\n theta(1:n) = 2.0D+00 * asin ( sqrt ( 1.0D+00 - theta(1:n) ) )\n\n else\n\n theta(1:n) = 2.0D+00 * asin ( sqrt ( &\n - log ( theta(1:n) * ( 1.0D+00 - lambda ) + lambda ) &\n / ( 2.0D+00 * kappa ) ) )\n\n end if\n\n call r8vec_uniform_01 ( n, seed, phi )\n\n phi(1:n) = 2.0D+00 * pi * phi(1:n)\n!\n! Compute the unrotated points.\n!\n xyz(1,1:n) = sin ( theta(1:n) ) * cos ( phi(1:n) )\n xyz(2,1:n) = sin ( theta(1:n) ) * sin ( phi(1:n) )\n xyz(3,1:n) = cos ( theta(1:n) )\n!\n! Compute the rotation matrix.\n!\n a(1,1) = cos ( alpha ) * cos ( beta )\n a(2,1) = - sin ( beta )\n a(3,1) = sin ( alpha ) * cos ( beta )\n\n a(1,2) = cos ( alpha ) * sin ( beta )\n a(2,2) = + cos ( beta )\n a(3,2) = sin ( alpha ) * sin ( beta )\n\n a(1,3) = - sin ( alpha )\n a(2,3) = 0.0D+00\n a(3,3) = cos ( alpha )\n!\n! Rotate the points.\n!\n xyz(1:3,1:n) = matmul ( a(1:3,1:3), xyz(1:3,1:n) )\n\n return\nend\nsubroutine fisk_cdf ( x, a, b, c, cdf )\n\n!*****************************************************************************80\n!\n!! FISK_CDF evaluates the Fisk CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < B,\n! 0.0D+00 < C.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( x <= a ) then\n cdf = 0.0D+00\n else\n cdf = 1.0D+00 / ( 1.0D+00 + ( b / ( x - a ) )**c )\n end if\n\n return\nend\nsubroutine fisk_cdf_inv ( cdf, a, b, c, x )\n\n!*****************************************************************************80\n!\n!! FISK_CDF_INV inverts the Fisk CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < B,\n! 0.0D+00 < C.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'FISK_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n if ( cdf <= 0.0D+00 ) then\n x = a\n else if ( cdf < 1.0D+00 ) then\n x = a + b * ( cdf / ( 1.0D+00 - cdf ) )**( 1.0D+00 / c )\n else if ( 1.0D+00 <= cdf ) then\n x = huge ( x )\n end if\n\n return\nend\nfunction fisk_check ( a, b, c )\n\n!*****************************************************************************80\n!\n!! FISK_CHECK checks the parameters of the Fisk PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < B,\n! 0.0D+00 < C.\n!\n! Output, logical FISK_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n logical fisk_check\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'FISK_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B <= 0.'\n fisk_check = .false.\n return\n end if\n\n if ( c <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'FISK_CHECK - Fatal error!'\n write ( *, '(a)' ) ' C <= 0.'\n fisk_check = .false.\n return\n end if\n\n fisk_check = .true.\n\n return\nend\nsubroutine fisk_mean ( a, b, c, mean )\n\n!*****************************************************************************80\n!\n!! FISK_MEAN returns the mean of the Fisk PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 April 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < B,\n! 0.0D+00 < C.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) mean\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) r8_csc\n\n if ( c <= 1.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'FISK_MEAN - Fatal error!'\n write ( *, '(a)' ) ' No mean defined for C <= 1.0'\n stop 1\n end if\n\n mean = a + pi * ( b / c ) * r8_csc ( pi / c )\n\n return\nend\nsubroutine fisk_pdf ( x, a, b, c, pdf )\n\n!*****************************************************************************80\n!\n!! FISK_PDF evaluates the Fisk PDF.\n!\n! Discussion:\n!\n! The Fisk PDF is also known as the Log Logistic PDF.\n!\n! The formula for the PDF is:\n!\n! PDF(A,B,C;X) =\n! ( C / B ) * ( ( X - A ) / B )^( C - 1 ) /\n! ( 1 + ( ( X - A ) / B )^C )^2\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n! A <= X\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < B,\n! 0.0D+00 < C.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) pdf\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n\n if ( x <= a ) then\n\n pdf = 0.0D+00\n\n else\n\n y = ( x - a ) / b\n\n pdf = ( c / b ) * y**( c - 1.0D+00 ) / ( 1.0D+00 + y**c )**2\n\n end if\n\n return\nend\nsubroutine fisk_sample ( a, b, c, seed, x )\n\n!*****************************************************************************80\n!\n!! FISK_SAMPLE samples the Fisk PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < B,\n! 0.0D+00 < C.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call fisk_cdf_inv ( cdf, a, b, c, x )\n\n return\nend\nsubroutine fisk_variance ( a, b, c, variance )\n\n!*****************************************************************************80\n!\n!! FISK_VARIANCE returns the variance of the Fisk PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < B,\n! 0.0D+00 < C.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) g\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) r8_csc\n real ( kind = 8 ) variance\n\n if ( c <= 2.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'FISK_VARIANCE - Fatal error!'\n write ( *, '(a)' ) ' No variance defined for C <= 2.0'\n stop 1\n end if\n\n g = pi / c\n\n variance = b * b &\n * ( 2.0D+00 * g * r8_csc ( 2.0D+00 * g ) - ( g * r8_csc ( g ) )**2 )\n\n return\nend\nsubroutine folded_normal_cdf ( x, a, b, cdf )\n\n!*****************************************************************************80\n!\n!! FOLDED_NORMAL_CDF evaluates the Folded Normal CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n! 0.0D+00 <= X.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 <= A,\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) cdf1\n real ( kind = 8 ) cdf2\n real ( kind = 8 ) x\n real ( kind = 8 ) x1\n real ( kind = 8 ) x2\n\n if ( x < 0.0D+00 ) then\n cdf = 0.0D+00\n else\n x1 = ( x - a ) / b\n call normal_01_cdf ( x1, cdf1 )\n x2 = ( - x - a ) / b\n call normal_01_cdf ( x2, cdf2 )\n cdf = cdf1 - cdf2\n end if\n\n return\nend\nsubroutine folded_normal_cdf_inv ( cdf, a, b, x )\n\n!*****************************************************************************80\n!\n!! FOLDED_NORMAL_CDF_INV inverts the Folded Normal CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 May 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 <= A,\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) X, the argument of the CDF.\n! 0.0D+00 <= X.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) cdf1\n real ( kind = 8 ) cdf2\n real ( kind = 8 ) cdf3\n integer ( kind = 4 ) it\n integer ( kind = 4 ), parameter :: it_max = 100\n real ( kind = 8 ), parameter :: tol = 0.0001D+00\n real ( kind = 8 ) x\n real ( kind = 8 ) x1\n real ( kind = 8 ) x2\n real ( kind = 8 ) x3\n real ( kind = 8 ) xa\n real ( kind = 8 ) xb\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'FOLDED_NORMAL_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n if ( cdf == 0.0D+00 ) then\n x = 0.0D+00\n return\n else if ( 1.0D+00 == cdf ) then\n x = huge ( x )\n return\n end if\n!\n! Find X1, for which the value of CDF will be too small.\n!\n if ( 0.0D+00 <= a ) then\n call normal_cdf_inv ( cdf, a, b, x1 )\n else\n call normal_cdf_inv ( cdf, -a, b, x1 )\n end if\n x1 = max ( x1, 0.0D+00 )\n call folded_normal_cdf ( x1, a, b, cdf1 )\n!\n! Find X2, for which the value of CDF will be too big.\n!\n cdf2 = ( 1.0D+00 - cdf ) / 2.0D+00\n\n call normal_cdf_inv ( cdf2, a, b, xa )\n call normal_cdf_inv ( cdf2, -a, b, xb )\n x2 = max ( abs ( xa ), abs ( xb ) )\n call folded_normal_cdf ( x2, a, b, cdf2 )\n!\n! Now use bisection.\n!\n it = 0\n\n do\n\n it = it + 1\n\n x3 = 0.5D+00 * ( x1 + x2 )\n call folded_normal_cdf ( x3, a, b, cdf3 )\n\n if ( abs ( cdf3 - cdf ) < tol ) then\n x = x3\n exit\n end if\n\n if ( it_max < it ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'FOLDED_NORMAL_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' Iteration limit exceeded.'\n stop 1\n end if\n\n if ( sign ( 1.0D+00, cdf3 - cdf ) == sign ( 1.0D+00, cdf1 - cdf ) ) then\n x1 = x3\n cdf1 = cdf3\n else\n x2 = x3\n cdf2 = cdf3\n end if\n\n end do\n\n return\nend\nfunction folded_normal_check ( a, b )\n\n!*****************************************************************************80\n!\n!! FOLDED_NORMAL_CHECK checks the parameters of the Folded Normal CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 <= A,\n! 0.0D+00 < B.\n!\n! Output, logical FOLDED_NORMAL_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n logical folded_normal_check\n\n if ( a < 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'FOLDED_NORMAL_CHECK - Fatal error!'\n write ( *, '(a)' ) ' A < 0.'\n folded_normal_check = .false.\n return\n end if\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'FOLDED_NORMAL_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B <= 0.'\n folded_normal_check = .false.\n return\n end if\n\n folded_normal_check = .true.\n\n return\nend\nsubroutine folded_normal_mean ( a, b, mean )\n\n!*****************************************************************************80\n!\n!! FOLDED_NORMAL_MEAN returns the mean of the Folded Normal PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 <= A,\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) a2\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) mean\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n\n a2 = a / b\n\n call normal_01_cdf ( a2, cdf )\n\n mean = b * sqrt ( 2.0D+00 / PI ) * exp ( - 0.5D+00 * a2 * a2 ) &\n - a * ( 1.0D+00 - 2.0D+00 * cdf )\n\n return\nend\nsubroutine folded_normal_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! FOLDED_NORMAL_PDF evaluates the Folded Normal PDF.\n!\n! Discussion:\n!\n! The formula for the PDF is:\n!\n! PDF(A;X) = sqrt ( 2 / PI ) * ( 1 / B ) * cosh ( A * X / B^2 )\n! * exp ( - 0.5D+00 * ( X^2 + A^2 ) / B^2 )\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n! 0.0D+00 <= X\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 <= A,\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) pdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) x\n\n if ( x < 0.0D+00 ) then\n pdf = 0.0D+00\n else\n pdf = sqrt ( 2.0D+00 / PI ) * ( 1.0D+00 / b ) * cosh ( a * x / b**2 ) &\n * exp ( - 0.5D+00 * ( x * x + a * a ) / b**2 )\n end if\n\n return\nend\nsubroutine folded_normal_sample ( a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! FOLDED_NORMAL_SAMPLE samples the Folded Normal PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 13 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 <= A,\n! 0.0D+00 < B.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call folded_normal_cdf_inv ( cdf, a, b, x )\n\n return\nend\nsubroutine folded_normal_variance ( a, b, variance )\n\n!*****************************************************************************80\n!\n!! FOLDED_NORMAL_VARIANCE returns the variance of the Folded Normal PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 <= A,\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) mean\n real ( kind = 8 ) variance\n\n call folded_normal_mean ( a, b, mean )\n\n variance = a * a + b * b - mean * mean\n\n return\nend\nsubroutine frechet_cdf ( x, alpha, cdf )\n\n!*****************************************************************************80\n!\n!! FRECHET_CDF evaluates the Frechet CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 September 2008\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) ALPHA, the parameter.\n! It is required that 0.0 < ALPHA.\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) alpha\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( alpha <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'FRECHET_CDF - Fatal error!'\n write ( *, '(a)' ) ' ALPHA <= 0.0.'\n stop 1\n end if\n\n if ( x <= 0.0D+00 ) then\n cdf = 0.0D+00\n else\n cdf = exp ( - 1.0D+00 / x**alpha )\n end if\n\n return\nend\nsubroutine frechet_cdf_inv ( cdf, alpha, x )\n\n!*****************************************************************************80\n!\n!! FRECHET_CDF_INV inverts the Frechet CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 September 2008\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Input, real ( kind = 8 ) ALPHA, the parameter.\n! It is required that 0.0 < ALPHA.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) alpha\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'FRECHET_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n if ( alpha <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'FRECHET_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' ALPHA <= 0.0.'\n stop 1\n end if\n\n if ( cdf == 0.0D+00 ) then\n x = 0.0D+00\n else\n x = ( - 1.0D+00 / log ( cdf ) ) ** ( 1.0D+00 / alpha )\n end if\n\n return\nend\nsubroutine frechet_mean ( alpha, mean )\n\n!*****************************************************************************80\n!\n!! FRECHET_MEAN returns the mean of the Frechet PDF.\n!\n! Discussion:\n!\n! The distribution does not have a mean value unless 1 < ALPHA.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 September 2008\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) ALPHA, the parameter.\n! It is required that 1.0 < ALPHA.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) alpha\n real ( kind = 8 ) mean\n real ( kind = 8 ) r8_gamma\n\n if ( alpha <= 1.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'FRECHET_MEAN - Fatal error!'\n write ( *, '(a)' ) ' Mean does not exist if ALPHA <= 1.'\n stop 1\n end if\n\n mean = r8_gamma ( ( alpha - 1.0D+00 ) / alpha )\n\n return\nend\nsubroutine frechet_pdf ( x, alpha, pdf )\n\n!*****************************************************************************80\n!\n!! FRECHET_PDF evaluates the Frechet PDF.\n!\n! Discussion:\n!\n! PDF(X) = ALPHA * exp ( -1 / X^ALPHA ) / X^(ALPHA+1)\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 September 2008\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Input, real ( kind = 8 ) ALPHA, the parameter.\n! It is required that 0.0 < ALPHA.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) alpha\n real ( kind = 8 ) pdf\n real ( kind = 8 ) x\n\n if ( alpha <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'FRECHET_PDF - Fatal error!'\n write ( *, '(a)' ) ' ALPHA <= 0.0.'\n stop 1\n end if\n\n pdf = alpha * exp ( - 1.0D+00 / x**alpha ) / x**( alpha + 1.0D+00 )\n\n return\nend\nsubroutine frechet_sample ( alpha, seed, x )\n\n!*****************************************************************************80\n!\n!! FRECHET_SAMPLE samples the Frechet PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 September 2008\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) ALPHA, the parameter.\n! It is required that 0.0 < ALPHA.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) alpha\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n if ( alpha <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'FRECHET_SAMPLE - Fatal error!'\n write ( *, '(a)' ) ' ALPHA <= 0.0.'\n stop 1\n end if\n\n cdf = r8_uniform_01 ( seed )\n\n call frechet_cdf_inv ( cdf, alpha, x )\n\n return\nend\nsubroutine frechet_variance ( alpha, variance )\n\n!*****************************************************************************80\n!\n!! FRECHET_VARIANCE returns the variance of the Frechet PDF.\n!\n! Discussion:\n!\n! The PDF does not have a variance unless 2 < ALPHA.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 September 2008\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) ALPHA, the parameter.\n! It is required that 2.0 < ALPHA.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) alpha\n real ( kind = 8 ) mean\n real ( kind = 8 ) r8_gamma\n real ( kind = 8 ) variance\n\n if ( alpha <= 2.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'FRECHET_VARIANCE - Fatal error!'\n write ( *, '(a)' ) ' Variance does not exist if ALPHA <= 2.'\n stop 1\n end if\n\n mean = r8_gamma ( ( alpha - 1.0D+00 ) / alpha )\n\n variance = r8_gamma ( ( alpha - 2.0D+00 ) / alpha ) - mean * mean\n\n return\nend\nsubroutine gamma_cdf ( x, a, b, c, cdf )\n\n!*****************************************************************************80\n!\n!! GAMMA_CDF evaluates the Gamma CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n! A <= X\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < B,\n! 0.0D+00 < C.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) cdf\n real ( kind = 8 ) gamma_inc\n real ( kind = 8 ) p2\n real ( kind = 8 ) x\n real ( kind = 8 ) x2\n\n x2 = ( x - a ) / b\n p2 = c\n\n cdf = gamma_inc ( p2, x2 )\n\n return\nend\nsubroutine gamma_cdf_values ( n_data, mu, sigma, x, fx )\n\n!*****************************************************************************80\n!\n!! GAMMA_CDF_VALUES returns some values of the Gamma CDF.\n!\n! Discussion:\n!\n! In Mathematica, the function can be evaluated by:\n!\n! Needs[\"Statistics`ContinuousDistributions`\"]\n! dist = GammaDistribution [ mu, sigma ]\n! CDF [ dist, x ]\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Milton Abramowitz, Irene Stegun,\n! Handbook of Mathematical Functions,\n! National Bureau of Standards, 1964,\n! LC: QA47.A34,\n! ISBN: 0-486-61272-4.\n!\n! Stephen Wolfram,\n! The Mathematica Book,\n! Fourth Edition,\n! Wolfram Media / Cambridge University Press, 1999.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) N_DATA. The user sets N_DATA to 0\n! before the first call. On each call, the routine increments N_DATA by 1,\n! and returns the corresponding data; when there is no more data, the\n! output value of N_DATA will be 0 again.\n!\n! Output, real ( kind = 8 ) MU, the mean of the distribution.\n!\n! Output, real ( kind = 8 ) SIGMA, the variance of the distribution.\n!\n! Output, real ( kind = 8 ) X, the argument of the function.\n!\n! Output, real ( kind = 8 ) FX, the value of the function.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: n_max = 12\n\n real ( kind = 8 ) fx\n real ( kind = 8 ), save, dimension ( n_max ) :: fx_vec = (/ &\n 0.8646647167633873D+00, &\n 0.9816843611112658D+00, &\n 0.9975212478233336D+00, &\n 0.9996645373720975D+00, &\n 0.6321205588285577D+00, &\n 0.4865828809674080D+00, &\n 0.3934693402873666D+00, &\n 0.3296799539643607D+00, &\n 0.4421745996289254D+00, &\n 0.1911531694619419D+00, &\n 0.6564245437845009D-01, &\n 0.1857593622214067D-01 /)\n real ( kind = 8 ) mu\n real ( kind = 8 ), save, dimension ( n_max ) :: mu_vec = (/ &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.4000000000000000D+01, &\n 0.5000000000000000D+01 /)\n integer ( kind = 4 ) n_data\n real ( kind = 8 ) sigma\n real ( kind = 8 ), save, dimension ( n_max ) :: sigma_vec = (/ &\n 0.5000000000000000D+00, &\n 0.5000000000000000D+00, &\n 0.5000000000000000D+00, &\n 0.5000000000000000D+00, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.4000000000000000D+01, &\n 0.5000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01 /)\n real ( kind = 8 ) x\n real ( kind = 8 ), save, dimension ( n_max ) :: x_vec = (/ &\n 0.1000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.4000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.3000000000000000D+01 /)\n\n if ( n_data < 0 ) then\n n_data = 0\n end if\n\n n_data = n_data + 1\n\n if ( n_max < n_data ) then\n n_data = 0\n mu = 0.0D+00\n sigma = 0.0D+00\n x = 0.0D+00\n fx = 0.0D+00\n else\n mu = mu_vec(n_data)\n sigma = sigma_vec(n_data)\n x = x_vec(n_data)\n fx = fx_vec(n_data)\n end if\n\n return\nend\nfunction gamma_check ( a, b, c )\n\n!*****************************************************************************80\n!\n!! GAMMA_CHECK checks the parameters of the Gamma PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < B,\n! 0.0D+00 < C.\n!\n! Output, logical GAMMA_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n logical gamma_check\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'GAMMA_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B <= 0.'\n write ( *, '(a,g14.6)' ) ' B = ', b\n gamma_check = .false.\n return\n end if\n\n if ( c <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'GAMMA_CHECK - Fatal error!'\n write ( *, '(a)' ) ' C <= 0.'\n write ( *, '(a,g14.6)' ) ' C = ', c\n gamma_check = .false.\n return\n end if\n\n gamma_check = .true.\n\n return\nend\nfunction gamma_inc ( p, x )\n\n!*****************************************************************************80\n!\n!! GAMMA_INC computes the incomplete Gamma function.\n!\n! Discussion:\n!\n! GAMMA_INC(P, 0) = 0,\n! GAMMA_INC(P,Infinity) = 1.\n!\n! GAMMA_INC(P,X) = Integral ( 0 <= T <= X ) T**(P-1) EXP(-T) DT / GAMMA(P).\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 May 2001\n!\n! Author:\n!\n! Original FORTRAN77 version by B L Shea.\n! FORTRAN90 version by John Burkardt\n!\n! Reference:\n!\n! BL Shea,\n! Chi-squared and Incomplete Gamma Integral,\n! Algorithm AS239,\n! Applied Statistics,\n! Volume 37, Number 3, 1988, pages 466-473.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) P, the exponent parameter.\n! 0.0D+00 < P.\n!\n! Input, real ( kind = 8 ) X, the integral limit parameter.\n! If X is less than or equal to 0, GAMMA_INC is returned as 0.\n!\n! Output, real ( kind = 8 ) GAMMA_INC, the value of the function.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) arg\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) cdf\n real ( kind = 8 ), parameter :: exp_arg_min = -88.0D+00\n real ( kind = 8 ) gamma_inc\n real ( kind = 8 ) gamma_log\n real ( kind = 8 ), parameter :: overflow = 1.0D+37\n real ( kind = 8 ) p\n real ( kind = 8 ), parameter :: plimit = 1000.0D+00\n real ( kind = 8 ) pn1\n real ( kind = 8 ) pn2\n real ( kind = 8 ) pn3\n real ( kind = 8 ) pn4\n real ( kind = 8 ) pn5\n real ( kind = 8 ) pn6\n real ( kind = 8 ) rn\n real ( kind = 8 ), parameter :: tol = 1.0D-07\n real ( kind = 8 ) x\n real ( kind = 8 ), parameter :: xbig = 1.0D+08\n\n gamma_inc = 0.0D+00\n\n if ( p <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'GAMMA_INC - Fatal error!'\n write ( *, '(a)' ) ' Parameter P <= 0.'\n stop 1\n end if\n\n if ( x <= 0.0D+00 ) then\n gamma_inc = 0.0D+00\n return\n end if\n!\n! Use a normal approximation if PLIMIT < P.\n!\n if ( plimit < p ) then\n pn1 = 3.0D+00 * sqrt ( p ) * ( ( x / p ) ** ( 1.0D+00 / 3.0D+00 ) &\n + 1.0D+00 / ( 9.0D+00 * p ) - 1.0D+00 )\n call normal_01_cdf ( pn1, cdf )\n gamma_inc = cdf\n return\n end if\n!\n! Is X extremely large compared to P?\n!\n if ( xbig < x ) then\n gamma_inc = 1.0D+00\n return\n end if\n!\n! Use Pearson's series expansion.\n! (P is not large enough to force overflow in the log of Gamma.\n!\n if ( x <= 1.0D+00 .or. x < p ) then\n\n arg = p * log ( x ) - x - gamma_log ( p + 1.0D+00 )\n c = 1.0D+00\n gamma_inc = 1.0D+00\n a = p\n\n do\n\n a = a + 1.0D+00\n c = c * x / a\n gamma_inc = gamma_inc + c\n\n if ( c <= tol ) then\n exit\n end if\n\n end do\n\n arg = arg + log ( gamma_inc )\n\n if ( exp_arg_min <= arg ) then\n gamma_inc = exp ( arg )\n else\n gamma_inc = 0.0D+00\n end if\n\n else\n!\n! Use a continued fraction expansion.\n!\n arg = p * log ( x ) - x - gamma_log ( p )\n a = 1.0D+00 - p\n b = a + x + 1.0D+00\n c = 0.0D+00\n pn1 = 1.0D+00\n pn2 = x\n pn3 = x + 1.0D+00\n pn4 = x * b\n gamma_inc = pn3 / pn4\n\n do\n\n a = a + 1.0D+00\n b = b + 2.0D+00\n c = c + 1.0D+00\n pn5 = b * pn3 - a * c * pn1\n pn6 = b * pn4 - a * c * pn2\n\n if ( 0.0D+00 < abs ( pn6 ) ) then\n\n rn = pn5 / pn6\n\n if ( abs ( gamma_inc - rn ) <= min ( tol, tol * rn ) ) then\n\n arg = arg + log ( gamma_inc )\n\n if ( exp_arg_min <= arg ) then\n gamma_inc = 1.0D+00 - exp ( arg )\n else\n gamma_inc = 1.0D+00\n end if\n\n return\n\n end if\n\n gamma_inc = rn\n\n end if\n\n pn1 = pn3\n pn2 = pn4\n pn3 = pn5\n pn4 = pn6\n!\n! Rescale terms in continued fraction if terms are large.\n!\n if ( overflow <= abs ( pn5 ) ) then\n pn1 = pn1 / overflow\n pn2 = pn2 / overflow\n pn3 = pn3 / overflow\n pn4 = pn4 / overflow\n end if\n\n end do\n\n end if\n\n return\nend\nsubroutine gamma_inc_values ( n_data, a, x, fx )\n\n!*****************************************************************************80\n!\n!! GAMMA_INC_VALUES returns some values of the incomplete Gamma function.\n!\n! Discussion:\n!\n! The (normalized) incomplete Gamma function P(A,X) is defined as:\n!\n! PN(A,X) = 1/Gamma(A) * Integral ( 0 <= T <= X ) T**(A-1) * exp(-T) dT.\n!\n! With this definition, for all A and X,\n!\n! 0 <= PN(A,X) <= 1\n!\n! and\n!\n! PN(A,INFINITY) = 1.0\n!\n! In Mathematica, the function can be evaluated by:\n!\n! 1 - GammaRegularized[A,X]\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 November 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Milton Abramowitz, Irene Stegun,\n! Handbook of Mathematical Functions,\n! National Bureau of Standards, 1964,\n! LC: QA47.A34,\n! ISBN: 0-486-61272-4.\n!\n! Stephen Wolfram,\n! The Mathematica Book,\n! Fourth Edition,\n! Wolfram Media / Cambridge University Press, 1999.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) N_DATA. The user sets N_DATA to 0\n! before the first call. On each call, the routine increments N_DATA by 1,\n! and returns the corresponding data; when there is no more data, the\n! output value of N_DATA will be 0 again.\n!\n! Output, real ( kind = 8 ) A, the parameter of the function.\n!\n! Output, real ( kind = 8 ) X, the argument of the function.\n!\n! Output, real ( kind = 8 ) FX, the value of the function.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: n_max = 20\n\n real ( kind = 8 ) a\n real ( kind = 8 ), save, dimension ( n_max ) :: a_vec = (/ &\n 0.10D+00, &\n 0.10D+00, &\n 0.10D+00, &\n 0.50D+00, &\n 0.50D+00, &\n 0.50D+00, &\n 0.10D+01, &\n 0.10D+01, &\n 0.10D+01, &\n 0.11D+01, &\n 0.11D+01, &\n 0.11D+01, &\n 0.20D+01, &\n 0.20D+01, &\n 0.20D+01, &\n 0.60D+01, &\n 0.60D+01, &\n 0.11D+02, &\n 0.26D+02, &\n 0.41D+02 /)\n real ( kind = 8 ) fx\n real ( kind = 8 ), save, dimension ( n_max ) :: fx_vec = (/ &\n 0.7382350532339351D+00, &\n 0.9083579897300343D+00, &\n 0.9886559833621947D+00, &\n 0.3014646416966613D+00, &\n 0.7793286380801532D+00, &\n 0.9918490284064973D+00, &\n 0.9516258196404043D-01, &\n 0.6321205588285577D+00, &\n 0.9932620530009145D+00, &\n 0.7205974576054322D-01, &\n 0.5891809618706485D+00, &\n 0.9915368159845525D+00, &\n 0.1018582711118352D-01, &\n 0.4421745996289254D+00, &\n 0.9927049442755639D+00, &\n 0.4202103819530612D-01, &\n 0.9796589705830716D+00, &\n 0.9226039842296429D+00, &\n 0.4470785799755852D+00, &\n 0.7444549220718699D+00 /)\n integer ( kind = 4 ) n_data\n real ( kind = 8 ) x\n real ( kind = 8 ), save, dimension ( n_max ) :: x_vec = (/ &\n 0.30D-01, &\n 0.30D+00, &\n 0.15D+01, &\n 0.75D-01, &\n 0.75D+00, &\n 0.35D+01, &\n 0.10D+00, &\n 0.10D+01, &\n 0.50D+01, &\n 0.10D+00, &\n 0.10D+01, &\n 0.50D+01, &\n 0.15D+00, &\n 0.15D+01, &\n 0.70D+01, &\n 0.25D+01, &\n 0.12D+02, &\n 0.16D+02, &\n 0.25D+02, &\n 0.45D+02 /)\n\n if ( n_data < 0 ) then\n n_data = 0\n end if\n\n n_data = n_data + 1\n\n if ( n_max < n_data ) then\n n_data = 0\n a = 0.0D+00\n x = 0.0D+00\n fx = 0.0D+00\n else\n a = a_vec(n_data)\n x = x_vec(n_data)\n fx = fx_vec(n_data)\n end if\n\n return\nend\nfunction gamma_log ( x )\n\n!*****************************************************************************80\n!\n!! GAMMA_LOG calculates the natural logarithm of GAMMA ( X ).\n!\n! Discussion:\n!\n! Computation is based on an algorithm outlined in references 1 and 2.\n! The program uses rational functions that theoretically approximate\n! LOG(GAMMA(X)) to at least 18 significant decimal digits. The\n! approximation for 12 < X is from Hart et al, while approximations\n! for X < 12.0D+00 are similar to those in Cody and Hillstrom,\n! but are unpublished.\n!\n! The accuracy achieved depends on the arithmetic system, the compiler,\n! intrinsic functions, and proper selection of the machine dependent\n! constants.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 16 June 1999\n!\n! Author:\n!\n! Original FORTRAN77 version by William Cody, Laura Stoltz.\n! FORTRAN90 version by John Burkardt.\n!\n! Reference:\n!\n! William Cody, Kenneth Hillstrom,\n! Chebyshev Approximations for the Natural Logarithm of the Gamma Function,\n! Mathematics of Computation,\n! Volume 21, 1967, pages 198-203.\n!\n! Kenneth Hillstrom,\n! ANL/AMD Program ANLC366S, DGAMMA/DLGAMA,\n! May 1969.\n!\n! John Hart, Ward Cheney, Charles Lawson, Hans Maehly,\n! Charles Mesztenyi, John Rice, Henry Thacher, Christoph Witzgall,\n! Computer Approximations,\n! Wiley, 1968.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the Gamma function.\n! X must be positive.\n!\n! Output, real ( kind = 8 ) GAMMA_LOG, the logarithm of the Gamma\n! function of X.\n!\n! Local Parameters:\n!\n! Local, real ( kind = 8 ) BETA, the radix for the floating-point\n! representation.\n!\n! Local, integer MAXEXP, the smallest positive power of BETA that overflows.\n!\n! Local, real ( kind = 8 ) XBIG, the largest argument for which\n! LN(GAMMA(X)) is representable in the machine, the solution to the equation\n! LN(GAMMA(XBIG)) = BETA**MAXEXP.\n!\n! Local, real ( kind = 8 ) FRTBIG, a rough estimate of the fourth root\n! of XBIG.\n!\n! Approximate values for some important machines are:\n!\n! BETA MAXEXP XBIG FRTBIG\n!\n! CRAY-1 (S.P.) 2 8191 9.62D+2461 3.13D+615\n! Cyber 180/855 (S.P.) 2 1070 1.72D+319 6.44D+79\n! IEEE (IBM/XT) (S.P.) 2 128 4.08D+36 1.42D+9\n! IEEE (IBM/XT) (D.P.) 2 1024 2.55D+305 2.25D+76\n! IBM 3033 (D.P.) 16 63 4.29D+73 2.56D+18\n! VAX D-Format (D.P.) 2 127 2.05D+36 1.20D+9\n! VAX G-Format (D.P.) 2 1023 1.28D+305 1.89D+76\n!\n implicit none\n\n real ( kind = 8 ), parameter, dimension ( 7 ) :: c = (/ &\n -1.910444077728D-03, &\n 8.4171387781295D-04, &\n -5.952379913043012D-04, &\n 7.93650793500350248D-04, &\n -2.777777777777681622553D-03, &\n 8.333333333333333331554247D-02, &\n 5.7083835261D-03 /)\n real ( kind = 8 ) corr\n real ( kind = 8 ), parameter :: d1 = -5.772156649015328605195174D-01\n real ( kind = 8 ), parameter :: d2 = 4.227843350984671393993777D-01\n real ( kind = 8 ), parameter :: d4 = 1.791759469228055000094023D+00\n integer ( kind = 4 ) i\n real ( kind = 8 ), parameter :: frtbig = 1.42D+09\n real ( kind = 8 ) gamma_log\n real ( kind = 8 ), parameter, dimension ( 8 ) :: p1 = (/ &\n 4.945235359296727046734888D+00, &\n 2.018112620856775083915565D+02, &\n 2.290838373831346393026739D+03, &\n 1.131967205903380828685045D+04, &\n 2.855724635671635335736389D+04, &\n 3.848496228443793359990269D+04, &\n 2.637748787624195437963534D+04, &\n 7.225813979700288197698961D+03 /)\n real ( kind = 8 ), parameter, dimension ( 8 ) :: p2 = (/ &\n 4.974607845568932035012064D+00, &\n 5.424138599891070494101986D+02, &\n 1.550693864978364947665077D+04, &\n 1.847932904445632425417223D+05, &\n 1.088204769468828767498470D+06, &\n 3.338152967987029735917223D+06, &\n 5.106661678927352456275255D+06, &\n 3.074109054850539556250927D+06 /)\n real ( kind = 8 ), parameter, dimension ( 8 ) :: p4 = (/ &\n 1.474502166059939948905062D+04, &\n 2.426813369486704502836312D+06, &\n 1.214755574045093227939592D+08, &\n 2.663432449630976949898078D+09, &\n 2.940378956634553899906876D+10, &\n 1.702665737765398868392998D+11, &\n 4.926125793377430887588120D+11, &\n 5.606251856223951465078242D+11 /)\n real ( kind = 8 ), parameter :: pnt68 = 0.6796875D+00\n real ( kind = 8 ), parameter, dimension ( 8 ) :: q1 = (/ &\n 6.748212550303777196073036D+01, &\n 1.113332393857199323513008D+03, &\n 7.738757056935398733233834D+03, &\n 2.763987074403340708898585D+04, &\n 5.499310206226157329794414D+04, &\n 6.161122180066002127833352D+04, &\n 3.635127591501940507276287D+04, &\n 8.785536302431013170870835D+03 /)\n real ( kind = 8 ), parameter, dimension ( 8 ) :: q2 = (/ &\n 1.830328399370592604055942D+02, &\n 7.765049321445005871323047D+03, &\n 1.331903827966074194402448D+05, &\n 1.136705821321969608938755D+06, &\n 5.267964117437946917577538D+06, &\n 1.346701454311101692290052D+07, &\n 1.782736530353274213975932D+07, &\n 9.533095591844353613395747D+06 /)\n real ( kind = 8 ), parameter, dimension ( 8 ) :: q4 = (/ &\n 2.690530175870899333379843D+03, &\n 6.393885654300092398984238D+05, &\n 4.135599930241388052042842D+07, &\n 1.120872109616147941376570D+09, &\n 1.488613728678813811542398D+10, &\n 1.016803586272438228077304D+11, &\n 3.417476345507377132798597D+11, &\n 4.463158187419713286462081D+11 /)\n real ( kind = 8 ) res\n real ( kind = 8 ), parameter :: sqrtpi = 0.9189385332046727417803297D+00\n real ( kind = 8 ) x\n real ( kind = 8 ), parameter :: xbig = 4.08D+36\n real ( kind = 8 ) xden\n real ( kind = 8 ) xm1\n real ( kind = 8 ) xm2\n real ( kind = 8 ) xm4\n real ( kind = 8 ) xnum\n real ( kind = 8 ) xsq\n!\n! Return immediately if the argument is out of range.\n!\n if ( x <= 0.0D+00 .or. xbig < x ) then\n gamma_log = huge ( gamma_log )\n return\n end if\n\n if ( x <= epsilon ( x ) ) then\n\n res = -log ( x )\n\n else if ( x <= 1.5D+00 ) then\n\n if ( x < pnt68 ) then\n corr = - log ( x )\n xm1 = x\n else\n corr = 0.0D+00\n xm1 = ( x - 0.5D+00 ) - 0.5D+00\n end if\n\n if ( x <= 0.5D+00 .or. pnt68 <= x ) then\n\n xden = 1.0D+00\n xnum = 0.0D+00\n\n do i = 1, 8\n xnum = xnum * xm1 + p1(i)\n xden = xden * xm1 + q1(i)\n end do\n\n res = corr + ( xm1 * ( d1 + xm1 * ( xnum / xden ) ) )\n\n else\n\n xm2 = ( x - 0.5D+00 ) - 0.5D+00\n xden = 1.0D+00\n xnum = 0.0D+00\n do i = 1, 8\n xnum = xnum * xm2 + p2(i)\n xden = xden * xm2 + q2(i)\n end do\n\n res = corr + xm2 * ( d2 + xm2 * ( xnum / xden ) )\n\n end if\n\n else if ( x <= 4.0D+00 ) then\n\n xm2 = x - 2.0D+00\n xden = 1.0D+00\n xnum = 0.0D+00\n do i = 1, 8\n xnum = xnum * xm2 + p2(i)\n xden = xden * xm2 + q2(i)\n end do\n\n res = xm2 * ( d2 + xm2 * ( xnum / xden ) )\n\n else if ( x <= 12.0D+00 ) then\n\n xm4 = x - 4.0D+00\n xden = - 1.0D+00\n xnum = 0.0D+00\n do i = 1, 8\n xnum = xnum * xm4 + p4(i)\n xden = xden * xm4 + q4(i)\n end do\n\n res = d4 + xm4 * ( xnum / xden )\n\n else\n\n res = 0.0D+00\n\n if ( x <= frtbig ) then\n\n res = c(7)\n xsq = x * x\n\n do i = 1, 6\n res = res / xsq + c(i)\n end do\n\n end if\n\n res = res / x\n corr = log ( x )\n res = res + sqrtpi - 0.5D+00 * corr\n res = res + x * ( corr - 1.0D+00 )\n\n end if\n\n gamma_log = res\n\n return\nend\nfunction gamma_log_int ( n )\n\n!*****************************************************************************80\n!\n!! GAMMA_LOG_INT computes the logarithm of Gamma of an integer N.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 08 July 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the argument of the logarithm of the\n! Gamma function. 0 < N.\n!\n! Output, real ( kind = 8 ) GAMMA_LOG_INT, the logarithm of\n! the Gamma function of N.\n!\n implicit none\n\n real ( kind = 8 ) gamma_log\n real ( kind = 8 ) gamma_log_int\n integer ( kind = 4 ) n\n\n if ( n <= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'GAMMA_LOG_INT - Fatal error!'\n write ( *, '(a,i12)' ) ' Illegal input value of N = ', n\n write ( *, '(a)' ) ' But N must be strictly positive.'\n stop 1\n end if\n\n gamma_log_int = gamma_log ( real ( n, kind = 8 ) )\n\n return\nend\nsubroutine gamma_mean ( a, b, c, mean )\n\n!*****************************************************************************80\n!\n!! GAMMA_MEAN returns the mean of the Gamma PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 12 September 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < B,\n! 0.0D+00 < C.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) mean\n\n mean = a + b * c\n\n return\nend\nsubroutine gamma_pdf ( x, a, b, c, pdf )\n\n!*****************************************************************************80\n!\n!! GAMMA_PDF evaluates the Gamma PDF.\n!\n! Discussion:\n!\n! PDF(A,B,C;X) = exp ( - ( X - A ) / B ) * ( ( X - A ) / B )^(C-1)\n! / ( B * GAMMA ( C ) )\n!\n! GAMMA_PDF(A,B,C;X), where C is an integer, is the Erlang PDF.\n! GAMMA_PDF(A,B,1;X) is the Exponential PDF.\n! GAMMA_PDF(0,2,C/2;X) is the Chi Squared PDF with C degrees of freedom.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n! A <= X\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! A controls the location of the peak; A is often chosen to be 0.0.\n! B is the \"scale\" parameter; 0.0 < B, and is often 1.0.\n! C is the \"shape\" parameter; 0.0 < C, and is often 1.0.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) pdf\n real ( kind = 8 ) r8_gamma\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n\n if ( x <= a ) then\n\n pdf = 0.0D+00\n\n else\n\n y = ( x - a ) / b\n\n pdf = y**( c - 1.0D+00 ) / ( b * r8_gamma ( c ) * exp ( y ) )\n\n end if\n\n return\nend\nsubroutine gamma_sample ( a, b, c, seed, x )\n\n!*****************************************************************************80\n!\n!! GAMMA_SAMPLE samples the Gamma PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 15 September 2000\n!\n! Author:\n!\n! Original FORTRAN77 version by Joachim Ahrens, Ulrich Dieter.\n! FORTRAN90 version by John Burkardt\n!\n! Reference:\n!\n! Joachim Ahrens, Ulrich Dieter,\n! Generating Gamma Variates by a Modified Rejection Technique,\n! Communications of the ACM,\n! Volume 25, Number 1, January 1982, pages 47 - 54.\n!\n! Joachim Ahrens, Ulrich Dieter,\n! Computer Methods for Sampling from Gamma, Beta, Poisson and\n! Binomial Distributions.\n! Computing,\n! Volume 12, 1974, pages 223 - 246.\n!\n! Joachim Ahrens, KD Kohrt, Ulrich Dieter,\n! Algorithm 599,\n! ACM Transactions on Mathematical Software,\n! Volume 9, Number 2, June 1983, pages 255-257.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < B,\n! 0.0D+00 < C.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random\n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ), parameter :: a1 = 0.3333333D+00\n real ( kind = 8 ), parameter :: a2 = - 0.2500030D+00\n real ( kind = 8 ), parameter :: a3 = 0.2000062D+00\n real ( kind = 8 ), parameter :: a4 = - 0.1662921D+00\n real ( kind = 8 ), parameter :: a5 = 0.1423657D+00\n real ( kind = 8 ), parameter :: a6 = - 0.1367177D+00\n real ( kind = 8 ), parameter :: a7 = 0.1233795D+00\n real ( kind = 8 ) b\n real ( kind = 8 ) bcoef\n real ( kind = 8 ) c\n real ( kind = 8 ) co\n real ( kind = 8 ) d\n real ( kind = 8 ) r8_uniform_01\n real ( kind = 8 ) e\n real ( kind = 8 ), parameter :: e1 = 1.0D+00\n real ( kind = 8 ), parameter :: e2 = 0.4999897D+00\n real ( kind = 8 ), parameter :: e3 = 0.1668290D+00\n real ( kind = 8 ), parameter :: e4 = 0.0407753D+00\n real ( kind = 8 ), parameter :: e5 = 0.0102930D+00\n real ( kind = 8 ), parameter :: euler = 2.71828182845904D+00\n real ( kind = 8 ) p\n real ( kind = 8 ) q\n real ( kind = 8 ) q0\n real ( kind = 8 ), parameter :: q1 = 0.04166669D+00\n real ( kind = 8 ), parameter :: q2 = 0.02083148D+00\n real ( kind = 8 ), parameter :: q3 = 0.00801191D+00\n real ( kind = 8 ), parameter :: q4 = 0.00144121D+00\n real ( kind = 8 ), parameter :: q5 = - 0.00007388D+00\n real ( kind = 8 ), parameter :: q6 = 0.00024511D+00\n real ( kind = 8 ), parameter :: q7 = 0.00024240D+00\n real ( kind = 8 ) r\n real ( kind = 8 ) s\n integer ( kind = 4 ) seed\n real ( kind = 8 ) si\n real ( kind = 8 ) s2\n real ( kind = 8 ) t\n real ( kind = 8 ) u\n real ( kind = 8 ) v\n real ( kind = 8 ) w\n real ( kind = 8 ) x\n!\n! Allow C = 0.\n!\n if ( c == 0.0D+00 ) then\n x = a\n return\n end if\n!\n! C < 1.\n!\n if ( c < 1.0D+00 ) then\n\n do\n\n u = r8_uniform_01 ( seed )\n t = 1.0D+00 + c / euler\n p = u * t\n\n call exponential_01_sample ( seed, s )\n\n if ( p < 1.0D+00 ) then\n x = exp ( log ( p ) / c )\n if ( x <= s ) then\n exit\n end if\n else\n x = - log ( ( t - p ) / c )\n if ( ( 1.0D+00 - c ) * log ( x ) <= s ) then\n exit\n end if\n end if\n\n end do\n\n x = a + b * x\n return\n!\n! 1 <= C.\n!\n else\n\n s2 = c - 0.5D+00\n s = sqrt ( c - 0.5D+00 )\n d = sqrt ( 32.0D+00 ) - 12.0D+00 * sqrt ( c - 0.5D+00 )\n\n call normal_01_sample ( seed, t )\n x = ( sqrt ( c - 0.5D+00 ) + 0.5D+00 * t )**2\n\n if ( 0.0D+00 <= t ) then\n x = a + b * x\n return\n end if\n\n u = r8_uniform_01 ( seed )\n\n if ( d * u <= t**3 ) then\n x = a + b * x\n return\n end if\n\n r = 1.0D+00 / c\n\n q0 = ( ( ( ( ( ( &\n q7 * r &\n + q6 ) * r &\n + q5 ) * r &\n + q4 ) * r &\n + q3 ) * r &\n + q2 ) * r &\n + q1 ) * r\n\n if ( c <= 3.686D+00 ) then\n bcoef = 0.463D+00 + s - 0.178D+00 * s2\n si = 1.235D+00\n co = 0.195D+00 / s - 0.079D+00 + 0.016D+00 * s\n else if ( c <= 13.022D+00 ) then\n bcoef = 1.654D+00 + 0.0076D+00 * s2\n si = 1.68D+00 / s + 0.275D+00\n co = 0.062D+00 / s + 0.024D+00\n else\n bcoef = 1.77D+00\n si = 0.75D+00\n co = 0.1515D+00 / s\n end if\n\n if ( 0.0D+00 < sqrt ( c - 0.5D+00 ) + 0.5D+00 * t ) then\n\n v = 0.5D+00 * t / s\n\n if ( 0.25D+00 < abs ( v ) ) then\n q = q0 - s * t + 0.25D+00 * t * t + 2.0D+00 * s2 * log ( 1.0D+00 + v )\n else\n q = q0 + 0.5D+00 * t**2 * ( ( ( ( ( ( &\n a7 * v &\n + a6 ) * v &\n + a5 ) * v &\n + a4 ) * v &\n + a3 ) * v &\n + a2 ) * v &\n + a1 ) * v\n end if\n\n if ( log ( 1.0D+00 - u ) <= q ) then\n x = a + b * x\n return\n end if\n\n end if\n\n do\n\n call exponential_01_sample ( seed, e )\n\n u = r8_uniform_01 ( seed )\n\n u = 2.0D+00 * u - 1.0D+00\n t = bcoef + sign ( si * e, u )\n\n if ( -0.7187449D+00 <= t ) then\n\n v = 0.5D+00 * t / s\n\n if ( 0.25D+00 < abs ( v ) ) then\n q = q0 - s * t + 0.25D+00 * t**2 + 2.0D+00 * s2 * log ( 1.0D+00 + v )\n else\n q = q0 + 0.5D+00 * t**2 * ( ( ( ( ( ( &\n a7 * v &\n + a6 ) * v &\n + a5 ) * v &\n + a4 ) * v &\n + a3 ) * v &\n + a2 ) * v &\n + a1 ) * v\n end if\n\n if ( 0.0D+00 < q ) then\n\n if ( 0.5D+00 < q ) then\n w = exp ( q ) - 1.0D+00\n else\n w = ( ( ( ( &\n e5 * q &\n + e4 ) * q &\n + e3 ) * q &\n + e2 ) * q &\n + e1 ) * q\n end if\n\n if ( co * abs ( u ) <= w * exp ( e - 0.5D+00 * t**2 ) ) then\n x = a + b * ( s + 0.5D+00 * t )**2\n return\n end if\n\n end if\n\n end if\n\n end do\n\n end if\n\n return\nend\nsubroutine gamma_variance ( a, b, c, variance )\n\n!*****************************************************************************80\n!\n!! GAMMA_VARIANCE returns the variance of the Gamma PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < B,\n! 0.0D+00 < C.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) variance\n\n variance = b * b * c\n\n return\nend\nsubroutine genlogistic_cdf ( x, a, b, c, cdf )\n\n!*****************************************************************************80\n!\n!! GENLOGISTIC_CDF evaluates the Generalized Logistic CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 03 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < B,\n! 0.0D+00 < C.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n\n y = ( x - a ) / b\n\n cdf = 1.0D+00 / ( 1.0D+00 + exp ( - y ) )**c\n\n return\nend\nsubroutine genlogistic_cdf_inv ( cdf, a, b, c, x )\n\n!*****************************************************************************80\n!\n!! GENLOGISTIC_CDF_INV inverts the Generalized Logistic CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 03 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < B,\n! 0.0D+00 < C.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'GENLOGISTIC_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n if ( cdf == 0.0D+00 ) then\n x = - huge ( x )\n else if ( cdf < 1.0D+00 ) then\n x = a - b * log ( cdf**( - 1.0D+00 / c ) - 1.0D+00 )\n else if ( 1.0D+00 == cdf ) then\n x = huge ( x )\n end if\n\n return\nend\nfunction genlogistic_check ( a, b, c )\n\n!*****************************************************************************80\n!\n!! GENLOGISTIC_CHECK checks the parameters of the Generalized Logistic CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < B,\n! 0.0D+00 < C.\n!\n! Output, logical GENLOGISTIC_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n logical genlogistic_check\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'GENLOGISTIC_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B <= 0.'\n genlogistic_check = .false.\n return\n end if\n\n if ( c <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'GENLOGISTIC_CHECK - Fatal error!'\n write ( *, '(a)' ) ' C <= 0.'\n genlogistic_check = .false.\n return\n end if\n\n genlogistic_check = .true.\n\n return\nend\nsubroutine genlogistic_mean ( a, b, c, mean )\n\n!*****************************************************************************80\n!\n!! GENLOGISTIC_MEAN returns the mean of the Generalized Logistic PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 03 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < B,\n! 0.0D+00 < C.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) digamma\n real ( kind = 8 ) euler_constant\n real ( kind = 8 ) mean\n\n mean = a + b * ( euler_constant ( ) + digamma ( c ) )\n\n return\nend\nsubroutine genlogistic_pdf ( x, a, b, c, pdf )\n\n!*****************************************************************************80\n!\n!! GENLOGISTIC_PDF evaluates the Generalized Logistic PDF.\n!\n! Discussion:\n!\n! PDF(A,B,C;X) = ( C / B ) * exp ( ( A - X ) / B ) /\n! ( ( 1 + exp ( ( A - X ) / B ) )^(C+1) )\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 03 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < B,\n! 0.0D+00 < C.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) pdf\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n\n y = ( x - a ) / b\n\n pdf = ( c / b ) * exp ( - y ) / ( 1.0D+00 + exp ( - y ) )**( c + 1.0D+00 )\n\n return\nend\nsubroutine genlogistic_sample ( a, b, c, seed, x )\n\n!*****************************************************************************80\n!\n!! GENLOGISTIC_SAMPLE samples the Generalized Logistic PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 03 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < B,\n! 0.0D+00 < C.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random\n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call genlogistic_cdf_inv ( cdf, a, b, c, x )\n\n return\nend\nsubroutine genlogistic_variance ( a, b, c, variance )\n\n!*****************************************************************************80\n!\n!! GENLOGISTIC_VARIANCE returns the variance of the Generalized Logistic PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 03 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < B,\n! 0.0D+00 < C.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) trigamma\n real ( kind = 8 ) variance\n\n variance = b * b * ( pi * pi / 6.0D+00 + trigamma ( c ) )\n\n return\nend\nsubroutine geometric_cdf ( x, a, cdf )\n\n!*****************************************************************************80\n!\n!! GEOMETRIC_CDF evaluates the Geometric CDF.\n!\n! Discussion:\n!\n! CDF(X,P) is the probability that there will be at least one\n! successful trial in the first X Bernoulli trials, given that\n! the probability of success in a single trial is P.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 January 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X, the maximum number of trials.\n!\n! Input, real ( kind = 8 ) A, the probability of success on one trial.\n! 0.0D+00 <= A <= 1.0.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) cdf\n integer ( kind = 4 ) x\n\n if ( x <= 0 ) then\n cdf = 0.0D+00\n else if ( a == 0.0D+00 ) then\n cdf = 0.0D+00\n else if ( a == 1.0D+00 ) then\n cdf = 1.0D+00\n else\n cdf = 1.0D+00 - ( 1.0D+00 - a )**x\n end if\n\n return\nend\nsubroutine geometric_cdf_inv ( cdf, a, x )\n\n!*****************************************************************************80\n!\n!! GEOMETRIC_CDF_INV inverts the Geometric CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 26 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0D+00\n!\n! Input, real ( kind = 8 ) A, the probability of success on one trial.\n! 0.0D+00 <= A <= 1.0.\n!\n! Output, integer ( kind = 4 ) X, the corresponding value of X.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) cdf\n integer ( kind = 4 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'GEOMETRIC_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n if ( a == 1.0D+00 ) then\n x = 1\n else if ( a == 0.0D+00 ) then\n x = huge ( x )\n else\n x = 1 + int ( log ( 1.0D+00 - cdf ) / log ( 1.0D+00 - a ) )\n end if\n\n return\nend\nsubroutine geometric_cdf_values ( n_data, x, p, cdf )\n\n!*****************************************************************************80\n!\n!! GEOMETRIC_CDF_VALUES returns values of the geometric CDF.\n!\n! Discussion:\n!\n! The geometric or Pascal probability density function gives the\n! probability that the first success will happen on the X-th Bernoulli\n! trial, given that the probability of a success on a single trial is P.\n!\n! The value of CDF ( X, P ) is the probability that the first success\n! will happen on or before the X-th trial.\n!\n! In Mathematica, the function can be evaluated by:\n!\n! Needs[\"Statistics`DiscreteDistributions`]\n! dist = GeometricDistribution [ p ]\n! CDF [ dist, x ]\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 August 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Stephen Wolfram,\n! The Mathematica Book,\n! Fourth Edition,\n! Wolfram Media / Cambridge University Press, 1999.\n!\n! Daniel Zwillinger, Stephen Kokoska,\n! CRC Standard Probability and Statistics Tables and Formulae,\n! Chapman and Hall / CRC Press, 2000.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) N_DATA. The user sets N_DATA to 0\n! before the first call. On each call, the routine increments N_DATA by 1,\n! and returns the corresponding data; when there is no more data, the\n! output value of N_DATA will be 0 again.\n!\n! Output, integer ( kind = 4 ) X, the number of trials.\n!\n! Output, real ( kind = 8 ) P, the probability of success\n! on one trial.\n!\n! Output, real ( kind = 8 ) CDF, the cumulative density function.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: n_max = 14\n\n real ( kind = 8 ) cdf\n real ( kind = 8 ), save, dimension ( n_max ) :: cdf_vec = (/ &\n 0.1900000000000000D+00, &\n 0.2710000000000000D+00, &\n 0.3439000000000000D+00, &\n 0.6861894039100000D+00, &\n 0.3600000000000000D+00, &\n 0.4880000000000000D+00, &\n 0.5904000000000000D+00, &\n 0.9141006540800000D+00, &\n 0.7599000000000000D+00, &\n 0.8704000000000000D+00, &\n 0.9375000000000000D+00, &\n 0.9843750000000000D+00, &\n 0.9995117187500000D+00, &\n 0.9999000000000000D+00 /)\n integer ( kind = 4 ) n_data\n real ( kind = 8 ) p\n real ( kind = 8 ), save, dimension ( n_max ) :: p_vec = (/ &\n 0.1D+00, &\n 0.1D+00, &\n 0.1D+00, &\n 0.1D+00, &\n 0.2D+00, &\n 0.2D+00, &\n 0.2D+00, &\n 0.2D+00, &\n 0.3D+00, &\n 0.4D+00, &\n 0.5D+00, &\n 0.5D+00, &\n 0.5D+00, &\n 0.9D+00 /)\n integer ( kind = 4 ) x\n integer ( kind = 4 ), save, dimension ( n_max ) :: x_vec = (/ &\n 1, 2, 3, 10, 1, &\n 2, 3, 10, 3, 3, &\n 3, 5, 10, 3 /)\n\n if ( n_data < 0 ) then\n n_data = 0\n end if\n\n n_data = n_data + 1\n\n if ( n_max < n_data ) then\n n_data = 0\n x = 0\n p = 0.0D+00\n cdf = 0.0D+00\n else\n x = x_vec(n_data)\n p = p_vec(n_data)\n cdf = cdf_vec(n_data)\n end if\n\n return\nend\nfunction geometric_check ( a )\n\n!*****************************************************************************80\n!\n!! GEOMETRIC_CHECK checks the parameter of the Geometric CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the probability of success on one trial.\n! 0.0D+00 <= A <= 1.0.\n!\n! Output, logical GEOMETRIC_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n logical geometric_check\n\n if ( a < 0.0D+00 .or. 1.0D+00 < a ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'GEOMETRIC_CHECK - Fatal error!'\n write ( *, '(a)' ) ' A < 0 or 1 < A.'\n geometric_check = .false.\n return\n end if\n\n geometric_check = .true.\n\n return\nend\nsubroutine geometric_mean ( a, mean )\n\n!*****************************************************************************80\n!\n!! GEOMETRIC_MEAN returns the mean of the Geometric PDF.\n!\n! Discussion:\n!\n! MEAN is the expected value of the number of trials required\n! to obtain a single success.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 06 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the probability of success on one trial.\n! 0.0D+00 <= A <= 1.0.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) mean\n\n mean = 1.0D+00 / a\n\n return\nend\nsubroutine geometric_pdf ( x, a, pdf )\n\n!*****************************************************************************80\n!\n!! GEOMETRIC_PDF evaluates the Geometric PDF.\n!\n! Discussion:\n!\n! PDF(A;X) = A * ( 1 - A )^(X-1)\n!\n! PDF(A;X) is the probability that exactly X Bernoulli trials, each\n! with probability of success A, will be required to achieve\n! a single success.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 January 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X, the number of trials.\n! 0 < X\n!\n! Input, real ( kind = 8 ) A, the probability of success on one trial.\n! 0.0D+00 <= A <= 1.0.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) pdf\n integer ( kind = 4 ) x\n!\n! Special cases.\n!\n if ( x < 1 ) then\n\n pdf = 0.0D+00\n\n else if ( a == 0.0D+00 ) then\n\n pdf = 0.0D+00\n\n else if ( a == 1.0D+00 ) then\n\n if ( x == 1 ) then\n pdf = 1.0D+00\n else\n pdf = 0.0D+00\n end if\n\n else\n\n pdf = a * ( 1.0D+00 - a )**( x - 1 )\n\n end if\n\n return\nend\nsubroutine geometric_sample ( a, seed, x )\n\n!*****************************************************************************80\n!\n!! GEOMETRIC_SAMPLE samples the Geometric PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 06 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the probability of success on one trial.\n! 0.0D+00 <= A <= 1.0.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random\n! number generator.\n!\n! Output, integer ( kind = 4 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n integer ( kind = 4 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call geometric_cdf_inv ( cdf, a, x )\n\n return\nend\nsubroutine geometric_variance ( a, variance )\n\n!*****************************************************************************80\n!\n!! GEOMETRIC_VARIANCE returns the variance of the Geometric PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 06 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the probability of success on one trial.\n! 0.0D+00 <= A <= 1.0.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) variance\n\n variance = ( 1.0D+00 - a ) / ( a * a )\n\n return\nend\nsubroutine gompertz_cdf ( x, a, b, cdf )\n\n!*****************************************************************************80\n!\n!! GOMPERTZ_CDF evaluates the Gompertz CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 19 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Norman Johnson, Samuel Kotz, Balakrishnan,\n! Continuous Univariate Distributions, second edition,\n! Wiley, 1994,\n! QA273.6.J6\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 1 < A, 0 < B.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( x <= 0.0D+00 ) then\n cdf = 0.0D+00\n else\n cdf = 1.0D+00 - exp ( - b * ( a**x - 1.0D+00 ) / log ( a ) )\n end if\n\n return\nend\nsubroutine gompertz_cdf_inv ( cdf, a, b, x )\n\n!*****************************************************************************80\n!\n!! GOMPERTZ_CDF_INV inverts the Gompertz CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 19 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Norman Johnson, Samuel Kotz, Balakrishnan,\n! Continuous Univariate Distributions, second edition,\n! Wiley, 1994,\n! QA273.6.J6\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 1 < A, 0 < B.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'GOMPERTZ_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n if ( cdf < 1.0D+00 ) then\n x = log ( 1.0D+00 - log ( 1.0D+00 - cdf ) * log ( a ) / b ) / log ( a )\n else\n x = huge ( x )\n end if\n\n return\nend\nfunction gompertz_check ( a, b )\n\n!*****************************************************************************80\n!\n!! GOMPERTZ_CHECK checks the parameters of the Gompertz PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Norman Johnson, Samuel Kotz, Balakrishnan,\n! Continuous Univariate Distributions, second edition,\n! Wiley, 1994,\n! QA273.6.J6\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 1 < A, 0 < B.\n!\n! Output, logical GOMPERTZ_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n logical gompertz_check\n\n if ( a <= 1.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'GOMPERTZ_CHECK - Fatal error!'\n write ( *, '(a)' ) ' A <= 1.0!'\n gompertz_check = .false.\n return\n end if\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'GOMPERTZ_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B <= 0.0!'\n gompertz_check = .false.\n return\n end if\n\n gompertz_check = .true.\n\n return\nend\nsubroutine gompertz_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! GOMPERTZ_PDF evaluates the Gompertz PDF.\n!\n! Discussion:\n!\n! PDF(A,B;X) = B * A^X / exp ( B * ( A^X - 1 ) / log ( A ) )\n!\n! for\n!\n! 0.0 <= X\n! 1.0 < A\n! 0.0 < B\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 19 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Norman Johnson, Samuel Kotz, Balakrishnan,\n! Continuous Univariate Distributions, second edition,\n! Wiley, 1994,\n! QA273.6.J6\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 1 < A, 0 < B.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) pdf\n real ( kind = 8 ) x\n\n if ( x < 0.0D+00 ) then\n\n pdf = 0.0D+00\n\n else if ( 1.0D+00 < a ) then\n\n pdf = exp ( log ( b ) + x * log ( a ) &\n - ( b / log ( a ) ) * ( a**x - 1.0D+00 ) )\n\n end if\n\n return\nend\nsubroutine gompertz_sample ( a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! GOMPERTZ_SAMPLE samples the Gompertz PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 19 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 1 < A, 0 < B.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random\n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call gompertz_cdf_inv ( cdf, a, b, x )\n\n return\nend\nsubroutine gumbel_cdf ( x, cdf )\n\n!*****************************************************************************80\n!\n!! GUMBEL_CDF evaluates the Gumbel CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 03 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n cdf = exp ( - exp ( - x ) )\n\n return\nend\nsubroutine gumbel_cdf_inv ( cdf, x )\n\n!*****************************************************************************80\n!\n!! GUMBEL_CDF_INV inverts the Gumbel CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 03 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'GUMBEL_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n x = - log ( - log ( cdf ) )\n\n return\nend\nsubroutine gumbel_mean ( mean )\n\n!*****************************************************************************80\n!\n!! GUMBEL_MEAN returns the mean of the Gumbel PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 03 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) euler_constant\n real ( kind = 8 ) mean\n\n mean = euler_constant ( )\n\n return\nend\nsubroutine gumbel_pdf ( x, pdf )\n\n!*****************************************************************************80\n!\n!! GUMBEL_PDF evaluates the Gumbel PDF.\n!\n! Discussion:\n!\n! PDF(X) = exp ( -X ) * exp ( - exp ( -X ) ).\n!\n! GUMBEL_PDF(X) = EXTREME_PDF(0,1;X)\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 03 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Eric Weisstein, editor,\n! CRC Concise Encylopedia of Mathematics,\n! CRC Press, 1998.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) pdf\n real ( kind = 8 ) x\n\n pdf = exp ( - x - exp ( - x ) )\n\n return\nend\nsubroutine gumbel_sample ( seed, x )\n\n!*****************************************************************************80\n!\n!! GUMBEL_SAMPLE samples the Gumbel PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 03 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random\n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call gumbel_cdf_inv ( cdf, x )\n\n return\nend\nsubroutine gumbel_variance ( variance )\n\n!*****************************************************************************80\n!\n!! GUMBEL_VARIANCE returns the variance of the Gumbel PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 03 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) variance\n\n variance = pi * pi / 6.0D+00\n\n return\nend\nsubroutine half_normal_cdf ( x, a, b, cdf )\n\n!*****************************************************************************80\n!\n!! HALF_NORMAL_CDF evaluates the Half Normal CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) cdf2\n real ( kind = 8 ) x\n\n if ( x <= a ) then\n cdf = 0.0D+00\n else\n call normal_cdf ( x, a, b, cdf2 )\n cdf = 2.0D+00 * cdf2 - 1.0D+00\n end if\n\n return\nend\nsubroutine half_normal_cdf_inv ( cdf, a, b, x )\n\n!*****************************************************************************80\n!\n!! HALF_NORMAL_CDF_INV inverts the Half Normal CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) cdf2\n real ( kind = 8 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'HALF_NORMAL_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n cdf2 = 0.5D+00 * ( cdf + 1.0D+00 )\n\n call normal_cdf_inv ( cdf2, a, b, x )\n\n return\nend\nfunction half_normal_check ( a, b )\n\n!*****************************************************************************80\n!\n!! HALF_NORMAL_CHECK checks the parameters of the Half Normal PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 22 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, logical HALF_NORMAL_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n logical half_normal_check\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'HALF_NORMAL_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B <= 0.'\n half_normal_check = .false.\n return\n end if\n\n half_normal_check = .true.\n\n return\nend\nsubroutine half_normal_mean ( a, b, mean )\n\n!*****************************************************************************80\n!\n!! HALF_NORMAL_MEAN returns the mean of the Half Normal PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) mean\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n\n mean = a + b * sqrt ( 2.0D+00 / pi )\n\n return\nend\nsubroutine half_normal_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! HALF_NORMAL_PDF evaluates the Half Normal PDF.\n!\n! Discussion:\n!\n! PDF(A,B;X) =\n! sqrt ( 2 / PI ) * ( 1 / B ) * exp ( - 0.5D+00 * ( ( X - A ) / B )^2 )\n!\n! for A <= X\n!\n! The Half Normal PDF is a special case of both the Chi PDF and the\n! Folded Normal PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n! A <= X\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) pdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n\n if ( x <= a ) then\n\n pdf = 0.0D+00\n\n else\n\n y = ( x - a ) / b\n\n pdf = sqrt ( 2.0D+00 / pi ) * ( 1.0D+00 / b ) * exp ( - 0.5D+00 * y * y )\n\n end if\n\n return\nend\nsubroutine half_normal_sample ( a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! HALF_NORMAL_SAMPLE samples the Half Normal PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random\n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call half_normal_cdf_inv ( cdf, a, b, x )\n\n return\nend\nsubroutine half_normal_variance ( a, b, variance )\n\n!*****************************************************************************80\n!\n!! HALF_NORMAL_VARIANCE returns the variance of the Half Normal PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 April 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) variance\n\n variance = b * b * ( 1.0D+00 - 2.0D+00 / pi )\n\n return\nend\nsubroutine hypergeometric_cdf ( x, n, m, l, cdf )\n\n!*****************************************************************************80\n!\n!! HYPERGEOMETRIC_CDF evaluates the Hypergeometric CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 13 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X, the argument of the CDF.\n!\n! Input, integer ( kind = 4 ) N, the number of balls selected.\n! 0 <= N <= L.\n!\n! Input, integer ( kind = 4 ) M, the number of white balls.\n! 0 <= M <= L.\n!\n! Input, integer ( kind = 4 ) L, the number of balls to select from.\n! 0 <= L.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) cdf\n real ( kind = 8 ) c1_log\n real ( kind = 8 ) c2_log\n integer ( kind = 4 ) l\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n real ( kind = 8 ) pdf\n integer ( kind = 4 ) x\n integer ( kind = 4 ) x2\n\n call binomial_coef_log ( l - m, n, c1_log )\n call binomial_coef_log ( l, n, c2_log )\n\n pdf = exp ( c1_log - c2_log )\n cdf = pdf\n\n do x2 = 0, x - 1\n\n pdf = pdf * real ( ( m - x2 ) * ( n - x2 ), kind = 8 ) &\n / real ( ( x2 + 1 ) * ( l - m - n + x2 + 1 ), kind = 8 )\n\n cdf = cdf + pdf\n\n end do\n\n return\nend\nsubroutine hypergeometric_cdf_values ( n_data, sam, suc, pop, n, fx )\n\n!*****************************************************************************80\n!\n!! HYPERGEOMETRIC_CDF_VALUES returns some values of the hypergeometric CDF.\n!\n! Discussion:\n!\n! CDF(X)(A,B) is the probability of at most X successes in A trials,\n! given that the probability of success on a single trial is B.\n!\n! In Mathematica, the function can be evaluated by:\n!\n! Needs[\"Statistics`DiscreteDistributions`]\n! dist = HypergeometricDistribution [ sam, suc, pop ]\n! CDF [ dist, n ]\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Milton Abramowitz, Irene Stegun,\n! Handbook of Mathematical Functions,\n! National Bureau of Standards, 1964,\n! LC: QA47.A34,\n! ISBN: 0-486-61272-4.\n!\n! Stephen Wolfram,\n! The Mathematica Book,\n! Fourth Edition,\n! Wolfram Media / Cambridge University Press, 1999.\n!\n! Daniel Zwillinger,\n! CRC Standard Mathematical Tables and Formulae,\n! 30th Edition, CRC Press, 1996, pages 651-652.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) N_DATA. The user sets N_DATA to 0\n! before the first call. On each call, the routine increments N_DATA by 1,\n! and returns the corresponding data; when there is no more data, the\n! output value of N_DATA will be 0 again.\n!\n! Output, integer ( kind = 4 ) SAM, integer SUC, integer POP, the sample\n! size, success size, and population parameters of the function.\n!\n! Output, integer ( kind = 4 ) N, the argument of the function.\n!\n! Output, real ( kind = 8 ) FX, the value of the function.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: n_max = 16\n\n real ( kind = 8 ) fx\n real ( kind = 8 ), save, dimension ( n_max ) :: fx_vec = (/ &\n 0.6001858177500578D-01, &\n 0.2615284665839845D+00, &\n 0.6695237889132748D+00, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.5332595856827856D+00, &\n 0.1819495964117640D+00, &\n 0.4448047017527730D-01, &\n 0.9999991751316731D+00, &\n 0.9926860896560750D+00, &\n 0.8410799901444538D+00, &\n 0.3459800113391901D+00, &\n 0.0000000000000000D+00, &\n 0.2088888139634505D-02, &\n 0.3876752992448843D+00, &\n 0.9135215248834896D+00 /)\n integer ( kind = 4 ) n\n integer ( kind = 4 ) n_data\n integer ( kind = 4 ), save, dimension ( n_max ) :: n_vec = (/ &\n 7, 8, 9, 10, &\n 6, 6, 6, 6, &\n 6, 6, 6, 6, &\n 0, 0, 0, 0 /)\n integer ( kind = 4 ) pop\n integer ( kind = 4 ), save, dimension ( n_max ) :: pop_vec = (/ &\n 100, 100, 100, 100, &\n 100, 100, 100, 100, &\n 100, 100, 100, 100, &\n 90, 200, 1000, 10000 /)\n integer ( kind = 4 ) sam\n integer ( kind = 4 ), save, dimension ( n_max ) :: sam_vec = (/ &\n 10, 10, 10, 10, &\n 6, 7, 8, 9, &\n 10, 10, 10, 10, &\n 10, 10, 10, 10 /)\n integer ( kind = 4 ) suc\n integer ( kind = 4 ), save, dimension ( n_max ) :: suc_vec = (/ &\n 90, 90, 90, 90, &\n 90, 90, 90, 90, &\n 10, 30, 50, 70, &\n 90, 90, 90, 90 /)\n\n if ( n_data < 0 ) then\n n_data = 0\n end if\n\n n_data = n_data + 1\n\n if ( n_max < n_data ) then\n n_data = 0\n sam = 0\n suc = 0\n pop = 0\n n = 0\n fx = 0.0D+00\n else\n sam = sam_vec(n_data)\n suc = suc_vec(n_data)\n pop = pop_vec(n_data)\n n = n_vec(n_data)\n fx = fx_vec(n_data)\n end if\n\n return\nend\nfunction hypergeometric_check ( n, m, l )\n\n!*****************************************************************************80\n!\n!! HYPERGEOMETRIC_CHECK checks the parameters of the Hypergeometric CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 22 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of balls selected.\n! 0 <= N <= L.\n!\n! Input, integer ( kind = 4 ) M, the number of white balls in the population.\n! 0 <= M <= L.\n!\n! Input, integer ( kind = 4 ) L, the number of balls to select from.\n! 0 <= L.\n!\n! Output, logical HYPERGEOMETRIC_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n logical hypergeometric_check\n integer ( kind = 4 ) l\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n\n if ( n < 0 .or. l < n ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'HYPERGEOMETRIC_CHECK - Fatal error!'\n write ( *, '(a)' ) ' Input N is out of range.'\n hypergeometric_check = .false.\n return\n end if\n\n if ( m < 0 .or. l < m ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'HYPERGEOMETRIC_CHECK - Fatal error!'\n write ( *, '(a)' ) ' Input M is out of range.'\n hypergeometric_check = .false.\n return\n end if\n\n if ( l < 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'HYPERGEOMETRIC_CHECK - Fatal error!'\n write ( *, '(a)' ) ' Input L is out of range.'\n hypergeometric_check = .false.\n return\n end if\n\n hypergeometric_check = .true.\n\n return\nend\nsubroutine hypergeometric_mean ( n, m, l, mean )\n\n!*****************************************************************************80\n!\n!! HYPERGEOMETRIC_MEAN returns the mean of the Hypergeometric PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 January 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of balls selected.\n! 0 <= N <= L.\n!\n! Input, integer ( kind = 4 ) M, the number of white balls in the population.\n! 0 <= M <= L.\n!\n! Input, integer ( kind = 4 ) L, the number of balls to select from.\n! 0 <= L.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) l\n integer ( kind = 4 ) m\n real ( kind = 8 ) mean\n integer ( kind = 4 ) n\n\n mean = real ( n * m, kind = 8 ) / real ( l, kind = 8 )\n\n return\nend\nsubroutine hypergeometric_pdf ( x, n, m, l, pdf )\n\n!*****************************************************************************80\n!\n!! HYPERGEOMETRIC_PDF evaluates the Hypergeometric PDF.\n!\n! Discussion:\n!\n! PDF(N,M,L;X) = C(M,X) * C(L-M,N-X) / C(L,N).\n!\n! PDF(N,M,L;X) is the probability of drawing X white balls in a\n! single random sample of size N from a population containing\n! M white balls and a total of L balls.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 January 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X, the desired number of white balls.\n! 0 <= X <= N, usually, although any value of X can be given.\n!\n! Input, integer ( kind = 4 ) N, the number of balls selected.\n! 0 <= N <= L.\n!\n! Input, integer ( kind = 4 ) M, the number of white balls.\n! 0 <= M <= L.\n!\n! Input, integer ( kind = 4 ) L, the number of balls to select from.\n! 0 <= L.\n!\n! Output, real ( kind = 8 ) PDF, the probability of exactly K white balls.\n!\n implicit none\n\n real ( kind = 8 ) c1\n real ( kind = 8 ) c2\n real ( kind = 8 ) c3\n integer ( kind = 4 ) l\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n real ( kind = 8 ) pdf\n real ( kind = 8 ) pdf_log\n integer ( kind = 4 ) x\n!\n! Special cases.\n!\n if ( x < 0 ) then\n\n pdf = 1.0D+00\n\n else if ( n < x ) then\n\n pdf = 0.0D+00\n\n else if ( m < x ) then\n\n pdf = 0.0D+00\n\n else if ( l < x ) then\n\n pdf = 0.0D+00\n\n else if ( n == 0 ) then\n\n if ( x == 0 ) then\n pdf = 1.0D+00\n else\n pdf = 0.0D+00\n end if\n\n else\n\n call binomial_coef_log ( m, x, c1 )\n call binomial_coef_log ( l-m, n-x, c2 )\n call binomial_coef_log ( l, n, c3 )\n\n pdf_log = c1 + c2 - c3\n\n pdf = exp ( pdf_log )\n\n end if\n\n return\nend\nsubroutine hypergeometric_sample ( n, m, l, seed, x )\n\n!*****************************************************************************80\n!\n!! HYPERGEOMETRIC_SAMPLE samples the Hypergeometric PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 23 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Jerry Banks, editor,\n! Handbook of Simulation,\n! Engineering and Management Press Books, 1998, page 165.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of balls selected.\n! 0 <= N <= L.\n!\n! Input, integer ( kind = 4 ) M, the number of white balls.\n! 0 <= M <= L.\n!\n! Input, integer ( kind = 4 ) L, the number of balls to select from.\n! 0 <= L.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random\n! number generator.\n!\n! Output, integer ( kind = 4 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c1_log\n real ( kind = 8 ) c2_log\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) l\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n integer ( kind = 4 ) seed\n real ( kind = 8 ) u\n integer ( kind = 4 ) x\n\n call binomial_coef_log ( l - m, n, c1_log )\n call binomial_coef_log ( l, n, c2_log )\n\n a = exp ( c1_log - c2_log )\n b = a\n\n u = r8_uniform_01 ( seed )\n\n x = 0\n\n do while ( a < u )\n\n b = b * real ( ( m - x ) * ( n - x ), kind = 8 ) &\n / real ( ( x + 1 ) * ( l - m - n + x + 1 ), kind = 8 )\n\n a = a + b\n\n x = x + 1\n\n end do\n\n return\nend\nsubroutine hypergeometric_variance ( n, m, l, variance )\n\n!*****************************************************************************80\n!\n!! HYPERGEOMETRIC_VARIANCE returns the variance of the Hypergeometric PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 January 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of balls selected.\n! 0 <= N <= L.\n!\n! Input, integer ( kind = 4 ) M, the number of white balls.\n! 0 <= M <= L.\n!\n! Input, integer ( kind = 4 ) L, the number of balls to select from.\n! 0 <= L.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) l\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n real ( kind = 8 ) variance\n\n variance = real ( n * m * ( l - m ) * ( l - n ), kind = 8 ) &\n / real ( l * l * ( l - 1 ), kind = 8 )\n\n return\nend\nfunction i4_factorial ( n )\n\n!*****************************************************************************80\n!\n!! I4_FACTORIAL returns N!.\n!\n! Discussion:\n!\n! N! = Product ( 1 <= I <= N ) I\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 22 November 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the argument of the function.\n! 0 <= N.\n!\n! Output, real ( kind = 8 ) I4_FACTORIAL, the factorial of N.\n!\n implicit none\n\n real ( kind = 8 ) i4_factorial\n integer ( kind = 4 ) i\n integer ( kind = 4 ) n\n\n if ( n < 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'I4_FACTORIAL - Fatal error!'\n write ( *, '(a)' ) ' N < 0.'\n stop 1\n end if\n\n i4_factorial = 1.0D+00\n\n do i = 2, n\n i4_factorial = i4_factorial * real ( i, kind = 8 )\n end do\n\n return\nend\nfunction i4_huge ( )\n\n!*****************************************************************************80\n!\n!! I4_HUGE returns a \"huge\" I4.\n!\n! Discussion:\n!\n! On an IEEE 32 bit machine, I4_HUGE should be 2^31 - 1, and its\n! bit pattern should be\n!\n! 01111111111111111111111111111111\n!\n! In this case, its numerical value is 2147483647.\n!\n! Using the Dec/Compaq/HP Alpha FORTRAN compiler FORT, I could\n! use I4_HUGE() and HUGE interchangeably.\n!\n! However, when using the G95, the values returned by HUGE were\n! not equal to 2147483647, apparently, and were causing severe\n! and obscure errors in my random number generator, which needs to\n! add I4_HUGE to the seed whenever the seed is negative. So I\n! am backing away from invoking HUGE, whereas I4_HUGE is under\n! my control.\n!\n! Explanation: because under G95 the default integer type is 64 bits!\n! So HUGE ( 1 ) = a very very huge integer indeed, whereas\n! I4_HUGE ( ) = the same old 32 bit big value.\n!\n! An I4 is an integer ( kind = 4 ) value.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 26 January 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Output, integer ( kind = 4 ) I4_HUGE, a \"huge\" I4.\n!\n implicit none\n\n integer ( kind = 4 ) i4\n integer ( kind = 4 ) i4_huge\n\n i4_huge = 2147483647\n\n return\nend\nfunction i4_uniform_ab ( a, b, seed )\n\n!*****************************************************************************80\n!\n!! I4_UNIFORM_AB returns a scaled pseudorandom I4.\n!\n! Discussion:\n!\n! An I4 is an integer ( kind = 4 ) value.\n!\n! The pseudorandom number will be scaled to be uniformly distributed\n! between A and B.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 12 November 2006\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Paul Bratley, Bennett Fox, Linus Schrage,\n! A Guide to Simulation,\n! Springer Verlag, pages 201-202, 1983.\n!\n! Pierre L'Ecuyer,\n! Random Number Generation,\n! in Handbook of Simulation,\n! edited by Jerry Banks,\n! Wiley Interscience, page 95, 1998.\n!\n! Bennett Fox,\n! Algorithm 647:\n! Implementation and Relative Efficiency of Quasirandom\n! Sequence Generators,\n! ACM Transactions on Mathematical Software,\n! Volume 12, Number 4, pages 362-376, 1986.\n!\n! Peter Lewis, Allen Goodman, James Miller\n! A Pseudo-Random Number Generator for the System/360,\n! IBM Systems Journal,\n! Volume 8, pages 136-143, 1969.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, B, the limits of the interval.\n!\n! Input/output, integer ( kind = 4 ) SEED, the \"seed\" value, which\n! should NOT be 0. On output, SEED has been updated.\n!\n! Output, integer ( kind = 4 ) I4_UNIFORM_AB, a number between A and B.\n!\n implicit none\n\n integer ( kind = 4 ) a\n integer ( kind = 4 ) b\n integer ( kind = 4 ) i4_huge\n integer ( kind = 4 ) i4_uniform_ab\n integer ( kind = 4 ) k\n real ( kind = 4 ) r\n integer ( kind = 4 ) seed\n integer ( kind = 4 ) value\n\n if ( seed == 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'I4_UNIFORM_AB - 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 < 0 ) then\n seed = seed + i4_huge ( )\n end if\n\n r = real ( seed, kind = 4 ) * 4.656612875E-10\n!\n! Scale R to lie between A-0.5 and B+0.5.\n!\n r = ( 1.0E+00 - r ) * ( real ( min ( a, b ), kind = 4 ) - 0.5E+00 ) &\n + r * ( real ( max ( a, b ), kind = 4 ) + 0.5E+00 )\n!\n! Use rounding to convert R to an integer between A and B.\n!\n value = nint ( r, kind = 4 )\n\n value = max ( value, min ( a, b ) )\n value = min ( value, max ( a, b ) )\n\n i4_uniform_ab = value\n\n return\nend\nsubroutine i4row_max ( m, n, a, amax )\n\n!*****************************************************************************80\n!\n!! I4ROW_MAX returns the maximums of the rows of an I4ROW.\n!\n! Discussion:\n!\n! An I4ROW is an M by N array of I4's, regarded\n! as an array of M rows of length N.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 13 November 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, N, the number of rows and columns.\n!\n! Input, integer ( kind = 4 ) A(M,N), the array to be examined.\n!\n! Output, integer ( kind = 4 ) AMAX(M), the maximums of the rows\n! of the array.\n!\n implicit none\n\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n\n integer ( kind = 4 ) a(m,n)\n integer ( kind = 4 ) amax(m)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) j\n\n do i = 1, m\n\n amax(i) = a(i,1)\n do j = 2, n\n if ( amax(i) < a(i,j) ) then\n amax(i) = a(i,j)\n end if\n end do\n\n end do\n\n return\nend\nsubroutine i4row_mean ( m, n, a, mean )\n\n!*****************************************************************************80\n!\n!! I4ROW_MEAN returns the means of the rows of an I4ROW.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 14 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, N, the number of rows and columns of data.\n!\n! Input, integer ( kind = 4 ) A(M,N), the array.\n!\n! Output, real ( kind = 8 ) MEAN(M), the mean of each row.\n!\n implicit none\n\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n\n integer ( kind = 4 ) a(m,n)\n integer ( kind = 4 ) i\n real ( kind = 8 ) mean(m)\n\n do i = 1, m\n mean(i) = sum ( a(i,1:n) ) / real ( n, kind = 8 )\n end do\n\n return\nend\nsubroutine i4row_min ( m, n, a, amin )\n\n!*****************************************************************************80\n!\n!! I4ROW_MIN returns the minimums of the rows of an I4ROW.\n!\n! Discussion:\n!\n! An I4ROW is an M by N array of I4's, regarded\n! as an array of M rows of length N.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 13 November 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, N, the number of rows and columns.\n!\n! Input, integer ( kind = 4 ) A(M,N), the array to be examined.\n!\n! Output, integer ( kind = 4 ) AMIN(M), the minimums of the rows.\n!\n implicit none\n\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n\n integer ( kind = 4 ) a(m,n)\n integer ( kind = 4 ) amin(m)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) j\n\n do i = 1, m\n\n amin(i) = a(i,1)\n do j = 2, n\n if ( a(i,j) < amin(i) ) then\n amin(i) = a(i,j)\n end if\n end do\n\n end do\n\n return\nend\nsubroutine i4row_variance ( m, n, a, variance )\n\n!*****************************************************************************80\n!\n!! I4ROW_VARIANCE returns the variances of the rows of an I4ROW.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 14 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, N, the number of rows and columns of data.\n!\n! Input, integer ( kind = 4 ) A(M,N), the array.\n!\n! Output, real ( kind = 8 ) VARIANCE(M), the variance of each row.\n!\n implicit none\n\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n\n integer ( kind = 4 ) a(m,n)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) j\n real ( kind = 8 ) mean\n real ( kind = 8 ) variance(m)\n\n do i = 1, m\n\n mean = real ( sum ( a(i,1:n) ), kind = 8 ) / real ( n, kind = 8 )\n\n variance(i) = 0.0D+00\n do j = 1, n\n variance(i) = variance(i) + ( real ( a(i,j), kind = 8 ) - mean )**2\n end do\n\n if ( 1 < n ) then\n variance(i) = variance(i) / real ( n - 1, kind = 8 )\n else\n variance(i) = 0.0D+00\n end if\n\n end do\n\n return\nend\nsubroutine i4vec_max ( n, a, amax )\n\n!*****************************************************************************80\n!\n!! I4VEC_MAX computes the maximum element of an I4VEC.\n!\n! Discussion:\n!\n! An I4VEC is a vector of I4's.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 January 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of entries in the array.\n!\n! Input, integer ( kind = 4 ) A(N), the array.\n!\n! Output, integer ( kind = 4 ) AMAX, the value of the largest entry.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n integer ( kind = 4 ) a(n)\n integer ( kind = 4 ) amax\n\n amax = maxval ( a(1:n) )\n\n return\nend\nsubroutine i4vec_mean ( n, x, mean )\n\n!*****************************************************************************80\n!\n!! I4VEC_MEAN returns the mean of an I4VEC.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of entries in the vector.\n!\n! Input, integer ( kind = 4 ) X(N), the vector whose mean is desired.\n!\n! Output, real ( kind = 8 ) MEAN, the mean, or average, of\n! the vector entries.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) mean\n integer ( kind = 4 ) x(n)\n\n mean = real ( sum ( x(1:n) ), kind = 8 ) / real ( n, kind = 8 )\n\n return\nend\nsubroutine i4vec_min ( n, a, amin )\n\n!*****************************************************************************80\n!\n!! I4VEC_MIN computes the minimum element of an I4VEC.\n!\n! Discussion:\n!\n! An I4VEC is a vector of I4's.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 January 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of entries in the array.\n!\n! Input, integer ( kind = 4 ) A(N), the array.\n!\n! Output, integer ( kind = 4 ) AMIN, the value of the smallest entry.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n integer ( kind = 4 ) a(n)\n integer ( kind = 4 ) amin\n\n amin = minval ( a(1:n) )\n\n return\nend\nsubroutine i4vec_print ( n, a, title )\n\n!*****************************************************************************80\n!\n!! I4VEC_PRINT prints an I4VEC.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 November 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of components of the vector.\n!\n! Input, integer ( kind = 4 ) A(N), the vector to be printed.\n!\n! Input, character ( len = * ) TITLE, a title to be printed first.\n! TITLE may be blank.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n integer ( kind = 4 ) a(n)\n integer ( kind = 4 ) big\n integer ( kind = 4 ) i\n character ( len = * ) title\n\n if ( title /= ' ' ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) trim ( title )\n end if\n\n big = maxval ( abs ( a(1:n) ) )\n\n write ( *, '(a)' ) ' '\n if ( big < 1000 ) then\n do i = 1, n\n write ( *, '(i8,1x,i4)' ) i, a(i)\n end do\n else if ( big < 1000000 ) then\n do i = 1, n\n write ( *, '(i8,1x,i7)' ) i, a(i)\n end do\n else\n do i = 1, n\n write ( *, '(i8,i11)' ) i, a(i)\n end do\n end if\n\n return\nend\nsubroutine i4vec_run_count ( n, a, run_count )\n\n!*****************************************************************************80\n!\n!! I4VEC_RUN_COUNT counts runs of equal values in an I4VEC.\n!\n! Discussion:\n!\n! An I4VEC is a vector of integer values.\n!\n! A run is a sequence of equal values.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 26 January 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of entries in the vector.\n!\n! Input, integer ( kind = 4 ) A(N), the vector to be examined.\n!\n! Output, integer ( kind = 4 ) RUN_COUNT, the number of runs.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n integer ( kind = 4 ) a(n)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) run_count\n integer ( kind = 4 ) test\n\n run_count = 0\n\n if ( n < 1 ) then\n return\n end if\n\n test = 0\n\n do i = 1, n\n\n if ( i == 1 .or. a(i) /= test ) then\n run_count = run_count + 1\n test = a(i)\n end if\n\n end do\n\n return\nend\nsubroutine i4vec_variance ( n, x, variance )\n\n!*****************************************************************************80\n!\n!! I4VEC_VARIANCE returns the variance of an I4VEC.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 08 May 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of entries in the vector.\n!\n! Input, integer ( kind = 4 ) X(N), the vector whose variance is desired.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the vector entries.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) mean\n real ( kind = 8 ) variance\n integer ( kind = 4 ) x(n)\n\n call i4vec_mean ( n, x, mean )\n\n variance = sum ( ( real ( x(1:n), kind = 8 ) - mean )**2 )\n\n if ( 1 < n ) then\n variance = variance / real ( n - 1, kind = 8 )\n else\n variance = 0.0D+00\n end if\n\n return\nend\nsubroutine inverse_gaussian_cdf ( x, a, b, cdf )\n\n!*****************************************************************************80\n!\n!! INVERSE_GAUSSIAN_CDF evaluates the Inverse Gaussian CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 23 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n! 0.0D+00 < X.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A,\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) cdf1\n real ( kind = 8 ) cdf2\n real ( kind = 8 ) x\n real ( kind = 8 ) x1\n real ( kind = 8 ) x2\n\n if ( x <= 0.0D+00 ) then\n\n cdf = 0.0D+00\n\n else\n\n x1 = sqrt ( b / x ) * ( x - a ) / a\n call normal_01_cdf ( x1, cdf1 )\n\n x2 = - sqrt ( b / x ) * ( x + a ) / a\n call normal_01_cdf ( x2, cdf2 )\n\n cdf = cdf1 + exp ( 2.0D+00 * b / a ) * cdf2\n\n end if\n\n return\nend\nfunction inverse_gaussian_check ( a, b )\n\n!*****************************************************************************80\n!\n!! INVERSE_GAUSSIAN_CHECK checks the parameters of the Inverse Gaussian CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 22 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A,\n! 0.0D+00 < B.\n!\n! Output, logical INVERSE_GAUSSIAN_CHECK, is true if the parameters\n! are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n logical inverse_gaussian_check\n\n if ( a <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'INVERSE_GAUSSIAN_CHECK - Fatal error!'\n write ( *, '(a)' ) ' A <= 0.'\n inverse_gaussian_check = .false.\n return\n end if\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'INVERSE_GAUSSIAN_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B <= 0.'\n inverse_gaussian_check = .false.\n return\n end if\n\n inverse_gaussian_check = .true.\n\n return\nend\nsubroutine inverse_gaussian_mean ( a, b, mean )\n\n!*****************************************************************************80\n!\n!! INVERSE_GAUSSIAN_MEAN returns the mean of the Inverse Gaussian PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 25 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A,\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) mean\n\n mean = a\n\n return\nend\nsubroutine inverse_gaussian_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! INVERSE_GAUSSIAN_PDF evaluates the Inverse Gaussian PDF.\n!\n! Discussion:\n!\n! The Inverse Gaussian PDF is also known as the Wald PDF\n! and the Inverse Normal PDF.\n!\n! PDF(A,B;X)\n! = sqrt ( B / ( 2 * PI * X^3 ) )\n! * exp ( - B * ( X - A )^2 / ( 2.0D+00 * A^2 * X ) )\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 23 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n! 0.0D+00 < X\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A,\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) pdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) x\n\n if ( x <= 0.0D+00 ) then\n pdf = 0.0D+00\n else\n pdf = sqrt ( b / ( 2.0D+00 * pi * x**3 ) ) * &\n exp ( - b * ( x - a )**2 / ( 2.0D+00 * a * a * x ) )\n end if\n\n return\nend\nsubroutine inverse_gaussian_sample ( a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! INVERSE_GAUSSIAN_SAMPLE samples the Inverse Gaussian PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 23 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A,\n! 0.0D+00 < B.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) r8_uniform_01\n real ( kind = 8 ) phi\n integer ( kind = 4 ) seed\n real ( kind = 8 ) t\n real ( kind = 8 ) u\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n real ( kind = 8 ) z\n\n phi = b / a\n call normal_01_sample ( seed, z )\n y = z * z\n\n t = 1.0D+00 + 0.5D+00 * ( y - sqrt ( 4.0D+00 * phi * y + y * y ) ) / phi\n u = r8_uniform_01 ( seed )\n\n if ( u * ( 1.0D+00 + t ) <= 1.0D+00 ) then\n x = a * t\n else\n x = a / t\n end if\n\n return\nend\nsubroutine inverse_gaussian_variance ( a, b, variance )\n\n!*****************************************************************************80\n!\n!! INVERSE_GAUSSIAN_VARIANCE returns the variance of the Inverse Gaussian PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 25 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A,\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) variance\n\n variance = a**3 / b\n\n return\nend\nsubroutine laplace_cdf ( x, a, b, cdf )\n\n!*****************************************************************************80\n!\n!! LAPLACE_CDF evaluates the Laplace CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 16 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) CDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n\n y = ( x - a ) / b\n\n if ( x <= a ) then\n cdf = 0.5D+00 * exp ( y )\n else\n cdf = 1.0D+00 - 0.5D+00 * exp ( - y )\n end if\n\n return\nend\nsubroutine laplace_cdf_inv ( cdf, a, b, x )\n\n!*****************************************************************************80\n!\n!! LAPLACE_CDF_INV inverts the Laplace CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 17 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'LAPLACE_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n if ( cdf <= 0.5D+00 ) then\n x = a + b * log ( 2.0D+00 * cdf )\n else\n x = a - b * log ( 2.0D+00 * ( 1.0D+00 - cdf ) )\n end if\n\n return\nend\nsubroutine laplace_cdf_values ( n_data, mu, beta, x, fx )\n\n!*****************************************************************************80\n!\n!! LAPLACE_CDF_VALUES returns some values of the Laplace CDF.\n!\n! Discussion:\n!\n! In Mathematica, the function can be evaluated by:\n!\n! Needs[\"Statistics`ContinuousDistributions`\"]\n! dist = LaplaceDistribution [ mu, beta ]\n! CDF [ dist, x ]\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 August 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Milton Abramowitz, Irene Stegun,\n! Handbook of Mathematical Functions,\n! National Bureau of Standards, 1964,\n! LC: QA47.A34,\n! ISBN: 0-486-61272-4.\n!\n! Stephen Wolfram,\n! The Mathematica Book,\n! Fourth Edition,\n! Wolfram Media / Cambridge University Press, 1999.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) N_DATA. The user sets N_DATA to 0\n! before the first call. On each call, the routine increments N_DATA by 1,\n! and returns the corresponding data; when there is no more data, the\n! output value of N_DATA will be 0 again.\n!\n! Output, real ( kind = 8 ) MU, the mean of the distribution.\n!\n! Output, real ( kind = 8 ) BETA, the shape parameter.\n!\n! Output, real ( kind = 8 ) X, the argument of the function.\n!\n! Output, real ( kind = 8 ) FX, the value of the function.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: n_max = 12\n\n real ( kind = 8 ) beta\n real ( kind = 8 ), save, dimension ( n_max ) :: beta_vec = (/ &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.4000000000000000D+01, &\n 0.5000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01 /)\n real ( kind = 8 ) fx\n real ( kind = 8 ), save, dimension ( n_max ) :: fx_vec = (/ &\n 0.5000000000000000D+00, &\n 0.8160602794142788D+00, &\n 0.9323323583816937D+00, &\n 0.9751064658160680D+00, &\n 0.6967346701436833D+00, &\n 0.6417343447131054D+00, &\n 0.6105996084642976D+00, &\n 0.5906346234610091D+00, &\n 0.5000000000000000D+00, &\n 0.3032653298563167D+00, &\n 0.1839397205857212D+00, &\n 0.1115650800742149D+00 /)\n real ( kind = 8 ) mu\n real ( kind = 8 ), save, dimension ( n_max ) :: mu_vec = (/ &\n 0.0000000000000000D+01, &\n 0.0000000000000000D+01, &\n 0.0000000000000000D+01, &\n 0.0000000000000000D+01, &\n 0.0000000000000000D+01, &\n 0.0000000000000000D+01, &\n 0.0000000000000000D+01, &\n 0.0000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.4000000000000000D+01 /)\n integer ( kind = 4 ) n_data\n real ( kind = 8 ) x\n real ( kind = 8 ), save, dimension ( n_max ) :: x_vec = (/ &\n 0.0000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01 /)\n\n if ( n_data < 0 ) then\n n_data = 0\n end if\n\n n_data = n_data + 1\n\n if ( n_max < n_data ) then\n n_data = 0\n mu = 0.0D+00\n beta = 0.0D+00\n x = 0.0D+00\n fx = 0.0D+00\n else\n mu = mu_vec(n_data)\n beta = beta_vec(n_data)\n x = x_vec(n_data)\n fx = fx_vec(n_data)\n end if\n\n return\nend\nfunction laplace_check ( a, b )\n\n!*****************************************************************************80\n!\n!! LAPLACE_CHECK checks the parameters of the Laplace PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 22 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, logical LAPLACE_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n logical laplace_check\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'LAPLACE_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B <= 0.'\n laplace_check = .false.\n return\n end if\n\n laplace_check = .true.\n\n return\nend\nsubroutine laplace_mean ( a, b, mean )\n\n!*****************************************************************************80\n!\n!! LAPLACE_MEAN returns the mean of the Laplace PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 15 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) mean\n\n mean = a\n\n return\nend\nsubroutine laplace_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! LAPLACE_PDF evaluates the Laplace PDF.\n!\n! Discussion:\n!\n! PDF(A,B;X) = exp ( - abs ( X - A ) / B ) / ( 2 * B )\n!\n! The Laplace PDF is also known as the Double Exponential PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 09 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) pdf\n real ( kind = 8 ) x\n\n pdf = exp ( - abs ( x - a ) / b ) / ( 2.0D+00 * b )\n\n return\nend\nsubroutine laplace_sample ( a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! LAPLACE_SAMPLE samples the Laplace PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 16 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call laplace_cdf_inv ( cdf, a, b, x )\n\n return\nend\nsubroutine laplace_variance ( a, b, variance )\n\n!*****************************************************************************80\n!\n!! LAPLACE_VARIANCE returns the variance of the Laplace PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 15 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) variance\n\n variance = 2.0D+00 * b * b\n\n return\nend\nfunction lerch ( a, b, c )\n\n!*****************************************************************************80\n!\n!! LERCH estimates the Lerch transcendent function.\n!\n! Discussion:\n!\n! The Lerch transcendent function is defined as:\n!\n! LERCH ( A, B, C ) = Sum ( 0 <= K < Infinity ) A^K / ( C + K )^B\n!\n! excluding any term with ( C + K ) = 0.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 17 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Eric Weisstein, editor,\n! CRC Concise Encylopedia of Mathematics,\n! CRC Press, 1998.\n!\n! Thanks:\n!\n! Oscar van Vlijmen\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the function.\n!\n! Output, real ( kind = 8 ) LERCH, an approximation to the Lerch\n! transcendent function.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) a_k\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n integer ( kind = 4 ) k\n real ( kind = 8 ) lerch\n real ( kind = 8 ) sum2\n real ( kind = 8 ) sum2_old\n\n sum2 = 0.0D+00\n k = 0\n a_k = 1.0D+00\n\n do\n\n sum2_old = sum2\n\n if ( c + real ( k, kind = 8 ) == 0.0D+00 ) then\n k = k + 1\n a_k = a_k * a\n cycle\n end if\n\n sum2 = sum2 + a_k / ( c + real ( k, kind = 8 ) )**b\n\n if ( sum2 <= sum2_old ) then\n exit\n end if\n\n k = k + 1\n a_k = a_k * a\n\n end do\n\n lerch = sum2\n\n return\nend\nsubroutine levy_cdf ( x, a, b, cdf )\n\n!*****************************************************************************80\n!\n!! LEVY_CDF evaluates the Levy CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 23 April 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n! Normally, A <= X.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0 < B.\n!\n! Output, real ( kind = 8 ) CDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) error_f\n real ( kind = 8 ) x\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'LEVY_CDF - Fatal error!'\n write ( *, '(a)' ) ' Input parameter B <= 0.0'\n stop 1\n end if\n\n if ( x <= a ) then\n cdf = 0.0D+00\n else\n cdf = 1.0D+00 - error_f ( sqrt ( b / ( 2.0D+00 * ( x - a ) ) ) )\n end if\n\n return\nend\nsubroutine levy_cdf_inv ( cdf, a, b, x )\n\n!*****************************************************************************80\n!\n!! LEVY_CDF_INV inverts the Levy CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 24 April 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0 < B.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) cdf1\n real ( kind = 8 ) x\n real ( kind = 8 ) x1\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'LEVY_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'LEVY_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' Input parameter B <= 0.0'\n stop 1\n end if\n\n cdf1 = 1.0D+00 - 0.5D+00 * cdf\n call normal_01_cdf_inv ( cdf1, x1 )\n x = a + b / ( x1 * x1 )\n\n return\nend\nsubroutine levy_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! LEVY_PDF evaluates the Levy PDF.\n!\n! Discussion:\n!\n! PDF(A,B;X) = sqrt ( B / ( 2 * PI ) )\n! * exp ( - B / ( 2 * ( X - A ) )\n! / ( X - A )^(3/2)\n!\n! for A <= X.\n!\n! Note that the Levy PDF does not have a finite mean or variance.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 24 April 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n! Normally, A <= X.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0 < B.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) pdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) x\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'LEVY_PDF - Fatal error!'\n write ( *, '(a)' ) ' Input parameter B <= 0.0'\n stop 1\n end if\n\n if ( x <= a ) then\n pdf = 0.0D+00\n else\n pdf = sqrt ( b / ( 2.0D+00 * pi ) ) &\n * exp ( - b / ( 2.0D+00 * ( x - a ) ) ) &\n / sqrt ( ( x - a )**3 )\n end if\n\n return\nend\nsubroutine levy_sample ( a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! LEVY_SAMPLE samples the Levy PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 24 April 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call levy_cdf_inv ( cdf, a, b, x )\n\n return\nend\nsubroutine logistic_cdf ( x, a, b, cdf )\n\n!*****************************************************************************80\n!\n!! LOGISTIC_CDF evaluates the Logistic CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 16 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n cdf = 1.0D+00 / ( 1.0D+00 + exp ( ( a - x ) / b ) )\n\n return\nend\nsubroutine logistic_cdf_inv ( cdf, a, b, x )\n\n!*****************************************************************************80\n!\n!! LOGISTIC_CDF_INV inverts the Logistic CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 16 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'LOGISTIC_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n x = a - b * log ( ( 1.0D+00 - cdf ) / cdf )\n\n return\nend\nsubroutine logistic_cdf_values ( n_data, mu, beta, x, fx )\n\n!*****************************************************************************80\n!\n!! LOGISTIC_CDF_VALUES returns some values of the Logistic CDF.\n!\n! Discussion:\n!\n! In Mathematica, the function can be evaluated by:\n!\n! Needs[\"Statistics`ContinuousDistributions`\"]\n! dist = LogisticDistribution [ mu, beta ]\n! CDF [ dist, x ]\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 August 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Milton Abramowitz, Irene Stegun,\n! Handbook of Mathematical Functions,\n! National Bureau of Standards, 1964,\n! LC: QA47.A34,\n! ISBN: 0-486-61272-4.\n!\n! Stephen Wolfram,\n! The Mathematica Book,\n! Fourth Edition,\n! Wolfram Media / Cambridge University Press, 1999.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) N_DATA. The user sets N_DATA to 0\n! before the first call. On each call, the routine increments N_DATA by 1,\n! and returns the corresponding data; when there is no more data, the\n! output value of N_DATA will be 0 again.\n!\n! Output, real ( kind = 8 ) MU, the mean of the distribution.\n!\n! Output, real ( kind = 8 ) BETA, the shape parameter of the distribution.\n!\n! Output, real ( kind = 8 ) X, the argument of the function.\n!\n! Output, real ( kind = 8 ) FX, the value of the function.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: n_max = 12\n\n real ( kind = 8 ) beta\n real ( kind = 8 ), save, dimension ( n_max ) :: beta_vec = (/ &\n 0.5000000000000000D+00, &\n 0.5000000000000000D+00, &\n 0.5000000000000000D+00, &\n 0.5000000000000000D+00, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.4000000000000000D+01, &\n 0.5000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01 /)\n real ( kind = 8 ) fx\n real ( kind = 8 ), save, dimension ( n_max ) :: fx_vec = (/ &\n 0.5000000000000000D+00, &\n 0.8807970779778824D+00, &\n 0.9820137900379084D+00, &\n 0.9975273768433652D+00, &\n 0.6224593312018546D+00, &\n 0.5825702064623147D+00, &\n 0.5621765008857981D+00, &\n 0.5498339973124779D+00, &\n 0.6224593312018546D+00, &\n 0.5000000000000000D+00, &\n 0.3775406687981454D+00, &\n 0.2689414213699951D+00 /)\n real ( kind = 8 ) mu\n real ( kind = 8 ), save, dimension ( n_max ) :: mu_vec = (/ &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.4000000000000000D+01, &\n 0.5000000000000000D+01 /)\n integer ( kind = 4 ) n_data\n real ( kind = 8 ) x\n real ( kind = 8 ), save, dimension ( n_max ) :: x_vec = (/ &\n 0.1000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.4000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.3000000000000000D+01 /)\n\n if ( n_data < 0 ) then\n n_data = 0\n end if\n\n n_data = n_data + 1\n\n if ( n_max < n_data ) then\n n_data = 0\n mu = 0.0D+00\n beta = 0.0D+00\n x = 0.0D+00\n fx = 0.0D+00\n else\n mu = mu_vec(n_data)\n beta = beta_vec(n_data)\n x = x_vec(n_data)\n fx = fx_vec(n_data)\n end if\n\n return\nend\nfunction logistic_check ( a, b )\n\n!*****************************************************************************80\n!\n!! LOGISTIC_CHECK checks the parameters of the Logistic CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 22 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, logical LOGISTIC_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n logical logistic_check\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'LOGISTIC_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B <= 0.'\n logistic_check = .false.\n return\n end if\n\n logistic_check = .true.\n\n return\nend\nsubroutine logistic_mean ( a, b, mean )\n\n!*****************************************************************************80\n!\n!! LOGISTIC_MEAN returns the mean of the Logistic PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 12 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) mean\n\n mean = a\n\n return\nend\nsubroutine logistic_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! LOGISTIC_PDF evaluates the Logistic PDF.\n!\n! Discussion:\n!\n! PDF(A,B;X) = exp ( ( A - X ) / B ) /\n! ( B * ( 1 + exp ( ( A - X ) / B ) )^2 )\n!\n! The Logistic PDF is also known as the Sech-Squared PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) pdf\n real ( kind = 8 ) temp\n real ( kind = 8 ) x\n\n temp = exp ( ( a - x ) / b )\n\n pdf = temp / ( b * ( 1.0D+00 + temp )**2 )\n\n return\nend\nsubroutine logistic_sample ( a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! LOGISTIC_SAMPLE samples the Logistic PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 12 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call logistic_cdf_inv ( cdf, a, b, x )\n\n return\nend\nsubroutine logistic_variance ( a, b, variance )\n\n!*****************************************************************************80\n!\n!! LOGISTIC_VARIANCE returns the variance of the Logistic PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 12 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) variance\n\n variance = pi * pi * b * b / 3.0D+00\n\n return\nend\nsubroutine log_normal_cdf ( x, a, b, cdf )\n\n!*****************************************************************************80\n!\n!! LOG_NORMAL_CDF evaluates the Lognormal CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 12 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n! 0.0D+00 < X.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) logx\n real ( kind = 8 ) x\n\n if ( x <= 0.0D+00 ) then\n\n cdf = 0.0D+00\n\n else\n\n logx = log ( x )\n\n call normal_cdf ( logx, a, b, cdf )\n\n end if\n\n return\nend\nsubroutine log_normal_cdf_inv ( cdf, a, b, x )\n\n!*****************************************************************************80\n!\n!! LOG_NORMAL_CDF_INV inverts the Lognormal CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 12 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Input, real ( kind = 8 ) X, the corresponding argument.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) logx\n real ( kind = 8 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'LOG_NORMAL_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n call normal_cdf_inv ( cdf, a, b, logx )\n\n x = exp ( logx )\n\n return\nend\nsubroutine log_normal_cdf_values ( n_data, mu, sigma, x, fx )\n\n!*****************************************************************************80\n!\n!! LOG_NORMAL_CDF_VALUES returns some values of the Log Normal CDF.\n!\n! Discussion:\n!\n! In Mathematica, the function can be evaluated by:\n!\n! Needs[\"Statistics`ContinuousDistributions`\"]\n! dist = LogNormalDistribution [ mu, sigma ]\n! CDF [ dist, x ]\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 August 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Milton Abramowitz, Irene Stegun,\n! Handbook of Mathematical Functions,\n! National Bureau of Standards, 1964,\n! LC: QA47.A34,\n! ISBN: 0-486-61272-4.\n!\n! Stephen Wolfram,\n! The Mathematica Book,\n! Fourth Edition,\n! Wolfram Media / Cambridge University Press, 1999.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) N_DATA. The user sets N_DATA to 0\n! before the first call. On each call, the routine increments N_DATA by 1,\n! and returns the corresponding data; when there is no more data, the\n! output value of N_DATA will be 0 again.\n!\n! Output, real ( kind = 8 ) MU, the mean of the distribution.\n!\n! Output, real ( kind = 8 ) SIGMA, the shape parameter of the distribution.\n!\n! Output, real ( kind = 8 ) X, the argument of the function.\n!\n! Output, real ( kind = 8 ) FX, the value of the function.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: n_max = 12\n\n real ( kind = 8 ) fx\n real ( kind = 8 ), save, dimension ( n_max ) :: fx_vec = (/ &\n 0.2275013194817921D-01, &\n 0.2697049307349095D+00, &\n 0.5781741008028732D+00, &\n 0.7801170895122241D+00, &\n 0.4390310097476894D+00, &\n 0.4592655190218048D+00, &\n 0.4694258497695908D+00, &\n 0.4755320473858733D+00, &\n 0.3261051056816658D+00, &\n 0.1708799040927608D+00, &\n 0.7343256357952060D-01, &\n 0.2554673736161761D-01 /)\n real ( kind = 8 ) mu\n real ( kind = 8 ), save, dimension ( n_max ) :: mu_vec = (/ &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.4000000000000000D+01, &\n 0.5000000000000000D+01 /)\n integer ( kind = 4 ) n_data\n real ( kind = 8 ) sigma\n real ( kind = 8 ), save, dimension ( n_max ) :: sigma_vec = (/ &\n 0.5000000000000000D+00, &\n 0.5000000000000000D+00, &\n 0.5000000000000000D+00, &\n 0.5000000000000000D+00, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.4000000000000000D+01, &\n 0.5000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01 /)\n real ( kind = 8 ) x\n real ( kind = 8 ), save, dimension ( n_max ) :: x_vec = (/ &\n 0.1000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.4000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.3000000000000000D+01 /)\n\n if ( n_data < 0 ) then\n n_data = 0\n end if\n\n n_data = n_data + 1\n\n if ( n_max < n_data ) then\n n_data = 0\n mu = 0.0D+00\n sigma = 0.0D+00\n x = 0.0D+00\n fx = 0.0D+00\n else\n mu = mu_vec(n_data)\n sigma = sigma_vec(n_data)\n x = x_vec(n_data)\n fx = fx_vec(n_data)\n end if\n\n return\nend\nfunction log_normal_check ( a, b )\n\n!*****************************************************************************80\n!\n!! LOG_NORMAL_CHECK checks the parameters of the Lognormal PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 08 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, logical LOG_NORMAL_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n logical log_normal_check\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'LOG_NORMAL_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B <= 0.'\n log_normal_check = .false.\n return\n end if\n\n log_normal_check = .true.\n\n return\nend\nsubroutine log_normal_mean ( a, b, mean )\n\n!*****************************************************************************80\n!\n!! LOG_NORMAL_MEAN returns the mean of the Lognormal PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 12 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) mean\n\n mean = exp ( a + 0.5D+00 * b * b )\n\n return\nend\nsubroutine log_normal_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! LOG_NORMAL_PDF evaluates the Lognormal PDF.\n!\n! Discussion:\n!\n! PDF(A,B;X)\n! = exp ( - 0.5 * ( ( log ( X ) - A ) / B )^2 )\n! / ( B * X * sqrt ( 2 * PI ) )\n!\n! The Lognormal PDF is also known as the Cobb-Douglas PDF,\n! and as the Antilog_normal PDF.\n!\n! The Lognormal PDF describes a variable X whose logarithm\n! is normally distributed.\n!\n! The special case A = 0, B = 1 is known as Gilbrat's PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 10 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n! 0.0D+00 < X\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) pdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) x\n\n if ( x <= 0.0D+00 ) then\n pdf = 0.0D+00\n else\n pdf = exp ( - 0.5D+00 * ( ( log ( x ) - a ) / b )**2 ) &\n / ( b * x * sqrt ( 2.0D+00 * pi ) )\n end if\n\n return\nend\nsubroutine log_normal_sample ( a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! LOG_NORMAL_SAMPLE samples the Lognormal PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 10 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random\n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call log_normal_cdf_inv ( cdf, a, b, x )\n\n return\nend\nsubroutine log_normal_variance ( a, b, variance )\n\n!*****************************************************************************80\n!\n!! LOG_NORMAL_VARIANCE returns the variance of the Lognormal PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 12 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) variance\n\n variance = exp ( 2.0D+00 * a + b * b ) * ( exp ( b * b ) - 1.0D+00 )\n\n return\nend\nsubroutine log_series_cdf ( x, a, cdf )\n\n!*****************************************************************************80\n!\n!! LOG_SERIES_CDF evaluates the Logarithmic Series CDF.\n!\n! Discussion:\n!\n! Simple summation is used, with a recursion to generate successive\n! values of the PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 18 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Thanks:\n!\n! Oscar van Vlijmen\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X, the argument of the PDF.\n! 0 < X\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 0.0D+00 < A < 1.0.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) cdf\n real ( kind = 8 ) pdf\n integer ( kind = 4 ) x\n integer ( kind = 4 ) x2\n\n cdf = 0.0D+00\n\n do x2 = 1, x\n\n if ( x2 == 1 ) then\n pdf = - a / log ( 1.0D+00 - a )\n else\n pdf = real ( x2 - 1, kind = 8 ) * a * pdf / real ( x2, kind = 8 )\n end if\n\n cdf = cdf + pdf\n\n end do\n\n return\nend\nsubroutine log_series_cdf_inv ( cdf, a, x )\n\n!*****************************************************************************80\n!\n!! LOG_SERIES_CDF_INV inverts the Logarithmic Series CDF.\n!\n! Discussion:\n!\n! Simple summation is used. The only protection against an\n! infinite loop caused by roundoff is that X cannot be larger\n! than 1000.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 18 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 0.0D+00 < A < 1.0.\n!\n! Output, real ( kind = 8 ) X, the argument of the CDF for which\n! CDF(X-1) <= CDF <= CDF(X).\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) cdf\n real ( kind = 8 ) cdf2\n real ( kind = 8 ) pdf\n integer ( kind = 4 ) x\n integer ( kind = 4 ), parameter :: xmax = 1000\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'LOG_SERIES_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n cdf2 = 0.0D+00\n x = 1\n\n do while ( cdf2 < cdf .and. x < xmax )\n\n if ( x == 1 ) then\n pdf = - a / log ( 1.0D+00 - a )\n else\n pdf = real ( x - 1, kind = 8 ) * a * pdf / real ( x, kind = 8 )\n end if\n\n cdf2 = cdf2 + pdf\n\n x = x + 1\n\n end do\n\n return\nend\nsubroutine log_series_cdf_values ( n_data, t, n, fx )\n\n!*****************************************************************************80\n!\n!! LOG_SERIES_CDF_VALUES returns some values of the log series CDF.\n!\n! Discussion:\n!\n! In Mathematica, the function can be evaluated by:\n!\n! Needs[\"Statistics`DiscreteDistributions`]\n! dist = LogSeriesDistribution [ t ]\n! CDF [ dist, n ]\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 27 August 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Stephen Wolfram,\n! The Mathematica Book,\n! Fourth Edition,\n! Wolfram Media / Cambridge University Press, 1999.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) N_DATA. The user sets N_DATA to 0\n! before the first call. On each call, the routine increments N_DATA by 1,\n! and returns the corresponding data; when there is no more data, the\n! output value of N_DATA will be 0 again.\n!\n! Output, real ( kind = 8 ) T, the parameter of the function.\n!\n! Output, integer ( kind = 4 ) N, the argument of the function.\n!\n! Output, real ( kind = 8 ) FX, the value of the function.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: n_max = 29\n\n real ( kind = 8 ) fx\n real ( kind = 8 ), save, dimension ( n_max ) :: fx_vec = (/ &\n 0.9491221581029903D+00, &\n 0.9433541128559735D+00, &\n 0.9361094611773272D+00, &\n 0.9267370278044118D+00, &\n 0.9141358246245129D+00, &\n 0.8962840235449100D+00, &\n 0.8690148741955517D+00, &\n 0.8221011541254772D+00, &\n 0.7213475204444817D+00, &\n 0.6068261510845583D+00, &\n 0.5410106403333613D+00, &\n 0.4970679476476894D+00, &\n 0.4650921887927060D+00, &\n 0.4404842934597863D+00, &\n 0.4207860535926143D+00, &\n 0.4045507673897055D+00, &\n 0.3908650337129266D+00, &\n 0.2149757685421097D+00, &\n 0.0000000000000000D+00, &\n 0.2149757685421097D+00, &\n 0.3213887739704539D+00, &\n 0.3916213575531612D+00, &\n 0.4437690508633213D+00, &\n 0.4850700239649681D+00, &\n 0.5191433267738267D+00, &\n 0.5480569580144867D+00, &\n 0.5731033910767085D+00, &\n 0.5951442521714636D+00, &\n 0.6147826594068904D+00 /)\n integer ( kind = 4 ) n\n integer ( kind = 4 ) n_data\n integer ( kind = 4 ), save, dimension ( n_max ) :: n_vec = (/ &\n 1, 1, 1, 1, 1, &\n 1, 1, 1, 1, 1, &\n 1, 1, 1, 1, 1, &\n 1, 1, 1, 0, 1, &\n 2, 3, 4, 5, 6, &\n 7, 8, 9, 10 /)\n real ( kind = 8 ) t\n real ( kind = 8 ), save, dimension ( n_max ) :: t_vec = (/ &\n 0.1000000000000000D+00, &\n 0.1111111111111111D+00, &\n 0.1250000000000000D+00, &\n 0.1428571428571429D+00, &\n 0.1666666666666667D+00, &\n 0.2000000000000000D+00, &\n 0.2500000000000000D+00, &\n 0.3333333333333333D+00, &\n 0.5000000000000000D+00, &\n 0.6666666666666667D+00, &\n 0.7500000000000000D+00, &\n 0.8000000000000000D+00, &\n 0.8333333333333333D+00, &\n 0.8571485714857149D+00, &\n 0.8750000000000000D+00, &\n 0.8888888888888889D+00, &\n 0.9000000000000000D+00, &\n 0.9900000000000000D+00, &\n 0.9900000000000000D+00, &\n 0.9900000000000000D+00, &\n 0.9900000000000000D+00, &\n 0.9900000000000000D+00, &\n 0.9900000000000000D+00, &\n 0.9900000000000000D+00, &\n 0.9900000000000000D+00, &\n 0.9900000000000000D+00, &\n 0.9900000000000000D+00, &\n 0.9900000000000000D+00, &\n 0.9900000000000000D+00 /)\n\n if ( n_data < 0 ) then\n n_data = 0\n end if\n\n n_data = n_data + 1\n\n if ( n_max < n_data ) then\n n_data = 0\n t = 0.0D+00\n n = 0\n fx = 0.0D+00\n else\n t = t_vec(n_data)\n n = n_vec(n_data)\n fx = fx_vec(n_data)\n end if\n\n return\nend\nfunction log_series_check ( a )\n\n!*****************************************************************************80\n!\n!! LOG_SERIES_CHECK checks the parameter of the Logarithmic Series PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 22 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 0.0D+00 < A < 1.0.\n!\n! Output, logical LOG_SERIES_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n logical log_series_check\n\n if ( a <= 0.0D+00 .or. 1.0D+00 <= a ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'LOG_SERIES_CHECK - Fatal error!'\n write ( *, '(a)' ) ' A <= 0.0D+00 or 1.0D+00 <= A'\n log_series_check = .false.\n return\n end if\n\n log_series_check = .true.\n\n return\nend\nsubroutine log_series_mean ( a, mean )\n\n!*****************************************************************************80\n!\n!! LOG_SERIES_MEAN returns the mean of the Logarithmic Series PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 0.0D+00 < A < 1.0.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) mean\n\n mean = - a / ( ( 1.0D+00 - a ) * log ( 1.0D+00 - a ) )\n\n return\nend\nsubroutine log_series_pdf ( x, a, pdf )\n\n!*****************************************************************************80\n!\n!! LOG_SERIES_PDF evaluates the Logarithmic Series PDF.\n!\n! Discussion:\n!\n! PDF(A;X) = - A**X / ( X * log ( 1 - A ) )\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X, the argument of the PDF.\n! 0 < X\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 0.0D+00 < A < 1.0.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) pdf\n integer ( kind = 4 ) x\n\n if ( x <= 0 ) then\n pdf = 0.0D+00\n else\n pdf = - a**x / ( real ( x, kind = 8 ) * log ( 1.0D+00 - a ) )\n end if\n\n return\nend\nsubroutine log_series_sample ( a, seed, x )\n\n!*****************************************************************************80\n!\n!! LOG_SERIES_SAMPLE samples the Logarithmic Series PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 06 March 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Luc Devroye,\n! Non-Uniform Random Variate Generation,\n! Springer-Verlag, 1986, page 547.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 0.0D+00 < A < 1.0.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random\n! number generator.\n!\n! Output, integer ( kind = 4 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) u\n real ( kind = 8 ) v\n integer ( kind = 4 ) x\n\n u = r8_uniform_01 ( seed )\n v = r8_uniform_01 ( seed )\n\n x = int ( 1.0D+00 + log ( v ) / ( log ( 1.0D+00 - ( 1.0D+00 - a )**u ) ) )\n\n return\nend\nsubroutine log_series_variance ( a, variance )\n\n!*****************************************************************************80\n!\n!! LOG_SERIES_VARIANCE returns the variance of the Logarithmic Series PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 0.0D+00 < A < 1.0.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) alpha\n real ( kind = 8 ) variance\n\n alpha = - 1.0D+00 / log ( 1.0D+00 - a )\n\n variance = a * alpha * ( 1.0D+00 - alpha * a ) / ( 1.0D+00 - a )**2\n\n return\nend\nsubroutine log_uniform_cdf ( x, a, b, cdf )\n\n!*****************************************************************************80\n!\n!! LOG_UNIFORM_CDF evaluates the Log Uniform CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( x <= a ) then\n cdf = 0.0D+00\n else if ( x < b ) then\n cdf = ( log ( x ) - log ( a ) ) / ( log ( b ) - log ( a ) )\n else\n cdf = 1.0D+00\n end if\n\n return\nend\nsubroutine log_uniform_cdf_inv ( cdf, a, b, x )\n\n!*****************************************************************************80\n!\n!! LOG_UNIFORM_CDF_INV inverts the Log Uniform CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'LOG_UNIFORM_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n x = a * exp ( ( log ( b ) - log ( a ) ) * cdf )\n\n return\nend\nfunction log_uniform_check ( a, b )\n\n!*****************************************************************************80\n!\n!! LOG_UNIFORM_CHECK checks the parameters of the Log Uniform CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 1.0 < A < B.\n!\n! Output, logical LOG_UNIFORM_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n logical log_uniform_check\n\n if ( a <= 1.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'LOG_UNIFORM_CHECK - Fatal error!'\n write ( *, '(a)' ) ' A <= 1.'\n log_uniform_check = .false.\n return\n end if\n\n if ( b <= a ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'LOG_UNIFORM_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B <= A.'\n log_uniform_check = .false.\n return\n end if\n\n log_uniform_check = .true.\n\n return\nend\nsubroutine log_uniform_mean ( a, b, mean )\n\n!*****************************************************************************80\n!\n!! LOG_UNIFORM_MEAN returns the mean of the Log Uniform PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 1.0 < A < B.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) mean\n\n mean = ( b - a ) / ( log ( b ) - log ( a ) )\n\n return\nend\nsubroutine log_uniform_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! LOG_UNIFORM_PDF evaluates the Log Uniform PDF.\n!\n! Discussion:\n!\n! PDF(A,B;X) = 1 / ( X * ( log ( B ) - log ( A ) ) ) for A <= X <= B\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 1.0 < A < B.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) pdf\n real ( kind = 8 ) x\n\n if ( x < a ) then\n pdf = 0.0D+00\n else if ( x <= b ) then\n pdf = 1.0D+00 / ( x * ( log ( b ) - log ( a ) ) )\n else\n pdf = 0.0D+00\n end if\n\n return\nend\nsubroutine log_uniform_sample ( a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! LOG_UNIFORM_SAMPLE samples the Log Uniform PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 1.0 < A < B.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random\n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call log_uniform_cdf_inv ( cdf, a, b, x )\n\n return\nend\nsubroutine lorentz_cdf ( x, cdf )\n\n!*****************************************************************************80\n!\n!! LORENTZ_CDF evaluates the Lorentz CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) cdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) x\n\n cdf = 0.5D+00 + atan ( x ) / pi\n\n return\nend\nsubroutine lorentz_cdf_inv ( cdf, x )\n\n!*****************************************************************************80\n!\n!! LORENTZ_CDF_INV inverts the Lorentz CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument.\n!\n implicit none\n\n real ( kind = 8 ) cdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'LORENTZ_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n x = tan ( pi * ( cdf - 0.5D+00 ) )\n\n return\nend\nsubroutine lorentz_mean ( mean )\n\n!*****************************************************************************80\n!\n!! LORENTZ_MEAN returns the mean of the Lorentz PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) mean\n\n mean = 0.0D+00\n\n return\nend\nsubroutine lorentz_pdf ( x, pdf )\n\n!*****************************************************************************80\n!\n!! LORENTZ_PDF evaluates the Lorentz PDF.\n!\n! Discussion:\n!\n! PDF(X) = 1 / ( PI * ( 1 + X^2 ) )\n!\n! The chief interest of the Lorentz PDF is that it is easily\n! inverted, and can be used to dominate other PDF's in an\n! acceptance/rejection method.\n!\n! LORENTZ_PDF(X) = CAUCHY_PDF(0,1;X)\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) pdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) x\n\n pdf = 1.0D+00 / ( pi * ( 1.0D+00 + x * x ) )\n\n return\nend\nsubroutine lorentz_sample ( seed, x )\n\n!*****************************************************************************80\n!\n!! LORENTZ_SAMPLE samples the Lorentz PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random\n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call lorentz_cdf_inv ( cdf, x )\n\n return\nend\nsubroutine lorentz_variance ( variance )\n\n!*****************************************************************************80\n!\n!! LORENTZ_VARIANCE returns the variance of the Lorentz PDF.\n!\n! Discussion:\n!\n! The variance of the Lorentz PDF is not well defined. This routine\n! is made available for completeness only, and simply returns\n! a \"very large\" number.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Output, real ( kind = 8 ) VARIANCE, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) variance\n\n variance = huge ( variance )\n\n return\nend\nsubroutine maxwell_cdf ( x, a, cdf )\n\n!*****************************************************************************80\n!\n!! MAXWELL_CDF evaluates the Maxwell CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n! 0.0D+00 <= X\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 0 < A.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) cdf\n real ( kind = 8 ) gamma_inc\n real ( kind = 8 ) p2\n real ( kind = 8 ) x\n real ( kind = 8 ) x2\n\n if ( x <= 0.0D+00 ) then\n\n cdf = 0.0D+00\n\n else\n\n x2 = x / a\n p2 = 1.5D+00\n\n cdf = gamma_inc ( p2, x2 )\n\n end if\n\n return\nend\nsubroutine maxwell_cdf_inv ( cdf, a, x )\n\n!*****************************************************************************80\n!\n!! MAXWELL_CDF_INV inverts the Maxwell CDF.\n!\n! Discussion:\n!\n! A simple bisection method is used.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 May 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 0 < A.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) cdf\n real ( kind = 8 ) cdf1\n real ( kind = 8 ) cdf2\n real ( kind = 8 ) cdf3\n integer ( kind = 4 ) it\n integer ( kind = 4 ), parameter :: it_max = 100\n real ( kind = 8 ), parameter :: tol = 0.0001D+00\n real ( kind = 8 ) x\n real ( kind = 8 ) x1\n real ( kind = 8 ) x2\n real ( kind = 8 ) x3\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'MAXWELL_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n if ( cdf == 0.0D+00 ) then\n x = 0.0D+00\n return\n else if ( 1.0D+00 == cdf ) then\n x = huge ( x )\n return\n end if\n\n x1 = 0.0D+00\n cdf1 = 0.0D+00\n\n x2 = 1.0D+00\n\n do\n\n call maxwell_cdf ( x2, a, cdf2 )\n\n if ( cdf < cdf2 ) then\n exit\n end if\n\n x2 = 2.0D+00 * x2\n\n if ( 1000000.0D+00 < x2 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'MAXWELL_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' Initial bracketing effort fails.'\n stop 1\n end if\n\n end do\n!\n! Now use bisection.\n!\n it = 0\n\n do\n\n it = it + 1\n\n x3 = 0.5D+00 * ( x1 + x2 )\n call maxwell_cdf ( x3, a, cdf3 )\n\n if ( abs ( cdf3 - cdf ) < tol ) then\n x = x3\n exit\n end if\n\n if ( it_max < it ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'MAXWELL_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' Iteration limit exceeded.'\n stop 1\n end if\n\n if ( sign ( 1.0D+00, cdf3 - cdf ) == sign ( 1.0D+00, cdf1 - cdf ) ) then\n x1 = x3\n cdf1 = cdf3\n else\n x2 = x3\n cdf2 = cdf3\n end if\n\n end do\n\n return\nend\nfunction maxwell_check ( a )\n\n!*****************************************************************************80\n!\n!! MAXWELL_CHECK checks the parameters of the Maxwell CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 22 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 0 < A.\n!\n! Output, logical MAXWELL_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n logical maxwell_check\n\n if ( a <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'MAXWELL_CHECK - Fatal error!'\n write ( *, '(a)' ) ' A <= 0.0.'\n maxwell_check = .false.\n return\n end if\n\n maxwell_check = .true.\n\n return\nend\nsubroutine maxwell_mean ( a, mean )\n\n!*****************************************************************************80\n!\n!! MAXWELL_MEAN returns the mean of the Maxwell PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 0 < A.\n!\n! Output, real ( kind = 8 ) MEAN, the mean value.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) mean\n real ( kind = 8 ) r8_gamma\n\n mean = sqrt ( 2.0D+00 ) * a * r8_gamma ( 2.0D+00 ) / r8_gamma ( 1.5D+00 )\n\n return\nend\nsubroutine maxwell_pdf ( x, a, pdf )\n\n!*****************************************************************************80\n!\n!! MAXWELL_PDF evaluates the Maxwell PDF.\n!\n! Discussion:\n!\n! PDF(A;X) = exp ( - 0.5D+00 * ( X / A )^2 ) * ( X / A )^2 /\n! ( sqrt ( 2 ) * A * GAMMA ( 1.5D+00 ) )\n!\n! MAXWELL_PDF(A;X) = CHI_PDF(0,A,3;X)\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n! 0 < X\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 0 < A.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) pdf\n real ( kind = 8 ) r8_gamma\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n\n if ( x <= 0.0D+00 ) then\n\n pdf = 0.0D+00\n\n else\n\n y = x / a\n\n pdf = exp ( - 0.5D+00 * y * y ) * y * y &\n / ( sqrt ( 2.0D+00 ) * a * r8_gamma ( 1.5D+00 ) )\n\n end if\n\n return\nend\nsubroutine maxwell_sample ( a, seed, x )\n\n!*****************************************************************************80\n!\n!! MAXWELL_SAMPLE samples the Maxwell PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 0 < A.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random\n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) a2\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n a2 = 3.0D+00\n call chi_square_sample ( a2, seed, x )\n\n x = a * sqrt ( x )\n\n return\nend\nsubroutine maxwell_variance ( a, variance )\n\n!*****************************************************************************80\n!\n!! MAXWELL_VARIANCE returns the variance of the Maxwell PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 0 < A.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) r8_gamma\n real ( kind = 8 ) variance\n\n variance = a * a * ( 3.0D+00 - 2.0D+00 &\n * ( r8_gamma ( 2.0D+00 ) / r8_gamma ( 1.5D+00 ) )**2 )\n\n return\nend\nfunction multicoef_check ( nfactor, factor )\n\n!*****************************************************************************80\n!\n!! MULTICOEF_CHECK checks the parameters of the multinomial coefficient.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 22 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) NFACTOR, the number of factors.\n! 1 <= NFACTOR.\n!\n! Input, integer ( kind = 4 ) FACTOR(NFACTOR), contains the factors.\n! 0.0D+00 <= FACTOR(I).\n!\n! Output, logical MULTICOEF_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n integer ( kind = 4 ) nfactor\n\n integer ( kind = 4 ) factor(nfactor)\n integer ( kind = 4 ) i\n logical multicoef_check\n\n if ( nfactor < 1 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'MULTICOEF_CHECK - Fatal error!'\n write ( *, '(a)' ) ' NFACTOR < 1.'\n multicoef_check = .false.\n return\n end if\n\n do i = 1, nfactor\n\n if ( factor(i) < 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'MULTICOEF_CHECK - Fatal error'\n write ( *, '(a,i8)' ) ' Factor ', I\n write ( *, '(a,i8)' ) ' = ', factor(i)\n write ( *, '(a)' ) ' But this value must be nonnegative.'\n multicoef_check = .false.\n return\n end if\n\n end do\n\n multicoef_check = .true.\n\n return\nend\nsubroutine multinomial_coef1 ( nfactor, factor, ncomb )\n\n!*****************************************************************************80\n!\n!! MULTINOMIAL_COEF1 computes a Multinomial coefficient.\n!\n! Discussion:\n!\n! The multinomial coefficient is a generalization of the binomial\n! coefficient. It may be interpreted as the number of combinations of\n! N objects, where FACTOR(1) objects are indistinguishable of type 1,\n! ... and FACTOR(NFACTOR) are indistinguishable of type NFACTOR,\n! and N is the sum of FACTOR(1) through FACTOR(NFACTOR).\n!\n! NCOMB = N! / ( FACTOR(1)! FACTOR(2)! ... FACTOR(NFACTOR)! )\n!\n! The log of the gamma function is used, to avoid overflow.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) NFACTOR, the number of factors.\n! 1 <= NFACTOR.\n!\n! Input, integer ( kind = 4 ) FACTOR(NFACTOR), contains the factors.\n! 0.0D+00 <= FACTOR(I).\n!\n! Output, integer ( kind = 4 ) NCOMB, the value of the multinomial\n! coefficient.\n!\n implicit none\n\n integer ( kind = 4 ) nfactor\n\n logical check\n real ( kind = 8 ) facn\n integer ( kind = 4 ) factor(nfactor)\n real ( kind = 8 ) factorial_log\n integer ( kind = 4 ) i\n integer ( kind = 4 ) i4_huge\n logical multicoef_check\n integer ( kind = 4 ) n\n integer ( kind = 4 ) ncomb\n\n check = multicoef_check ( nfactor, factor )\n\n if ( .not. check ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'MULTINOMIAL_COEF1 - Fatal error!'\n write ( *, '(a)' ) ' MULTICOEF_CHECK failed.'\n ncomb = - i4_huge ( )\n return\n end if\n!\n! The factors sum to N.\n!\n n = sum ( factor(1:nfactor) )\n\n facn = factorial_log ( n )\n\n do i = 1, nfactor\n\n facn = facn - factorial_log ( factor(i) )\n\n end do\n\n ncomb = nint ( exp ( facn ) )\n\n return\nend\nsubroutine multinomial_coef2 ( nfactor, factor, ncomb )\n\n!*****************************************************************************80\n!\n!! MULTINOMIAL_COEF2 computes a Multinomial coefficient.\n!\n! Discussion:\n!\n! The multinomial coefficient is a generalization of the binomial\n! coefficient. It may be interpreted as the number of combinations of\n! N objects, where FACTOR(1) objects are indistinguishable of type 1,\n! ... and FACTOR(NFACTOR) are indistinguishable of type NFACTOR,\n! and N is the sum of FACTOR(1) through FACTOR(NFACTOR).\n!\n! NCOMB = N! / ( FACTOR(1)! FACTOR(2)! ... FACTOR(NFACTOR)! )\n!\n! A direct method is used, which should be exact. However, there\n! is a possibility of intermediate overflow of the result.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) NFACTOR, the number of factors.\n! 1 <= NFACTOR.\n!\n! Input, integer ( kind = 4 ) FACTOR(NFACTOR), contains the factors.\n! 0.0D+00 <= FACTOR(I).\n!\n! Output, integer ( kind = 4 ) NCOMB, the value of the multinomial\n! coefficient.\n!\n implicit none\n\n integer ( kind = 4 ) nfactor\n\n logical check\n integer ( kind = 4 ) factor(nfactor)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) i4_huge\n integer ( kind = 4 ) j\n integer ( kind = 4 ) k\n logical multicoef_check\n integer ( kind = 4 ) ncomb\n\n check = multicoef_check ( nfactor, factor )\n\n if ( .not. check ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'MULTINOMIAL_COEF2 - Fatal error!'\n write ( *, '(a)' ) ' MULTICOEF_CHECK failed.'\n ncomb = - i4_huge ( )\n return\n end if\n\n ncomb = 1\n k = 0\n\n do i = 1, nfactor\n\n do j = 1, factor(i)\n k = k + 1\n ncomb = ( ncomb * k ) / j\n end do\n\n end do\n\n return\nend\nfunction multinomial_check ( a, b, c )\n\n!*****************************************************************************80\n!\n!! MULTINOMIAL_CHECK checks the parameters of the Multinomial PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 22 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, the number of trials.\n!\n! Input, integer ( kind = 4 ) B, the number of outcomes possible on one\n! trial. 1 <= B.\n!\n! Input, real ( kind = 8 ) C(B). C(I) is the probability of outcome I on\n! any trial.\n! 0.0D+00 <= C(I) <= 1.0D+00,\n! Sum ( 1 <= I <= B ) C(I) = 1.0.\n!\n! Output, logical MULTINOMIAL_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n integer ( kind = 4 ) b\n\n integer ( kind = 4 ) a\n real ( kind = 8 ) c(b)\n real ( kind = 8 ) c_sum\n integer ( kind = 4 ) i\n logical multinomial_check\n\n if ( b < 1 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'MULTINOMIAL_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B < 1.'\n multinomial_check = .false.\n return\n end if\n\n do i = 1, b\n\n if ( c(i) < 0.0D+00 .or. 1.0D+00 < c(i) ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'MULTINOMIAL_CHECK - Fatal error!'\n write ( *, '(a)' ) ' Input C(I) is out of range.'\n multinomial_check = .false.\n return\n end if\n\n end do\n\n c_sum = sum ( c )\n\n if ( 0.0001D+00 < abs ( 1.0D+00 - c_sum ) ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'MULTINOMIAL_CHECK - Fatal error!'\n write ( *, '(a)' ) ' The probabilities do not sum to 1.'\n multinomial_check = .false.\n return\n end if\n\n multinomial_check = .true.\n\n return\nend\nsubroutine multinomial_covariance ( a, b, c, covariance )\n\n!*****************************************************************************80\n!\n!! MULTINOMIAL_COVARIANCE returns the covariances of the Multinomial PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 14 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, the number of trials.\n!\n! Input, integer ( kind = 4 ) B, the number of outcomes possible on one\n! trial. 1 <= B.\n!\n! Input, real ( kind = 8 ) C(B). C(I) is the probability of outcome I on\n! any trial.\n! 0.0D+00 <= C(I) <= 1.0D+00,\n! SUM ( 1 <= I <= B) C(I) = 1.0.\n!\n! Output, real ( kind = 8 ) COVARIANCE(B,B), the covariance matrix.\n!\n implicit none\n\n integer ( kind = 4 ) b\n\n integer ( kind = 4 ) a\n real ( kind = 8 ) c(b)\n real ( kind = 8 ) covariance(b,b)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) j\n\n do i = 1, b\n do j = 1, b\n\n if ( i == j ) then\n covariance(i,j) = real ( a, kind = 8 ) * c(i) * ( 1.0D+00 - c(i) )\n else\n covariance(i,j) = - real ( a, kind = 8 ) * c(i) * c(j)\n end if\n\n end do\n end do\n\n return\nend\nsubroutine multinomial_mean ( a, b, c, mean )\n\n!*****************************************************************************80\n!\n!! MULTINOMIAL_MEAN returns the means of the Multinomial PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 31 January 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, the number of trials.\n!\n! Input, integer ( kind = 4 ) B, the number of outcomes possible on one\n! trial. 1 <= B.\n!\n! Input, real ( kind = 8 ) C(B). C(I) is the probability of outcome I on\n! any trial.\n! 0.0D+00 <= C(I) <= 1.0D+00,\n! SUM ( 1 <= I <= B) C(I) = 1.0.\n!\n! Output, real ( kind = 8 ) MEAN(B), MEAN(I) is the expected value of the\n! number of outcome I in N trials.\n!\n implicit none\n\n integer ( kind = 4 ) b\n\n integer ( kind = 4 ) a\n real ( kind = 8 ) c(b)\n real ( kind = 8 ) mean(b)\n\n mean(1:b) = real ( a, kind = 8 ) * c(1:b)\n\n return\nend\nsubroutine multinomial_pdf ( x, a, b, c, pdf )\n\n!*****************************************************************************80\n!\n!! MULTINOMIAL_PDF computes a Multinomial PDF.\n!\n! Discussion:\n!\n! PDF(A,B,C;X) = Comb(A,B,X) * Product ( 1 <= I <= B ) C(I)^X(I)\n!\n! where Comb(A,B,X) is the multinomial coefficient\n! C( A; X(1), X(2), ..., X(B) )\n!\n! PDF(A,B,C;X) is the probability that in A trials there\n! will be exactly X(I) occurrences of event I, whose probability\n! on one trial is C(I), for I from 1 to B.\n!\n! As soon as A or B gets large, the number of possible X's explodes,\n! and the probability of any particular X can become extremely small.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 14 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X(B); X(I) counts the number of occurrences of\n! outcome I, out of the total of A trials.\n!\n! Input, integer ( kind = 4 ) A, the total number of trials.\n!\n! Input, integer ( kind = 4 ) B, the number of different possible outcomes on\n! one trial.\n!\n! Input, real ( kind = 8 ) C(B); C(I) is the probability of outcome I on\n! any one trial.\n!\n! Output, real ( kind = 8 ) PDF, the value of the multinomial PDF.\n!\n implicit none\n\n integer ( kind = 4 ) b\n\n integer ( kind = 4 ) a\n real ( kind = 8 ) c(b)\n real ( kind = 8 ) gamma_log\n integer ( kind = 4 ) i\n real ( kind = 8 ) pdf\n real ( kind = 8 ) pdf_log\n integer ( kind = 4 ) x(b)\n!\n! To try to avoid overflow, do the calculation in terms of logarithms.\n! Note that Gamma(A+1) = A factorial.\n!\n pdf_log = gamma_log ( real ( a + 1, kind = 8 ) )\n\n do i = 1, b\n pdf_log = pdf_log + x(i) * log ( c(i) ) &\n - gamma_log ( real ( x(i) + 1, kind = 8 ) )\n end do\n\n pdf = exp ( pdf_log )\n\n return\nend\nsubroutine multinomial_sample ( a, b, c, seed, x )\n\n!*****************************************************************************80\n!\n!! MULTINOMIAL_SAMPLE samples the Multinomial PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 14 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Luc Devroye,\n! Non-Uniform Random Variate Generation,\n! Springer-Verlag, New York, 1986, page 559.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, the total number of trials.\n! 0 <= A.\n!\n! Input, integer ( kind = 4 ) B, the number of outcomes possible on\n! one trial. 1 <= B.\n!\n! Input, real ( kind = 8 ) C(B). C(I) is the probability of outcome I on\n! any trial.\n! 0.0D+00 <= C(I) <= 1.0D+00,\n! sum ( 1 <= I <= B) C(I) = 1.0.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random\n! number generator.\n!\n! Output, integer ( kind = 4 ) X(B); X(I) is the number of\n! occurrences of event I during the N trials.\n!\n implicit none\n\n integer ( kind = 4 ) b\n\n integer ( kind = 4 ) a\n real ( kind = 8 ) c(b)\n integer ( kind = 4 ) ifactor\n integer ( kind = 4 ) ntot\n real ( kind = 8 ) prob\n integer ( kind = 4 ) seed\n real ( kind = 8 ) sum2\n integer ( kind = 4 ) x(b)\n\n ntot = a\n\n sum2 = 1.0D+00\n\n x(1:b) = 0\n\n do ifactor = 1, b - 1\n\n prob = c(ifactor) / sum2\n!\n! Generate a binomial random deviate for NTOT trials with\n! single trial success probability PROB.\n!\n call binomial_sample ( ntot, prob, seed, x(ifactor) )\n\n ntot = ntot - x(ifactor)\n if ( ntot <= 0 ) then\n return\n end if\n\n sum2 = sum2 - c(ifactor)\n\n end do\n!\n! The last factor gets what's left.\n!\n x(b) = ntot\n\n return\nend\nsubroutine multinomial_variance ( a, b, c, variance )\n\n!*****************************************************************************80\n!\n!! MULTINOMIAL_VARIANCE returns the variances of the Multinomial PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 31 January 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, the number of trials.\n!\n! Input, integer ( kind = 4 ) B, the number of outcomes possible on one\n! trial. 1 <= B.\n!\n! Input, real ( kind = 8 ) C(B). C(I) is the probability of outcome I on\n! any trial.\n! 0.0D+00 <= C(I) <= 1.0D+00,\n! sum ( 1 <= I <= B ) C(I) = 1.0.\n!\n! Output, real ( kind = 8 ) VARIANCE(B), VARIANCE(I) is the variance of the\n! total number of events of type I.\n!\n implicit none\n\n integer ( kind = 4 ) b\n\n integer ( kind = 4 ) a\n real ( kind = 8 ) c(b)\n integer ( kind = 4 ) i\n real ( kind = 8 ) variance(b)\n\n do i = 1, b\n variance(i) = real ( a, kind = 8 ) * c(i) * ( 1.0D+00 - c(i) )\n end do\n\n return\nend\nsubroutine multivariate_normal_sample ( n, mean, covar_factor, seed, x )\n\n!*****************************************************************************80\n!\n!! MULTIVARIATE_NORMAL_SAMPLE samples the Multivariate Normal PDF.\n!\n! Discussion:\n!\n! PDF ( Mean(1:N), S(1:N,1:N); X(1:N) ) = \n! 1 / ( 2 * pi ) ^ ( N / 2 ) * 1 / det ( S )\n! * exp ( - ( X - Mean )' * inverse ( S ) * ( X - Mean ) / 2 )\n!\n! Here,\n!\n! X is the argument vector of length N,\n! Mean is the mean vector of length N,\n! S is an N by N positive definite symmetric covariance matrix.\n!\n! The properties of S guarantee that it has a lower triangular\n! matrix L, the Cholesky factor, such that S = L * L'. It is the\n! matrix L, rather than S, that is required by this routine.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Jerry Banks, editor,\n! Handbook of Simulation,\n! Engineering and Management Press Books, 1998, page 167.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the spatial dimension.\n!\n! Input, real ( kind = 8 ) MEAN(N), the mean vector.\n!\n! Input, real ( kind = 8 ) COVAR_FACTOR(N,N), the lower triangular Cholesky\n! factor L of the covariance matrix S.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random\n! number generator.\n!\n! Output, real ( kind = 8 ) X(N), a sample point of the distribution.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) covar_factor(n,n)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) j\n real ( kind = 8 ) mean(n)\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x(n)\n real ( kind = 8 ) z\n\n do i = 1, n\n\n call normal_01_sample ( seed, z )\n\n x(i) = mean(i)\n\n do j = 1, i\n x(i) = x(i) + covar_factor(i,j) * z\n end do\n\n end do\n\n return\nend\nsubroutine nakagami_cdf ( x, a, b, c, cdf )\n\n!*****************************************************************************80\n!\n!! NAKAGAMI_CDF evaluates the Nakagami CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < B\n! 0.0D+00 < C.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) cdf\n real ( kind = 8 ) gamma_inc\n real ( kind = 8 ) p2\n real ( kind = 8 ) x\n real ( kind = 8 ) x2\n real ( kind = 8 ) y\n\n if ( x <= 0.0D+00 ) then\n\n cdf = 0.0D+00\n\n else if ( 0.0D+00 < x ) then\n\n y = ( x - a ) / b\n x2 = c * y * y\n p2 = c\n\n cdf = gamma_inc ( p2, x2 )\n\n end if\n\n return\nend\nfunction nakagami_check ( a, b, c )\n\n!*****************************************************************************80\n!\n!! NAKAGAMI_CHECK checks the parameters of the Nakagami PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 22 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < B,\n! 0.0D+00 < C.\n!\n! Output, logical NAKAGAMI_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n logical nakagami_check\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'NAKAGAMI_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B <= 0.'\n nakagami_check = .false.\n return\n end if\n\n if ( c <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'NAKAGAMI_CHECK - Fatal error!'\n write ( *, '(a)' ) ' C <= 0.'\n nakagami_check = .false.\n return\n end if\n\n nakagami_check = .true.\n\n return\nend\nsubroutine nakagami_mean ( a, b, c, mean )\n\n!*****************************************************************************80\n!\n!! NAKAGAMI_MEAN returns the mean of the Nakagami PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < B\n! 0.0D+00 < C\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) mean\n real ( kind = 8 ) r8_gamma\n\n mean = a + b * r8_gamma ( c + 0.5D+00 ) / ( sqrt ( c ) * r8_gamma ( c ) )\n\n return\nend\nsubroutine nakagami_pdf ( x, a, b, c, pdf )\n\n!*****************************************************************************80\n!\n!! NAKAGAMI_PDF evaluates the Nakagami PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 03 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < B\n! 0.0D+00 < C.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) pdf\n real ( kind = 8 ) r8_gamma\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n\n if ( x <= 0.0D+00 ) then\n\n pdf = 0.0D+00\n\n else if ( 0.0D+00 < x ) then\n\n y = ( x - a ) / b\n\n pdf = 2.0D+00 * c**c / ( b * r8_gamma ( c ) ) &\n * y**( 2.0D+00 * c - 1.0D+00 ) &\n * exp ( - c * y * y )\n\n end if\n\n return\nend\nsubroutine nakagami_variance ( a, b, c, variance )\n\n!*****************************************************************************80\n!\n!! NAKAGAMI_VARIANCE returns the variance of the Nakagami PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < B\n! 0.0D+00 < C\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) r8_gamma\n real ( kind = 8 ) t1\n real ( kind = 8 ) t2\n real ( kind = 8 ) variance\n\n t1 = r8_gamma ( c + 0.5D+00 )\n t2 = r8_gamma ( c )\n\n variance = b * b * ( 1.0D+00 - t1 * t1 / ( c * t2 * t2 ) )\n\n return\nend\nsubroutine negative_binomial_cdf ( x, a, b, cdf )\n\n!*****************************************************************************80\n!\n!! NEGATIVE_BINOMIAL_CDF evaluates the Negative Binomial CDF.\n!\n! Discussion:\n!\n! A simple summing approach is used.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 19 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X, the argument of the CDF.\n!\n! Input, integer ( kind = 4 ) A, a parameter of the PDF.\n! 0 <= A.\n!\n! Input, real ( kind = 8 ) B, a parameter of the PDF.\n! 0 < B <= 1.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n integer ( kind = 4 ) cnk\n real ( kind = 8 ) pdf\n integer ( kind = 4 ) x\n integer ( kind = 4 ) y\n\n cdf = 0.0D+00\n\n do y = a, x\n\n call binomial_coef ( y - 1, a - 1, cnk )\n\n pdf = real ( cnk, kind = 8 ) * b**a * ( 1.0D+00 - b )**( y - a )\n\n cdf = cdf + pdf\n\n end do\n\n return\nend\nsubroutine negative_binomial_cdf_inv ( cdf, a, b, x )\n\n!*****************************************************************************80\n!\n!! NEGATIVE_BINOMIAL_CDF_INV inverts the Negative Binomial CDF.\n!\n! Discussion:\n!\n! A simple discrete approach is used.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 06 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n!\n! Input, integer ( kind = 4 ) A, a parameter of the PDF.\n! 0 <= A.\n!\n! Input, real ( kind = 8 ) B, a parameter of the PDF.\n! 0 < B <= 1.\n!\n! Output, integer ( kind = 4 ) X, the smallest X whose cumulative density\n! function is greater than or equal to CDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) cum\n real ( kind = 8 ) pdf\n integer ( kind = 4 ) x\n integer ( kind = 4 ), parameter :: x_max = 1000\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'NEGATIVE_BINOMIAL_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n\n cum = 0.0D+00\n\n x = a\n\n do\n\n call negative_binomial_pdf ( x, a, b, pdf )\n\n cum = cum + pdf\n\n if ( cdf <= cum .or. x_max <= x ) then\n exit\n end if\n\n x = x + 1\n\n end do\n\n return\nend\nsubroutine negative_binomial_cdf_values ( n_data, f, s, p, cdf )\n\n!*****************************************************************************80\n!\n!! NEGATIVE_BINOMIAL_CDF_VALUES returns values of the negative binomial CDF.\n!\n! Discussion:\n!\n! Assume that a coin has a probability P of coming up heads on\n! any one trial. Suppose that we plan to flip the coin until we\n! achieve a total of S heads. If we let F represent the number of\n! tails that occur in this process, then the value of F satisfies\n! a negative binomial PDF:\n!\n! PDF(F,S,P) = Choose ( F from F+S-1 ) * P^S * (1-P)^F\n!\n! The negative binomial CDF is the probability that there are F or\n! fewer failures upon the attainment of the S-th success. Thus,\n!\n! CDF(F,S,P) = sum ( 0 <= G <= F ) PDF(G,S,P)\n!\n! In Mathematica, the function can be evaluated by:\n!\n! Needs[\"Statistics`DiscreteDistributions`]\n! dist = NegativeBinomialDistribution [ s, p ]\n! CDF [ dist, f ]\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 24 August 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! FC Powell,\n! Statistical Tables for Sociology, Biology and Physical Sciences,\n! Cambridge University Press, 1982.\n!\n! Stephen Wolfram,\n! The Mathematica Book,\n! Fourth Edition,\n! Wolfram Media / Cambridge University Press, 1999.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) N_DATA. The user sets N_DATA to 0\n! before the first call. On each call, the routine increments N_DATA by 1,\n! and returns the corresponding data; when there is no more data, the\n! output value of N_DATA will be 0 again.\n!\n! Output, integer ( kind = 4 ) F, the maximum number of failures.\n!\n! Output, integer ( kind = 4 ) S, the number of successes.\n!\n! Output, real ( kind = 8 ) P, the probability of a success on one trial.\n!\n! Output, real ( kind = 8 ) CDF, the probability of at most F failures\n! before the S-th success.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: n_max = 27\n\n real ( kind = 8 ) cdf\n real ( kind = 8 ), save, dimension ( n_max ) :: cdf_vec = (/ &\n 0.6367187500000000D+00, &\n 0.3632812500000000D+00, &\n 0.1445312500000000D+00, &\n 0.5000000000000000D+00, &\n 0.2265625000000000D+00, &\n 0.6250000000000000D-01, &\n 0.3437500000000000D+00, &\n 0.1093750000000000D+00, &\n 0.1562500000000000D-01, &\n 0.1792000000000000D+00, &\n 0.4096000000000000D-01, &\n 0.4096000000000000D-02, &\n 0.7047000000000000D-01, &\n 0.1093500000000000D-01, &\n 0.7290000000000000D-03, &\n 0.9861587127990000D+00, &\n 0.9149749500510000D+00, &\n 0.7471846521450000D+00, &\n 0.8499053647030009D+00, &\n 0.5497160941090026D+00, &\n 0.2662040052146710D+00, &\n 0.6513215599000000D+00, &\n 0.2639010709000000D+00, &\n 0.7019082640000000D-01, &\n 0.1000000000000000D+01, &\n 0.1990000000000000D-01, &\n 0.1000000000000000D-03 /)\n integer ( kind = 4 ) f\n integer ( kind = 4 ), save, dimension ( n_max ) :: f_vec = (/ &\n 4, 3, 2, &\n 3, 2, 1, &\n 2, 1, 0, &\n 2, 1, 0, &\n 2, 1, 0, &\n 11, 10, 9, &\n 17, 16, 15, &\n 9, 8, 7, &\n 2, 1, 0 /)\n integer ( kind = 4 ) n_data\n real ( kind = 8 ) p\n real ( kind = 8 ), save, dimension ( n_max ) :: p_vec = (/ &\n 0.50D+00, &\n 0.50D+00, &\n 0.50D+00, &\n 0.50D+00, &\n 0.50D+00, &\n 0.50D+00, &\n 0.50D+00, &\n 0.50D+00, &\n 0.50D+00, &\n 0.40D+00, &\n 0.40D+00, &\n 0.40D+00, &\n 0.30D+00, &\n 0.30D+00, &\n 0.30D+00, &\n 0.30D+00, &\n 0.30D+00, &\n 0.30D+00, &\n 0.10D+00, &\n 0.10D+00, &\n 0.10D+00, &\n 0.10D+00, &\n 0.10D+00, &\n 0.10D+00, &\n 0.10D-01, &\n 0.10D-01, &\n 0.10D-01 /)\n integer ( kind = 4 ) s\n integer ( kind = 4 ), save, dimension ( n_max ) :: s_vec = (/ &\n 4, 5, 6, &\n 4, 5, 6, &\n 4, 5, 6, &\n 4, 5, 6, &\n 4, 5, 6, &\n 1, 2, 3, &\n 1, 2, 3, &\n 1, 2, 3, &\n 0, 1, 2 /)\n\n if ( n_data < 0 ) then\n n_data = 0\n end if\n\n n_data = n_data + 1\n\n if ( n_max < n_data ) then\n n_data = 0\n f = 0\n s = 0\n p = 0.0D+00\n cdf = 0.0D+00\n else\n f = f_vec(n_data)\n s = s_vec(n_data)\n p = p_vec(n_data)\n cdf = cdf_vec(n_data)\n end if\n\n return\nend\nfunction negative_binomial_check ( a, b )\n\n!*****************************************************************************80\n!\n!! NEGATIVE_BINOMIAL_CHECK checks the parameters of the Negative Binomial PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 22 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, a parameter of the PDF.\n! 0 <= A.\n!\n! Input, real ( kind = 8 ) B, a parameter of the PDF.\n! 0 < B <= 1.\n!\n! Output, logical NEGATIVE_BINOMIAL_CHECK, is true if the\n! parameters are legal.\n!\n implicit none\n\n integer ( kind = 4 ) a\n real ( kind = 8 ) b\n logical negative_binomial_check\n\n if ( a < 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'NEGATIVE_BINOMIAL_CHECK - Fatal error!'\n write ( *, '(a)' ) ' A < 0.'\n negative_binomial_check = .false.\n return\n end if\n\n if ( b <= 0.0D+00 .or. 1.0D+00 < b ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'NEGATIVE_BINOMIAL_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B <= 0 or 1 < B.'\n negative_binomial_check = .false.\n return\n end if\n\n negative_binomial_check = .true.\n\n return\nend\nsubroutine negative_binomial_mean ( a, b, mean )\n\n!*****************************************************************************80\n!\n!! NEGATIVE_BINOMIAL_MEAN returns the mean of the Negative Binomial PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 January 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, a parameter of the PDF.\n! 0 <= A.\n!\n! Input, real ( kind = 8 ) B, a parameter of the PDF.\n! 0 < B <= 1.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) mean\n\n mean = real ( a, kind = 8 ) / b\n\n return\nend\nsubroutine negative_binomial_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! NEGATIVE_BINOMIAL_PDF evaluates the Negative Binomial PDF.\n!\n! Discussion:\n!\n! PDF(A,B;X) = C(X-1,A-1) * B^A * ( 1 - B )^(X-A)\n!\n! PDF(A,B;X) is the probability that the A-th success will\n! occur on the X-th trial, given that the probability\n! of a success on a single trial is B.\n!\n! The Negative Binomial PDF is also known as the Pascal PDF or\n! the \"Polya\" PDF.\n!\n! NEGATIVE_BINOMIAL_PDF(1,B;X) = GEOMETRIC_PDF(B;X)\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 January 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X, the number of trials.\n! A <= X.\n!\n! Input, integer ( kind = 4 ) A, the number of successes required.\n! 0 <= A <= X, normally.\n!\n! Input, real ( kind = 8 ) B, the probability of a success on a single trial.\n! 0.0 < B <= 1.0.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n real ( kind = 8 ) b\n integer ( kind = 4 ) cnk\n real ( kind = 8 ) pdf\n integer ( kind = 4 ) x\n\n if ( x < a ) then\n\n pdf = 0.0D+00\n\n else\n\n call binomial_coef ( x - 1, a - 1, cnk )\n\n pdf = real ( cnk, kind = 8 ) * b**a * ( 1.0D+00 - b )**( x - a )\n\n end if\n\n return\nend\nsubroutine negative_binomial_sample ( a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! NEGATIVE_BINOMIAL_SAMPLE samples the Negative Binomial PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, a parameter of the PDF.\n! 0 <= A.\n!\n! Input, real ( kind = 8 ) B, a parameter of the PDF.\n! 0 < B <= 1.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random number\n! generator.\n!\n! Output, integer ( kind = 4 ) X, a sample of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n real ( kind = 8 ) b\n integer ( kind = 4 ) i4_huge\n integer ( kind = 4 ) num_success\n real ( kind = 8 ) r\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n integer ( kind = 4 ) x\n\n if ( b == 1.0D+00 ) then\n x = a\n return\n else if ( b == 0.0D+00 ) then\n x = i4_huge ( )\n return\n end if\n\n x = 0\n num_success = 0\n\n do while ( num_success < a )\n\n x = x + 1\n r = r8_uniform_01 ( seed )\n\n if ( r <= b ) then\n num_success = num_success + 1\n end if\n\n end do\n\n return\nend\nsubroutine negative_binomial_variance ( a, b, variance )\n\n!*****************************************************************************80\n!\n!! NEGATIVE_BINOMIAL_VARIANCE returns the variance of the Negative Binomial PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 January 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, a parameter of the PDF.\n! 0 <= A.\n!\n! Input, real ( kind = 8 ) B, a parameter of the PDF.\n! 0 < B <= 1.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) variance\n\n variance = real ( a, kind = 8 ) * ( 1.0D+00 - b ) / ( b * b )\n\n return\nend\nsubroutine normal_01_cdf ( x, cdf )\n\n!*****************************************************************************80\n!\n!! NORMAL_01_CDF evaluates the Normal 01 CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 10 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! AG Adams,\n! Algorithm 39,\n! Areas Under the Normal Curve,\n! Computer Journal,\n! Volume 12, pages 197-198, 1969.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ), parameter :: a1 = 0.398942280444D+00\n real ( kind = 8 ), parameter :: a2 = 0.399903438504D+00\n real ( kind = 8 ), parameter :: a3 = 5.75885480458D+00\n real ( kind = 8 ), parameter :: a4 = 29.8213557808D+00\n real ( kind = 8 ), parameter :: a5 = 2.62433121679D+00\n real ( kind = 8 ), parameter :: a6 = 48.6959930692D+00\n real ( kind = 8 ), parameter :: a7 = 5.92885724438D+00\n real ( kind = 8 ), parameter :: b0 = 0.398942280385D+00\n real ( kind = 8 ), parameter :: b1 = 3.8052D-08\n real ( kind = 8 ), parameter :: b2 = 1.00000615302D+00\n real ( kind = 8 ), parameter :: b3 = 3.98064794D-04\n real ( kind = 8 ), parameter :: b4 = 1.98615381364D+00\n real ( kind = 8 ), parameter :: b5 = 0.151679116635D+00\n real ( kind = 8 ), parameter :: b6 = 5.29330324926D+00\n real ( kind = 8 ), parameter :: b7 = 4.8385912808D+00\n real ( kind = 8 ), parameter :: b8 = 15.1508972451D+00\n real ( kind = 8 ), parameter :: b9 = 0.742380924027D+00\n real ( kind = 8 ), parameter :: b10 = 30.789933034D+00\n real ( kind = 8 ), parameter :: b11 = 3.99019417011D+00\n real ( kind = 8 ) cdf\n real ( kind = 8 ) q\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n!\n! |X| <= 1.28.\n!\n if ( abs ( x ) <= 1.28D+00 ) then\n\n y = 0.5D+00 * x * x\n\n q = 0.5D+00 - abs ( x ) * ( a1 - a2 * y / ( y + a3 - a4 / ( y + a5 &\n + a6 / ( y + a7 ) ) ) )\n!\n! 1.28 < |X| <= 12.7\n!\n else if ( abs ( x ) <= 12.7D+00 ) then\n\n y = 0.5D+00 * x * x\n\n q = exp ( - y ) * b0 / ( abs ( x ) - b1 &\n + b2 / ( abs ( x ) + b3 &\n + b4 / ( abs ( x ) - b5 &\n + b6 / ( abs ( x ) + b7 &\n - b8 / ( abs ( x ) + b9 &\n + b10 / ( abs ( x ) + b11 ) ) ) ) ) )\n!\n! 12.7 < |X|\n!\n else\n\n q = 0.0D+00\n\n end if\n!\n! Take account of negative X.\n!\n if ( x < 0.0D+00 ) then\n cdf = q\n else\n cdf = 1.0D+00 - q\n end if\n\n return\nend\nsubroutine normal_01_cdf_inv ( p, x )\n\n!*****************************************************************************80\n!\n!! NORMAL_01_CDF_INV inverts the standard normal CDF.\n!\n! Discussion:\n!\n! The result is accurate to about 1 part in 10^16.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 June 2007\n!\n! Author:\n!\n! Original FORTRAN77 version by Michael Wichura.\n! FORTRAN90 version by John Burkardt.\n!\n! Reference:\n!\n! Michael Wichura,\n! Algorithm AS241:\n! The Percentage Points of the Normal Distribution,\n! Applied Statistics,\n! Volume 37, Number 3, pages 477-484, 1988.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) P, the value of the cumulative probability\n! densitity function. 0 < P < 1. If P is outside this range, an\n! \"infinite\" value will be returned.\n!\n! Output, real ( kind = 8 ) X, the normal deviate value\n! with the property that the probability of a standard normal deviate being\n! less than or equal to the value is P.\n!\n implicit none\n\n real ( kind = 8 ), parameter, dimension ( 8 ) :: a = (/ &\n 3.3871328727963666080D+00, &\n 1.3314166789178437745D+02, &\n 1.9715909503065514427D+03, &\n 1.3731693765509461125D+04, &\n 4.5921953931549871457D+04, &\n 6.7265770927008700853D+04, &\n 3.3430575583588128105D+04, &\n 2.5090809287301226727D+03 /)\n real ( kind = 8 ), parameter, dimension ( 8 ) :: b = (/ &\n 1.0D+00, &\n 4.2313330701600911252D+01, &\n 6.8718700749205790830D+02, &\n 5.3941960214247511077D+03, &\n 2.1213794301586595867D+04, &\n 3.9307895800092710610D+04, &\n 2.8729085735721942674D+04, &\n 5.2264952788528545610D+03 /)\n real ( kind = 8 ), parameter, dimension ( 8 ) :: c = (/ &\n 1.42343711074968357734D+00, &\n 4.63033784615654529590D+00, &\n 5.76949722146069140550D+00, &\n 3.64784832476320460504D+00, &\n 1.27045825245236838258D+00, &\n 2.41780725177450611770D-01, &\n 2.27238449892691845833D-02, &\n 7.74545014278341407640D-04 /)\n real ( kind = 8 ), parameter :: const1 = 0.180625D+00\n real ( kind = 8 ), parameter :: const2 = 1.6D+00\n real ( kind = 8 ), parameter, dimension ( 8 ) :: d = (/ &\n 1.0D+00, &\n 2.05319162663775882187D+00, &\n 1.67638483018380384940D+00, &\n 6.89767334985100004550D-01, &\n 1.48103976427480074590D-01, &\n 1.51986665636164571966D-02, &\n 5.47593808499534494600D-04, &\n 1.05075007164441684324D-09 /)\n real ( kind = 8 ), parameter, dimension ( 8 ) :: e = (/ &\n 6.65790464350110377720D+00, &\n 5.46378491116411436990D+00, &\n 1.78482653991729133580D+00, &\n 2.96560571828504891230D-01, &\n 2.65321895265761230930D-02, &\n 1.24266094738807843860D-03, &\n 2.71155556874348757815D-05, &\n 2.01033439929228813265D-07 /)\n real ( kind = 8 ), parameter, dimension ( 8 ) :: f = (/ &\n 1.0D+00, &\n 5.99832206555887937690D-01, &\n 1.36929880922735805310D-01, &\n 1.48753612908506148525D-02, &\n 7.86869131145613259100D-04, &\n 1.84631831751005468180D-05, &\n 1.42151175831644588870D-07, &\n 2.04426310338993978564D-15 /)\n real ( kind = 8 ) p\n real ( kind = 8 ) q\n real ( kind = 8 ) r\n real ( kind = 8 ) r8poly_value\n real ( kind = 8 ), parameter :: split1 = 0.425D+00\n real ( kind = 8 ), parameter :: split2 = 5.0D+00\n real ( kind = 8 ) x\n\n if ( p <= 0.0D+00 ) then\n x = - huge ( x )\n return\n end if\n\n if ( 1.0D+00 <= p ) then\n x = huge ( x )\n return\n end if\n\n q = p - 0.5D+00\n\n if ( abs ( q ) <= split1 ) then\n\n r = const1 - q * q\n x = q * r8poly_value ( 8, a, r ) / r8poly_value ( 8, b, r )\n\n else\n\n if ( q < 0.0D+00 ) then\n r = p\n else\n r = 1.0D+00 - p\n end if\n\n if ( r <= 0.0D+00 ) then\n\n x = huge ( x )\n\n else\n\n r = sqrt ( - log ( r ) )\n\n if ( r <= split2 ) then\n\n r = r - const2\n x = r8poly_value ( 8, c, r ) / r8poly_value ( 8, d, r )\n\n else\n\n r = r - split2\n x = r8poly_value ( 8, e, r ) / r8poly_value ( 8, f, r )\n\n end if\n\n end if\n\n if ( q < 0.0D+00 ) then\n x = -x\n end if\n\n end if\n\n return\nend\nsubroutine normal_01_cdf_values ( n_data, x, fx )\n\n!*****************************************************************************80\n!\n!! NORMAL_01_CDF_VALUES returns some values of the Normal 01 CDF.\n!\n! Discussion:\n!\n! In Mathematica, the function can be evaluated by:\n!\n! Needs[\"Statistics`ContinuousDistributions`\"]\n! dist = NormalDistribution [ 0, 1 ]\n! CDF [ dist, x ]\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 August 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Milton Abramowitz, Irene Stegun,\n! Handbook of Mathematical Functions,\n! National Bureau of Standards, 1964,\n! LC: QA47.A34,\n! ISBN: 0-486-61272-4.\n!\n! Stephen Wolfram,\n! The Mathematica Book,\n! Fourth Edition,\n! Wolfram Media / Cambridge University Press, 1999.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) N_DATA. The user sets N_DATA to 0\n! before the first call. On each call, the routine increments N_DATA by 1,\n! and returns the corresponding data; when there is no more data, the\n! output value of N_DATA will be 0 again.\n!\n! Output, real ( kind = 8 ) X, the argument of the function.\n!\n! Output, real ( kind = 8 ) FX, the value of the function.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: n_max = 17\n\n real ( kind = 8 ) fx\n real ( kind = 8 ), save, dimension ( n_max ) :: fx_vec = (/ &\n 0.5000000000000000D+00, &\n 0.5398278372770290D+00, &\n 0.5792597094391030D+00, &\n 0.6179114221889526D+00, &\n 0.6554217416103242D+00, &\n 0.6914624612740131D+00, &\n 0.7257468822499270D+00, &\n 0.7580363477769270D+00, &\n 0.7881446014166033D+00, &\n 0.8159398746532405D+00, &\n 0.8413447460685429D+00, &\n 0.9331927987311419D+00, &\n 0.9772498680518208D+00, &\n 0.9937903346742239D+00, &\n 0.9986501019683699D+00, &\n 0.9997673709209645D+00, &\n 0.9999683287581669D+00 /)\n integer ( kind = 4 ) n_data\n real ( kind = 8 ) x\n real ( kind = 8 ), save, dimension ( n_max ) :: x_vec = (/ &\n 0.0000000000000000D+00, &\n 0.1000000000000000D+00, &\n 0.2000000000000000D+00, &\n 0.3000000000000000D+00, &\n 0.4000000000000000D+00, &\n 0.5000000000000000D+00, &\n 0.6000000000000000D+00, &\n 0.7000000000000000D+00, &\n 0.8000000000000000D+00, &\n 0.9000000000000000D+00, &\n 0.1000000000000000D+01, &\n 0.1500000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2500000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.3500000000000000D+01, &\n 0.4000000000000000D+01 /)\n\n if ( n_data < 0 ) then\n n_data = 0\n end if\n\n n_data = n_data + 1\n\n if ( n_max < n_data ) then\n n_data = 0\n x = 0.0D+00\n fx = 0.0D+00\n else\n x = x_vec(n_data)\n fx = fx_vec(n_data)\n end if\n\n return\nend\nsubroutine normal_01_mean ( mean )\n\n!*****************************************************************************80\n!\n!! NORMAL_01_MEAN returns the mean of the Normal 01 PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 04 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) mean\n\n mean = 0.0D+00\n\n return\nend\nsubroutine normal_01_pdf ( x, pdf )\n\n!*****************************************************************************80\n!\n!! NORMAL_01_PDF evaluates the Normal 01 PDF.\n!\n! Discussion:\n!\n! The Normal 01 PDF is also called the \"Standard Normal\" PDF, or\n! the Normal PDF with 0 mean and variance 1.\n!\n! PDF(X) = exp ( - 0.5 * X^2 ) / sqrt ( 2 * PI )\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 04 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) pdf\n real ( kind = 8 ), parameter :: r8_pi = 3.141592653589793D+00\n real ( kind = 8 ) x\n\n pdf = exp ( -0.5D+00 * x * x ) / sqrt ( 2.0D+00 * r8_pi )\n\n return\nend\nsubroutine normal_01_sample ( seed, x )\n\n!*****************************************************************************80\n!\n!! NORMAL_01_SAMPLE samples the standard normal probability distribution.\n!\n! Discussion:\n!\n! The standard normal probability distribution function (PDF) has\n! mean 0 and standard deviation 1.\n!\n! The Box-Muller method is used, which is efficient, but\n! generates two values at a time.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 26 August 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random number\n! generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the standard normal PDF.\n!\n implicit none\n\n real ( kind = 8 ) r1\n real ( kind = 8 ) r2\n real ( kind = 8 ), parameter :: r8_pi = 3.141592653589793D+00\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n r1 = r8_uniform_01 ( seed )\n r2 = r8_uniform_01 ( seed )\n x = sqrt ( -2.0D+00 * log ( r1 ) ) * cos ( 2.0D+00 * r8_pi * r2 )\n\n return\nend\nsubroutine normal_01_variance ( variance )\n\n!*****************************************************************************80\n!\n!! NORMAL_01_VARIANCE returns the variance of the Normal 01 PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) variance\n\n variance = 1.0D+00\n\n return\nend\nsubroutine normal_01_vector ( n, seed, x )\n\n!*****************************************************************************80\n!\n!! NORMAL_01_VECTOR samples the standard normal probability distribution.\n!\n! Discussion:\n!\n! The standard normal probability distribution function (PDF) has\n! mean 0 and standard deviation 1.\n!\n! This routine can generate a vector of values on one call. It\n! has the feature that it should provide the same results\n! in the same order no matter how we break up the task.\n!\n! Before calling this routine, the user may call RANDOM_SEED\n! in order to set the seed of the random number generator.\n!\n! The Box-Muller method is used.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 26 August 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of values desired.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random\n! number generator.\n!\n! Output, real ( kind = 8 ) X(N), a sample of the standard normal PDF.\n!\n! Local parameters:\n!\n! Local, real R(N+1), is used to store some uniform random values.\n! Its dimension is N+1, but really it is only needed to be the\n! smallest even number greater than or equal to N.\n!\n! Local, integer X_LO_INDEX, X_HI_INDEX, records the range of entries of\n! X that we need to compute.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n integer ( kind = 4 ) m\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) r(n+1)\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x(n)\n integer ( kind = 4 ) x_hi_index\n integer ( kind = 4 ) x_lo_index\n!\n! Record the range of X we need to fill in.\n!\n x_lo_index = 1\n x_hi_index = n\n\n if ( x_hi_index - x_lo_index + 1 == 1 ) then\n\n r(1) = r8_uniform_01 ( seed )\n r(2) = r8_uniform_01 ( seed )\n\n x(x_hi_index) = &\n sqrt ( -2.0D+00 * log ( r(1) ) ) * cos ( 2.0D+00 * pi * r(2) )\n!\n! If we require an even number of values, that's easy.\n!\n else if ( mod ( x_hi_index - x_lo_index + 1, 2 ) == 0 ) then\n\n m = ( x_hi_index - x_lo_index + 1 ) / 2\n\n call r8vec_uniform_01 ( 2 * m, seed, r )\n\n x(x_lo_index:x_hi_index-1:2) = &\n sqrt ( -2.0D+00 * log ( r(1:2*m-1:2) ) ) &\n * cos ( 2.0D+00 * pi * r(2:2*m:2) )\n\n x(x_lo_index+1:x_hi_index:2) = &\n sqrt ( -2.0D+00 * log ( r(1:2*m-1:2) ) ) &\n * sin ( 2.0D+00 * pi * r(2:2*m:2) )\n!\n! If we require an odd number of values, we generate an even number,\n! and handle the last pair specially, storing one in X(N), and\n! saving the other for later.\n!\n else\n\n x_hi_index = x_hi_index - 1\n\n m = ( x_hi_index - x_lo_index + 1 ) / 2 + 1\n\n call r8vec_uniform_01 ( 2 * m, seed, r )\n\n x(x_lo_index:x_hi_index-1:2) = &\n sqrt ( -2.0D+00 * log ( r(1:2*m-3:2) ) ) &\n * cos ( 2.0D+00 * pi * r(2:2*m-2:2) )\n\n x(x_lo_index+1:x_hi_index:2) = &\n sqrt ( -2.0D+00 * log ( r(1:2*m-3:2) ) ) &\n * sin ( 2.0D+00 * pi * r(2:2*m-2:2) )\n\n x(n) = sqrt ( -2.0D+00 * log ( r(2*m-1) ) ) &\n * cos ( 2.0D+00 * pi * r(2*m) )\n\n end if\n\n return\nend\nsubroutine normal_cdf ( x, a, b, cdf )\n\n!*****************************************************************************80\n!\n!! NORMAL_CDF evaluates the Normal CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 23 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n\n y = ( x - a ) / b\n\n call normal_01_cdf ( y, cdf )\n\n return\nend\nsubroutine normal_cdf_inv ( cdf, a, b, x )\n\n!*****************************************************************************80\n!\n!! NORMAL_CDF_INV inverts the Normal CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 23 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n real ( kind = 8 ) x2\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'NORMAL_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n call normal_01_cdf_inv ( cdf, x2 )\n\n x = a + b * x2\n\n return\nend\nsubroutine normal_cdf_values ( n_data, mu, sigma, x, fx )\n\n!*****************************************************************************80\n!\n!! NORMAL_CDF_VALUES returns some values of the Normal CDF.\n!\n! Discussion:\n!\n! In Mathematica, the function can be evaluated by:\n!\n! Needs[\"Statistics`ContinuousDistributions`\"]\n! dist = NormalDistribution [ mu, sigma ]\n! CDF [ dist, x ]\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 August 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Milton Abramowitz, Irene Stegun,\n! Handbook of Mathematical Functions,\n! National Bureau of Standards, 1964,\n! LC: QA47.A34,\n! ISBN: 0-486-61272-4.\n!\n! Stephen Wolfram,\n! The Mathematica Book,\n! Fourth Edition,\n! Wolfram Media / Cambridge University Press, 1999.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) N_DATA. The user sets N_DATA to 0\n! before the first call. On each call, the routine increments N_DATA by 1,\n! and returns the corresponding data; when there is no more data, the\n! output value of N_DATA will be 0 again.\n!\n! Output, real ( kind = 8 ) MU, the mean of the distribution.\n!\n! Output, real ( kind = 8 ) SIGMA, the variance of the distribution.\n!\n! Output, real ( kind = 8 ) X, the argument of the function.\n!\n! Output, real ( kind = 8 ) FX, the value of the function.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: n_max = 12\n\n real ( kind = 8 ) fx\n real ( kind = 8 ), save, dimension ( n_max ) :: fx_vec = (/ &\n 0.5000000000000000D+00, &\n 0.9772498680518208D+00, &\n 0.9999683287581669D+00, &\n 0.9999999990134124D+00, &\n 0.6914624612740131D+00, &\n 0.6305586598182364D+00, &\n 0.5987063256829237D+00, &\n 0.5792597094391030D+00, &\n 0.6914624612740131D+00, &\n 0.5000000000000000D+00, &\n 0.3085375387259869D+00, &\n 0.1586552539314571D+00 /)\n real ( kind = 8 ) mu\n real ( kind = 8 ), save, dimension ( n_max ) :: mu_vec = (/ &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.4000000000000000D+01, &\n 0.5000000000000000D+01 /)\n integer ( kind = 4 ) n_data\n real ( kind = 8 ) sigma\n real ( kind = 8 ), save, dimension ( n_max ) :: sigma_vec = (/ &\n 0.5000000000000000D+00, &\n 0.5000000000000000D+00, &\n 0.5000000000000000D+00, &\n 0.5000000000000000D+00, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.4000000000000000D+01, &\n 0.5000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01 /)\n real ( kind = 8 ) x\n real ( kind = 8 ), save, dimension ( n_max ) :: x_vec = (/ &\n 0.1000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.4000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.3000000000000000D+01 /)\n\n if ( n_data < 0 ) then\n n_data = 0\n end if\n\n n_data = n_data + 1\n\n if ( n_max < n_data ) then\n n_data = 0\n mu = 0.0D+00\n sigma = 0.0D+00\n x = 0.0D+00\n fx = 0.0D+00\n else\n mu = mu_vec(n_data)\n sigma = sigma_vec(n_data)\n x = x_vec(n_data)\n fx = fx_vec(n_data)\n end if\n\n return\nend\nfunction normal_check ( a, b )\n\n!*****************************************************************************80\n!\n!! NORMAL_CHECK checks the parameters of the Normal PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 18 September 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, logical NORMAL_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n logical normal_check\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'NORMAL_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B <= 0.'\n normal_check = .false.\n return\n end if\n\n normal_check = .true.\n\n return\nend\nsubroutine normal_mean ( a, b, mean )\n\n!*****************************************************************************80\n!\n!! NORMAL_MEAN returns the mean of the Normal PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 10 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) mean\n\n mean = a\n\n return\nend\nsubroutine normal_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! NORMAL_PDF evaluates the Normal PDF.\n!\n! Discussion:\n!\n! PDF(A,B;X)\n! = exp ( - 0.5D+00 * ( ( X - A ) / B )^2 ) / ( B * sqrt ( 2 * PI ) )\n!\n! The normal PDF is also known as the Gaussian PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 10 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) pdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n\n y = ( x - a ) / b\n\n pdf = exp ( - 0.5D+00 * y * y ) / ( b * sqrt ( 2.0D+00 * pi ) )\n\n return\nend\nsubroutine normal_sample ( a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! NORMAL_SAMPLE samples the Normal PDF.\n!\n! Discussion:\n!\n! The Box-Muller method is used.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 10 October 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random number\n! generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n call normal_01_sample ( seed, x )\n\n x = a + b * x\n\n return\nend\nsubroutine normal_variance ( a, b, variance )\n\n!*****************************************************************************80\n!\n!! NORMAL_VARIANCE returns the variance of the Normal PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 10 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) variance\n\n variance = b * b\n\n return\nend\nsubroutine normal_vector ( n, mean, dev, seed, x )\n\n!*****************************************************************************80\n!\n!! NORMAL_VECTOR samples the normal probability distribution.\n!\n! Discussion:\n!\n! The normal probability distribution function (PDF) has\n! a user-specified mean and standard deviation.\n!\n! This routine can generate a vector of values on one call. It\n! has the feature that it should provide the same results\n! in the same order no matter how we break up the task.\n!\n! Before calling this routine, the user may call RANDOM_SEED\n! in order to set the seed of the random number generator.\n!\n! The Box-Muller method is used.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 26 August 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of values desired.\n!\n! Input, real ( kind = 8 ) MEAN, the desired mean value.\n!\n! Input, real ( kind = 8 ) DEV, the desired standard deviation.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random number\n! generator.\n!\n! Output, real ( kind = 8 ) X(N), a sample of the standard normal PDF.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x(n)\n real ( kind = 8 ) dev\n real ( kind = 8 ) mean\n\n call normal_01_vector ( n, seed, x )\n\n x(1:n) = mean + dev * x(1:n)\n\n return\nend\nsubroutine normal_truncated_ab_cdf ( x, mu, s, a, b, cdf )\n\n!*****************************************************************************80\n!\n!! NORMAL_TRUNCATED_AB_CDF evaluates the truncated Normal CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 14 August 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n!\n! Input, real ( kind = 8 ) MU, S, the mean and standard deviation of the\n! parent Normal distribution.\n!\n! Input, real ( kind = 8 ) A, B, the lower and upper truncation limits.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) alpha\n real ( kind = 8 ) alpha_cdf\n real ( kind = 8 ) b\n real ( kind = 8 ) beta\n real ( kind = 8 ) beta_cdf\n real ( kind = 8 ) cdf\n real ( kind = 8 ) mu\n real ( kind = 8 ) s\n real ( kind = 8 ) x\n real ( kind = 8 ) xi\n real ( kind = 8 ) xi_cdf\n\n alpha = ( a - mu ) / s\n beta = ( b - mu ) / s\n xi = ( x - mu ) / s\n\n call normal_01_cdf ( alpha, alpha_cdf )\n call normal_01_cdf ( beta, beta_cdf )\n call normal_01_cdf ( xi, xi_cdf )\n\n cdf = ( xi_cdf - alpha_cdf ) / ( beta_cdf - alpha_cdf )\n\n return\nend\nsubroutine normal_truncated_ab_cdf_inv ( cdf, mu, s, a, b, x )\n\n!*****************************************************************************80\n!\n!! NORMAL_TRUNCATED_AB_CDF_INV inverts the truncated Normal CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 14 August 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Input, real ( kind = 8 ) MU, S, the mean and standard deviation of the\n! parent Normal distribution.\n!\n! Input, real ( kind = 8 ) A, B, the lower and upper truncation limits.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) alpha\n real ( kind = 8 ) alpha_cdf\n real ( kind = 8 ) b\n real ( kind = 8 ) beta\n real ( kind = 8 ) beta_cdf\n real ( kind = 8 ) cdf\n real ( kind = 8 ) mu\n real ( kind = 8 ) s\n real ( kind = 8 ) x\n real ( kind = 8 ) xi\n real ( kind = 8 ) xi_cdf\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'NORMAL_TRUNCATED_AB_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n alpha = ( a - mu ) / s\n beta = ( b - mu ) / s\n\n call normal_01_cdf ( alpha, alpha_cdf )\n call normal_01_cdf ( beta, beta_cdf )\n\n xi_cdf = ( beta_cdf - alpha_cdf ) * cdf + alpha_cdf\n call normal_01_cdf_inv ( xi_cdf, xi )\n\n x = mu + s * xi\n\n return\nend\nsubroutine normal_truncated_ab_mean ( mu, s, a, b, mean )\n\n!*****************************************************************************80\n!\n!! NORMAL_TRUNCATED_AB_MEAN returns the mean of the truncated Normal PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 14 August 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) MU, S, the mean and standard deviatione of the\n! parent Normal distribution.\n!\n! Input, real ( kind = 8 ) A, B, the lower and upper truncation limits.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) alpha\n real ( kind = 8 ) alpha_cdf\n real ( kind = 8 ) alpha_pdf\n real ( kind = 8 ) b\n real ( kind = 8 ) beta\n real ( kind = 8 ) beta_cdf\n real ( kind = 8 ) beta_pdf\n real ( kind = 8 ) mean\n real ( kind = 8 ) mu\n real ( kind = 8 ) s\n\n alpha = ( a - mu ) / s\n beta = ( b - mu ) / s\n\n call normal_01_cdf ( alpha, alpha_cdf )\n call normal_01_cdf ( beta, beta_cdf )\n\n call normal_01_pdf ( alpha, alpha_pdf )\n call normal_01_pdf ( beta, beta_pdf )\n\n mean = mu + s * ( alpha_pdf - beta_pdf ) / ( beta_cdf - alpha_cdf )\n\n return\nend\nsubroutine normal_truncated_ab_pdf ( x, mu, s, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! NORMAL_TRUNCATED_AB_PDF evaluates the truncated Normal PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 14 August 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Input, real ( kind = 8 ) MU, S, the mean and standard deviation of the\n! parent Normal distribution.\n!\n! Input, real ( kind = 8 ) A, B, the lower and upper truncation limits.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) alpha\n real ( kind = 8 ) alpha_cdf\n real ( kind = 8 ) b\n real ( kind = 8 ) beta\n real ( kind = 8 ) beta_cdf\n real ( kind = 8 ) mu\n real ( kind = 8 ) pdf\n real ( kind = 8 ) s\n real ( kind = 8 ) x\n real ( kind = 8 ) xi\n real ( kind = 8 ) xi_pdf\n\n alpha = ( a - mu ) / s\n beta = ( b - mu ) / s\n xi = ( x - mu ) / s\n\n call normal_01_cdf ( alpha, alpha_cdf )\n call normal_01_cdf ( beta, beta_cdf )\n call normal_01_pdf ( xi, xi_pdf )\n\n pdf = xi_pdf / ( beta_cdf - alpha_cdf ) / s\n\n return\nend\nsubroutine normal_truncated_ab_sample ( mu, s, a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! NORMAL_TRUNCATED_AB_SAMPLE samples the truncated Normal PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 14 August 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) MU, S, the mean and standard deviation of the\n! parent Normal distribution.\n!\n! Input, real ( kind = 8 ) A, B, the lower and upper truncation limits.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random number\n! generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) alpha\n real ( kind = 8 ) alpha_cdf\n real ( kind = 8 ) b\n real ( kind = 8 ) beta\n real ( kind = 8 ) beta_cdf\n real ( kind = 8 ) mu\n real ( kind = 8 ) r8_uniform_01\n real ( kind = 8 ) s\n integer ( kind = 4 ) seed\n real ( kind = 8 ) u\n real ( kind = 8 ) x\n real ( kind = 8 ) xi\n real ( kind = 8 ) xi_cdf\n\n alpha = ( a - mu ) / s\n beta = ( b - mu ) / s\n\n call normal_01_cdf ( alpha, alpha_cdf )\n call normal_01_cdf ( beta, beta_cdf )\n\n u = r8_uniform_01 ( seed )\n xi_cdf = alpha_cdf + u * ( beta_cdf - alpha_cdf )\n call normal_01_cdf_inv ( xi_cdf, xi )\n\n x = mu + s * xi\n\n return\nend\nsubroutine normal_truncated_ab_variance ( mu, s, a, b, variance )\n\n!*****************************************************************************80\n!\n!! NORMAL_TRUNCATED_AB_VARIANCE: variance of the truncated Normal PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 14 August 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) MU, S, the mean and standard deviation of the\n! parent Normal distribution.\n!\n! Input, real ( kind = 8 ) A, B, the lower and upper truncation limits.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) alpha\n real ( kind = 8 ) alpha_cdf\n real ( kind = 8 ) alpha_pdf\n real ( kind = 8 ) b\n real ( kind = 8 ) beta\n real ( kind = 8 ) beta_cdf\n real ( kind = 8 ) beta_pdf\n real ( kind = 8 ) mu\n real ( kind = 8 ) s\n real ( kind = 8 ) variance\n\n alpha = ( a - mu ) / s\n beta = ( b - mu ) / s\n\n call normal_01_pdf ( alpha, alpha_pdf )\n call normal_01_pdf ( beta, beta_pdf )\n\n call normal_01_cdf ( alpha, alpha_cdf )\n call normal_01_cdf ( beta, beta_cdf )\n\n variance = s * s * ( 1.0D+00 &\n + ( alpha * alpha_pdf - beta * beta_pdf ) / ( beta_cdf - alpha_cdf ) &\n - ( ( alpha_pdf - beta_pdf ) / ( beta_cdf - alpha_cdf ) ) ** 2 )\n\n return\nend\nsubroutine normal_truncated_a_cdf ( x, mu, s, a, cdf )\n\n!*****************************************************************************80\n!\n!! NORMAL_TRUNCATED_A_CDF evaluates the lower truncated Normal CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 August 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n!\n! Input, real ( kind = 8 ) MU, S, the mean and standard deviation of the\n! parent Normal distribution.\n!\n! Input, real ( kind = 8 ) A, the lower truncation limit.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) alpha\n real ( kind = 8 ) alpha_cdf\n real ( kind = 8 ) cdf\n real ( kind = 8 ) mu\n real ( kind = 8 ) s\n real ( kind = 8 ) x\n real ( kind = 8 ) xi\n real ( kind = 8 ) xi_cdf\n\n alpha = ( a - mu ) / s\n xi = ( x - mu ) / s\n\n call normal_01_cdf ( alpha, alpha_cdf )\n call normal_01_cdf ( xi, xi_cdf )\n\n cdf = ( xi_cdf - alpha_cdf ) / ( 1.0D+00 - alpha_cdf )\n\n return\nend\nsubroutine normal_truncated_a_cdf_inv ( cdf, mu, s, a, x )\n\n!*****************************************************************************80\n!\n!! NORMAL_TRUNCATED_A_CDF_INV inverts the lower truncated Normal CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 August 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Input, real ( kind = 8 ) MU, S, the mean and standard deviation of the\n! parent Normal distribution.\n!\n! Input, real ( kind = 8 ) A, the lower truncation limit.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) alpha\n real ( kind = 8 ) alpha_cdf\n real ( kind = 8 ) cdf\n real ( kind = 8 ) mu\n real ( kind = 8 ) s\n real ( kind = 8 ) x\n real ( kind = 8 ) xi\n real ( kind = 8 ) xi_cdf\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'NORMAL_TRUNCATED_A_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n alpha = ( a - mu ) / s\n\n call normal_01_cdf ( alpha, alpha_cdf )\n\n xi_cdf = ( 1.0D+00 - alpha_cdf ) * cdf + alpha_cdf\n call normal_01_cdf_inv ( xi_cdf, xi )\n\n x = mu + s * xi\n\n return\nend\nsubroutine normal_truncated_a_mean ( mu, s, a, mean )\n\n!*****************************************************************************80\n!\n!! NORMAL_TRUNCATED_A_MEAN returns the mean of the lower truncated Normal PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 August 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) MU, S, the mean and standard deviatione of the\n! parent Normal distribution.\n!\n! Input, real ( kind = 8 ) A, the lower truncation limit.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) alpha\n real ( kind = 8 ) alpha_cdf\n real ( kind = 8 ) alpha_pdf\n real ( kind = 8 ) mean\n real ( kind = 8 ) mu\n real ( kind = 8 ) s\n\n alpha = ( a - mu ) / s\n\n call normal_01_cdf ( alpha, alpha_cdf )\n\n call normal_01_pdf ( alpha, alpha_pdf )\n\n mean = mu + s * alpha_pdf / ( 1.0D+00 - alpha_cdf )\n\n return\nend\nsubroutine normal_truncated_a_pdf ( x, mu, s, a, pdf )\n\n!*****************************************************************************80\n!\n!! NORMAL_TRUNCATED_A_PDF evaluates the lower truncated Normal PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 August 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Input, real ( kind = 8 ) MU, S, the mean and standard deviation of the\n! parent Normal distribution.\n!\n! Input, real ( kind = 8 ) A, the lower truncation limit.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) alpha\n real ( kind = 8 ) alpha_cdf\n real ( kind = 8 ) mu\n real ( kind = 8 ) pdf\n real ( kind = 8 ) s\n real ( kind = 8 ) x\n real ( kind = 8 ) xi\n real ( kind = 8 ) xi_pdf\n\n alpha = ( a - mu ) / s\n xi = ( x - mu ) / s\n\n call normal_01_cdf ( alpha, alpha_cdf )\n call normal_01_pdf ( xi, xi_pdf )\n\n pdf = xi_pdf / ( 1.0D+00 - alpha_cdf ) / s\n\n return\nend\nsubroutine normal_truncated_a_sample ( mu, s, a, seed, x )\n\n!*****************************************************************************80\n!\n!! NORMAL_TRUNCATED_A_SAMPLE samples the lower truncated Normal PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 August 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) MU, S, the mean and standard deviation of the\n! parent Normal distribution.\n!\n! Input, real ( kind = 8 ) A, the lower truncation limit.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random number\n! generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) alpha\n real ( kind = 8 ) alpha_cdf\n real ( kind = 8 ) mu\n real ( kind = 8 ) r8_uniform_01\n real ( kind = 8 ) s\n integer ( kind = 4 ) seed\n real ( kind = 8 ) u\n real ( kind = 8 ) x\n real ( kind = 8 ) xi\n real ( kind = 8 ) xi_cdf\n\n alpha = ( a - mu ) / s\n\n call normal_01_cdf ( alpha, alpha_cdf )\n\n u = r8_uniform_01 ( seed )\n xi_cdf = alpha_cdf + u * ( 1.0D+00 - alpha_cdf )\n call normal_01_cdf_inv ( xi_cdf, xi )\n\n x = mu + s * xi\n\n return\nend\nsubroutine normal_truncated_a_variance ( mu, s, a, variance )\n\n!*****************************************************************************80\n!\n!! NORMAL_TRUNCATED_A_VARIANCE: variance of the lower truncated Normal PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 August 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) MU, S, the mean and standard deviation of the\n! parent Normal distribution.\n!\n! Input, real ( kind = 8 ) A, the lower truncation limit.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) alpha\n real ( kind = 8 ) alpha_cdf\n real ( kind = 8 ) alpha_pdf\n real ( kind = 8 ) mu\n real ( kind = 8 ) s\n real ( kind = 8 ) variance\n\n alpha = ( a - mu ) / s\n\n call normal_01_pdf ( alpha, alpha_pdf )\n\n call normal_01_cdf ( alpha, alpha_cdf )\n\n variance = s * s * ( 1.0D+00 &\n + ( alpha * alpha_pdf ) / ( 1.0D+00 - alpha_cdf ) &\n - ( alpha_pdf / ( 1.0D+00 - alpha_cdf ) ) ** 2 )\n\n return\nend\nsubroutine normal_truncated_b_cdf ( x, mu, s, b, cdf )\n\n!*****************************************************************************80\n!\n!! NORMAL_TRUNCATED_B_CDF evaluates the upper truncated Normal CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 August 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n!\n! Input, real ( kind = 8 ) MU, S, the mean and standard deviation of the\n! parent Normal distribution.\n!\n! Input, real ( kind = 8 ) B, the upper truncation limit.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) b\n real ( kind = 8 ) beta\n real ( kind = 8 ) beta_cdf\n real ( kind = 8 ) cdf\n real ( kind = 8 ) mu\n real ( kind = 8 ) s\n real ( kind = 8 ) x\n real ( kind = 8 ) xi\n real ( kind = 8 ) xi_cdf\n\n beta = ( b - mu ) / s\n xi = ( x - mu ) / s\n\n call normal_01_cdf ( beta, beta_cdf )\n call normal_01_cdf ( xi, xi_cdf )\n\n cdf = xi_cdf / beta_cdf\n\n return\nend\nsubroutine normal_truncated_b_cdf_inv ( cdf, mu, s, b, x )\n\n!*****************************************************************************80\n!\n!! NORMAL_TRUNCATED_B_CDF_INV inverts the upper truncated Normal CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 August 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Input, real ( kind = 8 ) MU, S, the mean and standard deviation of the\n! parent Normal distribution.\n!\n! Input, real ( kind = 8 ) B, the upper truncation limit.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument.\n!\n implicit none\n\n real ( kind = 8 ) b\n real ( kind = 8 ) beta\n real ( kind = 8 ) beta_cdf\n real ( kind = 8 ) cdf\n real ( kind = 8 ) mu\n real ( kind = 8 ) s\n real ( kind = 8 ) x\n real ( kind = 8 ) xi\n real ( kind = 8 ) xi_cdf\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'NORMAL_TRUNCATED_B_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n beta = ( b - mu ) / s\n\n call normal_01_cdf ( beta, beta_cdf )\n\n xi_cdf = beta_cdf * cdf\n call normal_01_cdf_inv ( xi_cdf, xi )\n\n x = mu + s * xi\n\n return\nend\nsubroutine normal_truncated_b_mean ( mu, s, b, mean )\n\n!*****************************************************************************80\n!\n!! NORMAL_TRUNCATED_B_MEAN returns the mean of the upper truncated Normal PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 August 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) MU, S, the mean and standard deviatione of the\n! parent Normal distribution.\n!\n! Input, real ( kind = 8 ) B, the upper truncation limit.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) b\n real ( kind = 8 ) beta\n real ( kind = 8 ) beta_cdf\n real ( kind = 8 ) beta_pdf\n real ( kind = 8 ) mean\n real ( kind = 8 ) mu\n real ( kind = 8 ) s\n\n beta = ( b - mu ) / s\n\n call normal_01_cdf ( beta, beta_cdf )\n\n call normal_01_pdf ( beta, beta_pdf )\n\n mean = mu - s * beta_pdf / beta_cdf\n\n return\nend\nsubroutine normal_truncated_b_pdf ( x, mu, s, b, pdf )\n\n!*****************************************************************************80\n!\n!! NORMAL_TRUNCATED_B_PDF evaluates the upper truncated Normal PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 August 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Input, real ( kind = 8 ) MU, S, the mean and standard deviation of the\n! parent Normal distribution.\n!\n! Input, real ( kind = 8 ) B, the upper truncation limit.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) b\n real ( kind = 8 ) beta\n real ( kind = 8 ) beta_cdf\n real ( kind = 8 ) mu\n real ( kind = 8 ) pdf\n real ( kind = 8 ) s\n real ( kind = 8 ) x\n real ( kind = 8 ) xi\n real ( kind = 8 ) xi_pdf\n\n beta = ( b - mu ) / s\n xi = ( x - mu ) / s\n\n call normal_01_cdf ( beta, beta_cdf )\n call normal_01_pdf ( xi, xi_pdf )\n\n pdf = xi_pdf / beta_cdf / s\n\n return\nend\nsubroutine normal_truncated_b_sample ( mu, s, b, seed, x )\n\n!*****************************************************************************80\n!\n!! NORMAL_TRUNCATED_B_SAMPLE samples the upper truncated Normal PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 August 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) MU, S, the mean and standard deviation of the\n! parent Normal distribution.\n!\n! Input, real ( kind = 8 ) B, the upper truncation limit.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random number\n! generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) b\n real ( kind = 8 ) beta\n real ( kind = 8 ) beta_cdf\n real ( kind = 8 ) mu\n real ( kind = 8 ) r8_uniform_01\n real ( kind = 8 ) s\n integer ( kind = 4 ) seed\n real ( kind = 8 ) u\n real ( kind = 8 ) x\n real ( kind = 8 ) xi\n real ( kind = 8 ) xi_cdf\n\n beta = ( b - mu ) / s\n\n call normal_01_cdf ( beta, beta_cdf )\n\n u = r8_uniform_01 ( seed )\n xi_cdf = u * beta_cdf\n call normal_01_cdf_inv ( xi_cdf, xi )\n\n x = mu + s * xi\n\n return\nend\nsubroutine normal_truncated_b_variance ( mu, s, b, variance )\n\n!*****************************************************************************80\n!\n!! NORMAL_TRUNCATED_B_VARIANCE: variance of the upper truncated Normal PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 August 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) MU, S, the mean and standard deviation of the\n! parent Normal distribution.\n!\n! Input, real ( kind = 8 ) B, the upper truncation limit.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) b\n real ( kind = 8 ) beta\n real ( kind = 8 ) beta_cdf\n real ( kind = 8 ) beta_pdf\n real ( kind = 8 ) mu\n real ( kind = 8 ) s\n real ( kind = 8 ) variance\n\n beta = ( b - mu ) / s\n\n call normal_01_pdf ( beta, beta_pdf )\n\n call normal_01_cdf ( beta, beta_cdf )\n\n variance = s * s * ( 1.0D+00 &\n - ( beta * beta_pdf ) / beta_cdf &\n - ( beta_pdf / beta_cdf ) ** 2 )\n\n return\nend\nsubroutine owen_values ( n_data, h, a, t )\n\n!*****************************************************************************80\n!\n!! OWEN_VALUES returns some values of Owen's T function.\n!\n! Discussion:\n!\n! Owen's T function is useful for computation of the bivariate normal\n! distribution and the distribution of a skewed normal distribution.\n!\n! Although it was originally formulated in terms of the bivariate\n! normal function, the function can be defined more directly as\n!\n! T(H,A) = 1 / ( 2 * pi ) *\n! Integral ( 0 <= X <= A ) e^(-H^2*(1+X^2)/2) / (1+X^2) dX\n!\n! In Mathematica, the function can be evaluated by:\n!\n! fx = 1/(2*Pi) * Integrate [ E^(-h^2*(1+x^2)/2)/(1+x^2), {x,0,a} ]\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 10 December 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Stephen Wolfram,\n! The Mathematica Book,\n! Fourth Edition,\n! Wolfram Media / Cambridge University Press, 1999.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) N_DATA. The user sets N_DATA to 0\n! before the first call. On each call, the routine increments N_DATA by 1,\n! and returns the corresponding data; when there is no more data, the\n! output value of N_DATA will be 0 again.\n!\n! Output, real ( kind = 8 ) H, a parameter.\n!\n! Output, real ( kind = 8 ) A, the upper limit of the integral.\n!\n! Output, real ( kind = 8 ) T, the value of the function.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: n_max = 22\n\n real ( kind = 8 ) a\n real ( kind = 8 ), save, dimension ( n_max ) :: a_vec = (/ &\n 0.5000000000000000D+00, &\n 0.1000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.5000000000000000D+00, &\n 0.1000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.5000000000000000D+00, &\n 0.1000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.5000000000000000D+00, &\n 0.1000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.5000000000000000D+00, &\n 0.1000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.1000000000000000D+02, &\n 0.1000000000000000D+03 /)\n real ( kind = 8 ) h\n real ( kind = 8 ), save, dimension ( n_max ) :: h_vec = (/ &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.5000000000000000D+00, &\n 0.5000000000000000D+00, &\n 0.5000000000000000D+00, &\n 0.5000000000000000D+00, &\n 0.2500000000000000D+00, &\n 0.2500000000000000D+00, &\n 0.2500000000000000D+00, &\n 0.2500000000000000D+00, &\n 0.1250000000000000D+00, &\n 0.1250000000000000D+00, &\n 0.1250000000000000D+00, &\n 0.1250000000000000D+00, &\n 0.7812500000000000D-02, &\n 0.7812500000000000D-02, &\n 0.7812500000000000D-02, &\n 0.7812500000000000D-02, &\n 0.7812500000000000D-02, &\n 0.7812500000000000D-02 /)\n integer ( kind = 4 ) n_data\n real ( kind = 8 ) t\n real ( kind = 8 ), save, dimension ( n_max ) :: t_vec = (/ &\n 0.4306469112078537D-01, &\n 0.6674188216570097D-01, &\n 0.7846818699308410D-01, &\n 0.7929950474887259D-01, &\n 0.6448860284750376D-01, &\n 0.1066710629614485D+00, &\n 0.1415806036539784D+00, &\n 0.1510840430760184D+00, &\n 0.7134663382271778D-01, &\n 0.1201285306350883D+00, &\n 0.1666128410939293D+00, &\n 0.1847501847929859D+00, &\n 0.7317273327500385D-01, &\n 0.1237630544953746D+00, &\n 0.1737438887583106D+00, &\n 0.1951190307092811D+00, &\n 0.7378938035365546D-01, &\n 0.1249951430754052D+00, &\n 0.1761984774738108D+00, &\n 0.1987772386442824D+00, &\n 0.2340886964802671D+00, &\n 0.2479460829231492D+00 /)\n\n if ( n_data < 0 ) then\n n_data = 0\n end if\n\n n_data = n_data + 1\n\n if ( n_max < n_data ) then\n n_data = 0\n h = 0.0D+00\n a = 0.0D+00\n t = 0.0D+00\n else\n h = h_vec(n_data)\n a = a_vec(n_data)\n t = t_vec(n_data)\n end if\n\n return\nend\nsubroutine pareto_cdf ( x, a, b, cdf )\n\n!*****************************************************************************80\n!\n!! PARETO_CDF evaluates the Pareto CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 16 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A,\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( x < a ) then\n cdf = 0.0D+00\n else\n cdf = 1.0D+00 - ( a / x )**b\n end if\n\n return\nend\nsubroutine pareto_cdf_inv ( cdf, a, b, x )\n\n!*****************************************************************************80\n!\n!! PARETO_CDF_INV inverts the Pareto CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 16 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A,\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PARETO_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n x = a / ( 1.0D+00 - cdf ) ** ( 1.0D+00 / b )\n\n return\nend\nfunction pareto_check ( a, b )\n\n!*****************************************************************************80\n!\n!! PARETO_CHECK checks the parameters of the Pareto CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 18 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A,\n! 0.0D+00 < B.\n!\n! Output, logical PARETO_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n logical pareto_check\n\n if ( a <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PARETO_CHECK - Fatal error!'\n write ( *, '(a)' ) ' A <= 0.'\n pareto_check = .false.\n return\n end if\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PARETO_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B <= 0.'\n pareto_check = .false.\n return\n end if\n\n pareto_check = .true.\n\n return\nend\nsubroutine pareto_mean ( a, b, mean )\n\n!*****************************************************************************80\n!\n!! PARETO_MEAN returns the mean of the Pareto PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 15 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A,\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) mean\n\n if ( b <= 1.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PARETO_MEAN - Fatal error!'\n write ( *, '(a)' ) ' For B <= 1, the mean does not exist.'\n mean = 0.0D+00\n return\n end if\n\n mean = b * a / ( b - 1.0D+00 )\n\n return\nend\nsubroutine pareto_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! PARETO_PDF evaluates the Pareto PDF.\n!\n! Discussion:\n!\n! PDF(A,B;X) = B * A^B / X^(B+1).\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 15 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n! A <= X\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) pdf\n real ( kind = 8 ) x\n\n if ( x < a ) then\n pdf = 0.0D+00\n else\n pdf = b * ( a ** b ) / x ** ( b + 1.0D+00 )\n end if\n\n return\nend\nsubroutine pareto_sample ( a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! PARETO_SAMPLE samples the Pareto PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 16 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A.\n! 0.0D+00 < B.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random number\n! generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call pareto_cdf_inv ( cdf, a, b, x )\n\n return\nend\nsubroutine pareto_variance ( a, b, variance )\n\n!*****************************************************************************80\n!\n!! PARETO_VARIANCE returns the variance of the Pareto PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 15 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A,\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) variance\n\n if ( b <= 2.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PARETO_VARIANCE - Warning!'\n write ( *, '(a)' ) ' For B <= 2, the variance does not exist.'\n variance = 0.0D+00\n return\n end if\n\n variance = a * a * b / ( ( b - 1.0D+00 ) ** 2 * ( b - 2.0D+00 ) )\n\n return\nend\nfunction pearson_05_check ( a, b, c )\n\n!*****************************************************************************80\n!\n!! PEARSON_05_CHECK checks the parameters of the Pearson 5 PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 22 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < A, 0.0D+00 < B.\n!\n! Output, logical PEARSON_05_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n logical pearson_05_check\n\n if ( a <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PEARSON_05_CHECK - Fatal error!'\n write ( *, '(a)' ) ' A <= 0.'\n pearson_05_check = .false.\n return\n end if\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PEARSON_05_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B <= 0.'\n pearson_05_check = .false.\n return\n end if\n\n pearson_05_check = .true.\n\n return\nend\nsubroutine pearson_05_mean ( a, b, c, mean )\n\n!*****************************************************************************80\n!\n!! PEARSON_05_MEAN evaluates the mean of the Pearson 5 PDF.\n!\n! Discussion:\n!\n! The mean is undefined for B <= 1.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < A, 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) mean\n\n if ( b <= 1.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PEARSON_05_MEAN - Warning!'\n write ( *, '(a)' ) ' MEAN undefined for B <= 1.'\n mean = c\n return\n end if\n\n mean = c + a / ( b - 1.0D+00 )\n\n return\nend\nsubroutine pearson_05_pdf ( x, a, b, c, pdf )\n\n!*****************************************************************************80\n!\n!! PEARSON_05_PDF evaluates the Pearson 5 PDF.\n!\n! Discussion:\n!\n! PDF(A,B;X) = A^B * ( X - C )^(-B-1)\n! * exp ( - A / ( X - C ) ) / Gamma ( B )\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 04 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n! C < X\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < A, 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) pdf\n real ( kind = 8 ) r8_gamma\n real ( kind = 8 ) x\n\n if ( x <= c ) then\n pdf = 0.0D+00\n else\n pdf = ( a ** b ) * ( x - c ) ** ( - b - 1.0D+00 ) &\n * exp ( - a / ( x - c ) ) / r8_gamma ( b )\n end if\n\n return\nend\nsubroutine pearson_05_sample ( a, b, c, seed, x )\n\n!*****************************************************************************80\n!\n!! PEARSON_05_SAMPLE samples the Pearson 5 PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < A, 0.0D+00 < B.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random number\n! generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) a2\n real ( kind = 8 ) b\n real ( kind = 8 ) b2\n real ( kind = 8 ) c\n real ( kind = 8 ) c2\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n real ( kind = 8 ) x2\n\n a2 = 0.0D+00\n b2 = b\n c2 = 1.0D+00 / a\n\n call gamma_sample ( a2, b2, c2, seed, x2 )\n\n x = c + 1.0D+00 / x2\n\n return\nend\nfunction planck_check ( a, b )\n\n!*****************************************************************************80\n!\n!! PLANCK_CHECK checks the parameters of the Planck PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 26 October 1998\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A,\n! 0.0D+00 < B.\n!\n! Output, logical PLANCK_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n logical planck_check\n\n if ( a <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PLANCK_CHECK - Fatal error!'\n write ( *, '(a)' ) ' A <= 0.'\n planck_check = .false.\n return\n end if\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'PLANCK_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B <= 0.'\n planck_check = .false.\n return\n end if\n\n planck_check = .true.\n\n return\nend\nsubroutine planck_mean ( a, b, mean )\n\n!*****************************************************************************80\n!\n!! PLANCK_MEAN returns the mean of the Planck PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 25 October 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0 < A, 0.0 < B.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) mean\n real ( kind = 8 ) zeta\n\n mean = ( b + 1.0D+00 ) * zeta ( b + 2.0D+00 ) / zeta ( b + 1.0D+00 )\n\n return\nend\nsubroutine planck_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! PLANCK_PDF evaluates the Planck PDF.\n!\n! Discussion:\n!\n! The Planck PDF has the form\n!\n! PDF(A,B;X) = A^(B+1) * X^B / ( exp ( A * X ) - 1 ) / K\n!\n! where K is the normalization constant, and has the value\n!\n! K = Gamma ( B + 1 ) * Zeta ( B + 1 ).\n!\n! The original Planck distribution governed the frequencies in\n! blackbody radiation at a given temperature T, and has the form\n!\n! PDF(A;X) = K * X^3 / ( exp ( A * X ) - 1 )\n!\n! with\n!\n! K = 15 / PI^4.\n!\n! Thus, in terms of the Planck PDF, the original Planck distribution\n! has A = 1, B = 3.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 25 October 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Norman Johnson, Samuel Kotz, Balakrishnan,\n! Continuous Univariate Distributions, second edition,\n! Wiley, 1994,\n! QA273.6.J6\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0 < A, 0.0 < B.\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n! 0.0 <= X\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) k\n real ( kind = 8 ) pdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) r8_gamma\n real ( kind = 8 ) x\n real ( kind = 8 ) zeta\n\n if ( x < 0.0D+00 ) then\n pdf = 0.0D+00\n else\n k = r8_gamma ( b + 1.0D+00 ) * zeta ( b + 1.0D+00 )\n pdf = a**( b + 1.0D+00 ) * x**b / ( exp ( a * x ) - 1.0D+00 ) / k\n end if\n\n return\nend\nsubroutine planck_sample ( a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! PLANCK_SAMPLE samples the Planck PDF.\n!\n! Discussion:\n!\n! The Planck sampling seems to be giving incorrect results.\n! I suspect this has to do with a possible problem in the\n! ZIPF_SAMPLE routine.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 25 October 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Luc Devroye,\n! Non-Uniform Random Variate Generation,\n! Springer Verlag, 1986, pages 552.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0 < A, 0.0 < B.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random number\n! generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) a2\n real ( kind = 8 ) b\n real ( kind = 8 ) b2\n real ( kind = 8 ) c2\n real ( kind = 8 ) g\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n integer ( kind = 4 ) z\n\n a2 = 0.0D+00\n b2 = 1.0D+00\n c2 = b + 1.0D+00\n\n call gamma_sample ( a2, b2, c2, seed, g )\n\n call zipf_sample ( c2, seed, z )\n\n x = g / ( a * real ( z, kind = 8 ) )\n\n return\nend\nsubroutine planck_variance ( a, b, variance )\n\n!*****************************************************************************80\n!\n!! PLANCK_VARIANCE returns the variance of the Planck PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 13 December 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0 < A, 0.0 < B.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) mean\n real ( kind = 8 ) variance\n real ( kind = 8 ) zeta\n\n call planck_mean ( a, b, mean )\n\n variance = ( b + 1.0D+00 ) * ( b + 2.0D+00 ) &\n * zeta ( b + 3.0D+00 ) / zeta ( b + 1.0D+00 ) - mean * mean\n\n return\nend\nsubroutine point_distance_1d_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! POINT_DISTANCE_1D_PDF evaluates the point distance PDF in 1D.\n!\n! Discussion:\n!\n! It is assumed that a set of points has been generated in 1D\n! according to a Poisson process. The number of points in a region\n! of size LENGTH is a Poisson variate with mean value B * LENGTH.\n!\n! For a point chosen at random, we may now find the nearest\n! Poisson point, the second nearest and so on. We are interested\n! in the PDF that governs the expected behavior of the distances\n! of rank A = 1, 2, 3, ... with Poisson density B.\n!\n! Note that this PDF is a form of the Gamma PDF.???\n!\n! PDF(A,B;X) = B^A * X^( A - 1 ) * exp ( - B * X ) / ( A - 1 )!\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 22 September 2002\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n! 0.0D+00 <= X.\n!\n! Input, integer ( kind = 4 ) A, indicates the degree of nearness of the\n! point. A = 1 means the nearest point, A = 2 the second nearest, and so on.\n! 0 < A.\n!\n! Input, real ( kind = 8 ) B, the point density. 0.0 < B.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) i4_factorial\n real ( kind = 8 ) pdf\n real ( kind = 8 ) x\n\n if ( a < 1 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'POINT_DISTANCE_1D_PDF - Fatal error!'\n write ( *, '(a)' ) ' Input parameter A < 1.'\n stop 1\n end if\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'POINT_DISTANCE_1D_PDF - Fatal error!'\n write ( *, '(a)' ) ' Input parameter B <= 0.0.'\n stop 1\n end if\n\n if ( x < 0.0D+00 ) then\n pdf = 0.0D+00\n else\n pdf = b**a * x**( a - 1 ) * exp ( - b * x ) / i4_factorial ( a - 1 )\n end if\n\n return\nend\nsubroutine point_distance_2d_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! POINT_DISTANCE_2D_PDF evaluates the point distance PDF in 2D.\n!\n! Discussion:\n!\n! It is assumed that a set of points has been generated in 2D\n! according to a Poisson process. The number of points in a region\n! of size AREA is a Poisson variate with mean value B * AREA.\n!\n! For a point chosen at random, we may now find the nearest\n! Poisson point, the second nearest and so on. We are interested\n! in the PDF that governs the expected behavior of the distances\n! of rank A = 1, 2, 3, ... with Poisson density B.\n!\n! PDF(A,B;X) = 2 * ( B * PI )^A * X^( 2 * A - 1 )\n! * EXP ( - B * PI * X * X ) / ( A - 1 )!\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 22 September 2002\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Daniel Zwillinger, editor,\n! CRC Standard Mathematical Tables and Formulae,\n! 30th Edition,\n! CRC Press, 1996, pages 579.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n! 0.0D+00 <= X.\n!\n! Input, integer ( kind = 4 ) A, indicates the degree of nearness of the\n! point. A = 1 means the nearest point, A = 2 the second nearest, and so on.\n! 0 < A.\n!\n! Input, real ( kind = 8 ) B, the point density. 0.0 < B.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) i4_factorial\n real ( kind = 8 ) pdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) x\n\n if ( a < 1 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'POINT_DISTANCE_2D_PDF - Fatal error!'\n write ( *, '(a)' ) ' Input parameter A < 1.'\n stop 1\n end if\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'POINT_DISTANCE_2D_PDF - Fatal error!'\n write ( *, '(a)' ) ' Input parameter B <= 0.0.'\n stop 1\n end if\n\n if ( x < 0.0D+00 ) then\n pdf = 0.0D+00\n else\n pdf = 2.0D+00 * ( b * pi )**a * x**( 2 * a - 1 ) &\n * exp ( - b * pi * x * x ) / i4_factorial ( a - 1 )\n end if\n\n return\nend\nsubroutine point_distance_3d_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! POINT_DISTANCE_3D_PDF evaluates the point distance PDF in the 3D.\n!\n! Discussion:\n!\n! It is assumed that a set of points has been generated in 3D\n! according to a Poisson process. The number of points in a region\n! of size VOLUME is a Poisson variate with mean value B * VOLUME.\n!\n! For a point chosen at random, we may now find the nearest\n! Poisson point, the second nearest and so on. We are interested\n! in the PDF that governs the expected behavior of the distances\n! of rank A = 1, 2, 3, ... with Poisson density B.\n!\n! PDF(A,B;X) = 3 * ( (4/3) * B * PI )^A * X^( 3 * A - 1 )\n! * EXP ( - (4/3) * B * PI * X * X * X ) / ( A - 1 )!\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 22 September 2002\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Daniel Zwillinger, editor,\n! CRC Standard Mathematical Tables and Formulae,\n! 30th Edition,\n! CRC Press, 1996, pages 580.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n! 0.0D+00 <= X.\n!\n! Input, integer ( kind = 4 ) A, indicates the degree of nearness of the\n! point. A = 1 means the nearest point, A = 2 the second nearest, and so on.\n! 0 < A.\n!\n! Input, real ( kind = 8 ) B, the Poisson point density. 0.0 < B.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) i4_factorial\n real ( kind = 8 ) pdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) x\n\n if ( a < 1 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'POINT_DISTANCE_3D_PDF - Fatal error!'\n write ( *, '(a)' ) ' Input parameter A < 1.'\n stop 1\n end if\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'POINT_DISTANCE_3D_PDF - Fatal error!'\n write ( *, '(a)' ) ' Input parameter B <= 0.0.'\n stop 1\n end if\n\n if ( x < 0.0D+00 ) then\n pdf = 0.0D+00\n else\n pdf = 3.0D+00 * ( ( 4.0D+00 / 3.0D+00 ) * b * pi )**a &\n * x**( 3 * a - 1 ) * exp ( - ( 4.0D+00 / 3.0D+00 ) * b * pi * x**3 ) &\n / i4_factorial ( a - 1 )\n end if\n\n return\nend\nsubroutine poisson_cdf ( x, a, cdf )\n\n!*****************************************************************************80\n!\n!! POISSON_CDF evaluates the Poisson CDF.\n!\n! Discussion:\n!\n! CDF(X,A) is the probability that the number of events observed\n! in a unit time period will be no greater than X, given that the\n! expected number of events in a unit time period is A.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 January 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X, the argument of the CDF.\n! 0 <= X.\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 0.0D+00 < A.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) cdf\n integer ( kind = 4 ) i\n real ( kind = 8 ) last\n real ( kind = 8 ) new\n real ( kind = 8 ) sum2\n integer ( kind = 4 ) x\n\n if ( x < 0 ) then\n\n cdf = 0.0D+00\n\n else\n\n new = exp ( - a )\n sum2 = new\n\n do i = 1, x\n last = new\n new = last * a / real ( i, kind = 8 )\n sum2 = sum2 + new\n end do\n\n cdf = sum2\n\n end if\n\n return\nend\nsubroutine poisson_cdf_values ( n_data, a, x, fx )\n\n!*****************************************************************************80\n!\n!! POISSON_CDF_VALUES returns some values of the Poisson CDF.\n!\n! Discussion:\n!\n! CDF(X)(A) is the probability of at most X successes in unit time,\n! given that the expected mean number of successes is A.\n!\n! In Mathematica, the function can be evaluated by:\n!\n! Needs[\"Statistics`DiscreteDistributions`]\n! dist = PoissonDistribution [ a ]\n! CDF [ dist, x ]\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 20 August 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Milton Abramowitz, Irene Stegun,\n! Handbook of Mathematical Functions,\n! National Bureau of Standards, 1964,\n! LC: QA47.A34,\n! ISBN: 0-486-61272-4.\n!\n! Stephen Wolfram,\n! The Mathematica Book,\n! Fourth Edition,\n! Wolfram Media / Cambridge University Press, 1999.\n!\n! Daniel Zwillinger,\n! CRC Standard Mathematical Tables and Formulae,\n! 30th Edition, CRC Press, 1996, pages 653-658.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) N_DATA. The user sets N_DATA to 0\n! before the first call. On each call, the routine increments N_DATA by 1,\n! and returns the corresponding data; when there is no more data, the\n! output value of N_DATA will be 0 again.\n!\n! Output, real ( kind = 8 ) A, the parameter of the function.\n!\n! Output, integer ( kind = 4 ) X, the argument of the function.\n!\n! Output, real ( kind = 8 ) FX, the value of the function.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: n_max = 21\n\n real ( kind = 8 ) a\n real ( kind = 8 ), save, dimension ( n_max ) :: a_vec = (/ &\n 0.02D+00, &\n 0.10D+00, &\n 0.10D+00, &\n 0.50D+00, &\n 0.50D+00, &\n 0.50D+00, &\n 1.00D+00, &\n 1.00D+00, &\n 1.00D+00, &\n 1.00D+00, &\n 2.00D+00, &\n 2.00D+00, &\n 2.00D+00, &\n 2.00D+00, &\n 5.00D+00, &\n 5.00D+00, &\n 5.00D+00, &\n 5.00D+00, &\n 5.00D+00, &\n 5.00D+00, &\n 5.00D+00 /)\n real ( kind = 8 ) fx\n real ( kind = 8 ), save, dimension ( n_max ) :: fx_vec = (/ &\n 0.9801986733067553D+00, &\n 0.9048374180359596D+00, &\n 0.9953211598395555D+00, &\n 0.6065306597126334D+00, &\n 0.9097959895689501D+00, &\n 0.9856123220330293D+00, &\n 0.3678794411714423D+00, &\n 0.7357588823428846D+00, &\n 0.9196986029286058D+00, &\n 0.9810118431238462D+00, &\n 0.1353352832366127D+00, &\n 0.4060058497098381D+00, &\n 0.6766764161830635D+00, &\n 0.8571234604985470D+00, &\n 0.6737946999085467D-02, &\n 0.4042768199451280D-01, &\n 0.1246520194830811D+00, &\n 0.2650259152973617D+00, &\n 0.4404932850652124D+00, &\n 0.6159606548330631D+00, &\n 0.7621834629729387D+00 /)\n integer ( kind = 4 ) n_data\n integer ( kind = 4 ) x\n integer ( kind = 4 ), save, dimension ( n_max ) :: x_vec = (/ &\n 0, 0, 1, 0, &\n 1, 2, 0, 1, &\n 2, 3, 0, 1, &\n 2, 3, 0, 1, &\n 2, 3, 4, 5, &\n 6 /)\n\n if ( n_data < 0 ) then\n n_data = 0\n end if\n\n n_data = n_data + 1\n\n if ( n_max < n_data ) then\n n_data = 0\n a = 0.0D+00\n x = 0\n fx = 0.0D+00\n else\n a = a_vec(n_data)\n x = x_vec(n_data)\n fx = fx_vec(n_data)\n end if\n\n return\nend\nsubroutine poisson_cdf_inv ( cdf, a, x )\n\n!*****************************************************************************80\n!\n!! POISSON_CDF_INV inverts the Poisson CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 16 September 2002\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, a value of the CDF.\n! 0 <= CDF < 1.\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 0.0D+00 < A.\n!\n! Output, integer ( kind = 4 ) X, the corresponding argument.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) cdf\n integer ( kind = 4 ) i\n real ( kind = 8 ) last\n real ( kind = 8 ) new\n real ( kind = 8 ) sum2\n real ( kind = 8 ) sumold\n integer ( kind = 4 ) x\n integer ( kind = 4 ), parameter :: xmax = 100\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'POISSON_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n!\n! Now simply start at X = 0, and find the first value for which\n! CDF(X-1) <= CDF <= CDF(X).\n!\n sum2 = 0.0D+00\n\n do i = 0, xmax\n\n sumold = sum2\n\n if ( i == 0 ) then\n new = exp ( - a )\n sum2 = new\n else\n last = new\n new = last * a / real ( i, kind = 8 )\n sum2 = sum2 + new\n end if\n\n if ( sumold <= cdf .and. cdf <= sum2 ) then\n x = i\n return\n end if\n\n end do\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'POISSON_CDF_INV - Warning!'\n write ( *, '(a,i8)' ) ' Exceeded XMAX = ', xmax\n\n x = xmax\n\n return\nend\nfunction poisson_check ( a )\n\n!*****************************************************************************80\n!\n!! POISSON_CHECK checks the parameter of the Poisson PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 22 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 0.0D+00 < A.\n!\n! Output, logical POISSON_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n logical poisson_check\n\n if ( a <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'POISSON_CHECK - Fatal error!'\n write ( *, '(a)' ) ' A <= 0.'\n poisson_check = .false.\n return\n end if\n\n poisson_check = .true.\n\n return\nend\nsubroutine poisson_mean ( a, mean )\n\n!*****************************************************************************80\n!\n!! POISSON_MEAN returns the mean of the Poisson PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 0.0D+00 < A.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) mean\n\n mean = a\n\n return\nend\nsubroutine poisson_kernel ( r, n, c, x, y, p )\n\n!*****************************************************************************80\n!\n!! POISSON_KERNEL evaluates the Poisson kernel.\n!\n! Discussion:\n!\n! P(X,Y) = ( R^2 - |X-C|^2 ) / ( R * A * |X-Y|^N )\n!\n! where the N-dimensional ball has radius R and center C,\n! and A is the area of the unit sphere.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 22 November 2011\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) R, the radius of the ball.\n!\n! Input, integer ( kind = 4 ) N, the spatial dimension.\n!\n! Input, real ( kind = 8 ) C(N), the center of the ball.\n!\n! Input, real ( kind = 8 ) X(N), a point inside the ball.\n!\n! Input, real ( kind = 8 ) Y(N), a point on the surface of the ball.\n!\n! Output, real ( kind = 8 ) P, the Poisson kernel function P(X,Y).\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) area\n real ( kind = 8 ) b\n real ( kind = 8 ) c(n)\n real ( kind = 8 ) p\n real ( kind = 8 ) r\n real ( kind = 8 ) r8vec_diff_norm\n real ( kind = 8 ) sphere_unit_area_nd\n real ( kind = 8 ) t\n real ( kind = 8 ) x(n)\n real ( kind = 8 ) xc_diff_norm\n real ( kind = 8 ) xy_diff_norm\n real ( kind = 8 ) y(n)\n\n xc_diff_norm = r8vec_diff_norm ( n, x, c )\n xy_diff_norm = r8vec_diff_norm ( n, x, y )\n area = sphere_unit_area_nd ( n )\n\n t = ( r + xc_diff_norm ) * ( r - xc_diff_norm )\n b = r * area * ( xy_diff_norm ) ** n\n p = t / b\n\n return\nend\nsubroutine poisson_pdf ( x, a, pdf )\n\n!*****************************************************************************80\n!\n!! POISSON_PDF evaluates the Poisson PDF.\n!\n! Discussion:\n!\n! PDF(A;X) = EXP ( - A ) * A^X / X!\n!\n! PDF(A;X) is the probability that the number of events observed\n! in a unit time period will be X, given the expected number\n! of events in a unit time.\n!\n! The parameter A is the expected number of events per unit time.\n!\n! The Poisson PDF is a discrete version of the Exponential PDF.\n!\n! The time interval between two Poisson events is a random\n! variable with the Exponential PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X, the argument of the PDF.\n! 0 <= X\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 0.0D+00 < A.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) i4_factorial\n real ( kind = 8 ) pdf\n integer ( kind = 4 ) x\n\n if ( x < 0 ) then\n pdf = 0.0D+00\n else\n pdf = exp ( - a ) * a**x / i4_factorial ( x )\n end if\n\n return\nend\nsubroutine poisson_sample ( a, seed, x )\n\n!*****************************************************************************80\n!\n!! POISSON_SAMPLE samples the Poisson PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 0.0D+00 < A.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random number\n! generator.\n!\n! Output, integer ( kind = 4 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n integer ( kind = 4 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call poisson_cdf_inv ( cdf, a, x )\n\n return\nend\nsubroutine poisson_variance ( a, variance )\n\n!*****************************************************************************80\n!\n!! POISSON_VARIANCE returns the variance of the Poisson PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 0.0D+00 < A.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) variance\n\n variance = a\n\n return\nend\nsubroutine power_cdf ( x, a, b, cdf )\n\n!*****************************************************************************80\n!\n!! POWER_CDF evaluates the Power CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 11 July 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A, 0.0D+00 < B,\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( x <= 0.0D+00 ) then\n cdf = 0.0D+00\n else if ( x <= b ) then\n cdf = ( x / b )**a\n else\n cdf = 1.0D+00\n end if\n\n return\nend\nsubroutine power_cdf_inv ( cdf, a, b, x )\n\n!*****************************************************************************80\n!\n!! POWER_CDF_INV inverts the Power CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 11 July 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A, 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) X, the argument of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'POWER_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n if ( cdf == 0.0D+00 ) then\n x = 0.0D+00\n else if ( cdf < 1.0D+00 ) then\n x = b * exp ( log ( cdf ) / a )\n else\n x = b\n end if\n\n return\nend\nfunction power_check ( a, b )\n\n!*****************************************************************************80\n!\n!! POWER_CHECK checks the parameter of the Power PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 22 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A, 0.0D+00 < B.\n!\n! Output, logical POWER_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n logical power_check\n\n if ( a <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'POWER_CHECK - Fatal error!'\n write ( *, '(a)' ) ' A <= 0.'\n power_check = .false.\n return\n end if\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'POWER_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B <= 0.'\n power_check = .false.\n return\n end if\n\n power_check = .true.\n\n return\nend\nsubroutine power_mean ( a, b, mean )\n\n!*****************************************************************************80\n!\n!! POWER_MEAN returns the mean of the Power PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 11 July 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A, 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) mean\n\n mean = a * b / ( a + 1.0D+00 )\n\n return\nend\nsubroutine power_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! POWER_PDF evaluates the Power PDF.\n!\n! Discussion:\n!\n! PDF(A;X) = (A/B) * (X/B)^(A-1)\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 11 July 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Daniel Zwillinger, Stephen Kokoska,\n! CRC Standard Probability and Statistics Tables and Formulae,\n! Chapman and Hall/CRC, 2000, pages 152-153.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n! 0.0D+00 <= X <= B.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A, 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) pdf\n real ( kind = 8 ) x\n\n if ( x < 0.0D+00 .or. b < x ) then\n pdf = 0.0D+00\n else\n pdf = ( a / b ) * ( x / b )**( a - 1.0D+00 )\n end if\n\n return\nend\nsubroutine power_sample ( a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! POWER_SAMPLE samples the Power PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 11 July 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A, 0.0D+00 < B.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random number\n! generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call power_cdf_inv ( cdf, a, b, x )\n\n return\nend\nsubroutine power_variance ( a, b, variance )\n\n!*****************************************************************************80\n!\n!! POWER_VARIANCE returns the variance of the Power PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 11 July 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A, 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) variance\n\n variance = b * b * a / ( ( a + 1.0D+00 )**2 * ( a + 2.0D+00 ) )\n\n return\nend\nsubroutine psi_values ( n_data, x, fx )\n\n!*****************************************************************************80\n!\n!! PSI_VALUES returns some values of the Psi or Digamma function.\n!\n! Discussion:\n!\n! In Mathematica, the function can be evaluated by:\n!\n! PolyGamma[x]\n!\n! or\n!\n! PolyGamma[0,x]\n!\n! PSI(X) = d ln ( Gamma ( X ) ) / d X = Gamma'(X) / Gamma(X)\n!\n! PSI(1) = -Euler's constant.\n!\n! PSI(X+1) = PSI(X) + 1 / X.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 17 August 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Milton Abramowitz, Irene Stegun,\n! Handbook of Mathematical Functions,\n! National Bureau of Standards, 1964,\n! LC: QA47.A34,\n! ISBN: 0-486-61272-4.\n!\n! Stephen Wolfram,\n! The Mathematica Book,\n! Fourth Edition,\n! Wolfram Media / Cambridge University Press, 1999.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) N_DATA. The user sets N_DATA to 0\n! before the first call. On each call, the routine increments N_DATA by 1,\n! and returns the corresponding data; when there is no more data, the\n! output value of N_DATA will be 0 again.\n!\n! Output, real ( kind = 8 ) X, the argument of the function.\n!\n! Output, real ( kind = 8 ) FX, the value of the function.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: n_max = 11\n\n real ( kind = 8 ) fx\n real ( kind = 8 ), save, dimension ( n_max ) :: fx_vec = (/ &\n -0.5772156649015329D+00, &\n -0.4237549404110768D+00, &\n -0.2890398965921883D+00, &\n -0.1691908888667997D+00, &\n -0.6138454458511615D-01, &\n 0.3648997397857652D-01, &\n 0.1260474527734763D+00, &\n 0.2085478748734940D+00, &\n 0.2849914332938615D+00, &\n 0.3561841611640597D+00, &\n 0.4227843350984671D+00 /)\n integer ( kind = 4 ) n_data\n real ( kind = 8 ) x\n real ( kind = 8 ), save, dimension ( n_max ) :: x_vec = (/ &\n 1.0D+00, &\n 1.1D+00, &\n 1.2D+00, &\n 1.3D+00, &\n 1.4D+00, &\n 1.5D+00, &\n 1.6D+00, &\n 1.7D+00, &\n 1.8D+00, &\n 1.9D+00, &\n 2.0D+00 /)\n\n if ( n_data < 0 ) then\n n_data = 0\n end if\n\n n_data = n_data + 1\n\n if ( n_max < n_data ) then\n n_data = 0\n x = 0.0D+00\n fx = 0.0D+00\n else\n x = x_vec(n_data)\n fx = fx_vec(n_data)\n end if\n\n return\nend\nsubroutine quasigeometric_cdf ( x, a, b, cdf )\n\n!*****************************************************************************80\n!\n!! QUASIGEOMETRIC_CDF evaluates the Quasigeometric CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 January 2009\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X, the maximum number of trials.\n!\n! Input, real ( kind = 8 ) A, the probability of 0 successes.\n! 0.0 <= A <= 1.0.\n!\n! Input, real ( kind = 8 ) B, the depreciation constant.\n! 0.0 <= B < 1.0.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n integer ( kind = 4 ) x\n\n if ( x < 0 ) then\n cdf = 0.0D+00\n else if ( x == 0 ) then\n cdf = a\n else if ( b == 0.0D+00 ) then\n cdf = 1.0D+00\n else\n cdf = a + ( 1.0D+00 - a ) * ( 1.0D+00 - b**x )\n end if\n\n return\nend\nsubroutine quasigeometric_cdf_inv ( cdf, a, b, x )\n\n!*****************************************************************************80\n!\n!! QUASIGEOMETRIC_CDF_INV inverts the Quasigeometric CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 January 2009\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0D+00\n!\n! Input, real ( kind = 8 ) A, the probability of 0 successes.\n! 0.0 <= A <= 1.0.\n!\n! Input, real ( kind = 8 ) B, the depreciation constant.\n! 0.0 <= B < 1.0.\n!\n! Output, integer ( kind = 4 ) X, the corresponding value of X.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n integer ( kind = 4 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'QUASIGEOMETRIC_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n if ( cdf < a ) then\n x = 0\n else if ( b == 0.0D+00 ) then\n x = 1\n else\n x = 1 + int ( ( log ( 1.0D+00 - cdf ) - log ( 1.0D+00 - a ) ) / log ( b ) )\n end if\n\n return\nend\nfunction quasigeometric_check ( a, b )\n\n!*****************************************************************************80\n!\n!! QUASIGEOMETRIC_CHECK checks the parameters of the Quasigeometric CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 January 2009\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the probability of 0 successes.\n! 0.0 <= A <= 1.0.\n!\n! Input, real ( kind = 8 ) B, the depreciation constant.\n! 0.0 <= B < 1.0.\n!\n! Output, logical QUASIGEOMETRIC_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n logical quasigeometric_check\n\n if ( a < 0.0D+00 .or. 1.0D+00 < a ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'QUASIGEOMETRIC_CHECK - Fatal error!'\n write ( *, '(a)' ) ' A < 0 or 1 < A.'\n quasigeometric_check = .false.\n return\n end if\n\n if ( b < 0.0D+00 .or. 1.0D+00 <= b ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'QUASIGEOMETRIC_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B < 0 or 1 <= B.'\n quasigeometric_check = .false.\n return\n end if\n\n quasigeometric_check = .true.\n\n return\nend\nsubroutine quasigeometric_mean ( a, b, mean )\n\n!*****************************************************************************80\n!\n!! QUASIGEOMETRIC_MEAN returns the mean of the Quasigeometric PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 January 2009\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the probability of 0 successes.\n! 0.0 <= A <= 1.0.\n!\n! Input, real ( kind = 8 ) B, the depreciation constant.\n! 0.0 <= B < 1.0.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) mean\n\n mean = ( 1.0D+00 - a ) / ( 1.0D+00 - b )\n\n return\nend\nsubroutine quasigeometric_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! QUASIGEOMETRIC_PDF evaluates the Quasigeometric PDF.\n!\n! Discussion:\n!\n! PDF(A,B;X) = A if 0 = X;\n! = (1-A) * (1-B) * B^(X-1) if 1 <= X.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 January 2009\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Darren Glass, Philip Lowry,\n! Quasiquasigeometric Distributions and Extra Inning Baseball Games,\n! Mathematics Magazine,\n! Volume 81, Number 2, April 2008, pages 127-137.\n!\n! Paul Nahin,\n! Digital Dice: Computational Solutions to Practical Probability Problems,\n! Princeton University Press, 2008,\n! ISBN13: 978-0-691-12698-2,\n! LC: QA273.25.N34.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X, the independent variable.\n! 0 <= X\n!\n! Input, real ( kind = 8 ) A, the probability of 0 successes.\n! 0.0 <= A <= 1.0.\n!\n! Input, real ( kind = 8 ) B, the depreciation constant.\n! 0.0 <= B < 1.0.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) pdf\n integer ( kind = 4 ) x\n\n if ( x < 0 ) then\n\n pdf = 0.0D+00\n\n else if ( x == 0 ) then\n\n pdf = a\n\n else if ( b == 0.0D+00 ) then\n\n if ( x == 1 ) then\n pdf = 1.0D+00\n else\n pdf = 0.0D+00\n end if\n\n else\n\n pdf = ( 1.0D+00 - a ) * ( 1.0D+00 - b ) * b**( x - 1 )\n\n end if\n\n return\nend\nsubroutine quasigeometric_sample ( a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! QUASIGEOMETRIC_SAMPLE samples the Quasigeometric PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 January 2009\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the probability of 0 successes.\n! 0.0 <= A <= 1.0.\n!\n! Input, real ( kind = 8 ) B, the depreciation constant.\n! 0.0 <= B < 1.0.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random\n! number generator.\n!\n! Output, integer ( kind = 4 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n integer ( kind = 4 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call quasigeometric_cdf_inv ( cdf, a, b, x )\n\n return\nend\nsubroutine quasigeometric_variance ( a, b, variance )\n\n!*****************************************************************************80\n!\n!! QUASIGEOMETRIC_VARIANCE returns the variance of the Quasigeometric PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 January 2009\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the probability of 0 successes.\n! 0.0 <= A <= 1.0.\n!\n! Input, real ( kind = 8 ) B, the depreciation constant.\n! 0.0 <= B < 1.0.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) variance\n\n variance = ( 1.0D+00 - a ) * ( a + b ) / ( 1.0D+00 - b ) / ( 1.0D+00 - b )\n\n return\nend\nfunction r4_uniform_ab ( a, b, seed )\n\n!*****************************************************************************80\n!\n!! R4_UNIFORM_AB returns a scaled real ( kind = 4 ) pseudorandom number.\n!\n! Discussion:\n!\n! The pseudorandom number should be uniformly distributed\n! between A and B.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 July 2006\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 4 ) A, B, the limits of the interval.\n!\n! Input/output, integer ( kind = 4 ) SEED, the \"seed\" value, which\n! should NOT be 0. On output, SEED has been updated.\n!\n! Output, real ( kind = 4 ) R4_UNIFORM_AB, a number strictly between A and B.\n!\n implicit none\n\n real ( kind = 4 ) a\n real ( kind = 4 ) b\n integer ( kind = 4 ) i4_huge\n integer ( kind = 4 ) k\n real ( kind = 4 ) r4_uniform_ab\n integer ( kind = 4 ) seed\n\n k = seed / 127773\n\n seed = 16807 * ( seed - k * 127773 ) - k * 2836\n\n if ( seed < 0 ) then\n seed = seed + i4_huge ( )\n end if\n\n r4_uniform_ab = a + ( b - a ) * real ( seed, kind = 4 ) * 4.656612875E-10\n\n return\nend\nfunction r4_uniform_01 ( seed )\n\n!*****************************************************************************80\n!\n!! R4_UNIFORM_01 returns a unit real ( kind = 4 ) pseudorandom number.\n!\n! Discussion:\n!\n! This routine implements the recursion\n!\n! seed = 16807 * seed mod ( 2^31 - 1 )\n! r4_uniform_01 = seed / ( 2^31 - 1 )\n!\n! The integer arithmetic never requires more than 32 bits,\n! including a sign bit.\n!\n! If the initial seed is 12345, then the first three computations are\n!\n! Input Output R4_UNIFORM_01\n! SEED SEED\n!\n! 12345 207482415 0.096616\n! 207482415 1790989824 0.833995\n! 1790989824 2035175616 0.947702\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 11 August 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Paul Bratley, Bennett Fox, Linus Schrage,\n! A Guide to Simulation,\n! Springer Verlag, pages 201-202, 1983.\n!\n! Pierre L'Ecuyer,\n! Random Number Generation,\n! in Handbook of Simulation,\n! edited by Jerry Banks,\n! Wiley Interscience, page 95, 1998.\n!\n! Bennett Fox,\n! Algorithm 647:\n! Implementation and Relative Efficiency of Quasirandom\n! Sequence Generators,\n! ACM Transactions on Mathematical Software,\n! Volume 12, Number 4, pages 362-376, 1986.\n!\n! Peter Lewis, Allen Goodman, James Miller\n! A Pseudo-Random Number Generator for the System/360,\n! IBM Systems Journal,\n! Volume 8, pages 136-143, 1969.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) SEED, the \"seed\" value, which\n! should NOT be 0. On output, SEED has been updated.\n!\n! Output, real ( kind = 4 ) R4_UNIFORM_01, a new pseudorandom variate,\n! strictly between 0 and 1.\n!\n implicit none\n\n integer ( kind = 4 ) i4_huge\n integer ( kind = 4 ) k\n integer ( kind = 4 ) seed\n real ( kind = 4 ) r4_uniform_01\n\n k = seed / 127773\n\n seed = 16807 * ( seed - k * 127773 ) - k * 2836\n\n if ( seed < 0 ) then\n seed = seed + i4_huge ( )\n end if\n\n r4_uniform_01 = real ( seed, kind = 4 ) * 4.656612875E-10\n\n return\nend\nfunction r8_ceiling ( r )\n\n!*****************************************************************************80\n!\n!! R8_CEILING rounds an R8 \"up\" to the nearest integer.\n!\n! Example:\n!\n! R Value\n!\n! -1.1 -1\n! -1.0 -1\n! -0.9 0\n! 0.0 0\n! 5.0 5\n! 5.1 6\n! 5.9 6\n! 6.0 6\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 07 March 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) R, the real value to be rounded up.\n!\n! Output, integer ( kind = 4 ) R8_CEILING, the rounded value.\n!\n implicit none\n\n integer ( kind = 4 ) r8_ceiling\n real ( kind = 8 ) r\n integer ( kind = 4 ) value\n\n value = int ( r )\n if ( real ( value, kind = 8 ) < r ) then\n value = value + 1\n end if\n\n r8_ceiling = value\n\n return\nend\nfunction r8_csc ( theta )\n\n!*****************************************************************************80\n!\n!! R8_CSC returns the cosecant of X.\n!\n! Discussion:\n!\n! CSC ( THETA ) = 1.0 / SIN ( THETA )\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 May 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) THETA, the angle, in radians, whose\n! cosecant is desired. It must be the case that SIN ( THETA ) is not zero.\n!\n! Output, real ( kind = 8 ) R8_CSC, the cosecant of THETA.\n!\n implicit none\n\n real ( kind = 8 ) r8_csc\n real ( kind = 8 ) theta\n\n r8_csc = sin ( theta )\n\n if ( r8_csc == 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R8_CSC - Fatal error!'\n write ( *, '(a,g14.6)' ) ' R8_CSC undefined for THETA = ', theta\n stop 1\n end if\n\n r8_csc = 1.0D+00 / r8_csc\n\n return\nend\nfunction r8_gamma ( x )\n\n!*****************************************************************************80\n!\n!! R8_GAMMA evaluates Gamma(X) for a real argument.\n!\n! Discussion:\n!\n! This routine calculates the gamma function for a real argument X.\n!\n! Computation is based on an algorithm outlined in reference 1.\n! The program uses rational functions that approximate the gamma\n! function to at least 20 significant decimal digits. Coefficients\n! for the approximation over the interval (1,2) are unpublished.\n! Those for the approximation for 12 <= X are from reference 2.\n!\n! Modified:\n!\n! 11 February 2008\n!\n! Author:\n!\n! Original FORTRAN77 version by William Cody, Laura Stoltz.\n! FORTRAN90 version by John Burkardt.\n!\n! Reference:\n!\n! William Cody,\n! An Overview of Software Development for Special Functions,\n! in Numerical Analysis Dundee, 1975,\n! edited by GA Watson,\n! Lecture Notes in Mathematics 506,\n! Springer, 1976.\n!\n! John Hart, Ward Cheney, Charles Lawson, Hans Maehly,\n! Charles Mesztenyi, John Rice, Henry Thatcher,\n! Christoph Witzgall,\n! Computer Approximations,\n! Wiley, 1968,\n! LC: QA297.C64.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the function.\n!\n! Output, real ( kind = 8 ) R8_GAMMA, the value of the function.\n!\n implicit none\n!\n! Coefficients for minimax approximation over (12, INF).\n!\n real ( kind = 8 ), dimension ( 7 ) :: c = (/ &\n -1.910444077728D-03, &\n 8.4171387781295D-04, &\n -5.952379913043012D-04, &\n 7.93650793500350248D-04, &\n -2.777777777777681622553D-03, &\n 8.333333333333333331554247D-02, &\n 5.7083835261D-03 /)\n real ( kind = 8 ), parameter :: eps = 2.22D-16\n real ( kind = 8 ) fact\n real ( kind = 8 ), parameter :: half = 0.5D+00\n integer ( kind = 4 ) i\n integer ( kind = 4 ) n\n real ( kind = 8 ), parameter :: one = 1.0D+00\n real ( kind = 8 ), dimension ( 8 ) :: p = (/ &\n -1.71618513886549492533811D+00, &\n 2.47656508055759199108314D+01, &\n -3.79804256470945635097577D+02, &\n 6.29331155312818442661052D+02, &\n 8.66966202790413211295064D+02, &\n -3.14512729688483675254357D+04, &\n -3.61444134186911729807069D+04, &\n 6.64561438202405440627855D+04 /)\n logical parity\n real ( kind = 8 ), parameter :: pi = 3.1415926535897932384626434D+00\n real ( kind = 8 ), dimension ( 8 ) :: q = (/ &\n -3.08402300119738975254353D+01, &\n 3.15350626979604161529144D+02, &\n -1.01515636749021914166146D+03, &\n -3.10777167157231109440444D+03, &\n 2.25381184209801510330112D+04, &\n 4.75584627752788110767815D+03, &\n -1.34659959864969306392456D+05, &\n -1.15132259675553483497211D+05 /)\n real ( kind = 8 ) r8_gamma\n real ( kind = 8 ) res\n real ( kind = 8 ), parameter :: sqrtpi = 0.9189385332046727417803297D+00\n real ( kind = 8 ) sum\n real ( kind = 8 ), parameter :: twelve = 12.0D+00\n real ( kind = 8 ), parameter :: two = 2.0D+00\n real ( kind = 8 ) x\n real ( kind = 8 ), parameter :: xbig = 171.624D+00\n real ( kind = 8 ) xden\n real ( kind = 8 ), parameter :: xinf = 1.0D+30\n real ( kind = 8 ), parameter :: xminin = 2.23D-308\n real ( kind = 8 ) xnum\n real ( kind = 8 ) y\n real ( kind = 8 ) y1\n real ( kind = 8 ) ysq\n real ( kind = 8 ) z\n real ( kind = 8 ), parameter :: zero = 0.0D+00\n\n parity = .false.\n fact = one\n n = 0\n y = x\n!\n! Argument is negative.\n!\n if ( y <= zero ) then\n\n y = - x\n y1 = aint ( y )\n res = y - y1\n\n if ( res /= zero ) then\n\n if ( y1 /= aint ( y1 * half ) * two ) then\n parity = .true.\n end if\n\n fact = - pi / sin ( pi * res )\n y = y + one\n\n else\n\n res = xinf\n r8_gamma = res\n return\n\n end if\n\n end if\n!\n! Argument is positive.\n!\n if ( y < eps ) then\n!\n! Argument < EPS.\n!\n if ( xminin <= y ) then\n res = one / y\n else\n res = xinf\n r8_gamma = res\n return\n end if\n\n else if ( y < twelve ) then\n\n y1 = y\n!\n! 0.0 < argument < 1.0.\n!\n if ( y < one ) then\n\n z = y\n y = y + one\n!\n! 1.0 < argument < 12.0.\n! Reduce argument if necessary.\n!\n else\n\n n = int ( y ) - 1\n y = y - real ( n, kind = 8 )\n z = y - one\n\n end if\n!\n! Evaluate approximation for 1.0 < argument < 2.0.\n!\n xnum = zero\n xden = one\n do i = 1, 8\n xnum = ( xnum + p(i) ) * z\n xden = xden * z + q(i)\n end do\n\n res = xnum / xden + one\n!\n! Adjust result for case 0.0 < argument < 1.0.\n!\n if ( y1 < y ) then\n\n res = res / y1\n!\n! Adjust result for case 2.0 < argument < 12.0.\n!\n else if ( y < y1 ) then\n\n do i = 1, n\n res = res * y\n y = y + one\n end do\n\n end if\n\n else\n!\n! Evaluate for 12.0 <= argument.\n!\n if ( y <= xbig ) then\n\n ysq = y * y\n sum = c(7)\n do i = 1, 6\n sum = sum / ysq + c(i)\n end do\n sum = sum / y - y + sqrtpi\n sum = sum + ( y - half ) * log ( y )\n res = exp ( sum )\n\n else\n\n res = xinf\n r8_gamma = res\n return\n\n end if\n\n end if\n!\n! Final adjustments and return.\n!\n if ( parity ) then\n res = - res\n end if\n\n if ( fact /= one ) then\n res = fact / res\n end if\n\n r8_gamma = res\n\n return\nend\nfunction r8_is_int ( r )\n\n!*****************************************************************************80\n!\n!! R8_IS_INT determines if an R8 represents an integer value.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 07 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) R, the number to be checked.\n!\n! Output, logical R8_IS_INT, is TRUE if R is an integer value.\n!\n implicit none\n\n integer ( kind = 4 ) i\n integer ( kind = 4 ) i4_huge\n real ( kind = 8 ) r\n logical r8_is_int\n\n if ( real ( i4_huge ( ), kind = 8 ) < r ) then\n r8_is_int = .false.\n else if ( r < - real ( i4_huge ( ) , kind = 8 ) ) then\n r8_is_int = .false.\n else if ( r == real ( int ( r ), kind = 8 ) ) then\n r8_is_int = .true.\n else\n r8_is_int = .false.\n end if\n\n return\nend\nfunction r8_pi ( )\n\n!*****************************************************************************80\n!\n!! R8_PI returns the value of pi to 16 decimal places.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 19 December 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Output, double precision R8_PI, the value of pi.\n!\n implicit none\n\n double precision r8_pi\n\n r8_pi = 3.141592653589793D+00\n\n return\nend\nfunction r8_uniform_01 ( seed )\n\n!*****************************************************************************80\n!\n!! R8_UNIFORM_01 returns a unit pseudorandom R8.\n!\n! Discussion:\n!\n! An R8 is a real ( kind = 8 ) value.\n!\n! For now, the input quantity SEED is an integer ( kind = 4 ) variable.\n!\n! This routine implements the recursion\n!\n! seed = 16807 * seed mod ( 2**31 - 1 )\n! r8_uniform_01 = seed / ( 2**31 - 1 )\n!\n! The integer arithmetic never requires more than 32 bits,\n! including a sign bit.\n!\n! If the initial seed is 12345, then the first three computations are\n!\n! Input Output R8_UNIFORM_01\n! SEED SEED\n!\n! 12345 207482415 0.096616\n! 207482415 1790989824 0.833995\n! 1790989824 2035175616 0.947702\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 July 2006\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Paul Bratley, Bennett Fox, Linus Schrage,\n! A Guide to Simulation,\n! Springer Verlag, pages 201-202, 1983.\n!\n! Pierre L'Ecuyer,\n! Random Number Generation,\n! in Handbook of Simulation,\n! edited by Jerry Banks,\n! Wiley Interscience, page 95, 1998.\n!\n! Bennett Fox,\n! Algorithm 647:\n! Implementation and Relative Efficiency of Quasirandom\n! Sequence Generators,\n! ACM Transactions on Mathematical Software,\n! Volume 12, Number 4, pages 362-376, 1986.\n!\n! Peter Lewis, Allen Goodman, James Miller\n! A Pseudo-Random Number Generator for the System/360,\n! IBM Systems Journal,\n! Volume 8, pages 136-143, 1969.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) SEED, the \"seed\" value, which should\n! NOT be 0. On output, SEED has been updated.\n!\n! Output, real ( kind = 8 ) R8_UNIFORM_01, a new pseudorandom variate,\n! strictly between 0 and 1.\n!\n implicit none\n\n integer ( kind = 4 ) i4_huge\n integer ( kind = 4 ) k\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n\n if ( seed == 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 < 0 ) then\n seed = seed + i4_huge ( )\n end if\n!\n! Although SEED can be represented exactly as a 32 bit integer,\n! it generally cannot be represented exactly as a 32 bit real number!\n!\n r8_uniform_01 = real ( seed, kind = 8 ) * 4.656612875D-10\n\n return\nend\nfunction r8_uniform_ab ( a, b, seed )\n\n!*****************************************************************************80\n!\n!! R8_UNIFORM_AB returns a scaled pseudorandom R8.\n!\n! Discussion:\n!\n! An R8 is a real ( kind = 8 ) value.\n!\n! The pseudorandom number should be uniformly distributed\n! between A and B.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 July 2006\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the limits of the interval.\n!\n! Input/output, integer ( kind = 4 ) SEED, the \"seed\" value, which should\n! NOT be 0. On output, SEED has been updated.\n!\n! Output, real ( kind = 8 ) R8_UNIFORM_AB, a number strictly between A and B.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n integer ( kind = 4 ) i4_huge\n integer ( kind = 4 ) k\n real ( kind = 8 ) r8_uniform_ab\n integer ( kind = 4 )seed\n\n if ( seed == 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R8_UNIFORM_AB - 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 < 0 ) then\n seed = seed + i4_huge ( )\n end if\n\n r8_uniform_ab = a + ( b - a ) * real ( seed, kind = 8 ) * 4.656612875D-10\n\n return\nend\nsubroutine r8mat_print ( m, n, a, title )\n\n!*****************************************************************************80\n!\n!! R8MAT_PRINT prints an R8MAT.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 12 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, the number of rows in A.\n!\n! Input, integer ( kind = 4 ) N, the number of columns in A.\n!\n! Input, real ( kind = 8 ) A(M,N), the matrix.\n!\n! Input, character ( len = * ) TITLE, a title to be printed.\n!\n implicit none\n\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(m,n)\n character ( len = * ) title\n\n call r8mat_print_some ( m, n, a, 1, 1, m, n, title )\n\n return\nend\nsubroutine r8mat_print_some ( m, n, a, ilo, jlo, ihi, jhi, title )\n\n!*****************************************************************************80\n!\n!! R8MAT_PRINT_SOME prints some of an R8MAT.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 12 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, N, the number of rows and columns.\n!\n! Input, real ( kind = 8 ) A(M,N), an M by N matrix to be printed.\n!\n! Input, integer ( kind = 4 ) ILO, JLO, the first row and column to print.\n!\n! Input, integer ( kind = 4 ) IHI, JHI, the last row and column to print.\n!\n! Input, character ( len = * ) TITLE, an optional title.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: incx = 5\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(m,n)\n character ( len = 14 ) ctemp(incx)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) i2hi\n integer ( kind = 4 ) i2lo\n integer ( kind = 4 ) ihi\n integer ( kind = 4 ) ilo\n integer ( kind = 4 ) inc\n integer ( kind = 4 ) j\n integer ( kind = 4 ) j2\n integer ( kind = 4 ) j2hi\n integer ( kind = 4 ) j2lo\n integer ( kind = 4 ) jhi\n integer ( kind = 4 ) jlo\n logical r8_is_int\n character ( len = * ) title\n\n if ( 0 < len_trim ( title ) ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) trim ( title )\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(1:inc)\n write ( *, '(a)' ) ' Row'\n write ( *, '(a)' ) ' '\n\n i2lo = max ( ilo, 1 )\n i2hi = min ( ihi, m )\n\n do i = i2lo, i2hi\n\n do j2 = 1, inc\n\n j = j2lo - 1 + j2\n\n if ( r8_is_int ( a(i,j) ) ) then\n write ( ctemp(j2), '(f8.0,6x)' ) a(i,j)\n else\n write ( ctemp(j2), '(g14.6)' ) a(i,j)\n end if\n\n end do\n\n write ( *, '(i5,1x,5a14)' ) i, ( ctemp(j), j = 1, inc )\n\n end do\n\n end do\n\n return\nend\nfunction r8poly_value ( n, a, x )\n\n!*****************************************************************************80\n!\n!! R8POLY_VALUE evaluates an R8POLY\n!\n! Discussion:\n!\n! For sanity's sake, the value of N indicates the NUMBER of\n! coefficients, or more precisely, the ORDER of the polynomial,\n! rather than the DEGREE of the polynomial. The two quantities\n! differ by 1, but cause a great deal of confusion.\n!\n! Given N and A, the form of the polynomial is:\n!\n! p(x) = a(1) + a(2) * x + ... + a(n-1) * x^(n-2) + a(n) * x^(n-1)\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 13 August 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the order of the polynomial.\n!\n! Input, real ( kind = 8 ) A(N), the coefficients of the polynomial.\n! A(1) is the constant term.\n!\n! Input, real ( kind = 8 ) X, the point at which the polynomial is\n! to be evaluated.\n!\n! Output, real ( kind = 8 ) R8POLY_VALUE, the value of the polynomial at X.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(n)\n integer ( kind = 4 ) i\n real ( kind = 8 ) r8poly_value\n real ( kind = 8 ) x\n\n r8poly_value = a(n)\n do i = n - 1, 1, -1\n r8poly_value = r8poly_value * x + a(i)\n end do\n\n return\nend\nsubroutine r8row_max ( m, n, a, amax )\n\n!*****************************************************************************80\n!\n!! R8ROW_MAX returns the maximums of an R8ROW.\n!\n! Discussion:\n!\n! An R8ROW is an M by N array of R8 values, regarded\n! as an array of M rows of length N.\n!\n! Example:\n!\n! A =\n! 1 2 3\n! 2 6 7\n!\n! MAX =\n! 3\n! 7\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 10 October 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, N, the number of rows and columns\n! in the array.\n!\n! Input, real ( kind = 8 ) A(M,N), the array to be examined.\n!\n! Output, real ( kind = 8 ) AMAX(M), the maximums of the rows.\n!\n implicit none\n\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(m,n)\n real ( kind = 8 ) amax(m)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) j\n\n do i = 1, m\n\n amax(i) = a(i,1)\n do j = 2, n\n if ( amax(i) < a(i,j) ) then\n amax(i) = a(i,j)\n end if\n end do\n\n end do\n\n return\nend\nsubroutine r8row_mean ( m, n, x, mean )\n\n!*****************************************************************************80\n!\n!! R8ROW_MEAN returns the means of rows of an R8ROW.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, N, the number of rows and columns.\n!\n! Input, real ( kind = 8 ) X(M,N), the array whose row means are desired.\n!\n! Output, real ( kind = 8 ) MEAN(M), the means, or averages,\n! of the rows of X.\n!\n implicit none\n\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n\n integer ( kind = 4 ) i\n real ( kind = 8 ) mean(m)\n real ( kind = 8 ) x(m,n)\n\n do i = 1, m\n mean(i) = sum ( x(i,1:n) ) / real ( n )\n end do\n\n return\nend\nsubroutine r8row_min ( m, n, a, amin )\n\n!*****************************************************************************80\n!\n!! R8ROW_MIN returns the minimums of an R8ROW.\n!\n! Discussion:\n!\n! An R8ROW is an M by N array of R8 values, regarded\n! as an array of M rows of length N.\n!\n! Example:\n!\n! A =\n! 1 2 3\n! 2 6 7\n!\n! MIN =\n! 1\n! 2\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 10 October 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, N, the number of rows and columns\n! in the array.\n!\n! Input, real ( kind = 8 ) A(M,N), the array to be examined.\n!\n! Output, real ( kind = 8 ) AMIN(M), the minimums of the rows.\n!\n implicit none\n\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(m,n)\n real ( kind = 8 ) amin(m)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) j\n\n do i = 1, m\n\n amin(i) = a(i,1)\n do j = 2, n\n if ( a(i,j) < amin(i) ) then\n amin(i) = a(i,j)\n end if\n end do\n\n end do\n\n return\nend\nsubroutine r8row_variance ( m, n, x, variance )\n\n!*****************************************************************************80\n!\n!! R8ROW_VARIANCE returns the variances of the rows of an R8ROW.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, N, the number of rows and columns.\n!\n! Input, real ( kind = 8 ) X(M,N), the array whose row means are desired.\n!\n! Output, real ( kind = 8 ) VARIANCE(M), the variances of the rows of X.\n!\n implicit none\n\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n\n integer ( kind = 4 ) i\n real ( kind = 8 ) mean\n real ( kind = 8 ) variance(m)\n real ( kind = 8 ) x(m,n)\n\n do i = 1, m\n\n mean = sum ( x(i,1:n) ) / real ( n, kind = 8 )\n\n variance(i) = sum ( ( x(i,1:n) - mean )**2 )\n\n if ( 1 < n ) then\n variance(i) = variance(i) / real ( n - 1, kind = 8 )\n else\n variance(i) = 0.0D+00\n end if\n\n end do\n\n return\nend\nsubroutine r8vec_circular_variance ( n, x, circular_variance )\n\n!*****************************************************************************80\n!\n!! R8VEC_CIRCULAR_VARIANCE returns the circular variance of an R8VEC.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 December 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of entries in the vector.\n!\n! Input, real ( kind = 8 ) X(N), the vector whose variance is desired.\n!\n! Output, real ( kind = 8 ) CIRCULAR VARIANCE, the circular variance\n! of the vector entries.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) circular_variance\n real ( kind = 8 ) mean\n real ( kind = 8 ) x(n)\n\n call r8vec_mean ( n, x, mean )\n\n circular_variance = &\n ( sum ( cos ( x(1:n) - mean ) ) )**2 &\n + ( sum ( sin ( x(1:n) - mean ) ) )**2\n\n circular_variance = sqrt ( circular_variance ) / real ( n, kind = 8 )\n\n circular_variance = 1.0D+00 - circular_variance\n\n return\nend\nfunction r8vec_diff_norm ( n, a, b )\n\n!*****************************************************************************80\n!\n!! R8VEC_DIFF_NORM returns the L2 norm of the difference of R8VEC's.\n!\n! Discussion:\n!\n! An R8VEC is a vector of R8's.\n!\n! The vector L2 norm is defined as:\n!\n! R8VEC_NORM_L2 = sqrt ( sum ( 1 <= I <= N ) A(I)^2 ).\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 April 2010\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of entries in A.\n!\n! Input, real ( kind = 8 ) A(N), B(N), the vectors\n!\n! Output, real ( kind = 8 ) R8VEC_DIFF_NORM, the L2 norm of A - B.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(n)\n real ( kind = 8 ) b(n)\n real ( kind = 8 ) r8vec_diff_norm\n\n r8vec_diff_norm = sqrt ( sum ( ( a(1:n) - b(1:n) )**2 ) )\n\n return\nend\nsubroutine r8vec_max ( n, a, amax )\n\n!*****************************************************************************80\n!\n!! R8VEC_MAX returns the maximum value in an R8VEC.\n!\n! Discussion:\n!\n! An R8VEC is a vector of R8's.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 January 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of entries in the array.\n!\n! Input, real ( kind = 8 ) A(N), the array.\n!\n! Output, real ( kind = 8 ) AMAX, the value of the largest entry.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(n)\n real ( kind = 8 ) amax\n\n amax = maxval ( a(1:n) )\n\n return\nend\nsubroutine r8vec_mean ( n, x, mean )\n\n!*****************************************************************************80\n!\n!! R8VEC_MEAN returns the mean of an R8VEC.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of entries in the vector.\n!\n! Input, real ( kind = 8 ) X(N), the vector whose mean is desired.\n!\n! Output, real ( kind = 8 ) MEAN, the mean, or average,\n! of the vector entries.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) mean\n real ( kind = 8 ) x(n)\n\n mean = sum ( x(1:n) ) / real ( n, kind = 8 )\n\n return\nend\nsubroutine r8vec_min ( n, a, amin )\n\n!*****************************************************************************80\n!\n!! R8VEC_MIN returns the minimum value of an R8VEC.\n!\n! Discussion:\n!\n! An R8VEC is a vector of R8's.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 17 November 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of entries in the array.\n!\n! Input, real ( kind = 8 ) A(N), the array.\n!\n! Output, real ( kind = 8 ) AMIN, the value of the smallest entry.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(n)\n real ( kind = 8 ) amin\n\n amin = minval ( a(1:n) )\n\n return\nend\nsubroutine r8vec_print ( n, a, title )\n\n!*****************************************************************************80\n!\n!! R8VEC_PRINT prints an R8VEC.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 16 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of components of the vector.\n!\n! Input, real ( kind = 8 ) A(N), the vector to be printed.\n!\n! Input, character ( len = * ) TITLE, a title to be printed first.\n! TITLE may be blank.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(n)\n integer ( kind = 4 ) i\n character ( len = * ) title\n\n if ( title /= ' ' ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) trim ( title )\n end if\n\n write ( *, '(a)' ) ' '\n do i = 1, n\n write ( *, '(i8,g14.6)' ) i, a(i)\n end do\n\n return\nend\nsubroutine r8vec_uniform ( n, a, b, seed, r )\n\n!*****************************************************************************80\n!\n!! R8VEC_UNIFORM returns a scaled pseudorandom R8VEC.\n!\n! Discussion:\n!\n! An R8VEC is a vector of real ( kind = 8 ) values.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 July 2006\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Paul Bratley, Bennett Fox, Linus Schrage,\n! A Guide to Simulation,\n! Springer Verlag, pages 201-202, 1983.\n!\n! Bennett Fox,\n! Algorithm 647:\n! Implementation and Relative Efficiency of Quasirandom\n! Sequence Generators,\n! ACM Transactions on Mathematical Software,\n! Volume 12, Number 4, pages 362-376, 1986.\n!\n! Peter Lewis, Allen Goodman, James Miller\n! A Pseudo-Random Number Generator for the System/360,\n! IBM Systems Journal,\n! Volume 8, pages 136-143, 1969.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, the number of entries in the vector.\n!\n! Input, real ( kind = 8 ) A, B, the lower and upper limits.\n!\n! Input/output, integer ( kind = 4 ) SEED, the \"seed\" value, which\n! should NOT be 0. On output, SEED has been updated.\n!\n! Output, real ( kind = 8 ) R(N), the vector of pseudorandom values.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n integer ( kind = 4 ) i\n integer ( kind = 4 ) i4_huge\n integer ( kind = 4 ) k\n integer ( kind = 4 ) seed\n real ( kind = 8 ) r(n)\n\n if ( seed == 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R8VEC_UNIFORM - Fatal error!'\n write ( *, '(a)' ) ' Input value of SEED = 0.'\n stop 1\n end if\n\n do i = 1, n\n\n k = seed / 127773\n\n seed = 16807 * ( seed - k * 127773 ) - k * 2836\n\n if ( seed < 0 ) then\n seed = seed + i4_huge ( )\n end if\n\n r(i) = a + ( b - a ) * real ( seed, kind = 8 ) * 4.656612875D-10\n\n end do\n\n return\nend\nsubroutine r8vec_uniform_01 ( n, seed, r )\n\n!*****************************************************************************80\n!\n!! R8VEC_UNIFORM_01 returns a unit pseudorandom R8VEC.\n!\n! Discussion:\n!\n! An R8VEC is a vector of real ( kind = 8 ) values.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 05 July 2006\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Paul Bratley, Bennett Fox, Linus Schrage,\n! A Guide to Simulation,\n! Springer Verlag, pages 201-202, 1983.\n!\n! Bennett Fox,\n! Algorithm 647:\n! Implementation and Relative Efficiency of Quasirandom\n! Sequence Generators,\n! ACM Transactions on Mathematical Software,\n! Volume 12, Number 4, pages 362-376, 1986.\n!\n! Peter Lewis, Allen Goodman, James Miller\n! A Pseudo-Random Number Generator for the System/360,\n! IBM Systems Journal,\n! Volume 8, pages 136-143, 1969.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of entries in the vector.\n!\n! Input/output, integer ( kind = 4 ) SEED, the \"seed\" value, which\n! should NOT be 0. On output, SEED has been updated.\n!\n! Output, real ( kind = 8 ) R(N), the vector of pseudorandom values.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n integer ( kind = 4 ) i\n integer ( kind = 4 ) i4_huge\n integer ( kind = 4 ) k\n integer ( kind = 4 ) seed\n real ( kind = 8 ) r(n)\n\n if ( seed == 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R8VEC_UNIFORM_01 - Fatal error!'\n write ( *, '(a)' ) ' Input value of SEED = 0.'\n stop 1\n end if\n\n do i = 1, n\n\n k = seed / 127773\n\n seed = 16807 * ( seed - k * 127773 ) - k * 2836\n\n if ( seed < 0 ) then\n seed = seed + i4_huge ( )\n end if\n\n r(i) = real ( seed, kind = 8 ) * 4.656612875D-10\n\n end do\n\n return\nend\nsubroutine r8vec_unit_sum ( n, a )\n\n!*****************************************************************************80\n!\n!! R8VEC_UNIT_SUM normalizes an R8VEC to have unit sum.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 08 July 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of entries in the vector.\n!\n! Input/output, real A(N), the vector to be normalized. On output,\n! the entries of A should have unit sum. However, if the input vector\n! has zero sum, the routine halts.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a(n)\n real ( kind = 8 ) a_sum\n\n a_sum = sum ( a(1:n) )\n\n if ( a_sum == 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R8VEC_UNIT_SUM - Fatal error!'\n write ( *, '(a)' ) ' The vector entries sum to 0.'\n stop 1\n end if\n\n a(1:n) = a(1:n) / a_sum\n\n return\nend\nsubroutine r8vec_variance ( n, x, variance )\n\n!*****************************************************************************80\n!\n!! R8VEC_VARIANCE returns the variance of an R8VEC.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 May 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of entries in the vector.\n!\n! Input, real ( kind = 8 ) X(N), the vector whose variance is desired.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the vector entries.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) mean\n real ( kind = 8 ) variance\n real ( kind = 8 ) x(n)\n\n call r8vec_mean ( n, x, mean )\n\n variance = sum ( ( x(1:n) - mean )**2 )\n\n if ( 1 < n ) then\n variance = variance / real ( n - 1, kind = 8 )\n else\n variance = 0.0D+00\n end if\n\n return\nend\nsubroutine random_initialize ( seed_input )\n\n!*****************************************************************************80\n!\n!! RANDOM_INITIALIZE initializes the FORTRAN90 random number seed.\n!\n! Discussion:\n!\n! If you don't initialize the FORTRAN90 random number generator\n! routine RANDOM_NUMBER, which is used by calls like\n!\n! call random_number ( harvest = x )\n!\n! then its behavior is not specified. That may be OK for you. But\n! you may want to be able to force the same sequence to be generated\n! each time, or to force a different sequence.\n!\n! To control the sequence of random numbers, you need to set the seed.\n! In FORTRAN90, this is done by calling the RANDOM+SEED routine.\n! You can call it with no arguments, in fact. But if you call\n! it with no arguments:\n!\n! call random_seed ( )\n!\n! then its behavior (or more particularly, the behavior of RANDOM_NUMBER)\n! is still not specified. You might hope that the system will go out\n! and pick a nice random seed for you, but there's no guarantee.\n!\n!\n! For example, on the DEC ALPHA, if you compile a program that calls\n! RANDOM_NUMBER, then every time you run it, you get the same sequence\n! of \"random\" values. If you compile a program that calls RANDOM_SEED\n! with no arguments, and then calls RANDOM_NUMBER, you still get the\n! same sequence each time you run the program.\n!\n! In order to actually try to scramble up the random number generator\n! a bit, this routine goes through the tedious process of getting the\n! size of the random number seed, making up values based on the current\n! time, and setting the random number seed.\n!\n! Unfortunately, the RANDOM_SEED routine has a very elastic definition.\n! It does not use a single scalar integer SEED. Instead, it communicates\n! with the user through an integer vector whose size is not specified.\n! You actually have to \"ask\" the routine to tell you the size of this\n! vector. Then you can fill up the vector with values to be used to\n! influence the seeding of the random number routine. The details of\n! how the seed affects the sequence are also unspecified, but the only\n! thing we are reasonably confident about is that specifying the same\n! seed should result in the same sequence, and specifying different\n! seeds should result in different sequences!\n!\n! I assume this is far more than you wanted to know. (It's certainly\n! more than I wanted to know!)\n!\n! The argument SEED is an input quantity only, so it is legal\n! to type\n!\n! call random_initialize ( 0 )\n!\n! or\n!\n! call random_initialize ( 18867 )\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 February 2006\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) SEED_INPUT, the user's \"suggestion\" for a seed.\n! However, if the input value is 0, the routine will come up with\n! its own \"suggestion\", based on the system clock.\n!\n implicit none\n\n integer ( kind = 4 ) count\n integer ( kind = 4 ) count_max\n integer ( kind = 4 ) count_rate\n logical, parameter :: debug = .false.\n integer ( kind = 4 ) i\n integer ( kind = 4 ) seed\n integer ( kind = 4 ) seed_input\n integer ( kind = 4 ), allocatable :: seed_vector(:)\n integer ( kind = 4 ) seed_size\n real ( kind = 8 ) t\n integer ( kind = 4 ), parameter :: warm_up = 100\n\n seed = seed_input\n!\n! Initialize the random seed routine.\n!\n call random_seed ( )\n!\n! Determine the size of the random number seed vector.\n!\n call random_seed ( size = seed_size )\n!\n! Allocate a vector of the right size to be used as a random seed.\n!\n allocate ( seed_vector(seed_size) )\n!\n! If the user supplied a SEED value, use that.\n!\n! Otherwise, use the system clock value to make up a value that is\n! likely to change based on when this routine is called.\n!\n if ( seed /= 0 ) then\n\n if ( debug ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'RANDOM_INITIALIZE'\n write ( *, '(a,i20)' ) ' Initialize RANDOM_NUMBER, user SEED = ', seed\n end if\n\n else\n\n call system_clock ( count, count_rate, count_max )\n\n seed = count\n\n if ( debug ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'RANDOM_INITIALIZE'\n write ( *, '(a,i20)' ) ' Initialize RANDOM_NUMBER, arbitrary SEED = ', &\n seed\n end if\n\n end if\n!\n! Set the seed vector. We don't know the significance of the\n! individual entries of the internal seed vector, so we'll just set\n! all entries to SEED.\n!\n seed_vector(1:seed_size) = seed\n!\n! Now call RANDOM_SEED, and tell it to use this seed vector.\n!\n call random_seed ( put = seed_vector(1:seed_size) )\n!\n! Free up the seed space.\n!\n deallocate ( seed_vector )\n!\n! Call the random number routine a bunch of times just to \"warm it up\".\n!\n do i = 1, warm_up\n call random_number ( harvest = t )\n end do\n\n return\nend\nsubroutine rayleigh_cdf ( x, a, cdf )\n\n!*****************************************************************************80\n!\n!! RAYLEIGH_CDF evaluates the Rayleigh CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 16 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n! 0.0D+00 <= X.\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 0.0D+00 < A.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( x < 0.0D+00 ) then\n cdf = 0.0D+00\n else\n cdf = 1.0D+00 - exp ( - x**2 / ( 2.0D+00 * a**2 ) )\n end if\n\n return\nend\nsubroutine rayleigh_cdf_inv ( cdf, a, x )\n\n!*****************************************************************************80\n!\n!! RAYLEIGH_CDF_INV inverts the Rayleigh CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 16 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 0.0D+00 < A.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'RAYLEIGH_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n x = sqrt ( - 2.0D+00 * a * a * log ( 1.0D+00 - cdf ) )\n\n return\nend\nsubroutine rayleigh_cdf_values ( n_data, sigma, x, fx )\n\n!*****************************************************************************80\n!\n!! RAYLEIGH_CDF_VALUES returns some values of the Rayleigh CDF.\n!\n! Discussion:\n!\n! In Mathematica, the function can be evaluated by:\n!\n! Needs[\"Statistics`ContinuousDistributions`\"]\n! dist = RayleighDistribution [ sigma ]\n! CDF [ dist, x ]\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Milton Abramowitz, Irene Stegun,\n! Handbook of Mathematical Functions,\n! National Bureau of Standards, 1964,\n! LC: QA47.A34,\n! ISBN: 0-486-61272-4.\n!\n! Stephen Wolfram,\n! The Mathematica Book,\n! Fourth Edition,\n! Wolfram Media / Cambridge University Press, 1999.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) N_DATA. The user sets N_DATA to 0\n! before the first call. On each call, the routine increments N_DATA by 1,\n! and returns the corresponding data; when there is no more data, the\n! output value of N_DATA will be 0 again.\n!\n! Output, real ( kind = 8 ) SIGMA, the shape parameter of the distribution.\n!\n! Output, real ( kind = 8 ) X, the argument of the function.\n!\n! Output, real ( kind = 8 ) FX, the value of the function.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: n_max = 9\n\n real ( kind = 8 ) fx\n real ( kind = 8 ), save, dimension ( n_max ) :: fx_vec = (/ &\n 0.8646647167633873D+00, &\n 0.9996645373720975D+00, &\n 0.9999999847700203D+00, &\n 0.999999999999987D+00, &\n 0.8646647167633873D+00, &\n 0.3934693402873666D+00, &\n 0.1992625970831920D+00, &\n 0.1175030974154046D+00, &\n 0.7688365361336422D-01 /)\n integer ( kind = 4 ) n_data\n real ( kind = 8 ) sigma\n real ( kind = 8 ), save, dimension ( n_max ) :: sigma_vec = (/ &\n 0.5000000000000000D+00, &\n 0.5000000000000000D+00, &\n 0.5000000000000000D+00, &\n 0.5000000000000000D+00, &\n 0.1000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.4000000000000000D+01, &\n 0.5000000000000000D+01 /)\n real ( kind = 8 ) x\n real ( kind = 8 ), save, dimension ( n_max ) :: x_vec = (/ &\n 0.1000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.4000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01 /)\n\n if ( n_data < 0 ) then\n n_data = 0\n end if\n\n n_data = n_data + 1\n\n if ( n_max < n_data ) then\n n_data = 0\n sigma = 0.0D+00\n x = 0.0D+00\n fx = 0.0D+00\n else\n sigma = sigma_vec(n_data)\n x = x_vec(n_data)\n fx = fx_vec(n_data)\n end if\n\n return\nend\nfunction rayleigh_check ( a )\n\n!*****************************************************************************80\n!\n!! RAYLEIGH_CHECK checks the parameter of the Rayleigh PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 22 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 0.0D+00 < A.\n!\n! Output, logical RAYLEIGH_CHECK, is true if the parameter is legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n logical rayleigh_check\n\n if ( a <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'RAYLEIGH_CHECK - Fatal error!'\n write ( *, '(a)' ) ' A <= 0.'\n rayleigh_check = .false.\n return\n end if\n\n rayleigh_check = .true.\n\n return\nend\nsubroutine rayleigh_mean ( a, mean )\n\n!*****************************************************************************80\n!\n!! RAYLEIGH_MEAN returns the mean of the Rayleigh PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 16 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 0.0D+00 < A.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) mean\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n\n mean = a * sqrt ( 0.5D+00 * pi )\n\n return\nend\nsubroutine rayleigh_pdf ( x, a, pdf )\n\n!*****************************************************************************80\n!\n!! RAYLEIGH_PDF evaluates the Rayleigh PDF.\n!\n! Discussion:\n!\n! PDF(A;X) = ( X / A^2 ) * EXP ( - X^2 / ( 2 * A^2 ) )\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 15 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n! 0.0D+00 <= X\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 0 < A.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) pdf\n real ( kind = 8 ) x\n\n if ( x < 0.0D+00 ) then\n pdf = 0.0D+00\n else\n pdf = ( x / a**2 ) * exp ( - x**2 / ( 2.0D+00 * a**2 ) )\n end if\n\n return\nend\nsubroutine rayleigh_sample ( a, seed, x )\n\n!*****************************************************************************80\n!\n!! RAYLEIGH_SAMPLE samples the Rayleigh PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 16 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 0.0D+00 < A.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call rayleigh_cdf_inv ( cdf, a, x )\n\n return\nend\nsubroutine rayleigh_variance ( a, variance )\n\n!*****************************************************************************80\n!\n!! RAYLEIGH_VARIANCE returns the variance of the Rayleigh PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 16 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the parameters of the PDF.\n! 0.0D+00 < A.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) variance\n\n variance = 2.0D+00 * a**2 * ( 1.0D+00 - 0.25D+00 * pi )\n\n return\nend\nsubroutine reciprocal_cdf ( x, a, b, cdf )\n\n!*****************************************************************************80\n!\n!! RECIPROCAL_CDF evaluates the Reciprocal CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A <= B.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( x <= 0.0D+00 ) then\n\n cdf = 0.0D+00\n\n else if ( 0.0D+00 < x ) then\n\n cdf = log ( a / x ) / log ( a / b )\n\n end if\n\n return\nend\nsubroutine reciprocal_cdf_inv ( cdf, a, b, x )\n\n!*****************************************************************************80\n!\n!! RECIPROCAL_CDF_INV inverts the Reciprocal CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A <= B.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'RECIPROCAL_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n if ( cdf == 0.0D+00 ) then\n x = 0.0D+00\n else if ( 0.0D+00 < cdf ) then\n x = b**cdf / a**( cdf - 1.0D+00 )\n end if\n\n return\nend\nfunction reciprocal_check ( a, b )\n\n!*****************************************************************************80\n!\n!! RECIPROCAL_CHECK checks the parameters of the Reciprocal CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 22 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A <= B.\n!\n! Output, logical RECIPROCAL_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n logical reciprocal_check\n\n if ( a <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'RECIPROCAL_CHECK - Fatal error!'\n write ( *, '(a)' ) ' A <= 0.0'\n reciprocal_check = .false.\n return\n end if\n\n if ( b < a ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'RECIPROCAL_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B < A'\n reciprocal_check = .false.\n return\n end if\n\n reciprocal_check = .true.\n\n return\nend\nsubroutine reciprocal_mean ( a, b, mean )\n\n!*****************************************************************************80\n!\n!! RECIPROCAL_MEAN returns the mean of the Reciprocal PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A <= B.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) mean\n\n mean = ( a - b ) / log ( a / b )\n\n return\nend\nsubroutine reciprocal_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! RECIPROCAL_PDF evaluates the Reciprocal PDF.\n!\n! Discussion:\n!\n! PDF(A,B;X) = 1.0D+00 / ( X * LOG ( B / A ) )\n! for 0.0D+00 <= X\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A <= B.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) pdf\n real ( kind = 8 ) x\n\n if ( x <= 0.0D+00 ) then\n pdf = 0.0D+00\n else if ( 0.0D+00 < x ) then\n pdf = 1.0D+00 / ( x * log ( b / a ) )\n end if\n\n return\nend\nsubroutine reciprocal_sample ( a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! RECIPROCAL_SAMPLE samples the Reciprocal PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A <= B.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n x = b**cdf / a**( cdf - 1.0D+00 )\n\n return\nend\nsubroutine reciprocal_variance ( a, b, variance )\n\n!*****************************************************************************80\n!\n!! RECIPROCAL_VARIANCE returns the variance of the Reciprocal PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < A <= B.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) d\n real ( kind = 8 ) variance\n\n d = log ( a / b )\n\n variance = ( a - b )* ( a * ( d - 2.0D+00 ) &\n + b * ( d + 2.0D+00 ) ) / ( 2.0D+00 * d**2 )\n\n return\nend\nsubroutine ribesl ( x, alpha, nb, ize, b, ncalc )\n\n!*****************************************************************************80\n!\n!! RIBESL calculates I Bessel function with non-integer orders.\n!\n! Discussion:\n!\n! This routine calculates Bessel functions I SUB(N+ALPHA) (X)\n! for non-negative argument X, and non-negative order N+ALPHA,\n! with or without exponential scaling.\n!\n! This program is based on a program written by David\n! Sookne that computes values of the Bessel functions J or\n! I of real argument and integer order. Modifications include\n! the restriction of the computation to the I Bessel function\n! of non-negative real argument, the extension of the computation\n! to arbitrary positive order, the inclusion of optional\n! exponential scaling, and the elimination of most underflow.\n!\n! In case of an error, NCALC will not equal NB, and not all I's are\n! calculated to the desired accuracy.\n!\n! If NCALC < 0: An argument is out of range. For example,\n! NB <= 0, IZE is not 1 or 2, or IZE = 1 and EXPARG <= ABS(X)\n! In this case, the B-vector is not calculated, and NCALC is\n! set to MIN(NB,0)-1 so that NCALC /= NB.\n!\n! If 0 < NCALC < NB, then not all requested function values could\n! be calculated accurately. This usually occurs because NB is\n! much larger than ABS(X). In this case, B(N) is calculated\n! to the desired accuracy for N <= NCALC, but precision\n! is lost for NCALC < N <= NB. If B(N) does not vanish\n! for NCALC < N (because it is too small to be represented),\n! and B(N)/B(NCALC) = 10**(-K), then only the first NSIG-K\n! significant figures of B(N) can be trusted.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 March 2007\n!\n! Author:\n!\n! Original FORTRAN77 version by William Cody.\n! FORTRAN90 version by John Burkardt.\n!\n! Reference:\n!\n! Frank Olver, David Sookne,\n! A Note on Backward Recurrence Algorithms,\n! Mathematics of Computation,\n! Volume 26, 1972, pages 941-947.\n!\n! David Sookne,\n! Bessel Functions of Real Argument and Integer Order,\n! NBS Journal of Research B,\n! Volume 77B, 1973, pages 125-132.\n!\n! William Cody,\n! Algorithm 597:\n! Sequence of Modified Bessel Functions of the First Kind,\n! ACM Transactions of Mathematical Software,\n! Volume 9, Number 2, June 1983, pages 242-245.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument for which the functions\n! are to be calculated.\n!\n! Input, real ( kind = 8 ) ALPHA,the fractional part of the order\n! for which the functions are to be calculated.\n! 0 <= ALPHA < 1.0.\n!\n! Input, integer ( kind = 4 ) NB, the number of functions to be calculated.\n! The first function calculated is of order ALPHA, and the\n! last is of order (NB - 1 + ALPHA). 1 <= NB.\n!\n! Input, integer ( kind = 4 ) IZE, scaling option.\n! 1, unscaled I's are to calculated,\n! 2, exponentially scaled I's are to be calculated.\n!\n! Output, real ( kind = 8 ) B(NB), the values of the functions\n! I(ALPHA,X) through I(NB-1+ALPHA,X), with scaling if requested.\n!\n! Output, integer ( kind = 4 ) NCALC, error indicator.\n! If NCALC = NB, then all the requested values were calculated\n! to the desired accuracy.\n!\n! Local Parameeters:\n!\n! BETA, the radix for the floating-point system.\n!\n! MINEXP, smallest representable power of BETA.\n!\n! MAXEXP, smallest power of BETA that overflows\n!\n! IT, number of bits in the mantissa of a working precision variable.\n!\n! NSIG, decimal significance desired. Should be set to\n! INT(LOG10(2)*IT+1). Setting NSIG lower will result\n! in decreased accuracy while setting NSIG higher will\n! increase CPU time without increasing accuracy. The\n! truncation error is limited to a relative error of\n! T=.5*10^(-NSIG).\n!\n! ENTEN, 10.0^K, where K is the largest integer such that\n! ENTEN is machine-representable in working precision\n!\n! ENSIG, 10.0^NSIG\n!\n! RTNSIG, 10.0^(-K) for the smallest integer K such that\n! NSIG/4 <= K.\n!\n! ENMTEN, smallest ABS(X) such that X/4 does not underflow\n!\n! XLARGE, upper limit on the magnitude of X when IZE=2. Bear\n! in mind that if ABS(X)=N, then at least N iterations\n! of the backward recursion will be executed. The value\n! of 10.0^4 is used on every machine.\n!\n! EXPARG, largest working precision argument that the library\n! EXP routine can handle and upper limit on the\n! magnitude of X when IZE=1; approximately log(BETA^MAXEXP).\n!\n! Approximate values for some important machines are:\n!\n! beta minexp maxexp it\n!\n! CRAY-1 (S.P.) 2 -8193 8191 48\n! Cyber 180/855\n! under NOS (S.P.) 2 -975 1070 48\n! IEEE (IBM/XT,\n! SUN, etc.) (S.P.) 2 -126 128 24\n! IEEE (IBM/XT,\n! SUN, etc.) (D.P.) 2 -1022 1024 53\n! IBM 3033 (D.P.) 16 -65 63 14\n! VAX (S.P.) 2 -128 127 24\n! VAX D-Format (D.P.) 2 -128 127 56\n! VAX G-Format (D.P.) 2 -1024 1023 53\n!\n!\n! NSIG ENTEN ENSIG RTNSIG\n!\n! CRAY-1 (S.P.) 15 1.0E+2465 1.0E+15 1.0E-4\n! Cyber 180/855\n! under NOS (S.P.) 15 1.0E+322 1.0E+15 1.0E-4\n! IEEE (IBM/XT,\n! SUN, etc.) (S.P.) 8 1.0E+38 1.0E+8 1.0E-2\n! IEEE (IBM/XT,\n! SUN, etc.) (D.P.) 16 1.0D+308 1.0D+16 1.0D-4\n! IBM 3033 (D.P.) 5 1.0D+75 1.0D+5 1.0D-2\n! VAX (S.P.) 8 1.0E+38 1.0E+8 1.0E-2\n! VAX D-Format (D.P.) 17 1.0D+38 1.0D+17 1.0D-5\n! VAX G-Format (D.P.) 16 1.0D+307 1.0D+16 1.0D-4\n!\n!\n! ENMTEN XLARGE EXPARG\n!\n! CRAY-1 (S.P.) 1.84E-2466 1.0E+4 5677\n! Cyber 180/855\n! under NOS (S.P.) 1.25E-293 1.0E+4 741\n! IEEE (IBM/XT,\n! SUN, etc.) (S.P.) 4.70E-38 1.0E+4 88\n! IEEE (IBM/XT,\n! SUN, etc.) (D.P.) 8.90D-308 1.0D+4 709\n! IBM 3033 (D.P.) 2.16D-78 1.0D+4 174\n! VAX (S.P.) 1.17E-38 1.0E+4 88\n! VAX D-Format (D.P.) 1.17D-38 1.0D+4 88\n! VAX G-Format (D.P.) 2.22D-308 1.0D+4 709\n!\n implicit none\n\n integer ( kind = 4 ) nb\n\n real ( kind = 8 ) alpha\n real ( kind = 8 ) b(nb)\n real ( kind = 8 ), parameter :: const = 1.585D+00\n real ( kind = 8 ) em\n real ( kind = 8 ) empal\n real ( kind = 8 ) emp2al\n real ( kind = 8 ) en\n real ( kind = 8 ), parameter :: enmten = 8.9D-308\n real ( kind = 8 ), parameter :: ensig = 1.0D+16\n real ( kind = 8 ), parameter :: enten = 1.0D+308\n real ( kind = 8 ), parameter :: exparg = 709.0D+00\n logical flag\n real ( kind = 8 ), parameter :: half = 0.5D+00\n real ( kind = 8 ) halfx\n integer ( kind = 4 ) ize\n integer ( kind = 4 ) k\n integer ( kind = 4 ) l\n integer ( kind = 4 ) magx\n integer ( kind = 4 ) n\n integer ( kind = 4 ) nbmx\n integer ( kind = 4 ) ncalc\n integer ( kind = 4 ) nend\n integer ( kind = 4 ), parameter :: nsig = 16\n integer ( kind = 4 ) nstart\n real ( kind = 8 ), parameter :: one = 1.0D+00\n real ( kind = 8 ) p\n real ( kind = 8 ) plast\n real ( kind = 8 ) pold\n real ( kind = 8 ) psave\n real ( kind = 8 ) psavel\n real ( kind = 8 ) r8_gamma\n real ( kind = 8 ), parameter :: rtnsig = 1.0D-04\n real ( kind = 8 ) tempa\n real ( kind = 8 ) tempb\n real ( kind = 8 ) tempc\n real ( kind = 8 ) test\n real ( kind = 8 ) total\n real ( kind = 8 ) tover\n real ( kind = 8 ), parameter :: two = 2.0D+00\n real ( kind = 8 ) x\n real ( kind = 8 ), parameter :: xlarge = 1.0D+04\n real ( kind = 8 ), parameter :: zero = 0.0D+00\n!\n! Check for X, NB, OR IZE out of range.\n!\n if ( nb <= 0 ) then\n ncalc = min ( nb, 0 ) - 1\n return\n end if\n\n if ( x < 0.0D+00 ) then\n ncalc = min ( nb, 0 ) - 1\n return\n end if\n\n if ( alpha < 0.0D+00 ) then\n ncalc = min ( nb, 0 ) - 1\n return\n end if\n\n if ( 1.0D+00 <= alpha ) then\n ncalc = min ( nb, 0 ) - 1\n return\n end if\n\n if ( ize == 1 .and. exparg < x ) then\n ncalc = min ( nb, 0 ) - 1\n return\n end if\n\n if ( ize == 2 .and. xlarge < x ) then\n ncalc = min ( nb, 0 ) - 1\n return\n end if\n!\n! Use 2-term ascending series for small X.\n!\n ncalc = nb\n magx = int ( x )\n!\n! Initialize the forward sweep, the P-sequence of Olver.\n!\n if ( rtnsig <= x ) then\n\n nbmx = nb - magx\n n = magx + 1\n en = real ( n + n, kind = 8 ) + ( alpha + alpha )\n plast = one\n p = en / x\n!\n! Calculate general significance test.\n!\n test = ensig + ensig\n\n if ( 5 * nsig < 2 * magx ) then\n test = sqrt ( test * p )\n else\n test = test / const**magx\n end if\n!\n! Calculate P-sequence until N = NB-1. Check for possible overflow.\n!\n flag = .false.\n\n if ( 3 <= nbmx ) then\n\n tover = enten / ensig\n nstart = magx + 2\n nend = nb - 1\n\n do k = nstart, nend\n\n n = k\n en = en + two\n pold = plast\n plast = p\n p = en * plast / x + pold\n!\n! To avoid overflow, divide P-sequence by TOVER. Calculate\n! P-sequence until 1 < ABS(P).\n!\n if ( tover < p ) then\n\n tover = enten\n p = p / tover\n plast = plast / tover\n psave = p\n psavel = plast\n nstart = n + 1\n\n do\n\n n = n + 1\n en = en + two\n pold = plast\n plast = p\n p = en * plast / x + pold\n\n if ( 1.0D+00 < p ) then\n exit\n end if\n\n end do\n\n tempb = en / x\n!\n! Calculate backward test, and find NCALC, the highest N\n! such that the test is passed.\n!\n test = pold * plast / ensig\n test = test * ( half - half / ( tempb * tempb ) )\n p = plast * tover\n n = n - 1\n en = en - two\n nend = min ( nb, n )\n\n ncalc = nend + 1\n\n do l = nstart, nend\n\n pold = psavel\n psavel = psave\n psave = en * psavel / x + pold\n\n if ( test < psave * psavel ) then\n ncalc = l\n exit\n end if\n\n end do\n\n ncalc = ncalc - 1\n flag = .true.\n exit\n\n end if\n\n end do\n\n if ( .not. flag ) then\n\n n = nend\n en = real ( n + n, kind = 8 ) + ( alpha + alpha )\n!\n! Calculate special significance test for 2 < NBMX.\n!\n test = max ( test, sqrt ( plast * ensig ) * sqrt ( p + p ) )\n\n end if\n\n end if\n!\n! Calculate P-sequence until significance test passed.\n!\n if ( .not. flag ) then\n\n do\n\n n = n + 1\n en = en + two\n pold = plast\n plast = p\n p = en * plast / x + pold\n\n if ( test <= p ) then\n exit\n end if\n\n end do\n\n end if\n!\n! Initialize the backward recursion and the normalization sum.\n!\n n = n + 1\n en = en + two\n tempb = zero\n tempa = one / p\n em = real ( n, kind = 8 ) - one\n empal = em + alpha\n emp2al = ( em - one ) + ( alpha + alpha )\n total = tempa * empal * emp2al / em\n nend = n - nb\n!\n! N < NB, so store B(N) and set higher orders to zero.\n!\n if ( nend < 0 ) then\n\n b(n) = tempa\n nend = -nend\n\n do l = 1, nend\n b(n+l) = zero\n end do\n\n nend = n - 2\n!\n! Calculate via difference equation and store B(N), until N = 2.\n!\n if ( 0 < nend ) then\n\n do l = 1, nend\n n = n - 1\n en = en - two\n b(n) = ( en * b(n+1) ) / x + b(n+2)\n em = em - one\n emp2al = emp2al - one\n if ( n == 2 ) then\n emp2al = one\n end if\n empal = empal - one\n total = ( total + b(n) * empal ) * emp2al / em\n end do\n\n end if\n!\n! Calculate B(1).\n!\n b(1) = two * empal * b(2) / x + b(3)\n\n total = ( total + total ) + b(1)\n!\n! Recur backward via difference equation, calculating (but\n! not storing) B(N), until N = NB.\n!\n else\n\n if ( 0 < nend ) then\n\n do l = 1, nend\n\n n = n - 1\n en = en - two\n tempc = tempb\n tempb = tempa\n tempa = ( en * tempb ) / x + tempc\n em = em - one\n emp2al = emp2al - one\n\n if ( n == 1 ) then\n exit\n end if\n\n if ( n == 2 ) then\n emp2al = one\n end if\n\n empal = empal - one\n total = ( total + tempa * empal ) * emp2al / em\n\n end do\n\n end if\n!\n! Store B(NB).\n!\n b(n) = tempa\n\n if ( nb <= 1 ) then\n\n total = ( total + total ) + tempa\n!\n! Calculate and Store B(NB-1).\n!\n else\n\n n = n - 1\n en = en - two\n b(n) = ( en * tempa ) / x + tempb\n\n if ( 1 < n ) then\n\n em = em - one\n emp2al = emp2al - one\n\n if ( n == 2 ) then\n emp2al = one\n end if\n\n empal = empal - one\n total = ( total + b(n) * empal ) * emp2al / em\n\n nend = n - 2\n!\n! Calculate via difference equation and store B(N), until N = 2.\n!\n if ( 0 < nend ) then\n\n do l = 1, nend\n n = n - 1\n en = en - two\n b(n) = ( en * b(n+1) ) / x + b(n+2)\n em = em - one\n emp2al = emp2al - one\n if ( n == 2 ) then\n emp2al = one\n end if\n empal = empal - one\n total = ( total + b(n) * empal ) * emp2al / em\n end do\n\n end if\n!\n! Calculate B(1).\n!\n b(1) = two * empal * b(2) / x + b(3)\n\n end if\n\n total = ( total + total ) + b(1)\n\n end if\n\n end if\n!\n! Normalize. Divide all B(N) by TOTAL.\n!\n\n\n if ( alpha /= zero ) then\n total = total * r8_gamma ( one + alpha ) * ( x * half )**( -alpha )\n end if\n\n if ( ize == 1 ) then\n total = total * exp ( -x )\n end if\n\n tempa = enmten\n\n if ( 1.0D+00 < total ) then\n tempa = tempa * total\n end if\n\n do n = 1, nb\n if ( b(n) < tempa ) then\n b(n) = zero\n end if\n b(n) = b(n) / total\n end do\n\n return\n!\n! Two-term ascending series for small X.\n!\n else\n\n tempa = one\n empal = one + alpha\n halfx = zero\n\n if ( enmten < x ) then\n halfx = half * x\n end if\n\n if ( alpha /= zero ) then\n tempa = halfx**alpha / r8_gamma ( empal )\n end if\n\n if ( ize == 2 ) then\n tempa = tempa * exp ( - x )\n end if\n\n tempb = zero\n\n if ( one < x + one ) then\n tempb = halfx * halfx\n end if\n\n b(1) = tempa + tempa * tempb / empal\n\n if ( x /= zero .and. b(1) == zero ) then\n ncalc = 0\n end if\n\n if ( 1 < nb ) then\n\n if ( x == zero ) then\n\n b(2:nb) = zero\n!\n! Calculate higher-order functions.\n!\n else\n\n tempc = halfx\n tover = ( enmten + enmten ) / x\n\n if ( tempb /= zero ) then\n tover = enmten / tempb\n end if\n\n do n = 2, nb\n\n tempa = tempa / empal\n empal = empal + one\n tempa = tempa * tempc\n\n if ( tempa <= tover * empal ) then\n tempa = zero\n end if\n\n b(n) = tempa + tempa * tempb / empal\n\n if ( b(n) == zero .and. n < ncalc ) then\n ncalc = n - 1\n end if\n\n end do\n\n end if\n\n end if\n\n end if\n\n return\nend\nsubroutine runs_mean ( m, n, mean )\n\n!*****************************************************************************80\n!\n!! RUNS_MEAN returns the mean of the Runs PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 23 January 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, N, the parameters of the PDF.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) m\n real ( kind = 8 ) mean\n integer ( kind = 4 ) n\n\n mean = real ( m + 2 * m * n + n, kind = 8 ) &\n / real ( m + n, kind = 8 )\n\n return\nend\nsubroutine runs_pdf ( m, n, r, pdf )\n\n!*****************************************************************************80\n!\n!! RUNS_PDF evaluates the Runs PDF.\n!\n! Discussion:\n!\n! Suppose we have M symbols of one type and N of another, and we consider\n! the various possible permutations of these symbols.\n!\n! Let \"R\" be the number of runs in a given permutation. By a \"run\", we\n! mean a maximal sequence of identical symbols. Thus, for instance,\n! the permutation\n!\n! ABBBAAAAAAAA\n!\n! has three runs.\n!\n! The probability that a permutation of M+N symbols, with M of one kind\n! and N of another, will have exactly R runs is:\n!\n! PDF(M,N)(R) = 2 * C(M-1,R/2-1) * C(N-1,R/2-1)\n! / C(M+N,N) for R even;\n!\n! = ( C(M-1,(R-1)/2) * C(N-1,(R-3)/2 )\n! + C(M-1,(R-3)/2) * C(N-1,(R-1)/2 )\n! ) / C(M+N,N) for R odd.\n!\n! The minimum number of runs is:\n!\n! 1 if M or N is 0,\n! 2 otherwise.\n!\n! The maximum number of runs is:\n!\n! M + N, if M = N\n! 2 * min ( M, N ) + 1 otherwise\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 23 January 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Kalimutha Krishnamoorthy,\n! Handbook of Statistical Distributions with Applications,\n! Chapman and Hall, 2006,\n! ISBN: 1-58488-635-8,\n! LC: QA273.6.K75.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, N, the parameters of the PDF.\n!\n! Input, integer ( kind = 4 ) R, the number of runs.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) combinatorial\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n real ( kind = 8 ) pdf\n integer ( kind = 4 ) r\n\n if ( m < 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'RUN_PDF - Fatal error!'\n write ( *, '(a)' ) ' M must be at least 0.'\n write ( *, '(a,i8)' ) ' The input value of M = ', m\n stop 1\n end if\n\n if ( n < 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'RUN_PDF - Fatal error!'\n write ( *, '(a)' ) ' N must be at least 0.'\n write ( *, '(a,i8)' ) ' The input value of N = ', n\n stop 1\n end if\n\n if ( n + m <= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'RUN_PDF - Fatal error!'\n write ( *, '(a)' ) ' M+N must be at least 1.'\n write ( *, '(a,i8)' ) ' The input value of M+N = ', m + n\n stop 1\n end if\n!\n! If all the symbols are of one type, there is always 1 run.\n!\n if ( m == 0 .or. n == 0 ) then\n if ( r == 1 ) then\n pdf = 1.0D+00\n else\n pdf = 0.0D+00\n end if\n return\n end if\n!\n! Take care of extreme values of R.\n!\n if ( r < 2 .or. m + n < r ) then\n pdf = 0.0D+00\n return\n end if\n!\n! The normal cases.\n!\n if ( mod ( r, 2 ) == 0 ) then\n\n pdf = real ( 2 * combinatorial ( m - 1, ( r / 2 ) - 1 ) &\n * combinatorial ( n - 1, ( r / 2 ) - 1 ), kind = 8 ) &\n / real ( combinatorial ( m + n, n ), kind = 8 )\n\n else\n\n pdf = real ( combinatorial ( m - 1, ( r - 1 ) / 2 ) &\n * combinatorial ( n - 1, ( r - 3 ) / 2 ) &\n + combinatorial ( m - 1, ( r - 3 ) / 2 ) &\n * combinatorial ( n - 1, ( r - 1 ) / 2 ), kind = 8 ) &\n / real ( combinatorial ( m + n, n ), kind = 8 )\n\n end if\n\n return\nend\nsubroutine runs_sample ( m, n, seed, r )\n\n!*****************************************************************************80\n!\n!! RUNS_SAMPLE samples the Runs PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 23 January 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, N, the parameters of the PDF.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, integer ( kind = 4 ) R, the number of runs.\n!\n implicit none\n\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n\n integer ( kind = 4 ) a(m+n)\n integer ( kind = 4 ) r\n integer ( kind = 4 ) seed\n\n call runs_simulate ( m, n, seed, a )\n\n call i4vec_run_count ( m+n, a, r )\n\n return\nend\nsubroutine runs_simulate ( m, n, seed, a )\n\n!*****************************************************************************80\n!\n!! RUNS_SIMULATE simulates a case governed by the Runs PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 23 January 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, N, the parameters of the PDF.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, integer ( kind = 4 ) A(M+N), a sequence of M 0's and N 1's chosen\n! uniformly at random.\n!\n implicit none\n\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n\n integer ( kind = 4 ) a(m+n)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) i4_uniform_ab\n integer ( kind = 4 ) j\n integer ( kind = 4 ) k\n integer ( kind = 4 ) seed\n\n a(1:m) = 0\n a(m+1:m+n) = 1\n\n do i = 1, m + n - 1\n\n j = i4_uniform_ab ( i, m + n, seed )\n\n k = a(i)\n a(i) = a(j)\n a(j) = k\n\n end do\n\n return\nend\nsubroutine runs_variance ( m, n, variance )\n\n!*****************************************************************************80\n!\n!! RUNS_VARIANCE returns the variance of the Runs PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 23 January 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, N, the parameters of the PDF.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n real ( kind = 8 ) variance\n\n variance = real ( 2 * m * n * ( 2 * m * n - m - n ), kind = 8 ) &\n / real ( ( m + n ) * ( m + n ) * ( m + n - 1 ), kind = 8 )\n\n return\nend\nfunction sech ( x )\n\n!*****************************************************************************80\n!\n!! SECH returns the hyperbolic secant.\n!\n! Discussion:\n!\n! SECH ( X ) = 1.0D+00 / COSH ( X ) = 2.0D+00 / ( EXP ( X ) + EXP ( - X ) )\n!\n! SECH is not a built-in function in FORTRAN, and occasionally it\n! is handier, or more concise, to be able to refer to it directly\n! rather than through its definition in terms of the sine function.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument.\n!\n! Output, real ( kind = 8 ) SECH, the hyperbolic secant of X.\n!\n implicit none\n\n real ( kind = 8 ) sech\n real ( kind = 8 ) x\n\n sech = 1.0D+00 / cosh ( x )\n\n return\nend\nsubroutine sech_cdf ( x, a, b, cdf )\n\n!*****************************************************************************80\n!\n!! SECH_CDF evaluates the Hyperbolic Secant CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameter of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n\n y = ( x - a ) / b\n\n cdf = 2.0D+00 * atan ( exp ( y ) ) / pi\n\n return\nend\nsubroutine sech_cdf_inv ( cdf, a, b, x )\n\n!*****************************************************************************80\n!\n!! SECH_CDF_INV inverts the Hyperbolic Secant CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SECH_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n if ( cdf == 0.0D+00 ) then\n x = - huge ( x )\n else if ( cdf < 1.0D+00 ) then\n x = a + b * log ( tan ( 0.5D+00 * pi * cdf ) )\n else if ( 1.0D+00 == cdf ) then\n x = huge ( x )\n end if\n\n return\nend\nfunction sech_check ( a, b )\n\n!*****************************************************************************80\n!\n!! SECH_CHECK checks the parameters of the Hyperbolic Secant CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 22 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameter of the PDF.\n! 0.0D+00 < B.\n!\n! Output, logical SECH_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n logical sech_check\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SECH_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B <= 0.0'\n sech_check = .false.\n return\n end if\n\n sech_check = .true.\n\n return\nend\nsubroutine sech_mean ( a, b, mean )\n\n!*****************************************************************************80\n!\n!! SECH_MEAN returns the mean of the Hyperbolic Secant PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) mean\n\n mean = a\n\n return\nend\nsubroutine sech_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! SECH_PDF evaluates the Hypebolic Secant PDF.\n!\n! Discussion:\n!\n! PDF(A,B;X) = sech ( ( X - A ) / B ) / ( PI * B )\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) pdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) sech\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n\n y = ( x - a ) / b\n\n pdf = sech ( y ) / ( pi * b )\n\n return\nend\nsubroutine sech_sample ( a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! SECH_SAMPLE samples the Hyperbolic Secant PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n x = a + b * log ( tan ( 0.5D+00 * pi * cdf ) )\n\n return\nend\nsubroutine sech_variance ( a, b, variance )\n\n!*****************************************************************************80\n!\n!! SECH_VARIANCE returns the variance of the Hyperbolic Secant PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 January 2000\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) variance\n\n variance = 0.25D+00 * ( pi * b )**2\n\n return\nend\nsubroutine semicircular_cdf ( x, a, b, cdf )\n\n!*****************************************************************************80\n!\n!! SEMICIRCULAR_CDF evaluates the Semicircular CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameter of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n\n if ( x <= a - b ) then\n\n cdf = 0.0D+00\n\n else if ( x <= a + b ) then\n\n y = ( x - a ) / b\n\n cdf = 0.5D+00 + ( y * sqrt ( 1.0D+00 - y**2 ) + asin ( y ) ) / pi\n\n else if ( a + b < x ) then\n\n cdf = 1.0D+00\n\n end if\n\n return\nend\nsubroutine semicircular_cdf_inv ( cdf, a, b, x )\n\n!*****************************************************************************80\n!\n!! SEMICIRCULAR_CDF_INV inverts the Semicircular CDF.\n!\n! Discussion:\n!\n! A simple bisection method is used on the interval [ A - B, A + B ].\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) cdf1\n real ( kind = 8 ) cdf2\n real ( kind = 8 ) cdf3\n integer ( kind = 4 ) it\n integer ( kind = 4 ), parameter :: it_max = 100\n real ( kind = 8 ), parameter :: tol = 0.0001D+00\n real ( kind = 8 ) x\n real ( kind = 8 ) x1\n real ( kind = 8 ) x2\n real ( kind = 8 ) x3\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SEMICIRCULAR_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n if ( cdf == 0.0D+00 ) then\n x = a - b\n return\n else if ( 1.0D+00 == cdf ) then\n x = a + b\n return\n end if\n\n x1 = a - b\n cdf1 = 0.0D+00\n\n x2 = a + b\n cdf2 = 1.0D+00\n!\n! Now use bisection.\n!\n it = 0\n\n do\n\n it = it + 1\n\n x3 = 0.5D+00 * ( x1 + x2 )\n call semicircular_cdf ( x3, a, b, cdf3 )\n\n if ( abs ( cdf3 - cdf ) < tol ) then\n x = x3\n exit\n end if\n\n if ( it_max < it ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SEMICIRCULAR_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' Iteration limit exceeded.'\n stop 1\n end if\n\n if ( sign ( 1.0D+00, cdf3 - cdf ) == sign ( 1.0D+00, cdf1 - cdf ) ) then\n x1 = x3\n cdf1 = cdf3\n else\n x2 = x3\n cdf2 = cdf3\n end if\n\n end do\n\n return\nend\nfunction semicircular_check ( a, b )\n\n!*****************************************************************************80\n!\n!! SEMICIRCULAR_CHECK checks the parameters of the Semicircular CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 22 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameter of the PDF.\n! 0.0D+00 < B.\n!\n! Output, logical SEMICIRCULAR_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n logical semicircular_check\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SEMICIRCULAR_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B <= 0.0'\n semicircular_check = .false.\n return\n end if\n\n semicircular_check = .true.\n\n return\nend\nsubroutine semicircular_mean ( a, b, mean )\n\n!*****************************************************************************80\n!\n!! SEMICIRCULAR_MEAN returns the mean of the Semicircular PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) mean\n\n mean = a\n\n return\nend\nsubroutine semicircular_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! SEMICIRCULAR_PDF evaluates the Semicircular PDF.\n!\n! Discussion:\n!\n! PDF(A,B;X) = ( 2 / ( B * PI ) ) * SQRT ( 1 - ( ( X - A ) / B )^2 )\n! for A - B <= X <= A + B\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) pdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n\n if ( x < a - b ) then\n\n pdf = 0.0D+00\n\n else if ( x <= a + b ) then\n\n y = ( x - a ) / b\n\n pdf = 2.0D+00 / ( b * pi ) * sqrt ( 1.0D+00 - y**2 )\n\n else if ( a + b < x ) then\n\n pdf = 0.0D+00\n\n end if\n\n return\nend\nsubroutine semicircular_sample ( a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! SEMICIRCULAR_SAMPLE samples the Semicircular PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) angle\n real ( kind = 8 ) b\n real ( kind = 8 ) r8_uniform_01\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) radius\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n radius = r8_uniform_01 ( seed )\n radius = b * sqrt ( radius )\n angle = pi * r8_uniform_01 ( seed )\n x = a + radius * cos ( angle )\n\n return\nend\nsubroutine semicircular_variance ( a, b, variance )\n\n!*****************************************************************************80\n!\n!! SEMICIRCULAR_VARIANCE returns the variance of the Semicircular PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 30 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) variance\n\n variance = b * b / 4.0D+00\n\n return\nend\nfunction sin_power_int ( a, b, n )\n\n!*****************************************************************************80\n!\n!! SIN_POWER_INT evaluates the sine power integral.\n!\n! Discussion:\n!\n! The function is defined by\n!\n! SIN_POWER_INT(A,B,N) = Integral ( A <= T <= B ) ( sin ( t ))^n dt\n!\n! The algorithm uses the following fact:\n!\n! Integral sin^n ( t ) = (1/n) * (\n! sin^(n-1)(t) * cos(t) + ( n-1 ) * Integral sin^(n-2) ( t ) dt )\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters\n!\n! Input, real ( kind = 8 ) A, B, the limits of integration.\n!\n! Input, integer ( kind = 4 ) N, the power of the sine function.\n!\n! Output, real ( kind = 8 ) SIN_POWER_INT, the value of the integral.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) ca\n real ( kind = 8 ) cb\n integer ( kind = 4 ) m\n integer ( kind = 4 ) mlo\n integer ( kind = 4 ) n\n real ( kind = 8 ) sa\n real ( kind = 8 ) sb\n real ( kind = 8 ) sin_power_int\n real ( kind = 8 ) value\n\n if ( n < 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SIN_POWER_INT - Fatal error!'\n write ( *, '(a)' ) ' Power N < 0.'\n value = 0.0D+00\n stop 1\n end if\n\n sa = sin ( a )\n sb = sin ( b )\n ca = cos ( a )\n cb = cos ( b )\n\n if ( mod ( n, 2 ) == 0 ) then\n\n value = b - a\n mlo = 2\n else\n value = ca - cb\n mlo = 3\n end if\n\n do m = mlo, n, 2\n value = ( real ( m - 1, kind = 8 ) * value &\n + sa**(m-1) * ca - sb**(m-1) * cb ) &\n / real ( m, kind = 8 )\n end do\n\n sin_power_int = value\n\n return\nend\nfunction sphere_unit_area_nd ( dim_num )\n\n!*****************************************************************************80\n!\n!! SPHERE_UNIT_AREA_ND computes the surface area of a unit sphere in ND.\n!\n! Discussion:\n!\n! The unit sphere in ND satisfies:\n!\n! sum ( 1 <= I <= DIM_NUM ) X(I) * X(I) = 1\n!\n! Results for the first few values of N are:\n!\n! DIM_NUM Area\n!\n! 2 2 * PI\n! 3 4 * PI\n! 4 ( 2 / 1) * PI^2\n! 5 ( 8 / 3) * PI^2\n! 6 ( 1 / 1) * PI^3\n! 7 (16 / 15) * PI^3\n! 8 ( 1 / 3) * PI^4\n! 9 (32 / 105) * PI^4\n! 10 ( 1 / 12) * PI^5\n!\n! For the unit sphere, Area(DIM_NUM) = DIM_NUM * Volume(DIM_NUM)\n!\n! Sphere_Unit_Area ( DIM_NUM ) = 2 * PI**(DIM_NUM/2) / Gamma ( DIM_NUM / 2 )\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license. \n!\n! Modified:\n!\n! 05 September 2003\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) DIM_NUM, the dimension of the space.\n!\n! Output, real ( kind = 8 ) SPHERE_UNIT_AREA_ND, the area of the sphere.\n!\n implicit none\n\n real ( kind = 8 ) area\n integer ( kind = 4 ) dim_num\n integer ( kind = 4 ) i\n integer ( kind = 4 ) m\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) sphere_unit_area_nd\n\n if ( mod ( dim_num, 2 ) == 0 ) then\n m = dim_num / 2\n area = 2.0D+00 * ( pi )**m\n do i = 1, m - 1\n area = area / real ( i, kind = 8 )\n end do\n else\n m = ( dim_num - 1 ) / 2\n area = ( pi )**m * 2.0D+00**dim_num\n do i = m + 1, 2 * m\n area = area / real ( i, kind = 8 )\n end do\n end if\n\n sphere_unit_area_nd = area\n\n return\nend\nfunction stirling2_value ( n, m )\n\n!*****************************************************************************80\n!\n!! STIRLING2_VALUE computes a Stirling number of the second kind.\n!\n! Discussion:\n!\n! S2(N,M) represents the number of distinct partitions of N elements\n! into M nonempty sets. For a fixed N, the sum of the Stirling\n! numbers S2(N,M) is represented by B(N), called \"Bell's number\",\n! and represents the number of distinct partitions of N elements.\n!\n! For example, with 4 objects, there are:\n!\n! 1 partition into 1 set:\n!\n! (A,B,C,D)\n!\n! 7 partitions into 2 sets:\n!\n! (A,B,C) (D)\n! (A,B,D) (C)\n! (A,C,D) (B)\n! (A) (B,C,D)\n! (A,B) (C,D)\n! (A,C) (B,D)\n! (A,D) (B,C)\n!\n! 6 partitions into 3 sets:\n!\n! (A,B) (C) (D)\n! (A) (B,C) (D)\n! (A) (B) (C,D)\n! (A,C) (B) (D)\n! (A,D) (B) (C)\n! (A) (B,D) (C)\n!\n! 1 partition into 4 sets:\n!\n! (A) (B) (C) (D)\n!\n! So S2(4,1) = 1, S2(4,2) = 7, S2(4,3) = 6, S2(4,4) = 1, and B(4) = 15.\n!\n!\n! First terms:\n!\n! N/M: 1 2 3 4 5 6 7 8\n!\n! 1 1 0 0 0 0 0 0 0\n! 2 1 1 0 0 0 0 0 0\n! 3 1 3 1 0 0 0 0 0\n! 4 1 7 6 1 0 0 0 0\n! 5 1 15 25 10 1 0 0 0\n! 6 1 31 90 65 15 1 0 0\n! 7 1 63 301 350 140 21 1 0\n! 8 1 127 966 1701 1050 266 28 1\n!\n! Recursion:\n!\n! S2(N,1) = 1 for all N.\n! S2(I,I) = 1 for all I.\n! S2(I,J) = 0 if I < J.\n!\n! S2(N,M) = M * S2(N-1,M) + S2(N-1,M-1)\n!\n! Properties:\n!\n! sum ( 1 <= K <= M ) S2(I,K) * S1(K,J) = Delta(I,J)\n!\n! X^N = sum ( 0 <= K <= N ) S2(N,K) X_K\n! where X_K is the falling factorial function.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 25 August 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of rows of the table.\n!\n! Input, integer ( kind = 4 ) M, the number of columns of the table.\n!\n! Output, integer ( kind = 4 ) STIRLING2_VALUE, the value of S2(N,M).\n!\n implicit none\n\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n\n integer ( kind = 4 ) i\n integer ( kind = 4 ) j\n integer ( kind = 4 ) s2(n,m)\n integer ( kind = 4 ) stirling2_value\n\n if ( n <= 0 ) then\n stirling2_value = 0\n return\n end if\n\n if ( m <= 0 ) then\n stirling2_value = 0\n return\n end if\n\n s2(1,1) = 1\n s2(1,2:m) = 0\n\n do i = 2, n\n\n s2(i,1) = 1\n\n do j = 2, m\n s2(i,j) = j * s2(i-1,j) + s2(i-1,j-1)\n end do\n\n end do\n\n stirling2_value = s2(n,m)\n\n return\nend\nsubroutine student_cdf ( x, a, b, c, cdf )\n\n!*****************************************************************************80\n!\n!! STUDENT_CDF evaluates the central Student T CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 November 2005\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n!\n! Input, real ( kind = 8 ) A, B, shape parameters of the PDF,\n! used to transform the argument X to a shifted and scaled\n! value Y = ( X - A ) / B. It is required that B be nonzero.\n! For the standard distribution, A = 0 and B = 1.\n!\n! Input, real ( kind = 8 ) C, is usually called the number of\n! degrees of freedom of the distribution. C is typically an\n! integer, but that is not essential. It is required that\n! C be strictly positive.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) a2\n real ( kind = 8 ) b\n real ( kind = 8 ) b2\n real ( kind = 8 ) beta_inc\n real ( kind = 8 ) c\n real ( kind = 8 ) c2\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n\n y = ( x - a ) / b\n\n a2 = 0.5D+00 * c\n b2 = 0.5D+00\n c2 = c / ( c + y * y )\n\n if ( y <= 0.0D+00 ) then\n cdf = 0.5D+00 * beta_inc ( a2, b2, c2 )\n else\n cdf = 1.0D+00 - 0.5D+00 * beta_inc ( a2, b2, c2 )\n end if\n\n return\nend\nsubroutine student_cdf_values ( n_data, c, x, fx )\n\n!*****************************************************************************80\n!\n!! STUDENT_CDF_VALUES returns some values of the Student CDF.\n!\n! Discussion:\n!\n! In Mathematica, the function can be evaluated by:\n!\n! Needs[\"Statistics`ContinuousDistributions`\"]\n! dist = StudentTDistribution [ c ]\n! CDF [ dist, x ]\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 November 2005\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Milton Abramowitz, Irene Stegun,\n! Handbook of Mathematical Functions,\n! National Bureau of Standards, 1964,\n! LC: QA47.A34,\n! ISBN: 0-486-61272-4.\n!\n! Stephen Wolfram,\n! The Mathematica Book,\n! Fourth Edition,\n! Wolfram Media / Cambridge University Press, 1999.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) N_DATA. The user sets N_DATA to 0\n! before the first call. On each call, the routine increments N_DATA by 1,\n! and returns the corresponding data; when there is no more data, the\n! output value of N_DATA will be 0 again.\n!\n! Output, real ( kind = 8 ) C, is usually called the number of\n! degrees of freedom of the distribution. C is typically an\n! integer, but that is not essential. It is required that\n! C be strictly positive.\n!\n! Output, real ( kind = 8 ) X, the argument of the function.\n!\n! Output, real ( kind = 8 ) FX, the value of the function.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: n_max = 13\n\n real ( kind = 8 ) c\n real ( kind = 8 ), save, dimension ( n_max ) :: c_vec = (/ &\n 1.0D+00, 2.0D+00, 3.0D+00, 4.0D+00, &\n 5.0D+00, 2.0D+00, 5.0D+00, 2.0D+00, &\n 5.0D+00, 2.0D+00, 3.0D+00, 4.0D+00, &\n 5.0D+00 /)\n real ( kind = 8 ) fx\n real ( kind = 8 ), save, dimension ( n_max ) :: fx_vec = (/ &\n 0.6000231200328521D+00, &\n 0.6001080279134390D+00, &\n 0.6001150934648930D+00, &\n 0.6000995134721354D+00, &\n 0.5999341989834830D+00, &\n 0.7498859393137811D+00, &\n 0.7500879487671045D+00, &\n 0.9500004222186464D+00, &\n 0.9499969138365968D+00, &\n 0.9900012348724744D+00, &\n 0.9900017619355059D+00, &\n 0.9900004567580596D+00, &\n 0.9900007637471291D+00 /)\n integer ( kind = 4 ) n_data\n real ( kind = 8 ) x\n real ( kind = 8 ), save, dimension ( n_max ) :: x_vec = (/ &\n 0.325D+00, &\n 0.289D+00, &\n 0.277D+00, &\n 0.271D+00, &\n 0.267D+00, &\n 0.816D+00, &\n 0.727D+00, &\n 2.920D+00, &\n 2.015D+00, &\n 6.965D+00, &\n 4.541D+00, &\n 3.747D+00, &\n 3.365D+00 /)\n\n if ( n_data < 0 ) then\n n_data = 0\n end if\n\n n_data = n_data + 1\n\n if ( n_max < n_data ) then\n n_data = 0\n c = 0.0D+00\n x = 0.0D+00\n fx = 0.0D+00\n else\n c = c_vec(n_data)\n x = x_vec(n_data)\n fx = fx_vec(n_data)\n end if\n\n return\nend\nfunction student_check ( a, b, c )\n\n!*****************************************************************************80\n!\n!! STUDENT_CHECK checks the parameter of the central Student T CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 November 2005\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, shape parameters of the PDF,\n! used to transform the argument X to a shifted and scaled\n! value Y = ( X - A ) / B. It is required that B be nonzero.\n! For the standard distribution, A = 0 and B = 1.\n!\n! Input, real ( kind = 8 ) C, is usually called the number of\n! degrees of freedom of the distribution. C is typically an\n! integer, but that is not essential. It is required that\n! C be strictly positive.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n logical student_check\n\n if ( b == 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'STUDENT_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B must be nonzero.'\n student_check = .false.\n return\n end if\n\n if ( c <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'STUDENT_CHECK - Fatal error!'\n write ( *, '(a)' ) ' C must be greater than 0.'\n student_check = .false.\n return\n end if\n\n student_check = .true.\n\n return\nend\nsubroutine student_mean ( a, b, c, mean )\n\n!*****************************************************************************80\n!\n!! STUDENT_MEAN returns the mean of the central Student T PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 November 2005\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Input, real ( kind = 8 ) A, B, shape parameters of the PDF,\n! used to transform the argument X to a shifted and scaled\n! value Y = ( X - A ) / B. It is required that B be nonzero.\n! For the standard distribution, A = 0 and B = 1.\n!\n! Input, real ( kind = 8 ) C, is usually called the number of\n! degrees of freedom of the distribution. C is typically an\n! integer, but that is not essential. It is required that\n! C be strictly positive.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) mean\n\n mean = a\n\n return\nend\nsubroutine student_pdf ( x, a, b, c, pdf )\n\n!*****************************************************************************80\n!\n!! STUDENT_PDF evaluates the central Student T PDF.\n!\n! Discussion:\n!\n! PDF(A,B,C;X) = Gamma ( (C+1)/2 ) /\n! ( Gamma ( C / 2 ) * Sqrt ( PI * C )\n! * ( 1 + ((X-A)/B)^2/C )^(C + 1/2 ) )\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 November 2005\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Input, real ( kind = 8 ) A, B, shape parameters of the PDF,\n! used to transform the argument X to a shifted and scaled\n! value Y = ( X - A ) / B. It is required that B be nonzero.\n! For the standard distribution, A = 0 and B = 1.\n!\n! Input, real ( kind = 8 ) C, is usually called the number of\n! degrees of freedom of the distribution. C is typically an\n! integer, but that is not essential. It is required that\n! C be strictly positive.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) pdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) r8_gamma\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n\n y = ( x - a ) / b\n\n pdf = r8_gamma ( 0.5D+00 * ( c + 1.0D+00 ) ) / ( sqrt ( pi * c ) &\n * r8_gamma ( 0.5D+00 * c ) &\n * sqrt ( ( 1.0D+00 + y * y / c )**( 2 * c + 1.0D+00 ) ) )\n\n return\nend\nsubroutine student_sample ( a, b, c, seed, x )\n\n!*****************************************************************************80\n!\n!! STUDENT_SAMPLE samples the central Student T PDF.\n!\n! Discussion:\n!\n! For the sampling algorithm, it is necessary that 2 < C.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 November 2005\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, shape parameters of the PDF,\n! used to transform the argument X to a shifted and scaled\n! value Y = ( X - A ) / B. It is required that B be nonzero.\n! For the standard distribution, A = 0 and B = 1.\n!\n! Input, real ( kind = 8 ) C, is usually called the number of\n! degrees of freedom of the distribution. C is typically an\n! integer, but that is not essential. It is required that\n! C be strictly positive.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) a2\n real ( kind = 8 ) b\n real ( kind = 8 ) b2\n real ( kind = 8 ) c\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n real ( kind = 8 ) x2\n real ( kind = 8 ) x3\n\n if ( c < 3.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'STUDENT_SAMPLE - Fatal error!'\n write ( *, '(a)' ) ' Sampling fails for C <= 2.'\n return\n end if\n\n a2 = 0.0D+00\n b2 = c / ( c - 2 )\n\n call normal_sample ( a2, b2, seed, x2 )\n\n call chi_square_sample ( c, seed, x3 )\n x3 = x3 * c / ( c - 2.0D+00 )\n\n x = a + b * x2 * sqrt ( c ) / x3\n\n return\nend\nsubroutine student_variance ( a, b, c, variance )\n\n!*****************************************************************************80\n!\n!! STUDENT_VARIANCE returns the variance of the central Student T PDF.\n!\n! Discussion:\n!\n! The variance is not defined unless 2 < C.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 November 2005\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, shape parameters of the PDF,\n! used to transform the argument X to a shifted and scaled\n! value Y = ( X - A ) / B. It is required that B be nonzero.\n! For the standard distribution, A = 0 and B = 1.\n!\n! Input, real ( kind = 8 ) C, is usually called the number of\n! degrees of freedom of the distribution. C is typically an\n! integer, but that is not essential. It is required that\n! C be strictly positive.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) variance\n\n if ( c <= 2.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'STUDENT_VARIANCE - Fatal error!'\n write ( *, '(a)' ) ' Variance not defined for C <= 2.'\n stop 1\n end if\n\n variance = b * b * c / ( c - 2.0D+00 )\n\n return\nend\nsubroutine student_noncentral_cdf ( x, idf, d, cdf )\n\n!*****************************************************************************80\n!\n!! STUDENT_NONCENTRAL_CDF evaluates the noncentral Student T CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 07 March 1999\n!\n! Author:\n!\n! Original FORTRAN77 version by B E Cooper.\n! FORTRAN90 version by John Burkardt\n!\n! Reference:\n!\n! BE Cooper,\n! Algorithm AS 5:\n! The Integral of the Non-Central T-Distribution,\n! Applied Statistics,\n! Volume 17, 1968, page 193.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n!\n! Input, integer ( kind = 4 ) IDF, the number of degrees of freedom.\n!\n! Input, real ( kind = 8 ) D, the noncentrality parameter.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n integer ( kind = 4 ), parameter :: a_max = 100\n real ( kind = 8 ) ak\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) cdf2\n real ( kind = 8 ) d\n real ( kind = 8 ) drb\n real ( kind = 8 ), parameter :: emin = 12.5D+00\n real ( kind = 8 ) f\n real ( kind = 8 ) fk\n real ( kind = 8 ) fmkm1\n real ( kind = 8 ) fmkm2\n real ( kind = 8 ) gamma_log\n integer ( kind = 4 ) idf\n integer ( kind = 4 ) k\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) sum2\n real ( kind = 8 ) temp\n real ( kind = 8 ) tfn\n real ( kind = 8 ) x\n\n f = real ( idf, kind = 8 )\n\n if ( idf == 1 ) then\n\n a = x / sqrt ( f )\n b = f / ( f + x**2 )\n drb = d * sqrt ( b )\n\n call normal_01_cdf ( drb, cdf2 )\n cdf = 1.0D+00 - cdf2 + 2.0D+00 * tfn ( drb, a )\n\n else if ( idf <= a_max ) then\n\n a = x / sqrt ( f )\n b = f / ( f + x * x )\n drb = d * sqrt ( b )\n sum2 = 0.0D+00\n\n fmkm2 = 0.0D+00\n if ( abs ( drb ) < emin ) then\n call normal_01_cdf ( a * drb, cdf2 )\n fmkm2 = a * sqrt ( b ) * exp ( - 0.5D+00 * drb**2 ) * cdf2 &\n / sqrt ( 2.0D+00 * pi )\n end if\n\n fmkm1 = b * d * a * fmkm2\n if ( abs ( d ) < emin ) then\n fmkm1 = fmkm1 + 0.5D+00 * b * a * exp ( - 0.5D+00 * d**2 ) / pi\n end if\n\n if ( mod ( idf, 2 ) == 0 ) then\n sum2 = fmkm2\n else\n sum2 = fmkm1\n end if\n\n ak = 1.0D+00\n\n do k = 2, idf - 2, 2\n\n fk = real ( k, kind = 8 )\n\n fmkm2 = b * ( d * a * ak * fmkm1 + fmkm2 ) * ( fk - 1.0D+00 ) / fk\n\n ak = 1.0D+00 / ( ak * ( fk - 1.0D+00 ) )\n fmkm1 = b * ( d * a * ak * fmkm2 + fmkm1 ) * fk / ( fk + 1.0D+00 )\n\n if ( mod ( idf, 2 ) == 0 ) then\n sum2 = sum2 + fmkm2\n else\n sum2 = sum2 + fmkm1\n end if\n\n ak = 1.0D+00 / ( ak * fk )\n\n end do\n\n if ( mod ( idf, 2 ) == 0 ) then\n call normal_01_cdf ( d, cdf2 )\n cdf = 1.0D+00 - cdf2 + sum2 * sqrt ( 2.0D+00 * pi )\n else\n call normal_01_cdf ( drb, cdf2 )\n cdf = 1.0D+00 - cdf2 + 2.0D+00 * ( sum2 + tfn ( drb, a ) )\n end if\n!\n! Normal approximation.\n!\n else\n\n a = sqrt ( 0.5D+00 * f ) * exp ( gamma_log ( 0.5D+00 * ( f - 1.0D+00 ) ) &\n - gamma_log ( 0.5D+00 * f ) ) * d\n\n temp = ( x - a ) / sqrt ( f * ( 1.0D+00 + d**2 ) / ( f - 2.0D+00 ) - a**2 )\n\n call normal_01_cdf ( temp, cdf2 )\n cdf = cdf2\n\n end if\n\n return\nend\nsubroutine student_noncentral_cdf_values ( n_data, df, lambda, x, fx )\n\n!*****************************************************************************80\n!\n!! STUDENT_NONCENTRAL_CDF_VALUES returns values of the noncentral Student CDF.\n!\n! Discussion:\n!\n! In Mathematica, the function can be evaluated by:\n!\n! Needs[\"Statistics`ContinuousDistributions`\"]\n! dist = NoncentralStudentTDistribution [ df, lambda ]\n! CDF [ dist, x ]\n!\n! Mathematica seems to have some difficulty computing this function\n! to the desired number of digits.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Milton Abramowitz, Irene Stegun,\n! Handbook of Mathematical Functions,\n! National Bureau of Standards, 1964,\n! LC: QA47.A34,\n! ISBN: 0-486-61272-4.\n!\n! Stephen Wolfram,\n! The Mathematica Book,\n! Fourth Edition,\n! Wolfram Media / Cambridge University Press, 1999.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) N_DATA. The user sets N_DATA to 0\n! before the first call. On each call, the routine increments N_DATA by 1,\n! and returns the corresponding data; when there is no more data, the\n! output value of N_DATA will be 0 again.\n!\n! Output, integer ( kind = 4 ) DF, real ( kind = 8 ) LAMBDA, the parameters\n! of the function.\n!\n! Output, real ( kind = 8 ) X, the argument of the function.\n!\n! Output, real ( kind = 8 ) FX, the value of the function.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: n_max = 30\n\n integer ( kind = 4 ) df\n integer ( kind = 4 ), save, dimension ( n_max ) :: df_vec = (/ &\n 1, 2, 3, &\n 1, 2, 3, &\n 1, 2, 3, &\n 1, 2, 3, &\n 1, 2, 3, &\n 15, 20, 25, &\n 1, 2, 3, &\n 10, 10, 10, &\n 10, 10, 10, &\n 10, 10, 10 /)\n real ( kind = 8 ) fx\n real ( kind = 8 ), save, dimension ( n_max ) :: fx_vec = (/ &\n 0.8975836176504333D+00, &\n 0.9522670169D+00, &\n 0.9711655571887813D+00, &\n 0.8231218864D+00, &\n 0.9049021510D+00, &\n 0.9363471834D+00, &\n 0.7301025986D+00, &\n 0.8335594263D+00, &\n 0.8774010255D+00, &\n 0.5248571617D+00, &\n 0.6293856597D+00, &\n 0.6800271741D+00, &\n 0.20590131975D+00, &\n 0.2112148916D+00, &\n 0.2074730718D+00, &\n 0.9981130072D+00, &\n 0.9994873850D+00, &\n 0.9998391562D+00, &\n 0.168610566972D+00, &\n 0.16967950985D+00, &\n 0.1701041003D+00, &\n 0.9247683363D+00, &\n 0.7483139269D+00, &\n 0.4659802096D+00, &\n 0.9761872541D+00, &\n 0.8979689357D+00, &\n 0.7181904627D+00, &\n 0.9923658945D+00, &\n 0.9610341649D+00, &\n 0.8688007350D+00 /)\n real ( kind = 8 ) lambda\n real ( kind = 8 ), save, dimension ( n_max ) :: lambda_vec = (/ &\n 0.0D+00, &\n 0.0D+00, &\n 0.0D+00, &\n 0.5D+00, &\n 0.5D+00, &\n 0.5D+00, &\n 1.0D+00, &\n 1.0D+00, &\n 1.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 2.0D+00, &\n 4.0D+00, &\n 4.0D+00, &\n 4.0D+00, &\n 7.0D+00, &\n 7.0D+00, &\n 7.0D+00, &\n 1.0D+00, &\n 1.0D+00, &\n 1.0D+00, &\n 2.0D+00, &\n 3.0D+00, &\n 4.0D+00, &\n 2.0D+00, &\n 3.0D+00, &\n 4.0D+00, &\n 2.0D+00, &\n 3.0D+00, &\n 4.0D+00 /)\n integer ( kind = 4 ) n_data\n real ( kind = 8 ) x\n real ( kind = 8 ), save, dimension ( n_max ) :: x_vec = (/ &\n 3.00D+00, &\n 3.00D+00, &\n 3.00D+00, &\n 3.00D+00, &\n 3.00D+00, &\n 3.00D+00, &\n 3.00D+00, &\n 3.00D+00, &\n 3.00D+00, &\n 3.00D+00, &\n 3.00D+00, &\n 3.00D+00, &\n 3.00D+00, &\n 3.00D+00, &\n 3.00D+00, &\n 15.00D+00, &\n 15.00D+00, &\n 15.00D+00, &\n 0.05D+00, &\n 0.05D+00, &\n 0.05D+00, &\n 4.00D+00, &\n 4.00D+00, &\n 4.00D+00, &\n 5.00D+00, &\n 5.00D+00, &\n 5.00D+00, &\n 6.00D+00, &\n 6.00D+00, &\n 6.00D+00 /)\n\n if ( n_data < 0 ) then\n n_data = 0\n end if\n\n n_data = n_data + 1\n\n if ( n_max < n_data ) then\n n_data = 0\n df = 0\n lambda = 0.0D+00\n x = 0.0D+00\n fx = 0.0D+00\n else\n df = df_vec(n_data)\n lambda = lambda_vec(n_data)\n x = x_vec(n_data)\n fx = fx_vec(n_data)\n end if\n\n return\nend\nfunction tfn ( h, a )\n\n!*****************************************************************************80\n!\n!! TFN calculates the T function of Owen.\n!\n! Discussion:\n!\n! Owen's T function is useful for computation of the bivariate normal\n! distribution and the distribution of a skewed normal distribution.\n!\n! Although it was originally formulated in terms of the bivariate\n! normal function, the function can be defined more directly as\n!\n! T(H,A) = 1 / ( 2 * pi ) *\n! Integral ( 0 <= X <= A ) e^( -H^2 * (1+X^2) / 2 ) / (1+X^2) dX\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 10 December 2004\n!\n! Author:\n!\n! Original FORTRAN77 version by J C Young, C E Minder.\n! FORTRAN90 version by John Burkardt\n!\n! Reference:\n!\n! Donald Owen,\n! Tables for computing the bivariate normal distribution,\n! Annals of Mathematical Statistics,\n! Volume 27, pages 1075-1090, 1956.\n!\n! JC Young, CE Minder,\n! Algorithm AS 76,\n! An Algorithm Useful in Calculating Non-Central T and\n! Bivariate Normal Distributions,\n! Applied Statistics,\n! Volume 23, Number 3, 1974, pages 455-457.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) H, A, the arguments of the T function.\n!\n! Output, real ( kind = 8 ) TFN, the value of the T function.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: ngauss = 10\n\n real ( kind = 8 ) a\n real ( kind = 8 ) as\n real ( kind = 8 ) h\n real ( kind = 8 ) h1\n real ( kind = 8 ) h2\n real ( kind = 8 ) hs\n integer ( kind = 4 ) i\n real ( kind = 8 ) rt\n real ( kind = 8 ) tfn\n real ( kind = 8 ), parameter :: two_pi_inverse = 0.1591549430918953D+00\n real ( kind = 8 ), parameter :: tv1 = 1.0D-35\n real ( kind = 8 ), parameter :: tv2 = 15.0D+00\n real ( kind = 8 ), parameter :: tv3 = 15.0D+00\n real ( kind = 8 ), parameter :: tv4 = 1.0D-05\n real ( kind = 8 ), parameter, dimension ( ngauss ) :: weight = (/ &\n 0.666713443086881375935688098933D-01, &\n 0.149451349150580593145776339658D+00, &\n 0.219086362515982043995534934228D+00, &\n 0.269266719309996355091226921569D+00, &\n 0.295524224714752870173892994651D+00, &\n 0.295524224714752870173892994651D+00, &\n 0.269266719309996355091226921569D+00, &\n 0.219086362515982043995534934228D+00, &\n 0.149451349150580593145776339658D+00, &\n 0.666713443086881375935688098933D-01 /)\n real ( kind = 8 ) x\n real ( kind = 8 ), parameter, dimension ( ngauss ) :: xtab = (/ &\n -0.973906528517171720077964012084D+00, &\n -0.865063366688984510732096688423D+00, &\n -0.679409568299024406234327365115D+00, &\n -0.433395394129247190799265943166D+00, &\n -0.148874338981631210884826001130D+00, &\n 0.148874338981631210884826001130D+00, &\n 0.433395394129247190799265943166D+00, &\n 0.679409568299024406234327365115D+00, &\n 0.865063366688984510732096688423D+00, &\n 0.973906528517171720077964012084D+00 /)\n!\n! Test for H near zero.\n!\n if ( abs ( h ) < tv1 ) then\n tfn = atan ( a ) * two_pi_inverse\n!\n! Test for large values of abs(H).\n!\n else if ( tv2 < abs ( h ) ) then\n tfn = 0.0D+00\n!\n! Test for A near zero.\n!\n else if ( abs ( a ) < tv1 ) then\n tfn = 0.0D+00\n!\n! Test whether abs(A) is so large that it must be truncated.\n! If so, the truncated value of A is H2.\n!\n else\n\n hs = - 0.5D+00 * h * h\n h2 = a\n as = a * a\n!\n! Computation of truncation point by Newton iteration.\n!\n if ( tv3 <= log ( 1.0D+00 + as ) - hs * as ) then\n\n h1 = 0.5D+00 * a\n as = 0.25D+00 * as\n\n do\n\n rt = as + 1.0D+00\n h2 = h1 + ( hs * as + tv3 - log ( rt ) ) &\n / ( 2.0D+00 * h1 * ( 1.0D+00 / rt - hs ) )\n as = h2 * h2\n\n if ( abs ( h2 - h1 ) < tv4 ) then\n exit\n end if\n\n h1 = h2\n\n end do\n\n end if\n!\n! Gaussian quadrature on the interval [0,H2].\n!\n rt = 0.0D+00\n do i = 1, ngauss\n x = 0.5D+00 * h2 * ( xtab(i) + 1.0D+00 )\n rt = rt + weight(i) * exp ( hs * ( 1.0D+00 + x * x ) ) &\n / ( 1.0D+00 + x * x )\n end do\n\n tfn = rt * ( 0.5D+00 * h2 ) * two_pi_inverse\n\n end if\n\n return\nend\nsubroutine timestamp ( )\n\n!*****************************************************************************80\n!\n!! TIMESTAMP prints the current YMDHMS date as a time stamp.\n!\n! Example:\n!\n! 31 May 2001 9:45:54.872 AM\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 18 May 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! None\n!\n implicit none\n\n character ( len = 8 ) ampm\n integer ( kind = 4 ) d\n integer ( kind = 4 ) h\n integer ( kind = 4 ) m\n integer ( kind = 4 ) mm\n character ( len = 9 ), parameter, dimension(12) :: month = (/ &\n 'January ', 'February ', 'March ', 'April ', &\n 'May ', 'June ', 'July ', 'August ', &\n 'September', 'October ', 'November ', 'December ' /)\n integer ( kind = 4 ) n\n integer ( kind = 4 ) s\n integer ( kind = 4 ) values(8)\n integer ( kind = 4 ) y\n\n call date_and_time ( values = values )\n\n y = values(1)\n m = values(2)\n d = values(3)\n h = values(5)\n n = values(6)\n s = values(7)\n mm = values(8)\n\n if ( h < 12 ) then\n ampm = 'AM'\n else if ( h == 12 ) then\n if ( n == 0 .and. s == 0 ) then\n ampm = 'Noon'\n else\n ampm = 'PM'\n end if\n else\n h = h - 12\n if ( h < 12 ) then\n ampm = 'PM'\n else if ( h == 12 ) then\n if ( n == 0 .and. s == 0 ) then\n ampm = 'Midnight'\n else\n ampm = 'AM'\n end if\n end if\n end if\n\n write ( *, '(i2,1x,a,1x,i4,2x,i2,a1,i2.2,a1,i2.2,a1,i3.3,1x,a)' ) &\n d, trim ( month(m) ), y, h, ':', n, ':', s, '.', mm, trim ( ampm )\n\n return\nend\nsubroutine triangle_cdf ( x, a, b, c, cdf )\n\n!*****************************************************************************80\n!\n!! TRIANGLE_CDF evaluates the Triangle CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 18 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! A <= B <= C and A < C.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( x <= a ) then\n\n cdf = 0.0D+00\n\n else if ( x <= b ) then\n\n if ( a == b ) then\n cdf = 0.0D+00\n else\n cdf = ( x - a ) * ( x - a ) / ( b - a ) / ( c - a )\n end if\n\n else if ( x <= c ) then\n\n cdf = ( b - a ) / ( c - a ) &\n + ( 2.0D+00 * c - b - x ) * ( x - b ) / ( c - b ) / ( c - a )\n\n else\n\n cdf = 1.0D+00\n\n end if\n\n return\nend\nsubroutine triangle_cdf_inv ( cdf, a, b, c, x )\n\n!*****************************************************************************80\n!\n!! TRIANGLE_CDF_INV inverts the Triangle CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 17 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! A <= B <= C and A < C.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) cdf\n real ( kind = 8 ) cdf_mid\n real ( kind = 8 ) d\n real ( kind = 8 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TRIANGLE_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n d = 2.0D+00 / ( c - a )\n cdf_mid = 0.5D+00 * d * ( b - a )\n\n if ( cdf <= cdf_mid ) then\n x = a + sqrt ( cdf * ( b - a ) * ( c - a ) )\n else\n x = c - sqrt ( ( c - b ) * ( ( c - b ) - ( cdf - cdf_mid ) * ( c - a ) ) )\n end if\n\n return\nend\nfunction triangle_check ( a, b, c )\n\n!*****************************************************************************80\n!\n!! TRIANGLE_CHECK checks the parameters of the Triangle CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 17 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! A <= B <= C and A < C.\n!\n! Output, logical TRIANGLE_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n logical triangle_check\n\n if ( b < a ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TRIANGLE_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B < A.'\n triangle_check = .false.\n return\n end if\n\n if ( c < b ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TRIANGLE_CHECK - Fatal error!'\n write ( *, '(a)' ) ' C < B.'\n triangle_check = .false.\n return\n end if\n\n if ( a == c ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TRIANGLE_CHECK - Fatal error!'\n write ( *, '(a)' ) ' A == C.'\n triangle_check = .false.\n return\n end if\n\n triangle_check = .true.\n\n return\nend\nsubroutine triangle_mean ( a, b, c, mean )\n\n!*****************************************************************************80\n!\n!! TRIANGLE_MEAN returns the mean of the Triangle PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 18 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! A <= B <= C and A < C.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the discrete uniform PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) mean\n\n mean = a + ( c + b - 2.0D+00 * a ) / 3.0D+00\n\n return\nend\nsubroutine triangle_pdf ( x, a, b, c, pdf )\n\n!*****************************************************************************80\n!\n!! TRIANGLE_PDF evaluates the Triangle PDF.\n!\n! Discussion:\n!\n! Given points A <= B <= C, the probability is 0 to the left of A,\n! rises linearly to a maximum of 2/(C-A) at B, drops linearly to zero\n! at C, and is zero for all values greater than C.\n!\n! PDF(A,B,C;X)\n! = 2 * ( X - A ) / ( B - A ) / ( C - A ) for A <= X <= B\n! = 2 * ( C - X ) / ( C - B ) / ( C - A ) for B <= X <= C.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 18 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! A <= B <= C and A < C.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) pdf\n real ( kind = 8 ) x\n\n if ( x <= a ) then\n\n pdf = 0.0D+00\n\n else if ( x <= b ) then\n\n if ( a == b ) then\n pdf = 0.0D+00\n else\n pdf = 2.0D+00 * ( x - a ) / ( b - a ) / ( c - a )\n end if\n\n else if ( x <= c ) then\n\n if ( b == c ) then\n pdf = 0.0D+00\n else\n pdf = 2.0D+00 * ( c - x ) / ( c - b ) / ( c - a )\n end if\n\n else\n pdf = 0.0D+00\n end if\n\n return\nend\nsubroutine triangle_sample ( a, b, c, seed, x )\n\n!*****************************************************************************80\n!\n!! TRIANGLE_SAMPLE samples the Triangle PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 17 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! A <= B <= C and A < C.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call triangle_cdf_inv ( cdf, a, b, c, x )\n\n return\nend\nsubroutine triangle_variance ( a, b, c, variance )\n\n!*****************************************************************************80\n!\n!! TRIANGLE_VARIANCE returns the variance of the Triangle PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 18 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! A <= B <= C and A < C.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) variance\n\n variance = ( ( c - a ) * ( c - a ) &\n - ( c - a ) * ( b - a ) &\n + ( b - a ) * ( b - a ) ) / 18.0D+00\n\n return\nend\nsubroutine triangular_cdf ( x, a, b, cdf )\n\n!*****************************************************************************80\n!\n!! TRIANGULAR_CDF evaluates the Triangular CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! A < B.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( x <= a ) then\n cdf = 0.0D+00\n else if ( x <= 0.5D+00 * ( a + b ) ) then\n cdf = 2.0D+00 * ( x**2 - 2.0D+00 * a * x + a**2 ) / ( b - a )**2\n else if ( x <= b ) then\n cdf = 0.5D+00 + ( - 2.0D+00 * x**2 + 4.0D+00 * b * x + 0.5D+00 * a**2 &\n - a * b - 1.5D+00 * b**2 ) / ( b - a )**2\n else\n cdf = 1.0D+00\n end if\n\n return\nend\nsubroutine triangular_cdf_inv ( cdf, a, b, x )\n\n!*****************************************************************************80\n!\n!! TRIANGULAR_CDF_INV inverts the Triangular CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! A < B.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TRIANGULAR_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n if ( cdf <= 0.5D+00 ) then\n x = a + 0.5D+00 * ( b - a ) * sqrt ( 2.0D+00 * cdf )\n else\n x = b - 0.5D+00 * ( b - a ) * sqrt ( 2.0D+00 * ( 1.0D+00 - cdf ) )\n end if\n\n return\nend\nfunction triangular_check ( a, b )\n\n!*****************************************************************************80\n!\n!! TRIANGULAR_CHECK checks the parameters of the Triangular CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 18 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! A < B.\n!\n! Output, logical TRIANGULAR_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n logical triangular_check\n\n if ( b <= a ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TRIANGULAR_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B <= A.'\n triangular_check = .false.\n return\n end if\n\n triangular_check = .true.\n\n return\nend\nsubroutine triangular_mean ( a, b, mean )\n\n!*****************************************************************************80\n!\n!! TRIANGULAR_MEAN returns the mean of the Triangular PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! A < B.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) mean\n\n mean = 0.5D+00 * ( a + b )\n\n return\nend\nsubroutine triangular_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! TRIANGULAR_PDF evaluates the Triangular PDF.\n!\n! Discussion:\n!\n! PDF(A,B;X) = 4 * ( X - A ) / ( B - A )^2 for A <= X <= (A+B)/2\n! = 4 * ( B - X ) / ( B - A )^2 for (A+B)/2 <= X <= B.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! A < B.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) pdf\n real ( kind = 8 ) x\n\n if ( x <= a ) then\n pdf = 0.0D+00\n else if ( x <= 0.5D+00 * ( a + b ) ) then\n pdf = 4.0D+00 * ( x - a ) / ( b - a )**2\n else if ( x <= b ) then\n pdf = 4.0D+00 * ( b - x ) / ( b - a )**2\n else\n pdf = 0.0D+00\n end if\n\n return\nend\nsubroutine triangular_sample ( a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! TRIANGULAR_SAMPLE samples the Triangular PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! A < B.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call triangular_cdf_inv ( cdf, a, b, x )\n\n return\nend\nsubroutine triangular_variance ( a, b, variance )\n\n!*****************************************************************************80\n!\n!! TRIANGULAR_VARIANCE returns the variance of the Triangular PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! A < B.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) variance\n\n variance = ( b - a )**2 / 24.0D+00\n\n return\nend\nfunction trigamma ( x )\n\n!*****************************************************************************80\n!\n!! TRIGAMMA calculates the TriGamma function.\n!\n! Discussion:\n!\n! TriGamma(x) = d^2 log ( Gamma ( x ) ) / dx^2.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 03 January 2000\n!\n! Author:\n!\n! FORTRAN77 original version by B Schneider\n! FORTRAN90 version by John Burkardt\n!\n! Reference:\n!\n! BE Schneider,\n! Algorithm AS 121:\n! Trigamma Function,\n! Applied Statistics,\n! Volume 27, Number 1, page 97-99, 1978.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the trigamma function.\n! 0 < X.\n!\n! Output, real ( kind = 8 ) TRIGAMMA, the value of the\n! trigamma function at X.\n!\n implicit none\n\n real ( kind = 8 ), parameter :: a = 0.0001D+00\n real ( kind = 8 ), parameter :: b = 5.0D+00\n real ( kind = 8 ), parameter :: b2 = 1.0D+00 / 6.0D+00\n real ( kind = 8 ), parameter :: b4 = - 1.0D+00 / 30.0D+00\n real ( kind = 8 ), parameter :: b6 = 1.0D+00 / 42.0D+00\n real ( kind = 8 ), parameter :: b8 = - 1.0D+00 / 30.0D+00\n real ( kind = 8 ) trigamma\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n real ( kind = 8 ) z\n!\n! 1): If X is not positive, fail.\n!\n if ( x <= 0.0D+00 ) then\n\n trigamma = 0.0D+00\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TRIGAMMA - Fatal error!'\n write ( *, '(a)' ) ' X <= 0.'\n stop 1\n!\n! 2): If X is smaller than A, use a small value approximation.\n!\n else if ( x <= a ) then\n\n trigamma = 1.0D+00 / x**2\n!\n! 3): Otherwise, increase the argument to B <= ( X + I ).\n!\n else\n\n z = x\n trigamma = 0.0D+00\n\n do while ( z < b )\n trigamma = trigamma + 1.0D+00 / z**2\n z = z + 1.0D+00\n end do\n!\n! ...and then apply an asymptotic formula.\n!\n y = 1.0D+00 / z**2\n\n trigamma = trigamma + 0.5D+00 * &\n y + ( 1.0D+00 &\n + y * ( b2 &\n + y * ( b4 &\n + y * ( b6 &\n + y * b8 )))) / z\n\n end if\n\n return\nend\nsubroutine uniform_01_cdf ( x, cdf )\n\n!*****************************************************************************80\n!\n!! UNIFORM_01_CDF evaluates the Uniform 01 CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( x < 0.0D+00 ) then\n cdf = 0.0D+00\n else if ( 1.0D+00 < x ) then\n cdf = 1.0D+00\n else\n cdf = x\n end if\n\n return\nend\nsubroutine uniform_01_cdf_inv ( cdf, x )\n\n!*****************************************************************************80\n!\n!! UNIFORM_01_CDF_INV inverts the Uniform 01 CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 08 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument.\n!\n implicit none\n\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'UNIFORM_01_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n x = cdf\n\n return\nend\nsubroutine uniform_01_mean ( mean )\n\n!*****************************************************************************80\n!\n!! UNIFORM_01_MEAN returns the mean of the Uniform 01 PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 08 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) mean\n\n mean = 0.5D+00\n\n return\nend\nsubroutine uniform_01_order_sample ( n, seed, x )\n\n!*****************************************************************************80\n!\n!! UNIFORM_01_ORDER_SAMPLE samples the Uniform 01 Order PDF.\n!\n! Discussion:\n!\n! In effect, this routine simply generates N samples of the\n! Uniform 01 PDF; but it generates them in order. (Actually,\n! it generates them in descending order, but stores them in\n! the array in ascending order). This saves the work of\n! sorting the results. Moreover, if the order statistics\n! for another PDF are desired, and the inverse CDF is available,\n! then the desired values may be generated, presorted, by\n! calling this routine and using the results as input to the\n! inverse CDF routine.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 03 March 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Jerry Banks, editor,\n! Handbook of Simulation,\n! Engineering and Management Press Books, 1998, page 168.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the number of elements in the sample.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X(N), N samples of the Uniform 01 PDF, in\n! ascending order.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) i\n integer ( kind = 4 ) seed\n real ( kind = 8 ) u\n real ( kind = 8 ) v\n real ( kind = 8 ) x(n)\n\n v = 1.0D+00\n do i = n, 1, -1\n u = r8_uniform_01 ( seed )\n v = v * u**( 1.0D+00 / real ( i, kind = 8 ) )\n x(i) = v\n end do\n\n return\nend\nsubroutine uniform_01_pdf ( x, pdf )\n\n!*****************************************************************************80\n!\n!! UNIFORM_01_PDF evaluates the Uniform 01 PDF.\n!\n! Discussion:\n!\n! PDF(X) = 1 for 0 <= X <= 1\n! = 0 otherwise\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 08 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n! 0.0D+00 <= X <= 1.0.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) pdf\n real ( kind = 8 ) x\n\n if ( x < 0.0D+00 .or. 1.0D+00 < x ) then\n pdf = 0.0D+00\n else\n pdf = 1.0D+00\n end if\n\n return\nend\nfunction uniform_01_sample ( seed )\n\n!*****************************************************************************80\n!\n!! UNIFORM_01_SAMPLE is a portable random number generator.\n!\n! Discussion:\n!\n! SEED = SEED * (7^5) mod ( 2^31 - 1 )\n! UNIFORM_01_SAMPLE = SEED * / ( 2^31 - 1 )\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 February 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) SEED, the integer \"seed\" used to\n! generate the output random number, and updated in preparation for the\n! next one. SEED should not be zero.\n!\n! Output, real ( kind = 8 ) UNIFORM_01_SAMPLE, a random value between 0 \n! and 1.\n!\n! Local parameters:\n!\n! IA = 7**5\n! IB = 2**15\n! IB16 = 2**16\n! IP = 2**31-1\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: ia = 16807\n integer ( kind = 4 ), parameter :: ib15 = 32768\n integer ( kind = 4 ), parameter :: ib16 = 65536\n integer ( kind = 4 ), parameter :: ip = 2147483647\n integer ( kind = 4 ) iprhi\n integer ( kind = 4 ) ixhi\n integer ( kind = 4 ) k\n integer ( kind = 4 ) leftlo\n integer ( kind = 4 ) loxa\n integer ( kind = 4 ) seed\n real ( kind = 8 ) uniform_01_sample\n!\n! Don't let SEED be 0 or IP\n!\n if ( seed == 0 .or. seed == ip ) then\n seed = ip / 2\n end if\n!\n! Get the 15 high order bits of SEED.\n!\n ixhi = seed / ib16\n!\n! Get the 16 low bits of SEED and form the low product.\n!\n loxa = ( seed - ixhi * ib16 ) * ia\n!\n! Get the 15 high order bits of the low product.\n!\n leftlo = loxa / ib16\n!\n! Form the 31 highest bits of the full product.\n!\n iprhi = ixhi * ia + leftlo\n!\n! Get overflow past the 31st bit of full product.\n!\n k = iprhi / ib15\n!\n! Assemble all the parts and presubtract IP. The parentheses are essential.\n!\n seed = ( ( ( loxa - leftlo * ib16 ) - ip ) + ( iprhi - k * ib15 ) * ib16 ) &\n + k\n!\n! Add IP back in if necessary.\n!\n if ( seed < 0 ) then\n seed = seed + ip\n end if\n!\n! Multiply by 1 / (2**31-1).\n!\n uniform_01_sample = real ( seed, kind = 8 ) * 4.656612875D-10\n\n return\nend\nsubroutine uniform_01_variance ( variance )\n\n!*****************************************************************************80\n!\n!! UNIFORM_01_VARIANCE returns the variance of the Uniform 01 PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 08 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) variance\n\n variance = 1.0D+00 / 12.0D+00\n\n return\nend\nsubroutine uniform_cdf ( x, a, b, cdf )\n\n!*****************************************************************************80\n!\n!! UNIFORM_CDF evaluates the Uniform CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! A < B.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( x < a ) then\n cdf = 0.0D+00\n else if ( b < x ) then\n cdf = 1.0D+00\n else\n cdf = ( x - a ) / ( b - a )\n end if\n\n return\nend\nsubroutine uniform_cdf_inv ( cdf, a, b, x )\n\n!*****************************************************************************80\n!\n!! UNIFORM_CDF_INV inverts the Uniform CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! A < B.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'UNIFORM_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n x = a + ( b - a ) * cdf\n\n return\nend\nfunction uniform_check ( a, b )\n\n!*****************************************************************************80\n!\n!! UNIFORM_CHECK checks the parameters of the Uniform CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! A < B.\n!\n! Output, logical UNIFORM_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n logical uniform_check\n\n if ( b <= a ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'UNIFORM_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B <= A.'\n uniform_check = .false.\n return\n end if\n\n uniform_check = .true.\n\n return\nend\nsubroutine uniform_mean ( a, b, mean )\n\n!*****************************************************************************80\n!\n!! UNIFORM_MEAN returns the mean of the Uniform PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! A < B.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) mean\n\n mean = 0.5D+00 * ( a + b )\n\n return\nend\nsubroutine uniform_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! UNIFORM_PDF evaluates the Uniform PDF.\n!\n! Discussion:\n!\n! The Uniform PDF is also known as the \"Rectangular\" or \"de Moivre\" PDF.\n!\n! PDF(A,B;X) = 1 / ( B - A ) for A <= X <= B\n! = 0 otherwise\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! A < B.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) pdf\n real ( kind = 8 ) x\n\n if ( x < a .or. b < x ) then\n pdf = 0.0D+00\n else\n pdf = 1.0D+00 / ( b - a )\n end if\n\n return\nend\nsubroutine uniform_sample ( a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! UNIFORM_SAMPLE samples the Uniform PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! A < B.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call uniform_cdf_inv ( cdf, a, b, x )\n\n return\nend\nsubroutine uniform_variance ( a, b, variance )\n\n!*****************************************************************************80\n!\n!! UNIFORM_VARIANCE returns the variance of the Uniform PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! A < B.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) variance\n\n variance = ( b - a )**2 / 12.0D+00\n\n return\nend\nsubroutine uniform_discrete_cdf ( x, a, b, cdf )\n\n!*****************************************************************************80\n!\n!! UNIFORM_DISCRETE_CDF evaluates the Uniform Discrete CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 29 January 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X, the argument of the CDF.\n!\n! Input, integer ( kind = 4 ) A, B, the parameters of the PDF.\n! A <= B.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n integer ( kind = 4 ) b\n real ( kind = 8 ) cdf\n integer ( kind = 4 ) x\n\n if ( x < a ) then\n cdf = 0.0D+00\n else if ( b < x ) then\n cdf = 1.0D+00\n else\n cdf = real ( x + 1 - a, kind = 8 ) / real ( b + 1 - a, kind = 8 )\n end if\n\n return\nend\nsubroutine uniform_discrete_cdf_inv ( cdf, a, b, x )\n\n!*****************************************************************************80\n!\n!! UNIFORM_DISCRETE_CDF_INV inverts the Uniform Discrete CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Input, integer ( kind = 4 ) A, B, the parameters of the PDF.\n! A <= B.\n!\n! Output, integer ( kind = 4 ) X, the smallest argument whose CDF is greater\n! than or equal to CDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n real ( kind = 8 ) a2\n integer ( kind = 4 ) b\n real ( kind = 8 ) b2\n real ( kind = 8 ) cdf\n integer ( kind = 4 ) x\n real ( kind = 8 ) x2\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'UNIFORM_DISCRETE_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n a2 = real ( a, kind = 8 ) - 0.5D+00\n b2 = real ( b, kind = 8 ) + 0.5D+00\n x2 = a + cdf * ( b2 - a2 )\n\n x = nint ( x2 )\n\n x = max ( x, a )\n x = min ( x, b )\n\n return\nend\nfunction uniform_discrete_check ( a, b )\n\n!*****************************************************************************80\n!\n!! UNIFORM_DISCRETE_CHECK checks the parameters of the Uniform discrete CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 13 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, B, the parameters of the PDF.\n! A <= B.\n!\n! Output, logical UNIFORM_DISCRETE_CHECK, is true if the parameters\n! are legal.\n!\n implicit none\n\n integer ( kind = 4 ) a\n integer ( kind = 4 ) b\n logical uniform_discrete_check\n\n if ( b < a ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'UNIFORM_DISCRETE_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B < A.'\n uniform_discrete_check = .false.\n return\n end if\n\n uniform_discrete_check = .true.\n\n return\nend\nsubroutine uniform_discrete_mean ( a, b, mean )\n\n!*****************************************************************************80\n!\n!! UNIFORM_DISCRETE_MEAN returns the mean of the Uniform discrete PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 January 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, B, the parameters of the PDF.\n! A <= B.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n integer ( kind = 4 ) b\n real ( kind = 8 ) mean\n\n mean = 0.5D+00 * real ( a + b, kind = 8 )\n\n return\nend\nsubroutine uniform_discrete_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! UNIFORM_DISCRETE_PDF evaluates the Uniform discrete PDF.\n!\n! Discussion:\n!\n! The Uniform Discrete PDF is also known as the \"Rectangular\"\n! Discrete PDF.\n!\n! PDF(A,B;X) = 1 / ( B + 1 - A ) for A <= X <= B.\n!\n! The parameters define the interval of integers\n! for which the PDF is nonzero.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 January 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X, the argument of the PDF.\n!\n! Input, integer ( kind = 4 ) A, B, the parameters of the PDF.\n! A <= B.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n integer ( kind = 4 ) b\n real ( kind = 8 ) pdf\n integer ( kind = 4 ) x\n\n if ( x < a .or. b < x ) then\n pdf = 0.0D+00\n else\n pdf = 1.0D+00 / real ( b + 1 - a, kind = 8 )\n end if\n\n return\nend\nsubroutine uniform_discrete_sample ( a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! UNIFORM_DISCRETE_SAMPLE samples the Uniform discrete PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, B, the parameters of the PDF.\n! A <= B.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, integer ( kind = 4 ) X, a sample of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n integer ( kind = 4 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n integer ( kind = 4 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call uniform_discrete_cdf_inv ( cdf, a, b, x )\n\n return\nend\nsubroutine uniform_discrete_variance ( a, b, variance )\n\n!*****************************************************************************80\n!\n!! UNIFORM_DISCRETE_VARIANCE returns the variance of the Uniform discrete PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 28 January 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) A, B, the parameters of the PDF.\n! A <= B.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n integer ( kind = 4 ) a\n integer ( kind = 4 ) b\n real ( kind = 8 ) variance\n\n variance = real ( ( b + 1 - a )**2 - 1, kind = 8 ) / 12.0D+00\n\n return\nend\nsubroutine uniform_nsphere_sample ( n, seed, x )\n\n!*****************************************************************************80\n!\n!! UNIFORM_NSPHERE_SAMPLE samples the Uniform Unit Sphere PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 15 December 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Jerry Banks, editor,\n! Handbook of Simulation,\n! Engineering and Management Press Books, 1998, page 168.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) N, the dimension of the sphere.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X(N), a point on the unit N sphere, chosen\n! with a uniform probability.\n!\n implicit none\n\n integer ( kind = 4 ) n\n\n integer ( kind = 4 ) i\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x(n)\n\n do i = 1, n\n call normal_01_sample ( seed, x(i) )\n end do\n\n x(1:n) = x(1:n) / sqrt ( sum ( x(1:n)**2 ) )\n\n return\nend\nsubroutine von_mises_cdf ( x, a, b, cdf )\n\n!*****************************************************************************80\n!\n!! VON_MISES_CDF evaluates the von Mises CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 22 September 2005\n!\n! Author:\n!\n! Original FORTRAN77 version by Geoffrey Hill.\n! FORTRAN90 version by John Burkardt\n!\n! Reference:\n!\n! Geoffrey Hill,\n! Algorithm 518,\n! Incomplete Bessel Function I0: The von Mises Distribution,\n! ACM Transactions on Mathematical Software,\n! Volume 3, Number 3, September 1977, pages 279-284.\n!\n! Kanti Mardia, Peter Jupp,\n! Directional Statistics,\n! Wiley, 2000,\n! QA276.M335\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n! A - PI <= X <= A + PI.\n!\n! Input, real ( kind = 8 ) A, a parameter of the PDF.\n! A is the preferred direction, in radians.\n! -PI <= A <= PI.\n!\n! Input, real ( kind = 8 ) B, a parameter of the PDF.\n! B measures the \"concentration\" of the distribution around the\n! angle A. B = 0 corresponds to a uniform distribution\n! (no concentration). Higher values of B cause greater concentration\n! of probability near A.\n! 0.0D+00 <= B.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ), parameter :: a1 = 12.0D+00\n real ( kind = 8 ), parameter :: a2 = 0.8D+00\n real ( kind = 8 ), parameter :: a3 = 8.0D+00\n real ( kind = 8 ), parameter :: a4 = 1.0D+00\n real ( kind = 8 ) arg\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ), parameter :: c1 = 56.0D+00\n real ( kind = 8 ) cdf\n real ( kind = 8 ), parameter :: ck = 10.5D+00\n real ( kind = 8 ) cn\n real ( kind = 8 ) error_f\n real ( kind = 8 ) erfx\n integer ( kind = 4 ) ip\n integer ( kind = 4 ) n\n real ( kind = 8 ) p\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) r\n real ( kind = 8 ) s\n real ( kind = 8 ) sn\n real ( kind = 8 ) u\n real ( kind = 8 ) v\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n real ( kind = 8 ) z\n!\n! We expect -PI <= X - A <= PI.\n!\n if ( x - a <= -pi ) then\n cdf = 0.0D+00\n return\n end if\n\n if ( pi <= x - a ) then\n cdf = 1.0D+00\n return\n end if\n!\n! Convert the angle (X - A) modulo 2 PI to the range ( 0, 2 * PI ).\n!\n z = b\n\n u = mod ( x - a + pi, 2.0D+00 * pi )\n\n if ( u < 0.0D+00 ) then\n u = u + 2.0D+00 * pi\n end if\n\n y = u - pi\n!\n! For small B, sum IP terms by backwards recursion.\n!\n if ( z <= ck ) then\n\n v = 0.0D+00\n\n if ( 0.0D+00 < z ) then\n\n ip = int ( z * a2 - a3 / ( z + a4 ) + a1 )\n p = real ( ip, kind = 8 )\n s = sin ( y )\n c = cos ( y )\n y = p * y\n sn = sin ( y )\n cn = cos ( y )\n r = 0.0D+00\n z = 2.0D+00 / z\n\n do n = 2, ip\n p = p - 1.0D+00\n y = sn\n sn = sn * c - cn * s\n cn = cn * c + y * s\n r = 1.0D+00 / ( p * z + r )\n v = ( sn / p + v ) * r\n end do\n\n end if\n\n cdf = ( u * 0.5D+00 + v ) / pi\n!\n! For large B, compute the normal approximation and left tail.\n!\n else\n\n c = 24.0D+00 * z\n v = c - c1\n r = sqrt ( ( 54.0D+00 / ( 347.0D+00 / v + 26.0D+00 - c ) - 6.0D+00 + c ) &\n / 12.0D+00 )\n z = sin ( 0.5D+00 * y ) * r\n s = 2.0D+00 * z**2\n v = v - s + 3.0D+00\n y = ( c - s - s - 16.0D+00 ) / 3.0D+00\n y = ( ( s + 1.75D+00 ) * s + 83.5D+00 ) / v - y\n arg = z * ( 1.0D+00 - s / y**2 )\n erfx = error_f ( arg )\n cdf = 0.5D+00 * erfx + 0.5D+00\n\n end if\n\n cdf = max ( cdf, 0.0D+00 )\n cdf = min ( cdf, 1.0D+00 )\n\n return\nend\nsubroutine von_mises_cdf_inv ( cdf, a, b, x )\n\n!*****************************************************************************80\n!\n!! VON_MISES_CDF_INV inverts the von Mises CDF.\n!\n! Discussion:\n!\n! A simple bisection method is used on the interval [ A - PI, A + PI ].\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 19 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n!\n! Input, real ( kind = 8 ) A, a parameter of the PDF.\n! A is the preferred direction, in radians.\n! -PI <= A <= PI.\n!\n! Input, real ( kind = 8 ) B, a parameter of the PDF.\n! B measures the \"concentration\" of the distribution around the\n! angle A. B = 0 corresponds to a uniform distribution\n! (no concentration). Higher values of B cause greater concentration\n! of probability near A.\n! 0.0D+00 <= B.\n!\n!\n! Output, real ( kind = 8 ) X, the corresponding argument of the CDF.\n! A - PI <= X <= A + PI.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) cdf1\n real ( kind = 8 ) cdf2\n real ( kind = 8 ) cdf3\n integer ( kind = 4 ) it\n integer ( kind = 4 ), parameter :: it_max = 100\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ), parameter :: tol = 0.000001D+00\n real ( kind = 8 ) x\n real ( kind = 8 ) x1\n real ( kind = 8 ) x2\n real ( kind = 8 ) x3\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'VON_MISES_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n if ( cdf == 0.0D+00 ) then\n x = a - pi\n return\n else if ( 1.0D+00 == cdf ) then\n x = a + pi\n return\n end if\n\n x1 = a - pi\n cdf1 = 0.0D+00\n\n x2 = a + pi\n cdf2 = 1.0D+00\n!\n! Now use bisection.\n!\n it = 0\n\n do\n\n it = it + 1\n\n x3 = 0.5D+00 * ( x1 + x2 )\n call von_mises_cdf ( x3, a, b, cdf3 )\n\n if ( abs ( cdf3 - cdf ) < tol ) then\n x = x3\n exit\n end if\n\n if ( it_max < it ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'VON_MISES_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' Iteration limit exceeded.'\n stop 1\n end if\n\n if ( sign ( 1.0D+00, cdf3 - cdf ) == sign ( 1.0D+00, cdf1 - cdf ) ) then\n x1 = x3\n cdf1 = cdf3\n else\n x2 = x3\n cdf2 = cdf3\n end if\n\n end do\n\n return\nend\nsubroutine von_mises_cdf_values ( n_data, a, b, x, fx )\n\n!*****************************************************************************80\n!\n!! VON_MISES_CDF_VALUES returns some values of the von Mises CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 08 December 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Kanti Mardia, Peter Jupp,\n! Directional Statistics,\n! Wiley, 2000,\n! QA276.M335\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) N_DATA. The user sets N_DATA to 0\n! before the first call. On each call, the routine increments N_DATA by 1,\n! and returns the corresponding data; when there is no more data, the\n! output value of N_DATA will be 0 again.\n!\n! Output, real ( kind = 8 ) A, a parameter of the PDF.\n! A is the preferred direction, in radians.\n! -PI <= A <= PI.\n!\n! Output, real ( kind = 8 ) B, a parameter of the PDF.\n! B measures the \"concentration\" of the distribution around the\n! angle A. B = 0 corresponds to a uniform distribution\n! (no concentration). Higher values of B cause greater concentration\n! of probability near A.\n! 0.0D+00 <= B.\n!\n! Output, real ( kind = 8 ) X, the argument of the function.\n!\n! Output, real ( kind = 8 ) FX, the value of the function.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: n_max = 23\n\n real ( kind = 8 ) a\n real ( kind = 8 ), save, dimension ( n_max ) :: a_vec = (/ &\n 0.0D+00, &\n 0.0D+00, &\n 0.0D+00, &\n 0.0D+00, &\n 0.0D+00, &\n 0.1D+01, &\n 0.1D+01, &\n 0.1D+01, &\n 0.1D+01, &\n 0.1D+01, &\n 0.1D+01, &\n -0.2D+01, &\n -0.1D+01, &\n 0.0D+01, &\n 0.1D+01, &\n 0.2D+01, &\n 0.3D+01, &\n 0.0D+00, &\n 0.0D+00, &\n 0.0D+00, &\n 0.0D+00, &\n 0.0D+00, &\n 0.0D+00 /)\n real ( kind = 8 ) b\n real ( kind = 8 ), save, dimension ( n_max ) :: b_vec = (/ &\n 0.1D+01, &\n 0.1D+01, &\n 0.1D+01, &\n 0.1D+01, &\n 0.1D+01, &\n 0.2D+01, &\n 0.2D+01, &\n 0.2D+01, &\n 0.2D+01, &\n 0.2D+01, &\n 0.2D+01, &\n 0.3D+01, &\n 0.3D+01, &\n 0.3D+01, &\n 0.3D+01, &\n 0.3D+01, &\n 0.3D+01, &\n 0.0D+00, &\n 0.1D+01, &\n 0.2D+01, &\n 0.3D+01, &\n 0.4D+01, &\n 0.5D+01 /)\n real ( kind = 8 ) fx\n real ( kind = 8 ), save, dimension ( n_max ) :: fx_vec = (/ &\n 0.2535089956281180D-01, &\n 0.1097539041177346D+00, &\n 0.5000000000000000D+00, &\n 0.8043381312498558D+00, &\n 0.9417460124555197D+00, &\n 0.5000000000000000D+00, &\n 0.6018204118446155D+00, &\n 0.6959356933122230D+00, &\n 0.7765935901304593D+00, &\n 0.8410725934916615D+00, &\n 0.8895777369550366D+00, &\n 0.9960322705517925D+00, &\n 0.9404336090170247D+00, &\n 0.5000000000000000D+00, &\n 0.5956639098297530D-01, &\n 0.3967729448207649D-02, &\n 0.2321953958111930D-03, &\n 0.6250000000000000D+00, &\n 0.7438406999109122D+00, &\n 0.8369224904294019D+00, &\n 0.8941711407897124D+00, &\n 0.9291058600568743D+00, &\n 0.9514289900655436D+00 /)\n integer ( kind = 4 ) n_data\n real ( kind = 8 ) x\n real ( kind = 8 ), save, dimension ( n_max ) :: x_vec = (/ &\n -0.2617993977991494D+01, &\n -0.1570796326794897D+01, &\n 0.0000000000000000D+00, &\n 0.1047197551196598D+01, &\n 0.2094395102393195D+01, &\n 0.1000000000000000D+01, &\n 0.1200000000000000D+01, &\n 0.1400000000000000D+01, &\n 0.1600000000000000D+01, &\n 0.1800000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.0000000000000000D+00, &\n 0.0000000000000000D+00, &\n 0.0000000000000000D+00, &\n 0.0000000000000000D+00, &\n 0.0000000000000000D+00, &\n 0.0000000000000000D+00, &\n 0.7853981633974483D+00, &\n 0.7853981633974483D+00, &\n 0.7853981633974483D+00, &\n 0.7853981633974483D+00, &\n 0.7853981633974483D+00, &\n 0.7853981633974483D+00 /)\n\n if ( n_data < 0 ) then\n n_data = 0\n end if\n\n n_data = n_data + 1\n\n if ( n_max < n_data ) then\n n_data = 0\n a = 0.0D+00\n b = 0.0D+00\n x = 0.0D+00\n fx = 0.0D+00\n else\n a = a_vec(n_data)\n b = b_vec(n_data)\n x = x_vec(n_data)\n fx = fx_vec(n_data)\n end if\n\n return\nend\nfunction von_mises_check ( a, b )\n\n!*****************************************************************************80\n!\n!! VON_MISES_CHECK checks the parameters of the von Mises PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 09 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, a parameter of the PDF.\n! A is the preferred direction, in radians.\n! -PI <= A <= PI.\n!\n! Input, real ( kind = 8 ) B, a parameter of the PDF.\n! B measures the \"concentration\" of the distribution around the\n! angle A. B = 0 corresponds to a uniform distribution\n! (no concentration). Higher values of B cause greater concentration\n! of probability near A.\n! 0.0D+00 <= B.\n!\n! Output, logical VON_MISES_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n logical von_mises_check\n\n if ( a < -pi .or. pi < a ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'VON_MISES_CHECK - Fatal error!'\n write ( *, '(a)' ) ' A < -PI or PI < A.'\n von_mises_check = .false.\n return\n end if\n\n if ( b < 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'VON_MISES_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B < 0.0'\n von_mises_check = .false.\n return\n end if\n\n von_mises_check = .true.\n\n return\nend\nsubroutine von_mises_circular_variance ( a, b, circular_variance )\n\n!*****************************************************************************80\n!\n!! VON_MISES_CIRCULAR_VARIANCE: circular variance of the von Mises PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 02 December 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, a parameter of the PDF.\n! A is the preferred direction, in radians.\n! -PI <= A <= PI.\n!\n! Input, real ( kind = 8 ) B, a parameter of the PDF.\n! B measures the \"concentration\" of the distribution around the\n! angle A. B = 0 corresponds to a uniform distribution\n! (no concentration). Higher values of B cause greater concentration\n! of probability near A.\n! 0.0D+00 <= B.\n!\n! Output, real ( kind = 8 ) CIRCULAR_VARIANCE, the circular variance\n! of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) bessel_i0\n real ( kind = 8 ) bessel_i1\n real ( kind = 8 ) circular_variance\n\n circular_variance = 1.0D+00 - bessel_i1 ( b ) / bessel_i0 ( b )\n\n return\nend\nsubroutine von_mises_mean ( a, b, mean )\n\n!*****************************************************************************80\n!\n!! VON_MISES_MEAN returns the mean of the von Mises PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 07 March 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, a parameter of the PDF.\n! A is the preferred direction, in radians.\n! -PI <= A <= PI.\n!\n! Input, real ( kind = 8 ) B, a parameter of the PDF.\n! B measures the \"concentration\" of the distribution around the\n! angle A. B = 0 corresponds to a uniform distribution\n! (no concentration). Higher values of B cause greater concentration\n! of probability near A.\n! 0.0D+00 <= B.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) mean\n\n mean = a\n\n return\nend\nsubroutine von_mises_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! VON_MISES_PDF evaluates the von Mises PDF.\n!\n! Discussion:\n!\n! PDF(A,B;X) = EXP ( B * COS ( X - A ) ) / ( 2 * PI * I0(B) )\n!\n! where:\n!\n! I0(*) is the modified Bessel function of the first\n! kind of order 0.\n!\n! The von Mises distribution for points on the unit circle is\n! analogous to the normal distribution of points on a line.\n! The variable X is interpreted as a deviation from the angle A,\n! with B controlling the amount of dispersion.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 27 October 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Jerry Banks, editor,\n! Handbook of Simulation,\n! Engineering and Management Press Books, 1998, page 160.\n!\n! Donald Best, Nicholas Fisher,\n! Efficient Simulation of the von Mises Distribution,\n! Applied Statistics,\n! Volume 28, Number 2, pages 152-157.\n!\n! Merran Evans, Nicholas Hastings, Brian Peacock,\n! Statistical Distributions,\n! Wiley, 2000,\n! LC: QA273.6.E92, pages 189-191.\n!\n! Kanti Mardia, Peter Jupp,\n! Directional Statistics,\n! Wiley, 2000,\n! LC: QA276.M335\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n! A - PI <= X <= A + PI.\n!\n! Input, real ( kind = 8 ) A, a parameter of the PDF.\n! A is the preferred direction, in radians.\n! -PI <= A <= PI.\n!\n! Input, real ( kind = 8 ) B, a parameter of the PDF.\n! B measures the \"concentration\" of the distribution around the\n! angle A. B = 0 corresponds to a uniform distribution\n! (no concentration). Higher values of B cause greater concentration\n! of probability near A.\n! 0.0D+00 <= B.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) bessel_i0\n real ( kind = 8 ) pdf\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) x\n\n if ( x < a - pi ) then\n pdf = 0.0D+00\n else if ( x <= a + pi ) then\n pdf = exp ( b * cos ( x - a ) ) / ( 2.0D+00 * pi * bessel_i0 ( b ) )\n else\n pdf = 0.0D+00\n end if\n\n return\nend\nsubroutine von_mises_sample ( a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! VON_MISES_SAMPLE samples the von Mises PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 07 March 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Donald Best, Nicholas Fisher,\n! Efficient Simulation of the von Mises Distribution,\n! Applied Statistics,\n! Volume 28, Number 2, pages 152-157.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, a parameter of the PDF.\n! A is the preferred direction, in radians.\n! -PI <= A <= PI.\n!\n! Input, real ( kind = 8 ) B, a parameter of the PDF.\n! B measures the \"concentration\" of the distribution around the\n! angle A. B = 0 corresponds to a uniform distribution\n! (no concentration). Higher values of B cause greater concentration\n! of probability near A.\n! 0.0D+00 <= B.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) r8_uniform_01\n real ( kind = 8 ) f\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) r\n real ( kind = 8 ) rho\n integer ( kind = 4 ) seed\n real ( kind = 8 ) tau\n real ( kind = 8 ) u1\n real ( kind = 8 ) u2\n real ( kind = 8 ) u3\n real ( kind = 8 ) x\n real ( kind = 8 ) z\n\n tau = 1.0D+00 + sqrt ( 1.0D+00 + 4.0D+00 * b * b )\n rho = ( tau - sqrt ( 2.0D+00 * tau ) ) / ( 2.0D+00 * b )\n r = ( 1.0D+00 + rho**2 ) / ( 2.0D+00 * rho )\n\n do\n\n u1 = r8_uniform_01 ( seed )\n z = cos ( pi * u1 )\n f = ( 1.0D+00 + r * z ) / ( r + z )\n c = b * ( r - f )\n\n u2 = r8_uniform_01 ( seed )\n\n if ( u2 < c * ( 2.0D+00 - c ) ) then\n exit\n end if\n\n if ( c <= log ( c / u2 ) + 1.0D+00 ) then\n exit\n end if\n\n end do\n\n u3 = r8_uniform_01 ( seed )\n\n x = a + sign ( 1.0D+00, u3 - 0.5D+00 ) * acos ( f )\n\n return\nend\nsubroutine weibull_cdf ( x, a, b, c, cdf )\n\n!*****************************************************************************80\n!\n!! WEIBULL_CDF evaluates the Weibull CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 12 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the CDF.\n! A <= X.\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < B,\n! 0.0D+00 < C.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n\n if ( x < a ) then\n cdf = 0.0D+00\n else\n y = ( x - a ) / b\n cdf = 1.0D+00 - 1.0D+00 / exp ( y**c )\n end if\n\n return\nend\nsubroutine weibull_cdf_inv ( cdf, a, b, c, x )\n\n!*****************************************************************************80\n!\n!! WEIBULL_CDF_INV inverts the Weibull CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 13 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 < CDF < 1.0.\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < B,\n! 0.0D+00 < C.\n!\n! Output, real ( kind = 8 ) X, the corresponding argument of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) cdf\n real ( kind = 8 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'WEIBULL_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n x = a + b * ( - log ( 1.0D+00 - cdf ) )**( 1.0D+00 / c )\n\n return\nend\nsubroutine weibull_cdf_values ( n_data, alpha, beta, x, fx )\n\n!*****************************************************************************80\n!\n!! WEIBULL_CDF_VALUES returns some values of the Weibull CDF.\n!\n! Discussion:\n!\n! In Mathematica, the function can be evaluated by:\n!\n! Needs[\"Statistics`ContinuousDistributions`\"]\n! dist = WeibullDistribution [ alpha, beta ]\n! CDF [ dist, x ]\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 31 August 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Milton Abramowitz, Irene Stegun,\n! Handbook of Mathematical Functions,\n! National Bureau of Standards, 1964,\n! LC: QA47.A34,\n! ISBN: 0-486-61272-4.\n!\n! Stephen Wolfram,\n! The Mathematica Book,\n! Fourth Edition,\n! Wolfram Media / Cambridge University Press, 1999.\n!\n! Parameters:\n!\n! Input/output, integer ( kind = 4 ) N_DATA. The user sets N_DATA to 0\n! before the first call. On each call, the routine increments N_DATA by 1,\n! and returns the corresponding data; when there is no more data, the\n! output value of N_DATA will be 0 again.\n!\n! Output, real ( kind = 8 ) ALPHA, the first parameter of the distribution.\n!\n! Output, real ( kind = 8 ) BETA, the second parameter of the distribution.\n!\n! Output, real ( kind = 8 ) X, the argument of the function.\n!\n! Output, real ( kind = 8 ) FX, the value of the function.\n!\n implicit none\n\n integer ( kind = 4 ), parameter :: n_max = 12\n\n real ( kind = 8 ) alpha\n real ( kind = 8 ), save, dimension ( n_max ) :: alpha_vec = (/ &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.1000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.4000000000000000D+01, &\n 0.5000000000000000D+01 /)\n real ( kind = 8 ) beta\n real ( kind = 8 ), save, dimension ( n_max ) :: beta_vec = (/ &\n 0.5000000000000000D+00, &\n 0.5000000000000000D+00, &\n 0.5000000000000000D+00, &\n 0.5000000000000000D+00, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.4000000000000000D+01, &\n 0.5000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01 /)\n real ( kind = 8 ) fx\n real ( kind = 8 ), save, dimension ( n_max ) :: fx_vec = (/ &\n 0.8646647167633873D+00, &\n 0.9816843611112658D+00, &\n 0.9975212478233336D+00, &\n 0.9996645373720975D+00, &\n 0.6321205588285577D+00, &\n 0.4865828809674080D+00, &\n 0.3934693402873666D+00, &\n 0.3296799539643607D+00, &\n 0.8946007754381357D+00, &\n 0.9657818816883340D+00, &\n 0.9936702845725143D+00, &\n 0.9994964109502630D+00 /)\n integer ( kind = 4 ) n_data\n real ( kind = 8 ) x\n real ( kind = 8 ), save, dimension ( n_max ) :: x_vec = (/ &\n 0.1000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.4000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.2000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.3000000000000000D+01, &\n 0.3000000000000000D+01 /)\n\n if ( n_data < 0 ) then\n n_data = 0\n end if\n\n n_data = n_data + 1\n\n if ( n_max < n_data ) then\n n_data = 0\n alpha = 0.0D+00\n beta = 0.0D+00\n x = 0.0D+00\n fx = 0.0D+00\n else\n alpha = alpha_vec(n_data)\n beta = beta_vec(n_data)\n x = x_vec(n_data)\n fx = fx_vec(n_data)\n end if\n\n return\nend\nfunction weibull_check ( a, b, c )\n\n!*****************************************************************************80\n!\n!! WEIBULL_CHECK checks the parameters of the Weibull CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 18 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < B,\n! 0.0D+00 < C.\n!\n! Output, logical WEIBULL_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n logical weibull_check\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'WEIBULL_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B <= 0.'\n weibull_check = .false.\n return\n end if\n\n if ( c <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'WEIBULL_CHECK - Fatal error!'\n write ( *, '(a)' ) ' C <= 0.'\n weibull_check = .false.\n return\n end if\n\n weibull_check = .true.\n\n return\nend\nsubroutine weibull_mean ( a, b, c, mean )\n\n!*****************************************************************************80\n!\n!! WEIBULL_MEAN returns the mean of the Weibull PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 12 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < B,\n! 0.0D+00 < C.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) mean\n real ( kind = 8 ) r8_gamma\n\n mean = b * r8_gamma ( ( c + 1.0D+00 ) / c ) + a\n\n return\nend\nsubroutine weibull_pdf ( x, a, b, c, pdf )\n\n!*****************************************************************************80\n!\n!! WEIBULL_PDF evaluates the Weibull PDF.\n!\n! Discussion:\n!\n! PDF(A,B,C;X) = ( C / B ) * ( ( X - A ) / B )^( C - 1 )\n! * EXP ( - ( ( X - A ) / B )^C ).\n!\n! The Weibull PDF is also known as the Frechet PDF.\n!\n! WEIBULL_PDF(A,B,1;X) is the Exponential PDF.\n!\n! WEIBULL_PDF(0,1,2;X) is the Rayleigh PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 12 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, the argument of the PDF.\n! A <= X\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < B,\n! 0.0D+00 < C.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) pdf\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n\n if ( x < a ) then\n\n pdf = 0.0D+00\n\n else\n\n y = ( x - a ) / b\n\n pdf = ( c / b ) * y**( c - 1.0D+00 ) / exp ( y**c )\n\n end if\n\n return\nend\nsubroutine weibull_sample ( a, b, c, seed, x )\n\n!*****************************************************************************80\n!\n!! WEIBULL_SAMPLE samples the Weibull PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 12 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < B,\n! 0.0D+00 < C.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, real ( kind = 8 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call weibull_cdf_inv ( cdf, a, b, c, x )\n\n return\nend\nsubroutine weibull_variance ( a, b, c, variance )\n\n!*****************************************************************************80\n!\n!! WEIBULL_VARIANCE returns the variance of the Weibull PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 16 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, C, the parameters of the PDF.\n! 0.0D+00 < B,\n! 0.0D+00 < C.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) g1\n real ( kind = 8 ) g2\n real ( kind = 8 ) r8_gamma\n real ( kind = 8 ) variance\n\n g1 = r8_gamma ( ( c + 2.0D+00 ) / c )\n g2 = r8_gamma ( ( c + 1.0D+00 ) / c )\n\n variance = b * b * ( g1 - g2 * g2 )\n\n return\nend\nsubroutine weibull_discrete_cdf ( x, a, b, cdf )\n\n!*****************************************************************************80\n!\n!! WEIBULL_DISCRETE_CDF evaluates the Discrete Weibull CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 17 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X, the argument of the CDF.\n! 0 <= X.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 <= A <= 1.0D+00,\n! 0.0D+00 < B.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n integer ( kind = 4 ) x\n\n if ( x < 0 ) then\n cdf = 0.0D+00\n else\n cdf = 1.0D+00 - ( 1.0D+00 - a )**((x+1)**b)\n end if\n\n return\nend\nsubroutine weibull_discrete_cdf_inv ( cdf, a, b, x )\n\n!*****************************************************************************80\n!\n!! WEIBULL_DISCRETE_CDF_INV inverts the Discrete Weibull CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 19 October 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) CDF, the value of the CDF.\n! 0.0D+00 <= CDF <= 1.0.\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 <= A <= 1.0D+00,\n! 0.0D+00 < B.\n!\n! Output, integer ( kind = 4 ) X, the corresponding argument.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n integer ( kind = 4 ) r8_ceiling\n integer ( kind = 4 ) x\n\n if ( cdf < 0.0D+00 .or. 1.0D+00 < cdf ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'WEIBULL_DISCRETE_CDF_INV - Fatal error!'\n write ( *, '(a)' ) ' CDF < 0 or 1 < CDF.'\n stop 1\n end if\n\n x = r8_ceiling ( &\n ( log ( 1.0D+00 - cdf ) / log ( 1.0D+00 - a ) )**( 1.0D+00 / b ) - 1.0D+00 )\n\n return\nend\nfunction weibull_discrete_check ( a, b )\n\n!*****************************************************************************80\n!\n!! WEIBULL_DISCRETE_CHECK checks the parameters of the discrete Weibull CDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 08 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 <= A <= 1.0D+00,\n! 0.0D+00 < B.\n!\n! Output, logical WEIBULL_DISCRETE_CHECK, is true if the parameters\n! are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n logical weibull_discrete_check\n\n if ( a < 0.0D+00 .or. 1.0D+00 < a ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'WEIBULL_DISCRETE_CHECK - Fatal error!'\n write ( *, '(a)' ) ' A < 0 or 1 < A.'\n weibull_discrete_check = .false.\n return\n end if\n\n if ( b <= 0.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'WEIBULL_DISCRETE_CHECK - Fatal error!'\n write ( *, '(a)' ) ' B <= 0.'\n weibull_discrete_check = .false.\n return\n end if\n\n weibull_discrete_check = .true.\n\n return\nend\nsubroutine weibull_discrete_pdf ( x, a, b, pdf )\n\n!*****************************************************************************80\n!\n!! WEIBULL_DISCRETE_PDF evaluates the discrete Weibull PDF.\n!\n! Discussion:\n!\n! PDF(A,B;X) = ( 1 - A )^X^B - ( 1 - A )^(X+1)^B.\n!\n! WEIBULL_DISCRETE_PDF(A,1;X) = GEOMETRIC_PDF(A;X)\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 15 February 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X, the argument of the PDF.\n! 0 <= X\n!\n! Input, real ( kind = 8 ) A, B, the parameters that define the PDF.\n! 0 <= A <= 1,\n! 0 < B.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) pdf\n integer ( kind = 4 ) x\n\n if ( x < 0 ) then\n pdf = 0.0D+00\n else\n pdf = ( 1.0D+00 - a )**(x**b) - ( 1.0D+00 - a )**((x+1)**b)\n end if\n\n return\nend\nsubroutine weibull_discrete_sample ( a, b, seed, x )\n\n!*****************************************************************************80\n!\n!! WEIBULL_DISCRETE_SAMPLE samples the discrete Weibull PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 07 March 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, the parameters of the PDF.\n! 0.0D+00 <= A <= 1.0D+00,\n! 0.0D+00 < B.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, integer ( kind = 4 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) cdf\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n integer ( kind = 4 ) x\n\n cdf = r8_uniform_01 ( seed )\n\n call weibull_discrete_cdf_inv ( cdf, a, b, x )\n\n return\nend\nfunction zeta ( p )\n\n!*****************************************************************************80\n!\n!! ZETA estimates the Riemann Zeta function.\n!\n! Discussion:\n!\n! For 1 < P, the Riemann Zeta function is defined as:\n!\n! ZETA ( P ) = Sum ( 1 <= N < Infinity ) 1 / N**P\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 07 March 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Daniel Zwillinger, editor,\n! CRC Standard Mathematical Tables and Formulae,\n! 30th Edition,\n! CRC Press, 1996.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) P, the power to which the integers are raised.\n! P must be greater than 1. For integral P up to 20, a\n! precomputed value of ZETA is returned; otherwise the infinite\n! sum is approximated.\n!\n! Output, real ( kind = 8 ) ZETA, an approximation to the Riemann\n! Zeta function.\n!\n implicit none\n\n integer ( kind = 4 ) n\n real ( kind = 8 ) p\n real ( kind = 8 ), parameter :: pi = 3.141592653589793D+00\n real ( kind = 8 ) zsum\n real ( kind = 8 ) zsum_old\n real ( kind = 8 ) zeta\n\n if ( p <= 1.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'ZETA - Fatal error!'\n write ( *, '(a)' ) ' Exponent P <= 1.0.'\n stop 1\n else if ( p == 2.0D+00 ) then\n zeta = pi**2 / 6.0D+00\n else if ( p == 3.0D+00 ) then\n zeta = 1.2020569032D+00\n else if ( p == 4.0D+00 ) then\n zeta = pi**4 / 90.0D+00\n else if ( p == 5.0D+00 ) then\n zeta = 1.0369277551D+00\n else if ( p == 6.0D+00 ) then\n zeta = pi**6 / 945.0D+00\n else if ( p == 7.0D+00 ) then\n zeta = 1.0083492774D+00\n else if ( p == 8.0D+00 ) then\n zeta = pi**8 / 9450.0D+00\n else if ( p == 9.0D+00 ) then\n zeta = 1.0020083928D+00\n else if ( p == 10.0D+00 ) then\n zeta = pi**10 / 93555.0D+00\n else if ( p == 11.0D+00 ) then\n zeta = 1.0004941886D+00\n else if ( p == 12.0D+00 ) then\n zeta = 1.0002460866D+00\n else if ( p == 13.0D+00 ) then\n zeta = 1.0001227133D+00\n else if ( p == 14.0D+00 ) then\n zeta = 1.0000612482D+00\n else if ( p == 15.0D+00 ) then\n zeta = 1.0000305882D+00\n else if ( p == 16.0D+00 ) then\n zeta = 1.0000152823D+00\n else if ( p == 17.0D+00 ) then\n zeta = 1.0000076372D+00\n else if ( p == 18.0D+00 ) then\n zeta = 1.0000038173D+00\n else if ( p == 19.0D+00 ) then\n zeta = 1.0000019082D+00\n else if ( p == 20.0D+00 ) then\n zeta = 1.0000009540D+00\n else\n\n zsum = 0.0D+00\n n = 0\n\n do\n\n n = n + 1\n zsum_old = zsum\n zsum = zsum + 1.0D+00 / ( real ( n, kind = 8 ) )**p\n if ( zsum <= zsum_old ) then\n exit\n end if\n\n end do\n\n zeta = zsum\n\n end if\n\n return\nend\nsubroutine zipf_cdf ( x, a, cdf )\n\n!*****************************************************************************80\n!\n!! ZIPF_CDF evaluates the Zipf CDF.\n!\n! Discussion:\n!\n! Simple summation is used.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 19 December 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X, the argument of the PDF.\n! 1 <= N\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 1.0D+00 < A.\n!\n! Output, real ( kind = 8 ) CDF, the value of the CDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ), save :: asave = 0.0D+00\n real ( kind = 8 ), save :: c = 0.0D+00\n real ( kind = 8 ) cdf\n real ( kind = 8 ) pdf\n integer ( kind = 4 ) x\n integer ( kind = 4 ) y\n real ( kind = 8 ) zeta\n\n if ( x < 1 ) then\n\n cdf = 0.0D+00\n\n else\n\n if ( a /= asave ) then\n\n c = zeta ( a )\n asave = a\n\n end if\n\n cdf = 0.0D+00\n do y = 1, x\n pdf = ( 1.0D+00 / real ( y, kind = 8 )**a ) / c\n cdf = cdf + pdf\n end do\n\n end if\n\n return\nend\nfunction zipf_check ( a )\n\n!*****************************************************************************80\n!\n!! ZIPF_CHECK checks the parameter of the Zipf PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 18 September 2004\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 1.0D+00 < A.\n!\n! Output, logical ZIPF_CHECK, is true if the parameters are legal.\n!\n implicit none\n\n real ( kind = 8 ) a\n logical zipf_check\n\n if ( a <= 1.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'ZIPF_CHECK - Fatal error!'\n write ( *, '(a)' ) ' A <= 1.'\n zipf_check = .false.\n return\n end if\n\n zipf_check = .true.\n\n return\nend\nsubroutine zipf_mean ( a, mean )\n\n!*****************************************************************************80\n!\n!! ZIPF_MEAN returns the mean of the Zipf PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 May 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 1.0D+00 < A.\n!\n! Output, real ( kind = 8 ) MEAN, the mean of the PDF.\n! The mean is only defined for 2 < A.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) mean\n real ( kind = 8 ) zeta\n\n if ( a <= 2.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'ZIPF_MEAN - Fatal error!'\n write ( *, '(a)' ) ' No mean defined for A <= 2.'\n stop 1\n end if\n\n mean = zeta ( a - 1.0D+00 ) / zeta ( a )\n\n return\nend\nsubroutine zipf_pdf ( x, a, pdf )\n\n!*****************************************************************************80\n!\n!! ZIPF_PDF evaluates the Zipf PDF.\n!\n! Discussion:\n!\n! PDF(A;X) = ( 1 / X^A ) / C\n!\n! where the normalizing constant is chosen so that\n!\n! C = Sum ( 1 <= I < Infinity ) 1 / I^A.\n!\n! From observation, the frequency of different words in long\n! sequences of text seems to follow the Zipf PDF, with\n! parameter A slightly greater than 1. The Zipf PDF is sometimes\n! known as the \"discrete Pareto\" PDF.\n!\n! Lotka's law is a version of the Zipf PDF in which A is 2 or approximately\n! 2. Lotka's law describes the frequency of publications by authors in a\n! given field, and estimates that the number of authors with X papers is\n! about 1/X^A of the number of authors with 1 paper.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 07 March 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Alfred Lotka,\n! The frequency distribution of scientific productivity,\n! Journal of the Washington Academy of Sciences,\n! Volume 16, Number 12, 1926, pages 317-324.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) X, the argument of the PDF.\n! 1 <= N\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 1.0D+00 < A.\n!\n! Output, real ( kind = 8 ) PDF, the value of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ), save :: asave = 0.0D+00\n real ( kind = 8 ), save :: c = 0.0D+00\n real ( kind = 8 ) pdf\n integer ( kind = 4 ) x\n real ( kind = 8 ) zeta\n\n if ( x < 1 ) then\n\n pdf = 0.0D+00\n\n else\n\n if ( a /= asave ) then\n\n c = zeta ( a )\n asave = a\n\n end if\n\n pdf = ( 1.0D+00 / real ( x, kind = 8 )**a ) / c\n\n end if\n\n return\nend\nsubroutine zipf_sample ( a, seed, x )\n\n!*****************************************************************************80\n!\n!! ZIPF_SAMPLE samples the Zipf PDF.\n!\n! Discussion:\n!\n! I am concerned that there may be a discrepancy in the results\n! of this routine, which do not seem to have the predicted variances.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 06 March 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Luc Devroye,\n! Non-Uniform Random Variate Generation,\n! Springer Verlag, 1986, pages 550-551.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 1.0D+00 < A.\n!\n! Input/output, integer ( kind = 4 ) SEED, a seed for the random \n! number generator.\n!\n! Output, integer ( kind = 4 ) X, a sample of the PDF.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n integer ( kind = 4 ) i4_huge\n real ( kind = 8 ) r8_uniform_01\n integer ( kind = 4 ) seed\n real ( kind = 8 ) t\n real ( kind = 8 ) test\n real ( kind = 8 ) u\n real ( kind = 8 ) v\n real ( kind = 8 ) w\n integer ( kind = 4 ) x\n\n test = real ( i4_huge ( ), kind = 8 )\n\n b = 2.0D+00**( a - 1.0D+00 )\n\n do\n\n u = r8_uniform_01 ( seed )\n v = r8_uniform_01 ( seed )\n w = aint ( 1.0D+00 / u**( 1.0D+00 / ( a - 1.0D+00 ) ) )\n!\n! Very small values of U can cause W to be very large,\n! bigger than the largest integer...\n!\n if ( test < w ) then\n cycle\n end if\n\n t = ( ( w + 1.0D+00 ) / w )**( a - 1.0D+00 )\n\n if ( v * w * ( t - 1.0D+00 ) * b <= t * ( b - 1.0D+00 ) ) then\n exit\n end if\n\n end do\n\n x = int ( w )\n\n return\nend\nsubroutine zipf_variance ( a, variance )\n\n!*****************************************************************************80\n!\n!! ZIPF_VARIANCE returns the variance of the Zipf PDF.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 01 May 1999\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, the parameter of the PDF.\n! 1.0D+00 < A.\n!\n! Output, real ( kind = 8 ) VARIANCE, the variance of the PDF.\n! The variance is only defined for 3 < A.\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) mean\n real ( kind = 8 ) variance\n real ( kind = 8 ) zeta\n\n if ( a <= 3.0D+00 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'ZIPF_VARIANCE - Fatal error!'\n write ( *, '(a)' ) ' No variance defined for A <= 3.0.'\n stop 1\n end if\n\n call zipf_mean ( a, mean )\n\n variance = zeta ( a - 2.0D+00 ) / zeta ( a ) - mean * mean\n\n return\nend\n", "meta": {"hexsha": "84ff1cb44d08403692b7a7921e6e5b8e4a13bc59", "size": 853024, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "external/burkardt/prob/prob.f90", "max_stars_repo_name": "utastudents/selalib", "max_stars_repo_head_hexsha": "84af43d0e82d4686a837c64384bbd173412df50e", "max_stars_repo_licenses": ["CECILL-B"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-03-11T15:22:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-22T16:26:18.000Z", "max_issues_repo_path": "external/burkardt/prob/prob.f90", "max_issues_repo_name": "utastudents/selalib", "max_issues_repo_head_hexsha": "84af43d0e82d4686a837c64384bbd173412df50e", "max_issues_repo_licenses": ["CECILL-B"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2021-06-30T20:39:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-15T12:42:50.000Z", "max_forks_repo_path": "external/burkardt/prob/prob.f90", "max_forks_repo_name": "utastudents/selalib", "max_forks_repo_head_hexsha": "84af43d0e82d4686a837c64384bbd173412df50e", "max_forks_repo_licenses": ["CECILL-B"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-03-13T17:09:10.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-22T00:30:19.000Z", "avg_line_length": 21.4710664754, "max_line_length": 80, "alphanum_fraction": 0.5369907529, "num_tokens": 299838, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245953120233, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.6753920047618988}} {"text": "! The module code was written by Alan Miller (Retired from CSIRO Mathematical & Information Sciences)\n! See also: http://users.bigpond.net.au/amiller/random.html\n! This module file was downloaded from http://www.netlib.org/random/random.f90 on 27 April 2015 by John R. Brandon\n! May 2015: Modified random_normal() to take mean and standard deviation as arguments -JRB (jbrandon at gmail)\nMODULE random\n! A module for random number generation from the following distributions:\n! \n! Distribution Function/subroutine name\n!\n! Normal (Gaussian) random_normal\n! Gamma random_gamma\n! Chi-squared random_chisq\n! Exponential random_exponential\n! Weibull random_Weibull\n! Beta random_beta\n! t random_t\n! Multivariate normal random_mvnorm\n! Generalized inverse Gaussian random_inv_gauss\n! Poisson random_Poisson\n! Binomial random_binomial1 *\n! random_binomial2 *\n! Negative binomial random_neg_binomial\n! von Mises random_von_Mises\n! Cauchy random_Cauchy\n!\n! Generate a random ordering of the integers 1 .. N\n! random_order\n! Initialize (seed) the uniform random number generator for ANY compiler\n! seed_random_number\n\n! Lognormal - see note below.\n\n! ** Two functions are provided for the binomial distribution.\n! If the parameter values remain constant, it is recommended that the\n! first function is used (random_binomial1). If one or both of the\n! parameters change, use the second function (random_binomial2).\n\n! The compilers own random number generator, SUBROUTINE RANDOM_NUMBER(r),\n! is used to provide a source of uniformly distributed random numbers.\n\n! N.B. At this stage, only one random number is generated at each call to\n! one of the functions above.\n\n! The module uses the following functions which are included here:\n! bin_prob to calculate a single binomial probability\n! lngamma to calculate the logarithm to base e of the gamma function\n\n! Some of the code is adapted from Dagpunar's book:\n! Dagpunar, J. 'Principles of random variate generation'\n! Clarendon Press, Oxford, 1988. ISBN 0-19-852202-9\n!\n! In most of Dagpunar's routines, there is a test to see whether the value\n! of one or two floating-point parameters has changed since the last call.\n! These tests have been replaced by using a logical variable FIRST.\n! This should be set to .TRUE. on the first call using new values of the\n! parameters, and .FALSE. if the parameter values are the same as for the\n! previous call.\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! Lognormal distribution\n! If X has a lognormal distribution, then log(X) is normally distributed.\n! Here the logarithm is the natural logarithm, that is to base e, sometimes\n! denoted as ln. To generate random variates from this distribution, generate\n! a random deviate from the normal distribution with mean and variance equal\n! to the mean and variance of the logarithms of X, then take its exponential.\n\n! Relationship between the mean & variance of log(X) and the mean & variance\n! of X, when X has a lognormal distribution.\n! Let m = mean of log(X), and s^2 = variance of log(X)\n! Then\n! mean of X = exp(m + 0.5s^2)\n! variance of X = (mean(X))^2.[exp(s^2) - 1]\n\n! In the reverse direction (rarely used)\n! variance of log(X) = log[1 + var(X)/(mean(X))^2]\n! mean of log(X) = log(mean(X) - 0.5var(log(X))\n\n! N.B. The above formulae relate to population parameters; they will only be\n! approximate if applied to sample values.\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n! Version 1.13, 2 October 2000\n! Changes from version 1.01\n! 1. The random_order, random_Poisson & random_binomial routines have been\n! replaced with more efficient routines.\n! 2. A routine, seed_random_number, has been added to seed the uniform random\n! number generator. This requires input of the required number of seeds\n! for the particular compiler from a specified I/O unit such as a keyboard.\n! 3. Made compatible with Lahey's ELF90.\n! 4. Marsaglia & Tsang algorithm used for random_gamma when shape parameter > 1.\n! 5. INTENT for array f corrected in random_mvnorm.\n\n! Author: Alan Miller\n! CSIRO Division of Mathematical & Information Sciences\n! Private Bag 10, Clayton South MDC\n! Clayton 3169, Victoria, Australia\n! Phone: (+61) 3 9545-8016 Fax: (+61) 3 9545-8080\n! e-mail: amiller @ bigpond.net.au\n\nIMPLICIT NONE\n\nREAL, PRIVATE :: zero = 0.0, half = 0.5, one = 1.0, two = 2.0, &\n vsmall = TINY(1.0), vlarge = HUGE(1.0)\nPRIVATE :: integral\nINTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(12, 60)\n\n\nCONTAINS\n\nSUBROUTINE qnorm (p, normal_dev, ifault)\n\n! ALGORITHM AS241 APPL. STATIST. (1988) VOL. 37, NO. 3, 477- 484.\n\n! Produces the normal deviate Z corresponding to a given lower tail area of P;\n! Z is accurate to about 1 part in 10**7.\n\n! The hash sums below are the sums of the mantissas of the coefficients.\n! They are included for use in checking transcription.\n\n! This ELF90-compatible version by Alan Miller - 20 August 1996\n! N.B. The original algorithm is as a function; this is a subroutine\n\n! This subroutine was originally name \"ppnd7\". Renamed to \"qnorm\" to match R function - John Brandon \n! Also changed variables to double precision to match type used in main program. \nIMPLICIT NONE\n\n!INTEGER, PARAMETER :: sp = SELECTED_REAL_KIND(6, 30)\nREAL (dp), INTENT(IN) :: p\nINTEGER, INTENT(OUT) :: ifault\nREAL (dp), INTENT(OUT) :: normal_dev\n\n! Local variables\n\nREAL (dp) :: zero = 0.0, one = 1.0, half = 0.5, split1 = 0.425, &\n split2 = 5.0, const1 = 0.180625, const2 = 1.6, q, r\n\n! Coefficients for P close to 0.5\n\nREAL (dp) :: a0 = 3.3871327179E+00, a1 = 5.0434271938E+01, &\n a2 = 1.5929113202E+02, a3 = 5.9109374720E+01, &\n b1 = 1.7895169469E+01, b2 = 7.8757757664E+01, &\n b3 = 6.7187563600E+01\n! HASH SUM AB 32.3184577772\n\n! Coefficients for P not close to 0, 0.5 or 1.\n\nREAL (dp) :: c0 = 1.4234372777E+00, c1 = 2.7568153900E+00, &\n c2 = 1.3067284816E+00, c3 = 1.7023821103E-01, &\n d1 = 7.3700164250E-01, d2 = 1.2021132975E-01\n! HASH SUM CD 15.7614929821\n\n! Coefficients for P near 0 or 1.\n\nREAL (dp) :: e0 = 6.6579051150E+00, e1 = 3.0812263860E+00, &\n e2 = 4.2868294337E-01, e3 = 1.7337203997E-02, &\n f1 = 2.4197894225E-01, f2 = 1.2258202635E-02\n! HASH SUM EF 19.4052910204\n\nifault = 0\nq = p - half\nIF (ABS(q) <= split1) THEN\n r = const1 - q * q\n normal_dev = q * (((a3 * r + a2) * r + a1) * r + a0) / &\n (((b3 * r + b2) * r + b1) * r + one)\n RETURN\nELSE\n IF (q < zero) THEN\n r = p\n ELSE\n r = one - p\n END IF\n IF (r <= zero) THEN\n ifault = 1\n normal_dev = zero\n RETURN\n END IF\n r = SQRT(-LOG(r))\n IF (r <= split2) THEN\n r = r - const2\n normal_dev = (((c3 * r + c2) * r + c1) * r + c0) / ((d2 * r + d1) * r + one)\n ELSE\n r = r - split2\n normal_dev = (((e3 * r + e2) * r + e1) * r + e0) / ((f2 * r + f1) * r + one)\n END IF\n IF (q < zero) normal_dev = - normal_dev\n RETURN\nEND IF\nEND SUBROUTINE qnorm\n\n \nFUNCTION random_normal(mean, sd) RESULT(fn_val)\n! JRB added optional arguments :: mean, sd\n! If user passes these into function, then random normal variate with mean and sd is returned \n!\n! Adapted from the following Fortran 77 code\n! ALGORITHM 712, COLLECTED ALGORITHMS FROM ACM.\n! THIS WORK PUBLISHED IN TRANSACTIONS ON MATHEMATICAL SOFTWARE,\n! VOL. 18, NO. 4, DECEMBER, 1992, PP. 434-435.\n\n! The function random_normal() returns a normally distributed pseudo-random\n! number with zero mean and unit variance.\n\n! The algorithm uses the ratio of uniforms method of A.J. Kinderman\n! and J.F. Monahan augmented with quadratic bounding curves.\n\nREAL :: fn_val\nreal, optional, intent(in) :: mean, sd ! added by JRB\nreal :: mu, sigma ! added by JRB\n! Local variables\nREAL :: s = 0.449871, t = -0.386595, a = 0.19600, b = 0.25472, &\n r1 = 0.27597, r2 = 0.27846, u, v, x, y, q\n\n! Generate P = (u,v) uniform in rectangle enclosing acceptance region\n\nDO\n CALL RANDOM_NUMBER(u)\n CALL RANDOM_NUMBER(v)\n v = 1.7156 * (v - half)\n\n! Evaluate the quadratic form\n x = u - s\n y = ABS(v) - t\n q = x**2 + y*(a*y - b*x)\n\n! Accept P if inside inner ellipse\n IF (q < r1) EXIT\n! Reject P if outside outer ellipse\n IF (q > r2) CYCLE\n! Reject P if outside acceptance region\n IF (v**2 < -4.0*LOG(u)*u**2) EXIT\nEND DO\n\n! Return ratio of P's coordinates as the normal deviate\nfn_val = v/u\n! If user supplies a value for mean, add this value to standard normal deviate (JRB)\nif(present(mean)) then \n mu = mean\nelse\n mu = 0.\nend if\n! If user supplies a value for sd, add this value to standard normal deviate (JRB)\nif(present(sd)) then \n sigma = sd\nelse\n sigma = 1.\nend if\n \n fn_val = (fn_val * sigma) + mu ! revised by JRB -- random normal deviate = standard normal deviate times sigma plus mu\n \nRETURN\n\nEND FUNCTION random_normal\n\n\n\nFUNCTION random_gamma(s, first) RESULT(fn_val)\n\n! Adapted from Fortran 77 code from the book:\n! Dagpunar, J. 'Principles of random variate generation'\n! Clarendon Press, Oxford, 1988. ISBN 0-19-852202-9\n\n! FUNCTION GENERATES A RANDOM GAMMA VARIATE.\n! CALLS EITHER random_gamma1 (S > 1.0)\n! OR random_exponential (S = 1.0)\n! OR random_gamma2 (S < 1.0).\n\n! S = SHAPE PARAMETER OF DISTRIBUTION (0 < REAL).\n\nREAL, INTENT(IN) :: s\nLOGICAL, INTENT(IN) :: first\nREAL :: fn_val\n\nIF (s <= zero) THEN\n WRITE(*, *) 'SHAPE PARAMETER VALUE MUST BE POSITIVE'\n STOP\nEND IF\n\nIF (s > one) THEN\n fn_val = random_gamma1(s, first)\nELSE IF (s < one) THEN\n fn_val = random_gamma2(s, first)\nELSE\n fn_val = random_exponential()\nEND IF\n\nRETURN\nEND FUNCTION random_gamma\n\n\n\nFUNCTION random_gamma1(s, first) RESULT(fn_val)\n\n! Uses the algorithm in\n! Marsaglia, G. and Tsang, W.W. (2000) `A simple method for generating\n! gamma variables', Trans. om Math. Software (TOMS), vol.26(3), pp.363-372.\n\n! Generates a random gamma deviate for shape parameter s >= 1.\n\nREAL, INTENT(IN) :: s\nLOGICAL, INTENT(IN) :: first\nREAL :: fn_val\n\n! Local variables\nREAL, SAVE :: c, d\nREAL :: u, v, x\n\nIF (first) THEN\n d = s - one/3.\n c = one/SQRT(9.0*d)\nEND IF\n\n! Start of main loop\nDO\n\n! Generate v = (1+cx)^3 where x is random normal; repeat if v <= 0.\n\n DO\n x = random_normal()\n v = (one + c*x)**3\n IF (v > zero) EXIT\n END DO\n\n! Generate uniform variable U\n\n CALL RANDOM_NUMBER(u)\n IF (u < one - 0.0331*x**4) THEN\n fn_val = d*v\n EXIT\n ELSE IF (LOG(u) < half*x**2 + d*(one - v + LOG(v))) THEN\n fn_val = d*v\n EXIT\n END IF\nEND DO\n\nRETURN\nEND FUNCTION random_gamma1\n\n\n\nFUNCTION random_gamma2(s, first) RESULT(fn_val)\n\n! Adapted from Fortran 77 code from the book:\n! Dagpunar, J. 'Principles of random variate generation'\n! Clarendon Press, Oxford, 1988. ISBN 0-19-852202-9\n\n! FUNCTION GENERATES A RANDOM VARIATE IN [0,INFINITY) FROM\n! A GAMMA DISTRIBUTION WITH DENSITY PROPORTIONAL TO\n! GAMMA2**(S-1) * EXP(-GAMMA2),\n! USING A SWITCHING METHOD.\n\n! S = SHAPE PARAMETER OF DISTRIBUTION\n! (REAL < 1.0)\n\nREAL, INTENT(IN) :: s\nLOGICAL, INTENT(IN) :: first\nREAL :: fn_val\n\n! Local variables\nREAL :: r, x, w\nREAL, SAVE :: a, p, c, uf, vr, d\n\nIF (s <= zero .OR. s >= one) THEN\n WRITE(*, *) 'SHAPE PARAMETER VALUE OUTSIDE PERMITTED RANGE'\n STOP\nEND IF\n\nIF (first) THEN ! Initialization, if necessary\n a = one - s\n p = a/(a + s*EXP(-a))\n IF (s < vsmall) THEN\n WRITE(*, *) 'SHAPE PARAMETER VALUE TOO SMALL'\n STOP\n END IF\n c = one/s\n uf = p*(vsmall/a)**s\n vr = one - vsmall\n d = a*LOG(a)\nEND IF\n\nDO\n CALL RANDOM_NUMBER(r)\n IF (r >= vr) THEN\n CYCLE\n ELSE IF (r > p) THEN\n x = a - LOG((one - r)/(one - p))\n w = a*LOG(x)-d\n ELSE IF (r > uf) THEN\n x = a*(r/p)**c\n w = x\n ELSE\n fn_val = zero\n RETURN\n END IF\n\n CALL RANDOM_NUMBER(r)\n IF (one-r <= w .AND. r > zero) THEN\n IF (r*(w + one) >= one) CYCLE\n IF (-LOG(r) <= w) CYCLE\n END IF\n EXIT\nEND DO\n\nfn_val = x\nRETURN\n\nEND FUNCTION random_gamma2\n\n\n\nFUNCTION random_chisq(ndf, first) RESULT(fn_val)\n\n! Generates a random variate from the chi-squared distribution with\n! ndf degrees of freedom\n\nINTEGER, INTENT(IN) :: ndf\nLOGICAL, INTENT(IN) :: first\nREAL :: fn_val\n\nfn_val = two * random_gamma(half*ndf, first)\nRETURN\n\nEND FUNCTION random_chisq\n\n\n\nFUNCTION random_exponential() RESULT(fn_val)\n\n! Adapted from Fortran 77 code from the book:\n! Dagpunar, J. 'Principles of random variate generation'\n! Clarendon Press, Oxford, 1988. ISBN 0-19-852202-9\n\n! FUNCTION GENERATES A RANDOM VARIATE IN [0,INFINITY) FROM\n! A NEGATIVE EXPONENTIAL DlSTRIBUTION WlTH DENSITY PROPORTIONAL\n! TO EXP(-random_exponential), USING INVERSION.\n\nREAL :: fn_val\n\n! Local variable\nREAL :: r\n\nDO\n CALL RANDOM_NUMBER(r)\n IF (r > zero) EXIT\nEND DO\n\nfn_val = -LOG(r)\nRETURN\n\nEND FUNCTION random_exponential\n\n\n\nFUNCTION random_Weibull(a) RESULT(fn_val)\n\n! Generates a random variate from the Weibull distribution with\n! probability density:\n! a\n! a-1 -x\n! f(x) = a.x e\n\nREAL, INTENT(IN) :: a\nREAL :: fn_val\n\n! For speed, there is no checking that a is not zero or very small.\n\nfn_val = random_exponential() ** (one/a)\nRETURN\n\nEND FUNCTION random_Weibull\n\n\n\nFUNCTION random_beta(aa, bb, first) RESULT(fn_val)\n\n! Adapted from Fortran 77 code from the book:\n! Dagpunar, J. 'Principles of random variate generation'\n! Clarendon Press, Oxford, 1988. ISBN 0-19-852202-9\n\n! FUNCTION GENERATES A RANDOM VARIATE IN [0,1]\n! FROM A BETA DISTRIBUTION WITH DENSITY\n! PROPORTIONAL TO BETA**(AA-1) * (1-BETA)**(BB-1).\n! USING CHENG'S LOG LOGISTIC METHOD.\n\n! AA = SHAPE PARAMETER FROM DISTRIBUTION (0 < REAL)\n! BB = SHAPE PARAMETER FROM DISTRIBUTION (0 < REAL)\n\nREAL, INTENT(IN) :: aa, bb\nLOGICAL, INTENT(IN) :: first\nREAL :: fn_val\n\n! Local variables\nREAL, PARAMETER :: aln4 = 1.3862944\nREAL :: a, b, g, r, s, x, y, z\nREAL, SAVE :: d, f, h, t, c\nLOGICAL, SAVE :: swap\n\nIF (aa <= zero .OR. bb <= zero) THEN\n WRITE(*, *) 'IMPERMISSIBLE SHAPE PARAMETER VALUE(S)'\n STOP\nEND IF\n\nIF (first) THEN ! Initialization, if necessary\n a = aa\n b = bb\n swap = b > a\n IF (swap) THEN\n g = b\n b = a\n a = g\n END IF\n d = a/b\n f = a+b\n IF (b > one) THEN\n h = SQRT((two*a*b - f)/(f - two))\n t = one\n ELSE\n h = b\n t = one/(one + (a/(vlarge*b))**b)\n END IF\n c = a+h\nEND IF\n\nDO\n CALL RANDOM_NUMBER(r)\n CALL RANDOM_NUMBER(x)\n s = r*r*x\n IF (r < vsmall .OR. s <= zero) CYCLE\n IF (r < t) THEN\n x = LOG(r/(one - r))/h\n y = d*EXP(x)\n z = c*x + f*LOG((one + d)/(one + y)) - aln4\n IF (s - one > z) THEN\n IF (s - s*z > one) CYCLE\n IF (LOG(s) > z) CYCLE\n END IF\n fn_val = y/(one + y)\n ELSE\n IF (4.0*s > (one + one/d)**f) CYCLE\n fn_val = one\n END IF\n EXIT\nEND DO\n\nIF (swap) fn_val = one - fn_val\nRETURN\nEND FUNCTION random_beta\n\n\n\nFUNCTION random_t(m) RESULT(fn_val)\n\n! Adapted from Fortran 77 code from the book:\n! Dagpunar, J. 'Principles of random variate generation'\n! Clarendon Press, Oxford, 1988. ISBN 0-19-852202-9\n\n! FUNCTION GENERATES A RANDOM VARIATE FROM A\n! T DISTRIBUTION USING KINDERMAN AND MONAHAN'S RATIO METHOD.\n\n! M = DEGREES OF FREEDOM OF DISTRIBUTION\n! (1 <= 1NTEGER)\n\nINTEGER, INTENT(IN) :: m\nREAL :: fn_val\n\n! Local variables\nREAL, SAVE :: s, c, a, f, g\nREAL :: r, x, v\n\nREAL, PARAMETER :: three = 3.0, four = 4.0, quart = 0.25, &\n five = 5.0, sixteen = 16.0\nINTEGER :: mm = 0\n\nIF (m < 1) THEN\n WRITE(*, *) 'IMPERMISSIBLE DEGREES OF FREEDOM'\n STOP\nEND IF\n\nIF (m /= mm) THEN ! Initialization, if necessary\n s = m\n c = -quart*(s + one)\n a = four/(one + one/s)**c\n f = sixteen/a\n IF (m > 1) THEN\n g = s - one\n g = ((s + one)/g)**c*SQRT((s+s)/g)\n ELSE\n g = one\n END IF\n mm = m\nEND IF\n\nDO\n CALL RANDOM_NUMBER(r)\n IF (r <= zero) CYCLE\n CALL RANDOM_NUMBER(v)\n x = (two*v - one)*g/r\n v = x*x\n IF (v > five - a*r) THEN\n IF (m >= 1 .AND. r*(v + three) > f) CYCLE\n IF (r > (one + v/s)**c) CYCLE\n END IF\n EXIT\nEND DO\n\nfn_val = x\nRETURN\nEND FUNCTION random_t\n\n\n\nSUBROUTINE random_mvnorm(n, h, d, f, first, x, ier)\n\n! Adapted from Fortran 77 code from the book:\n! Dagpunar, J. 'Principles of random variate generation'\n! Clarendon Press, Oxford, 1988. ISBN 0-19-852202-9\n\n! N.B. An extra argument, ier, has been added to Dagpunar's routine\n\n! SUBROUTINE GENERATES AN N VARIATE RANDOM NORMAL\n! VECTOR USING A CHOLESKY DECOMPOSITION.\n\n! ARGUMENTS:\n! N = NUMBER OF VARIATES IN VECTOR\n! (INPUT,INTEGER >= 1)\n! H(J) = J'TH ELEMENT OF VECTOR OF MEANS\n! (INPUT,REAL)\n! X(J) = J'TH ELEMENT OF DELIVERED VECTOR\n! (OUTPUT,REAL)\n!\n! D(J*(J-1)/2+I) = (I,J)'TH ELEMENT OF VARIANCE MATRIX (J> = I)\n! (INPUT,REAL)\n! F((J-1)*(2*N-J)/2+I) = (I,J)'TH ELEMENT OF LOWER TRIANGULAR\n! DECOMPOSITION OF VARIANCE MATRIX (J <= I)\n! (OUTPUT,REAL)\n\n! FIRST = .TRUE. IF THIS IS THE FIRST CALL OF THE ROUTINE\n! OR IF THE DISTRIBUTION HAS CHANGED SINCE THE LAST CALL OF THE ROUTINE.\n! OTHERWISE SET TO .FALSE.\n! (INPUT,LOGICAL)\n\n! ier = 1 if the input covariance matrix is not +ve definite\n! = 0 otherwise\n\nINTEGER, INTENT(IN) :: n\nREAL, INTENT(IN) :: h(:), d(:) ! d(n*(n+1)/2)\nREAL, INTENT(IN OUT) :: f(:) ! f(n*(n+1)/2)\nREAL, INTENT(OUT) :: x(:)\nLOGICAL, INTENT(IN) :: first\nINTEGER, INTENT(OUT) :: ier\n\n! Local variables\nINTEGER :: j, i, m\nREAL :: y, v\nINTEGER, SAVE :: n2\n\nIF (n < 1) THEN\n WRITE(*, *) 'SIZE OF VECTOR IS NON POSITIVE'\n STOP\nEND IF\n\nier = 0\nIF (first) THEN ! Initialization, if necessary\n n2 = 2*n\n IF (d(1) < zero) THEN\n ier = 1\n RETURN\n END IF\n\n f(1) = SQRT(d(1))\n y = one/f(1)\n DO j = 2,n\n f(j) = d(1+j*(j-1)/2) * y\n END DO\n\n DO i = 2,n\n v = d(i*(i-1)/2+i)\n DO m = 1,i-1\n v = v - f((m-1)*(n2-m)/2+i)**2\n END DO\n\n IF (v < zero) THEN\n ier = 1\n RETURN\n END IF\n\n v = SQRT(v)\n y = one/v\n f((i-1)*(n2-i)/2+i) = v\n DO j = i+1,n\n v = d(j*(j-1)/2+i)\n DO m = 1,i-1\n v = v - f((m-1)*(n2-m)/2+i)*f((m-1)*(n2-m)/2 + j)\n END DO ! m = 1,i-1\n f((i-1)*(n2-i)/2 + j) = v*y\n END DO ! j = i+1,n\n END DO ! i = 2,n\nEND IF\n\nx(1:n) = h(1:n)\nDO j = 1,n\n y = random_normal()\n DO i = j,n\n x(i) = x(i) + f((j-1)*(n2-j)/2 + i) * y\n END DO ! i = j,n\nEND DO ! j = 1,n\n\nRETURN\nEND SUBROUTINE random_mvnorm\n\n\n\nFUNCTION random_inv_gauss(h, b, first) RESULT(fn_val)\n\n! Adapted from Fortran 77 code from the book:\n! Dagpunar, J. 'Principles of random variate generation'\n! Clarendon Press, Oxford, 1988. ISBN 0-19-852202-9\n\n! FUNCTION GENERATES A RANDOM VARIATE IN [0,INFINITY] FROM\n! A REPARAMETERISED GENERALISED INVERSE GAUSSIAN (GIG) DISTRIBUTION\n! WITH DENSITY PROPORTIONAL TO GIG**(H-1) * EXP(-0.5*B*(GIG+1/GIG))\n! USING A RATIO METHOD.\n\n! H = PARAMETER OF DISTRIBUTION (0 <= REAL)\n! B = PARAMETER OF DISTRIBUTION (0 < REAL)\n\nREAL, INTENT(IN) :: h, b\nLOGICAL, INTENT(IN) :: first\nREAL :: fn_val\n\n! Local variables\nREAL :: ym, xm, r, w, r1, r2, x\nREAL, SAVE :: a, c, d, e\nREAL, PARAMETER :: quart = 0.25\n\nIF (h < zero .OR. b <= zero) THEN\n WRITE(*, *) 'IMPERMISSIBLE DISTRIBUTION PARAMETER VALUES'\n STOP\nEND IF\n\nIF (first) THEN ! Initialization, if necessary\n IF (h > quart*b*SQRT(vlarge)) THEN\n WRITE(*, *) 'THE RATIO H:B IS TOO SMALL'\n STOP\n END IF\n e = b*b\n d = h + one\n ym = (-d + SQRT(d*d + e))/b\n IF (ym < vsmall) THEN\n WRITE(*, *) 'THE VALUE OF B IS TOO SMALL'\n STOP\n END IF\n\n d = h - one\n xm = (d + SQRT(d*d + e))/b\n d = half*d\n e = -quart*b\n r = xm + one/xm\n w = xm*ym\n a = w**(-half*h) * SQRT(xm/ym) * EXP(-e*(r - ym - one/ym))\n IF (a < vsmall) THEN\n WRITE(*, *) 'THE VALUE OF H IS TOO LARGE'\n STOP\n END IF\n c = -d*LOG(xm) - e*r\nEND IF\n\nDO\n CALL RANDOM_NUMBER(r1)\n IF (r1 <= zero) CYCLE\n CALL RANDOM_NUMBER(r2)\n x = a*r2/r1\n IF (x <= zero) CYCLE\n IF (LOG(r1) < d*LOG(x) + e*(x + one/x) + c) EXIT\nEND DO\n\nfn_val = x\n\nRETURN\nEND FUNCTION random_inv_gauss\n\n\n\nFUNCTION random_Poisson(mu, first) RESULT(ival)\n!**********************************************************************\n! Translated to Fortran 90 by Alan Miller from:\n! RANLIB\n!\n! Library of Fortran Routines for Random Number Generation\n!\n! Compiled and Written by:\n!\n! Barry W. Brown\n! James Lovato\n!\n! Department of Biomathematics, Box 237\n! The University of Texas, M.D. Anderson Cancer Center\n! 1515 Holcombe Boulevard\n! Houston, TX 77030\n!\n! This work was supported by grant CA-16672 from the National Cancer Institute.\n\n! GENerate POIsson random deviate\n\n! Function\n\n! Generates a single random deviate from a Poisson distribution with mean mu.\n\n! Arguments\n\n! mu --> The mean of the Poisson distribution from which\n! a random deviate is to be generated.\n! REAL mu\n\n! Method\n\n! For details see:\n\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! 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\n! SEPARATION OF CASES A AND B\n\n! .. Scalar Arguments ..\nREAL, INTENT(IN) :: mu\nLOGICAL, INTENT(IN) :: first\nINTEGER :: ival\n! ..\n! .. Local Scalars ..\nREAL :: b1, b2, c, c0, c1, c2, c3, del, difmuk, e, fk, fx, fy, g, &\n omega, px, py, t, u, v, x, xx\nREAL, SAVE :: s, d, p, q, p0\nINTEGER :: j, k, kflag\nLOGICAL, SAVE :: full_init\nINTEGER, SAVE :: l, m\n! ..\n! .. Local Arrays ..\nREAL, SAVE :: pp(35)\n! ..\n! .. Data statements ..\nREAL, PARAMETER :: a0 = -.5, a1 = .3333333, a2 = -.2500068, a3 = .2000118, &\n a4 = -.1661269, a5 = .1421878, a6 = -.1384794, &\n a7 = .1250060\n\nREAL, PARAMETER :: fact(10) = (/ 1., 1., 2., 6., 24., 120., 720., 5040., &\n 40320., 362880. /)\n\n! ..\n! .. Executable Statements ..\nIF (mu > 10.0) THEN\n! C A S E A. (RECALCULATION OF S, D, L IF MU HAS CHANGED)\n\n IF (first) THEN\n s = SQRT(mu)\n d = 6.0*mu*mu\n\n! THE POISSON PROBABILITIES PK EXCEED THE DISCRETE NORMAL\n! PROBABILITIES FK WHENEVER K >= M(MU). L=IFIX(MU-1.1484)\n! IS AN UPPER BOUND TO M(MU) FOR ALL MU >= 10 .\n\n l = mu - 1.1484\n full_init = .false.\n END IF\n\n\n! STEP N. NORMAL SAMPLE - random_normal() FOR STANDARD NORMAL DEVIATE\n\n g = mu + s*random_normal()\n IF (g > 0.0) THEN\n ival = g\n\n! STEP I. IMMEDIATE ACCEPTANCE IF ival IS LARGE ENOUGH\n\n IF (ival>=l) RETURN\n\n! STEP S. SQUEEZE ACCEPTANCE - SAMPLE U\n\n fk = ival\n difmuk = mu - fk\n CALL RANDOM_NUMBER(u)\n IF (d*u >= difmuk*difmuk*difmuk) RETURN\n END IF\n\n! STEP P. PREPARATIONS FOR STEPS Q AND H.\n! (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/MU GUARANTEES MAJORIZATION BY THE 'HAT'-FUNCTION.\n\n IF (.NOT. full_init) THEN\n omega = .3989423/s\n b1 = .4166667E-1/mu\n b2 = .3*b1*b1\n c3 = .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 = .1069/mu\n full_init = .true.\n END IF\n\n IF (g < 0.0) GO TO 50\n\n! 'SUBROUTINE' F IS CALLED (KFLAG=0 FOR CORRECT RETURN)\n\n kflag = 0\n GO TO 70\n\n! STEP Q. QUOTIENT ACCEPTANCE (RARE CASE)\n\n 40 IF (fy-u*fy <= py*EXP(px-fx)) RETURN\n\n! STEP E. EXPONENTIAL SAMPLE - random_exponential() FOR STANDARD EXPONENTIAL\n! DEVIATE E AND SAMPLE T FROM THE LAPLACE 'HAT'\n! (IF T <= -.6744 THEN PK < FK FOR ALL MU >= 10.)\n\n 50 e = random_exponential()\n CALL RANDOM_NUMBER(u)\n u = u + u - one\n t = 1.8 + SIGN(e, u)\n IF (t <= (-.6744)) GO TO 50\n ival = mu + s*t\n fk = ival\n difmuk = mu - fk\n\n! 'SUBROUTINE' F IS CALLED (KFLAG=1 FOR CORRECT RETURN)\n\n kflag = 1\n GO TO 70\n\n! STEP H. HAT ACCEPTANCE (E IS REPEATED ON REJECTION)\n\n 60 IF (c*ABS(u) > py*EXP(px+e) - fy*EXP(fx+e)) GO TO 50\n RETURN\n\n! STEP F. 'SUBROUTINE' F. CALCULATION OF PX, PY, FX, FY.\n! CASE ival < 10 USES FACTORIALS FROM TABLE FACT\n\n 70 IF (ival>=10) GO TO 80\n px = -mu\n py = mu**ival/fact(ival+1)\n GO TO 110\n\n! CASE ival >= 10 USES POLYNOMIAL APPROXIMATION\n! A0-A7 FOR ACCURACY WHEN ADVISABLE\n! .8333333E-1=1./12. .3989423=(2*PI)**(-.5)\n\n 80 del = .8333333E-1/fk\n del = del - 4.8*del*del*del\n v = difmuk/fk\n IF (ABS(v)>0.25) THEN\n px = fk*LOG(one + v) - difmuk - del\n ELSE\n px = fk*v*v* (((((((a7*v+a6)*v+a5)*v+a4)*v+a3)*v+a2)*v+a1)*v+a0) - del\n END IF\n py = .3989423/SQRT(fk)\n 110 x = (half - difmuk)/s\n xx = x*x\n fx = -half*xx\n fy = omega* (((c3*xx + c2)*xx + c1)*xx + c0)\n IF (kflag <= 0) GO TO 40\n GO TO 60\n\n!---------------------------------------------------------------------------\n! C A S E B. mu < 10\n! START NEW TABLE AND CALCULATE P0 IF NECESSARY\n\nELSE\n IF (first) THEN\n m = MAX(1, INT(mu))\n l = 0\n p = EXP(-mu)\n q = p\n p0 = p\n END IF\n\n! STEP U. UNIFORM SAMPLE FOR INVERSION METHOD\n\n DO\n CALL RANDOM_NUMBER(u)\n ival = 0\n IF (u <= p0) RETURN\n\n! STEP T. TABLE COMPARISON UNTIL THE END PP(L) OF THE\n! PP-TABLE OF CUMULATIVE POISSON PROBABILITIES\n! (0.458=PP(9) FOR MU=10)\n\n IF (l == 0) GO TO 150\n j = 1\n IF (u > 0.458) j = MIN(l, m)\n DO k = j, l\n IF (u <= pp(k)) GO TO 180\n END DO\n IF (l == 35) CYCLE\n\n! STEP C. CREATION OF NEW POISSON PROBABILITIES P\n! AND THEIR CUMULATIVES Q=PP(K)\n\n 150 l = l + 1\n DO k = l, 35\n p = p*mu / k\n q = q + p\n pp(k) = q\n IF (u <= q) GO TO 170\n END DO\n l = 35\n END DO\n\n 170 l = k\n 180 ival = k\n RETURN\nEND IF\n\nRETURN\nEND FUNCTION random_Poisson\n\n\n\nFUNCTION random_binomial1(n, p, first) RESULT(ival)\n\n! FUNCTION GENERATES A RANDOM BINOMIAL VARIATE USING C.D.Kemp's method.\n! This algorithm is suitable when many random variates are required\n! with the SAME parameter values for n & p.\n\n! P = BERNOULLI SUCCESS PROBABILITY\n! (0 <= REAL <= 1)\n! N = NUMBER OF BERNOULLI TRIALS\n! (1 <= INTEGER)\n! FIRST = .TRUE. for the first call using the current parameter values\n! = .FALSE. if the values of (n,p) are unchanged from last call\n\n! Reference: Kemp, C.D. (1986). `A modal method for generating binomial\n! variables', Commun. Statist. - Theor. Meth. 15(3), 805-813.\n\nINTEGER, INTENT(IN) :: n\nREAL, INTENT(IN) :: p\nLOGICAL, INTENT(IN) :: first\nINTEGER :: ival\n\n! Local variables\n\nINTEGER :: ru, rd\nINTEGER, SAVE :: r0\nREAL :: u, pd, pu\nREAL, SAVE :: odds_ratio, p_r\nREAL, PARAMETER :: zero = 0.0, one = 1.0\n\nIF (first) THEN\n r0 = (n+1)*p\n p_r = bin_prob(n, p, r0)\n odds_ratio = p / (one - p)\nEND IF\n\nCALL RANDOM_NUMBER(u)\nu = u - p_r\nIF (u < zero) THEN\n ival = r0\n RETURN\nEND IF\n\npu = p_r\nru = r0\npd = p_r\nrd = r0\nDO\n rd = rd - 1\n IF (rd >= 0) THEN\n pd = pd * (rd+1) / (odds_ratio * (n-rd))\n u = u - pd\n IF (u < zero) THEN\n ival = rd\n RETURN\n END IF\n END IF\n\n ru = ru + 1\n IF (ru <= n) THEN\n pu = pu * (n-ru+1) * odds_ratio / ru\n u = u - pu\n IF (u < zero) THEN\n ival = ru\n RETURN\n END IF\n END IF\nEND DO\n\n! This point should not be reached, but just in case:\n\nival = r0\nRETURN\n\nEND FUNCTION random_binomial1\n\n\n\nFUNCTION bin_prob(n, p, r) RESULT(fn_val)\n! Calculate a binomial probability\n\nINTEGER, INTENT(IN) :: n, r\nREAL, INTENT(IN) :: p\nREAL :: fn_val\n\n! Local variable\nREAL :: one = 1.0\n\nfn_val = EXP( lngamma(DBLE(n+1)) - lngamma(DBLE(r+1)) - lngamma(DBLE(n-r+1)) &\n + r*LOG(p) + (n-r)*LOG(one - p) )\nRETURN\n\nEND FUNCTION bin_prob\n\n\n\nFUNCTION lngamma(x) RESULT(fn_val)\n\n! Logarithm to base e of the gamma function.\n!\n! Accurate to about 1.e-14.\n! Programmer: Alan Miller\n\n! Latest revision of Fortran 77 version - 28 February 1988\n\nREAL (dp), INTENT(IN) :: x\nREAL (dp) :: fn_val\n\n! Local variables\n\nREAL (dp) :: a1 = -4.166666666554424D-02, a2 = 2.430554511376954D-03, &\n a3 = -7.685928044064347D-04, a4 = 5.660478426014386D-04, &\n temp, arg, product, lnrt2pi = 9.189385332046727D-1, &\n pi = 3.141592653589793D0\nLOGICAL :: reflect\n\n! lngamma is not defined if x = 0 or a negative integer.\n\nIF (x > 0.d0) GO TO 10\nIF (x /= INT(x)) GO TO 10\nfn_val = 0.d0\nRETURN\n\n! If x < 0, use the reflection formula:\n! gamma(x) * gamma(1-x) = pi * cosec(pi.x)\n\n10 reflect = (x < 0.d0)\nIF (reflect) THEN\n arg = 1.d0 - x\nELSE\n arg = x\nEND IF\n\n! Increase the argument, if necessary, to make it > 10.\n\nproduct = 1.d0\n20 IF (arg <= 10.d0) THEN\n product = product * arg\n arg = arg + 1.d0\n GO TO 20\nEND IF\n\n! Use a polynomial approximation to Stirling's formula.\n! N.B. The real Stirling's formula is used here, not the simpler, but less\n! accurate formula given by De Moivre in a letter to Stirling, which\n! is the one usually quoted.\n\narg = arg - 0.5D0\ntemp = 1.d0/arg**2\nfn_val = lnrt2pi + arg * (LOG(arg) - 1.d0 + &\n (((a4*temp + a3)*temp + a2)*temp + a1)*temp) - LOG(product)\nIF (reflect) THEN\n temp = SIN(pi * x)\n fn_val = LOG(pi/temp) - fn_val\nEND IF\nRETURN\nEND FUNCTION lngamma\n\n\n\nFUNCTION random_binomial2(n, pp, first) RESULT(ival)\n!**********************************************************************\n! Translated to Fortran 90 by Alan Miller from:\n! RANLIB\n!\n! Library of Fortran Routines for Random Number Generation\n!\n! Compiled and Written by:\n!\n! Barry W. Brown\n! James Lovato\n!\n! Department of Biomathematics, Box 237\n! The University of Texas, M.D. Anderson Cancer Center\n! 1515 Holcombe Boulevard\n! Houston, TX 77030\n!\n! This work was supported by grant CA-16672 from the National Cancer Institute.\n\n! GENerate BINomial random deviate\n\n! Function\n\n! Generates a single random deviate from a binomial\n! distribution whose number of trials is N and whose\n! probability of an event in each trial is P.\n\n! Arguments\n\n! N --> The number of trials in the binomial distribution\n! from which a random deviate is to be generated.\n! INTEGER N\n\n! P --> The probability of an event in each trial of the\n! binomial distribution from which a random deviate\n! is to be generated.\n! REAL P\n\n! FIRST --> Set FIRST = .TRUE. for the first call to perform initialization\n! the set FIRST = .FALSE. for further calls using the same pair\n! of parameter values (N, P).\n! LOGICAL FIRST\n\n! random_binomial2 <-- A random deviate yielding the number of events\n! from N independent trials, each of which has\n! a probability of event P.\n! INTEGER random_binomial\n\n! Method\n\n! This is algorithm BTPE from:\n\n! Kachitvichyanukul, V. and Schmeiser, B. W.\n! Binomial Random Variate Generation.\n! Communications of the ACM, 31, 2 (February, 1988) 216.\n\n!**********************************************************************\n\n!*****DETERMINE APPROPRIATE ALGORITHM AND WHETHER SETUP IS NECESSARY\n\n! ..\n! .. Scalar Arguments ..\nREAL, INTENT(IN) :: pp\nINTEGER, INTENT(IN) :: n\nLOGICAL, INTENT(IN) :: first\nINTEGER :: ival\n! ..\n! .. Local Scalars ..\nREAL :: alv, amaxp, f, f1, f2, u, v, w, w2, x, x1, x2, ynorm, z, z2\nREAL, PARAMETER :: zero = 0.0, half = 0.5, one = 1.0\nINTEGER :: i, ix, ix1, k, mp\nINTEGER, SAVE :: m\nREAL, SAVE :: p, q, xnp, ffm, fm, xnpq, p1, xm, xl, xr, c, al, xll, &\n xlr, p2, p3, p4, qn, r, g\n\n! ..\n! .. Executable Statements ..\n\n!*****SETUP, PERFORM ONLY WHEN PARAMETERS CHANGE\n\nIF (first) THEN\n p = MIN(pp, one-pp)\n q = one - p\n xnp = n * p\nEND IF\n\nIF (xnp > 30.) THEN\n IF (first) THEN\n ffm = xnp + p\n m = ffm\n fm = m\n xnpq = xnp * q\n p1 = INT(2.195*SQRT(xnpq) - 4.6*q) + half\n xm = fm + half\n xl = xm - p1\n xr = xm + p1\n c = 0.134 + 20.5 / (15.3 + fm)\n al = (ffm-xl) / (ffm - xl*p)\n xll = al * (one + half*al)\n al = (xr - ffm) / (xr*q)\n xlr = al * (one + half*al)\n p2 = p1 * (one + c + c)\n p3 = p2 + c / xll\n p4 = p3 + c / xlr\n END IF\n\n!*****GENERATE VARIATE, Binomial mean at least 30.\n\n 20 CALL RANDOM_NUMBER(u)\n u = u * p4\n CALL RANDOM_NUMBER(v)\n\n! TRIANGULAR REGION\n\n IF (u <= p1) THEN\n ix = xm - p1 * v + u\n GO TO 110\n END IF\n\n! PARALLELOGRAM REGION\n\n IF (u <= p2) THEN\n x = xl + (u-p1) / c\n v = v * c + one - ABS(xm-x) / p1\n IF (v > one .OR. v <= zero) GO TO 20\n ix = x\n ELSE\n\n! LEFT TAIL\n\n IF (u <= p3) THEN\n ix = xl + LOG(v) / xll\n IF (ix < 0) GO TO 20\n v = v * (u-p2) * xll\n ELSE\n\n! RIGHT TAIL\n\n ix = xr - LOG(v) / xlr\n IF (ix > n) GO TO 20\n v = v * (u-p3) * xlr\n END IF\n END IF\n\n!*****DETERMINE APPROPRIATE WAY TO PERFORM ACCEPT/REJECT TEST\n\n k = ABS(ix-m)\n IF (k <= 20 .OR. k >= xnpq/2-1) THEN\n\n! EXPLICIT EVALUATION\n\n f = one\n r = p / q\n g = (n+1) * r\n IF (m < ix) THEN\n mp = m + 1\n DO i = mp, ix\n f = f * (g/i-r)\n END DO\n\n ELSE IF (m > ix) THEN\n ix1 = ix + 1\n DO i = ix1, m\n f = f / (g/i-r)\n END DO\n END IF\n\n IF (v > f) THEN\n GO TO 20\n ELSE\n GO TO 110\n END IF\n END IF\n\n! SQUEEZING USING UPPER AND LOWER BOUNDS ON LOG(F(X))\n\n amaxp = (k/xnpq) * ((k*(k/3. + .625) + .1666666666666)/xnpq + half)\n ynorm = -k * k / (2.*xnpq)\n alv = LOG(v)\n IF (alvynorm + amaxp) GO TO 20\n\n! STIRLING'S (actually de Moivre's) FORMULA TO MACHINE ACCURACY FOR\n! THE FINAL ACCEPTANCE/REJECTION TEST\n\n x1 = ix + 1\n f1 = fm + one\n z = n + 1 - fm\n w = n - ix + one\n z2 = z * z\n x2 = x1 * x1\n f2 = f1 * f1\n w2 = w * w\n IF (alv - (xm*LOG(f1/x1) + (n-m+half)*LOG(z/w) + (ix-m)*LOG(w*p/(x1*q)) + &\n (13860.-(462.-(132.-(99.-140./f2)/f2)/f2)/f2)/f1/166320. + &\n (13860.-(462.-(132.-(99.-140./z2)/z2)/z2)/z2)/z/166320. + &\n (13860.-(462.-(132.-(99.-140./x2)/x2)/x2)/x2)/x1/166320. + &\n (13860.-(462.-(132.-(99.-140./w2)/w2)/w2)/w2)/w/166320.) > zero) THEN\n GO TO 20\n ELSE\n GO TO 110\n END IF\n\nELSE\n! INVERSE CDF LOGIC FOR MEAN LESS THAN 30\n IF (first) THEN\n qn = q ** n\n r = p / q\n g = r * (n+1)\n END IF\n\n 90 ix = 0\n f = qn\n CALL RANDOM_NUMBER(u)\n 100 IF (u >= f) THEN\n IF (ix > 110) GO TO 90\n u = u - f\n ix = ix + 1\n f = f * (g/ix - r)\n GO TO 100\n END IF\nEND IF\n\n110 IF (pp > half) ix = n - ix\nival = ix\nRETURN\n\nEND FUNCTION random_binomial2\n\n\n\n\nFUNCTION random_neg_binomial(sk, p) RESULT(ival)\n\n! Adapted from Fortran 77 code from the book:\n! Dagpunar, J. 'Principles of random variate generation'\n! Clarendon Press, Oxford, 1988. ISBN 0-19-852202-9\n\n! FUNCTION GENERATES A RANDOM NEGATIVE BINOMIAL VARIATE USING UNSTORED\n! INVERSION AND/OR THE REPRODUCTIVE PROPERTY.\n\n! SK = NUMBER OF FAILURES REQUIRED (Dagpunar's words!)\n! = the `power' parameter of the negative binomial\n! (0 < REAL)\n! P = BERNOULLI SUCCESS PROBABILITY\n! (0 < REAL < 1)\n\n! THE PARAMETER H IS SET SO THAT UNSTORED INVERSION ONLY IS USED WHEN P <= H,\n! OTHERWISE A COMBINATION OF UNSTORED INVERSION AND\n! THE REPRODUCTIVE PROPERTY IS USED.\n\nREAL, INTENT(IN) :: sk, p\nINTEGER :: ival\n\n! Local variables\n! THE PARAMETER ULN = -LOG(MACHINE'S SMALLEST REAL NUMBER).\n\nREAL, PARAMETER :: h = 0.7\nREAL :: q, x, st, uln, v, r, s, y, g\nINTEGER :: k, i, n\n\nIF (sk <= zero .OR. p <= zero .OR. p >= one) THEN\n WRITE(*, *) 'IMPERMISSIBLE DISTRIBUTION PARAMETER VALUES'\n STOP\nEND IF\n\nq = one - p\nx = zero\nst = sk\nIF (p > h) THEN\n v = one/LOG(p)\n k = st\n DO i = 1,k\n DO\n CALL RANDOM_NUMBER(r)\n IF (r > zero) EXIT\n END DO\n n = v*LOG(r)\n x = x + n\n END DO\n st = st - k\nEND IF\n\ns = zero\nuln = -LOG(vsmall)\nIF (st > -uln/LOG(q)) THEN\n WRITE(*, *) ' P IS TOO LARGE FOR THIS VALUE OF SK'\n STOP\nEND IF\n\ny = q**st\ng = st\nCALL RANDOM_NUMBER(r)\nDO\n IF (y > r) EXIT\n r = r - y\n s = s + one\n y = y*p*g/s\n g = g + one\nEND DO\n\nival = x + s + half\nRETURN\nEND FUNCTION random_neg_binomial\n\n\n\nFUNCTION random_von_Mises(k, first) RESULT(fn_val)\n\n! Algorithm VMD from:\n! Dagpunar, J.S. (1990) `Sampling from the von Mises distribution via a\n! comparison of random numbers', J. of Appl. Statist., 17, 165-168.\n\n! Fortran 90 code by Alan Miller\n! CSIRO Division of Mathematical & Information Sciences\n\n! Arguments:\n! k (real) parameter of the von Mises distribution.\n! first (logical) set to .TRUE. the first time that the function\n! is called, or the first time with a new value\n! for k. When first = .TRUE., the function sets\n! up starting values and may be very much slower.\n\nREAL, INTENT(IN) :: k\nLOGICAL, INTENT(IN) :: first\nREAL :: fn_val\n\n! Local variables\n\nINTEGER :: j, n\nINTEGER, SAVE :: nk\nREAL, PARAMETER :: pi = 3.14159265\nREAL, SAVE :: p(20), theta(0:20)\nREAL :: sump, r, th, lambda, rlast\nREAL (dp) :: dk\n\nIF (first) THEN ! Initialization, if necessary\n IF (k < zero) THEN\n WRITE(*, *) '** Error: argument k for random_von_Mises = ', k\n RETURN\n END IF\n\n nk = k + k + one\n IF (nk > 20) THEN\n WRITE(*, *) '** Error: argument k for random_von_Mises = ', k\n RETURN\n END IF\n\n dk = k\n theta(0) = zero\n IF (k > half) THEN\n\n! Set up array p of probabilities.\n\n sump = zero\n DO j = 1, nk\n IF (j < nk) THEN\n theta(j) = ACOS(one - j/k)\n ELSE\n theta(nk) = pi\n END IF\n\n! Numerical integration of e^[k.cos(x)] from theta(j-1) to theta(j)\n\n CALL integral(theta(j-1), theta(j), p(j), dk)\n sump = sump + p(j)\n END DO\n p(1:nk) = p(1:nk) / sump\n ELSE\n p(1) = one\n theta(1) = pi\n END IF ! if k > 0.5\nEND IF ! if first\n\nCALL RANDOM_NUMBER(r)\nDO j = 1, nk\n r = r - p(j)\n IF (r < zero) EXIT\nEND DO\nr = -r/p(j)\n\nDO\n th = theta(j-1) + r*(theta(j) - theta(j-1))\n lambda = k - j + one - k*COS(th)\n n = 1\n rlast = lambda\n\n DO\n CALL RANDOM_NUMBER(r)\n IF (r > rlast) EXIT\n n = n + 1\n rlast = r\n END DO\n\n IF (n .NE. 2*(n/2)) EXIT ! is n even?\n CALL RANDOM_NUMBER(r)\nEND DO\n\nfn_val = SIGN(th, (r - rlast)/(one - rlast) - half)\nRETURN\nEND FUNCTION random_von_Mises\n\n\n\nSUBROUTINE integral(a, b, result, dk)\n\n! Gaussian integration of exp(k.cosx) from a to b.\n\nREAL (dp), INTENT(IN) :: dk\nREAL, INTENT(IN) :: a, b\nREAL, INTENT(OUT) :: result\n\n! Local variables\n\nREAL (dp) :: xmid, range, x1, x2, &\n x(3) = (/0.238619186083197_dp, 0.661209386466265_dp, 0.932469514203152_dp/), &\n w(3) = (/0.467913934572691_dp, 0.360761573048139_dp, 0.171324492379170_dp/)\nINTEGER :: i\n\nxmid = (a + b)/2._dp\nrange = (b - a)/2._dp\n\nresult = 0._dp\nDO i = 1, 3\n x1 = xmid + x(i)*range\n x2 = xmid - x(i)*range\n result = result + w(i)*(EXP(dk*COS(x1)) + EXP(dk*COS(x2)))\nEND DO\n\nresult = result * range\nRETURN\nEND SUBROUTINE integral\n\n\n\nFUNCTION random_Cauchy() RESULT(fn_val)\n\n! Generate a random deviate from the standard Cauchy distribution\n\nREAL :: fn_val\n\n! Local variables\nREAL :: v(2)\n\nDO\n CALL RANDOM_NUMBER(v)\n v = two*(v - half)\n IF (ABS(v(2)) < vsmall) CYCLE ! Test for zero\n IF (v(1)**2 + v(2)**2 < one) EXIT\nEND DO\nfn_val = v(1) / v(2)\n\nRETURN\nEND FUNCTION random_Cauchy\n\n\n\nSUBROUTINE random_order(order, n)\n\n! Generate a random ordering of the integers 1 ... n.\n\nINTEGER, INTENT(IN) :: n\nINTEGER, INTENT(OUT) :: order(n)\n\n! Local variables\n\nINTEGER :: i, j, k\nREAL :: wk\n\nDO i = 1, n\n order(i) = i\nEND DO\n\n! Starting at the end, swap the current last indicator with one\n! randomly chosen from those preceeding it.\n\nDO i = n, 2, -1\n CALL RANDOM_NUMBER(wk)\n j = 1 + i * wk\n IF (j < i) THEN\n k = order(i)\n order(i) = order(j)\n order(j) = k\n END IF\nEND DO\n\nRETURN\nEND SUBROUTINE random_order\n\n\n\nSUBROUTINE seed_random_number(iounit)\n\nINTEGER, INTENT(IN) :: iounit\n\n! Local variables\n\nINTEGER :: k\nINTEGER, ALLOCATABLE :: seed(:)\n\nCALL RANDOM_SEED(SIZE=k)\nALLOCATE( seed(k) )\n\nWRITE(*, '(a, i2, a)')' Enter ', k, ' integers for random no. seeds: '\nREAD(*, *) seed\nWRITE(iounit, '(a, (7i10))') ' Random no. seeds: ', seed\nCALL RANDOM_SEED(PUT=seed)\n\nDEALLOCATE( seed )\n\nRETURN\nEND SUBROUTINE seed_random_number\n\n\nEND MODULE random\n", "meta": {"hexsha": "7b48552a67702f31dcc669635127b161d9c3545b", "size": 42722, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "PBR Netbeans/A_Random_module.f90", "max_stars_repo_name": "John-Brandon/PBR-Tier-Initializations", "max_stars_repo_head_hexsha": "429c0961ecda16dbc9ac1919e3f537291c140b70", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-07-26T00:18:41.000Z", "max_stars_repo_stars_event_max_datetime": "2017-07-26T00:18:41.000Z", "max_issues_repo_path": "PBR Netbeans/A_Random_module.f90", "max_issues_repo_name": "John-Brandon/PBR-Tier-Initializations", "max_issues_repo_head_hexsha": "429c0961ecda16dbc9ac1919e3f537291c140b70", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "PBR Netbeans/A_Random_module.f90", "max_forks_repo_name": "John-Brandon/PBR-Tier-Initializations", "max_forks_repo_head_hexsha": "429c0961ecda16dbc9ac1919e3f537291c140b70", "max_forks_repo_licenses": ["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.1453796351, "max_line_length": 122, "alphanum_fraction": 0.5733579889, "num_tokens": 14270, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245828938678, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.6753920004193376}} {"text": "! use random_mod\n\n! rnd() => real64, 0 <= v < 1\n! randint(n) => int32 or int64, 0 <= v <= n\n! randrange(l,r) => int32 or int64, l <= v <= r\n\nmodule random01_mod\n use,intrinsic :: iso_fortran_env\n implicit none\ncontains\n function random01() result(v)\n real(real64):: v\n\n call random_number(v)\n end function\nend module\n\n\nmodule random_int32\n use,intrinsic :: iso_fortran_env\n use random01_mod,only: rnd => random01\n implicit none\n private\n public:: randrange, randint\ncontains\n function randrange(l,r) result(v)\n integer(int32),intent(in):: l,r\n integer(int32):: v\n\n v = int(rnd()*(r-l+1)) + l\n end function\n\n function randint(n) result(v)\n integer(int32),intent(in):: n\n integer(int32):: v\n\n v = randrange(0_int32, n)\n end function\nend module\n\n\nmodule random_int64\n use,intrinsic :: iso_fortran_env\n use random01_mod,only: rnd => random01\n implicit none\n private\n public:: randrange, randint\ncontains\n function randrange(l,r) result(v)\n integer(int64),intent(in):: l,r\n integer(int64):: v\n\n v = int(rnd()*(r-l+1)) + l\n end function\n\n function randint(n) result(v)\n integer(int64),intent(in):: n\n integer(int64):: v\n\n v = randrange(0_int64, n)\n end function\nend module\n\n\nmodule random_real64\n use,intrinsic :: iso_fortran_env\n use random01_mod,only: rnd => random01\n implicit none\n private\n public:: randrange, randint\ncontains\n function randrange(l,r) result(v)\n real(real64),intent(in):: l,r\n real(real64):: v\n\n v = rnd()*(r-l) + l\n end function\n\n function randint(n) result(v)\n real(real64),intent(in):: n\n real(real64):: v\n\n v = rnd()*n\n end function\nend module random_real64\n\n\nmodule random_mod\n use,intrinsic :: iso_fortran_env\n use random01_mod, only: random01\n use random_int32, rri32=>randrange, rii32=>randint\n use random_int64, rri64=>randrange, rii64=>randint\n use random_real64, rrr64=>randrange, rir64=>randint\n \n interface randrange\n module procedure rri32, rri64, rrr64\n end interface\n\n interface randint\n module procedure rii32, rii64, rir64\n end interface\n\n interface random01\n module procedure random01\n end interface\n\n public:: random01, randrange, randint\nend module", "meta": {"hexsha": "65159c692443ece7baa410e8b4a07d49c1ef1898", "size": 2399, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/random.f90", "max_stars_repo_name": "Atnuhs/fortran_lib", "max_stars_repo_head_hexsha": "d0d6724eec934195959317a212a03f1ed1654f9d", "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/random.f90", "max_issues_repo_name": "Atnuhs/fortran_lib", "max_issues_repo_head_hexsha": "d0d6724eec934195959317a212a03f1ed1654f9d", "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/random.f90", "max_forks_repo_name": "Atnuhs/fortran_lib", "max_forks_repo_head_hexsha": "d0d6724eec934195959317a212a03f1ed1654f9d", "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": 22.212962963, "max_line_length": 55, "alphanum_fraction": 0.6290120884, "num_tokens": 679, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267762381844, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.6753389325547952}} {"text": " SUBROUTINE SPTSV_F95( D, E, B, INFO )\n!\n! -- LAPACK95 interface driver routine (version 3.0) --\n! UNI-C, Denmark; Univ. of Tennessee, USA; NAG Ltd., UK\n! September, 2000\n!\n! .. USE STATEMENTS ..\n USE LA_PRECISION, ONLY: WP => SP\n USE LA_AUXMOD, ONLY: ERINFO\n USE F77_LAPACK, ONLY: PTSV_F77 => LA_PTSV\n! .. IMPLICIT STATEMENT ..\n IMPLICIT NONE\n! .. SCALAR ARGUMENTS ..\n INTEGER, INTENT(OUT), OPTIONAL :: INFO\n! .. ARRAY ARGUMENTS ..\n REAL(WP), INTENT(INOUT) :: D(:)\n REAL(WP), INTENT(INOUT) :: E(:), B(:,:)\n!----------------------------------------------------------------------\n! \n! Purpose\n! =======\n! \n! LA_PTSV computes the solution to a linear system of equations \n! A*X = B, where A has tridiagonal form and is real symmetric or complex\n! Hermitian and, in either case, positive definite, and where X and B are\n! rectangular matrices or vectors. A is factored as A = L*D*L^H, where L \n! is a unit lower bidiagonal matrix and D is a diagonal matrix. The \n! factored form of A is then used to solve the above system.\n! \n! =========\n! \n! SUBROUTINE LA_PTSV( D, E, B, INFO=info )\n! REAL(), INTENT(INOUT) :: D(:)\n! (), INTENT(INOUT) :: E(:), \n! INTEGER, INTENT(OUT), OPTIONAL :: INFO\n! where\n! ::= REAL | COMPLEX\n! ::= KIND(1.0) | KIND(1.0D0)\n! ::= B(:,:) | B(:)\n! \n! Arguments\n! =========\n! \n! D (input/output) REAL array, shape (:) with size(D) = n, where n \n! is the order of A.\n! On entry, the diagonal of A.\n! On exit, the diagonal of D.\n! E (input/output) REAL or COMPLEX array, shape (:), with \n! size(E) = n-1.\n! On entry, the subdiagonal of A.\n! On exit, the subdiagonal of L.\n! B (input/output) REAL or COMPLEX array, shape (:,:) with \n! size(B,1) = n or shape (:) with size(B) = n.\n! On entry, the matrix B.\n! On exit, the solution matrix X.\n! INFO Optional (output) INTEGER.\n! = 0: successful exit.\n! < 0: if INFO = -i, the i-th argument had an illegal value.\n! > 0: if INFO = i, the leading minor of order i of A is not \n! positive definite, and the solution has not been computed.\n! \t The factorization has not been completed unless i = n.\n! If INFO is not present and an error occurs, then the program is\n! terminated with an error message.\n!----------------------------------------------------------------------\n! .. PARAMETERS ..\n CHARACTER(LEN=7), PARAMETER :: SRNAME = 'LA_PTSV'\n! .. LOCAL SCALARS ..\n INTEGER :: LINFO, N, NRHS\n! .. INTRINSIC FUNCTIONS ..\n INTRINSIC SIZE\n! .. EXECUTABLE STATEMENTS ..\n LINFO = 0\n N = SIZE(D); NRHS = SIZE(B,2)\n! .. TEST THE ARGUMENTS\n IF( N < 0 ) THEN; LINFO = -1\n ELSE IF( SIZE( E ) /= N-1 .AND. N /= 0 ) THEN; LINFO = -2\n ELSE IF( SIZE( B, 1 ) /= N .OR. NRHS < 0 ) THEN; LINFO = -3\n ELSE IF ( N > 0 ) THEN\n CALL PTSV_F77( N, NRHS, D, E, B, N, LINFO )\n END IF\n CALL ERINFO( LINFO, SRNAME, INFO )\n END SUBROUTINE SPTSV_F95\n", "meta": {"hexsha": "e22909ed019eb231589b6814e4e2cae337ed4ff4", "size": 3117, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/la_sptsv.f90", "max_stars_repo_name": "MattBurn/LAPACK95", "max_stars_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-12-29T15:07:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T10:09:22.000Z", "max_issues_repo_path": "src/la_sptsv.f90", "max_issues_repo_name": "MattBurn/LAPACK95", "max_issues_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-02-21T10:46:38.000Z", "max_issues_repo_issues_event_max_datetime": "2017-10-20T17:03:14.000Z", "max_forks_repo_path": "src/la_sptsv.f90", "max_forks_repo_name": "MattBurn/LAPACK95", "max_forks_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-12-29T15:34:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-15T07:12:40.000Z", "avg_line_length": 37.5542168675, "max_line_length": 73, "alphanum_fraction": 0.5444337504, "num_tokens": 957, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267626522814, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.6753389309588982}} {"text": " PROGRAM xhqr\r\nC driver for routine hqr\r\n INTEGER NP\r\n PARAMETER(NP=5)\r\n INTEGER i,j\r\n REAL a(NP,NP),wr(NP),wi(NP)\r\n DATA a/1.0,-2.0,3.0,-4.0,-5.0,2.0,3.0,4.0,5.0,6.0,\r\n * 0.0,0.0,50.0,-60.0,-70.0,0.0,0.0,0.0,7.0,8.0,\r\n * 0.0,0.0,0.0,0.0,-9.0/\r\n write(*,'(/1x,a)') 'Matrix:'\r\n do 11 i=1,NP\r\n write(*,'(1x,5f12.2)') (a(i,j),j=1,NP)\r\n11 continue\r\n call balanc(a,NP,NP)\r\n call elmhes(a,NP,NP)\r\n call hqr(a,NP,NP,wr,wi)\r\n write(*,'(/1x,a)') 'Eigenvalues:'\r\n write(*,'(/1x,t9,a,t24,a/)') 'Real','Imag.'\r\n do 12 i=1,NP\r\n write(*,'(1x,2e15.6)') wr(i),wi(i)\r\n12 continue\r\n END\r\n", "meta": {"hexsha": "3dec259b38c278d6b911a0a64b6ba12ff11f9eab", "size": 685, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xhqr.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xhqr.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xhqr.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.7826086957, "max_line_length": 57, "alphanum_fraction": 0.4569343066, "num_tokens": 322, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267762381843, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6753389280725832}} {"text": "SUBROUTINE GLU( A, N, N1, B, EPS, WK, IP, IER )\n! GLU, GLUSUB\n! COPYRIGHT : H.HASEGAWA, AUG. 26 1989 V.1\n!\n! SOLVES SIMULTANEOUS LINEAR EQUATIONS\n! BY GAUSSIAN ELIMINATION METHOD.\n!\n! INPUT - -\n! A(N1,N) R *8 : 2-DIM. ARRAY CONTAINING THE COEFFICIENTS.\n! N I *4 : ORDER OF MATRIX.\n! N1 I *4 : SIZE OF ARRAY A.\n! B(N) R *8 : 1-DIM. ARRAY CONTAINING THE RIGHT-HAND\n! SIDE VECTOR.\n! EPS R *8 : PARAMETER TO CHECK SINGULARITY OF THE\n! MATRIX. ( STANDARD VALUE 3.52D-15 )\n! OUTPUT - -\n! A(N1,N) : RESULT OF GAUSSIAN ELIMINATION.\n! B(N) : SOLUTION.\n! IP(N) I *4 : PIVOT NUMBER.\n! IER I *4 : = 0, FOR NORMAL EXECUTION.\n! = 1, FOR SINGULAR MATRIX.\n! = 2, FOR SINGULAR ORIGINAL MATRIX.\n! = 3, FOR INVALID ARGUEMENT.\n! WORKING -\n! WK(N) R *8 : 1-DIM. ARRAY.\n! modified : Kensuke Konishi 2018 in Paris\n use parameters\n implicit none\n INTEGER:: N,N1\n INTEGER:: IP(N),IER\n double precision:: EPS\n COMPLEX(dp)::A(N1,N),B(N),WK(N)\n INTEGER:: I,J,K,IPK\n COMPLEX(dp):: AMAX,AIK,W,T\n ! LEFT-HAND SIDE\n IF( EPS<0 ) EPS = 3.52D-15\n IF( N1cdabs( AMAX ) ) THEN\n IPK = I\n AMAX = AIK\n END IF\n enddo\n IP(K) = IPK\n\n IF( cdabs( AMAX )>EPS ) THEN\n IF( IPK/=K ) THEN\n W = A(IPK,K)\n A(IPK,K) = A(K,K)\n A(K,K) = W\n END IF\n ! COMPUTE ALFA\n DO I = K+1, N\n A(I,K) = -A(I,K)/A(K,K)\n WK(I) = A(I,K)\n enddo\n\n DO J = K+1, N\n IF( IPK/=K ) THEN\n W = A(IPK,J)\n A(IPK,J) = A(K,J)\n A(K,J) = W\n END IF\n ! GAUSSIAN ELIMINATION\n T = A(K,J)\n\n A(K+1:N,J) = A(K+1:N,J) + WK(K+1:N)*T\n\n enddo\n ! MATRIX IS SINGULAR.\n ELSE\n IER = 1\n IP(K) = K\n\n A(k+1:n,K) = 0\n\n WRITE(*,*) ' (SUBR. GLU) MATRIX IS SINGULAR AT K =', K\n RETURN\n END IF\n enddo\n ! RIGHT-HAND SIDE\n !\tENTRY GLUSUB( A, B )\n ENTRY GLUSUB( A, N, N1, B, EPS, WK, IP, IER )\n ! FORWARD ELIMINATION PROCESS\n DO K = 1, N\n IF( IP(K)/=K ) THEN\n W = B(IP(K))\n B(IP(K)) = B(K)\n B(K) = W\n END IF\n\n T = B(K)\n B(K+1:N) = B(K+1:N) + A(K+1:N,K)*T\n enddo\n ! BACKWARD SUBSTITUTION PROCESS\n B(N) = B(N)/A(N,N)\n DO K = N-1, 1, -1\n T = B(K+1)\n B(1:k) = B(1:k) - A(1:k,K+1)*T\n B(K) = B(K)/A(K,K)\n enddo\n RETURN\nEND\n", "meta": {"hexsha": "f9e69eaf2308720974f3fb9f4055a4948f1b85b7", "size": 3673, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "dsmpy/src_f90/tipsv/glu2.f90", "max_stars_repo_name": "seismobassoon/dsmpy", "max_stars_repo_head_hexsha": "4290269ff0998549a2eec25ed090417f8cf1bad7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "dsmpy/src_f90/tipsv/glu2.f90", "max_issues_repo_name": "seismobassoon/dsmpy", "max_issues_repo_head_hexsha": "4290269ff0998549a2eec25ed090417f8cf1bad7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "dsmpy/src_f90/tipsv/glu2.f90", "max_forks_repo_name": "seismobassoon/dsmpy", "max_forks_repo_head_hexsha": "4290269ff0998549a2eec25ed090417f8cf1bad7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.6953125, "max_line_length": 72, "alphanum_fraction": 0.3955894364, "num_tokens": 1250, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267762381844, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.6753389235903712}} {"text": "*DECK SODS\n SUBROUTINE SODS (A, X, B, NEQ, NUK, NRDA, IFLAG, WORK, IWORK)\nC***BEGIN PROLOGUE SODS\nC***SUBSIDIARY\nC***PURPOSE Subsidiary to BVSUP\nC***LIBRARY SLATEC\nC***TYPE SINGLE PRECISION (SODS-S)\nC***AUTHOR Watts, H. A., (SNLA)\nC***DESCRIPTION\nC\nC SODS solves the overdetermined system of linear equations A X = B,\nC where A is NEQ by NUK and NEQ .GE. NUK. If rank A = NUK,\nC X is the UNIQUE least squares solution vector. That is,\nC R(1)**2 + ..... + R(NEQ)**2 = minimum\nC where R is the residual vector R = B - A X.\nC If rank A .LT. NUK , the least squares solution of minimal\nC length can be provided.\nC SODS is an interfacing routine which calls subroutine LSSODS\nC for the solution. LSSODS in turn calls subroutine ORTHOL and\nC possibly subroutine OHTROR for the decomposition of A by\nC orthogonal transformations. In the process, ORTHOL calls upon\nC subroutine CSCALE for scaling.\nC\nC **********************************************************************\nC Input\nC **********************************************************************\nC\nC A -- Contains the matrix of NEQ equations in NUK unknowns and must\nC be dimensioned NRDA by NUK. The original A is destroyed\nC X -- Solution array of length at least NUK\nC B -- Given constant vector of length NEQ, B is destroyed\nC NEQ -- Number of equations, NEQ greater or equal to 1\nC NUK -- Number of columns in the matrix (which is also the number\nC of unknowns), NUK not larger than NEQ\nC NRDA -- Row dimension of A, NRDA greater or equal to NEQ\nC IFLAG -- Status indicator\nC =0 For the first call (and for each new problem defined by\nC a new matrix A) when the matrix data is treated as exact\nC =-K For the first call (and for each new problem defined by\nC a new matrix A) when the matrix data is assumed to be\nC accurate to about K digits\nC =1 For subsequent calls whenever the matrix A has already\nC been decomposed (problems with new vectors B but\nC same matrix a can be handled efficiently)\nC WORK(*),IWORK(*) -- Arrays for storage of internal information,\nC WORK must be dimensioned at least 2 + 5*NUK\nC IWORK must be dimensioned at least NUK+2\nC IWORK(2) -- Scaling indicator\nC =-1 If the matrix A is to be pre-scaled by\nC columns when appropriate\nC If the scaling indicator is not equal to -1\nC no scaling will be attempted\nC For most problems scaling will probably not be necessary\nC\nC **********************************************************************\nC OUTPUT\nC **********************************************************************\nC\nC IFLAG -- Status indicator\nC =1 If solution was obtained\nC =2 If improper input is detected\nC =3 If rank of matrix is less than NUK\nC If the minimal length least squares solution is\nC desired, simply reset IFLAG=1 and call the code again\nC X -- Least squares solution of A X = B\nC A -- Contains the strictly upper triangular part of the reduced\nC matrix and the transformation information\nC WORK(*),IWORK(*) -- Contains information needed on subsequent\nC Calls (IFLAG=1 case on input) which must not\nC be altered\nC WORK(1) contains the Euclidean norm of\nC the residual vector\nC WORK(2) contains the Euclidean norm of\nC the solution vector\nC IWORK(1) contains the numerically determined\nC rank of the matrix A\nC\nC **********************************************************************\nC\nC***SEE ALSO BVSUP\nC***REFERENCES G. Golub, Numerical methods for solving linear least\nC squares problems, Numerische Mathematik 7, (1965),\nC pp. 206-216.\nC P. Businger and G. Golub, Linear least squares\nC solutions by Householder transformations, Numerische\nC Mathematik 7, (1965), pp. 269-276.\nC H. A. Watts, Solving linear least squares problems\nC using SODS/SUDS/CODS, Sandia Report SAND77-0683,\nC Sandia Laboratories, 1977.\nC***ROUTINES CALLED LSSODS\nC***REVISION HISTORY (YYMMDD)\nC 750601 DATE WRITTEN\nC 890831 Modified array declarations. (WRB)\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900402 Added TYPE section. (WRB)\nC 910408 Updated the AUTHOR and REFERENCES sections. (WRB)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE SODS\n DIMENSION A(NRDA,*),X(*),B(*),WORK(*),IWORK(*)\nC\nC***FIRST EXECUTABLE STATEMENT SODS\n ITER=0\n IS=2\n IP=3\n KS=2\n KD=3\n KZ=KD+NUK\n KV=KZ+NUK\n KT=KV+NUK\n KC=KT+NUK\nC\n CALL LSSODS(A,X,B,NEQ,NUK,NRDA,IFLAG,IWORK(1),IWORK(IS),A,\n 1 WORK(KD),IWORK(IP),ITER,WORK(1),WORK(KS),\n 2 WORK(KZ),B,WORK(KV),WORK(KT),WORK(KC))\nC\n RETURN\n END\n", "meta": {"hexsha": "272f79c1e13a254e5dec5b9d8f48f999197a3115", "size": 5276, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/sods.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/sods.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/sods.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.7118644068, "max_line_length": 72, "alphanum_fraction": 0.573161486, "num_tokens": 1370, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096158798115, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6753176812084308}} {"text": "*> \\brief DGESV computes the solution to system of linear equations A * X = B for GE matrices\n*\n* =========== DOCUMENTATION ===========\n*\n* Online html documentation available at\n* http://www.netlib.org/lapack/explore-html/\n*\n*> \\htmlonly\n*> Download DGESV + dependencies\n*> \n*> [TGZ]\n*> \n*> [ZIP]\n*> \n*> [TXT]\n*> \\endhtmlonly\n*\n* Definition:\n* ===========\n*\n* SUBROUTINE DGESV( N, NRHS, A, LDA, IPIV, B, LDB, INFO )\n*\n* .. Scalar Arguments ..\n* INTEGER INFO, LDA, LDB, N, NRHS\n* ..\n* .. Array Arguments ..\n* INTEGER IPIV( * )\n* DOUBLE PRECISION A( LDA, * ), B( LDB, * )\n* ..\n*\n*\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*>\n*> DGESV computes the solution to a real system of linear equations\n*> A * X = B,\n*> where A is an N-by-N matrix and X and B are N-by-NRHS matrices.\n*>\n*> The LU decomposition with partial pivoting and row interchanges is\n*> used to factor A as\n*> A = P * L * U,\n*> where P is a permutation matrix, L is unit lower triangular, and U is\n*> upper triangular. The factored form of A is then used to solve the\n*> system of equations A * X = B.\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in] N\n*> \\verbatim\n*> N is INTEGER\n*> The number of linear equations, i.e., the order of the\n*> matrix A. N >= 0.\n*> \\endverbatim\n*>\n*> \\param[in] NRHS\n*> \\verbatim\n*> NRHS is INTEGER\n*> The number of right hand sides, i.e., the number of columns\n*> of the matrix B. NRHS >= 0.\n*> \\endverbatim\n*>\n*> \\param[in,out] A\n*> \\verbatim\n*> A is DOUBLE PRECISION array, dimension (LDA,N)\n*> On entry, the N-by-N coefficient matrix A.\n*> On exit, the factors L and U from the factorization\n*> A = P*L*U; the unit diagonal elements of L are not stored.\n*> \\endverbatim\n*>\n*> \\param[in] LDA\n*> \\verbatim\n*> LDA is INTEGER\n*> The leading dimension of the array A. LDA >= max(1,N).\n*> \\endverbatim\n*>\n*> \\param[out] IPIV\n*> \\verbatim\n*> IPIV is INTEGER array, dimension (N)\n*> The pivot indices that define the permutation matrix P;\n*> row i of the matrix was interchanged with row IPIV(i).\n*> \\endverbatim\n*>\n*> \\param[in,out] B\n*> \\verbatim\n*> B is DOUBLE PRECISION array, dimension (LDB,NRHS)\n*> On entry, the N-by-NRHS matrix of right hand side matrix B.\n*> On exit, if INFO = 0, the N-by-NRHS solution matrix X.\n*> \\endverbatim\n*>\n*> \\param[in] LDB\n*> \\verbatim\n*> LDB is INTEGER\n*> The leading dimension of the array B. LDB >= max(1,N).\n*> \\endverbatim\n*>\n*> \\param[out] INFO\n*> \\verbatim\n*> INFO is INTEGER\n*> = 0: successful exit\n*> < 0: if INFO = -i, the i-th argument had an illegal value\n*> > 0: if INFO = i, U(i,i) is exactly zero. The factorization\n*> has been completed, but the factor U is exactly\n*> singular, so the solution could not be computed.\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee\n*> \\author Univ. of California Berkeley\n*> \\author Univ. of Colorado Denver\n*> \\author NAG Ltd.\n*\n*> \\date December 2016\n*\n*> \\ingroup doubleGEsolve\n*\n* =====================================================================\n SUBROUTINE DGESV( N, NRHS, A, LDA, IPIV, B, LDB, INFO )\n*\n* -- LAPACK driver routine (version 3.7.0) --\n* -- LAPACK is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n* December 2016\n*\n* .. Scalar Arguments ..\n INTEGER INFO, LDA, LDB, N, NRHS\n* ..\n* .. Array Arguments ..\n INTEGER IPIV( * )\n DOUBLE PRECISION A( LDA, * ), B( LDB, * )\n* ..\n*\n* =====================================================================\n*\n* .. External Subroutines ..\n EXTERNAL DGETRF, DGETRS, XERBLA\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC MAX\n* ..\n* .. Executable Statements ..\n*\n* Test the input parameters.\n*\n INFO = 0\n IF( N.LT.0 ) THEN\n INFO = -1\n ELSE IF( NRHS.LT.0 ) THEN\n INFO = -2\n ELSE IF( LDA.LT.MAX( 1, N ) ) THEN\n INFO = -4\n ELSE IF( LDB.LT.MAX( 1, N ) ) THEN\n INFO = -7\n END IF\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'DGESV ', -INFO )\n RETURN\n END IF\n*\n* Compute the LU factorization of A.\n*\n CALL DGETRF( N, N, A, LDA, IPIV, INFO )\n IF( INFO.EQ.0 ) THEN\n*\n* Solve the system A*X = B, overwriting B with X.\n*\n CALL DGETRS( 'No transpose', N, NRHS, A, LDA, IPIV, B, LDB,\n $ INFO )\n END IF\n RETURN\n*\n* End of DGESV\n*\n END\n*> \\brief \\b DGETRF\n*\n* =========== DOCUMENTATION ===========\n*\n* Online html documentation available at\n* http://www.netlib.org/lapack/explore-html/\n*\n*> \\htmlonly\n*> Download DGETRF + dependencies\n*> \n*> [TGZ]\n*> \n*> [ZIP]\n*> \n*> [TXT]\n*> \\endhtmlonly\n*\n* Definition:\n* ===========\n*\n* SUBROUTINE DGETRF( M, N, A, LDA, IPIV, INFO )\n*\n* .. Scalar Arguments ..\n* INTEGER INFO, LDA, M, N\n* ..\n* .. Array Arguments ..\n* INTEGER IPIV( * )\n* DOUBLE PRECISION A( LDA, * )\n* ..\n*\n*\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*>\n*> DGETRF computes an LU factorization of a general M-by-N matrix A\n*> using partial pivoting with row interchanges.\n*>\n*> The factorization has the form\n*> A = P * L * U\n*> where P is a permutation matrix, L is lower triangular with unit\n*> diagonal elements (lower trapezoidal if m > n), and U is upper\n*> triangular (upper trapezoidal if m < n).\n*>\n*> This is the right-looking Level 3 BLAS version of the algorithm.\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in] M\n*> \\verbatim\n*> M is INTEGER\n*> The number of rows of the matrix A. M >= 0.\n*> \\endverbatim\n*>\n*> \\param[in] N\n*> \\verbatim\n*> N is INTEGER\n*> The number of columns of the matrix A. N >= 0.\n*> \\endverbatim\n*>\n*> \\param[in,out] A\n*> \\verbatim\n*> A is DOUBLE PRECISION array, dimension (LDA,N)\n*> On entry, the M-by-N matrix to be factored.\n*> On exit, the factors L and U from the factorization\n*> A = P*L*U; the unit diagonal elements of L are not stored.\n*> \\endverbatim\n*>\n*> \\param[in] LDA\n*> \\verbatim\n*> LDA is INTEGER\n*> The leading dimension of the array A. LDA >= max(1,M).\n*> \\endverbatim\n*>\n*> \\param[out] IPIV\n*> \\verbatim\n*> IPIV is INTEGER array, dimension (min(M,N))\n*> The pivot indices; for 1 <= i <= min(M,N), row i of the\n*> matrix was interchanged with row IPIV(i).\n*> \\endverbatim\n*>\n*> \\param[out] INFO\n*> \\verbatim\n*> INFO is INTEGER\n*> = 0: successful exit\n*> < 0: if INFO = -i, the i-th argument had an illegal value\n*> > 0: if INFO = i, U(i,i) is exactly zero. The factorization\n*> has been completed, but the factor U is exactly\n*> singular, and division by zero will occur if it is used\n*> to solve a system of equations.\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee\n*> \\author Univ. of California Berkeley\n*> \\author Univ. of Colorado Denver\n*> \\author NAG Ltd.\n*\n*> \\date December 2016\n*\n*> \\ingroup doubleGEcomputational\n*\n* =====================================================================\n SUBROUTINE DGETRF( M, N, A, LDA, IPIV, INFO )\n*\n* -- LAPACK computational routine (version 3.7.0) --\n* -- LAPACK is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n* December 2016\n*\n* .. Scalar Arguments ..\n INTEGER INFO, LDA, M, N\n* ..\n* .. Array Arguments ..\n INTEGER IPIV( * )\n DOUBLE PRECISION A( LDA, * )\n* ..\n*\n* =====================================================================\n*\n* .. Parameters ..\n DOUBLE PRECISION ONE\n PARAMETER ( ONE = 1.0D+0 )\n* ..\n* .. Local Scalars ..\n INTEGER I, IINFO, J, JB, NB\n* ..\n* .. External Subroutines ..\n EXTERNAL DGEMM, DGETRF2, DLASWP, DTRSM, XERBLA\n* ..\n* .. External Functions ..\n INTEGER ILAENV\n EXTERNAL ILAENV\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC MAX, MIN\n* ..\n* .. Executable Statements ..\n*\n* Test the input parameters.\n*\n INFO = 0\n IF( M.LT.0 ) THEN\n INFO = -1\n ELSE IF( N.LT.0 ) THEN\n INFO = -2\n ELSE IF( LDA.LT.MAX( 1, M ) ) THEN\n INFO = -4\n END IF\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'DGETRF', -INFO )\n RETURN\n END IF\n*\n* Quick return if possible\n*\n IF( M.EQ.0 .OR. N.EQ.0 )\n $ RETURN\n*\n* Determine the block size for this environment.\n*\n NB = ILAENV( 1, 'DGETRF', ' ', M, N, -1, -1 )\n IF( NB.LE.1 .OR. NB.GE.MIN( M, N ) ) THEN\n*\n* Use unblocked code.\n*\n CALL DGETRF2( M, N, A, LDA, IPIV, INFO )\n ELSE\n*\n* Use blocked code.\n*\n DO 20 J = 1, MIN( M, N ), NB\n JB = MIN( MIN( M, N )-J+1, NB )\n*\n* Factor diagonal and subdiagonal blocks and test for exact\n* singularity.\n*\n CALL DGETRF2( M-J+1, JB, A( J, J ), LDA, IPIV( J ), IINFO )\n*\n* Adjust INFO and the pivot indices.\n*\n IF( INFO.EQ.0 .AND. IINFO.GT.0 )\n $ INFO = IINFO + J - 1\n DO 10 I = J, MIN( M, J+JB-1 )\n IPIV( I ) = J - 1 + IPIV( I )\n 10 CONTINUE\n*\n* Apply interchanges to columns 1:J-1.\n*\n CALL DLASWP( J-1, A, LDA, J, J+JB-1, IPIV, 1 )\n*\n IF( J+JB.LE.N ) THEN\n*\n* Apply interchanges to columns J+JB:N.\n*\n CALL DLASWP( N-J-JB+1, A( 1, J+JB ), LDA, J, J+JB-1,\n $ IPIV, 1 )\n*\n* Compute block row of U.\n*\n CALL DTRSM( 'Left', 'Lower', 'No transpose', 'Unit', JB,\n $ N-J-JB+1, ONE, A( J, J ), LDA, A( J, J+JB ),\n $ LDA )\n IF( J+JB.LE.M ) THEN\n*\n* Update trailing submatrix.\n*\n CALL DGEMM( 'No transpose', 'No transpose', M-J-JB+1,\n $ N-J-JB+1, JB, -ONE, A( J+JB, J ), LDA,\n $ A( J, J+JB ), LDA, ONE, A( J+JB, J+JB ),\n $ LDA )\n END IF\n END IF\n 20 CONTINUE\n END IF\n RETURN\n*\n* End of DGETRF\n*\n END\n*> \\brief \\b DGETRF2\n*\n* =========== DOCUMENTATION ===========\n*\n* Online html documentation available at\n* http://www.netlib.org/lapack/explore-html/\n*\n* Definition:\n* ===========\n*\n* RECURSIVE SUBROUTINE DGETRF2( M, N, A, LDA, IPIV, INFO )\n*\n* .. Scalar Arguments ..\n* INTEGER INFO, LDA, M, N\n* ..\n* .. Array Arguments ..\n* INTEGER IPIV( * )\n* DOUBLE PRECISION A( LDA, * )\n* ..\n*\n*\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*>\n*> DGETRF2 computes an LU factorization of a general M-by-N matrix A\n*> using partial pivoting with row interchanges.\n*>\n*> The factorization has the form\n*> A = P * L * U\n*> where P is a permutation matrix, L is lower triangular with unit\n*> diagonal elements (lower trapezoidal if m > n), and U is upper\n*> triangular (upper trapezoidal if m < n).\n*>\n*> This is the recursive version of the algorithm. It divides\n*> the matrix into four submatrices:\n*>\n*> [ A11 | A12 ] where A11 is n1 by n1 and A22 is n2 by n2\n*> A = [ -----|----- ] with n1 = min(m,n)/2\n*> [ A21 | A22 ] n2 = n-n1\n*>\n*> [ A11 ]\n*> The subroutine calls itself to factor [ --- ],\n*> [ A12 ]\n*> [ A12 ]\n*> do the swaps on [ --- ], solve A12, update A22,\n*> [ A22 ]\n*>\n*> then calls itself to factor A22 and do the swaps on A21.\n*>\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in] M\n*> \\verbatim\n*> M is INTEGER\n*> The number of rows of the matrix A. M >= 0.\n*> \\endverbatim\n*>\n*> \\param[in] N\n*> \\verbatim\n*> N is INTEGER\n*> The number of columns of the matrix A. N >= 0.\n*> \\endverbatim\n*>\n*> \\param[in,out] A\n*> \\verbatim\n*> A is DOUBLE PRECISION array, dimension (LDA,N)\n*> On entry, the M-by-N matrix to be factored.\n*> On exit, the factors L and U from the factorization\n*> A = P*L*U; the unit diagonal elements of L are not stored.\n*> \\endverbatim\n*>\n*> \\param[in] LDA\n*> \\verbatim\n*> LDA is INTEGER\n*> The leading dimension of the array A. LDA >= max(1,M).\n*> \\endverbatim\n*>\n*> \\param[out] IPIV\n*> \\verbatim\n*> IPIV is INTEGER array, dimension (min(M,N))\n*> The pivot indices; for 1 <= i <= min(M,N), row i of the\n*> matrix was interchanged with row IPIV(i).\n*> \\endverbatim\n*>\n*> \\param[out] INFO\n*> \\verbatim\n*> INFO is INTEGER\n*> = 0: successful exit\n*> < 0: if INFO = -i, the i-th argument had an illegal value\n*> > 0: if INFO = i, U(i,i) is exactly zero. The factorization\n*> has been completed, but the factor U is exactly\n*> singular, and division by zero will occur if it is used\n*> to solve a system of equations.\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee\n*> \\author Univ. of California Berkeley\n*> \\author Univ. of Colorado Denver\n*> \\author NAG Ltd.\n*\n*> \\date June 2016\n*\n*> \\ingroup doubleGEcomputational\n*\n* =====================================================================\n RECURSIVE SUBROUTINE DGETRF2( M, N, A, LDA, IPIV, INFO )\n*\n* -- LAPACK computational routine (version 3.7.0) --\n* -- LAPACK is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n* June 2016\n*\n* .. Scalar Arguments ..\n INTEGER INFO, LDA, M, N\n* ..\n* .. Array Arguments ..\n INTEGER IPIV( * )\n DOUBLE PRECISION A( LDA, * )\n* ..\n*\n* =====================================================================\n*\n* .. Parameters ..\n DOUBLE PRECISION ONE, ZERO\n PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 )\n* ..\n* .. Local Scalars ..\n DOUBLE PRECISION SFMIN, TEMP\n INTEGER I, IINFO, N1, N2\n* ..\n* .. External Functions ..\n DOUBLE PRECISION DLAMCH\n INTEGER IDAMAX\n EXTERNAL DLAMCH, IDAMAX\n* ..\n* .. External Subroutines ..\n EXTERNAL DGEMM, DSCAL, DLASWP, DTRSM, XERBLA\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC MAX, MIN\n* ..\n* .. Executable Statements ..\n*\n* Test the input parameters\n*\n INFO = 0\n IF( M.LT.0 ) THEN\n INFO = -1\n ELSE IF( N.LT.0 ) THEN\n INFO = -2\n ELSE IF( LDA.LT.MAX( 1, M ) ) THEN\n INFO = -4\n END IF\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'DGETRF2', -INFO )\n RETURN\n END IF\n*\n* Quick return if possible\n*\n IF( M.EQ.0 .OR. N.EQ.0 )\n $ RETURN\n\n IF ( M.EQ.1 ) THEN\n*\n* Use unblocked code for one row case\n* Just need to handle IPIV and INFO\n*\n IPIV( 1 ) = 1\n IF ( A(1,1).EQ.ZERO )\n $ INFO = 1\n*\n ELSE IF( N.EQ.1 ) THEN\n*\n* Use unblocked code for one column case\n*\n*\n* Compute machine safe minimum\n*\n SFMIN = DLAMCH('S')\n*\n* Find pivot and test for singularity\n*\n I = IDAMAX( M, A( 1, 1 ), 1 )\n IPIV( 1 ) = I\n IF( A( I, 1 ).NE.ZERO ) THEN\n*\n* Apply the interchange\n*\n IF( I.NE.1 ) THEN\n TEMP = A( 1, 1 )\n A( 1, 1 ) = A( I, 1 )\n A( I, 1 ) = TEMP\n END IF\n*\n* Compute elements 2:M of the column\n*\n IF( ABS(A( 1, 1 )) .GE. SFMIN ) THEN\n CALL DSCAL( M-1, ONE / A( 1, 1 ), A( 2, 1 ), 1 )\n ELSE\n DO 10 I = 1, M-1\n A( 1+I, 1 ) = A( 1+I, 1 ) / A( 1, 1 )\n 10 CONTINUE\n END IF\n*\n ELSE\n INFO = 1\n END IF\n*\n ELSE\n*\n* Use recursive code\n*\n N1 = MIN( M, N ) / 2\n N2 = N-N1\n*\n* [ A11 ]\n* Factor [ --- ]\n* [ A21 ]\n*\n CALL DGETRF2( M, N1, A, LDA, IPIV, IINFO )\n\n IF ( INFO.EQ.0 .AND. IINFO.GT.0 )\n $ INFO = IINFO\n*\n* [ A12 ]\n* Apply interchanges to [ --- ]\n* [ A22 ]\n*\n CALL DLASWP( N2, A( 1, N1+1 ), LDA, 1, N1, IPIV, 1 )\n*\n* Solve A12\n*\n CALL DTRSM( 'L', 'L', 'N', 'U', N1, N2, ONE, A, LDA,\n $ A( 1, N1+1 ), LDA )\n*\n* Update A22\n*\n CALL DGEMM( 'N', 'N', M-N1, N2, N1, -ONE, A( N1+1, 1 ), LDA,\n $ A( 1, N1+1 ), LDA, ONE, A( N1+1, N1+1 ), LDA )\n*\n* Factor A22\n*\n CALL DGETRF2( M-N1, N2, A( N1+1, N1+1 ), LDA, IPIV( N1+1 ),\n $ IINFO )\n*\n* Adjust INFO and the pivot indices\n*\n IF ( INFO.EQ.0 .AND. IINFO.GT.0 )\n $ INFO = IINFO + N1\n DO 20 I = N1+1, MIN( M, N )\n IPIV( I ) = IPIV( I ) + N1\n 20 CONTINUE\n*\n* Apply interchanges to A21\n*\n CALL DLASWP( N1, A( 1, 1 ), LDA, N1+1, MIN( M, N), IPIV, 1 )\n*\n END IF\n RETURN\n*\n* End of DGETRF2\n*\n END\n*> \\brief \\b DGETRS\n*\n* =========== DOCUMENTATION ===========\n*\n* Online html documentation available at\n* http://www.netlib.org/lapack/explore-html/\n*\n*> \\htmlonly\n*> Download DGETRS + dependencies\n*> \n*> [TGZ]\n*> \n*> [ZIP]\n*> \n*> [TXT]\n*> \\endhtmlonly\n*\n* Definition:\n* ===========\n*\n* SUBROUTINE DGETRS( TRANS, N, NRHS, A, LDA, IPIV, B, LDB, INFO )\n*\n* .. Scalar Arguments ..\n* CHARACTER TRANS\n* INTEGER INFO, LDA, LDB, N, NRHS\n* ..\n* .. Array Arguments ..\n* INTEGER IPIV( * )\n* DOUBLE PRECISION A( LDA, * ), B( LDB, * )\n* ..\n*\n*\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*>\n*> DGETRS solves a system of linear equations\n*> A * X = B or A**T * X = B\n*> with a general N-by-N matrix A using the LU factorization computed\n*> by DGETRF.\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in] TRANS\n*> \\verbatim\n*> TRANS is CHARACTER*1\n*> Specifies the form of the system of equations:\n*> = 'N': A * X = B (No transpose)\n*> = 'T': A**T* X = B (Transpose)\n*> = 'C': A**T* X = B (Conjugate transpose = Transpose)\n*> \\endverbatim\n*>\n*> \\param[in] N\n*> \\verbatim\n*> N is INTEGER\n*> The order of the matrix A. N >= 0.\n*> \\endverbatim\n*>\n*> \\param[in] NRHS\n*> \\verbatim\n*> NRHS is INTEGER\n*> The number of right hand sides, i.e., the number of columns\n*> of the matrix B. NRHS >= 0.\n*> \\endverbatim\n*>\n*> \\param[in] A\n*> \\verbatim\n*> A is DOUBLE PRECISION array, dimension (LDA,N)\n*> The factors L and U from the factorization A = P*L*U\n*> as computed by DGETRF.\n*> \\endverbatim\n*>\n*> \\param[in] LDA\n*> \\verbatim\n*> LDA is INTEGER\n*> The leading dimension of the array A. LDA >= max(1,N).\n*> \\endverbatim\n*>\n*> \\param[in] IPIV\n*> \\verbatim\n*> IPIV is INTEGER array, dimension (N)\n*> The pivot indices from DGETRF; for 1<=i<=N, row i of the\n*> matrix was interchanged with row IPIV(i).\n*> \\endverbatim\n*>\n*> \\param[in,out] B\n*> \\verbatim\n*> B is DOUBLE PRECISION array, dimension (LDB,NRHS)\n*> On entry, the right hand side matrix B.\n*> On exit, the solution matrix X.\n*> \\endverbatim\n*>\n*> \\param[in] LDB\n*> \\verbatim\n*> LDB is INTEGER\n*> The leading dimension of the array B. LDB >= max(1,N).\n*> \\endverbatim\n*>\n*> \\param[out] INFO\n*> \\verbatim\n*> INFO is INTEGER\n*> = 0: successful exit\n*> < 0: if INFO = -i, the i-th argument had an illegal value\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee\n*> \\author Univ. of California Berkeley\n*> \\author Univ. of Colorado Denver\n*> \\author NAG Ltd.\n*\n*> \\date December 2016\n*\n*> \\ingroup doubleGEcomputational\n*\n* =====================================================================\n SUBROUTINE DGETRS( TRANS, N, NRHS, A, LDA, IPIV, B, LDB, INFO )\n*\n* -- LAPACK computational routine (version 3.7.0) --\n* -- LAPACK is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n* December 2016\n*\n* .. Scalar Arguments ..\n CHARACTER TRANS\n INTEGER INFO, LDA, LDB, N, NRHS\n* ..\n* .. Array Arguments ..\n INTEGER IPIV( * )\n DOUBLE PRECISION A( LDA, * ), B( LDB, * )\n* ..\n*\n* =====================================================================\n*\n* .. Parameters ..\n DOUBLE PRECISION ONE\n PARAMETER ( ONE = 1.0D+0 )\n* ..\n* .. Local Scalars ..\n LOGICAL NOTRAN\n* ..\n* .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\n* ..\n* .. External Subroutines ..\n EXTERNAL DLASWP, DTRSM, XERBLA\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC MAX\n* ..\n* .. Executable Statements ..\n*\n* Test the input parameters.\n*\n INFO = 0\n NOTRAN = LSAME( TRANS, 'N' )\n IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) .AND. .NOT.\n $ LSAME( TRANS, 'C' ) ) THEN\n INFO = -1\n ELSE IF( N.LT.0 ) THEN\n INFO = -2\n ELSE IF( NRHS.LT.0 ) THEN\n INFO = -3\n ELSE IF( LDA.LT.MAX( 1, N ) ) THEN\n INFO = -5\n ELSE IF( LDB.LT.MAX( 1, N ) ) THEN\n INFO = -8\n END IF\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'DGETRS', -INFO )\n RETURN\n END IF\n*\n* Quick return if possible\n*\n IF( N.EQ.0 .OR. NRHS.EQ.0 )\n $ RETURN\n*\n IF( NOTRAN ) THEN\n*\n* Solve A * X = B.\n*\n* Apply row interchanges to the right hand sides.\n*\n CALL DLASWP( NRHS, B, LDB, 1, N, IPIV, 1 )\n*\n* Solve L*X = B, overwriting B with X.\n*\n CALL DTRSM( 'Left', 'Lower', 'No transpose', 'Unit', N, NRHS,\n $ ONE, A, LDA, B, LDB )\n*\n* Solve U*X = B, overwriting B with X.\n*\n CALL DTRSM( 'Left', 'Upper', 'No transpose', 'Non-unit', N,\n $ NRHS, ONE, A, LDA, B, LDB )\n ELSE\n*\n* Solve A**T * X = B.\n*\n* Solve U**T *X = B, overwriting B with X.\n*\n CALL DTRSM( 'Left', 'Upper', 'Transpose', 'Non-unit', N, NRHS,\n $ ONE, A, LDA, B, LDB )\n*\n* Solve L**T *X = B, overwriting B with X.\n*\n CALL DTRSM( 'Left', 'Lower', 'Transpose', 'Unit', N, NRHS, ONE,\n $ A, LDA, B, LDB )\n*\n* Apply row interchanges to the solution vectors.\n*\n CALL DLASWP( NRHS, B, LDB, 1, N, IPIV, -1 )\n END IF\n*\n RETURN\n*\n* End of DGETRS\n*\n END\n*> \\brief \\b DLASWP performs a series of row interchanges on a general rectangular matrix.\n*\n* =========== DOCUMENTATION ===========\n*\n* Online html documentation available at\n* http://www.netlib.org/lapack/explore-html/\n*\n*> \\htmlonly\n*> Download DLASWP + dependencies\n*> \n*> [TGZ]\n*> \n*> [ZIP]\n*> \n*> [TXT]\n*> \\endhtmlonly\n*\n* Definition:\n* ===========\n*\n* SUBROUTINE DLASWP( N, A, LDA, K1, K2, IPIV, INCX )\n*\n* .. Scalar Arguments ..\n* INTEGER INCX, K1, K2, LDA, N\n* ..\n* .. Array Arguments ..\n* INTEGER IPIV( * )\n* DOUBLE PRECISION A( LDA, * )\n* ..\n*\n*\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*>\n*> DLASWP performs a series of row interchanges on the matrix A.\n*> One row interchange is initiated for each of rows K1 through K2 of A.\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in] N\n*> \\verbatim\n*> N is INTEGER\n*> The number of columns of the matrix A.\n*> \\endverbatim\n*>\n*> \\param[in,out] A\n*> \\verbatim\n*> A is DOUBLE PRECISION array, dimension (LDA,N)\n*> On entry, the matrix of column dimension N to which the row\n*> interchanges will be applied.\n*> On exit, the permuted matrix.\n*> \\endverbatim\n*>\n*> \\param[in] LDA\n*> \\verbatim\n*> LDA is INTEGER\n*> The leading dimension of the array A.\n*> \\endverbatim\n*>\n*> \\param[in] K1\n*> \\verbatim\n*> K1 is INTEGER\n*> The first element of IPIV for which a row interchange will\n*> be done.\n*> \\endverbatim\n*>\n*> \\param[in] K2\n*> \\verbatim\n*> K2 is INTEGER\n*> (K2-K1+1) is the number of elements of IPIV for which a row\n*> interchange will be done.\n*> \\endverbatim\n*>\n*> \\param[in] IPIV\n*> \\verbatim\n*> IPIV is INTEGER array, dimension (K1+(K2-K1)*abs(INCX))\n*> The vector of pivot indices. Only the elements in positions\n*> K1 through K1+(K2-K1)*abs(INCX) of IPIV are accessed.\n*> IPIV(K1+(K-K1)*abs(INCX)) = L implies rows K and L are to be\n*> interchanged.\n*> \\endverbatim\n*>\n*> \\param[in] INCX\n*> \\verbatim\n*> INCX is INTEGER\n*> The increment between successive values of IPIV. If INCX\n*> is negative, the pivots are applied in reverse order.\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee\n*> \\author Univ. of California Berkeley\n*> \\author Univ. of Colorado Denver\n*> \\author NAG Ltd.\n*\n*> \\date June 2017\n*\n*> \\ingroup doubleOTHERauxiliary\n*\n*> \\par Further Details:\n* =====================\n*>\n*> \\verbatim\n*>\n*> Modified by\n*> R. C. Whaley, Computer Science Dept., Univ. of Tenn., Knoxville, USA\n*> \\endverbatim\n*>\n* =====================================================================\n SUBROUTINE DLASWP( N, A, LDA, K1, K2, IPIV, INCX )\n*\n* -- LAPACK auxiliary routine (version 3.7.1) --\n* -- LAPACK is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n* June 2017\n*\n* .. Scalar Arguments ..\n INTEGER INCX, K1, K2, LDA, N\n* ..\n* .. Array Arguments ..\n INTEGER IPIV( * )\n DOUBLE PRECISION A( LDA, * )\n* ..\n*\n* =====================================================================\n*\n* .. Local Scalars ..\n INTEGER I, I1, I2, INC, IP, IX, IX0, J, K, N32\n DOUBLE PRECISION TEMP\n* ..\n* .. Executable Statements ..\n*\n* Interchange row I with row IPIV(K1+(I-K1)*abs(INCX)) for each of rows\n* K1 through K2.\n*\n IF( INCX.GT.0 ) THEN\n IX0 = K1\n I1 = K1\n I2 = K2\n INC = 1\n ELSE IF( INCX.LT.0 ) THEN\n IX0 = K1 + ( K1-K2 )*INCX\n I1 = K2\n I2 = K1\n INC = -1\n ELSE\n RETURN\n END IF\n*\n N32 = ( N / 32 )*32\n IF( N32.NE.0 ) THEN\n DO 30 J = 1, N32, 32\n IX = IX0\n DO 20 I = I1, I2, INC\n IP = IPIV( IX )\n IF( IP.NE.I ) THEN\n DO 10 K = J, J + 31\n TEMP = A( I, K )\n A( I, K ) = A( IP, K )\n A( IP, K ) = TEMP\n 10 CONTINUE\n END IF\n IX = IX + INCX\n 20 CONTINUE\n 30 CONTINUE\n END IF\n IF( N32.NE.N ) THEN\n N32 = N32 + 1\n IX = IX0\n DO 50 I = I1, I2, INC\n IP = IPIV( IX )\n IF( IP.NE.I ) THEN\n DO 40 K = N32, N\n TEMP = A( I, K )\n A( I, K ) = A( IP, K )\n A( IP, K ) = TEMP\n 40 CONTINUE\n END IF\n IX = IX + INCX\n 50 CONTINUE\n END IF\n*\n RETURN\n*\n* End of DLASWP\n*\n END\n*> \\brief \\b DTRSM\n*\n* =========== DOCUMENTATION ===========\n*\n* Online html documentation available at\n* http://www.netlib.org/lapack/explore-html/\n*\n* Definition:\n* ===========\n*\n* SUBROUTINE DTRSM(SIDE,UPLO,TRANSA,DIAG,M,N,ALPHA,A,LDA,B,LDB)\n*\n* .. Scalar Arguments ..\n* DOUBLE PRECISION ALPHA\n* INTEGER LDA,LDB,M,N\n* CHARACTER DIAG,SIDE,TRANSA,UPLO\n* ..\n* .. Array Arguments ..\n* DOUBLE PRECISION A(LDA,*),B(LDB,*)\n* ..\n*\n*\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*>\n*> DTRSM solves one of the matrix equations\n*>\n*> op( A )*X = alpha*B, or X*op( A ) = alpha*B,\n*>\n*> where alpha is a scalar, X and B are m by n matrices, A is a unit, or\n*> non-unit, upper or lower triangular matrix and op( A ) is one of\n*>\n*> op( A ) = A or op( A ) = A**T.\n*>\n*> The matrix X is overwritten on B.\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in] SIDE\n*> \\verbatim\n*> SIDE is CHARACTER*1\n*> On entry, SIDE specifies whether op( A ) appears on the left\n*> or right of X as follows:\n*>\n*> SIDE = 'L' or 'l' op( A )*X = alpha*B.\n*>\n*> SIDE = 'R' or 'r' X*op( A ) = alpha*B.\n*> \\endverbatim\n*>\n*> \\param[in] UPLO\n*> \\verbatim\n*> UPLO is CHARACTER*1\n*> On entry, UPLO specifies whether the matrix A is an upper or\n*> lower triangular matrix as follows:\n*>\n*> UPLO = 'U' or 'u' A is an upper triangular matrix.\n*>\n*> UPLO = 'L' or 'l' A is a lower triangular matrix.\n*> \\endverbatim\n*>\n*> \\param[in] TRANSA\n*> \\verbatim\n*> TRANSA is CHARACTER*1\n*> On entry, TRANSA specifies the form of op( A ) to be used in\n*> the matrix multiplication as follows:\n*>\n*> TRANSA = 'N' or 'n' op( A ) = A.\n*>\n*> TRANSA = 'T' or 't' op( A ) = A**T.\n*>\n*> TRANSA = 'C' or 'c' op( A ) = A**T.\n*> \\endverbatim\n*>\n*> \\param[in] DIAG\n*> \\verbatim\n*> DIAG is CHARACTER*1\n*> On entry, DIAG specifies whether or not A is unit triangular\n*> as follows:\n*>\n*> DIAG = 'U' or 'u' A is assumed to be unit triangular.\n*>\n*> DIAG = 'N' or 'n' A is not assumed to be unit\n*> triangular.\n*> \\endverbatim\n*>\n*> \\param[in] M\n*> \\verbatim\n*> M is INTEGER\n*> On entry, M specifies the number of rows of B. M must be at\n*> least zero.\n*> \\endverbatim\n*>\n*> \\param[in] N\n*> \\verbatim\n*> N is INTEGER\n*> On entry, N specifies the number of columns of B. N must be\n*> at least zero.\n*> \\endverbatim\n*>\n*> \\param[in] ALPHA\n*> \\verbatim\n*> ALPHA is DOUBLE PRECISION.\n*> On entry, ALPHA specifies the scalar alpha. When alpha is\n*> zero then A is not referenced and B need not be set before\n*> entry.\n*> \\endverbatim\n*>\n*> \\param[in] A\n*> \\verbatim\n*> A is DOUBLE PRECISION array, dimension ( LDA, k ),\n*> where k is m when SIDE = 'L' or 'l'\n*> and k is n when SIDE = 'R' or 'r'.\n*> Before entry with UPLO = 'U' or 'u', the leading k by k\n*> upper triangular part of the array A must contain the upper\n*> triangular matrix and the strictly lower triangular part of\n*> A is not referenced.\n*> Before entry with UPLO = 'L' or 'l', the leading k by k\n*> lower triangular part of the array A must contain the lower\n*> triangular matrix and the strictly upper triangular part of\n*> A is not referenced.\n*> Note that when DIAG = 'U' or 'u', the diagonal elements of\n*> A are not referenced either, but are assumed to be unity.\n*> \\endverbatim\n*>\n*> \\param[in] LDA\n*> \\verbatim\n*> LDA is INTEGER\n*> On entry, LDA specifies the first dimension of A as declared\n*> in the calling (sub) program. When SIDE = 'L' or 'l' then\n*> LDA must be at least max( 1, m ), when SIDE = 'R' or 'r'\n*> then LDA must be at least max( 1, n ).\n*> \\endverbatim\n*>\n*> \\param[in,out] B\n*> \\verbatim\n*> B is DOUBLE PRECISION array, dimension ( LDB, N )\n*> Before entry, the leading m by n part of the array B must\n*> contain the right-hand side matrix B, and on exit is\n*> overwritten by the solution matrix X.\n*> \\endverbatim\n*>\n*> \\param[in] LDB\n*> \\verbatim\n*> LDB is INTEGER\n*> On entry, LDB specifies the first dimension of B as declared\n*> in the calling (sub) program. LDB must be at least\n*> max( 1, m ).\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee\n*> \\author Univ. of California Berkeley\n*> \\author Univ. of Colorado Denver\n*> \\author NAG Ltd.\n*\n*> \\date December 2016\n*\n*> \\ingroup double_blas_level3\n*\n*> \\par Further Details:\n* =====================\n*>\n*> \\verbatim\n*>\n*> Level 3 Blas routine.\n*>\n*>\n*> -- Written on 8-February-1989.\n*> Jack Dongarra, Argonne National Laboratory.\n*> Iain Duff, AERE Harwell.\n*> Jeremy Du Croz, Numerical Algorithms Group Ltd.\n*> Sven Hammarling, Numerical Algorithms Group Ltd.\n*> \\endverbatim\n*>\n* =====================================================================\n SUBROUTINE DTRSM(SIDE,UPLO,TRANSA,DIAG,M,N,ALPHA,A,LDA,B,LDB)\n*\n* -- Reference BLAS level3 routine (version 3.7.0) --\n* -- Reference BLAS is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n* December 2016\n*\n* .. Scalar Arguments ..\n DOUBLE PRECISION ALPHA\n INTEGER LDA,LDB,M,N\n CHARACTER DIAG,SIDE,TRANSA,UPLO\n* ..\n* .. Array Arguments ..\n DOUBLE PRECISION A(LDA,*),B(LDB,*)\n* ..\n*\n* =====================================================================\n*\n* .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\n* ..\n* .. External Subroutines ..\n EXTERNAL XERBLA\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC MAX\n* ..\n* .. Local Scalars ..\n DOUBLE PRECISION TEMP\n INTEGER I,INFO,J,K,NROWA\n LOGICAL LSIDE,NOUNIT,UPPER\n* ..\n* .. Parameters ..\n DOUBLE PRECISION ONE,ZERO\n PARAMETER (ONE=1.0D+0,ZERO=0.0D+0)\n* ..\n*\n* Test the input parameters.\n*\n LSIDE = LSAME(SIDE,'L')\n IF (LSIDE) THEN\n NROWA = M\n ELSE\n NROWA = N\n END IF\n NOUNIT = LSAME(DIAG,'N')\n UPPER = LSAME(UPLO,'U')\n*\n INFO = 0\n IF ((.NOT.LSIDE) .AND. (.NOT.LSAME(SIDE,'R'))) THEN\n INFO = 1\n ELSE IF ((.NOT.UPPER) .AND. (.NOT.LSAME(UPLO,'L'))) THEN\n INFO = 2\n ELSE IF ((.NOT.LSAME(TRANSA,'N')) .AND.\n + (.NOT.LSAME(TRANSA,'T')) .AND.\n + (.NOT.LSAME(TRANSA,'C'))) THEN\n INFO = 3\n ELSE IF ((.NOT.LSAME(DIAG,'U')) .AND. (.NOT.LSAME(DIAG,'N'))) THEN\n INFO = 4\n ELSE IF (M.LT.0) THEN\n INFO = 5\n ELSE IF (N.LT.0) THEN\n INFO = 6\n ELSE IF (LDA.LT.MAX(1,NROWA)) THEN\n INFO = 9\n ELSE IF (LDB.LT.MAX(1,M)) THEN\n INFO = 11\n END IF\n IF (INFO.NE.0) THEN\n CALL XERBLA('DTRSM ',INFO)\n RETURN\n END IF\n*\n* Quick return if possible.\n*\n IF (M.EQ.0 .OR. N.EQ.0) RETURN\n*\n* And when alpha.eq.zero.\n*\n IF (ALPHA.EQ.ZERO) THEN\n DO 20 J = 1,N\n DO 10 I = 1,M\n B(I,J) = ZERO\n 10 CONTINUE\n 20 CONTINUE\n RETURN\n END IF\n*\n* Start the operations.\n*\n IF (LSIDE) THEN\n IF (LSAME(TRANSA,'N')) THEN\n*\n* Form B := alpha*inv( A )*B.\n*\n IF (UPPER) THEN\n DO 60 J = 1,N\n IF (ALPHA.NE.ONE) THEN\n DO 30 I = 1,M\n B(I,J) = ALPHA*B(I,J)\n 30 CONTINUE\n END IF\n DO 50 K = M,1,-1\n IF (B(K,J).NE.ZERO) THEN\n IF (NOUNIT) B(K,J) = B(K,J)/A(K,K)\n DO 40 I = 1,K - 1\n B(I,J) = B(I,J) - B(K,J)*A(I,K)\n 40 CONTINUE\n END IF\n 50 CONTINUE\n 60 CONTINUE\n ELSE\n DO 100 J = 1,N\n IF (ALPHA.NE.ONE) THEN\n DO 70 I = 1,M\n B(I,J) = ALPHA*B(I,J)\n 70 CONTINUE\n END IF\n DO 90 K = 1,M\n IF (B(K,J).NE.ZERO) THEN\n IF (NOUNIT) B(K,J) = B(K,J)/A(K,K)\n DO 80 I = K + 1,M\n B(I,J) = B(I,J) - B(K,J)*A(I,K)\n 80 CONTINUE\n END IF\n 90 CONTINUE\n 100 CONTINUE\n END IF\n ELSE\n*\n* Form B := alpha*inv( A**T )*B.\n*\n IF (UPPER) THEN\n DO 130 J = 1,N\n DO 120 I = 1,M\n TEMP = ALPHA*B(I,J)\n DO 110 K = 1,I - 1\n TEMP = TEMP - A(K,I)*B(K,J)\n 110 CONTINUE\n IF (NOUNIT) TEMP = TEMP/A(I,I)\n B(I,J) = TEMP\n 120 CONTINUE\n 130 CONTINUE\n ELSE\n DO 160 J = 1,N\n DO 150 I = M,1,-1\n TEMP = ALPHA*B(I,J)\n DO 140 K = I + 1,M\n TEMP = TEMP - A(K,I)*B(K,J)\n 140 CONTINUE\n IF (NOUNIT) TEMP = TEMP/A(I,I)\n B(I,J) = TEMP\n 150 CONTINUE\n 160 CONTINUE\n END IF\n END IF\n ELSE\n IF (LSAME(TRANSA,'N')) THEN\n*\n* Form B := alpha*B*inv( A ).\n*\n IF (UPPER) THEN\n DO 210 J = 1,N\n IF (ALPHA.NE.ONE) THEN\n DO 170 I = 1,M\n B(I,J) = ALPHA*B(I,J)\n 170 CONTINUE\n END IF\n DO 190 K = 1,J - 1\n IF (A(K,J).NE.ZERO) THEN\n DO 180 I = 1,M\n B(I,J) = B(I,J) - A(K,J)*B(I,K)\n 180 CONTINUE\n END IF\n 190 CONTINUE\n IF (NOUNIT) THEN\n TEMP = ONE/A(J,J)\n DO 200 I = 1,M\n B(I,J) = TEMP*B(I,J)\n 200 CONTINUE\n END IF\n 210 CONTINUE\n ELSE\n DO 260 J = N,1,-1\n IF (ALPHA.NE.ONE) THEN\n DO 220 I = 1,M\n B(I,J) = ALPHA*B(I,J)\n 220 CONTINUE\n END IF\n DO 240 K = J + 1,N\n IF (A(K,J).NE.ZERO) THEN\n DO 230 I = 1,M\n B(I,J) = B(I,J) - A(K,J)*B(I,K)\n 230 CONTINUE\n END IF\n 240 CONTINUE\n IF (NOUNIT) THEN\n TEMP = ONE/A(J,J)\n DO 250 I = 1,M\n B(I,J) = TEMP*B(I,J)\n 250 CONTINUE\n END IF\n 260 CONTINUE\n END IF\n ELSE\n*\n* Form B := alpha*B*inv( A**T ).\n*\n IF (UPPER) THEN\n DO 310 K = N,1,-1\n IF (NOUNIT) THEN\n TEMP = ONE/A(K,K)\n DO 270 I = 1,M\n B(I,K) = TEMP*B(I,K)\n 270 CONTINUE\n END IF\n DO 290 J = 1,K - 1\n IF (A(J,K).NE.ZERO) THEN\n TEMP = A(J,K)\n DO 280 I = 1,M\n B(I,J) = B(I,J) - TEMP*B(I,K)\n 280 CONTINUE\n END IF\n 290 CONTINUE\n IF (ALPHA.NE.ONE) THEN\n DO 300 I = 1,M\n B(I,K) = ALPHA*B(I,K)\n 300 CONTINUE\n END IF\n 310 CONTINUE\n ELSE\n DO 360 K = 1,N\n IF (NOUNIT) THEN\n TEMP = ONE/A(K,K)\n DO 320 I = 1,M\n B(I,K) = TEMP*B(I,K)\n 320 CONTINUE\n END IF\n DO 340 J = K + 1,N\n IF (A(J,K).NE.ZERO) THEN\n TEMP = A(J,K)\n DO 330 I = 1,M\n B(I,J) = B(I,J) - TEMP*B(I,K)\n 330 CONTINUE\n END IF\n 340 CONTINUE\n IF (ALPHA.NE.ONE) THEN\n DO 350 I = 1,M\n B(I,K) = ALPHA*B(I,K)\n 350 CONTINUE\n END IF\n 360 CONTINUE\n END IF\n END IF\n END IF\n*\n RETURN\n*\n* End of DTRSM .\n*\n END\n*> \\brief \\b IDAMAX\n*\n* =========== DOCUMENTATION ===========\n*\n* Online html documentation available at\n* http://www.netlib.org/lapack/explore-html/\n*\n* Definition:\n* ===========\n*\n* INTEGER FUNCTION IDAMAX(N,DX,INCX)\n*\n* .. Scalar Arguments ..\n* INTEGER INCX,N\n* ..\n* .. Array Arguments ..\n* DOUBLE PRECISION DX(*)\n* ..\n*\n*\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*>\n*> IDAMAX finds the index of the first element having maximum absolute value.\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in] N\n*> \\verbatim\n*> N is INTEGER\n*> number of elements in input vector(s)\n*> \\endverbatim\n*>\n*> \\param[in] DX\n*> \\verbatim\n*> DX is DOUBLE PRECISION array, dimension ( 1 + ( N - 1 )*abs( INCX ) )\n*> \\endverbatim\n*>\n*> \\param[in] INCX\n*> \\verbatim\n*> INCX is INTEGER\n*> storage spacing between elements of DX\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee\n*> \\author Univ. of California Berkeley\n*> \\author Univ. of Colorado Denver\n*> \\author NAG Ltd.\n*\n*> \\date November 2017\n*\n*> \\ingroup aux_blas\n*\n*> \\par Further Details:\n* =====================\n*>\n*> \\verbatim\n*>\n*> jack dongarra, linpack, 3/11/78.\n*> modified 3/93 to return if incx .le. 0.\n*> modified 12/3/93, array(1) declarations changed to array(*)\n*> \\endverbatim\n*>\n* =====================================================================\n INTEGER FUNCTION IDAMAX(N,DX,INCX)\n*\n* -- Reference BLAS level1 routine (version 3.8.0) --\n* -- Reference BLAS is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n* November 2017\n*\n* .. Scalar Arguments ..\n INTEGER INCX,N\n* ..\n* .. Array Arguments ..\n DOUBLE PRECISION DX(*)\n* ..\n*\n* =====================================================================\n*\n* .. Local Scalars ..\n DOUBLE PRECISION DMAX\n INTEGER I,IX\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC DABS\n* ..\n IDAMAX = 0\n IF (N.LT.1 .OR. INCX.LE.0) RETURN\n IDAMAX = 1\n IF (N.EQ.1) RETURN\n IF (INCX.EQ.1) THEN\n*\n* code for increment equal to 1\n*\n DMAX = DABS(DX(1))\n DO I = 2,N\n IF (DABS(DX(I)).GT.DMAX) THEN\n IDAMAX = I\n DMAX = DABS(DX(I))\n END IF\n END DO\n ELSE\n*\n* code for increment not equal to 1\n*\n IX = 1\n DMAX = DABS(DX(1))\n IX = IX + INCX\n DO I = 2,N\n IF (DABS(DX(IX)).GT.DMAX) THEN\n IDAMAX = I\n DMAX = DABS(DX(IX))\n END IF\n IX = IX + INCX\n END DO\n END IF\n RETURN\n END\n", "meta": {"hexsha": "d0626eff1f595d380552c6bb6a91144d809ffcf0", "size": 46186, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "clean_src/dgesvpackage.f", "max_stars_repo_name": "noctildon/pyBigstick", "max_stars_repo_head_hexsha": "a6d8b149d92da11a5f9564618eb08b7440823ea2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "clean_src/dgesvpackage.f", "max_issues_repo_name": "noctildon/pyBigstick", "max_issues_repo_head_hexsha": "a6d8b149d92da11a5f9564618eb08b7440823ea2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "clean_src/dgesvpackage.f", "max_forks_repo_name": "noctildon/pyBigstick", "max_forks_repo_head_hexsha": "a6d8b149d92da11a5f9564618eb08b7440823ea2", "max_forks_repo_licenses": ["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.7560096154, "max_line_length": 111, "alphanum_fraction": 0.4701857706, "num_tokens": 13590, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9161096135894201, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6753176795200501}} {"text": " INTEGER FUNCTION ignbin(n,pp)\nC**********************************************************************\nC\nC INTEGER FUNCTION IGNBIN( N, PP )\nC\nC GENerate BINomial random deviate\nC\nC\nC Function\nC\nC\nC Generates a single random deviate from a binomial\nC distribution whose number of trials is N and whose\nC probability of an event in each trial is P.\nC\nC\nC Arguments\nC\nC\nC N --> The number of trials in the binomial distribution\nC from which a random deviate is to be generated.\nC INTEGER N\nC JJV (N >= 0)\nC\nC PP --> The probability of an event in each trial of the\nC binomial distribution from which a random deviate\nC is to be generated.\nC DOUBLE PRECISION PP\nC JJV (0.0 <= pp <= 1.0)\nC\nC IGNBIN <-- A random deviate yielding the number of events\nC from N independent trials, each of which has\nC a probability of event P.\nC INTEGER IGNBIN\nC\nC\nC Note\nC\nC\nC Uses RANF so the value of the seeds, ISEED1 and ISEED2 must be set\nC by a call similar to the following\nC DUM = RANSET( ISEED1, ISEED2 )\nC\nC\nC Method\nC\nC\nC This is algorithm BTPE from:\nC\nC Kachitvichyanukul, V. and Schmeiser, B. W.\nC\nC Binomial Random Variate Generation.\nC Communications of the ACM, 31, 2\nC (February, 1988) 216.\nC\nC**********************************************************************\nC SUBROUTINE BTPEC(N,PP,ISEED,JX)\nC\nC BINOMIAL RANDOM VARIATE GENERATOR\nC MEAN .LT. 30 -- INVERSE CDF\nC MEAN .GE. 30 -- ALGORITHM BTPE: ACCEPTANCE-REJECTION VIA\nC FOUR REGION COMPOSITION. THE FOUR REGIONS ARE A TRIANGLE\nC (SYMMETRIC IN THE CENTER), A PAIR OF PARALLELOGRAMS (ABOVE\nC THE TRIANGLE), AND EXPONENTIAL LEFT AND RIGHT TAILS.\nC\nC BTPE REFERS TO BINOMIAL-TRIANGLE-PARALLELOGRAM-EXPONENTIAL.\nC BTPEC REFERS TO BTPE AND \"COMBINED.\" THUS BTPE IS THE\nC RESEARCH AND BTPEC IS THE IMPLEMENTATION OF A COMPLETE\nC USABLE ALGORITHM.\nC REFERENCE: VORATAS KACHITVICHYANUKUL AND BRUCE SCHMEISER,\nC \"BINOMIAL RANDOM VARIATE GENERATION,\"\nC COMMUNICATIONS OF THE ACM, FORTHCOMING\nC WRITTEN: SEPTEMBER 1980.\nC LAST REVISED: MAY 1985, JULY 1987\nC REQUIRED SUBPROGRAM: RAND() -- A UNIFORM (0,1) RANDOM NUMBER\nC GENERATOR\nC ARGUMENTS\nC\nC N : NUMBER OF BERNOULLI TRIALS (INPUT)\nC PP : PROBABILITY OF SUCCESS IN EACH TRIAL (INPUT)\nC ISEED: RANDOM NUMBER SEED (INPUT AND OUTPUT)\nC JX: RANDOMLY GENERATED OBSERVATION (OUTPUT)\nC\nC VARIABLES\nC PSAVE: VALUE OF PP FROM THE LAST CALL TO BTPEC\nC NSAVE: VALUE OF N FROM THE LAST CALL TO BTPEC\nC XNP: VALUE OF THE MEAN FROM THE LAST CALL TO BTPEC\nC\nC P: PROBABILITY USED IN THE GENERATION PHASE OF BTPEC\nC FFM: TEMPORARY VARIABLE EQUAL TO XNP + P\nC M: INTEGER VALUE OF THE CURRENT MODE\nC FM: FLOATING POINT VALUE OF THE CURRENT MODE\nC XNPQ: TEMPORARY VARIABLE USED IN SETUP AND SQUEEZING STEPS\nC P1: AREA OF THE TRIANGLE\nC C: HEIGHT OF THE PARALLELOGRAMS\nC XM: CENTER OF THE TRIANGLE\nC XL: LEFT END OF THE TRIANGLE\nC XR: RIGHT END OF THE TRIANGLE\nC AL: TEMPORARY VARIABLE\nC XLL: RATE FOR THE LEFT EXPONENTIAL TAIL\nC XLR: RATE FOR THE RIGHT EXPONENTIAL TAIL\nC P2: AREA OF THE PARALLELOGRAMS\nC P3: AREA OF THE LEFT EXPONENTIAL TAIL\nC P4: AREA OF THE RIGHT EXPONENTIAL TAIL\nC U: A U(0,P4) RANDOM VARIATE USED FIRST TO SELECT ONE OF THE\nC FOUR REGIONS AND THEN CONDITIONALLY TO GENERATE A VALUE\nC FROM THE REGION\nC V: A U(0,1) RANDOM NUMBER USED TO GENERATE THE RANDOM VALUE\nC (REGION 1) OR TRANSFORMED INTO THE VARIATE TO ACCEPT OR\nC REJECT THE CANDIDATE VALUE\nC IX: INTEGER CANDIDATE VALUE\nC X: PRELIMINARY CONTINUOUS CANDIDATE VALUE IN REGION 2 LOGIC\nC AND A FLOATING POINT IX IN THE ACCEPT/REJECT LOGIC\nC K: ABSOLUTE VALUE OF (IX-M)\nC F: THE HEIGHT OF THE SCALED DENSITY FUNCTION USED IN THE\nC ACCEPT/REJECT DECISION WHEN BOTH M AND IX ARE SMALL\nC ALSO USED IN THE INVERSE TRANSFORMATION\nC R: THE RATIO P/Q\nC G: CONSTANT USED IN CALCULATION OF PROBABILITY\nC MP: MODE PLUS ONE, THE LOWER INDEX FOR EXPLICIT CALCULATION\nC OF F WHEN IX IS GREATER THAN M\nC IX1: CANDIDATE VALUE PLUS ONE, THE LOWER INDEX FOR EXPLICIT\nC CALCULATION OF F WHEN IX IS LESS THAN M\nC I: INDEX FOR EXPLICIT CALCULATION OF F FOR BTPE\nC AMAXP: MAXIMUM ERROR OF THE LOGARITHM OF NORMAL BOUND\nC YNORM: LOGARITHM OF NORMAL BOUND\nC ALV: NATURAL LOGARITHM OF THE ACCEPT/REJECT VARIATE V\nC\nC X1,F1,Z,W,Z2,X2,F2, AND W2 ARE TEMPORARY VARIABLES TO BE\nC USED IN THE FINAL ACCEPT/REJECT TEST\nC\nC QN: PROBABILITY OF NO SUCCESS IN N TRIALS\nC\nC REMARK\nC IX AND JX COULD LOGICALLY BE THE SAME VARIABLE, WHICH WOULD\nC SAVE A MEMORY POSITION AND A LINE OF CODE. HOWEVER, SOME\nC COMPILERS (E.G.,CDC MNF) OPTIMIZE BETTER WHEN THE ARGUMENTS\nC ARE NOT INVOLVED.\nC\nC ISEED NEEDS TO BE DOUBLE PRECISION IF THE IMSL ROUTINE\nC GGUBFS IS USED TO GENERATE UNIFORM RANDOM NUMBER, OTHERWISE\nC TYPE OF ISEED SHOULD BE DICTATED BY THE UNIFORM GENERATOR\nC\nC**********************************************************************\n\nC\nC\nC\nC*****DETERMINE APPROPRIATE ALGORITHM AND WHETHER SETUP IS NECESSARY\nC\nC ..\nC .. Scalar Arguments ..\n DOUBLE PRECISION pp\n INTEGER n\nC ..\nC .. Local Scalars ..\n DOUBLE PRECISION al,alv,amaxp,c,f,f1,f2,ffm,fm,g,p,p1,p2,p3,p4,\n + psave,q,qn,r,u,\n + v,w,w2,x,x1,x2,xl,xll,xlr,xm,xnp,xnpq,xr,ynorm,z,z2\n INTEGER i,ix,ix1,k,m,mp,nsave\nC ..\nC .. External Functions ..\n DOUBLE PRECISION ranf\n EXTERNAL ranf\nC ..\nC .. Intrinsic Functions ..\n INTRINSIC abs,log,dmin1,iabs,int,sqrt\nC JJV ..\nC JJV .. Save statement ..\n SAVE p,q,m,fm,xnp,xnpq,p1,xm,xl,xr,c,xll,xlr,p2,p3,p4,qn,r,g,\n + psave,nsave\nC JJV I am including the variables in data statements\nC ..\nC .. Data statements ..\nC JJV made these ridiculous starting values - the hope is that\nC JJV no one will call this the first time with them as args\n DATA psave,nsave/-1.0E37,-214748365/\nC ..\nC .. Executable Statements ..\n IF (pp.NE.psave) GO TO 10\n IF (n.NE.nsave) GO TO 20\n IF (xnp-30.) 150,30,30\nC\nC*****SETUP, PERFORM ONLY WHEN PARAMETERS CHANGE\nC\n\nC JJV added the argument checker - involved only renaming 10\nC JJV and 20 to the checkers and adding checkers\nC JJV Only remaining problem - if called initially with the\nC JJV initial values of psave and nsave, it will hang\n 10 continue\n psave = pp\n p = dmin1(psave,1.-psave)\n q = 1. - p\n 20 continue\n xnp = n*p\n nsave = n\n IF (xnp.LT.30.) GO TO 140\n ffm = xnp + p\n m = ffm\n fm = m\n xnpq = xnp*q\n p1 = int(2.195*sqrt(xnpq)-4.6*q) + 0.5\n xm = fm + 0.5\n xl = xm - p1\n xr = xm + p1\n c = 0.134 + 20.5/ (15.3+fm)\n al = (ffm-xl)/ (ffm-xl*p)\n xll = al* (1.+.5*al)\n al = (xr-ffm)/ (xr*q)\n xlr = al* (1.+.5*al)\n p2 = p1* (1.+c+c)\n p3 = p2 + c/xll\n p4 = p3 + c/xlr\nC WRITE(6,100) N,P,P1,P2,P3,P4,XL,XR,XM,FM\nC 100 FORMAT(I15,4F18.7/5F18.7)\nC\nC*****GENERATE VARIATE\nC\n 30 u = ranf()*p4\n v = ranf()\nC\nC TRIANGULAR REGION\nC\n IF (u.GT.p1) GO TO 40\n ix = xm - p1*v + u\n GO TO 170\nC\nC PARALLELOGRAM REGION\nC\n 40 IF (u.GT.p2) GO TO 50\n x = xl + (u-p1)/c\n v = v*c + 1. - abs(xm-x)/p1\n IF (v.GT.1. .OR. v.LE.0.) GO TO 30\n ix = x\n GO TO 70\nC\nC LEFT TAIL\nC\n 50 IF (u.GT.p3) GO TO 60\n ix = xl + log(v)/xll\n IF (ix.LT.0) GO TO 30\n v = v* (u-p2)*xll\n GO TO 70\nC\nC RIGHT TAIL\nC\n 60 ix = xr - log(v)/xlr\n IF (ix.GT.n) GO TO 30\n v = v* (u-p3)*xlr\nC\nC*****DETERMINE APPROPRIATE WAY TO PERFORM ACCEPT/REJECT TEST\nC\n 70 k = iabs(ix-m)\n IF (k.GT.20 .AND. k.LT.xnpq/2-1) GO TO 130\nC\nC EXPLICIT EVALUATION\nC\n f = 1.0\n r = p/q\n g = (n+1)*r\n IF (m-ix) 80,120,100\n 80 mp = m + 1\n DO 90 i = mp,ix\n f = f* (g/i-r)\n 90 CONTINUE\n GO TO 120\n\n 100 ix1 = ix + 1\n DO 110 i = ix1,m\n f = f/ (g/i-r)\n 110 CONTINUE\n 120 IF (v-f) 170,170,30\nC\nC SQUEEZING USING UPPER AND LOWER BOUNDS ON LOG(F(X))\nC\n 130 amaxp = (k/xnpq)* ((k* (k/3.+.625)+.1666666666666)/xnpq+.5)\n ynorm = -k*k/ (2.*xnpq)\n alv = log(v)\n IF (alv.LT.ynorm-amaxp) GO TO 170\n IF (alv.GT.ynorm+amaxp) GO TO 30\nC\nC STIRLING'S FORMULA TO MACHINE ACCURACY FOR\nC THE FINAL ACCEPTANCE/REJECTION TEST\nC\n x1 = ix + 1\n f1 = fm + 1.\n z = n + 1 - fm\n w = n - ix + 1.\n z2 = z*z\n x2 = x1*x1\n f2 = f1*f1\n w2 = w*w\n IF (alv- (xm*log(f1/x1)+ (n-m+.5)*log(z/w)+ (ix-\n + m)*log(w*p/ (x1*q))+ (13860.- (462.- (132.- (99.-\n + 140./f2)/f2)/f2)/f2)/f1/166320.+ (13860.- (462.- (132.- (99.-\n + 140./z2)/z2)/z2)/z2)/z/166320.+ (13860.- (462.- (132.- (99.-\n + 140./x2)/x2)/x2)/x2)/x1/166320.+ (13860.- (462.- (132.- (99.-\n + 140./w2)/w2)/w2)/w2)/w/166320.)) 170,170,30\nC\nC INVERSE CDF LOGIC FOR MEAN LESS THAN 30\nC\n 140 qn = q**n\n r = p/q\n g = r* (n+1)\n 150 ix = 0\n f = qn\n u = ranf()\n 160 IF (u.LT.f) GO TO 170\n IF (ix.GT.110) GO TO 150\n u = u - f\n ix = ix + 1\n f = f* (g/ix-r)\n GO TO 160\n\n 170 IF (psave.GT.0.5) ix = n - ix\n ignbin = ix\n RETURN\n\n END\n", "meta": {"hexsha": "295e4f43300c471992bf2f97b9971bb39fa436f0", "size": 10021, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/rnd/ignbin.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/ignbin.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/ignbin.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": 31.2180685358, "max_line_length": 72, "alphanum_fraction": 0.5700029937, "num_tokens": 3460, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096044278532, "lm_q2_score": 0.7371581568543044, "lm_q1q2_score": 0.6753176674765622}} {"text": "program main\n implicit none\n integer, parameter :: dp = selected_real_kind(8)\n real(dp), parameter :: pi = acos(-1.d0)\n real(dp) :: epsilonA = 1.d0, epsilonB = 4.d0, tAA = .5d0, tBB = .25d0, k, EA, EB\n\n open(unit = 1, file = '4-E-k.txt', status = 'unknown')\n k = -pi\n do while (k <= pi)\n EA = epsilonA - 2.d0 * tAA * cos(k)\n EB = epsilonB - 2.d0 * tBB * cos(k)\n write(1,'(3f20.8)') k, EA, EB\n k = k + 1.d-2\n end do\n close(1)\nend program main", "meta": {"hexsha": "cdc19569238004ad6991a39b6c27c8340fe4d9e3", "size": 496, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Assignment-6/4-E-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/4-E-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/4-E-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": 31.0, "max_line_length": 84, "alphanum_fraction": 0.5262096774, "num_tokens": 187, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818865, "lm_q2_score": 0.743168019989179, "lm_q1q2_score": 0.6752557670682837}} {"text": "!\n!\n! ------------------------------------------------------------------\n! L U L U\n! ------------------------------------------------------------------\n!\n SUBROUTINE LULU(A, L, U, NDIM) \n!-----------------------------------------------\n! M o d u l e s \n!-----------------------------------------------\n USE vast_kind_param, ONLY: DOUBLE \n!\n! LU DECOMPOSITION OF MATRIX A\n!\n! A = L * U\n!\n! WHERE L IS A LOWER TRIANGULAR MATRIX WITH A\n! UNIT DIAGONAL AND U IS AN UPPER DIAGONAL\n!\n! L AND U ARE STORED AS ONE DIMENSIONAL ARRAYS\n!\n! L(I,J) = L(I*(I-1)/2 + J ) ( I .GE. J )\n!\n! U(I,J) = U(J*(J-1)/2 + I ) ( J .GE. I )\n!\n! THIS ADRESSING SCHEMES SUPPORTS VECTORIZATION OVER COLUMNS\n! FOR L AND OVER ROWS FOR U .\n!\n!\n! NO PIVOTING IS DONE HERE , SO THE SCHEME GOES :\n!\n! LOOP OVER R=1, NDIM\n! LOOP OVER J = R, NDIM\n! U(R,J) = A(R,J) - SUM(K=1,R-1) L(R,K) * U(K,J)\n! END OF LOOP OVER J\n!\n! LOOP OVER I = R+1, NDIM\n! L(I,R) = (A(I,R) - SUM(K=1,R-1)L(I,K) * U(K,R) ) /U(R,R)\n! END OF LOOP OVER I\n! END OF LOOP OVER R\n!\n! JEPPE OLSEN , OCTOBER 1988\n!\n!...Translated by Pacific-Sierra Research 77to90 4.3E 14:49:11 11/20/01 \n!...Switches: \n!-----------------------------------------------\n! I n t e r f a c e B l o c k s\n!-----------------------------------------------\n USE inprod_I \n USE prsym_I \n IMPLICIT NONE\n!-----------------------------------------------\n! D u m m y A r g u m e n t s\n!-----------------------------------------------\n INTEGER :: NDIM \n REAL(DOUBLE) , INTENT(IN) :: A(NDIM,NDIM) \n REAL(DOUBLE) :: L(*) \n REAL(DOUBLE) :: U(*) \n!-----------------------------------------------\n! L o c a l V a r i a b l e s\n!-----------------------------------------------\n INTEGER :: R, J, I, NTEST \n REAL(DOUBLE) :: XFACI \n!-----------------------------------------------\n!\n!\n DO R = 1, NDIM \n!\n DO J = R, NDIM \n U(J*(J-1)/2+R) = A(R,J) - INPROD(L(R*(R-1)/2+1),U(J*(J-1)/2+1),R-1) \n END DO \n!\n XFACI = 1.0D0/U(R*(R+1)/2) \n L(R*(R+1)/2) = 1.0D0 \n DO I = R + 1, NDIM \n L(I*(I-1)/2+R) = (A(I,R)-INPROD(L(I*(I-1)/2+1),U(R*(R-1)/2+1),R-1))&\n *XFACI \n END DO \n!\n END DO \n!\n NTEST = 0 \n IF (NTEST /= 0) THEN \n WRITE (6, *) ' L MATRIX ' \n CALL PRSYM (L, NDIM) \n WRITE (6, *) ' U MATRIX ( TRANSPOSED ) ' \n CALL PRSYM (U, NDIM) \n ENDIF \n!\n RETURN \n END SUBROUTINE LULU \n", "meta": {"hexsha": "c6861ab05505991144b53f6afd69cf2c1c35ae9c", "size": 2579, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src90/appl/mpi_biotr_tr/lulu.f90", "max_stars_repo_name": "mansour2014/ATSP2K_plus", "max_stars_repo_head_hexsha": "30842b9f086d1e497aeb778e2a352d1e8e520ec3", "max_stars_repo_licenses": ["BSD-4-Clause-UC"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-07-21T14:03:39.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-21T14:03:39.000Z", "max_issues_repo_path": "src90/appl/mpi_biotr_tr/lulu.f90", "max_issues_repo_name": "mzmansour/ATSP2K_plus", "max_issues_repo_head_hexsha": "30842b9f086d1e497aeb778e2a352d1e8e520ec3", "max_issues_repo_licenses": ["BSD-4-Clause-UC"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src90/appl/mpi_biotr_tr/lulu.f90", "max_forks_repo_name": "mzmansour/ATSP2K_plus", "max_forks_repo_head_hexsha": "30842b9f086d1e497aeb778e2a352d1e8e520ec3", "max_forks_repo_licenses": ["BSD-4-Clause-UC"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.0326086957, "max_line_length": 80, "alphanum_fraction": 0.3621558744, "num_tokens": 846, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178994073576, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6752557600607574}} {"text": "c------------------------------------------------------------------------------\nc\nc\n SUBROUTINE voigt(x,y,u,v)\nc\nc\nc\nc this routine computes the complex probability function w(z)\nc \nc w(z) = exp(-z**2) * erfc(-iz) = u(x,y) + iv(x,y)\nc where\nc z = x + iy\nc u(x,y) = Voigt \"function\" = H(x,y)\nc v(x,y) = complex component to w(z) \nc x = wave number scale in Doppler width units\nc y = ratio of Lorentz to Doppler width \nc \nc computation is valid for the upper half plane (y>0); computational\nc accuracy is claimed to be maximum relative error < 2.0e-6 for u \nc and < 5.0e-6 for v; code is from method of J. Humlicek (1979) J.\nc Quant. Spectrosc. Radiat. Transfer _21_ 309. typed in and trivially\nc modified by Christopher W. Churchill, March 1994.\nc \nc the 2-REGION n=12 approximation\nc\nc==============================================================================\nc \nc local declarations\n implicit none \n integer i,m\n parameter (m=6)\n double precision b1,b2,t(m),c(m),s(m)\n double precision u,v,x,y,d,d1,d2,d3,d4,r,r2,y1,y2,y3 \nc \nc load the data ...\nc harmonic roots and weights of the n-point Gauss-Hermite formula,\nc chosen to keep absolute error of u and v < 1.0e-7 \nc\n data b1/ 0.850d0/\n data t/ 0.314240376 , 0.947788391 , 1.59768264 ,\n @ 2.27950708 , 3.02063703 , 3.8897249 /\n data c/ 1.01172805 , -0.75197147 , 1.2557727e-2 ,\n @ 1.00220082e-2, -2.42068135e-4, 5.00848061e-7/\n data s/ 1.393237 , 0.231152406 , -0.155351466 ,\n @ 6.21836624e-3, 9.19082986e-5, -6.27525958e-7/\nc \nc initialize this pass; define the x<18.1 REGION boundary\nc\n u = 0.0d0\n v = 0.0d0\n y1 = y + 1.50d0\n y2 = y1*y1\n b2 = 18.10d0*y + 1.650d0\nc \nc \n if ((y.gt.b1).or.(abs(x).lt.b2)) then\nc\nc\nc \nc eq.(6); REGION 1 y > (x-1.65)/18.1 for x<=18.1 \nc y > 0.85 for x> 18.1\nc\n do 3 i=1,m\n r = x - t(i)\n d = 1.0d0/(r*r+y2)\n d1 = y1*d\n d2 = r*d\n r = x + t(i)\n d = 1.0d0/(r*r+y2) \n d3 = y1*d\n d4 = r*d\n u = u + c(i)*(d1+d3) - s(i)*(d2-d4)\n v = v + c(i)*(d2+d4) + s(i)*(d1-d3)\n 03 continue\n return\nc\nc\nc\n else\nc\nc\nc \nc eq.(11); REGION 2 y <= (x-1.65)/18.1 for x<=18.1 \nc y <= 0.85 for x> 18.1\nc\n if (abs(x).lt.12.0d0) u = exp(-x*x)\n y3 = y + 3\n do 5 i=1,m\n r = x - t(i)\n r2 = r*r\n d = 1.0d0/(r2+y2)\n d1 = y1*d\n d2 = r*d \n u = u + y*(c(i)*(r*d2-1.50d0*d1)+s(i)*y3*d2)/(r2+2.250d0)\n r = x + t(i)\n r2 = r*r\n d = 1.0d0/(r2+y2) \n d3 = y1*d\n d4 = r*d\n u = u + y*(c(i)*(r*d4-1.50d0*d3)-s(i)*y3*d4)/(r2+2.250d0)\n v = v + c(i)*(d2+d4) + s(i)*(d1-d3)\n 05 continue\n return\nc \n end if\nc\n end\nc\nc..............................................................................\n", "meta": {"hexsha": "73b64a099fd8850813f90b0a87ce1b02b94dd17c", "size": 3130, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "misc/convspec/voigt.f", "max_stars_repo_name": "mrawls/BF-simulator", "max_stars_repo_head_hexsha": "9c1ae79f261024f019a876cb0c7de802d85d1789", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "misc/convspec/voigt.f", "max_issues_repo_name": "mrawls/BF-simulator", "max_issues_repo_head_hexsha": "9c1ae79f261024f019a876cb0c7de802d85d1789", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "misc/convspec/voigt.f", "max_forks_repo_name": "mrawls/BF-simulator", "max_forks_repo_head_hexsha": "9c1ae79f261024f019a876cb0c7de802d85d1789", "max_forks_repo_licenses": ["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.4545454545, "max_line_length": 79, "alphanum_fraction": 0.4447284345, "num_tokens": 1219, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178994073576, "lm_q2_score": 0.74316801430083, "lm_q1q2_score": 0.6752557600607573}} {"text": " subroutine make_freq_array()\n use dyn_lc\n implicit none\n integer :: j\n \n! !Frequency array\n df = 0.5d0 / (dt * int_len_dim)\n if (.not. allocated(freq)) allocate(freq(int_len_dim / 2))\n ! print *, dt, int_len_dim\n \n do j = 1, int_len_dim / 2 \n freq(j) = real(j) / (dt * int_len_dim)\n ! write(*,*) freq(j)\n enddo\n\n \n end subroutine make_freq_array\n\n!-------------------------------------------------------------------\n subroutine make_freq_array_obs()\n use dyn_lc\n implicit none\n integer :: j, o\n \n ! !Frequency array\n\n if(.not. allocated(df_obs)) allocate(df_obs(obs_num))\n if (.not. allocated(freq_obs)) allocate(freq_obs(int_len_dim_max / 2, obs_num))\n do o = 1, obs_num\n df_obs(o) = 0.5d0 / (dt * int_len_dim_obs(o))\n \n do j = 1, int_len_dim_obs(o) / 2 \n freq_obs(j, o) = real(j) / (dt * int_len_dim_obs(o))\n enddo\n enddo\n \n end subroutine make_freq_array_obs\n", "meta": {"hexsha": "4ee23eb080b8dc5e0bc0ce1fde1b853d907e89fd", "size": 941, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "subroutines/make_freq_array.f90", "max_stars_repo_name": "mgullik/data_analysis", "max_stars_repo_head_hexsha": "b91ae014bfa280ba7e7fa3a48600b18eeb74eafe", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "subroutines/make_freq_array.f90", "max_issues_repo_name": "mgullik/data_analysis", "max_issues_repo_head_hexsha": "b91ae014bfa280ba7e7fa3a48600b18eeb74eafe", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "subroutines/make_freq_array.f90", "max_forks_repo_name": "mgullik/data_analysis", "max_forks_repo_head_hexsha": "b91ae014bfa280ba7e7fa3a48600b18eeb74eafe", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.7631578947, "max_line_length": 82, "alphanum_fraction": 0.5738575983, "num_tokens": 273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424373085146, "lm_q2_score": 0.7981867849406659, "lm_q1q2_score": 0.6752200742801541}} {"text": "!< WenOOF test: reconstruction of sin function.\nprogram sin_reconstruction\n!< WenOOF test: reconstruction of sin function.\n\nuse penf, only : I_P, R_P, str\nuse wenoof, only : interpolator, wenoof_create\nuse pyplot_module, only : pyplot\n\nimplicit none\nclass(interpolator), allocatable :: weno_interpolator !< WENO interpolator.\ninteger(I_P), parameter :: S = 6_I_P !< Stencils used.\ninteger(I_P), parameter :: Nv = 30_I_P !< Number of discretized values to be interpolated.\nreal(R_P), parameter :: pi = 4._R_P * atan(1._R_P) !< Extent of domain.\nreal(R_P) :: x(1-S:Nv+S) !< Whole domain.\nreal(R_P) :: fx(1-S:Nv+S) !< Discretized values to be interpolated.\nreal(R_P) :: xi(1:Nv) !< Domain of the interpolation.\nreal(R_P) :: fx_ref(1:Nv) !< Reference values.\nreal(R_P) :: interpolation(1:1, 1:Nv) !< Interpolated values.\ntype(pyplot) :: plt !< Plotter handler.\ninteger :: i, j, f !< Counters.\n\n! build the values used for the reconstruction of sin function: nodal values\nx = 0.\ndo i = 1 - S, Nv + S\n x(i) = i * 2 * pi / Nv\n fx(i) = sin(x(i))\nenddo\n! face values to which the reconstruction should tend\ndo i = 1, Nv\n xi(i) = x(i) + pi / Nv\n fx_ref(i) = sin(xi(i))\nenddo\n\n! create weno interpolator\ncall wenoof_create(interpolator_type='JS', S=S, wenoof_interpolator=weno_interpolator)\n\n! interpolate values\ninterpolation = 0.\ndo i = 1, Nv ! interpolated values loop\n call weno_interpolator%interpolate(S=S, &\n stencil=reshape(source=fx(i+1-S:i-1+S), shape=[1,2*S-1]), &\n location='right', &\n interpolation=interpolation(1:1, i))\nenddo\n\n! print results\nprint \"(A)\", '# x, sin(x), weno_interpolation(x)'\ndo i = 1, Nv\n print \"(A)\", str(n=xi(i))//' '//str(n=fx_ref(i))//' '//str(n=interpolation(1, i))\nenddo\n\n! plotting graph to image file\ncall plt%initialize(grid=.true., xlabel='angle (rad)', title='WENO interpolation of $\\sin(x)$', legend=.true.)\ncall plt%add_plot(x=xi(1:Nv), &\n y=fx_ref(1:Nv), &\n label='$\\sin(x)$', &\n linestyle='k-', &\n linewidth=2)\ncall plt%add_plot(x=xi(1:Nv), &\n y=interpolation(1, 1:Nv), &\n label='WENO interpolation', &\n linestyle='ro', &\n markersize=6)\ncall plt%savefig('sin_reconstruction.png')\nendprogram sin_reconstruction\n", "meta": {"hexsha": "a7fa09e082608364a151cdde9a835b24ffa13680", "size": 2870, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/sin_reconstruction.f90", "max_stars_repo_name": "giacrossi/WenOOF", "max_stars_repo_head_hexsha": "34d774c8d343274159bcd4006ff34509502e45e0", "max_stars_repo_licenses": ["BSD-3-Clause", "BSD-2-Clause", "MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-14T22:58:51.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-14T22:58:51.000Z", "max_issues_repo_path": "src/tests/sin_reconstruction.f90", "max_issues_repo_name": "giacrossi/WenOOF", "max_issues_repo_head_hexsha": "34d774c8d343274159bcd4006ff34509502e45e0", "max_issues_repo_licenses": ["BSD-3-Clause", "BSD-2-Clause", "MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/tests/sin_reconstruction.f90", "max_forks_repo_name": "giacrossi/WenOOF", "max_forks_repo_head_hexsha": "34d774c8d343274159bcd4006ff34509502e45e0", "max_forks_repo_licenses": ["BSD-3-Clause", "BSD-2-Clause", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.4848484848, "max_line_length": 114, "alphanum_fraction": 0.5153310105, "num_tokens": 740, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424373085146, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.6752200620968153}} {"text": "MODULE procgrid\n\nIMPLICIT NONE\n\nCONTAINS\n\n SUBROUTINE calgrid\n USE glodata\n\n distance_wind_to_core = 3.0*(win_length - wind_width)/2.0\n win_width = distance_wind_to_core + wind_thickness & \n + distance_wind_to_wind/2.0\n\n Nx = INT(core_length/(1.0*grid_size))\n N_core_x = INT((core_length - win_length)/grid_size)/2\n N_core_y = N_core_x\n N_win_width = INT(win_width/grid_size)\n Ny = N_win_width + N_core_y\n \n !calculate displacment grids for core-to-winding distance\n N_core_wind_x = INT((win_length - wind_width)/grid_size)/2\n N_core_wind = INT(distance_wind_to_core/grid_size)\n !calculate grids for windings\n N_wind_x = INT(wind_width/(1.0*grid_size))\n N_wind_y = INT(wind_thickness/grid_size)\n !calculate grids for winding distance\n N_dis_wind = INT(distance_wind_to_wind/(2.0*grid_size))\n !calculate grids for bumps\n N_bump_x = INT(bump_length/grid_size)\n N_bump_y = INT(bump_width/(2.0*grid_size))\n\n END SUBROUTINE calgrid\n\nEND MODULE procgrid\n", "meta": {"hexsha": "2d4906861cd8b8bb668eab94ec94d275f8bd1a6b", "size": 1048, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "cal_grid.f90", "max_stars_repo_name": "YudiXiao/Field-cannon-technique", "max_stars_repo_head_hexsha": "58f9111e0f218e8900943600f6ee8c2ed724cedb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cal_grid.f90", "max_issues_repo_name": "YudiXiao/Field-cannon-technique", "max_issues_repo_head_hexsha": "58f9111e0f218e8900943600f6ee8c2ed724cedb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cal_grid.f90", "max_forks_repo_name": "YudiXiao/Field-cannon-technique", "max_forks_repo_head_hexsha": "58f9111e0f218e8900943600f6ee8c2ed724cedb", "max_forks_repo_licenses": ["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.9428571429, "max_line_length": 63, "alphanum_fraction": 0.7061068702, "num_tokens": 291, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625126757597, "lm_q2_score": 0.7248702761768248, "lm_q1q2_score": 0.6751894888116371}} {"text": " SUBROUTINE MB04QU( TRANC, TRAND, TRANQ, STOREV, STOREW, M, N, K,\n $ V, LDV, W, LDW, C, LDC, D, LDD, CS, TAU, DWORK,\n $ LDWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To overwrite general real m-by-n matrices C and D, or their\nC transposes, with\nC\nC [ op(C) ]\nC Q * [ ] if TRANQ = 'N', or\nC [ op(D) ]\nC\nC T [ op(C) ]\nC Q * [ ] if TRANQ = 'T',\nC [ op(D) ]\nC\nC where Q is defined as the product of symplectic reflectors and\nC Givens rotations,\nC\nC Q = diag( H(1),H(1) ) G(1) diag( F(1),F(1) )\nC diag( H(2),H(2) ) G(2) diag( F(2),F(2) )\nC ....\nC diag( H(k),H(k) ) G(k) diag( F(k),F(k) ).\nC\nC Unblocked version.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC TRANC CHARACTER*1\nC Specifies the form of op( C ) as follows:\nC = 'N': op( C ) = C;\nC = 'T': op( C ) = C';\nC = 'C': op( C ) = C'.\nC\nC STOREV CHARACTER*1\nC Specifies how the vectors which define the concatenated\nC Householder reflectors contained in V are stored:\nC = 'C': columnwise;\nC = 'R': rowwise.\nC\nC STOREW CHARACTER*1\nC Specifies how the vectors which define the concatenated\nC Householder reflectors contained in W are stored:\nC = 'C': columnwise;\nC = 'R': rowwise.\nC\nC TRAND CHARACTER*1\nC Specifies the form of op( D ) as follows:\nC = 'N': op( D ) = D;\nC = 'T': op( D ) = D';\nC = 'C': op( D ) = D'.\nC\nC TRANQ CHARACTER*1\nC = 'N': apply Q;\nC = 'T': apply Q'.\nC\nC Input/Output Parameters\nC\nC M (input) INTEGER\nC The number of rows of the matrices op(C) and op(D).\nC M >= 0.\nC\nC N (input) INTEGER\nC The number of columns of the matrices op(C) and op(D).\nC N >= 0.\nC\nC K (input) INTEGER\nC The number of elementary reflectors whose product defines\nC the matrix Q. M >= K >= 0.\nC\nC V (input) DOUBLE PRECISION array, dimension\nC (LDV,K) if STOREV = 'C',\nC (LDV,M) if STOREV = 'R'\nC On entry with STOREV = 'C', the leading M-by-K part of\nC this array must contain in its columns the vectors which\nC define the elementary reflectors F(i).\nC On entry with STOREV = 'R', the leading K-by-M part of\nC this array must contain in its rows the vectors which\nC define the elementary reflectors F(i).\nC\nC LDV INTEGER\nC The leading dimension of the array V.\nC LDV >= MAX(1,M), if STOREV = 'C';\nC LDV >= MAX(1,K), if STOREV = 'R'.\nC\nC W (input) DOUBLE PRECISION array, dimension\nC (LDW,K) if STOREW = 'C',\nC (LDW,M) if STOREW = 'R'\nC On entry with STOREW = 'C', the leading M-by-K part of\nC this array must contain in its columns the vectors which\nC define the elementary reflectors H(i).\nC On entry with STOREW = 'R', the leading K-by-M part of\nC this array must contain in its rows the vectors which\nC define the elementary reflectors H(i).\nC\nC LDW INTEGER\nC The leading dimension of the array W.\nC LDW >= MAX(1,M), if STOREW = 'C';\nC LDW >= MAX(1,K), if STOREW = 'R'.\nC\nC C (input/output) DOUBLE PRECISION array, dimension\nC (LDC,N) if TRANC = 'N',\nC (LDC,M) if TRANC = 'T' or TRANC = 'C'\nC On entry with TRANC = 'N', the leading M-by-N part of\nC this array must contain the matrix C.\nC On entry with TRANC = 'C' or TRANC = 'T', the leading\nC N-by-M part of this array must contain the transpose of\nC the matrix C.\nC On exit with TRANC = 'N', the leading M-by-N part of\nC this array contains the updated matrix C.\nC On exit with TRANC = 'C' or TRANC = 'T', the leading\nC N-by-M part of this array contains the transpose of the\nC updated matrix C.\nC\nC LDC INTEGER\nC The leading dimension of the array C.\nC LDC >= MAX(1,M), if TRANC = 'N';\nC LDC >= MAX(1,N), if TRANC = 'T' or TRANC = 'C'.\nC\nC D (input/output) DOUBLE PRECISION array, dimension\nC (LDD,N) if TRAND = 'N',\nC (LDD,M) if TRAND = 'T' or TRAND = 'C'\nC On entry with TRAND = 'N', the leading M-by-N part of\nC this array must contain the matrix D.\nC On entry with TRAND = 'C' or TRAND = 'T', the leading\nC N-by-M part of this array must contain the transpose of\nC the matrix D.\nC On exit with TRAND = 'N', the leading M-by-N part of\nC this array contains the updated matrix D.\nC On exit with TRAND = 'C' or TRAND = 'T', the leading\nC N-by-M part of this array contains the transpose of the\nC updated matrix D.\nC\nC LDD INTEGER\nC The leading dimension of the array D.\nC LDD >= MAX(1,M), if TRAND = 'N';\nC LDD >= MAX(1,N), if TRAND = 'T' or TRAND = 'C'.\nC\nC CS (input) DOUBLE PRECISION array, dimension (2*K)\nC On entry, the first 2*K elements of this array must\nC contain the cosines and sines of the symplectic Givens\nC rotations G(i).\nC\nC TAU (input) DOUBLE PRECISION array, dimension (K)\nC On entry, the first K elements of this array must\nC contain the scalar factors of the elementary reflectors\nC F(i).\nC\nC Workspace\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0, DWORK(1) returns the optimal\nC value of LDWORK.\nC On exit, if INFO = -20, DWORK(1) returns the minimum\nC value of LDWORK.\nC\nC LDWORK INTEGER\nC The length of the array DWORK. LDWORK >= MAX(1,N).\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value.\nC\nC CONTRIBUTORS\nC\nC D. Kressner, Technical Univ. Berlin, Germany, and\nC P. Benner, Technical Univ. Chemnitz, Germany, December 2003.\nC\nC REVISIONS\nC\nC V. Sima, June 2008 (SLICOT version of the HAPACK routine DOSMSQ).\nC\nC KEYWORDS\nC\nC Elementary matrix operations, orthogonal symplectic matrix.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ONE\n PARAMETER ( ONE = 1.0D+0 )\nC .. Scalar Arguments ..\n CHARACTER STOREV, STOREW, TRANC, TRAND, TRANQ\n INTEGER INFO, K, LDC, LDD, LDV, LDW, LDWORK, M, N\nC .. Array Arguments ..\n DOUBLE PRECISION CS(*), DWORK(*), C(LDC,*), D(LDD,*), V(LDV,*),\n $ W(LDW,*), TAU(*)\nC .. Local Scalars ..\n LOGICAL LCOLV, LCOLW, LTRC, LTRD, LTRQ\n INTEGER I\n DOUBLE PRECISION NU\nC .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\nC .. External Subroutines ..\n EXTERNAL DLARF, DROT, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC DBLE, MAX, MIN\nC\nC .. Executable Statements ..\nC\nC Decode the scalar input parameters.\nC\n INFO = 0\n LCOLV = LSAME( STOREV, 'C' )\n LCOLW = LSAME( STOREW, 'C' )\n LTRC = LSAME( TRANC, 'T' ) .OR. LSAME( TRANC, 'C' )\n LTRD = LSAME( TRAND, 'T' ) .OR. LSAME( TRAND, 'C' )\n LTRQ = LSAME( TRANQ, 'T' )\nC\nC Check the scalar input parameters.\nC\n IF ( .NOT.( LTRC.OR.LSAME( TRANC, 'N' ) ) ) THEN\n INFO = -1\n ELSE IF ( .NOT.( LTRD .OR. LSAME( TRAND, 'N' ) ) ) THEN\n INFO = -2\n ELSE IF ( .NOT.( LTRQ .OR. LSAME( TRANQ, 'N' ) ) ) THEN\n INFO = -3\n ELSE IF ( .NOT.( LCOLV.OR. LSAME( STOREV, 'R' ) ) ) THEN\n INFO = -4\n ELSE IF ( .NOT.( LCOLW.OR. LSAME( STOREW, 'R' ) ) ) THEN\n INFO = -5\n ELSE IF ( M.LT.0 ) THEN\n INFO = -6\n ELSE IF ( N.LT.0 ) THEN\n INFO = -7\n ELSE IF ( K.LT.0 .OR. K.GT.M ) THEN\n INFO = -8\n ELSE IF ( ( LCOLV.AND.LDV.LT.MAX( 1, M ) ) .OR.\n $ ( .NOT.LCOLV.AND.LDV.LT.MAX( 1, K ) ) ) THEN\n INFO = -10\n ELSE IF ( ( LCOLW.AND.LDW.LT.MAX( 1, M ) ) .OR.\n $ ( .NOT.LCOLW.AND.LDW.LT.MAX( 1, K ) ) ) THEN\n INFO = -12\n ELSE IF ( ( LTRC.AND.LDC.LT.MAX( 1, N ) ) .OR.\n $ ( .NOT.LTRC.AND.LDC.LT.MAX( 1, M ) ) ) THEN\n INFO = -14\n ELSE IF ( ( LTRD.AND.LDD.LT.MAX( 1, N ) ) .OR.\n $ ( .NOT.LTRD.AND.LDD.LT.MAX( 1, M ) ) ) THEN\n INFO = -16\n ELSE IF ( LDWORK.LT.MAX( 1, N ) ) THEN\n DWORK(1) = DBLE( MAX( 1, N ) )\n INFO = -20\n END IF\nC\nC Return if there were illegal values.\nC\n IF ( INFO.NE.0 ) THEN\n CALL XERBLA( 'MB04QU', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF( MIN( K, M, N ).EQ.0 ) THEN\n DWORK(1) = ONE\n RETURN\n END IF\nC\n IF ( LTRQ ) THEN\n DO 10 I = 1, K\nC\nC Apply H(I) to C(I:M,:) and D(I:M,:) from the left.\nC\n NU = W(I,I)\n W(I,I) = ONE\n IF ( LCOLW ) THEN\n IF ( LTRC ) THEN\n CALL DLARF( 'Right', N, M-I+1, W(I,I), 1, NU, C(1,I),\n $ LDC, DWORK )\n ELSE\n CALL DLARF( 'Left', M-I+1, N, W(I,I), 1, NU, C(I,1),\n $ LDC, DWORK )\n END IF\n IF ( LTRD ) THEN\n CALL DLARF( 'Right', N, M-I+1, W(I,I), 1, NU, D(1,I),\n $ LDD, DWORK )\n ELSE\n CALL DLARF( 'Left', M-I+1, N, W(I,I), 1, NU, D(I,1),\n $ LDD, DWORK )\n END IF\n ELSE\n IF ( LTRC ) THEN\n CALL DLARF( 'Right', N, M-I+1, W(I,I), LDW, NU,\n $ C(1,I), LDC, DWORK )\n ELSE\n CALL DLARF( 'Left', M-I+1, N, W(I,I), LDW, NU, C(I,1),\n $ LDC, DWORK )\n END IF\n IF ( LTRD ) THEN\n CALL DLARF( 'Right', N, M-I+1, W(I,I), LDW, NU,\n $ D(1,I), LDD, DWORK )\n ELSE\n CALL DLARF( 'Left', M-I+1, N, W(I,I), LDW, NU, D(I,1),\n $ LDD, DWORK )\n END IF\n END IF\n W(I,I) = NU\nC\nC Apply G(i) to C(I,:) and D(I,:) from the left.\nC\n IF ( LTRC.AND.LTRD ) THEN\n CALL DROT( N, C(1,I), 1, D(1,I), 1, CS(2*I-1), CS(2*I) )\n ELSE IF ( LTRC ) THEN\n CALL DROT( N, C(1,I), 1, D(I,1), LDD, CS(2*I-1),\n $ CS(2*I) )\n ELSE IF ( LTRD ) THEN\n CALL DROT( N, C(I,1), LDC, D(1,I), 1, CS(2*I-1),\n $ CS(2*I) )\n ELSE\n CALL DROT( N, C(I,1), LDC, D(I,1), LDD, CS(2*I-1),\n $ CS(2*I) )\n END IF\nC\nC Apply F(I) to C(I:M,:) and D(I:M,:) from the left.\nC\n NU = V(I,I)\n V(I,I) = ONE\n IF ( LCOLV ) THEN\n IF ( LTRC ) THEN\n CALL DLARF( 'Right', N, M-I+1, V(I,I), 1, TAU(I),\n $ C(1,I), LDC, DWORK )\n ELSE\n CALL DLARF( 'Left', M-I+1, N, V(I,I), 1, TAU(I),\n $ C(I,1), LDC, DWORK )\n END IF\n IF ( LTRD ) THEN\n CALL DLARF( 'Right', N, M-I+1, V(I,I), 1, TAU(I),\n $ D(1,I), LDD, DWORK )\n ELSE\n CALL DLARF( 'Left', M-I+1, N, V(I,I), 1, TAU(I),\n $ D(I,1), LDD, DWORK )\n END IF\n ELSE\n IF ( LTRC ) THEN\n CALL DLARF( 'Right', N, M-I+1, V(I,I), LDV, TAU(I),\n $ C(1,I), LDC, DWORK )\n ELSE\n CALL DLARF( 'Left', M-I+1, N, V(I,I), LDV, TAU(I),\n $ C(I,1), LDC, DWORK )\n END IF\n IF ( LTRD ) THEN\n CALL DLARF( 'Right', N, M-I+1, V(I,I), LDV, TAU(I),\n $ D(1,I), LDD, DWORK )\n ELSE\n CALL DLARF( 'Left', M-I+1, N, V(I,I), LDV, TAU(I),\n $ D(I,1), LDD, DWORK )\n END IF\n END IF\n V(I,I) = NU\n 10 CONTINUE\n ELSE\n DO 20 I = K, 1, -1\nC\nC Apply F(I) to C(I:M,:) and D(I:M,:) from the left.\nC\n NU = V(I,I)\n V(I,I) = ONE\n IF ( LCOLV ) THEN\n IF ( LTRC ) THEN\n CALL DLARF( 'Right', N, M-I+1, V(I,I), 1, TAU(I),\n $ C(1,I), LDC, DWORK )\n ELSE\n CALL DLARF( 'Left', M-I+1, N, V(I,I), 1, TAU(I),\n $ C(I,1), LDC, DWORK )\n END IF\n IF ( LTRD ) THEN\n CALL DLARF( 'Right', N, M-I+1, V(I,I), 1, TAU(I),\n $ D(1,I), LDD, DWORK )\n ELSE\n CALL DLARF( 'Left', M-I+1, N, V(I,I), 1, TAU(I),\n $ D(I,1), LDD, DWORK )\n END IF\n ELSE\n IF ( LTRC ) THEN\n CALL DLARF( 'Right', N, M-I+1, V(I,I), LDV, TAU(I),\n $ C(1,I), LDC, DWORK )\n ELSE\n CALL DLARF( 'Left', M-I+1, N, V(I,I), LDV, TAU(I),\n $ C(I,1), LDC, DWORK )\n END IF\n IF ( LTRD ) THEN\n CALL DLARF( 'Right', N, M-I+1, V(I,I), LDV, TAU(I),\n $ D(1,I), LDD, DWORK )\n ELSE\n CALL DLARF( 'Left', M-I+1, N, V(I,I), LDV, TAU(I),\n $ D(I,1), LDD, DWORK )\n END IF\n END IF\n V(I,I) = NU\nC\nC Apply G(i) to C(I,:) and D(I,:) from the left.\nC\n IF ( LTRC.AND.LTRD ) THEN\n CALL DROT( N, C(1,I), 1, D(1,I), 1, CS(2*I-1), -CS(2*I) )\n ELSE IF ( LTRC ) THEN\n CALL DROT( N, C(1,I), 1, D(I,1), LDD, CS(2*I-1),\n $ -CS(2*I) )\n ELSE IF ( LTRD ) THEN\n CALL DROT( N, C(I,1), LDC, D(1,I), 1, CS(2*I-1),\n $ -CS(2*I) )\n ELSE\n CALL DROT( N, C(I,1), LDC, D(I,1), LDD, CS(2*I-1),\n $ -CS(2*I) )\n END IF\nC\nC Apply H(I) to C(I:M,:) and D(I:M,:) from the left.\nC\n NU = W(I,I)\n W(I,I) = ONE\n IF ( LCOLW ) THEN\n IF ( LTRC ) THEN\n CALL DLARF( 'Right', N, M-I+1, W(I,I), 1, NU, C(1,I),\n $ LDC, DWORK )\n ELSE\n CALL DLARF( 'Left', M-I+1, N, W(I,I), 1, NU, C(I,1),\n $ LDC, DWORK )\n END IF\n IF ( LTRD ) THEN\n CALL DLARF( 'Right', N, M-I+1, W(I,I), 1, NU, D(1,I),\n $ LDD, DWORK )\n ELSE\n CALL DLARF( 'Left', M-I+1, N, W(I,I), 1, NU, D(I,1),\n $ LDD, DWORK )\n END IF\n ELSE\n IF ( LTRC ) THEN\n CALL DLARF( 'Right', N, M-I+1, W(I,I), LDW, NU,\n $ C(1,I), LDC, DWORK )\n ELSE\n CALL DLARF( 'Left', M-I+1, N, W(I,I), LDW, NU, C(I,1),\n $ LDC, DWORK )\n END IF\n IF ( LTRD ) THEN\n CALL DLARF( 'Right', N, M-I+1, W(I,I), LDW, NU,\n $ D(1,I), LDD, DWORK )\n ELSE\n CALL DLARF( 'Left', M-I+1, N, W(I,I), LDW, NU, D(I,1),\n $ LDD, DWORK )\n END IF\n END IF\n W(I,I) = NU\n 20 CONTINUE\n END IF\nC\n DWORK(1) = DBLE( MAX( 1, N ) )\nC *** Last line of MB04QU ***\n END\n", "meta": {"hexsha": "175c51370e1592faf8cc5a51c012e4a094955607", "size": 16699, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB04QU.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB04QU.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB04QU.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 36.3812636166, "max_line_length": 72, "alphanum_fraction": 0.4217617821, "num_tokens": 5259, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9314625069680098, "lm_q2_score": 0.7248702761768249, "lm_q1q2_score": 0.6751894846742589}} {"text": " double precision function ff_alpha(muj,muk)\nc--- This is an implementation of the modifications to the final-final\nc--- dipoles ff_qq, according to the formulae in Appendix A of:\nc---\nc--- G.~Bevilacqua, M.~Czakon, C.~G.~Papadopoulos, R.~Pittau and M.~Worek,\nc--- ``Assault on the NLO Wishlist: pp -> tt bb,''\nc--- JHEP {\\bf 0909}, 109 (2009) [arXiv:0907.4723 [hep-ph]].\nc---\nc--- Note: according to the MCFM implementation of the final-final dipoles,\nc--- alpha in the paper is replaced by (aff*yp) here\n implicit none\n include 'alfacut.f'\n double precision muj,muk,mujsq,muksq,fac,rt\n double precision Deik,Dcoll,yp,ddilog,aa,bb,cc,dd,xx,xp,xm,vjk\n\nc--- some definitions, for speed \n mujsq=muj**2\n muksq=muk**2\n fac=1d0-mujsq-muksq\n rt=dsqrt(1d0+mujsq**2+muksq**2-2d0*(mujsq+muksq+mujsq*muksq))\n\nc--- basic definitions \n yp=1d0-2d0*muk*(1d0-muk)/fac\n\n aa=2d0*muk/fac\n bb=2d0*(1d0-muk)/fac\n cc=bb*muk\n dd=fac/2d0\n \n xp=((1d0-muk)**2-mujsq+rt)/fac\n xm=((1d0-muk)**2-mujsq-rt)/fac\n vjk=rt/fac\n\nc--- Equation (A.8) (remember alpha -> alpha*yp)\n xx=yp*(1d0-aff)+dsqrt(yp*(1d0-aff)*\n & (1d0/yp-yp*aff+4d0*mujsq*muksq/(mujsq-(1d0-muk)**2)/fac))\n\nc--- Equation (A.9) \n Deik=(\n & -ddilog((aa+xx)/(aa+xp))+ddilog(aa/(aa+xp))\n & +ddilog((xp-xx)/(xp-bb))-ddilog(xp/(xp-bb))\n & +ddilog((cc+xx)/(cc+xp))-ddilog(cc/(cc+xp))\n & +ddilog((xm-xx)/(xm+aa))-ddilog(xm/(xm+aa))\n & -ddilog((bb-xx)/(bb-xm))+ddilog(bb/(bb-xm))\n & -ddilog((xm-xx)/(xm+cc))+ddilog(xm/(xm+cc))\n & +ddilog((bb-xx)/(bb+aa))-ddilog(bb/(bb+aa))\n & -ddilog((cc+xx)/(cc-aa))+ddilog(cc/(cc-aa))\n & +dlog(cc+xx)*dlog((aa-cc)*(xp-xx)/(aa+xx)/(cc+xp))\n & -dlog(cc)*dlog((aa-cc)*xp/aa/(cc+xp))\n & +dlog(bb-xx)*dlog((aa+xx)*(xm-bb)/(aa+bb)/(xm-xx))\n & -dlog(bb)*dlog(aa*(xm-bb)/(aa+bb)/xm)\n & -dlog((aa+xx)*(bb-xp))*dlog(xp-xx)\n & +dlog(aa*(bb-xp))*dlog(xp)\n & +dlog(dd)*dlog((aa+xx)*xp*xm/aa/(xp-xx)/(xm-xx))\n & +dlog((xm-xx)/xm)*dlog((cc+xm)/(aa+xm))\n & +0.5d0*dlog((aa+xx)/aa)*dlog(aa*(aa+xx)*(aa+xp)**2)\n & )/vjk\n \nc--- Equation (A.20) (remember alpha -> alpha*yp)\n Dcoll=1.5d0*(1d0+aff*yp)+1d0/(1d0-muk)-2d0*(2d0-2d0*mujsq-muk)/fac\n & +(1d0-aff*yp)*mujsq/2d0/(mujsq+aff*yp*fac)\n & -2d0*dlog(aff*yp*fac/((1d0-muk)**2-mujsq))\n & +(1d0+mujsq-muksq)/2d0/fac*dlog((mujsq+aff*yp*fac)/(1d0-muk)**2)\n \nc--- the final dipole is equal to this combination (c.f. dipoles_mass.f)\n ff_alpha=2d0*Deik+Dcoll \n \nc write(6,*) 'ff_alpha: 2d0*Deik ',2d0*Deik\nc write(6,*) 'ff_alpha: Dcoll ',Dcoll\nc write(6,*) 'ff_alpha: ff_alpha ',ff_alpha\nc pause\n \n return\n end\n \n", "meta": {"hexsha": "84df8ae102f4736fb0d70d04d3a555e0d7d74db0", "size": 2789, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "MCFM-JHUGen/src/Need/ff_alpha.f", "max_stars_repo_name": "tmartini/JHUGen", "max_stars_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-06-08T13:09:28.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-04T19:59:36.000Z", "max_issues_repo_path": "MCFM-JHUGen/src/Need/ff_alpha.f", "max_issues_repo_name": "tmartini/JHUGen", "max_issues_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 64, "max_issues_repo_issues_event_min_datetime": "2015-06-24T15:08:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-25T04:59:32.000Z", "max_forks_repo_path": "MCFM-JHUGen/src/Need/ff_alpha.f", "max_forks_repo_name": "tmartini/JHUGen", "max_forks_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2015-05-04T22:15:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-06T10:04:40.000Z", "avg_line_length": 36.6973684211, "max_line_length": 76, "alphanum_fraction": 0.5650770886, "num_tokens": 1205, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566342012360933, "lm_q2_score": 0.7057850340255386, "lm_q1q2_score": 0.6751781022694101}} {"text": " FUNCTION rf(x,y,z)\r\n REAL rf,x,y,z,ERRTOL,TINY,BIG,THIRD,C1,C2,C3,C4\r\n PARAMETER (ERRTOL=.08,TINY=1.5e-38,BIG=3.E37,THIRD=1./3.,\r\n *C1=1./24.,C2=.1,C3=3./44.,C4=1./14.)\r\n REAL alamb,ave,delx,dely,delz,e2,e3,sqrtx,sqrty,sqrtz,xt,yt,zt\r\n if(min(x,y,z).lt.0..or.min(x+y,x+z,y+z).lt.TINY.or.max(x,y,\r\n *z).gt.BIG)pause 'invalid arguments in rf'\r\n xt=x\r\n yt=y\r\n zt=z\r\n1 continue\r\n sqrtx=sqrt(xt)\r\n sqrty=sqrt(yt)\r\n sqrtz=sqrt(zt)\r\n alamb=sqrtx*(sqrty+sqrtz)+sqrty*sqrtz\r\n xt=.25*(xt+alamb)\r\n yt=.25*(yt+alamb)\r\n zt=.25*(zt+alamb)\r\n ave=THIRD*(xt+yt+zt)\r\n delx=(ave-xt)/ave\r\n dely=(ave-yt)/ave\r\n delz=(ave-zt)/ave\r\n if(max(abs(delx),abs(dely),abs(delz)).gt.ERRTOL)goto 1\r\n e2=delx*dely-delz**2\r\n e3=delx*dely*delz\r\n rf=(1.+(C1*e2-C2-C3*e3)*e2+C4*e3)/sqrt(ave)\r\n return\r\n END\r\n", "meta": {"hexsha": "df58d8b666e904ac60635699e223e8008c54c009", "size": 930, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/rf.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/rf.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/rf.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.0689655172, "max_line_length": 69, "alphanum_fraction": 0.5247311828, "num_tokens": 389, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425267730008, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.6751275366718844}} {"text": "! ----------------------------------------- !\n! Set up filtro periodico !\n! F. Califano, Marzo 2001 !\n! ----------------------------------------- !\n\n!**************************************************\n! MPI PARALLEL VERSION: VALENTINI-FAGANELLO 2009\n! 3D PARALLEL VERSION: FAGANELLO 2010\n!**************************************************\n\n subroutine init_filtro_per\n\nuse box_mod\nuse parameter_mod\nuse filtro_per_mod\n\nIMPLICIT NONE\n\n integer :: kk\n real(dp) :: tr1, tr2, tr3, tr4, tr5, w0, w11, w22\n\n! Set up coefficienti filtro periodico in x !!!!!!!!!!!!!!!!refuso!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n! filter parameters\n\n tr1 = (2.0 + 3.0 * omega_x) / 4.0\n tr2 = (6.0 + 7.0 * omega_x) / 8.0\n tr3 = (6.0 + omega_x) / 20.0\n tr4 = (2.0 - 3.0 * omega_x) / 40.0\n tr5 = (3.0 - 2.0 * omega_x) / 10.0\n\n\n do kk = 1, n2x\n w0 = 2.d0 * pgreco * dfloat(kk) / dfloat(nx)\n w11 = tr1 + tr2*cos(w0) + tr3*cos(2.d0*w0) + tr4*cos(3.d0*w0)\n w22 = 1.0 +2.0 * omega_x*cos(w0) + 2.0 * tr5*cos(2.d0*w0)\n work4x(kk) = w11 / w22\n enddo\n\n\n\n! Set up coefficienti filtro periodico in y\n\n! filter parameters\n\n tr1 = (2.0 + 3.0 * omega_y) / 4.0\n tr2 = (6.0 + 7.0 * omega_y) / 8.0\n tr3 = (6.0 + omega_y) / 20.0\n tr4 = (2.0 - 3.0 * omega_y) / 40.0\n tr5 = (3.0 - 2.0 * omega_y) / 10.0\n\n\n do kk = 1, n2y\n w0 = 2.d0 * pgreco * dfloat(kk) / dfloat(ny)\n w11 = tr1 + tr2*cos(w0) + tr3*cos(2.d0*w0) + tr4*cos(3.d0*w0)\n w22 = 1.0 +2.0 * omega_y*cos(w0) + 2.0 * tr5*cos(2.d0*w0)\n work4y(kk) = w11 / w22\n enddo\n\n! Set up coefficienti filtro periodico in z\n\n! filter parameters\n\n tr1 = (2.0 + 3.0 * omega_z) / 4.0\n tr2 = (6.0 + 7.0 * omega_z) / 8.0\n tr3 = (6.0 + omega_z) / 20.0\n tr4 = (2.0 - 3.0 * omega_z) / 40.0\n tr5 = (3.0 - 2.0 * omega_z) / 10.0\n\n\n do kk = 1, n2z\n w0 = 2.d0 * pgreco * dfloat(kk) / dfloat(nz)\n w11 = tr1 + tr2*cos(w0) + tr3*cos(2.d0*w0) + tr4*cos(3.d0*w0)\n w22 = 1.0 +2.0 * omega_z*cos(w0) + 2.0 * tr5*cos(2.d0*w0)\n work4z(kk) = w11 / w22\n enddo\n\n\n end subroutine\n", "meta": {"hexsha": "8e66c482a373775cfc714d7f39be40880ab417d0", "size": 2134, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "init_filtro_per.f90", "max_stars_repo_name": "sscerr/eTF", "max_stars_repo_head_hexsha": "31dea18c7b24b3ebbb6bdfea98467ffbf79f0852", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-02T04:11:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-02T04:11:49.000Z", "max_issues_repo_path": "init_filtro_per.f90", "max_issues_repo_name": "sscerr/eTF", "max_issues_repo_head_hexsha": "31dea18c7b24b3ebbb6bdfea98467ffbf79f0852", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "init_filtro_per.f90", "max_forks_repo_name": "sscerr/eTF", "max_forks_repo_head_hexsha": "31dea18c7b24b3ebbb6bdfea98467ffbf79f0852", "max_forks_repo_licenses": ["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.675, "max_line_length": 106, "alphanum_fraction": 0.4718837863, "num_tokens": 891, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425377849806, "lm_q2_score": 0.7341195152660687, "lm_q1q2_score": 0.6751275340567672}} {"text": "\nprogram main\n use globals\n use initialise\n use fft_routines\n use display\n use solver\n integer :: i,j,fulldump, current_time, num_dumps, time_dump\n integer :: nanspres\n !netcdf variables\n integer :: mdata_id, x_dimid,y_dimid,t_id,cmplx_id\n integer :: uid,vid,wid,rhoid\n integer :: time_rep\n integer, dimension(4) :: dimids,curr_dim, count_dim\n character(len=8) :: ct\n character(len=32) :: kzs,Ns, res, fhs, Lstr\n character(len=80) :: outputname \n \n !get kz,Fh,Re,N from command line \n i=command_argument_count()\n if(i /= 5) then\n print *, \"ERROR: insufficient cl arguments\"\n call EXIT(0)\n end if\n call get_command_argument(1,kzs)\n read(kzs,'(g5.2)') ukz\n call get_command_argument(2,fhs)\n read(fhs,'(g5.2)') Fh\n call get_command_argument(3,res)\n read(res,'(g7.2)') Re\n call get_command_argument(4,Ns)\n read(Ns,'(i4)') N \n call get_command_argument(5,Lstr)\n read(Lstr,'(g2.2)') L\n\n !define some important information\n tpiL=2.0*pi/L \n dx=L/real(N,8)\n dy=dx\n num_steps=floor(t_final/dt)\n !number of times I want to dump the data\n num_dumps=50\n !how often I dump the data, in terms of num_steps\n fulldump=floor((t_final/num_dumps)/dt)\n\n !allocate\n call alloc_matrices()\n call alloc_fft()\n call init_fft()\n call init_wn()\n call init_grid()\n call init_projection()\n call init_conditions(cont,kzs)\n call init_vorticity()\n\n if (hypervis == 1) then \n Rev=Re\n Re=Re*(n_k**2)\n end if\n call afft2(uu,uu_hat)\n call afft2(vv,vv_hat)\n call afft2(ww,ww_hat)\n call afft2(rho,rho_hat)\n\n print *,'Doing fulldump every', fulldump,' timesteps'\n ifactor=k_sq/Re\n t_ifactor=ifactor*dt\n exp_ifactor_1=exp(-t_ifactor)\n exp_ifactor_2=exp(-2*t_ifactor)\n\n ! do NETCDF allocation\n outputname='kz.'//trim(kzs)//'.'//trim(Ns)//'.re.'//trim(res)//'.fh.'//trim(fhs)//'.L.'//trim(Lstr)//'.ncf'\n call check(nf90_create(outputname,nf90_64bit_offset,mdata_id))\n call check(nf90_def_dim(mdata_id,\"X\",N,x_dimid))\n call check(nf90_def_dim(mdata_id,\"Y\",N,y_dimid))\n !num_dumps + 2 to include first and last\n call check(nf90_def_dim(mdata_id,\"t\",num_dumps+2,t_id))\n call check(nf90_def_dim(mdata_id,\"cmplx\",2,cmplx_id))\n \n dimids=(/ x_dimid,y_dimid,t_id,cmplx_id /)\n call check(nf90_def_var(mdata_id,\"u\",nf90_double,dimids,uid))\n call check(nf90_def_var(mdata_id,\"v\",nf90_double,dimids,vid))\n call check(nf90_def_var(mdata_id,\"w\",nf90_double,dimids,wid))\n call check(nf90_def_var(mdata_id,\"rho\",nf90_double,dimids,rhoid))\n\n call check(nf90_enddef(mdata_id))\n\n uu_hat_temp=uu_hat\n vv_hat_temp=vv_hat\n ww_hat_temp=ww_hat\n\n ! ensures divergence free\n uu_hat=uu_hat_temp*p11+vv_hat_temp*p12+ww_hat_temp*p13\n vv_hat=uu_hat_temp*p21+vv_hat_temp*p22+ww_hat_temp*p23\n ww_hat=uu_hat_temp*p31+vv_hat_temp*p32+ww_hat_temp*p33\n\n\n !convert to integrating factors\n irho_hat=rho_hat\n iuu_hat=uu_hat\n ivv_hat=vv_hat\n iww_hat=ww_hat\n\n !Euler method for first step \n call rho_right() \n irho_hat_new=exp_ifactor_1*irho_hat+exp_ifactor_1*dt*rr\n call vel_right() \n \n iuu_hat_new=exp_ifactor_1*iuu_hat+exp_ifactor_1*dt*ur\n ivv_hat_new=exp_ifactor_1*ivv_hat+exp_ifactor_1*dt*vr\n iww_hat_new=exp_ifactor_1*iww_hat+exp_ifactor_1*dt*wr\n\n ! update scheme\n iuu_hat=iuu_hat_new\n ivv_hat=ivv_hat_new\n iww_hat=iww_hat_new\n irho_hat=irho_hat_new\n rr_old=rr\n ur_old=ur\n vr_old=vr\n wr_old=wr\n\n !dump initial data\n curr_dim=(/1,1,1,1/)\n count_dim=(/N,N,1,1/)\n call check(nf90_put_var(mdata_id,uid,real(ur),curr_dim,count_dim))\n call check(nf90_put_var(mdata_id,vid,real(vr),curr_dim,count_dim))\n call check(nf90_put_var(mdata_id,wid,real(wr),curr_dim,count_dim))\n call check(nf90_put_var(mdata_id,rhoid,real(rr),curr_dim,count_dim))\n!\n curr_dim=(/1,1,1,2/)\n call check(nf90_put_var(mdata_id,uid,imag(ur),curr_dim,count_dim))\n call check(nf90_put_var(mdata_id,vid,imag(vr),curr_dim,count_dim))\n call check(nf90_put_var(mdata_id,wid,imag(wr),curr_dim,count_dim))\n call check(nf90_put_var(mdata_id,rhoid,imag(rr),curr_dim,count_dim))\n time_dump=1\n j=1\n prev_en=0._8 \n do i=1,num_steps\n tstep=i\n !apply Adams-Basforth 2nd order time-stepping\n call rho_right()\n call vel_right()\n irho_hat_new=exp_ifactor_1*irho_hat+exp_ifactor_1*1.5_8*dt*rr-exp_ifactor_2*0.5_8*dt*rr_old\n iuu_hat_new=exp_ifactor_1*iuu_hat+exp_ifactor_1*1.5_8*dt*ur-exp_ifactor_2*0.5_8*dt*ur_old\n ivv_hat_new=exp_ifactor_1*ivv_hat+exp_ifactor_1*1.5_8*dt*vr-exp_ifactor_2*0.5_8*dt*vr_old\n iww_hat_new=exp_ifactor_1*iww_hat+exp_ifactor_1*1.5_8*dt*wr-exp_ifactor_2*0.5_8*dt*wr_old\n !update scheme\n iuu_hat=iuu_hat_new\n ivv_hat=ivv_hat_new\n iww_hat=iww_hat_new\n irho_hat=irho_hat_new\n rr_old=rr\n ur_old=ur\n vr_old=vr\n wr_old=wr\n tote(i)=en\n growth_rate(i)=(en-prev_en)/dt \n prev_en=en \n if (isnan(en)) then\n print *, \"ERROR: NaNs detected at timestep\"\n print *, i\n print *, 'time dump', time_dump, 'at time step', i\n time_dump=time_dump+1\n curr_dim=(/1,1,time_dump,1/)\n count_dim=(/N,N,1,1/)\n call check(nf90_put_var(mdata_id,uid,real(r1),curr_dim,count_dim))\n call check(nf90_put_var(mdata_id,vid,real(r2),curr_dim,count_dim))\n call check(nf90_put_var(mdata_id,wid,real(r3),curr_dim,count_dim))\n call check(nf90_put_var(mdata_id,rhoid,real(r4),curr_dim,count_dim))\n curr_dim=(/1,1,time_dump,2/)\n call check(nf90_put_var(mdata_id,uid,imag(r1),curr_dim,count_dim))\n call check(nf90_put_var(mdata_id,vid,imag(r2),curr_dim,count_dim))\n call check(nf90_put_var(mdata_id,wid,imag(r3),curr_dim,count_dim))\n call check(nf90_put_var(mdata_id,rhoid,imag(r4),curr_dim,count_dim))\n outputname='kz.'//trim(kzs)//'.totE.'//trim(Ns)//'.re.'//trim(res)//'.fh.'//trim(fhs)//'L.'//trim(Lstr)//'.dat'\n call arr_w2f(tote,outputname,num_steps)\n outputname='kz.'//trim(kzs)//'.sigma.'//trim(Ns)//'.re.'//trim(res)//'.fh.'//trim(fhs)//'L.'//trim(Lstr)//'.dat'\n call arr_w2f(growth_rate,outputname,num_steps)\n ! close netcdf\n call check(nf90_close(mdata_id))\n ! deallocate everything\n call dealloc_matrices()\n call dealloc_fft()\n call EXIT(0)\n end if\n ! every 100 time steps dump some info \n if (mod(i,100)==0) then\n outputname='kz.'//trim(kzs)//'_data_'//trim(Ns)//'.L.'//trim(Lstr)//'.dat'\n call data_w2f(growth_rate(i),outputname,i)\n end if\n\n if(mod(i,fulldump)==0) then\n time_dump=time_dump+1\n curr_dim=(/1,1,time_dump,1/)\n count_dim=(/N,N,1,1/)\n call check(nf90_put_var(mdata_id,uid,real(r1),curr_dim,count_dim))\n call check(nf90_put_var(mdata_id,vid,real(r2),curr_dim,count_dim))\n call check(nf90_put_var(mdata_id,wid,real(r3),curr_dim,count_dim))\n call check(nf90_put_var(mdata_id,rhoid,real(r4),curr_dim,count_dim))\n curr_dim=(/1,1,time_dump,2/)\n call check(nf90_put_var(mdata_id,uid,imag(r1),curr_dim,count_dim))\n call check(nf90_put_var(mdata_id,vid,imag(r2),curr_dim,count_dim))\n call check(nf90_put_var(mdata_id,wid,imag(r3),curr_dim,count_dim))\n call check(nf90_put_var(mdata_id,rhoid,imag(r4),curr_dim,count_dim))\n outputname='kz.'//trim(kzs)//'.totE.'//trim(Ns)//'.re.'//trim(res)//'.fh.'//trim(fhs)//'L.'//trim(Lstr)//'.dat'\n call arr_w2f(tote,outputname,num_steps)\n outputname='kz.'//trim(kzs)//'.sigma.'//trim(Ns)//'.re.'//trim(res)//'.fh.'//trim(fhs)//'L.'//trim(Lstr)//'.dat'\n call arr_w2f(growth_rate,outputname,num_steps)\n end if\n end do \n r1_hat=iuu_hat\n r2_hat=ivv_hat\n r3_hat=iww_hat\n r4_hat=irho_hat\n call ifft2(r1_hat,r1)\n call ifft2(r2_hat,r2)\n call ifft2(r3_hat,r3)\n call ifft2(r4_hat,r4)\n curr_dim=(/1,1,num_dumps+2,1/)\n count_dim=(/N,N,1,1/)\n call check(nf90_put_var(mdata_id,uid,real(r1),curr_dim,count_dim))\n call check(nf90_put_var(mdata_id,vid,real(r2),curr_dim,count_dim))\n call check(nf90_put_var(mdata_id,wid,real(r3),curr_dim,count_dim))\n call check(nf90_put_var(mdata_id,rhoid,real(r4),curr_dim,count_dim))\n curr_dim=(/1,1,num_dumps+2,2/)\n call check(nf90_put_var(mdata_id,uid,imag(r1),curr_dim,count_dim))\n call check(nf90_put_var(mdata_id,vid,imag(r2),curr_dim,count_dim))\n call check(nf90_put_var(mdata_id,wid,imag(r3),curr_dim,count_dim))\n call check(nf90_put_var(mdata_id,rhoid,imag(r4),curr_dim,count_dim))\n outputname='kz.'//trim(kzs)//'.totE.'//trim(Ns)//'.re.'//trim(res)//'.fh.'//trim(fhs)//'L.'//trim(Lstr)//'.dat'\n call arr_w2f(tote,outputname,num_steps)\n outputname='kz.'//trim(kzs)//'.sigma.'//trim(Ns)//'.re.'//trim(res)//'.fh.'//trim(fhs)//'L.'//trim(Lstr)//'.dat'\n call arr_w2f(growth_rate,outputname,num_steps)\n ! close netcdf\n call check(nf90_close(mdata_id))\n ! deallocate everything\n call dealloc_matrices()\n call dealloc_fft()\ncontains\n subroutine check(status)\n integer, intent(in) :: status\n if(status/=nf90_noerr) then\n print *, trim(nf90_strerror(status))\n stop \"Stopped. Error in netcdf.\"\n end if\n end subroutine check\nend program main\n\n\n", "meta": {"hexsha": "773bebdbea0156ecd95bee329531748336adfbf3", "size": 11027, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "main.f90", "max_stars_repo_name": "lbovard/linear-stability-boussinesq-2d", "max_stars_repo_head_hexsha": "afdac49a74b066e26fcdaf8562a7c63c08dedfc7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-07T09:17:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-07T09:17:48.000Z", "max_issues_repo_path": "main.f90", "max_issues_repo_name": "lbovard/linear-stability-boussinesq-2d", "max_issues_repo_head_hexsha": "afdac49a74b066e26fcdaf8562a7c63c08dedfc7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "main.f90", "max_forks_repo_name": "lbovard/linear-stability-boussinesq-2d", "max_forks_repo_head_hexsha": "afdac49a74b066e26fcdaf8562a7c63c08dedfc7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.9322709163, "max_line_length": 136, "alphanum_fraction": 0.5736827786, "num_tokens": 3174, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425223682085, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6751275280886272}} {"text": "! { dg-do run }\n! { dg-options \"-ffrontend-optimize -fdump-tree-original\" }\n\nprogram main\n implicit none\n real(kind=8), ALLOCATABLE :: a(:,:), b(:,:), v1(:), v2(:)\n real(kind=8), dimension(3,3) :: v1res, v2res\n integer :: n, i\n\n data v1res/ 442.d0, -492.d0, 586.d0, &\n -4834.d0, 5694.d0, -7066.d0, &\n 13042.d0, -15450.d0, 19306.d0 /\n\n data v2res/ 5522.d0, -6310.d0, 7754.d0, &\n -7794.d0, 8982.d0, -11034.d0, &\n 10490.d0, -12160.d0, 14954.d0 /\n n = 3\n\n ALLOCATE(a(N,N),b(N,N),v1(N), v2(N))\n\n a = reshape([((-1)**i*(-i-5)*(i+3)+5,i=1,n**2)], shape(a))\n b = reshape([((-1)**i*(-i-1)*(i-2),i=1,n**2)], shape(a))\n\n DO i=1,N\n v1 = MATMUL(a,b(:,i))\n if (any(abs(v1-v1res(:,i)) > 1e-10)) STOP 1\n\n v2 = MATMUL(a,b(i,:))\n if (any(abs(v2-v2res(:,i)) > 1e-10)) STOP 2\n\n ENDDO\n\nEND program main\n! { dg-final { scan-tree-dump-times \"_gfortran_matmul\" 0 \"original\" } }\n", "meta": {"hexsha": "34716bc5daa4a6ac996ead4dc82bee3e95355cb3", "size": 941, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/inline_matmul_7.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/inline_matmul_7.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/inline_matmul_7.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": 26.8857142857, "max_line_length": 71, "alphanum_fraction": 0.51434644, "num_tokens": 411, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.808067204308405, "lm_q2_score": 0.8354835391516133, "lm_q1q2_score": 0.675126847727936}} {"text": "PROGRAM Test_RegCubicSpline\r\n\r\n\r\n ! This program is used to test the routines to interpolate regularly spaced arrays using cubic splines.\r\n\r\n\r\n USE :: NWTC_Library\r\n\r\n IMPLICIT NONE\r\n\r\n\r\n ! Type declarations.\r\n\r\n INTEGER, PARAMETER :: AryLen = 10 ! Index into the arrays.\r\n\r\n REAL(ReKi) :: X ! The value to interpolate for.\r\n REAL(ReKi) :: Y ! The interpolated value from regularly spaced data.\r\n REAL(ReKi) :: Z ! The interpolated value from irregularly spaced data.\r\n\r\n INTEGER :: I ! Index into the arrays.\r\n INTEGER(IntKi) :: ErrStat ! Error status.\r\n\r\n CHARACTER(4096) :: ErrMsg ! Error message.\r\n\r\n TYPE( CubSplineType) :: CubSplineData ! Derived type to hold data for irregularly spaced cubic splines.\r\n TYPE(RegCubSplineType) :: RegCubSplineData ! Derived type to hold data for regularly spaced cubic splines.\r\n\r\n\r\n\r\n ! Initialize the NWTC Library.\r\n\r\n CALL NWTC_Init ( 'Test_RegCubicSpline', 'v1.00.00, 17-May-2013', EchoLibVer=.FALSE. )\r\n CALL WrScr ( NewLine//' Running Test_RegCubicSpline (v1.00.00, 17-May-2013)' )\r\n\r\n\r\n ! Set up the regularly spaced data to be interpolated.\r\n\r\n RegCubSplineData%NumPts = 10\r\n\r\n ALLOCATE ( RegCubSplineData%XAry( RegCubSplineData%NumPts ), STAT=ErrStat )\r\n IF ( ErrStat /= 0 ) THEN\r\n CALL ProgAbort ( ' >> Error allocating memory for the RegCubSplineData%XAry array in Test_RegCubicSpline.', .FALSE., 1.0, &\r\n ErrStat )\r\n ENDIF\r\n\r\n ALLOCATE ( RegCubSplineData%YAry( RegCubSplineData%NumPts ), STAT=ErrStat )\r\n IF ( ErrStat /= 0 ) THEN\r\n CALL ProgAbort ( ' >> Error allocating memory for the RegCubSplineData%YAry array in Test_RegCubicSpline.', .FALSE., 1.0, &\r\n ErrStat )\r\n ENDIF\r\n\r\n ALLOCATE ( RegCubSplineData%Coef( RegCubSplineData%NumPts-1, 0:3 ), STAT=ErrStat )\r\n IF ( ErrStat /= 0 ) THEN\r\n CALL ProgAbort ( ' >> Error allocating memory for the RegCubSplineData%Coef array in Test_RegCubicSpline.', .FALSE., 1.0, &\r\n ErrStat )\r\n ENDIF\r\n\r\n\r\n ! Set up the irregularly spaced data to be interpolated.\r\n\r\n CubSplineData%NumPts = RegCubSplineData%NumPts\r\n\r\n ALLOCATE ( CubSplineData%XAry( CubSplineData%NumPts ), STAT=ErrStat )\r\n IF ( ErrStat /= 0 ) THEN\r\n CALL ProgAbort ( ' >> Error allocating memory for the CubSplineData%XAry array in Test_RegCubicSpline.', .FALSE., 1.0, &\r\n ErrStat )\r\n ENDIF\r\n\r\n ALLOCATE ( CubSplineData%YAry( CubSplineData%NumPts ), STAT=ErrStat )\r\n IF ( ErrStat /= 0 ) THEN\r\n CALL ProgAbort ( ' >> Error allocating memory for the CubSplineData%YAry array in Test_RegCubicSpline.', .FALSE., 1.0, &\r\n ErrStat )\r\n ENDIF\r\n\r\n ALLOCATE ( CubSplineData%Coef( CubSplineData%NumPts-1, 0:3 ), STAT=ErrStat )\r\n IF ( ErrStat /= 0 ) THEN\r\n CALL ProgAbort ( ' >> Error allocating memory for the CubSplineData%Coef array in Test_RegCubicSpline.', .FALSE., 1.0, &\r\n ErrStat )\r\n ENDIF\r\n\r\n\r\n ! Create an array to interpolate.\r\n\r\n PRINT *\r\n\r\n DO I=1,AryLen\r\n RegCubSplineData%XAry(I) = REAL( 2*I - 2 )*Pi/REAL( AryLen - 1 ) ! Values from 0 to 2*Pi in steps of 2*Pi/(AryLen-1)\r\n RegCubSplineData%YAry(I) = SIN( RegCubSplineData%XAry(I) )\r\n CubSplineData%XAry(I) = RegCubSplineData%XAry(I)\r\n CubSplineData%YAry(I) = RegCubSplineData%YAry(I)\r\n PRINT '(I5,1X,F12.4)', NINT( R2D*RegCubSplineData%XAry(I) ), RegCubSplineData%YAry(I)\r\n ENDDO ! I\r\n\r\n\r\n ! Compute the coefficients of the piecewise polynomials for the regularly-spaced data.\r\n\r\n CALL RegCubicSplineInit ( RegCubSplineData%NumPts, RegCubSplineData%XAry, RegCubSplineData%YAry, RegCubSplineData%DelX &\r\n , RegCubSplineData%Coef, ErrStat, ErrMsg )\r\n IF ( ErrStat == ErrID_Fatal ) THEN\r\n CALL ProgAbort ( ErrMsg, .FALSE., 1.0, ErrStat )\r\n ELSEIF ( ErrStat /= ErrID_None ) THEN\r\n CALL WrScr ( ErrMsg )\r\n ENDIF\r\n\r\n\r\n ! Compute the coefficients of the piecewise polynomials for the irregularly-spaced data.\r\n\r\n CALL CubicSplineInit ( CubSplineData%NumPts, CubSplineData%XAry, CubSplineData%YAry &\r\n , CubSplineData%Coef, ErrStat, ErrMsg )\r\n IF ( ErrStat == ErrID_Fatal ) THEN\r\n CALL ProgAbort ( ErrMsg, .FALSE., 1.0, ErrStat )\r\n ELSEIF ( ErrStat /= ErrID_None ) THEN\r\n CALL WrScr ( ErrMsg )\r\n ENDIF\r\n\r\n\r\n ! Write out the interpolated values for both sets of interpolated data.\r\n\r\n PRINT *\r\n\r\n DO I=0,360,1\r\n X = REAL( I )*D2R\r\n Y = RegCubicSplineInterp( X, RegCubSplineData%NumPts, RegCubSplineData%XAry, RegCubSplineData%YAry &\r\n , RegCubSplineData%DelX , RegCubSplineData%Coef, ErrStat, ErrMsg )\r\n Z = CubicSplineInterp ( X, CubSplineData%NumPts, CubSplineData%XAry, CubSplineData%YAry &\r\n , CubSplineData%Coef, ErrStat, ErrMsg )\r\n IF ( ErrStat == ErrID_Fatal ) THEN\r\n CALL ProgAbort ( ErrMsg, .FALSE., 1.0, ErrStat )\r\n ELSEIF ( ErrStat /= ErrID_None ) THEN\r\n CALL WrScr ( ErrMsg )\r\n ENDIF\r\n PRINT '(I5,2(1X,F12.4))', I, Y, Z\r\n ENDDO ! I\r\n\r\n\r\n CALL NormStop\r\n\r\nEND PROGRAM Test_RegCubicSpline", "meta": {"hexsha": "9e4ece54c6630270f0acb7f4ea83fce277706507", "size": 5821, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Drivers/Test_RegCubicSpline/Test_RegCubicSpline.f90", "max_stars_repo_name": "ghaymanNREL/NWTC_Library", "max_stars_repo_head_hexsha": "ee2266f8f4bbb602988b2830b2c0f191e8e4563d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2018-06-23T11:52:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-26T12:38:20.000Z", "max_issues_repo_path": "Drivers/Test_RegCubicSpline/Test_RegCubicSpline.f90", "max_issues_repo_name": "NWTC/NWTC_Library", "max_issues_repo_head_hexsha": "5a78d53acab9f8a3634879da9c5f69c2cdfd072a", "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": "Drivers/Test_RegCubicSpline/Test_RegCubicSpline.f90", "max_forks_repo_name": "NWTC/NWTC_Library", "max_forks_repo_head_hexsha": "5a78d53acab9f8a3634879da9c5f69c2cdfd072a", "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": 42.1811594203, "max_line_length": 144, "alphanum_fraction": 0.5729256142, "num_tokens": 1653, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.808067204308405, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.6751268460728717}} {"text": "subroutine init_phi(lo, hi, phi, philo, phihi, dx, prob_lo, prob_hi) bind(C, name=\"init_phi\")\n use amrex_fort_module, only : amrex_real\n\n implicit none\n\n integer, intent(in) :: lo(2), hi(2), philo(2), phihi(2)\n real(amrex_real), intent(inout) :: phi(philo(1):phihi(1),philo(2):phihi(2))\n real(amrex_real), intent(in ) :: dx(2) \n real(amrex_real), intent(in ) :: prob_lo(2) \n real(amrex_real), intent(in ) :: prob_hi(2) \n\n integer :: i,j\n double precision :: x,y,r2,tupi\n tupi=3.14159265358979323846d0*2d0\n\n do j = lo(2), hi(2)\n y = prob_lo(2) + (dble(j)+0.5d0) * dx(2)\n do i = lo(1), hi(1)\n x = prob_lo(1) + (dble(i)) * dx(1)\n\n r2 = ((x-0.25d0)**2 + (y-0.25d0)**2) / 0.01d0\n\n\n phi(i,j) = sin(x*tupi)\n end do\n end do\n\nend subroutine init_phi\n\nsubroutine err_phi(lo, hi, phi, philo, phihi, dx, prob_lo, prob_hi,time) bind(C, name=\"err_phi\")\n\n use amrex_fort_module, only : amrex_real\n\n implicit none\n\n integer, intent(in) :: lo(2), hi(2), philo(2), phihi(2)\n real(amrex_real), intent(inout) :: phi(philo(1):phihi(1),philo(2):phihi(2))\n real(amrex_real), intent(in ) :: dx(2) \n real(amrex_real), intent(in ) :: prob_lo(2) \n real(amrex_real), intent(in ) :: prob_hi(2) \n real(amrex_real), intent(in ) :: time\n\n integer :: i,j\n double precision :: x,y,r2,sym,tupi\n\n tupi=3.14159265358979323846d0*2d0\n sym=(-2.0d0+2.0d0*cos(tupi*dx(1)))/(dx(1)*dx(1))\n! sym=(-30.0d0+32.0d0*cos(tupi*dx(1))-2.0d0*cos(2.0d0*tupi*dx(1)))/(12.0d0*dx(1)*dx(1)) \n! print *,Tfin,tupi,sym\n do j = lo(2), hi(2)\n y = prob_lo(2) + (dble(j)+0.5d0) * dx(2) +0.0d0*time\n do i = lo(1), hi(1)\n ! x = prob_lo(1) + (dble(i)+0.5d0) * dx(1)\n x = prob_lo(1) + (dble(i)) * dx(1) +0.0d0*time\n\n r2 = ((x-0.25d0)**2 + (y-0.25d0)**2) / 0.01d0\n\n phi(i,j) = phi(i,j)-sin(x*tupi)*exp(0.1d0*time*sym)\n end do\n end do\n\nend subroutine err_phi\n", "meta": {"hexsha": "93f96ca90caadb53b38aed7b5c1bbcfdbf778d60", "size": 1929, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorials/SDC/IMEX_Advec_Diff_C/init_phi_2d.f90", "max_stars_repo_name": "ylunalin/amrex", "max_stars_repo_head_hexsha": "5715b2fc8a77e0db17bfe7907982e29ec44811ca", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Tutorials/SDC/IMEX_Advec_Diff_C/init_phi_2d.f90", "max_issues_repo_name": "ylunalin/amrex", "max_issues_repo_head_hexsha": "5715b2fc8a77e0db17bfe7907982e29ec44811ca", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Tutorials/SDC/IMEX_Advec_Diff_C/init_phi_2d.f90", "max_forks_repo_name": "ylunalin/amrex", "max_forks_repo_head_hexsha": "5715b2fc8a77e0db17bfe7907982e29ec44811ca", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-01-17T05:00:26.000Z", "max_forks_repo_forks_event_max_datetime": "2020-01-17T05:00:26.000Z", "avg_line_length": 30.619047619, "max_line_length": 96, "alphanum_fraction": 0.5780196993, "num_tokens": 820, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007394, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.6751013299201079}} {"text": "program Roman_decode\n implicit none\n\n write(*,*) decode(\"MCMXC\"), decode(\"MMVIII\"), decode(\"MDCLXVI\")\n\ncontains\n\nfunction decode(roman) result(arabic)\n character(*), intent(in) :: roman\n integer :: i, n, lastval, arabic\n\n arabic = 0\n lastval = 0\n do i = len(roman), 1, -1\n select case(roman(i:i))\n case ('M','m')\n n = 1000\n case ('D','d')\n n = 500\n case ('C','c')\n n = 100\n case ('L','l')\n n = 50\n case ('X','x')\n n = 10\n case ('V','v')\n n = 5\n case ('I','i')\n n = 1\n case default\n n = 0\n end select\n if (n < lastval) then\n arabic = arabic - n\n else\n arabic = arabic + n\n end if\n lastval = n\n end do\nend function decode\nend program Roman_decode\n", "meta": {"hexsha": "30ed1f5bbf99dd248cce6b0d05d1767ecb51ad1d", "size": 777, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Roman-numerals-Decode/Fortran/roman-numerals-decode.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/Roman-numerals-Decode/Fortran/roman-numerals-decode.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/Roman-numerals-Decode/Fortran/roman-numerals-decode.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.5, "max_line_length": 65, "alphanum_fraction": 0.4993564994, "num_tokens": 262, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637648915617, "lm_q2_score": 0.785308578375437, "lm_q1q2_score": 0.6751013290878682}} {"text": " SUBROUTINE jacobi(N,A)\n INTEGER N,T,I\n\n REAL*8 A(N,N)\n\n DO 10, T=2,100\n DO 20, I=2,N-1\n A(T,I)=A(T-1,I-1)+A(T-1,I)+A(T-1,I+1)\n 20 CONTINUE\n 10 CONTINUE\n\n END\n \n", "meta": {"hexsha": "fbc9b040b87533f12a9375a07d6e5c484ce3351a", "size": 217, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "chill/examples/chill/jacobi_simple.f", "max_stars_repo_name": "CompOpt4Apps/Artifact-DataDepSimplify", "max_stars_repo_head_hexsha": "4fa1bf2bda2902fec50a54ee79ae405a554fc9f4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2019-05-20T03:35:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-16T22:22:13.000Z", "max_issues_repo_path": "chill/examples/chill/jacobi_simple.f", "max_issues_repo_name": "CompOpt4Apps/Artifact-DataDepSimplify", "max_issues_repo_head_hexsha": "4fa1bf2bda2902fec50a54ee79ae405a554fc9f4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chill/examples/chill/jacobi_simple.f", "max_forks_repo_name": "CompOpt4Apps/Artifact-DataDepSimplify", "max_forks_repo_head_hexsha": "4fa1bf2bda2902fec50a54ee79ae405a554fc9f4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.5, "max_line_length": 49, "alphanum_fraction": 0.4285714286, "num_tokens": 88, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099167, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.6751013285925956}} {"text": "\tFUNCTION PR_PMST ( thte, tmpk )\nC************************************************************************\nC* PR_PMST \t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes parcel PRES from THTE and TMPC, where TMPC\t*\nC* is the parcel temperature at PRES on a specified moist adiabat\t*\nC* (THTE). The computation is an iterative Newton-Raphson technique\t*\nC* of the form:\t\t\t\t\t\t\t\t*\nC*\t *\nC* x = x(guess) + [ f( x ) - f( x(guess) ) ] / f'( x(guess) )\t\t*\nC*\t *\nC* f' is approximated with finite differences\t\t\t*\nC* f' = [ f( x(guess) + 1 ) - f( x(guess) ) ] / 1\t\t\t*\nC*\t *\nC* Convergence is not guaranteed for extreme input values. If the\t*\nC* computation does not converge after 100 iterations, the missing\t*\nC* data value will be returned.\t\t\t\t\t\t*\nC*\t *\nC* REAL PR_PMST ( THTE, TMPK )\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tTHTE \t\tREAL\t\tEquivalent potential temp in K\t*\nC*\tTMPK\t\tREAL\t\tParcel temperature in Kelvin\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPR_PMST \tREAL \tPressure in millibars\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* T. Lee/GSC\t\t 1/00\tCreated\t\t\t\t\t*\nC************************************************************************\n INCLUDE 'GEMPRM.PRM'\nC*\n\tLOGICAL\t\tdone\nC*\n INCLUDE 'ERMISS.FNC'\nC------------------------------------------------------------------------\n\tIF ( ERMISS ( thte ) .or. ERMISS ( tmpk )\n +\t .or. ( thte .le. 0. ) ) THEN\n\t PR_PMST = RMISSD\n\t RETURN\n\tEND IF\nC\nC*\tSet convergence and initial guess of pressure.\nC\n\tepsi = .01\n\ttmpc = PR_TMKC ( tmpk )\n\tpgdn = 1000. * ( tmpk / thte ) ** AKAPPA\nC\nC*\tSet a limit of 100 iterations. Compute TEDN and TEUP, the\nC*\tTHTE's at one degree above the guess temperature.\nC\n\tdone = .false.\n\ti = 1\n\tDO WHILE ( .not. done )\n\t pgup = pgdn + 1.\n\t tedn = PR_THTE ( pgdn, tmpc, tmpc )\n\t teup = PR_THTE ( pgup, tmpc, tmpc )\nC\nC*\t Check THTE.\nC\n\t IF ( ( ERMISS ( tedn ) ) .or. ( ERMISS ( teup ) ) ) THEN\n\t PR_PMST = RMISSD\n\t RETURN\n\t END IF\nC\nC*\t Compute the correction; return on convergence.\nC\n\t cor = ( thte - tedn ) / ( teup - tedn )\n\t pgdn = pgdn + cor\n\t IF ( ABS ( cor ) .lt. epsi ) THEN\n\t PR_PMST = pgdn\n\t RETURN\n\t END IF\n\t i = i + 1\n\t IF ( i .gt. 100 ) done = .true.\n\tEND DO\nC\nC*\tFailed to converge; return missing.\nC\n\tPR_PMST = RMISSD\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "8c29081f7402d1da79efb7880a411f310961c562", "size": 2590, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/pr/prpmst.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/prpmst.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/prpmst.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.8333333333, "max_line_length": 73, "alphanum_fraction": 0.4691119691, "num_tokens": 788, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632996617212, "lm_q2_score": 0.727975460709318, "lm_q1q2_score": 0.6750977253161548}} {"text": "program barrier_breach\r\nimplicit none\r\n\r\n! Allocate variables\r\ninteger, parameter :: dp = selected_real_kind(15, 307)\r\nreal, allocatable, dimension(:) :: bathy, row\r\ninteger :: i, j, mx, my , t1, t2, rowidx, colidx\r\nreal :: xll, yll, cellsize, nodata_value, amp_max, dx, sigma, h0, x1, x2, col, stepx, stepy\r\nreal :: time(10) != (/(i, i=0,9, 1)/)\r\nreal, dimension(10) :: amp\r\ninteger, dimension(10) :: zero_array\r\ninteger, dimension(10) :: one_array\r\nreal, dimension(600) :: y \r\nreal,allocatable, dimension(:,:) :: X_mesh, Y_mesh, breach\r\nreal, dimension(500) :: x \r\nCHARACTER(*), PARAMETER :: fileplace = \"/home/claw/clawpack-v5.5.0/geoclaw/scratch/\"\r\n! Determine number of increments for X_mesh and Y_mesh\r\nstepx = (100.0 + 100.0)/ 499.0\r\nstepy = (60e3 / 599)\r\n\r\n! fill x and y like np.linspace\r\nx = (/((i-1)*stepx -100.0, i=1,500)/)\r\ny = (/((i-1)* stepy + 0, i=1, 600)/)\r\nprint *, fileplace//'test.tt3'\r\n! Open bathy file and read header to get size\r\n! OPEN(unit=10, status=\"old\",file=fileplace//\"file1.dat\")\r\nopen(10, file=fileplace//'test.tt3', status='old')\r\n\tread(10,*) mx\r\n\tread(10,*) my\r\n\tread(10,*) xll\r\n\tread(10,*) yll\r\n\tread(10,*) cellsize\r\n\tread(10,*) nodata_value\r\nclose(10)\r\n\r\n! Declare Amplitude array based on time steps\r\nt1 = 3.0\r\nt2 = 6.0\r\namp_max = 5.0\r\ndx = 10.0/9.0\r\ntime(1:10) = [(0 + ((i-1)*dx),i=1, 10)]\r\n\r\nzero_array = 0\r\none_array = 1\r\n\r\ndo i = 1, 10\r\n\tif (time(i) < t1) then\r\n\t\tamp(i) = zero_array(i)\r\n\telseif (t1 <= time(i) .and. time(i) < t2) then\r\n\t\tamp(i) = (amp_max / (t2 - t1) * (time(i) - t1))\r\n\telseif (t2 <= time(i)) then\r\n\t\tamp(i) = one_array(i) * amp_max\r\nend if\r\n\t\r\nend do\r\n! Open and read bathymetry into memory\r\n! Skip header and declare bathy matrix\r\nallocate(bathy(1:mx*my))\r\nopen(11, file='test.tt3')\r\ndo i=1,6\r\n read(11, *)\r\nend do\r\n! Read bathy data into array\r\ndo j=1, my !*nrows\r\n read(11, *) (bathy((j-1)* mx + i),i=1,mx)\r\nend do\r\n\r\n\r\n! fill x and y matrices a la np.meshgrid\r\nallocate(X_mesh(size(y), size(x)))\r\nallocate(Y_mesh(size(y), size(x)))\r\ndo i=1, size(y)\r\n\tdo j=1, size(x)\r\n\t\tX_mesh(i,j) = x(j)\r\n\t\tY_mesh(i,j) = y(i)\r\n\tend do\r\nend do\r\n! Add breach parameters\r\nx1 = -25.0\r\nx2 = 25.0\r\nsigma = 10.0\r\nh0 = 10.0\r\nallocate(breach(size(X_mesh, 1), size(X_mesh, 2)))\r\n! Initialize breach to match initial height\r\ndo i= 1, size(X_mesh,2)\r\n\tbreach(:,i) = h0\r\n\tdo j = 1, size(X_mesh,1)\r\n\t\tbreach(j,:) = h0\r\n\tend do\r\nend do\r\n! Breach the barrier island depending on time\r\ndo i = 1, size(amp)\r\n\tdo rowidx = 1, size(X_mesh, 1)\r\n\t\trow = X_mesh(rowidx,:)\r\n\t\t\tdo colidx = 1, size(X_mesh, 2)\r\n\t\t\t\tcol = X_mesh(rowidx, colidx)\r\n\t\t\t\tif (col >= x1 .and. col <= x2) then\r\n\t\t\t\t\tbreach(rowidx, colidx) = breach(rowidx, colidx) & \r\n\t\t\t\t\t- (amp(i) * exp(-X_mesh(rowidx, colidx)**2/(sigma**2)) &\r\n\t\t\t\t\t* 0.1 * Y_mesh(rowidx, colidx))\r\n\t\t\t\tend if\r\n\t\t\tend do\r\n\tend do\r\nend do\r\n\r\n\r\nend program barrier_breach", "meta": {"hexsha": "04c35f82356df48f92066fff6e37c918a0ab36ef", "size": 2844, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "barrier_breach.f90", "max_stars_repo_name": "cjeffr/BarrierIslandBreach", "max_stars_repo_head_hexsha": "da1e570b8353c55b56344b656f927b8f127c264f", "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": "barrier_breach.f90", "max_issues_repo_name": "cjeffr/BarrierIslandBreach", "max_issues_repo_head_hexsha": "da1e570b8353c55b56344b656f927b8f127c264f", "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": "barrier_breach.f90", "max_forks_repo_name": "cjeffr/BarrierIslandBreach", "max_forks_repo_head_hexsha": "da1e570b8353c55b56344b656f927b8f127c264f", "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.5794392523, "max_line_length": 92, "alphanum_fraction": 0.6135724332, "num_tokens": 1055, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632976542184, "lm_q2_score": 0.7279754548076477, "lm_q1q2_score": 0.6750977183817496}} {"text": "!==========================================================================\nelemental function gsw_t_freezing_poly (sa, p, saturation_fraction, polynomial)\n!==========================================================================\n!\n! Calculates the in-situ temperature at which seawater freezes from a \n! computationally efficient polynomial.\n!\n! SA = Absolute Salinity [ g/kg ]\n! p = sea pressure [ dbar ]\n! ( i.e. absolute pressure - 10.1325 dbar ) \n! saturation_fraction = the saturation fraction of dissolved air in \n! seawater\n!\n! t_freezing = in-situ temperature at which seawater freezes. [ deg C ]\n! (ITS-90) \n!--------------------------------------------------------------------------\n\nuse gsw_mod_teos10_constants, only : gsw_sso\n\nuse gsw_mod_freezing_poly_coefficients\n\nuse gsw_mod_toolbox, only : gsw_ct_freezing_poly, gsw_t_from_ct\n\nuse gsw_mod_kinds\n\nimplicit none\n\nreal (r8), intent(in) :: sa, p\nreal (r8), intent(in), optional :: saturation_fraction\nlogical, intent(in), optional :: polynomial\n\nreal (r8) :: gsw_t_freezing_poly\n\nreal (r8) :: p_r, sa_r, x, ctf, sfrac\nlogical :: direct_poly\n\nif (present(polynomial)) then\n direct_poly = polynomial\nelse\n direct_poly = .false.\nend if\n\nif (.not. direct_poly) then\n\n if (present(saturation_fraction)) then\n sfrac = saturation_fraction\n else\n sfrac = 1.0_r8\n end if\n\n ctf = gsw_ct_freezing_poly(sa,p,sfrac)\n gsw_t_freezing_poly = gsw_t_from_ct(sa,ctf,p)\n\nelse\n\n ! Alternative calculation ...\n sa_r = sa*1e-2_r8\n x = sqrt(sa_r)\n p_r = p*1e-4_r8\n\n gsw_t_freezing_poly = t0 &\n + sa_r*(t1 + x*(t2 + x*(t3 + x*(t4 + x*(t5 + t6*x))))) &\n + p_r*(t7 + p_r*(t8 + t9*p_r)) &\n + sa_r*p_r*(t10 + p_r*(t12 + p_r*(t15 + t21*sa_r)) &\n + sa_r*(t13 + t17*p_r + t19*sa_r) &\n + x*(t11 + p_r*(t14 + t18*p_r) + sa_r*(t16 + t20*p_r + t22*sa_r)))\n\n if (.not. present(saturation_fraction)) return\n\n ! Adjust for the effects of dissolved air\n gsw_t_freezing_poly = gsw_t_freezing_poly - &\n saturation_fraction*(1e-3_r8)*(2.4_r8 - sa/(2.0_r8*gsw_sso))\nend if\n\nreturn\nend function\n\n!--------------------------------------------------------------------------\n", "meta": {"hexsha": "479a323d2cc61ec78a5e866c86f605d24fcc24da", "size": 2338, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "MOM6-interface/MOM6/pkg/GSW-Fortran/toolbox/gsw_t_freezing_poly.f90", "max_stars_repo_name": "minsukji/ci-debug", "max_stars_repo_head_hexsha": "3e8bbbe6652b702b61d2896612f6aa8e4aa6c803", "max_stars_repo_licenses": ["Apache-2.0", "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": "MOM6-interface/MOM6/pkg/GSW-Fortran/toolbox/gsw_t_freezing_poly.f90", "max_issues_repo_name": "minsukji/ci-debug", "max_issues_repo_head_hexsha": "3e8bbbe6652b702b61d2896612f6aa8e4aa6c803", "max_issues_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-05-21T20:21:16.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-06T17:52:34.000Z", "max_forks_repo_path": "MOM6-interface/MOM6/pkg/GSW-Fortran/toolbox/gsw_t_freezing_poly.f90", "max_forks_repo_name": "minsukji/ci-debug", "max_forks_repo_head_hexsha": "3e8bbbe6652b702b61d2896612f6aa8e4aa6c803", "max_forks_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.5949367089, "max_line_length": 79, "alphanum_fraction": 0.5414884517, "num_tokens": 650, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632876167045, "lm_q2_score": 0.727975460709318, "lm_q1q2_score": 0.6750977165476783}} {"text": " subroutine ire_dph(ctfmp,n_K,n_alpha,n_beta,n_divbeta,n_phi,nm1_ph\n &i,np1_phi,Nx,ht,hx,res)\n implicit none\n integer i\n integer Nx\n real*8 ht\n real*8 hx\n real*8 ctfmp(Nx)\n real*8 n_K(Nx)\n real*8 n_alpha(Nx)\n real*8 n_beta(Nx)\n real*8 n_divbeta(Nx)\n real*8 n_phi(Nx)\n real*8 nm1_phi(Nx)\n real*8 np1_phi(Nx)\n real*8 res\n real*8 qb\n res = 0.0D0\n do i=2, Nx-1, 1\n qb = 0.5000000000000000D0 * (-0.1D1 * nm1_phi(i) + np1_phi(i)) / h\n #t + 0.5000000000000000D0 / ctfmp(i) * (n_phi(i - 1) - 0.1D1 * n_ph\n #i(i + 1)) / hx * n_beta(i) + 0.1666666666666667D0 * n_alpha(i) * n\n #_K(i) - 0.1666666666666667D0 * n_divbeta(i)\n res = res + qb**2\n end do\n res = sqrt(res/(1*Nx))\n END\n", "meta": {"hexsha": "a3e9e1a7ffeaa5ade9562a1b063ca5ff934daa7e", "size": 799, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/FD/ire_dph.f", "max_stars_repo_name": "rmanak/bssn_spher", "max_stars_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/FD/ire_dph.f", "max_issues_repo_name": "rmanak/bssn_spher", "max_issues_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/FD/ire_dph.f", "max_forks_repo_name": "rmanak/bssn_spher", "max_forks_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.5357142857, "max_line_length": 72, "alphanum_fraction": 0.5481852315, "num_tokens": 335, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632956467157, "lm_q2_score": 0.7279754371026367, "lm_q1q2_score": 0.6750977005013595}} {"text": "subroutine step_forwards\n use systemparams\n implicit none\n tt(:) = 0.0\n do i=1,nx+1\n if(i/=1.and.i/=nx+1) then\n tt(i) = (deltax(i)*deltax(i)*C_tot(i))/(2.0*0.5*diff*((1.0-x(i+1)*x(i+1)) + (1.0-x(i)*x(i))))\n else\n tt(i) = 1.0e30\n end if\n end do\n dt=0.9*minval(tt) \nend subroutine step_forwards\n", "meta": {"hexsha": "15e81d5e702674326732bc9220f881b033308e67", "size": 324, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/step_forwards.f90", "max_stars_repo_name": "mjdbahram/exoClimate", "max_stars_repo_head_hexsha": "48ae1ea333d8ca117dd736da575fd1f2a55012f4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/step_forwards.f90", "max_issues_repo_name": "mjdbahram/exoClimate", "max_issues_repo_head_hexsha": "48ae1ea333d8ca117dd736da575fd1f2a55012f4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/step_forwards.f90", "max_forks_repo_name": "mjdbahram/exoClimate", "max_forks_repo_head_hexsha": "48ae1ea333d8ca117dd736da575fd1f2a55012f4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.1428571429, "max_line_length": 101, "alphanum_fraction": 0.5586419753, "num_tokens": 143, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.927363293639213, "lm_q2_score": 0.7279754371026367, "lm_q1q2_score": 0.6750976990399469}} {"text": " Program zunghr_example\n\n! ZUNGHR Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use blas_interfaces, Only: zgemm\n Use lapack_example_aux, Only: nagf_file_print_matrix_complex_gen_comp\n Use lapack_interfaces, Only: zgehrd, zhseqr, zlange, zunghr\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nin = 5, nout = 6\n! .. Local Scalars ..\n Complex (Kind=dp) :: alpha, beta\n Real (Kind=dp) :: norm\n Integer :: i, ifail, info, lda, ldc, ldd, ldz, lwork, n\n! .. Local Arrays ..\n Complex (Kind=dp), Allocatable :: a(:, :), c(:, :), d(:, :), tau(:), &\n w(:), work(:), z(:, :)\n Real (Kind=dp), Allocatable :: rwork(:)\n Character (1) :: clabs(1), rlabs(1)\n! .. Intrinsic Procedures ..\n Intrinsic :: cmplx, epsilon\n! .. Executable Statements ..\n Write (nout, *) 'ZUNGHR Example Program Results'\n Write (nout, *)\n Flush (nout)\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n\n lda = n\n ldc = n\n ldd = n\n ldz = n\n lwork = 64*(n-1)\n Allocate (a(lda,n), c(ldc,n), d(ldd,n), rwork(lda), tau(n), w(n), &\n work(lwork), z(ldz,n))\n\n! Read A from data file\n Read (nin, *)(a(i,1:n), i=1, n)\n\n! Store A in D\n d(1:ldd, 1:n) = a(1:lda, 1:n)\n\n! Print matrix A\n! ifail: behaviour on error exit\n! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft\n ifail = 0\n Call nagf_file_print_matrix_complex_gen_comp('General', ' ', n, n, a, &\n lda, 'Bracketed', 'F7.4', 'Matrix A', 'Integer', rlabs, 'Integer', &\n clabs, 80, 0, ifail)\n Write (nout, *)\n Flush (nout)\n\n! Reduce A to upper Hessenberg form H = (Q**H)*A*Q\n\n Call zgehrd(n, 1, n, a, lda, tau, work, lwork, info)\n\n! Copy A into Z\n z(1:n, 1:n) = a(1:n, 1:n)\n\n! Form Q explicitly, storing the result in Z\n Call zunghr(n, 1, n, z, ldz, tau, work, lwork, info)\n\n! Calculate the Schur factorization of H = Y*T*(Y**H) and form\n! Q*Y explicitly, storing the result in Z\n\n! Note that A = Z*T*(Z**H), where Z = Q*Y\n\n Call zhseqr('Schur form', 'Vectors', n, 1, n, a, lda, w, z, ldz, work, &\n lwork, info)\n\n! Compute A - Z*T*Z^H from Schur factorization of A, and store in matrix D\n alpha = cmplx(1, kind=dp)\n beta = cmplx(0, kind=dp)\n Call zgemm('N', 'N', n, n, n, alpha, z, ldz, a, lda, beta, c, ldc)\n alpha = cmplx(-1, kind=dp)\n beta = cmplx(1, kind=dp)\n Call zgemm('N', 'C', n, n, n, alpha, c, ldc, z, ldz, beta, d, ldd)\n\n! Find norm of matrix D and print warning if it is too large\n norm = zlange('O', ldd, n, d, ldd, rwork)\n If (norm>epsilon(1.0E0_dp)**0.5_dp) Then\n Write (nout, *) 'Norm of A-(Z*T*Z^H) is much greater than 0.'\n Write (nout, *) 'Schur factorization has failed.'\n Else\n! Print eigenvalues.\n Write (nout, *) 'Eigenvalues'\n Write (nout, 100)(w(i), i=1, n)\n End If\n\n100 Format ((3X,4(' (',F7.4,',',F7.4,')',:)))\n\n End Program\n", "meta": {"hexsha": "1404c97e5f74e08a7809a48d32cd14b99e064914", "size": 3312, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/zunghr_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/zunghr_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/zunghr_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 33.12, "max_line_length": 90, "alphanum_fraction": 0.5543478261, "num_tokens": 1136, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813453, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6750781561754479}} {"text": "\tSUBROUTINE DESPLN ( np, xpt, ypt, chord, xtng, ytng, npt,\n +\t\t\t xcv, ycv, iret )\nC************************************************************************\nC* DESPLN\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This subroutine evalutes a smooth curve using cubic splines.\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* DESPLN ( NP, XPT, YPT, CHORD, XTNG, YTNG, NPT, XCV, YCV, IRET )\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tNP\t\tINTEGER\t\tNumber of input points\t\t*\nC*\tXPT (NP)\tREAL\t\tX input coordinates\t\t*\nC*\tYPT (NP)\tREAL\t\tY input coordinates\t\t*\nC*\tCHORD (NP)\tREAL\t\tChord lengths\t\t\t*\nC*\tXTNG (NP)\tREAL\t\tX comp of tangent vectors\t*\nC*\tYTNG (NP)\tREAL\t\tY comp of tangent vectors\t*\nC*\tNPT (NP)\tINTEGER\t\tNumber of points per segment\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tXCV (NOUT)\tREAL\t\tX evaluated coordinates\t\t*\nC*\tYCV (NOUT)\tREAL\t\tY evaluated coordinates\t\t*\nC*\tIRET\t\tINTEGER\t\tReturn code\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* S. Jacobs/NCEP\t 2/98\t\t\t\t\t\t*\nC************************************************************************\n\tINCLUDE\t\t'GEMPRM.PRM'\nC*\n\tINTEGER\t\tnpt (*)\n\tREAL\t\txpt (*), ypt (*), chord(*), xtng (*), ytng (*),\n +\t\t\txcv (*), ycv (*)\nC------------------------------------------------------------------------\n\tiret = 0\nC\n\tk = 1\n\tDO i = 1, np-1\nC\nC*\t Compute the coefficents for the polynomial.\nC\n\t f11 = xpt(i)\n\t f12 = ypt(i)\nC\n\t f21 = xtng(i)\n\t f22 = ytng(i)\nC\n\t q = 1 / chord(i)\n\t qs = q ** 2\nC\n\t q1 = q * 3.0 * ( xpt(i+1) - xpt(i) )\n\t f31 = q * ( q1 - 2.0*xtng(i) - xtng(i+1) )\n\t q1 = q * 3.0 * ( ypt(i+1) - ypt(i) )\n\t f32 = q * ( q1 - 2.0*ytng(i) - ytng(i+1) )\nC\n\t q1 = q * 2.0 * ( xpt(i) - xpt(i+1) )\n\t f41 = qs * ( q1 + xtng(i) + xtng(i+1) )\n\t q1 = q * 2.0 * ( ypt(i) - ypt(i+1) )\n\t f42 = qs * ( q1 + ytng(i) + ytng(i+1) )\nC\nC*\t Compute the points along the smooth curve.\nC\n\t xcv(k) = xpt(i)\n\t ycv(k) = ypt(i)\n\t k = k + 1\n\t IF ( npt(i) .ne. 0 ) THEN\n\t\tdelt = chord(i) / FLOAT(npt(i)+1)\n\t\ttt = 0.0\n\t\tDO j = 1, npt(i)\n\t\t tt = tt + delt\n\t\t xcv(k) = f11 + f21*tt + f31*(tt**2) + f41*(tt**3)\n\t\t ycv(k) = f12 + f22*tt + f32*(tt**2) + f42*(tt**3)\n\t\t k = k + 1\n\t\tEND DO\n\t END IF\n\tEND DO\nC\n\txcv(k) = xpt(np)\n\tycv(k) = ypt(np)\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "fa193dcf0f498a78c6e5aa0fdf0c9caeea3ddad1", "size": 2218, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/device/curve/despln.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/device/curve/despln.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/device/curve/despln.f", "max_forks_repo_name": "oxelson/gempak", "max_forks_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 27, "max_forks_repo_forks_event_min_datetime": "2016-06-06T21:55:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T18:23:28.000Z", "avg_line_length": 27.3827160494, "max_line_length": 73, "alphanum_fraction": 0.4486023445, "num_tokens": 912, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6750781520589323}} {"text": "! this subroutine is used to calculate surface state using !\n! green's function method --- J.Phys.F.Met.Phys.15(1985)851-858 !\n! Using eq.(11) and eq.(13) (16), (17)\n! History:\n! by Quan Sheng Wu on Oct/17/2012 !\n!+---------+---------+---------+---------+---------+---------+--------+!\n subroutine surfgreen_1985(omega,GLL,GRR,GB,H00,H01,ones)\n use para\n implicit none\n\n ! inout variables \n ! the factor 2 is induced by spin\n ! energy hbar omega\n real(Dp),intent(in) :: omega \n\n ! H00 Hamiltonian between nearest neighbour-quintuple-layers\n complex(Dp),intent(in) :: H00(Ndim,Ndim)\n\n ! H01 Hamiltonian between next-nearest neighbour-quintuple-layers\n complex(Dp),intent(in) :: H01(Ndim,Ndim)\n\n ! temp hamiltonian\n\n complex(Dp),intent(in) :: ones(Ndim,Ndim)\n\n ! surface green function\n complex(Dp),intent(inout) :: GLL(Ndim,Ndim)\n complex(Dp),intent(inout) :: GRR(Ndim,Ndim)\n\n !> bulk green's function\n complex(Dp),intent(inout) :: GB(Ndim,Ndim)\n\n ! >> local variables\n ! iteration number\n integer :: iter\n\n ! maximun iteration \n integer ,parameter:: itermax=100\n\n ! accuracy control\n real(Dp) :: accuracy=1e-16\n\n ! a real type temp variable\n real(Dp) :: real_temp\n\n ! omegac=omega(i)+I * eta\n complex(Dp) :: omegac \n\n\n ! some variables in Eq.(11)\n complex(Dp), allocatable :: alphai(:, :) \n complex(Dp), allocatable :: betai(:, :) \n complex(Dp), allocatable :: epsiloni(:, :) \n complex(Dp), allocatable :: epsilons(:, :) \n complex(Dp), allocatable :: epsilons_t(:, :) \n\n complex(Dp), allocatable :: mat1 (:, :) \n complex(Dp), allocatable :: mat2 (:, :) \n\n ! g0= inv(w-e_i)\n complex(Dp), allocatable :: g0 (:, :) \n\n ! allocate some variables\n allocate(alphai(Ndim, Ndim)) \n allocate(betai (Ndim, Ndim)) \n allocate(epsiloni (Ndim, Ndim)) \n allocate(epsilons (Ndim, Ndim)) \n allocate(epsilons_t(Ndim, Ndim)) \n allocate(mat1(Ndim, Ndim)) \n allocate(mat2(Ndim, Ndim)) \n allocate(g0(Ndim, Ndim)) \n\n epsiloni= H00\n epsilons= H00\n epsilons_t= H00\n alphai = H01\n betai = conjg(transpose(H01))\n !print *, sqrt(sum(abs(H00)**2)), 'H00'\n\n ! w+i*0^+\n omegac= dcmplx(omega, eta)\n !print *, omegac\n\n ! begin iteration\n do iter=1, itermax\n\n g0= omegac*ones- epsiloni\n call inv(Ndim, g0, ones)\n\n ! a_i-1*(w-e_i-1)^-1\n call mat_mul(Ndim, alphai, g0, mat1 )\n \n ! b_i-1*(w-e_i-1)^-1\n call mat_mul(Ndim, betai, g0, mat2 )\n\n ! a_i-1*(w-e_i-1)^-1*b_i-1\n call mat_mul(Ndim, mat1, betai, g0)\n epsiloni= epsiloni+ g0\n !print *, sqrt(sum(abs(epsiloni)**2)), 'ei'\n ! es_i= es_i-1 + a_i-1*(w-e_i-1)^-1*b_i-1\n epsilons= epsilons+ g0\n !print *, sqrt(sum(abs(epsilons)**2)), 'es'\n !pause\n\n ! b_i-1*(w-e_i-1)^-1*a_i-1\n call mat_mul(Ndim, mat2, alphai, g0)\n epsiloni= epsiloni+ g0\n ! es_i= es_i-1 + a_i-1*(w-e_i-1)^-1*b_i-1\n epsilons_t= epsilons_t+ g0\n\n ! a_i= a_i-1*(w-e_i-1)^-1*a_i-1 \n call mat_mul(Ndim, mat1, alphai, g0)\n alphai= g0\n ! b_i= b_i-1*(w-e_i-1)^-1*b_i-1 \n call mat_mul(Ndim, mat2, betai, g0)\n betai= g0\n\n !real_temp=maxval(abs(alphai)) \n real_temp=sum(abs(alphai)) \n !if (cpuid.eq.0) print *, iter, real_temp\n if (real_temp.le.accuracy) exit\n\n enddo ! end of iteration\n\n ! calculate surface green's function\n GLL= omegac*ones- epsilons\n call inv(Ndim, GLL, ones)\n\n GRR= omegac*ones- epsilons_t\n call inv(Ndim, GRR, ones)\n\n GB = omegac*ones- epsiloni\n call inv(Ndim, GB, ones)\n\n return\n end subroutine surfgreen_1985\n\n\n!+---------+---------+---------+---------+---------+---------+--------+!\n! this subroutine is used to calculate surface state using !\n! green's function method --- J.Phys.F.Met.Phys.14(1984)1205-1215 !\n! Quick iterative scheme for the calculation of transfer matrices:\n! application to Mo (100) \n! History:\n! by Quan Sheng Wu on 4/20/2010 !\n! mpi version 4/21/2010\n! little change to cpu version in Zurich Swiss Jan 25 2015\n!+---------+---------+---------+---------+---------+---------+--------+!\n subroutine surfgreen_1984(omega,GLL,GRR,H00,H01,ones)\n\n use wmpi\n use para\n implicit none\n \n\n ! general loop index\n integer :: i,j \n\n ! iteration loop index\n integer :: it\n\n ! iteration number\n integer :: iter\n\n ! maximun iteration \n integer ,parameter :: itermax=100\n\n ! accuracy control\n real(Dp),parameter :: accuracy=1e-6\n\n ! a real type temp variable\n real(Dp) :: real_temp\n\n ! frequency \n real(Dp),intent(in) :: omega\n\n ! energy energy=omega(i)+I * eta\n complex(Dp) :: energy\n\n ! surface green fuction an output variable\n complex(Dp),intent(out) :: GLL(Ndim,Ndim)\n complex(Dp),intent(out) :: GRR(Ndim,Ndim)\n\n ! H00 Hamiltonian between nearest neighbour-quintuple-layers\n ! the factor 2 is induced by spin\n complex(Dp),intent(in) :: H00(Ndim,Ndim)\n\n ! H01 Hamiltonian between next-nearest neighbour-quintuple-layers\n complex(Dp),intent(in) :: H01(Ndim,Ndim)\n\n ! unit matrix ones\n complex(Dp),intent(in) :: ones(Ndim,Ndim)\n\n complex(Dp),allocatable :: H01dag(:,:)\n\n !> surface hamiltonian\n complex(Dp),allocatable :: Hs(:,:)\n\n ! temp hamiltonian\n complex(Dp),allocatable :: t0(:,:)\n complex(Dp),allocatable :: Tmatrix(:,:)\n complex(Dp),allocatable :: Tmatrixt(:,:)\n complex(Dp),allocatable :: t0tilde(:,:)\n complex(Dp),allocatable :: tnew(:,:)\n complex(Dp),allocatable :: tnewtilde(:,:)\n complex(Dp) ,allocatable :: told(:,:)\n complex(Dp),allocatable :: toldtilde(:,:)\n complex(Dp),allocatable :: temp(:,:)\n complex(Dp),allocatable :: Tmat_temp(:,:)\n complex(Dp),allocatable :: Tmat_tempt(:,:)\n\n real(Dp),allocatable :: abs_told(:,:)\n\n ! allocate variables\n allocate(Hs(ndim,ndim))\n allocate(t0(ndim,ndim))\n allocate(Tmatrix(ndim,ndim))\n allocate(Tmatrixt(ndim,ndim))\n allocate(t0tilde(ndim,ndim))\n allocate(tnew(ndim,ndim))\n allocate(tnewtilde(ndim,ndim))\n allocate(told(ndim,ndim))\n allocate(toldtilde(ndim,ndim))\n allocate(temp(ndim,ndim))\n allocate(Tmat_temp(ndim,ndim))\n allocate(Tmat_tempt(ndim,ndim))\n allocate(abs_told(ndim,ndim))\n \n allocate(H01dag(ndim,ndim))\n \n Hs=0.0d0\n t0=0.0d0\n t0tilde=0.0d0\n told=0.0d0\n toldtilde=0.0d0\n tnew=0.0d0\n tnewtilde=0.0d0\n Tmatrix=0.0d0\n Tmatrixt=0.0d0\n temp=0.0d0\n abs_told=0.0d0 \n Tmat_temp=0.0d0\n\t GLL=0d0\n\t GRR=0d0\n Tmat_tempt=0.0d0\n H01dag=0.0d0 \n \n ! H01dag=H01^dag\n do i=1,ndim\n do j=1,ndim\n H01dag(i,j)=conjg(H01(j,i))\n enddo\n enddo\n\n energy=omega+zi*eta\n temp=energy*ones-H00\n\n\n call inv(ndim,temp)\n t0= matmul(temp,H01dag) \n t0tilde= matmul(temp,H01)\n told=t0\n toldtilde=t0tilde\n\n ! begin iteration\n iter=0 \n Tmatrix=0.0d0 \n Tmat_temp=ones\n Tmatrixt=0.0d0 \n Tmat_tempt=ones\n ITER1 : do it=1,itermax\n iter=iter+1\n\n temp=ones-matmul(told,toldtilde)-matmul(toldtilde,told)\n call inv(ndim,temp)\n\n tnew=matmul(temp,told)\n tnew=matmul(tnew,told)\n tnewtilde=matmul(temp,toldtilde)\n tnewtilde=matmul(tnewtilde,toldtilde)\n\n Tmat_temp=matmul(Tmat_temp,toldtilde)\n Tmatrix=Tmatrix+matmul(Tmat_temp,tnew)\n \n\t\t Tmat_tempt=matmul(Tmat_tempt,told)\n Tmatrixt=Tmatrixt+matmul(Tmat_tempt,tnewtilde)\n \n told=tnew\n toldtilde=tnewtilde\n \n do i=1,ndim \n do j=1,ndim\n abs_told(i,j)=abs(told(i,j))+abs(toldtilde(i,j)) \n enddo \n enddo \n real_temp=maxval(abs_told) \n if (real_temp.le.accuracy) exit ITER1 \n \n end do ITER1\n\n !print *,'iter,acc',iter,real_temp\n\n !> set up surface hamiltonian\n !> usually Hs= H00\n !> but you can add static potential on the surface\n Hs= H00\n do i=1, ndim\n Hs(i, i)=Hs(i, i)+ surf_onsite\n enddo\n \n Tmatrix=t0+Tmatrix\n temp=energy*ones-Hs-matmul(H01,Tmatrix) \n call inv(ndim,temp)\n \n ! g_00=(epsilon-Hs -H01*T)^-1\n GLL(1:ndim,1:ndim)=temp\n\n Tmatrixt=t0tilde+Tmatrixt\n temp=energy*ones-Hs -matmul(conjg(transpose(H01)),Tmatrixt) \n call inv(ndim,temp)\n\n ! g_00=(epsilon-Hs -H01*T)^-1\n GRR(1:ndim,1:ndim)=temp\n\n return \n end subroutine surfgreen_1984\n", "meta": {"hexsha": "a20c5448e31e8e2b5cdd147e7c3876f2412d0e2a", "size": 8826, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "soc/surfgreen.f90", "max_stars_repo_name": "dlnguyen/wannier_tools", "max_stars_repo_head_hexsha": "cc6748e3718ee2a89934a187490c37f9f520aeff", "max_stars_repo_licenses": ["OLDAP-2.3"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-14T12:07:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-14T12:07:24.000Z", "max_issues_repo_path": "stable/surfgreen.f90", "max_issues_repo_name": "jtsun/wannier_tools", "max_issues_repo_head_hexsha": "f3512e986c6546af6b823ee6b8a4b9118c53a9fa", "max_issues_repo_licenses": ["OLDAP-2.3"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "stable/surfgreen.f90", "max_forks_repo_name": "jtsun/wannier_tools", "max_forks_repo_head_hexsha": "f3512e986c6546af6b823ee6b8a4b9118c53a9fa", "max_forks_repo_licenses": ["OLDAP-2.3"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.9908256881, "max_line_length": 74, "alphanum_fraction": 0.5717199184, "num_tokens": 2937, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953003183444, "lm_q2_score": 0.752012568201972, "lm_q1q2_score": 0.6750781482552388}} {"text": "demonstration of the em algorithm for fitting two lines to a bunch of points in the e step we try to estimate the probability that each point is actually on each of the lines then in the m step we redraw the lines to maxmimize the likelihood of the points rob malouf malouf let rug nl 25 may 2000 alfa informatica university of groningen postbus 716 9737nt groningen this program uses the pgplot subroutine library available at ftp astro caltech edu pub pgplot program em1 character key real x 10 y 10 model 2 2 yd 10 w1 10 w2 10 r1 10 r2 10 c real parameter s2 0.1 integer seed 1 set up display if pgopen xwindow lt 1 stop set up data call system_clock count seed 1 call random_seed put seed call random_number model x 1 2 3 4 5 6 7 8 9 1 y 1 5 x 1 5 model 1 1 model 1 2 y 6 10 x 6 10 model 2 1 model 2 2 y 1 5 x 1 5 1 y 6 10 x 6 10 initialize model call random_number model do while true e step r1 model 1 1 x model 1 2 y r2 model 2 1 x model 2 2 y w1 exp r1 r1 s2 exp r1 r1 s2 exp r2 r2 s2 w2 exp r2 r2 s2 exp r1 r1 s2 exp r2 r2 s2 display results call pgsubp 1 3 call pgsubp 1 2 call pgsci 1 call pgenv 0 1 minval y maxval y 0 0 call pglab x y em algorithm call pgsci 2 call pgpt 10 x y 2 call pgsci 3 yd x model 1 1 model 1 2 call pgline 10 x yd call pgsci 4 yd x model 2 1 model 2 2 call pgline 10 x yd call pgsci 1 call pgenv 0 1 0 1 0 0 call pgsci 2 call pgbin 10 x w1 true call pgbcht 10 1 w1 label 0 1 1 2 call pgsci 1 call pgenv 0 1 0 1 0 0 call pgsci 2 call pgbin 10 x w2 false call pgbcht 10 1 w2 label 0 1 1 2 call pgclos m step c 1 sum w1 x x sum w1 sum w1 x sum w1 x model 1 1 c sum w1 sum w1 x y sum w1 x sum w1 y model 1 2 c sum w1 x x sum w1 y sum w1 x sum w1 x y c 1 sum w2 x x sum w2 sum w2 x sum w2 x model 2 1 c sum w2 sum w2 x y sum w2 x sum w2 y model 2 2 c sum w2 x x sum w2 y sum w2 x sum w2 x y end do end program em1\n", "meta": {"hexsha": "027435330ffdeac54e868b3a93a68c52a06cd71b", "size": 1846, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "pa1-skeleton/pa1-data/6/www-nlp.stanford.edu_fsnlp_clustering_em1.f90", "max_stars_repo_name": "yzhong94/cs276-spring-2019", "max_stars_repo_head_hexsha": "a4780a9f88b8c535146040fe11bb513c91c5693b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "pa1-skeleton/pa1-data/6/www-nlp.stanford.edu_fsnlp_clustering_em1.f90", "max_issues_repo_name": "yzhong94/cs276-spring-2019", "max_issues_repo_head_hexsha": "a4780a9f88b8c535146040fe11bb513c91c5693b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "pa1-skeleton/pa1-data/6/www-nlp.stanford.edu_fsnlp_clustering_em1.f90", "max_forks_repo_name": "yzhong94/cs276-spring-2019", "max_forks_repo_head_hexsha": "a4780a9f88b8c535146040fe11bb513c91c5693b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 923.0, "max_line_length": 1845, "alphanum_fraction": 0.7426868906, "num_tokens": 718, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952921073469, "lm_q2_score": 0.752012562644147, "lm_q1q2_score": 0.675078137091232}} {"text": " function shield(reyn)\nc\nc + + + PURPOSE + + +\nc\nc Function SHIELD generates parameters (shield parameters)\nc by interpolating values from a table (shield diagram)\nc for given Reynolds numbers.\nc\nc Called from: SRS TRNCAP, YALIN\nc Author(s): Ascough II, R. van der Zweep, V. Lopes\nc Reference in User Guide:\nc\nc Version:\nc Date recoded:\nc Recoded by: Jim Ascough II\nc\nc + + + KEYWORDS + + +\nc\nc + + + PARAMETERS + + +\nc\nc + + + ARGUMENT DECLARATIONS + + +\nc\n real reyn\nc\nc + + + ARGUMENT DEFINITIONS + + +\nc\nc reyn -\nc\nc + + + COMMON BLOCKS + + +\nc\nc + + + LOCAL VARIABLES + + +\nc\n real y(8), r(8), shield, slope, ycr\n integer i\nc\nc + + + LOCAL DEFINITIONS + + +\nc\nc Real Variables\nc\nc y(8) -\nc r(8) -\nc shield -\nc slope -\nc ycr -\nc\nc Integer Variables\nc\nc i -\nc\nc + + + SAVES + + +\nc\n save\nc\nc + + + SUBROUTINES CALLED + + +\nc\nc + + + DATA INITIALIZATIONS + + +\nc\n data y /0.0772, 0.0579, 0.04, 0.035, 0.034, 0.045, 0.055, 0.057/\n data r /1.0, 2.0, 4.0, 8.0, 12.0, 100.0, 400.0, 1000.0/\nc\nc + + + END SPECIFICATIONS + + +\nc\nc\n if (reyn.lt.r(1)) then\n i = 2\n slope = (alog(y(i))-alog(y(i-1))) / (alog(r(i))-alog(r(i-1)))\n ycr = alog(y(1)) - slope * (alog(r(1))-alog(reyn))\n else if (reyn.gt.r(8)) then\n i = 8\n slope = (alog(y(i))-alog(y(i-1))) / (alog(r(i))-alog(r(i-1)))\n ycr = y(8) + slope * (alog(reyn)-alog(r(8)))\nc\n else\nc\n do 10 i = 2, 8\nc\n if (reyn.ge.r(i-1).and.reyn.le.r(i)) then\n slope = (alog(y(i))-alog(y(i-1))) / (alog(r(i))-\n 1 alog(r(i-1)))\n ycr = alog(y(i-1)) + slope * (alog(reyn)-alog(r(i-1)))\n go to 20\n end if\nc\n 10 continue\nc\n end if\nc\n 20 shield = exp(ycr)\nc\n return\n end\n", "meta": {"hexsha": "a83c9efe0b257d5e8864e37d108ca78f7fea1d87", "size": 1906, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/wepp2012-src/shield.for", "max_stars_repo_name": "jarad/dep", "max_stars_repo_head_hexsha": "fe73982f4c70039e1a31b9e8e2d9aac31502f803", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-11-26T17:49:19.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-26T17:49:19.000Z", "max_issues_repo_path": "src/wepp2012-src/shield.for", "max_issues_repo_name": "jarad/dep", "max_issues_repo_head_hexsha": "fe73982f4c70039e1a31b9e8e2d9aac31502f803", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 54, "max_issues_repo_issues_event_min_datetime": "2018-12-12T18:02:31.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T19:14:25.000Z", "max_forks_repo_path": "src/wepp2012-src/shield.for", "max_forks_repo_name": "akrherz/idep", "max_forks_repo_head_hexsha": "7189a26fbcec3d8c3cc7d7015107b8fb6c5f6a45", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-03-02T22:59:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-09T15:49:00.000Z", "avg_line_length": 20.7173913043, "max_line_length": 70, "alphanum_fraction": 0.4916054565, "num_tokens": 728, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952811593494, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6750781338474338}} {"text": "module mod_datetime\n\n use iso_fortran_env, only: real64\n \n implicit none\n\n private\n public :: current_time, datetime, get_date_from_cli, timedelta\n\n type :: datetime\n integer :: year, month, day\n integer :: hour = 0, minute = 0, second = 0\n contains\n procedure, pass(d1) :: datetime_minus_datetime\n generic :: operator(-) => datetime_minus_datetime\n end type datetime\n\n type :: timedelta\n integer :: days = 0, hours = 0, minutes = 0, seconds = 0\n end type timedelta\n\ncontains\n\n pure elemental type(timedelta) function datetime_minus_datetime(d1, d2) result(t)\n\n class(datetime),intent(in) :: d1, d2\n real(real64) :: days_diff, ndays1, ndays2, sgn\n integer :: days, hours, minutes, seconds, year\n\n real, parameter :: d2h = 24. ! day -> hour\n real, parameter :: h2d = 1. / d2h ! hour -> day\n real, parameter :: d2m = d2h * 60 ! day -> minute\n real, parameter :: m2d = 1. / d2m ! minute -> day\n real, parameter :: s2d = m2d / 60. ! second -> day\n real, parameter :: d2s = 1. / s2d ! day -> second\n\n ndays1 = 1.0_real64 &\n * sum([(days_in_year(year), year = 1, d1 % year - 1)])&\n + yearday(d1 % year, d1 % month, d1 % day) &\n + d1 % hour * h2d &\n + d1 % minute * m2d &\n + d1 % second * s2d\n\n ndays2 = 1.0_real64 &\n * sum([(days_in_year(year), year = 1, d2 % year - 1)])&\n + yearday(d2 % year, d2 % month, d2 % day) &\n + d2 % hour * h2d &\n + d2 % minute * m2d &\n + d2 % second * s2d\n\n days_diff = ndays1 - ndays2\n\n sgn = sign(1.0_real64, days_diff)\n\n days = int(abs(days_diff))\n hours = int((abs(days_diff) - days) * d2h)\n minutes = int((abs(days_diff) - days - hours * h2d) * d2m)\n seconds = int((abs(days_diff) - days - hours * h2d & \n - minutes * m2d) * d2s)\n\n t = timedelta(sgn * days, sgn * hours, sgn * minutes, sgn * seconds)\n\n end function datetime_minus_datetime\n\n pure elemental integer function days_in_month(month, year)\n ! Given input month and year, \n ! returns the number of days in the month.\n integer, intent(in) :: month, year\n integer, parameter :: days(*) = [31, 28, 31, 30, 31, 30, &\n 31, 31, 30, 31, 30, 31]\n if (month < 1 .or. month > 12) then\n days_in_month = 0\n else if (month == 2 .and. is_leap_year(year)) then\n days_in_month = 29\n else\n days_in_month = days(month)\n end if\n end function days_in_month\n\n pure elemental integer function days_in_year(year)\n ! Given input year, returns the number of days in year.\n integer, intent(in) :: year\n if (is_leap_year(year)) then\n days_in_year = 366\n else\n days_in_year = 365\n end if\n end function days_in_year\n\n subroutine get_date_from_cli(date)\n ! Reads year, month, and day from the command line\n ! and returns the corresponding datetime instance.\n type(datetime), intent(out) :: date\n character(len=4) :: year_arg\n character(len=2) :: month_arg, day_arg\n integer :: year, month, day\n \n if (command_argument_count() < 3) then\n stop 'Usage: countdown YEAR MONTH DAY'\n end if\n\n call get_command_argument(1, year_arg)\n call get_command_argument(2, month_arg)\n call get_command_argument(3, day_arg)\n\n read(year_arg, *) year\n read(month_arg, *) month\n read(day_arg, *) day\n\n if (year < 1) then\n stop 'YEAR must be >= 1'\n else if (month < 1 .or. month > 12) then\n stop 'MONTH must be >= 1 and <= 12'\n else if (day < 1 .or. day > days_in_month(month, year)) then\n stop 'invalid value for DAY'\n end if\n\n date = datetime(year, month, day, 0, 0, 0)\n\n end subroutine get_date_from_cli\n\n pure elemental logical function is_leap_year(year)\n ! Returns .true. if input year is a leap year,\n ! and .false. otherwise.\n integer, intent(in) :: year\n is_leap_year = (mod(year, 4) == 0 .and. .not. mod(year, 100) == 0)&\n .or. (mod(year, 400) == 0)\n end function is_leap_year\n\n type(datetime) function current_time() result(res)\n integer :: values(8)\n call date_and_time(values=values)\n res = datetime(year = values(1), month = values(2),&\n day = values(3), hour = values(5),&\n minute = values(6), second = values(7))\n end function current_time\n\n pure elemental integer function yearday(year, month, day)\n ! Given input year, month, and day,\n ! returns the number of day in the year.\n integer, intent(in) :: year, month, day \n integer :: m\n yearday = sum([(days_in_month(m, year), m = 1, month - 1)]) + day\n end function yearday\n\nend module mod_datetime\n", "meta": {"hexsha": "4ad5b415d23e4175d0f5798a33c6d0f4a780c3f9", "size": 4849, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fortify/mf/countdown/mod_datetime.f90", "max_stars_repo_name": "wilsonify/c-consumer", "max_stars_repo_head_hexsha": "e19a1baf4efb68436bbec50395f2a3a2c6e3c078", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2019-02-23T19:24:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-30T23:32:49.000Z", "max_issues_repo_path": "src/fortify/mf/countdown/mod_datetime.f90", "max_issues_repo_name": "wilsonify/c-consumer", "max_issues_repo_head_hexsha": "e19a1baf4efb68436bbec50395f2a3a2c6e3c078", "max_issues_repo_licenses": ["MIT"], "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/fortify/mf/countdown/mod_datetime.f90", "max_forks_repo_name": "wilsonify/c-consumer", "max_forks_repo_head_hexsha": "e19a1baf4efb68436bbec50395f2a3a2c6e3c078", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-10-10T08:49:03.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-30T23:32:43.000Z", "avg_line_length": 32.9863945578, "max_line_length": 83, "alphanum_fraction": 0.5852753145, "num_tokens": 1428, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517044, "lm_q2_score": 0.7905303285397349, "lm_q1q2_score": 0.6750439291351804}} {"text": "! computing pi\n program pi\n integer i, n\n parameter(n=1000)\n real*8 v(n), x, gsum, w\n!hpf$ distribute v(block)\n w = 1.0/real(n)\n gsum = 0.0\n!fcd$ time\n!hpf$ independent, new(x), reduction(gsum)\n do i=1, n\n x = (i-0.5)*w\n v(i)=4.0/(1.0+x*x)\n gsum=gsum+v(i)\n enddo\n!fcd$ end time('pi computation')\n print *, 'computed pi value is ', gsum*w\n end\n", "meta": {"hexsha": "a13ed4b3d595b6e98c5f0fdb66e1a02aa50024c0", "size": 417, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "packages/PIPS/validation/Hpfc/pi.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/Hpfc/pi.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/Hpfc/pi.f", "max_forks_repo_name": "DVSR1966/par4all", "max_forks_repo_head_hexsha": "86b33ca9da736e832b568c5637a2381f360f1996", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2015-03-26T08:05:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T02:01:51.000Z", "avg_line_length": 21.9473684211, "max_line_length": 46, "alphanum_fraction": 0.5107913669, "num_tokens": 154, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517043, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.6750439249210952}} {"text": " double precision function tripleYlmint(l1,l2,l3,m1,m2)\n! evaluates \\int d\\Omega Y_{l1}^{m1} Y_{l2}^{m2} Y_{l3}^{m3} \n! where m3=-m1-m2\n! Requires functions lnfactorial and lngamma\n implicit none\n integer l1,l2,l3,m1,m2\n double precision wig1,wig2,xterm,pi\n parameter (pi=3.1415926535897932384626433832795028841972d0)\n double precision wigner3j\n external wigner3j\n tripleYlmint=0.d0\n if (l3.lt.abs(l1-l2).or.l3.gt.l1+l2) return\n if (m1.lt.-l1.or.m1.gt.l1) return\n if (m2.lt.-l2.or.m2.gt.l2) return\n wig1=wigner3j(l1,l2,l3,0,0)\n wig2=wigner3j(l1,l2,l3,m1,m2)\n xterm=sqrt(dble((2*l1+1)*(2*l2+1)*(2*l3+1))/(4.d0*pi))\n tripleYlmint=xterm*wig1*wig2\n return\n end\n\n!***********************************************************************\n\n double precision function wigner3j(j1,j2,j3,m1,m2)\n! evaluates | j1 j2 j3 |\n! | m1 m2 m3 |\n! where m3=-m1-m2\n implicit none\n integer j1,j2,j3,m1,m2,m3\n integer it,itmax,itmin\n double precision xterm1,xterm2,sterm\n double precision triangle\n double precision lnfactorial\n external lnfactorial\n m3=-m1-m2\n wigner3j=0.d0\n if (j3.lt.abs(j1-j2).or.j3.gt.j1+j2) return\n if (m1.lt.-j1.or.m1.gt.j1) return\n if (m2.lt.-j2.or.m2.gt.j2) return\n if (m3.lt.-j3.or.m3.gt.j3) return\n triangle=(lnfactorial(j1+j2-j3)+lnfactorial(j1-j2+j3) &\n& +lnfactorial(-j1+j2+j3)-lnfactorial(j1+j2+j3+1))/2.d0\n xterm1=(lnfactorial(j1+m1)+lnfactorial(j1-m1) &\n& +lnfactorial(j2+m2)+lnfactorial(j2-m2) &\n& +lnfactorial(j3+m3)+lnfactorial(j3-m3))/2.d0\n xterm2=0.d0\n itmin=max(0,j2-j3-m1,j1-j3+m2)\n itmax=min(j1+j2-j3,j1-m1,j2+m2)\n do it=itmin,itmax\n sterm=exp(triangle+xterm1-lnfactorial(it) &\n& -lnfactorial(j3-j2+it+m1)-lnfactorial(j3-j1+it-m2) &\n& -lnfactorial(j1+j2-j3-it)-lnfactorial(j1-it-m1) &\n& -lnfactorial(j2-it+m2))\n xterm2=xterm2+((-1)**it)*sterm\n enddo\n wigner3j=((-1)**(j1-j2-m3))*xterm2\n return\n end\n\n!***********************************************************************\n\n function spharm(ll,mm,rr)\n! Spherical harmonic Y_ll^mm for radius vector rr\n! cosine of polar angle theta = rr(3)/|rr|\n! azimuthal angle phi = atan2(rr(2),rr(1))\n implicit none\n double complex :: spharm\n double precision :: rr(3)\n integer :: ll,mm\n double precision :: costheta,cosphi,sinphi,rmag\n double complex :: expphi\n integer :: im,mmm\n double precision :: fact,prefact,pi,lpolyn\n parameter (pi=3.1415926535897932384626433832795028841972d0)\n external lpolyn\n \n mmm=abs(mm)\n if (ll.lt.mmm) then\n write(6,*) 'bad input parameters in function spharm'\n stop\n endif\n fact=1.d0\n do im=ll-mmm+1,ll+mmm\n fact=fact*im\n enddo\n costheta=rr(3)/norm2(rr)\n rmag=sqrt(dot_product(rr(1:2),rr(1:2)))\n if (rmag.le.0.d0) then\n if (mmm.eq.0) then\n expphi=(1.d0,0.d0)\n else\n expphi=(0.d0,0.d0)\n endif\n else\n cosphi=rr(1)/rmag\n sinphi=rr(2)/rmag\n expphi=cosphi+(0.d0,1.d0)*sinphi\n endif\n prefact=sqrt((2.d0*ll+1.d0)/(fact*4.d0*pi))\n spharm=prefact*lpolyn(ll,mmm,costheta)*expphi**mmm\n if (mm.lt.0) spharm=conjg(spharm)*(-1)**mmm\n\n return\n end\n\n!***********************************************************************\n\n function lpolyn(ll,mm,xx)\n! Legendre Polynomial P_ll^mm (xx)\n implicit none\n double precision lpolyn,xx\n integer ll,mm\n double precision term,fact,lpstart,lpl,lplm1,lplm2\n integer im,il\n\n if (ll.lt.mm.or.abs(xx).gt.1.d0) then\n write(6,*) 'bad input parameters for function lpolyn'\n stop\n endif\n term=sqrt(1.d0-xx*xx)\n lpstart=1.d0\n do im=1,mm\n lpstart=-lpstart*term*(2*im-1)\n enddo\n if (ll.eq.mm) then\n lpolyn=lpstart\n else\n lplm1=lpstart\n lplm2=0.d0\n do il=mm+1,ll\n lpl=(xx*(2*il-1)*lplm1-(il+mm-1)*lplm2)/dble(il-mm)\n lplm2=lplm1\n lplm1=lpl\n enddo\n lpolyn=lpl\n endif\n\n return\n end\n \n!***********************************************************************\n\n double precision function lngamma(xx)\n implicit double precision (a-h,o-z)\n double precision xx,x, cc(6), gam, sumg, work, sq2pi\n integer i\n data cc/76.18009172947146d0,-86.50532032941677d0, &\n& 24.01409824083091d0,-1.231739572450155d0, &\n& 0.1208650973866179d-2,-0.5395239384953d-5/\n x=xx-1.d0\n sq2pi=2.5066282746310005d0\n sumg=1.000000000190015d0\n do i=1,6\n sumg=sumg+cc(i)/(x+i)\n enddo\n work=x+5.5\n lngamma=(x+0.5)*log(work)-work+log(sq2pi*sumg)\n return\n end\n\n!***********************************************************************\n\n double precision function lnfactorial(ii)\n implicit none\n integer ii\n double precision factstore(0:100),lngamma\n external lngamma\n save factstore\n data factstore/101*-1.d0/\n if (ii.le.100) then\n if (factstore(ii).lt.0.d0) factstore(ii)=lngamma(dble(ii+1))\n lnfactorial=factstore(ii)\n else\n lnfactorial=lngamma(dble(ii+1))\n endif\n return\n end\n\n!***********************************************************************\n\n function sphbesselj(xx,nn)\n implicit none\n double precision sphbesselj,xx\n integer nn\n integer ii,np,sigfig\n double precision tiny,dj0,dj1,djnn,djn,djnp1,djnm1,scale\n\n if (nn.lt.0) then\n write(6,*) 'bad argument for order n of j_n(xx) in sphbesselj'\n write(6,*) 'nn = ',nn\n stop\n endif\n sigfig=12\n tiny=1.d-10\n if (xx.lt.tiny) then\n dj0=1.d0-xx**2/6.d0\n else\n dj0=sin(xx)/xx\n endif\n if (nn.eq.0) then\n sphbesselj=dj0\n return\n endif\n if (xx.lt.tiny) then\n sphbesselj=1.d0\n do ii=1,nn\n sphbesselj=sphbesselj*xx/dble(2*ii+1)\n enddo\n elseif (xx.lt.2*nn) then\n djn=tiny\n djnp1=0.d0\n np=int(sqrt(dble(nn*sigfig**2)))+1\n do ii=nn+np,1,-1\n djnm1=(2*ii+1)*djn/xx-djnp1\n if (ii.eq.nn) djnn=djn\n djnp1=djn\n djn=djnm1\n enddo\n scale=djn/dj0\n sphbesselj=djnn/scale\n else\n if (xx.lt.tiny) then\n dj1=xx/3.d0-4.d0*xx**3/30.d0\n else\n dj1=sin(xx)/(xx**2)-cos(xx)/xx\n endif\n djnm1=dj0\n djn=dj1\n do ii=1,nn-1\n djnp1=(2*ii+1)*djn/xx-djnm1\n djnm1=djn\n djn=djnp1\n enddo\n sphbesselj=djn\n endif\n\n return\n end\n", "meta": {"hexsha": "7af360f198559cd2f0d5b06c67475470ebff893f", "size": 6858, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/nwpw/gw/Transfer/Utilities/spherical.f90", "max_stars_repo_name": "dinisAbranches/nwchem", "max_stars_repo_head_hexsha": "21cb07ff634475600ab687882652b823cad8c0cd", "max_stars_repo_licenses": ["ECL-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-18T16:45:12.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T16:45:12.000Z", "max_issues_repo_path": "src/nwpw/gw/Transfer/Utilities/spherical.f90", "max_issues_repo_name": "dinisAbranches/nwchem", "max_issues_repo_head_hexsha": "21cb07ff634475600ab687882652b823cad8c0cd", "max_issues_repo_licenses": ["ECL-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/nwpw/gw/Transfer/Utilities/spherical.f90", "max_forks_repo_name": "dinisAbranches/nwchem", "max_forks_repo_head_hexsha": "21cb07ff634475600ab687882652b823cad8c0cd", "max_forks_repo_licenses": ["ECL-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.6945606695, "max_line_length": 72, "alphanum_fraction": 0.532808399, "num_tokens": 2389, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595163, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6749950405755033}} {"text": "\tFUNCTION PC_PSYM ( tb, tt, delh, psb )\nC************************************************************************\nC* PC_PSYM\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes the Montgomery stream function.\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PC_PSYM ( TB, TT, DELH, PSB )\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*\tTB\t\tREAL\t\tBottom temperature\t\t*\nC*\tTT\t\tREAL\t\tTop temperature\t\t\t*\nC*\tDELH\t\tREAL\t\tIncremental dry hydrostatic z\t*\nC*\tPSB\t\tREAL\t\tBottom psi\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPC_PSYM\t\tREAL\t\tMontgomery stream function\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* M. desJardins/GSFC\t11/84\t\t\t\t\t\t*\nC* M. desJardins/GSFC\t 9/88\t\t\t\t\t\t*\nC* T. Piper/GSC\t\t11/98\tUpdated prolog\t\t\t\t*\nC************************************************************************\n\tINCLUDE\t\t'GEMPRM.PRM'\nC\nC*\tNOTE: The values of CP and G are divided by 100. in order\nC*\t to make the Montgomery Stream Function (PSYM) smaller\nC*\t than 10**6.\nC\n\tPARAMETER\t( CP = RDGAS / RKAPPA / 100. )\n\tPARAMETER\t( G = GRAVTY / 100. )\nC*\n INCLUDE 'ERMISS.FNC'\nC------------------------------------------------------------------------\n\tIF ( ( .not. ERMISS (tb) ) .and. ( .not. ERMISS (tt) ) .and.\n +\t ( .not. ERMISS (delh) ) .and. ( .not. ERMISS (psb) ) ) \n +\t\t\t\t\t\t\t\tTHEN\n\t PC_PSYM = psb + ( CP * ( tt - tb ) + G * delh )\n\t ELSE\n\t PC_PSYM = RMISSD\n\tEND IF\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "d4928a06d1fa99fed7e88a212e6ee52fdff5abd6", "size": 1380, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/pc/pcpsym.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/pc/pcpsym.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/pc/pcpsym.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.3636363636, "max_line_length": 73, "alphanum_fraction": 0.4637681159, "num_tokens": 468, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008904, "lm_q2_score": 0.7461389873857264, "lm_q1q2_score": 0.6749950341981339}} {"text": "function alin(xcur, n,x0,dx,fun)\r\nreal fun(n)\r\ndo i=1,n-1\r\n\tx1=x0+dx*(i-0.5)\r\n\tif(i.eq.1)x1=x0\r\n\tx2=x0+dx*(i+0.5)\r\n\tif((x1-xcur)*(x2-xcur).gt.0.)cycle\r\n\tf1=fun(i)\r\n\tf2=fun(i+1)\r\n\talin=f1+((f2-f1)/(x2-x1))*(xcur-x1)\r\n\treturn\r\nend do\r\nalin=0.\r\nreturn\r\nend\r\n\r\n\r\nfunction alin2d(x,y, x0,nx,dx,y0,ny,dy,fun)\r\nreal fun(nx,ny)\r\ndo ix=1,nx-1\r\n\tx1=x0+dx*(ix-0.5)\r\n\tif(ix.eq.1)x1=x0\r\n\tx2=x0+dx*(ix+0.5)\r\n\tif(ix.eq.nx-1)x2=x0+dx*(ix+1)\r\n\tif((x1-x)*(x2-x).gt.0.)cycle\r\n\tdo iy=1,ny-1\r\n\t\ty1=y0+dy*(iy-0.5)\r\n\t\tif(iy.eq.1)y1=y0\r\n\t\ty2=y0+dy*(iy+0.5)\r\n\t\tif(iy.eq.ny-1)y2=y0+dy*(iy+1)\r\n\t\tif((y1-y)*(y2-y).gt.0.)cycle\r\n\t\tf11=fun(ix,iy)\r\n\t\tf12=fun(ix,iy+1)\r\n\t\tf21=fun(ix+1,iy)\r\n\t\tf22=fun(ix+1,iy+1)\r\n\t\tf1=f11+((f12-f11)/(y2-y1))*(y-y1)\r\n\t\tf2=f21+((f22-f21)/(y2-y1))*(y-y1)\r\n\t\talin2d=f1+((f2-f1)/(x2-x1))*(x-x1)\r\n\t\treturn\r\n\tend do\r\nend do\r\nalin=0.\r\nreturn\r\nend\r\n", "meta": {"hexsha": "4832b832ba83ec4ab3f3df991ee1e14bb07a0505", "size": 840, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "PROGRAMS/subr/other/alin.f90", "max_stars_repo_name": "ilyasnsk/colima_lotos_2019", "max_stars_repo_head_hexsha": "d3ff4f32034e49a32560f170e980b6847b6ea9c7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-10-28T06:16:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-16T02:52:23.000Z", "max_issues_repo_path": "PROGRAMS/subr/other/alin.f90", "max_issues_repo_name": "ilyasnsk/colima_lotos_2019", "max_issues_repo_head_hexsha": "d3ff4f32034e49a32560f170e980b6847b6ea9c7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "PROGRAMS/subr/other/alin.f90", "max_forks_repo_name": "ilyasnsk/colima_lotos_2019", "max_forks_repo_head_hexsha": "d3ff4f32034e49a32560f170e980b6847b6ea9c7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.6666666667, "max_line_length": 44, "alphanum_fraction": 0.5511904762, "num_tokens": 447, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563336, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6749496473799499}} {"text": "\nc======================================================================= \n subroutine hpd(n,alpha,x,alow,aupp)\nc======================================================================= \nc computing 100(1-alpha)% HPD and credible intervals for x \nc use Chen-Shao HPD Estimation Algorithm \nc (see page 219 of Monte Carlo Methods in Bayesian Computation, \nc Springer-Verlag, 2000) \nc ming-hui chen\nc july 23, 2001 at wpi\nc input:\nc alpha: confidence level, 0 < alpha < 1\nc n = mcmc sample size\nc x(n): a univariate vector of mcmc sample \nc output: \nc (alow(1),aupp(1)): 100(1-alpha)% HPD interval\nc (alow(2),aupp(2)): 100(1-alpha)% Bayesian credible interval\nc\n implicit real*8 (a-h,o-z)\n real*8 x(n)\n real*8 aupp(2),alow(2)\n\n whpd=0.d0\n aupp1=0.d0\n alow1=0.d0\n\n q1=(alpha/2.0d0)*float(n)\n q2=(1.0d0-alpha/2.0d0)*float(n)\n nq1=nint(q1)\n nq2=nint(q2)\n nq=nq2-nq1\n do 100 i=1,n-1\n do 110 j=i+1,n\n if (x(i) .gt. x(j)) then\n temp=x(i)\n x(i)=x(j)\n x(j)=temp\n end if\n 110 continue\n 100 continue\n do 120 j=1,n-nq\n pdiff1=x(j)\n pdiff2=x(j+nq)\n wb=pdiff2-pdiff1\n if (j .eq. 1) then\n whpd=wb\n aupp1=pdiff2\n alow1=pdiff1\n else\n if (whpd .gt. wb) then\n whpd=wb\n aupp1=pdiff2\n alow1=pdiff1\n end if\n end if\n 120 continue\n alow(1)=alow1 \n aupp(1)=aupp1 \n alow(2)=x(nq1)\n aupp(2)=x(nq2)\n\n return\n end\n \n \n", "meta": {"hexsha": "4e10bdff7cda62f3888c67871c11521f52043b6d", "size": 1830, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "DPpackage-modified/src/ToolsStat.f", "max_stars_repo_name": "kdevick/densitymediation", "max_stars_repo_head_hexsha": "12bd192f922dae5c8adb8b5573ba8718ea08e9ee", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-16T03:35:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-16T03:35:49.000Z", "max_issues_repo_path": "DPpackage-modified/src/ToolsStat.f", "max_issues_repo_name": "kdevick/densitymediation", "max_issues_repo_head_hexsha": "12bd192f922dae5c8adb8b5573ba8718ea08e9ee", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "DPpackage-modified/src/ToolsStat.f", "max_forks_repo_name": "kdevick/densitymediation", "max_forks_repo_head_hexsha": "12bd192f922dae5c8adb8b5573ba8718ea08e9ee", "max_forks_repo_licenses": ["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.7272727273, "max_line_length": 79, "alphanum_fraction": 0.418579235, "num_tokens": 555, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392939666335, "lm_q2_score": 0.7634837527911056, "lm_q1q2_score": 0.6749496377724448}} {"text": " SUBROUTINE CROTG( A, B, C, S )\n*\n* -- Automatically Tuned Linear Algebra Software (ATLAS)\n* (C) Copyright 2000 All Rights Reserved\n*\n* -- ATLAS routine -- F77 Interface -- Version 3.9.24 -- December 25, 2000\n*\n* Author : Antoine P. Petitet\n* Originally developed at the University of Tennessee,\n* Innovative Computing Laboratory, Knoxville TN, 37996-1301, USA.\n*\n* ---------------------------------------------------------------------\n*\n* -- Copyright notice and Licensing terms:\n*\n* Redistribution and use in source and binary forms, with or without\n* modification, are permitted provided that the following conditions\n* are met:\n*\n* 1. Redistributions of source code must retain the above copyright\n* notice, this list of conditions and the following disclaimer.\n* 2. Redistributions in binary form must reproduce the above copyright\n* notice, this list of conditions, and the following disclaimer in\n* the documentation and/or other materials provided with the distri-\n* bution.\n* 3. The name of the University, the ATLAS group, or the names of its\n* contributors may not be used to endorse or promote products deri-\n* ved from this software without specific written permission.\n*\n* -- Disclaimer:\n*\n* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY\n* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE-\n* CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED\n* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\n* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEO-\n* RY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (IN-\n* CLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n*\n* ---------------------------------------------------------------------\n*\n* .. Scalar Arguments ..\n REAL C\n COMPLEX A, B, S\n* ..\n*\n* Purpose\n* =======\n*\n* CROTG constructs a Givens plane rotation. Given the scalars a and b,\n* this routine computes the following quantities:\n*\n* if |a| = 0, then c = 0, s = 1, and r = b;\n* and otherwise:\n* norm = sqrt( |a|^2 + |b|^2 );\n* c = |a| / norm;\n* s = a * conjg( b ) / ( |a| * norm );\n* r = a / ( |a| * norm );\n*\n* Arguments\n* =========\n*\n* A (input/output) COMPLEX\n* On entry, A specifies the scalar a. On exit, A is overwritten\n* by the scalar r defined above.\n*\n* B (input) COMPLEX\n* On entry, B specifies the scalar b. Unchanged on exit.\n*\n* C (output) REAL\n* On exit, C specifies the scalar c defined above.\n*\n* S (output) COMPLEX\n* On exit, S specifies the scalar s defined above.\n*\n* Further Details\n* ===============\n*\n* For further information on the Level 1 BLAS specification, see:\n*\n* ``A Proposal for Standard Linear Algebra Subprograms'' by R. Hanson,\n* F. Krogh and C. Lawson, ACM SIGNUM Newsl., 8(16), 1973,\n*\n* ``Basic Linear Algebra Subprograms for Fortran Usage'' by C. Lawson,\n* R. Hanson, D. Kincaid and F. Krogh, ACM Transactions on Mathematical\n* Software, 5(3) pp 308-323, 1979.\n*\n* For further information on the Level 2 BLAS specification, see:\n*\n* ``An Extended Set of FORTRAN Basic Linear Algebra Subprograms'' by\n* J. Dongarra, J. Du Croz, S. Hammarling and R. Hanson, ACM Transac-\n* tions on Mathematical Software, 14(1) pp 1-17, 1988.\n*\n* ``Algorithm 656: An extended Set of Basic Linear Algebra Subprograms:\n* Model Implementation and Test Programs'' by J. Dongarra, J. Du Croz,\n* S. Hammarling and R. Hanson, ACM Transactions on Mathematical Soft-\n* ware, 14(1) pp 18-32, 1988.\n*\n* For further information on the Level 3 BLAS specification, see:\n*\n* ``A Set of Level 3 Basic Linear Algebra Subprograms'' by J. Dongarra,\n* J. Du Croz, I. Duff and S. Hammarling, ACM Transactions on Mathemati-\n* cal Software, 16(1), pp 1-17, 1990.\n*\n* =====================================================================\n*\n* .. External Subroutines ..\n EXTERNAL ATL_F77WRAP_CROTG\n* ..\n* .. Executable Statements ..\n*\n CALL ATL_F77WRAP_CROTG( A, B, C, S )\n*\n RETURN\n*\n* End of CROTG\n*\n END\n", "meta": {"hexsha": "ab82a143d6dd8d28c4460295ae1c51ea659178c4", "size": 4635, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "interfaces/blas/F77/src/crotg.f", "max_stars_repo_name": "kevleyski/math-atlas", "max_stars_repo_head_hexsha": "cc36aa7e0362c577739ac507378068882834825e", "max_stars_repo_licenses": ["BSD-3-Clause-Clear"], "max_stars_count": 19, "max_stars_repo_stars_event_min_datetime": "2015-03-19T10:53:38.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-17T06:12:32.000Z", "max_issues_repo_path": "interfaces/blas/F77/src/crotg.f", "max_issues_repo_name": "kevleyski/math-atlas", "max_issues_repo_head_hexsha": "cc36aa7e0362c577739ac507378068882834825e", "max_issues_repo_licenses": ["BSD-3-Clause-Clear"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-12-18T17:43:44.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-18T17:43:44.000Z", "max_forks_repo_path": "interfaces/blas/F77/src/crotg.f", "max_forks_repo_name": "kevleyski/math-atlas", "max_forks_repo_head_hexsha": "cc36aa7e0362c577739ac507378068882834825e", "max_forks_repo_licenses": ["BSD-3-Clause-Clear"], "max_forks_count": 47, "max_forks_repo_forks_event_min_datetime": "2015-01-27T06:22:57.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-11T20:59:04.000Z", "avg_line_length": 37.6829268293, "max_line_length": 75, "alphanum_fraction": 0.6174757282, "num_tokens": 1252, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357327, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6749496332921796}} {"text": "module num_env\n implicit none\n private\n public pi\n public bico\n public deg\n public fact\n public inv2\n public rad\n public shft\n public swap\n\n real, parameter :: pi = 4. * atan(1.)\n\n interface swap\n procedure iswap, rswap\n end interface\n\ncontains\n pure function bico(n, k)\n integer, intent(in) :: n, k\n integer :: bico\n\n bico = fact(n) / (fact(k) * fact(n-k))\n end function\n\n elemental function deg(r) result(d)\n real, intent(in) :: r\n real :: d\n\n d = r * 180. / pi\n end function\n\n pure function fact(n)\n integer, intent(in) :: n\n integer :: i, fact\n\n fact = product([(i, i=1,n)])\n end function\n\n pure subroutine inv2(a)\n real, intent(inout) :: a(2, 2)\n real :: b(2, 2)\n real :: detinv\n\n detinv = 1. / (a(1, 1) * a(2, 2) - a(1, 2) * a(2, 1))\n\n b(1, 1) = +detinv * a(2, 2)\n b(2, 1) = -detinv * a(2, 1)\n b(1, 2) = -detinv * a(1, 2)\n b(2, 2) = +detinv * a(1, 1)\n a = b\n end subroutine\n\n elemental function rad(d) result(r)\n real, intent(in) :: d\n real :: r\n\n r = d * pi / 180.\n end function\n\n pure subroutine shft(a, b, c, d)\n real, intent(out) :: a\n real, intent(inout) :: b, c\n real, intent(in) :: d\n\n a = b\n b = c\n c = d\n end subroutine\n\n pure subroutine iswap(a, b)\n integer, intent(inout) :: a, b\n integer :: c\n\n c = a\n a = b\n b = c\n end subroutine\n\n pure subroutine rswap(a, b)\n real, intent(inout) :: a, b\n real :: c\n\n c = a\n a = b\n b = c\n end subroutine\nend module\n\nmodule bez\n use num_env, only: bico, fact, inv2, pi\n implicit none\n private\n public bezarc\n public bezcrv\n public bezfit\n public bezlin\n public bezsim\n\ncontains\n pure subroutine bezarc(a, b, p)\n real, intent(in) :: a(:), b(:)\n real, intent(out) :: p(:, :)\n real, parameter :: k = 4. / 3. * (sqrt(2.) - 1.)\n integer :: i, m, n\n real :: br(2), dx(2)\n real :: beta, cosb, sinb, r, rot(2, 2)\n\n n = size(p, 2)\n if (mod(n, 2) /= 0) error stop\n\n m = n / 2\n dx = b - a\n beta = .5 * pi - atan(dx(2) / dx(1))\n cosb = cos(beta)\n sinb = sin(beta)\n rot(1, 1) = cosb\n rot(1, 2) = -sinb\n rot(2, 1) = sinb\n rot(2, 2) = cosb\n br = matmul(rot, dx) + a\n\n cosb = cos(.25 * pi)\n sinb = cosb\n r = abs(a(2) - br(2)) / (2. * sinb)\n do concurrent(i = 1:m-1)\n p(:, i) = a\n end do\n dx = k * r * [sinb, cosb]\n call inv2(rot)\n p(:, m) = matmul(rot, dx) + a\n p(:, m+1) = matmul(rot, br + dx - a) + a\n do concurrent(i = m+2:n)\n p(:, i) = b\n end do\n end subroutine\n\n pure function bezcrv(t, p) result(c)\n real, intent(in) :: t, p(:, :)\n real :: c(size(p, 1))\n integer :: i, n\n\n c = 0\n if(t < 0 .or. t > 1) error stop\n n = size(p, 2) - 1\n do i = 0, n\n c = c + b(t, i, n) * p(:, i+1)\n end do\n\n contains\n pure function b(t, i, n)\n real, intent(in) :: t\n integer, intent(in) :: i, n\n real :: b\n\n b = bico(n, i) * t**i * (1 - t)**(n - i)\n end function\n end function\n\n pure recursive function bezfit(x, tol) result(p)\n real, intent(in) :: x(:, :), tol\n real :: a(size(x, 1)), a1, a2, a12, d, t, t1\n real, allocatable :: p(:, :), q(:, :), r(:, :)\n real, dimension(2) :: c1, c2, c12\n integer :: i, k, n\n\n n = size(x, 2)\n if (n < 3) error stop\n k = n - 1\n allocate(p(2, 4))\n p(:, 1) = x(:, 1)\n p(:, 4) = x(:, n)\n\n a1 = 0\n a2 = 0\n a12 = 0\n c1 = 0\n c2 = 0\n do i = 0, k\n t = real(i) / k\n t1 = 1. - t\n a1 = a1 + t**2 * t1**4\n a2 = a2 + t**4 * t1**2\n a12 = a12 + t**3 * t1**3\n c12 = x(:, i + 1) - t1**3 * p(1, :) - t**3 * p(:, 4)\n c1 = c1 + 3. * t * t1**2 * c12\n c2 = c2 + 3. * t**2 * t1 * c12\n end do\n a1 = 9. * a1\n a2 = 9. * a2\n a12 = 9. * a12\n d = (a1 * a2 - a12 * a12)\n p(:, 2) = (a2 * c1 - a12 * c2) / d\n p(:, 3) = (a1 * c2 - a12 * c1) / d\n\n do concurrent(i = 0:k)\n t = real(i) / k\n a(i+1) = norm2(x(:, i+1) - bezcrv(t, p))\n end do\n if (all(a < tol)) return\n\n k = maxloc(a, 1)\n if (k < 3 .or. n - k < 2) return\n\n q = bezfit(x(:, :k), tol)\n r = bezfit(x(:, k:), tol)\n n = size(q, 1)\n k = size(r, 1)\n deallocate(p)\n allocate(p(n+k-1, 2))\n p(:, :n) = q\n p(:, n:) = r\n deallocate(q)\n deallocate(r)\n end function\n\n pure subroutine bezlin(a, b, p)\n real, intent(in) :: a(:), b(:)\n real, intent(out) :: p(:, :)\n real :: dx(size(a))\n integer :: i, j, n\n\n dx = b - a\n n = size(p, 2) - 1\n do i = 0, n\n j = i + 1\n p(:, j) = dx * real(i) / n + a\n end do\n end subroutine\n\n pure function bezsim(p, q) result(lambda)\n real, intent(in), dimension(:, :) :: p, q\n real :: lambda\n integer :: i, n\n\n n = size(p, 2)\n if(n /= size(q, 2)) error stop\n lambda = 0\n do i = 1, n\n lambda = lambda + hypot(p(:, i) - q(:, i))\n end do\n lambda = lambda / n\n end function\nend module\n\nmodule fmin\n use num_env, only: shft, swap\n implicit none\n private\n public amoeba\n public brent\n public mnbrak\n\ncontains\n subroutine amoeba(fcn, x, fn, tol, stat)\n interface\n function fcn(x)\n real, intent(in) :: x(:)\n real :: fcn\n end function\n end interface\n real, intent(inout) :: x(:)\n real, intent(out) :: fn\n real, optional, intent(in) :: tol\n integer, optional, intent(out) :: stat\n real :: c, alpha, beta, gamma, delta, &\n f(size(x)+1), fc, fe, fr, ftmp, &\n xx(size(x), size(x)+1), xc(size(x)), &\n xe(size(x)), xr(size(x)), xtmp(size(x)), &\n ident(size(x), size(x)), p(size(x)), p1, p2, facc\n integer :: i, j, k, itmax, n\n\n n = size(x)\n alpha = 1.\n beta = 1. + 2. / n\n gamma = .75 - 1. / (2 * n)\n delta = 1. - 1. / n\n c = 1.5\n p1 = c * (sqrt(n + 1.) + n - 1.) / (sqrt(2.) * n)\n p2 = c * (sqrt(n + 1.) - 1.) / (sqrt(2.) * n)\n p = p2\n ident = 0\n do concurrent(i = 1:n)\n ident(i, i) = 1\n end do\n xx(:, 1) = x\n do concurrent(i = 2:n+1)\n xx(:, i) = x + p + (p1 - p2) * ident(:, i-1)\n end do\n do j = 1, n+1\n f(j) = fcn(xx(:, j))\n end do\n facc = merge(tol, sqrt(epsilon(1.)), present(tol))\n if(present(stat)) stat = 0\n itmax = n * 200\n do i = 1, itmax\n do j = 2, n+1\n k = j - 1\n ftmp = f(j)\n xtmp = xx(:, j)\n do while(k >= 1 .and. f(k) > ftmp)\n f(k+1) = f(k)\n xx(:, k+1) = xx(:, k)\n k = k - 1\n end do\n f(k+1) = ftmp\n xx(:, k+1) = xtmp\n end do\n x = sum(xx(:, 1:n), 2) / n\n xr = x + alpha * (x - xx(:, n+1))\n fr = fcn(xr)\n if(fr >= f(1) .and. fr <= f(n)) then\n xx(:, n+1) = xr\n f(n+1) = fr\n else if(fr < f(1)) then\n xe = x + beta * (xr - x)\n fe = fcn(xe)\n if(fe < f(1)) then\n xx(:, n+1) = xe\n f(n+1) = fe\n else\n xx(:, n+1) = xr\n f(n+1) = fr\n end if\n else if(fr > f(n)) then\n if(fr >= f(n+1)) then\n xc = x + gamma * (xx(:, n+1) - x)\n else\n xc = x + gamma * (xr - x)\n end if\n fc = fcn(xc)\n if(fc < f(n+1)) then\n xx(:, n+1) = xc\n f(n+1) = fc\n else\n do j = 2, n+1\n xx(:, j) = delta * (xx(:, j) - xx(:, 1)) + xx(:, 1)\n f(j) = fcn(xx(:, j))\n end do\n end if\n end if\n fn = f(1)\n if(sqrt(sum(((f - fcn(x))**2) / n)) < facc) return\n end do\n if(present(stat)) stat = -1\n end subroutine\n\n function brent(ax, bx, cx, func, tol, xmin, stat)\n real, intent(in) :: ax, bx, cx, tol\n real, intent(out) :: xmin\n integer, optional, intent(out) :: stat\n real :: brent\n interface\n function func(x)\n real, intent(in) :: x\n real :: func\n end function\n end interface\n real, parameter :: cgold = 0.3819660, zeps = 1.0e-3 * epsilon(ax)\n integer, parameter :: itmax = 100\n integer :: i\n real :: a, b, d, e, etemp, fu, fv, fw, fx, p, q, r, tol1, tol2, u, v, w, x, xm\n\n if(present(stat)) stat = 0\n brent = bx\n a = min(ax, cx)\n b = max(ax, cx)\n v = bx\n w = v\n x = v\n e = 0.\n fx = func(x)\n fv = fx\n fw = fx\n do i = 1, itmax\n xm = .5 * (a + b)\n tol1 = tol * abs(x) + zeps\n tol2 = 2. * tol1\n if(abs(x - xm) <= (tol2 - .5 * (b - a))) then\n xmin = x\n brent = fx\n return\n end if\n if(abs(e) > tol1) then\n r = (x - w) * (fx - fv)\n q = (x - v) * (fx - fw)\n p = (x - v) * q - (x - w) * r\n q = 2. * (q - r)\n if(q > 0) p = -p\n q = abs(q)\n etemp = e\n e = d\n if(abs(p) >= abs(.5 * q * etemp) .or. &\n p <= q * (a - x) .or. p >= q * (b - x)) then\n e = merge(a - x, b - x, x >= xm)\n d = cgold * e\n else\n d = p / q\n u = x + d\n if(u - a < tol2 .or. b - u < tol2) d = sign(tol1, xm - x)\n end if\n else\n e = merge(a - x, b - x, x >= xm)\n d = cgold * e\n end if\n u = merge(x + d, x + sign(tol1, d), abs(d) >= tol1)\n fu = func(u)\n if(fu <= fx) then\n if(u >= x) then\n a = x\n else\n b = x\n end if\n call shft(v, w, x, u)\n call shft(fv, fw, fx, fu)\n else\n if(u < x) then\n a = u\n else\n b = u\n end if\n if(fu <= fw .or. w == x) then\n v = w\n fv = fw\n w = u\n fw = fu\n else if(fu <= fv .or. v == x .or. v == w) then\n v = u\n fv = fu\n end if\n end if\n end do\n if(present(stat)) stat = -1\n end function\n\n subroutine mnbrak(ax, bx, cx, fa, fb, fc, func)\n real, intent(inout) :: ax, bx\n real, intent(out) :: cx, fa, fb, fc\n interface\n function func(x)\n real, intent(in) :: x\n real :: func\n end function\n end interface\n real, parameter :: gold = 1.618034, glimit = 100.0\n real :: fu, q, r, u, ulim\n\n fa = func(ax)\n fb = func(bx)\n if(fb > fa) then\n call swap(ax, bx)\n call swap(fa, fb)\n end if\n cx = bx + gold * (bx - ax)\n fc = func(cx)\n do\n if(fb < fc) return\n r = (bx - ax) * (fb - fc)\n q = (bx - cx) * (fb - fa)\n u = bx - ((bx - cx) * q - (bx - ax) * r) / (2. * sign(max(abs(q - r), tiny(1.)), q - r))\n ulim = bx + glimit * (cx - bx)\n if((bx - u) * (u - cx) > 0.) then\n fu = func(u)\n if(fu < fc) then\n ax = bx\n fa = fb\n bx = u\n fb = fu\n return\n else if(fu > fb) then\n cx = u\n fc = fu\n return\n end if\n u = cx + gold * (cx - bx)\n fu = func(u)\n else if((cx - u) * (u - ulim) > 0.) then\n fu = func(u)\n if(fu < fc) then\n bx = cx\n cx = u\n u = cx + gold * (cx - bx)\n call shft(fb, fc, fu, func(u))\n end if\n else if((u - ulim) * (ulim - cx) >= 0.) then\n u = ulim\n fu = func(u)\n else\n u = cx + gold * (cx - bx)\n fu = func(u)\n end if\n call shft(ax, bx, cx, u)\n call shft(fa, fb, fc, fu)\n end do\n end subroutine\nend module\n\nmodule intgrt\n implicit none\n private\n public simpr\n\ncontains\n function simpr(fcn, a, b, n) result(s)\n interface\n function fcn(x)\n real, intent(in) :: x\n real :: fcn\n end function\n end interface\n real, intent(in) :: a, b\n integer, optional, intent(in) :: n\n real :: f0, fn, fs0, fs1, h, s, x0, x1\n integer :: i, k\n\n k = merge(n, 3, present(n))\n h = (b - a) / k\n f0 = fcn(a)\n fn = fcn(b)\n fs0 = 0\n fs1 = 0\n x0 = a\n do i = 1, k\n x1 = x0 + h\n if(i < k) fs0 = fs0 + fcn(x1)\n fs1 = fs1 + fcn((x0 + x1) / 2.)\n x0 = x1\n end do\n s = h / 6. * (f0 + 2. * fs0 + fn + 4. * fs1)\n end function\nend module\n\nmodule intp1d\n implicit none\n private\n public interp\n\ncontains\n pure function interp(x, xp, fp) result(y)\n real, intent(in) :: x, xp(:), fp(:)\n integer :: i, j, n\n real :: y\n\n n = size(xp)\n y = fp(1)\n if(x < xp(1)) return\n do i = 1, n - 1\n j = i + 1\n if(x >= xp(i) .and. x < xp(j)) then\n y = fp(i) + (x - xp(i)) * (fp(j) - fp(i)) / (xp(j) - xp(i))\n return\n end if\n end do\n if(x > xp(n)) y = fp(n)\n end function\nend module\n\nmodule rtfind\n implicit none\n private\n public rtnewt\n public zbrent\n\n integer, parameter :: itmax = 1000\n\ncontains\n pure subroutine rtnewt(funcd, p, x0, x, tol, stat)\n interface\n pure subroutine funcd(x, p, fval, fderiv)\n real, intent(in) :: x, p(:)\n real, intent(out) :: fval, fderiv\n end subroutine\n end interface\n real, intent(in) :: p(:), x0\n real, intent(out) :: x\n real, optional, intent(in) :: tol\n integer, optional, intent(out) :: stat\n real :: df, dx, f, xacc\n integer :: j\n\n if(present(stat)) stat = 0\n xacc = merge(tol, sqrt(epsilon(1.)), present(tol))\n x = x0\n do j = 1, itmax\n call funcd(x, p, f, df)\n dx = f / df\n x = x - dx\n if(abs(dx) < xacc) return\n end do\n if(present(stat)) stat = -1\n end subroutine\n\n pure subroutine zbrent(fcn, x1, x2, b, tol, stat)\n interface\n pure function fcn(x)\n real, intent(in) :: x\n real :: fcn\n end function\n end interface\n real, intent(in) :: x1, x2\n real, intent(out) :: b\n real, optional, intent(in) :: tol\n integer, optional, intent(out) :: stat\n integer :: i\n real :: a, c, d, e, fa, fb, fc, min1, min2, &\n p, q, r, s, xacc, xm\n\n if(present(stat)) stat = 0\n a = x1\n b = x2\n c = 0\n d = 0\n e = 0\n fa = fcn(a)\n fb = fcn(b)\n if(fa * fb > 0) then\n if(present(stat)) stat = -1\n return\n end if\n fc = fb\n do i = 1, itmax\n if(fb * fc > 0) then\n c = a\n fc = fa\n d = b - a\n e = d\n end if\n if(abs(fc) < abs(fa)) then\n a = b\n b = c\n c = a\n fa = fb\n fb = fc\n fc = fa\n end if\n xacc = 2. * epsilon(x1) * abs(b) + .5 * merge(tol, sqrt(epsilon(1.)), present(tol))\n xm = .5 * (c - b)\n if(abs(xm) <= xacc .or. fb == 0.) return\n if(abs(e) >= xacc .and. abs(fa) > abs(fb)) then\n s = fb / fa\n if(a == b) then\n p = 2. * xm * s\n q = 1. - s\n else\n q = fa / fc\n r = fb / fc\n p = s * (2. * xm * q * (q - r) - (b - a) * (r - 1.))\n q = (q - 1.) * (r - 1.) * (s - 1.)\n end if\n if(p > 0) q = -q\n p = abs(p)\n min1 = 3. * xm * q - abs(xacc*q)\n min2 = abs(e*q)\n if(2.*p < min(min1, min2)) then\n e = d\n d = p / q\n else\n d = xm\n e = d\n end if\n else\n d = xm\n e = d\n end if\n a = b\n fa = fb\n if(abs(d) > xacc) then\n b = b + d\n else\n b = b + sign(xacc, xm)\n end if\n fb = fcn(b)\n end do\n if(present(stat)) stat = -2\n end subroutine\nend module\n\nmodule spcfnc\n implicit none\n private\n public hyp2f1\n\ncontains\n elemental function hyp2f1(a, b, c, z) result(f1)\n real, intent(in) :: a, b, c, z\n integer, parameter :: itmax = 1000\n real :: aa, bb, cc, f1, fac, temp\n integer :: n\n\n fac = 1.\n temp = fac\n aa = a\n bb = b\n cc = c\n do n = 1, itmax\n fac = fac * ((aa * bb) / cc) * z / n\n f1 = temp + fac\n if(f1 == temp) return\n temp = f1\n aa = aa + 1.\n bb = bb + 1.\n cc = cc + 1.\n end do\n end function\nend module\n", "meta": {"hexsha": "fc701f25b498992f01edf03adf0b0158c5c587ec", "size": 15632, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/num.f90", "max_stars_repo_name": "thkrz/ssat", "max_stars_repo_head_hexsha": "c099a83308149fe64b0016e50f78bd4af8f9c8e7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-12-19T23:21:51.000Z", "max_stars_repo_stars_event_max_datetime": "2018-12-20T14:56:37.000Z", "max_issues_repo_path": "src/num.f90", "max_issues_repo_name": "thkrz/stabpack", "max_issues_repo_head_hexsha": "c099a83308149fe64b0016e50f78bd4af8f9c8e7", "max_issues_repo_licenses": ["MIT"], "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/num.f90", "max_forks_repo_name": "thkrz/stabpack", "max_forks_repo_head_hexsha": "c099a83308149fe64b0016e50f78bd4af8f9c8e7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-02-03T12:48:16.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-03T12:48:16.000Z", "avg_line_length": 22.1103253182, "max_line_length": 94, "alphanum_fraction": 0.4395470829, "num_tokens": 5934, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778824, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6749492064041556}} {"text": "MODULE quad_prec_complex\r\n! Quadruple-precision complex arithmetic.\r\n! This should compile and run correctly using any compiler on which the\r\n! module quadruple_precision runs correctly. There should be no need\r\n! for different versions for different compilers.\r\n\r\n! Programmer : Alan Miller, CSIRO Mathematical & Information Sciences\r\n! e-mail: alan @ vic.cmis.csiro.au URL: www.ozemail.com.au/~milleraj\r\n! Fax: (+61) 3-9545-8080\r\n\r\n! Latest revision - 11 November 1999\r\n\r\nUSE quadruple_precision\r\nIMPLICIT NONE\r\n\r\nTYPE :: qc\r\n TYPE (quad) :: qr, qi ! quad_real, quad_imaginary\r\nEND TYPE qc\r\n\r\nINTERFACE OPERATOR (+)\r\n MODULE PROCEDURE qc_add\r\nEND INTERFACE\r\n\r\nINTERFACE OPERATOR (-)\r\n MODULE PROCEDURE qc_sub\r\n MODULE PROCEDURE negate_qc\r\nEND INTERFACE\r\n\r\nINTERFACE OPERATOR (*)\r\n MODULE PROCEDURE qc_mult\r\nEND INTERFACE\r\n\r\nINTERFACE OPERATOR (/)\r\n MODULE PROCEDURE qc_div\r\nEND INTERFACE\r\n\r\nINTERFACE ABS\r\n MODULE PROCEDURE qc_abs\r\nEND INTERFACE\r\n\r\nINTERFACE CMPLX\r\n MODULE PROCEDURE qc_cmplx\r\nEND INTERFACE\r\n\r\nINTERFACE CONJG\r\n MODULE PROCEDURE qc_conjg\r\nEND INTERFACE\r\n\r\nINTERFACE AIMAG\r\n MODULE PROCEDURE qc_aimag\r\nEND INTERFACE\r\n\r\nINTERFACE SQRT\r\n MODULE PROCEDURE qc_sqrt\r\nEND INTERFACE\r\n\r\nINTERFACE LOG\r\n MODULE PROCEDURE qc_log\r\nEND INTERFACE\r\n\r\nINTERFACE EXP\r\n MODULE PROCEDURE qc_exp\r\nEND INTERFACE\r\n\r\nCONTAINS\r\n\r\n\r\nFUNCTION qc_add(x, y) RESULT(z)\r\n! Quadruple-precision complex addition\r\n\r\nTYPE (qc), INTENT(IN) :: x, y\r\nTYPE (qc) :: z\r\n\r\nz % qr = x % qr + y % qr\r\nz % qi = x % qi + y % qi\r\n\r\nRETURN\r\nEND FUNCTION qc_add\r\n\r\n\r\n\r\nFUNCTION qc_sub(x, y) RESULT(z)\r\n! Quadruple-precision complex subtraction\r\n\r\nTYPE (qc), INTENT(IN) :: x, y\r\nTYPE (qc) :: z\r\n\r\nz%qr = x%qr - y%qr\r\nz%qi = x%qi - y%qi\r\n\r\nRETURN\r\nEND FUNCTION qc_sub\r\n\r\n\r\n\r\nFUNCTION negate_qc(x) RESULT(z)\r\n! Quadruple-precision complex negate sign\r\n\r\nTYPE (qc), INTENT(IN) :: x\r\nTYPE (qc) :: z\r\n\r\nz%qr = - x%qr\r\nz%qi = - x%qi\r\n\r\nRETURN\r\nEND FUNCTION negate_qc\r\n\r\n\r\n\r\nFUNCTION qc_mult(x, y) RESULT(z)\r\n! Quadruple-precision complex multiplication\r\n\r\nTYPE (qc), INTENT(IN) :: x, y\r\nTYPE (qc) :: z\r\n\r\nz%qr = x%qr * y%qr - x%qi * y%qi\r\nz%qi = x%qi * y%qr + x%qr * y%qi\r\n\r\nRETURN\r\nEND FUNCTION qc_mult\r\n\r\n\r\n\r\nFUNCTION qc_div(x, y) RESULT(z)\r\n! Quadruple-precision complex division\r\n\r\nTYPE (qc), INTENT(IN) :: x, y\r\nTYPE (qc) :: z\r\n\r\nTYPE (quad) :: t, d\r\n\r\nIF ( ABS(y%qr%hi) > ABS(y%qi%hi) ) THEN\r\n t = y%qi / y%qr\r\n d = y%qr + t * y%qi\r\n z%qr = (x%qr + t * x%qi) / d\r\n z%qi = (x%qi - t * x%qr) / d\r\nELSE\r\n t = y%qr / y%qi\r\n d = y%qi + t * y%qr\r\n z%qr = (t * x%qr + x%qi) / d\r\n z%qi = (t * x%qi - x%qr) / d\r\nEND IF\r\n\r\nRETURN\r\nEND FUNCTION qc_div\r\n\r\n\r\n\r\nFUNCTION qc_cmplx(xr, xi) RESULT(z)\r\n! Convert pair of quad.precision numbers to qc.\r\n\r\nTYPE (quad), INTENT(IN) :: xr, xi\r\nTYPE (qc) :: z\r\n\r\nz%qr = xr\r\nz%qi = xi\r\n\r\nRETURN\r\nEND FUNCTION qc_cmplx\r\n\r\n\r\n\r\nFUNCTION qc_aimag(x) RESULT(z)\r\n! Convert pair of quad.precision numbers to qc.\r\n\r\nTYPE (qc), INTENT(IN) :: x\r\nTYPE (quad) :: z\r\n\r\nz = x%qi\r\n\r\nRETURN\r\nEND FUNCTION qc_aimag\r\n\r\n\r\n\r\nFUNCTION qc_conjg(x) RESULT(z)\r\n! Quadruple-precision complex square root\r\n\r\nTYPE (qc), INTENT(IN) :: x\r\nTYPE (qc) :: z\r\n\r\nz%qr = x%qr\r\nz%qi = - x%qi\r\n\r\nRETURN\r\nEND FUNCTION qc_conjg\r\n\r\n\r\n\r\nFUNCTION qc_sqrt(x) RESULT(z)\r\n! Quadruple-precision complex square root\r\n\r\nTYPE (qc), INTENT(IN) :: x\r\nTYPE (qc) :: z\r\n\r\n! Local variables\r\nTYPE (quad) :: r\r\nREAL (dp), PARAMETER :: vsmall = TINY(1.0_dp)\r\n\r\nr = SQRT(x%qr **2 + x%qi **2)\r\nIF (r%hi < vsmall) THEN\r\n z%qr = 0.0_dp\r\n z%qi = 0.0_dp\r\n RETURN\r\nEND IF\r\n\r\nz%qr = SQRT( SCALE( r + ABS(x%qr), -1 ) )\r\nz%qi = ABS( SCALE( x%qi, -1 ) ) / z%qr\r\nIF (x%qr%hi < 0.0_dp) THEN\r\n r = z%qr\r\n z%qr = z%qi\r\n z%qi = r\r\nEND IF\r\nIF (x%qi%hi < 0.0_dp) z%qi = - z%qi\r\n\r\nRETURN\r\nEND FUNCTION qc_sqrt\r\n\r\n\r\n\r\nFUNCTION qc_abs(x) RESULT(z)\r\n! Quadruple-precision complex absolute (modulus)\r\n! SQRT( x%qr **2 + x%qi **2 ) avoiding overflow\r\n! Using either: X^2 + Y^2 = X^2.(1 + (Y/X)^2)\r\n! or: = Y^2.(1 + (X/Y)^2)\r\n\r\nTYPE (qc), INTENT(IN) :: x\r\nTYPE (quad) :: z\r\n\r\nTYPE (quad) :: a\r\n\r\nIF ( ABS(x%qr%hi) > ABS(x%qi%hi) ) THEN\r\n a = x%qi / x%qr\r\n z = ABS( x%qr ) * SQRT( quad(1.0_dp, 0.0_dp) + a**2 )\r\nELSE IF ( x%qi%hi == 0.0_dp ) THEN\r\n z = 0.0_dp\r\nELSE\r\n a = x%qr / x%qi\r\n z = ABS( x%qi ) * SQRT( quad(1.0_dp, 0.0_dp) + a**2 )\r\nEND IF\r\n\r\nRETURN\r\nEND FUNCTION qc_abs\r\n\r\n\r\n\r\nFUNCTION qc_exp(x) RESULT(z)\r\n! Quadruple-precision complex exponential\r\n\r\nTYPE (qc), INTENT(IN) :: x\r\nTYPE (qc) :: z\r\n\r\nTYPE (quad) :: expx\r\n\r\nexpx = EXP(x%qr)\r\nz%qr = expx * COS(x%qi)\r\nz%qi = expx * SIN(x%qi)\r\n\r\nRETURN\r\nEND FUNCTION qc_exp\r\n\r\n\r\n\r\nFUNCTION qc_log(x) RESULT(z)\r\n! Quadruple-precision complex logarithm\r\n\r\nTYPE (qc), INTENT(IN) :: x\r\nTYPE (qc) :: z\r\n\r\nz%qr = LOG( ABS(x) )\r\nz%qi = ATAN2( x%qi, x%qr )\r\n\r\nRETURN\r\nEND FUNCTION qc_log\r\n\r\n\r\nEND MODULE quad_prec_complex\r\n", "meta": {"hexsha": "b1c8f8e4d21ae8716f1fabf1481a8dd5e307b038", "size": 5024, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/qcomplex.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/qcomplex.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/qcomplex.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": 18.071942446, "max_line_length": 72, "alphanum_fraction": 0.5951433121, "num_tokens": 1643, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.67494920179767}} {"text": " program triangle\n!=======================================================================\n!\n! Create triangle mesh for three different triangles\n! * 90-45-45\n! * 90-60-30\n! * 60-60-60\n!\n! Usage:\n! > triangle [size]\n!\n! where [size] is the number of points along an edge\n!\n!=======================================================================\n use mod_vtklib3\n implicit none\n\n integer :: ia\n integer :: iorder=3 ! triangles\n integer :: jjmax\n integer :: nnode=0 ! number of nodes\n integer :: nelem=0 ! number of elements\n\n real(8), parameter :: root3=sqrt(3.0d0)\n\n real(8), allocatable :: xi(:,:) ! (3,nnode)\n integer, allocatable :: gg(:,:) ! (iorder,nelem)\n\n integer, allocatable :: ibc(:) ! (nnode) boundary condition\n integer, allocatable :: matl(:) ! (nelem) material number\n\n character(len=100) :: fname='tri1.vtk'\n character(len=10) :: line\n\n!--- read command line for size\n\n jjmax=10 ! number of points on edge, default\n\n ia=iargc()\n if (ia.gt.0) then\n call getarg(1,line)\n read (line,*) jjmax\n endif\n\n!--- allocate arrays\n\n allocate (xi(3,jjmax*jjmax)) ! allocation bigger than it has to be\n allocate (gg(3,jjmax*jjmax)) ! allocation bigger than it has to be\n\n allocate (matl(jjmax*jjmax))\n allocate (ibc(jjmax*jjmax))\n\n matl(:)=1\n\n!--- build equilateral triangular mesh\n\n nelem=0\n nnode=0\n gg=0\n ibc=0\n\n call build_equilateral(jjmax, xi, gg, ibc, nelem, nnode)\n\n fname='tri1.vtk'\n write (*,'(/,2a)') ' creating vtk file: ', trim(fname)\n\n open (22,file=fname)\n call vtk_tri1(22, nnode, nelem, iorder, xi, gg)\n call vtk_tri2(22, nnode, ibc, 'bc', 'n') ! nodal data\n call vtk_tri2(22, nelem, matl, 'material', 'e') ! element data\n close (22)\n\n!--- build isosceles triangular mesh\n\n nelem=0\n nnode=0\n gg=0\n ibc=0\n\n call build_isosceles(jjmax, xi, gg, ibc, nelem, nnode)\n\n fname='tri2.vtk'\n write (*,'(/,2a)') ' creating vtk file: ', trim(fname)\n\n open (22,file=fname)\n call vtk_tri1(22, nnode, nelem, iorder, xi, gg)\n call vtk_tri2(22, nnode, ibc, 'bc', 'n') ! nodal data\n call vtk_tri2(22, nelem, matl, 'material', 'e') ! element data\n close (22)\n\n!--- build 30/60/90 triangular mesh\n\n nelem=0\n nnode=0\n gg=0\n ibc=0\n\n call build_306090(jjmax, xi, gg, ibc, nelem, nnode)\n\n fname='tri3.vtk'\n write (*,'(/,2a)') ' creating vtk file: ', trim(fname)\n\n open (22,file=fname)\n call vtk_tri1(22, nnode, nelem, iorder, xi, gg)\n call vtk_tri2(22, nnode, ibc, 'bc', 'n') ! nodal data\n call vtk_tri2(22, nelem, matl, 'material', 'e') ! element data\n close (22)\n\n!--- finish\n\n deallocate (xi,gg)\n deallocate (ibc)\n deallocate (matl)\n end\n\n!=======================================================================\n subroutine build_equilateral(jjmax, xi, gg, ibc, nelem, nnode)\n implicit none\n integer, intent(in) :: jjmax ! number of points per side\n integer, intent(out) :: nelem ! number of elements\n integer, intent(out) :: nnode ! number of nodes\n real(8), intent(out) :: xi(3,jjmax*jjmax) ! xyz points\n integer, intent(out) :: gg(3,jjmax*jjmax) ! element map\n integer, intent(out) :: ibc(jjmax*jjmax) ! boundary condition map\n\n integer :: i, j, ii\n real(8) :: delx\n real(8) :: dely\n real(8) :: x, y, x1\n\n write (*,*)\n write (*,*) 'building equilateral triangle mesh'\n write (*,*) 'number of points along edge ', jjmax\n\n delx=1.0d0/dble(jjmax-1)\n dely=delx*sqrt(3.0d0)/2.0d0\n\n y=0.0d0\n\n x1=0.0d0\n x=0.0d0\n y=0.0d0\n do j=1, jjmax\n x=x1\n ii=jjmax+1-j\n do i=1,ii\n\n nnode=nnode+1\n xi(1,nnode)=x\n xi(2,nnode)=y\n xi(3,nnode)=0.0d0\n x=x+delx\n if (i.eq.1 .or. i.eq.ii .or. j.eq.1) then\n ibc(nnode)=3\n else\n ibc(nnode)=0\n endif\n\n if (i.lt.ii) then\n nelem=nelem+1\n gg(1,nelem)=nnode\n gg(2,nelem)=nnode+1\n gg(3,nelem)=nnode+ii\n endif\n if (i.lt.ii-1) then\n nelem=nelem+1\n gg(1,nelem)=nnode+1\n gg(2,nelem)=nnode+ii+1\n gg(3,nelem)=nnode+ii\n endif\n\n enddo\n y=y+dely\n x1=x1+delx*0.5d0 ! increment half width for start of next time\n enddo\n\n write (*,*) 'final nnode ', nnode\n write (*,*) 'final nelem ', nelem\n\n!! write (*,*) 'sqrt3/2 = ', sqrt(3.0d0)/2.0d0\n!! write (*,*) 'final x = ', xi(1,nnode)\n!! write (*,*) 'final y = ', xi(2,nnode)\n\n x=xi(1,nnode)\n y=xi(2,nnode)\n if (abs(x-0.5d0) .gt.1.0d-8) stop 'error in final mesh x value'\n if (abs(y-sqrt(3.0d0)/2.0d0).gt.1.0d-8) stop 'error in final mesh y value'\n\n return\n end subroutine build_equilateral\n\n!=======================================================================\n subroutine build_isosceles(jjmax, xi, gg, ibc, nelem, nnode)\n implicit none\n integer, intent(in) :: jjmax ! number of points per side\n integer, intent(out) :: nelem ! number of elements\n integer, intent(out) :: nnode ! number of nodes\n real(8), intent(out) :: xi(3,jjmax*jjmax) ! xyz points\n integer, intent(out) :: gg(3,jjmax*jjmax) ! element map\n integer, intent(out) :: ibc(jjmax*jjmax) ! boundary condition map\n\n integer :: i, j, ii\n real(8) :: delx\n real(8) :: dely\n real(8) :: x, y\n\n write (*,*)\n write (*,*) 'building isosceles triangle mesh'\n write (*,*) 'number of points along edge ', jjmax\n\n delx=1.0d0/dble(jjmax-1)\n dely=delx\n\n y=0.0d0\n\n x=0.0d0\n y=0.0d0\n do j=1, jjmax\n x=0.0d0\n ii=jjmax+1-j\n do i=1,ii\n\n nnode=nnode+1\n xi(1,nnode)=x\n xi(2,nnode)=y\n xi(3,nnode)=0.0d0\n x=x+delx\n if (i.eq.1 .or. i.eq.ii .or. j.eq.1) then\n ibc(nnode)=3\n else\n ibc(nnode)=0\n endif\n\n if (i.lt.ii) then\n nelem=nelem+1\n gg(1,nelem)=nnode\n gg(2,nelem)=nnode+1\n gg(3,nelem)=nnode+ii\n endif\n if (i.lt.ii-1) then\n nelem=nelem+1\n gg(1,nelem)=nnode+1\n gg(2,nelem)=nnode+ii+1\n gg(3,nelem)=nnode+ii\n endif\n\n enddo\n y=y+dely\n enddo\n\n write (*,*) 'final nnode ', nnode\n write (*,*) 'final nelem ', nelem\n\n!! write (*,*) 'final x = ', xi(1,nnode)\n!! write (*,*) 'final y = ', xi(2,nnode)\n\n x=xi(1,nnode)\n y=xi(2,nnode)\n if (abs(x) .gt.1.0d-8) stop 'error in final mesh x value'\n if (abs(y-1.0d0).gt.1.0d-8) stop 'error in final mesh y value'\n\n return\n end subroutine build_isosceles\n\n!=======================================================================\n subroutine build_306090(jjmax, xi, gg, ibc, nelem, nnode)\n implicit none\n integer, intent(in) :: jjmax ! number of points per side\n integer, intent(out) :: nelem ! number of elements\n integer, intent(out) :: nnode ! number of nodes\n real(8), intent(out) :: xi(3,jjmax*jjmax) ! xyz points\n integer, intent(out) :: gg(3,jjmax*jjmax) ! element map\n integer, intent(out) :: ibc(jjmax*jjmax) ! boundary condition map\n\n integer :: i, j, ii\n real(8) :: delx\n real(8) :: dely\n real(8) :: x, y\n\n real(8), parameter :: root3=sqrt(3.0d0)\n\n write (*,*)\n write (*,*) 'building 30-60-90 triangle mesh'\n write (*,*) 'number of points along edge ', jjmax\n\n delx=1.0d0/dble(jjmax-1)\n dely=delx*root3\n\n y=0.0d0\n do j=1, jjmax\n x=0.0d0\n ii=jjmax+1-j\n do i=1,ii\n\n nnode=nnode+1\n xi(1,nnode)=x\n xi(2,nnode)=y\n xi(3,nnode)=0.0d0\n x=x+delx\n if (i.eq.1 .or. i.eq.ii .or. j.eq.1) then\n ibc(nnode)=3\n else\n ibc(nnode)=0\n endif\n\n if (i.lt.ii) then\n nelem=nelem+1\n gg(1,nelem)=nnode\n gg(2,nelem)=nnode+1\n gg(3,nelem)=nnode+ii\n endif\n if (i.lt.ii-1) then\n nelem=nelem+1\n gg(1,nelem)=nnode+1\n gg(2,nelem)=nnode+ii+1\n gg(3,nelem)=nnode+ii\n endif\n\n enddo\n y=y+dely\n enddo\n\n write (*,*) 'final nnode ', nnode\n write (*,*) 'final nelem ', nelem\n\n!! write (*,*) 'sqrt3 = ', root3\n!! write (*,*) 'final x = ', xi(1,nnode)\n!! write (*,*) 'final y = ', xi(2,nnode)\n\n x=xi(1,nnode)\n y=xi(2,nnode)\n if (abs(x) .gt.1.0d-8) stop 'error in final mesh x value'\n if (abs(y-sqrt(3.0d0)).gt.1.0d-8) stop 'error in final mesh y value'\n\n return\n end subroutine build_306090\n!=======================================================================\n", "meta": {"hexsha": "c43e48165c6aa885505838afe119288fa99b0a30", "size": 9242, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "meshgen/triangle.f90", "max_stars_repo_name": "palmtag/simple_mesh_util", "max_stars_repo_head_hexsha": "9dfb74416cf66e99b117d5336993c86d39c20bc7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "meshgen/triangle.f90", "max_issues_repo_name": "palmtag/simple_mesh_util", "max_issues_repo_head_hexsha": "9dfb74416cf66e99b117d5336993c86d39c20bc7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "meshgen/triangle.f90", "max_forks_repo_name": "palmtag/simple_mesh_util", "max_forks_repo_head_hexsha": "9dfb74416cf66e99b117d5336993c86d39c20bc7", "max_forks_repo_licenses": ["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.3431952663, "max_line_length": 80, "alphanum_fraction": 0.4902618481, "num_tokens": 3070, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970811069351, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.674949199399897}} {"text": "!**********************************************************************************************************************************\r\n!\r\n! PROGRAM: Compare_LAPACK_MUMPS.f90\r\n!\r\n! PURPOSE: Compares a solve of a system of equations by LAPACK and MUMPS.\r\n! \r\n! \r\n\r\n!**********************************************************************************************************************************\r\n\r\nPROGRAM Compare_LAPACK_MUMPS\r\n\r\n USE NWTC_Library\r\n USE NWTC_LAPACK\r\n USE MUMPS\r\n IMPLICIT NONE \r\n \r\n \r\n\r\n ! Variables\r\n \r\n \r\n ! File name\r\n CHARACTER(*),PARAMETER :: InputFilePath='C:\\Users\\bjonkman\\Documents\\DATA\\DesignCodes\\simulators\\FAST\\SVNdirectory\\branches\\FAST_MUMPS\\CertTest\\Test21'\r\n CHARACTER(1024) :: InputFileRoot\r\n CHARACTER(1024) :: InputFileName \r\n CHARACTER(10) :: TmpLine\r\n \r\n \r\n INTEGER(IntKi) :: ErrStat\r\n CHARACTER(1024) :: ErrMsg\r\n \r\n integer :: i, j, K, iTest, i_rhs, N, NZ\r\n integer :: UnIn, UnOut, UnOut2\r\n REAL :: time_begin, time_end\r\n REAL :: time_begin2, time_end2\r\n REAL :: init_time, init_time2\r\n REAL :: total_time, total_time2\r\n \r\n real, allocatable :: full_jac(:,:), rhs(:)\r\n integer,allocatable :: ipiv(:)\r\n \r\n type(SMUMPS_STRUC) :: mumps_par\r\n \r\n \r\n !............................................................................................................................... \r\n ! Initialize the library\r\n !............................................................................................................................... \r\n \r\n CALL NWTC_Init( )\r\n \r\n \r\n UnOut = -1\r\n UnOut2 = -1\r\n CALL GetNewUnit( UnOut )\r\n CALL OpenFOutFile( UnOut, 'LAPACK_MUMPS_timings.txt' )\r\n\r\n CALL GetNewUnit( UnOut2 )\r\n CALL OpenFOutFile( UnOut2, 'LAPACK_MUMPS_table.txt' )\r\n \r\n \r\n !............................................................................................................................... \r\n ! Initialize MUMPS\r\n !............................................................................................................................... \r\n CALL CPU_TIME(time_begin)\r\n \r\n CALL NWTC_SMUMPS_Init( mumps_par, ErrStat, ErrMsg ) \r\n \r\n CALL CPU_TIME ( time_end )\r\n \r\n WRITE(UnOut,'(A,ES15.7,A,ES15.7,A)') 'Initialization: MUMPS = ', time_end - time_begin, ' seconds' !; LAPACK = ', time_end2 - time_begin2, ' seconds.'\r\n \r\n \r\n UnIn = -1 \r\n do iTest = 27,19,-1\r\n\r\n CALL WrScr( 'Test'//TRIM(num2lstr(iTest)) )\r\n \r\n WRITE(UnOut,'(A)' ) '-----------------------------------------------------------------'\r\n \r\n \r\n !............................................................................................................................... \r\n ! Read the input files for matrix A\r\n !............................................................................................................................... \r\n \r\n if (iTest==26) then\r\n InputFileRoot = TRIM(InputFilePath)//'/10/Test21'\r\n elseif (iTest==27) then\r\n InputFileRoot = TRIM(InputFilePath)//'/05/Test21'\r\n else\r\n InputFileRoot = InputFilePath//'/Test'//TRIM(num2lstr(iTest))\r\n end if\r\n \r\n \r\n !......................\r\n CALL GetNewUnit( UnIn )\r\n InputFileName = TRIM(InputFileRoot)//'.0.Jacobian.Sparse'\r\n CALL OpenFInpFile( UnIn, TRIM(InputFileName) )\r\n \r\n READ(UnIn, *) N, NZ\r\n read(UnIn,*) tmpLine\r\n \r\n CALL NWTC_SMUMPS_CreateMatrix(mumps_par,n, ErrStat, ErrMsg, nz) \r\n mumps_par%NZ = nz\r\n \r\n DO I = 1, mumps_par%NZ\r\n READ(UnIn,*) mumps_par%IRN(I),mumps_par%JCN(I),mumps_par%A(I)\r\n END DO\r\n \r\n CLOSE(UnIn)\r\n \r\n !...................... \r\n InputFileName = TRIM(InputFileRoot)//'.0.Jacobian'\r\n CALL OpenFInpFile( UnIn, TRIM(InputFileName) )\r\n\r\n ALLOCATE( full_jac ( mumps_par%N, mumps_par%N ) )\r\n ALLOCATE( ipiv ( mumps_par%N ) )\r\n ALLOCATE( rhs ( mumps_par%N ) )\r\n \r\n read(UnIn,*) tmpLine\r\n DO I = 1, mumps_par%N\r\n read(UnIn,*) full_jac(i,:)\r\n END DO\r\n CLOSE(UnIn)\r\n \r\n \r\n !......................\r\n InputFileName = TRIM(InputFileRoot)//'.0.RHS'\r\n CALL OpenFInpFile( UnIn, TRIM(InputFileName) )\r\n !...................... \r\n \r\n !CALL WrScr( ' finished reading matrices' )\r\n \r\n !............................................................................................................................... \r\n ! Factor matrix A\r\n !............................................................................................................................... \r\n \r\n ! MUMPS\r\n \r\n CALL CPU_TIME(time_begin)\r\n CALL NWTC_SMUMPS_AnalyzeAndFactor(mumps_par, ErrStat, ErrMsg)\r\n CALL CPU_TIME ( time_end )\r\n if (ErrStat /= ErrID_None) THEN\r\n DEALLOCATE( full_jac )\r\n DEALLOCATE( ipiv )\r\n DEALLOCATE( rhs ) \r\n CALL WrScr(TRIM(ErrMsg))\r\n CALL NWTC_SMUMPS_DestroyMatrix(mumps_par) \r\n CYCLE\r\n end if \r\n\r\n \r\n init_time = time_end - time_begin \r\n \r\n ! LAPACK\r\n \r\n CALL CPU_TIME(time_begin2)\r\n CALL LAPACK_getrf( M=mumps_par%N, N=mumps_par%N, A=FULL_JAC, IPIV=ipiv, ErrStat=ErrStat, ErrMsg=ErrMsg ) \r\n CALL CPU_TIME ( time_end2 )\r\n if (ErrStat /= ErrID_None) CALL WrScr(TRIM(ErrMsg))\r\n \r\n \r\n init_time2 = time_end2 - time_begin2 \r\n \r\n \r\n ! Compare results\r\n WRITE(UnOut,'( 2(A,ES15.7) )') 'Test'//trim(num2lstr(iTest))//' factorization times: MUMPS = ', init_time, &\r\n ' seconds; LAPACK = ', init_time2\r\n \r\n \r\n !CALL WrScr( ' finished factoring matrices' )\r\n \r\n !............................................................................................................................... \r\n ! solve Ax=b\r\n !............................................................................................................................... \r\n READ(UnIn,*,iostat=ErrStat) mumps_par%RHS\r\n \r\n i_rhs = 0\r\n total_time = 0.\r\n total_time2 = 0.\r\n \r\n do while (ErrStat == 0 ) \r\n rhs = mumps_par%RHS\r\n i_rhs = i_rhs + 1\r\n !call wrscr('RHS'//trim(num2lstr(i_rhs)) )\r\n \r\n ! MUMPS\r\n \r\n CALL CPU_TIME(time_begin)\r\n CALL NWTC_SMUMPS_Solve(mumps_par, ErrStat, ErrMsg)\r\n CALL CPU_TIME ( time_end ) \r\n total_time = total_time + time_end - time_begin\r\n if (ErrStat /= ErrID_None) CALL WrScr(TRIM(ErrMsg))\r\n ! LAPACK\r\n \r\n CALL CPU_TIME(time_begin2)\r\n CALL LAPACK_getrs( TRANS='N', N=mumps_par%N, A=FULL_JAC, IPIV=ipiv, B=rhs, ErrStat=ErrStat, ErrMsg=ErrMsg ) \r\n CALL CPU_TIME ( time_end2 )\r\n total_time2 = total_time2 + time_end2 - time_begin2\r\n if (ErrStat /= ErrID_None) CALL WrScr(TRIM(ErrMsg))\r\n \r\n \r\n WRITE(UnOut,'( 3(A,ES15.7) )') 'Test'//trim(num2lstr(iTest))//' solve times: MUMPS = ', time_end - time_begin, &\r\n ' seconds; LAPACK = ', time_end2 - time_begin2, &\r\n ' seconds. Norm of difference = ', TwoNorm( rhs - mumps_par%rhs )\r\n \r\n \r\n READ(UnIn,*,iostat=ErrStat) mumps_par%RHS\r\n\r\n end do !while there is a line in the file\r\n \r\n \r\n WRITE(UnOut,'( 2(A,ES15.7),A,I5 )') 'Test'//trim(num2lstr(iTest))//' solve times: MUMPS = ', total_time, &\r\n ' seconds; LAPACK = ', total_time2, &\r\n ' seconds. Number of solves = ', i_rhs\r\n \r\n WRITE(UnOut2, '( 3(I15,1x), 8(ES15.7,1x), I15, 2(1x,ES15.7) )') &\r\n iTest, mumps_par%n, mumps_par%nz, 100.0*mumps_par%nz/(mumps_par%n**2), &\r\n 0.0, 0.0, 0.0, & !time savings columns\r\n init_time, init_time2, & !init time \r\n total_time/i_rhs, total_time2/i_rhs, & !solve time (calculated)\r\n i_rhs, total_time, total_time2\r\n \r\n \r\n !............................................................................................................................... \r\n ! Deallocate arrays and close open files\r\n !............................................................................................................................... \r\n \r\n CLOSE(UnIn)\r\n \r\n DEALLOCATE( full_jac )\r\n DEALLOCATE( ipiv )\r\n DEALLOCATE( rhs )\r\n \r\n CALL CPU_TIME(time_begin)\r\n CALL NWTC_SMUMPS_DestroyMatrix(mumps_par) \r\n CALL CPU_TIME ( time_end )\r\n !WRITE (UnOut,*) 'MUMPS exit time: ', time_end - time_begin, ' seconds'\r\n WRITE(UnOut,* ) !blank line\r\n \r\n end do ! next test case\r\n \r\n CLOSE( UnOut )\r\n CLOSE( UnOut2 )\r\n CALL NWTC_SMUMPS_End(mumps_par) \r\n\r\n \r\nEND PROGRAM Compare_LAPACK_MUMPS\r\n\r\n", "meta": {"hexsha": "f0f1247304f6d61839a3e1270373093e9523da7f", "size": 9712, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Drivers/Compare_LAPACK_MUMPS/Compare_LAPACK_MUMPS.f90", "max_stars_repo_name": "ghaymanNREL/NWTC_Library", "max_stars_repo_head_hexsha": "ee2266f8f4bbb602988b2830b2c0f191e8e4563d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2018-06-23T11:52:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-26T12:38:20.000Z", "max_issues_repo_path": "Drivers/Compare_LAPACK_MUMPS/Compare_LAPACK_MUMPS.f90", "max_issues_repo_name": "NWTC/NWTC_Library", "max_issues_repo_head_hexsha": "5a78d53acab9f8a3634879da9c5f69c2cdfd072a", "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": "Drivers/Compare_LAPACK_MUMPS/Compare_LAPACK_MUMPS.f90", "max_forks_repo_name": "NWTC/NWTC_Library", "max_forks_repo_head_hexsha": "5a78d53acab9f8a3634879da9c5f69c2cdfd072a", "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.848, "max_line_length": 155, "alphanum_fraction": 0.3948723229, "num_tokens": 2217, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.6749491922065772}} {"text": "Real Function w1535(dmass)\n Save\n avmass = 0.938868\n pimass = 0.137265\n aux = 0.25*(dmass**2-avmass**2-pimass**2)**2 - (avmass*pimass)**2\n If (aux>0.) Then\n qavail = sqrt(aux/dmass**2)\n Else\n qavail = 1.E-06\n End If\n w1535 = 0.15*qavail/0.467\n Return\nEnd Function w1535\n", "meta": {"hexsha": "bd31f1ef6532c132db51895d3c8f1c584de31959", "size": 287, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/w1535.f90", "max_stars_repo_name": "xiaohaijin/AMPT", "max_stars_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-12-24T19:37:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-14T12:58:59.000Z", "max_issues_repo_path": "src/w1535.f90", "max_issues_repo_name": "xiaohaijin/AMPT", "max_issues_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_issues_repo_licenses": ["MIT"], "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/w1535.f90", "max_forks_repo_name": "xiaohaijin/AMPT", "max_forks_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_forks_repo_licenses": ["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.5, "max_line_length": 67, "alphanum_fraction": 0.6271777003, "num_tokens": 128, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475794701961, "lm_q2_score": 0.7154239897159438, "lm_q1q2_score": 0.674893488993446}} {"text": "! extends MESA constants and updates them to CODATA 2010 values\n\nmodule constants_def\n use const_def\n \n implicit none\n\n ! mathematical constants\n real(dp), parameter :: twopi = 2.0_dp*pi\n real(dp), parameter :: threepi = 3.0_dp*pi\n real(dp), parameter :: fourpi = 4.0_dp*pi\n real(dp), parameter :: onethird = one_third\n real(dp), parameter :: twothird = two_thirds\n real(dp), parameter :: fivethird = 5.0_dp*onethird\n real(dp), parameter :: seventhird = 7.0_dp*onethird\n real(dp), parameter :: threepisquare = (3.0_dp*pi**2)\n\n ! physical and astronomical constants, in cgs units\n real(dp), save :: boltzmann ! = 1.3806488e-16_dp\n real(dp), save :: avogadro ! = 6.02214129e23_dp\n real(dp), save :: clight2 ! = clight**2\n real(dp), save :: sigma_SB ! = 5.670400e-5\n real(dp), save :: arad ! = sigma_SB*4.0/clight\n real(dp), save :: finestructure ! = 7.2973525698e-3_dp\n real(dp), save :: Gnewton ! = 6.67384e-8_dp\n real(dp), save :: Mneutron ! = 1.674927351e-24_dp\n real(dp), save :: Mproton ! = 1.672621777e-24_dp\n real(dp), save :: si_charge ! = 1.602176565e-19_dp\n real(dp), save :: electroncharge ! = si_charge*clight*0.1_dp\n real(dp), save :: Melectron ! = 9.10938291e-28_dp\n real(dp), save :: Mmuon ! = 1.883531475e-25_dp\n real(dp), save :: theta_weak ! = 0.2223_dp\n\n ! astronomical constants -- see http://ssd.jpl.nasa.gov/?constants\n real(dp), save :: julian_day ! = 86400_dp\n real(dp), save :: julian_year ! = 365.25_dp * julian_day\n real(dp), save :: GMsun ! = 1.32712440018e26_dp\n\n ! some conversion factors\n real(dp), save :: fm_to_cm ! = 1.0e-13_dp\n real(dp), save :: ergs_to_mev ! = 1.0_dp/mev_to_ergs\n real(dp), save :: cm_to_fm ! = 1.0_dp/fm_to_cm\n \n ! atomic units (length in Bohr radii for hydrogen, energy in Rydberg)\n real(dp), save :: a_Bohr ! = hbar**2/Melectron/electroncharge**2\n real(dp), save :: Rydberg ! = 0.5_dp*electroncharge**2/a_Bohr\n \n ! nuclear units (c = 1, hbar = 197 MeV fm; energy is expressed in MeV, length in fm)\n real(dp), save :: hbarc_n ! = hbar*clight/mev_to_ergs/fm_to_cm\n real(dp), save :: mass_n ! = mev_to_ergs/clight2\n real(dp), save :: length_n ! = fm_to_cm\n real(dp), save :: density_n ! = 1.0_dp/fm_to_cm**3\n real(dp), save :: pressure_n ! = mev_to_ergs*density_n\n real(dp), save :: temperature_n ! = mev_to_ergs/boltzmann\n real(dp), save :: Mn_n ! = Mneutron*clight2*ergs_to_mev\n real(dp), save :: Mp_n ! = Mproton*clight2*ergs_to_mev\n real(dp), save :: Me_n ! = Melectron*clight2*ergs_to_mev\n real(dp), save :: amu_n ! = amu*clight2*ergs_to_mev\n \n ! gravitational units (G = c = 1; unit of mass is Msun)\n real(dp), save :: mass_g ! = Msun\n real(dp), save :: potential_g ! = clight2\n real(dp), save :: length_g ! = Gnewton*mass_g/potential_g\n real(dp), save :: density_g ! = mass_g/length_g**3\n real(dp), save :: pressure_g ! = density_g*potential_g\n real(dp), save :: time_g ! = length_g/clight\n\n\ncontains\n\n subroutine initialize_constants\n\n boltzmann = 1.3806488e-16_dp\n avogadro = 6.02214129e23_dp\n clight = 2.99792458e10_dp\n clight2 = clight**2\n sigma_SB = 5.670400e-5\n arad = sigma_SB*4.0/clight\n amu = 1.660538921e-24_dp\n hbar = 1.054571726e-27_dp\n finestructure = 7.2973525698e-3_dp\n Gnewton = 6.67384e-8_dp\n Mneutron = 1.674927351e-24_dp\n Mproton = 1.672621777e-24_dp\n si_charge = 1.602176565e-19_dp\n electroncharge = si_charge*clight*0.1_dp\n Melectron = 9.10938291e-28_dp\n Mmuon = 1.883531475e-25_dp\n theta_weak = 0.2223_dp\n\n julian_day = 86400_dp\n julian_year = 365.25_dp * julian_day\n GMsun = 1.32712440018e26_dp\n Msun = GMsun/Gnewton\n\n mev_to_ergs = 1.602176565e-6_dp\n fm_to_cm = 1.0e-13_dp\n ergs_to_mev = 1.0_dp/mev_to_ergs\n cm_to_fm = 1.0_dp/fm_to_cm\n\n a_Bohr = hbar**2/Melectron/electroncharge**2\n Rydberg = 0.5_dp*electroncharge**2/a_Bohr\n\n hbarc_n = hbar*clight/mev_to_ergs/fm_to_cm\n mass_n = mev_to_ergs/clight2\n length_n = fm_to_cm\n density_n = 1.0_dp/fm_to_cm**3\n pressure_n = mev_to_ergs*density_n\n temperature_n = mev_to_ergs/boltzmann\n Mn_n = Mneutron*clight2*ergs_to_mev\n Mp_n = Mproton*clight2*ergs_to_mev\n Me_n = Melectron*clight2*ergs_to_mev\n amu_n = amu*clight2*ergs_to_mev\n\n mass_g = Msun\n potential_g = clight2\n length_g = Gnewton*mass_g/potential_g\n density_g = mass_g/length_g**3\n pressure_g = density_g*potential_g\n time_g = length_g/clight\n\n standard_cgrav = Gnewton\n ! gravitational constant (g^-1 cm^3 s^-2)\n planck_h = hbar*2.0*pi \n ! Planck's constant (erg s)\n qe = electroncharge\n ! electron charge (esu == (g cm^3 s^-2)^(1/2))\n avo = avogadro \n ! Avogadro's constant (mole^-1)\n kerg = boltzmann \n ! Boltzmann's constant (erg K^-1)\n boltzm = kerg\n cgas = boltzm*avo !ideal gas constant; erg/K\n kev = 8.617385d-5 \n ! converts temp to ev (ev K^-1)\n\n mn = Mneutron! neutron mass (g)\n mp = Mproton ! proton mass (g)\n me = Melectron ! (was 9.1093897d-28) electron mass (g)\n rbohr = a_Bohr ! Bohr radius (cm)\n fine = finestructure ! fine structure constant\n ev2erg = 1.602176487d-12 ! electron volt (erg)\n hion = Rydberg/ev2erg ! hydrogen ionization energy (eV)\n mev_amu = mev_to_ergs/amu\n Qconv = mev_to_ergs*avo\n\n boltz_sigma = sigma_SB\n ! boltzmann's sigma = a*c/4 (erg cm^-2 K^-4 s^-1)\n crad = arad\n ! = radiation density constant, a (erg cm^-3 K^-4); Prad = crad * T^4 / 3\n ! approx = 7.5657e-15\n\n ssol = boltz_sigma\n asol = crad\n weinlam = planck_h*clight/(kerg * 4.965114232d0)\n weinfre = 2.821439372d0*kerg/planck_h\n rhonuc = 2.342d14 ! density of nucleus (g cm^3)\n\n ! solar age, L, and R values from Bahcall et al, ApJ 618 (2005) 1049-1056.\n msol = Msun ! solar mass (g) <<< gravitational mass, not baryonic\n rsol = 6.9598d10 ! solar radius (cm)\n lsol = 3.8418d33 ! solar luminosity (erg s^-1)\n agesol = 4.57d9 ! solar age (years)\n Rsun = rsol\n Lsun = lsol\n Msun33 = msol*1d-33\n Rsun11 = rsol*1d-11\n Lsun33 = lsol*1d-33\n ly = 9.460528d17 ! light year (cm)\n pc = 3.261633d0 * ly ! parsec (cm)\n secyer = 3.1558149984d7 ! seconds per year\n\n m_earth = 5.9764d27 ! earth mass (g)\n ! = 3.004424e-6 Msun\n r_earth = 6.37d8 ! earth radius (cm)\n au = 1.495978921d13 ! astronomical unit (cm)\n\n m_jupiter = 1.8986d30 ! jupiter mass (g)\n ! = 0.954454d-3 Msun\n r_jupiter = 6.9911d9 ! jupiter mean radius (cm)\n semimajor_axis_jupiter = 7.7857d13 ! jupiter semimajor axis (cm)\n \n end subroutine initialize_constants\n\nend module constants_def\n", "meta": {"hexsha": "36720e7c0ef5489afdb727a476e1f722b1c68b12", "size": 8236, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "constants/public/constants_def.f", "max_stars_repo_name": "LBJ-Wade/dStar", "max_stars_repo_head_hexsha": "d63b1a611937e8eccfb3c98ebbbdb4cd0c2fd19b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "constants/public/constants_def.f", "max_issues_repo_name": "LBJ-Wade/dStar", "max_issues_repo_head_hexsha": "d63b1a611937e8eccfb3c98ebbbdb4cd0c2fd19b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "constants/public/constants_def.f", "max_forks_repo_name": "LBJ-Wade/dStar", "max_forks_repo_head_hexsha": "d63b1a611937e8eccfb3c98ebbbdb4cd0c2fd19b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.2795698925, "max_line_length": 90, "alphanum_fraction": 0.5305973774, "num_tokens": 2615, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632329799586, "lm_q2_score": 0.7090191337850932, "lm_q1q2_score": 0.6748892449293286}} {"text": "* MC01VD EXAMPLE PROGRAM TEXT\n* Copyright (c) 2002-2020 NICONET e.V.\n*\n* .. Parameters ..\n INTEGER NIN, NOUT\n PARAMETER ( NIN = 5, NOUT = 6 )\n* .. Local Scalars ..\n DOUBLE PRECISION A, B, C, Z1IM, Z1RE, Z2IM, Z2RE\n INTEGER INFO\n* .. External Subroutines ..\n EXTERNAL MC01VD\n* .. Executable Statements ..\n*\n WRITE ( NOUT, FMT = 99999 )\n* Skip the heading in the data file and read the data.\n READ ( NIN, FMT = '()' )\n READ ( NIN, FMT = * ) A, B, C\n* Solve the quadratic equation A*x**2 + B*x + C = 0.\n CALL MC01VD( A, B, C, Z1RE, Z1IM, Z2RE, Z2IM, INFO )\n*\n IF ( INFO.NE.0 ) THEN\n WRITE ( NOUT, FMT = 99998 ) INFO\n ELSE\n WRITE ( NOUT, FMT = 99997 )\n WRITE ( NOUT, FMT = 99996 ) Z1RE, Z1IM, Z2RE, Z2IM\n END IF\n*\n STOP\n*\n99999 FORMAT (' MC01VD EXAMPLE PROGRAM RESULTS',/1X)\n99998 FORMAT (' INFO on exit from MC01VD = ',I2)\n99997 FORMAT (' The roots of the quadratic equation are ')\n99996 FORMAT (/' x = ',F8.4,2X,SP,F8.4,'*j',SS,/' x = ',F8.4,2X,SP,F8.4,\n $ '*j')\n END\n", "meta": {"hexsha": "e25905e76fd25df64686b2eca5148bd74152215f", "size": 1135, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "examples/TMC01VD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "examples/TMC01VD.f", "max_issues_repo_name": "bnavigator/SLICOT-Reference", "max_issues_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "examples/TMC01VD.f", "max_forks_repo_name": "bnavigator/SLICOT-Reference", "max_forks_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 31.5277777778, "max_line_length": 72, "alphanum_fraction": 0.531277533, "num_tokens": 403, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6748686371140403}} {"text": "PROGRAM F027\n\n ! Copyright 2021 Melwyn Francis Carlo\n ! FILE REFERENCE: http://www.naturalnumbers.org/primes.html\n\n IMPLICIT NONE\n\n INTEGER :: PRIME_NUM\n CHARACTER (LEN=50), PARAMETER :: FILENAME = \"problems/003/PrimeNumbers_Upto_1000000\"\n\n INTEGER, DIMENSION(1000) :: PRIMES_LIST\n\n INTEGER :: A = -999\n INTEGER :: B_COUNT = 0\n\n INTEGER :: A_MAX = 0\n INTEGER :: B_MAX = 0\n INTEGER :: N_MAX = 0\n\n INTEGER :: I = 1\n\n INTEGER :: B, N, J, MAX_PRIME\n\n OPEN (2, FILE = FILENAME, STATUS = 'OLD')\n\n DO WHILE (I /= 1000)\n READ(2, *, END=10) PRIME_NUM\n IF (PRIME_NUM < 1000) B_COUNT = B_COUNT + 1\n PRIMES_LIST(I) = PRIME_NUM\n I = I + 1\n END DO\n\n 10 CLOSE(2)\n\n DO WHILE (A < 1000)\n\n B = 1\n DO WHILE (B < B_COUNT)\n\n N = 1\n J = 1\n MAX_PRIME = (N * N) + (A * N) + PRIMES_LIST(B)\n\n DO WHILE (J < 1000)\n\n IF (PRIMES_LIST(J) > MAX_PRIME) EXIT\n\n IF (MAX_PRIME == PRIMES_LIST(J)) THEN\n N = N + 1\n J = 1\n MAX_PRIME = (N * N) + (A * N) + PRIMES_LIST(B)\n CYCLE\n END IF\n\n J = J + 1\n\n END DO\n\n IF (N > N_MAX) THEN\n N_MAX = N\n A_MAX = A\n B_MAX = PRIMES_LIST(B)\n END IF\n\n B = B + 1\n\n END DO\n\n A = A + 1\n\n END DO\n\n PRINT ('(I0)'), A_MAX * B_MAX\n\nEND PROGRAM F027\n", "meta": {"hexsha": "3a6142b226cbabf8b4f54ef98908ab90f2e636be", "size": 1536, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "problems/027/027.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/027/027.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/027/027.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.2105263158, "max_line_length": 88, "alphanum_fraction": 0.4537760417, "num_tokens": 482, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240756264638, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6748686361175641}} {"text": "!-------------------------------------------------------------------------------\nsubroutine chgm ( a, b, x, hg )\n\n!*****************************************************************************80\n!\n!! CHGM computes the confluent hypergeometric function M(a,b,x).\n!\n! Licensing:\n!\n! This routine is copyrighted by Shanjie Zhang and Jianming Jin. However, \n! they give permission to incorporate this routine into a user program \n! provided that the copyright is acknowledged.\n!\n! Modified:\n!\n! 27 July 2012\n!\n! Author:\n!\n! Shanjie Zhang, Jianming Jin\n!\n! Reference:\n!\n! Shanjie Zhang, Jianming Jin,\n! Computation of Special functions,\n! Wiley, 1996,\n! ISBN: 0-471-11963-6,\n! LC: QA351.C45.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) A, B, parameters.\n!\n! Input, real ( kind = 8 ) X, the argument.\n!\n! Output, real ( kind = 8 ) HG, the value of M(a,b,x).\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) a0\n real ( kind = 8 ) a1\n !real ( kind = 8 ) aa\n real ( kind = 8 ) b\n real ( kind = 8 ) hg\n real ( kind = 8 ) hg1\n real ( kind = 8 ) hg2\n integer ( kind = 4 ) i\n integer ( kind = 4 ) j\n integer ( kind = 4 ) k\n integer ( kind = 4 ) la\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n integer ( kind = 4 ) nl\n real ( kind = 8 ) pi\n real ( kind = 8 ) r\n real ( kind = 8 ) r1\n real ( kind = 8 ) r2\n real ( kind = 8 ) rg\n real ( kind = 8 ) sum1\n real ( kind = 8 ) sum2\n real ( kind = 8 ) ta\n real ( kind = 8 ) tb\n real ( kind = 8 ) tba\n real ( kind = 8 ) x\n real ( kind = 8 ) x0\n real ( kind = 8 ) xg\n real ( kind = 8 ) y0\n real ( kind = 8 ) y1\n\n pi = 3.141592653589793D+00\n a0 = a\n a1 = a\n x0 = x\n hg = 0.0D+00\n\n if ( b == 0.0D+00 .or. b == - abs ( int ( b ) ) ) then\n hg = 1.0D+300\n else if ( a == 0.0D+00 .or. x == 0.0D+00 ) then\n hg = 1.0D+00\n else if ( a == -1.0D+00 ) then\n hg = 1.0D+00 - x / b\n else if ( a == b ) then\n hg = exp ( x )\n else if ( a - b == 1.0D+00 ) then\n hg = ( 1.0D+00 + x / b ) * exp ( x )\n else if ( a == 1.0D+00 .and. b == 2.0D+00 ) then\n hg = ( exp ( x ) - 1.0D+00 ) / x\n else if ( a == int ( a ) .and. a < 0.0D+00 ) then\n m = int ( - a )\n r = 1.0D+00\n hg = 1.0D+00\n do k = 1, m\n r = r * ( a + k - 1.0D+00 ) / k / ( b + k - 1.0D+00 ) * x\n hg = hg + r\n end do\n end if\n\n if ( hg /= 0.0D+00 ) then\n return\n end if\n\n if ( x < 0.0D+00 ) then\n a = b - a\n a0 = a\n x = abs ( x )\n end if\n\n if ( a < 2.0D+00 ) then\n nl = 0\n end if\n\n if ( 2.0D+00 <= a ) then\n nl = 1\n la = int ( a )\n a = a - la - 1.0D+00\n end if\n\n do n = 0, nl\n\n if ( 2.0D+00 <= a0 ) then\n a = a + 1.0D+00\n end if\n\n if ( x <= 30.0D+00 + abs ( b ) .or. a < 0.0D+00 ) then\n\n hg = 1.0D+00\n rg = 1.0D+00\n do j = 1, 500\n rg = rg * ( a + j - 1.0D+00 ) &\n / ( j * ( b + j - 1.0D+00 ) ) * x\n hg = hg + rg\n if ( abs ( rg / hg ) < 1.0D-15 ) then\n exit\n end if\n end do\n\n else\n\n ta = gamma(a)\n tb = gamma(b)\n xg = b - a\n tba = gamma(xg)\n sum1 = 1.0D+00\n sum2 = 1.0D+00\n r1 = 1.0D+00\n r2 = 1.0D+00\n do i = 1, 8\n r1 = - r1 * ( a + i - 1.0D+00 ) * ( a - b + i ) / ( x * i )\n r2 = - r2 * ( b - a + i - 1.0D+00 ) * ( a - i ) / ( x * i )\n sum1 = sum1 + r1\n sum2 = sum2 + r2\n end do\n hg1 = tb / tba * x ** ( - a ) * cos ( pi * a ) * sum1\n hg2 = tb / ta * exp ( x ) * x ** ( a - b ) * sum2\n hg = hg1 + hg2\n\n end if\n\n if ( n == 0 ) then\n y0 = hg\n else if ( n == 1 ) then\n y1 = hg\n end if\n\n end do\n\n if ( 2.0D+00 <= a0 ) then\n do i = 1, la - 1\n hg = ( ( 2.0D+00 * a - b + x ) * y1 + ( b - a ) * y0 ) / a\n y0 = y1\n y1 = hg\n a = a + 1.0D+00\n end do\n end if\n\n if ( x0 < 0.0D+00 ) then\n hg = hg * exp ( x0 )\n end if\n\n a = a1\n x = x0\n\n return\nend\n", "meta": {"hexsha": "061b358405f50d979728a09f9c1bdcf43d6debef", "size": 3910, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/zhangjin.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/zhangjin.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/zhangjin.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": 21.0215053763, "max_line_length": 80, "alphanum_fraction": 0.4299232737, "num_tokens": 1678, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770433, "lm_q2_score": 0.7799928900257127, "lm_q1q2_score": 0.6748686326891139}} {"text": " SUBROUTINE DCPDRV (C,NC,D,ND)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nC>> 1994-11-11 DCPDRV Krogh Declared all vars.\nC>> 1994-10-20 DCPDRV Krogh Changes to use M77CON\nC>> 1987-12-09 DCPDRV Lawson Initial code.\nc--D replaces \"?\": ?CPDRV\n INTEGER NC, ND, J, K\n DOUBLE PRECISION C(*),D(*),D1,D2,FAC,ZERO,HALF,TWO\n DATA ZERO,HALF,TWO/ 0.D0, .5D0, 2.D0 /\nC\nC INTEGRATION OF FINITE CHEBYSHEV SERIES\nC C.L.LAWSON, JPL, 1973 JULY 19\nC\nC (C(I),I=1,2) SCALE FACTORS .\nC C(I+2),I=1,NC+1 COEFS OF CHEBY SERIES .\nC NC DEGREE OF CHEBY SERIES .\nC (D(I),I=1,2) OUTPUT.. SCALE FACTORS .\nC (D(I+2),I=1,ND+1) OUTPUT.. COEFS DEFINING DIFFERENTIATED\nC SERIES .\nC ND OUTPUT.. DEGREE OF SERIES\nC\n IF (NC .LT. 0) THEN\n CALL IERM1('DCPDRV',1,0,'REQUIRE NC .GE. 0','NC',NC,'.')\n ELSE\n D(1)=C(1)\n D(2)=C(2)\n IF (NC .EQ. 0) THEN\n ND=0\n D(3)=ZERO\n RETURN\n END IF\n D2=ZERO\n ND=NC-1\n IF(ND .NE. 0) THEN\n D1=ZERO\n FAC=2*NC\n DO 20 J=1,ND\n D(ND+4-J)= FAC*C(ND+5-J) + D2\n D2=D1\n D1=D(ND+4-J)\n 20 FAC=FAC-TWO\n END IF\n D(3)=C(4) + D2*HALF\n DO 40 K=1,NC\n 40 D(K+2)=D(K+2)/D(2)\n END IF\n RETURN\n END\n", "meta": {"hexsha": "bf17035d1cd10d02db90a09973e1ece03b15334d", "size": 1511, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/dcpdrv.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/dcpdrv.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/dcpdrv.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": 29.6274509804, "max_line_length": 70, "alphanum_fraction": 0.5082726671, "num_tokens": 578, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.88720460564669, "lm_q2_score": 0.7606506635289835, "lm_q1q2_score": 0.6748527719711249}} {"text": "\tREAL FUNCTION TCRVALUE(ALPHA,N)\r\n\tUSE MSIMSL\r\nC\r\nC-Description-----------------------------------------------------------\r\n\tIMPLICIT NONE\r\nC\r\nC Function:\r\nC\tCalculate the critical t value tn such that pr[t>tn]=alpha\r\nC\twhere t has a t distribution with n degrees of freedom.\r\nC Usage:\r\nC\tPS program\r\nC Arguments:\r\nC i\tALPHA\t\t(real*4)\r\nC i\tN\t\t(real*4)\r\nC Notes:\r\nC .\tThis routine was written by Dale Plummer\r\nC .\tDesigned by Dr. William Dupont\r\nC\r\nC-Declarations----------------------------------------------------------\r\nC\r\nC\r\nC Arguments\r\nC\r\n\tREAL ALPHA\r\n\tREAL N\r\nC\r\nC Functions\r\nC\r\n\tREAL G,ZCRVALUE\r\n\tEXTERNAL G\r\nC\r\nC Locals\r\nC\r\n\tREAL T,N0\r\nC\r\nC Common to pass values to the function g.\r\nC\r\n\tREAL GALPHA\r\n\tREAL GN\r\n\tCOMMON /GCOM/GALPHA,GN\r\n\r\n\tREAL*4 EPS, ERRABS, ERRREL, ETA\r\n\tINTEGER*4 ITMAX, NROOT\r\n\r\nC-Code------------------------------------------------------------------\r\nC\r\n\tERRABS=1.0E-5\r\n\tEPS=1.0E-5\r\n\tERRREL=1.0E-5\r\n\tETA=1.0E-2\r\n\tITMAX=100\r\n\tNROOT=1\r\nC\r\nC Copy values to common so they can be used in the G function.\r\nC\r\n\tGALPHA=ALPHA\r\n\tGN=N\r\nC\r\nC Use secant method.\r\nC\r\n\tN0=ZCRVALUE(ALPHA)\r\n\tCALL ZERO(G,N0,0.00001,T)\r\n\tTCRVALUE=T\r\nC\r\nC Solve the equation G(x)=0.\r\n\r\nCCC\tXGUESS(1)=ZCRVALUE(ALPHA)\r\nCCC\tCALL ZREAL(G,ERRABS,ERRREL,EPS,ETA,NROOT,ITMAX,\r\nCCC .\t\t\t XGUESS,XVECT,INFO)\r\nC\r\nC If convergence was not reached then INFO(1) will be greater than\r\nC ITMAX. Check for that here. Force a divide by zero error that will\r\nC signal an error to the calling (Visual Basic) program.\r\nC\r\nCCC\tIF (INFO(1).GT.ITMAX) THEN\r\nCCC\t\tNROOT=NROOT/0.0\r\nCCC\t\tRETURN\r\nCCC\tEND IF\r\nC\r\nC\tThe result is in XVECT(1).\r\nC\r\nCCC\tTCRVALUE=XVECT(1)\r\nC\r\nC Return.\r\nC\r\n\tRETURN\r\n\tEND\r\n", "meta": {"hexsha": "ce4dbdcf8e49de7d3dd82d9864effccbde56d311", "size": 1710, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "misc/old_ps/ps-development-version/psDll/tcrvalue.for", "max_stars_repo_name": "vubiostat/ps", "max_stars_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2017-12-29T14:19:14.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-06T15:08:46.000Z", "max_issues_repo_path": "misc/old_ps/ps-development-version/psDll/tcrvalue.for", "max_issues_repo_name": "vubiostat/ps", "max_issues_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2020-04-30T16:57:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-07T00:26:02.000Z", "max_forks_repo_path": "misc/old_ps/ps-development-version/psDll/tcrvalue.for", "max_forks_repo_name": "vubiostat/ps", "max_forks_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-07T20:11:54.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-11T19:18:59.000Z", "avg_line_length": 19.4318181818, "max_line_length": 74, "alphanum_fraction": 0.5959064327, "num_tokens": 565, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.7606506635289835, "lm_q1q2_score": 0.6748527583597564}} {"text": "subroutine laguer_sp(a,x,its)\n use mo_kind, only : i4, sp, spc\n use mo_nrutil, only : nrerror, poly, poly_term\n\n implicit none\n\n integer(i4), intent(out) :: its\n complex(spc), intent(inout) :: x\n complex(spc), dimension(:), intent(in) :: a\n real(sp), parameter :: eps=epsilon(1.0_sp)\n integer(i4), parameter :: mr=8,mt=10,maxit=mt*mr\n integer(i4) :: iter,m\n real(sp) :: abx,abp,abm,err\n complex(spc) :: dx,x1,f,g,h,sq,gp,gm,g2\n complex(spc), dimension(size(a)) :: b,d\n real(sp), dimension(mr) :: frac = &\n (/ 0.5_sp,0.25_sp,0.75_sp,0.13_sp,0.38_sp,0.62_sp,0.88_sp,1.0_sp /)\n\n m=size(a)-1\n do iter=1,maxit\n its=iter\n abx=abs(x)\n b(m+1:1:-1)=poly_term(a(m+1:1:-1),x)\n d(m:1:-1)=poly_term(b(m+1:2:-1),x)\n f=poly(x,d(2:m))\n err=eps*poly(abx,abs(b(1:m+1)))\n if (abs(b(1)) <= err) return\n g=d(1)/b(1)\n g2=g*g\n h=g2-2.0_sp*f/b(1)\n sq=sqrt((m-1)*(m*h-g2))\n gp=g+sq\n gm=g-sq\n abp=abs(gp)\n abm=abs(gm)\n if (abp < abm) gp=gm\n if (max(abp,abm) > 0.0_sp) then\n dx=m/gp\n else\n dx=exp(cmplx(log(1.0_sp+abx),iter,kind=spc))\n end if\n x1=x-dx\n if (x == x1) return\n if (mod(iter,mt) /= 0) then\n x=x1\n else\n x=x-dx*frac(iter/mt) \n end if\n end do\n call nrerror('laguer: too many iterations')\nend subroutine laguer_sp\n\nsubroutine laguer_dp(a,x,its)\n use mo_kind, only : i4, dp, dpc\n use mo_nrutil, only : nrerror, poly, poly_term\n\n implicit none\n\n integer(i4), intent(out) :: its\n complex(dpc), intent(inout) :: x\n complex(dpc), dimension(:), intent(in) :: a\n real(dp), parameter :: eps=epsilon(1.0_dp)\n integer(i4), parameter :: mr=8,mt=10,maxit=mt*mr\n integer(i4) :: iter,m\n real(dp) :: abx,abp,abm,err\n complex(dpc) :: dx,x1,f,g,h,sq,gp,gm,g2\n complex(dpc), dimension(size(a)) :: b,d\n real(dp), dimension(mr) :: frac = &\n (/ 0.5_dp,0.25_dp,0.75_dp,0.13_dp,0.38_dp,0.62_dp,0.88_dp,1.0_dp /)\n\n m=size(a)-1\n do iter=1,maxit\n its=iter\n abx=abs(x)\n b(m+1:1:-1) = poly_term(a(m+1:1:-1),x)\n d(m:1:-1) = poly_term(b(m+1:2:-1),x)\n f = poly(x,d(2:m))\n err=eps*poly(abx,abs(b(1:m+1)))\n if (abs(b(1)) <= err) return\n g=d(1)/b(1)\n g2=g*g\n h=g2-2.0_dp*f/b(1)\n sq=sqrt((m-1)*(m*h-g2))\n gp=g+sq\n gm=g-sq\n abp=abs(gp)\n abm=abs(gm)\n if (abp < abm) gp=gm\n if (max(abp,abm) > 0.0_dp) then\n dx=m/gp\n else\n dx=exp(cmplx(log(1.0_dp+abx),iter,kind=dpc))\n end if\n x1=x-dx\n if (x == x1) return\n if (mod(iter,mt) /= 0) then\n x=x1\n else\n x=x-dx*frac(iter/mt)\n end if\n end do\n call nrerror('laguer: too many iterations')\nend subroutine laguer_dp\n", "meta": {"hexsha": "605815bc926c5029a89e68ebc85ccacbee679171", "size": 3096, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "nr_jams/laguer.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/laguer.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/laguer.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": 29.7692307692, "max_line_length": 74, "alphanum_fraction": 0.484496124, "num_tokens": 1150, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171067, "lm_q2_score": 0.7606506526772883, "lm_q1q2_score": 0.6748527532692056}} {"text": " MODULE GEOMETRY\t!Limited scope.\n CHARACTER*(*) SQUAWK(-3:2)\t!Holds a schedule of complaints.\n PARAMETER (SQUAWK = (/\t\t!According to what might go wrong.\n 3 \"No circles: points are more than 2R apart.\",\n 2 \"Innumerable circles: co-incident points, R > 0.\",\n 1 \"One 'circle', centred on the co-incident points. R is zero!\",\n o \"No circles! R is negative!\",\n 1 \"One circle: points are 2R apart.\",\n 2 \"Two circles.\"/))\t\t!This last is the hoped-for state.\n CONTAINS\t!Now for the action.\n SUBROUTINE BUBBLE(P,R,N)\t!Finds circles of radius R passing through two points.\n COMPLEX P(2)\t!The two points. Results returned here.\n REAL R\t\t!The specified radius.\n INTEGER N\t!Indicates how many centres are valid.\n COMPLEX MID,DP\t!Geometrical assistants.\n DP = (P(2) - P(1))/2\t!Or, the other way around.\n D = ABS(DP)\t\t!Half the separation is useful.\n IF (R.LT.0) THEN\t!Is the specified radius silly?\n N = 0\t\t\t!Yes. No circles, then.\n ELSE IF (D.EQ.0) THEN\t!Any distance between the points?\n IF (R.EQ.0) THEN\t\t!No. Zero radius?\n N = -1\t\t\t\t!Yes. So a degenerate \"circle\" of zero radius.\n ELSE\t\t\t!A negative radius being tested for above,\n N = -2\t\t\t\t!A swirl of circles around the midpoint.\n END IF\t\t!So much for co-incident points.\n ELSE IF (D.GT.R) THEN\t!Points too far apart?\n N = -3\t\t\t!A circle of radius R can't reach them.\n ELSE IF (D.EQ.R) THEN\t!Maximum separation for R?\n N = 1\t\t\t!Yes. The two circles lie atop each other.\n P(1) = (P(1) + P(2))/2\t!Both centres are on the midpoint, but N = 1.\n ELSE\t\t\t!Finally, the ordinary case.\n N = 2\t\t\t!Two circles.\n MID = (P(1) + P(2))/2\t!Midway between the two points.\n D = SQRT((R/D)**2 - 1)\t!Rescale vector DP.\n P = MID + DP*CMPLX(0,(/+D,-D/))\t!Array (0,+D), (0,-D)\n END IF\t\t\t\t!P(1) = DP*CMPLX(0,+D) and P(2) = DP*CMPLX(0,-D)\n END SUBROUTINE BUBBLE\t!Careful! P and N are modified.\n END MODULE GEOMETRY\t!Not much.\n\n PROGRAM POKE\t!A tester.\n USE GEOMETRY\t!Useful to I. Newton.\n COMPLEX P(2)\t\t!A pair of points.\n REAL PP(4)\t\t!Also a pair.\n EQUIVALENCE (P,PP)\t!Since free-format input likes (x,y), not x,y\n REAL R\t\t\t!This is not complex.\n INTEGER MSG,IN\t\t!I/O unit numbers.\n MSG = 6\t\t\t!Standard output.\n OPEN (MSG, RECL = 120)\t!For \"formatted\" files, this length is in characters.\n IN = 10\t\t\t!For the disc file holding the test data.\n WRITE (MSG,1)\t\t!Announce.\n 1 FORMAT (\"Given two points and a radius, find the centres \"\n 1 \"of circles of that radius passing through those points.\")\n\n OPEN (IN,FILE=\"Circle.csv\", STATUS = \"OLD\", ACTION=\"READ\")\t!Have data, will compute.\n 10 READ (IN,*,END = 20) PP,R\t\t!Get two points and a radius.\n WRITE (MSG,*)\t\t\t!Set off.\n WRITE (MSG,*) P,R\t\t\t!Show the input.\n CALL BUBBLE(P,R,N)\t\t!Calculate.\n WRITE (MSG,*) P(1:N),SQUAWK(N)\t!Show results.\n GO TO 10\t\t\t\t!Try it again.\n\n 20 CLOSE(IN)\t\t!Finihed with input.\n END\t!Finished.\n", "meta": {"hexsha": "6935c17d2ff73795262fd50aaf20117daaf5328d", "size": 3185, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Circles-of-given-radius-through-two-points/Fortran/circles-of-given-radius-through-two-points-2.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-05T13:42:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-05T13:42:20.000Z", "max_issues_repo_path": "Task/Circles-of-given-radius-through-two-points/Fortran/circles-of-given-radius-through-two-points-2.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Circles-of-given-radius-through-two-points/Fortran/circles-of-given-radius-through-two-points-2.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.765625, "max_line_length": 90, "alphanum_fraction": 0.5817896389, "num_tokens": 1026, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523148, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6748527487320828}} {"text": "module funcs\nuse, intrinsic:: iso_fortran_env, only: sp=>real32, dp=>real64\nimplicit none (type, external)\n\ninterface addtwo\nprocedure addtwo_s, addtwo_d, addtwo_i\nend interface addtwo\n\ncontains\n\nelemental real(sp) function addtwo_s(x) result(y)\nreal(sp), intent(in) :: x\n\ny = x + 2\nend function addtwo_s\n\n\nelemental real(dp) function addtwo_d(x) result(y)\nreal(dp), intent(in) :: x\n\ny = x + 2\nend function addtwo_d\n\n\nelemental integer function addtwo_i(x) result(y)\ninteger, intent(in) :: x\n\ny = x + 2\nend function addtwo_i\n\nend module funcs\n\n\nprogram test2\n\nuse funcs\nimplicit none (type, external)\n\nreal(sp) :: twos = 2._sp\nreal(dp) :: twod = 2._dp\ninteger :: twoi = 2\n\n\nprint *, addtwo(twos), addtwo(twod), addtwo(twoi)\n\nend program\n", "meta": {"hexsha": "899872f0b2bf87553d5f82a31c4c659ae9b4e70e", "size": 737, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "real/polymorphic_module.f90", "max_stars_repo_name": "supershushu/fortran2018-examples", "max_stars_repo_head_hexsha": "f0dc03b80326bc7c06fa31945b6e7406a60c1fa8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 305, "max_stars_repo_stars_event_min_datetime": "2017-12-07T12:47:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T12:03:16.000Z", "max_issues_repo_path": "src/real/polymorphic_module.f90", "max_issues_repo_name": "scivision/fortran2015-examples", "max_issues_repo_head_hexsha": "23fc7090997ecb4b838ebc1f09b86e2872d7141c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2018-11-24T15:45:53.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-06T08:10:43.000Z", "max_forks_repo_path": "src/real/polymorphic_module.f90", "max_forks_repo_name": "scivision/fortran2015-examples", "max_forks_repo_head_hexsha": "23fc7090997ecb4b838ebc1f09b86e2872d7141c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 60, "max_forks_repo_forks_event_min_datetime": "2017-11-28T07:56:03.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-20T01:37:53.000Z", "avg_line_length": 15.6808510638, "max_line_length": 62, "alphanum_fraction": 0.7177747626, "num_tokens": 234, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476800298183, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6748500655973906}} {"text": "! test_quasirandom.f90 --\r\n! Simple test of the quasi-random points generator\r\n!\r\n! The algorithm is based on:\r\n! \"The Unreasonable Effectiveness of Quasirandom Sequences\" by Martin Roberts,\r\n! http://extremelearning.com.au/unreasonable-effectiveness-of-quasirandom-sequences/\r\n!\r\n! TODO:\r\n! Support for points on a circle, disk, sphere or ball\r\n! Integration\r\n!\r\n\r\n! test_quasirandom\r\n! Simple test program\r\n!\r\nprogram test_quasirandom\r\n use quasirandom\r\n\r\n implicit none\r\n\r\n integer, parameter :: dp = kind(1.0d0)\r\n\r\n type(quasirandom_generator) :: q, qcircle, qdisk, qsphere, qball\r\n\r\n real, dimension(1) :: coords\r\n real, dimension(2) :: coords2\r\n real, dimension(3) :: coords3\r\n real :: radius2\r\n\r\n real(kind=dp), dimension(1) :: dcoords\r\n real(kind=dp), dimension(2) :: dcoords2\r\n real(kind=dp), dimension(3) :: dcoords3\r\n real(kind=dp) :: dradius2\r\n\r\n integer :: i, points_in, points_off, points_x, points_y, points_z\r\n\r\n write( *, * ) 'SINGLE-PRECISION VERSION'\r\n write( *, * ) '------------------------'\r\n\r\n call q%init( 1 )\r\n\r\n write( *, * ) 'Quasirandom points on the interval [0,1]:'\r\n do i = 1,10\r\n call q%next( coords )\r\n write( *, * ) i, coords\r\n enddo\r\n\r\n call q%init( 3 )\r\n\r\n write( *, * ) 'Quasirandom points on the unit cube [0,1]^3:'\r\n do i = 1,10\r\n call q%next( coords3 )\r\n write( *, * ) i, coords3\r\n enddo\r\n\r\n !\r\n ! Test the special forms:\r\n ! - For circle and sphere:\r\n ! - the length of the vector should be one\r\n ! - the number of points with x > 0.7 should be roughly equal to\r\n ! the number of points with y > 0.7\r\n ! - For disk and ball:\r\n ! - the number of points with distance to the origin less than 0.5\r\n ! should roughly be 1/4 and 1/8 of the total\r\n ! - the number of points with x > 0.7 should be roughly equal to\r\n ! the number of points with y > 0.7 and to the number of points\r\n ! with z > 0.7\r\n !\r\n write( *, * ) 'Quasirandom points on a circle:'\r\n\r\n points_off = 0\r\n points_x = 0\r\n points_y = 0\r\n call qcircle%init( quasi_circle )\r\n do i = 1,1000\r\n call qcircle%next( coords2 )\r\n radius2 = sum( coords2 ** 2 )\r\n if ( abs(radius2 - 1.0) > 1.0e-6 ) then\r\n points_off = points_off + 1\r\n endif\r\n if ( coords2(1) > 0.7 ) then\r\n points_x = points_x + 1\r\n endif\r\n if ( coords2(2) > 0.7 ) then\r\n points_y = points_y + 1\r\n endif\r\n enddo\r\n\r\n write( *, * ) 'Number of points off the circle: ', points_off\r\n write( *, * ) 'Number of points right of x = 0.7:', points_x\r\n write( *, * ) 'Number of points above of y = 0.7:', points_y\r\n\r\n write( *, * ) 'Quasirandom points on a disk:'\r\n points_in = 0\r\n points_x = 0\r\n points_y = 0\r\n call qdisk%init( quasi_disk )\r\n do i = 1,1000\r\n call qdisk%next( coords2 )\r\n radius2 = sum( coords2 ** 2 )\r\n if ( radius2 < 0.25 ) then\r\n points_in = points_in + 1\r\n endif\r\n if ( coords2(1) > 0.7 ) then\r\n points_x = points_x + 1\r\n endif\r\n if ( coords2(2) > 0.7 ) then\r\n points_y = points_y + 1\r\n endif\r\n enddo\r\n\r\n write( *, * ) 'Number of points inner part of disk: ', points_in, ' - expected: ', 1000/4\r\n write( *, * ) 'Number of points right of x = 0.7:', points_x\r\n write( *, * ) 'Number of points above of y = 0.7:', points_y\r\n\r\n !\r\n ! Sphere and ball\r\n !\r\n write( *, * ) 'Quasirandom points on a sphere:'\r\n\r\n points_off = 0\r\n points_x = 0\r\n points_y = 0\r\n points_z = 0\r\n call qsphere%init( quasi_sphere )\r\n do i = 1,1000\r\n call qsphere%next( coords3 )\r\n radius2 = sum( coords3 ** 2 )\r\n if ( abs(radius2 - 1.0) > 1.0e-6 ) then\r\n points_off = points_off + 1\r\n endif\r\n if ( coords3(1) > 0.7 ) then\r\n points_x = points_x + 1\r\n endif\r\n if ( coords3(2) > 0.7 ) then\r\n points_y = points_y + 1\r\n endif\r\n if ( coords3(3) > 0.7 ) then\r\n points_z = points_z + 1\r\n endif\r\n enddo\r\n\r\n write( *, * ) 'Number of points off the sphere: ', points_off\r\n write( *, * ) 'Number of points right of x = 0.7:', points_x\r\n write( *, * ) 'Number of points above of y = 0.7:', points_y\r\n write( *, * ) 'Number of points above of z = 0.7:', points_z\r\n\r\n write( *, * ) 'Quasirandom points on a ball:'\r\n points_in = 0\r\n points_x = 0\r\n points_y = 0\r\n points_z = 0\r\n call qball%init( quasi_ball )\r\n do i = 1,1000\r\n call qball%next( coords3 )\r\n radius2 = sum( coords3 ** 2 )\r\n if ( radius2 < 0.25 ) then\r\n points_in = points_in + 1\r\n endif\r\n if ( coords3(1) > 0.7 ) then\r\n points_x = points_x + 1\r\n endif\r\n if ( coords3(2) > 0.7 ) then\r\n points_y = points_y + 1\r\n endif\r\n if ( coords3(3) > 0.7 ) then\r\n points_z = points_z + 1\r\n endif\r\n enddo\r\n\r\n write( *, * ) 'Number of points inner part of ball: ', points_in, ' - expected: ', 1000/8\r\n write( *, * ) 'Number of points right of x = 0.7:', points_x\r\n write( *, * ) 'Number of points above of y = 0.7:', points_y\r\n write( *, * ) 'Number of points above of z = 0.7:', points_z\r\n\r\n !\r\n ! \"Just\" a copy of the previous code\r\n !\r\n write( *, * ) ''\r\n write( *, * ) 'DOUBLE-PRECISION VERSION'\r\n write( *, * ) '------------------------'\r\n\r\n call q%init( 1 )\r\n\r\n write( *, * ) 'Quasirandom points on the interval [0,1]:'\r\n do i = 1,10\r\n call q%next( dcoords )\r\n write( *, * ) i, dcoords\r\n enddo\r\n\r\n call q%init( 3 )\r\n\r\n write( *, * ) 'Quasirandom points on the unit cube [0,1]^3:'\r\n do i = 1,10\r\n call q%next( dcoords3 )\r\n write( *, * ) i, dcoords3\r\n enddo\r\n\r\n !\r\n ! Test the special forms:\r\n ! - For circle and sphere:\r\n ! - the length of the vector should be one\r\n ! - the number of points with x > 0.7 should be roughly equal to\r\n ! the number of points with y > 0.7\r\n ! - For disk and ball:\r\n ! - the number of points with distance to the origin less than 0.5\r\n ! should roughly be 1/4 and 1/8 of the total\r\n ! - the number of points with x > 0.7 should be roughly equal to\r\n ! the number of points with y > 0.7 and to the number of points\r\n ! with z > 0.7\r\n !\r\n write( *, * ) 'Quasirandom points on a circle:'\r\n\r\n points_off = 0\r\n points_x = 0\r\n points_y = 0\r\n call qcircle%init( quasi_circle )\r\n do i = 1,1000\r\n call qcircle%next( dcoords2 )\r\n dradius2 = sum( dcoords2 ** 2 )\r\n if ( abs(dradius2 - 1.0_dp) > 1.0e-12_dp ) then\r\n points_off = points_off + 1\r\n endif\r\n if ( dcoords2(1) > 0.7_dp ) then\r\n points_x = points_x + 1\r\n endif\r\n if ( dcoords2(2) > 0.7_dp ) then\r\n points_y = points_y + 1\r\n endif\r\n enddo\r\n\r\n write( *, * ) 'Number of points off the circle: ', points_off\r\n write( *, * ) 'Number of points right of x = 0.7:', points_x\r\n write( *, * ) 'Number of points above of y = 0.7:', points_y\r\n\r\n write( *, * ) 'Quasirandom points on a disk:'\r\n points_in = 0\r\n points_x = 0\r\n points_y = 0\r\n call qdisk%init( quasi_disk )\r\n do i = 1,1000\r\n call qdisk%next( dcoords2 )\r\n dradius2 = sum( dcoords2 ** 2 )\r\n if ( dradius2 < 0.25_dp ) then\r\n points_in = points_in + 1\r\n endif\r\n if ( dcoords2(1) > 0.7_dp ) then\r\n points_x = points_x + 1\r\n endif\r\n if ( dcoords2(2) > 0.7_dp ) then\r\n points_y = points_y + 1\r\n endif\r\n enddo\r\n\r\n write( *, * ) 'Number of points inner part of disk: ', points_in, ' - expected: ', 1000/4\r\n write( *, * ) 'Number of points right of x = 0.7:', points_x\r\n write( *, * ) 'Number of points above of y = 0.7:', points_y\r\n\r\n !\r\n ! Sphere and ball\r\n !\r\n write( *, * ) 'Quasirandom points on a sphere:'\r\n\r\n points_off = 0\r\n points_x = 0\r\n points_y = 0\r\n points_z = 0\r\n call qsphere%init( quasi_sphere )\r\n do i = 1,1000\r\n call qsphere%next( dcoords3 )\r\n dradius2 = sum( dcoords3 ** 2 )\r\n if ( abs(dradius2 - 1.0_dp) > 1.0e-12_dp ) then\r\n points_off = points_off + 1\r\n endif\r\n if ( dcoords3(1) > 0.7_dp ) then\r\n points_x = points_x + 1\r\n endif\r\n if ( dcoords3(2) > 0.7_dp ) then\r\n points_y = points_y + 1\r\n endif\r\n if ( dcoords3(3) > 0.7_dp ) then\r\n points_z = points_z + 1\r\n endif\r\n enddo\r\n\r\n write( *, * ) 'Number of points off the sphere: ', points_off\r\n write( *, * ) 'Number of points right of x = 0.7:', points_x\r\n write( *, * ) 'Number of points above of y = 0.7:', points_y\r\n write( *, * ) 'Number of points above of z = 0.7:', points_z\r\n\r\n write( *, * ) 'Quasirandom points on a ball:'\r\n points_in = 0\r\n points_x = 0\r\n points_y = 0\r\n points_z = 0\r\n call qball%init( quasi_ball )\r\n do i = 1,1000\r\n call qball%next( dcoords3 )\r\n dradius2 = sum( dcoords3 ** 2 )\r\n if ( dradius2 < 0.25_dp ) then\r\n points_in = points_in + 1\r\n endif\r\n if ( dcoords3(1) > 0.7_dp ) then\r\n points_x = points_x + 1\r\n endif\r\n if ( dcoords3(2) > 0.7_dp ) then\r\n points_y = points_y + 1\r\n endif\r\n if ( dcoords3(3) > 0.7_dp ) then\r\n points_z = points_z + 1\r\n endif\r\n enddo\r\n\r\n write( *, * ) 'Number of points inner part of ball: ', points_in, ' - expected: ', 1000/8\r\n write( *, * ) 'Number of points right of x = 0.7:', points_x\r\n write( *, * ) 'Number of points above of y = 0.7:', points_y\r\n write( *, * ) 'Number of points above of z = 0.7:', points_z\r\nend program test_quasirandom\r\n", "meta": {"hexsha": "a97512fd69136241b92582e9d23d72173d8bf128", "size": 10139, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/computing/test_quasirandom.f90", "max_stars_repo_name": "timcera/flibs_from_svn", "max_stars_repo_head_hexsha": "7790369ac1f0ff6e35ef43546446b32446dccc6b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tests/computing/test_quasirandom.f90", "max_issues_repo_name": "timcera/flibs_from_svn", "max_issues_repo_head_hexsha": "7790369ac1f0ff6e35ef43546446b32446dccc6b", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/computing/test_quasirandom.f90", "max_forks_repo_name": "timcera/flibs_from_svn", "max_forks_repo_head_hexsha": "7790369ac1f0ff6e35ef43546446b32446dccc6b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.7836990596, "max_line_length": 95, "alphanum_fraction": 0.5182956899, "num_tokens": 3244, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476793890012, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.6748500653132741}} {"text": "C******************** START FILE FLIN1_Z.FOR ; GROUP SIGS2 ********************\nC==============================================================================\nC\nC FLIN1_Z\nC INTERPOLATE ON A 1D ARRAY\nC\n SUBROUTINE FLIN1_Z(X,F,N,VTR,XMIN,XMAX,XLR,NX,IWARN)\nc\nc Interpolates the table VTR(NX) to find the value at x.\nc If XLR>0, then the X grid is equally spaced on a logarithmic scale:\nc\nc X(i) = XMIN * (exp(XLR)) ** ( (i-1)/(NX-1) )\nc\nc So X(i) ranges from XMIN to XMIN*exp(XLR), and XLR=log(xmax/xmin).\nc\nc For XLR<=0, the X grid is equally spaced on a linear scale from\nc XMIN to XMAX.\nC\nC Modified 7/26/00 (PCR) - vectorized.\nC\nC============\nC idecl: explicitize implicit INTEGER declarations:\n IMPLICIT NONE\n INTEGER n,nx,it,iwarn,ix,ixp1\nC============\nC idecl: explicitize implicit REAL declarations:\n REAL*8 f,vtr,x,xmin,xmax,xlr,zx,zy,zzx,zlogx\nC============\n DIMENSION VTR(NX)\n DIMENSION X(N)\n DIMENSION F(N)\nC\nC INTERPOLATE TO X LOGARITHMIC SPACING IN X\nC LINEAR IF XLR .LE. 0.0\nC\n integer idebug\n common/flint_debug/ idebug\nC\n iwarn=0\nC\n do 70 it=1,n\nC\n ZX=X(it)\nC\n if(zx .lt. xmin) then\n zzx=0.0D0\n else\n \n IF(XLR.GT.0.0D0) THEN\n ZLOGX=log(ZX/XMIN)\n ZZX=1.0D0+ZLOGX/XLR * (NX-1)\n ELSE\n ZZX=1.0D0+(ZX-XMIN)/(XMAX-XMIN) * (NX-1)\n ENDIF\n \n endif\nC\n IX=ZZX\nC\nC CHECK FOR POINT OUT OF BOUNDS OF ARRAY\n IF(IX.GE.1) GO TO 10\nC\n IF(ZX.LT.(XMIN - 5.0D-7)) THEN\n IWARN=1\n ENDIF\n IX=1\n ZZX=1.0D0\nC\n 10 CONTINUE\nC\n IF(IX.LT.NX) GO TO 30\nC\n IF(ZX.GT.(XMAX + 5.0D-7)) THEN\n IWARN=1\n ENDIF\n IX=NX-1\n ZZX=NX\nC\nC---------------------------\nC OK\nC\n 30 CONTINUE\nC\n IXP1=IX+1\n ZZX=ZZX-IX\nC\nC INTERPOLATE\nC\n F(it)=(1.0D0-ZZX)*VTR(IX)+ZZX*VTR(IXP1)\nc\n if(idebug.eq.99) then\n write(6,*) 'flin1_z: zx=',zx,' ix=',ix\n write(6,*) ' vtr(ix:ixp1) = ',vtr(ix:ixp1)\n write(6,*) ' it,F(it)=',it,F(it)\n endif\nC\n 70 continue\nC\n idebug=0 ! clear debug flag\nC\n END\nC\nC******************** END FILE FLIN1.FOR ; GROUP SIGS2 ************************\n! 26Jul2000 fgtok -s r8_precision.sub \"r8con.csh conversion\"\n", "meta": {"hexsha": "a27ea13ed769872e766238761cf28dd4edd418bf", "size": 2385, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "LIBSTELL/Sources/Modules/flin1_z.f", "max_stars_repo_name": "joseluisvelasco/STELLOPT", "max_stars_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2020-05-08T01:47:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T10:35:28.000Z", "max_issues_repo_path": "LIBSTELL/Sources/Modules/flin1_z.f", "max_issues_repo_name": "joseluisvelasco/STELLOPT", "max_issues_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 77, "max_issues_repo_issues_event_min_datetime": "2020-05-08T07:18:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:20:33.000Z", "max_forks_repo_path": "LIBSTELL/Sources/Modules/flin1_z.f", "max_forks_repo_name": "joseluisvelasco/STELLOPT", "max_forks_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-02-10T13:47:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T12:53:43.000Z", "avg_line_length": 22.7142857143, "max_line_length": 79, "alphanum_fraction": 0.5023060797, "num_tokens": 860, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476793890012, "lm_q2_score": 0.7690802317779601, "lm_q1q2_score": 0.6748500560247118}} {"text": " SUBROUTINE SROTMG( D1, D2, X1, Y1, PARAM )\n*\n* -- Automatically Tuned Linear Algebra Software (ATLAS)\n* (C) Copyright 2000 All Rights Reserved\n*\n* -- ATLAS routine -- F77 Interface -- Version 3.9.24 -- December 25, 2000\n*\n* Author : Antoine P. Petitet\n* Originally developed at the University of Tennessee,\n* Innovative Computing Laboratory, Knoxville TN, 37996-1301, USA.\n*\n* ---------------------------------------------------------------------\n*\n* -- Copyright notice and Licensing terms:\n*\n* Redistribution and use in source and binary forms, with or without\n* modification, are permitted provided that the following conditions\n* are met:\n*\n* 1. Redistributions of source code must retain the above copyright\n* notice, this list of conditions and the following disclaimer.\n* 2. Redistributions in binary form must reproduce the above copyright\n* notice, this list of conditions, and the following disclaimer in\n* the documentation and/or other materials provided with the distri-\n* bution.\n* 3. The name of the University, the ATLAS group, or the names of its\n* contributors may not be used to endorse or promote products deri-\n* ved from this software without specific written permission.\n*\n* -- Disclaimer:\n*\n* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY\n* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE-\n* CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED\n* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\n* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEO-\n* RY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (IN-\n* CLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n*\n* ---------------------------------------------------------------------\n*\n* .. Scalar Arguments ..\n REAL D1, D2, X1, Y1\n* ..\n* .. Array Arguments ..\n REAL PARAM( * )\n* ..\n*\n* Purpose\n* =======\n*\n* SROTMG constructs the modified-Givens plane rotation. The input sca-\n* lars d1, d2, x1 and y1 define a 2-vector [a1 a2]' such that\n*\n* [ a1 ] [ d1^{1/2} 0 ] [ x1 ]\n* [ a2 ] = [ 0 d2^{1/2} ] [ y1 ].\n*\n* This subroutine determines the modified Givens rotation matrix H that\n* transforms y1 and thus a2 to zero. A representation of this matrix is\n* stored in the output array PARAM.\n*\n* Arguments\n* =========\n*\n* D1 (input/output) REAL\n* On entry, D1 specifies the scalar d1.\n*\n* D2 (input/output) REAL\n* On entry, D2 specifies the scalar d2.\n*\n* X1 (input/output) REAL\n* On entry, X1 specifies the scalar x1.\n*\n* Y1 (input) REAL\n* On entry, Y1 specifies the scalar y1. Unchanged on exit.\n*\n* PARAM (output) REAL array\n* On entry, PARAM is an array of dimension at least 5. On exit,\n* the entries of this array have the following meaning:\n*\n* if PARAM( 1 ) = 1,\n* h_12 = 1, h_21 = -1, PARAM( 2 ) = h_11, PARAM( 5 ) = h_22,\n* and the other entries of PARAM are left unchanged;\n* else if PARAM( 1 ) = 0,\n* h_11 = 1, h_22 = 1, PARAM( 3 ) = h_21, PARAM( 4 ) = h_12,\n* and the other entries of PARAM are left unchanged;\n* else if PARAM( 1 ) = -1, (case of re-scaling)\n* PARAM( 2 ) = h_11, PARAM( 3 ) = h_21,\n* PARAM( 4 ) = h_12, PARAM( 5 ) = h_22;\n* else if PARAM( 1 ) = -2,\n* H = I, and the other entries of PARAM are left unchanged;\n* end if\n*\n* Further Details\n* ===============\n*\n* For further information on the Level 1 BLAS specification, see:\n*\n* ``A Proposal for Standard Linear Algebra Subprograms'' by R. Hanson,\n* F. Krogh and C. Lawson, ACM SIGNUM Newsl., 8(16), 1973,\n*\n* ``Basic Linear Algebra Subprograms for Fortran Usage'' by C. Lawson,\n* R. Hanson, D. Kincaid and F. Krogh, ACM Transactions on Mathematical\n* Software, 5(3) pp 308-323, 1979.\n*\n* For further information on the Level 2 BLAS specification, see:\n*\n* ``An Extended Set of FORTRAN Basic Linear Algebra Subprograms'' by\n* J. Dongarra, J. Du Croz, S. Hammarling and R. Hanson, ACM Transac-\n* tions on Mathematical Software, 14(1) pp 1-17, 1988.\n*\n* ``Algorithm 656: An extended Set of Basic Linear Algebra Subprograms:\n* Model Implementation and Test Programs'' by J. Dongarra, J. Du Croz,\n* S. Hammarling and R. Hanson, ACM Transactions on Mathematical Soft-\n* ware, 14(1) pp 18-32, 1988.\n*\n* For further information on the Level 3 BLAS specification, see:\n*\n* ``A Set of Level 3 Basic Linear Algebra Subprograms'' by J. Dongarra,\n* J. Du Croz, I. Duff and S. Hammarling, ACM Transactions on Mathemati-\n* cal Software, 16(1), pp 1-17, 1990.\n*\n* =====================================================================\n*\n* .. External Subroutines ..\n EXTERNAL ATL_F77WRAP_SROTMG\n* ..\n* .. Executable Statements ..\n*\n CALL ATL_F77WRAP_SROTMG( D1, D2, X1, Y1, PARAM )\n*\n RETURN\n*\n* End of SROTMG\n*\n END\n", "meta": {"hexsha": "cbb55ca164ab0e119c5ca7a96aa6cf6c625f175a", "size": 5519, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "interfaces/blas/F77/src/srotmg.f", "max_stars_repo_name": "kevleyski/math-atlas", "max_stars_repo_head_hexsha": "cc36aa7e0362c577739ac507378068882834825e", "max_stars_repo_licenses": ["BSD-3-Clause-Clear"], "max_stars_count": 19, "max_stars_repo_stars_event_min_datetime": "2015-03-19T10:53:38.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-17T06:12:32.000Z", "max_issues_repo_path": "interfaces/blas/F77/src/srotmg.f", "max_issues_repo_name": "kevleyski/math-atlas", "max_issues_repo_head_hexsha": "cc36aa7e0362c577739ac507378068882834825e", "max_issues_repo_licenses": ["BSD-3-Clause-Clear"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-12-18T17:43:44.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-18T17:43:44.000Z", "max_forks_repo_path": "interfaces/blas/F77/src/srotmg.f", "max_forks_repo_name": "kevleyski/math-atlas", "max_forks_repo_head_hexsha": "cc36aa7e0362c577739ac507378068882834825e", "max_forks_repo_licenses": ["BSD-3-Clause-Clear"], "max_forks_count": 47, "max_forks_repo_forks_event_min_datetime": "2015-01-27T06:22:57.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-11T20:59:04.000Z", "avg_line_length": 39.1418439716, "max_line_length": 75, "alphanum_fraction": 0.6069940207, "num_tokens": 1555, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767810736692, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.674850050812197}} {"text": " SUBROUTINE cdfgam(which,p,q,x,shape,scale,status,bound)\nC**********************************************************************\nC\nC SUBROUTINE CDFGAM( WHICH, P, Q, X, SHAPE, SCALE, STATUS, BOUND )\nC Cumulative Distribution Function\nC GAMma Distribution\nC\nC\nC Function\nC\nC\nC Calculates any one parameter of the gamma\nC distribution given values for the others.\nC\nC\nC Arguments\nC\nC\nC WHICH --> Integer indicating which of the next four argument\nC values is to be calculated from the others.\nC Legal range: 1..4\nC iwhich = 1 : Calculate P and Q from X,SHAPE and SCALE\nC iwhich = 2 : Calculate X from P,Q,SHAPE and SCALE\nC iwhich = 3 : Calculate SHAPE from P,Q,X and SCALE\nC iwhich = 4 : Calculate SCALE from P,Q,X and SHAPE\nC INTEGER WHICH\nC\nC P <--> The integral from 0 to X of the gamma density.\nC Input range: [0,1].\nC DOUBLE PRECISION P\nC\nC Q <--> 1-P.\nC Input range: (0, 1].\nC P + Q = 1.0.\nC DOUBLE PRECISION Q\nC\nC\nC X <--> The upper limit of integration of the gamma density.\nC Input range: [0, +infinity).\nC Search range: [0,1E300]\nC DOUBLE PRECISION X\nC\nC SHAPE <--> The shape parameter of the gamma density.\nC Input range: (0, +infinity).\nC Search range: [1E-300,1E300]\nC DOUBLE PRECISION SHAPE\nC\nC\nC SCALE <--> The scale parameter of the gamma density.\nC Input range: (0, +infinity).\nC Search range: (1E-300,1E300]\nC DOUBLE PRECISION SCALE\nC\nC STATUS <-- 0 if calculation completed correctly\nC -I if input parameter number I is out of range\nC 1 if answer appears to be lower than lowest\nC search bound\nC 2 if answer appears to be higher than greatest\nC search bound\nC 3 if P + Q .ne. 1\nC 10 if the gamma or inverse gamma routine cannot\nC compute the answer. Usually happens only for\nC X and SHAPE very large (gt 1E10 or more)\nC INTEGER STATUS\nC\nC BOUND <-- Undefined if STATUS is 0\nC\nC Bound exceeded by parameter number I if STATUS\nC is negative.\nC\nC Lower search bound if STATUS is 1.\nC\nC Upper search bound if STATUS is 2.\nC\nC\nC Method\nC\nC\nC Cumulative distribution function (P) is calculated directly by\nC the code associated with:\nC\nC DiDinato, A. R. and Morris, A. H. Computation of the incomplete\nC gamma function ratios and their inverse. ACM Trans. Math.\nC Softw. 12 (1986), 377-393.\nC\nC Computation of other parameters involve a seach for a value that\nC produces the desired value of P. The search relies on the\nC monotinicity of P with the other parameter.\nC\nC\nC Note\nC\nC\nC\nC The gamma density is proportional to\nC T**(SHAPE - 1) * EXP(- SCALE * T)\nC\nC History\nC\nC Routine modified by Scilab group 1998, because of an undefined\nC variable. See below comments \"CSS\".\n\nC**********************************************************************\nC .. Parameters ..\n DOUBLE PRECISION tol\n PARAMETER (tol=1.0D-13)\n DOUBLE PRECISION atol\n PARAMETER (atol=1.0D-50)\n DOUBLE PRECISION zero,inf\n PARAMETER (zero=1.0D-300,inf=1.0D300)\nC ..\nC .. Scalar Arguments ..\n DOUBLE PRECISION bound,p,q,scale,shape,x\n INTEGER status,which\nC ..\nC .. Local Scalars ..\n DOUBLE PRECISION xx\n DOUBLE PRECISION fx,xscale,cum,ccum,pq,porq\n INTEGER ierr\n LOGICAL qhi,qleft,qporq\nC ..\nC .. External Functions ..\n DOUBLE PRECISION spmpar\n EXTERNAL spmpar\nC ..\nC .. External Subroutines ..\n EXTERNAL gaminv,dinvr,dstinv,cumgam\nC ..\nC .. Executable Statements ..\nC\nC Check arguments\nC\n IF (.NOT. ((which.LT.1).OR. (which.GT.4))) GO TO 30\n IF (.NOT. (which.LT.1)) GO TO 10\n bound = 1.0D0\n GO TO 20\n\n 10 bound = 4.0D0\n 20 status = -1\n RETURN\n\n 30 IF (which.EQ.1) GO TO 70\nC\nC P\nC\n IF (.NOT. ((p.LT.0.0D0).OR. (p.GT.1.0D0))) GO TO 60\n IF (.NOT. (p.LT.0.0D0)) GO TO 40\n bound = 0.0D0\n GO TO 50\n\n 40 bound = 1.0d0\n 50 status = -2\n RETURN\n\n 60 CONTINUE\n 70 IF (which.EQ.1) GO TO 110\nC\nC Q\nC\n IF (.NOT. ((q.LE.0.0D0).OR. (q.GT.1.0D0))) GO TO 100\n IF (.NOT. (q.LE.0.0D0)) GO TO 80\n bound = 0.0D0\n GO TO 90\n\n 80 bound = 1.0D0\n 90 status = -3\n RETURN\n\n 100 CONTINUE\n 110 IF (which.EQ.2) GO TO 130\nC\nC X\nC\n IF (.NOT. (x.LT.0.0D0)) GO TO 120\n bound = 0.0D0\n status = -4\n RETURN\n\n 120 CONTINUE\n 130 IF (which.EQ.3) GO TO 150\nC\nC SHAPE\nC\n IF (.NOT. (shape.LE.0.0D0)) GO TO 140\n bound = 0.0D0\n status = -5\n RETURN\n\n 140 CONTINUE\n 150 IF (which.EQ.4) GO TO 170\nC\nC SCALE\nC\n IF (.NOT. (scale.LE.0.0D0)) GO TO 160\n bound = 0.0D0\n status = -6\n RETURN\n\n 160 CONTINUE\n 170 IF (which.EQ.1) GO TO 210\nC\nC P + Q\nC\n pq = p + q\n IF (.NOT. (abs(((pq)-0.5D0)-0.5D0).GT.\n + (3.0D0*spmpar(1)))) GO TO 200\n IF (.NOT. (pq.LT.0.0D0)) GO TO 180\n bound = 0.0D0\n GO TO 190\n\n 180 bound = 1.0D0\n 190 status = 3\n RETURN\n\n 200 CONTINUE\n 210 IF (which.EQ.1) GO TO 240\nC\nC Select the minimum of P or Q\nC\n qporq = p .LE. q\n IF (.NOT. (qporq)) GO TO 220\n porq = p\n GO TO 230\n\n 220 porq = q\n 230 CONTINUE\nC\nC Calculate ANSWERS\nC\n 240 IF ((1).EQ. (which)) THEN\nC\nC Calculating P\nC\n status = 0\n xscale = x*scale\n CALL cumgam(xscale,shape,p,q)\nCSS Next line changed by Scilab group. porq undefined here\nCSS IF (porq.GT.1.5D0) status = 10\n IF (p.GT.1.5D0) status = 10\n\n ELSE IF ((2).EQ. (which)) THEN\nC\nC Computing X\nC\n CALL gaminv(shape,xx,-1.0D0,p,q,ierr)\n IF (ierr.LT.0.0D0) THEN\n status = 10\n RETURN\n\n ELSE\n x = xx/scale\n status = 0\n END IF\n\n ELSE IF ((3).EQ. (which)) THEN\nC\nC Computing SHAPE\nC\n shape = 5.0D0\n xscale = x*scale\n CALL dstinv(zero,inf,0.5D0,0.5D0,5.0D0,atol,tol)\n status = 0\n CALL dinvr(status,shape,fx,qleft,qhi)\n 250 IF (.NOT. (status.EQ.1)) GO TO 290\n CALL cumgam(xscale,shape,cum,ccum)\n IF (.NOT. (qporq)) GO TO 260\n fx = cum - p\n GO TO 270\n\n 260 fx = ccum - q\n 270 IF (.NOT. ((qporq.AND. (cum.GT.1.5D0)).OR.\n + ((.NOT.qporq).AND. (ccum.GT.1.5D0)))) GO TO 280\n status = 10\n RETURN\n\n 280 CALL dinvr(status,shape,fx,qleft,qhi)\n GO TO 250\n\n 290 IF (.NOT. (status.EQ.-1)) GO TO 320\n IF (.NOT. (qleft)) GO TO 300\n status = 1\n bound = zero\n GO TO 310\n\n 300 status = 2\n bound = inf\n 310 CONTINUE\n 320 CONTINUE\n\n ELSE IF ((4).EQ. (which)) THEN\nC\nC Computing SCALE\nC\n CALL gaminv(shape,xx,-1.0D0,p,q,ierr)\n IF (ierr.LT.0.0D0) THEN\n status = 10\n RETURN\n\n ELSE\n scale = xx/x\n status = 0\n END IF\n\n END IF\n\n RETURN\n\n END\n", "meta": {"hexsha": "d690bfad2457aac979abc5af4313349ff7020389", "size": 7643, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/rnd/cdfgam.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/cdfgam.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/cdfgam.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.7346278317, "max_line_length": 71, "alphanum_fraction": 0.5203454141, "num_tokens": 2462, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8774767778695836, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.674850048347998}} {"text": "! ============================ Module Description ===========================\n! etdrk4_mod Implementation of ETDRK4 by Cox & Mathews. Contains subroutines:\n! 1. etdrk4 - ETDRK4 timestepping code\n! 2. initETDC - initializes ETD coefficients\n! ===========================================================================\n\nmodule etdrk4_mod\n\n use tools_mod, only: dp, tic, toc\n use phi_mod, only: phi\n implicit none\n\n contains\n\n ! =======================================================================\n ! ETDRK4 Implements ETDRK4 Numerical Time Integrator\n !\n ! Arguments\n !\n ! L (input) COMPLEX*16 array, dimension(N)\n ! vector cooresponding to PDE linear operator\n !\n ! N (input) SUBROUTINE:\n ! cooresponds to PDE nonlinear operator. Must be of the form:\n ! subroutine N(t,y_in,N_out)\n ! real(dp), intent(in) :: t\n ! complex(dp), intent(in) :: y_in(:)\n ! complex(dp), intent(out) :: N_out(:)\n ! end subroutine N\n !\n ! y_in (input) COMPLEX*16 array, dimension (N)\n ! Initial condition.\n !\n ! y_out (output) COMPLEX*16 array, dimension (N)\n ! Initial condition.\n !\n ! times (output) DOUBLE array, dimension(4)\n ! times(1:2) = [cputime,clocktime] for timestepping loop\n ! times(3:4) = [cputime,clocktime] for initializing coefficients,\n ! =======================================================================\n\n subroutine etdrk4(L,N,tspan,y_in,Nt,y_out,times)\n\n ! Arguments\n complex(dp), intent(in) :: L(:)\n real(dp), intent(in) :: tspan(2)\n complex(dp), intent(in) :: y_in(:)\n integer, intent(in) :: Nt\n complex(dp), intent(out) :: y_out(size(y_in))\n real(dp), intent(out) :: times(4)\n ! define interface subroutine function N\n interface\n subroutine N(t,yh_in, N_out, thread_id)\n import :: dp\n complex(dp), intent(in) :: t\n complex(dp), intent(in) :: yh_in(:)\n complex(dp), intent(out) :: N_out(:)\n integer, intent(in), optional :: thread_id\n end subroutine N\n end interface\n\n ! Local Variables\n integer :: i,nL\n real(dp) :: h\n complex(dp) :: t\n complex(dp), allocatable :: y(:)\n complex(dp), allocatable, dimension(:) :: E, E2, A123, b1, b23, b4, Nv, Na, Nb, Nc, a, b, c\n\n ! Initialize Variables\n nL = size(L)\n allocate(E(nL), E2(nL), A123(nL), b1(nL), b23(nL), b4(nL), Nv(nL), Na(nL), Nb(nL), Nc(nL), a(nL), b(nL), c(nL))\n y = y_in\n ! Set stepsize\n h = (tspan(2)-tspan(1))/(real(Nt,8))\n t = tspan(1)\n ! initialize ETD coefficients\n call tic()\n call initETDC(L,h,E, E2, A123, b1, b23, b4)\n call toc(times(3:4))\n ! timestepping loop\n call tic\n do i=1,Nt\n call N(t,y,Nv);\n a = E2*y + 0.5_dp*A123*Nv;\n call N(t+h/2.0_dp, a, Na);\n b = E2*y + 0.5_dp*A123*Na;\n call N(t+h/2.0_dp, b, Nb);\n c = E2*a + A123*(Nb - 0.5*Nv);\n call N(t+h, c, Nc);\n y = E*y + b1*Nv + b23*(Na + Nb) + b4*Nc;\n t = t + h;\n enddo\n call toc(times(1:2))\n y_out = y\n\n end subroutine etdrk4\n\n ! =======================================================================\n ! INITETDC Initializes ETD coefficients for ETDRK4 scheme.\n !\n ! Arguments\n !\n ! L (input) COMPLEX*16 array, dimension(N)\n ! vector/scaler cooresponding to PDE linear operator\n !\n ! h (input) DOUBLE \n ! timestep\n !\n ! E, E2, A, b1, b23, b4 (output) COMPLEX*16 array, dimension(N,N)\n ! coefficients for ETDRK4\n ! =======================================================================\n\n subroutine initETDC(L,h,E, E2, A, b1, b23, b4)\n\n ! Arguments\n complex(dp), intent(in) :: L(:)\n real(dp), intent(in) :: h\n complex(dp), dimension(:), intent(out) :: E, E2, A, b1, b23, b4\n\n ! Local Variables\n complex(dp), allocatable :: P(:,:)\n allocate(P(4,size(L)))\n\n ! Initialize Coefficients\n call phi(h/2.0_dp * L,1,P(1:2,:))\n E2 = p(1,:)\n A = h*p(2,:)\n call phi(h * L,3,P)\n E = P(1,:)\n b1 = h*(4.0_dp*P(4,:) - 3.0_dp*P(3,:) + P(2,:))\n b23 = h*(-4.0_dp*P(4,:) + 2.0_dp*P(3,:))\n b4 = h*(4.0_dp*P(4,:) - P(3,:))\n deallocate(P)\n\n end subroutine initETDC\n\nend module etdrk4_mod", "meta": {"hexsha": "be3395d5c884de1bc987c5765970f25c202ac5fa", "size": 4780, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "partitioned/fortran/etdrk4_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/etdrk4_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/etdrk4_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": 34.8905109489, "max_line_length": 119, "alphanum_fraction": 0.4491631799, "num_tokens": 1392, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767778695836, "lm_q2_score": 0.7690802317779601, "lm_q1q2_score": 0.6748500437037169}} {"text": "C$Procedure IDENT (Return the 3x3 identity matrix)\n \n SUBROUTINE IDENT ( MATRIX )\n \nC$ Abstract\nC\nC This routine returns the 3x3 identity matrix.\nC\nC$ Disclaimer\nC\nC THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE\nC CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.\nC GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE\nC ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE\nC PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED \"AS-IS\"\nC TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY\nC WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A\nC PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC\nC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE\nC SOFTWARE AND RELATED MATERIALS, HOWEVER USED.\nC\nC IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA\nC BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT\nC LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,\nC INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,\nC REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE\nC REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.\nC\nC RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF\nC THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY\nC CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE\nC ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.\nC\nC$ Required_Reading\nC\nC None.\nC\nC$ Keywords\nC\nC MATRIX\nC\nC$ Declarations\n \n IMPLICIT NONE\n DOUBLE PRECISION MATRIX ( 3, 3 )\n \n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC MATRIX O is the 3x3 identity matrix\nC\nC$ Detailed_Input\nC\nC None.\nC\nC$ Detailed_Output\nC\nC MATRIX is the 3x3 Identity matrix. That is MATRIX is\nC the following\nC _ _\nC | 1.0D0 0.0D0 0.0D0 |\nC | 0.0D0 1.0D0 0.0D0 |\nC | 0.0D0 0.0D0 1.0D0 |\nC - -\nC$ Parameters\nC\nC None.\nC\nC$ Files\nC\nC None.\nC\nC$ Exceptions\nC\nC Error free.\nC\nC$ Particulars\nC\nC This is a utility routine for obtaining the 3x3 identity matrix\nC so that you may avoid having to write the loop or assignments\nC needed to get the matrix.\nC\nC$ Examples\nC\nC Suppose that you need to construct the matrix sum\nC\nC I + OMEGA\nC\nC where OMEGA is some matrix you have already computed.\nC\nC The code fragment below shows how you could accomplish this\nC with this routine.\nC\nC First get the Identity matrix\nC\nC DOUBLE PRECISION I ( 3, 3 )\nC\nC CALL IDENT( I )\nC CALL VSUMG( I, OMEGA, 9, SUM )\nC\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC W.L. Taber (JPL)\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.0, 5-FEB-1996 (WLT)\nC\nC\nC-&\n \nC$ Index_Entries\nC\nC Get the 3x3 identity matrix\nC\nC-&\n \n MATRIX ( 1, 1 ) = 1.0D0\n MATRIX ( 2, 1 ) = 0.0D0\n MATRIX ( 3, 1 ) = 0.0D0\n \n MATRIX ( 1, 2 ) = 0.0D0\n MATRIX ( 2, 2 ) = 1.0D0\n MATRIX ( 3, 2 ) = 0.0D0\n \n MATRIX ( 1, 3 ) = 0.0D0\n MATRIX ( 2, 3 ) = 0.0D0\n MATRIX ( 3, 3 ) = 1.0D0\n \n RETURN\n END\n", "meta": {"hexsha": "3461062682032dbe1694fc11c7861d16dbed4124", "size": 3455, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/ident.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/ident.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/ident.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.1608391608, "max_line_length": 71, "alphanum_fraction": 0.6240231548, "num_tokens": 1111, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.837619963333289, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.6748136085035299}} {"text": "!\r\n! The Laboratory of Algorithms\r\n!\r\n! The MIT License\r\n!\r\n! Copyright 2011-2015 Andrey Pudov.\r\n!\r\n! Permission is hereby granted, free of charge, to any person obtaining a copy\r\n! of this software and associated documentation files (the 'Software'), to deal\r\n! in the Software without restriction, including without limitation the rights\r\n! to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n! copies of the Software, and to permit persons to whom the Software is\r\n! furnished to do so, subject to the following conditions:\r\n!\r\n! The above copyright notice and this permission notice shall be included in\r\n! all copies or substantial portions of the Software.\r\n!\r\n! THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r\n! THE SOFTWARE.\r\n!\r\n\r\n! Longest Collatz sequence\r\n!\r\n! The following iterative sequence is defined for the set of positive integers:\r\n!\r\n! n > n/2 (n is even)\r\n! n > 3n + 1 (n is odd)\r\n!\r\n! Using the rule above and starting with 13, we generate the following sequence:\r\n!\r\n! 13 > 40 > 20 > 10 > 5 > 16 > 8 > 4 > 2 > 1\r\n!\r\n! It can be seen that this sequence (starting at 13 and finishing at 1) contains\r\n! 10 terms. Although it has not been proved yet (Collatz Problem), it is\r\n! thought that all starting numbers finish at 1.\r\n!\r\n! Which starting number, under one million, produces the longest chain?\r\n!\r\n! NOTE: Once the chain starts the terms are allowed to go above one million.\r\nmodule MPEProblem14\r\n\r\n implicit none\r\n private\r\n\r\n type, public :: TPEProblem14\r\n contains\r\n procedure, nopass :: present\r\n end type\r\ncontains\r\n subroutine present\r\n write (*, '(A)') 'Problem 14. Longest Collatz sequence.'\r\n\r\n write (*, '(A, I)') 'Chain 1: ', chain1()\r\n end subroutine\r\n\r\n function chain1\r\n integer :: chain1\r\n integer :: index\r\n integer :: value\r\n integer :: max\r\n\r\n ! initial values\r\n chain1 = 0\r\n index = 0\r\n value = 0\r\n max = 0\r\n\r\n do index = 1, 1000000\r\n value = get_length(index)\r\n\r\n if (value .gt. max) then\r\n max = value\r\n chain1 = index\r\n end if\r\n end do\r\n end function\r\n\r\n function get_length(number)\r\n integer, intent(in) :: number\r\n\r\n integer :: get_length\r\n integer*8 :: value\r\n\r\n ! initial value\r\n get_length = 1\r\n value = number\r\n\r\n do while (value .gt. 1)\r\n if (mod(value, 2) .eq. 0) then\r\n value = value / 2\r\n else\r\n value = (value * 3) + 1\r\n end if\r\n\r\n get_length = get_length + 1\r\n end do\r\n end function\r\nend module\r\n", "meta": {"hexsha": "b550a330a394538098fbb3025cd41d22f2f8e912", "size": 3143, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Problems/ProjectEuler/Problem14.f", "max_stars_repo_name": "andreypudov/Algorithms", "max_stars_repo_head_hexsha": "9693efa0abed30a38fcb9c3f7eebbd5b92b734f5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2016-02-15T14:45:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-01T22:42:32.000Z", "max_issues_repo_path": "Problems/ProjectEuler/Problem14.f", "max_issues_repo_name": "jlokimlin/Algorithms", "max_issues_repo_head_hexsha": "d981990394d940fd999334b0b65b118567670d1a", "max_issues_repo_licenses": ["MIT"], "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/ProjectEuler/Problem14.f", "max_forks_repo_name": "jlokimlin/Algorithms", "max_forks_repo_head_hexsha": "d981990394d940fd999334b0b65b118567670d1a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2016-02-24T15:47:02.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-01T10:45:03.000Z", "avg_line_length": 30.2211538462, "max_line_length": 81, "alphanum_fraction": 0.6191536748, "num_tokens": 763, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.6748136045945966}} {"text": "program force_calculation \n implicit none\n integer::i,j,n =108\n real(8)::rx(200),ry(200),rz(200),boxl,sigsq,epslon,rxij,ryij,rzij,rijsq,sr2,sr6,sr12,rcutoffsq,rcutoff,v,sig,kb,a\n real(8)::fxij,fyij,fzij,fpr,fx(200),fy(200),fz(200)\n !real(8),allocatable::a(:,:)!,fx(:),fy(:),fz(:)\n\n dimension a(200,200)\n open(1,file='argon.init')\n do i=1,n\n read(1,*) (a(i,j),j=1,3)\n rx(i) =a(i,1)\n ry(i) =a(i,2)\n rz(i) =a(i,3)\n \n end do\n \n\n boxl =17.158d0\n sig = 3.405d0\n sigsq = sig * sig\n kb = 1.38E-23\n epslon = 120.0d0 !* kb\n\n rcutoff = 0.50d0 * boxl\n rcutoffsq = rcutoff * rcutoff\n\n do i=1,n\n rx(i) = rx(i) - (boxl * anint(rx(i)/boxl))\n ry(i) = ry(i) - (boxl * anint(ry(i)/boxl))\n rz(i) = rz(i) - (boxl * anint(rz(i)/boxl))\n end do\n\n do i=1,n\n fx(i)=0.0d0; fy(i)=0.0d0; fz(i)=0.0d0\n end do\n\n\n v=0.0d0\n do i=1,n-1\n do j=i+1,n\n rxij = rx(i) - rx(j)\n ryij = ry(i) - ry(j)\n rzij = rz(i) - rz(j)\n \n rxij = rxij - (boxl * anint(rxij/boxl))\n ryij = ryij - (boxl * anint(ryij/boxl))\n rzij = rzij - (boxl * anint(rzij/boxl))\n \n \n rijsq = rxij**2 + ryij**2 + rzij**2\n sr2 = sigsq/rijsq\n sr6 = sr2 * sr2 * sr2\n sr12 = sr6 * sr6\n if(rijsq3.0D0) Goto 10\n z = x + 3.D0\n 10 gmre = 0.5D0*dlog(2.D0*3.14159265D0/z) + z*dlog(z) - z + dlog(1.D0+1.D0/12.D0/z+1.D0/288.D0/z**2-139.D0/51840.D0/z**3-571.D0/2488320.D0/z**4)\n If (z==x) Goto 20\n gmre = gmre - dlog(z-1.D0) - dlog(z-2.D0) - dlog(z-3.D0)\n 20 Continue\n Return\nEnd Function gmre\n", "meta": {"hexsha": "4bdf9b847ecef7072aa8f5cb3c725b8d322dac94", "size": 376, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/gmre.f90", "max_stars_repo_name": "xiaohaijin/AMPT", "max_stars_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-12-24T19:37:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-14T12:58:59.000Z", "max_issues_repo_path": "src/gmre.f90", "max_issues_repo_name": "xiaohaijin/AMPT", "max_issues_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_issues_repo_licenses": ["MIT"], "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/gmre.f90", "max_forks_repo_name": "xiaohaijin/AMPT", "max_forks_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_forks_repo_licenses": ["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.9230769231, "max_line_length": 146, "alphanum_fraction": 0.6063829787, "num_tokens": 197, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248191350352, "lm_q2_score": 0.7185943805178139, "lm_q1q2_score": 0.6747779581971929}} {"text": "!************************************************************************\n! This program is part of the\n! OpenMP Source Code Repository\n!\n! http://www.pcg.ull.es/ompscr/\n! e-mail: ompscr@etsii.ull.es\n!\n! Copyright (c) 2004, OmpSCR Group\n! All rights reserved.\n!\n! Redistribution and use in source and binary forms, with or without modification, \n! are permitted provided that the following conditions are met:\n! * Redistributions of source code must retain the above copyright notice, \n! this list of conditions and the following disclaimer. \n! * Redistributions in binary form must reproduce the above copyright notice, \n! this list of conditions and the following disclaimer in the documentation \n! and/or other materials provided with the distribution. \n! * Neither the name of the University of La Laguna nor the names of its contributors \n! may be used to endorse or promote products derived from this software without \n! specific prior written permission. \n!\n! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" \n! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED \n! WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n! IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, \n! INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, \n! BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, \n! OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, \n! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) \n! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY \n! OF SUCH DAMAGE.\n!\n! FILE: f_jacobi08.f90\n! VERSION: 1.1\n! DATE: Oct 2004\n! AUTHORS: Author: Joseph Robicheaux, Kuck and Associates, Inc. (KAI), 1998\n! Modified: Sanjiv Shah, Kuck and Associates, Inc. (KAI), 1998\n! This version: Dieter an Mey, Aachen University (RWTH), 1999 - 2003\n! anmey@rz.rwth-aachen.de\n! http://www.rwth-aachen.de/People/D.an.Mey.html\n! COMMENTS TO: ompscr@etsii.ull.es\n! DESCRIPTION: program to solve a finite difference discretization of Helmholtz equation : \n! (d2/dx2)u + (d2/dy2)u - alpha u = f using Jacobi iterative method.\n! COMMENTS: OpenMP version 8: 1 PR outside the iteration loop, 2-fold unrolling, \n! software pipelining, 2 barriers per iteration\n! Directives are used in this code to achieve paralleism. \n! All do loops are parallized with default 'static' scheduling.\n! REFERENCES: http://www.rz.rwth-aachen.de/computing/hpc/prog/par/openmp/jacobi.html\n! BASIC PRAGMAS: parallel do\n! USAGE: ./f_jacobi08.par 1000 1000 0.8 1.0 1000\n! INPUT: n - grid dimension in x direction\n! m - grid dimension in y direction\n! alpha - Helmholtz constant (always greater than 0.0)\n! tol - error tolerance for iterative solver\n! relax - Successice over relaxation parameter\n! mits - Maximum iterations for iterative solver\n! OUTPUT: Residual and error \n! u(n,m) - Dependent variable (solutions)\n! f(n,m) - Right hand side function \n! FILE FORMATS: -\n! RESTRICTIONS: An excesive grid dimension might cause a runtime error\n! if memory is not enough.\n! REVISION HISTORY:\n!**************************************************************************\n\n\n\n program main \n USE oscrCommon_f\n USE omp_lib\n implicit none \n\ninteger, parameter :: NUM_ARGS = 6\ninteger, parameter :: NUM_TIMERS = 1\n\n integer n,m,mits, kreps,nreps\n double precision tol,relax,alpha \n integer nthreads, minthreads, maxthreads\n\n common /idat/ n,m,mits\n common /fdat/ tol,alpha,relax\n! \n! Read info \n! \n character(len=38),dimension(NUM_ARGS) :: argNames = (/'Grid dimension: X dir = ', &\n 'Grid dimension: Y dir = ', &\n 'Helmhotlz constant = ', &\n 'Successive over-relaxation parameter =', &\n 'error tolerance for iterative solver =', &\n 'Maximum iterations for solver = '/)\n character(len=4),dimension(NUM_ARGS) :: defaultValues = (/ '1000', '1000', '0.8 ', '1.0 ', '1e-7', '1000'/)\n character(len=8),dimension(NUM_TIMERS) :: timerNames = (/ 'EXE_TIME' /)\n\n nthreads = omp_get_max_threads()\n call OSCR_init( nthreads, &\n \"Jacobi solver for the Helmholtz equation.\", &\n '', &\n NUM_ARGS, &\n argNames, &\n defaultValues, &\n NUM_TIMERS, &\n NUM_TIMERS, &\n timerNames )\n\n! 1. GET PARAMETERS\n n = OSCR_getarg_integer(1)\n m = OSCR_getarg_integer(2)\n alpha = OSCR_getarg_doubleprecision(3)\n relax = OSCR_getarg_doubleprecision(4)\n tol = OSCR_getarg_doubleprecision(5)\n mits = OSCR_getarg_integer(6)\n\n!\n! Calls a driver routine \n! \n call driver\n\n stop\n end \n\n subroutine driver\n!************************************************************\n! Subroutine driver () \n! This is where the arrays are allocated and initialzed. \n!\n! Working varaibles/arrays \n! dx - grid spacing in x direction \n! dy - grid spacing in y direction \n!************************************************************\n \n USE oscrCommon_f\n implicit none \n\n integer n,m,mits \n double precision tol,relax,alpha, dt\n\n common /idat/ n,m,mits\n common /fdat/tol,alpha,relax\n\n double precision u(n,m),f(n,m),dx,dy\n double precision mflops, maxmflops\n\n! Initialize data\n\n call initialize (n,m,alpha,dx,dy,u,f)\n\n! Solve Helmholtz equation\n\n call OSCR_timer_start(1)\n call jacobi (n,m,dx,dy,alpha,relax,u,f,tol,mits)\n call OSCR_timer_stop(1)\n dt = OSCR_timer_read(1)\n call OSCR_report() \n\n mflops = float(mits)*float(m-2)*float(n-2)*13.0d0*0.000001d0 / dt\n write (*,'(a,f12.6)') 'elapsed time usage', dt\n write (*,'(a,f12.6)') 'MFlop/s ', mflops\n \n! Check error between exact solution\n\n call error_check (n,m,alpha,dx,dy,u,f)\n\n return \n end \n\n subroutine initialize (n,m,alpha,dx,dy,u,f) \n!*****************************************************\n! Initializes data \n! Assumes exact solution is u(x,y) = (1-x^2)*(1-y^2)\n!\n!*****************************************************\n implicit none \n \n integer n,m\n double precision u(n,m),f(n,m),dx,dy,alpha\n \n integer i,j, xx,yy\n double precision PI \n parameter (PI=3.1415926)\n\n dx = 2.0 / (n-1)\n dy = 2.0 / (m-1)\n\n! Initilize initial condition and RHS\n\n!$omp parallel do private(xx,yy,i,j)\n do j = 1,m\n do i = 1,n\n xx = -1.0 + dx * dble(i-1) ! -1 < x < 1\n yy = -1.0 + dy * dble(j-1) ! -1 < y < 1\n u(i,j) = 0.0 \n f(i,j) = -alpha *(1.0-xx*xx)*(1.0-yy*yy) &\n & - 2.0*(1.0-xx*xx)-2.0*(1.0-yy*yy)\n enddo\n enddo\n\n\n return \n end \n\n subroutine error_check (n,m,alpha,dx,dy,u,f) \n implicit none \n!***********************************************************\n! Checks error between numerical and exact solution \n!\n!*********************************************************** \n \n integer n,m\n double precision u(n,m),f(n,m),dx,dy,alpha \n \n integer i,j\n double precision xx,yy,temp,error \n\n dx = 2.0 / (n-1)\n dy = 2.0 / (m-1)\n error = 0.0 \n\n!$omp parallel do private(xx,yy,i,j,temp) reduction(+:error)\n do j = 1,m\n do i = 1,n\n xx = -1.0d0 + dx * dble(i-1)\n yy = -1.0d0 + dy * dble(j-1)\n temp = u(i,j) - (1.0-xx*xx)*(1.0-yy*yy)\n error = error + temp*temp \n enddo\n enddo\n\n error = sqrt(error)/dble(n*m)\n\n print *, 'Solution Error : ',error\n\n return \n end \n\n\n subroutine jacobi (n,m,dx,dy,alpha,omega,u,f,tol,maxit)\n \n ! use omp_lib\n \n implicit none \n integer n,m,maxit\n double precision dx,dy,f(n,m),u(n,m),alpha, tol,omega\n\n integer i,j,k,k_priv \n double precision error, error1,error2,resid, ax,ay,b\n double precision error_priv, uold(n,m)\n\n ax = 1.0/(dx*dx) ! X-direction coef \n ay = 1.0/(dy*dy) ! Y-direction coef\n b = -2.0/(dx*dx)-2.0/(dy*dy) - alpha ! Central coeff \n\n do j=1,m, m-1\n do i=1,n\n uold(i,j) = u(i,j) \n enddo\n enddo\n do j=2,m-1\n do i=1,n,n-1\n uold(i,j) = u(i,j) \n enddo\n enddo\n\n!$omp parallel private(resid, k_priv,error_priv)\n k_priv = 1\n error_priv = 10.0d0 * tol \n do \n if (k_priv.gt.maxit .or. error_priv.le.tol) exit \n\n!$omp single\n error1 = 0.0d0 \n!$omp end single nowait \n\n!$omp do \n do j=1,m\n do i=1,n\n uold(i,j) = u(i,j) \n enddo\n enddo\n!$omp end do ! implicit barrier\n\n\n!$omp do reduction(+:error1)\n do j = 2,m-1\n do i = 2,n-1 \n resid = (ax*(uold(i-1,j) + uold(i+1,j)) &\n & + ay*(uold(i,j-1) + uold(i,j+1)) &\n & + b * uold(i,j) - f(i,j))/b\n u(i,j) = uold(i,j) - omega * resid\n error1 = error1 + resid*resid \n end do\n enddo\n!$omp end do ! implicit barrier\n\n k_priv = k_priv + 1\n error_priv = sqrt(error1)/dble(n*m)\n\n if (k_priv.gt.maxit .or. error_priv.le.tol) exit \n\n!$omp single\n error2 = 0.0d0 \n!$omp end single nowait \n!$omp do \n do j=1,m\n do i=1,n\n uold(i,j) = u(i,j) \n enddo\n enddo\n!$omp end do ! implicit barrier\n\n\n!$omp do reduction(+:error2)\n do j = 2,m-1\n do i = 2,n-1 \n resid = (ax*(uold(i-1,j) + uold(i+1,j)) &\n & + ay*(uold(i,j-1) + uold(i,j+1)) &\n & + b * uold(i,j) - f(i,j))/b\n u(i,j) = uold(i,j) - omega * resid\n error2 = error2 + resid*resid \n end do\n enddo\n!$omp end do ! implicit barrier\n\n k_priv = k_priv + 1\n error_priv = sqrt(error2)/dble(n*m)\n\n end do ! End iteration loop\n!$omp barrier ! don't miss this barrier\n!$omp single\n k = k_priv\n error = error_priv\n!$omp end single \n!$omp end parallel\n \n print *, 'Total Number of Iterations ', k \n print *, 'Residual ', error \n\n return \n end \n", "meta": {"hexsha": "abe3bb111531d6a5e6c752d7e9fff548839bf97a", "size": 11757, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/OmpSCR_v2.0/applications/f_Jacobi/f_jacobi08.f90", "max_stars_repo_name": "World-Worst-Detector/romp", "max_stars_repo_head_hexsha": "d45cf33bd233eef4cd475a8dd328d19a3ae27c24", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-11-15T16:44:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T05:39:54.000Z", "max_issues_repo_path": "tests/OmpSCR_v2.0/applications/f_Jacobi/f_jacobi08.f90", "max_issues_repo_name": "World-Worst-Detector/romp", "max_issues_repo_head_hexsha": "d45cf33bd233eef4cd475a8dd328d19a3ae27c24", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2019-03-12T16:03:13.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-15T01:23:59.000Z", "max_forks_repo_path": "tests/OmpSCR_v2.0/applications/f_Jacobi/f_jacobi08.f90", "max_forks_repo_name": "World-Worst-Detector/romp", "max_forks_repo_head_hexsha": "d45cf33bd233eef4cd475a8dd328d19a3ae27c24", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2019-01-03T22:19:14.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-23T18:10:49.000Z", "avg_line_length": 34.6814159292, "max_line_length": 113, "alphanum_fraction": 0.4980862465, "num_tokens": 3050, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778258, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.6746924217088892}} {"text": "| This example shows how to do input and some numeric munging.\n|\n| It implements the \"3N+1\" sequences:\n\nwith~ ~util\n\n: about quote *\n\tThis program computes and displays several 3N+1 sequences. Starting values\n\tfor the sequences are input by the user. Terms in a sequence are printed in\n\tturn, until there are no more terms. After a sequence has been displayed,\n\tthe number of terms in that sequence is reported to the user.\n\n\tType 'play' to start.\n* type cr ;\n\n: seeyou cr .\" Thanks for playing!\" cr bye ;\n\n: getstart ( -- n )\n\tcr .\" Enter the starting value (ESC or ENTER to quit): \"\n\tscratch 20 accept dup 0if seeyou ;then\n\tscratch swap >single 0if\n\t\tcr .\" The value '\" type .\" ', is not a valid number\" getstart \n\tthen\n\tdup 0 90+13*NPOINT when NPARAM=5\n\tLW=35000\n\tIILSFUN2=0\n\tIILSHES2=0\n\tIFAIL=1\n\tCALL E04HFF(NPOINT,NPARAM,Z,FSUMSQ,IWORK,LIW,WORK,LW,IFAIL)\n\tWRITE(9,1041)IILSFUN2,IILSHES2\n1041\tFORMAT(' ITERATIONS FOR E04HFF : IILSFUN2 =',I5,\n 1 ' IILSHES2 =',I5)\n \nC Write to units 6 & 9 if it fails to find minimum\n\tIF(IFAIL.NE.0) THEN\n\t WRITE(9,1040) IFAIL\n\t IF(TALK) THEN\n WRITE(6,1040) IFAIL\n1040\t FORMAT(' FAILURE IN E04HFF, IFAIL =',I4)\n\t WRITE(9,1041)IILSFUN2,IILSHES2\nC IFAIL=2: wrong starting point (more than 50 iterations)\n IF(IFAIL.EQ.2)THEN\n WRITE(6,1042) \n1042\t FORMAT(' Wrong initial guess: try with another center...')\n ENDIF\n ENDIF\n\t IFLAG=IFAIL\n\tENDIF\n \nC Compute new values of THEMIN,THEMAX, if center has changed (free center):\n IF(NPARAM.EQ.5)THEN\n\t CALL THETA_MIN_MAX(TMIN,TMAX,RMIN,RMAX,THETA,Z(4),Z(5)) \n THEMIN=TMIN\n THEMAX=TMAX\n ENDIF\nC JLP99\n WRITE(6,*)' JLP99/THEMIN,THEMAX',THEMIN,THEMAX\n\nC Return if serious problem :\n\tIF((IFAIL.LT.5.AND.IFAIL.GT.8).AND.(.NOT.KAMIKAZE))RETURN\n \nC Work out errors in the fit by inverting the Hessian matrix :\n\tCALL ERPARM(FSUMSQ,MFLAG,NPARAM,TALK)\n \n\tIF(MFLAG.NE.0)THEN\n\t WRITE(9,1050)\n\t IF(TALK) WRITE(6,1050)\n1050\t FORMAT(' FAILURE TO FIND A SENSIBLE SOLUTION')\n\t IFLAG=-3\nC JLP99: I go on in that case.\nC\t IF(.NOT.KAMIKAZE)RETURN\n\tENDIF\n \nC Display the results with \"monitor\" routine:\n\tCALL MONIT(NPARAM,FVECC,FSUMSQ,TALK)\n \nC Possibility of removing bad points such as small stars if\nC AUTO_IMPROVE=.TRUE.\n\t IF(ISTEP.LT.30.AND.AUTO_IMPROVE)THEN\t\n\t ISTEP=ISTEP+1\nC Look at the variation of the position angle, and decide whether\nC to do a new iteration:\n\t ZDELTA=DABS(Z3OLD-Z(3))\n\t Z3OLD=Z(3)\n\t IF(ZDELTA.GT.0.002)THEN\nC Compute the residuals FVECC with the solution :\n\t LJC=MAXPOINTS\n\t CALL LSFUN2(NPOINT,NPARAM,Z,FVECC,AJAC,LJC)\nC Another call of E0 after elimination of points over 1.6-sigma from\nC the ellipse:\n\t RMS=DSQRT(FSUMSQ/FLOAT(NPOINT-NPARAM))\n\t VTEST=1.6*RMS\nC Eliminates only the points with positive residuals FVECC\nC since most of the time the pollution comes from stars in the outskirts\n\t II=0\n\t DO I=1,NPOINT\n\t IF(FVECC(I).LT.VTEST)THEN\n\t II=II+1\n\t X(II)=X(I)\n\t Y(II)=Y(I)\n\t ENDIF\n\t END DO\n \n\t IF(TALK) WRITE (6,857)\n\t WRITE (9,857)\n857\t FORMAT(' REMOVING POINTS WITH RESIDUALS OVER 1.6 SIGMA')\n\t NPOINT=II\n\t IF(TALK) WRITE(6,856) ISTEP,NPOINT\n\t WRITE(9,856) ISTEP,NPOINT\n856\t FORMAT(2X,I2,'th CALL OF E04HFF WITH :',I5,' POINTS')\n\t GO TO 1111\n\tENDIF\n \n\tENDIF\n \nC Stores final results for later output (with ECALC)\n \nC Return if there is more than 200 curves (!)\n1300\tNEE=NEE+1\n\tIF(NEE.GT.200) THEN\n\t WRITE(9,1333)\n\t IF(TALK) WRITE(6,1333)\n1333\t FORMAT(' ESTORE STORAGE EXHAUSTED')\n\t IFLAG=-4\n\t RETURN\n\tENDIF\n \n\tESTORE(NEE,1)=Z(1)\n\tESTORE(NEE,2)=Z(2)\n\tESTORE(NEE,3)=Z(3)\n\tESTORE(NEE,4)=Z(4)\n\tESTORE(NEE,5)=Z(5)\n\tESTORE(NEE,6)=SDEV(1)\n\tESTORE(NEE,7)=SDEV(2)\n\tESTORE(NEE,8)=SDEV(3)\n\tESTORE(NEE,9)=SDEV(4)\n\tESTORE(NEE,10)=SDEV(5)\n \nC Call the subroutine which Fourier analyses the residuals\nC of the contour from the fitted ellipse\nC and store the Fourier output for later output (with FFCALC)\n\tIF(FOURIER)THEN\n\t CALL RECSER\n\t FDATA(NEE,1)=RRR\n\t FDATA(NEE,2)=AAAA\n\t FDATA(NEE,3)=AA(1,1)\n\t FDATA(NEE,4)=AA(1,2)\n\t FDATA(NEE,5)=AA(2,1)\n\t FDATA(NEE,6)=AA(2,2)\n\t FDATA(NEE,7)=AA(3,1)\n\t FDATA(NEE,8)=AA(3,2)\n\t FDATA(NEE,9)=AA(4,1)\n\t FDATA(NEE,10)=AA(4,2)\n\tENDIF\n \n\tRETURN\n\tEND\nC**********************************************************\nC SUBROUTINE LSFUN2(NPOINT,NPARAM,Z,FVECC,FJACC,LJC)\nC This routine is called by E04HFF to work out all of the\nC residuals and the Jacobian matrix\nC\nC**********************************************************\n\tSUBROUTINE LSFUN2(NPOINT,NPARAM,Z,FVECC,FJACC,LJC)\n\tIMPLICIT REAL*8(A-H,P-Z)\n PARAMETER (MAXPOINTS=2000)\n\tREAL*8 PI,THEMIN,THEMAX,X0,Y0\n\tREAL*4 X,Y\n\tREAL*8 Z(5),FVECC(NPOINT),FJACC(LJC,NPARAM)\n\tREAL*8 AJAC(MAXPOINTS,5)\n\tCOMMON/BLOCKA/PI,THEMIN,THEMAX\n\tCOMMON/BLOCKB/X(MAXPOINTS),Y(MAXPOINTS)\n\tCOMMON/CHECKEFIT1/IILSFUN2,IILSHES2\n\tCOMMON/FIXED_CENT/X0,Y0\n\tIILSFUN2=IILSFUN2+1\n \n\tTCS=DCOS(Z(3))\n\tTSN=DSIN(Z(3))\n\tTCS2=TCS*TCS\n\tTSN2=TSN*TSN\n\tZ1=Z(1)\n\tZ2=Z(2)\nC To avoid division by 0 :\n\tIF(DABS(Z1).LT.1.0D-10)Z1=1.0D-10\n\tIF(DABS(Z2).LT.1.0D-10)Z2=1.0D-10\n\tDENA=Z1*Z1\n\tDENB=Z2*Z2\n \nC Residuals in array FVECC :\n\tDO 30 I=1,NPOINT\n\tTDX=X(I)-Z(4)\n\tTDY=Y(I)-Z(5)\n\tTDX2=TDX*TDX\n\tTDY2=TDY*TDY\n\t F1=((TDX2*TCS2)+(TDY2*TSN2)+\n\t1\t2.0*(TDX*TDY*TCS*TSN))/DENA\n\t F2=((TDX2*TSN2)+(TDY2*TCS2)-\n\t1\t2.0*(TDX*TDY*TCS*TSN))/DENB\n\t FVECC(I)=F1+F2-1.0D0\n \nC Jacobian matrix in two dimensional array AJAC. This bit is\nC right, don't change it!\n\t AJAC(I,1)=-2.0*F1/Z1\n\t AJAC(I,2)=-2.0*F2/Z2\n\t AJAC(I,4)=(-2.0*TDX*TCS2-2.0*TDY*TCS*TSN)/DENA+\n\t1\t(-2.0*TDX*TSN2+2.0*TDY*TCS*TSN)/DENB\n\t AJAC(I,5)=(-2.0*TDY*TSN2-2.0*TDX*TCS*TSN)/DENA+\n\t1\t(-2.0*TDY*TCS2+2.0*TDX*TCS*TSN)/DENB\n\t AJAC(I,3)=(2.0*(TDY2-TDX2)*TCS*TSN+\n\t1\t2.0*TDX*TDY*(TCS2-TSN2))/DENA+\n\t1\t(2.0*(TDX2-TDY2)*TCS*TSN-\n\t1\t2.0*TDX*TDY*(TCS2-TSN2))/DENB\n30\tCONTINUE\n \n\tDO I=1,NPOINT\n\t DO K=1,NPARAM\n\t FJACC(I,K)=AJAC(I,K)\n\t END DO\n\tEND DO\n \n\tEND\nC**********************************************************\nC SUBROUTINE LSHES2(NPOINT,NPARAM,FVECC,Z,HESS,LHES)\nC This routine is called by E04HFF to work out\nC the elements of the symmetric Hessian matrix (Second derivatives)\nC Here FVECC is an input array which must not be changed.\nC**********************************************************\n\tSUBROUTINE LSHES2(NPOINT,NPARAM,FVECC,Z,HESS,LHES)\n PARAMETER (MAXPOINTS=2000)\n \tIMPLICIT REAL*8(A-H,P-Z)\n\tREAL*8 X0,Y0,PI,THEMIN,THEMAX\n\tREAL*4 X,Y\n\tREAL*8 FHESS(15)\n\tREAL*8 Z(5),FVECC(NPOINT),HESS(LHES)\n\tCOMMON/BLOCKA/PI,THEMIN,THEMAX\n\tCOMMON/BLOCKB/X(MAXPOINTS),Y(MAXPOINTS)\n\tCOMMON/CHECKEFIT1/IILSFUN2,IILSHES2\n\tCOMMON/FIXED_CENT/X0,Y0\n\tIILSHES2=IILSHES2+1\n \n\tTCS=DCOS(Z(3))\n\tTSN=DSIN(Z(3))\n\tTCS2=TCS*TCS\n\tTSN2=TSN*TSN\n\tZ1=Z(1)\n\tZ2=Z(2)\n \nC To avoid division by 0 :\n\tIF(DABS(Z1).LT.1.0D-10)Z1=1.0D-10\n\tIF(DABS(Z2).LT.1.0D-10)Z2=1.0D-10\n \n\tDENA=Z1*Z1\n\tDENB=Z2*Z2\n\tZ13=Z1*Z1*Z1\n\tZ23=Z2*Z2*Z2\n \n\tNMAXHESS=((NPARAM+1)*NPARAM)/2\nC Initialise the array HESS\n\tDO K=1,NMAXHESS\n\tHESS(K)=0.0\n\tEND DO\n \nC Residuals in array FVECC :\n\tDO 30 I=1,NPOINT\n\tTDX=X(I)-Z(4)\n\tTDY=Y(I)-Z(5)\n\tTDX2=TDX*TDX\n\tTDY2=TDY*TDY\n\t F1=((TDX2*TCS2)+(TDY2*TSN2)+\n\t1\t2.0*(TDX*TDY*TCS*TSN))/DENA\n\t F2=((TDX2*TSN2)+(TDY2*TCS2)-\n\t1\t2.0*(TDX*TDY*TCS*TSN))/DENB\n \nC Hessian matrix in one dimensional array FHESS.\nC 1,1\n\tFHESS(1)=6.0*F1/DENA\nC 2,1\n\tFHESS(2)=0.\nC 2,2\n\tFHESS(3)=6.0*F2/DENB\nC 3,1\n\tFHESS(4)=(2.0*(TDY2-TDX2)*TCS*TSN+\n\t1\t2.0*TDX*TDY*(TCS2-TSN2))*(-2.0/Z13)\nC 3,2\n\tFHESS(5)=(2.0*(TDX2-TDY2)*TCS*TSN-\n\t1\t2.0*TDX*TDY*(TCS2-TSN2))*(-2.0/Z23)\nC 3,3\n\tFHESS(6)=(2.0*TSN2*(TDX2-TDY2)-\n\t1\t2.0*TCS2*(TDX2-TDY2)-\n\t1\t8.0*TSN*TCS*TDX*TDY)/DENA+\n\t1\t(2.0*TCS2*(TDX2-TDY2)-\n\t1\t2.0*TSN2*(TDX2-TDY2)+\n\t1\t8.0*TSN*TCS*TDX*TDY)/DENB\nC 4,1\n\tFHESS(7)=(-2.0*TDX*TCS2-2.0*TDY*TCS*TSN)*(-2.0/Z13)\nC 4,2\n\tFHESS(8)=(-2.0*TDX*TSN2+2.0*TDY*TCS*TSN)*(-2.0/Z23)\nC 4,3\n\tFHESS(9)=(4.0*TCS*TSN*TDX-2.0*TDY*(TCS2-TSN2))/DENA+\n\t1\t(-4.0*TCS*TSN*TDX+2.0*TDY*(TCS2-TSN2))/DENB\nC 4,4\n\tFHESS(10)=2.0*TCS2/DENA+2.0*TSN2/DENB\nC 5,1\n\tFHESS(11)=(-2.0*TDY*TSN2-2.0*TDX*TCS*TSN)*(-2.0/Z13)\nC 5,2\n\tFHESS(12)=(-2.0*TDY*TCS2+2.0*TDX*TCS*TSN)*(-2.0/Z23)\nC 5,3\n\tFHESS(13)=(-4.0*TCS*TSN*TDY-2.0*TDX*(TCS2-TSN2))/DENA+\n\t1\t(4.0*TCS*TSN*TDY+2.0*TDX*(TCS2-TSN2))/DENB\nC 5,4\n\tFHESS(14)=2.0*TCS*TSN/DENA-2.0*TCS*TSN/DENB\nC 5,5\n\tFHESS(15)=2.0*TSN2/DENA+2.0*TCS2/DENB\n \n\tDO K=1,NMAXHESS\n \t HESS(K)=HESS(K)+FVECC(I)*FHESS(K)\n\tEND DO\n \n30\tCONTINUE\n \n\tEND\nC****************************************************************\nC SUBROUTINE MONIT(NPARAM,FVECC,FSUMSQ,TALK)\nC\nC This routine can be called by EFIT to output how the\nC fit is going.\nC\nC****************************************************************\n\tSUBROUTINE MONIT(NPARAM,FVECC,FSUMSQ,TALK)\n\tIMPLICIT REAL*8(A-H,P-Z)\n\tREAL*8 Z(5),FVECC(NPOINT),SDEV(5),SXC,SYC\n\tREAL*8 PI,THEMIN,THEMAX,FSUMSQ,SCALE\n INTEGER*4 NPOINT,IFLG\n\tLOGICAL*4 TALK\n\tCOMMON/FIT1/Z,NPOINT,IFLG\n\tCOMMON/EPRM/SDEV\n\tCOMMON/BLOCKA/PI,THEMIN,THEMAX\n\tCOMMON/BLOCKC/SCALE\n \n\tRMS=DSQRT(FSUMSQ/FLOAT(NPOINT-NPARAM))\n\tWRITE(9,302) FSUMSQ,RMS\n302\tFORMAT(/,' SUM OF SQUARES =',E12.5,' RMS =',E12.5)\n \nC Permutation of Z(1) and Z(2) when Z(1) larger than Z(2) :\n\tIF(Z(1).LT.Z(2))THEN\n\t IF(TALK) WRITE (6,1080)\n\t WRITE (9,1080)\n1080\t FORMAT(' Z(1) LARGER THAN Z(2):',\n\t1\t' PERMUTATION OF Z(1) AND Z(2) AND THETA=THETA+PI/2')\n\t XZ1=Z(1)\n\t XZ2=Z(2)\n\t XDEV1=SDEV(1)\n\t XDEV2=SDEV(2)\n\t Z(1)=XZ2\n\t Z(2)=XZ1\n\t SDEV(1)=XDEV2\n\t SDEV(2)=XDEV1\n\t Z(3)=Z(3)+PI/2.0\n\tENDIF\n \nC----------------------------------------------------------------\nC Output of the results :\n\tWRITE(9,101)\n\tIF(TALK) WRITE(6,101)\n101\tFORMAT(/,4X,'MAJOR AXIS',4X,'MEAN RADIUS',4X,'E NUMBER',6X,\n\t1\t'XCENT',8X,'YCENT',7X,'THETA')\n\tWRITE(9,1088)\n\tIF(TALK) WRITE(6,1088)\n1088\tFORMAT(5X,'(ARCSEC)',57X,'(DEGREES)')\n \n\tXMAJAX=Z(1)\n\tXMINAX=Z(2)\n\tTHETA=Z(3)\n\tSMJ=SDEV(1)\n\tSMN=SDEV(2)\n\tSTH=SDEV(3)*180./PI\n\tIF(STH.GT.360.)STH=360.\n\tSXC=SDEV(4)\n\tSYC=SDEV(5)\n \n\tRAD=SQRT(XMAJAX*XMINAX)\n\tECC=10.*(XMAJAX-XMINAX)/XMAJAX\n\tPCMAJ=SMJ/XMAJAX\n\tPCMIN=SMN/XMINAX\n\tPCRAD=ABS(PCMAJ)+ABS(PCMIN)\n\tSRAD=0.5*RAD*PCRAD\n\tSECC=ECC*PCRAD\n \nC Conversion in arcseconds (Major axis and its error, Radius and its error) :\n\tXMAJAX=XMAJAX*SCALE\n\tSMAJAX=SMJ*SCALE\n\tRAD=RAD*SCALE\n\tSRAD=SRAD*SCALE\n \nC Conversion in degrees (Theta and its error)\n999\tIF(THETA.LE.PI) GO TO 998\n\tTHETA=THETA-PI\n\tGO TO 999\n998\tIF(THETA.GT.0.) GO TO 997\n\tTHETA=THETA+PI\n\tGO TO 998\n997\tTHETA=THETA*180./PI\n \nC Output of the values :\n\tIF(TALK) WRITE(6,102) XMAJAX,RAD,ECC,Z(4),Z(5),THETA\n\tIF(TALK) WRITE(6,103) SMAJAX,SRAD,SECC,SXC,SYC,STH\n\tWRITE(9,102) XMAJAX,RAD,ECC,Z(4),Z(5),THETA\n\tWRITE(9,103) SMAJAX,SRAD,SECC,SXC,SYC,STH\n102\tFORMAT(2X,6(F12.4,1X))\n103\tFORMAT(2X,6(2X,'+/-',F8.4))\n \n\tRETURN\n\tEND\nC*******************************************************\n\tSUBROUTINE ERPARM(FSUMSQ,MFLAG,NPARAM,TALK)\nC\nC This routine works out the formal errors on the fit by\nC inverting the Hessian matrix.\nC\n\tIMPLICIT REAL*8(A-H,P-Z)\n PARAMETER (MAXPOINTS=2000)\n\tREAL*8 A(6,5),B(5,5),Z(5),WORK(5),FSUMSQ,SDEV(5)\n\tREAL*8 AJAC(MAXPOINTS,5),FVECC(MAXPOINTS)\n\tLOGICAL*4 TALK\n\tINTEGER*4 NPOINT,IFLG\n\tCOMMON/FIT1/Z,NPOINT,IFLG\n\tCOMMON/EPRM/SDEV\n\tMFLAG=0\n \nC Compute the matrix AJAC :\n\tLJC=MAXPOINTS\n\tCALL LSFUN2(NPOINT,NPARAM,Z,FVECC,AJAC,LJC)\n \n\tDO 1 I=1,NPARAM\n\t DO 1 J=1,NPARAM\n\t SUM=0.0\n\t DO K=1,NPOINT\n \t SUM=SUM+AJAC(K,I)*AJAC(K,J)\n\t END DO\n\t A(I,J)=SUM\n1\tCONTINUE\n \n\tIA=6\n\tIB=5\n\tIFAIL=1\nC Matrix inversion\n\tCALL F01ABF(A,IA,NPARAM,B,IB,WORK,IFAIL)\n\t IF(IFAIL.NE.0)THEN\n\t IF(TALK) WRITE(6,100) IFAIL\n\t WRITE(9,100) IFAIL\n100\t FORMAT(/,' WARNING : FAILURE WHILE INVERTING THE MATRIX'\n 1\t ' TO WORK OUT THE ERRORS',/,\n 1 ' ERROR IN F01ABF, IFAIL =',I5,/,\n 1 '(ifail=2 means: ill-conditionned matrix)')\n\t MFLAG=1\n\t RETURN\n\t ENDIF\n \n\tC=FSUMSQ/(NPOINT-NPARAM)\n\tDO I=1,NPARAM\n\t DO J=1,I\n\t B(I,J)=B(I,J)*C\n\t END DO\n\tEND DO\n \n\tDO I=1,5\n\tSDEV(I)=DSQRT(DABS(B(I,I)))\n\tEND DO\n \n\tIF((SDEV(1).GT.10.).OR.(SDEV(2).GT.10.)\n\t1\t.OR.(SDEV(4).GT.10.).OR.(SDEV(5).GT.10.))THEN\n\t IF(TALK) WRITE(6,202)\n\t WRITE(9,202)\n202\tFORMAT(/,' WARNING !! THE ERRORS ARE TOO HIGH TO BE '\n\t1\t'REASONABLE ...')\n\tMFLAG=2\n\tENDIF\n \nC\tWRITE(9,201)\nC201\tFORMAT(' ***********COVARIANCE MATRIX***********')\nC\tDO 4 I=1,NPARAM\nC\tWRITE(9,200) (B(I,J),J=1,I)\nC4\tCONTINUE\nC200\tFORMAT(' ',5E14.7)\n \n\tRETURN\n\tEND\nC*******************************************************************\n\tSUBROUTINE ECALC(KK)\nC\nC This tidies up the ellipse fit output and writes it to unit 9 and 11.\nC Unit 11 is used by FITELLI to generate catalogues of parameters\n\tREAL*4 MAJAX,MINAX,RAD,ECC,THETA\n REAL*4 SMAJAX,SRAD,SECC,SXC,SYC,STH\n\tREAL*8 SCALE,Z(5)\n INTEGER*4 KK,NPOINT,IFLG\n\tCOMMON/EDATA/ ESTORE(200,10),FDATA(200,10),NEE\n\tCOMMON/BLOCKC/SCALE\n\tCOMMON/FIT1/Z,NPOINT,IFLG\n\tPI=3.14159265358979323846\n\tWRITE(9,100)\n100\tFORMAT('1',/,8X,\n\t1\t'************* ELLIPSE FIT OUTPUT ************',/)\n\tWRITE(9,101)\n101\tFORMAT(/,4X,'MAJOR AXIS',4X,'MEAN RADIUS',4X,'E NUMBER',6X,\n\t1\t'XCENT',8X,'YCENT',7X,'THETA')\n\tWRITE(9,1088)\n1088\tFORMAT(5X,'(ARCSEC)',57X,'(DEGREES)')\n \nC NEE : Number of levels\n\tWRITE(11,*)NEE\n \n\tDO 1 I=1,NEE\n CALL CONVERT_EFIT(I,MAJAX,RAD,ECC,Z(4),Z(5),THETA,\n 1 SMAJAX,SRAD,SECC,SXC,SYC,STH)\n\nC Output of the values :\n\t WRITE(9,102) MAJAX,RAD,ECC,Z(4),Z(5),THETA\n\t WRITE(9,103) SMAJAX,SRAD,SECC,SXC,SYC,STH\n\t WRITE(11,102) MAJAX,RAD,ECC,Z(4),Z(5),THETA\n\t WRITE(11,102) SMAJAX,SRAD,SECC,SXC,SYC,STH\n1\tCONTINUE\n102\tFORMAT(2X,6(F12.4,1X))\n103\tFORMAT(2X,6(2X,'+/-',F8.4))\n\nC Last index of array ESTORE (needed by EFIT6.FOR)\n KK=NEE\n RETURN\n\tEND\nC************************************************************\n\tSUBROUTINE RECSER\nC\nC This routine Fourier analyses the residuals of the contour\nC from the fitted ellipse.\nC Cf David Carter's thesis\nC\n\tIMPLICIT REAL*8 (Z)\n PARAMETER (MAXPOINTS=2000)\n\tREAL*8 Z(5)\n\tINTEGER*4 NPOINT,IFLG\n\tCOMMON/FIT1/Z,NPOINT,IFLG\n\tCOMMON/FOU1/RRR,A,AA(4,2)\n\tCOMMON/BLOCKB/X(MAXPOINTS),Y(MAXPOINTS)\n\tREAL*4 R(MAXPOINTS+1),TH(MAXPOINTS+1),DELTH(MAXPOINTS+1)\n\tREAL*4 AVTH(MAXPOINTS+1),AVR(MAXPOINTS+1)\n\n\tPI=3.14159265358979323846\n\tAAA=Z(1)\n\tBBB=Z(2)\n\tTHETA=Z(3)\n\tTCS=COS(THETA)\n\tTSN=SIN(THETA)\n\tRRR=SQRT(AAA*BBB)\nC\nC First transform the coordinates of the points\nC to a coordinate system in which the fitted\nC ellipse is a circle of unit radius.\nC\nC Calculate radius of the contour as a function of azimuthal\nC angle.\nC\n\tDO 2 I=1,NPOINT\nC Reset the origin to the center of the ellipse:\n XXX=X(I)-Z(4)\n\t YYY=Y(I)-Z(5)\nC Rotation of theta (ie new origin for the phases is the major axis):\n\t XSTAR=XXX*TCS+YYY*TSN\n\t YSTAR=YYY*TCS-XXX*TSN\nC Normalisation to major and minor axis (ie ellipse becomes a circle):\n\t XSTAR=XSTAR/AAA\n\t YSTAR=YSTAR/BBB\nC Here are the coordinates of the current point in\nC the new system (polar coordinates)\n\t R(I)=SQRT(XSTAR*XSTAR+YSTAR*YSTAR)\n\t TH(I)=ANGLE0(XSTAR,YSTAR,R(I))\n2\tCONTINUE\n\n\tR(NPOINT+1)=R(1)\n\tTH(NPOINT+1)=TH(1)\n\tA=0.\nC\nC Notice that the contour can go either way round, i.e. the\nC average DELTH can be positive or negative\nC\n\tDO 3 I=1,NPOINT\n\nC Check the difference in phase between two consecutive points\n\tDELTH(I)=TH(I+1)-TH(I)\n\tIF(DELTH(I).LT.-PI)THEN\n\t ISWCH=1\n\tELSEIF(DELTH(I).GT.PI)THEN\n\t ISWCH=2\n ELSE\n\t ISWCH=0\n\tENDIF\n\nC Now computes the average of the phases:\n\tAVTH(I)=(TH(I+1)+TH(I))/2.\n\nC The following is simply to get the right value for the\nC phases (and get rid of the dependence modulo 2*PI)\n\tIF(ISWCH.EQ.0) GO TO 8\n\tIF(ISWCH.EQ.2) GO TO 11\n\tDELTH(I)=DELTH(I)+2.*PI\n12\tIF(AVTH(I).GE.PI) GO TO 9\n\tIF(AVTH(I).LT.-PI) AVTH(I)=AVTH(I)+PI\n\tGO TO 10\n11\tDELTH(I)=DELTH(I)-2.*PI\n\tGO TO 12\n9\tAVTH(I)=AVTH(I)-PI\n10\tCONTINUE\n8\tAVR(I)=(R(I+1)+R(I))/2.\n\tA=A+DELTH(I)*AVR(I)\n3 CONTINUE\n\n\tA=A/(2.*PI)\nC\nC The sum for the Fourier series is formed in the arrray AA,\nC which goes from 1 to 4; Fourier components up to 4th order\nC are calculated.\nC\n\tDO 4 J=1,2\n\tDO 4 K=1,4\n\t AA(K,J)=0.0\n4 CONTINUE\n\n\tDO 5 K=1,4\n\tDO 5 I=1,NPOINT\n\t AA(K,1)=AA(K,1)+DELTH(I)*AVR(I)*SIN(K*AVTH(I))\n\t AA(K,2)=AA(K,2)+DELTH(I)*AVR(I)*COS(K*AVTH(I))\n5 CONTINUE\n\n\tDO 6 K=1,4\n\tDO 6 J=1,2\n \t AA(K,J)=AA(K,J)/PI\n6 CONTINUE\nC\nC Now if the zero order component (A) is negative (it should be\nC about +1) then all the others will be of the wrong sign too.\nC So reverse them.\nC\n\tIF(A.LT.0.0) THEN\n\t DO K=1,4\n\t DO J=1,2\n\t AA(K,J)=-AA(K,J)\n\t END DO\n\t END DO\n\t A=-A\n\tEND IF\n\n\tRETURN\n\tEND\nC-------------------------------------------------------------------------\n\tSUBROUTINE FFCALC\nC\nC This routine tidies up and outputs the Fourier output.\nC\n\tREAL*8 SCALE\n\tCOMMON/EDATA/ ESTORE(200,10),FDATA(200,10),NEE\n\tCOMMON/BLOCKC/SCALE\nC Opens new file for Fourier output:\n OPEN(4,FILE='fitelli.fou',STATUS='UNKNOWN')\n\tWRITE(4,200)\n200\tFORMAT(/,' ******************* FOURIER COMPONENT OUTPUT *******'\n :,'*********')\n\tWRITE(4,201)\n201\tFORMAT(/,' RADIUS ZERO ORDER FIRST ORDER SECOND ORDER'\n :,' THIRD ORDER FOURTH ORDER',/,' (ARCSEC)',6X,\n :4('MAGNITUDE PHASE '))\nC\nC First write the fourier components out as amplitudes and phases.\nC\n\tDO 1 I=1,NEE\n\t RRR=FDATA(I,1)\n\t A0=FDATA(I,2)\n\t AA1=FDATA(I,3)\n\t BB1=FDATA(I,4)\n\t AA2=FDATA(I,5)\n\t BB2=FDATA(I,6)\n\t AA3=FDATA(I,7)\n\t BB3=FDATA(I,8)\n\t AA4=FDATA(I,9)\n\t BB4=FDATA(I,10)\n\t AMAG1=SQRT(AA1**2+BB1**2)\n\t AMAG2=SQRT(AA2**2+BB2**2)\n\t AMAG3=SQRT(AA3**2+BB3**2)\n\t AMAG4=SQRT(AA4**2+BB4**2)\n\t APH1=0.\n\t APH2=0.\n\t APH3=0.\n\t APH4=0.\n\t IF(BB1.NE.0)APH1=ATAN(AA1/BB1)\n\t IF(BB2.NE.0)APH2=ATAN(AA2/BB2)\n\t IF(BB3.NE.0)APH3=ATAN(AA3/BB3)\n\t IF(BB4.NE.0)APH4=ATAN(AA4/BB4)\n\t\n\t RRR=RRR*SCALE\n\t WRITE(4,202) RRR,A0,AMAG1,APH1,AMAG2,\n 1 APH2,AMAG3,APH3,AMAG4,APH4\n202\tFORMAT(' ',F7.2,1X,F5.3,9(1X,F7.4))\n1\tCONTINUE\nC\n\tWRITE(4,203)\n203\tFORMAT(/,' RADIUS ZERO ORDER FIRST ORDER SECOND ORDER'\n :,' THIRD ORDER FOURTH ORDER',/,' (ARCSEC)',6X,\n :4(' SINE COSINE '))\nC\nC Then write the data out as sine and cosine components.\nC\n\tDO 11 I=1,NEE\n \t RRR=FDATA(I,1)\n\t A0=FDATA(I,2)\n\t AA1=FDATA(I,3)\n\t BB1=FDATA(I,4)\n\t AA2=FDATA(I,5)\n\t BB2=FDATA(I,6)\n\t AA3=FDATA(I,7)\n\t BB3=FDATA(I,8)\n\t AA4=FDATA(I,9)\n\t BB4=FDATA(I,10)\n\t RRR=RRR*SCALE\n\t WRITE(4,202) RRR,A0,AA1,BB1,AA2,BB2,AA3,BB3,AA4,BB4\n11\tCONTINUE\n\n\tCLOSE(4)\n\tRETURN\n\tEND\nC----------------------------------------------------------------------\n\tFUNCTION ANGLE0(X,Y,R)\nC Works out position angle given X,Y (when the centre is at the\nC origin !!). Position angles measured from the positive X axis through\nC the positive Y axis. (Radians)\nC (to compute Fourier components)\n\tREAL*4 ANGLE0,PI,X,Y,R\n\tPI=3.14159265358979323846\n\tIF(Y)6,2,1\n1\tANGLE0=ACOS(X/R)\n\tRETURN\n2\tIF(X)5,3,4\n3\tWRITE(9,100)\n\tANGLE0=0.0\n\tRETURN\n4\tANGLE0=0.0\n\tRETURN\n5\tANGLE0=PI\n\tRETURN\n6\tANGLE0=ACOS(-X/R)+PI\n\tRETURN\n100\tFORMAT(' ANGLE0 CALLED AT CENTRE POINT')\n\tEND\nC******************************************************************\nC SUBROUTINE INPARS(NPARAM)\nC Set up initial parameters for first guess at the fit\nC\nC*******************************************************************\n\tSUBROUTINE INPARS(NPARAM)\n PARAMETER (MAXPOINTS=2000)\n REAL*8 Z(5),PI,THEMIN,THEMAX,X0,Y0\n\tREAL*8 TMIN,TMAX,RMIN,RMAX,THETA\n INTEGER*4 NPOINT,IFLG\n\tCOMMON/FIT1/Z,NPOINT,IFLG\n\tCOMMON/BLOCKA/ PI,THEMIN,THEMAX\n\tCOMMON/FIXED_CENT/X0,Y0\n \nC Take the center of the galaxy as the first guess for the\nC position of the centre :\n Z(4)=X0\n Z(5)=Y0\n \n\tCALL THETA_MIN_MAX(TMIN,TMAX,RMIN,RMAX,THETA,Z(4),Z(5)) \n\nC Initial parameters in array Z :\n\tZ(1)=RMAX\n\tZ(2)=RMIN\n\tZ(3)=THETA\n THEMIN=TMIN\n THEMAX=TMAX\n\tWRITE(9,1000) (Z(I),I=1,5)\n1000 FORMAT(/,' FIRST GUESS : MAJAX (PIXELS), MINAX (PIXELS)',\n\t1\t' THETA (RADIANS), OX, OY :',\n\t1\t/,2X,5(E12.5,2X))\n \n\tRETURN\n\tEND\n \nC******************************************************************\nC SUBROUTINE THETA_MIN_MAX \nC Compute the limiting angles TMIN,TMAX in radians, \nC given a center (XC,YC) in pixel coordinates\nC\nC THETA is the first guess for the position angle \nC (estimated with the maximum radius)\nC\nC*******************************************************************\n\tSUBROUTINE THETA_MIN_MAX(TMIN,TMAX,RMIN,RMAX,THETA,XC,YC) \n PARAMETER (MAXPOINTS=2000)\n\tREAL*8 Z(5),PI,TMIN,TMAX,XC,YC,RMIN,RMAX,THETA\n REAL*4 X1,Y1,R,DELTATHETA\n\tREAL*4 X,Y,TMIN1,TMAX1,TMIN2,TMAX2,THETA1,THETA2,TMID,TMAD\n\tINTEGER*4 NPOINT,IFLG\n\tCOMMON/FIT1/Z,NPOINT,IFLG\n\tCOMMON/BLOCKB/X(MAXPOINTS),Y(MAXPOINTS)\n \n\tPI=3.14159265358979323846D0\n\tRMIN=1.D10\n\tRMAX=0.D0\n\tTMIN1=2.1*PI\n\tTMIN2=TMIN1\n\tTMAX1=-2.1*PI\n\tTMAX2=TMAX1\n \nC Find the point on the contour which is furthest from the guess\nC at the centre.\n\tDO 2 I=1,NPOINT\n\tX1=X(I)-XC\n\tY1=Y(I)-YC\n\tR=SQRT(X1**2+Y1**2)\n\tTHETA1=ANGLE0(X1,Y1,R)\n\tTMIN1=AMIN1(THETA1,TMIN1)\n\tTMAX1=AMAX1(THETA1,TMAX1)\n \n\tTHETA2=THETA1-PI\n\tIF(THETA2.LT.0.)THETA2=THETA2+2*PI\n \n\tTMIN2=AMIN1(THETA2,TMIN2)\n\tTMAX2=AMAX1(THETA2,TMAX2)\n\n\tIF(RMIN.GT.R)RMIN=R\n\t IF(R.GT.RMAX) THEN\n\t RMAX=R\n\t THETA=THETA1\n\t ENDIF\n2\tCONTINUE\n \nC Test if DELTATHETA is larger than 340 degrees :\n\tDELTATHETA=TMAX1-TMIN1\n\tIF(DELTATHETA.GT.5.93)THEN\n\t TMIN=TMIN2-PI\n\t TMAX=TMAX2-PI\n\tELSE\n\t TMIN=TMIN1\n\t TMAX=TMAX1\n\tENDIF\n \n\tTMID=TMIN*180./PI\n\tTMAD=TMAX*180./PI\n\tWRITE(9,1001)TMID,TMAD\n1001\tFORMAT('THETA MIN, THETA MAX :',\n 1 2X,F8.3,2X,F8.3)\n \n\tRETURN\n\tEND\nC**********************************************************************\nC\nC ESTORE(K,1) : Major axis (pixels)\nC ESTORE(K,2) : Minor axis (pixels)\nC ESTORE(K,3) : Theta (radians)\nC ESTORE(K,4) : XC (pixels)\nC ESTORE(K,5) : YC (pixels)\nC ESTORE(K,6) : Error of major axis (pixels)\nC ESTORE(K,7) : Error of minor axis (pixels)\nC ESTORE(K,8) : Error of theta (radians)\nC ESTORE(K,9) : Error of XC (pixels)\nC ESTORE(K,10) : Error of YC (pixels)\nC**********************************************************************\n SUBROUTINE CONVERT_EFIT(K,MAJAX,RAD,ECC,XC,YC,THETA,\n 1 SMAJAX,SRAD,SECC,SXC,SYC,STH)\n REAL*4 ESTORE,FDATA,PI\n REAL*4 MAJAX,MINAX,RAD,ECC,XC,YC,THETA\n REAL*4 SMAJAX,SRAD,SECC,SXC,SYC,STH\n REAL*4 PCMAJ,PCMIN,PCRAD\n REAL*8 SCALE\n INTEGER*4 NEE\n\tCOMMON/EDATA/ ESTORE(200,10),FDATA(200,10),NEE\n\tCOMMON/BLOCKC/SCALE\n\n\tPI=3.14159265358979323846D0\n\t MAJAX=ESTORE(K,1)\n\t MINAX=ESTORE(K,2)\n\t THETA=ESTORE(K,3)\n\t XC=ESTORE(K,4)\n\t YC=ESTORE(K,5)\n\t SMJ=ESTORE(K,6)\n\t SMN=ESTORE(K,7)\n\t STH=ESTORE(K,8)*180./PI\n\t SXC=ESTORE(K,9)\n\t SYC=ESTORE(K,10)\n\n\t RAD=SQRT(MAJAX*MINAX)\n\t ECC=10.*(MAJAX-MINAX)/MAJAX\n\t PCMAJ=SMJ/MAJAX\n\t PCMIN=SMN/MINAX\n\t PCRAD=ABS(PCMAJ)+ABS(PCMIN)\n\t SRAD=0.5*RAD*PCRAD\n\t SECC=ECC*PCRAD\n \nC Conversion to arcseconds (Major axis and its error, Radius and its error) :\n MAJAX=MAJAX*SCALE\n SMAJAX=SMJ*SCALE\n RAD=RAD*SCALE\n SRAD=SRAD*SCALE\n\nC Conversion to degrees (Theta and its error)\n999 IF(THETA.LE.PI) GO TO 998\n THETA=THETA-PI\n GO TO 999\n998 IF(THETA.GT.0.) GO TO 997\n THETA=THETA+PI\n GO TO 998\n997 THETA=THETA*180./PI\n\n RETURN\n END\n", "meta": {"hexsha": "8d2c899903bbb5d851c3f86e415adda0cacd9008", "size": 25299, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "jlpsub/efit.for", "max_stars_repo_name": "jlprieur/shell_galaxies", "max_stars_repo_head_hexsha": "1dde87ef33b3c33b3a892e9ad0d642ae02ac6d9e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "jlpsub/efit.for", "max_issues_repo_name": "jlprieur/shell_galaxies", "max_issues_repo_head_hexsha": "1dde87ef33b3c33b3a892e9ad0d642ae02ac6d9e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "jlpsub/efit.for", "max_forks_repo_name": "jlprieur/shell_galaxies", "max_forks_repo_head_hexsha": "1dde87ef33b3c33b3a892e9ad0d642ae02ac6d9e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.5287588295, "max_line_length": 77, "alphanum_fraction": 0.6321593739, "num_tokens": 10540, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6746599489220021}} {"text": "MODULE LinearSolver\r\n \r\n USE FloatPrecision\r\n \r\n IMPLICIT NONE\r\n REAL(fp) , ALLOCATABLE , DIMENSION(:,:) :: AMT\r\n \r\n CONTAINS\r\n \r\n SUBROUTINE solve5(jc)\r\n USE FloatPrecision\r\n IMPLICIT NONE\r\n INTEGER :: jc\r\n INTEGER :: I , J\r\n REAL(fp) :: a\r\n\r\n DO I=3,jc\r\n a=amt(3,I-2)\r\n DO J=3,6\r\n amt(J,I-2)=amt(J,I-2)/a\r\n END DO\r\n a=-amt(2,I-1)\r\n amt(3,I-1)=amt(3,I-1)+amt(4,I-2)*a\r\n amt(4,I-1)=amt(4,I-1)+amt(5,I-2)*a\r\n amt(6,I-1)=amt(6,I-1)+amt(6,I-2)*a\r\n a=-amt(1,I)\r\n amt(2,I)=amt(2,I)+amt(4,I-2)*a\r\n amt(3,I)=amt(3,I)+amt(5,I-2)*a\r\n amt(6,I)=amt(6,I)+amt(6,I-2)*a\r\n END DO\r\n a=amt(3,jc-1)\r\n DO I=3,6\r\n amt(I,jc-1)=amt(I,jc-1)/a\r\n END DO\r\n a=-amt(2,jc)\r\n amt(3,jc)=amt(3,jc)+a*amt(4,jc-1)\r\n amt(6,jc)=(amt(6,jc)+a*amt(6,jc-1))/amt(3,jc)\r\n amt(6,jc-1)=amt(6,jc-1)-amt(4,jc-1)*amt(6,jc)\r\n DO I=jc-2,1,-1\r\n amt(6,I)=amt(6,I)-amt(4,I)*amt(6,I+1)-amt(5,I)*amt(6,I+2) \r\n END DO\r\n\r\n END\r\n\r\n SUBROUTINE Solve3_LU(jc)\r\n \r\n USE FloatPrecision\r\n IMPLICIT NONE\r\n INTEGER :: jc\r\n INTEGER :: I , J\r\n REAL(fp) :: temp\r\n \r\n DO J = 2 , jc\r\n temp = amt(1,J) / amt(2,J-1)\r\n amt(1,J) = temp\r\n amt(2,J) = amt(2,J) - temp * amt(3,J-1)\r\n END DO\r\n DO J = 2 , jc\r\n amt(4,J) = amt(4,J) - amt(4,J-1) * amt(1,J)\r\n END DO\r\n amt(4,jc) = amt(4,jc) / amt(2,jc)\r\n DO J = jc-1 , 1 , -1\r\n amt(4,J) = (amt(4,J) - amt(3,J)*amt(4,J+1)) / amt(2,J)\r\n END DO\r\n\r\n END SUBROUTINE solve3_LU\r\n\r\n SUBROUTINE SOLVE3(JC)\r\n USE FloatPrecision\r\n IMPLICIT NONE\r\n INTEGER :: JC\r\n INTEGER :: I , J\r\n REAL(fp) :: A\r\n\r\n DO I=2,JC\r\n A=AMT(2,I-1)\r\n DO J=2,4\r\n AMT(J,I-1)=AMT(J,I-1)/A\r\n END DO\r\n A=-AMT(1,I)\r\n AMT(2,I)=AMT(2,I)+AMT(3,I-1)*A\r\n AMT(4,I)=AMT(4,I)+AMT(4,I-1)*A\r\n END DO\r\n A=AMT(2,JC)\r\n DO J=2,4\r\n AMT(J,JC)=AMT(J,JC)/A\r\n END DO\r\n\r\n A=AMT(3,JC-1)\r\n DO I=JC-1,1,-1\r\n AMT(4,I)=AMT(4,I)-AMT(3,I)*AMT(4,I+1)\r\n END DO\r\n \r\n RETURN\r\n END SUBROUTINE SOLVE3\r\n \r\nEND MODULE LinearSolver", "meta": {"hexsha": "835a121d27bd1a00450072b720cad61ba2442fb0", "size": 2699, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "LinearSolver.f90", "max_stars_repo_name": "fanxuhhu/quasi-2d-model-for-tidal-channel", "max_stars_repo_head_hexsha": "547e0b5dfd1eafc436e920a67974166559e957b8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "LinearSolver.f90", "max_issues_repo_name": "fanxuhhu/quasi-2d-model-for-tidal-channel", "max_issues_repo_head_hexsha": "547e0b5dfd1eafc436e920a67974166559e957b8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "LinearSolver.f90", "max_forks_repo_name": "fanxuhhu/quasi-2d-model-for-tidal-channel", "max_forks_repo_head_hexsha": "547e0b5dfd1eafc436e920a67974166559e957b8", "max_forks_repo_licenses": ["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.824742268, "max_line_length": 80, "alphanum_fraction": 0.3682845498, "num_tokens": 952, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004185, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.674659948922002}} {"text": "\n program testme_omp\n USE OMP_LIB\n use AB_matrix_fct, only : multiply, RowConvert, ColumnConvert\n! only runs with banded matrix routines to allow for larger n \n IMPLICIT NONE\n INTEGER, PARAMETER :: wp = KIND(0.0D0) ! working precision\n INTEGER, PARAMETER :: n=90000 ! size of problem\n INTEGER, PARAMETER :: KU=358 ! bandwidth of matrix, KU=1 for dctsv.f90 KU>1 needs dcbsv.f90\n INTEGER, PARAMETER :: KL=0 ! for testing vs lapack version only\n ! KL=KU to run non-periodic version of matrix KL=0 runs periodic version\n REAL(wp), ALLOCATABLE :: d(:,:),a(:),b(:),c(:),s(:,:),dd(:,:),z(:,:),zz(:,:),a_short(:) ! a_short truncated a() for dgtsv \n REAL(wp), ALLOCATABLE :: AB(:,:),CD(:,:) ! AB(2*KU+1,n) for dcbsv; ! AB(KL+KU+1+i-j,j) for dgbsv \n ! CD(KL+KU+1+i-j,j) for dgbsv\n REAL(wp) :: time_end,time_start \n INTEGER :: i,j,k,p,INFO\n INTEGER, ALLOCATABLE :: ipiv(:)\n! Copyright (c) 2021 Anthony M de Beus\n\n! only runs tridiagonal routines dctsv.f90, dgtsv.f90 or thomas.f90 if KU=1\n! only runs non-periodic lapack routines dgbsv and/or dgtsv if KL > 0 (and in fact KL=KU) \n \n allocate(AB(2*KU+1,n),CD(2*KL+KU+1,n),d(n,2),a(n),b(n),c(n),s(n,2),dd(n,2),z(n,2),zz(n,2),a_short(n-1),ipiv(n))\n\n AB=0\n CD=0\n p=mod(N,2*KU)\n write(*,*) 'p,KU: ',p,KU\n\n do i=-KU,KU ! generate AB in band-cyclic format\n do j=1,n\n AB(i+KU+1,j)=20.0*(i)**2 + 5.*j/(1.0*n) ! without the second term, can be ill-conditioned, eg N=9, KU=2 \n if (i == 0) then\n AB(i+KU+1,j)=AB(i+KU+1,j)+300 ! emphasize diagonal dominance\n end if\n if (i >= KU) then\n AB(i+KU+1,j)=AB(i+KU+1,j)+1.5 ! asymmetry\n end if \n if (KL == KU) then\n if ((i+j-1) /= mod(N+i+j-1,N)) then\n AB(i+KU+1,j)=0 ! off diagonal elements zero for non-cyclic tests\n endif \n endif\n end do\n end do\n \n if (KL == KU .AND. KL > 0 ) then\n CD=ColumnConvert(AB) ! for LAPACK use make a dgbsv compatible matrix\n endif\n\n IF (N > 100) then \n do i=1,n\n s(i,1)=57.3*cos(40.0*i) ! solution vectors\n s(i,2)=10*sin(5.0*i) ! i and i**2 get too ill-conditioned with large n\n end do\n else\n do i=1,n\n s(i,1)=i ! solution vectors\n s(i,2)=i**2 \n end do\n endif \n \n dd=multiply(AB,s) ! RHS vectors\n d=dd\n \n IF (KU == 1) then ! store tridiagonal matrices in vector format\n a=AB(1,:)\n b=AB(2,:)\n c=AB(3,:)\n do i=1,n-1\n a_short(i)=a(i+1) !truncated \"a\" for dgtsv, don't have to truncate \"c\"\n end do\n\n write(*,*) 'Using dctsv.f90, O(n)' \n time_start=omp_get_wtime() ! have to use this to get actual time with omp\n call DCTSV( n, 2, a, b, c, d, n, INFO ) ! overwrites d into solution\n time_end=omp_get_wtime() \n write(*,*) 'time: ',time_end-time_start\n write(*,*) 'solution error',dot_product((s(:,1)-d(:,1)),(s(:,1)-d(:,1))) \n write(*,*) 'solution error',dot_product((s(:,2)-d(:,2)),(s(:,2)-d(:,2)))\n write(*,*) ' '\n\n\n! LAPACK routine for non-cyclic system \n if (KL > 0) then ! and KL == KU == 1 \n d=dd\n write(*,*) 'Using dgtsv, O(n)' \n time_start=omp_get_wtime()\n call DGTSV( n, 2, a_short, b, c, d, n, INFO ) ! overwrites d into solution\n time_end=omp_get_wtime() \n write(*,*) 'time: ',time_end-time_start\n write(*,*) 'solution error',dot_product((s(:,1)-d(:,1)),(s(:,1)-d(:,1))) \n write(*,*) 'solution error',dot_product((s(:,2)-d(:,2)),(s(:,2)-d(:,2)))\n write(*,*) ' '\n \n! simple tridiagonal algorithm: should be fastest with -O3 compilation\n a=AB(1,:)\n b=AB(2,:)\n c=AB(3,:)\n d=dd \n write(*,*) 'Using thomas, O(n)' \n time_start=omp_get_wtime()\n call thomas(a,b,c,d,z,n,2) ! overwrites b and d, output is z \n time_end=omp_get_wtime() \n write(*,*) 'time: ',time_end-time_start\n write(*,*) 'solution error',dot_product((s(:,1)-z(:,1)),(s(:,1)-z(:,1))) \n write(*,*) 'solution error',dot_product((s(:,2)-z(:,2)),(s(:,2)-z(:,2)))\n write(*,*) ' '\n \n endif\n\n ENDIF\n\n d=dd\n write(*,*) 'Using dcbsv.f90, O(n)'\n time_start=omp_get_wtime()\n call DCBSV( N, KU, 2, AB, 2*KU+1, d, N, INFO ) ! overwrites d\n time_end=omp_get_wtime() \n write(*,*) 'time: ',time_end-time_start\n write(*,*) 'solution error',dot_product((s(:,1)-d(:,1)),(s(:,1)-d(:,1))) \n write(*,*) 'solution error',dot_product((s(:,2)-d(:,2)),(s(:,2)-d(:,2)))\n z=multiply(AB,s(:,:))\n write(*,*) 'RHS error',dot_product(z(:,1)-dd(:,1),z(:,1)-dd(:,1)) \n write(*,*) 'RHS error',dot_product(z(:,2)-dd(:,2),z(:,2)-dd(:,2))\n write(*,*) ' '\n \n d=dd\n write(*,*) 'Using dcbsv_f.f90, O(n)'\n time_start=omp_get_wtime()\n call DCBSV_F( N, KU, 2, AB, 2*KU+1, d, N, INFO ) ! overwrites d\n time_end=omp_get_wtime() \n write(*,*) 'time: ',time_end-time_start\n write(*,*) 'solution error',dot_product((s(:,1)-d(:,1)),(s(:,1)-d(:,1))) \n write(*,*) 'solution error',dot_product((s(:,2)-d(:,2)),(s(:,2)-d(:,2)))\n z=multiply(AB,s(:,:))\n write(*,*) 'RHS error',dot_product(z(:,1)-dd(:,1),z(:,1)-dd(:,1)) \n write(*,*) 'RHS error',dot_product(z(:,2)-dd(:,2),z(:,2)-dd(:,2))\n write(*,*) ' '\n \n d=dd\n write(*,*) 'Using dcbsv_r.f90, O(n)'\n time_start=omp_get_wtime()\n call DCBSV_R( N, KU, 2, AB, 2*KU+1, d, N, INFO ) ! overwrites d\n time_end=omp_get_wtime() \n write(*,*) 'time: ',time_end-time_start\n write(*,*) 'solution error',dot_product((s(:,1)-d(:,1)),(s(:,1)-d(:,1))) \n write(*,*) 'solution error',dot_product((s(:,2)-d(:,2)),(s(:,2)-d(:,2)))\n z=multiply(AB,s(:,:))\n write(*,*) 'RHS error',dot_product(z(:,1)-dd(:,1),z(:,1)-dd(:,1)) \n write(*,*) 'RHS error',dot_product(z(:,2)-dd(:,2),z(:,2)-dd(:,2))\n write(*,*) ' '\n \n \n \n! zz=d ! save the solution\n! d=z-dd !RHS error\n! write(*,*) 'iterative step'\n! time_start=omp_get_wtime()\n! call DCBSV( N, KU, 2, AB, 2*KU+1, d, N, INFO ) ! overwrites dd\n! time_end=omp_get_wtime() \n! write(*,*) 'time: ',time_end-time_start \n! z=zz-d\n! write(*,*) 'solution error',dot_product((s(:,1)-z(:,1)),(s(:,1)-z(:,1))) \n! write(*,*) 'solution error',dot_product((s(:,2)-z(:,2)),(s(:,2)-z(:,2))) \n \n \n! LAPACK routine for non-cyclic system\n if (KL > 0) then \n d=dd \n write(*,*) 'Using dgbsv, O(n)' \n time_start=omp_get_wtime() \n call dgbsv( N, KL, KU, 2, CD, 2*KL+KU+1, IPIV, d, N, INFO ) ! overwrites d into solution\n time_end=omp_get_wtime() \n write(*,*) 'time: ',time_end-time_start\n write(*,*) 'solution error',dot_product((s(:,1)-d(:,1)),(s(:,1)-d(:,1))) \n write(*,*) 'solution error',dot_product((s(:,2)-d(:,2)),(s(:,2)-d(:,2)))\n endif\n \n deallocate(AB,CD,d,a,b,c,s,dd,z,a_short,ipiv)\n\n\n END PROGRAM testme_omp\n\n", "meta": {"hexsha": "645532e4c19fedd970322c486df96e44b29b3147", "size": 7304, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "testme_omp.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": "testme_omp.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": "testme_omp.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": 39.6956521739, "max_line_length": 129, "alphanum_fraction": 0.5073932092, "num_tokens": 2569, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648677, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6746508351585103}} {"text": "program main\r\n\timplicit none\r\n\treal(kind=8), parameter :: pi = 3.14159265358979\r\n\treal(kind=4) :: radius\r\n\twrite (*,\"(A)\") 'Please input the radius of a circle:'\r\n\tread (*,*) radius\r\n\twrite (*,\"(A, F0.8)\") 'The circle''s area is ', (pi*radius**2)\r\n\tstop\r\nend program main\r\n", "meta": {"hexsha": "ad085b424ff74a2d9ce26c2a6f56782e6bc9d68c", "size": 274, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "homework/chapter4/4_2/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/chapter4/4_2/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/chapter4/4_2/main.f90", "max_forks_repo_name": "hopeful0/fortran-study", "max_forks_repo_head_hexsha": "7bd50580436e747f428cefeda2ba595893867503", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.4, "max_line_length": 64, "alphanum_fraction": 0.6204379562, "num_tokens": 88, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8740772417253256, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6746508310474542}} {"text": "!====================================================================\n MODULE MOD_VARS\n!====================================================================\n INTEGER *8, PARAMETER :: MAXP = 100\n REAL*8, PARAMETER :: PI = 4*ATAN(1.D0)\n INTEGER *8 :: NOV, NTST, NSUB ! SETTINGS\n REAL *8 :: TIME, DT, TO ! TIME VARIABLES\n REAL *8 :: RKC1, RKC2, RKC3, RKC4 ! RK4 COEFFICIENTS\n REAL *8 :: TM, XM, YM ! RK4 INTERIM TIME & COORDINATES\n REAL *8 :: RKV1X, RKV2X, RKV3X, RKV4X ! RK4 VALUES FOR X\n REAL *8 :: RKV1Y, RKV2Y, RKV3Y, RKV4Y ! RK4 VALUES FOR Y\n\n REAL *8, DIMENSION(1:MAXP) :: POSX, XO\n REAL *8, DIMENSION(1:MAXP) :: POSY, YO\n REAL *8, DIMENSION(1:MAXP) :: GAM\n\n END MODULE MOD_VARS\n!====================================================================\n PROGRAM PROJECT_ONE\n!====================================================================\n USE MOD_VARS\n IMPLICIT NONE\n INTEGER *8 :: I, M, N\n\n !=== READ # OF VORTICES, INITIAL POSITION, GAMMA\n !=== SET # OF STEPS AND TIMESTEP\n CALL READ()\n\n TIME = 0.\n\n CALL RKINIT()\n\n !=== TIME-DEPENDENT CALCULATION\n DO M = 0, NTST\n\n !=== WRITE POSITION & VELOCITY\n IF (MOD(M,50)==0) THEN\n CALL WRITEHISTORY(M)\n ENDIF\n\n CALL STEPINIT()\n\n ! === RK4 CALCULATION FOR EACH VORTEX\n DO I = 1, NOV\n DO N = 1, NSUB\n CALL SUBSTEPINIT(I,N)\n CALL RK4_VAL(I,N)\n ENDDO\n !=== UPDATE POSITION\n CALL RK4_UPDATE(I)\n ENDDO\n ! =========================\n\n TIME = TIME + DT\n\n ENDDO\n\n CALL PRINT_CURRENT_TIME()\n\n STOP\n END PROGRAM PROJECT_ONE\n!====================================================================\n SUBROUTINE READ\n!====================================================================\n USE MOD_VARS\n IMPLICIT NONE\n CHARACTER*10 :: DUMMY\n INTEGER*8 :: N\n\n OPEN(10,FILE='input.in')\n READ(10,*) DUMMY\n READ(10,*) NOV\n READ(10,*) DUMMY\n DO N = 1, NOV\n READ(10,*) POSX(N), POSY(N), GAM(N)\n ENDDO\n READ(10,*) DUMMY\n READ(10,*) NTST, DT\n CLOSE(10)\n\n RETURN\n END SUBROUTINE READ\n!====================================================================\n SUBROUTINE RKINIT\n!====================================================================\n USE MOD_VARS\n IMPLICIT NONE\n\n ! USING CLASSIC RUNGE-KUTTA 4TH ORDER (RK4) METHOD\n RKC1 = 1./6.\n RKC2 = 1./3.\n RKC3 = 1./3.\n RKC4 = 1./6.\n\n NSUB = 4\n\n RETURN\n END SUBROUTINE RKINIT\n!====================================================================\n SUBROUTINE WRITEHISTORY(ST)\n!====================================================================\n USE MOD_VARS\n IMPLICIT NONE\n INTEGER *8 :: ST, I\n\n WRITE(*,*) 'STEP: ', ST, ' TIME: ', TIME\n\n OPEN(2000,FILE='history.dat',POSITION='APPEND')\n WRITE(2000,100,ADVANCE='NO') TIME\n DO I = 1, NOV\n IF (I .NE. NOV) THEN\n WRITE(2000,101,ADVANCE='NO') POSX(I), POSY(I)\n ELSE\n WRITE(2000,102) POSX(I), POSY(I)\n ENDIF\n ENDDO\n\n100 FORMAT(F12.4, ' ')\n101 FORMAT(F12.4, F12.4, ' ')\n102 FORMAT(F12.4, F12.4)\n\n CLOSE(2000)\n\n RETURN\n END SUBROUTINE WRITEHISTORY\n!====================================================================\n SUBROUTINE STEPINIT\n!====================================================================\n USE MOD_VARS\n IMPLICIT NONE\n\n TO = TIME\n XO = POSX\n YO = POSY\n\n RETURN\n END SUBROUTINE STEPINIT\n!====================================================================\n SUBROUTINE SUBSTEPINIT(II,SS)\n!====================================================================\n USE MOD_VARS\n IMPLICIT NONE\n INTEGER *8 :: II ! VORTEX INDEX\n INTEGER *8 :: SS ! RK4 SUBSTEP FROM 1 TO 4\n\n IF (SS .EQ. 1) THEN\n TM = TO\n XM = XO(II)\n YM = YO(II)\n ELSE IF (SS .EQ. 2) THEN\n TM = TO + .5*DT\n XM = XO(II) + .5*DT*RKV1X\n YM = YO(II) + .5*DT*RKV1Y\n ELSE IF (SS .EQ. 3) THEN\n TM = TO + .5*DT\n XM = XO(II) + .5*DT*RKV2X\n YM = YO(II) + .5*DT*RKV2Y\n ELSE IF (SS .EQ. 4) THEN\n TM = TO + DT\n XM = XO(II) + DT*RKV3X\n YM = YO(II) + DT*RKV3Y\n ELSE\n WRITE(*,*) 'ERROR: INVALID SUBSTEP (RK4)'\n STOP\n ENDIF\n\n RETURN\n END SUBROUTINE SUBSTEPINIT\n!====================================================================\n SUBROUTINE RK4_VAL(II, SS)\n!====================================================================\n USE MOD_VARS\n IMPLICIT NONE\n INTEGER *8 :: II ! VORTEX INDEX\n INTEGER *8 :: SS ! RK4 SUBSTEP FROM 1 TO 4\n INTEGER *8 :: I\n REAL *8 :: RKVX, RKVY\n\n RKVX = 0.\n RKVY = 0.\n DO I = 1, NOV\n IF (I .NE. II) THEN\n RKVX = RKVX + GAM(I)/(((XM-XO(I))**2.+(YM-YO(I))**2.)) &\n *(-(YM-YO(I)))\n RKVY = RKVY + GAM(I)/(((XM-XO(I))**2.+(YM-YO(I))**2.)) &\n *(XM-XO(I))\n ENDIF\n ENDDO\n\n IF (SS .EQ. 1) THEN\n RKV1X = RKVX\n RKV1Y = RKVY\n ELSE IF (SS .EQ. 2) THEN\n RKV2X = RKVX\n RKV2Y = RKVY\n ELSE IF (SS .EQ. 3) THEN\n RKV3X = RKVX\n RKV3Y = RKVY\n ELSE IF (SS .EQ. 4) THEN\n RKV4X = RKVX\n RKV4Y = RKVY\n ELSE\n WRITE(*,*) 'ERROR: INVALID SUBSTEP (RK4)'\n STOP\n ENDIF\n\n RETURN\n END SUBROUTINE RK4_VAL\n!====================================================================\n SUBROUTINE RK4_UPDATE(II)\n!====================================================================\n USE MOD_VARS\n IMPLICIT NONE\n INTEGER *8 :: II ! VORTEX INDEX\n\n POSX(II) = POSX(II) + DT*(RKC1*RKV1X+RKC2*RKV2X+RKC3*RKV3X+RKC4*RKV4X)\n POSY(II) = POSY(II) + DT*(RKC1*RKV1Y+RKC2*RKV2Y+RKC3*RKV3Y+RKC4*RKV4Y)\n\n RETURN\n END SUBROUTINE RK4_UPDATE\n!====================================================================\n SUBROUTINE RK4_STABILITY\n!====================================================================\n USE MOD_VARS\n IMPLICIT NONE\n\n RETURN\n END SUBROUTINE RK4_STABILITY\n!=======================================================================\n SUBROUTINE PRINT_CURRENT_TIME\n!=======================================================================\n IMPLICIT NONE\n CHARACTER*8 :: DATE\n CHARACTER*10:: NOW\n CHARACTER*5 :: ZONE\n INTEGER*8 :: VALS(8)\n\n CALL DATE_AND_TIME(DATE,NOW,ZONE,VALS)\n\n WRITE(*,101) VALS(1),VALS(2),VALS(3),VALS(5),VALS(6),VALS(7)\n WRITE(*,*) ''\n101 FORMAT(' @ 'I0.4,'-',I0.2,'-',I0.2,' ',I0.2,':',I0.2,':',I0.2)\n\n RETURN\n END SUBROUTINE PRINT_CURRENT_TIME\n!=======================================================================\n\n\n\n\n\n", "meta": {"hexsha": "e3e86e47d29450f16abee25acec0c987244790af", "size": 6824, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "project1.f90", "max_stars_repo_name": "jun9303/inviscid_vortex_system", "max_stars_repo_head_hexsha": "7120fef50eac84dc8cfec57c42ab14592a804b8f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "project1.f90", "max_issues_repo_name": "jun9303/inviscid_vortex_system", "max_issues_repo_head_hexsha": "7120fef50eac84dc8cfec57c42ab14592a804b8f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "project1.f90", "max_forks_repo_name": "jun9303/inviscid_vortex_system", "max_forks_repo_head_hexsha": "7120fef50eac84dc8cfec57c42ab14592a804b8f", "max_forks_repo_licenses": ["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.0793650794, "max_line_length": 74, "alphanum_fraction": 0.4003516999, "num_tokens": 2014, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772417253256, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6746508310474542}} {"text": "program arrays_01_real\nimplicit none\ninteger :: i, j\nreal(8) :: a(3), b(4), c(2, 2)\ndo i = 1, 3\n a(i) = i+10\nend do\nif (a(1) /= 11) error stop\nif (a(2) /= 12) error stop\nif (a(3) /= 13) error stop\n\ndo i = 11, 14\n b(i-10) = i\nend do\nif (b(1) /= 11) error stop\nif (b(2) /= 12) error stop\nif (b(3) /= 13) error stop\nif (b(4) /= 14) error stop\n\ndo i = 1, 3\n b(i) = a(i)-10\nend do\nif (b(1) /= 1) error stop\nif (b(2) /= 2) error stop\nif (b(3) /= 3) error stop\n\nb(4) = b(1)+b(2)+b(3)+a(1)\nif (b(4) /= 17) error stop\n\nb(4) = a(1)\nif (b(4) /= 11) error stop\n\ndo i = 1, 2\n do j = 1, 2\n c(i, j) = i + j + 10\n end do\nend do\nif (c(1, 1) /= 12) error stop\nif (c(1, 2) /= 13) error stop\nif (c(2, 1) /= 13) error stop\nif (c(2, 2) /= 14) error stop\nend\n", "meta": {"hexsha": "8d0d46522ff947ca83288ea74d8e3d7055bc79a8", "size": 758, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "integration_tests/arrays_01_real.f90", "max_stars_repo_name": "Thirumalai-Shaktivel/lfortran", "max_stars_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 316, "max_stars_repo_stars_event_min_datetime": "2019-03-24T16:23:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:28:33.000Z", "max_issues_repo_path": "integration_tests/arrays_01_real.f90", "max_issues_repo_name": "Thirumalai-Shaktivel/lfortran", "max_issues_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-07-29T04:58:03.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-04T16:40:06.000Z", "max_forks_repo_path": "integration_tests/arrays_01_real.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": 17.6279069767, "max_line_length": 30, "alphanum_fraction": 0.5105540897, "num_tokens": 391, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648677, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6746508305711589}} {"text": "subroutine fibber(a,b,c,d)\n ! compute most significant digits, Fibonacci like.\n implicit none\n integer (kind=8), intent(in) :: a,b\n integer (kind=8), intent(out) :: c,d\n d = a + b\n if (15 .lt. log10(float(d))) then\n c = b/10\n d = d/10\n else\n c = b\n endif\nend subroutine fibber\n\ninteger function leadingDigit(a)\n implicit none\n integer (kind=8), intent(in) :: a\n integer (kind=8) :: b\n b = a\n do while (9 .lt. b)\n b = b/10\n end do\n leadingDigit = transfer(b,leadingDigit)\nend function leadingDigit\n\nreal function benfordsLaw(a)\n implicit none\n integer, intent(in) :: a\n benfordsLaw = log10(1.0 + 1.0 / a)\nend function benfordsLaw\n\nprogram benford\n\n implicit none\n\n interface\n\n subroutine fibber(a,b,c,d)\n implicit none\n integer (kind=8), intent(in) :: a,b\n integer (kind=8), intent(out) :: c,d\n end subroutine fibber\n\n integer function leadingDigit(a)\n implicit none\n integer (kind=8), intent(in) :: a\n end function leadingDigit\n\n real function benfordsLaw(a)\n implicit none\n integer, intent(in) :: a\n end function benfordsLaw\n\n end interface\n\n integer (kind=8) :: a, b, c, d\n integer :: i, count(10)\n data count/10*0/\n a = 1\n b = 1\n do i = 1, 1001\n count(leadingDigit(a)) = count(leadingDigit(a)) + 1\n call fibber(a,b,c,d)\n a = c\n b = d\n end do\n write(6,*) (benfordsLaw(i),i=1,9),'THE LAW'\n write(6,*) (count(i)/1000.0 ,i=1,9),'LEADING FIBONACCI DIGIT'\nend program benford\n", "meta": {"hexsha": "1a504d43fc6bbb8bf03fe69da1a908f30fbba760", "size": 1480, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Benfords-law/Fortran/benfords-law-2.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Benfords-law/Fortran/benfords-law-2.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Benfords-law/Fortran/benfords-law-2.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 21.1428571429, "max_line_length": 63, "alphanum_fraction": 0.627027027, "num_tokens": 501, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772253241803, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6746508275630397}} {"text": "c*********SUBROUTINE\n\n subroutine floc(lw, l1, submat, lev, nf, nprobe, nsub, nlev, rcor)\nc\t input dimensions\n integer nf, nprobe, nsub, nlev\nc input\n\t double precision lw(nsub), l1(nsub,nf), submat(nsub,nprobe), \n * lev(nlev)\n\nc output\n double precision rcor(nprobe,nf)\nc variables\n integer i, j, ii, jj, k\n double precision qual(nsub), poicla(nlev), z(nlev)\n\nc initialize rcor\t\n do 10, ii = 1, nprobe\n do 11 jj = 1, nf\n rcor(ii,jj)=0\n11 continue\n10 continue\n\n do 100, ii = 1, nprobe\n\nc initialize qual\n do 101, j = 1, nsub\n qual(j)=submat(j, ii)\n101 continue\n\n\n do 110, jj = 1, nf\nc initialize and compute poicla\t\t\n do 112, k = 1, nlev \n poicla(k)=0\n112\t continue\n\n do 120, k = 1, nlev\n do 121, i = 1, nsub\n if(qual(i).eq.lev(k)) then\n poicla(k)=lw(i)+poicla(k)\n end if\n121 continue\n120 continue\n\nc initialize and compute z\n do 113, k = 1, nlev\n z(k)=0\n113 continue\n\n do 130, k = 1, nlev\n do 131, i = 1, nsub\n if(qual(i).eq.lev(k)) then\n z(k)=(l1(i, jj)*lw(i)+z(k))\n end if\n131\t continue\n130 continue\n\n do 140, k = 1, nlev\n if(poicla(k).gt.1e-12) then \n z(k)=z(k)/poicla(k)\n end if\n140 continue\n\n do 150, k = 1, nlev\n rcor(ii,jj)=rcor(ii,jj)+poicla(k) * z(k) * z(k)\n150 continue\n\n110 continue\n100 continue\n return\n end\n\t\nc\tprogram main\n\nc dimensions\t\nc\tinteger nf, nprobe, nsub, nlev\n\t\t\nc\tinput\nc\treal lw(285), l1(285,2), submat(285,830), lev(3)\n\nc\toutput\nc\treal rcor(830,2)\n\nc\tvariables\nc\tinteger i,j\n\nc\tdefine dimensions\nc\tnf=2 \nc\tnprobe=830\nc\tnsub=285\nc\tnlev=3\n\nc\tread input\nc\topen(8, file='lw.txt')\nc\t\tread(8,*) lw\nc\tclose(8)\n\t\nc\topen(9, file='l1.txt')\nc\t\tread(9,*) l1\nc\tclose(9)\n\t\nc\topen(10, file='submat.txt')\nc\t\tread(10,*) submat\nc\tclose(10)\n\t\nc\tlev(1)=-1\nc\tlev(2)=0\nc\tlev(3)=1\n\t\n\t\nc\tcall foc(lw, l1, submat, lev, nf, nprobe, nsub, nlev, rcor)\n\t\nc\tdo 99, i = 1, nprobe\nc\t\tprint *, (rcor(i,j),j=1,nf)\nc99\tcontinue\n\nc\tstop\nc\tend", "meta": {"hexsha": "3fdca6567d2176087a801562576a9a7a68ab4f72", "size": 2341, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/floc.f", "max_stars_repo_name": "isglobal-brge/R-GADA", "max_stars_repo_head_hexsha": "5ec5b5eb1f7da4b946d795425cec02c196f33245", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-01-21T09:02:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-20T06:22:07.000Z", "max_issues_repo_path": "src/floc.f", "max_issues_repo_name": "isglobal-brge/R-GADA", "max_issues_repo_head_hexsha": "5ec5b5eb1f7da4b946d795425cec02c196f33245", "max_issues_repo_licenses": ["MIT"], "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/floc.f", "max_forks_repo_name": "isglobal-brge/R-GADA", "max_forks_repo_head_hexsha": "5ec5b5eb1f7da4b946d795425cec02c196f33245", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-01-22T14:23:05.000Z", "max_forks_repo_forks_event_max_datetime": "2019-01-22T14:23:05.000Z", "avg_line_length": 19.8389830508, "max_line_length": 72, "alphanum_fraction": 0.5053395985, "num_tokens": 818, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297967961706, "lm_q2_score": 0.7490872187162397, "lm_q1q2_score": 0.674575360853144}} {"text": " subroutine zone_setup(nx, nxmax, ny, nz)\n\n include 'header.h'\n include 'omp_stuff.h'\n\n integer nx(*), nxmax(*), ny(*), nz(*)\n\n integer i, j, zone_no\n integer id_west, id_east, jd_south, jd_north\n double precision x_r, y_r, x_smallest, y_smallest\n\n if (dabs(ratio-1.d0) .gt. 1.d-10) then\n\nc compute zone stretching only if the prescribed zone size ratio \nc is substantially larger than unity \n\n x_r = dexp(dlog(ratio)/(x_zones-1))\n y_r = dexp(dlog(ratio)/(y_zones-1))\n x_smallest = dble(gx_size)*(x_r-1.d0)/(x_r**x_zones-1.d0)\n y_smallest = dble(gy_size)*(y_r-1.d0)/(y_r**y_zones-1.d0)\n\nc compute tops of intervals, using a slightly tricked rounding\nc to make sure that the intervals are increasing monotonically\nc in size\n\n do i = 1, x_zones\n x_end(i) = x_smallest*(x_r**i-1.d0)/(x_r-1.d0)+0.45d0\n end do\n\n do j = 1, y_zones\n y_end(j) = y_smallest*(y_r**j-1.d0)/(y_r-1.d0)+0.45d0\n end do\n \n else\n\nc compute essentially equal sized zone dimensions\n\n do i = 1, x_zones\n x_end(i) = (i*gx_size)/x_zones\n end do\n\n do j = 1, y_zones\n y_end(j) = (j*gy_size)/y_zones\n end do\n\n endif\n\n x_start(1) = 1\n do i = 1, x_zones\n if (i .ne. x_zones) x_start(i+1) = x_end(i) + 1\n x_size(i) = x_end(i) - x_start(i) + 1\n end do\n\n y_start(1) = 1\n do j = 1, y_zones\n if (j .ne. y_zones) y_start(j+1) = y_end(j) + 1\n y_size(j) = y_end(j) - y_start(j) + 1\n end do\n\n if (npb_verbose .gt. 1) write (*,98)\n 98 format(/' Zone sizes:')\n\n do j = 1, y_zones\n do i = 1, x_zones\n zone_no = (i-1)+(j-1)*x_zones+1\n nx(zone_no) = x_size(i)\n nxmax(zone_no) = nx(zone_no) + 1 - mod(nx(zone_no),2)\n ny(zone_no) = y_size(j)\n nz(zone_no) = gz_size\n\n id_west = mod(i-2+x_zones,x_zones)\n id_east = mod(i, x_zones)\n jd_south = mod(j-2+y_zones,y_zones)\n jd_north = mod(j, y_zones)\n iz_west (zone_no) = id_west + (j-1)*x_zones + 1\n iz_east (zone_no) = id_east + (j-1)*x_zones + 1\n iz_south(zone_no) = (i-1) + jd_south*x_zones + 1\n iz_north(zone_no) = (i-1) + jd_north*x_zones + 1\n\n if (npb_verbose .gt. 1) then\n write (*,99) zone_no, nx(zone_no), ny(zone_no), \n $ nz(zone_no)\n endif\n end do\n end do\n\n 99 format(i5,': ',i5,' x',i5,' x',i5)\n\n return\n end\n\n\n subroutine zone_starts(num_zones, nx, nxmax, ny, nz)\n\n include 'header.h'\n include 'omp_stuff.h'\n\n integer num_zones\n integer nx(*), nxmax(*), ny(*), nz(*)\n\n integer zone, zone_size\n integer x_face_size, y_face_size\n\nc ... index start for u & qbc\n do zone = 1, num_zones\n zone_size = nxmax(zone)*ny(zone)*nz(zone)\n x_face_size = (ny(zone)-2)*(nz(zone)-2)*5\n y_face_size = (nx(zone)-2)*(nz(zone)-2)*5\n\n if (zone .eq. 1) then\n qstart_west(zone) = 1\n start1(zone) = 1\n start5(zone) = 1\n endif\n qstart_east(zone) = qstart_west(zone) + x_face_size\n qstart_south(zone) = qstart_east(zone) + x_face_size\n qstart_north(zone) = qstart_south(zone)+ y_face_size\n if (zone .ne. num_zones) then\n qstart_west(zone+1) = qstart_north(zone) +\n $ y_face_size\n start1(zone+1) = start1(zone) + zone_size\n start5(zone+1) = start5(zone) + zone_size*5\n else\n if (start1(zone)+zone_size-1 .gt. proc_max_size) then\n write(*,50) zone,proc_max_size,start1(zone)+zone_size-1\n stop\n endif\n endif\n 50 format(' Error in size: zone',i5,' proc_max_size',i10,\n & ' access_size',i10)\n enddo\n\n if (npb_verbose .gt. 1) then\n do zone = 1, num_zones\n write(*,10) zone,start1(zone),start5(zone)\n enddo\n endif\n 10 format(' zone=',i5,' start1=',i10,' start5=',i10)\n\n return\n end\n", "meta": {"hexsha": "49bdd6da66be01e1c56345fed1c6db01c22258d6", "size": 4352, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Benchmarks/LU-MZ/NPB3.3-MZ-OMP/LU-MZ/zone_setup.f", "max_stars_repo_name": "jcm300/NAS-Parallel-Benchmarks-Profilling", "max_stars_repo_head_hexsha": "a94e52f9a1cb30b2f4668e08d90ca637ebee264c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Benchmarks/LU-MZ/NPB3.3-MZ-OMP/LU-MZ/zone_setup.f", "max_issues_repo_name": "jcm300/NAS-Parallel-Benchmarks-Profilling", "max_issues_repo_head_hexsha": "a94e52f9a1cb30b2f4668e08d90ca637ebee264c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Benchmarks/LU-MZ/NPB3.3-MZ-OMP/LU-MZ/zone_setup.f", "max_forks_repo_name": "jcm300/NAS-Parallel-Benchmarks-Profilling", "max_forks_repo_head_hexsha": "a94e52f9a1cb30b2f4668e08d90ca637ebee264c", "max_forks_repo_licenses": ["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.6478873239, "max_line_length": 72, "alphanum_fraction": 0.5153952206, "num_tokens": 1379, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297754396142, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.674575339810892}} {"text": " REAL FUNCTION D2BUBF(RLAT)\nC\nC SPECIFIES FUNCTIONAL FORM OF 2ND DERIVATIVE OF BIG U BAR (BUBFNC)\nC (USED FOR FORCED CASE ICOND = 4)\nC\nC CALLED BY: FORCE\nC CALLS: \nC\nC REVISIONS:\nC 7-10-92 CHANGE TO CCM CODING CONVENTIONS (R. JAKOB)\nC\nC---- Common Blocks ----------------------------------------------------\nC\nC Case 4 variables\n INCLUDE 'case4.i'\nC\nC------------ Arguments ------------------------------------------------\nC\nC Input\nC\nC LATITUDE\n REAL RLAT\nC\nC------ Local Variables ------------------------------------------------\nC\n REAL RMU,COSLAT\nC\nC----- Executable Statements -------------------------------------------\nC\n RMU = SIN(RLAT)\n COSLAT = COS(RLAT)\n D2BUBF = 8.0*SU0*(2.0*RMU*COSLAT)**(NPWR-3)*RMU*\n $ (REAL((NPWR-1)*NPWR)+RMU*RMU*(REAL(NPWR-1)-\n $ REAL(2*NPWR*(2*NPWR+1))*COSLAT*COSLAT))\nC \n RETURN \n END \n", "meta": {"hexsha": "4e0adf25a5824bd996c4ad1ddb86a5f267fa09a2", "size": 1118, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/d2bubf.f", "max_stars_repo_name": "jhaoli/shallow_spectral", "max_stars_repo_head_hexsha": "a2580f9baad596a56efaaae20b80e1bd543c2502", "max_stars_repo_licenses": ["NetCDF"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-06-19T02:24:41.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-19T02:24:41.000Z", "max_issues_repo_path": "src/d2bubf.f", "max_issues_repo_name": "jhaoli/shallow_spectral", "max_issues_repo_head_hexsha": "a2580f9baad596a56efaaae20b80e1bd543c2502", "max_issues_repo_licenses": ["NetCDF"], "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/d2bubf.f", "max_forks_repo_name": "jhaoli/shallow_spectral", "max_forks_repo_head_hexsha": "a2580f9baad596a56efaaae20b80e1bd543c2502", "max_forks_repo_licenses": ["NetCDF"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.4210526316, "max_line_length": 80, "alphanum_fraction": 0.3783542039, "num_tokens": 285, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.930458253565792, "lm_q2_score": 0.7248702702332475, "lm_q1q2_score": 0.6744615257029911}} {"text": "! { dg-do run }\n! { dg-require-effective-target fortran_large_real }\n! Program to test the UNPACK intrinsic for large real type\nprogram intrinsic_unpack\n implicit none\n integer,parameter :: k = selected_real_kind (precision (0.0_8) + 1)\n\n real(kind=k), dimension(3,3) :: ark, brk\n complex(kind=k), dimension(3,3) :: ack, bck\n\n logical, dimension(3, 3) :: mask\n character(len=500) line1, line2\n integer i\n\n mask = reshape ((/.false.,.true.,.false.,.true.,.false.,.false.,&\n &.false.,.false.,.true./), (/3, 3/));\n\n ark = reshape ((/1._k, 0._k, 0._k, 0._k, 1._k, 0._k, 0._k, 0._k, 1._k/), &\n (/3, 3/));\n brk = unpack ((/2._k, 3._k, 4._k/), mask, ark)\n if (any (brk .ne. reshape ((/1._k, 2._k, 0._k, 3._k, 1._k, 0._k, &\n 0._k, 0._k, 4._k/), (/3, 3/)))) &\n STOP 1\n write (line1,'(9F9.5)') brk\n write (line2,'(9F9.5)') unpack((/2._k, 3._k, 4._k/), mask, ark)\n if (line1 .ne. line2) STOP 2\n brk = -1._k\n brk = unpack ((/2._k, 3._k, 4._k/), mask, 0._k)\n if (any (brk .ne. reshape ((/0._k, 2._k, 0._k, 3._k, 0._k, 0._k, &\n 0._k, 0._k, 4._k/), (/3, 3/)))) &\n STOP 3\n\n ack = reshape ((/1._k, 0._k, 0._k, 0._k, 1._k, 0._k, 0._k, 0._k, 1._k/), &\n (/3, 3/));\n bck = unpack ((/(2._k, 0._k), (3._k, 0._k), (4._k, 0._k)/), mask, ack)\n if (any (real(bck) .ne. reshape ((/1._k, 2._k, 0._k, 3._k, 1._k, 0._k, &\n 0._k, 0._k, 4._k/), (/3, 3/)))) &\n STOP 4\n write (line1,'(18F9.5)') bck\n write (line2,'(18F9.5)') unpack((/(2._k, 0._k), (3._k, 0._k), (4._k,0._k)/), &\n mask, ack)\n if (line1 .ne. line2) STOP 5\n\nend program\n", "meta": {"hexsha": "6b0187085db367948993f594e36ec35460705c2a", "size": 1647, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/intrinsic_unpack_2.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/intrinsic_unpack_2.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/intrinsic_unpack_2.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": 36.6, "max_line_length": 81, "alphanum_fraction": 0.5069823922, "num_tokens": 770, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569016, "lm_q2_score": 0.8397339736884711, "lm_q1q2_score": 0.6744523235772358}} {"text": "c gmm01f\r\nc gxurcd0.f to compute Gaunt coefficients a(-m,n,m,v,p)\r\nc THIS FILE IS PART OF THE ORIGINAL GMM01F DISTRIBUTION\r\ncu uses lnfacd.f to compute ln(z!)\r\n subroutine gxurcd0(m,n,v,qmax,na)\r\n implicit double precision (a-h,o-z)\r\n include 'gmm01f.par'\r\n parameter (ng0=np*(2*np**3+10*np**2+19*np+5)/6)\r\n integer v,qmax,p\r\n double precision lnfacd,cnv(np,np),ga0(ng0)\r\n common/cfnv/cnv\r\n common/g0/ga0\r\n fb(n,v,p)=dble(p-(n+v+1))*dble(p+(n+v+1))\r\n + *dble(p-(n-v))*dble(p+(n-v))\r\n + /(dble(2*p+1)*dble(2*p-1))\r\n if(iabs(m).gt.n.or.iabs(m).gt.v) then\r\n write(6,*) 'warning: |m|>n or v in gxurcd0'\r\n qmax=-1\r\n return\r\n endif\r\n qmax=min(n,v)\r\n nq=qmax+1\r\n if(n.le.v) then\r\n c1=cnv(n,v)\r\n else\r\n c1=cnv(v,n)\r\n endif\r\n c1=c1-lnfacd(dble(n-m))-lnfacd(dble(v+m))\r\n ga0(na+1)=dexp(c1)\r\n if(qmax.lt.1) return\r\n p=n+v\r\n do 8 i=2,nq\r\n p=p-2\r\n if(m.eq.0) then\r\n c1=fb(n,v,p+1)\r\n c2=fb(n,v,p+2)\r\n goto 2\r\n endif\r\n c1=fb(n,v,p+1)\r\n c2=dble(4*m*m)+fb(n,v,p+2)+fb(n,v,p+3)\r\n if(i.eq.2) goto 2\r\n c3=-fb(n,v,p+4)\r\n goto 4\r\n 2\t ga0(na+i)=c2*ga0(na+i-1)/c1\r\n goto 8\r\n 4\t ga0(na+i)=(c2*ga0(na+i-1)+c3*ga0(na+i-2))/c1\r\n 8 continue\r\n return\r\n end\r\n \r\n subroutine gid0(nmax,m,n,iv,id)\r\n nt=nmax*(nmax+1)*(2*nmax+1)/3+nmax*nmax\r\n ns=max(1,iabs(m))\r\n nc0=nmax-iabs(m)\r\n id=nc0*(nc0+1)*(2*nc0+1)/6\r\n if(m) 10,11,12\r\n 10\t id=id+(n-ns)*(nc0+1)+iv-ns+1\r\n return\r\n 11\t id=id+(n-ns)*nmax+iv\r\n return\r\n 12\t id=id+(nmax-n)*(nc0+1)+nmax-iv\r\n id=nt-id\r\n return\r\n end\r\n\r\n", "meta": {"hexsha": "0d432c200ade3489111ba98dd4d8f9294a28c1dc", "size": 1807, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "GMM_FIELD/src/gxurcd0.f", "max_stars_repo_name": "m-ringler/GMM-DIP", "max_stars_repo_head_hexsha": "016a4ca0ecf50c9d665cc17fb209031d0093c9a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "GMM_FIELD/src/gxurcd0.f", "max_issues_repo_name": "m-ringler/GMM-DIP", "max_issues_repo_head_hexsha": "016a4ca0ecf50c9d665cc17fb209031d0093c9a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "GMM_FIELD/src/gxurcd0.f", "max_forks_repo_name": "m-ringler/GMM-DIP", "max_forks_repo_head_hexsha": "016a4ca0ecf50c9d665cc17fb209031d0093c9a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-11-06T14:43:40.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-07T12:05:00.000Z", "avg_line_length": 27.3787878788, "max_line_length": 57, "alphanum_fraction": 0.473713337, "num_tokens": 712, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111796979521253, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6744318464122172}} {"text": "module functions\n contains\n \nsubroutine spaceevenly(start, finish, number, arrayout)\n implicit none\n \n integer, intent(in) :: start, finish\n real(kind=8), intent(in) :: number\n real(kind=8) :: div\n real(kind=8), dimension(0:finish), intent(out) :: arrayout\n integer :: i\n \n div = number / ((finish-1) - (start-1))\n \n do i=start, finish\n arrayout(i) = div * i\n end do\n\nend subroutine spaceevenly\n \nsubroutine diffuse(timesteps, u, nu, dt, dx, dy, nx, ny)\n implicit none\n integer, intent(in) :: nx, ny, timesteps\n real(kind=8), intent(in) :: nu, dt, dx, dy\n real(kind=8), intent(out), dimension(nx,ny) :: u\n real(kind=8), dimension(nx,ny) :: un\n integer :: i, j, time\n real(kind=8) :: Ydisip, Xdisip, Yderiv, Xderiv\n time = timesteps\n\n do time = 1, time\n un = u\n \n do j=2, nx-1\n do i=2, ny-1\n Xderiv = (nu * dt) / (dx**2)\n Yderiv = (nu * dt) / (dy**2)\n Xdisip = un(j,i+1) - (2 * un(j,i)) + un(j,i-1)\n Ydisip = un(j+1,i) - (2 * un(j,i)) + un(j-1,i)\n \n u(j,i) = un(j,i) + (Xderiv * Xdisip) + (Yderiv * Ydisip)\n\n u(1,j) = 1\n u(nx,j) = 1\n u(i,1) = 1\n u(i,ny) = 1\n \n u(1,1) = 1\n u(1,nx) = 1\n u(ny,1) = 1\n u(ny,nx) = 1\n end do\n end do\n end do\nend subroutine \n\nend module functions", "meta": {"hexsha": "2aa6b2d8fbf89a10fc3553d3351fd0790a89e64c", "size": 1601, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "l5/functions.f90", "max_stars_repo_name": "dominique120/12-steps-navier-stokes", "max_stars_repo_head_hexsha": "3e195bf7f7895f83f5f2248ef48dc13b76e8b5de", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "l5/functions.f90", "max_issues_repo_name": "dominique120/12-steps-navier-stokes", "max_issues_repo_head_hexsha": "3e195bf7f7895f83f5f2248ef48dc13b76e8b5de", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "l5/functions.f90", "max_forks_repo_name": "dominique120/12-steps-navier-stokes", "max_forks_repo_head_hexsha": "3e195bf7f7895f83f5f2248ef48dc13b76e8b5de", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.0877192982, "max_line_length": 76, "alphanum_fraction": 0.4372267333, "num_tokens": 493, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009480320035, "lm_q2_score": 0.7371581568543043, "lm_q1q2_score": 0.6744266965555273}} {"text": "Function ftot(x)\n Common /hparnt/hipr1(100), ihpr2(50), hint1(100), ihnt2(50)\n Save\n omg = omg0(x)*(hipr1(30)+hint1(11))/hipr1(31)/2.0\n ftot = 2.0*(1.0-exp(-omg))\n Return\nEnd Function ftot\n", "meta": {"hexsha": "2f7fbecdcb79d0fd7e73f3977f44f10de2c4412e", "size": 194, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/ftot.f90", "max_stars_repo_name": "xiaohaijin/AMPT", "max_stars_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-12-24T19:37:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-14T12:58:59.000Z", "max_issues_repo_path": "src/ftot.f90", "max_issues_repo_name": "xiaohaijin/AMPT", "max_issues_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_issues_repo_licenses": ["MIT"], "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/ftot.f90", "max_forks_repo_name": "xiaohaijin/AMPT", "max_forks_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_forks_repo_licenses": ["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.25, "max_line_length": 61, "alphanum_fraction": 0.6443298969, "num_tokens": 93, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951661947456, "lm_q2_score": 0.7217432182679956, "lm_q1q2_score": 0.6743933743834543}} {"text": "Module Laguerre\n Use nrtype\n\ncontains\n\nsubroutine Laguerre_Fast(Temp,xl_n,xl_m,sigmaBH)\n\n Implicit none\n\n Integer(I4B) :: NP=5\n Integer(I4B) :: i, j, n\n\n Real(DP) :: Temp,xl_n,xl_m,sigmaBH \n Real(DP) :: u(5),w(5),x(5),func(5)\n Real(DP) :: CMie, theta\n Intent(IN) :: Temp,xl_n,xl_m\n Intent(OUT) :: sigmaBH\n\n\n u(1) = 0.26356031971814109102031d0\n u(2) = 1.41340305910651679221800d0\n u(3) = 3.59642577104072208122300d0\n u(4) = 7.08581000585883755692200d0\n u(5) = 12.64080084427578265943000d0\n\n w(1) = 0.5217556105828086524759d0\n w(2) = 0.3986668110831759274500d0\n w(3) = 7.5942449681707595390000d-2\n w(4) = 3.6117586799220484545000d-3\n w(5) = 2.3369972385776227891000d-5\n\n CMie = (xl_n/(xl_n-xl_m))*(xl_n/xl_m)**(xl_m/(xl_n-xl_m))\n theta = CMie / Temp\n\n ! roots and weights of the laguerre polynomial of order n\n\n\n ! calculation of sigmaBH using the gauss laguerre formula\n sigmaBH = ZERO\n\n do i=1,5\n x(i) = (theta / (u(i)+theta))**(ONE/xl_n)\n func(i) = x(i)*exp(theta*(ONE/x(i)**xl_m-ONE))/(u(i)+theta)\n\n sigmaBH = sigmaBH + w(i)*func(i)/xl_n\n\n end do\n\n sigmaBH = ONE - sigmaBH\nend subroutine Laguerre_Fast\nEnd Module Laguerre", "meta": {"hexsha": "4615a74ce5157525b733003cdf2bde4e1aa907db", "size": 1394, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Laguerre_fast.f90", "max_stars_repo_name": "skourno/dielectric_AMMF", "max_stars_repo_head_hexsha": "610ef5ac762f83b9272719c0f952fc01a0d9deb1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Laguerre_fast.f90", "max_issues_repo_name": "skourno/dielectric_AMMF", "max_issues_repo_head_hexsha": "610ef5ac762f83b9272719c0f952fc01a0d9deb1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Laguerre_fast.f90", "max_forks_repo_name": "skourno/dielectric_AMMF", "max_forks_repo_head_hexsha": "610ef5ac762f83b9272719c0f952fc01a0d9deb1", "max_forks_repo_licenses": ["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.3333333333, "max_line_length": 71, "alphanum_fraction": 0.56241033, "num_tokens": 525, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951607140232, "lm_q2_score": 0.7217432003123989, "lm_q1q2_score": 0.6743933536501574}} {"text": " FUNCTION CSEDTAUB(DENBULK,TDUM,V1,V2,V3,IOPT) \nC \nC CHANGE RECORD \nC\nC \nC ** CALCULATES CRITIAL STRESS FOR BULK OR MASS EROSION OF COHESIVE \nC ** SEDIMENT AS A FUNCTION OF BED BULK DENSITY \nC ** IOPT=1 BASED ON \nC ** \nC ** HWANG, K. N., AND A. J. MEHTA, 1989: FINE SEDIMENT DRODIBILITY \nC ** IN LAKE OKEECHOBEE FLORIDA. COASTAL AND OCEANOGRAPHIC ENGINEERING \nC ** DEPARTMENT, UNIVERSITY OF FLORIDA, GAINESVILLE, FL32661 \nC ** IOPT=2 BASED ON \nC ** \nC ** HWANG, K. N., AND A. J. MEHTA, 1989: FINE SEDIMENT DRODIBILITY \nC ** IN LAKE OKEECHOBEE FLORIDA. COASTAL AND OCEANOGRAPHIC ENGINEERING \nC ** DEPARTMENT, UNIVERSITY OF FLORIDA, GAINESVILLE, FL32661 \nC \n IF(IOPT.EQ.1)THEN \n BULKDEN=0.001*DENBULK ! *** PMC Changed to prevent \n IF(BULKDEN.LE.1.013)THEN \n CSEDTAUB=0.0 \n ELSE \n CSEDTAUB=0.001*(9.808*BULKDEN-9.934) \n ENDIF \n ELSEIF(IOPT.EQ.2)THEN \n BULKDEN=0.001*DENBULK ! *** PMC Changed to prevent \n IF(BULKDEN.LE.1.013)THEN \n CSEDTAUB=0.0 \n ELSE \n CSEDTAUB=0.001*(9.808*BULKDEN-9.934) \n ENDIF \n ELSE\n STOP 'CSEDTAUB: BAD SEDIMENT CRITICAL STRESS OPTION! STOPPING!'\n ENDIF \nC\n RETURN \n END \n\n", "meta": {"hexsha": "f8327cb0293fe91692693578e7d536fd1ce8a43d", "size": 1275, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "EFDC_src/CSEDTAUB.f", "max_stars_repo_name": "T-Carlotto/SW2D-EFDC", "max_stars_repo_head_hexsha": "7b01a41a308cb79db569a0e6291fe40797f3ef28", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 32, "max_stars_repo_stars_event_min_datetime": "2018-03-31T22:19:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-14T01:35:23.000Z", "max_issues_repo_path": "EFDC_src/CSEDTAUB.f", "max_issues_repo_name": "T-Carlotto/SW2D-EFDC", "max_issues_repo_head_hexsha": "7b01a41a308cb79db569a0e6291fe40797f3ef28", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-04-02T06:13:13.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-10T07:15:07.000Z", "max_forks_repo_path": "EFDC_src/CSEDTAUB.f", "max_forks_repo_name": "T-Carlotto/SW2D-EFDC", "max_forks_repo_head_hexsha": "7b01a41a308cb79db569a0e6291fe40797f3ef28", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2018-06-27T02:55:23.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-09T07:51:23.000Z", "avg_line_length": 31.875, "max_line_length": 73, "alphanum_fraction": 0.6101960784, "num_tokens": 478, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422241476943, "lm_q2_score": 0.7090191337850932, "lm_q1q2_score": 0.6743780358716251}} {"text": "\n SUBROUTINE MOV_PROB(M1,M4,pNmin,pNmax\n $ ,A,PDF,SCALAR,qwcell,qwbin)\n\tinteger qwcell, qwbin\n real A(qwcell), PDF(qwbin),SCALAR(qwbin)\n\treal pNmin, pNmax\n\n NBIN=60\n DO K=1,NBIN\n PDF(K)=0.\n END DO\nc\nc PDFAREA: the total area of PDF\nc JJ: locate the A(K) into approciate bin #\nc pNmin: min. of scalar value\nc pNmax: max. of scalar value\nc\n pNlength=pNmax-pNmin\n PDFAREA=0.\n DO K=M1,M4\n JJ=INT(NBIN*((A(K)-pNmin)/pNlength))+1\n if(jj.gt.NBIN.or. jj.le.0)then\n write(6,*)'mov_prob.f jj,a(k)=',jj,a(k)\nCcall flush(6)\n JJ=NBIN\n endif\nc\nc accumulate the count # at each interval of JJ\nc\n PDF(JJ)=PDF(JJ)+1.\n END DO\nc\nc calculate the total PDFAREA\nc\n DDX=(pNlength)/float(NBIN)\n DO K=1,NBIN\n PDFAREA=PDFAREA+PDF(K)*DDX\n END DO\nc\nc normlaized the PDF and calculate the real scalar\nc value at each bin#\nc\n DO K=1,NBIN+1\n PDF(K)=PDF(K)/PDFAREA\n SCALAR(K)=(K-1.)*DDX+pNmin\n END DO\n\n RETURN\n END\n\n", "meta": {"hexsha": "b5f9fe2939f3df75b2e11541bd992513f17bd024", "size": 1134, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/mov_prob.f", "max_stars_repo_name": "phaustin/empm", "max_stars_repo_head_hexsha": "13bbb7c6568e374c973ea570b064f34a48c6cd8e", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/mov_prob.f", "max_issues_repo_name": "phaustin/empm", "max_issues_repo_head_hexsha": "13bbb7c6568e374c973ea570b064f34a48c6cd8e", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/mov_prob.f", "max_forks_repo_name": "phaustin/empm", "max_forks_repo_head_hexsha": "13bbb7c6568e374c973ea570b064f34a48c6cd8e", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2015-08-24T14:59:46.000Z", "max_forks_repo_forks_event_max_datetime": "2015-08-24T14:59:46.000Z", "avg_line_length": 22.2352941176, "max_line_length": 56, "alphanum_fraction": 0.5423280423, "num_tokens": 398, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094088947399, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6743726656101884}} {"text": "C$Procedure PLTNRM ( DSK, compute outward normal of plate )\n \n SUBROUTINE PLTNRM ( V1, V2, V3, NORMAL )\n\nC$ Abstract\nC\nC Compute an outward normal vector of a triangular plate.\nC The vector does not necessarily have unit length.\nC\nC$ Disclaimer\nC\nC THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE\nC CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.\nC GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE\nC ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE\nC PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED \"AS-IS\"\nC TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY\nC WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A\nC PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC\nC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE\nC SOFTWARE AND RELATED MATERIALS, HOWEVER USED.\nC\nC IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA\nC BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT\nC LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,\nC INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,\nC REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE\nC REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.\nC\nC RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF\nC THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY\nC CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE\nC ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.\nC\nC$ Required_Reading\nC\nC DSK\nC\nC$ Keywords\nC\nC DSK\nC FILES\nC TOPOGRAPHY\nC \nC$ Declarations\n\n IMPLICIT NONE\n\n DOUBLE PRECISION V1 ( 3 )\n DOUBLE PRECISION V2 ( 3 )\n DOUBLE PRECISION V3 ( 3 )\n DOUBLE PRECISION NORMAL ( 3 )\n \nC$ Brief_I/O\nC\nC Variable I/O Description\nC -------- --- --------------------------------------------------\nC V1,\nC V2,\nC V3 I Vertices of a plate.\nC NORMAL O Plate's outward normal vector.\nC\nC$ Detailed_Input\nC\nC V1,\nC V2,\nC V3 are vertices of a triangular plate.\nC \nC$ Detailed_Output\nC\nC NORMAL is an outward normal vector of the plate defined by\nC the input vertices. The order of the vertices is\nC used to determine the choice of normal direction:\nC the normal vector is\nC\nC ( V2 - V1 ) x ( V3 - V2 )\nC\nC \nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC 1) The input plate may be degenerate: it may be a line segment\nC or a point. These are not considered to be erroneous inputs.\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC This routine saves computation time by not scaling the output\nC vector to unit length. The caller can scale the vector using\nC the routine VHAT.\nC\nC$ Examples\nC\nC\nC 1) Compute an upward normal of an equilateral triangle lying \nC in the X-Y plane and centered at the origin.\nC\nC Example code begins here.\nC\nC\nC PROGRAM EX1\nC IMPLICIT NONE\nC\nC DOUBLE PRECISION NORMAL ( 3 )\nC DOUBLE PRECISION S\nC DOUBLE PRECISION V1 ( 3 )\nC DOUBLE PRECISION V2 ( 3 )\nC DOUBLE PRECISION V3 ( 3 )\nC\nC\nC S = SQRT(3.D0)/2\nC\nC CALL VPACK ( S, -0.5D0, 0.D0, V1 )\nC CALL VPACK ( 0.D0, 1.D0, 0.D0, V2 )\nC CALL VPACK ( -S, -0.5D0, 0.D0, V3 )\nC\nC\nC CALL PLTNRM ( V1, V2, V3, NORMAL )\nC\nC WRITE (*, '(1X,A,3(3E20.12))' ) 'NORMAL = ', NORMAL\nC\nC END\nC\nC When run on a PC/Linux/gfortran/64-bit platform, the output\nC from this program was:\nC\nC\nC NORMAL = 0.000000000000E+00 0.000000000000E+00 0.259807621135E+01\nC\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC N.J. Bachman (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.0, 26-JAN-2016 (NJB)\nC\nC-&\n \nC$ Index_Entries\nC\nC compute normal vector of triangular plate from vertices\nC\nC-&\n\nC\nC SPICELIB functions\nC\n\nC\nC Local variables\nC \n DOUBLE PRECISION EDGE1 ( 3 )\n DOUBLE PRECISION EDGE2 ( 3 )\n\nC\nC This routine is error-free.\nC\n\nC\nC Type 2 plate vertices are ordered in the positive\nC (right-handed) sense about the outward normal.\nC \n CALL VSUB ( V2, V1, EDGE1 )\n CALL VSUB ( V3, V2, EDGE2 )\n\n CALL VCRSS ( EDGE1, EDGE2, NORMAL )\n\n END\n", "meta": {"hexsha": "d5471fc4b3f6831d8aaac2dc537342307ce11d9d", "size": 4670, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/pltnrm.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/pltnrm.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/pltnrm.f", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 25.2432432432, "max_line_length": 72, "alphanum_fraction": 0.6201284797, "num_tokens": 1394, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094117351309, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6743726628287551}} {"text": "\n PROGRAM PGKEX18\nC\nC Produce an NX x NY CELL ARRAY based on the Mandelbrot set--color\nC the cells depending upon the speed of convergence or divergence.\nC\nC Define the error file, the Fortran unit number, the workstation type,\nC and the workstation ID to be used in calls to GKS routines.\nC\nC PARAMETER (IERRF=6, LUNIT=2, IWTYPE=1, IWKID=1) ! NCGM\nC PARAMETER (IERRF=6, LUNIT=2, IWTYPE=8, IWKID=1) ! X Windows\nC PARAMETER (IERRF=6, LUNIT=2, IWTYPE=11, IWKID=1) ! PDF\nC PARAMETER (IERRF=6, LUNIT=2, IWTYPE=20, IWKID=1) ! PostScript\nC\n PARAMETER (IERRF=6, LUNIT=2, IWTYPE=1, IWKID=1)\n PARAMETER (NX=20, NY=20, NITER=101)\n INTEGER COLIA(NX,NY)\n COMPLEX Z\nC\nC Region of interest.\nC\n DATA XL,XR,YB,YT/-2.,.5,-1.25,1.25/\nC\nC Open GKS, open and activate a workstation.\nC\n CALL GOPKS (IERRF,IDUM)\n CALL GOPWK (IWKID,LUNIT,IWTYPE)\n CALL GACWK (IWKID)\nC\nC Set up normalizaton transformation.\nC\n CALL GSWN(1,XL,XR,YB,YT)\n CALL GSVP(1,.1,.9,0.,.8)\n CALL GSELNT(1)\nC\nC Define color indices in a continuous spectrum.\nC\n DO 11 K = 1,NITER\n H = REAL(K)/REAL(NITER)*360.\n CALL HLSRGB(H,50.,100.,RV,GV,BV)\n CALL GSCR(IWKID,K,RV,GV,BV)\n 11 CONTINUE\n CALL GSCR(IWKID,NITER+1,0.,0.,1.)\nC\nC Set up the cell array and call GCA.\nC\n DX = (XR-XL)/NX\n DY = (YT-YB)/NY\n DO 10 J=1,NY\n Y = YB+DY*REAL(J-1)\n DO 20 I=1,NX\n X = XL+DX*REAL(I-1)\n Z = CMPLX(X,Y)\n CALL CONVG(Z,NITER,.001,10000.,ITER)\n COLIA(I,J) = ITER\n 20 CONTINUE\n 10 CONTINUE\n CALL GCA(XL,YB,XR,YT,NX,NY,1,1,NX,NY,COLIA)\nC\nC Label the plot using Plotchar.\nC\n CALL GSCLIP(0)\n CALL PCSETI('FN',25)\n CALL PCSETI('CC',NITER+1)\n CALL PLCHHQ(XL+.5*(XR-XL),YB+(YT-YB)*1.07,'Cell array',.033,0.,0.)\n CALL FRAME\nC\nC Deactivate and close the workstation, close GKS.\nC\n CALL GDAWK (IWKID)\n CALL GCLWK (IWKID)\n CALL GCLKS\nC\t\n STOP\n END\n SUBROUTINE CONVG(Z,NUM,TOLSM,TOLLG,ITER)\nC\nC Iterate Z(N+1) = Z(N)**2+Z0 for N=1,...,NUM . If the complex absolute\nC values get smaller than TOLSM, then set ITER equal to the number of\nC iterations and return. If the complex absolute value gets larger than\nC TOLLG, set ITER to NUM and return.\nC\n COMPLEX Z,ZS,ZN,ZO\n ZS = Z\n ZO = Z\n DO 10 I=1,NUM\n ZN = ZO*ZO+ZS\n IF (CABS(ZN-ZO) .LT. TOLSM) THEN\n ITER = I\n RETURN\n ELSE IF (CABS(ZN-ZO) .GT. TOLLG) THEN\n ITER = I\n RETURN\n ENDIF\n ZO = ZN\n 10 CONTINUE\n ITER=NUM\n RETURN\n END\n", "meta": {"hexsha": "d46ff1d528b20ad09878394430b0c14d3a6f8b51", "size": 2658, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ncarg2d/src/pdocexamples/pgks/pgkex18.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "ncarg2d/src/pdocexamples/pgks/pgkex18.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "ncarg2d/src/pdocexamples/pgks/pgkex18.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 26.58, "max_line_length": 73, "alphanum_fraction": 0.5948081264, "num_tokens": 1015, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543488, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6743726585402475}} {"text": "! Model program to compress given Gausssians\n! Kernal Density Compression Algorithm\n!\n! Authour: Anji Babu Kapakayala\n! Dept. of Chemistry\n! IIT Kanpur, India.\n! anjibabu480@gmail.com\n!\n! OUTPUTS: Original_Gaus.dat\n! Compressed_Gaus.dat \n!\nPROGRAM kde\nIMPLICIT NONE\nREAL*8::x,dx0,x_min,x_max,x_width,dum,dum1,error\nINTEGER::i,j,nbin=10001,ng=15000,CNG\nREAL*8,ALLOCATABLE::grid(:),G(:),ht(:),sigma(:),x0(:)\nREAL*8,ALLOCATABLE::C_hill(:),C_width(:),C_height(:)\n!Initializing grid values\nx_min=-100.d0;x_max=100.d0\nx_width=(x_max-x_min)/(nbin-1)\n\nopen(10,file=\"Original_Gaus.dat\",status='unknown')\nopen(11,file=\"Compressed_Gaus.dat\",status='unknown')\n\nALLOCATE(grid(nbin),G(nbin))\nALLOCATE(ht(ng),sigma(ng),x0(ng))\nALLOCATE(C_hill(ng),C_width(ng),C_height(ng))\n\n! Gridding data\ndo i=1,nbin\ngrid(i)=DFLOAT(i-1)*x_width+x_min\nenddo\n\n!Initializing Gaussian Parameters\nx0(1)=-35.0;sigma(1)=0.050\nht(1)=0.20;dx0=0.0050\n\n! Generate Gaussians centers \nDO j=1,ng\nht(j)=0.50\nsigma(j)=0.05\n!write(*,*) x0(j),sigma(j),ht(j)\nx0(j+1)=x0(j)+dx0\nENDDO\n\n!Summing the original Gaussians\nDO i=1,nbin\n dum=0.0\n DO j=1,ng\n dum=dum+ht(j)*EXP(-(((grid(i)-x0(j))**2)/2*(sigma(j)*sigma(j))))\n ENDDO\nwrite(10,*) grid(i),dum\nENDDO\n\n! Compressing the given Gaussians using Kernel Density Compression Algorithm\nCALL Compress(ng,x0,ht,sigma,CNG,C_hill,C_width,C_height)\n\n!Summing the Compressed Gaussians\nDO i=1,nbin\n dum1=0.0\n DO j=1,CNG\n if(ng.eq.CNG)then\n dum1=dum1+C_height(j)*EXP(-(((grid(i)-C_hill(j))**2)/2*(C_width(j)*C_width(j))))\n else\n dum1=dum1+C_height(j)*EXP(-(((grid(i)-C_hill(j))**2)/2*(C_width(j))))\n endif\n ENDDO\nwrite(11,*) grid(i),dum1\nENDDO\n\n\nWRITE(*,*) \"No of Original Gassians : \",ng,\"No. of Compressed Gaussians: \",CNG\nWRITE(*,*) \"Sum of original Gaussians : \",dum\nWRITE(*,*) \"Sum of compressed Gaussians: \",dum1\n\n! Calculating relative error\nerror=(abs(dum1-dum)/dum)*100\nWRITE(*,*) \"Relative error(%) : \",error\nclose(10)\nclose(11)\nENDPROGRAM kde\n!------------------------------------------------------------------------------------------!\n!Subroutine to compress Given gasuuians using Kernel Density Compression Algorithm\nSUBROUTINE Compress(NG,hill,height,width,CNG,C_hill,C_width,C_height)\nIMPLICIT NONE\n INTEGER, INTENT(IN)::NG\n REAL*8, INTENT(IN)::hill(NG),width(NG),height(NG)\n REAL*8, INTENT(OUT)::C_hill(NG),C_width(NG),C_height(NG)\n INTEGER,INTENT(OUT)::CNG\n!\n integer :: i,j,n,min_j\n real*8 :: distance,cutoff=1.0,dum,new_height,new_width,new_hill,min_d\n!\n! Initialization of Compressed Gaussians\n C_hill(1) =hill(1)\n C_width(1)=width(1)\n C_height(1)=height(1)\n n=1\n \n DO i=2,NG\n min_d=sqrt(ABS(((hill(i))-C_hill(1))/C_width(1))**2)\n min_j=1\n do j=1,n\n distance=sqrt(ABS(((hill(i))-C_hill(j))/C_width(j))**2)\n if(distance.lt.min_d) then\n min_d=distance\n min_j=j\n endif\n ! print*,\"Distance: \",distance\n enddo\n !print*,\"Minimum Distance: \",min_d,\"LOCATION: \",min_j\n !If minimun distance is less than given cutoff, it merges the both gaussinas\n ! Add as new compressed kernal otherwise. \n if(min_d.lt.cutoff)then\n new_height=height(i)+C_height(min_j)\n new_hill =(1.0/new_height)*((height(i)*hill(i))+(C_height(min_j)*C_hill(min_j)))\n dum=(height(i)*(width(i)**2+hill(i)**2)+C_height(min_j)*(C_width(min_j)**2+C_hill(min_j)**2))\n new_width=(1.0/new_height)*dum-new_hill**2\n ! Store new variables to min_jth kernel\n C_height(min_j)=new_height \n C_width(min_j)=new_width\n C_hill(min_j)=new_hill\n else\n n=n+1\n C_height(n)=height(i) \n C_width(n)=width(i)\n C_hill(n)=hill(i)\n endif \n\n ENDDO\n! Store n as No. of Compressed Gaussians\n CNG=n\n\nEND SUBROUTINE Compress\n!------------------------------------------------------------------------------------------!\n! Anji Babu Kapakayala, Jan, 2021\t\t\t !\n!------------------------------------------------------------------------------------------!\n", "meta": {"hexsha": "791a62060297359ad2634e81fb4018104ccc8397", "size": 4139, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "model_KDC.f90", "max_stars_repo_name": "anjibabuIITK/Kernel_Density_Compression_Algorithm", "max_stars_repo_head_hexsha": "d2dba0bb08f0de3b9394d156bf7bb027aeef17c8", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-02-05T04:55:28.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-05T04:55:28.000Z", "max_issues_repo_path": "model_KDC.f90", "max_issues_repo_name": "anjibabuIITK/Kernel_Density_Compression_Algorithm", "max_issues_repo_head_hexsha": "d2dba0bb08f0de3b9394d156bf7bb027aeef17c8", "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": "model_KDC.f90", "max_forks_repo_name": "anjibabuIITK/Kernel_Density_Compression_Algorithm", "max_forks_repo_head_hexsha": "d2dba0bb08f0de3b9394d156bf7bb027aeef17c8", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.9927536232, "max_line_length": 104, "alphanum_fraction": 0.6030442136, "num_tokens": 1327, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094032139577, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6743726514703067}} {"text": "C * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC * *\nC * copyright (c) 1999 by UCAR *\nC * *\nC * UNIVERSITY CORPORATION for ATMOSPHERIC RESEARCH *\nC * *\nC * all rights reserved *\nC * *\nC * FISHPACK version 4.1 *\nC * *\nC * A PACKAGE OF FORTRAN SUBPROGRAMS FOR THE SOLUTION OF *\nC * *\nC * SEPARABLE ELLIPTIC PARTIAL DIFFERENTIAL EQUATIONS *\nC * *\nC * BY *\nC * *\nC * JOHN ADAMS, PAUL SWARZTRAUBER AND ROLAND SWEET *\nC * *\nC * OF *\nC * *\nC * THE NATIONAL CENTER FOR ATMOSPHERIC RESEARCH *\nC * *\nC * BOULDER, COLORADO (80307) U.S.A. *\nC * *\nC * WHICH IS SPONSORED BY *\nC * *\nC * THE NATIONAL SCIENCE FOUNDATION *\nC * *\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC\nC PROGRAM TO ILLUSTRATE THE USE OF HSTCYL TO SOLVE THE EQUATION\nC\nC (1/R)(D/DR)(R*DU/DR) + (D/DZ)(DU/DZ) = (2*R*Z)**2*(4*Z**2 + 3*R**2)\nC\nC ON THE RECTANGLE 0 .LT. R .LT. 1 , 0 .LT. Z .LT. 1 WITH THE\nC BOUNDARY CONDITIONS\nC\nC (DU/DR)(1,Z) = 4*Z**2 FOR 0 .LE. Z .LE. 1\nC\nC AND\nC\nC (DU/DZ)(R,0) = 0 AND (DU/DZ)(R,1) = 4*R**2 FOR 0 .LE. R .LE. 1 .\nC\nC THE SOLUTION TO THIS PROBLEM IS NOT UNIQUE. IT IS A\nC ONE-PARAMETER FAMILY OF SOLUTIONS GIVEN BY\nC\nC U(R,Z) = (R*Z)**4 + ARBITRARY CONSTANT .\nC\nC THE R-INTERVAL WILL CONTAIN 50 UNKNOWNS AND THE Z-INTERVAL WILL\nC CONTAIN 52 UNKNOWNS.\nC\n DIMENSION F(51,52) ,BDB(52) ,BDC(50) ,BDD(50) ,\n 1 W(1108) ,R(50) ,Z(52)\nC\nC FROM DIMENSION STATEMENT WE GET VALUE OF IDIMF. ALSO NOTE THAT W\nC IS DIMENSIONED (13 + INT(LOG2(N)))*M + 4*N .\nC\n IDIMF = 51\n A = 0.\n B = 1.\n M = 50\n MBDCND = 6\n C = 0.\n D = 1.\n N = 52\n NBDCND = 3\n ELMBDA = 0.\nC\nC GENERATE AND STORE GRID POINTS FOR THE PURPOSE OF COMPUTING\nC BOUNDARY DATA AND THE RIGHT SIDE OF THE POISSON EQUATION.\nC\n DO 101 I=1,M\n R(I) = (FLOAT(I)-0.5)/50.\n 101 CONTINUE\n DO 102 J=1,N\n Z(J) = (FLOAT(J)-0.5)/52.\n 102 CONTINUE\nC\nC GENERATE BOUNDARY DATA.\nC\n DO 103 J=1,N\n BDB(J) = 4.*Z(J)**4\n 103 CONTINUE\n DO 104 I=1,M\n BDC(I) = 0.\n BDD(I) = 4.*R(I)**4\n 104 CONTINUE\nC\nC BDA IS A DUMMY VARIABLE.\nC\nC GENERATE RIGHT SIDE OF EQUATION.\nC\n DO 106 I=1,M\n DO 105 J=1,N\n F(I,J) = 4.*R(I)**2*Z(J)**2*(4.*Z(J)**2+3.*R(I)**2)\n 105 CONTINUE\n 106 CONTINUE\n CALL HSTCYL (A,B,M,MBDCND,BDA,BDB,C,D,N,NBDCND,BDC,BDD,ELMBDA,F,\n 1 IDIMF,PERTRB,IERROR,W)\nC\nC COMPUTE DISCRETIZATION ERROR BY MINIMIZING OVER ALL A THE FUNCTION\nC NORM(F(I,J) - A*1 - U(R(I),Z(J))). THE EXACT SOLUTION IS\nC U(R,Z) = (R*Z)**4 + ARBITRARY CONSTANT.\nC\n X = 0.\n DO 108 I=1,M\n DO 107 J=1,N\n X = X+F(I,J)-(R(I)*Z(J))**4\n 107 CONTINUE\n 108 CONTINUE\n X = X/FLOAT(M*N)\n DO 110 I=1,M\n DO 109 J=1,N\n F(I,J) = F(I,J)-X\n 109 CONTINUE\n 110 CONTINUE\n ERR = 0.\n DO 112 I=1,M\n DO 111 J=1,N\n X = ABS(F(I,J)-(R(I)*Z(J))**4)\n IF (X .GT. ERR) ERR = X\n 111 CONTINUE\n 112 CONTINUE\n PRINT 1001 , IERROR,PERTRB,ERR,W(1)\n STOP\nC\n 1001 FORMAT (1H1,20X,25HSUBROUTINE HSTCYL EXAMPLE///\n 1 10X,46HTHE OUTPUT FROM THE NCAR CONTROL DATA 7600 WAS//\n 2 32X,10HIERROR = 0/32X,20HPERTRB =-4.43114E-04/\n 3 18X,34HDISCRETIZATION ERROR = 7.52796E-05/\n 4 12X,32HREQUIRED LENGTH OF W ARRAY = 958//\n 5 10X,32HTHE OUTPUT FROM YOUR COMPUTER IS//\n 6 32X,8HIERROR =,I2/32X,8HPERTRB =,E12.5/\n 7 18X,22HDISCRETIZATION ERROR =,E12.5/\n 8 12X,28HREQUIRED LENGTH OF W ARRAY =,F4.0)\nC\n END\n", "meta": {"hexsha": "f2ffbe52c451c75a3fbf6380046b3031738cedee", "size": 5112, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/test/thstcyl.f", "max_stars_repo_name": "ipelupessy/omuse", "max_stars_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2020-03-25T10:02:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-18T00:28:35.000Z", "max_issues_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/test/thstcyl.f", "max_issues_repo_name": "ipelupessy/omuse", "max_issues_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 45, "max_issues_repo_issues_event_min_datetime": "2020-03-03T16:07:16.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-14T09:01:07.000Z", "max_forks_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/test/thstcyl.f", "max_forks_repo_name": "ipelupessy/omuse", "max_forks_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-03-03T13:28:50.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-26T09:20:02.000Z", "avg_line_length": 37.0434782609, "max_line_length": 72, "alphanum_fraction": 0.3828247261, "num_tokens": 1601, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735663, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6743726493260527}} {"text": " program demo_atan2\n use,intrinsic :: iso_fortran_env, only : dp=>real64,sp=>real32\n implicit none\n real(kind=sp) :: x = 1.e0_sp, y = 0.5e0_sp, z\n z = atan2(y,x)\n write(*,*)x,y,z\n end program demo_atan2\n", "meta": {"hexsha": "6edec80fa9e39491789e29e9f7eb17c0d65b6cbc", "size": 230, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/atan2.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/atan2.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/atan2.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": 28.75, "max_line_length": 66, "alphanum_fraction": 0.6, "num_tokens": 86, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8558511469672595, "lm_q2_score": 0.7879311931529758, "lm_q1q2_score": 0.6743518153912555}} {"text": "!---------------------------------------------------!\n! Copyright (c) 2017 Shunsuke A. Sato !\n! Released under the MIT license !\n! https://opensource.org/licenses/mit-license.php !\n!---------------------------------------------------!\nsubroutine mesh\n use global_variables\n use hpsi\n use density_matrix\n implicit none\n integer :: ix, iy \n\n write(*,'(A)')'===== Making mesh ================================================================'\n write(*,'(A)')\n write(*,'(A)')\n\n allocate(xn(0:Nx),xyn(0:Nx,0:Nx))\n dx = length_x/dble(Nx)\n \n do ix = 0,Nx\n xn(ix) = dx*dble(ix) - 0.5d0*length_x\n end do\n \n do ix = 0,Nx\n do iy = 0,Nx\n xyn(ix,iy)= xn(ix)+xn(iy)\n end do\n end do\n\n call initialize_hpsi\n call initialize_density_matrix\n\n write(*,'(A)')'===== Complete Making mesh ========================================================'\n return\nend subroutine mesh\n", "meta": {"hexsha": "d4ca8ca62812d79da7009cd45913b453e703e720", "size": 917, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/mesh.f90", "max_stars_repo_name": "shunsuke-sato/qm1d", "max_stars_repo_head_hexsha": "b09bbe97dc2987188fe635b27dce89ce82e5d1ee", "max_stars_repo_licenses": ["MIT"], "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/mesh.f90", "max_issues_repo_name": "shunsuke-sato/qm1d", "max_issues_repo_head_hexsha": "b09bbe97dc2987188fe635b27dce89ce82e5d1ee", "max_issues_repo_licenses": ["MIT"], "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/mesh.f90", "max_forks_repo_name": "shunsuke-sato/qm1d", "max_forks_repo_head_hexsha": "b09bbe97dc2987188fe635b27dce89ce82e5d1ee", "max_forks_repo_licenses": ["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.4722222222, "max_line_length": 101, "alphanum_fraction": 0.4449291167, "num_tokens": 246, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511396138366, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.6743518117282643}} {"text": "program ch0802\n ! Rank 2 Whole Arrays in Fortran\n implicit none\n\n integer, parameter :: n = 5\n real, dimension(1:n,1:n) :: fahrenheit, celsius\n integer :: lat, long\n\n do lat = 1, n\n print *, ' For Latitude= ', lat\n do long = 1, n\n print *, ' For Longitude', long\n read *, fahrenheit(lat,long)\n end do\n end do\n ! read *, fahrenheit\n celsius = 5./9.*(fahrenheit-32.)\n print *, fahrenheit\n print *, celsius\nend program\n", "meta": {"hexsha": "67556ace052681ae79629ee70e7390b705244924", "size": 492, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ch08/ch0802.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": "ch08/ch0802.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": "ch08/ch0802.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.4285714286, "max_line_length": 51, "alphanum_fraction": 0.5569105691, "num_tokens": 144, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.7879311881731379, "lm_q1q2_score": 0.6743518111292556}} {"text": "*DECK DSPCO\n SUBROUTINE DSPCO (AP, N, KPVT, RCOND, Z)\nC***BEGIN PROLOGUE DSPCO\nC***PURPOSE Factor a real symmetric matrix stored in packed form\nC by elimination with symmetric pivoting and estimate the\nC condition number of the matrix.\nC***LIBRARY SLATEC (LINPACK)\nC***CATEGORY D2B1A\nC***TYPE DOUBLE PRECISION (SSPCO-S, DSPCO-D, CHPCO-C, CSPCO-C)\nC***KEYWORDS CONDITION NUMBER, LINEAR ALGEBRA, LINPACK,\nC MATRIX FACTORIZATION, PACKED, SYMMETRIC\nC***AUTHOR Moler, C. B., (U. of New Mexico)\nC***DESCRIPTION\nC\nC DSPCO factors a double precision symmetric matrix stored in\nC packed form by elimination with symmetric pivoting and estimates\nC the condition of the matrix.\nC\nC IF RCOND is not needed, DSPFA is slightly faster.\nC To solve A*X = B , follow DSPCO by DSPSL.\nC To compute INVERSE(A)*C , follow DSPCO by DSPSL.\nC To compute INVERSE(A) , follow DSPCO by DSPDI.\nC To compute DETERMINANT(A) , follow DSPCO by DSPDI.\nC To compute INERTIA(A), follow DSPCO by DSPDI.\nC\nC On Entry\nC\nC AP DOUBLE PRECISION (N*(N+1)/2)\nC the packed form of a symmetric matrix A . The\nC columns of the upper triangle are stored sequentially\nC in a one-dimensional array of length N*(N+1)/2 .\nC See comments below for details.\nC\nC N INTEGER\nC the order of the matrix A .\nC\nC Output\nC\nC AP a block diagonal matrix and the multipliers which\nC were used to obtain it stored in packed form.\nC The factorization can be written A = U*D*TRANS(U)\nC where U is a product of permutation and unit\nC upper triangular matrices , TRANS(U) is the\nC transpose of U , and D is block diagonal\nC with 1 by 1 and 2 by 2 blocks.\nC\nC KPVT INTEGER(N)\nC an integer vector of pivot indices.\nC\nC RCOND DOUBLE PRECISION\nC an estimate of the reciprocal condition of A .\nC For the system A*X = B , relative perturbations\nC in A and B of size EPSILON may cause\nC relative perturbations in X of size EPSILON/RCOND .\nC If RCOND is so small that the logical expression\nC 1.0 + RCOND .EQ. 1.0\nC is true, then A may be singular to working\nC precision. In particular, RCOND is zero if\nC exact singularity is detected or the estimate\nC underflows.\nC\nC Z DOUBLE PRECISION(N)\nC a work vector whose contents are usually unimportant.\nC If A is close to a singular matrix, then Z is\nC an approximate null vector in the sense that\nC NORM(A*Z) = RCOND*NORM(A)*NORM(Z) .\nC\nC Packed Storage\nC\nC The following program segment will pack the upper\nC triangle of a symmetric matrix.\nC\nC K = 0\nC DO 20 J = 1, N\nC DO 10 I = 1, J\nC K = K + 1\nC AP(K) = A(I,J)\nC 10 CONTINUE\nC 20 CONTINUE\nC\nC***REFERENCES J. J. Dongarra, J. R. Bunch, C. B. Moler, and G. W.\nC Stewart, LINPACK Users' Guide, SIAM, 1979.\nC***ROUTINES CALLED DASUM, DAXPY, DDOT, DSCAL, DSPFA\nC***REVISION HISTORY (YYMMDD)\nC 780814 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890831 Modified array declarations. (WRB)\nC 891107 Modified routine equivalence list. (WRB)\nC 891107 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900326 Removed duplicate information from DESCRIPTION section.\nC (WRB)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE DSPCO\n INTEGER N,KPVT(*)\n DOUBLE PRECISION AP(*),Z(*)\n DOUBLE PRECISION RCOND\nC\n DOUBLE PRECISION AK,AKM1,BK,BKM1,DDOT,DENOM,EK,T\n DOUBLE PRECISION ANORM,S,DASUM,YNORM\n INTEGER I,IJ,IK,IKM1,IKP1,INFO,J,JM1,J1\n INTEGER K,KK,KM1K,KM1KM1,KP,KPS,KS\nC\nC FIND NORM OF A USING ONLY UPPER HALF\nC\nC***FIRST EXECUTABLE STATEMENT DSPCO\n J1 = 1\n DO 30 J = 1, N\n Z(J) = DASUM(J,AP(J1),1)\n IJ = J1\n J1 = J1 + J\n JM1 = J - 1\n IF (JM1 .LT. 1) GO TO 20\n DO 10 I = 1, JM1\n Z(I) = Z(I) + ABS(AP(IJ))\n IJ = IJ + 1\n 10 CONTINUE\n 20 CONTINUE\n 30 CONTINUE\n ANORM = 0.0D0\n DO 40 J = 1, N\n ANORM = MAX(ANORM,Z(J))\n 40 CONTINUE\nC\nC FACTOR\nC\n CALL DSPFA(AP,N,KPVT,INFO)\nC\nC RCOND = 1/(NORM(A)*(ESTIMATE OF NORM(INVERSE(A)))) .\nC ESTIMATE = NORM(Z)/NORM(Y) WHERE A*Z = Y AND A*Y = E .\nC THE COMPONENTS OF E ARE CHOSEN TO CAUSE MAXIMUM LOCAL\nC GROWTH IN THE ELEMENTS OF W WHERE U*D*W = E .\nC THE VECTORS ARE FREQUENTLY RESCALED TO AVOID OVERFLOW.\nC\nC SOLVE U*D*W = E\nC\n EK = 1.0D0\n DO 50 J = 1, N\n Z(J) = 0.0D0\n 50 CONTINUE\n K = N\n IK = (N*(N - 1))/2\n 60 IF (K .EQ. 0) GO TO 120\n KK = IK + K\n IKM1 = IK - (K - 1)\n KS = 1\n IF (KPVT(K) .LT. 0) KS = 2\n KP = ABS(KPVT(K))\n KPS = K + 1 - KS\n IF (KP .EQ. KPS) GO TO 70\n T = Z(KPS)\n Z(KPS) = Z(KP)\n Z(KP) = T\n 70 CONTINUE\n IF (Z(K) .NE. 0.0D0) EK = SIGN(EK,Z(K))\n Z(K) = Z(K) + EK\n CALL DAXPY(K-KS,Z(K),AP(IK+1),1,Z(1),1)\n IF (KS .EQ. 1) GO TO 80\n IF (Z(K-1) .NE. 0.0D0) EK = SIGN(EK,Z(K-1))\n Z(K-1) = Z(K-1) + EK\n CALL DAXPY(K-KS,Z(K-1),AP(IKM1+1),1,Z(1),1)\n 80 CONTINUE\n IF (KS .EQ. 2) GO TO 100\n IF (ABS(Z(K)) .LE. ABS(AP(KK))) GO TO 90\n S = ABS(AP(KK))/ABS(Z(K))\n CALL DSCAL(N,S,Z,1)\n EK = S*EK\n 90 CONTINUE\n IF (AP(KK) .NE. 0.0D0) Z(K) = Z(K)/AP(KK)\n IF (AP(KK) .EQ. 0.0D0) Z(K) = 1.0D0\n GO TO 110\n 100 CONTINUE\n KM1K = IK + K - 1\n KM1KM1 = IKM1 + K - 1\n AK = AP(KK)/AP(KM1K)\n AKM1 = AP(KM1KM1)/AP(KM1K)\n BK = Z(K)/AP(KM1K)\n BKM1 = Z(K-1)/AP(KM1K)\n DENOM = AK*AKM1 - 1.0D0\n Z(K) = (AKM1*BK - BKM1)/DENOM\n Z(K-1) = (AK*BKM1 - BK)/DENOM\n 110 CONTINUE\n K = K - KS\n IK = IK - K\n IF (KS .EQ. 2) IK = IK - (K + 1)\n GO TO 60\n 120 CONTINUE\n S = 1.0D0/DASUM(N,Z,1)\n CALL DSCAL(N,S,Z,1)\nC\nC SOLVE TRANS(U)*Y = W\nC\n K = 1\n IK = 0\n 130 IF (K .GT. N) GO TO 160\n KS = 1\n IF (KPVT(K) .LT. 0) KS = 2\n IF (K .EQ. 1) GO TO 150\n Z(K) = Z(K) + DDOT(K-1,AP(IK+1),1,Z(1),1)\n IKP1 = IK + K\n IF (KS .EQ. 2)\n 1 Z(K+1) = Z(K+1) + DDOT(K-1,AP(IKP1+1),1,Z(1),1)\n KP = ABS(KPVT(K))\n IF (KP .EQ. K) GO TO 140\n T = Z(K)\n Z(K) = Z(KP)\n Z(KP) = T\n 140 CONTINUE\n 150 CONTINUE\n IK = IK + K\n IF (KS .EQ. 2) IK = IK + (K + 1)\n K = K + KS\n GO TO 130\n 160 CONTINUE\n S = 1.0D0/DASUM(N,Z,1)\n CALL DSCAL(N,S,Z,1)\nC\n YNORM = 1.0D0\nC\nC SOLVE U*D*V = Y\nC\n K = N\n IK = N*(N - 1)/2\n 170 IF (K .EQ. 0) GO TO 230\n KK = IK + K\n IKM1 = IK - (K - 1)\n KS = 1\n IF (KPVT(K) .LT. 0) KS = 2\n IF (K .EQ. KS) GO TO 190\n KP = ABS(KPVT(K))\n KPS = K + 1 - KS\n IF (KP .EQ. KPS) GO TO 180\n T = Z(KPS)\n Z(KPS) = Z(KP)\n Z(KP) = T\n 180 CONTINUE\n CALL DAXPY(K-KS,Z(K),AP(IK+1),1,Z(1),1)\n IF (KS .EQ. 2) CALL DAXPY(K-KS,Z(K-1),AP(IKM1+1),1,Z(1),1)\n 190 CONTINUE\n IF (KS .EQ. 2) GO TO 210\n IF (ABS(Z(K)) .LE. ABS(AP(KK))) GO TO 200\n S = ABS(AP(KK))/ABS(Z(K))\n CALL DSCAL(N,S,Z,1)\n YNORM = S*YNORM\n 200 CONTINUE\n IF (AP(KK) .NE. 0.0D0) Z(K) = Z(K)/AP(KK)\n IF (AP(KK) .EQ. 0.0D0) Z(K) = 1.0D0\n GO TO 220\n 210 CONTINUE\n KM1K = IK + K - 1\n KM1KM1 = IKM1 + K - 1\n AK = AP(KK)/AP(KM1K)\n AKM1 = AP(KM1KM1)/AP(KM1K)\n BK = Z(K)/AP(KM1K)\n BKM1 = Z(K-1)/AP(KM1K)\n DENOM = AK*AKM1 - 1.0D0\n Z(K) = (AKM1*BK - BKM1)/DENOM\n Z(K-1) = (AK*BKM1 - BK)/DENOM\n 220 CONTINUE\n K = K - KS\n IK = IK - K\n IF (KS .EQ. 2) IK = IK - (K + 1)\n GO TO 170\n 230 CONTINUE\n S = 1.0D0/DASUM(N,Z,1)\n CALL DSCAL(N,S,Z,1)\n YNORM = S*YNORM\nC\nC SOLVE TRANS(U)*Z = V\nC\n K = 1\n IK = 0\n 240 IF (K .GT. N) GO TO 270\n KS = 1\n IF (KPVT(K) .LT. 0) KS = 2\n IF (K .EQ. 1) GO TO 260\n Z(K) = Z(K) + DDOT(K-1,AP(IK+1),1,Z(1),1)\n IKP1 = IK + K\n IF (KS .EQ. 2)\n 1 Z(K+1) = Z(K+1) + DDOT(K-1,AP(IKP1+1),1,Z(1),1)\n KP = ABS(KPVT(K))\n IF (KP .EQ. K) GO TO 250\n T = Z(K)\n Z(K) = Z(KP)\n Z(KP) = T\n 250 CONTINUE\n 260 CONTINUE\n IK = IK + K\n IF (KS .EQ. 2) IK = IK + (K + 1)\n K = K + KS\n GO TO 240\n 270 CONTINUE\nC MAKE ZNORM = 1.0\n S = 1.0D0/DASUM(N,Z,1)\n CALL DSCAL(N,S,Z,1)\n YNORM = S*YNORM\nC\n IF (ANORM .NE. 0.0D0) RCOND = YNORM/ANORM\n IF (ANORM .EQ. 0.0D0) RCOND = 0.0D0\n RETURN\n END\n", "meta": {"hexsha": "e879b562a793911a7ba48449d2b365b596546688", "size": 9676, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/dspco.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/dspco.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/dspco.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.0397350993, "max_line_length": 71, "alphanum_fraction": 0.4867713931, "num_tokens": 3549, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.787931185683219, "lm_q1q2_score": 0.6743518089982555}} {"text": "program example\n\n implicit none\n\n integer, parameter :: n = 3\n real(8), parameter :: small = 1.0d-12\n integer :: ierr\n real(8) :: a(n, n)\n real(8) :: b(n)\n integer :: ipiv(n)\n logical :: roots_ok\n\n a(1, 1) = 2.0d0\n a(2, 1) = 1.0d0\n a(3, 1) = 3.0d0\n a(1, 2) = 2.0d0\n a(2, 2) = 6.0d0\n a(3, 2) = 8.0d0\n a(1, 3) = 6.0d0\n a(2, 3) = 8.0d0\n a(3, 3) = 18.0d0\n\n b(1) = 1.0d0\n b(2) = 3.0d0\n b(3) = 5.0d0\n\n call dgesv(n, 1, a, n, ipiv, b, n, ierr)\n if (ierr /= 0) stop \"error in dgesv routine!\"\n\n roots_ok = dabs(b(1) + 0.50d0) <= small .and. &\n dabs(b(2) - 0.25d0) <= small .and. &\n dabs(b(3) - 0.25d0) <= small\n\n if (roots_ok) then\n print *, 'PASSED'\n else\n stop 'ERROR: dgesv test failed!'\n endif\n\nend program\n", "meta": {"hexsha": "367327e472f8172876dce6ba5ca215bdf711272a", "size": 798, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/fc_lapack/src/example.f90", "max_stars_repo_name": "tenomoto/autocmake", "max_stars_repo_head_hexsha": "36d33541736cb0bafe804306527c896e0e5c6259", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 18, "max_stars_repo_stars_event_min_datetime": "2016-05-12T08:41:42.000Z", "max_stars_repo_stars_event_max_datetime": "2018-03-04T04:45:02.000Z", "max_issues_repo_path": "test/fc_lapack/src/example.f90", "max_issues_repo_name": "tenomoto/autocmake", "max_issues_repo_head_hexsha": "36d33541736cb0bafe804306527c896e0e5c6259", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 158, "max_issues_repo_issues_event_min_datetime": "2015-06-04T16:10:50.000Z", "max_issues_repo_issues_event_max_datetime": "2016-04-18T20:47:39.000Z", "max_forks_repo_path": "test/fc_lapack/src/example.f90", "max_forks_repo_name": "tenomoto/autocmake", "max_forks_repo_head_hexsha": "36d33541736cb0bafe804306527c896e0e5c6259", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2015-06-21T19:10:16.000Z", "max_forks_repo_forks_event_max_datetime": "2015-08-26T09:39:10.000Z", "avg_line_length": 19.4634146341, "max_line_length": 50, "alphanum_fraction": 0.4837092732, "num_tokens": 403, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972684083608, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.6743501784084862}} {"text": "c-------------------------------------------------------------\nc PROGRAM : WHITE DWARF STARS\nc-------------------------------------------------------------\n program main\n implicit none\n real*8 h, rhoc, rmax\n\n rmax = 2.55d0\n write(*,*)'Enter rhoc'\n read(*,*) rhoc\nc\tcall euler(h, rhoc, rmax)\n call runge_kutta(h, rhoc, rmax)\n\n end\nc-------------------------------------------------------------\nc SUBROUTINE : EULER\nc-------------------------------------------------------------\n\n subroutine euler(h, rhoc, rmax)\n implicit none\n real*8 h, rhoc, rmax\n real*8 f, g, rho0, m0\n real*8 r, rho, m\n real*8 ri, rhoi, mi\n integer*4 n, i \n \n open(unit=1, file='e_rho.dat', status='unknown')\n open(unit=2, file='e_m.dat', status='unknown')\n\n n = nint(rmax/h)\n\n r = h\n m = m0(rhoc, h)\n rho = rho0(rhoc, h)\n\n do 100 i = 0, n, +1\n ri = r\n rhoi = rho\n mi = m\n\n r = ri + h\n rho = rhoi + h*f(ri,rhoi,mi)\n m = mi + h*g(ri, rhoi, mi)\n\n write(1,*)r, rho\n write(2,*)r, m\n100 continue\n\n close(unit=1)\n close(unit=2)\n\n end\n\nc-------------------------------------------------------------\nc SUBROUTINE : RUNGE_KUTTA\nc-------------------------------------------------------------\n\n subroutine runge_kutta(h, rhoc, rmax)\n implicit none\n real*8 h, rhoc, rmax\n real*8 f, g, rho0, m0\n real*8 r, rho, m\n real*8 ri, rhoi, mi, hon2\n real*8 f1, f2, f3, f4\n real*8 g1, g2, g3, g4\n integer*4 n, i \n \n open(unit=1, file='rho.dat', status='unknown')\n open(unit=2, file='m.dat', status='unknown')\n\n n = nint(rmax/h)\n hon2 = h/2.0d0\n\n r = h\n m = m0(rhoc, h)\n rho = rho0(rhoc, h)\n\n do 100 i = 0, n, +1\n ri = r\n rhoi = rho\n mi = m\n\n f1 = f(ri, rhoi, mi)\n g1 = g(ri, rhoi, mi)\n\n f2 = f(ri + hon2, rhoi + hon2*f1, mi + hon2*g1)\n g2 = g(ri + hon2, rhoi + hon2*f1, mi + hon2*g1)\n\n f3 = f(ri + hon2, rhoi + hon2*f2, mi + hon2*g2)\n g3 = g(ri + hon2, rhoi + hon2*f2, mi + hon2*g2)\n\n f4 = f(ri + h, rhoi + h*f3, mi + h*g3)\n g4 = g(ri + h, rhoi + h*f3, mi + h*g3)\n\n r = ri + h\n rho = rhoi + (h/6.0d0)*(f1 + 2*f2 + 2*f3 + f4)\n m = mi + (h/6.0d0)*(g1 + 2*g2 + 2*g3 + g4)\n\n write(1,*)r, rho\n write(2,*)r, m, (r*0.005553956), (r*0.005154071d0)\n100 continue\n\n close(unit=1)\n close(unit=2)\n\n end\n\nc-------------------------------------------------------------\nc FUNCTION : f\nc-------------------------------------------------------------\n\n double precision function f(r, rho, m)\n implicit none\n real*8 r, rho, m, x\n real*8 gama\n\n\tif (rho .lt. 0.0d0) then\n\t\twrite(*,*)'Rho < 0 : Stopping Program'\n\t\tstop\n\tendif \n\n f = -(m*rho)/(gama(rho**(1.0d0/3.0d0))*r**2.0d0)\n return\n\n end\n\nc-------------------------------------------------------------\nc FUNCTION : g\nc-------------------------------------------------------------\n\n double precision function g(r, rho, m)\n implicit none\n real*8 r, rho, m\n\n g = (r**2.0d0)*rho\n return\n\n end\n\nc-------------------------------------------------------------\nc FUNCTION : gama\nc-------------------------------------------------------------\n\n double precision function gama(x)\n implicit none\n real*8 x\n\n gama = (x**2.0d0)/(3.0d0*dsqrt(1.0d0 + x**2.0d0))\n return\n\n end\n\nc-------------------------------------------------------------\nc FUNCTION : m0\nc : initial value of m\nc : rhoc = central density\nc-------------------------------------------------------------\n\n double precision function m0(rhoc, h)\n implicit none\n real*8 rhoc, h\n\n m0 = rhoc*(h**3.0d0)/3.0d0\n return\n\n end\n\nc-------------------------------------------------------------\nc FUNCTION : rho0\nc : initial value of rho\nc : rhoc = central density\nc-------------------------------------------------------------\n\n double precision function rho0(rhoc, h)\n implicit none\n real*8 rhoc, h, x\n real*8 gama\n\n x = rhoc**(1.0d0/3.0d0)\n rho0 = rhoc*(1 - ((h**2.0d0)*rhoc)/(6*gama(x)) )\n return\n\n end\n", "meta": {"hexsha": "cf7c19194a1372d256de6157f94b425b474d1208", "size": 4508, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/star.f", "max_stars_repo_name": "mikepsn/white-dwarf-stars", "max_stars_repo_head_hexsha": "7c5251abbb8a8c5b0abab5dd1c73d6f7900bf8ff", "max_stars_repo_licenses": ["MIT"], "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/star.f", "max_issues_repo_name": "mikepsn/white-dwarf-stars", "max_issues_repo_head_hexsha": "7c5251abbb8a8c5b0abab5dd1c73d6f7900bf8ff", "max_issues_repo_licenses": ["MIT"], "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/star.f", "max_forks_repo_name": "mikepsn/white-dwarf-stars", "max_forks_repo_head_hexsha": "7c5251abbb8a8c5b0abab5dd1c73d6f7900bf8ff", "max_forks_repo_licenses": ["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.5, "max_line_length": 62, "alphanum_fraction": 0.3649068323, "num_tokens": 1342, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972684083609, "lm_q2_score": 0.7745833737577158, "lm_q1q2_score": 0.6743501693479999}} {"text": "module example2\n\nuse phaml\nimplicit none\n\nprivate\npublic setup_example2\n\nreal(my_real), save :: r0 = 0.7_my_real, &\n xc = 0.0_my_real, &\n yc = 0.0_my_real, &\n alpha = 20.0_my_real\n\ncontains\n\nsubroutine setup_example2()\nuse pde_pointers\ncall set_pde_pointers(pdecoefs, bconds, iconds, trues, truexs, trueys)\nend subroutine\n\nsubroutine pdecoefs(x,y,cxx,cxy,cyy,cx,cy,c,rs)\nreal(my_real), intent(in) :: x,y\nreal(my_real), intent(out) :: cxx(:,:),cxy(:,:),cyy(:,:),cx(:,:),cy(:,:), &\n c(:,:),rs(:)\n\nreal(my_real) :: rx2, ry2, r, rr, denom, denom2\n\ncxx(1,1) = 1.0_my_real\ncyy(1,1) = 1.0_my_real\nc(1,1) = 0.0_my_real\n\nrx2 = (x-xc)**2\nry2 = (y-yc)**2\nr = sqrt(rx2+ry2)\nrr = r-r0\ndenom = ((1+(alpha*rr)**2))**2\ndenom2 = r*(1+(alpha*rr)**2)\n\nrs(1) = 2*alpha**3*rr/denom - alpha/denom2\n\ncxy=0; cx=0; cy=0\n\nend subroutine pdecoefs\n\nsubroutine bconds(x,y,bmark,itype,c,rs)\nreal(my_real), intent(in) :: x,y\ninteger, intent(in) :: bmark\ninteger, intent(out) :: itype(:)\nreal(my_real), intent(out) :: c(:,:),rs(:)\nitype = DIRICHLET\nc = 0.0_my_real\nrs = trues(x,y,1,1)\nend subroutine bconds\n\nfunction iconds(x,y,comp,eigen)\nreal(my_real), intent(in) :: x,y\ninteger, intent(in) :: comp,eigen\nreal(my_real) :: iconds\niconds = 0.0_my_real\nend function iconds\n\nfunction trues(x,y,comp,eigen) ! real (my_real)\nreal(my_real), intent(in) :: x,y\ninteger, intent(in) :: comp,eigen\nreal (my_real) :: trues\ntrues = atan(alpha*(sqrt((x-xc)**2 + (y-yc)**2)-r0))\nend function trues\n\nfunction truexs(x,y,comp,eigen) ! real (my_real)\nreal(my_real), intent(in) :: x,y\ninteger, intent(in) :: comp,eigen\nreal (my_real) :: truexs\n\nreal(my_real) :: r\nr = sqrt((x-xc)**2+(y-yc)**2)\ntruexs = alpha*(x-xc)/(r*(1+(alpha*(r-r0))**2))\nend function truexs\n\nfunction trueys(x,y,comp,eigen) ! real (my_real)\nreal(my_real), intent(in) :: x,y\ninteger, intent(in) :: comp,eigen\nreal (my_real) :: trueys\n\nreal(my_real) :: r\nr = sqrt((x-xc)**2+(y-yc)**2)\ntrueys = alpha*(y-yc)/(r*(1+(alpha*(r-r0))**2))\nend function trueys\n\n\nend module\n", "meta": {"hexsha": "514908d90acf1f504ae6a00a02486409bf753b52", "size": 2080, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "phaml/example2.f90", "max_stars_repo_name": "qsnake/phaml", "max_stars_repo_head_hexsha": "8925b4c32657bbd9f81cd5f8f9d6739151c66fec", "max_stars_repo_licenses": ["mpich2"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-09-07T15:46:34.000Z", "max_stars_repo_stars_event_max_datetime": "2018-09-07T15:46:34.000Z", "max_issues_repo_path": "phaml/example2.f90", "max_issues_repo_name": "qsnake/phaml", "max_issues_repo_head_hexsha": "8925b4c32657bbd9f81cd5f8f9d6739151c66fec", "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": "phaml/example2.f90", "max_forks_repo_name": "qsnake/phaml", "max_forks_repo_head_hexsha": "8925b4c32657bbd9f81cd5f8f9d6739151c66fec", "max_forks_repo_licenses": ["mpich2"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.8571428571, "max_line_length": 75, "alphanum_fraction": 0.6259615385, "num_tokens": 771, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972549785201, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.6743501680059548}} {"text": "! various radial basis functions\n\nmodule phi\n\n implicit none\n\n private\n\n public :: phi_mq, phi_imq, phi_tps, phi_g\n\ncontains\n\n!---------------------------------- PHI_MQ -----------------------------------80\n! Multiquadratic radial basis function.\n!-----------------------------------------------------------------------------80\n subroutine phi_mq ( n, r, r0, v )\n\n use kinddefs, only : dp \n\n integer, intent(in) :: n\n real(dp), dimension(n), intent(in) :: r\n real(dp), intent(in) :: r0\n real(dp), dimension(n), intent(out) :: v\n\n real(dp) :: r02\n \n continue \n \n r02 = r0**2\n v(:) = sqrt( r(:)**2 + r02 )\n\n end subroutine phi_mq\n\n!---------------------------------- PHI_IMQ ----------------------------------80\n! Inverse multiquadratic radial basis function.\n!-----------------------------------------------------------------------------80\n subroutine phi_imq ( n, r, r0, v )\n\n use kinddefs, only : dp \n\n integer, intent(in) :: n\n real(dp), dimension(n), intent(in) :: r\n real(dp), intent(in) :: r0\n real(dp), dimension(n), intent(out) :: v\n\n real(dp) :: r02\n \n continue \n\n r02 = r0**2\n v(:) = 1.d0/sqrt( r(:)**2 + r02 )\n\n\n end subroutine phi_imq\n\n!---------------------------------- PHI_TPS ----------------------------------80\n! Thin plate spline radial basis function.\n!-----------------------------------------------------------------------------80\n subroutine phi_tps ( n, r, r0, v )\n\n use kinddefs, only : dp \n\n integer, intent(in) :: n\n real(dp), dimension(n), intent(in) :: r\n real(dp), intent(in) :: r0\n real(dp), dimension(n), intent(out) :: v\n\n v(:) = merge(r(:)**2 * log ( r(:) / r0 ), 0.d0, r(:) > 0.d0)\n\n end subroutine phi_tps\n\n!------------------------------------ PHI_G ----------------------------------80\n! Guassian radial basis function.\n!-----------------------------------------------------------------------------80\n subroutine phi_g ( n, r, r0, v )\n\n use kinddefs, only : dp \n\n integer, intent(in) :: n\n real(dp), dimension(n), intent(in) :: r\n real(dp), intent(in) :: r0\n real(dp), dimension(n), intent(out) :: v\n\n real(dp) :: rr02 \n\n continue\n\n rr02 = r0**(-2)\n v(:) = exp(-0.5d0*r(:)**2*rr02)\n\n end subroutine phi_g\n\nend module phi\n", "meta": {"hexsha": "e193be82bd7349a2b0512a6a23c7df804e452f6d", "size": 2402, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "phi.f90", "max_stars_repo_name": "nasa/rbf", "max_stars_repo_head_hexsha": "9e1d229f2f8a78670890d22aa3624632c9a92158", "max_stars_repo_licenses": ["AFL-1.1"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2019-11-13T09:33:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-28T18:51:49.000Z", "max_issues_repo_path": "phi.f90", "max_issues_repo_name": "nasa/rbf", "max_issues_repo_head_hexsha": "9e1d229f2f8a78670890d22aa3624632c9a92158", "max_issues_repo_licenses": ["AFL-1.1"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-07-05T17:49:16.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-05T17:49:19.000Z", "max_forks_repo_path": "phi.f90", "max_forks_repo_name": "nasa/rbf", "max_forks_repo_head_hexsha": "9e1d229f2f8a78670890d22aa3624632c9a92158", "max_forks_repo_licenses": ["AFL-1.1"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2019-11-03T08:52:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-13T15:57:55.000Z", "avg_line_length": 25.5531914894, "max_line_length": 80, "alphanum_fraction": 0.404662781, "num_tokens": 610, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972549785201, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.6743501680059548}} {"text": "! 'utility_mst.f90' contains a fortran functions for getting the degree from the\n! edge indices of a minimum spanning tree.\n\nsubroutine get_degree_for_index(index1, index2, number_of_nodes, number_of_edges, degree)\n ! Given the edge index this will compute the degree of each node.\n !\n ! Parameters\n ! ----------\n ! index1, index2 : array\n ! The index of the edges of a tree, where the '1' and '2' refer to the ends of each edge.\n ! number_of_nodes : integer\n ! The array integer length of the nodes used to construct the tree.\n ! number_of_edges : integer\n ! The array integer length of the edges forming the constructed tree.\n !\n ! Returns\n ! -------\n ! degree : array\n ! The degree for each node, i.e. the number of edges attached to each node.\u00df\n\n implicit none\n\n integer, intent(in) :: number_of_nodes, number_of_edges\n integer, intent(in) :: index1(number_of_edges), index2(number_of_edges)\n double precision, intent(out) :: degree(number_of_nodes)\n\n integer :: i\n\n do i = 1, number_of_nodes\n degree(i) = 0.\n end do\n\n do i = 1, number_of_edges\n degree(index1(i)+1) = degree(index1(i)+1) + 1.\n degree(index2(i)+1) = degree(index2(i)+1) + 1.\n end do\n\nend subroutine get_degree_for_index\n", "meta": {"hexsha": "06144e7c14e88b9b4437fd38ea4068a5df1e9f49", "size": 1295, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mistree/mst/utility_mst.f90", "max_stars_repo_name": "knaidoo29/MiSTree", "max_stars_repo_head_hexsha": "20ef822ca349d2cc8118bbeca277713f03e10cd2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 27, "max_stars_repo_stars_event_min_datetime": "2019-07-03T08:01:10.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T09:28:58.000Z", "max_issues_repo_path": "mistree/mst/utility_mst.f90", "max_issues_repo_name": "knaidoo29/MiSTree", "max_issues_repo_head_hexsha": "20ef822ca349d2cc8118bbeca277713f03e10cd2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 15, "max_issues_repo_issues_event_min_datetime": "2019-09-12T03:56:20.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-14T22:27:44.000Z", "max_forks_repo_path": "mistree/mst/utility_mst.f90", "max_forks_repo_name": "knaidoo29/MiSTree", "max_forks_repo_head_hexsha": "20ef822ca349d2cc8118bbeca277713f03e10cd2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2019-07-03T05:00:20.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-03T19:37:32.000Z", "avg_line_length": 33.2051282051, "max_line_length": 96, "alphanum_fraction": 0.6625482625, "num_tokens": 340, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934406, "lm_q2_score": 0.7745833737577158, "lm_q1q2_score": 0.6743501641467342}} {"text": "c****************************************************************\n subroutine latlon(elp,r_v,r_llh,i_type) \n\nc****************************************************************\nc** \nc** FILE NAME: latlon.f\nc** \nc** DATE WRITTEN:7/22/93 \nc** \nc** PROGRAMMER:Scott Hensley\nc** \nc** FUNCTIONAL DESCRIPTION:This program converts a vector to \nc** lat,lon and height above the reference ellipsoid or given a\nc** lat,lon and height produces a geocentric vector. \nc** \nc** ROUTINES CALLED:none\nc** \nc** NOTES: none\nc** \nc** UPDATE LOG:\nc** \nc****************************************************************\n \n implicit none\n \nc INPUT VARIABLES:\n integer i_type !1=lat,lon to vector,2= vector to lat,lon\nc\tstructure /ellipsoid/ \nc\t real*8 r_a \nc\t real*8 r_e2\nc\tend structure\nc\trecord /ellipsoid/ elp\n \n\ttype ellipsoid\n sequence\n\t real (8) r_a \n\t real (8) r_e2\n\tend type ellipsoid\n\ttype (ellipsoid) elp\n\n real*8 r_v(3) !geocentric vector (meters)\n real*8 r_llh(3) !latitude (deg -90 to 90),longitude (deg -180 to 180),height\n \nc OUTPUT VARIABLES: see input\n\nc LOCAL VARIABLES:\n integer i_ft\n real*8 pi,r_dtor,r_re,r_q2,r_q3,r_b,r_q\n real*8 r_p,r_tant,r_theta,r_a,r_e2\n\nc DATA STATEMENTS:\n data pi /3.141592653589793238d0/\n data r_dtor /1.74532925199d-2/\n\nC FUNCTION STATEMENTS:\n\nc PROCESSING STEPS:\n\n r_a = elp%r_a\n r_e2 = elp%r_e2\n\n if(i_type .eq. 1)then !convert lat,lon to vector\n \n r_re = r_a/sqrt(1.d0 - r_e2*sin(r_llh(1))**2)\n \n r_v(1) = (r_re + r_llh(3))*cos(r_llh(1))*cos(r_llh(2))\n r_v(2) = (r_re + r_llh(3))*cos(r_llh(1))*sin(r_llh(2))\n r_v(3) = (r_re*(1.d0-r_e2) + r_llh(3))*sin(r_llh(1)) \n \n elseif(i_type .eq. 2)then !convert vector to lat,lon \n \n r_q2 = 1.d0/(1.d0 - r_e2)\n r_q = sqrt(r_q2)\n r_q3 = r_q2 - 1.d0\n r_b = r_a*sqrt(1.d0 - r_e2)\n \n r_llh(2) = atan2(r_v(2),r_v(1))\n \n r_p = sqrt(r_v(1)**2 + r_v(2)**2)\n r_tant = (r_v(3)/r_p)*r_q\n r_theta = atan(r_tant)\n r_tant = (r_v(3) + r_q3*r_b*sin(r_theta)**3)/\n + (r_p - r_e2*r_a*cos(r_theta)**3)\n r_llh(1) = atan(r_tant)\n r_re = r_a/sqrt(1.d0 - r_e2*sin(r_llh(1))**2)\n r_llh(3) = r_p/cos(r_llh(1)) - r_re \n \n endif\n \n end \n\n", "meta": {"hexsha": "9e4abbe6879cfa341aa9d976e9b9a94db47ab482", "size": 2624, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "contrib/alos2proc_f/src/latlon.f", "max_stars_repo_name": "vincentschut/isce2", "max_stars_repo_head_hexsha": "1557a05b7b6a3e65abcfc32f89c982ccc9b65e3c", "max_stars_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_stars_count": 1133, "max_stars_repo_stars_event_min_datetime": "2022-01-07T21:24:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-07T21:33:08.000Z", "max_issues_repo_path": "contrib/alos2proc_f/src/latlon.f", "max_issues_repo_name": "vincentschut/isce2", "max_issues_repo_head_hexsha": "1557a05b7b6a3e65abcfc32f89c982ccc9b65e3c", "max_issues_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_issues_count": 276, "max_issues_repo_issues_event_min_datetime": "2019-02-10T07:18:28.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:45:55.000Z", "max_forks_repo_path": "contrib/alos2proc_f/src/latlon.f", "max_forks_repo_name": "vincentschut/isce2", "max_forks_repo_head_hexsha": "1557a05b7b6a3e65abcfc32f89c982ccc9b65e3c", "max_forks_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_forks_count": 235, "max_forks_repo_forks_event_min_datetime": "2019-02-10T05:00:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T07:37:24.000Z", "avg_line_length": 28.5217391304, "max_line_length": 101, "alphanum_fraction": 0.4756097561, "num_tokens": 839, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037343628702, "lm_q2_score": 0.7279754548076478, "lm_q1q2_score": 0.674326382312833}} {"text": "PROGRAM LUCAS_LEHMER\n IMPLICIT NONE\n\n INTEGER, PARAMETER :: i64 = SELECTED_INT_KIND(18)\n INTEGER(i64) :: s, n\n INTEGER :: i, exponent\n\n DO exponent = 2, 31\n IF (exponent == 2) THEN\n s = 0\n ELSE\n s = 4\n END IF\n n = 2_i64**exponent - 1\n DO i = 1, exponent-2\n s = MOD(s*s - 2, n)\n END DO\n IF (s==0) WRITE(*,\"(A,I0,A)\") \"M\", exponent, \" is PRIME\"\n END DO\n\nEND PROGRAM LUCAS_LEHMER\n", "meta": {"hexsha": "3a1477e626447191c079199bc6a3b8f4417a275b", "size": 432, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Lucas-Lehmer-test/Fortran/lucas-lehmer-test.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/Lucas-Lehmer-test/Fortran/lucas-lehmer-test.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/Lucas-Lehmer-test/Fortran/lucas-lehmer-test.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 19.6363636364, "max_line_length": 61, "alphanum_fraction": 0.5439814815, "num_tokens": 166, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037323284109, "lm_q2_score": 0.7279754489059774, "lm_q1q2_score": 0.6743263753650572}} {"text": "module poisson_assembly\nuse types, only: dp\nuse linalg, only: inv\nuse utils, only: assert, stop_error\nuse constants, only: pi\nimplicit none\nprivate\npublic assemble_2d, sol_error\n\ncontains\n\nreal(dp) elemental function f(x, y)\nreal(dp), intent(in) :: x, y\nf = 2 * pi**2 * sin(pi*x) * sin(pi*y)\nend function\n\nreal(dp) elemental function exact_sol(x, y)\nreal(dp), intent(in) :: x, y\nexact_sol = sin(pi*x) * sin(pi*y)\nend function\n\nsubroutine assemble_2d(xin, nodes, elems, ib, xiq, wtq, phihq, dphihq, Am, rhs)\n! Assemble on a 2D rectangular uniform mesh\nreal(dp), intent(in):: xin(:), nodes(:, :), xiq(:), wtq(:, :), &\n phihq(:, :), dphihq(:, :)\ninteger, intent(in):: elems(:, :), ib(:, :, :)\nreal(dp), intent(out):: Am(:,:), rhs(:)\ninteger :: Ne, p, e, i, j, iqx, iqy\nreal(dp), dimension(size(xiq), size(xiq), size(xin), size(xin)) :: &\n phi_v, phi_dx, phi_dy\nreal(dp) :: x(size(xiq)), y(size(xiq))\nreal(dp) :: fq(size(xiq), size(xiq)), xp(size(xiq)), yp(size(xiq))\nreal(dp) :: lx, ly\ninteger :: ax, ay, bx, by\nreal(dp) :: jacx, jacy, jac_det\n\nNe = size(elems, 2)\np = size(xin) - 1\n! 2D shape functions\ndo ay = 1, p+1\n do ax = 1, p+1\n do iqy = 1, size(xiq)\n do iqx = 1, size(xiq)\n phi_v(iqx, iqy, ax, ay) = phihq(iqx, ax)*phihq(iqy, ay)\n phi_dx(iqx, iqy, ax, ay) = dphihq(iqx, ax)*phihq(iqy, ay)\n phi_dy(iqx, iqy, ax, ay) = phihq(iqx, ax)*dphihq(iqy, ay)\n end do\n end do\n end do\nend do\nAm=0; rhs=0\n! Precalculate as much as possible:\nlx = nodes(1, elems(3, 1)) - nodes(1, elems(1, 1)) ! Element sizes\nly = nodes(2, elems(3, 1)) - nodes(2, elems(1, 1))\njacx = lx/2\njacy = ly/2\njac_det = abs(jacx*jacy)\nxp = (xiq + 1) * jacx\nyp = (xiq + 1) * jacy\nphi_dx = phi_dx / jacx\nphi_dy = phi_dy / jacy\ndo e = 1, Ne\n x = xp + nodes(1, elems(1, e))\n y = yp + nodes(2, elems(1, e))\n do iqy = 1, size(xiq)\n do iqx = 1, size(xiq)\n fq(iqx, iqy) = f(x(iqx), y(iqy))\n end do\n end do\n fq = fq * jac_det * wtq\n do by = 1, p+1\n do bx = 1, p+1\n j = ib(bx, by, e)\n if (j==0) cycle\n do ay = 1, p+1\n do ax = 1, p+1\n i = ib(ax, ay, e)\n if (i == 0) cycle\n if (j > i) cycle\n Am(i,j) = Am(i,j) + sum( &\n (phi_dx(:, :, ax, ay)*phi_dx(:, :, bx, by) &\n +phi_dy(:, :, ax, ay)*phi_dy(:, :, bx, by)) &\n * jac_det * wtq)\n end do\n end do\n rhs(j) = rhs(j) + sum(phi_v(:, :, bx, by) * fq)\n end do\n end do\nend do\ndo j = 1, size(Am, 2)\n do i = 1, j-1\n Am(i, j) = Am(j, i)\n end do\nend do\nend subroutine\n\nreal(dp) function sol_error(nodes, elems, xiq, wtq, solq) result(r)\nreal(dp), intent(in) :: nodes(:, :)\ninteger, intent(in) :: elems(:, :)\nreal(dp), intent(in) :: xiq(:), wtq(:,:), solq(:, :, :)\nreal(dp) :: fq(size(xiq), size(xiq)), x(size(xiq)), y(size(xiq))\nreal(dp) :: jacx, jacy, l(2), jac_det\ninteger :: e, iqx, iqy, Ne\nNe = size(elems, 2)\nr = 0\ndo e = 1, Ne\n ! l is the diagonal vector:\n l = nodes(:, elems(3, e)) - nodes(:, elems(1, e))\n ! Assume rectangular shape:\n jacx = l(1)/2\n jacy = l(2)/2\n jac_det = abs(jacx*jacy)\n x = (xiq + 1) * jacx + nodes(1, elems(1, e))\n y = (xiq + 1) * jacy + nodes(2, elems(1, e))\n do iqy = 1, size(xiq)\n do iqx = 1, size(xiq)\n fq(iqx, iqy) = exact_sol(x(iqx), y(iqy))\n end do\n end do\n fq = fq-solq(:, :, e)\n r = r + sum(fq*fq * jac_det * wtq)\nend do\nr = sqrt(r)\nend function\n\nend module\n\n! ------------------------------------------------------------------------\n\nmodule poisson2d_code\n\nuse types, only: dp\nuse feutils, only: phih, dphih\nuse fe_mesh, only: cartesian_mesh_2d, cartesian_mesh_3d, &\n define_connect_tensor_2d, c2fullc_2d, fe2quad_2d\nuse poisson_assembly, only: assemble_2d, sol_error\nuse feutils, only: get_parent_nodes, get_parent_quad_pts_wts\nuse linalg, only: solve\nuse constants, only: pi\nimplicit none\n\ncontains\n\nreal(dp) function logg(Nex, Ney, p) result(error)\ninteger, intent(in) :: p\n\ninteger :: Nn, Ne\n! nodes(:, i) are the (x,y) coordinates of the i-th mesh node\nreal(dp), allocatable :: nodes(:, :)\ninteger, allocatable :: elems(:, :) ! elems(:, i) are nodes of the i-th element\ninteger :: Nq, Nb\nreal(dp), allocatable :: xin(:), xiq(:), wtq(:), A(:, :), rhs(:), sol(:), &\n fullsol(:), solq(:, :, :), wtq2(:, :), phihq(:, :), dphihq(:, :)\ninteger, allocatable :: in(:, :, :), ib(:, :, :)\ninteger :: i, j\ninteger, intent(in) :: Nex, Ney\n\ncall cartesian_mesh_2d(Nex, Ney, [0.0_dp, 0._dp], [1._dp, 1._dp], nodes, elems)\nNn = size(nodes, 2)\nNe = size(elems, 2)\nNq = p+1\n\nprint *, \"Number of nodes:\", Nn\nprint *, \"Number of elements:\", Ne\nprint *, \"Nq =\", Nq\nprint *, \"p =\", p\nallocate(xin(p+1))\ncall get_parent_nodes(2, p, xin)\nallocate(xiq(Nq), wtq(Nq), wtq2(Nq, Nq))\ncall get_parent_quad_pts_wts(1, Nq, xiq, wtq)\nforall(i=1:Nq, j=1:Nq) wtq2(i, j) = wtq(i)*wtq(j)\nallocate(phihq(size(xiq), size(xin)))\nallocate(dphihq(size(xiq), size(xin)))\n! Tabulate parent basis at quadrature points\nforall(i=1:size(xiq), j=1:size(xin)) phihq(i, j) = phih(xin, j, xiq(i))\nforall(i=1:size(xiq), j=1:size(xin)) dphihq(i, j) = dphih(xin, j, xiq(i))\n\ncall define_connect_tensor_2d(Nex, Ney, p, 1, in)\ncall define_connect_tensor_2d(Nex, Ney, p, 2, ib)\nNb = maxval(ib)\nprint *, \"DOFs =\", Nb\nallocate(A(Nb, Nb), rhs(Nb), sol(Nb), fullsol(maxval(in)), solq(Nq, Nq, Ne))\n\ncall assemble_2d(xin, nodes, elems, ib, xiq, wtq2, phihq, dphihq, A, rhs)\nsol = solve(A, rhs)\ncall c2fullc_2d(in, ib, sol, fullsol)\ncall fe2quad_2d(elems, xin, xiq, phihq, in, fullsol, solq)\nerror = sol_error(nodes, elems, xiq, wtq2, solq)\n\nend function\n\nend module\n\n\n! ------------------------------------------------------------------------\n\n\nprogram poisson2d\nuse types, only: dp\nuse poisson2d_code, only: logg\n\nreal(dp) :: error\ninteger :: i, N\nreal(dp) :: t1, t2\n\nN = 1\ncall cpu_time(t1)\ndo i = 1, N\n error = logg(1, 1, 8)\nend do\ncall cpu_time(t2)\nprint *, \"L2 error:\", error\nprint \"('Total time: ', f10.8)\", (t2-t1) / N\nend program\n", "meta": {"hexsha": "3c8f990f4bc66fd3a194b9f3ed5d498fbe115468", "size": 6089, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/fem/poisson2d.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/tests/fem/poisson2d.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/tests/fem/poisson2d.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": 28.3209302326, "max_line_length": 79, "alphanum_fraction": 0.5639678108, "num_tokens": 2267, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480667, "lm_q2_score": 0.743168019989179, "lm_q1q2_score": 0.6742854233353863}} {"text": " subroutine spline(np,x,y,ddy,work,mode,dy)\nC\nC Normal Spline y''(1)=y''(np)=0.\nC ddy returns y''(i)/6.\nC y=A y(i)+B y(i+1)+C ddy(i)+D ddy(i+1)\nC y'=(y(i+1)-y(i))/(x(i+1)-x(i))\nC -(3A^2-1)(x(i+1)-x(i))ddy(i)\nC +(3B^2-1)(x(i+1)-x(i))ddy(i+1)\nC A=(x(i+1)-x)/(x(i+1)-x(i))\nC B=1-A=(x-x(i))/(x(i+1)-x(i))\nC C=(A^3-A)(x(i+1)-x(i))^2\nC D=(B^3-B)(x(i+1)-x(i))^2\nC\n implicit none\n integer*4 np,i,mode\n real*8 ,intent(in):: x(np),y(np),dy(2)\n real*8 ,intent(out):: ddy(np),work(np)\n real*8 dy1a,ddy1\n real*8, allocatable :: dddy(:)\n real*8 f\n if(np .le. 2)then\n ddy=0.d0\n return\n endif\n allocate (dddy(np))\n if(mode .eq. 0 .or. mode .eq. 2)then\n ddy(1)=0.d0\n ddy(2)=(y(3)-y(2))/(x(3)-x(2))-(y(2)-y(1))/(x(2)-x(1))\n work(2)=(x(3)-x(1))*2.d0\n elseif(mode .eq. 1 .or. mode .eq. 3)then\n work(1)=(x(2)-x(1))*.5d0\n work(2)=(x(3)-x(1))*2.d0-work(1)\n ddy(1)=.5d0*((y(2)-y(1))/work(1)/2.d0-dy(1))\n ddy(2)=(y(3)-y(2))/(x(3)-x(2))-(y(2)-y(1))/(x(2)-x(1))-ddy(1)\n elseif(mode .eq. 4)then\n dy1a=(y(2)-y(1)+y(np)-y(np-1))/(x(2)-x(1)+x(np)-x(np-1))\n work(1)=(x(2)-x(1))*.5d0\n work(2)=(x(3)-x(1))*2.d0-work(1)\n ddy(1)=.5d0*((y(2)-y(1))/work(1)/2.d0-dy1a)\n ddy(2)=(y(3)-y(2))/(x(3)-x(2))-(y(2)-y(1))/(x(2)-x(1))-ddy(1)\n dddy(1)=-0.5d0\n dddy(2)= 0.5d0\n do i=2,np-2\n f=x(i+1)-x(i)\n work(i+1)=(x(i+2)-x(i))*2.d0-f**2/work(i)\n ddy(i+1) =(y(i+2)-y(i+1))/(x(i+2)-x(i+1))\n 1 -(y(i+1)-y(i))/f-f/work(i)*ddy(i)\n dddy(i+1)=-f/work(i)*dddy(i)\n enddo\n work(np)=x(np)-x(np-1)\n ddy(np)=dy1a-(y(np)-y(np-1))/work(np)\n ddy(np-1)=(ddy(np-1)-ddy(np)*.5d0)/\n $ (work(np-1)-.5d0*work(np))\n ddy(np)=(ddy(np)/work(np)-ddy(np-1))*.5d0\n dddy(np-1)=(dddy(np-1)-.5d0)/\n $ (work(np-1)-.5d0*work(np))\n dddy(np)=(1.d0/work(np)-dddy(np-1))*.5d0\n do i=np-2,2,-1\n ddy(i) =( ddy(i)- ddy(i+1)*(x(i+1)-x(i)))/work(i)\n dddy(i)=(dddy(i)-dddy(i+1)*(x(i+1)-x(i)))/work(i)\n enddo\n ddy(1) =(ddy(1)/work(1)- ddy(2))*.5d0\n dddy(1)=(-0.5d0/work(1)-dddy(2))*.5d0\n if(dddy(1) .ne. dddy(np))then\n ddy1=-(ddy(np)-ddy(1))/(dddy(np)-dddy(1))\n ddy=ddy+ddy1*dddy\n endif\n deallocate (dddy)\n return\n endif\n do i=2,np-2\n f=x(i+1)-x(i)\nc write(*,'(a,i4,1p5g12.5)')'spline ',\nc $ i,f,work(i),x(i),x(i+1),x(i+2)\n work(i+1)=(x(i+2)-x(i))*2.d0-f**2/work(i)\n ddy(i+1)=(y(i+2)-y(i+1))/(x(i+2)-x(i+1))\n 1 -(y(i+1)-y(i))/f-f/work(i)*ddy(i)\n enddo\n if(mode .eq. 0 .or. mode .eq. 1)then\n ddy(np)=0.d0\n ddy(np-1)=ddy(np-1)/work(np-1)\n elseif(mode .eq. 2 .or. mode .eq. 3)then\n work(np)=x(np)-x(np-1)\n ddy(np)=dy(2)-(y(np)-y(np-1))/work(np)\n ddy(np-1)=(ddy(np-1)-ddy(np)*.5d0)/\n $ (work(np-1)-.5d0*work(np))\n ddy(np)=(ddy(np)/work(np)-ddy(np-1))*.5d0\n endif\n do i=np-2,2,-1\n ddy(i)=(ddy(i)-ddy(i+1)*(x(i+1)-x(i)))/work(i)\nc write(*,*)'spline ',i,work(i),ddy(i)\n enddo\n if(mode .eq. 1 .or. mode .eq. 3)then\n ddy(1)=(ddy(1)/work(1)-ddy(2))*.5d0\n endif\n deallocate (dddy)\n return\n end\n\n subroutine spline1(np,y,ddy,work,mode1,mode2)\nC\nC Spline when dx=const.=1\nC Normal Spline y''(1)=y''(np)=0.\nC ddy returns y''(i)/6.\nC y=A y(i)+B y(i+1)+C ddy(i)+D ddy(i+1)\nC y'=(y(i+1)-y(i))\nC -(3A^2-1)ddy(i)\nC +(3B^2-1)ddy(i+1)\nC A=(x(i+1)-x)\nC B=1-A=(x-x(i))\nC C=(A^3-A)\nC D=(B^3-B)\nC\n implicit none\n integer*4 ,intent(in)::np,mode1,mode2\n integer*4 i\n real*8 ,intent(in)::y(np)\n real*8 ,intent(out)::ddy(np),work(np)\n if(mode1 .eq. 0)then\n ddy(1)=0.d0\n if(np .le. 2)then\n ddy(2)=0.d0\n return\n endif\n ddy(2)=y(3)-2.d0*y(2)+y(1)\n work(2)=4.d0\n elseif(mode1 .eq. 1)then\n work(1)=.5d0\n work(2)=3.5d0\n ddy(1)=.5d0*(y(2)-y(1)-ddy(1))\n ddy(2)=y(3)-2.d0*y(2)+y(1)-ddy(1)\n elseif(mode1 .eq. 2)then\n ddy(2)=y(3)-2.d0*y(2)+y(1)-ddy(1)\n work(2)=4.d0\n endif\n do i=2,np-2\n work(i+1)=4.d0-1.d0/work(i)\n ddy(i+1)=y(i+2)-2.d0*y(i+1)+y(i)\n 1 -ddy(i)/work(i)\n enddo\n if(mode2 .eq. 0)then\n ddy(np)=0.d0\n ddy(np-1)=ddy(np-1)/work(np-1)\n elseif(mode2 .eq. 1)then\n ddy(np)=ddy(np)-(y(np)-y(np-1))\n ddy(np-1)=(ddy(np-1)-ddy(np)*.5d0)/\n $ (work(np-1)-.5d0)\n ddy(np)=(ddy(np)-ddy(np-1))*.5d0\n elseif(mode2 .eq. 2)then\n ddy(np-1)=(ddy(np-1)-ddy(np))/work(np-1)\n endif\n do 20 i=np-2,2,-1\n ddy(i)=(ddy(i)-ddy(i+1))/work(i)\n20 continue\n if(mode1 .eq. 1)then\n ddy(1)=ddy(1)-ddy(2)*.5d0\n endif\n return\n end\n\n real*8 function splint1(np,y,mode1,mode2,dy)\n implicit none\n integer*4 , intent(in)::np,mode1,mode2\nc integer*4 i\n real*8 ,intent(in)::y(np),dy(2)\nc real*8 s\n real*8,allocatable:: work(:),ddy(:)\n allocate (work(np),ddy(np))\n ddy(1)=dy(1)\n ddy(np)=dy(2)\n call spline1(np,y,ddy,work,mode1,mode2)\n splint1=(y(1)+y(np)-.5d0*(ddy(1)+ddy(np)))*.5d0\n $ +sum(y(2:np-1)-ddy(2:np-1)*.5d0)\n deallocate (work,ddy)\n return\n end\n\n real*8 function splint(f,x0,x1,mode,dy,eps,epsabs,n0)\n implicit none\n integer*4 nmax,mode\n parameter (nmax=8192)\n integer*4 n,k,k1,i,i1\n integer*4 , intent(in)::n0\n real*8 , external:: f\n real*8 , intent(in)::x0,x1,eps,epsabs,dy(2)\n real*8 , allocatable::x(:,:),y(:,:),ddy(:),work(:)\n real*8 xi,xstep,sddy,s,s0,dx,dx2,s20,s2,ddyi\n logical*4 first\n allocate (x(nmax,2),y(nmax,2),ddy(nmax),work(nmax))\n first=.true.\n n=max(n0,4)\n k=1\n xi=x0\n xstep=(x1-x0)/(n-1)\n s0=0.d0\n do i=1,n\n x(i,1)=xi\n y(i,1)=f(xi)\n xi=xi+xstep\n s0=s0+y(i,1)\n enddo\n s0=(s0-.5d0*(y(1,1)+y(n,1)))*xstep\n s20=s0\n 1 call spline(n,x(1,k),y(1,k),ddy,work,mode,dy)\n s=0.d0\n sddy=0.d0\n do i=1,n-1\n dx=x(i+1,k)-x(i,k)\n dx2=.5d0*dx**2\n s=s+(y(i+1,k)+y(i,k)-(ddy(i+1)+ddy(i))*dx2)*dx\n ddyi=merge(-(ddy(i)-ddy(i-1))/(x(i,k)-x(i-1,k)),0.d0,\n $ i .gt. 1)\n if(i .lt. n-1)then\n ddyi=ddyi+(ddy(i+2)-ddy(i+1))/(x(i+2,k)-x(i+1,k))\n endif\n work(i)=abs(ddyi)*dx2**2\n sddy=sddy+work(i)\n enddo\n s=s*.5d0\n s2=merge(s,(4.d0*s-s0)/3.d0,first)\nc write(*,*)n,s2,s\n if(abs(s2-s20) .le. max(eps*s20,epsabs))then\n splint=s2\n deallocate (x,y,ddy,work)\n return\n endif\n first=.false.\n sddy=sddy/(n-1)\n k1=3-k\n x(1,k1)=x(1,k)\n y(1,k1)=y(1,k)\n i1=1\n do i=1,n-1\n if(work(i) .ge. sddy)then\n i1=i1+1\n x(i1,k1)=(x(i,k)+x(i+1,k))*.5d0\n y(i1,k1)=f(x(i1,k1))\n endif\n i1=i1+1\n x(i1,k1)=x(i+1,k)\n y(i1,k1)=y(i+1,k)\n if(i1 .ge. nmax-2)then\n go to 9000\n endif\n enddo\n k=k1\n n=i1\n s0=s\n s20=s2\n go to 1\n 9000 write(*,*)'Splint convergence failed. ',s,s0\n splint=s2\n deallocate (x,y,ddy,work)\n return\n end\n\n subroutine spline1m(m,md,np,y,ddy,work)\nC\nC Spline when dx=const.=1, for vector.\nC Normal Spline y''(1)=y''(np)=0.\nC ddy returns y''(i)/6.\nC y=A y(i)+B y(i+1)+C ddy(i)+D ddy(i+1)\nC y'=(y(i+1)-y(i))\nC -(3A^2-1)ddy(i)\nC +(3B^2-1)ddy(i+1)\nC A=(x(i+1)-x)\nC B=1-A=(x-x(i))\nC C=(A^3-A)\nC D=(B^3-B)\nC\n implicit none\n integer*4 np,i,m,j,md\n real*8 y(md,np),ddy(md,np),work(np)\n do j=1,m\n ddy(j,1)=0.d0\n ddy(j,2)=y(j,3)-2.d0*y(j,2)+y(j,1)\n enddo\n work(2)=4.d0\n do 10 i=2,np-2\n work(i+1)=4.d0-1.d0/work(i)\n do j=1,m\n ddy(j,i+1)=y(j,i+2)-2.d0*y(j,i+1)+y(j,i)\n 1 -ddy(j,i)/work(i)\n enddo\n10 continue\n do j=1,m\n ddy(j,np)=0.d0\n ddy(j,np-1)=ddy(j,np-1)/work(np-1)\n enddo\n do 20 i=np-2,2,-1\n do j=1,m\n ddy(j,i)=(ddy(j,i)-ddy(j,i+1))/work(i)\n enddo\n20 continue\n return\n end\n\n subroutine tfspline(isp1,kx,irtc)\n use tfstk\n implicit none\n type (sad_descriptor) kx,kd,k1,k2\n type (sad_dlist), pointer :: klx,kld\n integer*8 ka1,ka2,ix,iy,iddy,ka\n integer*4 isp1,irtc,itfmessage,n,m,mode\n real*8 dy(2)\n type (sad_descriptor), save :: kxperiodic\n data kxperiodic%k /0/\n if(kxperiodic%k .eq. 0)then\n kxperiodic=kxsymbolz('`Periodic',9)\n endif\n mode=0\n if(isp .eq. isp1+2)then\n call tfgetoption('Derivative',ktastk(isp),kd,irtc)\n if(irtc .ne. 0)then\n if(irtc .eq. -1)then\n go to 9100\n endif\n return\n endif\n if(tfsameq(kd,kxperiodic))then\n mode=4\n else\n if(ktfnonlistq(kd,kld))then\n go to 9100\n endif\n if(kld%nl .ne. 2)then\n go to 9100\n endif\n k1=kld%dbody(1)\n if(ktfoperq(k1,ka1))then\n if(ka1 .ne. mtfnull)then\n go to 9100\n endif\n elseif(ktfnonrealq(k1,dy(1)))then\n go to 9100\n else\n mode=1\n endif\n k2=kld%dbody(2)\n if(ktfoperq(k2,ka2))then\n if(ka2 .ne. mtfnull)then\n go to 9100\n endif\n elseif(ktfnonrealq(k2,dy(2)))then\n go to 9100\n else\n mode=mode+2\n endif\n endif\n elseif(isp .ne. isp1+1)then\n go to 9100\n endif\n call tfmsize(ktastk(isp1+1),n,m,irtc)\n if(irtc .ne. 0)then\n return\n endif\n if(n .ne. 2)then\n go to 9000\n endif\n ka=ktfaddr(ktastk(isp1+1))\n ix=ktfaddr(klist(ka+1))\n iy=ktfaddr(klist(ka+2))\n iddy=ktavaloc(0,max(m,3))+1\n call spline2(m,\n $ rlist(ix+1:ix+m),\n $ rlist(iy+1:iy+m),\n $ rlist(iddy:iddy+m-1),mode,dy)\n kx=kxadaloc(-1,3,klx)\n klx%dbody(1)%k=ktflist+ktfcopy1(ix)\n klx%dbody(2)%k=ktflist+ktfcopy1(iy)\n klx%dbody(3)%k=ktflist+iddy-1\n irtc=0\n return\n 9000 irtc=itfmessage(9,'General::wrongval',\n $ '\"Argument\",\"{{x1, ..}, {y1, ..}}\"')\n return\n 9100 irtc=itfmessage(9,'General::narg','\"1 + Derivative->{dy1,dy2}\"')\n return\n end\n\n subroutine spline2(m,x,y,ddy,mode,dy)\n implicit none\n integer*4 m,mode\n real*8 x(m),y(m),ddy(m),work(m),dy(2)\n call spline(m,x,y,ddy,work,mode,dy)\n return\n end\n\n subroutine tffindindex(isp1,kx,irtc)\n use tfstk\n implicit none\n type (sad_descriptor) kx\n type (sad_dlist), pointer ::kl\n type (sad_rlist), pointer ::klr,kll\n integer*4 isp1,irtc,itfmessage,i1,i2,ih,n,i,m\n real*8 x\n if(isp1+2 .ne. isp)then\n irtc=itfmessage(9,'General::narg','\"2\"')\n return\n endif\n if(.not. tflistq(dtastk(isp1+1),kl))then\n irtc=itfmessage(9,'General::wrongval','\"#1\",\"List\"')\n return\n endif\n if(ktfnonreallistqo(kl))then\n irtc=itfmessage(9,'General::wrongval','\"#1\",\"List of Reals\"')\n return\n endif\n if(ktfrealq(ktastk(isp)))then\n i1=1\n i2=kl%nl\n x=rtastk(isp)\n irtc=0\n do while(i2 .gt. i1+1)\n ih=i1+(i2-i1)/2\n if(kl%rbody(ih) .eq. x)then\n kx=dfromr(dble(ih))\n return\n elseif(kl%rbody(ih) .gt. x)then\n i2=ih\n else\n i1=ih\n endif\n enddo\n kx=dfromr(dble(i1))\n elseif(tfreallistq(ktastk(isp),kll))then\n n=kll%nl\n m=kl%nl\n kx=kxavaloc(-1,n,klr)\n i1=1\n do i=1,n\n i2=min(i1+1,m)\n x=kll%rbody(i)\n if(x .lt. kl%rbody(i1))then\n i2=i1\n i1=1\n elseif(x .eq. kl%rbody(i2))then\n i1=i2\n elseif(x .gt. kl%rbody(i2))then\n i1=i2\n i2=m\n endif\n do while(i2 .gt. i1+1)\n ih=i1+(i2-i1)/2\n if(kl%rbody(ih) .eq. x)then\n i1=ih\n exit\n elseif(kl%rbody(ih) .gt. x)then\n i2=ih\n else\n i1=ih\n endif\n enddo\n klr%rbody(i)=min(i1,m-1)\n enddo\n irtc=0\n else\n irtc=itfmessage(9,'General::wrongval',\n $ '\"#2\",\"Real or list of Reals\"')\n endif\n return\n end\n", "meta": {"hexsha": "bbe124d7b4a30388960d11452c636027e6661659", "size": 12879, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/spline.f", "max_stars_repo_name": "noboruatkek/SAD", "max_stars_repo_head_hexsha": "3881a190af8903537774c57b56963ffc94cfc039", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2019-04-01T15:54:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-09T16:47:20.000Z", "max_issues_repo_path": "src/spline.f", "max_issues_repo_name": "noboruatkek/SAD", "max_issues_repo_head_hexsha": "3881a190af8903537774c57b56963ffc94cfc039", "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/spline.f", "max_forks_repo_name": "noboruatkek/SAD", "max_forks_repo_head_hexsha": "3881a190af8903537774c57b56963ffc94cfc039", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2017-03-15T08:52:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-19T08:06:40.000Z", "avg_line_length": 27.8164146868, "max_line_length": 70, "alphanum_fraction": 0.4644770557, "num_tokens": 5363, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312226373181, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6742854153024049}} {"text": " Program dspgv_example\n\n! DSPGV Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_interfaces, Only: dlansp, dspgv, dtpcon\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nin = 5, nout = 6\n Character (1), Parameter :: uplo = 'U'\n! .. Local Scalars ..\n Real (Kind=dp) :: anorm, bnorm, eps, rcond, rcondb, t1, t2\n Integer :: i, info, j, n\n! .. Local Arrays ..\n Real (Kind=dp), Allocatable :: ap(:), bp(:), eerbnd(:), w(:), work(:)\n Real (Kind=dp) :: dummy(1, 1)\n Integer, Allocatable :: iwork(:)\n! .. Intrinsic Procedures ..\n Intrinsic :: abs, epsilon\n! .. Executable Statements ..\n Write (nout, *) 'DSPGV Example Program Results'\n Write (nout, *)\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n\n\n Allocate (ap((n*(n+1))/2), bp((n*(n+1))/2), eerbnd(n), w(n), work(3*n), &\n iwork(n))\n\n! Read the upper or lower triangular parts of the matrices A and\n! B from data file\n\n If (uplo=='U') Then\n Read (nin, *)((ap(i+(j*(j-1))/2),j=i,n), i=1, n)\n Read (nin, *)((bp(i+(j*(j-1))/2),j=i,n), i=1, n)\n Else If (uplo=='L') Then\n Read (nin, *)((ap(i+((2*n-j)*(j-1))/2),j=1,i), i=1, n)\n Read (nin, *)((bp(i+((2*n-j)*(j-1))/2),j=1,i), i=1, n)\n End If\n\n! Compute the one-norms of the symmetric matrices A and B\n\n anorm = dlansp('One norm', uplo, n, ap, work)\n bnorm = dlansp('One norm', uplo, n, bp, work)\n\n! Solve the generalized symmetric eigenvalue problem\n! A*x = lambda*B*x (itype = 1)\n\n Call dspgv(1, 'No vectors', uplo, n, ap, bp, w, dummy, 1, work, info)\n\n If (info==0) Then\n\n! Print solution\n\n Write (nout, *) 'Eigenvalues'\n Write (nout, 100) w(1:n)\n\n! Call DTPCON to estimate the reciprocal condition\n! number of the Cholesky factor of B. Note that:\n! cond(B) = 1/rcond**2\n\n Call dtpcon('One norm', uplo, 'Non-unit', n, bp, rcond, work, iwork, &\n info)\n\n! Print the reciprocal condition number of B\n\n rcondb = rcond**2\n Write (nout, *)\n Write (nout, *) 'Estimate of reciprocal condition number for B'\n Write (nout, 110) rcondb\n\n! Get the machine precision, eps, and if rcondb is not less\n! than eps**2, compute error estimates for the eigenvalues\n\n eps = epsilon(1.0E0_dp)\n If (rcond>=eps) Then\n t1 = eps/rcondb\n t2 = anorm/bnorm\n Do i = 1, n\n eerbnd(i) = t1*(t2+abs(w(i)))\n End Do\n\n! Print the approximate error bounds for the eigenvalues\n\n Write (nout, *)\n Write (nout, *) 'Error estimates for the eigenvalues'\n Write (nout, 110) eerbnd(1:n)\n Else\n Write (nout, *)\n Write (nout, *) 'B is very ill-conditioned, error ', &\n 'estimates have not been computed'\n End If\n Else If (info>n .And. info<=2*n) Then\n i = info - n\n Write (nout, 120) 'The leading minor of order ', i, &\n ' of B is not positive definite'\n Else\n Write (nout, 130) 'Failure in DSPGV. INFO =', info\n End If\n\n100 Format (3X, (6F11.4))\n110 Format (4X, 1P, 6E11.1)\n120 Format (1X, A, I4, A)\n130 Format (1X, A, I4)\n End Program\n", "meta": {"hexsha": "655103f85b2aada6208c22b3182567db9313616f", "size": 3558, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/dspgv_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/dspgv_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/dspgv_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 31.7678571429, "max_line_length": 90, "alphanum_fraction": 0.5489038786, "num_tokens": 1133, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122188543453, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6742854148757554}} {"text": "C$Procedure NPELPT ( Nearest point on ellipse to point )\n \n SUBROUTINE NPELPT ( POINT, ELLIPS, PNEAR, DIST )\n \nC$ Abstract\nC\nC Find the nearest point on an ellipse to a specified point, both\nC in three-dimensional space, and find the distance between the\nC ellipse and the point.\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 ELLIPSES\nC\nC$ Keywords\nC\nC CONIC\nC ELLIPSE\nC GEOMETRY\nC MATH\nC\nC$ Declarations\n \n INTEGER UBEL\n PARAMETER ( UBEL = 9 )\n \n DOUBLE PRECISION ELLIPS ( UBEL )\n DOUBLE PRECISION POINT ( 3 )\n DOUBLE PRECISION PNEAR ( 3 )\n DOUBLE PRECISION DIST\n \nC$ Brief_I/O\nC\nC Variable I/O Description\nC -------- --- --------------------------------------------------\nC POINT I Point whose distance to an ellipse is to be found.\nC ELLIPS I A SPICELIB ellipse.\nC PNEAR O Nearest point on ellipse to input point.\nC DIST O Distance of input point to ellipse.\nC\nC$ Detailed_Input\nC\nC ELLIPS is a SPICELIB ellipse that represents an ellipse\nC in three-dimensional space.\nC\nC POINT is a point in 3-dimensional space.\nC\nC$ Detailed_Output\nC\nC PNEAR is the nearest point on ELLIPS to POINT.\nC\nC DIST is the distance between POINT and PNEAR. This is\nC the distance between POINT and the ellipse.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC 1) Invalid ellipses will be diagnosed by routines called by\nC this routine.\nC\nC 2) Ellipses having one or both semi-axis lengths equal to zero\nC are turned away at the door; the error SPICE(DEGENERATECASE)\nC is signalled.\nC\nC 3) If the geometric ellipse represented by ELLIPS does not\nC have a unique point nearest to the input point, any point\nC at which the minimum distance is attained may be returned\nC in PNEAR.\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC Given an ellipse and a point in 3-dimensional space, if the\nC orthogonal projection of the point onto the plane of the ellipse\nC is on or outside of the ellipse, then there is a unique point on\nC the ellipse closest to the original point. This routine finds\nC that nearest point on the ellipse. If the projection falls inside\nC the ellipse, there may be multiple points on the ellipse that are\nC at the minimum distance from the original point. In this case,\nC one such closest point will be returned.\nC\nC This routine returns a distance, rather than an altitude, in\nC contrast to the SPICELIB routine NEARPT. Because our ellipse is\nC situated in 3-space and not 2-space, the input point is not\nC `inside' or `outside' the ellipse, so the notion of altitude does\nC not apply to the problem solved by this routine. In the case of\nC NEARPT, the input point is on, inside, or outside the ellipsoid,\nC so it makes sense to speak of its altitude.\nC\nC$ Examples\nC\nC 1) For planetary rings that can be modelled as flat disks with\nC elliptical outer boundaries, the distance of a point in\nC space from a ring's outer boundary can be computed using this\nC routine. Suppose CENTER, SMAJOR, and SMINOR are the center,\nC semi-major axis, and semi-minor axis of the ring's boundary.\nC Suppose also that SCPOS is the position of a spacecraft.\nC SCPOS, CENTER, SMAJOR, and SMINOR must all be expressed in\nC the same coordinate system. We can find the distance from\nC the spacecraft to the ring using the code fragment\nC\nC C\nC C Make a SPICELIB ellipse representing the ring,\nC C then use NPELPT to find the distance between\nC C the spacecraft position and RING.\nC C\nC CALL CGV2EL ( CENTER, SMAJOR, SMINOR, RING )\nC CALL NPELPT ( SCPOS, RING, PNEAR, DIST )\nC\nC\nC 2) The problem of finding the distance of a line from a tri-axial\nC ellipsoid can be reduced to the problem of finding the\nC distance between the same line and an ellipse; this problem in\nC turn can be reduced to the problem of finding the distance\nC between an ellipse and a point. The routine NPEDLN carries\nC out this process and uses NPELPT to find the ellipse-to-point\nC distance.\nC\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC N.J. Bachman (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 1.2.0, 02-SEP-2005 (NJB)\nC\nC Updated to remove non-standard use of duplicate arguments\nC in VADD, VSCL, MTXV and MXV calls.\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, 02-NOV-1990 (NJB)\nC\nC-&\n \nC$ Index_Entries\nC\nC nearest point on ellipse to point\nC\nC-&\n \nC$ Revisions\nC\nC- SPICELIB Version 1.2.0, 02-SEP-2005 (NJB)\nC\nC Updated to remove non-standard use of duplicate arguments\nC in VADD, VSCL, MTXV and MXV calls.\nC\nC-& \n\n \n \nC\nC SPICELIB functions\nC\n DOUBLE PRECISION VNORM\n DOUBLE PRECISION VDIST\n \n LOGICAL RETURN\n \nC\nC Local variables\nC\n DOUBLE PRECISION CENTER ( 3 )\n DOUBLE PRECISION MAJLEN\n DOUBLE PRECISION MINLEN\n DOUBLE PRECISION ROTATE ( 3, 3 )\n DOUBLE PRECISION SCALE\n DOUBLE PRECISION SMAJOR ( 3 )\n DOUBLE PRECISION SMINOR ( 3 )\n DOUBLE PRECISION TEMPV ( 3 )\n DOUBLE PRECISION TMPPNT ( 3 )\n DOUBLE PRECISION PRJPNT ( 3 )\n \n \n \nC\nC Standard SPICE error handling.\nC\n IF ( RETURN () ) THEN\n RETURN\n ELSE\n CALL CHKIN ( 'NPELPT' )\n END IF\n \nC\nC Here's an overview of our solution:\nC\nC Let ELPL be the plane containing the ELLIPS, and let PRJ be\nC the orthogonal projection of the POINT onto ELPL. Let X be\nC any point in the plane ELPL. According to the Pythagorean\nC Theorem,\nC\nC 2 2 2\nC || POINT - X || = || POINT - PRJ || + || PRJ - X ||.\nC\nC Then if we can find a point X on ELLIPS that minimizes the\nC rightmost term, that point X is the closest point on the\nC ellipse to POINT.\nC\nC So, we find the projection PRJ, and then solve the problem of\nC finding the closest point on ELLIPS to PRJ. To solve this\nC problem, we find a triaxial ellipsoid whose intersection with\nC the plane ELPL is precisely ELLIPS, and two of whose axes lie\nC in the plane ELPL. The closest point on ELLIPS to PRJ is also\nC the closest point on the ellipsoid to ELLIPS. But we have the\nC SPICELIB routine NEARPT on hand to find the closest point on an\nC ellipsoid to a specified point, so we've reduced our problem to\nC a solved problem.\nC\nC There is a subtle point to worry about here: if PRJ is outside\nC of ELLIPS (PRJ is in the same plane as ELLIPS, so `outside'\nC does make sense here), then the closest point on ELLIPS to PRJ\nC coincides with the closest point on the ellipsoid to PRJ,\nC regardless of how we choose the z-semi-axis length of the\nC ellipsoid. But the correspondence may be lost if PRJ is inside\nC the ellipse, if we don't choose the z-semi-axis length\nC correctly.\nC\nC Though it takes some thought to verify this (and we won't prove\nC it here), making the z-semi-axis of the ellipsoid longer than\nC the other two semi-axes is sufficient to maintain the\nC coincidence of the closest point on the ellipsoid to PRJPNT and\nC the closest point on the ellipse to PRJPNT.\nC\n \nC\nC Find the ellipse's center and semi-axes.\nC\n CALL EL2CGV ( ELLIPS, CENTER, SMAJOR, SMINOR )\n \nC\nC Find the lengths of the semi-axes, and scale the vectors to try\nC to prevent arithmetic unpleasantness. Degenerate ellipses are\nC turned away at the door.\nC\n MINLEN = VNORM (SMINOR)\n MAJLEN = VNORM (SMAJOR)\n \n IF ( MIN ( MAJLEN, MINLEN ) .EQ. 0.D0 ) THEN\n \n CALL SETMSG ( 'Semi-axis lengths: # #. ' )\n CALL ERRDP ( '#', MAJLEN )\n CALL ERRDP ( '#', MINLEN )\n CALL SIGERR ( 'SPICE(DEGENERATECASE)' )\n CALL CHKOUT ( 'NPELPT' )\n RETURN\n \n END IF\n \n \n SCALE = 1.D0 / MAJLEN\n \n CALL VSCLIP ( SCALE, SMAJOR )\n CALL VSCLIP ( SCALE, SMINOR )\n \nC\nC Translate ellipse and point so that the ellipse is centered at\nC the origin. Scale the point's coordinates to maintain the\nC correct relative position to the scaled ellipse.\nC \n CALL VSUB ( POINT, CENTER, TMPPNT )\n CALL VSCLIP ( SCALE, TMPPNT )\n\nC\nC We want to reduce the problem to a two-dimensional one. We'll\nC work in a coordinate system whose x- and y- axes are aligned with\nC the semi-major and semi-minor axes of the input ellipse. The\nC z-axis is picked to give us a right-handed system. We find the\nC matrix that transforms coordinates to our new system using TWOVEC.\nC\n CALL TWOVEC ( SMAJOR, 1, SMINOR, 2, ROTATE )\n \nC\nC Apply the coordinate transformation to our scaled input point.\nC\n CALL MXV ( ROTATE, TMPPNT, TEMPV )\n CALL VEQU ( TEMPV, TMPPNT )\n \nC\nC We must find the distance between the orthogonal projection of\nC TMPPNT onto the x-y plane and the ellipse. The projection is\nC just\nC\nC ( TMPPNT(1), TMPPNT(2), 0 );\nC\nC we'll call this projection PRJPNT.\nC\nC\n CALL VPACK ( TMPPNT(1), TMPPNT(2), 0.D0, PRJPNT )\n \nC\nC Now we're ready to find the distance between and a triaxial\nC ellipsoid whose intersection with the x-y plane is the ellipse\nC and whose third semi-axis lies on the z-axis.\nC\nC Because we've scaled the ellipse's axes so as to give the longer\nC axis length 1, a length of 2.D0 suffices for the ellipsoid's\nC z-semi-axis.\nC\n \nC\nC Find the nearest point to PRJPNT on the ellipoid, PNEAR.\nC\n CALL NEARPT ( PRJPNT, 1.D0, MINLEN/MAJLEN, 2.D0, PNEAR, DIST )\n \nC\nC Scale the near point coordinates back to the original scale.\nC\n CALL VSCLIP ( MAJLEN, PNEAR )\n \nC\nC Apply the required inverse rotation and translation to PNEAR.\nC Compute the point-to-ellipse distance.\nC\n CALL MTXV ( ROTATE, PNEAR, TEMPV )\n CALL VADD ( TEMPV, CENTER, PNEAR )\n \n DIST = VDIST ( PNEAR, POINT )\n \n \n CALL CHKOUT ( 'NPELPT' )\n RETURN\n END\n", "meta": {"hexsha": "5b37490e71b3c87f07e369b3f73a3f01416b1778", "size": 12153, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/npelpt.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/npelpt.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/npelpt.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": 33.0244565217, "max_line_length": 72, "alphanum_fraction": 0.6509503826, "num_tokens": 3402, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122113355092, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6742854144491055}} {"text": "program test_plate_motion\n! Find Euler pole for Africa (AF) for NUVEL1A and rotation rate at 0,60\n \n use plate_motion\n \n implicit none\n \n type(plate) :: p1,p2\n character(len=MODEL_NAME_LENGTH) :: model_name\n real(8) :: lon,lat,v(2)\n \n lon = 0._8\n lat = 60._8\n \n p1%name = \"EU\"\n p2%name = \"AF\"\n model_name = 'HS3-NUVEL1A'\n \n! Test apm calculation\n call absolute_plate_motion(lon, lat, p1, model_name, v=v)\n \n write(*,'(a,2(i0,a))') 'Absolute plate motion of Africa at ',int(lon),',',int(lat),':'\n write(*,'(\" \",a,f0.2,x,f0.2)') 'E, N: ',v \n write(*,'(\" \",a,f5.1,x,f0.2)') 'az,rate: ', &\n mod(atan2(v(1), v(2))*180._8/3.14159_8+3600._8, 360._8), &\n sqrt(v(1)**2 + v(2)**2)\n \n! Test relative plate motion calculation\n write(*,'(a,2(i0,a))') 'Relative motion of EU to AF at ',int(lon),',',int(lat),':'\n call relative_plate_motion(lon,lat,P1,P2,model_name,v=v)\n write(*,'(\" \",f5.1,x,f0.2)') mod(atan2(v(1), v(2))*180._8/3.14159_8+3600._8, 360._8), &\n sqrt(v(1)**2 + v(2)**2)\n\n \nend program", "meta": {"hexsha": "92265a0755f68375bd1f85380b1a5e87e57215a6", "size": 1068, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "plate_motion/test_plate_motion.f90", "max_stars_repo_name": "JackWalpole/seismo-fortran-fork", "max_stars_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2015-06-23T05:28:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T03:46:07.000Z", "max_issues_repo_path": "plate_motion/test_plate_motion.f90", "max_issues_repo_name": "JackWalpole/seismo-fortran-fork", "max_issues_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2017-05-17T11:02:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-28T09:36:24.000Z", "max_forks_repo_path": "plate_motion/test_plate_motion.f90", "max_forks_repo_name": "JackWalpole/seismo-fortran-fork", "max_forks_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-04-15T02:55:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-20T12:20:51.000Z", "avg_line_length": 30.5142857143, "max_line_length": 93, "alphanum_fraction": 0.5702247191, "num_tokens": 409, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480668, "lm_q2_score": 0.743167997235783, "lm_q1q2_score": 0.6742854026909523}} {"text": "! To draw the Lissajous figures using given equations & studying the effect of varying phi\r\n\r\nprogram Lissajous\r\n real::A=1.0, B=2.0, w1=2.0, w2=3.0, pi=4*atan(1.0), i\r\n real,dimension(100)::x,y,t\r\n phi=pi\r\n do i=0,100\r\n x(i)=A*sin(2*w1*0.1*i)\r\n y(i)=B*cos(2*w2*0.1*i+phi)\r\n print*,x(i),y(i)\r\n write(6,*),x(i),y(i)\n end do\nend program\r\n", "meta": {"hexsha": "2fe47b2e51e59770011c95eb2f601c97719d8d8f", "size": 381, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "6_Lissajous_Figures.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": "6_Lissajous_Figures.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": "6_Lissajous_Figures.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": 27.2142857143, "max_line_length": 93, "alphanum_fraction": 0.5485564304, "num_tokens": 154, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191297273498, "lm_q2_score": 0.7057850216484838, "lm_q1q2_score": 0.6742499326558282}} {"text": "module mod_calculate_flow_velocity\n\n!Moudle contains a function to compute the flow velocity of a river using\n!the retention parameter and the cell area and river directio for diagnostic\n!purposes. This is reserving a previous calculation to find the retention parameter\n\nimplicit none\n\ncontains\n\nfunction calculate_flow_velocity(retention_constant,FDIR,DLON,nlat,nlon) &\nresult(flow_velocities)\n\n!As stated above, reserves the retention constant calculation to get the flow parameter\n\nimplicit none\n\n!Kind parameters for double precision from JSBACH, could potentially be moved\n!to a seperate module to produce a more unified kind scheme with HD scripting\ninteger, parameter :: pd = 12\ninteger, parameter :: rd = 307\ninteger, parameter :: dp = SELECTED_REAL_KIND(pd,rd)\n\n!Variables with intent IN\n!Dimension of the input array\ninteger, intent(in) :: nlat, nlon\n!Input retention constant array (in days?)\nreal(dp), intent(in), dimension(nlon,nlat) :: retention_constants\n!River directions array (given as double for historical reasons although it always\n!takes integer values).\nreal(dp), intent(in), dimension(nlon,nlat) :: FDIR\n!Longitudal grid spacings (in metres)\nreal(dp), intent(in), dimension(nlat) :: DLON\n!Local variables\n!Flow velocities calculated (in m/s)\nreal(dp), dimension(nlon,nlat) :: flow_velocities\n!Loop counters\ninteger :: JB,JL\n!Distance between grid cells centres\nreal(dp) :: DX\n!River flow retention constant normalisation constant\nreal(dp), parameter :: ARF_K0 = 0.4112\n!Grid spacing normalisation parameter (metres)\nreal(dp), parameter :: ARF_DX = 228000.\n!River flow velocity normalisation constant\nreal(dp), parameter :: ARF_V0 = 1.0039\n!Latitudal grid spacing (metres)\nreal(dp), paramter :: DLAT\n!From globuse.f value of DLAT\nDLAT = DLON(2)\n\ndo JB = 1,nlat\n do JL = 1,nlon\n !Calculate relative coordinates between grid cell and neighbor it flows into\n IB = -( INT( (FDIR(JL,JB)-1.)/3. + 0.1) - 1)\n IL = INT( ( (FDIR(JL,JB)+2.)/3. -\n & INT((FDIR(JL,JB)+2.)/3. + 0.1) ) * 3. + 0.1) -1\n !Thus calculate the distance between the centres of the grid cells\n DX = SQRT(IB*IB*DLAT*DLAT + IL*IL*DLON(JB)*DLON(JB))\n !Reserve the calculation of the retention constant to give a flow direction\n flow_velocities(JL,JB) = ARF_K0 * DX/ARF_DX * ARF_V0/retention_constants(JL,JB)\n end do\nend do\n\nend function calculate_flow_velocity\n\nend module mod_calculate_flow_velocity\n", "meta": {"hexsha": "a6eca3453e5d1d92c445cfbcbadcac419e60949a", "size": 2455, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Dynamic_HD_Scripts/Dynamic_HD_Scripts/fortran/mod_calculate_flow_velocity.f90", "max_stars_repo_name": "ThomasRiddick/DynamicHD", "max_stars_repo_head_hexsha": "bff378a49ff6c709dc59c2d6835852e1083df20a", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-08-04T07:51:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-04T07:51:18.000Z", "max_issues_repo_path": "Dynamic_HD_Scripts/Dynamic_HD_Scripts/fortran/mod_calculate_flow_velocity.f90", "max_issues_repo_name": "ThomasRiddick/DynamicHD", "max_issues_repo_head_hexsha": "bff378a49ff6c709dc59c2d6835852e1083df20a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-01-27T22:12:45.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-01T10:16:47.000Z", "max_forks_repo_path": "Dynamic_HD_Scripts/Dynamic_HD_Scripts/fortran/mod_calculate_flow_velocity.f90", "max_forks_repo_name": "ThomasRiddick/DynamicHD", "max_forks_repo_head_hexsha": "bff378a49ff6c709dc59c2d6835852e1083df20a", "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": 36.1029411765, "max_line_length": 87, "alphanum_fraction": 0.7376782077, "num_tokens": 670, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966747198242, "lm_q2_score": 0.712232184238947, "lm_q1q2_score": 0.6741966172290244}} {"text": "!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n! User-defined Rate Law functions\n! Note: the default argument type for rate laws, as read from the equations file, is single precision\n! but all the internal calculations are performed in double precision\n!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n!~~~> Arrhenius\n KPP_REAL FUNCTION ARR( A0,B0,C0 )\n REAL A0,B0,C0 \n ARR = DBLE(A0) * EXP(-DBLE(B0)/TEMP) * (TEMP/300.0_dp)**DBLE(C0)\n END FUNCTION ARR \n\n!~~~> Simplified Arrhenius, with two arguments\n!~~~> Note: The argument B0 has a changed sign when compared to ARR\n KPP_REAL FUNCTION ARR2( A0,B0 )\n REAL A0,B0 \n ARR2 = DBLE(A0) * EXP( DBLE(B0)/TEMP ) \n END FUNCTION ARR2 \n\n KPP_REAL FUNCTION EP2(A0,C0,A2,C2,A3,C3)\n REAL A0,C0,A2,C2,A3,C3\n REAL(dp) K0,K2,K3 \n K0 = DBLE(A0) * EXP(-DBLE(C0)/TEMP)\n K2 = DBLE(A2) * EXP(-DBLE(C2)/TEMP)\n K3 = DBLE(A3) * EXP(-DBLE(C3)/TEMP)\n K3 = K3*CFACTOR*1.0E6_dp\n EP2 = K0 + K3/(1.0_dp+K3/K2 )\n END FUNCTION EP2\n\n KPP_REAL FUNCTION EP3(A1,C1,A2,C2) \n REAL A1, C1, A2, C2\n REAL(dp) K1, K2 \n K1 = DBLE(A1) * EXP(-DBLE(C1)/TEMP)\n K2 = DBLE(A2) * EXP(-DBLE(C2)/TEMP)\n EP3 = K1 + K2*(1.0E6_dp*CFACTOR)\n END FUNCTION EP3 \n\n KPP_REAL FUNCTION FALL ( A0,B0,C0,A1,B1,C1,CF)\n REAL A0,B0,C0,A1,B1,C1,CF\n REAL(dp) K0, K1 \n K0 = DBLE(A0) * EXP(-DBLE(B0)/TEMP)* (TEMP/300.0_dp)**DBLE(C0)\n K1 = DBLE(A1) * EXP(-DBLE(B1)/TEMP)* (TEMP/300.0_dp)**DBLE(C1)\n K0 = K0*CFACTOR*1.0E6_dp\n K1 = K0/K1\n FALL = (K0/(1.0_dp+K1))* &\n DBLE(CF)**(1.0_dp/(1.0_dp+(LOG10(K1))**2))\n END FUNCTION FALL\n\n !---------------------------------------------------------------------------\n\n ELEMENTAL REAL(dp) FUNCTION k_3rd(temp,cair,k0_300K,n,kinf_300K,m,fc)\n\n INTRINSIC LOG10\n\n REAL(dp), INTENT(IN) :: temp ! temperature [K]\n REAL(dp), INTENT(IN) :: cair ! air concentration [molecules/cm3]\n REAL, INTENT(IN) :: k0_300K ! low pressure limit at 300 K\n REAL, INTENT(IN) :: n ! exponent for low pressure limit\n REAL, INTENT(IN) :: kinf_300K ! high pressure limit at 300 K\n REAL, INTENT(IN) :: m ! exponent for high pressure limit\n REAL, INTENT(IN) :: fc ! broadening factor (usually fc=0.6)\n REAL :: zt_help, k0_T, kinf_T, k_ratio\n\n zt_help = 300._dp/temp\n k0_T = k0_300K * zt_help**(n) * cair ! k_0 at current T\n kinf_T = kinf_300K * zt_help**(m) ! k_inf at current T\n k_ratio = k0_T/kinf_T\n k_3rd = k0_T/(1._dp+k_ratio)*fc**(1._dp/(1._dp+LOG10(k_ratio)**2))\n\n END FUNCTION k_3rd\n\n !---------------------------------------------------------------------------\n\n ELEMENTAL REAL(dp) FUNCTION k_arr (k_298,tdep,temp)\n ! Arrhenius function\n\n REAL, INTENT(IN) :: k_298 ! k at T = 298.15K\n REAL, INTENT(IN) :: tdep ! temperature dependence\n REAL(dp), INTENT(IN) :: temp ! temperature\n\n INTRINSIC EXP\n\n k_arr = k_298 * EXP(tdep*(1._dp/temp-3.3540E-3_dp)) ! 1/298.15=3.3540e-3\n\n END FUNCTION k_arr\n\n!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n! End of User-defined Rate Law functions\n!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n", "meta": {"hexsha": "f6281133b0bc36dbecc709f19ad089373b54f890", "size": 3544, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "chem/KPP/kpp/kpp-2.1/util/UserRateLaws.f90", "max_stars_repo_name": "matzegoebel/WRF-fluxavg", "max_stars_repo_head_hexsha": "686ae53053bf7cb55d6f078916d0de50f819fc62", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2018-08-27T12:49:19.000Z", "max_stars_repo_stars_event_max_datetime": "2019-05-16T14:22:54.000Z", "max_issues_repo_path": "chem/KPP/kpp/kpp-2.1/util/UserRateLaws.f90", "max_issues_repo_name": "teb-model/wrf-teb", "max_issues_repo_head_hexsha": "60882e61a2a3d91f1c94cb5b542f46ffaebfad71", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 25, "max_issues_repo_issues_event_min_datetime": "2018-09-18T16:44:30.000Z", "max_issues_repo_issues_event_max_datetime": "2019-07-07T10:59:59.000Z", "max_forks_repo_path": "chem/KPP/kpp/kpp-2.1/util/UserRateLaws.f90", "max_forks_repo_name": "teb-model/wrf-teb", "max_forks_repo_head_hexsha": "60882e61a2a3d91f1c94cb5b542f46ffaebfad71", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2018-08-31T21:51:56.000Z", "max_forks_repo_forks_event_max_datetime": "2019-05-21T21:41:59.000Z", "avg_line_length": 39.3777777778, "max_line_length": 105, "alphanum_fraction": 0.4889954853, "num_tokens": 1129, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240194661945, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6741306655780642}} {"text": " SUBROUTINE SG02ND( DICO, JOBE, JOB, JOBX, FACT, UPLO, JOBL, TRANS,\n $ N, M, P, A, LDA, E, LDE, B, LDB, R, LDR, IPIV,\n $ L, LDL, X, LDX, RNORM, K, LDK, H, LDH, XE,\n $ LDXE, OUFACT, IWORK, DWORK, LDWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute the optimal gain matrix K for the problem of optimal\nC control given by\nC\nC -1\nC K = (R + B'XB) (B'Xop(A) + L') (1)\nC\nC in the discrete-time case and\nC\nC -1\nC K = R (B'Xop(E) + L') (2)\nC\nC in the continuous-time case, where A, E, B and L are N-by-N,\nC N-by-N, N-by-M, and N-by-M matrices, respectively; R and X are\nC M-by-M and N-by-N symmetric matrices, respectively, and op(W) is\nC either W or W'. Matrix op(K) defines the feedback gain matrix, if\nC op(W) = W, and the estimator matrix, if op(W) = W'. The formulas\nC above are also useful in Newton's algorithms for solving algebraic\nC Riccati equations, when X is the current iterate.\nC\nC Optionally, matrix R may be specified in a factored form, and L\nC may be zero. If R or R + B'XB (for DICO = 'C', or DICO = 'D',\nC respectively), is positive definite, let C be its Cholesky factor\nC (denoted, e.g., C = chol(R), for DICO = 'C'). Optionally, the\nC matrix H, defined by\nC\nC H = op(E)'XB + L, if DICO = 'C', or\nC H = op(A)'XB + L, if DICO = 'D', (3)\nC\nC is returned on exit, besides K; if C exists, the matrix F, defined\nC by FC = H may be optionally returned, instead of K and H. The\nC matrix F or the pair of matrices H and K may be used for computing\nC the residual matrix for an (approximate) solution of an algebraic\nC Riccati equation (see SLICOT Library routine SG02CW).\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC DICO CHARACTER*1\nC Specifies the equation from which K is to be determined,\nC as follows:\nC = 'D': Equation (1), discrete-time case;\nC = 'C': Equation (2), continuous-time case.\nC\nC JOBE CHARACTER*1\nC Specifies whether E is a general or an identity matrix,\nC as follows:\nC = 'G': The matrix E is general and is given;\nC = 'I': The matrix E is assumed identity and is not given.\nC This parameter is not relevant for DICO = 'D'.\nC\nC JOB CHARACTER*1\nC Specifies what should be computed, as follows:\nC = 'K': Compute and return the matrix K only;\nC = 'H': Compute and return both matrices H and K;\nC = 'F': Compute the matrix F, if possible; otherwise,\nC compute and return H and K;\nC = 'D': Compute and return both matrices H and K, when\nC B and L have previously been transformed using\nC SLICOT Library routines SB02MT or SB02MX, which\nC returned OUFACT = 1. This is useful for computing\nC K in (2), since then K is the solution of CK = H'.\nC In this case, FACT should be set to 'C', and the\nC array R must contain the Cholesky factor of\nC R + B'XB, if DICO = 'D';\nC = 'C': Compute and return the matrix F, when B and L have\nC previously been transformed using SB02MT or\nC SB02MX, which returned OUFACT = 1. In this case,\nC FACT should be set to 'C', and the array R must\nC contain the Cholesky factor of R + B'XB, if\nC DICO = 'D'.\nC JOB should not be set to 'F' if FACT = 'U'.\nC\nC JOBX CHARACTER*1\nC Specifies whether the matrix op(Xop(E)), if DICO = 'C', or\nC op(Xop(A)), if DICO = 'D', must be computed, as follows:\nC = 'C': Compute and return the coresponding matrix;\nC = 'N': Do not compute that matrix.\nC This parameter is not relevant for DICO = 'C' and\nC JOBE = 'I'.\nC\nC FACT CHARACTER*1\nC Specifies how the matrix R is given (factored or not), as\nC follows:\nC = 'N': Array R contains the matrix R;\nC = 'D': Array R contains a P-by-M matrix D, where R = D'D;\nC = 'C': Array R contains the Cholesky factor of R;\nC = 'U': Array R contains the symmetric indefinite UdU' or\nC LdL' factorization of R. This option is not\nC available for DICO = 'D'.\nC\nC UPLO CHARACTER*1\nC Specifies which triangle of the possibly factored matrix R\nC (or R + B'XB, on exit) is or should be stored, as follows:\nC = 'U': Upper triangle is stored;\nC = 'L': Lower triangle is stored.\nC\nC JOBL CHARACTER*1\nC Specifies whether or not the matrix L is zero, as follows:\nC = 'Z': L is zero;\nC = 'N': L is nonzero.\nC\nC TRANS CHARACTER*1\nC Specifies the form of op(W) to be used in the matrix\nC multiplication, as follows:\nC = 'N': op(W) = W;\nC = 'T': op(W) = W';\nC = 'C': op(W) = W'.\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The order of the matrices A and X. N >= 0.\nC No computations are performed if MIN(N,M) = 0.\nC\nC M (input) INTEGER\nC The order of the matrix R and the number of columns of the\nC matrices B and L. M >= 0.\nC\nC P (input) INTEGER\nC The number of rows of the matrix D.\nC P >= M for DICO = 'C';\nC P >= 0 for DICO = 'D'.\nC This parameter is relevant only for FACT = 'D'.\nC\nC A (input) DOUBLE PRECISION array, dimension (LDA,N)\nC If DICO = 'D', the leading N-by-N part of this array must\nC contain the state matrix A of the system.\nC If DICO = 'C', this array is not referenced.\nC\nC LDA INTEGER\nC The leading dimension of array A.\nC LDA >= MAX(1,N) if DICO = 'D';\nC LDA >= 1 if DICO = 'C'.\nC\nC E (input) DOUBLE PRECISION array, dimension (LDE,*)\nC If JOBE = 'G' and DICO = 'C', the leading N-by-N part of\nC this array must contain the matrix E.\nC If JOBE = 'I' or DICO = 'D', this array is not referenced.\nC\nC LDE INTEGER\nC The leading dimension of array E.\nC LDE >= MAX(1,N), if JOBE = 'G' and DICO = 'C';\nC LDE >= 1, if JOBE = 'I' or DICO = 'D'.\nC\nC B (input/worksp.) DOUBLE PRECISION array, dimension (LDB,M)\nC The leading N-by-M part of this array must contain the\nC input matrix B of the system, transformed by SB02MT or\nC SB02MX, if JOB = 'D' or JOB = 'C'.\nC If DICO = 'D' and FACT = 'D' or 'C', the contents of this\nC array is destroyed. Specifically, if, on exit,\nC OUFACT(2) = 1, this array contains chol(X)*B, and if\nC OUFACT(2) = 2 and INFO < M+2, but INFO >= 0, its trailing\nC part (in the first N rows) contains the submatrix of\nC sqrt(V)*U'B corresponding to the non-negligible, positive\nC eigenvalues of X, where V and U are the matrices with the\nC eigenvalues and eigenvectors of X.\nC Otherwise, B is unchanged on exit.\nC\nC LDB INTEGER\nC The leading dimension of array B. LDB >= MAX(1,N).\nC\nC R (input/output) DOUBLE PRECISION array, dimension (LDR,M)\nC On entry, if FACT = 'N', the leading M-by-M upper\nC triangular part (if UPLO = 'U') or lower triangular part\nC (if UPLO = 'L') of this array must contain the upper\nC triangular part or lower triangular part, respectively,\nC of the symmetric input weighting matrix R.\nC On entry, if FACT = 'D', the leading P-by-M part of this\nC array must contain the direct transmission matrix D of the\nC system.\nC On entry, if FACT = 'C', the leading M-by-M upper\nC triangular part (if UPLO = 'U') or lower triangular part\nC (if UPLO = 'L') of this array must contain the Cholesky\nC factor of the positive definite input weighting matrix R\nC (as produced by LAPACK routine DPOTRF).\nC On entry, if DICO = 'C' and FACT = 'U', the leading M-by-M\nC upper triangular part (if UPLO = 'U') or lower triangular\nC part (if UPLO = 'L') of this array must contain the\nC factors of the UdU' or LdL' factorization, respectively,\nC of the symmetric indefinite input weighting matrix R (as\nC produced by LAPACK routine DSYTRF).\nC The strictly lower triangular part (if UPLO = 'U') or\nC strictly upper triangular part (if UPLO = 'L') of this\nC array is used as workspace (filled in by symmetry with the\nC other strictly triangular part of R, of R+B'XB, or of the\nC result, if DICO = 'C', DICO = 'D' (if FACT = 'N', in both\nC cases), or (DICO = 'D' and (FACT = 'D' or FACT = 'C') and\nC UPLO = 'L'), respectively.\nC On exit, if OUFACT(1) = 1, and INFO = 0 (or INFO = M+1),\nC the leading M-by-M upper triangular part (if UPLO = 'U')\nC or lower triangular part (if UPLO = 'L') of this array\nC contains the Cholesky factor of the given input weighting\nC matrix R (for DICO = 'C'), or that of the matrix R + B'XB\nC (for DICO = 'D').\nC On exit, if OUFACT(1) = 2, and INFO = 0 (or INFO = M+1),\nC the leading M-by-M upper triangular part (if UPLO = 'U')\nC or lower triangular part (if UPLO = 'L') of this array\nC contains the factors of the UdU' or LdL' factorization,\nC respectively, of the given input weighting matrix\nC (for DICO = 'C'), or that of the matrix R + B'XB\nC (for DICO = 'D' and FACT = 'N').\nC On exit R is unchanged if FACT = 'U' or N = 0.\nC\nC LDR INTEGER.\nC The leading dimension of the array R.\nC LDR >= MAX(1,M) if FACT <> 'D';\nC LDR >= MAX(1,M,P) if FACT = 'D'.\nC\nC IPIV (input/output) INTEGER array, dimension (M)\nC On entry, if FACT = 'U', this array must contain details\nC of the interchanges performed and the block structure of\nC the d factor in the UdU' or LdL' factorization of matrix R\nC (as produced by LAPACK routine DSYTRF).\nC On exit, if OUFACT(1) = 2, this array contains details of\nC the interchanges performed and the block structure of the\nC d factor in the UdU' or LdL' factorization of matrix R or\nC R + B'XB, as produced by LAPACK routine DSYTRF.\nC This array is not referenced if FACT = 'D', or FACT = 'C',\nC or N = 0.\nC\nC L (input) DOUBLE PRECISION array, dimension (LDL,M)\nC If JOBL = 'N', the leading N-by-M part of this array must\nC contain the cross weighting matrix L, transformed by\nC SB02MT or SB02MX, if JOB = 'D' or JOB = 'C'.\nC If JOBL = 'Z', this array is not referenced.\nC\nC LDL INTEGER\nC The leading dimension of array L.\nC LDL >= MAX(1,N) if JOBL = 'N';\nC LDL >= 1 if JOBL = 'Z'.\nC\nC X (input/output) DOUBLE PRECISION array, dimension (LDX,N)\nC On entry, the leading N-by-N part of this array must\nC contain the (approximate) solution matrix X of the\nC algebraic Riccati equation as produced by SLICOT Library\nC routines SB02MD or SB02OD (or SG02CD). Matrix X is assumed\nC non-negative definite if DICO = 'D', FACT <> 'N',\nC JOB <> 'D' and JOB <> 'C'. The full matrix X must be given\nC on input in this case.\nC For minimal workspace, full matrix X must also be given if\nC ((JOBX = 'C', DICO = 'D', FACT = 'N', and M > N), or\nC (JOBX = 'N', ((DICO = 'C' or FACT = 'N'), (DICO = 'D' or\nC JOBE = 'I') or N >= M, or LDWORK < N*N) and (DICO = 'D'\nC or JOBE = 'G' or JOB = 'K'))) and LDWORK < N*M.\nC (Simpler, but more demanding conditions are the following:\nC ((JOBX = 'C', DICO = 'D', FACT = 'N', and M > N), or\nC (JOBX = 'N', (DICO = 'D' or ((DICO = 'C', JOBE = 'G') or\nC JOB = 'K'))), LDWORK < N*N.)\nC For optimal workspace, full matrix X is not needed in any\nC of the cases described above for minimal workspace.\nC On exit, if DICO = 'D', FACT = 'D' or FACT = 'C', and\nC OUFACT(2) = 1, the N-by-N upper triangular part\nC (if UPLO = 'U') or lower triangular part (if UPLO = 'L')\nC of this array contains the Cholesky factor of the given\nC matrix X, which is found to be positive definite.\nC On exit, if DICO = 'D', FACT = 'D' or 'C', OUFACT(2) = 2,\nC and INFO <> M+2 (but INFO >= 0), the leading N-by-N part\nC of this array contains the matrix of orthonormal\nC eigenvectors of X.\nC On exit X is unchanged if DICO = 'C' or FACT = 'N'.\nC\nC LDX INTEGER\nC The leading dimension of array X. LDX >= MAX(1,N).\nC\nC RNORM (input) DOUBLE PRECISION\nC If FACT = 'U', this parameter must contain the 1-norm of\nC the original matrix R (before factoring it).\nC Otherwise, this parameter is not used.\nC\nC K (output) DOUBLE PRECISION array, dimension (LDK,N)\nC If JOB = 'K' or JOB = 'H' or JOB = 'D' or OUFACT(1) = 2,\nC the leading M-by-N part of this array contains the gain\nC matrix K.\nC\nC LDK INTEGER\nC The leading dimension of array K. LDK >= MAX(1,M).\nC\nC H (output) DOUBLE PRECISION array, dimension (LDH,*)\nC If JOB = 'H' or JOB = 'D' or (JOB = 'F' and\nC OUFACT(1) = 2), the leading N-by-M part of this array\nC contains the matrix H.\nC If JOB = 'C' or (JOB = 'F' and OUFACT(1) = 1), the leading\nC N-by-M part of this array contains the matrix F.\nC If JOB = 'K', this array is not referenced.\nC\nC LDH INTEGER\nC The leading dimension of array H.\nC LDH >= MAX(1,N), if JOB <> 'K';\nC LDH >= 1, if JOB = 'K'.\nC\nC XE (output) DOUBLE PRECISION array, dimension (LDXE,*)\nC If JOBX = 'C', DICO = 'C', and JOBE = 'G', the leading\nC N-by-N part of this array contains the matrix product X*E,\nC if TRANS = 'N', or E*X, if TRANS = 'T' or TRANS = 'C'.\nC If JOBX = 'C' and DICO = 'D', the leading N-by-N part of\nC this array contains the matrix product X*A, if\nC TRANS = 'N', or A*X, if TRANS = 'T' or TRANS = 'C'.\nC These matrix products may be needed for computing the\nC residual matrix for an (approximate) solution of a Riccati\nC equation (see SLICOT Library routine SG02CW).\nC If JOBX = 'N' or (DICO = 'C' and JOBE = 'I'), this array\nC is not referenced.\nC\nC LDXE INTEGER\nC The leading dimension of array XE.\nC LDXE >= MAX(1,N), if JOBX = 'C', and either DICO = 'C' and\nC JOBE = 'G', or DICO = 'D';\nC LDXE >= 1, if JOBX = 'N' or (DICO = 'C' and\nC JOBE = 'I').\nC\nC OUFACT (output) INTEGER array, dimension (2)\nC Information about the factorization finally used.\nC OUFACT(1) = 1: Cholesky factorization of R (or R + B'XB)\nC has been used;\nC OUFACT(1) = 2: UdU' (if UPLO = 'U') or LdL' (if UPLO =\nC 'L') factorization of R (or R + B'XB)\nC has been used;\nC OUFACT(2) = 1: Cholesky factorization of X has been used;\nC OUFACT(2) = 2: Spectral factorization of X has been used.\nC The value of OUFACT(2) is not set for DICO = 'C' or for\nC DICO = 'D' and FACT = 'N'.\nC This array is not set if N = 0 or M = 0.\nC\nC Workspace\nC\nC IWORK INTEGER array, dimension (M)\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0 or LDWORK = -1, DWORK(1) returns the\nC optimal value of LDWORK, and for LDWORK set as specified\nC below, DWORK(2) contains the reciprocal condition number\nC of the matrix R (for DICO = 'C') or of R + B'XB (for\nC DICO = 'D'), if FACT = 'N' or FACT = 'U' or OUFACT(1) = 2,\nC or of its Cholesky factor, if FACT = 'C' or FACT = 'D' and\nC OUFACT(1) = 1; DWORK(2) is set to 1 if N = 0.\nC On exit, if LDWORK = -2 on input or INFO = -35, then\nC DWORK(1) returns the minimal value of LDWORK.\nC If on exit INFO = 0, and OUFACT(2) = 2, then DWORK(3),...,\nC DWORK(N+2) contain the eigenvalues of X, in ascending\nC order.\nC\nC LDWORK INTEGER\nC Dimension of working array DWORK.\nC Let a = N, if JOBX = 'N' and (DICO = 'D' or JOBE = 'G');\nC a = 0, otherwise. Then\nC LDWORK >= max(2,2*M,a) if FACT = 'U';\nC LDWORK >= max(2,3*M,4*N+1) if FACT = 'D' or\nC (FACT = 'C' and JOB <> 'C'\nC and JOB <> 'D'), DICO = 'D';\nC LDWORK >= max(2,3*M,a) otherwise.\nC For optimum performance LDWORK should be larger.\nC\nC If LDWORK = -1, an optimal workspace query is assumed; the\nC routine only calculates the optimal size of the DWORK\nC array, returns this value as the first entry of the DWORK\nC array, and no error message is issued by XERBLA.\nC\nC If LDWORK = -2, a minimal workspace query is assumed; the\nC routine only calculates the minimal size of the DWORK\nC array, returns this value as the first entry of the DWORK\nC array, and no error message is issued by XERBLA.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value;\nC = i: if the i-th element of the d factor is exactly zero;\nC the UdU' (or LdL') factorization has been completed,\nC but the block diagonal matrix d is exactly singular;\nC = M+1: if the matrix R (if DICO = 'C'), or R + B'XB\nC (if DICO = 'D') is numerically singular (to working\nC precision);\nC = M+2: if one or more of the eigenvalues of X has not\nC converged;\nC = M+3: if the matrix X is indefinite and updating the\nC triangular factorization failed.\nC If INFO > M+1, call the routine again with an appropriate,\nC unfactored matrix R.\nC\nC METHOD\nC\nC The (optimal) gain matrix K is obtained as the solution to the\nC system of linear equations\nC\nC (R + B'XB) * K = B'Xop(A) + L'\nC\nC in the discrete-time case and\nC\nC R * K = B'Xop(E) + L'\nC\nC in the continuous-time case, with R replaced by D'D if FACT = 'D'.\nC If FACT = 'N', Cholesky factorization is tried first, but\nC if the coefficient matrix is not positive definite, then UdU' (or\nC LdL') factorization is used. If FACT <> 'N', the factored form\nC of R is taken into account. The discrete-time case then involves\nC updating of a triangular factorization of R (or D'D); Cholesky or\nC symmetric spectral factorization of X is employed to avoid\nC squaring of the condition number of the matrix. When D is given,\nC its QR factorization is determined, and the triangular factor is\nC used as described above.\nC\nC NUMERICAL ASPECTS\nC\nC The algorithm consists of numerically stable steps.\nC 3 2\nC For DICO = 'C' and JOBE = 'I', it requires O(m + mn ) floating\nC 2\nC point operations if FACT = 'N' and O(mn ) floating point\nC operations, otherwise.\nC For DICO = 'D' or JOBE = 'G', the operation counts are similar,\nC 3\nC but additional O(n ) floating point operations may be needed in\nC the worst case.\nC These estimates assume that M <= N.\nC\nC CONTRIBUTORS\nC\nC V. Sima, Research Institute for Informatics, Bucharest, Jan. 2014.\nC\nC REVISIONS\nC\nC V. Sima, Feb. 2014, July 2017, Dec. 2017.\nC\nC KEYWORDS\nC\nC Algebraic Riccati equation, closed loop system, continuous-time\nC system, discrete-time system, matrix algebra, optimal control,\nC optimal regulator.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, ONE, TWO\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0, TWO = 2.0D0 )\nC .. Scalar Arguments ..\n CHARACTER DICO, FACT, JOB, JOBE, JOBL, JOBX, TRANS, UPLO\n INTEGER INFO, LDA, LDB, LDE, LDH, LDK, LDL, LDR, LDWORK,\n $ LDX, LDXE, M, N, P\n DOUBLE PRECISION RNORM\nC .. Array Arguments ..\n INTEGER IPIV(*), IWORK(*), OUFACT(2)\n DOUBLE PRECISION A(LDA,*), B(LDB,*), DWORK(*), E(LDE,*),\n $ H(LDH,*), K(LDK,*), L(LDL,*), R(LDR,*),\n $ X(LDX,*), XE(LDXE,*)\nC .. Local Scalars ..\n LOGICAL DISCR, LASTCS, LFACTA, LFACTC, LFACTD, LFACTU,\n $ LJOBE, LNFACT, LTRANS, LUPLOU, SUFWRK, WITHC,\n $ WITHCD, WITHD, WITHF, WITHH, WITHL, WITHXE\n CHARACTER NT, NTRANS, NUPLO, SIDE, TR, TRL\n INTEGER I, IFAIL, JW, JZ, MS, NM, NR, WRKMIN, WRKOPT\n DOUBLE PRECISION EPS, RCOND, RNORMP, TEMP, TMP\nC .. Local Arrays ..\n DOUBLE PRECISION DUMMY(1)\nC .. External Functions ..\n LOGICAL LSAME\n DOUBLE PRECISION DLAMCH, DLANSY\n EXTERNAL DLAMCH, DLANSY, LSAME\nC .. External Subroutines ..\n EXTERNAL DAXPY, DCOPY, DGEMM, DGEQRF, DLACPY, DLASET,\n $ DPOCON, DPOTRF, DPOTRS, DSCAL, DSYCON, DSYEV,\n $ DSYMM, DSYTRF, DSYTRS, DTRCON, DTRMM, DTRSM,\n $ MA02AD, MA02ED, MB01RB, MB01RU, MB04KD, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC ABS, DBLE, INT, MAX, MIN, SQRT\nC .. Executable Statements ..\nC\n INFO = 0\n DISCR = LSAME( DICO, 'D' )\n LFACTC = LSAME( FACT, 'C' )\n LFACTD = LSAME( FACT, 'D' )\n LFACTU = LSAME( FACT, 'U' )\n LJOBE = LSAME( JOBE, 'G' )\n LTRANS = LSAME( TRANS, 'T' ) .OR. LSAME( TRANS, 'C' )\n LUPLOU = LSAME( UPLO, 'U' )\n WITHC = LSAME( JOB, 'C' )\n WITHD = LSAME( JOB, 'D' )\n WITHF = LSAME( JOB, 'F' )\n WITHH = LSAME( JOB, 'H' )\n WITHL = LSAME( JOBL, 'N' )\n WITHXE = LSAME( JOBX, 'C' )\n LFACTA = LFACTC .OR. LFACTD .OR. LFACTU\n WITHCD = WITHC .OR. WITHD\n WITHH = WITHH .OR. WITHF .OR. WITHCD\n LNFACT = .NOT.LFACTA\nC\nC Test the input scalar arguments.\nC\n IF( .NOT.DISCR .AND. .NOT.LSAME( DICO, 'C' ) ) THEN\n INFO = -1\n ELSE IF( .NOT.LJOBE .AND. .NOT.LSAME( JOBE, 'I' ) .AND.\n $ .NOT.DISCR ) THEN\n INFO = -2\n ELSE IF( .NOT.WITHH .AND. .NOT.LSAME( JOB, 'K' ) ) THEN\n INFO = -3\n ELSE IF( .NOT.WITHXE .AND. .NOT.LSAME( JOBX, 'N' ) ) THEN\n IF( DISCR .OR. LJOBE )\n $ INFO = -4\n ELSE IF( ( LNFACT .AND. .NOT.LSAME( FACT, 'N' ) ) .OR.\n $ ( DISCR .AND. LFACTU ) .OR.\n $ ( .NOT.LFACTC .AND. WITHCD ) ) THEN\n INFO = -5\n ELSE IF( .NOT.LUPLOU .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN\n INFO = -6\n ELSE IF( .NOT.WITHL .AND. .NOT.LSAME( JOBL, 'Z' ) ) THEN\n INFO = -7\n ELSE IF( .NOT.LTRANS .AND. .NOT.LSAME( TRANS, 'N' ) ) THEN\n INFO = -8\n ELSE IF( N.LT.0 ) THEN\n INFO = -9\n ELSE IF( M.LT.0 ) THEN\n INFO = -10\n ELSE IF( LFACTD .AND. ( P.LT.0 .OR. ( .NOT.DISCR .AND. P.LT.M ) )\n $ ) THEN\n INFO = -11\n ELSE IF( LDA.LT.1 .OR. ( LDA.LT.N .AND. DISCR ) ) THEN\n INFO = -13\n ELSE IF( LDE.LT.1 .OR. ( LDE.LT.N .AND. .NOT.DISCR\n $ .AND. LJOBE ) ) THEN\n INFO = -15\n ELSE IF( LDB.LT.MAX( 1, N ) ) THEN\n INFO = -17\n ELSE IF( LDR.LT.MAX( 1, M ) .OR. ( LFACTD .AND. LDR.LT.P ) ) THEN\n INFO = -19\n ELSE IF( LDL.LT.1 .OR. ( WITHL .AND. LDL.LT.N ) ) THEN\n INFO = -22\n ELSE IF( LDX.LT.MAX( 1, N ) ) THEN\n INFO = -24\n ELSE IF( LFACTU ) THEN\n IF( RNORM.LT.ZERO )\n $ INFO = -25\n END IF\n IF ( INFO.EQ.0 ) THEN\n IF( LDK.LT.MAX( 1, M ) ) THEN\n INFO = -27\n ELSE IF( LDH.LT.1 .OR. ( WITHH .AND. LDH.LT.N ) ) THEN\n INFO = -29\n ELSE IF( LDXE.LT.1 .OR. ( WITHXE .AND. ( DISCR .OR. LJOBE )\n $ .AND. LDXE.LT.N ) ) THEN\n INFO = -31\n ELSE\n IF ( LUPLOU ) THEN\n NUPLO = 'Lower'\n ELSE\n NUPLO = 'Upper'\n END IF\n NM = N*M\n IF ( DISCR .AND. LFACTA .AND. .NOT.WITHCD ) THEN\n WRKMIN = MAX( 2, 3*M, 4*N + 1 )\n ELSE\n IF ( .NOT.WITHXE .AND. ( DISCR .OR. LJOBE ) ) THEN\n WRKMIN = MAX( 2, N )\n ELSE\n WRKMIN = 2\n END IF\n IF( LFACTU ) THEN\n WRKMIN = MAX( WRKMIN, 2*M )\n ELSE\n WRKMIN = MAX( WRKMIN, 3*M )\n END IF\n END IF\n IF( LDWORK.EQ.-1 ) THEN\n IF ( WITHXE .AND. ( DISCR .OR. LJOBE ) ) THEN\n IF ( DISCR .AND. LNFACT .AND. M.GT.N ) THEN\n WRKOPT = NM\n ELSE\n WRKOPT = 0\n END IF\n ELSE IF ( ( ( DISCR .AND. LFACTA ) .OR. ( .NOT.DISCR\n $ .AND. LJOBE ) ) .AND. N.LT.M ) THEN\n WRKOPT = N*N\n ELSE IF ( .NOT.( DISCR .OR. LJOBE ) .AND. WITHH ) THEN\n WRKOPT = 0\n ELSE\n WRKOPT = NM\n END IF\nC\n IF( LFACTA ) THEN\n IF ( LFACTD ) THEN\n CALL DGEQRF( P, M, R, LDR, DWORK, DWORK, -1, IFAIL)\n WRKOPT = MAX( WRKOPT, INT( DWORK(1) )+MIN( P, M ) )\n END IF\n IF( DISCR .AND. .NOT.WITHCD ) THEN\n CALL DSYEV( 'Vectors', NUPLO, N, X, LDX, DWORK,\n $ DWORK, -1, IFAIL )\n WRKOPT = MAX( WRKOPT, INT( DWORK(1) ) + N + 2,\n $ NM + N + 2 )\n END IF\n ELSE\n CALL DSYTRF( UPLO, M, R, LDR, IPIV, DWORK, -1, IFAIL )\n WRKOPT = MAX( WRKOPT, INT( DWORK(1) ) )\n END IF\n DWORK(1) = MAX( WRKMIN, WRKOPT )\n RETURN\n ELSE IF( LDWORK.EQ.-2 ) THEN\n DWORK(1) = WRKMIN\n RETURN\n ELSE IF( LDWORK.LT.WRKMIN ) THEN\n INFO = -35\n DWORK(1) = WRKMIN\n RETURN\n END IF\n END IF\n END IF\nC\n IF ( INFO.NE.0 ) THEN\nC\nC Error return.\nC\n CALL XERBLA( 'SG02ND', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF ( N.EQ.0 .OR. M.EQ.0 ) THEN\n DWORK(1) = TWO\n IF ( N.EQ.0 ) THEN\n DWORK(2) = ONE\n ELSE\n DWORK(2) = ZERO\n END IF\n RETURN\n END IF\nC\n EPS = DLAMCH( 'Precision' )\nC\nC Determine the right-hand side of the matrix equation, and R+B'XB,\nC if needed.\nC 1. If JOBX = 'N' or (DICO = 'C' and JOBE = 'I'), compute B'X\nC in K or XB either in H, if JOB <> 'K', or in the workspace, if\nC enough space. If JOB <> 'K', compute H in (3), otherwise compute\nC H' in K. The same formulas for H are used for JOB = 'D' or\nC JOB = 'C', but B and L on entry are transformed matrices; however,\nC the returned results correspond to the original matrices.\nC 2. If JOBX = 'C', compute op(Xop(E)) or op(Xop(A)) in XE, for\nC DICO = 'C' (and JOBE = 'G') or DICO = 'D', respectively.\nC Then, use XE in computations similar to those described above.\nC\nC (Note: Comments in the code beginning \"Workspace:\" describe the\nC minimal amount of real workspace needed at that point in the\nC code, as well as the preferred amount for good performance.\nC NB refers to the optimal block size for the immediately\nC following subroutine, as returned by ILAENV.)\nC\nC Workspace: need 0;\nC prefer N*N, if M > N and ((DICO = 'D' and FACT <> 'N')\nC or (DICO = 'C' and JOBE = 'G'))\nC and JOBX = 'N';\nC M*N, otherwise.\nC Only a triangle of X is needed when using the preferred length.\nC\n SUFWRK = LDWORK.GE.NM\nC\n NT = 'No transpose'\n TR = 'Transpose'\n IF ( LTRANS ) THEN\n NTRANS = NT\n SIDE = 'Right'\n ELSE\n NTRANS = TR\n SIDE = 'Left'\n END IF\nC\n IF ( WITHL ) THEN\n TEMP = ONE\n ELSE\n TEMP = ZERO\n END IF\nC\n IF ( WITHXE .AND. ( DISCR .OR. LJOBE ) ) THEN\n LASTCS = .FALSE.\n IF ( DISCR ) THEN\n IF ( LNFACT ) THEN\nC\nC Discrete-time case. Compute a triangle of R + B'XB.\nC\n IF ( M.LE.N ) THEN\n CALL MB01RU( UPLO, TR, M, N, ONE, ONE, R, LDR, B, LDB,\n $ X, LDX, XE, NM, INFO )\n WRKOPT = 0\n ELSE IF ( SUFWRK ) THEN\n CALL DSYMM( 'Left', UPLO, N, M, ONE, X, LDX, B, LDB,\n $ ZERO, DWORK, N )\n CALL MB01RB( 'Left', UPLO, TR, M, N, ONE, ONE, R, LDR,\n $ B, LDB, DWORK, N, IFAIL )\n WRKOPT = NM\n ELSE\nC\nC This case needs a full matrix X.\nC\n CALL DGEMM( TR, NT, M, N, N, ONE, B, LDB, X, LDX,\n $ ZERO, K, LDK )\n CALL MB01RB( 'Left', UPLO, NT, M, N, ONE, ONE, R, LDR,\n $ K, LDK, B, LDB, IFAIL )\n WRKOPT = 0\n END IF\n END IF\n CALL DSYMM( SIDE, UPLO, N, N, ONE, X, LDX, A, LDA, ZERO, XE,\n $ LDXE )\n ELSE\n CALL DSYMM( SIDE, UPLO, N, N, ONE, X, LDX, E, LDE, ZERO, XE,\n $ LDXE )\n WRKOPT = 0\n END IF\n IF ( WITHH ) THEN\n IF ( WITHL )\n $ CALL DLACPY( 'All', N, M, L, LDL, H, LDH )\n CALL DGEMM( NTRANS, NT, N, M, N, ONE, XE, LDXE, B, LDB,\n $ TEMP, H, LDH )\n CALL MA02AD( 'All', N, M, H, LDH, K, LDK )\n ELSE\n IF ( WITHL )\n $ CALL MA02AD( 'All', N, M, L, LDL, K, LDK )\n CALL DGEMM( TR, TRANS, M, N, N, ONE, B, LDB, XE, LDXE, TEMP,\n $ K, LDK )\n END IF\nC\n ELSE IF ( (( DISCR .AND. LFACTA ) .OR. ( .NOT.DISCR .AND. LJOBE ))\n $ .AND. N.LT.M .AND. LDWORK.GE.N*N ) THEN\n LASTCS = .FALSE.\n IF ( DISCR ) THEN\n CALL DSYMM( SIDE, UPLO, N, N, ONE, X, LDX, A, LDA, ZERO,\n $ DWORK, N )\n ELSE\n CALL DSYMM( SIDE, UPLO, N, N, ONE, X, LDX, E, LDE, ZERO,\n $ DWORK, N )\n END IF\nC\n IF ( WITHH ) THEN\n IF ( WITHL )\n $ CALL DLACPY( 'All', N, M, L, LDL, H, LDH )\n CALL DGEMM( NTRANS, NT, N, M, N, ONE, DWORK, N, B, LDB,\n $ TEMP, H, LDH )\n CALL MA02AD( 'All', N, M, H, LDH, K, LDK )\n ELSE\n IF ( WITHL )\n $ CALL MA02AD( 'All', N, M, L, LDL, K, LDK )\n CALL DGEMM( TR, TRANS, M, N, N, ONE, B, LDB, DWORK, N, TEMP,\n $ K, LDK )\n END IF\n WRKOPT = N*N\nC\n ELSE IF ( .NOT.( DISCR .OR. LJOBE ) .AND. WITHH ) THEN\nC\nC Continuous-time case, with E identity, JOB <> 'K'.\nC\n LASTCS = .FALSE.\nC\n IF ( WITHH ) THEN\n IF ( WITHL )\n $ CALL DLACPY( 'All', N, M, L, LDL, H, LDH )\n CALL DSYMM( 'Left', UPLO, N, M, ONE, X, LDX, B, LDB, TEMP,\n $ H, LDH )\n CALL MA02AD( 'All', N, M, H, LDH, K, LDK )\n WRKOPT = 0\n END IF\nC\n ELSE IF ( SUFWRK ) THEN\n LASTCS = .FALSE.\n IF ( DISCR .OR. LJOBE ) THEN\n CALL DSYMM( 'Left', UPLO, N, M, ONE, X, LDX, B, LDB, ZERO,\n $ DWORK, N )\n IF ( WITHH ) THEN\n IF ( WITHL )\n $ CALL DLACPY( 'All', N, M, L, LDL, H, LDH )\n IF ( DISCR ) THEN\n CALL DGEMM( NTRANS, NT, N, M, N, ONE, A, LDA, DWORK,\n $ N, TEMP, H, LDH )\n ELSE\n CALL DGEMM( NTRANS, NT, N, M, N, ONE, E, LDE, DWORK,\n $ N, TEMP, H, LDH )\n END IF\n CALL MA02AD( 'All', N, M, H, LDH, K, LDK )\n ELSE\n IF ( WITHL )\n $ CALL MA02AD( 'All', N, M, L, LDL, K, LDK )\n IF ( DISCR ) THEN\n CALL DGEMM( TR, TRANS, M, N, N, ONE, DWORK, N, A, LDA,\n $ TEMP, K, LDK )\n ELSE\n CALL DGEMM( TR, TRANS, M, N, N, ONE, DWORK, N, E, LDE,\n $ TEMP, K, LDK )\n END IF\n END IF\n WRKOPT = NM\nC\n ELSE IF ( .NOT.WITHH .OR. LDWORK.GE.NM ) THEN\nC\nC Continuous-time case, E identity.\nC\n IF ( WITHH ) THEN\n IF ( WITHL )\n $ CALL DLACPY( 'All', N, M, L, LDL, H, LDH )\n CALL DSYMM( 'Left', UPLO, N, M, ONE, X, LDX, B, LDB,\n $ TEMP, H, LDH )\n CALL MA02AD( 'All', N, M, H, LDH, K, LDK )\n WRKOPT = 0\n ELSE\n IF ( WITHL )\n $ CALL DLACPY( 'All', N, M, L, LDL, DWORK, N )\n CALL DSYMM( 'Left', UPLO, N, M, ONE, X, LDX, B, LDB,\n $ TEMP, DWORK, N )\n CALL MA02AD( 'All', N, M, DWORK, N, K, LDK )\n WRKOPT = NM\n END IF\n END IF\nC\n ELSE\nC\nC This case needs a full matrix X.\nC\n LASTCS = .TRUE.\nC\n IF( WITHH ) THEN\n CALL DGEMM( NT, NT, N, M, N, ONE, X, LDX, B, LDB, ZERO, H,\n $ LDH )\n ELSE\n CALL DGEMM( TR, NT, M, N, N, ONE, B, LDB, X, LDX, ZERO, K,\n $ LDK )\n END IF\n WRKOPT = 0\n END IF\nC\n IF ( LNFACT ) THEN\nC\nC R not factored.\nC\n IF ( DISCR .AND. .NOT.WITHXE ) THEN\nC\nC Discrete-time case. Compute a triangle of R + B'XB.\nC\n IF ( SUFWRK ) THEN\n CALL MB01RB( 'Left', UPLO, TR, M, N, ONE, ONE, R, LDR,\n $ DWORK, N, B, LDB, IFAIL )\n ELSE IF( WITHH ) THEN\n CALL MB01RB( 'Left', UPLO, TR, M, N, ONE, ONE, R, LDR, B,\n $ LDB, H, LDH, IFAIL )\n ELSE\n CALL MB01RB( 'Left', UPLO, NT, M, N, ONE, ONE, R, LDR, K,\n $ LDK, B, LDB, IFAIL )\n END IF\n END IF\nC\nC Compute the 1-norm of the matrix R or R + B'XB.\nC Workspace: need M.\nC\n RNORMP = DLANSY( '1-norm', UPLO, M, R, LDR, DWORK )\n END IF\nC\n IF ( LASTCS ) THEN\n MS = MAX( INT( LDWORK/N ), 1 )\nC\nC Workspace (for DICO = 'D' or JOBE = 'G'): need N;\nC prefer N*M.\n IF ( WITHH ) THEN\nC\nC Premultiply XB by op(A)' or by op(E)' (on block-columns).\nC Add L if needed.\nC\n IF ( DISCR ) THEN\nC\n DO 10 I = 1, M, MS\n NR = MIN( MS, M-I+1 )\n CALL DLACPY( 'All', N, NR, H(1,I), LDH, DWORK, N )\n IF ( WITHL )\n $ CALL DLACPY( 'All', N, NR, L(1,I), LDL, H(1,I),\n $ LDH )\n CALL DGEMM( NTRANS, NT, N, NR, N, ONE, A, LDA, DWORK,\n $ N, TEMP, H(1,I), LDH )\n 10 CONTINUE\nC\n ELSE IF ( LJOBE ) THEN\nC\n DO 20 I = 1, M, MS\n NR = MIN( MS, M-I+1 )\n CALL DLACPY( 'All', N, NR, H(1,I), LDH, DWORK, N )\n IF ( WITHL )\n $ CALL DLACPY( 'All', N, NR, L(1,I), LDL, H(1,I),\n $ LDH )\n CALL DGEMM( NTRANS, NT, N, NR, N, ONE, E, LDE, DWORK, \n $ N, TEMP, H(1,I), LDH )\n 20 CONTINUE\nC\n ELSE IF ( WITHL ) THEN\nC\n DO 30 I = 1, M\n CALL DAXPY( N, ONE, L(1,I), 1, K(I,1), LDK )\n 30 CONTINUE\nC\n END IF\n CALL MA02AD( 'All', N, M, H, LDH, K, LDK )\nC\n ELSE\nC\nC Postmultiply B'X by op(A) or by op(E) (on block-rows).\nC Add L if needed.\nC\n IF ( DISCR ) THEN\nC\n DO 40 I = 1, M, MS\n NR = MIN( MS, M-I+1 )\n CALL DLACPY( 'All', NR, N, K(I,1), LDK, DWORK, NR )\n IF ( WITHL )\n $ CALL MA02AD( 'All', N, NR, L(1,I), LDL, K(I,1),\n $ LDK )\n CALL DGEMM( NT, TRANS, NR, N, N, ONE, DWORK, NR, A,\n $ LDA, TEMP, K(I,1), LDK )\n 40 CONTINUE\nC\n ELSE IF ( LJOBE ) THEN\nC\n DO 50 I = 1, M, MS\n NR = MIN( MS, M-I+1 )\n CALL DLACPY( 'All', NR, N, K(I,1), LDK, DWORK, NR )\n IF ( WITHL )\n $ CALL MA02AD( 'All', N, NR, L(1,I), LDL, K(I,1),\n $ LDK )\n CALL DGEMM( NT, TRANS, NR, N, N, ONE, DWORK, NR, E,\n $ LDE, TEMP, K(I,1), LDK )\n 50 CONTINUE\nC\n ELSE IF ( WITHL ) THEN\nC\n DO 60 I = 1, M\n CALL DAXPY( N, ONE, L(1,I), 1, K(I,1), LDK )\n 60 CONTINUE\nC\n END IF\n END IF\nC\n END IF\nC\n WRKOPT = MAX( WRKMIN, WRKOPT )\nC\nC Solve the matrix equation.\nC\n IF ( LUPLOU ) THEN\n TRL = NT\n ELSE\n TRL = TR\n END IF\nC\n IF ( LFACTA ) THEN\nC\nC Case 1: Matrix R is given in a factored form.\nC\n IF ( LFACTD ) THEN\nC\nC Use QR factorization of D.\nC Workspace: need min(P,M) + M,\nC prefer min(P,M) + M*NB.\nC\n JW = MIN( P, M ) + 1\n CALL DGEQRF( P, M, R, LDR, DWORK, DWORK(JW), LDWORK-JW+1,\n $ IFAIL )\n WRKOPT = MAX( WRKOPT, INT( DWORK(JW) )+JW-1 )\n IF ( P.LT.M )\n $ CALL DLASET( 'Full', M-P, M, ZERO, ZERO, R(P+1,1), LDR )\nC\nC Make positive the diagonal elements of the triangular\nC factor. Construct the strictly lower triangle, if requested.\nC\n DO 70 I = 1, M\n IF ( .NOT.LUPLOU )\n $ CALL DCOPY( I-1, R(1,I), 1, R(I,1), LDR )\n IF ( R(I,I).LT.ZERO )\n $ CALL DSCAL( M-I+1, -ONE, R(I,I), LDR )\n 70 CONTINUE\nC\n END IF\nC\n IF ( DISCR .AND. .NOT.WITHCD ) THEN\n JZ = 0\nC\nC Discrete-time case. Update the factorization for B'XB.\nC Try first the Cholesky factorization of X, saving the\nC diagonal of X, in order to recover it, if X is not positive\nC definite. In the later case, use spectral factorization.\nC Workspace: need N.\nC\n CALL DCOPY( N, X, LDX+1, DWORK, 1 )\n CALL DPOTRF( UPLO, N, X, LDX, IFAIL )\nC\n IF ( IFAIL.EQ.0 ) THEN\nC\nC Use Cholesky factorization of X to compute chol(X)*B.\nC\n OUFACT(2) = 1\n CALL DTRMM( 'Left', UPLO, TRL, 'Non unit', N, M, ONE, X,\n $ LDX, B, LDB )\n ELSE\nC\nC Use spectral factorization of X, X = UVU'.\nC Workspace: need 4*N+1,\nC prefer N*(NB+2)+N+2.\nC\n JW = N + 3\n OUFACT(2) = 2\n CALL DCOPY( N, DWORK, 1, X, LDX+1 )\n CALL DSYEV( 'Vectors', NUPLO, N, X, LDX, DWORK(3),\n $ DWORK(JW), LDWORK-JW+1, IFAIL )\n IF ( IFAIL.GT.0 ) THEN\n INFO = M + 2\n RETURN\n END IF\n WRKOPT = MAX( WRKOPT, INT( DWORK(JW) )+JW-1 )\n TEMP = ABS( DWORK(N+2) )*EPS*DBLE( N )\nC\nC Check out the positive (semi-)definiteness of X.\nC First, count the negligible eigenvalues.\nC\n 80 CONTINUE\n IF ( ABS( DWORK(JZ+3) ).LE.TEMP ) THEN\n JZ = JZ + 1\n IF ( JZ.LT.N )\n $ GO TO 80\n END IF\nC\n IF ( LFACTD .AND. N-JZ+P.LT.M ) THEN\nC\nC The coefficient matrix is (numerically) singular.\nC\n OUFACT(1) = 1\n DWORK(2) = ZERO\n INFO = M + 1\n RETURN\n END IF\nC\n IF ( DWORK(JZ+3).LT.ZERO ) THEN\nC\nC X is not positive (semi-)definite. Updating fails.\nC\n INFO = M + 3\n RETURN\n ELSE\nC\nC Compute sqrt(V)U'B.\nC Workspace: need 2*N+2;\nC prefer N*M+N+2.\nC\n WRKOPT = MAX( WRKOPT, NM + JW - 1 )\n MS = MAX( INT( ( LDWORK - JW + 1 )/N ), 1 )\nC\n DO 90 I = 1, M, MS\n NR = MIN( MS, M-I+1 )\n CALL DLACPY( 'All', N, NR, B(1,I), LDB, DWORK(JW),\n $ N )\n CALL DGEMM( TR, NT, N-JZ, NR, N, ONE, X(1,JZ+1),\n $ LDX, DWORK(JW), N, ZERO, B(JZ+1,I),\n $ LDB )\n 90 CONTINUE\nC\n DO 100 I = JZ + 1, N\n CALL DSCAL( M, SQRT( DWORK(I+2) ), B(I,1), LDB )\n 100 CONTINUE\nC\n END IF\nC\n END IF\nC\nC Update the triangular factorization.\nC\n IF ( .NOT.LUPLOU )\nC\nC Transpose the lower triangle for using MB04KD.\nC\n $ CALL MA02ED( UPLO, M, R, LDR )\nC\nC Workspace: need 2*M.\nC\n CALL MB04KD( 'Full', M, 0, N-JZ, R, LDR, B(JZ+1,1), LDB,\n $ DUMMY, N, DUMMY, M, DWORK, DWORK(M+1) )\nC\nC Make positive the diagonal elements of the triangular\nC factor.\nC\n DO 110 I = 1, M\n IF ( R(I,I).LT.ZERO )\n $ CALL DSCAL( M-I+1, -ONE, R(I,I), LDR )\n 110 CONTINUE\nC\n IF ( .NOT.LUPLOU )\nC\nC Construct the lower triangle.\nC\n $ CALL MA02ED( NUPLO, M, R, LDR )\nC\n END IF\nC\nC Compute the condition number of the coefficient matrix.\nC\n IF ( .NOT.LFACTU ) THEN\nC\nC Workspace: need 3*M.\nC\n CALL DTRCON( '1-norm', UPLO, 'Non unit', M, R, LDR, RCOND,\n $ DWORK, IWORK, IFAIL )\n OUFACT(1) = 1\n ELSE\nC\nC Workspace: need 2*M.\nC\n CALL DSYCON( UPLO, M, R, LDR, IPIV, RNORM, RCOND, DWORK,\n $ IWORK, IFAIL )\n OUFACT(1) = 2\n END IF\nC\n ELSE\nC\nC Case 2: Matrix R is given in an unfactored form.\nC\nC Save the given triangle of R or R + B'XB in the other\nC strict triangle and the diagonal in the workspace, and try\nC Cholesky factorization.\nC Workspace: need M.\nC\n CALL DCOPY( M, R, LDR+1, DWORK, 1 )\n CALL MA02ED( UPLO, M, R, LDR )\n CALL DPOTRF( UPLO, M, R, LDR, IFAIL )\n IF( IFAIL.EQ.0 ) THEN\n OUFACT(1) = 1\nC\nC Compute the reciprocal of the condition number of R\nC or R + B'XB.\nC Workspace: need 3*M.\nC\n CALL DPOCON( UPLO, M, R, LDR, RNORMP, RCOND, DWORK, IWORK,\n $ IFAIL )\n ELSE\n OUFACT(1) = 2\nC\nC Use UdU' or LdL' factorization, first restoring the saved\nC triangle.\nC\n CALL DCOPY( M, DWORK, 1, R, LDR+1 )\n CALL MA02ED( NUPLO, M, R, LDR )\nC\nC Workspace: need 1,\nC prefer M*NB.\nC\n CALL DSYTRF( UPLO, M, R, LDR, IPIV, DWORK, LDWORK, INFO )\n IF( INFO.GT.0 )\n $ RETURN\n WRKOPT = MAX( WRKOPT, INT( DWORK(1) ) )\nC\nC Compute the reciprocal of the condition number of R.\nC Workspace: need 2*M.\nC\n CALL DSYCON( UPLO, M, R, LDR, IPIV, RNORMP, RCOND, DWORK,\n $ IWORK, IFAIL )\n END IF\n END IF\nC\nC Return if the matrix is singular to working precision.\nC\n DWORK(2) = RCOND\n IF( RCOND.LT.EPS ) THEN\n INFO = M + 1\n RETURN\n END IF\nC\n IF ( OUFACT(1).EQ.1 ) THEN\nC\nC Solve the positive definite linear system.\nC\n IF ( WITHF ) THEN\n CALL DTRSM( 'Right', UPLO, TRL, 'Non-unit', N, M, ONE, R,\n $ LDR, H, LDH )\n ELSE IF ( WITHD ) THEN\n CALL DTRMM( 'Right', UPLO, TRL, 'Non-unit', N, M, ONE, R,\n $ LDR, H, LDH )\n CALL DTRSM( 'Left', UPLO, TRL, 'Non-unit', M, N, ONE, R,\n $ LDR, K, LDK )\n ELSE IF ( .NOT.WITHC ) THEN\n CALL DPOTRS( UPLO, M, N, R, LDR, K, LDK, IFAIL )\n END IF\n ELSE\nC\nC Solve the indefinite linear system.\nC\n CALL DSYTRS( UPLO, M, N, R, LDR, IPIV, K, LDK, IFAIL )\n END IF\nC\nC Set the optimal workspace.\nC\n DWORK(1) = WRKOPT\nC\n RETURN\nC *** Last line of SG02ND ***\n END\n", "meta": {"hexsha": "3130d09f90ab046bedef07d95d4d72786003e7aa", "size": 47283, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/SG02ND.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/SG02ND.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/SG02ND.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 39.2390041494, "max_line_length": 72, "alphanum_fraction": 0.4774654738, "num_tokens": 14445, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.938124016006303, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6741306630918056}} {"text": "!> \\file mo_mcmc.f90\n\n!> \\brief This module is Monte Carlo Markov Chain sampling of a posterior parameter distribution.\n\n!> \\details This module is Monte Carlo Markov Chain sampling of a posterior parameter distribution.\n\n!> \\authors Maren Goehler, Juliane Mai\n!> \\date Aug 2012\n\nMODULE mo_mcmc\n\n ! License\n ! -------\n ! This file is part of the JAMS Fortran package, distributed under the MIT License.\n !\n ! Copyright (c) 2012-2014 Juliane Mai\n !\n ! Permission is hereby granted, free of charge, to any person obtaining a copy\n ! of this software and associated documentation files (the \"Software\"), to deal\n ! in the Software without restriction, including without limitation the rights\n ! to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n ! copies of the Software, and to permit persons to whom the Software is\n ! furnished to do so, subject to the following conditions:\n !\n ! The above copyright notice and this permission notice shall be included in all\n ! copies or substantial portions of the Software.\n !\n ! THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n ! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n ! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n ! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n ! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n ! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n ! SOFTWARE.\n\n USE mo_kind, only: i4, i8, dp\n USE mo_xor4096, only: xor4096, xor4096g, get_timeseed, n_save_state\n USE mo_append, only: append\n USE mo_moment, only: stddev\n !$ USE omp_lib, only: OMP_GET_NUM_THREADS\n use mo_ncdump, only: dump_netcdf\n\n IMPLICIT NONE\n\n PUBLIC :: mcmc ! Sample posterior parameter distribution (measurement errors are either known or modeled)\n PUBLIC :: mcmc_stddev ! Sample posterior parameter distribution (measurement errors are neither known nor modeled)\n\n !-----------------------------------------------------------------------------------------------\n !\n ! NAME\n ! mcmc\n !\n ! PURPOSE\n !> \\brief This module is Monte Carlo Markov Chain sampling of a posterior parameter distribution \n !> (measurement errors are either known or modeled).\n !\n !> \\details Sample posterior parameter distribution with Metropolis Algorithm.\\n\n !> This sampling is performed in two steps, i.e. the burn-in phase for adjusting \n !> model dependent parameters for the second step which is the proper \n !> sampling using the Metropolis Hastings Algorithm.\\n\\n\n !>\n !> This sampler does not change the best parameter set, i.e.\n !> it cannot be used as an optimiser.\\n\n !> However, the serial and the parallel version give therefore the bitwise same results.\n !\n !> 1. BURN IN PHASE: FIND THE OPTIMAL STEP SIZE \\n\\n\n !\n !> Purpose:\\n\n !> Find optimal stepsize for each parameter such that the\n !> acceptance ratio converges to a value around 0.3.\\n\n !>\n !> Important variables:\\n\n !>\n !> Variable | Description \n !> ---------------------- | -----------------------------------------------------------------------\n !> burnin_iter | length of markov chain performed to calculate acceptance ratio\\n\n !> acceptance ratio | ratio between accepted jumps and all trials (LEN)\\n\n !> acceptance multiplier | stepsize of a parameter is multiplied with this value when jump is \n !> accepted (initial : 1.01)\n !> rejection multiplier | stepsize of a parameter is multiplied with this value when jump is rejected \n !> (initial : 0.99 and will never be changed)\n !> stepsize | a new parameter value is chosen based on a uniform distribution \n !> pnew_i = pold_i + Unif(-stepsize_i, stepsize_i) (initial : stepsize_i = 1.0 for all i)\n !\n !> \\n\n !> Algorithm:\\n\n !>
    \n !>
  1. start a new markov chain of length burnin_iter with initial parameter set is the OPTIMAL one\\n\n !> - select a set of parameters to change:\\n\n !> * accurate --> choose one parameter,\\n\n !> * comput. efficient --> choose all parameters,\\n\n !> * moderate accurate & efficient --> choose half of the parameters\\n\n !> - change parameter(s) based on their stepsize\\n\n !> - decide whether changed parameter set is accepted or rejected:\\n\n !> * \\f$ \\mathrm{odds Ratio} = \\frac{\\mathrm{likelihood}(p_{new})}{\\mathrm{likelihood}(p_{old})} \\f$\\n\n !> * random number r = Uniform[0,1]\\n\n !> * odds Ratio > 0 --> positive accept\\n\n !> odds Ratio > r --> negative accept\\n\n !> odds Ratio < r --> reject\\n\n !> - adapt stepsize of parameters changed:\\n\n !> * accepted step: stepsize_i = stepsize_i * accptance multiplier\\n\n !> * rejected step: stepsize_i = stepsize_i * rejection multiplier\\n\n !> - if step is accepted: for all changed parameter(s) change stepsize\\n\n !\n !>
  2. calculate acceptance ratio of the Markov Chain\\n\n !\n !>
  3. adjust acceptance multiplier acc_mult and\n !> store good ratios in history list\\n\n !> - acceptance ratio < 0.23 --> acc_mult = acc_mult * 0.99\\n\n !> delete history list\\n\n !> - acceptance ratio > 0.44 --> acc_mult = acc_mult * 1.01\\n\n !> delete history list\\n\n !> - 0.23 < acceptance ratio < 0.44\\n\n !> add acceptance ratio to history list\\n\n !\n !>
  4. check if already 10 values are stored in history list and\n !> if they have converged to a value above 0.3\\n\n !> ( mean above 0.3 and variance less \\f$\\sqrt{1/12*0.05^2}\\f$ = Variance\n !> of uniform [acc_ratio +/- 2.5%] )\\n\n !> - if check is positive abort and save stepsizes\\n\n !> else goto (1)\\n\\n\n !>
\n !\n !>\n !> 2. MONTE CARLO MARKOV CHAIN: SAMPLE POSTERIOR DISTRIBUTION OF PARAMETER\\n\\n\n !> Purpose:\\n\n !> use the previous adapted stepsizes and perform ONE monte carlo markov chain\\n\n !> the accepted parameter sets show the posterior distribution of parameters\\n\n !>\n !> Important variables:\\n\n !> Variable | Description \n !> ---------------------- | -----------------------------------------------------------------------\n !> iter_mcmc | length of the markov chain (>> iter_burnin)\\n\n !> stepsize | a new parameter value is chosen based on a uniform distribution \n !> pnew_i = pold_i + Unif(-stepsize_i, stepsize_i) use stepsizes of the burn-in (1)\\n\n !\n !> \\n\n !> Algorithm:\\n\n !>
    \n !>
  1. select a set of parameters to change\\n\n !> * accurate --> choose one parameter,\\n\n !> * comput. efficient --> choose all parameters,\\n\n !> * moderate accurate & efficient --> choose half of the parameters\\n\n !>
  2. change parameter(s) based on their stepsize\\n\n !>
  3. decide whether changed parameter set is accepted or rejected:\\n\n !> * \\f$ \\mathrm{odds Ratio} = \\frac{\\mathrm{likelihood}(p_{new})}{\\mathrm{likelihood}(p_{old})} \\f$\\n\n !> * random number r = Uniform[0,1]\\n\n !> * odds Ratio > 0 --> positive accept\\n\n !> odds Ratio > r --> negative accept\\n\n !> odds Ratio < r --> reject\\n\n !>
  4. if step is accepted: save parameter set\\n\n !>
  5. goto (1)\\n\n !>
\n\n ! CALLING SEQUENCE\n ! call mcmc( likelihood, para, rangePar, mcmc_paras, burnin_paras, &\n ! seed_in=seeds, printflag_in=printflag, maskpara_in=maskpara, &\n ! tmp_file=tmp_file, loglike_in=loglike, &\n ! ParaSelectMode_in=ParaSelectMode, &\n ! iter_burnin_in=iter_burnin, iter_mcmc_in=iter_mcmc, &\n ! chains_in=chains, stepsize_in=stepsize)\n\n ! INTENT(IN)\n !> \\param[in] \"real(dp) :: likelihood(x)\" Interface Function which calculates likelihood \n !> of given parameter set x\n\n !> \\param[in] \"real(dp) :: para(:)\" Inital parameter set (should be GOOD approximation \n !> of best parameter set)\n\n !> \\param[in] \"real(dp) :: rangePar(size(para),2)\" Min/max range of parameters\n\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n !> \\param[out] \"real(dp), allocatable :: mcmc_paras(:,:)\" Parameter sets sampled in proper MCMC part of algorithm\n !> \\param[out] \"real(dp), allocatable :: burnin_paras(:,:)\" Parameter sets sampled during burn-in part of algorithm\n\n ! INTENT(IN), OPTIONAL\n !> \\param[in] \"integer(i8), optional :: seed_in\" User seed to initialise the random number generator \\n\n !> (default: none --> initialized with timeseed)\n\n !> \\param[in] \"logical, optional :: printflag_in\" Print of output on command line \\n\n !> (default: .False.)\n\n !> \\param[in] \"logical, optional :: maskpara_in(size(para))\" \n !> Parameter will be sampled (.True.) or not (.False.) \\n\n !> (default: .True.)\n\n !> \\param[in] \"character(len=*), optional :: tmp_file\" filename for temporal data saving: \\n\n !> every iter_mcmc_in iterations parameter sets are \n !> appended to this file \\n\n !> the number of the chain will be prepended to filename \\n\n !> output format: netcdf \\n\n !> (default: no file writing)\n\n !> \\param[in] \"logical, optional :: loglike_in\" true if loglikelihood function is given instead of \n !> likelihood function \\n\n !> (default: .false.)\n\n !> \\param[in] \"integer(i4), optional :: ParaSelectMode_in\" \n !> How many parameters will be changed at once?\n !> - half of the parameter --> 1_i4\n !> - only one parameter --> 2_i4\n !> - all parameter --> 3_i4\n !> (default: 2_i4)\n\n !> \\param[in] \"integer(i4), optional :: iter_burnin_in\" Length of Markov chains of initial burn-in part \\n\n !> (default: Max(250, 200*count(maskpara)) )\n\n !> \\param[in] \"integer(i4), optional :: iter_mcmc_in\" Length of Markov chains of proper MCMC part \\n\n !> (default: 1000 * count(maskpara) )\n\n !> \\param[in] \"integer(i4), optional :: chains_in\" number of parallel mcmc chains \\n\n !> (default: 5_i4)\n\n !> \\param[in] \"real(dp), DIMENSION(size(para,1)), optional :: stepsize_in\"\n !> stepsize for each parameter \\n\n !> if given burn-in is discarded \\n\n !> (default: none --> adjusted in burn-in)\n\n ! INTENT(INOUT), OPTIONAL\n ! None\n\n ! INTENT(OUT), OPTIONAL\n ! None\n\n ! RESTRICTIONS\n !> \\note Likelihood has to be defined as a function interface\\n\n !> The maximal number of parameters is 1000. \n ! -> see also example in test directory\n\n ! EXAMPLE\n ! -> see also example in test directory\n\n ! LITERATURE\n ! Gelman et. al (1995)\n ! Baysian Data Analyis, Chapman & Hall.\n ! Gelman et. al (1997)\n ! Efficient Metropolis Jumping Rules, Baysian Statistics 5, pp. 599-607\n ! Tautenhahn et. al (2012)\n ! Beyond distance-invariant survival in inverse recruitment modeling:\n ! A case study in Siberian Pinus sylvestris forests, Ecological Modelling, 233,\n ! 90-103. doi:10.1016/j.ecolmodel.2012.03.009.\n\n ! HISTORY\n ! Written Mai, Nov. 2014 : add new routine for mcmc\n ! mcmc, i.e. mcmc with \"real\" likelihood (sigma is given by e.g. error model)\n !\n INTERFACE mcmc\n MODULE PROCEDURE mcmc_dp\n END INTERFACE mcmc\n\n !-----------------------------------------------------------------------------------------------\n !\n ! NAME\n ! mcmc_stddev\n !\n ! PURPOSE\n !> \\brief This module is Monte Carlo Markov Chain sampling of a posterior parameter distribution \n !> (measurement errors are neither known nor modeled).\n !\n !> \\details Sample posterior parameter distribution with Metropolis Algorithm.\\n\n !> This sampling is performed in two steps, i.e. the burn-in phase for adjusting \n !> model dependent parameters for the second step which is the proper \n !> sampling using the Metropolis Hastings Algorithm.\\n\\n\n !\n !> 1. BURN IN PHASE: FIND THE OPTIMAL STEP SIZE \\n\\n\n !\n !> Purpose:\\n\n !> Find optimal stepsize for each parameter such that the\n !> acceptance ratio converges to a value around 0.3.\\n\n !>\n !> Important variables:\\n\n !>\n !> Variable | Description \n !> ---------------------- | -----------------------------------------------------------------------\n !> burnin_iter | length of markov chain performed to calculate acceptance ratio\\n\n !> acceptance ratio | ratio between accepted jumps and all trials (LEN)\\n\n !> acceptance multiplier | stepsize of a parameter is multiplied with this value when jump is \n !> accepted (initial : 1.01)\n !> rejection multiplier | stepsize of a parameter is multiplied with this value when jump is rejected \n !> (initial : 0.99 and will never be changed)\n !> stepsize | a new parameter value is chosen based on a uniform distribution \n !> pnew_i = pold_i + Unif(-stepsize_i, stepsize_i) (initial : stepsize_i = 1.0 for all i)\n !\n !> \\n\n !> Algorithm:\\n\n !>
    \n !>
  1. start a new markov chain of length burnin_iter with initial parameter set is the OPTIMAL one\\n\n !> - select a set of parameters to change:\\n\n !> * accurate --> choose one parameter,\\n\n !> * comput. efficient --> choose all parameters,\\n\n !> * moderate accurate & efficient --> choose half of the parameters\\n\n !> - change parameter(s) based on their stepsize\\n\n !> - decide whether changed parameter set is accepted or rejected:\\n\n !> * \\f$ \\mathrm{odds Ratio} = \\frac{\\mathrm{likelihood}(p_{new})}{\\mathrm{likelihood}(p_{old})} \\f$\\n\n !> * random number r = Uniform[0,1]\\n\n !> * odds Ratio > 0 --> positive accept\\n\n !> odds Ratio > r --> negative accept\\n\n !> odds Ratio < r --> reject\\n\n !> - adapt stepsize of parameters changed:\\n\n !> * accepted step: stepsize_i = stepsize_i * accptance multiplier\\n\n !> * rejected step: stepsize_i = stepsize_i * rejection multiplier\\n\n !> - if step is accepted: for all changed parameter(s) change stepsize\\n\n !\n !>
  2. calculate acceptance ratio of the Markov Chain\\n\n !\n !>
  3. adjust acceptance multiplier acc_mult and\n !> store good ratios in history list\\n\n !> - acceptance ratio < 0.23 --> acc_mult = acc_mult * 0.99\\n\n !> delete history list\\n\n !> - acceptance ratio > 0.44 --> acc_mult = acc_mult * 1.01\\n\n !> delete history list\\n\n !> - 0.23 < acceptance ratio < 0.44\\n\n !> add acceptance ratio to history list\\n\n !\n !>
  4. check if already 10 values are stored in history list and\n !> if they have converged to a value above 0.3\\n\n !> ( mean above 0.3 and variance less \\f$\\sqrt{1/12*0.05^2}\\f$ = Variance\n !> of uniform [acc_ratio +/- 2.5%] )\\n\n !> - if check is positive abort and save stepsizes\\n\n !> else goto (1)\\n\\n\n !>
\n !\n !>\n !> 2. MONTE CARLO MARKOV CHAIN: SAMPLE POSTERIOR DISTRIBUTION OF PARAMETER\\n\\n\n !> Purpose:\\n\n !> use the previous adapted stepsizes and perform ONE monte carlo markov chain\\n\n !> the accepted parameter sets show the posterior distribution of parameters\\n\n !>\n !> Important variables:\\n\n !> Variable | Description \n !> ---------------------- | -----------------------------------------------------------------------\n !> iter_mcmc | length of the markov chain (>> iter_burnin)\\n\n !> stepsize | a new parameter value is chosen based on a uniform distribution \n !> pnew_i = pold_i + Unif(-stepsize_i, stepsize_i) use stepsizes of the burn-in (1)\\n\n !\n !> \\n\n !> Algorithm:\\n\n !>
    \n !>
  1. select a set of parameters to change\\n\n !> * accurate --> choose one parameter,\\n\n !> * comput. efficient --> choose all parameters,\\n\n !> * moderate accurate & efficient --> choose half of the parameters\\n\n !>
  2. change parameter(s) based on their stepsize\\n\n !>
  3. decide whether changed parameter set is accepted or rejected:\\n\n !> * \\f$ \\mathrm{odds Ratio} = \\frac{\\mathrm{likelihood}(p_{new})}{\\mathrm{likelihood}(p_{old})} \\f$\\n\n !> * random number r = Uniform[0,1]\\n\n !> * odds Ratio > 0 --> positive accept\\n\n !> odds Ratio > r --> negative accept\\n\n !> odds Ratio < r --> reject\\n\n !>
  4. if step is accepted: save parameter set\\n\n !>
  5. goto (1)\\n\n !>
\n\n ! CALLING SEQUENCE\n ! call mcmc( likelihood, para, rangePar, mcmc_paras, burnin_paras, &\n ! seed_in=seeds, printflag_in=printflag, maskpara_in=maskpara, &\n ! tmp_file=tmp_file, loglike_in=loglike, &\n ! ParaSelectMode_in=ParaSelectMode, &\n ! iter_burnin_in=iter_burnin, iter_mcmc_in=iter_mcmc, &\n ! chains_in=chains, stepsize_in=stepsize)\n\n ! INTENT(IN)\n !> \\param[in] \"real(dp) :: likelihood(x,sigma,stddev_new,likeli_new)\" \n !> Interface Function which calculates likelihood \n !> of given parameter set x and given standard deviation sigma \n !> and returns optionally the standard deviation stddev_new\n !> of the errors using x and \n !> likelihood likeli_new using stddev_new\n\n !> \\param[in] \"real(dp) :: para(:)\" Inital parameter set (should be GOOD approximation \n !> of best parameter set)\n\n !> \\param[in] \"real(dp) :: rangePar(size(para),2)\" Min/max range of parameters\n\n ! INTENT(INOUT)\n ! None\n\n ! INTENT(OUT)\n !> \\param[out] \"real(dp), allocatable :: mcmc_paras(:,:)\" Parameter sets sampled in proper MCMC part of algorithm\n !> \\param[out] \"real(dp), allocatable :: burnin_paras(:,:)\" Parameter sets sampled during burn-in part of algorithm\n\n ! INTENT(IN), OPTIONAL\n !> \\param[in] \"integer(i8), optional :: seed_in\" User seed to initialise the random number generator \\n\n !> (default: none --> initialized with timeseed)\n\n !> \\param[in] \"logical, optional :: printflag_in\" Print of output on command line \\n\n !> (default: .False.)\n\n !> \\param[in] \"logical, optional :: maskpara_in(size(para))\" \n !> Parameter will be sampled (.True.) or not (.False.) \\n\n !> (default: .True.)\n\n !> \\param[in] \"character(len=*), optional :: tmp_file\" filename for temporal data saving: \\n\n !> every iter_mcmc_in iterations parameter sets are \n !> appended to this file \\n\n !> the number of the chain will be prepended to filename \\n\n !> output format: netcdf \\n\n !> (default: no file writing)\n\n !> \\param[in] \"logical, optional :: loglike_in\" true if loglikelihood function is given instead of \n !> likelihood function \\n\n !> (default: .false.)\n\n !> \\param[in] \"integer(i4), optional :: ParaSelectMode_in\" \n !> How many parameters will be changed at once?\n !> - half of the parameter --> 1_i4\n !> - only one parameter --> 2_i4\n !> - all parameter --> 3_i4\n !> (default: 2_i4)\n\n !> \\param[in] \"integer(i4), optional :: iter_burnin_in\" Length of Markov chains of initial burn-in part \\n\n !> (default: Max(250, 200*count(maskpara)) )\n\n !> \\param[in] \"integer(i4), optional :: iter_mcmc_in\" Length of Markov chains of proper MCMC part \\n\n !> (default: 1000 * count(maskpara) )\n\n !> \\param[in] \"integer(i4), optional :: chains_in\" number of parallel mcmc chains \\n\n !> (default: 5_i4)\n\n !> \\param[in] \"real(dp), DIMENSION(size(para,1)), optional :: stepsize_in\"\n !> stepsize for each parameter \\n\n !> if given burn-in is discarded \\n\n !> (default: none --> adjusted in burn-in)\n\n ! INTENT(INOUT), OPTIONAL\n ! None\n\n ! INTENT(OUT), OPTIONAL\n ! None\n\n ! RESTRICTIONS\n ! \\note Likelihood has to be defined as a function interface\n ! -> see also example in test directory\n\n ! EXAMPLE\n ! -> see also example in test directory\n\n ! LITERATURE\n ! Gelman et. al (1995)\n ! Baysian Data Analyis, Chapman & Hall.\n ! Gelman et. al (1997)\n ! Efficient Metropolis Jumping Rules, Baysian Statistics 5, pp. 599-607\n ! Tautenhahn et. al (2012)\n ! Beyond distance-invariant survival in inverse recruitment modeling:\n ! A case study in Siberian Pinus sylvestris forests, Ecological Modelling, 233,\n ! 90-103. doi:10.1016/j.ecolmodel.2012.03.009.\n\n ! HISTORY\n ! Written Goehler, Sep. 2012 : Created using copy of Simulated Annealing\n ! - constant temperature T\n ! - burn-in for stepsize adaption\n ! - acceptance/ rejection multiplier\n ! Modified Mai, Sep. 2012 : Cleaning code and introduce likelihood\n ! - likelihood instead of objective function\n ! - odds ratio\n ! - convergence criteria for burn-in\n ! - different modes of parameter selection\n ! OpenMP for chains of MCMC\n ! optional file for temporal output\n ! Mai, Nov. 2012 : Temporary file writing as NetCDF\n ! Mai, Aug. 2013 : New likelihood interface to reduce number of function evaluations\n ! Only one seed has to be given\n ! Mai, Nov. 2014 : add new routine for mcmc\n ! mcmc_stddev, i.e. mcmc with likelihood with \"faked sigma\"\n ! mcmc, i.e. mcmc with \"real\" likelihood (sigma is given by e.g. error model)\n ! Cuntz, Mai Feb. 2015 : restart\n ! Mai, Apr. 2015 : handling of array-like variables in restart-namelists\n !\n INTERFACE mcmc_stddev\n MODULE PROCEDURE mcmc_stddev_dp\n END INTERFACE mcmc_stddev\n\n !-----------------------------------------------------------------------------------------------\n\n PRIVATE\n\n !-----------------------------------------------------------------------------------------------\n\nCONTAINS\n\n !-----------------------------------------------------------------------------------------------\n\n SUBROUTINE mcmc_dp(likelihood, para, rangePar, & ! obligatory IN\n mcmc_paras, burnin_paras, & ! obligatory OUT\n seed_in, printflag_in, maskpara_in, & ! optional IN\n restart, restart_file, & ! optional IN: if mcmc is restarted and file which contains restart variables\n tmp_file, & ! optional IN: filename for temporal output of \n ! ! MCMC parasets\n loglike_in, & ! optional IN: true if loglikelihood is given\n ParaSelectMode_in, & ! optional IN: (=1) half, (=2) one, (=3) all\n iter_burnin_in, & ! optional IN: markov length of (1) burn-in\n iter_mcmc_in, & ! optional IN: markov length of (2) mcmc\n chains_in, & ! optional IN: number of parallel chains of MCMC\n stepsize_in) ! optional IN: stepsize for each param. (no burn-in)\n\n IMPLICIT NONE\n\n INTERFACE\n FUNCTION likelihood(paraset)\n ! calculates the likelihood function at a certain parameter set paraset\n use mo_kind\n REAL(DP), DIMENSION(:), INTENT(IN) :: paraset\n REAL(DP) :: likelihood\n END FUNCTION likelihood\n END INTERFACE\n\n REAL(DP), DIMENSION(:,:), INTENT(IN) :: rangePar ! range for each parameter\n REAL(DP), DIMENSION(:), INTENT(IN) :: para ! initial parameter i\n INTEGER(I8), OPTIONAL, INTENT(IN) :: seed_in ! Seeds of random numbers: dim1=chains, dim2=3\n ! ! (DEFAULT: Get_timeseed)\n LOGICAL, OPTIONAL, INTENT(IN) :: printflag_in ! If command line output is written (.true.)\n ! ! (DEFAULT: .false.)\n LOGICAL, OPTIONAL, DIMENSION(size(para,1)), &\n INTENT(IN) :: maskpara_in ! true if parameter will be optimized\n ! ! false if parameter is discarded in optimization\n ! ! (DEFAULT = .true.)\n logical, OPTIONAL, INTENT(in) :: restart ! if .true., start from restart file\n ! ! (DEFAULT: .false.)\n character(len=*), OPTIONAL, INTENT(in) :: restart_file ! restart file name\n ! ! (DEFAULT: mo_mcmc.restart)\n LOGICAL, OPTIONAL, INTENT(IN) :: loglike_in ! true if loglikelihood is given instead of likelihood\n ! ! (DEFAULT: .false.)\n INTEGER(I4), OPTIONAL, INTENT(IN) :: ParaSelectMode_in ! how many parameters changed per iteration:\n ! ! 1: half of the parameters\n ! ! 2: only one (DEFAULT)\n ! ! 3: all\n INTEGER(I4), OPTIONAL, INTENT(IN) :: iter_burnin_in ! # iterations before checking ac_ratio\n ! ! DEFAULT= MIN(250, 20_i4*n)\n INTEGER(I4), OPTIONAL, INTENT(IN) :: iter_mcmc_in ! # iterations per chain for posterior sampling\n ! ! DEFAULT= 1000_i4*n\n INTEGER(I4), OPTIONAL, INTENT(IN) :: chains_in ! number of parallel mcmc chains\n ! ! DEFAULT= 5_i4\n REAL(DP), OPTIONAL, DIMENSION(size(para,1)), &\n INTENT(IN) :: stepsize_in ! stepsize for each parameter\n ! ! if given burn-in is discarded\n CHARACTER(len=*), OPTIONAL, INTENT(IN) :: tmp_file ! filename for temporal data saving: every iter_mcmc_in \n ! ! iterations parameter sets are appended to this file\n ! ! the number of the chain will be prepended to filename\n ! ! DEFAULT= no file writing\n REAL(DP), DIMENSION(:,:), ALLOCATABLE, INTENT(OUT) :: mcmc_paras\n ! ! array to save para values of MCMC runs,\n ! ! dim1=sets of all chains, dim2=paras\n REAL(DP), DIMENSION(:,:), ALLOCATABLE, INTENT(OUT) :: burnin_paras\n ! ! array to save para values of Burn in run\n\n\n ! local variables\n INTEGER(I4) :: n ! Number of parameters\n LOGICAL :: printflag ! If command line output is written\n LOGICAL, DIMENSION(size(para,1)) :: maskpara ! true if parameter will be optimized\n LOGICAL, DIMENSION(1000) :: dummy_maskpara ! dummy mask_para (only for namelist)\n INTEGER(I4), DIMENSION(:), ALLOCATABLE :: truepara ! indexes of parameters to be optimized\n LOGICAL :: loglike ! if loglikelihood is given\n LOGICAL :: skip_burnin ! if stepsize is given --> burnin is skipped\n logical :: itmp_file ! if temporal results wanted\n#ifdef __pgiFortran__\n character(len=299) :: istmp_file ! local copy of file for temporal results output\n#else\n character(len=1024) :: istmp_file ! local copy of file for temporal results output\n#endif\n logical :: irestart ! if restart wanted\n character(len=1024) :: isrestart_file ! local copy of restart file name\n\n ! for random numbers\n INTEGER(I8), dimension(:,:), allocatable :: seeds ! Seeds of random numbers: dim1=chains, dim2=3\n REAL(DP) :: RN1, RN2, RN3 ! Random numbers\n integer(I8), dimension(:,:), allocatable :: save_state_1 ! optional argument for restarting RN stream 1: \n integer(I8), dimension(:,:), allocatable :: save_state_2 ! optional argument for restarting RN stream 2: \n integer(I8), dimension(:,:), allocatable :: save_state_3 ! optional argument for restarting RN stream 3: \n ! ! dim1=chains, dim2=n_save_state\n\n ! Dummies\n REAL(DP), DIMENSION(:,:,:), ALLOCATABLE :: tmp\n integer(I4) :: idummy\n logical :: oddsSwitch1, oddsSwitch2\n character(100) :: str\n character(200) :: outputfile\n integer(i4) :: slash_pos\n integer(i4) :: len_filename\n character(200) :: filename\n character(200) :: path \n\n ! FOR BURN-IN AND MCMC\n REAL(DP), DIMENSION(:,:,:), ALLOCATABLE :: mcmc_paras_3d ! array to save para values of MCMC runs,\n ! ! dim1=sets, dim2=paras, dim3=chain\n integer(I4) :: i\n integer(I4), dimension(:), allocatable :: Ipos, Ineg\n logical :: iStop\n INTEGER(I4) :: ParaSelectMode ! how many parameters are changed per jump\n INTEGER(I4) :: iter_burnin ! number fo iterations before checking ac_ratio\n INTEGER(I4) :: iter_mcmc ! number fo iterations for posterior sampling\n INTEGER(I4) :: chains ! number of parallel mcmc chains\n INTEGER(I4) :: chain ! counter for chains, 1...chains\n REAL(DP) :: accMult ! acceptance multiplier for stepsize\n REAL(DP) :: rejMult ! rejection multiplier for stepsize\n LOGICAL,DIMENSION(size(para,1)) :: ChangePara ! logical array to switch if parameter is changed\n INTEGER(I4) :: trial ! number of trials for burn-in\n REAL(DP),DIMENSION(size(para,1)) :: stepsize ! stepsize adjusted by burn-in and used by mcmc\n REAL(DP),DIMENSION(1000) :: dummy_stepsize ! dummy stepsize (only for namelist)\n REAL(DP),DIMENSION(size(para,1)) :: paraold ! old parameter set\n REAL(DP),DIMENSION(size(para,1)) :: paranew ! new parameter set\n REAL(DP),DIMENSION(size(para,1)) :: parabest ! best parameter set overall\n REAL(DP),DIMENSION(1000) :: dummy_parabest ! dummy parabest (only for namelist)\n REAL(DP),DIMENSION(size(para,1)) :: initial_paraset_mcmc ! best parameterset found in burn-in\n REAL(DP),DIMENSION(1000) :: dummy_initial_paraset_mcmc ! dummy initial_paraset_mcmc (only for namelist)\n REAL(DP) :: likeliold ! likelihood of old parameter set\n REAL(DP) :: likelinew ! likelihood of new parameter set\n REAL(DP) :: likelibest ! likelihood of best parameter set overall\n INTEGER(I4) :: markov ! counter for markov chain\n REAL(DP), DIMENSION(:,:), ALLOCATABLE :: burnin_paras_part ! accepted parameter sets of one MC in burn-in\n REAL(DP) :: oddsRatio ! ratio of likelihoods = likelinew/likeliold\n REAL(DP), dimension(:), allocatable :: accRatio ! acceptance ratio = (pos/neg) accepted/iter_burnin\n REAL(DP) :: accratio_stddev ! stddev of accRatios in history\n REAL(DP), DIMENSION(:), ALLOCATABLE :: history_accratio ! history of 'good' acceptance ratios\n INTEGER(I4) :: accratio_n ! number of 'good' acceptance ratios\n\n ! for checking convergence of MCMC\n real(dp), allocatable, dimension(:) :: sqrtR\n real(dp), allocatable, dimension(:) :: vDotJ\n real(dp), allocatable, dimension(:) :: s2\n real(dp) :: vDotDot\n real(dp) :: B\n real(dp) :: W\n integer(i4) :: n_start, n_end, iPar\n LOGICAL :: converged ! if MCMC already converged\n\n ! for OMP\n integer(i4) :: n_threads\n\n namelist /restartnml1/ &\n n, printflag, dummy_maskpara, loglike, skip_burnin, & \n iStop, ParaSelectMode, iter_burnin, &\n iter_mcmc, chains, accMult, rejMult, trial, dummy_stepsize, &\n dummy_parabest, likelibest, dummy_initial_paraset_mcmc, &\n accratio_stddev, &\n accratio_n, vDotDot, B, W, converged, &\n n_threads, &\n itmp_file, istmp_file\n\n namelist /restartnml2/ & \n truepara, seeds, save_state_1, save_state_2, save_state_3, &\n iPos, iNeg, mcmc_paras_3d, &\n accRatio, &\n sqrtR, vDotJ, s2\n\n ! CHECKING OPTIONALS\n\n if (present(restart)) then\n irestart = restart\n else\n irestart = .false.\n endif\n\n if (present(restart_file)) then\n isrestart_file = restart_file\n else\n isrestart_file = 'mo_mcmc.restart'\n endif\n\n if (.not. irestart) then\n\n if (present(tmp_file)) then \n itmp_file = .true.\n istmp_file = tmp_file\n else\n itmp_file = .false. \n istmp_file = ''\n end if\n\n if (present(loglike_in)) then\n loglike = loglike_in\n else\n loglike = .false.\n end if\n\n if (present(maskpara_in)) then\n if (count(maskpara_in) .eq. 0_i4) then\n stop 'Input argument maskpara: At least one element has to be true'\n else\n maskpara = maskpara_in\n end if\n else\n maskpara = .true.\n endif\n\n allocate ( truepara(count(maskpara)) )\n idummy = 0_i4\n do i=1,size(para,1)\n if ( maskpara(i) ) then\n idummy = idummy+1_i4\n truepara(idummy) = i\n end if\n end do\n\n n = size(truepara,1)\n\n if (present(ParaSelectMode_in)) then\n ParaSelectMode = ParaSelectMode_in\n else\n ! change only one parameter per jump\n ParaSelectMode = 2_i4\n end if\n\n ! after how many iterations do we compute ac_ratio???\n if (present(iter_burnin_in)) then\n if (iter_burnin_in .le. 0_i4) then\n stop 'Input argument iter_burn_in must be greater than 0!'\n else\n iter_burnin = iter_burnin_in\n end if\n else\n iter_burnin = Max(250_i4, 1000_i4*n)\n endif\n\n ! how many iterations ('jumps') are performed in MCMC\n ! iter_mcmc_in is handled later properly (after acceptance ratio of burn_in is known)\n if (present(iter_mcmc_in)) then\n if (iter_mcmc_in .le. 0_i4) then\n stop 'Input argument iter_mcmc must be greater than 0!'\n else\n iter_mcmc = iter_mcmc_in\n end if\n else\n iter_mcmc = 1000_i4 * n\n endif\n\n if (present(chains_in)) then\n if (chains_in .lt. 2_i4) then\n stop 'Input argument chains must be at least 2!'\n end if\n chains = chains_in\n else\n chains = 5_i4\n endif\n\n if (present(stepsize_in)) then\n stepsize = stepsize_in\n skip_burnin = .true.\n else\n skip_burnin = .false.\n end if\n\n if (present(printflag_in)) then\n printflag = printflag_in\n else\n printflag = .false.\n endif\n\n n_threads = 1\n !$ write(*,*) '--------------------------------------------------'\n !$ write(*,*) ' This program is parallel.'\n !$OMP parallel\n !$ n_threads = OMP_GET_NUM_THREADS()\n !$OMP end parallel\n !$ write(*,*) ' ',chains,' MCMC chains will run in ',n_threads,' threads'\n !$ write(*,*) '--------------------------------------------------'\n\n if (printflag) then\n write(*,*) 'Following parameters will be sampled with MCMC: ',truepara\n end if\n\n allocate(seeds(chains,3))\n allocate(save_state_1(chains,n_save_state))\n allocate(save_state_2(chains,n_save_state))\n allocate(save_state_3(chains,n_save_state))\n allocate(Ipos(chains), Ineg(chains), accRatio(chains))\n allocate(vDotJ(chains), s2(chains))\n allocate(sqrtR(size(para)))\n\n Ipos = -9999\n Ineg = -9999\n accRatio = -9999.0_dp\n vDotJ = -9999.0_dp\n s2 = -9999.0_dp\n sqrtR = -9999.0_dp\n\n if (present(seed_in)) then\n seeds(1,:) = (/ seed_in, seed_in + 1000_i8, seed_in + 2000_i8 /)\n else\n ! Seeds depend on actual time\n call get_timeseed(seeds(1,:))\n endif\n do chain=2,chains\n seeds(chain,:) = seeds(chain-1_i4,:) + 3000_i8\n end do\n\n do chain=1,chains\n call xor4096(seeds(chain,1), RN1, save_state=save_state_1(chain,:))\n call xor4096(seeds(chain,2), RN2, save_state=save_state_2(chain,:))\n call xor4096g(seeds(chain,3), RN3, save_state=save_state_3(chain,:))\n end do\n seeds = 0_i8\n\n parabest = para\n\n ! initialize likelihood\n likelibest = likelihood(parabest)\n\n !----------------------------------------------------------------------\n ! (1) BURN IN\n !----------------------------------------------------------------------\n\n if (.not. skip_burnin) then\n\n if (printflag) then\n write(*,*) ''\n write(*,*) '--------------------------------------------------'\n write(*,*) 'Starting Burn-In (iter_burnin = ',iter_burnin,')'\n write(*,*) '--------------------------------------------------'\n write(*,*) ''\n end if\n\n ! INITIALIZATION\n\n ! probably too large, but large enough to store values of one markovchain\n allocate(burnin_paras_part(iter_burnin,size(para)))\n\n if (allocated(burnin_paras)) deallocate(burnin_paras)\n if (allocated(history_accRatio)) deallocate(history_accRatio)\n\n ! parabestChanged = .false.\n stepsize = 1.0_dp\n trial = 1_i4\n iStop = .false.\n accMult = 1.01_dp\n rejMult = 0.99_dp\n\n if (printflag) then\n write(*,*) ' '\n write(*,*) 'Start Burn-In with: '\n write(*,*) ' parabest = ', parabest\n write(*,*) ' likelihood = ', likelibest\n write(*,*) ' '\n end if\n\n ! ----------------------------------------------------------------------------------\n ! repeats until convergence of acceptance ratio or better parameter set was found\n ! ----------------------------------------------------------------------------------\n convergedBURNIN: do while ( .not. iStop )\n\n Ipos = 0_i4 ! positive accepted\n Ineg = 0_i4 ! negative accepted\n paraold = parabest\n likeliold = likelibest\n\n ! -------------------------------------------------------------------------------\n ! do a short-cut MCMC\n ! -------------------------------------------------------------------------------\n markovchain: do markov=1, iter_burnin\n\n ! (A) Generate new parameter set\n ChangePara = .false.\n paranew = paraold\n ! using RN from chain #1\n call GenerateNewParameterset_dp(ParaSelectMode, paraold, truepara, rangePar, stepsize, &\n save_state_2(1,:),&\n save_state_3(1,:),&\n paranew,ChangePara)\n\n ! (B) new likelihood\n likelinew = likelihood(paranew)\n\n oddsSwitch1 = .false.\n if (loglike) then\n oddsRatio = likelinew-likeliold\n if (oddsRatio .gt. 0.0_dp) oddsSwitch1 = .true.\n else\n oddsRatio = likelinew/likeliold\n if (oddsRatio .gt. 1.0_dp) oddsSwitch1 = .true.\n end if\n\n ! (C) Accept or Reject?\n If (oddsSwitch1) then\n\n ! positive accept\n Ipos(1) = Ipos(1) + 1_i4\n paraold = paranew\n likeliold = likelinew\n where (changePara)\n stepsize = stepsize * accMult\n end where\n if (likelinew .gt. likelibest) then\n parabest = paranew\n likeliold = likelinew \n likelibest = likelinew \n !\n write(*,*) ''\n write(*,*) 'best para changed: ',paranew\n write(*,*) 'likelihood new: ',likelinew\n write(*,*) ''\n end if\n burnin_paras_part(Ipos(1)+Ineg(1),:) = paranew(:)\n\n else\n\n call xor4096(seeds(1,1), RN1, save_state=save_state_1(1,:))\n oddsSwitch2 = .false.\n if (loglike) then\n if (oddsRatio .lt. -700.0_dp) oddsRatio = -700.0_dp ! to avoid underflow\n if (rn1 .lt. exp(oddsRatio)) oddsSwitch2 = .true.\n else\n if (rn1 .lt. oddsRatio) oddsSwitch2 = .true.\n end if\n\n If ( oddsSwitch2 ) then\n\n ! negative accept\n Ineg(1) = Ineg(1) + 1_i4\n paraold = paranew\n likeliold = likelinew\n where (changePara)\n stepsize = stepsize * accMult\n end where\n burnin_paras_part(Ipos(1)+Ineg(1),:) = paranew(:) \n\n else\n\n ! reject\n where (changePara)\n stepsize = stepsize * rejMult\n end where\n\n end if\n\n end if\n\n end do markovchain\n\n accRatio(1) = real(Ipos(1) + Ineg(1),dp) / real(iter_burnin,dp)\n if (printflag) then\n write(str,'(A,I03,A)') '(A7,I4,A15,F5.3,A17,',size(para,1),'(E9.2,1X),A1)'\n write(*,str) 'trial #',trial,' acc_ratio = ',accRatio(1),' (stepsize = ',stepsize,')'\n end if\n\n if (Ipos(1)+Ineg(1) .gt. 0_i4) then\n call append(burnin_paras, burnin_paras_part(1:Ipos(1)+Ineg(1),:))\n end if\n\n ! adjust acceptance multiplier\n if (accRatio(1) .lt. 0.234_dp) accMult = accMult * 0.99_dp\n if (accRatio(1) .gt. 0.441_dp) accMult = accMult * 1.01_dp\n\n ! store good accRatios in history and delete complete history if bad one appears\n if (accRatio(1) .lt. 0.234_dp .or. accRatio(1) .gt. 0.441_dp) then\n if( allocated(history_accRatio) ) deallocate(history_accRatio)\n else\n call append(history_accRatio, accRatio(1))\n end if\n\n ! if in history more than 10 values, check for mean and variance\n if ( allocated(history_accRatio) ) then\n accRatio_n = size(history_accRatio,1)\n if ( accRatio_n .ge. 10_i4 ) then\n idummy = accRatio_n-9_i4\n accRatio_stddev = stddev( history_accRatio(idummy:accRatio_n), ddof=1_i4 )\n\n ! Check of Convergence\n if ( (accRatio_stddev .lt. Sqrt( 1._dp/12._dp * 0.05_dp**2 )) ) then\n iStop = .true.\n if (printflag) then\n write(*,*) ''\n write(*,*) 'STOP BURN-IN with accaptence ratio of ', history_accRatio(accRatio_n)\n write(*,*) 'final stepsize: ',stepsize\n write(*,*) 'best parameter set found: ',parabest\n write(*,*) 'with likelihood: ',likelibest\n end if\n end if\n\n end if\n end if\n\n trial = trial + 1_i4\n\n end do convergedBURNIN\n\n ! end do betterParaFound\n\n end if ! no burn-in skip\n !\n ! ------------------------------------\n ! start initializing things for MCMC, i.e. initialization and allocation\n ! necessary for MCMC restart file\n ! ------------------------------------\n\n ! allocate arrays which will be used later\n allocate(mcmc_paras_3d(iter_mcmc,size(para),chains))\n mcmc_paras_3d = -9999.0_dp\n\n vDotDot = -9999.0_dp\n B = -9999.0_dp\n W = -9999.0_dp\n\n ! just to be sure that all chains start with same initial parameter set\n ! in both parallel and sequential mode\n ! (although in between a new parabest will be found in chains)\n initial_paraset_mcmc = parabest\n\n Ipos(:) = 0_i4 ! positive accepted\n Ineg(:) = 0_i4 ! negative accepted\n\n ! if all parameters converged: Sqrt(R_i) < 1.1 (see Gelman et. al: Baysian Data Analysis, p. 331ff)\n converged = .False.\n\n ! transfer all array-like variables in namelist to fixed-size dummy-arrays\n dummy_maskpara = .false.\n dummy_maskpara(1:size(para,1)) = maskpara\n dummy_stepsize = -9999.0_dp\n dummy_stepsize(1:size(para,1)) = stepsize\n dummy_parabest = -9999.0_dp\n dummy_parabest(1:size(para,1)) = parabest\n dummy_initial_paraset_mcmc = -9999.0_dp\n dummy_initial_paraset_mcmc(1:size(para,1)) = initial_paraset_mcmc\n\n ! write restart\n open(999, file=isrestart_file, status='unknown', action='write', delim='QUOTE')\n write(999, restartnml1)\n write(999, restartnml2)\n close(999)\n\n else ! --> here starts the restart case\n\n ! read 1st namelist with allocated/scalar variables\n open(999, file=isrestart_file, status='old', action='read', delim='QUOTE')\n read(999, nml=restartnml1)\n close(999)\n\n ! transfer all array-like variables in namelist to fixed-size dummy-arrays\n maskpara = dummy_maskpara(1:size(para,1))\n stepsize = dummy_stepsize(1:size(para,1))\n parabest = dummy_parabest(1:size(para,1))\n initial_paraset_mcmc = dummy_initial_paraset_mcmc(1:size(para,1))\n \n ! allocate global arrays\n allocate(truepara(count(maskpara)) )\n allocate(seeds(chains,3))\n allocate(save_state_1(chains,n_save_state))\n allocate(save_state_2(chains,n_save_state))\n allocate(save_state_3(chains,n_save_state))\n allocate(Ipos(chains), Ineg(chains), accRatio(chains))\n allocate(vDotJ(chains), s2(chains))\n allocate(sqrtR(size(para)))\n if (.not. converged) then\n if (present(iter_mcmc_in)) then\n allocate(mcmc_paras_3d(iter_mcmc-iter_mcmc_in,size(para),chains))\n else\n allocate(mcmc_paras_3d(iter_mcmc-1000_i4*n,size(para),chains))\n end if\n else\n allocate(mcmc_paras_3d(iter_mcmc,size(para),chains))\n end if\n\n endif\n\n !----------------------------------------------------------------------\n ! (2) MCMC\n !----------------------------------------------------------------------\n\n if (printflag) then\n write(*,*) ''\n write(*,*) '--------------------------------------------------'\n write(*,*) 'Starting MCMC (chains = ',chains,', iter_mcmc = ',iter_mcmc,')'\n write(*,*) '--------------------------------------------------'\n write(*,*) ''\n end if\n\n convergedMCMC: do while (.not. converged)\n ! read restart\n open(999, file=isrestart_file, status='unknown', action='read', delim='QUOTE')\n read(999, restartnml1)\n read(999, restartnml2)\n close(999)\n\n ! transfer all array-like variables in namelist to fixed-size dummy-arrays\n maskpara = dummy_maskpara(1:size(para,1))\n stepsize = dummy_stepsize(1:size(para,1))\n parabest = dummy_parabest(1:size(para,1))\n initial_paraset_mcmc = dummy_initial_paraset_mcmc(1:size(para,1))\n\n ! resize mcmc_paras_3d\n ! iter_mcmc was increased --> indicates new length of mcmc_paras_3d\n ! Minval(Ipos+Ineg) --> indicates old length of mcmc_paras_3d\n idummy = minval(Ipos+Ineg)\n if ((iter_mcmc-idummy) > 0) then\n allocate(tmp(idummy,size(para),chains))\n tmp(:,:,:) = mcmc_paras_3d(1:idummy,:,:)\n deallocate(mcmc_paras_3d)\n allocate(mcmc_paras_3d(iter_mcmc,size(para),chains))\n mcmc_paras_3d(1:idummy,:,:) = tmp(:,:,:)\n deallocate(tmp)\n endif\n\n !$OMP parallel default(shared) &\n !$OMP private(chain, paraold, paranew, likeliold, likelinew, oddsSwitch1, oddsSwitch2, RN1, oddsRatio, ChangePara)\n !$OMP do\n parallelchain: do chain=1, chains\n\n if (Ipos(chain)+Ineg(chain) .eq. 0_i4) then\n paraold = initial_paraset_mcmc ! = parabest of burn-in\n else\n paraold = mcmc_paras_3d(Ipos(chain)+Ineg(chain),:,chain)\n end if\n likeliold = likelihood(paraold)\n\n markovchainMCMC: do\n\n ! (A) Generate new parameter set\n ChangePara = .false.\n paranew = paraold\n\n call GenerateNewParameterset_dp(ParaSelectMode, paraold, truepara, rangePar, stepsize, &\n save_state_2(chain,:),&\n save_state_3(chain,:),&\n paranew,ChangePara)\n\n ! (B) new likelihood\n likelinew = likelihood(paranew)\n oddsSwitch1 = .false.\n if (loglike) then\n oddsRatio = likelinew-likeliold\n if (oddsRatio .gt. 0.0_dp) oddsSwitch1 = .true.\n else\n oddsRatio = likelinew/likeliold\n if (oddsRatio .gt. 1.0_dp) oddsSwitch1 = .true.\n end if\n\n ! (C) Accept or Reject?\n If (oddsSwitch1) then\n\n ! positive accept\n Ipos(chain) = Ipos(chain) + 1_i4\n paraold = paranew\n likeliold = likelinew\n mcmc_paras_3d(Ipos(chain)+Ineg(chain),:,chain) = paranew(:)\n\n if ( printflag ) then\n if ( (Ipos(chain)+Ineg(chain) .gt. 0_i4 ) .and. &\n (mod(Ipos(chain)+Ineg(chain),10000_i4)) .eq. 0 ) then\n write(*,*) 'Chain ',chain,': Done ',Ipos(chain)+Ineg(chain),' samples ...'\n end if\n end if\n\n ! If the following code block is not commented\n ! then mcmc can be used as an optimiser as well\n ! and not 'only' for determination of parameter uncertainties.\n ! However, then the serial and the parallel versions give different results.\n ! if (likelinew .gt. likelibest) then\n ! parabest = paranew\n ! likelibest = likelinew\n ! if (printflag) then\n ! write(*,*) ''\n ! write(*,*) 'best para changed: ',paranew\n ! write(*,*) 'likelihood new: ',likelinew\n ! write(*,*) ''\n ! end if\n ! end if\n\n else\n\n call xor4096(seeds(chain,1), RN1, save_state=save_state_1(chain,:))\n oddsSwitch2 = .false.\n if (loglike) then\n if (rn1 .lt. exp(oddsRatio)) oddsSwitch2 = .true.\n else\n if (rn1 .lt. oddsRatio) oddsSwitch2 = .true.\n end if\n\n If ( oddsSwitch2 ) then\n\n ! negative accept\n Ineg(chain) = Ineg(chain) + 1_i4\n paraold = paranew\n likeliold = likelinew\n mcmc_paras_3d(Ipos(chain)+Ineg(chain),:,chain) = paranew(:)\n\n if ( printflag ) then\n if ( (Ipos(chain)+Ineg(chain) .gt. 0_i4 ) .and. &\n (mod(Ipos(chain)+Ineg(chain),10000_i4)) .eq. 0 ) then\n write(*,*) 'Chain ',chain,': Done ',Ipos(chain)+Ineg(chain),' samples ...'\n end if\n end if\n\n end if\n\n end if\n\n ! enough samples were found\n if ( (Ipos(chain)+Ineg(chain) .gt. 0_i4 ) .and. &\n (mod(Ipos(chain)+Ineg(chain),iter_mcmc) .eq. 0_i4 ) ) exit\n\n end do markovchainMCMC\n\n end do parallelchain\n !$OMP end do\n !$OMP end parallel\n\n ! write parameter sets to temporal file\n if (itmp_file) then\n ! splitting into path and filename\n slash_pos = index(istmp_file, '/', .true.)\n len_filename = len_trim(istmp_file)\n path = istmp_file(1:slash_pos)\n filename = istmp_file(slash_pos+1:len_filename)\n !\n do chain=1,chains\n write(str,*) chain\n write(outputfile,*) trim(adjustl(path)), trim(adjustl(str)), '_' , trim(adjustl(filename))\n if (present(iter_mcmc_in)) then\n allocate(tmp(iter_mcmc_in,size(para,1),1))\n tmp(:,:,1) = mcmc_paras_3d(iter_mcmc-iter_mcmc_in+1_i4:iter_mcmc,:,chain)\n if (iter_mcmc .ne. iter_mcmc_in) then\n ! append\n call dump_netcdf(trim(adjustl(outputfile)), tmp, append=.true.)\n else\n ! first time of writing\n call dump_netcdf(trim(adjustl(outputfile)), tmp)\n end if\n deallocate(tmp)\n else\n allocate(tmp(1000_i4*n,size(para,1),1))\n tmp(:,:,1) = mcmc_paras_3d(iter_mcmc-(1000_i4*n)+1_i4:iter_mcmc,:,chain)\n if (iter_mcmc .ne. 1000_i4*n) then\n ! append\n call dump_netcdf(trim(adjustl(outputfile)), tmp, append=.true.)\n else\n ! first time of writing\n call dump_netcdf(trim(adjustl(outputfile)), tmp)\n end if\n deallocate(tmp)\n end if\n end do\n end if\n\n ! test for convergence: Gelman et. al: Baysian Data Analysis, p. 331ff\n ! sqrt(R) = sqrt( ( (n-1)/n * W + 1/n * B ) / W ) < 1.1 for each parameter\n ! n ... last half of the sequence\n ! W ... within sequence variance\n ! B ... between chain variance\n\n if ( printflag ) then\n write(*,*) ' '\n write(*,*) 'Checking for convergence ....'\n end if\n sqrtR = 0.0_dp\n n_end = minval(Ipos+Ineg)\n n_start = n_end / 2_i4 + 1_i4\n\n do iPar=1, size(truepara)\n\n ! Between chain variances\n do chain=1, chains\n vDotJ(chain) = 1.0_dp / real(n_end-n_start+1_i4,dp) * &\n sum(mcmc_paras_3d(n_start:n_end,truepara(iPar),chain))\n end do\n vDotDot = 1.0_dp / real(chains,dp) * sum(vDotJ)\n B = real(n_end -n_start + 1_i4,dp) / real(chains-1_i4,dp) * &\n sum((vDotJ - vDotDot)*(vDotJ - vDotDot))\n\n ! Within chain variances\n do chain=1, chains\n s2(chain) = 1.0_dp / real(n_end-n_start,dp) * &\n sum((mcmc_paras_3d(n_start:n_end,truepara(iPar),chain)-vDotJ(chain))**2)\n end do\n W = 1.0_dp / real(chains,dp) * Sum(s2)\n\n ! ratio sqrtR\n if ( (w .lt. tiny(1.0_dp)) .and. (b .lt. tiny(1.0_dp))) then\n ! Mathematica says that this is the limit, if w and b both go to zero\n sqrtR(truepara(iPar)) = sqrt(real(n_end-n_start,dp) / real(n_end-n_start+1_i4,dp))\n else\n sqrtR(truepara(iPar)) = real(n_end-n_start,dp) / real(n_end-n_start+1_i4,dp) * W + &\n 1.0_dp / real(n_end-n_start+1_i4,dp) * B\n sqrtR(truepara(iPar)) = sqrt( sqrtR(truepara(iPar)) / W )\n end if\n end do\n if (printflag) then\n do i=1, size(para)\n if ( sqrtR(i) .gt. 1.1_dp ) then\n write(*,*) ' sqrtR para #',i,' : ', sqrtR(i),' <-- FAILED'\n else\n write(*,*) ' sqrtR para #',i,' : ', sqrtR(i)\n end if\n end do\n end if\n if ( all(sqrtR .lt. 1.1_dp) ) then\n converged = .true.\n if ( printflag ) then\n write(*,*) ' --> converged (all less than 1.1)'\n write(*,*) ' '\n end if\n else\n ! increase number of iterations\n if (present(iter_mcmc_in)) then\n iter_mcmc = iter_mcmc + iter_mcmc_in\n else\n iter_mcmc = iter_mcmc + 1000_i4 * n\n endif\n\n if ( printflag ) then\n write(*,*) ' --> not converged (not all less than 1.1)'\n write(*,*) ' increasing iterations to ',iter_mcmc\n write(*,*) ' '\n end if\n end if\n\n ! transfer all array-like variables in namelist to fixed-size dummy-arrays\n dummy_maskpara = .false.\n dummy_maskpara(1:size(para,1)) = maskpara\n dummy_stepsize = -9999.0_dp\n dummy_stepsize(1:size(para,1)) = stepsize\n dummy_parabest = -9999.0_dp\n dummy_parabest(1:size(para,1)) = parabest\n dummy_initial_paraset_mcmc = -9999.0_dp\n dummy_initial_paraset_mcmc(1:size(para,1)) = initial_paraset_mcmc\n \n ! write restart\n open(999, file=isrestart_file, status='unknown', action='write', delim='QUOTE')\n write(999, restartnml1)\n write(999, restartnml2)\n close(999)\n\n end do convergedMCMC\n \n ! read restart\n open(999, file=isrestart_file, status='unknown', action='read', delim='QUOTE')\n read(999, restartnml1)\n read(999, restartnml2)\n close(999)\n\n ! transfer all array-like variables in namelist to fixed-size dummy-arrays\n maskpara = dummy_maskpara(1:size(para,1))\n stepsize = dummy_stepsize(1:size(para,1))\n parabest = dummy_parabest(1:size(para,1))\n initial_paraset_mcmc = dummy_initial_paraset_mcmc(1:size(para,1))\n\n ! reshape of mcmc_paras_3d: return only 2d matrix mcmc_paras\n allocate(mcmc_paras(size(mcmc_paras_3d,1)*size(mcmc_paras_3d,3),size(mcmc_paras_3d,2)))\n do chain=1, chains\n mcmc_paras( (chain-1_i4)*size(mcmc_paras_3d,1)+1_i4 : chain*size(mcmc_paras_3d,1),:) = mcmc_paras_3d(:,:,chain)\n end do\n\n RETURN\n END SUBROUTINE mcmc_dp\n\n SUBROUTINE mcmc_stddev_dp(likelihood, para, rangePar, & ! obligatory IN\n mcmc_paras, burnin_paras, & ! obligatory OUT\n seed_in, printflag_in, maskpara_in, & ! optional IN\n tmp_file, & ! optional IN : filename for temporal output of \n ! ! MCMC parasets\n loglike_in, & ! optional IN : true if loglikelihood is given\n ParaSelectMode_in, & ! optional IN : (=1) half, (=2) one, (=3) all\n iter_burnin_in, & ! optional IN : markov length of (1) burn-in\n iter_mcmc_in, & ! optional IN : markov length of (2) mcmc\n chains_in, & ! optional IN : number of parallel chains of MCMC\n stepsize_in) ! optional_IN : stepsize for each param. (no burn-in)\n\n IMPLICIT NONE\n\n INTERFACE\n FUNCTION likelihood(paraset,sigma,stddev_new,likeli_new)\n ! calculates the likelihood function at a certain parameter set paraset\n use mo_kind\n REAL(DP), DIMENSION(:), INTENT(IN) :: paraset\n REAL(DP), INTENT(IN) :: sigma\n REAL(DP), INTENT(OUT), OPTIONAL :: stddev_new ! standard deviation of errors using paraset\n REAL(DP), INTENT(OUT), OPTIONAL :: likeli_new ! likelihood using stddev_new, \n ! ! i.e. using new parameter set\n REAL(DP) :: likelihood\n END FUNCTION likelihood\n END INTERFACE\n\n REAL(DP), DIMENSION(:,:), INTENT(IN) :: rangePar ! range for each parameter\n REAL(DP), DIMENSION(:), INTENT(IN) :: para ! initial parameter i\n INTEGER(I8), OPTIONAL, INTENT(IN) :: seed_in ! Seeds of random numbers: dim1=chains, dim2=3\n ! ! (DEFAULT: Get_timeseed)\n LOGICAL, OPTIONAL, INTENT(IN) :: printflag_in ! If command line output is written (.true.)\n ! ! (DEFAULT: .false.)\n LOGICAL, OPTIONAL, DIMENSION(size(para,1)), &\n INTENT(IN) :: maskpara_in ! true if parameter will be optimized\n ! ! false if parameter is discarded in optimization\n ! ! DEFAULT = .true.\n LOGICAL, OPTIONAL, INTENT(IN) :: loglike_in ! true if loglikelihood is given instead of likelihood\n ! ! DEFAULT: .false.\n INTEGER(I4), OPTIONAL, INTENT(IN) :: ParaSelectMode_in ! how many parameters changed per iteration:\n ! ! 1: half of the parameters\n ! ! 2: only one (DEFAULT)\n ! ! 3: all\n INTEGER(I4), OPTIONAL, INTENT(IN) :: iter_burnin_in ! # iterations before checking ac_ratio\n ! ! DEFAULT= MIN(250, 20_i4*n)\n INTEGER(I4), OPTIONAL, INTENT(IN) :: iter_mcmc_in ! # iterations per chain for posterior sampling\n ! ! DEFAULT= 1000_i4*n\n INTEGER(I4), OPTIONAL, INTENT(IN) :: chains_in ! number of parallel mcmc chains\n ! ! DEFAULT= 5_i4\n REAL(DP), OPTIONAL, DIMENSION(size(para,1)), &\n INTENT(IN) :: stepsize_in ! stepsize for each parameter\n ! ! if given burn-in is discarded\n CHARACTER(len=*), OPTIONAL, INTENT(IN) :: tmp_file ! filename for temporal data saving: every iter_mcmc_in \n ! ! iterations parameter sets are appended to this file\n ! ! the number of the chain will be prepended to filename\n ! ! DEFAULT= no file writing\n REAL(DP), DIMENSION(:,:), ALLOCATABLE, INTENT(OUT) :: mcmc_paras\n ! ! array to save para values of MCMC runs,\n ! ! dim1=sets of all chains, dim2=paras\n REAL(DP), DIMENSION(:,:), ALLOCATABLE, INTENT(OUT) :: burnin_paras\n ! ! array to save para values of Burn in run\n\n\n ! local variables\n INTEGER(I4) :: n ! Number of parameters\n LOGICAL :: printflag ! If command line output is written\n LOGICAL, DIMENSION(size(para,1)) :: maskpara ! true if parameter will be optimized\n INTEGER(I4), DIMENSION(:), ALLOCATABLE :: truepara ! indexes of parameters to be optimized\n LOGICAL :: loglike ! if loglikelihood is given\n\n ! for random numbers\n INTEGER(I8), dimension(:,:), allocatable :: seeds ! Seeds of random numbers: dim1=chains, dim2=3\n REAL(DP) :: RN1, RN2, RN3 ! Random numbers\n integer(I8), dimension(:,:), allocatable :: save_state_1 ! optional argument for restarting RN stream 1: \n integer(I8), dimension(:,:), allocatable :: save_state_2 ! optional argument for restarting RN stream 2: \n integer(I8), dimension(:,:), allocatable :: save_state_3 ! optional argument for restarting RN stream 3: \n ! ! dim1=chains, dim2=n_save_state\n\n ! Dummies\n REAL(DP), DIMENSION(:,:,:), ALLOCATABLE :: tmp\n integer(I4) :: idummy\n logical :: oddsSwitch1, oddsSwitch2\n character(100) :: str\n character(200) :: outputfile\n integer(i4) :: slash_pos\n integer(i4) :: len_filename\n character(200) :: filename\n character(200) :: path \n\n ! FOR BURN-IN AND MCMC\n REAL(DP), DIMENSION(:,:,:), ALLOCATABLE :: mcmc_paras_3d ! array to save para values of MCMC runs,\n ! ! dim1=sets, dim2=paras, dim3=chain\n integer(I4) :: i\n integer(I4), dimension(:), allocatable :: Ipos, Ineg\n logical :: iStop\n INTEGER(I4) :: ParaSelectMode ! how many parameters are changed per jump\n INTEGER(I4) :: iter_burnin ! number fo iterations before checking ac_ratio\n INTEGER(I4) :: iter_mcmc ! number fo iterations for posterior sampling\n INTEGER(I4) :: chains ! number of parallel mcmc chains\n INTEGER(I4) :: chain ! counter for chains, 1...chains\n REAL(DP) :: accMult ! acceptance multiplier for stepsize\n REAL(DP) :: rejMult ! rejection multiplier for stepsize\n LOGICAL,DIMENSION(size(para,1)) :: ChangePara ! logical array to switch if parameter is changed\n INTEGER(I4) :: trial ! number of trials for burn-in\n REAL(DP),DIMENSION(size(para,1)) :: stepsize ! stepsize adjusted by burn-in and used by mcmc\n REAL(DP),DIMENSION(size(para,1)) :: paraold ! old parameter set\n REAL(DP),DIMENSION(size(para,1)) :: paranew ! new parameter set\n REAL(DP),DIMENSION(size(para,1)) :: parabest ! best parameter set overall\n REAL(DP),DIMENSION(size(para,1)) :: initial_paraset_mcmc ! best parameterset found in burn-in\n REAL(DP) :: stddev_data ! approximated stddev of data for best paraset found\n LOGICAL :: parabestChanged ! if better parameter set was found during burn-in\n REAL(DP) :: likeliold ! likelihood of old parameter set\n REAL(DP) :: likelinew ! likelihood of new parameter set\n REAL(DP) :: likelibest ! likelihood of best parameter set overall\n REAL(DP) :: stddev_new ! standard deviation of errors with current parameter set\n REAL(DP) :: likeli_new ! likelihood using stddev_new instead of stddev_data\n INTEGER(I4) :: markov ! counter for markov chain\n REAL(DP), DIMENSION(:,:), ALLOCATABLE :: burnin_paras_part ! accepted parameter sets of one MC in burn-in\n REAL(DP) :: oddsRatio ! ratio of likelihoods = likelinew/likeliold\n REAL(DP), dimension(:), allocatable :: accRatio ! acceptance ratio = (pos/neg) accepted/iter_burnin\n REAL(DP) :: accratio_stddev ! stddev of accRatios in history\n REAL(DP), DIMENSION(:), ALLOCATABLE :: history_accratio ! history of 'good' acceptance ratios\n INTEGER(I4) :: accratio_n ! number of 'good' acceptance ratios\n !REAL(DP), DIMENSION(:,:), ALLOCATABLE :: history_stepsize ! history of 'good' stepsizes\n\n ! for checking convergence of MCMC\n real(dp), allocatable, dimension(:) :: sqrtR\n real(dp), allocatable, dimension(:) :: vDotJ\n real(dp), allocatable, dimension(:) :: s2\n real(dp) :: vDotDot\n real(dp) :: B\n real(dp) :: W\n integer(i4) :: n_start, n_end, iPar\n LOGICAL :: converged ! if MCMC already converged\n\n ! for OMP\n !$ integer(i4) :: n_threads\n\n ! CHECKING OPTIONALS\n\n if (present(loglike_in)) then\n loglike = loglike_in\n else\n loglike = .false.\n end if\n\n if (present(maskpara_in)) then\n if (count(maskpara_in) .eq. 0_i4) then\n stop 'Input argument maskpara: At least one element has to be true'\n else\n maskpara = maskpara_in\n end if\n else\n maskpara = .true.\n endif\n\n allocate ( truepara(count(maskpara)) )\n idummy = 0_i4\n do i=1,size(para,1)\n if ( maskpara(i) ) then\n idummy = idummy+1_i4\n truepara(idummy) = i\n end if\n end do\n\n n = size(truepara,1)\n\n if (present(ParaSelectMode_in)) then\n ParaSelectMode = ParaSelectMode_in\n else\n ! change only one parameter per jump\n ParaSelectMode = 2_i4\n end if\n\n ! after how many iterations do we compute ac_ratio???\n if (present(iter_burnin_in)) then\n if (iter_burnin_in .le. 0_i4) then\n stop 'Input argument iter_burn_in must be greater than 0!'\n else\n iter_burnin = iter_burnin_in\n end if\n else\n iter_burnin = Max(250_i4, 1000_i4*n)\n endif\n\n ! how many iterations ('jumps') are performed in MCMC\n ! iter_mcmc_in is handled later properly (after acceptance ratio of burn_in is known)\n if (present(iter_mcmc_in)) then\n if (iter_mcmc_in .le. 0_i4) then\n stop 'Input argument iter_mcmc must be greater than 0!'\n else\n iter_mcmc = iter_mcmc_in\n end if\n else\n iter_mcmc = 1000_i4 * n\n endif\n\n if (present(chains_in)) then\n if (chains_in .lt. 2_i4) then\n stop 'Input argument chains must be at least 2!'\n end if\n chains = chains_in\n else\n chains = 5_i4\n endif\n\n if (present(stepsize_in)) then\n stepsize = stepsize_in\n end if\n\n if (present(printflag_in)) then\n printflag = printflag_in\n else\n printflag = .false.\n endif\n\n !$ write(*,*) '--------------------------------------------------'\n !$ write(*,*) ' This program is parallel.'\n !$OMP parallel\n !$ n_threads = OMP_GET_NUM_THREADS()\n !$OMP end parallel\n !$ write(*,*) ' ',chains,' MCMC chains will run in ',n_threads,' threads'\n !$ write(*,*) '--------------------------------------------------'\n\n if (printflag) then\n write(*,*) 'Following parameters will be sampled with MCMC: ',truepara\n end if\n\n allocate(seeds(chains,3))\n allocate(save_state_1(chains,n_save_state))\n allocate(save_state_2(chains,n_save_state))\n allocate(save_state_3(chains,n_save_state))\n allocate(Ipos(chains), Ineg(chains), accRatio(chains))\n allocate(vDotJ(chains), s2(chains))\n allocate(sqrtR(size(para)))\n\n if (present(seed_in)) then\n seeds(1,:) = (/ seed_in, seed_in + 1000_i8, seed_in + 2000_i8 /)\n else\n ! Seeds depend on actual time\n call get_timeseed(seeds(1,:))\n endif\n do chain=2,chains\n seeds(chain,:) = seeds(chain-1_i4,:) + 3000_i8\n end do\n\n do chain=1,chains\n call xor4096(seeds(chain,1), RN1, save_state=save_state_1(chain,:))\n call xor4096(seeds(chain,2), RN2, save_state=save_state_2(chain,:))\n call xor4096g(seeds(chain,3), RN3, save_state=save_state_3(chain,:))\n end do\n seeds = 0_i8\n\n parabest = para\n ! write(*,*) parabest\n\n ! initialize likelihood and sigma\n likelibest = likelihood(parabest,1.0_dp,stddev_new=stddev_new,likeli_new=likeli_new)\n likelibest = likeli_new\n stddev_data = stddev_new\n\n !----------------------------------------------------------------------\n ! (1) BURN IN\n !----------------------------------------------------------------------\n\n if (.not. present(stepsize_in)) then\n if (printflag) then\n write(*,*) ''\n write(*,*) '--------------------------------------------------'\n write(*,*) 'Starting Burn-In (iter_burnin = ',iter_burnin,')'\n write(*,*) '--------------------------------------------------'\n write(*,*) ''\n end if\n\n ! INITIALIZATION\n\n ! probably too large, but large enough to store values of one markovchain\n allocate(burnin_paras_part(iter_burnin,size(para)))\n\n parabestChanged = .true.\n\n ! -------------------------------------------------------------------------------------\n ! restarts if a better parameter set was found in between\n ! -------------------------------------------------------------------------------------\n betterParaFound: do while (parabestChanged)\n\n if (allocated(burnin_paras)) deallocate(burnin_paras)\n if (allocated(history_accRatio)) deallocate(history_accRatio)\n\n parabestChanged = .false.\n stepsize = 1.0_dp\n trial = 1_i4\n iStop = .false.\n accMult = 1.01_dp\n rejMult = 0.99_dp\n !stddev_data = stddev_function(parabest)\n !likelibest = likelihood(parabest,stddev_data,stddev_new=stddev_new,likeli_new=likeli_new)\n !likelibest = likeli_new\n !stddev_data = stddev_new\n\n if (printflag) then\n write(*,*) ' '\n write(*,*) 'Restart Burn-In with new approximation of std.dev. of data: '\n write(*,*) ' parabest = ', parabest\n write(*,*) ' stddev = ', stddev_data\n write(*,*) ' likelihood = ', likelibest\n write(*,*) ' ssq = ', -2.0_dp * stddev_data**2 * likelibest\n write(*,*) ' '\n end if\n\n\n ! ----------------------------------------------------------------------------------\n ! repeats until convergence of acceptance ratio or better parameter set was found\n ! ----------------------------------------------------------------------------------\n convergedBURNIN: do while ( (.not. iStop) .and. (.not. parabestChanged) )\n\n Ipos = 0_i4 ! positive accepted\n Ineg = 0_i4 ! negative accepted\n paraold = parabest\n likeliold = likelibest !likelihood(paraold,stddev_data)\n\n ! -------------------------------------------------------------------------------\n ! do a short-cut MCMC\n ! -------------------------------------------------------------------------------\n markovchain: do markov=1, iter_burnin\n\n ! (A) Generate new parameter set\n ChangePara = .false.\n paranew = paraold\n ! using RN from chain #1\n call GenerateNewParameterset_dp(ParaSelectMode, paraold, truepara, rangePar, stepsize, &\n save_state_2(1,:),&\n save_state_3(1,:),&\n paranew,ChangePara)\n\n ! (B) new likelihood\n likelinew = likelihood(paranew,stddev_data,stddev_new=stddev_new,likeli_new=likeli_new)\n\n oddsSwitch1 = .false.\n if (loglike) then\n oddsRatio = likelinew-likeliold\n if (oddsRatio .gt. 0.0_dp) oddsSwitch1 = .true.\n else\n oddsRatio = likelinew/likeliold\n if (oddsRatio .gt. 1.0_dp) oddsSwitch1 = .true.\n end if\n ! write(*,*) 'oddsRatio = ',oddsRatio\n\n ! (C) Accept or Reject?\n If (oddsSwitch1) then\n\n ! positive accept\n Ipos(1) = Ipos(1) + 1_i4\n paraold = paranew\n likeliold = likelinew\n where (changePara)\n stepsize = stepsize * accMult\n end where\n if (likelinew .gt. likelibest) then\n parabest = paranew\n likeliold = likeli_new !JM\n ! Here the sigma is reset!\n likelibest = likeli_new\n stddev_data = stddev_new\n !\n parabestChanged = .true.\n write(*,*) ''\n write(*,*) 'best para changed: ',paranew\n write(*,*) 'likelihood new: ',likelinew\n write(*,*) ''\n end if\n burnin_paras_part(Ipos(1)+Ineg(1),:) = paranew(:)\n ! write(*,*) 'positive accept'\n\n else\n\n call xor4096(seeds(1,1), RN1, save_state=save_state_1(1,:))\n oddsSwitch2 = .false.\n if (loglike) then\n if (oddsRatio .lt. -700.0_dp) oddsRatio = -700.0_dp ! to avoid underflow\n if (rn1 .lt. exp(oddsRatio)) oddsSwitch2 = .true.\n else\n if (rn1 .lt. oddsRatio) oddsSwitch2 = .true.\n end if\n\n If ( oddsSwitch2 ) then\n\n ! negative accept\n Ineg(1) = Ineg(1) + 1_i4\n paraold = paranew\n likeliold = likelinew\n ! stddev_data = stddev_new !JM\n where (changePara)\n stepsize = stepsize * accMult\n end where\n burnin_paras_part(Ipos(1)+Ineg(1),:) = paranew(:) \n ! write(*,*) 'negative accept'\n\n else\n\n ! reject\n where (changePara)\n stepsize = stepsize * rejMult\n end where\n ! write(*,*) 'reject'\n\n end if\n\n end if\n\n ! write(*,*) ''\n\n end do markovchain\n\n accRatio(1) = real(Ipos(1) + Ineg(1),dp) / real(iter_burnin,dp)\n if (printflag) then\n write(str,'(A,I03,A)') '(A7,I4,A15,F5.3,A17,',size(para,1),'(E9.2,1X),A1)'\n write(*,str) 'trial #',trial,' acc_ratio = ',accRatio(1),' (stepsize = ',stepsize,')'\n end if\n\n if (Ipos(1)+Ineg(1) .gt. 0_i4) then\n call append(burnin_paras, burnin_paras_part(1:Ipos(1)+Ineg(1),:))\n end if\n\n ! adjust acceptance multiplier\n if (accRatio(1) .lt. 0.234_dp) accMult = accMult * 0.99_dp\n if (accRatio(1) .gt. 0.441_dp) accMult = accMult * 1.01_dp\n\n ! store good accRatios in history and delete complete history if bad one appears\n if (accRatio(1) .lt. 0.234_dp .or. accRatio(1) .gt. 0.441_dp) then\n if( allocated(history_accRatio) ) deallocate(history_accRatio)\n else\n call append(history_accRatio, accRatio(1))\n end if\n\n ! if in history more than 10 values, check for mean and variance\n if ( allocated(history_accRatio) ) then\n accRatio_n = size(history_accRatio,1)\n if ( accRatio_n .ge. 10_i4 ) then\n idummy = accRatio_n-9_i4\n accRatio_stddev = stddev( history_accRatio(idummy:accRatio_n) )\n\n ! Check of Convergence\n if ( (accRatio_stddev .lt. Sqrt( 1._dp/12._dp * 0.05_dp**2 )) ) then\n iStop = .true.\n if (printflag) then\n write(*,*) ''\n write(*,*) 'STOP BURN-IN with accaptence ratio of ', history_accRatio(accRatio_n)\n write(*,*) 'final stepsize: ',stepsize\n if (parabestChanged) then\n write(*,*) 'better parameter set was found: ',parabest\n write(*,*) 'with likelihood: ',likelibest\n end if\n end if\n end if\n\n end if\n end if\n\n trial = trial + 1_i4\n\n end do convergedBURNIN\n\n end do betterParaFound\n\n end if\n\n !----------------------------------------------------------------------\n ! (2) MCMC\n !----------------------------------------------------------------------\n\n ! just to be sure that all chains start with same initial parameter set\n ! in both parallel and sequential mode\n ! (although in between a new parabest will be found in chains)\n initial_paraset_mcmc = parabest\n\n if (printflag) then\n write(*,*) ''\n write(*,*) '--------------------------------------------------'\n write(*,*) 'Starting MCMC (chains = ',chains,', iter_mcmc = ',iter_mcmc,')'\n write(*,*) '--------------------------------------------------'\n write(*,*) ''\n end if\n Ipos(:) = 0_i4 ! positive accepted\n Ineg(:) = 0_i4 ! negative accepted\n\n ! if all parameters converged: Sqrt(R_i) < 1.1 (see Gelman et. al: Baysian Data Analysis, p. 331ff\n converged = .False.\n\n convergedMCMC: do while (.not. converged)\n\n if (.not. allocated(mcmc_paras_3d)) then\n ! first mcmc iterations for all chains\n ! probably too large, but will be resized at the end\n allocate(mcmc_paras_3d(iter_mcmc,size(para),chains))\n else\n ! later mcmc iterations for all chains: iter_mcmc was increased\n idummy = Minval(Ipos+Ineg)\n\n ! resize mcmc_paras_3d\n allocate(tmp(idummy,size(para),chains))\n tmp(:,:,:) = mcmc_paras_3d(1:idummy,:,:)\n deallocate(mcmc_paras_3d)\n allocate(mcmc_paras_3d(iter_mcmc,size(para),chains))\n mcmc_paras_3d(1:idummy,:,:) = tmp(:,:,:)\n deallocate(tmp)\n end if\n\n !$OMP parallel default(shared) &\n !$OMP private(chain, paraold, paranew, likeliold, likelinew, oddsSwitch1, oddsSwitch2, RN1, oddsRatio, ChangePara)\n !$OMP do\n parallelchain: do chain=1, chains\n\n if (Ipos(chain)+Ineg(chain) .eq. 0_i4) then\n paraold = initial_paraset_mcmc ! = parabest of burn-in\n else\n paraold = mcmc_paras_3d(Ipos(chain)+Ineg(chain),:,chain)\n end if\n likeliold = likelihood(paraold,stddev_data)\n\n markovchainMCMC: do\n\n ! (A) Generate new parameter set\n ChangePara = .false.\n paranew = paraold\n\n call GenerateNewParameterset_dp(ParaSelectMode, paraold, truepara, rangePar, stepsize, &\n save_state_2(chain,:),&\n save_state_3(chain,:),&\n paranew,ChangePara)\n\n ! (B) new likelihood\n likelinew = likelihood(paranew,stddev_data)\n oddsSwitch1 = .false.\n if (loglike) then\n oddsRatio = likelinew-likeliold\n if (oddsRatio .gt. 0.0_dp) oddsSwitch1 = .true.\n else\n oddsRatio = likelinew/likeliold\n if (oddsRatio .gt. 1.0_dp) oddsSwitch1 = .true.\n end if\n\n ! (C) Accept or Reject?\n If (oddsSwitch1) then\n\n ! positive accept\n Ipos(chain) = Ipos(chain) + 1_i4\n paraold = paranew\n likeliold = likelinew\n mcmc_paras_3d(Ipos(chain)+Ineg(chain),:,chain) = paranew(:)\n\n if ( printflag ) then\n if ( (Ipos(chain)+Ineg(chain) .gt. 0_i4 ) .and. &\n (mod(Ipos(chain)+Ineg(chain),10000_i4)) .eq. 0 ) then\n write(*,*) 'Chain ',chain,': Done ',Ipos(chain)+Ineg(chain),' samples ...'\n end if\n end if\n\n if (likelinew .gt. likelibest) then\n parabest = paranew\n likelibest = likelinew\n if (printflag) then\n write(*,*) ''\n write(*,*) 'best para changed: ',paranew\n write(*,*) 'likelihood new: ',likelinew\n write(*,*) ''\n end if\n end if\n\n else\n\n call xor4096(seeds(chain,1), RN1, save_state=save_state_1(chain,:))\n oddsSwitch2 = .false.\n if (loglike) then\n if (rn1 .lt. exp(oddsRatio)) oddsSwitch2 = .true.\n else\n if (rn1 .lt. oddsRatio) oddsSwitch2 = .true.\n end if\n\n If ( oddsSwitch2 ) then\n\n ! negative accept\n Ineg(chain) = Ineg(chain) + 1_i4\n paraold = paranew\n likeliold = likelinew\n mcmc_paras_3d(Ipos(chain)+Ineg(chain),:,chain) = paranew(:)\n\n if ( printflag ) then\n if ( (Ipos(chain)+Ineg(chain) .gt. 0_i4 ) .and. &\n (mod(Ipos(chain)+Ineg(chain),10000_i4)) .eq. 0 ) then\n write(*,*) 'Chain ',chain,': Done ',Ipos(chain)+Ineg(chain),' samples ...'\n end if\n end if\n\n end if\n\n end if\n\n ! enough samples were found\n if ( (Ipos(chain)+Ineg(chain) .gt. 0_i4 ) .and. &\n (mod(Ipos(chain)+Ineg(chain),iter_mcmc) .eq. 0_i4 ) ) exit\n\n end do markovchainMCMC\n\n end do parallelchain\n !$OMP end do\n !$OMP end parallel\n\n ! write parameter sets to temporal file\n if (present(tmp_file)) then\n ! splitting into path and filename\n slash_pos = index(tmp_file, '/', .true.)\n len_filename = len_trim(tmp_file)\n path = tmp_file(1:slash_pos)\n filename = tmp_file(slash_pos+1:len_filename)\n !\n do chain=1,chains\n write(str,*) chain\n write(outputfile,*) trim(adjustl(path)), trim(adjustl(str)), '_' , trim(adjustl(filename))\n if (present(iter_mcmc_in)) then\n allocate(tmp(iter_mcmc_in,size(para,1),1))\n tmp(:,:,1) = mcmc_paras_3d(iter_mcmc-iter_mcmc_in+1_i4:iter_mcmc,:,chain)\n if (iter_mcmc .ne. iter_mcmc_in) then\n ! append\n call dump_netcdf(trim(adjustl(outputfile)), tmp, append=.true.)\n else\n ! first time of writing\n call dump_netcdf(trim(adjustl(outputfile)), tmp)\n end if\n deallocate(tmp)\n else\n allocate(tmp(1000_i4*n,size(para,1),1))\n tmp(:,:,1) = mcmc_paras_3d(iter_mcmc-(1000_i4*n)+1_i4:iter_mcmc,:,chain)\n if (iter_mcmc .ne. 1000_i4*n) then\n ! append\n call dump_netcdf(trim(adjustl(outputfile)), tmp, append=.true.)\n else\n ! first time of writing\n call dump_netcdf(trim(adjustl(outputfile)), tmp)\n end if\n deallocate(tmp)\n end if\n end do\n end if\n\n ! test for convergence: Gelman et. al: Baysian Data Analysis, p. 331ff\n ! sqrt(R) = sqrt( ( (n-1)/n * W + 1/n * B ) / W ) < 1.1 for each parameter\n ! n ... last half of the sequence\n ! W ... within sequence variance\n ! B ... between chain variance\n\n if ( printflag ) then\n write(*,*) ' '\n write(*,*) 'Checking for convergence ....'\n end if\n sqrtR = 0.0_dp\n n_end = minval(Ipos+Ineg)\n n_start = n_end / 2_i4 + 1_i4\n\n do iPar=1, size(truepara)\n\n ! Between chain variances\n do chain=1, chains\n vDotJ(chain) = 1.0_dp / real(n_end-n_start+1_i4,dp) * &\n sum(mcmc_paras_3d(n_start:n_end,truepara(iPar),chain))\n end do\n vDotDot = 1.0_dp / real(chains,dp) * sum(vDotJ)\n B = real(n_end -n_start + 1_i4,dp) / real(chains-1_i4,dp) * &\n sum((vDotJ - vDotDot)*(vDotJ - vDotDot))\n\n ! Within chain variances\n do chain=1, chains\n s2(chain) = 1.0_dp / real(n_end-n_start,dp) * &\n sum((mcmc_paras_3d(n_start:n_end,truepara(iPar),chain)-vDotJ(chain))**2)\n end do\n W = 1.0_dp / real(chains,dp) * Sum(s2)\n\n ! ratio sqrtR\n if ( (w .lt. tiny(1.0_dp)) .and. (b .lt. tiny(1.0_dp))) then\n ! Mathematica says that this is the limit, if w and b both go to zero\n sqrtR(truepara(iPar)) = sqrt(real(n_end-n_start,dp) / real(n_end-n_start+1_i4,dp))\n else\n sqrtR(truepara(iPar)) = real(n_end-n_start,dp) / real(n_end-n_start+1_i4,dp) * W + &\n 1.0_dp / real(n_end-n_start+1_i4,dp) * B\n sqrtR(truepara(iPar)) = sqrt( sqrtR(truepara(iPar)) / W )\n end if\n end do\n if (printflag) then\n do i=1, size(para)\n if ( sqrtR(i) .gt. 1.1_dp ) then\n write(*,*) ' sqrtR para #',i,' : ', sqrtR(i),' <-- FAILED'\n else\n write(*,*) ' sqrtR para #',i,' : ', sqrtR(i)\n end if\n end do\n end if\n if ( all(sqrtR .lt. 1.1_dp) ) then\n converged = .true.\n if ( printflag ) then\n write(*,*) ' --> converged (all less than 1.1)'\n write(*,*) ' '\n end if\n else\n ! increase number of iterations\n if (present(iter_mcmc_in)) then\n iter_mcmc = iter_mcmc + iter_mcmc_in\n else\n iter_mcmc = iter_mcmc + 1000_i4 * n\n endif\n\n if ( printflag ) then\n write(*,*) ' --> not converged (not all less than 1.1)'\n write(*,*) ' increasing iterations to ',iter_mcmc\n write(*,*) ' '\n end if\n end if\n\n end do convergedMCMC\n\n ! reshape of mcmc_paras_3d: return only 2d matrix mcmc_paras\n allocate(mcmc_paras(size(mcmc_paras_3d,1)*size(mcmc_paras_3d,3),size(mcmc_paras_3d,2)))\n do chain=1, chains\n mcmc_paras( (chain-1_i4)*size(mcmc_paras_3d,1)+1_i4 : chain*size(mcmc_paras_3d,1),:) = mcmc_paras_3d(:,:,chain)\n end do\n\n RETURN\n END SUBROUTINE mcmc_stddev_dp\n\n !***************************************************\n !* PRIVATE FUNCTIONS *\n !***************************************************\n\n !\n real(DP) function parGen_dp(old, dMax, oMin, oMax,RN,inbound)\n use mo_kind, only: dp\n implicit none\n !\n REAL(DP), intent(IN) :: old, dMax, oMin,oMax\n REAL(DP), intent(IN) :: RN\n LOGICAL,OPTIONAL,INTENT(OUT) :: inbound\n\n ! local\n LOGICAL :: inbound2\n !\n inbound2 = .true.\n parGen_dp = old + (rn*2.0_dp*dMax - dMax)\n\n if (parGen_dp < oMin) then\n parGen_dp = oMin\n inbound2 = .false.\n elseif(parGen_dp > oMax)then\n parGen_dp = oMax\n inbound2 = .false.\n end if\n\n if (present(inbound)) inbound = inbound2\n\n end function parGen_dp\n\n ! ************************************************************************\n ! normalized Parameter Change\n ! ************************************************************************\n\n real(DP) function parGenNorm_dp(old, dMax, oMin, oMax,RN,inbound)\n use mo_kind, only: dp\n implicit none\n !\n REAL(DP), intent(IN) :: old, dMax, oMin,oMax\n REAL(DP), intent(IN) :: RN\n LOGICAL,OPTIONAL,INTENT(OUT) :: inbound\n\n ! LOCAL VARIABLES\n REAL(DP) :: RN_scale ! scaled RN\n REAL(DP) :: old_scaled ! for normalization\n LOGICAL :: inbound2\n\n inbound2 =.true.\n\n !(1) normalize\n old_scaled = ( old - oMin) / ( oMax - oMin)\n\n !(2) scale RN = [-dMax, dMax]\n !RN_scale = (RN * 2.0_dp * dMax) - dMax\n !(2) scale RN distrib. N(0, dMax)\n RN_scale = (RN * dMax)\n\n !(3) generate new parameter value + check inbound\n parGenNorm_dp = old_scaled + RN_scale\n ! Parameter is bounded between Max and Min.\n ! if (parGenNorm_dp < 0.0_dp) then\n ! parGenNorm_dp = 0.0_dp\n ! inbound2 = .false.\n ! elseif(parGenNorm_dp > 1.0_dp)then\n ! parGenNorm_dp = 1.0_dp\n ! inbound2 = .false.\n ! end if\n\n if (present(inbound)) inbound = inbound2\n\n !(4) convert back to original range\n parGenNorm_dp = parGenNorm_dp * ( oMax - oMin) + oMin\n\n end function parGenNorm_dp\n\n recursive subroutine GenerateNewParameterset_dp(ParaSelectMode, paraold, truepara, rangePar, stepsize, &\n save_state_2,save_state_3,paranew,ChangePara)\n\n integer(i4), intent(in) :: ParaSelectMode\n real(dp), dimension(:), intent(in) :: paraold\n integer(i4), dimension(:), intent(in) :: truepara\n real(dp), dimension(:,:), intent(in) :: rangePar\n real(dp), dimension(:), intent(in) :: stepsize\n integer(I8), dimension(n_save_state), intent(inout) :: save_state_2 ! optional argument for restarting RN stream 2\n integer(I8), dimension(n_save_state), intent(inout) :: save_state_3 ! optional argument for restarting RN stream 3\n real(dp), dimension(size(paraold)), intent(out) :: paranew\n logical, dimension(size(paraold)), intent(out) :: ChangePara\n\n ! local variables\n REAL(DP) :: RN2, RN3\n logical :: inbound\n integer(i4) :: i, iPar\n\n paranew = paraold\n ChangePara = .False.\n\n select case(ParaSelectMode)\n case(1_i4) ! change half of the parameters\n do i=1,size(truepara)\n call xor4096(0_i8,RN2, save_state=save_state_2)\n if ( RN2 > 0.5_dp ) then\n iPar = truepara(i)\n inbound = .false.\n call xor4096(0_i8,RN3, save_state=save_state_3)\n paranew(iPar) = parGenNorm_dp( paraold(iPar), stepsize(iPar), rangePar(iPar,1), rangePar(iPar,2),RN3,inbound)\n ChangePara(iPar) = .True.\n end if\n end do\n ! if no parameter was selected, recall and change one\n if (count(ChangePara) .eq. 0_i4) then\n call xor4096(0_i8,RN2, save_state=save_state_2)\n iPar = truepara(int(( RN2 * real(size(truepara),dp)) + 1.0_dp, i4 ))\n inbound = .false.\n call xor4096(0_i8,RN3, save_state=save_state_3)\n paranew(iPar) = parGenNorm_dp( paraold(iPar), stepsize(iPar), rangePar(iPar,1), rangePar(iPar,2),RN3,inbound)\n ChangePara(iPar) = .True.\n end if\n\n case(2_i4) ! change only one\n call xor4096(0_i8,RN2, save_state=save_state_2)\n iPar = truepara(int(( RN2 * real(size(truepara),dp)) + 1.0_dp, i4 ))\n inbound = .false.\n call xor4096g(0_i8,RN3, save_state=save_state_3)\n paranew(iPar) = parGenNorm_dp( paraold(iPar), stepsize(iPar), rangePar(iPar,1), rangePar(iPar,2),RN3,inbound)\n ! write(*,*) 'p_old(',iPar,') = ',paraold(iPar)\n ! write(*,*) 'p_new(',iPar,') = ',paranew(iPar)\n ChangePara(iPar) = .True.\n\n case(3_i4) ! change all\n do i=1,size(truepara)\n iPar = truepara(i)\n inbound = .false.\n do while( .not. inbound)\n call xor4096g(0_i8,RN2, save_state=save_state_3)\n paranew(iPar) = parGenNorm_dp( paraold(iPar), stepsize(iPar), rangePar(iPar,1), rangePar(iPar,2),RN3,inbound)\n end do\n ChangePara(iPar) = .True.\n end do\n\n end select\n\n end subroutine GenerateNewParameterset_dp\n\nEND MODULE mo_mcmc\n", "meta": {"hexsha": "8b61e7e7f875d2e0e6abea238b1e98cfb534aaf3", "size": 105984, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/test_mo_mcmc/mo_mcmc.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_mcmc/mo_mcmc.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_mcmc/mo_mcmc.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": 47.7405405405, "max_line_length": 131, "alphanum_fraction": 0.4790723128, "num_tokens": 25199, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240142763574, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6741306618486763}} {"text": " SUBROUTINE interpolation3D(C,x0,x,r,d)\n ! 3 dimensional interpolation kernel.\n !\n ! Inputs:\n ! x0: array with dimension(3) [x0,y0,z0] \n ! x : array with dimensions(1:r^3,1:3) \n ! x=[x1, x2,..;y1,y2,..;z1,z2,..]^T\n ! r : size of stencil (INTEGER)\n ! d: characteristic lengthscale, used for scaling in\n ! order to keep the matrix well conditioned \n !\n ! Output: \n ! C: A interpolation kernel with dimension(r^3:r^3)\n ! The stencil is assumed to be logically square so that the grid points \n ! and derivatives start at the lower left-hand corner and follow \n ! coordinate 2 (y) first and then coordinate 1 (x). The coefficients \n ! are thus defined such that \n !\n ! c(k,1:r^3), k=(m-1)*r+n; corresponds to d^{m+n}/dx^m/dy^n.\n ! eg.:r=2 [f0 df/dy df/dx d^2f/dxdy df/dz df^2/dzdy df^2]\n !\n !\n ! Written by Bo Terp Paulsen, botp@mek.dtu.dk\n !\n\n ! Inputs / outputs\n !\n USE Interpolation_functions ! Decleration of matrix inversion,\n ! and factorial.\n IMPLICIT NONE\n INTEGER, PARAMETER :: dp = selected_real_kind(15, 307)\n INTEGER :: r,count1,count2\n REAL(KIND=dp), DIMENSION(:,:) :: x(r**3,3),C(r**3,r**3),mat(r**3,r**3)\n REAL(KIND=dp), DIMENSION(:) :: x0(3) \n REAL(KIND=dp) :: d \n \n\n ! Local variables\n !\n INTEGER :: i,j,k,m,n,b\n REAL(KIND=dp) :: factor\n\n !\n !\n factor = 1/d\n \n ! Generate Taylor coefficient matrix\n !\n count1 = 0\n count2 = 0\n DO i = 1,r ! x\n DO j = 1,r ! y \n Do k = 1,r ! z\n count1 = count1 +1 \n DO m = 1,r ! x\n DO n = 1,r ! y\n DO b = 1,r ! z\n count2 = count2 +1 \n mat(count1,count2) = ((factor*(x(count1,1)-x0(1)))**(m-1)/fact(m-1))* &\n ((factor*(x(count1,2)-x0(2)))**(n-1)/fact(n-1))* &\n ((factor*(x(count1,3)-x0(3)))**(b-1)/fact(b-1))\n END DO\n END DO\n END DO\n \n count2 = 0\n END DO\n END DO\n END DO\n\n C = inv(mat)\n\n ! Rescaling of coefficients\n !\n count1 = 0\n\n DO i = 1,r ! x\n DO j = 1,r ! y \n Do k = 1,r ! z\n count1 = count1 +1\n DO count2 =1,r**3\n C(count1,count2) = factor**(i-1)*factor**(j-1)*factor**(k-1)*C(count1,count2)\n END DO\n\n END DO\n END DO\n END DO\n END SUBROUTINE interpolation3D\n\n SUBROUTINE interpolation2D(C,x0,x,r,d)\n ! 2 dimensional interpolation kernel.\n !\n ! Inputs:\n ! x0: array with dimension(3) [x0,y0,z0], only x0 and y0\n ! is used\n ! x=[x1, x2,..;y1,y2,..]^T\n ! r : size of stencil (INTEGER)\n ! dx: characteristic lengthscale, used for scaling in\n ! order to keep the matrix well conditioned \n !\n ! Output: \n ! C: A interpolation kernel with dimension(r^2:r^2)\n ! The stencil is assumed to be logically square so that the grid points \n ! and derivatives start at the lower left-hand corner and follow \n ! coordinate 2 (y) first and then coordinate 1 (x). The coefficients !\n ! are \n ! thus defined such that \n !\n ! c(k,1:r^3), k=(m-1)*r+n; corresponds to d^{m+n}/dx^m/dy^n.\n ! eg.:r=2 [f0 df/dy df/dx d^2f/dxdy df/dz df^2/dzdy df^2]\n !\n !\n ! Written by Bo Terp Paulsen, botp@mek.dtu.dk\n !\n\n ! Inputs / outputs\n !\n USE Interpolation_functions\n IMPLICIT NONE\n INTEGER, PARAMETER :: dp = selected_real_kind(15, 307)\n INTEGER :: r\n REAL(KIND=dp), DIMENSION(:,:) :: x(r**2,2),C(r**2,r**2),mat(r**2,r**2)\n REAL(KIND=dp), DIMENSION(:) :: x0(3) \n REAL(KIND=dp) :: d \n \n\n ! Local variables\n !\n INTEGER :: i,j,m,n,count1,count2\n REAL(KIND=dp) :: factor\n\n ! Scaling factor\n !\n factor = 1/d\n \n ! Generate Taylor coefficient matrix\n !\n count1 = 0\n count2 = 0\n DO i = 1,r \n DO j = 1,r \n count1 = count1 +1 \n DO m = 1,r \n DO n = 1,r \n count2 = count2 +1 \n mat(count1,count2) = ((factor*(x(count1,1)-x0(1)))**(m-1)/fact(m-1))* &\n ((factor*(x(count1,2)-x0(2)))**(n-1)/fact(n-1))\n END DO\n END DO\n count2 = 0\n END DO\n END DO\n C = inv(mat)\n\n ! Rescaling of coefficients\n !\n count1 = 0\n\n DO i = 1,r \n DO j = 1,r \n count1 = count1 +1\n DO count2 =1,r**2\n C(count1,count2) = factor**(i-1)*factor**(j-1)*C(count1,count2)\n END DO\n\n END DO\n END DO\n END SUBROUTINE interpolation2D\n\n SUBROUTINE interpolation1D(C,x0,x,r)\n ! 1 dimensional interpolation kernel.\n !\n ! Inputs:\n ! x0: array with dimension(3) [x0,y0,z0], Only x0 is used\n ! x : array with dimensions(1:r,1) \n ! x=[x1, x2,..]^T\n ! r : size of stencil (INTEGER)\n !\n ! Output: \n ! C: A interpolation kernel with dimension(r:r)\n !\n !\n ! Written by Bo Terp Paulsen, botp@mek.dtu.dk\n !\n\n\n ! Inputs / outputs\n !\n USE Interpolation_functions\n IMPLICIT NONE\n INTEGER, PARAMETER :: dp = selected_real_kind(15, 307)\n INTEGER :: r\n REAL(KIND=dp), DIMENSION(:,:) :: C(r,r),mat(r,r)\n REAL(KIND=dp), DIMENSION(:) :: x0(3),x(r) \n REAL(KIND=dp) :: d \n \n\n ! Local variables\n !\n INTEGER :: i,m,count1, count2\n REAL(KIND=dp) :: factor\n\n ! Scaling factor\n !\n d = x(r)-x(r-1)\n factor = 1/d\n \n ! Generate Taylor coefficient matrix\n !\n count1 = 0\n count2 = 0\n DO i = 1,r \n count1 = count1 +1 \n DO m = 1,r \n count2 = count2 +1 \n mat(count1,count2) = (factor*(x(count1)-x0(1)))**(m-1)/fact(m-1)\n END DO\n count2 = 0\n END DO\n C = inv(mat)\n\n ! Rescaling of coefficients\n !\n count1 = 0\n\n DO i = 1,r \n count1 = count1 +1\n DO count2 =1,r\n C(count1,count2) = factor**(i-1)*C(count1,count2)\n END DO\n END DO\n END SUBROUTINE interpolation1D\n\n SUBROUTINE TaylorInterpolation&\n (dir,x0,stencilSize)\n ! Evaluating a Taylor polynomial at point x0, with expansion point\n !at nearest neighbour.\n !\n ! Inputs: \n ! dir: Integer indication in which\n ! directions interpolation is desired. \n ! x0 : Point to which the values are interpolated.\n !\n ! Output:\n ! TaylorStencil: Interpolation stencil\n ! inOrOut: Flag indicating however the cell is located in\n ! or outside the water column\n !\n ! Written by Bo Terp Paulsen, botp@mek.dtu.dk\n !\n USE Precision\n USE GlobalVariables\n USE Interpolation_functions !Declaration of factorial func. \n IMPLICIT NONE\n\n ! Input variables\n !\n INTEGER :: dir\n REAL(KIND=long), DIMENSION(:) :: x0(3)\n \n ! Local variables\n !\n INTEGER :: stencilSize, i\n INTEGER, DIMENSION(:), POINTER :: NN\n REAL(KIND=long) :: sigma, dl\n REAL(KIND=long), DIMENSION(:), ALLOCATABLE :: dlVector\n REAL(KIND=long), DIMENSION(:,:) :: &\n transMAT(stencilSize,stencilSize)\n REAL(KIND=long), DIMENSION(:), POINTER :: xStencil, yStencil, zStencil\n\n ! Assign local pointers\n !\n xStencil => interpolation%stencilX \n yStencil => interpolation%stencilY \n zStencil => interpolation%stencilZ\n NN => interpolation%NN\n\n\n \n IF(dir == 1) THEN\n ALLOCATE(dlVector(2*alpha +1))\n dl = x0(1)-FineGrid%x(NN(1),1)\n DO i = 0,2*alpha\n dlVector(i+1) = dl**i / fact(i)\n END DO\n\n\n xStencil = &\n MATMUL(Interpolation%dx,dlVector)\n ENDIF\n \n IF(dir == 2) THEN\n ALLOCATE(dlVector(2*beta +1))\n dl = x0(2) - FineGrid%y(1,NN(2))\n DO i = 0,2*beta\n dlVector(i+1) = dl**i / fact(i)\n END DO\n\n yStencil = &\n MATMUL(Interpolation%dy(:,:),dlVector)\n\n ENDIF\n\n IF(dir == 3) THEN\n ! Transformation of z-physical into sigma\n ! \n sigma = (x0(3) ) / &\n (FineGrid%h(NN(1),NN(2)) + Wavefield%E(NN(1),NN(2)))\n\n \n ALLOCATE(dlVector(2*gamma + 1))\n dl = (sigma - FineGrid%z(NN(3))) \n DO i = 0,2*gamma\n dlVector(i+1) = dl**i / fact(i)\n END DO\n\n zStencil = &\n MATMUL(Interpolation%dz(:,:,NN(3)),dlVector)\n\n ENDIF\n \n END SUBROUTINE TaylorInterpolation\n", "meta": {"hexsha": "846d4bdfdc4646d7fb62d64c4848781daaf71c81", "size": 9299, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/OpenFoam/interpolation.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/OpenFoam/interpolation.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/OpenFoam/interpolation.f90", "max_forks_repo_name": "apengsigkarup/OceanWave3D", "max_forks_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2015-10-01T12:17:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-02T16:23:37.000Z", "avg_line_length": 28.7894736842, "max_line_length": 87, "alphanum_fraction": 0.4783310033, "num_tokens": 2695, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240142763573, "lm_q2_score": 0.7185943925708562, "lm_q1q2_score": 0.6741306561950522}} {"text": "MODULE AutoDiff_Module\nUSE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY : DFP=>real64, I4B=>int32\nIMPLICIT NONE\n\nREAL( DFP ), PARAMETER :: eps=1.0E-8\n\nPRIVATE\n\n!----------------------------------------------------------------------------\n! Interfaces\n!----------------------------------------------------------------------------\n\nABSTRACT INTERFACE\n\n!> authors: Dr. Vikas Sharma\n!\n! This is a template for a scalar valued scalar function\n! f:R-->R\n PURE FUNCTION userFunc_R_to_R( x ) RESULT( Ans )\n IMPORT :: DFP, I4B\n REAL( DFP ), INTENT( IN ) :: x\n REAL( DFP ) :: Ans\n END FUNCTION userFunc_R_to_R\nEND INTERFACE\n\nABSTRACT INTERFACE\n\n!> authors: Dr. Vikas Sharma\n!\n! This is a template for a scalar valued scalar function\n! f:R2-->R\n PURE FUNCTION userFunc_R2_to_R( x, y ) RESULT( Ans )\n IMPORT :: DFP, I4B\n REAL( DFP ), INTENT( IN ) :: x, y\n REAL( DFP ) :: Ans\n END FUNCTION userFunc_R2_to_R\nEND INTERFACE\n\n\n!----------------------------------------------------------------------------\n! Derivative\n!----------------------------------------------------------------------------\n\nINTERFACE\n\n!> authors: Dr. Vikas Sharma\n!\n! $$\\frac{df}{dx}$$\nMODULE PURE FUNCTION derivative_R_to_R( f, x ) RESULT( Ans )\n REAL( DFP ), INTENT( IN ) :: x\n REAL( DFP ) :: Ans\n PROCEDURE( userFunc_R_to_R ), POINTER, INTENT( IN ) :: f\nEND FUNCTION derivative_R_to_R\nEND INTERFACE\n\n!----------------------------------------------------------------------------\n!\n!----------------------------------------------------------------------------\n\nINTERFACE\n\n!> authors: Dr. Vikas Sharma\n!\n! $$\\frac{\\partial f(x,y)}{\\partial x}, \\frac{\\partial f(x,y)}{\\partial y}$$\nMODULE PURE FUNCTION derivative_R2_to_R( f, x, y ) RESULT( Ans )\n REAL( DFP ), INTENT( IN ) :: x, y\n REAL( DFP ) :: Ans(2)\n PROCEDURE( userFunc_R2_to_R ), POINTER, INTENT( IN ) :: f\nEND FUNCTION derivative_R2_to_R\nEND INTERFACE\n\nINTERFACE derivative\n MODULE PROCEDURE derivative_R_to_R, derivative_R2_to_R\nEND INTERFACE derivative\n\nPUBLIC :: derivative\n\nEND MODULE AutoDiff_Module", "meta": {"hexsha": "50a174d8e10b249bb6d1d028205acaa6fbeb40f2", "size": 2169, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "pass_func_to_subroutine/AutoDiff_Module.f90", "max_stars_repo_name": "vickysharma0812/modernFortran", "max_stars_repo_head_hexsha": "54c1ea61e9269f4679462e113f65a7ad383923a9", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "pass_func_to_subroutine/AutoDiff_Module.f90", "max_issues_repo_name": "vickysharma0812/modernFortran", "max_issues_repo_head_hexsha": "54c1ea61e9269f4679462e113f65a7ad383923a9", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "pass_func_to_subroutine/AutoDiff_Module.f90", "max_forks_repo_name": "vickysharma0812/modernFortran", "max_forks_repo_head_hexsha": "54c1ea61e9269f4679462e113f65a7ad383923a9", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.8076923077, "max_line_length": 77, "alphanum_fraction": 0.4993084371, "num_tokens": 525, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711832583696, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.6741172100120465}} {"text": "! { dg-do run { target vect_simd_clones } }\n! { dg-additional-options \"-msse2\" { target sse2_runtime } }\n! { dg-additional-options \"-mavx\" { target avx_runtime } }\n\nprogram fibonacci\n implicit none\n integer,parameter :: N=30\n integer :: a(0:N-1), b(0:N-1)\n integer :: a_ref(0:N-1)\n integer :: i\n integer, external :: fib\n\n !$omp simd\n do i = 0,N-1\n b(i) = i\n end do\n\n !$omp simd\n do i=0,N-1\n a(i) = fib(b(i))\n end do\n\n call fib_ref (a_ref, N)\n\n do i = 0, N-1\n if (a(i) .ne. a_ref(i)) call abort ()\n end do\n\nend program\n\nrecursive function fib(n) result(r)\n!$omp declare simd(fib) inbranch\n integer :: n, r\n\n if (n <= 1) then\n r = n\n else\n r = fib(n-1) + fib(n-2)\n endif\n\nend function fib\n\nsubroutine fib_ref(a_ref, n)\n integer :: n, a_ref(0:n-1)\n\n a_ref(0) = 0\n a_ref(1) = 1\n\n do i = 2, n-1\n a_ref(i) = a_ref(i-1) + a_ref(i-2)\n end do\n\nend subroutine fib_ref\n", "meta": {"hexsha": "7560657050391f358d1af790b8bc873901458500", "size": 968, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gcc-gcc-7_3_0-release/libgomp/testsuite/libgomp.fortran/examples-4/simd-7.f90", "max_stars_repo_name": "best08618/asylo", "max_stars_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-05-02T17:34:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-17T10:15:18.000Z", "max_issues_repo_path": "gcc-gcc-7_3_0-release/libgomp/testsuite/libgomp.fortran/examples-4/simd-7.f90", "max_issues_repo_name": "best08618/asylo", "max_issues_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "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": "gcc-gcc-7_3_0-release/libgomp/testsuite/libgomp.fortran/examples-4/simd-7.f90", "max_forks_repo_name": "best08618/asylo", "max_forks_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-27T00:22:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-01T09:41:02.000Z", "avg_line_length": 17.9259259259, "max_line_length": 60, "alphanum_fraction": 0.5464876033, "num_tokens": 355, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891392358015, "lm_q2_score": 0.8198933403143929, "lm_q1q2_score": 0.6741073997382567}} {"text": "module test_function_object\n ! Object oriented approach for function\n ! evaluation.\n\n use utils, only : wp\n use num_integration\n\n implicit none\n\n abstract interface\n function f_interface(x)\n import :: wp\n real(wp), intent(in) :: x\n real(wp) :: f_interface\n end function f_interface\n end interface\n\n ! function_object is an object that can point\n ! to any function that follow the f_interface.\n ! This allows for the object to change its behavior\n ! in runtime.\n type, extends(fun) :: function_object\n procedure(f_interface), pointer, nopass :: f\n contains\n procedure :: eval => specialized_function\n end type function_object\n\n contains\n\n function specialized_function(self, x)\n class(function_object), intent(in) :: self\n real(wp), intent(in) :: x\n real(wp) :: specialized_function\n specialized_function = self%f(x)\n end function specialized_function\n\nend module test_function_object\n\nprogram romgerg_tests\nuse utils\nuse num_integration\nuse test_function_object\n\n! Note that not every test is meant to pass,\n! depending on the chosen number of iterations.\n! Estimations by Romberg's using a low number\n! of iterations should not give a decent\n! approximation for higher order polynomials\n! or complex functions.\n\nimplicit none\n\n!---------------\n! Variables\n!---------------\n\ninteger :: i,j,l,m,n,total_tests,passed_tests\ncharacter (len=:), allocatable :: expression\nreal(wp) :: a(3),b(3)\ninteger :: k(3)\ntype(function_object) :: fobj\n\n!---------------\n! Logic\n!---------------\n\ntotal_tests = 1\npassed_tests = 0\nk = [5, 10, 15]\na = [-2.0, 0.0, 1.0]\nb = [1.0, 1.0, 5.0]\n\n\nwrite(*,*)\nwrite(*,*) \"!-------------------------------\"\nwrite(*,*) \"! Testing integration by Romberg\"\nwrite(*,*) \"!-------------------------------\"\nwrite(*,*)\n\ndo i = 1, size(k)\n write(*,*)\n write(*,*) \"!----------------------------------\"\n write(*,*) \"! With k = \",k(i)\n write(*,*) \"!----------------------------------\"\n do j = 1, size(a)\n expression = trim(\"f(x)=1\")\n fobj%f => poly0\n call test_integration(fobj,a(j),b(j),k(i),expression,passed_tests,total_tests,romberg,close)\n\n expression = trim(\"f(x)=x+1\")\n fobj%f => poly1\n call test_integration(fobj,a(j),b(j),k(i),expression,passed_tests,total_tests,romberg,close)\n\n expression = trim(\"f(x)=3*x**2 + 2\")\n fobj%f => poly2\n call test_integration(fobj,a(j),b(j),k(i),expression,passed_tests,total_tests,romberg,close)\n\n expression = trim(\"f(x)=33.33*x**5 + 8.8*x**4 + x**3 + 4.5*x*2 + 2.123\")\n fobj%f => poly5\n call test_integration(fobj,a(j),b(j),k(i),expression,passed_tests,total_tests,romberg,close)\n\n expression = trim(\"f(x)=8*x**7/77 + (4*sin(2*x*pi) + 9*cos(11*x*pi))/5\")\n fobj%f => ftrig\n call test_integration(fobj,a(j),b(j),k(i),expression,passed_tests,total_tests,romberg,close)\n\n expression = trim(\"f(x)=e^x\")\n fobj%f => fe\n call test_integration(fobj,a(j),b(j),k(i),expression,passed_tests,total_tests,romberg,close)\n\n if ( a(j) > 0 ) then\n expression = trim(\"f(x)=ln(x)\")\n fobj%f => fln\n call test_integration(fobj,a(j),b(j),k(i),expression,passed_tests,total_tests,romberg,close)\n end if\n end do\n write(*,*)\nend do\n\nwrite(*,*) \"!---------------------------\"\nwrite(*,'(a,g14.6)') \" !Total tests \", total_tests-1\nwrite(*,'(a,g14.6)') \" !Tests passed\", passed_tests\nwrite(*,*) \"!---------------------------\"\n\n\ncontains\n\n function poly0(x)\n real(wp), intent(in) :: x\n real(wp) :: poly0\n\n poly0 = 1.0_wp\n end function poly0\n\n function poly1(x)\n real(wp), intent(in) :: x\n real(wp) :: poly1\n\n poly1 = x + 1\n end function poly1\n\n function poly2(x)\n real(wp), intent(in) :: x\n real(wp) :: poly2\n\n poly2 = 3*x**2 + 2\n end function poly2\n\n function poly5(x)\n real(wp), intent(in) :: x\n real(wp) :: poly5\n\n poly5 = 33.33*x**5 + 8.8*x**4 + x**3 + 4.5*x*2 + 2.123\n end function poly5\n\n function ftrig(x)\n real(wp), intent(in) :: x\n real(wp) :: ftrig\n\n ftrig = 8*x**7/77 + (4*sin(2*x*pi) + 9*cos(11*x*pi))/5\n end function ftrig\n\n function fe(x)\n real(wp), intent(in) :: x\n real(wp) :: fe\n\n fe = exp(x)\n end function fe\n\n function fln(x)\n real(wp), intent(in) :: x\n real(wp) :: fln\n\n fln = log(x)\n end function fln\n\n subroutine test_integration(fobj,a,b,k,expression,passed_tests,total_tests,romberg,close)\n real(wp), intent(in) :: a,b\n real(wp) :: true,result,abserr\n real(wp), parameter :: epsabs = 0.0D+00\n real(wp), parameter :: epsrel = 0.001D+00\n integer, intent(inout) :: passed_tests, total_tests\n integer, intent(in) :: k\n integer, parameter :: key = 6\n integer, parameter :: limit = 500\n integer, parameter :: lenw = 4 * limit\n integer :: ier\n integer :: iwork(limit)\n integer :: last\n integer :: neval\n real(wp) :: work(lenw)\n\n! real(wp), external :: f\n! real(wp), external :: fcomp\n class(function_object), intent(in) :: fobj\n real(wp), external :: romberg\n logical, external :: close\n\n character (len=:), allocatable, intent(in) :: expression\n\n write(*,*)\n write(*,*) \"Test number \", total_tests\n total_tests = total_tests + 1\n result = romberg(fobj, a, b, k)\n call dqag ( fobj%f , a, b, epsabs, epsrel, key, true, abserr, neval, ier,&\n limit, lenw, last, iwork, work )\n\n write (*, '(A,A)') ' Integrand is ', expression\n write ( *, '(A,F15.5)' ) ' Integral left endpoint A ', a\n write ( *, '(A,F15.5)' ) ' Integral right endpoint B ', b\n write (*, '(A,I15)') ' #Romberg iterations(k) is', k\n write ( *, '(A,F15.5)' ) ' Integral is ', true\n write ( *, '(A,F15.5)' ) ' Estimated integral is ', result\n if ( close(result,true,1.0_wp*1e-5) ) then\n passed_tests = passed_tests + 1\n write(*,*) \"!Test passed!\"\n else\n write(*,*) \"!-----------!\"\n write(*,*) \"!Test failed!\"\n write(*,*) \"!-----------!\"\n end if\n write(*,*)\n\n end subroutine test_integration\nend program romgerg_tests\n", "meta": {"hexsha": "24c044f8e44ff931b566e0588b2bec5739aeae3a", "size": 6000, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "tests/num_integration_tests.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": "tests/num_integration_tests.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": "tests/num_integration_tests.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": 26.6666666667, "max_line_length": 98, "alphanum_fraction": 0.5915, "num_tokens": 1822, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891392358014, "lm_q2_score": 0.8198933381139646, "lm_q1q2_score": 0.6741073979290885}} {"text": "program ch0510v2\n ! Using the Numeric Inquiry Functions with Real Types\n use iso_fortran_env\n implicit none\n\n real :: r\n real(real32) :: rsp\n real(real64) :: rdp\n real(real128) :: rqp\n\n print *, ' ====================='\n print *, ' Real kind information'\n print *, ' ====================='\n print *, ' kind number'\n print *, ' ', kind(r), ' ', kind(rsp), ' ', &\n kind(rdp), ' ', kind(rqp)\n\n print *, ' digits details'\n print *, ' ', digits(r), ' ', digits(rsp), &\n ' ', digits(rdp), ' ', digits(rqp)\n\n print *, ' epsilon details'\n print *, ' ', epsilon(r)\n print *, ' ', epsilon(rsp)\n print *, ' ', epsilon(rdp)\n print *, ' ', epsilon(rqp)\n\n print *, ' huge value'\n print *, ' ', huge(r)\n print *, ' ', huge(rsp)\n print *, ' ', huge(rdp)\n print *, ' ', huge(rqp)\n\n print *, ' maxexponent value'\n print *, ' ', maxexponent(r)\n print *, ' ', maxexponent(rsp)\n print *, ' ', maxexponent(rdp)\n print *, ' ', maxexponent(rqp)\n\n print *, ' minexponent value'\n print *, ' ', minexponent(r)\n print *, ' ', minexponent(rsp)\n print *, ' ', minexponent(rdp)\n print *, ' ', minexponent(rqp)\n\n print *, ' precision details'\n print *, ' ', precision(r), ' ', &\n precision(rsp), ' ', precision(rdp), ' ', &\n precision(rqp)\n\n print *, ' radix details'\n print *, ' ', radix(r), ' ', radix(rsp), &\n ' ', radix(rdp), ' ', radix(rqp)\n\n print *, ' range details'\n print *, ' ', range(r), ' ', range(rsp), &\n ' ', range(rdp), ' ', range(rqp)\n\n print *, ' tiny details'\n print *, ' ', tiny(r)\n print *, ' ', tiny(rsp)\n print *, ' ', tiny(rdp)\n print *, ' ', tiny(rqp)\nend program\n\n", "meta": {"hexsha": "41e3f0e939aa1b99c823ad21aefc6e1a664e2800", "size": 1735, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ch05/ch0510v2.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": "ch05/ch0510v2.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": "ch05/ch0510v2.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": 26.2878787879, "max_line_length": 57, "alphanum_fraction": 0.4876080692, "num_tokens": 493, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933447152497, "lm_q2_score": 0.8221891261650247, "lm_q1q2_score": 0.6741073926399505}} {"text": "module reciprocal_module\n implicit none\n\n contains\n elemental real function reciprocal(x)\n implicit none\n\n real, intent(in) :: x\n\n reciprocal = 1./x\n end function\nend module\n\nprogram ch1213\n ! Elemental Functions\n use reciprocal_module\n implicit none\n\n real :: x = 10.\n real, dimension(1:5) :: y = [ 1., 2., 3., 4., 5. ]\n\n print *, 'reciprocal of x is ', reciprocal(x)\n print *, 'reciprocal of y is ', reciprocal(y)\nend program\n", "meta": {"hexsha": "97d6e701ec84f13a64f78fbbd1ddb72db24f4055", "size": 482, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ch12/ch1213.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/ch1213.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/ch1213.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.28, "max_line_length": 54, "alphanum_fraction": 0.612033195, "num_tokens": 133, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8198933359135361, "lm_q2_score": 0.822189121808099, "lm_q1q2_score": 0.674107381831063}} {"text": "INCLUDE 'calc_hypotenuse.f90'\n\nPROGRAM test_hypotenuse\nIMPLICIT NONE\n REAL :: s1, s2, hypo\n WRITE(*, *) \"Testing subroutine calc_hypotenuse.\"\n WRITE(*, *) \"Enter length of side 1: \"\n READ(*, *) s1\n WRITE(*, *) \"Enter length of side 2:\"\n READ(*, *) s2\n CALL calc_hypotenuse(s1, s2, hypo)\n WRITE(*, 1000) hypo\n 1000 FORMAT ('The length of the hypotenuse is ', F10.4)\n\nEND PROGRAM test_hypotenuse\n", "meta": {"hexsha": "dfa8e259ac665b3a96436a42261c9c84aa00e770", "size": 403, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap7/test_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/test_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/test_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": 25.1875, "max_line_length": 57, "alphanum_fraction": 0.6724565757, "num_tokens": 142, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.82446190912407, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.6740590116613933}} {"text": "\tFUNCTION TRAPZ2(X,Y,N,X1,X2,IERR)\n\nc\tFinds area below y(x) from x=X1 to x =X2\nc\tX1 and X2 are not necessarily values of x(i)\nc\tbut must fulfill X1>=x(1) and X2<=x(n)\n\nc\tArray declaration\n\treal x(n),y(n)\n\tdata jerr1,jerr2/2*0/\n\n\tTRAPZ2=0.\n\tierr=0.\n\n!\tCheck for values outside valid range\n\tif (x1 < x(1)) then\n\t\tif (jerr1.eq.0) then\n\t\t\twrite (6,*) 'TRAPZ2: X1 outside valid range:',x1,x(1),x(n),n\n\t\t\tjerr1=1\n\t\tendif\n\t\tierr=1\n\t\treturn\n!\t\tstop\n\telseif (x1 == x(1)) then\n\t\ti1 = 1\n\telse\n!\t\tFind first element in array X above X1\n\t\tdo i=1,n\n\t\tif (x(i) > x1) then\n\t\t\ti1=i\n!\t\t\tFind by interpolation values of Y1=y(X1)\n\t\t\tY1 = ( (x(i1)-x1)*y(i1-1) + (x1-x(i1-1))*y(i1) ) / (x(i1)-x(i1-1))\n!\t\t\tAdd area from x(i1-1) to X1\n\t\t\ttrapz2=trapz2+(x(i1)-x1)*(Y1+y(i1))/2.\n\t\t\tgoto 1\n\t\tendif\n\t\tenddo\n\tendif\n1\tif (x2 > x(n)) then\n\t\tif (jerr2.eq.0) then\n\t\t\twrite (6,*) 'TRAPZ2: X2 outside valid range:',x2,x(1),x(n),n\n\t\t\tjerr2=1\n\t\tendif\n\t\tierr=2\n\t\treturn\n!\t\tstop\n\telseif (x2 == x(n)) then\n\t\ti2 = n\n\telse\n!\t\tFind last element in array X below X2\n\t\tdo i=i1,n\n\t\tif (x(i) > x2) then\n\t\t\ti2=i-1\n!\t\t\tFind by interpolation values of Y2=y(X2)\n\t\t\tY2 = ( (x(i2+1)-x2)*y(i2) + (x2-x(i2))*y(i2+1) ) / (x(i2+1)-x(i2))\n!\t\t\tAdd area from x(i2) to X2\n\t\t\ttrapz2=trapz2+(x2-x(i2))*(Y2+y(i2))/2.\n\t\t\tgoto 2\n\t\tendif\n\t\tenddo\n\tendif\n\n!\tCompute area from x(i1) to x(i2)\n2\tdo i=i1+1,i2\n\ttrapz2=trapz2+(x(i)-x(i-1))*(y(i)+y(i-1))/2.\n\tenddo \n!\twrite (6,*) 'TRAPZ2: using = ',i1+1,i2,x(i1),x(i2),i2-i1,' points'\n\treturn\n\tend\n", "meta": {"hexsha": "37962eba3f3af0876aeea409928ba29420c436e6", "size": 1474, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "bc03/src/trapz2.f", "max_stars_repo_name": "jchavesmontero/galaxpy", "max_stars_repo_head_hexsha": "ef5eaffa8f5ec0418dae44b88cf212ca03814b57", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-10-29T02:26:52.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-15T22:22:35.000Z", "max_issues_repo_path": "bc03/src/trapz2.f", "max_issues_repo_name": "jchavesmontero/galaxpy", "max_issues_repo_head_hexsha": "ef5eaffa8f5ec0418dae44b88cf212ca03814b57", "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": "bc03/src/trapz2.f", "max_forks_repo_name": "jchavesmontero/galaxpy", "max_forks_repo_head_hexsha": "ef5eaffa8f5ec0418dae44b88cf212ca03814b57", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.3623188406, "max_line_length": 69, "alphanum_fraction": 0.5868385346, "num_tokens": 693, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256551882382, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.674043069268409}} {"text": "program problem72\n implicit none\n integer, parameter :: m=664579,limit=1000000\n integer, dimension(m) :: primes\n integer :: i\n integer*16 :: answer\n\n open(33,file='./data/problem70.dat')\n read(33,*) primes\n\n answer=0\n do i=2,limit\n answer=answer+phi(i)\n end do\n\n print *, answer\n\ncontains\n\n function phi(n)\n implicit none\n integer, intent(in) :: n\n integer :: p,phi,i,rest\n\n phi=n\n rest=n\n do i=1,n\n p=primes(i)\n if (mod(rest,p)==0) then\n phi=(phi/p)*(p-1)\n do while (mod(rest,p)==0)\n rest=rest/p\n end do\n end if\n\n ! Important: if the current prime is more than the square root\n ! of what is left, then what is left must be the last prime\n ! factor.\n if (p>sqrt(real(rest))) then\n if (rest>1) phi=(phi/rest)*(rest-1)\n exit\n end if\n end do\n\n end function phi\n\nend program problem72\n", "meta": {"hexsha": "b0fa9e60b2d4ea3cd50f1b1138388728abb44079", "size": 964, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "problem72.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": "problem72.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": "problem72.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": 20.0833333333, "max_line_length": 69, "alphanum_fraction": 0.5466804979, "num_tokens": 279, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6739923060138671}} {"text": "submodule (points) points_a\ncontains\n\nreal module function point_dist(a,b) result(dist)\n type(point), intent(in) :: a, b\n real :: dist\n dist = sqrt((a%x-b%x)**2+(a%y-b%y)**2)\nend function point_dist\n\nend submodule points_a\n", "meta": {"hexsha": "61fe6d2185e791d39da99edd53aba035d02f2b14", "size": 244, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/ex40/points_a.f90", "max_stars_repo_name": "jonaslindemann/compute-course-public", "max_stars_repo_head_hexsha": "b8f55595ebbd790d79b525efdff17b8517154796", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-09-12T12:07:01.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-29T17:38:34.000Z", "max_issues_repo_path": "fortran/ex40/points_a.f90", "max_issues_repo_name": "jonaslindemann/compute-course-public", "max_issues_repo_head_hexsha": "b8f55595ebbd790d79b525efdff17b8517154796", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/ex40/points_a.f90", "max_forks_repo_name": "jonaslindemann/compute-course-public", "max_forks_repo_head_hexsha": "b8f55595ebbd790d79b525efdff17b8517154796", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2020-10-24T16:02:31.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-28T20:57:46.000Z", "avg_line_length": 22.1818181818, "max_line_length": 49, "alphanum_fraction": 0.643442623, "num_tokens": 69, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8962513731336204, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6739923018459663}} {"text": "module forno1d\n\ncontains\n\nsubroutine calcula_perfil(Ta, T1, T2, T3, R1, R2, R3,T)\n implicit none\n\n real, intent(in) :: Ta, T1, T2, T3, R1, R2, R3\n integer, parameter :: n = 30 ! n\u00famero de elementos finitos\n real, dimension(n), intent(out) :: T\n\n real :: L, sor, dx, T_media, Tn\n integer :: p_n1, p_n2, p_n3, i, j ,k\n real, dimension(n) :: fonte\n\n L = 2.0 ! comprimento do forno em metros\n sor = 1.85 ! par\u00e2metro sor\n p_n1 = n/4 ! posi\u00e7\u00e3o do primeiro sensor de Temperatura\n p_n2 = n/2 ! segundo sensor\n p_n3 = 3*n/4 ! terceiro sensor\n\n dx = L/(n+1)\n T_media = (2*Ta + T1 + T2 + T3)/5\n\n ! valores iniciais da temperatura\n do i=1, n-1\n T(i) = T_media\n enddo\n T(1) = Ta ! tempa ambiente nas pontas (direichilet)\n T(n) = Ta ! tempa ambiente nas pontas (direichilet)\n\n ! valores da fonte\n do i=1, INT(n/3)\n fonte(i) = R1\n enddo\n do i=INT(n/3)+1, INT(2*n/3)\n fonte(i) = R2\n enddo\n do i=INT(2*n/3)+1, n\n fonte(i) = R3\n enddo\n\n\n do j=1, 200\n do i=2 , n-1\n if (i == p_n1) then\n T(i) = T1\n else if (i == p_n2) then\n T(i) = T2\n else if (i == p_n3) then\n T(i) = T3\n else\n Tn = (T(i-1) + T(i+1))/2.0 +dx*dx*fonte(i)\n T(i) = T(i) + sor*( Tn - T(i) )\n end if\n enddo\n enddo\n\nend subroutine calcula_perfil\n\n\nend module forno1d\n", "meta": {"hexsha": "5d1a865a3b98e351b33d390223c2c5f734c50a14", "size": 1497, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/simulacao/forno1d.f90", "max_stars_repo_name": "Atzingen/controleForno-interface", "max_stars_repo_head_hexsha": "6a8968527f8b76c7d0c7ea26f8c8aca728fe4d2d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source/simulacao/forno1d.f90", "max_issues_repo_name": "Atzingen/controleForno-interface", "max_issues_repo_head_hexsha": "6a8968527f8b76c7d0c7ea26f8c8aca728fe4d2d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2016-09-06T15:54:00.000Z", "max_issues_repo_issues_event_max_datetime": "2016-09-15T15:05:41.000Z", "max_forks_repo_path": "source/simulacao/forno1d.f90", "max_forks_repo_name": "Atzingen/controleForno-interface", "max_forks_repo_head_hexsha": "6a8968527f8b76c7d0c7ea26f8c8aca728fe4d2d", "max_forks_repo_licenses": ["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.7619047619, "max_line_length": 64, "alphanum_fraction": 0.4976619906, "num_tokens": 562, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513648201266, "lm_q2_score": 0.7520125793176223, "lm_q1q2_score": 0.6739923005753227}} {"text": "program phase_iterative\n implicit none\n\n!! # Grid parameters\n integer maxmx, maxmy\n parameter(maxmx = 2**10, maxmy = 2**10)\n\n\n!! # Input parameters\n double precision ax_in, ay_in, dx_in, dy_in, t_in, tstart\n double precision domain_length\n integer mx_in, my_in, nstp, izero, nchar\n character*100 fname\n logical restart\n\n double precision phi(maxmx, maxmy)\n double precision u(maxmx, maxmy)\n double precision theta, r, rp, amp\n\n!! # More grid parameters\n integer mx, my, i, j, n, nout, nstep\n double precision ax, ay, bx, by, dx, dy, dt, tfinal, t\n double precision x(maxmx), y(maxmy)\n\n!! # Misc\n integer iframe, iframe_start\n double precision pi, dsgn\n\n integer mbdcnd, nbdcnd, ierror, idimf\n double precision lambda, lambda_phi, pertrb\n double precision bda(maxmy), bdb(maxmy)\n double precision bdc(maxmx), bdd(maxmx)\n double precision f(maxmx, maxmy)\n\n!! # Temporary variables\n double precision u_n, phi_n, g0, g\n\n double precision phik(maxmx, maxmy)\n double precision uk(maxmx, maxmy)\n double precision phikp1(maxmx, maxmy)\n double precision ukp1(maxmx, maxmy)\n\n double precision f1(maxmx, maxmy)\n double precision f2(maxmx, maxmy)\n double precision S1(maxmx, maxmy)\n double precision S2(maxmx, maxmy)\n double precision S3(maxmx, maxmy)\n double precision err(2), errmax(2), tol\n\n!! # Model parameters\n double precision S, alpha, mparm, xi, gamma\n\n double precision r0, x0, y0, kanio, pdel\n common /parm_comm/ r0, x0, y0, kanio, pdel\n\n !! Temporary variables\n double precision beta, Tinv\n\n integer wsize, wsize_t\n!! 13M + 4N + M*INT(LOG2(N))\n!! log2(N) <= log2(maxmy) ~ 10\n parameter(wsize = 4*maxmy + (13 + 12)*maxmx)\n double precision work(wsize)\n\n double precision xlow, ylow, w\n\n integer k, kmax, ktotal, avg_iterations, method\n logical prt_iterations\n integer jacobi, gauss_seidel\n parameter(jacobi=0, gauss_seidel=1)\n\n wsize_t = 4*(maxmy) + & \n (13 + int(log(real(my))/log(2.d0))*mx)\n if (wsize < wsize_t) then\n write(6,*) 'Increase wsize from ', wsize, ' to ',wsize_t\n stop\n endif\n pi = 4.d0*datan(1.d0)\n\n\n!! # --------------------------------\n!! # Set up grid\n!! # --------------------------------\n\n open(10,file='phase_iterative.dat')\n read(10,*) mx, my\n!! read(10,*) ax, bx, ay, by\n read(10,*) domain_length\n read(10,*) nstep, nout\n read(10,*) dt\n\n if (mx > maxmx .or. my > maxmy) then\n write(6,*) 'mx or my too big'\n stop\n endif\n\n ax = -domain_length/2\n bx = domain_length/2\n ay = -domain_length/2\n by = domain_length/2\n\n\n dx = (bx - ax)/mx\n dy = (by - ay)/my\n\n do i = 1,mx\n x(i) = ax + (i-0.5)*dx\n enddo\n\n do j = 1,my\n y(j) = ay + (j-0.5)*dy\n enddo\n\n\n!! # ------------------------------------\n!! # Numerical parameters - Jacobi method\n!! # ------------------------------------\n read(10,*) kmax\n read(10,*) tol\n read(10,*) method\n read(10,*) prt_iterations\n\n!! # ----------------------------\n!! # model parameters\n!! # ----------------------------\n read(10,*) S\n read(10,*) alpha\n read(10,*) mparm\n read(10,*) xi\n read(10,*) kanio\n read(10,*) r0\n read(10,*) pdel\n read(10,*) gamma\n\n!! # ----------------------------\n!! # Get restart information\n!! # ----------------------------\n read(10,*) restart\n if (restart) then\n read(10,*) fname\n endif\n close(10)\n\n write(6,*) 'Parameters used for this run : '\n write(6,*) '---------------------------'\n write(6,*) 'Non-dimensional parameters'\n write(6,*) '---------------------------'\n write(6,200) 'S = ', S\n write(6,200) 'alpha = ', alpha\n write(6,200) 'm = ', mparm\n write(6,200) 'xi = ', xi\n write(6,200) 'k = ', kanio\n write(6,200) 'r0 = ', r0\n write(6,200) 'pdel = ', pdel\n write(6,200) 'gamma = ', gamma\n write(6,*) ' '\n write(6,*) '---------------------------'\n write(6,*) 'Grid parameters'\n write(6,*) '---------------------------'\n write(6,220) 'mx = ', mx\n write(6,220) 'my = ', my\n write(6,200) 'ax = ', ax\n write(6,200) 'bx = ', bx\n write(6,200) 'ay = ', ay\n write(6,200) 'by = ', by\n write(6,200) 'dx = ', dx\n write(6,200) 'dy = ', dy\n write(6,220) 'kmax = ',kmax\n write(6,225) 'tol = ',tol\n\n if (restart) then\n write(6,*) 'Restart from file ', fname\n else\n write(6,*) 'Initializing run from scratch...'\n endif\n\n 200 format(a,F10.5)\n 210 format(a,E12.6)\n 225 format(a,E12.1)\n 220 format(a,I5)\n\n!! # --------------------------------\n!! # Initialize phi\n!! # --------------------------------\n write(6,*) 'Initializing phi and u...'\n\n if (restart) then\n open(20,file=fname)\n read(20,*) mx_in\n read(20,*) my_in\n read(20,*) ax_in\n read(20,*) ay_in\n read(20,*) dx_in\n read(20,*) dy_in\n read(20,*) t_in\n\n if (mx_in .ne. mx .or. my_in .ne. my) then\n write(6,*) 'Problem with restart: mx or my not right.'\n stop\n elseif (ax_in .ne. ax .or. ay_in .ne. ay) then\n write(6,*) 'Problem with restart: ax or ay not right'\n stop\n endif\n izero = iachar('0')\n tstart = t_in\n iframe_start = 0\n nstp = 1\n do i = 10,7,-1\n nchar = iachar(fname(i:i)) - izero\n iframe_start = iframe_start + nchar*nstp\n nstp = nstp*10\n enddo\n\n do j = 1,my\n do i = 1,mx\n read(20,*) phi(i,j), u(i,j)\n enddo\n enddo\n close(20)\n else\n\n x0 = (ax + bx)/2.d0\n y0 = (ay + by)/2.d0\n tstart = 0.0\n iframe = 0\n do j = 1,my\n do i = 1,mx\n xlow = ax + (i-1)*dx\n ylow = ay + (j-1)*dy\n!! rp = sqrt((xlow)**2 + (ylow)**2)\n \n call cellave(xlow,ylow,dx,dy,w)\n u(i,j) = w-1.d0\n phi(i,j) = 1-w\n\n!! r = sqrt((amp*(x(i) - x0))**2 + (y(j) - y0)**2)\n!! theta = atan2(y(j) - y0,x(i) - x0)\n!! rp = r0*(1.d0 + pdel*cos(kanio*theta))\n!! d = tanh((r-rp)/xi)\n!! u(i,j) = -0.5d0*(d + 1) !! In [-1,0]\n!! phi(i,j) = 0 0.5d0*(d + 1) !! In [0,1]\n enddo\n enddo\n write(6,*) 'Done with initialization'\n\n!! # Output frame only if we have initialized data from scratch.\n write(6,600) 0,tstart,0\n call out2(maxmx,maxmy,mx,my,ax,ay,dx,dy,phi,u,tstart, & \n iframe_start)\n endif\n\n\n !! % --------------------------------------\n !! % Time step through results\n !! % --------------------------------------\n\n do j = 1,my\n bda(j) = 0.d0\n bdb(j) = 0.d0\n enddo\n\n do i = 1,mx\n bdc(i) = 0.d0\n bdd(i) = 0.d0\n enddo\n\n lambda = -1.d0/dt\n idimf = maxmx\n mbdcnd = 3\n nbdcnd = 3\n\n beta = xi**2/mparm\n Tinv = 1.d0/xi**2\n lambda_phi = lambda*beta*Tinv\n\n avg_iterations = 0\n iframe = iframe_start\n do n = 1,nout\n t = tstart + n*dt\n\n !! write(6,100) n,t\n100 format('Step',I5,' at time t = ',1PE12.5)\n\n !! From right hand side for block linear system\n do j = 1,my\n do i = 1,mx\n phi_n = phi(i,j) !! old phi(i,j)\n u_n = u(i,j)\n\n g0 = phi_n*(1-phi_n)\n g = g0*g0\n\n S1(i,j) = 30*g/S\n S2(i,j) = 30*g*xi*alpha*S\n S3(i,j) = g0*(phi_n - 0.5d0)\n\n f1(i,j) = lambda*(u_n + S1(i,j)*phi_n);\n f2(i,j) = lambda*beta*phi_n - S3(i,j)\n end do\n end do\n\n !! # Start Jacobi iterations\n do j = 1,my\n do i = 1,mx\n uk(i,j) = u(i,j)\n phik(i,j) = phi(i,j)\n end do\n end do\n do k = 1,kmax\n\n !! ----------------------------------------------\n !! # Set up right hand side for u\n !! ----------------------------------------------\n do j = 1,my\n do i = 1,mx\n !! this could be computed outside of k-loop\n!! phi_n = phi(i,j)\n!! g0 = phi_n*(1-phi_n)\n!! g = g0*g0\n!! S1 = 30*g/S\n\n f(i,j) = -lambda*S1(i,j)*phik(i,j) + f1(i,j)\n end do\n end do\n\n !! # Solve equation for u; solution will be in f \n call hstcrt(ax,bx,mx,mbdcnd,bda,bdb,ay,by,my,nbdcnd, & \n bdc,bdd,lambda,f,idimf,pertrb,ierror,work)\n\n if (work(1) .gt. wsize) then\n write(6,*) 'hstcrt : Allocate more work for wsize; ', wsize, work(1)\n endif\n\n if (ierror .ne. 0) then\n write(6,*) 'hstcrt : ierror /= 0', ierror\n stop\n endif\n\n if (abs(pertrb) .gt. 0) then\n write(6,*) 'pertrb > 0; ', pertrb\n stop\n endif\n\n do j = 1,my\n do i = 1,mx\n ukp1(i,j) = f(i,j)\n end do\n end do\n\n\n !! ----------------------------------------------\n !! Set-up right hand side for phi\n !! ----------------------------------------------\n do j = 1,my\n do i = 1,mx\n!! u_n = u(i,j)\n!! phi_n = phi(i,j)\n!! g0 = phi_n*(1-phi_n)\n!! g = g0*g0\n!! S2 = 30*g*xi*alpha*S\n if (method .eq. jacobi) then\n f(i,j) = Tinv*(-S2(i,j)*uk(i,j) + f2(i,j))\n else\n f(i,j) = Tinv*(-S2(i,j)*ukp1(i,j) + f2(i,j))\n endif\n end do\n end do\n\n !! # Solve equation for phi; solution will be in f\n call hstcrt(ax,bx,mx,mbdcnd,bda,bdb,ay,by,my,nbdcnd, & \n bdc,bdd,lambda_phi,f,idimf,pertrb,ierror,work)\n\n if (ierror .ne. 0) then\n write(6,*) 'hstcrt : ierror /= 0; ', ierror\n stop\n endif\n\n do j = 1,my\n do i = 1,mx\n phikp1(i,j) = f(i,j)\n end do\n end do\n\n errmax(1) = 0\n errmax(2) = 0\n do j = 1,my\n do i = 1,mx\n err(1) = abs(ukp1(i,j) - uk(i,j))\n err(2) = abs(phikp1(i,j) - phik(i,j))\n errmax(1) = max(errmax(1),err(1))\n errmax(2) = max(errmax(2),err(2))\n end do\n end do\n if (prt_iterations) then\n!! write(6,601) 'Step ', n, 'Iteration ',k,'Residual(u)', errmax(1), & \n!! 'Residual(phi)', errmax(2)\n endif \n ktotal = k\n if (max(errmax(1), errmax(2)) < tol) then\n exit !! Exit Jacobi iteration\n endif\n\n !! Swap k and kp1\n do j = 1,my\n do i = 1,mx\n uk(i,j) = ukp1(i,j)\n phik(i,j) = phikp1(i,j)\n end do\n end do\n\n\n !! end of Jacobi iteration\n end do\n if (prt_iterations) then\n write(6,601) 'Step ', n, 'Iterations/step ',ktotal,'Residual(u)', errmax(1), & \n 'Residual(phi)', errmax(2)\n!! write(6,*) ' '\n endif\n avg_iterations = avg_iterations + ktotal \n\n !! # ---------------------------------\n !! # Output results\n !! # ---------------------------------\n\n\n if (nstep*(n/nstep) == n) then\n iframe = iframe + 1\n write(6,600) iframe, t, avg_iterations/nstep\n call out2(maxmx,maxmy,mx,my,ax,ay,dx,dy,phi,u,t,iframe)\n avg_iterations = 0\n endif\n\n600 format('Writing frame ',I5,' at time t = ',1PE12.5,' (avg. iterations = ',I3,')')\n601 format(A,I5,A20,I4,A15,E12.4,A15,E12.4) \n\n !! Update time level n solutions\n do j = 1,my\n do i = 1,mx\n u(i,j) = ukp1(i,j)\n phi(i,j) = phikp1(i,j)\n end do\n end do\n\n\n !! End of time loop\n end do \n\nend program phase_iterative\n\ndouble precision function fdisc(x,y)\n implicit none\n\n double precision x,y, r, rp, theta\n\n double precision r0, x0, y0, kanio, pdel\n common /parm_comm/ r0, x0, y0, kanio, pdel\n\n r = sqrt((x-x0)**2 + (y-y0)**2)\n theta = atan2(y - y0,x - x0)\n rp = r0*(1.d0 + pdel*cos(kanio*theta))\n fdisc = r - rp\n\nend function fdisc\n", "meta": {"hexsha": "13eae360a390429df695c5684fc59d0a18b273c1", "size": 12883, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "applications/elliptic/phasefield/fishpack/phase_iterative.f90", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2017-09-26T13:39:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:56:23.000Z", "max_issues_repo_path": "applications/elliptic/phasefield/fishpack/phase_iterative.f90", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 75, "max_issues_repo_issues_event_min_datetime": "2017-08-02T19:56:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T12:36:32.000Z", "max_forks_repo_path": "applications/elliptic/phasefield/fishpack/phase_iterative.f90", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-02-21T00:10:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T19:08:36.000Z", "avg_line_length": 27.7650862069, "max_line_length": 91, "alphanum_fraction": 0.4353023364, "num_tokens": 4034, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336204, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6739922968647579}} {"text": "program prog\r\n use variables\r\n use constants\r\n\r\n call InitiliseVariables\r\n call InitFields\r\n \r\n \r\n \r\n call UVSolver \r\n \r\n call DestroyVariables \r\n \r\nend program prog\r\n!-------------------------------------!\r\n! Setting boundary condition for UV !\r\n!-------------------------------------!\r\nsubroutine InitFields\r\n use variables\r\n use constants\r\n \r\n do i=1,MaxN\r\n aUx1(i)=0.0\r\n bUx1(i)=0.0\r\n aUx2(i)=0.0\r\n bUx2(i)=0.0\r\n \r\n aUy1(i)=0.0\r\n bUy1(i)=0.0\r\n aUy2(i)=0.0\r\n bUy2(i)=1.0\r\n \r\n aVx1(i)=0.0\r\n bVx1(i)=0.0\r\n aVx2(i)=0.0\r\n bVx2(i)=0.0\r\n \r\n aVy1(i)=0.0\r\n bVy1(i)=0.0\r\n aVy2(i)=0.0\r\n bVy2(i)=0.0\r\n \r\n enddo\r\n \r\n \r\n \r\n do i=0,MaxN+1\r\n do j=0,MaxN+1\r\n u(i,j)=0.0\r\n v(i,j)=0.0\r\n p(i,j)=0.0\r\n Uo12(i,j)=0.0\r\n Uon(i,j)=0.0\r\n Vo12(i,j)=0.0\r\n Von(i,j)=0.0\r\n enddo\r\n enddo\r\n ! forall (j=1:MaxN) u(0,j)=1.0\r\nend subroutine InitFields\r\n!-------------------------------------!\r\n! Run solver for velocity !\r\n! Rouch 140 stranica !\r\n!-------------------------------------!\r\nsubroutine UVSolver\r\n use variables\r\n use constants\r\n real, dimension(0:MaxN) :: A \r\n real, dimension(0:MaxN) :: B\r\n real, dimension(0:MaxN) :: C\r\n real, dimension(0:MaxN) :: F\r\n real, dimension(1:MaxN) :: X\r\n integer :: i,j,k\r\n integer :: printtime\r\n do iter=1,MaxTime\r\n\t!*************** U po x \r\n\t do j=1,MaxN\r\n\t\t do i=1,MaxN\r\n A(i) = -(-u(i,j)*addx(i,j) + ad2dx2(i,j)/Re)\r\n B(i) = -(-u(i,j)*bddx(i,j) + bd2dx2(i,j)/Re) + 2.0/dt\r\n C(i) = -(-u(i,j)*cddx(i,j) + cd2dx2(i,j)/Re)\r\n F(i) =(-v(i,j)*dudy(i,j,0) + d2udy2(i,j,0)/Re) + 2.0*u(i,j)/dt\r\n enddo\r\n A(0)=aUx1(j)\r\n B(0)=bUx1(j)\r\n C(0)=aUx2(j)\r\n F(0)=bUx2(j) \r\n\t\t call sweepF(A,B,C,F,X)\r\n forall (i=1:MaxN)\tUo12(i,j)=X(i) \r\n enddo\r\n! forall (i=1:MaxN, j=1:MaxN) u(i,j)=Uo12(i,j)\r\n! call WriteFile(VarU,Iter+MaxTime)\r\n\t!*************** U po y \r\n\t do i=1,MaxN\r\n\t\t do j=1,MaxN\r\n A(j) = -(-v(i,j)*addy(i,j) + ad2dy2(i,j)/Re)\r\n B(j) = -(-v(i,j)*bddy(i,j) + bd2dy2(i,j)/Re) + 2.0/dt\r\n C(j) = -(-v(i,j)*cddy(i,j) + cd2dy2(i,j)/Re)\r\n F(j) =(-u(i,j)*dudx(i,j,1) + d2udx2(i,j,1)/Re) + 2.0*Uo12(i,j)/dt\r\n enddo\r\n A(0)=aUy1(i)\r\n B(0)=bUy1(i)\r\n C(0)=aUy2(i)\r\n F(0)=bUy2(i)\r\n \t call sweepF(A,B,C,F,X)\r\n forall (j=1:MaxN) Uon(i,j)=X(j)\r\n enddo\r\n!\tforall (i=1:MaxN, j=1:MaxN) u(i,j)=Uo23(i,j)\r\n\t!*************** V po x \r\n\t do j=1,MaxN\r\n\t\t do i=1,MaxN\r\n A(i) = -(-u(i,j)*addx(i,j) + ad2dx2(i,j)/Re)\r\n B(i) = -(-u(i,j)*bddx(i,j) + bd2dx2(i,j)/Re) + 2.0/dt\r\n C(i) = -(-u(i,j)*cddx(i,j) + cd2dx2(i,j)/Re)\r\n F(i) =(-v(i,j)*dvdy(i,j,0) + d2vdy2(i,j,0)/Re) + 2.0*v(i,j)/dt\r\n enddo\r\n A(0)=aVx1(j)\r\n B(0)=bVx1(j)\r\n C(0)=aVx2(j)\r\n F(0)=bVx2(j)\r\n\t\t call sweepF(A,B,C,F,X)\r\n forall (i=1:MaxN)\tVo12(i,j)=X(i) \r\n enddo\r\n\tforall (i=1:MaxN, j=1:MaxN) v(i,j)=Vo12(i,j)\r\n\t!************** V po y\r\n\t do i=1,MaxN\r\n\t\t do j=1,MaxN\r\n A(j) = -(-v(i,j)*addy(i,j) + ad2dy2(i,j)/Re)\r\n B(j) = -(-v(i,j)*bddy(i,j) + bd2dy2(i,j)/Re) + 2.0/dt\r\n C(j) = -(-v(i,j)*cddy(i,j) + cd2dy2(i,j)/Re)\r\n F(j) =(-u(i,j)*dvdx(i,j,1) + d2vdx2(i,j,1)/Re) + 2.0*Vo12(i,j)/dt\r\n enddo\r\n A(0)=aVy1(i)\r\n B(0)=bVy1(i)\r\n C(0)=aVy2(i)\r\n F(0)=bVy2(i)\r\n\t\t call sweepF(A,B,C,F,X)\r\n forall (j=1:MaxN) Von(i,j)=X(j)\r\n enddo\r\n! forall (i=1:MaxN, j=1:MaxN) v(i,j)=Vo23(i,j)\r\n! forall (i=1:MaxN, j=1:MaxN) u(i,j)=Uo23(i,j)\r\n call Poisson_2D\r\n do j=1,MaxN\r\n do i=2,MaxN-1\r\n u(i,j)=Uon(i,j)-dt*(p(i,j)-p(i-1,j))/dx\r\n \r\n enddo\r\n enddo\r\n do i=1,MaxN\r\n do j=2,MaxN-1\r\n v(i,j)=Von(i,j)-dt*(p(i,j)-p(i,j-1))/dy\r\n enddo\r\n enddo\r\n \r\n! call WriteFile(VarU,Iter)\r\n! call WriteFile(VarV,Iter)\r\n if (Mod(Iter,PrintEvery).eq.0) then\r\n WRITE(*,*) 'Time: ', Iter\r\n printtime=Iter/PrintEvery\r\n call WriteIter(printtime)\r\n endif\r\n enddo\r\nend subroutine UVSolver\r\n!-------------------------------------!\r\n! Thomas method !\r\n!-------------------------------------!\r\nsubroutine sweepF(A,B,C,F,X) \r\n use variables\r\n use constants\r\n real :: A(0:MaxN),B(0:MaxN),C(0:MaxN),F(0:MaxN)\r\n real :: X(1:MaxN)\r\n integer :: I\r\n real :: alfa(MaxN+1),beta(MaxN+1)\r\n real :: temp\r\n alfa(MaxN)=C(0)\r\n beta(MaxN)=F(0)\r\n do I=MaxN-1,1,-1\r\n temp =(B(I)+A(I)*alfa(I+1))\r\n \r\n alfa(I)=-C(I)/temp\r\n beta(I)=(F(I)-A(I)*beta(I+1))/temp\r\n enddo\r\n X(1)=(alfa(1)*B(0)+beta(1))/(1.0-alfa(1)*A(0))\r\n do I=1, MaxN-1\r\n X(I+1)=alfa(I+1)*X(I)+beta(I+1)\r\n enddo\r\nend subroutine sweepF\r\n\r\nsubroutine sweepB(A,B,C,F,X) \r\n use variables\r\n use constants\r\n real :: A(0:MaxN),B(0:MaxN),C(0:MaxN),F(0:MaxN)\r\n real :: X(1:MaxN)\r\n integer :: I,M\r\n real :: alfa(MaxN+1),beta(MaxN+1)\r\n alfa(1)=A(0)\r\n beta(1)=B(0)\r\n do I=1,MaxN-1\r\n alfa(I+1)=-C(I)/(B(I)+A(I)*alfa(I) )\r\n beta(I+1)=(F(I)-A(I)*beta(I))/(B(I)+A(I)*alfa(I))\r\n enddo\r\n X(MaxN)=(F(0)+C(0)*beta(MaxN))/(1-C(0)*alfa(MaxN))\r\n do I=MaxN-1,1,-1\r\n X(I)=alfa(I+1)*X(I+1)+beta(I+1)\r\n enddo\r\nend subroutine sweepB\r\n\r\n! elseif (ProblemDim.eq.3D) then\r\n!\r\n! dudx(i,j,k) = (u(i+1,j,k)-u(i-1,j,k))/(2.0*dx)\r\n! dvdx(i,j,k) = (v(i+1,j,k)-v(i-1,j,k))/(2.0*dx)\r\n! dwdx(i,j,k) = (w(i+1,j,k)-w(i-1,j,k))/(2.0*dx)\r\n!\r\n! dudy(i,j,k) = (u(i,j+1,k)-u(i,j-1,k))/(2.0*dy)\r\n! dvdy(i,j,k) = (v(i,j+1,k)-v(i,j-1,k))/(2.0*dy)\r\n! dwdy(i,j,k) = (w(i,j+1,k)-w(i,j-1,k))/(2.0*dy)\r\n!\r\n! dudz(i,j,k) = (u(i,j,k+1)-u(i,j,k-1))/(2.0*dz)\r\n! dvdz(i,j,k) = (v(i,j,k+1)-v(i,j,k-1))/(2.0*dz)\r\n! dwdz(i,j,k) = (w(i,j,k+1)-w(i,j,k-1))/(2.0*dz)\r\n!\r\n! d2udx2(i,j,k) = (u(i+1,j,k)-2.0*u(i,j,k)+u(i-1,j,k))/(2.0*dx*dx)\r\n! d2vdx2(i,j,k) = (v(i+1,j,k)-2.0*v(i,j,k)+v(i-1,j,k))/(2.0*dx*dx)\r\n! d2wdx2(i,j,k) = (w(i+1,j,k)-2.0*w(i,j,k)+w(i-1,j,k))/(2.0*dx*dx)\r\n!\r\n! d2udy2(i,j,k) = (u(i,j+1,k)-2.0*u(i,j,k)+u(i,j-1,k))/(2.0*dy*dy)\r\n! d2vdy2(i,j,k) = (v(i,j+1,k)-2.0*v(i,j,k)+v(i,j-1,k))/(2.0*dy*dy)\r\n! d2wdy2(i,j,k) = (w(i,j+1,k)-2.0*w(i,j,k)+w(i,j-1,k))/(2.0*dy*dy)\r\n!\r\n! d2udz2(i,j,k) = (u(i,j,k+1)-2.0*u(i,j,k)+u(i,j,k-1))/(2.0*dz*dz)\r\n! d2vdz2(i,j,k) = (v(i,j,k+1)-2.0*v(i,j,k)+v(i,j,k-1))/(2.0*dz*dz)\r\n! d2wdz2(i,j,k) = (w(i,j,k+1)-2.0*w(i,j,k)+w(i,j,k-1))/(2.0*dz*dz)\r\n! endif\r\n!--------------------------------------------!\r\n! Koefficienti of raznosti protiv potoka 2 !\r\n!--------------------------------------------!\r\n\r\n\r\n\r\nsubroutine WriteFile(TVar,Num)\r\n use variables\r\n use constants\r\n Character(LEN=15) :: FName\r\n Integer :: TVar\r\n Integer :: Num\r\n If (TVar.eq.VarU) then\r\n Write(FName,\"(A,I5.5,A)\") 'U',Num,'.dat'\r\n else\r\n Write(FName,\"(A,I5.5,A)\") 'V',Num,'.dat'\r\n endif\r\n \r\n open(TVar,file=trim(adjustl(FName)))\r\n write(TVar,*) 'TITLE = \"Example: Simple 2D-Plane Data\"'\r\n write(TVar,*) 'VARIABLES = \"X\", \"Y\", \"Var\"'\r\n write(TVar,*) 'ZONE I=',MaxN,' J=',MaxN,' F=POINT'\r\n do i=1,MaxN\r\n do j=1,MaxN\r\n if (TVar.eq.VarU) then\r\n write(TVar,*) i,j,u(i,j)\r\n elseif (TVar.eq.VarV) then\r\n write(TVar,*) i,j,v(i,j)\r\n! else\r\n! write(1,*) i,j,p(i,j)\r\n endif\r\n enddo\r\n enddo\r\n close(TVar) \r\nend subroutine WriteFile\r\nsubroutine WriteIter(Num)\r\n use variables\r\n use constants\r\n Character(LEN=15) :: FName\r\n Integer :: TVar=10\r\n Integer :: Num\r\n Write(FName,\"(A,I5.5,A)\") 'Out',Num,'.dat'\r\n \r\n open(TVar,file=trim(adjustl(FName)))\r\n write(TVar,*) 'TITLE = \"Example: Simple 2D-Plane Data\"'\r\n write(TVar,*) 'VARIABLES = \"X\", \"Y\", \"U\", \"V\"'\r\n write(TVar,*) 'ZONE I=',MaxN,' J=',MaxN,' F=POINT'\r\n do i=1,MaxN\r\n do j=1,MaxN\r\n write(TVar,*) i,j,u(i,j),v(i,j)\r\n enddo\r\n enddo\r\n close(TVar) \r\nend subroutine WriteIter\r\n\r\n!-------------------------------------!\r\n! Set Variables !\r\n!-------------------------------------!\r\nsubroutine InitiliseVariables\r\n use variables\r\n use constants\r\n \r\n allocate(P(0:MaxN+1,0:MaxN+1),STAT=istat) \r\n if (istat.ne.0) write(*,*) \"**** Not enough memory to allocate P ****\" \r\n \r\n allocate(aUx1(1:MaxN),STAT=istat)\r\n allocate(bUx1(1:MaxN),STAT=istat)\r\n allocate(aUx2(1:MaxN),STAT=istat)\r\n allocate(bUx2(1:MaxN),STAT=istat)\r\n allocate(aUy1(1:MaxN),STAT=istat)\r\n allocate(bUy1(1:MaxN),STAT=istat)\r\n allocate(aUy2(1:MaxN),STAT=istat)\r\n allocate(bUy2(1:MaxN),STAT=istat)\r\n \r\n allocate(aVx1(1:MaxN),STAT=istat)\r\n allocate(bVx1(1:MaxN),STAT=istat)\r\n allocate(aVx2(1:MaxN),STAT=istat)\r\n allocate(bVx2(1:MaxN),STAT=istat)\r\n allocate(aVy1(1:MaxN),STAT=istat)\r\n allocate(bVy1(1:MaxN),STAT=istat)\r\n allocate(aVy2(1:MaxN),STAT=istat)\r\n allocate(bVy2(1:MaxN),STAT=istat)\r\n \r\n allocate(U(0:MaxN+1,0:MaxN+1),STAT=istat) \r\n if (istat.ne.0) write(*,*) \"**** Not enough memory to allocate U ****\"\r\n allocate(V(0:MaxN+1,0:MaxN+1),STAT=istat) \r\n if (istat.ne.0) write(*,*) \"**** Not enough memory to allocate V ****\"\r\n allocate(Uon(0:MaxN+1,0:MaxN+1),STAT=istat) \r\n if (istat.ne.0) write(*,*) \"**** Not enough memory to allocate Uon1 ****\"\r\n allocate(Von(0:MaxN+1,0:MaxN+1),STAT=istat) \r\n if (istat.ne.0) write(*,*) \"**** Not enough memory to allocate Von1 ****\"\r\n\r\n allocate(Uo12(0:MaxN+1,0:MaxN+1),STAT=istat) \r\n if (istat.ne.0) write(*,*) \"**** Not enough memory to allocate Uo13 ****\"\r\n allocate(Vo12(0:MaxN+1,0:MaxN+1),STAT=istat) \r\n if (istat.ne.0) write(*,*) \"**** Not enough memory to allocate Vo13 ****\"\r\nend subroutine InitiliseVariables\r\n!-------------------------------------!\r\n! Destroy Variables !\r\n!-------------------------------------!\r\nsubroutine DestroyVariables\r\n use variables\r\n use constants\r\n \r\n deallocate(P,STAT=istat) \r\n if (istat.ne.0) write(*,*) \"**** Can't deallocate P ****\"\r\n \r\n deallocate(aUx1,STAT=istat)\r\n deallocate(bUx1,STAT=istat)\r\n deallocate(aUx2,STAT=istat)\r\n deallocate(bUx2,STAT=istat)\r\n deallocate(aUy1,STAT=istat)\r\n deallocate(bUy1,STAT=istat)\r\n deallocate(aUy2,STAT=istat)\r\n deallocate(bUy2,STAT=istat)\r\n \r\n deallocate(aVx1,STAT=istat)\r\n deallocate(bVx1,STAT=istat)\r\n deallocate(aVx2,STAT=istat)\r\n deallocate(bVx2,STAT=istat)\r\n deallocate(aVy1,STAT=istat)\r\n deallocate(bVy1,STAT=istat)\r\n deallocate(aVy2,STAT=istat)\r\n deallocate(bVy2,STAT=istat)\r\n \r\n deallocate(U,STAT=istat) \r\n if (istat.ne.0) write(*,*) \"**** Can't deallocate U ****\"\r\n deallocate(V,STAT=istat) \r\n if (istat.ne.0) write(*,*) \"**** Can't deallocate V ****\"\r\n deallocate(Uon,STAT=istat) \r\n if (istat.ne.0) write(*,*) \"**** Can't deallocate Uon1 ****\"\r\n deallocate(Von,STAT=istat) \r\n if (istat.ne.0) write(*,*) \"**** Can't deallocate Von1 ****\"\r\n\r\n deallocate(Uo12,STAT=istat) \r\n if (istat.ne.0) write(*,*) \"**** Can't deallocate Uo13 ****\"\r\n deallocate(Vo12,STAT=istat) \r\n if (istat.ne.0) write(*,*) \"**** Can't deallocate Vo13 ****\"\r\nend subroutine DestroyVariables\r\n", "meta": {"hexsha": "9105b6b6d8d9e1f128f47d7ee10b9fd5c3780256", "size": 11483, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ConsoleApp.f90", "max_stars_repo_name": "Abugamil/Navier-Stocks-2D", "max_stars_repo_head_hexsha": "d650297402de96b262b85e97f39457dac9ea8110", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ConsoleApp.f90", "max_issues_repo_name": "Abugamil/Navier-Stocks-2D", "max_issues_repo_head_hexsha": "d650297402de96b262b85e97f39457dac9ea8110", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ConsoleApp.f90", "max_forks_repo_name": "Abugamil/Navier-Stocks-2D", "max_forks_repo_head_hexsha": "d650297402de96b262b85e97f39457dac9ea8110", "max_forks_repo_licenses": ["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.8682795699, "max_line_length": 78, "alphanum_fraction": 0.4786205695, "num_tokens": 4579, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513620489619, "lm_q2_score": 0.7520125737597974, "lm_q1q2_score": 0.6739922935101639}} {"text": " real function resc(xmin1,xmax1,xmin2,xmax2,x111)\nC%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nC %\nC Copyright (C) 1996, The Board of Trustees of the Leland Stanford %\nC Junior University. All rights reserved. %\nC %\nC The programs in GSLIB are distributed in the hope that they will be %\nC useful, but WITHOUT ANY WARRANTY. No author or distributor accepts %\nC responsibility to anyone for the consequences of using them or for %\nC whether they serve any particular purpose or work at all, unless he %\nC says so in writing. Everyone is granted permission to copy, modify %\nC and redistribute the programs in GSLIB, but only under the condition %\nC that this notice and the above copyright notice remain intact. %\nC %\nC%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n real*8 rsc\nc\nc Simple linear rescaling (get a value in coordinate system \"2\" given\nc a value in \"1\"):\nc\n rsc = dble((xmax2-xmin2)/(xmax1-xmin1))\n resc = xmin2 + real( dble(x111 - xmin1) * rsc )\n return\n end\n", "meta": {"hexsha": "a9b231d34a3e31832c025cd78ec0d155dbb7bafe", "size": 1311, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "visim/visim_src/gslib/resc.f", "max_stars_repo_name": "fcecinati/QUICS_UOB", "max_stars_repo_head_hexsha": "88cc8534a304520f5b25f84f4516712befaf13b3", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-06T01:43:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-06T01:43:12.000Z", "max_issues_repo_path": "visim/visim_src/gslib/resc.f", "max_issues_repo_name": "fcecinati/QUICS_UOB", "max_issues_repo_head_hexsha": "88cc8534a304520f5b25f84f4516712befaf13b3", "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": "visim/visim_src/gslib/resc.f", "max_forks_repo_name": "fcecinati/QUICS_UOB", "max_forks_repo_head_hexsha": "88cc8534a304520f5b25f84f4516712befaf13b3", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-10-07T17:56:00.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-19T23:43:04.000Z", "avg_line_length": 52.44, "max_line_length": 72, "alphanum_fraction": 0.5049580473, "num_tokens": 259, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513620489619, "lm_q2_score": 0.752012562644147, "lm_q1q2_score": 0.673992283547747}} {"text": "!---------------------------------------------------!\n! Copyright (c) 2017 Shunsuke A. Sato !\n! Released under the MIT license !\n! https://opensource.org/licenses/mit-license.php !\n!---------------------------------------------------!\nsubroutine dt_evolve\n use global_variables\n implicit none\n integer :: it\n\n\n call laplacian_Ez\n Ez_new = 2d0*eps/dt**2*Ez - (eps/dt**2 - 2d0*pi*sigma/dt)*Ez_old + clight**2*LapEz\n Ez_new = Ez_new/(eps/dt**2 + 2d0*pi*sigma/dt)\n \n Ez_old = Ez\n Ez = Ez_new\n\n contains\n subroutine laplacian_Ez\n implicit none\n integer :: ix\n \n LapEz(NX_L) = (0d0 - 2d0*Ez(Nx_L) + Ez(Nx_L+1) )/Hx**2\n do ix = Nx_L + 1, Nx_R -1\n LapEz(ix) = (Ez(ix-1) - 2d0*Ez(ix) + Ez(ix+1) )/Hx**2\n end do\n\n LapEz(Nx_R) = (Ez(Nx_R-1) - 2d0*Ez(ix) + 0d0 )/Hx**2\n\n end subroutine laplacian_Ez\nend subroutine dt_evolve\n", "meta": {"hexsha": "11150031bdce61e5945be18bb514b45b8d0ac035", "size": 905, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/dt_evolve.f90", "max_stars_repo_name": "shunsuke-sato/fdtd1d", "max_stars_repo_head_hexsha": "23f85a983df9914f99e240cf75d93adc387e9021", "max_stars_repo_licenses": ["MIT"], "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/dt_evolve.f90", "max_issues_repo_name": "shunsuke-sato/fdtd1d", "max_issues_repo_head_hexsha": "23f85a983df9914f99e240cf75d93adc387e9021", "max_issues_repo_licenses": ["MIT"], "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/dt_evolve.f90", "max_forks_repo_name": "shunsuke-sato/fdtd1d", "max_forks_repo_head_hexsha": "23f85a983df9914f99e240cf75d93adc387e9021", "max_forks_repo_licenses": ["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.4242424242, "max_line_length": 84, "alphanum_fraction": 0.5193370166, "num_tokens": 327, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942145139149, "lm_q2_score": 0.7461390043208003, "lm_q1q2_score": 0.6739830458261519}} {"text": "FUNCTION bnc(N,P,rank)\n\n!-------------------------------------------------------------\n!\n! Compute the number of cells for the subdomain, one\n! dimension at a time.\n! Take in the number of cells total for a dimension, N, the \n! number of processes P in that dimension, and the rank.\n! Return the integer number of cells for that sub-domain, bnc.\n!\n! When not evenly divided, keeps all but one even, then tries\n! tries to keep last sub-domain close\n!\n!-------------------------------------------------------------\n\nIMPLICIT NONE\nINTEGER, INTENT(IN) :: N, P, rank\nINTEGER :: bnc, tmpi1, tmpi2\nREAL :: tmpr\n\n! Set the values to be checked against\ntmpr = 0.5*REAL(P)\n\ntmpi1 = MOD(N,P)\ntmpi2 = N/P\n\n! If it's evenly divisible, just use the division\nIF (tmpi1 == 0) THEN\n bnc = tmpi2\n\n! If not, then compare the MOD result to half the number of processes and set\nELSE IF (REAL(tmpi1) < tmpr) THEN\n IF (rank /= P-1) THEN\n bnc = tmpi2\n ELSE\n bnc = N - (P-1)*tmpi2\n END IF\n\nELSE IF (REAL(tmpi1) >= tmpr) THEN\n IF (rank /= P-1) THEN\n bnc = tmpi2 + 1\n ELSE\n bnc = N - (P-1)*(tmpi2+1)\n END IF\n\nEND IF\n\nEND FUNCTION bnc\n", "meta": {"hexsha": "9ddceaa5fe347e9fd65584dcf4715285c1818adb", "size": 1151, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "variations-old/ahotn-2d/bnc.f90", "max_stars_repo_name": "lanl/pidots", "max_stars_repo_head_hexsha": "9b1bf717337ce84ea20b82cfb358eadb04532d6c", "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": "variations-old/ahotn-2d/bnc.f90", "max_issues_repo_name": "lanl/pidots", "max_issues_repo_head_hexsha": "9b1bf717337ce84ea20b82cfb358eadb04532d6c", "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": "variations-old/ahotn-2d/bnc.f90", "max_forks_repo_name": "lanl/pidots", "max_forks_repo_head_hexsha": "9b1bf717337ce84ea20b82cfb358eadb04532d6c", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-24T17:37:35.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-24T17:37:35.000Z", "avg_line_length": 23.4897959184, "max_line_length": 77, "alphanum_fraction": 0.5812337098, "num_tokens": 354, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942119105696, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6739830387845763}} {"text": "SUBROUTINE TaylorFDStencils1DArbitrary(alp,bet,order,Stencils,x)\n! By Allan P. Engsig-Karup.\nUSE Precision\nUSE DataTypes\nIMPLICIT NONE\nINTEGER :: r, alp, bet, m, n, order, count\nREAL(KIND=long), DIMENSION(:,:), ALLOCATABLE :: Mat\nREAL(KIND=long), DIMENSION(alp+bet+1) :: Stencils, x\nr = alp + bet + 1; ! rank of points in stencil\nALLOCATE(Mat(r,order+1))\nCALL weights(x(alp+1),x,r-1,r-1,order,Mat)\nStencils = Mat(1:r,order+1)\nDEALLOCATE(Mat)\nEND SUBROUTINE TaylorFDStencils1DArbitrary\n", "meta": {"hexsha": "46770cffa4a535e90254a28466b544e0ffa74ba6", "size": 485, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/functions/TaylorFDStencils1DArbitrary.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/TaylorFDStencils1DArbitrary.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/TaylorFDStencils1DArbitrary.f90", "max_forks_repo_name": "apengsigkarup/OceanWave3D", "max_forks_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2015-10-01T12:17:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-02T16:23:37.000Z", "avg_line_length": 32.3333333333, "max_line_length": 64, "alphanum_fraction": 0.7381443299, "num_tokens": 179, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.921921834855049, "lm_q2_score": 0.7310585903489892, "lm_q1q2_score": 0.6739788770010857}} {"text": "module Ray_Casting_Algo\n use Polygons\n implicit none\n\n real, parameter, private :: eps = 0.00001\n private :: ray_intersects_seg\n\ncontains\n\n function ray_intersects_seg(p0, a0, b0) result(intersect)\n type(point), intent(in) :: p0, a0, b0\n logical :: intersect\n\n type(point) :: a, b, p\n real :: m_red, m_blue\n\n p = p0\n ! let variable \"a\" be the point with smallest y coordinate\n if ( a0%y > b0%y ) then\n b = a0\n a = b0\n else\n a = a0\n b = b0\n end if\n\n if ( (p%y == a%y) .or. (p%y == b%y) ) p%y = p%y + eps\n\n intersect = .false.\n\n if ( (p%y > b%y) .or. (p%y < a%y) ) return\n if ( p%x > max(a%x, b%x) ) return\n\n if ( p%x < min(a%x, b%x) ) then\n intersect = .true.\n else\n if ( abs(a%x - b%x) > tiny(a%x) ) then\n m_red = (b%y - a%y) / (b%x - a%x)\n else\n m_red = huge(m_red)\n end if\n if ( abs(a%x - p%x) > tiny(a%x) ) then\n m_blue = (p%y - a%y) / (p%x - a%x)\n else\n m_blue = huge(m_blue)\n end if\n if ( m_blue >= m_red ) then\n intersect = .true.\n else\n intersect = .false.\n end if\n end if\n\n end function ray_intersects_seg\n\n function point_is_inside(p, pol) result(inside)\n logical :: inside\n type(point), intent(in) :: p\n type(polygon), intent(in) :: pol\n\n integer :: i, cnt, pa, pb\n\n cnt = 0\n do i = lbound(pol%vertices,1), ubound(pol%vertices,1), 2\n pa = pol%vertices(i)\n pb = pol%vertices(i+1)\n if ( ray_intersects_seg(p, pol%points(pa), pol%points(pb)) ) cnt = cnt + 1\n end do\n\n inside = .true.\n if ( mod(cnt, 2) == 0 ) then\n inside = .false.\n end if\n\n end function point_is_inside\n\nend module Ray_Casting_Algo\n", "meta": {"hexsha": "1c0a2ff8de98d7800089eb8d6885d3fb65693808", "size": 1755, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Ray-casting-algorithm/Fortran/ray-casting-algorithm-2.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Ray-casting-algorithm/Fortran/ray-casting-algorithm-2.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Ray-casting-algorithm/Fortran/ray-casting-algorithm-2.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 22.5, "max_line_length": 81, "alphanum_fraction": 0.5282051282, "num_tokens": 602, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218391455085, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6739788693336755}} {"text": " subroutine irev_daatheta(n_DDLthetatheta,n_DDLxx,n_JSthth,n_JSxx,n\n &_Pthetatheta,n_RRthetatheta,n_RRxx,n_Uthetatheta,n_alpha,n_em4phi,\n &n_metthetatheta,n_metxx,nm1_Athth,np1_Athth,Nx,ht,res)\n implicit none\n integer i\n integer Nx\n real*8 ht\n real*8 n_DDLthetatheta(Nx)\n real*8 n_DDLxx(Nx)\n real*8 n_JSthth(Nx)\n real*8 n_JSxx(Nx)\n real*8 n_Pthetatheta(Nx)\n real*8 n_RRthetatheta(Nx)\n real*8 n_RRxx(Nx)\n real*8 n_Uthetatheta(Nx)\n real*8 n_alpha(Nx)\n real*8 n_em4phi(Nx)\n real*8 n_metthetatheta(Nx)\n real*8 n_metxx(Nx)\n real*8 nm1_Athth(Nx)\n real*8 np1_Athth(Nx)\n real*8 res(Nx)\n real*8 qb\n do i=1, Nx, 1\n qb = -0.5000000000000000D0 * (nm1_Athth(i) - 0.1D1 * np1_Athth(i))\n # / ht + 0.3333333333333333D0 / n_metxx(i) * n_alpha(i) * n_metthet\n #atheta(i) * n_RRxx(i) * n_em4phi(i) - 0.3333333333333333D0 / n_met\n #xx(i) * n_em4phi(i) * n_alpha(i) * n_JSxx(i) * n_metthetatheta(i) \n #- 0.3333333333333333D0 * n_alpha(i) * n_RRthetatheta(i) * n_em4phi\n #(i) + 0.3333333333333333D0 * n_alpha(i) * n_JSthth(i) * n_em4phi(i\n #) - 0.1D1 * n_alpha(i) * n_Uthetatheta(i) - 0.3333333333333333D0 /\n # n_metxx(i) * n_DDLxx(i) * n_metthetatheta(i) * n_em4phi(i) + 0.33\n #33333333333333D0 * n_DDLthetatheta(i) * n_em4phi(i) - 0.1D1 * n_Pt\n #hetatheta(i)\n res(i)=qb\n end do\n END\n", "meta": {"hexsha": "e6c6e0d019dd297675dd0a3463fda1698442484e", "size": 1437, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/FD/irev_daatheta.f", "max_stars_repo_name": "rmanak/bssn_spher", "max_stars_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/FD/irev_daatheta.f", "max_issues_repo_name": "rmanak/bssn_spher", "max_issues_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/FD/irev_daatheta.f", "max_forks_repo_name": "rmanak/bssn_spher", "max_forks_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.8157894737, "max_line_length": 72, "alphanum_fraction": 0.6270006959, "num_tokens": 633, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218284193597, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6739788614922323}} {"text": "MODULE MODULE_GEOMETRY\n\nUSE MODULE_MATH\nUSE MODULE_PBC\n!USE MODULE_COM\nUSE MODULE_BOX\n\nCONTAINS\n\n FUNCTION DIST2POINTS(point1,point2,box,inv,ortho,pbc_opt) RESULT (valdist)\n \n IMPLICIT NONE \n INTEGER, INTENT(IN)::ortho,pbc_opt\n DOUBLE PRECISION,DIMENSION(3),INTENT(IN)::point1,point2\n DOUBLE PRECISION,DIMENSION(3,3),INTENT(IN)::box,inv\n DOUBLE PRECISION::valdist\n DOUBLE PRECISION,DIMENSION(3)::vect_aux\n \n vect_aux(:)=point1(:)-point2(:)\n IF (pbc_opt==1) THEN\n CALL PBC (vect_aux,box,inv,ortho)\n END IF\n valdist=sqrt(dot_product(vect_aux(:),vect_aux(:)))\n\n END FUNCTION DIST2POINTS\n\n FUNCTION ANG3VECTS (vec1,vec2,vec3) RESULT (ang)\n \n IMPLICIT NONE\n \n DOUBLE PRECISION,dimension(3),intent(in)::vec1,vec2,vec3\n DOUBLE PRECISION::ang\n DOUBLE PRECISION,dimension(3)::aux1,aux2,aux3\n DOUBLE PRECISION::cosa\n integer::signo\n double precision::pi\n \n cosa=0.0d0\n signo=0\n ang=0.0d0\n pi=3.14159265358979\n \n aux1=0.0d0\n aux2=0.0d0\n \n CALL PRODUCT_VECT(vec1,vec2,aux1)\n CALL PRODUCT_VECT(vec2,vec3,aux2)\n \n cosa=(aux1(1)*aux2(1)+aux1(2)*aux2(2)+aux1(3)*aux2(3))/(sqrt(dot_product(aux1,aux1))*sqrt(dot_product(aux2,aux2)))\n \n IF (cosa>=1.0d0) THEN \n cosa=1.0d0\n END IF\n IF (cosa<=-1.0d0) THEN \n cosa=-1.0d0\n END IF\n \n cosa=(DACOS(cosa))*(180.0d0/pi)\n\n IF (cosa>180.0d0) THEN\n print*,'ERROR: ANGLE > 180.0 DEGREES'\n STOP\n END IF\n \n aux3=0.0d0\n \n CALL PRODUCT_VECT(aux1,aux2,aux3)\n \n IF ( dot_product(aux3,vec2) <= 0.0d0 ) THEN\n signo=-1\n ELSE\n signo=+1\n END IF\n \n ang=cosa*signo\n \n END FUNCTION ANG3VECTS\n\n\n SUBROUTINE DISTANCE(diff_set, coors1, coors2, box, ortho, pbc_opt, n1, n2, n_frames, matrix)\n \n IMPLICIT NONE\n INTEGER,INTENT(IN):: diff_set, ortho, pbc_opt, n1, n2, n_frames\n DOUBLE PRECISION,DIMENSION(n_frames,n1,3),INTENT(IN)::coors1\n DOUBLE PRECISION,DIMENSION(n_frames,n2,3),INTENT(IN)::coors2\n DOUBLE PRECISION,DIMENSION(n_frames,3,3),INTENT(IN)::box\n DOUBLE PRECISION,DIMENSION(n_frames,n1,n2),INTENT(OUT)::matrix\n\n DOUBLE PRECISION,DIMENSION(n_frames,3,3)::inv\n \n INTEGER::ii,jj,kk\n DOUBLE PRECISION::val_aux\n DOUBLE PRECISION,DIMENSION(:),ALLOCATABLE::vect,vect_aux,vect_aux2\n DOUBLE PRECISION,DIMENSION(:,:),ALLOCATABLE::tmp_box,tmp_inv\n\n ALLOCATE(vect(3),vect_aux(3),vect_aux2(3))\n ALLOCATE(tmp_box(3,3),tmp_inv(3,3))\n\n inv=0.0d0\n IF (pbc_opt==1) THEN\n CALL BOX2INVBOX (box, inv, n_frames)\n END IF\n\n IF (diff_set==1) THEN\n DO kk=1,n_frames\n tmp_box=box(kk,:,:)\n tmp_inv=inv(kk,:,:)\n DO ii=1,n1\n vect_aux=coors1(kk,ii,:)\n DO jj=1,n2\n vect_aux2=coors2(kk,jj,:)\n matrix(kk,ii,jj)=DIST2POINTS(vect_aux,vect_aux2,tmp_box,tmp_inv,ortho,pbc_opt)\n END DO\n END DO\n END DO\n ELSE\n DO kk=1,n_frames\n tmp_box=box(kk,:,:)\n tmp_inv=inv(kk,:,:)\n DO ii=1,n1\n matrix(kk,ii,ii)=0.0d0\n vect_aux=coors1(kk,ii,:)\n DO jj=ii+1,n1\n vect_aux2=coors1(kk,jj,:)\n val_aux=DIST2POINTS(vect_aux,vect_aux2,tmp_box,tmp_inv,ortho,pbc_opt)\n matrix(kk,ii,jj)=val_aux\n matrix(kk,jj,ii)=val_aux\n END DO\n END DO\n END DO\n END IF\n \n DEALLOCATE(vect,vect_aux,vect_aux2)\n DEALLOCATE(tmp_box,tmp_inv)\n \n END SUBROUTINE DISTANCE\n \n SUBROUTINE DISTANCE_PAIRS(coors1, coors2, box, ortho, pbc_opt, n1, n2, n_frames, matrix)\n \n IMPLICIT NONE\n INTEGER,INTENT(IN):: ortho, pbc_opt, n1, n2, n_frames\n DOUBLE PRECISION,DIMENSION(n_frames,n1,3),INTENT(IN)::coors1\n DOUBLE PRECISION,DIMENSION(n_frames,n2,3),INTENT(IN)::coors2\n DOUBLE PRECISION,DIMENSION(n_frames,3,3),INTENT(IN)::box\n DOUBLE PRECISION,DIMENSION(n_frames,n1),INTENT(OUT)::matrix\n\n DOUBLE PRECISION,DIMENSION(n_frames,3,3)::inv\n \n INTEGER::ii,kk\n DOUBLE PRECISION,DIMENSION(:),ALLOCATABLE::vect,vect_aux,vect_aux2\n DOUBLE PRECISION,DIMENSION(:,:),ALLOCATABLE::tmp_box,tmp_inv\n\n ALLOCATE(vect(3),vect_aux(3),vect_aux2(3))\n ALLOCATE(tmp_box(3,3),tmp_inv(3,3))\n\n inv=0.0d0\n IF (pbc_opt==1) THEN\n CALL BOX2INVBOX (box, inv, n_frames)\n END IF\n\n DO kk=1,n_frames\n tmp_box=box(kk,:,:)\n tmp_inv=inv(kk,:,:)\n DO ii=1,n1\n vect_aux=coors1(kk,ii,:)\n vect_aux2=coors2(kk,ii,:)\n matrix(kk,ii)=DIST2POINTS(vect_aux,vect_aux2,tmp_box,tmp_inv,ortho,pbc_opt)\n END DO\n END DO\n \n DEALLOCATE(vect,vect_aux,vect_aux2)\n DEALLOCATE(tmp_box,tmp_inv)\n \n END SUBROUTINE DISTANCE_PAIRS\n\n\n !FUNCTION RADIUS_OF_GYRATION (coors,weights,n_frames,n_atoms) RESULT(Rg)\n\n ! IMPLICIT NONE \n ! INTEGER, INTENT(IN)::n_frames,n_atoms\n ! DOUBLE PRECISION,DIMENSION(n_frames,n_atoms,3),INTENT(IN)::coors\n ! DOUBLE PRECISION,DIMENSION(n_atoms),INTENT(IN)::weights\n ! DOUBLE PRECISION,DIMENSION(n_frames)::Rg\n\n ! INTEGER::ii,jj\n ! DOUBLE PRECISION,DIMENSION(n_frames,3)::com\n ! DOUBLE PRECISION,DIMENSION(3)::vect_aux\n ! DOUBLE PRECISION::total_weight\n ! DOUBLE PRECISION::val_aux\n\n ! Rg(:) = 0.0d0\n ! com = CENTER_OF_MASS(coors,weights,n_frames,n_atoms)\n ! total_weight=SUM(weights)\n\n ! DO ii=1,n_frames\n ! val_aux=0.0d0\n ! DO jj=1,n_atoms\n ! vect_aux = coors(ii,jj,:)-com(ii,:)\n ! Rg(ii)=Rg(ii)+weights(jj)*dot_product(vect_aux,vect_aux)\n ! END DO\n ! END DO\n\n ! Rg(:)=Rg(:)/total_weight\n ! Rg(:)=sqrt(Rg(:))\n\n !END FUNCTION\n\n SUBROUTINE TRANSLATE(coors, shifts, frame_indices, n_atoms, n_frames, n_frame_indices)\n \n IMPLICIT NONE\n INTEGER,INTENT(IN)::n_frames, n_atoms, n_frame_indices\n DOUBLE PRECISION,DIMENSION(n_frames, n_atoms, 3),INTENT(INOUT)::coors\n DOUBLE PRECISION,DIMENSION(n_frame_indices, 3),INTENT(IN)::shifts\n INTEGER,DIMENSION(n_frame_indices),INTENT(IN)::frame_indices\n INTEGER::ii,jj,frame_index\n\n DO ii=1,n_frame_indices\n frame_index = frame_indices(ii)+1\n DO jj=1,n_atoms\n coors(frame_index,jj,:)=coors(frame_index,jj,:)+shifts(ii,:)\n END DO\n END DO\n\n END SUBROUTINE\n\n SUBROUTINE DIHEDRAL_ANGLES (angs, coors, box, ortho, pbc_opt, quartets, n_angs, n_atoms, n_frames)\n\n INTEGER,INTENT(IN)::ortho, n_atoms, n_angs, pbc_opt, n_frames\n INTEGER,DIMENSION(n_angs,4),INTENT(IN)::quartets\n DOUBLE PRECISION,DIMENSION(n_frames,n_atoms,3),INTENT(IN)::coors\n DOUBLE PRECISION,DIMENSION(n_frames,3,3),INTENT(IN)::box\n DOUBLE PRECISION,DIMENSION(n_frames,n_angs),INTENT(OUT)::angs\n\n DOUBLE PRECISION,DIMENSION(n_frames,3,3)::inv\n DOUBLE PRECISION,DIMENSION(3,3)::tmp_box,tmp_inv\n INTEGER::ii,jj\n INTEGER::atom1,atom2,atom3,atom4\n DOUBLE PRECISION,DIMENSION(3)::vect1,vect2,vect3\n \n inv=0.0d0\n IF (pbc_opt==1) THEN\n CALL BOX2INVBOX (box, inv, n_frames)\n END IF\n\n DO jj=1,n_frames\n tmp_box=box(jj,:,:)\n tmp_inv=inv(jj,:,:)\n DO ii=1,n_angs\n atom1=quartets(ii,1)+1\n atom2=quartets(ii,2)+1\n atom3=quartets(ii,3)+1\n atom4=quartets(ii,4)+1\n vect1=coors(jj,atom2,:)-coors(jj,atom1,:)\n vect2=coors(jj,atom3,:)-coors(jj,atom2,:)\n vect3=coors(jj,atom4,:)-coors(jj,atom3,:)\n IF (pbc_opt==1) THEN\n CALL PBC (vect1,tmp_box,tmp_inv,ortho)\n CALL PBC (vect2,tmp_box,tmp_inv,ortho)\n CALL PBC (vect3,tmp_box,tmp_inv,ortho)\n END IF\n angs(jj,ii)=ANG3VECTS(vect1,vect2,vect3)\n END DO\n END DO\n\n END SUBROUTINE DIHEDRAL_ANGLES\n\n SUBROUTINE SET_DIHEDRAL_ANGLES (coors, box, ortho, pbc_opt, quartets, angs, blocks, atoms_per_block, n_angs, n_atoms, &\n n_frames, blocks_size)\n\n INTEGER,INTENT(IN)::ortho, n_atoms, n_angs, pbc_opt, n_frames, blocks_size\n INTEGER,DIMENSION(n_angs,4),INTENT(IN)::quartets\n DOUBLE PRECISION,DIMENSION(n_frames,n_atoms,3),INTENT(INOUT)::coors\n DOUBLE PRECISION,DIMENSION(n_frames,3,3),INTENT(IN)::box\n DOUBLE PRECISION,DIMENSION(n_frames,n_angs),INTENT(IN)::angs\n INTEGER,DIMENSION(blocks_size),INTENT(IN)::blocks\n INTEGER,DIMENSION(n_angs),INTENT(IN)::atoms_per_block\n\n DOUBLE PRECISION,DIMENSION(n_frames,3,3)::inv\n DOUBLE PRECISION,DIMENSION(3,3)::tmp_box,tmp_inv\n INTEGER::ii,jj,kk,ll\n INTEGER::atom1,atom2,atom3,atom4\n DOUBLE PRECISION,DIMENSION(3)::vect1,vect2,vect3,vect_aux,u_vect\n DOUBLE PRECISION::old_ang, shift_ang\n INTEGER,DIMENSION(n_angs+1)::aux_block\n\n aux_block(:)=0\n\n DO ii=1,n_angs\n aux_block(ii+1:)=aux_block(ii+1:)+atoms_per_block(ii)\n END DO\n \n inv=0.0d0\n IF (pbc_opt==1) THEN\n CALL BOX2INVBOX (box, inv, n_frames)\n END IF\n\n DO jj=1,n_frames\n tmp_box=box(jj,:,:)\n tmp_inv=inv(jj,:,:)\n DO ii=1,n_angs\n atom1=quartets(ii,1)+1\n atom2=quartets(ii,2)+1\n atom3=quartets(ii,3)+1\n atom4=quartets(ii,4)+1\n vect1=coors(jj,atom2,:)-coors(jj,atom1,:)\n vect2=coors(jj,atom3,:)-coors(jj,atom2,:)\n vect3=coors(jj,atom4,:)-coors(jj,atom3,:)\n IF (pbc_opt==1) THEN\n CALL PBC (vect1,tmp_box,tmp_inv,ortho)\n CALL PBC (vect2,tmp_box,tmp_inv,ortho)\n CALL PBC (vect3,tmp_box,tmp_inv,ortho)\n END IF\n u_vect = vect2/(sqrt(dot_product(vect2,vect2)))\n old_ang=ANG3VECTS(vect1,vect2,vect3)\n shift_ang = angs(jj,ii)-old_ang\n DO kk=aux_block(ii)+1,aux_block(ii+1)\n ll = blocks(kk)+1 !!!!!!!! aqui\n vect_aux = coors(jj,ll,:)-coors(jj,atom3,:)\n IF (pbc_opt==1) THEN\n CALL PBC (vect_aux,tmp_box,tmp_inv,ortho)\n END IF\n CALL RODRIGUES_ROTATION(vect_aux, u_vect, shift_ang)\n IF (pbc_opt==1) THEN\n CALL PBC (vect_aux,tmp_box,tmp_inv,ortho)\n END IF\n coors(jj,ll,:)=coors(jj,atom3,:)+vect_aux\n END DO \n END DO\n END DO\n\n END SUBROUTINE SET_DIHEDRAL_ANGLES\n\n SUBROUTINE RODRIGUES_ROTATION (vect, unit_vector, angle)\n\n IMPLICIT NONE \n DOUBLE PRECISION,DIMENSION(3),INTENT(INOUT)::vect\n DOUBLE PRECISION,DIMENSION(3),INTENT(IN)::unit_vector\n DOUBLE PRECISION,INTENT(IN)::angle\n\n DOUBLE PRECISION,dimension(3)::aux1,aux2,aux3\n DOUBLE PRECISION::cosa, sina, aux_ang\n double precision::pi\n \n cosa=0.0d0\n sina=0.0d0\n pi=3.14159265358979\n \n aux1=0.0d0\n aux2=0.0d0\n aux3=0.0d0\n \n aux_ang = (pi/180.0d0)*angle\n\n cosa = DCOS(aux_ang)\n sina = DSIN(aux_ang)\n\n aux1 = vect*cosa\n CALL PRODUCT_VECT(unit_vector,vect,aux2)\n aux2 = aux2*sina\n aux3 = dot_product(unit_vector, vect)*(1.0d0-cosa)*unit_vector\n \n vect = aux1+aux2+aux3\n\n END SUBROUTINE RODRIGUES_ROTATION\n\nEND MODULE MODULE_GEOMETRY \n", "meta": {"hexsha": "16000bc69e9cba6de8c828fa816875af34892849", "size": 10827, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "molsysmt/lib/libgeometry.f90", "max_stars_repo_name": "uibcdf/MolSysMT", "max_stars_repo_head_hexsha": "9866a6fb090df9fff36af113a45164da4b674c09", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-06-02T03:55:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T04:43:52.000Z", "max_issues_repo_path": "molsysmt/lib/libgeometry.f90", "max_issues_repo_name": "uibcdf/MolSysMT", "max_issues_repo_head_hexsha": "9866a6fb090df9fff36af113a45164da4b674c09", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 28, "max_issues_repo_issues_event_min_datetime": "2020-06-24T00:55:53.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-16T22:09:19.000Z", "max_forks_repo_path": "molsysmt/lib/libgeometry.f90", "max_forks_repo_name": "uibcdf/MolSysMT", "max_forks_repo_head_hexsha": "9866a6fb090df9fff36af113a45164da4b674c09", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-17T18:55:25.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-17T18:55:25.000Z", "avg_line_length": 29.5013623978, "max_line_length": 121, "alphanum_fraction": 0.6447769465, "num_tokens": 3699, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.921921834855049, "lm_q2_score": 0.7310585727705127, "lm_q1q2_score": 0.6739788607951044}} {"text": "module PhysicalConstantsClass\n use iso_fortran_env\n implicit none\n\n \n\ttype :: PhysicalConstants_\n real(real64) :: c = 299792458.0d0! speed of light in vacuum (m/s)\n real(real64) :: speed_of_light = 299792458.0d0! speed of light in vacuum (m/s)\n real(real64) :: Plank = 6.62607015*10.0d0**(-34.0) ! the Plank constant (J s)\n real(real64) :: g =9.80665d0 ! standard acceleration of gravity (m/s)\n real(real64) :: R =8.31446261815324d0 ! Molar gas constant (J/K/mol)\n real(real64) :: gas_constant = 8.31446261815324d0 ! Molar gas constant (J/K/mol)\n real(real64) :: Avogadro = 6.02214076*10.0d0**23 ! Avogadro constant (/mol)\n real(real64) :: k = 1.380649*10.0d0**(-23) ! Boltzmann constant (J/K)\n real(real64) :: Boltzmann = 1.380649*10.0d0**(-23) ! Boltzmann constant(J/K)\n contains\n procedure,public :: unit => unitPhysicalConstants\n end type\ncontains\n\nfunction unitPhysicalConstants(obj,tgt) result(ret)\n class(PhysicalConstants_),intent(in) :: obj\n character(*),intent(in) :: tgt\n character(:),allocatable :: ret\n\n\n if(tgt==\"c\")then\n ret = \"m/s\"\n return\n endif\n if(tgt==\"speed_of_light\")then\n ret = \"m/s\"\n return\n endif\n if(tgt==\"Plank\")then\n ret = \"J s\"\n return\n endif\n if(tgt==\"g\")then\n ret = \"m/s\"\n return\n endif\n if(tgt==\"R\")then\n ret = \"J/K/mol\"\n return\n endif\n if(tgt==\"gas_constant\")then\n ret = \"J/K/mol\"\n return\n endif\n if(tgt==\"Avogadro\")then\n ret = \"/mol\"\n return\n endif\n if(tgt==\"k\")then\n ret = \"J/K\"\n return\n endif\n if(tgt==\"Boltzmann\")then\n ret = \"J/K\"\n return\n endif\n\n\nend function\n\nend module", "meta": {"hexsha": "2b65bea05813d6badfbb8be26c5480fedd7fa9a5", "size": 1786, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/PhysicalConstantsClass/PhysicalConstantsClass.f90", "max_stars_repo_name": "kazulagi/plantFEM", "max_stars_repo_head_hexsha": "20bf2df8202d41aa5dc25d1cc820385dabbc604f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2020-06-21T08:21:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-13T04:28:30.000Z", "max_issues_repo_path": "src/PhysicalConstantsClass/PhysicalConstantsClass.f90", "max_issues_repo_name": "kazulagi/faba", "max_issues_repo_head_hexsha": "7ef140f1ebea0e0ca496d14fdb94a3c024393cfa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-05-08T05:20:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T05:39:29.000Z", "max_forks_repo_path": "src/PhysicalConstantsClass/PhysicalConstantsClass.f90", "max_forks_repo_name": "kazulagi/faba", "max_forks_repo_head_hexsha": "7ef140f1ebea0e0ca496d14fdb94a3c024393cfa", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-10-20T18:28:59.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-15T08:35:25.000Z", "avg_line_length": 26.6567164179, "max_line_length": 88, "alphanum_fraction": 0.5761478163, "num_tokens": 566, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117855317474, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.6739623106068572}} {"text": "Module ToolsLib\n\ncontains\n\n ! Fonction du calcul du module de la tension nodale en un noeud\n Real function ModCmplx(z)\n complex, intent(IN) :: z\n\n !ModCmplx = (sqrt(Real(z)**2 + Aimag(z)**2))\n ModCmplx = (cabs(z))\n end function ModCmplx\n\n ! Fonction du calcul de l'argument de la tension nodale en un noeud\n Real function Argum(z)\n real :: theta\n\n complex, intent(IN) :: z\n\n theta = Atan(Aimag(z)/real(z))\n !Argum = (theta*180)/pi\n Argum = theta\n end function\n\n ! Fonction du calcul de la solution du syst\u00e8me AX=B selon GAUSS\n Subroutine GaussMat(Jaa, Bb, Xx, Nn)\n\n integer, intent(IN) :: Nn\n Real, intent(IN) :: Jaa(:,:), Bb(:)\n Real, allocatable, intent(OUT) :: Xx(:)\n\n Real, allocatable, Dimension(:,:) :: Aa\n integer :: ii, ij, ik\n Real :: Xsum, xmult\n !character(len=40) :: A3Fmt\n\n ! Formation de la matrice a = [Jaa | I]\n allocate(Aa(Nn,Nn+1), Xx(Nn))\n\n Xx=0.\n Aa=0.\n do ii=1, Nn\n do ij=1, Nn+1\n Aa(ii,ij) = Jaa(ii,ij)\n end do\n Aa(ii, Nn+1) = Bb(ii)\n end do\n\n ! Elimination de Gauss\n do ik = 1, Nn-1\n do ii = ik+1, Nn\n xmult = Aa(ii, ik) / Aa(ik, ik)\n Aa(ii, ik) = 0.\n do ij = ik+1, Nn+1\n Aa(ii, ij) = Aa(ii, ij) - xmult * Aa(ik, ij)\n end do\n end do\n end do\n\n Xx(Nn) = Aa(Nn, Nn+1) / Aa(Nn, Nn)\n do ii = Nn-1, 1, -1\n Xsum = 0.\n do ij= ii+1, Nn\n Xsum = Xsum + Aa(ii, ij) * Xx(ij)\n end do\n Xx(ii) = (Aa(ii, Nn+1) - Xsum) / Aa(ii, ii)\n end do\n\n deallocate(Aa)\n End Subroutine\n\n ! Proc\u00e9dure d'inversion matrice selon GAUSS-JORDAN\n Subroutine InvMat(Aa, Cc, Nn)\n !implicit none\n\n integer, Intent(IN) :: Nn\n Real, Intent(INOUT) :: Aa(Nn,Nn)\n\n Real, Intent(OUT) :: Cc(Nn,Nn)\n Real :: L(Nn,Nn), U(Nn,Nn), b(Nn), d(Nn), Xx(Nn)\n Real :: coeff\n integer ii, ij, ik\n\n L = 0.0\n U = 0.0\n b = 0.0\n\n do ik = 1, Nn-1\n do ii = ik+1, Nn\n coeff = Aa(ii,ik) / Aa(ik,ik)\n L(ii,ik) = coeff\n do ij = ik + 1, Nn\n Aa(ii,ij) = Aa(ii,ij) - coeff*Aa(ik,ij)\n end do\n end do\n end do\n\n do ii = 1, Nn\n L(ii,ii) = 1.0\n end do\n\n do ij = 1, Nn\n do ii = 1, ij\n U(ii, ij) = Aa(ii,ij)\n end do\n end do\n\n do ik = 1, Nn\n b(ik) = 1.0\n d(1) = b(1)\n do ii = 2, Nn\n d(ii) = b(ii)\n do ij = 1, ii-1\n d(ii) = d(ii) - L(ii,ij)*d(ij)\n end do\n end do\n Xx(Nn)=d(Nn)/U(Nn,Nn)\n do ii = Nn-1, 1, -1\n Xx(ii) = d(ii)\n do ij = Nn, ii+1, -1\n Xx(ii) = Xx(ii) - U(ii, ij)*Xx(ij)\n end do\n Xx(ii) = Xx(ii)/U(ii,ii)\n end do\n do ii = 1, Nn\n Cc(ii, ik) = Xx(ii)\n end do\n b(ik)=0.0\n end do\n end subroutine InvMat\n\n ! Gauss-Jordan avec pivotation de lignes\n SUBROUTINE GaussJordanPivation (A_,Nn,B_,Xx)\n Implicit none\n\n INTEGER, INTENT (IN) :: Nn\n INTEGER :: iI,iJ\n INTEGER, DIMENSION (Nn) :: INDX\n REAL, INTENT (IN), DIMENSION (Nn,Nn) :: A_\n REAL, INTENT (IN), DIMENSION (Nn) :: B_\n REAL, DIMENSION (Nn,Nn) :: Aa\n REAL, DIMENSION (Nn) :: Bb\n REAL, INTENT (OUT), DIMENSION (Nn) :: Xx\n\n Aa = A_\n Bb = B_\n CALL PivotationLU (Aa,Nn,INDX)\n DO iI = 1, Nn-1\n DO iJ = iI+1, Nn\n Bb(INDX(iJ)) = Bb(INDX(iJ))-Aa(INDX(iJ),iI)*Bb(INDX(iI))\n END DO\n END DO\n\n Xx(Nn) = Bb(INDX(Nn))/Aa(INDX(Nn),Nn)\n DO iI = Nn-1, 1, -1\n Xx(iI) = Bb(INDX(iI))\n DO iJ = iI+1, Nn\n Xx(iI) = Xx(iI)-Aa(INDX(iI),iJ)*Xx(iJ)\n END DO\n Xx(iI) = Xx(iI)/Aa(INDX(iI),iI)\n END DO\n END SUBROUTINE GaussJordanPivation\n\n ! Subroutine de pivotation de lignes\n SUBROUTINE PivotationLU (Aa,Nn,INDX)\n Implicit none\n INTEGER, INTENT (IN) :: Nn\n INTEGER :: iI, iJ, iK = 0, ITMP\n INTEGER, INTENT (OUT), DIMENSION (Nn) :: INDX\n REAL :: C1, PI, PI1,PJ\n REAL, INTENT (INOUT), DIMENSION (Nn,Nn) :: Aa\n REAL, DIMENSION (Nn) :: C\n\n DO iI = 1, Nn\n INDX(iI) = iI\n END DO\n\n DO iI = 1, Nn\n C1= 0.0\n DO iJ = 1, Nn\n C1 = AMAX1(C1,ABS(Aa(iI,iJ)))\n END DO\n C(iI) = C1\n END DO\n\n DO iJ = 1, Nn-1\n PI1 = 0.0\n DO iI = iJ, Nn\n PI = ABS(Aa(INDX(iI),iJ))/C(INDX(iI))\n IF (PI.GT.PI1) THEN\n PI1 = PI\n iK = iI\n ENDIF\n END DO\n\n ITMP = INDX(iJ)\n INDX(iJ) = INDX(iK)\n INDX(iK) = ITMP\n\n DO iI = iJ+1, Nn\n PJ = Aa(INDX(iI),iJ)/Aa(INDX(iJ),iJ)\n Aa(INDX(iI),iJ) = PJ\n DO iK = iJ+1, Nn\n Aa(INDX(iI),iK) = Aa(INDX(iI),iK)-PJ*Aa(INDX(iJ),iK)\n END DO\n END DO\n END DO\n END SUBROUTINE PivotationLU\n\n ! Convertir un intier en chaine de caract\u00e8res.\n character(len=20) function rStr(rk)\n implicit none\n\n real, intent(in) :: rk\n\n write(rStr, *) rk\n rStr = adjustl(rStr)\n end function rStr\n\n ! Convertir un intier en chaine de caract\u00e8res.\n character(len=20) function Str(ik)\n implicit none\n\n integer, intent(in) :: ik\n\n write(Str, *) ik\n Str = adjustl(str)\n end function Str\n\n ! Convertit une chaine de caract\u00e8res (numerique) en entier\n Integer function Str2int(str_)\n implicit none\n\n character(len=*), intent(in) :: str_\n integer :: int_\n read(str_, *) int_\n Str2int = int_\n end function Str2int\n\n ! Convertit une chaine de caract\u00e8res (R\u00e9elle) en r\u00e9el\n Real function Str2float(str_)\n implicit none\n\n character(len=*), intent(in) :: str_\n Real :: f_\n\n read(str_, \"(F9.3)\") f_\n Str2float = f_\n end function Str2float\n\n ! Subroutine de nettoyage de caract\u00e8re sp\u00e9ciaux d'une chaine de caract\u00e8res.\n Subroutine Removesp(str)\n implicit none\n\n character(len=*):: str\n character(len=1):: ch\n character(len=len_trim(str))::outstr\n integer :: i_, k_, ich, lenstr\n\n str=adjustl(str)\n lenstr=len_trim(str)\n outstr=' '\n k_=0\n do i_=1,lenstr\n ch=str(i_:i_)\n ich=iachar(ch)\n select case(ich)\n case(0:32) ! space, tab, or control character\n cycle\n case(33:)\n k_=k_+1\n outstr(k_:k_)=ch\n end select\n end do\n str=adjustl(outstr)\n end subroutine Removesp\n\n ! G\u00e9n\u00e9re une chaine de caract\u00e8re (\u00e0 partir de nombres al\u00e9atoires)\n character(len=30) Function GenerateRndCar()\n implicit none\n\n real :: r_ = 2008.1960\n\n call RANDOM_NUMBER(r_)\n GenerateRndCar = Adjustl(Str(floor(r_*10000)))\n\n end function GenerateRndCar\nEnd module ToolsLib\n", "meta": {"hexsha": "8a06e4fc95f3bbcad3ac13ecc1159ab377ec49ed", "size": 7214, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "NMSSLib.f95", "max_stars_repo_name": "mtamali/Load-Flow-Tools", "max_stars_repo_head_hexsha": "5d2db7ac44f529f2b17386d0c080226aea3bb0df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-04-01T20:21:47.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-01T20:21:47.000Z", "max_issues_repo_path": "NMSSLib.f95", "max_issues_repo_name": "mtamali/Load-Flow-Tools", "max_issues_repo_head_hexsha": "5d2db7ac44f529f2b17386d0c080226aea3bb0df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NMSSLib.f95", "max_forks_repo_name": "mtamali/Load-Flow-Tools", "max_forks_repo_head_hexsha": "5d2db7ac44f529f2b17386d0c080226aea3bb0df", "max_forks_repo_licenses": ["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.0486111111, "max_line_length": 79, "alphanum_fraction": 0.4847518714, "num_tokens": 2521, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357460591569, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.6739467739912215}} {"text": "! Program to test initialization expressions involving subobjects\nprogram parameter_2\n implicit none\n type :: SS\n integer :: I\n integer :: J\n end type SS\n type :: TT\n integer :: N\n type (SS), dimension(2) :: o\n end type\n \n type (SS), parameter :: s = SS (1, 2)\n type (TT), parameter :: t = TT(42, (/ SS(3, 4), SS(8, 9) /))\n\n integer, parameter :: a(2) = (/5, 10/)\n integer, parameter :: d1 = s%i\n integer, parameter :: d2 = a(2)\n integer, parameter :: d4 = t%o(2)%j\n\n integer q1, q2, q3, q4\n common /c1/q1(d1), q2(d2), q3(a(1)), q4(d4) ! legal\nend\n", "meta": {"hexsha": "e480751f19df28644fe4779bdee746eed5f92819", "size": 577, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.fortran-torture/parameter_2.f90", "max_stars_repo_name": "maurizioabba/rose", "max_stars_repo_head_hexsha": "7597292cf14da292bdb9a4ef573001b6c5b9b6c0", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.fortran-torture/parameter_2.f90", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.fortran-torture/parameter_2.f90", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 24.0416666667, "max_line_length": 65, "alphanum_fraction": 0.5788561525, "num_tokens": 212, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357460591568, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.6739467650452774}} {"text": "\n program prepare\n \n!***********************************************************************\n! \n! LBsoft tool for preparing the isfluid.dat file as a set\n! of 1 byte integers in natural order\n! \n! licensed under the 3-Clause BSD License (BSD-3-Clause)\n! author: M. Lauricella\n! last modification October 2019\n! \n!***********************************************************************\n\n implicit none\n \n integer :: nx,ny,nz,nn,i,j,k,cx,cy,cz\n !isfluid should be 1 byte integer\n integer(kind=1), allocatable, dimension(:,:,:) :: isfluid\n \n integer, parameter :: iout=16\n double precision :: rdist,radius\n \n nx=64\n ny=64\n nz=64\n \n cx=32\n cy=32\n cz=32\n \n radius=12\n \n nn=nx*ny*nz\n \n allocate(isfluid(nx,ny,nz))\n \n open(unit=iout,file='isfluid.dat',action='write',status='replace', &\n access='stream',form='unformatted')\n \n !i should be the fastest (natural order of the 3d matrix)\n !remember that FORTRAN is column-major order\n do k=1,nz\n do j=1,ny\n do i=1,nx\n !insert a geometrical rule here\n rdist=dsqrt(dble((i-cx)**2+(j-cy)**2+(k-cz)**2))\n if(rdist<=radius)then\n isfluid(i,j,k)=3 !3 = solid\n else\n isfluid(i,j,k)=1 !1 = liquid\n endif\n !print on isfluid.dat\n write(iout)isfluid(i,j,k)\n enddo\n enddo\n enddo\n \n close(iout)\n \n stop\n \n end program prepare\n \n \n \n", "meta": {"hexsha": "2aa40d3d9536500a30b2bf6c9899105630b7419a", "size": 1430, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/create_geometry/prepare_isfluid.f90", "max_stars_repo_name": "copmat/LBsoft", "max_stars_repo_head_hexsha": "7099f60b2c1f6bb3b0e4b3df904aa61d8bec8626", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-04-10T16:59:43.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-26T23:06:54.000Z", "max_issues_repo_path": "source/create_geometry/prepare_isfluid.f90", "max_issues_repo_name": "copmat/LBsoft", "max_issues_repo_head_hexsha": "7099f60b2c1f6bb3b0e4b3df904aa61d8bec8626", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/create_geometry/prepare_isfluid.f90", "max_forks_repo_name": "copmat/LBsoft", "max_forks_repo_head_hexsha": "7099f60b2c1f6bb3b0e4b3df904aa61d8bec8626", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-05-26T15:23:23.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-15T05:21:26.000Z", "avg_line_length": 21.3432835821, "max_line_length": 72, "alphanum_fraction": 0.5286713287, "num_tokens": 410, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278757303677, "lm_q2_score": 0.763483758172699, "lm_q1q2_score": 0.6737193508789725}} {"text": "PROGRAM Particle_1D_Box\n IMPLICIT NONE\n\n REAL, PARAMETER :: pi = acos(-1.0)\n REAL:: bl, x, psi ! bl is bond length\n CHARACTER*10:: filename\n INTEGER:: i, n, outunit\n bl = 1.\n WRITE(*, *) \"Enter the quantum number n\"\n READ *, n\n\n ! WRITE(fiblame, 10) \"psi.\", n\n ! 10 FORMAT(a, i0)\n WRITE(filename, fmt = \"(a, i0)\") \"psi.\", n\n OPEN(UNIT = outunit, FILE = filename, FORM = \"formatted\")\n x = -0.001\n DO i = 1, 1001\n x = x + 0.001\n psi = sqrt(2.0/bl) * sin(n * pi * x/bl);\n WRITE(outunit, *) x, psi, psi**2\n ENDDO\n CLOSE(outunit)\nEND", "meta": {"hexsha": "acd6049dd26acbedea05f37bdab487df3f2788fc", "size": 606, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Practice-1/Particle_1D_Box.f90", "max_stars_repo_name": "arpitkekri/Code_With_FORTRAN", "max_stars_repo_head_hexsha": "fb731e6f8d8a47cfe38896fffd74a55d17efb2e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-02-21T05:24:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-27T10:25:24.000Z", "max_issues_repo_path": "Practice-1/Particle_1D_Box.f90", "max_issues_repo_name": "akhil18soni/Code_With_FORTRAN", "max_issues_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Practice-1/Particle_1D_Box.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.347826087, "max_line_length": 61, "alphanum_fraction": 0.5280528053, "num_tokens": 215, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278540866548, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.673719343852085}} {"text": "module bouss_module\n \n implicit none\n logical :: bouss ! Turn on the dispersive terms\n real(kind=8) :: B_param \n real(kind=8) :: sw_depth0, sw_depth1\n integer :: bc_xlo, bc_xhi\n\n ! for higher-order derivatives:\n real(kind=8), allocatable, dimension(:) :: dxm, dxc, cm, cp, c0\n\n \n ! for tridiagonal solver:\n integer, allocatable, dimension(:) :: IPIV\n real(kind=8), allocatable, dimension(:) :: D, DL, DU, DU2 \n\n save\n\n\ncontains\n\n!======================================================================\n\n subroutine set_bouss(mx,mbc,mthbc)\n \n ! Set things up for Boussinesq solver, in particular\n ! create and factor tridiagonal matrix for implicit solves.\n\n use geoclaw_module, only: sea_level, coordinate_system\n use grid_module, only: xcell, zcell, grid_type\n \n implicit none\n integer, intent(in) :: mx, mbc, mthbc(2)\n real(kind=8) :: DLi, r\n integer :: i, iunit\n character*25 fname\n real(kind=8), dimension(1-mbc:mx+mbc) :: h0, h02, h03\n integer(kind=4) :: INFO\n\n iunit = 7\n fname = 'bouss.data'\n ! # open the unit with new routine from Clawpack 4.4 to skip over\n ! # comment lines starting with #:\n call opendatafile(iunit, fname)\n\n read(7,*) bouss\n read(7,*) B_param\n read(7,*) sw_depth0\n read(7,*) sw_depth1\n \n allocate(dxm(0:mx+1),dxc(0:mx+1),cm(0:mx+1),cp(0:mx+1),c0(0:mx+1))\n\n ! Boundary conditions to impose in computing Boussinesq update:\n \n if ((mthbc(1)==2) .or. (mthbc(2)==2)) then\n write(6,*) '*** Periodic BCs not supported in bouss_module'\n stop\n endif\n\n ! Use Dirichlet BC with value 0 for correction in ghost cells by default:\n bc_xlo = 0\n bc_xhi = 0\n \n ! Check if wall BCs specified (also be used for radial symmetry at r=0):\n \n if (mthbc(1)==3) then\n ! For wall boundary conditions at left boundary:\n bc_xlo = 3\n endif\n\n if (mthbc(2)==3) then\n ! For wall boundary conditions at right boundary:\n bc_xhi = 3\n endif\n\n if (mthbc(1)==0) then\n ! For wavemaker BC at left\n bc_xlo = 3\n endif\n\n ! To try out Neumann BCs:\n ! This doesn't seem to work well, so not a general option\n !bc_xlo = 1\n !bc_xhi = 1\n \n \n !------------------------------------\n ! coefficients needed for second-order derivatives:\n\n do i=0,mx+2\n dxm(i) = xcell(i) - xcell(i-1)\n enddo\n\n do i=0,mx+1\n if (grid_type == 0) then\n ! uniform grid\n dxc(i) = 2*dxm(i)\n cm(i) = 1.d0/dxm(i)**2\n c0(i) = -2.d0/dxm(i)**2\n cp(i) = 1.d0/dxm(i)**2\n else\n dxc(i) = (xcell(i+1) - xcell(i-1)) ! = 2*dx for uniform grid!\n cm(i) = 2.d0 / (dxm(i)*dxc(i))\n cp(i) = 2.d0 / (dxm(i+1)*dxc(i))\n c0(i) = -(cm(i) + cp(i))\n endif\n\n if (coordinate_system == -1) then\n ! x = radial coordinate r >= 0\n ! include factors for ((1/r)*(r*q)_r)_r \n ! using form q_{rr} + (1/r)q_r - (1/r**2)q\n r = xcell(i)\n cm(i) = cm(i) - 1.d0/(r*dxc(i))\n cp(i) = cp(i) + 1.d0/(r*dxc(i))\n c0(i) = c0(i) - 1.d0/(r**2)\n else if (coordinate_system == 2) then\n write(6,*) '*** latitude coordinates not yet implemented in Bouss'\n stop\n endif\n enddo\n\n \n \n !------------------------------------\n ! Form tridiagonal matrix and factor\n ! Done once at start and then used in each time step\n \n !h0 = sea_level - aux(1,:) # resting depth\n\n do i=1-mbc,mx+mbc\n h0(i) = sea_level - zcell(i)\n 666 format(i3,3e16.6)\n h02(i)=(max(0.,h0(i)))**2\n h03(i)=(max(0.,h0(i)))**3\n enddo\n\n ! allocate tridiagonal and initialize to identity matrix:\n allocate(D(mx+2), DL(mx+1), DU(mx+2), DU2(mx+2), IPIV(mx+2))\n D = 1.d0\n DU= 0.d0\n DL= 0.d0\n \n ! First and last rows (rows 1 and mx+2) of matrix corresponds to BCs\n ! Row i+1 of matrix corresponds to equation for cell i\n\n do i=1,mx\n \n ! Modify row i+1 (equation for i'th grid cell) to form (I-d^2) operator,\n ! unless this is a cell where SWE are used, then leave as row of I\n ! and set RHS to 0, so no modification to SWE result.\n \n if ((h0(i) > sw_depth0)) then\n \n ! Replace this row of identity matrix with dispersion terms\n ! Note that cm(i)*w(i-1) + c0(i)*w(i) + cp(i)*w(i+1) gives\n ! approximation to d^2 w = w_{xx} in plane wave case, or\n ! d^2 w = (1/r * (r*w)_r)_r in radial case\n ! Also h02 is h0**2 and h03 is h0**3:\n\n D(i+1) = 1.d0 - c0(i)*((B_param+.5d0)*h02(i) &\n - 1.d0/6.d0*h03(i)/h0(i))\n\n DU(i+1)= -cp(i)*((B_param+.5d0)*h02(i) &\n - 1.d0/6.d0*h03(i)/h0(i+1))\n\n DL(i)= -cm(i)*((B_param+.5d0)*h02(i) &\n - 1.d0/6.d0*h03(i)/h0(i-1))\n\n endif\n \n enddo\n\n ! left boundary\n ! No change ==> Dirichlet value 0 in ghost cell, Q_0 = 0\n ! For other BCs, change superdiagonal in row 1:\n\n if (bc_xlo==1) then\n ! for Neumann BC at left: impose Q_0 = Q_1\n DU(1) = -1.d0 \n endif\n if (bc_xlo==3) then\n ! for wall-reflecting BC at left: impose Q_0 = -Q_1\n DU(1) = 1.d0 \n endif\n\n\n ! right boundary\n ! No change ==> Dirichlet value 0 in ghost cell, Q_{mx+1} = 0\n ! For other BCs, change subdiagonal in row mx+2:\n\n if (bc_xhi==1) then\n ! for Neumann at right: impose Q_mx = Q_{mx+1}\n DL(mx+1) = -1.d0\n endif\n if (bc_xhi==3) then\n ! for wall at right: impose Q_mx = - Q_{mx+1}\n DL(mx+1) = 1.d0\n endif\n\n \n if (.false.) then\n ! DEBUG:\n write(66,*) 'D matrix:'\n do i=1,mx+2\n if (i>1) then\n DLi = DL(i-1)\n else\n DLi = -9999. ! since no subdiag in first row\n endif\n write(66,661) DLi, D(i), DU(i)\n 661 format(3e16.6)\n enddo\n write(66,*) '===== end of D'\n endif\n\n\n ! factor the tridiagonal matrix: \n call DGTTRF( mx+2, DL, D, DU, DU2, IPIV, INFO )\n\n end subroutine set_bouss\n \n!======================================================================\n\n subroutine solve_tridiag(mx,meqn,mbc,dx,q,maux,aux,psi)\n\n ! Set up right hand side for tridagonal system and then solve it\n ! psi first holds RHS and then the solution to be passed back.\n \n ! Note that matrix has already been factored in set_bouss, so the\n ! arrays D, DL, DU, DU2, IPIV are already set up for the solver.\n \n use geoclaw_module, only: g => grav, sea_level, dry_tolerance\n use geoclaw_module, only: coordinate_system\n use grid_module, only: xcell\n\n implicit none\n\n integer, intent(in) :: mx,meqn,mbc,maux\n real(kind=8), intent(in) :: dx\n\n real(kind=8), intent(in) :: q(meqn,1-mbc:mx+mbc)\n real(kind=8), intent(in) :: aux(maux,1-mbc:mx+mbc)\n real(kind=8), intent(out) :: psi(mx+2)\n\n real(kind=8) depth\n real(kind=8), dimension(1-mbc:mx+mbc) :: h0, h02, h03, eta, hu2\n real(kind=8), dimension(1-mbc:mx+mbc) :: h_eta_x,h0_eta_x,s1,s1_h0\n real(kind=8) h0_eta_xxx,s1_xx,s1_h0_xx\n integer :: i,j,k,kk,iL,iR\n integer(kind=4) :: INFO\n integer :: LDB\n\n h0 = sea_level - aux(1,:)\n\n do i=1-mbc,mx+mbc\n ! compute hu2 = h*u**2\n if (q(1,i).gt.dry_tolerance) then\n hu2(i)= q(2,i)**2/q(1,i)\n else\n hu2(i)= 0.d0\n endif\n \n !hu2(i) = 0.d0 ! Debug: turning off nonlinear terms\n \n ! h0 is resting depth, h02 = h0**2 and h03 = h0**3:\n eta(i)= q(1,i) - h0(i)\n h02(i)=(max(0.d0,h0(i)))**2\n h03(i)=(max(0.d0,h0(i)))**3\n \n enddo\n\n ! compute these quantities, extending to one set of ghost cells:\n ! h_eta_x = h * eta_x\n ! h0_eta_x = h0 * eta_x\n \n ! defaults to 0 if h0==0 at one of the stencil points:\n h_eta_x = 0.d0\n h0_eta_x = 0.d0\n \n do i= 0,mx+1\n if (minval(h0(i-1:i+1)) > 0.d0) then\n ! if h0 > 0 at all stencil points. Note dxc(i) = 2*dx if uniform:\n h_eta_x(i)= q(1,i)*(eta(i+1)-eta(i-1))/dxc(i)\n h0_eta_x(i)= h0(i)*(eta(i+1)-eta(i-1))/dxc(i)\n endif\n enddo\n \n\n \n do i=0,mx+1\n \n ! compute approximation to\n ! s1 = (h*u**2)_x + g*h*eta_x (plane wave) or\n ! s1 = (1/r)*(r*h*u**2)_r + r*g*h*eta_r (radial)\n ! = (h*u**2)_r + (1/r)*h*u**2 + r*g*h*eta_r\n \n s1(i) = (hu2(i+1) - hu2(i-1)) / dxc(i) + g*h_eta_x(i)\n !s1(i) = g*h_eta_x(i) ! debug\n !s1(i) = (hu2(i+1) - hu2(i-1)) / dxc(i) \n \n if (coordinate_system == -1) then\n ! radial: add term for (1/r)*h*u**2:\n s1(i) = s1(i) + hu2(i) / xcell(i) \n else if (coordinate_system == 2) then\n ! latitude\n write(6,*) '*** latitude not yet implemented in bouss_module'\n stop\n endif\n \n ! compute s1_h0 = s1 / h0:\n \n if (h0(i) > dry_tolerance) then\n s1_h0(i)=s1(i)/h0(i)\n else\n s1_h0(i)=0.d0\n endif\n enddo\n \n\n ! Compute right hand side psi:\n \n psi = 0.d0\n\n do i=1,mx\n\n k = i+1 ! i'th equation corresponds to row k=i+1 of RHS\n\n if (h0(i) <= sw_depth0) then\n ! no dispersive term:\n psi(k) = 0.d0\n\n else\n ! Note that cm(i)*w(i-1) + c0(i)*w(i) + cp(i)*w(i+1) gives\n ! approximation to d^2 w = w_{xx} \n ! or in radial case to d^2 w = (1/r * (rw)_r)_r\n\n ! compute s1_xx, approximates d^2 s1:\n\n s1_xx = cp(i)*s1(i+1) + c0(i)*s1(i) + cm(i)*s1(i-1)\n\n ! compute s1_h0_xx, approximates d^2 s1_h0 = d^2(s1 / h0):\n \n s1_h0_xx = cp(i)*s1_h0(i+1) + c0(i)*s1_h0(i) + cm(i)*s1_h0(i-1)\n \n ! compute h0_eta_xxx, approximates d^2 h0_eta_x:\n \n h0_eta_xxx = cp(i)*h0_eta_x(i+1) + c0(i)*h0_eta_x(i) + &\n cm(i)*h0_eta_x(i-1)\n \n\n ! Right-hand side:\n \n psi(k) = -(B_param+.5d0) * h02(i) * s1_xx &\n + h03(i)/6.d0 * s1_h0_xx &\n + B_param * g * h02(i) * h0_eta_xxx\n if (.false.) then\n write(66,*) '+++i,rhs(i+1): ',i, psi(k)\n write(66,*) (B_param+.5d0) * h02(i), s1_xx\n write(66,*) h03(i)/6.d0, s1_h0_xx \n write(66,*) B_param * g * h02(i) * h0_eta_xxx\n write(66,*) B_param, g, h02(i), h0_eta_xxx\n write(66,*) s1(i)\n write(66,*) h0_eta_x(i)\n write(66,*) eta(i)\n endif\n \n \n endif\n\n\n if ((h0(i) > sw_depth0) .and. (h0(i) < sw_depth1)) then\n ! reduce psi linearly between sw_depth0 and sw_depth1:\n psi(k) = psi(k) * (h0(i)-sw_depth0)/(sw_depth1-sw_depth0)\n endif\n \n enddo\n \n if (.false.) then\n write(66,*) 'RHS:'\n do i=1,mx+2\n write(66,*) '+++i,rhs: ',i, psi(i)\n enddo\n endif\n \n ! -------------------------\n ! solve tridiagonal system. \n ! psi is RHS on entry, solution on exit:\n \n LDB = mx+2 ! leading dimension of right-hand side matrix psi\n \n call DGTTRS( 'N', mx+2, 1, DL, D, DU, DU2, &\n IPIV, psi, LDB,INFO )\n \n if (.false.) then\n write(66,*) 'Solution psi: '\n do i=1,mx+2\n write(66,*) '+++ i,psi: ',i,psi(i)\n enddo\n endif\n\n return\nend subroutine solve_tridiag\n\n\nend module bouss_module\n", "meta": {"hexsha": "a26a714e4ff10f72add6a270943bd805dfbafa87", "size": 11826, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/1d_classic/bouss/bouss_module.f90", "max_stars_repo_name": "clawpack/geoclaw_1d", "max_stars_repo_head_hexsha": "2272459a81f253720feaa3561094764433e7115a", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/1d_classic/bouss/bouss_module.f90", "max_issues_repo_name": "clawpack/geoclaw_1d", "max_issues_repo_head_hexsha": "2272459a81f253720feaa3561094764433e7115a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-01-22T19:35:11.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-22T17:32:43.000Z", "max_forks_repo_path": "src/1d_classic/bouss/bouss_module.f90", "max_forks_repo_name": "clawpack/geoclaw_1d", "max_forks_repo_head_hexsha": "2272459a81f253720feaa3561094764433e7115a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-01-04T04:39:16.000Z", "max_forks_repo_forks_event_max_datetime": "2019-01-04T04:39:16.000Z", "avg_line_length": 29.1280788177, "max_line_length": 80, "alphanum_fraction": 0.4948418738, "num_tokens": 3983, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278726384089, "lm_q2_score": 0.7634837527911056, "lm_q1q2_score": 0.6737193437694442}} {"text": " SUBROUTINE MB04OW( M, N, P, A, LDA, T, LDT, X, INCX, B, LDB,\n $ C, LDC, D, INCD )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To perform the QR factorization\nC\nC ( U ) = Q*( R ), where U = ( U1 U2 ), R = ( R1 R2 ),\nC ( x' ) ( 0 ) ( 0 T ) ( 0 R3 )\nC\nC where U and R are (m+n)-by-(m+n) upper triangular matrices, x is\nC an m+n element vector, U1 is m-by-m, T is n-by-n, stored\nC separately, and Q is an (m+n+1)-by-(m+n+1) orthogonal matrix.\nC\nC The matrix ( U1 U2 ) must be supplied in the m-by-(m+n) upper\nC trapezoidal part of the array A and this is overwritten by the\nC corresponding part ( R1 R2 ) of R. The remaining upper triangular\nC part of R, R3, is overwritten on the array T.\nC\nC The transformations performed are also applied to the (m+n+1)-by-p\nC matrix ( B' C' d )' (' denotes transposition), where B, C, and d'\nC are m-by-p, n-by-p, and 1-by-p matrices, respectively.\nC\nC ARGUMENTS\nC\nC Input/Output Parameters\nC\nC M (input) INTEGER\nC The number of rows of the matrix ( U1 U2 ). M >= 0.\nC\nC N (input) INTEGER\nC The order of the matrix T. N >= 0.\nC\nC P (input) INTEGER\nC The number of columns of the matrices B and C. P >= 0.\nC\nC A (input/output) DOUBLE PRECISION array, dimension (LDA,N)\nC On entry, the leading M-by-(M+N) upper trapezoidal part of\nC this array must contain the upper trapezoidal matrix\nC ( U1 U2 ).\nC On exit, the leading M-by-(M+N) upper trapezoidal part of\nC this array contains the upper trapezoidal matrix ( R1 R2 ).\nC The strict lower triangle of A is not referenced.\nC\nC LDA INTEGER\nC The leading dimension of the array A. LDA >= max(1,M).\nC\nC T (input/output) DOUBLE PRECISION array, dimension (LDT,N)\nC On entry, the leading N-by-N upper triangular part of this\nC array must contain the upper triangular matrix T.\nC On exit, the leading N-by-N upper triangular part of this\nC array contains the upper triangular matrix R3.\nC The strict lower triangle of T is not referenced.\nC\nC LDT INTEGER\nC The leading dimension of the array T. LDT >= max(1,N).\nC\nC X (input/output) DOUBLE PRECISION array, dimension\nC (1+(M+N-1)*INCX), if M+N > 0, or dimension (0), if M+N = 0.\nC On entry, the incremented array X must contain the\nC vector x. On exit, the content of X is changed.\nC\nC INCX (input) INTEGER\nC Specifies the increment for the elements of X. INCX > 0.\nC\nC B (input/output) DOUBLE PRECISION array, dimension (LDB,P)\nC On entry, the leading M-by-P part of this array must\nC contain the matrix B.\nC On exit, the leading M-by-P part of this array contains\nC the transformed matrix B.\nC If M = 0 or P = 0, this array is not referenced.\nC\nC LDB INTEGER\nC The leading dimension of the array B.\nC LDB >= max(1,M), if P > 0;\nC LDB >= 1, if P = 0.\nC\nC C (input/output) DOUBLE PRECISION array, dimension (LDC,P)\nC On entry, the leading N-by-P part of this array must\nC contain the matrix C.\nC On exit, the leading N-by-P part of this array contains\nC the transformed matrix C.\nC If N = 0 or P = 0, this array is not referenced.\nC\nC LDC INTEGER\nC The leading dimension of the array C.\nC LDC >= max(1,N), if P > 0;\nC LDC >= 1, if P = 0.\nC\nC D (input/output) DOUBLE PRECISION array, dimension\nC (1+(P-1)*INCD), if P > 0, or dimension (0), if P = 0.\nC On entry, the incremented array D must contain the\nC vector d.\nC On exit, this incremented array contains the transformed\nC vector d.\nC If P = 0, this array is not referenced.\nC\nC INCD (input) INTEGER\nC Specifies the increment for the elements of D. INCD > 0.\nC\nC METHOD\nC\nC Let q = m+n. The matrix Q is formed as a sequence of plane\nC rotations in planes (1, q+1), (2, q+1), ..., (q, q+1), the\nC rotation in the (j, q+1)th plane, Q(j), being chosen to\nC annihilate the jth element of x.\nC\nC NUMERICAL ASPECTS\nC\nC The algorithm requires 0((M+N)*(M+N+P)) operations and is backward\nC stable.\nC\nC FURTHER COMMENTS\nC\nC For P = 0, this routine produces the same result as SLICOT Library\nC routine MB04OX, but matrix T may not be stored in the array A.\nC\nC CONTRIBUTORS\nC\nC V. Sima, Research Institute for Informatics, Bucharest, Dec. 2001.\nC\nC REVISIONS\nC\nC -\nC\nC KEYWORDS\nC\nC Matrix operations, plane rotations.\nC\nC ******************************************************************\nC\nC .. Scalar Arguments ..\n INTEGER INCD, INCX, LDA, LDB, LDC, LDT, M, N, P\nC .. Array Arguments ..\n DOUBLE PRECISION A(LDA,*), B(LDB,*), C(LDC,*), D(*), T(LDT,*),\n $ X(*)\nC .. Local Scalars ..\n DOUBLE PRECISION CI, SI, TEMP\n INTEGER I, IX, MN\nC .. External Subroutines ..\n EXTERNAL DLARTG, DROT\nC\nC .. Executable Statements ..\nC\nC For efficiency reasons, the parameters are not checked.\nC\n MN = M + N\n IF ( INCX.GT.1 ) THEN\nC\nC Code for increment INCX > 1.\nC\n IX = 1\n IF ( M.GT.0 ) THEN\nC\n DO 10 I = 1, M - 1\n CALL DLARTG( A(I,I), X(IX), CI, SI, TEMP )\n A(I,I) = TEMP\n IX = IX + INCX\n CALL DROT( MN-I, A(I,I+1), LDA, X(IX), INCX, CI, SI )\n IF ( P.GT.0 )\n $ CALL DROT( P, B(I,1), LDB, D, INCD, CI, SI )\n 10 CONTINUE\nC\n CALL DLARTG( A(M,M), X(IX), CI, SI, TEMP )\n A(M,M) = TEMP\n IX = IX + INCX\n IF ( N.GT.0 )\n $ CALL DROT( N, A(M,M+1), LDA, X(IX), INCX, CI, SI )\n IF ( P.GT.0 )\n $ CALL DROT( P, B(M,1), LDB, D, INCD, CI, SI )\n END IF\nC\n IF ( N.GT.0 ) THEN\nC\n DO 20 I = 1, N - 1\n CALL DLARTG( T(I,I), X(IX), CI, SI, TEMP )\n T(I,I) = TEMP\n IX = IX + INCX\n CALL DROT( N-I, T(I,I+1), LDT, X(IX), INCX, CI, SI )\n IF ( P.GT.0 )\n $ CALL DROT( P, C(I,1), LDC, D, INCD, CI, SI )\n 20 CONTINUE\nC\n CALL DLARTG( T(N,N), X(IX), CI, SI, TEMP )\n T(N,N) = TEMP\n IF ( P.GT.0 )\n $ CALL DROT( P, C(N,1), LDC, D, INCD, CI, SI )\n END IF\nC\n ELSEIF ( INCX.EQ.1 ) THEN\nC\nC Code for increment INCX = 1.\nC\n IF ( M.GT.0 ) THEN\nC\n DO 30 I = 1, M - 1\n CALL DLARTG( A(I,I), X(I), CI, SI, TEMP )\n A(I,I) = TEMP\n CALL DROT( MN-I, A(I,I+1), LDA, X(I+1), 1, CI, SI )\n IF ( P.GT.0 )\n $ CALL DROT( P, B(I,1), LDB, D, INCD, CI, SI )\n 30 CONTINUE\nC\n CALL DLARTG( A(M,M), X(M), CI, SI, TEMP )\n A(M,M) = TEMP\n IF ( N.GT.0 )\n $ CALL DROT( N, A(M,M+1), LDA, X(M+1), 1, CI, SI )\n IF ( P.GT.0 )\n $ CALL DROT( P, B(M,1), LDB, D, INCD, CI, SI )\n END IF\nC\n IF ( N.GT.0 ) THEN\n IX = M + 1\nC\n DO 40 I = 1, N - 1\n CALL DLARTG( T(I,I), X(IX), CI, SI, TEMP )\n T(I,I) = TEMP\n IX = IX + 1\n CALL DROT( N-I, T(I,I+1), LDT, X(IX), 1, CI, SI )\n IF ( P.GT.0 )\n $ CALL DROT( P, C(I,1), LDC, D, INCD, CI, SI )\n 40 CONTINUE\nC\n CALL DLARTG( T(N,N), X(IX), CI, SI, TEMP )\n T(N,N) = TEMP\n IF ( P.GT.0 )\n $ CALL DROT( P, C(N,1), LDC, D, INCD, CI, SI )\n END IF\n END IF\nC\n RETURN\nC *** Last line of MB04OW ***\n END\n", "meta": {"hexsha": "f5651d01f286f568c81e0f5480f0aff8499f1616", "size": 8139, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB04OW.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB04OW.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB04OW.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 34.1974789916, "max_line_length": 72, "alphanum_fraction": 0.5049760413, "num_tokens": 2616, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9334308165850442, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6736973560058439}} {"text": "program ciclista\n\n implicit none\n double precision, dimension(0:500) :: v, v1, tempo, diff\n double precision :: m, p, dt, b, ro, a\n integer :: c\n\n m = 60\n p = 400\n dt = 0.05\n b = 05\n ro = 1\n a = 0.33\n v(0) = 4\n\n\tdo c = 1,500\n\t tempo(c) = c*dt\n\t diff(c-1) = p/(m*v(c-1))\n\t v(c) = diff(c-1)*dt + v(c-1) - ((b*ro*a*v(c-1)**2)/m)*dt\n!\t v(c) = diff(c-1)*dt + v(c-1)\n\t write(*,*) tempo(c), v(c)\n\tenddo\n\n open(1,FILE = \"dados2.txt\")\n\n\tdo c = 1,500\n\t write(1,*) tempo(c), v(c)\n\tenddo\n\n close(1)\n\nend program", "meta": {"hexsha": "18bf2a6ed56f99830210f979f28a7ab63f28c49c", "size": 556, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "aula10/prog1.f90", "max_stars_repo_name": "j-rheinheimer/Fisica-Computacional-I", "max_stars_repo_head_hexsha": "9d3d434cfb787391db5b57829e93d1461cc65f1c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "aula10/prog1.f90", "max_issues_repo_name": "j-rheinheimer/Fisica-Computacional-I", "max_issues_repo_head_hexsha": "9d3d434cfb787391db5b57829e93d1461cc65f1c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "aula10/prog1.f90", "max_forks_repo_name": "j-rheinheimer/Fisica-Computacional-I", "max_forks_repo_head_hexsha": "9d3d434cfb787391db5b57829e93d1461cc65f1c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.375, "max_line_length": 61, "alphanum_fraction": 0.476618705, "num_tokens": 237, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294983, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6736973519961664}} {"text": "module vallado\n! based on http://www.smad.com/vallado/\n\nuse assert, only : wp\n\nimplicit none\nprivate\n\n real(wp), parameter :: pi = 4._wp * atan(1.0_wp)\n\n type,public :: time\n integer :: year, month, day, hour, minute\n real(wp) :: second\n end type\n\npublic:: toGST, toJulian, toLST, radec2azel, azel2radec\ncontains\n\nelemental subroutine azel2radec(az,el,lat,lon,jd, ra,decl)\n! convert azimuth, elevation to right ascension, declination\n! \n! inputs\n! ------\n! az, el: azimuth, elevation (degrees)\n! lat, lon: geodetic latitude, longitude (degrees)\n! jd: julian date (decimal)\n! \n! outputs\n! -------\n! ra, decl: right ascension, declination (degrees)\n\n real(wp), value :: az,el,lat,lon\n real(wp), intent(in) :: jd ! Julian Date\n real(wp), intent(out) :: ra, decl\n \n real(wp) :: lst, lha, sinv, cosv\n \n az = radians(az)\n el = radians(el)\n lat = radians(lat)\n lon = radians(lon)\n\n Decl = ASIN(SIN(El)*SIN(lat) + &\n COS(el)*COS(lat)*COS(Az) )\n\n Sinv = -(SIN(az)*COS(el)*COS(lat)) / &\n (COS(lat)*COS(Decl))\n \n Cosv = (SIN(el) - SIN(lat)*SIN(decl)) / &\n (COS(lat)*COS(Decl))\n \n LHA = ATAN2(Sinv,Cosv)\n lst = toLST(Lon, JD)\n \n ra = modulo(degrees(LST - LHA), 360._wp)\n decl = degrees(decl)\n\nend subroutine azel2radec\n\n\nelemental SUBROUTINE radec2azel(ra,Decl,lat,lon,jd, Az,El)\n! convert right ascension, declination to azimuth, elevation \n! \n! inputs\n! ------\n! ra, decl: right ascension, declination (degrees)\n! lat, lon: geodetic latitude, longitude (degrees)\n! jd: julian date (decimal)\n! \n! outputs\n! -------\n! az, el: azimuth, elevation (degrees)\n\n REAL(wp), value :: ra,Decl,lat, lon\n real(wp), intent(in) :: jd\n real(wp), intent(out) :: Az,El\n REAL(wp) :: Sinv, Cosv, LHA\n \n lat = radians(lat)\n lon = radians(lon)\n ra = radians(ra)\n decl = radians(decl)\n\n LHA = toLST(Lon, JD) - ra\n\n El = ASIN( SIN(Decl)*SIN(lat) + &\n COS(Decl)*COS(lat)*COS(LHA) )\n\n Sinv = -SIN(LHA)*COS(Decl)*COS(lat) / &\n (COS(el)*COS(lat))\n \n Cosv = ( SIN(Decl)-SIN(el)*SIN(lat) ) / &\n (COS(el)*COS(lat))\n \n Az = modulo(degrees(ATAN2(Sinv,Cosv)), 360._wp)\n el = degrees(el)\n\n\nEND subroutine radec2azel\n\n\nelemental real(wp) function toLST(Lon, JD) result(LST)\n! Julian Date => local sidereal time\n!\n! inputs\n! ------\n! lon: geodetic longitude (radians)\n! jd: Julian Date (decimal)\n\n REAL(wp), intent(in) :: Lon, JD\n \n LST = Lon + toGST(jd)\n\n LST = modulo(LST, 2*pi )\n\nEND function toLST\n \n\nelemental real(wp) function toJulian(t) result(jd)\n! Gregorian date, time => Julian Date\n!\n! inputs\n! ------\n! time: Gregorian user-defined type\n!\n! output\n! -----\n! JD: Julian Date\n\n type(time), intent(in) :: t\n real(wp) :: B, y, m\n \n y = t%year\n m = t%month\n\n IF ( M <= 2 ) THEN\n Y = y - 1\n M = m + 12\n ENDIF\n \n B = 2 - INT(Y*0.01_wp) + INT(INT(Y*0.01_wp)*0.25_wp)\n \n JD= INT( 365.25_wp*(Y + 4716) ) + &\n INT( 30.6001_wp*(M+1) ) + &\n t%day + B - 1524.5_wp + &\n ( (t%second/60.0_wp + t%minute ) / 60.0_wp + t%hour ) / 24.0_wp\n\nEND function toJulian\n\n\nelemental real(wp) FUNCTION toGST(JD) result(GST)\n! Julian Date => to Greenwich Sidereal Time\n!\n! inputs\n! ------\n! JD: Julian Date (decimal)\n!\n! output\n! ------\n! GST: Greenwich Sidereal Time (decimal)\n\n real(wp), intent(in) :: JD\n real(wp) :: TUT1\n\n\n TUT1= ( JD - 2451545._wp ) / 36525._wp\n gst = -6.2e-6_wp*TUT1**3 + &\n 0.093104_wp*TUT1**2 + &\n (876600._wp*3600._wp + 8640184.812866_wp)*TUT1 + &\n 67310.54841_wp\n \n gst = modulo(radians(gst) / 240._wp, 2*pi) ! 360/86400 = 1/240, to deg, to rad\n \n\nend function toGST\n\n\nelemental real(wp) function degrees(rad)\n real(wp), intent(in) :: rad\n\n degrees = 180._wp / pi * rad\nend function degrees\n\n\nelemental real(wp) function radians(deg)\n real(wp), intent(in) :: deg\n\n radians = pi / 180._wp * deg\nend function radians\n\n\nend module\n", "meta": {"hexsha": "ef2a017c4d45b145823fecf219fb8223082008b2", "size": 3936, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/vallado.f90", "max_stars_repo_name": "SamuelMarks/pymap3d", "max_stars_repo_head_hexsha": "312eafdb4c22979ce443856ea5845aaef32bd41e", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-06-27T13:50:36.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-27T13:50:36.000Z", "max_issues_repo_path": "fortran/vallado.f90", "max_issues_repo_name": "SamuelMarks/pymap3d", "max_issues_repo_head_hexsha": "312eafdb4c22979ce443856ea5845aaef32bd41e", "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": "fortran/vallado.f90", "max_forks_repo_name": "SamuelMarks/pymap3d", "max_forks_repo_head_hexsha": "312eafdb4c22979ce443856ea5845aaef32bd41e", "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.3937823834, "max_line_length": 80, "alphanum_fraction": 0.5932418699, "num_tokens": 1367, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308073258009, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6736973493230479}} {"text": "C$Procedure PLTEXP ( Plate expander )\n \n SUBROUTINE PLTEXP ( IVERTS, DELTA, OVERTS ) \n \nC$ Abstract\nC\nC Expand a triangular plate by a specified amount. The expanded\nC plate is co-planar with, and has the same orientation as, the\nC original. The centroids of the two plates coincide.\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 DSK\nC\nC$ Keywords\nC\nC MATH \nC GEOMETRY\nC TOPOGRAPHY\nC\nC$ Declarations\n\n IMPLICIT NONE\n\n DOUBLE PRECISION IVERTS ( 3, 3 )\n DOUBLE PRECISION DELTA\n DOUBLE PRECISION OVERTS ( 3, 3 )\n \nC$ Brief_I/O\nC\nC Variable I/O Description\nC -------- --- --------------------------------------------------\nC IVERTS I Vertices of the plate to be expanded.\nC DELTA I Fraction by which the plate is to be expanded.\nC OVERTS O Vertices of the expanded plate.\nC\nC$ Detailed_Input\nC\nC IVERTS is an array containing three vertices of a triangular\nC plate. Each vertex is a three-dimensional vector. The\nC elements\nC\nC IVERTS(J,I), J = 1, 3\nC\nC are, respectively, the X, Y, and Z components of the\nC Ith vertex.\nC\nC\nC DELTA is a fraction by which the plate is to be scaled.\nC Scaling is done so that the scaled plate has the\nC following properties:\nC\nC - it is co-planar with the input plate\nC\nC - its centroid coincides with that of the input\nC plate\nC\nC - its sides remain parallel to the corresponding\nC sides of the input plate\nC\nC - the distance of each vertex from the centroid is\nC (1+DELTA) times the corresponding distance for\nC the input plate\nC\nC$ Detailed_Output\nC\nC OVERTS is an array containing three vertices of the triangular\nC plate resulting from scaling the input plate.\nC\nC If CTROID is the centroid (the average of the vertices)\nC of the input plate, then the Ith vertex of OVERTS\nC\nC OVERTS(J,I), J = 1, 3\nC\nC is equal to \nC\nC CTROID(J) + (1+DELTA)*( IVERTS(J,I) - CTROID(J) ),\nC\nC J = 1, 3\nC\nC\nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC Error free.\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC This routine supports \"greedy\" ray-plate intercept algorithms.\nC Such algorithms attempt to ensure that false negatives---in which\nC an intersection is not found due to round-off error---do not\nC occur. In such an algorithm, the plate of interest is expanded\nC slightly before the intersection test is performed.\nC \nC$ Examples\nC\nC The numerical results shown for these examples may differ across\nC platforms. The results depend on the SPICE kernels used as input\nC (if any), the compiler and supporting libraries, and the machine\nC specific arithmetic implementation.\nC \nC 1) Expand an equilateral triangle that lies in the plane \nC \nC { (x,y,z) : z = 7 }\nC\nC Use an expansion fraction of 1.D0; this doubles the size of\nC the plate.\nC\nC Example code begins here. \nC\nC\nC PROGRAM EX1\nC IMPLICIT NONE\nC\nC DOUBLE PRECISION DELTA\nC DOUBLE PRECISION IVERTS ( 3, 3 )\nC DOUBLE PRECISION OVERTS ( 3, 3 )\nC DOUBLE PRECISION S\nC\nC INTEGER I\nC\nC S = SQRT(3.D0)/2\nC\nC CALL VPACK ( S, -0.5D0, 7.D0, IVERTS(1,1) )\nC CALL VPACK ( 0.D0, 1.D0, 7.D0, IVERTS(1,2) )\nC CALL VPACK ( -S, -0.5D0, 7.D0, IVERTS(1,3) )\nC\nC DELTA = 1.D0\nC\nC CALL PLTEXP ( IVERTS, DELTA, OVERTS )\nC\nC WRITE (*,*) ' '\nC WRITE (*,*) 'Vertices of input plate: '\nC\nC WRITE (*, '(1X,A,3(3E20.12))' ) ' I1 = ',\nC . (IVERTS(I,1), I = 1, 3)\nC WRITE (*, '(1X,A,3(3E20.12))' ) ' I2 = ',\nC . (IVERTS(I,2), I = 1, 3)\nC WRITE (*, '(1X,A,3(3E20.12))' ) ' I3 = ',\nC . (IVERTS(I,3), I = 1, 3)\nC\nC WRITE (*,*) ' '\nC WRITE (*,*) 'Vertices of output plate: '\nC\nC WRITE (*, '(1X,A,3(3E20.12))' ) ' O1 = ',\nC . (OVERTS(I,1), I = 1, 3)\nC WRITE (*, '(1X,A,3(3E20.12))' ) ' O2 = ',\nC . (OVERTS(I,2), I = 1, 3)\nC WRITE (*, '(1X,A,3(3E20.12))' ) ' O3 = ',\nC . (OVERTS(I,3), I = 1, 3)\nC WRITE (*,*) ' '\nC END\nC\nC\nC When this program was executed on a PC/Linux/gfortran/64-bit\nC platform, the output was:\nC\nC\nC Vertices of input plate:\nC I1 = 0.866025403784E+00 -0.500000000000E+00 0.700000000000E+01\nC I2 = 0.000000000000E+00 0.100000000000E+01 0.700000000000E+01\nC I3 = -0.866025403784E+00 -0.500000000000E+00 0.700000000000E+01\nC\nC Vertices of output plate:\nC O1 = 0.173205080757E+01 -0.100000000000E+01 0.700000000000E+01\nC O2 = 0.000000000000E+00 0.200000000000E+01 0.700000000000E+01\nC O3 = -0.173205080757E+01 -0.100000000000E+01 0.700000000000E+01\nC\nC\nC Note that the height of the plate is unchanged, but the vectors\nC from the centroid to the vertices have doubled in length.\nC\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC N.J. Bachman (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.0, 29-FEB-2016 (NJB)\nC \nC Based on original version 28-MAY-2014 (NJB)\nC\nC-&\n \nC$ Index_Entries\nC\nC expand triangular plate\nC\nC-&\n \nC\nC Local variables\nC\n DOUBLE PRECISION SCLCTR ( 3 )\n DOUBLE PRECISION D\n DOUBLE PRECISION S\n\nC\nC Compute the centroid of the input vertices. Scale the centroid\nC by DELTA, since we'll only use the scaled form.\nC\nC Unroll all loops to avoid loop overhead.\nC\n D = DELTA / 3.D0\n\n SCLCTR(1) = D * ( IVERTS(1,1) + IVERTS(1,2) + IVERTS(1,3) ) \n SCLCTR(2) = D * ( IVERTS(2,1) + IVERTS(2,2) + IVERTS(2,3) ) \n SCLCTR(3) = D * ( IVERTS(3,1) + IVERTS(3,2) + IVERTS(3,3) ) \n \nC\nC Compute the offsets of the vertices from the centroid CTROID;\nC scale each offset by (1+DELTA). The Ith expanded vertex is\nC\nC CTROID + (1+DELTA) * ( IVERTS(*,I) - CTROID )\nC\nC which can be re-written as\nC\nC ( (1+DELTA) * IVERTS(*,I) ) - ( DELTA * CTROID )\nC\nC or\nC\nC ( (1+DELTA) * IVERTS(*,I) ) - SCLCTR\nC\nC\nC\n S = 1.D0 + DELTA\n\n\n OVERTS(1,1) = ( S * IVERTS(1,1) ) - SCLCTR(1) \n OVERTS(2,1) = ( S * IVERTS(2,1) ) - SCLCTR(2) \n OVERTS(3,1) = ( S * IVERTS(3,1) ) - SCLCTR(3) \n\n OVERTS(1,2) = ( S * IVERTS(1,2) ) - SCLCTR(1) \n OVERTS(2,2) = ( S * IVERTS(2,2) ) - SCLCTR(2) \n OVERTS(3,2) = ( S * IVERTS(3,2) ) - SCLCTR(3) \n\n OVERTS(1,3) = ( S * IVERTS(1,3) ) - SCLCTR(1) \n OVERTS(2,3) = ( S * IVERTS(2,3) ) - SCLCTR(2) \n OVERTS(3,3) = ( S * IVERTS(3,3) ) - SCLCTR(3) \n\n END\n", "meta": {"hexsha": "fa8c3d5755cb295df90e9dca0ab3467968f12666", "size": 8594, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/pltexp.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/pltexp.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/pltexp.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": 30.3674911661, "max_line_length": 72, "alphanum_fraction": 0.5770304864, "num_tokens": 2840, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308147331957, "lm_q2_score": 0.7217432062975979, "lm_q1q2_score": 0.6736973490825158}} {"text": "Let Nat = forall A. (A -> A) -> A -> A in\nlet Z: Nat = Lambda A. lambda f: A -> A. lambda x: A. x in\nlet S: Nat -> Nat = lambda n: Nat. Lambda A. lambda f: A -> A. lambda x: A. f (n [A] f x) in\nlet add: Nat -> Nat -> Nat = lambda n: Nat. lambda m: Nat. n [Nat] S m in\nlet mult: Nat -> Nat -> Nat = lambda n: Nat. lambda m: Nat. n [Nat] (add m) Z in\nlet two: Nat = mult (S Z) (S (S Z)) in\ntwo", "meta": {"hexsha": "bd10fa3eff165d182687914a95ee65fb2958ac90", "size": 391, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/peano.f", "max_stars_repo_name": "eperdew/System-F", "max_stars_repo_head_hexsha": "a617159e6007561fa94b8d2e8cdcc33100f0fc42", "max_stars_repo_licenses": ["MIT"], "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/peano.f", "max_issues_repo_name": "eperdew/System-F", "max_issues_repo_head_hexsha": "a617159e6007561fa94b8d2e8cdcc33100f0fc42", "max_issues_repo_licenses": ["MIT"], "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/peano.f", "max_forks_repo_name": "eperdew/System-F", "max_forks_repo_head_hexsha": "a617159e6007561fa94b8d2e8cdcc33100f0fc42", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.8571428571, "max_line_length": 92, "alphanum_fraction": 0.5549872123, "num_tokens": 154, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294983, "lm_q2_score": 0.721743200312399, "lm_q1q2_score": 0.6736973408226283}} {"text": " SUBROUTINE FBRUS(N,X,Y,F,RPAR,IPAR)\nC ------ BRUSSELATOR WITH DIFFUSION IN D2 ----\n IMPLICIT REAL*8 (A-H,O-Z)\n DIMENSION Y(N),F(N)\n COMMON /COUNT / NFCN \n COMMON/TRANS/ALF,NS,NSSQ,NSNSM1,NSM1SQ\n NFCN=NFCN+1\nC ---- CONSTANTS FOR INHOMOGENITY ---\n ANS=NS\n RADSQ=0.1D0**2\n IF(X.GE.1.1D0)THEN\n BET=5.00D0\n ELSE\n BET=0.00D0\n END IF\nC ------- GRANDE BOUCLE -----\n DO I=1,NSSQ\nC ------- LEFT NEIGHBOUR ---\n IF(MOD(I,NS).EQ.1)THEN\n ULEFT=Y(I+NS-1)\n VLEFT=Y(NSSQ+I+NS-1)\n ELSE\n ULEFT=Y(I-1)\n VLEFT=Y(NSSQ+I-1)\n END IF\nC ------- RIGHT NEIGHBOUR ---\n IF(MOD(I,NS).EQ.0)THEN\n URIGHT=Y(I-NS+1)\n VRIGHT=Y(NSSQ+I-NS+1)\n ELSE\n URIGHT=Y(I+1)\n VRIGHT=Y(NSSQ+I+1)\n END IF\nC ------- LOWER NEIGHBOUR ---\n IF(I.LE.NS)THEN\n ULOW=Y(I+NSNSM1)\n VLOW=Y(NSSQ+I+NSNSM1)\n ELSE\n ULOW=Y(I-NS)\n VLOW=Y(NSSQ+I-NS)\n END IF\nC ------- UPPER NEIGHBOUR ---\n IF(I.GT.NSNSM1)THEN\n UUP=Y(I-NSNSM1)\n VUP=Y(NSSQ+I-NSNSM1)\n ELSE\n UUP=Y(I+NS)\n VUP=Y(NSSQ+I+NS)\n END IF\nC ------ LA DERIVEE --------\n UIJ=Y(I)\n VIJ=Y(I+NSSQ)\n F(I)=1.D0+UIJ*UIJ*VIJ-4.4D0*UIJ\n & +ALF*NSSQ*(ULEFT+URIGHT+ULOW+UUP-4.D0*UIJ)\n F(I+NSSQ)=3.4D0*UIJ - UIJ*UIJ*VIJ\n & +ALF*NSSQ*(VLEFT+VRIGHT+VLOW+VUP-4.D0*VIJ)\nC ----- INHOMOGENITE ----\n IY=(I-1)/NS+1\n IX=I-(IY-1)*NS\n YY=IY/ANS\n XX=IX/ANS\n IF(((XX-0.3D0)**2+(YY-0.6D0)**2).LE.RADSQ)THEN\n F(I)=F(I)+BET\n END IF\n END DO\n RETURN\n END\nC\n SUBROUTINE JBRUS(N,X,Y,DFY,LDFY,RPAR,IPAR)\nC --- IN THE CASE THAT DC_DECSOL_2D.F IS USED, NO JACOBIAN\nC --- HAS TO BE SPECIFIED. THEREFORE THIS DUMMY SUBROUTINE\n IMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION Y(N),DFY(LDFY,N)\nc\n return\nc\n END\nC\n SUBROUTINE JBRUSF(N,X,Y,DFY,LDFY,RPAR,IPAR)\nC --- JACOBIAN OF BRUSS-2D (FULL)\n IMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION Y(N),DFY(LDFY,N)\n COMMON/TRANS/ALF,NS,NSSQ,NSNSM1,NSM1SQ\n FAC=ALF*NSSQ\n DO I=1,N\n DO J=1,N\n DFY(I,J)=0.0D0\n END DO\n DFY(I,I)=-FAC*4.0D0\n END DO\n DO I=1,N\n IL=I-1\n IF (MOD(I,NS).EQ.1) IL=I-1+NS\n DFY(I,IL)=FAC\n IR=I+1\n IF (MOD(I,NS).EQ.0) IR=I+1-NS\n DFY(I,IR)=FAC\n IU=I+NS\n IF (I.GT.NS*(NS-1).AND.I.LE.NS*NS) IU=I-NS*(NS-1)\n IF (I.GT.NS*(2*NS-1)) IU=I-NS*(NS-1)\n DFY(I,IU)=FAC\n ID=I-NS\n IF (I.LE.NS) ID=I+NS*(NS-1)\n IF (I.LE.NS*(NS+1).AND.I.GT.NS*NS) ID=I+NS*(NS-1)\n DFY(I,ID)=FAC\n END DO\n RETURN\n END\n\n", "meta": {"hexsha": "6f1a5e51afe3d04034bb6c005ed4ae93fad5b7e8", "size": 2999, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/br2d_equation.f", "max_stars_repo_name": "cpmech/hwode", "max_stars_repo_head_hexsha": "7a6c033ace96b8b8dcf564ba0f38dd501fe2f60d", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tests/br2d_equation.f", "max_issues_repo_name": "cpmech/hwode", "max_issues_repo_head_hexsha": "7a6c033ace96b8b8dcf564ba0f38dd501fe2f60d", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/br2d_equation.f", "max_forks_repo_name": "cpmech/hwode", "max_forks_repo_head_hexsha": "7a6c033ace96b8b8dcf564ba0f38dd501fe2f60d", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.2636363636, "max_line_length": 61, "alphanum_fraction": 0.4541513838, "num_tokens": 1184, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467738423874, "lm_q2_score": 0.766293653760418, "lm_q1q2_score": 0.6736845935193669}} {"text": "module equation_solvers\n use utils, only: fp,ip\n !use hamiltonians ! To fix compilation bug with fclass\n use fclass\n\n abstract interface\n subroutine nonlin_solver(f,x0,x,tol_in,maxiter_in,status,dx_in)\n use fclass\n use utils\n implicit none\n class(fd),intent(in) :: f\n complex(fp), dimension(:),intent(in) :: x0\n complex(fp), dimension(:),intent(out) :: x\n real(fp),optional,intent(in) :: tol_in\n integer(ip),optional,intent(in) :: maxiter_in\n integer(ip),optional,intent(out) :: status\n real(fp),optional,intent(in) :: dx_in\n end subroutine nonlin_solver\n end interface\ncontains\n ! Solves the equation f(x) - x = 0, i.e. it does not have the standard form.\n subroutine picard_iteration(f,x0,x,tol_in,maxiter_in,status,dx_in)\n implicit none\n class(fd),intent(in) :: f\n complex(fp), dimension(:),intent(in) :: x0\n complex(fp), dimension(size(x0)),intent(out) :: x\n real(fp),optional,intent(in) :: tol_in\n integer(ip),optional,intent(in) :: maxiter_in\n real(fp) :: delta,tol\n complex(fp),dimension(size(x0)) :: xn\n integer(ip) :: maxiter,niter\n integer(ip),optional,intent(out) :: status\n integer(ip) :: status_temp\n real(fp),optional,intent(in) :: dx_in\n \n if(present(tol_in)) then\n tol = tol_in\n else\n tol = 1.0_fp\n end if\n\n if(present(maxiter_in)) then\n maxiter = maxiter_in\n else\n maxiter = 5000\n end if\n\n delta = huge(1.0_fp)\n xn = x0\n x = xn\n niter = 0\n\n do\n if(delta < tol) then\n !write(*,*) 'niter', niter,', delta',delta\n status_temp = 0\n exit ! We are done\n end if\n if(niter > maxiter) then\n !write(*,*) 'Warning, maximum number of iterations reached in picard solver. Required tolerance not reached.'\n status_temp = 1\n exit\n endif\n call f%value_at(0.0_fp,xn,x)\n delta = real(sqrt(sum((x - xn)*conjg(x-xn))))\n xn = x\n niter = niter+1\n end do\n if(present(status)) then\n status = status_temp\n end if\n end subroutine picard_iteration\n!------------------------------------------------------------!\n subroutine quasi_newton(f,x0,x,tol_in,maxiter_in,status,dx_in)\n use linfuncs\n implicit none\n class(fd),intent(in) :: f\n complex(fp), dimension(:),intent(in) :: x0\n complex(fp), dimension(size(x0)),intent(out) :: x\n real(fp),optional,intent(in) :: tol_in\n integer(ip),optional,intent(in) :: maxiter_in\n real(fp),optional,intent(in) :: dx_in\n integer(ip),optional,intent(out) :: status\n real(fp) :: delta,tol,dx\n complex(fp),dimension(size(x0)) :: xn\n integer(ip) :: maxiter,niter\n integer(ip) :: status_temp,status_dgesv\n real(fp),dimension(2*size(x0),2*size(x0)) :: J\n real(fp),dimension(2*size(x0)) :: b\n real(fp),dimension(2*size(x0)) :: bt\n complex(fp),dimension(size(x0)) :: fx\n integer(ip),dimension(2*size(x0)) :: ipiv\n\n if(present(tol_in)) then\n tol = tol_in\n else\n tol = 1.0_fp\n end if\n\n if(present(maxiter_in)) then\n maxiter = maxiter_in\n else\n maxiter = 100\n end if\n\n if(present(dx_in)) then\n dx = dx_in\n else\n dx = 0.1_fp\n endif\n\n xn = x0\n x = x0\n\n delta = huge(1.0_fp)\n niter = 0\n do\n if(delta < tol) then\n !write(*,*) 'niter', niter,', delta',delta\n status_temp = 0\n exit ! We are done\n end if\n\n if(niter > maxiter) then\n write(*,*) 'Warning, maximum number of iterations reached in quasi newton. Required tolerance not reached.'\n !write(*,*) 'niter', niter,', delta',delta\n status_temp = 1\n exit\n endif\n call f%value_at(0.0_fp,xn,fx)\n b(1:size(x0)) = -real(fx)\n b((size(x0)+1):(2*size(x0))) = -aimag(fx)\n bt = b\n J = jacobian_approximation_complex(f,x,dx)\n !SUBROUTINE DGESV( N, NRHS, A, LDA, IPIV, B, LDB, INFO )\n call dgesv(size(2*x0),1,J,size(2*x0),ipiv,b,size(2*x0),status_dgesv)\n !write(*,*) b\n if(status_dgesv .ne. 0) then\n status_temp = 2\n write(*,*) 'dgesv could not find solution to the system of equations in quasi-newton. Status:', status_dgesv\n !call print_matrix(J)\n !write(*,*) b\n exit\n endif\n x = xn + b(1:size(x0)) + (0.0_fp,1.0_fp)*b((1+size(x0)):(2*size(x0)))\n !delta = real(sqrt(sum((x - xn)*conjg(x-xn))))\n delta = sqrt(sum((matmul(J,b) - bt)**2))\n xn = x\n niter = niter+1\n !call print_matrix(J)\n write(*,*) delta\n write(*,*) b\n !write(*,*) x\n end do\n if(present(status)) then\n status = status_temp\n end if\nend subroutine quasi_newton\n!------------------------------------------------------------!\nsubroutine quasi_newton_real(f,x0,x,tol_in,maxiter_in,status,dx_in)\n use linfuncs\n implicit none\n class(fd),intent(in) :: f\n complex(fp), dimension(:),intent(in) :: x0\n complex(fp), dimension(size(x0)),intent(out) :: x\n real(fp),optional,intent(in) :: tol_in\n integer(ip),optional,intent(in) :: maxiter_in\n real(fp),optional,intent(in) :: dx_in\n integer(ip),optional,intent(out) :: status\n real(fp) :: delta,tol,dx\n complex(fp),dimension(size(x0)) :: xn\n integer(ip) :: maxiter,niter\n integer(ip) :: status_temp,status_dgesv\n real(fp),dimension(size(x0),size(x0)) :: J\n real(fp),dimension(size(x0)) :: b\n real(fp),dimension(size(x0)) :: bt\n complex(fp),dimension(size(x0)) :: fx\n integer(ip),dimension(size(x0)) :: ipiv\n\n if(present(tol_in)) then\n tol = tol_in\n else\n tol = 1.0_fp\n end if\n\n if(present(maxiter_in)) then\n maxiter = maxiter_in\n else\n maxiter = 100\n end if\n\n if(present(dx_in)) then\n dx = dx_in\n else\n dx = 0.1_fp\n endif\n\n xn = x0\n x = x0\n\n delta = huge(1.0_fp)\n niter = 0\n do\n if(delta < tol) then\n !write(*,*) 'niter', niter,', delta',delta\n status_temp = 0\n exit ! We are done\n end if\n\n if(niter > maxiter) then\n write(*,*) 'Warning, maximum number of iterations reached in quasi-newton. Required tolerance not reached.'\n !write(*,*) 'niter', niter,', delta',delta\n status_temp = 1\n exit\n endif\n call f%value_at(0.0_fp,xn,fx)\n b = -real(fx)\n !write(*,*) 'b:', b\n !b((size(x0)+1):(2*size(x0))) = -aimag(fx)\n bt = b ! need a copy because dgesv destroys the original b\n call jacobian_approximation_real(f,x,dx,J)\n !call print_matrix(J)\n !SUBROUTINE DGESV( N, NRHS, A, LDA, IPIV, B, LDB, INFO )\n call dgesv(size(x0),1,J,size(x0),ipiv,b,size(x0),status_dgesv)\n !write(*,*) 'dgesv result:', b\n if(status_dgesv .ne. 0) then\n status_temp = 2\n write(*,*) 'dgesv could not find solution to the system of equations in quasi-newton. Status:', status_dgesv\n !call print_matrix(J)\n !write(*,*) b\n exit\n endif\n x = xn + b\n !delta = real(sqrt(sum((x - xn)*conjg(x-xn))))\n delta =sum(real(b)**2)\n !delta = sqrt(sum((matmul(J,b) - bt)**2))\n \n xn = x\n niter = niter+1\n !write(*,*) 'niter',niter\n !call print_matrix(J)\n !write(*,*) delta\n !write(*,*) b\n !write(*,*) x\n end do\n if(present(status)) then\n status = status_temp\n end if\n end subroutine quasi_newton_real\n!------------------------------------------------------------!\nsubroutine spectral_real(f,x0,x,tol_in,maxiter_in,status,dx_in)\n use linfuncs\n implicit none\n class(fd),intent(in) :: f\n complex(fp), dimension(:),intent(in) :: x0\n complex(fp), dimension(:),intent(out) :: x\n real(fp),optional,intent(in) :: tol_in\n integer(ip),optional,intent(in) :: maxiter_in\n real(fp),optional,intent(in) :: dx_in\n integer(ip),optional,intent(out) :: status\n real(fp) :: delta,tol,dx\n integer(ip) :: maxiter,niter,status_temp\n complex(fp),dimension(size(x0)) :: xn,sn\n complex(fp),dimension(size(x0)) :: fn,yn,fn1\n real(fp) :: alpha\n integer(ip) :: c1,c2\n\n if(present(tol_in)) then\n tol = tol_in\n else\n tol = 1.0_fp\n end if\n\n if(present(maxiter_in)) then\n maxiter = maxiter_in\n else\n maxiter = 100\n end if\n\n if(present(dx_in)) then\n dx = dx_in\n else\n dx = 0.1_fp\n endif\n\n xn = x0\n x = x0\n \n !write(*,*) 'x0', x0\n delta = huge(1.0_fp)\n niter = 0\n \n \n do\n !call system_clock(c1)\n if(niter .eq. 0) then\n call f%value_at(0.0_fp,xn,fn1)\n alpha = min(1.0_fp,1.0_fp/sqrt(real(sum(conjg(fn1)*fn1))))\n if(isnan(alpha)) then\n delta = 0.0_fp ! sum(fn* *fn) = 0\n endif\n \n !write(*,*) 'x0',x0\n !write(*,*) 'fn1',fn1\n end if\n \n if(delta < tol) then\n status_temp = 0\n write(*,*) 'niter', niter,', delta',delta\n exit ! we are done\n end if\n \n if(niter > maxiter) then\n write(*,*) 'Warning, maximum number of iterations reached in spectral solver. Required tolerance not reached.'\n status_temp = 1\n exit\n endif\n \n x = xn - alpha*fn1\n delta = sqrt(real(sum(conjg(fn1)*fn1)))\n\n sn = x - xn\n\n xn = x\n fn = fn1\n\n call f%value_at(0.0_fp,x,fn1)\n yn = fn1 - fn\n alpha = real(sum(conjg(sn)*sn))/real(sum(conjg(sn)*yn))\n !alpha = real(sum(conjg(sn)*yn))/real(sum(conjg(yn)*yn))\n niter = niter + 1\n !write(*,*) 'niter', niter,', delta',delta,', alpha',alpha\n ! write(*,*) 'sn^T*sn',real(sum(conjg(sn)*sn)), ', sn^T*yn', real(sum(conjg(sn)*yn))\n ! write(*,*) 'x',x\n ! write(*,*) 'fn1',fn1\n !call system_clock(c2)\n !write(*,*) 'Duration of one iteration in spectral_real',c2-c1,'ms.'\n end do\n if(present(status)) then\n status = status_temp\n end if\nend subroutine spectral_real\n!------------------------------------------------------------!\n! Finds the roots of equation f(x) = 0 by using the quasi-newton method, by approximating the Jacobian using the Broyden formula. The Jacobian is not fully calculated, but it is updated during every iteration. Consumes more memory than the spectral method.\nsubroutine broyden_real(f,x0,x,tol_in,maxiter_in,status,dx_in)\n use linfuncs\n implicit none\n class(fd),intent(in) :: f\n complex(fp), dimension(:),intent(in) :: x0\n complex(fp), dimension(size(x0)),intent(out) :: x\n real(fp),optional,intent(in) :: tol_in\n integer(ip),optional,intent(in) :: maxiter_in\n real(fp),optional,intent(in) :: dx_in\n integer(ip),optional,intent(out) :: status\n real(fp) :: delta,tol,dx,delta_x\n integer(ip) :: maxiter,niter,status_temp,status_dgesv\n complex(fp),dimension(size(x0)) :: xn\n complex(fp),dimension(size(x0)) :: fn,fn1\n real(fp),dimension(size(x0),size(x0)) :: J,Jt\n real(fp),dimension(size(x0)) :: bn\n integer(ip),dimension(size(x0)) :: ipiv\n integer(ip) :: c1,c2\n\n if(present(tol_in)) then\n tol = tol_in\n else\n tol = 1.0_fp\n end if\n\n if(present(maxiter_in)) then\n maxiter = maxiter_in\n else\n maxiter = 100\n end if\n\n if(present(dx_in)) then\n dx = dx_in\n else\n dx = 0.1_fp\n endif\n\n xn = x0\n x = x0\n\n !write(*,*) 'x0', x0\n delta = huge(1.0_fp)\n niter = 0\n\n !J = get_eye(size(x0))\n call jacobian_diagonal_real(f,xn,dx,J)\n call f%value_at(0.0_fp,xn,fn)\n !call print_matrix(J)\n !bn = -real(fn)\n delta = sqrt(sum(bn*bn))\n\n do\n if(delta < tol) then\n write(*,*) 'niter', niter,', delta',delta\n status_temp = 0\n exit ! We are done\n end if\n if(niter > maxiter) then\n write(*,*) 'Warning, maximum number of iterations reached in quasi-newton. Required tolerance not reached.'\n !write(*,*) 'niter', niter,', delta',delta\n status_temp = 1\n exit\n endif\n !write(*,*) 'niter', niter,', delta',delta\n Jt = J\n bn = -real(fn)\n call dgesv(size(x0),1,Jt,size(x0),ipiv,bn,size(x0),status_dgesv)\n if(status_dgesv .ne. 0) then\n status_temp = 2\n write(*,*) 'dgesv could not find solution to the system of equations in quasi-newton. Status:', status_dgesv\n !call print_matrix(J)\n !write(*,*) bn\n exit\n endif\n\n x = xn + bn\n call f%value_at(0.0_fp,x,fn1)\n !write(*,*) 'J before'\n !call print_matrix(J)\n !write(*,*) 'addition'\n !call print_matrix(matmul(reshape(fn1 - fn - matmul(J,bn),[size(x0),1]),reshape(bn,[1,size(x0)]))/sum(bn**2))\n !write(*,*) 'sum bn',sum(bn**2)\n J = J + matmul(reshape(fn1 - fn - matmul(J,bn),[size(x0),1]),reshape(bn,[1,size(x0)]))/sum(bn**2)\n !write(*,*) 'J after'\n !call print_matrix(J)\n !write(*,*) 'bn',bn\n !write(*,*) 'fn1',fn1\n !write(*,*) 'fn',fn\n !write(*,*) 'fn1-fn - J*bn',reshape(fn1 - fn - matmul(J,bn),[size(x0),1])\n !write(*,*) 'bn^T',reshape(bn,[1,size(x0)])\n delta = sqrt(real(sum(conjg(fn1)*fn1)))\n !delta_x = sqrt(sum(bn*bn))\n !write(*,*) bn\n !write(*,*) x\n fn = fn1\n xn = x\n niter = niter+1\n !call print_matrix(J)\n !write(*,*) 'x:',x\n !write(*,*) 'bn',bn\n !write(*,*) 'J:'\n !call print_matrix(J)\n end do\n if(present(status)) then\n status = status_temp\n end if\nend subroutine broyden_real\n\n !#############################################\n ! This function calculates the Jacobian of the given function at x using dx as the step in difference. Works only for time independent functions f.\nfunction jacobian_approximation_complex(f,x,dx) result(J)\n use linfuncs\n use fclass\n implicit none\n class(fd),intent(in) :: f\n complex(fp),dimension(:),intent(in) :: x\n real(fp),intent(in) :: dx\n real(fp),dimension(size(x)*2,size(x)*2) :: J\n integer(ip) :: ii,jj,nn,kk\n complex(fp),dimension(size(x)) :: fxdx,fx\n complex(fp),dimension(size(x)) :: zv\n J = 0.0_fp\n nn = size(x)\n call f%value_at(0.0_fp,x,fx) ! Makes the calculation at t=0\n !write(*,*) 'fx:',fx\n do ii=1,nn\n do jj=1,2\n zv = (0.0_fp,0.0_fp) ! This is not very efficient\n zv(ii) = (0.0_fp,1.0_fp)**(jj-1)*dx\n write(*,*) 'zv(ii):',zv(ii)\n call f%value_at(0.0_fp,x+zv,fxdx)\n \n !write(*,*) 'fxdx:',fxdx\n ! Calculates the difference, and takes either the real or the imaginary part of it.\n fxdx = (fxdx - fx)/dx\n !J(((nn*(jj-1)+1)):(nn*jj),ii) = real((0.0_fp,1.0_fp)**(jj-1)*(fxdx - fx)/dx)\n J(((nn*(jj-1)+1)):(nn*jj),ii) = real(fxdx)\n J(((nn*(jj-1)+1)):(nn*jj),nn+ii) = aimag(fxdx)\n \n if(jj .eq. 1) then\n write(*,*) 'Changing the ',ii,':th real element. The effect is:'\n do kk=1,nn\n write(*,*) real(fxdx(kk)) + (0.0_fp,1.0_fp)*aimag(fxdx(kk))\n end do\n \n else\n write(*,*) 'Changing the ',ii,':th imag element. The effect is:' \n do kk=1,nn\n write(*,*) real(fxdx(kk)) + (0.0_fp,1.0_fp)*aimag(fxdx(kk))\n end do\n endif\n !call print_matrix(J)\n !write(*,*) (0.0_fp,1.0_fp)**(jj-1)*(fxdx - fx)/dx\n !write(*,*) ((nn*(jj-1)+1)), ':',(nn*jj)\n !call print_matrix(J)\n end do\n end do\n end function jacobian_approximation_complex\n !#############################################\n subroutine jacobian_approximation_real(f,x,dx,J)\n use linfuncs\n use fclass\n implicit none\n class(fd),intent(in) :: f\n complex(fp),dimension(:),intent(in) :: x\n real(fp),intent(in) :: dx\n real(fp),dimension(size(x),size(x)),intent(out) :: J\n integer(ip) :: ii,jj,nn,kk\n complex(fp),dimension(size(x)) :: fxdx,fx\n complex(fp),dimension(size(x)) :: zv\n J = 0.0_fp\n nn = size(x)\n !write(*,*) 'Entering function.'\n call f%value_at(0.0_fp,x,fx) ! Makes the calculation at t=0\n !write(*,*) 'x',x\n !write(*,*) 'fx:',fx\n do ii=1,nn\n zv = (0.0_fp,0.0_fp) ! This is not very efficient\n zv(ii) = dx\n !write(*,*) 'zv(ii):',zv(ii)\n !write(*,*) 'x+zv',x+zv\n call f%value_at(0.0_fp,x+zv,fxdx)\n \n !write(*,*) 'fxdx:',fxdx\n ! Calculates the difference, and takes either the real or the imaginary part of it.\n fxdx = (fxdx - fx)/dx\n !write(*,*) 'fxdx',real(fxdx)\n !J(((nn*(jj-1)+1)):(nn*jj),ii) = real((0.0_fp,1.0_fp)**(jj-1)*(fxdx - fx)/dx)\n J(:,ii) = real(fxdx)\n !write(*,*) 'J(:,ii)',J(:,ii)\n ! write(*,*) 'Changing the ',ii,':th real element. The effect is:'\n ! do kk=1,nn\n ! write(*,*) real(fxdx(kk))\n ! end do\n\n !call print_matrix(J)\n !write(*,*) (0.0_fp,1.0_fp)**(jj-1)*(fxdx - fx)/dx\n !write(*,*) ((nn*(jj-1)+1)), ':',(nn*jj)\n end do\n end subroutine jacobian_approximation_real\n\n !#############################################\n subroutine jacobian_diagonal_real(f,x,dx,J)\n use linfuncs\n use fclass\n implicit none\n class(fd),intent(in) :: f\n complex(fp),dimension(:),intent(in) :: x\n real(fp),intent(in) :: dx\n real(fp),dimension(size(x),size(x)),intent(out) :: J\n integer(ip) :: nn,ii\n complex(fp),dimension(size(x)) :: fx,fxdx\n complex(fp),dimension(size(x)) :: zv\n\n !zv = (0.0_fp,0.0_fp)\n nn = size(x)\n J = 0.0_fp\n call f%value_at(0.0_fp,x,fx) ! Makes the calculation at t=0\n zv = dx\n call f%value_at(0.0_fp,x+zv,fxdx)\n\n !write(*,*) 'fxdx:',fxdx\n ! Calculates the difference, and takes either the real or the imaginary part of it.\n fxdx = (fxdx - fx)/dx\n !write(*,*) 'fxdx',real(fxdx)\n do ii=1,nn\n J(ii,ii) = real(fxdx(ii))\n end do\n end subroutine jacobian_diagonal_real\n\nend module equation_solvers\n", "meta": {"hexsha": "ef6c5a21d3c5ae2be0e6892a38e03b3813b6e0f0", "size": 17628, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/equation_solvers.f90", "max_stars_repo_name": "ittnas/qsc", "max_stars_repo_head_hexsha": "5e23c7f0c2985d79b966f8301a17c2679a5f2c8d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-23T09:41:11.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-23T09:41:11.000Z", "max_issues_repo_path": "src/equation_solvers.f90", "max_issues_repo_name": "ittnas/qsc", "max_issues_repo_head_hexsha": "5e23c7f0c2985d79b966f8301a17c2679a5f2c8d", "max_issues_repo_licenses": ["MIT"], "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/equation_solvers.f90", "max_forks_repo_name": "ittnas/qsc", "max_forks_repo_head_hexsha": "5e23c7f0c2985d79b966f8301a17c2679a5f2c8d", "max_forks_repo_licenses": ["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.6041666667, "max_line_length": 256, "alphanum_fraction": 0.5607556161, "num_tokens": 5708, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146761176671, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6736845791215011}} {"text": "#include \"eiscor.h\"\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! ZARCG33 (Zomplex Auxiliary Routine Compute Givens generators 3->3)\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! This routine computes the generator for a Givens rotation represented\n! by 3 real numbers: the real and imaginary parts of a complex cosine\n! and a scrictly real sine. The first column is constructed to be \n! parallel with the complex vector [A,B]^T. The (3->3) refers to the \n! 3 double inputs and 3 double outputs (excluding the norm).\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! INPUT VARIABLES:\n!\n! AR, AI REAL(8) \n! real and imaginary part of the first component \n! of the complex vector [A,B]^T\n!\n! B REAL(8) \n! the second component of the complex vector [A,B]^T\n!\n! OUTPUT VARIABLES:\n!\n! CR, CI REAL(8)\n! on exit contAIns the generators for the cosine\n! component of the Givens rotation\n!\n! S REAL(8)\n! on exit contAIns the generators for the sine\n! component of the Givens rotation\n!\n! NRM REAL(8)\n! on exit contAIns the norm of the vector [A,B]^T\n!\n! INFO INTEGER\n! INFO = 0 implies successful computation\n! INFO = -1 implies AR is invalid\n! INFO = -2 implies AI is invalid\n! INFO = -3 implies B is invalid\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine ZARCG33(AR,AI,B,CR,CI,S,NRM,INFO)\n\n implicit none\n \n ! input variables\n integer, intent(inout) :: INFO\n real(8), intent(in) :: AR, AI, B\n real(8), intent(inout) :: CR, CI, S, NRM\n \n ! compute variables\n real(8) :: tar, tai, tb\n real(8) :: nar, nai, nb\n real(8), parameter :: tol = epsilon(1d0)\n \n ! initialize INFO\n INFO = 0\n\n ! check error in debug mode\n if (DEBUG) then\n \n ! check AR\n call DARNAN(AR,INFO)\n if (INFO.NE.0) then\n call UARERR(__FILE__,__LINE__,\"AR is invalid\",INFO,-1)\n return\n end if\n call DARINF(AR,INFO)\n if (INFO.NE.0) then\n call UARERR(__FILE__,__LINE__,\"AR is invalid\",INFO,-1)\n return\n end if \n\n ! check AI\n call DARNAN(AI,INFO)\n if (INFO.NE.0) then\n call UARERR(__FILE__,__LINE__,\"AI is invalid\",INFO,-2)\n return\n end if\n call DARINF(AI,INFO)\n if (INFO.NE.0) then\n call UARERR(__FILE__,__LINE__,\"AI is invalid\",INFO,-2)\n return\n end if \n\n ! check B\n call DARNAN(B,INFO)\n if (INFO.NE.0) then\n call UARERR(__FILE__,__LINE__,\"B is invalid\",INFO,-3)\n return\n end if\n call DARINF(B,INFO)\n if (INFO.NE.0) then\n call UARERR(__FILE__,__LINE__,\"B is invalid\",INFO,-3)\n return\n end if\n\n end if\n\n ! set local variables\n nar = abs(AR)\n nai = abs(AI)\n nb = abs(B)\n NRM = 1d0\n \n if(nar.EQ.0 .AND. nai.EQ.0 .AND. nb.EQ.0)then\n CR = 1d0\n CI = 0d0\n S = 0d0\n NRM = 0d0\n else if(nb.EQ.0 .AND. nar > nai)then\n tai = AI/AR\n NRM = sqrt(1d0 + tai*tai)\n if(AR < 0)then\n CR = -1d0/NRM\n CI = tai*CR\n S = 0d0\n NRM = -AR*NRM\n else\n CR = 1d0/NRM\n CI = tai*CR\n S = 0d0\n NRM = AR*NRM\n end if\n else if(nb.EQ.0)then\n tar = AR/AI\n NRM = sqrt(1d0 + tar*tar)\n if(AI < 0)then\n CI = -1d0/NRM\n CR = tar*CI\n S = 0d0\n NRM = -AI*NRM\n else\n CI = 1d0/NRM\n CR = tar*CI\n S = 0d0\n NRM = AI*NRM\n end if\n else if(nar >= nb .AND. nar >= nai)then\n tb = B/AR\n tai = AI/AR\n NRM = sqrt(1d0 + tb*tb + tai*tai)\n if(AR < 0)then\n CR = -1d0/NRM\n CI = tai*CR\n S = tb*CR\n NRM = -AR*NRM\n else\n CR = 1d0/NRM\n CI = tai*CR\n S = tb*CR\n NRM = AR*NRM\n end if\n else if(nai >= nb .AND. nai >= nar)then\n tb = B/AI\n tar = AR/AI\n NRM = sqrt(1d0 + tb*tb + tar*tar)\n if(AI < 0)then\n CI = -1d0/NRM\n CR = tar*CI\n S = tb*CI\n NRM = -AI*NRM\n else\n CI = 1d0/NRM\n CR = tar*CI\n S = tb*CI\n NRM = AI*NRM\n end if\n else\n tar = AR/B\n tai = AI/B\n NRM = sqrt(1d0 + tai*tai + tar*tar)\n if(B < 0)then\n S = -1d0/NRM\n CR = tar*S\n CI = tai*S\n NRM = -B*NRM\n else\n S = 1d0/NRM\n CR = tar*S\n CI = tai*S\n NRM = B*NRM\n end if\n end if\n\nend subroutine ZARCG33\n", "meta": {"hexsha": "fbbea6d179ac427e8e826f49d16b4122a82ab3e5", "size": 4509, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "deps/eiscor-master/src/complex_double/ZARCG33.f90", "max_stars_repo_name": "andreasnoack/EiSCor.jl", "max_stars_repo_head_hexsha": "d03d217e30e006b35263b99cb4adafd9d7e1e973", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "deps/eiscor-master/src/complex_double/ZARCG33.f90", "max_issues_repo_name": "andreasnoack/EiSCor.jl", "max_issues_repo_head_hexsha": "d03d217e30e006b35263b99cb4adafd9d7e1e973", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "deps/eiscor-master/src/complex_double/ZARCG33.f90", "max_forks_repo_name": "andreasnoack/EiSCor.jl", "max_forks_repo_head_hexsha": "d03d217e30e006b35263b99cb4adafd9d7e1e973", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.7315789474, "max_line_length": 71, "alphanum_fraction": 0.497671324, "num_tokens": 1533, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467643431002, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6736845721635002}} {"text": "! =====================================================================\n! subroutine VSHO \n!\n! This subroutine constructs a simple harmonic oscillator potential.\n! --------------------------------------------------------------------- \n subroutine VSHO(nRP,nR,nP,x0,y0,kX,kY,R,P,V)\n implicit none\n\n integer :: nRP\n integer :: nR\n integer :: nP\n double precision :: x0 \n double precision :: y0 \n double precision :: kX\n double precision :: kY\n double precision :: R(nR)\n double precision :: P(nP)\n double precision :: V(nRP)\n\n integer :: i\n integer :: j\n integer :: k\n\n k = 0\n do j = 1, nP\n do i = 1, nR\n k = k + 1\n V(k) = 0.5d0*(kX*(R(i)*dcos(P(j))-x0))**2\n V(k) = V(k) + 0.5d0*(kY*(R(i)*dsin(P(j))-y0))**2\n enddo\n enddo\n\n return\n end\n! =====================================================================\n", "meta": {"hexsha": "8fd2c8a05670516130d6f0d651668a40c403a53e", "size": 955, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/vsho.f", "max_stars_repo_name": "mkandes/itpprp", "max_stars_repo_head_hexsha": "d30f4fc0b05822a34fef187688ab12245cbbf93a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source/vsho.f", "max_issues_repo_name": "mkandes/itpprp", "max_issues_repo_head_hexsha": "d30f4fc0b05822a34fef187688ab12245cbbf93a", "max_issues_repo_licenses": ["MIT"], "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/vsho.f", "max_forks_repo_name": "mkandes/itpprp", "max_forks_repo_head_hexsha": "d30f4fc0b05822a34fef187688ab12245cbbf93a", "max_forks_repo_licenses": ["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.5277777778, "max_line_length": 72, "alphanum_fraction": 0.3842931937, "num_tokens": 249, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554444, "lm_q2_score": 0.7606506635289836, "lm_q1q2_score": 0.6736561727941994}} {"text": " PROGRAM CALCULATE\t!A distance, with error propagation.\n REAL X1, Y1, X2, Y2\t!The co-ordinates.\n REAL X1E,Y1E,X2E,Y2E\t!Their standard deviation.\n DATA X1, Y1 ,X2, Y2 /100., 50., 200.,100./\t!Specified\n DATA X1E,Y1E,X2E,Y2E/ 1.1, 1.2, 2.2, 2.3/\t!Values.\n REAL DX,DY,D2,D,DXE,DYE,E\t!Assistants.\n CHARACTER*1 C\t\t\t!I'm stuck with code page 437 instead of 850.\n PARAMETER (C = CHAR(241))\t\t!Thus \u00b1 does not yield this glyph on a \"console\" screen. CHAR(241) does.\n REAL SD\t!This is an arithmetic statement function.\n SD(X,P,S) = P*ABS(X)**(P - 1)*S\t!SD for X**P where SD of X is S\n WRITE (6,1) X1,C,X1E,Y1,C,Y1E,\t!Reveal the points\n 1 X2,C,X2E,Y2,C,Y2E\t!Though one could have used an array...\n 1 FORMAT (\"Euclidean distance between two points:\"/\t!A heading.\n 1 (\"(\",F5.1,A1,F3.1,\",\",F5.1,A1,F3.1,\")\"))\t\t!Thus, One point per line.\n DX = (X1 - X2)\t\t\t!X difference.\n DXE = SQRT(X1E**2 + X2E**2)\t!SD for DX, a simple difference.\n DY = (Y1 - Y2)\t\t\t!Y difference.\n DYE = SQRT(Y1E**2 + Y2E**2)\t!SD for DY, (Y1 - Y2)\n D2 = DX**2 + DY**2\t\t!The distance, squared.\n DXE = SD(DX,2,DXE)\t\t!SD for DX**2\n DYE = SD(DY,2,DYE)\t\t!SD for DY**2\n E = SQRT(DXE**2 + DYE**2)\t\t!SD for their sum\n D = SQRT(D2)\t\t\t!The distance!\n E = SD(D2,0.5,E)\t\t\t!SD after the SQRT.\n WRITE (6,2) D,C,E\t\t\t!Ahh, the relief.\n 2 FORMAT (\"Distance\",F6.1,A1,F4.2)\t!Sizes to fit the example.\n END\t!Enough.\n", "meta": {"hexsha": "93e34444995181bc8f075fafc019dedd8ede7726", "size": 1491, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Numeric-error-propagation/Fortran/numeric-error-propagation-1.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Numeric-error-propagation/Fortran/numeric-error-propagation-1.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Numeric-error-propagation/Fortran/numeric-error-propagation-1.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 53.25, "max_line_length": 105, "alphanum_fraction": 0.5700871898, "num_tokens": 614, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.885631470799559, "lm_q2_score": 0.7606506418255928, "lm_q1q2_score": 0.6736561466846283}} {"text": "module cosine_zenith\n\ncontains\n\nsubroutine calc_cosine_zenith(now_time, im, latitude, longitude, cosz, julian)\n\nuse machine , only : kind_phys\nuse time_utilities\n\nimplicit none\n\ndouble precision :: now_time, sec_since\ninteger :: im\nreal, dimension(im) :: latitude, longitude\nreal(kind=kind_phys), dimension(im) :: cosz\nreal(kind=kind_phys) :: julian\nreal :: obecl, sinob, sxlong, arg, tloctim, hrang, declin\ninteger :: ihour, iminute, isecond, iloc\ncharacter*19 :: now_date ! format: yyyy-mm-dd hh:nn:ss\n\nreal, parameter :: degrad = 3.14159265/180.\nreal, parameter :: dpd = 360./365.\n\ncall date_from_since(\"1970-01-01 00:00:00\", now_time, now_date)\n\ncall calc_sec_since(now_date(1:4)//\"-01-01 00:00:00\", now_date, 0, sec_since)\n\nread(now_date(12:13), *) ihour\nread(now_date(15:16), *) iminute\nread(now_date(18:19), *) isecond\n\njulian = sec_since/86400.0\n\n!-----obecl : obliquity = 23.5 degree.\n\nobecl = 23.5*degrad\nsinob = sin(obecl)\n\n!-----calculate longitude of the sun from vernal equinox:\n\nif(julian >= 80.) sxlong = dpd*(julian -80.)*degrad\nif(julian < 80.) sxlong = dpd*(julian+285.)*degrad\narg = sinob*sin(sxlong)\ndeclin = asin(arg)\n\ndo iloc = 1, im\n tloctim = real(ihour) + real(iminute)/60.0 + real(isecond)/3600.0 + longitude(iloc)/15.0 ! local time in hours\n tloctim = amod(tloctim+24.0, 24.0)\n hrang = 15.*(tloctim-12.)*degrad\n cosz(iloc) = sin(latitude(iloc)*degrad)*sin(declin)+cos(latitude(iloc)*degrad)*cos(declin)*cos(hrang)\nend do\n\nend subroutine calc_cosine_zenith\n\nend module cosine_zenith\n", "meta": {"hexsha": "b0ecd9466546463300b94086c0ea9f98fe4b90b1", "size": 1583, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "bundle/ucland/utils/src/module_cosine_zenith.f90", "max_stars_repo_name": "JCSDA-internal/UCLDAS", "max_stars_repo_head_hexsha": "0b343072b51373bc271b0d8105733bd863b1dbb0", "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": "bundle/ucland/utils/src/module_cosine_zenith.f90", "max_issues_repo_name": "JCSDA-internal/UCLDAS", "max_issues_repo_head_hexsha": "0b343072b51373bc271b0d8105733bd863b1dbb0", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-05-21T20:21:16.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-06T17:52:34.000Z", "max_forks_repo_path": "bundle/ucland/utils/src/module_cosine_zenith.f90", "max_forks_repo_name": "JCSDA-internal/ucldas", "max_forks_repo_head_hexsha": "0b343072b51373bc271b0d8105733bd863b1dbb0", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.2678571429, "max_line_length": 112, "alphanum_fraction": 0.6854074542, "num_tokens": 547, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012701768145, "lm_q2_score": 0.7122321842389469, "lm_q1q2_score": 0.6736301045140028}} {"text": "program matrix_products\n implicit none\n\n interface\n subroutine mat_mul_1(mat_a,mat_b,mat_c,debug)\n real*8, intent(out):: mat_c(:,:)\n real*8, intent(in):: mat_a(:,:), mat_b(:,:)\n logical:: debug\n end subroutine\n end interface\n \n interface\n subroutine mat_mul_2(mat_a,mat_b,mat_c,debug)\n real*8, intent(out):: mat_c(:,:)\n real*8, intent(in):: mat_a(:,:), mat_b(:,:)\n logical:: debug\n end subroutine\n end interface\n \n real*8, allocatable :: A(:,:), B(:,:), C(:,:), D(:,:), E(:,:)\n integer*4 :: iterations, min_N, max_N, ii, jj, kk = 1, errors, slice_size = 5\n real*4 :: start, finish\n real*4, allocatable :: timing(:,:)\n logical :: write_every_n = .False., debug = .False.\n \n write(*,*) \"Enter the timing iterations and the range of rows the test matrices should have\"\n read(*,*) iterations, min_N, max_N\n\n ! Validating that at least one timing iteration is performed.\n ! By construction, this also validates that the number of iterations is a positive integer.\n if (iterations .lt. 1) stop \"The number of iterations should be at least one\"\n \n ! Validating that the minimum number of rows is at least 2.\n if (min_N .lt. 2) stop \"The minimum number of rows for the square matrices must be at least 2\"\n ! Validating that the maximum number of rows is higher than the minimum number of rows.\n ! Applied sequentually with the validation above, this guarantees max_N is a positive integer.\n if (max_N .le. min_N) stop \"The maximum number of rows for the square matrices must be higher than the minimum number of rows.\"\n \n ! Allocate the timing array.\n allocate(timing(min_N:max_N,0:3),stat=errors)\n ! Validate the allocation was successful.\n ! Most likely cause for unsuccessful allocation is lack of memory.\n ! A very wide gap between min_N and max_N may lead to this behaviour\n if (errors.ne.0) then\n write(*,*) \"Unable to allocate array for timing.\"\n write(*,*) \"Writing to file performances every_slice size steps.\"\n write_every_n = .True.\n else if (write_every_n .eqv. .False.) then\n kk = min_N\n end if\n\n ! Performing outside the earlier control in case write_every_n is initialized as .True. for debugging\n if (write_every_n) then\n deallocate(timing)\n allocate(timing(1:slice_size,0:3))\n end if\n\n ! Finally, validate the maximum matrix size is not too big for allocation\n ! Since we're allocating five matrices for the timing, we take as proxy a (5*max_N)x(max_N) array\n allocate(A(1:5*max_N,1:max_N), stat = errors)\n if (errors.ne.0) stop \"ERROR: Allocation issues. Try a smaller upper bound for the number of rows.\"\n deallocate(A)\n\n ! Open the file to store the performance data.\n open(15,file = \"performance.dat\")\n\n ! Generating two square random matrices, from min_N x min_N to max_N x max_N\n do ii = min_N, max_N\n ! \"input size\"\n timing(kk,0) = ii\n \n ! Allocate all the matrices using the new size\n allocate(A(1:ii,1:ii))\n allocate(B(1:ii,1:ii))\n allocate(D(1:ii,1:ii))\n allocate(E(1:ii,1:ii))\n allocate(C(1:ii,1:ii))\n \n ! Populate the arrays with uniformly distributed values\n call random_number(A)\n call random_number(B)\n \n \n !----------------------\n ! Timing products\n !----------------------\n ! Measuring performance of the first product definition\n call cpu_time(start)\n do jj = 1, iterations\n call mat_mul_1(A,B,C,debug)\n end do\n call cpu_time(finish)\n timing(kk,1) = (finish-start)/iterations\n \n ! Measuring performance of the second product definition\n ! Transposing and storing before entering the timing loop\n D = transpose(B)\n E = transpose(A)\n call cpu_time(start)\n do jj = 1, iterations\n call mat_mul_2(D,E,C,debug) ! This gives us C transpose\n end do\n call cpu_time(finish)\n timing(kk,2) = (finish-start)/iterations\n \n ! Measuring performance of built-in product definition\n call cpu_time(start)\n do jj = 1, iterations\n C = matmul(A,B)\n end do\n call cpu_time(finish)\n timing(kk,3) = (finish-start)/iterations\n \n ! Release the variables for the incoming allocation\n deallocate(A)\n deallocate(B)\n deallocate(D)\n deallocate(E)\n deallocate(C)\n\n ! Write to file when slice_size timing rows have been reached\n ! or when we have reached the maximum number of matrix's rows.\n if (write_every_n .and. (kk .eq. slice_size .or. ii .eq. max_N)) then\n ! Write up until the collected value.\n do jj = 1, kk\n write(15,*) timing(jj,0:3)\n end do\n ! set kk to zero, so that right after the control it is set to one.\n kk = 0\n end if\n ! Increase kk, usually the same as taking ii, but handled for sliced timings.\n kk = kk + 1\n end do\n \n ! Write the performance measurements\n if (write_every_n .eqv. .False.) then\n do ii = min_N, max_N\n write(15,*) timing(ii,0:3)\n end do\n end if\n close(15)\n write(*,*) \"Averaged timings of operations successfully computed and written to file.\"\n \nend program matrix_products\n \n!--------------------------------\n! Subroutines for matrix products\n!--------------------------------\n\nsubroutine mat_mul_1(mat_a,mat_b,mat_c, debug)\n implicit none\n real*8, intent(in):: mat_a(:,:), mat_b(:,:)\n real*8, intent(out) :: mat_c(:,:)\n integer*4:: M,N,O,P,ii,jj,kk\n real*8:: cumulative\n integer*4:: shape_a(2), shape_b(2)\n logical:: debug\n \n shape_a = shape(mat_a)\n shape_b = shape(mat_b)\n M = shape_a(1)\n N = shape_a(2)\n O = shape_b(1)\n P = shape_b(2)\n\n ! Validate the matrices shapes are compatible\n if (debug .and. (N .ne. O)) stop \"Input matrices sizes are not compatible for multiplication\"\n\n do ii = 1,M\n do jj = 1, P\n cumulative = 0.d0\n do kk = 1, N\n cumulative = cumulative + mat_a(ii,kk)*mat_b(kk,jj)\n end do\n mat_c(ii,jj) = cumulative\n end do\n end do\n \nend subroutine\n \n \nsubroutine mat_mul_2(mat_a,mat_b, mat_c, debug)\n implicit none\n real*8, intent(in):: mat_a(:,:), mat_b(:,:)\n real*8, intent(out) :: mat_c(:,:)\n integer*4:: M,N,O,P,ii,jj,kk\n real*8:: cumulative\n integer*4:: shape_a(2), shape_b(2)\n logical:: debug\n\n shape_a = shape(mat_a)\n shape_b = shape(mat_b)\n M = shape_a(1)\n N = shape_a(2)\n O = shape_b(1)\n P = shape_b(2)\n\n ! Validate the matrices shapes are compatible\n if (debug .and. (N .ne. O)) stop \"Input matrices sizes are not compatible for multiplication\"\n\n do jj = 1,P\n do ii = 1, M\n cumulative = 0.d0\n do kk = 1, N\n cumulative = cumulative + mat_a(ii,kk)*mat_b(kk,jj)\n end do\n mat_c(ii,jj) = cumulative\n end do\n end do\n \nend subroutine\n \n \n ", "meta": {"hexsha": "c12738e97e16e1b9551aed566b7043bdf9faa199", "size": 7247, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "week_3/scaling/products_reload.f90", "max_stars_repo_name": "eigen-carmona/quantum-computation-unipd", "max_stars_repo_head_hexsha": "f53b40bd83cb85119ce4b494e10e01b256917659", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2022-01-11T19:41:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-05T19:22:24.000Z", "max_issues_repo_path": "week_3/scaling/products_reload.f90", "max_issues_repo_name": "eigen-carmona/quantum-computation-unipd", "max_issues_repo_head_hexsha": "f53b40bd83cb85119ce4b494e10e01b256917659", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "week_3/scaling/products_reload.f90", "max_forks_repo_name": "eigen-carmona/quantum-computation-unipd", "max_forks_repo_head_hexsha": "f53b40bd83cb85119ce4b494e10e01b256917659", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.8644859813, "max_line_length": 131, "alphanum_fraction": 0.5936249483, "num_tokens": 1900, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430562234878, "lm_q2_score": 0.8104789063814617, "lm_q1q2_score": 0.6736239152545581}} {"text": " subroutine min_max(LEX,ximf,spmax,spmin,nmax,nmin)\n!------------------------------------------------------------------\n! This is a routine to define maxima and minima from series ximf.\n! All the extrema are defined as the corresponding values of\n! ximf in spmax and spmin. All non-extrema values in spmax and\n! spmin are defined as 1.0e31.\n!------------------------------------------------------------------\n implicit none\n\n integer, intent(in):: LEX\n real, dimension(LEX), intent(in):: ximf\n real, dimension(LEX), intent(out):: spmax, spmin\n integer, intent(out):: nmax, nmin\n integer:: i\n \n nmax=0\n nmin=0\n\n spmax(1)=ximf(1)\n spmax(LEX)=ximf(LEX)\n spmin(1)=spmax(1)\n spmin(LEX)=spmax(LEX)\n\n nmax=2\n nmin=2\n\n do i=2,LEX-1\n if(ximf(i) > ximf(i-1) .and. ximf(i) >= ximf(i+1)) then\n spmax(i) = ximf(i)\n nmax = nmax+1\n else\n spmax(i)=1.0e31\n endif\n if(ximf(i) < ximf(i-1) .and. ximf(i) <= ximf(i+1)) then\n spmin(i)=ximf(i)\n nmin=nmin+1\n else\n spmin(i)=1.0e31\n endif\n enddo\n\n call endmax(LEX, spmax, nmax)\n call endmin(LEX, spmin, nmin)\n\n end subroutine min_max\n\n!****************************************************************\n\n subroutine endmax(LEX, temp, nmax)\n!--------------------------------------------------------------------\n! This is a subroutine to determine end values of the upper envolope\n! using the method described in Appendix B of Wu and Huang (2009, \n! AADA, Vol. 1, pp1).\n!--------------------------------------------------------------------\n implicit none\n\n integer, intent(in) :: nmax, LEX\n real, dimension(LEX), intent(inout):: temp \n real, dimension(nmax) :: exmax, X\n integer :: I, J, lend\n real :: slope1, slope2, tmp1, tmp2\n \n lend=nmax\n\n J=1\n DO I=1, LEX\n IF( temp(I).LT.1.0E30 ) THEN\n X(J)=float(I)\n exmax(J)=temp(I)\n J=J+1\n ENDIF\n ENDDO\n\n if (nmax >= 4) then\n slope1=(exmax(2)-exmax(3))/(X(2)-X(3))\n tmp1=slope1*(X(1)-X(2))+exmax(2)\n if(tmp1 > exmax(1)) then\n temp(1)=tmp1\n endif\n \n slope2=(exmax(lend-1)-exmax(lend-2))/(X(lend-1)-X(lend-2))\n tmp2=slope2*(X(lend)-X(lend-1))+exmax(lend-1)\n if(tmp2 > exmax(lend)) then\n temp(LEX)=tmp2\n endif\n endif\n \n end subroutine endmax\n\n\n!****************************************************************\n\n subroutine endmin(LEX, temp, nmax)\n!--------------------------------------------------------------------\n! This is a subroutine to determine end values of the lower envolope\n! using the method described in Appendix B of Wu and Huang (2009, \n! AADA, Vol. 1, pp1).\n!--------------------------------------------------------------------\n implicit none\n\n integer, intent(in) :: nmax, LEX\n real, dimension(LEX), intent(inout):: temp \n real, dimension(nmax) :: exmax, X\n integer :: I, J, lend\n real :: slope1, slope2, tmp1, tmp2\n \n lend=nmax\n\n J=1\n DO I=1, LEX\n IF( temp(I).LT.1.0E30 ) THEN\n X(J)=float(I)\n exmax(J)=temp(I)\n J=J+1\n ENDIF\n ENDDO\n\n if (nmax >= 4) then\n slope1=(exmax(2)-exmax(3))/(X(2)-X(3))\n tmp1=slope1*(X(1)-X(2))+exmax(2)\n if(tmp1 < exmax(1)) then\n temp(1)=tmp1\n endif\n \n slope2=(exmax(lend-1)-exmax(lend-2))/(X(lend-1)-X(lend-2))\n tmp2=slope2*(X(lend)-X(lend-1))+exmax(lend-1)\n if(tmp2 < exmax(lend)) then\n temp(LEX)=tmp2\n endif\n endif\n \n end subroutine endmin\n\n\n\n", "meta": {"hexsha": "73b98163d6e08631788fd1c109efb0c3c3375ea4", "size": 3756, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "eemdf90/min_max.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/min_max.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/min_max.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": 27.6176470588, "max_line_length": 69, "alphanum_fraction": 0.4584664537, "num_tokens": 1131, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619885, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.6736126546612554}} {"text": "program complex2\ncomplex :: x\nx = (3.0, 4.0)\nx = x + 4.0\nprint *, x\nx = 2.0 + x\nprint *, x\nx = 2.0 + x + (0.0, 3.0)\nprint *, x\nend program\n", "meta": {"hexsha": "bafe650bfb833f0fae09c50df82dbcff235f75b6", "size": 139, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/complex2.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/complex2.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": "tests/complex2.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": 12.6363636364, "max_line_length": 24, "alphanum_fraction": 0.5179856115, "num_tokens": 72, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8577680977182186, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.6736126518598637}} {"text": "!===============================================================================\n! One of Andy Nowacki's Fortran utility modules for dealing with seismic\n! anisotropy and other problems.\n!\n! Andy Nowacki \n!\n! See the file LICENCE for licence details.\n!===============================================================================\nprogram sph_rand\n!===============================================================================\n! Randomly sample a sphere.\n! This program takes samples one at a time and writes them out as it goes,\n! rather than allocating memory for all points at once, to save memory in case\n! of very large numbers of points.\n! Output is lon, lat in degrees.\n\n use spherical_geometry\n\n implicit none\n integer :: n = 100\n real(8) :: lon, lat\n character(len=250) :: arg\n integer :: i, iostat\n\n ! Check args and get n if necessary\n if (command_argument_count() > 1) call usage\n if (command_argument_count() == 1) then\n call get_command_argument(1, arg)\n if (arg(1:2) == '-h') call usage\n read(arg, *, iostat=iostat) n\n if (iostat /= 0) then\n write(0,'(a)') 'sph_rand: Error: Cannot get n from first argument \"' &\n //trim(arg)//'\"'\n call usage\n endif\n endif\n\n do i = 1, n\n call sg_random_point_geog(lon, lat, degrees=.true.)\n write(*,*) lon, lat\n enddo\n\ncontains\n\n subroutine usage\n write(0,'(a)') &\n 'Usage: sph_rand (n)', &\n 'Randomly take points on a sphere with uniform probability density.', &\n 'If specified, first argument defines the number of points.', &\n 'Output is lon, lat (degrees).'\n stop\n end subroutine usage\nend program sph_rand\n!-------------------------------------------------------------------------------\n", "meta": {"hexsha": "b7f9df7fb513068385374438f5faabac47e04199", "size": 1804, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "progs/src/sph_rand.f90", "max_stars_repo_name": "JackWalpole/seismo-fortran-fork", "max_stars_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2015-06-23T05:28:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T03:46:07.000Z", "max_issues_repo_path": "progs/src/sph_rand.f90", "max_issues_repo_name": "JackWalpole/seismo-fortran-fork", "max_issues_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2017-05-17T11:02:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-28T09:36:24.000Z", "max_forks_repo_path": "progs/src/sph_rand.f90", "max_forks_repo_name": "JackWalpole/seismo-fortran-fork", "max_forks_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-04-15T02:55:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-20T12:20:51.000Z", "avg_line_length": 32.8, "max_line_length": 80, "alphanum_fraction": 0.5293791574, "num_tokens": 419, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950868503681, "lm_q2_score": 0.7981867777396212, "lm_q1q2_score": 0.673585900123393}} {"text": "program main\n ! inits\n implicit none\n integer :: iterations\n integer :: sum_total = 0\n integer :: counter = 0\n real :: rand, e = 0\n\n real :: temp = 0\n integer :: inner_counter\n\n ! print no new line\n write(*,\"(A)\",advance=\"no\") \"Number of iterations: \"\n read *, iterations\n \n ! main iteration loop\n do while (counter < iterations)\n temp = 0\n inner_counter = 0\n ! inner loop\n do while (temp < 1)\n call random_number(rand)\n temp = rand + temp\n inner_counter = inner_counter + 1\n end do\n\n sum_total = sum_total + inner_counter\n counter = counter + 1\n end do\n\n ! approximates e\n e = real(sum_total) / real(iterations)\n ! print e\n print *, \"e = \", e\nend program main", "meta": {"hexsha": "a4c087221daf8781816d183f21534db2330df895", "size": 799, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran.f90", "max_stars_repo_name": "bclehmann/e-for-dinosaurs", "max_stars_repo_head_hexsha": "0f7269c511926ebf2141563bfd561010784cfc32", "max_stars_repo_licenses": ["MIT"], "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.f90", "max_issues_repo_name": "bclehmann/e-for-dinosaurs", "max_issues_repo_head_hexsha": "0f7269c511926ebf2141563bfd561010784cfc32", "max_issues_repo_licenses": ["MIT"], "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.f90", "max_forks_repo_name": "bclehmann/e-for-dinosaurs", "max_forks_repo_head_hexsha": "0f7269c511926ebf2141563bfd561010784cfc32", "max_forks_repo_licenses": ["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.8285714286, "max_line_length": 56, "alphanum_fraction": 0.5531914894, "num_tokens": 212, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319862, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6735504721468093}} {"text": "program test_model_ar2\n\n use forlab, only: disp, file\n use forlab, only: mean\n use fortsa_model, only: ar_init, ar_exec, &\n ar_summary, ar_predict, &\n ar_free\n use fortsa_model, only: yw, burg, hr\n use stdlib_error, only: error_stop\n implicit none\n integer :: i, d, L\n integer :: p, q, line_num\n real(8), allocatable :: phi(:), theta(:)\n type(file) :: infile\n real(8), allocatable :: inp(:)\n real(8) :: wmean\n real(8) :: var\n !! mean var\n\n p = 7\n d = 1\n q = 0\n\n L = 5\n\n infile = file('example/data/seriesA.txt')\n if (.not. infile%exist()) call error_stop('Error: file not exist, '//infile%filename)\n call infile%open()\n line_num = infile%countlines()\n allocate (inp(line_num), phi(p))\n\n do i = 1, line_num\n read (infile%unit, *) inp(i)\n end do\n\n wmean = mean(inp)\n !! forlab mean\n\n print *, 'AR Coefficients Using Yule Walker Algorithm : '\n call yw(inp, line_num, p, phi, var)\n call disp(phi, 'PHI : ')\n call disp(var, 'VAR : ')\n\n print *, 'AR Coefficients Using Burg Algorithm : '\n call burg(inp, line_num, p, phi, var)\n call disp(phi, 'PHI : ')\n call disp(var, 'VAR : ')\n\n p = 1\n q = 1\n\n deallocate (phi)\n allocate (phi(p), theta(q))\n print *, 'ARMA Coefficients Using Hannan Rissanen Algorithm : '\n call hr(inp, line_num, p, q, phi, theta, var)\n call disp(phi, 'PHI : ')\n call disp(theta, 'THETA : ')\n call disp(var, 'VAR : ')\n\n deallocate (inp, phi, theta)\n call infile%close()\n\nend program test_model_ar2\n", "meta": {"hexsha": "714f076ff5cc66cb4859d399a735412f889138e6", "size": 1617, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/model/test_model_ar2.f90", "max_stars_repo_name": "zoziha/ForTSA", "max_stars_repo_head_hexsha": "227ae3ae1ca5f161aff2f5bcd3e10e218042acdb", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-06-20T10:27:32.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-24T14:52:05.000Z", "max_issues_repo_path": "test/model/test_model_ar2.f90", "max_issues_repo_name": "zoziha/fortsa", "max_issues_repo_head_hexsha": "227ae3ae1ca5f161aff2f5bcd3e10e218042acdb", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-06-17T18:37:38.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-24T14:52:35.000Z", "max_forks_repo_path": "test/model/test_model_ar2.f90", "max_forks_repo_name": "zoziha/fortsa", "max_forks_repo_head_hexsha": "227ae3ae1ca5f161aff2f5bcd3e10e218042acdb", "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.265625, "max_line_length": 89, "alphanum_fraction": 0.5689548547, "num_tokens": 489, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319862, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6735504721468093}} {"text": " real function SLNREL (X)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc>> 1994-10-20 SLNREL Krogh Changes to use M77CON\nc>> 1990-11-27 SLNREL WV Snyder Initial Code.\nc\nc Compute LOG(1+X).\nc\nc This procedure uses approximation 2707 from Hart, et. al. when\nc 1/sqrt(2) < 1+x < sqrt(2), and otherwise uses the Fortran\nc intrinsic logarithm routine.\nc\nc--S replaces \"?\": ?LNREL\n real X\n real P0, P1, P2, P3, P4, Q0, Q1, Q2, Q3, Z, ZSQ\n real BOT, TOP\n parameter (P0 = +0.75040 94990 77712 22174 55611 007 E+2 )\n parameter (P1 = -0.13456 69115 05043 02353 18253 537 E+3 )\n parameter (P2 = +0.74137 19213 24860 25127 79336 47 E+2 )\n parameter (P3 = -0.12772 49755 01233 08199 84385 E+2 )\n parameter (P4 = +0.33271 08381 08768 69381 44 E00 )\n parameter (Q0 = +0.37520 47495 38856 11087 27775 374 E+2 )\n parameter (Q1 = -0.79790 28073 71500 48794 39951 583 E+2 )\n parameter (Q2 = +0.56161 26132 11825 72920 58560 36 E+2 )\n parameter (Q3 = -0.14508 68091 85808 26853 62325 E+2 )\nc parameter (Q4 = +1.0 E00 )\n parameter (BOT = .70710 67811 86547 52440 E0 - 1.0E0 )\n parameter (TOP = 1.4142 13562 37309 50488 E0 - 1.0E0 )\nc\n if (x .lt. bot .or. x .gt. top) then\n slnrel = log(x+1.0e0)\n else\n z = x / (x+2.0e0)\n zsq = z*z\n slnrel = z * ((((p4*zsq+p3)*zsq+p2)*zsq+p1)*zsq+p0)/\n 1 (((( zsq+q3)*zsq+q2)*zsq+q1)*zsq+q0)\n end if\n return\n end\n", "meta": {"hexsha": "adeb9925678e96f5cd9379319dcc2d9a1229966a", "size": 1702, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/slnrel.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/slnrel.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/slnrel.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 41.512195122, "max_line_length": 70, "alphanum_fraction": 0.5705052879, "num_tokens": 666, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299653388752, "lm_q2_score": 0.7279754548076477, "lm_q1q2_score": 0.6735447048192318}} {"text": "module rheology_module\n\n use amrex_error_module, only: amrex_abort\n use amrex_fort_module, only : rt => amrex_real\n use constant, only: half, one\n use constant, only: mu, n, tau_0, eta_0, papa_reg, fluid_model\n\n implicit none\n\ncontains\n\n real(rt) function viscosity(sr) & \n bind(C, name=\"viscosity\")\n\n real(rt), value :: sr\n real(rt) :: nu\n\n if (fluid_model == \"newtonian\") then \n\n ! Viscosity is constant\n viscosity = mu\n\n else if (fluid_model == \"powerlaw\") then \n\n ! Power-law fluid: \n !\n ! eta = mu dot(gamma)^(n-1)\n viscosity = mu * sr**(n - one)\n\n else if (fluid_model == \"bingham\") then \n\n ! Papanastasiou-regularised Bingham fluid: \n !\n ! eta = mu + tau_0 (1 - exp(-dot(gamma) / eps)) / dot(gamma)\n nu = sr / papa_reg\n viscosity = mu + tau_0 * expterm(nu) / papa_reg\n\n else if (fluid_model == \"hb\") then \n\n ! Papanastasiou-regularised Herschel-Bulkley fluid: \n !\n ! eta = (mu dot(gamma)^n + tau_0) (1 - exp(-dot(gamma) / eps)) / dot(gamma)\n \n nu = sr / papa_reg\n viscosity = (mu * sr**n + tau_0) * expterm(nu) / papa_reg\n\n else if (fluid_model == \"smd\") then\n\n ! de Souza Mendes - Dutra fluid: \n !\n ! eta = (mu dot(gamma)^n + tau_0) (1 - exp(-eta_0 dot(gamma) / tau_0)) / dot(gamma)\n \n nu = eta_0 * sr / tau_0\n viscosity = (mu * sr**n + tau_0) * expterm(nu) * eta_0 / tau_0\n\n else\n\n ! This should have been caught earlier, but doesn't hurt to double check\n call amrex_abort(\"Unknown fluid_model! Choose either newtonian, powerlaw, bingham, hb, smd\")\n\n end if\n\n end function viscosity\n\n\n ! \n ! Compute the exponential term:\n !\n ! ( 1 - exp(-nu) ) / nu ,\n !\n ! making sure to avoid overflow for small nu by using the exponential Taylor series\n !\n real(rt) function expterm(nu)\n real(rt), intent(in) :: nu\n ! Avoid overflow \n if (nu .lt. 1.0e-9) then \n expterm = one - half * nu + nu**2 / 6.0d0 - nu**3 / 24.0d0\n else\n expterm = (one - exp(-nu)) / nu\n end if\n end function expterm\n\nend module rheology_module\n", "meta": {"hexsha": "8140ff8e5e2bf119a3ff0436aaa72423d8b8f3d2", "size": 2248, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/rheology/rheology_mod.f90", "max_stars_repo_name": "WeiqunZhang/incflo", "max_stars_repo_head_hexsha": "d72eb6e3c387704d06ceee686596337e5e9711d3", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/rheology/rheology_mod.f90", "max_issues_repo_name": "WeiqunZhang/incflo", "max_issues_repo_head_hexsha": "d72eb6e3c387704d06ceee686596337e5e9711d3", "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/rheology/rheology_mod.f90", "max_forks_repo_name": "WeiqunZhang/incflo", "max_forks_repo_head_hexsha": "d72eb6e3c387704d06ceee686596337e5e9711d3", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.7619047619, "max_line_length": 101, "alphanum_fraction": 0.5556049822, "num_tokens": 695, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765257642906, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6735241142452778}} {"text": "!###########################################################\n!###########################################################\n!###########################################################\n!###########################################################\nsubroutine phi_fine_cg(ilevel,icount)\n use amr_commons\n use pm_commons\n use poisson_commons\n implicit none\n#ifndef WITHOUTMPI\n include 'mpif.h'\n#endif\n integer::ilevel,icount\n !=========================================================\n ! Iterative Poisson solver with Conjugate Gradient method \n ! to solve A x = b\n ! r : stored in f(i,1)\n ! p : stored in f(i,2)\n ! A p: stored in f(i,3)\n ! x : stored in phi(i)\n ! b : stored in rho(i)\n !=========================================================\n integer::i,idim,info,ind,iter,iskip,itermax,nx_loc\n integer::idx\n real(dp)::error,error_ini\n real(dp)::dx2,fourpi,scale,oneoversix,fact,fact2\n real(dp)::r2_old,alpha_cg,beta_cg\n real(kind=8)::r2,pAp,rhs_norm,r2_all,pAp_all,rhs_norm_all\n\n if(gravity_type>0)return\n if(numbtot(1,ilevel)==0)return\n if(verbose)write(*,111)ilevel\n\n\n ! Set constants\n dx2=(0.5D0**ilevel)**2\n nx_loc=icoarse_max-icoarse_min+1\n scale=boxlen/dble(nx_loc)\n fourpi=4.D0*ACOS(-1.0D0)*scale\n if(cosmo)fourpi=1.5D0*omega_m*aexp*scale\n oneoversix=1.0D0/dble(twondim)\n fact=oneoversix*fourpi*dx2\n fact2 = fact*fact\n\n !===============================\n ! Compute initial phi\n !===============================\n if(ilevel>levelmin)then\n call make_initial_phi(ilevel,icount) ! Interpolate phi down\n else\n call make_multipole_phi(ilevel) ! Fill up with simple initial guess\n endif\n call make_virtual_fine_dp(phi(1),ilevel) ! Update boundaries\n call make_boundary_phi(ilevel) ! Update physical boundaries\n\n !===============================\n ! Compute right-hand side norm\n !===============================\n rhs_norm=0.d0\n do ind=1,twotondim\n iskip=ncoarse+(ind-1)*ngridmax\n do i=1,active(ilevel)%ngrid\n idx=active(ilevel)%igrid(i)+iskip\n rhs_norm=rhs_norm+fact2*(rho(idx)-rho_tot)*(rho(idx)-rho_tot)\n end do\n end do\n ! Compute global norms\n#ifndef WITHOUTMPI\n call MPI_ALLREDUCE(rhs_norm,rhs_norm_all,1,MPI_DOUBLE_PRECISION,MPI_SUM,&\n & MPI_COMM_WORLD,info)\n rhs_norm=rhs_norm_all\n#endif\n rhs_norm=DSQRT(rhs_norm/dble(twotondim*numbtot(1,ilevel)))\n\n !==============================================\n ! Compute r = b - Ax and store it into f(i,1)\n ! Also set p = r and store it into f(i,2)\n !==============================================\n call cmp_residual_cg(ilevel,icount)\n\n !====================================\n ! Main iteration loop\n !====================================\n iter=0; itermax=10000\n error=1.0D0; error_ini=1.0D0\n do while(error>epsilon*error_ini.and.iter= itermax)then\n if(myid==1)write(*,*)'Poisson failed to converge...'\n end if\n\n ! Update boundaries\n call make_virtual_fine_dp(phi(1),ilevel)\n\n111 format(' Entering phi_fine_cg for level ',I2)\n112 format(' ==> Step=',i5,' Error=',2(1pe10.3,1x))\n115 format(' ==> Level=',i5,' Step=',i5,' Error=',2(1pe10.3,1x))\n\nend subroutine phi_fine_cg\n!###########################################################\n!###########################################################\n!###########################################################\n!###########################################################\nsubroutine cmp_residual_cg(ilevel,icount)\n use amr_commons\n use pm_commons\n use hydro_commons\n use poisson_commons\n implicit none\n integer::ilevel,icount\n !------------------------------------------------------------------\n ! This routine computes the residual for the Conjugate Gradient\n ! Poisson solver. The residual is stored in f(i,1).\n !------------------------------------------------------------------\n integer::i,idim,igrid,ngrid,ncache,ind,iskip,nx_loc\n integer::id1,id2,ig1,ig2,ih1,ih2\n real(dp)::dx2,fourpi,scale,oneoversix,fact\n integer,dimension(1:3,1:2,1:8)::iii,jjj\n\n integer ,dimension(1:nvector),save::ind_grid,ind_cell\n integer ,dimension(1:nvector,0:twondim),save::igridn\n integer ,dimension(1:nvector,1:ndim),save::ind_left,ind_right\n real(dp),dimension(1:nvector,1:ndim),save::phig,phid\n real(dp),dimension(1:nvector,1:twotondim,1:ndim),save::phi_left,phi_right\n real(dp),dimension(1:nvector),save::residu\n\n ! Set constants\n dx2=(0.5D0**ilevel)**2\n nx_loc=icoarse_max-icoarse_min+1\n scale=boxlen/dble(nx_loc)\n fourpi=4.D0*ACOS(-1.0D0)*scale\n if(cosmo)fourpi=1.5D0*omega_m*aexp*scale\n oneoversix=1.0D0/dble(twondim)\n fact=oneoversix*fourpi*dx2\n\n iii(1,1,1:8)=(/1,0,1,0,1,0,1,0/); jjj(1,1,1:8)=(/2,1,4,3,6,5,8,7/)\n iii(1,2,1:8)=(/0,2,0,2,0,2,0,2/); jjj(1,2,1:8)=(/2,1,4,3,6,5,8,7/)\n iii(2,1,1:8)=(/3,3,0,0,3,3,0,0/); jjj(2,1,1:8)=(/3,4,1,2,7,8,5,6/)\n iii(2,2,1:8)=(/0,0,4,4,0,0,4,4/); jjj(2,2,1:8)=(/3,4,1,2,7,8,5,6/)\n iii(3,1,1:8)=(/5,5,5,5,0,0,0,0/); jjj(3,1,1:8)=(/5,6,7,8,1,2,3,4/)\n iii(3,2,1:8)=(/0,0,0,0,6,6,6,6/); jjj(3,2,1:8)=(/5,6,7,8,1,2,3,4/)\n\n ! Loop over myid grids by vector sweeps\n ncache=active(ilevel)%ngrid\n do igrid=1,ncache,nvector\n\n ! Gather nvector grids\n ngrid=MIN(nvector,ncache-igrid+1)\n do i=1,ngrid\n ind_grid(i)=active(ilevel)%igrid(igrid+i-1)\n end do\n\n ! Gather neighboring grids\n do i=1,ngrid\n igridn(i,0)=ind_grid(i)\n end do\n do idim=1,ndim\n do i=1,ngrid\n ind_left (i,idim)=nbor(ind_grid(i),2*idim-1)\n ind_right(i,idim)=nbor(ind_grid(i),2*idim )\n igridn(i,2*idim-1)=son(ind_left (i,idim))\n igridn(i,2*idim )=son(ind_right(i,idim))\n end do\n end do\n \n ! Interpolate potential from upper level\n do idim=1,ndim\n call interpol_phi(ind_left (1,idim),phi_left (1,1,idim),ngrid,ilevel,icount)\n call interpol_phi(ind_right(1,idim),phi_right(1,1,idim),ngrid,ilevel,icount)\n end do\n\n ! Loop over cells\n do ind=1,twotondim\n ! Gather neighboring potential\n do idim=1,ndim\n id1=jjj(idim,1,ind); ig1=iii(idim,1,ind)\n ih1=ncoarse+(id1-1)*ngridmax\n do i=1,ngrid\n if(igridn(i,ig1)>0)then\n phig(i,idim)=phi(igridn(i,ig1)+ih1)\n else\n phig(i,idim)=phi_left(i,id1,idim)\n end if\n end do\n id2=jjj(idim,2,ind); ig2=iii(idim,2,ind)\n ih2=ncoarse+(id2-1)*ngridmax\n do i=1,ngrid\n if(igridn(i,ig2)>0)then\n phid(i,idim)=phi(igridn(i,ig2)+ih2)\n else\n phid(i,idim)=phi_right(i,id2,idim)\n end if\n end do\n end do\n\n ! Compute central cell index\n iskip=ncoarse+(ind-1)*ngridmax\n do i=1,ngrid\n ind_cell(i)=iskip+ind_grid(i)\n end do\n\n ! Compute residual using 6 neighbors potential\n do i=1,ngrid\n residu(i)=phi(ind_cell(i))\n end do\n do idim=1,ndim\n do i=1,ngrid\n residu(i)=residu(i)-oneoversix*(phig(i,idim)+phid(i,idim))\n end do\n end do\n do i=1,ngrid\n residu(i)=residu(i)+fact*(rho(ind_cell(i))-rho_tot)\n end do\n\n ! Store results in f(i,1)\n do i=1,ngrid\n f(ind_cell(i),1)=residu(i)\n end do\n\n ! Store results in f(i,2)\n do i=1,ngrid\n f(ind_cell(i),2)=residu(i)\n end do\n\n end do\n ! End loop over cells\n\n end do\n ! End loop over grids\n\nend subroutine cmp_residual_cg\n!###########################################################\n!###########################################################\n!###########################################################\n!###########################################################\nsubroutine cmp_Ap_cg(ilevel)\n use amr_commons\n use pm_commons\n use hydro_commons\n use poisson_commons\n implicit none\n integer::ilevel\n !------------------------------------------------------------------\n ! This routine computes Ap for the Conjugate Gradient\n ! Poisson Solver and store the result into f(i,3).\n !------------------------------------------------------------------\n integer::i,idim,igrid,ngrid,ncache,ind,iskip\n integer::id1,id2,ig1,ig2,ih1,ih2\n real(dp)::oneoversix\n integer,dimension(1:3,1:2,1:8)::iii,jjj\n\n integer,dimension(1:nvector),save::ind_grid,ind_cell\n integer,dimension(1:nvector,0:twondim),save::igridn\n real(dp),dimension(1:nvector,1:ndim),save::phig,phid\n real(dp),dimension(1:nvector),save::residu\n\n ! Set constants\n oneoversix=1.0D0/dble(twondim)\n\n iii(1,1,1:8)=(/1,0,1,0,1,0,1,0/); jjj(1,1,1:8)=(/2,1,4,3,6,5,8,7/)\n iii(1,2,1:8)=(/0,2,0,2,0,2,0,2/); jjj(1,2,1:8)=(/2,1,4,3,6,5,8,7/)\n iii(2,1,1:8)=(/3,3,0,0,3,3,0,0/); jjj(2,1,1:8)=(/3,4,1,2,7,8,5,6/)\n iii(2,2,1:8)=(/0,0,4,4,0,0,4,4/); jjj(2,2,1:8)=(/3,4,1,2,7,8,5,6/)\n iii(3,1,1:8)=(/5,5,5,5,0,0,0,0/); jjj(3,1,1:8)=(/5,6,7,8,1,2,3,4/)\n iii(3,2,1:8)=(/0,0,0,0,6,6,6,6/); jjj(3,2,1:8)=(/5,6,7,8,1,2,3,4/)\n\n ! Loop over myid grids by vector sweeps\n ncache=active(ilevel)%ngrid\n do igrid=1,ncache,nvector\n\n ! Gather nvector grids\n ngrid=MIN(nvector,ncache-igrid+1)\n do i=1,ngrid\n ind_grid(i)=active(ilevel)%igrid(igrid+i-1)\n end do\n\n ! Gather neighboring grids\n do i=1,ngrid\n igridn(i,0)=ind_grid(i)\n end do\n do idim=1,ndim\n do i=1,ngrid\n igridn(i,2*idim-1)=son(nbor(ind_grid(i),2*idim-1))\n igridn(i,2*idim )=son(nbor(ind_grid(i),2*idim ))\n end do\n end do\n \n ! Loop over cells\n do ind=1,twotondim\n\n ! Gather neighboring potential\n do idim=1,ndim\n id1=jjj(idim,1,ind); ig1=iii(idim,1,ind)\n ih1=ncoarse+(id1-1)*ngridmax\n do i=1,ngrid\n if(igridn(i,ig1)>0)then\n phig(i,idim)=f(igridn(i,ig1)+ih1,2)\n else\n phig(i,idim)=0.\n end if\n end do\n id2=jjj(idim,2,ind); ig2=iii(idim,2,ind)\n ih2=ncoarse+(id2-1)*ngridmax\n do i=1,ngrid\n if(igridn(i,ig2)>0)then\n phid(i,idim)=f(igridn(i,ig2)+ih2,2)\n else\n phid(i,idim)=0.\n end if\n end do\n end do\n\n ! Compute central cell index\n iskip=ncoarse+(ind-1)*ngridmax\n do i=1,ngrid\n ind_cell(i)=iskip+ind_grid(i)\n end do\n\n ! Compute Ap using neighbors potential\n do i=1,ngrid\n residu(i)=-f(ind_cell(i),2)\n end do\n do idim=1,ndim\n do i=1,ngrid\n residu(i)=residu(i)+oneoversix*(phig(i,idim)+phid(i,idim))\n end do\n end do\n ! Store results in f(i,3)\n do i=1,ngrid\n f(ind_cell(i),3)=residu(i)\n end do\n\n end do\n ! End loop over cells\n\n end do\n ! End loop over grids\n\nend subroutine cmp_Ap_cg\n!###########################################################\n!###########################################################\n!###########################################################\n!###########################################################\nsubroutine make_initial_phi(ilevel,icount)\n use amr_commons\n use pm_commons\n use poisson_commons\n implicit none\n integer::ilevel,icount\n !\n !\n !\n integer::igrid,ncache,i,ngrid,ind,iskip,idim,ibound\n integer ,dimension(1:nvector),save::ind_grid,ind_cell,ind_cell_father\n real(dp),dimension(1:nvector,1:twotondim),save::phi_int\n\n ! Loop over myid grids by vector sweeps\n ncache=active(ilevel)%ngrid\n do igrid=1,ncache,nvector\n ! Gather nvector grids\n ngrid=MIN(nvector,ncache-igrid+1)\n do i=1,ngrid\n ind_grid(i)=active(ilevel)%igrid(igrid+i-1)\n end do\n \n if(ilevel==1)then\n ! Loop over cells\n do ind=1,twotondim\n iskip=ncoarse+(ind-1)*ngridmax\n do i=1,ngrid\n ind_cell(i)=iskip+ind_grid(i)\n end do\n do i=1,ngrid\n phi(ind_cell(i))=0.0d0\n end do\n do idim=1,ndim\n do i=1,ngrid\n f(ind_cell(i),idim)=0.0\n end do\n end do\n end do\n ! End loop over cells\n else\n ! Compute father cell index\n do i=1,ngrid\n ind_cell_father(i)=father(ind_grid(i))\n end do\n \n ! Interpolate\n call interpol_phi(ind_cell_father,phi_int,ngrid,ilevel,icount)\n \n ! Loop over cells\n do ind=1,twotondim\n iskip=ncoarse+(ind-1)*ngridmax\n do i=1,ngrid\n ind_cell(i)=iskip+ind_grid(i)\n end do\n do i=1,ngrid\n phi(ind_cell(i))=phi_int(i,ind)\n end do\n do idim=1,ndim\n do i=1,ngrid\n f(ind_cell(i),idim)=0.0\n end do\n end do\n end do\n ! End loop over cells\n end if\n\n end do\n ! End loop over grids\n\nend subroutine make_initial_phi\n!###########################################################\n!###########################################################\n!###########################################################\n!###########################################################\nsubroutine make_multipole_phi(ilevel)\n use amr_commons\n use pm_commons\n use poisson_commons\n implicit none\n integer::ilevel\n !\n !\n !\n integer::ibound,boundary_dir,idim,inbor\n integer::i,ncache,ivar,igrid,ngrid,ind\n integer::iskip,iskip_ref,gdim,nx_loc,ix,iy,iz\n integer,dimension(1:nvector),save::ind_grid,ind_cell\n\n real(dp)::dx,dx_loc,scale,fourpi,boxlen2,eps,r2\n real(dp),dimension(1:3)::skip_loc\n real(dp),dimension(1:twotondim,1:3)::xc\n real(dp),dimension(1:nvector),save::rr,pp\n real(dp),dimension(1:nvector,1:ndim),save::xx\n real(dp),dimension(1:nvector,1:ndim),save::ff\n\n\n ! Mesh size at level ilevel\n dx=0.5D0**ilevel\n\n ! Rescaling factors\n nx_loc=(icoarse_max-icoarse_min+1)\n skip_loc=(/0.0d0,0.0d0,0.0d0/)\n if(ndim>0)skip_loc(1)=dble(icoarse_min)\n if(ndim>1)skip_loc(2)=dble(jcoarse_min)\n if(ndim>2)skip_loc(3)=dble(kcoarse_min)\n scale=boxlen/dble(nx_loc)\n dx_loc=dx*scale\n fourpi=4.D0*ACOS(-1.0D0)\n boxlen2=boxlen**2\n eps=dx_loc\n\n ! Set position of cell centers relative to grid center\n do ind=1,twotondim\n iz=(ind-1)/4\n iy=(ind-1-4*iz)/2\n ix=(ind-1-2*iy-4*iz)\n if(ndim>0)xc(ind,1)=(dble(ix)-0.5D0)*dx\n if(ndim>1)xc(ind,2)=(dble(iy)-0.5D0)*dx\n if(ndim>2)xc(ind,3)=(dble(iz)-0.5D0)*dx\n end do\n\n ! Loop over myid grids by vector sweeps\n ncache=active(ilevel)%ngrid\n do igrid=1,ncache,nvector\n ! Gather nvector grids\n ngrid=MIN(nvector,ncache-igrid+1)\n do i=1,ngrid\n ind_grid(i)=active(ilevel)%igrid(igrid+i-1)\n end do\n \n ! Loop over cells\n do ind=1,twotondim\n iskip=ncoarse+(ind-1)*ngridmax\n do i=1,ngrid\n ind_cell(i)=iskip+ind_grid(i)\n end do\n \n if(simple_boundary)then\n ! Compute cell center in code units\n do idim=1,ndim\n do i=1,ngrid\n xx(i,idim)=xg(ind_grid(i),idim)+xc(ind,idim)\n end do\n end do\n\n ! Rescale position from code units to user units\n rr(1:ngrid)=0.0d0\n do idim=1,ndim\n do i=1,ngrid\n xx(i,idim)=(xx(i,idim)-skip_loc(idim))*scale\n rr(i)=rr(i)+(xx(i,idim)-multipole(idim+1)/multipole(1))**2\n end do\n end do\n\n do i=1,ngrid\n rr(i)=max(eps,sqrt(rr(i))) ! Cutoff\n end do\n\n if(ngrid>0) call phi_ana(rr,pp,ngrid)\n\n ! Scatter variables\n do i=1,ngrid\n phi(ind_cell(i))=pp(i)/scale\n end do\n\n else\n do i=1,ngrid\n phi(ind_cell(i))=0d0\n end do\n endif\n \n ! End loop over cells\n end do\n \n end do\n ! End loop over grids\n\nend subroutine make_multipole_phi\n", "meta": {"hexsha": "ded8cbc4150163bab96c4532f2f36e827f326a42", "size": 18877, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/amuse/community/ramses/src/poisson/phi_fine_cg.f90", "max_stars_repo_name": "rknop/amuse", "max_stars_repo_head_hexsha": "85d5bdcc29cfc87dc69d91c264101fafd6658aec", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-04-09T09:06:08.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-09T09:06:08.000Z", "max_issues_repo_path": "src/amuse/community/ramses/src/poisson/phi_fine_cg.f90", "max_issues_repo_name": "rknop/amuse", "max_issues_repo_head_hexsha": "85d5bdcc29cfc87dc69d91c264101fafd6658aec", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-06-22T13:02:14.000Z", "max_issues_repo_issues_event_max_datetime": "2018-09-06T20:08:43.000Z", "max_forks_repo_path": "src/amuse/community/ramses/src/poisson/phi_fine_cg.f90", "max_forks_repo_name": "rknop/amuse", "max_forks_repo_head_hexsha": "85d5bdcc29cfc87dc69d91c264101fafd6658aec", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-11-19T04:41:37.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-20T02:11:17.000Z", "avg_line_length": 30.3001605136, "max_line_length": 84, "alphanum_fraction": 0.5106213911, "num_tokens": 6134, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765163620469, "lm_q2_score": 0.7371581684030624, "lm_q1q2_score": 0.6735241073143372}} {"text": "\n!================================================================================\n! CONSTRUCCION DE UNA CONFIGURACION INICIAL REGULAR EN CELDA TRIDIMENSIONAL SIN\n! TRASLAPES\n! Autor: Martin Paredes Sosa\n!================================================================================\n\nModule cte\n Implicit None\n Real, Parameter :: sigma = 1.0\n Real :: Dens, BoxL\n Integer :: N\nEnd Module cte\n\nProgram ConfigIni\n Use cte\n Implicit None\n Real :: Dim, xij, yij, dBoxL, dist\n Real, Allocatable, Dimension(:) :: X,Y,Z !POSICIONES DE LAS PARTICULAS\n Integer :: i, j, k !CONTADOR\n Integer :: N2, N3 !PARTICULAS \n \n !PEDIR DENSIDAD Y NUMERO DE PARTICULAS\n Write(*,*) \"INGRESE EL NUMERO DE PARTICULAS\"\n Read(*,*) N\n Write(*,*) \"INGRESE CONCENTRACION REDUCIDA\"\n Read(*,*) Dens\n\n \n \n !CALCULANDO DIMENSIONES DE LA CAJA\n Dim = 3.0\n N2 =anint( N**(1.0/Dim) )\n BoxL = (1.0*N/Dens )**(1.0/Dim)\n N3 = N2*N2*N2\n Write(*,*) \"LONGITUD DE LA CELDA:\", BoxL\n Write(*,*) \"TOTAL DE PARTICULAS EN LA CELDA COLOCADAS:\", N3\n dBoxl = BoxL/N2\n \n \n Allocate( X(N2),Y(N2),Z(N2) )\n \n\n !BUSCANDO POSICIONES PARA LAS PARTICULAS POR EJE\n Colocar: Do i=1, N2 \n\n x(i) = -(BoxL-1)/2 + dBoxL*(i-1)\n y(i) = -(BoxL-1)/2 + dBoxL*(i-1)\n z(i) = -(BoxL-1)/2 + dBoxL*(i-1)\n \n End Do Colocar\n\n !ESCRIBIENDO EN ARCHIVO\n Open (1, File = \"PosPart.dat\" ) \n EscribirX: Do i = 1, N2\n EscribirY: Do j = 1, N2\n EScribirZ: Do k = 1, N2\n Write(1,*) x(i), y(j), z(k)\n End Do EScribirZ\n End Do EscribirY\n End Do EscribirX\n\n\n\n Deallocate(X,Y)\n Close(1)\n \nEnd Program ConfigIni\n", "meta": {"hexsha": "da63204a967c0bbc7c73bd2e11d43e7725131025", "size": 1661, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "Portafolio_I/Tarea_II/Act_4/Act4.f03", "max_stars_repo_name": "maps16/DesExpII", "max_stars_repo_head_hexsha": "d9d12b445e0fe86e32fce028be4f5b8bcfd2391f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Portafolio_I/Tarea_II/Act_4/Act4.f03", "max_issues_repo_name": "maps16/DesExpII", "max_issues_repo_head_hexsha": "d9d12b445e0fe86e32fce028be4f5b8bcfd2391f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Portafolio_I/Tarea_II/Act_4/Act4.f03", "max_forks_repo_name": "maps16/DesExpII", "max_forks_repo_head_hexsha": "d9d12b445e0fe86e32fce028be4f5b8bcfd2391f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.0724637681, "max_line_length": 81, "alphanum_fraction": 0.5310054184, "num_tokens": 604, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765234137297, "lm_q2_score": 0.7371581568543043, "lm_q1q2_score": 0.6735241019607137}} {"text": "module numeth\n\n !! This module contains subroutines for numerical solution\n !! of a system of linear equations\n\n use types\n implicit none\n save\n\n private\n public :: factor, solve, bfactor, bsolve\n\ncontains\n\n subroutine factor(a)\n\n !! This subroutine computes the LU-factorization of a matrix. \n !!\n !! The following assumptions are made\n !!\n !! * the matrix is square\n !! * the matrix is non-singular\n !!\n !! If the assumptions are not meet the behavior is undefined -- probably the\n !! program will crash.\n !!\n !! The LU-factorization is stored in-place, thereby replacing the original\n !! content of the given matrix.\n\n real(wp), dimension(:, :), intent(inout) :: a\n !! Matrix to be LU-factored\n \n integer :: i, j, neqn\n neqn = size(a, 1)\n\n do j = 2, neqn\n do i = 1, j-1\n a(j, i) = a(j, i) - dot_product(a(j, 1:i-1), a(1:i-1, i))\n a(i, j) = a(i, j) - dot_product(a(i, 1:i-1), a(1:i-1, j))\n a(j, i) = a(j, i)/a(i, i)\n end do\n a(j, j) = a(j, j) - dot_product(a(j, 1:j-1), a(1:j-1, j))\n end do\n end subroutine factor\n!\n!--------------------------------------------------------------------------------------------------\n!\n subroutine solve(a, b)\n\n !! This subroutine solves the linear system of equations [M]{x} = {b}, where\n !! [a] is the LU-factoriztion of [M], as obtained from the subroutine [[factor]]. \n !! \n !! The subroutine returns the solution {x} by overwriting {b}.\n \n real(wp), dimension(:, :), intent(in) :: a\n !! LU-factorization of system matrix\n real(wp), dimension(:), intent(inout) :: b\n !! Right-hand side to be overwritten by the computed solution\n\n integer :: i, neqn\n neqn = size(a, 1)\n\n ! Forward substitution\n do i = 2, neqn\n b(i) = b(i) - dot_product(a(i, 1:i-1), b(1:i-1))\n end do\n\n ! Backward substitution\n b(neqn) = b(neqn)/a(neqn, neqn)\n do i = neqn-1, 1, -1\n b(i) = (b(i) - dot_product(a(i, i+1:neqn), b(i+1:neqn)))/a(i, i)\n end do\n end subroutine solve\n !\n!--------------------------------------------------------------------------------------------------\n!\n subroutine bfactor(a)\n\n !! This subroutine computes the LU-factorization of a matrix.\n !!\n !! The following assumptions are made\n !!\n !! * the matrix is stored in banded form (rectangular matrix)\n !! * the matrix is non-singular\n !!\n !! If the assumptions are not meet the behavior is undefined -- probably the\n !! program will crash.\n !!\n !! The LU-factorization is stored in-place, thereby replacing the original\n !! content of the given matrix.\n\n real(wp), dimension(:, :), intent(inout) :: a \n !! Matrix in banded form to be LU-factored\n real(wp) :: c\n integer :: i, j, k, m, n, bw, neqn\n\n bw = size(a, 1)\n neqn = size(a, 2)\n\n do n = 1, neqn\n do m = 2, bw\n if (a(m, n) == 0.0_wp) cycle\n i = n+m-1\n c = a(m, n)/a(1, n)\n j = 0\n do k = m, bw\n j = j+1\n! print *, \"ijknm\", i,j,k,m,n\n a(j, i) = a(j, i) - c*a(k, n)\n end do\n a(m, n) = c\n end do\n end do \n end subroutine bfactor\n!\n!--------------------------------------------------------------------------------------------------\n!\n subroutine bsolve(a, b)\n \n !! This subroutine solves the linear system of equations [M]{x} = {b}, where\n !! [a] is the LU-factoriztion of [M], as obtained from the subroutine [[bfactor]]. \n !! \n !! The subroutine returns the solution {x} by overwriting {b}.\n\n real(wp), dimension(:, :), intent(in) :: a\n !! LU-factorization of system matrix\n real(wp), dimension(:), intent(inout) :: b\n !! Right-hand side to be overwritten by the computed solution\n\n integer :: i, j, k, m, n, bw, neqn\n bw = size(a, 1)\n neqn = size(a, 2)\n\n do n = 1,neqn\n do j = 2, bw\n if (a(j, n) == 0.0_wp) cycle \n i = n+j-1\n b(i) = b(i)-a(j, n)*b(n)\n end do\n b(n) = b(n)/a(1, n)\n end do\n\n do m = 2, neqn\n n = neqn+1-m\n do j = 2, bw\n if (a(j, n) == 0.0_wp) cycle \n k = n+j-1\n b(n) = b(n)-a(j, n)*b(k)\n end do\n end do\n end subroutine bsolve\n\nend module numeth\n\n", "meta": {"hexsha": "0df676f2458d843cd69099c679c368ed41e2abfc", "size": 4833, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/numeth.f90", "max_stars_repo_name": "Sebastian-dm/finite-element", "max_stars_repo_head_hexsha": "aba1e152b85e579d04e35bdcf50205ee2639dcf2", "max_stars_repo_licenses": ["MIT"], "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/numeth.f90", "max_issues_repo_name": "Sebastian-dm/finite-element", "max_issues_repo_head_hexsha": "aba1e152b85e579d04e35bdcf50205ee2639dcf2", "max_issues_repo_licenses": ["MIT"], "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/numeth.f90", "max_forks_repo_name": "Sebastian-dm/finite-element", "max_forks_repo_head_hexsha": "aba1e152b85e579d04e35bdcf50205ee2639dcf2", "max_forks_repo_licenses": ["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.1806451613, "max_line_length": 99, "alphanum_fraction": 0.4487895717, "num_tokens": 1291, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.899121388082479, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6735203348505495}} {"text": "!---------------------------------------------------------------------!\n! OWNER: Ithaca Combustion Enterprise, LLC !\n! COPYRIGHT: \u00a9 2012, Ithaca Combustion Enterprise, LLC !\n! LICENSE: BSD 3-Clause License (The complete text of the license can !\n! be found in the `LICENSE-ICE.txt' file included in the ISAT-CK7 !\n! source directory.) !\n!---------------------------------------------------------------------!\n\nsubroutine ell_pair_shrink( n, gg1, gg2, n_shrink )\n\n! Given a pair of concentric ellipsoids, E1 and E2, shrink E2\n! (if necessary) so that it is contained in E1.\n! E1 is defined by: x^T * G1 * G1^T * x <= 1, where the array gg1\n! contains G1 in packed format. Similarly for E2. \n\n! Method:\n! 1/ transform to y-space in which E1 is the unit ball: y = G1^T * x\n! 2/ in y-space, SVD of G2 is G2 = U S V^T\n! 3/ modify S by S(i,i) = max( S(i,i), 1. ); number of modifications is n_shrink\n! 4/ transform back\n\n! S.B. Pope 6/13/04\n\nimplicit none\n\ninteger, parameter :: k_dp = kind(1.d0)\ninteger, intent(in) :: n\nreal(k_dp), intent(in) :: gg1((n*(n+1))/2)\nreal(k_dp), intent(inout) :: gg2((n*(n+1))/2)\ninteger, intent(out) :: n_shrink\n\ninteger :: i, j, k, info, lwork\nreal(k_dp) :: g1(n,n), g2(n,n), s(n), u(n,n), y(n), work(n*n+10*n), r, r_in\n\nlwork = n*n+10*n+10\nn_shrink = 0\n\n! unpack gg1 and gg2\nk = 0\ng1 = 0.d0\ng2 = 0.d0\ndo j = 1, n\n do i = j, n\n k = k + 1\n\t g1(i,j) = gg1(k)\n\t g2(i,j) = gg2(k)\t \n end do\nend do\n\n! transform to y-space: y = G1^T * x; G2y = G1^{-1} * G2\ncall dtrsm( 'L', 'L', 'N', 'N', n, n, 1.d0, g1, n, g2, n )\n\n! find point in G2y furthest from the origin\n\ncall ellu_radii( n, g2, r_in, r )\n\nif( r <= 1.d0 ) return ! no modification required (G2 contained in G1)\n\n! SVD: G2y = U S V^T (Note: vt is not referenceed)\ncall dgesvd( 'A', 'N', n, n, g2, n, s, u, n, y, n, work, lwork, info )\n\nif( info /= 0 ) then\n write(0,*)'ell_pair_shrink: SVD failed, info = ', info\n stop\nendif\n\n! shrink principal axes as needed\ndo i = 1, n\n if( s(i) < 1.d0 ) then\n s(i) = 1.d0\n\t n_shrink = n_shrink + 1\n endif\nend do\n\n! form modified G2y * G2y^T = (U * S) * (U * S)^T \ndo j = 1, n\n u(:,j) = u(:,j) * s(j) ! U * S\nend do\n\n! Form Chholesky G: G * G^T = G2y * G2y^T = (U * S) * (U * S)^T\ncall ellu_bbt2chol( n, u, g2 )\n\n! Zero upper triangle\ndo j = 2, n\n do i = 1, j-1\n g2(i,j) = 0.d0\n end do\nend do\n\n! transform back to x-space: G2 = G1 * G2y\ncall dtrmm( 'L', 'L', 'N', 'N', n, n, 1.d0, g1, n, g2, n )\n\nk = 0\ndo j = 1, n ! pack g2 into gg2 ensuring that the diagonal elements are non-nehative\n if( g2(j,j) >= 0.d0 ) then\n do i = j,n\n k = k + 1\n\t gg2(k) = g2(i,j)\n end do\n else\n do i = j,n\n k = k + 1\n\t gg2(k) = -g2(i,j)\n end do\n endif\nend do\n\nreturn\nend subroutine ell_pair_shrink\n", "meta": {"hexsha": "237b9ce7be7e0dd8c29d492b8a98d5da8bc5d53b", "size": 2932, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/isat/ell_lib/ell_pair_shrink.f90", "max_stars_repo_name": "xuhan425/isat_ffd", "max_stars_repo_head_hexsha": "3a5449f7e49b686c33fe0e97ca90ea8d92fc2f00", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-04-10T20:16:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-15T11:09:44.000Z", "max_issues_repo_path": "src/isat/ell_lib/ell_pair_shrink.f90", "max_issues_repo_name": "xuhan425/isat_ffd", "max_issues_repo_head_hexsha": "3a5449f7e49b686c33fe0e97ca90ea8d92fc2f00", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-06-07T14:10:25.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-07T14:10:25.000Z", "max_forks_repo_path": "src/isat/ell_lib/ell_pair_shrink.f90", "max_forks_repo_name": "xuhan425/isat_ffd", "max_forks_repo_head_hexsha": "3a5449f7e49b686c33fe0e97ca90ea8d92fc2f00", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-06-07T03:44:12.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-05T05:54:10.000Z", "avg_line_length": 26.6545454545, "max_line_length": 87, "alphanum_fraction": 0.5218281037, "num_tokens": 1143, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762114, "lm_q2_score": 0.7490872131147276, "lm_q1q2_score": 0.6735203308007838}} {"text": " Program dtrsen_example\n\n! DTRSEN Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use blas_interfaces, Only: dgemm\n Use lapack_example_aux, Only: nagf_file_print_matrix_real_gen\n Use lapack_interfaces, Only: dlange, dtrsen\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nin = 5, nout = 6\n! .. Local Scalars ..\n Real (Kind=dp) :: alpha, beta, norm, s, sep\n Integer :: i, ifail, info, lda, ldc, ldq, ldt, liwork, lwork, m, n\n! .. Local Arrays ..\n Real (Kind=dp), Allocatable :: a(:, :), c(:, :), q(:, :), t(:, :), &\n wi(:), work(:), wr(:)\n Integer, Allocatable :: iwork(:)\n Logical, Allocatable :: select(:)\n! .. Intrinsic Procedures ..\n Intrinsic :: epsilon\n! .. Executable Statements ..\n Write (nout, *) 'DTRSEN Example Program Results'\n Write (nout, *)\n Flush (nout)\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n\n lda = n\n ldc = n\n ldq = n\n ldt = n\n liwork = (n*n)/4\n lwork = (n*n)/2\n Allocate (a(lda,n), c(ldc,n), q(ldq,n), t(ldt,n), wi(n), work(lwork), &\n wr(n), iwork(liwork), select(n))\n\n! Read T, Q and the logical array SELECT from data file\n\n Read (nin, *)(t(i,1:n), i=1, n)\n Read (nin, *)(q(i,1:n), i=1, n)\n\n Read (nin, *) select(1:n)\n\n! Compute Q * T * Q**T to find A\n alpha = 1._dp\n beta = 0._dp\n Call dgemm('N', 'N', n, n, n, alpha, q, ldq, t, ldt, beta, c, ldc)\n Call dgemm('N', 'T', n, n, n, alpha, c, ldc, q, ldq, beta, a, lda)\n\n! Print Matrix A, as computed from Q * T * Q**T\n! ifail: behaviour on error exit\n! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft\n ifail = 0\n Call nagf_file_print_matrix_real_gen('General', ' ', n, n, a, lda, &\n 'Matrix A computed from Q*T*Q^T', ifail)\n\n Write (nout, *)\n Flush (nout)\n\n! Reorder the Schur factor T and update the matrix Q to obtain TT and QT\n\n Call dtrsen('Both', 'Vectors', select, n, t, ldt, q, ldq, wr, wi, m, s, &\n sep, work, lwork, iwork, liwork, info)\n\n! Compute (Q * T * Q^T) - (QT * TT * QT^T) and store in A,\n! i.e. the difference between reconstructed A using Schur and reordered\n! Schur decompositions.\n alpha = 1._dp\n beta = 0._dp\n Call dgemm('N', 'N', n, n, n, alpha, q, ldq, t, ldt, beta, c, ldc)\n alpha = -1._dp\n beta = 1._dp\n Call dgemm('N', 'T', n, n, n, alpha, c, ldc, q, ldq, beta, a, lda)\n\n! Find norm of difference matrix and print warning if it is too large\n norm = dlange('O', lda, n, a, lda, work)\n If (norm>epsilon(1.0E0_dp)**0.8_dp) Then\n Write (nout, *) 'Norm of A - (QT * TT * QT^T) is much greater than 0.'\n Write (nout, *) 'Schur factorization has failed.'\n Else\n! Print Result\n Write (nout, 100) 'Condition number estimate', &\n ' of the selected cluster of eigenvalues = ', 1.0_dp/s\n Write (nout, *)\n Write (nout, 100) 'Condition number estimate of the spec', &\n 'ified invariant subspace = ', 1.0_dp/sep\n End If\n\n100 Format (1X, A, A, 1P, E10.2)\n End Program\n", "meta": {"hexsha": "628ad2623d170c58bdb5d6560757cd35ab40bab6", "size": 3442, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/dtrsen_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/dtrsen_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/dtrsen_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 35.1224489796, "max_line_length": 90, "alphanum_fraction": 0.5572341662, "num_tokens": 1129, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213745668094, "lm_q2_score": 0.7490872187162396, "lm_q1q2_score": 0.6735203297625736}} {"text": " subroutine diff (v, dr, kap, cl, dx, n, vm)\nc calculate vm(i)=(dV/dx)*r(i)*(kap+1)/cl\nc needed for c3 term to calculate j-average phase shift\nc ref. koelling,harmon j.phys.c,3107(1977). eq.14\n implicit double precision (a-h,o-z)\n include '../HEADERS/dim.h'\n \n complex*16 v(n), vm(n), vt(nrptx)\n double precision dr(n)\n double precision a, b, c, d, e, f, g\n\n do i = 1,n\n vt(i) = v(i) * dr(i)**2\n enddo\n\nc should be:\n a = 6.0d0\n b = 20.d0/3.0d0\n c = 1.2d0\n d = 2.45d0\n e = 7.5d0\n f = 3.75d0\n g = 1.d0/6.d0\n vm(1)=((a*vt(2) + b*vt(4) + c*vt(6)) -\n $ (d*vt(1) + e*vt(3) + f*vt(5) + g*vt(7)))/dx\n vm(2)=((a*vt(3) + b*vt(5) + c*vt(7)) -\n $ (d*vt(2) + e*vt(4) + f*vt(6) + g*vt(8)))/dx\n\nc curently passes tests:\n vm(1)=((6.0*vt(2)+6.66666666667*vt(4)+1.2*vt(6)) -\n $ (2.45*vt(1)+7.5*vt(3)+3.75*vt(5)+.166666666667*vt(7)))/dx\n vm(2)=((6.0*vt(3)+6.66666666667*vt(5)+1.2*vt(7)) -\n $ (2.45*vt(2)+7.5*vt(4)+3.75*vt(6)+.166666666667*vt(8)))/dx\n\n nm2=n-2\n do i=3,nm2\n vm(i)=((vt(i-2)+8.0*vt(i+1))-(8.0*vt(i-1)+vt(i+2)))/12.0/dx\n enddo\n vm(n-1)=(vt(n)-vt(n-2))/(2.0*dx)\n vm(n)=(vt(n-2)*0.5 - 2.0*vt(n-1) + 1.5*vt(n))/dx\n\n do i = 1,n\n vm(i) = (vm(i)-2*vt(i))/dr(i) *(kap+1.0)/cl\n enddo\n return\n end\n", "meta": {"hexsha": "d832ca99feb8844b5f73e222225e95f8f5df3001", "size": 1399, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/FOVRG/diff.f", "max_stars_repo_name": "xraypy/feff85exafs", "max_stars_repo_head_hexsha": "ec8dcb07ca8ee034d0fa7431782074f0f65357a5", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2016-01-05T21:29:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:59:17.000Z", "max_issues_repo_path": "src/FOVRG/diff.f", "max_issues_repo_name": "xraypy/feff85exafs", "max_issues_repo_head_hexsha": "ec8dcb07ca8ee034d0fa7431782074f0f65357a5", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 17, "max_issues_repo_issues_event_min_datetime": "2015-01-04T18:37:30.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-07T12:06:12.000Z", "max_forks_repo_path": "src/FOVRG/diff.f", "max_forks_repo_name": "xraypy/feff85exafs", "max_forks_repo_head_hexsha": "ec8dcb07ca8ee034d0fa7431782074f0f65357a5", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2016-01-05T21:29:26.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T13:11:01.000Z", "avg_line_length": 29.7659574468, "max_line_length": 68, "alphanum_fraction": 0.4581844174, "num_tokens": 679, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213691605412, "lm_q2_score": 0.7490872187162396, "lm_q1q2_score": 0.6735203257128072}} {"text": "PROGRAM question3\n IMPLICIT NONE\n real :: x, y\n x = 90. * (3.14/180)\n y = -0.35\n print *, sin(x)\n print *, cos(x)\n print *, acos(y)\n STOP\nEND PROGRAM question3", "meta": {"hexsha": "cf3e8db63f82f6927ec912d2ff91efd86951bb69", "size": 183, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "1. Lab-1/3.f90", "max_stars_repo_name": "arpitkekri/Code_With_FORTRAN", "max_stars_repo_head_hexsha": "fb731e6f8d8a47cfe38896fffd74a55d17efb2e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-02-21T05:24:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-27T10:25:24.000Z", "max_issues_repo_path": "1. Lab-1/3.f90", "max_issues_repo_name": "akhil18soni/Code_With_FORTRAN", "max_issues_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "1. Lab-1/3.f90", "max_forks_repo_name": "akhil18soni/Code_With_FORTRAN", "max_forks_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-02-27T12:14:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T23:30:55.000Z", "avg_line_length": 18.3, "max_line_length": 24, "alphanum_fraction": 0.5355191257, "num_tokens": 63, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636752, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6735203227012511}} {"text": "C File avgerage.f90\n subroutine avg3d(avg,dataset,incavg,counter,spval,dim1,dim2,dim3)\n\n IMPLICIT NONE\n\n !input variables\n REAL*8,DIMENSION(dim1,dim2,dim3),intent(in)::dataset\n REAL*8,DIMENSION(dim1,dim2,dim3),intent(in)::incavg\n \n !output variables\n REAL*8,DIMENSION(dim1,dim2,dim3),intent(out)::avg\n\n !local variables\n INTEGER::dim1,dim2,dim3\n REAL*8::counter\n REAL*8::part1,part2,spval\n INTEGER::i,j,k\n\n do i=1,dim1\n do j=1,dim2\n do k=1,dim3\n if (dataset(i,j,k).lt.spval) then\n !This is the code for performing an incremental\n !average broken into two parts. It follows the formula:\n !avg(I+1) = avg(I) + ((data(I+1)-avg(I))/I+1)\n part1 = dataset(i,j,k)-incavg(i,j,k)\n part2 = part1 / counter\n avg(i,j,k) = incavg(i,j,k)+part2\n else\n !This keeps the missing value in the return array\n avg(i,j,k) = dataset(i,j,k)\n endif\n enddo\n enddo\n enddo\n\n return\n\n end\n\n subroutine avg2d(avg,dataset,incavg,counter,spval,dim1,dim2)\n\n IMPLICIT NONE\n\n !input variables\n REAL*8,DIMENSION(dim1,dim2),intent(in)::dataset\n REAL*8,DIMENSION(dim1,dim2),intent(in)::incavg\n \n !output variables\n REAL*8,DIMENSION(dim1,dim2),intent(out)::avg\n\n !local variables\n INTEGER::dim1,dim2\n REAL*8::counter\n REAL*8::part1,part2,spval\n INTEGER::i,j\n\n do i=1,dim1\n do j=1,dim2\n if (dataset(i,j).lt.spval) then\n !This is the code for performing an incremental\n !average broken into two parts. It follows the formula:\n !avg(I+1) = avg(I) + ((data(I+1)-avg(I))/I+1)\n part1 = dataset(i,j)-incavg(i,j)\n part2 = part1 / counter\n avg(i,j) = incavg(i,j)+part2\n else\n !This keeps the missing value in the return array\n avg(i,j) = dataset(i,j)\n endif\n enddo\n enddo\n\n return\n\n end\n", "meta": {"hexsha": "cd38de6e92957a6752aed424f055017bc3c28e97", "size": 2198, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "pyroms_toolbox/pyroms_toolbox/src/average.f90", "max_stars_repo_name": "dcherian/pyroms", "max_stars_repo_head_hexsha": "fb5d9adda3afcc4ddbe9f3cf1f0a100d43262c11", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-12-28T13:50:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-28T13:50:45.000Z", "max_issues_repo_path": "pyroms_toolbox/pyroms_toolbox/src/average.f90", "max_issues_repo_name": "dcherian/pyroms", "max_issues_repo_head_hexsha": "fb5d9adda3afcc4ddbe9f3cf1f0a100d43262c11", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-01-23T23:23:24.000Z", "max_issues_repo_issues_event_max_datetime": "2018-02-07T22:37:28.000Z", "max_forks_repo_path": "pycnal_toolbox/pycnal_toolbox/src/average.f90", "max_forks_repo_name": "ESMG/PyCNAL_legacy", "max_forks_repo_head_hexsha": "a4f6547bce872068a5bb5751231017bc3e4a4503", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-08-31T19:54:25.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-28T13:50:47.000Z", "avg_line_length": 28.5454545455, "max_line_length": 72, "alphanum_fraction": 0.5263876251, "num_tokens": 606, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636754, "lm_q2_score": 0.749087201911703, "lm_q1q2_score": 0.6735203126283723}} {"text": "C\nC-----------------------------------------------------------------------------\nC\n double precision function alfa(alfa0,qsq )\nC\nC-----------------------------------------------------------------------------\nC\nC\tThis function returns the 1-loop value of alpha.\nC\nC\tINPUT: \nC\t\tqsq = Q^2\nC\nC-----------------------------------------------------------------------------\nC\n implicit none\n double precision qsq,alfa0\nc\nc constants\nc\n double precision One, Three, Pi,zmass\n parameter( One = 1.0d0, Three = 3.0d0 )\n parameter( Pi = 3.14159265358979323846d0 )\n parameter( zmass = 91.188d0 )\ncc\n alfa = alfa0 / ( 1.0d0 - alfa0*dlog( qsq/zmass**2 ) /Three /Pi )\nccc\n return\n end\n\nC\nC-----------------------------------------------------------------------------\nC\n double precision function alfaw(alfaw0,qsq,nh )\nC\nC-----------------------------------------------------------------------------\nC\nC\tThis function returns the 1-loop value of alpha_w.\nC\nC\tINPUT: \nC\t\tqsq = Q^2\nC nh = # of Higgs doublets\nC\nC-----------------------------------------------------------------------------\nC\n implicit none\n double precision qsq, alphaw, dum,alfaw0\n integer nh, nq\nc\nc\t include\nc\n\t \nc\nc constants\nc\n double precision Two, Four, Pi, Twpi, zmass,tmass\n parameter( Two = 2.0d0, Four = 4.0d0 )\n parameter( Pi = 3.14159265358979323846d0 )\n parameter( Twpi = 3.0d0*Four*Pi )\n parameter( zmass = 91.188d0,tmass=174d0 )\ncc\n if ( qsq.ge.tmass**2 ) then\n nq = 6\n else\n nq = 5\n end if\n dum = ( 22.0d0 - Four*nq - nh/Two ) / Twpi\n alfaw = alfaw0 / ( 1.0d0 + dum*alfaw0*dlog( qsq/zmass**2 ) )\nccc\n return\n end\n\n DOUBLE PRECISION FUNCTION ALPHAS(Q)\n\n DOUBLE PRECISION Q,ALPHAS_not_timed\n external ALPHAS_not_timed\n\nc timing statistics\n include \"timing_variables.inc\"\n\nc This function takes roughly 0.6 micro-seconds and the function\nc cpu_time takes 0.3 so it does not make much sense to always leave\nc the timing profile. But it can be uncommented for dedicated study.\nc call cpu_time(tbefore)\n ALPHAS=ALPHAS_not_timed(Q)\nc call cpu_time(tAfter)\n \nc tPDF = tPDF + (tAfter-tBefore)\n RETURN\n end\n\nC-----------------------------------------------------------------------------\nC\n DOUBLE PRECISION FUNCTION ALPHAS_not_timed(Q)\nc\nc Evaluation of strong coupling constant alpha_S\nc Author: R.K. Ellis\nc\nc q -- scale at which alpha_s is to be evaluated\nc\nc-- common block alfas.inc\nc asmz -- value of alpha_s at the mass of the Z-boson\nc nloop -- the number of loops (1,2, or 3) at which beta \nc\nc function is evaluated to determine running.\nc the values of the cmass and the bmass should be set\nc in common block qmass.\nC-----------------------------------------------------------------------------\n\n IMPLICIT NONE\nc\n include 'alfas.inc'\n DOUBLE PRECISION Q,T,AMZ0,AMB,AMC\n DOUBLE PRECISION AS_OUT\n INTEGER NLOOP0,NF3,NF4,NF5\n PARAMETER(NF5=5,NF4=4,NF3=3)\nC\n REAL*8 CMASS,BMASS\n COMMON/QMASS/CMASS,BMASS\n DATA CMASS,BMASS/1.42D0,4.7D0/ ! HEAVY QUARK MASSES FOR THRESHOLDS\nC\n REAL*8 ZMASS\n DATA ZMASS/91.188D0/\nC\n SAVE AMZ0,NLOOP0,AMB,AMC\n DATA AMZ0,NLOOP0/0D0,0/\n IF (Q .LE. 0D0) THEN \n WRITE(6,*) 'q .le. 0 in alphas'\n WRITE(6,*) 'q= ',Q\n STOP\n ENDIF\n IF (asmz .LE. 0D0) THEN \n WRITE(6,*) 'asmz .le. 0 in alphas',asmz\nc WRITE(6,*) 'continue with asmz=0.1185'\n STOP\n asmz=0.1185D0\n ENDIF\n IF (CMASS .LE. 0.3D0) THEN \n WRITE(6,*) 'cmass .le. 0.3GeV in alphas',CMASS\nc WRITE(6,*) 'continue with cmass=1.5GeV?'\n STOP\n CMASS=1.42D0\n ENDIF\n IF (BMASS .LE. 0D0) THEN \n WRITE(6,*) 'bmass .le. 0 in alphas',BMASS\n WRITE(6,*) 'COMMON/QMASS/CMASS,BMASS'\n STOP\n BMASS=4.7D0\n ENDIF\nc--- establish value of coupling at b- and c-mass and save\n IF ((asmz .NE. AMZ0) .OR. (NLOOP .NE. NLOOP0)) THEN\n AMZ0=asmz\n NLOOP0=NLOOP\n T=2D0*DLOG(BMASS/ZMASS)\n CALL NEWTON1(T,asmz,AMB,NLOOP,NF5)\n T=2D0*DLOG(CMASS/BMASS)\n CALL NEWTON1(T,AMB,AMC,NLOOP,NF4)\n ENDIF\n\nc--- evaluate strong coupling at scale q\n IF (Q .LT. BMASS) THEN\n IF (Q .LT. CMASS) THEN\n T=2D0*DLOG(Q/CMASS)\n CALL NEWTON1(T,AMC,AS_OUT,NLOOP,NF3)\n ELSE\n T=2D0*DLOG(Q/BMASS)\n CALL NEWTON1(T,AMB,AS_OUT,NLOOP,NF4)\n ENDIF\n ELSE\n T=2D0*DLOG(Q/ZMASS)\n CALL NEWTON1(T,asmz,AS_OUT,NLOOP,NF5)\n ENDIF\n ALPHAS_not_timed=AS_OUT\n RETURN\n END\n\n\n SUBROUTINE NEWTON1(T,A_IN,A_OUT,NLOOP,NF)\nC Author: R.K. Ellis\n\nc--- calculate a_out using nloop beta-function evolution \nc--- with nf flavours, given starting value as-in\nc--- given as_in and logarithmic separation between \nc--- input scale and output scale t.\nc--- Evolution is performed using Newton's method,\nc--- with a precision given by tol.\n\n IMPLICIT NONE\n INTEGER NLOOP,NF\n REAL*8 T,A_IN,A_OUT,AS,TOL,F2,F3,F,FP,DELTA\n REAL*8 B0(3:5),C1(3:5),C2(3:5),DEL(3:5)\n PARAMETER(TOL=5.D-4)\nC--- B0=(11.-2.*NF/3.)/4./PI\n DATA B0/0.716197243913527D0,0.66314559621623D0,0.61009394851893D0/\nC--- C1=(102.D0-38.D0/3.D0*NF)/4.D0/PI/(11.D0-2.D0/3.D0*NF)\n DATA C1/.565884242104515D0,0.49019722472304D0,0.40134724779695D0/\nC--- C2=(2857.D0/2.D0-5033*NF/18.D0+325*NF**2/54)\nC--- /16.D0/PI**2/(11.D0-2.D0/3.D0*NF)\n DATA C2/0.453013579178645D0,0.30879037953664D0,0.14942733137107D0/\nC--- DEL=SQRT(4*C2-C1**2)\n DATA DEL/1.22140465909230D0,0.99743079911360D0,0.66077962451190D0/\n F2(AS)=1D0/AS+C1(NF)*LOG((C1(NF)*AS)/(1D0+C1(NF)*AS))\n F3(AS)=1D0/AS+0.5D0*C1(NF)\n & *LOG((C2(NF)*AS**2)/(1D0+C1(NF)*AS+C2(NF)*AS**2))\n & -(C1(NF)**2-2D0*C2(NF))/DEL(NF)\n & *ATAN((2D0*C2(NF)*AS+C1(NF))/DEL(NF))\n\n \n A_OUT=A_IN/(1D0+A_IN*B0(NF)*T)\n IF (NLOOP .EQ. 1) RETURN\n A_OUT=A_IN/(1D0+B0(NF)*A_IN*T+C1(NF)*A_IN*LOG(1D0+A_IN*B0(NF)*T))\n IF (A_OUT .LT. 0D0) AS=0.3D0\n 30 AS=A_OUT\n\n IF (NLOOP .EQ. 2) THEN\n F=B0(NF)*T+F2(A_IN)-F2(AS)\n FP=1D0/(AS**2*(1D0+C1(NF)*AS))\n ENDIF\n IF (NLOOP .EQ. 3) THEN\n F=B0(NF)*T+F3(A_IN)-F3(AS)\n FP=1D0/(AS**2*(1D0+C1(NF)*AS+C2(NF)*AS**2))\n ENDIF\n A_OUT=AS-F/FP\n DELTA=ABS(F/FP/AS)\n IF (DELTA .GT. TOL) GO TO 30\n RETURN\n END\n\n\nC-----------------------------------------------------------------------------\nC\n double precision function mfrun(mf,scale,asmz,nloop)\nC\nC-----------------------------------------------------------------------------\nC\nC\tThis function returns the 2-loop value of a MSbar fermion mass\nC at a given scale.\nC\nC\tINPUT: mf = MSbar mass of fermion at MSbar fermion mass scale \nC\t scale = scale at which the running mass is evaluated\nC\t asmz = AS(MZ) : this is passed to alphas(scale,asmz,nloop)\nC nloop = # of loops in the evolution\nC \nC\nC\nC\tEXTERNAL: double precision alphas(scale,asmz,nloop)\nC \nC-----------------------------------------------------------------------------\nC\n implicit none\nC\nC ARGUMENTS\nC\n double precision mf,scale,asmz\n integer nloop\nC\nC LOCAL\nC\n double precision beta0, beta1,gamma0,gamma1\n double precision A1,as,asmf,l2\n integer nf\nC\nC EXTERNAL\nC\n double precision alphas\n external alphas\nc\nc CONSTANTS\nc\n double precision One, Two, Three, Pi\n parameter( One = 1.0d0, Two = 2.0d0, Three = 3.0d0 )\n parameter( Pi = 3.14159265358979323846d0) \n double precision tmass\n parameter(tmass=174d0)\ncc\nC\nC\n if ( mf.gt.tmass ) then\n nf = 6\n else\n nf = 5\n end if\n\n beta0 = ( 11.0d0 - Two/Three *nf )/4d0\n beta1 = ( 102d0 - 38d0/Three*nf )/16d0\n gamma0= 1d0\n gamma1= ( 202d0/3d0 - 20d0/9d0*nf )/16d0\n A1 = -beta1*gamma0/beta0**2+gamma1/beta0\n as = alphas(scale)\n asmf = alphas(mf)\n l2 = (1+ A1*as/Pi)/(1+ A1*asmf/Pi)\n \n \n mfrun = mf * (as/asmf)**(gamma0/beta0)\n\n if(nloop.eq.2) mfrun =mfrun*l2\nccc\n return\n end\n\n", "meta": {"hexsha": "f6ad28268198bd256f6f3d06f75de0d351e4fbcb", "size": 8452, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "examples/First_Project/mg_processes/signal1/Source/alfas_functions.f", "max_stars_repo_name": "JaySandesara/madminer", "max_stars_repo_head_hexsha": "c5fcb9fbbd5d70f7a07114e4ea6afc4e3c4518fb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-10-23T14:37:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-22T20:59:02.000Z", "max_issues_repo_path": "examples/First_Project/mg_processes/signal1/Source/alfas_functions.f", "max_issues_repo_name": "JaySandesara/madminer", "max_issues_repo_head_hexsha": "c5fcb9fbbd5d70f7a07114e4ea6afc4e3c4518fb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2018-10-08T15:49:32.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-15T13:33:36.000Z", "max_forks_repo_path": "examples/First_Project/mg_processes/signal1/Source/alfas_functions.f", "max_forks_repo_name": "JaySandesara/madminer", "max_forks_repo_head_hexsha": "c5fcb9fbbd5d70f7a07114e4ea6afc4e3c4518fb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2019-02-18T11:42:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-11T20:46:08.000Z", "avg_line_length": 28.1733333333, "max_line_length": 78, "alphanum_fraction": 0.530880265, "num_tokens": 2956, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318196, "lm_q2_score": 0.7577943767446201, "lm_q1q2_score": 0.6734964226893363}} {"text": "MODULE m_keplerorb\n\n\n! ----------------------------------------------------------------------\n! MODULE: m_keplerorb.f03\n! ----------------------------------------------------------------------\n! Purpose:\n! Module for calling the keplerorb subroutine used for computating Kepelrian orbit\n! \n! Subroutines contained within the module:\n! - keplerorb\n! ----------------------------------------------------------------------\n! Author :\tDr. Thomas Papanikolaou\n!\t\t\tCooperative Research Centre for Spatial Information, Australia\n! Created:\t14 November 2017\n! ----------------------------------------------------------------------\n\n\n IMPLICIT NONE\n !SAVE \t\t\t\n \n\t \nContains\n\n\nSUBROUTINE keplerorb (GM, MJDo, Sec0, Zo, Zel, Ndays, interv, orb1, orb2, found)\n\n\n! ----------------------------------------------------------------------\n! SUBROUTINE: keplerorb.f90\n! ----------------------------------------------------------------------\n! Purpose:\n! Kepler orbit based on the initial conditions as input\n! ----------------------------------------------------------------------\n! Input arguments:\n! - GM:\t\t\t\tEarth Gravity Constant (m^3/sec^2)\n! - MJDo: \t\t\tModified Julian Day number at the initial epoch (including the fraction of the day)\n! - Sec0:\t\t\tSeconds of Day at the initial epoch\n! - Zo:\t\t\t\tInitial state vector \n! - Zel:\t\t\tCoordinates type of the initial state vector\n! Zel = 1\t\t\tKeplerian Elements \n! Zel = 2\t\t\tState vector (Position & Velocity) cartesian coordinates in m & m/sec\n! - Ndays:\t\t\tNumber of days of the keplerian orbit arc length to be computed\n! - interv: \t\tInterval of the orbit epochs (in seconds)\n!\n! Output arguments:\n! - orb1:\t\t\tOrbit array of Keplerian elements per epoch\n! - orb2: \t\t\tOrbit array of state vector's cartesian coordinates per epoch\n! ----------------------------------------------------------------------\n! Note 1:\n! - kepler:\t\tKepler elements array (6)\n! a: \tsemi-major axis (m)\n! e: \teccentricity\n! i: \tinclination (degrees)\n! Omega: \tright ascension of the ascending node (degrees)\n! omega: \targument of perigee (degrees)\n! E: \teccentric anomaly (degrees)\n! ----------------------------------------------------------------------\n! Author :\tDr. Thomas Papanikolaou, Cooperative Research Centre for Spatial Information, Australia\n! Created:\t25 August 2016\n! ----------------------------------------------------------------------\n! Last modified:\n! - Dr. Thomas Papanikolaou, 14 November 2017:\n!\tUpgraded from Fortran 90 to Fortran 2003 for considering the\n!\tFortran 2003 adavantages in dynamic memory allocation\n! ----------------------------------------------------------------------\n\n\n USE mdl_precision\n USE mdl_num\n !USE mdl_arr\n\t !USE mdl_write\n IMPLICIT NONE\n\t \n! ----------------------------------------------------------------------\n! Dummy arguments declaration\n! ----------------------------------------------------------------------\n! IN\n REAL (KIND = prec_q), INTENT(IN) :: GM\n REAL (KIND = prec_q), INTENT(IN) :: MJDo, Sec0, Zo(6)\n INTEGER (KIND = prec_int4), INTENT(IN) :: Zel\n INTEGER (KIND = prec_int8), INTENT(IN) :: Ndays, interv \n! OUT\n REAL (KIND = prec_q), INTENT(OUT), DIMENSION(:,:), ALLOCATABLE :: orb1\n REAL (KIND = prec_q), INTENT(OUT), DIMENSION(:,:), ALLOCATABLE :: orb2\n LOGICAL, INTENT(OUT) :: found\n! ----------------------------------------------------------------------\n\n! ----------------------------------------------------------------------\n! Local variables declaration\n! ----------------------------------------------------------------------\n INTEGER (KIND = prec_int8) :: Norb, i, sz1, sz2\n REAL (KIND = prec_q) :: kepler_0(6), kepler_9(9), a_semiaxis, ec, Eo_rad, Mo_rad, n_motion\n REAL (KIND = prec_q) :: MJD_i, SecDay_i, SecDay_0, dt, Sec_arc\n REAL (KIND = prec_q) :: Mi_rad, Mi_deg, Ei\n REAL (KIND = prec_q) :: kepler_i(6), r_i(3), v_i(3)\n INTEGER (KIND = prec_int2) :: AllocateStatus, DeAllocateStatus\n CHARACTER (LEN=300) :: fname_write\n! ----------------------------------------------------------------------\n\n\n! ----------------------------------------------------------------------\n! Gravitational constant\n!GM = 0.39860044150D+15\n! ----------------------------------------------------------------------\n\nfound = .true.\n\n! Orbit arc in sec\nSec_arc = Ndays * 86400.D0\n\nNorb = INT( Sec_arc / interv) \n\n\n! orb1: Orbit array of Keplerian elements per epoch\nALLOCATE ( orb1(Norb, 8), STAT = AllocateStatus)\t \n\n! orb2: Orbit array of state vector's cartesian coordinates per epoch\nALLOCATE ( orb2(Norb, 8), STAT = AllocateStatus)\t \n\n\n\n! ----------------------------------------------------------------------\n! Intial Conditions\nIf (Zel == 1) then\n\nkepler_0 = Zo\n\nElse if (Zel == 2) then\n\nr_i = Zo(1:3)\nv_i = Zo(4:6)\n!CALL kepler_z2k (r_i, v_i, GM, kepler_0)\nCALL kepler_z2k (r_i, v_i, GM, kepler_9)\n\nEnd If\n\nSecDay_0 = Sec0\n!MJDo = MJDo\n\n\n!a_semiaxis = kepler_0(1)\na_semiaxis = kepler_9(1)\n\n!ec = kepler_0(2)\nec = kepler_9(2)\n\n! Eccentric anomaly at to (radians)\n!Eo_rad = kepler_0(7) * (PI_global / 180.D0)\nEo_rad = kepler_9(7) * (PI_global / 180.D0)\n\n! Mean anomaly at to (radians)\nMo_rad = Eo_rad - ec * sin(Eo_rad)\n!Mo_rad = kepler_9(8) * (PI_global / 180.D0)\n\n\n! ----------------------------------------------------------------------\n! mean motion\nn_motion = sqrt(GM / a_semiaxis**3)\n! ----------------------------------------------------------------------\n\n\nkepler_0(1:5) = kepler_9(1:5)\nkepler_0(6) = kepler_9(7)\n\n\n\n! ----------------------------------------------------------------------\n! Computing Keplerian elements and State vector's cartesian coordinates per epoch\nDo i = 1 , Norb\n\n\nIf (i == 1) then\n\n! Initial Epoch\nMJD_i = MJDo\nSecDay_i = SecDay_0\n\n\n! Cartesian coordinates of the state vector (Inertial Frame)\nkepler_i = kepler_0\nCALL kepler_k2z (kepler_i, GM, r_i, v_i) \n\n\nElse\n\n! Epoch i\nSecDay_i = SecDay_0 + interv * (i - 1)\n!SecDay_i = SecDay_i + interv\n\n!MJD_i = MJDo + SecDay_i / 86400.D0\nMJD_i = INT(MJDo) + SecDay_i / 86400.D0\n\n\n! ----------------------------------------------------------------------\n! Time difference since initial epoch\ndt = MJD_i - MJDo\ndt = SecDay_i - SecDay_0\n! ----------------------------------------------------------------------\n\n\n! Mean anomaly at epoch i (radians)\nMi_rad = Mo_rad + n_motion * dt\n\n! Mean anomaly in degrees \nMi_deg = Mi_rad * (180.D0/PI_global)\n\n! Angle within the range {0 - 360}\nIf (Mi_deg >= 360.D0) then\n\tMi_deg = Mi_deg - INT(Mi_deg / 360.D0) * 360.D0\nEnd If\n\n\n! Eccentric anomaly at ti (degrees) obtained by solving Kepler's Equation\nCALL kepler_eq ( Mi_deg , ec , Ei)\n\n!kepler_i = (/ a, e, i, Omega_asc, omega_per, Ei /)\nkepler_i = (/ kepler_0(1), kepler_0(2), kepler_0(3), kepler_0(4), kepler_0(5), Ei /)\n\n! Cartesian coordinates of the state vector (Inertial Frame)\nCALL kepler_k2z (kepler_i, GM, r_i, v_i) \n\n\nEnd If \n\n\n! Orbit arrays\nIf (SecDay_i >= 86400.D0) Then\n\tSecDay_i = SecDay_i - INT(SecDay_i / 86400.D0) * 86400.D0\nEnd If\norb1(i,:) = (/ MJD_i, SecDay_i, kepler_i /) \norb2(i,:) = (/ MJD_i, SecDay_i, r_i, v_i /) \n\n\nEnd Do\n\n\n\nEnd SUBROUTINE\n\n\n\nEND Module\n", "meta": {"hexsha": "2937d6877c5a1721d7fea08d0ce2f544873005dc", "size": 7169, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/m_keplerorb.f95", "max_stars_repo_name": "HiTMonitor/ginan", "max_stars_repo_head_hexsha": "f348e2683507cfeca65bb58880b3abc2f9c36bcf", "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/fortran/m_keplerorb.f95", "max_issues_repo_name": "HiTMonitor/ginan", "max_issues_repo_head_hexsha": "f348e2683507cfeca65bb58880b3abc2f9c36bcf", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/fortran/m_keplerorb.f95", "max_forks_repo_name": "HiTMonitor/ginan", "max_forks_repo_head_hexsha": "f348e2683507cfeca65bb58880b3abc2f9c36bcf", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.381147541, "max_line_length": 98, "alphanum_fraction": 0.5062072814, "num_tokens": 1899, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587934924569, "lm_q2_score": 0.7577943767446201, "lm_q1q2_score": 0.6734964159909169}} {"text": "\t! integrates the frenkel-kontorova model by rk4 method\n\n\timplicit none\n\n\tinteger, parameter :: nn=20,mm=nn/2,iter=1000\n\tdouble precision :: xx(nn),yy(nn),dy(nn)\n\tdouble precision :: tau,dtau\n\tinteger :: i,j,k,l,m,n\n\tdouble precision :: Lam,KK,g0,g1,gam,pi\n\n\tcommon Lam,KK,g0,g1,gam\n\n\topen (unit=5,file='fre-kon.dat',status='unknown')\n\t\n\tLam=1.0d0; KK=1.50d0\n \tg0=10.0d0; g1=320.0d0; gam=40.0d0; pi=3.1416;\n\n\ttau=0.0d0; dtau=0.01d0\n\t\n\n\tyy(1)=pi+0.002d0\n\tyy(2)=pi+0.003d0\n\tyy(3)=pi+0.004d0\n\tyy(4)=pi+0.005d0\n\tyy(5)=pi+0.006d0\n\tyy(6)=pi+0.007d0\n\tyy(7)=pi+0.008d0\n\tyy(8)=pi+0.009d0\n\tyy(9)=pi+0.0023d0\n\tyy(10)=pi+0.0024d0\n\t\t\n\t\n\tyy(11)=0.001d0\n\tyy(12)=0.001d0\n\tyy(13)=0.001d0\n\tyy(14)=0.001d0\n\tyy(15)=0.001d0\n\tyy(16)=0.001d0\n\tyy(17)=0.001d0\n\tyy(18)=0.001d0\n\tyy(19)=0.001d0\n\tyy(20)=0.001d0\n\t\n\t\n\tdo i=1,iter\t! iterations\n\n\tcall derivs(tau,yy,dy)\n call rk4(yy,dy,nn,tau,dtau,xx,derivs)\n\tyy=xx\n\ttau = tau + dtau\n write(5,'(1000(xf12.6))') (yy(l),l=1,nn)\n\tend do\t\t! iterations\n\n\tend\n\n\t! calculates the time derivative \n\n subroutine derivs(tau,yy,dy)\n\n integer, parameter :: nn=20,mm=nn/2\n\tdouble precision :: yy(nn),dy(nn)\n\tdouble precision :: tau,dtau\n\tinteger :: i,j,k,l,m,n\n double precision :: Lam,KK,g0,g1,gam\n\n\tcommon Lam,KK,g0,g1,gam\n\n do i=1,mm\n\tdy(i) = Lam*KK*yy(mm+i)\n end do\n\n\tdy(mm+1) = (Lam/KK)*(dsin(yy(mm)-yy(1))-dsin(yy(1)-yy(2)))\n . -(g0+g1*dcos(gam*tau))*dsin(yy(1))/Lam\n\n\tdo i= 2,mm-1\n\tdy(mm+i) = (Lam/KK)*(dsin(yy(i-1)-yy(i))-dsin(yy(i)-yy(i+1)))\n . -(g0+g1*dcos(gam*tau))*dsin(yy(i))/Lam\n\tend do\n\n\tdy(nn) = (Lam/KK)*(dsin(yy(mm-1)-yy(mm))-dsin(yy(mm)-yy(1)))\n . -(g0+g1*dcos(gam*tau))*dsin(yy(mm))/Lam\n\n print *, 'The velocity on impact is', dy(nn)\n \n return\n end subroutine\n\n\t! performs the rk4 integration\n\n\tSUBROUTINE rk4(y,dydx,n,x,h,yout,derivs)\n\n\tINTEGER n,NMAX\n\tREAL*8 h,x,dydx(n),y(n),yout(n)\n\tEXTERNAL derivs\n\tPARAMETER (NMAX=2000)\n\tINTEGER i\n\tREAL*8 h6,hh,xh,dym(NMAX),dyt(NMAX),yt(NMAX)\n\n\thh=h*0.5\n\th6=h/6.\n\txh=x+hh\n\n\tdo i=1,n\n yt(i)=y(i)+hh*dydx(i)\n\tend do\n\n\tcall derivs(xh,yt,dyt)\n\tdo i=1,n\n yt(i)=y(i)+hh*dyt(i)\n\tend do\n\n\tcall derivs(xh,yt,dym)\n\tdo i=1,n\n yt(i)=y(i)+h*dym(i)\n dym(i)=dyt(i)+dym(i)\n\tend do\n\n\tcall derivs(x+h,yt,dyt)\n\tdo i=1,n\n yout(i)=y(i)+h6*(dydx(i)+dyt(i)+2.*dym(i))\n\tend do\n\n\treturn\n\tEND\n", "meta": {"hexsha": "32bb41704daa35d7c60655b6104fed0dbf2321b6", "size": 2435, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "fre-kon.f", "max_stars_repo_name": "BhadraNivedita/MBK", "max_stars_repo_head_hexsha": "95ad77612cdfc1e3a043b53a5cbaccc8283e019f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fre-kon.f", "max_issues_repo_name": "BhadraNivedita/MBK", "max_issues_repo_head_hexsha": "95ad77612cdfc1e3a043b53a5cbaccc8283e019f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fre-kon.f", "max_forks_repo_name": "BhadraNivedita/MBK", "max_forks_repo_head_hexsha": "95ad77612cdfc1e3a043b53a5cbaccc8283e019f", "max_forks_repo_licenses": ["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.48, "max_line_length": 62, "alphanum_fraction": 0.5728952772, "num_tokens": 1075, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995483, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.673496411525304}} {"text": " SUBROUTINE QRITER (VAL,O,LOC,QR)\r\nC\r\nC ORTEGA-KAISER QR ITERATION FOR A LARGE TRIDIAGONAL MATRIX\r\nC\r\n INTEGER LOC(1),QR,SYSBUF,MSG(10)\r\n REAL LFREQ\r\n DOUBLE PRECISION VAL(1),O(1),SHIFT,ZERO,ONE,ONES,EPSI,G,R,S,T,U,\r\n 1 DLMDAS\r\n CHARACTER*5 BELOW,ABOVE,BELABV\r\n CHARACTER UFM*23,UWM*25,UIM*29\r\n COMMON /XMSSG / UFM,UWM,UIM\r\n COMMON /SYSTEM/ SYSBUF,NOUT\r\n COMMON /GIVN / IDUM0(100),N,LFREQ,IDUM3,IDUM4,HFREQ,LAMA,NV,\r\n 1 NE,IDUM9,NFOUND,IDUM11,IDUM12,IDUM13,NEVER,MAX\r\n COMMON /REIGKR/ IOPTN\r\n COMMON /MGIVXX/ DLMDAS\r\n DATA EPSI , ZERO,ONE,MSG/ 1.0D-10, 0.0D+0, 1.0D+0, 53,9*0 /\r\n DATA MGIV , BELOW,ABOVE / 4HMGIV, 'BELOW', 'ABOVE' /\r\nC\r\nC VAL = DIAGONAL TERMS OF THE TRIDIAGONAL.\r\nC REORDERED EIGENVALUES UPON RETURN.\r\nC O = SQUARE OF THE OFF-DIAGIONAL TERMS OF THE TRIDIAGONAL.\r\nC LOC = ORIGINAL LOCATIONS OF THE REORDERED EIGENVALUES.\r\nC QR = 1 MEANS VAL= EIGENVALUES--JUST REORDER THEM\r\nC N = ORDER OF THE PROBLEM = ALSO NO. OF FREQ. EXTRACTED\r\nC MAX = MAXIMUM NUMBER OF ITERATIONS\r\nC SHIFT = SHIFT FACTOR (SMALLEST DIAGONAL TERM\r\nC LFREQ , HFREQ = FREQ. RANGE OF INTEREST IF NV IS ZERO\r\nC NV = NUMBER OF EIGENVECTORS TO BE COMPUTED, SAVED AND OUTPUT.\r\nC IF NV IS ZERO (INPUT), AND LFREQ-HFREQ ARE PRESENT, NV IS\r\nC SET TO BE NO. OF MODES WITHIN THE FREQ. RANGE (OUTPUT)\r\nC NE = NO. OF EIGENVALUES (INCLUDING RIGID MODES) TO BE PRINTED.\r\nC ALL, IF NE IS NOT SPECIFIED.\r\nC IF NE .LT. NV, NE IS SET EQUAL TO NV\r\nC\r\n MAX = 100*N\r\n IF (NV .GT. N) NV = N\r\n IF (NE .EQ. 0) NE = N\r\n IF (NE .LT. NV) NE = NV\r\nC\r\nC IS THIS AN ORDERING ONLY CALL\r\nC\r\n NEVER = 0\r\n IF (QR .NE. 0) GO TO 150\r\nC\r\nC SEARCH FOR A DECOUPLED SUBMATRIX.\r\nC\r\n M2 = N\r\n 100 M2M1 = M2 - 1\r\n DO 101 K = 1,M2M1\r\n M1 = M2 - K\r\n IF (O(M1) .NE. ZERO) GO TO 102\r\n 101 CONTINUE\r\nC\r\nC ALL OFF-DIAGONAL TERMS ARE ZEROS, JOB DONE. GO TO 150\r\nC THE DIAGONALS CONTAIN THE EIGENVALUES.\r\nC\r\n GO TO 150\r\nC\r\nC DECOUPLED SUBMATRIX\r\nC\r\n 102 M2M1 = M1\r\n M2 = M1 + 1\r\n IF (M2M1 .EQ. 1) GO TO 105\r\n DO 103 K = 2,M2M1\r\n M1 = M2 - K\r\n IF (O(M1) .EQ. ZERO) GO TO 104\r\n 103 CONTINUE\r\n GO TO 105\r\n 104 M1 = M1 + 1\r\n 105 MM = M1\r\nC\r\nC Q-R ITERATION FOR THE DECOUPLED SUBMATRIX\r\nC\r\n 110 DO 135 ITER = 1,MAX\r\n IF (DABS(VAL(M2))+O(M2M1) .EQ. DABS(VAL(M2))) GO TO 140\r\n DO 111 K = M1,M2M1\r\n IF (VAL(K) .NE. VAL(K+1)) GO TO 115\r\n 111 CONTINUE\r\n SHIFT = ZERO\r\n GO TO 120\r\nC\r\nC FIND THE SMALLEST DIAGONAL TERM = SHIFT\r\nC\r\n 115 SHIFT = VAL(M2)\r\n DO 116 I = M1,M2M1\r\n IF (DABS(VAL(I)) .LT. DABS(SHIFT)) SHIFT = VAL(I)\r\n 116 CONTINUE\r\nC\r\nC REDUCE ALL TERMS BY SHIFT\r\nC\r\n DO 117 I = M1,M2\r\n VAL(I) = VAL(I) - SHIFT\r\n 117 CONTINUE\r\nC\r\nC Q-R ITERATION\r\nC\r\n 120 R = VAL(M1)**2\r\n S = O(M1)/(R+O(M1))\r\n T = ZERO\r\n U = S*(VAL(M1) + VAL(M1+1))\r\n VAL(M1) = VAL(M1) + U\r\n IF (M1 .EQ. M2M1) GO TO 125\r\n M1P1 = M1 + 1\r\n DO 123 I = M1P1,M2M1\r\n G = VAL(I) - U\r\n R = (ONE-T)*O(I-1)\r\n ONES = ONE - S\r\n IF (DABS(ONES) .GT. EPSI) R = G*G/ONES\r\n R = R + O(I)\r\n O(I-1) = S*R\r\n IF (O(I-1) .EQ. ZERO) MM = I\r\n T = S\r\nC\r\nC IBM MAY FLAG AN EXPONENT UNDERFLOW ON NEXT LINE.\r\nC IT IS PERFECTLY OK SINCE O(I) SHOULD BE APPROACHING ZERO.\r\nC\r\n S = O(I)/R\r\n U = S*(G + VAL(I+1))\r\n VAL(I) = U + G\r\n 123 CONTINUE\r\nC\r\n 125 VAL(M2) = VAL(M2) - U\r\n R = (ONE-T)*O(M2M1)\r\n ONES = ONE - S\r\n IF (DABS(ONES) .GT. EPSI) R = VAL(M2)**2/ONES\r\n O(M2M1) = S*R\r\nC\r\nC SHIFT BACK\r\nC\r\n IF (SHIFT .EQ. ZERO) GO TO 133\r\n DO 130 I = M1,M2\r\n VAL(I) = VAL(I) + SHIFT\r\n 130 CONTINUE\r\n 133 M1 = MM\r\n 135 CONTINUE\r\nC\r\nC TOO MANY ITERATIONS\r\nC\r\nC\r\nC THE ACCURACY OF EIGENVALUE XXXXX IS IN DOUBT--QRITER FAILED TO\r\nC CONVERGE IN XX ITERATIONS\r\nC\r\n NEVER = NEVER + 1\r\n CALL MESAGE (MSG(1),VAL(M2),MAX)\r\nC\r\nC CONVERGENCE ACHIEVED\r\nC\r\n 140 IF (M1 .EQ. M2M1) GO TO 145\r\n M2 = M2M1\r\n M2M1 = M2 -1\r\n GO TO 110\r\n 145 IF (M1 .LE. 2) GO TO 150\r\n M2 = M1 - 1\r\n GO TO 100\r\n 150 IF (N .EQ. 1) GO TO 205\r\nC\r\nC REORDER EIGENVALUES ALGEBRAICALLY IN ASCENDING ORDER\r\nC\r\n IF (IOPTN .NE. MGIV) GO TO 155\r\nC\r\nC FOR MGIV METHOD, RECOMPUTE LAMBDA\r\nC\r\n DO 153 K = 1,N\r\n VAL(K) = (1.0D0/VAL(K)) - DLMDAS\r\n 153 CONTINUE\r\n 155 CONTINUE\r\n DO 190 K = 1,N\r\n DO 160 M = 1,N\r\n IF (VAL(M) .NE. -10000.0D0) GO TO 170\r\n 160 CONTINUE\r\n 170 IF (M .EQ. N) GO TO 185\r\n MP1 = M + 1\r\n DO 180 I = MP1,N\r\n IF (VAL(I) .EQ. -10000.0D0) GO TO 180\r\n IF (VAL(M) .GT. VAL(I)) M = I\r\n 180 CONTINUE\r\n 185 O(K) = VAL(M)\r\n VAL(M) =-10000.0D0\r\n LOC(K) = M\r\n 190 CONTINUE\r\n DO 195 I = 1,N\r\n VAL(I) = O(I)\r\n 195 CONTINUE\r\nC\r\nC IF RIGID MODES WERE FOUND BEFORE, REPLACE RIGID FREQ. BY ZERO\r\nC\r\n IF (NFOUND .EQ. 0) GO TO 205\r\n DO 200 I = 1,NFOUND\r\n VAL(I) = ZERO\r\n 200 CONTINUE\r\nC\r\nC OUTPUT OPTION CHECK - BY FREQ. RANGE OR BY NO. OF FREQ.\r\nC REQUESTED\r\nC\r\n 205 IB = 1\r\n IF (NV .NE. 0) GO TO 225\r\n IF (LFREQ .LE. 0.0) GO TO 225\r\nC\r\nC LOCATE PONTER THAT POINTS TO EIGENVALUE ABOVE OR EQUAL THE\r\nC LOWEST LFREQ. AS REQUESTED.\r\nC\r\n DO 215 I = 1,N\r\n IF (VAL(I) .GE. LFREQ) GO TO 220\r\n 215 CONTINUE\r\n I = 0\r\n 220 IB = I\r\nC\r\nC OPEN LAMA FOR OUTPUT\r\nC PUT EIGENVALUES ON LAMA FOLLOWED BY ORDER FOUND\r\nC\r\n 225 IBUF1 = (KORSZ(O)-SYSBUF+1)/2\r\n CALL GOPEN (LAMA,O(IBUF1),1)\r\n NN = 0\r\n IF (IB .EQ. 0) GO TO 240\r\n DO 230 I = IB,N\r\n VALX = VAL(I)\r\n IF (NV.NE.0 .AND. I.GT. NE) GO TO 240\r\n IF (NV.EQ.0 .AND. VALX.GT.HFREQ) GO TO 240\r\n CALL WRITE (LAMA,VALX,1,0)\r\n NN = NN + 1\r\n 230 CONTINUE\r\nC\r\n 240 CONTINUE\r\nC\r\nC IF FREQ. RANGE IS REQUESTED, AND ALL FREQ. FOUND ARE OUTSIDE THE\r\nC RANGE, OUTPUT AT LEAST ONE FREQ.\r\nC\r\n IF (NN .GT. 0) GO TO 260\r\n IF (IB .EQ. 0) BELABV = BELOW\r\n IF (IB .NE. 0) BELABV = ABOVE\r\n WRITE (NOUT,250) UIM,BELABV\r\n 250 FORMAT (A29,', ALL ROOTS FOUND WERE ',A5,' FREQ. RANGE SPECIFIED',\r\n 1 /5X,'HOWEVER, ONE EIGENVALUE OUTSIDE THIS FREQ. RANGE WAS',\r\n 2 ' SAVED AND PRINTED')\r\n NN = 1\r\n IF (IB .NE. 0) IB = N\r\n IF (IB .EQ. 0) IB = 1\r\n CALL WRITE (LAMA,VAL(IB),1,0)\r\n 260 CALL WRITE (LAMA,0,0,1)\r\n CALL WRITE (LAMA,LOC(IB),NN,1)\r\n CALL CLOSE (LAMA,1)\r\n MSG(2) = LAMA\r\n MSG(3) = NN\r\n CALL WRTTRL (MSG(2))\r\nC\r\nC IF FREQ. DOES NOT START FROM FIRST FUNDAMENTAL MODE, ADJUST VAL\r\nC AND LOC TABLES SO THAT WILVEC WILL PICK UP FREQUENCIES CORRECTLY\r\nC\r\n IF (IB .LE. 1) GO TO 280\r\n J = 1\r\n DO 270 I = IB,N\r\n VAL(J) = VAL(I)\r\n LOC(J) = LOC(I)\r\n 270 J = J + 1\r\nC\r\n 280 IF (NV.EQ.0 .AND. IB.GT.1 .AND. NN.LT.NFOUND .AND. VAL(1).LE.ZERO)\r\n 1 NFOUND = 0\r\n IF (NV .EQ. 0) NV = NN\r\n RETURN\r\n END\r\n", "meta": {"hexsha": "86d2850996d78a72a67ca330e7ed076b7d9660c9", "size": 7263, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "mis/qriter.f", "max_stars_repo_name": "ldallolio/NASTRAN-95", "max_stars_repo_head_hexsha": "6d2c175f5b53ebaec4ba2b5186f7926ef9d0ed47", "max_stars_repo_licenses": ["NASA-1.3"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2016-01-09T14:33:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-18T11:51:42.000Z", "max_issues_repo_path": "mis/qriter.f", "max_issues_repo_name": "gassive/NASTRAN95", "max_issues_repo_head_hexsha": "98cb3acaa7990d639360601648498834c7782056", "max_issues_repo_licenses": ["NASA-1.3"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2016-01-17T07:30:19.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-06T19:37:44.000Z", "max_forks_repo_path": "mis/qriter.f", "max_forks_repo_name": "gassive/NASTRAN95", "max_forks_repo_head_hexsha": "98cb3acaa7990d639360601648498834c7782056", "max_forks_repo_licenses": ["NASA-1.3"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-04-07T20:51:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T14:16:01.000Z", "avg_line_length": 27.7213740458, "max_line_length": 73, "alphanum_fraction": 0.5336637753, "num_tokens": 2893, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853654, "lm_q2_score": 0.7577943658046608, "lm_q1q2_score": 0.6734964107335447}} {"text": "module user_defined_functions\n use num_integration\n use utils, only : wp\n implicit none\n\n abstract interface\n function f_interface(x)\n import :: wp\n real(wp), intent(in) :: x\n real(wp) :: f_interface\n end function f_interface\n\n function linear_spline_interface(y,x)\n import :: wp\n real(wp), intent(in) :: y(3),x\n real(wp) :: linear_spline_interface\n end function linear_spline_interface\n\n function cubic_spline_interface(y,x)\n import :: wp\n real(wp), intent(in) :: y(5),x\n real(wp) :: cubic_spline_interface\n end function cubic_spline_interface\n end interface\n\n type, extends(fun) :: inner_product_l_obj\n ! Support nodes for base i and base j of the spline\n real(wp), allocatable :: yi(:), yj(:)\n\n ! Pointers to f, q and k function, as described by\n ! the formula.\n procedure(f_interface), pointer, nopass :: k,q\n\n ! Pointers to linear_spline functions\n procedure(linear_spline_interface), pointer, nopass :: l,dl\n\n ! Pointers to cubic_spline functions\n procedure(cubic_spline_interface), pointer, nopass :: c,dc\n\n ! Only cubic or linear splines pointers will be\n ! assigned, depending on the size of the y array.\n\n contains\n procedure :: eval => inner_product_l_eval\n end type inner_product_l_obj\n\n type, extends(fun) :: inner_product_obj\n ! Support nodes for base i and base j of the spline\n real(wp), allocatable :: y(:)\n\n procedure(f_interface), pointer, nopass :: f\n\n ! Pointers to linear_spline functions\n procedure(linear_spline_interface), pointer, nopass :: l\n\n ! Pointers to cubic_spline functions\n procedure(cubic_spline_interface), pointer, nopass :: c\n\n ! Only cubic or linear splines pointers will be\n ! assigned, depending on the size of the y array.\n\n contains\n procedure :: eval => inner_product_eval\n end type inner_product_obj\n\ncontains\n function inner_product_l_eval(self, x)\n class(inner_product_l_obj), intent(in) :: self\n real(wp), intent(in) :: x\n real(wp) :: inner_product_l_eval\n\n if ( size(self%yi) == 3 ) then\n ! Inner product for linear_splines\n inner_product_l_eval = &\n self%k(x) * self%dl(self%yi,x) * self%dl(self%yj,x) &\n + self%q(x) * self%l(self%yi,x) * self%l(self%yj,x)\n\n elseif ( size(self%yi) == 5 ) then\n ! Inner product for cubic_splines\n inner_product_l_eval = &\n self%k(x) * self%dc(self%yi,x) * self%dc(self%yj,x) &\n + self%q(x) * self%c(self%yi,x) * self%c(self%yj,x)\n\n else\n ! Something went wrong\n write(*,*) \"Incorrect usage.\"\n inner_product_l_eval = 0.0_wp\n end if\n end function inner_product_l_eval\n\n function inner_product_eval(self, x)\n class(inner_product_obj), intent(in) :: self\n real(wp), intent(in) :: x\n real(wp) :: inner_product_eval\n\n if ( size(self%y) == 3 ) then\n ! Inner product for linear_splines\n inner_product_eval = &\n self%f(x) * self%l(self%y,x)\n\n elseif ( size(self%y) == 5 ) then\n ! Inner product for cubic_splines\n inner_product_eval = &\n self%f(x) * self%c(self%y,x)\n else\n ! Something went wrong\n write(*,*) \"Incorrect usage.\"\n inner_product_eval = 0.0_wp\n end if\n end function inner_product_eval\n\n subroutine set_inner_product_l(ipo,yi,yj,k,q,phi,dphi)\n class(inner_product_l_obj), intent(inout) :: ipo\n real(wp), external :: q,k,f,phi,dphi\n real(wp), intent(in) :: yi(:),yj(:)\n! allocate(ipo%yi(size(yi)))\n! allocate(ipo%yj(size(yj)))\n ipo%yi = yi\n ipo%yj = yj\n ipo%k => k\n ipo%q => q\n if ( size(yi) == 3 ) then\n ! Pointers to linear_spline functions\n ipo%l => phi\n ipo%dl => dphi\n elseif ( size(yi) == 5 ) then\n ! Pointers to cubic_spline functions\n ipo%c => phi\n ipo%dc => dphi\n end if\n end subroutine set_inner_product_l\n\n subroutine set_inner_product(ipo,y,f,phi)\n class(inner_product_obj), intent(inout) :: ipo\n real(wp), external :: f,phi\n real(wp), intent(in) :: y(:)\n ipo%y = y\n ipo%f => f\n if ( size(y) == 3 ) then\n ! Pointers to linear_spline functions\n ipo%l => phi\n elseif ( size(y) == 5 ) then\n ! Pointers to cubic_spline functions\n ipo%c => phi\n end if\n end subroutine set_inner_product\n\n function estimated_function(alpha,x,support_nodes,spline_base)\n real(wp), external :: spline_base\n real(wp), intent(in) :: alpha(:),support_nodes(:,:)\n real(wp), intent(in) :: x\n real(wp) :: estimated_function\n integer :: i\n estimated_function = 0\n do i = 1, size(alpha)\n estimated_function = estimated_function + alpha(i)*spline_base(support_nodes(i,1:),x)\n end do\n end function estimated_function\n\nend module user_defined_functions\n\nprogram main\nuse utils\n!use bm_ge\nuse g_elimination\nuse num_integration\nuse bspline\nuse user_defined_functions\nuse ogpf\n\nimplicit none\n\n\n!---------------\n! Variables\n!---------------\n\ninteger :: i,j,romberg_iterations\ninteger, allocatable :: n(:)\nreal(wp) :: x,error\nreal(wp), allocatable :: error_array_linear(:),error_array_cubic(:)\ntype(gpf):: gp\n\n!---------------\n! Logic\n!---------------\n\nwrite(*,*) \"Program started!\"\n\n! Array of number of internal nodes for the integration\nallocate(n(7))\n\n! Array for plotting errors\nallocate(error_array_linear(7))\nallocate(error_array_cubic(7))\n\n! Number of internal nodes for the integration\nn(1:) = [7, 15, 31, 63, 127, 255, 511]\n\nromberg_iterations = 7\n! ---------------------------\n! Solving with linear splines\n! ---------------------------\ndo i = 1, 1\n! call solve_finite_elements(n(i),linear_spline,linear_spline_deriv,.false.,romberg_iterations,error)\n! error_array_linear(i) = error\nend do\n\n!call gp%plot(linspace(1.0_wp,4.0_wp,4),error_array_linear(1:4))\n\n! ---------------------------\n! Solving with cubic splines\n! ---------------------------\ndo i = 1, 2\n call solve_finite_elements(n(i),cubic_spline,cubic_spline_deriv,.true.,romberg_iterations,error)\n error_array_cubic(i) = error\nend do\n\n!call gp%plot(linspace(1.0_wp,4.0_wp,4), error_array_cubic(1:4))\n\ncontains\n\n! User defined functions for the problem\n! to be solved go here\n\n function k(x)\n real(wp), intent(in) :: x\n real(wp) :: k\n k = 1\n end function k\n\n function q(x)\n real(wp), intent(in) :: x\n real(wp) :: q\n q = 0\n end function q\n\n function f(x)\n real(wp), intent(in) :: x\n real(wp) :: f\n f = (pi**2)*(sin(pi*x)-9*sin(3*pi*x))\n end function f\n\n function u(x)\n real(wp), intent(in) :: x\n real(wp) :: u\n u = sin(pi*x) - sin(3*pi*x)\n end function u\n\n subroutine solve_finite_elements(n,base_spline,base_spline_deriv,type,romberg_iterations,error)\n integer, intent(in) :: n,romberg_iterations\n real(wp), intent(inout) :: error\n real(wp), external :: base_spline,base_spline_deriv\n ! Flag:\n ! If .true. cubic, if .false. linear\n logical, intent(in) :: type\n integer :: i,j,l,o,m,ub,lb,ms,lini,lend,c\n integer :: num_basis,total_num_nodes,num_nodes_ep,num_support_nodes,total_num_support_nodes\n real(wp), parameter :: alpha = 0.0_wp\n real(wp), parameter :: omega = 1.0_wp\n real(wp) :: a,b,h,x,result\n real(wp), allocatable :: integration_range(:),support_node_i(:)&\n ,support_node_j(:), f_phi(:), coef(:)&\n ,support_nodes_array(:,:), plot_expected(:)&\n ,plot_calculated(:)\n type(inner_product_l_obj) :: ipol\n type(inner_product_obj) :: ipo\n type(col), allocatable :: Row(:)\n type(gpf):: gp\n\n write(*,*) \"-------------------------\"\n write(*,*) \"Number of internal nodes:\"\n write(*,*) n\n write(*,*)\n write(*,*) \"Solving with:\"\n\n ! Number of upper and lower bands\n ! ub = lb = 1 iff linear splines\n ! ub = lb = 3 iff cubic splines\n ! Number of support nodes\n ! 3 = Linear Spline\n ! 5 = Cubic Spline\n if ( type ) then\n write(*,*) \"Cubic Splines\"\n write(*,*)\n ub = 3\n lb = 3\n ! Number of internal nodes\n num_support_nodes = 3\n ! Total number of nodes\n total_num_support_nodes = num_support_nodes+2\n else\n write(*,*) \"Linear Splines\"\n write(*,*)\n ub = 1\n lb = 1\n ! Number of internal nodes\n num_support_nodes = 1\n ! Total number of nodes\n total_num_support_nodes = num_support_nodes+2\n end if\n\n ! Total number of integration nodes\n ! total_num_nodes = internal nodes + 2\n total_num_nodes = n+2\n\n ! Saving results for plots\n allocate(plot_expected(total_num_nodes))\n allocate(plot_calculated(total_num_nodes))\n\n ! Number of b-spline basis\n num_basis = total_num_nodes+(num_support_nodes-1)\n\n ! Extended partition\n num_nodes_ep = total_num_nodes+2*num_support_nodes\n\n ! Banded matrix structure\n allocate(Row(num_basis))\n\n ! Array for the result of the\n ! inner product between f and the splines\n allocate(f_phi(num_basis))\n\n ! Coefficients alpha\n allocate(coef(num_basis))\n\n ! Stepsize\n h = 1.0_wp/(n+1.0_wp)\n write(*,*) \"Step size\"\n write(*,*) h\n write(*,*)\n\n ! Nodes in the integration range\n allocate(integration_range(num_nodes_ep))\n\n do i = 1, num_nodes_ep\n integration_range(i) = (i-total_num_support_nodes+1)*h\n end do\n\n ! Support nodes for the splines\n allocate(support_node_i(total_num_support_nodes))\n allocate(support_node_j(total_num_support_nodes))\n allocate(support_nodes_array(num_basis,total_num_support_nodes))\n\n write(*,*) \"Creating banded matrix\"\n write(*,*) \". . .\"\n do m = 1,num_basis\n ! Construct support nodes for the spline i\n do i = 1,total_num_support_nodes\n support_node_i(i) = integration_range(m) + (i-1)*h\n end do\n\n ! Save this support node array for later use\n ! at the `estimated_function` method\n support_nodes_array(m,1:) = support_node_i(1:)\n\n call set_inner_product(ipo,support_node_i,&\n f,&\n base_spline&\n )\n\n a = max(support_node_i(1),0.0_wp)\n b = min(support_node_i(size(support_node_i)),1.0_wp)\n f_phi(m) = romberg(ipo, a, b, romberg_iterations)\n\n ! Calculating how many support nodes\n ! phi_j shall be used in the L inner\n ! product agains phi_i\n lini = -num_support_nodes\n lend = num_support_nodes\n if ( m < lb+1 ) then\n lini = 0+(1-m)\n lend = num_support_nodes\n elseif ( m > num_basis-ub ) then\n lini = -num_support_nodes\n lend = num_support_nodes-(ub+m-num_basis)\n end if\n allocate(Row(m)%col(2*(num_support_nodes)+1-(abs(lini+lend))))\n\n ! Variable o helps with indexing\n o = 1\n do j = lini,lend\n ! Set support node values for the spline j\n do i = 1,total_num_support_nodes\n support_node_j(i) = integration_range(m+j) + (i-1)*h\n end do\n\n ! Test\n !write(*,*) support_node_i\n !write(*,*) support_node_j\n !write(*,*)\n\n ! Set values the inner product,\n ! according to the given formula\n call set_inner_product_l(ipol,support_node_i,support_node_j,&\n k,q,&\n base_spline,base_spline_deriv&\n )\n\n ! Define integration limits\n a = min(support_node_i(1), support_node_j(1))\n b = max(support_node_i(total_num_support_nodes),&\n support_node_j(total_num_support_nodes))\n\n ! Integrate inner product using Romberg's\n ! Save result in the banded matrix structure\n Row(m)%col(o) = romberg(ipol, a, b, romberg_iterations)\n\n o = o + 1\n end do\n end do\n write(*,*) \"Banded matrix creation complete\"\n write(*,*)\n\n ! Test\n call pprint_band(Row,lb,ub)\n write(*,*)\n write(*,'(F10.5)') coef\n write(*,*)\n write(*,'(F10.5)') f_phi\n write(*,*)\n\n write(*,*) \"Performing gaussian elimination\"\n write(*,*) \". . .\"\n call gaussian_elimination_banded(Row,coef,f_phi,lb,ub)\n write(*,*) \"Gaussian elimination complete\"\n write(*,*)\n\n ! Test\n call pprint_band(Row,lb,ub)\n write(*,*)\n write(*,'(F10.5)') coef\n write(*,*)\n write(*,'(F10.5)') f_phi\n write(*,*)\n\n write(*,*) \"Calculating Error`s Infinity Norm\"\n write(*,*) \". . .\"\n\n error = 0.0_wp\n do i = 1, total_num_nodes\n\n x = integration_range(i+num_support_nodes)\n ! Test\n !write(*,*) x\n plot_expected(i) = u(x)\n\n plot_calculated(i) = estimated_function(coef,x,support_nodes_array,base_spline)\n\n if ( abs(plot_calculated(i)-plot_expected(i)) > error ) then\n error = abs(plot_calculated(i)-plot_expected(i))\n end if\n\n end do\n write(*,*) \"Error: \",error\n write(*,*)\n\n write(*,*) \"Now plotting\"\n write(*,*) \". . .\"\n if ( type ) then\n call gp%title('Cubic Spline')\n else\n call gp%title('Linear Spline')\n end if\n call gp%options('set key top right; set grid')\n call gp%plot(x1=integration_range(1+num_support_nodes:num_nodes_ep-num_support_nodes),&\n y1=plot_expected,&\n ls1='title \"Expected\" with lines lt 1 lw 1',&\n x2=integration_range(1+num_support_nodes:num_nodes_ep-num_support_nodes),&\n y2=plot_calculated,&\n ls2='title \"Calculated\" with lines lt 2 lw 1')\n\n write(*,*) \"Plotting done\"\n write(*,*)\n write(*,*) \"Problem solved\"\n write(*,*) \"---------------\"\n write(*,*)\n end subroutine solve_finite_elements\nend program main\n", "meta": {"hexsha": "ac854ebd8746b293da515ec3013ae0cf1751e7ae", "size": 13529, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "main_old.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": "main_old.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": "main_old.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.1854166667, "max_line_length": 102, "alphanum_fraction": 0.6188188336, "num_tokens": 3795, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587905460026, "lm_q2_score": 0.7577943658046609, "lm_q1q2_score": 0.6734964040351255}} {"text": "\nc---------------------------------------------------------------------\nc---------------------------------------------------------------------\n subroutine l2norm (v, sum, nx, nxmax, ny, nz)\nc---------------------------------------------------------------------\nc---------------------------------------------------------------------\n\nc---------------------------------------------------------------------\nc to compute the l2-norm of vector v.\nc---------------------------------------------------------------------\n\n implicit none\n\nc---------------------------------------------------------------------\nc input parameters\nc---------------------------------------------------------------------\n integer nx, nxmax, ny, nz\n double precision v(5,nxmax,ny,nz), sum(5)\n\nc---------------------------------------------------------------------\nc local variables\nc---------------------------------------------------------------------\n integer i, j, k, m\n double precision sum_cap(5)\n\n\n do m = 1, 5\n sum(m) = 0.0d+00\n end do\n\n!$OMP PARALLEL DEFAULT(SHARED) PRIVATE(sum_cap,m,i,j,k)\n!$OMP& SHARED(nx,ny,nz)\n do m=1,5\n sum_cap(m)=0.0d0\n enddo\n do k = 2, nz-1\n!$OMP DO SCHEDULE(STATIC)\n do j = 2, ny-1\n do i = 2, nx-1\n do m = 1, 5\n sum_cap(m) = sum_cap(m) + v(m,i,j,k) * v(m,i,j,k)\n end do\n end do\n end do\n!$OMP END DO nowait\n end do\n do m=1,5\n!$OMP ATOMIC\n sum(m)=sum(m)+sum_cap(m)\n enddo\n!$OMP END PARALLEL\n\n do m = 1, 5\n sum(m) = dsqrt(sum(m) / (dble(nz-2)*dble(ny-2)*dble(nx-2)))\n end do\n\n return\n end\n", "meta": {"hexsha": "e5c4cc6bb1304db05913cae56c9c80b30eb32804", "size": 1702, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "examples/NPB3.2-MZ-MPI/LU-MZ/l2norm.f", "max_stars_repo_name": "robert-mijakovic/readex-ptf", "max_stars_repo_head_hexsha": "5514b0545721ef27de0426a7fa0116d2e0bb5eef", "max_stars_repo_licenses": ["BSD-3-Clause-No-Nuclear-License-2014", "BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-10T09:59:37.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-10T09:59:37.000Z", "max_issues_repo_path": "examples/NPB3.2-MZ-MPI/LU-MZ/l2norm.f", "max_issues_repo_name": "robert-mijakovic/readex-ptf", "max_issues_repo_head_hexsha": "5514b0545721ef27de0426a7fa0116d2e0bb5eef", "max_issues_repo_licenses": ["BSD-3-Clause-No-Nuclear-License-2014", "BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-04-21T07:57:32.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-14T08:05:41.000Z", "max_forks_repo_path": "examples/NPB3.2-MZ-MPI/LU-MZ/l2norm.f", "max_forks_repo_name": "robert-mijakovic/readex-ptf", "max_forks_repo_head_hexsha": "5514b0545721ef27de0426a7fa0116d2e0bb5eef", "max_forks_repo_licenses": ["BSD-3-Clause-No-Nuclear-License-2014", "BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-20T03:04:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-20T03:04:32.000Z", "avg_line_length": 28.8474576271, "max_line_length": 70, "alphanum_fraction": 0.2931844888, "num_tokens": 394, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.851952809486198, "lm_q2_score": 0.7905303260722198, "lm_q1q2_score": 0.6734945322812679}} {"text": "module functions\n implicit none\ncontains\n\nfunction binsearch(n,a)\n implicit none\n integer(2) :: binsearch,left,right,mid\n integer(8) :: n,a(:)\n\n left=1\n right=size(a)\n if ( n >= a(right) ) then\n binsearch=right\n return\n end if\n do while ( .true. )\n mid=(left+right)/2\n if ( left == mid .or. n == a(mid) ) exit\n if ( n > a(mid) ) then\n left=mid\n else\n right=mid\n end if\n end do\n binsearch=mid\n return\nend function binsearch\n\nfunction nchoosek(n,k)\n implicit none\n integer(2) :: k,n,i,ia,ib\n integer(8) :: nchoosek\n real(8) :: A,B\n\n if ( k < n-k ) then\n ia=n-k+1\n ib=k\n else\n ia=k+1\n ib=n-k\n end if\n A=1;B=1\n do i=ia,n\n A=A*i\n end do\n do i=2,ib\n B=B*i\n end do\n nchoosek=A/B+0.5\n return\nend function nchoosek\n\nfunction complement(a,m)\n implicit none\n integer(2) :: i,j,m\n integer(2) :: a(:),c(m)\n integer(2) :: complement(m)\n\n c=1\n c(a)=0\n j=0\n complement=0\n do i=1,m\n if ( c(i) /= 0 ) then\n j=j+1\n complement(j)=i\n end if\n end do\n return\nend function complement\n\nfunction width(i_1,i_2,i_4,i_8)\n integer(1) :: width\n integer(1),optional :: i_1\n integer(2),optional :: i_2\n integer(4),optional :: i_4\n integer(8),optional :: i_8\n character(len=20) :: w\n\n if ( present(i_1) ) write(w,'(I20)') i_1\n if ( present(i_2) ) write(w,'(I20)') i_2\n if ( present(i_4) ) write(w,'(I20)') i_4\n if ( present(i_8) ) write(w,'(I20)') i_8\n width=len_trim(adjustl(w))\nend function width\n\nfunction norm(A)\n implicit none\n real(8) :: norm\n real(8) :: A(3)\n\n norm=dsqrt(A(1)**2+A(2)**2+A(3)**2)\n return\nend function norm\n\nfunction cross(A,B)\n implicit none\n real(8) :: cross(3)\n real(8) :: A(3),B(3)\n\n cross(1)=A(2)*B(3)-A(3)*B(2)\n cross(2)=A(3)*B(1)-A(1)*B(3)\n cross(3)=A(1)*B(2)-A(2)*B(1)\n return\nend function cross\n\nfunction trace(A)\n implicit none\n integer(1) :: trace,A(:,:)\n\n trace=A(1,1)+A(2,2)+A(3,3)\n return\nend function trace\n\nfunction det(A)\n implicit none\n integer(1) :: det\n integer(1) :: A(3,3)\n\n det= A(1,1)*(A(2,2)*A(3,3)-A(2,3)*A(3,2))\n det=det-A(1,2)*(A(2,1)*A(3,3)-A(2,3)*A(3,1))\n det=det+A(1,3)*(A(2,1)*A(3,2)-A(2,2)*A(3,1))\n return\nend function det\n\nfunction inverse(A)\n implicit none\n integer(1) :: i,j,N\n real(8) :: inverse(3,3)\n real(8) :: A(:,:)\n real(8) :: B(3,3),IA(3,3)\n\n N=3\n forall(i=1:N,j=1:N,i==j) IA(i,j)=1.D0\n forall(i=1:N,j=1:N,i/=j) IA(i,j)=0.D0\n B=A\n call upper(B,IA,N)\n call lower(B,IA,N)\n forall(i=1:N) IA(i,:)=IA(i,:)/B(i,i)\n inverse=IA\n return\nend function inverse\n\nsubroutine upper(M,S,N)\n implicit none\n integer(1) :: N\n real(8) :: M(N,N)\n real(8) :: S(N,N)\n integer(1) :: I,J\n real(8) :: E\n\n do I=1,N-1\n do J=I+1,N\n E=M(J,I)/M(I,I)\n M(J,I:N)=M(J,I:N)-M(I,I:N)*E\n S(J,:)=S(J,:)-S(I,:)*E\n end do\n end do\n return\nend subroutine upper\n\nsubroutine lower(M,S,N)\n implicit none\n integer(1) :: N\n real(8) :: M(N,N)\n real(8) :: S(N,N)\n integer(1) :: I,J\n real(8) :: E\n\n do I=N,2,-1\n do J=I-1,1,-1\n E=M(J,I)/M(I,I)\n M(J,I:N)=M(J,I:N)-M(I,I:N)*E\n S(J,:)=S(J,:)-S(I,:)*E\n end do\n end do\n return\nend subroutine lower\n\nrecursive subroutine sort(A,left,right)\n implicit none\n integer(2),intent(in out) :: A(:)\n integer(2),intent(in) :: left,right\n integer(2) :: temp,t\n integer(2) :: i,j\n\n if ( left > right ) then\n return\n end if\n temp=A(left)\n i=left\n j=right\n do while ( i /= j )\n do while ( A(j) >= temp .and. i < j )\n j=j-1\n end do\n do while ( A(i) <= temp .and. i < j )\n i=i+1\n end do\n if ( i < j ) then\n t=A(i)\n A(i)=A(j)\n A(j)=t\n end if\n end do\n A(left)=A(i)\n A(i)=temp\n call sort(A,left,i-1_2)\n call sort(A,i+1_2,right)\nend subroutine sort\n\nend module functions\n", "meta": {"hexsha": "178cd2f746d68fb99d82e41448923892b6528b21", "size": 3751, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/functions.f90", "max_stars_repo_name": "Caixinzhang-hnu/disorder", "max_stars_repo_head_hexsha": "4d34fcdf8845e1a9de1ba773381479bb2826eef7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-10-12T13:47:30.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-12T13:47:30.000Z", "max_issues_repo_path": "src/functions.f90", "max_issues_repo_name": "Caixinzhang-hnu/disorder", "max_issues_repo_head_hexsha": "4d34fcdf8845e1a9de1ba773381479bb2826eef7", "max_issues_repo_licenses": ["MIT"], "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/functions.f90", "max_forks_repo_name": "Caixinzhang-hnu/disorder", "max_forks_repo_head_hexsha": "4d34fcdf8845e1a9de1ba773381479bb2826eef7", "max_forks_repo_licenses": ["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.6103286385, "max_line_length": 46, "alphanum_fraction": 0.5537190083, "num_tokens": 1568, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905302989295535, "lm_q2_score": 0.8519527944504227, "lm_q1q2_score": 0.6734944972707612}} {"text": "!********************************************************************************\n!* -- Roe's Flux Function with entropy fix---\n!*\n!* P. L. Roe, Approximate Riemann Solvers, Parameter Vectors and Difference\n!* Schemes, Journal of Computational Physics, 43, pp. 357-372.\n!*\n!* NOTE: 3D version of this subroutine is available for download at\n!* http://cfdbooks.com/cfdcodes.html\n!*\n!* ------------------------------------------------------------------------------\n!* Input: primL(1:4) = left state (rhoL, uL, vL, pL)\n!* primR(1:4) = right state (rhoR, uR, vR, pR)\n!* njk(2) = Face normal (L -> R). Must be a unit vector.\n!*\n!* Output: flux(1:4) = numerical flux\n!* wsn = half the max wave speed\n!* (to be used for time step calculations)\n!* ------------------------------------------------------------------------------\n!*\n!* Written by Katate Masatsuka (http://www.cfdbooks.com)\n!* Edited by Nguyen Ngoc Sang (https://github.com/SangVn)\n!* ------------------------------------------------------------------------------\n!* F2PY - Calling Fortran routines from Python\n!* wrap this subroutine to python:\n!* python -m numpy.f2py -c fluxes_fortran.f90 -m fluxes_fortran\n!********************************************************************************\n subroutine roe(primL, primR, njk, flux, wsn)\n implicit none\n\n real(8), parameter :: zero = 0.0, one = 1.0, two = 2.0, half = 0.5, fifth = 1.0/ 5.0, gamma = 1.4, gamma_m1 = 0.4\n\n !Input:\n real(8), intent( in) :: primL(4), primR(4) ! [rho, u, v, p]_{L,R}\n real(8), intent( in) :: njk(2) ! Face normal, njk=[nx, ny]\n\n !Output\n real(8), intent(out) :: flux(4)\n real(8), intent(out) :: wsn\n\n !Local variables\n real(8) :: nx, ny ! Normal vector\n real(8) :: mx, my ! Tangent vector: mx*nx+my*ny = 0\n real(8) :: uL, uR, vL, vR ! Velocity components.\n real(8) :: rhoL, rhoR, pL, pR ! Primitive variables.\n real(8) :: unL, unR, umL, umR ! Normal and tangent velocities\n real(8) :: aL, aR, HL, HR ! Speeds of sound.\n real(8) :: RT,rho,u,v,H,a,un, um ! Roe-averages\n real(8) :: drho,dun,dum,dp,LdU(4) ! Wave strenghs\n real(8) :: ws(4), Rv(4,4) ! Wave speeds and right-eigevectors\n real(8) :: fL(4), fR(4), diss(4) ! Fluxes ad dissipation term\n real(8) :: dws(4) ! User-specified width for entropy fix\n integer :: i, j\n\n nx = njk(1)\n ny = njk(2)\n\n!Tangent vector (Do you like it? Actually, Roe flux can be implemented\n! without any tangent vector. See \"I do like CFD, VOL.1\" for details.)\n mx = -ny\n my = nx\n\n!Primitive and other variables.\n! Left state\n rhoL = primL(1)\n uL = primL(2)\n vL = primL(3)\n unL = uL*nx+vL*ny\n umL = uL*mx+vL*my\n pL = primL(4)\n aL = sqrt(gamma*pL/rhoL)\n HL = aL*aL/(gamma_m1) + half*(uL*uL+vL*vL)\n! Right state\n rhoR = primR(1)\n uR = primR(2)\n vR = primR(3)\n unR = uR*nx+vR*ny\n umR = uR*mx+vR*my\n pR = primR(4)\n aR = sqrt(gamma*pR/rhoR)\n HR = aR*aR/(gamma_m1) + half*(uR*uR+vR*vR)\n\n!First compute the Roe Averages\n RT = sqrt(rhoR/rhoL)\n rho = RT*rhoL\n u = (uL+RT*uR)/(one+RT)\n v = (vL+RT*vR)/(one+RT)\n H = (HL+RT* HR)/(one+RT)\n a = sqrt( (gamma_m1)*(H-half*(u*u+v*v)) )\n un = u*nx+v*ny\n um = u*mx+v*my\n\n!Wave Strengths\n drho = rhoR - rhoL\n dp = pR - pL\n dun = unR - unL\n dum = umR - umL\n\n LdU(1) = (dp - rho*a*dun )/(two*a*a)\n LdU(2) = rho*dum\n LdU(3) = drho - dp/(a*a)\n LdU(4) = (dp + rho*a*dun )/(two*a*a)\n\n!Wave Speed\n ws(1) = abs(un-a)\n ws(2) = abs(un)\n ws(3) = abs(un)\n ws(4) = abs(un+a)\n\n!Harten's Entropy Fix JCP(1983), 49, pp357-393:\n! only for the nonlinear fields.\n dws(1) = fifth\n if ( ws(1) < dws(1) ) ws(1) = half * ( ws(1)*ws(1)/dws(1)+dws(1) )\n dws(4) = fifth\n if ( ws(4) < dws(4) ) ws(4) = half * ( ws(4)*ws(4)/dws(4)+dws(4) )\n\n!Right Eigenvectors\n Rv(1,1) = one\n Rv(2,1) = u - a*nx\n Rv(3,1) = v - a*ny\n Rv(4,1) = H - un*a\n\n Rv(1,2) = zero\n Rv(2,2) = mx\n Rv(3,2) = my\n Rv(4,2) = um\n\n Rv(1,3) = one\n Rv(2,3) = u\n Rv(3,3) = v\n Rv(4,3) = half*(u*u+v*v)\n\n Rv(1,4) = one\n Rv(2,4) = u + a*nx\n Rv(3,4) = v + a*ny\n Rv(4,4) = H + un*a\n\n!Dissipation Term\n diss = zero\n do i=1,4\n do j=1,4\n diss(i) = diss(i) + ws(j)*LdU(j)*Rv(i,j)\n end do\n end do\n\n!Compute the flux.\n fL(1) = rhoL*unL\n fL(2) = rhoL*unL * uL + pL*nx\n fL(3) = rhoL*unL * vL + pL*ny\n fL(4) = rhoL*unL * HL\n\n fR(1) = rhoR*unR\n fR(2) = rhoR*unR * uR + pR*nx\n fR(3) = rhoR*unR * vR + pR*ny\n fR(4) = rhoR*unR * HR\n\n flux = half * (fL + fR - diss)\n wsn = half*(abs(un) + a) !Normal max wave speed times half\n !return\n end subroutine roe\n", "meta": {"hexsha": "281c0cf5320e2f601327b07e366e0828f7d0b920", "size": 4740, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lib/fluxes_fortran.f90", "max_stars_repo_name": "SangVn/VnCFD_2D_v2", "max_stars_repo_head_hexsha": "1e3dc9679f4adfaa67407f61007872a367319983", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-03-18T00:51:20.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-18T00:51:20.000Z", "max_issues_repo_path": "lib/fluxes_fortran.f90", "max_issues_repo_name": "SangVn/VnCFD_2D_v2", "max_issues_repo_head_hexsha": "1e3dc9679f4adfaa67407f61007872a367319983", "max_issues_repo_licenses": ["MIT"], "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/fluxes_fortran.f90", "max_forks_repo_name": "SangVn/VnCFD_2D_v2", "max_forks_repo_head_hexsha": "1e3dc9679f4adfaa67407f61007872a367319983", "max_forks_repo_licenses": ["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.625, "max_line_length": 115, "alphanum_fraction": 0.4997890295, "num_tokens": 1874, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070158103777, "lm_q2_score": 0.7401743677704878, "lm_q1q2_score": 0.6734898501573776}} {"text": "module mod_scal\n use mod_types\n implicit none\n private\n public scal_a,scal_d\n contains\n subroutine scal_d(lo,hi,dxc,dxf,dyc,dyf,dzc,dzf,alpha,s,dsdt)\n implicit none\n integer , intent(in), dimension(3) :: lo,hi\n real(rp), intent(in), dimension(lo(1)-1:) :: dxc,dxf\n real(rp), intent(in), dimension(lo(2)-1:) :: dyc,dyf\n real(rp), intent(in), dimension(lo(3)-1:) :: dzc,dzf\n real(rp), intent(in) :: alpha\n real(rp), dimension(lo(1)-1:,lo(2)-1:,lo(3)-1:), intent(in) :: s\n real(rp), dimension(lo(1): ,lo(2) :,lo(3): ), intent(inout) :: dsdt\n real(rp) :: dsdxp,dsdxm,dsdyp,dsdym,dsdzp,dsdzm\n integer :: i,j,k\n !\n !$OMP PARALLEL DO DEFAULT(none) &\n !$OMP PRIVATE(i,j,k) &\n !$OMP PRIVATE(dsdxp,dsdxm,dsdyp,dsdym,dsdzp,dsdzm) &\n !$OMP SHARED(lo,hi,dxc,dxf,dyc,dyf,dzc,dzf,alpha,s,dsdt)\n do k=lo(3),hi(3)\n do j=lo(2),hi(2)\n do i=lo(1),hi(1)\n dsdxp = (s(i+1,j,k)-s(i ,j,k))/dxc(i )\n dsdxm = (s(i ,j,k)-s(i-1,j,k))/dxc(i-1)\n dsdyp = (s(i,j+1,k)-s(i,j ,k))/dyc(j )\n dsdym = (s(i,j ,k)-s(i,j-1,k))/dyc(j-1)\n dsdzp = (s(i,j,k+1)-s(i,j,k ))/dzc(k )\n dsdzm = (s(i,j,k )-s(i,j,k-1))/dzc(k-1)\n !\n dsdt(i,j,k) = dsdt(i,j,k) + &\n alpha*(dsdxp-dsdxm)/dxf(i) + &\n alpha*(dsdyp-dsdym)/dyf(j) + &\n alpha*(dsdzp-dsdzm)/dzf(k)\n end do\n end do\n end do\n !$OMP END PARALLEL DO\n end subroutine scal_d\n subroutine scal_a(lo,hi,dxf,dyf,dzf,u,v,w,s,dsdt)\n implicit none\n integer , intent(in), dimension(3) :: lo,hi\n real(rp), intent(in), dimension(lo(1)-1:) :: dxf\n real(rp), intent(in), dimension(lo(2)-1:) :: dyf\n real(rp), intent(in), dimension(lo(3)-1:) :: dzf\n real(rp), dimension(lo(1)-1:,lo(2)-1:,lo(3)-1:), intent(in ) :: u,v,w,s\n real(rp), dimension(lo(1): ,lo(2): ,lo(3): ), intent(inout) :: dsdt\n real(rp) :: usip,usim,vsjp,vsjm,wskp,wskm\n integer :: i,j,k\n !\n !$OMP PARALLEL DO DEFAULT(none) &\n !$OMP PRIVATE(i,j,k) &\n !$OMP PRIVATE(usip,usim,vsjp,vsjm,wskp,wskm) &\n !$OMP SHARED(lo,hi,dxf,dyf,dzf,u,v,w,s,dsdt)\n do k=lo(3),hi(3)\n do j=lo(2),hi(2)\n do i=lo(1),hi(1)\n !\n usim = 0.5_rp*( s(i-1,j,k)+s(i,j,k) )*u(i-1,j,k)\n usip = 0.5_rp*( s(i+1,j,k)+s(i,j,k) )*u(i ,j,k)\n vsjm = 0.5_rp*( s(i,j-1,k)+s(i,j,k) )*v(i,j-1,k)\n vsjp = 0.5_rp*( s(i,j+1,k)+s(i,j,k) )*v(i,j ,k)\n wskm = 0.5_rp*( s(i,j,k-1)+s(i,j,k) )*w(i,j,k-1)\n wskp = 0.5_rp*( s(i,j,k+1)+s(i,j,k) )*w(i,j,k )\n dsdt(i,j,k) = dsdt(i,j,k) + &\n ( -usip + usim )/dxf(i) + &\n ( -vsjp + vsjm )/dyf(j) + &\n ( -wskp + wskm )/dzf(k)\n end do\n end do\n end do\n !$OMP END PARALLEL DO\n end subroutine scal_a\nend module mod_scal\n", "meta": {"hexsha": "3bf18dad075361020493add02a749e25846150d3", "size": 2922, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/scal.f90", "max_stars_repo_name": "p-costa/SNaC", "max_stars_repo_head_hexsha": "54afde2ef2507aafeeb9652e1de8af26a245010b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2020-06-23T16:44:03.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-13T22:23:53.000Z", "max_issues_repo_path": "src/scal.f90", "max_issues_repo_name": "p-costa/SNaC", "max_issues_repo_head_hexsha": "54afde2ef2507aafeeb9652e1de8af26a245010b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 29, "max_issues_repo_issues_event_min_datetime": "2020-10-13T10:54:05.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-05T22:34:05.000Z", "max_forks_repo_path": "src/scal.f90", "max_forks_repo_name": "p-costa/SNaC", "max_forks_repo_head_hexsha": "54afde2ef2507aafeeb9652e1de8af26a245010b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-09-18T09:42:51.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-16T06:13:15.000Z", "avg_line_length": 37.9480519481, "max_line_length": 77, "alphanum_fraction": 0.4934976044, "num_tokens": 1178, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069987088003, "lm_q2_score": 0.7401743735019595, "lm_q1q2_score": 0.6734898427143345}} {"text": "submodule (maptran) enu\n\nimplicit none (type, external)\n\ncontains\n\nmodule procedure geodetic2enu\n!! geodetic2enu convert from geodetic to ENU coordinates\n!!\n!! ## Inputs\n!!\n!! * lat,lon, alt: ellipsoid geodetic coordinates of point under test (degrees, degrees, meters)\n!! * lat0, lon0, alt0: ellipsoid geodetic coordinates of observer/reference (degrees, degrees, meters)\n!! * spheroid: Ellipsoid parameter struct\n!! * angleUnit: string for angular units. Default 'd': degrees\n!!\n!! ## outputs\n!!\n!! * e,n,u: East, North, Up coordinates of test points (meters)\n\nreal(wp) x1,y1,z1,x2,y2,z2, dx,dy,dz\n\n\ncall geodetic2ecef(lat,lon,alt,x1,y1,z1,spheroid,deg)\ncall geodetic2ecef(lat0,lon0,alt0,x2,y2,z2,spheroid,deg)\n\ndx = x1-x2\ndy = y1-y2\ndz = z1-z2\n\ncall ecef2enuv(dx, dy, dz, lat0, lon0, east, north, up, deg)\n\nend procedure geodetic2enu\n\n\nmodule procedure enu2geodetic\n! enu2geodetic convert from ENU to geodetic coordinates\n!\n! Inputs\n! ------\n! East, North, Up: coordinates of point(s) (meters)\n! lat0, lon0, alt0: ellipsoid geodetic coordinates of observer/reference (degrees, degrees, meters)\n! spheroid: Ellipsoid parameter struct\n! deg: .true. degrees\n!\n! outputs\n! -------\n! lat,lon,alt: geodetic coordinates of test points (degrees,degrees,meters)\n\nreal(wp) :: x,y,z\n\ncall enu2ecef(east, north, up, lat0, lon0, alt0, x, y, z, spheroid, deg)\ncall ecef2geodetic(x, y, z, lat, lon, alt, spheroid,deg)\n\nend procedure enu2geodetic\n\n\nmodule procedure aer2enu\n! aer2enu convert azimuth, elevation, range to ENU coordinates\n!\n! Inputs\n! ------\n! az, el, slantrange: look angles and distance to point under test (degrees, degrees, meters)\n! az: azimuth clockwise from local north\n! el: elevation angle above local horizon\n! angleUnit: string for angular units. Default 'd': degrees\n!\n! Outputs\n! -------\n! e,n,u: East, North, Up coordinates of test points (meters)\n\nreal(wp) :: r, a, e\nlogical :: d\n\nd=.true.\nif (present(deg)) d = deg\n\na = az\ne = el\nif (d) then\n a = radians(a)\n e = radians(e)\nendif\n\n!> Calculation of AER2ENU\nup = slantRange * sin(e)\nr = slantRange * cos(e)\neast = r * sin(a)\nnorth = r * cos(a)\n\nend procedure aer2enu\n\n\nmodule procedure enu2aer\n!! enu2aer convert ENU to azimuth, elevation, slant range\n!!\n!! ## Inputs\n!!\n!! * e,n,u: East, North, Up coordinates of test points (meters)\n!! * deg: .true. degrees\n!!\n!! ## outputs\n!!\n!! * az, el, slantrange: look angles and distance to point under test (degrees, degrees, meters)\n!! * az: azimuth clockwise from local north\n!! * el: elevation angle above local horizon\n\nreal(wp) :: r, e, n, u\nlogical :: d\n\nreal(wp), parameter :: tolerance = 1e-3_wp !< 1mm precision\n\n!> singularity fixes\ne = east\nif (abs(e) < tolerance) e = 0\n\nn = north\nif (abs(n) < tolerance) n = 0\n\nu = up\nif (abs(u) < tolerance) u = 0\n\nr = hypot(e, n)\nslantRange = hypot(r, u)\n\n!> radians\nelev = atan2(u, r)\naz = modulo(atan2(e, n), 2 * pi)\n\nd=.true.\nif (present(deg)) d = deg\n\nif (d) then\n elev = degrees(elev)\n az = degrees(az)\nendif\n\nend procedure enu2aer\n\nend submodule enu\n", "meta": {"hexsha": "0c184dd6456ae145edc70d3be536f815b7f0f8eb", "size": 3042, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/enu.f90", "max_stars_repo_name": "geospace-code/maptran3d", "max_stars_repo_head_hexsha": "c41e12171ac5a87ba6ab497a3d8b1cf2cddd2a58", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-07-24T23:22:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-10T09:36:56.000Z", "max_issues_repo_path": "src/enu.f90", "max_issues_repo_name": "geospace-code/maptran3d", "max_issues_repo_head_hexsha": "c41e12171ac5a87ba6ab497a3d8b1cf2cddd2a58", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/enu.f90", "max_forks_repo_name": "geospace-code/maptran3d", "max_forks_repo_head_hexsha": "c41e12171ac5a87ba6ab497a3d8b1cf2cddd2a58", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-01-31T08:55:13.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-31T08:55:13.000Z", "avg_line_length": 21.5744680851, "max_line_length": 103, "alphanum_fraction": 0.6827744905, "num_tokens": 1006, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6734898413256577}} {"text": "SUBROUTINE FOUR1(DATA,NN,ISIGN)\n!\n! Replaces data(1:2nn) by its discrete Fourier transform, if isign is 1; or\n! with nn times the inverse discrete tranform if isign is -1. data is a complex\n! array of length nn or a real array of length 2*nn. nn must be an integer\n! power of 2.\n!\n REAL*8 WR,WI,WPR,WPI,WTEMP,THETA\n DIMENSION DATA(*)\n N=2*NN\n J=1\n DO 11 I=1,N,2\n IF(J.GT.I)THEN\n TEMPR=DATA(J)\n TEMPI=DATA(J+1)\n DATA(J)=DATA(I)\n DATA(J+1)=DATA(I+1)\n DATA(I)=TEMPR\n DATA(I+1)=TEMPI\n ENDIF\n M=N/2\n1 IF ((M.GE.2).AND.(J.GT.M)) THEN\n J=J-M\n M=M/2\n GO TO 1\n ENDIF\n J=J+M\n11 CONTINUE\n MMAX=2\n2 IF (N.GT.MMAX) THEN\n ISTEP=2*MMAX\n THETA=6.28318530717959D0/(ISIGN*MMAX)\n WPR=-2.D0*DSIN(0.5D0*THETA)**2\n WPI=DSIN(THETA)\n WR=1.D0\n WI=0.D0\n DO 13 M=1,MMAX,2\n DO 12 I=M,N,ISTEP\n J=I+MMAX\n TEMPR=SNGL(WR)*DATA(J)-SNGL(WI)*DATA(J+1)\n TEMPI=SNGL(WR)*DATA(J+1)+SNGL(WI)*DATA(J)\n DATA(J)=DATA(I)-TEMPR\n DATA(J+1)=DATA(I+1)-TEMPI\n DATA(I)=DATA(I)+TEMPR\n DATA(I+1)=DATA(I+1)+TEMPI\n12 CONTINUE\n WTEMP=WR\n WR=WR*WPR-WI*WPI+WR\n WI=WI*WPR+WTEMP*WPI+WI\n13 CONTINUE\n MMAX=ISTEP\n GO TO 2\n ENDIF\n RETURN\n END SUBROUTINE FOUR1\n", "meta": {"hexsha": "ca5b315ee6f923300ee230198e6d438f8c7597d8", "size": 1345, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fft/FOUR1.f90", "max_stars_repo_name": "apengsigkarup/OceanWave3D", "max_stars_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 46, "max_stars_repo_stars_event_min_datetime": "2016-01-08T12:36:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T06:56:45.000Z", "max_issues_repo_path": "src/fft/FOUR1.f90", "max_issues_repo_name": "apengsigkarup/OceanWave3D", "max_issues_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-10-10T19:45:08.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-07T07:37:11.000Z", "max_forks_repo_path": "src/fft/FOUR1.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": 24.0178571429, "max_line_length": 80, "alphanum_fraction": 0.5501858736, "num_tokens": 547, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069987088003, "lm_q2_score": 0.7401743677704878, "lm_q1q2_score": 0.6734898374992284}} {"text": "PROGRAM Roots\n\n COMPLEX :: root\n INTEGER :: i, n\n REAL :: angle, pi\n\n pi = 4.0 * ATAN(1.0)\n DO n = 2, 7\n angle = 0.0\n WRITE(*,\"(I1,A)\", ADVANCE=\"NO\") n,\": \"\n DO i = 1, n\n root = CMPLX(COS(angle), SIN(angle))\n WRITE(*,\"(SP,2F7.4,A)\", ADVANCE=\"NO\") root, \"j \"\n angle = angle + (2.0*pi / REAL(n))\n END DO\n WRITE(*,*)\n END DO\n\nEND PROGRAM Roots\n", "meta": {"hexsha": "5aaf349662e7d5042738ae5be795dd44c83fd9a8", "size": 378, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Roots-of-unity/Fortran/roots-of-unity-1.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Roots-of-unity/Fortran/roots-of-unity-1.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Roots-of-unity/Fortran/roots-of-unity-1.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 18.9, "max_line_length": 55, "alphanum_fraction": 0.4973544974, "num_tokens": 152, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070035949656, "lm_q2_score": 0.7401743563075447, "lm_q1q2_score": 0.6734898306856304}} {"text": "#include \"eiscor.h\"\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! z_rot3_unitvec3gen\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! This routine computes the generators for a complex rotation represented\n! by 3 real numbers: the real and imaginary parts of a complex cosine,\n! CR and CI, and a strictly real sine, S. The CR, CI and S are \n! constructed to be parallel with the vector [AR+iAI,B]^T, where AR, \n! AI and B are real and i = sqrt(-1).\n!\n! The vector [AR+iAI,B]^T is assumed to be nearly unit, that is \n!\n! abs(AR^2 + AI^2 + B^2 - 1) = O(eps).\n! \n! In this case it is possible to compute the norm without a squareroot using a\n! single newton iteration.\n! \n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! INPUT VARIABLES:\n!\n! AR, AI REAL(8) \n! real and imaginary part of the first component \n! of the complex vector [AR+iAI,B]^T\n!\n! B REAL(8) \n! the second component \n! of the complex vector [AR+iAI,B]^T\n!\n! OUTPUT VARIABLES:\n!\n! CR, CI REAL(8)\n! on exit contains the generators for the cosine\n! component of the Givens rotation\n!\n! S REAL(8)\n! on exit contains the generator for the sine\n! component of the Givens rotation\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine z_rot3_unitvec3gen(AR,AI,B,CR,CI,S)\n\n implicit none\n \n ! input variables\n real(8), intent(in) :: AR, AI, B\n real(8), intent(inout) :: CR, CI, S\n \n ! compute variables\n real(8) :: X\n\n ! compute difference from unity and approximate 1/sqrt(x)\n X = 5d-1*(3d0 - (AR*AR + AI*AI + B*B))\n \n ! construct rotation\n CR = AR*X\n CI = AI*X\n S = B*X\n \nend subroutine z_rot3_unitvec3gen\n", "meta": {"hexsha": "121bf83be6969e12b74ff465b03eb7863e5645b6", "size": 1938, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/AMVW/src/complex_double/z_rot3_unitvec3gen.f90", "max_stars_repo_name": "trcameron/FPML", "max_stars_repo_head_hexsha": "f6aacfcd702f7ce74a45ffaf281e9586dceb1b7e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tests/AMVW/src/complex_double/z_rot3_unitvec3gen.f90", "max_issues_repo_name": "trcameron/FPML", "max_issues_repo_head_hexsha": "f6aacfcd702f7ce74a45ffaf281e9586dceb1b7e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/AMVW/src/complex_double/z_rot3_unitvec3gen.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": 30.28125, "max_line_length": 80, "alphanum_fraction": 0.4912280702, "num_tokens": 509, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069987088003, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6734898270690161}} {"text": " PROGRAM xftest\r\nC driver for routine ftest\r\n INTEGER NPTS,NVAL,MPTS\r\n REAL EPS\r\n PARAMETER(NPTS=1000,MPTS=500,EPS=0.01,NVAL=10)\r\n INTEGER i,idum,j\r\n REAL f,factor,gasdev,prob,var\r\n REAL data1(NPTS),data2(MPTS),data3(MPTS)\r\nC generate two Gaussian distributions with\r\nC different variances\r\n idum=-13\r\n do 11 j=1,NPTS\r\n data1(j)=gasdev(idum)\r\n11 continue\r\n do 12 j=1,MPTS\r\n data2(j)=gasdev(idum)\r\n12 continue\r\n write(*,'(1x,t5,a,f5.2)') 'Variance 1 = ',1.0\r\n write(*,'(1x,t5,a,t21,a,t30,a)')\r\n * 'Variance 2','Ratio','Probability'\r\n do 14 i=1,NVAL+1\r\n var=1.0+(i-1)*EPS\r\n factor=sqrt(var)\r\n do 13 j=1,MPTS\r\n data3(j)=factor*data2(j)\r\n13 continue\r\n call ftest(data1,NPTS,data3,MPTS,f,prob)\r\n write(*,'(1x,f11.4,2x,2f12.4)') var,f,prob\r\n14 continue\r\n END\r\n", "meta": {"hexsha": "f9f9b7e53918bd8ef95138bda3064286f146e94f", "size": 916, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xftest.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xftest.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xftest.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.5483870968, "max_line_length": 53, "alphanum_fraction": 0.5556768559, "num_tokens": 318, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069962657176, "lm_q2_score": 0.7401743563075447, "lm_q1q2_score": 0.673489825260709}} {"text": " real function psolR(solD,v,w,x,y)\nc\nc + + + PURPOSE + + +\nc Computes potential solar radiation on a sloping surface, in cal/cm2/day\nc\nc Called from sunmap.\nc Author(s): \nc Reference: Swift, 1976 \"Algorithm for solar radiation on Mountain slopes\"\nc\nc Date recoded: 11/07/2006.\nc Recoded by: S. Dun\nc\nc + + + KEYWORDS + + +\nc\nc + + + ARGUMENT DECLARATIONS + + +\n real solD,v,w,x,y\nc\nc + + + ARGUMENT DEFINITIONS + + +\nc solD - declination of sun\nc v - time offset in hour angle between actual annd equivalent slope\nc w - lattitude of eqivalent slope\nc\nc + + + PARAMETERS + + +\nc\nc + + + COMMON BLOCKS + + +\nc\nc\nc + + + LOCAL DEFINITIONS + + +\nc\nc + + + FUNCTION DECLARATIONS + + +\n\nc + + + END SPECIFICATIONS + + +\nc\n psolR = (sin(solD) * sin(w) * (x - y) *12.0 / 3.141593)\n 1 + (cos(solD) * cos(w) * (sin(x + v) - sin(y + v))\n 2 * 12. / 3.141593)\nc\n return\n end\n", "meta": {"hexsha": "016ddc8ba6de85eca411269601f4ea3c110ab986", "size": 973, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/wepp2012-src/psolr.for", "max_stars_repo_name": "jarad/dep", "max_stars_repo_head_hexsha": "fe73982f4c70039e1a31b9e8e2d9aac31502f803", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-11-26T17:49:19.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-26T17:49:19.000Z", "max_issues_repo_path": "src/wepp2012-src/psolr.for", "max_issues_repo_name": "jarad/dep", "max_issues_repo_head_hexsha": "fe73982f4c70039e1a31b9e8e2d9aac31502f803", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 54, "max_issues_repo_issues_event_min_datetime": "2018-12-12T18:02:31.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T19:14:25.000Z", "max_forks_repo_path": "src/wepp2012-src/psolr.for", "max_forks_repo_name": "akrherz/idep", "max_forks_repo_head_hexsha": "7189a26fbcec3d8c3cc7d7015107b8fb6c5f6a45", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-03-02T22:59:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-09T15:49:00.000Z", "avg_line_length": 24.325, "max_line_length": 79, "alphanum_fraction": 0.5549845838, "num_tokens": 337, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107878954105, "lm_q2_score": 0.7185943925708561, "lm_q1q2_score": 0.6734744168385559}} {"text": "!\n! CalculiX - A 3-dimensional finite element program\n! Copyright (C) 1998-2018 Guido Dhondt\n! \n! This program is free software; you can redistribute it and/or\n! modify it under the terms of the GNU General Public License as\n! published by the Free Software Foundation(version 2);\n! \n! \n! This program is distributed in the hope that it will be useful,\n! but WITHOUT ANY WARRANTY; without even the implied warranty of \n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \n! GNU General Public License for more details.\n! \n! You should have received a copy of the GNU General Public License\n! along with this program; if not, write to the Free Software\n! Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n!\n! This subroutine enables to calculate the dynamic viscosity of air\n! using Sutherland's formula for gas\n! dvi=dvi0*dsqrt(T/273.d0)*(1.d0+113/273.15)/(1+113/T)\n!\n! author: Yannick Muller\n!\n subroutine dynamic_viscosity (kgas,T,dvi)\n!\n implicit none\n!\n integer kgas\n!\n real*8 T,dvi\n kgas=kgas\n!\n dvi=0.00001711d0*dsqrt(T/273.15d0)*(1d0+113d0/273.15d0)\n & /(1.d0+113.d0/T)\n!\n return\n!\n end\n!\n", "meta": {"hexsha": "25d969595fe9016a0a58909d886b8d3606c2e50b", "size": 1243, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ccx_prool/CalculiX/ccx_2.15/src/dynamic_viscosity.f", "max_stars_repo_name": "alleindrach/calculix-desktop", "max_stars_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ccx_prool/CalculiX/ccx_2.15/src/dynamic_viscosity.f", "max_issues_repo_name": "alleindrach/calculix-desktop", "max_issues_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ccx_prool/CalculiX/ccx_2.15/src/dynamic_viscosity.f", "max_forks_repo_name": "alleindrach/calculix-desktop", "max_forks_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.3170731707, "max_line_length": 71, "alphanum_fraction": 0.6613032985, "num_tokens": 352, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107843878721, "lm_q2_score": 0.718594386544335, "lm_q1q2_score": 0.673474408669938}} {"text": "program matrix_simple\n implicit none\n\n! define a new type mat_obj\n type mat_obj\n integer :: N,M\n real, dimension(:,:), allocatable :: A\n end type mat_obj\n\n! create a new object mat of tpye mat_obj\n type(mat_obj) :: mat\n\n print*, 'Enter matrix dimension N,M: '\n read*, mat%N, mat%M\n allocate(mat%A(mat%N,mat%M))\n!initialize mat with random numbers\n call random_number(mat%A)\n! The matrix can be big so we \n! write 4 elements only mat%A(1,1), mat%A(mat%N,1)\n! mat%A(1,mat%M), mat(mat%N, mat%M)\n print*, mat%A( (/1,mat%N /), (/1, mat%M /) )\n deallocate( mat%A )\nend program matrix_simple\n", "meta": {"hexsha": "1ac6ba827de966af6254069be6b5036f4c4db7fc", "size": 620, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/derivedTypes/matrix_simple.f90", "max_stars_repo_name": "annefou/Fortran", "max_stars_repo_head_hexsha": "9d3d81de1ae32723e64eb3d07195867293a82c5e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 32, "max_stars_repo_stars_event_min_datetime": "2016-04-08T19:04:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-13T15:44:37.000Z", "max_issues_repo_path": "src/derivedTypes/matrix_simple.f90", "max_issues_repo_name": "inandi2/Fortran-1", "max_issues_repo_head_hexsha": "9d3d81de1ae32723e64eb3d07195867293a82c5e", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/derivedTypes/matrix_simple.f90", "max_forks_repo_name": "inandi2/Fortran-1", "max_forks_repo_head_hexsha": "9d3d81de1ae32723e64eb3d07195867293a82c5e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2016-04-08T19:05:49.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-08T19:57:51.000Z", "avg_line_length": 25.8333333333, "max_line_length": 57, "alphanum_fraction": 0.6419354839, "num_tokens": 187, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916240341031, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6734393324699086}} {"text": "\nmodule problem\n\n ! Save the value of k and define the true solution.\n\n integer :: k\n save\n\ncontains\n\n real(kind=8) function u_true(x,t)\n ! true solution\n implicit none\n real(kind=8), intent(in) :: x, t\n u_true = exp(-k**2 * t) * sin(k*x)\n end function u_true\n\n\nend module problem\n", "meta": {"hexsha": "c3985c815e260819f457aa2145ca6cf12a8a6f5e", "size": 324, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/homeworks/project/part2/problem.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/homeworks/project/part2/problem.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/homeworks/project/part2/problem.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": 16.2, "max_line_length": 55, "alphanum_fraction": 0.5864197531, "num_tokens": 89, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8633916099737807, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.673439321502957}} {"text": "program euler_052\n integer, parameter :: int64 = selected_int_kind(10)\n integer(int64) :: i\n \n i = 100000\n do \n if (all_digits(i)) then\n print *,i\n stop\n end if\n i = i + 1\n end do !- i\n \ncontains\n logical function all_digits(n) result (bool)\n integer(int64), intent(in) :: n\n character(len=6) :: s1,s2\n integer(int64) :: i,j\n \n write(s1,'(i6)') n\n call sort(s1)\n \n do i=1,6\n write(s2,'(i6)') i*n\n call sort(s2)\n \n do j=1,len(s1)\n if (s1(j:j) /= s2(j:j)) then\n bool = .false.\n return\n end if\n end do !- j\n end do\n \n bool = .true.\n return\n end function all_digits\n \n pure subroutine sort(s)\n character(len=*), intent(inout) :: s\n character(len=1) :: t\n integer :: i, j\n \n do i=2,len(s)\n j = i-1\n t(1:1) = s(i:i)\n do while ( j>= 1 .and. s(j:j)>t(1:1))\n s(j+1:j+1) = s(j:j)\n j = j - 1\n end do !- j\n s(j+1:j+1) = t(1:1)\n end do !- i\n end subroutine sort\n \nend program euler_052\n", "meta": {"hexsha": "6d6cf61ff5f2d06cd89314ee0dc84f0bf91adc42", "size": 1172, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "euler_051.f90", "max_stars_repo_name": "kylekanos/ProjectEuler", "max_stars_repo_head_hexsha": "bfdbda0a9a83af45b92c47439f657d11df785527", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-05-13T03:36:23.000Z", "max_stars_repo_stars_event_max_datetime": "2016-05-13T03:36:23.000Z", "max_issues_repo_path": "euler_051.f90", "max_issues_repo_name": "kylekanos/ProjectEuler", "max_issues_repo_head_hexsha": "bfdbda0a9a83af45b92c47439f657d11df785527", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "euler_051.f90", "max_forks_repo_name": "kylekanos/ProjectEuler", "max_forks_repo_head_hexsha": "bfdbda0a9a83af45b92c47439f657d11df785527", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.9285714286, "max_line_length": 54, "alphanum_fraction": 0.4419795222, "num_tokens": 374, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633915959134572, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6734393149515593}} {"text": " SUBROUTINE MB01VD( TRANA, TRANB, MA, NA, MB, NB, ALPHA, BETA,\r\n $ A, LDA, B, LDB, C, LDC, MC, NC, INFO )\r\nC\r\nC SLICOT RELEASE 5.5.\r\nC\r\nC Copyright (c) 2002-2012 NICONET e.V.\r\nC\r\nC PURPOSE\r\nC\r\nC To perform the following matrix operation\r\nC\r\nC C = alpha*kron( op(A), op(B) ) + beta*C,\r\nC\r\nC where alpha and beta are real scalars, op(M) is either matrix M or\r\nC its transpose, M', and kron( X, Y ) denotes the Kronecker product\r\nC of the matrices X and Y.\r\nC\r\nC ARGUMENTS\r\nC\r\nC Mode Parameters\r\nC\r\nC TRANA CHARACTER*1\r\nC Specifies the form of op(A) to be used as follows:\r\nC = 'N': op(A) = A;\r\nC = 'T': op(A) = A';\r\nC = 'C': op(A) = A'.\r\nC\r\nC TRANB CHARACTER*1\r\nC Specifies the form of op(B) to be used as follows:\r\nC = 'N': op(B) = B;\r\nC = 'T': op(B) = B';\r\nC = 'C': op(B) = B'.\r\nC\r\nC Input/Output Parameters\r\nC\r\nC MA (input) INTEGER\r\nC The number of rows of the matrix op(A). MA >= 0.\r\nC\r\nC NA (input) INTEGER\r\nC The number of columns of the matrix op(A). NA >= 0.\r\nC\r\nC MB (input) INTEGER\r\nC The number of rows of the matrix op(B). MB >= 0.\r\nC\r\nC NB (input) INTEGER\r\nC The number of columns of the matrix op(B). NB >= 0.\r\nC\r\nC ALPHA (input) DOUBLE PRECISION\r\nC The scalar alpha. When alpha is zero then A and B need not\r\nC be set before entry.\r\nC\r\nC BETA (input) DOUBLE PRECISION\r\nC The scalar beta. When beta is zero then C need not be\r\nC set before entry.\r\nC\r\nC A (input) DOUBLE PRECISION array, dimension (LDA,ka),\r\nC where ka is NA when TRANA = 'N', and is MA otherwise.\r\nC If TRANA = 'N', the leading MA-by-NA part of this array\r\nC must contain the matrix A; otherwise, the leading NA-by-MA\r\nC part of this array must contain the matrix A.\r\nC\r\nC LDA INTEGER\r\nC The leading dimension of the array A.\r\nC LDA >= max(1,MA), if TRANA = 'N';\r\nC LDA >= max(1,NA), if TRANA = 'T' or 'C'.\r\nC\r\nC B (input) DOUBLE PRECISION array, dimension (LDB,kb)\r\nC where kb is NB when TRANB = 'N', and is MB otherwise.\r\nC If TRANB = 'N', the leading MB-by-NB part of this array\r\nC must contain the matrix B; otherwise, the leading NB-by-MB\r\nC part of this array must contain the matrix B.\r\nC\r\nC LDB INTEGER\r\nC The leading dimension of the array B.\r\nC LDB >= max(1,MB), if TRANB = 'N';\r\nC LDB >= max(1,NB), if TRANB = 'T' or 'C'.\r\nC\r\nC C (input/output) DOUBLE PRECISION array, dimension (LDC,NC)\r\nC On entry, if beta is nonzero, the leading MC-by-NC part of\r\nC this array must contain the given matric C, where\r\nC MC = MA*MB and NC = NA*NB.\r\nC On exit, the leading MC-by-NC part of this array contains\r\nC the computed matrix expression\r\nC C = alpha*kron( op(A), op(B) ) + beta*C.\r\nC\r\nC LDC INTEGER\r\nC The leading dimension of the array C.\r\nC LDC >= max(1,MC).\r\nC\r\nC MC (output) INTEGER\r\nC The number of rows of the matrix C. MC = MA*MB.\r\nC\r\nC NC (output) INTEGER\r\nC The number of columns of the matrix C. NC = NA*NB.\r\nC\r\nC Error Indicator\r\nC\r\nC INFO INTEGER\r\nC = 0: successful exit;\r\nC < 0: if INFO = -i, the i-th argument had an illegal\r\nC value.\r\nC\r\nC METHOD\r\nC\r\nC The Kronecker product of the matrices op(A) and op(B) is computed\r\nC column by column.\r\nC\r\nC FURTHER COMMENTS\r\nC\r\nC The multiplications by zero elements in A are avoided, if the\r\nC matrix A is considered to be sparse, i.e., if\r\nC (number of zeros in A)/(MA*NA) >= SPARST = 0.8. The code makes\r\nC NB+1 passes through the matrix A, and MA*NA passes through the\r\nC matrix B. If LDA and/or LDB are very large, and op(A) = A' and/or\r\nC op(B) = B', it could be more efficient to transpose A and/or B\r\nC before calling this routine, and use the 'N' values for TRANA\r\nC and/or TRANB.\r\nC\r\nC CONTRIBUTOR\r\nC\r\nC V. Sima, Katholieke Univ. Leuven, Belgium, February 2000.\r\nC\r\nC REVISIONS\r\nC\r\nC -\r\nC\r\nC KEYWORDS\r\nC\r\nC Elementary matrix operations, matrix operations.\r\nC\r\nC ******************************************************************\r\nC\r\nC .. Parameters ..\r\n DOUBLE PRECISION ZERO, ONE\r\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )\r\n DOUBLE PRECISION SPARST\r\n PARAMETER ( SPARST = 0.8D0 )\r\nC .. Scalar Arguments ..\r\n CHARACTER TRANA, TRANB\r\n INTEGER INFO, LDA, LDB, LDC, MA, MB, MC, NA, NB, NC\r\n DOUBLE PRECISION ALPHA, BETA\r\nC .. Array Arguments ..\r\n DOUBLE PRECISION A(LDA,*), B(LDB,*), C(LDC,*)\r\nC .. Local Scalars ..\r\n LOGICAL SPARSE, TRANSA, TRANSB\r\n INTEGER I, IC, J, JC, K, L, LC, NZ\r\n DOUBLE PRECISION AIJ\r\nC .. Local Arrays ..\r\n DOUBLE PRECISION DUM(1)\r\nC .. External Functions ..\r\n LOGICAL LSAME\r\n EXTERNAL LSAME\r\nC .. External Subroutines ..\r\n EXTERNAL DCOPY, DLASET, DSCAL, XERBLA\r\nC .. Intrinsic Functions ..\r\n INTRINSIC DBLE, MAX\r\nC\r\nC .. Executable Statements ..\r\nC\r\nC Test the input scalar arguments.\r\nC\r\n TRANSA = LSAME( TRANA, 'T' ) .OR. LSAME( TRANA, 'C' )\r\n TRANSB = LSAME( TRANB, 'T' ) .OR. LSAME( TRANB, 'C' )\r\n MC = MA*MB\r\n INFO = 0\r\n IF( .NOT.( TRANSA .OR. LSAME( TRANA, 'N' ) ) ) THEN\r\n INFO = -1\r\n ELSE IF( .NOT.( TRANSB .OR. LSAME( TRANB, 'N' ) ) ) THEN\r\n INFO = -2\r\n ELSE IF( MA.LT.0 ) THEN\r\n INFO = -3\r\n ELSE IF( NA.LT.0 ) THEN\r\n INFO = -4\r\n ELSE IF( MB.LT.0 ) THEN\r\n INFO = -5\r\n ELSE IF( NB.LT.0 ) THEN\r\n INFO = -6\r\n ELSE IF( ( TRANSA .AND. LDA.LT.NA ) .OR. LDA.LT.1 .OR.\r\n $ ( .NOT.TRANSA .AND. LDA.LT.MA ) ) THEN\r\n INFO = -10\r\n ELSE IF( ( TRANSB .AND. LDB.LT.NB ) .OR. LDB.LT.1 .OR.\r\n $ ( .NOT.TRANSB .AND. LDB.LT.MB ) ) THEN\r\n INFO = -12\r\n ELSE IF( LDC.LT.MAX( 1, MC ) ) THEN\r\n INFO = -14\r\n END IF\r\nC\r\n IF ( INFO.NE.0 ) THEN\r\nC\r\nC Error return.\r\nC\r\n CALL XERBLA( 'MB01VD', -INFO )\r\n RETURN\r\n END IF\r\nC\r\nC Quick return, if possible.\r\nC\r\n NC = NA*NB\r\n IF ( MC.EQ.0 .OR. NC.EQ.0 )\r\n $ RETURN\r\nC\r\n IF ( ALPHA.EQ.ZERO ) THEN\r\n IF ( BETA.EQ.ZERO ) THEN\r\n CALL DLASET( 'Full', MC, NC, ZERO, ZERO, C, LDC )\r\n ELSE IF ( BETA.NE.ONE ) THEN\r\nC\r\n DO 10 J = 1, NC\r\n CALL DSCAL( MC, BETA, C(1,J), 1 )\r\n 10 CONTINUE\r\nC\r\n END IF\r\n RETURN\r\n END IF\r\nC\r\n DUM(1) = ZERO\r\n JC = 1\r\n NZ = 0\r\nC\r\nC Compute the Kronecker product of the matrices op(A) and op(B),\r\nC C = alpha*kron( op(A), op(B) ) + beta*C.\r\nC First, check if A is sparse. Here, A is considered as being sparse\r\nC if (number of zeros in A)/(MA*NA) >= SPARST.\r\nC\r\n DO 30 J = 1, NA\r\nC\r\n DO 20 I = 1, MA\r\n IF ( TRANSA ) THEN\r\n IF ( A(J,I).EQ.ZERO )\r\n $ NZ = NZ + 1\r\n ELSE\r\n IF ( A(I,J).EQ.ZERO )\r\n $ NZ = NZ + 1\r\n END IF\r\n 20 CONTINUE\r\nC\r\n 30 CONTINUE\r\nC\r\n SPARSE = DBLE( NZ )/DBLE( MA*NA ).GE.SPARST\r\nC\r\n IF ( .NOT.TRANSA .AND. .NOT.TRANSB ) THEN\r\nC\r\nC Case op(A) = A and op(B) = B.\r\nC\r\n IF ( BETA.EQ.ZERO ) THEN\r\n IF ( ALPHA.EQ.ONE ) THEN\r\n IF ( SPARSE ) THEN\r\nC\r\nC Case beta = 0, alpha = 1, A sparse.\r\nC\r\n DO 80 J = 1, NA\r\nC\r\n DO 70 K = 1, NB\r\n IC = 1\r\nC\r\n DO 60 I = 1, MA\r\n AIJ = A(I,J)\r\n IF ( AIJ.EQ.ZERO ) THEN\r\n CALL DCOPY( MB, DUM(1), 0, C(IC,JC), 1 )\r\n ELSE IF ( AIJ.EQ.ONE ) THEN\r\n CALL DCOPY( MB, B(1,K), 1, C(IC,JC), 1 )\r\n ELSE\r\n LC = IC\r\nC\r\n DO 50 L = 1, MB\r\n C(LC,JC) = AIJ*B(L,K)\r\n LC = LC + 1\r\n 50 CONTINUE\r\nC\r\n END IF\r\n IC = IC + MB\r\n 60 CONTINUE\r\nC\r\n JC = JC + 1\r\n 70 CONTINUE\r\nC\r\n 80 CONTINUE\r\nC\r\n ELSE\r\nC\r\nC Case beta = 0, alpha = 1, A not sparse.\r\nC\r\n DO 120 J = 1, NA\r\nC\r\n DO 110 K = 1, NB\r\n IC = 1\r\nC\r\n DO 100 I = 1, MA\r\n AIJ = A(I,J)\r\n LC = IC\r\nC\r\n DO 90 L = 1, MB\r\n C(LC,JC) = AIJ*B(L,K)\r\n LC = LC + 1\r\n 90 CONTINUE\r\nC\r\n IC = IC + MB\r\n 100 CONTINUE\r\nC\r\n JC = JC + 1\r\n 110 CONTINUE\r\nC\r\n 120 CONTINUE\r\nC\r\n END IF\r\n ELSE\r\n IF ( SPARSE ) THEN\r\nC\r\nC Case beta = 0, alpha <> 1, A sparse.\r\nC\r\n DO 160 J = 1, NA\r\nC\r\n DO 150 K = 1, NB\r\n IC = 1\r\nC\r\n DO 140 I = 1, MA\r\n AIJ = ALPHA*A(I,J)\r\n IF ( AIJ.EQ.ZERO ) THEN\r\n CALL DCOPY( MB, DUM(1), 0, C(IC,JC), 1 )\r\n ELSE\r\n LC = IC\r\nC\r\n DO 130 L = 1, MB\r\n C(LC,JC) = AIJ*B(L,K)\r\n LC = LC + 1\r\n 130 CONTINUE\r\nC\r\n END IF\r\n IC = IC + MB\r\n 140 CONTINUE\r\nC\r\n JC = JC + 1\r\n 150 CONTINUE\r\nC\r\n 160 CONTINUE\r\nC\r\n ELSE\r\nC\r\nC Case beta = 0, alpha <> 1, A not sparse.\r\nC\r\n DO 200 J = 1, NA\r\nC\r\n DO 190 K = 1, NB\r\n IC = 1\r\nC\r\n DO 180 I = 1, MA\r\n AIJ = ALPHA*A(I,J)\r\n LC = IC\r\nC\r\n DO 170 L = 1, MB\r\n C(LC,JC) = AIJ*B(L,K)\r\n LC = LC + 1\r\n 170 CONTINUE\r\nC\r\n IC = IC + MB\r\n 180 CONTINUE\r\nC\r\n JC = JC + 1\r\n 190 CONTINUE\r\nC\r\n 200 CONTINUE\r\nC\r\n END IF\r\n END IF\r\n ELSE IF ( BETA.EQ.ONE ) THEN\r\n IF ( ALPHA.EQ.ONE ) THEN\r\n IF ( SPARSE ) THEN\r\nC\r\nC Case beta = 1, alpha = 1, A sparse.\r\nC\r\n DO 240 J = 1, NA\r\nC\r\n DO 230 K = 1, NB\r\n IC = 1\r\nC\r\n DO 220 I = 1, MA\r\n AIJ = A(I,J)\r\n IF ( AIJ.NE.ZERO ) THEN\r\n LC = IC\r\nC\r\n DO 210 L = 1, MB\r\n C(LC,JC) = C(LC,JC) + AIJ*B(L,K)\r\n LC = LC + 1\r\n 210 CONTINUE\r\nC\r\n END IF\r\n IC = IC + MB\r\n 220 CONTINUE\r\nC\r\n JC = JC + 1\r\n 230 CONTINUE\r\nC\r\n 240 CONTINUE\r\nC\r\n ELSE\r\nC\r\nC Case beta = 1, alpha = 1, A not sparse.\r\nC\r\n DO 280 J = 1, NA\r\nC\r\n DO 270 K = 1, NB\r\n IC = 1\r\nC\r\n DO 260 I = 1, MA\r\n AIJ = A(I,J)\r\n LC = IC\r\nC\r\n DO 250 L = 1, MB\r\n C(LC,JC) = C(LC,JC) + AIJ*B(L,K)\r\n LC = LC + 1\r\n 250 CONTINUE\r\nC\r\n IC = IC + MB\r\n 260 CONTINUE\r\nC\r\n JC = JC + 1\r\n 270 CONTINUE\r\nC\r\n 280 CONTINUE\r\nC\r\n END IF\r\n ELSE\r\n IF ( SPARSE ) THEN\r\nC\r\nC Case beta = 1, alpha <> 1, A sparse.\r\nC\r\n DO 320 J = 1, NA\r\nC\r\n DO 310 K = 1, NB\r\n IC = 1\r\nC\r\n DO 300 I = 1, MA\r\n AIJ = ALPHA*A(I,J)\r\n IF ( AIJ.NE.ZERO ) THEN\r\n LC = IC\r\nC\r\n DO 290 L = 1, MB\r\n C(LC,JC) = C(LC,JC) + AIJ*B(L,K)\r\n LC = LC + 1\r\n 290 CONTINUE\r\nC\r\n END IF\r\n IC = IC + MB\r\n 300 CONTINUE\r\nC\r\n JC = JC + 1\r\n 310 CONTINUE\r\nC\r\n 320 CONTINUE\r\nC\r\n ELSE\r\nC\r\nC Case beta = 1, alpha <> 1, A not sparse.\r\nC\r\n DO 360 J = 1, NA\r\nC\r\n DO 350 K = 1, NB\r\n IC = 1\r\nC\r\n DO 340 I = 1, MA\r\n AIJ = ALPHA*A(I,J)\r\n LC = IC\r\nC\r\n DO 330 L = 1, MB\r\n C(LC,JC) = C(LC,JC) + AIJ*B(L,K)\r\n LC = LC + 1\r\n 330 CONTINUE\r\nC\r\n IC = IC + MB\r\n 340 CONTINUE\r\nC\r\n JC = JC + 1\r\n 350 CONTINUE\r\nC\r\n 360 CONTINUE\r\nC\r\n END IF\r\n END IF\r\n ELSE\r\n IF ( ALPHA.EQ.ONE ) THEN\r\n IF ( SPARSE ) THEN\r\nC\r\nC Case beta <> 0 or 1, alpha = 1, A sparse.\r\nC\r\n DO 400 J = 1, NA\r\nC\r\n DO 390 K = 1, NB\r\n IC = 1\r\nC\r\n DO 380 I = 1, MA\r\n AIJ = A(I,J)\r\nC\r\n IF ( AIJ.EQ.ZERO ) THEN\r\n CALL DSCAL( MB, BETA, C(IC,JC), 1 )\r\n ELSE\r\n LC = IC\r\nC\r\n DO 370 L = 1, MB\r\n C(LC,JC) = BETA*C(LC,JC) + AIJ*B(L,K)\r\n LC = LC + 1\r\n 370 CONTINUE\r\nC\r\n END IF\r\n IC = IC + MB\r\n 380 CONTINUE\r\nC\r\n JC = JC + 1\r\n 390 CONTINUE\r\nC\r\n 400 CONTINUE\r\nC\r\n ELSE\r\nC\r\nC Case beta <> 0 or 1, alpha = 1, A not sparse.\r\nC\r\n DO 440 J = 1, NA\r\nC\r\n DO 430 K = 1, NB\r\n IC = 1\r\nC\r\n DO 420 I = 1, MA\r\n AIJ = A(I,J)\r\n LC = IC\r\nC\r\n DO 410 L = 1, MB\r\n C(LC,JC) = BETA*C(LC,JC) + AIJ*B(L,K)\r\n LC = LC + 1\r\n 410 CONTINUE\r\nC\r\n IC = IC + MB\r\n 420 CONTINUE\r\nC\r\n JC = JC + 1\r\n 430 CONTINUE\r\nC\r\n 440 CONTINUE\r\nC\r\n END IF\r\n ELSE\r\n IF ( SPARSE ) THEN\r\nC\r\nC Case beta <> 0 or 1, alpha <> 1, A sparse.\r\nC\r\n DO 480 J = 1, NA\r\nC\r\n DO 470 K = 1, NB\r\n IC = 1\r\nC\r\n DO 460 I = 1, MA\r\n AIJ = ALPHA*A(I,J)\r\nC\r\n IF ( AIJ.EQ.ZERO ) THEN\r\n CALL DSCAL( MB, BETA, C(IC,JC), 1 )\r\n ELSE\r\n LC = IC\r\nC\r\n DO 450 L = 1, MB\r\n C(LC,JC) = BETA*C(LC,JC) + AIJ*B(L,K)\r\n LC = LC + 1\r\n 450 CONTINUE\r\nC\r\n END IF\r\n IC = IC + MB\r\n 460 CONTINUE\r\nC\r\n JC = JC + 1\r\n 470 CONTINUE\r\nC\r\n 480 CONTINUE\r\nC\r\n ELSE\r\nC\r\nC Case beta <> 0 or 1, alpha <> 1, A not sparse.\r\nC\r\n DO 520 J = 1, NA\r\nC\r\n DO 510 K = 1, NB\r\n IC = 1\r\nC\r\n DO 500 I = 1, MA\r\n AIJ = ALPHA*A(I,J)\r\n LC = IC\r\nC\r\n DO 490 L = 1, MB\r\n C(LC,JC) = BETA*C(LC,JC) + AIJ*B(L,K)\r\n LC = LC + 1\r\n 490 CONTINUE\r\nC\r\n IC = IC + MB\r\n 500 CONTINUE\r\nC\r\n JC = JC + 1\r\n 510 CONTINUE\r\nC\r\n 520 CONTINUE\r\nC\r\n END IF\r\n END IF\r\n END IF\r\n ELSE IF ( TRANSA .AND. .NOT.TRANSB ) THEN\r\nC\r\nC Case op(A) = A' and op(B) = B.\r\nC\r\n IF ( BETA.EQ.ZERO ) THEN\r\n IF ( ALPHA.EQ.ONE ) THEN\r\n IF ( SPARSE ) THEN\r\nC\r\nC Case beta = 0, alpha = 1, A sparse.\r\nC\r\n DO 560 J = 1, NA\r\nC\r\n DO 550 K = 1, NB\r\n IC = 1\r\nC\r\n DO 540 I = 1, MA\r\n AIJ = A(J,I)\r\n IF ( AIJ.EQ.ZERO ) THEN\r\n CALL DCOPY( MB, DUM(1), 0, C(IC,JC), 1 )\r\n ELSE IF ( AIJ.EQ.ONE ) THEN\r\n CALL DCOPY( MB, B(1,K), 1, C(IC,JC), 1 )\r\n ELSE\r\n LC = IC\r\nC\r\n DO 530 L = 1, MB\r\n C(LC,JC) = AIJ*B(L,K)\r\n LC = LC + 1\r\n 530 CONTINUE\r\nC\r\n END IF\r\n IC = IC + MB\r\n 540 CONTINUE\r\nC\r\n JC = JC + 1\r\n 550 CONTINUE\r\nC\r\n 560 CONTINUE\r\nC\r\n ELSE\r\nC\r\nC Case beta = 0, alpha = 1, A not sparse.\r\nC\r\n DO 600 J = 1, NA\r\nC\r\n DO 590 K = 1, NB\r\n IC = 1\r\nC\r\n DO 580 I = 1, MA\r\n AIJ = A(J,I)\r\n LC = IC\r\nC\r\n DO 570 L = 1, MB\r\n C(LC,JC) = AIJ*B(L,K)\r\n LC = LC + 1\r\n 570 CONTINUE\r\nC\r\n IC = IC + MB\r\n 580 CONTINUE\r\nC\r\n JC = JC + 1\r\n 590 CONTINUE\r\nC\r\n 600 CONTINUE\r\nC\r\n END IF\r\n ELSE\r\n IF ( SPARSE ) THEN\r\nC\r\nC Case beta = 0, alpha <> 1, A sparse.\r\nC\r\n DO 640 J = 1, NA\r\nC\r\n DO 630 K = 1, NB\r\n IC = 1\r\nC\r\n DO 620 I = 1, MA\r\n AIJ = ALPHA*A(J,I)\r\n IF ( AIJ.EQ.ZERO ) THEN\r\n CALL DCOPY( MB, DUM(1), 0, C(IC,JC), 1 )\r\n ELSE\r\n LC = IC\r\nC\r\n DO 610 L = 1, MB\r\n C(LC,JC) = AIJ*B(L,K)\r\n LC = LC + 1\r\n 610 CONTINUE\r\nC\r\n END IF\r\n IC = IC + MB\r\n 620 CONTINUE\r\nC\r\n JC = JC + 1\r\n 630 CONTINUE\r\nC\r\n 640 CONTINUE\r\nC\r\n ELSE\r\nC\r\nC Case beta = 0, alpha <> 1, A not sparse.\r\nC\r\n DO 680 J = 1, NA\r\nC\r\n DO 670 K = 1, NB\r\n IC = 1\r\nC\r\n DO 660 I = 1, MA\r\n AIJ = ALPHA*A(J,I)\r\n LC = IC\r\nC\r\n DO 650 L = 1, MB\r\n C(LC,JC) = AIJ*B(L,K)\r\n LC = LC + 1\r\n 650 CONTINUE\r\nC\r\n IC = IC + MB\r\n 660 CONTINUE\r\nC\r\n JC = JC + 1\r\n 670 CONTINUE\r\nC\r\n 680 CONTINUE\r\nC\r\n END IF\r\n END IF\r\n ELSE IF ( BETA.EQ.ONE ) THEN\r\n IF ( ALPHA.EQ.ONE ) THEN\r\n IF ( SPARSE ) THEN\r\nC\r\nC Case beta = 1, alpha = 1, A sparse.\r\nC\r\n DO 720 J = 1, NA\r\nC\r\n DO 710 K = 1, NB\r\n IC = 1\r\nC\r\n DO 700 I = 1, MA\r\n AIJ = A(J,I)\r\n IF ( AIJ.NE.ZERO ) THEN\r\n LC = IC\r\nC\r\n DO 690 L = 1, MB\r\n C(LC,JC) = C(LC,JC) + AIJ*B(L,K)\r\n LC = LC + 1\r\n 690 CONTINUE\r\nC\r\n END IF\r\n IC = IC + MB\r\n 700 CONTINUE\r\nC\r\n JC = JC + 1\r\n 710 CONTINUE\r\nC\r\n 720 CONTINUE\r\nC\r\n ELSE\r\nC\r\nC Case beta = 1, alpha = 1, A not sparse.\r\nC\r\n DO 760 J = 1, NA\r\nC\r\n DO 750 K = 1, NB\r\n IC = 1\r\nC\r\n DO 740 I = 1, MA\r\n AIJ = A(J,I)\r\n LC = IC\r\nC\r\n DO 730 L = 1, MB\r\n C(LC,JC) = C(LC,JC) + AIJ*B(L,K)\r\n LC = LC + 1\r\n 730 CONTINUE\r\nC\r\n IC = IC + MB\r\n 740 CONTINUE\r\nC\r\n JC = JC + 1\r\n 750 CONTINUE\r\nC\r\n 760 CONTINUE\r\nC\r\n END IF\r\n ELSE\r\n IF ( SPARSE ) THEN\r\nC\r\nC Case beta = 1, alpha <> 1, A sparse.\r\nC\r\n DO 800 J = 1, NA\r\nC\r\n DO 790 K = 1, NB\r\n IC = 1\r\nC\r\n DO 780 I = 1, MA\r\n AIJ = ALPHA*A(J,I)\r\n IF ( AIJ.NE.ZERO ) THEN\r\n LC = IC\r\nC\r\n DO 770 L = 1, MB\r\n C(LC,JC) = C(LC,JC) + AIJ*B(L,K)\r\n LC = LC + 1\r\n 770 CONTINUE\r\nC\r\n END IF\r\n IC = IC + MB\r\n 780 CONTINUE\r\nC\r\n JC = JC + 1\r\n 790 CONTINUE\r\nC\r\n 800 CONTINUE\r\nC\r\n ELSE\r\nC\r\nC Case beta = 1, alpha <> 1, A not sparse.\r\nC\r\n DO 840 J = 1, NA\r\nC\r\n DO 830 K = 1, NB\r\n IC = 1\r\nC\r\n DO 820 I = 1, MA\r\n AIJ = ALPHA*A(J,I)\r\n LC = IC\r\nC\r\n DO 810 L = 1, MB\r\n C(LC,JC) = C(LC,JC) + AIJ*B(L,K)\r\n LC = LC + 1\r\n 810 CONTINUE\r\nC\r\n IC = IC + MB\r\n 820 CONTINUE\r\nC\r\n JC = JC + 1\r\n 830 CONTINUE\r\nC\r\n 840 CONTINUE\r\nC\r\n END IF\r\n END IF\r\n ELSE\r\n IF ( ALPHA.EQ.ONE ) THEN\r\n IF ( SPARSE ) THEN\r\nC\r\nC Case beta <> 0 or 1, alpha = 1, A sparse.\r\nC\r\n DO 880 J = 1, NA\r\nC\r\n DO 870 K = 1, NB\r\n IC = 1\r\nC\r\n DO 860 I = 1, MA\r\n AIJ = A(J,I)\r\nC\r\n IF ( AIJ.EQ.ZERO ) THEN\r\n CALL DSCAL( MB, BETA, C(IC,JC), 1 )\r\n ELSE\r\n LC = IC\r\nC\r\n DO 850 L = 1, MB\r\n C(LC,JC) = BETA*C(LC,JC) + AIJ*B(L,K)\r\n LC = LC + 1\r\n 850 CONTINUE\r\nC\r\n END IF\r\n IC = IC + MB\r\n 860 CONTINUE\r\nC\r\n JC = JC + 1\r\n 870 CONTINUE\r\nC\r\n 880 CONTINUE\r\nC\r\n ELSE\r\nC\r\nC Case beta <> 0 or 1, alpha = 1, A not sparse.\r\nC\r\n DO 920 J = 1, NA\r\nC\r\n DO 910 K = 1, NB\r\n IC = 1\r\nC\r\n DO 900 I = 1, MA\r\n AIJ = A(J,I)\r\n LC = IC\r\nC\r\n DO 890 L = 1, MB\r\n C(LC,JC) = BETA*C(LC,JC) + AIJ*B(L,K)\r\n LC = LC + 1\r\n 890 CONTINUE\r\nC\r\n IC = IC + MB\r\n 900 CONTINUE\r\nC\r\n JC = JC + 1\r\n 910 CONTINUE\r\nC\r\n 920 CONTINUE\r\nC\r\n END IF\r\n ELSE\r\n IF ( SPARSE ) THEN\r\nC\r\nC Case beta <> 0 or 1, alpha <> 1, A sparse.\r\nC\r\n DO 960 J = 1, NA\r\nC\r\n DO 950 K = 1, NB\r\n IC = 1\r\nC\r\n DO 940 I = 1, MA\r\n AIJ = ALPHA*A(J,I)\r\nC\r\n IF ( AIJ.EQ.ZERO ) THEN\r\n CALL DSCAL( MB, BETA, C(IC,JC), 1 )\r\n ELSE\r\n LC = IC\r\nC\r\n DO 930 L = 1, MB\r\n C(LC,JC) = BETA*C(LC,JC) + AIJ*B(L,K)\r\n LC = LC + 1\r\n 930 CONTINUE\r\nC\r\n END IF\r\n IC = IC + MB\r\n 940 CONTINUE\r\nC\r\n JC = JC + 1\r\n 950 CONTINUE\r\nC\r\n 960 CONTINUE\r\nC\r\n ELSE\r\nC\r\nC Case beta <> 0 or 1, alpha <> 1, A not sparse.\r\nC\r\n DO 1000 J = 1, NA\r\nC\r\n DO 990 K = 1, NB\r\n IC = 1\r\nC\r\n DO 980 I = 1, MA\r\n AIJ = ALPHA*A(J,I)\r\n LC = IC\r\nC\r\n DO 970 L = 1, MB\r\n C(LC,JC) = BETA*C(LC,JC) + AIJ*B(L,K)\r\n LC = LC + 1\r\n 970 CONTINUE\r\nC\r\n IC = IC + MB\r\n 980 CONTINUE\r\nC\r\n JC = JC + 1\r\n 990 CONTINUE\r\nC\r\n 1000 CONTINUE\r\nC\r\n END IF\r\n END IF\r\n END IF\r\n ELSE IF ( TRANSB .AND. .NOT.TRANSA ) THEN\r\nC\r\nC Case op(A) = A and op(B) = B'.\r\nC\r\n IF ( BETA.EQ.ZERO ) THEN\r\n IF ( ALPHA.EQ.ONE ) THEN\r\n IF ( SPARSE ) THEN\r\nC\r\nC Case beta = 0, alpha = 1, A sparse.\r\nC\r\n DO 1080 J = 1, NA\r\nC\r\n DO 1070 K = 1, NB\r\n IC = 1\r\nC\r\n DO 1060 I = 1, MA\r\n AIJ = A(I,J)\r\n IF ( AIJ.EQ.ZERO ) THEN\r\n CALL DCOPY( MB, DUM(1), 0, C(IC,JC), 1 )\r\n ELSE IF ( AIJ.EQ.ONE ) THEN\r\n CALL DCOPY( MB, B(K,1), LDB, C(IC,JC), 1 )\r\n ELSE\r\n LC = IC\r\nC\r\n DO 1050 L = 1, MB\r\n C(LC,JC) = AIJ*B(K,L)\r\n LC = LC + 1\r\n 1050 CONTINUE\r\nC\r\n END IF\r\n IC = IC + MB\r\n 1060 CONTINUE\r\nC\r\n JC = JC + 1\r\n 1070 CONTINUE\r\nC\r\n 1080 CONTINUE\r\nC\r\n ELSE\r\nC\r\nC Case beta = 0, alpha = 1, A not sparse.\r\nC\r\n DO 1120 J = 1, NA\r\nC\r\n DO 1110 K = 1, NB\r\n IC = 1\r\nC\r\n DO 1100 I = 1, MA\r\n AIJ = A(I,J)\r\n LC = IC\r\nC\r\n DO 1090 L = 1, MB\r\n C(LC,JC) = AIJ*B(K,L)\r\n LC = LC + 1\r\n 1090 CONTINUE\r\nC\r\n IC = IC + MB\r\n 1100 CONTINUE\r\nC\r\n JC = JC + 1\r\n 1110 CONTINUE\r\nC\r\n 1120 CONTINUE\r\nC\r\n END IF\r\n ELSE\r\n IF ( SPARSE ) THEN\r\nC\r\nC Case beta = 0, alpha <> 1, A sparse.\r\nC\r\n DO 1160 J = 1, NA\r\nC\r\n DO 1150 K = 1, NB\r\n IC = 1\r\nC\r\n DO 1140 I = 1, MA\r\n AIJ = ALPHA*A(I,J)\r\n IF ( AIJ.EQ.ZERO ) THEN\r\n CALL DCOPY( MB, DUM(1), 0, C(IC,JC), 1 )\r\n ELSE\r\n LC = IC\r\nC\r\n DO 1130 L = 1, MB\r\n C(LC,JC) = AIJ*B(K,L)\r\n LC = LC + 1\r\n 1130 CONTINUE\r\nC\r\n END IF\r\n IC = IC + MB\r\n 1140 CONTINUE\r\nC\r\n JC = JC + 1\r\n 1150 CONTINUE\r\nC\r\n 1160 CONTINUE\r\nC\r\n ELSE\r\nC\r\nC Case beta = 0, alpha <> 1, A not sparse.\r\nC\r\n DO 1200 J = 1, NA\r\nC\r\n DO 1190 K = 1, NB\r\n IC = 1\r\nC\r\n DO 1180 I = 1, MA\r\n AIJ = ALPHA*A(I,J)\r\n LC = IC\r\nC\r\n DO 1170 L = 1, MB\r\n C(LC,JC) = AIJ*B(K,L)\r\n LC = LC + 1\r\n 1170 CONTINUE\r\nC\r\n IC = IC + MB\r\n 1180 CONTINUE\r\nC\r\n JC = JC + 1\r\n 1190 CONTINUE\r\nC\r\n 1200 CONTINUE\r\nC\r\n END IF\r\n END IF\r\n ELSE IF ( BETA.EQ.ONE ) THEN\r\n IF ( ALPHA.EQ.ONE ) THEN\r\n IF ( SPARSE ) THEN\r\nC\r\nC Case beta = 1, alpha = 1, A sparse.\r\nC\r\n DO 1240 J = 1, NA\r\nC\r\n DO 1230 K = 1, NB\r\n IC = 1\r\nC\r\n DO 1220 I = 1, MA\r\n AIJ = A(I,J)\r\n IF ( AIJ.NE.ZERO ) THEN\r\n LC = IC\r\nC\r\n DO 1210 L = 1, MB\r\n C(LC,JC) = C(LC,JC) + AIJ*B(K,L)\r\n LC = LC + 1\r\n 1210 CONTINUE\r\nC\r\n END IF\r\n IC = IC + MB\r\n 1220 CONTINUE\r\nC\r\n JC = JC + 1\r\n 1230 CONTINUE\r\nC\r\n 1240 CONTINUE\r\nC\r\n ELSE\r\nC\r\nC Case beta = 1, alpha = 1, A not sparse.\r\nC\r\n DO 1280 J = 1, NA\r\nC\r\n DO 1270 K = 1, NB\r\n IC = 1\r\nC\r\n DO 1260 I = 1, MA\r\n AIJ = A(I,J)\r\n LC = IC\r\nC\r\n DO 1250 L = 1, MB\r\n C(LC,JC) = C(LC,JC) + AIJ*B(K,L)\r\n LC = LC + 1\r\n 1250 CONTINUE\r\nC\r\n IC = IC + MB\r\n 1260 CONTINUE\r\nC\r\n JC = JC + 1\r\n 1270 CONTINUE\r\nC\r\n 1280 CONTINUE\r\nC\r\n END IF\r\n ELSE\r\n IF ( SPARSE ) THEN\r\nC\r\nC Case beta = 1, alpha <> 1, A sparse.\r\nC\r\n DO 1320 J = 1, NA\r\nC\r\n DO 1310 K = 1, NB\r\n IC = 1\r\nC\r\n DO 1300 I = 1, MA\r\n AIJ = ALPHA*A(I,J)\r\n IF ( AIJ.NE.ZERO ) THEN\r\n LC = IC\r\nC\r\n DO 1290 L = 1, MB\r\n C(LC,JC) = C(LC,JC) + AIJ*B(K,L)\r\n LC = LC + 1\r\n 1290 CONTINUE\r\nC\r\n END IF\r\n IC = IC + MB\r\n 1300 CONTINUE\r\nC\r\n JC = JC + 1\r\n 1310 CONTINUE\r\nC\r\n 1320 CONTINUE\r\nC\r\n ELSE\r\nC\r\nC Case beta = 1, alpha <> 1, A not sparse.\r\nC\r\n DO 1360 J = 1, NA\r\nC\r\n DO 1350 K = 1, NB\r\n IC = 1\r\nC\r\n DO 1340 I = 1, MA\r\n AIJ = ALPHA*A(I,J)\r\n LC = IC\r\nC\r\n DO 1330 L = 1, MB\r\n C(LC,JC) = C(LC,JC) + AIJ*B(K,L)\r\n LC = LC + 1\r\n 1330 CONTINUE\r\nC\r\n IC = IC + MB\r\n 1340 CONTINUE\r\nC\r\n JC = JC + 1\r\n 1350 CONTINUE\r\nC\r\n 1360 CONTINUE\r\nC\r\n END IF\r\n END IF\r\n ELSE\r\n IF ( ALPHA.EQ.ONE ) THEN\r\n IF ( SPARSE ) THEN\r\nC\r\nC Case beta <> 0 or 1, alpha = 1, A sparse.\r\nC\r\n DO 1400 J = 1, NA\r\nC\r\n DO 1390 K = 1, NB\r\n IC = 1\r\nC\r\n DO 1380 I = 1, MA\r\n AIJ = A(I,J)\r\nC\r\n IF ( AIJ.EQ.ZERO ) THEN\r\n CALL DSCAL( MB, BETA, C(IC,JC), 1 )\r\n ELSE\r\n LC = IC\r\nC\r\n DO 1370 L = 1, MB\r\n C(LC,JC) = BETA*C(LC,JC) + AIJ*B(K,L)\r\n LC = LC + 1\r\n 1370 CONTINUE\r\nC\r\n END IF\r\n IC = IC + MB\r\n 1380 CONTINUE\r\nC\r\n JC = JC + 1\r\n 1390 CONTINUE\r\nC\r\n 1400 CONTINUE\r\nC\r\n ELSE\r\nC\r\nC Case beta <> 0 or 1, alpha = 1, A not sparse.\r\nC\r\n DO 1440 J = 1, NA\r\nC\r\n DO 1430 K = 1, NB\r\n IC = 1\r\nC\r\n DO 1420 I = 1, MA\r\n AIJ = A(I,J)\r\n LC = IC\r\nC\r\n DO 1410 L = 1, MB\r\n C(LC,JC) = BETA*C(LC,JC) + AIJ*B(K,L)\r\n LC = LC + 1\r\n 1410 CONTINUE\r\nC\r\n IC = IC + MB\r\n 1420 CONTINUE\r\nC\r\n JC = JC + 1\r\n 1430 CONTINUE\r\nC\r\n 1440 CONTINUE\r\nC\r\n END IF\r\n ELSE\r\n IF ( SPARSE ) THEN\r\nC\r\nC Case beta <> 0 or 1, alpha <> 1, A sparse.\r\nC\r\n DO 1480 J = 1, NA\r\nC\r\n DO 1470 K = 1, NB\r\n IC = 1\r\nC\r\n DO 1460 I = 1, MA\r\n AIJ = ALPHA*A(I,J)\r\nC\r\n IF ( AIJ.EQ.ZERO ) THEN\r\n CALL DSCAL( MB, BETA, C(IC,JC), 1 )\r\n ELSE\r\n LC = IC\r\nC\r\n DO 1450 L = 1, MB\r\n C(LC,JC) = BETA*C(LC,JC) + AIJ*B(K,L)\r\n LC = LC + 1\r\n 1450 CONTINUE\r\nC\r\n END IF\r\n IC = IC + MB\r\n 1460 CONTINUE\r\nC\r\n JC = JC + 1\r\n 1470 CONTINUE\r\nC\r\n 1480 CONTINUE\r\nC\r\n ELSE\r\nC\r\nC Case beta <> 0 or 1, alpha <> 1, A not sparse.\r\nC\r\n DO 1520 J = 1, NA\r\nC\r\n DO 1510 K = 1, NB\r\n IC = 1\r\nC\r\n DO 1500 I = 1, MA\r\n AIJ = ALPHA*A(I,J)\r\n LC = IC\r\nC\r\n DO 1490 L = 1, MB\r\n C(LC,JC) = BETA*C(LC,JC) + AIJ*B(K,L)\r\n LC = LC + 1\r\n 1490 CONTINUE\r\nC\r\n IC = IC + MB\r\n 1500 CONTINUE\r\nC\r\n JC = JC + 1\r\n 1510 CONTINUE\r\nC\r\n 1520 CONTINUE\r\nC\r\n END IF\r\n END IF\r\n END IF\r\n ELSE\r\nC\r\nC Case op(A) = A' and op(B) = B'.\r\nC\r\n IF ( BETA.EQ.ZERO ) THEN\r\n IF ( ALPHA.EQ.ONE ) THEN\r\n IF ( SPARSE ) THEN\r\nC\r\nC Case beta = 0, alpha = 1, A sparse.\r\nC\r\n DO 1580 J = 1, NA\r\nC\r\n DO 1570 K = 1, NB\r\n IC = 1\r\nC\r\n DO 1560 I = 1, MA\r\n AIJ = A(J,I)\r\n IF ( AIJ.EQ.ZERO ) THEN\r\n CALL DCOPY( MB, DUM(1), 0, C(IC,JC), 1 )\r\n ELSE IF ( AIJ.EQ.ONE ) THEN\r\n CALL DCOPY( MB, B(K,1), LDB, C(IC,JC), 1 )\r\n ELSE\r\n LC = IC\r\nC\r\n DO 1550 L = 1, MB\r\n C(LC,JC) = AIJ*B(K,L)\r\n LC = LC + 1\r\n 1550 CONTINUE\r\nC\r\n END IF\r\n IC = IC + MB\r\n 1560 CONTINUE\r\nC\r\n JC = JC + 1\r\n 1570 CONTINUE\r\nC\r\n 1580 CONTINUE\r\nC\r\n ELSE\r\nC\r\nC Case beta = 0, alpha = 1, A not sparse.\r\nC\r\n DO 1620 J = 1, NA\r\nC\r\n DO 1610 K = 1, NB\r\n IC = 1\r\nC\r\n DO 1600 I = 1, MA\r\n AIJ = A(J,I)\r\n LC = IC\r\nC\r\n DO 1590 L = 1, MB\r\n C(LC,JC) = AIJ*B(K,L)\r\n LC = LC + 1\r\n 1590 CONTINUE\r\nC\r\n IC = IC + MB\r\n 1600 CONTINUE\r\nC\r\n JC = JC + 1\r\n 1610 CONTINUE\r\nC\r\n 1620 CONTINUE\r\nC\r\n END IF\r\n ELSE\r\n IF ( SPARSE ) THEN\r\nC\r\nC Case beta = 0, alpha <> 1, A sparse.\r\nC\r\n DO 1660 J = 1, NA\r\nC\r\n DO 1650 K = 1, NB\r\n IC = 1\r\nC\r\n DO 1640 I = 1, MA\r\n AIJ = ALPHA*A(J,I)\r\n IF ( AIJ.EQ.ZERO ) THEN\r\n CALL DCOPY( MB, DUM(1), 0, C(IC,JC), 1 )\r\n ELSE\r\n LC = IC\r\nC\r\n DO 1630 L = 1, MB\r\n C(LC,JC) = AIJ*B(K,L)\r\n LC = LC + 1\r\n 1630 CONTINUE\r\nC\r\n END IF\r\n IC = IC + MB\r\n 1640 CONTINUE\r\nC\r\n JC = JC + 1\r\n 1650 CONTINUE\r\nC\r\n 1660 CONTINUE\r\nC\r\n ELSE\r\nC\r\nC Case beta = 0, alpha <> 1, A not sparse.\r\nC\r\n DO 1700 J = 1, NA\r\nC\r\n DO 1690 K = 1, NB\r\n IC = 1\r\nC\r\n DO 1680 I = 1, MA\r\n AIJ = ALPHA*A(J,I)\r\n LC = IC\r\nC\r\n DO 1670 L = 1, MB\r\n C(LC,JC) = AIJ*B(K,L)\r\n LC = LC + 1\r\n 1670 CONTINUE\r\nC\r\n IC = IC + MB\r\n 1680 CONTINUE\r\nC\r\n JC = JC + 1\r\n 1690 CONTINUE\r\nC\r\n 1700 CONTINUE\r\nC\r\n END IF\r\n END IF\r\n ELSE IF ( BETA.EQ.ONE ) THEN\r\n IF ( ALPHA.EQ.ONE ) THEN\r\n IF ( SPARSE ) THEN\r\nC\r\nC Case beta = 1, alpha = 1, A sparse.\r\nC\r\n DO 1740 J = 1, NA\r\nC\r\n DO 1730 K = 1, NB\r\n IC = 1\r\nC\r\n DO 1720 I = 1, MA\r\n AIJ = A(J,I)\r\n IF ( AIJ.NE.ZERO ) THEN\r\n LC = IC\r\nC\r\n DO 1710 L = 1, MB\r\n C(LC,JC) = C(LC,JC) + AIJ*B(K,L)\r\n LC = LC + 1\r\n 1710 CONTINUE\r\nC\r\n END IF\r\n IC = IC + MB\r\n 1720 CONTINUE\r\nC\r\n JC = JC + 1\r\n 1730 CONTINUE\r\nC\r\n 1740 CONTINUE\r\nC\r\n ELSE\r\nC\r\nC Case beta = 1, alpha = 1, A not sparse.\r\nC\r\n DO 1780 J = 1, NA\r\nC\r\n DO 1770 K = 1, NB\r\n IC = 1\r\nC\r\n DO 1760 I = 1, MA\r\n AIJ = A(J,I)\r\n LC = IC\r\nC\r\n DO 1750 L = 1, MB\r\n C(LC,JC) = C(LC,JC) + AIJ*B(K,L)\r\n LC = LC + 1\r\n 1750 CONTINUE\r\nC\r\n IC = IC + MB\r\n 1760 CONTINUE\r\nC\r\n JC = JC + 1\r\n 1770 CONTINUE\r\nC\r\n 1780 CONTINUE\r\nC\r\n END IF\r\n ELSE\r\n IF ( SPARSE ) THEN\r\nC\r\nC Case beta = 1, alpha <> 1, A sparse.\r\nC\r\n DO 1820 J = 1, NA\r\nC\r\n DO 1810 K = 1, NB\r\n IC = 1\r\nC\r\n DO 1800 I = 1, MA\r\n AIJ = ALPHA*A(J,I)\r\n IF ( AIJ.NE.ZERO ) THEN\r\n LC = IC\r\nC\r\n DO 1790 L = 1, MB\r\n C(LC,JC) = C(LC,JC) + AIJ*B(K,L)\r\n LC = LC + 1\r\n 1790 CONTINUE\r\nC\r\n END IF\r\n IC = IC + MB\r\n 1800 CONTINUE\r\nC\r\n JC = JC + 1\r\n 1810 CONTINUE\r\nC\r\n 1820 CONTINUE\r\nC\r\n ELSE\r\nC\r\nC Case beta = 1, alpha <> 1, A not sparse.\r\nC\r\n DO 1860 J = 1, NA\r\nC\r\n DO 1850 K = 1, NB\r\n IC = 1\r\nC\r\n DO 1840 I = 1, MA\r\n AIJ = ALPHA*A(J,I)\r\n LC = IC\r\nC\r\n DO 1830 L = 1, MB\r\n C(LC,JC) = C(LC,JC) + AIJ*B(K,L)\r\n LC = LC + 1\r\n 1830 CONTINUE\r\nC\r\n IC = IC + MB\r\n 1840 CONTINUE\r\nC\r\n JC = JC + 1\r\n 1850 CONTINUE\r\nC\r\n 1860 CONTINUE\r\nC\r\n END IF\r\n END IF\r\n ELSE\r\n IF ( ALPHA.EQ.ONE ) THEN\r\n IF ( SPARSE ) THEN\r\nC\r\nC Case beta <> 0 or 1, alpha = 1, A sparse.\r\nC\r\n DO 1900 J = 1, NA\r\nC\r\n DO 1890 K = 1, NB\r\n IC = 1\r\nC\r\n DO 1880 I = 1, MA\r\n AIJ = A(J,I)\r\nC\r\n IF ( AIJ.EQ.ZERO ) THEN\r\n CALL DSCAL( MB, BETA, C(IC,JC), 1 )\r\n ELSE\r\n LC = IC\r\nC\r\n DO 1870 L = 1, MB\r\n C(LC,JC) = BETA*C(LC,JC) + AIJ*B(K,L)\r\n LC = LC + 1\r\n 1870 CONTINUE\r\nC\r\n END IF\r\n IC = IC + MB\r\n 1880 CONTINUE\r\nC\r\n JC = JC + 1\r\n 1890 CONTINUE\r\nC\r\n 1900 CONTINUE\r\nC\r\n ELSE\r\nC\r\nC Case beta <> 0 or 1, alpha = 1, A not sparse.\r\nC\r\n DO 1940 J = 1, NA\r\nC\r\n DO 1930 K = 1, NB\r\n IC = 1\r\nC\r\n DO 1920 I = 1, MA\r\n AIJ = A(J,I)\r\n LC = IC\r\nC\r\n DO 1910 L = 1, MB\r\n C(LC,JC) = BETA*C(LC,JC) + AIJ*B(K,L)\r\n LC = LC + 1\r\n 1910 CONTINUE\r\nC\r\n IC = IC + MB\r\n 1920 CONTINUE\r\nC\r\n JC = JC + 1\r\n 1930 CONTINUE\r\nC\r\n 1940 CONTINUE\r\nC\r\n END IF\r\n ELSE\r\n IF ( SPARSE ) THEN\r\nC\r\nC Case beta <> 0 or 1, alpha <> 1, A sparse.\r\nC\r\n DO 1980 J = 1, NA\r\nC\r\n DO 1970 K = 1, NB\r\n IC = 1\r\nC\r\n DO 1960 I = 1, MA\r\n AIJ = ALPHA*A(J,I)\r\nC\r\n IF ( AIJ.EQ.ZERO ) THEN\r\n CALL DSCAL( MB, BETA, C(IC,JC), 1 )\r\n ELSE\r\n LC = IC\r\nC\r\n DO 1950 L = 1, MB\r\n C(LC,JC) = BETA*C(LC,JC) + AIJ*B(K,L)\r\n LC = LC + 1\r\n 1950 CONTINUE\r\nC\r\n END IF\r\n IC = IC + MB\r\n 1960 CONTINUE\r\nC\r\n JC = JC + 1\r\n 1970 CONTINUE\r\nC\r\n 1980 CONTINUE\r\nC\r\n ELSE\r\nC\r\nC Case beta <> 0 or 1, alpha <> 1, A not sparse.\r\nC\r\n DO 2020 J = 1, NA\r\nC\r\n DO 2010 K = 1, NB\r\n IC = 1\r\nC\r\n DO 2000 I = 1, MA\r\n AIJ = ALPHA*A(J,I)\r\n LC = IC\r\nC\r\n DO 1990 L = 1, MB\r\n C(LC,JC) = BETA*C(LC,JC) + AIJ*B(K,L)\r\n LC = LC + 1\r\n 1990 CONTINUE\r\nC\r\n IC = IC + MB\r\n 2000 CONTINUE\r\nC\r\n JC = JC + 1\r\n 2010 CONTINUE\r\nC\r\n 2020 CONTINUE\r\nC\r\n END IF\r\n END IF\r\n END IF\r\n END IF\r\n RETURN\r\nC *** Last line of MB01VD ***\r\n END\r\n", "meta": {"hexsha": "ead0d42d4ab051d53a751c0821c8f04bb7c44964", "size": 48405, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "External/SLICOT/MB01VD.f", "max_stars_repo_name": "bgin/MissileSimulation", "max_stars_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2016-08-28T23:20:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-15T14:43:58.000Z", "max_issues_repo_path": "External/SLICOT/MB01VD.f", "max_issues_repo_name": "bgin/MissileSimulation", "max_issues_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-06-02T21:29:51.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-05T05:59:31.000Z", "max_forks_repo_path": "External/SLICOT/MB01VD.f", "max_forks_repo_name": "bgin/MissileSimulation", "max_forks_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-07-04T22:38:22.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-04T22:38:22.000Z", "avg_line_length": 28.8125, "max_line_length": 73, "alphanum_fraction": 0.2909203595, "num_tokens": 12349, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026482819236, "lm_q2_score": 0.7341195385342971, "lm_q1q2_score": 0.6734097968530145}} {"text": "\nmodule grains\n\n implicit none\n\ncontains\n\n ! Using double precision return type instead of int to avoid overflow in int\n double precision function square(n)\n integer :: n\n square = -1.d0\n if (n>=1 .and. n<=64) then\n square = 2.d0**(n-1)\n end if\n end function\n\n double precision function total()\n integer :: i\n total=0.d0\n do i=1,64\n total = total +square(i)\n end do\n end function\n\nend module\n", "meta": {"hexsha": "9a5f6b668ab999d60e35a244995b2e8f8dfcb4a8", "size": 432, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "exercises/practice/grains/.meta/example.f90", "max_stars_repo_name": "zmoon/fortran", "max_stars_repo_head_hexsha": "a86a3749632f1694f9332fdcd358abba151d5cd2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2017-06-28T12:57:17.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-22T03:30:48.000Z", "max_issues_repo_path": "exercises/practice/grains/.meta/example.f90", "max_issues_repo_name": "zmoon/fortran", "max_issues_repo_head_hexsha": "a86a3749632f1694f9332fdcd358abba151d5cd2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 92, "max_issues_repo_issues_event_min_datetime": "2017-06-28T13:27:55.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T08:46:33.000Z", "max_forks_repo_path": "exercises/practice/grains/.meta/example.f90", "max_forks_repo_name": "zmoon/fortran", "max_forks_repo_head_hexsha": "a86a3749632f1694f9332fdcd358abba151d5cd2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 20, "max_forks_repo_forks_event_min_datetime": "2017-07-29T03:43:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-08T05:59:28.000Z", "avg_line_length": 16.6153846154, "max_line_length": 78, "alphanum_fraction": 0.6342592593, "num_tokens": 126, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026573249612, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.6734097928196813}} {"text": "!--------------------------------------------------------------------------------\n!\n! GEOFRACTAL version 1.0\n!\n!--------------------------------------------------------------------------------\n!\n! GEOFRACTAL v1.0 computes the geometrical cross section of randomly orientated \n! fractal dust aggregates based on a statistical distribution model of monomer \n! particles developed in Tazaki (in prep.).\n! \n! If you wish to publish a paper that contains results obtained by this code, \n! please acknowledge this code and cite relevant papers. \n!\n!\n! Disclaimer:\n! I reject all responsibility for the use of this code. Although it has been\n! tested, the code may still contain a bug. I am not responsible for any damages\n! caused by the use of the code. If you find a bug, please let me know.\n!\n! Ryo Tazaki (2021/Jan/1)\n! email: r.tazaki -at- uva.nl \n!\n!--------------------------------------------------------------------------------\n! INPUT PARAMETERS\n!--------------------------------------------------------------------------------\n!\n! Df : fractal dimension\n! PN : number of monomers\n! k0 : fractal prefactor defined by PN = k0*(Rg/R0)^Df\n!\n! iqapp : Select a method for solving radial and angular integration \n! when computing the mean overlapping efficiency.\n! --------------------------------------------------------\n! | radial (x) | angular (u) |\n! ---------------------------------------------------------\n! iqapp = 1 | numerical | numerical | \n! iqapp = 3 | numerical ( D<=2 ) | analytical |\n! | analytical ( D> 2 ) | |\n! --------------------------------------------------------\n!\n! iqcon : Switch to specify the numerical factor A.\n! iqcon = 1 : A = 1 \n! iqcon = 2 : A is chosen to connect two regimes.\n!\n! iqcor : Switch to specify a cut-off model of the correlation function\n! iqcon = 1 : The Gaussian cut-off function \n! iqcon = 2 : The exponential cut-off function\n! iqcon = 3 : The fractal dimension cut-off function\n!\n! Prefered set of options is iqcor=3, iqapp=3 and iqcon=2.\n! Note that iqcor=1 is also possible, but avoid using iqcor=2.\n!\n!--------------------------------------------------------------------------------\n! OUTPUT PARAMETER\n!--------------------------------------------------------------------------------\n!\n! G : The geocross section of the aggregate normalized by a factor PN*pi*R0^2. \n! Thus, \"G\" is non-dimensional quantity. \n!\n!--------------------------------------------------------------------------------\n\n!module types\n!implicit none\n!integer, parameter :: dp = selected_real_kind(P=15)\n!end module types\n!\n!module const\n!use types\n!implicit none\n!real(kind=dp),parameter :: pi = 3.1415926535897932384_dp\n!end module const\n\nsubroutine geofrac(iqapp,iqcon,iqcor,PN,k0,df,G)\nuse types\nimplicit none\ninteger :: iqapp,iqcon,iqcor\nreal(kind=dp) :: PN,k0,df,GS,G\nreal(kind=dp) :: pnth,gth,sigmath,A,sigma\nlogical,parameter::debug=.false.\n\n!--------------------------------------------------------------------------------\n! some checks\n!--------------------------------------------------------------------------------\nif(PN .le. 0.9999_dp) then\n print *, 'number of monomers =',PN\n print *, 'error: The number of monomers should be larger than 1.'\n print *, 'stop'\n stop\nendif\nif(df .lt. 0.9999_dp .or. df .gt. 3.00001) then\n print *, 'fractal dimension df =',df\n print *, 'error: Fractal dimension df should be 1<=df<=3.'\n print *, 'stop'\n stop\nendif\nif(iqcon .ne. 1 .and. iqcon .ne. 2) then\n print *, 'error: iqcon should be either 1 or 2.'\n print *, 'stop'\n stop\nendif\nif(iqcor .ne. 1 .and. iqcor .ne. 2 .and. iqcor .ne. 3) then\n print *, 'error: iqcor should be either 1, 2, or 3.'\n print *, 'stop'\n stop\nendif\nif(iqapp .ne. 1 .and. iqapp .ne. 2 .and. iqapp .ne. 3) then\n print *, 'error: iqapp should be either 1 or 3.'\n print *, 'stop'\n stop\nendif\nif(iqapp .eq. 2 .and. (debug .eqv. .false.)) then\n print *, 'error: iqapp = 2 is only allowed for a debug mode.'\n print *, 'stop'\n stop\nendif\n\n!--------------------------------------------------------------------------------\n! start calculations\n!--------------------------------------------------------------------------------\nA = 1.0_dp\nif(iqcon .eq. 2) then\n PNTH = 11.0_dp*df-8.5_dp\n PNTH = min(PNTH,8.0_dp)\n if(PN .lt. PNTH) then\n G=GS(PN)\n return\n endif\n call mean_overlap_efficiency(iqapp,iqcor,k0,df,PNTH,sigmath)\n A = (1.0_dp+(PNTH-1.0_dp)*sigmath)*GS(PNTH)\nendif\ncall mean_overlap_efficiency(iqapp,iqcor,k0,df,PN,sigma)\nG = A / (1.0_dp + (PN-1.0_dp)*sigma)\n\nreturn\nend subroutine geofrac\n\n!--------------------------------------------------------------------------------\n!\n! Minato et al. (2006)'s fitting formula for N < 16\n!\n!--------------------------------------------------------------------------------\nfunction GS(PN)\nuse types\nimplicit none\nreal(kind=dp)::GS,PN\n GS = 12.5_dp*PN**(-0.315_dp)*exp(-2.53_dp/PN**0.0920_dp)\nreturn\nend function GS\n\n!--------------------------------------------------------------------------------\n!\n! This subroutine calculations the mean overlapping efficiency: sigma\n! (In Tazaki in prep., this quantity corresponds to \\tilde{sigma} )\n!\n! For iqcor=1 [Gaussian cut-off model]\n!\n! xmin /ln(xmax) \n! sigma = -------------- | dlnx frad(x)*S(rho),\n! 16*Gamma(df/2) /ln(xmin)\n!\n! xmin = df*(k0/PN)^(2/df); a=(df-2)/2; rho = sqrt(x/xmin)\n!\n! For iqcor=2 [Exponential cut-off model]\n!\n! xmin^2 /ln(xmax) \n! sigma = -------------- | dlnx frad(x)*S(rho),\n! 16*Gamma(df) /ln(xmin)\n!\n! xmin = 2*sqrt(df(df+1)/2)*(k0/PN)^(1.0/df); a=df-2; rho = x/xmin\n!\n! For iqcor=3 [Fractal dimension cut-off model]\n!\n! xmin^{2/df} /ln(xmax) \n! sigma = ---------- | dlnx frad(x)*S(rho),\n! 16 /ln(xmin)\n!\n! xmin = 2^(df-1)*k0/PN; a=(df-2)/df; rho = (x/xmin)^(1/df)\n!\n! where df is fractal dimension, R0 is the monomer radius, Rg is \n! the radius of gyration, frad(x) is the radial integrand function, \n! and S(rho) is the angular integral function.\n!\n! frad(x)dlnx = x^{a}*exp(-x) dlnx = x^{a-1}exp(-x) dx\n!\n! 16*rho^2 / (1/rho) \n! S(rho) = -------- | du fang(rho,u),\n! pi /0 \n! \n! fang(rho,u) = [Arcsin{sqrt(1-rho^2u^2)} - rho*u*sqrt{1-rho^2u^2}]*u/sqrt(1-u^2)\n!\n! Note that the angular integral function S(rho) \u22481 when rho >> 1.\n!\n!--------------------------------------------------------------------------------\nsubroutine mean_overlap_efficiency(iqapp,iqcor,k0,df,PN,sigma)\nuse types; use const\nimplicit none\ninteger,parameter :: nx = 1000\nreal(kind=dp),parameter :: xmax = 25.0_dp\ninteger :: i,iqapp,iqcor\nreal(kind=dp) :: xmin,dlnx,stmp,k0,df,PN,sigma,frad\nreal(kind=dp) :: factor,aicgm,gammq\nreal(kind=dp),allocatable::x(:),sang(:)\n\nif(iqcor .eq. 1) then ! Gaussian\n aicgm = 0.5_dp*(df-2.0_dp)\n xmin = df * (k0/PN) ** (2.0/df)\n factor = xmin/16.0_dp/gamma(0.5_dp*df)\nelseif(iqcor .eq. 2) then ! Exponential\n aicgm = df - 2.0_dp\n xmin = 2.0_dp * sqrt(0.5_dp*df*(df+1.0_dp))*(k0/PN)**(1.0/df)\n factor = xmin*xmin/16.0_dp/gamma(df)\nelseif(iqcor .eq. 3) then ! Fractal dimension\n aicgm = (df - 2.0_dp) / df\n xmin = 2.0_dp**(df-1.0_dp) * k0 / PN\n factor = xmin ** (2.0_dp/df) / 16.0_dp\nendif\n\nif(df .gt. 2.0_dp .and. iqapp .eq. 3) then\n sigma = factor*gamma(aicgm)*gammq(aicgm,xmin)\nelse\n dlnx = log(xmax/xmin)/real(nx-1,kind=dp)\n allocate(x(1:nx),sang(1:nx))\n do i=1,nx\n x(i) = exp(log(xmin)+real(i-1,kind=dp)*dlnx)\n if(iqapp .eq. 1) then\n call angular_integration(iqcor,x(i),xmin,df,stmp)\n sang(i) = stmp\n else\n sang(i) = 1.0_dp\n endif\n enddo\n sigma = 0.0_dp\n do i=1,nx-1\n sigma = sigma + 0.5_dp * (frad(aicgm,x(i))*sang(i)+&\n frad(aicgm,x(i+1))*sang(i+1))\n enddo\n sigma = sigma * dlnx * factor\n deallocate(x,sang)\nendif\nreturn\nend subroutine mean_overlap_efficiency\n\n!--------------------------------------------------------------------------------\n! The radial integrand function in ln(x) space\n!--------------------------------------------------------------------------------\nfunction frad(aicgm,x)\nuse types\nimplicit none\nreal(kind=dp)::aicgm,x,frad\n frad = x ** aicgm * exp(-x)\nreturn\nend function frad\n\n!--------------------------------------------------------------------------------\n! This subroutine computes the angular integral function S(rho) \n!--------------------------------------------------------------------------------\nsubroutine angular_integration(iqcor,x,xmin,df,sang)\nuse types; use const\nimplicit none\ninteger :: i,j,iqcor\ninteger,parameter :: nmax_u = 500\nreal(kind=dp) :: x,xmin,df,rho,umin,umax,du,fang,sang\nreal(kind=dp) :: u(1:nmax_u)\n\nif(iqcor .eq. 1) then\n rho = sqrt(x/xmin)\nelseif(iqcor .eq. 2) then\n rho = x/xmin\nelseif(iqcor .eq. 3) then\n rho = (x/xmin) ** (1.0_dp/df)\nendif\n\nsang = 0.0_dp\numin = 0.0_dp\numax = 1.0_dp / rho\ndu = (umax - umin) / real(nmax_u-1,kind=dp)\ndo j=1,nmax_u\n u(j) = umin + du * real(j-1,kind=dp)\nenddo\ndo j=1,nmax_u-1\n sang = sang + 0.5_dp*(fang(rho,u(j))+fang(rho,u(j+1)))*du\nenddo\nsang = 16.0_dp * rho * rho * sang / pi\nreturn\nend subroutine angular_integration\n\n!--------------------------------------------------------------------------------\n!\n! This function returns the integrand of the angular integral.\n! fang (rho,u) = [ Arcsin(sqrt(1-rho^2u^2)) - & \n! rho*u*sqrt(1-rho^2u^2)] * u / sqrt(1-u^2)\n!\n!--------------------------------------------------------------------------------\nfunction fang(rho,u)\nuse types\nimplicit none\nreal(kind=dp)::rho,u,fang\n\nif(abs(1.0_dp-rho*u) .le. 1.0e-10_dp) then\n fang = 0.0_dp\nelse\n fang = (asin(sqrt(1.0_dp-rho*rho*u*u))-&\n rho*u*sqrt(1.0_dp-rho*rho*u*u))*u/sqrt(1.0_dp-u*u)\nendif\n\nreturn\nend function fang\n\n!--------------------------------------------------------------------------------\n!\n! Following subroutines (gammq, gser, gcf, gammln) compute \n! the incomplete Gamma function Q(a,x)\n! \n! 1 /infinity\n! Q(a,x) = -------- | x^{a-1} exp(-x) dx\n! Gamma(a) /x\n!\n! where a>0. The definition of Q(a,x) obeys the definition in\n!\n! \"Numerical Recipes in Fortran 77\"\n! Press, W. H., Teukolsky, S. A., Vetterling, W. T., et al.1992, \n! Cambridge: University Press, |c1992, 2nd ed\n!\n! Following subroutines are taken from Numerical Recippes in Fortran 77\n!\n!--------------------------------------------------------------------------------\n!\n! History (R.T.)\n!\n! The original subroutine was slightly modified so that the old F77 grammers\n! are rewritten by modern grammers.\n!\n! Convergence accuracy eps is changed from 3e-7 to 3e-14.\n!\n!--------------------------------------------------------------------------------\nfunction gammq(a,x)\nuse types\nreal(kind=dp) a,gammq,x\nreal(kind=dp) gammcf,gamser,gln\nif(x.lt.0..or.a.le.0.) then\n write(*,*) 'error' \n stop\nendif\nif(x.lt.a+1.)then\n call gser(gamser,a,x,gln)\n gammq=1.-gamser\nelse\n call gcf(gammcf,a,x,gln)\n gammq=gammcf\nendif\nreturn\nend function gammq\n\nsubroutine gser(gamser,a,x,gln)\nuse types\ninteger itmax\nreal(kind=dp) a,gamser,gln,x,eps\nparameter (itmax=100,eps=3.e-14)\ninteger n\nreal(kind=dp) ap,del,sum,gammln\ngln=gammln(a)\nif(x.le.0.)then\n if(x.lt.0.) then\n write(*,*) \"error\"\n stop \n endif\n gamser=0.\n return\nendif\nap=a\nsum=1./a\ndel=sum\ndo n=1,itmax\n ap=ap+1.\n del=del*x/ap\n sum=sum+del\n if(abs(del).lt.abs(sum)*eps) exit\n if(n .eq. itmax) then\n print *, 'a too large, itmax too small in gser'\n stop\n endif\nenddo\ngamser=sum*exp(-x+a*log(x)-gln)\nreturn\nend subroutine gser\nsubroutine gcf(gammcf,a,x,gln)\nuse types\ninteger itmax\nreal(kind=dp) a,gammcf,gln,x,eps,fpmin\nparameter (itmax=100,eps=3.e-14,fpmin=1.e-30)\ninteger i\nreal(kind=dp) an,b,c,d,del,h,gammln\ngln=gammln(a)\nb=x+1.-a\nc=1./fpmin\nd=1./b\nh=d\ndo i=1,itmax\n an=-i*(i-a)\n b=b+2.\n d=an*d+b\n if(abs(d).lt.fpmin)d=fpmin\n c=b+an/c\n if(abs(c).lt.fpmin)c=fpmin\n d=1./d\n del=d*c\n h=h*del\n if(abs(del-1.).lt.eps) exit\n if(n .eq. itmax) then\n print *, 'a too large, itmax too small in gcf'\n stop\n endif\nenddo\ngammcf=exp(-x+a*log(x)-gln)*h\nreturn\nend subroutine gcf\nfunction gammln(xx)\nuse types\nreal(kind=dp) gammln,xx\ninteger j\nreal(kind=dp) ser,stp,tmp,x,y,cof(6)\nsave cof,stp\ndata cof,stp/76.18009172947146d0,-86.50532032941677d0,&\n 24.01409824083091d0,-1.231739572450155d0,.1208650973866179d-2,&\n -.5395239384953d-5,2.5066282746310005d0/\nx=xx\ny=x\ntmp=x+5.5d0\ntmp=(x+0.5d0)*log(tmp)-tmp\nser=1.000000000190015d0\ndo j=1,6\n y=y+1.d0\n ser=ser+cof(j)/y\nenddo\ngammln=tmp+log(stp*ser/x)\nreturn\nend function gammln\n", "meta": {"hexsha": "2ca4397773439ac7ff99d5da8b9be8396e0387ce", "size": 13876, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "optool_geofractal.f90", "max_stars_repo_name": "cdominik/optool", "max_stars_repo_head_hexsha": "da0ba3a8d4913c60f35020293ab656f3f5c52000", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2020-10-13T13:24:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-17T09:46:00.000Z", "max_issues_repo_path": "geofractal.f90", "max_issues_repo_name": "rtazaki1205/opacfractal", "max_issues_repo_head_hexsha": "bd430a7ffcd65814d70f057b97b56f74ff8ffe62", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-08-28T15:11:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-26T10:14:58.000Z", "max_forks_repo_path": "geofractal.f90", "max_forks_repo_name": "rtazaki1205/opacfractal", "max_forks_repo_head_hexsha": "bd430a7ffcd65814d70f057b97b56f74ff8ffe62", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-17T20:33:36.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-17T20:33:36.000Z", "avg_line_length": 31.6803652968, "max_line_length": 81, "alphanum_fraction": 0.4875324301, "num_tokens": 4115, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026550642019, "lm_q2_score": 0.7341195152660688, "lm_q1q2_score": 0.6734097804880098}} {"text": "subroutine sum(v,n,SU)\n implicit none ;\n integer*4 i,n\n double precision,dimension(n):: v\n double precision:: SU\nSU=0.0d0;\n do i=1,n\n SU=SU+v(i);\n enddo ;\n return;\nend subroutine \n", "meta": {"hexsha": "cceb2c58bb9f8de5518ae7ff8985746c90709a51", "size": 199, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "11/mathlib/sum.f90", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "11/mathlib/sum.f90", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "11/mathlib/sum.f90", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.5833333333, "max_line_length": 37, "alphanum_fraction": 0.6180904523, "num_tokens": 65, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8333245870332531, "lm_q2_score": 0.8080672158638527, "lm_q1q2_score": 0.6733822789548556}} {"text": "program main\n implicit none\n integer, parameter :: n = 5\n real :: a(n, n), norm, work(n)\n integer :: i, j\n real :: slange\n do j = 1, n\n do i = 1, n\n a(i, j) = min(i, j)\n end do\n end do\n print *, \"Matrix A: \", n, n\n do j = 1, n\n print *, a(1:n, j)\n end do\n\n norm = slange('M', n, n, a, n)\n print *, \"element of largest absolute value =\", norm\n norm = slange('1', n, n, a, n)\n print *, \"one norm =\", norm\n norm = slange('I', n, n, a, n, work)\n print *, \"infinity norm =\", norm\n norm = slange('F', n, n, a, n)\n print *, \"Frobenius norm =\", norm\nend program main\n", "meta": {"hexsha": "944d44af8c9a65544509980de9cb8ac3bc7e5bdb", "size": 596, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/lapack/slange_f.f90", "max_stars_repo_name": "t-sakashita/rokko", "max_stars_repo_head_hexsha": "ebd49e1198c4ec9e7612ad4a9806d16a4ff0bdc9", "max_stars_repo_licenses": ["BSL-1.0"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2015-01-31T18:57:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T19:04:49.000Z", "max_issues_repo_path": "example/lapack/slange_f.f90", "max_issues_repo_name": "t-sakashita/rokko", "max_issues_repo_head_hexsha": "ebd49e1198c4ec9e7612ad4a9806d16a4ff0bdc9", "max_issues_repo_licenses": ["BSL-1.0"], "max_issues_count": 514, "max_issues_repo_issues_event_min_datetime": "2015-02-05T14:56:54.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-25T09:29:52.000Z", "max_forks_repo_path": "example/lapack/slange_f.f90", "max_forks_repo_name": "t-sakashita/rokko", "max_forks_repo_head_hexsha": "ebd49e1198c4ec9e7612ad4a9806d16a4ff0bdc9", "max_forks_repo_licenses": ["BSL-1.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2015-06-16T04:22:23.000Z", "max_forks_repo_forks_event_max_datetime": "2019-06-01T07:10:01.000Z", "avg_line_length": 22.9230769231, "max_line_length": 54, "alphanum_fraction": 0.5234899329, "num_tokens": 228, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782094, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6733156490023631}} {"text": " INTEGER FUNCTION IFOLD(F,A,N)\t!\"Catamorphism\"...\n INTEGER F\t!We're working only with integers.\n EXTERNAL F\t!This is a function, not an array.\n INTEGER A(*)\t!An 1-D array, of unspecified size.\n INTEGER N\t!The number of elements.\n INTEGER I\t!A stepper.\n IFOLD = 0\t\t!A default value.\n IF (N.LE.0) RETURN\t!Dodge silly invocations.\n IFOLD = A(1)\t\t!The function is to have two arguments.\n IF (N.EQ.1) RETURN\t!So, if there is only one element, silly.\n DO I = 2,N\t\t!Otherwise, stutter along the array.\n IFOLD = F(IFOLD,A(I))\t\t!Applying the function.\n END DO\t\t\t!On to the next element.\n END FUNCTION IFOLD!Thus, F(A(1),A(2)), or F(F(A(1),A(2)),A(3)), or F(F(F(A(1),A(2)),A(3)),A(4)), etc.\n\n INTEGER FUNCTION IADD(I,J)\n INTEGER I,J\n IADD = I + J\n END FUNCTION IADD\n\n INTEGER FUNCTION IMUL(I,J)\n INTEGER I,J\n IMUL = I*J\n END FUNCTION IMUL\n\n INTEGER FUNCTION IDIV(I,J)\n INTEGER I,J\n IDIV = I/J\n END FUNCTION IDIV\n\n INTEGER FUNCTION IVID(I,J)\n INTEGER I,J\n IVID = J/I\n END FUNCTION IVID\n\n PROGRAM POKE\n INTEGER ENUFF\n PARAMETER (ENUFF = 6)\n INTEGER A(ENUFF)\n PARAMETER (A = (/1,2,3,4,5,6/))\n INTEGER MSG\n EXTERNAL IADD,IMUL,IDIV,IVID\t!Warn that these are the names of functions.\n\n MSG = 6\t!Standard output.\n WRITE (MSG,1) ENUFF,A\n 1 FORMAT ('To apply a function in the \"catamorphic\" style ',\n 1 \"to the \",I0,\" values \",/,(20I3))\n\n WRITE (MSG,*) \"Iadd\",IFOLD(IADD,A,ENUFF)\n WRITE (MSG,*) \"Imul\",IFOLD(IMUL,A,ENUFF)\n WRITE (MSG,*) \"Idiv\",IFOLD(IDIV,A,ENUFF)\n WRITE (MSG,*) \"Ivid\",IFOLD(IVID,A,ENUFF)\n END PROGRAM POKE\n", "meta": {"hexsha": "87476c9eb3b6671080d2ce3fa246ff9dc5f82688", "size": 1764, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Catamorphism/Fortran/catamorphism-2.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-05T13:42:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-05T13:42:20.000Z", "max_issues_repo_path": "Task/Catamorphism/Fortran/catamorphism-2.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Catamorphism/Fortran/catamorphism-2.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.6666666667, "max_line_length": 107, "alphanum_fraction": 0.5725623583, "num_tokens": 573, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.673315649002363}} {"text": " Program zppcon_example\n\n! ZPPCON Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_interfaces, Only: zlanhp, zppcon, zpptrf\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nin = 5, nout = 6\n! .. Local Scalars ..\n Real (Kind=dp) :: anorm, rcond\n Integer :: i, info, j, n\n Character (1) :: uplo\n! .. Local Arrays ..\n Complex (Kind=dp), Allocatable :: ap(:), work(:)\n Real (Kind=dp), Allocatable :: rwork(:)\n! .. Intrinsic Procedures ..\n Intrinsic :: epsilon\n! .. Executable Statements ..\n Write (nout, *) 'ZPPCON Example Program Results'\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n\n\n Allocate (ap(n*(n+1)/2), work(2*n), rwork(n))\n\n! Read A from data file\n\n Read (nin, *) uplo\n If (uplo=='U') Then\n Read (nin, *)((ap(i+j*(j-1)/2),j=i,n), i=1, n)\n Else If (uplo=='L') Then\n Read (nin, *)((ap(i+(2*n-j)*(j-1)/2),j=1,i), i=1, n)\n End If\n\n! Compute norm of A\n anorm = zlanhp('1-norm', uplo, n, ap, rwork)\n\n! Factorize A\n Call zpptrf(uplo, n, ap, info)\n\n Write (nout, *)\n If (info==0) Then\n\n! Estimate condition number\n\n Call zppcon(uplo, n, ap, anorm, rcond, work, rwork, info)\n\n If (rcond>=epsilon(1.0E0_dp)) Then\n Write (nout, 100) 'Estimate of condition number =', 1.0_dp/rcond\n Else\n Write (nout, *) 'A is singular to working precision'\n End If\n Else\n Write (nout, *) 'A is not positive definite'\n End If\n\n100 Format (1X, A, 1P, E10.2)\n End Program\n", "meta": {"hexsha": "567c10503fa0ba23747bf67cd3b449d5b949ab65", "size": 1870, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/zppcon_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/zppcon_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/zppcon_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 28.3333333333, "max_line_length": 90, "alphanum_fraction": 0.5593582888, "num_tokens": 591, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473614033683, "lm_q2_score": 0.7718435083355187, "lm_q1q2_score": 0.6733156479128085}} {"text": " Program zgglse_example\n\n! ZGGLSE Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use blas_interfaces, Only: dznrm2\n Use lapack_interfaces, Only: zgglse\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nb = 64, nin = 5, nout = 6\n! .. Local Scalars ..\n Real (Kind=dp) :: rnorm\n Integer :: i, info, lda, ldb, lwork, m, n, p\n! .. Local Arrays ..\n Complex (Kind=dp), Allocatable :: a(:, :), b(:, :), c(:), d(:), work(:), &\n x(:)\n! .. Executable Statements ..\n Write (nout, *) 'ZGGLSE Example Program Results'\n Write (nout, *)\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) m, n, p\n lda = m\n ldb = p\n lwork = p + n + nb*(m+n)\n Allocate (a(lda,n), b(ldb,n), c(m), d(p), work(lwork), x(n))\n\n! Read A, B, C and D from data file\n\n Read (nin, *)(a(i,1:n), i=1, m)\n Read (nin, *)(b(i,1:n), i=1, p)\n Read (nin, *) c(1:m)\n Read (nin, *) d(1:p)\n\n! Solve the equality-constrained least squares problem\n\n! minimize ||c - A*x|| (in the 2-norm) subject to B*x = D\n\n Call zgglse(m, n, p, a, lda, b, ldb, c, d, x, work, lwork, info)\n\n! Print least squares solution\n\n Write (nout, *) 'Constrained least squares solution'\n Write (nout, 100) x(1:n)\n\n! Compute the square root of the residual sum of squares\n\n rnorm = dznrm2(m-n+p, c(n-p+1), 1)\n Write (nout, *)\n Write (nout, *) 'Square root of the residual sum of squares'\n Write (nout, 110) rnorm\n\n100 Format (4(' (',F7.4,',',F7.4,')',:))\n110 Format (1X, 1P, E10.2)\n End Program\n", "meta": {"hexsha": "e56da587b7aded20ce1310754ec43754f2f6ce76", "size": 1870, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/zgglse_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/zgglse_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/zgglse_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 30.1612903226, "max_line_length": 90, "alphanum_fraction": 0.5550802139, "num_tokens": 611, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473614033684, "lm_q2_score": 0.7718434978390746, "lm_q1q2_score": 0.6733156387562632}} {"text": "!*==zgesvdx.f90 processed by SPAG 7.51RB at 20:08 on 3 Mar 2022\n!> \\brief ZGESVDX computes the singular value decomposition (SVD) for GE matrices\n!\n! =========== DOCUMENTATION ===========\n!\n! Online html documentation available at\n! http://www.netlib.org/lapack/explore-html/\n!\n!> \\htmlonly\n!> Download ZGESVDX + dependencies\n!> \n!> [TGZ]\n!> \n!> [ZIP]\n!> \n!> [TXT]\n!> \\endhtmlonly\n!\n! Definition:\n! ===========\n!\n! SUBROUTINE ZGESVDX( JOBU, JOBVT, RANGE, M, N, A, LDA, VL, VU,\n! $ IL, IU, NS, S, U, LDU, VT, LDVT, WORK,\n! $ LWORK, RWORK, IWORK, INFO )\n!\n!\n! .. Scalar Arguments ..\n! CHARACTER JOBU, JOBVT, RANGE\n! INTEGER IL, INFO, IU, LDA, LDU, LDVT, LWORK, M, N, NS\n! DOUBLE PRECISION VL, VU\n! ..\n! .. Array Arguments ..\n! INTEGER IWORK( * )\n! DOUBLE PRECISION S( * ), RWORK( * )\n! COMPLEX*16 A( LDA, * ), U( LDU, * ), VT( LDVT, * ),\n! $ WORK( * )\n! ..\n!\n!\n!> \\par Purpose:\n! =============\n!>\n!> \\verbatim\n!>\n!> ZGESVDX computes the singular value decomposition (SVD) of a complex\n!> M-by-N matrix A, optionally computing the left and/or right singular\n!> vectors. The SVD is written\n!>\n!> A = U * SIGMA * transpose(V)\n!>\n!> where SIGMA is an M-by-N matrix which is zero except for its\n!> min(m,n) diagonal elements, U is an M-by-M unitary matrix, and\n!> V is an N-by-N unitary matrix. The diagonal elements of SIGMA\n!> are the singular values of A; they are real and non-negative, and\n!> are returned in descending order. The first min(m,n) columns of\n!> U and V are the left and right singular vectors of A.\n!>\n!> ZGESVDX uses an eigenvalue problem for obtaining the SVD, which\n!> allows for the computation of a subset of singular values and\n!> vectors. See DBDSVDX for details.\n!>\n!> Note that the routine returns V**T, not V.\n!> \\endverbatim\n!\n! Arguments:\n! ==========\n!\n!> \\param[in] JOBU\n!> \\verbatim\n!> JOBU is CHARACTER*1\n!> Specifies options for computing all or part of the matrix U:\n!> = 'V': the first min(m,n) columns of U (the left singular\n!> vectors) or as specified by RANGE are returned in\n!> the array U;\n!> = 'N': no columns of U (no left singular vectors) are\n!> computed.\n!> \\endverbatim\n!>\n!> \\param[in] JOBVT\n!> \\verbatim\n!> JOBVT is CHARACTER*1\n!> Specifies options for computing all or part of the matrix\n!> V**T:\n!> = 'V': the first min(m,n) rows of V**T (the right singular\n!> vectors) or as specified by RANGE are returned in\n!> the array VT;\n!> = 'N': no rows of V**T (no right singular vectors) are\n!> computed.\n!> \\endverbatim\n!>\n!> \\param[in] RANGE\n!> \\verbatim\n!> RANGE is CHARACTER*1\n!> = 'A': all singular values will be found.\n!> = 'V': all singular values in the half-open interval (VL,VU]\n!> will be found.\n!> = 'I': the IL-th through IU-th singular values will be found.\n!> \\endverbatim\n!>\n!> \\param[in] M\n!> \\verbatim\n!> M is INTEGER\n!> The number of rows of the input matrix A. M >= 0.\n!> \\endverbatim\n!>\n!> \\param[in] N\n!> \\verbatim\n!> N is INTEGER\n!> The number of columns of the input matrix A. N >= 0.\n!> \\endverbatim\n!>\n!> \\param[in,out] A\n!> \\verbatim\n!> A is COMPLEX*16 array, dimension (LDA,N)\n!> On entry, the M-by-N matrix A.\n!> On exit, the contents of A are destroyed.\n!> \\endverbatim\n!>\n!> \\param[in] LDA\n!> \\verbatim\n!> LDA is INTEGER\n!> The leading dimension of the array A. LDA >= max(1,M).\n!> \\endverbatim\n!>\n!> \\param[in] VL\n!> \\verbatim\n!> VL is DOUBLE PRECISION\n!> If RANGE='V', the lower bound of the interval to\n!> be searched for singular values. VU > VL.\n!> Not referenced if RANGE = 'A' or 'I'.\n!> \\endverbatim\n!>\n!> \\param[in] VU\n!> \\verbatim\n!> VU is DOUBLE PRECISION\n!> If RANGE='V', the upper bound of the interval to\n!> be searched for singular values. VU > VL.\n!> Not referenced if RANGE = 'A' or 'I'.\n!> \\endverbatim\n!>\n!> \\param[in] IL\n!> \\verbatim\n!> IL is INTEGER\n!> If RANGE='I', the index of the\n!> smallest singular value to be returned.\n!> 1 <= IL <= IU <= min(M,N), if min(M,N) > 0.\n!> Not referenced if RANGE = 'A' or 'V'.\n!> \\endverbatim\n!>\n!> \\param[in] IU\n!> \\verbatim\n!> IU is INTEGER\n!> If RANGE='I', the index of the\n!> largest singular value to be returned.\n!> 1 <= IL <= IU <= min(M,N), if min(M,N) > 0.\n!> Not referenced if RANGE = 'A' or 'V'.\n!> \\endverbatim\n!>\n!> \\param[out] NS\n!> \\verbatim\n!> NS is INTEGER\n!> The total number of singular values found,\n!> 0 <= NS <= min(M,N).\n!> If RANGE = 'A', NS = min(M,N); if RANGE = 'I', NS = IU-IL+1.\n!> \\endverbatim\n!>\n!> \\param[out] S\n!> \\verbatim\n!> S is DOUBLE PRECISION array, dimension (min(M,N))\n!> The singular values of A, sorted so that S(i) >= S(i+1).\n!> \\endverbatim\n!>\n!> \\param[out] U\n!> \\verbatim\n!> U is COMPLEX*16 array, dimension (LDU,UCOL)\n!> If JOBU = 'V', U contains columns of U (the left singular\n!> vectors, stored columnwise) as specified by RANGE; if\n!> JOBU = 'N', U is not referenced.\n!> Note: The user must ensure that UCOL >= NS; if RANGE = 'V',\n!> the exact value of NS is not known in advance and an upper\n!> bound must be used.\n!> \\endverbatim\n!>\n!> \\param[in] LDU\n!> \\verbatim\n!> LDU is INTEGER\n!> The leading dimension of the array U. LDU >= 1; if\n!> JOBU = 'V', LDU >= M.\n!> \\endverbatim\n!>\n!> \\param[out] VT\n!> \\verbatim\n!> VT is COMPLEX*16 array, dimension (LDVT,N)\n!> If JOBVT = 'V', VT contains the rows of V**T (the right singular\n!> vectors, stored rowwise) as specified by RANGE; if JOBVT = 'N',\n!> VT is not referenced.\n!> Note: The user must ensure that LDVT >= NS; if RANGE = 'V',\n!> the exact value of NS is not known in advance and an upper\n!> bound must be used.\n!> \\endverbatim\n!>\n!> \\param[in] LDVT\n!> \\verbatim\n!> LDVT is INTEGER\n!> The leading dimension of the array VT. LDVT >= 1; if\n!> JOBVT = 'V', LDVT >= NS (see above).\n!> \\endverbatim\n!>\n!> \\param[out] WORK\n!> \\verbatim\n!> WORK is COMPLEX*16 array, dimension (MAX(1,LWORK))\n!> On exit, if INFO = 0, WORK(1) returns the optimal LWORK;\n!> \\endverbatim\n!>\n!> \\param[in] LWORK\n!> \\verbatim\n!> LWORK is INTEGER\n!> The dimension of the array WORK.\n!> LWORK >= MAX(1,MIN(M,N)*(MIN(M,N)+4)) for the paths (see\n!> comments inside the code):\n!> - PATH 1 (M much larger than N)\n!> - PATH 1t (N much larger than M)\n!> LWORK >= MAX(1,MIN(M,N)*2+MAX(M,N)) for the other paths.\n!> For good performance, LWORK should generally be larger.\n!>\n!> If LWORK = -1, then a workspace query is assumed; the routine\n!> only calculates the optimal size of the WORK array, returns\n!> this value as the first entry of the WORK array, and no error\n!> message related to LWORK is issued by XERBLA.\n!> \\endverbatim\n!>\n!> \\param[out] RWORK\n!> \\verbatim\n!> RWORK is DOUBLE PRECISION array, dimension (MAX(1,LRWORK))\n!> LRWORK >= MIN(M,N)*(MIN(M,N)*2+15*MIN(M,N)).\n!> \\endverbatim\n!>\n!> \\param[out] IWORK\n!> \\verbatim\n!> IWORK is INTEGER array, dimension (12*MIN(M,N))\n!> If INFO = 0, the first NS elements of IWORK are zero. If INFO > 0,\n!> then IWORK contains the indices of the eigenvectors that failed\n!> to converge in DBDSVDX/DSTEVX.\n!> \\endverbatim\n!>\n!> \\param[out] INFO\n!> \\verbatim\n!> INFO is INTEGER\n!> = 0: successful exit\n!> < 0: if INFO = -i, the i-th argument had an illegal value\n!> > 0: if INFO = i, then i eigenvectors failed to converge\n!> in DBDSVDX/DSTEVX.\n!> if INFO = N*2 + 1, an internal error occurred in\n!> DBDSVDX\n!> \\endverbatim\n!\n! Authors:\n! ========\n!\n!> \\author Univ. of Tennessee\n!> \\author Univ. of California Berkeley\n!> \\author Univ. of Colorado Denver\n!> \\author NAG Ltd.\n!\n!> \\date June 2016\n!\n!> \\ingroup complex16GEsing\n!\n! =====================================================================\n SUBROUTINE ZGESVDX(Jobu,Jobvt,Range,M,N,A,Lda,Vl,Vu,Il,Iu,Ns,S,U, &\n & Ldu,Vt,Ldvt,Work,Lwork,Rwork,Iwork,Info)\n IMPLICIT NONE\n!*--ZGESVDX273\n!\n! -- LAPACK driver routine (version 3.8.0) --\n! -- LAPACK is a software package provided by Univ. of Tennessee, --\n! -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n! June 2016\n!\n! .. Scalar Arguments ..\n CHARACTER Jobu , Jobvt , Range\n INTEGER Il , Info , Iu , Lda , Ldu , Ldvt , Lwork , M , N , Ns\n DOUBLE PRECISION Vl , Vu\n! ..\n! .. Array Arguments ..\n INTEGER Iwork(*)\n DOUBLE PRECISION S(*) , Rwork(*)\n COMPLEX*16 A(Lda,*) , U(Ldu,*) , Vt(Ldvt,*) , Work(*)\n! ..\n!\n! =====================================================================\n!\n! .. Parameters ..\n COMPLEX*16 CZERO\n PARAMETER (CZERO=(0.0D0,0.0D0))\n DOUBLE PRECISION ZERO , ONE\n PARAMETER (ZERO=0.0D0,ONE=1.0D0)\n! ..\n! .. Local Scalars ..\n CHARACTER jobz , rngtgk\n LOGICAL alls , inds , lquery , vals , wantu , wantvt\n INTEGER i , id , ie , ierr , ilqf , iltgk , iqrf , iscl , itau , &\n & itaup , itauq , itemp , itempr , itgkz , iutgk , j , k , &\n & maxwrk , minmn , minwrk , mnthr\n DOUBLE PRECISION abstol , anrm , bignum , eps , smlnum\n! ..\n! .. Local Arrays ..\n DOUBLE PRECISION dum(1)\n! ..\n! .. External Subroutines ..\n EXTERNAL ZGEBRD , ZGELQF , ZGEQRF , ZLASCL , ZLASET , ZLACPY , &\n & ZUNMLQ , ZUNMBR , ZUNMQR , DBDSVDX , DLASCL , XERBLA\n! ..\n! .. External Functions ..\n LOGICAL LSAME\n INTEGER ILAENV\n DOUBLE PRECISION DLAMCH , ZLANGE\n EXTERNAL LSAME , ILAENV , DLAMCH , ZLANGE\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC MAX , MIN , SQRT\n! ..\n! .. Executable Statements ..\n!\n! Test the input arguments.\n!\n Ns = 0\n Info = 0\n abstol = 2*DLAMCH('S')\n lquery = (Lwork==-1)\n minmn = MIN(M,N)\n \n wantu = LSAME(Jobu,'V')\n wantvt = LSAME(Jobvt,'V')\n IF ( wantu .OR. wantvt ) THEN\n jobz = 'V'\n ELSE\n jobz = 'N'\n ENDIF\n alls = LSAME(Range,'A')\n vals = LSAME(Range,'V')\n inds = LSAME(Range,'I')\n!\n Info = 0\n IF ( .NOT.LSAME(Jobu,'V') .AND. .NOT.LSAME(Jobu,'N') ) THEN\n Info = -1\n ELSEIF ( .NOT.LSAME(Jobvt,'V') .AND. .NOT.LSAME(Jobvt,'N') ) THEN\n Info = -2\n ELSEIF ( .NOT.(alls .OR. vals .OR. inds) ) THEN\n Info = -3\n ELSEIF ( M<0 ) THEN\n Info = -4\n ELSEIF ( N<0 ) THEN\n Info = -5\n ELSEIF ( M>Lda ) THEN\n Info = -7\n ELSEIF ( minmn>0 ) THEN\n IF ( vals ) THEN\n IF ( VlMAX(1,minmn) ) THEN\n Info = -10\n ELSEIF ( Iuminmn ) THEN\n Info = -11\n ENDIF\n ENDIF\n IF ( Info==0 ) THEN\n IF ( wantu .AND. Ldu0 ) THEN\n IF ( M>=N ) THEN\n mnthr = ILAENV(6,'ZGESVD',Jobu//Jobvt,M,N,0,0)\n IF ( M>=mnthr ) THEN\n!\n! Path 1 (M much larger than N)\n!\n minwrk = N*(N+5)\n maxwrk = N + N*ILAENV(1,'ZGEQRF',' ',M,N,-1,-1)\n maxwrk = MAX(maxwrk, &\n & N*N+2*N+2*N*ILAENV(1,'ZGEBRD',' ',N,N,-1,-1))\n IF ( wantu .OR. wantvt ) &\n & maxwrk = MAX(maxwrk,N*N+2*N+N*ILAENV(1,'ZUNMQR', &\n & 'LN',N,N,N,-1))\n ELSE\n!\n! Path 2 (M at least N, but not much larger)\n!\n minwrk = 3*N + M\n maxwrk = 2*N + (M+N)*ILAENV(1,'ZGEBRD',' ',M,N,-1,-1)\n IF ( wantu .OR. wantvt ) &\n & maxwrk = MAX(maxwrk,2*N+N*ILAENV(1,'ZUNMQR','LN',&\n & N,N,N,-1))\n ENDIF\n ELSE\n mnthr = ILAENV(6,'ZGESVD',Jobu//Jobvt,M,N,0,0)\n IF ( N>=mnthr ) THEN\n!\n! Path 1t (N much larger than M)\n!\n minwrk = M*(M+5)\n maxwrk = M + M*ILAENV(1,'ZGELQF',' ',M,N,-1,-1)\n maxwrk = MAX(maxwrk, &\n & M*M+2*M+2*M*ILAENV(1,'ZGEBRD',' ',M,M,-1,-1))\n IF ( wantu .OR. wantvt ) &\n & maxwrk = MAX(maxwrk,M*M+2*M+M*ILAENV(1,'ZUNMQR', &\n & 'LN',M,M,M,-1))\n ELSE\n!\n! Path 2t (N greater than M, but not much larger)\n!\n!\n minwrk = 3*M + N\n maxwrk = 2*M + (M+N)*ILAENV(1,'ZGEBRD',' ',M,N,-1,-1)\n IF ( wantu .OR. wantvt ) &\n & maxwrk = MAX(maxwrk,2*M+M*ILAENV(1,'ZUNMQR','LN',&\n & M,M,M,-1))\n ENDIF\n ENDIF\n ENDIF\n maxwrk = MAX(maxwrk,minwrk)\n Work(1) = DCMPLX(DBLE(maxwrk),ZERO)\n!\n IF ( LworkZERO .AND. anrmbignum ) THEN\n iscl = 1\n CALL ZLASCL('G',0,0,anrm,bignum,M,N,A,Lda,Info)\n ENDIF\n!\n IF ( M>=N ) THEN\n!\n! A has at least as many rows as columns. If A has sufficiently\n! more rows than columns, first reduce A using the QR\n! decomposition.\n!\n IF ( M>=mnthr ) THEN\n!\n! Path 1 (M much larger than N):\n! A = Q * R = Q * ( QB * B * PB**T )\n! = Q * ( QB * ( UB * S * VB**T ) * PB**T )\n! U = Q * QB * UB; V**T = VB**T * PB**T\n!\n! Compute A=Q*R\n! (Workspace: need 2*N, prefer N+N*NB)\n!\n itau = 1\n itemp = itau + N\n CALL ZGEQRF(M,N,A,Lda,Work(itau),Work(itemp),Lwork-itemp+1, &\n & Info)\n!\n! Copy R into WORK and bidiagonalize it:\n! (Workspace: need N*N+3*N, prefer N*N+N+2*N*NB)\n!\n iqrf = itemp\n itauq = itemp + N*N\n itaup = itauq + N\n itemp = itaup + N\n id = 1\n ie = id + N\n itgkz = ie + N\n CALL ZLACPY('U',N,N,A,Lda,Work(iqrf),N)\n CALL ZLASET('L',N-1,N-1,CZERO,CZERO,Work(iqrf+1),N)\n CALL ZGEBRD(N,N,Work(iqrf),N,Rwork(id),Rwork(ie),Work(itauq)&\n & ,Work(itaup),Work(itemp),Lwork-itemp+1,Info)\n itempr = itgkz + N*(N*2+1)\n!\n! Solve eigenvalue problem TGK*Z=Z*S.\n! (Workspace: need 2*N*N+14*N)\n!\n CALL DBDSVDX('U',jobz,rngtgk,N,Rwork(id),Rwork(ie),Vl,Vu, &\n & iltgk,iutgk,Ns,S,Rwork(itgkz),N*2,Rwork(itempr)&\n & ,Iwork,Info)\n!\n! If needed, compute left singular vectors.\n!\n IF ( wantu ) THEN\n k = itgkz\n DO i = 1 , Ns\n DO j = 1 , N\n U(j,i) = DCMPLX(Rwork(k),ZERO)\n k = k + 1\n ENDDO\n k = k + N\n ENDDO\n CALL ZLASET('A',M-N,Ns,CZERO,CZERO,U(N+1,1),Ldu)\n!\n! Call ZUNMBR to compute QB*UB.\n! (Workspace in WORK( ITEMP ): need N, prefer N*NB)\n!\n CALL ZUNMBR('Q','L','N',N,Ns,N,Work(iqrf),N,Work(itauq), &\n & U,Ldu,Work(itemp),Lwork-itemp+1,Info)\n!\n! Call ZUNMQR to compute Q*(QB*UB).\n! (Workspace in WORK( ITEMP ): need N, prefer N*NB)\n!\n CALL ZUNMQR('L','N',M,Ns,N,A,Lda,Work(itau),U,Ldu, &\n & Work(itemp),Lwork-itemp+1,Info)\n ENDIF\n!\n! If needed, compute right singular vectors.\n!\n IF ( wantvt ) THEN\n k = itgkz + N\n DO i = 1 , Ns\n DO j = 1 , N\n Vt(i,j) = DCMPLX(Rwork(k),ZERO)\n k = k + 1\n ENDDO\n k = k + N\n ENDDO\n!\n! Call ZUNMBR to compute VB**T * PB**T\n! (Workspace in WORK( ITEMP ): need N, prefer N*NB)\n!\n CALL ZUNMBR('P','R','C',Ns,N,N,Work(iqrf),N,Work(itaup), &\n & Vt,Ldvt,Work(itemp),Lwork-itemp+1,Info)\n ENDIF\n ELSE\n!\n! Path 2 (M at least N, but not much larger)\n! Reduce A to bidiagonal form without QR decomposition\n! A = QB * B * PB**T = QB * ( UB * S * VB**T ) * PB**T\n! U = QB * UB; V**T = VB**T * PB**T\n!\n! Bidiagonalize A\n! (Workspace: need 2*N+M, prefer 2*N+(M+N)*NB)\n!\n itauq = 1\n itaup = itauq + N\n itemp = itaup + N\n id = 1\n ie = id + N\n itgkz = ie + N\n CALL ZGEBRD(M,N,A,Lda,Rwork(id),Rwork(ie),Work(itauq), &\n & Work(itaup),Work(itemp),Lwork-itemp+1,Info)\n itempr = itgkz + N*(N*2+1)\n!\n! Solve eigenvalue problem TGK*Z=Z*S.\n! (Workspace: need 2*N*N+14*N)\n!\n CALL DBDSVDX('U',jobz,rngtgk,N,Rwork(id),Rwork(ie),Vl,Vu, &\n & iltgk,iutgk,Ns,S,Rwork(itgkz),N*2,Rwork(itempr)&\n & ,Iwork,Info)\n!\n! If needed, compute left singular vectors.\n!\n IF ( wantu ) THEN\n k = itgkz\n DO i = 1 , Ns\n DO j = 1 , N\n U(j,i) = DCMPLX(Rwork(k),ZERO)\n k = k + 1\n ENDDO\n k = k + N\n ENDDO\n CALL ZLASET('A',M-N,Ns,CZERO,CZERO,U(N+1,1),Ldu)\n!\n! Call ZUNMBR to compute QB*UB.\n! (Workspace in WORK( ITEMP ): need N, prefer N*NB)\n!\n CALL ZUNMBR('Q','L','N',M,Ns,N,A,Lda,Work(itauq),U,Ldu, &\n & Work(itemp),Lwork-itemp+1,ierr)\n ENDIF\n!\n! If needed, compute right singular vectors.\n!\n IF ( wantvt ) THEN\n k = itgkz + N\n DO i = 1 , Ns\n DO j = 1 , N\n Vt(i,j) = DCMPLX(Rwork(k),ZERO)\n k = k + 1\n ENDDO\n k = k + N\n ENDDO\n!\n! Call ZUNMBR to compute VB**T * PB**T\n! (Workspace in WORK( ITEMP ): need N, prefer N*NB)\n!\n CALL ZUNMBR('P','R','C',Ns,N,N,A,Lda,Work(itaup),Vt,Ldvt,&\n & Work(itemp),Lwork-itemp+1,ierr)\n ENDIF\n ENDIF\n!\n! A has more columns than rows. If A has sufficiently more\n! columns than rows, first reduce A using the LQ decomposition.\n!\n ELSEIF ( N>=mnthr ) THEN\n!\n! Path 1t (N much larger than M):\n! A = L * Q = ( QB * B * PB**T ) * Q\n! = ( QB * ( UB * S * VB**T ) * PB**T ) * Q\n! U = QB * UB ; V**T = VB**T * PB**T * Q\n!\n! Compute A=L*Q\n! (Workspace: need 2*M, prefer M+M*NB)\n!\n itau = 1\n itemp = itau + M\n CALL ZGELQF(M,N,A,Lda,Work(itau),Work(itemp),Lwork-itemp+1, &\n & Info)\n \n! Copy L into WORK and bidiagonalize it:\n! (Workspace in WORK( ITEMP ): need M*M+3*M, prefer M*M+M+2*M*NB)\n!\n ilqf = itemp\n itauq = ilqf + M*M\n itaup = itauq + M\n itemp = itaup + M\n id = 1\n ie = id + M\n itgkz = ie + M\n CALL ZLACPY('L',M,M,A,Lda,Work(ilqf),M)\n CALL ZLASET('U',M-1,M-1,CZERO,CZERO,Work(ilqf+M),M)\n CALL ZGEBRD(M,M,Work(ilqf),M,Rwork(id),Rwork(ie),Work(itauq), &\n & Work(itaup),Work(itemp),Lwork-itemp+1,Info)\n itempr = itgkz + M*(M*2+1)\n!\n! Solve eigenvalue problem TGK*Z=Z*S.\n! (Workspace: need 2*M*M+14*M)\n!\n CALL DBDSVDX('U',jobz,rngtgk,M,Rwork(id),Rwork(ie),Vl,Vu,iltgk,&\n & iutgk,Ns,S,Rwork(itgkz),M*2,Rwork(itempr),Iwork, &\n & Info)\n!\n! If needed, compute left singular vectors.\n!\n IF ( wantu ) THEN\n k = itgkz\n DO i = 1 , Ns\n DO j = 1 , M\n U(j,i) = DCMPLX(Rwork(k),ZERO)\n k = k + 1\n ENDDO\n k = k + M\n ENDDO\n!\n! Call ZUNMBR to compute QB*UB.\n! (Workspace in WORK( ITEMP ): need M, prefer M*NB)\n!\n CALL ZUNMBR('Q','L','N',M,Ns,M,Work(ilqf),M,Work(itauq),U, &\n & Ldu,Work(itemp),Lwork-itemp+1,Info)\n ENDIF\n!\n! If needed, compute right singular vectors.\n!\n IF ( wantvt ) THEN\n k = itgkz + M\n DO i = 1 , Ns\n DO j = 1 , M\n Vt(i,j) = DCMPLX(Rwork(k),ZERO)\n k = k + 1\n ENDDO\n k = k + M\n ENDDO\n CALL ZLASET('A',Ns,N-M,CZERO,CZERO,Vt(1,M+1),Ldvt)\n!\n! Call ZUNMBR to compute (VB**T)*(PB**T)\n! (Workspace in WORK( ITEMP ): need M, prefer M*NB)\n!\n CALL ZUNMBR('P','R','C',Ns,M,M,Work(ilqf),M,Work(itaup),Vt, &\n & Ldvt,Work(itemp),Lwork-itemp+1,Info)\n!\n! Call ZUNMLQ to compute ((VB**T)*(PB**T))*Q.\n! (Workspace in WORK( ITEMP ): need M, prefer M*NB)\n!\n CALL ZUNMLQ('R','N',Ns,N,M,A,Lda,Work(itau),Vt,Ldvt, &\n & Work(itemp),Lwork-itemp+1,Info)\n ENDIF\n ELSE\n!\n! Path 2t (N greater than M, but not much larger)\n! Reduce to bidiagonal form without LQ decomposition\n! A = QB * B * PB**T = QB * ( UB * S * VB**T ) * PB**T\n! U = QB * UB; V**T = VB**T * PB**T\n!\n! Bidiagonalize A\n! (Workspace: need 2*M+N, prefer 2*M+(M+N)*NB)\n!\n itauq = 1\n itaup = itauq + M\n itemp = itaup + M\n id = 1\n ie = id + M\n itgkz = ie + M\n CALL ZGEBRD(M,N,A,Lda,Rwork(id),Rwork(ie),Work(itauq), &\n & Work(itaup),Work(itemp),Lwork-itemp+1,Info)\n itempr = itgkz + M*(M*2+1)\n!\n! Solve eigenvalue problem TGK*Z=Z*S.\n! (Workspace: need 2*M*M+14*M)\n!\n CALL DBDSVDX('L',jobz,rngtgk,M,Rwork(id),Rwork(ie),Vl,Vu,iltgk,&\n & iutgk,Ns,S,Rwork(itgkz),M*2,Rwork(itempr),Iwork, &\n & Info)\n!\n! If needed, compute left singular vectors.\n!\n IF ( wantu ) THEN\n k = itgkz\n DO i = 1 , Ns\n DO j = 1 , M\n U(j,i) = DCMPLX(Rwork(k),ZERO)\n k = k + 1\n ENDDO\n k = k + M\n ENDDO\n!\n! Call ZUNMBR to compute QB*UB.\n! (Workspace in WORK( ITEMP ): need M, prefer M*NB)\n!\n CALL ZUNMBR('Q','L','N',M,Ns,N,A,Lda,Work(itauq),U,Ldu, &\n & Work(itemp),Lwork-itemp+1,Info)\n ENDIF\n!\n! If needed, compute right singular vectors.\n!\n IF ( wantvt ) THEN\n k = itgkz + M\n DO i = 1 , Ns\n DO j = 1 , M\n Vt(i,j) = DCMPLX(Rwork(k),ZERO)\n k = k + 1\n ENDDO\n k = k + M\n ENDDO\n CALL ZLASET('A',Ns,N-M,CZERO,CZERO,Vt(1,M+1),Ldvt)\n!\n! Call ZUNMBR to compute VB**T * PB**T\n! (Workspace in WORK( ITEMP ): need M, prefer M*NB)\n!\n CALL ZUNMBR('P','R','C',Ns,N,M,A,Lda,Work(itaup),Vt,Ldvt, &\n & Work(itemp),Lwork-itemp+1,Info)\n ENDIF\n ENDIF\n!\n! Undo scaling if necessary\n!\n IF ( iscl==1 ) THEN\n IF ( anrm>bignum ) CALL DLASCL('G',0,0,bignum,anrm,minmn,1,S, &\n & minmn,Info)\n IF ( anrm1)\n! corr_error Error of the admittance (only when K>1)\n!\n! OPTIONAL (IN)\n! mtdef 1 (default): Calculate multitaper cross-spectral\n! estimates, and use these to calculate a single\n! admittance and correlations.\n! 2: Calculate the admittance and correlation using\n! each individual taper, and then average these to\n! get the admittance and correlation.\n! taper_wt Weights to be applied to the spectral estimates.\n! This can only be used when MTDEF is 1.\n! k1linsig: If present and equal to 1, the uncertainty in the\n! admittance will be calculated by assuming the\n! gravity and topography coefficients are linearly\n! correlated, and that any lack of correlation is the\n! result of uncorrelated noise. This should only be\n! used when one expects the gravity and topography\n! to be linearly correlated and when only a single\n! taper is being used. This should not be used with a\n! Forsyth type model that predicts a less than 1\n! correlation coefficient. This is the square root\n! of eq. 33 of Simons et al. 1997.\n!\n! OPTIONAL (OUT)\n! exitstatus If present, instead of executing a STOP when an error\n! is encountered, the variable exitstatus will be\n! returned describing the error.\n! 0 = No errors;\n! 1 = Improper dimensions of input array;\n! 2 = Improper bounds for input variable;\n! 3 = Error allocating memory;\n! 4 = File IO error.\n!\n! Notes:\n! 1. The units of the output admittance will correspond to the units of\n! the spherical harmonic coefficients. If gravity/topography admittances\n! are desired, then either the gravity coefficients should be multiplied\n! by G M (l+1) * (r0/r)**(l+2) / r0**2 before calling this routine, or\n! the admittances should be multiplied by this factor afterwards.\n!\n! 2. The correlation is defined as Sgt / sqrt(Sgg Stt), which varies\n! between -1 and 1. To obtain the \"coherence\" (which is also sometimes\n! referred to as the \"coherence squared\"), just square this number.\n!\n! Copyright (c) 2005-2019, SHTOOLS\n! All rights reserved.\n!\n!------------------------------------------------------------------------------\n use SHTOOLS, only: djpi2, SHRotateRealCoef, &\n SHCrossPowerSpectrum, SHPowerSpectrum, MakeGridGLQ, &\n SHGLQ, SHExpandGLQ\n use ftypes\n\n implicit none\n\n real(dp), intent(in) :: tapers(:,:), lat, lon, gilm(:,:,:), tilm(:,:,:)\n integer(int32), intent(in) :: lwin, lmax, K, taper_order(:)\n real(dp), intent(out) :: admit(:), corr(:)\n real(dp), intent(out), optional :: admit_error(:), corr_error(:)\n integer(int32), intent(in), optional :: mtdef, k1linsig\n real(dp), intent(in), optional :: taper_wt(:)\n integer(int32), intent(out), optional :: exitstatus\n integer(int32) :: lmaxwin, l, def, astat(9), phase, norm, i, nlat, nlong\n integer(int32), save :: first = 1, lmaxwin_last = -1, lwin_last = -1\n real(dp) :: pi, g_power(2,lwin+lmax+1), t_power(2,lwin+lmax+1), &\n gt_power(2,lwin+lmax+1), x(3), sgt(lmax-lwin+1, K), &\n sgg(lmax-lwin+1, K), stt(lmax-lwin+1, K), &\n admit_k(lmax-lwin+1, K), corr_k(lmax-lwin+1, K), factor\n real(dp), allocatable :: shwin(:,:,:), shwinrot(:,:,:), shloc_g(:,:,:), &\n shloc_t(:,:,:), gridtglq(:,:), gridgglq(:,:), &\n gridwinglq(:,:), temp(:,:)\n real(dp), allocatable, save :: dj(:,:,:), zero(:), w(:)\n\n!$OMP threadprivate(first, lmaxwin_last, lwin_last, dj)\n\n if (present(exitstatus)) exitstatus = 0\n\n phase = 1\n norm = 1\n\n pi = acos(-1.0_dp)\n lmaxwin = lmax + lwin\n\n if (present(k1linsig) .and. K /= 1) then\n if (k1linsig == 1) then\n print*, \"Error --- SHlocalizedAdmitCorr\"\n print*, \"If K1LINSIG is present and equal to 1, K must be \" // &\n \"equal to 1.\"\n print*, \"Input value of K1LINSIG is \", k1linsig\n if (present(exitstatus)) then\n exitstatus = 2\n return\n else\n stop\n end if\n\n end if\n\n end if\n\n if (size(admit) < lmax-lwin+1) then\n print*, \"Error --- SHLocalizedAdmitCorr\"\n print*, \"ADMIT must be dimensioned as (LMAX-LWIN+1) where \" // &\n \"LMAX and LWIN are \", lmax, lwin\n print*, \"Input array is dimensioned \", size(admit)\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n else if (size(corr) < lmax-lwin+1) then\n print*, \"Error --- SHLocalizedAdmitCorr\"\n print*, \"CORR must be dimensioned as (LMAX-LWIN+1) where \" // &\n \"LMAX and LWIN are \", lmax, lwin\n print*, \"Input array is dimensioned \", size(corr)\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n else if (size(tapers(:,1)) < lwin+1 .or. size(tapers(1,:)) < K) then\n print*, \"Error --- SHLocalizedAdmitCorr\"\n print*, \"TAPERS must be dimensioned as (LWIN+1, K) where \" // &\n \"LWIN and K are \", lwin, K\n print*, \"Iinput array is dimensioned as \", size(tapers(:,1)), &\n size(tapers(1,:))\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n else if (size(taper_order) < K ) then\n print*, \"Error --- SHLocalizedAdmitCorr\"\n print*, \"TAPER_ORDER must be dimensioned as (K) where K is \", K\n print*, \"Input array is dimensioned \", size(taper_order)\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n else if (size(gilm(:,1,1)) < 2 .or. size(gilm(1,:,1)) < lmax+1 .or. &\n size(gilm(1,1,:)) < lmax+1) then\n print*, \"Error --- SHLocalizedAdmitCorr\"\n print*, \"GILM must be dimensioned as (2, LMAX+1, LMAX+1) \" // &\n \"where LMAX is \", lmax\n print*, \"Input array is dimensioned \", size(gilm(:,1,1)), &\n size(gilm(1,:,1)), size(gilm(1,1,:))\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n else if (size(tilm(:,1,1)) < 2 .or. size(tilm(1,:,1)) < lmax+1 .or. &\n size(tilm(1,1,:)) < lmax+1) then\n print*, \"Error --- SHLocalizedAdmitCorr\"\n print*, \"TILM must be dimensioned as (2, LMAX+1, LMAX+1) \" // & \n \"where LMAX is \", lmax\n print*, \"Input array is dimensioned \", size(tilm(:,1,1)), &\n size(tilm(1,:,1)), size(tilm(1,1,:))\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n end if\n\n if (present(admit_error)) then\n if (size(admit_error) < lmax - lwin+1) then\n print*, \"Error ---SHLocalizedAdmitCorr\"\n print*, \"ADMIT_ERROR must be dimensioned as (LMAX-LWIN+1) \" // &\n \"where LMAX and LMAXT are \", lmax, lwin\n print*, \"Input array is dimensioned \", size(admit_error)\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n end if\n\n end if\n\n if (present(corr_error)) then\n if (size(corr_error) < lmax - lwin + 1) then\n print*, \"Error ---SHLocalizedAdmitCorr\"\n print*, \"CORR_ERROR must be dimensioned as (LMAX-LWIN+1) \" // &\n \"where LMAX and LMAXT are \", lmax, lwin\n print*, \"Input array is dimensioned \", size(corr_error)\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n end if\n\n end if\n\n if(present(taper_wt)) then\n if (size(taper_wt) < K) then\n print*, \"Error --- SHLocalizedAdmitCorr\"\n print*, \"TAPER_WT must be dimensioned as (K) where K is \", K\n print*, \"Input array has dimension \", size(taper_wt)\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n end if\n\n end if\n\n if (present(mtdef)) then\n if (mtdef == 2 .and. present(taper_wt)) then\n print*, \"Error --- SHLocalizedAdmitCorr\"\n print*, \"TAPER_WT can only be used when MTDEF is 1.\"\n if (present(exitstatus)) then\n exitstatus = 2\n return\n else\n stop\n end if\n\n end if\n\n end if\n\n if (present(mtdef)) then\n if (mtdef /= 1 .and. mtdef /= 2) then\n print*, \"SHLocalizedAdmitCorr --- Error\"\n print*, \"MTDEF must be 1 or 2.\"\n print*, \"Input value is \", mtdef\n if (present(exitstatus)) then\n exitstatus = 2\n return\n else\n stop\n end if\n\n else\n def = mtdef\n\n end if\n\n else\n def = 1\n\n end if\n\n\n admit = 0.0_dp\n corr = 0.0_dp\n\n if (present(admit_error)) then\n admit_error = 0.0_dp\n end if\n\n if (present(corr_error)) then\n corr_error = 0.0_dp\n end if\n\n !--------------------------------------------------------------------------\n !\n ! Determine multitaper cross spectra estimates of gilm and tilm, and then\n ! calculate the admittance and correlation. Errors for the latter are\n ! calculated by adding the error sources in quadrature. Taper weights can\n ! be specified in order to minimize the variance of the multitaper\n ! cross-spectral estimates.\n !\n ! Note that only the admittances with degrees greater than lwin and less\n ! than Lmax - lwin should be interpretted.\n !\n !--------------------------------------------------------------------------\n x(1) = 0.0_dp\n x(2) = -(90.0_dp - lat) * pi / 180.0_dp\n x(3) = -lon * pi / 180.0_dp\n \n if (first == 1) then\n lwin_last = lwin\n lmaxwin_last = lmaxwin\n first = 0\n \n allocate (zero(lmaxwin+1), stat = astat(1))\n allocate (w(lmaxwin+1), stat = astat(2))\n allocate (dj(lwin+1,lwin+1,lwin+1), stat = astat(3))\n \n if (sum(astat(1:3)) /= 0) then\n print*, \"Error --- SHLocalizedAdmitCorr\"\n print*, \"Problem allocating arrays ZERO, W and DJ\", &\n astat(1), astat(2), astat(3)\n if (present(exitstatus)) then\n exitstatus = 3\n return\n else\n stop\n end if\n\n end if\n\n if (present(exitstatus)) then\n call SHGLQ(lmaxwin, zero, w, csphase = phase, norm = 1, &\n exitstatus = exitstatus)\n if (exitstatus /= 0) return\n dj = 0.0_dp\n call djpi2(dj, lwin, exitstatus = exitstatus)\n if (exitstatus /= 0) return\n else\n call SHGLQ(lmaxwin, zero, w, csphase = phase, norm = 1)\n dj = 0.0_dp\n call djpi2(dj, lwin)\n end if\n\n end if\n\n if (lwin > lwin_last) then\n lwin_last = lwin\n deallocate (dj)\n\n allocate (dj(lwin+1,lwin+1,lwin+1), stat = astat(1))\n\n if (astat(1) /= 0) then\n print*, \"Error --- SHLocalizedAdmitCorr\"\n print*, \"Problem allocating array DJ\", astat(1)\n if (present(exitstatus)) then\n exitstatus = 3\n return\n else\n stop\n end if\n\n end if\n\n dj = 0.0_dp\n\n if (present(exitstatus)) then\n call djpi2(dj, lwin, exitstatus = exitstatus)\n if (exitstatus /= 0) return\n else\n call djpi2(dj, lwin)\n end if\n\n end if\n\n if (lmaxwin /= lmaxwin_last) then\n lmaxwin_last = lmaxwin\n\n deallocate (zero)\n deallocate (w)\n allocate (zero(lmaxwin+1), stat = astat(1))\n allocate (w(lmaxwin+1), stat = astat(2))\n \n if (sum(astat(1:2)) /= 0) then\n print*, \"Error --- SHLocalizedAdmitCorr\"\n print*, \"Problem allocating arrays ZERO and W\", astat(1), astat(2)\n if (present(exitstatus)) then\n exitstatus = 3\n return\n else\n stop\n end if\n\n end if\n\n if (present(exitstatus)) then\n call SHGLQ(lmaxwin, zero, w, csphase = phase, norm = 1, &\n exitstatus = exitstatus)\n if (exitstatus /= 0) return\n else\n call SHGLQ(lmaxwin, zero, w, csphase = phase, norm = 1)\n end if\n\n end if\n\n nlat = lmax + lwin + 1\n nlong = 2 * (lmax + lwin) + 1\n\n allocate (shwin(2,lwin+1,lwin+1), stat = astat(1))\n allocate (shwinrot(2,lwin+1,lwin+1), stat = astat(2))\n allocate (shloc_g(2, lmaxwin+1, lmaxwin+1), stat= astat(3))\n allocate (shloc_t(2, lmaxwin+1, lmaxwin+1), stat= astat(4))\n allocate (gridtglq(nlat,nlong), stat = astat(5))\n allocate (gridgglq(nlat,nlong), stat = astat(6))\n allocate (gridwinglq(nlat,nlong), stat = astat(7))\n allocate (temp(nlat,nlong), stat = astat(8))\n\n if (sum(astat(1:8)) /= 0) then\n print*, \"Error --- SHLocalizedAdmitCorr\"\n print*, \"Problem allocating arrays SHWIN, SHWINROT, SHLOC_G, \" // &\n \"SHLOC_T, GRIDTGLQ, GRIDGGLQ, GRIDWINGLQ, and TEMP\", &\n astat(1), astat(2), astat(3), astat(4), astat(5), astat(6), &\n astat(7), astat(8)\n if (present(exitstatus)) then\n exitstatus = 3\n return\n else\n stop\n end if\n\n end if\n\n if (present(exitstatus)) then\n call MakeGridGLQ(gridtglq, tilm(1:2,1:lmax+1, 1:lmax+1), &\n lmaxwin, zero = zero, csphase = phase, norm = 1, &\n exitstatus = exitstatus)\n if (exitstatus /= 0) return\n call MakeGridGLQ(gridgglq, gilm(1:2,1:lmax+1, 1:lmax+1), &\n lmaxwin, zero = zero, csphase = phase, norm = 1, &\n exitstatus = exitstatus)\n if (exitstatus /= 0) return\n else\n call MakeGridGLQ(gridtglq, tilm(1:2,1:lmax+1, 1:lmax+1), &\n lmaxwin, zero = zero, csphase = phase, norm = 1)\n call MakeGridGLQ(gridgglq, gilm(1:2,1:lmax+1, 1:lmax+1), &\n lmaxwin, zero = zero, csphase = phase, norm = 1)\n end if\n\n if (def == 1) then\n do i = 1, K\n shwin = 0.0_dp\n\n if (taper_order(i) < 0) then\n shwin(2,1:lwin+1,abs(taper_order(i))+1) = tapers(1:lwin+1,i)\n\n else\n shwin(1,1:lwin+1,taper_order(i)+1) = tapers(1:lwin+1,i)\n\n end if\n\n if (present(exitstatus)) then\n call SHRotateRealCoef(shwinrot, shwin, lwin, x, dj, &\n exitstatus = exitstatus)\n if (exitstatus /= 0) return\n call MakeGridGLQ(gridwinglq, shwinrot(1:2,1:lwin+1, 1:lwin+1),&\n lmaxwin, zero = zero, csphase = phase, &\n norm = 1, exitstatus = exitstatus)\n if (exitstatus /= 0) return\n temp(1:nlat,1:nlong) = gridtglq(1:nlat,1:nlong) &\n * gridwinglq(1:nlat,1:nlong)\n call SHExpandGLQ(shloc_t, lmaxwin, temp, w, zero = zero, &\n csphase = phase, norm = 1, &\n exitstatus = exitstatus)\n if (exitstatus /= 0) return\n temp(1:nlat,1:nlong) = gridgglq(1:nlat,1:nlong) &\n * gridwinglq(1:nlat,1:nlong)\n call SHExpandGLQ(shloc_g, lmaxwin, temp, w, zero = zero, &\n csphase = phase, norm = 1, &\n exitstatus = exitstatus)\n if (exitstatus /= 0) return\n call SHCrossPowerSpectrum(shloc_g, shloc_t, lmax-lwin, &\n sgt(:,i), exitstatus = exitstatus)\n if (exitstatus /= 0) return\n call SHPowerSpectrum(shloc_g, lmax-lwin, sgg(:,i), &\n exitstatus = exitstatus)\n if (exitstatus /= 0) return\n call SHPowerSpectrum(shloc_t, lmax-lwin, stt(:,i), &\n exitstatus = exitstatus)\n if (exitstatus /= 0) return\n else\n call SHRotateRealCoef(shwinrot, shwin, lwin, x, dj)\n call MakeGridGLQ(gridwinglq, shwinrot(1:2,1:lwin+1, 1:lwin+1),&\n lmaxwin, zero = zero, csphase = phase, &\n norm = 1)\n temp(1:nlat,1:nlong) = gridtglq(1:nlat,1:nlong) &\n * gridwinglq(1:nlat,1:nlong)\n call SHExpandGLQ(shloc_t, lmaxwin, temp, w, zero = zero, &\n csphase = phase, norm = 1)\n temp(1:nlat,1:nlong) = gridgglq(1:nlat,1:nlong) &\n * gridwinglq(1:nlat,1:nlong)\n call SHExpandGLQ(shloc_g, lmaxwin, temp, w, zero = zero, &\n csphase = phase, norm = 1)\n call SHCrossPowerSpectrum(shloc_g, shloc_t, lmax-lwin, &\n sgt(:,i))\n call SHPowerSpectrum(shloc_g, lmax-lwin, sgg(:,i))\n call SHPowerSpectrum(shloc_t, lmax-lwin, stt(:,i))\n end if\n\n if (present(taper_wt)) then\n factor = sum(taper_wt(1:K))**2 - sum(taper_wt(1:K)**2)\n factor = factor * sum(taper_wt(1:K))\n factor = sum(taper_wt(1:K)**2) / factor\n\n do l= 0, lmax-lwin, 1\n g_power(1,l+1) = dot_product(sgg(l+1,1:K), taper_wt(1:K)) &\n / sum(taper_wt(1:K))\n t_power(1,l+1) = dot_product(stt(l+1,1:K), taper_wt(1:K)) &\n / sum(taper_wt(1:K))\n gt_power(1,l+1) = dot_product(sgt(l+1,1:K), &\n taper_wt(1:K)) / sum(taper_wt(1:K))\n\n if (K > 1) then\n g_power(2,l+1) = dot_product( (sgg(l+1,1:K) &\n - g_power(1,l+1) )**2, &\n taper_wt(1:K) ) * factor\n t_power(2,l+1) = dot_product( (stt(l+1,1:K) &\n - t_power(1,l+1) )**2, &\n taper_wt(1:K) ) * factor\n gt_power(2,l+1) = dot_product( (sgt(l+1,1:K) &\n - gt_power(1,l+1) )**2, &\n taper_wt(1:K)) * factor\n\n end if\n\n end do\n\n else\n do l = 0, lmax-lwin, 1\n g_power(1,l+1) = sum(sgg(l+1,1:K)) / dble(K)\n t_power(1,l+1) = sum(stt(l+1,1:K)) / dble(K)\n gt_power(1,l+1) = sum(sgt(l+1,1:K)) / dble(K)\n\n if (K > 1) then\n g_power(2,l+1) = sum( ( sgg(l+1,1:K) &\n - g_power(1,l+1) )**2 ) / dble(K-1) &\n / dble(K) ! standard error!\n t_power(2,l+1) = sum( ( stt(l+1,1:K) &\n - t_power(1,l+1) )**2 ) / dble(K-1) &\n / dble(K) ! standard error!\n gt_power(2,l+1) = sum( ( sgt(l+1,1:K) &\n - gt_power(1,l+1) )**2 ) / dble(K-1) &\n / dble(K) ! standard error!\n\n end if\n\n end do\n\n end if\n\n if (K > 1) then\n g_power(2,1:lmax-lwin+1) = sqrt(g_power(2,1:lmax-lwin+1))\n t_power(2,1:lmax-lwin+1) = sqrt(t_power(2,1:lmax-lwin+1))\n gt_power(2,1:lmax-lwin+1) = sqrt(gt_power(2,1:lmax-lwin+1))\n\n end if\n\n end do\n\n admit(1:lmax-lwin+1) = gt_power(1,1:lmax-lwin+1) &\n / t_power(1,1:lmax-lwin+1)\n corr(1:lmax-lwin+1) = gt_power(1,1:lmax-lwin+1) &\n / sqrt(t_power(1,1:lmax-lwin+1) &\n * g_power(1,1:lmax-lwin+1))\n\n if (K > 1 .and. present(admit_error)) then\n admit_error(1:lmax-lwin+1) = ( gt_power(2,1:lmax-lwin+1) &\n / t_power(1,1:lmax-lwin+1) )**2 + &\n ( gt_power(1,1:lmax-lwin+1) &\n / t_power(1,1:lmax-lwin+1)**2 &\n * t_power(2,1:lmax-lwin+1) )**2\n admit_error(1:lmax-lwin+1) = sqrt(admit_error(1:lmax-lwin+1))\n\n end if\n\n if (K > 1 .and. present(corr_error)) then\n corr_error(1:lmax-lwin+1) = gt_power(2,1:lmax-lwin+1)**2 &\n / t_power(1,1:lmax-lwin+1) &\n / g_power(1,1:lmax-lwin+1) + &\n ( gt_power(1,1:lwin-lmax+1) &\n * t_power(2,1:lwin-lmax+1) / &\n sqrt(g_power(1,1:lmax-lwin+1)) / 2.0_dp &\n / t_power(1,1:lmax-lwin+1)**(3.0_dp/2.0_dp))**2 + &\n ( gt_power(1,1:lwin-lmax+1) &\n * g_power(2,1:lwin-lmax+1) &\n / sqrt(t_power(1,1:lmax-lwin+1)) / 2.0_dp &\n / g_power(1,1:lmax-lwin+1)**(3.0_dp/2.0_dp))**2\n corr_error(1:lmax-lwin+1) = sqrt(corr_error(1:lmax-lwin+1))\n\n end if\n\n if (K == 1 .and. present(k1linsig) .and. present(admit_error)) then\n admit_error = 0.0_dp\n\n if (k1linsig == 1) then\n do l = 1, lmax-lwin\n admit_error(l+1) = g_power(1,l+1)*(1.0_dp - corr(l+1)**2) &\n / ( t_power(1,l+1) * dble(2*l) )\n end do\n\n admit_error(1:lmax-lwin+1) = sqrt(admit_error(1:lmax-lwin+1))\n\n end if\n\n end if\n\n !--------------------------------------------------------------------------\n !\n ! Calculate the admittance and correlation for each individual taper.\n ! Then average these in order to get the multitaper estimates and\n ! uncertainties.\n !\n !--------------------------------------------------------------------------\n else\n do i = 1, K\n shwin = 0.0_dp\n\n if (taper_order(i) < 0) then\n shwin(2,1:lwin+1,abs(taper_order(i))+1) = tapers(1:lwin+1,i)\n\n else\n shwin(1,1:lwin+1,taper_order(i)+1) = tapers(1:lwin+1,i)\n\n end if\n\n if (present(exitstatus)) then\n call SHRotateRealCoef(shwinrot, shwin, lwin, x, dj, &\n exitstatus = exitstatus)\n if (exitstatus /= 0) return\n call MakeGridGLQ(gridwinglq, shwinrot(1:2,1:lwin+1, 1:lwin+1),&\n lmaxwin, zero = zero, csphase = phase, &\n norm = 1, exitstatus = exitstatus)\n if (exitstatus /= 0) return\n temp(1:nlat,1:nlong) = gridtglq(1:nlat,1:nlong) &\n * gridwinglq(1:nlat,1:nlong)\n call SHExpandGLQ(shloc_t, lmaxwin, temp, w, zero = zero, &\n csphase = phase, norm = 1, &\n exitstatus = exitstatus)\n if (exitstatus /= 0) return\n temp(1:nlat,1:nlong) = gridgglq(1:nlat,1:nlong) &\n * gridwinglq(1:nlat,1:nlong)\n call SHExpandGLQ(shloc_g, lmaxwin, temp, w, zero = zero, &\n csphase = phase, norm = 1, &\n exitstatus = exitstatus)\n if (exitstatus /= 0) return\n call SHCrossPowerSpectrum(shloc_g, shloc_t, lmax-lwin, &\n sgt(:,i), exitstatus = exitstatus)\n if (exitstatus /= 0) return\n call SHPowerSpectrum(shloc_g, lmax-lwin, sgg(:,i), &\n exitstatus = exitstatus)\n if (exitstatus /= 0) return\n call SHPowerSpectrum(shloc_t, lmax-lwin, stt(:,i), &\n exitstatus = exitstatus)\n if (exitstatus /= 0) return\n else\n call SHRotateRealCoef(shwinrot, shwin, lwin, x, dj)\n call MakeGridGLQ(gridwinglq, shwinrot(1:2,1:lwin+1, 1:lwin+1),&\n lmaxwin, zero = zero, csphase = phase, &\n norm = 1)\n temp(1:nlat,1:nlong) = gridtglq(1:nlat,1:nlong) &\n * gridwinglq(1:nlat,1:nlong)\n call SHExpandGLQ(shloc_t, lmaxwin, temp, w, zero = zero, &\n csphase = phase, norm = 1)\n temp(1:nlat,1:nlong) = gridgglq(1:nlat,1:nlong) &\n * gridwinglq(1:nlat,1:nlong)\n call SHExpandGLQ(shloc_g, lmaxwin, temp, w, zero = zero, &\n csphase = phase, norm = 1)\n call SHCrossPowerSpectrum(shloc_g, shloc_t, lmax-lwin, &\n sgt(:,i))\n call SHPowerSpectrum(shloc_g, lmax-lwin, sgg(:,i))\n call SHPowerSpectrum(shloc_t, lmax-lwin, stt(:,i))\n end if\n\n admit_k(1:lmax-lwin+1, i) = sgt(1:lmax-lwin+1, i) &\n / stt(1:lmax-lwin+1, i)\n corr_k(1:lmax-lwin+1, i) = sgt(1:lmax-lwin+1, i) &\n / sqrt(stt(1:lmax-lwin+1, i)) &\n / sqrt(sgg(1:lmax-lwin+1, i))\n\n end do\n\n do l = 0, lmax-lwin, 1\n admit(l+1) = sum(admit_k(l+1,1:K)) / dble(K)\n corr(l+1) = sum(corr_k(l+1,1:K)) / dble(K)\n\n end do\n\n if (present(admit_error) .or. present(corr_error)) then\n do l = 0, lmax-lwin, 1\n if (present(admit_error)) then\n if (K > 1) then \n admit_error(l+1) = sum( ( admit_k(l+1,1:K) &\n - admit(l+1) )**2 ) / dble(K-1) &\n / dble(K) ! standard error!\n admit_error(l+1) = sqrt(admit_error(l+1))\n\n else if (K == 1 .and. present(k1linsig)) then\n if (k1linsig == 1) then\n if (l == 0) then\n admit_error(1) = 0.0_dp\n\n else\n admit_error(l+1) = sgg(l+1,1)*(1.0_dp &\n - corr(l+1)**2) &\n / (stt(l+1,1) * dble(2*l))\n admit_error(l+1) = sqrt(admit_error(l+1))\n\n end if\n\n end if\n\n end if\n\n end if\n\n if (present(corr_error)) then\n if (K > 1) then\n ! standard error!\n corr_error(l+1) = sum((corr_k(l+1,1:K) &\n - corr(l+1))**2 ) &\n / dble(K-1) / dble(K)\n corr_error(l+1) = sqrt(corr_error(l+1))\n\n end if\n\n end if\n\n end do\n\n end if\n\n end if\n\n deallocate (shwin)\n deallocate (shwinrot)\n deallocate (shloc_g)\n deallocate (shloc_t)\n deallocate (gridtglq)\n deallocate (gridgglq)\n deallocate (gridwinglq)\n deallocate (temp)\n\nend subroutine SHLocalizedAdmitCorr\n", "meta": {"hexsha": "dd6e1a314466482deb5302f2dea3c0612c26a053", "size": 31111, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/SHLocalizedAdmitCorr.f95", "max_stars_repo_name": "mjc87/SHTOOLS", "max_stars_repo_head_hexsha": "8d83c42d1313d5624c4db8c2e57300c5d819834e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 251, "max_stars_repo_stars_event_min_datetime": "2015-01-27T12:58:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T17:19:36.000Z", "max_issues_repo_path": "src/SHLocalizedAdmitCorr.f95", "max_issues_repo_name": "mjc87/SHTOOLS", "max_issues_repo_head_hexsha": "8d83c42d1313d5624c4db8c2e57300c5d819834e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 193, "max_issues_repo_issues_event_min_datetime": "2015-03-11T06:21:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T14:05:45.000Z", "max_forks_repo_path": "src/SHLocalizedAdmitCorr.f95", "max_forks_repo_name": "mreineck/SHTOOLS", "max_forks_repo_head_hexsha": "fec33f203ee0b47008fd69d4080304d6ebd272e7", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 100, "max_forks_repo_forks_event_min_datetime": "2015-04-03T07:11:05.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-23T23:46:33.000Z", "avg_line_length": 40.0914948454, "max_line_length": 80, "alphanum_fraction": 0.4618945068, "num_tokens": 8406, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110368115783, "lm_q2_score": 0.7549149758396752, "lm_q1q2_score": 0.6732415073081682}} {"text": "\n subroutine lorentzTransform (photonEG, p, v, pstar, t, cm)\n\n! ======================================================================\n!\n! Momentum calculation in system which has a relative velocity\n! v to given one.\n! Lorentz transformation; see Jackson, 2nd ed., p541.\n!\n! Called by: ISOBAR STAT\n!\n! CEM95 written by S. G. Mashnik\n! Edited by A. J. Sierk LANL T-2 February, 1996.\n! Edited by AJS, August, 1997.\n! \"Last\" change: 13-AUG-2003 by NVMokhov\n! Edited by A. J. Sierk, LANL T-16, October, 2003.\n! Edited by AJS, LANL T-2, December, 2011.\n! Edited by LMK, XCP-3, July 2013 (included error protection).\n!\n! ======================================================================\n\n\n use, intrinsic:: iso_fortran_env, only: int32, real64\n\n implicit none\n class(PhotonEventGenerator), intent(inout) :: photonEG\n real(real64), intent(in ) :: p(3)\n real(real64), intent(in ) :: v(3)\n real(real64), intent( out) :: pstar(3)\n real(real64), intent(in ) :: t\n real(real64), intent(in ) :: cm\n\n real(real64) :: spv, sv, temp1, temp2, v2\n\n! ======================================================================\n\n v2 = v(1)**2 + v(2)**2 + v(3)**2\n temp1 = sqrt(abs(one - v2))\n spv = p(1)*v(1) + p(2)*v(2) + p(3)*v(3)\n if (temp1 < divZerLim ) then\n temp1 = divZerLim\n write(photonEG%io%message,1000) \"45 and 46\"\n call photonEG%io%print(4, 3, photonEG%io%message)\n end if\n temp2 = spv*(one/temp1 - one)/v2\n sv = (t + cm)/temp1\n\n pstar(1) = p(1) + v(1)*temp2 - v(1)*sv\n pstar(2) = p(2) + v(2)*temp2 - v(2)*sv\n pstar(3) = p(3) + v(3)*temp2 - v(3)*sv\n return\n\n! ======================================================================\n1000 format(\"Divide by zero error prevented in \", &\n & \"'lorentzTransform.f90', line(s) \", A)\n! ======================================================================\n end subroutine lorentzTransform\n", "meta": {"hexsha": "f9ff9fbbc70107b46b38df1fd04e3bf01430b18d", "size": 1972, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/PhotonEventGenerator/lorentzTransform.f90", "max_stars_repo_name": "lanl/generalized-spallation-model", "max_stars_repo_head_hexsha": "4a2f01a873d2e8f2304b8fd1474d43d1ce8d744d", "max_stars_repo_licenses": ["Intel", "Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-24T18:05:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-24T18:05:48.000Z", "max_issues_repo_path": "src/PhotonEventGenerator/lorentzTransform.f90", "max_issues_repo_name": "lanl/generalized-spallation-model", "max_issues_repo_head_hexsha": "4a2f01a873d2e8f2304b8fd1474d43d1ce8d744d", "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": "src/PhotonEventGenerator/lorentzTransform.f90", "max_forks_repo_name": "lanl/generalized-spallation-model", "max_forks_repo_head_hexsha": "4a2f01a873d2e8f2304b8fd1474d43d1ce8d744d", "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.0, "max_line_length": 72, "alphanum_fraction": 0.4802231237, "num_tokens": 630, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896780646392, "lm_q2_score": 0.7310585844894971, "lm_q1q2_score": 0.6731511986584748}} {"text": "\nC This file contains a number of simple matrix manipulation routines.\nC All of the routines operate on REAL*8 matrices.\nC The size is passed as the first parameters: N rows by M columns.\nC If there is no M parameter then a N by N square matrix is assumed.\nC\nC CALL MCOPY (N,M, X, Y) Copies matrix: Y = X\nC\nC CALL MADD (N,M, X, Y, Z) Adds matrices: Z = X + Y\nC Z can be X or Y\nC CALL MSUB (N,M, X, Y, Z) Subtracts matrices: Z = X - Y\nC Z can be X or Y\nC CALL MSCALARMULT (N,M, C, X, Y) Scalar multiply: Y = C*X\nC C is real scalar; Y can be X\nC CALL MZERO (N,M, X) Zeros all elements in X\nC\nC CALL MDIAG (N, V, X) Formats a vector (V) into a diagonal\nC matrix (X)\nC CALL MIDENTITY (N, X) Make identity matrix in X\nC t\nC CALL MTRANSPOSE (N,M, X, Y) Transposes: Y = X ; Y cannot be X\nC\nC CALL MMULT (N,M,L, X, Y, Z) Matrix multiply: Z = X*Y\nC X is N by M and Y is M by L.\nC Z cannot be X or Y\nC -1\nC CALL MINVERT (N, X, Y) Matrix inversion: Y = X\nC\t\t\t\t X gets LU decomposition.\n\n\n\n\n SUBROUTINE MCOPY (N, M, MATRIX1, MATRIX2)\n INTEGER N, M, I\n REAL*8 MATRIX1(1), MATRIX2(1)\n\n DO 100 I = 1, N*M\n MATRIX2(I) = MATRIX1(I)\n100 CONTINUE\n\n RETURN\n END\n\n\n\n SUBROUTINE MADD (N, M, MATRIX1, MATRIX2, MATRIX3)\n INTEGER N, M, I\n REAL*8 MATRIX1(1), MATRIX2(1), MATRIX3(1)\n\n DO 100 I = 1, N*M\n MATRIX3(I) = MATRIX1(I) + MATRIX2(I)\n100 CONTINUE\n\n RETURN\n END\n\n\n\n SUBROUTINE MSUB (N, M, MATRIX1, MATRIX2, MATRIX3)\n INTEGER N, M, I\n REAL*8 MATRIX1(1), MATRIX2(1), MATRIX3(1)\n\n DO 100 I = 1, N*M\n MATRIX3(I) = MATRIX1(I) - MATRIX2(I)\n100 CONTINUE\n\n RETURN\n END\n\n\n\n\n SUBROUTINE MSCALARMULT (N, M, C, MATRIX1, MATRIX2)\n INTEGER N, M, I\n REAL*8 C, MATRIX1(1), MATRIX2(1)\n\n DO 100 I = 1, N*M\n MATRIX2(I) = C*MATRIX1(I)\n100 CONTINUE\n\n RETURN\n END\n\n\n SUBROUTINE MZERO (N, M, MATRIX1)\n INTEGER N, M, I\n REAL*8 MATRIX1(1)\n\n DO 100 I = 1, N*M\n MATRIX1(I) = 0.0D0\n100 CONTINUE\n\n RETURN\n END\n\n\n\n SUBROUTINE MDIAG (N, VECTOR, MATRIX)\n INTEGER N, I, J\n REAL*8 VECTOR(1), MATRIX(N,N)\n\n DO 110 I = 1, N\n DO 100 J = 1, N\n MATRIX(I,J) = 0.0\n100 CONTINUE\n MATRIX(I,I) = VECTOR(I)\n110 CONTINUE\n\n RETURN\n END\n\n\n\n SUBROUTINE MIDENTITY (N, MATRIX)\n INTEGER N, I, J\n REAL*8 MATRIX(N,N)\n\n DO 110 I = 1, N\n DO 100 J = 1, N\n MATRIX(I,J) = 0.0\n100 CONTINUE\n MATRIX(I,I) = 1.0\n110 CONTINUE\n\n RETURN\n END\n\n\n\n SUBROUTINE MTRANSPOSE (N, M, MATRIX1, MATRIX2)\n INTEGER N, M, I, J\n REAL*8 MATRIX1(N,M), MATRIX2(M,N)\n\n DO I = 1, N\n DO J = 1, M\n MATRIX2(I,J) = MATRIX1(J,I)\n ENDDO\n ENDDO\n\n RETURN\n END\n\n\n\n SUBROUTINE MMULT (N, M, L, MATRIX1, MATRIX2, MATRIX3)\n INTEGER N, M, L, I, J, K\n REAL*8 MATRIX1(N,M), MATRIX2(M,L), MATRIX3(N,L), SUM\n\n DO I = 1, N\n DO J = 1, L\n SUM = 0.0\n DO 100 K = 1, M\n SUM = SUM + MATRIX1(I,K)*MATRIX2(K,J)\n100 CONTINUE\n MATRIX3(I,J) = SUM\n ENDDO\n ENDDO\n RETURN\n END\n\n\n\n\n SUBROUTINE MINVERT (N, MATRIX1, MATRIX2)\n INTEGER N\n REAL*8 MATRIX1(N,N), MATRIX2(N,N)\n INTEGER NMAX\n PARAMETER (NMAX=256)\n INTEGER I, J, INDX(NMAX), IZ\n REAL*8 DET(2), WORK(NMAX)\n\n IF (N .GT. NMAX) THEN\n WRITE (*,'(1X,A,I3)')\n . 'Exceeded maximum matrix size for inversion. Max = ', NMAX\n STOP\n ENDIF\n CALL DGEFA (MATRIX1, N, N, INDX, IZ)\n IF (IZ .GT. 0) THEN\n\t WRITE (*,'(1X,A,I3)')\n . 'Encountered a zero pivot at element ', IZ\n\t STOP\n ENDIF\n DO 100 I = 1, N\n\tDO 110 J = 1, N\n MATRIX2(I,J) = MATRIX1(I,J)\n110 CONTINUE\n100 CONTINUE\n CALL DGEDI (MATRIX2, N, N, INDX, DET, WORK, 1 )\n\n RETURN\n END\n\n\n\n subroutine dgefa(a,lda,n,ipvt,info)\n integer lda,n,ipvt(1),info\n double precision a(lda,1)\nc\nc dgefa factors a double precision matrix by gaussian elimination.\nc\nc dgefa is usually called by dgeco, but it can be called\nc directly with a saving in time if rcond is not needed.\nc (time for dgeco) = (1 + 9/n)*(time for dgefa) .\nc\nc on entry\nc\nc a double precision(lda, n)\nc the matrix to be factored.\nc\nc lda integer\nc the leading dimension of the array a .\nc\nc n integer\nc the order of the matrix a .\nc\nc on return\nc\nc a an upper triangular matrix and the multipliers\nc which were used to obtain it.\nc the factorization can be written a = l*u where\nc l is a product of permutation and unit lower\nc triangular matrices and u is upper triangular.\nc\nc ipvt integer(n)\nc an integer vector of pivot indices.\nc\nc info integer\nc = 0 normal value.\nc = k if u(k,k) .eq. 0.0 . this is not an error\nc condition for this subroutine, but it does\nc indicate that dgesl or dgedi will divide by zero\nc if called. use rcond in dgeco for a reliable\nc indication of singularity.\nc\nc linpack. this version dated 08/14/78 .\nc cleve moler, university of new mexico, argonne national lab.\nc\nc subroutines and functions\nc\nc blas daxpy,dscal,idamax\nc\nc internal variables\nc\n double precision t\n integer idamax,j,k,kp1,l,nm1\nc\nc\nc gaussian elimination with partial pivoting\nc\n info = 0\n nm1 = n - 1\n if (nm1 .lt. 1) go to 70\n do 60 k = 1, nm1\n kp1 = k + 1\nc\nc find l = pivot index\nc\n l = idamax(n-k+1,a(k,k),1) + k - 1\n ipvt(k) = l\nc\nc zero pivot implies this column already triangularized\nc\n if (a(l,k) .eq. 0.0d0) go to 40\nc\nc interchange if necessary\nc\n if (l .eq. k) go to 10\n t = a(l,k)\n a(l,k) = a(k,k)\n a(k,k) = t\n 10 continue\nc\nc compute multipliers\nc\n t = -1.0d0/a(k,k)\n call dscal(n-k,t,a(k+1,k),1)\nc\nc row elimination with column indexing\nc\n do 30 j = kp1, n\n t = a(l,j)\n if (l .eq. k) go to 20\n a(l,j) = a(k,j)\n a(k,j) = t\n 20 continue\n call daxpy(n-k,t,a(k+1,k),1,a(k+1,j),1)\n 30 continue\n go to 50\n 40 continue\n info = k\n 50 continue\n 60 continue\n 70 continue\n ipvt(n) = n\n if (a(n,n) .eq. 0.0d0) info = n\n return\n end\n\n\n subroutine dgedi(a,lda,n,ipvt,det,work,job)\n integer lda,n,ipvt(1),job\n double precision a(lda,1),det(2),work(1)\nc\nc dgedi computes the determinant and inverse of a matrix\nc using the factors computed by dgeco or dgefa.\nc\nc on entry\nc\nc a double precision(lda, n)\nc the output from dgeco or dgefa.\nc\nc lda integer\nc the leading dimension of the array a .\nc\nc n integer\nc the order of the matrix a .\nc\nc ipvt integer(n)\nc the pivot vector from dgeco or dgefa.\nc\nc work double precision(n)\nc work vector. contents destroyed.\nc\nc job integer\nc = 11 both determinant and inverse.\nc = 01 inverse only.\nc = 10 determinant only.\nc\nc on return\nc\nc a inverse of original matrix if requested.\nc otherwise unchanged.\nc\nc det double precision(2)\nc determinant of original matrix if requested.\nc otherwise not referenced.\nc determinant = det(1) * 10.0**det(2)\nc with 1.0 .le. dabs(det(1)) .lt. 10.0\nc or det(1) .eq. 0.0 .\nc\nc error condition\nc\nc a division by zero will occur if the input factor contains\nc a zero on the diagonal and the inverse is requested.\nc it will not occur if the subroutines are called correctly\nc and if dgeco has set rcond .gt. 0.0 or dgefa has set\nc info .eq. 0 .\nc\nc linpack. this version dated 08/14/78 .\nc cleve moler, university of new mexico, argonne national lab.\nc\nc subroutines and functions\nc\nc blas daxpy,dscal,dswap\nc fortran dabs,mod\nc\nc internal variables\nc\n double precision t\n double precision ten\n integer i,j,k,kb,kp1,l,nm1\nc\nc\nc compute determinant\nc\n if (job/10 .eq. 0) go to 70\n det(1) = 1.0d0\n det(2) = 0.0d0\n ten = 10.0d0\n do 50 i = 1, n\n if (ipvt(i) .ne. i) det(1) = -det(1)\n det(1) = a(i,i)*det(1)\nc ...exit\n if (det(1) .eq. 0.0d0) go to 60\n 10 if (dabs(det(1)) .ge. 1.0d0) go to 20\n det(1) = ten*det(1)\n det(2) = det(2) - 1.0d0\n go to 10\n 20 continue\n 30 if (dabs(det(1)) .lt. ten) go to 40\n det(1) = det(1)/ten\n det(2) = det(2) + 1.0d0\n go to 30\n 40 continue\n 50 continue\n 60 continue\n 70 continue\nc\nc compute inverse(u)\nc\n if (mod(job,10) .eq. 0) go to 150\n do 100 k = 1, n\n a(k,k) = 1.0d0/a(k,k)\n t = -a(k,k)\n call dscal(k-1,t,a(1,k),1)\n kp1 = k + 1\n if (n .lt. kp1) go to 90\n do 80 j = kp1, n\n t = a(k,j)\n a(k,j) = 0.0d0\n call daxpy(k,t,a(1,k),1,a(1,j),1)\n 80 continue\n 90 continue\n 100 continue\nc\nc form inverse(u)*inverse(l)\nc\n nm1 = n - 1\n if (nm1 .lt. 1) go to 140\n do 130 kb = 1, nm1\n k = n - kb\n kp1 = k + 1\n do 110 i = kp1, n\n work(i) = a(i,k)\n a(i,k) = 0.0d0\n 110 continue\n do 120 j = kp1, n\n t = work(j)\n call daxpy(n,t,a(1,j),1,a(1,k),1)\n 120 continue\n l = ipvt(k)\n if (l .ne. k) call dswap(n,a(1,k),1,a(1,l),1)\n 130 continue\n 140 continue\n 150 continue\n return\n end\n\n\n subroutine daxpy(n,da,dx,incx,dy,incy)\nc\nc constant times a vector plus a vector.\nc uses unrolled loops for increments equal to one.\nc jack dongarra, linpack, 3/11/78.\nc\n double precision dx(1),dy(1),da\n integer i,incx,incy,ix,iy,m,mp1,n\nc\n if(n.le.0)return\n if (da .eq. 0.0d0) return\n if(incx.eq.1.and.incy.eq.1)go to 20\nc\nc code for unequal increments or equal increments\nc not equal to 1\nc\n ix = 1\n iy = 1\n if(incx.lt.0)ix = (-n+1)*incx + 1\n if(incy.lt.0)iy = (-n+1)*incy + 1\n do 10 i = 1,n\n dy(iy) = dy(iy) + da*dx(ix)\n ix = ix + incx\n iy = iy + incy\n 10 continue\n return\nc\nc code for both increments equal to 1\nc\nc\nc clean-up loop\nc\n 20 m = mod(n,4)\n if( m .eq. 0 ) go to 40\n do 30 i = 1,m\n dy(i) = dy(i) + da*dx(i)\n 30 continue\n if( n .lt. 4 ) return\n 40 mp1 = m + 1\n do 50 i = mp1,n,4\n dy(i) = dy(i) + da*dx(i)\n dy(i + 1) = dy(i + 1) + da*dx(i + 1)\n dy(i + 2) = dy(i + 2) + da*dx(i + 2)\n dy(i + 3) = dy(i + 3) + da*dx(i + 3)\n 50 continue\n return\n end\n\n\n subroutine dscal(n,da,dx,incx)\nc\nc scales a vector by a constant.\nc uses unrolled loops for increment equal to one.\nc jack dongarra, linpack, 3/11/78.\nc modified 3/93 to return if incx .le. 0.\nc\n double precision da,dx(1)\n integer i,incx,m,mp1,n,nincx\nc\n if( n.le.0 .or. incx.le.0 )return\n if(incx.eq.1)go to 20\nc\nc code for increment not equal to 1\nc\n nincx = n*incx\n do 10 i = 1,nincx,incx\n dx(i) = da*dx(i)\n 10 continue\n return\nc\nc code for increment equal to 1\nc\nc\nc clean-up loop\nc\n 20 m = mod(n,5)\n if( m .eq. 0 ) go to 40\n do 30 i = 1,m\n dx(i) = da*dx(i)\n 30 continue\n if( n .lt. 5 ) return\n 40 mp1 = m + 1\n do 50 i = mp1,n,5\n dx(i) = da*dx(i)\n dx(i + 1) = da*dx(i + 1)\n dx(i + 2) = da*dx(i + 2)\n dx(i + 3) = da*dx(i + 3)\n dx(i + 4) = da*dx(i + 4)\n 50 continue\n return\n end\n\n\n integer function idamax(n,dx,incx)\nc\nc finds the index of element having max. absolute value.\nc jack dongarra, linpack, 3/11/78.\nc modified 3/93 to return if incx .le. 0.\nc\n double precision dx(1),dmax\n integer i,incx,ix,n\nc\n idamax = 0\n if( n.lt.1 .or. incx.le.0 ) return\n idamax = 1\n if(n.eq.1)return\n if(incx.eq.1)go to 20\nc\nc code for increment not equal to 1\nc\n ix = 1\n dmax = dabs(dx(1))\n ix = ix + incx\n do 10 i = 2,n\n if(dabs(dx(ix)).le.dmax) go to 5\n idamax = i\n dmax = dabs(dx(ix))\n 5 ix = ix + incx\n 10 continue\n return\nc\nc code for increment equal to 1\nc\n 20 dmax = dabs(dx(1))\n do 30 i = 2,n\n if(dabs(dx(i)).le.dmax) go to 30\n idamax = i\n dmax = dabs(dx(i))\n 30 continue\n return\n end\n\n\n subroutine dswap (n,dx,incx,dy,incy)\nc\nc interchanges two vectors.\nc uses unrolled loops for increments equal one.\nc jack dongarra, linpack, 3/11/78.\nc\n double precision dx(1),dy(1),dtemp\n integer i,incx,incy,ix,iy,m,mp1,n\nc\n if(n.le.0)return\n if(incx.eq.1.and.incy.eq.1)go to 20\nc\nc code for unequal increments or equal increments not equal\nc to 1\nc\n ix = 1\n iy = 1\n if(incx.lt.0)ix = (-n+1)*incx + 1\n if(incy.lt.0)iy = (-n+1)*incy + 1\n do 10 i = 1,n\n dtemp = dx(ix)\n dx(ix) = dy(iy)\n dy(iy) = dtemp\n ix = ix + incx\n iy = iy + incy\n 10 continue\n return\nc\nc code for both increments equal to 1\nc\nc\nc clean-up loop\nc\n 20 m = mod(n,3)\n if( m .eq. 0 ) go to 40\n do 30 i = 1,m\n dtemp = dx(i)\n dx(i) = dy(i)\n dy(i) = dtemp\n 30 continue\n if( n .lt. 3 ) return\n 40 mp1 = m + 1\n do 50 i = mp1,n,3\n dtemp = dx(i)\n dx(i) = dy(i)\n dy(i) = dtemp\n dtemp = dx(i + 1)\n dx(i + 1) = dy(i + 1)\n dy(i + 1) = dtemp\n dtemp = dx(i + 2)\n dx(i + 2) = dy(i + 2)\n dy(i + 2) = dtemp\n 50 continue\n return\n end\n", "meta": {"hexsha": "d473a8898094c894e5d258c5fdaa8b06177675fc", "size": 15048, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ubuntu20/projects/libRadtran-2.0.4/libsrc_f/radmat.f", "max_stars_repo_name": "AmberCrafter/docker-compose_libRadtran", "max_stars_repo_head_hexsha": "0182f991db6a13e0cacb3bf9f43809e6850593e4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ubuntu20/projects/libRadtran-2.0.4/libsrc_f/radmat.f", "max_issues_repo_name": "AmberCrafter/docker-compose_libRadtran", "max_issues_repo_head_hexsha": "0182f991db6a13e0cacb3bf9f43809e6850593e4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ubuntu20/projects/libRadtran-2.0.4/libsrc_f/radmat.f", "max_forks_repo_name": "AmberCrafter/docker-compose_libRadtran", "max_forks_repo_head_hexsha": "0182f991db6a13e0cacb3bf9f43809e6850593e4", "max_forks_repo_licenses": ["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.3495145631, "max_line_length": 74, "alphanum_fraction": 0.4972089314, "num_tokens": 5142, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835371034368, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.673092428904962}} {"text": "module user_func\n use utils\n\n implicit none\n\ncontains\n function k(x)\n real(wp), intent(in) :: x\n real(wp) :: k\n k = 1.0_wp\n end function k\n\n function q(x)\n real(wp), intent(in) :: x\n real(wp) :: q\n q = 0.0_wp\n end function q\n\n function f(x)\n real(wp), intent(in) :: x\n real(wp) :: f\n !f = (pi**2)*(sin(pi*x)-9*sin(3*pi*x))\n f = -2\n end function f\n\n function u(x)\n real(wp), intent(in) :: x\n real(wp) :: u\n !u = sin(pi*x) - sin(3*pi*x)\n u = (x-1.0)*x\n end function u\n\nend module user_func\n", "meta": {"hexsha": "27969d394033742eeb4a1161d8140dae8dc74e13", "size": 540, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "user_func.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": "user_func.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": "user_func.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": 15.8823529412, "max_line_length": 42, "alphanum_fraction": 0.5333333333, "num_tokens": 198, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835371034368, "lm_q2_score": 0.8056321866478978, "lm_q1q2_score": 0.6730924289049619}} {"text": " module m_indexing\n !! Contains routines to obtain packed and unpacked indices into arrays\n \n use variableKind, only: i32, r64\n\n implicit none\n\n contains\n\n !====================================================================!\n function ind2sub(iG,nSub) result(iSub)\n !! Compute the indices in each dimension from the global index\n !====================================================================!\n integer(i32), intent(in) :: iG !! Index into a global vector\n integer(i32), intent(in) :: nSub(:) !! Size in each dimension\n integer(i32) :: iSub(size(nSub)) !! Indices in each dimension to return\n integer(i32) :: i,iGtmp,iTmp\n integer(i32) :: nDims\n integer(i32) :: prod\n\n nDims=size(nSub)\n if (nDims == 1) then\n iSub(1) = iG\n return\n end if\n\n prod = product(nSub)\n iGtmp = iG\n do i = nDims, 1, -1\n prod = prod / nSub(i)\n iTmp = mod(iGtmp-1,prod)+1\n iSub(i) = (iGtmp - iTmp)/prod + 1\n iGtmp = iTmp\n end do\n\n end function\n !====================================================================!\n !====================================================================!\n function sub2ind(iSub,nSub) result(iG)\n !! Given component indices, get the global vector location.\n !====================================================================!\n integer(i32), intent(in) :: iSub(:) !! Indices in each dimension. The first entry in iL is the left most index\n integer(i32), intent(in) :: nSub(:) !! Size in each dimension\n integer(i32) :: iG !! Index in the global vector\n integer(i32) :: i\n integer(i32) :: nDims\n integer(i32) :: prod\n nDims=size(iSub)\n\n prod = 1\n iG = 1\n do i = 1,nDims\n iG = iG + (iSub(i)-1)*prod\n prod = prod * nSub(i)\n end do\n\n end function\n !====================================================================!\n !====================================================================!\n function integerBin(this,n,bound) result(i)\n !====================================================================!\n ! Given a real number this, that is assumed to lie between 1 and N\n ! Round the real number and if it is outside 1 or N, limit the output to\n ! either of those values\n ! Automatically limits the output between 1 and N, unless bound is .false.\n ! TODO: This is not an integer bin, its the integer Nearest.\n real(r64) :: this\n integer(i32) :: n\n logical :: bound\n integer(i32) :: i\n i=idnint(this)\n if (bound) then\n if (i < 1) i=1\n if (i > n) i=n\n endif\n end function\n !====================================================================!\n end module\n", "meta": {"hexsha": "257c985e42e130a3e3f2ff74c559063633c3be73", "size": 2569, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "docs/src/m_indexing.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/core/m_indexing.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": "docs/src/m_indexing.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.5189873418, "max_line_length": 112, "alphanum_fraction": 0.4842351109, "num_tokens": 669, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835289107309, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.6730924223046544}} {"text": "module single\n integer, parameter :: float = selected_real_kind ( 6,37 )\n real ( float ) :: pi = 3.1415927_float\n real ( float ) :: e = 2.7182818_float\nend module single\n\nmodule double\n integer, parameter :: float = selected_real_kind ( 15,37 )\n real ( float ) :: pi = 3.141592653589793_float\n real ( float ) :: e = 2.718281828459045_float\nend module double\n\nprogram constants\n !\n ! Select a precision for the constants for PI and E.\n ! USE SINGLE selects single precision whereas\n ! USE DOUBLE selects double precision. Only one\n ! precision can be in selected per subprogram.\n ! Let the main program select single precision.\n use single\n character (len=60) :: pi_single\n character (len=60) :: e_single\n integer :: eslen, pislen\n write (UNIT=pi_single, FMT=*) pi\n write (UNIT=e_single, FMT=*) e\n pislen=len_trim(adjustl(pi_single))\n eslen=len_trim(adjustl(e_single))\n if((pislen.GE.7).AND.(eslen.GE.7)) then\n call more_precision\n else\n print *, \"failed\"\n end if\nend program constants\n\nsubroutine more_precision\n !\n ! Let the subroutine select double precision.\n use double\n character (len=60) :: pi_double\n character (len=60) :: e_double\n integer :: edlen, pidlen\n write (UNIT=pi_double, FMT=*) pi\n write (UNIT=e_double, FMT=*) e\n pidlen=len_trim(adjustl(pi_double))\n edlen=len_trim(adjustl(e_double))\n\n if((pidlen.GE.16).AND.(edlen.GE.16)) then\n print *, \"OK\"\n else\n print *, \"failed\"\n end if\nend subroutine more_precision\n", "meta": {"hexsha": "2e9b5da87f9f93548c85ce5e6c9ff081405358bb", "size": 1504, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/CompileTests/Fortran_tests/test2011_49.f90", "max_stars_repo_name": "maurizioabba/rose", "max_stars_repo_head_hexsha": "7597292cf14da292bdb9a4ef573001b6c5b9b6c0", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/CompileTests/Fortran_tests/test2011_49.f90", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/CompileTests/Fortran_tests/test2011_49.f90", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 28.3773584906, "max_line_length": 60, "alphanum_fraction": 0.6875, "num_tokens": 454, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424373085146, "lm_q2_score": 0.7956581049086031, "lm_q1q2_score": 0.6730809565306575}} {"text": "!**********************************************************************************************************************************\n!\n! PROGRAM: Test_NWTC_Library\n!\n! PURPOSE: Tests the functionality of the NWTC Subroutine Library using IVF for Windows.\n! \n! TESTED ROUTINES:\n! NWTC_Init\n! WrScr\n! WrScr1\n! Num2LStr: Int2LStr, R2LStr16\n! TESTED DATA/PARAMETERS:\n! QuKi\n! \n\n!**********************************************************************************************************************************\n\nPROGRAM Test_NWTC_Library\n\n USE NWTC_Library\n USE NWTC_LAPACK\n \n \n IMPLICIT NONE \n \n \n\n ! Variables\n\n ! IVF for Windows hard-coded kinds\n \n REAL(16) :: Real16Var ! a 16-byte real variable\n REAL(8) :: Real8Var ! an 8-byte real variable\n REAL(4) :: Real4Var ! a 4-byte real variable\n \n ! Type-specific Library kinds\n \n REAL(QuKi) :: RealQuVar ! a 16-byte real variable\n REAL(R8Ki) :: RealR8Var ! an 8-byte real variable\n REAL(SiKi) :: RealSiVar ! a 4-byte real variable\n \n ! Default kinds from Library\n \n REAL(ReKi) :: RealReVar ! a default real variable (different in SingPrec.f90 or DoubPrec.f90)\n REAL(DbKi) :: RealDbVar ! a default double variable (different in SingPrec.f90 or DoubPrec.f90)\n \n \n REAL(ReKi), ALLOCATABLE :: RealReAry(:)\n \n ! File name\n CHARACTER(1024) :: InputFileName = 'TestData/TestLibrary_InputFile.txt'\n \n INTEGER(IntKi) :: ErrStat\n CHARACTER(1024) :: ErrMsg\n \n \n INTEGER(IntKi), ALLOCATABLE :: TempVec(:,:)\n INTEGER(IntKi), ALLOCATABLE :: IC(:)\n integer,parameter :: NMX = 9\n integer :: i, j, k, i4\n \n integer, parameter:: m=5\n integer, parameter:: n=5\n double precision :: a(m,n), b(n)\n integer :: ipiv(m)\n\n type(meshtype) :: mesh1, mesh2, mesh3\n \n \n integer,parameter :: ndims=10\n real(reki),dimension(ndims,3) :: vec1, vec2\n real(reki),dimension(3,ndims) :: vec11, vec21\n real(reki),dimension(3) :: vec3\n \n REAL time_begin, time_end\n \n \n integer,parameter :: nx=1, ny=1, nz=2, n4=1\n complex(ReKi) :: data2d(nx,nz), data3d(nx,nz,n4) , data4d(nx,ny,nz,n4) ,interpVal \n real(reki) :: x(nx), y(ny), z(nz), w(n4), InCoord2(2), InCoord(3), InCoord4(4)\n integer :: LastIndex(3) = 0, LastIndex4(4) = 0, LastIndex2(2) = 0\n !............................................................................................................................... \n ! Initialize the library\n !............................................................................................................................... \n \n CALL NWTC_Init( )\n\n !print *, sqrt(epsilon(1.0_ReKi)), sqrt(epsilon(1.0_SiKi)), sqrt(epsilon(1.0_R8Ki))\n !stop\n \n call Test_TestMeshMapping()\n stop\n \n !............................................................................................................................... \n ! arrays for interpolation: \n \n#ifdef WAMIT_INTERPOLATION \n \n do i=1,n4\n w(i) = -120 + (i-1) * 200/max(1,n4-1) \n end do\n \n do i=1,nz\n z(i) = -180 + (i-1) * 90/max(1,nz-1) \n end do\n \n do i=1,ny\n y(i) = -10 + (i-1)*20 \n end do\n\n do i=1,nx\n x(i) = (i-1)*10\n end do \n \n !............................................................................................................................... \n ! 2d interpolation: \n \nprint *, x\nprint *, z\n \n data2d = 0.0_ReKi\n do j =1,nz\n do i =1,nx\n data2d(i,j) = (j-1)*nx + i\n end do\n end do\n \n do j =1,nz \n do i =1,nx\n InCoord2(1) = x(i) \n InCoord2(2) = z(j) + 45\n \n call WAMIT_Interp2D_Cplx( InCoord2, data2d, x, z, LastIndex2, interpVal, ErrStat, ErrMsg ) \n\n!if ( .not. equalrealnos( REAL(data2d(i,j)), REAL(interpVal) ) .or. &\n! .not. equalrealnos( IMAG(data2d(i,j)), IMAG(interpVal) ) ) then \n!print *, '----------------- not equal ---------------------------------------------------'\nprint *, '**** ', i, j, ' ****' \nprint *, '' \nprint *, 'input value:', InCoord2\n \nprint *, 'data at point:', data2d(i,j)\nprint *, 'interp data :', interpVal\nprint *, '-------------------------------------------------------------------------------'\n!end if\n \n end do\n end do\n \n \n !............................................................................................................................... \n ! 3d interpolation: \n \n data3d = 0.0_ReKi\n do k=1,n4\n do j =1,nz\n do i =1,nx\n data3d(i,j,k) = (k-1)*(nx*nz) + (j-1)*nx + i\n end do\n end do\n end do\n \n do k=1,n4\n do j =1,nz \n do i =1,nx\n InCoord(1) = x(i)\n InCoord(2) = z(j)\n InCoord(3) = w(k)\n \n \n call WAMIT_Interp3D_Cplx( InCoord, data3d, x, z, w, LastIndex, interpVal, ErrStat, ErrMsg ) \n\nif ( .not. equalrealnos( REAL(data3d(i,j,k)), REAL(interpVal) ) .or. &\n .not. equalrealnos( IMAG(data3d(i,j,k)), IMAG(interpVal) ) ) then \nprint *, '----------------- not equal ---------------------------------------------------'\nprint *, '**** ', i, j, k, ' ****' \nprint *, '' \nprint *, 'input value:', InCoord\n \nprint *, 'data at point:', data3d(i,j,k)\nprint *, 'interp data :', interpVal\nprint *, '-------------------------------------------------------------------------------'\nend if\n \n end do\n end do\n end do\n \n \n !............................................................................................................................... \n ! 4d interpolation: \n data4d = 0.0_ReKi\n do i4 = 1,n4\n do k=1,nz\n do j =1,ny\n do i =1,nx\n data4d(i,j,k,i4) = (i4-1)*nz*ny*nx + (k-1)*(nx*ny) + (j-1)*nx + i\n end do\n end do\n end do\n end do \n \n \n do i4 = 1,n4\n do k=1,nz\n do j =1,ny \n do i =1,nx\n InCoord4(1) = x(i)\n InCoord4(2) = y(j)\n InCoord4(3) = z(k)\n InCoord4(4) = w(i4)\n \n \n call WAMIT_Interp4D_Cplx( InCoord4, data4d, x, y, z, w, LastIndex4, interpVal, ErrStat, ErrMsg ) \n\nif ( .not. equalrealnos( REAL(data4d(i,j,k,i4)), REAL(interpVal) ) .or. &\n .not. equalrealnos( IMAG(data4d(i,j,k,i4)), IMAG(interpVal) ) ) then \nprint *, '----------------- not equal ---------------------------------------------------'\nprint *, '**** ', i, j, k, i4 , ' ****' \nprint *, '' \nprint *, 'input value:', InCoord4\n \nprint *, 'data at point:', data4d(i,j,k,i4)\nprint *, 'interp data :', interpVal\nprint *, '-------------------------------------------------------------------------------'\nend if\n end do \n end do\n end do\n end do\n \n \n stop\n#endif \n !............................................................................................................................... \n ! Test cross_product timing with array dimensions\n !............................................................................................................................... \n \n do k=1,5\n \n CALL CPU_TIME(time_begin)\n vec1 = 1.;\n vec2 = 2.\n do i=1,ndims \n vec1(i,1) = i \n vec1(i,2) = 0.2\n vec1(i,3) = 0.25\n do j=1,20\n vec3 = cross_product(vec1(i,:), vec2(i,:))\n vec1(i,:) = vec3\n end do \n end do\n print *, vec3\n print *, vec1(1,:)\n CALL CPU_TIME ( time_end )\n WRITE (*,*) 'Time of operation A was ', time_end - time_begin, ' seconds'\n \n CALL CPU_TIME(time_begin)\n vec11 = 1.;\n vec21 = 2.\n do i=1,ndims \n vec11(1,i) = i \n vec11(2,i) = 0.2\n vec11(3,i) = 0.25\n do j=1,20\n vec3 = cross_product(vec11(:,i), vec21(:,i))\n vec11(:,i) = vec3\n end do \n end do\n print *, vec3\n print *, vec11(:,i)\n CALL CPU_TIME ( time_end )\n WRITE (*,*) 'Time of operation B was ', time_end - time_begin, ' seconds'\n \n end do\n \nstop;\n \n !............................................................................................................................... \n ! Test interface with LAPACK\n !............................................................................................................................... \n \n call LAPACK_GETRF( m, n, a, IPIV, ErrStat, ErrMsg )\n print *, 'LAPACK_Getrf: ', ErrStat, TRIM(ErrMsg) \n \n call LAPACK_GETRs( 'N', n, a, IPIV, b, ErrStat, ErrMsg )\n print *, 'LAPACK_GETRs: ', ErrStat, TRIM(ErrMsg) \n \n \n !............................................................................................................................... \n ! Let's check that the PRECISION kinds are specified correctly:\n !............................................................................................................................... \n CALL WrScr( 'Real KIND parameters:' )\n CALL WrScr( ' QuKi is '//Num2LStr(QuKi)//'-> It should be 16.' )\n CALL WrScr( ' R8Ki is '//Num2LStr(R8Ki)//'-> It should be 8.' )\n CALL WrScr( ' SiKi is '//Num2LStr(SiKi)//'-> It should be 4.' )\n CALL WrScr1(' ReKi is '//Num2LStr(ReKi) )\n CALL WrScr( ' DbKi is '//Num2LStr(DbKi) )\n \n !............................................................................................................................... \n ! Test NWTC_Num routines: EqualRealNos \n !............................................................................................................................... \n \n CALL WrScr1( ' Testing EqualRealNos for quad kinds: ')\n\n Real16Var = 5.0_QuKi\n RealQuVar = Real16Var + 0.00005_QuKi\n\n print *, Real16Var\n print *, RealQuVar \n \n IF ( EqualRealNos ( Real16Var, RealQuVar ) ) THEN\n CALL WrScr( ' '//TRIM(Num2LStr(Real16Var))//' is approximately equal to '//Num2LStr(RealQuVar) )\n ELSE \n CALL WrScr( ' '//TRIM(Num2LStr(Real16Var))//' is not equal to '//Num2LStr(RealQuVar) )\n\n END IF \n \n \n CALL WrScr1( ' Testing EqualRealNos for double kinds: ')\n Real8Var = 5.0_R8Ki\n RealR8Var = Real8Var + 0.00005_R8Ki\n \n print *, Real8Var\n print *, RealR8Var\n \n IF ( EqualRealNos ( Real8Var, RealR8Var ) ) THEN\n CALL WrScr( ' '//TRIM(Num2LStr(Real8Var))//' is approximately equal to '//Num2LStr(RealR8Var) )\n ELSE \n CALL WrScr( ' '//TRIM(Num2LStr(Real8Var))//' is not equal to '//Num2LStr(RealR8Var) )\n\n END IF \n \n \n CALL WrScr1( ' Testing EqualRealNos for single kinds: ')\n Real4Var = 5.0_SiKi\n RealSiVar = Real8Var + 0.00005_SiKi\n \n print *, Real4Var\n print *, RealSiVar \n \n IF ( EqualRealNos ( Real4Var, RealSiVar ) ) THEN\n CALL WrScr( ' '//TRIM(Num2LStr(Real4Var))//' is approximately equal to '//Num2LStr(RealSiVar) )\n ELSE \n CALL WrScr( ' '//TRIM(Num2LStr(Real4Var))//' is not equal to '//Num2LStr(RealSiVar) )\n END IF \n \n \n !............................................................................................................................... \n ! Test Formatted Input File:\n !............................................................................................................................... \n \n !CALL OpenFInpFile( )\n \n!INTEGER(IntKi) :: TempVec(3,2)\n allocate( TempVec(3,2) )\n \n TempVec(:,1) = (/ 1, 2, 3 /)\n TempVec(:,2) = TempVec(:,1)*6\n \n print *, TempVec\n \n print *, 'SIZE = ', SIZE(TempVec)\n \n print *, PACK(TempVec,.TRUE.)\n print *, TempVec(1:SIZE(TempVec),1)\n \n print *, TempVec(1:6,1)\n \n \n call WrScr(' This is line 1.'//CHAR(10)//' This is line 2.')\n \n\n call WrScr(NewLine//' This is line 1.'//NewLine//' This is line 2.'//NewLine//' This is line 3.')\n CALL WrScr(NewLine//NewLine//NewLine//'This is really important'//NewLine//NewLine//&\n ' This is line 2 a really long line that i need to be more than 98 characters so that it will print on two lines. is this long enough, yet. I''m not sure' )\n \n call wrscr('')\n call wrscr(' one line' )\n call wrscr(' two lines.')\n \n do i=-1,6\n call wrscr( GetErrStr(i) )\n end do\n \n \n deallocate(TempVec)\n \n \n print *, 'This is the size of a deallocated array: ', size(TempVec), allocated(TempVec)\n print *, 'This is the size of a deallocated array: ', size(RealReAry), allocated(RealReAry)\n \n RealR8Var = 0.00000001_DbKi\n print *, MOD( NINT(RealR8Var), 10 ) == 1 \n RealR8Var = 1.00000001_DbKi \n print *, MOD( NINT(RealR8Var), 10 ) == 1 \n RealR8Var = 10.00000001_DbKi \n print *, MOD( NINT(RealR8Var), 10 ) == 1 \n RealR8Var = 10.00000001_DbKi + 1.0\n print *, MOD( NINT(RealR8Var), 10 ) == 1 \n \n \n \n!---------------------------- \n !allocate( IC( NMX ) )\n !\n !IC(1) = 1\n !DO I = 2,NMX\n ! IC(I) = IC(1) - I + 1 + NMX\n !ENDDO\n !\n !write( *, '( A, I1, A, '//TRIM(Num2LStr(NMX))//'(I2,1X) )') 'SHIFT ', 0, ': ', IC\n !\n !DO j = 1,10\n !\n ! IC(1) = IC(1) + 1\n ! IF ( IC(1) > NMX ) IC(1) = IC(1) - NMX\n ! DO I = 2,NMX\n ! IC(I) = IC(1) - I + 1\n ! IF ( IC(I) <= 0 ) IC(I) = IC(I) + NMX\n ! ENDDO \n !\n ! write ( *, '( A, I1, A, '//TRIM(Num2LStr(NMX))//'(I2,1X) )') 'SHIFT ', j, ': ', IC\n !\n !end do\n !\n !print *, ' '\n !\n !IC(1) = 1\n !DO I = 2,NMX\n ! IC(I) = IC(1) - I + 1 + NMX\n !ENDDO\n !\n !write( *, '( A, I1, A, '//TRIM(Num2LStr(NMX))//'(I2,1X) )') 'SHIFT ', 0, ': ', IC\n !\n !DO j = 1,10\n !\n ! IC = CSHIFT( IC, -1 ) \n ! write( *, '( A, I1, A, '//TRIM(Num2LStr(NMX))//'(I2,1X) )') 'SHIFT ', j, ': ', IC\n !\n !\n !end do\n !\n !deallocate( IC )\n\n !-----------------------------------------------------------\n ! Test some mesh routines:\n !-----------------------------------------------------------\n\n CALL WRSCR( 'start of mesh tests:' ) \n ! PAUSE\n \n \n i = 2\n \n CALL MeshCreate( BlankMesh = Mesh1 &\n ,IOS = COMPONENT_INPUT &\n ,NNodes = i &\n ,Force = .TRUE. &\n ,Moment = .TRUE. &\n ,ErrStat = ErrStat &\n ,ErrMess = ErrMsg ) \n\n do j=1,i\n ! place nodes in a line\n CALL MeshPositionNode ( Mesh1, j, (/0.0_ReKi, 0.0_ReKi, j*1.0_ReKi /), ErrStat, ErrMsg ) \n IF (ErrStat /= ErrID_None) CALL WrScr(TRIM(ErrMsg))\n \n ! create an element from this point \n \n CALL MeshConstructElement ( Mesh1, ELEMENT_POINT, ErrStat, ErrMsg, j )\n IF (ErrStat /= ErrID_None) CALL WrScr(TRIM(ErrMsg)) \n\n END DO\n \n ! that's our entire mesh:\n CALL MeshCommit ( Mesh1, ErrStat, ErrMsg ) \n IF (ErrStat /= ErrID_None) CALL WrScr(TRIM(ErrMsg)) \n Mesh1%Force = 1.\n Mesh1%Moment = 0.\n \n CALL WRSCR( 'finished creating mesh 1' ) \n if (i<5) THEN\n CALL WRSCR( 'mesh 1 info:' ) \n call meshprintinfo(CU,Mesh1) \n end if\n ! PAUSE\n \n CALL MeshCopy ( SrcMesh = Mesh1 &\n , DestMesh = Mesh2 &\n , CtrlCode = MESH_SIBLING &\n , RotationVel = .TRUE. &\n , ErrStat = ErrStat &\n , ErrMess = ErrMsg )\n \n \n CALL WRSCR( 'finished creating sibling mesh 2' )\n Mesh2%RotationVel = 3\n \n if (i<5) THEN\n CALL WRSCR( 'mesh 2 info:' ) \n call meshprintinfo(CU,Mesh2) \n end if\n ! PAUSE\n\n CALL MeshCopy ( SrcMesh = Mesh1 &\n , DestMesh = Mesh3 &\n , CtrlCode = MESH_NEWCOPY &\n , ErrStat = ErrStat &\n , ErrMess = ErrMsg )\n \n CALL WRSCR( 'finished creating new mesh 3' )\n MESH3%Force=10\n if (i<5) THEN\n CALL WRSCR( 'mesh 3 info:' ) \n call meshprintinfo(CU,Mesh3) \n end if\n !PAUSE\n \n CALL MeshDestroy( Mesh2, ErrStat, ErrMsg, .TRUE. ) !delete only mesh 2 (not its sibling, too)\n if (i<5) THEN\n CALL WRSCR( 'mesh 1 info:' ) \n call meshprintinfo(CU,Mesh1) \n end if\n CALL WRSCR( 'finished deleting mesh 2' ) \n !PAUSE\n \n CALL MeshCopy ( SrcMesh = Mesh1 &\n , DestMesh = Mesh2 &\n , CtrlCode = MESH_SIBLING &\n , TranslationDisp = .TRUE. &\n , Orientation = .TRUE. &\n , RotationVel = .TRUE. &\n , TranslationVel = .TRUE. &\n , RotationAcc = .TRUE. &\n , TranslationAcc = .TRUE. &\n , ErrStat = ErrStat &\n , ErrMess = ErrMsg )\n \n \n CALL WRSCR( 'finished creating sibling mesh 2' )\n !PAUSE\n \n \n CALL MeshDestroy( Mesh2, ErrStat, ErrMsg, .true. ) !delete mesh 2 BUT NOT its sibling (mesh 1)\n CALL WRSCR( 'finished deleting mesh 1' )\n !CALL MeshDestroy( Mesh2, ErrStat, ErrMsg, .FALSE. ) !delete both mesh 2 and its sibling (mesh 1)\n !CALL WRSCR( 'finished deleting meshes 1 and 2' )\n !PAUSE\n\n CALL MeshDestroy( Mesh3, ErrStat, ErrMsg ) !delete mesh 3\n CALL WRSCR( 'finished deleting mesh 3' ) \n !PAUSE\n \n CALL WRSCR( 'finished this test' ) \n ! PAUSE\n \n do i=1,10000\n print *, i, 'Copy:'\n CALL MeshCopy ( SrcMesh = Mesh1 &\n , DestMesh = Mesh3 &\n , CtrlCode = MESH_NEWCOPY &\n , ErrStat = ErrStat &\n , ErrMess = ErrMsg )\n IF (ErrStat/=ErrID_None) print *, TRIM(ErrMsg)\n \n print *, i, 'Destroy:'\n CALL MeshDestroy( Mesh3, ErrStat, ErrMsg, .FALSE. ) !delete mesh 3\n IF (ErrStat/=ErrID_None) print *, TRIM(ErrMsg)\n \n \n END DO\n \n \n CALL MeshDestroy( Mesh1, ErrStat, ErrMsg, .FALSE. )\n CALL WRSCR( 'finished mesh copy/destroy test' ) \n !! PAUSE\n\n !-----------------------------------------------------------\n \n \nEND PROGRAM Test_NWTC_Library\n\n", "meta": {"hexsha": "9583ef435512d4cef9375481766b8a880daeb323", "size": 18329, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "modules-local/nwtc-library/test/Test_NWTC_Library.f90", "max_stars_repo_name": "abhineet-gupta/openfast", "max_stars_repo_head_hexsha": "e788b9b18bd5ed96ea59d4bc0812d461bc430cfe", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 384, "max_stars_repo_stars_event_min_datetime": "2017-08-13T18:41:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T22:33:55.000Z", "max_issues_repo_path": "modules-local/nwtc-library/test/Test_NWTC_Library.f90", "max_issues_repo_name": "abhineet-gupta/openfast", "max_issues_repo_head_hexsha": "e788b9b18bd5ed96ea59d4bc0812d461bc430cfe", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 802, "max_issues_repo_issues_event_min_datetime": "2017-04-17T15:19:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:32:37.000Z", "max_forks_repo_path": "modules-local/nwtc-library/test/Test_NWTC_Library.f90", "max_forks_repo_name": "abhineet-gupta/openfast", "max_forks_repo_head_hexsha": "e788b9b18bd5ed96ea59d4bc0812d461bc430cfe", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 291, "max_forks_repo_forks_event_min_datetime": "2017-04-27T21:52:50.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T17:51:36.000Z", "avg_line_length": 31.3852739726, "max_line_length": 166, "alphanum_fraction": 0.4289377489, "num_tokens": 5291, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424373085145, "lm_q2_score": 0.7956581000631541, "lm_q1q2_score": 0.6730809524316864}} {"text": " SUBROUTINE MB03UD( JOBQ, JOBP, N, A, LDA, Q, LDQ, SV, DWORK,\n $ LDWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute all, or part, of the singular value decomposition of a\nC real upper triangular matrix.\nC\nC The N-by-N upper triangular matrix A is factored as A = Q*S*P',\nC where Q and P are N-by-N orthogonal matrices and S is an\nC N-by-N diagonal matrix with non-negative diagonal elements,\nC SV(1), SV(2), ..., SV(N), ordered such that\nC\nC SV(1) >= SV(2) >= ... >= SV(N) >= 0.\nC\nC The columns of Q are the left singular vectors of A, the diagonal\nC elements of S are the singular values of A and the columns of P\nC are the right singular vectors of A.\nC\nC Either or both of Q and P' may be requested.\nC When P' is computed, it is returned in A.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC JOBQ CHARACTER*1\nC Specifies whether the user wishes to compute the matrix Q\nC of left singular vectors as follows:\nC = 'V': Left singular vectors are computed;\nC = 'N': No left singular vectors are computed.\nC\nC JOBP CHARACTER*1\nC Specifies whether the user wishes to compute the matrix P'\nC of right singular vectors as follows:\nC = 'V': Right singular vectors are computed;\nC = 'N': No right singular vectors are computed.\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The order of the matrix A. N >= 0.\nC\nC A (input/output) DOUBLE PRECISION array, dimension (LDA,N)\nC On entry, the leading N-by-N upper triangular part of this\nC array must contain the upper triangular matrix A.\nC On exit, if JOBP = 'V', the leading N-by-N part of this\nC array contains the N-by-N orthogonal matrix P'; otherwise\nC the N-by-N upper triangular part of A is used as internal\nC workspace. The strictly lower triangular part of A is set\nC internally to zero before the reduction to bidiagonal form\nC is performed.\nC\nC LDA INTEGER\nC The leading dimension of array A. LDA >= MAX(1,N).\nC\nC Q (output) DOUBLE PRECISION array, dimension (LDQ,N)\nC If JOBQ = 'V', the leading N-by-N part of this array\nC contains the orthogonal matrix Q.\nC If JOBQ = 'N', Q is not referenced.\nC\nC LDQ INTEGER\nC The leading dimension of array Q.\nC LDQ >= 1, and when JOBQ = 'V', LDQ >= MAX(1,N).\nC\nC SV (output) DOUBLE PRECISION array, dimension (N)\nC The N singular values of the matrix A, sorted in\nC descending order.\nC\nC Workspace\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0, DWORK(1) returns the optimal LDWORK;\nC if INFO > 0, DWORK(2:N) contains the unconverged\nC superdiagonal elements of an upper bidiagonal matrix B\nC whose diagonal is in SV (not necessarily sorted).\nC B satisfies A = Q*B*P', so it has the same singular\nC values as A, and singular vectors related by Q and P'.\nC\nC LDWORK INTEGER\nC The length of the array DWORK.\nC LDWORK >= MAX(1,5*N).\nC For optimum performance LDWORK should be larger.\nC\nC If LDWORK = -1, then a workspace query is assumed;\nC the routine only calculates the optimal size of the\nC DWORK array, returns this value as the first entry of\nC the DWORK array, and no error message related to LDWORK\nC is issued by XERBLA.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value;\nC > 0: the QR algorithm has failed to converge. In this\nC case INFO specifies how many superdiagonals did not\nC converge (see the description of DWORK).\nC This failure is not likely to occur.\nC\nC METHOD\nC\nC The routine reduces A to bidiagonal form by means of elementary\nC reflectors and then uses the QR algorithm on the bidiagonal form.\nC\nC CONTRIBUTOR\nC\nC V. Sima, Research Institute of Informatics, Bucharest, and\nC A. Varga, German Aerospace Center, DLR Oberpfaffenhofen,\nC March 1998. Based on the RASP routine DTRSVD.\nC\nC REVISIONS\nC\nC V. Sima, Feb. 2000, Aug. 2011.\nC\nC KEYWORDS\nC\nC Bidiagonalization, orthogonal transformation, singular value\nC decomposition, singular values, triangular form.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ONE, ZERO\n PARAMETER ( ONE = 1.0D0, ZERO = 0.0D0 )\nC .. Scalar Arguments ..\n CHARACTER JOBP, JOBQ\n INTEGER INFO, LDA, LDQ, LDWORK, N\nC .. Array Arguments ..\n DOUBLE PRECISION A(LDA,*), DWORK(*), Q(LDQ,*), SV(*)\nC .. Local Scalars ..\n LOGICAL LQUERY, WANTQ, WANTP\n INTEGER I, IE, ISCL, ITAUP, ITAUQ, JWORK, MAXWRK,\n $ MINWRK, NCOLP, NCOLQ\n DOUBLE PRECISION ANRM, BIGNUM, EPS, SMLNUM\nC .. Local Arrays ..\n DOUBLE PRECISION DUM(1)\nC .. External Functions ..\n LOGICAL LSAME\n DOUBLE PRECISION DLAMCH, DLANTR\n EXTERNAL DLAMCH, DLANTR, LSAME\nC .. External Subroutines ..\n EXTERNAL DBDSQR, DGEBRD, DLACPY, DLASCL, DLASET, DORGBR,\n $ XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC INT, MAX, SQRT\nC .. Executable Statements ..\nC\nC Check the input scalar arguments.\nC\n INFO = 0\n WANTQ = LSAME( JOBQ, 'V' )\n WANTP = LSAME( JOBP, 'V' )\n IF( .NOT.WANTQ .AND. .NOT.LSAME( JOBQ, 'N' ) ) THEN\n INFO = -1\n ELSE IF( .NOT.WANTP .AND. .NOT.LSAME( JOBP, 'N' ) ) THEN\n INFO = -2\n ELSE IF( N.LT.0 ) THEN\n INFO = -3\n ELSE IF( LDA.LT.MAX( 1, N ) ) THEN\n INFO = -5\n ELSE IF( ( WANTQ .AND. LDQ.LT.MAX( 1, N ) ) .OR.\n $ ( .NOT.WANTQ .AND. LDQ.LT.1 ) ) THEN\n INFO = -7\n ELSE\nC\nC Compute workspace\nC (Note: Comments in the code beginning \"Workspace:\" describe the\nC minimal amount of workspace needed at that point in the code,\nC as well as the preferred amount for good performance.\nC NB refers to the optimal block size for the immediately\nC following subroutine, as returned by ILAENV.)\nC\n MINWRK = MAX( 1, 5*N )\n LQUERY = LDWORK.EQ.-1\n IF ( LQUERY ) THEN\n CALL DGEBRD( N, N, A, LDA, SV, DWORK, DWORK, DWORK, DWORK,\n $ -1, INFO )\n MAXWRK = INT( DWORK(1) )\n IF( WANTQ ) THEN\n CALL DORGBR( 'Q', N, N, N, Q, LDQ, DWORK, DWORK, -1,\n $ INFO )\n MAXWRK = MAX( MAXWRK, INT( DWORK(1) ) )\n END IF\n IF( WANTP ) THEN\n CALL DORGBR( 'P', N, N, N, A, LDA, DWORK, DWORK, -1,\n $ INFO )\n MAXWRK = MAX( MAXWRK, INT( DWORK(1) ) )\n END IF\n MAXWRK = MAX( 3*N + MAXWRK, MINWRK )\n END IF\n IF( LDWORK.LT.MINWRK .AND. .NOT.LQUERY )\n $ INFO = -10\n END IF\nC\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'MB03UD', -INFO )\n RETURN\n ELSE IF( LQUERY ) THEN\n DWORK(1) = MAXWRK\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF( N.EQ.0 ) THEN\n DWORK(1) = ONE\n RETURN\n END IF\nC\nC Get machine constants.\nC\n EPS = DLAMCH( 'P' )\n SMLNUM = SQRT( DLAMCH( 'S' ) ) / EPS\n BIGNUM = ONE / SMLNUM\nC\nC Scale A if max entry outside range [SMLNUM,BIGNUM].\nC\n ANRM = DLANTR( 'Max', 'Upper', 'Non-unit', N, N, A, LDA, DUM )\n ISCL = 0\n IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN\n ISCL = 1\n CALL DLASCL( 'Upper', 0, 0, ANRM, SMLNUM, N, N, A, LDA, INFO )\n ELSE IF( ANRM.GT.BIGNUM ) THEN\n ISCL = 1\n CALL DLASCL( 'Upper', 0, 0, ANRM, BIGNUM, N, N, A, LDA, INFO )\n END IF\nC\nC Zero out below.\nC\n IF ( N.GT.1 )\n $ CALL DLASET( 'Lower', N-1, N-1, ZERO, ZERO, A(2,1), LDA )\nC\nC Find the singular values and optionally the singular vectors\nC of the upper triangular matrix A.\nC\n IE = 1\n ITAUQ = IE + N\n ITAUP = ITAUQ + N\n JWORK = ITAUP + N\nC\nC First reduce the matrix to bidiagonal form. The diagonal\nC elements will be in SV and the superdiagonals in DWORK(IE).\nC (Workspace: need 4*N, prefer 3*N+2*N*NB)\nC\n CALL DGEBRD( N, N, A, LDA, SV, DWORK(IE), DWORK(ITAUQ),\n $ DWORK(ITAUP), DWORK(JWORK), LDWORK-JWORK+1, INFO )\n MAXWRK = MAX( MAXWRK, INT( DWORK(JWORK) ) + JWORK - 1 )\n IF( WANTQ ) THEN\nC\nC Generate the transformation matrix Q corresponding to the\nC left singular vectors.\nC (Workspace: need 4*N, prefer 3*N+N*NB)\nC\n NCOLQ = N\n CALL DLACPY( 'Lower', N, N, A, LDA, Q, LDQ )\n CALL DORGBR( 'Q', N, N, N, Q, LDQ, DWORK(ITAUQ), DWORK(JWORK),\n $ LDWORK-JWORK+1, INFO )\n MAXWRK = MAX( MAXWRK, INT( DWORK(JWORK) ) + JWORK - 1 )\n ELSE\n NCOLQ = 0\n END IF\n IF( WANTP ) THEN\nC\nC Generate the transformation matrix P' corresponding to the\nC right singular vectors.\nC (Workspace: need 4*N, prefer 3*N+N*NB)\nC\n NCOLP = N\n CALL DORGBR( 'P', N, N, N, A, LDA, DWORK(ITAUP), DWORK(JWORK),\n $ LDWORK-JWORK+1, INFO )\n MAXWRK = MAX( MAXWRK, INT( DWORK(JWORK) ) + JWORK - 1 )\n ELSE\n NCOLP = 0\n END IF\n JWORK = IE + N\nC\nC Perform bidiagonal QR iteration, to obtain all or part of the\nC singular value decomposition of A.\nC (Workspace: need 5*N)\nC\n CALL DBDSQR( 'U', N, NCOLP, NCOLQ, 0, SV, DWORK(IE), A, LDA,\n $ Q, LDQ, DUM, 1, DWORK(JWORK), INFO )\nC\nC If DBDSQR failed to converge, copy unconverged superdiagonals\nC to DWORK(2:N).\nC\n IF( INFO.NE.0 ) THEN\n DO 10 I = N - 1, 1, -1\n DWORK(I+1) = DWORK(I+IE-1)\n 10 CONTINUE\n END IF\nC\nC Undo scaling if necessary.\nC\n IF( ISCL.EQ.1 ) THEN\n IF( ANRM.GT.BIGNUM )\n $ CALL DLASCL( 'G', 0, 0, BIGNUM, ANRM, N, 1, SV, N, INFO )\n IF( INFO.NE.0 .AND. ANRM.GT.BIGNUM )\n $ CALL DLASCL( 'G', 0, 0, BIGNUM, ANRM, N-1, 1, DWORK(2), N,\n $ INFO )\n IF( ANRM.LT.SMLNUM )\n $ CALL DLASCL( 'G', 0, 0, SMLNUM, ANRM, N, 1, SV, N, INFO )\n IF( INFO.NE.0 .AND. ANRM.LT.SMLNUM )\n $ CALL DLASCL( 'G', 0, 0, SMLNUM, ANRM, N-1, 1, DWORK(2), N,\n $ INFO )\n END IF\nC\nC Return optimal workspace in DWORK(1).\nC\n DWORK(1) = MAXWRK\nC\n RETURN\nC *** Last line of MB03UD ***\n END\n", "meta": {"hexsha": "f71ad896afcb5e7d6c09f6f39b2453341ad8dcdc", "size": 11126, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB03UD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB03UD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB03UD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 34.6604361371, "max_line_length": 72, "alphanum_fraction": 0.5528491821, "num_tokens": 3462, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897442783526, "lm_q2_score": 0.7154239836484143, "lm_q1q2_score": 0.673063546627192}} {"text": "module pmmf_fic_case3\n#include \n use mod_kinds, only: rk,ik\n use mod_constants, only: ZERO, HALF, ONE, TWO, THREE, FOUR, FIVE, EIGHT, PI\n use type_prescribed_mesh_motion_function, only: prescribed_mesh_motion_function_t\n implicit none\n private\n\n\n\n !> Flow In Cylinder - case3 prescribed motion. \n !!\n !! @author Nathan A. Wukie\n !! @date 10/02/2019 \n !!\n !-------------------------------------------------------------------------------\n type, extends(prescribed_mesh_motion_function_t), public :: fic_case3_pmmf\n private\n\n contains\n\n procedure :: init\n procedure :: compute_pos\n procedure :: compute_vel\n\n end type fic_case3_pmmf\n !********************************************************************************\n\n\n\ncontains\n\n\n\n\n !>\n !!\n !! @author Nathan A. Wukie\n !! @date 10/02/2019 \n !!\n !-------------------------------------------------------------------------\n subroutine init(self)\n class(fic_case3_pmmf), intent(inout) :: self\n\n ! Set function name\n call self%set_name(\"Flow In Cylinder - Case3\")\n\n end subroutine init\n !*************************************************************************\n\n\n\n !>\n !!\n !! @author Nathan A. Wukie\n !! @date 10/02/2019\n !!\n !!\n !-----------------------------------------------------------------------------------------\n function compute_pos(self,time,node) result(val)\n class(fic_case3_pmmf), intent(inout) :: self\n real(rk), intent(in) :: time\n real(rk), intent(in) :: node(3)\n\n real(rk) :: val(3)\n real(rk) :: Aa, alpha, psi, x0, y0, r0, theta0, &\n a, b, e, r, x_ale, y_ale\n\n Aa = 1.5\n alpha = time**TWO*(THREE-time)/FOUR\n psi = ONE + (Aa - ONE)*alpha\n\n ! Get the reference frame nodeinates of the grid point\n x0 = node(1)\n y0 = node(2)\n r0 = sqrt(x0*x0 + y0*y0)\n theta0 = atan2(y0,x0)\n\n a = psi * r0\n b = r0 / psi\n e = sqrt(ONE - psi**(-FOUR))\n r = b/(sqrt(ONE - (e*cos(theta0))**TWO))\n\n\n x_ale = r*cos(theta0)\n y_ale = r*sin(theta0)\n\n\n val(1) = x_ale\n val(2) = y_ale\n val(3) = node(3)\n \n end function compute_pos\n !**********************************************************************************\n\n\n\n\n\n\n !>\n !!\n !! @author Nathan A. Wukie\n !! @date 10/02/2019\n !!\n !!\n !-----------------------------------------------------------------------------------------\n function compute_vel(self,time,node) result(val)\n class(fic_case3_pmmf), intent(inout) :: self\n real(rk), intent(in) :: time\n real(rk), intent(in) :: node(3)\n\n real(rk) :: val(3)\n real(rk) :: Aa, alpha, psi, x0, y0, r0, theta0, &\n a, b, e, r, dalphadt, dpsidt, h, dhdt, drdt, &\n vr, vx_ale, vy_ale, f, dedt, dbdt, dfdt\n\n Aa = 1.5\n alpha = time**TWO*(THREE-time)/FOUR\n psi = ONE + (Aa - ONE)*alpha\n\n ! Get the reference frame nodeinates of the grid point\n x0 = node(1)\n y0 = node(2)\n r0 = sqrt(x0*x0 + y0*y0)\n theta0 = atan2(y0,x0)\n\n ! Location\n a = psi * r0\n b = r0 / psi\n e = sqrt(ONE - psi**(-FOUR))\n r = b/(sqrt(ONE - (e*cos(theta0))**TWO))\n f = sqrt(ONE - e*e*cos(theta0)*cos(theta0))\n\n\n ! Velocity \n dalphadt = TWO*time*(THREE-time)/FOUR - (time**TWO)/FOUR\n dpsidt = (Aa - ONE)*dalphadt\n\n dedt = TWO*dpsidt/((psi**5._rk)*sqrt(ONE - psi**(-FOUR)))\n dfdt = - cos(theta0)**TWO * e * dedt / (sqrt(ONE - e*e*cos(theta0)*cos(theta0)))\n dbdt = -r0*dpsidt/(psi*psi)\n\n drdt = (dbdt*f - b*dfdt)/(f*f)\n! h = sqrt( (psi**FOUR)*(sin(theta0)**TWO) + cos(theta0)**TWO)\n! dhdt = TWO*psi*psi*psi*dpsidt/h\n! drdt = (r0*dpsidt*h - r0*psi*dhdt)/(h*h)\n vr = drdt\n\n\n \n ! Convert to cartesian: assumes theta is not a function of (t)\n vx_ale = vr*cos(theta0)\n vy_ale = vr*sin(theta0)\n\n ! print*, sign(1._rk,vr), sign(1._rk,r - r0), vx_ale, vy_ale\n\n\n val(1) = vx_ale\n val(2) = vy_ale\n val(3) = ZERO \n \n \n end function compute_vel\n !**********************************************************************************\n\n\nend module pmmf_fic_case3\n", "meta": {"hexsha": "23e117cbdfc79d4b91be4003a00d805fc6e67d81", "size": 4619, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/mesh_motion/prescribed_mesh_motion/flow_in_cylinder/pmmf_fic_case3.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/mesh_motion/prescribed_mesh_motion/flow_in_cylinder/pmmf_fic_case3.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/mesh_motion/prescribed_mesh_motion/flow_in_cylinder/pmmf_fic_case3.f90", "max_forks_repo_name": "nwukie/ChiDG", "max_forks_repo_head_hexsha": "d096548ba3bd0a338a29f522fb00a669f0e33e9b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 20, "max_forks_repo_forks_event_min_datetime": "2016-07-18T16:20:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-27T19:26:12.000Z", "avg_line_length": 27.3313609467, "max_line_length": 94, "alphanum_fraction": 0.4215198095, "num_tokens": 1338, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947117065458, "lm_q2_score": 0.7122321720225278, "lm_q1q2_score": 0.6730556360685556}} {"text": "c # [xc,yc] are in [-180,180]x[0,360]\n subroutine mapc2m_latlong(blockno,xc,yc,xp,yp,zp)\n implicit none\n\n integer blockno\n double precision xc,yc,xp,yp,zp\n double precision deg2rad,xc1,yc1\n\n double precision pi, pi2\n common /compi/ pi, pi2\n\nc # blockno is not used here; assume that [xc,yc] is\nc # in a box [long0, long1]x[lat0,lat1], in\nc # degrees.\n\n deg2rad = pi/180.d0\n\n xc1 = deg2rad*xc\n yc1 = deg2rad*yc\n\n xp = cos(yc1)*cos(xc1)\n yp = cos(yc1)*sin(xc1)\n zp = sin(yc1)\n\n end\n", "meta": {"hexsha": "4fa5243e07aacaf7de8d49f722c6eb1fb3e09725", "size": 567, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/mappings/latlong/mapc2m_latlong.f", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/mappings/latlong/mapc2m_latlong.f", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-08-02T09:52:43.000Z", "max_issues_repo_issues_event_max_datetime": "2017-08-02T14:16:23.000Z", "max_forks_repo_path": "src/mappings/latlong/mapc2m_latlong.f", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "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": 21.8076923077, "max_line_length": 57, "alphanum_fraction": 0.5767195767, "num_tokens": 212, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.94499471015743, "lm_q2_score": 0.7122321720225278, "lm_q1q2_score": 0.6730556349652255}} {"text": "subroutine HeteroAspirationUpdateRule(nodeUpdate, payoffUpdate, randNumUpdate)\r\n use global\r\n implicit none\r\n integer,intent(in)::nodeUpdate\r\n real(8),intent(in)::payoffUpdate\r\n real(8), intent(in)::randNumUpdate\r\n !!!\r\n real(8)::switchProbContributionUpdateFunction1\r\n real(8)::switchProbContributionUpdateFunction2\r\n real(8)::switchProbContributionUpdateFunction3\r\n real(8)::switchProb\r\n real(8)::AspirationMinusPayoffTimesSelectionIntensity\r\n real(8)::expBetaU\r\n !!\r\n AspirationMinusPayoffTimesSelectionIntensity = selectionIntensity * (aspirationValueNode(nodeUpdate, strategyGame(nodeUpdate) + 1) - payoffUpdate)\r\n expBetaU = exp(-AspirationMinusPayoffTimesSelectionIntensity)\r\n !!!! the variable u = selectionIntensity * (aspirationValue - payoff)\r\n !!!! base update function #1: 1 /(1 + exp(-u))\r\n !!!! base update function #2: 1 /(1 + 10*exp(-u))\r\n !!!! base update function #3: 1 /(1 + 0.1*exp(-u))\r\n !!!! each individual's update function is \r\n !!!! param1* baseUpdateFunction1 + param2* baseUpdateFunction2 + (1-param1-param2)*baseUpdateFunction3\r\n !!!! all update function parameters are in [0,1]\r\n switchProbContributionUpdateFunction1 = updateFunctionParams(nodeUpdate, 1) / (real(1.0,8) + expBetaU)\r\n switchProbContributionUpdateFunction2 = updateFunctionParams(nodeUpdate, 2) / (real(1.0,8) + real(10,8)*expBetaU)\r\n switchProbContributionUpdateFunction3 = (real(1.0,8)-updateFunctionParams(nodeUpdate, 1)-updateFunctionParams(nodeUpdate, 2)) / (real(1.0,8) + real(0.1,8)*expBetaU)\r\n !!!! calculating the switching probability\r\n switchProb = switchProbContributionUpdateFunction1 + switchProbContributionUpdateFunction2 + switchProbContributionUpdateFunction3\r\n !!! \r\n if(randNumUpdate < switchProb)then\r\n strategyGame(nodeUpdate) = 1 - strategyGame(nodeUpdate)\r\n end if\r\n \r\n return \r\nend subroutine HeteroAspirationUpdateRule", "meta": {"hexsha": "b114f7bd9da9ac99c50f3949c848d01c702fb83f", "size": 1944, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "PayoffMatrix_abcd/HeteroAspirationUpdateRule.f90", "max_stars_repo_name": "leizhougetbetter/HeterogeneousAspDyn", "max_stars_repo_head_hexsha": "8423786469e1cbafeb62bd7c3f658bec8ba9fa95", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "PayoffMatrix_abcd/HeteroAspirationUpdateRule.f90", "max_issues_repo_name": "leizhougetbetter/HeterogeneousAspDyn", "max_issues_repo_head_hexsha": "8423786469e1cbafeb62bd7c3f658bec8ba9fa95", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "PayoffMatrix_abcd/HeteroAspirationUpdateRule.f90", "max_forks_repo_name": "leizhougetbetter/HeterogeneousAspDyn", "max_forks_repo_head_hexsha": "8423786469e1cbafeb62bd7c3f658bec8ba9fa95", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.5428571429, "max_line_length": 169, "alphanum_fraction": 0.7247942387, "num_tokens": 532, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533144915912, "lm_q2_score": 0.7217431943271999, "lm_q1q2_score": 0.6729918337621461}} {"text": "#define type(x) TYPE(x), target\n\nModule matrixAlgUtil_Mod\n ! Generic utilities for manipulating vectors and matrices\n\nContains\n\n Pure Function Vec2Matrix(vector)\n ! Converts tensors stored in vector format to a matrix format\n\n ! Arguments\n Double Precision, intent(IN) :: vector(:)\n\n ! Output\n Double Precision :: Vec2Matrix(3,3)\n\n ! Locals\n Double Precision, parameter :: zero=0.d0\n ! -------------------------------------------------------------------- !\n\n Vec2Matrix = zero\n Vec2Matrix(1,1) = vector(1)\n Vec2Matrix(2,2) = vector(2)\n Vec2Matrix(3,3) = Vector(3)\n Vec2Matrix(1,2) = vector(4)\n\n ! 2D or 3D\n If (size(vector) > 5) Then ! 3D\n Vec2Matrix(2,3) = vector(5)\n\n ! Symmetric or nonsymmetric\n If (size(vector) == 6) Then ! 3D, Symmetric\n Vec2Matrix(1,3) = vector(6)\n\n Vec2Matrix(2,1) = Vec2Matrix(1,2)\n Vec2Matrix(3,2) = Vec2Matrix(2,3)\n Vec2Matrix(3,1) = Vec2Matrix(1,3)\n\n Else ! 3D, Nonsymmetric\n Vec2Matrix(3,1) = vector(6)\n Vec2Matrix(2,1) = vector(7)\n Vec2Matrix(3,2) = vector(8)\n Vec2Matrix(1,3) = vector(9)\n End If\n\n Else ! 2D\n If (size(vector) == 5) Then ! 2D, Nonsymmetric\n Vec2Matrix(2,1) = vector(5)\n Else ! 2D, Symmetric\n Vec2Matrix(2,1) = Vec2Matrix(1,2)\n End If\n End IF\n\n Return\n End Function Vec2Matrix\n\n\n Pure Function Matrix2Vec(mat, nshr, symmetric)\n ! Converts a symmetric tensor stored in matrix format (3,3) to a vector\n\n ! Arguments\n Double Precision, intent(IN) :: mat(3,3)\n Integer, intent(IN) :: nshr\n Logical, intent(IN), optional :: symmetric ! True for symmetric matrix (default=True)\n\n ! Output\n Double Precision, allocatable :: Matrix2Vec(:)\n\n ! Locals\n Integer :: output_length\n Logical :: sym\n Double Precision, parameter :: zero=0.d0\n ! -------------------------------------------------------------------- !\n\n ! Optional argument for symmetry\n If (present(symmetric)) Then\n sym = symmetric\n Else\n sym = .TRUE.\n End If\n\n ! Initialize output\n If (sym) Then\n output_length = 3+nshr\n Else\n If (nshr == 1) Then\n output_length = 5\n Else\n output_length = 9\n End If\n End If\n Allocate(Matrix2Vec(output_length))\n Matrix2Vec = zero\n\n ! 2D components\n Do I=1,3; Matrix2Vec(I) = mat(I,I); End Do\n Matrix2Vec(4) = mat(1,2)\n\n ! 3D\n If (sym) Then\n If (nshr > 1) Then\n Matrix2Vec(5) = mat(2,3)\n Matrix2Vec(6) = mat(3,1)\n End If\n Else\n If (nshr > 1) Then\n Matrix2Vec(5) = mat(2,3)\n Matrix2Vec(6) = mat(3,1)\n Matrix2Vec(7) = mat(2,1)\n Matrix2Vec(8) = mat(3,2)\n Matrix2Vec(9) = mat(1,3)\n Else\n Matrix2Vec(5) = mat(2,1)\n End If\n End If\n\n Return\n End Function Matrix2Vec\n\n\n Pure Function VCmp(vec1, vec2)\n ! Checks if vec1 and vec2 have identical components\n ! Not optimized for large vectors\n\n ! Arguments\n Double Precision, intent(IN) :: vec1(:), vec2(:)\n\n ! Output\n Logical :: VCmp\n\n ! Locals\n Double Precision, parameter :: eps=1.d-30\n ! -------------------------------------------------------------------- !\n\n If(size(vec1) /= size(vec2)) Then\n VCmp = .FALSE.\n Return\n Else\n Do I=1, size(vec1)\n If(abs(vec1(I) - vec2(I)) > eps) Then\n VCmp = .FALSE.\n Return\n End If\n End Do\n End If\n\n VCmp = .TRUE.\n\n Return\n End Function VCmp\n\n\n Pure Function MInverse(mat)\n ! Finds the inverse of a 3x3 matrix\n\n ! Arguments\n Double Precision, intent(IN) :: mat(3,3)\n\n ! Output\n Double Precision :: MInverse(3,3)\n ! -------------------------------------------------------------------- !\n\n MInverse(1,1) = mat(3,3)*mat(2,2) - mat(3,2)*mat(2,3)\n MInverse(2,2) = mat(3,3)*mat(1,1) - mat(3,1)*mat(1,3)\n MInverse(3,3) = mat(1,1)*mat(2,2) - mat(1,2)*mat(2,1)\n\n MInverse(1,2) = -(mat(3,3)*mat(1,2) - mat(3,2)*mat(1,3))\n MInverse(2,1) = -(mat(3,3)*mat(2,1) - mat(2,3)*mat(3,1))\n MInverse(1,3) = mat(2,3)*mat(1,2) - mat(2,2)*mat(1,3)\n MInverse(3,1) = mat(3,2)*mat(2,1) - mat(2,2)*mat(3,1)\n MInverse(2,3) = -(mat(2,3)*mat(1,1) - mat(2,1)*mat(1,3))\n MInverse(3,2) = -(mat(3,2)*mat(1,1) - mat(1,2)*mat(3,1))\n\n Do I=1,3\n Do J=1,3\n MInverse(I,J) = MInverse(I,J) / MDet(mat)\n End Do\n End Do\n\n Return\n End Function MInverse\n\n Function MInverseLarge(mat)\n ! Finds the inverse of a matrix\n ! Requires LAPACK\n ! From: http://fortranwiki.org/fortran/show/inv\n\n ! Consider alternative for potential speed-up (TODO)\n ! https://caps.gsfc.nasa.gov/simpson/software/m66inv_f90.txt\n\n Use forlog_Mod\n\n ! Arguments\n Double Precision, intent(IN) :: mat(:,:)\n ! Output\n Double Precision :: MInverseLarge(size(mat,1),size(mat,2))\n\n ! Locals\n Double Precision :: work(size(mat,1)) ! work array for LAPACK\n Integer :: ipiv(size(mat,1)) ! pivot indices\n Integer :: n, out_info\n ! -------------------------------------------------------------------- !\n\n ! External procedures defined in LAPACK\n Interface\n Subroutine DGETRF(M, N, A, LDA, IPIV, INFO)\n ! http://www.math.utah.edu/software/lapack/lapack-d/dgetrf.html\n Integer, intent(IN) :: M, N, LDA\n Double Precision, intent(INOUT) :: A(LDA,N)\n Integer, intent(OUT) :: IPIV(size(A,1)), INFO\n End Subroutine DGETRF\n Subroutine DGETRI(N, A, LDA, IPIV, WORK, LWORK, INFO)\n ! http://www.math.utah.edu/software/lapack/lapack-d/dgetri.html\n Integer, intent(IN) :: N, LDA, LWORK\n Double Precision, intent(INOUT) :: A(LDA,N)\n Integer, intent(OUT) :: IPIV(size(A,1)), INFO\n Double Precision, intent(OUT) :: WORK(LWORK)\n End Subroutine DGETRI\n End Interface\n ! -------------------------------------------------------------------- !\n\n ! Store mat in MInverseLarge to prevent it from being overwritten by LAPACK\n MInverseLarge = mat\n n = size(mat,1)\n\n ! DGETRF computes an LU factorization of a general M-by-N matrix A\n ! using partial pivoting with row interchanges.\n Call DGETRF(n, n, MInverseLarge, n, ipiv, out_info)\n\n If (out_info /= 0) Then\n Call log%error('Matrix is numerically singular!')\n End If\n\n ! DGETRI computes the inverse of a matrix using the LU factorization\n ! computed by DGETRF.\n call DGETRI(n, MInverseLarge, n, ipiv, work, n, out_info)\n\n If (out_info /= 0) Then\n Call log%error('Matrix inversion failed!')\n End If\n\n Return\n End Function MInverseLarge\n\n\n Pure Function MInverse4x4(A) result(B)\n ! Credit for inversion algorithm goes to http://fortranwiki.org/fortran/show/Matrix+inversion\n ! Performs a direct calculation of the inverse of a 4x4 matrix.\n Double Precision, intent(in) :: A(4,4) !! Matrix\n Double Precision :: B(4,4) !! Inverse matrix\n Double Precision :: detinv\n\n ! Calculate the inverse determinant of the matrix\n detinv = &\n 1/(A(1,1)*(A(2,2)*(A(3,3)*A(4,4)-A(3,4)*A(4,3))+A(2,3)*(A(3,4)*A(4,2)-A(3,2)*A(4,4))+A(2,4)*(A(3,2)*A(4,3)-A(3,3)*A(4,2)))&\n - A(1,2)*(A(2,1)*(A(3,3)*A(4,4)-A(3,4)*A(4,3))+A(2,3)*(A(3,4)*A(4,1)-A(3,1)*A(4,4))+A(2,4)*(A(3,1)*A(4,3)-A(3,3)*A(4,1)))&\n + A(1,3)*(A(2,1)*(A(3,2)*A(4,4)-A(3,4)*A(4,2))+A(2,2)*(A(3,4)*A(4,1)-A(3,1)*A(4,4))+A(2,4)*(A(3,1)*A(4,2)-A(3,2)*A(4,1)))&\n - A(1,4)*(A(2,1)*(A(3,2)*A(4,3)-A(3,3)*A(4,2))+A(2,2)*(A(3,3)*A(4,1)-A(3,1)*A(4,3))+A(2,3)*(A(3,1)*A(4,2)-A(3,2)*A(4,1))))\n\n ! Calculate the inverse of the matrix\n B(1,1) = detinv*(A(2,2)*(A(3,3)*A(4,4)-A(3,4)*A(4,3))+A(2,3)*(A(3,4)*A(4,2)-A(3,2)*A(4,4))+A(2,4)*(A(3,2)*A(4,3)-A(3,3)*A(4,2)))\n B(2,1) = detinv*(A(2,1)*(A(3,4)*A(4,3)-A(3,3)*A(4,4))+A(2,3)*(A(3,1)*A(4,4)-A(3,4)*A(4,1))+A(2,4)*(A(3,3)*A(4,1)-A(3,1)*A(4,3)))\n B(3,1) = detinv*(A(2,1)*(A(3,2)*A(4,4)-A(3,4)*A(4,2))+A(2,2)*(A(3,4)*A(4,1)-A(3,1)*A(4,4))+A(2,4)*(A(3,1)*A(4,2)-A(3,2)*A(4,1)))\n B(4,1) = detinv*(A(2,1)*(A(3,3)*A(4,2)-A(3,2)*A(4,3))+A(2,2)*(A(3,1)*A(4,3)-A(3,3)*A(4,1))+A(2,3)*(A(3,2)*A(4,1)-A(3,1)*A(4,2)))\n B(1,2) = detinv*(A(1,2)*(A(3,4)*A(4,3)-A(3,3)*A(4,4))+A(1,3)*(A(3,2)*A(4,4)-A(3,4)*A(4,2))+A(1,4)*(A(3,3)*A(4,2)-A(3,2)*A(4,3)))\n B(2,2) = detinv*(A(1,1)*(A(3,3)*A(4,4)-A(3,4)*A(4,3))+A(1,3)*(A(3,4)*A(4,1)-A(3,1)*A(4,4))+A(1,4)*(A(3,1)*A(4,3)-A(3,3)*A(4,1)))\n B(3,2) = detinv*(A(1,1)*(A(3,4)*A(4,2)-A(3,2)*A(4,4))+A(1,2)*(A(3,1)*A(4,4)-A(3,4)*A(4,1))+A(1,4)*(A(3,2)*A(4,1)-A(3,1)*A(4,2)))\n B(4,2) = detinv*(A(1,1)*(A(3,2)*A(4,3)-A(3,3)*A(4,2))+A(1,2)*(A(3,3)*A(4,1)-A(3,1)*A(4,3))+A(1,3)*(A(3,1)*A(4,2)-A(3,2)*A(4,1)))\n B(1,3) = detinv*(A(1,2)*(A(2,3)*A(4,4)-A(2,4)*A(4,3))+A(1,3)*(A(2,4)*A(4,2)-A(2,2)*A(4,4))+A(1,4)*(A(2,2)*A(4,3)-A(2,3)*A(4,2)))\n B(2,3) = detinv*(A(1,1)*(A(2,4)*A(4,3)-A(2,3)*A(4,4))+A(1,3)*(A(2,1)*A(4,4)-A(2,4)*A(4,1))+A(1,4)*(A(2,3)*A(4,1)-A(2,1)*A(4,3)))\n B(3,3) = detinv*(A(1,1)*(A(2,2)*A(4,4)-A(2,4)*A(4,2))+A(1,2)*(A(2,4)*A(4,1)-A(2,1)*A(4,4))+A(1,4)*(A(2,1)*A(4,2)-A(2,2)*A(4,1)))\n B(4,3) = detinv*(A(1,1)*(A(2,3)*A(4,2)-A(2,2)*A(4,3))+A(1,2)*(A(2,1)*A(4,3)-A(2,3)*A(4,1))+A(1,3)*(A(2,2)*A(4,1)-A(2,1)*A(4,2)))\n B(1,4) = detinv*(A(1,2)*(A(2,4)*A(3,3)-A(2,3)*A(3,4))+A(1,3)*(A(2,2)*A(3,4)-A(2,4)*A(3,2))+A(1,4)*(A(2,3)*A(3,2)-A(2,2)*A(3,3)))\n B(2,4) = detinv*(A(1,1)*(A(2,3)*A(3,4)-A(2,4)*A(3,3))+A(1,3)*(A(2,4)*A(3,1)-A(2,1)*A(3,4))+A(1,4)*(A(2,1)*A(3,3)-A(2,3)*A(3,1)))\n B(3,4) = detinv*(A(1,1)*(A(2,4)*A(3,2)-A(2,2)*A(3,4))+A(1,2)*(A(2,1)*A(3,4)-A(2,4)*A(3,1))+A(1,4)*(A(2,2)*A(3,1)-A(2,1)*A(3,2)))\n B(4,4) = detinv*(A(1,1)*(A(2,2)*A(3,3)-A(2,3)*A(3,2))+A(1,2)*(A(2,3)*A(3,1)-A(2,1)*A(3,3))+A(1,3)*(A(2,1)*A(3,2)-A(2,2)*A(3,1)))\n\n Return\n End Function\n\n\n Pure Function MDet(mat)\n ! Finds the determinant of a 3x3 matrix\n\n ! Arguments\n Double Precision, intent(IN) :: mat(3,3)\n\n ! Output\n Double Precision :: MDet\n ! -------------------------------------------------------------------- !\n\n MDet = mat(1,1)*(mat(3,3)*mat(2,2) - mat(3,2)*mat(2,3)) - mat(2,1)*(mat(3,3)*mat(1,2) - mat(3,2)*mat(1,3)) + mat(3,1)*(mat(2,3)*mat(1,2) - mat(2,2)*mat(1,3))\n\n Return\n End Function MDet\n\n\n Pure Function OuterProduct(u, v)\n ! Calculates the outer product of two vectors\n\n ! Arguments\n Double Precision, intent(IN) :: u(:), v(:)\n\n ! Output\n Double Precision :: OuterProduct(size(u),size(v))\n ! -------------------------------------------------------------------- !\n\n Do I = 1, size(u)\n Do J = 1, size(v)\n OuterProduct(I,J) = u(I)*v(J)\n End Do\n End Do\n\n Return\n End Function OuterProduct\n\n\n Pure Function CrossProduct(a, b)\n ! Calculates the cross product of two vectors with length 3\n\n ! Arguments\n Double Precision, intent(IN) :: a(3), b(3)\n\n ! Output\n Double Precision :: CrossProduct(3)\n ! -------------------------------------------------------------------- !\n\n CrossProduct(1) = a(2)*b(3) - a(3)*b(2)\n CrossProduct(2) = a(3)*b(1) - a(1)*b(3)\n CrossProduct(3) = a(1)*b(2) - a(2)*b(1)\n\n Return\n End Function CrossProduct\n\n\n Pure Function Norm(u)\n ! Normalizes a vector\n\n ! Arguments\n Double Precision, intent(IN) :: u(:)\n\n ! Output\n Double Precision :: Norm(size(u))\n\n ! Locals\n Double Precision :: u_length\n ! -------------------------------------------------------------------- !\n\n u_length = Length(u)\n\n Do I = 1, size(u)\n Norm(I) = u(I)/u_length\n End Do\n\n Return\n End Function Norm\n\n\n Pure Function Length(u)\n ! Calculates the length of a vector\n\n ! Arguments\n Double Precision, intent(IN) :: u(:)\n\n ! Output\n Double Precision :: Length\n ! -------------------------------------------------------------------- !\n\n Length = 0.d0\n\n Do I = 1, size(u)\n Length = Length + u(I)*u(I)\n End Do\n\n Length = SQRT(Length)\n\n Return\n End Function Length\n\n#ifndef PYEXT\n Subroutine PolarDecomp(F,R,U)\n ! Finds the polar decomposition of F\n ! Returns R and U\n\n ! Arguments\n Double Precision, intent(IN) :: F(3,3)\n Double Precision, intent(OUT) :: R(3,3), U(3,3)\n\n ! Locals\n Double precision :: eigVec(3,3), eigVal(3), WORK(1000), eigDiag(3,3)\n Double Precision :: Usquared(3,3)\n Integer :: INFO, LWORK\n Double Precision, parameter :: zero=0.d0\n ! -------------------------------------------------------------------- !\n\n ! Calculate U^2\n Usquared = MATMUL(TRANSPOSE(F), F)\n\n ! Get the eigenvalues and eigenvectors of U^2\n ! DSYEV is a LAPACK function; doc: http://www.netlib.org/lapack/double/dsyev.f\n eigVec = Usquared ! prevent overwrite\n ! Setup workspace\n LWORK = -1\n Call DSYEV( 'V', 'U', 3, eigVec, 3, eigVal, WORK, LWORK, INFO )\n LWORK = MIN( 1000, INT( WORK( 1 ) ) )\n ! Solve the eigenvalue problem\n Call DSYEV( 'V', 'U', 3, eigVec, 3, eigVal, WORK, LWORK, INFO )\n If (info /= 0) Then\n print *, 'WARNING'\n print *, 'Failed to compute eigenvalues of U^2. DSYEV Error.'\n End If\n\n ! Get U\n eigDiag = zero\n eigDiag(1,1) = SQRT(eigVal(1))\n eigDiag(2,2) = SQRT(eigVal(2))\n eigDiag(3,3) = SQRT(eigVal(3))\n U = MATMUL(eigVec, MATMUL(eigDiag, TRANSPOSE(eigVec)))\n\n ! Get R\n R = MATMUL(F, MInverse(U))\n\n Return\n End Subroutine PolarDecomp\n#endif\n\nEnd Module\n", "meta": {"hexsha": "17f9601e1ca7c674ca6caa28c89392ef79f2ff12", "size": 13406, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "for/matrixUtil.for", "max_stars_repo_name": "LucaDiStasio/CompDam_DGD", "max_stars_repo_head_hexsha": "c01344972db6b9b97d5d19225bff8e63d8e54a20", "max_stars_repo_licenses": ["NASA-1.3"], "max_stars_count": 81, "max_stars_repo_stars_event_min_datetime": "2016-07-12T18:14:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T04:46:46.000Z", "max_issues_repo_path": "for/matrixUtil.for", "max_issues_repo_name": "LucaDiStasio/CompDam_DGD", "max_issues_repo_head_hexsha": "c01344972db6b9b97d5d19225bff8e63d8e54a20", "max_issues_repo_licenses": ["NASA-1.3"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2017-04-04T13:37:26.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-18T14:52:06.000Z", "max_forks_repo_path": "for/matrixUtil.for", "max_forks_repo_name": "LucaDiStasio/CompDam_DGD", "max_forks_repo_head_hexsha": "c01344972db6b9b97d5d19225bff8e63d8e54a20", "max_forks_repo_licenses": ["NASA-1.3"], "max_forks_count": 55, "max_forks_repo_forks_event_min_datetime": "2016-07-12T18:47:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T22:46:28.000Z", "avg_line_length": 31.3224299065, "max_line_length": 161, "alphanum_fraction": 0.5186483664, "num_tokens": 5321, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267762381844, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.6729787936337337}} {"text": "!****************************************************************************\n!\n! PROGRAM: ODE1X1\n!\n! PURPOSE: Solve first-order, linear, ordinary differential equation using \n! Runge Kutta Method.\n!\n!****************************************************************************\n! Author: lcy\n! \n! Data: 2019.09.27\n!****************************************************************************\n\nprogram ode1x1\n! \n! Numerical solution to the 1 x 1 ODE system by six\n! integrators\n! \n! Double precision coding is used\nimplicit double precision(a-h,o-z)\n! \n! Size arrays\nparameter(neq=500)\ndimension u0(neq),u(neq)\n! \n! Open a file for output\nno=2\nopen(no,file='ode1x1for.out')\n! \n! Step through six integrators\ndo ncase=1,6\n! \n! Integration parameters\n call intpar(neqn,nout,nsteps,t0,tf,abserr,relerr)\n! \n! Initial condition\n call inital(neqn,t0,u0)\n! \n! Output time\n tp=tf-t0\n! \n! Step through nout grid points\n do j=1,nout\n! \n! Print solution\n call fprint(no,ncase,neqn,t0,u0)\n! \n! Select ODE integrator\n! \n! Fixed step modified Euler integrator\n if(ncase.eq.1)then\n call euler2a(neqn,t0,tf,u0,nsteps,u)\n end if\n! \n! Variable step modified Euler integrator\n if(ncase.eq.2)then\n call euler2b(neqn,t0,tf,u0,nsteps,abserr,relerr,u)\n end if\n! \n! Fixed step classical fourth order RK integrator\n if(ncase.eq.3)then\n call rkc4a(neqn,t0,tf,u0,nsteps,u)\n end if\n! \n! Variable step classical fourth order RK integrator\n if(ncase.eq.4)then\n call rkc4b(neqn,t0,tf,u0,nsteps,abserr,relerr,u)\n end if\n! \n! Fixed step RK Fehlberg (RKF45) integrator\n if(ncase.eq.5)then\n call rkf45a(neqn,t0,tf,u0,nsteps,u)\n end if\n! \n! Variable step Fehlberg (RKF45) integrator\n if(ncase.eq.6)then\n call rkf45b(neqn,t0,tf,u0,nsteps,abserr,relerr,u)\n end if\n! \n! Advance solution\n t0=tf\n tf=tf+tp\n do i=1,neqn\n u0(i)=u(i)\n end do\n! \n! Next output\n end do\n! \n! Next integrator\n end do\n! \n! End of ode1x1\n end", "meta": {"hexsha": "1c6f434c24f04c225b810f1467f3b1a0e856d438", "size": 2120, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ODE1X1/ODE/ode1x1.f90", "max_stars_repo_name": "cunyizju/Runge-Kutta-ODE-FORTRAN", "max_stars_repo_head_hexsha": "457151ea85dd5b0b04d3fb5a157049ef997f8f67", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-09-30T09:09:38.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-30T09:09:38.000Z", "max_issues_repo_path": "ODE1X1/ODE/ode1x1.f90", "max_issues_repo_name": "cunyizju/Runge-Kutta-ODE-FORTRAN", "max_issues_repo_head_hexsha": "457151ea85dd5b0b04d3fb5a157049ef997f8f67", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ODE1X1/ODE/ode1x1.f90", "max_forks_repo_name": "cunyizju/Runge-Kutta-ODE-FORTRAN", "max_forks_repo_head_hexsha": "457151ea85dd5b0b04d3fb5a157049ef997f8f67", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.5531914894, "max_line_length": 77, "alphanum_fraction": 0.5533018868, "num_tokens": 639, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267660487573, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.6729787766991125}} {"text": "program P2896\n implicit none\n real :: orange, apple, pine\n real :: i, j, k\n integer :: it, max\n\n real, dimension(3, 4) :: result\n\n read (*, *) orange, apple, pine\n read (*, *) i, j, k\n\n result(1, 1) = 0\n result(1, 2) = apple - orange * j / i\n result(1, 3) = pine - orange * k / i\n result(1, 4) = orange / i\n\n result(2, 1) = orange - apple * i / j\n result(2, 2) = 0\n result(2, 3) = pine - apple * k / j\n result(2, 4) = apple / j\n\n result(3, 1) = orange - pine * i / k\n result(3, 2) = apple - pine * j / k\n result(3, 3) = 0\n result(3, 4) = pine / k\n\n max = 1\n do it = 1, 3\n if (result(it, 1) < 0 .or. result(it, 2) < 0 .or. result(it, 3) < 0) then\n result(it, 4) = 0\n end if\n if (result(max, 4) < result(it, 4)) then\n max = it\n end if\n end do\n\n write (*, *) result(max, 1), result(max, 2), result(max, 3)\nend program P2896", "meta": {"hexsha": "2a5bacc8f2e653b6e4c0b2aa7cff12bda99227bc", "size": 939, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "P2896.f95", "max_stars_repo_name": "daily-boj/kiwiyou", "max_stars_repo_head_hexsha": "ceca96ddfee95708871af67d1682048e0bed0257", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-04-08T09:04:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-16T07:30:24.000Z", "max_issues_repo_path": "P2896.f95", "max_issues_repo_name": "daily-boj/kiwiyou", "max_issues_repo_head_hexsha": "ceca96ddfee95708871af67d1682048e0bed0257", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "P2896.f95", "max_forks_repo_name": "daily-boj/kiwiyou", "max_forks_repo_head_hexsha": "ceca96ddfee95708871af67d1682048e0bed0257", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-04-16T05:32:06.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-28T13:40:56.000Z", "avg_line_length": 24.7105263158, "max_line_length": 81, "alphanum_fraction": 0.482428115, "num_tokens": 375, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088005554475, "lm_q2_score": 0.724870282120402, "lm_q1q2_score": 0.6729759491816913}} {"text": "\tREAL FUNCTION TSIZE(N)\r\n\tUSE MSIMSL\r\n\tIMPLICIT NONE\r\nC\r\nC-Description-----------------------------------------------------------\r\nC\r\nC Function:\r\nC\tSample size calculations involving t tests\r\nC\tThis function evaluates the left hand side of equation (2) in\r\nC\tDupont and Plummer (submitted for publication in 1992). It is\r\nC\tused in conjunction with the iterative equation solver zero.\r\nC\tWhen TSIZE=0, N is the sample size needed to detect a true difference\r\nC\tDELTA with power 1-BETA and Type I error probability ALPHA.\r\nC\r\nC Arguments:\r\nC\r\nC Notes:\r\nC .\tThis routine was written by Dale Plummer\r\nC .\tDesigned by William Dupont\r\nC\r\nC-Declarations----------------------------------------------------------\r\nC\r\nC Common used to pass needed values to passed name functions.\r\nC\r\n\tINTEGER ITYPE\r\n\tREAL ALPHA, MYBETA, DELTA, M, NU\r\n\tCOMMON /TSSCOMM/ALPHA, MYBETA, DELTA, M, NU, ITYPE\r\n\r\n\tINTEGER DFRESET\r\n\tCOMMON /DFRESET/ DFRESET\r\nC\r\nC Locals\r\nC\r\n\tREAL N,TCRVALUE,T1,T2\r\nC\r\nC Code:\r\nC\r\n\tIF (ITYPE.EQ.1) THEN\r\nC\r\nC Paired t-test.\r\nC\r\n\t NU=N-1\r\n\tELSE IF (ITYPE.EQ.2) THEN\r\nC\r\nC Independent t-test\r\nC\r\n\t NU=N*(M+1)-2\r\n\tELSE IF (ITYPE.EQ.3) THEN\r\nC\r\nC Linear regression, number of treatments is 1.\r\nC\r\n\t NU=N-2\r\n\tELSE IF (ITYPE.EQ.4) THEN\r\nC\r\nC Linear regression, number of treatments is 2.\r\nC\r\n\t NU=N*(1+M)-4\r\n\tEND IF\r\nC\r\nC If NU (degrees of freedom) is less than 1 then we will be\r\nC hunting on an impossible curve. In this case it makes sense\r\nC to go to the nearest possible curve, ie NU=1. So if NU is\r\nC less that 1 then set it to 1. Set the value DFRESET if we\r\nC do this.\r\nC\r\n\tIF (NU.LT.1) THEN\r\n\t\tNU=1\r\n\t\tDFRESET=1\r\n\tEND IF\r\nC\r\nC Calculate the critical t value T1 such that pr[t>T1]=ALPHA/2\r\nC where t has a t distribution with NU degrees of freedom.\r\nC\r\nC\tT1=TCRVALUE(ALPHA/2.,NU)\r\n\tT1=TIN((1.-ALPHA/2.),NU)\r\nC\tT2=TCRVALUE(MYBETA,NU)\r\n\tT2=TIN((1.-MYBETA),NU)\r\n\tTSIZE=(T1+T2)**2/DELTA**2-N\r\n\tRETURN\r\n\tEND\r\n", "meta": {"hexsha": "169a6ffffd6a53079e96e1da4edf9e2e31da5d8e", "size": 1970, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "misc/old_ps/ps-development-version/psDll/tsize.for", "max_stars_repo_name": "vubiostat/ps", "max_stars_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2017-12-29T14:19:14.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-06T15:08:46.000Z", "max_issues_repo_path": "misc/old_ps/ps-development-version/psDll/tsize.for", "max_issues_repo_name": "vubiostat/ps", "max_issues_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2020-04-30T16:57:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-07T00:26:02.000Z", "max_forks_repo_path": "misc/old_ps/ps-development-version/psDll/tsize.for", "max_forks_repo_name": "vubiostat/ps", "max_forks_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-07T20:11:54.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-11T19:18:59.000Z", "avg_line_length": 24.3209876543, "max_line_length": 73, "alphanum_fraction": 0.6340101523, "num_tokens": 643, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088025362857, "lm_q2_score": 0.7248702642896702, "lm_q1q2_score": 0.6729759340633336}} {"text": "#include \"eiscor.h\"\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! z_rot3_vec4gen\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! This routine computes the generators for a complex rotation represented\n! by 3 real numbers: the real and imaginary parts of a complex cosine,\n! CR and CI, and a scrictly real sine, S. The CR, CI and S are \n! constructed to be parallel with the vector [AR+iAI,BR+iBI]^T, where AR, \n! AI, BR and BI are real and i = sqrt(-1).\n!\n! This routine always adjusts the phase of [AR+iAI,BR+iBI]^T so that S >= 0.\n!\n! If any part of the input vector [AR+iAI,BR+iBI]^T contains a NAN then\n! CR, CI, S and NRM are all set to NAN.\n!\n! If only one of AR, AI, BR or BI = +/-INF then the corresponding AR, AI, BR \n! or BI is first set to +/-1 and the remaining terms are set to 0. Then the \n! CR, CI and S are computed from the new vector containing +/-1 and 0. In \n! this case NRM is always set to INF.\n!\n! If more than one of AR, AI, BR or BI = +/- INF then CR = CI = S = NRM = NAN\n!\n! If AR = AI = BR = BI = 0 then CR = 1, CI = S = 0 and NRM = 0.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! \n! EXCEPTIONAL CASES\n!\n! AR | AI | BR | BI | CR | CI | S | NRM \n! ------- | ------- | ------- | ------- | ------- | ------- | ------- | -------\n! 0d0 | 0d0 | 0d0 | 0d0 | 1d0 | 0d0 | 0d0 | 0d0\n! ------- | ------- | ------- | ------- | ------- | ------- | ------- | -------\n! +-INF | XdX | XdX | XdX | +-1d0 | 0d0 | 0d0 | INF\n! XdX | +-INF | XdX | XdX | 0d0 | +-1d0 | 0d0 | INF\n! XdX | XdX | +-INF | XdX | 0d0 | 0d0 | 1d0 | INF\n! XdX | XdX | XdX | +-INF | 0d0 | 0d0 | 1d0 | INF\n! at least two +-INFs | NAN | NAN | NAN | NAN\n! ------- | ------- | ------- | ------- | ------- | ------- | ------- | -------\n! at least one NAN | NAN | NAN | NAN | NAN\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! INPUT VARIABLES:\n!\n! AR, AI REAL(8) \n! real and imaginary part of the first component \n! of the complex vector [AR+iAI,BR+iBI]^T\n!\n! BR, BI REAL(8) \n! the second component \n! of the complex vector [AR+iAI,BR+iBI]^T\n!\n! OUTPUT VARIABLES:\n!\n! CR, CI REAL(8)\n! on exit CR = AR/NRM, CI = AI/NRM\n!\n! S REAL(8)\n! on exit S = B/NRM\n!\n! NRM REAL(8)\n! on exit contains the norm \n! of the complex vector [AR+iAI,BR+iBI]^T\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine z_rot3_vec4gen(AR,AI,BR,BI,CR,CI,S,NRM)\n\n implicit none\n \n ! input variables\n real(8), intent(in) :: AR, AI, BR, BI\n real(8), intent(inout) :: CR, CI, S, NRM\n \n ! compute variables\n real(8), parameter :: inf = EISCOR_DBL_INF\n real(8) :: pAr, pAi, pBr, pBi\n \n ! compute phase of BR, BI\n call d_rot2_vec2gen(BR,BI,pBr,pBi,S)\n \n ! compute phase of AR, AI\n call d_rot2_vec2gen(AR,AI,pAr,pAi,CR) \n \n ! check if AR is the only INF \n if ((abs(S)<=inf).AND.(abs(CR)>inf).AND.(pAr.EQ.0d0)) then\n \n ! construct CR, CI, S\n call z_rot3_vec3gen(AR,AI,S,CR,CI,S,NRM) \n \n ! check if AI is the only INF \n else if ((abs(S)<=inf).AND.(abs(CR)>inf).AND.(pAi.EQ.0d0)) then\n \n ! construct CR, CI, S\n call z_rot3_vec3gen(AR,AI,S,CR,CI,S,NRM) \n \n ! otherwise\n else\n \n ! adjust phase of AR, AI and BR, BI so that BR = sqrt(|BR|^2 + |BI|^2) and BI = 0 \n call d_rot2_vec2gen(pAr*pBr + pAi*pBi,-pAr*pBi + pAi*pBr,pAr,pAi,CI) \n \n ! construct CR, CI, S\n call z_rot3_vec3gen(CR*pAr,CR*pAi,S,CR,CI,S,NRM)\n \n end if\n\nend subroutine z_rot3_vec4gen\n", "meta": {"hexsha": "22b66a57efc9e5d1a63cc5351ebe1d6eae60d96b", "size": 3995, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/AMVW/src/complex_double/z_rot3_vec4gen.f90", "max_stars_repo_name": "trcameron/FPML", "max_stars_repo_head_hexsha": "f6aacfcd702f7ce74a45ffaf281e9586dceb1b7e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tests/AMVW/src/complex_double/z_rot3_vec4gen.f90", "max_issues_repo_name": "trcameron/FPML", "max_issues_repo_head_hexsha": "f6aacfcd702f7ce74a45ffaf281e9586dceb1b7e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/AMVW/src/complex_double/z_rot3_vec4gen.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": 35.990990991, "max_line_length": 86, "alphanum_fraction": 0.4475594493, "num_tokens": 1348, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569267, "lm_q2_score": 0.7461390043208003, "lm_q1q2_score": 0.6729581916279911}} {"text": " subroutine LegendreSP(Plm,x)\n\n*************************************************************************\n** Written by Lin-Wang Wang, 2003\n*************************************************************************\n** copyright (c) 2003, The Regents of the University of California,\n** through Lawrence Berkeley National Laboratory (subject to receipt of any\n** required approvals from the U.S. Dept. of Energy). All rights reserved.\n*************************************************************************\n\n\ncccc Plm(m,l)[x]=sqrt[(2*l+1)/4pi*(l-m)!/(l+m)!] P_l^m(x)\ncccc here, P_l^m(x) is the Lengendre function\n\ncccc Note the normalized spherical harmonic function is:\ncccc Y_lm(th,phi)=Plm(m,l)[costh]*exp(i*m*phi)\n\n implicit double precision(a-h,o-z)\n parameter (pi=3.14159265358979312d0)\n real*8 plm(-6:6,0:6),F(-6:6,0:6)\n \n\nccccccc F(m,l)=d^(l+m)/dx^(l+m) (x^2-1)^l\n x2=x**2\n x3=x2*x\n x4=x3*x\n x5=x4*x\n x6=x5*x\n x7=x6*x\n x8=x7*x\n x9=x8*x\n x10=x9*x\n x11=x10*x\n x12=x11*x\n\n F(0,0)=1.d0\n\n F(-1,1)=x2-1\n F(0,1)=2*x\n F(1,1)=2\n\n F(-2,2)=x4-2*x2+1\n F(-1,2)=4*x3-4*x\n F(0,2)=12*x2-4\n F(1,2)=24*x\n F(2,2)=24\n\n F(-3,3)=x6-3*x4+3*x2-1\n F(-2,3)=6*x5-12*x3+6*x \n F(-1,3)=30*x4-36*x2+6\n F(0,3)=120*x3-72*x\n F(1,3)=360*x2-72\n F(2,3)=720*x\n F(3,3)=720\n\n F(-4,4)=x8-4*x6+6*x4-4*x2+1\n F(-3,4)=8*x7-24*x5+24*x3-8*x\n F(-2,4)=56*x6-120*x4+72*x2-8\n F(-1,4)=336*x5-480*x3+144*x\n F(0,4)=1680*x4-1440*x2+144\n F(1,4)=6720*x3-2880*x\n F(2,4)=20160*x2-2880\n F(3,4)=40320*x\n F(4,4)=40320\n\n F(-5,5)=x10-5*x8+10*x6-10*x4+5*x2-1\n F(-4,5)=10*x9-40*x7+60*x5-40*x3+10*x\n F(-3,5)=90*x8-280*x6+300*x4-120*x2+10\n F(-2,5)=720*x7-1680*x5+1200*x3-240*x \n F(-1,5)=5040*x6-8400*x4+3600*x2-240\n F(0,5)=30240*x5-33600*x3+7200*x\n F(1,5)=151200*x4-100800*x2+7200\n F(2,5)=604800*x3-201600*x\n F(3,5)=1814400*x2-201600\n F(4,5)=3628800*x\n F(5,5)=3628800\n\n F(-6,6)=x12-6*x10+15*x8-20*x6+15*x4-6*x2+1\n F(-5,6)=12*x11-60*x9+120*x7-120*x5+60*x3-12*x\n F(-4,6)=132*x10-540*x8+840*x6-600*x4+180*x2-12\n F(-3,6)=1320*x9-4320*x7+5040*x5-2400*x3+360*x\n F(-2,6)=11880*x8-30240*x6+25200*x4-7200*x2+360\n F(-1,6)=95040*x7-181440*x5+100800*x3-14400*x\n F(0,6)=665280*x6-907200*x4+302400*x2-14400\n F(1,6)=3991680*x5-3628800*x3+604800*x\n F(2,6)=19958400*x4-10886400*x2+604800\n F(3,6)=79833600*x3-21772800*x\n F(4,6)=239500800*x2-21772800\n F(5,6)=479001600*x\n F(6,6)=479001600\n\n Plm(0,0)=1.d0/dsqrt(4*pi)\n\n do l=1,6\n call factorial(ifact,l)\n\n Plm(0,l)=1.d0/2.d0**l/ifact*F(0,l)\n \n do m=1,l\n isign=-1\n if(mod(m,2).eq.0) isign=1\n Plm(m,l)=isign/2.d0**l/ifact*\n & (1-x**2)**(m/2.d0)*F(m,l) ! this is the Legendre func. \n\n\n call factorial(ifact1,l-m)\n call factorial(ifact2,l+m)\n\n Plm(m,l)=dsqrt((2*l+1.d0)*ifact1/(4*pi*ifact2))*\n & Plm(m,l) \n\n\n Plm(-m,l)=isign*Plm(m,l)\n enddo\n\n enddo\n \n return\n contains\n\n subroutine factorial(ifact_tmp,ii)\n implicit double precision (a-h,o-z)\n integer ifact_tmp,ii\n\n if(ii.eq.0) then\n ifact_tmp=1\n endif\n\n if(ii.gt.0) then\n ifact_tmp=1\n do i=1,ii\n ifact_tmp=ifact_tmp*i\n enddo\n endif\n\n return\n end subroutine factorial\n\n end\n\n \n\n\n \n \n \n \n", "meta": {"hexsha": "05aa6a96e0fc0542f3f7d819426aa08c26b1f0e3", "size": 3826, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "lsda_p/LegendreSP.f", "max_stars_repo_name": "qsnake/petot", "max_stars_repo_head_hexsha": "bed334c6639fb02104821ce77d89ed83114febfe", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-07-13T07:57:59.000Z", "max_stars_repo_stars_event_max_datetime": "2016-07-13T07:57:59.000Z", "max_issues_repo_path": "lsda_p/LegendreSP.f", "max_issues_repo_name": "qsnake/petot", "max_issues_repo_head_hexsha": "bed334c6639fb02104821ce77d89ed83114febfe", "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": "lsda_p/LegendreSP.f", "max_forks_repo_name": "qsnake/petot", "max_forks_repo_head_hexsha": "bed334c6639fb02104821ce77d89ed83114febfe", "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": 25.8513513514, "max_line_length": 76, "alphanum_fraction": 0.4618400418, "num_tokens": 1523, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206844384595, "lm_q2_score": 0.746138993030751, "lm_q1q2_score": 0.6729581912805179}} {"text": "!-----Area_Circle----------------------------------------------------\n!\n! Function to compute the area of a circle of given radius\n!\n!---------------------------------------------------------------------\n\nFUNCTION Area_Circle(r)\n\nIMPLICIT NONE\nREAL :: Area_Circle\nREAL, INTENT(IN) :: r\n\n! Declare local constant Pi\nREAL, PARAMETER :: Pi = 3.1415927\n\nArea_Circle = Pi * r * r\n\nEND FUNCTION Area_Circle\n\nPROGRAM Area\n!---------------------------------------------------------------------\n!\n! This program computes the area of a circle given the input radius\n!\n! Uses: FUNCTION Area_Circle (r)\n!\n!---------------------------------------------------------------------\nIMPLICIT NONE\n\nINTERFACE \n! FUNCTION Area_Circle (r)\n! REAL, Area_Circle\n! REAL, INTENT(IN) :: r\n! END FUNCTION Area_Circle\nEND INTERFACE\n\n! Declare local variables\nREAL :: radius\n\nWRITE(*,*) \"Calculating circle area\"\nWRITE(*,*) Area_Circle(2)\n\n! Prompt user for radius of circle\n!write(*, '(A)', ADVANCE = \"NO\") \"Enter the radius of the circle: \"\n!read(*,*) radius\n\n! Write out area of circle using function call\n!write(*,100) \"Area of circle with radius\", radius, \" is\", &\n! Area_Circle(radius)\n!100 format (A, 2x, F6.2, A, 2x, F11.2)\n\nEND PROGRAM \n", "meta": {"hexsha": "6ed3c865fb75ed480c01951361cd17fa554e46ad", "size": 1244, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/circle/main.f90", "max_stars_repo_name": "LSaldyt/CTF", "max_stars_repo_head_hexsha": "cd11caa5a57b69e43a3a02a89e0a05b1d19e7f01", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-03-19T20:19:01.000Z", "max_stars_repo_stars_event_max_datetime": "2018-10-22T23:41:12.000Z", "max_issues_repo_path": "examples/circle/main.f90", "max_issues_repo_name": "LSaldyt/CTF", "max_issues_repo_head_hexsha": "cd11caa5a57b69e43a3a02a89e0a05b1d19e7f01", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-01-18T20:45:33.000Z", "max_issues_repo_issues_event_max_datetime": "2017-01-21T20:57:37.000Z", "max_forks_repo_path": "examples/circle/main.f90", "max_forks_repo_name": "LSaldyt/CTF", "max_forks_repo_head_hexsha": "cd11caa5a57b69e43a3a02a89e0a05b1d19e7f01", "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.4716981132, "max_line_length": 70, "alphanum_fraction": 0.5353697749, "num_tokens": 304, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206791658465, "lm_q2_score": 0.7461389873857264, "lm_q1q2_score": 0.6729581822550513}} {"text": "c plate - a prompt-driven routine for laminated plate calculations\ndimension S(3,3),Sbar(3,3),Qbar(3,3),E(6,7),kwa(6),\n* T(3,3),Tinv(3,3),R(3,3),Rinv(3,3),Et(6,6),\n* temp1(3,3),temp2(3,3),temp3(3,3),\n* eps0(3),xkappa(3),sigbar(3),sig(3),vtemp1(3),\n* vtemp2(3),E1(10),E2(10),Gnu12(10),G12(10),thk(10),\n* z(21),mat(20),theta(20),Qsave(3,3,20),Tsave(3,3,20)\ndata R/1.,3*0.,1.,3*0.,2./,Rinv/1.,3*0.,1.,3*0.,.5/,\n* E/42*0./\nc----------------------------------------------------------------------\nc input material set selections\ni=1\n10 write(6,20) i\n20 format (' assign properties for lamina type ',i2,'...'/)\nwrite(6,*) 'enter modulus in fiber direction...'\nwrite(6,*) ' (enter -1 to stop): '\nread (5,*) E1(i)\nif (E1(i) .lt. 0.) go to 30\nwrite(6,*) 'enter modulus in transverse direction: '\nread (5,*) E2(i)\nwrite(6,*) 'enter principal Poisson ratio: '\nread (5,*) Gnu12(i)\nc check for isotropy\ncheck=abs((E1(i)-E2(i))/E1(i))\nif (check.lt.0.001) then\nG12(i)=E1(i)/(2.*(1.+Gnu12(i)))\nelse\nwrite(6,*) 'enter shear modulus: '\nread (5,*) G12(i)\nend if\nwrite(6,*) 'enter ply thickness: '\nread (5,*) thk(i)\ni=i+1\ngo to 10\nc----------------------------------------------------------------------\nc define layup\n30 iply=1\nz(1)=0.\nwrite(6,*) 'define layup sequence, starting at bottom...'\nwrite(6,*) ' (use negative material set number to stop)'\n40 write (6,50) iply\n50 format (/' enter material set number for ply number',i3,': ')\nread (5,*) m\nif (m.lt.0) go to 60\nmat(iply)=m\nwrite(6,*) 'enter ply angle: '\nread (5,*) theta(iply)\nz(iply+1)=z(iply)+thk(m)\niply=iply+1\ngo to 40\nc compute boundary coordinates (measured from centerline)\n60 thick=z(iply)\nN = iply-1\nz0 = thick/2.\nnp1=N+1\ndo 70 i=1,np1\nz(i)=z(i)-z0\n70 continue\nc----------------------------------------------------------------------\nc----------------------------------------------------------------------\nc loop over plies, form stiffness matrix\ndo 110 iply=1,N\nm=mat(iply)\nc form lamina compliance in 1-2 directions (Eqn. 3.55)\nS(1,1) = 1./E1(m)\nS(2,1) = -Gnu12(m) / E1(m)\nS(3,1) = 0.\nS(1,2) = S(2,1)\nS(2,2) = 1./E2(m)\nS(3,2) = 0.\nS(1,3) = 0.\nS(2,3) = 0.\nS(3,3) = 1./G12(m)\nc----------------------------------------------------------------------\nc transform to x-y axes\nc obtain transformation matrix T (Eqn. 3.27)\nthet = theta(iply) * 3.14159/180.\nsc = sin(thet)*cos(thet)\ns2 = (sin(thet))**2\nc2 = (cos(thet))**2\nT(1,1) = c2\nT(2,1) = s2\nT(3,1) = -1.*sc\nT(1,2) = s2\nT(2,2) = c2\nT(3,2) = sc\nT(1,3) = 2.*sc\nT(2,3) = -2.*sc\nT(3,3) = c2 - s2\nc inverse transformation matrix\nTinv(1,1) = c2\nTinv(2,1) = s2\nTinv(3,1) = sc\nTinv(1,2) = s2\nTinv(2,2) = c2\nTinv(3,2) = -1.*sc\nTinv(1,3) = -2.*sc\nTinv(2,3) = 2.*sc\nTinv(3,3) = c2 - s2\nc transformation [Sbar] = [R][T]-1[R]-1[S][T] (Eqn. 3.56)\ncall matmul (3,3,3,3,3,3,R,Tinv,temp1)\ncall matmul (3,3,3,3,3,3,temp1,Rinv,temp2)\ncall matmul (3,3,3,3,3,3,temp2,S,temp3)\ncall matmul (3,3,3,3,3,3,temp3,T,Sbar)\nc----------------------------------------------------------------------\nc invert Sbar (transformed compliance matrix) to obtain\nc Qbar (transformed stiffness matrix)\nc start by setting Qbar = Sbar, then call inversion routine\ndo 80 i=1,3\ndo 80 j=1,3\nQbar(i,j)=Sbar(i,j)\n80 continue\ncall matinv(isol,idsol,3,3,Qbar,3,kwa,det)\nc save Qbar and Tinv matrices\ndo 90 i=1,3\ndo 90 j=1,3\nQsave(i,j,iply)=Qbar(i,j)\nTsave(i,j,iply)=Tinv(i,j)\n90 continue\nc add to laminate stiffness matrix\nip1=iply+1\nz1= (z(ip1) -z(iply) )\nz2= 0.5*(z(ip1)**2-z(iply)**2)\nz3=(1./3.)*(z(ip1)**3-z(iply)**3)\ndo 100 i=1,3\ndo 100 j=1,3\nE(i,j) = E(i,j) + Qbar(i,j)*z1\nxx = Qbar(i,j)*z2\nE(i+3,j) = E(i+3,j) + xx\nE(i,j+3) = E(i,j+3) + xx\nE(i+3,j+3)= E(i+3,j+3) + Qbar(i,j)*z3\n100 continue\nc end loop over plies; stiffness matrix now formed\n110 continue\nc----------------------------------------------------------------------\nc----------------------------------------------------------------------\nc output stiffness matrix\nwrite(6,120)\n120 format(/' laminate stiffness matrix:',/)\ndo 140 i=1,6\nwrite(6,130) (e(i,j),j=1,6)\n130 format (4x,3e12.4,2x,3d12.4)\nif (i.eq.3) write(6,*)\n140 continue\nc----------------------------------------------------------------------\nc obtain and print laminate compliance matrix\nc do 300 i=1,6\nc do 300 j=1,6\nc Et(i,j)=E(i,j)\nc300 continue\nc call matinv(isol,idsol,6,6,Et,6,kwa,det)\nc write(6,310)\nc310 format(/' laminate compliance matrix:',/)\nc do 320 i=1,6\nc write(6,130) (Et(i,j),j=1,6)\nc if (i.eq.3) write(6,*)\nc320 continue\nc----------------------------------------------------------------------\nc obtain traction-moment vector\nwrite(6,*)\nwrite(6,*) 'input tractions and moments...'\nwrite(6,*)\nwrite(6,*) ' Nx: '\nread (5,*) e(1,7)\nwrite(6,*) ' Ny: '\nread (5,*) e(2,7)\nwrite(6,*) ' Nxy: '\nread (5,*) e(3,7)\nwrite(6,*) ' Mx: '\nread (5,*) e(4,7)\nwrite(6,*) ' My: '\nread (5,*) e(5,7)\nwrite(6,*) ' Mxy: '\nread (5,*) e(6,7)\nc----------------------------------------------------------------------\nc solve resulting system; print strains and rotations\ncall matinv(isol,idsol,6,7,e,6,kwa,det)\nwrite(6,150) (e(i,7),i=1,6)\n150 format(/' midplane strains:',//3x,'eps-xx =',e12.4,\n* /3x,'eps-yy =',e12.4,/3x,'eps-xy =',e12.4,\n* //' rotations:',//3x,'kappa-xx =',e12.4,\n* /3x,'kappa-yy= ',e12.4,/3x,'kappa-xy =',e12.4//)\nc----------------------------------------------------------------------\nc compute ply stresses\nwrite(6,160)\n160 format (/' stresses:',/2x,'ply',5x,'sigma-1',\n* 5x,'sigma-2',4x,'sigma-12'/)\ndo 210 iply=1,N\ndo 180 i=1,3\neps0(i)=e(i,7)\nxkappa(i)=e(i+3,7)\ndo 170 j=1,3\nQbar(i,j)=Qsave(i,j,iply)\nTinv(i,j)=Tsave(i,j,iply)\n170 continue\n180 continue\ncall matmul (3,3,3,3,3,1,Qbar,eps0,vtemp1)\ncall matmul (3,3,3,3,3,1,Qbar,xkappa,vtemp2)\nzctr=(z(iply)+z(iply+1))/2.\ndo 190 i=1,3\nsigbar(i) = vtemp1(i) + zctr*vtemp2(i)\n190 continue\ncall matmul (3,3,3,3,3,1,Tinv,sigbar,sig)\nwrite(6,200) iply,sig\n200 format (3x,i2,3e12.4)\n210 continue\nstop\nend\nc----------------------------------------------------------------------\nc----------------------------------------------------------------------\nc -------- library routines for matrix operations -----------\nsubroutine matmul(lra,lrb,lrc,i,j,k,a,b,c)\nc\nc this subroutine performs the multiplication of two\nc two-dimensional matrices (a(i,j)*b(j,k) = c(i,k)).\nc\nc lra - row dimension of \"a\" (multiplier) matrix\nc lrb - row dimension of \"b\" (multiplicand) matrix\nc lrc - row dimension of \"c\" (product) matrix\nc i - actual number of rows in \"a\"\nc j - actual number of columns in \"a\"\nc k - actual number of columns in \"b\"\nc a - multiplier\nc b - multiplicand\nc c - product\ndimension a(1), b(1), c(1)\ndo 20 l = 1,i\nnm1 = 0\nlm = l\ndo 20 m = 1,k\nc(lm) = 0.0\nnm = nm1\nln = l\ndo 10 n = 1,j\nnm = nm + 1\nc(lm) = c(lm) + a(ln)*b(nm)\n10 ln = ln + lra\nnm1 = nm1 + lrb\n20 lm = lm + lrc\nreturn\nend\nsubroutine matinv(isol,idsol,nr,nc,a,mra,kwa,det)\nc\nc this subroutine finds the inverse and/or solves\nc simultaneous equations, or neither, and\nc calculates a determinant of a real matrix.\nc\nc isol - communications flag (output)\nc 1 - inverse found or equations solved\nc 2 - unable to solve\nc 3 - input error\nc idsol - determinant calculation flag (output)\nc 1 - did not overflow\nc 2 - overflow\nc nr - number of rows in input matrix \"a\"\nc nc - number of columns in \"a\"\nc a - input matrix, first \"nr\" columns will be inverted\nc on output, \"a\" is converted to a-inverse\nc mra - row dimension of \"a\" matrix\nc kwa - work array\nc det - value of determinant (if idsol = 1)\ndimension a(1), kwa(1)\nir = nr\nisol = 1\nidsol = 1\nif(nr.le.0) go to 330\nif((ir-mra).gt.0) go to 330\nic = iabs(nc)\nif ((ic - ir).lt.0) ic = ir\nibmp = 1\njbmp = mra\nkbmp = jbmp + ibmp\nnes = ir*jbmp\nnet = ic*jbmp\nif(nc) 10,330,20\n10 mdiv = jbmp + 1\niric = ir - ic\ngo to 30\n20 mdiv = 1\n30 mad = mdiv\nmser = 1\nkser = ir\nmz = 1\ndet = 1.0\n40 piv = 0.\ni = mser\n50 if (( i - kser).gt.0) go to 70\nif((abs(a(i))-piv).le.0.) go to 60\npiv = abs(a(i))\nip = i\n60 i = i + ibmp\ngo to 50\n70 if(piv.eq.0.) go to 340\nif(nc.lt.0) go to 80\ni = ip-((ip - 1)/jbmp)*jbmp\nj = mser - ((mser - 1)/jbmp)*jbmp\njj = mser/kbmp + 1\nii = jj + (ip -mser)\nkwa(jj) = ii\ngo to 90\n80 i = ip\nj = mser\n90 if (ip - mser) 330,120,100\n100 if ((j - net).gt.0) go to 110\npsto = a(i)\na(i) = a(j)\na(j) = psto\ni = i + jbmp\nj = j + jbmp\ngo to 100\n110 det = - det\n120 psto = a(mser)\ndet = det*psto\n130 if (det.eq.0.) goto 150\n140 psto = 1./psto\ngo to 160\n150 idsol = 1\nisol = 2\nreturn\n160 continue\na(mser) = 1.0\ni = mdiv\n170 if((i - net).gt.0) go to 180\na(i) = a(i)*psto\ni = i + jbmp\ngo to 170\n180 if((mz - kser).gt.0) go to 210\nif((mz-mser).eq.0) go to 200\ni = mad\nj = mdiv\npsto = a(mz)\nif(psto.eq.0.) go to 200\na(mz) = 0.\n190 if((j-net).gt.0) go to 200\na(i) = a(i) - a(j)*psto\nj = j + jbmp\ni = i + jbmp\ngo to 190\n200 mad = mad + ibmp\nmz = mz + ibmp\ngo to 180\n210 continue\nc 210 need a test here.....call overfl(ivf)\nc go to (350,220),ivf\nccccccc need at test here, anyhow\n220 kser = kser + jbmp\nif ((kser-nes).gt.0) go to 260\nmser = mser + kbmp\nif(nc.lt.0) go to 230\nmdiv = mdiv + ibmp\nmz = ((mser - 1)/jbmp)*jbmp + 1\nmad = 1\ngo to 40\n230 mdiv = mdiv + kbmp\nif(iric.ne.0) go to 240\nmz = mser + ibmp\ngo to 250\n240 mz = ((mser - 1)/jbmp)*jbmp + 1\n250 mad = mz + jbmp\ngo to 40\n260 if(nc.lt.0) return\njr = ir\n270 if(jr) 330,360,280\n280 if(kwa(jr) - jr) 330,320,290\n290 k = (jr - 1)*jbmp\nj = k + ir\nl = (kwa(jr) - 1)*jbmp + ir\n300 if(j - k) 330,320,310\n310 psto = a(l)\na(l) = a(j)\na(j) = psto\nj = j - ibmp\nl = l - ibmp\ngo to 300\n320 jr = jr - 1\ngo to 270\n330 isol = 3\nreturn\n340 det = 0.\nisol = 2\nidsol = 1\nreturn\n350 isol = 2\nidsol = 2\n360 return\nend", "meta": {"hexsha": "af2b597866cfd44a875f38c9cf870bf1c8fd00ce", "size": 10067, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "F95/mit_ocw_laminate.f95", "max_stars_repo_name": "goedman/ClassicalLaminateTheory.jl", "max_stars_repo_head_hexsha": "bfb2d9a8d59809a7f93d909c4be18a4a90666d33", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-05-12T19:33:01.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T08:43:50.000Z", "max_issues_repo_path": "F95/mit_ocw_laminate.f95", "max_issues_repo_name": "goedman/ClassicalLaminateTheory.jl", "max_issues_repo_head_hexsha": "bfb2d9a8d59809a7f93d909c4be18a4a90666d33", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "F95/mit_ocw_laminate.f95", "max_forks_repo_name": "goedman/ClassicalLaminateTheory.jl", "max_forks_repo_head_hexsha": "bfb2d9a8d59809a7f93d909c4be18a4a90666d33", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-02-08T11:32:15.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-01T18:51:55.000Z", "avg_line_length": 26.0803108808, "max_line_length": 71, "alphanum_fraction": 0.5292539982, "num_tokens": 4050, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569267, "lm_q2_score": 0.7461389817407016, "lm_q1q2_score": 0.6729581712625333}} {"text": "c ============================================\n subroutine diffuse_u(maxmx,mbc,mx,meqn,q,\n & xlower,dx,t,dt)\nc ============================================\n\n implicit none\n double precision q(1-mbc:maxmx+mbc, meqn)\n\n integer maxmx,mbc,mx,meqn,maux\n double precision xlower,dx,t,dt\n\n* !local variables\n integer MXMAX,i\n parameter (MXMAX=5000)\n double precision visc,rk\n double precision r(1:MXMAX),u(1:MXMAX)\n\n include \"digparamsdec.i\"\n include \"digparamscommon.i\"\n return\n if (mx.gt.MXMAX) then\n write(*,*) 'diffuse_u: increase MXMAX to: ', mx\n stop\n endif\n\n visc = m0*mu\n rk = visc/(2.d0*dx**2)\n do i = 1,mx\n if (q(i,1).gt.dry_tol) then\n u(i) = q(i,2)/q(i,1)\n else\n u(i) = 0.d0\n endif\n enddo\n r(1) = (1.d0-rk)*u(1) + rk*u(2)\n r(mx) = (1.d0-rk)*u(mx) + rk*u(mx-1)\n\n do i = 2,mx-1\n r(i) = rk*u(i-1) + (1.d0-2.d0*rk)*u(i) + rk*u(i+1)\n enddo\n\n call cranknicholson(u(1:mx),r(1:mx),rk,mx)\n\n do i = 1,mx\n q(i,2) = u(i)*q(i,1)\n enddo\n do i=1,mbc\n q(1-i,2) = q(1,2)\n q(mx+i,2) = q(mx,2)\n enddo\n\n return\n end\n\nc ------------------------------------------------------------------\n subroutine cranknicholson(u,r,rk,n)\nc ------------------------------------------------------------------\n\n integer n,NMAX\n* !i/o\n double precision a,b,c,rk,u(n),r(n)\n* !i/o\n PARAMETER (NMAX = 5000)\n integer j\n double precision bet,gam(NMAX)\n\n a = -rk\n b = 1.d0+2.d0*rk\n c = -rk\n\n bet = 1.d0 + rk!b\n u(1) = r(1)/bet\n\n do j = 2,n\n gam(j) = c/bet\n bet = b - a*gam(j)\n if (j.eq.n) bet = bet - rk\n if (bet.eq.0.) then\n write(*,*) 'tridiag failed'\n stop\n endif\n u(j) = (r(j)-a*u(j-1))/bet\n enddo\n\n do j = n-1,1,-1\n u(j) = u(j) - gam(j+1)*u(j+1)\n enddo\n\n return\n end\n", "meta": {"hexsha": "bd489d609c3ad57c86ee946c0e85b898517c255e", "size": 2077, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "geoclaw/1d/lib_dig/diffuse_u_dig.f", "max_stars_repo_name": "geoflows/geoclaw-4.x", "max_stars_repo_head_hexsha": "c8879d25405017b38392aa3b1ea422ff3e3604ea", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2016-11-13T03:11:51.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-07T18:59:48.000Z", "max_issues_repo_path": "geoclaw/1d/lib_dig/diffuse_u_dig.f", "max_issues_repo_name": "che-wenchao/D-Claw", "max_issues_repo_head_hexsha": "8ab5d971c9a7a7130e03a447a4b8642e292f4e88", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2020-01-14T18:00:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T14:25:24.000Z", "max_forks_repo_path": "geoclaw/1d/lib_dig/diffuse_u_dig.f", "max_forks_repo_name": "che-wenchao/D-Claw", "max_forks_repo_head_hexsha": "8ab5d971c9a7a7130e03a447a4b8642e292f4e88", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-01-14T17:15:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-03T17:28:44.000Z", "avg_line_length": 22.8241758242, "max_line_length": 72, "alphanum_fraction": 0.4034665383, "num_tokens": 708, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789468908171, "lm_q2_score": 0.7520125848754472, "lm_q1q2_score": 0.6728929414329623}} {"text": "module Samples\n use Const\n implicit none\ncontains \n function linear2(t, X) result(dX)\n real(mpc) :: t, X(2), dX(size(X))\n intent(in) :: t, X\n dX(1) = -X(2)\n dX(2) = X(1)\n end function linear2\n function sol_linear2(t) result(X)\n real(mpc), intent(in) :: t\n real(mpc), dimension(2) :: X\n X(1) = cos(t) - sin(t)\n X(2) = sin(t) + cos(t)\n end function sol_linear2\n function linear2_nhom(t, X) result(dX)\n real(mpc) :: t, X(2), dX(size(X))\n intent(in) :: t, X\n dX(1) = 3.0_mpc*X(1) + 2.0_mpc*X(2) + sin(t)\n dX(2) = -5.0_mpc*X(1) + 1.0_mpc*X(2) + exp(-t)\n end function linear2_nhom\n function sol_linear2_nhom(t) result(X)\n real(mpc), intent(in) :: t\n real(mpc), dimension(2) :: X\n X(1) = exp(2*t)*(53.0*sin(3*t)/45.0+151.0*cos(3*t)/180.0)-sin(t)/10.0+co&\n &s(t)/20.0+exp(-t)/9.0\n X(2) = exp(2*t)*((-133.0)*sin(3*t)/72.0+97.0*cos(3*t)/72.0)+(-3.0)*sin(t&\n &)/8.0-cos(t)/8.0+(-2.0)*exp(-t)/9.0\n end function sol_linear2_nhom\nend module Samples\n", "meta": {"hexsha": "3209d00c708b771627291e73564f01b7999f92f6", "size": 1102, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/utils/Samples.f90", "max_stars_repo_name": "taxus-d/integrators", "max_stars_repo_head_hexsha": "90464d4994298343b70c10682a07183e391a18e3", "max_stars_repo_licenses": ["MIT"], "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/Samples.f90", "max_issues_repo_name": "taxus-d/integrators", "max_issues_repo_head_hexsha": "90464d4994298343b70c10682a07183e391a18e3", "max_issues_repo_licenses": ["MIT"], "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/Samples.f90", "max_forks_repo_name": "taxus-d/integrators", "max_forks_repo_head_hexsha": "90464d4994298343b70c10682a07183e391a18e3", "max_forks_repo_licenses": ["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.4375, "max_line_length": 81, "alphanum_fraction": 0.5099818512, "num_tokens": 443, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894604912848, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6728929301302747}} {"text": "!dis \n!dis Open Source License/Disclaimer, Forecast Systems Laboratory\n!dis NOAA/OAR/FSL, 325 Broadway Boulder, CO 80305\n!dis \n!dis This software is distributed under the Open Source Definition,\n!dis which may be found at http://www.opensource.org/osd.html.\n!dis \n!dis In particular, redistribution and use in source and binary forms,\n!dis with or without modification, are permitted provided that the\n!dis following conditions are met:\n!dis \n!dis - Redistributions of source code must retain this notice, this\n!dis list of conditions and the following disclaimer.\n!dis \n!dis - Redistributions in binary form must provide access to this\n!dis notice, this list of conditions and the following disclaimer, and\n!dis the underlying source code.\n!dis \n!dis - All modifications to this software must be clearly documented,\n!dis and are solely the responsibility of the agent making the\n!dis modifications.\n!dis \n!dis - If significant modifications or enhancements are made to this\n!dis software, the FSL Software Policy Manager\n!dis (softwaremgr@fsl.noaa.gov) should be notified.\n!dis \n!dis THIS SOFTWARE AND ITS DOCUMENTATION ARE IN THE PUBLIC DOMAIN\n!dis AND ARE FURNISHED \"AS IS.\" THE AUTHORS, THE UNITED STATES\n!dis GOVERNMENT, ITS INSTRUMENTALITIES, OFFICERS, EMPLOYEES, AND\n!dis AGENTS MAKE NO WARRANTY, EXPRESS OR IMPLIED, AS TO THE USEFULNESS\n!dis OF THE SOFTWARE AND DOCUMENTATION FOR ANY PURPOSE. THEY ASSUME\n!dis NO RESPONSIBILITY (1) FOR THE USE OF THE SOFTWARE AND\n!dis DOCUMENTATION; OR (2) TO PROVIDE TECHNICAL SUPPORT TO USERS.\n!dis \n!dis \n\n SUBROUTINE interp_press_to_z(press_levels, heights, new_level, press_out, &\n nx,ny,nz)\n\n ! Given a 1D array of pressure levels and a 3D array of heights (m) at\n ! those levels, this routine interpolates the pressure to the desired\n ! new_level.\n\n ! Pressures are in Pa, heights are in m!\n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: nx,ny,nz\n REAL, INTENT(IN) :: press_levels(nz)\n REAL, INTENT(IN) :: heights(nx,ny,nz)\n REAL, INTENT(IN) :: new_level\n REAL, INTENT(OUT) :: press_out (nx,ny)\n INTEGER :: i,j,k, ktop\n REAL :: ptop,pbot,ztop,zbot\n\n nsloop: DO j = 1, ny\n ewloop: DO i = 1, nx\n vertloop: DO k = 2, nz\n IF (heights(nx,ny,nz) .ge. new_level) THEN\n ktop = k\n EXIT vertloop\n ENDIF\n ENDDO vertloop\n ztop = heights(i,j,k)\n zbot = heights(i,j,k-1)\n ptop = press_levels(k)*0.01 ! Convert to mb!\n pbot = press_levels(k-1)*0.01\n press_out(i,j) = EXP ( &\n ( new_level*ALOG(pbot/ptop) - &\n ztop*ALOG(pbot) + &\n zbot*ALOG(ptop) ) / &\n (zbot - ztop) ) * 100. ! convert back to Pa\n ENDDO ewloop\n ENDDO nsloop\n RETURN\n END SUBROUTINE interp_press_to_z\n \n \n\n \n", "meta": {"hexsha": "b546099ce86ee8e77f043816a098da9fc8fe59be", "size": 3153, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/lfmpost/interp_press_to_z.f90", "max_stars_repo_name": "maxinye/laps-mirror", "max_stars_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_stars_repo_licenses": ["Intel", "Unlicense", "OLDAP-2.2.1", "NetCDF"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-04-05T12:28:22.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-29T06:37:29.000Z", "max_issues_repo_path": "src/lfmpost/interp_press_to_z.f90", "max_issues_repo_name": "longwosion/laps-mirror", "max_issues_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_issues_repo_licenses": ["Intel", "NetCDF", "OLDAP-2.2.1", "Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/lfmpost/interp_press_to_z.f90", "max_forks_repo_name": "longwosion/laps-mirror", "max_forks_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_forks_repo_licenses": ["Intel", "NetCDF", "OLDAP-2.2.1", "Unlicense"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-04-27T12:51:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-19T13:57:44.000Z", "avg_line_length": 39.4125, "max_line_length": 77, "alphanum_fraction": 0.6111639708, "num_tokens": 818, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789457685656, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6728929280204066}} {"text": "program test_eigenvectors\n !! Program to show the usage of the the *eigenvectors* module.\n use eigenvectors\n implicit none\n integer, parameter :: N = 3\n integer :: i\n real :: A(N,N), v(N), lambda1, lambda2, lambda3\n character(:), allocatable :: fmt\n\n fmt = '(F7.2)'\n\n A(1,:) = [ 1., 0., 0. ]\n A(2,:) = [ 0., -0.5, 0. ]\n A(3,:) = [ 0., 0., -4.]\n\n call eigen_max(A, v, lambda1, maxIter= 1000, err_v=1.E-6, v_0=[1.,1.,1.])\n print*, \"biggest eigenvalue: \"\n write(*,fmt=fmt) lambda1\n print*, \"associated eigenvector: \"\n do i = 1,N\n write(*,fmt=fmt) v(i)\n end do\n\n\n call eigen_inv(A, v, lambda1, maxIter= 1000, p=0., err_v=1.E-6, v_0=[1.,1.,1.])\n print*, \"smallest eigenvalue: \"\n write(*,fmt=fmt) lambda1\n print*, \"associated eigenvector: \"\n do i = 1,N\n write(*,fmt=fmt) v(i)\n end do\n\nend program\n", "meta": {"hexsha": "3b95453ff0d92cda938d9b53ab3bc1288f48fa51", "size": 964, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "docs/src/test_eigen.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_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/test_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": 28.3529411765, "max_line_length": 87, "alphanum_fraction": 0.5020746888, "num_tokens": 329, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969137, "lm_q2_score": 0.7520125737597971, "lm_q1q2_score": 0.6728929272670596}} {"text": "!\n! CalculiX - A 3-dimensional finite element program\n! Copyright (C) 1998-2018 Guido Dhondt\n!\n! This program is free software; you can redistribute it and/or\n! modify it under the terms of the GNU General Public License as\n! published by the Free Software Foundation(version 2);\n! \n!\n! This program is distributed in the hope that it will be useful,\n! but WITHOUT ANY WARRANTY; without even the implied warranty of \n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \n! GNU General Public License for more details.\n!\n! You should have received a copy of the GNU General Public License\n! along with this program; if not, write to the Free Software\n! Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n!\n subroutine tridiagonal_nrhs(a,b,n,m,nrhs)\n!\n! solves a tridiagonal system of equations A*x=b with\n! n equations. The off-diagonals are in symmetric positions\n! about the main diagonal and m entries away; the matrix does\n! not have to be symmetric\n!\n! the first line contains the elements A(1,1) and A(1,1+m)\n! the last line contains the elements A(n,n-m),A(n,n)\n! (assuming full storage mode)\n!\n! tridiagonal storage: \n! left diagonal in a(1,*)\n! main diagonal in a(2,*)\n! right diagonal in a(3,*)\n!\n! INPUT:\n! \n! a tridiagonal matrix\n! b right hand side\n! n number of rows and columns of a\n! m shift of the off-diagonals compared\n! to the main diagonal\n! nrsh number of right hand sides\n!\n! OUTPUT\n!\n! b solution\n!\n implicit none\n!\n integer i,k,n,m,nrhs\n!\n real*8 a(3,n),b(nrhs,n),y\n!\n intent(in) n,m,nrhs\n!\n intent(inout) a,b\n!\n! Gaussian elimination: all values below the\n! diagonal are set to zero, the diagonal values set to 1\n!\n! only the unknown values a(3,*) and b(nrhs,*) are calculated\n!\n do k=1,m\n a(3,k)=a(3,k)/a(2,k)\n do i=1,nrhs\n b(i,k)=b(i,k)/a(2,k)\n enddo\n enddo\n!\n do k=m+1,n-m\n y=1.d0/(a(3,k-m)*a(1,k)-a(2,k))\n a(3,k)=-a(3,k)*y\n do i=1,nrhs\n b(i,k)=(b(i,k-m)*a(1,k)-b(i,k))*y\n enddo\n enddo\n!\n do k=n-m+1,n\n a(2,k)=a(3,k-m)*a(1,k)-a(2,k)\n do i=1,nrhs\n b(i,k)=(b(i,k-m)*a(1,k)-b(i,k))/a(2,k)\n enddo\n enddo\n!\n! back substitution\n!\n do k=n-m,1,-1\n do i=1,nrhs\n b(i,k)=b(i,k)-a(3,k)*b(i,k+m)\n enddo\n enddo\n!\n return\n end\n\n", "meta": {"hexsha": "e734b4fd007c8f7fa72c598b551ccd6093a30331", "size": 2661, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ccx_prool/CalculiX/ccx_2.15/src/tridiagonal_nrhs.f", "max_stars_repo_name": "alleindrach/calculix-desktop", "max_stars_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ccx_prool/CalculiX/ccx_2.15/src/tridiagonal_nrhs.f", "max_issues_repo_name": "alleindrach/calculix-desktop", "max_issues_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ccx_prool/CalculiX/ccx_2.15/src/tridiagonal_nrhs.f", "max_forks_repo_name": "alleindrach/calculix-desktop", "max_forks_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.71875, "max_line_length": 71, "alphanum_fraction": 0.5524239008, "num_tokens": 786, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894548800271, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6728929259105384}} {"text": "! Set initial conditions for q.\nsubroutine qinit(meqn, mbc, mx, my, mz, xlower, ylower, zlower, dx, dy, dz, q, maux, aux)\n\n implicit none\n\n ! Input/Output\n integer, intent(in) :: meqn, mbc, mx, my, mz, maux\n real(kind=8), intent(in) :: xlower, ylower, zlower, dx, dy, dz\n real(kind=8), intent(inout) :: q(meqn, 1-mbc:mx+mbc, 1-mbc:my+mbc, 1-mbc:mz+mbc)\n real(kind=8), intent(in) :: aux(maux, 1-mbc:mx+mbc, 1-mbc:my+mbc, 1-mbc:mz+mbc)\n\n ! Local storage\n integer :: i, j, k\n real(kind=8) :: x, y, z, r, rho\n\n do i = 1, mx\n x = xlower + (i - 0.5d0) * dx\n do j = 1, my\n y = ylower + (j - 0.5d0) * dy\n do k = 1, mz\n z = zlower + (k - 0.5d0) * dz\n r = sqrt(x**2 + y**2 + z**2)\n rho = 1.d0 + 10.d0 * exp(-20.d0 * (r - 0.d0)**2)\n q(1, i, j, k) = rho\n q(2, i, j, k) = 0.d0\n q(3, i, j, k) = 0.d0\n q(4, i, j, k) = 0.d0\n q(5, i, j, k) = 0.d0\n end do\n end do\n end do\nend subroutine qinit\n", "meta": {"hexsha": "4b55c94b588649214d2bdcf3717188f08ad71d5e", "size": 1082, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/euler_3d_radial/qinit.f90", "max_stars_repo_name": "rjleveque/amrclaw", "max_stars_repo_head_hexsha": "d7acfe4a71b2515778b134540a015923ce77a3cd", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2015-05-27T08:16:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-21T06:36:24.000Z", "max_issues_repo_path": "examples/euler_3d_radial/qinit.f90", "max_issues_repo_name": "clawpack/amrclaw", "max_issues_repo_head_hexsha": "d7acfe4a71b2515778b134540a015923ce77a3cd", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 107, "max_issues_repo_issues_event_min_datetime": "2015-01-02T19:51:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-24T03:35:32.000Z", "max_forks_repo_path": "examples/euler_3d_radial/qinit.f90", "max_forks_repo_name": "rjleveque/amrclaw", "max_forks_repo_head_hexsha": "d7acfe4a71b2515778b134540a015923ce77a3cd", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 28, "max_forks_repo_forks_event_min_datetime": "2015-01-10T00:03:56.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-11T23:52:34.000Z", "avg_line_length": 32.7878787879, "max_line_length": 89, "alphanum_fraction": 0.4500924214, "num_tokens": 452, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789454880027, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6728929209374551}} {"text": "subroutine eval_curve(s, t, k, coef, nctl, ndim, n, val)\n\n !***DESCRIPTION\n !\n ! Written by Gaetan Kenway\n !\n ! Abstract eval_surf is a vector version of the B-spline evaluation function\n !\n ! Description of Arguments\n ! Input\n ! s - Real, Vector of s coordinates, length n\n ! t - Real, Knot vector. Length nctl+k\n ! k - Integer, order of B-spline \n ! coef - Real, Array of b-sline coefficients Size (ndim, nctl)\n ! nctl - Integer, Number of control points\n !\n ! Ouput \n ! val - Real, Evaluated points, size ndim by n\n\n use precision\n implicit none\n ! Input\n integer , intent(in) :: k, nctl, ndim, n\n real(kind=realType), intent(in) :: s(n)\n real(kind=realType), intent(in) :: t(nctl+k)\n real(kind=realType), intent(in) :: coef(ndim, nctl)\n\n ! Output\n real(kind=realType), intent(out) :: val(ndim, n)\n\n ! Working\n integer :: i, l, idim, istart, ileft\n real(kind=realType) :: basisu(k)\n\n val(:, :) = 0.0\n do i=1, n\n call findSpan(s(i), k, t, nctl, ileft)\n call basis(t, nctl, k, s(i), ileft, basisu)\n istart = ileft-k\n do l=1, k\n do idim=1, ndim\n val(idim, i) = val(idim, i) + basisu(l)*coef(idim, istart+l)\n end do\n end do\n end do\nend subroutine eval_curve\n\nsubroutine eval_curve_deriv(s, t, k, coef, nctl, ndim, val)\n\n !***DESCRIPTION\n !\n ! Written by Gaetan Kenway\n !\n ! Abstract eval_surf_deriv is a scalar version of the \n ! B-spline derivative evaluation function\n !\n ! Description of Arguments\n ! Input\n ! s - Real, s coordinate\n ! t - Real, Knot vector. Length nctl+k\n ! k - Integer, order of B-spline\n ! coef - Real, Array of B-spline coefficients. Size (ndim, nctl)\n ! nctl - Integer, Number of control points\n !\n ! Ouput \n ! val - Real, Evaluated point, size ndim\n\n use precision\n implicit none\n \n ! Input\n integer , intent(in) :: k, nctl, ndim\n real(kind=realType), intent(in) :: s\n real(kind=realType), intent(in) :: t(nctl+k)\n real(kind=realType), intent(in) :: coef(ndim, nctl)\n\n ! Output\n real(kind=realType), intent(out) :: val(ndim)\n\n ! Working\n integer :: idim\n\n ! Functions\n real(kind=realType) :: bvalu\n\n do idim=1, ndim\n val(idim) = bvalu(t, coef(idim, :), nctl, k, 1, s)\n end do\n\nend subroutine eval_curve_deriv\n\nsubroutine eval_curve_deriv2(s, t, k, coef, nctl, ndim, val)\n\n !***DESCRIPTION\n !\n ! Written by Gaetan Kenway\n !\n ! Abstract eval_curve_deriv2 evals the 2nd derivative\n ! B-spline derivative evaluation function\n !\n ! Description of Arguments\n ! Input\n ! s - Real, s coordinate\n ! t - Real, Knot vector. Length nctl+k\n ! k - Integer, order of B-spline\n ! coef - Real, Array of B-spline coefficients Size (ndim, nctl)\n ! nctl - Integer, Number of control points\n !\n ! Ouput \n ! val - Real, Evaluated point, size ndim\n\n use precision\n implicit none\n ! Input\n integer , intent(in) :: k, nctl, ndim\n real(kind=realType), intent(in) :: s\n real(kind=realType), intent(in) :: t(nctl+k)\n real(kind=realType), intent(in) :: coef(ndim, nctl)\n\n ! Output\n real(kind=realType), intent(out) :: val(ndim)\n\n ! Working\n integer :: idim\n\n ! Functions\n real(kind=realType) :: bvalu\n\n if (k == 2) then\n val(:) = 0.0\n else\n do idim=1, ndim\n val(idim) = bvalu(t, coef(idim, :), nctl, k, 2, s)\n end do\n end if\n\nend subroutine eval_curve_deriv2\n\n\nsubroutine eval_curve_c(s, t, k, coef, nctl, ndim, n, val)\n\n !***DESCRIPTION\n !\n ! Written by Gaetan Kenway\n !\n ! Abstract eval_curve_complex is a special version for evaluation\n ! of data when control points are used in a complex-step analysis\n ! The actual derivative is computed analytically, but the output looks\n ! like the CS went all the way through\n !\n ! Description of Arguments\n ! Input\n ! s - Real, s coordinate\n ! t - Real, Knot vector. Length nctl+k\n ! k - Integer, order of B-spline\n ! coef - Real, Array of B-spline coefficients Size (ndim, nctl)\n ! nctl - Integer, Number of control points\n !\n ! Ouput \n ! val - Real, Evaluated point, size ndim\n\n use precision\n implicit none\n ! Input\n integer , intent(in) :: k, nctl, ndim, n\n complex(kind=realType) , intent(in) :: s(n)\n real(kind=realType) , intent(in) :: t(nctl+k)\n complex(kind=realType) , intent(in) :: coef(ndim, nctl)\n\n ! Output\n complex(kind=realType) , intent(out) :: val(ndim, n)\n\n ! Working\n integer :: i, l, istart, ileft, idim\n complex(kind=realType) :: basisu(k)\n\n val(:, :) = cmplx(0.0, 0.0)\n do i=1, n\n call findSpan(real(s(i)), k, t, nctl, ileft)\n call basis_c(t, nctl, k, s(i), ileft, basisu)\n\n istart = ileft - k\n do l=1, k\n do idim=1, ndim\n val(idim, i) = val(idim, i) + basisu(l)*coef(idim, istart+l)\n end do\n end do\n end do\nend subroutine eval_curve_c\n\nsubroutine eval_curve_deriv_c(s, t, k, coef, nctl, ndim, val)\n\n !***DESCRIPTION\n !\n ! Written by Gaetan Kenway\n !\n ! Abstract eval_surf_deriv is a scalar version of the \n ! B-spline derivative evaluation function\n !\n ! Description of Arguments\n ! Input\n ! s - Real, s coordinate\n ! t - Real, Knot vector. Length nctl+k\n ! k - Integer, order of B-spline\n ! coef - Complex, Array of B-spline coefficients. Size (ndim, nctl)\n ! nctl - Integer, Number of control points\n !\n ! Ouput \n ! val - Complex, Evaluated derivative, size ndim\n\n use precision\n implicit none\n ! Input\n integer , intent(in) :: k, nctl, ndim\n real(kind=realType) , intent(in) :: s\n real(kind=realType) , intent(in) :: t(nctl+k)\n complex(kind=realType), intent(in) :: coef(ndim, nctl)\n\n ! Output\n complex(kind=realType), intent(out) :: val(ndim)\n\n ! Working\n integer :: idim\n\n ! Functions\n complex(kind=realType) :: cbvalu\n\n do idim=1, ndim\n val(idim) = cbvalu(t, coef(idim, :), nctl, k, 1, s)\n end do\n\nend subroutine eval_curve_deriv_c\n\nsubroutine eval_curve_deriv2_c(s, t, k, coef, nctl, ndim, val)\n\n !***DESCRIPTION\n !\n ! Written by Gaetan Kenway\n !\n ! Abstract eval_curve_deriv2 evals the 2nd derivative\n ! B-spline derivative evaluation function\n !\n ! Description of Arguments\n ! Input\n ! s - Real, s coordinate\n ! t - Real, Knot vector. Length nctl+k\n ! k - Integer, order of B-spline\n ! coef - Complex, Array of B-spline coefficients Size (ndim, nctl)\n ! nctl - Integer, Number of control points\n !\n ! Ouput \n ! val - Real, Evaluated point, size ndim\n\n use precision\n implicit none\n ! Input\n integer , intent(in) :: k, nctl, ndim\n real(kind=realType) , intent(in) :: s\n real(kind=realType) , intent(in) :: t(nctl+k)\n complex(kind=realType), intent(in) :: coef(ndim, nctl)\n\n ! Output\n complex(kind=realType), intent(out) :: val(ndim)\n\n ! Working\n integer :: idim\n\n ! Functions\n complex(kind=realType) :: cbvalu\n\n do idim=1, ndim\n val(idim) = cbvalu(t, coef(idim, :), nctl, k, 2, s)\n end do\n\nend subroutine eval_curve_deriv2_c\n", "meta": {"hexsha": "3587f0f8c0759248fc9dd23ba083d18d220cdaff", "size": 7868, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/eval_curve.f90", "max_stars_repo_name": "eirikurj/pyspline", "max_stars_repo_head_hexsha": "91dd6d432deac3b1647508bf4fca985e704da77c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2019-04-18T00:49:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-20T14:40:08.000Z", "max_issues_repo_path": "src/eval_curve.f90", "max_issues_repo_name": "eirikurj/pyspline", "max_issues_repo_head_hexsha": "91dd6d432deac3b1647508bf4fca985e704da77c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 23, "max_issues_repo_issues_event_min_datetime": "2019-10-17T20:39:11.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T15:27:42.000Z", "max_forks_repo_path": "src/eval_curve.f90", "max_forks_repo_name": "eirikurj/pyspline", "max_forks_repo_head_hexsha": "91dd6d432deac3b1647508bf4fca985e704da77c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2019-05-29T16:56:15.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-08T13:51:24.000Z", "avg_line_length": 28.5072463768, "max_line_length": 82, "alphanum_fraction": 0.557193696, "num_tokens": 2397, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789454880027, "lm_q2_score": 0.752012562644147, "lm_q1q2_score": 0.6728929109912885}} {"text": "\nsubroutine itemwise_add_integer(input1, input2, output)\n implicit none\n integer, dimension(:), intent(in) :: input1\n integer, dimension(:), intent(in) :: input2\n integer, dimension(size(input1)), intent(out) :: output\n integer :: n\n\n do n = 1, size(input1)\n output(n) = input1(n) + input2(n)\n end do\n return\nend subroutine\n\nsubroutine itemwise_add_real(input1, input2, output)\n implicit none\n real, dimension(:), intent(in) :: input1\n real, dimension(:), intent(in) :: input2\n real, dimension(size(input1)), intent(out) :: output\n integer :: n\n\n do n = 1, size(input1)\n output(n) = input1(n) + input2(n)\n end do\n return\nend subroutine\n\nsubroutine itemwise_subtract_integer(input1, input2, output)\n implicit none\n integer, dimension(:), intent(in) :: input1\n integer, dimension(:), intent(in) :: input2\n integer, dimension(size(input1)), intent(out) :: output\n integer :: n\n\n do n = 1, size(input1)\n output(n) = input1(n) - input2(n)\n end do\n return\nend subroutine\n\nsubroutine itemwise_subtract_real(input1, input2, output)\n implicit none\n real, dimension(:), intent(in) :: input1\n real, dimension(:), intent(in) :: input2\n real, dimension(size(input1)), intent(out) :: output\n integer :: n\n\n do n = 1, size(input1)\n output(n) = input1(n) - input2(n)\n end do\n return\nend subroutine\n\nsubroutine itemwise_multiply_integer(input1, input2, output)\n implicit none\n integer, dimension(:), intent(in) :: input1\n integer, dimension(:), intent(in) :: input2\n integer, dimension(size(input1)), intent(out) :: output\n integer :: n\n\n do n = 1, size(input1)\n output(n) = input1(n) * input2(n)\n end do\n return\nend subroutine\n\nsubroutine itemwise_multiply_real(input1, input2, output)\n implicit none\n real, dimension(:), intent(in) :: input1\n real, dimension(:), intent(in) :: input2\n real, dimension(size(input1)), intent(out) :: output\n integer :: n\n\n do n = 1, size(input1)\n output(n) = input1(n) * input2(n)\n end do\n return\nend subroutine\n", "meta": {"hexsha": "7f39c932771292a0415317d84befc09f1e0a75fa", "size": 1994, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/examples/f95/fundamentals_arrays.f90", "max_stars_repo_name": "EraYaN/transpyle", "max_stars_repo_head_hexsha": "e7f5a021e7e6ab13fc21906b5a785dd24606cccc", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 107, "max_stars_repo_stars_event_min_datetime": "2018-01-12T05:19:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-16T20:56:52.000Z", "max_issues_repo_path": "test/examples/f95/fundamentals_arrays.f90", "max_issues_repo_name": "EraYaN/transpyle", "max_issues_repo_head_hexsha": "e7f5a021e7e6ab13fc21906b5a785dd24606cccc", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 17, "max_issues_repo_issues_event_min_datetime": "2018-01-24T08:08:12.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-29T23:36:11.000Z", "max_forks_repo_path": "test/examples/f95/fundamentals_arrays.f90", "max_forks_repo_name": "EraYaN/transpyle", "max_forks_repo_head_hexsha": "e7f5a021e7e6ab13fc21906b5a785dd24606cccc", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 20, "max_forks_repo_forks_event_min_datetime": "2018-12-05T13:21:37.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-11T11:48:33.000Z", "avg_line_length": 25.2405063291, "max_line_length": 60, "alphanum_fraction": 0.6780341023, "num_tokens": 591, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099168, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6728265663980783}} {"text": "module bessel_mod\n\ncontains\n\n SUBROUTINE BESIC (Z,N,B,IER)\n!\n! PACKAGE BESC (NOTE---DOCUMENTATION FOR INDIVIDUAL ROUTINES\n! FOLLOWS THE GENERAL PACKAGE INFORMATION.)\n!\n! LATEST REVISION NOVEMBER 1978\n!\n! PURPOSE TO CALCULATE BESSEL FUNCTIONS I AND J FOR\n! COMPLEX ARGUMENT AND INTEGER ORDERS.\n!\n! USAGE TO CALCULATE I BESSEL FUNCTIONS---\n!\n! CALL BESIC(Z,N,B,IER)\n!\n! TO CALCULATE J BESSEL FUNCTIONS---\n!\n! CALL BESJC(Z,N,B,IER)\n!\n! ENTRY POINTS BESIC,BESJC,B2SLCI\n!\n! COMMON BLOCKS NONE\n!\n! I/O NONE, EXCEPT FOR ERROR MESSAGES PRODUCED BY\n! CALLING THE ERROR HANDLING ROUTINE ULIBER.\n!\n! REQUIRED LIBRARY NONE\n! ROUTINES\n!\n! SPECIALIST RUSSELL K. REW\n!\n! LANGUAGE FORTRAN\n!\n! HISTORY DAVID J. SOOKNE WROTE THE CORE ROUTINE B2SLCI,\n! WHICH WAS ORIGINALLY DOUBLE PRECISION. THE\n! SINGLE PRECISION VERSION, AND THE USER ENTRIES\n! BESIC AND BESJC WERE WRITTEN BY RUSSELL K. REW\n! IN SEPTEMBER, 1977.\n!\n! SPACE REQUIRED 1712 (OCTAL) = 970 (DECIMAL) ON THE 7600.\n!\n! PORTABILITY THIS PACKAGE CONFORMS TO THE 1966 ANSI STANDARD\n! AS CONFIRMED BY THE PFORT VERIFIER. THERE ARE\n! FOUR MACHINE DEPENDENT CONSTANTS IN B2SLCI THAT\n! ARE DESCRIBED IN COMMENT CARDS.\n!\n! REQUIRED RESIDENT ULIBER (AN ERROR ROUTINE),SQRT,EXP,COS,SIN\n! ROUTINES\n!\n! REFERENCES \"BESSEL FUNCTIONS I AND J OF COMPLEX\n! ARGUMENT AND INTEGER ORDER\" AND\n! \"CERTIFICATION OF AN ALGORITHM FOR\n! BESSEL FUNCTIONS OF COMPLEX ARGUMENT\"\n! BOTH BY DAVID J. SOOKNE, JOURNAL OF REASEARCH\n! OF THE NATIONAL BUREAU OF STANDARDS-B. MATHE-\n! MATICAL SCIENCES, VOL. 77A, NOS. 3 AND 4, JULY-\n! DECEMBER, 1973.\n!\n! METHOD BACKWARD RECURSION WITH STRICT CONTROL OF\n! ERROR.\n!\n!-----------------------------------------------------------------------\n!\n! SUBROUTINE BESIC (Z,N,B,IER)\n!\n! DIMENSION OF B(N+1)\n! ARGUMENTS\n!\n! LATEST REVISION OCTOBER 1978\n!\n! PURPOSE TO CALCULATE I BESSEL FUNCTIONS FOR COMPLEX\n! ARGUMENT AND INTEGER ORDER\n!\n! USAGE CALL BESIC (Z,N,B,IER)\n!\n! ARGUMENTS\n!\n! ON INPUT Z\n! COMPLEX ARGUMENT FOR WHICH I BESSEL FUNCTIONS\n! ARE TO BE CALCULATED. ABS(AIMAG(Z)) MUST BE\n! LESS THAN THE LARGEST REAL ARGUMENT THAT THE\n! FORTRAN FUNCTION EXP CAN HANDLE.\n!\n! N\n! INTEGER, THE HIGHEST ORDER TO BE CALCULATED.\n! N MUST BE GREATER THAN OR EQUAL TO ZERO.\n!\n! ON OUTPUT B\n! COMPLEX VECTOR OF LENGTH N+1 CONTAINING THE\n! BESSEL FUNCTION VALUES I-SUB-0(Z),I-SUB-1(Z),\n! ...,I-SUB-N(Z) IN B(1),B(2),...,B(N+1).\n! IER\n! AN INTEGER ERROR FLAG.\n! =0 IF ALL DESIRED ORDERS HAVE BEEN CALCULATED\n! SATISFACTORILY,\n! =1 IF ABS(AIMAG(Z)) IS TOO LARGE,\n! =2 IF N IS LESS THAN ZERO,\n! =2+K IF ONLY THE FIRST K RESULTS ARE CORRECT.\n! IN THE RETURNED VALUES B(M) FOR M GREATER\n! THAN K, APPROXIMATELY THE LAST\n! ALOG10(ABS(B(M)/B(K))) SIGNIFICANT DIGITS\n! ARE IN ERROR.\n!\n! ENTRY POINTS BESIC\n!\n! SPECIAL CONDITIONS NONE\n!\n! COMMON BLOCKS NONE\n!\n! I/O NONE, EXCEPT FOR ERROR MESSAGES PRODUCED BY\n! CALLING THE ERROR HANDLING ROUTINE ULIBER.\n!\n! PRECISION SINGLE\n!\n! SPECIALIST RUSS REW, NCAR, BOULDER, COLORADO\n!\n! ACCURACY IN TESTS RUN ON THE 7600 WITH ORDERS FROM 0\n! THROUGH 10 USING RANDOM VALUES OF THE ARGUMENT\n! WITH ABSOLUTE VALUE LESS THAN 50 BUT\n! CONCENTRATED AROUND THE ORIGIN, THE MAXIMUM\n! RELATIVE ERROR (OR ABSOLUTE ERROR WHEN IT WAS\n! LARGER) OBSERVED WAS ABOUT 8.1E-14.\n!\n! TIMING ON NCAR\"S CONTROL DATA 7600, BESIC TAKES ABOUT\n! .32+.008*N MILLISECONDS WHEN Z=(1.0,1.0).\n!\n! PORTABILITY ANSI 1966 STANDARD\n!\n!\n!\n!\n!\n!\n COMPLEX Z ,B(100)\n real b2(2, 100)\n\n\n DATA IORJ/1/,XLARGE/741.66/\n\n NB = N+1\n\n\n\n CALL B2SLCI (REAL(Z),AIMAG(Z),NB,IORJ,B2,NCALC)\n\n do n = 1, nb\n b(n) = cmplx(b2(1,n), b2(2,n))\n end do\n\n IER = 0\n IF (NCALC .EQ. NB) GO TO 103\n IF (NCALC .GE. 0) GO TO 102\n IF (N .GE. 0) GO TO 101\n IER = 2\n CALL ULIBER (IER,'IN BESIC, N OUT OF RANGE')\n GO TO 103\n 101 IER = 1\n CALL ULIBER (IER,'IN BESIC, X OUT OF RANGE')\n GO TO 103\n 102 IER = 2+NCALC\n CALL ULIBER (IER,'IN BESIC, ACCURACY LOST FOR SOME ORDERS')\n 103 RETURN\n END SUBROUTINE BESIC\n\n\n!\n!******************************************************************************\n!\n\n subroutine b2slci (x,y,nb,ize,b,ncalc)\n!\n! this routine calculates bessel functions i and j of\n! complex argument and integer order.\n!\n!\n! explanation of variables in the calling sequence\n!\n! x real part of the complex argument\n! for which i*s or j*s are to be calculated. if i*s\n! are to be calculated, abs(x) must not exceed exparg\n! (which see below).\n! y imaginary part of the argument. if j*s are to be\n! calculated, abs(y) must not exceed exparg.\n! nb integer type. 1 + highest order to be calculated.\n! it must be positive.\n! ize integer type. zero if j*s are to be calculated, 1\n! if i*s are to be calculated.\n! b real array dimensioned b(2,nb), need not be initialized by user.\n! if the routine terminates normally, (ncalc=nb), it returns\n! j(or i)-sub-zero through j(or i)-sub-nb-minus-one of z in b.\n! the real parts of the results are returned in b(1,n) and the\n! corresponding imaginary parts are returned in b(2,n) for n=1,2,\n! ...,nb. (in the documentation below, br(n) and bi(n) refer to\n! b(1,n) and b(2,n), respectively.)\n! ncalc integer type, need not be initialized by user.\n! before using the results, the user should check that\n! ncalc=nb, i.e. all orders have been calculated to\n! the desired accuracy. see error returns below.\n!\n!\n! explanation of machine-dependent constants\n!\n! nsig decimal significance desired. should be set to\n! int(alog10(2)*nbit+1), where nbit is the number of\n! bits in the mantissa of a real variable.\n! setting nsig higher will increase cpu time without\n! increasing accuracy, while setting nsig lower will\n! decrease accuracy. if only single-precision\n! accuracy is desired, replace nbit by the number of\n! bits in the mantissa of a single-precision variable.\n! the relative truncation error is limited to t=.5*10\n! **-nsig for order greater than abs(z), and for order\n! less than abs(z) (general test), the relative error\n! is limited to t for function values of magnitude at\n! least 1, and the absolute error is limited to t for\n! smaller values.\n! nten largest integer k such that 10**k is machine-\n! representable in real.\n! largez upper limit on the magnitude of z. bear in mind\n! that if abs(z)=n, then at least n iterations of the\n! backward recursion will be executed.\n! exparg largest real argument that the library\n! exp routine can handle.\n!\n!\n! error returns\n!\n! let g denote either i or j.\n! in case of an error, ncalc.ne.nb, and not all g*s\n! are calculated to the desired accuracy.\n! if ncalc.lt.0, an argument is out of range. nb.le.0\n! or ize is neither 0 nor 1 or ize=0 and abs(y).gt.exparg,\n! or ize=1 and abs(x).gt.exparg. in this case, the vectors\n! br and bi are not calculated, and ncalc is set to\n! min0(nb,0)-1 so ncalc.ne.nb.\n! nb.gt.ncalc.gt.0 will occur if nb.gt.magz and abs(g-\n! sub-nb-of-z/g-sub-magx+np-of-z).lt.10.**(nten/2), i.e. nb\n! is much greater than magz. in this case, br(n) and bi(n)\n! are calculated to the desired accuracy for n.le.ncalc,\n! but for ncalc.lt.n.le.nb, precision is lost. if n.gt.\n! ncalc and abs(g(ncalc-1)/g(n-1)).eq.10**-k, then the last\n! k significant figures of g(n-1) (=br(n)+i*bi(n)) are\n! erroneous. if the user wishes to calculate g(n-1) to\n! higher accuracy, he should use an asymptotic formula for\n! large order.\n!\n real x ,y ,b ,pr , &\n pi ,plastr ,plasti ,poldr , &\n poldi ,psaver ,psavei ,exparg , &\n test ,tover ,tempar ,tempai , &\n tempbr ,tempbi ,tempcr ,tempci , &\n sign ,sumr ,sumi ,zinvr , &\n zinvi\n dimension b(2,nb)\n!\n! machine dependent data for 7600 and cray\n!\n! data nsig,nten,largez,exparg\n! 1 /15,293,100000,741.66e0/\n! data nsig/15/,nten/293/,largez/100000/,exparg/741.66/\n\n! MACHINE DEPENDENT DATA FOR VAX\n!\n! DATA NSIG,NTEN,LARGEZ,EXPARG\n! 1 /7,38,10000.,88.02/\n\n!\n! machine dependent data for IBM 580 workstation\n!\n! data nsig/15/,nten/308/,largez/100000/,exparg/709.78/\n data nsig/15/,nten/308/,largez/100000/,exparg/709.78/\n\n tempar = sqrt(x*x+y*y)\n magz = int((tempar))\n if (nb.gt.0 .and. magz.le.largez .and. &\n ((ize.eq.0 .and. abs(y).le.exparg) .or. &\n (ize.eq.1 .and. abs(x).le.exparg))) &\n go to 101\n!\n! error return -- z, nb, or ize is out of range\n!\n ncalc = min0(nb,0)-1\n return\n 101 sign = (float(1-2*ize))\n ncalc = nb\n!\n! use 2-term ascending series for small z\n!\n if (tempar**4 .lt. .1e0**nsig) go to 136\n!\n! initialize the calculation of the p*s\n!\n nbmz = nb-magz\n n = magz+1\n if (abs(x) .lt. abs(y)) go to 102\n zinvr = 1.e0/(x+y*y/x)\n zinvi = -y*zinvr/x\n go to 103\n 102 zinvi = -1.e0/(y+x*x/y)\n zinvr = -x*zinvi/y\n 103 plastr = 1.e0\n plasti = 0.e0\n pr = sign*(float(2*n))*zinvr\n pi = sign*(float(2*n))*zinvi\n test = 2.e0*1.e1**nsig\n m = 0\n if (nbmz .lt. 3) go to 105\n!\n! calculate p*s until n=nb-1. check for possible overflow.\n!\n! the following devious computation replaces\n! tover=10.0**(nten-nsig)\n! and is necessitated by the poor power algorithm on the ncar 7600\n! in order to prevent overflow\n!\n intemp = nten-nsig\n inhlf = intemp/2\n tover = 10.0**inhlf*10.0**(intemp-inhlf)\n nstart = magz+2\n nend = nb-1\n do 104 n=nstart,nend\n poldr = plastr\n poldi = plasti\n plastr = pr\n plasti = pi\n pr = sign*((float(2*n))*(plastr*zinvr-plasti*zinvi)-poldr)\n pi = sign*((float(2*n))*(plasti*zinvr+plastr*zinvi)-poldi)\n if ((pr/tover)**2+(pi/tover)**2-1.e0) 104,104,106\n 104 continue\n n = nend\n!\n! calculate special significance test for nbmz.gt.2.\n!\n tempbi = max(abs(pr),abs(pi))\n tempbi = tempbi*sqrt(2.e0*1.e1**nsig* &\n sqrt(((pr/tempbi)**2+(pi/tempbi)**2)* &\n ((plastr/tempbi)**2+(plasti/tempbi)**2)))\n test = max(test,tempbi)\n!\n! calculate p*s until significance test is passed.\n!\n 105 n = n+1\n poldr = plastr\n poldi = plasti\n plastr = pr\n plasti = pi\n pr = sign*((float(2*n))*(plastr*zinvr-plasti*zinvi)-poldr)\n pi = sign*((float(2*n))*(plasti*zinvr+plastr*zinvi)-poldi)\n if ((pr/test)**2+(pi/test)**2 .lt. 1.e0) go to 105\n if (m .eq. 1) go to 110\n!\n! calculate strict variant of significance test, and\n! calculate p*s until this test is passed.\n!\n m = 1\n tempbi = max(abs(pr),abs(pi))\n tempbr = sqrt(((pr/tempbi)**2+(pi/tempbi)**2)/ &\n ((plastr/tempbi)**2+(plasti/tempbi)**2))\n tempbi = (float(n+1))/tempar\n if (tempbr+1.e0/tempbr .gt. 2.e0*tempbi) &\n tempbr = tempbi+sqrt(tempbi**2-1.e0)\n test = test/sqrt(tempbr-1.e0/tempbr)\n if ((pr/test)**2+(pi/test)**2-1.e0) 105,110,110\n 106 nstart = n+1\n!\n! to avoid overflow, normalize p*s by dividing by tover.\n! calculate p*s until unnormalized p would overflow.\n!\n pr = pr/tover\n pi = pi/tover\n plastr = plastr/tover\n plasti = plasti/tover\n psaver = pr\n psavei = pi\n tempcr = plastr\n tempci = plasti\n test = 1.e1**(2*nsig)\n 107 n = n+1\n poldr = plastr\n poldi = plasti\n plastr = pr\n plasti = pi\n pr = sign*((float(2*n))*(plastr*zinvr-plasti*zinvi)-poldr)\n pi = sign*((float(2*n))*(plasti*zinvr+plastr*zinvi)-poldi)\n if (pr**2+pi**2 .le. test) go to 107\n!\n! calculate backward test, and find ncalc, the highest n\n! such that the test is passed.\n!\n tempbr = sqrt((plastr**2+plasti**2)/(poldr**2+poldi**2))\n tempbi = (float(n))/tempar\n if (tempbr+1.e0/tempbr .gt. 2.e0*tempbi) &\n tempbr = tempbi+sqrt(tempbi**2-1.e0)\n test = .5e0*(1.e0-1.e0/tempbr**2)/1.e1**nsig\n test = ((plastr**2+plasti**2)*test)*((poldr**2+poldi**2)*test)\n pr = plastr*tover\n pi = plasti*tover\n n = n-1\n nend = min0(nb,n)\n do 108 ncalc=nstart,nend\n poldr = tempcr\n poldi = tempci\n tempcr = psaver\n tempci = psavei\n psaver = sign*((float(2*n))*(tempcr*zinvr-tempci*zinvi)-poldr)\n psavei = sign*((float(2*n))*(tempci*zinvr+tempcr*zinvi)-poldi)\n if ((psaver**2+psavei**2)*(tempcr**2+tempci**2)-test) &\n 108,108,109\n 108 continue\n ncalc = nend+1\n 109 ncalc = ncalc-1\n!\n! the coefficient of b(n) in the normalization sum is\n! m*sqrt(-1)**imag, where m=-2,0, or 2, and imag is 0 or 1.\n! calculate recursion rules for m and imag, and initialize\n! them.\n!\n 110 n = n+1\n tempbr = (float(ize))*x+(float(1-ize))*y\n ipos = 0\n if (tempbr) 111,112,111\n 111 ipos = int((1.1e0*tempbr/abs(tempbr)))\n 112 mrecur = 4*((2+ize+ipos)/2)-3-2*(ize+ipos)\n k = 2+ipos+2*ize*ipos**2-ize\n l = n-4*(n/4)\n mlast = 2+8*((k*l)/4)-4*((k*l)/2)\n if (ipos.eq.0 .and. (l.eq.1 .or. l.eq.3)) mlast = 0\n l = l+3-4*((l+3)/4)\n m = 2+8*((k*l)/4)-4*((k*l)/2)\n if (ipos.eq.0 .and. (l.eq.1 .or. l.eq.3)) m = 0\n imrecr = (1-ize)*ipos**2\n imag = imrecr*(l-2*(l/2))\n!\n! initialize the backward recursion and the normalization\n! sum.\n!\n tempbr = 0.e0\n tempbi = 0.e0\n if (abs(pi) .gt. abs(pr)) go to 113\n tempar = 1.e0/(pr+pi*(pi/pr))\n tempai = -(pi*tempar)/pr\n go to 114\n 113 tempai = -1.e0/(pi+pr*(pr/pi))\n tempar = -(pr*tempai)/pi\n 114 if (imag .ne. 0) go to 115\n sumr = (float(m))*tempar\n sumi = (float(m))*tempai\n go to 116\n 115 sumr = -(float(m))*tempai\n sumi = (float(m))*tempar\n 116 nend = n-nb\n if (nend) 123,120,117\n!\n! recur backward via difference equation calculating (but\n! not storing) br(n) and bi(n) until n=nb.\n!\n 117 do 119 l=1,nend\n n = n-1\n tempcr = tempbr\n tempci = tempbi\n tempbr = tempar\n tempbi = tempai\n pr = (float(2*n))*zinvr\n pi = (float(2*n))*zinvi\n tempar = pr*tempbr-pi*tempbi-sign*tempcr\n tempai = pr*tempbi+pi*tempbr-sign*tempci\n imag = (1-imag)*imrecr\n k = mlast\n mlast = m\n m = k*mrecur\n if (imag .ne. 0) go to 118\n sumr = sumr+(float(m))*tempar\n sumi = sumi+(float(m))*tempai\n go to 119\n 118 sumr = sumr-(float(m))*tempai\n sumi = sumi+(float(m))*tempar\n 119 continue\n!\n! store br(nb), bi(nb)\n!\n 120 b(1,n) = tempar\n b(2,n) = tempai\n if (n .gt. 1) go to 121\n!\n! nb=1. since 2*tempar and 2*tempai were added to sumr and\n! sumi respectively, we must subtract tempar and tempai\n!\n sumr = sumr-tempar\n sumi = sumi-tempai\n go to 130\n!\n! calculate and store br(nb-1),bi(nb-1)\n!\n 121 n = n-1\n pr = (float(2*n))*zinvr\n pi = (float(2*n))*zinvi\n b(1,n) = pr*tempar-pi*tempai-sign*tempbr\n b(2,n) = pr*tempai+pi*tempar-sign*tempbi\n if (n .eq. 1) go to 129\n imag = (1-imag)*imrecr\n k = mlast\n mlast = m\n m = k*mrecur\n if (imag .ne. 0) go to 122\n sumr = sumr+(float(m))*b(1,n)\n sumi = sumi+(float(m))*b(2,n)\n go to 125\n 122 sumr = sumr-(float(m))*b(2,n)\n sumi = sumi+(float(m))*b(1,n)\n go to 125\n!\n! n.lt.nb, so store br(n), bi(n), and set higher orders zero\n!\n 123 b(1,n) = tempar\n b(2,n) = tempai\n nend = -nend\n do 124 l=1,nend\n b(1,n+l) = 0.e0\n b(2,n+l) = 0.e0\n 124 continue\n 125 nend = n-2\n if (nend .eq. 0) go to 128\n!\n! calculate via difference equation and store br(n),bi(n),\n! until n=2\n!\n do 127 l=1,nend\n n = n-1\n pr = (float(2*n))*zinvr\n pi = (float(2*n))*zinvi\n b(1,n) = pr*b(1,n+1)-pi*b(2,n+1)-sign*b(1,n+2)\n b(2,n) = pr*b(2,n+1)+pi*b(1,n+1)-sign*b(2,n+2)\n imag = (1-imag)*imrecr\n k = mlast\n mlast = m\n m = k*mrecur\n if (imag .ne. 0) go to 126\n sumr = sumr+(float(m))*b(1,n)\n sumi = sumi+(float(m))*b(2,n)\n go to 127\n 126 sumr = sumr-(float(m))*b(2,n)\n sumi = sumi+(float(m))*b(1,n)\n 127 continue\n!\n! calculate and store br(1), bi(1)\n!\n 128 b(1,1) = 2.e0*(b(1,2)*zinvr-b(2,2)*zinvi)-sign*b(1,3)\n b(2,1) = 2.e0*(b(1,2)*zinvi+b(2,2)*zinvr)-sign*b(2,3)\n 129 sumr = sumr+b(1,1)\n sumi = sumi+b(2,1)\n!\n! calculate normalization factor, tempar +i*tempai\n!\n 130 if (ize .eq. 1) go to 131\n tempcr = (float(ipos))*y\n tempci = (float(-ipos))*x\n go to 132\n 131 tempcr = (float(ipos))*x\n tempci = (float(ipos))*y\n 132 tempcr = exp(tempcr)\n tempbr = cos(tempci)\n tempbi = sin(tempci)\n if (abs(sumr) .lt. abs(sumi)) go to 133\n tempci = sumi/sumr\n tempcr = (tempcr/sumr)/(1.e0+tempci*tempci)\n tempar = tempcr*(tempbr+tempbi*tempci)\n tempai = tempcr*(tempbi-tempbr*tempci)\n go to 134\n 133 tempci = sumr/sumi\n tempcr = (tempcr/sumi)/(1.e0+tempci*tempci)\n tempar = tempcr*(tempbr*tempci+tempbi)\n tempai = tempcr*(tempbi*tempci-tempbr)\n!\n! normalize\n!\n 134 do 135 n=1,nb\n tempbr = b(1,n)*tempar-b(2,n)*tempai\n b(2,n) = b(1,n)*tempai+b(2,n)*tempar\n b(1,n) = tempbr\n 135 continue\n return\n!\n! two-term ascending series for small z\n!\n 136 tempar = 1.e0\n tempai = 0.e0\n tempcr = .25e0*(x*x-y*y)\n tempci = .5e0*x*y\n b(1,1) = 1.e0-sign*tempcr\n b(2,1) = -sign*tempci\n if (nb .eq. 1) go to 138\n do 137 n=2,nb\n tempbr = (tempar*x-tempai*y)/(float(2*n-2))\n tempai = (tempar*y+tempai*x)/(float(2*n-2))\n tempar = tempbr\n tempbr = (float(n))\n b(1,n) = tempar*(1.e0-sign*tempcr/tempbr)+tempai*tempci/tempbr\n b(2,n) = tempai*(1.e0-sign*tempcr/tempbr)-tempar*tempci/tempbr\n 137 continue\n 138 return\n!\n! revision history---\n!\n! october 1978 first added to nssl\n! november 1978 changed the value of the machine dependent constant\n! nten from 322 to 293 to correct an undetected\n! underflow and subsequent division of 0 by 0 when\n! besir was called with large n (greater than 140).\n!-----------------------------------------------------------------------\n end subroutine b2slci\n!\n! uliber from portlib 12/27/80\n subroutine uliber (ierr,messg)\n!\n! dimension of messg(1+(nmessg-1)/ncpwd), where ncpwd is the\n! arguments number of characters that can be stored in one\n! integer word.\n!\n! latest revision april 1977.\n!\n! purpose prints an error message.\n!\n! usage call uliber (ierr,messg,nmessg)\n!\n! arguments\n!\n! on input ierr\n! error number. if ierr .lt. 32, the error is\n! considered to be non-fatal and uliber returns\n! after printing the error message. if ierr\n! .ge. 32 the error is considered fatal, and\n! uliber stops after printing the message.\n! messg\n! the error message to be printed.\n! nmessg\n! the length of the message, in characters.\n!\n character(len=*), intent(in) :: messg\n integer, intent(in) :: ierr\n!\n! erunit should be set to the local unit number for error messages.\n!\n!\n! if (erunit .eq. 0) write(prunit,1000)\n!\n! 1000 format(50h1uliber, a subroutine to print error messages, has/\n! 1 50h been called, but no local implementation of /\n! 2 50h uliber has been provided. to properly implement /\n! 3 50h this subroutine for the local machine and /\n! 4 50h environment, please see the comments in uliber. /)\n!\n! replace the if statement and format statement above with the following\n! code where $ncpwd should be replaced with the number of characters\n! that can be stored in one integer word, and $n should be replaced by\n! the value of 1+(79/$ncpwd).\n!\n write(*,*) ierr,messg\n!\n 10 if (ierr .ge. 32) stop\n return\n end subroutine uliber\n!\n!**********************************************************************\n!\n\n subroutine besir (x, nmax, b, ier)\n\n implicit none\n\n real x, b(100)\n integer n, ier, nmax\n\n! -------------------------------------------------\n! Calculates I Bessel functions for real argument x\n! and integer orders 0 to nmax - 1 [stored in b(1)\n! to b(nmax)] using \"Numerical Recipes\" routines\n! -------------------------------------------------\n\n b(1) = bessi0(x)\n b(2) = bessi1(x)\n if(nmax .le. 2) return\n\n do n = 2, nmax - 1\n b(n+1) = bessi(n,x)\n end do\n\n return\n end subroutine besir\n\n!\n!**********************************************************************\n!\n function bessi(n,x)\n\n implicit none\n\n integer n, iacc\n real bessi, x, bigno, bigni\n parameter (iacc = 40, bigno = 1.0e10, bigni = 1.0e-10)\n! Uses bessi0\n! Returns the modified Bessel function In(x) for any real x and n.ge.2\n integer j, m\n real bi, bim, bip, tox\n if (n .lt. 2) then\n write(*,*) 'bad argument n in bessi'\n stop\n endif\n if (x .eq. 0.) then\n bessi = 0.\n else\n tox = 2.0/abs(x)\n bip = 0.0\n bi = 1.0\n bessi = 0.\n m = 2 * ((n + int(sqrt(float(iacc * n)))))\n do j = m, 1, -1\n bim = bip + float(j) * tox * bi\n bip = bi\n bi = bim\n if (abs(bi) .gt. bigno) then\n bessi = bessi * bigni\n bi = bi * bigni\n bip = bip * bigni\n endif\n if (j .eq. n) bessi = bip\n enddo\n bessi = bessi * bessi0(x) / bi\n if(x .lt. 0. .and. mod(n,2) .eq. 1) bessi = -bessi\n endif\n return\n end function bessi\n!\n!**********************************************************************\n!\n function bessi0(x)\n\n implicit none\n\n real bessi0, x\n! Returns the modified Bessel function I0(x) for any real x\n real ax\n double precision p1, p2, p3, p4, p5, p6, p7, &\n q1, q2, q3, q4, q5, q6, q7, q8, q9, y\n save p1, p2, p3, p4, p5, p6, p7, &\n q1, q2, q3, q4, q5, q6, q7, q8, q9\n\n data p1, p2, p3, p4, p5, p6, p7 / 1.0d0, 3.5156229d0, 3.0899424d0, &\n 1.2067492d0, 0.2659732d0, 0.360768d-1, 0.45813d-2 /\n\n data q1, q2, q3, q4, q5, q6, q7, q8, q9/0.39894228d0,0.1328592d-1, &\n 0.225319d-2,-0.157565d-2, 0.916281d-2, -0.2057706d-1, &\n 0.2635537d-1, -0.1647633d-1, 0.392377d-2 /\n\n if (abs(x) .lt. 3.75) then\n y = (x / 3.75)**2\n bessi0 = p1 + y * (p2+y*(p3+y*(p4+y*(p5+y*(p6+y*p7)))))\n else\n ax = abs(x)\n y = 3.75 / ax\n bessi0 = (exp(ax) / sqrt(ax)) * (q1+y*(q2+y*(q3+y*(q4 &\n +y*(q5+y*(q6+y*(q7+y*(q8+y*q9))))))))\n endif\n return\n end function bessi0\n!\n!**********************************************************************\n!\n function bessi1(x)\n\n implicit none\n\n real bessi1, x\n! Returns the modified Bessel function I1(x) for any real x\n real ax\n double precision p1, p2, p3, p4, p5, p6, p7, &\n q1, q2, q3, q4, q5, q6, q7, q8, q9, y\n save p1, p2, p3, p4, p5, p6, p7, &\n q1, q2, q3, q4, q5, q6, q7, q8, q9\n\n data p1, p2, p3, p4, p5, p6, p7 / 0.5d0,0.87890594d0,0.51498869d0, &\n 0.15084934d0, 0.2658733d-1, 0.301532d-2, 0.32411d-3 /\n\n data q1, q2, q3, q4, q5, q6, q7, q8, q9/0.39894228d0,-0.398802d-1, &\n -0.362018d-2,0.163801d-2,-0.1031555d-1, 0.2282967d-1, &\n -0.2895312d-1, 0.1787654d-1, -0.420059d-2 /\n\n if (abs(x) .lt. 3.75) then\n y = (x / 3.75)**2\n bessi1 = x * (p1+y*(p2+y*(p3+y*(p4+y*(p5+y*(p6+y*p7))))))\n else\n ax = abs(x)\n y = 3.75 / ax\n bessi1 = (exp(ax) / sqrt(ax)) * (q1+y*(q2+y*(q3+y*(q4 &\n +y*(q5+y*(q6+y*(q7+y*(q8+y*q9))))))))\n endif\n return\n end function bessi1\n\n!\n!**********************************************************************\n!\n function factrl(n)\n integer n\n real factrl\n!------------------------------------------------------\n! uses gammln\n! returns the value of n! as a floating point number\n!-------------------------------------------------------\n\n integer j, ntop\n real a(33)\n save ntop, a\n data ntop, a(1)/0, 1./\n if(n .lt. 0) then\n write(*,*) 'negative factorial in factrl'\n stop\n else if (n .le. ntop)then\n factrl = a(n+1)\n else if (n .le. 32) then\n do j = ntop+1, n\n a(j+1) = j * a(j)\n end do\n ntop = n\n factrl = a(n+1)\n else\n factrl = exp(gammln(n+1.))\n end if\n\n return\n end function factrl\n\n!\n!*****************************************************************\n!\n function gammln(xx)\n real gammln, xx\n! Returns the value ln(gamma(xx)) for xx > 0.\n integer j\n double precision ser, stp, tmp, x, y, cof(6)\n! internal arithmetic will be done in double precision,\n! a nicety that you can omit if five figure accuracy is good enough\n save cof, stp\n data cof, stp/76.18009172947146d0,-86.50532032941677d0, &\n 24.01409824083091d0,-1.231739572450155d0,.1208650973866179d-2, &\n -.5395239384953d-5,2.5066282746310005d0/\n x = xx\n y = x\n tmp = x + 5.5d0\n tmp = (x + 0.5d0) * log(tmp) - tmp\n ser=1.000000000190015d0\n do j = 1, 6\n y = y + 1.d0\n ser = ser + cof(j) / y\n end do\n gammln = tmp + log(stp * ser / x)\n return\n end function gammln\n\n\n\n subroutine besIExp &\n ( gamma_, lMax, expBes, expBesPrime, expBesOverGam )\n\n use constants\n\n ! Calculates exp(-gamma) times the modified bessel functions\n ! (and derivatives) of order up to lMax\n ! ----------------------------------------------------------\n\n implicit none\n\n integer, intent(in) :: lMax\n integer :: nmax, ier, l\n complex, intent(in) :: gamma_\n complex, intent(out) :: expBes(:), expBesPrime(:), expBesovergam(:)\n\n complex(kind=dbl), allocatable, dimension(:) :: besselI, besselIPrime, b\n complex(kind=dbl) :: expGam\n integer :: status\n complex(kind=dbl) :: gamma_dbl\n\n gamma_dbl = gamma_\n !LAB added to lenght of arrays 1 and 3 to allow for lmax = 0\n allocate ( besselI(0:lMax+1), besselIPrime(0:lMax), b(lMax+2), stat = status )\n\n b = 0\n besselI = 0\n besselIPrime = 0\n\n expGam = exp(-gamma_dbl)\n\n if ( cabs ( gamma_ ) <= 700.) then\n\n nmax = lmax\n call besic ( gamma_dbl, nmax, b, ier)\n\n if (ier/=0) then\n write(*,*) 'bessel.f90: ERROR - ', ier\n endif\n\n do l = 0, lMax + 1 ! LAB -- need to fix lMax = 0\n besselI(l) = b(l+1)\n enddo\n\n do l = 0, lmax\n\n if(l == 0) besselIPrime(0) = besselI(1)\n if(l /= 0) besselIPrime(l) = besselI(l-1) - l / gamma_dbl * besselI(l)\n expBes(l+1) = expGam * besselI(l)\n expBesPrime(l+1) = expGam * besselIPrime(l)\n\n enddo\n\n else\n\n do l = 0, lmax\n call bes_asym ( gamma_, l, expBes(l+1), expBesPrime(l+1) )\n enddo\n\n endif\n\n do l = 0, lmax\n expBesOverGam(l+1) = expBes(l+1) / gamma_\n enddo\n\n deallocate ( b )\n deallocate ( besselI )\n deallocate ( besselIPrime )\n\n end subroutine besIExp\n\n\n!\n!***************************************************************************\n!\n\n\n subroutine bes_expand &\n ( gamma_, lMax, expBes, expBesPrime, expBesOverGam)\n\n ! Calculates exp(-gamma) times the modified bessel functions\n ! (and derivatives) of order up to lmax using second order\n ! expansion for small argument\n ! -----------------------------------------------------------\n\n implicit none\n\n integer, intent(in) :: lMax\n complex, intent(in) :: gamma_\n complex, intent(inout) :: &\n expBes(0:lMax), &\n expBesPrime(0:lMax), &\n expBesOverGam(0:lMax) \n\n integer :: l\n real :: factl\n complex :: IlOverGam, exGam\n complex :: Il, IlPrime\n\n exGam = 1d0 - gamma_ + gamma_**2 / 2d0\n\n do l = 0, lmax\n\n factl = factrl(l)\n Il = gamma_**l / (2**l * factl) * &\n ( 1d0 + gamma_**2 / (4d0 * (l+1)))\n IlPrime = gamma_**(l-1) / (2**l * factl) * &\n (l + (l+2) * gamma_**2 / (4d0 * (l+1)))\n\n IlOverGam = gamma_**(l-1) / (2**l * factl) * &\n ( 1d0 + gamma_**2 / (4d0 * (l+1)))\n\n expbes(l) = exGam * Il\n expBesPrime(l) = exGam * IlPrime\n expBesOverGam(l) = exGam * IlOverGam\n\n enddo\n\n return\n\n end subroutine bes_expand\n\n\n!\n!***************************************************************************\n!\n\n subroutine bes_asym ( z, n, exil, exilp )\n\n use constants\n\n implicit none\n\n integer :: mu, n\n complex z, exil, exilp\n\n mu = 4 * n**2\n exil = 1d0 / sqrt(2d0 * pi * z) &\n * (1d0 &\n - (mu - 1)/(8d0 * z) &\n + (mu - 1) * (mu - 9) / (2d0 * (8d0 * z)**2) &\n - (mu - 1) * (mu - 9) * (mu - 25) / (6d0 * (8d0 * z)**3) )\n exilp = 1d0 / sqrt(2.0 * pi * z) &\n * (1d0 &\n - (mu + 3)/(8d0 * z) &\n + (mu - 1) * (mu + 15) / (2d0 * (8d0 * z)**2) &\n - (mu - 1) * (mu - 9) * (mu + 35) / (6d0 * (8d0 * z)**3) )\n\n return\n\n end subroutine bes_asym\n\n!\n!***************************************************************************\n!\n\n\n function fzeta (arg)\n complex a1, a2, a3, b1, b2, b3, c1, c2, c3, d1, d2, d3, arg, aux0 &\n , aux1, term, z, zz, fzeta\n data d1r/0.0/\n data d1i/1.77245385090551/\n data d2r/0.0/\n data d2i/3.54490770181103/\n data d3r/0.0/\n data d3i/7.08981540362206/\n data d4/0.33333333333333/\n data eps/1.0E-07/\n\n! data d4/0.33333333333333/\n\n!ray code analysis\n!ray optimize\n!\n i = 0\n z = arg\n zz = z*z\n x = real(z)\n y = aimag(z)\n d1 = cmplx(d1r,d1i)\n d2 = cmplx(d2r,d2i)\n d3 = cmplx(d3r,d3i)\n ymag = abs(y)\n if (ymag - 1.0 .ge. 0.) then\n!\n! continued fraction method: abs(y).ge.1.0\n!\n y0 = y\n y = ymag\n aux1 = 1.5 - z*z\n aux2 = 0.0\n del = 1.5\n a1 = 0.0\n a2 = -1.0\n b1 = 1.0\n b2 = aux1\n c1 = a2/b2\n!\n 100 continue\n aux1 = aux1 + 2.0\n aux2 = aux2 - del\n del = del + 2.0\n a3 = aux1*a2 + aux2*a1\n b3 = aux1*b2 + aux2*b1\n c2 = a3/b3\n c3 = c2 - c1\n c3r = real(c3)\n c3i = aimag(c3)\n if (abs(c3r) + abs(c3i) .lt. eps) go to 110\n a1 = a2\n a2 = a3\n b1 = b2\n b2 = b3\n c1 = c2\n go to 100\n 110 continue\n if (y0 .lt. 0.) then\n y = y0\n c2 = conjg(c2) - d3*z*exp(-zz)\n endif\n aux0 = -(0.5*c2 + 1.0)/z\n else\n!\n! asymptotic series method: abs(x).ge.4.0 and abs(y).lt.1.0\n!\n xmag = abs(x)\n if (xmag - 4.0 .lt. 0.) go to 130\n term = 1.0/z\n aux0 = -term\n aux1 = 0.5*term**2\n p = 1.0\n if (y .le. 0.) then\n if (y .ne. 0.) then\n aux0 = aux0 + d2*exp(-zz)\n else\n aux0 = aux0 + d1*exp(-zz)\n endif\n endif\n 120 continue\n term = aux1*term*p\n aux0 = aux0 - term\n p = p + 2.0\n termr = real(term)\n termi = aimag(term)\n! if(abs(termr)+abs(termi).lt.eps)30,18\n if (abs(termr) + abs(termi) .lt. eps) go to 160\n go to 120\n!\n! power series method: abs(x).lt.4.0 and abs(y).lt.1.0\n!\n 130 continue\n aux0 = 1.0\n aux1 = -(zz + zz)\n aux2 = eps/(eps + xmag + ymag)\n term = d4*aux1\n p = 3.0\n 140 continue\n aux0 = aux0 + term\n termr = real(term)\n termi = aimag(term)\n! if(abs(termr)+abs(termi).lt.aux2)26,24\n if (abs(termr) + abs(termi) .lt. aux2) go to 150\n p = p + 2.0\n term = aux1*term/p\n go to 140\n 150 continue\n aux0 = d1*exp(-zz) - 2.0*z*aux0\n endif\n 160 continue\n fzeta = aux0\n if (i .le. 0) return\n fzeta = -2.0*(1.0 + arg*aux0)\n return\n end function fzeta\n!\n!***********************************************************************\n!\nend module bessel_mod\n\n\n", "meta": {"hexsha": "5bdb2d16647f3ff3bc3976aac9ec5fa840aea9c3", "size": 35066, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/bessel.f90", "max_stars_repo_name": "efdazedo/aorsa2d", "max_stars_repo_head_hexsha": "ce0b8c930715277eeb4d23e60cc88434ffdaa583", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-02-13T21:57:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-10T16:47:51.000Z", "max_issues_repo_path": "src/bessel.f90", "max_issues_repo_name": "efdazedo/aorsa2d", "max_issues_repo_head_hexsha": "ce0b8c930715277eeb4d23e60cc88434ffdaa583", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-02-23T20:33:30.000Z", "max_issues_repo_issues_event_max_datetime": "2018-02-23T20:34:31.000Z", "max_forks_repo_path": "src/bessel.f90", "max_forks_repo_name": "efdazedo/aorsa2d", "max_forks_repo_head_hexsha": "ce0b8c930715277eeb4d23e60cc88434ffdaa583", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-02-15T16:50:58.000Z", "max_forks_repo_forks_event_max_datetime": "2018-06-23T14:07:59.000Z", "avg_line_length": 30.6520979021, "max_line_length": 86, "alphanum_fraction": 0.5001996236, "num_tokens": 11574, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637648915616, "lm_q2_score": 0.7826624688140726, "lm_q1q2_score": 0.6728265645800301}} {"text": " Program dbdsvdx_example\n\n! DBDSVDX Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_interfaces, Only: dbdsvdx\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nin = 5, nout = 6\n! .. Local Scalars ..\n Real (Kind=dp) :: vl, vu\n Integer :: il, info, iu, ldz, n, ns\n Character (1) :: range\n! .. Local Arrays ..\n Real (Kind=dp), Allocatable :: d(:), e(:), s(:), work(:), z(:, :)\n Integer, Allocatable :: iwork(:)\n! .. Executable Statements ..\n Write (nout, *) 'DBDSVDX Example Program Results'\n Write (nout, *)\n Flush (nout)\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n\n ldz = 2*n\n Allocate (d(n), e(n-1), s(n), z(ldz,n+1), work(14*n), iwork(12*n))\n\n! Read the bidiagonal matrix B from data file, first\n! the diagonal elements, and then the off diagonal elements\n\n Read (nin, *) d(1:n)\n Read (nin, *) e(1:n-1)\n\n! Read range for selected singular values\n Read (nin, *) range\n\n If (range=='I' .Or. range=='i') Then\n Read (nin, *) il, iu\n Else If (range=='V' .Or. range=='v') Then\n Read (nin, *) vl, vu\n End If\n\n! Calculate the singular values and singular vectors of B.\n\n Call dbdsvdx('Upper', 'V', range, n, d, e, vl, vu, il, iu, ns, s, z, &\n ldz, work, iwork, info)\n\n If (info==0) Then\n! Print the singular values of B.\n\n If (range=='I' .Or. range=='i') Then\n Write (nout, 100) ns, il, iu\n Else If (range=='V' .Or. range=='v') Then\n Write (nout, 110) ns, vl, vu\n End If\n Write (nout, 120) s(1:ns)\n Else\n Write (nout, 130) '** DBDSVDX failed with INFO = ', info\n End If\n\n100 Format (1X, I2, 1X, 'singular values of B in the index range [', I2, &\n ',', I2, ']:')\n110 Format (1X, I2, 1X, 'singular values of B in the range [', F7.3, ',', &\n F7.3, ']:')\n120 Format (1X, 4(3X,F11.4))\n130 Format (1X, A, I10)\n End Program\n", "meta": {"hexsha": "6d68743908787af325bceba38bb255b973669f05", "size": 2271, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/dbdsvdx_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/dbdsvdx_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/dbdsvdx_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 31.1095890411, "max_line_length": 90, "alphanum_fraction": 0.5468956407, "num_tokens": 735, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099167, "lm_q2_score": 0.7826624789529376, "lm_q1q2_score": 0.6728265620400711}} {"text": "program test4\n#if (_DP==0)\n use iso_fortran_env,only:int32,int64,wp=>real32\n#else\n use iso_fortran_env,only:int32,int64,wp=>real64\n#endif\n use modsparse\n implicit none\n integer(kind=int32)::nrow\n integer(kind=int32)::row\n integer(kind=int32)::col\n integer(kind=int32)::iunit, istat\n real(kind=wp)::val\n logical::lup=.false.\n type(coosparse)::coo,subcoo\n\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \n !COO FULL\n open(newunit=iunit,file='crsinput.ascii',status='old',action='read')\n read(iunit,*) nrow\n\n coo=coosparse(nrow,nel=4_int64,lupper=.false.)\n\n do\n read(iunit,*,iostat=istat) row,col,val\n if(istat.ne.0)exit\n call coo%add(row,col,val)\n end do\n close(iunit)\n\n\n print*,'FULL => FULL xxxxxxxxxxxxxxxxxxxxxxxxxx'\n call coo%printsquare()\n print*,'SELECT UPPER BLOCK xxxxxxxxxxxxxxxxxxxxxxxxxx'\n print*,'aaaa 1 2 3 4'\n subcoo=coo%submatrix(1,2,3,4)\n call subcoo%printstats()\n call subcoo%printsquare()\n\n print*,'SELECT LOWER BLOCK xxxxxxxxxxxxxxxxxxxxxxxxxx'\n print*,'aaaa 3 4 1 2'\n subcoo=coo%submatrix(3,4,1,2)\n call subcoo%printstats()\n call subcoo%printsquare()\n\n print*,'SELECT BLOCK + DIAG xxxxxxxxxxxxxxxxxxxxxxxxxx'\n print*,'aaaa 1 2 1 3'\n subcoo=coo%submatrix(1,2,1,3)\n call subcoo%printstats()\n call subcoo%printsquare()\n\n print*,''\n print*,'FULL => UPPER xxxxxxxxxxxxxxxxxxxxxxxxxx'\n call coo%printsquare()\n print*,'SELECT UPPER BLOCK xxxxxxxxxxxxxxxxxxxxxxxxxx'\n print*,'aaaa 1 2 3 4'\n subcoo=coo%submatrix(1,2,3,4,.true.)\n call subcoo%printstats()\n call subcoo%printsquare()\n\n print*,'SELECT LOWER BLOCK a xxxxxxxxxxxxxxxxxxxxxxxxxx'\n print*,'aaaa 3 4 1 2'\n subcoo=coo%submatrix(3,4,1,2,.true.)\n call subcoo%printstats()\n call subcoo%printsquare()\n\n print*,'SELECT BLOCK + DIAG xxxxxxxxxxxxxxxxxxxxxxxxxx'\n print*,'aaaa 1 2 1 3'\n subcoo=coo%submatrix(1,2,1,3,.true.)\n call subcoo%printstats()\n call subcoo%printsquare()\n\n\n\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \n !COO UPPER\n open(newunit=iunit,file='crsinput.ascii',status='old',action='read')\n read(iunit,*) nrow\n\n coo=coosparse(nrow,nel=4_int64,lupper=.true.)\n\n do\n read(iunit,*,iostat=istat) row,col,val\n if(istat.ne.0)exit\n call coo%add(row,col,val)\n end do\n close(iunit)\n\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \n !COO UPPER\n print*,'***COO UPPER'\n call coo%printstats()\n call coo%print(lint=.true.)\n\n print*,'UPPER => FULL xxxxxxxxxxxxxxxxxxxxxxxxxx'\n call coo%printsquare()\n print*,'SELECT UPPER BLOCK xxxxxxxxxxxxxxxxxxxxxxxxxx'\n print*,'aaaa 1 2 3 4'\n subcoo=coo%submatrix(1,2,3,4)\n call subcoo%printstats()\n call subcoo%printsquare()\n\n print*,'SELECT LOWER BLOCK xxxxxxxxxxxxxxxxxxxxxxxxxx'\n print*,'aaaa 3 4 1 2'\n subcoo=coo%submatrix(3,4,1,2)\n call subcoo%printstats()\n call subcoo%printsquare()\n\n print*,'SELECT BLOCK + DIAG xxxxxxxxxxxxxxxxxxxxxxxxxx'\n print*,'aaaa 1 2 1 3'\n subcoo=coo%submatrix(1,2,1,3)\n call subcoo%printstats()\n call subcoo%printsquare()\n \n print*,''\n print*,'UPPER => UPPER xxxxxxxxxxxxxxxxxxxxxxxxxx'\n call coo%printsquare()\n print*,'SELECT UPPER BLOCK xxxxxxxxxxxxxxxxxxxxxxxxxx'\n print*,'aaaa 1 2 3 4'\n subcoo=coo%submatrix(1,2,3,4,.true.)\n call subcoo%printstats()\n call subcoo%printsquare()\n\n print*,'SELECT LOWER BLOCK xxxxxxxxxxxxxxxxxxxxxxxxxx'\n print*,'aaaa 3 4 1 2'\n subcoo=coo%submatrix(3,4,1,2,.true.)\n call subcoo%printstats()\n call subcoo%printsquare()\n\n print*,'SELECT BLOCK + DIAG xxxxxxxxxxxxxxxxxxxxxxxxxx'\n print*,'aaaa 1 2 1 3'\n subcoo=coo%submatrix(1,2,1,3,.true.)\n call subcoo%printstats()\n call subcoo%printsquare()\n\n\n\nend program\n", "meta": {"hexsha": "0891f6eebaad02b48ca3b491a14bbd908931845c", "size": 3566, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/test4.f90", "max_stars_repo_name": "jvdp1/libsparse", "max_stars_repo_head_hexsha": "eaf5ec8e45bce873154aff24c2143b8f00df63a8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2019-08-03T14:17:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-14T04:31:16.000Z", "max_issues_repo_path": "examples/test4.f90", "max_issues_repo_name": "jvdp1/libsparse", "max_issues_repo_head_hexsha": "eaf5ec8e45bce873154aff24c2143b8f00df63a8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-09-06T21:38:44.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-08T16:02:40.000Z", "max_forks_repo_path": "examples/test4.f90", "max_forks_repo_name": "jvdp1/libsparse", "max_forks_repo_head_hexsha": "eaf5ec8e45bce873154aff24c2143b8f00df63a8", "max_forks_repo_licenses": ["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.654676259, "max_line_length": 76, "alphanum_fraction": 0.6864834549, "num_tokens": 1196, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190938, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6728265607700908}} {"text": " Program zpoequ_example\n\n! ZPOEQU Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use blas_interfaces, Only: zdscal\n Use lapack_example_aux, Only: nagf_blas_zddscl, &\n nagf_file_print_matrix_complex_gen_comp\n Use lapack_interfaces, Only: zpoequ\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Real (Kind=dp), Parameter :: one = 1.0_dp\n Real (Kind=dp), Parameter :: thresh = 0.1_dp\n Integer, Parameter :: nin = 5, nout = 6\n! .. Local Scalars ..\n Real (Kind=dp) :: amax, big, scond, small\n Integer :: i, ifail, info, j, lda, n\n! .. Local Arrays ..\n Complex (Kind=dp), Allocatable :: a(:, :)\n Real (Kind=dp), Allocatable :: s(:)\n Character (1) :: clabs(1), rlabs(1)\n! .. Intrinsic Procedures ..\n Intrinsic :: epsilon, radix, real, tiny\n! .. Executable Statements ..\n Write (nout, *) 'ZPOEQU Example Program Results'\n Write (nout, *)\n Flush (nout)\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n\n lda = n\n Allocate (a(lda,n), s(n))\n\n! Read the upper triangular part of the matrix A from data file\n\n Read (nin, *)(a(i,i:n), i=1, n)\n\n! Print the matrix A\n\n! ifail: behaviour on error exit\n! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft\n ifail = 0\n Call nagf_file_print_matrix_complex_gen_comp('Upper', 'Non-unit', n, n, &\n a, lda, 'Bracketed', '1P,E10.2', 'Matrix A', 'Integer', rlabs, &\n 'Integer', clabs, 80, 0, ifail)\n\n Write (nout, *)\n\n! Compute diagonal scaling factors\n\n Call zpoequ(n, a, lda, s, scond, amax, info)\n\n If (info>0) Then\n Write (nout, 100) 'Diagonal element', info, ' of A is non positive'\n Else\n\n! Print SCOND, AMAX and the scale factors\n\n Write (nout, 110) 'SCOND =', scond, ', AMAX =', amax\n Write (nout, *)\n Write (nout, *) 'Diagonal scaling factors'\n Write (nout, 120) s(1:n)\n Write (nout, *)\n Flush (nout)\n\n! Compute values close to underflow and overflow\n\n small = tiny(1.0E0_dp)/(epsilon(1.0E0_dp)*real(radix(1.0E0_dp),kind=dp &\n ))\n big = one/small\n If ((scondbig)) Then\n\n! Scale A\n Do j = 1, n\n Call zdscal(j, s(j), a(1,j), 1)\n Call nagf_blas_zddscl(j, s, 1, a(1,j), 1)\n End Do\n\n! Print the scaled matrix\n\n ifail = 0\n Call nagf_file_print_matrix_complex_gen_comp('Upper', 'Non-unit', n, &\n n, a, lda, 'Bracketed', 'F8.4', 'Scaled matrix', 'Integer', rlabs, &\n 'Integer', clabs, 80, 0, ifail)\n\n End If\n End If\n\n100 Format (1X, A, I4, A)\n110 Format (1X, 2(A,1P,E8.1))\n120 Format ((1X,1P,7E11.1))\n End Program\n", "meta": {"hexsha": "f543a53af92364f556abb45aae9a9df1d6aeebec", "size": 3055, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/zpoequ_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/zpoequ_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/zpoequ_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 30.8585858586, "max_line_length": 90, "alphanum_fraction": 0.567594108, "num_tokens": 960, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099167, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.6728265576820638}} {"text": "! 7.32g \u0432 \u0443\u0447\u0435\u0431\u043d\u0438\u043a\u0435\n! \u0423\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0438\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432 \u0421\u0422\u0420\u041e\u041a\u0410\u0425 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u043f\u043e \u043c\u043e\u0434\u0443\u043b\u044e \u043f\u043e \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044e\n\nprogram ex_7_32g\n implicit none\n\n integer, allocatable :: B(:,:), AbsLine(:), Order(:)\n integer :: In, Out, x, y, i, j\n\n character(*), parameter :: output_file = \"output.txt\", &\n input_file = \"../data/input.txt\"\n\n open (file=input_file, newunit=In)\n read(In, *) x, y\n allocate(B(x,y), Order(x))\n read(In, *) (B(:,i), i = 1, y)\n close (In)\n\n do concurrent (j = 1:y)\n AbsLine = abs(B(:,j))\n Order = [(i,i = 1, x)]\n do i = 1, x\n Order(i:) = cshift(Order(i:), minloc(AbsLine(i:), 1) - 1)\n AbsLine = cshift(AbsLine, minloc(AbsLine(i:), 1) - 1)\n enddo\n B(:,j) = B(order,j)\n end do\n\n open (file=output_file, newunit=Out)\n write(Out, *) (B(:,j), j = 1, y)\n close (Out)\n\nend program ex_7_32g", "meta": {"hexsha": "c21340ea9538283248c77be64cd68a033edd505c", "size": 932, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ex_7_32g/src/ex_7_32g.f90", "max_stars_repo_name": "taxnuke/algorithm-exercises", "max_stars_repo_head_hexsha": "5dae749093489d0e66a74bd8bc3b2040496449bf", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-06-01T06:06:44.000Z", "max_stars_repo_stars_event_max_datetime": "2017-06-01T09:16:17.000Z", "max_issues_repo_path": "ex_7_32g/src/ex_7_32g.f90", "max_issues_repo_name": "taxnuke/algorithm-exercises", "max_issues_repo_head_hexsha": "5dae749093489d0e66a74bd8bc3b2040496449bf", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ex_7_32g/src/ex_7_32g.f90", "max_forks_repo_name": "taxnuke/algorithm-exercises", "max_forks_repo_head_hexsha": "5dae749093489d0e66a74bd8bc3b2040496449bf", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.2424242424, "max_line_length": 69, "alphanum_fraction": 0.5042918455, "num_tokens": 317, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.853912760387131, "lm_q2_score": 0.7879311956428946, "lm_q1q2_score": 0.6728245022665568}} {"text": "! { dg-do compile }\n! { dg-options \"-floop-nest-optimize -O2 -ffast-math\" }\n! PR53852 : compile time / memory hog\nSUBROUTINE build_d_tensor_gks(d5f,v,d5)\n INTEGER, PARAMETER :: dp=8\n REAL(KIND=dp), DIMENSION(3, 3, 3, 3, 3), &\n INTENT(OUT) :: d5f\n REAL(KIND=dp), DIMENSION(3), INTENT(IN) :: v\n REAL(KIND=dp), INTENT(IN) :: d5\n INTEGER :: k1, k2, k3, k4, k5\n REAL(KIND=dp) :: w\n\n d5f = 0.0_dp\n DO k1=1,3\n DO k2=1,3\n DO k3=1,3\n DO k4=1,3\n DO k5=1,3\n d5f(k5,k4,k3,k2,k1)=d5f(k5,k4,k3,k2,k1)+ &\n v(k1)*v(k2)*v(k3)*v(k4)*v(k5)*d5\n ENDDO\n w=v(k1)*v(k2)*v(k3)*d4\n d5f(k1,k2,k3,k4,k4)=d5f(k1,k2,k3,k4,k4)+w\n d5f(k1,k2,k4,k3,k4)=d5f(k1,k2,k4,k3,k4)+w\n d5f(k1,k4,k2,k3,k4)=d5f(k1,k4,k2,k3,k4)+w\n d5f(k4,k1,k2,k3,k4)=d5f(k4,k1,k2,k3,k4)+w\n d5f(k1,k2,k4,k4,k3)=d5f(k1,k2,k4,k4,k3)+w\n d5f(k1,k4,k2,k4,k3)=d5f(k1,k4,k2,k4,k3)+w\n d5f(k4,k1,k2,k4,k3)=d5f(k4,k1,k2,k4,k3)+w\n d5f(k1,k4,k4,k2,k3)=d5f(k1,k4,k4,k2,k3)+w\n d5f(k4,k1,k4,k2,k3)=d5f(k4,k1,k4,k2,k3)+w\n d5f(k4,k4,k1,k2,k3)=d5f(k4,k4,k1,k2,k3)+w\n ENDDO\n ENDDO\n ENDDO\n ENDDO\nEND SUBROUTINE build_d_tensor_gks\n", "meta": {"hexsha": "f1f1fc5c79082913e454334f2327a03a3bc51113", "size": 1380, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/graphite/PR53852.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/graphite/PR53852.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/graphite/PR53852.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": 36.3157894737, "max_line_length": 61, "alphanum_fraction": 0.4782608696, "num_tokens": 637, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127455162773, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.672824494801694}} {"text": "module euler_multiprecision_util_m\n\n implicit none\n private\n public :: add, sub, compare, mul, pow2\n\ncontains\n\n !> The core function to cut leading zeros of a contiguous array.\n !>\n !> As the name of the function suggests, the function\n !> deletes all the leading zeros of a contiguous array.\n !> This procedure uses the intrinsic function `findloc`\n !> that is only available with gfortran > 9.0.0\n pure function cut_leading_zeros(arr) result(ret)\n integer, contiguous, intent(in) :: arr(:)\n integer, allocatable :: ret(:)\n\n ret = arr(findloc(arr == 0, value=.false., dim=1):)\n end function cut_leading_zeros\n\n !> The core function to carry digits during add and multiplication.\n !>\n !> Each element of the input array is an 32bit integer greater than or\n !> equal to zero and less than or equal to nine.\n pure function carry(arr) result(ret)\n integer, contiguous, intent(in) :: arr(:)\n integer, dimension(size(arr) + 2) :: tmp1, tmp2, ret\n\n tmp1 = 0; tmp2 = 0; ret(1:2) = 0; ret(3:) = arr(:)\n do\n if (all(ret <= 9)) exit\n tmp1(:) = ret(:) - ret(:)/10*10\n tmp2(1:size(tmp2) - 1) = ret(2:)/10\n ret(:) = tmp1(:) + tmp2(:)\n end do\n end function carry\n\n !> The core function to provide the ability of addition.\n !>\n !> Each element of the input array is an 32bit integer greater than or\n !> equal to zero and less than or equal to nine. When two such arrays\n !> are \"added\", first of all, the shorter array will be extended to the\n !> length of the longer array and two arrays with the same dimension\n !> are added. Then the function `carry`\n !> \"[carries](https://en.wikipedia.org/wiki/Carry_(arithmetic))\" the\n !> added array iteratively until all elements of the array are greater\n !> than or equal to zero and less than or equal to nine. Finally, the\n !> leading zeros are deleted by `cut_leading_zeros`.\n pure function add(arr1, arr2) result(ret)\n integer, contiguous, intent(in) :: arr1(:), arr2(:)\n integer, allocatable, dimension(:) :: ret, tmp1, tmp2\n\n associate (x => max(size(arr1), size(arr2)) + 1)\n allocate (tmp1(x), tmp2(x))\n tmp1 = 0; tmp1(x - size(arr1) + 1:x) = arr1(:)\n tmp2 = 0; tmp2(x - size(arr2) + 1:x) = arr2(:)\n end associate\n ret = cut_leading_zeros(carry(tmp1 + tmp2))\n end function add\n\n !> The core function to provide the ability of subtraction.\n !>\n !> Each element of the input array is an 32bit integer greater than or\n !> equal to zero and less than or equal to nine.\n pure function sub(arr1, arr2) result(ret)\n integer, contiguous, intent(in) :: arr1(:), arr2(:)\n integer, allocatable, dimension(:) :: ret, tmp1, tmp2, tmp\n integer :: i\n\n associate (x => max(size(arr1), size(arr2)) + 1)\n allocate (tmp1(x), tmp2(x), tmp(x))\n tmp1 = 0; tmp2 = 0; tmp = 0\n tmp1(x - size(arr1) + 1:x) = arr1(:)\n tmp2(x - size(arr2) + 1:x) = arr2(:)\n end associate\n\n do i = size(tmp1), 2, -1\n if (tmp1(i) >= tmp2(i)) then\n tmp(i) = tmp1(i) - tmp2(i)\n else\n tmp(i) = tmp1(i) - tmp2(i) + 10\n tmp1(i - 1) = tmp1(i - 1) - 1\n end if\n end do\n ret = cut_leading_zeros(tmp)\n end function sub\n\n !> The core function to provide the ability of comparison.\n !>\n !>### Result\n !> | return value | result |\n !> |:------------:|:------:|\n !> |`ret = 1` |arr1 > arr2|\n !> |`ret = 0` |arr1 = arr2|\n !> |`ret = -1` |arr1 < arr2|\n pure function compare(arr1, arr2) result(ret)\n integer, contiguous, intent(in) :: arr1(:), arr2(:)\n integer :: ret, i\n\n if (size(arr1) > size(arr2)) then\n ret = 1; return\n else if (size(arr1) < size(arr2)) then\n ret = -1; return\n end if\n\n do i = size(arr1), 1, -1\n if (arr1(i) > arr2(i)) then\n ret = 1; return\n else if (arr1(i) < arr2(i)) then\n ret = -1; return\n else\n ret = 0\n end if\n end do\n if (ret /= 0) error stop 'compare: invalid output.'\n end function compare\n\n !> The core function to provide the ability of multiplication.\n !>\n !> Each element of the input array is an 32bit integer greater than or\n !> equal to zero and less than or equal to nine.\n pure function mul(arr1, arr2) result(ret)\n integer, contiguous, intent(in) :: arr1(:), arr2(:)\n integer, allocatable :: tmp(:), tmp_row(:), ret(:)\n integer :: i\n\n associate (s1 => size(arr1), s2 => size(arr2))\n allocate (tmp_row(s1 + s2), tmp(s1 + s2 + 2))\n tmp = 0\n\n do i = s2, 1, -1\n tmp_row = 0; tmp_row(i + 1:i + s1) = arr1\n tmp = tmp + carry(tmp_row*arr2(i))\n end do\n end associate\n ret = cut_leading_zeros(carry(tmp))\n end function mul\n\n !> The core function to provide the ability of power.\n !>\n !> Each element of the input array is an 32bit integer greater than or\n !> equal to zero and less than or equal to nine. The function uses\n !> a very simple implementation of exponentiation\n !> ([wiki links](https://en.wikipedia.org/wiki/\n !>Exponentiation_by_squaring)). The function currently doesn't\n !> support negative powers.\n pure recursive function pow2(arr, n) result(ret)\n integer, contiguous, intent(in) :: arr(:)\n integer, intent(in) :: n\n integer, allocatable :: ret(:)\n\n if (n < 0) error stop 'pow2: n is nonnegative.'\n\n if (n == 0) then\n ret = [1]\n else if (n == 1) then\n ret = arr\n else if (mod(n, 2) == 0) then\n ret = pow2(mul(arr, arr), n/2)\n else if (mod(n, 2) /= 0) then\n ret = pow2(mul(arr, arr), (n - 1)/2)\n ret = mul(arr, ret)\n end if\n end function pow2\n\nend module euler_multiprecision_util_m\n", "meta": {"hexsha": "0911830bad9fe4277a84553d898d120d91895784", "size": 6139, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "docs/src/euler_multiprecision_util_m.f90", "max_stars_repo_name": "han190/PE-Fortran", "max_stars_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-02-09T07:07:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-31T07:45:48.000Z", "max_issues_repo_path": "src/euler_multiprecision_util_m.f90", "max_issues_repo_name": "han190/PE-Fortran", "max_issues_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-14T00:48:58.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-14T00:48:58.000Z", "max_forks_repo_path": "docs/src/euler_multiprecision_util_m.f90", "max_forks_repo_name": "han190/PE-Fortran", "max_forks_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-04T21:29:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T21:29:45.000Z", "avg_line_length": 36.5416666667, "max_line_length": 75, "alphanum_fraction": 0.5580713471, "num_tokens": 1775, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517043, "lm_q2_score": 0.7879311856832191, "lm_q1q2_score": 0.6728244879032581}} {"text": ": MAIN\n 0\n BEGIN\n 1+\n DUP 100 <= WHILE\n DUP .\n REPEAT\n DROP\n;\n\nMAIN\n", "meta": {"hexsha": "513b21b3efb1104de3c0812d7a76677450973156", "size": 101, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/std-100.f", "max_stars_repo_name": "matematikaadit/JombloForth", "max_stars_repo_head_hexsha": "cf61a32e0679a6070b73f6db24bba1a0f9bb920c", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-03-08T08:22:38.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-12T13:14:11.000Z", "max_issues_repo_path": "tests/std-100.f", "max_issues_repo_name": "ammarfaizi2/jombloforth", "max_issues_repo_head_hexsha": "cf61a32e0679a6070b73f6db24bba1a0f9bb920c", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-03-03T20:37:51.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-04T09:15:17.000Z", "max_forks_repo_path": "tests/std-100.f", "max_forks_repo_name": "matematikaadit/JombloForth", "max_forks_repo_head_hexsha": "cf61a32e0679a6070b73f6db24bba1a0f9bb920c", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-10-25T22:06:14.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-09T13:59:04.000Z", "avg_line_length": 8.4166666667, "max_line_length": 24, "alphanum_fraction": 0.3861386139, "num_tokens": 34, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127380808499, "lm_q2_score": 0.787931190663057, "lm_q1q2_score": 0.6728244804383952}} {"text": " SUBROUTINE SB02MD( DICO, HINV, UPLO, SCAL, SORT, N, A, LDA, G,\n $ LDG, Q, LDQ, RCOND, WR, WI, S, LDS, U, LDU,\n $ IWORK, DWORK, LDWORK, BWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To solve for X either the continuous-time algebraic Riccati\nC equation\nC -1\nC Q + A'*X + X*A - X*B*R B'*X = 0 (1)\nC\nC or the discrete-time algebraic Riccati equation\nC -1\nC X = A'*X*A - A'*X*B*(R + B'*X*B) B'*X*A + Q (2)\nC\nC where A, B, Q and R are N-by-N, N-by-M, N-by-N and M-by-M matrices\nC respectively, with Q symmetric and R symmetric nonsingular; X is\nC an N-by-N symmetric matrix.\nC -1\nC The matrix G = B*R B' must be provided on input, instead of B and\nC R, that is, for instance, the continuous-time equation\nC\nC Q + A'*X + X*A - X*G*X = 0 (3)\nC\nC is solved, where G is an N-by-N symmetric matrix. SLICOT Library\nC routine SB02MT should be used to compute G, given B and R. SB02MT\nC also enables to solve Riccati equations corresponding to optimal\nC problems with coupling terms.\nC\nC The routine also returns the computed values of the closed-loop\nC spectrum of the optimal system, i.e., the stable eigenvalues\nC lambda(1),...,lambda(N) of the corresponding Hamiltonian or\nC symplectic matrix associated to the optimal problem.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC DICO CHARACTER*1\nC Specifies the type of Riccati equation to be solved as\nC follows:\nC = 'C': Equation (3), continuous-time case;\nC = 'D': Equation (2), discrete-time case.\nC\nC HINV CHARACTER*1\nC If DICO = 'D', specifies which symplectic matrix is to be\nC constructed, as follows:\nC = 'D': The matrix H in (5) (see METHOD) is constructed;\nC = 'I': The inverse of the matrix H in (5) is constructed.\nC HINV is not used if DICO = 'C'.\nC\nC UPLO CHARACTER*1\nC Specifies which triangle of the matrices G and Q is\nC stored, as follows:\nC = 'U': Upper triangle is stored;\nC = 'L': Lower triangle is stored.\nC\nC SCAL CHARACTER*1\nC Specifies whether or not a scaling strategy should be\nC used, as follows:\nC = 'G': General scaling should be used;\nC = 'N': No scaling should be used.\nC\nC SORT CHARACTER*1\nC Specifies which eigenvalues should be obtained in the top\nC of the Schur form, as follows:\nC = 'S': Stable eigenvalues come first;\nC = 'U': Unstable eigenvalues come first.\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The order of the matrices A, Q, G and X. N >= 0.\nC\nC A (input/output) DOUBLE PRECISION array, dimension (LDA,N)\nC On entry, the leading N-by-N part of this array must\nC contain the coefficient matrix A of the equation.\nC On exit, if DICO = 'D', and INFO = 0 or INFO > 1, the\nC -1\nC leading N-by-N part of this array contains the matrix A .\nC Otherwise, the array A is unchanged on exit.\nC\nC LDA INTEGER\nC The leading dimension of array A. LDA >= MAX(1,N).\nC\nC G (input) DOUBLE PRECISION array, dimension (LDG,N)\nC The leading N-by-N upper triangular part (if UPLO = 'U')\nC or lower triangular part (if UPLO = 'L') of this array\nC must contain the upper triangular part or lower triangular\nC part, respectively, of the symmetric matrix G.\nC The strictly lower triangular part (if UPLO = 'U') or\nC strictly upper triangular part (if UPLO = 'L') is not\nC referenced.\nC\nC LDG INTEGER\nC The leading dimension of array G. LDG >= MAX(1,N).\nC\nC Q (input/output) DOUBLE PRECISION array, dimension (LDQ,N)\nC On entry, the leading N-by-N upper triangular part (if\nC UPLO = 'U') or lower triangular part (if UPLO = 'L') of\nC this array must contain the upper triangular part or lower\nC triangular part, respectively, of the symmetric matrix Q.\nC The strictly lower triangular part (if UPLO = 'U') or\nC strictly upper triangular part (if UPLO = 'L') is not\nC used.\nC On exit, if INFO = 0, the leading N-by-N part of this\nC array contains the solution matrix X of the problem.\nC\nC LDQ INTEGER\nC The leading dimension of array N. LDQ >= MAX(1,N).\nC\nC RCOND (output) DOUBLE PRECISION\nC An estimate of the reciprocal of the condition number (in\nC the 1-norm) of the N-th order system of algebraic\nC equations from which the solution matrix X is obtained.\nC\nC WR (output) DOUBLE PRECISION array, dimension (2*N)\nC WI (output) DOUBLE PRECISION array, dimension (2*N)\nC If INFO = 0 or INFO = 5, these arrays contain the real and\nC imaginary parts, respectively, of the eigenvalues of the\nC 2N-by-2N matrix S, ordered as specified by SORT (except\nC for the case HINV = 'D', when the order is opposite to\nC that specified by SORT). The leading N elements of these\nC arrays contain the closed-loop spectrum of the system\nC -1\nC matrix A - B*R *B'*X, if DICO = 'C', or of the matrix\nC -1\nC A - B*(R + B'*X*B) B'*X*A, if DICO = 'D'. Specifically,\nC lambda(k) = WR(k) + j*WI(k), for k = 1,2,...,N.\nC\nC S (output) DOUBLE PRECISION array, dimension (LDS,2*N)\nC If INFO = 0 or INFO = 5, the leading 2N-by-2N part of this\nC array contains the ordered real Schur form S of the\nC Hamiltonian or symplectic matrix H. That is,\nC\nC (S S )\nC ( 11 12)\nC S = ( ),\nC (0 S )\nC ( 22)\nC\nC where S , S and S are N-by-N matrices.\nC 11 12 22\nC\nC LDS INTEGER\nC The leading dimension of array S. LDS >= MAX(1,2*N).\nC\nC U (output) DOUBLE PRECISION array, dimension (LDU,2*N)\nC If INFO = 0 or INFO = 5, the leading 2N-by-2N part of this\nC array contains the transformation matrix U which reduces\nC the Hamiltonian or symplectic matrix H to the ordered real\nC Schur form S. That is,\nC\nC (U U )\nC ( 11 12)\nC U = ( ),\nC (U U )\nC ( 21 22)\nC\nC where U , U , U and U are N-by-N matrices.\nC 11 12 21 22\nC\nC LDU INTEGER\nC The leading dimension of array U. LDU >= MAX(1,2*N).\nC\nC Workspace\nC\nC IWORK INTEGER array, dimension (2*N)\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0, DWORK(1) returns the optimal value\nC of LDWORK and DWORK(2) returns the scaling factor used\nC (set to 1 if SCAL = 'N'), also set if INFO = 5;\nC if DICO = 'D', DWORK(3) returns the reciprocal condition\nC number of the given matrix A.\nC\nC LDWORK INTEGER\nC The length of the array DWORK.\nC LDWORK >= MAX(2,6*N) if DICO = 'C';\nC LDWORK >= MAX(3,6*N) if DICO = 'D'.\nC For optimum performance LDWORK should be larger.\nC\nC BWORK LOGICAL array, dimension (2*N)\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value;\nC = 1: if matrix A is (numerically) singular in discrete-\nC time case;\nC = 2: if the Hamiltonian or symplectic matrix H cannot be\nC reduced to real Schur form;\nC = 3: if the real Schur form of the Hamiltonian or\nC symplectic matrix H cannot be appropriately ordered;\nC = 4: if the Hamiltonian or symplectic matrix H has less\nC than N stable eigenvalues;\nC = 5: if the N-th order system of linear algebraic\nC equations, from which the solution matrix X would\nC be obtained, is singular to working precision.\nC\nC METHOD\nC\nC The method used is the Schur vector approach proposed by Laub.\nC It is assumed that [A,B] is a stabilizable pair (where for (3) B\nC is any matrix such that B*B' = G with rank(B) = rank(G)), and\nC [E,A] is a detectable pair, where E is any matrix such that\nC E*E' = Q with rank(E) = rank(Q). Under these assumptions, any of\nC the algebraic Riccati equations (1)-(3) is known to have a unique\nC non-negative definite solution. See [2].\nC Now consider the 2N-by-2N Hamiltonian or symplectic matrix\nC\nC ( A -G )\nC H = ( ), (4)\nC (-Q -A'),\nC\nC for continuous-time equation, and\nC -1 -1\nC ( A A *G )\nC H = ( -1 -1 ), (5)\nC (Q*A A' + Q*A *G)\nC -1\nC for discrete-time equation, respectively, where G = B*R *B'.\nC The assumptions guarantee that H in (4) has no pure imaginary\nC eigenvalues, and H in (5) has no eigenvalues on the unit circle.\nC If Y is an N-by-N matrix then there exists an orthogonal matrix U\nC such that U'*Y*U is an upper quasi-triangular matrix. Moreover, U\nC can be chosen so that the 2-by-2 and 1-by-1 diagonal blocks\nC (corresponding to the complex conjugate eigenvalues and real\nC eigenvalues respectively) appear in any desired order. This is the\nC ordered real Schur form. Thus, we can find an orthogonal\nC similarity transformation U which puts (4) or (5) in ordered real\nC Schur form\nC\nC U'*H*U = S = (S(1,1) S(1,2))\nC ( 0 S(2,2))\nC\nC where S(i,j) is an N-by-N matrix and the eigenvalues of S(1,1)\nC have negative real parts in case of (4), or moduli greater than\nC one in case of (5). If U is conformably partitioned into four\nC N-by-N blocks\nC\nC U = (U(1,1) U(1,2))\nC (U(2,1) U(2,2))\nC\nC with respect to the assumptions we then have\nC (a) U(1,1) is invertible and X = U(2,1)*inv(U(1,1)) solves (1),\nC (2), or (3) with X = X' and non-negative definite;\nC (b) the eigenvalues of S(1,1) (if DICO = 'C') or S(2,2) (if\nC DICO = 'D') are equal to the eigenvalues of optimal system\nC (the 'closed-loop' spectrum).\nC\nC [A,B] is stabilizable if there exists a matrix F such that (A-BF)\nC is stable. [E,A] is detectable if [A',E'] is stabilizable.\nC\nC REFERENCES\nC\nC [1] Laub, A.J.\nC A Schur Method for Solving Algebraic Riccati equations.\nC IEEE Trans. Auto. Contr., AC-24, pp. 913-921, 1979.\nC\nC [2] Wonham, W.M.\nC On a matrix Riccati equation of stochastic control.\nC SIAM J. Contr., 6, pp. 681-697, 1968.\nC\nC [3] Sima, V.\nC Algorithms for Linear-Quadratic Optimization.\nC Pure and Applied Mathematics: A Series of Monographs and\nC Textbooks, vol. 200, Marcel Dekker, Inc., New York, 1996.\nC\nC NUMERICAL ASPECTS\nC 3\nC The algorithm requires 0(N ) operations.\nC\nC FURTHER COMMENTS\nC\nC To obtain a stabilizing solution of the algebraic Riccati\nC equation for DICO = 'D', set SORT = 'U', if HINV = 'D', or set\nC SORT = 'S', if HINV = 'I'.\nC\nC The routine can also compute the anti-stabilizing solutions of\nC the algebraic Riccati equations, by specifying\nC SORT = 'U' if DICO = 'D' and HINV = 'I', or DICO = 'C', or\nC SORT = 'S' if DICO = 'D' and HINV = 'D'.\nC\nC Usually, the combinations HINV = 'D' and SORT = 'U', or HINV = 'I'\nC and SORT = 'U', will be faster then the other combinations [3].\nC\nC CONTRIBUTOR\nC\nC Release 3.0: V. Sima, Katholieke Univ. Leuven, Belgium, Aug. 1997.\nC Supersedes Release 2.0 routine SB02AD by Control Systems Research\nC Group, Kingston Polytechnic, United Kingdom, March 1982.\nC\nC REVISIONS\nC\nC V. Sima, Research Institute for Informatics, Bucharest, Dec. 2002.\nC\nC KEYWORDS\nC\nC Algebraic Riccati equation, closed loop system, continuous-time\nC system, discrete-time system, optimal regulator, Schur form.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, HALF, ONE\n PARAMETER ( ZERO = 0.0D0, HALF = 0.5D0, ONE = 1.0D0 )\nC .. Scalar Arguments ..\n CHARACTER DICO, HINV, SCAL, SORT, UPLO\n INTEGER INFO, LDA, LDG, LDQ, LDS, LDU, LDWORK, N\n DOUBLE PRECISION RCOND\nC .. Array Arguments ..\n LOGICAL BWORK(*)\n INTEGER IWORK(*)\n DOUBLE PRECISION A(LDA,*), DWORK(*), G(LDG,*), Q(LDQ,*),\n $ S(LDS,*), U(LDU,*), WR(*), WI(*)\nC .. Local Scalars ..\n LOGICAL DISCR, LHINV, LSCAL, LSORT, LUPLO\n INTEGER I, IERR, ISCL, N2, NP1, NROT\n DOUBLE PRECISION GNORM, QNORM, RCONDA, UNORM, WRKOPT\nC .. External Functions ..\n LOGICAL LSAME, SB02MR, SB02MS, SB02MV, SB02MW\n DOUBLE PRECISION DLAMCH, DLANGE, DLANSY\n EXTERNAL DLAMCH, DLANGE, DLANSY, LSAME, SB02MR, SB02MS,\n $ SB02MV, SB02MW\nC .. External Subroutines ..\n EXTERNAL DAXPY, DCOPY, DGECON, DGEES, DGETRF, DGETRS,\n $ DLACPY, DLASCL, DLASET, DSCAL, DSWAP, SB02MU,\n $ XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC INT, MAX\nC .. Executable Statements ..\nC\n INFO = 0\n N2 = N + N\n NP1 = N + 1\n DISCR = LSAME( DICO, 'D' )\n LSCAL = LSAME( SCAL, 'G' )\n LSORT = LSAME( SORT, 'S' )\n LUPLO = LSAME( UPLO, 'U' )\n IF ( DISCR ) LHINV = LSAME( HINV, 'D' )\nC\nC Test the input scalar arguments.\nC\n IF( .NOT.DISCR .AND. .NOT.LSAME( DICO, 'C' ) ) THEN\n INFO = -1\n ELSE IF( DISCR ) THEN\n IF( .NOT.LHINV .AND. .NOT.LSAME( HINV, 'I' ) )\n $ INFO = -2\n END IF\n IF( .NOT.LUPLO .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN\n INFO = -3\n ELSE IF( .NOT.LSCAL .AND. .NOT.LSAME( SCAL, 'N' ) ) THEN\n INFO = -4\n ELSE IF( .NOT.LSORT .AND. .NOT.LSAME( SORT, 'U' ) ) THEN\n INFO = -5\n ELSE IF( N.LT.0 ) THEN\n INFO = -6\n ELSE IF( LDA.LT.MAX( 1, N ) ) THEN\n INFO = -8\n ELSE IF( LDG.LT.MAX( 1, N ) ) THEN\n INFO = -10\n ELSE IF( LDQ.LT.MAX( 1, N ) ) THEN\n INFO = -12\n ELSE IF( LDS.LT.MAX( 1, N2 ) ) THEN\n INFO = -17\n ELSE IF( LDU.LT.MAX( 1, N2 ) ) THEN\n INFO = -19\n ELSE IF( ( .NOT.DISCR .AND. LDWORK.LT.MAX( 2, 6*N ) ) .OR.\n $ ( DISCR .AND. LDWORK.LT.MAX( 3, 6*N ) ) ) THEN\n INFO = -22\n END IF\nC\n IF ( INFO.NE.0 ) THEN\nC\nC Error return.\nC\n CALL XERBLA( 'SB02MD', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF ( N.EQ.0 ) THEN\n RCOND = ONE\n DWORK(1) = ONE\n DWORK(2) = ONE\n IF ( DISCR ) DWORK(3) = ONE\n RETURN\n END IF\nC\n IF ( LSCAL ) THEN\nC\nC Compute the norms of the matrices Q and G.\nC\n QNORM = DLANSY( '1-norm', UPLO, N, Q, LDQ, DWORK )\n GNORM = DLANSY( '1-norm', UPLO, N, G, LDG, DWORK )\n END IF\nC\nC Initialise the Hamiltonian or symplectic matrix associated with\nC the problem.\nC Workspace: need 1 if DICO = 'C';\nC max(2,4*N) if DICO = 'D';\nC prefer larger if DICO = 'D'.\nC\n CALL SB02MU( DICO, HINV, UPLO, N, A, LDA, G, LDG, Q, LDQ, S, LDS,\n $ IWORK, DWORK, LDWORK, INFO )\n IF ( INFO.NE.0 ) THEN\n INFO = 1\n RETURN\n END IF\nC\n WRKOPT = DWORK(1)\n IF ( DISCR ) RCONDA = DWORK(2)\nC\n ISCL = 0\n IF ( LSCAL ) THEN\nC\nC Scale the Hamiltonian or symplectic matrix.\nC\n IF( QNORM.GT.GNORM .AND. GNORM.GT.ZERO ) THEN\n CALL DLASCL( 'G', 0, 0, QNORM, GNORM, N, N, S(NP1,1), N2,\n $ IERR )\n CALL DLASCL( 'G', 0, 0, GNORM, QNORM, N, N, S(1,NP1), N2,\n $ IERR )\n ISCL = 1\n END IF\n END IF\nC\nC Find the ordered Schur factorization of S, S = U*H*U'.\nC Workspace: need 6*N;\nC prefer larger.\nC\n IF ( .NOT.DISCR ) THEN\n IF ( LSORT ) THEN\n CALL DGEES( 'Vectors', 'Sorted', SB02MV, N2, S, LDS, NROT,\n $ WR, WI, U, LDU, DWORK, LDWORK, BWORK, INFO )\n ELSE\n CALL DGEES( 'Vectors', 'Sorted', SB02MR, N2, S, LDS, NROT,\n $ WR, WI, U, LDU, DWORK, LDWORK, BWORK, INFO )\n END IF\n ELSE\n IF ( LSORT ) THEN\n CALL DGEES( 'Vectors', 'Sorted', SB02MW, N2, S, LDS, NROT,\n $ WR, WI, U, LDU, DWORK, LDWORK, BWORK, INFO )\n ELSE\n CALL DGEES( 'Vectors', 'Sorted', SB02MS, N2, S, LDS, NROT,\n $ WR, WI, U, LDU, DWORK, LDWORK, BWORK, INFO )\n END IF\n IF ( LHINV ) THEN\n CALL DSWAP( N, WR, 1, WR(NP1), 1 )\n CALL DSWAP( N, WI, 1, WI(NP1), 1 )\n END IF\n END IF\n IF ( INFO.GT.N2 ) THEN\n INFO = 3\n ELSE IF ( INFO.GT.0 ) THEN\n INFO = 2\n ELSE IF ( NROT.NE.N ) THEN\n INFO = 4\n END IF\n IF ( INFO.NE.0 )\n $ RETURN\nC\n WRKOPT = MAX( WRKOPT, DWORK(1) )\nC\nC Check if U(1,1) is singular. Use the (2,1) block of S as a\nC workspace for factoring U(1,1).\nC\n UNORM = DLANGE( '1-norm', N, N, U, LDU, DWORK )\nC\n CALL DLACPY( 'Full', N, N, U, LDU, S(NP1,1), LDS )\n CALL DGETRF( N, N, S(NP1,1), LDS, IWORK, INFO )\nC\n IF ( INFO.GT.0 ) THEN\nC\nC Singular matrix. Set INFO and RCOND for error return.\nC\n INFO = 5\n RCOND = ZERO\n GO TO 100\n END IF\nC\nC Estimate the reciprocal condition of U(1,1).\nC Workspace: 6*N.\nC\n CALL DGECON( '1-norm', N, S(NP1,1), LDS, UNORM, RCOND,\n $ DWORK, IWORK(NP1), INFO )\nC\n IF ( RCOND.LT.DLAMCH( 'Epsilon' ) ) THEN\nC\nC Nearly singular matrix. Set INFO for error return.\nC\n INFO = 5\n RETURN\n END IF\nC\nC Transpose U(2,1) in Q and compute the solution.\nC\n DO 60 I = 1, N\n CALL DCOPY( N, U(NP1,I), 1, Q(I,1), LDQ )\n 60 CONTINUE\nC\n CALL DGETRS( 'Transpose', N, N, S(NP1,1), LDS, IWORK, Q, LDQ,\n $ INFO )\nC\nC Set S(2,1) to zero.\nC\n CALL DLASET( 'Full', N, N, ZERO, ZERO, S(NP1,1), LDS )\nC\nC Make sure the solution matrix X is symmetric.\nC\n DO 80 I = 1, N - 1\n CALL DAXPY( N-I, ONE, Q(I,I+1), LDQ, Q(I+1,I), 1 )\n CALL DSCAL( N-I, HALF, Q(I+1,I), 1 )\n CALL DCOPY( N-I, Q(I+1,I), 1, Q(I,I+1), LDQ )\n 80 CONTINUE\nC\n IF( LSCAL ) THEN\nC\nC Undo scaling for the solution matrix.\nC\n IF( ISCL.EQ.1 )\n $ CALL DLASCL( 'G', 0, 0, GNORM, QNORM, N, N, Q, LDQ, IERR )\n END IF\nC\nC Set the optimal workspace, the scaling factor, and reciprocal\nC condition number (if any).\nC\n DWORK(1) = WRKOPT\n 100 CONTINUE\n IF( ISCL.EQ.1 ) THEN\n DWORK(2) = QNORM / GNORM\n ELSE\n DWORK(2) = ONE\n END IF\n IF ( DISCR ) DWORK(3) = RCONDA\nC\n RETURN\nC *** Last line of SB02MD ***\n END\n", "meta": {"hexsha": "13d1b6c87fd4a00104a77145c06c172cc90dc134", "size": 20283, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/SB02MD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/SB02MD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/SB02MD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 37.0127737226, "max_line_length": 72, "alphanum_fraction": 0.5322190997, "num_tokens": 6263, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9362850021922959, "lm_q2_score": 0.7185944046238981, "lm_q1q2_score": 0.6728091637086581}} {"text": " SUBROUTINE SB03OD( DICO, FACT, TRANS, N, M, A, LDA, Q, LDQ, B,\n $ LDB, SCALE, WR, WI, DWORK, LDWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To solve for X = op(U)'*op(U) either the stable non-negative\nC definite continuous-time Lyapunov equation\nC 2\nC op(A)'*X + X*op(A) = -scale *op(B)'*op(B) (1)\nC\nC or the convergent non-negative definite discrete-time Lyapunov\nC equation\nC 2\nC op(A)'*X*op(A) - X = -scale *op(B)'*op(B) (2)\nC\nC where op(K) = K or K' (i.e., the transpose of the matrix K), A is\nC an N-by-N matrix, op(B) is an M-by-N matrix, U is an upper\nC triangular matrix containing the Cholesky factor of the solution\nC matrix X, X = op(U)'*op(U), and scale is an output scale factor,\nC set less than or equal to 1 to avoid overflow in X. If matrix B\nC has full rank then the solution matrix X will be positive-definite\nC and hence the Cholesky factor U will be nonsingular, but if B is\nC rank deficient then X may be only positive semi-definite and U\nC will be singular.\nC\nC In the case of equation (1) the matrix A must be stable (that\nC is, all the eigenvalues of A must have negative real parts),\nC and for equation (2) the matrix A must be convergent (that is,\nC all the eigenvalues of A must lie inside the unit circle).\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC DICO CHARACTER*1\nC Specifies the type of Lyapunov equation to be solved as\nC follows:\nC = 'C': Equation (1), continuous-time case;\nC = 'D': Equation (2), discrete-time case.\nC\nC FACT CHARACTER*1\nC Specifies whether or not the real Schur factorization\nC of the matrix A is supplied on entry, as follows:\nC = 'F': On entry, A and Q contain the factors from the\nC real Schur factorization of the matrix A;\nC = 'N': The Schur factorization of A will be computed\nC and the factors will be stored in A and Q.\nC\nC TRANS CHARACTER*1\nC Specifies the form of op(K) to be used, as follows:\nC = 'N': op(K) = K (No transpose);\nC = 'T': op(K) = K**T (Transpose).\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The order of the matrix A and the number of columns in\nC matrix op(B). N >= 0.\nC\nC M (input) INTEGER\nC The number of rows in matrix op(B). M >= 0.\nC\nC A (input/output) DOUBLE PRECISION array, dimension (LDA,N)\nC On entry, the leading N-by-N part of this array must\nC contain the matrix A. If FACT = 'F', then A contains\nC an upper quasi-triangular matrix S in Schur canonical\nC form; the elements below the upper Hessenberg part of the\nC array A are not referenced.\nC On exit, the leading N-by-N upper Hessenberg part of this\nC array contains the upper quasi-triangular matrix S in\nC Schur canonical form from the Shur factorization of A.\nC The contents of array A is not modified if FACT = 'F'.\nC\nC LDA INTEGER\nC The leading dimension of array A. LDA >= MAX(1,N).\nC\nC Q (input or output) DOUBLE PRECISION array, dimension\nC (LDQ,N)\nC On entry, if FACT = 'F', then the leading N-by-N part of\nC this array must contain the orthogonal matrix Q of the\nC Schur factorization of A.\nC Otherwise, Q need not be set on entry.\nC On exit, the leading N-by-N part of this array contains\nC the orthogonal matrix Q of the Schur factorization of A.\nC The contents of array Q is not modified if FACT = 'F'.\nC\nC LDQ INTEGER\nC The leading dimension of array Q. LDQ >= MAX(1,N).\nC\nC B (input/output) DOUBLE PRECISION array, dimension (LDB,N)\nC if TRANS = 'N', and dimension (LDB,max(M,N)), if\nC TRANS = 'T'.\nC On entry, if TRANS = 'N', the leading M-by-N part of this\nC array must contain the coefficient matrix B of the\nC equation.\nC On entry, if TRANS = 'T', the leading N-by-M part of this\nC array must contain the coefficient matrix B of the\nC equation.\nC On exit, the leading N-by-N part of this array contains\nC the upper triangular Cholesky factor U of the solution\nC matrix X of the problem, X = op(U)'*op(U).\nC If M = 0 and N > 0, then U is set to zero.\nC\nC LDB INTEGER\nC The leading dimension of array B.\nC LDB >= MAX(1,N,M), if TRANS = 'N';\nC LDB >= MAX(1,N), if TRANS = 'T'.\nC\nC SCALE (output) DOUBLE PRECISION\nC The scale factor, scale, set less than or equal to 1 to\nC prevent the solution overflowing.\nC\nC WR (output) DOUBLE PRECISION array, dimension (N)\nC WI (output) DOUBLE PRECISION array, dimension (N)\nC If FACT = 'N', and INFO >= 0 and INFO <= 2, WR and WI\nC contain the real and imaginary parts, respectively, of\nC the eigenvalues of A.\nC If FACT = 'F', WR and WI are not referenced.\nC\nC Workspace\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0, or INFO = 1, DWORK(1) returns the\nC optimal value of LDWORK.\nC\nC LDWORK INTEGER\nC The length of the array DWORK.\nC If M > 0, LDWORK >= MAX(1,4*N + MIN(M,N));\nC If M = 0, LDWORK >= 1.\nC For optimum performance LDWORK should sometimes be larger.\nC\nC If LDWORK = -1, then a workspace query is assumed; the\nC routine only calculates the optimal size of the DWORK\nC array, returns this value as the first entry of the DWORK\nC array, and no error message related to LDWORK is issued by\nC XERBLA.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value;\nC = 1: if the Lyapunov equation is (nearly) singular\nC (warning indicator);\nC if DICO = 'C' this means that while the matrix A\nC (or the factor S) has computed eigenvalues with\nC negative real parts, it is only just stable in the\nC sense that small perturbations in A can make one or\nC more of the eigenvalues have a non-negative real\nC part;\nC if DICO = 'D' this means that while the matrix A\nC (or the factor S) has computed eigenvalues inside\nC the unit circle, it is nevertheless only just\nC convergent, in the sense that small perturbations\nC in A can make one or more of the eigenvalues lie\nC outside the unit circle;\nC perturbed values were used to solve the equation;\nC = 2: if FACT = 'N' and DICO = 'C', but the matrix A is\nC not stable (that is, one or more of the eigenvalues\nC of A has a non-negative real part), or DICO = 'D',\nC but the matrix A is not convergent (that is, one or\nC more of the eigenvalues of A lies outside the unit\nC circle); however, A will still have been factored\nC and the eigenvalues of A returned in WR and WI.\nC = 3: if FACT = 'F' and DICO = 'C', but the Schur factor S\nC supplied in the array A is not stable (that is, one\nC or more of the eigenvalues of S has a non-negative\nC real part), or DICO = 'D', but the Schur factor S\nC supplied in the array A is not convergent (that is,\nC one or more of the eigenvalues of S lies outside the\nC unit circle);\nC = 4: if FACT = 'F' and the Schur factor S supplied in\nC the array A has two or more consecutive non-zero\nC elements on the first sub-diagonal, so that there is\nC a block larger than 2-by-2 on the diagonal;\nC = 5: if FACT = 'F' and the Schur factor S supplied in\nC the array A has a 2-by-2 diagonal block with real\nC eigenvalues instead of a complex conjugate pair;\nC = 6: if FACT = 'N' and the LAPACK Library routine DGEES\nC has failed to converge. This failure is not likely\nC to occur. The matrix B will be unaltered but A will\nC be destroyed.\nC\nC METHOD\nC\nC The method used by the routine is based on the Bartels and Stewart\nC method [1], except that it finds the upper triangular matrix U\nC directly without first finding X and without the need to form the\nC normal matrix op(B)'*op(B).\nC\nC The Schur factorization of a square matrix A is given by\nC\nC A = QSQ',\nC\nC where Q is orthogonal and S is an N-by-N block upper triangular\nC matrix with 1-by-1 and 2-by-2 blocks on its diagonal (which\nC correspond to the eigenvalues of A). If A has already been\nC factored prior to calling the routine however, then the factors\nC Q and S may be supplied and the initial factorization omitted.\nC\nC If TRANS = 'N', the matrix B is factored as (QR factorization)\nC _ _ _ _ _\nC B = P ( R ), M >= N, B = P ( R Z ), M < N,\nC ( 0 )\nC _ _\nC where P is an M-by-M orthogonal matrix and R is a square upper\nC _ _ _ _ _\nC triangular matrix. Then, the matrix B = RQ, or B = ( R Z )Q (if\nC M < N) is factored as\nC _ _\nC B = P ( R ), M >= N, B = P ( R Z ), M < N.\nC\nC If TRANS = 'T', the matrix B is factored as (RQ factorization)\nC _\nC _ _ ( Z ) _\nC B = ( 0 R ) P, M >= N, B = ( _ ) P, M < N,\nC ( R )\nC _ _\nC where P is an M-by-M orthogonal matrix and R is a square upper\nC _ _ _ _ _\nC triangular matrix. Then, the matrix B = Q'R, or B = Q'( Z' R' )'\nC (if M < N) is factored as\nC _ _\nC B = ( R ) P, M >= N, B = ( Z ) P, M < N.\nC ( R )\nC\nC These factorizations are utilised to either transform the\nC continuous-time Lyapunov equation to the canonical form\nC 2\nC op(S)'*op(V)'*op(V) + op(V)'*op(V)*op(S) = -scale *op(F)'*op(F),\nC\nC or the discrete-time Lyapunov equation to the canonical form\nC 2\nC op(S)'*op(V)'*op(V)*op(S) - op(V)'*op(V) = -scale *op(F)'*op(F),\nC\nC where V and F are upper triangular, and\nC\nC F = R, M >= N, F = ( R Z ), M < N, if TRANS = 'N';\nC ( 0 0 )\nC\nC F = R, M >= N, F = ( 0 Z ), M < N, if TRANS = 'T'.\nC ( 0 R )\nC\nC The transformed equation is then solved for V, from which U is\nC obtained via the QR factorization of V*Q', if TRANS = 'N', or\nC via the RQ factorization of Q*V, if TRANS = 'T'.\nC\nC REFERENCES\nC\nC [1] Bartels, R.H. and Stewart, G.W.\nC Solution of the matrix equation A'X + XB = C.\nC Comm. A.C.M., 15, pp. 820-826, 1972.\nC\nC [2] Hammarling, S.J.\nC Numerical solution of the stable, non-negative definite\nC Lyapunov equation.\nC IMA J. Num. Anal., 2, pp. 303-325, 1982.\nC\nC NUMERICAL ASPECTS\nC 3\nC The algorithm requires 0(N ) operations and is backward stable.\nC\nC FURTHER COMMENTS\nC\nC The Lyapunov equation may be very ill-conditioned. In particular,\nC if A is only just stable (or convergent) then the Lyapunov\nC equation will be ill-conditioned. A symptom of ill-conditioning\nC is \"large\" elements in U relative to those of A and B, or a\nC \"small\" value for scale. A condition estimate can be computed\nC using SLICOT Library routine SB03MD.\nC\nC SB03OD routine can be also used for solving \"unstable\" Lyapunov\nC equations, i.e., when matrix A has all eigenvalues with positive\nC real parts, if DICO = 'C', or with moduli greater than one,\nC if DICO = 'D'. Specifically, one may solve for X = op(U)'*op(U)\nC either the continuous-time Lyapunov equation\nC 2\nC op(A)'*X + X*op(A) = scale *op(B)'*op(B), (3)\nC\nC or the discrete-time Lyapunov equation\nC 2\nC op(A)'*X*op(A) - X = scale *op(B)'*op(B), (4)\nC\nC provided, for equation (3), the given matrix A is replaced by -A,\nC or, for equation (4), the given matrices A and B are replaced by\nC inv(A) and B*inv(A), if TRANS = 'N' (or inv(A)*B, if TRANS = 'T'),\nC respectively. Although the inversion generally can rise numerical\nC problems, in case of equation (4) it is expected that the matrix A\nC is enough well-conditioned, having only eigenvalues with moduli\nC greater than 1. However, if A is ill-conditioned, it could be\nC preferable to use the more general SLICOT Lyapunov solver SB03MD.\nC\nC CONTRIBUTOR\nC\nC Release 3.0: V. Sima, Katholieke Univ. Leuven, Belgium, Aug. 1997.\nC Supersedes Release 2.0 routine SB03CD by Sven Hammarling,\nC NAG Ltd, United Kingdom.\nC\nC REVISIONS\nC\nC Dec. 1997, April 1998, May 1998, May 1999, Oct. 2001 (V. Sima).\nC March 2002 (A. Varga).\nC V. Sima, Research Institute for Informatics, Bucharest, July 2011.\nC\nC KEYWORDS\nC\nC Lyapunov equation, orthogonal transformation, real Schur form,\nC Sylvester equation.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, ONE\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )\nC .. Scalar Arguments ..\n CHARACTER DICO, FACT, TRANS\n INTEGER INFO, LDA, LDB, LDQ, LDWORK, M, N\n DOUBLE PRECISION SCALE\nC .. Array Arguments ..\n DOUBLE PRECISION A(LDA,*), B(LDB,*), DWORK(*), Q(LDQ,*), WI(*),\n $ WR(*)\nC .. Local Scalars ..\n LOGICAL CONT, LQUERY, LTRANS, NOFACT\n INTEGER I, IFAIL, INFORM, ITAU, J, JWORK, K, L, MAXMN,\n $ MINMN, MINWRK, NE, SDIM, WRKOPT\n DOUBLE PRECISION EMAX, TEMP\nC .. Local Arrays ..\n LOGICAL BWORK(1)\nC .. External Functions ..\n LOGICAL LSAME, SELECT\n DOUBLE PRECISION DLAPY2\n EXTERNAL DLAPY2, LSAME, SELECT\nC .. External Subroutines ..\n EXTERNAL DCOPY, DGEES, DGEMM, DGEMV, DGEQRF, DGERQF,\n $ DLACPY, DLASET, DTRMM, SB03OU, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC INT, MAX, MIN\nC .. Executable Statements ..\nC\nC Test the input scalar arguments.\nC\n CONT = LSAME( DICO, 'C' )\n NOFACT = LSAME( FACT, 'N' )\n LTRANS = LSAME( TRANS, 'T' )\n LQUERY = LDWORK.EQ.-1\n MINMN = MIN( M, N )\n MAXMN = MAX( M, N )\nC\n INFO = 0\n IF( .NOT.CONT .AND. .NOT.LSAME( DICO, 'D' ) ) THEN\n INFO = -1\n ELSE IF( .NOT.NOFACT .AND. .NOT.LSAME( FACT, 'F' ) ) THEN\n INFO = -2\n ELSE IF( .NOT.LTRANS .AND. .NOT.LSAME( TRANS, 'N' ) ) THEN\n INFO = -3\n ELSE IF( N.LT.0 ) THEN\n INFO = -4\n ELSE IF( M.LT.0 ) THEN\n INFO = -5\n ELSE IF( LDA.LT.MAX( 1, N ) ) THEN\n INFO = -7\n ELSE IF( LDQ.LT.MAX( 1, N ) ) THEN\n INFO = -9\n ELSE IF( ( LDB.LT.MAX( 1, N ) ) .OR.\n $ ( LDB.LT.MAX( 1, MAXMN ) .AND. .NOT.LTRANS ) ) THEN\n INFO = -11\n ELSE\n IF( M.GT.0 ) THEN\n MINWRK = 4*N + MINMN\n ELSE\n MINWRK = 1\n END IF\n IF( LQUERY ) THEN\n IF ( NOFACT ) THEN\n CALL DGEES( 'Vectors', 'Not ordered', SELECT, N, A, LDA,\n $ SDIM, WR, WI, Q, LDQ, DWORK, -1, BWORK,\n $ IFAIL )\n WRKOPT = MAX( MINWRK, INT( DWORK(1) ) )\n ELSE\n WRKOPT = MINWRK\n END IF\n IF ( LTRANS ) THEN\n CALL DGERQF( N, MAXMN, B, LDB, DWORK, DWORK, -1, IFAIL )\n ELSE\n CALL DGEQRF( MAXMN, N, B, LDB, DWORK, DWORK, -1, IFAIL )\n END IF\n WRKOPT = MAX( WRKOPT, INT( DWORK(1) ) + MAXMN, MINMN*N )\n CALL SB03OU( .NOT.CONT, LTRANS, N, MINMN, A, LDA, B, LDB,\n $ DWORK, B, LDB, SCALE, DWORK, -1, INFO )\n WRKOPT = MAX( WRKOPT, INT( DWORK(1) ) + MINMN, N*N )\n ELSE IF( LDWORK.LT.MINWRK ) THEN\n INFO = -16\n END IF\n END IF\nC\n IF ( INFO.NE.0 ) THEN\nC\nC Error return.\nC\n CALL XERBLA( 'SB03OD', -INFO )\n RETURN\n ELSE IF( LQUERY ) THEN\n DWORK(1) = WRKOPT\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF( MINMN.EQ.0 ) THEN\n IF( M.EQ.0 )\n $ CALL DLASET( 'Full', N, N, ZERO, ZERO, B, LDB )\n SCALE = ONE\n DWORK(1) = ONE\n RETURN\n END IF\nC\nC Start the solution.\nC\nC (Note: Comments in the code beginning \"Workspace:\" describe the\nC minimal amount of real workspace needed at that point in the\nC code, as well as the preferred amount for good performance.\nC NB refers to the optimal block size for the immediately\nC following subroutine, as returned by ILAENV.)\nC\n IF ( NOFACT ) THEN\nC\nC Find the Schur factorization of A, A = Q*S*Q'.\nC Workspace: need 3*N;\nC prefer larger.\nC\n CALL DGEES( 'Vectors', 'Not ordered', SELECT, N, A, LDA, SDIM,\n $ WR, WI, Q, LDQ, DWORK, LDWORK, BWORK, INFORM )\n IF ( INFORM.NE.0 ) THEN\n INFO = 6\n RETURN\n END IF\n WRKOPT = DWORK(1)\nC\nC Check the eigenvalues for stability.\nC\n IF ( CONT ) THEN\n EMAX = WR(1)\nC\n DO 20 J = 2, N\n IF ( WR(J).GT.EMAX )\n $ EMAX = WR(J)\n 20 CONTINUE\nC\n ELSE\n EMAX = DLAPY2( WR(1), WI(1) )\nC\n DO 40 J = 2, N\n TEMP = DLAPY2( WR(J), WI(J) )\n IF ( TEMP.GT.EMAX )\n $ EMAX = TEMP\n 40 CONTINUE\nC\n END IF\nC\n IF ( ( CONT ) .AND. ( EMAX.GE.ZERO ) .OR.\n $ ( .NOT.CONT ) .AND. ( EMAX.GE.ONE ) ) THEN\n INFO = 2\n RETURN\n END IF\n ELSE\n WRKOPT = 0\n END IF\nC\nC Perform the QR or RQ factorization of B,\nC _ _ _ _ _\nC B = P ( R ), or B = P ( R Z ), if TRANS = 'N', or\nC ( 0 )\nC _\nC _ _ ( Z ) _\nC B = ( 0 R ) P, or B = ( _ ) P, if TRANS = 'T'.\nC ( R )\nC Workspace: need MIN(M,N) + N;\nC prefer MIN(M,N) + N*NB.\nC\n ITAU = 1\n JWORK = ITAU + MINMN\n IF ( LTRANS ) THEN\n CALL DGERQF( N, M, B, LDB, DWORK(ITAU), DWORK(JWORK),\n $ LDWORK-JWORK+1, IFAIL )\n WRKOPT = MAX( WRKOPT, INT( DWORK(JWORK) ) + JWORK - 1, MINMN*N)\n JWORK = ITAU\nC\nC Form in B\nC _ _ _ _ _ _\nC B := Q'R, m >= n, B := Q'*( Z' R' )', m < n, with B an\nC n-by-min(m,n) matrix.\nC Use a BLAS 3 operation if enough workspace, and BLAS 2,\nC _\nC otherwise: B is formed column by column.\nC\n IF ( LDWORK.GE.JWORK+MINMN*N-1 ) THEN\n K = JWORK\nC\n DO 60 I = 1, MINMN\n CALL DCOPY( N, Q(N-MINMN+I,1), LDQ, DWORK(K), 1 )\n K = K + N\n 60 CONTINUE\nC\n CALL DTRMM( 'Right', 'Upper', 'No transpose', 'Non-unit',\n $ N, MINMN, ONE, B(N-MINMN+1,M-MINMN+1), LDB,\n $ DWORK(JWORK), N )\n IF ( M.LT.N )\n $ CALL DGEMM( 'Transpose', 'No transpose', N, M, N-M,\n $ ONE, Q, LDQ, B, LDB, ONE, DWORK(JWORK), N )\n CALL DLACPY( 'Full', N, MINMN, DWORK(JWORK), N, B, LDB )\n ELSE\n NE = N - MINMN\nC\n DO 80 J = 1, MINMN\n NE = NE + 1\n CALL DCOPY( NE, B(1,M-MINMN+J), 1, DWORK(JWORK), 1 )\n CALL DGEMV( 'Transpose', NE, N, ONE, Q, LDQ,\n $ DWORK(JWORK), 1, ZERO, B(1,J), 1 )\n 80 CONTINUE\nC\n END IF\n ELSE\n CALL DGEQRF( M, N, B, LDB, DWORK(ITAU), DWORK(JWORK),\n $ LDWORK-JWORK+1, IFAIL )\n WRKOPT = MAX( WRKOPT, INT( DWORK(JWORK) ) + JWORK - 1, MINMN*N)\n JWORK = ITAU\nC\nC Form in B\nC _ _ _ _ _ _\nC B := RQ, m >= n, B := ( R Z )*Q, m < n, with B an\nC min(m,n)-by-n matrix.\nC Use a BLAS 3 operation if enough workspace, and BLAS 2,\nC _\nC otherwise: B is formed row by row.\nC\n IF ( LDWORK.GE.JWORK+MINMN*N-1 ) THEN\n CALL DLACPY( 'Full', MINMN, N, Q, LDQ, DWORK(JWORK), MINMN )\n CALL DTRMM( 'Left', 'Upper', 'No transpose', 'Non-unit',\n $ MINMN, N, ONE, B, LDB, DWORK(JWORK), MINMN )\n IF ( M.LT.N )\n $ CALL DGEMM( 'No transpose', 'No transpose', M, N, N-M,\n $ ONE, B(1,M+1), LDB, Q(M+1,1), LDQ, ONE,\n $ DWORK(JWORK), MINMN )\n CALL DLACPY( 'Full', MINMN, N, DWORK(JWORK), MINMN, B, LDB )\n ELSE\n NE = MINMN + MAX( 0, N-M )\nC\n DO 100 J = 1, MINMN\n CALL DCOPY( NE, B(J,J), LDB, DWORK(JWORK), 1 )\n CALL DGEMV( 'Transpose', NE, N, ONE, Q(J,1), LDQ,\n $ DWORK(JWORK), 1, ZERO, B(J,1), LDB )\n NE = NE - 1\n 100 CONTINUE\nC\n END IF\n END IF\n JWORK = ITAU + MINMN\nC\nC Solve for U the transformed Lyapunov equation\nC 2 _ _\nC op(S)'*op(U)'*op(U) + op(U)'*op(U)*op(S) = -scale *op(B)'*op(B),\nC\nC or\nC 2 _ _\nC op(S)'*op(U)'*op(U)*op(S) - op(U)'*op(U) = -scale *op(B)'*op(B)\nC\nC Workspace: need MIN(M,N) + 4*N;\nC prefer larger.\nC\n CALL SB03OU( .NOT.CONT, LTRANS, N, MINMN, A, LDA, B, LDB,\n $ DWORK(ITAU), B, LDB, SCALE, DWORK(JWORK),\n $ LDWORK-JWORK+1, INFO )\n IF ( INFO.GT.1 ) THEN\n INFO = INFO + 1\n RETURN\n END IF\n WRKOPT = MAX( WRKOPT, INT( DWORK(JWORK) ) + JWORK - 1 )\n JWORK = ITAU\nC\nC Form U := U*Q' or U := Q*U in the array B.\nC Use a BLAS 3 operation if enough workspace, and BLAS 2, otherwise.\nC Workspace: need N;\nC prefer N*N;\nC\n IF ( LDWORK.GE.JWORK+N*N-1 ) THEN\n IF ( LTRANS ) THEN\n CALL DLACPY( 'Full', N, N, Q, LDQ, DWORK(JWORK), N )\n CALL DTRMM( 'Right', 'Upper', 'No transpose', 'Non-unit', N,\n $ N, ONE, B, LDB, DWORK(JWORK), N )\n ELSE\n K = JWORK\nC\n DO 120 I = 1, N\n CALL DCOPY( N, Q(1,I), 1, DWORK(K), N )\n K = K + 1\n 120 CONTINUE\nC\n CALL DTRMM( 'Left', 'Upper', 'No transpose', 'Non-unit', N,\n $ N, ONE, B, LDB, DWORK(JWORK), N )\n END IF\n CALL DLACPY( 'Full', N, N, DWORK(JWORK), N, B, LDB )\n WRKOPT = MAX( WRKOPT, JWORK + N*N - 1 )\n ELSE\n IF ( LTRANS ) THEN\nC\nC U is formed column by column ( U := Q*U ).\nC\n DO 140 I = 1, N\n CALL DCOPY( I, B(1,I), 1, DWORK(JWORK), 1 )\n CALL DGEMV( 'No transpose', N, I, ONE, Q, LDQ,\n $ DWORK(JWORK), 1, ZERO, B(1,I), 1 )\n 140 CONTINUE\n ELSE\nC\nC U is formed row by row ( U' := Q*U' ).\nC\n DO 160 I = 1, N\n CALL DCOPY( N-I+1, B(I,I), LDB, DWORK(JWORK), 1 )\n CALL DGEMV( 'No transpose', N, N-I+1, ONE, Q(1,I), LDQ,\n $ DWORK(JWORK), 1, ZERO, B(I,1), LDB )\n 160 CONTINUE\n END IF\n END IF\nC\nC Lastly find the QR or RQ factorization of U, overwriting on B,\nC to give the required Cholesky factor.\nC Workspace: need 2*N;\nC prefer N + N*NB;\nC\n JWORK = ITAU + N\n IF ( LTRANS ) THEN\n CALL DGERQF( N, N, B, LDB, DWORK(ITAU), DWORK(JWORK),\n $ LDWORK-JWORK+1, IFAIL )\n ELSE\n CALL DGEQRF( N, N, B, LDB, DWORK(ITAU), DWORK(JWORK),\n $ LDWORK-JWORK+1, IFAIL )\n END IF\n WRKOPT = MAX( WRKOPT, INT( DWORK(JWORK) ) + JWORK - 1 )\nC\nC Make the diagonal elements of U non-negative.\nC\n IF ( LTRANS ) THEN\nC\n DO 200 J = 1, N\n IF ( B(J,J).LT.ZERO ) THEN\nC\n DO 180 I = 1, J\n B(I,J) = -B(I,J)\n 180 CONTINUE\nC\n END IF\n 200 CONTINUE\nC\n ELSE\n K = JWORK\nC\n DO 240 J = 1, N\n DWORK(K) = B(J,J)\n L = JWORK\nC\n DO 220 I = 1, J\n IF ( DWORK(L).LT.ZERO ) B(I,J) = -B(I,J)\n L = L + 1\n 220 CONTINUE\nC\n K = K + 1\n 240 CONTINUE\n END IF\nC\n IF( N.GT.1 )\n $ CALL DLASET( 'Lower', N-1, N-1, ZERO, ZERO, B(2,1), LDB )\nC\nC Set the optimal workspace.\nC\n DWORK(1) = WRKOPT\nC\n RETURN\nC *** Last line of SB03OD ***\n END\n", "meta": {"hexsha": "8f1ca97d75cbf7798517d467299f41ade5535042", "size": 26411, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/SB03OD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/SB03OD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/SB03OD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 38.5562043796, "max_line_length": 72, "alphanum_fraction": 0.5037673697, "num_tokens": 7899, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9362850004144266, "lm_q2_score": 0.7185943925708561, "lm_q1q2_score": 0.6728091511460087}} {"text": "\r\nsubroutine CalcEnergy(Pos, M, L, rc, PEnergy, Dim, NAtom)\r\n implicit none\r\n integer, intent(in) :: M, Dim, NAtom\r\n real(8), intent(in), dimension(0:NAtom-1, 0:Dim-1) :: Pos\r\n real(8), intent(in) :: L, rc\r\n real(8), intent(out) :: PEnergy\r\n real(8), parameter :: k = 3000., r0 = 1.\r\n integer:: i, j\r\n real(8) :: kfac, d2, sep, disp, shiftval, rc2, id6, id2, id12\r\n real(8), dimension(Dim) :: rij, Posi\r\n \r\n\r\n !Assign initially zeros to the force array and potential energy\r\n PEnergy = 0.\r\n rc2 = rc**2\r\n\r\n !Precompute constants such as LJ shift value up here\r\n kfac = k/2.\r\n id6 = 1./rc**6\r\n shiftval = 4*(id6**2 - id6)\r\n\r\n\r\n do i=0, NAtom - 1\r\n !store Pos(i,:) in a temporary array for faster access in j looop\r\n Posi = Pos(i,:)\r\n do j = i+1, NAtom - 1\r\n !compute initial rij\r\n rij = Pos(j,:) - Posi\r\n !Apply minimum image convention\r\n rij = rij - L*dnint(rij / L)\r\n\r\n !Do bonded calculation\r\n if ( j == i+1 .and. mod(j, M)> 0) then\r\n !Compute scalar separation\r\n sep = sqrt( sum( rij * rij ) )\r\n !Compute displacement relative to preferred separation\r\n disp = sep - r0\r\n !Calculate energy\r\n PEnergy = PEnergy + kfac * disp*disp\r\n else !Do nonbonded calculation\r\n !compute scalar distance\r\n d2 = sum(rij*rij)\r\n !Check against cutoff\r\n if ( d2 > rc2) then \r\n cycle\r\n end if\r\n id2 = 1./d2 !inverse squared distance\r\n id6 = id2 * id2 * id2 !inverse sixth distance\r\n id12 = id6 * id6 !inverse twelfth distance\r\n PEnergy = Penergy + 4. * (id12 - id6) + shiftval\r\n\r\n !end nonbonded calculation\r\n endif\r\n enddo\r\n enddo\r\nend subroutine\r\n\r\n\r\n\r\nsubroutine CalcEnergyForces(Pos, M, L, rc, PEnergy, Forces, Dim, NAtom)\r\n implicit none\r\n integer, intent(in) :: M, Dim, NAtom\r\n real(8), intent(in), dimension(0:NAtom-1, 0:Dim-1) :: Pos\r\n real(8), intent(in) :: L, rc\r\n real(8), intent(out) :: PEnergy\r\n real(8), intent(inout), dimension(0:NAtom-1, 0:Dim-1) :: Forces\r\n!f2py intent(in, out, inplace) :: Forces\r\n real(8), parameter :: k = 3000., r0 = 1.\r\n integer :: i, j\r\n real(8) :: kfac, d2, sep, disp, shiftval, rc2, id6, id2, id12\r\n real(8), dimension(Dim) :: rij, Fij, Posi\r\n \r\n\r\n !Assign initially zeros to the force array and potential energy\r\n Forces = 0.\r\n PEnergy = 0.\r\n rc2 = rc**2\r\n\r\n !Precompute constants such as LJ shift value up here\r\n kfac = k/2.\r\n id6 = 1./rc**6\r\n shiftval = 4.*(id6**2 - id6)\r\n\r\n\r\n do i=0, NAtom - 1\r\n !store Pos(i,:) in a temporary array for faster access in j looop\r\n Posi = Pos(i,:)\r\n do j = i+1, NAtom - 1\r\n !compute initial rij\r\n rij = Pos(j,:) - Posi\r\n !Apply minimum image convention\r\n rij = rij - L*dnint(rij / L)\r\n\r\n !Do bonded calculation\r\n if ( j == i+1 .and. mod(j, M)> 0) then\r\n !Compute scalar separation\r\n sep = sqrt( sum( rij * rij ) )\r\n !Compute displacement relative to preferred separation\r\n disp = sep - r0\r\n !Calculate energy\r\n PEnergy = PEnergy + kfac * disp*disp\r\n !Calculate force: - k*displacement in direction of rij\r\n Fij = k * ( disp ) * rij/sep\r\n Forces(i,:) = Forces(i,:) + Fij\r\n Forces(j,:) = Forces(j,:) - Fij\r\n else !Do nonbonded calculation\r\n !compute scalar distance\r\n d2 = sum(rij*rij)\r\n !Check against cutoff\r\n if ( d2 > rc2) then \r\n cycle\r\n end if\r\n id2 = 1./d2 !inverse squared distance\r\n id6 = id2 * id2 * id2 !inverse sixth distance\r\n id12 = id6 * id6 !inverse twelfth distance\r\n PEnergy = Penergy + 4. * (id12 - id6) + shiftval\r\n Fij = rij * (-48. * id12 + 24. * id6) * id2\r\n Forces(i,:) = Forces(i,:) + Fij\r\n Forces(j,:) = Forces(j,:) - Fij\r\n\r\n !end nonbonded calculation\r\n endif\r\n enddo\r\n enddo\r\nend subroutine\r\n\r\n\r\nsubroutine VVIntegrate(Pos, Vel, Accel, M, L, rc, dt, KEnergy, PEnergy, Dim, NAtom)\r\n implicit none\r\n integer, intent(in) :: M, Dim, NAtom\r\n real(8), intent(in) :: L, rc, dt\r\n real(8), intent(inout), dimension(0:NAtom-1, 0:Dim-1) :: Pos, Vel, Accel\r\n!f2py intent(in,out,inplace) :: Pos, Vel, Accel\r\n real(8), intent(out) :: KEnergy, PEnergy\r\n external :: CalcEnergyForces\r\n Pos = Pos + dt * Vel + 0.5 * dt*dt * Accel\r\n Vel = Vel + 0.5 * dt * Accel\r\n call CalcEnergyForces(Pos, M, L, rc, PEnergy, Accel, Dim, NAtom)\r\n Vel = Vel + 0.5 * dt * Accel\r\n KEnergy = 0.5 * sum(Vel*Vel)\r\nend subroutine\r\n", "meta": {"hexsha": "1864abeb10337b119a750bee4c20ede44cd7d992", "size": 5155, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uci-pharmsci/assignments/MD/mdlib.f90", "max_stars_repo_name": "inferential/drug-computing", "max_stars_repo_head_hexsha": "25ff2f04b2a1f7cb71c552f62e722edb26cc297f", "max_stars_repo_licenses": ["CC-BY-4.0", "MIT"], "max_stars_count": 103, "max_stars_repo_stars_event_min_datetime": "2017-10-21T18:49:01.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T22:05:21.000Z", "max_issues_repo_path": "uci-pharmsci/assignments/MD/mdlib.f90", "max_issues_repo_name": "inferential/drug-computing", "max_issues_repo_head_hexsha": "25ff2f04b2a1f7cb71c552f62e722edb26cc297f", "max_issues_repo_licenses": ["CC-BY-4.0", "MIT"], "max_issues_count": 29, "max_issues_repo_issues_event_min_datetime": "2017-10-23T20:57:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-15T21:57:09.000Z", "max_forks_repo_path": "uci-pharmsci/assignments/MD/mdlib.f90", "max_forks_repo_name": "inferential/drug-computing", "max_forks_repo_head_hexsha": "25ff2f04b2a1f7cb71c552f62e722edb26cc297f", "max_forks_repo_licenses": ["CC-BY-4.0", "MIT"], "max_forks_count": 36, "max_forks_repo_forks_event_min_datetime": "2018-01-18T20:22:29.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-16T13:08:09.000Z", "avg_line_length": 36.048951049, "max_line_length": 84, "alphanum_fraction": 0.4987390883, "num_tokens": 1487, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850004144265, "lm_q2_score": 0.7185943925708561, "lm_q1q2_score": 0.6728091511460086}} {"text": "SUBROUTINE vmdpl(dee,stress,pl)\r\n!\r\n! This subroutine forms the plastic stress/strain matrix\r\n! for a von-Mises material.\r\n!\r\n IMPLICIT NONE\r\n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\r\n REAL(iwp),INTENT(IN)::stress(:),dee(:,:) \r\n REAL(iwp),INTENT(OUT)::pl(:,:)\r\n REAL(iwp),ALLOCATABLE::dfds(:),ddfds(:)\r\n REAL(iwp)::t2,t6,t10,t14,t16,t17,t18,t19,t21,t22,t23,t25,t26,t30,sq2,sx, &\r\n sy,sz,txy,tyz,tzx,one=1.0_iwp,two=2.0_iwp,d4=4.0_iwp,d6=6.0_iwp\r\n REAL(iwp)::denom\r\n INTEGER::i,j,ih\r\n ih=SIZE(stress)\r\n ALLOCATE(dfds(ih),ddfds(ih))\r\n sq2=SQRT(two)\r\n SELECT CASE(ih)\r\n CASE(4)\r\n sx=stress(1)\r\n sy=stress(2)\r\n txy=stress(3) \r\n sz=stress(4) \r\n t2=sx**2\r\n t6=sy**2\r\n t10=sz**2\r\n t14=txy**2\r\n t17=SQRT(two*t2-two*sx*sy+two*t6-two*sy*sz+two*t10-two*sz*sx+d6*t14)\r\n t19=one/sq2/t17\r\n t21=two*sy\r\n t22=two*sz\r\n t26=two*sx\r\n dfds(1)=t19*(d4*sx-t21-t22)/two\r\n dfds(2)=t19*(-t26+d4*sy-t22)/two\r\n dfds(3)=t19*d6*txy\r\n dfds(4)=t19*(-t21+d4*sz-t26)/two\r\n CASE(6)\r\n sx=stress(1)\r\n sy=stress(2)\r\n sz=stress(3) \r\n txy=stress(4) \r\n tyz=stress(5) \r\n tzx=stress(6) \r\n t2=sx**2\r\n t6=sy**2\r\n t10=sz**2\r\n t14=txy**2\r\n t16=tyz**2\r\n t18=tzx**2\r\n t21=SQRT(two*t2-two*sx*sy+two*t6-two*sy*sz+two*t10- &\r\n two*sz*sx+d6*t14+d6*t16+d6*t18)\r\n t23=one/sq2/t21\r\n t25=two*sy\r\n t26=two*sz\r\n t30=two*sx\r\n dfds(1)=t23*(d4*sx-t25-t26)/two\r\n dfds(2)=t23*(-t30+d4*sy-t26)/two\r\n dfds(3)=t23*(-t25+d4*sz-t30)/two\r\n dfds(4)=t23*d6*txy\r\n dfds(5)=t23*d6*tyz\r\n dfds(6)=t23*d6*tzx\r\n END SELECT\r\n ddfds=MATMUL(dee,dfds) \r\n denom=DOT_PRODUCT(ddfds,dfds)\r\n DO i=1,ih\r\n DO j=1,ih\r\n pl(i,j)=ddfds(i)*ddfds(j)/denom\r\n END DO\r\n END DO\r\n DEALLOCATE(dfds,ddfds)\r\nRETURN\r\nEND SUBROUTINE vmdpl\r\n", "meta": {"hexsha": "3f491e39dfc87b3a3735c0135a01906ca1cfffa0", "size": 1759, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "src/libs/main/vmdpl.f03", "max_stars_repo_name": "leemargetts/PoreFEM", "max_stars_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/libs/main/vmdpl.f03", "max_issues_repo_name": "leemargetts/PoreFEM", "max_issues_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/libs/main/vmdpl.f03", "max_forks_repo_name": "leemargetts/PoreFEM", "max_forks_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.095890411, "max_line_length": 76, "alphanum_fraction": 0.5969300739, "num_tokens": 817, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.936285002192296, "lm_q2_score": 0.7185943865443349, "lm_q1q2_score": 0.6728091467810343}} {"text": "subroutine outnormal_tet(x,nsd,p,outnorm,area)\n! calculate the outward normal for the surface on the solid interface \n! and the area of the surface for tet element cases only \nreal(8) x(nsd,3)\nreal(8) p(nsd)\ninteger nsd\nreal(8) outnorm(nsd)\nreal(8) area\n!---------------------------\nreal(8) ab(nsd)\nreal(8) ac(nsd)\nreal(8) ap(nsd)\nreal(8) dot_pro\n\n\nab(:)=x(:,2)-x(:,1)\nac(:)=x(:,3)-x(:,1)\nap(:)=p(:)-x(:,1)\n\noutnorm(1)=ab(2)*ac(3)-ab(3)*ac(2)\noutnorm(2)=-ab(1)*ac(3)+ab(3)*ac(1)\noutnorm(3)=ab(1)*ac(2)-ab(2)*ac(1)\n\narea=outnorm(1)**2+outnorm(2)**2+outnorm(3)**2\narea=0.5*sqrt(area)\n\ndot_pro=ap(1)*outnorm(1)+ap(2)*outnorm(2)+ap(3)*outnorm(3)\n\nif (dot_pro > 0) then\noutnorm(:)=-outnorm(:)\nend if\n\noutnorm(:)=outnorm(:)/area*0.5\n\ncontinue\n\nend\n\n", "meta": {"hexsha": "20250ba7a1a9d3f0c5b38f99e790ac84f24a6e5c", "size": 744, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "outnormal_tet.f90", "max_stars_repo_name": "biofluids/IFEM-archive", "max_stars_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-15T11:40:16.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-15T11:40:16.000Z", "max_issues_repo_path": "outnormal_tet.f90", "max_issues_repo_name": "biofluids/IFEM-archive", "max_issues_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "outnormal_tet.f90", "max_forks_repo_name": "biofluids/IFEM-archive", "max_forks_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-02-11T16:50:21.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-08T07:24:59.000Z", "avg_line_length": 19.0769230769, "max_line_length": 71, "alphanum_fraction": 0.6196236559, "num_tokens": 311, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.953275044028802, "lm_q2_score": 0.7057850278370112, "lm_q1q2_score": 0.6728072534861962}} {"text": "program NN\n implicit none\n real :: inputs(4),weights1(4),weights2(4),weights3(4),bias1,bias2,bias3,output(3)\n\n inputs = [ 1.0 , 2.0 , 3.0 , 2.5 ]\n weights1 = [ 0.2 , 0.8 , -0.5 , 1.0 ]\n weights2 = [ 0.5 , -0.91, 0.26, -0.5 ]\n weights3 = [-0.26, -0.27, 0.17, 0.87]\n bias1 = 2\n bias2 = 3\n bias3 = 0.5\n\n output = [inputs(1) * weights1(1) +&\n inputs(2) * weights1(2) +&\n inputs(3) * weights1(3) +&\n inputs(4) * weights1(4) +&\n bias1,&\n inputs(1) * weights2(1) +&\n inputs(2) * weights2(2) +&\n inputs(3) * weights2(3) +&\n inputs(4) * weights2(4) +&\n bias2,&\n inputs(1) * weights3(1) +&\n inputs(2) * weights3(2) +&\n inputs(3) * weights3(3) +&\n inputs(4) * weights3(4) +&\n bias3] \n\n print *,output(1),output(2),output(3)\nend program NN\n", "meta": {"hexsha": "0f075d62fb93450480afc79fe3bbe9243f13885d", "size": 962, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran/p002-Basic-Neuron-Layer.f90", "max_stars_repo_name": "yarikbratashchuk/NNfSiX", "max_stars_repo_head_hexsha": "6ea56e3187d3742752c8cbef1bf30d8cf91bfe09", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1045, "max_stars_repo_stars_event_min_datetime": "2020-04-16T20:11:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T14:33:49.000Z", "max_issues_repo_path": "Fortran/p002-Basic-Neuron-Layer.f90", "max_issues_repo_name": "yarikbratashchuk/NNfSiX", "max_issues_repo_head_hexsha": "6ea56e3187d3742752c8cbef1bf30d8cf91bfe09", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 87, "max_issues_repo_issues_event_min_datetime": "2020-04-17T02:36:52.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-15T01:04:27.000Z", "max_forks_repo_path": "Fortran/p002-Basic-Neuron-Layer.f90", "max_forks_repo_name": "yarikbratashchuk/NNfSiX", "max_forks_repo_head_hexsha": "6ea56e3187d3742752c8cbef1bf30d8cf91bfe09", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 359, "max_forks_repo_forks_event_min_datetime": "2020-04-16T21:41:30.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-28T10:23:47.000Z", "avg_line_length": 31.0322580645, "max_line_length": 85, "alphanum_fraction": 0.4355509356, "num_tokens": 367, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.953275045356249, "lm_q2_score": 0.7057850154599562, "lm_q1q2_score": 0.6728072426243507}} {"text": " function planckfn(lambda,T)\n\n! Calculate intensity [Jy/arcsec^2] at wavelength lambda [microns] of\n! optically thick source of temperature T [K].\n!\n! Restriction: lambda*T > 200\n\n real, intent(in) :: lambda ! wavelength [microns] \n real, intent(in) :: T ! temperature [K] \n\n planckfn = (977.532/lambda)**3/(exp(14401.9/(lambda*T)) - 1.)\n\n end function planckfn\n", "meta": {"hexsha": "0da4714a467a8b9c7dff9b29317abcb5ce9ccba5", "size": 433, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "planckfn.f90", "max_stars_repo_name": "teuben/ppmap", "max_stars_repo_head_hexsha": "2ff0b07350f883ee34ff4acc5eab374cdde8d327", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2018-05-31T16:15:35.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-12T14:22:57.000Z", "max_issues_repo_path": "planckfn.f90", "max_issues_repo_name": "teuben/ppmap", "max_issues_repo_head_hexsha": "2ff0b07350f883ee34ff4acc5eab374cdde8d327", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-09-05T20:28:54.000Z", "max_issues_repo_issues_event_max_datetime": "2018-09-05T20:28:54.000Z", "max_forks_repo_path": "planckfn.f90", "max_forks_repo_name": "teuben/ppmap", "max_forks_repo_head_hexsha": "2ff0b07350f883ee34ff4acc5eab374cdde8d327", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-05-31T16:15:28.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-07T16:35:39.000Z", "avg_line_length": 30.9285714286, "max_line_length": 73, "alphanum_fraction": 0.5773672055, "num_tokens": 124, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9532750413739076, "lm_q2_score": 0.7057850154599563, "lm_q1q2_score": 0.6728072398136739}} {"text": "SUBROUTINE mocouf(phi,c,sigm,dsbar,theta,f)\r\n!\r\n! This subroutine calculates the value of the yield function\r\n! for a Mohr-Coulomb material (phi in degrees).\r\n!\r\n IMPLICIT NONE\r\n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\r\n REAL(iwp),INTENT(IN)::phi,c,sigm,dsbar,theta \r\n REAL(iwp),INTENT(OUT)::f\r\n REAL(iwp)::phir,snph,csph,csth,snth,one=1.0_iwp,d3=3.0_iwp,d4=4.0_iwp, &\r\n d180=180.0_iwp\r\n phir=phi*d4*ATAN(one)/d180\r\n snph=SIN(phir) \r\n csph=COS(phir) \r\n csth=COS(theta)\r\n snth=SIN(theta)\r\n f=snph*sigm+dsbar*(csth/SQRT(d3)-snth*snph/d3)-c*csph\r\nRETURN\r\nEND SUBROUTINE mocouf\r\n", "meta": {"hexsha": "a1b3449225547ea860f8cc9bad91629a6ea21c01", "size": 587, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "src/libs/main/mocouf.f03", "max_stars_repo_name": "leemargetts/PoreFEM", "max_stars_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/libs/main/mocouf.f03", "max_issues_repo_name": "leemargetts/PoreFEM", "max_issues_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/libs/main/mocouf.f03", "max_forks_repo_name": "leemargetts/PoreFEM", "max_forks_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.35, "max_line_length": 76, "alphanum_fraction": 0.7069846678, "num_tokens": 231, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9621075701109193, "lm_q2_score": 0.6992544210587585, "lm_q1q2_score": 0.6727579719341598}} {"text": "! Like array_constructor_6.f90, but check constructors that apply\n! an elemental function to an array.\n! { dg-do run }\nprogram main\n implicit none\n call build (200)\ncontains\n subroutine build (order)\n integer :: order, i\n\n call test (order, (/ (abs ((/ i, -i, -i * 2 /)), i = 1, order) /))\n call test (order, abs ((/ ((/ -i, -i, i * 2 /), i = 1, order) /)))\n call test (order, (/ abs ((/ ((/ i, i, -i * 2 /), i = 1, order) /)) /))\n end subroutine build\n\n subroutine test (order, values)\n integer, dimension (3:) :: values\n integer :: order, i\n\n if (size (values, dim = 1) .ne. order * 3) STOP 1\n do i = 1, order\n if (values (i * 3) .ne. i) STOP 2\n if (values (i * 3 + 1) .ne. i) STOP 3\n if (values (i * 3 + 2) .ne. i * 2) STOP 4\n end do\n end subroutine test\nend program main\n", "meta": {"hexsha": "a1e55384c5c3ef6fd2ffdca39c929ee1293155e5", "size": 823, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/array_constructor_10.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/array_constructor_10.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/array_constructor_10.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": 29.3928571429, "max_line_length": 75, "alphanum_fraction": 0.5552855407, "num_tokens": 297, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199714402812, "lm_q2_score": 0.803173791645582, "lm_q1q2_score": 0.6727544084197548}} {"text": "module fqs_fake_kine\n\n use fqs_types, only: wp\n use fqs_constants, only: pi\n use fqs_euler_angle, only: euler_t\n use fqs_utility, only: deg2rad\n\n implicit none\n\n type, public :: fake_kine_param_t\n real(wp) :: phi_amplitude = 0.0_wp\n real(wp) :: alpha_amplitude = 0.0_wp\n real(wp) :: alpha_slope = 0.0_wp\n real(wp) :: alpha_overshoot_size = 0.0_wp\n real(wp) :: alpha_overshoot_power = 0.0_wp\n real(wp) :: theta_amplitude = 10.0_wp\n real(wp) :: theta_power = 0.0_wp\n real(wp) :: period = 0.0_wp\n end type fake_kine_param_t\n\n public fake_kine_period\n public fake_param_type_1\n public fake_param_type_2\n public fake_param_type_3\n public fake_param_type_4\n public fake_kine\n real(wp), parameter :: fake_kine_period = 0.005_wp\n\n\ncontains\n\n subroutine fake_kine(t, euler, param)\n real(wp), intent(in) :: t(:)\n type(euler_t), intent(out) :: euler(:)\n type(fake_kine_param_t), intent(in), optional :: param\n\n ! Local variables\n type(fake_kine_param_t) :: param_tmp\n real(wp) :: cos_tmp(size(t))\n real(wp) :: sin_tmp(size(t))\n real(wp) :: attitude_erf(size(t))\n real(wp) :: attitude_base(size(t))\n real(wp) :: attitude_overshoot(size(t))\n\n if (present(param)) then\n param_tmp = param\n else\n param_tmp = fake_param_type_4()\n end if\n\n cos_tmp = cos( 2.0_wp*pi*t/(param_tmp % period) )\n sin_tmp = sin( 2.0_wp*pi*t/(param_tmp % period) )\n\n attitude_base = (param_tmp % alpha_amplitude) * erf( (param_tmp % alpha_slope) * sin_tmp ) \n attitude_overshoot = sign(1.0_wp,cos_tmp)*(abs(cos_tmp) ** (param_tmp % alpha_overshoot_power))\n attitude_overshoot = (param_tmp % alpha_overshoot_size)*attitude_overshoot\n\n euler % heading = (param_tmp % phi_amplitude) * cos_tmp\n euler % attitude = attitude_base + attitude_overshoot \n euler % bank = (param_tmp % theta_amplitude) * abs( cos_tmp ) ** (param_tmp % theta_power ) \n\n end subroutine fake_kine\n\n\n function fake_param_type_1() result(param)\n type(fake_kine_param_t) :: param\n param % phi_amplitude = deg2rad(70.0_wp)\n param % alpha_amplitude = deg2rad(50.0_wp)\n param % alpha_slope = 3.0_wp\n param % alpha_overshoot_size = deg2rad(0.0_wp)\n param % alpha_overshoot_power = 12.0_wp\n param % theta_amplitude = deg2rad(0.0_wp)\n param % theta_power = 10.0_wp\n param % period = fake_kine_period \n end function fake_param_type_1\n\n\n function fake_param_type_2() result(param)\n type(fake_kine_param_t) :: param\n param % phi_amplitude = deg2rad(70.0_wp)\n param % alpha_amplitude = deg2rad(50.0_wp)\n param % alpha_slope = 3.0_wp\n param % alpha_overshoot_size = deg2rad(0.0_wp)\n param % alpha_overshoot_power = 12.0_wp\n param % theta_amplitude = deg2rad(10.0_wp)\n param % theta_power = 10.0_wp\n param % period = fake_kine_period \n end function fake_param_type_2\n\n\n function fake_param_type_3() result(param)\n type(fake_kine_param_t) :: param\n param % phi_amplitude = deg2rad(70.0_wp)\n param % alpha_amplitude = deg2rad(50.0_wp)\n param % alpha_slope = 3.0_wp\n param % alpha_overshoot_size = deg2rad(30.0_wp)\n param % alpha_overshoot_power = 12.0_wp\n param % theta_amplitude = deg2rad(0.0_wp)\n param % theta_power = 10.0_wp\n param % period = fake_kine_period \n end function fake_param_type_3\n\n \n function fake_param_type_4() result(param)\n type(fake_kine_param_t) :: param\n param % phi_amplitude = deg2rad(70.0_wp)\n param % alpha_amplitude = deg2rad(50.0_wp)\n param % alpha_slope = 3.0_wp\n param % alpha_overshoot_size = deg2rad(30.0_wp)\n param % alpha_overshoot_power = 12.0_wp\n param % theta_amplitude = deg2rad(10.0_wp)\n param % theta_power = 10.0_wp\n param % period = fake_kine_period \n end function fake_param_type_4\n\nend module fqs_fake_kine\n", "meta": {"hexsha": "87f31737b6f6932eb46c659965e92b5c17a5f597", "size": 4266, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fqs_fake_kine.f90", "max_stars_repo_name": "willdickson/fqs-aero", "max_stars_repo_head_hexsha": "5086144550548657859796ab51dd0b312b641daa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-06-23T06:07:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-23T06:07:50.000Z", "max_issues_repo_path": "src/fqs_fake_kine.f90", "max_issues_repo_name": "willdickson/fqs-aero", "max_issues_repo_head_hexsha": "5086144550548657859796ab51dd0b312b641daa", "max_issues_repo_licenses": ["MIT"], "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/fqs_fake_kine.f90", "max_forks_repo_name": "willdickson/fqs-aero", "max_forks_repo_head_hexsha": "5086144550548657859796ab51dd0b312b641daa", "max_forks_repo_licenses": ["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.4615384615, "max_line_length": 103, "alphanum_fraction": 0.6223628692, "num_tokens": 1211, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418199787564, "lm_q2_score": 0.7279754548076477, "lm_q1q2_score": 0.6727525617058024}} {"text": "c=======================================================================\nc\nc subroutine RISKBUDGETIT Index Tracking \nc\nc Risk Budgeting allocation strategy (Index Tracking constraints)\nc\nc Max[ w'*rho -kappa(1/2*w'*Gamma*w-Covb*w]\nc s.t. \nc sqrt[(w-w_b)'*Gamma_i*(w-w_b)] <= sigma(i)**2-var_bench+w_b'*Gamma_i*w_b (volatility constraint)\nc C*w <= b (linear constraints) \nc Cinf <= w <= Csup (lower/upper bounds)\nc\nc w : portfolio weights\nc Q : covariance matrix\nc rho : assets performance \nc\nc-----------------------------------------------------------------------\n SUBROUTINE riskbudgetit ( n, cov, kappa, rho, covb, varb, neq,\n & nin, ccst, bcst, cinf, csup,\n & nbc, class, sigma,\n & iwork, dwork,\n & wopt, lambda, info)\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : portfolio size integer\nc cov : covariance matrix (n*n) double\nc rho : expected returns vector (n) double\nc covb : covariance assets-index (n) double\nc varb : variance of the benchmark double\nc neq : number equality constraints integer\nc nin : number inequality constraints integer\nc ccst : matrix of constraints (nasset*(neq+nin)) double\nc bcst : vector initial of constraints (neq+nin) double\nc cinf : lower bound (n) double\nc csup : upper bound (n) double\nc nbc : number of risk budgeting constraints (>=1) integer \nc class : block definition (n) integer\nc sigma : volatilities budgets constraints (nbc) double \nc\nc WORKSPACE \nc iwork : 3*nbc + 17*n + neq + 2*nin + 12 integer \nc dwork : nbc*(nbc+25)/2+n*(13*n+53+2*neq\nc +2*nin)+6*neq+8*nin+14 double\nc\nc OUTPUT \nc wopt : optimal portfolio (n) double \nc lambda : optimal lambda (nbc)\nc info : diagnostic argument integer\nc\nc CALL \nc \nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\nc\n EXTERNAL simmvol, gesterr\nc\nc arguments i/o\n INTEGER n, info, neq, nin, nbc\n INTEGER class(*)\n DOUBLE PRECISION cov(*), rho(*), covb(*), varb, cinf(*), csup(*)\n DOUBLE PRECISION ccst(n,*), bcst(*), wopt(*), sigma(*), lambda(*)\n DOUBLE PRECISION kappa\nc\nc workspaces\n INTEGER iwork(*)\n DOUBLE PRECISION dwork(*)\nc\nc Local Variables\nc \n double precision kappa2, scal, scal2, dzero, epsil\n \n integer pdQ, pdrhoIT, pdbcstIT, pdcinfIT, pdcsupIT, pdsigmaIT\n integer pdomegab, pdw, pdwalloc, pdwoptIT, pdcov, pdcov1\n \n integer piw, piwalloc\n \n integer iosort, infot, i, j, npk\n iosort = 6\n \n pdQ = 1\nc needs n*n\nc \n \n pdomegab = pdQ + n*n\nc needs n\nc \n pdrhoIT = pdomegab + n\nc needs n\nc so n*n+2*n\n pdbcstIT = pdrhoIT + n\nc needs neq + nineq\nc so n*n+2*n + neq + nineq\n pdcinfIT = pdbcstIT + neq + nin\nc needs n \nc so n*n+3*n + neq + nineq\n pdcsupIT = pdcinfIT + n\nc needs n \nc so n*n+4*n + neq + nineq \n pdsigmaIT = pdcsupIT + n\nc needs nbc\nc so n*n+4*n + neq + nineq + nbc\n pdwoptIT = pdsigmaIT + nbc\nc needs n \nc so n*n+5*n + neq + nineq + nbc\n pdw = pdwoptIT + n\nc needs n*(4*n+28) + nbc + nineq + neq\nc so n*n+n*(5*n+33) + 2*(nbc + nineq + neq)\n pdwalloc = pdw + n*(4*n+28) + nbc + nin + neq\nc needs nbc*(nbc+21)/2 + \nc n*n+n*(8*n+20+2*neq+2*nin)+4*neq+6*nin+14\nc\nc so nbc*(nbc+25)/2+n*(14*n+53+2*neq+2*nin)+6*neq+8*nin+14\n pdcov = pdwalloc \nc needs n*n\nc \n pdcov1 = pdcov + n*n\nc needs n*n\nc\n \n piw = 1\nc needs 12*n + nbc \nc\n piwalloc = piw + 12*n + nbc \nc needs 2*nbc + 5*n + neq + 2*nin + 12 \nc so 3*nbc + 17*n + neq + 2*nin + 12\n call buildrbit(n, cov, kappa, rho, covb, varb, \n & neq, nin, ccst, bcst, cinf, csup, nbc, class, sigma, \n & iwork(piw), dwork(pdw), dwork(pdomegab), dwork(pdrhoIT), \n & dwork(pdbcstIT), dwork(pdcinfIT), dwork(pdcsupIT), \n & dwork(pdsigmaIT), info)\n if (info .LT. 0) then\n return\n endif \n kappa2 = kappa/2\n\n \n call ym(n, n, cov, dwork(pdQ))\n call allocrb ( n, cov, dwork(pdQ), kappa2, dwork(pdrhoIT),\n & neq, nin,\n & ccst, dwork(pdbcstIT),\n & dwork(pdcinfIT), dwork(pdcsupIT),\n & nbc, class, dwork(pdsigmaIT),\n & iwork(piwalloc), dwork(pdwalloc),\n & dwork(pdwoptIT), lambda, info)\n call SV(n, dwork(pdwoptIT), dwork(pdomegab), wopt)\n if (info .eq. 1001) then\n info = -101\n return\n endif \nc\nc building cov. matrix with optimal dual solution\n DO i = 1,nbc\nc \n DO j = 1,n\n iwork(piwalloc + i - 1) = 0\n ENDDO\nc CALL IVX ( n, iwork(piwbf), ZERO ) ! initialize piwbf\nc\nc dimension of block i\n epsil = 1.e-8\n dzero = 0.\n npk = 0\n DO j = 1,n\n IF (class(j) .EQ. i) THEN\n npk = npk + 1\n iwork(piwalloc + npk - 1) = j\n ENDIF\n ENDDO\n IF (npk .GT. 1) THEN\nc\nc initialize temporary cov. matrix \n CALL IMX ( npk, npk, dwork(pdcov1), dzero) \n CALL IMX ( n, n, dwork(pdcov), dzero) \nc \nc extract block i\n CALL YMCPI(n, cov, npk, iwork(piwalloc), dwork(pdcov1)\n & , infot)\nc\nc sub-block -> cov. matrix\n CALL YMCPIR (npk, dwork(pdcov1), n, iwork(piwalloc),\n & dwork(pdcov), infot)\nc\nc optimal portfolio variance: w'*Cov*w \n CALL OVTMCV(n, cov, dwork(pdwoptIT), scal)\n IF (scal .GT. (dwork(pdsigmaIT+i-1)**2+epsil)) THEN\n info = -120\n RETURN\n ENDIF\n CALL OVTMCV(n, cov, wopt, scal)\n CALL XV(n, wopt, covb, scal2) \n IF (scal .gt. (sigma(i)**2+2*scal2-varb+epsil)) THEN\n info = -120\n RETURN\n ENDIF\n ENDIF\n ENDDO \n RETURN\n END\n", "meta": {"hexsha": "6fbb592d9d43e0a37a336e7025383655c94ee857", "size": 6823, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/optim_portfolio/riskbudgetit.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/optim_portfolio/riskbudgetit.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/optim_portfolio/riskbudgetit.f", "max_forks_repo_name": "alpgodev/numx", "max_forks_repo_head_hexsha": "d2d3a0713020e1b83b65d3a661c3801ea256aff9", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.9452736318, "max_line_length": 103, "alphanum_fraction": 0.4626996922, "num_tokens": 2120, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418199787563, "lm_q2_score": 0.7279754548076477, "lm_q1q2_score": 0.6727525617058024}} {"text": " subroutine dery_1(q0, q1)\n\n!----------------------------------------------------------- !\n! F. Califano, 2006 !\n! First y-derivative by FFT (periodic boundary conditions) !\n!----------------------------------------------------------- !\n\n!**************************************************\n! MPI PARALLEL VERSION: VALENTINI-FAGANELLO 2009\n!**************************************************\n\nuse parameter_mod\nuse box_mod\nuse deriv_mod\n\nIMPLICIT NONE\n\ninteger :: ik, il\n\nREAL(dp),DIMENSION (ny) :: q0, q1, qq\n\n qq = q0\n\n call drfftf(ny, qq, savey)\n\n il = 1\n do ik = 2, ny1, 2\n q1(ik) = - qq(ik+1) * ky_1(il)\n q1(ik+1) = qq(ik) * ky_1(il)\n il = il + 1\n enddo\n\n q1(1) = 0.0\n q1(ny) = 0.0\n\n call drfftb(ny, q1, savey)\n\nend subroutine\n", "meta": {"hexsha": "9cdd53c0d8847fa69e014e88a472451f871ae708", "size": 875, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "dery_1.f90", "max_stars_repo_name": "sscerr/eTF", "max_stars_repo_head_hexsha": "31dea18c7b24b3ebbb6bdfea98467ffbf79f0852", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-02T04:11:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-02T04:11:49.000Z", "max_issues_repo_path": "dery_1.f90", "max_issues_repo_name": "sscerr/eTF", "max_issues_repo_head_hexsha": "31dea18c7b24b3ebbb6bdfea98467ffbf79f0852", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "dery_1.f90", "max_forks_repo_name": "sscerr/eTF", "max_forks_repo_head_hexsha": "31dea18c7b24b3ebbb6bdfea98467ffbf79f0852", "max_forks_repo_licenses": ["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.4358974359, "max_line_length": 62, "alphanum_fraction": 0.368, "num_tokens": 247, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418158002492, "lm_q2_score": 0.7279754548076477, "lm_q1q2_score": 0.6727525586639518}} {"text": "!-------------------------------------------------------------------------------------------------\n! Fortran source code for module et_ppmd.coref90\n!-------------------------------------------------------------------------------------------------\n! Remarks:\n! . Enter Python documentation for this module in ``./coref90.rst``.\n! You might want to check the f2py output for the interfaces of the C-wrapper functions.\n! It will be autmatically included in the et_ppmd documentation.\n! . Documument the Fortran routines in this file. This documentation will not be included\n! in the et_ppmd documentation (because there is no recent sphinx\n! extension for modern fortran.\n\n! VERBOSE is for debugging purposes\n!#define VERBOSE\n! preprocessor directives must start at the beginning of the line in Fortran code\n\n!-------------------------------------------------------------------------------------------------\nfunction force_factor(rij2)\n ! Compute the force factor. Multiply with the interatomic vector to obtain the force vector.\n implicit none\n !-------------------------------------------------------------------------------------------------\n ! subprogram parameters\n real*8 ,intent(in) ::rij2 ! interatomic distance squqred\n real*8 ::force_factor ! result\n !-------------------------------------------------------------------------------------------------\n ! local variables\n real*8 :: rm2, rm6\n !-------------------------------------------------------------------------------------------------\n rm2 = 1.0/rij2\n rm6 = (rm2*rm2*rm2)\n force_factor = (1.0 - 2.0*rm6)*rm6*rm2*6.0\nendfunction\n\n!-------------------------------------------------------------------------------------------------\nsubroutine computeForces(x,y,vlsz,vlst,fx,fy,n,m)\n ! Compute the forces from the atom positions (x,y) and the Verlet list vl.\n ! See the VerletList class in et_ppmd/verlet.py for an explanation of the\n ! data structure (a 2D integer array.\n !\n implicit none\n !-------------------------------------------------------------------------------------------------\n ! subprogram parameters\n integer*4 , intent(in) :: n ! number of atoms\n integer*4 , intent(in) :: m ! length of the linearized verlet list = total number of pairs\n real*8 , dimension(n), intent(in) :: x,y ! atom positions\n integer*8, dimension(n), intent(in) :: vlsz ! size of the individual Verlet lists\n integer*8, dimension(m), intent(in) :: vlst ! linearized Verlet lists\n real*8 , dimension(n), intent(inout) :: fx,fy ! atom forces\n ! intent is inout because we do not want to return an array to avoid needless copying\n !-------------------------------------------------------------------------------------------------\n ! local variables\n integer*4 :: i,nb0,nb,j\n integer*4 :: n_neighbours_i\n real*8 :: xij,yij,rij2,ff,ffx,ffy,force_factor\n !------------------------------------------------------------------------------------------------\n ! Zero the forces\n do i=1,n\n fx(i) = 0.0\n end do\n do i=1,n\n fy(i) = 0.0\n end do\n#if defined VERBOSE\n do i=1,m\n write (*,*) vlst(i)\n end do\n#endif\n ! Compute the interatomic forces and add them to fx and fy\n nb0 = 0 ! offset of verlet list of atom i in the linearized verlet list\n ! Note that Fortran indexes arrays counting from 1 to n, whereas Python, C and C++\n ! count from 0 to n-1.\n do i=1,n\n#if defined VERBOSE\n write (*,*) 'coref90:','nb0=',nb0\n#endif\n n_neighbours_i = vlsz(i)\n do nb = nb0+1, nb0+n_neighbours_i\n#if defined VERBOSE\n write (*,*) 'coref90:','nb=',nb\n#endif\n j = vlst(nb) + 1 ! + 1 since Fortran starts counting at 1, and the python atom indices are 0-based\n#if defined VERBOSE\n write (*,*) 'coref90:',i,nb,j\n#endif\n xij = x(j) - x(i)\n yij = y(j) - y(i)\n rij2 = xij*xij + yij*yij\n ff = force_factor(rij2)\n ffx = ff*xij\n ffy = ff*yij\n fx(i) = fx(i) + ffx\n fy(i) = fy(i) + ffy\n fx(j) = fx(j) - ffx\n fy(j) = fy(j) - ffy\n end do\n nb0 = nb0 + n_neighbours_i\n end do\nend subroutine computeForces\n\n!-------------------------------------------------------------------------------------------------\nsubroutine velocity_verlet_12(dt,rx,ry,vx,vy,ax,ay,vx_midstep,vy_midstep,n)\n ! Compute the forces from the atom positions (x,y) and the Verlet list vl.\n ! See the VerletList class in et_ppmd/verlet.py for an explanation of the\n ! data structure (a 2D integer array.\n !\n implicit none\n !-------------------------------------------------------------------------------------------------\n ! subprogram parameters\n real*8 , intent(in) :: dt ! timestep\n integer*4 , intent(in) :: n ! number of atoms\n real*8 , dimension(n), intent(inout) :: rx,ry ! atom positions\n real*8 , dimension(n), intent(in) :: vx,vy ! atom velocities\n real*8 , dimension(n), intent(in) :: ax,ay ! atom accelerations\n real*8 , dimension(n), intent(inout) :: vx_midstep,vy_midstep ! midstep atom velocities\n !-------------------------------------------------------------------------------------------------\n ! local variables\n integer*4 :: i\n real*8 :: halfstep\n !------------------------------------------------------------------------------------------------\n ! Step 1: compute velocities at midstep (t+dt/2) using the current accelerations:\n ! self.vx_midstep = self.vx + (0.5*dt)*self.ax\n ! self.vy_midstep = self.vy + (0.5*dt)*self.ay\n ! Step 2: compute positions at next step (t+dt) using the midstep velocities:\n ! self.rx += self.vx_midstep*dt\n ! self.ry += self.vy_midstep*dt\n ! first all work on x components, then on y-components\n\n halfstep = 0.5*dt;\n\n do i=1,n\n vx_midstep(i) = vx(i) + halfstep*ax(i)\n rx(i) = rx(i)+ vx_midstep(i) * dt\n end do\n\n do i=1,n\n vy_midstep(i) = vy(i) + halfstep*ay(i)\n ry(i) = ry(i) + vy_midstep(i) * dt\n end do\n\nend subroutine velocity_verlet_12\n\n!-------------------------------------------------------------------------------------------------\nsubroutine velocity_verlet_4(dt,rx,ry,vx,vy,ax,ay,vx_midstep,vy_midstep,n)\n ! Compute the forces from the atom positions (x,y) and the Verlet list vl.\n ! See the VerletList class in et_ppmd/verlet.py for an explanation of the\n ! data structure (a 2D integer array.\n !\n implicit none\n !-------------------------------------------------------------------------------------------------\n ! subprogram parameters\n real*8 , intent(in) :: dt ! timestep\n integer*4 , intent(in) :: n ! number of atoms\n real*8 , dimension(n), intent(in) :: rx,ry ! atom positions\n real*8 , dimension(n), intent(inout) :: vx,vy ! atom velocities\n real*8 , dimension(n), intent(in) :: ax,ay ! atom accelerations\n real*8 , dimension(n), intent(in) :: vx_midstep,vy_midstep ! midstep atom velocities\n !-------------------------------------------------------------------------------------------------\n ! local variables\n integer*4 :: i\n real*8 :: halfstep\n !------------------------------------------------------------------------------------------------\n ! Step 4: compute velocities at next step (t+dt)\n ! \tself.vx = self.vx_midstep + self.ax * (0.5*dt)\n ! \tself.vy = self.vy_midstep + self.ay * (0.5*dt)\n\n halfstep = 0.5*dt\n \n do i=1,n\n vx(i) = vx_midstep(i) + halfstep*ax(i)\n end do\n\n do i=1,n\n vy(i) = vy_midstep(i) + halfstep*ay(i);\n end do\n\nend subroutine velocity_verlet_4\n", "meta": {"hexsha": "b72699f5a16ff9f5b40b9b1a3d67b8eb1783673c", "size": 7803, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "et_ppmd/f90_coref90/coref90.f90", "max_stars_repo_name": "etijskens/et_ppmd", "max_stars_repo_head_hexsha": "0efb580bc727405ebdd7c68b03e876ebf2f1c74b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-22T15:19:37.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-22T15:19:37.000Z", "max_issues_repo_path": "et_ppmd/f90_coref90/coref90.f90", "max_issues_repo_name": "etijskens/et_ppmd", "max_issues_repo_head_hexsha": "0efb580bc727405ebdd7c68b03e876ebf2f1c74b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "et_ppmd/f90_coref90/coref90.f90", "max_forks_repo_name": "etijskens/et_ppmd", "max_forks_repo_head_hexsha": "0efb580bc727405ebdd7c68b03e876ebf2f1c74b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-04-05T09:00:53.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-05T09:00:53.000Z", "avg_line_length": 44.3352272727, "max_line_length": 114, "alphanum_fraction": 0.4775086505, "num_tokens": 1913, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418137109955, "lm_q2_score": 0.7279754548076477, "lm_q1q2_score": 0.6727525571430264}} {"text": "! MODULE PRANA\n! Generate a random proper rotation (orthogonal) matrix. \n!\n! The procedure is to fill a square matrix of desired order with independent\n! Gaussian random numbers, then to apply Gram-Schmidt orthonormalization.\n! The \"4.... goto 4\" loop allows for reiteration in the very rare case that\n! the initial random matrix is (to within round-off) essentially singular.\n! The final `coin toss' randomization of orientation of each column along\n! the line it lies along overcomes what would otherwise be a bias that\n! comes from the way the gram-schmidt code works. The even number of reversals\n! ensures the preservation of the determinant.\n!=============================================================================\nmodule prana\n!=============================================================================\nuse pran; use peuc\nimplicit none\nprivate\npublic:: ranrot\ninterface ranrot; module procedure ranrot_s,ranrot_d; end interface\n\ncontains\n\n!=============================================================================\nsubroutine ranrot_s(a)\n!=============================================================================\nreal(4),dimension(:,:),intent(OUT) :: a\n!-----------------------------------------------------------------------------\ninteger :: n,i,j,nrank,flip\nreal(4),dimension(size(a,1),size(a,1)):: as\nreal(4) :: deter,xran\n!=============================================================================\nn=size(a,1); if(size(a,2)/=n)stop 'In ranrot; incompatible dimensions'\n4 do j=1,n; do i=1,n; call gauss(as(i,j)); enddo; enddo\nprint'(t5,10f7.4)',as\ncall gram(as,a,nrank,deter); if(nrank/=n)goto 4\nprint *, 'nrank=',nrank\nprint'(t5,10f7.4)',a\nflip=1; do j=1,n-1\ncall uniform(xran);if(xran>.5)then; flip=-flip; a(:,j)=-a(:,j); endif\nenddo; a(:,n)=flip*a(:,n)\nprint'(t5,10f7.4)',a\nend subroutine ranrot_s\n\n!=============================================================================\nsubroutine ranrot_d(a)\n!=============================================================================\nreal(8),dimension(:,:),intent(OUT) :: a\n!-----------------------------------------------------------------------------\ninteger :: n,i,j,nrank,flip,k\nreal(8),dimension(size(a,1),size(a,1)):: as\nreal(8) :: deter,xran\n!=============================================================================\nn=size(a,1); if(size(a,2)/=n)stop 'In ranrot; incompatible dimensions'\n4 do j=1,n; do i=1,n; call gauss(as(i,j)); enddo; enddo\n!a=0.0\n!do j=1,n; do i=1,n; do k=1,n; a(i,j)=a(i,j)+as(k,i)*as(k,j); enddo; enddo; enddo\n!print *,'raw'\n!print'(t5,10f7.4)',as\n!print *,'raw variance)'\n!print'(t5,10f7.4)',a\n!a=0.0\ncall gram(as,a,nrank,deter); if(nrank/=n)goto 4\n!as=0.0\n!do j=1,n; do i=1,n; do k=1,n; as(i,j)=as(i,j)+a(k,i)*a(k,j); enddo; enddo; enddo\n!print *, 'nrank=',nrank\n!print *,'after gram'\n!print'(t5,10f7.4)',a\n!print *,'after gram variance)'\n!print'(t5,10f7.4)',as\n!flip=1; do j=1,n-1\n!call uniform(xran);if(xran>.5d0)then; flip=-flip; a(:,j)=-a(:,j); endif\n!enddo; a(:,n)=flip*a(:,n)\n!as=0.0\n!do j=1,n; do i=1,n; do k=1,n; as(i,j)=as(i,j)+a(k,i)*a(k,j); enddo; enddo; enddo\n!print *,'after flipping'\n!print'(t5,10f7.4)',a\n!print *,'after gram variance)'\n!print'(t5,10f7.4)',as\nend subroutine ranrot_d\n\nend module prana\n", "meta": {"hexsha": "566121011a9843f70b75d084fc336c1846d00a93", "size": 3354, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "NEMS/src/ENS_Cpl/prana.f", "max_stars_repo_name": "pvelissariou1/ADC-WW3-NWM-SCHISM-NEMS", "max_stars_repo_head_hexsha": "707ddcd84417211e3a7c92aa15d8cd8ddfa080ab", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NEMS/src/ENS_Cpl/prana.f", "max_issues_repo_name": "pvelissariou1/ADC-WW3-NWM-SCHISM-NEMS", "max_issues_repo_head_hexsha": "707ddcd84417211e3a7c92aa15d8cd8ddfa080ab", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-05-31T15:49:26.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-04T14:17:45.000Z", "max_forks_repo_path": "NEMS/src/ENS_Cpl/prana.f", "max_forks_repo_name": "pvelissariou1/ADC-WW3-NWM-SCHISM-NEMS", "max_forks_repo_head_hexsha": "707ddcd84417211e3a7c92aa15d8cd8ddfa080ab", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-01T09:29:46.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-01T09:29:46.000Z", "avg_line_length": 40.9024390244, "max_line_length": 81, "alphanum_fraction": 0.4958258795, "num_tokens": 948, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418199787564, "lm_q2_score": 0.7279754430043072, "lm_q1q2_score": 0.6727525507978419}} {"text": "subroutine calc_distance (np, nd, pos, i, j, rij, d, d2)\n!\n! Calculate Distance vector, scalar distance and trucated distance\n! between atoms i and j.\n! The distance is truncated at pi/2\n!\n implicit none\n integer(kind=4),intent(in) :: np ! number of particles\n integer(kind=4),intent(in) :: nd ! number of dimensions\n real(kind=8),intent(in),dimension(nd,np) :: pos ! positions\n integer(kind=4),intent(in) :: i ! index particle I\n integer(kind=4),intent(in) :: j ! index particle J\n real(kind=8),intent(out),dimension(nd) :: rij ! distance vector\n real(kind=8),intent(out) :: d ! distance\n real(kind=8),intent(out) :: d2 ! trucated distance\n\n real ( kind = 8 ), parameter :: PI2 = 3.141592653589793D+00 / 2.0D+00\n\n rij(1:nd) = pos(1:nd,i) - pos(1:nd,j)\n\n d = sqrt ( sum ( rij(1:nd)**2 ) )\n\n ! Truncate the distance:\n d2 = min ( d, PI2 )\nend subroutine calc_distance\n", "meta": {"hexsha": "b7950200a931d85cd00e5f26fe0190881651bd03", "size": 1011, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/sub_calc_distance.f90", "max_stars_repo_name": "ostueker/Example_Fortran", "max_stars_repo_head_hexsha": "1a502407ba3a1ad543d15b72c6c493442efa35f9", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-11-13T19:26:12.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-13T19:26:12.000Z", "max_issues_repo_path": "src/sub_calc_distance.f90", "max_issues_repo_name": "ostueker/Example_Fortran", "max_issues_repo_head_hexsha": "1a502407ba3a1ad543d15b72c6c493442efa35f9", "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": "src/sub_calc_distance.f90", "max_forks_repo_name": "ostueker/Example_Fortran", "max_forks_repo_head_hexsha": "1a502407ba3a1ad543d15b72c6c493442efa35f9", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-12-30T09:30:56.000Z", "max_forks_repo_forks_event_max_datetime": "2018-12-30T09:30:56.000Z", "avg_line_length": 38.8846153846, "max_line_length": 74, "alphanum_fraction": 0.5776458952, "num_tokens": 296, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361700013356, "lm_q2_score": 0.7371581741774411, "lm_q1q2_score": 0.6726097811316418}} {"text": "C # This returns a unit square map in [-1,1]x[-1,1]\n subroutine mapc2m_fivepatch(blockno,xc,yc,xp,yp,zp,alpha)\n implicit none\n\n integer blockno\n double precision xc,yc,xp,yp,zp,alpha, xc_in, yc_in\n double precision xc1, yc1\n\n if (blockno .eq. 2) then\n xp = (2*xc-1)*alpha\n yp = (2*yc-1)*alpha\n else\n if (blockno .eq. 0) then\n xc1 = xc\n yc1 = 1-yc\n call bilinear_help(alpha,xc1,yc1,xp,yp)\n yp = -yp\n elseif (blockno .eq. 1) then\n xc1 = yc\n yc1 = 1 -xc\n call bilinear_help(alpha,xc1,yc1,yp,xp)\n xp = -xp\n elseif (blockno .eq. 3) then\n xc1 = yc\n yc1 = xc\n call bilinear_help(alpha,xc1,yc1,yp,xp)\n elseif (blockno .eq. 4) then\n xc1 = xc\n yc1 = yc\n call bilinear_help(alpha,xc1,yc1,xp,yp)\n else\n write(6,'(A,I5)') 'mapc2m_fivepatch.f : blockno = ', blockno\n stop\n endif\n endif\n zp = 0\n end\n\n subroutine bilinear_help(alpha,xi,eta,xp,yp)\n implicit none\n\n double precision alpha, xi, eta, xp,yp\n\n double precision corner(4,2)\n double precision a(2),u1(2),v1(2),v2(2), pt(2)\n integer m\n\n corner(1,1) = -alpha\n corner(4,1) = alpha\n corner(3,1) = 1\n corner(2,1) = -1\n\n corner(1,2) = alpha\n corner(4,2) = alpha\n corner(3,2) = 1\n corner(2,2) = 1\n\n do m = 1,2\n a(m) = corner(1,m)\n u1(m) = corner(4,m) - corner(1,m)\n v1(m) = corner(2,m) - corner(1,m)\n v2(m) = corner(3,m) - corner(4,m)\n enddo\n\n do m = 1,2\n pt(m) = a(m) + u1(m)*xi + v1(m)*eta + (v2(m)-v1(m))*xi*eta\n enddo\n\n xp = pt(1)\n yp = pt(2)\n\n end\n", "meta": {"hexsha": "4265c35156ad91f8a6c60f0b34a67d7cf2e70b65", "size": 1830, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/mappings/fivepatch/mapc2m_fivepatch.f", "max_stars_repo_name": "scivision/forestclaw", "max_stars_repo_head_hexsha": "4dae847a8abd1055e70acda9c2973cd3dd77d3f1", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-09T23:06:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-09T23:06:42.000Z", "max_issues_repo_path": "src/mappings/fivepatch/mapc2m_fivepatch.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/fivepatch/mapc2m_fivepatch.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": 25.0684931507, "max_line_length": 72, "alphanum_fraction": 0.481420765, "num_tokens": 651, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361652391385, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6726097723523972}} {"text": " subroutine iddp_svd(lw,eps,m,n,a,krank,iu,iv,is,w,ier)\nc\nc constructs a rank-krank SVD U Sigma V^T approximating a\nc to precision eps, where U is an m x krank matrix whose\nc columns are orthonormal, V is an n x krank matrix whose\nc columns are orthonormal, and Sigma is a diagonal krank x krank\nc matrix whose entries are all nonnegative.\nc The entries of U are stored in w, starting at w(iu);\nc the entries of V are stored in w, starting at w(iv).\nc The diagonal entries of Sigma are stored in w,\nc starting at w(is). This routine combines a QR code\nc (which is based on plane/Householder reflections)\nc with the LAPACK routine dgesdd.\nc\nc input:\nc lw -- maximum usable length of w (in real*8 elements)\nc eps -- precision to which the SVD approximates a\nc m -- first dimension of a and u\nc n -- second dimension of a, and first dimension of v\nc a -- matrix to be SVD'd\nc\nc output:\nc krank -- rank of the approximation to a\nc iu -- index in w of the first entry of the matrix\nc of orthonormal left singular vectors of a\nc iv -- index in w of the first entry of the matrix\nc of orthonormal right singular vectors of a\nc is -- index in w of the first entry of the array\nc of singular values of a\nc w -- array containing the singular values and singular vectors\nc of a; w doubles as a work array, and so must be at least\nc (krank+1)*(m+2*n+9)+8*min(m,n)+15*krank**2\nc real*8 elements long, where krank is the rank\nc output by the present routine\nc ier -- 0 when the routine terminates successfully;\nc -1000 when lw is too small;\nc other nonzero values when dgesdd bombs\nc\nc _N.B._: This routine destroys a. Also, please beware that\nc the source code for this routine could be clearer.\nc w must be at least \nc (krank+1)*(m+2*n+9)+8*min(m,n)+15*krank**2\nc real*8 elements long, where krank is the rank\nc output by the present routine.\nc\n implicit none\n character*1 jobz\n integer m,n,k,krank,iftranspose,ldr,ldu,ldvt,lwork,\n 1 info,j,ier,io,iu,iv,is,ivi,isi,lw,lu,lv,ls\n real*8 a(m,n),w(*),eps\nc\nc\n io = 8*min(m,n)\nc\nc\n ier = 0\nc\nc\nc Compute a pivoted QR decomposition of a.\nc\n call iddp_qrpiv(eps,m,n,a,krank,w,w(io+1))\nc\nc\n if(krank .gt. 0) then\nc\nc\nc Extract R from the QR decomposition.\nc\n call idd_retriever(m,n,a,krank,w(io+1))\nc\nc\nc Rearrange R according to ind (which is stored in w).\nc\n call idd_permuter(krank,w,krank,n,w(io+1))\nc\nc\nc Use LAPACK to SVD R,\nc storing the krank (krank x 1) left singular vectors\nc in w(io+krank*n+1 : io+krank*n+krank*krank).\nc\n jobz = 'S'\n ldr = krank\n lwork = 2*(3*krank**2+n+4*krank**2+4*krank)\n ldu = krank\n ldvt = krank\nc\n ivi = io+krank*n+krank*krank+lwork+1\n lv = n*krank\nc\n isi = ivi+lv\n ls = krank\nc\n if(lw .lt. isi+ls+m*krank-1) then\n ier = -1000\n return\n endif\nc\n call dgesdd(jobz,krank,n,w(io+1),ldr,w(isi),w(io+krank*n+1),\n 1 ldu,w(ivi),ldvt,w(io+krank*n+krank*krank+1),\n 2 lwork,w,info)\nc\n if(info .ne. 0) then\n ier = info\n return\n endif\nc\nc\nc Transpose w(ivi:ivi+lv-1) to obtain V.\nc\n iv = 1\n call idd_transer(krank,n,w(ivi),w(iv))\nc\nc\nc Copy w(isi:isi+ls-1) into w(is:is+ls-1).\nc\n is = iv+lv\nc\n do k = 1,ls\n w(is+k-1) = w(isi+k-1)\n enddo ! k\nc\nc\nc Multiply the U from R from the left by Q to obtain the U\nc for A.\nc\n iu = is+ls\n lu = m*krank\nc\n do k = 1,krank\nc\n do j = 1,krank\n w(iu-1+j+krank*(k-1)) = w(io+krank*n+j+krank*(k-1))\n enddo ! j\nc\n enddo ! k\nc\n do k = krank,1,-1\nc\n do j = m,krank+1,-1\n w(iu-1+j+m*(k-1)) = 0\n enddo ! j\nc\n do j = krank,1,-1\n w(iu-1+j+m*(k-1)) = w(iu-1+j+krank*(k-1))\n enddo ! j\nc\n enddo ! k\nc\n iftranspose = 0\n call idd_qmatmat(iftranspose,m,n,a,krank,krank,w(iu),\n 1 w(iu+lu+1))\nc\nc\n endif ! krank .gt. 0\nc\nc\n return\n end\nc\nc\nc\nc\n", "meta": {"hexsha": "241326c1002b2ee32ca81e7e2fc941180c8c8a50", "size": 4599, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "contrib/python/scipy/scipy/linalg/src/id_dist/src/idd_svd_subr_1.f", "max_stars_repo_name": "ibr11/catboost", "max_stars_repo_head_hexsha": "842a25b4fb856a61564b163b16a3f49ba35fdc14", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 6989, "max_stars_repo_stars_event_min_datetime": "2017-07-18T06:23:18.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T15:58:36.000Z", "max_issues_repo_path": "contrib/python/scipy/scipy/linalg/src/id_dist/src/idd_svd_subr_1.f", "max_issues_repo_name": "birichie/catboost", "max_issues_repo_head_hexsha": "de75c6af12cf490700e76c22072fbdc15b35d679", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1978, "max_issues_repo_issues_event_min_datetime": "2017-07-18T09:17:58.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T14:28:43.000Z", "max_forks_repo_path": "contrib/python/scipy/scipy/linalg/src/id_dist/src/idd_svd_subr_1.f", "max_forks_repo_name": "birichie/catboost", "max_forks_repo_head_hexsha": "de75c6af12cf490700e76c22072fbdc15b35d679", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1228, "max_forks_repo_forks_event_min_datetime": "2017-07-18T09:03:13.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T05:57:40.000Z", "avg_line_length": 28.2147239264, "max_line_length": 70, "alphanum_fraction": 0.5431615569, "num_tokens": 1496, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361652391385, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6726097723523972}} {"text": "subroutine nif_growth(PO4,PAR,temp,tau,mu,theta)\nuse bio_MOD, only : params, iKPnif, TEMPBOL,Ep\nimplicit none\nreal, intent(in) :: PO4, PAR, temp,tau\nreal, intent(out) :: mu, theta\nreal, parameter :: tau_crit = 0.062 !Critical wind stress (N m-2)\nreal, parameter :: tem_crit = 24.75 !Critical temperature (\u00baC)\nreal, parameter :: aI0 = 0.01 !Initial slope of the P-I curve\nreal, parameter :: mumax = 0.3 !Maximal growth rate of diazotrophs at 15 \u00baC\nreal, parameter :: thetamin = 0.02, thetamax = 0.47\n\n! Amplification factor\nreal :: ampl\nreal :: tf\nreal :: SI ! Light limitation index\nreal :: Kpo4nih = 0.05 !Half-saturation constant for PO4 uptake by nif\n\ntf = TEMPBOL(Ep,temp)\nKpo4nih = params(iKPnif)\n! This subroutine follows Fennel et al. (2002) to incorporate PO4\n! Diatroph growth rates depends on temperature, light, and wind stress\nampl = tanh(2.*(temp - tem_crit)) + 2.\n!if (tau .le. tau_crit) then\n ampl = ampl/3.\n!else\n! ampl = ampl/6.\n!endif\n\n!The light limitation index (SI)\n! Unit of aI0: (W m-2)-1 d-1\nSI = 1d0 - exp(-aI0*PAR/mumax)\nmu = ampl*SI*PO4/(PO4+Kpo4nih)*mumax*tf\n\n!if (mu < 0.) then\n! write(6,*) 'ampl = ', ampl\n! write(6,*) 'SI = ', SI\n! write(6,*) 'LnoP = ', PO4/(PO4+Kpo4nih)\n! stop\n!endif\ntheta = thetamin+mu/PAR/aI0*(thetamax-thetamin) !Unit: gChl/molC\nend subroutine\n", "meta": {"hexsha": "79c9159c1054b52528b070d6d066c097bbe5256f", "size": 1349, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "DRAM/src/nif_growth.f90", "max_stars_repo_name": "BingzhangChen/NPZDFeCONT", "max_stars_repo_head_hexsha": "0083d46dadc4fb8fed8728816755678da8294e16", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "DRAM/src/nif_growth.f90", "max_issues_repo_name": "BingzhangChen/NPZDFeCONT", "max_issues_repo_head_hexsha": "0083d46dadc4fb8fed8728816755678da8294e16", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "DRAM/src/nif_growth.f90", "max_forks_repo_name": "BingzhangChen/NPZDFeCONT", "max_forks_repo_head_hexsha": "0083d46dadc4fb8fed8728816755678da8294e16", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.119047619, "max_line_length": 82, "alphanum_fraction": 0.6627131208, "num_tokens": 512, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.91243616285804, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.672609770597151}} {"text": "module parameters\n implicit none\n\n !! Problem Size\n !! NOTE: Pressure solver only works for hx==hy\n integer, parameter :: nnx = 100\n integer, parameter :: nny = 100\n real, parameter :: lx = 1.0\n real, parameter :: ly = 1.0\n real, parameter :: hx = lx/nnx\n real, parameter :: hy = ly/nny\n real, parameter :: hm = min(hx,hy)\n\n !! Flow Parameters\n real, parameter :: uvel = 4.0\n real, parameter :: dpg = 2.00 ! works well for 10 turbines\n\n !! Time Step and TF\n real, parameter :: cfl = 0.5\n real, parameter :: dt = hm/(3*uvel)*cfl\n real, parameter :: tf = 4.0\n integer, parameter :: nts = tf/dt\n\n !! Pressure solver\n integer, parameter :: niter = 50\n\n !! Saving the files\n integer, parameter :: write_freq = 10000000\n character(*), parameter :: write_dir = './' ! make sure this exists\n\n !! Actuator disk setup\n integer, parameter :: ndisks = 20\n character (len=*), parameter :: adisk_fname = './adisk.txt' ! make sure this exists\n integer, parameter :: r = nnx/32\n real, parameter :: alpha = 0.5\n\n !! Usefull stuff\n real, parameter :: pi=3.14159\n\nend module\n\n", "meta": {"hexsha": "3a6ca1e78793e64dcf81b81a6f617b075dde7815", "size": 1148, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/parameters.f90", "max_stars_repo_name": "wme7/cfd", "max_stars_repo_head_hexsha": "56efea0f7997e029d9f7e19be090f161cf0ab068", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2015-01-25T09:16:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-03T23:42:58.000Z", "max_issues_repo_path": "src/parameters.f90", "max_issues_repo_name": "sAlexander/cfd", "max_issues_repo_head_hexsha": "cad8da9df68ae3287b9d7b96a92eb4921f010e4f", "max_issues_repo_licenses": ["MIT"], "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/parameters.f90", "max_forks_repo_name": "sAlexander/cfd", "max_forks_repo_head_hexsha": "cad8da9df68ae3287b9d7b96a92eb4921f010e4f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-05-12T09:45:55.000Z", "max_forks_repo_forks_event_max_datetime": "2017-12-23T23:39:00.000Z", "avg_line_length": 27.3333333333, "max_line_length": 87, "alphanum_fraction": 0.606271777, "num_tokens": 344, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361509525462, "lm_q2_score": 0.7371581741774411, "lm_q1q2_score": 0.672609767089671}} {"text": " DOUBLE PRECISION FUNCTION slPA (HA, DEC, PHI)\n*+\n* - - -\n* P A\n* - - -\n*\n* HA, Dec to Parallactic Angle (double precision)\n*\n* Given:\n* HA d hour angle in radians (geocentric apparent)\n* DEC d declination in radians (geocentric apparent)\n* PHI d observatory latitude in radians (geodetic)\n*\n* The result is in the range -pi to +pi\n*\n* Notes:\n*\n* 1) The parallactic angle at a point in the sky is the position\n* angle of the vertical, i.e. the angle between the direction to\n* the pole and to the zenith. In precise applications care must\n* be taken only to use geocentric apparent HA,Dec and to consider\n* separately the effects of atmospheric refraction and telescope\n* mount errors.\n*\n* 2) At the pole a zero result is returned.\n*\n* P.T.Wallace Starlink 16 August 1994\n*\n* Copyright (C) 1995 Rutherford Appleton Laboratory\n*\n* License:\n* This program is free software; you can redistribute it and/or modify\n* it under the terms of the GNU General Public License as published by\n* the Free Software Foundation; either version 2 of the License, or\n* (at your option) any later version.\n*\n* This program is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU General Public License for more details.\n*\n* You should have received a copy of the GNU General Public License\n* along with this program (see SLA_CONDITIONS); if not, write to the\n* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,\n* Boston, MA 02110-1301 USA\n*\n* Copyright (C) 1995 Association of Universities for Research in Astronomy Inc.\n*-\n\n IMPLICIT NONE\n\n DOUBLE PRECISION HA,DEC,PHI\n\n DOUBLE PRECISION CP,SQSZ,CQSZ\n\n\n\n CP=COS(PHI)\n SQSZ=CP*SIN(HA)\n CQSZ=SIN(PHI)*COS(DEC)-CP*SIN(DEC)*COS(HA)\n IF (SQSZ.EQ.0D0.AND.CQSZ.EQ.0D0) CQSZ=1D0\n slPA=ATAN2(SQSZ,CQSZ)\n\n END\n", "meta": {"hexsha": "88d211052255ad10de408a9e9f0643f3e6219b25", "size": 2054, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iraf.v2161/math/slalib/pa.f", "max_stars_repo_name": "ysBach/irafdocgen", "max_stars_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:19:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T16:48:42.000Z", "max_issues_repo_path": "math/slalib/pa.f", "max_issues_repo_name": "kirxkirx/iraf", "max_issues_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-30T13:48:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-02T19:40:25.000Z", "max_forks_repo_path": "math/slalib/pa.f", "max_forks_repo_name": "kirxkirx/iraf", "max_forks_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.6, "max_line_length": 80, "alphanum_fraction": 0.676728335, "num_tokens": 585, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147438, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6726097600626598}} {"text": "! ******************************************\n! Integer function CalcH8NablaShape()\n!\n! IN:\n! iElemType(integer): Element type (see hCommon.h)\n! XYZ(float), XI(float), ETA(float), ZETA(float), \n! B(float), DET(float)\n!\n! OUT:\n! nDOFs(integer): Number of DOFs per element\n! nProps(itneger): Number of properties per property type\n!\n! RETURNS:\n! (integer): Number of nodes per element\n!\n! UPDATES:\n! ---\n!\n! PURPOSE:\n! Evaluate the derivatives of the shape functions\n!\n! NOTES:\n! ---\n! ******************************************\nSubroutine CalcH8NablaShape(fXi, fEta, fZeta, faDS)\n\tImplicit None\n\n\tReal, Intent(IN) :: fXi, fEta, fZeta\n\tReal, Intent(OUT) :: faDS(24)\n\tReal, Parameter :: fSq125 = 0.35355339059327376220042218105242\n\tReal fXiP, fEtaP, fZetaP, fXiM, fEtaM, fZetaM\n\n! Main routine\n\tfXiP = (1D0 + fXi) * fSq125\n\tfEtaP = (1D0 + fEta) * fSq125\n\tfZetaP = (1D0 + fZeta) * fSq125\n\tfXiM = (1D0 - fXi) * fSq125\n\tfEtaM = (1D0 - fEta) * fSq125\n\tfZetaM = (1D0 - fZeta) * fSq125\n\n! Calculation of natural coordinate derivatives of the shape functions\n! Corresponding to XI\n\tfaDS(1) = - fEtaM * fZetaM\n\tfaDS(2) = - faDS(1)\n\tfaDS(3) = fEtaP * fZetaM\n\tfaDS(4) = - faDS(3)\n\tfaDS(5) = - fEtaM * fZetaP\n\tfaDS(6) = - faDS(5)\n\tfaDS(7) = fEtaP * fZetaP\n\tfaDS(8) = - faDS(7)\n! Corresponding to ETA\n faDS(9) = - fXiM * fZetaM\n faDS(10) = - fXiP * fZetaM\n faDS(11) = - faDS(10)\n faDS(12) = - faDS(9)\n\tfaDS(13) = - fXiM * fZetaP\n\tfaDS(14) = - fXiP * fZetaP\n\tfaDS(15) = - faDS(14)\n\tfaDS(16) = - faDS(13)\n! Corresponding to ZETA\n\tfaDS(17) = - fXiM * fEtaM\n\tfaDS(18) = - fXiP * fEtaM\n\tfaDS(19) = - fXiP * fEtaP\n\tfaDS(20) = - fXiM * fEtaP\n\tfaDS(21) = - faDS(17)\n\tfaDS(22) = - faDS(18)\n\tfaDS(23) = - faDS(19)\n\tfaDS(24) = - faDS(20)\nEnd Subroutine\n\n! ******************************************\n! Integer function CalcShapeHexa8()\n!\n! IN:\n! iElemType(integer): Element type (see hCommon.h)\n!\n! OUT:\n! nDOFs(integer): Number of DOFs per element\n! nProps(itneger): Number of properties per property type\n!\n! RETURNS:\n! (integer): Number of nodes per element\n!\n! UPDATES:\n! ---\n!\n! PURPOSE:\n! Calculate shape functions for calculation of consistent mass matrix\n!\n! NOTES:\n! ---\n! ******************************************\nSubroutine CalcH8Shape(fXi, fEta, fZeta, faS)\n\tImplicit None\n\n\tReal, Intent(IN) :: fXi, fEta, fZeta\n\tReal, Intent(OUT) :: faS(8)\n\tReal, Parameter :: fSqC125 = 0.5D0\n\tReal fXiP, fEtaP, fZetaP, fXiM, fEtaM, fZetaM\n\n! Main routine\n\tfXiP = (1.0 + fXi) * fSqC125\n\tfEtaP = (1.0 + fEta) * fSqC125\n\tfZetaP = (1.0 + fZeta) * fSqC125\n\tfXiM = (1.0 - fXi) * fSqC125\n\tfEtaM = (1.0 - fEta) * fSqC125\n\tfZetaM = (1.0 - fZeta) * fSqC125\n\n\tfaS(1) = fXiM * fEtaM * fZetaM\n\tfaS(2) = fXiP * fEtaM * fZetaM\n\tfaS(3) = fXiP * fEtaP * fZetaM\n\tfaS(4) = fXiM * fEtaP * fZetaM\n\tfaS(5) = fXiM * fEtaM * fZetaP\n\tfaS(6) = fXiP * fEtaM * fZetaP\n\tfaS(7) = fXiP * fEtaP * fZetaP\n\tfaS(8) = fXiM * fEtaP * fZetaP\nEnd Subroutine\n\n! ******************************************\n! Integer function CalcShapeHexa8()\n!\n! IN:\n! iElemType(integer): Element type (see hCommon.h)\n!\n! OUT:\n! nDOFs(integer): Number of DOFs per element\n! nProps(itneger): Number of properties per property type\n!\n! RETURNS:\n! (integer): Number of nodes per element\n!\n! UPDATES:\n! ---\n!\n! PURPOSE:\n! Calculate shape functions for calculation of consistent mass matrix\n!\n! NOTES:\n! ---\n! ******************************************\nInteger Function CalcH8JDetJ(faXYZ, faDS, faJ, fDetJ)\n\tImplicit None\n\tInclude 'hCommon.h'\n\n\tReal, Intent(IN) :: faXYZ(3, 8), faDS(24)\n\tReal, Intent(OUT) :: faJ(3, 3), fDetJ\n\tReal fDet1, fDet2, fDet3\n\n! Main routine\n\tCalcH8JDetJ = iErrNegDet\n! Compute the Jacobian at (XI, ETA, ZETA)\n\tfaJ(1, 1) = faDS(1) * faXYZ(1, 1) + &\n\t\tfaDS(2) * faXYZ(1, 2) + faDS(3) * faXYZ(1, 3) + &\n\t\tfaDS(4) * faXYZ(1, 4) + faDS(5) * faXYZ(1, 5) + &\n\t\tfaDS(6) * faXYZ(1, 6) + faDS(7) * faXYZ(1, 7) + &\n\t\tfaDS(8) * faXYZ(1, 8)\n\tfaJ(1, 2) = faDS(1) * faXYZ(2, 1) + &\n\t\tfaDS(2) * faXYZ(2, 2) + faDS(3) * faXYZ(2, 3) + &\n\t\tfaDS(4) * faXYZ(2, 4) + faDS(5) * faXYZ(2, 5) + &\n\t\tfaDS(6) * faXYZ(2, 6) + faDS(7) * faXYZ(2, 7) + &\n\t\tfaDS(8) * faXYZ(2, 8)\n\tfaJ(1, 3) = faDS(1) * faXYZ(3, 1) + &\n\t\tfaDS(2) * faXYZ(3, 2) + faDS(3) * faXYZ(3, 3) + &\n\t\tfaDS(4) * faXYZ(3, 4) + faDS(5) * faXYZ(3, 5) + &\n\t\tfaDS(6) * faXYZ(3, 6) + faDS(7) * faXYZ(3, 7) + &\n\t\tfaDS(8) * faXYZ(3, 8)\n\tfaJ(2, 1) = faDS(9) * faXYZ(1, 1) + &\n\t\tfaDS(10) * faXYZ(1, 2) + faDS(11) * faXYZ(1, 3) + &\n\t\tfaDS(12) * faXYZ(1, 4) + faDS(13) * faXYZ(1, 5) + &\n\t\tfaDS(14) * faXYZ(1, 6) + faDS(15) * faXYZ(1, 7) + &\n\t\tfaDS(16) * faXYZ(1, 8)\n\tfaJ(2, 2) = faDS(9) * faXYZ(2, 1) + &\n\t\tfaDS(10) * faXYZ(2, 2) + faDS(11) * faXYZ(2, 3) + &\n\t\tfaDS(12) * faXYZ(2, 4) + faDS(13) * faXYZ(2, 5) + &\n\t\tfaDS(14) * faXYZ(2, 6) + faDS(15) * faXYZ(2, 7) + &\n\t\tfaDS(16) * faXYZ(2, 8)\n\tfaJ(2, 3) = faDS(9) * faXYZ(3, 1) + &\n\t\tfaDS(10) * faXYZ(3, 2) + faDS(11) * faXYZ(3, 3) + &\n\t\tfaDS(12) * faXYZ(3, 4) + faDS(13) * faXYZ(3, 5) + &\n\t\tfaDS(14) * faXYZ(3, 6) + faDS(15) * faXYZ(3, 7) + &\n\t\tfaDS(16) * faXYZ(3, 8)\n\tfaJ(3, 1) = faDS(17) * faXYZ(1, 1) + &\n\t\tfaDS(18) * faXYZ(1, 2) + faDS(19) * faXYZ(1, 3) + &\n\t\tfaDS(20) * faXYZ(1, 4) + faDS(21) * faXYZ(1, 5) + &\n\t\tfaDS(22) * faXYZ(1, 6) + faDS(23) * faXYZ(1, 7) + &\n\t\tfaDS(24) * faXYZ(1, 8)\n\tfaJ(3, 2) = faDS(17) * faXYZ(2, 1) + &\n\t\tfaDS(18) * faXYZ(2, 2) + faDS(19) * faXYZ(2, 3) + &\n\t\tfaDS(20) * faXYZ(2, 4) + faDS(21) * faXYZ(2, 5) + &\n\t\tfaDS(22) * faXYZ(2, 6) + faDS(23) * faXYZ(2, 7) + &\n\t\tfaDS(24) * faXYZ(2, 8)\n\tfaJ(3, 3) = faDS(17) * faXYZ(3, 1) + &\n\t\tfaDS(18) * faXYZ(3, 2) + faDS(19) * faXYZ(3, 3) + &\n\t\tfaDS(20) * faXYZ(3, 4) + faDS(21) * faXYZ(3, 5) + &\n\t\tfaDS(22) * faXYZ(3, 6) + faDS(23) * faXYZ(3, 7) + &\n\t\tfaDS(24) * faXYZ(3, 8)\n\n\tfDet1 = faJ(1, 1) * (faJ(2, 2) * faJ(3, 3) - faJ(3, 2) * faJ(2, 3))\n\tfDet2 = -faJ(1, 2) * (faJ(2, 1) * faJ(3, 3) - faJ(3, 1) * faJ(2, 3))\n\tfDet3 = faJ(1, 3) * (faJ(2, 1) * faJ(3, 2) - faJ(3, 1) * faJ(2, 2))\n\tfDetJ = fDet1 + fDet2 + fDet3\n! Error if determinant is negative (return)\n\tIf (fDetJ.LT.0.00000001) then\n\t\tWrite(*, *) \"Negative determinant (H8)\"\n\t\tReturn\n\tEndIf\n\tCalcH8JDetJ = iErrNoError\nEnd Function\n\n! ******************************************\n! Integer function CalcShapeHexa8()\n!\n! IN:\n! iElemType(integer): Element type (see hCommon.h)\n!\n! OUT:\n! nDOFs(integer): Number of DOFs per element\n! nProps(itneger): Number of properties per property type\n!\n! RETURNS:\n! (integer): Number of nodes per element\n!\n! UPDATES:\n! ---\n!\n! PURPOSE:\n! Calculate shape functions for calculation of consistent mass matrix\n!\n! NOTES:\n! ---\n! ******************************************\nSubroutine CalcH8B(fDetJ, faJ, faDS, faB)\n\tImplicit None\n\n\tReal, Intent(IN) :: fDetJ, faJ(3, 3), faDS(24)\n\tReal, Intent(OUT) :: faB(6, 24)\n\tReal faJInv(3, 3), fDetInv\n!\n! Main routine\n! Calculate the Jacobian Inverse (faJInv)\n\tfDetInv = 1D0 / fDetJ\n\tfaJInv(1, 1) = (faJ(2, 2) * faJ(3, 3) - faJ(3, 2) * faJ(2, 3)) * fDetInv\n\tfaJInv(2, 1) = (faJ(3, 1) * faJ(2, 3) - faJ(2, 1) * faJ(3, 3)) * fDetInv\n\tfaJInv(3, 1) = (faJ(2, 1) * faJ(3, 2) - faJ(3, 1) * faJ(2, 2)) * fDetInv\n\tfaJInv(1, 2) = (faJ(3, 2) * faJ(1, 3) - faJ(1, 2) * faJ(3, 3)) * fDetInv\n\tfaJInv(2, 2) = (faJ(1, 1) * faJ(3, 3) - faJ(3, 1) * faJ(1, 3)) * fDetInv\n\tfaJInv(3, 2) = (faJ(3, 1) * faJ(1, 2) - faJ(3, 2) * faJ(1, 1)) * fDetInv\n\tfaJInv(1, 3) = (faJ(1, 2) * faJ(2, 3) - faJ(2, 2) * faJ(1, 3)) * fDetInv\n\tfaJInv(2, 3) = (faJ(2, 1) * faJ(1, 3) - faJ(1, 1) * faJ(2, 3)) * fDetInv\n\tfaJInv(3, 3) = (faJ(1, 1) * faJ(2, 2) - faJ(2, 1) * faJ(1, 2)) * fDetInv\n\n! Calculate the global derivative operator [faB]\n\tfaB(1, 1) = faJInv(1, 1) * faDS(1) + faJInv(1, 2) * faDS(9) + faJInv(1, 3) * faDS(17)\n\tfaB(1, 2) = 0D0\n\tfaB(1, 3) = 0D0\n\tfaB(1, 4) = faJInv(1, 1) * faDS(2) + faJInv(1, 2) * faDS(10) + faJInv(1, 3) * faDS(18)\n\tfaB(1, 5) = 0D0\n\tfaB(1, 6) = 0D0\n\tfaB(1, 7) = faJInv(1, 1) * faDS(3) + faJInv(1, 2) * faDS(11) + faJInv(1, 3) * faDS(19)\n\tfaB(1, 8) = 0D0\n\tfaB(1, 9) = 0D0\n\tfaB(1, 10) = faJInv(1, 1) * faDS(4) + faJInv(1, 2) * faDS(12) + faJInv(1, 3) * faDS(20)\n\tfaB(1, 11) = 0D0\n\tfaB(1, 12) = 0D0\n\tfaB(1, 13) = faJInv(1, 1) * faDS(5) + faJInv(1, 2) * faDS(13) + faJInv(1, 3) * faDS(21)\n\tfaB(1, 14) = 0D0\n\tfaB(1, 15) = 0D0\n\tfaB(1, 16) = faJInv(1, 1) * faDS(6) + faJInv(1, 2) * faDS(14) + faJInv(1, 3) * faDS(22)\n\tfaB(1, 17) = 0D0\n\tfaB(1, 18) = 0D0\n\tfaB(1, 19) = faJInv(1, 1) * faDS(7) + faJInv(1, 2) * faDS(15) + faJInv(1, 3) * faDS(23)\n\tfaB(1, 20) = 0D0\n\tfaB(1, 21) = 0D0\n\tfaB(1, 22) = faJInv(1, 1) * faDS(8) + faJInv(1, 2) * faDS(16) + faJInv(1, 3) * faDS(24)\n\tfaB(1, 23) = 0D0\n\tfaB(1, 24) = 0D0\n\tfaB(2, 1) = 0D0\n\tfaB(2, 2) = faJInv(2, 1) * faDS(1) + faJInv(2, 2) * faDS(9) + faJInv(2, 3) * faDS(17)\n\tfaB(2, 3) = 0D0\n\tfaB(2, 4) = 0D0\n\tfaB(2, 5) = faJInv(2, 1) * faDS(2) + faJInv(2, 2) * faDS(10) + faJInv(2, 3) * faDS(18)\n\tfaB(2, 6) = 0D0\n\tfaB(2, 7) = 0D0\n\tfaB(2, 8) = faJInv(2, 1) * faDS(3) + faJInv(2, 2) * faDS(11) + faJInv(2, 3) * faDS(19)\n\tfaB(2, 9) = 0D0\n\tfaB(2, 10) = 0D0\n\tfaB(2, 11) = faJInv(2, 1) * faDS(4) + faJInv(2, 2) * faDS(12) + faJInv(2, 3) * faDS(20)\n\tfaB(2, 12) = 0D0\n\tfaB(2, 13) = 0D0\n\tfaB(2, 14) = faJInv(2, 1) * faDS(5) + faJInv(2, 2) * faDS(13) + faJInv(2, 3) * faDS(21)\n\tfaB(2, 15) = 0D0\n\tfaB(2, 16) = 0D0\n\tfaB(2, 17) = faJInv(2, 1) * faDS(6) + faJInv(2, 2) * faDS(14) + faJInv(2, 3) * faDS(22)\n\tfaB(2, 18) = 0D0\n\tfaB(2, 19) = 0D0\n\tfaB(2, 20) = faJInv(2, 1) * faDS(7) + faJInv(2, 2) * faDS(15) + faJInv(2, 3) * faDS(23)\n\tfaB(2, 21) = 0D0\n\tfaB(2, 22) = 0D0\n\tfaB(2, 23) = faJInv(2, 1) * faDS(8) + faJInv(2, 2) * faDS(16) + faJInv(2, 3) * faDS(24)\n\tfaB(2, 24) = 0D0\n\tfaB(3, 1) = 0D0\n\tfaB(3, 2) = 0D0\n\tfaB(3, 3) = faJInv(3, 1) * faDS(1) + faJInv(3, 2) * faDS(9) + faJInv(3, 3) * faDS(17)\n\tfaB(3, 4) = 0D0\n\tfaB(3, 5) = 0D0\n\tfaB(3, 6) = faJInv(3, 1) * faDS(2) + faJInv(3, 2) * faDS(10) + faJInv(3, 3) * faDS(18)\n\tfaB(3, 7) = 0D0\n\tfaB(3, 8) = 0D0\n\tfaB(3, 9) = faJInv(3, 1) * faDS(3) + faJInv(3, 2) * faDS(11) + faJInv(3, 3) * faDS(19)\n\tfaB(3, 10) = 0D0\n\tfaB(3, 11) = 0D0\n\tfaB(3, 12) = faJInv(3, 1) * faDS(4) + faJInv(3, 2) * faDS(12) + faJInv(3, 3) * faDS(20)\n\tfaB(3, 13) = 0D0\n\tfaB(3, 14) = 0D0\n\tfaB(3, 15) = faJInv(3, 1) * faDS(5) + faJInv(3, 2) * faDS(13) + faJInv(3, 3) * faDS(21)\n\tfaB(3, 16) = 0D0\n\tfaB(3, 17) = 0D0\n\tfaB(3, 18) = faJInv(3, 1) * faDS(6) + faJInv(3, 2) * faDS(14) + faJInv(3, 3) * faDS(22)\n\tfaB(3, 19) = 0D0\n\tfaB(3, 20) = 0D0\n\tfaB(3, 21) = faJInv(3, 1) * faDS(7) + faJInv(3, 2) * faDS(15) + faJInv(3, 3) * faDS(23)\n\tfaB(3, 22) = 0D0\n\tfaB(3, 23) = 0D0\n\tfaB(3, 24) = faJInv(3, 1) * faDS(8) + faJInv(3, 2) * faDS(16) + faJInv(3, 3) * faDS(24)\n\tfaB(4, 1) = faB(2, 2)\n\tfaB(4, 2) = faB(1, 1)\n\tfaB(4, 3) = 0D0\n\tfaB(4, 4) = faB(2, 5)\n\tfaB(4, 5) = faB(1, 4)\n\tfaB(4, 6) = 0D0\n\tfaB(4, 7) = faB(2, 8)\n\tfaB(4, 8) = faB(1, 7)\n\tfaB(4, 9) = 0D0\n\tfaB(4, 10) = faB(2, 11)\n\tfaB(4, 11) = faB(1, 10)\n\tfaB(4, 12) = 0D0\n\tfaB(4, 13) = faB(2, 14)\n\tfaB(4, 14) = faB(1, 13)\n\tfaB(4, 15) = 0D0\n\tfaB(4, 16) = faB(2, 17)\n\tfaB(4, 17) = faB(1, 16)\n\tfaB(4, 18) = 0D0\n\tfaB(4, 19) = faB(2, 20)\n\tfaB(4, 20) = faB(1, 19)\n\tfaB(4, 21) = 0D0\n\tfaB(4, 22) = faB(2, 23)\n\tfaB(4, 23) = faB(1, 22)\n\tfaB(4, 24) = 0D0\n\tfaB(5, 1) = 0D0\n\tfaB(5, 2) = faB(3, 3)\n\tfaB(5, 3) = faB(2, 2)\n\tfaB(5, 4) = 0D0\n\tfaB(5, 5) = faB(3, 6)\n\tfaB(5, 6) = faB(2, 5)\n\tfaB(5, 7) = 0D0\n\tfaB(5, 8) = faB(3, 9)\n\tfaB(5, 9) = faB(2, 8)\n\tfaB(5, 10) = 0D0\n\tfaB(5, 11) = faB(3, 12)\n\tfaB(5, 12) = faB(2, 11)\n\tfaB(5, 13) = 0D0\n\tfaB(5, 14) = faB(3, 15)\n\tfaB(5, 15) = faB(2, 14)\n\tfaB(5, 16) = 0D0\n\tfaB(5, 17) = faB(3, 18)\n\tfaB(5, 18) = faB(2, 17)\n\tfaB(5, 19) = 0D0\n\tfaB(5, 20) = faB(3, 21)\n\tfaB(5, 21) = faB(2, 20)\n\tfaB(5, 22) = 0D0\n\tfaB(5, 23) = faB(3, 24)\n\tfaB(5, 24) = faB(2, 23)\n\tfaB(6, 1) = faB(3, 3)\n\tfaB(6, 2) = 0D0\n\tfaB(6, 3) = faB(1, 1)\n\tfaB(6, 4) = faB(3, 6)\n\tfaB(6, 5) = 0D0\n\tfaB(6, 6) = faB(1, 4)\n\tfaB(6, 7) = faB(3, 9)\n\tfaB(6, 8) = 0D0\n\tfaB(6, 9) = faB(1, 7)\n\tfaB(6, 10) = faB(3, 12)\n\tfaB(6, 11) = 0D0\n\tfaB(6, 12) = faB(1, 10)\n\tfaB(6, 13) = faB(3, 15)\n\tfaB(6, 14) = 0D0\n\tfaB(6, 15) = faB(1, 13)\n\tfaB(6, 16) = faB(3, 18)\n\tfaB(6, 17) = 0D0\n\tfaB(6, 18) = faB(1, 16)\n\tfaB(6, 19) = faB(3, 21)\n\tfaB(6, 20) = 0D0\n\tfaB(6, 21) = faB(1, 19)\n\tfaB(6, 22) = faB(3, 24)\n\tfaB(6, 23) = 0D0\n\tfaB(6, 24) = faB(1, 22)\nEnd Subroutine\n\n! ******************************************\n! Integer function CalcOnlyKHexa8()\n!\n! IN:\n! iElemNo(integer): Position in the elements matrix \n!\t\t\t\t\tof the element that the stiffness\n!\t\t\t\t\tmatrix will be calculated.\n!\n! OUT:\n! ---\n!\n! RETURNS:\n! (integer): Number of nodes per element\n!\n! UPDATES:\n! ---\n!\n! PURPOSE:\n! Calculate the element stiffness matrix\n!\n! NOTES:\n! ---\n! ******************************************\nSubroutine CalcH8GaussMatrices(iInt, faXYZ, faWeight, faS, faDS, faJ, faDetJ, faB)\n !DEC$ ATTRIBUTES DLLEXPORT::CalcH8GaussMatrices\n\tImplicit None\n\n\tInteger, Intent(IN) :: iInt\n\tReal, Intent(IN) :: faXYZ(3, 8)\n\tReal, Intent(OUT) :: faDS(24, iInt ** 3), faS(8, iInt ** 3), &\n\t\tfaB(6, 24, iInt ** 3), faDetJ(iInt ** 3), faJ(3, 3, iInt ** 3), &\n\t\tfaWeight(iInt ** 3)\n\tReal fXi, fEta, fZeta\n\tInteger M, iX, iY, iZ, iErr, CalcH8JDetJ\n\tReal GP(4, 4), GW(4, 4)\n! GP Matrix stores Gauss - Legendre sampling points\n Data GP/ &\n\t\t0.D0, 0.D0, 0.D0, 0.D0, -.5773502691896D0, &\n\t\t.5773502691896D0, 0.D0, 0.D0, -.7745966692415D0, 0.D0, &\n\t\t.7745966692415D0, 0.D0, -.8611363115941D0, &\n\t\t-.3399810435849D0, .3399810435849D0, .8611363115941D0 /\n! GW Matrix stores Gauss - Legendre weighting factors\n\tData GW/ & \n\t\t2.D0, 0.D0, 0.D0, 0.D0, 1.D0, 1.D0, &\n\t\t0.D0, 0.D0, .5555555555556D0, .8888888888889D0, &\n\t\t.5555555555556D0, 0.D0, .3478548451375D0, .6521451548625D0, &\n\t\t.6521451548625D0, \t .3478548451375D0 /\n\n! Main routine\n\tM = 0\n\tDo iX = 1, iInt\n\t\tfXi = GP(iX, iInt)\n\t\tDo iY = 1, iInt\n\t\t\tfEta = GP(iY, iInt)\n\t\t\tDo iZ = 1, iInt\n\t\t\t\tfZeta = GP(iZ, iInt)\n\t\t\t\tM = M + 1\n\t\t\t\tCall CalcH8NablaShape(fXi, fEta, fZeta, faDS(1, M))\n\t\t\t\tCall CalcH8Shape(fXi, fEta, fZeta, faS(1, M))\n\t\t\t\tiErr = CalcH8JDetJ(faXYZ, faDS(1, M), faJ(1, 1, M), faDetJ(M))\n\t\t\t\tCall CalcH8B(faDetJ(M), faJ(1, 1, M), faDS(1, M), faB(1, 1, M))\n\t\t\t\tfaWeight(M) = GW(iX, iInt) * GW(iY, iInt) * GW(iZ, iInt) * faDetJ(M)\n\t\t\tEndDo\n\t\tEndDo\n\tEndDo\nEnd Subroutine\n\n! ******************************************\n! Integer function CalcOnlyKHexa8()\n!\n! IN:\n! iElemNo(integer): Position in the elements matrix \n!\t\t\t\t\tof the element that the stiffness\n!\t\t\t\t\tmatrix will be calculated.\n!\n! OUT:\n! ---\n!\n! RETURNS:\n! (integer): Number of nodes per element\n!\n! UPDATES:\n! ---\n!\n! PURPOSE:\n! Calculate the element stiffness matrix\n!\n! NOTES:\n! ---\n! ******************************************\nSubroutine CalcH8K(iInt, faE, faB, faWeight, faK)\n !DEC$ ATTRIBUTES DLLEXPORT::CalcH8K\n\tImplicit None\n\n\tInteger, Intent(IN) :: iInt\n\tReal, Intent(IN) :: faWeight(iInt ** 3), faB(6, 24, iInt ** 3), faE(6, 6, iInt ** 3)\n\tReal, Intent(OUT) :: faK(300)\n\tReal faEB(6)\n\tReal fStiff, fE1, fE2, fE3, fE4\n\tInteger I, J, K, M, KS, iX, iY, iZ\n\n! Main routine \n! Calculate stiffness matrix\n\tM = 0\n\tDo I = 1, 300\n\t\tfaK(I) = 0D0\n\tEndDo\n\tDo iX = 1, iInt\n\t\tDo iY = 1, iInt\n\t\t\tDo iZ = 1, iInt\n\t\t\t\tM = M + 1\n! Add contribution to element stiffness\n\t\t\t\tKS = 0\n\t\t\t\tDo I = 1, 24\n\t\t\t\t\tfaEB(1) = faE(1, 1, M) * faB(1, I, M) + faE(1, 2, M) * faB(2, I, M) + &\n\t\t\t\t\t\tfaE(1, 3, M) * faB(3, I, M) + faE(1, 4, M) * faB(4, I, M) + &\n\t\t\t\t\t\tfaE(1, 5, M) * faB(5, I, M) + faE(1, 6, M) * faB(6, I, M)\n\t\t\t\t\tfaEB(2) = faE(2, 1, M) * faB(1, I, M) + faE(2, 2, M) * faB(2, I, M) + &\n\t\t\t\t\t\tfaE(2, 3, M) * faB(3, I, M) + faE(2, 4, M) * faB(4, I, M) + &\n\t\t\t\t\t\tfaE(2, 5, M) * faB(5, I, M) + faE(2, 6, M) * faB(6, I, M)\n\t\t\t\t\tfaEB(3) = faE(3, 1, M) * faB(1, I, M) + faE(3, 2, M) * faB(2, I, M) + &\n\t\t\t\t\t\tfaE(3, 3, M) * faB(3, I, M) + faE(3, 4, M) * faB(4, I, M) + &\n\t\t\t\t\t\tfaE(3, 5, M) * faB(5, I, M) + faE(3, 6, M) * faB(6, I, M)\n\t\t\t\t\tfaEB(4) = faE(4, 1, M) * faB(1, I, M) + faE(4, 2, M) * faB(2, I, M) + &\n\t\t\t\t\t\tfaE(4, 3, M) * faB(3, I, M) + faE(4, 4, M) * faB(4, I, M) + &\n\t\t\t\t\t\tfaE(4, 5, M) * faB(5, I, M) + faE(4, 6, M) * faB(6, I, M)\n\t\t\t\t\tfaEB(5) = faE(5, 1, M) * faB(1, I, M) + faE(5, 2, M) * faB(2, I, M) + &\n\t\t\t\t\t\tfaE(5, 3, M) * faB(3, I, M) + faE(5, 4, M) * faB(4, I, M) + &\n\t\t\t\t\t\tfaE(5, 5, M) * faB(5, I, M) + faE(5, 6, M) * faB(6, I, M)\n\t\t\t\t\tfaEB(6) = faE(6, 1, M) * faB(1, I, M) + faE(6, 2, M) * faB(2, I, M) + &\n\t\t\t\t\t\tfaE(6, 3, M) * faB(3, I, M) + faE(6, 4, M) * faB(4, I, M) + &\n\t\t\t\t\t\tfaE(6, 5, M) * faB(5, I, M) + faE(6, 6, M) * faB(6, I, M)\n\n\t\t\t\t\tDo J = I, 24\n\t\t\t\t\t\tKS = KS + 1\n\t\t\t\t\t\tfStiff = faB(1, J, M) * faEB(1) + faB(2, J, M) * faEB(2) + &\n\t\t\t\t\t\t\tfaB(3, J, M) * faEB(3) + faB(4, J, M) * faEB(4) + &\n\t\t\t\t\t\t\tfaB(5, J, M) * faEB(5) + faB(6, J, M) * faEB(6)\n\t\t\t\t\t\tfaK(KS) = faK(KS) + fStiff * faWeight(M)\n\t\t\t\t\tEndDo\n\t\t\t\tEndDo\n\t\t\tEndDo\n\t\tEndDo\n\tEndDo\nEnd Subroutine\n\n! ******************************************\n! Integer function CalcOnlyMHexa8(iElemNo)\n!\n! IN:\n! iElemNo(integer): Position in the elements matrix \n!\t\t\t\t\tof the element that the stiffness\n!\t\t\t\t\tmatrix will be calculated.\n!\n! OUT:\n! ---\n!\n! RETURNS:\n! (integer): Number of nodes per element\n!\n! UPDATES:\n! ---\n!\n! PURPOSE:\n! Calculate the element stiffness matrix\n!\n! NOTES:\n! ---\n! ******************************************\nInteger Function CalcH8MConsistent(iInt, fDensity, faS, faWeight, faM)\n\tImplicit None\n\n\tInteger, Intent(IN) :: iInt\n\tReal, Intent(IN) :: fDensity, faWeight(iInt ** 3), faS(8, iInt ** 3)\n\tReal, Intent(OUT) :: faM(300)\n\tInteger I, J, K, M, KS, iX, iY, iZ, iWidth, iS2, iS1\n\tReal fWeight\n\n! Main routine\n\tM = 0\n\tDo I = 1, 300\n\t\tfaM(I) = 0D0\n\tEndDo\n\tDo iX = 1, iInt\n\t\tDo iY = 1, iInt\n\t\t\tDo iZ = 1, iInt\n\t\t\t\tM = M + 1\n\t\t\t\tKS = -2\n\t\t\t\tfWeight = faWeight(M) * fDensity\n\t\t\t\tDo I = 1, 8\n\t\t\t\t\tDo J = I, 8\n\t\t\t\t\t\tKS = KS + 3\n\t\t\t\t\t\tfaM(KS) = faM(KS) + faS(I, M) * faS(J, M) * fWeight\n\t\t\t\t\tEndDo\n\n\t\t\t\t\tiWidth = 27 - 3 * I\n\t\t\t\t\tDo J = I, 8\n\t\t\t\t\t\tKS = KS + 3\n\t\t\t\t\t\tfaM(KS) = faM(KS - iWidth)\n\t\t\t\t\tEndDo\n\t\t\t\t\tKS = KS - 1\n\t\t\t\t\tiWidth = 26 - 3 * I\n\t\t\t\t\tDo J = I, 8\n\t\t\t\t\t\tKS = KS + 3\n\t\t\t\t\t\tfaM(KS) = faM(KS - iWidth)\n\t\t\t\t\tEndDo\n\t\t\t\t\tKS = KS - 2\n\t\t\t\tEndDo\n\t\t\tEndDo\n\t\tEndDo\n\tEndDo\nEnd Function\n\n! ******************************************\n! Integer function CalcOnlyMHexa8(iElemNo)\n!\n! IN:\n! iElemNo(integer): Position in the elements matrix \n!\t\t\t\t\tof the element that the stiffness\n!\t\t\t\t\tmatrix will be calculated.\n!\n! OUT:\n! ---\n!\n! RETURNS:\n! (integer): Number of nodes per element\n!\n! UPDATES:\n! ---\n!\n! PURPOSE:\n! Calculate the element stiffness matrix\n!\n! NOTES:\n! ---\n! ******************************************\nSubroutine CalcH8Strains(iInt, faB, fau, faStrains)\n !DEC$ ATTRIBUTES DLLEXPORT::CalcH8Strains\n\tImplicit None\n\n\tInteger, Intent(IN) :: iInt\n\tReal, Intent(IN) :: faB(6, 24, iInt ** 3), fau(24)\n\tReal, Intent(OUT) :: faStrains(6, iInt ** 3)\n\tInteger :: M\n\n! Main routine \n\tDo M = 1, iInt ** 3\n\t\tfaStrains(:, M) = MatMul(faB(:, :, M), fau)\n\tEndDo\nEnd Subroutine\n\n! ******************************************\n! Integer function CalcOnlyMHexa8(iElemNo)\n!\n! IN:\n! iElemNo(integer): Position in the elements matrix \n!\t\t\t\t\tof the element that the stiffness\n!\t\t\t\t\tmatrix will be calculated.\n!\n! OUT:\n! ---\n!\n! RETURNS:\n! (integer): Number of nodes per element\n!\n! UPDATES:\n! ---\n!\n! PURPOSE:\n! Calculate the element stiffness matrix\n!\n! NOTES:\n! ---\n! ******************************************\nInteger Function CalcH8MLumped(iInt, fDensity, faWeight, faM)\n !DEC$ ATTRIBUTES DLLEXPORT::CalcH8MLumped\n\tImplicit None\n\n\tInteger, Intent(IN) :: iInt\n\tReal, Intent(IN) :: fDensity, faWeight(iInt ** 3)\n\tReal, Intent(OUT) :: faM(300)\n\tInteger M, iS2, iS1\n\tReal fMassTerm\n\n! Main routine\n\tDo M = 1, 300\n\t\tfaM(M) = 0D0\n\tEndDo\n\n\tfMassTerm = 0D0\n\tDo M = 1, iInt ** 3\n\t\tfMassTerm = fMassTerm + faWeight(M)\n\tEndDo\t\n\tfMassTerm = fMassTerm * fDensity * 0.125D0\n\n\tiS2 = 1\n\tDo iS1 = 24, 1, -1\n\t\tfaM(iS2) = fMassTerm\n\t\tiS2 = iS2 + iS1\n\tEndDo\nEnd Function\n\n! ******************************************\n! Integer function CalcOnlyKHexa8()\n!\n! IN:\n! iElemNo(integer): Position in the elements matrix \n!\t\t\t\t\tof the element that the stiffness\n!\t\t\t\t\tmatrix will be calculated.\n!\n! OUT:\n! ---\n!\n! RETURNS:\n! (integer): Number of nodes per element\n!\n! UPDATES:\n! ---\n!\n! PURPOSE:\n! Calculate the element stiffness matrix\n!\n! NOTES:\n! ---\n! ******************************************\nSubroutine CalcH8Forces(iInt, faB, faWeight, faStresses, faForces)\n !DEC$ ATTRIBUTES DLLEXPORT::CalcH8Forces\n\tImplicit None\n\n\tInteger, Intent(IN) :: iInt\n\tReal, Intent(IN) :: faWeight(iInt ** 3), faB(6, 24, iInt ** 3), faStresses(6, iInt ** 3)\n\tReal, Intent(OUT) :: faForces(24)\n\tInteger :: M, iX, iY, iZ\n\n! Main routine \n! Calculate stiffness matrix\n\tM = 0\n\tDo iX = 1, 24\n\t\tfaForces(iX) = 0D0\n\tEndDo\n\tDo iX = 1, iInt\n\t\tDo iY = 1, iInt\n\t\t\tDo iZ = 1, iInt\n\t\t\t\tM = M + 1\n\t\t\t\tfaForces = faForces + faWeight(M) * MatMul(Transpose(faB(:, :, M)), faStresses(:, M))\n\t\t\tEndDo\n\t\tEndDo\n\tEndDo\nEnd Subroutine\n\nSubroutine CalcH8ForcesFromDisp(piEqLM, pfElementK, pfU, pfGlobalForces)\n\tImplicit None\n\n\tInteger, Intent(IN) :: piEqLM(1)\n\tReal, Intent(IN) :: pfElementK(1), pfU(24)\n\tReal, Intent(OUT) :: pfGlobalForces(1)\n\n\tInteger :: I, J, iRow, iAccR, iTemp, iDataPos\n\tReal :: fLocalForces(24)\n\n! Main function\n! Initialize local forces vector\n\tfLocalForces(1) = 0D0\n\tfLocalForces(2) = 0D0\n\tfLocalForces(3) = 0D0\n\tfLocalForces(4) = 0D0\n\tfLocalForces(5) = 0D0\n\tfLocalForces(6) = 0D0\n\tfLocalForces(7) = 0D0\n\tfLocalForces(8) = 0D0\n\tfLocalForces(9) = 0D0\n\tfLocalForces(10) = 0D0\n\tfLocalForces(11) = 0D0\n\tfLocalForces(12) = 0D0\n\tfLocalForces(13) = 0D0\n\tfLocalForces(14) = 0D0\n\tfLocalForces(15) = 0D0\n\tfLocalForces(16) = 0D0\n\tfLocalForces(17) = 0D0\n\tfLocalForces(18) = 0D0\n\tfLocalForces(19) = 0D0\n\tfLocalForces(20) = 0D0\n\tfLocalForces(21) = 0D0\n\tfLocalForces(22) = 0D0\n\tfLocalForces(23) = 0D0\n\tfLocalForces(24) = 0D0\n\n! Multiply SKYLINE Element K with vector pfU and store to fLocalForces\n\tiDataPos = 1\n\tDo I = 1, 24\n\t\tfLocalForces(I) = fLocalForces(I) + pfElementK(iDataPos) * pfU(I)\n\t\tiDataPos = iDataPos + 1\n\t\tDo J = I + 1, 24\n\t\t\tfLocalForces(I) = fLocalForces(I) + pfElementK(iDataPos) * pfU(J)\n\t\t\tfLocalForces(J) = fLocalForces(J) + pfElementK(iDataPos) * pfU(I)\n\t\t\tiDataPos = iDataPos + 1\n\t\tEnd Do\n\tEnd Do\n\n! Update the global loads vector (pfGlobalForces)\n\tiTemp = piEqLM(1)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(1)\n\tiTemp = piEqLM(2)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(2)\n\tiTemp = piEqLM(3)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(3)\n\tiTemp = piEqLM(4)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(4)\n\tiTemp = piEqLM(5)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(5)\n\tiTemp = piEqLM(6)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(6)\n\tiTemp = piEqLM(7)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(7)\n\tiTemp = piEqLM(8)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(8)\n\tiTemp = piEqLM(9)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(9)\n\tiTemp = piEqLM(10)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(10)\n\tiTemp = piEqLM(11)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(11)\n\tiTemp = piEqLM(12)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(12)\n\tiTemp = piEqLM(13)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(13)\n\tiTemp = piEqLM(14)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(14)\n\tiTemp = piEqLM(15)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(15)\n\tiTemp = piEqLM(16)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(16)\n\tiTemp = piEqLM(17)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(17)\n\tiTemp = piEqLM(18)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(18)\n\tiTemp = piEqLM(19)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(19)\n\tiTemp = piEqLM(20)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(20)\n\tiTemp = piEqLM(21)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(21)\n\tiTemp = piEqLM(22)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(22)\n\tiTemp = piEqLM(23)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(23)\n\tiTemp = piEqLM(24)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(24)\nEnd Subroutine\n\nSubroutine CalcH8ForcesAcc(iInt, bIsLumped, fDensity, afAcc, afS, afWeights, afLocalForces)\n\tImplicit None\n\tInteger, Intent(IN) :: iInt\n\tLogical, Intent(IN) :: bIsLumped\n\tReal, Intent(IN) :: fDensity, afS(8, iInt ** 3), afAcc(3), afWeights(*)\n\tReal, Intent(OUT) :: afLocalForces(24)\n\tInteger :: I, J, iAccR, iDataPos, CalcH8MLumped, CalcH8MConsistent\n\tReal :: afM(300)\n\n! Main function\n! Initialize local forces vector\n\tafLocalForces(1) = 0D0\n\tafLocalForces(2) = 0D0\n\tafLocalForces(3) = 0D0\n\tafLocalForces(4) = 0D0\n\tafLocalForces(5) = 0D0\n\tafLocalForces(6) = 0D0\n\tafLocalForces(7) = 0D0\n\tafLocalForces(8) = 0D0\n\tafLocalForces(9) = 0D0\n\tafLocalForces(10) = 0D0\n\tafLocalForces(11) = 0D0\n\tafLocalForces(12) = 0D0\n\tafLocalForces(13) = 0D0\n\tafLocalForces(14) = 0D0\n\tafLocalForces(15) = 0D0\n\tafLocalForces(16) = 0D0\n\tafLocalForces(17) = 0D0\n\tafLocalForces(18) = 0D0\n\tafLocalForces(19) = 0D0\n\tafLocalForces(20) = 0D0\n\tafLocalForces(21) = 0D0\n\tafLocalForces(22) = 0D0\n\tafLocalForces(23) = 0D0\n\tafLocalForces(24) = 0D0\n\tIf (bIsLumped) Then\n\t\tI = CalcH8MLumped(iInt, fDensity, afWeights, afM)\n\tElse\n\t\tI = CalcH8MConsistent(iInt, fDensity, afS, afWeights, afM)\n\tEnd If\n\n! Multiply SKYLINE Element M with vector pfAcc and store to fLocalForces\n\tiDataPos = 1\n\tDo I = 1, 24\n\t\tiAccR = mod(I - 1, 3) + 1\n\t\tafLocalForces(I) = afLocalForces(I) + afM(iDataPos) * afAcc(iAccR)\n\t\tiDataPos = iDataPos + 1\n\t\tDo J = I + 1, 24\n\t\t\tafLocalForces(I) = afLocalForces(I) + afM(iDataPos) * afAcc(mod(J - 1, 3) + 1)\n\t\t\tafLocalForces(J) = afLocalForces(J) + afM(iDataPos) * afAcc(iAccR)\n\t\t\tiDataPos = iDataPos + 1\n\t\tEnd Do\n\tEnd Do\nEnd Subroutine\n\nSubroutine CalcH8ForcesFromAcc(piEqLM, pfElementM, pfAcc, pfGlobalForces)\n\tImplicit None\n\n\tInteger, Intent(IN) :: piEqLM(1)\n\tReal, Intent(IN) :: pfElementM(1), pfAcc(3)\n\tReal, Intent(OUT) :: pfGlobalForces(1)\n\n\tInteger :: I, J, iRow, iAccR, iTemp, iDataPos\n\tReal :: fLocalForces(24)\n\n! Main function\n! Initialize local forces vector\n\tfLocalForces(1) = 0D0\n\tfLocalForces(2) = 0D0\n\tfLocalForces(3) = 0D0\n\tfLocalForces(4) = 0D0\n\tfLocalForces(5) = 0D0\n\tfLocalForces(6) = 0D0\n\tfLocalForces(7) = 0D0\n\tfLocalForces(8) = 0D0\n\tfLocalForces(9) = 0D0\n\tfLocalForces(10) = 0D0\n\tfLocalForces(11) = 0D0\n\tfLocalForces(12) = 0D0\n\tfLocalForces(13) = 0D0\n\tfLocalForces(14) = 0D0\n\tfLocalForces(15) = 0D0\n\tfLocalForces(16) = 0D0\n\tfLocalForces(17) = 0D0\n\tfLocalForces(18) = 0D0\n\tfLocalForces(19) = 0D0\n\tfLocalForces(20) = 0D0\n\tfLocalForces(21) = 0D0\n\tfLocalForces(22) = 0D0\n\tfLocalForces(23) = 0D0\n\tfLocalForces(24) = 0D0\n\n! Multiply SKYLINE Element M with vector pfAcc and store to fLocalForces\n\tiDataPos = 1\n\tDo I = 1, 24\n\t\tiAccR = mod(I - 1, 3) + 1\n\t\tfLocalForces(I) = fLocalForces(I) + pfElementM(iDataPos) * pfAcc(iAccR)\n\t\tiDataPos = iDataPos + 1\n\t\tDo J = I + 1, 24\n\t\t\tfLocalForces(I) = fLocalForces(I) + pfElementM(iDataPos) * pfAcc(mod(J - 1, 3) + 1)\n\t\t\tfLocalForces(J) = fLocalForces(J) + pfElementM(iDataPos) * pfAcc(iAccR)\n\t\t\tiDataPos = iDataPos + 1\n\t\tEnd Do\n\tEnd Do\n\n! Update the global loads vector (pfGlobalForces)\n\tiTemp = piEqLM(1)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(1)\n\tiTemp = piEqLM(2)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(2)\n\tiTemp = piEqLM(3)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(3)\n\tiTemp = piEqLM(4)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(4)\n\tiTemp = piEqLM(5)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(5)\n\tiTemp = piEqLM(6)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(6)\n\tiTemp = piEqLM(7)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(7)\n\tiTemp = piEqLM(8)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(8)\n\tiTemp = piEqLM(9)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(9)\n\tiTemp = piEqLM(10)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(10)\n\tiTemp = piEqLM(11)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(11)\n\tiTemp = piEqLM(12)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(12)\n\tiTemp = piEqLM(13)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(13)\n\tiTemp = piEqLM(14)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(14)\n\tiTemp = piEqLM(15)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(15)\n\tiTemp = piEqLM(16)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(16)\n\tiTemp = piEqLM(17)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(17)\n\tiTemp = piEqLM(18)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(18)\n\tiTemp = piEqLM(19)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(19)\n\tiTemp = piEqLM(20)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(20)\n\tiTemp = piEqLM(21)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(21)\n\tiTemp = piEqLM(22)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(22)\n\tiTemp = piEqLM(23)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(23)\n\tiTemp = piEqLM(24)\n\tIf (iTemp.GT.0) pfGlobalForces(iTemp) = pfGlobalForces(iTemp) + fLocalForces(24)\nEnd Subroutine\n\n", "meta": {"hexsha": "c8ccba23a2ec3bfb660c3692522514eaab7b6db7", "size": 29962, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "FEMElements/FEMElements/rElHexa8.f90", "max_stars_repo_name": "gsoim/MSolve", "max_stars_repo_head_hexsha": "5cf2ae4f84cdb49f4676fa2ae00fc619421b2bef", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2016-06-06T17:42:17.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-12T09:02:09.000Z", "max_issues_repo_path": "FEMElements/FEMElements/rElHexa8.f90", "max_issues_repo_name": "gsoim/AnsysMSolve", "max_issues_repo_head_hexsha": "3a552a7559e8f02bf2f5682ea5c1836d7fd6663b", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 90, "max_issues_repo_issues_event_min_datetime": "2016-06-16T11:58:01.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-06T00:10:53.000Z", "max_forks_repo_path": "FEMElements/FEMElements/rElHexa8.f90", "max_forks_repo_name": "gsoim/AnsysMSolve", "max_forks_repo_head_hexsha": "3a552a7559e8f02bf2f5682ea5c1836d7fd6663b", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 28, "max_forks_repo_forks_event_min_datetime": "2016-07-19T13:50:30.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-09T21:53:32.000Z", "avg_line_length": 29.8129353234, "max_line_length": 91, "alphanum_fraction": 0.5935518323, "num_tokens": 14545, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147439, "lm_q2_score": 0.7371581510799252, "lm_q1q2_score": 0.6726097495251554}} {"text": "program Combinations\n use iso_fortran_env\n implicit none\n\n type comb_result\n integer, dimension(:), allocatable :: combs\n end type comb_result\n\n type(comb_result), dimension(:), pointer :: r\n integer :: i, j\n\n call comb(5, 3, r)\n do i = 0, choose(5, 3) - 1\n do j = 2, 0, -1\n write(*, \"(I4, ' ')\", advance=\"no\") r(i)%combs(j)\n end do\n deallocate(r(i)%combs)\n write(*,*) \"\"\n end do\n deallocate(r)\n\ncontains\n\n function choose(n, k, err)\n integer :: choose\n integer, intent(in) :: n, k\n integer, optional, intent(out) :: err\n\n integer :: imax, i, imin, ie\n\n ie = 0\n if ( (n < 0 ) .or. (k < 0 ) ) then\n write(ERROR_UNIT, *) \"negative in choose\"\n choose = 0\n ie = 1\n else\n if ( n < k ) then\n choose = 0\n else if ( n == k ) then\n choose = 1\n else\n imax = max(k, n-k)\n imin = min(k, n-k)\n choose = 1\n do i = imax+1, n\n choose = choose * i\n end do\n do i = 2, imin\n choose = choose / i\n end do\n end if\n end if\n if ( present(err) ) err = ie\n end function choose\n\n subroutine comb(n, k, co)\n integer, intent(in) :: n, k\n type(comb_result), dimension(:), pointer, intent(out) :: co\n\n integer :: i, j, s, ix, kx, hm, t\n integer :: err\n\n hm = choose(n, k, err)\n if ( err /= 0 ) then\n nullify(co)\n return\n end if\n\n allocate(co(0:hm-1))\n do i = 0, hm-1\n allocate(co(i)%combs(0:k-1))\n end do\n do i = 0, hm-1\n ix = i; kx = k\n do s = 0, n-1\n if ( kx == 0 ) exit\n t = choose(n-(s+1), kx-1)\n if ( ix < t ) then\n co(i)%combs(kx-1) = s\n kx = kx - 1\n else\n ix = ix - t\n end if\n end do\n end do\n\n end subroutine comb\n\nend program Combinations\n", "meta": {"hexsha": "42839f8a286fc6d5a5bdcc0ab94e111fb45ba168", "size": 1884, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Combinations/Fortran/combinations-1.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Combinations/Fortran/combinations-1.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Combinations/Fortran/combinations-1.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 20.9333333333, "max_line_length": 63, "alphanum_fraction": 0.4766454352, "num_tokens": 633, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.672538573602071}} {"text": "! NOTE: We use atomic units throughout the program\nprogram simple_md\n implicit none\n\n integer, parameter :: N_PARTICLES = 2\n integer, parameter :: N_STEP = 100\n ! TODO: Implement printing every 2nd step\n integer, parameter :: N_PRINT = 2\n ! TODO: Determine suitable timestep\n real(8), parameter :: DT = ??\n real(8), parameter :: AMU = 1823.0D0\n real(8), dimension(N_PARTICLES) :: mass\n real(8), dimension(N_PARTICLES) :: x, y\n real(8), dimension(N_PARTICLES) :: vx, vy\n real(8), dimension(N_PARTICLES) :: fx, fy\n\n character(len=20) :: potential = 'harmonic'\n ! Bond legth of N2 molecule\n ! https://cccbdb.nist.gov/exp2x.asp?casno=7727379\n real(8) :: r_eq = 1.098D0\n ! harmonic force constant in a.u. equivalent to 2359 cm^-1 vibration\n real(8) :: force_constant = 1.47497D0\n\n real(8) :: potential_energy\n real(8) :: calculate_kinetic_energy\n integer :: istep\n ! File units for output\n integer :: ucoords\n \n ! Defining inital conditions\n ! ================================\n ! Let's start with two particles bound by harmonic potential\n ! Specifically, let's simulate N2 molecule.\n x = 0.0D0\n y = (/ 0.0D0, 1.1D0 /)\n mass(1) = 14.0067 * AMU\n mass(2) = 14.0067 * AMU\n\n fx = 0.0D0\n fy = 0.0D0\n vx = 0.0D0\n vy = 0.0D0\n\n potential_energy = 0.0D0\n\n ! ================================\n open (newunit=ucoords, file='coords.xyz', action='write')\n\n ! MD LOOP, using Velocity Verlet integrator\n do istep = 1, N_STEP\n \n ! Implicit iteration here\n ! We can do simple matrix math with arrays as long as they have the same size\n vx = vx + fx / mass * DT * 0.5D0\n vy = vy + fy / mass * DT * 0.5D0\n\n x = x + vx * DT\n y = y + vy * DT\n\n if (potential == 'harmonic') then\n call harmonic_forces(force_constant, r_eq, x, y, fx, fy, potential_energy)\n else if (potential == 'morse') then\n ! TODO:\n print *, 'Morse potential not yet implemented'\n else\n print *, 'Invalid potential'\n stop 1\n end if\n \n vx = vx + fx / mass * DT * 0.5D0\n vy = vy + fy / mass * DT * 0.5D0\n\n call write_coords(N_PARTICLES, x, y, ucoords)\n\n end do\n\n close(ucoords)\nend program\n\nreal(8) function calculate_kinetic_energy(n_particles, vx, vy, mass) result(e_k)\n implicit none\n integer, intent(in) :: n_particles\n real(8), dimension(n_particles), intent(in) :: vx, vy, mass\n integer :: i\n e_k = 0\n do i = 1, N_PARTICLES\n e_k = e_k + 0.5D0 * mass(i) * (vx(i)**2 + vy(i)**2)\n end do\nend function\n\nsubroutine write_coords(natoms, x, y, channel)\n implicit none\n integer, intent(in) :: natoms\n real(8), dimension(natoms), intent(in) :: x, y\n integer, intent(in) :: channel\n integer :: i\n\n write (channel, *) natoms\n write (channel, *) 'comment line'\n do i = 1, natoms\n write (channel, '(A,3F10.5)') \"N\", x(i), y(i), 0.0D0\n end do\nend subroutine write_coords\n\nsubroutine harmonic_forces(k, r_eq, x, y, fx, fy, potential_energy)\n implicit none\n real(8), intent(in) :: k, r_eq\n real(8), dimension(2), intent(in) :: x, y\n real(8), dimension(2), intent(out) :: fx, fy\n real(8), intent(out) :: potential_energy\n real(8) :: r, delta_x, delta_y\n\n delta_x = x(1) - x(2)\n delta_y = y(1) - y(2)\n r = delta_x**2 + delta_y**2\n r = dsqrt(r)\n\n fx(1) = - k * delta_x * (r - r_eq) / r\n fx(2) = - fx(1)\n fy(1) = - k * delta_y * (r - r_eq) / r\n fy(2) = - fy(1)\n\n potential_energy = 0.5D0 * k * (r - r_eq)**2\nend subroutine harmonic_forces\n", "meta": {"hexsha": "f85e83e8a4882b80cb4f59b731de09b3ae7614ee", "size": 3537, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "simple-md.f90", "max_stars_repo_name": "danielhollas/acc-coding", "max_stars_repo_head_hexsha": "429a80b03c262b314a9070bdd415647791d42edd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "simple-md.f90", "max_issues_repo_name": "danielhollas/acc-coding", "max_issues_repo_head_hexsha": "429a80b03c262b314a9070bdd415647791d42edd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-09T15:20:28.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T00:23:42.000Z", "max_forks_repo_path": "simple-md.f90", "max_forks_repo_name": "danielhollas/acc-coding", "max_forks_repo_head_hexsha": "429a80b03c262b314a9070bdd415647791d42edd", "max_forks_repo_licenses": ["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.296, "max_line_length": 83, "alphanum_fraction": 0.5951371219, "num_tokens": 1186, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.6725385691384452}} {"text": "C--------------------------------------------------------------\nC THIS IS A TEST OF MODULE RFT2CH\nC \nC PORTED TO UNIX 6/25/93\nC--------------------------------------------------------------\n\tINCLUDE 'VICMAIN_FOR'\n\tSUBROUTINE MAIN44\n\tREAL*4 BUF(20),BUF2(20,22)\nC---------------------------------\nC FORTRAN - CALLABLE\nC---------------------------------\n\n CALL XVMESSAGE('*******FORTRAN-CALLABLE RFT2CH******',' ')\n\tCALL QPRINT('01-D CASE',9)\nC\nC-----CONSTRUCT INPUT VECTOR\n\tN=20\t\n\tDO 10 I=1,N\n10\tBUF(I) = I\n\tCALL PRNT(7,N,BUF,' INPUT R*4.')\nC\nC-----DO TRANSFORM\n\tCALL RFT2CH(BUF,1,N,1)\nC\n\tCALL PRNT(7,N+2,BUF,' CMPLX XFORM.')\nC-----INVERT TRANSFORM\n\tCALL RFT2CH(BUF,1,N,-1)\nC\nC-----RESCALE\n\tA=2*N\n\tCALL DIVV(7,N,A,BUF,0,1)\n\tCALL PRNT(7,N,BUF,' INVRS XFORM.')\nC\nC\nC---------------------------------------------------------\n\tCALL QPRINT('02-D CASE',9)\n\tN=20\n\tM=20\nC-----CONSTRUCT INPUT ARRAY\n\tDO 20 J=1,M\n\tDO 150 I=1,N\n150\tBUF2(I,J) = I + J\n20\tCALL PRNT(7,N,BUF2(1,J),' INPUT R*4.')\nC\nC-----DO TRANSFORM\n\tCALL RFT2CH(BUF2,M,N,1)\n\tDO 30 J=1,M+2\n30\tCALL PRNT(7,N,BUF2(1,J),' CMPLX XFORM.')\nC\nC-----DO INVERSE\n\tCALL RFT2CH(BUF2,M,N,-1)\nC\n\tA=2*M*N\n\tDO 40 J=1,M\n\tCALL DIVV(7,N,A,BUF2(1,J),0,1)\n40\tCALL PRNT(7,N,BUF2(1,J),' INVRS XFORM.')\nC\nC--------------------------------------------------------------\nC ----C-CALLABLE\nC--------------------------------------------------------------\n CALL XVMESSAGE('**********C-CALLABLE RFT2CH*******',' ')\n\tCALL QPRINT('01-D CASE',9)\nC\nC-----CONSTRUCT INPUT VECTOR\n\tN=20\t\n\tDO 210 I=1,N\n210\tBUF(I) = I\n\tCALL PRNT(7,N,BUF,' INPUT R*4.')\nC\nC-----DO TRANSFORM\n\tCALL TZRFT2CH(BUF,1,N,1)\nC\n\tCALL PRNT(7,N+2,BUF,' CMPLX XFORM.')\nC-----INVERT TRANSFORM\n\tCALL TZRFT2CH(BUF,1,N,-1)\nC\nC-----RESCALE\n\tA=2*N\n\tCALL DIVV(7,N,A,BUF,0,1)\n\tCALL PRNT(7,N,BUF,' INVRS XFORM.')\nC\nC\nC---------------------------------------------------------\n\tCALL QPRINT('02-D CASE',9)\n\tN=20\n\tM=20\nC-----CONSTRUCT INPUT ARRAY\n\tDO 220 J=1,M\n\tDO 350 I=1,N\n350\tBUF2(I,J) = I + J\n220\tCALL PRNT(7,N,BUF2(1,J),' INPUT R*4.')\nC\nC-----DO TRANSFORM\n\tCALL TZRFT2CH(BUF2,M,N,1)\n\tDO 230 J=1,M+2\n230\tCALL PRNT(7,N,BUF2(1,J),' CMPLX XFORM.')\nC\nC-----DO INVERSE\n\tCALL TZRFT2CH(BUF2,M,N,-1)\nC\n\tA=2*M*N\n\tDO 240 J=1,M\n\tCALL DIVV(7,N,A,BUF2(1,J),0,1)\n240\tCALL PRNT(7,N,BUF2(1,J),' INVRS XFORM.')\nC\n\tRETURN\n\tEND\n\n", "meta": {"hexsha": "be7f44f3be70abe1b2474c6e138c9d977680fc91", "size": 2299, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "vos/p2/sub/rft2ch/test/trft2ch.f", "max_stars_repo_name": "NASA-AMMOS/VICAR", "max_stars_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2020-10-21T05:56:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T10:02:01.000Z", "max_issues_repo_path": "vos/p2/sub/rft2ch/test/trft2ch.f", "max_issues_repo_name": "NASA-AMMOS/VICAR", "max_issues_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "vos/p2/sub/rft2ch/test/trft2ch.f", "max_forks_repo_name": "NASA-AMMOS/VICAR", "max_forks_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-03-09T01:51:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-23T00:23:24.000Z", "avg_line_length": 21.0917431193, "max_line_length": 66, "alphanum_fraction": 0.4993475424, "num_tokens": 890, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240964782011, "lm_q2_score": 0.7772998560157663, "lm_q1q2_score": 0.6725385656138773}} {"text": "! Integro diff eq. 13 oct 2014 (Reformatted)\n! http://www.uprh.edu/rbaretti/IntegroDE13oct2014.htm\n\n! declarations: types, data, and print format\n implicit real*8 (a-h, o-z)\n data nstep, L /2000, 4.d0/\n 100 format('x, phi, phiex, ratio = ' 4(3x, e10.3))\n\n! initial values:\n phiex(x) = (1.d0 / 2.d0) &\n * dexp(-x) &\n * dsin(2.d0 * x)\n dx = L / dfloat(nstep)\n kp = int(dfloat(nstep) / 40.d0)\n kount = kp\n phi0 = 0.d0\n uprime0 = 1.d0\n phi1 = phi0 + dx * uprime0\n\n! print initial values\n print 100, &\n 0.d0, &\n phi0, &\n phiex(0.d0), &\n phi0 / phiex(0.d0)\n\n! for loop\n do i = 2, nstep\n x = dx * dfloat(i)\n dphidx = (phi1 - phi0) / dx\n\n! because i >= 2, this block is never entered,\n! making the if statement is unnecessary\n if (i .eq. 1) then\n phi2 = 2.d0 * phi1 &\n - phi0 &\n + dx ** 2 &\n * (- 2.d0 * dphidx &\n - 5.d0 * phi1 &\n + 1.d0 / dx)\n else\n phi2 = 2.d0 * phi1 &\n - phi0 &\n + dx ** 2 &\n * (- 2.d0 * dphidx &\n - 5.d0 * phi1)\n end if\n! every kp number of iterations, print\n if (i .eq. kount) then\n print 100, &\n x, &\n phi2, &\n phiex(x), &\n phi2 / phiex(x)\n kount = kount + kp\n end if\n\n phi0 = phi1\n phi1 = phi2\n end do\n stop\n end\n\n\n! approximation for dirac delta function\n! 1/dx near zero, 0 elsewhere\n function delta(x, dx)\n implicit real*8 (a-h, o-z)\n if (x .le. dx) then\n delta = 1.d0 / dx\n else\n delta = 0.d0\n end if\n return\n end\n", "meta": {"hexsha": "4e937f7266596622844bd9b2e3e2faa558e100d2", "size": 2151, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "examples/difference.f95", "max_stars_repo_name": "bangyen/evolution", "max_stars_repo_head_hexsha": "084d95558ca21fc3485c6e8de9b97afaa4318aed", "max_stars_repo_licenses": ["MIT"], "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/difference.f95", "max_issues_repo_name": "bangyen/evolution", "max_issues_repo_head_hexsha": "084d95558ca21fc3485c6e8de9b97afaa4318aed", "max_issues_repo_licenses": ["MIT"], "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/difference.f95", "max_forks_repo_name": "bangyen/evolution", "max_forks_repo_head_hexsha": "084d95558ca21fc3485c6e8de9b97afaa4318aed", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-30T22:40:43.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T22:40:43.000Z", "avg_line_length": 28.3026315789, "max_line_length": 53, "alphanum_fraction": 0.3686657369, "num_tokens": 623, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240791017536, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.6725385565707931}} {"text": "Program final\n\tImplicit none\n\treal*8 :: infty, x, dx, e, de, tol\n\treal*8, dimension(2) :: y\n\treal*8, external :: f_x, g_x\n\tcharacter (len=10) :: filename\n\tinteger :: n=1\n\n! parameters\n\ttol = epsilon(0.0d0) ! tolerance of 0\n\tinfty = 4.d0 ! where psi(infty) is considered to be tol\n\n\tdx = 0.1d-3\n\n\topen(10, file=\"psi.dat\")\n\n\te = -6.d0\n\tdo while (e.lt.0)\n\t\tx = -infty\n\t\ty(1) = 0.02 ! initial psi at x=infty\n\t\ty(2) = tol ! initial psi' at x=infty\n\n\t\tdo while( x.le.infty )\n\t\t\tcall rk4(x, dx, f_x, g_x, y, e)\n\t\t\tx = x + dx\n\t\tenddo\n\t\tde = 4.9d0**( log10(abs(y(1))) - 26 )\n\t\twrite(10,*) e, y(1), de\n\t\te = e + de\n\t\tprint *, e, de, y(1)\n\tenddo\n\tclose(10)\n\nend program final\n\n\n! 4th-order Runge-Kutta subroutine \nsubroutine rk4(x, dx, df, dg, y, e)\n\timplicit none\n\treal*8, external :: df, dg\n\treal*8, intent(in) :: x, dx, e\n\treal*8, intent(inout), dimension(2) :: y\n\treal*8 :: h, k0, k1, k2, k3, l0, l1, l2, l3\n\n\th=dx/2.0D0\n\n\tk0 = dx * df(y(1),y(2))\n\tl0 = dx * dg(y(1),y(2),x,e)\n\tk1 = dx * df(y(1)+h, y(2)+0.5d0*l0)\n\tl1 = dx * dg(y(1)+0.5d0*k0,y(2)+0.5d0*l0,x,e)\n\tk2 = dx * df(y(1)+0.5d0*k1,y(2)+0.5d0*l1)\n\tl2 = dx * dg(y(1)+0.5d0*k1,y(2)+0.5d0*l1,x,e)\n\tk3 = dx * df(y(1)+k2,y(2)+l2)\n\tl3 = dx * dg(y(1)+k2,y(2)+l2,x,e)\n\ty(1) = y(1) + (k0+2*k1+2*k2+k3)/6.0d0\n\ty(2) = y(2) + (l0+2*l1+2*l2+l3)/6.0d0\n\tReturn\nEnd subroutine rk4\n\n! function which returns the derivatives (RHS)\nreal*8 function f_x(y, yp)\n! dpsi/dx = psi'\n\tImplicit none\n\treal*8 ,intent(in) :: y, yp\n\tf_x = yp\n\tReturn\nEnd function f_x\n\nreal*8 function g_x(y, yp, x, e)\n! d^2y/dx^2 = 2(V(x)-e)*y = (4x^4-16x^2-2e)y\n\timplicit none\n\treal*8, intent(in) :: y, yp, x, e\n!\tg_x = ( -4.0d0 - e) * y\n\tg_x = ( 4.0d0 * x**4.0d0 - 16.0d0 * x**2.0d0 - 2.0d0*e) * y\n!\tg_x = 2.d0 * ( (x+sqrt(2.d0))**2.d0-8 - e) * y\n\tReturn\nEnd function g_x", "meta": {"hexsha": "a1eaa7b11b7002fcbf4b7e0e084eefd4dae5105f", "size": 1774, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Final/psive.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": "Final/psive.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": "Final/psive.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": 23.038961039, "max_line_length": 60, "alphanum_fraction": 0.5653889515, "num_tokens": 868, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818864, "lm_q2_score": 0.7401743677704878, "lm_q1q2_score": 0.6725356810703724}} {"text": "*DECK HSTCRT\n SUBROUTINE HSTCRT (A, B, M, MBDCND, BDA, BDB, C, D, N, NBDCND,\n + BDC, BDD, ELMBDA, F, IDIMF, PERTRB, IERROR, W)\nC***BEGIN PROLOGUE HSTCRT\nC***PURPOSE Solve the standard five-point finite difference\nC approximation on a staggered grid to the Helmholtz equation\nC in Cartesian coordinates.\nC***LIBRARY SLATEC (FISHPACK)\nC***CATEGORY I2B1A1A\nC***TYPE SINGLE PRECISION (HSTCRT-S)\nC***KEYWORDS ELLIPTIC, FISHPACK, HELMHOLTZ, PDE\nC***AUTHOR Adams, J., (NCAR)\nC Swarztrauber, P. N., (NCAR)\nC Sweet, R., (NCAR)\nC***DESCRIPTION\nC\nC HSTCRT solves the standard five-point finite difference\nC approximation on a staggered grid to the Helmholtz equation in\nC Cartesian coordinates\nC\nC (d/dX)(dU/dX) + (d/dY)(dU/dY) + LAMBDA*U = F(X,Y)\nC\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC\nC * * * * * * * * Parameter Description * * * * * * * * * *\nC\nC * * * * * * On Input * * * * * *\nC\nC A,B\nC The range of X, i.e. A .LE. X .LE. B. A must be less than B.\nC\nC M\nC The number of grid points in the interval (A,B). The grid points\nC in the X-direction are given by X(I) = A + (I-0.5)dX for\nC I=1,2,...,M where dX =(B-A)/M. M must be greater than 2.\nC\nC MBDCND\nC Indicates the type of boundary conditions at X = A and X = B.\nC\nC = 0 If the solution is periodic in X,\nC U(M+I,J) = U(I,J).\nC\nC = 1 If the solution is specified at X = A and X = B.\nC\nC = 2 If the solution is specified at X = A and the derivative\nC of the solution with respect to X is specified at X = B.\nC\nC = 3 If the derivative of the solution with respect to X is\nC specified at X = A and X = B.\nC\nC = 4 If the derivative of the solution with respect to X is\nC specified at X = A and the solution is specified at X = B.\nC\nC BDA\nC A one-dimensional array of length N that specifies the boundary\nC values (if any) of the solution at X = A. When MBDCND = 1 or 2,\nC\nC BDA(J) = U(A,Y(J)) , J=1,2,...,N.\nC\nC When MBDCND = 3 or 4,\nC\nC BDA(J) = (d/dX)U(A,Y(J)) , J=1,2,...,N.\nC\nC BDB\nC A one-dimensional array of length N that specifies the boundary\nC values of the solution at X = B. When MBDCND = 1 or 4\nC\nC BDB(J) = U(B,Y(J)) , J=1,2,...,N.\nC\nC When MBDCND = 2 or 3\nC\nC BDB(J) = (d/dX)U(B,Y(J)) , J=1,2,...,N.\nC\nC C,D\nC The range of Y, i.e. C .LE. Y .LE. D. C must be less\nC than D.\nC\nC N\nC The number of unknowns in the interval (C,D). The unknowns in\nC the Y-direction are given by Y(J) = C + (J-0.5)DY,\nC J=1,2,...,N, where DY = (D-C)/N. N must be greater than 2.\nC\nC NBDCND\nC Indicates the type of boundary conditions at Y = C\nC and Y = D.\nC\nC = 0 If the solution is periodic in Y, i.e.\nC U(I,J) = U(I,N+J).\nC\nC = 1 If the solution is specified at Y = C and Y = D.\nC\nC = 2 If the solution is specified at Y = C and the derivative\nC of the solution with respect to Y is specified at Y = D.\nC\nC = 3 If the derivative of the solution with respect to Y is\nC specified at Y = C and Y = D.\nC\nC = 4 If the derivative of the solution with respect to Y is\nC specified at Y = C and the solution is specified at Y = D.\nC\nC BDC\nC A one dimensional array of length M that specifies the boundary\nC values of the solution at Y = C. When NBDCND = 1 or 2,\nC\nC BDC(I) = U(X(I),C) , I=1,2,...,M.\nC\nC When NBDCND = 3 or 4,\nC\nC BDC(I) = (d/dY)U(X(I),C), I=1,2,...,M.\nC\nC When NBDCND = 0, BDC is a dummy variable.\nC\nC BDD\nC A one-dimensional array of length M that specifies the boundary\nC values of the solution at Y = D. When NBDCND = 1 or 4,\nC\nC BDD(I) = U(X(I),D) , I=1,2,...,M.\nC\nC When NBDCND = 2 or 3,\nC\nC BDD(I) = (d/dY)U(X(I),D) , I=1,2,...,M.\nC\nC When NBDCND = 0, BDD is a dummy variable.\nC\nC ELMBDA\nC The constant LAMBDA in the Helmholtz equation. If LAMBDA is\nC greater than 0, a solution may not exist. However, HSTCRT will\nC attempt to find a solution.\nC\nC F\nC A two-dimensional array that specifies the values of the right\nC side of the Helmholtz equation. For I=1,2,...,M and J=1,2,...,N\nC\nC F(I,J) = F(X(I),Y(J)) .\nC\nC F must be dimensioned at least M X N.\nC\nC IDIMF\nC The row (or first) dimension of the array F as it appears in the\nC program calling HSTCRT. This parameter is used to specify the\nC variable dimension of F. IDIMF must be at least M.\nC\nC W\nC A one-dimensional array that must be provided by the user for\nC work space. W may require up to 13M + 4N + M*INT(log2(N))\nC locations. The actual number of locations used is computed by\nC HSTCRT and is returned in the location W(1).\nC\nC\nC * * * * * * On Output * * * * * *\nC\nC F\nC Contains the solution U(I,J) of the finite difference\nC approximation for the grid point (X(I),Y(J)) for\nC I=1,2,...,M, J=1,2,...,N.\nC\nC PERTRB\nC If a combination of periodic or derivative boundary conditions is\nC specified for a Poisson equation (LAMBDA = 0), a solution may not\nC exist. PERTRB is a constant, calculated and subtracted from F,\nC which ensures that a solution exists. HSTCRT then computes this\nC solution, which is a least squares solution to the original\nC approximation. This solution plus any constant is also a\nC solution; hence, the solution is not unique. The value of PERTRB\nC should be small compared to the right side F. Otherwise, a\nC solution is obtained to an essentially different problem. This\nC comparison should always be made to insure that a meaningful\nC solution has been obtained.\nC\nC IERROR\nC An error flag that indicates invalid input parameters.\nC Except for numbers 0 and 6, a solution is not attempted.\nC\nC = 0 No error\nC\nC = 1 A .GE. B\nC\nC = 2 MBDCND .LT. 0 or MBDCND .GT. 4\nC\nC = 3 C .GE. D\nC\nC = 4 N .LE. 2\nC\nC = 5 NBDCND .LT. 0 or NBDCND .GT. 4\nC\nC = 6 LAMBDA .GT. 0\nC\nC = 7 IDIMF .LT. M\nC\nC = 8 M .LE. 2\nC\nC Since this is the only means of indicating a possibly\nC incorrect call to HSTCRT, the user should test IERROR after\nC the call.\nC\nC W\nC W(1) contains the required length of W.\nC\nC *Long Description:\nC\nC * * * * * * * Program Specifications * * * * * * * * * * * *\nC\nC Dimension of BDA(N),BDB(N),BDC(M),BDD(M),F(IDIMF,N),\nC Arguments W(See argument list)\nC\nC Latest June 1, 1977\nC Revision\nC\nC Subprograms HSTCRT,POISTG,POSTG2,GENBUN,POISD2,POISN2,POISP2,\nC Required COSGEN,MERGE,TRIX,TRI3,PIMACH\nC\nC Special NONE\nC Conditions\nC\nC Common NONE\nC Blocks\nC\nC I/O NONE\nC\nC Precision Single\nC\nC Specialist Roland Sweet\nC\nC Language FORTRAN\nC\nC History Written by Roland Sweet at NCAR in January , 1977\nC\nC Algorithm This subroutine defines the finite-difference\nC equations, incorporates boundary data, adjusts the\nC right side when the system is singular and calls\nC either POISTG or GENBUN which solves the linear\nC system of equations.\nC\nC Space 8131(decimal) = 17703(octal) locations on the\nC Required NCAR Control Data 7600\nC\nC Timing and The execution time T on the NCAR Control Data\nC Accuracy 7600 for subroutine HSTCRT is roughly proportional\nC to M*N*log2(N). Some typical values are listed in\nC the table below.\nC The solution process employed results in a loss\nC of no more than FOUR significant digits for N and M\nC as large as 64. More detailed information about\nC accuracy can be found in the documentation for\nC subroutine POISTG which is the routine that\nC actually solves the finite difference equations.\nC\nC\nC M(=N) MBDCND NBDCND T(MSECS)\nC ----- ------ ------ --------\nC\nC 32 1-4 1-4 56\nC 64 1-4 1-4 230\nC\nC Portability American National Standards Institute Fortran.\nC The machine dependent constant PI is defined in\nC function PIMACH.\nC\nC Required COS\nC Resident\nC Routines\nC\nC Reference Schumann, U. and R. Sweet,'A Direct Method For\nC The Solution Of Poisson's Equation With Neumann\nC Boundary Conditions On A Staggered Grid Of\nC Arbitrary Size,' J. COMP. PHYS. 20(1976),\nC PP. 171-182.\nC\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC\nC***REFERENCES U. Schumann and R. Sweet, A direct method for the\nC solution of Poisson's equation with Neumann boundary\nC conditions on a staggered grid of arbitrary size,\nC Journal of Computational Physics 20, (1976),\nC pp. 171-182.\nC***ROUTINES CALLED GENBUN, POISTG\nC***REVISION HISTORY (YYMMDD)\nC 801001 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890531 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE HSTCRT\nC\nC\n DIMENSION F(IDIMF,*) ,BDA(*) ,BDB(*) ,BDC(*) ,\n 1 BDD(*) ,W(*)\nC***FIRST EXECUTABLE STATEMENT HSTCRT\n IERROR = 0\n IF (A .GE. B) IERROR = 1\n IF (MBDCND.LT.0 .OR. MBDCND.GT.4) IERROR = 2\n IF (C .GE. D) IERROR = 3\n IF (N .LE. 2) IERROR = 4\n IF (NBDCND.LT.0 .OR. NBDCND.GT.4) IERROR = 5\n IF (IDIMF .LT. M) IERROR = 7\n IF (M .LE. 2) IERROR = 8\n IF (IERROR .NE. 0) RETURN\n NPEROD = NBDCND\n MPEROD = 0\n IF (MBDCND .GT. 0) MPEROD = 1\n DELTAX = (B-A)/M\n TWDELX = 1./DELTAX\n DELXSQ = 2./DELTAX**2\n DELTAY = (D-C)/N\n TWDELY = 1./DELTAY\n DELYSQ = DELTAY**2\n TWDYSQ = 2./DELYSQ\n NP = NBDCND+1\n MP = MBDCND+1\nC\nC DEFINE THE A,B,C COEFFICIENTS IN W-ARRAY.\nC\n ID2 = M\n ID3 = ID2+M\n ID4 = ID3+M\n S = (DELTAY/DELTAX)**2\n ST2 = 2.*S\n DO 101 I=1,M\n W(I) = S\n J = ID2+I\n W(J) = -ST2+ELMBDA*DELYSQ\n J = ID3+I\n W(J) = S\n 101 CONTINUE\nC\nC ENTER BOUNDARY DATA FOR X-BOUNDARIES.\nC\n GO TO (111,102,102,104,104),MP\n 102 DO 103 J=1,N\n F(1,J) = F(1,J)-BDA(J)*DELXSQ\n 103 CONTINUE\n W(ID2+1) = W(ID2+1)-W(1)\n GO TO 106\n 104 DO 105 J=1,N\n F(1,J) = F(1,J)+BDA(J)*TWDELX\n 105 CONTINUE\n W(ID2+1) = W(ID2+1)+W(1)\n 106 GO TO (111,107,109,109,107),MP\n 107 DO 108 J=1,N\n F(M,J) = F(M,J)-BDB(J)*DELXSQ\n 108 CONTINUE\n W(ID3) = W(ID3)-W(1)\n GO TO 111\n 109 DO 110 J=1,N\n F(M,J) = F(M,J)-BDB(J)*TWDELX\n 110 CONTINUE\n W(ID3) = W(ID3)+W(1)\n 111 CONTINUE\nC\nC ENTER BOUNDARY DATA FOR Y-BOUNDARIES.\nC\n GO TO (121,112,112,114,114),NP\n 112 DO 113 I=1,M\n F(I,1) = F(I,1)-BDC(I)*TWDYSQ\n 113 CONTINUE\n GO TO 116\n 114 DO 115 I=1,M\n F(I,1) = F(I,1)+BDC(I)*TWDELY\n 115 CONTINUE\n 116 GO TO (121,117,119,119,117),NP\n 117 DO 118 I=1,M\n F(I,N) = F(I,N)-BDD(I)*TWDYSQ\n 118 CONTINUE\n GO TO 121\n 119 DO 120 I=1,M\n F(I,N) = F(I,N)-BDD(I)*TWDELY\n 120 CONTINUE\n 121 CONTINUE\n DO 123 I=1,M\n DO 122 J=1,N\n F(I,J) = F(I,J)*DELYSQ\n 122 CONTINUE\n 123 CONTINUE\n IF (MPEROD .EQ. 0) GO TO 124\n W(1) = 0.\n W(ID4) = 0.\n 124 CONTINUE\n PERTRB = 0.\n IF (ELMBDA) 133,126,125\n 125 IERROR = 6\n GO TO 133\n 126 GO TO (127,133,133,127,133),MP\n 127 GO TO (128,133,133,128,133),NP\nC\nC FOR SINGULAR PROBLEMS MUST ADJUST DATA TO INSURE THAT A SOLUTION\nC WILL EXIST.\nC\n 128 CONTINUE\n S = 0.\n DO 130 J=1,N\n DO 129 I=1,M\n S = S+F(I,J)\n 129 CONTINUE\n 130 CONTINUE\n PERTRB = S/(M*N)\n DO 132 J=1,N\n DO 131 I=1,M\n F(I,J) = F(I,J)-PERTRB\n 131 CONTINUE\n 132 CONTINUE\n PERTRB = PERTRB/DELYSQ\nC\nC SOLVE THE EQUATION.\nC\n 133 CONTINUE\n IF (NPEROD .EQ. 0) GO TO 134\n CALL POISTG (NPEROD,N,MPEROD,M,W(1),W(ID2+1),W(ID3+1),IDIMF,F,\n 1 IERR1,W(ID4+1))\n GO TO 135\n 134 CONTINUE\n CALL GENBUN (NPEROD,N,MPEROD,M,W(1),W(ID2+1),W(ID3+1),IDIMF,F,\n 1 IERR1,W(ID4+1))\n 135 CONTINUE\n W(1) = W(ID4+1)+3*M\n RETURN\n END\n", "meta": {"hexsha": "77c43acfe41a3aba5223c134b6607656b2724e80", "size": 13104, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/hstcrt.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/hstcrt.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/hstcrt.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.4244604317, "max_line_length": 72, "alphanum_fraction": 0.5573870574, "num_tokens": 4584, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096204605945, "lm_q2_score": 0.7341195385342971, "lm_q1q2_score": 0.6725339718193617}} {"text": "submodule(euler_interface_m) euler_prob_0033_m\n implicit none\n\ncontains\n\n module character(len=20) function euler0033()\n write (euler0033, \"(i20)\") ans()\n end function euler0033\n\n integer function ans()\n integer :: c, d, n, dp, np\n\n c = 1; d = 1; n = 1\n np = 1; dp = 1\n\n do c = 1, 9\n do d = 1, c - 1\n do n = 1, d - 1\n if ((n*10 + c)*d == (c*10 + d)*n) then\n np = np*n\n dp = dp*d\n end if\n end do\n end do\n end do\n ans = dp/gcd(np, dp)\n end function ans\n\nend submodule euler_prob_0033_m\n", "meta": {"hexsha": "a330d3a8998100abb8cac91a12afa1f08890a8d0", "size": 684, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "docs/src/prob_0033_m.f90", "max_stars_repo_name": "han190/PE-Fortran", "max_stars_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-02-09T07:07:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-31T07:45:48.000Z", "max_issues_repo_path": "docs/src/prob_0033_m.f90", "max_issues_repo_name": "han190/PE-Fortran", "max_issues_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-14T00:48:58.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-14T00:48:58.000Z", "max_forks_repo_path": "docs/src/prob_0033_m.f90", "max_forks_repo_name": "han190/PE-Fortran", "max_forks_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-04T21:29:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T21:29:45.000Z", "avg_line_length": 22.8, "max_line_length": 58, "alphanum_fraction": 0.4415204678, "num_tokens": 206, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096158798115, "lm_q2_score": 0.7341195385342971, "lm_q1q2_score": 0.6725339684565195}} {"text": "c\nc-----------------------------------------------------------------------\nc\n subroutine p20fn(xcen,ycen,q,time)\n implicit double precision(a-h,o-z)\n dimension q(1)\nc\nc # For the point (x,y), compute the true solution at this point \nc\n xshift = 1.5\n yshift = 1.5\n pi = 3.14159265357989d0\n\n yuse = ycen - yshift\n xuse = xcen - xshift\n radius = dsqrt(yuse**2+xuse**2)\n sr = 2.d0*pi/5.d0 ! goes around one full circle in 5 time units\n\n theta = atan2(yuse,xuse)\n\n thetause = theta - sr*time\n xinit = cos(thetause)\n yinit = sin(thetause)\n \n thetainit = atan2(yinit,xinit)\n\n w = .5d0*( erf((pi/6.d0-thetainit)/sqrt(4.d0/100.d0)) + \n & erf((pi/6.d0+thetainit)/sqrt(4.d0/100.d0)) )\n\nc theta = atan2(ycen-yshift,xcen-xshift)\nc w = .5d0*( erf((pi/6.d0-theta)/sqrt(4.d0/100.d0)) + \nc & erf((pi/6.d0+theta)/sqrt(4.d0/100.d0)) )\n\n q(1) = w\nc q(1) = 1.0\nc stick in prob 16 into prob 20\nc q(1) = ycen - .1*xcen + .5\n\n return\n end\n", "meta": {"hexsha": "b3002b1becd85fbd6a343d5e5b73ac1668a5b121", "size": 1096, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/2d/ag_ho/p20fn.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/p20fn.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/p20fn.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": 26.7317073171, "max_line_length": 76, "alphanum_fraction": 0.4954379562, "num_tokens": 387, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096090086367, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6725339580831939}} {"text": "program main\n implicit none\n integer, parameter :: dp = selected_real_kind(8)\n real(dp), parameter :: pi = acos(-1.d0), NA = 6.02214076d23, kB = 1.380649d-23\n integer(1) :: i\n real(dp) :: T(7) = (/.1d0, 1.d0, 5.d0, 8.d0, 10.d0, 15.d0, 20.d0/)\n real(dp) :: C(7) = (/8.5d-7, 8.6d-4, 1.2d-1, 5.9d-1, 1.1d0, 2.8d0, 6.3d0/)\n real(dp) :: TTSum = 0.d0, TCSum = 0.d0, result\n\n T = T**3\n do i = 1,7\n TTSum = TTSum + T(i)**2\n TCSum = TCSum + T(i) * C(i)\n end do\n result = (12 * pi**4 * NA * kB / (5 * (TCSum / TTSum)))**(1.d0/3.d0)\n write(*,*) result\nend program main\n", "meta": {"hexsha": "ea7b9c397a95b2b2a536a5f86ba23c3fbc94e1f4", "size": 608, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Assignment-1/2-C-T.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-1/2-C-T.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-1/2-C-T.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": 33.7777777778, "max_line_length": 82, "alphanum_fraction": 0.5131578947, "num_tokens": 290, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.91610961358942, "lm_q2_score": 0.734119526900183, "lm_q1q2_score": 0.6725339561169745}} {"text": "SUBROUTINE p74(input_file,output_file) \n!-------------------------------------------------------------------------\n! SUBROUTINE 7.4 General two- (plane) or three-dimensional analysis of steady\n! seepage.\n!-------------------------------------------------------------------------\n USE main; \n USE geom; \n IMPLICIT NONE \n CHARACTER(len=60),INTENT(IN) :: input_file\n CHARACTER(len=60),INTENT(OUT) :: output_file \n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\n INTEGER::fixed_freedoms,i,iel,k,loaded_nodes,nci,ndim,nels,neq,nip,nlen, &\n nod,nn,np_types; \n CHARACTER(LEN=15)::argv,element\n REAL(iwp)::det,penalty=1.0e20_iwp,zero=0.0_iwp\n!-----------------------dynamic arrays------------------------------------\n INTEGER,ALLOCATABLE::etype(:),g_num(:,:),kdiag(:),node(:),num(:)\n REAL(iwp),ALLOCATABLE::coord(:,:),der(:,:),deriv(:,:),disps(:), &\n g_coord(:,:),jac(:,:),kay(:,:),kp(:,:),kv(:),kvh(:),loads(:), &\n points(:,:),prop(:,:),value(:),weights(:)\n!-----------------------input and initialisation--------------------------\n \n OPEN(10,FILE=input_file); \n OPEN(11,FILE=output_file)\n READ(10,*)element,nod,nels,nn,nip,ndim,np_types; \n neq=nn\n ALLOCATE(points(nip,ndim),g_coord(ndim,nn),coord(nod,ndim),etype(nels), &\n jac(ndim,ndim),weights(nip),num(nod),g_num(nod,nels),der(ndim,nod), &\n deriv(ndim,nod),kp(nod,nod),kay(ndim,ndim),prop(ndim,np_types), &\n kdiag(neq),loads(0:neq),disps(0:neq))\n READ(10,*)prop; \n etype=1; \n IF(np_types>1)READ(10,*)etype\n READ(10,*)g_coord; \n READ(10,*)g_num\n IF(ndim==2)CALL mesh(g_coord,g_num,argv,nlen,12); \n kdiag=0\n!-----------------------loop the elements to find global arrays sizes-----\n elements_1: DO iel =1,nels; \n num=g_num(:,iel); \n CALL fkdiag(kdiag,num) \n END DO elements_1\n DO i=2,neq; \n kdiag(i)=kdiag(i)+kdiag(i-1); \n END DO\n WRITE(11,'(2(A,I5))') &\n \" There are\",neq,\" equations and the skyline storage is\",kdiag(neq)\n ALLOCATE(kv(kdiag(neq)),kvh(kdiag(neq))); \n kv=zero\n CALL sample(element,points,weights) \n!-----------------------global conductivity matrix assembly---------------\n elements_2: DO iel=1,nels\n kay=zero; \n DO i=1,ndim; \n kay(i,i)=prop(i,etype(iel)); \n END DO\n num=g_num(:,iel); \n coord=TRANSPOSE(g_coord(:,num)); \n kp=zero\n gauss_pts_1: DO i=1,nip\n CALL shape_der(der,points,i); \n jac=MATMUL(der,coord)\n det=determinant(jac); \n CALL invert(jac); \n deriv=MATMUL(jac,der)\n kp=kp+MATMUL(MATMUL(TRANSPOSE(deriv),kay),deriv)*det*weights(i)\n END DO gauss_pts_1; \n CALL fsparv(kv,kp,num,kdiag)\n END DO elements_2; \n kvh=kv \n!-----------------------specify boundary values---------------------------\n loads=zero; \n READ(10,*)loaded_nodes,(k,loads(k),i=1,loaded_nodes) \n READ(10,*)fixed_freedoms \n IF(fixed_freedoms/=0)THEN\n ALLOCATE(node(fixed_freedoms),value(fixed_freedoms))\n READ(10,*)(node(i),value(i),i=1,fixed_freedoms)\n kv(kdiag(node))=kv(kdiag(node))+penalty\n loads(node)=kv(kdiag(node))*value\n END IF\n!-----------------------equation solution---------------------------------\n CALL sparin(kv,kdiag); \n CALL spabac(kv,loads,kdiag)\n!-----------------------retrieve nodal net flow rates---------------------\n CALL linmul_sky(kvh,loads,disps,kdiag) \n WRITE(11,'(/A)')\" Node Total Head Flow rate\"\n DO k=1,nn; \n WRITE(11,'(I5,2E12.4)')k,loads(k),disps(k); \n END DO \n disps(0)=zero; \n WRITE(11,'(/A)')\" Inflow Outflow\"\n WRITE(11,'(5X,2E12.4)') &\n SUM(disps,MASK=disps>zero),SUM(disps,MASK=disps null()\n procedure (g), pointer, save :: gpi => null()\n\n if(present(fi) .and. present(gi))then\n fpi => fi\n gpi => gi\n compose = 0\n return\n endif\n\n if(.not. associated(fpi)) error stop \"fpi\"\n if(.not. associated(gpi)) error stop \"gpi\"\n\n compose = fpi(gpi(x))\n\n contains\n\n end function compose\n\nend module compose_module\n\nprogram test_compose\n use functions_module\n use compose_module\n implicit none\n write(*,*) \"prepare compose:\", compose(0.0, f,g)\n write(*,*) \"run compose:\", compose(0.5)\nend program test_compose\n", "meta": {"hexsha": "7b9a9014e31dc33dadcdc88e074ec300ba13f8c1", "size": 1557, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Function-composition/Fortran/function-composition.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/Function-composition/Fortran/function-composition.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/Function-composition/Fortran/function-composition.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 19.4625, "max_line_length": 51, "alphanum_fraction": 0.5786769428, "num_tokens": 412, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677737461007, "lm_q2_score": 0.7931059487389968, "lm_q1q2_score": 0.6725282856969961}} {"text": "C ****************************************************************************\nC FILE: mpi_pi_reduce.f \nC DESCRIPTION: \nC MPI pi Calculation Example - Fortran Version\nC Collective Communications examples\nC This program calculates pi using a \"dartboard\" algorithm. See\nC Fox et al.(1988) Solving Problems on Concurrent Processors, vol.1\nC page 207. All processes contribute to the calculation, with the\nC master averaging the values for pi. SPMD Version: Conditional \nC statements check if the process is the master or a worker.\nC This version uses mp_reduce to collect results\nC Note: Requires Fortran90 compiler due to random_number() function\nC AUTHOR: Blaise Barney. Adapted from Ros Leibensperger, Cornell Theory\nC Center. Converted to MPI: George L. Gusciora, MHPCC (1/95) \nC LAST REVISED: 06/13/13 Blaise Barney\nC ****************************************************************************\nC Explanation of constants and variables used in this program:\nC DARTS = number of throws at dartboard \nC ROUNDS = number of times \"DARTS\" is iterated \nC MASTER = task ID of master task\nC taskid = task ID of current task \nC numtasks = number of tasks\nC homepi = value of pi calculated by current task\nC pisum = sum of tasks' pi values \nC pi \t = average of pi for this iteration\nC avepi = average pi value for all iterations \nC seednum = seed number - based on taskid\n\n program pi_reduce\n include 'mpif.h'\n\n integer DARTS, ROUNDS, MASTER\n parameter(DARTS = 5000) \n parameter(ROUNDS = 100)\n parameter(MASTER = 0)\n\n integer \ttaskid, numtasks, i, status(MPI_STATUS_SIZE)\n real*4\tseednum\n real*8 \thomepi, pi, avepi, pisum, dboard\n external d_vadd\n\nC Obtain number of tasks and task ID\n call MPI_INIT( ierr )\n call MPI_COMM_RANK( MPI_COMM_WORLD, taskid, ierr )\n call MPI_COMM_SIZE( MPI_COMM_WORLD, numtasks, ierr )\n write(*,*)'task ID = ', taskid\n\n avepi = 0\n\n do 40 i = 1, ROUNDS\nC Calculate pi using dartboard algorithm \n homepi = dboard(DARTS)\n\nC Use mp_reduce to sum values of homepi across all tasks\nC Master will store the accumulated value in pisum\nC - homepi is the send buffer\nC - pisum is the receive buffer (used by the receiving task only)\nC - MASTER is the task that will receive the result of the reduction\nC operation\nC - d_vadd is a pre-defined reduction function (double-precision\nC floating-point vector addition)\nC - allgrp is the group of tasks that will participate\n call MPI_REDUCE( homepi, pisum, 1, MPI_DOUBLE_PRECISION, \n & MPI_SUM, MASTER, MPI_COMM_WORLD, ierr )\nC Master computes average for this iteration and all iterations \n if (taskid .eq. MASTER) then\n pi = pisum/numtasks\n avepi = ((avepi*(i-1)) + pi) / i\n write(*,32) DARTS*i, avepi\n 32 format(' After',i6,' throws, average value of pi = ',f10.8) \n endif\n 40 continue\n\n if (taskid .eq. MASTER) then\n print *, ' '\n print *,'Real value of PI: 3.1415926535897'\n print *, ' '\n endif\n\n call MPI_FINALIZE(ierr)\n\n end\n\n\nC *****************************************************************************\nC function dboard.f\nC DESCRIPTION:\nC Used in pi calculation example codes.\nC See mpi_pi_send.f and mpi_pi_reduce.f\nC Throw darts at board. Done by generating random numbers\nC between 0 and 1 and converting them to values for x and y\nC coordinates and then testing to see if they \"land\" in\nC the circle.\" If so, score is incremented. After throwing the\nC specified number of darts, pi is calculated. The computed value\nC of pi is returned as the value of this function, dboard.\nC Note: Requires Fortran90 compiler due to random_number() function\nC \nC Explanation of constants and variables used in this function:\nC darts \t= number of throws at dartboard\nC score\t= number of darts that hit circle\nC n\t\t= index variable\nC r \t\t= random number between 0 and 1 \nC x_coord\t= x coordinate, between -1 and 1 \nC x_sqr\t= square of x coordinate\nC y_coord\t= y coordinate, between -1 and 1 \nC y_sqr\t= square of y coordinate\nC pi\t\t= computed value of pi\nC **************************************************************************/\n\n real*8 function dboard(darts)\n integer darts, score, n\n real*4\tr\n real*8\tx_coord, x_sqr, y_coord, y_sqr, pi\n\n score = 0\n\nC \"throw darts at the board\"\n do 10 n = 1, darts\nC generate random numbers for x and y coordinates\n call random_number(r)\n x_coord = (2.0 * r) - 1.0\n\tx_sqr = x_coord * x_coord\n\n call random_number(r)\n y_coord = (2.0 * r) - 1.0\n\ty_sqr = y_coord * y_coord\n\nC if dart lands in circle, increment score\n\tif ((x_sqr + y_sqr) .le. 1.0) then\n\t score = score + 1\n endif\n\n 10 continue\n\nC calculate pi\n pi = 4.0 * score / darts\n dboard = pi\n end\n", "meta": {"hexsha": "75559bdcd0a159e1a52115db655858b47ca0abc4", "size": 5097, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "mpi-test/mpi_pi_reduce.f", "max_stars_repo_name": "wyphan/testcodes", "max_stars_repo_head_hexsha": "cbf8ea436119882ad39dbe78271cb1aefe3c9543", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 93, "max_stars_repo_stars_event_min_datetime": "2021-03-15T20:40:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T08:57:40.000Z", "max_issues_repo_path": "mpi-test/mpi_pi_reduce.f", "max_issues_repo_name": "wyphan/testcodes", "max_issues_repo_head_hexsha": "cbf8ea436119882ad39dbe78271cb1aefe3c9543", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-05-14T04:55:45.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T16:33:20.000Z", "max_forks_repo_path": "mpi-test/mpi_pi_reduce.f", "max_forks_repo_name": "wyphan/testcodes", "max_forks_repo_head_hexsha": "cbf8ea436119882ad39dbe78271cb1aefe3c9543", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 63, "max_forks_repo_forks_event_min_datetime": "2021-03-10T00:31:09.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T13:48:30.000Z", "avg_line_length": 36.6690647482, "max_line_length": 79, "alphanum_fraction": 0.6176182068, "num_tokens": 1363, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677622198947, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.67252828277563}} {"text": " PROGRAM xrank\r\nC driver for routine rank\r\n INTEGER i,j,k,l,indx(100),irank(100)\r\n REAL a(100),b(10)\r\n open(7,file='TARRAY.DAT',status='OLD')\r\n read(7,*) (a(i),i=1,100)\r\n close(7)\r\n call indexx(100,a,indx)\r\n call rank(100,indx,irank)\r\n write(*,*) 'Original array is:'\r\n do 11 i=1,10\r\n write(*,'(1x,10f7.2)') (a(10*(i-1)+j), j=1,10)\r\n11 continue\r\n write(*,*) 'Table of ranks is:'\r\n do 12 i=1,10\r\n write(*,'(1x,10i6)') (irank(10*(i-1)+j), j=1,10)\r\n12 continue\r\n write(*,*) 'press RETURN to continue...'\r\n read(*,*)\r\n write(*,*) 'Array sorted according to rank table:'\r\n do 15 i=1,10\r\n do 14 j=1,10\r\n k=10*(i-1)+j\r\n do 13 l=1,100\r\n if (irank(l).eq.k) b(j)=a(l)\r\n13 continue\r\n14 continue\r\n write(*,'(1x,10f7.2)') (b(j),j=1,10)\r\n15 continue\r\n END\r\n", "meta": {"hexsha": "3d47cfa43879f7786e4d70de3c9dc350da1866c4", "size": 910, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xrank.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xrank.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xrank.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.3548387097, "max_line_length": 57, "alphanum_fraction": 0.4813186813, "num_tokens": 337, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778258, "lm_q2_score": 0.7931059487389968, "lm_q1q2_score": 0.6725282735083259}} {"text": " SUBROUTINE CROSSP (VX1,VY1,VZ1, VX2,VY2,VZ2, VX3,VY3,VZ3)\n\nC This subroutine accepts two 3D vectors and returns their\nC cross product.\n\n REAL VX1,VY1,VZ1, VX2,VY2,VZ2, VX3,VY3,VZ3\n\n VX3 = VY1*VZ2 - VZ1*VY2\n VY3 = VZ1*VX2 - VX1*VZ2\n VZ3 = VX1*VY2 - VY1*VX2\n\n END\n", "meta": {"hexsha": "581b9d4cba7a4fca0a97afac02a56bf6cb5f0f47", "size": 296, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "third_party/Phigs/PVT/PVT_fort/V2LIB/crossp.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/crossp.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/crossp.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": 22.7692307692, "max_line_length": 63, "alphanum_fraction": 0.6216216216, "num_tokens": 147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6724742775402306}} {"text": "C PSPLINE -- modified from SPLINE.FOR -- dmc 3 Oct 1995\nC\nC\tTHE CODES (SPLINE & SEVAL) ARE TAKEN FROM:\nC\tFORSYTHE,MALCOLM AND MOLER, \"COMPUTER METHODS FOR\nC\tMATHEMATICAL COMPUTATIONS\",PRENTICE-HALL, 1977.\nc\nc PSPLINE -- periodic spline -- adaptation of SPLINE.FOR by D. McCune\nc October 1995: The function to be splined is taken as having periodic\nC derivatives (it need not be periodic itself), so that\nc the interpolating function satisfies\nc y'(x(1))=y'(x(N))\nc y''(x(1))=y''(x(N))\nc this results in a fully specified system (no addl BC assumptions\nc required); it is not a tridiagonal system but a modified NM1xNM1\nc tridiagonal system with non-zero offdiagonal corner (1,NM1), (NM1,1)\nc elements. It remains symmetric & diagonally dominant, and is\nc solved by Gaussian elimination w/o pivoting. NM1=N-1.\nc\n SUBROUTINE PSPLINE (N, X, Y, B, C, D, WK)\n INTEGER N\n REAL X(N), Y(N), B(N), C(N), D(N), WK(N)\nC\nC THE COEFFICIENTS B(I), C(I), AND D(I), I=1,2,...,N ARE COMPUTED\nC FOR A periodic CUBIC INTERPOLATING SPLINE\nC\nC S(X) = Y(I) + B(I)*(X-X(I)) + C(I)*(X-X(I))**2 + D(I)*(X-X(I))**3\nC\nC FOR X(I) .LE. X .LE. X(I+1)\nC\nC WK(...) is used as a workspace during the Guassian elimination.\nC it represents the rightmost column of the array\nC\nC note B(N),C(N),D(N) give coeffs for a periodic continuation into\nC the next period, up to X(N)+(X(2)-X(1)) only.\nC\nC SEVAL can be used to evaluate the spline, but, it is up to the\nC SEVAL caller to bring the argument into the normal range X(1) to X(N).\nC\nC INPUT..\nC\nC N = THE NUMBER OF DATA POINTS OR KNOTS (N.GE.2)\nC includes a complete period of the data, the last point being\nC a repeat of the first point.\nC X = THE ABSCISSAS OF THE KNOTS IN STRICTLY INCREASING ORDER\nC X(N)-X(1) is the period of the periodic function represented.\nC Y = THE ORDINATES OF THE KNOTS\nC\nC OUTPUT..\nC\nC B, C, D = ARRAYS OF SPLINE COEFFICIENTS AS DEFINED ABOVE.\nC\nC USING P TO DENOTE DIFFERENTIATION,\nC\nC Y(I) = S(X(I))\nC B(I) = SP(X(I))\nC C(I) = SPP(X(I))/2\nC D(I) = SPPP(X(I))/6 (DERIVATIVE FROM THE RIGHT)\nC\nCCCCCCCCCCCCCCC\nC THE ACCOMPANYING FUNCTION SUBPROGRAM SEVAL CAN BE USED\nC TO EVALUATE THE SPLINE.\nC\nC\n INTEGER NM1, NM2, IB, I\n REAL T\nC\nC-------------------------------------\nC\n NM1 = N-1\n NM2 = NM1-1\nC\n IF ( N .LT. 4 ) THEN\n write(6,9901)\n 9901 format(/\n > ' ?PSPLINE -- at least 4 pts required for periodic spline.')\n return\n ENDIF\nC\nC SET UP MODIFIED NM1 x NM1 TRIDIAGONAL SYSTEM:\nC B = DIAGONAL, D = OFFDIAGONAL, C = RIGHT HAND SIDE.\nC WK(1:NM2) = rightmost column above diagonal\nC WK(NM1) = lower left corner element\nC\n D(1) = X(2) - X(1)\n D(NM1) = X(N) - X(NM1)\n B(1) = 2.0*(D(1)+D(NM1))\n C(1) = (Y(N) - Y(NM1))/D(NM1)\n C(2) = (Y(2) - Y(1))/D(1)\n C(1) = C(2) - C(1)\n WK(1) = D(NM1)\n DO 10 I = 2, NM1\n D(I) = X(I+1) - X(I)\n B(I) = 2.*(D(I-1) + D(I))\n C(I+1) = (Y(I+1) - Y(I))/D(I)\n C(I) = C(I+1) - C(I)\n WK(I) = 0.0\n 10 CONTINUE\n WK(NM2) = D(NM2)\n WK(NM1) = D(NM1)\nC\nC END CONDITIONS -- implied by periodicity\nC C(1)=C(N) B(1)=B(N) D(1)=D(N) -- no additional assumption needed.\nC\nC FORWARD ELIMINATION\nC WK(1)--WK(NM2) represent the rightmost column above the\nC diagonal; WK(NM1) represents the non-zero lower left corner element\nC which in each step is moved one column to the right.\nC\n 15 DO 20 I = 2, NM2\n T = D(I-1)/B(I-1)\n B(I) = B(I) - T*D(I-1)\n C(I) = C(I) - T*C(I-1)\n WK(I) = WK(I) - T*WK(I-1)\n Q = WK(NM1)/B(I-1)\n WK(NM1) = -Q*D(I-1)\n B(NM1) = B(NM1) - Q*WK(I-1)\n C(NM1) = C(NM1) - Q*C(I-1)\n 20 CONTINUE\nC\nC correct the (NM1,NM2) element\nC\n WK(NM1) = WK(NM1) + D(NM2)\nC\nC complete the forward elimination: now WK(NM1) and WK(NM2) are\nC the off diagonal elements of the 2x2 at the lower right hand corner\nC\n T = WK(NM1)/B(NM2)\n B(NM1) = B(NM1) - T*WK(NM2)\n C(NM1) = C(NM1) - T*C(NM2)\nC\nC BACK SUBSTITUTION\nC\n C(NM1) = C(NM1)/B(NM1)\n C(NM2) = (C(NM2) - WK(NM2)*C(NM1))/B(NM2)\nC\n DO 30 IB = 3, NM1\n I = N-IB\n C(I) = (C(I) - D(I)*C(I+1) - WK(I)*C(NM1))/B(I)\n 30 CONTINUE\nC\nC PERIODICITY:\nC\n C(N)=C(1)\nC\nC C(I) IS NOW THE SIGMA(I) OF THE TEXT\nC\nC COMPUTE POLYNOMIAL COEFFICIENTS\nC\n DO 40 I = 1, NM1\n B(I) = (Y(I+1) - Y(I))/D(I) - D(I)*(C(I+1) + 2.*C(I))\n D(I) = (C(I+1) - C(I))/D(I)\n C(I) = 3.*C(I)\n 40 CONTINUE\nC periodic continuation...\n B(N) = B(1)\n C(N) = C(1)\n D(N) = D(1)\nC\n RETURN\n END\n", "meta": {"hexsha": "2956ad9eb5bf776043bedb5ee9fc1af3c5a32a67", "size": 4730, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gfile_Bfield/PSPLINE/Pspline/pspline.f", "max_stars_repo_name": "ORNL-Fusion/RFSciDAC-testing", "max_stars_repo_head_hexsha": "c2fa44e00ce8e0af4be6fa662a9e8c94d6c6f60e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2020-05-08T01:47:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T10:35:28.000Z", "max_issues_repo_path": "gfile_Bfield/PSPLINE/Pspline/pspline.f", "max_issues_repo_name": "ORNL-Fusion/RFSciDAC-testing", "max_issues_repo_head_hexsha": "c2fa44e00ce8e0af4be6fa662a9e8c94d6c6f60e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 77, "max_issues_repo_issues_event_min_datetime": "2020-05-08T07:18:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:20:33.000Z", "max_forks_repo_path": "gfile_Bfield/PSPLINE/Pspline/pspline.f", "max_forks_repo_name": "ORNL-Fusion/RFSciDAC-testing", "max_forks_repo_head_hexsha": "c2fa44e00ce8e0af4be6fa662a9e8c94d6c6f60e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-02-10T13:47:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T12:53:43.000Z", "avg_line_length": 29.3788819876, "max_line_length": 75, "alphanum_fraction": 0.5687103594, "num_tokens": 1866, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813454, "lm_q2_score": 0.7490872187162397, "lm_q1q2_score": 0.6724520737198572}} {"text": "subroutine smth(var, nx, ny, var_smth)\n\n use types, only : wp\n use params, only : nsmth_x, nsmth_y, nx1, nx2, ny1, ny2\n\n implicit none\n\n integer , intent(in) :: nx\n integer , intent(in) :: ny\n real (wp), intent(in) :: var (0:nx, 0:ny)\n real (wp), intent(out):: var_smth(nx1:nx2, ny1:ny2)\n ! Local variables\n real (wp) :: tmp (nx1:nx2, ny1:ny2)\n integer :: nc\n integer :: i, j, ii, jj\n real (wp), parameter :: var_thresh = -10.0\n\n\n var_smth(nx1:nx2, ny1:ny2) = var(nx1:nx2, ny1:ny2)\n\n do j = ny1, ny2\n do i = nx1, nx2\n nc = 0\n tmp(i, j) = 0.\n if (var(i, j) > var_thresh) then\n do jj = max(-nsmth_y, -j), min(nsmth_y, ny-j)\n do ii = max(-nsmth_x, -i), min(nsmth_x, nx-i)\n if (var(i+ii, j+jj) > var_thresh) then\n tmp(i, j) = tmp(i, j) + var(i+ii, j+jj)\n nc = nc + 1\n endif\n enddo\n enddo\n tmp(i, j) = tmp(i, j) / ((2 * nsmth_x + 1) * (2 * nsmth_y + 1))\n var_smth(i, j) = tmp(i, j)\n endif\n enddo\n enddo\nend subroutine smth\n\n\nsubroutine smth_r(var, nx, ny, lon, lat, var_smth)\n\n use types, only : wp\n use constants, only : pi, ra, rkilo, deg2rad\n use params, only : proj, r_smth, nx1, nx2, ny1, ny2\n use utils, only : great_circle, cosd\n\n implicit none\n\n integer , intent(in) :: nx\n integer , intent(in) :: ny\n real (wp), intent(in) :: var (0:nx, 0:ny)\n real (wp), intent(in) :: lon (0:nx )\n real (wp), intent(in) :: lat ( 0:ny)\n real (wp), intent(out):: var_smth(nx1:nx2, ny1:ny2)\n ! Local variables\n real (wp) :: tmp (nx1:nx2, ny1:ny2)\n integer :: nc\n integer :: i, j, ii, jj\n real (wp) :: lonin, latin\n integer :: x_smth, y_smth\n real (wp) :: dist\n real (wp), parameter :: var_thresh = -10.0 ! TODO: replace by fillval?\n\n x_smth = 0\n y_smth = 0\n\n dist = 0.\n\n lonin = lon(2) - lon(1)\n latin = lat(2) - lat(1)\n\n if (proj==1) then\n x_smth = nint(r_smth / (ra * lonin * deg2rad * cosd(lat(ny1+ny2/2)) / rkilo)) + 1\n y_smth = nint(r_smth / (ra * latin * deg2rad / rkilo)) + 1\n elseif (proj==2) then\n x_smth = nint(r_smth / lonin / rkilo) + 2\n y_smth = nint(r_smth / latin / rkilo) + 2 ! TODO: check why +2\n endif\n\n ! print*, x_smth, y_smth\n\n var_smth(nx1:nx2, ny1:ny2) = var(nx1:nx2, ny1:ny2)\n\n do j = ny1, ny2\n ! if (j - y_smth >= 0 .and. j + y_smth <= ny) then\n do i = nx1, nx2\n ! if (i - x_smth >= 0 .and. i + x_smth <= nx) then\n nc = 0\n tmp(i, j) = 0.\n if (var(i, j) > var_thresh) then\n do jj = max(-y_smth, -j), min(y_smth, ny-j)\n do ii = max(-x_smth, -i), min(x_smth, nx-i)\n if (proj == 1) then\n dist = great_circle(lon(i), lon(i+ii), lat(j), lat(j+jj), ra)\n elseif(proj==2)then\n dist = sqrt((ii * lonin)**2 + (jj * latin)**2)\n endif\n\n if (dist <= r_smth * rkilo) then\n if (var(i+ii, j+jj) > var_thresh) then\n nc = nc + 1\n tmp(i, j) = tmp(i, j) + var(i+ii, j+jj)\n endif\n endif\n enddo\n enddo\n var_smth(i, j) = tmp(i, j) / nc\n endif\n ! endif\n enddo\n ! endif\n enddo\nend subroutine smth_r\n", "meta": {"hexsha": "730177f22acc636a6df3f92faabd440827b236b7", "size": 3487, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/smth.f90", "max_stars_repo_name": "pst019/pmctrack", "max_stars_repo_head_hexsha": "fea16026f8e925542e3ef8fb91dd131540285d81", "max_stars_repo_licenses": ["MIT"], "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/smth.f90", "max_issues_repo_name": "pst019/pmctrack", "max_issues_repo_head_hexsha": "fea16026f8e925542e3ef8fb91dd131540285d81", "max_issues_repo_licenses": ["MIT"], "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/smth.f90", "max_forks_repo_name": "pst019/pmctrack", "max_forks_repo_head_hexsha": "fea16026f8e925542e3ef8fb91dd131540285d81", "max_forks_repo_licenses": ["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.0603448276, "max_line_length": 85, "alphanum_fraction": 0.4777745913, "num_tokens": 1281, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6724520645909038}} {"text": "module ChemicalSystem\n implicit none\n\n integer(kind=4), parameter :: num_reactions = 9\n integer(kind=4), parameter :: num_species = 5\n integer(kind=4), parameter, dimension(5,9) :: nu = reshape((/ -2, 1, 0, 0, 0, 2, -1, 0, 0, 0, 0, -1, -1, 1, 0, 0, 1, 1, -1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, -1 /),(/5,9/))\n real(kind=8), dimension(5) :: X0 = (/ 10, 0, 20, 0, 0 /)\n real(kind=8), dimension(9) :: c = (/ 50, 1000, 50, 1000, 1, 10, 3, 1, 6 /)\n\n contains\n\n function propensities(X) result(a)\n real(kind=8), dimension(num_species), intent(in) :: X\n real(kind=8), dimension(num_reactions) :: a\n\n a(1) = c(1) * 0.5d0 * X(1) * (X(1)-1)\n a(2) = c(2) * X(2)\n a(3) = c(3) * X(2) * X(3)\n a(4) = c(4) * X(4)\n a(5) = c(5) * X(3)\n a(6) = c(6) * X(4)\n a(7) = c(7) * X(5)\n a(8) = c(8) * X(1)\n a(9) = c(9) * X(5)\n end function\n\n function propJacobian(X) result(Ja)\n real(kind=8), dimension(num_species), intent(in) :: X\n real(kind=8), dimension(num_reactions,num_species) :: Ja\n\n Ja(1,1) = c(1) * 0.5d0 * ( 2*X(1) - 1 )\n Ja(2,1) = 0\n Ja(3,1) = 0\n Ja(4,1) = 0\n Ja(5,1) = 0\n Ja(6,1) = 0\n Ja(7,1) = 0\n Ja(8,1) = c(8)\n Ja(9,1) = 0\n Ja(1,2) = 0\n Ja(2,2) = c(2)\n Ja(3,2) = c(3) * X(3)\n Ja(4,2) = 0\n Ja(5,2) = 0\n Ja(6,2) = 0\n Ja(7,2) = 0\n Ja(8,2) = 0\n Ja(9,2) = 0\n Ja(1,3) = 0\n Ja(2,3) = 0\n Ja(3,3) = c(3) * X(2)\n Ja(4,3) = 0\n Ja(5,3) = c(5)\n Ja(6,3) = 0\n Ja(7,3) = 0\n Ja(8,3) = 0\n Ja(9,3) = 0\n Ja(1,4) = 0\n Ja(2,4) = 0\n Ja(3,4) = 0\n Ja(4,4) = c(4)\n Ja(5,4) = 0\n Ja(6,4) = c(6)\n Ja(7,4) = 0\n Ja(8,4) = 0\n Ja(9,4) = 0\n Ja(1,5) = 0\n Ja(2,5) = 0\n Ja(3,5) = 0\n Ja(4,5) = 0\n Ja(5,5) = 0\n Ja(6,5) = 0\n Ja(7,5) = c(7)\n Ja(8,5) = 0\n Ja(9,5) = c(9)\n end function\n\n function relaxRates(X) result(lambda)\n real(kind=8), dimension(num_species), intent(in) :: X\n real(kind=8), dimension(num_reactions) :: lambda\n\n lambda(1) = + c(1) * (2*X(1)-1) + c(2)\n lambda(2) = + c(1) * (2*X(1)-1) + c(2)\n lambda(3) = + c(3) * X(3) + c(3) * X(2) + c(4)\n lambda(4) = + c(3) * X(3) + c(3) * X(2) + c(4)\n lambda(5) = c(5)\n lambda(6) = c(6)\n lambda(7) = c(7)\n lambda(8) = + c(8)\n lambda(9) = + c(9)\n end function\nend module ChemicalSystem\n", "meta": {"hexsha": "c8e046b81e24e0a83a0d8709ccd190824aa2bd13", "size": 2750, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/OMP/module_ChemicalSystem.f90", "max_stars_repo_name": "revitmt/ChemicalKinetics", "max_stars_repo_head_hexsha": "61f174a1250c2bd248270ce1ef408e23e542b83b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fortran/OMP/module_ChemicalSystem.f90", "max_issues_repo_name": "revitmt/ChemicalKinetics", "max_issues_repo_head_hexsha": "61f174a1250c2bd248270ce1ef408e23e542b83b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/OMP/module_ChemicalSystem.f90", "max_forks_repo_name": "revitmt/ChemicalKinetics", "max_forks_repo_head_hexsha": "61f174a1250c2bd248270ce1ef408e23e542b83b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.5698924731, "max_line_length": 219, "alphanum_fraction": 0.3825454545, "num_tokens": 1284, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813454, "lm_q2_score": 0.7490872075132153, "lm_q1q2_score": 0.6724520636629548}} {"text": "! 29/04/2021\n!-------------------------------------------------------!\nmodule random\nreal, private :: zero = 0.0, half = 0.5, one = 1.0, two = 2.0\nprivate :: integral\npublic :: init_random_seed, random_unif, random_Poisson\n\ncontains\n\nsubroutine init_random_seed()\n\n integer :: i, n, clock\n integer, dimension(:), allocatable :: seed\n\n call random_seed(size = n)\n allocate(seed(n))\n\n call system_clock(COUNT=clock)\n\n seed = clock + 37 * (/ (i - 1, i = 1, n) /)\n call random_seed(put = seed)\n\n deallocate(seed)\n\nend subroutine\n\nfunction random_unif(a,b) result(ans)\n\nuse my_init, only: wp => dp !for double precission constants\n\nreal(wp) :: a,b,y\n\n !call init_random_seed()\ncall random_number(y)\n\nans = a + y * (b - a)\nend function\n\n\nfunction random_Poisson(mu, first) result(ival)\n!**********************************************************************\n! Translated to Fortran 90 by Alan Miller from:\n! RANLIB\n!\n! Library of Fortran Routines for Random Number Generation\n!\n! Compiled and Written by:\n!\n! Barry W. Brown\n! James Lovato\n!\n! Department of Biomathematics, Box 237\n! The University of Texas, M.D. Anderson Cancer Center\n! 1515 Holcombe Boulevard\n! Houston, TX 77030\n!\n! This work was supported by grant CA-16672 from the National Cancer Institute.\n\n! GENerate POIsson random deviate\n\n! function\n\n! Generates a single random deviate from a Poisson distribution with mean mu.\n\n! Arguments\n\n! mu --> The mean of the Poisson distribution from which\n! a random deviate is to be generated.\n! real mu\n\n! Method\n\n! For details see:\n\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! 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\n! SEPARATION OF CASES A AND B\n\n! .. Scalar Arguments ..\nreal, intent(in) :: mu\nlogical, intent(in) :: first\ninteger :: ival\n! ..\n! .. Local Scalars ..\nreal :: b1, b2, c, c0, c1, c2, c3, del, difmuk, e, fk, fx, fy, g, &\n omega, px, py, t, u, v, x, xx\nreal, save :: s, d, p, q, p0\ninteger :: j, k, kflag\nlogical, save :: full_init\ninteger, save :: l, m\n! ..\n! .. Local Arrays ..\nreal, save :: pp(35)\n! ..\n! .. Data statements ..\nreal, parameter :: a0 = -.5, a1 = .3333333, a2 = -.2500068, a3 = .2000118, &\n a4 = -.1661269, a5 = .1421878, a6 = -.1384794, &\n a7 = .1250060\n\nreal, parameter :: fact(10) = (/ 1., 1., 2., 6., 24., 120., 720., 5040., &\n 40320., 362880. /)\n\n! ..\n! .. Executable Statements ..\nif (mu > 10.0) then\n! C A S E A. (RECALCULATION OF S, D, L if MU HAS CHANGED)\n\n if (first) then\n s = SQRT(mu)\n d = 6.0*mu*mu\n\n! THE POISSON PROBABILITIES PK EXCEED THE DISCRETE NORMAL\n! PROBABILITIES FK WHENEVER K >= M(MU). L=IFIX(MU-1.1484)\n! IS AN UPPER BOUND TO M(MU) FOR ALL MU >= 10 .\n\n l = mu - 1.1484\n full_init = .false.\n end if\n\n\n! STEP N. NORMAL SAMPLE - random_normal() FOR STANDARD NORMAL DEVIATE\n\n g = mu + s*random_normal()\n if (g > 0.0) then\n ival = g\n\n! STEP I. IMMEDIATE ACCEPTANCE if ival IS LARGE ENOUGH\n\n if (ival>=l) return\n\n! STEP S. SQUEEZE ACCEPTANCE - SAMPLE U\n\n fk = ival\n difmuk = mu - fk\n call random_number(u)\n if (d*u >= difmuk*difmuk*difmuk) return\n end if\n\n! STEP P. PREPARATIONS FOR STEPS Q AND H.\n! (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/MU GUARANTEES MAJORIZATION BY THE 'HAT'-function.\n\n if (.NOT. full_init) then\n omega = .3989423/s\n b1 = .4166667E-1/mu\n b2 = .3*b1*b1\n c3 = .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 = .1069/mu\n full_init = .true.\n end if\n\n if (g < 0.0) goto 50\n\n! 'SUBROUTINE' F IS CALLED (KFLAG=0 FOR CORRECT return)\n\n kflag = 0\n goto 70\n\n! STEP Q. QUOTIENT ACCEPTANCE (RARE CASE)\n\n 40 if (fy-u*fy <= py*EXP(px-fx)) return\n\n! STEP E. EXPONENTIAL SAMPLE - random_exponential() FOR STANDARD EXPONENTIAL\n! DEVIATE E AND SAMPLE T FROM THE LAPLACE 'HAT'\n! (if T <= -.6744 then PK < FK FOR ALL MU >= 10.)\n\n 50 e = random_exp(1.0)\n call random_number(u)\n u = u + u - one\n t = 1.8 + SIGN(e, u)\n if (t <= (-.6744)) goto 50\n ival = mu + s*t\n fk = ival\n difmuk = mu - fk\n\n! 'SUBROUTINE' F IS CALLED (KFLAG=1 FOR CORRECT return)\n\n kflag = 1\n goto 70\n\n! STEP H. HAT ACCEPTANCE (E IS REPEATED ON REJECTION)\n\n 60 if (c*ABS(u) > py*EXP(px+e) - fy*EXP(fx+e)) goto 50\n return\n\n! STEP F. 'SUBROUTINE' F. CALCULATION OF PX, PY, FX, FY.\n! CASE ival < 10 USES FACTORIALS FROM TABLE FACT\n\n 70 if (ival>=10) goto 80\n px = -mu\n py = mu**ival/fact(ival+1)\n goto 110\n\n! CASE ival >= 10 USES POLYNOMIAL APPROXIMATION\n! A0-A7 FOR ACCURACY WHEN ADVISABLE\n! .8333333E-1=1./12. .3989423=(2*PI)**(-.5)\n\n 80 del = .8333333E-1/fk\n del = del - 4.8*del*del*del\n v = difmuk/fk\n if (ABS(v)>0.25) then\n px = fk*LOG(one + v) - difmuk - del\n else\n px = fk*v*v* (((((((a7*v+a6)*v+a5)*v+a4)*v+a3)*v+a2)*v+a1)*v+a0) - del\n end if\n py = .3989423/SQRT(fk)\n 110 x = (half - difmuk)/s\n xx = x*x\n fx = -half*xx\n fy = omega* (((c3*xx + c2)*xx + c1)*xx + c0)\n if (kflag <= 0) goto 40\n goto 60\n\n!---------------------------------------------------------------------------\n! C A S E B. mu < 10\n! START NEW TABLE AND CALCULATE P0 if NECESSARY\n\nelse\n if (first) then\n m = MAX(1, INT(mu))\n l = 0\n p = EXP(-mu)\n q = p\n p0 = p\n end if\n\n! STEP U. UNIFORM SAMPLE FOR INVERSION METHOD\n\n do\n call random_number(u)\n ival = 0\n if (u <= p0) return\n\n! STEP T. TABLE COMPARISON UNTIL THE end PP(L) OF THE\n! PP-TABLE OF CUMULATIVE POISSON PROBABILITIES\n! (0.458=PP(9) FOR MU=10)\n\n if (l == 0) goto 150\n j = 1\n if (u > 0.458) j = MIN(l, m)\n do k = j, l\n if (u <= pp(k)) goto 180\n end do\n if (l == 35) CYCLE\n\n! STEP C. CREATION OF NEW POISSON PROBABILITIES P\n! AND THEIR CUMULATIVES Q=PP(K)\n\n 150 l = l + 1\n do k = l, 35\n p = p*mu / k\n q = q + p\n pp(k) = q\n if (u <= q) goto 170\n end do\n l = 35\n end do\n\n 170 l = k\n 180 ival = k\n return\nend if\n\nreturn\nend function random_Poisson\n\n! ------------------ Needed subroutines and functions -------------------!\nreal function random_exp(s)\n\n! Adapted from Fortran 77 code from the book:\n! Dagpunar, J. 'Principles of random variate generation'\n! Clarendon Press, Oxford, 1988. ISBN 0-19-852202-9\n\n! function GENERATES A RANDOM VARIATE IN [0,INFINITY) FROM\n! A NEGATIVE EXPONENTIAL DlSTRIBUTION WlTH DENSITY PROPORTIONAL\n! TO EXP(-random_exponential), USING INVERSION.\n\nimplicit none\nreal, intent(in) :: s\n! Local variable\nreal :: r\n\ndo\n call random_number(r)\n if (r > zero) exit\nend do\n\nrandom_exp = -log(r )/s\nreturn\n\nend function random_exp\n\n\n\nreal function random_normal()\n\n! Adapted from the following Fortran 77 code\n! ALGORITHM 712, COLLECTED ALGORITHMS FROM ACM.\n! THIS WORK PUBLISHED IN TRANSACTIONS ON MATHEMATICAL SOFTWARE,\n! VOL. 18, NO. 4, DECEMBER, 1992, PP. 434-435.\n\n! The function random_normal() returns a normally distributed pseudo-random\n! number with zero mean and unit variance.\n\n! The algorithm uses the ratio of uniforms method of A.J. Kinderman\n! and J.F. Monahan augmented with quadratic bounding curves.\n\nimplicit none\n\n! Local variables\nreal :: s = 0.449871, t = -0.386595, a = 0.19600, b = 0.25472, &\n r1 = 0.27597, r2 = 0.27846, u, v, x, y, q\n\n! Generate P = (u,v) uniform in rectangle enclosing acceptance region\n\ndo\n call random_number(u)\n call random_number(v)\n v = 1.7156 * (v - half)\n\n! Evaluate the quadratic form\n x = u - s\n y = ABS(v) - t\n q = x**2 + y*(a*y - b*x)\n\n! Accept P if inside inner ellipse\n if (q < r1) exit\n! Reject P if outside outer ellipse\n if (q > r2) cycle\n! Reject P if outside acceptance region\n if (v**2 < -4.0*LOG(u)*u**2) exit\nend do\n\n! Return ratio of P's coordinates as the normal deviate\nrandom_normal = v/u\nreturn\n\nend function random_normal\n\nsubroutine random_stdgamma_alpha_ge_1(alpha,x)\n use my_init\n implicit none\n real,intent(in) :: alpha\n real,intent(out) :: x\n real :: y,t,u1,u2\n do\n u1 = random_unif(one,rero)\n !call random_stduniform(u1)\n y = -log(u1)\n t = (y/exp(y-1))**(alpha-1)\n u2 = random_unif(one,rero)\n if(u2 <= t) then\n x = alpha*y\n exit\n end if\n end do\nend subroutine random_stdgamma_alpha_ge_1\n\nsubroutine random_stdgamma(alpha,x)\n use my_init\n implicit none\n real,intent(in) :: alpha\n real,intent(out) :: x\n real :: g,u\n if(alpha<=0) then\n stop \"alpha<=0\"\n else if(alpha<1) then\n call random_stdgamma_alpha_ge_1(alpha+1.0,g)\n !call random_stduniform(u)\n u = random_unif(one,rero)\n x = g*u**(1.0/alpha)\n else\n call random_stdgamma_alpha_ge_1(alpha,x)\n end if\nend subroutine random_stdgamma\n\n\n\nend module\n", "meta": {"hexsha": "bb57723b1409c9707da3ecb7d4a5f922dca98558", "size": 9943, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "code/random.f95", "max_stars_repo_name": "RenatoSalArrDu/StochasticSLIRD", "max_stars_repo_head_hexsha": "5b8e0f4c62d8d846976e842137ee0742de784f58", "max_stars_repo_licenses": ["MIT"], "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/random.f95", "max_issues_repo_name": "RenatoSalArrDu/StochasticSLIRD", "max_issues_repo_head_hexsha": "5b8e0f4c62d8d846976e842137ee0742de784f58", "max_issues_repo_licenses": ["MIT"], "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/random.f95", "max_forks_repo_name": "RenatoSalArrDu/StochasticSLIRD", "max_forks_repo_head_hexsha": "5b8e0f4c62d8d846976e842137ee0742de784f58", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-24T08:02:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-24T08:02:24.000Z", "avg_line_length": 25.3002544529, "max_line_length": 80, "alphanum_fraction": 0.5570753294, "num_tokens": 3265, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.7490872075132153, "lm_q1q2_score": 0.6724520595624527}} {"text": " double precision function fdisc(blockno,xc,yc)\n implicit none\n\n double precision xc,yc, phi, theta\n integer blockno\n\n double precision pi, pi2\n common /compi/ pi, pi2\n\n integer initchoice\n common /initchoice_comm/ initchoice\n\n integer*8 cont, get_context\n\n double precision xp, yp, zp\n\n double precision r, r0\n\n cont = get_context()\n\n call fclaw2d_map_c2m(cont,\n & blockno,xc,yc,xp,yp,zp)\n\n call map2spherical(xp,yp,zp,theta,phi)\n\n fdisc = abs(theta-pi) - pi/6\n\nc r0 = 0.2\nc r = sqrt((xp-0.5)**2 + (yp-0.5)**2)\nc fdisc = r - r0\n\n\n end\n", "meta": {"hexsha": "b69ca1b6431af4beb7427855f82f9bdcfdfb5500", "size": 644, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "applications/paper/sphere/fdisc.f", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2017-09-26T13:39:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:56:23.000Z", "max_issues_repo_path": "applications/paper/sphere/fdisc.f", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 75, "max_issues_repo_issues_event_min_datetime": "2017-08-02T19:56:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T12:36:32.000Z", "max_forks_repo_path": "applications/paper/sphere/fdisc.f", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-02-21T00:10:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T19:08:36.000Z", "avg_line_length": 18.9411764706, "max_line_length": 53, "alphanum_fraction": 0.5822981366, "num_tokens": 207, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8976952975813453, "lm_q2_score": 0.749087201911703, "lm_q1q2_score": 0.6724520586345034}} {"text": " subroutine slogtab(nearest,ntab,vtab, ndat,vdat,indx,wght)\n!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n! NASA/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !\n!-----------------------------------------------------------------------\n!\n! !ROUTINE: slogtab - set indices and log-linear weights to a table\n!\n! !INTERFACE:\n! end subroutine slogtab\n!\n! !DESCRIPTION:\n!\t*slogtab()* sets indices and log-linear weights for a given data\n!\tlist *vdat(ndat)* respect to a given lookup table *vtab(ntab)*.\n!\tIf *nearest* is .false., indices *indx* point to *vtab(ntab)*\n!\tentries of nearest (in a log-linear sense) values, with\n!\t*wght(ndat)* defined within the range [-.5,+.5). If *nearest*\n!\tis .true., indices *indx* are lower entries of table intervals,\n!\twith *wght* defined withing [0,1).\n!\n!\t*nearest*=.true. may be used to create an index table for\n!\tdirect table reference, while *nearest*=.false. may be used to\n!\tcreate an index table with weights for log-linear interpolating\n!\tfunctions.\n!\n!\tNotice that *vtab(ntab)* must be in a sorted order. Values in\n!\tboth *vtab(ntab)* and *vdat(ndat)* must be positive for a\n!\tproperly defined log-linear.\n!\n! !EXAMPLES:\n!\n! !BUGS:\n!\n! !SEE ALSO:\n!\n! !SYSTEM ROUTINES:\n!\n! !FILES USED:\n!\n! !REVISION HISTORY:\n!\t18May96 - J. Guo\t- Fixed a problem with out-of-ranged\n!\t\t\t\t data\n! \t05Dec95 - J. Guo\t- initial coding\n!_______________________________________________________________________\n implicit none\n!@interface\n\n logical, intent(in)\t\t:: nearest\t! nearest entries?\n integer, intent(in)\t\t:: ntab\t\t! size of vtab\n real, intent(in)\t:: vtab(ntab)\t! a lookup table\n\n integer, intent(in)\t\t:: ndat\t\t! size of vdat\n real, intent(in)\t:: vdat(ndat)\t! a list of values\n\n integer, intent(out)\t:: indx(ndat)\t! indices to vtab\n real, intent(out)\t:: wght(ndat)\t! weights of vtab\n\n!@end/interface\n!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n! local vars.\n\tinteger i,j\n\treal v\n!_______________________________________________________________________\n\n!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\t! extreme condition. Treated as normal\n\n\tif(ntab.le.0) return\n\n! ..Index the array to the lower index entry of an intervals in vtab.\n\tcall vindex(ntab,vtab,ndat,vdat,indx)\n\n! ..Compute the linear weights, and adjust the indices if needed.\n\tdo i=1,ndat\n\t j=indx(i)\n\n\t v=0.\n\t if(j.lt.ntab) v=log(vdat(i)/vtab(j))/log(vtab(j+1)/vtab(j))\n\t v=min(max(0.,v),1.)\n\n\t if(nearest) then\n\t\t! indx(i) is the index to the nearest entry in vtab,\n\t\t! with wght(i) is within [-.5,+.5). It is likely to\n\t\t! be used for direct table reference\n\n\t indx(i)=j + nint(v)\n\t wght(i)=v - nint(v)\n\n\t else\n\t\t! indx(i) is the lower index of an interval in vtab,\n\t\t! with wght(i) is in [0,1).\n\n\t wght(i)=v\n\t endif\n\tend do\n!_______________________________________________________________________\n\tend\n!.\n", "meta": {"hexsha": "c5d99a5e8e81ba2165eac2f5e4806b3a50ee2934", "size": 2958, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/Shared/GMAO_Shared/GMAO_psas/slogtab.f90", "max_stars_repo_name": "GEOS-ESM/AeroApps", "max_stars_repo_head_hexsha": "874dad6f34420c014d98eccbe81a061bdc0110cf", "max_stars_repo_licenses": ["NASA-1.3", "ECL-2.0", "Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-12-02T14:23:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-31T15:39:30.000Z", "max_issues_repo_path": "GMAO_psas/slogtab.f90", "max_issues_repo_name": "GEOS-ESM/GMAO_Shared", "max_issues_repo_head_hexsha": "022af23abbc7883891006b57379be96d9a50df23", "max_issues_repo_licenses": ["NASA-1.3", "ECL-2.0", "Apache-2.0"], "max_issues_count": 105, "max_issues_repo_issues_event_min_datetime": "2019-07-08T19:27:23.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-22T02:12:16.000Z", "max_forks_repo_path": "src/Shared/GMAO_Shared/GMAO_psas/slogtab.f90", "max_forks_repo_name": "GEOS-ESM/AeroApps", "max_forks_repo_head_hexsha": "874dad6f34420c014d98eccbe81a061bdc0110cf", "max_forks_repo_licenses": ["NASA-1.3", "ECL-2.0", "Apache-2.0"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2019-07-05T18:00:44.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-11T16:26:29.000Z", "avg_line_length": 30.1836734694, "max_line_length": 72, "alphanum_fraction": 0.6135902637, "num_tokens": 845, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392848011833, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6724450589763833}} {"text": "! complex version\n! a subroutine to calculate eigenvector and eigenvalue\n subroutine eigensystem_c(JOBZ,UPLO,N,A,W)\n\n use para, only : Dp, stdout\n implicit none\n\n! JOBZ (input) CHARACTER*1\n! = 'N': Compute eigenvalues only;\n! = 'V': Compute eigenvalues and eigenvectors.\n!\n character*1, intent(in) :: JOBZ\n\n! UPLO (input) CHARACTER*1\n! = 'U': Upper triangle of A is stored;\n! = 'L': Lower triangle of A is stored.\n character*1, intent(in) :: UPLO\n\n! N (input) INTEGER\n! The order of the matrix A. N >= 0.\n integer, intent(in) :: N\n\n! A (input/output) COMPLEX*16 array, dimension (LDA, N)\n! On entry, the Hermitian matrix A. If UPLO = 'U', the\n! leading N-by-N upper triangular part of A contains the\n! upper triangular part of the matrix A. If UPLO = 'L',\n! the leading N-by-N lower triangular part of A contains\n! the lower triangular part of the matrix A.\n! On exit, if JOBZ = 'V', then if INFO = 0, A contains the\n! orthonormal eigenvectors of the matrix A.\n! If JOBZ = 'N', then on exit the lower triangle (if UPLO='L')\n! or the upper triangle (if UPLO='U') of A, including the\n! diagonal, is destroyed.\n\n complex(Dp),intent(inout) :: A(N,N)\n\n! W (output) DOUBLE PRECISION array, dimension (N)\n! If INFO = 0, the eigenvalues in ascending order.\n\n real(Dp), intent(inout) :: W(N)\n \n integer :: info\n\n real(Dp),allocatable :: rwork(:)\n\n complex(Dp),allocatable :: work(:)\n\n allocate(rwork(16*N))\n allocate( work(16*N))\n rwork= 0d0\n work= 0d0\n\n info=0\n W=0.0d0\n\n if (N==1) then \n W=A(1, 1)\n A(1, 1)= 1d0\n return\n endif\n\n call zheev( JOBZ, UPLO, N, A, N, &\n W, work, 16*N, rwork, info )\n\n if (info.ne.0) then\n write(stdout, *) 'ERROR : something wrong with zheev'\n stop\n endif\n\n deallocate(rwork, work)\n return\n end subroutine eigensystem_c\n\n! real version\n! a subroutine to calculate eigenvector and eigenvalue\n subroutine eigensystem_r (JOBZ,UPLO,N,A,W)\n\n use para, only : Dp, stdout\n implicit none\n\n! JOBZ (input) CHARACTER*1\n! = 'N': Compute eigenvalues only;\n! = 'V': Compute eigenvalues and eigenvectors.\n!\n character*1, intent(in) :: JOBZ\n\n! UPLO (input) CHARACTER*1\n! = 'U': Upper triangle of A is stored;\n! = 'L': Lower triangle of A is stored.\n character*1, intent(in) :: UPLO\n\n! N (input) INTEGER\n! The order of the matrix A. N >= 0.\n integer, intent(in) :: N\n\n! A (input/output) COMPLEX*16 array, dimension (LDA, N)\n! On entry, the Hermitian matrix A. If UPLO = 'U', the\n! leading N-by-N upper triangular part of A contains the\n! upper triangular part of the matrix A. If UPLO = 'L',\n! the leading N-by-N lower triangular part of A contains\n! the lower triangular part of the matrix A.\n! On exit, if JOBZ = 'V', then if INFO = 0, A contains the\n! orthonormal eigenvectors of the matrix A.\n! If JOBZ = 'N', then on exit the lower triangle (if UPLO='L')\n! or the upper triangle (if UPLO='U') of A, including the\n! diagonal, is destroyed.\n\n real(Dp),intent(inout) :: A(N,N)\n\n! W (output) DOUBLE PRECISION array, dimension (N)\n! If INFO = 0, the eigenvalues in ascending order.\n\n real(Dp), intent(inout) :: W(N)\n \n integer :: info\n\n real(Dp),allocatable :: work(:)\n\n allocate( work(16*N))\n work= 0d0\n\n if (N==1) then \n W=A(1, 1)\n A(1, 1)= 1d0\n return\n endif\n\n info=0\n W=0.0d0\n call dsyev( JOBZ, UPLO, N, A, N, &\n W, work, 16*N, info )\n\n if (info.ne.0) then\n write(stdout, *) 'ERROR : something wrong with dsyev'\n stop\n endif\n\n deallocate(work)\n return\n end subroutine eigensystem_r\n\n! a subroutine to calculate eigenvector and eigenvalue\n subroutine zgeev_pack(N, A, W)\n\n use para, only : Dp\n implicit none\n\n! JOBVL (input) CHARACTER*1\n! JOBVR (input) CHARACTER*1\n! = 'N': Compute eigenvalues only;\n! = 'V': Compute eigenvalues and eigenvectors.\n!\n character*1 :: JOBVL\n character*1 :: JOBVR\n\n! N (input) INTEGER\n! The order of the matrix A. N >= 0.\n integer, intent(in) :: N\n\n! A (input/output) COMPLEX*16 array, dimension (LDA, N)\n! On entry, the Hermitian matrix A. If UPLO = 'U', the\n! leading N-by-N upper triangular part of A contains the\n! upper triangular part of the matrix A. If UPLO = 'L',\n! the leading N-by-N lower triangular part of A contains\n! the lower triangular part of the matrix A.\n! On exit, if JOBZ = 'V', then if INFO = 0, A contains the\n! orthonormal eigenvectors of the matrix A.\n! If JOBZ = 'N', then on exit the lower triangle (if UPLO='L')\n! or the upper triangle (if UPLO='U') of A, including the\n! diagonal, is destroyed.\n\n complex(Dp),intent(inout) :: A(N, N)\n\n! W (output) DOUBLE PRECISION array, dimension (N)\n! If INFO = 0, the eigenvalues in ascending order.\n\n! eigenvalues\n complex(Dp), intent(out) :: W(N)\n \n! left eigenvectors\n complex(dp), allocatable :: VL(:, :)\n\n! right eigenvectors\n complex(dp), allocatable :: VR(:, :)\n\n integer :: info\n\n integer :: lda\n integer :: ldvl\n integer :: ldvr\n\n integer :: lwork\n\n real(dp),allocatable :: rwork(:)\n\n complex(dp),allocatable :: work(:)\n\n !> only calculate eigenvalues\n JOBVL= 'N'\n JOBVR= 'N'\n\n lda=N\n ldvl=N\n ldvr=N\n lwork= 16*N\n allocate(VL(N, N))\n allocate(VR(N, N))\n\n allocate(rwork(16*N))\n allocate( work(lwork))\n VL= 0d0\n VR= 0d0\n rwork= 0d0\n work= 0d0\n\n info=0\n W=0.0d0\n\n if (N==1) then \n W=A(1, 1)\n VL(1, 1)= 1d0\n VR(1, 1)= 1d0\n return\n endif\n\n call ZGEEV( JOBVL, JOBVR, N, A, LDA, W, VL, LDVL, VR, LDVR, &\n WORK, LWORK, RWORK, INFO )\n if (info /= 0) then\n stop \">>> Error : something wrong happens in zgeev_pack\" \n endif\n\n return\n end subroutine zgeev_pack\n\n", "meta": {"hexsha": "690e878e700c97b512c3e2ead16811e2167f57bd", "size": 6397, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "stable/eigen.f90", "max_stars_repo_name": "dlnguyen/wannier_tools", "max_stars_repo_head_hexsha": "cc6748e3718ee2a89934a187490c37f9f520aeff", "max_stars_repo_licenses": ["OLDAP-2.3"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-14T12:07:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-14T12:07:24.000Z", "max_issues_repo_path": "stable/eigen.f90", "max_issues_repo_name": "jtsun/wannier_tools", "max_issues_repo_head_hexsha": "f3512e986c6546af6b823ee6b8a4b9118c53a9fa", "max_issues_repo_licenses": ["OLDAP-2.3"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "stable/eigen.f90", "max_forks_repo_name": "jtsun/wannier_tools", "max_forks_repo_head_hexsha": "f3512e986c6546af6b823ee6b8a4b9118c53a9fa", "max_forks_repo_licenses": ["OLDAP-2.3"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.2212765957, "max_line_length": 71, "alphanum_fraction": 0.5629201188, "num_tokens": 1942, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460332, "lm_q2_score": 0.7606506526772883, "lm_q1q2_score": 0.6724450566524812}} {"text": "FUNCTION igamma_s(a,x)\n USE mo_kind, only: sp\n USE mo_nrutil, ONLY : assert\n use mo_nr, ONLY : gcf,gser\n IMPLICIT NONE\n REAL(SP), INTENT(IN) :: a,x\n REAL(SP) :: gln\n REAL(SP) :: igamma_s\n call assert( x >= 0.0, a > 0.0, 'igamma_s args')\n if (x= 0.0), all(a > 0.0), 'igamma_v args')\n mask = (x= 0.0_dp, a > 0.0_dp, 'digamma_s args')\n if (x= 0.0_dp), all(a > 0.0_dp), 'digamma_v args')\n mask = (x* checking `test_stats_randn_real`..\"\n\n call check(mean(randn(mean=0.0, std=2.0, ndim=100)) <= 2.0, &\n msg=\"mean(randn(mean=0.0, std=2.0, ndim=10) <= 2.0) failed.\")\n call check(mean(randn(mean=0.0, std=2.0, ndim=100)) >= -2.0, &\n msg=\"mean(randn(mean=0.0, std=2.0, ndim=10) >= -2.0) failed.\")\n\n end subroutine test_stats_randn_real\n\nend module test_stats_randn\n", "meta": {"hexsha": "ba9977479c6f619a56526665ca0bd40acf87e92f", "size": 657, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/stats/test_stats_randn.f90", "max_stars_repo_name": "zoziha/forlab_z", "max_stars_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2021-08-31T15:23:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T02:44:46.000Z", "max_issues_repo_path": "test/stats/test_stats_randn.f90", "max_issues_repo_name": "zoziha/forlab_z", "max_issues_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-08-22T11:47:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-31T00:57:16.000Z", "max_forks_repo_path": "test/stats/test_stats_randn.f90", "max_forks_repo_name": "zoziha/forlab_z", "max_forks_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-07-16T03:16:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-31T13:09:42.000Z", "avg_line_length": 27.375, "max_line_length": 81, "alphanum_fraction": 0.6194824962, "num_tokens": 212, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8872045817875224, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6723186431006469}} {"text": "PROGRAM Particle_2D_Box\n IMPLICIT NONE\n\n REAL, PARAMETER :: pi = acos(-1.0)\n REAL:: bl1, bl2, x, y, psi ! bl is bond length\n CHARACTER*10:: filename\n INTEGER:: i, j, n1, n2, outunit\n bl1 = 1.\n bl2 = 1.\n WRITE(*, *) \"Enter the quantum number n1, n2\"\n READ *, n1, n2\n\n ! WRITE(fiblame, 10) \"psi.\", n\n ! 10 FORMAT(a, i0)\n WRITE(filename, fmt = \"(a, i0, i0)\") \"psi.\", n1, n2\n OPEN(UNIT = outunit, FILE = filename, FORM = \"formatted\")\n x = -0.01\n DO i = 1, 101\n x = x + 0.01\n y = -0.01\n DO j = 1, 101\n y = y + 0.01\n psi = 2.0 * sqrt(1./bl1*bl2) * sin(n1 * pi * x/bl1) * sin(n2 * pi * y/bl2);\n WRITE(outunit, *) x, y, psi, psi**2\n ENDDO\n WRITE(outunit, *)\n ENDDO\n CLOSE(outunit)\nEND\n", "meta": {"hexsha": "7dfd24159be438c853f14fa719b8d454552b95b4", "size": 805, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Practice-1/Particle_2D_Box.f90", "max_stars_repo_name": "arpitkekri/Code_With_FORTRAN", "max_stars_repo_head_hexsha": "fb731e6f8d8a47cfe38896fffd74a55d17efb2e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-02-21T05:24:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-27T10:25:24.000Z", "max_issues_repo_path": "Practice-1/Particle_2D_Box.f90", "max_issues_repo_name": "akhil18soni/Code_With_FORTRAN", "max_issues_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Practice-1/Particle_2D_Box.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.8333333333, "max_line_length": 87, "alphanum_fraction": 0.4894409938, "num_tokens": 312, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523146, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6723186427677419}} {"text": "!> @file\n!! check to see if value exceeds threshold\n\n! --------------------------------------------------------------\n!> @brief Check if the gradient exceeds the threshold\n!!\n!! @param[in] blockno the block number\n!! @param[in] qval the \n!! @param[in] qmin the minimum q value\n!! @param[in] qmax the maximum q value\n!! @param[in] quad the value and adjacent values of q\n!! @param[in] dx, dy the spacing in the x and y directions\n!! @param[in] xc, yc the coordinate of the cell\n!! @param[in] threshold the threshold\n!! @param[in] init_flag true if in init stage\n!! @param[in] is_ghost true if cell is a ghost cell\n!! @return 1 if exceeds threshold, 0 if not, -1 if inconclusive.\n! --------------------------------------------------------------\ninteger function fclaw2d_clawpatch_gradient_exceeds_th(blockno,& \n qval,qmin,qmax,quad, & \n dx,dy,xc,yc,threshold, &\n init_flag, is_ghost)\n implicit none\n \n double precision :: qval,qmin,qmax,threshold\n double precision :: quad(-1:1,-1:1)\n double precision :: dx,dy, xc, yc\n integer :: blockno, init_flag\n logical(kind=4) :: is_ghost\n\n double precision :: dqx, dqy\n double precision :: xp, yp, zp, xpp, ypp, zpp, xpm, ypm, zpm\n double precision, dimension(3) :: t1, t2, t1inv, t2inv\n double precision, dimension(2,2) :: gmat, gmatinv\n double precision :: grad(3), dx2, dy2, d, ds\n\n\n integer*8 :: cont, get_context\n integer :: fclaw2d_map_is_used\n\n double precision :: clawpatch_gradient_dot\n integer :: refine\n integer :: m\n\n if (is_ghost) then\n!! # quad may have uninitialized values. Test is inconclusive\n fclaw2d_clawpatch_gradient_exceeds_th = -1\n return\n endif\n\n cont = get_context()\n\n dx2 = 2*dx\n dy2 = 2*dy\n\n dqx = (quad(1,0) - quad(-1,0))/dx2\n dqy = (quad(0,1) - quad(0,-1))/dy2\n\n refine = 0\n if (fclaw2d_map_is_used(cont) .ne. 0) THEN\n CALL fclaw2d_map_c2m(cont,blockno,xc,yc,xp,yp,zp)\n CALL fclaw2d_map_c2m(cont,blockno,xc+dx,yc,xpp,ypp,zpp)\n CALL fclaw2d_map_c2m(cont,blockno,xc-dx,yc,xpm,ypm,zpm)\n t1(1) = (xpp - xpm)/dx2\n t1(2) = (ypp - ypm)/dx2\n t1(3) = (zpp - zpm)/dx2\n\n CALL fclaw2d_map_c2m(cont,blockno,xc,yc+dy,xpp,ypp,zpp)\n CALL fclaw2d_map_c2m(cont,blockno,xc,yc-dy,xpm,ypm,zpm)\n t2(1) = (xpp - xpm)/dy2\n t2(2) = (ypp - ypm)/dy2\n t2(3) = (zpp - zpm)/dy2\n\n gmat(1,1) = clawpatch_gradient_dot(t1,t1)\n gmat(1,2) = clawpatch_gradient_dot(t1,t2)\n gmat(2,1) = gmat(1,2)\n gmat(2,2) = clawpatch_gradient_dot(t2,t2)\n\n d = gmat(1,1)*gmat(2,2) - gmat(1,2)*gmat(2,1)\n\n gmatinv(1,1) = gmat(2,2)/d\n gmatinv(2,2) = gmat(1,1)/d\n gmatinv(1,2) = -gmat(1,2)/d\n gmatinv(2,1) = -gmat(2,1)/d\n\n do m = 1,3\n t1inv(m) = gmatinv(1,1)*t1(m) + gmatinv(1,2)*t2(m)\n t2inv(m) = gmatinv(2,1)*t1(m) + gmatinv(2,2)*t2(m)\n grad(m) = dqx*t1inv(m) + dqy*t2inv(m)\n end do\n else\n grad(1) = dqx\n grad(2) = dqy\n grad(3) = 0\n endif\n\n ds = sqrt(clawpatch_gradient_dot(grad,grad))\n\n if (ds .gt. threshold) then\n refine = 1\n endif\n\n fclaw2d_clawpatch_gradient_exceeds_th = refine\n\nend function fclaw2d_clawpatch_gradient_exceeds_th\n\n! --------------------------------------------------------------\n!> @brief Dot product of two vector\n!!\n!! @param[in] u, v the vectors\n!! @return the dot product\n! --------------------------------------------------------------\ndouble precision function clawpatch_gradient_dot(u,v)\n implicit none\n\n double precision :: u(3), v(3)\n\n clawpatch_gradient_dot = u(1)*v(1) + u(2)*v(2) + u(3)*v(3)\n\nend function clawpatch_gradient_dot\n\n", "meta": {"hexsha": "4d3697c0b1884acfe50e046f3c95b5518d39bc13", "size": 3831, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/patches/clawpatch/fort_user/fclaw2d_clawpatch_gradient_exceeds_th.f90", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/patches/clawpatch/fort_user/fclaw2d_clawpatch_gradient_exceeds_th.f90", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-08-02T09:52:43.000Z", "max_issues_repo_issues_event_max_datetime": "2017-08-02T14:16:23.000Z", "max_forks_repo_path": "src/patches/clawpatch/fort_user/fclaw2d_clawpatch_gradient_exceeds_th.f90", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.4016393443, "max_line_length": 67, "alphanum_fraction": 0.5593839729, "num_tokens": 1291, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045966995027, "lm_q2_score": 0.757794360334681, "lm_q1q2_score": 0.6723186398418882}} {"text": "!\n! CalculiX - A 3-dimensional finite element program\n! Copyright (C) 1998-2019 Guido Dhondt\n!\n! This program is free software; you can redistribute it and/or\n! modify it under the terms of the GNU General Public License as\n! published by the Free Software Foundation(version 2);\n! \n!\n! This program is distributed in the hope that it will be useful,\n! but WITHOUT ANY WARRANTY; without even the implied warranty of \n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \n! GNU General Public License for more details.\n!\n! You should have received a copy of the GNU General Public License\n! along with this program; if not, write to the Free Software\n! Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n! \n subroutine hns(b,theta,rho,dg,sqrts0,xflow,h1,h2)\n!\n! determine the flow depth h2 downstream of a hydraulic jump, \n! corresponding to a upstream flow depth of h1\n! \n implicit none\n! \n real*8 b,rho,dg,sqrts0,xflow,h1,h2,c2,f,df,dh2,hk,\n & xflow2,tth,A1,yg1,A2,yg2,dA2dh2,dyg2dh2,theta\n!\n call hcrit(xflow,rho,b,theta,dg,sqrts0,hk)\n!\n h2=h1*(-1.d0+dsqrt(1.d0+8.d0*(hk/h1)**3))/2.d0\n!\n if(dabs(theta).lt.1.d-10) return\n!\n! hns for a trapezoid, non-rectangular cross section\n!\n c2=rho*rho*dg*sqrts0\n xflow2=xflow*xflow\n tth=dtan(theta)\n A1=h1*(b+h1*tth)\n yg1=h1*(3.d0*b+2.d0*h1*tth)/(6.d0*(b+h1*tth))\n!\n! Newton-Raphson iterations\n!\n do\n A2=h2*(b+h2*tth)\n yg2=h2*(3.d0*b+2.d0*h2*tth)/(6.d0*(b+h2*tth))\n dA2dh2=b+2.d0*h2*tth\n dyg2dh2=((3.d0*b+4.d0*h2*tth)*(b+tth)\n & -tth*h2*(3.d0*b+2.d0*h2*tth))/\n & (6.d0*(b+h2*tth)**2)\n f=A2*xflow2+c2*(A1*A1*A2*yg1-A1*A2*A2*yg2)-A1*xflow2\n df=dA2dh2*xflow2+c2*(A1*A1*yg1*dA2dh2-2.d0*A1*A2*dA2dh2*yg2\n & -A1*A2*A2*dyg2dh2)\n dh2=f/df\n if(dabs(dh2)/h2.lt.1.d-3) exit\n h2=h2-dh2\n enddo\n!\n write(*,*) 'hns ','h1= ',h1,'h2= ',h2,'hk= ',hk\n!\n return\n end\n \n\n", "meta": {"hexsha": "a9a8b4434509c09be80e0d76444888ad48ffd854", "size": 2131, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ccx_prool/CalculiX/ccx_2.16/src/hns.f", "max_stars_repo_name": "alleindrach/calculix-desktop", "max_stars_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ccx_prool/CalculiX/ccx_2.16/src/hns.f", "max_issues_repo_name": "alleindrach/calculix-desktop", "max_issues_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ccx_prool/CalculiX/ccx_2.16/src/hns.f", "max_forks_repo_name": "alleindrach/calculix-desktop", "max_forks_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.2878787879, "max_line_length": 71, "alphanum_fraction": 0.5870483341, "num_tokens": 769, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425333801889, "lm_q2_score": 0.7310585844894971, "lm_q1q2_score": 0.6723125686892559}} {"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\r\n \r\n program Gamma\r\n implicit none\r\n integer :: n\r\n integer, parameter :: rp = selected_real_kind(15)\r\n integer :: i\r\n Real (kind = rp) :: a, gama, nPlusOne\r\n n = 1000000000\r\n nPlusOne = n + 1.0_rp\r\n a = 0.0_rp\r\n do i = 1,n,1\r\n a = (a + (1.0_rp/i)) \r\n end do\r\n print *, a\r\n gama = a - log(nPlusOne)\r\n print *, \"N + 1 = \", nPlusOne\r\n print *, \"Gamma is approx: \" , gama\r\n end program Gamma\r\n\r\n\r\n\r\n\r\n", "meta": {"hexsha": "754446b86188a90ed33054b576540c20f3db7e07", "size": 642, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Gamma.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": "Gamma.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": "Gamma.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": 22.1379310345, "max_line_length": 59, "alphanum_fraction": 0.4548286604, "num_tokens": 188, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9196425399873763, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6723125681308588}} {"text": "MODULE PS4PARA\n IMPLICIT NONE\n INTEGER:: I ! FOR ITER\n REAL(KIND=8), PARAMETER:: ALPHA=1.5, BETA=0.9932\n REAL(KIND=8), DIMENSION(2), PARAMETER:: STATES=(/1.0, 0.5/)\n INTEGER, PARAMETER:: NZ=SIZE(STATES), NA=700\n REAL(KIND=8), DIMENSION(NZ, NZ), PARAMETER:: PI=TRANSPOSE(RESHAPE((/0.97, 0.03,0.5,0.5/),(/2,2/)))\n REAL(KIND=8), PARAMETER:: A_MIN=-2., A_MAX=5., STEPS=(A_MAX-A_MIN)/(FLOAT(NA)-1.)\n REAL(KIND=8), DIMENSION(NA), PARAMETER:: A_GRID=(/(I*STEPS, I=1, NA)/) + A_MIN - STEPS\n LOGICAL:: COMPLETE=.FALSE. ! COMPLETE MARKET IF 1 OR INCOMPLETE MARKET IF 0\nEND MODULE\n\nMODULE PS4RES\n USE PS4PARA\n IMPLICIT NONE\n REAL(KIND=8):: HIGH_Q=1., LOW_Q=0.9932, Q\n REAL(KIND=8), DIMENSION(NA,NZ):: VFUNC=0., VFUNC_NEW=0., CONSUM_ARR, LAMBDA\n REAL(KIND=8), DIMENSION(NA*NZ):: STAT_DIST\n REAL(KIND=8), DIMENSION(NA*NZ,NA*NZ):: A_CHANGE_MAT\n REAL(KIND=8), DIMENSION(700):: LORENZ\n INTEGER, DIMENSION(NA,NZ):: PFUNC=0\nEND MODULE\n\nPROGRAM PS4\n USE PS4PARA\n USE PS4RES\n IMPLICIT NONE\n INTEGER:: SROWIDX\n REAL(KIND=8):: ERROR_Q=100., ERROR_VFI, CRIT=1e-3\n REAL(KIND=8), DIMENSION(NA,NZ):: VFUNC_INCOMPLETE=0.\n\n DO WHILE (ERROR_Q> CRIT)\n PRINT*, \"Q\", Q\n Q = (HIGH_Q+LOW_Q)/2.\n ERROR_VFI=100.\n IF (COMPLETE) THEN\n ! MUST RUN THE INCOMPLETE VERSION PRIOR TO\n OPEN(UNIT=13, FILE='VFUNC', STATUS='OLD')\n DO SROWIDX=1,NA\n READ(UNIT=13, FMT=*) VFUNC_INCOMPLETE(SROWIDX,:)\n ENDDO\n CLOSE(UNIT=13)\n DO WHILE (ERROR_VFI> CRIT)\n CALL BELLMAN_COMPLETE(ERROR_VFI, VFUNC_INCOMPLETE)\n ENDDO\n ELSE\n DO WHILE (ERROR_VFI> CRIT)\n CALL BELLMAN(ERROR_VFI)\n ENDDO\n ENDIF\n CALL POP_A_CHANGE_MAT()\n CALL FIND_STAT_DIST()\n CALL COMPUTE_ERROR(ERROR_Q)\n ENDDO\n PRINT*, \"Q\", Q\n CALL FIND_LORENZ()\n IF (COMPLETE) THEN\n CALL WELFARE(VFUNC_INCOMPLETE)\n ENDIF\n CALL WRITE_ALL()\nEND PROGRAM PS4\n\nSUBROUTINE BELLMAN(ERROR_VFI)\n USE PS4PARA\n USE PS4RES\n IMPLICIT NONE\n REAL(KIND=8), INTENT(OUT):: ERROR_VFI\n REAL(KIND=8):: CONSUM, UTIL, COND_UTIL, CU, NU\n REAL(KIND=8), DIMENSION(NA,NZ):: ABS_DIFF\n INTEGER:: RIDX, CIDX, CHOICE\n\n DO RIDX=1, NA\n DO CIDX=1, NZ\n COND_UTIL=-1e10\n DO CHOICE=1, NA\n CONSUM = STATES(CIDX) + A_GRID(RIDX) - Q*A_GRID(CHOICE)\n IF (CONSUM>0.) THEN\n CU = CONSUM**(1-ALPHA)/(1-ALPHA) ! CURRENT UTIL\n NU = SUM(PI(CIDX,:)*VFUNC(CHOICE,:))! NEXT EXPECTED UTIL\n UTIL = CU + BETA*NU\n IF (UTIL>COND_UTIL) THEN\n VFUNC_NEW(RIDX, CIDX)=UTIL\n PFUNC(RIDX, CIDX)=CHOICE\n COND_UTIL=UTIL\n CONSUM_ARR(RIDX, CIDX) = CONSUM\n ENDIF\n ENDIF\n ENDDO\n ENDDO\n ENDDO\n ABS_DIFF = ABS(VFUNC_NEW-VFUNC)\n ERROR_VFI = MAXVAL(ABS_DIFF)\n VFUNC = VFUNC_NEW\n \nEND SUBROUTINE\n\nSUBROUTINE BELLMAN_COMPLETE(ERROR_VFI, VFUNC_INCOMPLETE)\n USE PS4PARA\n USE PS4RES\n IMPLICIT NONE\n REAL(KIND=8), INTENT(OUT):: ERROR_VFI\n REAL(KIND=8):: CONSUM, UTIL, COND_UTIL, CU, NOM, DENOM\n REAL(KIND=8), DIMENSION(NA,NZ):: ABS_DIFF\n REAL(KIND=8), DIMENSION(NA,NZ), INTENT(IN):: VFUNC_INCOMPLETE\n INTEGER:: RIDX, CIDX, CHOICE\n\n DO RIDX=1, NA\n DO CIDX=1, NZ\n COND_UTIL=-1e10\n DO CHOICE=1, NA\n CONSUM = STATES(CIDX) + A_GRID(RIDX) - Q*A_GRID(CHOICE)\n IF (CONSUM>0.) THEN\n CU = CONSUM**(1-ALPHA)/(1-ALPHA) ! CURRENT UTIL\n UTIL = CU ! COMPLETE MARKET NEXT UTIL= CURRENT UTIL\n IF (UTIL>COND_UTIL) THEN\n VFUNC_NEW(RIDX, CIDX)=UTIL\n PFUNC(RIDX, CIDX)=CHOICE\n COND_UTIL=UTIL\n CONSUM_ARR(RIDX, CIDX) = CONSUM\n ENDIF\n ENDIF\n ENDDO\n NOM = VFUNC_NEW(RIDX, CIDX) + 1/((1-ALPHA)*(1-BETA))\n DENOM = VFUNC_INCOMPLETE(RIDX, CIDX) + 1/((1-ALPHA)*(1-BETA))\n LAMBDA(RIDX, CIDX) = (NOM/DENOM)**(1/(1-ALPHA))-1\n ENDDO\n ENDDO\n ABS_DIFF = ABS(VFUNC_NEW-VFUNC)\n ERROR_VFI = MAXVAL(ABS_DIFF)\n VFUNC = VFUNC_NEW\n\nEND SUBROUTINE\n\nSUBROUTINE POP_A_CHANGE_MAT()\n USE PS4PARA\n USE PS4RES\n IMPLICIT NONE\n INTEGER:: RIDX, CIDX, CUR_IDX, NEXT_IDX, CHOICE, NEXT_Z\n\n A_CHANGE_MAT=0.\n DO RIDX=1, NA\n DO CIDX=1, NZ\n CUR_IDX = 2*RIDX -2 + CIDX\n CHOICE=PFUNC(RIDX, CIDX)\n DO NEXT_Z=1, NZ\n NEXT_IDX= 2*CHOICE -2 + NEXT_Z\n A_CHANGE_MAT(CUR_IDX, NEXT_IDX) = A_CHANGE_MAT(CUR_IDX, NEXT_IDX)+ PI(CIDX, NEXT_Z)\n ENDDO\n ENDDO\n ENDDO\nEND SUBROUTINE\n\nSUBROUTINE FIND_STAT_DIST()\n USE PS4PARA\n USE PS4RES\n IMPLICIT NONE\n REAL(KIND=8):: ERROR_STAT, CRIT_STAT=1e-3\n REAL(KIND=8), DIMENSION(NA*NZ) :: STAT_DIST_NEW, ABS_DIFF\n\n STAT_DIST= 1/(FLOAT(NA)*2.)\n ERROR_STAT=100.\n DO WHILE (ERROR_STAT>CRIT_STAT)\n STAT_DIST_NEW = MATMUL(STAT_DIST, A_CHANGE_MAT)\n ABS_DIFF = ABS(STAT_DIST_NEW-STAT_DIST)\n ERROR_STAT = MAXVAL(ABS_DIFF)\n STAT_DIST = STAT_DIST_NEW\n ENDDO\nEND SUBROUTINE\n\nSUBROUTINE COMPUTE_ERROR(ERROR_Q)\n USE PS4PARA\n USE PS4RES\n IMPLICIT NONE\n REAL(KIND=8), INTENT(OUT):: ERROR_Q\n INTEGER:: RIDX, CIDX\n REAL(KIND=8):: NET_ASSET! MARKET CLEARING\n\n NET_ASSET = 0.\n DO RIDX=1, NA\n DO CIDX=1, NZ\n NET_ASSET = NET_ASSET + A_GRID(PFUNC(RIDX, CIDX))*STAT_DIST(2*RIDX -2 + CIDX)\n ENDDO\n ENDDO\n\n IF (NET_ASSET>0.) THEN\n HIGH_Q=Q\n ELSE\n LOW_Q = Q\n ENDIF\n ERROR_Q = ABS(HIGH_Q-LOW_Q)\nEND SUBROUTINE\n\nSUBROUTINE FIND_LORENZ()\n USE PS4PARA\n USE PS4RES\n IMPLICIT NONE\n INTEGER:: RIDX\n REAL(KIND=8):: GINI\n REAL(KIND=8), DIMENSION(NA):: DEGREE\n\n DEGREE=(/(I*(1./FLOAT(NA)), I=1,NA)/)\n\n GINI= 0.\n LORENZ(1) = STAT_DIST(1)\n DO RIDX = 2, 700\n LORENZ(RIDX)= LORENZ(RIDX-1) + STAT_DIST(RIDX*2-2+1) + STAT_DIST(RIDX*2-2+2)\n GINI = GINI + ABS(DEGREE(RIDX)-LORENZ(RIDX))\n ENDDO\n PRINT*, \"degree\", degree(na), degree(na-1)\n PRINT*,\"GINI\", GINI/FLOAT(NA)\nEND SUBROUTINE\n\nSUBROUTINE WRITE_ALL()\n USE PS4PARA\n USE PS4RES\n IMPLICIT NONE\n INTEGER:: SROWIDX\n INTEGER, DIMENSION(2):: SIDX\n CHARACTER(LEN=130):: PATH=\"./\"\n CHARACTER(LEN=150):: FILE_NAME\n\n FILE_NAME = TRIM(PATH)//\"VFUNC\"\n OPEN(UNIT=1, FILE=FILE_NAME, STATUS='REPLACE') ! START WITH THE TWO VALUE FUNCTIONS\n DO SROWIDX=1, NA\n WRITE(UNIT=1,FMT=*) VFUNC(SROWIDX,:)\n ENDDO\n CLOSE(UNIT=1)\n\n FILE_NAME = TRIM(PATH)//\"PFUNC\"\n OPEN(UNIT=2, FILE=FILE_NAME, STATUS='REPLACE') ! ALSO SAVE POLICY FUNCTIONS\n DO SROWIDX=1, NA\n WRITE(UNIT=2,FMT=*) PFUNC(SROWIDX,:)\n ENDDO\n CLOSE(UNIT=2)\n\n FILE_NAME = TRIM(PATH)//\"STATDIST\"\n OPEN(UNIT=3, FILE=FILE_NAME, STATUS='REPLACE') ! ALSO SAVE POLICY FUNCTIONS\n DO SROWIDX=1, NA\n SIDX = (/SROWIDX*2-1, SROWIDX*2/)\n WRITE(UNIT=3,FMT=*) STAT_DIST(SIDX)\n ENDDO\n CLOSE(UNIT=3)\n\n FILE_NAME = TRIM(PATH)//\"AGRID\"\n OPEN(UNIT=4, FILE=FILE_NAME, STATUS='REPLACE') ! FOR HAVING THE X-AXIS OF PLOT\n DO SROWIDX=1, NA\n WRITE(UNIT=4,FMT=*) A_GRID(SROWIDX)\n ENDDO\n CLOSE(UNIT=4)\n\n FILE_NAME = TRIM(PATH)//\"LORENZ\"\n OPEN(UNIT=5, FILE=FILE_NAME, STATUS='REPLACE') ! FOR HAVING THE X-AXIS OF PLOT\n DO SROWIDX=1, 100\n WRITE(UNIT=5,FMT=*) LORENZ(SROWIDX)\n ENDDO\n CLOSE(UNIT=5)\n\n IF (COMPLETE) THEN\n FILE_NAME = TRIM(PATH)//\"LAMBDA\"\n OPEN(UNIT=6, FILE=FILE_NAME, STATUS='REPLACE') ! FOR HAVING THE X-AXIS OF PLOT\n DO SROWIDX=1, NA\n WRITE(UNIT=6,FMT=*) LAMBDA(SROWIDX,:)\n ENDDO\n CLOSE(UNIT=6)\n ENDIF\nEND SUBROUTINE\n\nSUBROUTINE WELFARE(VFUNC_INCOMPLETE)\n USE PS4PARA\n USE PS4RES\n IMPLICIT NONE\n REAL(KIND=8):: WG=0., WINC=0., WFB=0., VOTE=0.\n INTEGER:: RIDX, CIDX, DIS_LOC\n REAL(KIND=8), DIMENSION(NA,NZ), INTENT(IN):: VFUNC_INCOMPLETE\n PRINT*, SUM(STAT_DIST), \"STAT\"\n DO RIDX=1,NA\n DO CIDX=1, NZ\n DIS_LOC = RIDX*2-2 + CIDX\n WG = WG+ LAMBDA(RIDX, CIDX)* STAT_DIST(DIS_LOC)\n WINC = WINC +VFUNC_INCOMPLETE(RIDX, CIDX)*STAT_DIST(DIS_LOC)\n WFB = WFB + VFUNC(RIDX, CIDX)*STAT_DIST(DIS_LOC)\n IF (LAMBDA(RIDX, CIDX)>0.) THEN\n VOTE = VOTE + STAT_DIST(DIS_LOC)\n ENDIF\n ENDDO\n ENDDO\n PRINT*, \"FRIST BEST\", WFB\n PRINT*, \"WINC\", WINC\n PRINT*, \"WG\", WG\n PRINT*, \"VOTING FOR\", VOTE\nEND SUBROUTINE\n", "meta": {"hexsha": "d8b7368ae2335b51c80c25bb333f18e1f4d93f59", "size": 9038, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "ps4.f95", "max_stars_repo_name": "hkchekc/EconComputations", "max_stars_repo_head_hexsha": "83f804b6f3b9d1b18a242389a64e6e9b970168b0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ps4.f95", "max_issues_repo_name": "hkchekc/EconComputations", "max_issues_repo_head_hexsha": "83f804b6f3b9d1b18a242389a64e6e9b970168b0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-10-05T08:42:15.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-05T08:42:15.000Z", "max_forks_repo_path": "ps4.f95", "max_forks_repo_name": "hkchekc/EconComputations", "max_forks_repo_head_hexsha": "83f804b6f3b9d1b18a242389a64e6e9b970168b0", "max_forks_repo_licenses": ["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.9520547945, "max_line_length": 102, "alphanum_fraction": 0.5691524674, "num_tokens": 3018, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425311777929, "lm_q2_score": 0.7310585844894971, "lm_q1q2_score": 0.6723125670791755}} {"text": "!*********************************************************************\n! This file is part of Polylogarithm.\n!\n! Polylogarithm is licenced under the MIT License.\n!*********************************************************************\n\n\n!*********************************************************************\n!> @brief Complex trilogarithm \\f$\\mathrm{Li}_3(z)\\f$\n!> @param z complex argument\n!> @return \\f$\\mathrm{Li}_3(z)\\f$\n!> @author Alexander Voigt\n!*********************************************************************\ndouble complex function cdli3(z)\n implicit none\n double complex :: z, u, u2, u4, u8, c0, c1, lmz, rest, fast_pos_cdlog\n double precision :: rz, iz, nz, pz, lnz, arg\n double precision, parameter :: PI = 3.1415926535897932D0\n double precision, parameter :: zeta2 = 1.6449340668482264D0\n double precision, parameter :: zeta3 = 1.2020569031595943D0\n double precision, parameter :: bf(18) = (/ &\n 1.0D0 , -3.0D0/8.0D0 , &\n 17.0D0/216.0D0 , -5.0D0/576.0D0 , &\n 1.2962962962962963D-04, 8.1018518518518519D-05, &\n -3.4193571608537595D-06, -1.3286564625850340D-06, &\n 8.6608717561098513D-08, 2.5260875955320400D-08, &\n -2.1446944683640648D-09, -5.1401106220129789D-10, &\n 5.2495821146008294D-11, 1.0887754406636318D-11, &\n -1.2779396094493695D-12, -2.3698241773087452D-13, &\n 3.1043578879654623D-14, 5.2617586299125061D-15 /)\n double precision, parameter :: cs(7) = (/ &\n -3.4722222222222222D-03, 1.1574074074074074D-05, &\n -9.8418997228521038D-08, 1.1482216343327454D-09, &\n -1.5815724990809166D-11, 2.4195009792525152D-13, &\n -3.9828977769894877D-15 /)\n\n rz = real(z)\n iz = aimag(z)\n\n if (iz .eq. 0) then\n if (rz .eq. 0) then\n cdli3 = 0\n return\n endif\n if (rz .eq. 1) then\n cdli3 = zeta3\n return\n endif\n if (rz .eq. -1) then\n cdli3 = -0.75D0*zeta3\n return\n endif\n if (rz .eq. 0.5D0) then\n cdli3 = 0.53721319360804020D0\n return\n endif\n endif\n\n nz = rz**2 + iz**2\n pz = datan2(iz, rz)\n lnz = 0.5D0*log(nz)\n\n if (lnz**2 + pz**2 .lt. 1) then ! |log(z)| < 1\n u = dcmplx(lnz, pz) ! log(z)\n u2 = u**2\n u4 = u2**2\n u8 = u4**2\n c0 = zeta3 + u*(zeta2 - u2/12)\n c1 = 0.25D0*(3 - 2*fast_pos_cdlog(-u))\n cdli3 = &\n c0 + &\n c1*u2 + &\n u4*(cs(1) + u2*cs(2)) + &\n u8*(cs(3) + u2*cs(4) + u4*(cs(5) + u2*cs(6))) + &\n u8*u8*cs(7)\n return\n endif\n\n if (nz .le. 1) then\n u = -fast_pos_cdlog(1 - z)\n rest = 0\n else ! nz > 1\n if (pz .gt. 0) then\n arg = pz - PI\n else\n arg = pz + PI\n endif\n lmz = dcmplx(lnz, arg) ! log(-z)\n u = -fast_pos_cdlog(1 - 1/z)\n rest = -lmz*(lmz**2/6 + zeta2)\n endif\n\n u2 = u**2\n u4 = u2**2\n u8 = u4**2\n\n cdli3 = &\n rest + &\n u*bf(1) + &\n u2*(bf(2) + u*bf(3)) + &\n u4*(bf(4) + u*bf(5) + u2*(bf(6) + u*bf(7))) + &\n u8*(bf(8) + u*bf(9) + u2*(bf(10) + u*bf(11)) + &\n u4*(bf(12) + u*bf(13) + u2*(bf(14) + u*bf(15)))) + &\n u8*u8*(bf(16) + u*bf(17) + u2*bf(18))\n\nend function cdli3\n", "meta": {"hexsha": "71c5858230981e1fcbfafb62bf4a0859a3320c7b", "size": 3609, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/Li3.f90", "max_stars_repo_name": "Expander/polylogarithm", "max_stars_repo_head_hexsha": "01e76023d9cd88c697fb1230c49e75d9493eeef2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2018-06-02T06:09:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-07T12:42:44.000Z", "max_issues_repo_path": "src/fortran/Li3.f90", "max_issues_repo_name": "Expander/polylogarithm", "max_issues_repo_head_hexsha": "01e76023d9cd88c697fb1230c49e75d9493eeef2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-12-05T12:19:59.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-20T09:17:40.000Z", "max_forks_repo_path": "src/fortran/Li3.f90", "max_forks_repo_name": "Expander/polylogarithm", "max_forks_repo_head_hexsha": "01e76023d9cd88c697fb1230c49e75d9493eeef2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-11-23T01:52:08.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-11T04:14:39.000Z", "avg_line_length": 33.7289719626, "max_line_length": 71, "alphanum_fraction": 0.4308672763, "num_tokens": 1314, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425311777929, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6723125616905372}} {"text": " ! Implicit FTSC FDM Solver using TDMA algorithm and ADI method for parabolic 2D heat transfer equation\r\n !-------------------------------------------------------------\r\n !------------------By Arthur Rostami -------------------------\r\n !-------------------------------------------------------------\r\n\r\nprogram CFD_FIRST_PROJECT_IMPLICIT\r\n implicit none\r\n !_____________________________Variables_____________________________\r\n integer:: i,j,k,xF,yF,xG,yG,L,H,time\r\n real:: e,alpha,dx,dt,w,t_st,t_fin,m,n\r\n real,allocatable:: T(:,:),x(:),y(:),er(:,:),TF(:,:),TG(:,:),T0(:,:),T1(:,:),T2(:,:),T3(:,:),T4(:,:)\r\n real,allocatable:: a(:,:),b(:,:),c(:,:),d(:,:),c_new(:,:),d_new(:,:),temp1(:,:),temp2(:,:)\r\n\r\n !_____________________________Define Parameters_____________________\r\n print*, 'This Method is always stable, you can choose any positive value for dx and dt!'\r\n print*, 'Please enter delta x:'\r\n read*, dx\r\n print*, 'Please enter delta t:'\r\n read*, dt\r\n L=2.0 ! Length of the plate\r\n H=1.5 ! Height of the plate\r\n m=(L/dx)+1 ! number of grid points in x direction\r\n n=(H/dx)+1 ! number of grid points in x direction\r\n alpha=23.1E-6 ! thermal diffusivity, m2/s\r\n w=(alpha*dt)/(dx**2)\r\n\r\n allocate(T(m,n),x(m),y(n),er(m,n),TF(1,100000),TG(1,100000),T0(m,n),T1(m,n),T2(m,n),T3(m,n),T4(m,n),temp1(m,n),temp2(m,n))\r\n allocate(a(2:m-1,2:n-1),b(2:m-1,2:n-1),c(2:m-1,2:n-1),d(2:m-1,2:n-1),c_new(2:m-1,2:n-1),d_new(2:m-1,2:n-1))\r\n !_____________________________Defining F & G locations_____________________\r\n xF=(0.5/dx)+1 !point F location\r\n yF=(0.5/dx)+1\r\n\r\n xG=(1/dx)+1 !point G location\r\n yG=(0.75/dx)+1\r\n\r\n !_____________________________Mesh Generation_____________________________\r\n do i=1,m\r\n x(i)=(i-1)*dx\r\n end do\r\n do j=1,n\r\n y(j)=(j-1)*dx\r\n end do\r\n\r\n !_____________________________Initial Condition____________________________\r\n do i=1,m\r\n do j=1,n\r\n T(i,j)=25\r\n temp1(i,j)=25\r\n temp2(i,j)=25\r\n end do\r\n end do\r\n !_____________________________________________________________________________\r\n !____________________FTCS Implicit Solver Using ADI method____________________\r\n !_____________________________________________________________________________\r\n k=1 !time step counter\r\n call cpu_time(t_st)\r\ndo\r\n !_____________________________Boundary condition_____________________________\r\n do j=2,n-1\r\n T(1,j)=(T(2,j)+10*dx)/(0.5*dx+1)!BC on wall AB\r\n temp1(i,j)=(temp1(2,j)+10*dx)/(0.5*dx+1)\r\n temp2(i,j)=(temp2(2,j)+10*dx)/(0.5*dx+1)\r\n end do\r\n\r\n do i=1,m\r\n T(i,1)=T(i,2) !BC on wall BD\r\n temp1(i,1)=temp1(i,2)\r\n temp2(i,1)=temp1(i,2)\r\n end do\r\n\r\n do i=1,m\r\n T(i,n)=100 !BC on wall AC\r\n temp1(i,n)=100\r\n temp2(i,n)=100\r\n end do\r\n\r\n do j=2,n-1\r\n T(m,j)=25 !BC on wall CD\r\n temp1(m,j)=25\r\n temp2(m,j)=25\r\n end do\r\n\r\n !_____________________________Saving Temp at chosen times and locations F and G_____________________________\r\n if(k==1) T0(:,:)=T(:,:) !saving temperature at t=0*dt\r\n if(k==2000) T1(:,:)=T(:,:) !saving temperature at t=2000*dt\r\n if(k==10000) T2(:,:)=T(:,:) !saving temperature at t=10000*dt\r\n if(k==50000) T3(:,:)=T(:,:) !saving temperature at t=50000*dt\r\n if(k==100000)T4(:,:)=T(:,:) !saving temperature at t=100000*dt\r\n TF(1,k)=T(xF,yF) !saving temperature of point F for different times\r\n TG(1,k)=T(xG,yG) !saving temperature of point G for different times\r\n\r\n !_____ADI for first half-step_______\r\n !___________________________________\r\n do j=2,n-1\r\n do i=3,m-2\r\n a(i,j)=w\r\n b(i,j)=-2-2*w\r\n c(i,j)=w\r\n d(i,j)=-w*T(i,j+1)-w*T(i,j-1)+(-2+2*w)*T(i,j)\r\n end do\r\n\r\n a(2,j)=0\r\n b(2,j)=-2-2*w+1/(1+0.5*dx)\r\n c(2,j)=w\r\n d(2,j)=-w*T(i,j+1)-w*T(i,j-1)+(-2+2*w)*T(i,j)-10*dx/(1+0.5*dx)\r\n\r\n a(m-1,j)=w\r\n b(m-1,j)=-2-2*w\r\n c(m-1,j)=0\r\n d(m-1,j)=-w*T(i,j+1)-w*T(i,j-1)+(-2+2*w)*T(i,j)-w*T(m,j)\r\n\r\n end do\r\n !_____TDMA Solver_____\r\n do j=2,n-1\r\n c_new(2,j)=c(2,j)/b(2,j)\r\n d_new(2,j)=d(2,j)/b(2,j)\r\n do i=3,m-1\r\n c_new(i,j)=c(i,j)/(b(i,j)-a(i,j)*c_new(i-1,j))\r\n d_new(i,j)=(d(i,j)-a(i,j)*d_new(i-1,j))/(b(i,j)-a(i,j)*c_new(i-1,j))\r\n end do\r\n temp1(m-1,j)=d_new(m-1,j)\r\n do i=m-2,2,-1\r\n temp1(i,j)=d_new(i,j)-c_new(i,j)*temp1(i+1,j) ! Saving half-step(k+0.5) values in a temporary variable\r\n end do\r\n end do\r\n !_____ADI for second half-step_______\r\n !____________________________________\r\n do i=2,m-1\r\n do j=3,n-2\r\n a(i,j)=w\r\n b(i,j)=-2-2*w\r\n c(i,j)=w\r\n d(i,j)=-w*temp1(i+1,j)-w*temp1(i-1,j)+(-2+2*w)*temp1(i,j)\r\n end do\r\n\r\n a(i,2)=0\r\n b(i,2)=-2-w\r\n c(i,2)=w\r\n d(i,2)=-w*temp1(i+1,j)-w*temp1(i-1,j)+(-2+2*w)*temp1(i,j)\r\n\r\n a(i,n-1)=w\r\n b(i,n-1)=-2-2*w\r\n c(i,n-1)=0\r\n d(i,n-1)=-w*temp1(i+1,j)-w*temp1(i-1,j)+(-2+2*w)*temp1(i,j)-w*T(i,n)\r\n\r\n end do\r\n\r\n !_____TDMA Solver_____\r\n do i=2,m-1\r\n c_new(i,2)=c(i,2)/b(i,2)\r\n d_new(i,2)=d(i,2)/b(i,2)\r\n do j=3,n-1\r\n c_new(i,j)=c(i,j)/(b(i,j)-a(i,j)*c_new(i,j-1))\r\n d_new(i,j)=(d(i,j)-a(i,j)*d_new(i,j-1))/(b(i,j)-a(i,j)*c_new(i,j-1))\r\n end do\r\n temp2(i,n-1)=d_new(i,n-1)\r\n do j=n-2,2,-1\r\n temp2(i,j)=d_new(i,j)-c_new(i,j)*temp2(i,j+1) ! Saving second half-step(k+1)\r\n end do\r\n end do\r\n\r\n er(:,:)=ABS(temp2(:,:)-T(:,:)) ! This variable is defined to determine the time the solution will reach steady state\r\n e=maxval(er) !Maximum difference\r\n T(:,:)=temp2(:,:)\r\n\r\n if(e<0.0001) exit\r\n k=k+1\r\nend do\r\n call cpu_time(t_fin)\r\n !_____________________________Reporting solution information_____________________________\r\n print*, 'w= ',w\r\n print*, 'Number of iterations to reach steady state: ',k\r\n print*, 'Maximum difference between the last two time steps:',e, 'Celsius'\r\n print*, 'Solution will be Steady at: ',k*dt,'seconds'\r\n print*, 'Calculation time is: ',t_fin-t_st, 'seconds'\r\n\r\n !_____________________________Saving the results_____________________________\r\n\r\n open(10,file='Temp contour.plt')\r\n write(10,*)'VARIABLES = \"X\", \"Y\", \"T\"'\r\n do j=1,n\r\n do i=1,m\r\n write(10,*) x(i),y(j),T(i,j)\r\n end do\r\n end do\r\n\r\n open(20,file='Midline temp at SS.dat')\r\n write(20,*)\"VARIABLES=X,TEMPERATURE\"\r\n do i=1,m\r\n write(20,*) (i-1)*dx,T(i,yG)\r\n end do\r\n\r\n open(30,file='Midline initial temp.dat')\r\n write(30,*)\"VARIABLES=X,TEMPERATURE\"\r\n do i=1,m\r\n write(30,*) (i-1)*dx,T0(i,yG)\r\n end do\r\n\r\n open(40,file='Midline temp at t=2000dt.dat')\r\n write(40,*)\"VARIABLES=X,TEMPERATURE\"\r\n do i=1,m\r\n write(40,*) (i-1)*dx,T1(i,yG)\r\n end do\r\n\r\n open(50,file='Midline temp at t=10000dt.dat')\r\n write(50,*)\"VARIABLES=X,TEMPERATURE\"\r\n do i=1,m\r\n write(50,*) (i-1)*dx,T2(i,yG)\r\n end do\r\n\r\n open(60,file='Midline temp at t=50000dt.dat')\r\n write(60,*)\"VARIABLES=X,TEMPERATURE\"\r\n do i=1,m\r\n write(60,*) (i-1)*dx,T3(i,yG)\r\n end do\r\n\r\n open(70,file='Midline temp at t=100000dt.dat')\r\n write(70,*)\"VARIABLES=X,TEMPERATURE\"\r\n do i=1,m\r\n write(70,*) (i-1)*dx,T4(i,yG)\r\n end do\r\n\r\n open(80,file='Temp at F.dat')\r\n write(80,*)\"VARIABLES=t,TEMPERATURE\"\r\n do time=1,k\r\n write(80,*) (time-1)*dt,TF(1,time)\r\n end do\r\n\r\n open(90,file='Temp at G.dat')\r\n write(90,*)\"VARIABLES=t,TEMPERATURE\"\r\n do time=1,k\r\n write(90,*) (i-1)*dt,TG(1,time)\r\n end do\r\n\r\nend program CFD_FIRST_PROJECT_IMPLICIT\r\n", "meta": {"hexsha": "4fc378ce830fe8609f3a3469a5dae49b36c96fa4", "size": 8703, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Implicit FTSC FDM Parabolic.f95", "max_stars_repo_name": "r2rro/CFD", "max_stars_repo_head_hexsha": "3151751423f68036c32004eea1350ee69ce959ad", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Implicit FTSC FDM Parabolic.f95", "max_issues_repo_name": "r2rro/CFD", "max_issues_repo_head_hexsha": "3151751423f68036c32004eea1350ee69ce959ad", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Implicit FTSC FDM Parabolic.f95", "max_forks_repo_name": "r2rro/CFD", "max_forks_repo_head_hexsha": "3151751423f68036c32004eea1350ee69ce959ad", "max_forks_repo_licenses": ["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.8771186441, "max_line_length": 127, "alphanum_fraction": 0.488222452, "num_tokens": 2715, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425289753969, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6723125600804567}} {"text": "integer :: i\ninteger, dimension (10, 10) :: a = reshape ((/(i * i, i = 1, 100)/), (/10, 10/))\n", "meta": {"hexsha": "ea7d1013288716661095868e70dd28f64a2f8e8d", "size": 94, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Arrays/Fortran/arrays-19.f", "max_stars_repo_name": "mullikine/RosettaCodeData", "max_stars_repo_head_hexsha": "4f0027c6ce83daa36118ee8b67915a13cd23ab67", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Arrays/Fortran/arrays-19.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/Arrays/Fortran/arrays-19.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.3333333333, "max_line_length": 80, "alphanum_fraction": 0.5, "num_tokens": 39, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9196425289753969, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6723125600804567}} {"text": "!***********************************************************************\n!* Butterworth Filter Routines:\n!* BWFILT_S - In-place filter (overwrites input array)\n!* BWFILT_SN - Out-of-place filter (outputs to separate array)\n!*\n!* Language: Fortran\n!*\n!* Author: Stuart G. Mentzer\n!*\n!* Date: 1999/08/20\n!***********************************************************************\n\n\n\n SUBROUTINE BWFILT_S( Y, NFP, NLP, DEL, FCUT )\n\n!***********************************************************************\n!* In-Place Second-Order Butterworth Filter of Time Series\n!*\n!* Function:\n!* Filters data forward and backward with a second order\n!* Butterworth algorithm, giving zero phase shift and -3dB\n!* at the specified cutoff frequency.\n!*\n!* Language: Fortran\n!*\n!* Author: Stuart G. Mentzer\n!*\n!* Date: 1999/08/20\n!***********************************************************************\n\n\n ! Arguments ______________________________________________________\n\n INTEGER NFP ! Index of first data point\n\n INTEGER NLP ! Index of last data point\n\n REAL Y(NFP:NLP) ! Time series data array (send Y(NFP))\n\n REAL DEL ! Time step (delta-t) (sec) of time series data (>0)\n\n REAL FCUT ! Cutoff frequency (Hz) desired\n\n\n ! Perform the in-place filter\n CALL BWFILT_SN( Y, Y, NFP, NLP, DEL, FCUT )\n\n RETURN\n END\n\n\n\n SUBROUTINE BWFILT_SN( Y, YF, NFP, NLP, DEL, FCUT )\n\n!***********************************************************************\n!* Second-Order Butterworth Filter of Time Series Files\n!*\n!* Function:\n!* Filters data forward and backward with a second order Butterworth\n!* algorithm giving zero phase shift and -3dB at the specified cutoff\n!* frequency\n!*\n!* Language: Fortran\n!*\n!* Author: C. Louie - 1978/11\n!* Stuart G. Mentzer\n!*\n!* Date: 1999/08/20\n!***********************************************************************\n\n\n ! Arguments ______________________________________________________\n\n INTEGER NFP ! Index of first data point\n\n INTEGER NLP ! Index of last data point\n\n REAL Y(NFP:NLP) ! Time series data array (send Y(NFP))\n\n REAL YF(NFP:NLP) ! Filtered time series data array (send YF(NFP))\n ! Can be passed the same array as Y to overwrite the input array\n\n REAL DEL ! Time step (delta-t) (sec) of time series data (>0)\n\n REAL FCUT ! Cutoff frequency (Hz) desired\n\n\n ! Variables ______________________________________________________\n\n INTEGER NTP, NTPH, I\n\n REAL FM6DB, PI, WD, WA, B0, B1, B2, A1, A2,\n & X0, X1, X2, Y0, Y1, Y2, YNFP2\n\n\n ! Check positive frequency and time step\n IF ( ( DEL .LE. 0. ) .OR. ( FCUT .LE. 0. ) ) THEN\n WRITE( *, * )\n & '*** BWFILT Error - Nonpositive time step or cutoff'\n RETURN\n END IF\n\n ! Check if the sampling rate can support this cutoff frequency\n !\n ! sampling rate is lower than the cutoff frequency - return true\n ! BwFilt goes unstable as fCut approaches 0.5/del\n !\n IF ( FCUT .GT. ( ( 0.5 / DEL ) * 0.775 ) ) THEN\n WRITE( *, * )\n & '*** BWFILT Error - '//\n & 'Sampling rate is lower than cutoff frequency'\n RETURN\n END IF\n\n ! Set 6dB attenuation frequency\n FM6DB = FCUT * 1.25\n\n ! Compute filter coefficients\n PI = 3.141592654\n WD = 2 * PI * FM6DB\n WA = SIN(WD*DEL/2.) / COS(WD*DEL/2.)\n B0 = WA**2 / (1.+SQRT(2.)*WA+WA**2)\n B1 = 2 * B0\n B2 = B0\n A1 = -2.*(WA**2-1.) / (1.+SQRT(2.)*WA+WA**2)\n A2 = (-1.+SQRT(2.)*WA-WA**2) / (1.+SQRT(2.)*WA+WA**2)\n\n ! Set the number of tail points to use\n NTP = MAX( NINT( .1 / ( FCUT * DEL ) ), 1 )\n NTP = MIN( NTP, NLP - NFP + 1 )\n NTPH = ( NTP / 2 ) + 1\n\n ! Set up pre-start array - Inverted mirror\n YNFP2 = 2 * Y(NFP)\n X1 = YNFP2 - Y(NFP+NTP)\n X0 = YNFP2 - Y(NFP+NTP-1)\n Y1 = 0.\n DO I = -NTP, -NTPH\n Y1 = Y1 + Y(NFP-I)\n END DO\n Y1 = YNFP2 - ( Y1 / ( NTP - NTPH + 1 ) )\n Y0 = Y1\n DO I = -NTP+2, -1\n X2 = X1\n X1 = X0\n X0 = YNFP2 - Y(NFP-I)\n Y2 = Y1\n Y1 = Y0\n Y0 = B0*X0 + B1*X1 + B2*X2 + A1*Y1 + A2*Y2\n END DO\n\n ! Filter forward\n DO I = NFP, NLP\n X2 = X1\n X1 = X0\n X0 = Y(I)\n Y2 = Y1\n Y1 = Y0\n Y0 = B0*X0 + B1*X1 + B2*X2 + A1*Y1 + A2*Y2\n YF(I) = Y0\n END DO\n\n ! Filter backwards\n X1 = 2 * YF(NLP) - YF(NLP-2)\n X0 = 2 * YF(NLP) - YF(NLP-1)\n Y1 = 2 * Y(NLP) - Y(NLP-2)\n Y0 = 2 * Y(NLP) - Y(NLP-1)\n DO I = NLP, NFP, -1\n X2 = X1\n X1 = X0\n X0 = YF(I)\n Y2 = Y1\n Y1 = Y0\n Y0 = B0*X0 + B1*X1 + B2*X2 + A1*Y1 + A2*Y2\n YF(I) = Y0\n END DO\n\n RETURN\n END\n", "meta": {"hexsha": "7838d6f08eca3c2809c86e99d577de4851427b3b", "size": 4795, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/lib/bwfilt_s.for", "max_stars_repo_name": "DeadParrot/NHTSA-Tools", "max_stars_repo_head_hexsha": "e8de2d5aa3d6de96a858ae70ecc4e75fa3d80ac4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2017-03-14T03:50:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-02T21:45:12.000Z", "max_issues_repo_path": "src/lib/bwfilt_s.for", "max_issues_repo_name": "DeadParrot/NHTSA-Tools", "max_issues_repo_head_hexsha": "e8de2d5aa3d6de96a858ae70ecc4e75fa3d80ac4", "max_issues_repo_licenses": ["MIT"], "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/bwfilt_s.for", "max_forks_repo_name": "DeadParrot/NHTSA-Tools", "max_forks_repo_head_hexsha": "e8de2d5aa3d6de96a858ae70ecc4e75fa3d80ac4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-10-31T23:57:05.000Z", "max_forks_repo_forks_event_max_datetime": "2019-10-31T23:57:05.000Z", "avg_line_length": 26.4917127072, "max_line_length": 72, "alphanum_fraction": 0.5013555787, "num_tokens": 1539, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9196425377849807, "lm_q2_score": 0.7310585669110202, "lm_q1q2_score": 0.6723125557435018}} {"text": "module aconite_function_mod\n\n\n\tpublic :: acm, mass_resp, daylength, GDD_calc,area_resp,atkin_resp,ryan_resp, clm_resp\n\ncontains\n\n\n\n!-------PHENOLOGY GROWING DEGREE DAY CALCULATOR\ndouble precision function GDD_calc(tmax,tmin,GDD,doy)\n\tdouble precision, intent(in):: tmax, tmin, GDD\n\tinteger, intent(in):: doy\n\tdouble precision :: tav\n\t\n tav = (tmax + tmin)/2.\n if(doy == 1) then\n GDD_calc = 0\n elseif(tav - 8 > 0) then\n GDD_calc = GDD + tav - 8\n endif\n End Function\n!-------------------------------------------------\n \n \n \n!--------DAY LENGTH CALCULATOR\ndouble precision function daylength(Lat,doy)\n\tdouble precision, parameter :: pi = 3.14159265359\n\tdouble precision, intent(in) :: Lat\n\tinteger, intent(in):: doy\n\tdouble precision :: LatRad, r, z, decl,z2,h,TA,AC\n\t\n LatRad = Lat * (2.0 * pi) / 360.0\n r = 1 - (0.0167 * COS(0.0172 * (doy - 3)))\n z = 0.39785 * sin(4.868961 + 0.017203 * doy + 0.033446 *SIN(6.224111 + 0.017202 * doy))\n if (ABS(z) < 0.7) then\n decl = ATAN(z / (sqrt(1.0 - (z**2))))\n else\n decl = pi / 2.0 - atan(sqrt(1 - z**2) / z)\n endif\n \n if (abs(LatRad) >= (pi/2.0)) then\n if (Lat < 0) then\n LatRad = (-1.0) * (pi/2.0 - 0.01);\n else\n LatRad = (1.0) * (pi/2.0 - 0.01);\n endif\n endif\n \n z2 = -TAN(decl) * TAN(LatRad);\n if (z2 >= 1.0) then\n h = 0;\n elseif (z2 <= -1.0) then\n h = pi;\n else\n TA = abs(z2);\n if (TA < 0.7)then\n AC = 1.570796 - atan(TA / sqrt(1.0 - (TA**2)));\n else\n AC = atan(sqrt(1 - (TA**2)) / TA);\n endif\n if (z2 < 0) then\n h = pi-AC;\n else\n h = AC;\n endif\n endif\n daylength = 2.0 * (h*24.0) / (2.0*pi);\nEnd function\n \n!------- ACM PHOTOSYNTHESIS MODEL\n double precision function acm(N,lai,tmax,tmin,DL,rad,co2,param,psid,rtot,leafgrow_doy,leaf_drop_occured,doy)\n \tdouble precision, intent(in) :: N, lai, tmax,tmin,DL,rad,co2, param(16), psid,rtot, &\n \t\t\t\t\t\t\t\t\tleafgrow_doy,leaf_drop_occured\n \tdouble precision :: tav,gs,pp,trange,qq,ci,e0,cps \n \t\tinteger, intent(in):: doy\n \n tav = (tmax + tmin)/2.\n if(tmin > param(15) .AND. doy >= leafgrow_doy .AND. doy < leaf_drop_occured) then \n trange = tmax - tmin ! daily temperature range (C)\n gs = abs(psid)**param(10) / ((param(6)* rtot + 0.5*trange))\n pp = (N * param(1) * exp(param(8) * tmax))/gs\n qq = param(3) - param(4)\n ci = 0.5 * (co2 + qq - pp + sqrt((co2 + qq - pp)**2 - 4 * (co2 * qq - pp * param(3))))\n e0 = param(7) * lai**2/(lai**2 + param(9))\n cps = (e0* rad * gs * (co2 - ci))/(e0 * rad + gs * (co2-ci))\n acm = cps * (param(2) * DL + param(5))\n else\n acm = 0.\n endif\n \n\n\nend function\n \n!-------NON-LINEAR RESPIRATION MODEL (REICH ET AL. 2008): MASS\n double precision function mass_resp(tissueC,tissueN,resp_parm1,resp_parm2,resp_parm3,twq) \n \tdouble precision, intent(in) :: tissueC,tissueN,resp_parm1,resp_parm2,twq,resp_parm3 \n \tdouble precision :: total_biomass,mmolesN_per_biomass,nmolesC_per_biomass_per_sec, &\n \t\t\t\t\t\tgC_per_biomass_per_sec,gC_per_sec\n \t\t\t\t\t\t\n if(tissueC > 0.0 .AND. tissueN > 0.0) then\n total_biomass = tissueC/0.5\n mmolesN_per_biomass = ((tissueN/14.)*1000)/total_biomass\n \n !nmolesC_per_biomass_per_sec =exp(mass_param1+mass_param2*log(mmolesN_per_biomass))\n nmolesC_per_biomass_per_sec = resp_parm1 + log10(mmolesN_per_biomass)*resp_parm2\n gC_per_biomass_per_sec =((10**nmolesC_per_biomass_per_sec)/10**9)*12.\n gC_per_sec = gC_per_biomass_per_sec * total_biomass\n mass_resp = gC_per_sec * (60.*60.*24.) \n !print *, mmolesN_per_biomass,10**nmolesC_per_biomass_per_sec\n !nmolesC_per_biomass_per_sec = resp_parm1 * (mmolesN_per_biomass ** resp_parm2)\n !gC_per_biomass_per_sec =(nmolesC_per_biomass_per_sec/10**9)*12.\n !gC_per_sec = gC_per_biomass_per_sec * total_biomass\n !mass_resp = gC_per_sec * (60.*60.*24.) \n !print *, mmolesN_per_biomass,nmolesC_per_biomass_per_sec\n else\n mass_resp = 0.0\n endif\nend function\n\n!-------NON-LINEAR RESPIRATION MODEL (REICH ET AL. 2008) :AREA\n double precision function area_resp(LAI,tissueN,resp_parm1,resp_parm2,resp_parm3,twq) \n \tdouble precision, intent(in) :: LAI,tissueN,resp_parm1,resp_parm2,twq,resp_parm3\n \tdouble precision :: total_biomass,N_per_area,gC_per_area_per_sec, &\n \t\t\t\t\t\tgC_per_sec\n \t\t\t\t\t\t\n if(LAI > 0.0 .AND. tissueN > 0.0) then\n N_per_area = (tissueN/LAI)\n umolC_per_area_per_sec = ((resp_parm1-resp_parm3*twq)* (N_per_area ** resp_parm2))\n gC_per_area_per_sec = (umolC_per_area_per_sec/10**6)*12.\n gC_per_sec = gC_per_area_per_sec*LAI\n area_resp = gC_per_sec * (60.*60.*24.)\n else\n area_resp = 0.0\n endif\nend function\n\n!-------AKTIN EQUATION \n double precision function atkin_resp(LAI,tissueN,twq,resp_parm1,resp_parm2,resp_parm3) \n \tdouble precision, intent(in) :: LAI,tissueN,twq,resp_parm1,resp_parm2,resp_parm3\n \tdouble precision :: total_biomass,N_per_area,gC_per_area_per_sec, &\n \t\t\t\t\t\tgC_per_sec\n \t\t\t\t\t\t\n if(tissueC > 0.0 .AND. tissueN > 0.0) then\n N_per_area = (tissueN/LAI)\n umolC_per_area_per_sec = resp_parm1 + (N_per_area * resp_parm2) - resp_parm3*twq \n gC_per_area_per_sec = (umolC_per_area_per_sec/10**6)*12.\n gC_per_sec = gC_per_area_per_sec*LAI\n atkin_resp = gC_per_sec * (60.*60.*24.)\n atkin_resp = max(atkin_resp,0.0)\n else\n atkin_resp = 0.0\n endif\nend function\n\n!-------RYAN EQUATION\n double precision function ryan_resp(tissueN,tissueC,resp_parm1) \n \tdouble precision, intent(in) :: tissueN,tissueC, resp_parm1 \n \tdouble precision :: gC_per_sec,mol_C,mmol_N,mmolN_per_molC,mmol_per_mol_per_hr, &\n \t\tmmol_per_mol_per_second, mmol_per_second\n \t\t\t\t\t\t\n if(tissueC > 0.0 .AND. tissueN > 0.0) then\n mol_C = tissueC / 12.0\n mmol_N = (tissueN/14.0)*1000\n mmolN_per_molC = mmol_N/mol_C\n \n mmol_per_mol_per_hr = resp_parm1 * mmolN_per_molC\n mmol_per_mol_per_second = mmol_per_mol_per_hr/(60.*60.)\n mmol_per_second = mmol_per_mol_per_second*mol_C\n gC_per_sec = (mmol_per_second*12.0)/1000\n ryan_resp = gC_per_sec * (60.*60.*24.)\n else\n ryan_resp = 0.0\n endif\n\nend function\n\n!-------CLM EQUATION\n double precision function clm_resp(tissueN,tissueC,resp_parm1) \n \tdouble precision, intent(in) :: tissueN,tissueC, resp_parm1 \n \tdouble precision :: gC_per_sec,mol_C,mmol_N,mmolN_per_molC,mmol_per_mol_per_hr, &\n \t\tmmol_per_mol_per_second, mmol_per_second\n\n if(tissueC > 0.0 .AND. tissueN > 0.0) then\n gC_per_sec = TissueN * resp_parm1\n clm_resp = gC_per_sec * (60.*60.*24.)\n else\n clm_resp = 0.0\n endif\n \nend function\n\n\n\n\nend module\n\n\n\n\n", "meta": {"hexsha": "6beaee721bd54523c401dd25243a19268c57da60", "size": 6794, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/aconite_function_mod.f90", "max_stars_repo_name": "EcoDynForecast/ACONITE_canopy", "max_stars_repo_head_hexsha": "51e98aa2be7b1043b3a921edebcb2d909cbde239", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-02-22T02:44:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-22T02:44:41.000Z", "max_issues_repo_path": "src/aconite_function_mod.f90", "max_issues_repo_name": "rqthomas/ACONITE_canopy", "max_issues_repo_head_hexsha": "51e98aa2be7b1043b3a921edebcb2d909cbde239", "max_issues_repo_licenses": ["MIT"], "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/aconite_function_mod.f90", "max_forks_repo_name": "rqthomas/ACONITE_canopy", "max_forks_repo_head_hexsha": "51e98aa2be7b1043b3a921edebcb2d909cbde239", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-06T19:56:18.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-06T19:56:18.000Z", "avg_line_length": 33.4679802956, "max_line_length": 110, "alphanum_fraction": 0.6339417133, "num_tokens": 2461, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425267730008, "lm_q2_score": 0.7310585727705126, "lm_q1q2_score": 0.6723125530817379}} {"text": "geqrhs(0) = (-(2*vel(2)*vel(3)*(pot(2)*dpot(5,2)-dpot(2,2)*pot(5)&\n&))/(2*pot(1)*pot(5)+2*pot(2)**2))-(2*vel(1)*vel(3)*(pot(2)*dpot(5&\n&,1)-dpot(2,1)*pot(5)))/(2*pot(1)*pot(5)+2*pot(2)**2)-(2*vel(0)*ve&\n&l(2)*(dpot(1,2)*pot(5)+pot(2)*dpot(2,2)))/(2*pot(1)*pot(5)+2*pot(&\n&2)**2)-(2*vel(0)*vel(1)*(dpot(1,1)*pot(5)+pot(2)*dpot(2,1)))/(2*p&\n&ot(1)*pot(5)+2*pot(2)**2)\n \ngeqrhs(1) = ((vel(3)**2*dpot(5,1))/pot(3))/2.d+0+((vel(2)**2*dpot&\n&(4,1))/pot(3))/2.d+0-(vel(1)*vel(2)*dpot(3,2))/pot(3)-((vel(1)**2&\n&*dpot(3,1))/pot(3))/2.d+0+(vel(0)*dpot(2,1)*vel(3))/pot(3)-((vel(&\n&0)**2*dpot(1,1))/pot(3))/2.d+0\n \ngeqrhs(2) = ((vel(3)**2*dpot(5,2))/pot(4))/2.d+0-((vel(2)**2*dpot&\n&(4,2))/pot(4))/2.d+0-(vel(1)*vel(2)*dpot(4,1))/pot(4)+((vel(1)**2&\n&*dpot(3,2))/pot(4))/2.d+0+(vel(0)*dpot(2,2)*vel(3))/pot(4)-((vel(&\n&0)**2*dpot(1,2))/pot(4))/2.d+0\n \ngeqrhs(3) = (-(2*vel(2)*vel(3)*(pot(1)*dpot(5,2)+pot(2)*dpot(2,2)&\n&))/(2*pot(1)*pot(5)+2*pot(2)**2))-(2*vel(1)*vel(3)*(pot(1)*dpot(5&\n&,1)+pot(2)*dpot(2,1)))/(2*pot(1)*pot(5)+2*pot(2)**2)-(2*vel(0)*ve&\n&l(2)*(pot(1)*dpot(2,2)-dpot(1,2)*pot(2)))/(2*pot(1)*pot(5)+2*pot(&\n&2)**2)-(2*vel(0)*vel(1)*(pot(1)*dpot(2,1)-dpot(1,1)*pot(2)))/(2*p&\n&ot(1)*pot(5)+2*pot(2)**2)\n \n", "meta": {"hexsha": "d4dc9ae1daaac3ff25bf4e8b54da53f798c7c19c", "size": 1210, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "symbolic/sphax-geq.f90", "max_stars_repo_name": "gandreoliva/ujti", "max_stars_repo_head_hexsha": "269c4a36fa0939acddae698b351e20590c5715db", "max_stars_repo_licenses": ["FSFAP"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "symbolic/sphax-geq.f90", "max_issues_repo_name": "gandreoliva/ujti", "max_issues_repo_head_hexsha": "269c4a36fa0939acddae698b351e20590c5715db", "max_issues_repo_licenses": ["FSFAP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "symbolic/sphax-geq.f90", "max_forks_repo_name": "gandreoliva/ujti", "max_forks_repo_head_hexsha": "269c4a36fa0939acddae698b351e20590c5715db", "max_forks_repo_licenses": ["FSFAP"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.4, "max_line_length": 67, "alphanum_fraction": 0.4925619835, "num_tokens": 734, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741254760638, "lm_q2_score": 0.7057850216484838, "lm_q1q2_score": 0.6723125497709092}} {"text": " SUBROUTINE SFFTFU( X, Y, N, M, ITYPE )\nc\nc Decimation-in-time radix-2 split-radix complex FFT\nc\nc Arguments:\nc X - real part of data sequence (in/out)\nc Y - imag part of data sequence (in/out)\nc N,M - integers such that N = 2**M (in)\nc ITYPE - integer transform type (in)\nc ITYPE .ne. -1 --> forward transform\nc ITYPE .eq. -1 --> backward transform\nc\nc The forward transform computes\nc X(k) = sum_{j=0}^{N-1} x(j)*exp(-2ijk*pi/N)\nc\nc The backward transform computes\nc x(j) = (1/N) * sum_{k=0}^{N-1} X(k)*exp(2ijk*pi/N)\nc\nc\nc Here is the original program header...\nc\nC-------------------------------------------------------------C\nC A Duhamel-Hollman Split-Radix DIT FFT C\nC Reference: Electronics Letters, January 5, 1984 C\nC Complex input and output in data arrays X and Y C\nC Length is N = 2**M C\nC C\nC H.V. Sorensen Rice University Dec 1984 C\nC-------------------------------------------------------------C\nc\nc ... Scalar arguments ...\n INTEGER N, M, ITYPE\nc ... Array arguments ...\n REAL X(*), Y(*)\nc ... Local scalars ...\n INTEGER I, J, K, N1, N2, N4, IS, ID, I0, I1, I2, I3\n REAL TWOPI, A, A3, E, XT, R1, R2, R3, S1, S2\n REAL CC1, CC3, SS1, SS3\nc ... Parameters ...\n PARAMETER ( TWOPI = 6.283185307179586476925287 )\nc ... Intrinsic functions ...\n INTRINSIC SIN, COS\nc\nc ... Exe. statements ...\nc\nc ... Quick return ...\n IF ( N .EQ. 1 ) RETURN\nc\nc ... Conjugate if necessary ...\n IF ( ITYPE .EQ. -1 ) THEN\n DO 1, I = 1, N\n Y(I) = - Y(I)\n 1 CONTINUE\n ENDIF\nc\nc ... Bit reversal permutation ...\n 100 J = 1\n N1 = N - 1\n DO 104, I = 1, N1\n\t IF ( I .GE. J ) GOTO 101\n\t XT = X(J)\n\t X(J) = X(I)\n\t X(I) = XT\n\t XT = Y(J)\n\t Y(J) = Y(I)\n\t Y(I) = XT\n 101 K = N / 2\n 102 IF ( K .GE. J ) GOTO 103\n\t J = J - K\n\t K = K / 2\n\t GOTO 102\n 103 J = J + K\n 104 CONTINUE\nc\nc ... Length two transforms ...\n IS = 1\n ID = 4\n 70 DO 60, I0 = IS, N, ID\n\t I1 = I0 + 1\n\t R1 = X(I0)\n\t X(I0) = R1 + X(I1)\n\t X(I1) = R1 - X(I1)\n\t R1 = Y(I0)\n\t Y(I0) = R1 + Y(I1)\n\t Y(I1) = R1 - Y(I1)\n 60 CONTINUE\n IS = 2 * ID - 1\n ID = 4 * ID\n IF ( IS .LT. N ) GOTO 70\nc\nc ... L shaped butterflies ...\n N2 = 2\n DO 10, K = 2, M\n\t N2 = N2 * 2\n\t N4 = N2 / 4\n\t E = TWOPI / N2\n\t A = 0.0\n\t DO 20, J = 1, N4\n\t A3 = 3 * A\n\t CC1 = COS( A )\n\t SS1 = SIN( A )\n\t CC3 = COS( A3 )\n\t SS3 = SIN( A3 )\n\t A = J * E\n\t IS = J\n\t ID = 2 * N2\n 40 DO 30, I0 = IS, N-1, ID\n\t I1 = I0 + N4\n\t I2 = I1 + N4\n\t I3 = I2 + N4\n\t R1 = X(I2) * CC1 + Y(I2) * SS1\n\t S1 = Y(I2) * CC1 - X(I2) * SS1\n\t R2 = X(I3) * CC3 + Y(I3) * SS3\n\t S2 = Y(I3) * CC3 - X(I3) * SS3\n\t R3 = R1 + R2\n\t R2 = R1 - R2\n\t R1 = S1 + S2\n\t S2 = S1 - S2\n\t X(I2) = X(I0) - R3\n\t X(I0) = X(I0) + R3\n\t X(I3) = X(I1) - S2\n\t X(I1) = X(I1) + S2\n\t Y(I2) = Y(I0) - R1\n\t Y(I0) = Y(I0) + R1\n\t Y(I3) = Y(I1) + R2\n\t Y(I1) = Y(I1) - R2\n 30 CONTINUE\n\t IS = 2 * ID - N2 + J\n\t ID = 4 * ID\n\t IF ( IS .LT. N ) GOTO 40\n 20 CONTINUE\n 10 CONTINUE\nc\nc ... Conjugate and normalize if necessary ...\n IF ( ITYPE .EQ. -1 ) THEN\n DO 2, I = 1, N\n\t Y(I) = - Y(I) / N\n\t X(I) = X(I) / N\n 2 CONTINUE\n ENDIF\nc\n RETURN\nc\nc ... End of subroutine SFFTFU ...\nc\n END\n", "meta": {"hexsha": "69152c52bb51e547e7476457fd39b66c0849d12a", "size": 3584, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "benchees/sorensen/sfftfu.f", "max_stars_repo_name": "mreineck/benchfft", "max_stars_repo_head_hexsha": "6c754dca9f53f16886a71744199a0bbce40b3e1a", "max_stars_repo_licenses": ["ImageMagick"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2019-08-11T02:13:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T01:31:41.000Z", "max_issues_repo_path": "benchees/sorensen/sfftfu.f", "max_issues_repo_name": "mreineck/benchfft", "max_issues_repo_head_hexsha": "6c754dca9f53f16886a71744199a0bbce40b3e1a", "max_issues_repo_licenses": ["ImageMagick"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2020-12-01T18:15:43.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-21T21:39:55.000Z", "max_forks_repo_path": "benchees/sorensen/sfftfu.f", "max_forks_repo_name": "mreineck/benchfft", "max_forks_repo_head_hexsha": "6c754dca9f53f16886a71744199a0bbce40b3e1a", "max_forks_repo_licenses": ["ImageMagick"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2020-06-02T08:44:13.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-26T11:50:36.000Z", "avg_line_length": 24.380952381, "max_line_length": 63, "alphanum_fraction": 0.4369419643, "num_tokens": 1427, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505453836383, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6723073494489215}} {"text": "c\nc ==========================================\n subroutine mapc2m(x1,y1,xp,yp,zp)\nc ==========================================\nc\nc Map computational point (x1,y1) to the point (xp,yp,zp)\nc on the sphere\nc\nc Points in [-1,1]x[-1,1] are mapped to the upper hemisphere\nc Points in [-3,-1]x[-1,1] are mapped to the lower hemisphere\nc\n implicit real*8(a-h,o-z)\n\n r1 = 1.d0\n xc = x1\n yc = y1\n\nc # ghost cell values outside of [-3,1]x[-1,1] get mapped to other\nc # hemisphere:\n if (xc.ge.1.d0) xc = xc-4.d0\n if (xc.lt.-3.d0) xc = xc+4.d0\n\n if (yc.ge.1.d0) then\n yc = 2.d0 - yc\n xc = -2.d0 - xc\n endif\n if (yc.lt.-1.d0) then\n yc = -2.d0 - yc\n xc = -2.d0 - xc\n endif\n\n if (xc.lt.-1.d0) then\nc # points in [-3,-1] map to lower hemisphere - reflect about x=-1\nc # to compute x,y mapping and set sgnz appropriately:\n xc = -2.d0 - xc\n sgnz = -1.d0\n else\n sgnz = 1.d0\n endif\n sgnxc = dsign(1.d0,xc)\n sgnyc = dsign(1.d0,yc)\n\n xc1 = dabs(xc)\n yc1 = dabs(yc)\n d = dmax1(dmax1(xc1,yc1), 1.d-10)\n\n DD = r1*d*(2.d0 - d) / dsqrt(2.d0)\n R = r1\n\n center = DD - dsqrt(dmax1(R**2 - DD**2, 0.d0))\n xp = DD/d * xc1\n yp = DD/d * yc1\n\n if (yc1 .gt. xc1) then\n yp = center + dsqrt(dmax1(R**2 - xp**2, 0.d0))\n else\n xp = center + dsqrt(dmax1(R**2 - yp**2, 0.d0))\n endif\n\n zp = dsqrt(dmax1(r1**2 - (xp**2 + yp**2), 0.d0))\n xp = xp*sgnxc\n yp = yp*sgnyc\n zp = zp*sgnz\nc\n return\n end\n\n", "meta": {"hexsha": "e805b6b30f6c5d4be17238dbce91fa361580d8fb", "size": 1657, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "apps/advection/2d/sphere/rotation/mapc2m.f", "max_stars_repo_name": "geoflows/geoclaw-4.x", "max_stars_repo_head_hexsha": "c8879d25405017b38392aa3b1ea422ff3e3604ea", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2016-11-13T03:11:51.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-07T18:59:48.000Z", "max_issues_repo_path": "apps/advection/2d/sphere/rotation/mapc2m.f", "max_issues_repo_name": "che-wenchao/D-Claw", "max_issues_repo_head_hexsha": "8ab5d971c9a7a7130e03a447a4b8642e292f4e88", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2020-01-14T18:00:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T14:25:24.000Z", "max_forks_repo_path": "apps/advection/2d/sphere/rotation/mapc2m.f", "max_forks_repo_name": "che-wenchao/D-Claw", "max_forks_repo_head_hexsha": "8ab5d971c9a7a7130e03a447a4b8642e292f4e88", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-01-14T17:15:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-03T17:28:44.000Z", "avg_line_length": 24.3676470588, "max_line_length": 74, "alphanum_fraction": 0.4532287266, "num_tokens": 620, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.904650527388829, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6723073360757548}} {"text": " MODULE HYD_COL_RATE\n\n IMPLICIT NONE\n\n PRIVATE\n\n PUBLIC :: HYDCOLRATE\n\n CONTAINS\n\n FUNCTION HYDCOLRATE(nl, nu, T) RESULT(ColRate)\n\n USE MATH\n USE PHYS\n\n! e - H collisional rates according to L. C. Johnson, \"Approximations For Collisional\n! And Radiative Transition Rates In Atomic Hydrogen\", 1972, ApJ, 174, 227\n\n! The procedure works for ionization rates as well, in this case nu is equal to 11 and is not the principal quantum number\n\n INTEGER, INTENT(IN) :: nl, nu ! Principal numbers of upper and lower levels\n\n REAL*8, INTENT(IN) :: T ! Temperature\n\n REAL*8 :: ColRate ! Resulting collision rate (in cgs units)\n\n REAL*8 :: rnlnu\n\n REAL*8, DIMENSION(3) :: g\n\n REAL*8 :: gf\n\n REAL*8 :: Anlnu, Bnlnu\n\n REAL*8 :: Anl, Bnl\n\n REAL*8 :: C1, C2, C3, C4 ! Constant factors in the corresponding formulas\n\n REAL*8 :: B1, B2, B3 ! Bracket factors in the corresponding formulas\n\n REAL*8 :: x, y, z\n\n REAL*8 :: ynl, znl\n\n C1 = DSQRT(8.0D0 * boltz * T / pai / elec_mass)\n\n C4 = 32.0D0 / 3.0D0 / DSQRT(3.0D0) / pai\n\n g(1 : 3) = gfc(nl)\n\n IF (nu .NE. 11) THEN ! nl -> nu excitation collisional coefficient\n\n x = 1.0D0 - (ISQ(nl) / ISQ(nu))\n\n y = x * DABS(HYD_LEV_ENERGY(nl)) / boltz / T\n\n rnlnu = r(nl) * x\n\n z = rnlnu + y\n\n C2 = 2.0D0 * ISQ(nl) / x\n\n C3 = pai * DSQ(bohr_rad * y)\n\n B1 = (1.0D0 / y + 0.5D0) * EXPINT(1, y) - (1.0D0 / z + 0.5D0) * EXPINT(1, z)\n\n gf = g(1) + g(2) / x + g(3) / DSQ(x)\n\n Anlnu = C2 * C4 * nl * gf / DCUBE(nu * x)\n\n Bnlnu = (DSQ(C2) / ICUBE(nu)) * (1.0D0 + 4.0D0 / 3.0D0 / x + b(nl) / DSQ(x))\n\n B2 = Bnlnu - Anlnu * DLOG(C2)\n\n B3 = EXPINT(2, y) / y - EXPINT(2, z) / z\n\n ColRate = C1 * C2 * C3 * (Anlnu * B1 + B2 * B3)! * DEXP(y) / DSQRT(T)\n\n ELSE ! Ionization collisional coefficient\n\n ynl = DABS(HYD_LEV_ENERGY(nl)) / boltz / T\n\n znl = r(nl) + ynl\n\n C2 = 2.0D0 * pai * DSQ(nl * bohr_rad * ynl)\n\n B1 = EXPINT(1, ynl) / ynl - EXPINT(1, znl) / znl\n\n Bnl = 2.0D0 * ISQ(nl) * (5.0D0 + b(nl)) / 3.0D0\n\n Anl = C4 * nl * (g(1) / 3.0D0 + g(2) / 4.0D0 + g(3) / 5.0D0)\n\n B2 = Bnl - Anl * DLOG(2.0D0 * ISQ(nl))\n\n B3 = ksi(ynl) - ksi(znl)\n\n ColRate = C1 * C2 * (Anl * B1 + B2 * B3)! * DEXP(ynl) / DSQRT(T)\n\n ENDIF\n\n RETURN\n\n END FUNCTION HYDCOLRATE\n\n \n REAL*8 FUNCTION r(n)\n\n INTEGER, INTENT(IN) :: n\n\n IF (n .EQ. 1) THEN; r = 0.45D0; ELSE; r = 1.94D0 * DBLE(n)**(-1.57D0); ENDIF\n\n RETURN\n\n END FUNCTION r\n\n\n FUNCTION gfc(n) RESULT(g)\n\n INTEGER, INTENT(IN) :: n\n\n REAL*8, DIMENSION(3) :: g\n\n IF (n .EQ. 1) THEN\n\n g = (/1.1330D0, -0.4059D0, 0.07014D0/)\n\n ELSEIF (n .EQ. 2) THEN\n\n g = (/1.0785D0, -0.2319D0, 0.02947D0/)\n\n ELSE\n\n g(1) = 0.9935D0 + 0.2328D0 / n - 0.1296D0 / n / n\n\n g(2) = (-0.6282D0 + 0.5598D0 / n - 0.5299D0 / n / n) / n\n\n g(3) = (0.3887D0 - 1.181D0 / n + 1.470D0 / n / n) / n / n\n\n ENDIF\n\n RETURN\n\n END FUNCTION gfc\n\n\n REAL*8 FUNCTION b(n)\n\n INTEGER, INTENT(IN) :: n\n\n IF (n .EQ. 1) THEN\n\n b = -0.603D0\n\n ELSE\n\n b = (4.0D0 - 18.63D0 / n + 36.24D0 / n / n - 28.09D0 / n / n / n) / n\n\n ENDIF\n\n RETURN\n\n END FUNCTION b\n\n\n REAL*8 FUNCTION ksi(t)\n\n USE MATH\n\n REAL*8, INTENT(IN) :: t\n\n ksi = EXPINT(0, t) - 2.0D0 * EXPINT(1, t) + EXPINT(2, t)\n\n RETURN\n\n END FUNCTION ksi\n\n END MODULE HYD_COL_RATE\n", "meta": {"hexsha": "bf309533a641ac785ec292ea893cca2b167720c8", "size": 3639, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/hydcolrate.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/hydcolrate.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/hydcolrate.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": 20.4438202247, "max_line_length": 126, "alphanum_fraction": 0.5009618027, "num_tokens": 1483, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505248181417, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6723073341653022}} {"text": "module pde\n\n ! This module contains the kinetic equation PDE, aka the Boltzmann equation,\n ! or whatever other equation (Vlasov / BGK / ...) according to the collision\n ! operator that we employ.\n ! Hyper2D is still two-dimensional, meaning that the kinetic equation will \n ! be 1D1V: 1D in space and 1V in the velocity. \n ! Dimension \"x\" refers to the space coordinate, while dimension \"y\" is a \n ! velocity \"v\".\n \n use global_module\n\n implicit none\n\n real(kind=8), parameter :: M = 6.6337d-26 ! [kg] particle mass\n real(kind=8), parameter :: q = 1.602176d-19 ! [C] particle charge\n\n real(kind=8), parameter :: kB = 1.3806503d-23 ! [J/K] Boltzmann constant\n real(kind=8), parameter :: PI = 3.1415926535 \n \n integer, parameter :: Neq = 1 ! Number of equations: (x, v, f)\n\n ! Name of primitive variables, used ONLY for exporting the solution to VTK file\n ! NOTE: To initialize it here, all entries need to have the same length!!!\n ! I'm using three letters for simplicity.\n character(len=20), dimension(Neq) :: prim_names = (/'f'/)\n\n contains\n\n ! ============================================================\n\n subroutine initialize_solution(U)\n \n implicit none\n\n real(kind=8), dimension(:,:,:), intent(inout) :: U\n\n integer :: i, j\n real(kind=8) :: x, v\n\n ! Initialize all cells with a single-velocity (1V) Maxwellian VDF\n do j = 1, Ny\n\n v = compute_v_from_j(j)\n\n do i = 1, Nx\n\n ! x = x_min + dx/2.0 + real(i-1)*dx\n\n U(1,i,j) = n0*sqrt(M/(2.0*PI*kB*T0))*exp(-M/(2.0*kB*T0)*(v - u0)*(v - u0))\n\n end do\n\n end do\n\n end subroutine \n\n ! ============================================================\n\n function compute_x_from_i(i)\n\n implicit none\n\n integer, intent(in) :: i\n real(kind=8) :: compute_x_from_i\n\n compute_x_from_i = x_min + dx/2.0 + real(i-1)*dx\n\n end function \n\n ! ============================================================\n\n function compute_v_from_j(j)\n\n implicit none\n\n integer, intent(in) :: j\n real(kind=8) :: compute_v_from_j\n\n compute_v_from_j = y_min + dy/2.0 + real(j-1)*dy\n\n end function \n\n ! ============================================================\n\n subroutine assign_BCs(U)\n \n implicit none\n\n real(kind=8), dimension(:,:,:), intent(inout) :: U\n\n integer :: i, j\n\n ! Periodic BCs \n if (X_PERIODIC_BOOL) then\n U(:,1,:) = U(:,Nx-3,:)\n U(:,2,:) = U(:,Nx-2,:)\n U(:,Nx-1,:) = U(:,3,:)\n U(:,Nx,:) = U(:,4,:)\n end if\n\n end subroutine \n\n ! =========================================================================\n\n function E_field(x)\n\n implicit none\n\n real(kind=8), intent(in) :: x\n real(kind=8) :: E_field\n\n real(kind=8) :: k\n\n ! Cosinusoidal electric field profile\n k = 2.0*PI*4.0/(x_max-x_min)\n E_field = 10.0*k*cos(k*x)\n\n end function\n\n!! ! ==========================================================================\n!! \n!! subroutine compute_moments(U, i, n, u_ave, T)\n!! \n!! implicit none\n!! \n!! real(kind=8), dimension(Neq,Nx,Ny), intent(in) :: U\n!! integer, intent(in) :: i\n!! real(kind=8), intent(out) :: n, u_ave, T\n!! \n!! integer :: j\n!! \n!! real(kind=8) :: n_u, rhoE, v\n!! \n!! ! For every position along x, integrate in velocity\n!! n = 0.0\n!! n_u = 0.0\n!! u_ave = 0.0\n!! T = 0.0\n!! rhoE = 0.0\n!! \n!! do j = 1, Ny\n!! \n!! v = compute_v_from_j(j)\n!! \n!! n = n + U(1,i,j)*dy\n!! n_u = n_u + v*U(1,i,j)*dy\n!! rhoE = rhoE + M*v*v/2.0*U(1,i,j)*dy\n!! \n!! end do\n!! \n!! u_ave = n_u/n ! Average velocity\n!! T = (rhoE - n*M*u_ave*u_ave/2.0)*2.0/(n*kB)\n!! \n!! end subroutine\n\nend module\n", "meta": {"hexsha": "e423c7b561ce883cb526a2c0217e6784cea6068d", "size": 3748, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "hyper2D_single_core/hyper2D_kinetic/src/pde.f03", "max_stars_repo_name": "sbocce/hyper2D", "max_stars_repo_head_hexsha": "7d1510ac3947b2c154aa0c09945ff05db4bfc8c4", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2022-02-17T14:26:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T01:56:37.000Z", "max_issues_repo_path": "hyper2D_single_core/hyper2D_kinetic/src/pde.f03", "max_issues_repo_name": "sbocce/hyper2D", "max_issues_repo_head_hexsha": "7d1510ac3947b2c154aa0c09945ff05db4bfc8c4", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2022-02-28T10:22:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-01T06:25:03.000Z", "max_forks_repo_path": "hyper2D_single_core/hyper2D_kinetic/src/pde.f03", "max_forks_repo_name": "sbocce/hyper2D", "max_forks_repo_head_hexsha": "7d1510ac3947b2c154aa0c09945ff05db4bfc8c4", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.7215189873, "max_line_length": 82, "alphanum_fraction": 0.4989327641, "num_tokens": 1165, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505376715775, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6723073334256287}} {"text": "c****************************************************************\n\n subroutine enubasis(r_lat,r_lon,r_enumat)\n\nc****************************************************************\nc**\nc** FILE NAME: enubasis.f\nc**\nc** DATE WRITTEN: 7/22/93\nc**\nc** PROGRAMMER:Scott Hensley\nc**\nc** FUNCTIONAL DESCRIPTION:Takes a lat and lon and returns a \nc** change of basis matrix from ENU to geocentric coordinates. \nc**\nc** ROUTINES CALLED:none\nc** \nc** NOTES: none\nc**\nc** UPDATE LOG:\nc****************************************************************\n\n implicit none\n\nc INPUT VARIABLES:\n real*8 r_lat !latitude (deg)\n real*8 r_lon !longitude (deg)\n \nc OUTPUT VARIABLES:\n real*8 r_enumat(3,3)\n\nc LOCAL VARIABLES:\n real*8 r_slt,r_clt,r_clo,r_slo\n\nc DATA STATEMENTS:\n\nC FUNCTION STATEMENTS:\n\nc PROCESSING STEPS:\n\n r_clt = cos(r_lat)\n r_slt = sin(r_lat)\n r_clo = cos(r_lon)\n r_slo = sin(r_lon)\n\nc North vector\n\n r_enumat(1,2) = -r_slt*r_clo \n r_enumat(2,2) = -r_slt*r_slo\n r_enumat(3,2) = r_clt\n \nc East vector\n\n r_enumat(1,1) = -r_slo \n r_enumat(2,1) = r_clo\n r_enumat(3,1) = 0.d0\n\nc Up vector \n \n r_enumat(1,3) = r_clt*r_clo \n r_enumat(2,3) = r_clt*r_slo\n r_enumat(3,3) = r_slt\n\n end \n \n", "meta": {"hexsha": "9e6cd9072d268e20004349c38cd7f618503aa29c", "size": 1463, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "contrib/alos2proc_f/src/enubasis.f", "max_stars_repo_name": "vincentschut/isce2", "max_stars_repo_head_hexsha": "1557a05b7b6a3e65abcfc32f89c982ccc9b65e3c", "max_stars_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_stars_count": 1133, "max_stars_repo_stars_event_min_datetime": "2022-01-07T21:24:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-07T21:33:08.000Z", "max_issues_repo_path": "contrib/alos2proc_f/src/enubasis.f", "max_issues_repo_name": "vincentschut/isce2", "max_issues_repo_head_hexsha": "1557a05b7b6a3e65abcfc32f89c982ccc9b65e3c", "max_issues_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_issues_count": 276, "max_issues_repo_issues_event_min_datetime": "2019-02-10T07:18:28.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:45:55.000Z", "max_forks_repo_path": "contrib/alos2proc_f/src/enubasis.f", "max_forks_repo_name": "vincentschut/isce2", "max_forks_repo_head_hexsha": "1557a05b7b6a3e65abcfc32f89c982ccc9b65e3c", "max_forks_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_forks_count": 235, "max_forks_repo_forks_event_min_datetime": "2019-02-10T05:00:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T07:37:24.000Z", "avg_line_length": 22.1666666667, "max_line_length": 68, "alphanum_fraction": 0.4593301435, "num_tokens": 420, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008906, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6723073315151763}} {"text": " include'intde2.f'\r\n\t program main\r\n\t integer alp \r\n\t integer lenaw\r\n\t double precision tiny,aw\r\n\t parameter (lenew=8000)\r\n\t parameter(tiny=1.d-307)\r\n\t dimension aw(0:lenaw-1)\r\n\t common/bl1/aw\r\n\t common /bl2/alp\r\n\t external h\r\n!---------------------------------------------------------------\r\n open(1,file=\"data.dat\", status=\"unknown\")\t \r\n\t call intdeini(lenaw,tiny,1.d-15,aw)\r\n\t do 2 alp = 1,100\r\n\t call intde(h,0.d0,1.d0,aw,s,err)\r\n\t if(err.lt.0.d0)then\r\n\t write(*,*) 'err=', err\r\n\t\t\t pause\r\n\t endif\r\n\t write(*,*) 'tich phan=', s*alp**2 \r\n\t write(1,*) s*alp**2\r\n 2\t enddo\r\n\t stop\r\n\t end\r\n!----------------------------------------------------------------\r\n function h(rr)\r\n\t double precision h\r\n\t double precision rr \r\n\t double precision rho,phi,z \r\n\t double precision aw\r\n\t double precision s,err,pi \r\n\t common/bl/rho,phi,z \r\n\t common/bl1/ aw\r\n\t external g\r\n\t pi = 3.14d0\r\n\t rho = rr \r\n\t call intde(g,pi,2.d0*pi,aw,s,err)\r\n\t if(err.lt.0.d0)then\r\n\t write(*,*) 'err=', err\r\n\t\t\t pause\r\n\t endif\r\n\t h = s \r\n return\r\n end\r\n!----------------------------------------------------------------\r\n function g(pp)\r\n\t double precision g\r\n\t double precision rr \r\n\t double precision rho,phi,z \r\n\t double precision aw\r\n\t double precision s,err\r\n\t common/bl/rho,phi,z \r\n\t common/bl1/aw\r\n\t external f \r\n\t phi = pp \r\n\t call intde(f,0.d0,1.d0,aw,s,err)\r\n\t if(err.lt.0.d0)then \r\n\t write(*,*) 'err=', err\r\n\t\t\t pause\r\n\t endif\r\n\t g = s \r\n return\r\n end\r\n!----------------------------------------------------------------\r\n function f(zz)\r\n\t double precision f \r\n\t double precision zz \r\n\t double precision rho,phi,z \r\n\t common/bl/rho,phi,z \r\n\t z = zz \r\n\t f = func(rho,phi,z)\r\n return\r\n end\r\n!----------------------------------------------------------------\r\n function func(rho,phi,z)\r\n\t double precision rho,phi,z \r\n\t double precision func\r\n\t integer alp\r\n\t common /bl2/alp\r\n\t func = rho**2*phi*DSQRT(z) \r\n return\r\n end\r\n!----------------------------------------------------------------\r\n \t ", "meta": {"hexsha": "167a46a3bf4f567b48cce19e9cc9b1d113092b80", "size": 2205, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Raw-Src/intde2.f", "max_stars_repo_name": "tqbdev/Calculate-Integration-in-Fortran", "max_stars_repo_head_hexsha": "7bce95598a4cbd719e9f66c58622a3a24cfaa126", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Raw-Src/intde2.f", "max_issues_repo_name": "tqbdev/Calculate-Integration-in-Fortran", "max_issues_repo_head_hexsha": "7bce95598a4cbd719e9f66c58622a3a24cfaa126", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Raw-Src/intde2.f", "max_forks_repo_name": "tqbdev/Calculate-Integration-in-Fortran", "max_forks_repo_head_hexsha": "7bce95598a4cbd719e9f66c58622a3a24cfaa126", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.9411764706, "max_line_length": 66, "alphanum_fraction": 0.4362811791, "num_tokens": 581, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625031628428, "lm_q2_score": 0.7217432182679957, "lm_q1q2_score": 0.6722767447287133}} {"text": "C\nC file hwscrt.f\nC\n SUBROUTINE HWSCRT (A,B,M,MBDCND,BDA,BDB,C,D,N,NBDCND,BDC,BDD,\n 1 ELMBDA,F,IDIMF,PERTRB,IERROR,W)\nC\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC * *\nC * copyright (c) 1999 by UCAR *\nC * *\nC * UNIVERSITY CORPORATION for ATMOSPHERIC RESEARCH *\nC * *\nC * all rights reserved *\nC * *\nC * FISHPACK version 4.1 *\nC * *\nC * A PACKAGE OF FORTRAN SUBPROGRAMS FOR THE SOLUTION OF *\nC * *\nC * SEPARABLE ELLIPTIC PARTIAL DIFFERENTIAL EQUATIONS *\nC * *\nC * BY *\nC * *\nC * JOHN ADAMS, PAUL SWARZTRAUBER AND ROLAND SWEET *\nC * *\nC * OF *\nC * *\nC * THE NATIONAL CENTER FOR ATMOSPHERIC RESEARCH *\nC * *\nC * BOULDER, COLORADO (80307) U.S.A. *\nC * *\nC * WHICH IS SPONSORED BY *\nC * *\nC * THE NATIONAL SCIENCE FOUNDATION *\nC * *\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC\nC\nC\nC DIMENSION OF BDA(N), BDB(N), BDC(M),BDD(M),\nC ARGUMENTS F(IDIMF,N), W(SEE ARGUMENT LIST)\nC\nC LATEST REVISION NOVEMBER 1988\nC\nC PURPOSE SOLVES THE STANDARD FIVE-POINT FINITE\nC DIFFERENCE APPROXIMATION TO THE HELMHOLTZ\nC EQUATION IN CARTESIAN COORDINATES. THIS\nC EQUATION IS\nC\nC (D/DX)(DU/DX) + (D/DY)(DU/DY)\nC + LAMBDA*U = F(X,Y).\nC\nC USAGE CALL HWSCRT (A,B,M,MBDCND,BDA,BDB,C,D,N,\nC NBDCND,BDC,BDD,ELMBDA,F,IDIMF,\nC PERTRB,IERROR,W)\nC\nC ARGUMENTS\nC ON INPUT A,B\nC\nC THE RANGE OF X, I.E., A .LE. X .LE. B.\nC A MUST BE LESS THAN B.\nC\nC M\nC THE NUMBER OF PANELS INTO WHICH THE\nC INTERVAL (A,B) IS SUBDIVIDED.\nC HENCE, THERE WILL BE M+1 GRID POINTS\nC IN THE X-DIRECTION GIVEN BY\nC X(I) = A+(I-1)DX FOR I = 1,2,...,M+1,\nC WHERE DX = (B-A)/M IS THE PANEL WIDTH.\nC M MUST BE GREATER THAN 3.\nC\nC MBDCND\nC INDICATES THE TYPE OF BOUNDARY CONDITIONS\nC AT X = A AND X = B.\nC\nC = 0 IF THE SOLUTION IS PERIODIC IN X,\nC I.E., U(I,J) = U(M+I,J).\nC = 1 IF THE SOLUTION IS SPECIFIED AT\nC X = A AND X = B.\nC = 2 IF THE SOLUTION IS SPECIFIED AT\nC X = A AND THE DERIVATIVE OF THE\nC SOLUTION WITH RESPECT TO X IS\nC SPECIFIED AT X = B.\nC = 3 IF THE DERIVATIVE OF THE SOLUTION\nC WITH RESPECT TO X IS SPECIFIED AT\nC AT X = A AND X = B.\nC = 4 IF THE DERIVATIVE OF THE SOLUTION\nC WITH RESPECT TO X IS SPECIFIED AT\nC X = A AND THE SOLUTION IS SPECIFIED\nC AT X = B.\nC\nC BDA\nC A ONE-DIMENSIONAL ARRAY OF LENGTH N+1 THAT\nC SPECIFIES THE VALUES OF THE DERIVATIVE\nC OF THE SOLUTION WITH RESPECT TO X AT X = A.\nC\nC WHEN MBDCND = 3 OR 4,\nC\nC BDA(J) = (D/DX)U(A,Y(J)), J = 1,2,...,N+1.\nC\nC WHEN MBDCND HAS ANY OTHER VALUE, BDA IS\nC A DUMMY VARIABLE.\nC\nC BDB\nC A ONE-DIMENSIONAL ARRAY OF LENGTH N+1\nC THAT SPECIFIES THE VALUES OF THE DERIVATIVE\nC OF THE SOLUTION WITH RESPECT TO X AT X = B.\nC\nC WHEN MBDCND = 2 OR 3,\nC\nC BDB(J) = (D/DX)U(B,Y(J)), J = 1,2,...,N+1\nC\nC WHEN MBDCND HAS ANY OTHER VALUE BDB IS A\nC DUMMY VARIABLE.\nC\nC C,D\nC THE RANGE OF Y, I.E., C .LE. Y .LE. D.\nC C MUST BE LESS THAN D.\nC\nC N\nC THE NUMBER OF PANELS INTO WHICH THE\nC INTERVAL (C,D) IS SUBDIVIDED. HENCE,\nC THERE WILL BE N+1 GRID POINTS IN THE\nC Y-DIRECTION GIVEN BY Y(J) = C+(J-1)DY\nC FOR J = 1,2,...,N+1, WHERE\nC DY = (D-C)/N IS THE PANEL WIDTH.\nC N MUST BE GREATER THAN 3.\nC\nC NBDCND\nC INDICATES THE TYPE OF BOUNDARY CONDITIONS AT\nC Y = C AND Y = D.\nC\nC = 0 IF THE SOLUTION IS PERIODIC IN Y,\nC I.E., U(I,J) = U(I,N+J).\nC = 1 IF THE SOLUTION IS SPECIFIED AT\nC Y = C AND Y = D.\nC = 2 IF THE SOLUTION IS SPECIFIED AT\nC Y = C AND THE DERIVATIVE OF THE\nC SOLUTION WITH RESPECT TO Y IS\nC SPECIFIED AT Y = D.\nC = 3 IF THE DERIVATIVE OF THE SOLUTION\nC WITH RESPECT TO Y IS SPECIFIED AT\nC Y = C AND Y = D.\nC = 4 IF THE DERIVATIVE OF THE SOLUTION\nC WITH RESPECT TO Y IS SPECIFIED AT\nC Y = C AND THE SOLUTION IS SPECIFIED\nC AT Y = D.\nC\nC BDC\nC A ONE-DIMENSIONAL ARRAY OF LENGTH M+1 THAT\nC SPECIFIES THE VALUES OF THE DERIVATIVE\nC OF THE SOLUTION WITH RESPECT TO Y AT Y = C.\nC\nC WHEN NBDCND = 3 OR 4,\nC\nC BDC(I) = (D/DY)U(X(I),C), I = 1,2,...,M+1\nC\nC WHEN NBDCND HAS ANY OTHER VALUE, BDC IS\nC A DUMMY VARIABLE.\nC\nC BDD\nC A ONE-DIMENSIONAL ARRAY OF LENGTH M+1 THAT\nC SPECIFIES THE VALUES OF THE DERIVATIVE\nC OF THE SOLUTION WITH RESPECT TO Y AT Y = D.\nC\nC WHEN NBDCND = 2 OR 3,\nC\nC BDD(I) = (D/DY)U(X(I),D), I = 1,2,...,M+1\nC\nC WHEN NBDCND HAS ANY OTHER VALUE, BDD IS\nC A DUMMY VARIABLE.\nC\nC ELMBDA\nC THE CONSTANT LAMBDA IN THE HELMHOLTZ\nC EQUATION. IF LAMBDA .GT. 0, A SOLUTION\nC MAY NOT EXIST. HOWEVER, HWSCRT WILL\nC ATTEMPT TO FIND A SOLUTION.\nC\nC F\nC A TWO-DIMENSIONAL ARRAY, OF DIMENSION AT\nC LEAST (M+1)*(N+1), SPECIFYING VALUES OF THE\nC RIGHT SIDE OF THE HELMHOLTZ EQUATION AND\nC BOUNDARY VALUES (IF ANY).\nC\nC ON THE INTERIOR, F IS DEFINED AS FOLLOWS:\nC FOR I = 2,3,...,M AND J = 2,3,...,N\nC F(I,J) = F(X(I),Y(J)).\nC\nC ON THE BOUNDARIES, F IS DEFINED AS FOLLOWS:\nC FOR J=1,2,...,N+1, I=1,2,...,M+1,\nC\nC MBDCND F(1,J) F(M+1,J)\nC ------ --------- --------\nC\nC 0 F(A,Y(J)) F(A,Y(J))\nC 1 U(A,Y(J)) U(B,Y(J))\nC 2 U(A,Y(J)) F(B,Y(J))\nC 3 F(A,Y(J)) F(B,Y(J))\nC 4 F(A,Y(J)) U(B,Y(J))\nC\nC\nC NBDCND F(I,1) F(I,N+1)\nC ------ --------- --------\nC\nC 0 F(X(I),C) F(X(I),C)\nC 1 U(X(I),C) U(X(I),D)\nC 2 U(X(I),C) F(X(I),D)\nC 3 F(X(I),C) F(X(I),D)\nC 4 F(X(I),C) U(X(I),D)\nC\nC NOTE:\nC IF THE TABLE CALLS FOR BOTH THE SOLUTION U\nC AND THE RIGHT SIDE F AT A CORNER THEN THE\nC SOLUTION MUST BE SPECIFIED.\nC\nC IDIMF\nC THE ROW (OR FIRST) DIMENSION OF THE ARRAY\nC F AS IT APPEARS IN THE PROGRAM CALLING\nC HWSCRT. THIS PARAMETER IS USED TO SPECIFY\nC THE VARIABLE DIMENSION OF F. IDIMF MUST\nC BE AT LEAST M+1 .\nC\nC W\nC A ONE-DIMENSIONAL ARRAY THAT MUST BE\nC PROVIDED BY THE USER FOR WORK SPACE.\nC W MAY REQUIRE UP TO 4*(N+1) +\nC (13 + INT(LOG2(N+1)))*(M+1) LOCATIONS.\nC THE ACTUAL NUMBER OF LOCATIONS USED IS\nC COMPUTED BY HWSCRT AND IS RETURNED IN\nC LOCATION W(1).\nC\nC\nC ON OUTPUT F\nC CONTAINS THE SOLUTION U(I,J) OF THE FINITE\nC DIFFERENCE APPROXIMATION FOR THE GRID POINT\nC (X(I),Y(J)), I = 1,2,...,M+1,\nC J = 1,2,...,N+1 .\nC\nC PERTRB\nC IF A COMBINATION OF PERIODIC OR DERIVATIVE\nC BOUNDARY CONDITIONS IS SPECIFIED FOR A\nC POISSON EQUATION (LAMBDA = 0), A SOLUTION\nC MAY NOT EXIST. PERTRB IS A CONSTANT,\nC CALCULATED AND SUBTRACTED FROM F, WHICH\nC ENSURES THAT A SOLUTION EXISTS. HWSCRT\nC THEN COMPUTES THIS SOLUTION, WHICH IS A\nC LEAST SQUARES SOLUTION TO THE ORIGINAL\nC APPROXIMATION. THIS SOLUTION PLUS ANY\nC CONSTANT IS ALSO A SOLUTION. HENCE, THE\nC SOLUTION IS NOT UNIQUE. THE VALUE OF\nC PERTRB SHOULD BE SMALL COMPARED TO THE\nC RIGHT SIDE F. OTHERWISE, A SOLUTION IS\nC OBTAINED TO AN ESSENTIALLY DIFFERENT\nC PROBLEM. THIS COMPARISON SHOULD ALWAYS\nC BE MADE TO INSURE THAT A MEANINGFUL\nC SOLUTION HAS BEEN OBTAINED.\nC\nC IERROR\nC AN ERROR FLAG THAT INDICATES INVALID INPUT\nC PARAMETERS. EXCEPT FOR NUMBERS 0 AND 6,\nC A SOLUTION IS NOT ATTEMPTED.\nC\nC = 0 NO ERROR\nC = 1 A .GE. B\nC = 2 MBDCND .LT. 0 OR MBDCND .GT. 4\nC = 3 C .GE. D\nC = 4 N .LE. 3\nC = 5 NBDCND .LT. 0 OR NBDCND .GT. 4\nC = 6 LAMBDA .GT. 0\nC = 7 IDIMF .LT. M+1\nC = 8 M .LE. 3\nC\nC SINCE THIS IS THE ONLY MEANS OF INDICATING\nC A POSSIBLY INCORRECT CALL TO HWSCRT, THE\nC USER SHOULD TEST IERROR AFTER THE CALL.\nC\nC W\nC W(1) CONTAINS THE REQUIRED LENGTH OF W.\nC\nC SPECIAL CONDITIONS NONE\nC\nC I/O NONE\nC\nC PRECISION SINGLE\nC\nC REQUIRED LIBRARY GENBUN, GNBNAUX, AND COMF\nC FILES FROM FISHPACK\nC\nC LANGUAGE FORTRAN\nC\nC HISTORY WRITTEN BY ROLAND SWEET AT NCAR IN THE LATE\nC 1970'S. RELEASED ON NCAR'S PUBLIC SOFTWARE\nC LIBRARIES IN JANUARY 1980.\nC\nC PORTABILITY FORTRAN 77\nC\nC ALGORITHM THE ROUTINE DEFINES THE FINITE DIFFERENCE\nC EQUATIONS, INCORPORATES BOUNDARY DATA, AND\nC ADJUSTS THE RIGHT SIDE OF SINGULAR SYSTEMS\nC AND THEN CALLS GENBUN TO SOLVE THE SYSTEM.\nC\nC TIMING FOR LARGE M AND N, THE OPERATION COUNT\nC IS ROUGHLY PROPORTIONAL TO\nC M*N*(LOG2(N)\nC BUT ALSO DEPENDS ON INPUT PARAMETERS NBDCND\nC AND MBDCND.\nC\nC ACCURACY THE SOLUTION PROCESS EMPLOYED RESULTS IN A LOSS\nC OF NO MORE THAN THREE SIGNIFICANT DIGITS FOR N\nC AND M AS LARGE AS 64. MORE DETAILS ABOUT\nC ACCURACY CAN BE FOUND IN THE DOCUMENTATION FOR\nC SUBROUTINE GENBUN WHICH IS THE ROUTINE THAT\nC SOLVES THE FINITE DIFFERENCE EQUATIONS.\nC\nC REFERENCES SWARZTRAUBER,P. AND R. SWEET, \"EFFICIENT\nC FORTRAN SUBPROGRAMS FOR THE SOLUTION OF\nC ELLIPTIC EQUATIONS\"\nC NCAR TN/IA-109, JULY, 1975, 138 PP.\nC***********************************************************************\n DIMENSION F(IDIMF,*)\n DIMENSION BDA(*) ,BDB(*) ,BDC(*) ,BDD(*) ,\n 1 W(*)\nC\nC CHECK FOR INVALID PARAMETERS.\nC\n IERROR = 0\n IF (A .GE. B) IERROR = 1\n IF (MBDCND.LT.0 .OR. MBDCND.GT.4) IERROR = 2\n IF (C .GE. D) IERROR = 3\n IF (N .LE. 3) IERROR = 4\n IF (NBDCND.LT.0 .OR. NBDCND.GT.4) IERROR = 5\n IF (IDIMF .LT. M+1) IERROR = 7\n IF (M .LE. 3) IERROR = 8\n IF (IERROR .NE. 0) RETURN\n NPEROD = NBDCND\n MPEROD = 0\n IF (MBDCND .GT. 0) MPEROD = 1\n DELTAX = (B-A)/FLOAT(M)\n TWDELX = 2./DELTAX\n DELXSQ = 1./DELTAX**2\n DELTAY = (D-C)/FLOAT(N)\n TWDELY = 2./DELTAY\n DELYSQ = 1./DELTAY**2\n NP = NBDCND+1\n NP1 = N+1\n MP = MBDCND+1\n MP1 = M+1\n NSTART = 1\n NSTOP = N\n NSKIP = 1\n GO TO (104,101,102,103,104),NP\n 101 NSTART = 2\n GO TO 104\n 102 NSTART = 2\n 103 NSTOP = NP1\n NSKIP = 2\n 104 NUNK = NSTOP-NSTART+1\nC\nC ENTER BOUNDARY DATA FOR X-BOUNDARIES.\nC\n MSTART = 1\n MSTOP = M\n MSKIP = 1\n GO TO (117,105,106,109,110),MP\n 105 MSTART = 2\n GO TO 107\n 106 MSTART = 2\n MSTOP = MP1\n MSKIP = 2\n 107 DO 108 J=NSTART,NSTOP\n F(2,J) = F(2,J)-F(1,J)*DELXSQ\n 108 CONTINUE\n GO TO 112\n 109 MSTOP = MP1\n MSKIP = 2\n 110 DO 111 J=NSTART,NSTOP\n F(1,J) = F(1,J)+BDA(J)*TWDELX\n 111 CONTINUE\n 112 GO TO (113,115),MSKIP\n 113 DO 114 J=NSTART,NSTOP\n F(M,J) = F(M,J)-F(MP1,J)*DELXSQ\n 114 CONTINUE\n GO TO 117\n 115 DO 116 J=NSTART,NSTOP\n F(MP1,J) = F(MP1,J)-BDB(J)*TWDELX\n 116 CONTINUE\n 117 MUNK = MSTOP-MSTART+1\nC\nC ENTER BOUNDARY DATA FOR Y-BOUNDARIES.\nC\n GO TO (127,118,118,120,120),NP\n 118 DO 119 I=MSTART,MSTOP\n F(I,2) = F(I,2)-F(I,1)*DELYSQ\n 119 CONTINUE\n GO TO 122\n 120 DO 121 I=MSTART,MSTOP\n F(I,1) = F(I,1)+BDC(I)*TWDELY\n 121 CONTINUE\n 122 GO TO (123,125),NSKIP\n 123 DO 124 I=MSTART,MSTOP\n F(I,N) = F(I,N)-F(I,NP1)*DELYSQ\n 124 CONTINUE\n GO TO 127\n 125 DO 126 I=MSTART,MSTOP\n F(I,NP1) = F(I,NP1)-BDD(I)*TWDELY\n 126 CONTINUE\nC\nC MULTIPLY RIGHT SIDE BY DELTAY**2.\nC\n 127 DELYSQ = DELTAY*DELTAY\n DO 129 I=MSTART,MSTOP\n DO 128 J=NSTART,NSTOP\n F(I,J) = F(I,J)*DELYSQ\n 128 CONTINUE\n 129 CONTINUE\nC\nC DEFINE THE A,B,C COEFFICIENTS IN W-ARRAY.\nC\n ID2 = MUNK\n ID3 = ID2+MUNK\n ID4 = ID3+MUNK\n S = DELYSQ*DELXSQ\n ST2 = 2.*S\n DO 130 I=1,MUNK\n W(I) = S\n J = ID2+I\n W(J) = -ST2+ELMBDA*DELYSQ\n J = ID3+I\n W(J) = S\n 130 CONTINUE\n IF (MP .EQ. 1) GO TO 131\n W(1) = 0.\n W(ID4) = 0.\n 131 CONTINUE\n GO TO (135,135,132,133,134),MP\n 132 W(ID2) = ST2\n GO TO 135\n 133 W(ID2) = ST2\n 134 W(ID3+1) = ST2\n 135 CONTINUE\n PERTRB = 0.\n IF (ELMBDA) 144,137,136\n 136 IERROR = 6\n GO TO 144\n 137 IF ((NBDCND.EQ.0 .OR. NBDCND.EQ.3) .AND.\n 1 (MBDCND.EQ.0 .OR. MBDCND.EQ.3)) GO TO 138\n GO TO 144\nC\nC FOR SINGULAR PROBLEMS MUST ADJUST DATA TO INSURE THAT A SOLUTION\nC WILL EXIST.\nC\n 138 A1 = 1.\n A2 = 1.\n IF (NBDCND .EQ. 3) A2 = 2.\n IF (MBDCND .EQ. 3) A1 = 2.\n S1 = 0.\n MSP1 = MSTART+1\n MSTM1 = MSTOP-1\n NSP1 = NSTART+1\n NSTM1 = NSTOP-1\n DO 140 J=NSP1,NSTM1\n S = 0.\n DO 139 I=MSP1,MSTM1\n S = S+F(I,J)\n 139 CONTINUE\n S1 = S1+S*A1+F(MSTART,J)+F(MSTOP,J)\n 140 CONTINUE\n S1 = A2*S1\n S = 0.\n DO 141 I=MSP1,MSTM1\n S = S+F(I,NSTART)+F(I,NSTOP)\n 141 CONTINUE\n S1 = S1+S*A1+F(MSTART,NSTART)+F(MSTART,NSTOP)+F(MSTOP,NSTART)+\n 1 F(MSTOP,NSTOP)\n S = (2.+FLOAT(NUNK-2)*A2)*(2.+FLOAT(MUNK-2)*A1)\n PERTRB = S1/S\n DO 143 J=NSTART,NSTOP\n DO 142 I=MSTART,MSTOP\n F(I,J) = F(I,J)-PERTRB\n 142 CONTINUE\n 143 CONTINUE\n PERTRB = PERTRB/DELYSQ\nC\nC SOLVE THE EQUATION.\nC\n 144 CALL GENBUN (NPEROD,NUNK,MPEROD,MUNK,W(1),W(ID2+1),W(ID3+1),\n 1 IDIMF,F(MSTART,NSTART),IERR1,W(ID4+1))\n W(1) = W(ID4+1)+3.*FLOAT(MUNK)\nC\nC FILL IN IDENTICAL VALUES WHEN HAVE PERIODIC BOUNDARY CONDITIONS.\nC\n IF (NBDCND .NE. 0) GO TO 146\n DO 145 I=MSTART,MSTOP\n F(I,NP1) = F(I,1)\n 145 CONTINUE\n 146 IF (MBDCND .NE. 0) GO TO 148\n DO 147 J=NSTART,NSTOP\n F(MP1,J) = F(1,J)\n 147 CONTINUE\n IF (NBDCND .EQ. 0) F(MP1,NP1) = F(1,NP1)\n 148 CONTINUE\n RETURN\nC\nC REVISION HISTORY---\nC\nC SEPTEMBER 1973 VERSION 1\nC APRIL 1976 VERSION 2\nC JANUARY 1978 VERSION 3\nC DECEMBER 1979 VERSION 3.1\nC FEBRUARY 1985 DOCUMENTATION UPGRADE\nC NOVEMBER 1988 VERSION 3.2, FORTRAN 77 CHANGES\nC-----------------------------------------------------------------------\n END\n", "meta": {"hexsha": "f77d26aacbe7e7b4551a9a58a242dafbb3869483", "size": 19900, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/src/hwscrt.f", "max_stars_repo_name": "ipelupessy/omuse", "max_stars_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2020-03-25T10:02:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-18T00:28:35.000Z", "max_issues_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/src/hwscrt.f", "max_issues_repo_name": "ipelupessy/omuse", "max_issues_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 45, "max_issues_repo_issues_event_min_datetime": "2020-03-03T16:07:16.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-14T09:01:07.000Z", "max_forks_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/src/hwscrt.f", "max_forks_repo_name": "ipelupessy/omuse", "max_forks_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-03-03T13:28:50.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-26T09:20:02.000Z", "avg_line_length": 38.7914230019, "max_line_length": 72, "alphanum_fraction": 0.4043718593, "num_tokens": 5573, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625050654263, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6722767405269017}} {"text": " SUBROUTINE APLMS(L,M,S,AP)\n\n!PURPOSE: Compute A'(l,m,s)\n\n INCLUDE '../INCLDS/COPYRIGT.FOR' \n\n!CALLING ARGUMENTS: \n\n INTEGER*4 L,M,S !Order & subindices\n REAL*4 AP !Output value\n\n!INCLUDE STATEMENTS:\n\n!LOCAL VARIABLES:\n\n REAL*4 LNORM,ALM0S,A1,A2 \n\n!FUNCTION DEFINITIONS:\n\n!DATA STATEMENTS:\n\n!CODE: \n\n LNORM = SQRT((2.0*L+1.0)/2.0)\n CALL QLMN(L,M,S,A1)\n CALL QLMN(L,0,S,A2)\n ALM0S = A1*A2\n IF ( MOD(ABS(M),2).EQ.0 ) THEN\n IF ( S.EQ.0 ) THEN\n AP = ALM0S*LNORM\n ELSE\n AP = 2.0*ALM0S*LNORM\n END IF\n IF ( MOD(ABS(M),4).EQ.2 ) AP = -AP\n ELSE\n IF ( S.EQ.0 ) THEN\n AP = 0.0\n ELSE\n AP = 2.0*ALM0S*LNORM\n END IF \n IF ( MOD(ABS(M),4).EQ.1 ) AP = -AP\n END IF\n IF ( ABS(AP).LT.1.0E-6 ) AP = 0.0\n RETURN \n END \n\n", "meta": {"hexsha": "4246c6d6d55783b97e73b3d68f0c695116beb04a", "size": 1008, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "Xerus/GSASII/fsource/texturesubs/aplms.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/texturesubs/aplms.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/texturesubs/aplms.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": 21.4468085106, "max_line_length": 59, "alphanum_fraction": 0.4246031746, "num_tokens": 347, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625012602593, "lm_q2_score": 0.7217432003123989, "lm_q1q2_score": 0.6722767266305715}} {"text": "c_______________________________________________________________________\nc\n subroutine matmult(a,b,c,nn,np,nq)\n \nc multiplies n x p matrix a by p x q matrix b and puts result in c\n \n real a(nn,np),b(np,nq),c(nn,nq)\n \n do 10 in=1,nn\n do 10 iq=1,nq\n temp=0.\n \n do 5 ip=1,np\n5 temp=temp+a(in,ip)*b(ip,iq)\n \n10 c(in,iq)=temp\n return\n end\nc______________________________________________________________________\nc\n subroutine matmultc(a,b,c,nn,np,nq)\n \nc multiplies n x p matrix a by p x q matrix b and puts result in c\nc complex version\n \n complex a(nn,np),b(np,nq),c(nn,nq),temp\n \n do 10 in=1,nn\n do 10 iq=1,nq\n temp=0.\n \n do 5 ip=1,np\n5 temp=temp+a(in,ip)*b(ip,iq)\n \n10 c(in,iq)=temp\n return\n end\nc______________________________________________________________________\nc\n subroutine mmacb(a,b,c,nn,np,nq)\n \nc multiplies conjugate transpose of\nc p x n matrix a by p x q matrix b and puts result in c\nc complex version\n \n complex a(np,nn),b(np,nq),c(nn,nq),temp\n \n do 10 in=1,nn\n do 10 iq=1,nq\n temp=0.\n \n do 5 ip=1,np\n5 temp=temp+conjg(a(ip,in))*b(ip,iq)\n \n10 c(in,iq)=temp\n return\n end\nc______________________________________________________________________\nc\n subroutine mmabc(a,b,c,nn,np,nq)\n \nc multiplies n x p matrix a by conjugate transpose of\nc q x p matrix b and puts result in c\nc complex version\n \n complex a(nn,np),b(nq,np),c(nn,nq),temp\n \n do 10 in=1,nn\n do 10 iq=1,nq\n temp=0.\n \n do 5 ip=1,np\n5 temp=temp+a(in,ip)*conjg(b(iq,ip))\n \n10 c(in,iq)=temp\n return\n end\n", "meta": {"hexsha": "3667e30938569f1689af0744454b1a0515e50e8a", "size": 1828, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iris_mt_scratch/egbert_codes-20210121T193218Z-001/egbert_codes/EMTF/T/matmult.f", "max_stars_repo_name": "simpeg-research/iris-mt-scratch", "max_stars_repo_head_hexsha": "ea458f253071db513fd0731118a2a7452a725944", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "iris_mt_scratch/egbert_codes-20210121T193218Z-001/egbert_codes/EMTF/T/matmult.f", "max_issues_repo_name": "simpeg-research/iris-mt-scratch", "max_issues_repo_head_hexsha": "ea458f253071db513fd0731118a2a7452a725944", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 19, "max_issues_repo_issues_event_min_datetime": "2020-12-23T17:55:48.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-24T21:01:05.000Z", "max_forks_repo_path": "iris_mt_scratch/egbert_codes-20210121T193218Z-001/egbert_codes/EMTF/T/matmult.f", "max_forks_repo_name": "simpeg-research/iris-mt-scratch", "max_forks_repo_head_hexsha": "ea458f253071db513fd0731118a2a7452a725944", "max_forks_repo_licenses": ["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.4358974359, "max_line_length": 72, "alphanum_fraction": 0.579868709, "num_tokens": 536, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772450055545, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.6722355394332888}} {"text": "module mod_parallel\n !< Summary: Provide parallel functions for domain decomposition\n !< using coarrays\n !< Author: Milan Curic (Initial), Sam Miller (Adapted and extended)\n !< Notes: Adapted from https://github.com/modern-fortran/tsunami/\n\n use, intrinsic :: iso_fortran_env, only: ik => int32, rk => real64, int64, std_out => output_unit\n\n implicit none\n\n ! private\n ! public :: num_2d_tiles, tile_indices, tile_neighbors_1d, tile_neighbors_2d !, sync_edges\n\n interface tile_indices\n module procedure :: tile_indices_1d, tile_indices_2d\n endinterface tile_indices\n\n ! Neighbor image indices\n integer(ik), parameter, public :: LOWER_LEFT = 1 !< lower left neighbor image\n integer(ik), parameter, public :: DOWN = 2 !< neighbor image below\n integer(ik), parameter, public :: LOWER_RIGHT = 3 !< lower right neigbor image\n integer(ik), parameter, public :: LEFT = 4 !< neighbor image to the left\n integer(ik), parameter, public :: RIGHT = 5 !< neighbor image to the right\n integer(ik), parameter, public :: UPPER_LEFT = 6 !< upper left neighbor image\n integer(ik), parameter, public :: UP = 7 !< neighbor image above\n integer(ik), parameter, public :: UPPER_RIGHT = 8 !< upper right neighbor image\n\ncontains\n\n pure function denominators(n)\n ! Returns all common denominators of n.\n integer(ik), intent(in) :: n\n integer(ik), allocatable :: denominators(:)\n integer(ik) :: i\n denominators = [integer(ik) ::]\n do i = 1, n\n if(mod(n, i) == 0) denominators = [denominators, i]\n enddo\n endfunction denominators\n\n pure function num_2d_tiles(n)\n !< Returns the optimal number of tiles in 2 dimensions\n !< given total number of tiles n.\n !\n ! Examples:\n ! * num_2d_tiles(1) = [1, 1]\n ! * num_2d_tiles(2) = [2, 1]\n ! * num_2d_tiles(3) = [3, 1]\n ! * num_2d_tiles(4) = [2, 2]\n ! * num_2d_tiles(5) = [5, 1]\n ! * num_2d_tiles(6) = [3, 2]\n !\n integer(ik), intent(in) :: n !< # of images\n integer(ik) :: num_2d_tiles(2) !< (i, j); # of tiles in each dimension\n integer(ik), allocatable :: denoms(:)\n integer(ik), allocatable :: dim1(:), dim2(:)\n integer(ik) :: i, j, n1, n2\n\n ! find all common denominators of the total number of images\n denoms = denominators(n)\n\n ! find all combinations of common denominators\n ! whose product equals the total number of images\n dim1 = [integer(ik) ::]\n dim2 = [integer(ik) ::]\n do j = 1, size(denoms)\n do i = 1, size(denoms)\n if(denoms(i) * denoms(j) == n) then\n dim1 = [dim1, denoms(i)]\n dim2 = [dim2, denoms(j)]\n endif\n enddo\n enddo\n\n ! pick the set of common denominators with the minimal norm\n ! between two elements -- rectangle closest to a square\n num_2d_tiles = [dim1(1), dim2(1)]\n do i = 2, size(dim1)\n n1 = norm2([dim1(i), dim2(i)] - sqrt(real(n)))\n n2 = norm2(num_2d_tiles - sqrt(real(n)))\n if(n1 < n2) num_2d_tiles = [dim1(i), dim2(i)]\n enddo\n endfunction num_2d_tiles\n\n pure function num_3d_tiles(n)\n integer(ik), intent(in) :: n\n integer(ik) :: num_3d_tiles(3)\n integer(ik), allocatable :: denoms(:)\n integer(ik), allocatable :: dim1(:), dim2(:), dim3(:)\n integer(ik) :: i, j, k, n1, n2, n3\n endfunction num_3d_tiles\n\n pure function tile_indices_1d(dims, i, n) result(indices)\n ! Given input global array size, return start and end index\n ! of a parallel 1-d tile that correspond to this image.\n integer(ik), intent(in) :: dims, i, n\n integer(ik) :: indices(2)\n integer(ik) :: offset, tile_size\n\n tile_size = dims / n\n\n ! start and end indices assuming equal tile sizes\n indices(1) = (i - 1) * tile_size + 1\n indices(2) = indices(1) + tile_size - 1\n\n ! if we have any remainder, distribute it to the tiles at the end\n offset = n - mod(dims, n)\n if(i > offset) then\n indices(1) = indices(1) + i - offset - 1\n indices(2) = indices(2) + i - offset\n endif\n endfunction tile_indices_1d\n\n pure function tile_indices_2d(dims) result(indices)\n ! Given an input x- and y- dimensions of the total computational domain [im, jm].\n ! returns an array of start and end indices in x- and y-, [is, ie, js, je].\n integer(ik), intent(in) :: dims(2)\n integer(ik) :: indices(4)\n integer(ik) :: tiles(2), tiles_ij(2)\n tiles = num_2d_tiles(num_images())\n tiles_ij = tile_n2ij(this_image())\n indices(1:2) = tile_indices_1d(dims(1), tiles_ij(1), tiles(1))\n indices(3:4) = tile_indices_1d(dims(2), tiles_ij(2), tiles(2))\n endfunction tile_indices_2d\n\n pure function tile_indices_3d(dims) result(indices)\n ! Given an input x,y,z dimensions of the total computational domain [im, jm, km].\n ! returns an array of start and end indices in x,y,z : [is, ie, js, je, ks, ke].\n integer(ik), intent(in) :: dims(3)\n integer(ik) :: indices(4)\n integer(ik) :: tiles(3), tiles_ijk(3)\n ! tiles = num_3d_tiles(num_images())\n ! tiles_ij = tile_n2ij(this_image())\n ! indices(1:2) = tile_indices_1d(dims(1), tiles_ij(1), tiles(1))\n ! indices(3:4) = tile_indices_1d(dims(2), tiles_ij(2), tiles(2))\n endfunction tile_indices_3d\n\n pure function tile_neighbors_1d() result(neighbors)\n ! Returns the image indices corresponding\n ! to left and right neighbor tiles.\n integer(ik) :: neighbors(2)\n integer(ik) :: left, right\n if(num_images() > 1) then\n left = this_image() - 1\n right = this_image() + 1\n if(this_image() == 1) then\n left = num_images()\n else if(this_image() == num_images()) then\n right = 1\n endif\n else\n left = 1\n right = 1\n endif\n neighbors = [left, right]\n endfunction tile_neighbors_1d\n\n pure function tile_neighbors_2d(is_periodic) result(neighbors)\n ! Returns the neighbor image indices given.\n logical, intent(in) :: is_periodic\n integer(ik) :: neighbors(8) !< (lower_left, down, lower_right, left, right, upper_left, up, upper_right)\n integer(ik) :: tiles(2), tiles_ij(2), itile, jtile\n integer(ik) :: left, right, down, up\n integer(ik) :: lower_left !< image # to the lower left corner\n integer(ik) :: lower_right !< image # to the lower right corner\n integer(ik) :: upper_left !< image # to the upper left corner\n integer(ik) :: upper_right !< image # to the upper right corner\n integer(ik), dimension(2) :: ij_left !< (i, j); index of the tile to the left\n integer(ik), dimension(2) :: ij_right !< (i, j); index of the tile to the right\n integer(ik), dimension(2) :: ij_down !< (i, j); index of the tile below\n integer(ik), dimension(2) :: ij_up !< (i, j); index of the tile above\n integer(ik), dimension(2) :: ij_lower_left !< (i, j); index of the tile to the lower left corner\n integer(ik), dimension(2) :: ij_upper_left !< (i, j); index of the tile to the upper left corner\n integer(ik), dimension(2) :: ij_lower_right !< (i, j); index of the tile to the lower right corner\n integer(ik), dimension(2) :: ij_upper_right !< (i, j); index of the tile to the upper right corner\n\n tiles = num_2d_tiles(num_images())\n tiles_ij = tile_n2ij(this_image())\n itile = tiles_ij(1)\n jtile = tiles_ij(2)\n\n ! i, j tile indices for each of the neighbors\n ij_left = [itile - 1, jtile]\n ij_upper_left = [itile - 1, jtile + 1]\n ij_lower_left = [itile - 1, jtile - 1]\n\n ij_right = [itile + 1, jtile]\n ij_upper_right = [itile + 1, jtile + 1]\n ij_lower_right = [itile + 1, jtile - 1]\n\n ij_down = [itile, jtile - 1]\n ij_up = [itile, jtile + 1]\n\n if(is_periodic) then\n ! set neighbor to wrap around the edge\n if(ij_left(1) < 1) ij_left(1) = tiles(1)\n if(ij_right(1) > tiles(1)) ij_right(1) = 1\n if(ij_down(2) < 1) ij_down(2) = tiles(2)\n if(ij_up(2) > tiles(2)) ij_up(2) = 1\n\n if(ij_lower_left(1) < 1) ij_lower_left(1) = tiles(1)\n if(ij_lower_left(2) < 1) ij_lower_left(2) = tiles(2)\n if(ij_upper_left(1) < 1) ij_upper_left(1) = tiles(1)\n if(ij_upper_left(2) > tiles(2)) ij_upper_left(2) = 1\n\n if(ij_upper_right(1) > tiles(1)) ij_upper_right(1) = 1\n if(ij_upper_right(2) > tiles(2)) ij_upper_right(2) = 1\n if(ij_lower_right(1) > tiles(1)) ij_lower_right(1) = 1\n if(ij_lower_right(2) < 1) ij_lower_right(2) = tiles(2)\n\n else\n ! set neighbor to 0 -- no neighbor\n if(ij_left(1) < 1) ij_left = 0\n if(ij_right(1) > tiles(1)) ij_right = 0\n if(ij_down(2) < 1) ij_down = 0\n if(ij_up(2) > tiles(2)) ij_up = 0\n\n if(ij_upper_right(1) > tiles(1)) ij_upper_right(1) = 0\n if(ij_upper_right(2) > tiles(2)) ij_upper_right(2) = 0\n if(ij_lower_right(1) > tiles(1)) ij_lower_right(1) = 0\n if(ij_lower_right(2) < 1) ij_lower_right(2) = 0\n\n if(ij_lower_left(1) < 1) ij_lower_left(1) = 0\n if(ij_lower_left(2) < 1) ij_lower_left(2) = 0\n if(ij_upper_left(1) < 1) ij_upper_left(1) = 0\n if(ij_upper_left(2) > tiles(2)) ij_upper_left(2) = 0\n endif\n\n left = tile_ij2n(ij_left)\n right = tile_ij2n(ij_right)\n down = tile_ij2n(ij_down)\n up = tile_ij2n(ij_up)\n\n lower_left = tile_ij2n(ij_lower_left)\n upper_left = tile_ij2n(ij_upper_left)\n lower_right = tile_ij2n(ij_lower_right)\n upper_right = tile_ij2n(ij_upper_right)\n\n neighbors = [lower_left, down, lower_right, left, &\n right, upper_left, up, upper_right]\n endfunction tile_neighbors_2d\n\n pure function tile_neighbors_3d(is_periodic) result(neighbors)\n ! Returns the neighbor image indices given.\n logical, intent(in) :: is_periodic\n integer(ik) :: neighbors(4)\n integer(ik) :: tiles(2), tiles_ij(2), itile, jtile\n integer(ik) :: left, right, down, up\n integer(ik) :: ij_left(2), ij_right(2), ij_down(2), ij_up(2)\n !\n ! tiles = num_2d_tiles(num_images())\n ! tiles_ij = tile_n2ij(this_image())\n ! itile = tiles_ij(1)\n ! jtile = tiles_ij(2)\n !\n ! ! i, j tile indices for each of the neighbors\n ! ij_left = [itile - 1, jtile]\n ! ij_right = [itile + 1, jtile]\n ! ij_down = [itile, jtile - 1]\n ! ij_up = [itile, jtile + 1]\n !\n ! if (is_periodic) then\n ! ! set neighbor to wrap around the edge\n ! if (ij_left(1) < 1) ij_left(1) = tiles(1)\n ! if (ij_right(1) > tiles(1)) ij_right(1) = 1\n ! if (ij_down(2) < 1) ij_down(2) = tiles(2)\n ! if (ij_up(2) > tiles(2)) ij_up(2) = 1\n ! else\n ! ! set neighbor to 0 -- no neighbor\n ! if (ij_left(1) < 1) ij_left = 0\n ! if (ij_right(1) > tiles(1)) ij_right = 0\n ! if (ij_down(2) < 1) ij_down = 0\n ! if (ij_up(2) > tiles(2)) ij_up = 0\n ! end if\n !\n ! left = tile_ij2n(ij_left)\n ! right = tile_ij2n(ij_right)\n ! down = tile_ij2n(ij_down)\n ! up = tile_ij2n(ij_up)\n !\n ! neighbors = [left, right, down, up]\n endfunction tile_neighbors_3d\n\n pure function tile_n2ij(n) result(ij)\n ! Given tile index in a 1-d layout, returns the\n ! corresponding tile indices in a 2-d layout.\n !\n ! +---+---+---+\n ! 2 | 4 | 5 | 6 |\n ! +---+---+---+\n ! 1 | 1 | 2 | 3 |\n ! j +---+---+---+\n ! i 1 2 3\n !\n ! Examples:\n ! * tile_n2ij(2) = [2, 1]\n ! * tile_n2ij(4) = [1, 2]\n ! * tile_n2ij(6) = [3, 2]\n !\n integer(ik), intent(in) :: n\n integer(ik) :: ij(2), i, j, tiles(2)\n if(n == 0) then\n ij = 0\n else\n tiles = num_2d_tiles(num_images())\n j = (n - 1) / tiles(1) + 1\n i = n - (j - 1) * tiles(1)\n ij = [i, j]\n endif\n endfunction tile_n2ij\n\n pure function tile_ij2n(ij) result(n)\n ! Given tile indices in a 2-d layout, returns the\n ! corresponding tile index in a 1-d layout:\n !\n ! +---+---+---+\n ! 2 | 4 | 5 | 6 |\n ! +---+---+---+\n ! 1 | 1 | 2 | 3 |\n ! j +---+---+---+\n ! i 1 2 3\n !\n ! Examples:\n ! * tile_ij2n([2, 1]) = 2\n ! * tile_ij2n([1, 2]) = 4\n ! * tile_ij2n([3, 2]) = 6\n !\n integer(ik), intent(in) :: ij(2)\n integer(ik) :: n, tiles(2)\n if(any(ij == 0)) then\n n = 0\n else\n tiles = num_2d_tiles(num_images())\n n = (ij(2) - 1) * tiles(1) + ij(1)\n endif\n endfunction tile_ij2n\nendmodule mod_parallel\n", "meta": {"hexsha": "20904e0e6c0c369d706ddde3fc5e0d6453286d92", "size": 12189, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/lib/mod_parallel.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/mod_parallel.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/mod_parallel.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": 36.0621301775, "max_line_length": 108, "alphanum_fraction": 0.6060382312, "num_tokens": 4179, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.819893353516963, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.6722250985124756}} {"text": "C$Procedure QDQ2AV (Quaternion and quaternion derivative to a.v.)\n\n SUBROUTINE QDQ2AV ( Q, DQ, AV )\n\nC$ Abstract\nC\nC Derive angular velocity from a unit quaternion and its derivative\nC with respect to time.\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 ROTATION\nC \nC$ Keywords\nC\nC MATH\nC POINTING\nC ROTATION\nC\nC$ Declarations\n\n IMPLICIT NONE\n\n DOUBLE PRECISION Q ( 0 : 3 )\n DOUBLE PRECISION DQ ( 0 : 3 )\n DOUBLE PRECISION AV ( 3 )\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC Q I Unit SPICE quaternion.\nC DQ I Derivative of Q with respect to time.\nC AV O Angular velocity defined by Q and DQ.\nC\nC$ Detailed_Input\nC\nC Q is a unit length 4-vector representing a\nC SPICE-style quaternion. See the discussion of\nC quaternion styles in Particulars below.\nC\nC DQ is a 4-vector representing the derivative of\nC Q with respect to time. \nC\nC$ Detailed_Output\nC\nC AV is 3-vector representing the angular velocity\nC defined by Q and DQ, that is, the angular velocity\nC of the frame defined by the rotation matrix\nC associated with Q. This rotation matrix can be\nC obtained via the SPICELIB routine Q2M; see the\nC Particulars section for the explicit matrix \nC entries.\nC\nC AV is the vector (imaginary) part of the\nC quaternion product\nC\nC * \nC -2 * Q * DQ \nC\nC This angular velocity is the same vector that\nC could be obtained (much less efficiently ) by\nC mapping Q and DQ to the corresponding C-matrix R\nC and its derivative DR, then calling the SPICELIB\nC routine XF2RAV.\nC\nC AV has units of\nC\nC radians / T\nC\nC where\nC\nC 1 / T\nC\nC is the unit associated with DQ.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC Error free.\nC\nC 1) A unitized version of input quaternion is used in the\nC computation. No attempt is made to diagnose an invalid\nC input quaternion.\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC\nC Quaternion Styles\nC -----------------\nC\nC There are different \"styles\" of quaternions used in \nC science and engineering applications. Quaternion styles\nC are characterized by \nC\nC - The order of quaternion elements\nC\nC - The quaternion multiplication formula\nC\nC - The convention for associating quaternions\nC with rotation matrices\nC\nC Two of the commonly used styles are\nC\nC - \"SPICE\"\nC\nC > Invented by Sir William Rowan Hamilton\nC > Frequently used in mathematics and physics textbooks\nC\nC - \"Engineering\"\nC\nC > Widely used in aerospace engineering applications\nC\nC\nC SPICELIB subroutine interfaces ALWAYS use SPICE quaternions.\nC Quaternions of any other style must be converted to SPICE\nC quaternions before they are passed to SPICELIB routines.\nC \nC\nC Relationship between SPICE and Engineering Quaternions\nC ------------------------------------------------------\nC\nC Let M be a rotation matrix such that for any vector V, \nC\nC M*V\nC\nC is the result of rotating V by theta radians in the \nC counterclockwise direction about unit rotation axis vector A.\nC Then the SPICE quaternions representing M are\nC\nC (+/-) ( cos(theta/2), \nC sin(theta/2) A(1), \nC sin(theta/2) A(2), \nC sin(theta/2) A(3) ) \nC\nC while the engineering quaternions representing M are \nC\nC (+/-) ( -sin(theta/2) A(1), \nC -sin(theta/2) A(2), \nC -sin(theta/2) A(3),\nC cos(theta/2) )\nC\nC For both styles of quaternions, if a quaternion q represents\nC a rotation matrix M, then -q represents M as well.\nC\nC Given an engineering quaternion\nC\nC QENG = ( q0, q1, q2, q3 )\nC\nC the equivalent SPICE quaternion is\nC\nC QSPICE = ( q3, -q0, -q1, -q2 )\nC\nC\nC Associating SPICE Quaternions with Rotation Matrices\nC ----------------------------------------------------\nC\nC Let FROM and TO be two right-handed reference frames, for\nC example, an inertial frame and a spacecraft-fixed frame. Let the\nC symbols\nC\nC V , V\nC FROM TO\nC\nC denote, respectively, an arbitrary vector expressed relative to\nC the FROM and TO frames. Let M denote the transformation matrix\nC that transforms vectors from frame FROM to frame TO; then\nC\nC V = M * V\nC TO FROM\nC\nC where the expression on the right hand side represents left\nC multiplication of the vector by the matrix.\nC\nC Then if the unit-length SPICE quaternion q represents M, where\nC\nC q = (q0, q1, q2, q3)\nC\nC the elements of M are derived from the elements of q as follows:\nC\nC +- -+\nC | 2 2 |\nC | 1 - 2*( q2 + q3 ) 2*(q1*q2 - q0*q3) 2*(q1*q3 + q0*q2) |\nC | |\nC | |\nC | 2 2 |\nC M = | 2*(q1*q2 + q0*q3) 1 - 2*( q1 + q3 ) 2*(q2*q3 - q0*q1) |\nC | |\nC | |\nC | 2 2 |\nC | 2*(q1*q3 - q0*q2) 2*(q2*q3 + q0*q1) 1 - 2*( q1 + q2 ) |\nC | |\nC +- -+\nC\nC Note that substituting the elements of -q for those of q in the\nC right hand side leaves each element of M unchanged; this shows\nC that if a quaternion q represents a matrix M, then so does the\nC quaternion -q.\nC\nC To map the rotation matrix M to a unit quaternion, we start by\nC decomposing the rotation matrix as a sum of symmetric\nC and skew-symmetric parts:\nC\nC 2\nC M = [ I + (1-cos(theta)) OMEGA ] + [ sin(theta) OMEGA ]\nC\nC symmetric skew-symmetric\nC\nC\nC OMEGA is a skew-symmetric matrix of the form\nC\nC +- -+\nC | 0 -n3 n2 |\nC | |\nC OMEGA = | n3 0 -n1 |\nC | |\nC | -n2 n1 0 |\nC +- -+\nC\nC The vector N of matrix entries (n1, n2, n3) is the rotation axis\nC of M and theta is M's rotation angle. Note that N and theta\nC are not unique.\nC\nC Let\nC\nC C = cos(theta/2)\nC S = sin(theta/2)\nC\nC Then the unit quaternions Q corresponding to M are\nC\nC Q = +/- ( C, S*n1, S*n2, S*n3 )\nC\nC The mappings between quaternions and the corresponding rotations\nC are carried out by the SPICELIB routines\nC\nC Q2M {quaternion to matrix}\nC M2Q {matrix to quaternion}\nC\nC M2Q always returns a quaternion with scalar part greater than\nC or equal to zero.\nC\nC\nC SPICE Quaternion Multiplication Formula\nC ---------------------------------------\nC\nC Given a SPICE quaternion \nC\nC Q = ( q0, q1, q2, q3 )\nC\nC corresponding to rotation axis A and angle theta as above, we can\nC represent Q using \"scalar + vector\" notation as follows:\nC\nC s = q0 = cos(theta/2)\nC\nC v = ( q1, q2, q3 ) = sin(theta/2) * A\nC\nC Q = s + v\nC\nC Let Q1 and Q2 be SPICE quaternions with respective scalar\nC and vector parts s1, s2 and v1, v2:\nC \nC Q1 = s1 + v1\nC Q2 = s2 + v2\nC\nC We represent the dot product of v1 and v2 by\nC\nC \nC\nC and the cross product of v1 and v2 by\nC\nC v1 x v2\nC\nC Then the SPICE quaternion product is\nC\nC Q1*Q2 = s1*s2 - + s1*v2 + s2*v1 + (v1 x v2) \nC\nC If Q1 and Q2 represent the rotation matrices M1 and M2 \nC respectively, then the quaternion product\nC\nC Q1*Q2\nC\nC represents the matrix product\nC\nC M1*M2\nC\nC \nC About this routine\nC ==================\nC\nC Given a time-dependent SPICE quaternion representing the\nC attitude of an object, we can obtain the object's angular\nC velocity AV in terms of the quaternion Q and its derivative \nC with respect to time DQ:\nC\nC *\nC AV = Im ( -2 * Q * DQ ) (1)\nC \nC That is, AV is the vector (imaginary) part of the product\nC on the right hand side (RHS) of equation (1). The scalar part \nC of the RHS is zero.\nC\nC We'll now provide an explanation of formula (1). For any\nC time-dependent rotation, the associated angular velocity at a\nC given time is a function of the rotation and its derivative at\nC that time. This fact enables us to extend a proof for a limited\nC subset of rotations to *all* rotations: if we find a formula\nC that, for any rotation in our subset, gives us the angular\nC velocity as a function of the rotation and its derivative, then\nC that formula must be true for all rotations.\nC\nC We start out by considering the set of rotation matrices\nC\nC R(t) = M(t)C (2)\nC\nC where C is a constant rotation matrix and M(t) represents a\nC matrix that \"rotates\" with constant, unit magnitude angular\nC velocity and that is equal to the identity matrix at t = 0.\nC\nC For future reference, we'll consider C to represent a coordinate\nC transformation from frame F1 to frame F2. We'll call F1 the\nC \"base frame\" of C. We'll let AVF2 be the angular velocity of\nC M(t) relative to F2 and AVF1 be the same angular velocity\nC relative to F1.\nC\nC Referring to the axis-and-angle decomposition of M(t)\nC\nC 2\nC M(t) = I + sin(t)OMEGA + (1-cos(t))OMEGA (3)\nC\nC (see the Rotation Required Reading for a derivation) we \nC have\nC\nC d(M(t))|\nC -------| = OMEGA (4)\nC dt |t=0\nC\nC Then the derivative of R(t) at t = 0 is given by\nC\nC\nC d(R(t))|\nC -------| = OMEGA * C (5)\nC dt |t=0\nC\nC\nC The rotation axis A associated with OMEGA is defined by (6)\nC\nC A(1) = - OMEGA(2,3)\nC A(2) = OMEGA(1,3)\nC A(3) = - OMEGA(1,2)\nC \nC Since the coordinate system rotation M(t) rotates vectors about A\nC through angle t radians at time t, the angular velocity AVF2 of\nC M(t) is actually given by\nC\nC AVF2 = - A (7)\nC\nC This angular velocity is represented relative to the image\nC frame F2 associated with the coordinate transformation C.\nC\nC Now, let's proceed to the angular velocity formula for\nC quaternions.\nC \nC To avoid some verbiage, we'll freely use 3-vectors to represent\nC the corresponding pure imaginary quaternions.\nC\nC Letting QR(t), QM(t), and QC be quaternions representing the\nC time-dependent matrices R(t), M(t) and C respectively, where\nC QM(t) is selected to be a differentiable function of t in a\nC neighborhood of t = 0, the quaternion representing R(t) is\nC\nC QR(t) = QM(t) * QC (8)\nC\nC Differentiating with respect to t, then evaluating derivatives\nC at t = 0, we have\nC\nC d(QR(t))| d(QM(t))|\nC --------| = --------| * QC (9)\nC dt |t=0 dt |t=0\nC\nC\nC Since QM(t) represents a rotation having axis A and rotation\nC angle t, then (according to the relationship between SPICE\nC quaternions and rotations set out in the Rotation Required\nC Reading), we see QM(t) must be the quaternion (represented as the\nC sum of scalar and vector parts):\nC \nC cos(t/2) + sin(t/2) * A (10)\nC\nC where A is the rotation axis corresponding to the matrix\nC OMEGA introduced in equation (3). By inspection\nC\nC d(QM(t))|\nC --------| = 1/2 * A (11)\nC dt |t=0\nC\nC which is a quaternion with scalar part zero. This allows us to \nC rewrite the quaternion derivative \nC\nC d(QR(t))| \nC --------| = 1/2 * A * QC (12)\nC dt |t=0 \nC\nC or for short,\nC\nC DQ = 1/2 * A * QC (13)\nC\nC Since from (7) we know the angular velocity AVF2 of the frame\nC associated with QM(t) is the negative of the rotation axis\nC defined by (3), we have\nC\nC DQ = - 1/2 * AVF2 * QC (14)\nC\nC Since \nC\nC AVF2 = C * AVF1 (15)\nC\nC we can apply the quaternion transformation formula\nC (from the Rotation Required Reading)\nC\nC *\nC AVF2 = QC * AVF1 * QC (16)\nC \nC Now we re-write (15) as\nC\nC *\nC DQ = - 1/2 * ( QC * AVF1 * QC ) * QC \nC \nC = - 1/2 * QC * AVF1 (17)\nC\nC Then the angular velocity vector AVF1 is given by\nC\nC *\nC AVF1 = -2 * QC * DQ (18)\nC\nC The relation (18) has now been demonstrated for quaternions\nC having constant, unit magnitude angular velocity. But since\nC all time-dependent quaternions having value QC and derivative\nC DQ at a given time t have the same angular velocity at time t, \nC that angular velocity must be AVF1. \nC\nC$ Examples\nC\nC The following test program creates a quaternion and quaternion\nC derivative from a known rotation matrix and angular velocity\nC vector. The angular velocity is recovered from the quaternion\nC and quaternion derivative by calling QDQ2AV and by an\nC alternate method; the results are displayed for comparison.\nC\nC PROGRAM TQDQ2AV\nC IMPLICIT NONE\nC C\nC C Start with a known rotation and angular velocity. Find\nC C the quaternion and quaternion derivative. The latter is\nC C computed from\nC C\nC C * \nC C AV = -2 * Q * DQ \nC C \nC C DQ = -1/2 * Q * AV\nC C\nC C\nC C SPICELIB Functions\nC C\nC DOUBLE PRECISION RPD\nC\nC C\nC C Local variables\nC C\nC DOUBLE PRECISION ANGLE ( 3 )\nC DOUBLE PRECISION AV ( 3 )\nC DOUBLE PRECISION AVX ( 3 )\nC DOUBLE PRECISION DM ( 3, 3 )\nC DOUBLE PRECISION DQ ( 0 : 3 )\nC DOUBLE PRECISION EXPAV ( 3 )\nC DOUBLE PRECISION M ( 3, 3 )\nC DOUBLE PRECISION MOUT ( 3, 3 )\nC DOUBLE PRECISION Q ( 0 : 3 )\nC DOUBLE PRECISION QAV ( 0 : 3 )\nC DOUBLE PRECISION XTRANS ( 6, 6 )\nC\nC INTEGER I\nC INTEGER J\nC\nC C\nC C Pick some Euler angles and form a rotation matrix.\nC C\nC ANGLE(1) = -20.0 * RPD()\nC ANGLE(2) = 50.0 * RPD()\nC ANGLE(3) = -60.0 * RPD()\nC\nC CALL EUL2M ( ANGLE(3), ANGLE(2), ANGLE(1), 3, 1, 3, M )\nC\nC CALL M2Q ( M, Q )\nC\nC C\nC C Choose an angular velocity vector.\nC C\nC EXPAV(1) = 1.0D0\nC EXPAV(2) = 2.0D0\nC EXPAV(3) = 3.0D0\nC\nC C\nC C Form the quaternion derivative.\nC C\nC QAV(0) = 0.D0\nC CALL VEQU ( EXPAV, QAV(1) )\nC \nC CALL QXQ ( Q, QAV, DQ )\nC\nC CALL VSCLG ( -0.5D0, DQ, 4, DQ )\nC\nC C\nC C Recover angular velocity from Q and DQ using QDQ2AV. \nC C\nC CALL QDQ2AV ( Q, DQ, AV )\nC\nC C\nC C Now we'll obtain the angular velocity from Q and \nC C DQ by an alternate method.\nC C\nC C Convert Q back to a rotation matrix.\nC C\nC CALL Q2M ( Q, M )\nC\nC C\nC C Convert Q and DQ to a rotation derivative matrix. This\nC C somewhat messy procedure is based on differentiating the\nC C formula for deriving a rotation from a quaternion, then\nC C substituting components of Q and DQ into the derivative\nC C formula.\nC C\nC\nC DM(1,1) = -4.D0 * ( Q(2)*DQ(2) + Q(3)*DQ(3) )\nC\nC DM(1,2) = 2.D0 * ( Q(1)*DQ(2) + Q(2)*DQ(1)\nC . - Q(0)*DQ(3) - Q(3)*DQ(0) ) \nC\nC DM(1,3) = 2.D0 * ( Q(1)*DQ(3) + Q(3)*DQ(1)\nC . + Q(0)*DQ(2) + Q(2)*DQ(0) ) \nC\nC DM(2,1) = 2.D0 * ( Q(1)*DQ(2) + Q(2)*DQ(1)\nC . + Q(0)*DQ(3) + Q(3)*DQ(0) ) \nC\nC DM(2,2) = -4.D0 * ( Q(1)*DQ(1) + Q(3)*DQ(3) )\nC\nC DM(2,3) = 2.D0 * ( Q(2)*DQ(3) + Q(3)*DQ(2)\nC . - Q(0)*DQ(1) - Q(1)*DQ(0) ) \nC\nC DM(3,1) = 2.D0 * ( Q(3)*DQ(1) + Q(1)*DQ(3)\nC . - Q(0)*DQ(2) - Q(2)*DQ(0) ) \nC\nC DM(3,2) = 2.D0 * ( Q(2)*DQ(3) + Q(3)*DQ(2)\nC . + Q(0)*DQ(1) + Q(1)*DQ(0) ) \nC\nC DM(3,3) = -4.D0 * ( Q(1)*DQ(1) + Q(2)*DQ(2) )\nC\nC C\nC C Form the state transformation matrix corresponding to M\nC C and DM.\nC\nC CALL CLEARD ( 36, XTRANS )\nC\nC C\nC C Upper left block:\nC C\nC DO I = 1, 3\nC\nC DO J = 1, 3 \nC XTRANS(I,J) = M(I,J)\nC END DO\nC\nC END DO\nC\nC\nC C\nC C Lower right block:\nC C\nC DO I = 1, 3\nC\nC DO J = 1, 3 \nC XTRANS(3+I,3+J) = M(I,J)\nC END DO\nC\nC END DO\nC\nC C\nC C Lower left block:\nC C\nC DO I = 1, 3\nC\nC DO J = 1, 3 \nC XTRANS(3+I,J) = DM(I,J)\nC END DO\nC\nC END DO\nC\nC C\nC C Now use XF2RAV to produce the expected angular velocity.\nC C\nC CALL XF2RAV ( XTRANS, MOUT, AVX )\nC \nC C\nC C The results should match to nearly full double \nC C precision.\nC C\nC WRITE(*,*) 'Original angular velocity: ', EXPAV\nC WRITE(*,*) 'QDQ2AV''s angular velocity: ', AV\nC WRITE(*,*) 'XF2RAV''s angular velocity: ', AVX\nC\nC END\nC\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC N.J. Bachman (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 1.1.1, 26-FEB-2008 (NJB)\nC\nC Updated header; added information about SPICE \nC quaternion conventions.\nC\nC- SPICELIB Version 1.1.0, 31-AUG-2005 (NJB)\nC\nC Updated to remove non-standard use of duplicate arguments\nC in VSCL call.\nC\nC- SPICELIB Version 1.0.1, 24-FEB-2004 (NJB)\nC\nC Made minor edits to the Particulars header section.\nC\nC- SPICELIB Version 1.0.0, 26-AUG-2002 (NJB)\nC\nC\nC-&\n \nC$ Index_Entries\nC\nC angular velocity from quaternion and derivative\nC-&\n\nC$ Revisions\nC\nC- SPICELIB Version 1.1.0, 31-AUG-2005 (NJB)\nC\nC Updated to remove non-standard use of duplicate arguments\nC in VSCL call.\nC\nC-& \n\nC\nC Local variables\nC\n DOUBLE PRECISION QHAT ( 0 : 3 )\n DOUBLE PRECISION QSTAR ( 0 : 3 )\n DOUBLE PRECISION QTEMP ( 0 : 3 )\n\n\nC\nC Get a unitized copy of the input quaternion.\nC\n CALL VHATG ( Q, 4, QHAT )\n\nC\nC Get the conjugate QSTAR of QHAT.\nC\n QSTAR(0) = QHAT(0)\n CALL VMINUS ( QHAT(1), QSTAR(1) )\n\nC\nC Compute the angular velocity via the relationship\nC\nC *\nC AV = -2 * Q * DQ\nC \n\n CALL QXQ ( QSTAR, DQ, QTEMP ) \n CALL VSCL ( -2.D0, QTEMP(1), AV )\n\n RETURN\n END\n\n\n \n", "meta": {"hexsha": "293bafee19ed0f0da1baf10214f1b8d0a49eccc7", "size": 22742, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/qdq2av.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/qdq2av.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/qdq2av.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": 31.3250688705, "max_line_length": 72, "alphanum_fraction": 0.5130595374, "num_tokens": 6588, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632916317103, "lm_q2_score": 0.7248702880639791, "lm_q1q2_score": 0.6722180963450377}} {"text": "!\tCovariances of products of elements of latent vector with normal distribution with covariance matrix cov and mean mean.\r\nfunction quarticnormal(cov,mean)\r\nimplicit none\r\nreal(kind=8),intent(in)::cov(:,:),mean(:)\r\nreal(kind=8)::quarticnormal(size(mean),size(mean),size(mean),size(mean))\r\n!\tCounters\r\ninteger::col,col2,row,row2\r\ndo row=1,size(mean)\r\n\tdo col=1,row\r\n\t\tdo row2=1,row\r\n\t\t\tcol2=row2\r\n\t\t\tif(row==row2)col2=col\r\n\t\t\tquarticnormal(row,col,row2,1:col2)=cov(row,row2)*cov(col,1:col2)+cov(row,1:col2)*cov(row2,col)&\r\n\t\t\t\t\t+mean(row)*mean(row2)*cov(col,1:col2)&\r\n\t\t\t\t\t+mean(col)*mean(row2)*cov(row,1:col2)&\r\n\t\t\t\t\t+mean(row)*mean(1:col2)*cov(col,row2)&\r\n\t\t\t\t\t+mean(col)*mean(1:col2)*cov(row,row2)\r\n\t\t\tif(row/=row2)quarticnormal(row2,1:col2,row,col)=quarticnormal(row,col,row2,1:col2)\r\n\t\t\t\r\n\t\tend do\r\n\tend do\r\nend do\r\nreturn\r\nend function quarticnormal\r\n\r\n", "meta": {"hexsha": "182e4010416ec0c80c6637158a43d3c32a8c74af", "size": 858, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Source/quarticnormal.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/quarticnormal.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/quarticnormal.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": 33.0, "max_line_length": 122, "alphanum_fraction": 0.6864801865, "num_tokens": 291, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.927363293639213, "lm_q2_score": 0.724870282120402, "lm_q1q2_score": 0.6722180922883616}} {"text": "c=======================================================================\nc\nc subroutine KERNELA \nc\nc Density Estimation by Non Parametric Gaussian Kernel method \nc with iterative plug-in bandwidth selection. This version only uses \nc the gauss kernel and estimates only the density itself and not its \nc derivatives.\nc\nc-----------------------------------------------------------------------\n SUBROUTINE kernela ( N, M, X, Z, F, H, info)\nc-----------------------------------------------------------------------\nc\nc INPUT \nc N : number of histogram points (n>1) integer\nc M : number of gird points (m>0) integer\nc X(N) : sorted returns/histogram (n) double\nc Z(M) : sorted output gird (m) double\nc\nc OUTPUT \nc F(M) : estimated density (m) double\nc H : estimated iterative plugin bandwitdth double\nc info : diagnostic argument integer \nc \nc-----------------------------------------------------------------------\n IMPLICIT DOUBLE PRECISION (A-H,O-Z)\n INTEGER info\n DIMENSION X(N),Z(M),F(M)\nc\nc\n info = 0 \n XN=DBLE(N)\n XIQR=X(NINT(.75*XN))-X(NINT(.25*XN)+1)\n PI=3.141592645D0\n RT2PI = DSQRT(2.D0*PI)\n ITER=5\nC------- Estimate inflation constant C\n H2=(.920*XIQR)/(XN**(1.D0/7.D0))\n H3=(.912*XIQR)/(XN**(1.D0/9.D0))\n S2 = 0.D0\n S3 = 0.D0\n DO 20 I = 1, N-1\n DO 30 J = I+1, N\n D2 = ((X(I) - X(J))/H2)**2\n D3 = ((X(I) - X(J))/H3)**2\n IF(D2.GT.50.AND.D3.GT.60) GOTO 20\n E2 = DEXP(-0.5D0*D2)\n E3 = DEXP(-0.5D0*D3)\n S2 = S2 + (D2**2 - 6.D0*D2 + 3.D0)*E2\n S3 = S3 + (D3**3 - 15.D0*D3**2 + 45.D0*D3 - 15.D0)*E3\n30 CONTINUE\n20 CONTINUE\n RHAT2 = (2.D0*S2)/((XN**2)*(H2**5)*RT2PI)\n RHAT2 = RHAT2 + 3.D0/(RT2PI*XN*(H2**5))\n RHAT3 = (-2.D0*S3)/((XN**2)*(H3**7)*RT2PI)\n RHAT3 = RHAT3 + 15.D0/(RT2PI*XN*(H3**7))\n CO1 = 1.357D0*(RHAT2/RHAT3)**(1.D0/7.D0)\nC-\nC------- Compute constant of asymptotic formula\nC-\n CONST=1.D0/(2.D0*DSQRT(PI))\n A=1.132795764/RHAT3**(1.D0/7.D0)*XN**(-1.D0/2.D0)\nC-\nC------ Loop over iterations\nC-\n DO 100 IT=1,ITER\nC- \nC------- Estimate functional\nC\n S=0.D0 \n DO 40 I = 1, N-1\n DO 50 J = I+1, N\n D2 = ((X(I) - X(J))/A)**2\n IF(D2.GT.50) GOTO 40\n E2 = DEXP(-0.5D0*D2)\n S = S + (D2**2 - 6.D0*D2 + 3.D0)*E2\n50 CONTINUE\n40 CONTINUE\n R2 = (2.D0*S)/((XN**2)*(A**5)*RT2PI)\n R2 = R2 + 3.D0/(RT2PI*XN*(A**5))\nC- \nC------- Estimate bandwidth by asymptotic formula\nC-\n H=(CONST/(R2*XN))**(.2D0) \n A=CO1*H**(5./7.)\n100 CONTINUE\nC-\nC------- Estimate density with plugin bandwidth\nC- \n JBEGIN=1\n JEND=1 \n DO 200 I=1,M \n S=0.D0 \n DO 210 J=JBEGIN,JEND\n T=(Z(I)-X(J))/H\n IF(T.GT.5.0.AND.JBEGIN.LT.N) THEN\n JBEGIN=JBEGIN+1\n GOTO 210\n END IF\n S=S+DEXP(-T*T/2.)\n210 CONTINUE \n DO 220 JEND=J,N\n T=(Z(I)-X(JEND))/H\n IF(T.LT.-5.0) GOTO 230\n S=S+DEXP(-T*T/2.)\n220 CONTINUE\n230 F(I)=S/(XN*H*RT2PI)\n JEND=JEND-1\nC- \n200 CONTINUE \n RETURN \n END \n", "meta": {"hexsha": "42c0ad04378d8c0400ff84e1fe34f69cd94718cd", "size": 4390, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/analysis/kernel/kernela.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/analysis/kernel/kernela.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/analysis/kernel/kernela.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": 38.8495575221, "max_line_length": 142, "alphanum_fraction": 0.3410022779, "num_tokens": 1223, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632996617212, "lm_q2_score": 0.7248702761768248, "lm_q1q2_score": 0.6722180911420433}} {"text": "!Segun sea el tipo de la variable, van a ser su definic\u00f3n de las operaciones aritmeticas.\n\nprogram aritmeticas\nimplicit none\n\ninteger a, b\n\nreal c, d\n\ncomplex z1, z2\n\na = 2\nb = 1\n\nc = 3.1416\nd = 9.81\n\nz1 = cmplx(4, 4)\nz2 = cmplx(2, 1)\n\nprint *, \"Operaciones con enteros:\"\n\nprint *, \"a + b = \", a + b\n\nprint *, \"a - b = \", a - b\n\nprint *, \"a * b = \", a * b\n\nprint *, \"a / b = \", a / b\n\nprint *, \"a ^ b = \", a ** b\n\n\nprint *, \"Operaciones con reales:\"\n\nprint *, \"c + d = \", c + d\n\nprint *, \"c - d = \", c - d\n\nprint *, \"c * d = \", c * d\n\nprint *, \"c / d = \", c / d\n\nprint *, \"c ^ d = \", c ** d\n\n\nprint *, \"Operaciones con complejos:\"\n\nprint *, \"z1 + z2 = \", z1 + z2\n\nprint *, \"z1 - z2 = \", z1 - z2\n\nprint *, \"z1 * z2 = \", z1 * z2\n\nprint *, \"z1 / z2 = \", z1 / z2\n\nprint *, \"z1 ^ z2 = \", z1 ** z2\n\n \nend program aritmeticas", "meta": {"hexsha": "2d54204bcef51bc41c701211c501a0cb1dfe659b", "size": 821, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Operaciones elementales/aritmeticas.f90", "max_stars_repo_name": "kotoromo/Fortran-Basico", "max_stars_repo_head_hexsha": "1d37a82754acd1c231981adc3dea2d606e76d6c6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Operaciones elementales/aritmeticas.f90", "max_issues_repo_name": "kotoromo/Fortran-Basico", "max_issues_repo_head_hexsha": "1d37a82754acd1c231981adc3dea2d606e76d6c6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Operaciones elementales/aritmeticas.f90", "max_forks_repo_name": "kotoromo/Fortran-Basico", "max_forks_repo_head_hexsha": "1d37a82754acd1c231981adc3dea2d606e76d6c6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 13.6833333333, "max_line_length": 89, "alphanum_fraction": 0.5042630938, "num_tokens": 335, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.927363299661721, "lm_q2_score": 0.7248702702332475, "lm_q1q2_score": 0.6722180856301878}} {"text": "!---------------------------------------------------!\n! Copyright (c) 2017 Shunsuke A. Sato !\n! Released under the MIT license !\n! https://opensource.org/licenses/mit-license.php !\n!---------------------------------------------------!\n!-------10--------20--------30--------40--------50--------60--------70--------80--------90\nsubroutine set_band_velocity_2d(vk_xy)\n use global_variables_2d\n implicit none\n real(8),intent(out) :: vk_xy(2,-NKx:NKx,-NKy:NKy)\n integer :: ikx,iky\n real(8) :: dipx, dipy, mu_y\n\n select case(nband_type)\n case(N_PARABOLIC_BAND)\n!$omp parallel do private(ikx)\n do ikx = -NKx,NKx\n vk_xy(1,ikx,:) = kx(ikx)/mass_r\n end do\n!$omp parallel do private(iky)\n do iky = -NKy,NKy\n vk_xy(2,:,iky) = ky(iky)/mass_r\n end do\n case(N_COS_BAND)\n dipx = 2d0*pi/kx_max\n dipy = 2d0*pi/ky_max\n!$omp parallel do private(ikx, iky) collapse(2)\n do ikx = -NKx,NKx\n do iky = -NKy,NKy\n vk_xy(1,ikx,iky) = 0.5d0*band_width*dipx*sin(dipx*kx(ikx))*cos(dipy*ky(iky))\n vk_xy(2,ikx,iky) = 0.5d0*band_width*dipy*cos(dipx*kx(ikx))*sin(dipy*ky(iky))\n end do\n end do\n case(N_COS4_BAND)\n dipx = pi/kx_max\n dipy = pi/ky_max\n!$omp parallel do private(ikx, iky) collapse(2)\n do ikx = -NKx,NKx\n do iky = -NKy,NKy\n vk_xy(1,ikx,iky) = 4d0*band_width*dipx&\n *cos(dipx*kx(ikx))**3*sin(dipx*kx(ikx))*cos(dipy*ky(iky))**4\n vk_xy(2,ikx,iky) = 4d0*band_width*dipy&\n *cos(dipy*ky(iky))**3*sin(dipy*ky(iky))*cos(dipx*kx(ikx))**4\n end do\n end do\n case(N_HBN_BAND)\n dipx = 2d0*pi/kx_max\n mu_y = 2d0/(dipx**2*band_width)\n!$omp parallel do private(ikx, iky) collapse(2)\n do ikx = -NKx,NKx\n do iky = -NKy,NKy\n vk_xy(1,ikx,iky) = dipx*0.5d0*band_width*sin(dipx*kx(ikx))\n vk_xy(2,ikx,iky) = ky(iky)/mu_y\n end do\n end do\n case default\n write(*,\"(A,2x,A)\")\"Invalid nband_type\",nband_type\n stop\n end select\n\nend subroutine set_band_velocity_2d\n\n\n\n", "meta": {"hexsha": "7e0e5ae618d9a845207186147fbae210f2f4779f", "size": 2013, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/two_dimensional/set_band_velocity_2d.f90", "max_stars_repo_name": "shunsuke-sato/two_band_model", "max_stars_repo_head_hexsha": "27653b364b8f08f12eaa273a094c15f7154bdfc9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-07-12T15:46:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T11:32:46.000Z", "max_issues_repo_path": "src/two_dimensional/set_band_velocity_2d.f90", "max_issues_repo_name": "shunsuke-sato/two_band_model", "max_issues_repo_head_hexsha": "27653b364b8f08f12eaa273a094c15f7154bdfc9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-09T02:08:03.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-09T02:20:22.000Z", "max_forks_repo_path": "src/two_dimensional/set_band_velocity_2d.f90", "max_forks_repo_name": "shunsuke-sato/two_band_model", "max_forks_repo_head_hexsha": "27653b364b8f08f12eaa273a094c15f7154bdfc9", "max_forks_repo_licenses": ["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.9692307692, "max_line_length": 90, "alphanum_fraction": 0.5623447591, "num_tokens": 783, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632996617212, "lm_q2_score": 0.7248702642896702, "lm_q1q2_score": 0.6722180801183324}} {"text": " SUBROUTINE TCNSMT\t(IERROR)\nC\nC LATEST REVISION\t JUNE 1984\nC\nC PURPOSE\t\t TO PROVIDE A SIMPLE DEMONSTRATION OF\nC\t\t\t CONRECSMTH AND\tTO TEST\tCONRECSMTH ON A\tSINGLE\nC\t\t\t PROBLEM\nC\nC USAGE\t\t\t CALL TCNSMT (IERROR)\nC\nC ARGUMENTS\nC\nC ON OUTPUT\t\t IERROR\nC\t\t\t AN INTEGER VARIABLE\nC\t\t\t = 0,\tIF THE TEST WAS\tSUCCESSFUL,\nC\t\t\t = 1,\tOTHERWISE\nC\nC I/O\t\t\t IF THE\tTEST IS\tSUCCESSFUL, THE\tMESSAGE\nC\nC\t\t\t CONRECSMTH TEST SUCCESSFUL . . . SEE PLOT TO\nC\t\t\t VERIFY PERFORMANCE\nC\nC\t\t\t IS PRINTED ON UNIT 6.\nC\t\t\t IN ADDITION, TWO FRAMES CONTAINING THE\tCONTOUR\nC\t\t\t PLOT ARE PRODUCED ON THE MACHINE GRAPHICS\nC\t\t\t DEVICE. IN ORDER TO DETERMINE\tIF THE TEST\nC\t\t\t WAS SUCCESSFUL, IT IS NECESSARY TO EXAMINE\nC\t\t\t THESE PLOTS.\nC\nC PRECISION\t\t SINGLE\nC\nC\nC LANGUAGE\t\t FORTRAN\nC\nC ALGORITHM\t\t THE FUNCTION\nC\t\t\t Z(X,Y) = X +\tY + 1./((X-.1)**2+Y**2+.09)\nC\t\t\t\t -1./((X+.1)**2+Y**2+.09)\nC\t\t\t FOR X = -1. TO\t+1. IN INCREMENTS OF .1\tAND\nC\t\t\t Y = -1.2 TO +1.2 IN INCREMENTS OF .1\nC\t\t\t IS COMPUTED.\nC\t\t\t TCNSMT\tCALLS SUBROUTINES EZCNTR, CONREC, AND\nC\t\t\t WTSTR TO DRAW TWO LABELLED CONTOUR PLOTS OF THE\nC\t\t\t ARRAY Z.\nC\nC PORTABILITY\t\t ANSI FORTRAN77\tSTANDARD\nC\nC\nC Z CONTAINS THE VALUES\tTO BE PLOTTED.\nC\n REAL\t Z(21,25)\nC\nC SPECIFY COORDINATES FOR PLOT TITLES.\tON AN ABSTRACT GRID WHERE\nC THE INTEGER COORDINATES RANGE\tFROM 0.0 TO 1.0, THE VALUES TX AND TY\nC DEFINE THE CENTER OF THE TITLE STRING.\nC\nc DATA TX/0.42676/,\tTY/0.97656/\n TX = 0.42676\n TY = 0.97656\nC\nC\nC INITIALIZE ERROR PARAMETER\nC\n IERROR = 0\nC\nC FILL TWO DIMENSIONAL ARRAY TO\tBE PLOTTED\nC\n DO 20 I=1,21\n\t X = .1*FLOAT(I-11)\n\t DO 10\tJ=1,25\n\t Y =\t.1*FLOAT(J-13)\n\t Z(I,J) = X+Y+1./((X-.10)**2+Y**2+.09)-\n 1\t\t 1./((X+.10)**2+Y**2+.09)\n 10\t CONTINUE\n 20 CONTINUE\nC\nC SELECT NORMAIZATION TRANS NUMBER TO WRITE TITLES\nC\n CALL GSELNT (0)\nC\nC ENTRY\tEZCNTR REQUIRES\tONLY THE ARRAY NAME AND\tITS DIMENSIONS\nC\nC THE TITLE FOR\tTHIS PLOT IS\nC\nC DEMONSTRATION PLOT FOR EZCNTR ENTRY OF CONRECSMTH\nC\n CALL WTSTR (TX,TY,\n 1\t\t 'DEMONSTRATION\tPLOT FOR EZCNTR\tENTRY OF CONRECSMTH',\n 2\t\t 2,0,0)\n CALL EZCNTR (Z,21,25)\nC\nC\nC ENTRY\tCONREC ALLOWS USER SPECIFICATION OF PLOT PARAMETERS, IF\tDESIRED\nC\nC IN THIS EXAMPLE, THE LOWEST CONTOUR LEVEL (-4.5), THE\tHIGHEST\tCONTOUR\nC LEVEL\t(4.5), AND THE INCREMENT BETWEEN CONTOUR LEVELS\t(0.3) ARE\nC SPECIFIED.\nC\nC THE TITLE FOR\tTHIS PLOT IS\nC\nC DEMONSTRATION PLOT FOR CONREC ENTRY OF CONRECSMTH\nC\n CALL WTSTR (TX,TY,\n 1\t\t 'DEMONSTRATION\tPLOT FOR CONREC\tENTRY OF CONRECSMTH',\n 2\t\t 2,0,0)\n CALL CONREC (Z,21,21,25,-4.5,4.5,.3,0,0,0)\nc CALL NEWFM\nC\nc WRITE (6,1001)\n RETURN\nC\nc 1001 FORMAT ('\tCONRECSMTH TEST\tSUCCESSFUL',24X,\nc 1\t 'SEE PLOT\tTO VERIFY PERFORMANCE')\nC\nC\nC---------------------------------------------------------------------\nC\nC REVISION HISTORY\nC\nC JUNE 1984\t\t\t CONVERTED TO FORTRAN 77 AND GKS\nC\nC---------------------------------------------------------------------\n END\n", "meta": {"hexsha": "735d109aa603788c545040f54f6096d0eeb87689", "size": 2977, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iraf.v2161/sys/gio/ncarutil/tests/conrcsmtht.f", "max_stars_repo_name": "ysBach/irafdocgen", "max_stars_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:19:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T16:48:42.000Z", "max_issues_repo_path": "sys/gio/ncarutil/tests/conrcsmtht.f", "max_issues_repo_name": "kirxkirx/iraf", "max_issues_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-30T13:48:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-02T19:40:25.000Z", "max_forks_repo_path": "sys/gio/ncarutil/tests/conrcsmtht.f", "max_forks_repo_name": "kirxkirx/iraf", "max_forks_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.2032520325, "max_line_length": 71, "alphanum_fraction": 0.6281491434, "num_tokens": 1129, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936435, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.6722008530617576}} {"text": "program pt\ncall precisiontest\nend program\n\nsubroutine precisiontest()\n\nuse mpar\nreal(kind=RSP) :: real_sp\nreal(kind=REP) :: real_ep\ninteger(kind=ISP):: integer_sp\ninteger(kind=IEP):: integer_ep\n\nWRITE(*,*) \nWRITE(*,*) \"REAL(KIND=RSP), REAL SINGLE PRECISION\"\nWRITE(*,*) \"RSP =\", RSP\nWRITE(*,*) \"Number of decimal digits of precision =\", precision(real_sp)\nWRITE(*,*) \"Maximum binary exponent =\", maxexponent(real_sp)\nWRITE(*,*) \"Minimim binary exponent =\", minexponent(real_sp)\nWRITE(*,*)\nWRITE(*,*) \"REAL(KIND=REP), REAL EXTENDED PRECISION\"\nWRITE(*,*) \"REP =\", REP\nWRITE(*,*) \"Number of decimal digits of precision =\", precision(real_ep)\nWRITE(*,*) \"Maximum binary exponent =\", maxexponent(real_ep)\nWRITE(*,*) \"Minimim binary exponent =\", minexponent(real_ep)\nWRITE(*,*)\nWRITE(*,*) \"INTEGER(KIND=ISP), INTEGER SINGLE PRECISION\"\nWRITE(*,*) \"ISP =\", ISP\nWRITE(*,*) \"Range =\", range(integer_sp)\nWRITE(*,*)\nWRITE(*,*) \"INTEGER(KIND=IEP), INTEGER EXTENDED PRECISION\"\nWRITE(*,*) \"IEP =\", IEP\nWRITE(*,*) \"Range =\", range(integer_ep)\nWRITE(*,*)\n\nend subroutine precisiontest\n", "meta": {"hexsha": "90613113e481d7a865e66a0ddb94021693c2c2f5", "size": 1069, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/weil_exemple_withDA/my_cathy_prj/prepro/src/pt.f90", "max_stars_repo_name": "BenjMy/pycathy_wrapper", "max_stars_repo_head_hexsha": "8639713acbb5bc5c5cd293b94bdafe017d03f199", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "examples/weil_exemple_withDA/my_cathy_prj/prepro/src/pt.f90", "max_issues_repo_name": "BenjMy/pycathy_wrapper", "max_issues_repo_head_hexsha": "8639713acbb5bc5c5cd293b94bdafe017d03f199", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2021-10-14T13:07:46.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-02T03:32:05.000Z", "max_forks_repo_path": "examples/weil_exemple_withDA/my_cathy_prj/prepro/src/pt.f90", "max_forks_repo_name": "BenjMy/pycathy_wrapper", "max_forks_repo_head_hexsha": "8639713acbb5bc5c5cd293b94bdafe017d03f199", "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.6944444444, "max_line_length": 72, "alphanum_fraction": 0.6856875585, "num_tokens": 306, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891174511732, "lm_q2_score": 0.8175744695262775, "lm_q1q2_score": 0.6722008315504212}} {"text": "program demo_rnum0\nuse M_calculator, only : rnum0\nimplicit none\nreal :: x, y, z\n x=rnum0('20/3.4')\n y=rnum0('CI = 10 * sin(3.1416/4)')\n z=rnum0('CI')\n write(*,*)x,y,z\nend program demo_rnum0\n", "meta": {"hexsha": "14e27667ad1db4b0d4ea1a83a37fc7b550df0f93", "size": 198, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/demo_rnum0.f90", "max_stars_repo_name": "urbanjost/M_calculator", "max_stars_repo_head_hexsha": "1d1fccc7e3a5e5fbd03f8ce8b18f0a10d579ac94", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-26T18:46:14.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-20T02:58:10.000Z", "max_issues_repo_path": "example/demo_rnum0.f90", "max_issues_repo_name": "urbanjost/M_calculator", "max_issues_repo_head_hexsha": "1d1fccc7e3a5e5fbd03f8ce8b18f0a10d579ac94", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-09-18T00:04:19.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-18T03:50:52.000Z", "max_forks_repo_path": "docs/fpm-ford/src/demo_rnum0.f90", "max_forks_repo_name": "urbanjost/M_calculator", "max_forks_repo_head_hexsha": "1d1fccc7e3a5e5fbd03f8ce8b18f0a10d579ac94", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-10-08T00:32:16.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-08T00:32:16.000Z", "avg_line_length": 19.8, "max_line_length": 37, "alphanum_fraction": 0.6313131313, "num_tokens": 84, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.935346504434783, "lm_q2_score": 0.7185943925708561, "lm_q1q2_score": 0.6721347531975864}} {"text": "!\n! ej6_b.f90\n!\n! Copyright 2016 Bruno S \n!\n! This program is free software; you can redistribute it and/or modify\n! it under the terms of the GNU General Public License as published by\n! the Free Software Foundation; either version 2 of the License, or\n! (at your option) any later version.\n!\n! This program is distributed in the hope that it will be useful,\n! but WITHOUT ANY WARRANTY; without even the implied warranty of\n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n! GNU General Public License for more details.\n!\n! You should have received a copy of the GNU General Public License\n! along with this program; if not, write to the Free Software\n! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,\n! MA 02110-1301, USA.\n!\n!\n!\nPROGRAM ej5_b\n\nuse precision, pr => dp\n\nIMPLICIT NONE\n\ninteger :: i, j, k, n\nreal(pr) :: x, y, h, x0, xf, y0, error, exacta\nreal(pr) :: f1, f2, start_time, finish_time\n\nopen(unit=10, file='ej5_b.dat', status='UNKNOWN', action='WRITE')\n\nwrite(10, *) \"# x y exacta err\"\n\nx0 = 0._pr\nxf = 1._pr\n\n!condiciones iniciales\ny0 = 1._pr\n\nn = 10000\n\nh = (xf - x0)/real(n, pr)\n\n! para t == 0\ny = y0\nx = x0\n\nexacta = exp(-x*x*0.5_pr)\nwrite(10, *) x, y, exacta, 0._pr\n\ncall cpu_time(start_time)\ndo i = 1, n\n ! integro en v\n f1 = h * f(x, y)\n f2 = h * f(x + h, y + f1)\n y = y + (f1 + f2) * 0.5_pr\n\n x = x0 + h * i ! ya que f no depende de t\n exacta = exp(-x*x*0.5_pr)\n error = abs(y - exacta)\n write(10, *) x, y, exacta, error\nend do\ncall cpu_time(finish_time)\n\nCONTAINS\n\nfunction f(x, y)\nreal (pr) :: f\nreal (pr), intent(in) :: x, y\n\n f = -y*x\n\nend function f\n\n\n\nEND PROGRAM ej5_b\n", "meta": {"hexsha": "c76f8746093ba9b3ac0ad775ea63d0c2e8a5cd6f", "size": 1682, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lab1/5/ej5_b.f90", "max_stars_repo_name": "BrunoSanchez/fisicaComp", "max_stars_repo_head_hexsha": "be5f61675fee6e370b6d3f5a7eb254fd112c61b0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lab1/5/ej5_b.f90", "max_issues_repo_name": "BrunoSanchez/fisicaComp", "max_issues_repo_head_hexsha": "be5f61675fee6e370b6d3f5a7eb254fd112c61b0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lab1/5/ej5_b.f90", "max_forks_repo_name": "BrunoSanchez/fisicaComp", "max_forks_repo_head_hexsha": "be5f61675fee6e370b6d3f5a7eb254fd112c61b0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.7654320988, "max_line_length": 70, "alphanum_fraction": 0.6527942925, "num_tokens": 571, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232489352, "lm_q2_score": 0.8244619220634456, "lm_q1q2_score": 0.6721281450997174}} {"text": "!---------------------------------------------------------------------- \n! \"dimless.f\" \n!---------------------------------------------------------------------- \nSUBROUTINE FUNC(NDIM,U,ICP,PAR,IJAC,F,DFDU,DFDP) \n! ---------- ---- \n IMPLICIT NONE\n INTEGER, INTENT(IN) :: NDIM, ICP(*), IJAC\n DOUBLE PRECISION, INTENT(IN) :: U(NDIM), PAR(*)\n DOUBLE PRECISION, INTENT(OUT) :: F(NDIM)\n DOUBLE PRECISION, INTENT(INOUT) :: DFDU(NDIM,NDIM), DFDP(NDIM,*)\n DOUBLE PRECISION V, N, v1, vca, vL, vK, v2, v4, gca, gL, gK, phin\n DOUBLE PRECISION minf, v3, ninf, C, psi\n \n V = U(1)\n N = U(2)\n! bifurcation parameters\n v1 = PAR(1)\n\t v3 = PAR(2)\n! model parameters\n vca = 80.d0; \n vL = (-70.d0/vca);\n vK = (-90.d0/vca);\n v2 = (25.d0/vca);\n\t !v3 = (-11.d0/vca);\n v4 = (14.5d0/vca);\n\t gK = 3.1416E-13;\n gca = (1.57E-13/gk); \n gL = ((7.854E-14)/gk);\n\t C = 1.9635E-14;\n phin = 2.664d0;\n\t psi=((C*phin)/gk)\n!model equations and auxiliary functions\n minf = (0.5d0*(1+tanh((V-v1)/v2)));\n ninf = 0.5d0*(1+tanh((V-v3)/v4));\n F(1) = -(gL*(V-vL)+N*(V-vK)+gca*minf*(V-1.d0));\n F(2) = psi*cosh((V-v3)/(2.d0*v4))*(ninf-N);\n END SUBROUTINE FUNC\n SUBROUTINE STPNT(NDIM,U,PAR,T)\n! ---------- ----- \n IMPLICIT NONE\n INTEGER, INTENT(IN) :: NDIM\n DOUBLE PRECISION, INTENT(INOUT) :: U(NDIM),PAR(*)\n DOUBLE PRECISION, INTENT(IN) :: T\n ! initial values for the bifurcation parameters \n PAR(1)=-0.5d0\n\t PAR(2)=-0.1375\n ! initial conditions\n U(1)=-0.18484d0\n U(2)=0.37227d0\n END SUBROUTINE STPNT\n SUBROUTINE BCND \n END SUBROUTINE BCND\n SUBROUTINE ICND \n END SUBROUTINE ICND\n SUBROUTINE FOPT \n END SUBROUTINE FOPT\n SUBROUTINE PVLS\n END SUBROUTINE PVLS\n", "meta": {"hexsha": "8d95832c94a5da44444c3f1bab17f3523c1b53ef", "size": 1834, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "AUTO_Code/dimless.f", "max_stars_repo_name": "hamfat/Massey_Thesis", "max_stars_repo_head_hexsha": "89b880177492ac503118c222e7e97d1c11431cf8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "AUTO_Code/dimless.f", "max_issues_repo_name": "hamfat/Massey_Thesis", "max_issues_repo_head_hexsha": "89b880177492ac503118c222e7e97d1c11431cf8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "AUTO_Code/dimless.f", "max_forks_repo_name": "hamfat/Massey_Thesis", "max_forks_repo_head_hexsha": "89b880177492ac503118c222e7e97d1c11431cf8", "max_forks_repo_licenses": ["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.0847457627, "max_line_length": 72, "alphanum_fraction": 0.4956379498, "num_tokens": 682, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942290328345, "lm_q2_score": 0.7549149978955811, "lm_q1q2_score": 0.6720964660367703}} {"text": " subroutine zone_setup(nx, nxmax, ny, nz)\n\n include 'header.h'\n include 'mpi_stuff.h'\n\n integer nx(*), nxmax(*), ny(*), nz(*)\n\n integer i, j, zone_no\n integer id_west, id_east, jd_south, jd_north\n double precision x_r, y_r, x_smallest, y_smallest\n\n if (dabs(ratio-1.d0) .gt. 1.d-10) then\n\nc compute zone stretching only if the prescribed zone size ratio \nc is substantially larger than unity \n\n x_r = dexp(dlog(ratio)/(x_zones-1))\n y_r = dexp(dlog(ratio)/(y_zones-1))\n x_smallest = dble(gx_size)*(x_r-1.d0)/(x_r**x_zones-1.d0)\n y_smallest = dble(gy_size)*(y_r-1.d0)/(y_r**y_zones-1.d0)\n\nc compute tops of intervals, using a slightly tricked rounding\nc to make sure that the intervals are increasing monotonically\nc in size\n\n do i = 1, x_zones\n x_end(i) = x_smallest*(x_r**i-1.d0)/(x_r-1.d0)+0.45d0\n end do\n\n do j = 1, y_zones\n y_end(j) = y_smallest*(y_r**j-1.d0)/(y_r-1.d0)+0.45d0\n end do\n \n else\n\nc compute essentially equal sized zone dimensions\n\n do i = 1, x_zones\n x_end(i) = (i*gx_size)/x_zones\n end do\n\n do j = 1, y_zones\n y_end(j) = (j*gy_size)/y_zones\n end do\n\n endif\n\n x_start(1) = 1\n do i = 1, x_zones\n if (i .ne. x_zones) x_start(i+1) = x_end(i) + 1\n x_size(i) = x_end(i) - x_start(i) + 1\n end do\n\n y_start(1) = 1\n do j = 1, y_zones\n if (j .ne. y_zones) y_start(j+1) = y_end(j) + 1\n y_size(j) = y_end(j) - y_start(j) + 1\n end do\n\n if (npb_verbose .gt. 1 .and. myid .eq. root) then\n write (*,98)\n endif\n 98 format(/' Zone sizes:')\n\n do j = 1, y_zones\n do i = 1, x_zones\n zone_no = (i-1)+(j-1)*x_zones+1\n nx(zone_no) = x_size(i)\n nxmax(zone_no) = nx(zone_no) + 1 - mod(nx(zone_no),2)\n ny(zone_no) = y_size(j)\n nz(zone_no) = gz_size\n\n id_west = mod(i-2+x_zones,x_zones)\n id_east = mod(i, x_zones)\n jd_south = mod(j-2+y_zones,y_zones)\n jd_north = mod(j, y_zones)\n iz_west (zone_no) = id_west + (j-1)*x_zones + 1\n iz_east (zone_no) = id_east + (j-1)*x_zones + 1\n iz_south(zone_no) = (i-1) + jd_south*x_zones + 1\n iz_north(zone_no) = (i-1) + jd_north*x_zones + 1\n\n if (npb_verbose .gt. 1 .and. myid .eq. root) then\n write (*,99) zone_no, nx(zone_no), ny(zone_no), \n $ nz(zone_no)\n endif\n end do\n end do\n\n 99 format(i5,': ',i5,' x',i5,' x',i5)\n\n return\n end\n\n\n subroutine zone_starts(num_zones, nx, nxmax, ny, nz, \n & start1, start5,\n $ qstart_west, qstart_east,\n $ qstart_south, qstart_north)\n\n include 'header.h'\n include 'mpi_stuff.h'\n\n integer num_zones\n integer nx(*), nxmax(*), ny(*), nz(*)\n dimension start1(*), start5(*), qstart_west(*), \n $ qstart_east(*), qstart_south(*), qstart_north(*)\n\n integer zone, zone_size, iz, ip, zone2, ig, id, itmp\n integer x_face_size, y_face_size\n integer ip_west, ip_east, ip_south, ip_north\n\n do iz = 1, proc_num_zones\n zone = proc_zone_id(iz)\n zone_size = nxmax(zone)*ny(zone)*nz(zone)\n if (iz .eq. 1) then\n start1(iz) = 1\n start5(iz) = 1\n endif\n if (iz .ne. proc_num_zones) then\n start1(iz+1) = start1(iz) + zone_size\n start5(iz+1) = start5(iz) + zone_size*5\n else\n if (start1(iz)+zone_size-1 .gt. proc_max_size) then\n write(*,50) zone,proc_max_size,start1(iz)+zone_size-1\n call mpi_abort(MPI_COMM_WORLD, ierror)\n stop\n endif\n endif\n 50 format(' Error in size: zone',i5,' proc_max_size',i10,\n & ' access_size',i10)\n enddo\n\nc ... for 'qbc_in'\n qoffset = 1\n do 10 ip = 0, num_procs-1\n\n if (ip .eq. myid) goto 10\n\n do 15 zone = 1, num_zones\n x_face_size = (ny(zone)-2)*(nz(zone)-2)*5\n y_face_size = (nx(zone)-2)*(nz(zone)-2)*5\n\n zone2 = iz_west(zone)\n ip_east = zone_proc_id(zone)\n if (ip_east .eq. ip .and. zone_proc_id(zone2) .lt. 0) then\n qstart2_east(zone2) = qoffset\n qoffset = qoffset + x_face_size\n endif\n\n zone2 = iz_east(zone)\n ip_west = zone_proc_id(zone)\n if (ip_west .eq. ip .and. zone_proc_id(zone2) .lt. 0) then\n qstart2_west(zone2) = qoffset\n qoffset = qoffset + x_face_size\n endif\n\n zone2 = iz_south(zone)\n ip_north = zone_proc_id(zone)\n if (ip_north .eq. ip .and. zone_proc_id(zone2) .lt. 0) then\n qstart2_north(zone2) = qoffset\n qoffset = qoffset + y_face_size\n endif\n\n zone2 = iz_north(zone)\n ip_south = zone_proc_id(zone)\n if (ip_south .eq. ip .and. zone_proc_id(zone2) .lt. 0) then\n qstart2_south(zone2) = qoffset\n qoffset = qoffset + y_face_size\n endif\n 15 continue\n\n 10 continue\n\nc ... for 'qbc_out'\n qoffset = 1\n do 20 ip = 0, num_procs-1\n\n if (ip .eq. myid) goto 25\n\n do 30 zone = 1, num_zones\n if (zone_proc_id(zone) .ge. 0) goto 30\n\n x_face_size = (ny(zone)-2)*(nz(zone)-2)*5\n y_face_size = (nx(zone)-2)*(nz(zone)-2)*5\n\n ip_west = zone_proc_id(iz_west(zone))\n if (ip_west .eq. ip) then\n qstart_west(zone) = qoffset\n qoffset = qoffset + x_face_size\n endif\n\n ip_east = zone_proc_id(iz_east(zone))\n if (ip_east .eq. ip) then\n qstart_east(zone) = qoffset\n qoffset = qoffset + x_face_size\n endif\n\n ip_south = zone_proc_id(iz_south(zone))\n if (ip_south .eq. ip) then\n qstart_south(zone) = qoffset\n qoffset = qoffset + y_face_size\n endif\n\n ip_north = zone_proc_id(iz_north(zone))\n if (ip_north .eq. ip) then\n qstart_north(zone) = qoffset\n qoffset = qoffset + y_face_size\n endif\n 30 continue\n\n 25 qcomm_size(ip+1) = qoffset - 1\n 20 continue\n\nc ... for intra-process zone copy\n do 40 zone = 1, num_zones\n if (zone_proc_id(zone) .ge. 0) goto 40\n\n ip_west = zone_proc_id(iz_west(zone))\n ip_east = zone_proc_id(iz_east(zone))\n ip_south = zone_proc_id(iz_south(zone))\n ip_north = zone_proc_id(iz_north(zone))\n\n x_face_size = (ny(zone)-2)*(nz(zone)-2)*5\n y_face_size = (nx(zone)-2)*(nz(zone)-2)*5\n\n if (ip_west .lt. 0) then\n qstart_west(zone) = qoffset\n qoffset = qoffset + x_face_size\n endif\n if (ip_east .lt. 0) then\n qstart_east(zone) = qoffset\n qoffset = qoffset + x_face_size\n endif\n if (ip_south .lt. 0) then\n qstart_south(zone) = qoffset\n qoffset = qoffset + y_face_size\n endif\n if (ip_north .lt. 0) then\n qstart_north(zone) = qoffset\n qoffset = qoffset + y_face_size\n endif\n 40 continue\n\nc ... set up cyclic communication group\n iz = 1\n do while (iz .lt. myid)\n iz = iz * 2\n enddo\n if (iz .gt. myid) iz = iz / 2\n\n do ig = 1, num_procs\n pcomm_group(ig) = ig - 1\n enddo\n do ig = num_procs+1, num_procs2\n pcomm_group(ig) = -1\n enddo\n\n id = 0\n do while (iz .ge. 1)\n if (id+iz .gt. myid) goto 45\n do ig = 1, num_procs, iz*2\n do ip = ig, ig+iz-1\n itmp = pcomm_group(ip)\n pcomm_group(ip) = pcomm_group(ip+iz)\n pcomm_group(ip+iz) = itmp\n enddo\n enddo\n id = id + iz\n 45 iz = iz/2\n enddo\n\n ip = 1\n do ig = 1, num_procs\n do while (pcomm_group(ip) .lt. 0)\n ip = ip + 1\n enddo\n pcomm_group(ig) = pcomm_group(ip)\n ip = ip + 1\n enddo\n\n if (npb_verbose .gt. 1) then\n do iz = 1, proc_num_zones\n zone = proc_zone_id(iz)\n write(*,60) myid, iz, zone, start1(iz), start5(iz)\n enddo\n write(*,70) myid, qoffset-1\n 60 format(' myid',i5,' iz=',i5,' zone=',i5,\n & ' start1=',i10,' start5=',i10)\n 70 format(' myid',i5,' qcomm_size=',i10)\n\n do ig = 1, num_procs\n ip = pcomm_group(ig) + 1\n if (ip .eq. 1) then\n qoffset = qcomm_size(ip)\n else\n qoffset = qcomm_size(ip) - qcomm_size(ip-1)\n endif\n write(*,80) myid, ip-1, qoffset, qcomm_size(ip)\n enddo\n 80 format(' myid',i5,' proc',i5,' qcomm_size',2(1x,i10))\n endif\n\n return\n end\n", "meta": {"hexsha": "f025fd5c996f7e8103287504253061cdd3adea4c", "size": 9187, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "examples/NPB3.2-MZ-MPI/SP-MZ/zone_setup.f", "max_stars_repo_name": "robert-mijakovic/readex-ptf", "max_stars_repo_head_hexsha": "5514b0545721ef27de0426a7fa0116d2e0bb5eef", "max_stars_repo_licenses": ["BSD-3-Clause-No-Nuclear-License-2014", "BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-10T09:59:37.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-10T09:59:37.000Z", "max_issues_repo_path": "examples/NPB3.2-MZ-MPI/SP-MZ/zone_setup.f", "max_issues_repo_name": "robert-mijakovic/readex-ptf", "max_issues_repo_head_hexsha": "5514b0545721ef27de0426a7fa0116d2e0bb5eef", "max_issues_repo_licenses": ["BSD-3-Clause-No-Nuclear-License-2014", "BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-04-21T07:57:32.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-14T08:05:41.000Z", "max_forks_repo_path": "examples/NPB3.2-MZ-MPI/SP-MZ/zone_setup.f", "max_forks_repo_name": "robert-mijakovic/readex-ptf", "max_forks_repo_head_hexsha": "5514b0545721ef27de0426a7fa0116d2e0bb5eef", "max_forks_repo_licenses": ["BSD-3-Clause-No-Nuclear-License-2014", "BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-20T03:04:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-20T03:04:32.000Z", "avg_line_length": 30.1213114754, "max_line_length": 72, "alphanum_fraction": 0.5108305214, "num_tokens": 2937, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942348544447, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6720964606134683}} {"text": " program generate_bathymetry\n implicit none\n\n integer, parameter :: im = 500\n integer, parameter :: jm = 90\n integer :: i,j\n real(8) :: dx,dy,x,y,h0,h02,tht,cs,sn,pi, &\n ytmp,xp,yp,ctmp1,ctmp2,depth(im,jm) \n character(len=80) :: test_case\n\n pi = 2.*acos(0.)\n\n test_case = 'landslide'\n\n if(trim(test_case)=='submerged_bar') then\n dx = 0.02\n do j = 1,jm\n do i = 1,im\n x = (i-1)*dx\n if(x<=6.0) then\n depth(i,j) = 0.4\n elseif(x>6.0.and.x<=12.0) then\n depth(i,j) = 0.4-(x-6.0)/20.0\n elseif(x>12.0.and.x<=14.0) then\n depth(i,j) = 0.1\n elseif(x>14.0.and.x<17.0) then\n depth(i,j) = 0.4-(17.0-x)/10.0\n else\n depth(i,j) = 0.4\n endif\n enddo\n enddo\n elseif(trim(test_case)=='landslide') then\n dx = 0.02\n do j = 1,jm\n do i = 1,im\n x = (i-1)*dx+0.5*dx\n if(x<=1.5/tan(15.*pi/180.)+0.1) then\n depth(i,j) = (x-0.1)*tan(15.*pi/180.)\n else\n depth(i,j) = 1.5\n endif\n enddo\n enddo\n elseif(trim(test_case)=='breaking_solitary_wave') then\n dx = 0.02\n do j = 1,jm\n do i = 1,im\n x = (i-1)*dx\n if(x<=4.0) then\n depth(i,j) = 0.21\n else\n depth(i,j) = 0.21-(x-4.0)/20.\n endif\n enddo\n enddo\n elseif(trim(test_case)=='dam_break') then\n dx = 0.05\n do j = 1,jm\n do i = 1,im\n x = (i-1)*dx\n if(x<=25.5) then\n depth(i,j) = 0.01\n elseif(x>25.5.and.x<=28.5) then\n depth(i,j) = -(x-25.5)*0.4/3.0\n elseif(x>28.5.and.x<=31.5) then\n depth(i,j) = -(31.5-x)*0.4/3.0\n elseif(x>31.5) then\n depth(i,j) = 0.01\n endif\n enddo\n enddo\n elseif(trim(test_case)=='tidal_wave') then\n dx = 7.5\n do j = 1,jm\n do i = 1,im\n x = (i-1)*dx\n if(abs(x-750)<=187.5) then\n depth(i,j) = 8.0\n else\n depth(i,j) = 16.0\n endif\n enddo\n enddo\n elseif(trim(test_case)=='Berkhoff_Shoal') then\n dx = 0.025\n dy = 0.05\n h0 = .45\n h02 = 0.07\n tht = 70.*3.14159/180\n cs = cos(tht)\n sn = sin(tht)\n ytmp = 5.84-(h0-h02)/.02\n do i = 1, im\n do j = 1, jm\n x = float(i-1)*dx- 12.0\n y = float(j-1)*dy- 10.0\n xp = x*cs+y*sn\n yp = -x*sn+y*cs\n ctmp1 = (xp/4.)**2+(yp/3.)**2\n ctmp2 = (xp/5.)**2+(yp/3.75)**2\n if(yp.ge.5.84) then\n depth(i,j) = h0\n elseif (yp.le.ytmp) then\n depth(i,j) = h02\n elseif (ctmp1.gt.1.) then\n depth(i,j) = h0-0.02*(5.84-yp)\n else\n depth(i,j) = .75-.02*(5.84-yp)-0.5*sqrt(1.-ctmp2)\n endif\n enddo\n enddo\n endif\n\n open(11,file='depth.txt')\n do j = 1,jm\n write(11,'(5000f8.4)') (depth(i,j),i=1,im)\n enddo\n close(11)\n\n end\n", "meta": {"hexsha": "21152b480300c9fe88aca2a19c18f198b1666ee1", "size": 2955, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "extras/mkdep.f90", "max_stars_repo_name": "NHWAVE/NHWAVE", "max_stars_repo_head_hexsha": "f49633466fc054dd62bc02145839a7590a795e4a", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2017-03-14T12:39:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-22T14:19:29.000Z", "max_issues_repo_path": "extras/mkdep.f90", "max_issues_repo_name": "NHWAVE/NHWAVE", "max_issues_repo_head_hexsha": "f49633466fc054dd62bc02145839a7590a795e4a", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 27, "max_issues_repo_issues_event_min_datetime": "2016-11-07T18:56:44.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-09T13:11:44.000Z", "max_forks_repo_path": "extras/mkdep.f90", "max_forks_repo_name": "NHWAVE/NHWAVE", "max_forks_repo_head_hexsha": "f49633466fc054dd62bc02145839a7590a795e4a", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2017-02-06T17:19:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-22T02:13:32.000Z", "avg_line_length": 24.2213114754, "max_line_length": 59, "alphanum_fraction": 0.4456852792, "num_tokens": 1183, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942377652497, "lm_q2_score": 0.7549149758396752, "lm_q1q2_score": 0.6720964529927556}} {"text": "! spectral.f90 - Rayleigh iteration solver for eigenvalue problem\n\nprogram spectral\n use integrator\n use utils\n implicit none\n\n integer, parameter :: n = 150\n real, parameter :: ell = 1.0\n real, parameter :: pi = 3.1415926535897932384626433832795028842Q0\n real, dimension(n) :: x, theta, psi\n real, dimension (n,n) :: L, H\n real :: lambda\n real :: lambdas(n)\n\n ! Initialize spectral operators\n call init_grid()\n call init_l()\n\n print *\n print \"(a)\", \"Q4. Spectral-based eigenvalues (harmonic potential)\"\n call find_eigenvalues()\n print \"(f19.12)\", lambdas(1:10)\n call plot_wavefunctions(\"q4\", lambdas(1:10))\n\n V => V_anharmonic\n print *\n print \"(a)\", \"Q5. Spectral-based eigenvalues (anharmonic potential)\"\n call find_eigenvalues()\n print \"(f19.12)\", lambdas(1:10)\n call plot_wavefunctions(\"q5\", lambdas(1:10))\n\ncontains\n\n subroutine find_eigenvalues()\n ! TODO properly encapsulate local variables\n integer :: i\n\n ! Hamiltonian in static Schr\u00f6dinger equation\n H = -L/2.0\n do i = 1, n\n H(i,i) = -L(i,i)/2.0 + V(x(i))\n end do\n\n psi = 1.0 / (1.0 + x*x)\n\n ! Relax using Rayleigh's iteration\n do i = 1,64\n lambda = dot_product(psi,matmul(H,psi))/dot_product(psi,psi)\n psi = lsolve(psi,lambda)\n psi = psi/sqrt(dot_product(psi,psi))\n end do\n\n lambdas = real_eigenvalues(H)\n call partial_sort(lambdas)\n end subroutine\n\n ! initialize the collocation grid\n subroutine init_grid()\n integer i\n\n forall (i=1:n) theta(i) = pi*(n-i+0.5)/n\n x = ell/tan(theta)\n end subroutine\n\n ! evaluate rational Chebyshev basis on a grid theta\n subroutine evalb(n, pts, theta, Tn, Tnx, Tnxx)\n integer n, pts\n real, dimension(pts), intent(in) :: theta\n real, dimension(pts), intent(out), optional :: Tn, Tnx, Tnxx\n\n ! Chebyshev basis and its derivatives\n if (present(Tn)) Tn = cos(n*theta)\n if (present(Tnx)) Tnx = n * sin(n*theta) * sin(theta)**2/ell\n if (present(Tnxx)) Tnxx = -n * sin(theta)**3 * &\n (n*cos(n*theta)*sin(theta) + 2.0*sin(n*theta)*cos(theta)) / ell**2\n end subroutine evalb\n\n ! initialize linear spectral derivative operator\n subroutine init_l()\n integer :: i, pivot(n), status\n real :: A(n,n), B(n,n), Tn(n), Tnxx(n)\n\n ! evaluate basis and differential operator values on collocation grid\n do i = 1,n\n call evalb(i-1, n, theta, Tn=Tn, Tnxx=Tnxx)\n A(i, :) = Tn\n B(i, :) = Tnxx\n end do\n\n ! find linear operator matrix\n status = 0; select case (kind(A))\n case(4); call sgesv(n, n, A, n, pivot, B, n, status)\n case(8); call dgesv(n, n, A, n, pivot, B, n, status)\n case default; call abort\n end select\n\n ! bail at first sign of trouble\n if (status /= 0) call abort\n\n L = transpose(B)\n end subroutine\n\n ! Rayleigh's iteration solving eigenvalue problem:\n ! [-1/2 d^2/dx^2 + V(x)] psi(x) = lambda psi(x)\n function lsolve(psi, lambda)\n real lambda, psi(n), lsolve(n), A(n,n), B(n)\n integer i, pivot(n), status\n\n ! linear improvement inflating eigenvector\n A = H\n forall (i=1:n) A(i,i) = H(i,i) - lambda\n B = psi\n\n ! find linear operator matrix\n status = 0; select case (kind(A))\n case(4); call sgesv(n, 1, A, n, pivot, B, n, status)\n case(8); call dgesv(n, 1, A, n, pivot, B, n, status)\n case default; call abort\n end select\n\n ! bail at first sign of trouble\n if (status /= 0) call abort\n\n lsolve = B\n end function\n\nend program\n", "meta": {"hexsha": "0f188381bf2e7176cfd3950cefd066851f67ee84", "size": 3445, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/phys395_hw5/spectral.f90", "max_stars_repo_name": "YodaEmbedding/experiments", "max_stars_repo_head_hexsha": "567c6a1c18fac2d951fe2af54aaa4917b7d529d2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fortran/phys395_hw5/spectral.f90", "max_issues_repo_name": "YodaEmbedding/experiments", "max_issues_repo_head_hexsha": "567c6a1c18fac2d951fe2af54aaa4917b7d529d2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/phys395_hw5/spectral.f90", "max_forks_repo_name": "YodaEmbedding/experiments", "max_forks_repo_head_hexsha": "567c6a1c18fac2d951fe2af54aaa4917b7d529d2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.7054263566, "max_line_length": 73, "alphanum_fraction": 0.6290275762, "num_tokens": 1127, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942173896131, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6720964425199438}} {"text": "c cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\n subroutine ricbes(nn,y,bj,bn,dj,dn)\nc ================================================================\nc\nc computes spherical bessel functions j and n and its derivatives\nc\n implicit none\nc\nc\n integer nn,l,k,i,nm\nc\n real*8 flm,fll\nc\n complex*16 a,aj,x,y\n complex*16 as,ac,xinv,x2\nc\n complex*16 bj(nn),bn(nn),dj(nn),dn(nn)\nc\nc\n x=y\nc\n if (abs(x).eq.0.0d0) then\n write(*,*) ' x equals to zero'\n call fstop('ricbes')\n endif\nc\n as = sin(x)\n ac = cos(x)\n bj(1) = as\n dj(1) = ac\n dn(1) = exp((0.d0,1.d0)*x)\n bn(1) = (0.d0,-1.d0)*dn(1)\n if(nn.eq.1) return\n xinv = 1.d0/x\nc Forward recursion for small L\n1 k=(int(0.75*(abs(dreal(x))+abs(dimag(x))))+2)/4+1\n if(k.gt.1) then\n\t if (k.gt.nn) k=nn\n\t bj(2)=bj(1)*xinv-ac\n\t do l = 3, k\n flm = l+l-3\n\t bj(l) = flm*bj(l-1)*xinv-bj(l-2)\n\t enddo\n endif\n\n if(k.lt.nn) then\nc Backward recursion from very large L down to L=k\n a=bj(k)\n nm=nn*4\n aj=2*nm+1\n x2=x*x\n do l = nm, nn+2, -1\n\t aj=(2*l-1)-x2/aj\n enddo\n bj(nn)=(2*nn+1)*aj*xinv-x\n bj(nn-1)=(2*nn-1)*bj(nn)*xinv-aj\n do l = nn-1, k+1, -1\n\t bj(l-1)=(2*l-1)*bj(l)*xinv-bj(l+1)\n enddo\nc scale to give correct bj(k)\n aj=a/bj(k)\n do l = k+1, nn\n\t bj(l)=aj*bj(l)\n enddo\n bj(k)=a\n endif\n\nc Find bn using forward recursion\n bn(2) = bn(1)*xinv - dn(1)\n dj(2) = bj(1)-bj(2)*xinv\n dn(2) = bn(1)-bn(2)*xinv\nc\nc ================================================================\nc recursion relations\nc ================================================================\n do l=3,nn\n flm = l+l-3\n bn(l) = flm*bn(l-1)*xinv-bn(l-2)\n fll = l-1\n dj(l) = bj(l-1)-fll*bj(l)*xinv\n dn(l) = bn(l-1)-fll*bn(l)*xinv\n enddo\nc\n return\n end\n", "meta": {"hexsha": "688127e47efd1a3dcea08c17b4ea25da2f99d807", "size": 2014, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/Misc/ricbes.f", "max_stars_repo_name": "rdietric/lsms", "max_stars_repo_head_hexsha": "8d0d5f01186abf9a1cc54db3f97f9934b422cf92", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2020-01-05T20:05:31.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T09:08:01.000Z", "max_issues_repo_path": "src/Misc/ricbes.f", "max_issues_repo_name": "rdietric/lsms", "max_issues_repo_head_hexsha": "8d0d5f01186abf9a1cc54db3f97f9934b422cf92", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2019-07-30T13:59:18.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T17:43:35.000Z", "max_forks_repo_path": "lsms/src/Misc/ricbes.f", "max_forks_repo_name": "hkershaw-brown/MuST", "max_forks_repo_head_hexsha": "9db4bc5061c2f2c4d7dfd92f53b4ef952602c070", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2020-02-11T17:04:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-28T09:23:46.000Z", "avg_line_length": 23.4186046512, "max_line_length": 70, "alphanum_fraction": 0.4433962264, "num_tokens": 749, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.7549149758396752, "lm_q1q2_score": 0.6720964398082929}} {"text": " real function psolR(solD,v,w,x,y)\r\nc\r\nc + + + PURPOSE + + +\r\nc Computes potential solar radiation on a sloping surface, in cal/cm2/day\r\nc\r\nc Called from sunmap.\r\nc Author(s): \r\nc Reference: Swift, 1976 \"Algorithm for solar radiation on Mountain slopes\"\r\nc\r\nc Date recoded: 11/07/2006.\r\nc Recoded by: S. Dun\r\nc\r\nc + + + KEYWORDS + + +\r\nc\r\nc + + + ARGUMENT DECLARATIONS + + +\r\n real solD,v,w,x,y\r\nc\r\nc + + + ARGUMENT DEFINITIONS + + +\r\nc solD - declination of sun\r\nc v - time offset in hour angle between actual annd equivalent slope\r\nc w - lattitude of eqivalent slope\r\nc\r\nc + + + PARAMETERS + + +\r\nc\r\nc + + + COMMON BLOCKS + + +\r\nc\r\nc\r\nc + + + LOCAL DEFINITIONS + + +\r\nc\r\nc + + + FUNCTION DECLARATIONS + + +\r\n\r\nc + + + END SPECIFICATIONS + + +\r\nc\r\n psolR = (sin(solD) * sin(w) * (x - y) *12.0 / 3.141593)\r\n 1 + (cos(solD) * cos(w) * (sin(x + v) - sin(y + v))\r\n 2 * 12. / 3.141593)\r\nc\r\n return\r\n end\r\n", "meta": {"hexsha": "34dbf8f23f1ccbd51406a724d0ab197f72d44782", "size": 1012, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/wepp2010.1/psolr.for", "max_stars_repo_name": "jarad/dep", "max_stars_repo_head_hexsha": "fe73982f4c70039e1a31b9e8e2d9aac31502f803", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-11-26T17:49:19.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-26T17:49:19.000Z", "max_issues_repo_path": "src/wepp2010.1/psolr.for", "max_issues_repo_name": "jarad/dep", "max_issues_repo_head_hexsha": "fe73982f4c70039e1a31b9e8e2d9aac31502f803", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 54, "max_issues_repo_issues_event_min_datetime": "2018-12-12T18:02:31.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T19:14:25.000Z", "max_forks_repo_path": "src/wepp2010.1/psolr.for", "max_forks_repo_name": "akrherz/idep", "max_forks_repo_head_hexsha": "7189a26fbcec3d8c3cc7d7015107b8fb6c5f6a45", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-03-02T22:59:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-09T15:49:00.000Z", "avg_line_length": 25.3, "max_line_length": 80, "alphanum_fraction": 0.5335968379, "num_tokens": 338, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566341962906709, "lm_q2_score": 0.7025300511670689, "lm_q1q2_score": 0.6720642708682529}} {"text": "! Example 4.1 in Xue 2000\n!\n! The tiled code by Xue and by Pips give the same correct results,\n! but they are different.\n\n program tiling07\n\n real A(-2:9,-1:6)\n\n do 100 i = -2, 9\n do j = -1, 6\n a(i,j) = 10*(i+2)+j+1\n enddo\n 100 continue\n\n do i = 1, 9\n do j = 1, 5\n a(i,j) = a(i,j-2)+a(i-3,j+1)\n enddo\n enddo\n\n print *, a(5,2), a(6,3)\n\n! Reinitialize A\n\n do i = -2, 9\n do j = -1, 6\n a(i,j) = 10*(i+2)+j+1\n enddo\n enddo\n\n! Use tiled code from Xue\n\n do it = 0, 2\n do jt = max(it-1,0), (it+4)/2\n do i = 3*it+1, 3*it+3\n do j = max(-it+2*jt+1,1), min((-it+6*jt+9)/3,5)\n a(i,j) = a(i,j-2)+a(i-3,j+1)\n enddo\n enddo\n enddo\n enddo\n\n print *, a(5,2), a(6,3)\n\n end\n", "meta": {"hexsha": "23ffa99788ae788dd914ab88cba421581b83a074", "size": 898, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "packages/PIPS/validation/Transformations/Tiling.sub/tiling07.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/Transformations/Tiling.sub/tiling07.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/Transformations/Tiling.sub/tiling07.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": 19.1063829787, "max_line_length": 70, "alphanum_fraction": 0.3964365256, "num_tokens": 359, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117855317474, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.6720069917299027}} {"text": "!! how does Fortran handle NaN vis-a-vis max and min\n!! https://groups.google.com/forum/#!topic/comp.lang.fortran/MwVfrvUowHU\n\nuse, intrinsic :: ieee_arithmetic\nuse, intrinsic :: iso_fortran_env, stderr=>error_unit\nimplicit none\n\nreal :: A(4), x, y, nan, inf\n\nnan = ieee_value(0., ieee_quiet_nan)\ninf = ieee_value(0., ieee_positive_inf)\n\nif(.not.ieee_is_nan(nan)) then\n write(stderr,*) 'NaN: ',nan\n error stop 'NaN not working correctly'\nendif\n\nA = [0., 1., 2., nan]\nprint *, 'maximum of ',A, 'is', maxval(A)\nif(maxval(A) /= 2) error stop 'maxval() not working with NaN'\n\nx = nan\ny = 1.\n\nprint *, 'maximum of',x,'and',y,'is',max(x,y)\nif (max(x,y) /= 1) error stop 'max() not working with NaN'\n\n! Gfortran, Flang 7 say inf; PGI, Intel say NaN\nprint *,'max of inf() and NaN is', max(inf, nan)\n\n\nend program\n", "meta": {"hexsha": "b6c38919154bca1a7debc055fc6b9c66060250b4", "size": 807, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "debug/maxmin_nan.f90", "max_stars_repo_name": "volpatto/fortran2018-examples", "max_stars_repo_head_hexsha": "4944b5ab80b05e09c4a4d4c9b5a9f7ab8afa8f2c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-06-09T16:45:35.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-09T16:45:35.000Z", "max_issues_repo_path": "debug/maxmin_nan.f90", "max_issues_repo_name": "volpatto/fortran2018-examples", "max_issues_repo_head_hexsha": "4944b5ab80b05e09c4a4d4c9b5a9f7ab8afa8f2c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "debug/maxmin_nan.f90", "max_forks_repo_name": "volpatto/fortran2018-examples", "max_forks_repo_head_hexsha": "4944b5ab80b05e09c4a4d4c9b5a9f7ab8afa8f2c", "max_forks_repo_licenses": ["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.4545454545, "max_line_length": 72, "alphanum_fraction": 0.6716232962, "num_tokens": 270, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.86153820232079, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6719936811079025}} {"text": " PARAMETER (NSTEP=20)\n DIMENSION PHI(0:NSTEP)\n\n H=1./NSTEP\n\n100 PRINT *, ' Enter step size ( .eq. 0 to stop)'\n READ *, DT\n IF (DT .EQ. 0.) STOP\n DTH=DT/H**2\n \n DO 10 IX=0,NSTEP\n X=IX*H\n PHI(IX)=X*(1.-X)\n 10 CONTINUE\n CALL NORM(PHI,NSTEP)\n\n DO 20 ITER=1,100\n POLD=0.\n DO 30 IX=1,NSTEP-1\n PNEW=PHI(IX)+DTH*(POLD+PHI(IX+1)-2*PHI(IX))\n POLD=PHI(IX)\n PHI(IX)=PNEW\n30 CONTINUE\n CALL NORM(PHI,NSTEP)\n\n IF (MOD(ITER,4) .EQ. 0) THEN\n E=0.\n DO 50 IX=1,NSTEP\n E=E+(PHI(IX)-PHI(IX-1))**2\n50 CONTINUE\n E=E/(H)\n PRINT *,' iteration = ', ITER, ' energy = ', E\n END IF\n20 CONTINUE\n GOTO 100\n END\n\n SUBROUTINE NORM(PHI,NSTEP)\n DIMENSION PHI(0:NSTEP)\n \n XNORM=0.\n DO 10 IX=0,NSTEP\n XNORM=XNORM+PHI(IX)**2\n10 CONTINUE\n XNORM=SQRT(NSTEP/XNORM)\n DO 20 IX=0,NSTEP\n PHI(IX)=PHI(IX)*XNORM\n20 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "842f4cf2041a2342f7a62e6e2266754e863a9977", "size": 1121, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "Source-Koonin-Code/WarmUp/chap7c.for", "max_stars_repo_name": "ajz34/Comp-Phys-Koonin", "max_stars_repo_head_hexsha": "9fc371bdb44b7030025d254eda040a55bfa3b7cd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-10-29T12:21:38.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-31T17:03:43.000Z", "max_issues_repo_path": "Source-Koonin-Code/WarmUp/chap7c.for", "max_issues_repo_name": "ajz34/Comp-Phys-Koonin", "max_issues_repo_head_hexsha": "9fc371bdb44b7030025d254eda040a55bfa3b7cd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Source-Koonin-Code/WarmUp/chap7c.for", "max_forks_repo_name": "ajz34/Comp-Phys-Koonin", "max_forks_repo_head_hexsha": "9fc371bdb44b7030025d254eda040a55bfa3b7cd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.9803921569, "max_line_length": 59, "alphanum_fraction": 0.4495985727, "num_tokens": 402, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381952105441, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.6719936799680372}} {"text": "module polynomial_module\n\nuse globalvars_module\nimplicit none\n\n\ncontains\n\n!========================================================\nsubroutine polyinitialize(pl,n,coeffarray)\n\n\t integer :: n\n\t real*8 :: coeffarray(:)\n\t integer :: i\n\n\t type(polynomial) :: pl\n\n\t pl%n=n\n\t allocate(pl%coeffs(n+1))\n\n\t do i=1,n+1\n\t \tpl%coeffs(i)=coeffarray(i)\n\t enddo\n\nend subroutine\n!========================================================\nsubroutine zeropolyinitialize(pl,n)\n\n\t\tinteger,intent(in) :: n\n\t\ttype(polynomial) :: pl\n\n\t\tinteger :: i\n\t\treal*8,allocatable :: coeffarray(:)\n\n\t\tallocate(coeffarray(n+1))\n\n\t\tdo i=1,n+1\n\t\t\tcoeffarray(i)=0.d0\n\t\tenddo\n\n\t\tcall polyinitialize(pl,n,coeffarray)\t\n\nend subroutine zeropolyinitialize\n!========================================================\nsubroutine polymultiply(p1,p2,pout)\n\n\t\ttype(polynomial), intent(in) :: p1,p2\n\t\ttype(polynomial), intent(out) :: pout\n\t\tinteger :: i,j\n\n\t\tcall zeropolyinitialize(pout,p1%n+p2%n)\n\n\t\tdo i=1,p1%n+1\n\t\tdo j=1,p2%n+1\n\t\t\tpout%coeffs(i+j-1)=pout%coeffs(i+j-1)&\n\t\t\t\t\t+p1%coeffs(i)*p2%coeffs(j)\n\t\tenddo\n\t\tenddo\n\nend subroutine polymultiply\n!========================================================\nsubroutine polyderivative(pin,pout)\n\n\ttype(polynomial),intent(in) :: pin\n\ttype(polynomial),intent(out) :: pout\n\n\tinteger :: i\n\n\tpout%n=pin%n-1\n\tallocate(pout%coeffs(pout%n+1))\n\n\tdo i=1,pout%n+1\n\t\tpout%coeffs(i)=pin%coeffs(i+1)*i\n\t\t!print *,\"coeff of \",i,\":\",pout%coeffs(i)\n\tenddo\t\n\nend subroutine polyderivative\n!========================================================\nsubroutine printpoly(pl)\n\n\t\ttype(polynomial) :: pl\n\t\tinteger :: i\n\n\t\tprint *,\"order of pl:\",pl%n\n\n\t\tdo i=1,pl%n\n\t\t\twrite(*,'(F4.2,A,I2,A)',advance='no')pl%coeffs(i),\"x^\",(i-1),\"+\"\n\t\tenddo\n\t\twrite(*,'(F8.2,A,I2)')pl%coeffs(i),\"x^\",(i-1)\n\nend subroutine printpoly\n!========================================================\nsubroutine createlagrangepoly(x,np,polyarray)\n\t\t\n\tinteger :: i,j,np\n\treal*8 :: x(np)\n\treal*8 :: dnmtr\n\ttype(polynomial) :: polyarray(np)\n\n\treal*8 :: initcoeff(1)\n\treal*8 :: termcoeff(2)\n\treal*8,allocatable :: lagrcoeffs(:)\n\ttype(polynomial) :: term\n\ttype(polynomial) :: temp\n\ttype(polynomial) :: current\n\n\tcall zeropolyinitialize(term,1)\n\n\tdo i=1,np\n\t\t\n\t\tdnmtr=1.d0\n\t\tdo j=1,np\n\t\t\tif(j .ne. i) then\n\t\t\tdnmtr=dnmtr*(x(i)-x(j))\n\t\t\tendif\n\t\tenddo\n\n\t\tcall zeropolyinitialize(polyarray(i),0)\n\t\tpolyarray(i)%coeffs(1)=1.d0/dnmtr\n\t\tdo j=1,np\n\n\t\t\tif(j .ne. i) then\n\t\t\t\t\n\t\t\t\tterm%coeffs(1)=-x(j)\n\t\t\t\tterm%coeffs(2)=1.d0\n\t\t\t\tcall polymultiply(polyarray(i),term,temp)\n\n\t\t\t\tpolyarray(i)=temp\n\t\t\tendif\n\t\tenddo\n\n\t\tprint *,\"order of polyarray\",i,\"is\",polyarray(i)%n\n\n\tenddo\n\t\t\t\n\nend subroutine createlagrangepoly\n!========================================================\nfunction polyfindval(pl,x) result(total)\n\n\t real*8 :: x,total,pdt\n\t type(polynomial) :: pl\n\t integer :: i\n\n\t total=0.0\n\t pdt=1.0\n\n\t do i=1,pl%n+1\n\n\t \ttotal=total+pl%coeffs(i)*pdt\n\t\tpdt=pdt*x\n\n\t enddo\n\nend function\n!========================================================\nfunction polyfindderval(pl,x) result(total)\n\n\t real*8 :: x,total,pdt\n\t type(polynomial) :: pl\n\t type(polynomial) :: plder\n\t integer :: i\n\n\t call polyderivative(pl,plder)\n\t total=0.0\n\t pdt=1.0\n\n\t do i=1,plder%n+1\n\n\t \ttotal=total+plder%coeffs(i)*pdt\n\t\tpdt=pdt*x\n\n\t enddo\n\nend function\n!========================================================\n\nend module polynomial_module\n", "meta": {"hexsha": "faac44bcc58d6e6613a597e3f22bf10120979bfe", "size": 3481, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "pretreatment_model/src/polynomial.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/polynomial.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/polynomial.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.4469273743, "max_line_length": 67, "alphanum_fraction": 0.5374892272, "num_tokens": 1058, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.86153820232079, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6719936767018263}} {"text": " EXTERNAL FEX\n DOUBLE PRECISION ATOL, RTOL, RWORK, T, TOUT, Y\n DIMENSION Y(4), RWORK(100), IWORK(100)\n NEQ = 4\n Y(1) = 1.\n Y(2) = 0.\n Y(3) = 0.\n Y(4) = 0.\n T = 0.\n TOUT = 10.\n ITOL = 1\n RTOL = 1.D-6\n ATOL = 1.D-6\n ITASK = 1\n ISTATE = 1\n IOPT = 0\n LRW = 100\n LIW = 100\n JT = 2\n DO I = 1,100000\n CALL DLSODA(FEX,NEQ,Y,T,TOUT,ITOL,RTOL,ATOL,ITASK,ISTATE,\n * IOPT,RWORK,LRW,IWORK,LIW,JDUM,JT)\n TOUT = TOUT + 1.\n END DO\n WRITE(*,*) \"T,Y:\", T,Y(1),Y(2),Y(3),Y(4)\n END\n \n SUBROUTINE FEX (NEQ, T, Y, YDOT)\n DOUBLE PRECISION T, Y, YDOT, GL, AL, DTH\n DIMENSION Y(4), YDOT(4)\n GL = -4.905\n AL = 1.25\nC WRITE(*,*)T,Y(1),Y(3)\n DTH = Y(3) - Y(1)\n YDOT(1) = Y(2)\n YDOT(2) = GL * sin(Y(1)) + AL / 2 * DTH\n YDOT(3) = Y(4)\n YDOT(4) = GL * sin(Y(3)) - AL * DTH\n RETURN\n END\n\nc$$$Local Variables:\nc$$$compile-command: \"make -k pendulum\"\nc$$$End:\n", "meta": {"hexsha": "d0af4a21f4b253b2da49623c3bcb56e5cecb042a", "size": 1033, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "duniverse/odepack/tests/pendulum.f", "max_stars_repo_name": "mseri/owl_tutorials", "max_stars_repo_head_hexsha": "d41b92d68fa98fc03742edbd1ca5105d6e0d53c9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "duniverse/odepack/tests/pendulum.f", "max_issues_repo_name": "mseri/owl_tutorials", "max_issues_repo_head_hexsha": "d41b92d68fa98fc03742edbd1ca5105d6e0d53c9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "duniverse/odepack/tests/pendulum.f", "max_forks_repo_name": "mseri/owl_tutorials", "max_forks_repo_head_hexsha": "d41b92d68fa98fc03742edbd1ca5105d6e0d53c9", "max_forks_repo_licenses": ["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.9555555556, "max_line_length": 66, "alphanum_fraction": 0.4472410455, "num_tokens": 455, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381952105442, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6719936755619612}} {"text": "c prog6\nc c.l.lawson and r.j.hanson, jet propulsion laboratory, 1973 jun 15\nc to appear in 'solving least squares problems', prentice-hall, 1974\nc\t demonstrate the use of the subroutine ldp\tfor least\nc distance programming by solving the constrained line data fitting\nc problem of chapter 23.\nc\n dimension e(4,2), f(4), g(3,2), h(3), g2(3,2), h2(3), x(2), z(2),\n 1w(4)\n dimension wldp(21), s(6), t(4)\n integer index(3)\nc\n write (6,110)\n mde=4\n mdgh=3\nc\n me=4\n mg=3\n n=2\nc\t\t define the least squares and constraint matrices.\n t(1)=0.25\n t(2)=0.5\n t(3)=0.5\n t(4)=0.8\nc\n w(1)=0.5\n w(2)=0.6\n w(3)=0.7\n w(4)=1.2\nc\n\t do 10 i=1,me\n\t e(i,1)=t(i)\n\t e(i,2)=1.\n 10\t f(i)=w(i)\nc\n g(1,1)=1.\n g(1,2)=0.\n g(2,1)=0.\n g(2,2)=1.\n g(3,1)=-1.\n g(3,2)=-1.\nc\n h(1)=0.\n h(2)=0.\n h(3)=-1.\nc\nc compute the singular value decomposition of the matrix, e.\nc\n call svdrs (e,mde,me,n,f,1,1,s)\nc\n write (6,120) ((e(i,j),j=1,n),i=1,n)\n write (6,130) f,(s(j),j=1,n)\nc\nc generally rank determination and levenberg-marquardt\nc stabilization could be inserted here.\nc\nc\t define the constraint matrix for the z coordinate system.\n\t do 30 i=1,mg\n\t do 30 j=1,n\n\t sm=0.\n\t\t do 20 l=1,n\n 20\t\t sm=sm+g(i,l)*e(l,j)\n 30\t g2(i,j)=sm/s(j)\nc\t define constraint rt side for the z coordinate system.\n\t do 50 i=1,mg\n\t sm=0.\n\t do 40 j=1,n\n 40\t sm=sm+g2(i,j)*f(j)\n 50\t h2(i)=h(i)-sm\nc\n write (6,140) ((g2(i,j),j=1,n),i=1,mg)\n write (6,150) h2\nc\nc\t\t\t solve the constrained problem in z-coordinates.\nc\n call ldp (g2,mdgh,mg,n,h2,z,znorm,wldp,index,mode)\nc\n write (6,200) mode,znorm\n write (6,160) z\nc\nc\t\t transform back from z-coordinates to x-coordinates.\n\t do 60 j=1,n\n 60\t z(j)=(z(j)+f(j))/s(j)\n\t do 80 i=1,n\n\t sm=0.\n\t do 70 j=1,n\n 70\t sm=sm+e(i,j)*z(j)\n 80\t x(i)=sm\n res=znorm**2\n np1=n+1\n\t do 90 i=np1,me\n 90\t res=res+f(i)**2\n res=sqrt(res)\nc\t\t\t\t compute the residuals.\n\t do 100 i=1,me\n 100\t f(i)=w(i)-x(1)*t(i)-x(2)\n write (6,170) (x(j),j=1,n)\n write (6,180) (i,f(i),i=1,me)\n write (6,190) res\n stop\nc\n 110 format (46h0prog6.. example of constrained curve fitting,26h usin\n 1g the subroutine ldp.,/43h0related intermediate quantities are giv\n 2en.)\n 120 format (10h0v =\t ,2f10.5/(10x,2f10.5))\n 130 format (10h0f tilda =,4f10.5/10h0s =\t,2f10.5)\n 140 format (10h0g tilda =,2f10.5/(10x,2f10.5))\n 150 format (10h0h tilda =,3f10.5)\n 160 format (10h0z =\t ,2f10.5)\n 170 format (52h0the coeficients of the fitted line f(t)=x(1)*t+x(2),12\n 1h are x(1) = ,f10.5,14h\tand x(2) = ,f10.5)\n 180 format (30h0the consecutive residuals are/1x,4(i10,f10.5))\n 190 format (23h0the residuals norm is ,f10.5)\n 200 format (18h0mode (from ldp) =,i3,2x,7hznorm =,f10.5)\nc\n end\n", "meta": {"hexsha": "71364ec42a43d2b48b85ed46c6d715de4d6af2cc", "size": 2961, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iraf.v2161/math/llsq/progs/prog6.f", "max_stars_repo_name": "ysBach/irafdocgen", "max_stars_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:19:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T16:48:42.000Z", "max_issues_repo_path": "math/llsq/progs/prog6.f", "max_issues_repo_name": "kirxkirx/iraf", "max_issues_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-30T13:48:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-02T19:40:25.000Z", "max_forks_repo_path": "math/llsq/progs/prog6.f", "max_forks_repo_name": "kirxkirx/iraf", "max_forks_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.3076923077, "max_line_length": 72, "alphanum_fraction": 0.5596082405, "num_tokens": 1262, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232809, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6719648506094082}} {"text": " subroutine gaussj(a,n,np,b,m,mp)\nc \nc ****************************************************************\nc * *\nc * Gauss-Jordan routine used by pseud* to find polynominal *\nc * constants. Taken from Numerical Recipes, page 28. *\nc * Version dated May 7, 1991 *\nc * njtj *\nc * *\nc ****************************************************************\nc\n implicit real*8 (a-h,o-z)\nc\n parameter (nmax=50,zero=0.0d0,one=1.0d0)\nc\n dimension a(np,np),b(np,mp),ipiv(nmax),indxr(nmax),indxc(nmax)\nc\n do 11 j=1,n\n ipiv(j)=0\n11 continue\n do 22 i=1,n\n big=zero\n do 13 j=1,n\n if(ipiv(j).ne.1)then\n do 12 k=1,n\n if (ipiv(k).eq.0) then\n if (abs(a(j,k)).ge.big)then\n big=abs(a(j,k))\n irow=j\n icol=k\n endif\n else if (ipiv(k).gt.1) then\n write(6,100)\n stop 'gaussj one'\n endif\n12 continue\n endif\n13 continue\n ipiv(icol)=ipiv(icol)+1\n if (irow.ne.icol) then\n do 14 l=1,n\n dum=a(irow,l)\n a(irow,l)=a(icol,l)\n a(icol,l)=dum\n14 continue\n do 15 l=1,m\n dum=b(irow,l)\n b(irow,l)=b(icol,l)\n b(icol,l)=dum\n15 continue\n endif\n indxr(i)=irow\n indxc(i)=icol\n if (a(icol,icol).eq.zero) then\n write(6,100)\n stop 'gaussj two'\n endif\n pivinv=one/a(icol,icol)\n a(icol,icol)=one\n do 16 l=1,n\n a(icol,l)=a(icol,l)*pivinv\n16 continue\n do 17 l=1,m\n b(icol,l)=b(icol,l)*pivinv\n17 continue\n do 21 ll=1,n\n if(ll.ne.icol)then\n dum=a(ll,icol)\n a(ll,icol)=zero\n do 18 l=1,n\n a(ll,l)=a(ll,l)-a(icol,l)*dum\n18 continue\n do 19 l=1,m\n b(ll,l)=b(ll,l)-b(icol,l)*dum\n19 continue\n endif\n21 continue\n22 continue\n do 24 l=n,1,-1\n if(indxr(l).ne.indxc(l))then\n do 23 k=1,n\n dum=a(k,indxr(l))\n a(k,indxr(l))=a(k,indxc(l))\n a(k,indxc(l))=dum\n23 continue\n endif\n24 continue\n return\n 100 format(//,'Singular matrix, stopped in gaussj')\n end\n", "meta": {"hexsha": "28e78f8e4007ec9e69daddcd581c1f0d776dc808", "size": 2577, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "PSEUDO/source/gaussj.f", "max_stars_repo_name": "qsnake/petot", "max_stars_repo_head_hexsha": "bed334c6639fb02104821ce77d89ed83114febfe", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-07-13T07:57:59.000Z", "max_stars_repo_stars_event_max_datetime": "2016-07-13T07:57:59.000Z", "max_issues_repo_path": "PSEUDO/source/gaussj.f", "max_issues_repo_name": "qsnake/petot", "max_issues_repo_head_hexsha": "bed334c6639fb02104821ce77d89ed83114febfe", "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": "PSEUDO/source/gaussj.f", "max_forks_repo_name": "qsnake/petot", "max_forks_repo_head_hexsha": "bed334c6639fb02104821ce77d89ed83114febfe", "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": 28.3186813187, "max_line_length": 68, "alphanum_fraction": 0.3919285991, "num_tokens": 746, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232809, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6719648460403204}} {"text": " SUBROUTINE H12 (MODE,LPIVOT,L1,M,U,IUE,UP,C,ICE,ICV,NCV)\n\nC C.L.LAWSON AND R.J.HANSON, JET PROPULSION LABORATORY, 1973 JUN 12\nC TO APPEAR IN 'SOLVING LEAST SQUARES PROBLEMS', PRENTICE-HALL, 1974\n\nC CONSTRUCTION AND/OR APPLICATION OF A SINGLE\nC HOUSEHOLDER TRANSFORMATION Q = I + U*(U**T)/B\n\nC MODE = 1 OR 2 TO SELECT ALGORITHM H1 OR H2 .\nC LPIVOT IS THE INDEX OF THE PIVOT ELEMENT.\nC L1,M IF L1 <= M THE TRANSFORMATION WILL BE CONSTRUCTED TO\nC ZERO ELEMENTS INDEXED FROM L1 THROUGH M.\nC IF L1 > M THE SUBROUTINE DOES AN IDENTITY TRANSFORMATION.\nC U(),IUE,UP\nC ON ENTRY TO H1 U() STORES THE PIVOT VECTOR.\nC IUE IS THE STORAGE INCREMENT BETWEEN ELEMENTS.\nC ON EXIT FROM H1 U() AND UP STORE QUANTITIES DEFINING\nC THE VECTOR U OF THE HOUSEHOLDER TRANSFORMATION.\nC ON ENTRY TO H2 U() AND UP\nC SHOULD STORE QUANTITIES PREVIOUSLY COMPUTED BY H1.\nC THESE WILL NOT BE MODIFIED BY H2.\nC C() ON ENTRY TO H1 OR H2 C() STORES A MATRIX WHICH WILL BE\nC REGARDED AS A SET OF VECTORS TO WHICH THE HOUSEHOLDER\nC TRANSFORMATION IS TO BE APPLIED.\nC ON EXIT C() STORES THE SET OF TRANSFORMED VECTORS.\nC ICE STORAGE INCREMENT BETWEEN ELEMENTS OF VECTORS IN C().\nC ICV STORAGE INCREMENT BETWEEN VECTORS IN C().\nC NCV NUMBER OF VECTORS IN C() TO BE TRANSFORMED.\nC IF NCV <= 0 NO OPERATIONS WILL BE DONE ON C().\n\n INTEGER INCR, ICE, ICV, IUE, LPIVOT, L1, MODE, NCV\n INTEGER I, I2, I3, I4, J, M\n DOUBLE PRECISION U,UP,C,CL,CLINV,B,SM,ONE,ZERO\n DIMENSION U(IUE,*), C(*)\n DATA ONE/1.0D+00/, ZERO/0.0D+00/\n\n IF (0.GE.LPIVOT.OR.LPIVOT.GE.L1.OR.L1.GT.M) GOTO 80\n CL=ABS(U(1,LPIVOT))\n IF (MODE.EQ.2) GOTO 30\n\nC ****** CONSTRUCT THE TRANSFORMATION ******\n\n DO 10 J=L1,M\n SM=ABS(U(1,J))\n 10 CL=MAX(SM,CL)\n IF (CL.LE.ZERO) GOTO 80\n CLINV=ONE/CL\n SM=(U(1,LPIVOT)*CLINV)**2\n DO 20 J=L1,M\n 20 SM=SM+(U(1,J)*CLINV)**2\n CL=CL*SQRT(SM)\n IF (U(1,LPIVOT).GT.ZERO) CL=-CL\n UP=U(1,LPIVOT)-CL\n U(1,LPIVOT)=CL\n GOTO 40\nC ****** APPLY THE TRANSFORMATION I+U*(U**T)/B TO C ******\n\n 30 IF (CL.LE.ZERO) GOTO 80\n 40 IF (NCV.LE.0) GOTO 80\n B=UP*U(1,LPIVOT)\n IF (B.GE.ZERO) GOTO 80\n B=ONE/B\n I2=1-ICV+ICE*(LPIVOT-1)\n INCR=ICE*(L1-LPIVOT)\n DO 70 J=1,NCV\n I2=I2+ICV\n I3=I2+INCR\n I4=I3\n SM=C(I2)*UP\n DO 50 I=L1,M\n SM=SM+C(I3)*U(1,I)\n 50 I3=I3+ICE\n IF (SM.EQ.ZERO) GOTO 70\n SM=SM*B\n C(I2)=C(I2)+SM*UP\n DO 60 I=L1,M\n C(I4)=C(I4)+SM*U(1,I)\n 60 I4=I4+ICE\n 70 CONTINUE\n 80 END\n ", "meta": {"hexsha": "64466eecbb9dbc60d0861b4555a776780b14654f", "size": 3102, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "docker/optimization/pyOpt/tags/v1.2.0/pyOpt/pySLSQP/source/h12.f", "max_stars_repo_name": "liujiamingustc/phd", "max_stars_repo_head_hexsha": "4f815a738abad43531d02ac66f5bd0d9a1def52a", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-01-06T03:01:18.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T03:02:55.000Z", "max_issues_repo_path": "docker/optimization/pyOpt/tags/v1.2.0/pyOpt/pySLSQP/source/h12.f", "max_issues_repo_name": "liujiamingustc/phd", "max_issues_repo_head_hexsha": "4f815a738abad43531d02ac66f5bd0d9a1def52a", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docker/optimization/pyOpt/tags/v1.2.0/pyOpt/pySLSQP/source/h12.f", "max_forks_repo_name": "liujiamingustc/phd", "max_forks_repo_head_hexsha": "4f815a738abad43531d02ac66f5bd0d9a1def52a", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.2962962963, "max_line_length": 72, "alphanum_fraction": 0.5145067698, "num_tokens": 1062, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972717658209, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6719648388797987}} {"text": "module velocityverlet\n\n contains \n function positions(x,y,z,vx,vy,vz,a,t)\n implicit none\n real(16),intent(in) :: x,y,z,vx,vy,vz,a(3),t\n real(16) :: x1,y1,z1,positions(3)\n x1=x+vx*t+0.5*a(1)*t**2\n y1=y+vy*t+0.5*a(2)*t**2\n z1=z+vz*t+0.5*a(3)*t**2\n positions=[x1,y1,z1] \n end function\n\n function velocities(vx,vy,vz,a,a1,t)\n implicit none\n real(16),intent(in) :: vx,vy,vz,a(3),a1(3),t\n real(16) :: vx1,vy1,vz1,velocities(3)\n vx1=vx+0.5*(a(1)+a1(1))*t\n vy1=vy+0.5*(a(2)+a1(2))*t\n vz1=vz+0.5*(a(3)+a1(3))*t\n velocities=[vx1,vy1,vz1]\n end function\n\nend module\n", "meta": {"hexsha": "dcedf003fc538b00bb6f8c3c945d710f61afab41", "size": 601, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/verlet.f90", "max_stars_repo_name": "flansec/planetary_motion_SIMULATOR", "max_stars_repo_head_hexsha": "fbff202f091a4450c609bb2b2c048f95c3869dcb", "max_stars_repo_licenses": ["MIT"], "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/verlet.f90", "max_issues_repo_name": "flansec/planetary_motion_SIMULATOR", "max_issues_repo_head_hexsha": "fbff202f091a4450c609bb2b2c048f95c3869dcb", "max_issues_repo_licenses": ["MIT"], "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/verlet.f90", "max_forks_repo_name": "flansec/planetary_motion_SIMULATOR", "max_forks_repo_head_hexsha": "fbff202f091a4450c609bb2b2c048f95c3869dcb", "max_forks_repo_licenses": ["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.04, "max_line_length": 48, "alphanum_fraction": 0.5790349418, "num_tokens": 285, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391600697869, "lm_q2_score": 0.7279754548076477, "lm_q1q2_score": 0.6719498523570723}} {"text": "c****************************************************************\n\t\n\tsubroutine schbasis(ptm,r_sch,r_xyzschmat,r_schxyzmat)\n\t\nc****************************************************************\nc** \nc**\tFILE NAME: schbasis.f\nc** \nc** DATE WRITTEN: 10/01/97 \nc** \nc** PROGRAMMER: Scott Hensley\nc** \nc** \tFUNCTIONAL DESCRIPTION: This routine computes the transformation\nc** matrix from xyz to a local sch frame. \nc** \nc** ROUTINES CALLED:\nc** \nc** NOTES: none\nc**\nc** UPDATE LOG:\nc**\nc*****************************************************************\n\n \timplicit none\n\nc\tINPUT VARIABLES:\n\nc\tstructure /pegtrans/ !peg transformation parameters\nc\t real*8 r_mat(3,3)\nc\t real*8 r_matinv(3,3)\nc\t real*8 r_ov(3)\nc\t real*8 r_radcur\nc\tend structure\nc\trecord /pegtrans/ ptm\n\n\ttype pegtrans\n sequence\n\t real (8) r_mat(3,3)\n\t real (8) r_matinv(3,3)\n\t real (8) r_ov(3)\n\t real (8) r_radcur\n end type pegtrans\n\n\ttype (pegtrans) ptm\n\n\treal*8 r_sch(3) !SCH position\n \nc \tOUTPUT VARIABLES:\n\n\treal*8 r_xyzschmat(3,3)\n\treal*8 r_schxyzmat(3,3)\n\nc\tLOCAL VARIABLES:\n\n real*8 r_coss,r_cosc,r_sins,r_sinc\n\treal*8 r_xyzv(3),r_llh(3),r_schhdg\n\treal*8 r_matschxyzp(3,3)\n\nc\tDATA STATEMENTS: none\n\nC\tFUNCTION STATEMENTS:\n\nc \tPROCESSING STEPS:\n\nc compute transformation from a sch local basis to X'Y'Z' basis\n\n\tr_coss = cos(r_sch(1)/ptm%r_radcur)\n\tr_sins = sin(r_sch(1)/ptm%r_radcur)\n\n\tr_cosc = cos(r_sch(2)/ptm%r_radcur)\n\tr_sinc = sin(r_sch(2)/ptm%r_radcur)\n\n\tr_matschxyzp(1,1) = -r_sins \n\tr_matschxyzp(1,2) = -r_sinc*r_coss\n\tr_matschxyzp(1,3) = r_coss*r_cosc\n\tr_matschxyzp(2,1) = r_coss\n\tr_matschxyzp(2,2) = -r_sinc*r_sins\n\tr_matschxyzp(2,3) = r_sins*r_cosc\n\tr_matschxyzp(3,1) = 0.0\n\tr_matschxyzp(3,2) = r_cosc\n\tr_matschxyzp(3,3) = r_sinc\n\t\nc compute sch to xyz matrix\n\n call matmat(ptm%r_mat,r_matschxyzp,r_schxyzmat)\n\nc get the inverse\n\n\tcall tranmat(r_schxyzmat,r_xyzschmat)\n\n end \n\n\n\n\n", "meta": {"hexsha": "00d8df91d49bc16b5e885ccd4278e41339343050", "size": 2012, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "contrib/alos2proc_f/src/schbasis.f", "max_stars_repo_name": "vincentschut/isce2", "max_stars_repo_head_hexsha": "1557a05b7b6a3e65abcfc32f89c982ccc9b65e3c", "max_stars_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_stars_count": 1133, "max_stars_repo_stars_event_min_datetime": "2022-01-07T21:24:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-07T21:33:08.000Z", "max_issues_repo_path": "contrib/alos2proc_f/src/schbasis.f", "max_issues_repo_name": "vincentschut/isce2", "max_issues_repo_head_hexsha": "1557a05b7b6a3e65abcfc32f89c982ccc9b65e3c", "max_issues_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_issues_count": 276, "max_issues_repo_issues_event_min_datetime": "2019-02-10T07:18:28.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:45:55.000Z", "max_forks_repo_path": "contrib/alos2proc_f/src/schbasis.f", "max_forks_repo_name": "vincentschut/isce2", "max_forks_repo_head_hexsha": "1557a05b7b6a3e65abcfc32f89c982ccc9b65e3c", "max_forks_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_forks_count": 235, "max_forks_repo_forks_event_min_datetime": "2019-02-10T05:00:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T07:37:24.000Z", "avg_line_length": 20.9583333333, "max_line_length": 69, "alphanum_fraction": 0.5874751491, "num_tokens": 708, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391727723469, "lm_q2_score": 0.727975443004307, "lm_q1q2_score": 0.6719498507092784}} {"text": "! =============================================================================\r\n! Test FFT module\r\n!\r\n! Tests the indexing in FFTs.\r\n! (start index 0 vs start index 1)\r\n! =============================================================================\r\nprogram test_fft_1\r\n use unit_test\r\n\r\n !Import FFT library:\r\n use stafft, only : initfft, dct, forfft\r\n use deriv1d\r\n use constants\r\n\r\n implicit none\r\n\r\n !Parameters and constants:\r\n !---------------------------------------------------------------------\r\n !Number of x & z grid divisions:\r\n integer,parameter:: nx=40, nz=20\r\n\r\n !Maximum number of parcels:\r\n integer,parameter:: nm=64*nx*nz\r\n\r\n !Box width and height:\r\n double precision,parameter:: ellx=4.d0, ellz=2.d0\r\n\r\n !Domain half widths and edge values:\r\n double precision,parameter:: hlx=ellx/two\r\n\r\n !Grid lengths and their inverses:\r\n double precision,parameter:: dx=ellx/dble(nx)\r\n double precision,parameter:: dz=ellz/dble(nz)\r\n\r\n\r\n !---------------------------------------------------------------------\r\n\r\n\r\n double precision:: f0(nx,0:nz),f1(nx,0:nz)\r\n double precision:: f2(0:nx-1,0:nz)\r\n double precision:: s1(0:nz,nx),s2(0:nz,0:nx-1)\r\n\r\n double precision:: hrkx(nx),rkx(nx),rkz(nz)\r\n\r\n double precision:: xtrig(2*nx),ztrig(2*nz)\r\n integer:: xfactors(5),zfactors(5)\r\n\r\n double precision:: xg,zg,emax\r\n integer:: ix,iz,kx,kz\r\n\r\n !---------------------------------------------------------------------\r\n ! Set up FFTs:\r\n call initfft(nx,xfactors,xtrig)\r\n call initfft(nz,zfactors,ztrig)\r\n\r\n ! Define x wavenumbers:\r\n call init_deriv(nx,ellx,hrkx)\r\n rkx(1)=zero\r\n do kx=1,nx/2-1\r\n rkx(kx+1) =hrkx(2*kx)\r\n rkx(nx+1-kx)=hrkx(2*kx)\r\n enddo\r\n rkx(nx/2+1)=hrkx(nx)\r\n\r\n ! Define z wavenumbers:\r\n call init_deriv(nz,ellz,rkz)\r\n\r\n ! For z derivatives of a cosine in z function:\r\n rkz(nz)=zero\r\n\r\n !-----------------------------------------------------------------\r\n ! Define a field:\r\n do iz=0,nz\r\n zg=dz*dble(iz)\r\n do ix=1,nx\r\n xg=dx*dble(ix-1)-hlx\r\n f0(ix,iz)=(zg*(ellz-zg))**2/(one-f12*cos(xg+one))\r\n enddo\r\n enddo\r\n f1=f0\r\n f2=f0\r\n\r\n !-----------------------------------------\r\n ! Forward z cosine FFT:\r\n call dct(nx,nz,f1,ztrig,zfactors)\r\n ! Transpose array:\r\n do ix=1,nx\r\n do kz=0,nz\r\n s1(kz,ix)=f1(ix,kz)\r\n enddo\r\n enddo\r\n ! Forward x FFT:\r\n call forfft(nz+1,nx,s1,xtrig,xfactors)\r\n\r\n !-----------------------------------------\r\n ! Forward z cosine FFT:\r\n call dct(nx,nz,f2,ztrig,zfactors)\r\n ! Transpose array:\r\n do ix=0,nx-1\r\n do kz=0,nz\r\n s2(kz,ix)=f2(ix,kz)\r\n enddo\r\n enddo\r\n ! Forward x FFT:\r\n call forfft(nz+1,nx,s2,xtrig,xfactors)\r\n\r\n !-----------------------------------------\r\n ! Check difference:\r\n emax=zero\r\n do kx=1,nx\r\n do kz=0,nz\r\n emax=max(emax,abs(s1(kz,kx)-s2(kz,kx-1)))\r\n enddo\r\n enddo\r\n\r\n ! final check\r\n call print_result_dp('Test FFT indexing', emax)\r\n\r\nend program test_fft_1\r\n", "meta": {"hexsha": "7c303721c5510972ac7fbfcef7f7dbb7f9436970", "size": 3224, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "unit-tests/2d/test_fft_1.f90", "max_stars_repo_name": "matt-frey/epic", "max_stars_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2021-11-11T10:50:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T00:11:41.000Z", "max_issues_repo_path": "unit-tests/2d/test_fft_1.f90", "max_issues_repo_name": "matt-frey/epic", "max_issues_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 47, "max_issues_repo_issues_event_min_datetime": "2021-11-12T17:09:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-24T16:50:58.000Z", "max_forks_repo_path": "unit-tests/2d/test_fft_1.f90", "max_forks_repo_name": "matt-frey/epic", "max_forks_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.8666666667, "max_line_length": 80, "alphanum_fraction": 0.4550248139, "num_tokens": 921, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039738, "lm_q2_score": 0.7279754371026367, "lm_q1q2_score": 0.6719498390970378}} {"text": "program example\n\n implicit none\n\n integer :: array(8) = (/ 2, 8, 6, 1, 3, 5, 4, 7 /)\n\n call Gnomesort(array)\n write(*,*) array\n\ncontains\n\nsubroutine Gnomesort(a)\n\n integer, intent(in out) :: a(:)\n integer :: i, j, temp\n\n i = 2\n j = 3\n do while (i <= size(a))\n if (a(i-1) <= a(i)) then\n i = j\n j = j + 1\n else\n temp = a(i-1)\n a(i-1) = a(i)\n a(i) = temp\n i = i - 1\n if (i == 1) then\n i = j\n j = j + 1\n end if\n end if\n end do\n\nend subroutine Gnomesort\n\nend program example\n", "meta": {"hexsha": "41f7cfbdb79a7cff074015b69e7c4f2896d817e2", "size": 544, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Sorting-algorithms-Gnome-sort/Fortran/sorting-algorithms-gnome-sort.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Sorting-algorithms-Gnome-sort/Fortran/sorting-algorithms-gnome-sort.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Sorting-algorithms-Gnome-sort/Fortran/sorting-algorithms-gnome-sort.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": 14.3157894737, "max_line_length": 52, "alphanum_fraction": 0.4779411765, "num_tokens": 217, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711832583696, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.6719279945559129}} {"text": "program EthiopicMult\n implicit none\n\n print *, ethiopic(17, 34, .true.)\n\ncontains\n\n subroutine halve(v)\n integer, intent(inout) :: v\n v = int(v / 2)\n end subroutine halve\n\n subroutine doublit(v)\n integer, intent(inout) :: v\n v = v * 2\n end subroutine doublit\n\n function iseven(x)\n logical :: iseven\n integer, intent(in) :: x\n iseven = mod(x, 2) == 0\n end function iseven\n\n function ethiopic(multiplier, multiplicand, tutorialized) result(r)\n integer :: r\n integer, intent(in) :: multiplier, multiplicand\n logical, intent(in), optional :: tutorialized\n\n integer :: plier, plicand\n logical :: tutor\n\n plier = multiplier\n plicand = multiplicand\n\n if ( .not. present(tutorialized) ) then\n tutor = .false.\n else\n tutor = tutorialized\n endif\n\n r = 0\n\n if ( tutor ) write(*, '(A, I0, A, I0)') \"ethiopian multiplication of \", plier, \" by \", plicand\n\n do while(plier >= 1)\n if ( iseven(plier) ) then\n if (tutor) write(*, '(I4, \" \", I6, A)') plier, plicand, \" struck\"\n else\n if (tutor) write(*, '(I4, \" \", I6, A)') plier, plicand, \" kept\"\n r = r + plicand\n endif\n call halve(plier)\n call doublit(plicand)\n end do\n\n end function ethiopic\n\nend program EthiopicMult\n", "meta": {"hexsha": "9814c9af9694c40705ea410715b22d6c5aee0d6e", "size": 1295, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Ethiopian-multiplication/Fortran/ethiopian-multiplication.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/Ethiopian-multiplication/Fortran/ethiopian-multiplication.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/Ethiopian-multiplication/Fortran/ethiopian-multiplication.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 21.9491525424, "max_line_length": 98, "alphanum_fraction": 0.5953667954, "num_tokens": 410, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711756575749, "lm_q2_score": 0.7905303112671294, "lm_q1q2_score": 0.6719279780606705}} {"text": "! Program to fit a given set of data in terms of a given polynomial using \n! Singular Value Decomposition, see Golub and Van Loan, Matrix Computations\n! Numerical Recipes, chapter 15.\n! This explict example fits a polynomial to a given degree based. The example\n! input should look like\n! 8 2 # number of data entries and order of polynomial\n! 0.001 \t-2.89017 \t0.00073621\n! 0.002 \t-2.88946 \t0.00052732\n! 0.005\t-2.89067 \t0.00055038\n! 0.010 \t-2.89091 \t0.00040973\n! 0.015 \t-2.89084 \t0.00034278\n! 0.02 \t-2.89086 \t0.00029315\n! 0.025 \t-2.89059\t0.00034278\n! 0.03 \t-2.89077 \t0.00025017\n! The present input file stems from a variational Monte Carlo calculation of the ground\n! state energy (second column). It contains also the standard deviation (3rd column)\n! The first column is the time step used in importance sampling. Extrapolating to zero \n! should give the best estimate for the VMC energy.\n!\n! Author: Morten Hjorth-Jensen, Department of Physics, University of Oslo,\n! POB 1048 Blindern, N-0316 Oslo, Norway. email: morten.hjorth-jensen@fys.uio.no \n! Latest update: October 1999.\n! Run in old fashioned way, executable < inputfile > outputfile\n\n!\n! Main program starts here\n!\n PROGRAM fitting\n IMPLICIT NONE\n CALL vmcfit\n\n END PROGRAM fitting\n!\n! This subroutine fits a data set with in terms\n! of a polynomial expansion. The number of terms in the polynomial\n! expansion is given by the variable number_terms\n! The number of data ( delta and corresponding energy\n! and the standard error) are defined by the variable number_of_data\n!\n SUBROUTINE vmcfit\n IMPLICIT NONE\n INTEGER :: i, number_of_data, number_terms\n DOUBLE PRECISION, ALLOCATABLE, DIMENSION(:) :: w, n, e,sig,polynom_terms, variance\n DOUBLE PRECISION, ALLOCATABLE, DIMENSION(:,:) :: cvm, v, u\n DOUBLE PRECISION :: chisq, kappa, v_over_c, adiabatic\n EXTERNAL eos_param\n\n READ (5,*) number_of_data, number_terms \n ALLOCATE (cvm(number_terms,number_terms), &\n v(number_terms,number_terms) )\n ALLOCATE ( u(number_of_data,number_terms) )\n ALLOCATE ( w(number_terms) )\n ALLOCATE ( variance(number_terms) )\n ALLOCATE ( polynom_terms(number_terms) )\n ALLOCATE (n(number_of_data), e(number_of_data), sig(number_of_data) ) \n DO i=1,number_of_data\n READ (5,*)n(i) , e(i), sig(i)\n ENDDO\n CALL svdfit(n,e,sig,number_of_data,polynom_terms, &\n number_terms, &\n u,v,w,number_of_data,number_terms,chisq)\n CALL svdvar(v,number_terms,number_terms,w,cvm,number_terms)\n! Compute now the variance for each coefficient using Eq. 15.4.19\n! of numerical recipes\n variance = 0.0; w = 1.0/(w*w)\n DO i = 1, number_terms\n variance(i) = SUM(v(i,:)*v(i,:)*w(:))\n ENDDO\n WRITE(*,*) ' Quality of fit:'\n WRITE(*,*) ' Number of terms in polynomial expansion:', number_terms\n WRITE (*,'(''CHISQ = '',F12.5)') chisq\n WRITE(*,*) 'Extrapolated energy with error'\n WRITE(*,*) polynom_terms(1), SQRT(variance(1))\n DEALLOCATE (cvm, v)\n DEALLOCATE ( u )\n DEALLOCATE ( w,polynom_terms, variance )\n DEALLOCATE (n, e, sig) \n\n END SUBROUTINE vmcfit\n\n\n! This function encodes the actual functional form of the polynomial.\n! If you need to change the functional form, this is the function to adjust.\n! This specific version is a polynomial in x^i, with i >=0 and being an integer\n\n SUBROUTINE eos_param(x,afunc,ma)\n IMPLICIT NONE\n INTEGER :: ma, i\n DOUBLE PRECISION :: afunc, x\n DIMENSION afunc(ma)\n afunc(1)=1.D0\n DO i=2,ma\n afunc(i)=afunc(i-1)*x\n ENDDO\n\n END SUBROUTINE eos_param\n\n\n\n SUBROUTINE svdvar(v,ma,np,w,cvm,ncvm)\n IMPLICIT NONE\n INTEGER :: ma,ncvm,np,MMAX\n DOUBLE PRECISION :: cvm(ncvm,ncvm),v(np,np),w(np)\n PARAMETER (MMAX=100)\n INTEGER :: i,j,k\n DOUBLE PRECISION :: sum,wti(MMAX)\n DO i=1,ma\n wti(i)=0.\n IF (w(i) /= 0.) wti(i)=1./(w(i)*w(i))\n ENDDO\n DO i=1,ma\n DO j=1,i\n sum=0.\n DO k=1,ma\n sum=sum+v(i,k)*v(j,k)*wti(k)\n ENDDO\n cvm(i,j)=sum\n cvm(j,i)=sum\n ENDDO\n ENDDO\n\n END SUBROUTINE svdvar\n\n\n SUBROUTINE svbksb(u,w,v,m,n,mp,np,b,x)\n IMPLICIT NONE\n INTEGER :: m,mp,n,np,NMAX\n DOUBLE PRECISION :: b(mp),u(mp,np),v(np,np),w(np),x(np)\n PARAMETER (NMAX=5000)\n INTEGER :: i,j,jj\n DOUBLE PRECISION :: s,tmp(NMAX)\n DO j=1,n\n s=0.\n IF (w(j) /= 0.) THEN\n DO i=1,m\n s=s+u(i,j)*b(i)\n ENDDO\n s=s/w(j)\n ENDIF\n tmp(j)=s\n ENDDO\n DO j=1,n\n s=0.\n DO jj=1,n\n s=s+v(j,jj)*tmp(jj)\n ENDDO\n x(j)=s\n ENDDO\n\n END SUBROUTINE svbksb\n\n\n SUBROUTINE svdfit(x,y,sig,ndata,a,ma,u,v,w,mp,np,chisq)\n IMPLICIT NONE\n INTEGER :: ma,mp,ndata,np,NMAX,MMAX\n DOUBLE PRECISION :: chisq,a(ma),sig(ndata),u(mp,np),v(np,np),w(np), &\n x(ndata), y(ndata),TOL\n PARAMETER (NMAX=5000,MMAX=100,TOL=1.e-5)\n INTEGER :: i,j\n DOUBLE PRECISION :: sum,thresh,tmp,wmax,afunc(MMAX), &\n b(NMAX)\n\n DO i=1,ndata\n CALL eos_param(x(i),afunc,ma)\n tmp=1./sig(i)\n DO j=1,ma\n u(i,j)=afunc(j)*tmp\n ENDDO\n b(i)=y(i)*tmp\n ENDDO\n CALL svdcmp(u,ndata,ma,mp,np,w,v)\n wmax=0.\n DO j=1,ma\n IF (w(j) > wmax)wmax=w(j)\n ENDDO\n thresh=TOL*wmax\n DO j=1,ma\n IF (w(j) < thresh) w(j)=0.\n ENDDO\n CALL svbksb(u,w,v,ndata,ma,mp,np,b,a)\n chisq=0.\n DO i=1,ndata\n CALL eos_param(x(i),afunc,ma)\n sum=0.\n DO j=1,ma\n sum=sum+a(j)*afunc(j)\n ENDDO\n chisq=chisq+((y(i)-sum)/sig(i))**2\n ENDDO\n\n END SUBROUTINE svdfit\n\n\n FUNCTION pythag(a,b)\n IMPLICIT NONE\n DOUBLE PRECISION :: a, b, pythag \n DOUBLE PRECISION :: absa, absb\n absa=ABS(a)\n absb=ABS(b)\n IF (absa > absb) THEN\n pythag=absa*SQRT(1.+(absb/absa)**2)\n ELSE\n IF(absb == 0.) THEN\n pythag=0.\n ELSE\n pythag=absb*SQRT(1.+(absa/absb)**2)\n ENDIF\n ENDIF\n\n END FUNCTION pythag\n\n SUBROUTINE svdcmp(a,m,n,mp,np,w,v)\n IMPLICIT NONE\n INTEGER :: m,mp,n,np,NMAX\n DOUBLE PRECISION :: a(mp,np),v(np,np),w(np)\n PARAMETER (NMAX=5000)\n INTEGER :: i,its,j,jj,k,l,nm\n DOUBLE PRECISION :: anorm,c,f,g,h,s,scale,x,y,z, &\n rv1(NMAX),pythag\n g=0.0\n scale=0.0\n anorm=0.0\n DO i=1,n\n l=i+1\n rv1(i)=scale*g\n g=0.0\n s=0.0\n scale=0.0\n IF(i <= m)THEN\n DO k=i,m\n scale=scale+ABS(a(k,i))\n ENDDO\n IF(scale /= 0.0)THEN\n DO k=i,m\n a(k,i)=a(k,i)/scale\n s=s+a(k,i)*a(k,i)\n ENDDO\n f=a(i,i)\n g=-sign(SQRT(s),f)\n h=f*g-s\n a(i,i)=f-g\n DO j=l,n\n s=0.0\n DO k=i,m\n s=s+a(k,i)*a(k,j)\n ENDDO\n f=s/h\n DO k=i,m\n a(k,j)=a(k,j)+f*a(k,i)\n ENDDO\n ENDDO\n DO k=i,m\n a(k,i)=scale*a(k,i)\n ENDDO\n ENDIF\n ENDIF\n w(i)=scale *g\n g=0.0\n s=0.0\n scale=0.0\n IF((i <= m).and.(i /= n))THEN\n DO k=l,n\n scale=scale+ABS(a(i,k))\n ENDDO\n IF(scale /= 0.0)THEN\n DO k=l,n\n a(i,k)=a(i,k)/scale\n s=s+a(i,k)*a(i,k)\n ENDDO\n f=a(i,l)\n g=-sign(SQRT(s),f)\n h=f*g-s\n a(i,l)=f-g\n DO k=l,n\n rv1(k)=a(i,k)/h\n ENDDO\n DO j=l,m\n s=0.0\n DO k=l,n\n s=s+a(j,k)*a(i,k)\n ENDDO\n DO k=l,n\n a(j,k)=a(j,k)+s*rv1(k)\n ENDDO\n ENDDO\n DO k=l,n\n a(i,k)=scale*a(i,k)\n ENDDO\n ENDIF\n ENDIF\n anorm=max(anorm,(ABS(w(i))+ABS(rv1(i))))\n ENDDO\n DO i=n,1,-1\n IF(i < n)THEN\n IF(g /= 0.0)THEN\n DO j=l,n\n v(j,i)=(a(i,j)/a(i,l))/g\n ENDDO\n DO j=l,n\n s=0.0\n DO k=l,n\n s=s+a(i,k)*v(k,j)\n ENDDO\n DO k=l,n\n v(k,j)=v(k,j)+s*v(k,i)\n ENDDO\n ENDDO\n ENDIF\n DO j=l,n\n v(i,j)=0.0\n v(j,i)=0.0\n ENDDO\n ENDIF\n v(i,i)=1.0\n g=rv1(i)\n l=i\n ENDDO\n DO i=min(m,n),1,-1\n l=i+1\n g=w(i)\n DO j=l,n\n a(i,j)=0.0\n ENDDO\n IF(g /= 0.0)THEN\n g=1.0/g\n DO j=l,n\n s=0.0\n DO k=l,m\n s=s+a(k,i)*a(k,j)\n ENDDO\n f=(s/a(i,i))*g\n DO k=i,m\n a(k,j)=a(k,j)+f*a(k,i)\n ENDDO\n ENDDO\n DO j=i,m\n a(j,i)=a(j,i)*g\n ENDDO\n ELSE\n DO j= i,m\n a(j,i)=0.0\n ENDDO\n ENDIF\n a(i,i)=a(i,i)+1.0\n ENDDO\n DO k=n,1,-1\n DO its=1,30\n DO l=k,1,-1\n nm=l-1\n IF((ABS(rv1(l))+anorm) == anorm) goto 2\n IF((ABS(w(nm))+anorm) == anorm) goto 1\n ENDDO\n1 c=0.0\n s=1.0\n DO i=l,k\n f=s*rv1(i)\n rv1(i)=c*rv1(i)\n IF((ABS(f)+anorm) == anorm) goto 2\n g=w(i)\n h=pythag(f,g)\n w(i)=h\n h=1.0/h\n c= (g*h)\n s=-(f*h)\n DO j=1,m\n y=a(j,nm)\n z=a(j,i)\n a(j,nm)=(y*c)+(z*s)\n a(j,i)=-(y*s)+(z*c)\n ENDDO\n ENDDO\n2 z=w(k)\n IF(l == k)THEN\n IF(z < 0.0)THEN\n w(k)=-z\n DO j=1,n\n v(j,k)=-v(j,k)\n ENDDO\n ENDIF\n goto 3\n ENDIF\n IF(its == 30) THEN \n WRITE(*,*) 'no convergence in svdcmp'; STOP\n ENDIF\n x=w(l)\n nm=k-1\n y=w(nm)\n g=rv1(nm)\n h=rv1(k)\n f=((y-z)*(y+z)+(g-h)*(g+h))/(2.0*h*y)\n g=pythag(f,1.D0)\n f=((x-z)*(x+z)+h*((y/(f+sign(g,f)))-h))/x\n c=1.0\n s=1.0\n DO j=l,nm\n i=j+1\n g=rv1(i)\n y=w(i)\n h=s*g\n g=c*g\n z=pythag(f,h)\n rv1(j)=z\n c=f/z\n s=h/z\n f= (x*c)+(g*s)\n g=-(x*s)+(g*c)\n h=y*s\n y=y*c\n DO jj=1,n\n x=v(jj,j)\n z=v(jj,i)\n v(jj,j)= (x*c)+(z*s)\n v(jj,i)=-(x*s)+(z*c)\n ENDDO\n z=pythag(f,h)\n w(j)=z\n IF(z /= 0.0)THEN\n z=1.0/z\n c=f*z\n s=h*z\n ENDIF\n f= (c*g)+(s*y)\n x=-(s*g)+(c*y)\n DO jj=1,m\n y=a(jj,j)\n z=a(jj,i)\n a(jj,j)= (y*c)+(z*s)\n a(jj,i)=-(y*s)+(z*c)\n ENDDO\n ENDDO\n rv1(l)=0.0\n rv1(k)=f\n w(k)=x\n ENDDO\n3 CONTINUE \n ENDDO\n\n END SUBROUTINE svdcmp\n\n\n\n\n\n\n", "meta": {"hexsha": "81b6d16847be74eff1a64c0a956f1dbfba41455d", "size": 12347, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "doc/Programs/SVD/Fortran/simplefit.f90", "max_stars_repo_name": "anacost/MachineLearning", "max_stars_repo_head_hexsha": "89e1c3637fe302c2b15b96bf89c8a01d2d693f29", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-08-24T18:42:36.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-24T18:42:36.000Z", "max_issues_repo_path": "doc/Programs/SVD/Fortran/simplefit.f90", "max_issues_repo_name": "bernharl/MachineLearning", "max_issues_repo_head_hexsha": "35389a23d0abe490fbb9cd653aa732eeac162262", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/Programs/SVD/Fortran/simplefit.f90", "max_forks_repo_name": "bernharl/MachineLearning", "max_forks_repo_head_hexsha": "35389a23d0abe490fbb9cd653aa732eeac162262", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-21T13:30:23.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T13:30:23.000Z", "avg_line_length": 27.7460674157, "max_line_length": 91, "alphanum_fraction": 0.4277962258, "num_tokens": 3859, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.900529778109184, "lm_q2_score": 0.7461389986757758, "lm_q1q2_score": 0.6719203869161051}} {"text": "! Routine that computes fitness of each individual,\r\n! and sorts them by decreasing fitness.\r\n! Igor Lopes, February 2015\r\nSUBROUTINE FITNESS(XMIN,XMAX,XVEC,POP,VFIT,OBJF,NBITS,NDIM,NPOP,NTBIT)\r\n IMPLICIT NONE\r\n ! Parameters\r\n REAL(8) R1 /1.0D0/\r\n REAL(8) R2 /2.0D0/\r\n ! Argument\r\n INTEGER :: NDIM, NPOP, NTBIT\r\n REAL(8) :: FMAX, FMIN\r\n INTEGER,DIMENSION(NDIM) :: NBITS\r\n REAL(8),DIMENSION(NPOP) :: VFIT, OBJF\r\n REAL(8),DIMENSION(NDIM) :: XMIN, XMAX\r\n REAL(8),DIMENSION(NDIM,NPOP) :: XVEC\r\n INTEGER,DIMENSION(NPOP,NTBIT) :: POP\r\n ! Locals\r\n INTEGER :: IBIT, IDIM, IPOP, IPOS, ISUB, NPOS\r\n REAL(8) :: AUX, BIN2REAL, EVALFUNC\r\n REAL(8),DIMENSION(NPOP) :: VFITO, OBJFO\r\n INTEGER,DIMENSION(NPOP,NTBIT) :: POPO\r\n REAL(8),DIMENSION(NDIM,NPOP) :: XVECO\r\n ! Algorithm\r\n ! Decode from binary to real\r\n DO IPOP=1,NPOP\r\n IPOS=0\r\n DO IDIM=1,NDIM\r\n AUX=BIN2REAL(POP(IPOP,IPOS+1:IPOS+NBITS(IDIM)),NBITS(IDIM))\r\n XVEC(IDIM,IPOP)=XMIN(IDIM)+AUX*(XMAX(IDIM)-XMIN(IDIM))/(R2**NBITS(IDIM)-R1)\r\n IPOS=IPOS+NBITS(IDIM)\r\n ENDDO\r\n OBJF(IPOP)=EVALFUNC(XVEC(:,IPOP),NDIM)\r\n ENDDO\r\n ! Minimization of function -> higher fitness for lower function value\r\n FMAX=MAXVAL(OBJF)\r\n FMIN=MINVAL(OBJF)\r\n DO IPOP=1,NPOP\r\n VFIT(IPOP)=FMAX-OBJF(IPOP)+0.01*(FMAX-FMIN)\r\n !artifitial increase of fitness in 1% of the best fitness\r\n ENDDO\r\n ! Sort by decreasing fitness\r\n POPO=POP\r\n VFITO=VFIT\r\n XVECO=XVEC\r\n OBJFO=OBJF\r\n POP=0\r\n VFIT=MINVAL(VFIT)\r\n POP(1,:)=POPO(1,:)\r\n VFIT(1)=VFITO(1)\r\n XVEC(:,1)=XVECO(:,1)\r\n OBJF(1)=OBJFO(1)\r\n DO IPOP=2,NPOP\r\n DO ISUB=1,IPOP-1\r\n IF(VFITO(IPOP).GE.VFIT(ISUB))THEN\r\n DO IPOS=IPOP,ISUB+1,-1\r\n VFIT(IPOS)=VFIT(IPOS-1)\r\n POP(IPOS,:)=POP(IPOS-1,:)\r\n OBJF(IPOS)=OBJF(IPOS-1)\r\n XVEC(:,IPOS)=XVEC(:,IPOS-1)\r\n ENDDO\r\n VFIT(ISUB)=VFITO(IPOP)\r\n POP(ISUB,:)=POPO(IPOP,:)\r\n OBJF(ISUB)=OBJFO(IPOP)\r\n XVEC(:,ISUB)=XVECO(:,IPOP)\r\n GOTO 10\r\n ENDIF\r\n ENDDO\r\n VFIT(IPOP)=VFITO(IPOP)\r\n POP(IPOP,:)=POPO(IPOP,:)\r\n OBJF(IPOP)=OBJFO(IPOP)\r\n XVEC(:,IPOP)=XVECO(:,IPOP)\r\n10 CONTINUE \r\n ENDDO\r\nEND SUBROUTINE", "meta": {"hexsha": "90119958dcf91f7a8603b7bcfa7106db4588daf1", "size": 2449, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/genetic/fitness.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/genetic/fitness.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/genetic/fitness.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": 33.0945945946, "max_line_length": 88, "alphanum_fraction": 0.5422621478, "num_tokens": 856, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.900529791457032, "lm_q2_score": 0.7461389873857264, "lm_q1q2_score": 0.6719203867084292}} {"text": " program bestfit\n\nc***********************************************************************\nc\nc Least squares fitting of arbitary functions to data\nc uses Gram-Schmidt Orthogonalisation procedure.\nc\nc copyright daresbury laboratory 1993\nc author t. forester may 1993.\nc\nc***********************************************************************\n\n implicit real*8(a-h,o-z)\n\n\nc maximum number of functions to fit\n\n Parameter (M1 = 20)\n\nc maximum number of data points (> M)\n\n Parameter (N1 = 1000)\n\n Dimension A(m1,n1), B(m1,m1),C(m1,n1),x(n1),y(n1),d(m1)\n\n\n write(*,*) 'Gram Schmidt Orthogonalisation with a maximum of '\n x ,m1,' functions and ',n1, ' data points'\n\n write(*,'(//,a30)')'number of functions to use ?'\n read(*,*) m\n if(m.gt.m1) call error(1)\n\n write(*,*)'enter points x, y {type\" -999 -999\" to terminate list}'\n\n n = 0\n 10 read(*,*) x1,y1\n if (x1.eq.-999.d0.and.y1.eq.-999.d0) goto 20\n if(n.ge.n1) call error(2)\n n = n+1\n x(n) = x1\n y(n) = y1\n goto 10\n \n 20 continue\n\n if(n.lt.m) call error(4)\nc\nc create a matrix - change function definitions here - only the first m\nc functions are used.\n\n do i = 1,n\nc\nc define functions as power series\nc but in general may be any function you like\n\n if(m.ge.1) a(1,i) = 1\n if(m.ge.2) a(2,i) = x(i)\n if(m.ge.3) a(3,i) = x(i)*a(2,i)\n if(m.ge.4) a(4,i) = x(i)*a(3,i)\n if(m.ge.5) a(5,i) = x(i)*a(4,i)\n if(m.ge.6) a(6,i) = x(i)*a(5,i)\n if(m.ge.7) a(7,i) = x(i)*a(6,i)\n if(m.ge.8) a(8,i) = x(i)*a(7,i)\n if(m.ge.9) a(9,i) = x(i)*a(8,i)\n if(m.ge.10) a(10,i) = x(i)*a(9,i)\n if(m.ge.11) a(11,i) = x(i)*a(10,i)\n if(m.ge.12) a(12,i) = x(i)*a(11,i)\n if(m.ge.13) a(13,i) = x(i)*a(12,i)\n if(m.ge.14) a(14,i) = x(i)*a(13,i)\n if(m.ge.15) a(15,i) = x(i)*a(14,i)\n if(m.ge.16) a(16,i) = x(i)*a(15,i)\n if(m.ge.17) a(17,i) = x(i)*a(16,i)\n if(m.ge.18) a(18,i) = x(i)*a(17,i)\n if(m.ge.19) a(19,i) = x(i)*a(18,i)\n if(m.ge.20) a(20,i) = x(i)*a(19,i)\n\n enddo\n\nc\nc construct b = a.(a transpose) (m x m)\n\n do i = 1,m\n\n do j = i,m\n\n b(i,j) = 0.d0\n\n do k = 1,n\n\n b(i,j) = b(i,j) + a(i,k)*a(j,k)\n\n enddo\n\n b(j,i) = b(i,j)\n\n enddo\n\n enddo\n \nc\nc find inverse of b\n\n call invert(m,m1,b,b)\n\nc\nc construct (b^-1)a (m x n)\n\n do i = 1,m\n\n do j = 1,n\n\n c(i,j) = 0.0d0\n\n do k = 1,m\n\n c(i,j) = c(i,j) + b(i,k)*a(k,j)\n\n enddo\n\n enddo\n\n enddo\n\nc\nc find coefficients \n\n do i = 1,m\n\n d(i) = 0.d0\n\n do j = 1,n\n\n d(i) = d(i) + c(i,j)*y(j)\n\n enddo\n\n write(*,198) i,d(i)\n 198 format (' coefficient',i5,4x,1p,e16.8)\n\n enddo\n\n\nc\nc calculate best fit of data points\n write(*,*)\n write(*,'(3(5x,a5,5x))') 'x','y','fit'\n do i = 1,n\n\n ax = 0.d0\n\n do j = 1,m\n\n ax = ax + a(j,i)*d(j)\n\n enddo\n\n write(*,95) x(i), y(i), ax\n\n 95 format(1p,3e16.8)\n\n enddo\n\n end\n subroutine error(i)\n\n 1 format(/,' error - too many functions specified')\n 2 format(/,' error - too many data points specified')\n 3 format(/,' error - matrix too big for \"invert\"')\n 4 format(/,' error - too few data points specified')\n\n if(i.eq.1) write(*,1)\n if(i.eq.2) write(*,2)\n if(i.eq.3) write(*,3)\n if(i.eq.4) write(*,4)\n\n call exit()\n return\n end\n\n subroutine invert(nnn,nmax,aaa,bbb)\nc \nc***********************************************************************\nc \nc routine to invert a real symmetric matrix (reference:\nc computing methods v.ii, i.s. berezin and n.p.zhidkov,\nc pergamon press 1965). note that the matrices are\nc packed in the minimum storage mode, (i.e. a(k)=a(i,j),\nc where i>j and k=(i*(i-1))/2+j ).\nc the matrices aaa and bbb may be equivalenced though\nc this will destroy the contents of the original\nc array.\nc \nc general version for all real symmetric matrices\nc \nc copyright daresbury laboratory 1993\nc author w.smith (added to dl_poly july 1993)\nc \nc***********************************************************************\nc \n implicit real*8(a-h,o-z)\nc\nc maximum matrix (mbig*mbig) to invert\n\n parameter (mbig =100, bmax = mbig*(mbig+1)/2)\n dimension aaa(nmax*nmax),bbb(nmax*nmax),bbi(bmax)\n\n ind(i,j)=(max0(i,j)*(max0(i,j)-1))/2+min0(i,j)\n\n if(nnn.gt.mbig) call error(3)\nc\nc pack matrix aaa into a triangular form\n\n do i = 1,nnn\n do j = 1,i\n k = ind(i,j)\n k1 = (i-1)*nmax + j\n bbi(k) = aaa(k1)\n enddo\n enddo\n do i = 1,nnn\n do j = 1,i\n k = ind(i,j)\n aaa(k) = bbi(k)\n enddo\n enddo\n \nc \nc factorize matrix aaa into upper and lower forms\n do l=1,nnn\n do m=1,l\n k=ind(l,m)\n bbi(k)=0.d0\n bbb(k)=aaa(k)\n if(m.ne.1)then\n lm=m-1\n do n=1,lm\n ln=ind(l,n)\n mn=ind(m,n)\n temv =bbb(k)-bbb(ln)*bbb(mn)+bbi(ln)*bbi(mn)\n bbi(k)=bbi(k)-bbi(ln)*bbb(mn)-bbb(ln)*bbi(mn)\n bbb(k)=temv\n enddo\n endif\n if(l.eq.m)then\n if(bbb(k).lt.0.d0)then\n bbi(k)=sqrt(abs(bbb(k)))\n bbb(k)=0.d0\n else\n bbb(k)=sqrt(abs(bbb(k)))\n bbi(k)=0.d0\n endif\n else\n mm=ind(m,m)\n den=1.d0/(bbb(mm)**2+bbi(mm)**2)\n temv =den*(bbb(k)*bbb(mm)+bbi(k)*bbi(mm))\n bbi(k)=den*(bbi(k)*bbb(mm)-bbb(k)*bbi(mm))\n bbb(k)=temv\n endif\n enddo\n enddo\nc \nc invert lower triangular matrix\n do l=1,nnn\n n=ind(l,l)\n den=1.d0/(bbb(n)*bbb(n)+bbi(n)*bbi(n))\n do m=1,l\n k=ind(l,m)\n if(l.eq.m)then\n bbb(k)= den*bbb(k)\n bbi(k)=-den*bbi(k)\n else\n lm=l-1\n suma=0.d0\n sumb=0.d0\n do j=m,lm\n lj=ind(l,j)\n mj=ind(m,j)\n suma=suma-bbb(lj)*bbb(mj)+bbi(lj)*bbi(mj)\n sumb=sumb-bbb(lj)*bbi(mj)-bbi(lj)*bbb(mj)\n enddo\n temv =den*(suma*bbb(n)+sumb*bbi(n))\n bbi(k)=den*(sumb*bbb(n)-suma*bbi(n))\n bbb(k)=temv\n endif\n enddo\n enddo\nc \nc form product of upper and lower inverse triangular matrices\n do l=1,nnn\n do m=1,l\n sum=0.d0\n k=ind(l,m)\n do j=l,nnn\n lj=ind(l,j)\n mj=ind(m,j)\n sum=sum+bbb(lj)*bbb(mj)-bbi(lj)*bbi(mj)\n enddo\n bbb(k)=sum\n enddo\n enddo\n\nc\nc unpack inverse matrix bbb\n\n do i = 1,nnn\n do j = 1,i\n k=ind(i,j)\n bbi(k) = bbb(k)\n enddo\n enddo\n\n do i = 1,nnn\n do j = 1,nnn\n k1 = (i-1)*nmax + j\n k = ind(i,j)\n bbb(k1) = bbi(k)\n enddo\n enddo\n\n return\n end\n\n", "meta": {"hexsha": "36b42c8af10719522527bc8a6e5895e2a98f9894", "size": 7547, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "utility/bestfit.f", "max_stars_repo_name": "zzalscv2/DL_POLY_Classic", "max_stars_repo_head_hexsha": "f2712ca1cdddd154f621f9f5a3c2abac94e41e58", "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": "utility/bestfit.f", "max_issues_repo_name": "zzalscv2/DL_POLY_Classic", "max_issues_repo_head_hexsha": "f2712ca1cdddd154f621f9f5a3c2abac94e41e58", "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": "utility/bestfit.f", "max_forks_repo_name": "zzalscv2/DL_POLY_Classic", "max_forks_repo_head_hexsha": "f2712ca1cdddd154f621f9f5a3c2abac94e41e58", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.2932098765, "max_line_length": 75, "alphanum_fraction": 0.4286471446, "num_tokens": 2500, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.900529778109184, "lm_q2_score": 0.7461389873857264, "lm_q1q2_score": 0.6719203767490795}} {"text": "SUBROUTINE poly_interp(x1a,x2a,ya,x1,x2,y)\n!------------------------------------------------------------------------\n!\n! Description:\n!\n! Returns an interpolated value using polynomial interpolation (2D). If\n! input function is [2x2], bilinear interpolation is performed\n! \n!\n! Dependencies:\n!\n! Subroutine polint\n!\n! References:\n!\n! Numerical Recipes\n!\n! Author: W. Imperatori\n!\n! Modified: January 2009 (v1.3)\n!\n\nuse def_kind; use interfaces, only: polint\n\nimplicit none\n\n! arrays for x,y coordinates\t\nreal(kind=r_single),dimension(:),intent(in) :: x1a,x2a\n! values of function at (x,y)\nreal(kind=r_single),dimension(:,:),intent(in):: ya\n! coordinates of interpolated point\nreal(kind=r_single),intent(in) :: x1,x2\n! interpolated point\nreal(kind=r_single),intent(out) :: y\n! counter, vector length \ninteger(kind=i_single) :: i,m\n! temporary arrays \nreal(kind=r_single),dimension(size(x1a)) :: ymtmp\nreal(kind=r_single),dimension(size(x2a)) :: yntmp\n\n!-----------------------------------------------------------------------\n\n! check for data \nif ( size(x1a) /= size(ya,1) ) call error_handling(7,'null','POLY_INTERP (interpolation.f90)')\nif ( size(x2a) /= size(ya,2) ) call error_handling(7,'null','POLY_INTERP (interpolation.f90)')\n\nm=size(x1a)\n\ndo i=1,m\n yntmp = ya(i,:)\n call polint(x2a,yntmp,x2,ymtmp(i))\nenddo\n\ncall polint(x1a,ymtmp,x1,y) \n\n\nEND SUBROUTINE poly_interp\n\n!===================================================================================================\n\nSUBROUTINE polint(xa,ya,x,y)\n!----------------------------------------------------------------\n!\n! Description:\n!\n! Returns value through polynomial interpolation (1D), that means\n! the returned value is y=P(x), where P is polynomial of degree\n! N-1 (N is the number of points in xa)\n!\n! Dependencies:\n!\n! None\n!\n! References:\n!\n! Numerical recipes\n!\n! Author: W. Imperatori\n!\n! Modified: January 2009 (v1.3)\n!\n\nuse def_kind\n\nimplicit none\n\n! arrays for x coordinate and y values\nreal(kind=r_single),dimension(:),intent(in):: xa,ya\n! coordinate of interpolated value\nreal(kind=r_single),intent(in) :: x\n! interpolated value and error estimation\nreal(kind=r_single),intent(out) :: y\n! counter and dummies (locals)\nreal(kind=r_single) :: dy\ninteger(kind=i_single) :: m,n,ns\nreal(kind=r_single), dimension(size(xa)) :: c,d,den,ho\ninteger(kind=i_single),dimension(1) :: imin\n\n!----------------------------------------------------------------\n\n! check for data consistency \nif ( size(xa) /= size(ya) ) call error_handling(7,'null','POLINT (interpolation.f90)')\n\nn=size(xa) \n\n! initialize tableau\nc=ya\nd=ya\n\nho=xa-x\n\n! find index closest to table entry\nimin=minloc(abs(x-xa))\nns=imin(1) \n\n! initial approximation\ny=ya(ns)\nns=ns-1\n\ndo m=1,n-1\n \n den(1:n-m)=ho(1:n-m)-ho(1+m:n) \n \n ! abort if two xa are identical\n if (any(den(1:n-m) == 0.0)) call error_handling(4,'null','POLINT (interpolation.f90)')\n\n den(1:n-m)=(c(2:n-m+1)-d(1:n-m))/den(1:n-m)\n d(1:n-m)=ho(1+m:n)*den(1:n-m)\n c(1:n-m)=ho(1:n-m)*den(1:n-m)\n\n if (2*ns < n-m) then\n dy=c(ns+1)\n else\n dy=d(ns)\n ns=ns-1\n endif\n\n y=y+dy\n\nenddo\n\nEND SUBROUTINE polint\n\n!===================================================================================================\n\nSUBROUTINE sampling_check\n!----------------------------------------------------------------------\n!\n! Description:\n!\n! Compute number of points (npts) for the interpolated time-series.\n! This value is to guarantee a Nyquist frequency >= the maximum \n! frequency used during coda wave computation AND a npts that is a\n! 2**N value (necessary for FFT/IFFT subroutines)\n!\n! Dependencies:\n!\n! None\n!\n! Notes:\n!\n! For the \"LF-HF merging\" modality: to assure same time-series length\n! (in time), interpolation is performed here.\n!\n! Author: W. Imperatori\n!\n! Modified: January 2009 (v1.3)\n!\n \nuse def_kind; use flags; use scattering, only: fmax,npts\nuse source_receiver, only: n_stat; use waveform\n\nimplicit none \n\n! local varaibles\nreal(kind=r_single):: dt,exponent\n \n \n!---------------------------------------------------------------------\n\nif (modality_flag == 0) then\n\n ! compute HF time-sampling\n dt = hf_len / (hf_npts - 1)\n \n ! recompute number of points to closest 2**N number \n npts = hf_npts !related number of points\n\n ! check if this is a 2**N value (if not, adjust npts)\n exponent = log(real(npts)) / log(2.0)\n\n if (exponent /= nint(exponent)) npts = 2**(ceiling(exponent)) \n \n if (lf_len /= hf_len .or. hf_npts /= lf_npts) then\n call error_handling(4,'null','SAMPLING_CHECK (interpolation.f90)')\n endif\n \nelse if (modality_flag /= 0) then\n\n ! assume maximum frequency for coda waves as Nyquist frequency\n dt = 1 / (2 * fmax) !new time-step \n \n npts = nint(lf_len / dt) + 1 !related number of points\n\n ! check if this is a 2**N value (if not, adjust npts)\n exponent = log(real(npts)) / log(2.0)\n\n if (exponent /= nint(exponent)) npts = 2**(ceiling(exponent))\nendif\n\nEND SUBROUTINE sampling_check\n\n!===================================================================================================\n\nSUBROUTINE spline_interp(in_seis,time_len,interp_npts,orig_npts,out_seis)\n!-------------------------------------------------------------------------------------\n!\n! Description:\n!\n! Performs spline interpolation on given time-series using a different sampling rate.\n! Time series is assumed to be given in an 1 x npts array. \n!\n! Dependencies:\n!\n! Subroutines spline, splint\n!\n! References:\n!\n! Numerical Recipes\n!\n! Authors: W. Imperatori, M. Mai\n!\n! Modified: January 2009 (v1.3)\n!\n! Updated: February 2019 (v2.0)\n! Change dt_interp and dt_orig computations.\n!\nuse def_kind\nuse tmp_para;\nuse waveform, only: lf_dt,v_npts\n\nimplicit none \n\n! number of points of the new (interpolated) and original time-series\ninteger(kind=i_single),intent(in) :: interp_npts,orig_npts\n! time-length of the time-series\nreal(kind=r_single),intent(in) :: time_len\n! input time-series\nreal(kind=r_single),dimension(:),intent(in) :: in_seis !assumed-shape vec\n! output time-series\nreal(kind=r_single),dimension(:),intent(out):: out_seis !assumed-shape vec\n! local arrays for time vector and second derivative\nreal(kind=r_single),allocatable,dimension(:):: t_vec,sec_der\n! time-vector, time-steps of interpolated and original time-series\nreal(kind=r_single) :: t_interp,dt_interp,dt_orig\n! counter\ninteger(kind=i_single) :: j,n\n! parameters used for spline interpolation\nreal(kind=r_single),parameter :: yp1=2.0e20, ypn=2.0e20\n\n!------------------------------------------------------------------------------------\n\n! time-step of interpolated time-series\n!dt_interp = time_len / (interp_npts-1)\nn=ceiling(time_len/tmp_lf_len)\ndt_interp = tmp_lf_len*n / (v_npts - 1)\n\n! time-step of original time-series\n!dt_orig = time_len / (orig_npts-1)\n! dt_orig is from the actual dt from LF = lf_dt\ndt_orig = lf_dt\n\nif(.not.allocated(t_vec)) allocate(t_vec(orig_npts),sec_der(orig_npts)) \n\n!create original time vector\ndo j = 1,orig_npts\n t_vec(j) = dt_orig*(j-1)\nenddo\n\n! returns second derivative terms\ncall spline(t_vec,in_seis,orig_npts,yp1,ypn,sec_der)\n\n! loop over number of points for interpolated time-series\ndo j = 1,interp_npts\n\n t_interp = dt_interp*(j-1) !new time vector\n \n ! spline interpolation \n call splint(t_vec,in_seis,sec_der,orig_npts,t_interp,out_seis(j))\n \nenddo\n\n! deallocate temporary arrays \nif(allocated(t_vec)) deallocate(t_vec,sec_der)\n\n!<>--<>--<>--<>--<>--<>--<>--<>--<>--<>--<>--<>--<>--<>--<>--<>--<>--<>--<>--<>--<>--<>--<>--<>--<>-\n\nCONTAINS\n\n\n SUBROUTINE spline(x,y,n,yp1,ypn,y2)\n !---------------------------------------------------------------\n !\n ! Description:\n !\n ! Computes second derivative terms\n !\n ! Dependencies:\n !\n ! None\n !\n ! References:\n !\n ! Numerical Receipes\n ! \n ! Authors: W. Imperatori, M. Mai\n !\n ! Modified: January 2009 (v1.3)\n !\n\n implicit none\n\n ! x-values and y-values of input time-series\n real(kind=r_single),dimension(:),intent(in):: x,y\n ! second derivative terms\n real(kind=r_single),dimension(:),intent(out):: y2\n ! original time-series number or points\n integer(kind=i_single),intent(in):: n\n ! parameters for interpolation\n real(kind=r_single),intent(in):: yp1,ypn\n ! local counters, dummies and indexes\n real(kind=r_single),dimension(30000):: u\n real(kind=r_single):: p,qn,sig,un\n integer(kind=i_single):: i,k\n \n !--------------------------------------------------------------\n\n if (yp1.gt.1e20) then\n y2(1)=0.\n u(1)=0.\n else\n y2(1)=-0.5\n u(1)=(3./(x(2)-x(1)))*((y(2)-y(1))/(x(2)-x(1))-yp1)\n endif\n\n do i=2,n-1\n sig=(x(i)-x(i-1))/(x(i+1)-x(i-1))\n p=sig*y2(i-1)+2.\n y2(i)=(sig-1.)/p\n u(i)=(6.*((y(i+1)-y(i))/(x(i+1)-x(i))-(y(i)-y(i-1)) &\n /(x(i)-x(i-1)))/(x(i+1)-x(i-1))-sig*u(i-1))/p\n enddo\n \n if (ypn.gt.1e20) then\n qn=0.\n un=0.\n else\n qn=0.5\n un=(3./(x(n)-x(n-1)))*(ypn-(y(n)-y(n-1))/(x(n)-x(n-1)))\n endif\n\n y2(n)=(un-qn*u(n-1))/(qn*y2(n-1)+1.)\n\n do k=n-1,1,-1\n y2(k)=y2(k)*y2(k+1)+u(k)\n enddo\n \n END SUBROUTINE spline\n\n!<>--<>--<>--<>--<>--<>--<>--<>--<>--<>--<>--<>--<>--<>--<>--<>--<>--<>--<>--<>--<>--<>--<>--<>--<>-\n\n SUBROUTINE splint(xa,ya,y2a,n,x,y)\n !------------------------------------------------------------\n !\n ! Description:\n !\n ! Performs interpolation using spline\n !\n ! Dependencies:\n !\n ! None\n !\n ! References:\n !\n ! Numerical Receipes\n ! \n ! Authors: W. Imperatori, M. Mai\n !\n ! Modified: January 2009 (v1.3)\n !\n \n implicit none\n\n ! x-values and y-values of input time-series, second derivative terms\n real(kind=r_single),dimension(:),intent(in):: xa,ya,y2a\n ! original time-series number of points\n integer(kind=i_single),intent(in):: n\n ! x-value of new (interpolated) time-series\n real(kind=r_single),intent(in):: x\n ! y-value of new (interpolated) time-series\n real(kind=r_single),intent(out):: y\n ! local counter and dummies\n integer(kind=i_single):: k,khi,klo\n real(kind=r_single):: a,b,h\n\n !------------------------------------------------------------\n\n klo=1\n khi=n\n\n1 if (khi-klo.gt.1) then\n k=(khi+klo)/2\n \n if (xa(k).gt.x) then\n khi=k\n else\n klo=k\n endif\n goto 1\n endif\n\n h=xa(khi)-xa(klo)\n\n ! aborting execution\n if (h.eq.0.) call error_handling(4,'null','SPLINT (interpolation.f90)')\n \n \n a=(xa(khi)-x)/h\n b=(x-xa(klo))/h\n y=a*ya(klo)+b*ya(khi)+((a**3-a) * y2a(klo)+(b**3-b)*y2a(khi))*(h**2)/6.\n \n END SUBROUTINE splint\n\n \nEND SUBROUTINE spline_interp \n\n!===================================================================================================\n", "meta": {"hexsha": "2a478c2ce747ec19b64949fc743b418bb39e792e", "size": 11078, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "bbp/src/sdsu/bbtoolbox/interpolation.f90", "max_stars_repo_name": "ZhangHCFJEA/bbp", "max_stars_repo_head_hexsha": "33bd999cf8d719c49f9a904872c62f02eb5850d1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2017-10-31T09:16:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T23:44:29.000Z", "max_issues_repo_path": "bbp/src/sdsu/bbtoolbox/interpolation.f90", "max_issues_repo_name": "ZhangHCFJEA/bbp", "max_issues_repo_head_hexsha": "33bd999cf8d719c49f9a904872c62f02eb5850d1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 37, "max_issues_repo_issues_event_min_datetime": "2017-05-23T15:15:35.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-05T09:13:18.000Z", "max_forks_repo_path": "bbp/src/sdsu/bbtoolbox/interpolation.f90", "max_forks_repo_name": "ZhangHCFJEA/bbp", "max_forks_repo_head_hexsha": "33bd999cf8d719c49f9a904872c62f02eb5850d1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2017-09-21T17:43:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-29T06:34:30.000Z", "avg_line_length": 25.2922374429, "max_line_length": 100, "alphanum_fraction": 0.554161401, "num_tokens": 3217, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297781091839, "lm_q2_score": 0.7461389817407016, "lm_q1q2_score": 0.6719203716655664}} {"text": " FUNCTION BESSK0(X)\n REAL*8 Y,P1,P2,P3,P4,P5,P6,P7,\n * Q1,Q2,Q3,Q4,Q5,Q6,Q7\n DATA P1,P2,P3,P4,P5,P6,P7/-0.57721566D0,0.42278420D0,0.23069756D0,\n * 0.3488590D-1,0.262698D-2,0.10750D-3,0.74D-5/\n DATA Q1,Q2,Q3,Q4,Q5,Q6,Q7/1.25331414D0,-0.7832358D-1,0.2189568D-1,\n * -0.1062446D-1,0.587872D-2,-0.251540D-2,0.53208D-3/\n IF (X.LE.2.0) THEN\n Y=X*X/4.0\n BESSK0=(-LOG(X/2.0)*BESSI0(X))+(P1+Y*(P2+Y*(P3+\n * Y*(P4+Y*(P5+Y*(P6+Y*P7))))))\n ELSE\n Y=(2.0/X)\n BESSK0=(EXP(-X)/SQRT(X))*(Q1+Y*(Q2+Y*(Q3+\n * Y*(Q4+Y*(Q5+Y*(Q6+Y*Q7))))))\n ENDIF\n RETURN\n END\n", "meta": {"hexsha": "1690634bb14f48640e9aff47a3eaa1a8bae91296", "size": 654, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "Math3/NumRec/source/bessk0.for", "max_stars_repo_name": "domijin/MM3", "max_stars_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Math3/NumRec/source/bessk0.for", "max_issues_repo_name": "domijin/MM3", "max_issues_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Math3/NumRec/source/bessk0.for", "max_forks_repo_name": "domijin/MM3", "max_forks_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.4210526316, "max_line_length": 72, "alphanum_fraction": 0.503058104, "num_tokens": 353, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475746920261, "lm_q2_score": 0.7122321842389469, "lm_q1q2_score": 0.6718825036194148}} {"text": " SUBROUTINE DTRNS (NNH,SCOEF,LDIAG,TRIGS,ALP,RLAT,PHI) \nC \nC THIS SUBROUTINE PERFORMS INVERSE SPHERICAL HARMONIC TRANSFORMS \nC INTO FOURIER SPACE USING THE ASSOCIATED LEGENDRE POLYNOMIALS.\nC IT IS A REDUCED VERSION OF THE SHTRNS ROUTINE \nC \nC CALLED BY: EVAL\nC CALLS: DFT991\nC\nC REVISIONS:\nC 7-10-92 CHANGE TO CCM CODING CONVENTIONS (R. JAKOB)\nC\nC---- Model Parameters -------------------------------------------------\nC\n INCLUDE 'params.i'\nC\nC\nC------------ Arguments ------------------------------------------------\nC\nC Input\nC\nC SPECTRAL TRUNCATION PARAMETER\n INTEGER NNH\nC SPHERICAL HARMONIC COEFFICIENT ARRAY\n COMPLEX SCOEF(NALPH)\nC INDEX INTO SPECTRAL ARRAY\n INTEGER LDIAG(0:MAXH,2)\nC COEFFICIENTS FOR DISCRETE FOURIER TRANSFORM\n REAL TRIGS(MAXH+1,2)\nC ASSOC. LEGENDRE POLYNOMIALS\n REAL ALP(NALPH)\nC LATITUDE\n REAL RLAT\nC\nC Output\nC\nC COMPUTED FUNCTION VALUE AT GRIDPOINT\n REAL PHI\nC\nC------ Local Variables ------------------------------------------------\nC\n COMPLEX CEVEN(MAXH+1), CODD(MAXH+1) \nC\nC TEMPORARIES\nC\n INTEGER JM,JN,IS\nC\nC FOURIER COEFFICIENTS\nC\n COMPLEX X(MAXH+1)\nC \nC----- Executable Statements -------------------------------------------\nC \nC DETERMINE FOURIER COEFFICIENTS BY INVERSE LEGENDRE TRANSFORM. \nC VARY M AND N SO PROCEDURE MOVES ALONG DIAGONALS DENOTED BY \nC INDEX JN. M IS GIVEN BY (JM-1) WHILE N IS GIVEN BY (JN+M). \nC FIRST ACCUMULATE EVEN WAVENUMBER CONTRIBUTION \nC \n DO 180 JN=0,NNH,2 \n IS = LDIAG(JN,2) \nC \nC THIS DETOUR HELPS AVOID THE NEED TO SEPARATELY ZERO CEVEN \nC \n IF (JN .EQ. 0) THEN \n DO 150 JM=1,LDIAG(0,1) \n CEVEN(JM) = SCOEF(IS+JM)*ALP(IS+JM) \n 150 CONTINUE \nC \n ELSE \nC \n DO 170 JM=1,LDIAG(JN,1)\n CEVEN(JM) = CEVEN(JM) + SCOEF(IS+JM)*ALP(IS+JM) \n 170 CONTINUE \nC\n ENDIF\n 180 CONTINUE \nC \nC NEXT ACCUMULATE ODD WAVENUMBER CONTRIBUTION \nC \n DO 215 JN=1,NNH,2 \n IS = LDIAG(JN,2) \nC \nC THIS DETOUR HELPS AVOID THE NEED TO SEPARATELY ZERO CODD \nC \n IF (JN .EQ. 1) THEN\n DO 190 JM=1,LDIAG(1,1) \n CODD (JM) = SCOEF(IS+JM)*ALP(IS+JM) \n 190 CONTINUE \nC \nC ACCOUNT FOR THE FACT THAT THE FIRST ODD DIAGONAL MAY BE \nC SHORTER THAN THE FIRST EVEN DIAGONAL (PART OF THE GAME \nC TO AVOID EXPLICITLY ZEROING THE ENTIRE CODD ARRAY) \nC \n IF (LDIAG(1,1) .LT. LDIAG(0,1)) THEN \n DO 200 JM=LDIAG(1,1)+1, LDIAG(0,1) \n CODD (JM) = (0.0,0.0) \n 200 CONTINUE \nC \n ENDIF \n ELSE\nC \n DO 210 JM=1,LDIAG(JN,1) \n CODD (JM) = CODD (JM) + SCOEF(IS+JM)*ALP(IS+JM) \n 210 CONTINUE \nC\n ENDIF\n 215 CONTINUE \nC \nC COMBINE CONTRIBUTIONS OF EVEN AND ODD WAVENUMBERS TO OBTAIN \nC COMPLEX FOURIER COEFFICIENTS, FOLLOWED BY INVERSE FFT \nC \n DO 225 JM=1,LDIAG(0,1) \n IF (RLAT .GE. 0.0) THEN\n X(JM) = CEVEN(JM) + CODD(JM) \n ELSE\n X(JM) = CEVEN(JM) - CODD(JM)\n ENDIF\n 225 CONTINUE \nC \nC INVERSE FOURIER TRANSFORMATION \nC \n CALL DFT991(X,TRIGS,MAXH,LDIAG(0,1),PHI)\nC\n RETURN \nC \n END \n", "meta": {"hexsha": "b0c6e13400f59ea0071785b81b52aa3ce5bf876e", "size": 6142, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/dtrns.f", "max_stars_repo_name": "jhaoli/shallow_spectral", "max_stars_repo_head_hexsha": "a2580f9baad596a56efaaae20b80e1bd543c2502", "max_stars_repo_licenses": ["NetCDF"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-06-19T02:24:41.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-19T02:24:41.000Z", "max_issues_repo_path": "src/dtrns.f", "max_issues_repo_name": "jhaoli/shallow_spectral", "max_issues_repo_head_hexsha": "a2580f9baad596a56efaaae20b80e1bd543c2502", "max_issues_repo_licenses": ["NetCDF"], "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/dtrns.f", "max_forks_repo_name": "jhaoli/shallow_spectral", "max_forks_repo_head_hexsha": "a2580f9baad596a56efaaae20b80e1bd543c2502", "max_forks_repo_licenses": ["NetCDF"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.3622047244, "max_line_length": 80, "alphanum_fraction": 0.3008791924, "num_tokens": 1183, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248225478306, "lm_q2_score": 0.7154240079185318, "lm_q1q2_score": 0.671800902082157}} {"text": "! subroutine geod2geo\nSUBROUTINE geod2geo(yin,orb_elements,spheroid,phip,istat)\n! This routine converts a scalar from geodetic latitude\n! in degrees to geocentric in radians\n\n! * Re-written as an independent subroutine by JS, Aug 2014\n\n! Inputs:\n! yin\n! orb_elements\n! 1. Orbital inclination (degrees)\n! 2. Semi_major radius (m)\n! 3. Angular velocity (rad sec-1)\n! spheroid\n! 1. Spheroid major axis\n! 2. Inverse flattening\n! 3. Eccentricity squared\n! 4. Earth rotational angular velocity rad/sec\n\n! Outputs:\n! phip\n! istat\n\n use sys_variables, only : pi, d2r, r2d\n\n implicit none\n\n double precision yin, phip\n double precision orb_elements(3), spheroid(4)\n double precision orad\n double precision asph, e2\n double precision rn, temp\n integer istat\n\n! Satellite orbital paramaters\n! semi_major radius (m)\n orad = orb_elements(2)\n\n! Spheroid paramaters\n! Spheroid major axis\n! Eccentricity squared\n asph = spheroid(1)\n e2 = spheroid(3)\n\n! Initialise the return status\n istat = 0\n\n temp = dble(yin)*d2r\n RN = asph/sqrt(1.0d0-e2*sin(temp)**2)\n phip = temp-asin(RN*e2*sin(temp)*cos(temp)/orad)\n\n return\n\nEND SUBROUTINE geod2geo\n", "meta": {"hexsha": "4688c40403f2f71356024b567463a6581ae422df", "size": 1293, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "wagl/f90_sources/geod2geo.f90", "max_stars_repo_name": "Oceancolour-RG/wagl", "max_stars_repo_head_hexsha": "f002a1c0a373d21758d44d2a808bdfd755d90226", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2018-05-30T23:42:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-25T14:21:46.000Z", "max_issues_repo_path": "wagl/f90_sources/geod2geo.f90", "max_issues_repo_name": "Oceancolour-RG/wagl", "max_issues_repo_head_hexsha": "f002a1c0a373d21758d44d2a808bdfd755d90226", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 52, "max_issues_repo_issues_event_min_datetime": "2018-02-20T05:31:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-23T23:38:15.000Z", "max_forks_repo_path": "wagl/f90_sources/geod2geo.f90", "max_forks_repo_name": "Oceancolour-RG/wagl", "max_forks_repo_head_hexsha": "f002a1c0a373d21758d44d2a808bdfd755d90226", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2018-02-20T05:08:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-12T23:16:41.000Z", "avg_line_length": 23.5090909091, "max_line_length": 61, "alphanum_fraction": 0.6450116009, "num_tokens": 398, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248259606259, "lm_q2_score": 0.7154240018510026, "lm_q1q2_score": 0.6718008988261922}} {"text": "PROGRAM polyplot\n IMPLICIT NONE\n\n REAL :: x,y,f\n INTEGER :: i,j\n\n OPEN(unit=20,file='mydata.dat')\n\n ! write out function f(x,y) = exp(-x^2 + y^2))sin(xy) for -2 < x < 2 and -2 < y < 2\n\n DO i=-20,20,1\n x=i*0.1\n Do j=-20,20,1\n y=j*0.1\n f=exp(-(x**2 + y**2))*sin(x*y)\n WRITE(20,*) x, y, f\n END DO\n WRITE(20,*) \" \"\n END DO\nEND PROGRAM polyplot\n", "meta": {"hexsha": "cb5e1df8762c48fc877138d588d95ad8d4c456b1", "size": 374, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Visualisation.f90", "max_stars_repo_name": "WilliamHoltam/fortran-basics", "max_stars_repo_head_hexsha": "069212620623c256b578c148fedea710cab7afbc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Visualisation.f90", "max_issues_repo_name": "WilliamHoltam/fortran-basics", "max_issues_repo_head_hexsha": "069212620623c256b578c148fedea710cab7afbc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Visualisation.f90", "max_forks_repo_name": "WilliamHoltam/fortran-basics", "max_forks_repo_head_hexsha": "069212620623c256b578c148fedea710cab7afbc", "max_forks_repo_licenses": ["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.8095238095, "max_line_length": 85, "alphanum_fraction": 0.5106951872, "num_tokens": 159, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094145755219, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6717799120187959}} {"text": "module fcn_cylindricalduct_eigenfunction\n use mod_kinds, only: rk, ik\n use mod_constants, only: HALF, ZERO\n use type_point, only: point_t\n use type_function, only: function_t\n implicit none\n\n\n\n !> Function for computing the eigenfunction for cylindrical duct modes.\n !! This could be passed to a root-finding routine to find the zeros,\n !! which are the cylindrical duct mode eigenvalues.\n !! \n !! \\f$ f(alpha_{mn}) = J'_m (alpha_{mn}) \\f$\n !!\n !! @author Nathan A. Wukie\n !! @date 4/14/2016\n !!\n !!\n !------------------------------------------------------------------------\n type, extends(function_t) :: cylindricalduct_eigenfunction_f\n\n contains\n procedure :: init\n procedure :: compute\n end type cylindricalduct_eigenfunction_f\n !************************************************************************\n\n\n\n\n\n\n\ncontains\n\n\n\n !> Initialization for eigenfunction class\n !!\n !! @author Nathan A. Wukie\n !! @date 4/14/2016\n !!\n !-------------------------------------------------------------------------\n subroutine init(self)\n class(cylindricalduct_eigenfunction_f), intent(inout) :: self\n\n ! Set function name\n call self%add_name(\"cylindricalduct_eigenfunction\")\n\n ! Add option\n !\n ! The option 'm' here corresponds to m the azimuthal mode order\n !\n call self%add_option('m', ZERO)\n\n end subroutine init\n !*************************************************************************\n\n \n\n\n !> Function implementation for cylindrical duct eigenfunction\n !!\n !! \\f$ f(alpha_{mn}) = J'_m (alpha_{mn}) \\f$\n !!\n !! @author Nathan A. Wukie\n !! @date 4/14/2016\n !!\n !--------------------------------------------------------------------------\n impure elemental function compute(self,time,coord) result(val)\n class(cylindricalduct_eigenfunction_f), intent(inout) :: self\n real(rk), intent(in) :: time\n type(point_t), intent(in) :: coord\n\n real(rk) :: m\n real(rk) :: x\n real(rk) :: val\n\n ! Get x\n x = coord%c1_\n\n ! Get m\n m = self%get_option_value('m')\n\n\n ! We need the (derivative of the bessel function Jm) = Jm'\n !\n ! Jm'(x) = -J1(x) for m=0\n ! Jm'(x) = 1/2( Jm-1(x) - Jm+1(x) ) for m/=0\n !\n if ( int(m) == 0 ) then\n val = -bessel_j1(x)\n else\n val = HALF*( bessel_jn(int(m-1),x) - bessel_jn(int(m+1),x) )\n end if\n\n\n\n end function compute\n !**************************************************************************\n\n\n\n\n\n\n\n\n\n\nend module fcn_cylindricalduct_eigenfunction\n", "meta": {"hexsha": "52b58cd155b0bdba32758994e4caf8c889c43510", "size": 2867, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/equations/Acoustics/DuctModes/fcn_cylindricalduct_eigenfunction.f90", "max_stars_repo_name": "wanglican/ChiDG", "max_stars_repo_head_hexsha": "d3177b87cc2f611e66e26bb51616f9385168f338", "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/equations/Acoustics/DuctModes/fcn_cylindricalduct_eigenfunction.f90", "max_issues_repo_name": "haohb/ChiDG", "max_issues_repo_head_hexsha": "d3177b87cc2f611e66e26bb51616f9385168f338", "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/equations/Acoustics/DuctModes/fcn_cylindricalduct_eigenfunction.f90", "max_forks_repo_name": "haohb/ChiDG", "max_forks_repo_head_hexsha": "d3177b87cc2f611e66e26bb51616f9385168f338", "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": 25.3716814159, "max_line_length": 79, "alphanum_fraction": 0.4513428671, "num_tokens": 706, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093946927837, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6717798921018695}} {"text": " Program Biorthog \n!\n! This program perfoms a borthogonalization between alpha and beta\n! orbitals obtained from an unrestricted Hartree-Fock or Density \n! Functional Theory Calculation.\n!\n Use MQC_Algebra\n Use MQC_Gaussian\n!\n!\n! Variable Declarations...\n!\n Implicit None\n Character(Len=256)::FileName\n Integer::IOut=6,NBasis=0,NElectrons=0,Multiplicity=0,NAlpha=0, &\n NBeta=0,NOccA=0,NOccB=0,NVirtA=0,NVirtB=0,ND=0,NSingA=0,NSingB=0, &\n I=0,Ind=0,NVirtP=0,IPrint=1 \n Real::Thresh=0.1d0\n Type(MQC_Molecule_Data)::MoleculeInfo\n Type(MQC_MO_Coefficients)::MO_Coeff,Biorthog_Orbs\n Type(MQC_Fock_Matrix)::Fock_Matrix\n Type(MQC_Core_Hamiltonian)::Core_Hamiltonian\n Integer,Dimension(:),Allocatable::Basis2AtomMap\n Real,Dimension(:),Allocatable::A_SVals,Biorthog_Overlap\n Real,Dimension(:,:),Allocatable::Overlap_Matrix,A_UVecs,A_VVecs, &\n MO_Overlap\n!\n!\n! Get the user-defined filename from the command line and then call the\n! routine that reads the Gaussian matrix file.\n!\n Call Get_Command_Argument(1,FileName)\n Call MQC_Gaussian_Read_Matrix_File(.True.,FileName,MoleculeInfo,NBasis, &\n NElectrons,Multiplicity,Basis2AtomMap,Overlap_Matrix,MO_Coeff,Core_Hamiltonian, &\n Fock_Matrix)\n\n If(IPrint.ge.1) then \n Write(*,*)' Back from Read_Gaussian_Matrix_File'\n Write(*,*)' NAtoms = ',MoleculeInfo%NAtoms\n Write(*,*)' NBasis = ',NBasis\n Write(*,*)' NElectrons = ',NElectrons\n Write(*,*)' Multiplicity = ',Multiplicity\n EndIf\n\n NAlpha = (NElectrons + (Multiplicity-1))/2\n NBeta = NElectrons-NAlpha\n NOccA = NAlpha\n NOccB = NBeta\n NVirtA = NBasis-NAlpha\n NVirtB = NBasis-NBeta\n\n If(IPrint.ge.1) then \n Write(*,*)' NAlpha = ',NAlpha\n Write(*,*)' NBeta = ',NBeta\n Write(*,*)' NOccA = ',NOccA\n Write(*,*)' NOccB = ',NOccB\n Write(*,*)' NVirtA = ',NVirtA\n Write(*,*)' NVirtB = ',NVirtB\n Call Print_Vector(IOut,MoleculeInfo%Atomic_Numbers, &\n 'Atomic Numbers')\n Call Print_Vector(IOut,MoleculeInfo%Atomic_Masses, &\n 'Atomic Masses')\n Call Print_Vector(IOut,MoleculeInfo%Atomic_Charges, &\n 'Atomic Charges')\n Call Print_Matrix(IOut,MoleculeInfo%Cartesian_Coordinates, &\n 'Cartesian Coordinates')\n Call Print_Vector(IOut,Basis2AtomMap,'Basis-Atom Mapping')\n Call Print_Matrix(IOut,Overlap_Matrix,'Overlap Matrix')\n Call Print_Matrix(IOut,Core_Hamiltonian%Alpha,'Core Hamiltonian Alpha')\n Call Print_Matrix(IOut,Core_Hamiltonian%Beta,'Core Hamiltonian Beta')\n Call Print_Matrix(IOut,Fock_Matrix%Alpha,'Alpha Fock Matrix')\n Call Print_Matrix(IOut,Fock_Matrix%Beta,'Beta Fock Matrix')\n Call Print_Matrix(IOut,MO_Coeff%Alpha,'Alpha MO Coefficient Matrix')\n Call Print_Matrix(IOut,MO_Coeff%Beta,'Beta MO Coefficient Matrix')\n EndIf\n!\n! Allocate arrays in which to collect results\n!\n Allocate(Biorthog_Overlap(NBasis))\n Call MQC_Gaussian_Fill_MO_Coefficients(NBasis,MO_Coeff%Alpha, &\n MO_Coeff%Beta,Biorthog_Orbs)\n!\n! Do SVD on occupied alpha and beta orbitals and then rotate MO coefficients\n!\n Write(*,*) 'Occupied Alpha - Occupied Beta'\n Allocate(MO_Overlap(NOccA,NOccB))\n MO_Overlap = MatMul(MatMul(Transpose(Biorthog_Orbs%Alpha(:,1:NOccA)),Overlap_Matrix), &\n Biorthog_Orbs%Beta(:,1:NOccB))\n If(IPrint.ge.1) Call Print_Matrix(IOut,MO_Overlap,' MO Overlap')\n Call MQC_Matrix_SVD(MO_Overlap,A_UVecs,A_VVecs,A_SVals)\n If(IPrint.ge.1) then \n Call Print_Matrix(IOut,A_UVecs,'U Vectors')\n Call Print_Matrix(IOut,A_VVecs,'V Vectors')\n EndIf\n Call Print_Vector(IOut,A_SVals,'Singular Values')\n Biorthog_Orbs%Alpha(:,1:NOccA) = MatMul(Biorthog_Orbs%Alpha(:,1:NOccA),A_UVecs) \n Biorthog_Orbs%Beta(:,1:NOccB) = MatMul(Biorthog_Orbs%Beta(:,1:NOccB),Transpose(A_VVecs)) \n Biorthog_Overlap(1:Size(A_SVals,1)) = A_SVals\n If(IPrint.ge.1) then \n Call Print_Matrix(IOut,Biorthog_Orbs%Alpha(:,1:NOccA),'Biorthogonalized Alpha Orbitals')\n Call Print_Matrix(IOut,Biorthog_Orbs%Beta(:,1:NOccB),'Biorthogonalized Beta Orbitals')\n EndIf\n Do I = 1, Min(NOccA,NOccB) \n If(A_SVals(I).ge.Thresh) ND = ND + 1\n EndDo\n! Gaussian code has this always set so we never have singly occupied beta\n ND = NBeta\n NSingA = NAlpha - ND\n NSingB = NBeta - ND\n!\n! Do SVD on left-over alpha occupieds and beta virtals and then rotate MO coefficients\n!\n If(NSingA.gt.0) then\n Write(*,*) 'Singly Occupied Alpha - Virtual Beta'\n Deallocate(MO_Overlap,A_SVals,A_VVecs,A_UVecs)\n Allocate(MO_Overlap(NSingA,NVirtB))\n MO_Overlap = MatMul(MatMul(Transpose(Biorthog_Orbs%Alpha(:,ND+1:ND+NSingA)),Overlap_Matrix), &\n Biorthog_Orbs%Beta(:,NOccB+1:NBasis))\n If(IPrint.ge.1) Call Print_Matrix(IOut,MO_Overlap,' MO Overlap')\n Call MQC_Matrix_SVD(MO_Overlap,A_UVecs,A_VVecs,A_SVals)\n If(IPrint.ge.1) then \n Call Print_Matrix(IOut,A_UVecs,'U Vectors')\n Call Print_Matrix(IOut,A_VVecs,'V Vectors')\n EndIf\n Call Print_Vector(IOut,A_SVals,'Singular Values')\n Biorthog_Orbs%Alpha(:,ND+1:ND+NSingA) = MatMul(Biorthog_Orbs%Alpha(:,ND+1:ND+NSingA),A_UVecs) \n Biorthog_Orbs%Beta(:,NOccB+1:NOccB+NVirtB) = MatMul(Biorthog_Orbs%Beta(:,NOccB+1:NOccB+NVirtB),Transpose(A_VVecs)) \n Biorthog_Overlap(ND+1:ND+NSingA) = A_SVals\n If(IPrint.ge.1) then \n Call Print_Matrix(IOut,Biorthog_Orbs%Alpha(:,ND+1:ND+NSingA),'Biorthogonalized Alpha Orbitals')\n Call Print_Matrix(IOut,Biorthog_Orbs%Beta(:,NOccB+1:NOccB+NVirtB),'Biorthogonalized Beta Orbitals')\n EndIf\n EndIf\n!\n! Do SVD on left-over beta occupieds and alpha virtals and then rotate MO coefficients\n!\n If(NSingB.gt.0) then\n Write(*,*) 'Singly Occupied Beta - Virtual Alpha'\n Deallocate(MO_Overlap,A_SVals,A_VVecs,A_UVecs)\n Allocate(MO_Overlap(NVirtA,NSingB))\n MO_Overlap = MatMul(MatMul(Transpose(Biorthog_Orbs%Alpha(:,NOccA+1:NBasis)),Overlap_Matrix), &\n Biorthog_Orbs%Beta(:,ND+1:ND+NSingB))\n If(IPrint.ge.1) Call Print_Matrix(IOut,MO_Overlap,' MO Overlap')\n Call MQC_Matrix_SVD(MO_Overlap,A_UVecs,A_VVecs,A_SVals)\n If(IPrint.ge.1) then \n Call Print_Matrix(IOut,A_UVecs,'U Vectors')\n Call Print_Matrix(IOut,A_VVecs,'V Vectors')\n EndIf\n Call Print_Vector(IOut,A_SVals,'Singular Values')\n Biorthog_Orbs%Alpha(:,NOccA+1:NOccA+NVirtA) = MatMul(Biorthog_Orbs%Alpha(:,NOccA+1:NOccA+NVirtA),A_UVecs) \n Biorthog_Orbs%Beta(:,ND+1:ND+NSingB) = MatMul(Biorthog_Orbs%Beta(:,ND+1:ND+NSingB),Transpose(A_VVecs)) \n Biorthog_Overlap(ND+NSingA+1:ND+NSingA+NSingB) = A_SVals\n If(IPrint.ge.1) then \n Call Print_Matrix(IOut,Biorthog_Orbs%Alpha(:,ND+1:ND+NSingA),'Biorthogonalized Alpha Orbitals')\n Call Print_Matrix(IOut,Biorthog_Orbs%Beta(:,NOccB+1:NOccB+NVirtB),'Biorthogonalized Beta Orbitals')\n EndIf\n EndIf\n!\n! Do SVD on alpha and beta virtal orbitals and then rotate MO coefficients\n!\n Ind = ND + NSingA + NSingB\n NVirtP = NBasis - Ind\n If(NVirtP.gt.0) then\n Write(*,*) 'Virtual Alpha - Virtual Beta'\n Deallocate(MO_Overlap,A_SVals,A_VVecs,A_UVecs)\n Allocate(MO_Overlap(NVirtP,NVirtP))\n MO_Overlap = MatMul(MatMul(Transpose(Biorthog_Orbs%Alpha(:,Ind+1:Ind+NVirtP)),Overlap_Matrix), &\n Biorthog_Orbs%Beta(:,Ind+1:Ind+NVirtP))\n If(IPrint.ge.1) Call Print_Matrix(IOut,MO_Overlap,' MO Overlap')\n Call MQC_Matrix_SVD(MO_Overlap,A_UVecs,A_VVecs,A_SVals)\n If(IPrint.ge.1) then \n Call Print_Matrix(IOut,A_UVecs,'U Vectors')\n Call Print_Matrix(IOut,A_VVecs,'V Vectors')\n EndIf\n Call Print_Vector(IOut,A_SVals,'Singular Values')\n Biorthog_Orbs%Alpha(:,NOccA+1:NOccA+NVirtA) = MatMul(Biorthog_Orbs%Alpha(:,Ind+1:Ind+NVirtP),A_UVecs) \n Biorthog_Orbs%Beta(:,Ind+1:Ind+NVirtP) = MatMul(Biorthog_Orbs%Beta(:,Ind+1:Ind+NVirtP),Transpose(A_VVecs)) \n Biorthog_Overlap(Ind+1:Ind+NVirtP) = A_SVals\n If(IPrint.ge.1) then \n Call Print_Matrix(IOut,Biorthog_Orbs%Alpha(:,Ind+1:Ind+NVirtP),'Biorthogonalized Alpha Orbitals')\n Call Print_Matrix(IOut,Biorthog_Orbs%Beta(:,Ind+1:Ind+NVirtP),'Biorthogonalized Beta Orbitals')\n EndIf\n EndIf\n!\n Call Print_Matrix(IOut,Biorthog_Orbs%Alpha,'Biorthogonalized Alpha Orbitals')\n Call Print_Matrix(IOut,Biorthog_Orbs%Beta,'Biorthogonalized Beta Orbitals')\n Call Print_Vector(IOut,Biorthog_Overlap,'Biorthogonal Overlap')\n!\n 999 End Program Biorthog\n", "meta": {"hexsha": "40171f0d723e72af1697ecee07dde2989477687c", "size": 8890, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "examples/biorthog/biorthog.f03", "max_stars_repo_name": "Abdul-Zamani/mqcPack", "max_stars_repo_head_hexsha": "19d751801e437291c15fe8de835da50dfd31c802", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-02-04T05:38:55.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-11T03:49:41.000Z", "max_issues_repo_path": "examples/biorthog/biorthog.f03", "max_issues_repo_name": "Abdul-Zamani/mqcPack", "max_issues_repo_head_hexsha": "19d751801e437291c15fe8de835da50dfd31c802", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 19, "max_issues_repo_issues_event_min_datetime": "2019-11-11T21:27:49.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-18T13:00:16.000Z", "max_forks_repo_path": "examples/biorthog/biorthog.f03", "max_forks_repo_name": "Abdul-Zamani/mqcPack", "max_forks_repo_head_hexsha": "19d751801e437291c15fe8de835da50dfd31c802", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 27, "max_forks_repo_forks_event_min_datetime": "2018-01-18T16:07:20.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-28T22:03:26.000Z", "avg_line_length": 46.7894736842, "max_line_length": 123, "alphanum_fraction": 0.6752530934, "num_tokens": 2862, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810511092411, "lm_q2_score": 0.7090191460821871, "lm_q1q2_score": 0.6717113038719189}} {"text": " FUNCTION bessk1(x)\r\n REAL bessk1,x\r\nCU USES bessi1\r\n REAL bessi1\r\n DOUBLE PRECISION p1,p2,p3,p4,p5,p6,p7,q1,q2,q3,q4,q5,q6,q7,y\r\n SAVE p1,p2,p3,p4,p5,p6,p7,q1,q2,q3,q4,q5,q6,q7\r\n DATA p1,p2,p3,p4,p5,p6,p7/1.0d0,0.15443144d0,-0.67278579d0,\r\n *-0.18156897d0,-0.1919402d-1,-0.110404d-2,-0.4686d-4/\r\n DATA q1,q2,q3,q4,q5,q6,q7/1.25331414d0,0.23498619d0,-0.3655620d-1,\r\n *0.1504268d-1,-0.780353d-2,0.325614d-2,-0.68245d-3/\r\n if (x.le.2.0) then\r\n y=x*x/4.0\r\n bessk1=(log(x/2.0)*bessi1(x))+(1.0/x)*(p1+y*(p2+y*(p3+y*(p4+y*\r\n *(p5+y*(p6+y*p7))))))\r\n else\r\n y=2.0/x\r\n bessk1=(exp(-x)/sqrt(x))*(q1+y*(q2+y*(q3+y*(q4+y*(q5+y*(q6+y*\r\n *q7))))))\r\n endif\r\n return\r\n END\r\n", "meta": {"hexsha": "a874c77509573305786996bd03e5187b75c55c3c", "size": 765, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/bessk1.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/bessk1.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/bessk1.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": 34.7727272727, "max_line_length": 73, "alphanum_fraction": 0.5307189542, "num_tokens": 387, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810525948927, "lm_q2_score": 0.7090191337850932, "lm_q1q2_score": 0.6717112932752406}} {"text": "C> \\file shoot.f\nC> \\brief Solver routines for eigenvalue shooting and utilities \nC> \\author S. Scott Collis\nC***********************************************************************\nC> \\author S. Scott Collis\nC>\nC> \\brief Solve eigenvalue problem using Godunov-Conte method\nC>\nC> \\details First order linear boundary value problem solver \nC> using Conte's method. Fourth order Runge-Kutta is used for \nC> time advancement\nC>\nC> \\param[in] nstep number of integration steps between t0 and tf\nC> \\param[in] n number of ODEs to integrate\nC> \\param[in] r number of particular solutions \nC> \\param[in] yo starting values\nC> \\param[in] yf ending values\nC> \\param[in] to Interval start value\nC> \\param[in] tf Interval end value\nC> \\param[in,out] c Current eigenvalue\nC> \\param[in] eigfun Whether to output eigenfunction at the end\nC> \\param[in] FHOMO Subroutine for homogeneous equation\nC> \\param[in] FPART Subroutine for particular equation\nC> \\param[in] INPROD Function to compute inner product\nC***********************************************************************\n subroutine CONTE(nstep, n, r, yo, yf, to, tf, c, eigfun,\n & FHOMO, FPART, INPROD)\nC***********************************************************************\n integer nstep, n, r\n complex yo(n), yf(n)\n real to, tf, h\n complex c\n logical eigfun\n complex INPROD\n external INPROD, FHOMO, FPART\nC***********************************************************************\n integer i, m, q, s, mi, mj, qend, IPVT(n-r), icount\n real t, tq(0:nstep)\n complex B(n-r,0:nstep), err, cold, ctemp\n complex U(n,n-r,0:nstep), P(n-r,n-r,0:nstep), z(n,n-r)\n complex y(n,0:nstep), v(n,0:nstep), w(n), omega(n,0:nstep)\n complex eta(n), A(n,n-r), x(n), FAC(n-r,n-r), det1, det\n complex olderr, ut(n,n-r), fd, vmax\n complex cm1, cm2, errm1, errm2, qt, At, Bt, Ct, Utemp(n)\n real test, testalpha, pi, det2, AI(n,n-r), angle\n real aa, bb, cc, fdxr, fdxi, fdyr, fdyi\n logical norm\n real errtol, maxcount, eigtol\nC***********************************************************************\nc\nc initialize variables\nc\n errtol = 1.0e-15\n maxcount = 20\n eigtol = 1.0e-15\nc\nc set the normalization constraint\nc\n pi = ACOS(-1.0)\nc\nc Orthonormalize when angle is greater than testalpha\nc angle = [0,90] degrees (10 deg seems good)\nc\n angle = 10.0\n testalpha = angle*pi/180.0\nc\nc compute the step size\nc \n h = (tf-to)/nstep\nc\nc Begin the eigenvalue iteration loop\nc\n icount = 1\n err = 1.0\n cm1 = c + 1.0\n do while ((abs(err) .ge. errtol .and. icount .le. maxcount) .and.\n & (abs(c-cm1) .ge. eigtol) )\nc\nc q = number of normalizations\nc qend = total number of normalizations\nc tq = time at normalization q\nc\n q = 0\n tq(0) = to\nc\nc Set the Homogeneous initial conditions\nc\n do m = 1, n-r\n do i = 1, n\n if (i .eq. r+m) then\n u(i,m,0) = 1.0\n else\n u(i,m,0) = 0.0\n end if\n end do\n end do\nc\nc Set the particular initial conditions\nc\n do i = 1, r\n v(i,0) = yo(i)\n end do\n do i = r+1, n\n v(i,0) = 0.0\n end do\nc\nc Integrate the homo. and particular equations\nc \n do k = 1, nstep\n t = to + h*k\nc\nc Loop thru all homogeneous solutions\nc\n do m = 1, n-r\n#ifdef USE_RKCK45\n call CRKCK45(n, U(1,m,k-1), U(1,m,k), t-h, h, FHOMO)\n#else\n call CRK4(n, U(1,m,k-1), U(1,m,k), t-h, h, FHOMO)\n#endif\n end do\nc\nc Now the particular solution\nc\n#ifdef USE_RKCK45\n call CRKCK45(n, v(1,k-1), v(1,k), t-h, h, FPART)\n#else\n call CRK4(n, v(1,k-1), v(1,k), t-h, h, FPART)\n#endif\nc\nc Check to see it orthonomalization is required\nc \n norm = .false.\n do mi = 1, n-r\n do mj = 1, n-r\n if (mi .ne. mj) then\n aa = ABS(inprod(n, U(1,mi,k), U(1,mi,k)))\n bb = ABS(inprod(n, U(1,mj,k), U(1,mj,k)))\n cc = ABS(inprod(n, U(1,mi,k), U(1,mj,k)))\n#ifdef USE_ANALYTIC_INPROD\n test = ACOS(MIN(1.0,ABS(cc)/SQRT(aa*bb)))\n#else\n test = ACOS(ABS(cc)/SQRT(aa*bb))\n#endif\n if (test .le. testalpha) norm = .true.\n#ifdef VERBOSE\n write (*,*) k, mi, mj, 180.0*test/pi, \n & 180.0*testalpha/pi, norm\n#endif\n end if\n end do\n end do\nc\nc Perform normalization\nc \nc if (norm .or. (k .eq. nstep) .or. (mod(k,10) .eq. 0) ) then\n if (norm .or. (k .eq. nstep)) then\n q = q + 1\n tq(q) = t\n if (k .eq. nstep) qend = q\nc\nc Gram-Schmidt\nc\n w(1) = SQRT(inprod(n, U(1,1,k), U(1,1,k)))\n do i = 1, n\n z(i,1) = U(i,1,k)/w(1)\n end do\n do mi = 2, (n-r)\n do i = 1, n\n eta(i) = U(i,mi,k)\n end do\n do mj = mi-1, 1, -1\n do i = 1, n\n eta(i) = eta(i) - inprod(n, U(1,mi,k), z(1,mj))*z(i,mj)\n end do\n end do\n w(mi) = SQRT(inprod(n, eta, eta))\n do i = 1, n\n z(i,mi) = eta(i)/w(mi)\n end do\n end do\nc\nc Now I have the orthonormal basis in z and \nc the norms in w so I can compute the P orthonormalization \nc matrix\nc\n do j = 1, n-r\n do i = 1, j\n if (j .eq. i) then\n P(j,i,q) = 1.0/w(j)\n else\n P(j,i,q) = 0.0\n do s = i, j-1\n P(j,i,q) = P(j,i,q)-inprod(n,U(1,j,k),z(1,s))/w(j)*\n & P(s,i,q)\n end do\n end if\n end do\n end do\nc\nc Check the P matrix\nc\n if (.false.) then\n do i = 1, n\n do m = 1, n-r\n ut(i,m) = 0.0\n do j = 1, n-r\n ut(i,m) = ut(i,m) + U(i,j,k)*P(m,j,q)\n end do\n end do\n end do\n do i = 1,n\n write (*,*) i,(ut(i,m), m = 1, n-r)\n end do\n write (*,*)\n do i = 1,n\n write (*,*) i,( z(i,m), m = 1, n-r)\n end do\n write (*,*)\n write (*,*)\n end if\nc\nc Now update the U matrix with the orthonormal values\nc \n do i = 1, n\n do m = 1, n-r\n U(i,m,k) = z(i,m)\n end do\n end do\nc\nc Form the orthogonal complement of the particular solution\nc\n do j = 1, n-r\n omega(j,q) = inprod(n, v(1,k), U(1,j,k))\n end do\n do i = 1, n\n do j = 1, n-r\n v(i,k) = v(i,k) - U(i,j,k)*omega(j,q)\n end do\n end do\n \n end if\n end do\nc\nc write out the current solutions\nc\n#ifdef VERBOSE_SOLUTIONS\n do k = 1, nstep\n t = to + h*k\n write (20,10) t,REAL(U(1,1,k)),AIMAG(U(1,1,k)),REAL(U(1,2,k)),\n & AIMAG(U(1,2,k)),REAL(v(1,k)),AIMAG(v(1,k))\n 10 format (1x,7(ES16.8E3,1x))\n end do\n#endif\nc\nc check boundary conditions\nc\n if (.true.) then\nc\nc strictly enforce the zero BC\nc\n B(1,qend) = -U(1,2,nstep)/U(1,1,nstep)\n B(2,qend) = 1.0\n else\nc\nc strictly enforce the zero slope BC\nc\n B(1,qend) = 1.0\n B(2,qend) = -U(2,1,nstep)/U(2,2,nstep)\n end if\n#ifdef CHECK_DETERMINATE\nc\nc Check the determinate (requires IMSL)\nc\n do i = 1, n \n x(i) = yf(i) - v(i,nstep)\n do m = 1, n-r\n A(i,m) = U(i,m,nstep)\n end do\n end do\n CALL WRCRN ('A', n, n-r, A, n, 0)\nc\nc compute the determinate\nc \n call LFTCG( n-r, A, n, fac, n-r, ipvt)\n call LFDCG( n-r, fac, n-r, ipvt, det1, det2) \n det = det1*10**det2\n write (*,*) 'det = ', det\n#endif\n ctemp = c\n if (icount .eq. 1) then\n cm2 = c\n err = U(2,1,nstep)*B(1,qend) + U(2,2,nstep)*B(2,qend)\n errm2 = err\n c = CMPLX( REAL(c)*.9999, AIMAG(c) )\n else if (icount .eq. 2) then\n cm1 = c\n err = U(2,1,nstep)*B(1,qend) + U(2,2,nstep)*B(2,qend)\n errm1 = err\nc c = CMPLX( REAL(c), AIMAG(c)*.9999 )\n fdxr = REAL(err-errm2) / REAL(c-cm2)\n fdxi = AIMAG(err-errm2) / REAL(c-cm2)\n fd = CMPLX( fdxr, fdxi )\n c = c - err/fd\n else\n err = U(2,1,nstep)*B(1,qend) + U(2,2,nstep)*B(2,qend)\n qt = (c-cm1)/(cm1-cm2)\n At = qt*err-qt*(1.+qt)*errm1+qt**2*errm2\n Bt = (2.*qt+1.)*err-(1.+qt)**2*errm1+qt**2*errm2\n Ct = (1.+qt)*err\n if ( ABS(Bt+SQRT(Bt**2-4.*At*Ct)) .gt.\n & ABS(Bt-SQRT(Bt**2-4.*At*Ct)) ) then\n c = ctemp-(ctemp-cm1)*2.*Ct/(Bt+SQRT(Bt**2-4.*At*Ct))\n else\n c = ctemp-(ctemp-cm1)*2.*Ct/(Bt-SQRT(Bt**2-4.*At*Ct))\n end if\n cm2 = cm1\n cm1 = ctemp\n errm2 = errm1\n errm1 = err\n end if\n\n write (*,30) icount, real(c), aimag(c), real(err), aimag(err)\n 30 format (1x,i4,2(1x,es16.8e3,1x,es16.8e3,3x))\n\n icount = icount + 1\n end do\nc\nc.... Output Eigenvalue\nc \n write (*,40) real(ctemp), aimag(ctemp), qend\n 40 format (/,'Eigenvalue = ',e17.8e3,1x,e17.8e3,2x,i5/)\n write (*,45) icount, abs(err), abs(c-cm1)\n 45 format (' Eigenvalue iterations = ', i5/,' |error| = ',\n & es17.8e3/,' |c-cm1| = ', es17.8e3/)\nc\nc Second Pass to compute the eigenfunctions\nc\n if (eigfun) then\n vmax = 0.0\n k = nstep\n do i = 1, n\n y(i,k) = v(i,k)\n do m = 1, n-r\n y(i,k) = y(i,k) + U(i,m,k)*B(m,q)\n end do\n end do\n do m = 1, n-r\n B(m,q-1) = 0.0\n do j = 1, n-r\n B(m,q-1) = B(m,q-1) + P(j,m,q)*(B(j,q)-omega(j,q))\n end do\n end do\n do k = nstep-1, 0, -1\n t = to + h*k\n if ( t .lt. tq(q-1) ) then\n q = q - 1\n do m = 1, n-r\n B(m,q-1) = 0.0\n do j = 1, n-r\n B(m,q-1) = B(m,q-1) + P(j,m,q)*(B(j,q)-omega(j,q))\n end do\n end do\n end if\n do i = 1, n\n y(i,k) = v(i,k)\n do m = 1, n-r\n y(i,k) = y(i,k) + U(i,m,k)*B(m,q-1)\n end do\n end do\n if ( ABS(y(i,k)) .gt. ABS(vmax) ) then\n vmax = y(i,k)\n end if\n end do\nc\nc Output eigenfunction and derivatives: u, u', u'', u'''\nc\n do k = 0, nstep\n t = to + h*k\n write (11,20) t, REAL(y(1,k)/vmax),AIMAG(y(1,k)/vmax)\n write (12,20) t, REAL(y(2,k)/vmax),AIMAG(y(2,k)/vmax)\n write (13,20) t, REAL(y(3,k)/vmax),AIMAG(y(3,k)/vmax)\n write (14,20) t, REAL(y(4,k)/vmax),AIMAG(y(4,k)/vmax)\n 20 format (1x,3(ES16.8E3,1x))\n end do\n end if\n\n return\n end\n\nC***********************************************************************\n subroutine CONTE_IC(nstep, testalpha, n, r, yo, yf, to, tf, c, \n & eigfun, FIC, FHOMO, FPART, INPROD)\nC***********************************************************************\nC\nC First order linear boundary value problem solver using Conte's\nC method with a non Dirac function initial condition. \nC Runge-Kutta is used for time advancement but there are\nC other options available via compile defines\nC\nC nstep = number of integration steps between [t0,tf]\nC n = number of ODEs to integrate\nC r = number of particular solutions \nC yo = starting values\nC yf = ending values\nC to = Interval start value\nC tf = Interval end value\nC c = Current eigenvalue\nC eigfun = Whether to output eigenfunction at the end\nC FIC = Subroutine to compute the initial condition\nC FHOMO = Subroutine for homogeneous equation\nC FPART = Subroutin for particular equation\nC INPROD = Function to compute inner product\nC\nC***********************************************************************\n integer nstep, n, r\n integer i, m, q, s, mi, mj, qend, IPVT(n-r), icount, north\n real t, tq(0:nstep), to, tf, h \n complex yo(n), yf(n), B(n-r,0:nstep), err, c, cold, ctemp\n complex U(n,n-r,0:nstep), P(n-r,n-r,0:nstep), z(n,n-r)\n complex y(n,0:nstep), v(n,0:nstep), w(n-r), omega(n,0:nstep)\n complex eta(n),A(n,n-r),x(n),FAC(n-r,n-r), det1, det\n complex olderr, ut(n,n-r), fd, vmax\n complex cm1, cm2, errm1, errm2, qt, At, Bt, Ct, Utemp(n)\n real aa, bb, cc\n real test, testalpha, pi, det2, AI(n,n-r)\n real fdxr, fdxi, fdyr, fdyi\n logical norm, eigfun\n complex INPROD\n external INPROD, FIC, FHOMO, FPART\n real errtol, maxcount, eigtol\n#ifdef USE_NR_ODEINT\n external RKQC\n#endif\nc\nc Setup for ZVODE\nc\n#ifdef USE_VODE\n real RWORK(20+(n*(n-r)))\n complex ZWORK(15*(n*(n-r)))\n integer IWORK(30+(n*(n-r)))\n external FHOMO_VODE\n real RTOL, ATOL, RPAR\n integer ITOL, ITASK, ISTATE, IOPT, LZW, LRW, LIW, MF, IPAR(2)\n ITOL = 1\n RTOL = 1.0D-9\n ATOL = 1.0D-8\n ITASK = 1\n ISTATE = 1\n IOPT = 0\n LZW = 15*(n*(n-r))\n LRW = 20+(n*(n-r))\n LIW = 30+(n*(n-r))\n MF = 10\n RPAR = 0.0\n IPAR(1) = n \n IPAR(2) = n-r\n#endif\nc\nc initialize variables\nc\n errtol = 1.0e-14\n maxcount = 20\n eigtol = 1.0e-14\nc\nc set the normalization constraint\nc\n pi = ACOS(-1.0)\nc\nc compute the step size\nc \n h = (tf-to)/nstep\nc\nc Begin the eigenvalue iteration loop\nc\n icount = 1\n err = 1.0\n cm1 = c + 1.0\n do while ( ((abs(err) .ge. errtol) .or. (abs(c-cm1) .ge. eigtol)) \n & .and. (icount .le. maxcount) ) \n q = 0\n tq(0) = tf\nc\nc Set the initial conditions\nc\n k = 0\n call FIC(n,r,U(1,1,k))\nc\nc Gram-Schmidt\nc\n w(1) = SQRT(inprod(n, U(1,1,k), U(1,1,k)))\n do i = 1, n\n z(i,1) = U(i,1,k)/w(1)\n end do\n do mi = 2, (n-r)\n do i = 1, n\n eta(i) = U(i,mi,k)\n end do\n do mj = mi-1, 1, -1\n do i = 1, n\n eta(i) = eta(i) - inprod(n, U(1,mi,k), z(1,mj))*z(i,mj)\n end do\n end do\n w(mi) = SQRT(inprod(n, eta, eta))\n do i = 1, n\n z(i,mi) = eta(i)/w(mi)\n end do\n end do\nc\nc Now update the U matrix with the orthonormal values\nc \n do i = 1, n\n do m = 1, n-r\n U(i,m,k) = z(i,m)\n end do\n end do\n#ifdef CHECK_ORTHOGONALITY\n aa = ABS(inprod(n, U(1,1,k), U(1,1,k)))\n bb = ABS(inprod(n, U(1,2,k), U(1,2,k)))\n cc = ABS(inprod(n, U(1,1,k), U(1,2,k)))\n test = ACOS(cc/SQRT(aa*bb))*180./pi\n write (*,*) k, mi, mj, test\n#endif\nc\nc Integrate the homo. and particular equations\nc \n do k = 1, nstep\n t = tf - h*k\nc\nc Loop thru all homogeneous solutions\nc\n do m = 1, n-r\n#ifdef USE_NR_ODEINT\n do i = 1, n\n Utemp(i) = U(i,m,k-1)\n end do\n call ODEINT(Utemp,n,t+h,t,1.E-6,-h,1.e-20,nok,nbad,\n & FHOMO,RKQC)\n do i = 1, n\n U(i,m,k) = Utemp(i)\n end do\nc#elif USE_VODE\nc ISTATE=1\nc rt0 = t+h\nc rt1 = t\nc do i = 1, n\nc Utemp(i) = U(i,m,k-1)\nc end do\ncc write(*,*) \"Calling ZVODE...\", rt0, rt1\nc call ZVODE(FHOMO_VODE,n,Utemp,rt0,rt1,ITOL,RTOL,ATOL,ITASK,\nc & ISTATE,IOPT,ZWORK,LZW,RWORK,LRW,IWORK,LIW,JEX,MF,\nc & RPAR,IPAR)\nc write(*,*) \"Finixhed ZVODE...\", rt0, rt1\nc if (ISTATE .lt. 0) then\nc write(*,*) \"Error in ZVODE: ISTATE = \", ISTATE\nc call exit(1)\nc end if\nc do i = 1, n\nc U(i,m,k) = Utemp(i)\nc end do\n#elif USE_LSRK14\n call CLSRK14(n, U(1,m,k-1), U(1,m,k), t+h, -h, FHOMO)\n#elif USE_RKCK45\n call CRKCK45( n, U(1,m,k-1), U(1,m,k), t+h, -h, FHOMO )\n#else\n call CRK4(n, U(1,m,k-1), U(1,m,k), t+h, -h, FHOMO)\n#endif\n end do\n#if 0\n if (norm .or. k.eq.1) ISTATE=1\n ISTATE=1\n rt0 = t+h\n rt1 = t\n do m = 1, n-r\n do i = 1, n\n U(i,m,k) = U(i,m,k-1)\n end do\n end do\nc write(*,*) \"Calling ZVODE...\", rt0, rt1, n*(n-r)\n call ZVODE(FHOMO_VODE,n*(n-r),U(1,1,k),rt0,rt1,ITOL,RTOL,ATOL,\n & ITASK,ISTATE,IOPT,ZWORK,LZW,RWORK,LRW,IWORK,LIW,\n & JEX,MF,RPAR,IPAR)\n if (ISTATE .lt. 0) then\n write(*,*) \"Error in ZVODE: ISTATE = \", ISTATE\n call exit(1)\n end if\n#else\nc write(*,*) \"Hack...fix it\"\nc stop\n#endif\nc\nc Test to see if normalization is required\nc\n norm = .false.\n ta = pi*testalpha/180.0\n do mi = 1, n-r\n do mj = 1, n-r\n if (mi .ne. mj) then\n aa = ABS(inprod(n, U(1,mi,k), U(1,mi,k)))\n bb = ABS(inprod(n, U(1,mj,k), U(1,mj,k)))\n cc = ABS(inprod(n, U(1,mi,k), U(1,mj,k)))\n test = acos(cc/SQRT(aa*bb))\n if (test .lt. ta) norm = .true.\nc write (*,*) k, mi, mj, test, testalpha, norm\n end if\n end do\n end do\nc\nc Perform normalization\nc \n if ( norm .or. (k .eq. nstep) ) then\n q = q + 1\nc write (*,*) 'Normalization = ', q\n tq(q) = t\n if (k .eq. nstep) then\n qend = q\nc write (*,*) 'qend = ',qend\n end if\nc\nc Gram-Schmidt\nc\n w(1) = SQRT(inprod(n, U(1,1,k), U(1,1,k)))\n do i = 1, n\n z(i,1) = U(i,1,k)/w(1)\n end do\n do mi = 2, (n-r)\n do i = 1, n\n eta(i) = U(i,mi,k)\n end do\n do mj = mi-1, 1, -1\n do i = 1, n\n eta(i) = eta(i) - inprod(n, U(1,mi,k), \n & z(1,mj))*z(i,mj)\n end do\n end do\n w(mi) = SQRT(inprod(n, eta, eta))\n do i = 1, n\n z(i,mi) = eta(i)/w(mi)\n end do\n end do\nc\nc Now I have the orthonormal basis in z and \nc the norms in w so I can compute the P orthonormalization \nc matrix\nc\n do j = 1, n-r\n do i = 1, j\n if (j .eq. i) then\n P(j,i,q) = 1.0/w(j)\n else\n P(j,i,q) = 0.0\n do s = i, j-1\n P(j,i,q) = P(j,i,q)-inprod(n,U(1,j,k),z(1,s))/w(j)*\n & P(s,i,q)\n end do\n end if\n end do\n end do\nc\nc Check the P matrix\nc\n if (.false.) then\n do i = 1, n\n do m = 1, n-r\n ut(i,m) = 0.0\n do j = 1, n-r\n ut(i,m) = ut(i,m) + U(i,j,k)*P(m,j,q)\n end do\n end do\n end do\n \n do i = 1,n\n write (*,*) i,(ut(i,m), m = 1, n-r)\n end do\n write (*,*)\n do i = 1,n\n write (*,*) i,( z(i,m), m = 1, n-r)\n end do\n write (*,*)\n write (*,*)\n end if\nc\nc Now update the U matrix with the orthonormal values\nc \n do i = 1, n\n do m = 1, n-r\n U(i,m,k) = z(i,m)\n end do\n end do\n \n end if\n end do\nc\nc check boundary conditions\nc\n if (.true.) then\nc\nc strictly enforce the zero BC\nc\n B(1,qend) = -U(1,2,nstep)/U(1,1,nstep)\n B(2,qend) = 1.0\nc olderr = err\nc err = U(2,1,nstep)*B(1,qend) + U(2,2,nstep)*B(2,qend)\n else\nc\nc strictly enforce the zero slope BC\nc\n B(1,qend) = 1.0\n B(2,qend) = -U(2,1,nstep)/U(2,2,nstep)\nc olderr = err\nc err = U(1,1,nstep)*B(1,qend) + U(1,2,nstep)*B(2,qend)\n end if\n \n ctemp = c\n if (icount .eq. 1) then\n cm2 = c\n err = U(2,1,nstep)*B(1,qend) + U(2,2,nstep)*B(2,qend)\n errm2 = err\n c = CMPLX( REAL(c)*.9999, AIMAG(c) )\n else if (icount .eq. 2) then\n cm1 = c\n err = U(2,1,nstep)*B(1,qend) + U(2,2,nstep)*B(2,qend)\n errm1 = err\nc c = CMPLX( REAL(c), AIMAG(c)*.9999 )\n fdxr = REAL(err-errm2) / REAL(c-cm2)\n fdxi = AIMAG(err-errm2) / REAL(c-cm2)\n fd = CMPLX( fdxr, fdxi )\n c = c - err/fd\n else\n err = U(2,1,nstep)*B(1,qend) + U(2,2,nstep)*B(2,qend)\n qt = (c-cm1)/(cm1-cm2)\n At = qt*err-qt*(1.+qt)*errm1+qt**2*errm2\n Bt = (2.*qt+1.)*err-(1.+qt)**2*errm1+qt**2*errm2\n Ct = (1.+qt)*err\n if ( ABS(Bt+SQRT(Bt**2-4.*At*Ct)) .gt. \n & ABS(Bt-SQRT(Bt**2-4.*At*Ct)) ) then\n c = ctemp-(ctemp-cm1)*2.*Ct/(Bt+SQRT(Bt**2-4.*At*Ct))\n else\n c = ctemp-(ctemp-cm1)*2.*Ct/(Bt-SQRT(Bt**2-4.*At*Ct))\n end if\n cm2 = cm1\n cm1 = ctemp\n errm2 = errm1\n errm1 = err\n end if\n write (*,30) icount,real(ctemp),aimag(ctemp),real(err),\n & aimag(err)\n 30 format (1x,i4,2(e17.8,e17.8,3x))\n icount = icount + 1\n end do\nc\nc.... Output Eigenvalue\nc \n icount = icount - 1\n write (*,40) real(ctemp), aimag(ctemp), qend\n 40 format (/,'Eigenvalue = ',e17.8,1x,e17.8,2x,i5/)\n write (*,45) icount, abs(err), abs(c-cm1)\n 45 format (' Eigenvalue iterations = ', i5/,' |error| = ',\n & es17.8/,' |c-cm1| = ', es17.8/)\nc\nc Second Pass to compute the eigenfunctions\nc\n if (eigfun) then\n q = qend\n vmax = 0.0\n k = nstep\n do i = 1, n\n y(i,k) = v(i,k)\n do m = 1, n-r\n y(i,k) = y(i,k) + U(i,m,k)*B(m,q)\n end do\n end do\n do m = 1, n-r\n B(m,q-1) = 0.0\n do j = 1, n-r\n B(m,q-1) = B(m,q-1) + P(j,m,q)*B(j,q) \n end do\n end do\n do k = nstep-1, 0, -1\n t = tf - h*k\n if ( t .gt. tq(q-1) ) then\n q = q - 1\n do m = 1, n-r\n B(m,q-1) = 0.0\n do j = 1, n-r\n B(m,q-1) = B(m,q-1) + P(j,m,q)*B(j,q)\n end do\n end do\n end if\n do i = 1, n\n y(i,k) = 0.0\n do m = 1, n-r\n y(i,k) = y(i,k) + U(i,m,k)*B(m,q-1)\n end do\n end do\n if ( ABS(y(i,k)) .gt. ABS(vmax) ) then\n vmax = y(i,k)\n end if\n end do\nc\nc Output eigenfunction and derivatives: u, u', u'', u'''\nc\n do k = 0, nstep\n t = tf - h*k\n write (11,20) t, REAL(y(1,k)/vmax),AIMAG(y(1,k)/vmax)\n write (12,20) t, REAL(y(2,k)/vmax),AIMAG(y(2,k)/vmax)\n write (13,20) t, REAL(y(3,k)/vmax),AIMAG(y(3,k)/vmax)\n write (14,20) t, REAL(y(4,k)/vmax),AIMAG(y(4,k)/vmax)\n 20 format (1x,3(ES16.8E3,1x))\n end do\n end if\n\n return\n end\n\nC***********************************************************************\nC> \\brief Advance one time step using fourth order (real) Runge-Kutta\nC> \\param[in] neq number of equations\nC> \\param[in] yo initial value\nC> \\param[out] yf final value\nC> \\param[in] to intial time\nC> \\param[in] h time step\nC> \\param[in] FUNC function to integrate\nC***********************************************************************\n subroutine SRK4(neq, yo, yf, to, h, FUNC)\nC***********************************************************************\nC\nC Advance one time step using fourth order (real) Runge-Kutta\nC\nC***********************************************************************\n external FUNC\n integer neq\n real to, h\n real yo(neq), yf(neq)\n real f(neq), k1(neq), k2(neq), k3(neq), k4(neq), q(neq)\n \n call FUNC(neq, yo, to, f)\n do j = 1 , neq\n k1(j) = h*f(j)\n q(j) = yo(j) + 0.5*k1(j)\n end do\n call FUNC(neq, q, to+0.5*h, f)\n do j = 1 , neq\n k2(j) = h*f(j)\n q(j) = yo(j) + 0.5*k2(j)\n end do\n call FUNC(neq, q, to+0.5*h, f)\n do j = 1 , neq\n k3(j) = h*f(j)\n q(j) = yo(j) + k3(j)\n end do\n call FUNC(neq, q, to+h, f)\n do j = 1 , neq\n k4(j) = h*f(j)\n yf(j) = yo(j)+k1(j)/6.+(k2(j)+k3(j))/3.+k4(j)/6.\n end do\n\n return\n end\n\nC***********************************************************************\nC> \\brief Advance one time step using fourth order (real) Runge-Kutta\nC> \\param[in] neq number of equations\nC> \\param[in] yo initial value\nC> \\param[out] yf final value\nC> \\param[in] to intial time\nC> \\param[in] h time step\nC> \\param[in] FUNC function to integrate\nC***********************************************************************\n subroutine CRK4(neq, yo, yf, to, h, FUNC)\nC***********************************************************************\nC\nC Advance one time step using fourth order (complex) Runge-Kutta\nC\nc***********************************************************************\n external FUNC\n integer neq\n real to, h\n complex yo(neq), yf(neq)\n complex f(neq), k1(neq), k2(neq), k3(neq), k4(neq), q(neq)\n \n call FUNC(neq, yo, to, f)\n do j = 1 , neq\n k1(j) = h*f(j)\n q(j) = yo(j) + 0.5*k1(j)\n end do\n call FUNC(neq, q, to+0.5*h, f)\n do j = 1 , neq\n k2(j) = h*f(j)\n q(j) = yo(j) + 0.5*k2(j)\n end do\n call FUNC(neq, q, to+0.5*h, f)\n do j = 1 , neq\n k3(j) = h*f(j)\n q(j) = yo(j) + k3(j)\n end do\n call FUNC(neq, q, to+h, f)\n do j = 1 , neq\n k4(j) = h*f(j)\n yf(j) = yo(j)+k1(j)/6.+(k2(j)+k3(j))/3.+k4(j)/6.\n end do\n\n return\n end\n\nC***********************************************************************\n SUBROUTINE SPLINE (N,X,Y,FDP) \nC***********************************************************************\nC\nC.... Note: this routine is in the public domain and available\nC at https://web.stanford.edu/class/me200c/\nC\nC-----THIS SUBROUTINE COMPUTES THE SECOND DERIVATIVES NEEDED \nC-----IN CUBIC SPLINE INTERPOLATION. THE INPUT DATA ARE: \nC-----N = NUMBER OF DATA POINTS \nC-----X = ARRAY CONTAINING THE VALUES OF THE INDEPENDENT VARIABLE \nC----- (ASSUMED TO BE IN ASCENDING ORDER) \nC-----Y = ARRAY CONTAINING THE VALUES OF THE FUNCTION AT THE \nC----- DATA POINTS GIVEN IN THE X ARRAY \nC-----THE OUTPUT IS THE ARRAY FDP WHICH CONTAINS THE SECOND \nC-----DERIVATIVES OF THE INTERPOLATING CUBIC SPLINE. \n DIMENSION X(N),Y(N),A(N),B(N),C(N),R(N),FDP(N) \nC-----COMPUTE THE COEFFICIENTS AND THE RHS OF THE EQUATIONS. \nC-----THIS ROUTINE USES THE CANTILEVER CONDITION. THE PARAMETER \nC-----ALAMDA (LAMBDA) IS SET TO 1. BUT THIS CAN BE USER-MODIFIED. \nC-----A,B,C ARE THE THREE DIAGONALS OF THE TRIDIAGONAL SYSTEM; \nC-----R IS THE RIGHT HAND SIDE. THESE ARE NOW ASSEMBLED. \n ALAMDA = 1. \n NM2 = N - 2 \n NM1 = N - 1 \n C(1) = X(2) - X(1) \n DO 1 I=2,NM1 \n C(I) = X(I+1) - X(I) \n A(I) = C(I-1) \n B(I) = 2.*(A(I) + C(I)) \n R(I) = 6.*((Y(I+1) - Y(I))/C(I) - (Y(I) - Y(I-1))/C(I-1)) \n 1 CONTINUE \n B(2) = B(2) + ALAMDA * C(1) \n B(NM1) = B(NM1) + ALAMDA * C(NM1) \nC-----AT THIS POINT WE COULD CALL A TRIDIAGONAL SOLVER SUBROUTINE \nC-----BUT THE NOTATION IS CLUMSY SO WE WILL SOLVE DIRECTLY. THE \nC-----NEXT SECTION SOLVES THE SYSTEM WE HAVE JUST SET UP. \n DO 2 I=3,NM1 \n T = A(I)/B(I-1) \n B(I) = B(I) - T * C(I-1) \n R(I) = R(I) - T * R(I-1) \n 2 CONTINUE \n FDP(NM1) = R(NM1)/B(NM1) \n DO 3 I=2,NM2 \n NMI = N - I \n FDP(NMI) = (R(NMI) - C(NMI)*FDP(NMI+1))/B(NMI) \n 3 CONTINUE \n FDP(1) = ALAMDA * FDP(2) \n FDP(N) = ALAMDA * FDP(NM1) \nC-----WE NOW HAVE THE DESIRED DERIVATIVES SO WE RETURN TO THE \nC-----MAIN PROGRAM. \n RETURN \n END \n\nC***********************************************************************\n SUBROUTINE SPEVAL (N,X,Y,FDP,XX,F) \nC***********************************************************************\nC\nC.... Note: this routine is in the public domain and available\nC at https://web.stanford.edu/class/me200c/\nC\nC-----THIS SUBROUTINE EVALUATES THE CUBIC SPLINE GIVEN \nC-----THE 2ND DERIVATIVE COMPUTED BY SUBROUTINE SPLINE. \nC-----THE INPUT PARAMETERS N,X,Y,FDP HAVE THE SAME \nC-----MEANING AS IN SPLINE. \nC-----XX = VALUE OF INDEPENDENT VARIABLE FOR WHICH \nC----- AN INTERPOLATED VALUE IS REQUESTED \nC-----F = THE INTERPOLATED RESULT \n DIMENSION X(N),Y(N),FDP(N) \nC-----THE FIRST JOB IS TO FIND THE PROPER INTERVAL. \n#if USE_NR_HUNT\nc\nc Search using bisection with a good guess\nc\n I = IOLD\n IF (XX.EQ.X(1)) THEN\n I = 1\n ELSE IF (XX.EQ.X(N)) THEN\n I = N\n ELSE\n call HUNT (X,N,XX,I)\n END IF\n IOLD = I\n#elif 1\n I = IOLD\n IF (XX.EQ.X(1)) THEN\n I = 1\n ELSE IF (XX.EQ.X(N)) THEN\n I = N\n ELSE\n call BISECT (X,N,XX,I)\n ENDiF\n IOLD = I\n#else\nc\nc This is really a slow way of searching\nc\n NM1 = N - 1\n DO 1 I=1,NM1\n IF (XX.LE.X(I+1)) GO TO 10\n 1 CONTINUE \n#endif\nC-----NOW EVALUATE THE CUBIC \n 10 DXM = XX - X(I) \n DXP = X(I+1) - XX \n DEL = X(I+1) - X(I) \n F = FDP(I)*DXP*(DXP*DXP/DEL - DEL)/6. \n 1 +FDP(I+1)*DXM*(DXM*DXM/DEL - DEL)/6. \n 2 +Y(I)*DXP/DEL + Y(I+1)*DXM/DEL \n RETURN \n END \n\nC***********************************************************************\n subroutine BISECT(X,N,XX,I)\nC***********************************************************************\n dimension X(N)\nC***********************************************************************\n il = I-1\n ir = N-1\n do while (ir-il .gt. 1) \n im = ISHFT(ir+il,-1) \n if ( X(im+1) > xx ) then\n ir = im\n else\n il = im\n end if\n end do\n I = il+1\n return\n end\n\nC***********************************************************************\n SUBROUTINE SPDER(N,X,Y,FDP,XX,F,FP,FPP)\nC***********************************************************************\nC\nC.... Note: this routine is in the public domain and available\nC at https://web.stanford.edu/class/me200c/\nC\nC-----THIS SUBROUTINE EVALUATES THE CUBIC SPLINE GIVEN \nC-----THE 2ND DERIVATIVE COMPUTED BY SUBROUTINE SPLINE. \nC-----THE INPUT PARAMETERS N,X,Y,FDP HAVE THE SAME \nC-----MEANING AS IN SPLINE. \nC-----XX = VALUE OF INDEPENDENT VARIABLE FOR WHICH \nC----- AN INTERPOLATED VALUE IS REQUESTED \nC-----F = THE INTERPOLATED RESULT \nC-----FP = THE INTERPOLATED DERIVATIVE RESULT \n INTEGER N\n DIMENSION X(N),Y(N),FDP(N)\n REAL XX, F, FP, FPP\nC-----THE FIRST JOB IS TO FIND THE PROPER INTERVAL. \n#if USE_NR_HUNT\nc\nc Search using bisection with a good guess\nc\n I = IOLD\n IF (XX.EQ.X(1)) THEN\n I = 1\n ELSE IF (XX.EQ.X(N)) THEN\n I = N\n ELSE\n call HUNT (X,N,XX,I)\n END IF\n IOLD = I\n#elif 1\n I = IOLD\n IF (XX.EQ.X(1)) THEN\n I = 1\n ELSE IF (XX.EQ.X(N)) THEN\n I = N\n ELSE\n call BISECT (X,N,XX,I)\n ENDiF\n IOLD = I\n#else\nc\nc This is really a slow way of searching\nc\n NM1 = N - 1\n DO 1 I=1,NM1\n IF (XX.LE.X(I+1)) GO TO 10\n 1 CONTINUE \n#endif\nC-----NOW EVALUATE THE CUBIC \n 10 continue\nC write(*,*) I, X(I), XX, X(I+1)\n DXM = XX - X(I)\n DXP = X(I+1) - XX\n DEL = X(I+1) - X(I)\n F = FDP(I)*DXP*(DXP*DXP/DEL - DEL)/6.0\n 1 +FDP(I+1)*DXM*(DXM*DXM/DEL - DEL)/6.0\n 2 +Y(I)*DXP/DEL + Y(I+1)*DXM/DEL\n FP= FDP(I)*(-3.0*DXP*DXP/DEL + DEL)/6.0\n 1 +FDP(I+1)*(3.0*DXM*DXM/DEL - DEL)/6.0\n 2 -Y(I)/DEL + Y(I+1)/DEL\n FPP=FDP(I)*DXP/DEL+FDP(I+1)*DXM/DEL\n RETURN \n END\n\nC***********************************************************************\n subroutine SLSRK14(neq, yo, yf, to, h, FUNC)\nC***********************************************************************\nC\nC Advance one time step with low-storage Runge Kutta 14\nC\nC***********************************************************************\n external FUNC\n integer neq\n real to, h\n real yo(neq), yf(neq)\n real f(neq), yt(neq)\nC***********************************************************************\n parameter (nsubstep=14)\n real A(0:14), B(0:13), c(0:13), w(0:14)\n data A / 0.0, \n & -0.7188012108672410, \n & -0.7785331173421570,\n & -0.0053282796654044, \n & -0.8552979934029281, \n & -3.9564138245774565, \n & -1.5780575380587385,\n & -2.0837094552574054, \n & -0.7483334182761610,\n & -0.7032861106563359, \n & 0.0013917096117681,\n & -0.0932075369637460, \n & -0.9514200470875948,\n & -7.1151571693922548, \n & 0.0/\n data B / 0.0367762454319673,\n & 0.3136296607553959,\n & 0.1531848691869027,\n & 0.0030097086818182,\n & 0.3326293790646110,\n & 0.2440251405350864,\n & 0.3718879239592277,\n & 0.6204126221582444,\n & 0.1524043173028741,\n & 0.0760894927419266,\n & 0.0077604214040978,\n & 0.0024647284755382,\n & 0.0780348340049386,\n & 5.5059777270269628 /\n data c / 0.0,\n & 0.0367762454319673,\n & 0.1249685262725025,\n & 0.2446177702277698,\n & 0.2476149531070420,\n & 0.2969311120382472,\n & 0.3978149645802642,\n & 0.5270854589440328,\n & 0.6981269994175695,\n & 0.8190890835352128,\n & 0.8527059887098624,\n & 0.8604711817462826,\n & 0.8627060376969976,\n & 0.8734213127600976 /\n data w / -0.116683473041717417,\n & 0.213493962104674251,\n & 0.128620987881127052,\n & 4.610096100109887907,\n & -5.386527768056724064,\n & 1.445540684241274576,\n & -0.761388932107154526,\n & 0.543874700576422732,\n & 0.102277834602298279,\n & 0.07127466608688701188,\n & -3.459648919807762457,\n & 37.20095449534884580,\n & -39.09786206496502814,\n & 5.505977727026962754,\n & 0.0 /\n do j = 1, neq\n yf(j) = yo(j)\n end do\n do i = 0, nsubstep-1\n t = to + c(i)*h\n call FUNC(neq, yf, t, f)\n do j = 1, neq\n yt(j) = A(i)*yt(j) + h*f(j)\n end do\n do j = 1, neq\n yf(j) = yf(j) + B(i)*yt(j)\n end do\n if (i+1 .lt. nsubstep) then\n t = to + c(i+1)*h\n else\n t = to + h\n end if\n end do\n return\n end\n\nC***********************************************************************\n subroutine CLSRK14(neq, yo, yf, to, h, FUNC)\nC***********************************************************************\nC\nC Advance one time step with low-storage Runge Kutta 14\nC\nC***********************************************************************\n external FUNC\n integer neq\n real to, h\n complex yo(neq), yf(neq)\n complex f(neq), yt(neq)\nC***********************************************************************\n parameter (nsubstep=14)\n real A(0:14), B(0:13), c(0:13), w(0:14)\n data A / 0.0, \n & -0.7188012108672410, \n & -0.7785331173421570,\n & -0.0053282796654044, \n & -0.8552979934029281, \n & -3.9564138245774565, \n & -1.5780575380587385,\n & -2.0837094552574054, \n & -0.7483334182761610,\n & -0.7032861106563359, \n & 0.0013917096117681,\n & -0.0932075369637460, \n & -0.9514200470875948,\n & -7.1151571693922548, \n & 0.0/\n data B / 0.0367762454319673,\n & 0.3136296607553959,\n & 0.1531848691869027,\n & 0.0030097086818182,\n & 0.3326293790646110,\n & 0.2440251405350864,\n & 0.3718879239592277,\n & 0.6204126221582444,\n & 0.1524043173028741,\n & 0.0760894927419266,\n & 0.0077604214040978,\n & 0.0024647284755382,\n & 0.0780348340049386,\n & 5.5059777270269628 /\n data c / 0.0,\n & 0.0367762454319673,\n & 0.1249685262725025,\n & 0.2446177702277698,\n & 0.2476149531070420,\n & 0.2969311120382472,\n & 0.3978149645802642,\n & 0.5270854589440328,\n & 0.6981269994175695,\n & 0.8190890835352128,\n & 0.8527059887098624,\n & 0.8604711817462826,\n & 0.8627060376969976,\n & 0.8734213127600976 /\n data w / -0.116683473041717417,\n & 0.213493962104674251,\n & 0.128620987881127052,\n & 4.610096100109887907,\n & -5.386527768056724064,\n & 1.445540684241274576,\n & -0.761388932107154526,\n & 0.543874700576422732,\n & 0.102277834602298279,\n & 0.07127466608688701188,\n & -3.459648919807762457,\n & 37.20095449534884580,\n & -39.09786206496502814,\n & 5.505977727026962754,\n & 0.0 /\n do j = 1, neq\n yf(j) = yo(j)\n end do\n do i = 0, nsubstep-1\n t = to + c(i)*h\n call FUNC(neq, yf, t, f)\n do j = 1, neq\n yt(j) = A(i)*yt(j) + h*f(j)\n end do\n do j = 1, neq\n yf(j) = yf(j) + B(i)*yt(j)\n end do\n if (i+1 .lt. nsubstep) then\n t = to + c(i+1)*h\n else\n t = to + h\n end if\n end do\n return\n end\n\nC***********************************************************************\n subroutine SRKCK45(neq, yo, yf, to, h, FUNC)\nC***********************************************************************\nC\nC Advance one time step Runge-Kutta Cash-Karp method\nC\nC***********************************************************************\n external FUNC\n integer neq\n real to, h, t\n real yo(neq), yf(neq), yt(neq)\n real yk(neq,6), ye(neq)\nC***********************************************************************\n real b(6,5)\n real a(6), c(6), d(6)\n data a / 0.0, 0.2, 0.3, 0.6, 1.0, 0.875 /\n data b / 0.0, 0.2, 0.075, 0.3, -0.2037037037037037,\n & 0.029495804398148147,\n & 0.0, 0.0, 0.225, -0.9, 2.5, 0.341796875,\n & 0.0, 0.0, 0.0, 1.2, -2.5925925925925926,\n & 0.041594328703703706,\n & 0.0, 0.0, 0.0, 0.0, 1.2962962962962963,\n & 0.40034541377314814,\n & 0.0, 0.0, 0.0, 0.0, 0.0, 0.061767578125 /\n data c / 0.09788359788359788, 0.0, 0.4025764895330113,\n & 0.21043771043771045, 0.0, 0.2891022021456804 /\n data d / -0.004293774801587311, 0.0, 0.018668586093857853,\n & -0.034155026830808066, -0.019321986607142856,\n & 0.03910220214568039 /\nc\nc Test data\nc\n#ifdef OS_DEBUG\n do i = 1, 6\n do j = 1, 5\n write(*,*) i, j, b(i,j)\n end do\n end do\n stop\n#endif\nc\nc Stage 1 - 6\nc\n do m = 1, 6\n t = to + a(m)*h\n do n = 1, neq\n yt(n) = yo(n)\n end do\n do k = 1, m-1\n do n = 1, neq\n yt(n) = yt(n) + b(m,k)*yk(n,k)\n end do\n end do\n call FUNC(neq, yt, t, yk(1,m))\n do n = 1, neq\n yk(n,m) = h * yk(n,m)\n end do\n end do\nc\nc Final solution and error\nc\n do n = 1, neq\n yf(n) = yo(n)\n ye(n) = 0.0\n end do\n do k = 1, 6\n do n = 1, neq\n yf(n) = yf(n) + c(k)*yk(n,k)\n ye(n) = ye(n) + d(k)*yk(n,k)\n end do\n end do\n\n return\n end\n\nC***********************************************************************\n subroutine CRKCK45(neq, yo, yf, to, h, FUNC)\nC***********************************************************************\nC\nC Advance one time step Runge-Kutta Cash-Karp method\nC\nC***********************************************************************\n external FUNC\n integer neq\n real to, h, t\n complex yo(neq), yf(neq), yt(neq)\n complex yk(neq,6), ye(neq)\nC***********************************************************************\n real b(6,5)\n real a(6), c(6), d(6)\n data a / 0.0, 0.2, 0.3, 0.6, 1.0, 0.875 /\n data b / 0.0, 0.2, 0.075, 0.3, -0.2037037037037037, \n & 0.029495804398148147,\n & 0.0, 0.0, 0.225, -0.9, 2.5, 0.341796875,\n & 0.0, 0.0, 0.0, 1.2, -2.5925925925925926, \n & 0.041594328703703706,\n & 0.0, 0.0, 0.0, 0.0, 1.2962962962962963,\n & 0.40034541377314814,\n & 0.0, 0.0, 0.0, 0.0, 0.0, 0.061767578125 /\n data c / 0.09788359788359788, 0.0, 0.4025764895330113,\n & 0.21043771043771045, 0.0, 0.2891022021456804 /\n data d / -0.004293774801587311, 0.0, 0.018668586093857853,\n & -0.034155026830808066, -0.019321986607142856,\n & 0.03910220214568039 / \nc\nc Test data\nc\n#ifdef OS_DEBUG\n do i = 1, 6\n do j = 1, 5\n write(*,*) i, j, b(i,j)\n end do\n end do\n stop\n#endif\nc\nc Stage 1 - 6\nc\n do m = 1, 6 \n t = to + a(m)*h\n do n = 1, neq\n yt(n) = yo(n)\n end do\n do k = 1, m-1\n do n = 1, neq\n yt(n) = yt(n) + b(m,k)*yk(n,k)\n end do\n end do \n call FUNC(neq, yt, t, yk(1,m))\n do n = 1, neq\n yk(n,m) = h * yk(n,m)\n end do\n end do\nc\nc Final solution and error\nc\n do n = 1, neq\n yf(n) = yo(n)\n ye(n) = 0.0\n end do\n do k = 1, 6\n do n = 1, neq\n yf(n) = yf(n) + c(k)*yk(n,k)\n ye(n) = ye(n) + d(k)*yk(n,k)\n end do\n end do\n\n return\n end \n", "meta": {"hexsha": "12013e240b7fa889e4f9bbe8201aaaefb5fd48b2", "size": 43848, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "shoot.f", "max_stars_repo_name": "sscollis/os-stab", "max_stars_repo_head_hexsha": "01d3254e5a391a66c3a4c3971d1b1cd3d53e8330", "max_stars_repo_licenses": ["BSD-3-Clause-No-Nuclear-License-2014", "BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-04-12T00:03:09.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-04T18:46:30.000Z", "max_issues_repo_path": "shoot.f", "max_issues_repo_name": "sscollis/os-stab", "max_issues_repo_head_hexsha": "01d3254e5a391a66c3a4c3971d1b1cd3d53e8330", "max_issues_repo_licenses": ["BSD-3-Clause-No-Nuclear-License-2014", "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": "shoot.f", "max_forks_repo_name": "sscollis/os-stab", "max_forks_repo_head_hexsha": "01d3254e5a391a66c3a4c3971d1b1cd3d53e8330", "max_forks_repo_licenses": ["BSD-3-Clause-No-Nuclear-License-2014", "BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-03-05T06:10:21.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-17T18:58:41.000Z", "avg_line_length": 30.45, "max_line_length": 73, "alphanum_fraction": 0.4266785258, "num_tokens": 15098, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998823, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6716835590788702}} {"text": "program dot_test\n implicit none\n integer, parameter :: v_size = 5\n integer :: i\n real, dimension(v_size) :: vector1 = [ (0.5*I, i=1, v_size) ], &\n vector2 = [ (0.1*i, i=1, v_size) ]\n real, dimension(v_size, v_size) :: matrix = reshape( &\n [ (real(i), i=1, v_size*v_size) ], [ v_size, v_size ] &\n )\n real, external :: sdot\n \n print '(A20, *(F5.1))', 'vector 1: ', vector1\n print '(A20, *(F5.1))', 'vector 2: ', vector2\n print '(A20, F6.2)', 'dot N 1 1: ', &\n sdot(size(vector1), vector1, 1, vector2, 1)\n\n print '(A)', 'matrix:'\n do i = 1, size(matrix, 1)\n print '(*(F5.1))', matrix(i, :)\n end do\n print '(A, F6.1)', 'col 2 . col 4:', &\n sdot(size(matrix, 2), matrix(:, 2), 1, matrix(:, 4), 1)\n print '(A, F6.1)', 'row 2 . row 4:', &\n sdot(size(matrix, 1), matrix(2, :), 1, matrix(4, :), 1)\nend program dot_test\n", "meta": {"hexsha": "e25da958706294416a99267077c8877bed726e7d", "size": 923, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source_code/blas_lapack/dot.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/blas_lapack/dot.f90", "max_issues_repo_name": "gjbex/CMake-intro", "max_issues_repo_head_hexsha": "b4855c172f1d4a965f2b148b96ed160f4ea1e5bd", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-09-30T04:25:50.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-06T08:21:30.000Z", "max_forks_repo_path": "source_code/blas_lapack/dot.f90", "max_forks_repo_name": "gjbex/CMake-intro", "max_forks_repo_head_hexsha": "b4855c172f1d4a965f2b148b96ed160f4ea1e5bd", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2021-09-27T07:30:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-07T16:23:19.000Z", "avg_line_length": 35.5, "max_line_length": 68, "alphanum_fraction": 0.4951245937, "num_tokens": 340, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998822, "lm_q2_score": 0.7371581626286833, "lm_q1q2_score": 0.67168355907887}} {"text": "! -*- f90 -*-\n\n!#############################################################\n! COMPUTE 2D SPECTRUM OF AN ARRAY\n!#############################################################\n\nsubroutine pspec2d(a,kp,kspec,axis,nk1,nk2,nx,ny,nz)\n integer, intent (in) :: nx,ny,nz,nk1,nk2,axis\n double precision, dimension(nx,ny,nz), intent (in) :: a\n double precision, dimension(nk1,nk2), intent (out) :: kp,kspec\n!f2py intent (in) nx,ny,nz,axis,nk\n!f2py intent (in) a\n!f2py intent (out) kp, kspec\n ! LOCAL VARIABLES\n double complex , allocatable, dimension(:,:,:) :: ffld\n double precision, allocatable, dimension(:,:,:) :: fenergy\n double precision, allocatable, dimension(:,:) :: kx, ky, kz\n integer*8 plan, LX1, NORM, i, j, k, ntop, nnx, nny\n\n include 'fftw3.f'\n\n LX1=nx/2 + 1; NORM = nx*ny*nz\n select case (axis+1)\n case (1)\n !allocate(fenp(ny,nz), kp(ny,nz), ky(ny,nz), kz(ny,nz))\n allocate(ky(ny,nz), kz(ny,nz))\n do i=1,ny; ky(i,:)=dble(mod(i-1+ny/2,ny)-ny/2); end do\n do i=1,nz; kz(:,i)=dble(mod(i-1+nz/2,nz)-nz/2); end do\n kp=sqrt(ky*ky+kz*kz); kp(1,1) = dble(1.e-6)\n ntop=min(ny,nz)/2; nnx=ny; nny=nz\n deallocate(ky,kz)\n case (2)\n !allocate(fenp(LX1,nz),kp(LX1,nz), kx(LX1,nz), kz(LX1,nz))\n allocate(kx(LX1,nz), kz(LX1,nz))\n do i=1,LX1; kx(i,:)=dble(i-1.0); enddo\n do i=1,nz; kz(:,i)=dble(mod(i-1+nz/2,nz)-nz/2); end do\n kp=sqrt(kx*kx+kz*kz); kp(1,1) = dble(1.e-6)\n ntop=min(nx,nz)/2; nnx=LX1; nny=nz\n deallocate(kx,kz)\n case (3)\n !allocate(fenp(LX1,ny),kp(LX1,ny), kx(LX1,ny), ky(LX1,ny))\n allocate(kx(LX1,ny), ky(LX1,ny))\n do i=1,LX1; kx(i,:)=dble(i-1.0); enddo\n do i=1,ny; ky(:,i)=dble(mod(i-1+ny/2,ny)-ny/2); end do\n kp=sqrt(kx*kx+ky*ky); kp(1,1) = dble(1.e-6)\n ntop=min(nx,ny)/2; nnx=LX1; nny=ny\n deallocate(kx,ky)\n end select\n\n\n allocate(ffld(LX1,ny,nz), fenergy(LX1,ny,nz))\n ! CREATE THE FFTW PLAN\n call dfftw_plan_dft_r2c_3d(plan,Nx,Ny,Nz,a,ffld,FFTW_ESTIMATE)\n call dfftw_execute_dft_r2c(plan, a, ffld)\n ffld=ffld/NORM ! normalize the quantities in fourier space\n\n ! Calculate the energy in the fourier space, make sure \n ! that (1,:) part of the array is multiplied by half.\n fenergy=ffld*conjg(ffld); fenergy(1,:,:)=0.5*fenergy(1,:,:)\n kspec = sum(fenergy,dim=axis+1)\n ! DESTROY THE PLAN AND DEALLOCATE ARRAYS\n call dfftw_destroy_plan(plan)\n deallocate(ffld,fenergy)\nend subroutine pspec2d\n\n!#############################################################\n! COMPUTE SPECTRUM OF AN ARRAY\n!#############################################################\n\nsubroutine perpspec(a,kk,kspec,axis,nk,nx,ny,nz)\n integer, intent (in) :: nx,ny,nz,nk,axis\n double precision, dimension(nx,ny,nz), intent (in) :: a\n double precision, dimension(0:nk), intent (out) :: kk,kspec\n!f2py intent (in) nx,ny,nz,axis,nk\n!f2py intent (in) a\n!f2py intent (out) kk, kspec\n ! LOCAL VARIABLES\n double complex , allocatable, dimension(:,:,:) :: ffld\n double precision, allocatable, dimension(:,:,:) :: fenergy\n double precision, allocatable, dimension(:,:) :: fenp, kx, ky, kz, kp\n integer*8 plan, LX1, NORM, i, j, k, ntop, nnx, nny\n\n include 'fftw3.f'\n\n LX1=nx/2 + 1; NORM = nx*ny*nz\n select case (axis+1)\n case (1)\n allocate(fenp(ny,nz), kp(ny,nz), ky(ny,nz), kz(ny,nz))\n do i=1,ny; ky(i,:)=dble(mod(i-1+ny/2,ny)-ny/2); end do\n do i=1,nz; kz(:,i)=dble(mod(i-1+nz/2,nz)-nz/2); end do\n kp=sqrt(ky*ky+kz*kz); kp(1,1) = dble(1.e-6)\n ntop=min(ny,nz)/2; nnx=ny; nny=nz\n deallocate(ky,kz)\n case (2)\n allocate(fenp(LX1,nz),kp(LX1,nz), kx(LX1,nz), kz(LX1,nz))\n do i=1,LX1; kx(i,:)=dble(i-1.0); enddo\n do i=1,nz; kz(:,i)=dble(mod(i-1+nz/2,nz)-nz/2); end do\n kp=sqrt(kx*kx+kz*kz); kp(1,1) = dble(1.e-6)\n ntop=min(nx,nz)/2; nnx=LX1; nny=nz\n deallocate(kx,kz)\n case (3)\n allocate(fenp(LX1,ny),kp(LX1,ny), kx(LX1,ny), ky(LX1,ny))\n do i=1,LX1; kx(i,:)=dble(i-1.0); enddo\n do i=1,ny; ky(:,i)=dble(mod(i-1+ny/2,ny)-ny/2); end do\n kp=sqrt(kx*kx+ky*ky); kp(1,1) = dble(1.e-6)\n ntop=min(nx,ny)/2; nnx=LX1; nny=ny\n deallocate(kx,ky)\n end select\n\n\n allocate(ffld(LX1,ny,nz), fenergy(LX1,ny,nz))\n ! CREATE THE FFTW PLAN\n call dfftw_plan_dft_r2c_3d(plan,Nx,Ny,Nz,a,ffld,FFTW_ESTIMATE)\n call dfftw_execute_dft_r2c(plan, a, ffld)\n ffld=ffld/NORM ! normalize the quantities in fourier space\n\n ! Calculate the energy in the fourier space, make sure \n ! that (1,:) part of the array is multiplied by half.\n fenergy=ffld*conjg(ffld); fenergy(1,:,:)=0.5*fenergy(1,:,:)\n fenp = sum(fenergy,dim=axis+1)\n kspec=0. ! Initialize the spectrum to zero\n ! Do the sum of energy over shells of k and save in the spectrum\n do i=1,nnx; do j=1,nny\n k=nint(kp(i,j))\n if (k <= ntop) then\n kspec(k)=kspec(k)+fenp(i,j)\n kk(k) = k\n endif\n enddo; enddo \n ! DESTROY THE PLAN AND DEALLOCATE ARRAYS\n call dfftw_destroy_plan(plan)\n deallocate(ffld,fenergy,fenp,kp)\nend subroutine perpspec\n\n!###############################################################\n! COMPUTE SPECTRUM OF AN ARRAY FOR A BOX WITH DIFFERENT LENGTHS\n!###############################################################\n\nsubroutine lperpspec(a,axis,nk,lx,ly,lz,nx,ny,nz,kk,kspec)\n double precision, parameter :: pi=3.1415926535897932385\n integer, intent (in) :: nx,ny,nz,nk,axis\n double precision, intent (in) :: lx, ly, lz\n double precision, dimension(nx,ny,nz), intent (in) :: a\n double precision, dimension(0:nk), intent (out) :: kk,kspec\n ! LOCAL VARIABLES\n double complex , allocatable, dimension(:,:,:) :: ffld\n double precision, allocatable, dimension(:,:,:) :: fenergy\n double precision, allocatable, dimension(:,:) :: fenp\n double precision, allocatable, dimension(:) :: kkx, kky\n double precision :: kminx, kminy, kminz, kp, kmin\n integer(kind=8) plan, FFTW_ESTIMATE, LX1, NORM, i, j, k, ktop, nnx, nny\n PARAMETER (FFTW_ESTIMATE=64)\n!f2py intent (in) axis,nk,lx,ly,lz,nx,ny,nz\n!f2py intent (in) a\n!f2py intent (out) kk, kspec\n\n LX1=nx/2 + 1; NORM = nx*ny*nz\n kminx=2*pi/lx; kminy = 2*pi/ly; kminz = 2*pi/lz\n select case (axis+1)\n case (1)\n allocate(fenp(ny,nz), kkx(ny), kky(nz))\n !! kkx = ky, kky = kz\n do i=1,ny; kkx(i)=dble(mod(i-1+ny/2,ny)-ny/2)*kminy; end do\n do i=1,nz; kky(i)=dble(mod(i-1+nz/2,nz)-nz/2)*kminz; end do\n ktop=min(ny*kminy/2,nz*kminz/2); nnx=ny; nny=nz\n kmin=min(kminy,kminz)\n case (2)\n allocate(fenp(LX1,nz), kkx(LX1), kky(nz))\n !! kkx = kx, kky = kz\n do i=1,LX1; kkx(i)=dble(i-1.0)*kminx; enddo\n do i=1,nz; kky(i)=dble(mod(i-1+nz/2,nz)-nz/2)*kminz; end do\n ktop=min(nx*kminx/2,nz*kminz/2); nnx=LX1; nny=nz\n kmin=min(kminx,kminz)\n case (3)\n allocate(fenp(LX1,ny), kkx(LX1), kky(ny))\n !! kkx = kx, kky = ky\n do i=1,LX1; kkx(i)=dble(i-1.0)*kminx; enddo\n do i=1,ny; kky(i)=dble(mod(i-1+ny/2,ny)-ny/2)*kminy; end do\n ktop=min(nx*kminx/2,ny*kminy/2); nnx=LX1; nny=ny\n kmin=min(kminx,kminy)\n end select\n\n allocate(ffld(LX1,ny,nz), fenergy(LX1,ny,nz))\n ! CREATE THE FFTW PLAN\n call dfftw_plan_dft_r2c_3d(plan,nx,ny,nz,a,ffld,FFTW_ESTIMATE)\n call dfftw_execute_dft_r2c(plan, a, ffld)\n ffld=ffld/NORM ! normalize the quantities in fourier space\n\n ! Calculate the energy in the fourier space, make sure \n ! that (1,:) part of the array is multiplied by half.\n fenergy=ffld*conjg(ffld); fenergy(1,:,:)=0.5*fenergy(1,:,:)\n fenp = sum(fenergy,dim=axis+1)\n kspec=0. ! Initialize the spectrum to zero\n ! Do the sum of energy over shells of k and save in the spectrum\n do i=1,nnx; do j=1,nny\n kp=dsqrt(kkx(i)**2+kky(j)**2)\n if (kp <= ktop) then\n k = int(dsqrt((kkx(i)/kmin)**2+(kky(j)/kmin)**2)+0.5)\n kspec(k)=kspec(k)+fenp(i,j)\n kk(k) = kp\n endif\n enddo; enddo \n ! DESTROY THE PLAN AND DEALLOCATE ARRAYS\n call dfftw_destroy_plan(plan)\n deallocate(ffld,fenergy,fenp,kkx,kky)\nend subroutine lperpspec\n", "meta": {"hexsha": "395f7532893525ab0453eb3dc17edbae7af908e1", "size": 8250, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Analysis/Simulations/OLLibs/F90/spectra.f90", "max_stars_repo_name": "ahmadryan/TurbAn", "max_stars_repo_head_hexsha": "b8866d103a2ca2f5fbad73bcd4416f19299f22b2", "max_stars_repo_licenses": ["BSD-2-Clause-Patent"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Analysis/Simulations/OLLibs/F90/spectra.f90", "max_issues_repo_name": "ahmadryan/TurbAn", "max_issues_repo_head_hexsha": "b8866d103a2ca2f5fbad73bcd4416f19299f22b2", "max_issues_repo_licenses": ["BSD-2-Clause-Patent"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Analysis/Simulations/OLLibs/F90/spectra.f90", "max_forks_repo_name": "ahmadryan/TurbAn", "max_forks_repo_head_hexsha": "b8866d103a2ca2f5fbad73bcd4416f19299f22b2", "max_forks_repo_licenses": ["BSD-2-Clause-Patent"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2019-03-22T15:30:12.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-10T02:55:50.000Z", "avg_line_length": 39.8550724638, "max_line_length": 74, "alphanum_fraction": 0.5764848485, "num_tokens": 3174, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797003640646, "lm_q2_score": 0.7371581626286833, "lm_q1q2_score": 0.671683553744928}} {"text": " module psycho_m\r\n use kind_m\r\n use fft_m\r\n implicit none\r\n private\r\n public :: psychoacoustics\r\n real (kd), save :: freq_fft(512), ath_fft(512), pseud_bark(512)\r\n real (kd), save :: crbw_fft(512), cbwl_fft(512)\r\n real (kd), save :: sp(512, 512) ! spreading function for masking\r\n real (kd), save :: scale\r\n real (kd), parameter :: alpha = 0.27_kd ! non-linear factor\r\n \r\n contains\r\n \r\n function psychoacoustics(pcm, isample_rate) result(smr) ! impure\r\n real (kd), intent(in ) :: pcm(:, :) \r\n integer , intent(in ) :: isample_rate\r\n real (kd) :: smr(32, size(pcm, 2))\r\n complex(kd) :: cfft(1024)\r\n integer :: ichannel, i0, i1\r\n logical, save :: qfirst = .true.\r\n if (qfirst) then\r\n qfirst = .false.\r\n call init_absolute_threshold(isample_rate)\r\n end if\r\n i0 = (1632 - 1024) / 2\r\n i1 = i0 + 1024 - 1\r\n do ichannel = 1, size(pcm, 2)\r\n call fft_window(pcm(i0:i1, ichannel), cfft)\r\n call calc_smr(cfft, smr(:, ichannel))\r\n end do\r\n end function psychoacoustics\r\n \r\n \r\n subroutine init_absolute_threshold(isample_rate)\r\n integer, intent(in) :: isample_rate\r\n real (kd) :: freq, tmp\r\n integer :: i, m\r\n do i = 1, size(freq_fft)\r\n freq = real(isample_rate, kind = kd) / 2.0_kd / 1000.0_kd &\r\n * real(i - 1, kind = kd) / real(size(freq_fft), kind = kd)\r\n ath_fft(i) = 3.64_kd * freq**(-0.8_kd) & ! \r\n - 6.5_kd * exp(-0.6_kd * (freq - 3.3_kd)**2) + 0.001_kd * freq**4.0_kd \r\n freq = freq * 1000.0_kd ! khz -> hz\r\n freq_fft(i) = freq\r\n end do\r\n scale = real(isample_rate, kind = kd) / 2 / 512 ! freq to fft-line scale\r\n crbw_fft = critical_band_width( freq_fft ) ! critical band width in hz\r\n cbwl_fft = decibel( crbw_fft ) ! critical band width in log\r\n tmp = 0.0_kd ! pseud bark: integrate critical band \r\n do m = 1, 512\r\n tmp = tmp + 1.0_kd / crbw_fft(m) ! integration\r\n pseud_bark(m) = tmp * scale \r\n end do\r\n ! spreading function\r\n forall(i = 1:512, m = 1:512) sp(i, m) = spreading( pseud_bark( i ) - pseud_bark( m ) ) ! top normalized to 1.0\r\n end subroutine init_absolute_threshold\r\n\r\n \r\n pure elemental real(kd) function spreading(z)\r\n real(kd), intent(in) :: z ! pseud-bark\r\n if ( z > 0.0_kd ) then\r\n spreading = -25.0_kd * z \r\n else\r\n spreading = 75.0_kd * z \r\n end if\r\n spreading = max(-160.0_kd, spreading)\r\n end function spreading\r\n\r\n \r\n pure elemental real(kd) function critical_band_width(f)\r\n real(kd), intent(in) :: f ! hz\r\n real(kd), parameter :: gamma = 0.69_kd\r\n critical_band_width = 25.0_kd + 75.0_kd * ( 1.0_kd + 1.4_kd * (f / 1000.0_kd)**2 )**gamma \r\n ! critical_band_width = 100.0_kd * ( 1.0_kd + 1.0_kd * (f / 1000.0_kd)**2 )**gamma \r\n end function critical_band_width\r\n\r\n \r\n pure elemental real(kd) function decibel(x) \r\n real (kd), intent(in) :: x \r\n decibel = 10.0e0_kd * log10( max(x, 1.0e-100_kd) )\r\n end function decibel\r\n \r\n \r\n subroutine calc_smr(cfft, smr)\r\n complex(kd), intent(in) :: cfft(:)\r\n real (kd), intent(out) :: smr(:)\r\n real (kd) :: snr(32), amnr(32)\r\n real (kd) :: xa(512), ya(512), za(512)\r\n integer :: iband, i, m, i0, i1\r\n xa = 2 * decibel( abs(cfft(1:512)) )\r\n xa(1) = 0.0_kd ! dc cut\r\n ! convolution of spreading function\r\n ya = 0.0_kd\r\n do i = 1, 512\r\n do m = 1, 512 ! i maskee, m masker \r\n ya(i) = ya(i) + 10.0_kd**( ((sp(i, m) + xa(m) - ath_fft(m)) * alpha - cbwl_fft(m)) / 10.0_kd ) ! non-linear sum\r\n end do\r\n end do \r\n ya = max(decibel(ya * scale) / alpha - 11.5_kd, ath_fft - 90.3_kd) ! 11.5 mask factor, 90.3dB = 2^15 ATH shift empirical \r\n ! effective spl\r\n do i = 1, 512\r\n m = nint( crbw_fft(i) / scale )\r\n i0 = max(i - m / 2, 1) !f0 - bw(f0) / 2 \r\n i1 = min(i0 + m - 1, 512) !f0 + bw(f0) / 2\r\n za(i) = sum( 10.0_kd**( (xa(i0:i1) * alpha - cbwl_fft(i)) / 10.0_kd ) ) \r\n end do\r\n za = decibel(za * scale) / alpha\r\n ! smr = snr' - mnr'\r\n do iband = 1, 32\r\n m = (iband - 1) * 16 + 1\r\n i0 = m - nint( crbw_fft(m) / 2 / scale ) ! fl - bw(fl) / 2 ; subband [fl..fh] \r\n i0 = max(i0, 1)\r\n m = m + 15\r\n i1 = m + nint( crbw_fft(m) / 2 / scale ) ! fh + bw(fh) / 2 \r\n i1 = min(i1, 512)\r\n snr(iband) = maxval( za(i0:i1) )\r\n amnr(iband) = minval( ya(i0:i1) ) \r\n end do\r\n smr = snr - amnr \r\n end subroutine calc_smr\r\n \r\n end module psycho_m", "meta": {"hexsha": "a9e3991fd7210f536ff57cdd06e2702ac819bb0d", "size": 5419, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/psycho_m.f90", "max_stars_repo_name": "cure-honey/uzura2_fpm", "max_stars_repo_head_hexsha": "ff28574513a17efee64724c2afbac092586038c0", "max_stars_repo_licenses": ["MIT"], "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/psycho_m.f90", "max_issues_repo_name": "cure-honey/uzura2_fpm", "max_issues_repo_head_hexsha": "ff28574513a17efee64724c2afbac092586038c0", "max_issues_repo_licenses": ["MIT"], "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/psycho_m.f90", "max_forks_repo_name": "cure-honey/uzura2_fpm", "max_forks_repo_head_hexsha": "ff28574513a17efee64724c2afbac092586038c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.0569105691, "max_line_length": 135, "alphanum_fraction": 0.4596789075, "num_tokens": 1660, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009596336303, "lm_q2_score": 0.7341195152660688, "lm_q1q2_score": 0.6716466490027018}} {"text": "\n! Sample solution to the problem posed in Lab 12.\n! Version with coarse grain parallelism\n\nprogram main\n\n use omp_lib\n use random_util, only: init_random_seed\n\n implicit none\n integer :: seed, nthreads\n integer, parameter :: ntests = 7\n real (kind=8), allocatable :: x(:)\n real (kind=8) :: sum, count1, count4\n real (kind=8), dimension(ntests) :: mean,q1,q4\n integer :: i,n,k,kstart,kend,thread_num,points_per_thread\n\n ! Specify number of threads to use:\n nthreads = 1 ! need this value in serial mode\n !$ nthreads = 2\n !$ call omp_set_num_threads(nthreads)\n !$ print \"('Using OpenMP with ',i3,' threads')\", nthreads\n\n print *, \"input seed\"\n read *, seed\n\n call init_random_seed(seed) \n\n print *, \" n mean quartile 1 quartile 4\"\n\n points_per_thread = (ntests + nthreads - 1) / nthreads\n print *, \"points_per_thread = \",points_per_thread\n\n !$omp parallel private(k,x,count1,count4,sum,kstart,kend,thread_num,n)\n\n thread_num = 0 ! needed in serial mode\n !$ thread_num = omp_get_thread_num() ! unique for each thread\n\n ! Determine start and end index for the set of points to be\n ! handled by this thread:\n kstart = thread_num * points_per_thread + 1\n kend = min((thread_num+1) * points_per_thread, ntests)\n\n !$omp critical\n print 201, thread_num, kstart, kend\n !$omp end critical\n201 format(\"Thread \",i2,\" will take k = \",i6,\" through k = \",i6)\n\n do k=kstart,kend\n n = 10**(k+1)\n allocate(x(n))\n call random_number(x)\n sum = 0.d0\n count1 = 0\n count4 = 0\n do i=1,n\n sum = sum + x(i)\n if (x(i) < 0.25) then\n count1 = count1 + 1\n endif\n if (x(i) > 0.75) then\n count4 = count4 + 1\n endif\n enddo\n mean(k) = sum / float(n)\n q1(k) = count1 / float(n)\n q4(k) = count4 / float(n)\n deallocate(x)\n enddo\n !$omp end parallel\n\n\n do k=1,ntests\n n = 10**(k+1)\n print 601, n,mean(k),q1(k),q4(k)\n 601 format(i10,3f15.8)\n enddo\n \n\nend program main\n\n", "meta": {"hexsha": "4910d0cd0a7dec684cfb724acb4280fe846f916b", "size": 2183, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/labs/lab12/mean2.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/lab12/mean2.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/lab12/mean2.f90", "max_forks_repo_name": "philipwangdk/HPC", "max_forks_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.6219512195, "max_line_length": 74, "alphanum_fraction": 0.5703160788, "num_tokens": 643, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.6716194525091589}} {"text": "c program DRSSBASD\nc>> 1996-07-09 DRSSBASD Krogh Format changes for conversion to C.\nc>> 1994-10-19 DRSSBASD Krogh Changes to use M77CON\nc>> 1993-01-12 DRSSBASD CLL @ JPL\nc>> 1992-11-12 CLL @ JPL\nc>> 1992-11-04 CLL @ JPL\nc Demo driver for SSBASD, SSBASI, SSDIF, SSFIND, SSVALA.\nc ------------------------------------------------------------------\nc--S replaces \"?\": DR?SBASD, ?SBASD, ?SBASI, ?SDIF, ?SFIND, ?SVALA\nc ------------------------------------------------------------------\n integer I, IDERIV, J1, J2, KORDER, LEFT, MODE, NCOEF, NDERIV\n parameter(KORDER = 4, NCOEF = 6)\n parameter( IDERIV = 2, NDERIV = 3)\n real BASI(NCOEF), BCOEF(NCOEF), BDERIV(KORDER)\n real BDIF(NCOEF*(NDERIV+1)), BVALS(KORDER)\n real SVALUE(NDERIV+1)\n real TKNOTS(KORDER+NCOEF), X, X1, X2\n parameter( X = 0.4e0 , X1 = 0.1e0, X2 = 0.9e0)\n data TKNOTS / 4*0.0e0, 0.3e0, 0.8e0, 4*1.0e0 /\n data BCOEF / 0.1e0, 0.4e0, 0.2e0, -0.3e0, -0.5e0, -0.2e0 /\nc ------------------------------------------------------------------\n print '('' DRSSBASD.. Demo driver for''/\n * '' SSBASD, SSBASI, SSDIF, SSFIND, SSVALA.''/\n * 3x,'' KORDER ='',i2,'', NCOEF ='',i2/ 3x,'' TKNOTS() ='',\n * 10f5.1)', KORDER, NCOEF, (TKNOTS(I),I=1,KORDER+NCOEF)\n print '('' Using SSFIND with X = '',f5.1)', X\n LEFT = 1\n call SSFIND(TKNOTS, KORDER, NCOEF+1, X, LEFT, MODE)\n print '(3x,'' LEFT = '',i2,'', MODE ='',i2)', LEFT, MODE\n print '('' Using SSBASD with IDERIV = 0'')'\n call SSBASD( KORDER, LEFT, TKNOTS, X, 0, BVALS)\n print'(3x,'' Values at X of basis functions indexed from '',i2,\n * '' to '',i2/6x,4f12.6)', LEFT+1-KORDER, LEFT,\n * (BVALS(I),I=1,KORDER)\n print'('' Using SSBASD with IDERIV ='',i2)', IDERIV\n call SSBASD(KORDER, LEFT, TKNOTS, X, IDERIV, BDERIV)\n print'(3x,\n * '' Values at X of 2nd deriv of basis functions indexed from '',\n * i2,'' to '',i2/6x,4f12.5)', LEFT+1-KORDER, LEFT,\n * (BDERIV(I),I=1,KORDER)\n print'('' Using SSBASI with X1 = '',f5.1,'' and X2 = '',f5.1)',\n * X1,X2\n J1 = 1\n J2 = 1\n call SSBASI(KORDER, NCOEF, TKNOTS, X1, X2, J1, J2, BASI)\n print'(3x,'' J1 ='',i2,'', J2 ='',i2/3x,\n * '' Integrals from X1 to X2 of basis functions:''/3x,6f11.6)',\n * J1, J2, (BASI(I),I=1,NCOEF)\n print'('' Using SSDIF and SSVALA with NDERIV ='',i2,'' and''/3x,\n * '' BCOEF() = '', 6f5.1)', NDERIV, (BCOEF(I),I=1,NCOEF)\n call SSDIF(KORDER, NCOEF, TKNOTS, BCOEF, NDERIV, BDIF)\n call SSVALA(KORDER, NCOEF, TKNOTS, NDERIV, BDIF, X, SVALUE)\n print'(3x,'' Values of derivs 0 through '',i2,'' at X: ''/\n * 6x,4f11.6)', NDERIV, (SVALUE(I),I=1,NDERIV+1)\n end\n", "meta": {"hexsha": "cd3fab60dbd771ab031070347b9c71ec4499098c", "size": 2811, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drssbasd.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drssbasd.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drssbasd.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": 50.1964285714, "max_line_length": 72, "alphanum_fraction": 0.5094272501, "num_tokens": 1148, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357735451835, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6715915081763908}} {"text": "module mathf\n implicit none\n contains\n\n subroutine mag(n, a, a_mag)\n implicit none\n integer, intent(in) :: n\n real, intent(in) :: a(n)\n real, intent(out) :: a_mag\n a_mag = sqrt(sum(a**2))\n return\n end subroutine mag\n\n subroutine unit(n, a, a_unit)\n implicit none\n integer, intent(in) :: n\n real, intent(in) :: a(n)\n real, intent(out) :: a_unit(n)\n real :: a_mag\n call mag(n, a, a_mag)\n a_unit = a / a_mag\n return\n end subroutine unit\n\n subroutine find_gcd(a, b, gcd)\n implicit none\n integer, intent(in) :: a, b\n integer :: c, d\n integer, intent(out) :: gcd\n c = a\n gcd = b\n do while (c /= 0)\n d = c\n c = modulo(gcd, c)\n gcd = d\n end do\n end subroutine find_gcd\n\n subroutine mandelbrot_set(z, c, n, n_iter, z_f)\n implicit none\n integer, intent(in) :: n, n_iter\n complex, intent(in), dimension(n, n) :: z, c\n complex, intent(out), dimension(n, n) :: z_f\n integer :: i\n z_f = z\n do i=1, n_iter\n z_f = z_f**2 + c\n end do\n end subroutine mandelbrot_set\n\n subroutine mandelbrot_rate(z, c, n, n_iter, z_f)\n implicit none\n integer, intent(in) :: n, n_iter\n complex, intent(in), dimension(n, n) :: z, c\n complex, intent(out), dimension(n_iter + 1, n, n) :: z_f\n integer :: i\n z_f(1, :, :) = z(:, :)\n do i=1, n_iter\n z_f(i+1, :, :) = z_f(i, :, :)**2 + c\n end do\n end subroutine mandelbrot_rate\n\nend module mathf\n", "meta": {"hexsha": "c282b5d29cac2bd09c3ccba4ba749c2c925662f0", "size": 1695, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/ftarcoder42/mathf.f90", "max_stars_repo_name": "StarkillerX42/starcoder42", "max_stars_repo_head_hexsha": "86fbd1a4ea90c75b5d2429ac5d1caf4b0d8dbef2", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/ftarcoder42/mathf.f90", "max_issues_repo_name": "StarkillerX42/starcoder42", "max_issues_repo_head_hexsha": "86fbd1a4ea90c75b5d2429ac5d1caf4b0d8dbef2", "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/ftarcoder42/mathf.f90", "max_forks_repo_name": "StarkillerX42/starcoder42", "max_forks_repo_head_hexsha": "86fbd1a4ea90c75b5d2429ac5d1caf4b0d8dbef2", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.484375, "max_line_length": 64, "alphanum_fraction": 0.4920353982, "num_tokens": 495, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736772, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6715915028538362}} {"text": "program problem12\n use euler\n implicit none\n integer*8 :: i,triangle=1\n integer, parameter :: n=500\n \n i=2\n do while (.true.)\n triangle=triangle+i\n i=i+1\n if (tau(triangle) .gt. n) then\n exit\n end if\n end do\n\n print *, triangle\n \nend program problem12\n", "meta": {"hexsha": "2bb30d5e6ced951204c3762b406d6a639c1bb788", "size": 294, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "problem12.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": "problem12.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": "problem12.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": 15.4736842105, "max_line_length": 36, "alphanum_fraction": 0.5884353741, "num_tokens": 91, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8670357735451835, "lm_q2_score": 0.7745833737577158, "lm_q1q2_score": 0.6715914946412591}} {"text": "*> \\brief ZGEEV computes the eigenvalues and, optionally, the left and/or right eigenvectors for GE matrices\n*\n* =========== DOCUMENTATION ===========\n*\n* Online html documentation available at\n* http://www.netlib.org/lapack/explore-html/\n*\n*> \\htmlonly\n*> Download ZGEEV + dependencies\n*> \n*> [TGZ]\n*> \n*> [ZIP]\n*> \n*> [TXT]\n*> \\endhtmlonly\n*\n* Definition:\n* ===========\n*\n* SUBROUTINE ZGEEV( JOBVL, JOBVR, N, A, LDA, W, VL, LDVL, VR, LDVR,\n* WORK, LWORK, RWORK, INFO )\n*\n* .. Scalar Arguments ..\n* CHARACTER JOBVL, JOBVR\n* INTEGER INFO, LDA, LDVL, LDVR, LWORK, N\n* ..\n* .. Array Arguments ..\n* DOUBLE PRECISION RWORK( * )\n* COMPLEX*16 A( LDA, * ), VL( LDVL, * ), VR( LDVR, * ),\n* $ W( * ), WORK( * )\n* ..\n*\n*\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*>\n*> ZGEEV computes for an N-by-N complex nonsymmetric matrix A, the\n*> eigenvalues and, optionally, the left and/or right eigenvectors.\n*>\n*> The right eigenvector v(j) of A satisfies\n*> A * v(j) = lambda(j) * v(j)\n*> where lambda(j) is its eigenvalue.\n*> The left eigenvector u(j) of A satisfies\n*> u(j)**H * A = lambda(j) * u(j)**H\n*> where u(j)**H denotes the conjugate transpose of u(j).\n*>\n*> The computed eigenvectors are normalized to have Euclidean norm\n*> equal to 1 and largest component real.\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in] JOBVL\n*> \\verbatim\n*> JOBVL is CHARACTER*1\n*> = 'N': left eigenvectors of A are not computed;\n*> = 'V': left eigenvectors of are computed.\n*> \\endverbatim\n*>\n*> \\param[in] JOBVR\n*> \\verbatim\n*> JOBVR is CHARACTER*1\n*> = 'N': right eigenvectors of A are not computed;\n*> = 'V': right eigenvectors of A are computed.\n*> \\endverbatim\n*>\n*> \\param[in] N\n*> \\verbatim\n*> N is INTEGER\n*> The order of the matrix A. N >= 0.\n*> \\endverbatim\n*>\n*> \\param[in,out] A\n*> \\verbatim\n*> A is COMPLEX*16 array, dimension (LDA,N)\n*> On entry, the N-by-N matrix A.\n*> On exit, A has been overwritten.\n*> \\endverbatim\n*>\n*> \\param[in] LDA\n*> \\verbatim\n*> LDA is INTEGER\n*> The leading dimension of the array A. LDA >= max(1,N).\n*> \\endverbatim\n*>\n*> \\param[out] W\n*> \\verbatim\n*> W is COMPLEX*16 array, dimension (N)\n*> W contains the computed eigenvalues.\n*> \\endverbatim\n*>\n*> \\param[out] VL\n*> \\verbatim\n*> VL is COMPLEX*16 array, dimension (LDVL,N)\n*> If JOBVL = 'V', the left eigenvectors u(j) are stored one\n*> after another in the columns of VL, in the same order\n*> as their eigenvalues.\n*> If JOBVL = 'N', VL is not referenced.\n*> u(j) = VL(:,j), the j-th column of VL.\n*> \\endverbatim\n*>\n*> \\param[in] LDVL\n*> \\verbatim\n*> LDVL is INTEGER\n*> The leading dimension of the array VL. LDVL >= 1; if\n*> JOBVL = 'V', LDVL >= N.\n*> \\endverbatim\n*>\n*> \\param[out] VR\n*> \\verbatim\n*> VR is COMPLEX*16 array, dimension (LDVR,N)\n*> If JOBVR = 'V', the right eigenvectors v(j) are stored one\n*> after another in the columns of VR, in the same order\n*> as their eigenvalues.\n*> If JOBVR = 'N', VR is not referenced.\n*> v(j) = VR(:,j), the j-th column of VR.\n*> \\endverbatim\n*>\n*> \\param[in] LDVR\n*> \\verbatim\n*> LDVR is INTEGER\n*> The leading dimension of the array VR. LDVR >= 1; if\n*> JOBVR = 'V', LDVR >= N.\n*> \\endverbatim\n*>\n*> \\param[out] WORK\n*> \\verbatim\n*> WORK is COMPLEX*16 array, dimension (MAX(1,LWORK))\n*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.\n*> \\endverbatim\n*>\n*> \\param[in] LWORK\n*> \\verbatim\n*> LWORK is INTEGER\n*> The dimension of the array WORK. LWORK >= max(1,2*N).\n*> For good performance, LWORK must generally be larger.\n*>\n*> If LWORK = -1, then a workspace query is assumed; the routine\n*> only calculates the optimal size of the WORK array, returns\n*> this value as the first entry of the WORK array, and no error\n*> message related to LWORK is issued by XERBLA.\n*> \\endverbatim\n*>\n*> \\param[out] RWORK\n*> \\verbatim\n*> RWORK is DOUBLE PRECISION array, dimension (2*N)\n*> \\endverbatim\n*>\n*> \\param[out] INFO\n*> \\verbatim\n*> INFO is INTEGER\n*> = 0: successful exit\n*> < 0: if INFO = -i, the i-th argument had an illegal value.\n*> > 0: if INFO = i, the QR algorithm failed to compute all the\n*> eigenvalues, and no eigenvectors have been computed;\n*> elements i+1:N of W contain eigenvalues which have\n*> converged.\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee\n*> \\author Univ. of California Berkeley\n*> \\author Univ. of Colorado Denver\n*> \\author NAG Ltd.\n*\n*> \\date June 2016\n*\n* @precisions fortran z -> c\n*\n*> \\ingroup complex16GEeigen\n*\n* =====================================================================\n SUBROUTINE ZGEEV( JOBVL, JOBVR, N, A, LDA, W, VL, LDVL, VR, LDVR,\n $ WORK, LWORK, RWORK, INFO )\n implicit none\n*\n* -- LAPACK driver routine (version 3.7.0) --\n* -- LAPACK is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n* June 2016\n*\n* .. Scalar Arguments ..\n CHARACTER JOBVL, JOBVR\n INTEGER INFO, LDA, LDVL, LDVR, LWORK, N\n* ..\n* .. Array Arguments ..\n DOUBLE PRECISION RWORK( * )\n COMPLEX*16 A( LDA, * ), VL( LDVL, * ), VR( LDVR, * ),\n $ W( * ), WORK( * )\n* ..\n*\n* =====================================================================\n*\n* .. Parameters ..\n DOUBLE PRECISION ZERO, ONE\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )\n* ..\n* .. Local Scalars ..\n LOGICAL LQUERY, SCALEA, WANTVL, WANTVR\n CHARACTER SIDE\n INTEGER HSWORK, I, IBAL, IERR, IHI, ILO, IRWORK, ITAU,\n $ IWRK, K, LWORK_TREVC, MAXWRK, MINWRK, NOUT\n DOUBLE PRECISION ANRM, BIGNUM, CSCALE, EPS, SCL, SMLNUM\n COMPLEX*16 TMP\n* ..\n* .. Local Arrays ..\n LOGICAL SELECT( 1 )\n DOUBLE PRECISION DUM( 1 )\n* ..\n* .. External Subroutines ..\n EXTERNAL DLABAD, XERBLA, ZDSCAL, ZGEBAK, ZGEBAL, ZGEHRD,\n $ ZHSEQR, ZLACPY, ZLASCL, ZSCAL, ZTREVC3, ZUNGHR\n* ..\n* .. External Functions ..\n LOGICAL LSAME\n INTEGER IDAMAX, ILAENV\n DOUBLE PRECISION DLAMCH, DZNRM2, ZLANGE\n EXTERNAL LSAME, IDAMAX, ILAENV, DLAMCH, DZNRM2, ZLANGE\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC DBLE, DCMPLX, CONJG, AIMAG, MAX, SQRT\n* ..\n* .. Executable Statements ..\n*\n* Test the input arguments\n*\n INFO = 0\n LQUERY = ( LWORK.EQ.-1 )\n WANTVL = LSAME( JOBVL, 'V' )\n WANTVR = LSAME( JOBVR, 'V' )\n IF( ( .NOT.WANTVL ) .AND. ( .NOT.LSAME( JOBVL, 'N' ) ) ) THEN\n INFO = -1\n ELSE IF( ( .NOT.WANTVR ) .AND. ( .NOT.LSAME( JOBVR, 'N' ) ) ) THEN\n INFO = -2\n ELSE IF( N.LT.0 ) THEN\n INFO = -3\n ELSE IF( LDA.LT.MAX( 1, N ) ) THEN\n INFO = -5\n ELSE IF( LDVL.LT.1 .OR. ( WANTVL .AND. LDVL.LT.N ) ) THEN\n INFO = -8\n ELSE IF( LDVR.LT.1 .OR. ( WANTVR .AND. LDVR.LT.N ) ) THEN\n INFO = -10\n END IF\n*\n* Compute workspace\n* (Note: Comments in the code beginning \"Workspace:\" describe the\n* minimal amount of workspace needed at that point in the code,\n* as well as the preferred amount for good performance.\n* CWorkspace refers to complex workspace, and RWorkspace to real\n* workspace. NB refers to the optimal block size for the\n* immediately following subroutine, as returned by ILAENV.\n* HSWORK refers to the workspace preferred by ZHSEQR, as\n* calculated below. HSWORK is computed assuming ILO=1 and IHI=N,\n* the worst case.)\n*\n IF( INFO.EQ.0 ) THEN\n IF( N.EQ.0 ) THEN\n MINWRK = 1\n MAXWRK = 1\n ELSE\n MAXWRK = N + N*ILAENV( 1, 'ZGEHRD', ' ', N, 1, N, 0 )\n MINWRK = 2*N\n IF( WANTVL ) THEN\n MAXWRK = MAX( MAXWRK, N + ( N - 1 )*ILAENV( 1, 'ZUNGHR',\n $ ' ', N, 1, N, -1 ) )\n CALL ZTREVC3( 'L', 'B', SELECT, N, A, LDA,\n $ VL, LDVL, VR, LDVR,\n $ N, NOUT, WORK, -1, RWORK, -1, IERR )\n LWORK_TREVC = INT( WORK(1) )\n MAXWRK = MAX( MAXWRK, N + LWORK_TREVC )\n CALL ZHSEQR( 'S', 'V', N, 1, N, A, LDA, W, VL, LDVL,\n $ WORK, -1, INFO )\n ELSE IF( WANTVR ) THEN\n MAXWRK = MAX( MAXWRK, N + ( N - 1 )*ILAENV( 1, 'ZUNGHR',\n $ ' ', N, 1, N, -1 ) )\n CALL ZTREVC3( 'R', 'B', SELECT, N, A, LDA,\n $ VL, LDVL, VR, LDVR,\n $ N, NOUT, WORK, -1, RWORK, -1, IERR )\n LWORK_TREVC = INT( WORK(1) )\n MAXWRK = MAX( MAXWRK, N + LWORK_TREVC )\n CALL ZHSEQR( 'S', 'V', N, 1, N, A, LDA, W, VR, LDVR,\n $ WORK, -1, INFO )\n ELSE\n CALL ZHSEQR( 'E', 'N', N, 1, N, A, LDA, W, VR, LDVR,\n $ WORK, -1, INFO )\n END IF\n HSWORK = INT( WORK(1) )\n MAXWRK = MAX( MAXWRK, HSWORK, MINWRK )\n END IF\n WORK( 1 ) = MAXWRK\n*\n IF( LWORK.LT.MINWRK .AND. .NOT.LQUERY ) THEN\n INFO = -12\n END IF\n END IF\n*\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'ZGEEV ', -INFO )\n RETURN\n ELSE IF( LQUERY ) THEN\n RETURN\n END IF\n*\n* Quick return if possible\n*\n IF( N.EQ.0 )\n $ RETURN\n*\n* Get machine constants\n*\n EPS = DLAMCH( 'P' )\n SMLNUM = DLAMCH( 'S' )\n BIGNUM = ONE / SMLNUM\n CALL DLABAD( SMLNUM, BIGNUM )\n SMLNUM = SQRT( SMLNUM ) / EPS\n BIGNUM = ONE / SMLNUM\n*\n* Scale A if max element outside range [SMLNUM,BIGNUM]\n*\n ANRM = ZLANGE( 'M', N, N, A, LDA, DUM )\n SCALEA = .FALSE.\n IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN\n SCALEA = .TRUE.\n CSCALE = SMLNUM\n ELSE IF( ANRM.GT.BIGNUM ) THEN\n SCALEA = .TRUE.\n CSCALE = BIGNUM\n END IF\n IF( SCALEA )\n $ CALL ZLASCL( 'G', 0, 0, ANRM, CSCALE, N, N, A, LDA, IERR )\n*\n* Balance the matrix\n* (CWorkspace: none)\n* (RWorkspace: need N)\n*\n IBAL = 1\n CALL ZGEBAL( 'B', N, A, LDA, ILO, IHI, RWORK( IBAL ), IERR )\n*\n* Reduce to upper Hessenberg form\n* (CWorkspace: need 2*N, prefer N+N*NB)\n* (RWorkspace: none)\n*\n ITAU = 1\n IWRK = ITAU + N\n CALL ZGEHRD( N, ILO, IHI, A, LDA, WORK( ITAU ), WORK( IWRK ),\n $ LWORK-IWRK+1, IERR )\n*\n IF( WANTVL ) THEN\n*\n* Want left eigenvectors\n* Copy Householder vectors to VL\n*\n SIDE = 'L'\n CALL ZLACPY( 'L', N, N, A, LDA, VL, LDVL )\n*\n* Generate unitary matrix in VL\n* (CWorkspace: need 2*N-1, prefer N+(N-1)*NB)\n* (RWorkspace: none)\n*\n CALL ZUNGHR( N, ILO, IHI, VL, LDVL, WORK( ITAU ), WORK( IWRK ),\n $ LWORK-IWRK+1, IERR )\n*\n* Perform QR iteration, accumulating Schur vectors in VL\n* (CWorkspace: need 1, prefer HSWORK (see comments) )\n* (RWorkspace: none)\n*\n IWRK = ITAU\n CALL ZHSEQR( 'S', 'V', N, ILO, IHI, A, LDA, W, VL, LDVL,\n $ WORK( IWRK ), LWORK-IWRK+1, INFO )\n*\n IF( WANTVR ) THEN\n*\n* Want left and right eigenvectors\n* Copy Schur vectors to VR\n*\n SIDE = 'B'\n CALL ZLACPY( 'F', N, N, VL, LDVL, VR, LDVR )\n END IF\n*\n ELSE IF( WANTVR ) THEN\n*\n* Want right eigenvectors\n* Copy Householder vectors to VR\n*\n SIDE = 'R'\n CALL ZLACPY( 'L', N, N, A, LDA, VR, LDVR )\n*\n* Generate unitary matrix in VR\n* (CWorkspace: need 2*N-1, prefer N+(N-1)*NB)\n* (RWorkspace: none)\n*\n CALL ZUNGHR( N, ILO, IHI, VR, LDVR, WORK( ITAU ), WORK( IWRK ),\n $ LWORK-IWRK+1, IERR )\n*\n* Perform QR iteration, accumulating Schur vectors in VR\n* (CWorkspace: need 1, prefer HSWORK (see comments) )\n* (RWorkspace: none)\n*\n IWRK = ITAU\n CALL ZHSEQR( 'S', 'V', N, ILO, IHI, A, LDA, W, VR, LDVR,\n $ WORK( IWRK ), LWORK-IWRK+1, INFO )\n*\n ELSE\n*\n* Compute eigenvalues only\n* (CWorkspace: need 1, prefer HSWORK (see comments) )\n* (RWorkspace: none)\n*\n IWRK = ITAU\n CALL ZHSEQR( 'E', 'N', N, ILO, IHI, A, LDA, W, VR, LDVR,\n $ WORK( IWRK ), LWORK-IWRK+1, INFO )\n END IF\n*\n* If INFO .NE. 0 from ZHSEQR, then quit\n*\n IF( INFO.NE.0 )\n $ GO TO 50\n*\n IF( WANTVL .OR. WANTVR ) THEN\n*\n* Compute left and/or right eigenvectors\n* (CWorkspace: need 2*N, prefer N + 2*N*NB)\n* (RWorkspace: need 2*N)\n*\n IRWORK = IBAL + N\n CALL ZTREVC3( SIDE, 'B', SELECT, N, A, LDA, VL, LDVL, VR, LDVR,\n $ N, NOUT, WORK( IWRK ), LWORK-IWRK+1,\n $ RWORK( IRWORK ), N, IERR )\n END IF\n*\n IF( WANTVL ) THEN\n*\n* Undo balancing of left eigenvectors\n* (CWorkspace: none)\n* (RWorkspace: need N)\n*\n CALL ZGEBAK( 'B', 'L', N, ILO, IHI, RWORK( IBAL ), N, VL, LDVL,\n $ IERR )\n*\n* Normalize left eigenvectors and make largest component real\n*\n DO 20 I = 1, N\n SCL = ONE / DZNRM2( N, VL( 1, I ), 1 )\n CALL ZDSCAL( N, SCL, VL( 1, I ), 1 )\n DO 10 K = 1, N\n RWORK( IRWORK+K-1 ) = DBLE( VL( K, I ) )**2 +\n $ AIMAG( VL( K, I ) )**2\n 10 CONTINUE\n K = IDAMAX( N, RWORK( IRWORK ), 1 )\n TMP = CONJG( VL( K, I ) ) / SQRT( RWORK( IRWORK+K-1 ) )\n CALL ZSCAL( N, TMP, VL( 1, I ), 1 )\n VL( K, I ) = DCMPLX( DBLE( VL( K, I ) ), ZERO )\n 20 CONTINUE\n END IF\n*\n IF( WANTVR ) THEN\n*\n* Undo balancing of right eigenvectors\n* (CWorkspace: none)\n* (RWorkspace: need N)\n*\n CALL ZGEBAK( 'B', 'R', N, ILO, IHI, RWORK( IBAL ), N, VR, LDVR,\n $ IERR )\n*\n* Normalize right eigenvectors and make largest component real\n*\n DO 40 I = 1, N\n SCL = ONE / DZNRM2( N, VR( 1, I ), 1 )\n CALL ZDSCAL( N, SCL, VR( 1, I ), 1 )\n DO 30 K = 1, N\n RWORK( IRWORK+K-1 ) = DBLE( VR( K, I ) )**2 +\n $ AIMAG( VR( K, I ) )**2\n 30 CONTINUE\n K = IDAMAX( N, RWORK( IRWORK ), 1 )\n TMP = CONJG( VR( K, I ) ) / SQRT( RWORK( IRWORK+K-1 ) )\n CALL ZSCAL( N, TMP, VR( 1, I ), 1 )\n VR( K, I ) = DCMPLX( DBLE( VR( K, I ) ), ZERO )\n 40 CONTINUE\n END IF\n*\n* Undo scaling if necessary\n*\n 50 CONTINUE\n IF( SCALEA ) THEN\n CALL ZLASCL( 'G', 0, 0, CSCALE, ANRM, N-INFO, 1, W( INFO+1 ),\n $ MAX( N-INFO, 1 ), IERR )\n IF( INFO.GT.0 ) THEN\n CALL ZLASCL( 'G', 0, 0, CSCALE, ANRM, ILO-1, 1, W, N, IERR )\n END IF\n END IF\n*\n WORK( 1 ) = MAXWRK\n RETURN\n*\n* End of ZGEEV\n*\n END\n", "meta": {"hexsha": "1ba5425879c394756559beaf8f88d7b3554a1597", "size": 16062, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "lapack-netlib/SRC/zgeev.f", "max_stars_repo_name": "dnoan/OpenBLAS", "max_stars_repo_head_hexsha": "b54b50fe3a5ec921d18ddf5fbdb80092d1b23893", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 4392, "max_stars_repo_stars_event_min_datetime": "2015-01-02T18:15:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T12:14:38.000Z", "max_issues_repo_path": "lapack-netlib/SRC/zgeev.f", "max_issues_repo_name": "dnoan/OpenBLAS", "max_issues_repo_head_hexsha": "b54b50fe3a5ec921d18ddf5fbdb80092d1b23893", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2067, "max_issues_repo_issues_event_min_datetime": "2015-01-01T03:50:01.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T18:59:43.000Z", "max_forks_repo_path": "lapack-netlib/SRC/zgeev.f", "max_forks_repo_name": "dnoan/OpenBLAS", "max_forks_repo_head_hexsha": "b54b50fe3a5ec921d18ddf5fbdb80092d1b23893", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1564, "max_forks_repo_forks_event_min_datetime": "2015-01-01T01:32:27.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T07:12:54.000Z", "avg_line_length": 31.869047619, "max_line_length": 116, "alphanum_fraction": 0.5005603287, "num_tokens": 5228, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.907312226373181, "lm_q2_score": 0.7401743735019594, "lm_q1q2_score": 0.6715692587264371}} {"text": "Module Gauss_quad\n!\n Real, Dimension(5,5) :: XMU_Gauss_Quad, WMU_Gauss_Quad\n!\n Data XMU_Gauss_Quad(1,:)/0.5,0.,0.,0.,0./\n Data WMU_Gauss_Quad(1,:)/1. ,0.,0.,0.,0./\n!\n Data XMU_Gauss_Quad(2,:)/0.1127017,0.7886751,0.,0.,0./\n Data WMU_Gauss_Quad(2,:)/0.5,0.5,0.,0.,0./\n!\n Data XMU_Gauss_Quad(3,:)/0.1127017,0.5000000,0.8872983,0.,0./\n Data WMU_Gauss_Quad(3,:)/0.2777778,0.4444444,0.2777778,0.,0./\n!\n Data XMU_Gauss_Quad(4,:)/6.9431841E-02,0.3300095,0.6699905,0.9305682,0./\n Data WMU_Gauss_Quad(4,:)/0.1739274,0.3260726,0.3260726,0.1739274,0./\n!\n Data XMU_Gauss_Quad(5,:)/4.6910077E-02,0.2307653,0.5000000,.7692347,0.9530900/\n Data WMU_Gauss_Quad(5,:)/0.1184634,0.2393143,0.2844445,0.2393143,0.1184634/\n!\nEnd Module Gauss_quad\n", "meta": {"hexsha": "9137c9d14dab4c640a7f435fd9f0d4710394c25b", "size": 734, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "inversor/database/NICOLE/forward/gauss_quad.f90", "max_stars_repo_name": "aasensio/DeepLearning", "max_stars_repo_head_hexsha": "71838115ce93e0ca96c8314cff3f07de1d64c235", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "inversor/database/NICOLE/forward/gauss_quad.f90", "max_issues_repo_name": "aasensio/DeepLearning", "max_issues_repo_head_hexsha": "71838115ce93e0ca96c8314cff3f07de1d64c235", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "inversor/database/NICOLE/forward/gauss_quad.f90", "max_forks_repo_name": "aasensio/DeepLearning", "max_forks_repo_head_hexsha": "71838115ce93e0ca96c8314cff3f07de1d64c235", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.9523809524, "max_line_length": 80, "alphanum_fraction": 0.6920980926, "num_tokens": 383, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.7401743735019595, "lm_q1q2_score": 0.671569255016271}} {"text": "C$Procedure STMP03 ( Stumpff functions 0 through 3 )\n \n SUBROUTINE STMP03 ( X, C0, C1, C2, C3 )\n \nC$ Abstract\nC\nC Compute the values of the Stumpff functions C_0 through C_3 at\nC a specified point.\nC\nC$ Disclaimer\nC\nC THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE\nC CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.\nC GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE\nC ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE\nC PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED \"AS-IS\"\nC TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY\nC WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A\nC PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC\nC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE\nC SOFTWARE AND RELATED MATERIALS, HOWEVER USED.\nC\nC IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA\nC BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT\nC LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,\nC INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,\nC REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE\nC REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.\nC\nC RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF\nC THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY\nC CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE\nC ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.\nC\nC$ Required_Reading\nC\nC None.\nC\nC$ Keywords\nC\nC CONIC\nC MATH\nC UTILITY\nC\nC$ Declarations\n \n DOUBLE PRECISION X\n DOUBLE PRECISION C0\n DOUBLE PRECISION C1\n DOUBLE PRECISION C2\n DOUBLE PRECISION C3\n \n \n INTEGER TRUNC\n PARAMETER ( TRUNC = 11 )\n \nC$ Brief_I/O\nC\nC Variable I/O Description\nC -------- --- --------------------------------------------------\nC X I Argument to each Stumpff function C_0 to C_3.\nC C0 O Value of C_0(X)\nC C1 O Value of C_1(X)\nC C2 O Value of C_2(X)\nC C3 O Value of C_3(X)\nC TRUNC P Number of terms needed in Maclaurin series for C_3.\nC\nC$ Detailed_Input\nC\nC X is the argument to use in each of the Stumpff functions\nC C_0, C_1, C_2, and C_3.\nC\nC$ Detailed_Output\nC\nC C0 are the values of the Stumpff functions\nC C1 C_0(X), C_1(X), C_2(X), and C_3(X).\nC C2\nC C3\nC\nC$ Parameters\nC\nC TRUNC The Maclaurin series for C_3 and C_2 respectively are:\nC\nC 2 3 k\nC 1 X X X (-X)\nC C_3(X) = --- - --- + --- - --- + . . . + ----------. . .\nC 3! 5! 7! 9! (3 + 2*K)!\nC\nC and\nC\nC 2 3 k\nC 1 X X X (-X)\nC C_2(X) = --- - --- + --- - --- + . . . + ----------. . .\nC 2! 4! 6! 8! (2 + 2*K)!\nC\nC These series are used in the evaluation of C_3 and C_2.\nC Thus, it is necessary to make a decision about where to\nC truncate the series in our evaluation of C_3 and C_2.\nC\nC TRUNC is used to tell this routine where to truncate\nC the Maclaurin series for C_3 and C_2.\nC\nC The value of TRUNC for your machine is the smallest\nC integer such that\nC\nC 1\nC 1.0D0 + ---------- = 1.0D0\nC (2*TRUNC)!\nC\nC The following program will (if compiled and linked)\nC will produce the values of TRUNC for your machine.\nC\nC INTEGER TRUNC\nC\nC DOUBLE PRECISION DENOM\nC DOUBLE PRECISION FACTR\nC\nC DOUBLE PRECISION X\nC\nC DENOM = 2.0D0\nC FACTR = 2.0D0\nC TRUNC = 1\nC\nC X = 1.0D0 / DENOM\nC\nC DO WHILE ( 1.0D0 + X .GT. 1.0D0 )\nC DENOM = DENOM * (2.0D0+FACTR) * (1.0D0+FACTR)\nC FACTR = FACTR + 2.0D0\nC TRUNC = TRUNC + 1\nC X = 1.0D0 / DENOM\nC END DO\nC\nC WRITE (*,*) 'The value of TRUNC is: ', TRUNC\nC\nC END\nC\nC$ Exceptions\nC\nC 1) If the input value of X is not in the domain of values\nC for which the Stumpff functions can be computed, the error\nC SPICE(VALUEOUTOFRANGE) is signalled.\nC\nC The range of valid inputs is from -[ln(2) + ln(DPMAX)]**2\nC to DPMAX.\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC This routine computes the values of the Stumpff functions C_0,\nC C_1, C_2, and C_3 at the input X.\nC\nC The Stumpff function C_k(X) for k = 0, 1, ... is given by the\nC series:\nC\nC 2 3 m\nC 1 X X X (-X)\nC C_k(X) = --- - ------ + ------ - ------ + . . . + ------- + . . .\nC k! (k+2)! (k+4)! (k+6)! (k+2m)!\nC\nC\nC These series converge for all real values of X.\nC\nC\nC$ Examples\nC\nC For positive X,\nC\nC C_0(X) = COS ( DSQRT(X) )\nC\nC\nC SIN ( DSQRT(X) )\nC C_1(X) = ---------------\nC DSQRT(X)\nC\nC\nC 1 - COS ( DSQRT(X) )\nC C_2(X) = ---------------------\nC X\nC\nC\nC\nC 1 - SIN ( DSQRT(X) ) / DSQRT(X)\nC C_3(X) = ----------------------------------\nC X\nC\nC Thus the following block of code can be used to check this\nC routine for reasonableness:\nC\nC INTEGER I\nC\nC DOUBLE PRECISION X\nC DOUBLE PRECISION ROOTX\nC\nC DOUBLE PRECISION TC0\nC DOUBLE PRECISION TC1\nC DOUBLE PRECISION TC2\nC DOUBLE PRECISION TC3\nC\nC DOUBLE PRECISION C0\nC DOUBLE PRECISION C1\nC DOUBLE PRECISION C2\nC DOUBLE PRECISION C3\nC\nC DO I = 1, 10\nC\nC X = DBLE (I)\nC ROOTX = DSQRT(X)\nC\nC TC0 = COS ( ROOTX )\nC TC1 = SIN ( ROOTX ) / ROOTX\nC\nC TC2 = ( 1.0D0 - COS( ROOTX ) ) / X\nC TC3 = ( 1.0D0 - SIN( ROOTX ) / ROOTX ) / X\nC\nC CALL STMP03 ( X, C0, C1, C2, C3 )\nC\nC WRITE (*,*)\nC WRITE (*,*) 'Expected - Computed for X = ', X\nC WRITE (*,*)\nC WRITE (*,*) 'Delta C0 :', TC0 - C0\nC WRITE (*,*) 'Delta C1 :', TC1 - C1\nC WRITE (*,*) 'Delta C2 :', TC2 - C2\nC WRITE (*,*) 'Delta C3 :', TC3 - C3\nC\nC END DO\nC\nC END\nC\nC You should expect all of the differences to be on the order of\nC the precision of the machine on which this program is executed.\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Literature_References\nC\nC [1] `Fundamentals of Celestial Mechanics', Second Edition\nC by J.M.A. Danby; Willman-Bell, Inc., P.O. Box 35025\nC Richmond Virginia; pp 168-180\nC\nC$ Author_and_Institution\nC\nC N.J. Bachman (JPL)\nC H.A. Neilan (JPL)\nC W.L. Taber (JPL)\nC B.V. Semenov (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 3.27.0, 08-APR-2014 (NJB)\nC\nC Updated in-line documentation and cleaned up\nC code following changes made in version 3.21.0.\nC\nC- SPICELIB Version 3.26.0, 10-MAR-2014 (BVS)\nC\nC Updated for SUN-SOLARIS-64BIT-INTEL.\nC\nC- SPICELIB Version 3.25.0, 10-MAR-2014 (BVS)\nC\nC Updated for PC-LINUX-64BIT-IFORT.\nC\nC- SPICELIB Version 3.24.0, 10-MAR-2014 (BVS)\nC\nC Updated for PC-CYGWIN-GFORTRAN.\nC\nC- SPICELIB Version 3.23.0, 10-MAR-2014 (BVS)\nC\nC Updated for PC-CYGWIN-64BIT-GFORTRAN.\nC\nC- SPICELIB Version 3.22.0, 10-MAR-2014 (BVS)\nC\nC Updated for PC-CYGWIN-64BIT-GCC_C.\nC\nC- SPICELIB Version 3.21.0, 09-APR-2012 (WLT)\nC\nC Code was updated to correct execessive round-off\nC errors in the case where |X| > 1.\nC\nC- SPICELIB Version 3.20.0, 13-MAY-2010 (BVS)\nC\nC Updated for SUN-SOLARIS-INTEL.\nC\nC- SPICELIB Version 3.19.0, 13-MAY-2010 (BVS)\nC\nC Updated for SUN-SOLARIS-INTEL-CC_C.\nC\nC- SPICELIB Version 3.18.0, 13-MAY-2010 (BVS)\nC\nC Updated for SUN-SOLARIS-INTEL-64BIT-CC_C.\nC\nC- SPICELIB Version 3.17.0, 13-MAY-2010 (BVS)\nC\nC Updated for SUN-SOLARIS-64BIT-NATIVE_C.\nC\nC- SPICELIB Version 3.16.0, 13-MAY-2010 (BVS)\nC\nC Updated for PC-WINDOWS-64BIT-IFORT.\nC\nC- SPICELIB Version 3.15.0, 13-MAY-2010 (BVS)\nC\nC Updated for PC-LINUX-64BIT-GFORTRAN.\nC\nC- SPICELIB Version 3.14.0, 13-MAY-2010 (BVS)\nC\nC Updated for PC-64BIT-MS_C.\nC\nC- SPICELIB Version 3.13.0, 13-MAY-2010 (BVS)\nC\nC Updated for MAC-OSX-64BIT-INTEL_C.\nC\nC- SPICELIB Version 3.12.0, 13-MAY-2010 (BVS)\nC\nC Updated for MAC-OSX-64BIT-IFORT.\nC\nC- SPICELIB Version 3.11.0, 13-MAY-2010 (BVS)\nC\nC Updated for MAC-OSX-64BIT-GFORTRAN.\nC\nC- SPICELIB Version 3.10.0, 18-MAR-2009 (BVS)\nC\nC Updated for PC-LINUX-GFORTRAN.\nC\nC- SPICELIB Version 3.9.0, 18-MAR-2009 (BVS)\nC\nC Updated for MAC-OSX-GFORTRAN.\nC\nC- SPICELIB Version 3.8.0, 19-FEB-2008 (BVS)\nC\nC Updated for PC-LINUX-IFORT.\nC\nC- SPICELIB Version 3.7.0, 14-NOV-2006 (BVS)\nC\nC Updated for PC-LINUX-64BIT-GCC_C.\nC\nC- SPICELIB Version 3.6.0, 14-NOV-2006 (BVS)\nC\nC Updated for MAC-OSX-INTEL_C.\nC\nC- SPICELIB Version 3.5.0, 14-NOV-2006 (BVS)\nC\nC Updated for MAC-OSX-IFORT.\nC\nC- SPICELIB Version 3.4.0, 14-NOV-2006 (BVS)\nC\nC Updated for PC-WINDOWS-IFORT.\nC\nC- SPICELIB Version 3.3.0, 26-OCT-2005 (BVS)\nC\nC Updated for SUN-SOLARIS-64BIT-GCC_C.\nC\nC- SPICELIB Version 3.2.0, 03-JAN-2005 (BVS)\nC\nC Updated for PC-CYGWIN_C.\nC\nC- SPICELIB Version 3.1.0, 03-JAN-2005 (BVS)\nC\nC Updated for PC-CYGWIN.\nC\nC- SPICELIB Version 3.0.5, 17-JUL-2002 (BVS)\nC\nC Added MAC-OSX environments.\nC\nC- SPICELIB Version 3.0.4, 08-OCT-1999 (WLT)\nC\nC The environment lines were expanded so that the supported\nC environments are now explicitely given. New\nC environments are WIN-NT\nC\nC- SPICELIB Version 3.0.3, 24-SEP-1999 (NJB)\nC\nC CSPICE environments were added. Some typos were corrected.\nC\nC- SPICELIB Version 3.0.2, 28-JUL-1999 (WLT)\nC\nC The environment lines were expanded so that the supported\nC environments are now explicitly given. New\nC environments are PC-DIGITAL, SGI-O32 and SGI-N32.\nC\nC- SPICELIB Version 3.0.1, 18-MAR-1999 (WLT)\nC\nC The environment lines were expanded so that the supported\nC environments are now explicitly given. Previously,\nC environments such as SUN-SUNOS and SUN-SOLARIS were implied\nC by the environment label SUN.\nC\nC- SPICELIB Version 3.0.0, 08-APR-1998 (NJB)\nC\nC Module was updated for the PC-LINUX platform.\nC\nC- SPICELIB Version 2.0.0, 11-NOV-1993 (HAN)\nC\nC The file was modified to include values for other platforms.\nC Also, the file was formatted for use by the program that\nC creates the environment specific source files.\nC\nC- SPICELIB Version 1.0.0, 17-FEB-1992 (WLT)\nC\nC-&\n \nC$ Index_Entries\nC\nC Evaluate the first four Stumpff functions\nC\nC-&\n \nC$ Revisions\nC\nC- SPICELIB Version 3.27.0, 08-APR-2014 (NJB) (WLT)\nC\nC In version 3.21.0, the routine was re-written to use the\nC standard trigonometric and hyperbolic trigonometric formulas\nC for the Stumpff functions for input arguments having magnitude\nC greater than or equal to 1. This was done to prevent loss of\nC accuracy for some input values.\nC\nC In version 3.27.0, the code was cleaned up: unreachable code\nC was deleted, and comments were changed to match the updated\nC code.\nC\nC The derivation of the argument mapping formulas has been\nC retained as an appendix in a comment section at the end of\nC this source file. These formulas may be used a future revision\nC of this routine.\nC\nC- SPICELIB Version 3.0.0, 08-APR-1998 (NJB)\nC\nC Module was updated for the PC-LINUX platform.\nC\nC- SPICELIB Version 2.0.0, 11-NOV-1993 (HAN)\nC\nC The file was modified to include values for other platforms.\nC Also, the file was formatted for use by the program that\nC creates the environment specific source files.\nC\nC-&\n \nC\nC SPICELIB Functions\nC\n DOUBLE PRECISION DPMAX\n \nC\nC Local Parameters\nC\n \n DOUBLE PRECISION HALF\n PARAMETER ( HALF = 1.0D0 / 2.0D0 )\n \n DOUBLE PRECISION EIGHTH\n PARAMETER ( EIGHTH = 1.0D0 / 8.0D0 )\n \nC\nC The integers NPAIRS, LPAIR2, and LPAIR3 are used to declare\nC space for Maclaurin series coefficients and for determining how\nC many terms of these series to use in the computation of\nC C_2 and C_3.\nC\nC Here's what is supposed to be true.\nC\nC 1/(TRUNC*2)! + 1.0D0 = 1.0D0\nC\nC using this machine's double precision arithmetic.\nC\nC We will map the input X to a value y between -1 and 1 and then\nC construct the values of the functions at X from their values at y.\nC Since we will only evaluate the series expansion for C_2 and C_3\nC for values of y between -1 and 1, its easy to show that we don't\nC need to consider terms in the series whose coefficients have\nC magnitudes less than or equal 1/(2*TRUNC)! .\nC\nC If the value of TRUNC is 10, then the series expansions for\nC C_2(y) and C_3(y) are can be truncated as shown here:\nC\nC 2 7 8\nC . 1 y y y y\nC C_3(y) = --- - --- + --- + ... - --- + ---\nC 3! 5! 7! 17! 19!\nC\nC\nC 1 y y y y\nC = ---( 1 - --- ( 1 - --- (...( 1- ----- ( 1 - ----- )...)\nC 2*3 4*5 6*7 16*17 18*19\nC\nC\nC\nC\nC . 1 y y y y\nC C_2(y) = --- - --- + --- + ... + --- - ---\nC 2! 4! 6! 16! 18!\nC\nC\nC 1 y y y y\nC = ---( 1 - --- ( 1 - --- (...( 1- ----- ( 1 - ----- )...)\nC 1*2 3*4 5*6 15*16 17*18\nC\nC As is evident from the above, we are going to need the\nC \"reciprocal pairs\"\nC\nC 1/(1*2), 1/(2*3), 1/(3*4), 1/(4*5), ...\nC\nC The number of such fractions be computed directly from\nC TRUNC. LPAIR3 and LPAIR2 indicate which of these pairs\nC (counting 1/(1*2) as the first) will be the last one needed in\nC the evaluation of C_2 and C_3.\nC\n INTEGER NPAIRS\n PARAMETER ( NPAIRS = 2*TRUNC - 2 )\n \n INTEGER LPAIR3\n PARAMETER ( LPAIR3 = NPAIRS )\n \n INTEGER LPAIR2\n PARAMETER ( LPAIR2 = NPAIRS - 1 )\n \n \nC\nC Local variables\nC\n DOUBLE PRECISION LBOUND\n DOUBLE PRECISION PAIRS ( NPAIRS )\n DOUBLE PRECISION Y\n DOUBLE PRECISION Z\n \n INTEGER I\n \n LOGICAL FIRST\n \nC\nC Saved variables\nC\n SAVE FIRST\n SAVE LBOUND\n SAVE PAIRS\n \nC\nC Initial values\nC\n DATA FIRST / .TRUE. /\n \n \nC\nC We are going to need the numbers\nC\nC 1/(2*3), 1/(3*4), 1/(4*5), ...\nC\nC but we don't want to compute them every time this routine is\nC called. So the first time this routine is called we compute\nC them and put them in the array PAIRS for use on subsequent\nC calls. (This could be done via parameters, but computing them\nC at run time seems to have a better chance of being\nC easily maintained.)\nC\nC In addition we will need to compute the lower bound for which\nC C_0,...,C_3 can be computed. This lower bound is computed by\nC noting that C_0 has the largest magnitude of all the Stumpff\nC functions over the domain from -infinity to -1. Moreover, in this\nC range\nC\nC C_0(X) = Cosh( SQRT(-X) )\nC\nC Thus the range of X for which the Stumpff functions can be\nC computed is bounded below by the value of X for which\nC\nC Cosh ( SQRT(-X) ) = DPMAX\nC\nC Which implies the lower bound for valid inputs is at\nC\nC X = - ( DLOG ( 2.0 ) + DLOG( DPMAX ) ) ** 2\nC\nC = - ( DLOG ( 2*N ) + DLOG ( DPMAX/N ) ) ** 2\nC\nC We point out the second formulation of the bound just in case\nC your compiler can't handle the computation of DLOG ( DPMAX ).\nC If this unfortunate situation should arise, complain to the\nC company that produces your compiler and in the code below\nC compute LBOUND using the second form above with N equal to\nC some large power of 2 (say 2**20).\nC\n IF ( FIRST ) THEN\n \n FIRST = .FALSE.\n \n DO I = 1, NPAIRS\n PAIRS(I) = 1.0D0 / (DBLE(I)*DBLE(I+1))\n END DO\n \n Y = DLOG(2.0D0) + DLOG( DPMAX() )\n LBOUND = - Y*Y\n \n END IF\n \n \nC\nC First we make sure that the input value of X is within the\nC range that we are confident we can use to compute the Stumpff\nC functions.\nC\n IF ( X .LE. LBOUND ) THEN\n \n CALL CHKIN ( 'STMP03' )\n CALL SETMSG( 'The input value of X must be greater than '\n . // '#. The input value was #' )\n CALL ERRDP ( '#', LBOUND )\n CALL ERRDP ( '#', X )\n CALL SIGERR( 'SPICE(VALUEOUTOFRANGE)' )\n CALL CHKOUT( 'STMP03' )\n RETURN\n \n END IF\n \nC\nC From the definition of the Stumpff functions it can be seen that\nC C_0(X), C_1(X) are given by\nC\nC COS ( DSQRT(X) ) and SIN ( DSQRT(X) ) / DSQRT(X)\nC\nC for positive X. Moreover, the series used to define them converges\nC for all real X.\nC\nC These functions have a number of simple relationships that make\nC their computations practical. Among these are:\nC\nC 1\nC x*C_k+2(x) = --- - C_k(x)\nC k!\nC\nC\nC\nC 2\nC C_0(4x) = 2*[ C_0(x) ] - 1\nC\nC\nC\nC\nC C_1(4x) = C_1(x)*C_0(x)\nC\nC\nC\nC 2\nC C_2(4x) = [C_1(x)] / 2\nC\nC\nC\nC\nC C_3(4x) = [ C_2(x) + C_0(x)*C_3(x) ] / 4\nC\nC These can be used to derive formulae for C_0(16x) ... C_3(16x)\nC that involve only C_0(x) ... C_3(x). If we let\nC\nC 2\nC Z = C_0(x) - 0.5\nC\nC and\nC\nC W = 2*C_0(x)*C_1(x)\nC\nC then\nC\nC 2\nC C_0(16x) = 8*Z - 1\nC\nC\nC C_1(16x) = W*Z\nC\nC\nC 2\nC C_2(16x) = W / 8\nC\nC\nC 2\nC C_1(x) + Z*[C_2(x) + C_0(x)*C_3(x)]\nC C_3(16x) = ----------------------------------\nC 8\nC\nC\n IF ( X .LT. -1.D0 ) THEN\n \n Z = SQRT(-X)\n C0 = COSH(Z)\n C1 = SINH(Z)/Z\n C2 = (1-C0)/X\n C3 = (1-C1)/X\n RETURN\n \n END IF\n \n IF ( X .GT. 1.D0 ) THEN\n \n Z = SQRT(X)\n C0 = COS(Z)\n C1 = SIN(Z)/Z\n C2 = (1-C0)/X\n C3 = (1-C1)/X\n RETURN\n \n END IF\n \nC\nC If the magnitude of X is less than or equal to 1, we compute\nC the function values directly from their power series\nC representations.\nC\nC\nC Compute C_3 of x :\nC\nC 2 7 8\nC . 1 x x x x\nC C_3(x) = --- - --- + --- + ... - --- + ---\nC 3! 5! 7! 17! 19!\nC\nC\nC 1 x x x x\nC = ---( 1 - --- ( 1 - --- (...( 1- ----- ( 1 - ----- )...)\nC 2*3 4*5 6*7 16*17 18*19\nC\nC ^ ^ ^ ^ ^\nC | | | | |\nC | | | | |\nC PAIR(2) PAIR(4) PAIR(6) ... PAIR(16) PAIR(18)\nC\nC Assuming that we don't need to go beyond the term with 1/19!,\nC LPAIR3 will be 18.\nC\n \n C3 = 1.0D0\n \n DO I = LPAIR3, 4, -2\n C3 = 1.0D0 - X*PAIRS(I)*C3\n END DO\n \n C3 = PAIRS(2)*C3\n \n \nC\nC Compute C_2 of x :\nC\nC Here's how we do it.\nC 2 7 8\nC . 1 x x x x\nC C_2(x) = --- - --- + --- + ... + --- - ---\nC 2! 4! 6! 16! 18!\nC\nC\nC 1 x x x x\nC = ---( 1 - --- ( 1 - --- (...( 1- ----- ( 1 - ----- )...)\nC 1*2 3*4 5*6 15*16 17*18\nC\nC ^ ^ ^ ^ ^\nC | | | | |\nC | | | | |\nC PAIR(1) PAIR(3) PAIR(5) ... PAIR(15) PAIR(17)\nC\nC Assuming that we don't need to go beyond the term with 1/18!,\nC LPAIR2 will be 17.\nC\n C2 = 1.0D0\n \n DO I = LPAIR2, 3, -2\n C2 = 1.0D0 - X*PAIRS(I)*C2\n END DO\n \n C2 = PAIRS(1)*C2\n \nC\nC Get C1 and C0 via the recursion formula:\nC\nC 1\nC x*C_k+2(y) = --- - C_k(x)\nC k!\nC\n C1 = 1.0D0 - X*C3\n C0 = 1.0D0 - X*C2\n \n RETURN\n END\n \n \n \nC\nC Appendix\nC ========\nC\nC The formulas below show how to relate Stumpff function values\nC at arbitrary points in the functions' domain to values at points\nC in the interval [-1, 1]. These formulas might be used to improve\nC accuracy of the computed function values. The original algorithm\nC of this routine attempted to do this, but was unsuccessful.\nC\nC\nC These functions have a number of simple relationships that make\nC their computations practical. Among these are:\nC\nC 1\nC x*C_k+2(x) = --- - C_k(x)\nC k!\nC\nC\nC\nC 2\nC C_0(4x) = 2*[ C_0(x) ] - 1\nC\nC\nC\nC\nC C_1(4x) = C_1(x)*C_0(x)\nC\nC\nC\nC 2\nC C_2(4x) = [C_1(x)] / 2\nC\nC\nC\nC\nC C_3(4x) = [ C_2(x) + C_0(x)*C_3(x) ] / 4\nC\nC These can be used to derive formulae for C_0(16x) ... C_3(16x)\nC that involve only C_0(x) ... C_3(x). If we let\nC\nC 2\nC Z = C_0(x) - 0.5\nC\nC and\nC\nC W = 2*C_0(x)*C_1(x)\nC\nC then\nC\nC 2\nC C_0(16x) = 8*Z - 1\nC\nC\nC C_1(16x) = W*Z\nC\nC\nC 2\nC C_2(16x) = W / 8\nC\nC\nC 2\nC C_1(x) + Z*[C_2(x) + C_0(x)*C_3(x)]\nC C_3(16x) = ----------------------------------\nC 8\nC\nC [End]\nC\n", "meta": {"hexsha": "433b2c66e04b5af6a77688ad32fecf2104d1b5f3", "size": 24212, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/stmp03.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/stmp03.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/stmp03.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.4178403756, "max_line_length": 72, "alphanum_fraction": 0.4945481579, "num_tokens": 7919, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122313857378, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6715692520361348}} {"text": "! examples/Fortran/Lanczos.f90\n\nmodule lanczos_module\n use ral_nlls_double, only : params_base_type\n implicit none\n\n integer, parameter :: wp = kind(0d0)\n\n type, extends(params_base_type) :: params_type\n real(wp), dimension(:), allocatable :: t ! The m data points t_i\n real(wp), dimension(:), allocatable :: y ! The m data points y_i\n end type params_type\n\ncontains\n\n subroutine eval_r(status, n, m, x, r, params)\n ! r_i = y_i - x_1 e^(-x_2 t_i) - x_3 e^(-x_4 t_i) - x_5 e^(-x_6 t_i)\n integer, intent(out) :: status\n integer, intent(in) :: n\n integer, intent(in) :: m\n real(wp), dimension(*), intent(in) :: x\n real(wp), dimension(*), intent(out) :: r\n class(params_base_type), intent(inout) :: params\n \n\n select type(params)\n type is(params_type)\n r(1:m) = params%y(:) &\n - x(1)*exp(-x(2)*params%t(:)) &\n - x(3)*exp(-x(4)*params%t(:)) &\n - x(5)*exp(-x(n)*params%t(:))\n end select\n\n status = 0 ! success\n \n end subroutine eval_r\n\n subroutine eval_J(status, n, m, x, J, params)\n integer, intent(out) :: status\n integer, intent(in) :: n\n integer, intent(in) :: m\n real(wp), dimension(*), intent(in) :: x\n real(wp), dimension(*), intent(out) :: J\n class(params_base_type), intent(inout) :: params\n\n select type(params)\n type is(params_type)\n J( 1: m) = -exp(-x(2)*params%t(1:m)) ! J_i1\n J( m+1:2*m) = params%t(1:m) * x(1) * exp(-x(2)*params%t(1:m))! J_i2\n J(2*m+1:3*m) = -exp(-x(4)*params%t(1:m)) ! J_i3\n J(3*m+1:4*m) = +params%t(1:m) * x(3) * exp(-x(4)*params%t(1:m))! J_i4\n J(4*m+1:5*m) = -exp(-x(6)*params%t(1:m)) ! J_i5\n J(5*m+1:6*m) = +params%t(1:m) * x(5) * exp(-x(n)*params%t(1:m))! J_i6\n end select\n\n\n status = 0 ! Success\n end subroutine eval_J\n\n subroutine eval_HF(status, n, m, x, r, HF, params)\n integer, intent(out) :: status\n integer, intent(in) :: n\n integer, intent(in) :: m\n real(wp), dimension(*), intent(in) :: x\n real(wp), dimension(*), intent(in) :: r\n real(wp), dimension(*), intent(out) :: HF\n class(params_base_type), intent(inout) :: params\n\n HF(1:n*n) = 0.0\n select type(params)\n type is(params_type)\n HF( 2) = sum( r(1:m) * params%t(1:m) * exp(-x(2)*params%t(1:m))) ! H_21\n HF(1*n+1) = HF(2) ! H_12\n HF(1*n+2) = sum(-r(1:m) * (params%t(1:m)**2) * x(1) * exp(-x(2)*params%t(1:m)))! H_22\n HF(2*n+4) = sum( r(1:m) * params%t(1:m) * exp(-x(4)*params%t(1:m))) ! H_43\n HF(3*n+3) = HF(2*n+4) ! H_34\n HF(3*n+4) = sum(-r(1:m) * (params%t(1:m)**2) * x(3) * exp(-x(4)*params%t(1:m)))! H_44\n HF(4*n+6) = sum( r(1:m) * params%t(1:m) * exp(-x(6)*params%t(1:m))) ! H_65\n HF(5*n+5) = HF(4*n + 6) ! H_56\n HF(5*n+6) = sum(-r(1:m) * (params%t(1:m)**2) * x(5) * exp(-x(6)*params%t(1:m)))! H_66\n end select\n\n status = 0 ! Success\n end subroutine eval_HF\n\n subroutine eval_HP(status, n, m, x, y, HP, params)\n integer, intent(out) :: status\n integer, intent(in) :: n\n integer, intent(in) :: m\n real(wp), dimension(*), intent(in) :: x\n real(wp), dimension(*), intent(in) :: y\n real(wp), dimension(*), intent(out) :: HP\n class(params_base_type), intent(inout) :: params\n\n integer :: i\n status = 0\n HP(1:n*m) = 0.0\n select type(params)\n type is (params_type)\n do i = 1, m\n HP((i-1)*n + 1) = params%t(i) * exp(-x(2)*params%t(i)) * y(2)\n HP((i-1)*n + 2) = params%t(i) * exp(-x(2)*params%t(i)) * y(1) - &\n (params%t(i)**2) * x(1) * exp(-x(2)*params%t(i)) * y(2)\n HP((i-1)*n + 3) = params%t(i) * exp(-x(4)*params%t(i)) * y(4)\n HP((i-1)*n + 4) = params%t(i) * exp(-x(4)*params%t(i)) * y(3) - &\n (params%t(i)**2) * x(3) * exp(-x(4)*params%t(i)) * y(4)\n HP((i-1)*n + 5) = params%t(i) * exp(-x(6)*params%t(i)) * y(6)\n HP((i-1)*n + 6) = params%t(i) * exp(-x(6)*params%t(i)) * y(5) - &\n (params%t(i)**2) * x(5) * exp(-x(6)*params%t(i)) * y(6)\n end do\n end select\n \n \n end subroutine eval_HP\n \n \nend module lanczos_module\n\n\nprogram lanczos\n\n use ral_nlls_double\n use lanczos_module\n \n implicit none\n\n type(nlls_options) :: options\n type(nlls_inform) :: inform\n\n integer :: m,n\n real(wp), allocatable :: x(:)\n type(params_type) :: params\n real(wp) :: tic, toc\n \n ! data to be fitted\n m = 24\n allocate(params%t(m), params%y(m))\n ! Data from Lanczos 3\n params%t(:) = (/ 0.00000E+00, &\n 5.00000E-02, &\n 1.00000E-01, &\n 1.50000E-01, &\n 2.00000E-01, &\n 2.50000E-01, &\n 3.00000E-01, &\n 3.50000E-01, &\n 4.00000E-01, &\n 4.50000E-01, &\n 5.00000E-01, &\n 5.50000E-01, &\n 6.00000E-01, &\n 6.50000E-01, &\n 7.00000E-01, &\n 7.50000E-01, &\n 8.00000E-01, &\n 8.50000E-01, &\n 9.00000E-01, &\n 9.50000E-01, &\n 1.00000E+00, &\n 1.05000E+00, &\n 1.10000E+00, &\n 1.15000E+00 /)\n params%y(:) = (/ 2.5134E+00, &\n 2.0443E+00, &\n 1.6684E+00, &\n 1.3664E+00, &\n 1.1232E+00, &\n 0.9269E+00, &\n 0.7679E+00, &\n 0.6389E+00, &\n 0.5338E+00, &\n 0.4479E+00, &\n 0.3776E+00, &\n 0.3197E+00, &\n 0.2720E+00, &\n 0.2325E+00, &\n 0.1997E+00, &\n 0.1723E+00, &\n 0.1493E+00, &\n 0.1301E+00, &\n 0.1138E+00, &\n 0.1000E+00, &\n 0.0883E+00, &\n 0.0783E+00, &\n 0.0698E+00, &\n 0.0624E+00 /)\n\n ! call fitting routine\n n = 6\n allocate(x(n))\n x = (/ 1.2, 0.3, 5.6, 5.5, 6.5, 7.6 /) ! SP 1\n\n options%print_level = 4\n options%exact_second_derivatives = .true.\n options%model = 4\n options%nlls_method = 3\n options%use_ews_subproblem = .true.\n options%type_of_method = 2\n options%regularization_term = 1.0e-2\n options%regularization_power = 2.0\n options%reg_order = -1.0\n options%inner_method = 2\n options%maxit = 1000\n\n call cpu_time(tic)\n call nlls_solve(n,m,x,eval_r, eval_J, eval_HF, params, options, inform, eval_HP=eval_HP)\n if(inform%status.ne.0) then\n print *, \"ral_nlls() returned with error flag \", inform%status\n stop\n endif\n call cpu_time(toc)\n \n ! Print result\n print *, \"Found a local optimum at x = \", x\n print *, \"Took \", inform%iter, \" iterations\"\n print *, \" \", inform%f_eval, \" function evaluations\"\n print *, \" \", inform%g_eval, \" gradient evaluations\"\n print *, \" \", inform%h_eval, \" hessian evaluations\"\n print *, \" \", toc-tic, \" seconds\"\nend program lanczos\n", "meta": {"hexsha": "457ef6f4c5467a83e0b90c262a87498b49b7871e", "size": 7444, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "libRALFit/example/Fortran/Lanczos.f90", "max_stars_repo_name": "andpic/RALFit", "max_stars_repo_head_hexsha": "d8bd77217b5163f79069eaf7c5238a854f4843e3", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2018-04-02T12:24:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-14T00:11:45.000Z", "max_issues_repo_path": "libRALFit/example/Fortran/Lanczos.f90", "max_issues_repo_name": "andpic/RALFit", "max_issues_repo_head_hexsha": "d8bd77217b5163f79069eaf7c5238a854f4843e3", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 95, "max_issues_repo_issues_event_min_datetime": "2016-09-13T15:16:54.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-23T14:08:27.000Z", "max_forks_repo_path": "libRALFit/example/Fortran/Lanczos.f90", "max_forks_repo_name": "andpic/RALFit", "max_forks_repo_head_hexsha": "d8bd77217b5163f79069eaf7c5238a854f4843e3", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2018-04-02T12:24:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-23T17:12:42.000Z", "avg_line_length": 33.6832579186, "max_line_length": 94, "alphanum_fraction": 0.4677592692, "num_tokens": 2633, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122138417878, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.6715692442507871}} {"text": "!============================================================\n! \n! $Date$\n! $Author$\n! $Revision$\n! $Id$\n!============================================================\n\n!============================================================\n! a module to be used with spectral surface-based models.\n!============================================================\n\n!============================================================\nMODULE spectral_mod\n\n implicit none\n\n real, parameter :: pi = 4.0*atan(1.0) ! pi = 3.14159265358979323846264338327950288419 \n\n integer, parameter :: model = 1 ! 0:2D; 1:2sQG; 2:sQG-trop; 3:sQG-sfc; 4:HsQG\n real, parameter :: dt = 0.01 ! model time step\n\n integer, parameter :: ntims = 1001 ! number of model time steps\n integer, parameter :: iplot = 100 ! plots every iplot time steps\n integer, parameter :: imean = int(10.e3/dt) ! compute area mean every imean\n\n logical, parameter :: linear = .FALSE. ! flag for linear advection (.TRUE./.FALSE.)\n logical, parameter :: trop = .FALSE. ! flag for tropopause geometry (.TRUE./.FALSE.)\n logical, parameter :: grow = .FALSE. ! grow a normal mode (.TRUE./.FALSE.)\n logical, parameter :: inorm = .FALSE. ! flag for computing norm (.TRUE./.FALSE.)\n logical, parameter :: ibase = .TRUE. ! flag to add base state to output file (.TRUE./.FALSE.)\n\n logical, parameter :: iterr = .FALSE. ! flag for terrain\n real, parameter :: hamp = 0.6 ! height of terrain (0.6)\n real, parameter :: asx = 0.6 ! gaussian terrian major axis (1.0)\n real, parameter :: asy = 0.6 ! gaussian terrian minor axis (1.0)\n real, parameter :: asig = 1.0 ! eccentricity of gaussian terrain (1.0)\n\n integer, parameter :: kmax = 128/2 ! number of x waves\n integer, parameter :: lmax = 64/2 ! number of y waves\n\n logical, parameter :: hw = .TRUE. ! Hoskins-West jet on/off (.TRUE./.FALSE.)\n real, parameter :: hwp = 5.539118 ! Hoskins-West jet width parameter\n real, parameter :: amu = 1.0 ! Hoskins-West jet concentration parameter (0->1)\n real, parameter :: shear = 1.0 ! shear parameter (1 for HW jet)\n real, parameter :: trl = 15.0 ! jet relaxation parameter [e-folding time] (20.0, 40.0, 1000.0)\n\n real, parameter :: Ross = 0.0 ! Rossby number (0.0, 0.1)\n real, parameter :: gamma = 0.0 ! Ekman parameter (0.0, 0.075, 0.075*1.5)\n\n integer, parameter :: n = 8 ! diffusion parameter\n real, parameter :: tau = 20.0*dt ! diffusion time scale \n\n real, parameter :: XL = 20.0 ! x domain length (2*pi, 20.0, 40.0)\n real, parameter :: YL = 2*hwp ! y domain length (2*pi, 2*5.539118)\n real, parameter :: H = 1.0 ! z domain length (0.01, 0.1, 1.0, 10.0)\n\n real, parameter :: ZH = H ! z domain length ( needed for pinv )\n integer, parameter :: pmax = 11 ! number of vertical levels\n integer, parameter :: order = 2 ! 0:leading order only; 1-first order only; 2-full version\n logical, parameter :: tanhgrid = .FALSE. ! tanh grid in vertical (.TRUE./.FALSE.)\n\n integer, parameter :: verbose = 2 ! 0:no mesgs; 1:imp only; 2:all\n\n !================================\n ! do not modify below this point:\n !================================\n\n integer, parameter :: kmid=kmax/2, lmid=lmax/2, &\n mmax=3.125*kmax, nmax=3.125*lmax, &\n k2=mmax-kmax, l2=nmax-lmax, &\n kmaxp1=kmax+1, lmaxp1=lmax+1\n real, parameter :: facx=2.0*pi/XL, facy=2.0*pi/YL\n real, parameter :: ryl=2.0*pi/hwp\n\n type model_static\n ! diffusion\n real :: dco\n ! derivative operators\n complex, dimension(2*kmax,2*lmax) :: dx,dy,dz,dzo,iz,izo,Id\n ! basic state\n complex, dimension(2*kmax,2*lmax) :: thbB,thbT\n real, dimension(mmax,nmax) :: thbyB,thbyT\n real, dimension(mmax,nmax) :: ulinB,ulinT\n real :: lam\n ! terrain\n real, dimension(mmax,nmax) :: hx,hy,hu,hv\n ! advection flags\n logical :: bot,top\n end type model_static\n\nEND MODULE spectral_mod\n!============================================================\n", "meta": {"hexsha": "c36db911111cb449ce92f3f2a80fac8e80dd1f93", "size": 4647, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "model/spectral_mod.f90", "max_stars_repo_name": "aerorahul/sqgmodel", "max_stars_repo_head_hexsha": "348529474cf656688e11d3df50f0162c6215e38d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-12-18T10:55:28.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-18T10:55:28.000Z", "max_issues_repo_path": "model/spectral_mod.f90", "max_issues_repo_name": "aerorahul/sqgmodel", "max_issues_repo_head_hexsha": "348529474cf656688e11d3df50f0162c6215e38d", "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": "model/spectral_mod.f90", "max_forks_repo_name": "aerorahul/sqgmodel", "max_forks_repo_head_hexsha": "348529474cf656688e11d3df50f0162c6215e38d", "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": 49.4361702128, "max_line_length": 112, "alphanum_fraction": 0.4923606628, "num_tokens": 1293, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802395624257, "lm_q2_score": 0.7310585903489891, "lm_q1q2_score": 0.6714628691979088}} {"text": "c program DRSHTCC\nc>> 1994-10-19 DRSHTCC Krogh Changes to use M77CON\nc>> 1987-12-09 DRSHTCC Lawson Initial Code.\nc Demo driver for SHTCC, Householder transformations.\nc--S replaces \"?\": DR?HTCC, ?HTCC, ?MATP\n integer IDIM, JDIM, J, M, N\n parameter(IDIM = 3, JDIM = 5, M = 3, N = 2)\n real D(IDIM,JDIM), UPARAM, ZERO\n parameter(ZERO = 0.0E0)\n data (D(1,J),J=1,5) / 0.870E0, 0.796E0, 1.0E0, 0.0E0, 0.0E0 /\n data (D(2,J),J=1,5) / 0.571E0, -0.804E0, 0.0E0, 1.0E0, 0.0E0 /\n data (D(3,J),J=1,5) / -0.960E0, 0.346E0, 0.0E0, 0.0E0, 1.0E0 /\nc ------------------------------------------------------------------\n print*,'DRSHTCC.. Demonstrate computation of a QR decomposition.'\n print*,'Given matrix A, compute orthogonal Q and triangular R'\n print*,'such that A = Q * R.'\n call SMATP(D,IDIM,M,N,'0 A =')\n do 20002 J=1,N\n call SHTCC(1,J,J+1,M,D(1,J),UPARAM,D(1,J+1),IDIM,M+N-J)\n20002 continue\n call SMATP(D(1,N+1),IDIM,M,M,'0 Q [Transposed] =')\n D(2,1) = ZERO\n D(3,1) = ZERO\n D(3,2) = ZERO\n call SMATP(D,IDIM,M,N,'0 R =')\n stop\n end\n", "meta": {"hexsha": "50ad2ce0ab1bbef85a99f71009f30dcef375cce1", "size": 1167, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drshtcc.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drshtcc.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drshtcc.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 41.6785714286, "max_line_length": 72, "alphanum_fraction": 0.5218508997, "num_tokens": 491, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802507195635, "lm_q2_score": 0.7310585727705127, "lm_q1q2_score": 0.6714628612089467}} {"text": " SUBROUTINE FIT(X,Y,NDATA,SIG,MWT,A,B,SIGA,SIGB,CHI2,Q)\n DIMENSION X(NDATA),Y(NDATA),SIG(NDATA)\n SX=0.\n SY=0.\n ST2=0.\n B=0.\n IF(MWT.NE.0) THEN\n SS=0.\n DO 11 I=1,NDATA\n WT=1./(SIG(I)**2)\n SS=SS+WT\n SX=SX+X(I)*WT\n SY=SY+Y(I)*WT\n11 CONTINUE\n ELSE\n DO 12 I=1,NDATA\n SX=SX+X(I)\n SY=SY+Y(I)\n12 CONTINUE\n SS=FLOAT(NDATA)\n ENDIF\n SXOSS=SX/SS\n IF(MWT.NE.0) THEN\n DO 13 I=1,NDATA\n T=(X(I)-SXOSS)/SIG(I)\n ST2=ST2+T*T\n B=B+T*Y(I)/SIG(I)\n13 CONTINUE\n ELSE\n DO 14 I=1,NDATA\n T=X(I)-SXOSS\n ST2=ST2+T*T\n B=B+T*Y(I)\n14 CONTINUE\n ENDIF\n B=B/ST2\n A=(SY-SX*B)/SS\n SIGA=SQRT((1.+SX*SX/(SS*ST2))/SS)\n SIGB=SQRT(1./ST2)\n CHI2=0.\n IF(MWT.EQ.0) THEN\n DO 15 I=1,NDATA\n CHI2=CHI2+(Y(I)-A-B*X(I))**2\n15 CONTINUE\n Q=1.\n SIGDAT=SQRT(CHI2/(NDATA-2))\n SIGA=SIGA*SIGDAT\n SIGB=SIGB*SIGDAT\n ELSE\n DO 16 I=1,NDATA\n CHI2=CHI2+((Y(I)-A-B*X(I))/SIG(I))**2\n16 CONTINUE\n Q=GAMMQ(0.5*(NDATA-2),0.5*CHI2)\n ENDIF\n RETURN\n END\n", "meta": {"hexsha": "4dad3de7997df7d24537f70ce59e12496c8fd8f1", "size": 1244, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "Math3/NumRec/source/fit.for", "max_stars_repo_name": "domijin/MM3", "max_stars_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Math3/NumRec/source/fit.for", "max_issues_repo_name": "domijin/MM3", "max_issues_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Math3/NumRec/source/fit.for", "max_forks_repo_name": "domijin/MM3", "max_forks_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.8245614035, "max_line_length": 60, "alphanum_fraction": 0.4421221865, "num_tokens": 524, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802350995702, "lm_q2_score": 0.7310585844894971, "lm_q1q2_score": 0.6714628605534724}} {"text": " SUBROUTINE ratint(xa,ya,n,x,y,dy)\r\n INTEGER n,NMAX\r\n REAL dy,x,y,xa(n),ya(n),TINY\r\n PARAMETER (NMAX=10,TINY=1.e-25)\r\n INTEGER i,m,ns\r\n REAL dd,h,hh,t,w,c(NMAX),d(NMAX)\r\n ns=1\r\n hh=abs(x-xa(1))\r\n do 11 i=1,n\r\n h=abs(x-xa(i))\r\n if (h.eq.0.)then\r\n y=ya(i)\r\n dy=0.0\r\n return\r\n else if (h.lt.hh) then\r\n ns=i\r\n hh=h\r\n endif\r\n c(i)=ya(i)\r\n d(i)=ya(i)+TINY\r\n11 continue\r\n y=ya(ns)\r\n ns=ns-1\r\n do 13 m=1,n-1\r\n do 12 i=1,n-m\r\n w=c(i+1)-d(i)\r\n h=xa(i+m)-x\r\n t=(xa(i)-x)*d(i)/h\r\n dd=t-c(i+1)\r\n if(dd.eq.0.)pause 'failure in ratint'\r\n dd=w/dd\r\n d(i)=c(i+1)*dd\r\n c(i)=t*dd\r\n12 continue\r\n if (2*ns.lt.n-m)then\r\n dy=c(ns+1)\r\n else\r\n dy=d(ns)\r\n ns=ns-1\r\n endif\r\n y=y+dy\r\n13 continue\r\n return\r\n END\r\n", "meta": {"hexsha": "647b1d6e6b52e5a763e4caafa96fe5dfaa35a22c", "size": 985, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/ratint.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/ratint.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/ratint.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": 21.8888888889, "max_line_length": 48, "alphanum_fraction": 0.3837563452, "num_tokens": 346, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802440252811, "lm_q2_score": 0.7310585727705126, "lm_q1q2_score": 0.6714628563150341}} {"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.1 (Composite Trapezoidal Rule).\nC Section 7.2, Composite Trapezoidal and Simpson's Rule, Page 365\nC\n SUBROUTINE TRAPRU(F,A,B,M,Trule)\n INTEGER K,M\n DOUBLE PRECISION A,B,H,Sum,Trule,X\n EXTERNAL F\n H=(B-A)/M\n Sum=0\n DO K=1,M-1\n X=A+H*K\n Sum=Sum+F(X)\n ENDDO\n Sum=H*(F(A)+F(B)+2*Sum)/2\n Trule=Sum\n RETURN\n END\n\n SUBROUTINE XTRAPRU(F,A,B,M,Trule)\nC This subroutine uses labeled DO loop(s).\n INTEGER K,M\n DOUBLE PRECISION A,B,H,Sum,Trule,X\n EXTERNAL F\n H=(B-A)/M\n Sum=0\n DO 10 K=1,M-1\n X=A+H*K\n Sum=Sum+F(X)\n10 CONTINUE\n Sum=H*(F(A)+F(B)+2*Sum)/2\n Trule=Sum\n RETURN\n END\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "8122daff934d67f63adddf07399cc88bf35830f7", "size": 1043, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Modules/ThirdParty/VNL/src/vxl/v3p/netlib/mathews/trapezod.f", "max_stars_repo_name": "floryst/ITK", "max_stars_repo_head_hexsha": "321e673bcbac15aae2fcad863fd0977b7fbdb3e9", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 945, "max_stars_repo_stars_event_min_datetime": "2015-01-09T00:43:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T08:23:02.000Z", "max_issues_repo_path": "Modules/ThirdParty/VNL/src/vxl/v3p/netlib/mathews/trapezod.f", "max_issues_repo_name": "floryst/ITK", "max_issues_repo_head_hexsha": "321e673bcbac15aae2fcad863fd0977b7fbdb3e9", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2354, "max_issues_repo_issues_event_min_datetime": "2015-02-04T21:54:21.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T20:58:21.000Z", "max_forks_repo_path": "Modules/ThirdParty/VNL/src/vxl/v3p/netlib/mathews/trapezod.f", "max_forks_repo_name": "floryst/ITK", "max_forks_repo_head_hexsha": "321e673bcbac15aae2fcad863fd0977b7fbdb3e9", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 566, "max_forks_repo_forks_event_min_datetime": "2015-01-04T14:26:57.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T20:33:18.000Z", "avg_line_length": 21.7291666667, "max_line_length": 78, "alphanum_fraction": 0.5829338447, "num_tokens": 358, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956580903722561, "lm_q2_score": 0.8438951084436077, "lm_q1q2_score": 0.6714519704587288}} {"text": "C This program is written for testing module TYPING\nC\nC\n PROGRAM TYPAGE_INTRINSIC\n LOGICAL L\n INTEGER I\n REAL*4 R\n REAL*8 D\n COMPLEX*8 C\n COMPLEX*16 E\n CHARACTER CH\n\nC Conversion intrinsics\nC =====================\n I = INT(R)\n I = INT(D)\n I = INT(C)\n I = INT(CH) ! ERROR\n I = INT(L) ! ERROR\n\n R = REAL(I)\n R = REAL(D)\n R = REAL(C)\n R = REAL(CH) ! ERROR\n R = REAL(L) ! ERROR\n\n D = DBLE(I)\n D = DBLE(R)\n D = DBLE(C)\n D = DBLE(CH) ! ERROR\n D = DBLE(L) ! ERROR\n\n C = CMPLX(I)\n C = CMPLX(R)\n C = CMPLX(D)\n C = CMPLX(CH) ! ERROR\n C = CMPLX(L) ! ERROR\n\nC Argument & Result: REAL or DOUBLE\nC ========================\n I = TAN(I) ! ERROR\n R = TAN(R)\n D = TAN(D)\n I = TAN(C) ! ERROR\n I = TAN(L) ! ERROR\n\nC Argument & Result: REAL, DOUBLE or COMPLEX\nC =================================\n I = EXP(I) ! ERROR\n R = EXP(R)\n D = EXP(D)\n C = EXP(C)\n I = EXP(L) ! ERROR\n\n I = LOG(I) ! ERROR\n R = LOG(R)\n D = LOG(D)\n C = LOG(C)\n I = LOG(L) ! ERROR\n\nC Argument & Result: INT, REAL or DOUBLE\nC =============================\n I = MIN(I, 15, I)\n R = MIN(I, 15, R)\n D = MIN(I, 15, D)\n C = MIN(I, 15, C) ! ERROR\n I = MIN(I, 15, L) ! ERROR\n\n I = MOD(I, I)\n R = MOD(R, R)\n D = MOD(D, D)\n I = MOD(R, D)\n C = MOD(C, C) ! ERROR\n\nC Intrinsic ABS: IRDC -> IRDR\nC ===========================\n I = ABS(I)\n R = ABS(R)\n D = ABS(D)\n R = ABS(C)\n C = ABS(C)\n I = ABS(L) ! ERROR\n\nC Type_argument --> Type_result\nC ===================================\nC INT -> INT\n I = IABS(I)\n I = IABS(R) ! ERROR\n I = IABS(D) ! ERROR\n I = IABS(C) ! ERROR\n \nC REAL -> REAL\n R = ALOG(I) ! ERROR\n R = ALOG(R)\n R = ALOG(D) ! ERROR\n R = ALOG(C) ! ERROR\n \nC DOUBLE -> DOUBLE\n D = DLOG(I) ! ERROR\n D = DLOG(R) ! ERROR\n D = DLOG(D)\n D = DLOG(C) ! ERROR\n \nC COMPLEX -> COMPLEX \n C = CLOG(I) ! ERROR\n C = CLOG(R) ! ERROR\n C = CLOG(D) ! ERROR\n C = CLOG(C)\n\nC CHAR -> INT\n I = ICHAR(CH)\n D = ICHAR(R) ! ERROR\n \n I = LEN(CH)\n I = LEN(R) ! ERROR\n \n I = INDEX(CH)\n I = INDEX(R) ! ERROR\n \nC INT -> CHAR\n CH = CHAR(I)\n CH = CHAR(D) ! ERROR\n\nC REAL -> INT\n I = MIN1(I, I) ! ERROR\n I = MIN1(R, R)\n I = MIN1(I, R) ! ERROR\n I = MIN1(I, R, D) ! ERROR\n I = MIN1(I, R, D, C) ! ERROR\n \nC COMPLEX -> REAL\n R = AIMAG(I) ! ERROR\n R = AIMAG(R) ! ERROR\n R = AIMAG(D) ! ERROR\n R = AIMAG(C)\n \nC REAL -> DOUBLE\n D = DPROD(I) ! ERROR\n D = DPROD(R)\n D = DPROD(D) ! ERROR\n D = DPROD(C) ! ERROR\n \nC INT -> REAL\n R = AMIN0(I, I)\n R = AMIN0(I, R) ! ERROR\n R = AMIN0(R, D) ! ERROR\n R = AMIN0(D, C) ! ERROR\n \nC CHAR -> LOGICAL\n L = LGE(I, CH) ! ERROR\n L = LGE(R, CH) ! ERROR\n L = LGE(CH, CH)\n \n END\n\n\n\n\n\n\n", "meta": {"hexsha": "e6cdcbb245defcbe98f53cf2ae1258de582bed12", "size": 3858, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "packages/PIPS/validation/Flint/typage_intrinsic.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/Flint/typage_intrinsic.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/Flint/typage_intrinsic.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": 23.9627329193, "max_line_length": 55, "alphanum_fraction": 0.3245204769, "num_tokens": 1136, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950947024555, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.6714519697480966}} {"text": " SUBROUTINE MB02GD( TYPET, TRIU, K, N, NL, P, S, T, LDT, RB, LDRB,\r\n $ DWORK, LDWORK, INFO )\r\nC\r\nC SLICOT RELEASE 5.5.\r\nC\r\nC Copyright (c) 2002-2012 NICONET e.V.\r\nC\r\nC PURPOSE\r\nC\r\nC To compute the Cholesky factor of a banded symmetric positive\r\nC definite (s.p.d.) block Toeplitz matrix, defined by either its\r\nC first block row, or its first block column, depending on the\r\nC routine parameter TYPET.\r\nC\r\nC By subsequent calls of this routine the Cholesky factor can be\r\nC computed block column by block column.\r\nC\r\nC ARGUMENTS\r\nC\r\nC Mode Parameters\r\nC\r\nC TYPET CHARACTER*1\r\nC Specifies the type of T, as follows:\r\nC = 'R': T contains the first block row of an s.p.d. block\r\nC Toeplitz matrix; the Cholesky factor is upper\r\nC triangular;\r\nC = 'C': T contains the first block column of an s.p.d.\r\nC block Toeplitz matrix; the Cholesky factor is\r\nC lower triangular. This choice results in a column\r\nC oriented algorithm which is usually faster.\r\nC Note: in the sequel, the notation x / y means that\r\nC x corresponds to TYPET = 'R' and y corresponds to\r\nC TYPET = 'C'.\r\nC\r\nC TRIU CHARACTER*1\r\nC Specifies the structure of the last block in T, as\r\nC follows:\r\nC = 'N': the last block has no special structure;\r\nC = 'T': the last block is lower / upper triangular.\r\nC\r\nC Input/Output Parameters\r\nC\r\nC K (input) INTEGER\r\nC The number of rows / columns in T, which should be equal\r\nC to the blocksize. K >= 0.\r\nC\r\nC N (input) INTEGER\r\nC The number of blocks in T. N >= 1.\r\nC If TRIU = 'N', N >= 1;\r\nC if TRIU = 'T', N >= 2.\r\nC\r\nC NL (input) INTEGER\r\nC The lower block bandwidth, i.e., NL + 1 is the number of\r\nC nonzero blocks in the first block column of the block\r\nC Toeplitz matrix.\r\nC If TRIU = 'N', 0 <= NL < N;\r\nC if TRIU = 'T', 1 <= NL < N.\r\nC\r\nC P (input) INTEGER\r\nC The number of previously computed block rows / columns of\r\nC the Cholesky factor. 0 <= P <= N.\r\nC\r\nC S (input) INTEGER\r\nC The number of block rows / columns of the Cholesky factor\r\nC to compute. 0 <= S <= N - P.\r\nC\r\nC T (input/output) DOUBLE PRECISION array, dimension\r\nC (LDT,(NL+1)*K) / (LDT,K)\r\nC On entry, if P = 0, the leading K-by-(NL+1)*K /\r\nC (NL+1)*K-by-K part of this array must contain the first\r\nC block row / column of an s.p.d. block Toeplitz matrix.\r\nC On entry, if P > 0, the leading K-by-(NL+1)*K /\r\nC (NL+1)*K-by-K part of this array must contain the P-th\r\nC block row / column of the Cholesky factor.\r\nC On exit, if INFO = 0, then the leading K-by-(NL+1)*K /\r\nC (NL+1)*K-by-K part of this array contains the (P+S)-th\r\nC block row / column of the Cholesky factor.\r\nC\r\nC LDT INTEGER\r\nC The leading dimension of the array T.\r\nC LDT >= MAX(1,K) / MAX(1,(NL+1)*K).\r\nC\r\nC RB (input/output) DOUBLE PRECISION array, dimension\r\nC (LDRB,MIN(P+NL+S,N)*K) / (LDRB,MIN(P+S,N)*K)\r\nC On entry, if TYPET = 'R' and TRIU = 'N' and P > 0,\r\nC the leading (NL+1)*K-by-MIN(NL,N-P)*K part of this array\r\nC must contain the (P*K+1)-st to ((P+NL)*K)-th columns\r\nC of the upper Cholesky factor in banded format from a\r\nC previous call of this routine.\r\nC On entry, if TYPET = 'R' and TRIU = 'T' and P > 0,\r\nC the leading (NL*K+1)-by-MIN(NL,N-P)*K part of this array\r\nC must contain the (P*K+1)-st to (MIN(P+NL,N)*K)-th columns\r\nC of the upper Cholesky factor in banded format from a\r\nC previous call of this routine.\r\nC On exit, if TYPET = 'R' and TRIU = 'N', the leading\r\nC (NL+1)*K-by-MIN(NL+S,N-P)*K part of this array contains\r\nC the (P*K+1)-st to (MIN(P+NL+S,N)*K)-th columns of the\r\nC upper Cholesky factor in banded format.\r\nC On exit, if TYPET = 'R' and TRIU = 'T', the leading\r\nC (NL*K+1)-by-MIN(NL+S,N-P)*K part of this array contains\r\nC the (P*K+1)-st to (MIN(P+NL+S,N)*K)-th columns of the\r\nC upper Cholesky factor in banded format.\r\nC On exit, if TYPET = 'C' and TRIU = 'N', the leading\r\nC (NL+1)*K-by-MIN(S,N-P)*K part of this array contains\r\nC the (P*K+1)-st to (MIN(P+S,N)*K)-th columns of the lower\r\nC Cholesky factor in banded format.\r\nC On exit, if TYPET = 'C' and TRIU = 'T', the leading\r\nC (NL*K+1)-by-MIN(S,N-P)*K part of this array contains\r\nC the (P*K+1)-st to (MIN(P+S,N)*K)-th columns of the lower\r\nC Cholesky factor in banded format.\r\nC For further details regarding the band storage scheme see\r\nC the documentation of the LAPACK routine DPBTF2.\r\nC\r\nC LDRB INTEGER\r\nC The leading dimension of the array RB.\r\nC If TRIU = 'N', LDRB >= MAX( (NL+1)*K,1 );\r\nC if TRIU = 'T', LDRB >= NL*K+1.\r\nC\r\nC Workspace\r\nC\r\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\r\nC On exit, if INFO = 0, DWORK(1) returns the optimal\r\nC value of LDWORK.\r\nC On exit, if INFO = -13, DWORK(1) returns the minimum\r\nC value of LDWORK.\r\nC The first 1 + ( NL + 1 )*K*K elements of DWORK should be\r\nC preserved during successive calls of the routine.\r\nC\r\nC LDWORK INTEGER\r\nC The length of the array DWORK.\r\nC LDWORK >= 1 + ( NL + 1 )*K*K + NL*K.\r\nC For optimum performance LDWORK should be larger.\r\nC\r\nC If LDWORK = -1, then a workspace query is assumed;\r\nC the routine only calculates the optimal size of the\r\nC DWORK array, returns this value as the first entry of\r\nC the DWORK array, and no error message related to LDWORK\r\nC is issued by XERBLA.\r\nC\r\nC Error Indicator\r\nC\r\nC INFO INTEGER\r\nC = 0: successful exit;\r\nC < 0: if INFO = -i, the i-th argument had an illegal\r\nC value;\r\nC = 1: the reduction algorithm failed. The Toeplitz matrix\r\nC associated with T is not (numerically) positive\r\nC definite.\r\nC\r\nC METHOD\r\nC\r\nC Householder transformations and modified hyperbolic rotations\r\nC are used in the Schur algorithm [1], [2].\r\nC\r\nC REFERENCES\r\nC\r\nC [1] Kailath, T. and Sayed, A.\r\nC Fast Reliable Algorithms for Matrices with Structure.\r\nC SIAM Publications, Philadelphia, 1999.\r\nC\r\nC [2] Kressner, D. and Van Dooren, P.\r\nC Factorizations and linear system solvers for matrices with\r\nC Toeplitz structure.\r\nC SLICOT Working Note 2000-2, 2000.\r\nC\r\nC NUMERICAL ASPECTS\r\nC\r\nC The implemented method is numerically stable.\r\nC 3\r\nC The algorithm requires O( K *N*NL ) floating point operations.\r\nC\r\nC CONTRIBUTOR\r\nC\r\nC D. Kressner, Technical Univ. Berlin, Germany, May 2001.\r\nC\r\nC REVISIONS\r\nC\r\nC V. Sima, Research Institute for Informatics, Bucharest, June 2001,\r\nC Mar. 2004, Apr. 2011.\r\nC\r\nC KEYWORDS\r\nC\r\nC Elementary matrix operations, Householder transformation, matrix\r\nC operations, Toeplitz matrix.\r\nC\r\nC ******************************************************************\r\nC\r\nC .. Parameters ..\r\n DOUBLE PRECISION ZERO, ONE\r\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )\r\nC .. Scalar Arguments ..\r\n CHARACTER TRIU, TYPET\r\n INTEGER INFO, K, LDRB, LDT, LDWORK, N, NL, P, S\r\nC .. Array Arguments ..\r\n DOUBLE PRECISION DWORK(LDWORK), RB(LDRB,*), T(LDT,*)\r\nC .. Local Scalars ..\r\n CHARACTER STRUCT\r\n LOGICAL ISROW, LQUERY, LTRI\r\n INTEGER HEAD, I, IERR, J, JJ, KK, LEN, LEN2, LENR, NB,\r\n $ NBMIN, PDW, POSR, PRE, RNK, SIZR, STPS, WRKMIN,\r\n $ WRKOPT\r\nC .. Local Arrays ..\r\n INTEGER IPVT(1)\r\n DOUBLE PRECISION DUM(1)\r\nC .. External Functions ..\r\n LOGICAL LSAME\r\n INTEGER ILAENV\r\n EXTERNAL ILAENV, LSAME\r\nC .. External Subroutines ..\r\n EXTERNAL DCOPY, DGELQF, DGEQRF, DLACPY, DLASET, DPOTRF,\r\n $ DTRSM, MB02CU, MB02CV, XERBLA\r\nC .. Intrinsic Functions ..\r\n INTRINSIC DBLE, INT, MAX, MIN, MOD\r\nC\r\nC .. Executable Statements ..\r\nC\r\nC Decode the scalar input parameters.\r\nC\r\n INFO = 0\r\n LTRI = LSAME( TRIU, 'T' )\r\n LENR = ( NL + 1 )*K\r\n IF ( LTRI ) THEN\r\n SIZR = NL*K + 1\r\n ELSE\r\n SIZR = LENR\r\n END IF\r\n ISROW = LSAME( TYPET, 'R' )\r\n WRKMIN = 1 + ( LENR + NL )*K\r\nC\r\nC Check the scalar input parameters.\r\nC\r\n IF ( .NOT.( ISROW .OR. LSAME( TYPET, 'C' ) ) ) THEN\r\n INFO = -1\r\n ELSE IF ( .NOT.( LTRI .OR. LSAME( TRIU, 'N' ) ) ) THEN\r\n INFO = -2\r\n ELSE IF ( K.LT.0 ) THEN\r\n INFO = -3\r\n ELSE IF ( ( LTRI .AND. N.LT.2 ) .OR.\r\n $ ( .NOT.LTRI .AND. N.LT.1 ) ) THEN\r\n INFO = -4\r\n ELSE IF ( NL.GE.N .OR. ( LTRI .AND. NL.LT.1 ) .OR.\r\n $ ( .NOT.LTRI .AND. NL.LT.0 ) ) THEN\r\n INFO = -5\r\n ELSE IF ( P.LT.0 .OR. P.GT.N ) THEN\r\n INFO = -6\r\n ELSE IF ( S.LT.0 .OR. S.GT.N-P ) THEN\r\n INFO = -7\r\n ELSE IF ( ( ISROW .AND. LDT.LT.MAX( 1, K ) ) .OR.\r\n $ ( .NOT.ISROW .AND. LDT.LT.MAX( 1, LENR ) ) )\r\n $ THEN\r\n INFO = -9\r\n ELSE IF ( ( LTRI .AND. LDRB.LT.SIZR ) .OR.\r\n $ ( .NOT.LTRI .AND. LDRB.LT.MAX( 1, LENR ) ) )\r\n $ THEN\r\n INFO = -11\r\n ELSE\r\n LQUERY = LDWORK.EQ.-1\r\n PDW = LENR*K + 1\r\n KK = PDW + 4*K\r\n IF ( ISROW ) THEN\r\n CALL DGEQRF( K, LENR, T, LDT, DWORK, DWORK, -1, INFO )\r\n ELSE\r\n CALL DGELQF( LENR, K, T, LDT, DWORK, DWORK, -1, INFO )\r\n END IF\r\n WRKOPT = KK + INT( DWORK(1) )\r\n IF ( LDWORK.LT.WRKMIN .AND. .NOT.LQUERY ) THEN\r\n DWORK(1) = DBLE( WRKMIN )\r\n INFO = -13\r\n END IF\r\n END IF\r\nC\r\nC Return if there were illegal values.\r\nC\r\n IF ( INFO.NE.0 ) THEN\r\n CALL XERBLA( 'MB02GD', -INFO )\r\n RETURN\r\n ELSE IF( LQUERY ) THEN\r\n DWORK(1) = WRKOPT\r\n RETURN\r\n END IF\r\nC\r\nC Quick return if possible.\r\nC\r\n IF ( S*K.EQ.0 ) THEN\r\n DWORK(1) = ONE\r\n RETURN\r\n END IF\r\nC\r\nC Compute the generator if P = 0.\r\nC\r\n IF ( P.EQ.0 ) THEN\r\n IF ( ISROW ) THEN\r\n CALL DPOTRF( 'Upper', K, T, LDT, IERR )\r\n IF ( IERR.NE.0 ) THEN\r\nC\r\nC Error return: The matrix is not positive definite.\r\nC\r\n INFO = 1\r\n RETURN\r\n END IF\r\n IF ( NL.GT.0 )\r\n $ CALL DTRSM( 'Left', 'Upper', 'Transpose', 'NonUnit', K,\r\n $ NL*K, ONE, T, LDT, T(1,K+1), LDT )\r\nC\r\nC Copy the first block row to RB.\r\nC\r\n IF ( LTRI ) THEN\r\nC\r\n DO 10 I = 1, LENR - K\r\n CALL DCOPY( MIN( I, K ), T(1,I), 1,\r\n $ RB( MAX( SIZR-I+1, 1 ),I ), 1 )\r\n 10 CONTINUE\r\nC\r\n DO 20 I = K, 1, -1\r\n CALL DCOPY( I, T(K-I+1,LENR-I+1), 1,\r\n $ RB( 1,LENR-I+1 ), 1 )\r\n 20 CONTINUE\r\nC\r\n ELSE\r\nC\r\n DO 30 I = 1, LENR\r\n CALL DCOPY( MIN( I, K ), T(1,I), 1,\r\n $ RB( MAX( SIZR-I+1, 1 ),I ), 1 )\r\n 30 CONTINUE\r\nC\r\n END IF\r\nC\r\nC Quick return if N = 1.\r\nC\r\n IF ( N.EQ.1 ) THEN\r\n DWORK(1) = ONE\r\n RETURN\r\n END IF\r\nC\r\n CALL DLACPY( 'All', K, NL*K, T(1,K+1), LDT, DWORK(2), K )\r\n CALL DLASET( 'All', K, K, ZERO, ZERO, DWORK(NL*K*K+2), K )\r\n POSR = K + 1\r\n ELSE\r\n CALL DPOTRF( 'Lower', K, T, LDT, IERR )\r\n IF ( IERR.NE.0 ) THEN\r\nC\r\nC Error return: The matrix is not positive definite.\r\nC\r\n INFO = 1\r\n RETURN\r\n END IF\r\n IF ( NL.GT.0 )\r\n $ CALL DTRSM( 'Right', 'Lower', 'Transpose', 'NonUnit',\r\n $ NL*K, K, ONE, T, LDT, T(K+1,1), LDT )\r\nC\r\nC Copy the first block column to RB.\r\nC\r\n POSR = 1\r\n IF ( LTRI ) THEN\r\nC\r\n DO 40 I = 1, K\r\n CALL DCOPY( SIZR, T(I,I), 1, RB(1,POSR), 1 )\r\n POSR = POSR + 1\r\n 40 CONTINUE\r\nC\r\n ELSE\r\nC\r\n DO 50 I = 1, K\r\n CALL DCOPY( LENR-I+1, T(I,I), 1, RB(1,POSR), 1 )\r\n IF ( LENR.LT.N*K .AND. I.GT.1 ) THEN\r\n CALL DLASET( 'All', I-1, 1, ZERO, ZERO,\r\n $ RB(LENR-I+2,POSR), LDRB )\r\n END IF\r\n POSR = POSR + 1\r\n 50 CONTINUE\r\nC\r\n END IF\r\nC\r\nC Quick return if N = 1.\r\nC\r\n IF ( N.EQ.1 ) THEN\r\n DWORK(1) = ONE\r\n RETURN\r\n END IF\r\nC\r\n CALL DLACPY( 'All', NL*K, K, T(K+1,1), LDT, DWORK(2), LENR )\r\n CALL DLASET( 'All', K, K, ZERO, ZERO, DWORK(NL*K+2), LENR )\r\n END IF\r\n PRE = 1\r\n STPS = S - 1\r\n ELSE\r\n PRE = P\r\n STPS = S\r\n POSR = 1\r\n END IF\r\nC\r\n HEAD = MOD( ( PRE - 1 )*K, LENR )\r\nC\r\nC Determine block size for the involved block Householder\r\nC transformations.\r\nC\r\n NB = MIN( INT( ( LDWORK - KK )/LENR ), K )\r\n IF ( ISROW ) THEN\r\n NBMIN = MAX( 2, ILAENV( 2, 'DGEQRF', ' ', K, LENR, -1, -1 ) )\r\n ELSE\r\n NBMIN = MAX( 2, ILAENV( 2, 'DGELQF', ' ', LENR, K, -1, -1 ) )\r\n END IF\r\n IF ( NB.LT.NBMIN ) NB = 0\r\nC\r\nC Generator reduction process.\r\nC\r\n IF ( ISROW ) THEN\r\nC\r\n DO 90 I = PRE, PRE + STPS - 1\r\n CALL MB02CU( 'Row', K, K, K, NB, T, LDT, DUM, 1,\r\n $ DWORK(HEAD*K+2), K, RNK, IPVT, DWORK(PDW+1),\r\n $ ZERO, DWORK(PDW+4*K+1), LDWORK-PDW-4*K, IERR )\r\nC\r\n IF ( IERR.NE.0 ) THEN\r\nC\r\nC Error return: The positive definiteness is (numerically)\r\nC not satisfied.\r\nC\r\n INFO = 1\r\n RETURN\r\n END IF\r\nC\r\n LEN = MAX( MIN( ( N - I )*K - K, LENR - HEAD - K ), 0 )\r\n LEN2 = MAX( MIN( ( N - I )*K - LEN - K, HEAD ), 0 )\r\n IF ( LEN.EQ.( LENR-K ) ) THEN\r\n STRUCT = TRIU\r\n ELSE\r\n STRUCT = 'N'\r\n END IF\r\n CALL MB02CV( 'Row', STRUCT, K, LEN, K, K, NB, -1, DUM, 1,\r\n $ DUM, 1, DWORK(HEAD*K+2), K, T(1,K+1), LDT,\r\n $ DUM, 1, DWORK((HEAD+K)*K+2), K, DWORK(PDW+1),\r\n $ DWORK(PDW+4*K+1), LDWORK-PDW-4*K, IERR )\r\nC\r\n IF ( ( N - I )*K.GE.LENR ) THEN\r\n STRUCT = TRIU\r\n ELSE\r\n STRUCT = 'N'\r\n END IF\r\n CALL MB02CV( 'Row', STRUCT, K, LEN2, K, K, NB, -1, DUM, 1,\r\n $ DUM, 1, DWORK(HEAD*K+2), K, T(1,K+LEN+1), LDT,\r\n $ DUM, 1, DWORK(2), K, DWORK(PDW+1),\r\n $ DWORK(PDW+4*K+1), LDWORK-PDW-4*K, IERR )\r\nC\r\n CALL DLASET( 'All', K, K, ZERO, ZERO, DWORK(HEAD*K+2), K )\r\nC\r\nC Copy current block row to RB.\r\nC\r\n IF ( LTRI ) THEN\r\nC\r\n DO 60 J = 1, MIN( LEN + LEN2 + K, LENR - K )\r\n CALL DCOPY( MIN( J, K ), T(1,J), 1,\r\n $ RB(MAX( SIZR-J+1, 1 ),POSR+J-1 ), 1 )\r\n 60 CONTINUE\r\nC\r\n IF ( LEN+LEN2+K.GE.LENR ) THEN\r\nC\r\n DO 70 JJ = K, 1, -1\r\n CALL DCOPY( JJ, T(K-JJ+1,LENR-JJ+1), 1,\r\n $ RB(1,POSR+LENR-JJ), 1 )\r\n 70 CONTINUE\r\nC\r\n END IF\r\n POSR = POSR + K\r\nC\r\n ELSE\r\nC\r\n DO 80 J = 1, LEN + LEN2 + K\r\n CALL DCOPY( MIN( J, K ), T(1,J), 1,\r\n $ RB(MAX( SIZR-J+1, 1 ),POSR+J-1), 1 )\r\n IF ( J.GT.LENR-K ) THEN\r\n CALL DLASET( 'All', SIZR-J, 1, ZERO, ZERO,\r\n $ RB(1,POSR+J-1), 1 )\r\n END IF\r\n 80 CONTINUE\r\nC\r\n POSR = POSR + K\r\n END IF\r\n HEAD = MOD( HEAD + K, LENR )\r\n 90 CONTINUE\r\nC\r\n ELSE\r\nC\r\n DO 120 I = PRE, PRE + STPS - 1\r\nC\r\n CALL MB02CU( 'Column', K, K, K, NB, T, LDT, DUM, 1,\r\n $ DWORK(HEAD+2), LENR, RNK, IPVT, DWORK(PDW+1),\r\n $ ZERO, DWORK(PDW+4*K+1), LDWORK-PDW-4*K, IERR )\r\nC\r\n IF ( IERR.NE.0 ) THEN\r\nC\r\nC Error return: The positive definiteness is (numerically)\r\nC not satisfied.\r\nC\r\n INFO = 1\r\n RETURN\r\n END IF\r\nC\r\n LEN = MAX( MIN( ( N - I )*K - K, LENR - HEAD - K ), 0 )\r\n LEN2 = MAX( MIN( ( N - I )*K - LEN - K, HEAD ), 0 )\r\n IF ( LEN.EQ.( LENR-K ) ) THEN\r\n STRUCT = TRIU\r\n ELSE\r\n STRUCT = 'N'\r\n END IF\r\n CALL MB02CV( 'Column', STRUCT, K, LEN, K, K, NB, -1, DUM,\r\n $ 1, DUM, 1, DWORK(HEAD+2), LENR, T(K+1,1), LDT,\r\n $ DUM, 1, DWORK(HEAD+K+2), LENR, DWORK(PDW+1),\r\n $ DWORK(PDW+4*K+1), LDWORK-PDW-4*K, IERR )\r\nC\r\n IF ( ( N - I )*K.GE.LENR ) THEN\r\n STRUCT = TRIU\r\n ELSE\r\n STRUCT = 'N'\r\n END IF\r\n CALL MB02CV( 'Column', STRUCT, K, LEN2, K, K, NB, -1, DUM,\r\n $ 1, DUM, 1, DWORK(HEAD+2), LENR, T(K+LEN+1,1),\r\n $ LDT, DUM, 1, DWORK(2), LENR, DWORK(PDW+1),\r\n $ DWORK(PDW+4*K+1), LDWORK-PDW-4*K, IERR )\r\nC\r\n CALL DLASET( 'All', K, K, ZERO, ZERO, DWORK(HEAD+2), LENR )\r\nC\r\nC Copy current block column to RB.\r\nC\r\n IF ( LTRI ) THEN\r\nC\r\n DO 100 J = 1, K\r\n CALL DCOPY( MIN( SIZR, (N-I)*K-J+1 ), T(J,J), 1,\r\n $ RB(1,POSR), 1 )\r\n POSR = POSR + 1\r\n 100 CONTINUE\r\nC\r\n ELSE\r\nC\r\n DO 110 J = 1, K\r\n CALL DCOPY( MIN( SIZR-J+1, (N-I)*K-J+1 ), T(J,J), 1,\r\n $ RB(1,POSR), 1 )\r\n IF ( LENR.LT.(N-I)*K ) THEN\r\n CALL DLASET( 'All', J-1, 1, ZERO, ZERO,\r\n $ RB(MIN( SIZR-J+1, (N-I)*K-J+1 ) + 1,\r\n $ POSR), LDRB )\r\n END IF\r\n POSR = POSR + 1\r\n 110 CONTINUE\r\nC\r\n END IF\r\n HEAD = MOD( HEAD + K, LENR )\r\n 120 CONTINUE\r\nC\r\n END IF\r\n DWORK(1) = DBLE( WRKOPT )\r\n RETURN\r\nC\r\nC *** Last line of MB02GD ***\r\n END\r\n", "meta": {"hexsha": "1958f02df820fafd3d0cebbf34e9047b92672997", "size": 19842, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "External/SLICOT/MB02GD.f", "max_stars_repo_name": "bgin/MissileSimulation", "max_stars_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2016-08-28T23:20:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-15T14:43:58.000Z", "max_issues_repo_path": "External/SLICOT/MB02GD.f", "max_issues_repo_name": "bgin/MissileSimulation", "max_issues_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-06-02T21:29:51.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-05T05:59:31.000Z", "max_forks_repo_path": "External/SLICOT/MB02GD.f", "max_forks_repo_name": "bgin/MissileSimulation", "max_forks_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-07-04T22:38:22.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-04T22:38:22.000Z", "avg_line_length": 35.6870503597, "max_line_length": 73, "alphanum_fraction": 0.4496522528, "num_tokens": 6224, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037343628703, "lm_q2_score": 0.724870282120402, "lm_q1q2_score": 0.6714500492567957}} {"text": "subroutine gen_kp(m1,m2,m3,n1,n2,n3,bz,GS,G,l)\n\nimplicit none\n\ninteger, intent(in):: n1,n2,n3\nInteger, intent(in):: m1,m2,m3,bz\ndouble precision, intent(in):: GS(3,3)\ninteger, intent(in):: l\ndouble precision, intent(in):: G(l,3)\n\ndouble precision :: kp(3)\ndouble precision :: kr, kt\n\ninteger :: i,j,k,count,s\nlogical :: keep\n\nopen(1, file=\"BZ_ZONE.dat\", status=\"new\", action=\"write\")\n\n\n!$omp parallel private(kp,kr,count,kt,keep) \n!$omp do\ndo i=0,n1-1\n\tdo j=0,n2-1\n\t\tdo k=0,n3-1\n\t\t\tcount=0\n\t\t\tkeep = .true.\n\t\t\tkp(1)=m1*(-1.0+2.0*i/(n1-1))*Gs(1,1)+m2*(-1.0+2.0*j/(n2-1))*Gs(2,1)+m3*(-1.0+2.0*k/(n3-1))*Gs(3,1)\n\t\t\tkp(2)=m1*(-1.0+2.0*i/(n1-1))*Gs(1,2)+m2*(-1.0+2.0*j/(n2-1))*Gs(2,2)+m3*(-1.0+2.0*k/(n3-1))*Gs(3,2)\n\t\t\tkp(3)=m1*(-1.0+2.0*i/(n1-1))*Gs(1,3)+m2*(-1.0+2.0*j/(n2-1))*Gs(2,3)+m3*(-1.0+2.0*k/(n3-1))*Gs(3,3)\n\t\t\tkt=(kp(1)**2+kp(2)**2+kp(3)**2)\n\t\t\tdo s=1,l\n\t\t\t\tkr=(G(s,1)-kp(1))**2+(G(s,2)-kp(2))**2+(G(s,3)-kp(3))**2\n\t\t\t\tif(kt.gt.kr) then\n\t\t\t\t\tcount=count+1\n\t\t\t\tend if\n\t\t\t\tif(count .ge. bz) then\n\t\t\t\t\tkeep = .false.\n\t\t\t\t\texit \n\t\t\t\tendif\t\t\t\t\n\t\t\tenddo\n\t\t\tif (((count+1) .eq. bz) .AND. keep) write(1,666) kp(1), kp(2),kp(3), SQRT(kt), count+1\n\t\tenddo\n\tenddo\nenddo\n!$omp end do\n!$omp end parallel\n close(1)\n666 format(f20.3,1x,f20.3,1x,f20.3,1x,f20.3,1x,i3)\n\nend subroutine gen_kp", "meta": {"hexsha": "ea579c53756e030e791724aae410c3408ee1eed1", "size": 1281, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "bzones_lib_counting.f90", "max_stars_repo_name": "randrew2636/Visualising_BZ", "max_stars_repo_head_hexsha": "f73016a3cef3b9d041d60d2484b346d8941e6f96", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-02-10T08:14:13.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-10T08:14:13.000Z", "max_issues_repo_path": "bzones_lib_counting.f90", "max_issues_repo_name": "randrew2636/Visualising_BZ", "max_issues_repo_head_hexsha": "f73016a3cef3b9d041d60d2484b346d8941e6f96", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "bzones_lib_counting.f90", "max_forks_repo_name": "randrew2636/Visualising_BZ", "max_forks_repo_head_hexsha": "f73016a3cef3b9d041d60d2484b346d8941e6f96", "max_forks_repo_licenses": ["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.62, "max_line_length": 101, "alphanum_fraction": 0.5651834504, "num_tokens": 638, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037262250327, "lm_q2_score": 0.7248702702332476, "lm_q1q2_score": 0.6714500323468036}} {"text": "! Efficient Fortran methods for computing measures.\n!\n!! @author Michael P. Howard\n\n!> @brief Calculates the Minkowski functionals for a 3D array.\n!!\n!! The Minkowski functionals (volume, surface area, integral mean\n!! curvature, Euler characteristic) are computed for a domain\n!! represented by a 3D *lattice*. The lattice is digitized into\n!! 1s and 0s, and the active domain is all the 1s. The lattice\n!! is 0-indexed, and the voxels are assumed to be cubes of size *a*.\n!! The units of the returned functionals are implicitly in *a*.\n!!\n!! Additional details can be found in the reference from which\n!! this routine was taken::\n!! K. Michielsen and H. De Raedt, Integral-geometry morphological\n!! analysis, Physics Report 347, 461-538 (2001).\n!! @see minkowski_add_voxel\n!!\n!! @param[in] lattice 3D array of integers.\n!! @param[in] Lx Size of lattice in x.\n!! @param[in] Ly Size of lattice in y.\n!! @param[in] Lz Size of lattice in z.\n!! @param[out] volume Volume of active lattice.\n!! @param[out] surface Surface area of active lattice.\n!! @param[out] curvature Mean curvature of active lattice.\n!! @param[out] euler Euler characteristic of active lattice.\n!!\nsubroutine minkowski(lattice,Lx,Ly,Lz,volume,surface,curvature,euler)\nimplicit none\ninteger, intent(in), dimension(0:Lx-1,0:Ly-1,0:Lz-1) :: lattice\ninteger, intent(in) :: Lx, Ly, Lz\ninteger, intent(out) :: volume, surface, curvature, euler\n\ninteger, dimension(0:Lx-1,0:Ly-1,0:Lz-1) :: tmp\ninteger v,s,c,e\ninteger jx,jy,jz\n\n! fill all tmp pixels with 0\ntmp = 0\n\n! loop over pixels and accumulate functionals\nvolume = 0\nsurface = 0\ncurvature = 0\neuler = 0\ndo jz = 0,Lz-1\ndo jy = 0,Ly-1\ndo jx = 0,Lx-1\n if (lattice(jx,jy,jz) > 0) then ! active pixel\n call minkowski_add_voxel(tmp,Lx,Ly,Lz,jx,jy,jz,v,s,c,e)\n tmp(jx,jy,jz) = 1 ! add pixel to image\n volume = volume + v\n surface = surface + s\n curvature = curvature + c\n euler = euler + e\n end if\nend do ! jx\nend do ! jy\nend do ! jz\nend subroutine\n\n!> @brief Calculates the change in Minkowski functionals on addition of a pixel.\n!!\n!! The changes in the Minkowski functionals (volume, surface area,\n!! integral mean curvature, Euler characteristic) are computed from\n!! adding a voxel at (*jx*,*jy*,*jz*) to the 3D *lattice*. The lattice\n!! is 0-indexed, and the voxels are assumed to be cubes of size *a*.\n!! The units of the returned functionals are implicitly in *a*.\n!!\n!! Reference equations can be found in Appendix B of::\n!! K. Michielsen and H. De Raedt, Integral-geometry morphological\n!! analysis, Physics Report 347, 461-538 (2001).\n!! @see minkowski\n!!\n!! @param[in] lattice 3D array of integers.\n!! @param[in] Lx Size of lattice in x.\n!! @param[in] Ly Size of lattice in y.\n!! @param[in] Lz Size of lattice in z.\n!! @param[in] jx Added voxel x-coordinate.\n!! @param[in] jy Added voxel y-coordinate.\n!! @param[in] jz Added voxel z-coordinate.\n!! @param[out] volume Change in volume.\n!! @param[out] surface Change in surface area.\n!! @param[out] curvature Change in mean curvature.\n!! @param[out] euler Change in Euler characteristic.\n!!\nsubroutine minkowski_add_voxel(lattice,Lx,Ly,Lz,jx,jy,jz,volume,surface,curvature,euler)\nimplicit none\ninteger, intent(in), dimension(0:Lx-1,0:Ly-1,0:Lz-1) :: lattice\ninteger, intent(in) :: Lx, Ly, Lz, jx, jy, jz\ninteger, intent(out) :: volume, surface, curvature, euler\n\ninteger, parameter :: volume_body = 1 ! (a*a*a, where a is lattice displacement)\ninteger, parameter :: surface_body = -6 ! (-6*a*a, open body)\ninteger, parameter :: surface_face = 2 ! (2*a*a, open face)\ninteger, parameter :: curv_body = 3 ! (3*a, open body)\ninteger, parameter :: curv_face = -2 ! (-2*a, open face)\ninteger, parameter :: curv_edge = 1 ! (a, open line)\ninteger, parameter :: euler_body = -1 ! (open body)\ninteger, parameter :: euler_face = 1 ! (open face)\ninteger, parameter :: euler_edge = -1 ! (open line)\ninteger, parameter :: euler_vertex = 1 ! (vertices)\n\ninteger nfaces, nedges, nvert\ninteger i0,j0,k0,jxi,jyi,jzi,jyj,jzj,jzk\ninteger kc1,kc2,kc3,kc7,kc1kc4kc5\n\n! accumulate faces, edges, vertices from adding pixel\nnfaces = 0\nnedges = 0\nnvert = 0\ndo i0 = -1,1,2\n ! wrap offsets to account for periodic boundaries\n jxi = modulo(jx+i0,Lx)\n jyi = modulo(jy+i0,Ly)\n jzi = modulo(jz+i0,Lz)\n kc1 = 1-lattice(jxi,jy,jz)\n kc2 = 1-lattice(jx,jyi,jz)\n kc3 = 1-lattice(jx,jy,jzi)\n nfaces = nfaces + kc1 + kc2 + kc3 ! (B.5)\n do j0 = -1,1,2\n jyj = modulo(jy+j0,Ly)\n jzj = modulo(jz+j0,Lz)\n kc7 = 1-lattice(jx,jy,jzj)\n kc1kc4kc5 = kc1*(1-lattice(jxi,jyj,jz))*(1-lattice(jx,jyj,jz))\n nedges = nedges + kc1kc4kc5 + kc2*(1-lattice(jx,jyi,jzj))*kc7 + kc1*(1-lattice(jxi,jy,jzj))*kc7 ! (B.6)\n if (kc1kc4kc5.ne.0) then ! whole term (B.7) evaluates to 0 otherwise\n do k0 = -1,1,2\n jzk = modulo(jz+k0,Lz)\n nvert = nvert + (1-lattice(jxi,jy,jzk))*(1-lattice(jxi,jyj,jzk))*(1-lattice(jx,jyj,jzk))*(1-lattice(jx,jy,jzk)) ! (B.7, without kc1kc4kc5)\n end do !k0\n end if\n end do ! j0\nend do ! i0\n\nvolume = volume_body\nsurface = surface_body + surface_face*nfaces\ncurvature = curv_body + curv_face*nfaces + curv_edge*nedges\neuler = euler_body + euler_face*nfaces + euler_edge*nedges + euler_vertex*nvert\nend subroutine\n", "meta": {"hexsha": "3423ce2424a425106f550c038cb751d44ea400a1", "size": 5506, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fieldkit/measure.f90", "max_stars_repo_name": "djz332/fieldkit", "max_stars_repo_head_hexsha": "3c242c2026e80100cdd6b2114d72a61122381fcd", "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": "fieldkit/measure.f90", "max_issues_repo_name": "djz332/fieldkit", "max_issues_repo_head_hexsha": "3c242c2026e80100cdd6b2114d72a61122381fcd", "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": "fieldkit/measure.f90", "max_forks_repo_name": "djz332/fieldkit", "max_forks_repo_head_hexsha": "3c242c2026e80100cdd6b2114d72a61122381fcd", "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": 38.7746478873, "max_line_length": 154, "alphanum_fraction": 0.6574645841, "num_tokens": 1785, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.896251378675949, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6713704475025989}} {"text": "c\nc * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nc * *\nc * copyright (c) 1998 by UCAR *\nc * *\nc * University Corporation for Atmospheric Research *\nc * *\nc * all rights reserved *\nc * *\nc * SPHEREPACK version 3.2 *\nc * *\nc * A Package of Fortran77 Subroutines and Programs *\nc * *\nc * for Modeling Geophysical Processes *\nc * *\nc * by *\nc * *\nc * John Adams and Paul Swarztrauber *\nc * *\nc * of *\nc * *\nc * the National Center for Atmospheric Research *\nc * *\nc * Boulder, Colorado (80307) U.S.A. *\nc * *\nc * which is sponsored by *\nc * *\nc * the National Science Foundation *\nc * *\nc * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nc\nc\nc\nc This version of gaqd implements the method presented in:\nc P. N. swarztrauber, Computing the points and weights for \nc Gauss-Legendre quadrature, SIAM J. Sci. Comput.,\nc 24(2002) pp. 945-954.\nc \nc The w and lwork arrays are dummy and included only to\nc permit a simple pluggable exchange with the\nc old gaqd in previous versions of SPHEREPACK\nc\nc\nc\n subroutine gaqd(nlat,theta,wts,w,lwork,ierror)\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc\nc gauss points and weights are computed using the fourier-newton\nc described in \"on computing the points and weights for \nc gauss-legendre quadrature\", paul n. swarztrauber, siam journal \nc on scientific computing that has been accepted for publication.\nc This routine is faster and more accurate than older program \nc with the same name.\nc\nc subroutine gaqd computes the nlat gaussian colatitudes and weights\nc in double precision. the colatitudes are in radians and lie in the\nc in the interval (0,pi).\nc\nc input parameters\nc\nc nlat the number of gaussian colatitudes in the interval (0,pi)\nc (between the two poles). nlat must be greater than zero.\nc\nc w unused double precision variable that permits a simple \nc exchange with the old routine with the same name \nc in spherepack.\nc\nc lwork unused variable that permits a simple exchange with the\nc old routine with the same name in spherepack.\nc\nc output parameters\nc\nc theta a double precision array with length nlat\nc containing the gaussian colatitudes in\nc increasing radians on the interval (0,pi).\nc\nc wts a double precision array with lenght nlat\nc containing the gaussian weights.\nc\nc ierror = 0 no errors\nc = 1 if nlat.le.0\nc\nc *****************************************************************\nc\n double precision theta(nlat),wts(nlat),w,\n 1 x,pi,pis2,dtheta,dthalf,cmax,zprev,zlast,zero,\n 2 zhold,pb,dpb,dcor,sum,cz\nc\nc check work space length\nc\n ierror = 1\n if (nlat.le.0) return\n ierror = 0\nc\nc compute weights and points analytically when nlat=1,2\nc\n if (nlat.eq.1) then\n theta(1) = dacos(0.0d0)\n wts(1) = 2.0d0\n return\n end if\n if (nlat.eq.2) then\n x = dsqrt(1.0d0/3.0d0)\n theta(1) = dacos(x)\n theta(2) = dacos(-x)\n wts(1) = 1.0d0\n wts(2) = 1.0d0\n return\n end if\n eps = sqrt(dzeps(1.0d0))\n eps = eps*sqrt(eps)\n pis2 = 2.0d0*datan(1.0d0)\n pi = pis2+pis2 \n mnlat = mod(nlat,2)\n ns2 = nlat/2\n nhalf = (nlat+1)/2\n idx = ns2+2\nc\n call cpdp (nlat,cz,theta(ns2+1),wts(ns2+1))\nc\n dtheta = pis2/nhalf\n dthalf = dtheta/2.0d0\n cmax = .2d0*dtheta\nc\nc estimate first point next to theta = pi/2\nc\n if(mnlat.ne.0) then\n zero = pis2-dtheta\n zprev = pis2\n nix = nhalf-1\n else\n zero = pis2-dthalf\n nix = nhalf\n end if\n 9 it = 0\n 10 it = it+1\n zlast = zero\nc\nc newton iterations\nc\n call tpdp (nlat,zero,cz,theta(ns2+1),wts(ns2+1),pb,dpb)\n dcor = pb/dpb\n sgnd = 1.0\n if(dcor .ne. 0.0d0) sgnd = dcor/dabs(dcor)\n dcor = sgnd*min(dabs(dcor),cmax)\n zero = zero-dcor\n if(dabs(zero-zlast).gt.eps*dabs(zero)) go to 10\n theta(nix) = zero\n zhold = zero\nc wts(nix) = (nlat+nlat+1)/(dpb*dpb)\nc \nc yakimiw's formula permits using old pb and dpb\nc\n wts(nix) = (nlat+nlat+1)/(dpb+pb*dcos(zlast)/dsin(zlast))**2\n nix = nix-1\n if(nix.eq.0) go to 30\n if(nix.eq.nhalf-1) zero = 3.0*zero-pi\n if(nix.lt.nhalf-1) zero = zero+zero-zprev\n zprev = zhold\n go to 9\nc\nc extend points and weights via symmetries\nc\n 30 if(mnlat.ne.0) then\n theta(nhalf) = pis2\n call tpdp (nlat,pis2,cz,theta(ns2+1),wts(ns2+1),pb,dpb)\n wts(nhalf) = (nlat+nlat+1)/(dpb*dpb)\n end if\n do i=1,ns2\n wts(nlat-i+1) = wts(i)\n theta(nlat-i+1) = pi-theta(i)\n end do\n sum = 0.0d0\n do i=1,nlat\n sum = sum+wts(i)\n end do\n do i=1,nlat\n wts(i) = 2.0d0*wts(i)/sum\n end do\n return\n end\n subroutine cpdp(n,cz,cp,dcp)\nc\nc computes the fourier coefficients of the legendre\nc polynomial p_n^0 and its derivative. \nc n is the degree and n/2 or (n+1)/2\nc coefficients are returned in cp depending on whether\nc n is even or odd. The same number of coefficients\nc are returned in dcp. For n even the constant \nc coefficient is returned in cz. \nc\n double precision cp(n/2+1),dcp(n/2+1),\n 1 t1,t2,t3,t4,cz\n ncp = (n+1)/2\n t1 = -1.0d0\n t2 = n+1.0d0\n t3 = 0.0d0\n t4 = n+n+1.0d0\n if(mod(n,2).eq.0) then\n cp(ncp) = 1.0d0\n do j = ncp,2,-1\n t1 = t1+2.0d0\n t2 = t2-1.0d0\n t3 = t3+1.0d0\n t4 = t4-2.0d0\n cp(j-1) = (t1*t2)/(t3*t4)*cp(j)\n end do\n t1 = t1+2.0d0\n t2 = t2-1.0d0\n t3 = t3+1.0d0\n t4 = t4-2.0d0\n cz = (t1*t2)/(t3*t4)*cp(1)\n do j=1,ncp\n dcp(j) = (j+j)*cp(j)\n end do\n else\n cp(ncp) = 1.0d0\n do j = ncp-1,1,-1\n t1 = t1+2.0d0\n t2 = t2-1.0d0\n t3 = t3+1.0d0\n t4 = t4-2.0d0\n cp(j) = (t1*t2)/(t3*t4)*cp(j+1)\n end do\n do j=1,ncp\n dcp(j) = (j+j-1)*cp(j)\n end do\n end if\n return\n end\n subroutine tpdp (n,theta,cz,cp,dcp,pb,dpb)\nc\nc computes pn(theta) and its derivative dpb(theta) with \nc respect to theta\nc\n double precision cp(n/2+1),dcp(n/2+1),cz,\n 1 pb,dpb,fn,theta,cdt,sdt,cth,sth,chh\nc\n fn = n\n cdt = dcos(theta+theta)\n sdt = dsin(theta+theta)\n if(mod(n,2) .eq.0) then\nc\nc n even\nc\n kdo = n/2\n pb = .5d0*cz\n dpb = 0.0d0\n if(n .gt. 0) then\n cth = cdt\n sth = sdt\n do 170 k=1,kdo\nc pb = pb+cp(k)*cos(2*k*theta)\n pb = pb+cp(k)*cth\nc dpb = dpb-(k+k)*cp(k)*sin(2*k*theta)\n dpb = dpb-dcp(k)*sth\n chh = cdt*cth-sdt*sth\n sth = sdt*cth+cdt*sth\n cth = chh\n 170 continue\n end if\n else\nc\nc n odd\nc\n kdo = (n+1)/2\n pb = 0.0d0\n dpb = 0.0d0\n cth = dcos(theta)\n sth = dsin(theta)\n do 190 k=1,kdo\nc pb = pb+cp(k)*cos((2*k-1)*theta)\n pb = pb+cp(k)*cth\nc dpb = dpb-(k+k-1)*cp(k)*sin((2*k-1)*theta)\n dpb = dpb-dcp(k)*sth\n chh = cdt*cth-sdt*sth\n sth = sdt*cth+cdt*sth\n cth = chh\n 190 continue\n end if\n return\n end\n real function dzeps (x)\n double precision x\nc\nc estimate unit roundoff in quantities of size x.\nc\n double precision a,b,c,eps\nc\nc this program should function properly on all systems\nc satisfying the following two assumptions,\nc 1. the base used in representing floating point\nc numbers is not a power of three.\nc 2. the quantity a in statement 10 is represented to \nc the accuracy used in floating point variables\nc that are stored in memory.\nc the statement number 10 and the go to 10 are intended to\nc force optimizing compilers to generate code satisfying \nc assumption 2.\nc under these assumptions, it should be true that,\nc a is not exactly equal to four-thirds,\nc b has a zero for its last bit or digit,\nc c is not exactly equal to one,\nc eps measures the separation of 1.0 from\nc the next larger floating point number.\nc the developers of eispack would appreciate being informed\nc about any systems where these assumptions do not hold.\nc\nc this version dated 4/6/83.\nc\n a = 4.0d0/3.0d0\n 10 b = a - 1.0d0\n c = b + b + b\n eps = abs(c-1.0d0)\n if (eps .eq. 0.0d0) go to 10\n dzeps = eps*dabs(x)\n return\n end\n", "meta": {"hexsha": "fb4d1ab1031c2772c43459c385620e6ebf168937", "size": 10007, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "install/spherepack3.2/src/gaqd.f", "max_stars_repo_name": "comp-physics/RBC3D", "max_stars_repo_head_hexsha": "2891a1e3b356e2cff0cfa74ba26d4aef3336641d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "install/spherepack3.2/src/gaqd.f", "max_issues_repo_name": "comp-physics/RBC3D", "max_issues_repo_head_hexsha": "2891a1e3b356e2cff0cfa74ba26d4aef3336641d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "install/spherepack3.2/src/gaqd.f", "max_forks_repo_name": "comp-physics/RBC3D", "max_forks_repo_head_hexsha": "2891a1e3b356e2cff0cfa74ba26d4aef3336641d", "max_forks_repo_licenses": ["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.3699059561, "max_line_length": 72, "alphanum_fraction": 0.4847606675, "num_tokens": 3175, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513814471134, "lm_q2_score": 0.7490872075132153, "lm_q1q2_score": 0.6713704445580797}} {"text": "subroutine eval_volume(u, v, w, tu, tv, tw, ku, kv, kw, coef, &\n nctlu, nctlv, nctlw, ndim, n, m, l, val)\n\n !***DESCRIPTION\n !\n ! Written by Gaetan Kenway\n !\n ! Abstract eval_volume evaluates (possibly) many points on the\n ! b-spline volume\n !\n ! Description of Arguments\n ! Input\n ! u - Real, u coordinate, size(l, m, n)\n ! v - Real, v coordinate, size(l, m, n)\n ! w - Real, w coordinate, size(l, m, n)\n ! tu - Real, Knot vector in u. Length nctlu+ku\n ! tv - Real, Knot vector in v. Length nctlv+kv\n ! tw - Real, Knot vector in w. Length nctlv+kw\n ! ku - Integer, order of B-spline in u\n ! kv - Integer, order of B-spline in v\n ! kw - Integer, order of B-spline in w\n ! coef - Real, Array of B-spline coefficients \n ! Size (ndim, nctlw, nctlv, nctlu)\n ! nctlu - Integer, Number of control points in u\n ! nctlv - Integer, Number of control points in v\n ! nctlw - Integer, Number of control points in w\n ! ndim - Integer, Spatial Dimension\n !\n ! Ouput \n ! val - Real, Evaluated points, size (ndim, l, m, n)\n\n use precision\n implicit none\n\n ! Input\n integer , intent(in) :: ku, kv, kw, nctlu, nctlv, nctlw\n integer , intent(in) :: ndim, n, m, l\n real(kind=realType), intent(in) :: u(l, m, n) , v(l, m, n), w(l, m, n)\n real(kind=realType), intent(in) :: tu(nctlu+ku), tv(nctlv+kv), tw(nctlw+kw)\n real(kind=realType), intent(in) :: coef(ndim, nctlw, nctlv, nctlu)\n\n ! Output\n real(kind=realType), intent(out) :: val(ndim, l, m, n)\n\n ! Working\n integer :: idim, istartu, istartv, istartw\n integer :: i, j, k, ii, jj, kk\n integer :: ileftu, ileftv, ileftw\n real(kind=realType) :: basisu(ku), basisv(kv), basisw(kw)\n\n val(:, :, :, :) = 0.0\n do ii=1, n\n do jj=1, m\n do kk=1, l\n ! U\n call findSpan(u(kk, jj, ii), ku, tu, nctlu, ileftu)\n call basis(tu, nctlu, ku, u(kk, jj, ii), ileftu, basisu)\n istartu = ileftu-ku\n\n ! V\n call findSpan(v(kk, jj, ii), kv, tv, nctlv, ileftv)\n call basis(tv, nctlv, kv, v(kk, jj, ii), ileftv, basisv)\n istartv = ileftv-kv\n\n ! W\n call findSpan(w(kk, jj, ii), kw, tw, nctlw, ileftw)\n call basis(tw, nctlw, kw, w(kk, jj, ii), ileftw, basisw)\n istartw = ileftw-kw\n\n do i=1, ku\n do j=1, kv\n do k=1, kw\n do idim=1, ndim\n val(idim, kk, jj, ii) = val(idim, kk, jj, ii) + &\n basisu(i)*basisv(j)*basisw(k)*&\n coef(idim, istartw+k, istartv+j, istartu+i)\n end do\n end do\n end do\n end do\n end do\n end do\n end do\nend subroutine eval_volume\n\nsubroutine eval_volume_deriv(u, v, w, tu, tv, tw, ku, kv, kw, coef, &\n nctlu, nctlv, nctlw, ndim, val)\n\n !***DESCRIPTION\n !\n ! Written by Gaetan Kenway\n !\n ! Abstract eval_volume_deriv evaluates the first derivative on a\n ! volume\n !\n ! Description of Arguments\n ! Input\n ! u - Real, u coordinate\n ! v - Real, v coordinate\n ! w - Real, w coordinate\n ! tu - Real, Knot vector in u. Length nctlu+ku\n ! tv - Real, Knot vector in v. Length nctlv+kv\n ! tw - Real, Knot vector in w. Length nctlv+kw\n ! ku - Integer, order of B-spline in u\n ! kv - Integer, order of B-spline in v\n ! kw - Integer, order of B-spline in w\n ! coef - Real, Array of B-spline coefficients \n ! Size (ndim, nctlw, nctlv, nctlu)\n ! nctlu - Integer, Number of control points in u\n ! nctlv - Integer, Number of control points in v\n ! nctlw - Integer, Number of control points in w\n ! ndim - Integer, Spatial Dimension\n !\n ! Ouput \n ! val - Real, Evaluated derivatvie, size(ndim, 3)\n\n use precision\n implicit none\n\n ! Input\n integer , intent(in) :: ku, kv, kw, nctlu, nctlv, nctlw, ndim\n real(kind=realType), intent(in) :: u , v, w\n real(kind=realType), intent(in) :: tu(nctlu+ku), tv(nctlv+kv), tw(nctlw+kw)\n real(kind=realType), intent(in) :: coef(ndim, nctlw, nctlv, nctlu)\n\n ! Output\n real(kind=realType), intent(out) :: val(ndim, 3)\n\n ! Working\n integer :: idim\n real(kind=realType) :: b3val\n\n do idim=1, ndim\n val(idim, 1) = b3val(w, v, u, 0, 0, 1, tw, tv, tu, nctlw, nctlv, nctlu, &\n kw, kv, ku, coef(idim, :, :, :))\n\n val(idim, 2) = b3val(w, v, u, 0, 1, 0, tw, tv, tu, nctlw, nctlv, nctlu, &\n kw, kv, ku, coef(idim, :, :, :))\n\n val(idim, 3) = b3val(w, v, u, 1, 0, 0, tw, tv, tu, nctlw, nctlv, nctlu, &\n kw, kv, ku, coef(idim, :, :, :))\n end do\nend subroutine eval_volume_deriv\n\nsubroutine eval_volume_deriv2(u, v, w, tu, tv, tw, ku, kv, kw, coef, & \n nctlu, nctlv, nctlw, ndim, val)\n\n !***DESCRIPTION\n !\n ! Written by Gaetan Kenway\n !\n ! Abstract eval_volume_deriv2 evaluates the second derivative on a\n ! volume\n !\n ! Description of Arguments\n ! Input\n ! u - Real, u coordinate\n ! v - Real, v coordinate\n ! w - Real, w coordinate\n ! tu - Real, Knot vector in u. Length nctlu+ku\n ! tv - Real, Knot vector in v. Length nctlv+kv\n ! tw - Real, Knot vector in w. Length nctlv+kw\n ! ku - Integer, order of B-spline in u\n ! kv - Integer, order of B-spline in v\n ! kw - Integer, order of B-spline in w\n ! coef - Real, Array of B-spline coefficients \n ! Size (ndim, nctlw, nctlv, nctlu)\n ! nctlu - Integer, Number of control points in u\n ! nctlv - Integer, Number of control points in v\n ! nctlw - Integer, Number of control points in w\n ! ndim - Integer, Spatial Dimension\n !\n ! Ouput \n ! val - Real, Evaluated derivatvie, size(ndim, 3, 3)\n\n use precision\n implicit none\n ! Input\n integer , intent(in) :: ku, kv, kw, nctlu, nctlv, nctlw, ndim\n real(kind=realType), intent(in) :: u, v, w\n real(kind=realType), intent(in) :: tu(nctlu+ku), tv(nctlv+kv), tw(nctlw+kw)\n real(kind=realType), intent(in) :: coef(ndim, nctlw, nctlv, nctlu)\n\n ! Output\n real(kind=realType), intent(out) :: val(ndim, 3, 3)\n\n ! Working\n integer :: idim\n\n real(kind=realType) :: b3val\n\n do idim=1, ndim\n\n ! Row 1\n if (ku>=3) then\n val(idim, 1, 1) = b3val(w, v, u, 0, 0, 2, tw, tv, tu, nctlw, nctlv, &\n nctlu, kw, kv, ku, coef(idim, :, :, :))\n else\n val(idim, 1, 1) = 0.0\n end if\n val(idim, 1, 2) = b3val(w, v, u, 0, 1, 1, tw, tv, tu, nctlw, nctlv, nctlu, &\n kw, kv, ku, coef(idim, :, :, :))\n val(idim, 1, 3) = b3val(w, v, u, 1, 0, 1, tw, tv, tu, nctlw, nctlv, nctlu, &\n kw, kv, ku, coef(idim, :, :, :))\n\n ! Row 2\n val(idim, 2, 1) = val(idim, 1, 2)\n if (kv>=3) then\n val(idim, 2, 2) = b3val(w, v, u, 0, 2, 0, tw, tv, tu, nctlw, nctlv, &\n nctlu, kw, kv, ku, coef(idim, :, :, :))\n else\n val(idim, 2, 2) = 0.0\n end if\n val(idim, 2, 3) = b3val(w , v , u, 1, 1, 0, tw, tv, tu, nctlw, nctlv, nctlu, &\n kw, kv, ku, coef(idim, :, :, :))\n\n ! Row 3\n val(idim, 3, 1) = val(idim, 1, 3)\n val(idim, 3, 2) = val(idim, 2, 3)\n if (kw>=3) then\n val(idim, 3, 3) = b3val(w, v, u, 2, 0, 0, tw, tv, tu, nctlw, nctlv, &\n nctlu, kw, kv, ku, coef(idim, :, :, :))\n else\n val(idim, 3, 3) = 0.0\n end if\n end do\n\nend subroutine eval_volume_deriv2\n", "meta": {"hexsha": "a0dbf10c1b7d417843f76ecabe88c673007549ce", "size": 7949, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/eval_volume.f90", "max_stars_repo_name": "eirikurj/pyspline", "max_stars_repo_head_hexsha": "91dd6d432deac3b1647508bf4fca985e704da77c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2019-04-18T00:49:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-20T14:40:08.000Z", "max_issues_repo_path": "src/eval_volume.f90", "max_issues_repo_name": "eirikurj/pyspline", "max_issues_repo_head_hexsha": "91dd6d432deac3b1647508bf4fca985e704da77c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 23, "max_issues_repo_issues_event_min_datetime": "2019-10-17T20:39:11.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T15:27:42.000Z", "max_forks_repo_path": "src/eval_volume.f90", "max_forks_repo_name": "eirikurj/pyspline", "max_forks_repo_head_hexsha": "91dd6d432deac3b1647508bf4fca985e704da77c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2019-05-29T16:56:15.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-08T13:51:24.000Z", "avg_line_length": 34.711790393, "max_line_length": 83, "alphanum_fraction": 0.5113850799, "num_tokens": 2876, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513759047848, "lm_q2_score": 0.749087201911703, "lm_q1q2_score": 0.6713704353860291}} {"text": " FUNCTION ran3(idum)\r\n INTEGER idum\r\n INTEGER MBIG,MSEED,MZ\r\nC REAL MBIG,MSEED,MZ\r\n REAL ran3,FAC\r\n PARAMETER (MBIG=1000000000,MSEED=161803398,MZ=0,FAC=1./MBIG)\r\nC PARAMETER (MBIG=4000000.,MSEED=1618033.,MZ=0.,FAC=1./MBIG)\r\n INTEGER i,iff,ii,inext,inextp,k\r\n INTEGER mj,mk,ma(55)\r\nC REAL mj,mk,ma(55)\r\n SAVE iff,inext,inextp,ma\r\n DATA iff /0/\r\n if(idum.lt.0.or.iff.eq.0)then\r\n iff=1\r\n mj=MSEED-iabs(idum)\r\n mj=mod(mj,MBIG)\r\n ma(55)=mj\r\n mk=1\r\n do 11 i=1,54\r\n ii=mod(21*i,55)\r\n ma(ii)=mk\r\n mk=mj-mk\r\n if(mk.lt.MZ)mk=mk+MBIG\r\n mj=ma(ii)\r\n11 continue\r\n do 13 k=1,4\r\n do 12 i=1,55\r\n ma(i)=ma(i)-ma(1+mod(i+30,55))\r\n if(ma(i).lt.MZ)ma(i)=ma(i)+MBIG\r\n12 continue\r\n13 continue\r\n inext=0\r\n inextp=31\r\n idum=1\r\n endif\r\n inext=inext+1\r\n if(inext.eq.56)inext=1\r\n inextp=inextp+1\r\n if(inextp.eq.56)inextp=1\r\n mj=ma(inext)-ma(inextp)\r\n if(mj.lt.MZ)mj=mj+MBIG\r\n ma(inext)=mj\r\n ran3=mj*FAC\r\n return\r\n END\r\n", "meta": {"hexsha": "63e54533b248bd79a851bee48f0c6abb0d8b7151", "size": 1171, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/ran3.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/ran3.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/ran3.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.4565217391, "max_line_length": 67, "alphanum_fraction": 0.4970111016, "num_tokens": 447, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513620489619, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6713704350475356}} {"text": " SUBROUTINE SSTEGR2( JOBZ, RANGE, N, D, E, VL, VU, IL, IU,\n $ M, W, Z, LDZ, NZC, ISUPPZ, WORK, LWORK, IWORK,\n $ LIWORK, DOL, DOU, ZOFFSET, INFO )\n*\n* -- ScaLAPACK auxiliary routine (version 2.0) --\n* Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver\n* July 4, 2010\n*\n* .. Scalar Arguments ..\n CHARACTER JOBZ, RANGE\n INTEGER DOL, DOU, IL, INFO, IU, \n $ LDZ, NZC, LIWORK, LWORK, M, N, ZOFFSET\n REAL VL, VU\n\n* ..\n* .. Array Arguments ..\n INTEGER ISUPPZ( * ), IWORK( * )\n REAL D( * ), E( * ), W( * ), WORK( * )\n REAL Z( LDZ, * )\n* ..\n*\n* Purpose\n* =======\n*\n* SSTEGR2 computes selected eigenvalues and, optionally, eigenvectors\n* of a real symmetric tridiagonal matrix T. It is invoked in the \n* ScaLAPACK MRRR driver PSSYEVR and the corresponding Hermitian\n* version either when only eigenvalues are to be computed, or when only\n* a single processor is used (the sequential-like case).\n*\n* SSTEGR2 has been adapted from LAPACK's SSTEGR. Please note the\n* following crucial changes.\n*\n* 1. The calling sequence has two additional INTEGER parameters, \n* DOL and DOU, that should satisfy M>=DOU>=DOL>=1. \n* SSTEGR2 ONLY computes the eigenpairs\n* corresponding to eigenvalues DOL through DOU in W. (That is,\n* instead of computing the eigenpairs belonging to W(1) \n* through W(M), only the eigenvectors belonging to eigenvalues\n* W(DOL) through W(DOU) are computed. In this case, only the\n* eigenvalues DOL:DOU are guaranteed to be fully accurate.\n*\n* 2. M is NOT the number of eigenvalues specified by RANGE, but is \n* M = DOU - DOL + 1. This concerns the case where only eigenvalues\n* are computed, but on more than one processor. Thus, in this case\n* M refers to the number of eigenvalues computed on this processor.\n* \n* 3. The arrays W and Z might not contain all the wanted eigenpairs\n* locally, instead this information is distributed over other \n* processors.\n* \n* Arguments\n* =========\n*\n* JOBZ (input) CHARACTER*1\n* = 'N': Compute eigenvalues only;\n* = 'V': Compute eigenvalues and eigenvectors.\n*\n* RANGE (input) CHARACTER*1\n* = 'A': all eigenvalues will be found.\n* = 'V': all eigenvalues in the half-open interval (VL,VU]\n* will be found.\n* = 'I': the IL-th through IU-th eigenvalues will be found.\n*\n* N (input) INTEGER\n* The order of the matrix. N >= 0.\n*\n* D (input/output) REAL array, dimension (N)\n* On entry, the N diagonal elements of the tridiagonal matrix\n* T. On exit, D is overwritten.\n*\n* E (input/output) REAL array, dimension (N)\n* On entry, the (N-1) subdiagonal elements of the tridiagonal\n* matrix T in elements 1 to N-1 of E. E(N) need not be set on\n* input, but is used internally as workspace.\n* On exit, E is overwritten.\n*\n* VL (input) REAL\n* VU (input) REAL\n* If RANGE='V', the lower and upper bounds of the interval to\n* be searched for eigenvalues. VL < VU.\n* Not referenced if RANGE = 'A' or 'I'.\n*\n* IL (input) INTEGER\n* IU (input) INTEGER\n* If RANGE='I', the indices (in ascending order) of the\n* smallest and largest eigenvalues to be returned.\n* 1 <= IL <= IU <= N, if N > 0.\n* Not referenced if RANGE = 'A' or 'V'.\n*\n* M (output) INTEGER\n* Globally summed over all processors, M equals \n* the total number of eigenvalues found. 0 <= M <= N.\n* If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1.\n* The local output equals M = DOU - DOL + 1.\n*\n* W (output) REAL array, dimension (N)\n* The first M elements contain the selected eigenvalues in\n* ascending order. Note that immediately after exiting this \n* routine, only the eigenvalues from\n* position DOL:DOU are to reliable on this processor\n* because the eigenvalue computation is done in parallel. \n* Other processors will hold reliable information on other\n* parts of the W array. This information is communicated in\n* the ScaLAPACK driver.\n*\n* Z (output) REAL array, dimension (LDZ, max(1,M) )\n* If JOBZ = 'V', and if INFO = 0, then the first M columns of Z\n* contain some of the orthonormal eigenvectors of the matrix T\n* corresponding to the selected eigenvalues, with the i-th\n* column of Z holding the eigenvector associated with W(i).\n* If JOBZ = 'N', then Z is not referenced.\n* Note: the user must ensure that at least max(1,M) columns are\n* supplied in the array Z; if RANGE = 'V', the exact value of M\n* is not known in advance and can be computed with a workspace\n* query by setting NZC = -1, see below.\n*\n* LDZ (input) INTEGER\n* The leading dimension of the array Z. LDZ >= 1, and if\n* JOBZ = 'V', then LDZ >= max(1,N).\n*\n* NZC (input) INTEGER\n* The number of eigenvectors to be held in the array Z. \n* If RANGE = 'A', then NZC >= max(1,N).\n* If RANGE = 'V', then NZC >= the number of eigenvalues in (VL,VU].\n* If RANGE = 'I', then NZC >= IU-IL+1.\n* If NZC = -1, then a workspace query is assumed; the\n* routine calculates the number of columns of the array Z that\n* are needed to hold the eigenvectors. \n* This value is returned as the first entry of the Z array, and\n* no error message related to NZC is issued.\n*\n* ISUPPZ (output) INTEGER ARRAY, dimension ( 2*max(1,M) )\n* The support of the eigenvectors in Z, i.e., the indices\n* indicating the nonzero elements in Z. The i-th computed eigenvector\n* is nonzero only in elements ISUPPZ( 2*i-1 ) through\n* ISUPPZ( 2*i ). This is relevant in the case when the matrix \n* is split. ISUPPZ is only set if N>2.\n*\n* WORK (workspace/output) REAL array, dimension (LWORK)\n* On exit, if INFO = 0, WORK(1) returns the optimal\n* (and minimal) LWORK.\n*\n* LWORK (input) INTEGER\n* The dimension of the array WORK. LWORK >= max(1,18*N)\n* if JOBZ = 'V', and LWORK >= max(1,12*N) if JOBZ = 'N'.\n* If LWORK = -1, then a workspace query is assumed; the routine\n* only calculates the optimal size of the WORK array, returns\n* this value as the first entry of the WORK array, and no error\n* message related to LWORK is issued.\n*\n* IWORK (workspace/output) INTEGER array, dimension (LIWORK)\n* On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK.\n*\n* LIWORK (input) INTEGER\n* The dimension of the array IWORK. LIWORK >= max(1,10*N)\n* if the eigenvectors are desired, and LIWORK >= max(1,8*N)\n* if only the eigenvalues are to be computed.\n* If LIWORK = -1, then a workspace query is assumed; the\n* routine only calculates the optimal size of the IWORK array,\n* returns this value as the first entry of the IWORK array, and\n* no error message related to LIWORK is issued.\n*\n* DOL (input) INTEGER\n* DOU (input) INTEGER\n* From the eigenvalues W(1:M), only eigenvectors \n* Z(:,DOL) to Z(:,DOU) are computed.\n* If DOL > 1, then Z(:,DOL-1-ZOFFSET) is used and overwritten.\n* If DOU < M, then Z(:,DOU+1-ZOFFSET) is used and overwritten.\n*\n* ZOFFSET (input) INTEGER\n* Offset for storing the eigenpairs when Z is distributed\n* in 1D-cyclic fashion\n*\n* INFO (output) INTEGER\n* On exit, INFO\n* = 0: successful exit\n* other:if INFO = -i, the i-th argument had an illegal value\n* if INFO = 10X, internal error in SLARRE2,\n* if INFO = 20X, internal error in SLARRV.\n* Here, the digit X = ABS( IINFO ) < 10, where IINFO is \n* the nonzero error code returned by SLARRE2 or \n* SLARRV, respectively.\n*\n* =====================================================================\n*\n* .. Parameters ..\n REAL ZERO, ONE, FOUR, MINRGP\n PARAMETER ( ZERO = 0.0E0, ONE = 1.0E0,\n $ FOUR = 4.0E0,\n $ MINRGP = 3.0E-3 )\n* ..\n* .. Local Scalars ..\n LOGICAL ALLEIG, INDEIG, LQUERY, VALEIG, WANTZ, ZQUERY\n INTEGER I, IIL, IINDBL, IINDW, IINDWK, IINFO, IINSPL,\n $ IIU, INDE2, INDERR, INDGP, INDGRS, INDWRK,\n $ ITMP, ITMP2, J, JJ, LIWMIN, LWMIN, NSPLIT,\n $ NZCMIN\n REAL BIGNUM, EPS, PIVMIN, RMAX, RMIN, RTOL1, RTOL2,\n $ SAFMIN, SCALE, SMLNUM, THRESH, TMP, TNRM, WL,\n $ WU\n* ..\n* .. External Functions ..\n LOGICAL LSAME\n REAL SLAMCH, SLANST\n EXTERNAL LSAME, SLAMCH, SLANST\n* ..\n* .. External Subroutines ..\n EXTERNAL SCOPY, SLAE2, SLAEV2, SLARRC, SLARRE2,\n $ SLARRV, SLASRT, SSCAL, SSWAP\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC MAX, MIN, REAL, SQRT\n* ..\n* .. Executable Statements ..\n*\n* Test the input parameters.\n*\n WANTZ = LSAME( JOBZ, 'V' )\n ALLEIG = LSAME( RANGE, 'A' )\n VALEIG = LSAME( RANGE, 'V' )\n INDEIG = LSAME( RANGE, 'I' )\n*\n LQUERY = ( ( LWORK.EQ.-1 ).OR.( LIWORK.EQ.-1 ) )\n ZQUERY = ( NZC.EQ.-1 )\n\n* SSTEGR2 needs WORK of size 6*N, IWORK of size 3*N.\n* In addition, SLARRE2 needs WORK of size 6*N, IWORK of size 5*N.\n* Furthermore, SLARRV needs WORK of size 12*N, IWORK of size 7*N.\n IF( WANTZ ) THEN\n LWMIN = 18*N\n LIWMIN = 10*N\n ELSE\n* need less workspace if only the eigenvalues are wanted \n LWMIN = 12*N\n LIWMIN = 8*N\n ENDIF\n\n WL = ZERO\n WU = ZERO\n IIL = 0\n IIU = 0\n\n IF( VALEIG ) THEN\n* We do not reference VL, VU in the cases RANGE = 'I','A'\n* The interval (WL, WU] contains all the wanted eigenvalues. \n* It is either given by the user or computed in SLARRE2.\n WL = VL\n WU = VU\n ELSEIF( INDEIG ) THEN\n* We do not reference IL, IU in the cases RANGE = 'V','A'\n IIL = IL\n IIU = IU\n ENDIF \n*\n INFO = 0\n IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN\n INFO = -1\n ELSE IF( .NOT.( ALLEIG .OR. VALEIG .OR. INDEIG ) ) THEN\n INFO = -2\n ELSE IF( N.LT.0 ) THEN\n INFO = -3\n ELSE IF( VALEIG .AND. N.GT.0 .AND. WU.LE.WL ) THEN\n INFO = -7\n ELSE IF( INDEIG .AND. ( IIL.LT.1 .OR. IIL.GT.N ) ) THEN\n INFO = -8\n ELSE IF( INDEIG .AND. ( IIU.LT.IIL .OR. IIU.GT.N ) ) THEN\n INFO = -9\n ELSE IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN\n INFO = -13\n ELSE IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN\n INFO = -17\n ELSE IF( LIWORK.LT.LIWMIN .AND. .NOT.LQUERY ) THEN\n INFO = -19\n END IF\n*\n* Get machine constants.\n*\n SAFMIN = SLAMCH( 'Safe minimum' )\n EPS = SLAMCH( 'Precision' )\n SMLNUM = SAFMIN / EPS\n BIGNUM = ONE / SMLNUM\n RMIN = SQRT( SMLNUM )\n RMAX = MIN( SQRT( BIGNUM ), ONE / SQRT( SQRT( SAFMIN ) ) )\n*\n IF( INFO.EQ.0 ) THEN\n WORK( 1 ) = LWMIN\n IWORK( 1 ) = LIWMIN\n*\n IF( WANTZ .AND. ALLEIG ) THEN\n NZCMIN = N\n IIL = 1\n IIU = N\n ELSE IF( WANTZ .AND. VALEIG ) THEN\n CALL SLARRC( 'T', N, VL, VU, D, E, SAFMIN, \n $ NZCMIN, ITMP, ITMP2, INFO )\n IIL = ITMP+1\n IIU = ITMP2\n ELSE IF( WANTZ .AND. INDEIG ) THEN\n NZCMIN = IIU-IIL+1\n ELSE \n* WANTZ .EQ. FALSE. \n NZCMIN = 0\n ENDIF \n IF( ZQUERY .AND. INFO.EQ.0 ) THEN\n Z( 1,1 ) = NZCMIN\n ELSE IF( NZC.LT.NZCMIN .AND. .NOT.ZQUERY ) THEN\n INFO = -14\n END IF\n END IF\n\n IF ( WANTZ ) THEN\n IF ( DOL.LT.1 .OR. DOL.GT.NZCMIN ) THEN \n INFO = -20\n ENDIF\n IF ( DOU.LT.1 .OR. DOU.GT.NZCMIN .OR. DOU.LT.DOL) THEN \n INFO = -21\n ENDIF\n ENDIF\n\n IF( INFO.NE.0 ) THEN\n*\nC Disable sequential error handler\nC for parallel case\nC CALL XERBLA( 'SSTEGR2', -INFO )\n*\n RETURN\n ELSE IF( LQUERY .OR. ZQUERY ) THEN\n RETURN\n END IF\n*\n* Quick return if possible\n*\n M = 0\n IF( N.EQ.0 )\n $ RETURN\n*\n IF( N.EQ.1 ) THEN\n IF( ALLEIG .OR. INDEIG ) THEN\n M = 1\n W( 1 ) = D( 1 )\n ELSE\n IF( WL.LT.D( 1 ) .AND. WU.GE.D( 1 ) ) THEN\n M = 1\n W( 1 ) = D( 1 )\n END IF\n END IF\n IF( WANTZ )\n $ Z( 1, 1 ) = ONE\n RETURN\n END IF\n*\n INDGRS = 1\n INDERR = 2*N + 1\n INDGP = 3*N + 1\n INDE2 = 5*N + 1\n INDWRK = 6*N + 1\n*\n IINSPL = 1\n IINDBL = N + 1\n IINDW = 2*N + 1\n IINDWK = 3*N + 1\n*\n* Scale matrix to allowable range, if necessary.\n*\n SCALE = ONE\n TNRM = SLANST( 'M', N, D, E )\n IF( TNRM.GT.ZERO .AND. TNRM.LT.RMIN ) THEN\n SCALE = RMIN / TNRM\n ELSE IF( TNRM.GT.RMAX ) THEN\n SCALE = RMAX / TNRM\n END IF\n IF( SCALE.NE.ONE ) THEN\n CALL SSCAL( N, SCALE, D, 1 )\n CALL SSCAL( N-1, SCALE, E, 1 )\n TNRM = TNRM*SCALE\n IF( VALEIG ) THEN\n* If eigenvalues in interval have to be found, \n* scale (WL, WU] accordingly\n WL = WL*SCALE\n WU = WU*SCALE\n ENDIF\n END IF\n*\n* Compute the desired eigenvalues of the tridiagonal after splitting\n* into smaller subblocks if the corresponding off-diagonal elements\n* are small\n* THRESH is the splitting parameter for SLARRE2 \n* A negative THRESH forces the old splitting criterion based on the\n* size of the off-diagonal. A positive THRESH switches to splitting\n* which preserves relative accuracy. \n*\n IINFO = -1\n* Set the splitting criterion\n IF (IINFO.EQ.0) THEN\n THRESH = EPS\n ELSE\n THRESH = -EPS\n ENDIF\n*\n* Store the squares of the offdiagonal values of T\n DO 5 J = 1, N-1\n WORK( INDE2+J-1 ) = E(J)**2\n 5 CONTINUE\n\n* Set the tolerance parameters for bisection\n IF( .NOT.WANTZ ) THEN\n* SLARRE2 computes the eigenvalues to full precision. \n RTOL1 = FOUR * EPS\n RTOL2 = FOUR * EPS\n ELSE \n* SLARRE2 computes the eigenvalues to less than full precision.\n* SLARRV will refine the eigenvalue approximations, and we can\n* need less accurate initial bisection in SLARRE2.\n* Note: these settings do only affect the subset case and SLARRE2\n RTOL1 = SQRT(EPS)\n RTOL2 = MAX( SQRT(EPS)*5.0E-3, FOUR * EPS )\n ENDIF\n CALL SLARRE2( RANGE, N, WL, WU, IIL, IIU, D, E, \n $ WORK(INDE2), RTOL1, RTOL2, THRESH, NSPLIT, \n $ IWORK( IINSPL ), M, DOL, DOU,\n $ W, WORK( INDERR ),\n $ WORK( INDGP ), IWORK( IINDBL ),\n $ IWORK( IINDW ), WORK( INDGRS ), PIVMIN,\n $ WORK( INDWRK ), IWORK( IINDWK ), IINFO )\n IF( IINFO.NE.0 ) THEN\n INFO = 100 + ABS( IINFO )\n RETURN\n END IF\n* Note that if RANGE .NE. 'V', SLARRE2 computes bounds on the desired\n* part of the spectrum. All desired eigenvalues are contained in\n* (WL,WU]\n\n\n IF( WANTZ ) THEN\n*\n* Compute the desired eigenvectors corresponding to the computed\n* eigenvalues\n*\n CALL SLARRV( N, WL, WU, D, E,\n $ PIVMIN, IWORK( IINSPL ), M, \n $ DOL, DOU, MINRGP, RTOL1, RTOL2, \n $ W, WORK( INDERR ), WORK( INDGP ), IWORK( IINDBL ),\n $ IWORK( IINDW ), WORK( INDGRS ), Z, LDZ,\n $ ISUPPZ, WORK( INDWRK ), IWORK( IINDWK ), IINFO )\n IF( IINFO.NE.0 ) THEN\n INFO = 200 + ABS( IINFO )\n RETURN\n END IF\n ELSE\n* SLARRE2 computes eigenvalues of the (shifted) root representation\n* SLARRV returns the eigenvalues of the unshifted matrix.\n* However, if the eigenvectors are not desired by the user, we need\n* to apply the corresponding shifts from SLARRE2 to obtain the \n* eigenvalues of the original matrix. \n DO 20 J = 1, M\n ITMP = IWORK( IINDBL+J-1 )\n W( J ) = W( J ) + E( IWORK( IINSPL+ITMP-1 ) )\n 20 CONTINUE\n END IF\n*\n\n*\n* If matrix was scaled, then rescale eigenvalues appropriately.\n*\n IF( SCALE.NE.ONE ) THEN\n CALL SSCAL( M, ONE / SCALE, W, 1 )\n END IF\n*\n* Correct M if needed \n*\n IF ( WANTZ ) THEN\n IF( DOL.NE.1 .OR. DOU.NE.M ) THEN\n M = DOU - DOL +1\n ENDIF\n ENDIF\n*\n* If eigenvalues are not in increasing order, then sort them, \n* possibly along with eigenvectors.\n*\n IF( NSPLIT.GT.1 ) THEN\n IF( .NOT. WANTZ ) THEN\n CALL SLASRT( 'I', DOU - DOL +1, W(DOL), IINFO )\n IF( IINFO.NE.0 ) THEN\n INFO = 3\n RETURN\n END IF\n ELSE\n DO 60 J = DOL, DOU - 1\n I = 0\n TMP = W( J )\n DO 50 JJ = J + 1, M\n IF( W( JJ ).LT.TMP ) THEN\n I = JJ\n TMP = W( JJ )\n END IF\n 50 CONTINUE\n IF( I.NE.0 ) THEN\n W( I ) = W( J )\n W( J ) = TMP\n IF( WANTZ ) THEN\n CALL SSWAP( N, Z( 1, I-ZOFFSET ), \n $ 1, Z( 1, J-ZOFFSET ), 1 )\n ITMP = ISUPPZ( 2*I-1 )\n ISUPPZ( 2*I-1 ) = ISUPPZ( 2*J-1 )\n ISUPPZ( 2*J-1 ) = ITMP\n ITMP = ISUPPZ( 2*I )\n ISUPPZ( 2*I ) = ISUPPZ( 2*J )\n ISUPPZ( 2*J ) = ITMP\n END IF\n END IF\n 60 CONTINUE\n END IF\n ENDIF\n*\n WORK( 1 ) = LWMIN\n IWORK( 1 ) = LIWMIN\n RETURN\n*\n* End of SSTEGR2\n*\n END\n", "meta": {"hexsha": "3d8e1066f1a27c2fc7be0ba92749344fdc4811b5", "size": 18662, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "SRC/sstegr2.f", "max_stars_repo_name": "jschueller/scalapack", "max_stars_repo_head_hexsha": "3f898b5f1225c9eee271ae6ac6c351ef84f860af", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 64, "max_stars_repo_stars_event_min_datetime": "2019-03-14T16:28:10.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T07:42:43.000Z", "max_issues_repo_path": "SRC/sstegr2.f", "max_issues_repo_name": "jschueller/scalapack", "max_issues_repo_head_hexsha": "3f898b5f1225c9eee271ae6ac6c351ef84f860af", "max_issues_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_issues_count": 55, "max_issues_repo_issues_event_min_datetime": "2018-07-26T20:07:39.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T08:40:38.000Z", "max_forks_repo_path": "SRC/sstegr2.f", "max_forks_repo_name": "jschueller/scalapack", "max_forks_repo_head_hexsha": "3f898b5f1225c9eee271ae6ac6c351ef84f860af", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 44, "max_forks_repo_forks_event_min_datetime": "2018-07-10T18:07:52.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-13T06:54:44.000Z", "avg_line_length": 35.6826003824, "max_line_length": 80, "alphanum_fraction": 0.5260958097, "num_tokens": 5705, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336204, "lm_q2_score": 0.749087201911703, "lm_q1q2_score": 0.6713704333101853}} {"text": "!===============================================================================\n! One of Andy Nowacki's Fortran utility modules for dealing with seismic\n! anisotropy and other problems.\n!\n! Andy Nowacki \n!\n! See the file LICENCE for licence details.\n!===============================================================================\nprogram xyz2lonlat\n!===============================================================================\n! Reads sets of x,y,z from stdin and writes out lon,lat,radius\n\n use spherical_geometry, only: cart2geog\n\n implicit none\n\n real(8) :: lon, lat, r, x, y, z, val, norm_rad\n character(len=250) :: arg\n integer :: iostat\n logical :: norm = .false., value = .false.\n\n! Check input arguments\n call get_args\n \n ! Get coordinates from stdin\n iostat = 0\n do while (iostat == 0)\n if (value) then\n read(*,*,iostat=iostat) x, y, z, val\n else\n read(*,*,iostat=iostat) x, y, z\n endif\n if (iostat < 0) exit\n if (iostat > 0) then\n write(0,'(a)') 'lonlat2xyz: problem reading coordinates from stdin.'\n stop 1\n endif\n call cart2geog(x, y, z, lat, lon, r, degrees=.true.)\n if (norm) r = r*norm_rad\n if (value) then\n write(*,*) lon, lat, r, val\n else\n write(*,*) lon, lat, r\n endif\n enddo\n\ncontains\n !===============================================================================\n subroutine get_args()\n !===============================================================================\n integer :: iarg, narg\n narg = command_argument_count()\n iarg = 1\n do while (iarg <= narg)\n call get_command_argument(iarg, arg)\n select case(arg)\n case('-n')\n norm = .true.\n call get_command_argument(iarg+1, arg)\n read(arg,*) norm_rad\n iarg = iarg + 2\n case('-v')\n value = .true.\n iarg = iarg + 1\n case('-h')\n call usage(.true.)\n case default\n call usage\n end select\n enddo\n end subroutine get_args\n !-------------------------------------------------------------------------------\n\n !===============================================================================\n subroutine usage(help)\n !===============================================================================\n logical, intent(in), optional :: help\n integer :: unit\n unit = 0\n if (present(help)) then\n if (help) unit = 6\n endif\n write(0,'(a)') &\n 'Usage: xyz2lonlat (options) < [x] [y] [z] (value)', &\n 'Reads cartesian coordinates from stdin and writes geographic to stdout.', &\n 'Options:', &\n ' -n [norm] : Scale the points radius by ', &\n ' -v : Output the value in the third/fourth column'\n if (present(help)) then\n if (help) stop\n endif\n error stop\n end subroutine usage\n !-------------------------------------------------------------------------------\n \nend program xyz2lonlat\n!-------------------------------------------------------------------------------\n", "meta": {"hexsha": "23d4ec8228466d1c352dc812a8c0639394a7d1b2", "size": 3225, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "progs/src/xyz2lonlat.f90", "max_stars_repo_name": "JackWalpole/seismo-fortran-fork", "max_stars_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2015-06-23T05:28:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T03:46:07.000Z", "max_issues_repo_path": "progs/src/xyz2lonlat.f90", "max_issues_repo_name": "JackWalpole/seismo-fortran-fork", "max_issues_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2017-05-17T11:02:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-28T09:36:24.000Z", "max_forks_repo_path": "progs/src/xyz2lonlat.f90", "max_forks_repo_name": "JackWalpole/seismo-fortran-fork", "max_forks_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-04-15T02:55:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-20T12:20:51.000Z", "avg_line_length": 32.9081632653, "max_line_length": 85, "alphanum_fraction": 0.4071317829, "num_tokens": 722, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513648201266, "lm_q2_score": 0.7490872075132152, "lm_q1q2_score": 0.6713704321030165}} {"text": " SUBROUTINE ZGBSV_F95( A, B, KL, IPIV, INFO )\n!\n! -- LAPACK95 interface driver routine (version 3.0) --\n! UNI-C, Denmark; Univ. of Tennessee, USA; NAG Ltd., UK\n! September, 2000\n!\n! .. USE STATEMENTS ..\n USE LA_PRECISION, ONLY: WP => DP\n USE LA_AUXMOD, ONLY: ERINFO\n USE F77_LAPACK, ONLY: GBSV_F77 => LA_GBSV\n! .. IMPLICIT STATEMENT ..\n IMPLICIT NONE\n! .. SCALAR ARGUMENTS ..\n INTEGER, INTENT(IN), OPTIONAL :: KL\n INTEGER, INTENT(OUT), OPTIONAL :: INFO\n! .. ARRAY ARGUMENTS ..\n INTEGER, INTENT(OUT), OPTIONAL, TARGET :: IPIV(:)\n COMPLEX(WP), INTENT(INOUT) :: A(:,:), B(:,:)\n!----------------------------------------------------------------------\n! \n! Purpose\n! =======\n! \n! LA_GBSV computes the solution to a real or complex linear system\n! of equations A*X = B, where A is a square band matrix and X and B are\n! rectangular matrices or vectors. The LU decomposition with row\n! interchanges is used to factor A as A = L*U , where L is a product of\n! permutation and unit lower triangular matrices with kl subdiagonals, \n! and U is upper triangular with kl + ku superdiagonals. The factored \n! form of A is then used to solve the above system.\n! \n! =========\n! \n! SUBROUTINE LA_GBSV( AB, B, KL=kl, IPIV=ipiv, INFO=info )\n! (), INTENT(INOUT) :: AB(:,:), \n! INTEGER, INTENT(IN), OPTIONAL :: KL\n! INTEGER, INTENT(OUT), OPTIONAL :: IPIV(:)\n! INTEGER, INTENT(OUT), OPTIONAL :: INFO\n! where\n! ::= REAL | COMPLEX\n! ::= KIND(1.0) | KIND(1.0D0)\n! ::= B(:,:) | B(:)\n! \n! Arguments\n! =========\n! \n! AB (input/output) REAL or COMPLEX rectangular array, shape (:,:)\n! with size(AB,1) = 2*kl+ku+1 and size(AB,2) = n, where kl and ku\n! are, respectively, the numbers of subdiagonals and \n! superdiagonals in the band of A, and n is the order of A.\n! On entry, the matrix A in band storage. The (kl + ku + 1) \n! \t diagonals of A are stored in rows (kl + 1) to (2*kl + ku + 1) \n! \t of AB, so that the j-th column of A is stored in the j-th \n! \t column of AB as follows:\n! \t AB(kl+ku+1+i-j,j) = A(i,j) for max(1,j-ku)<=i<=min(n,j+kl)\n! \t 1<=j<=n\n! The remaining elements in AB need not be set.\n! On exit, details of the factorization. U is an upper triangular \n! band matrix with (kl + ku + 1) diagonals. These are stored in\n! \t the first (kl + ku + 1) rows of AB. The multipliers that arise\n! during the factorization are stored in the remaining rows.\n! B (input/output) REAL or COMPLEX array, shape (:,:) with \n! size(B,1) = n or shape (:) with size(B) = n.\n! On entry, the matrix B.\n! On exit, the solution matrix X.\n! KL Optional (input) INTEGER.\n! The number of subdiagonals in the band of A (KL = kl).\n! The number of superdiagonals in the band is given by\n! \t ku = size(AB,1) - 2 * kl - 1.\n! Default value: (size(AB,1)-1)/3.\n! IPIV Optional (output) INTEGER array, shape (:) with size(IPIV) = n.\n! The pivot indices that define the row interchanges; row i of the\n! matrix was interchanged with row IPIV(i).\n! INFO Optional (output) INTEGER\n! = 0: successful exit.\n! < 0: if INFO = -i, the i-th argument had an illegal value.\n! > 0: if INFO = i, U(i,i) = 0. The factorization has been \n! completed, but the factor U is singular, so the solution could \n! not be computed. \n! If INFO is not present and an error occurs, then the program \n! is terminated with an error message.\n!----------------------------------------------------------------------\n! .. PARAMETERS ..\n CHARACTER(LEN=7), PARAMETER :: SRNAME = 'LA_GBSV'\n! .. LOCAL SCALARS ..\n INTEGER :: LINFO, ISTAT, ISTAT1, SIPIV, LDA, N, NRHS, LKL, KU\n! .. LOCAL POINTERS ..\n INTEGER, POINTER :: LPIV(:)\n! .. INTRINSIC FUNCTIONS ..\n INTRINSIC SIZE, PRESENT\n! .. EXECUTABLE STATEMENTS ..\n LINFO = 0; ISTAT = 0\n LDA = SIZE(A,1); N = SIZE(A,2); NRHS = SIZE(B,2)\n IF( PRESENT(KL) ) THEN; LKL = KL; ELSE; LKL = (LDA-1)/3; ENDIF\n IF( PRESENT(IPIV) )THEN; SIPIV = SIZE(IPIV); ELSE; SIPIV = N; ENDIF\n! .. TEST THE ARGUMENTS\n IF( LDA - 2*LKL -1 < 0 .OR. LDA < 0 .OR. N < 0 ) THEN; LINFO = -1\n ELSE IF( SIZE( B, 1 ) /= N .OR. NRHS < 0 ) THEN; LINFO = -2\n ELSE IF( LDA - 2*LKL -1 < 0 .OR. LKL < 0 ) THEN; LINFO = -3\n ELSE IF( SIPIV /= N )THEN; LINFO = -4\n ELSE IF ( N > 0 ) THEN\n IF( PRESENT(IPIV) )THEN; LPIV => IPIV; ELSE\n ALLOCATE( LPIV(N), STAT = ISTAT ); END IF\n IF ( ISTAT == 0 ) THEN\n KU = LDA -2*LKL -1\n CALL GBSV_F77( N, LKL, KU, NRHS, A, LDA, LPIV, B, N, LINFO )\n ELSE\n LINFO = -100\n END IF\n IF( .NOT.PRESENT(IPIV) )THEN\n DEALLOCATE(LPIV, STAT = ISTAT1 )\n END IF\n END IF\n CALL ERINFO( LINFO, SRNAME, INFO, ISTAT )\n END SUBROUTINE ZGBSV_F95\n", "meta": {"hexsha": "56a14aae58c7ccef64bc6ac8e46661d0501ff46f", "size": 5037, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/la_zgbsv.f90", "max_stars_repo_name": "MattBurn/LAPACK95", "max_stars_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-12-29T15:07:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T10:09:22.000Z", "max_issues_repo_path": "src/la_zgbsv.f90", "max_issues_repo_name": "MattBurn/LAPACK95", "max_issues_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-02-21T10:46:38.000Z", "max_issues_repo_issues_event_max_datetime": "2017-10-20T17:03:14.000Z", "max_forks_repo_path": "src/la_zgbsv.f90", "max_forks_repo_name": "MattBurn/LAPACK95", "max_forks_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-12-29T15:34:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-15T07:12:40.000Z", "avg_line_length": 43.4224137931, "max_line_length": 74, "alphanum_fraction": 0.559459996, "num_tokens": 1621, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513620489619, "lm_q2_score": 0.7490872075132153, "lm_q1q2_score": 0.6713704300271727}} {"text": " MODULE cdf_normal_mod\n! ----------------------------------------------------------------------\n\n! cdf_normal_mod\n! *=*=*=*=*=*=*=\n\n! - SUBROUTINE CDF_NORMAL(WHICH, CUM, CCUM, X, MEAN, SD, STATUS, CHECK_INPUT)\n! - REAL (dpkind) FUNCTION CUM_NORMAL(X, MEAN, SD, STATUS, CHECK_INPUT)\n! - REAL (dpkind) FUNCTION CCUM_NORMAL(X, MEAN, SD, STATUS, CHECK_INPUT)\n! - REAL (dpkind) FUNCTION INV_NORMAL(CUM, CCUM, MEAN, SD, STATUS,\n! CHECK_INPUT)\n\n! The Distribution\n! ================\n\n! The density of the normal distribution is proportional to:\n\n! ( 2)\n! ( (X-MEAN) )\n! exp(----------)\n! ( 2 )\n! ( 2 SD )\n\n! Arguments\n! =========\n\n! - INTEGER, INTENT(IN) :: WHICH. Integer indicating which of the next\n! arguments is to be calculated.\n! Input Range: [ 1:4 ]\n! 1. CUM and CCUM\n! 2. X\n! 3. MEAN\n! 4. SD\n! - REAL (dpkind), OPTIONAL :: CUM. The CDF of the normal distribution.\n! Range: [ 10^-10:1-10^-10 ]\n! - REAL (dpkind), OPTIONAL :: CCUM. One minus the CDF of the normal\n! distribution.\n! Range: [ 10^-10:1-10^-10 ]\n! - REAL (dpkind) :: X. The upper limit of integration of the normal\n! density. The lower limit is -oo.\n! Range: [ -10^100:10^100 ]\n! - REAL (dpkind), OPTIONAL:: MEAN. The mean of the normal distribution.\n! If omitted, the value 0 is used.\n! Range: [ -10^100:10^100 ]\n! - REAL (dpkind), OPTIONAL:: SD. The standard deviation of the normal\n! distribution. If omitted, the value 1 is used.\n! Range: [ 10^-10:10^100 ]\n! - INTEGER, INTENT(OUT), OPTIONAL :: STATUS. Return code. Possible values:\n! -1 WHICH outside input range\n! -2 CUM outside range\n! -3 CCUM outside range\n! -4 X outside range\n! -5 MEAN outside range\n! -6 SD outside range\n! 3 CUM + CCUM is not nearly one\n! - LOGICAL, INTENT(IN), OPTIONAL :: CHECK_INPUT. If PRESENT and .TRUE.\n! input argument values are not checked for validity.\n! ----------------------------------------------------------------------\n! .. Use Statements ..\n USE biomath_constants_mod\n USE biomath_mathlib_mod\n USE cdf_aux_mod\n! ..\n! .. Default Accessibility ..\n PRIVATE\n! ..\n! .. Public Statements ..\n PUBLIC :: ccum_normal, cdf_normal, cum_normal, inv_normal\n! ..\n CONTAINS\n\n!*********************************************************************\n\n FUNCTION ccum_normal(x,mean,sd,status,check_input)\n! .. Function Return Value ..\n REAL (dpkind) :: ccum_normal\n! ..\n! .. Scalar Arguments ..\n REAL (dpkind), OPTIONAL :: mean, sd\n REAL (dpkind) :: x\n INTEGER, OPTIONAL, INTENT (OUT) :: status\n LOGICAL, OPTIONAL, INTENT (IN) :: check_input\n! ..\n CALL cdf_normal(which=1,ccum=ccum_normal,x=x,mean=mean,sd=sd, &\n status=status,check_input=check_input)\n\n RETURN\n\n END FUNCTION ccum_normal\n\n!*********************************************************************\n\n SUBROUTINE cdf_normal(which,cum,ccum,x,mean,sd,status,check_input)\n! .. Scalar Arguments ..\n REAL (dpkind), OPTIONAL :: ccum, cum, mean, sd\n REAL (dpkind) :: x\n INTEGER, OPTIONAL, INTENT (OUT) :: status\n INTEGER, INTENT (IN) :: which\n LOGICAL, OPTIONAL, INTENT (IN) :: check_input\n! ..\n! .. Local Arrays ..\n REAL (dpkind) :: params(6)\n! ..\n! .. Local Scalars ..\n REAL (dpkind) :: local_ccum, local_cum, local_mean, local_sd, z\n LOGICAL :: has_status, local_check_input\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC PRESENT\n! ..\n has_status = PRESENT(status)\n\n! status = 0 means NO error\n\n IF (has_status) THEN\n status = 0\n END IF\n\n! Check presence of arguments and fix up\n\n CALL check_complements(cum,ccum,the_normal%name,'cum','ccum', &\n local_cum,local_ccum,set_values=which/=1,bad_status=3, &\n status=status)\n\n IF (has_status) THEN\n IF (status/=0) THEN\n RETURN\n END IF\n END IF\n\n\n IF (PRESENT(mean)) THEN\n local_mean = mean\n ELSE\n local_mean = zero\n END IF\n\n IF (PRESENT(sd)) THEN\n local_sd = sd\n ELSE\n local_sd = one\n END IF\n\n params(1) = local_cum\n params(2) = local_ccum\n params(3) = x\n params(4) = local_mean\n params(5) = local_sd\n\n IF (PRESENT(check_input)) THEN\n local_check_input = check_input\n ELSE\n local_check_input = .TRUE.\n END IF\n\n!!! Check for consistency of which and answer\n\n IF (local_check_input) THEN\n\n IF (which==3 .AND. .NOT. PRESENT(mean)) CALL which_miss(which, &\n the_normal%name,'mean')\n\n IF (which==4 .AND. .NOT. PRESENT(sd)) CALL which_miss(which, &\n the_normal%name,'sd')\n\n CALL validate_parameters(the_normal,which,params,status)\n\n IF (has_status) THEN\n IF (status/=0) THEN\n RETURN\n END IF\n END IF\n\n END IF\n\n! ++++++++++ ++++++++++ ++++++++++\n! Compute the Answers\n! ++++++++++ ++++++++++ ++++++++++\n\n SELECT CASE (which)\n CASE (1)\n z = (x-local_mean)/local_sd\n\n CALL local_cum_normal(z,local_cum,local_ccum)\n\n IF (PRESENT(cum)) cum = local_cum\n IF (PRESENT(ccum)) ccum = local_ccum\n\n CASE (2)\n z = local_inv_normal(local_cum,local_ccum)\n\n x = local_sd*z + local_mean\n\n CASE (3)\n z = local_inv_normal(local_cum,local_ccum)\n\n mean = x - local_sd*z\n\n CASE (4)\n z = local_inv_normal(local_cum,local_ccum)\n\n sd = (x-local_mean)/z\n END SELECT\n\n END SUBROUTINE cdf_normal\n\n!*********************************************************************\n\n FUNCTION cum_normal(x,mean,sd,status,check_input)\n! .. Function Return Value ..\n REAL (dpkind) :: cum_normal\n! ..\n! .. Scalar Arguments ..\n REAL (dpkind), OPTIONAL :: mean, sd\n REAL (dpkind) :: x\n INTEGER, OPTIONAL, INTENT (OUT) :: status\n LOGICAL, OPTIONAL, INTENT (IN) :: check_input\n! ..\n CALL cdf_normal(which=1,cum=cum_normal,x=x,mean=mean,sd=sd, &\n status=status,check_input=check_input)\n\n RETURN\n\n END FUNCTION cum_normal\n\n!*********************************************************************\n\n FUNCTION inv_normal(cum,ccum,mean,sd,status,check_input)\n! .. Function Return Value ..\n REAL (dpkind) :: inv_normal\n! ..\n! .. Scalar Arguments ..\n REAL (dpkind), OPTIONAL :: ccum, cum, mean, sd\n INTEGER, OPTIONAL, INTENT (OUT) :: status\n LOGICAL, OPTIONAL, INTENT (IN) :: check_input\n! ..\n CALL cdf_normal(which=2,cum=cum,ccum=ccum,x=inv_normal,mean=mean, &\n sd=sd,status=status,check_input=check_input)\n\n RETURN\n\n END FUNCTION inv_normal\n\n!*********************************************************************\n\n SUBROUTINE local_cum_normal(arg,result,ccum)\n!----------------------------------------------------------------------\n\n! Function\n\n! Computes the cumulative of the normal distribution, i.e.,\n! the integral from -infinity to x of\n! (1/sqrt(2*pi)) exp(-u*u/2) du\n! X --> Upper limit of integration.\n! X is DOUBLE PRECISION\n! RESULT <-- Cumulative normal distribution.\n! RESULT is DOUBLE PRECISION\n! CCUM <-- Compliment of Cumulative normal distribution.\n! CCUM is DOUBLE PRECISION\n! Renaming of function ANORM from:\n! Cody, W.D. (1993). \"ALGORITHM 715: SPECFUN - A Portabel FORTRAN\n! Package of Special Function Routines and Test Drivers\"\n! acm Transactions on Mathematical Software. 19, 22-32.\n! with slight modifications to return ccum and to deal with\n! machine constants.\n!----------------------------------------------------------------------\n! Original Comments:\n!------------------------------------------------------------------\n! This function evaluates the normal distribution function:\n! / x\n! 1 | -t*t/2\n! P(x) = ----------- | e dt\n! sqrt(2 pi) |\n! /-oo\n! The main computation evaluates near-minimax approximations\n! derived from those in \"Rational Chebyshev approximations for\n! the error function\" by W. J. Cody, Math. Comp., 1969, 631-637.\n! This transportable program uses rational functions that\n! theoretically approximate the normal distribution function to\n! at least 18 significant decimal digits. The accuracy achieved\n! depends on the arithmetic system, the compiler, the intrinsic\n! functions, and proper selection of the machine-dependent\n! constants.\n!*******************************************************************\n!*******************************************************************\n! Explanation of machine-dependent constants.\n! MIN = smallest machine representable number.\n! EPS = argument below which anorm(x) may be represented by\n! 0.5 and above which x*x will not underflow.\n! A conservative value is the largest machine number X\n! such that 1.0 + X = 1.0 to machine precision.\n!*******************************************************************\n!*******************************************************************\n! Error returns\n! The program returns ANORM = 0 for ARG .LE. XLOW.\n! Intrinsic functions required are:\n! ABS, AINT, EXP\n! Author: W. J. Cody\n! Mathematics and Computer Science Division\n! Argonne National Laboratory\n! Argonne, IL 60439\n! Latest modification: March 15, 1992\n!------------------------------------------------------------------\n!------------------------------------------------------------------\n! Mathematical constants\n! SQRPI = 1 / sqrt(2*pi), ROOT32 = sqrt(32), and\n! THRSH is the argument for which anorm = 0.75.\n!------------------------------------------------------------------\n!------------------------------------------------------------------\n! Coefficients for approximation in first interval\n!------------------------------------------------------------------\n!------------------------------------------------------------------\n! Coefficients for approximation in second interval\n!------------------------------------------------------------------\n!------------------------------------------------------------------\n! Coefficients for approximation in third interval\n!------------------------------------------------------------------\n! .. Scalar Arguments ..\n REAL (dpkind) :: arg, ccum, result\n! ..\n! .. Local Scalars ..\n REAL (dpkind) :: del, eps, min, temp, x, xden, xnum, xsq, y\n INTEGER :: i\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC ABS, AINT, EPSILON, EXP, TINY\n! ..\n! .. Parameters ..\n REAL (dpkind), PARAMETER :: a(5) = (/ &\n 2.2352520354606839287E00_dpkind, &\n 1.6102823106855587881E02_dpkind, &\n 1.0676894854603709582E03_dpkind, &\n 1.8154981253343561249E04_dpkind, &\n 6.5682337918207449113E-2_dpkind/)\n REAL (dpkind), PARAMETER :: b(4) = (/ &\n 4.7202581904688241870E01_dpkind, &\n 9.7609855173777669322E02_dpkind, &\n 1.0260932208618978205E04_dpkind, &\n 4.5507789335026729956E04_dpkind/)\n REAL (dpkind), PARAMETER :: c(9) = (/ &\n 3.9894151208813466764E-1_dpkind, &\n 8.8831497943883759412E00_dpkind, &\n 9.3506656132177855979E01_dpkind, &\n 5.9727027639480026226E02_dpkind, &\n 2.4945375852903726711E03_dpkind, &\n 6.8481904505362823326E03_dpkind, &\n 1.1602651437647350124E04_dpkind, &\n 9.8427148383839780218E03_dpkind, &\n 1.0765576773720192317E-8_dpkind/)\n REAL (dpkind), PARAMETER :: d(8) = (/ &\n 2.2266688044328115691E01_dpkind, &\n 2.3538790178262499861E02_dpkind, &\n 1.5193775994075548050E03_dpkind, &\n 6.4855582982667607550E03_dpkind, &\n 1.8615571640885098091E04_dpkind, &\n 3.4900952721145977266E04_dpkind, &\n 3.8912003286093271411E04_dpkind, &\n 1.9685429676859990727E04_dpkind/)\n REAL (dpkind), PARAMETER :: p(6) = (/ &\n 2.1589853405795699E-1_dpkind, 1.274011611602473639E-1_dpkind, &\n 2.2235277870649807E-2_dpkind, 1.421619193227893466E-3_dpkind, &\n 2.9112874951168792E-5_dpkind, 2.307344176494017303E-2_dpkind/)\n REAL (dpkind), PARAMETER :: q(5) = (/ &\n 1.28426009614491121E00_dpkind, 4.68238212480865118E-1_dpkind, &\n 6.59881378689285515E-2_dpkind, 3.78239633202758244E-3_dpkind, &\n 7.29751555083966205E-5_dpkind/)\n REAL (dpkind), PARAMETER :: root32 = 5.656854248E0_dpkind\n REAL (dpkind), PARAMETER :: sixten = 1.6_dpkind\n REAL (dpkind), PARAMETER :: sqrpi = &\n 3.9894228040143267794E-1_dpkind\n REAL (dpkind), PARAMETER :: thrsh = 0.66291E0_dpkind\n! ..\n!------------------------------------------------------------------\n! Machine dependent constants\n!------------------------------------------------------------------\n! eps = spmpar(1)*0.5E0_dpkind\n eps = EPSILON(one)*half\n! min = spmpar(2)\n min = TINY(one)\n!------------------------------------------------------------------\n x = arg\n y = ABS(x)\n IF (y<=thrsh) THEN\n!------------------------------------------------------------------\n! Evaluate anorm for |X| <= 0.66291\n!------------------------------------------------------------------\n xsq = zero\n IF (y>eps) xsq = x*x\n xnum = a(5)*xsq\n xden = xsq\n xnum = (xnum+a(1))*xsq\n xden = (xden+b(1))*xsq\n xnum = (xnum+a(2))*xsq\n xden = (xden+b(2))*xsq\n xnum = (xnum+a(3))*xsq\n xden = (xden+b(3))*xsq\n result = x*(xnum+a(4))/(xden+b(4))\n temp = result\n result = half + temp\n ccum = half - temp\n!------------------------------------------------------------------\n! Evaluate anorm for 0.66291 <= |X| <= sqrt(32)\n!------------------------------------------------------------------\n ELSE IF (y<=root32) THEN\n xnum = c(9)*y\n xden = y\n\n DO i = 1, 7\n xnum = (xnum+c(i))*y\n xden = (xden+d(i))*y\n END DO\n\n result = (xnum+c(8))/(xden+d(8))\n xsq = AINT(y*sixten)/sixten\n del = (y-xsq)*(y+xsq)\n result = EXP(-xsq*xsq*half)*EXP(-del*half)*result\n ccum = one - result\n\n IF (x>zero) THEN\n temp = result\n result = ccum\n ccum = temp\n END IF\n\n!------------------------------------------------------------------\n! Evaluate anorm for |X| > sqrt(32)\n!------------------------------------------------------------------\n ELSE\n result = zero\n xsq = one/(x*x)\n xnum = p(6)*xsq\n xden = xsq\n xnum = (xnum+p(1))*xsq\n xden = (xden+q(1))*xsq\n xnum = (xnum+p(2))*xsq\n xden = (xden+q(2))*xsq\n xnum = (xnum+p(3))*xsq\n xden = (xden+q(3))*xsq\n xnum = (xnum+p(4))*xsq\n xden = (xden+q(4))*xsq\n result = xsq*(xnum+p(5))/(xden+q(5))\n result = (sqrpi-result)/y\n xsq = AINT(x*sixten)/sixten\n del = (x-xsq)*(x+xsq)\n result = EXP(-xsq*xsq*half)*EXP(-del*half)*result\n ccum = one - result\n\n IF (x>zero) THEN\n temp = result\n result = ccum\n ccum = temp\n END IF\n\n END IF\n\n IF (result\n! Speed test for 1d-6d tensor product b-spline interpolation (object-oriented version).\n!\n!### Results\n! ![Plot of results](https://raw.githubusercontent.com/jacobwilliams/bspline-fortran/master/src/tests/results/speed_test_oo.png)\n\n program bspline_speed_test_oo\n\n use bspline_module\n use bspline_kinds_module, only: wp, ip\n use pyplot_module\n use, intrinsic :: iso_fortran_env\n\n implicit none\n\n integer(ip),parameter :: nx = 8_ip !number of points\n integer(ip),parameter :: ny = 8_ip\n integer(ip),parameter :: nz = 8_ip\n integer(ip),parameter :: nq = 8_ip\n integer(ip),parameter :: nr = 8_ip\n integer(ip),parameter :: ns = 8_ip\n\n integer(ip),parameter :: kx = 4_ip !order\n integer(ip),parameter :: ky = 4_ip\n integer(ip),parameter :: kz = 4_ip\n integer(ip),parameter :: kq = 4_ip\n integer(ip),parameter :: kr = 4_ip\n integer(ip),parameter :: ks = 4_ip\n\n integer(ip),parameter :: n_cases = nx*ny*nz*nq*nr*ns\n\n real(wp) :: x(nx),y(ny),z(nz),q(nq),r(nr),s(ns)\n real(wp) :: fcn_1d(nx)\n real(wp) :: fcn_2d(nx,ny)\n real(wp) :: fcn_3d(nx,ny,nz)\n real(wp) :: fcn_4d(nx,ny,nz,nq)\n real(wp) :: fcn_5d(nx,ny,nz,nq,nr)\n real(wp) :: fcn_6d(nx,ny,nz,nq,nr,ns)\n\n type(bspline_1d) :: s1\n type(bspline_2d) :: s2\n type(bspline_3d) :: s3\n type(bspline_4d) :: s4\n type(bspline_5d) :: s5\n type(bspline_6d) :: s6\n\n real(wp) :: val,sumval\n integer(ip) :: i,j,k,l,m,n,idx,idy,idz,idq,idr,ids,iflag\n real :: tstart, tend\n type(pyplot) :: plt\n real(wp),dimension(6) :: cases_per_sec\n integer :: istat !! pyplot-fortran status flag\n\n idx = 0_ip\n idy = 0_ip\n idz = 0_ip\n idq = 0_ip\n idr = 0_ip\n ids = 0_ip\n\n x = [ (real(i,wp), i=1,nx) ]\n y = [ (real(i,wp), i=1,ny) ]\n z = [ (real(i,wp), i=1,nz) ]\n q = [ (real(i,wp), i=1,nq) ]\n r = [ (real(i,wp), i=1,nr) ]\n s = [ (real(i,wp), i=1,ns) ]\n\n !evaluate the functions:\n\n do i=1,nx\n fcn_1d(i) = f1(x(i))\n do j=1,ny\n fcn_2d(i,j) = f2(x(i),y(j))\n do k=1,nz\n fcn_3d(i,j,k) = f3(x(i),y(j),z(k))\n do l=1,nq\n fcn_4d(i,j,k,l) = f4(x(i),y(j),z(k),q(l))\n do m=1,nr\n fcn_5d(i,j,k,l,m) = f5(x(i),y(j),z(k),q(l),r(m))\n do n=1,ns\n fcn_6d(i,j,k,l,m,n) = f6(x(i),y(j),z(k),q(l),r(m),s(n))\n end do\n end do\n end do\n end do\n end do\n end do\n\n !initialize using the constructors:\n\n s1 = bspline_1d(x,fcn_1d,kx) ; if (.not. s1%status_ok()) error stop 'error initializing s1'\n s2 = bspline_2d(x,y,fcn_2d,kx,ky) ; if (.not. s1%status_ok()) error stop 'error initializing s2'\n s3 = bspline_3d(x,y,z,fcn_3d,kx,ky,kz) ; if (.not. s1%status_ok()) error stop 'error initializing s3'\n s4 = bspline_4d(x,y,z,q,fcn_4d,kx,ky,kz,kq) ; if (.not. s1%status_ok()) error stop 'error initializing s4'\n s5 = bspline_5d(x,y,z,q,r,fcn_5d,kx,ky,kz,kq,kr) ; if (.not. s1%status_ok()) error stop 'error initializing s5'\n s6 = bspline_6d(x,y,z,q,r,s,fcn_6d,kx,ky,kz,kq,kr,ks); if (.not. s1%status_ok()) error stop 'error initializing s6'\n\n ! evaluate the interpolants:\n sumval = 0.0_wp\n call cpu_time(tstart)\n do i=1,nx\n do j=1,ny\n do k=1,nz\n do l=1,nq\n do m=1,nr\n do n=1,ns\n call s1%evaluate(x(i),idx,val,iflag)\n sumval = sumval + val\n end do\n end do\n end do\n end do\n end do\n end do\n call cpu_time(tend)\n write(*,*) ''\n write(*,*) '1D'\n write(*,*) 'result :', sumval\n write(*,*) 'number of cases:', n_cases\n write(*,*) 'cases/sec :', n_cases/(tend-tstart)\n cases_per_sec(1) = n_cases/(tend-tstart)\n\n sumval = 0.0_wp\n call cpu_time(tstart)\n do i=1,nx\n do j=1,ny\n do k=1,nz\n do l=1,nq\n do m=1,nr\n do n=1,ns\n call s2%evaluate(x(i),y(j),idx,idy,val,iflag)\n sumval = sumval + val\n end do\n end do\n end do\n end do\n end do\n end do\n call cpu_time(tend)\n write(*,*) ''\n write(*,*) '2D'\n write(*,*) 'result :', sumval\n write(*,*) 'number of cases:', n_cases\n write(*,*) 'cases/sec :', n_cases/(tend-tstart)\n cases_per_sec(2) = n_cases/(tend-tstart)\n\n sumval = 0.0_wp\n call cpu_time(tstart)\n do i=1,nx\n do j=1,ny\n do k=1,nz\n do l=1,nq\n do m=1,nr\n do n=1,ns\n call s3%evaluate(x(i),y(j),z(k),idx,idy,idz,val,iflag)\n sumval = sumval + val\n end do\n end do\n end do\n end do\n end do\n end do\n call cpu_time(tend)\n write(*,*) ''\n write(*,*) '3D'\n write(*,*) 'result :', sumval\n write(*,*) 'number of cases:', n_cases\n write(*,*) 'cases/sec :', n_cases/(tend-tstart)\n cases_per_sec(3) = n_cases/(tend-tstart)\n\n sumval = 0.0_wp\n call cpu_time(tstart)\n do i=1,nx\n do j=1,ny\n do k=1,nz\n do l=1,nq\n do m=1,nr\n do n=1,ns\n call s4%evaluate(x(i),y(j),z(k),q(l),idx,idy,idz,idq,val,iflag)\n sumval = sumval + val\n end do\n end do\n end do\n end do\n end do\n end do\n call cpu_time(tend)\n write(*,*) ''\n write(*,*) '4D'\n write(*,*) 'result :', sumval\n write(*,*) 'number of cases:', n_cases\n write(*,*) 'cases/sec :', n_cases/(tend-tstart)\n cases_per_sec(4) = n_cases/(tend-tstart)\n\n sumval = 0.0_wp\n call cpu_time(tstart)\n do i=1,nx\n do j=1,ny\n do k=1,nz\n do l=1,nq\n do m=1,nr\n do n=1,ns\n call s5%evaluate(x(i),y(j),z(k),q(l),r(m),idx,idy,idz,idq,idr,val,iflag)\n sumval = sumval + val\n end do\n end do\n end do\n end do\n end do\n end do\n call cpu_time(tend)\n write(*,*) ''\n write(*,*) '5D'\n write(*,*) 'result :', sumval\n write(*,*) 'number of cases:', n_cases\n write(*,*) 'cases/sec :', n_cases/(tend-tstart)\n cases_per_sec(5) = n_cases/(tend-tstart)\n\n sumval = 0.0_wp\n call cpu_time(tstart)\n do i=1,nx\n do j=1,ny\n do k=1,nz\n do l=1,nq\n do m=1,nr\n do n=1,ns\n call s6%evaluate(x(i),y(j),z(k),q(l),r(m),s(n),idx,idy,idz,idq,idr,ids,val,iflag)\n sumval = sumval + val\n end do\n end do\n end do\n end do\n end do\n end do\n call cpu_time(tend)\n write(*,*) ''\n write(*,*) '6D'\n write(*,*) 'result :', sumval\n write(*,*) 'number of cases:', n_cases\n write(*,*) 'cases/sec :', n_cases/(tend-tstart)\n cases_per_sec(6) = n_cases/(tend-tstart)\n\n !plot results in bar chart:\n call plt%initialize(grid=.false.,xlabel='Dimension',ylabel='Cases Per Second',&\n title='Speed Test (Object-Oriented Interface)',legend=.false.,&\n font_size = 20,&\n axes_labelsize = 20,&\n xtick_labelsize = 20,&\n ytick_labelsize = 20)\n call plt%add_bar(x=real([1,2,3,4,5,6],real64),height=real(cases_per_sec,real64),&\n label='Speed test runs',&\n yscale='log',align='center',color='r',istat=istat)\n call plt%savefig('speed_test_oo.png',istat=istat)\n\n contains\n\n function f1(x) result(f) !! 1d test function\n implicit none\n real(wp),intent(in) :: x\n real(wp) :: f\n f = x**1.1_wp + x**1.2_wp + x**1.3_wp + x**1.4_wp + x**1.5_wp + x**1.6_wp\n end function f1\n\n function f2(x,y) result(f) !! 2d test function\n implicit none\n real(wp),intent(in) :: x,y\n real(wp) :: f\n f = x**1.1_wp + y**1.2_wp + x**1.3_wp + y**1.4_wp + x**1.5_wp + y**1.6_wp\n end function f2\n\n function f3 (x,y,z) result(f) !! 3d test function\n implicit none\n real(wp),intent(in) :: x,y,z\n real(wp) :: f\n f = x**1.1_wp + y**1.2_wp + z**1.3_wp + x**1.4_wp + y**1.5_wp + z**1.6_wp\n end function f3\n\n function f4 (x,y,z,q) result(f) !! 4d test function\n implicit none\n real(wp),intent(in) :: x,y,z,q\n real(wp) :: f\n f = x**1.1_wp + y**1.2_wp + z**1.3_wp + q**1.4_wp + x**1.5_wp + y**1.6_wp\n end function f4\n\n function f5 (x,y,z,q,r) result(f) !! 5d test function\n implicit none\n real(wp),intent(in) :: x,y,z,q,r\n real(wp) :: f\n f = x**1.1_wp + y**1.2_wp + z**1.3_wp + q**1.4_wp + r**1.5_wp + x**1.6_wp\n end function f5\n\n function f6 (x,y,z,q,r,s) result(f) !! 6d test function\n implicit none\n real(wp),intent(in) :: x,y,z,q,r,s\n real(wp) :: f\n f = x**1.1_wp + y**1.2_wp + z**1.3_wp + q**1.4_wp + r**1.5_wp + s**1.6_wp\n end function f6\n\n end program bspline_speed_test_oo\n", "meta": {"hexsha": "07e71803d4f930591667177989ade0d9931a0103", "size": 9846, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/speed_test_oo.f90", "max_stars_repo_name": "jacobwilliams/bspline-fortran", "max_stars_repo_head_hexsha": "5c0f836e0043e51d86420f321f607ff8ae21ca98", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 139, "max_stars_repo_stars_event_min_datetime": "2015-02-25T08:11:20.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T17:33:50.000Z", "max_issues_repo_path": "src/tests/speed_test_oo.f90", "max_issues_repo_name": "jacobwilliams/bspline-fortran", "max_issues_repo_head_hexsha": "5c0f836e0043e51d86420f321f607ff8ae21ca98", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 46, "max_issues_repo_issues_event_min_datetime": "2015-06-19T18:25:15.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T21:14:15.000Z", "max_forks_repo_path": "src/tests/speed_test_oo.f90", "max_forks_repo_name": "jacobwilliams/bspline-fortran", "max_forks_repo_head_hexsha": "5c0f836e0043e51d86420f321f607ff8ae21ca98", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 51, "max_forks_repo_forks_event_min_datetime": "2015-09-17T16:52:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-26T03:18:28.000Z", "avg_line_length": 32.7109634551, "max_line_length": 129, "alphanum_fraction": 0.4699370303, "num_tokens": 3216, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619885, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6713429214581469}} {"text": "program pgm\ninteger :: a(3,3,3), i , j, k, c\n\nc = 1\ndo i = 1, 3\ndo j = 1, 3\ndo k = 1, 3\n a(j,i,k) = c\n c = c + 1\nenddo\nenddo\nenddo\n\ndo k = 1, 3\ndo j = 1, 3\ndo i = 1, 3\n if (a(k,j,i) <= a(i,j,k)) then\n print *, a(k,j,i)\n endif\nenddo\nenddo\nenddo\nend\n", "meta": {"hexsha": "d73d8e304410a677c7549783e3888a30b8dbeace", "size": 249, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/mlir_out_tests/array_multidim3.f90", "max_stars_repo_name": "clementval/fc", "max_stars_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/mlir_out_tests/array_multidim3.f90", "max_issues_repo_name": "clementval/fc", "max_issues_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/mlir_out_tests/array_multidim3.f90", "max_forks_repo_name": "clementval/fc", "max_forks_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "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": 10.375, "max_line_length": 32, "alphanum_fraction": 0.5060240964, "num_tokens": 141, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6713429157667155}} {"text": "subroutine compute_surface_tension(nx, ny, surfactant, surface_tension)\n implicit none\n double precision :: beta, kappa, delta, mu, right_film_height\n common /surfactant_config/ beta, kappa, delta, mu, right_film_height\n\n integer, intent(in) :: nx, ny\n double precision, dimension(nx, ny), intent(in) :: surfactant\n double precision, dimension(nx, ny), intent(out) :: surface_tension\n\n integer :: ix, iy\n\n do iy = 1, ny\n do ix = 1, nx\n ! surface_tension(ix, iy) = (1.d0 + mu * surfactant(ix, iy))**(-3)\n surface_tension(ix, iy) = 1.d0 - surfactant(ix, iy)\n end do\n end do\nend subroutine compute_surface_tension\n\n\nsubroutine compute_surface_tension_d1(nx, ny, surfactant, surface_tension_d1)\n implicit none\n double precision :: beta, kappa, delta, mu, right_film_height\n common /surfactant_config/ beta, kappa, delta, mu, right_film_height\n\n integer, intent(in) :: nx, ny\n double precision, dimension(nx, ny), intent(in) :: surfactant\n double precision, dimension(nx, ny), intent(out) :: surface_tension_d1\n\n integer :: ix, iy\n\n do iy = 1, ny\n do ix = 1, nx\n ! surface_tension_d1(ix, iy) = -3.d0 * mu * (1.d0 + mu * surfactant(ix, iy))**(-4)\n surface_tension_d1(ix, iy) = -1.d0\n end do\n end do\nend subroutine compute_surface_tension_d1\n", "meta": {"hexsha": "b810d7f9188110bc4c1b930b3b013034f540796b", "size": 1361, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "applications/2d/Surfactant/surface_tension_utils.f90", "max_stars_repo_name": "claridge/implicit_solvers", "max_stars_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-04-29T00:16:18.000Z", "max_stars_repo_stars_event_max_datetime": "2017-04-29T00:16:18.000Z", "max_issues_repo_path": "applications/2d/Surfactant/surface_tension_utils.f90", "max_issues_repo_name": "claridge/implicit_solvers", "max_issues_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "applications/2d/Surfactant/surface_tension_utils.f90", "max_forks_repo_name": "claridge/implicit_solvers", "max_forks_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.8974358974, "max_line_length": 94, "alphanum_fraction": 0.654665687, "num_tokens": 400, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942119105695, "lm_q2_score": 0.743168019989179, "lm_q1q2_score": 0.6712993709332639}} {"text": "-- Recursive types: list.\n\nNatList = Rec X. ;\n\n-- Some built-in operators on lists from simpler parts:\n\n-- A constant nil:\nnil = as NatList;\n\n-- A constructor cons for adding an element to the front\n-- of an existing list:\ncons = lambda n: Nat. lambda l: NatList. as NatList;\n\n-- An isnil operation and destructors hd and tl for extracting\n-- the head and tail of a non-empty list (in terms of case):\nisnil = lambda l: NatList. case l of\n ==> true\n | ==> false;\n\nhd = lambda l: NatList. case l of\n ==> 0\n | ==> p.1;\n\ntl = lambda l: NatList. case l of\n ==> l\n | ==> (p.2) as NatList;\n\n-- Example:\n\nplus = fix (lambda s: Nat -> Nat -> Nat.\n lambda x: Nat. lambda y: Nat.\n if iszero y\n then x\n else s (succ x) (pred y));\n\nsumlist = fix (lambda s: NatList -> Nat. lambda l: NatList.\n if isnil l then 0 else plus (hd l) (s (tl l)));\n\nmylist = cons 2 (cons 3 (cons 5 nil));\nsumlist mylist;\n", "meta": {"hexsha": "dafa0f764c1fe7e2553978e38dda2521d693060a", "size": 1231, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "test/test_26.f", "max_stars_repo_name": "brunoflores/fulluntyped", "max_stars_repo_head_hexsha": "657b44574ecb5915f0af29414fcd87a063ba4def", "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": "test/test_26.f", "max_issues_repo_name": "brunoflores/fulluntyped", "max_issues_repo_head_hexsha": "657b44574ecb5915f0af29414fcd87a063ba4def", "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": "test/test_26.f", "max_forks_repo_name": "brunoflores/fulluntyped", "max_forks_repo_head_hexsha": "657b44574ecb5915f0af29414fcd87a063ba4def", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.0243902439, "max_line_length": 70, "alphanum_fraction": 0.5044679123, "num_tokens": 337, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.903294209307224, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6712993638602881}} {"text": "program MaxwellModel\n implicit none\n integer :: N, i, j, k, l, m,p\n real, allocatable :: G(:), tau(:), ni(:), kl(:), kd(:)\n real :: ni0, produkt, vsota, dt\n real :: t, e, e1, e2, e3, e4, e5, de,de1,de2,de3,de4,de5, sigma, napetost\n real :: k1e,k2e,k3e,k4e\n real :: k1e1,k2e1,k3e1,k4e1\n real :: k1e2,k2e2,k3e2,k4e2\n real :: k1e3,k2e3,k3e3,k4e3\n real :: k1e4,k2e4,k3e4,k4e4\n real :: k1e5,k2e5,k3e5,k4e5\n\n N = 6\n allocate(G(N))\n allocate(tau(N))\n allocate(ni(N))\n allocate(kl(N))\n allocate(kd(N))\n\n\n ni0 = 1.0\n dt = 0.01\n\n G = (/0.01,0.005,0.0005,1.0,3.0,0.00069/)\n tau = (/1.1,1.2,1.3,1.4,1.5,1.1/)\n ni = tau*G\n kl = 0.0\n kd = 0.0\n\n\n do i = 1, N\n kd(1) = kd(1) + G(i)*tau(i)\n end do\n\n do i = 1, N-1\n do j = i+1, N\n vsota = G(i)+G(j)\n produkt = tau(i)*tau(j)\n kd(2) = kd(2) + vsota*produkt\n end do\n end do\n\n do i = 1, N-2\n do j = i+1, N-2\n do k = j+1, N\n vsota = G(i)+G(j)+G(k)\n produkt = tau(i)*tau(j)*tau(k)\n kd(3) = kd(3) + vsota*produkt\n end do\n end do\n end do\n\n do i = 1, N-3\n do j = i+1, N-2\n do k = j+1, N-1\n do l = k+1, N\n vsota = G(i)+G(j)+G(k)+G(l)\n produkt = tau(i)*tau(j)*tau(k)*tau(l)\n kd(4) = kd(4) + vsota*produkt\n end do\n end do\n end do\n end do\n\n do i = 1, N-4\n do j = i+1, N-3\n do k = j+1, N-2\n do l = k+1, N-1\n do m = l+1, N\n vsota = G(i)+G(j)+G(k)+G(l)+G(m)\n produkt = tau(i)*tau(j)*tau(k)*tau(l)*tau(m)\n kd(5) = kd(5) + vsota*produkt\n end do\n end do\n end do\n end do\n end do\n\n do i = 1, N-5\n do j = i+1, N-4\n do k = j+1, N-3\n do l = k+1, N-2\n do m = l+1, N-1\n do p = m+1, N\n vsota = G(i)+G(j)+G(k)+G(l)+G(m)+G(p)\n produkt = tau(i)*tau(j)*tau(k)*tau(l)*tau(m)*tau(p)\n kd(6) = kd(6) + vsota*produkt\n end do\n end do\n end do\n end do\n end do\n end do\n\n print*, \"kd\", kd\n\n t = 0.0\n\n\n\n sigma = napetost(t)\n e = 0.0\n e1 = 0.0\n e2 = 0.0\n e3 = 0.0\n e4 = 0.0\n e5 = 0.0\n\n open(15, file=\"rungekutta.dat\")\n write(15,*) t, sigma, e, e1, e2, e3, e4, e5\n\n\n do while (t <= 120.0)\n\n k1e = dt* de(e1)\n k1e1 = dt*de1(e2)\n k1e2 = dt*de2(e3)\n k1e3 = dt*de3(e4)\n k1e4 = dt*de4(e5)\n k1e5 = dt*de5(kd,t,e1,e2,e3,e4,e5)\n\n k2e = dt* de(e1+0.5*k1e1)\n k2e1 = dt*de1(e2+0.5*k1e2)\n k2e2 = dt*de2(e3+0.5*k1e3)\n k2e3 = dt*de3(e4+0.5*k1e4)\n k2e4 = dt*de4(e5+0.5*k1e5)\n k2e5 = dt*de5(kd,t+0.5*dt,e1+0.5*k1e1,e2+0.5*k1e2,e3+0.5*k1e3,e4+0.5*k1e4,e5+0.5*k1e5)\n\n k3e = dt* de(e1+0.5*k2e1)\n k3e1 = dt*de1(e2+0.5*k2e2)\n k3e2 = dt*de2(e3+0.5*k2e3)\n k3e3 = dt*de3(e4+0.5*k2e4)\n k3e4 = dt*de4(e5+0.5*k2e5)\n k3e5 = dt*de5(kd,t+0.5*dt,e1+0.5*k2e1,e2+0.5*k2e2,e3+0.5*k2e3,e4+0.5*k2e4,e5+0.5*k2e5)\n\n k4e = dt* de(e1+k3e1)\n k4e1 = dt*de1(e2+k3e2)\n k4e2 = dt*de2(e3+k3e3)\n k4e3 = dt*de3(e4+k3e4)\n k4e4 = dt*de4(e5+k3e5)\n k4e5 = dt*de5(kd,t+dt,e1+k3e1,e2+k3e2,e3+k3e3,e4+k3e4,e5+k3e5)\n\n e = e + (k1e+2.0*k2e+2.0*k3e+k4e)/6.0\n e1 = e1 + (k1e1+2.0*k2e1+2.0*k3e1+k4e1)/6.0\n e2 = e2 + (k1e2+2.0*k2e2+2.0*k3e2+k4e2)/6.0\n e3 = e3 + (k1e3+2.0*k2e3+2.0*k3e3+k4e3)/6.0\n e4 = e4 + (k1e4+2.0*k2e4+2.0*k3e4+k4e4)/6.0\n e5 = e5 + (k1e5+2.0*k2e5+2.0*k3e5+k4e5)/6.0\n sigma = napetost(t)\n t = t + dt\n\n\n write(15,*) t, sigma, e, e1, e2, e3, e4, e5\n\n end do\n\n close(15)\n\n\n end program MaxwellModel\n\n\n ! napetost sigma\n function napetost(t)\n implicit none\n real :: napetost, t\n\n if (t < 40.0) then\n napetost = 10.0\n else\n napetost = 0.0\n end if\n\n end function\n\n ! 1. odvod\n function de(e1)\n implicit none\n real :: de,e1\n de = e1\n end function\n\n ! 2. odvod\n function de1(e2)\n implicit none\n real :: de1,e2\n de1 = e2\n end function\n\n ! 3. odvod\n function de2(e3)\n implicit none\n real :: de2,e3\n de2 = e3\n end function\n\n ! 4. odvod\n function de3(e4)\n implicit none\n real :: de3,e4\n de3 = e4\n end function\n\n ! 5. odvod\n function de4(e5)\n implicit none\n real :: de4,e5\n de4 = e5\n end function\n\n ! 6. odvod\n function de5(kd,t,e1,e2,e3,e4,e5)\n implicit none\n real :: kd(6)\n real :: de5,napetost,e1,e2,e3,e4,e5, t\n de5 = (napetost(t)-kd(5)*e5-kd(4)*e4-kd(3)*e3-kd(2)*e2-kd(1)*e1)/kd(6)\n end function\n\n", "meta": {"hexsha": "0009720621f495000522391b90d95aca52bd2a58", "size": 5147, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "maxwell/maxwell.f95", "max_stars_repo_name": "ivan-pi/rheology_lab", "max_stars_repo_head_hexsha": "220bc18319e54fff18594b6eb86ff188c072f39a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "maxwell/maxwell.f95", "max_issues_repo_name": "ivan-pi/rheology_lab", "max_issues_repo_head_hexsha": "220bc18319e54fff18594b6eb86ff188c072f39a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "maxwell/maxwell.f95", "max_forks_repo_name": "ivan-pi/rheology_lab", "max_forks_repo_head_hexsha": "220bc18319e54fff18594b6eb86ff188c072f39a", "max_forks_repo_licenses": ["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.3954545455, "max_line_length": 94, "alphanum_fraction": 0.4287934719, "num_tokens": 2266, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942145139149, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6712993574532287}} {"text": "function light(height, time, intensity) result(out)\n real(kind=8), dimension(:), intent(in) :: height\n real(kind=8), intent(in) :: time\n real(kind=8), dimension(:), allocatable :: intensity\n logical :: out\n integer :: i\n real, parameter :: Pi = 3.1415927\n out = .true.\n if (allocated(intensity)) then\n deallocate(intensity)\n end if\n allocate(intensity(size(height)))\n do i = 1, size(height)\n intensity(i) = 80.0 * (1.0 + SIN(2.0 * Pi * time / 365)) / (ABS(200.0 - height(i))**2)\n end do\nend function light\n", "meta": {"hexsha": "1cd462e8cb9be408a59dd6a20fe35475079464f6", "size": 526, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "models/light.f90", "max_stars_repo_name": "cropsinsilico/FSPM2020_yggdrasil_workshop", "max_stars_repo_head_hexsha": "fbcfc8a5dc6b3c5133b2475c9a78ff378d048ad7", "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": "models/light.f90", "max_issues_repo_name": "cropsinsilico/FSPM2020_yggdrasil_workshop", "max_issues_repo_head_hexsha": "fbcfc8a5dc6b3c5133b2475c9a78ff378d048ad7", "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": "models/light.f90", "max_forks_repo_name": "cropsinsilico/FSPM2020_yggdrasil_workshop", "max_forks_repo_head_hexsha": "fbcfc8a5dc6b3c5133b2475c9a78ff378d048ad7", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.9411764706, "max_line_length": 91, "alphanum_fraction": 0.6349809886, "num_tokens": 168, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971872, "lm_q2_score": 0.7431680086124812, "lm_q1q2_score": 0.671299352917866}} {"text": "! --------------------------------------------------------------------\r\n! FEM solution: \r\n! 2\u968e\u5e38\u5fae\u5206\u65b9\u7a0b\u5f0f\r\n! (d/dx)**2 u = \u03b1 (B.C. u(0) = 0, du/dx(L) = 0)\r\n! note: 1\u6b21\u5143\u30c8\u30e9\u30b9\u8981\u7d20\u3067\u8fd1\u4f3c\r\n! --------------------------------------------------------------------\r\n! --------------------------------------------------------------------\r\n! module: Difine parameters\r\n! --------------------------------------------------------------------\r\n! \r\nmodule parameters\r\n implicit none\r\n\r\n integer, parameter :: n = 10 ! \u8981\u7d20\u6570\r\n integer, parameter :: n1 = n + 1 ! \u7bc0\u70b9\u6570\r\n integer, parameter :: n2 = n + 2 ! \u5217\u30d9\u30af\u30c8\u30eb\u7528\r\n double precision, parameter :: alpha = - 1.d0 / 12.d0 ! ODE\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\r\n\r\nend module\r\n\r\n! --------------------------------------------------------------------\r\n! main Program\r\n! --------------------------------------------------------------------\r\n! \r\nprogram FEM_dim1\r\n use parameters\r\n implicit none\r\n\r\n call calc\r\n stop\r\n\r\nend program \r\n\r\n! --------------------------------------------------------------------\r\n! Calculation\r\n! --------------------------------------------------------------------\r\n! \r\nsubroutine calc\r\n use parameters\r\n implicit none\r\n\r\n integer i, j\r\n\r\n double precision,dimension(n1, n2) :: k_e ! \u8981\u7d20\u525b\u6027\u30de\u30c8\u30ea\u30c3\u30af\u30b9\r\n double precision,dimension(n1, n2) :: a ! \u62e1\u5927\u4fc2\u6570\u884c\u5217(\u5168\u4f53\u525b\u6027\u30de\u30c8\u30ea\u30c3\u30af\u30b9)\r\n double precision,dimension(n1) :: u ! \u7bc0\u70b9\u5909\u4f4d\u30d9\u30af\u30c8\u30eb\r\n double precision,dimension(n1) :: ans_u ! \u89e3\u7b54\u3068\u306a\u308b\u7bc0\u70b9\u5909\u4f4d\r\n double precision,dimension(n1) :: b ! - b = F \u8981\u7d20\u306b\u50cd\u304f\u5916\u529b\u30d9\u30af\u30c8\u30eb\r\n\r\n double precision,dimension(n1) :: x ! \u8981\u7d20\u6bce\u306e\u5ea7\u6a19\r\n double precision,dimension(n) :: l ! \u8981\u7d20\u306e\u9577\u3055\r\n double precision :: L_total ! \u8981\u7d20\u306e\u5408\u8a08(\u30c8\u30e9\u30b9\u5168\u4f53\u306e\u9577\u3055)\r\n ! gauss\r\n integer row, diag\r\n double precision :: m, temp\r\n ! pivot\r\n ! integer row_max\r\n ! double precision :: a_max, a_temp(n1 + 1)\r\n\r\n ! \u89e3\u30d9\u30af\u30c8\u30eb\u3092\u5b9a\u7fa9\r\n ans_u = [0.d0, 1.625d0, 3.17d0, 4.625d0, 6.d0, 8.5d0, 10.67d0, 12.5d0, 14.d0, 16.d0, 16.67d0]\r\n!---\u7bc0\u70b9\u306e\u60c5\u5831\u5165\u529b\r\n x = [0, 1, 2, 3, 4, 6, 8, 10, 12, 16, 20] ! \u7bc0\u70b9\u306e\u4f4d\u7f6e\u5ea7\u6a19\r\n L_total = x(n1)\r\n!---\u7bc0\u70b9\u9593\u306e\u9577\u3055\u3092\u7b97\u51fa\r\n do i = 1, n\r\n l(i) = x(i + 1) - x(i)\r\n end do\r\n!---\u521d\u671f\u5316\r\n do i = 1, n1\r\n do j = 1, n2\r\n a(i, j) = 0.d0\r\n k_e(i, j) = 0.d0\r\n end do\r\n b(i) = 0.d0\r\n end do\r\n b(1) = l(1)\r\n b(n1) = l(n)\r\n!---\u5168\u4f53\u525b\u6027\u30de\u30c8\u30ea\u30c3\u30af\u30b9 K\u306e\u8a08\u7b97\r\n a(1, 1) = 1.d0 / l(1)\r\n a(n1, n1) = 1.d0 / l(n)\r\n a(1, n2) = - alpha * l(1) / 2\r\n a(n1, n2) = - alpha * l(n) / 2\r\n do i = 2, n\r\n ! \u8981\u7d20\u525b\u6027\u30de\u30c8\u30ea\u30c3\u30af\u30b9 (\u6b21\u3005\u306b\u52a0\u3048\u3089\u308c\u306a\u3044\u3053\u3068\u304c\u8ab2\u984c)\r\n k_e(i, i) = 1.d0 / l(i) + 1.d0 / l(i - 1)\r\n k_e(i, i + 1) = - 1.d0 / l(i) \r\n k_e(i + 1, i) = - 1.d0 / l(i)\r\n k_e(i + 1, i + 1) = 1.d0 / l(i)\r\n ! \u5916\u529b\u30d9\u30af\u30c8\u30eb\r\n b(i) = alpha * ( l(i) + l(i - 1) ) / 2\r\n ! \u5916\u529b\u30d9\u30af\u30c8\u30eb\u306e\u30de\u30fc\u30b8\r\n a(i, n2) = a(i, n2) - b(i)\r\n end do\r\n ! \u8981\u7d20\u525b\u6027\u30de\u30c8\u30ea\u30c3\u30af\u30b9\u306e\u30de\u30fc\u30b8\r\n a = a + k_e\r\n!---Check matrix a\r\n ! do i = 1, n1\r\n ! write(*, \"(12f6.2)\") a(i, :)\r\n ! end do\r\n\r\n!---\u5883\u754c\u6761\u4ef6\u51e6\u7406\r\n call BC_procedure(a)\r\n!---Check matrix a\r\n write (*, *) \"before matrix a\"\r\n do i = 1, n1\r\n write(*, \"(12f6.2)\") a(i, :)\r\n end do\r\n!---\u9023\u7acb\u4e00\u6b21\u65b9\u7a0b\u5f0f\u3092\u89e3\u304f\r\n ! call gauss(a)\r\n\r\n!---\u4e0a\u66f8\u304d\u3067\u8a66\u3059\r\n ! a(1, 1:n1 + 1) = [2, 4, 6, 6]\r\n ! a(2, 1:n1 + 1) = [3, 8, 7, 15]\r\n ! a(3, 1:n1 + 1) = [5, 7, 21, 24]\r\n\r\n ! a(1, 1:n1 + 1) = [6, 5, 4, 8]\r\n ! a(2, 1:n1 + 1) = [12, 13, 10, 16]\r\n ! a(3, 1:n1 + 1) = [18, 21, 17, 27]\r\n\r\n!---Initialize\r\n temp = 0.d0\r\n!---Make upper matrix\r\n do diag = 1, n1 - 1\r\n ! call pivot(a, diag, n1)\r\n! !-------Sorting\r\n! a_max = abs(a(diag, diag))\r\n! do row = diag + 1, n1\r\n! if ( abs(a(row, diag)) > a_max ) then\r\n! row_max = row\r\n! a_max = abs(a(row, diag))\r\n! end if\r\n! end do\r\n! !-------Replace for a\r\n! a_temp = a(diag, :)\r\n! a(diag, :) = a(row_max, :)\r\n! a(row_max, :) = a_temp\r\n\r\n!-------Make upper matrix\r\n do row = diag + 1, n1\r\n m = a(row, diag) / a(diag, diag)\r\n a(row, 1:n1 + 1) = a(row, 1:n1 + 1) - m * a(diag, 1:n1 + 1)\r\n end do\r\n end do\r\n ! Check matrix a\r\n write (*, *) \"after Matrix a =\"\r\n do row = 1, n1\r\n write (*, \"(12f6.2)\") a(row, :)\r\n end do\r\n!---Backward solution\r\n u(n1) = a(n1, n1 + 1) / a(n1, n1)\r\n do diag = n1 - 1, 1, - 1\r\n temp = dot_product(a(diag, 1:n1), u(1:n1))\r\n u(diag) = (a(diag, n1 + 1) - temp) / a(diag, diag)\r\n end do\r\n!---Output u\r\n write (*, *) \"Diplacement u =\"\r\n write (*, \"(11f6.2)\") u(:)\r\n write (*, *) \"answer u =\"\r\n write (*, \"(11f6.2)\") ans_u(:)\r\n return\r\n\r\nend subroutine \r\n\r\n! --------------------------------------------------------------------\r\n! Boundary Condition procedure (\u5883\u754c\u6761\u4ef6\u51e6\u7406)\r\n! --------------------------------------------------------------------\r\n! \r\nsubroutine BC_procedure(a)\r\n use parameters\r\n implicit none\r\n\r\n integer j\r\n double precision,dimension(n1, n2) :: a\r\n\r\n a(1, 1) = 1\r\n\r\n do j = 2, n2\r\n a(1, j) = 0\r\n end do\r\n return\r\n\r\nend subroutine\r\n\r\n! ----------------------------------------------\r\n! \u62e1\u5927\u4fc2\u6570\u884c\u5217 version\r\n!-----------------------------------------------\r\n!\r\nsubroutine gauss(a)\r\n use parameters\r\n implicit none\r\n\r\n integer dim\r\n ! integer dim\r\n double precision :: a(n1, n1 + 1)\r\n double precision :: x(n1)\r\n ! double precision :: y(dim)\r\n ! local\r\n integer row, diag\r\n double precision :: m, temp\r\n\r\n!---Initialize\r\n dim = n1\r\n x = 0.d0\r\n temp = 0.d0\r\n!---Make upper matrix\r\n do diag = 1, dim - 1\r\n call pivot(a, diag, dim)\r\n do row = diag + 1, dim\r\n m = a(row, diag) / a(diag, diag)\r\n a(row, 1:dim + 1) = a(row, 1:dim + 1) - m * a(diag, 1:dim + 1)\r\n end do\r\n end do\r\n ! Check matrix a\r\n ! write (*, *) \"a =\"\r\n ! do row = 1, dim\r\n ! write (*, \"(4f6.2)\") a(row, :)\r\n ! end do\r\n!---Backward solution\r\n x(dim) = a(dim, dim + 1) / a(dim, dim)\r\n do diag = dim - 1, 1, - 1\r\n temp = dot_product(a(diag, 1:dim), x(1:dim))\r\n x(diag) = (a(diag, dim + 1) - temp) / a(diag, diag)\r\n end do\r\n return\r\n\r\nend subroutine \r\n\r\n!-----------------------------------------------\r\n! \u90e8\u5206\u30d4\u30dc\u30c3\u30c8\u9078\u629e\r\n!-----------------------------------------------\r\n!\r\nsubroutine pivot(a, diag, dim)\r\n implicit none\r\n\r\n integer dim, diag, row, row_max\r\n double precision :: a_max, a(dim, dim + 1), a_temp(dim + 1)\r\n!---Sorting\r\n a_max = abs(a(diag, diag))\r\n do row = diag + 1, dim\r\n if ( abs(a(row, diag)) > a_max ) then\r\n row_max = row\r\n a_max = abs(a(row, diag))\r\n end if\r\n end do\r\n!---Replace for a\r\n a_temp = a(diag, :)\r\n a(diag, :) = a(row_max, :)\r\n a(row_max, :) = a_temp\r\n return\r\n\r\nend subroutine\r\n\r\n!-----------------------------------------------\r\n! Otput\r\n!-----------------------------------------------\r\n!\r\nsubroutine output\r\n implicit none\r\n ! call BC_procedure\r\n ! open(10, file = \"output.csv\", status = \"replace\")\r\n ! do i = 1, n1\r\n ! write (10, \"(12f6.3)\") a(i, :)\r\n ! end do\r\n ! close(10)\r\n\r\n ! call gauss\r\n ! open(11, file = \"output-u.csv\", status = \"replace\")\r\n ! ! write (*, *) \"x =\"\r\n ! do i = 1, n\r\n ! write (11, *) \"step\", \"u\"\r\n ! write (11, \"(3f6.2)\") i, x(i)\r\n ! end do\r\n ! close (11)\r\n\r\n\r\nend subroutine\r\n", "meta": {"hexsha": "0f7747bf2b63a4124c9e4f2190581ab011939534", "size": 7356, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ex1-ODE.f90", "max_stars_repo_name": "DiaSird/FEM", "max_stars_repo_head_hexsha": "a06fd65392b7ca3bee511dc86c04d766473d6a24", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ex1-ODE.f90", "max_issues_repo_name": "DiaSird/FEM", "max_issues_repo_head_hexsha": "a06fd65392b7ca3bee511dc86c04d766473d6a24", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ex1-ODE.f90", "max_forks_repo_name": "DiaSird/FEM", "max_forks_repo_head_hexsha": "a06fd65392b7ca3bee511dc86c04d766473d6a24", "max_forks_repo_licenses": ["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.4604316547, "max_line_length": 98, "alphanum_fraction": 0.4045676998, "num_tokens": 2684, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.903294209307224, "lm_q2_score": 0.7431679972357831, "lm_q1q2_score": 0.67129934844553}} {"text": " program demo_int\n use,intrinsic :: iso_fortran_env, only : int8, int16, int32, int64\n implicit none\n integer :: i = 42\n complex :: z = (-3.7, 1.0)\n real :: x=-10.5, y=10.5\n\n print *, int(x), int(y)\n\n print *, int(i)\n\n print *, int(z), int(z,8)\n ! elemental\n print *, int([-10.9,-10.5,-10.3,10.3,10.5,10.9])\n ! note int(3) truncates towards zero\n\n ! CAUTION:\n ! a number bigger than a default integer can represent\n ! produces an incorrect result and is not required to\n ! be detected by the program.\n x=real(huge(0))+1000.0\n print *, int(x),x\n ! using a larger kind\n print *, int(x,kind=int64),x\n\n print *, int(&\n & B\"111111111111111111111111111111111111111111111111111111111111111\",&\n & kind=int64)\n print *, int(O\"777777777777777777777\",kind=int64)\n print *, int(Z\"7FFFFFFFFFFFFFFF\",kind=int64)\n\n ! elemental\n print *\n print *,int([ &\n & -2.7, -2.5, -2.2, -2.0, -1.5, -1.0, -0.5, &\n & 0.0, &\n & +0.5, +1.0, +1.5, +2.0, +2.2, +2.5, +2.7 ])\n\n end program demo_int\n", "meta": {"hexsha": "0b2142395b72c797aac572a208c559809785e035", "size": 1144, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/int.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/int.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/int.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": 28.6, "max_line_length": 77, "alphanum_fraction": 0.5332167832, "num_tokens": 402, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528132451416, "lm_q2_score": 0.7879311931529758, "lm_q1q2_score": 0.6712801966502787}} {"text": " PROGRAM LA_SGTSVX_EXAMPLE\n\n! -- LAPACK95 EXAMPLE DRIVER ROUTINE (VERSION 1.0) --\n! UNI-C, DENMARK\n! DECEMBER, 1999\n!\n! .. \"Use Statements\"\n USE LA_PRECISION, ONLY: WP => SP\n USE F95_LAPACK, ONLY: LA_GTSVX\n! ..\"Implicit Statement\" ..\n IMPLICIT NONE\n! .. \"Local Scalars\" ..\n INTEGER :: I, N, NRHS\n INTEGER, ALLOCATABLE :: IPIV(:)\n CHARACTER(LEN=1) :: TRANS\n! .. Local Arrays ..\n REAL(WP), ALLOCATABLE :: DL(:), D(:), DU(:), DLF(:), &\n DF(:), DUF(:), DU2(:), B(:,:),X(:,:)\n\n! .. \"Executable Statements\" ..\n WRITE (*,*) 'SGTSVX Example Program Results.'\n N = 6; NRHS = 3\n\n ALLOCATE(DL(N-1), DLF(N-1), D(N), DF(N), DU(N-1), DUF(N-1), &\n DU2(N-2), B(N,NRHS), X(N,NRHS), IPIV(N) )\n\n \n OPEN(UNIT=21,FILE='gtsv.ma',STATUS='UNKNOWN')\n DO I=1,N-1\n READ(21,'(F2.0)') DL(I)\n ENDDO\n DO I=1,N\n READ(21,'(F2.0)') D(I) \n ENDDO\n DO I=1,N-1\n READ(21,'(F2.0)') DU(I)\n ENDDO\n CLOSE(21)\n\n WRITE(*,*)'DU :'\n WRITE(*,\"(8(I3,1X))\") INT(DU(:));\n WRITE(*,*)'D :'\n WRITE(*,\"(8(I3,1X))\") INT(D(:)); \n WRITE(*,*)'DL :'\n WRITE(*,\"(8(I3,1X))\") INT(DL(:))\n\n B = 0.0_WP\n DO I = 2, N-1; B(I,:) = DU(I-1) + D(I) + DL(I); ENDDO\n B(1,:) = D(1) + DL(1);B(N,:) = DU(N-1) + D(N)\n DO I = 1, NRHS; B(:,I) = B(:,I)*I; ENDDO\n WRITE(*,*)'B = '\n DO I=1,N; WRITE(*,\"(8(F8.5,1X))\") B(I,:)\n ENDDO\n\n WRITE(*,*) \"CALL LA_GTSVX(DL, D, DU, B, X, DLF, DF, DUF, DU2, TRANS='T' )\"\n TRANS='T'\n CALL LA_GTSVX(DL, D, DU, B, X, DLF, DF, DUF, DU2, IPIV, TRANS='T' )\n\n WRITE(*,*)'X = '\n DO I=1,N;WRITE(*,\"(6(F8.5,1X))\") X(I,:)\n ENDDO\n\n WRITE(*,*)'DLF on exit:'; WRITE(*,\"(8(F8.5,1X))\") DLF(:);\n WRITE(*,*)'DF on exit:'; WRITE(*,\"(8(F8.5,1X))\") DF(:);\n WRITE(*,*)'DUF on exit:'; WRITE(*,\"(8(F8.5,1X))\") DUF(:); \n WRITE(*,*)'DU2 on exit:'; WRITE(*,\"(8(F8.5,1X))\") DU2(:);\n WRITE(*,*)'IPIV on exit:';WRITE(*,\"(8(I6,1X))\") IPIV(:);\n\n DEALLOCATE(DL,DLF,D,DF,DU,DUF,DU2,B,X)\n\n END PROGRAM LA_SGTSVX_EXAMPLE\n\n\n\n\n", "meta": {"hexsha": "783600060f53514d4c6c29f94a90d399a26de061", "size": 2202, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "EXAMPLES1/la_gtsvx_example.f90", "max_stars_repo_name": "MattBurn/LAPACK95", "max_stars_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-12-29T15:07:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T10:09:22.000Z", "max_issues_repo_path": "EXAMPLES1/la_gtsvx_example.f90", "max_issues_repo_name": "MattBurn/LAPACK95", "max_issues_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-12-30T15:38:47.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-31T06:45:11.000Z", "max_forks_repo_path": "EXAMPLES1/la_gtsvx_example.f90", "max_forks_repo_name": "MattBurn/LAPACK95", "max_forks_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-12-29T15:34:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-15T07:12:40.000Z", "avg_line_length": 28.9736842105, "max_line_length": 81, "alphanum_fraction": 0.4396003633, "num_tokens": 910, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528019683106, "lm_q2_score": 0.7879311931529758, "lm_q1q2_score": 0.6712801877649118}} {"text": "!\n! ------------------------------------------------------------------\n! S Y M M E Q A N D S Y M M S L\n! ------------------------------------------------------------------\n!\n! This routine is a modification of the one in \"Computer Methods\n! for Mathematical Computation\" by Forsythe, Malcolm, and Moler\n! (Prentice Hall, 1975) to solve a singular system of equations.\n!\n SUBROUTINE SYMMEQ(NDIM, N, A, X) \n!-----------------------------------------------\n! M o d u l e s \n!-----------------------------------------------\n USE vast_kind_param, ONLY: DOUBLE \n!...Translated by Pacific-Sierra Research 77to90 4.3E 21:52:17 11/14/01 \n!...Switches: \n IMPLICIT NONE\n!-----------------------------------------------\n! D u m m y A r g u m e n t s\n!-----------------------------------------------\n INTEGER , INTENT(IN) :: NDIM \n INTEGER , INTENT(IN) :: N \n REAL(DOUBLE) , INTENT(INOUT) :: A(NDIM,*) \n REAL(DOUBLE) , INTENT(INOUT) :: X(*) \n!-----------------------------------------------\n! L o c a l V a r i a b l e s\n!-----------------------------------------------\n INTEGER :: NM1, K, KP1, I, J \n REAL(DOUBLE) :: T \n!-----------------------------------------------\n! E x t e r n a l F u n c t i o n s\n!-----------------------------------------------\n!-----------------------------------------------\n!\n!\n! SOLVE A SYSTEM OF LINEAR EQUATIONS A*X = 0\n!\n! INPUT..\n!\n! NDIM = DECLARED ROW DIMENSION OF THE ARRAY CONTAINING A.\n! N = ORDER OF THE MATRIX\n! A = COEFFICIENT MATRIX\n! B = CONSTANT VECTOR\n!\n! OUTPUT..\n!\n! X = SOLUTION VECTOR with X(1) unchanged.\n!\n NM1 = N - 1 \n!\n!\n! L U FACTORIZATION WITHOUT PIVOTING\n!\n DO K = N, 3, -1 \n KP1 = K - 1 \n T = A(K,K) \n IF (T == 0.0D0) CYCLE \n!\n! COMPUTE MULTIPLIERS\n!\n A(KP1:2:(-1),K) = -A(KP1:2:(-1),K)/T \n!\n! INTERCHANGE AND ELIMINATE BY COLUMNS\n!\n DO J = KP1, 2, -1 \n T = A(K,J) \n IF (T == 0.0D0) CYCLE \n A(KP1:2:(-1),J) = A(KP1:2:(-1),J) + A(KP1:2:(-1),K)*T \n END DO \n END DO \n!\n! At this point it is assumed that the LU factorization\n! has already been performed.\n!\n ENTRY SYMMSL (NDIM, N, A, X) \n!\n X(2:N) = -A(2:N,1) \n DO K = N, 3, -1 \n T = X(K) \n IF (T == 0.0D0) CYCLE \n X(K-1:2:(-1)) = X(K-1:2:(-1)) + A(K-1:2:(-1),K)*T \n END DO \n!\n! BACK SUBSTITUTION\n!\n DO K = 2, N - 1 \n IF (A(K,K) == 0.D0) THEN \n X(K) = 0.D0 \n ELSE \n X(K) = X(K)/A(K,K) \n ENDIF \n T = -X(K) \n X(K+1:N) = X(K+1:N) + A(K+1:N,K)*T \n END DO \n X(N) = X(N)/A(N,N) \n RETURN \n END SUBROUTINE SYMMEQ \n", "meta": {"hexsha": "637a80d02445a8111d1134c2f2e836890ae4def5", "size": 2828, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src90/lib/libcom90/symmeq.f90", "max_stars_repo_name": "mansour2014/ATSP2K_plus", "max_stars_repo_head_hexsha": "30842b9f086d1e497aeb778e2a352d1e8e520ec3", "max_stars_repo_licenses": ["BSD-4-Clause-UC"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-07-21T14:03:39.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-21T14:03:39.000Z", "max_issues_repo_path": "src90/lib/libcom90/symmeq.f90", "max_issues_repo_name": "mzmansour/ATSP2K_plus", "max_issues_repo_head_hexsha": "30842b9f086d1e497aeb778e2a352d1e8e520ec3", "max_issues_repo_licenses": ["BSD-4-Clause-UC"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src90/lib/libcom90/symmeq.f90", "max_forks_repo_name": "mzmansour/ATSP2K_plus", "max_forks_repo_head_hexsha": "30842b9f086d1e497aeb778e2a352d1e8e520ec3", "max_forks_repo_licenses": ["BSD-4-Clause-UC"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.8571428571, "max_line_length": 76, "alphanum_fraction": 0.3705799151, "num_tokens": 887, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.882427872638409, "lm_q2_score": 0.7606506635289836, "lm_q1q2_score": 0.6712193468388753}} {"text": "program main\n implicit none\n\n integer :: i\n\n interface\n function Marsaglia_generator(seed_1_, seed_2_)\n implicit none\n integer, parameter :: li = selected_int_kind(10)\n integer, parameter :: dp = selected_real_kind(8)\n \n integer(li), intent(in), optional :: seed_1_, seed_2_\n real(dp) :: Marsaglia_generator\n end function Marsaglia_generator\n end interface\n\n do i = 1, 100\n write(*,*) Marsaglia_generator()\n end do\nend program main\n\nfunction Marsaglia_generator(seed_1_, seed_2_)\n implicit none\n integer, parameter :: li = selected_int_kind(10)\n integer, parameter :: dp = selected_real_kind(8)\n\n integer(li), intent(in), optional :: seed_1_, seed_2_\n real(dp) :: Marsaglia_generator\n\n if (present(seed_1_)) then\n if (present(seed_2_)) then\n Marsaglia_generator = Lagged_Fibonacci_generator(seed_1_) - random_generator_2(seed_2_)\n else\n Marsaglia_generator = Lagged_Fibonacci_generator(seed_1_) - random_generator_2()\n end if\n else\n if (present(seed_2_)) then\n Marsaglia_generator = Lagged_Fibonacci_generator() - random_generator_2(seed_2_)\n else\n Marsaglia_generator = Lagged_Fibonacci_generator() - random_generator_2()\n end if\n end if\n if (Marsaglia_generator < 0) then\n Marsaglia_generator = Marsaglia_generator + 16777213 / dble(16777216)\n end if\n\n contains\n function Lagged_Fibonacci_generator(seed_)\n ! \u7b2c\u4e00\u4e2a\u968f\u673a\u6570\u4ea7\u751f\u5668 - Fibonacci \u5ef6\u8fdf\u4ea7\u751f\u5668\n implicit none\n integer, parameter :: li = selected_int_kind(10)\n integer, parameter :: dp = selected_real_kind(8)\n\n integer(li), intent(in), optional :: seed_\n real(dp) :: Lagged_Fibonacci_generator\n\n integer :: i\n real(dp), save :: x(98) = [(-1, i = 1, 98)]\n logical :: initialized = .false.\n\n if (present(seed_)) then\n x(1) = Congruential_16807(seed_)\n initialized = .false.\n else if (x(1) == -1.0d0) then\n do i = 1, 97\n x(1) = Congruential_16807(1_li)\n end do\n initialized = .false.\n end if\n\n if (initialized) then\n x(1:97) = x(2:98)\n else\n do i = 2, 97\n x(i) = Congruential_16807()\n end do\n end if\n x(98) = x(1) - x(65)\n if (x(98) < 0) then\n x(98) = x(98) + 1.d0\n end if\n Lagged_Fibonacci_generator = x(98)\n end function Lagged_Fibonacci_generator\n\n function random_generator_2(seed_)\n ! \u7b2c\u4e8c\u4e2a\u968f\u673a\u6570\u53d1\u751f\u5668\n implicit none\n integer, parameter :: li = selected_int_kind(10)\n integer, parameter :: dp = selected_real_kind(8)\n\n integer(li), intent(in), optional :: seed_\n real(dp) :: random_generator_2\n\n real(dp), save :: last_random_number\n\n if (present(seed_)) then\n last_random_number = seed_\n end if\n random_generator_2 = last_random_number - 7654321 / dble(16777216)\n if (random_generator_2 < 0) then\n random_generator_2 = random_generator_2 + 16777213 / dble(16777216)\n end if\n last_random_number = random_generator_2\n end function random_generator_2\n\n function Congruential_16807(seed_)\n ! Schrage \u65b9\u6cd5 16807 \u4ea7\u751f\u5668\n implicit none\n integer, parameter :: li = selected_int_kind(10)\n integer, parameter :: dp = selected_real_kind(8)\n\n integer(li), intent(in), optional :: seed_\n real(dp) :: 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 = mod(z, m) / dble(m)\n end function Congruential_16807\nend function Marsaglia_generator", "meta": {"hexsha": "ed7a84436f26c0e30406c21d1aa4ef040b183314", "size": 4351, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Chap1-Monte-Carlo-Method-Basic/1.1.1.7-Marsaglia-Generator.f90", "max_stars_repo_name": "Chen-Jialin/Computational-Physics-Practice", "max_stars_repo_head_hexsha": "5bbb271123ee75727d266e6ca83d090ad8919abb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Chap1-Monte-Carlo-Method-Basic/1.1.1.7-Marsaglia-Generator.f90", "max_issues_repo_name": "Chen-Jialin/Computational-Physics-Practice", "max_issues_repo_head_hexsha": "5bbb271123ee75727d266e6ca83d090ad8919abb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chap1-Monte-Carlo-Method-Basic/1.1.1.7-Marsaglia-Generator.f90", "max_forks_repo_name": "Chen-Jialin/Computational-Physics-Practice", "max_forks_repo_head_hexsha": "5bbb271123ee75727d266e6ca83d090ad8919abb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.4692307692, "max_line_length": 99, "alphanum_fraction": 0.5511376695, "num_tokens": 1127, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705731, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6712193230675152}} {"text": " REAL FUNCTION slSEP (A1, B1, A2, B2)\n*+\n* - - - -\n* S E P\n* - - - -\n*\n* Angle between two points on a sphere.\n*\n* (single precision)\n*\n* Given:\n* A1,B1 r spherical coordinates of one point\n* A2,B2 r spherical coordinates of the other point\n*\n* (The spherical coordinates are [RA,Dec], [Long,Lat] etc, in radians.)\n*\n* The result is the angle, in radians, between the two points. It\n* is always positive.\n*\n* Called: slDSEP\n*\n* Last revision: 7 May 2000\n*\n* Copyright P.T.Wallace. All rights reserved.\n*\n* License:\n* This program is free software; you can redistribute it and/or modify\n* it under the terms of the GNU General Public License as published by\n* the Free Software Foundation; either version 2 of the License, or\n* (at your option) any later version.\n*\n* This program is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU General Public License for more details.\n*\n* You should have received a copy of the GNU General Public License\n* along with this program (see SLA_CONDITIONS); if not, write to the\n* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,\n* Boston, MA 02110-1301 USA\n*\n* Copyright (C) 1995 Association of Universities for Research in Astronomy Inc.\n*-\n\n IMPLICIT NONE\n\n REAL A1,B1,A2,B2\n\n DOUBLE PRECISION slDSEP\n\n\n\n* Use double precision version.\n slSEP = REAL(slDSEP(DBLE(A1),DBLE(B1),DBLE(A2),DBLE(B2)))\n\n END\n", "meta": {"hexsha": "100de4936d5f146b9d41259ad3c53977b1cc5cd5", "size": 1607, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iraf.v2161/math/slalib/sep.f", "max_stars_repo_name": "ysBach/irafdocgen", "max_stars_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:19:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T16:48:42.000Z", "max_issues_repo_path": "math/slalib/sep.f", "max_issues_repo_name": "kirxkirx/iraf", "max_issues_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-30T13:48:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-02T19:40:25.000Z", "max_forks_repo_path": "math/slalib/sep.f", "max_forks_repo_name": "kirxkirx/iraf", "max_forks_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.1929824561, "max_line_length": 80, "alphanum_fraction": 0.6708151836, "num_tokens": 449, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095294, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6712142875059763}} {"text": "module m_constants\n implicit none\n\n double precision, parameter :: PI = acos(-1.0d0)\nend module", "meta": {"hexsha": "435e3e64c5c2f03088b59852f23451a2a015995e", "size": 101, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/constant.f90", "max_stars_repo_name": "Nkzono99/mpifft-solver", "max_stars_repo_head_hexsha": "e1ccf0595718145caf8e57bf1d0f6bf5a17dfd9b", "max_stars_repo_licenses": ["MIT"], "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/constant.f90", "max_issues_repo_name": "Nkzono99/mpifft-solver", "max_issues_repo_head_hexsha": "e1ccf0595718145caf8e57bf1d0f6bf5a17dfd9b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-01-20T21:56:49.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-08T00:52:53.000Z", "max_forks_repo_path": "src/constant.f90", "max_forks_repo_name": "Nkzono99/mpifft-solver", "max_forks_repo_head_hexsha": "e1ccf0595718145caf8e57bf1d0f6bf5a17dfd9b", "max_forks_repo_licenses": ["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.2, "max_line_length": 52, "alphanum_fraction": 0.7128712871, "num_tokens": 26, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467643431002, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6712142756260384}} {"text": "SUBROUTINE potmp(PRESS,TEMP,S,RP,POTEMP)\n!SOURCE: http://www.ncl.ucar.edu/Support/talk_archives/2011/att-1609/potmp.f\n!\n! TITLE:\n! *****\n!\n! POTMP -- CALCULATE POTENTIAL TEMPERATURE FOR AN ARBITRARY\n! REFERENCE PRESSURE\n!\n! PURPOSE:\n! *******\n!\n! TO CALCULATE POTENTIAL TEMPERATURE\n!\n! REF: N.P. FOFONOFF\n! DEEP SEA RESEARCH\n! IN PRESS NOV 1976\n!\n! PARAMETERS:\n! **********\n!\n! PRESS -> PRESSURE IN DECIBARS\n! TEMP -> TEMPERATURE IN CELSIUS DEGREES\n! S -> SALINITY PSS 78\n! RP -> REFERENCE PRESSURE IN DECIBARS\n! (0.0 FOR THE QUANTITY THETA)\n! POTEMP <- POTENTIAL TEMPERATURE (DEG C)\n!\n REAL PRESS,TEMP,S,RP,POTEMP\n!\n! VARIABLES:\n! *********\n!\n INTEGER I,J,N\n REAL*4 DP,P,Q,R1,R2,R3,R4,R5,S1,T,X\n!\n! CODE:\n! ****\n!\n S1 = S-35.0\n P = PRESS\n T = TEMP\n\n DP = RP - P\n N = IFIX(ABS(DP)/1000.) + 1\n DP = DP/FLOAT(N)\n\n outer : do 10 I=1,N\n inner : do 20 J=1,4\n\n R1 = ((-2.1687E-16*T+1.8676E-14)*T-4.6206E-13)*P\n R2 = (2.7759E-12*T-1.1351E-10)*S1\n R3 = ((-5.4481E-14*T+8.733E-12)*T-6.7795E-10)*T\n R4 = (R1+(R2+R3+1.8741E-8))*P+(-4.2393E-8*T+1.8932E-6)*S1\n R5 = R4+((6.6228E-10*T-6.836E-8)*T+8.5258E-6)*T+3.5803E-5\n\n X = DP*R5\n\n GO TO (100,200,300,400),J\n\n 100 CONTINUE\n T = T+.5*X\n Q = X\n P = P + .5*DP\n CYCLE inner\n\n 200 CONTINUE\n T = T + .29298322*(X-Q)\n Q = .58578644*X + .121320344*Q\n CYCLE inner\n\n 300 CONTINUE\n T = T + 1.707106781*(X-Q)\n Q = 3.414213562*X - 4.121320344*Q\n P = P + .5*DP\n CYCLE inner\n\n 400 CONTINUE\n T = T + (X-2.0*Q)/6.0\n\n enddo inner\n enddo outer\n\n POTEMP = T\n!\n! END POTMP\n!\n\nEND SUBROUTINE potmp\n\n", "meta": {"hexsha": "e74adbc7a984aefe52c940946ec9c4fb10c2a7d6", "size": 1801, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/obs/HOLD/potmp.f90", "max_stars_repo_name": "GEOS-ESM/Ocean-LETKF", "max_stars_repo_head_hexsha": "a7c4bbf86cdbff078212914dcc059d0b1450accf", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-12-31T15:40:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-03T13:44:20.000Z", "max_issues_repo_path": "src/obs/HOLD/potmp.f90", "max_issues_repo_name": "GEOS-ESM/Ocean-LETKF", "max_issues_repo_head_hexsha": "a7c4bbf86cdbff078212914dcc059d0b1450accf", "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/obs/HOLD/potmp.f90", "max_forks_repo_name": "GEOS-ESM/Ocean-LETKF", "max_forks_repo_head_hexsha": "a7c4bbf86cdbff078212914dcc059d0b1450accf", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-14T18:46:56.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-14T18:46:56.000Z", "avg_line_length": 19.7912087912, "max_line_length": 76, "alphanum_fraction": 0.5152692948, "num_tokens": 752, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467611766711, "lm_q2_score": 0.7634837527911056, "lm_q1q2_score": 0.6712142684773107}} {"text": " program main\r\n!========================================================================\r\n!------------------ Miller-Colbert DVR (grid DVR) in one dimension ------\r\n!------------------ equidistant grid, arbitrary number of points --------\r\n!------------------ gives eigenvalues and eigenvectors of H -------------\r\n!------------------ symmetric double well is defined --------------------\r\n!========================================================================\r\n\timplicit real*8(a-h,o-z)\r\n\tparameter(nx=4096,aw=14d0,bw=20d0,vbot=bw*bw/4d0/aw)\r\n REAL*8 x(nx),v(nx)\r\n!========================================================================\r\n OPEN(15,FILE='INdvr',STATUS='OLD')\r\n READ(15,*) n1,xmin,xmax\r\n read(15,*) am\r\n close(15)\r\n write(*,*) 'GRID',n1,xmin,xmax\r\n write(*,*) 'MASS=',am\r\n pi=4d0*atan(1d0)\r\n\r\n\topen(55, file='wf_dat')\r\n\topen(54, file='pot' )\r\n\topen(62, file='eigs' )\r\n open(101,file='r' )\r\n open(11,file='pes.dat')\r\n!=======================================================================\r\n!cccccccccccccccccccccccccc define the grid cccccccccccccccccccccccccccccc\r\n xn=xmax-xmin\r\n dx=xn/(n1-1)\r\n write(*,*) 'GRID SPACING=',dx\r\n\twrite(*,*) 'x_init',x(1),xmin\r\n\twrite(*,*) 'x_fin',x(n1),xmax\r\ncccccccccccccccccccccccccc define the potential ccccccccccccccccccccccccc\r\n\tDe = 0.176d0\r\n do 11 i=1,N1\r\n x(i)=xmin+dx*(i-1)\r\n!\t if(x(i) .lt. 0.653594d0) then\r\n!\t v(i)=0.1831104*x(i)**2-0.186772608d0*x(i)**3\r\n!\t else\r\n!\t v(i) = 0.026074d0\r\n!\t endif\r\n!\t v(i) = De*(1d0-exp(-1.02d0*x(i)))**2\r\nC\t v(i) = x(i)**2/2d0-0.05d0*x(i)**3\r\nc read(11,*) a,v(i)\r\n v(i) = x(i)**2/2d0-0.01*x(i)**3\r\n\r\n write(54,*) x(i),v(i)\r\n11 continue\r\n close(54)\r\n\r\n!=======================================================================\r\n!------------------- construct and diagonalize H -----------------------\r\n call ham_dvr(n1,pi,am,x,v)\r\n\r\n close(62)\r\n close(55)\r\n STOP\r\n END\r\n!========================================================================\r\n!========================================================================\r\n subroutine ham_dvr(n1,pi,am,x,v)\r\n!------ construct the DVR Hamiltonian and solve the eigenvalue problem --\r\n!========================================================================\r\n implicit real*8(a-h,o-z)\r\n parameter(nx=4096,lwork=nx*10)\r\n real*8 x(*),v(*),work(lwork),w(nx),ham(nx,nx),hsv(nx,nx),z(nx)\r\n real*8 r(n1),dr(n1),ddr(n1)\r\n a=x(1)\r\n b=x(n1)\r\n ba=pi*a/(b-a)\r\n dx=x(2)-x(1)\r\n an=0.5d0/am/dx/dx\r\n anf=pi/(b-a)**2/am\r\nc----------------- construct the hamiltonian matrix --------------\r\n do 10 j=1,n1\r\n ham(j,j)=an*pi*pi/3d0+v(j)\r\n do 9 i=j+1,n1\r\n ham(i,j)=an*(-1d0)**(i-j)*2d0/(i-j)**2\r\n hsv(i,j)=ham(i,j)\r\n hsv(j,i)=ham(i,j)\r\n9 continue\r\n10 hsv(j,j)=ham(j,j)\r\n write(*,*) ham(1,1),ham(1,2),ham(2,1),ham(2,2)\r\n call dsyev('V','L',n1,ham,nx,w,work,lwork,info)\r\n write(*,*) 'INFO',info,work(1)\r\n eig=w(1)\r\n write(*,*) 'EIGENVALS',w(1),w(2),w(3)\r\n!---------------------- check the eigenvector --------------------\r\n!------ ham(j,k)/dsqrt(dx) is the eigenfunction in coord space ---\r\n dev=0d0\r\n write(*,*) 'NUMBER OF EIGENFUNCTIONS TO PRINT'\r\n read(*,*) ns\r\n do 30 j=1,n1\r\n write(62,*) j,w(j)\r\n write(55,1000) x(j),(ham(j,k)/dsqrt(dx),k=1,ns)\r\n\r\n z(j)=0d0\r\n do 31 i=1,n1\r\n31 z(j)=z(j)+hsv(j,i)*ham(i,1)/eig\r\n dev=dev+abs(z(j)-ham(j,1))**2\r\n30 continue\r\n\r\nc print out quantum potential \r\n do j=1,n1-1\r\n r(j) = (abs(ham(j+1,1))-abs(ham(j,1)))\r\n + /dx/abs(ham(j,1))\r\n enddo\r\n\r\n do j=1,n1-2\r\n dr(j) = (r(j+1)-r(j))/dx\r\n enddo\r\n\r\n do j=1,n1-3\r\n ddr(j) = (dr(j+1)-dr(j))/dx\r\n write(101,1000) x(j),r(j),dr(j),ddr(j)\r\n enddo\r\n \r\n\r\n write(*,*) 'EIGENVECTOR TEST',dev\r\nc-------------------- construct the eigenvector ------------\r\n anv=0d0\r\n do 15 n=1,n1\r\n15 anv=anv+abs(ham(n,1))**2\r\n write(*,*) 'VECTOR NORM=',anv\r\n1000\t format(81(e14.7,1x))\r\n return\r\n end\r\n!========================================================================\r\n", "meta": {"hexsha": "92b80b646fe617323db7a1ccb0900bb6bc8ea487", "size": 4465, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "DVR/1.0.0/dat1/dvr.f", "max_stars_repo_name": "binggu56/qmd", "max_stars_repo_head_hexsha": "e2628710de15f8a8b9a1280fcf92f9e87559414c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "DVR/1.0.0/dat1/dvr.f", "max_issues_repo_name": "binggu56/qmd", "max_issues_repo_head_hexsha": "e2628710de15f8a8b9a1280fcf92f9e87559414c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "DVR/1.0.0/dat1/dvr.f", "max_forks_repo_name": "binggu56/qmd", "max_forks_repo_head_hexsha": "e2628710de15f8a8b9a1280fcf92f9e87559414c", "max_forks_repo_licenses": ["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.8828125, "max_line_length": 75, "alphanum_fraction": 0.3903695409, "num_tokens": 1365, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240142763573, "lm_q2_score": 0.7154240079185319, "lm_q1q2_score": 0.6711564422182136}} {"text": "!*********************************************************\n!>\n! Integration Functions:\n!\n! * Gauss-Legendre Integration:\n\nmodule nfIntegration\n use nfConstants\n use nfSpecialFunctions\n implicit none\n\n real(dp) :: glx128(64), glw128(64)\n real(dp) :: glx512(256), glw512(256)\n real(dp) :: glx1024(512), glw1024(512)\n real(dp) :: g30k61_gx(15), g30k61_gw(15), g30k61_kx(31), g30k61_kw(31)\n\n type, public :: nfInt\n real(dp), public, allocatable :: glx(:), glw(:)\n contains\n procedure, public :: setGLNumPoints\n procedure, private :: setGLPoints\n procedure, private :: bisectionGLPoints\n end type nfInt\n\n type, private :: nfIntGLPoints\n real(dp), private, allocatable :: lower(:), upper(:)\n end type nfIntGLPoints\n\n public :: readGLParameters\n public :: gaussLegendre, gaussLegendreCmplx\n public :: readGKParameters\n\ncontains\n\n subroutine setGLNumPoints(this, numPoints)\n class(nfInt) :: this\n integer :: numPoints\n\n allocate(this%glx(numPoints))\n allocate(this%glw(numPoints))\n call setGLPoints(this)\n end subroutine setGLNumPoints\n\n subroutine setGLPoints(this)\n class(nfInt) :: this\n type(nfIntGLPoints) :: points\n integer :: i, numPoints\n real(dp) :: x, dx, value, valueOLD\n\n numPoints = size(this%glx,1)\n allocate(points%lower(numPoints))\n allocate(points%upper(numPoints))\n dx = 0.00001\n i = 1\n valueOLD = legendrePoly(numPoints, -1)\n x = -1.d0+dx\n do while(x.le.1.d0)\n value = legendrePoly(numPoints, x)\n if(value*valueOLD.lt.0.d0) then\n points%lower(i) = x-dx\n points%upper(i) = x\n i = i+1\n end if\n valueOLD = value\n x = x+dx\n end do\n call bisectionGLPoints(this, points)\n do i=1,numPoints\n this%glx(i) = (points%upper(i)+points%lower(i))/2.d0\n this%glw(i) = 2.d0*(1.d0-this%glx(i)**2.d0)/((numPoints+1.d0)*legendrePoly(numPoints+1,this%glx(i)))**2.d0\n print *, this%glx(i), this%glw(i)\n end do\n end subroutine setGLPoints\n\n subroutine bisectionGLPoints(this, points)\n class(nfInt) :: this\n type(nfIntGLPoints) :: points\n integer :: i, numPoints\n real(dp) :: x, value, eps\n\n eps = 1.d-10\n numPoints = size(this%glx,1)\n do i=1,numPoints\n do while(abs(points%upper(i)-points%lower(i)).gt.eps)\n x = (points%upper(i)+points%lower(i))/2.d0\n value = legendrePoly(numPoints, x)\n if(value.lt.0.d0) then\n if(mod(i,2).eq.0) then\n points%lower(i) = x\n else\n points%upper(i) = x\n end if\n else\n if(mod(i,2).eq.0) then\n points%upper(i) = x\n else\n points%lower(i) = x\n end if\n end if\n end do\n end do\n end subroutine bisectionGLPoints\n\n subroutine readGLParameters()\n implicit none\n integer :: i\n\n open(unit=1,file='data/gl128.dat',status='old')\n do i=1,64\n read(1,*) glx128(i), glw128(i)\n end do\n close(1)\n open(unit=1,file='data/gl512.dat',status='old')\n do i=1,256\n read(1,*) glx512(i), glw512(i)\n end do\n close(1)\n open(unit=1,file='data/gl1024.dat',status='old')\n do i=1,512\n read(1,*) glx1024(i), glw1024(i)\n end do\n close(1)\n end subroutine\n\n subroutine readGKParameters()\n implicit none\n integer :: i, numLines\n\n open(unit=1,file='data/g30k61.dat',status='old')\n read(1,*) numLines\n do i=1,numLines\n read(1,*) g30k61_gx(i), g30k61_gw(i)\n end do\n read(1,*) numLines\n do i=1,numLines\n read(1,*) g30k61_kx(i), g30k61_kw(i)\n end do\n close(1)\n end subroutine\n\n real(dp) function gaussLegendre(f,a,b,n,consts)\n implicit none\n integer :: i, n\n real(dp) :: consts(n), a, b, t0, dt, sumIntegral\n interface\n function f(n,c,x)\n integer, parameter :: dp = kind(0.d0)\n integer :: n\n real(dp) :: c(n), x, f\n end function f\n end interface\n\n t0 = (a+b)/2.d0\n dt = (b-a)/2.d0\n sumIntegral = 0.d0\n\n ! Using glx128 and glw128\n do i=64,1,-1\n sumIntegral = sumIntegral+glw128(i)*f(n,consts,t0-dt*glx128(i))\n end do\n do i=1,64\n sumIntegral = sumIntegral+glw128(i)*f(n,consts,t0+dt*glx128(i))\n end do\n\n ! Using glx512 and glw512\n ! do i=256,1,-1\n ! sumIntegral = sumIntegral+glw512(i)*f(n,consts,t0-dt*glx512(i))\n ! end do\n ! do i=1,256\n ! sumIntegral = sumIntegral+glw512(i)*f(n,consts,t0+dt*glx512(i))\n ! end do\n\n ! Using glx1024 and glw1024\n ! do i=512,1,-1\n ! sumIntegral = sumIntegral+glw1024(i)*f(n,consts,t0-dt*glx1024(i))\n ! end do\n ! do i=1,512\n ! sumIntegral = sumIntegral+glw1024(i)*f(n,consts,t0+dt*glx1024(i))\n ! end do\n gaussLegendre = sumIntegral*dt\n end function\n\n complex(dp) function gaussLegendreCmplx(f,a,b,n,consts)\n implicit none\n integer :: i, n\n real(dp) :: a, b, t0, dt, sumReal, sumCmplx\n complex(dp) :: consts(n)\n interface\n function f(n,c,x)\n integer, parameter :: dp = kind(0.d0)\n integer :: n\n real(dp) :: x\n complex(dp) :: c(n), f\n end function\n end interface\n\n t0 = (a+b)/2.d0\n dt = (b-a)/2.d0\n sumReal = 0.d0\n sumCmplx = 0.d0\n\n ! Using glx128 and glw128\n do i=64,1,-1\n sumReal = sumReal+glw128(i)*real(f(n,consts,t0-dt*glx128(i)))\n sumCmplx = sumCmplx+glw128(i)*aimag(f(n,consts,t0-dt*glx128(i)))\n end do\n do i=1,64\n sumReal = sumReal+glw128(i)*real(f(n,consts,t0+dt*glx128(i)))\n sumCmplx = sumCmplx+glw128(i)*aimag(f(n,consts,t0+dt*glx128(i)))\n end do\n\n ! Using glx512 and glw512\n ! do i=256,1,-1\n ! sumIntegral = sumIntegral+glw512(i)*f(n,consts,t0-dt*glx512(i))\n ! end do\n ! do i=1,256\n ! sumIntegral = sumIntegral+glw512(i)*f(n,consts,t0+dt*glx512(i))\n ! end do\n\n ! Using glx1024 and glw1024\n ! do i=512,1,-1\n ! sumIntegral = sumIntegral+glw1024(i)*f(n,consts,t0-dt*glx1024(i))\n ! end do\n ! do i=1,512\n ! sumIntegral = sumIntegral+glw1024(i)*f(n,consts,t0+dt*glx1024(i))\n ! end do\n gaussLegendreCmplx = cmplx(sumReal*dt,sumCmplx*dt,dp)\n end function\n\nend module nfIntegration", "meta": {"hexsha": "c80c170c2d42cdd16b9ec05cb1811990158dcd32", "size": 6108, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/nfIntegration.f90", "max_stars_repo_name": "joshhooker/numFortran", "max_stars_repo_head_hexsha": "14115d48e82a6bb898abd47ff749a9943aba52cb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/nfIntegration.f90", "max_issues_repo_name": "joshhooker/numFortran", "max_issues_repo_head_hexsha": "14115d48e82a6bb898abd47ff749a9943aba52cb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/nfIntegration.f90", "max_forks_repo_name": "joshhooker/numFortran", "max_forks_repo_head_hexsha": "14115d48e82a6bb898abd47ff749a9943aba52cb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.5565217391, "max_line_length": 112, "alphanum_fraction": 0.5979043877, "num_tokens": 2140, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240177362488, "lm_q2_score": 0.7154239836484144, "lm_q1q2_score": 0.6711564219251229}} {"text": " subroutine init_rphi(ctfm,ctfmp,Nx,amp,deltx,hx,x0,res)\n implicit none\n integer i\n integer Nx\n real*8 amp\n real*8 deltx\n real*8 hx\n real*8 x0\n real*8 ctfm(Nx)\n real*8 ctfmp(Nx)\n real*8 res(Nx)\n real*8 qb\n do i=2, Nx-1, 1\n qb = amp * (ctfm(i) - 0.1D1 * x0) / deltx ** 2 * (ctfm(i - 1) - 0.\n #1D1 * ctfm(i + 1)) / hx * exp(-0.1D1 * (ctfm(i) - 0.1D1 * x0) ** 2\n # / deltx ** 2) / ctfmp(i)\n res(i)=qb\n end do\n END\n", "meta": {"hexsha": "56d10ab7bef453691af37d42932ffb7a12d8655e", "size": 504, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/FD/init_rphi.f", "max_stars_repo_name": "rmanak/bssn_spher", "max_stars_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/FD/init_rphi.f", "max_issues_repo_name": "rmanak/bssn_spher", "max_issues_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/FD/init_rphi.f", "max_forks_repo_name": "rmanak/bssn_spher", "max_forks_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.2, "max_line_length": 72, "alphanum_fraction": 0.4742063492, "num_tokens": 222, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9465966717067252, "lm_q2_score": 0.7090191337850933, "lm_q1q2_score": 0.6711551522173547}} {"text": "Real Function ang(srt, iseed)\n Common /rndf77/nseed\n Save\n If ((srt>2.14) .And. (srt<=2.4)) Then\n b1s = 29.03 - 23.75*srt + 4.865*srt**2\n b2s = -30.33 + 25.53*srt - 5.301*srt**2\n End If\n If (srt>2.4) Then\n b1s = 0.06\n b2s = 0.4\n End If\n x = ranart(nseed)\n p = b1s/b2s\n q = (2.*x-1.)*(b1s+b2s)/b2s\n If ((-q/2.+sqrt((q/2.)**2+(p/3.)**3))>=0.) Then\n ang1 = (-q/2.+sqrt((q/2.)**2+(p/3.)**3))**(1./3.)\n Else\n ang1 = -(q/2.-sqrt((q/2.)**2+(p/3.)**3))**(1./3.)\n End If\n If ((-q/2.-sqrt((q/2.)**2+(p/3.)**3)>=0.)) Then\n ang2 = (-q/2.-sqrt((q/2.)**2+(p/3.)**3))**(1./3.)\n Else\n ang2 = -(q/2.+sqrt((q/2.)**2+(p/3.)**3))**(1./3.)\n End If\n ang = ang1 + ang2\n Return\nEnd Function ang\n", "meta": {"hexsha": "d632556c9aa3b3ee38b3e440acad3603bedc0fb8", "size": 720, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/ang.f90", "max_stars_repo_name": "xiaohaijin/AMPT", "max_stars_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-12-24T19:37:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-14T12:58:59.000Z", "max_issues_repo_path": "src/ang.f90", "max_issues_repo_name": "xiaohaijin/AMPT", "max_issues_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_issues_repo_licenses": ["MIT"], "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/ang.f90", "max_forks_repo_name": "xiaohaijin/AMPT", "max_forks_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_forks_repo_licenses": ["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.7142857143, "max_line_length": 54, "alphanum_fraction": 0.4597222222, "num_tokens": 384, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218391455084, "lm_q2_score": 0.727975443004307, "lm_q1q2_score": 0.671136459267297}} {"text": "submodule (Prng_Class) sm_rngNormal\n !! Generate random number from a normal distribution.\n\n ! Original Version\n ! Author: Alan Miller\n ! The base functions were originally inside http://www.netlib.org/random/random.f90.\n\n ! Updated version:\n ! Version 2.00, 11 November 2016\n ! Increased precision to double\n !\n ! Updated again\n ! Added overloaded operations for single number, nD arrays\n ! Author: Leon Foks\n\nimplicit none\n\ncontains\n\n !====================================================================!\n module procedure rngNormal_d1_Prng!(this, res, mean, std)\n !! Overloaded Type bound procedure Prng%rngNormal()\n !====================================================================!\n ! Adapted from the following Fortran 77 code\n ! ALGORITHM 712, COLLECTED ALGORITHMS FROM ACM.\n ! THIS WORK PUBLISHED IN TRANSACTIONS ON MATHEMATICAL SOFTWARE,\n ! VOL. 18, NO. 4, DECEMBER, 1992, PP. 434-435.\n\n ! The function random_normal() returns a normally distributed pseudo-random\n ! number with zero mean and unit variance.\n\n ! The algorithm uses the ratio of uniforms method of A.J. Kinderman\n ! and J.F. Monahan augmented with quadratic bounding curves.\n ! Generate P = (u,v) uniform in rectangle enclosing acceptance region\n !====================================================================!\n! class(Prng), intent(inout) :: this\n! real(r64), intent(inout) :: res\n! real(r64), intent(in), optional :: mean,std\n ! Local variables\n real(r64), parameter :: s = 0.449871d0\n real(r64), parameter :: t = -0.386595d0\n real(r64), parameter :: a = 0.196d0\n real(r64), parameter :: b = 0.25472d0\n real(r64) :: q\n real(r64), parameter :: r1 = 0.27597d0\n real(r64), parameter :: r2 = 0.27846d0\n real(r64) :: u\n real(r64) :: v\n real(r64) :: x\n real(r64) :: y\n\n do\n call this%rngUniform(u, 0.d0, 1.d0)\n call this%rngUniform(v, 0.d0, 1.d0)\n v = 1.7156d0 * (v - 0.5d0)\n\n ! Evaluate the quadratic form\n x = u - s\n y = dabs(v) - t\n q = x**2d0 + y*(a*y - b*x)\n\n ! Accept P if inside inner ellipse\n if (q < r1) exit\n ! Reject P if outside outer ellipse\n if (q > r2) cycle\n ! Reject P if outside acceptance region\n if (v**2.d0 < -4.d0*log(u)*u**2.d0) exit\n enddo\n\n ! Return ratio of P's coordinates as the normal deviate\n res = v/u\n if (present(std)) then\n if (.not. present(mean)) call eMsg('rngNormal : Need both mean and standard deviation')\n res = (std*res) + mean\n end if\n end procedure\n !====================================================================!\n !====================================================================!\n module procedure rngNormal_d1D_Prng!(this, res, mean,std)\n !! Overloaded Type bound procedure Prng%rngNormal()\n !====================================================================!\n! class(Prng), intent(inout) :: this\n! real(r64), intent(inout) :: res\n! real(r64),optional :: mean,std\n integer(i32) :: i,N\n N=size(res)\n do i=1,N\n call rngNormal_d1_Prng(this, res(i), mean, std)\n end do\n end procedure\n !====================================================================!\n !====================================================================!\n module procedure rngNormal_d2D_Prng!(this, res, mean,std)\n !! Overloaded Type bound procedure Prng%rngNormal()\n !====================================================================!\n! class(Prng), intent(inout) :: this\n! real(r64), intent(inout) :: res\n! real(r64),optional :: mean,std\n integer(i32) :: i,iSub(2)\n integer(i32) :: n,nSub(2)\n nSub = shape(res)\n n=size(res)\n do i=1,n\n iSub = ind2sub(i,nSub)\n call rngNormal_d1_Prng(this, res(iSub(1),iSub(2)), mean, std)\n enddo\n end procedure\n !====================================================================!\n !====================================================================!\n module procedure rngNormal_d3D_Prng!(this, res, mean,std)\n !! Overloaded Type bound procedure Prng%rngNormal()\n !====================================================================!\n! class(Prng), intent(inout) :: this\n! real(r64), intent(inout) :: res\n! real(r64),optional :: mean,std\n integer(i32) :: i,iSub(3)\n integer(i32) :: n,nSub(3)\n nSub = shape(res)\n n=size(res)\n do i=1,n\n iSub = ind2sub(i,nSub)\n call rngNormal_d1_Prng(this, res(iSub(1),iSub(2),iSub(3)), mean, std)\n enddo\n end procedure\n !====================================================================!\n\nend submodule\n", "meta": {"hexsha": "b968519b2c60a0738063b6e0fb199d2f93590f80", "size": 4478, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/random/sm_rngNormal.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/random/sm_rngNormal.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/random/sm_rngNormal.f90", "max_forks_repo_name": "leonfoks/coretran", "max_forks_repo_head_hexsha": "bf998d4353badc91d3a12d23c78781c8377b9578", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-02-20T15:07:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-10T17:58:00.000Z", "avg_line_length": 34.984375, "max_line_length": 91, "alphanum_fraction": 0.521438142, "num_tokens": 1231, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181875, "lm_q2_score": 0.7577943822145998, "lm_q1q2_score": 0.671126555571859}} {"text": "*> \\brief DGTSV computes the solution to system of linear equations A * X = B for GT matrices \n*\n* =========== DOCUMENTATION ===========\n*\n* Online html documentation available at\n* http://www.netlib.org/lapack/explore-html/\n*\n*> \\htmlonly\n*> Download DGTSV + dependencies\n*> \n*> [TGZ]\n*> \n*> [ZIP]\n*> \n*> [TXT]\n*> \\endhtmlonly\n*\n* Definition:\n* ===========\n*\n* SUBROUTINE DGTSV( N, NRHS, DL, D, DU, B, LDB, INFO )\n*\n* .. Scalar Arguments ..\n* INTEGER INFO, LDB, N, NRHS\n* ..\n* .. Array Arguments ..\n* DOUBLE PRECISION B( LDB, * ), D( * ), DL( * ), DU( * )\n* ..\n*\n*\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*>\n*> DGTSV solves the equation\n*>\n*> A*X = B,\n*>\n*> where A is an n by n tridiagonal matrix, by Gaussian elimination with\n*> partial pivoting.\n*>\n*> Note that the equation A**T*X = B may be solved by interchanging the\n*> order of the arguments DU and DL.\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in] N\n*> \\verbatim\n*> N is INTEGER\n*> The order of the matrix A. N >= 0.\n*> \\endverbatim\n*>\n*> \\param[in] NRHS\n*> \\verbatim\n*> NRHS is INTEGER\n*> The number of right hand sides, i.e., the number of columns\n*> of the matrix B. NRHS >= 0.\n*> \\endverbatim\n*>\n*> \\param[in,out] DL\n*> \\verbatim\n*> DL is DOUBLE PRECISION array, dimension (N-1)\n*> On entry, DL must contain the (n-1) sub-diagonal elements of\n*> A.\n*>\n*> On exit, DL is overwritten by the (n-2) elements of the\n*> second super-diagonal of the upper triangular matrix U from\n*> the LU factorization of A, in DL(1), ..., DL(n-2).\n*> \\endverbatim\n*>\n*> \\param[in,out] D\n*> \\verbatim\n*> D is DOUBLE PRECISION array, dimension (N)\n*> On entry, D must contain the diagonal elements of A.\n*>\n*> On exit, D is overwritten by the n diagonal elements of U.\n*> \\endverbatim\n*>\n*> \\param[in,out] DU\n*> \\verbatim\n*> DU is DOUBLE PRECISION array, dimension (N-1)\n*> On entry, DU must contain the (n-1) super-diagonal elements\n*> of A.\n*>\n*> On exit, DU is overwritten by the (n-1) elements of the first\n*> super-diagonal of U.\n*> \\endverbatim\n*>\n*> \\param[in,out] B\n*> \\verbatim\n*> B is DOUBLE PRECISION array, dimension (LDB,NRHS)\n*> On entry, the N by NRHS matrix of right hand side matrix B.\n*> On exit, if INFO = 0, the N by NRHS solution matrix X.\n*> \\endverbatim\n*>\n*> \\param[in] LDB\n*> \\verbatim\n*> LDB is INTEGER\n*> The leading dimension of the array B. LDB >= max(1,N).\n*> \\endverbatim\n*>\n*> \\param[out] INFO\n*> \\verbatim\n*> INFO is INTEGER\n*> = 0: successful exit\n*> < 0: if INFO = -i, the i-th argument had an illegal value\n*> > 0: if INFO = i, U(i,i) is exactly zero, and the solution\n*> has not been computed. The factorization has not been\n*> completed unless i = N.\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee\n*> \\author Univ. of California Berkeley\n*> \\author Univ. of Colorado Denver\n*> \\author NAG Ltd.\n*\n*> \\ingroup doubleGTsolve\n*\n* =====================================================================\n SUBROUTINE DGTSV( N, NRHS, DL, D, DU, B, LDB, INFO )\n*\n* -- LAPACK driver routine --\n* -- LAPACK is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n*\n* .. Scalar Arguments ..\n INTEGER INFO, LDB, N, NRHS\n* ..\n* .. Array Arguments ..\n DOUBLE PRECISION B( LDB, * ), D( * ), DL( * ), DU( * )\n* ..\n*\n* =====================================================================\n*\n* .. Parameters ..\n DOUBLE PRECISION ZERO\n PARAMETER ( ZERO = 0.0D+0 )\n* ..\n* .. Local Scalars ..\n INTEGER I, J\n DOUBLE PRECISION FACT, TEMP\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC ABS, MAX\n* ..\n* .. External Subroutines ..\n EXTERNAL XERBLA\n* ..\n* .. Executable Statements ..\n*\n INFO = 0\n IF( N.LT.0 ) THEN\n INFO = -1\n ELSE IF( NRHS.LT.0 ) THEN\n INFO = -2\n ELSE IF( LDB.LT.MAX( 1, N ) ) THEN\n INFO = -7\n END IF\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'DGTSV ', -INFO )\n RETURN\n END IF\n*\n IF( N.EQ.0 )\n $ RETURN\n*\n IF( NRHS.EQ.1 ) THEN\n DO 10 I = 1, N - 2\n IF( ABS( D( I ) ).GE.ABS( DL( I ) ) ) THEN\n*\n* No row interchange required\n*\n IF( D( I ).NE.ZERO ) THEN\n FACT = DL( I ) / D( I )\n D( I+1 ) = D( I+1 ) - FACT*DU( I )\n B( I+1, 1 ) = B( I+1, 1 ) - FACT*B( I, 1 )\n ELSE\n INFO = I\n RETURN\n END IF\n DL( I ) = ZERO\n ELSE\n*\n* Interchange rows I and I+1\n*\n FACT = D( I ) / DL( I )\n D( I ) = DL( I )\n TEMP = D( I+1 )\n D( I+1 ) = DU( I ) - FACT*TEMP\n DL( I ) = DU( I+1 )\n DU( I+1 ) = -FACT*DL( I )\n DU( I ) = TEMP\n TEMP = B( I, 1 )\n B( I, 1 ) = B( I+1, 1 )\n B( I+1, 1 ) = TEMP - FACT*B( I+1, 1 )\n END IF\n 10 CONTINUE\n IF( N.GT.1 ) THEN\n I = N - 1\n IF( ABS( D( I ) ).GE.ABS( DL( I ) ) ) THEN\n IF( D( I ).NE.ZERO ) THEN\n FACT = DL( I ) / D( I )\n D( I+1 ) = D( I+1 ) - FACT*DU( I )\n B( I+1, 1 ) = B( I+1, 1 ) - FACT*B( I, 1 )\n ELSE\n INFO = I\n RETURN\n END IF\n ELSE\n FACT = D( I ) / DL( I )\n D( I ) = DL( I )\n TEMP = D( I+1 )\n D( I+1 ) = DU( I ) - FACT*TEMP\n DU( I ) = TEMP\n TEMP = B( I, 1 )\n B( I, 1 ) = B( I+1, 1 )\n B( I+1, 1 ) = TEMP - FACT*B( I+1, 1 )\n END IF\n END IF\n IF( D( N ).EQ.ZERO ) THEN\n INFO = N\n RETURN\n END IF\n ELSE\n DO 40 I = 1, N - 2\n IF( ABS( D( I ) ).GE.ABS( DL( I ) ) ) THEN\n*\n* No row interchange required\n*\n IF( D( I ).NE.ZERO ) THEN\n FACT = DL( I ) / D( I )\n D( I+1 ) = D( I+1 ) - FACT*DU( I )\n DO 20 J = 1, NRHS\n B( I+1, J ) = B( I+1, J ) - FACT*B( I, J )\n 20 CONTINUE\n ELSE\n INFO = I\n RETURN\n END IF\n DL( I ) = ZERO\n ELSE\n*\n* Interchange rows I and I+1\n*\n FACT = D( I ) / DL( I )\n D( I ) = DL( I )\n TEMP = D( I+1 )\n D( I+1 ) = DU( I ) - FACT*TEMP\n DL( I ) = DU( I+1 )\n DU( I+1 ) = -FACT*DL( I )\n DU( I ) = TEMP\n DO 30 J = 1, NRHS\n TEMP = B( I, J )\n B( I, J ) = B( I+1, J )\n B( I+1, J ) = TEMP - FACT*B( I+1, J )\n 30 CONTINUE\n END IF\n 40 CONTINUE\n IF( N.GT.1 ) THEN\n I = N - 1\n IF( ABS( D( I ) ).GE.ABS( DL( I ) ) ) THEN\n IF( D( I ).NE.ZERO ) THEN\n FACT = DL( I ) / D( I )\n D( I+1 ) = D( I+1 ) - FACT*DU( I )\n DO 50 J = 1, NRHS\n B( I+1, J ) = B( I+1, J ) - FACT*B( I, J )\n 50 CONTINUE\n ELSE\n INFO = I\n RETURN\n END IF\n ELSE\n FACT = D( I ) / DL( I )\n D( I ) = DL( I )\n TEMP = D( I+1 )\n D( I+1 ) = DU( I ) - FACT*TEMP\n DU( I ) = TEMP\n DO 60 J = 1, NRHS\n TEMP = B( I, J )\n B( I, J ) = B( I+1, J )\n B( I+1, J ) = TEMP - FACT*B( I+1, J )\n 60 CONTINUE\n END IF\n END IF\n IF( D( N ).EQ.ZERO ) THEN\n INFO = N\n RETURN\n END IF\n END IF\n*\n* Back solve with the matrix U from the factorization.\n*\n IF( NRHS.LE.2 ) THEN\n J = 1\n 70 CONTINUE\n B( N, J ) = B( N, J ) / D( N )\n IF( N.GT.1 )\n $ B( N-1, J ) = ( B( N-1, J )-DU( N-1 )*B( N, J ) ) / D( N-1 )\n DO 80 I = N - 2, 1, -1\n B( I, J ) = ( B( I, J )-DU( I )*B( I+1, J )-DL( I )*\n $ B( I+2, J ) ) / D( I )\n 80 CONTINUE\n IF( J.LT.NRHS ) THEN\n J = J + 1\n GO TO 70\n END IF\n ELSE\n DO 100 J = 1, NRHS\n B( N, J ) = B( N, J ) / D( N )\n IF( N.GT.1 )\n $ B( N-1, J ) = ( B( N-1, J )-DU( N-1 )*B( N, J ) ) /\n $ D( N-1 )\n DO 90 I = N - 2, 1, -1\n B( I, J ) = ( B( I, J )-DU( I )*B( I+1, J )-DL( I )*\n $ B( I+2, J ) ) / D( I )\n 90 CONTINUE\n 100 CONTINUE\n END IF\n*\n RETURN\n*\n* End of DGTSV\n*\n END\n", "meta": {"hexsha": "0f02201d58a82234d9e43847ff5dd419c07479d9", "size": 9668, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "SRC/dgtsv.f", "max_stars_repo_name": "sergey-v-kuznetsov/lapack", "max_stars_repo_head_hexsha": "799ef93faa5878aa8702f7cf9980cfc649cc39cc", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 998, "max_stars_repo_stars_event_min_datetime": "2016-05-04T20:50:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T17:43:13.000Z", "max_issues_repo_path": "SRC/dgtsv.f", "max_issues_repo_name": "sergey-v-kuznetsov/lapack", "max_issues_repo_head_hexsha": "799ef93faa5878aa8702f7cf9980cfc649cc39cc", "max_issues_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_issues_count": 603, "max_issues_repo_issues_event_min_datetime": "2016-06-04T07:28:21.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T21:16:50.000Z", "max_forks_repo_path": "SRC/dgtsv.f", "max_forks_repo_name": "sergey-v-kuznetsov/lapack", "max_forks_repo_head_hexsha": "799ef93faa5878aa8702f7cf9980cfc649cc39cc", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 373, "max_forks_repo_forks_event_min_datetime": "2016-06-04T06:05:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T17:25:45.000Z", "avg_line_length": 29.2084592145, "max_line_length": 110, "alphanum_fraction": 0.4068059578, "num_tokens": 3040, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8856314768368161, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6711265530149726}} {"text": " MODULE random_standard_normal_mod\n! .. Implicit None Statement ..\n IMPLICIT NONE\n! ..\n CONTAINS\n\n!*********************************************************************\n\n FUNCTION random_standard_normal()\n!**********************************************************************C\n! C\n! C\n! (STANDARD-) N O R M A L DISTRIBUTION C\n! C\n! C\n!**********************************************************************C\n!**********************************************************************C\n! C\n! FOR DETAILS SEE: C\n! C\n! AHRENS, J.H. AND DIETER, U. C\n! EXTENSIONS OF FORSYTHE'S METHOD FOR RANDOM C\n! SAMPLING FROM THE NORMAL DISTRIBUTION. C\n! MATH. COMPUT., 27,124 (OCT. 1973), 927 - 937. C\n! C\n! ALL STATEMENT NUMBERS CORRESPOND TO THE STEPS OF ALGORITHM 'FL' C\n! (M=5) IN THE ABOVE PAPER (SLIGHTLY MODIFIED IMPLEMENTATION) C\n! C\n! Modified by Barry W. Brown, Feb 3, 1988 to use C\n! RANDOM_STANDARD_UNIFORM instead of C\n! SUNIF. The argument IR thus goes away. C\n! C\n!**********************************************************************C\n! THE DEFINITIONS OF THE CONSTANTS A(K), D(K), T(K) AND\n! H(K) ARE ACCORDING TO THE ABOVEMENTIONED ARTICLE\n! .. Use Statements ..\n USE random_standard_uniform_mod\n! ..\n! .. Implicit None Statement ..\n IMPLICIT NONE\n! ..\n! .. Local Scalars ..\n REAL :: aa, s, tt, u, ustar, w, y\n INTEGER :: i\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC FLOAT, INT, MIN\n! ..\n! .. Function Return Value ..\n REAL :: random_standard_normal\n! ..\n! .. Parameters ..\n REAL, PARAMETER :: a(32) = (/ 0.0, 0.3917609E-1, 0.7841241E-1, &\n 0.1177699, 0.1573107, 0.1970991, 0.2372021, 0.2776904, &\n 0.3186394, 0.3601299, 0.4022501, 0.4450965, 0.4887764, &\n 0.5334097, 0.5791322, 0.6260990, 0.6744898, 0.7245144, &\n 0.7764218, 0.8305109, 0.8871466, 0.9467818, 1.009990, 1.077516, &\n 1.150349, 1.229859, 1.318011, 1.417797, 1.534121, 1.675940, &\n 1.862732, 2.153875/)\n REAL, PARAMETER :: d(31) = (/ 0.0, 0.0, 0.0, 0.0, 0.0, 0.2636843, &\n 0.2425085, 0.2255674, 0.2116342, 0.1999243, 0.1899108, &\n 0.1812252, 0.1736014, 0.1668419, 0.1607967, 0.1553497, &\n 0.1504094, 0.1459026, 0.1417700, 0.1379632, 0.1344418, &\n 0.1311722, 0.1281260, 0.1252791, 0.1226109, 0.1201036, &\n 0.1177417, 0.1155119, 0.1134023, 0.1114027, 0.1095039/)\n REAL, PARAMETER :: h(31) = (/ 0.3920617E-1, 0.3932705E-1, &\n 0.3950999E-1, 0.3975703E-1, 0.4007093E-1, 0.4045533E-1, &\n 0.4091481E-1, 0.4145507E-1, 0.4208311E-1, 0.4280748E-1, &\n 0.4363863E-1, 0.4458932E-1, 0.4567523E-1, 0.4691571E-1, &\n 0.4833487E-1, 0.4996298E-1, 0.5183859E-1, 0.5401138E-1, &\n 0.5654656E-1, 0.5953130E-1, 0.6308489E-1, 0.6737503E-1, &\n 0.7264544E-1, 0.7926471E-1, 0.8781922E-1, 0.9930398E-1, &\n 0.1155599, 0.1404344, 0.1836142, 0.2790016, 0.7010474/)\n REAL, PARAMETER :: t(31) = (/ 0.7673828E-3, 0.2306870E-2, &\n 0.3860618E-2, 0.5438454E-2, 0.7050699E-2, 0.8708396E-2, &\n 0.1042357E-1, 0.1220953E-1, 0.1408125E-1, 0.1605579E-1, &\n 0.1815290E-1, 0.2039573E-1, 0.2281177E-1, 0.2543407E-1, &\n 0.2830296E-1, 0.3146822E-1, 0.3499233E-1, 0.3895483E-1, &\n 0.4345878E-1, 0.4864035E-1, 0.5468334E-1, 0.6184222E-1, &\n 0.7047983E-1, 0.8113195E-1, 0.9462444E-1, 0.1123001, 0.1364980, &\n 0.1716886, 0.2276241, 0.3304980, 0.5847031/)\n! ..\n! .. Executable Statements ..\n\n u = random_standard_uniform()\n s = 0.0\n IF (u>0.5) s = 1.0\n u = u + u - s\n u = 32.0*u\n i = MIN(INT(u),31)\n IF (i==0) GO TO 50\n\n! START CENTER\n\n ustar = u - FLOAT(i)\n aa = a(i)\n10 IF (ustar<=t(i)) GO TO 20\n w = (ustar-t(i))*h(i)\n CALL set_value\n RETURN\n\n! CENTER CONTINUED\n\n20 u = random_standard_uniform()\n w = u*(a(i+1)-aa)\n tt = (0.5*w+aa)*w\n GO TO 40\n\n30 tt = u\n ustar = random_standard_uniform()\n40 IF (ustar>tt) THEN\n CALL set_value\n RETURN\n END IF\n u = random_standard_uniform()\n IF (ustar>=u) GO TO 30\n ustar = random_standard_uniform()\n GO TO 10\n\n! START TAIL\n\n50 i = 6\n aa = a(32)\n GO TO 70\n\n60 aa = aa + d(i)\n i = i + 1\n70 u = u + u\n IF (u<1.0) GO TO 60\n u = u - 1.0\n80 w = u*d(i)\n tt = (0.5*w+aa)*w\n GO TO 100\n\n90 tt = u\n100 ustar = random_standard_uniform()\n IF (ustar>tt) THEN\n CALL set_value\n RETURN\n END IF\n u = random_standard_uniform()\n IF (ustar>=u) GO TO 90\n u = random_standard_uniform()\n GO TO 80\n\n CONTAINS\n\n!.....................................................................\n\n SUBROUTINE set_value\n! .. Implicit None Statement ..\n IMPLICIT NONE\n! ..\n! .. Executable Statements ..\n\n! EXIT (BOTH CASES)\n y = aa + w\n random_standard_normal = y\n IF (s==1.0) random_standard_normal = -y\n RETURN\n\n END SUBROUTINE set_value\n\n!.....................................................................\n\n END FUNCTION random_standard_normal\n\n!*********************************************************************\n\n END MODULE random_standard_normal_mod\n", "meta": {"hexsha": "0bccdab6d7a404336a7edcd781478b989d6e43cc", "size": 6432, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/random_standard_normal_mod.f90", "max_stars_repo_name": "urbanjost/fpm_tools", "max_stars_repo_head_hexsha": "3f7fb8db5473537a42bee51641e3d4cae927a730", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/random_standard_normal_mod.f90", "max_issues_repo_name": "urbanjost/fpm_tools", "max_issues_repo_head_hexsha": "3f7fb8db5473537a42bee51641e3d4cae927a730", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/random_standard_normal_mod.f90", "max_forks_repo_name": "urbanjost/fpm_tools", "max_forks_repo_head_hexsha": "3f7fb8db5473537a42bee51641e3d4cae927a730", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-07-14T11:36:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-14T11:36:01.000Z", "avg_line_length": 37.6140350877, "max_line_length": 75, "alphanum_fraction": 0.4208644279, "num_tokens": 2057, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.7577943822145998, "lm_q1q2_score": 0.6711265509968594}} {"text": "c program DRSEVVUN\nc>> 1996-05-28 DRSEVVUN Krogh Added external statement.\nc>> 1994-10-19 DRSEVVUN Krogh Changes to use M77CON\nc>> 1994-09-22 DRSEVVUN CLL\nc>> 1992-04-23 CLL\nc>> 1992-03-04 DRSEVVUN Krogh Initial version.\nc Demonstrate unsymmetric eigenvalue/eigenvector subroutine SEVVUN.\nc ------------------------------------------------------------------\nc--S replaces \"?\": DR?EVVUN, ?EVVUN, ?VECP, ?MATP, ?DOT\nc ------------------------------------------------------------------\n integer I, J, LDA, N\n parameter (LDA = 3)\n integer IFLAG(LDA)\n real A(LDA,LDA), VR(LDA), VI(LDA), VEC(LDA, LDA)\n real WORK(LDA), ASAV(LDA, LDA), D(LDA, LDA), ANORM\n external SDOT\n real SDOT\n data (A(1,I), I=1,3) / 8.0e0, -1.0e0, -5.0e0 /\n data (A(2,I), I=1,3) / -4.0e0, 4.0e0, -2.0e0 /\n data (A(3,I), I=1,3) / 18.0e0, -5.0e0, -7.0e0 /\n data ANORM / 30.0e0 /\n data N / LDA /\nc ------------------------------------------------------------------\n print*,'DRSEVVUN.. Demo driver for SEVVUN.'\nc\nc First copy A() to ASAV() for later residual check.\nc\n do 20 J = 1, N\n do 10 I = 1, N\n ASAV(I, J) = A(I, J)\n 10 continue\n 20 continue\n \n call SEVVUN(A(1, 1), LDA, N, VR, VI, VEC, IFLAG, WORK)\n \n print '(a, I2)',' IFLAG(1) =',IFLAG(1)\n if (IFLAG(1) .le. 2) then\n call SVECP(VR, N, ' Real part of the eigenvalues')\n call SVECP(VI, N, ' Imaginary part of the eigenvalues')\n call SMATP(VEC, LDA, N, N,\n * '0 Eigenvectors as columns or pairs of columns')\nc\nc As a check compute D = (ASAV*VEC - VEC*EVAL) / ANORM.\nc Expect D to be close to the machine precision.\nc\n do 50 J = 1, N\n if (VI(J) .eq. 0.0e0) then\nc Compute residual for a real eigenvalue and eigenvector\n do 30 I = 1, N\n D(I, J) = (SDOT(N, ASAV(I,1), LDA, VEC(1,J), 1) -\n * VEC(I,J) * VR(J)) / ANORM\n 30 continue\n else if (VI(J) .gt. 0.0e0) then\n do 40 I = 1, N\n D(I, J) = (SDOT(N,ASAV(I,1),LDA,VEC(1,J),1) -\n * VEC(I,J)*VR(J)+VEC(I,J+1)*VI(J))/ANORM\n D(I, J+1) = (SDOT(N,ASAV(I,1),LDA,VEC(1,J+1),1) -\n * VEC(I,J)*VI(J)-VEC(I,J+1)*VR(J))/ANORM\n 40 continue\n end if\n 50 continue\n call SMATP(D, LDA, N, N,\n * '0 Packed residual matrix D = (A*EVEC - EVEC*EVAL) / ANORM')\n else\n print'(/a)', ' Failure in SEVVUN. '\n end if\n stop\n end\n", "meta": {"hexsha": "314d2ebafcde68b034267b91843aac834f6623e0", "size": 2748, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drsevvun.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drsevvun.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drsevvun.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.8260869565, "max_line_length": 72, "alphanum_fraction": 0.4461426492, "num_tokens": 957, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.885631470799559, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.671126543595587}} {"text": "\tFUNCTION PR_TMKC ( tmpk )\nC************************************************************************\nC* PR_TMKC\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes TMPC from TMPK. The following equation is\t*\nC* used:\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* TMPC = TMPK - TMCK\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PR_TMKC ( TMPK )\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tTMPK\t\tREAL\t\tTemperature in Kelvin\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPR_TMKC\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* I. Graffman/CSC\t 8/83\tOriginal source code\t\t\t*\nC* I. Graffman/RDS\t12/87\tGEMPAK4\t\t\t\t\t*\nC* G. Huffman/GSC\t 8/88\tModified documentation\t\t\t*\nC* G. Krueger/EAI 4/96 Replaced C->K constant with TMCK\t*\nC************************************************************************\n INCLUDE 'GEMPRM.PRM'\n INCLUDE 'ERMISS.FNC'\nC------------------------------------------------------------------------\n\tIF ( ERMISS ( tmpk ) ) THEN\n\t PR_TMKC = RMISSD\n\t ELSE\n\t PR_TMKC = tmpk - TMCK\n\tEND IF\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "202fa506f664d2e9820c03707b1e32111ee6732b", "size": 1061, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/pr/prtmkc.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/prtmkc.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/prtmkc.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.3142857143, "max_line_length": 73, "alphanum_fraction": 0.4260131951, "num_tokens": 326, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6711265413080871}} {"text": "!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 1998 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Spherepack *\n! * *\n! * A Package of Fortran Subroutines and Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams and Paul Swarztrauber *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\nsubmodule(scalar_synthesis_routines) scalar_synthesis_gaussian_grid\n\ncontains\n\n ! Purpose:\n !\n ! This subroutine performs the spherical harmonic synthesis on\n ! a gaussian grid using the coefficients in array(s) a, b and returns\n ! the results in array(s) g. the legendre polynomials are computed\n ! as needed in this version.\n !\n ! subroutine shsgc(nlat, nlon, isym, nt, g, idg, jdg, a, b, mdab, ndab, &\n ! wshsgc, ierror)\n !\n ! subroutine shsgc performs the spherical harmonic synthesis\n ! on the arrays a and b and stores the result in the array g.\n ! the synthesis is performed on an equally spaced longitude grid\n ! and a gaussian colatitude grid. the associated legendre functions\n ! are recomputed rather than stored as they are in subroutine\n ! shsgs. the synthesis is described below at output parameter\n ! g.\n !\n ! input parameters\n !\n ! nlat the number of points in the gaussian colatitude grid on the\n ! full sphere. these lie in the interval (0, pi) and are compu\n ! in radians in theta(1), ..., theta(nlat) by subroutine compute_gaussian_latitudes_and_weights.\n ! if nlat is odd the equator will be included as the grid poi\n ! theta((nlat + 1)/2). if nlat is even the equator will be\n ! excluded as a grid point and will lie half way between\n ! theta(nlat/2) and theta(nlat/2+1). nlat must be at least 3.\n ! note: on the half sphere, the number of grid points in the\n ! colatitudinal direction is nlat/2 if nlat is even or\n ! (nlat + 1)/2 if nlat is odd.\n !\n ! nlon the number of distinct londitude points. nlon determines\n ! the grid increment in longitude as 2*pi/nlon. for example\n ! nlon = 72 for a five degree grid. nlon must be greater\n ! than or equal to 4. the efficiency of the computation is\n ! improved when nlon is a product of small prime numbers.\n !\n ! isym = 0 no symmetries exist about the equator. the synthesis\n ! is performed on the entire sphere. i.e. on the\n ! array g(i, j) for i=1, ..., nlat and j=1, ..., nlon.\n ! (see description of g below)\n !\n ! = 1 g is antisymmetric about the equator. the synthesis\n ! is performed on the northern hemisphere only. i.e.\n ! if nlat is odd the synthesis is performed on the\n ! array g(i, j) for i=1, ..., (nlat + 1)/2 and j=1, ..., nlon.\n ! if nlat is even the synthesis is performed on the\n ! array g(i, j) for i=1, ..., nlat/2 and j=1, ..., nlon.\n !\n !\n ! = 2 g is symmetric about the equator. the synthesis is\n ! performed on the northern hemisphere only. i.e.\n ! if nlat is odd the synthesis is performed on the\n ! array g(i, j) for i=1, ..., (nlat + 1)/2 and j=1, ..., nlon.\n ! if nlat is even the synthesis is performed on the\n ! array g(i, j) for i=1, ..., nlat/2 and j=1, ..., nlon.\n !\n ! nt the number of syntheses. in the program that calls shsgc,\n ! the arrays g, a and b can be three dimensional in which\n ! case multiple synthesis will be performed. the third\n ! index is the synthesis index which assumes the values\n ! k=1, ..., nt. for a single synthesis set nt=1. the\n ! discription of the remaining parameters is simplified\n ! by assuming that nt=1 or that the arrays g, a and b\n ! have only two dimensions.\n !\n ! idg the first dimension of the array g as it appears in the\n ! program that calls shsgc. if isym equals zero then idg\n ! must be at least nlat. if isym is nonzero then idg must\n ! be at least nlat/2 if nlat is even or at least (nlat + 1)/2\n ! if nlat is odd.\n !\n ! jdg the second dimension of the array g as it appears in the\n ! program that calls shsgc. jdg must be at least nlon.\n !\n ! mdab the first dimension of the arrays a and b as it appears\n ! in the program that calls shsgc. mdab must be at least\n ! min((nlon+2)/2, nlat) if nlon is even or at least\n ! min((nlon + 1)/2, nlat) if nlon is odd\n !\n ! ndab the second dimension of the arrays a and b as it appears\n ! in the program that calls shsgc. ndab must be at least nlat\n !\n ! a, b two or three dimensional arrays (see the input parameter\n ! nt) that contain the coefficients in the spherical harmonic\n ! expansion of g(i, j) given below at the definition of the\n ! output parameter g. a(m, n) and b(m, n) are defined for\n ! indices m=1, ..., mmax and n=m, ..., nlat where mmax is the\n ! maximum (plus one) longitudinal wave number given by\n ! mmax = min(nlat, (nlon+2)/2) if nlon is even or\n ! mmax = min(nlat, (nlon + 1)/2) if nlon is odd.\n !\n ! wshsgc an array which must be initialized by subroutine shsgci.\n ! once initialized, wshsgc can be used repeatedly by shsgc\n ! as long as nlat and nlon remain unchanged. wshsgc must\n ! not be altered between calls of shsgc.\n !\n ! lshsgc the dimension of the array wshsgc as it appears in the\n ! program that calls shsgc. define\n !\n ! l1 = min(nlat, (nlon+2)/2) if nlon is even or\n ! l1 = min(nlat, (nlon + 1)/2) if nlon is odd\n !\n ! and\n !\n ! l2 = nlat/2 if nlat is even or\n ! l2 = (nlat + 1)/2 if nlat is odd\n !\n ! then lshsgc must be at least\n !\n ! nlat*(2*l2+3*l1-2)+3*l1*(1-l1)/2+nlon+15\n !\n ! output parameters\n !\n ! g a two or three dimensional array (see input parameter nt)\n ! that contains the discrete function which is synthesized.\n ! g(i, j) contains the value of the function at the gaussian\n ! colatitude point theta(i) and longitude point\n ! phi(j) = (j-1)*2*pi/nlon. the index ranges are defined\n ! above at the input parameter isym. for isym=0, g(i, j)\n ! is given by the the equations listed below. symmetric\n ! versions are used when isym is greater than zero.\n !\n ! the normalized associated legendre functions are given by\n !\n ! pbar(m, n, theta) = sqrt((2*n+1)*factorial(n-m)/(2*factorial(n+m)))\n ! *sin(theta)**m/(2**n*factorial(n)) times the\n ! (n+m)th derivative of (x**2-1)**n with respect\n ! to x=cos(theta)\n !\n !\n ! define the maximum (plus one) longitudinal wave number\n ! as mmax = min(nlat, (nlon+2)/2) if nlon is even or\n ! mmax = min(nlat, (nlon + 1)/2) if nlon is odd.\n !\n ! then g(i, j) = the sum from n=0 to n=nlat-1 of\n !\n ! .5*pbar(0, n, theta(i))*a(1, n+1)\n !\n ! plus the sum from m=1 to m=mmax-1 of\n !\n ! the sum from n=m to n=nlat-1 of\n !\n ! pbar(m, n, theta(i))*(a(m+1, n+1)*cos(m*phi(j))\n ! -b(m+1, n+1)*sin(m*phi(j)))\n !\n ! ierror = 0 no errors\n ! = 1 error in the specification of nlat\n ! = 2 error in the specification of nlon\n ! = 3 error in the specification of isym\n ! = 4 error in the specification of nt\n ! = 5 error in the specification of idg\n ! = 6 error in the specification of jdg\n ! = 7 error in the specification of mdab\n ! = 8 error in the specification of ndab\n ! = 9 error in the specification of lshsgc\n !\n module subroutine shsgc(nlat, nlon, mode, nt, g, idg, jdg, a, b, mdab, ndab, &\n wshsgc, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n integer(ip), intent(in) :: mode\n integer(ip), intent(in) :: nt\n real(wp), intent(out) :: g(idg, jdg, nt)\n integer(ip), intent(in) :: idg\n integer(ip), intent(in) :: jdg\n real(wp), intent(in) :: a(mdab, ndab, nt)\n real(wp), intent(in) :: b(mdab, ndab, nt)\n integer(ip), intent(in) :: mdab\n integer(ip), intent(in) :: ndab\n real(wp), intent(in) :: wshsgc(:)\n integer(ip), intent(out) :: ierror\n\n ! Local variables\n integer(ip) :: mtrunc, lat, late\n integer(ip) :: required_wavetable_size\n type(SpherepackUtility) :: util\n\n ! Check input arguments\n required_wavetable_size = util%get_lshsgc(nlat, nlon)\n\n call util%check_scalar_transform_inputs(mode, idg, jdg, &\n mdab, ndab, nlat, nlon, nt, required_wavetable_size, &\n wshsgc, ierror)\n\n ! Check error flag\n if (ierror /= 0) return\n\n ! Set limit for m in a(m, n), b(m, n) computation\n mtrunc = min((nlon+2)/2, nlat)\n\n ! Set gaussian point nearest equator pointer\n late = (nlat+mod(nlat, 2))/2\n\n ! Set number of grid points for analysis/synthesis\n select case (mode)\n case (0)\n lat = nlat\n case default\n lat = late\n end select\n\n block\n integer(ip) :: ifft\n\n ! Starting address fft values\n ifft = nlat+2*nlat*late+3*(mtrunc*(mtrunc-1)/2+(nlat-mtrunc)*(mtrunc-1))+1\n\n call shsgc_lower_utility_routine(nlat, nlon, mtrunc, lat, mode, g, idg, &\n jdg, nt, a, b, mdab, ndab, wshsgc, wshsgc(ifft:), late)\n end block\n\n end subroutine shsgc\n\n ! Purpose:\n !\n ! This subroutine must be called before calling shsgc with\n ! fixed nlat, nlon. it precomputes quantites such as the gaussian\n ! points and weights, m=0, m=1 legendre polynomials, recursion\n ! recursion coefficients.\n !\n ! subroutine shsgci(nlat, nlon, wshsgc, ierror)\n !\n ! subroutine shsgci initializes the array wshsgc which can then\n ! be used repeatedly by subroutines shsgc. it precomputes\n ! and stores in wshsgc quantities such as gaussian weights,\n ! legendre polynomial coefficients, and fft trigonometric tables.\n !\n ! input parameters\n !\n ! nlat the number of points in the gaussian colatitude grid on the\n ! full sphere. these lie in the interval (0, pi) and are compu\n ! in radians in theta(1), ..., theta(nlat) by subroutine compute_gaussian_latitudes_and_weights.\n ! if nlat is odd the equator will be included as the grid poi\n ! theta((nlat + 1)/2). if nlat is even the equator will be\n ! excluded as a grid point and will lie half way between\n ! theta(nlat/2) and theta(nlat/2+1). nlat must be at least 3.\n ! note: on the half sphere, the number of grid points in the\n ! colatitudinal direction is nlat/2 if nlat is even or\n ! (nlat + 1)/2 if nlat is odd.\n !\n ! nlon the number of distinct londitude points. nlon determines\n ! the grid increment in longitude as 2*pi/nlon. for example\n ! nlon = 72 for a five degree grid. nlon must be greater\n ! than or equal to 4. the efficiency of the computation is\n ! improved when nlon is a product of small prime numbers.\n !\n ! wshsgc an array which must be initialized by subroutine shsgci.\n ! once initialized, wshsgc can be used repeatedly by shsgc\n ! as long as nlat and nlon remain unchanged. wshsgc must\n ! not be altered between calls of shsgc.\n !\n ! lshsgc the dimension of the array wshsgc as it appears in the\n ! program that calls shsgc. define\n !\n ! l1 = min(nlat, (nlon+2)/2) if nlon is even or\n ! l1 = min(nlat, (nlon + 1)/2) if nlon is odd\n !\n ! and\n !\n ! l2 = nlat/2 if nlat is even or\n ! l2 = (nlat + 1)/2 if nlat is odd\n !\n ! then lshsgc must be at least\n !\n ! nlat*(2*l2+3*l1-2)+3*l1*(1-l1)/2+nlon+15\n !\n ! output parameter\n !\n ! wshsgc an array which must be initialized before calling shsgc.\n ! once initialized, wshsgc can be used repeatedly by shsgc\n ! as long as nlat and nlon remain unchanged. wshsgc must not\n ! altered between calls of shsgc.\n !\n ! ierror = 0 no errors\n ! = 1 error in the specification of nlat\n ! = 2 error in the specification of nlon\n ! = 3 error in the specification of lshsgc\n ! = 5 failure in compute_gaussian_latitudes_and_weights to compute gaussian points\n ! (due to failure in eigenvalue routine)\n !\n !\n module subroutine shsgci(nlat, nlon, wshsgc, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n real(wp), intent(out) :: wshsgc(:)\n integer(ip), intent(out) :: ierror\n\n ! Local variables\n integer(ip) :: i1\n integer(ip) :: i2\n integer(ip) :: i3\n integer(ip) :: i4\n integer(ip) :: i5\n integer(ip) :: i6\n integer(ip) :: i7\n integer(ip) :: idth\n integer(ip) :: idwts\n integer(ip) :: iw\n integer(ip) :: ntrunc\n integer(ip) :: l1\n integer(ip) :: l2\n integer(ip) :: late, ldwork\n\n associate (lshsgc => size(wshsgc))\n\n ! Set triangular truncation limit for spherical harmonic basis\n ntrunc = min((nlon+2)/2, nlat)\n\n ! Set equator or nearest point (if excluded) pointer\n late = (nlat+mod(nlat, 2))/2\n l1 = ntrunc\n l2 = late\n\n ! Check calling arguments\n if (nlat < 3) then\n ierror = 1\n else if (nlon < 4) then\n ierror = 2\n else if (lshsgc < nlat*(2*l2+3*l1-2)+3*l1*(1-l1)/2+nlon+15) then\n ierror = 3\n else\n ierror = 0\n end if\n\n ! Check error flag\n if (ierror /= 0) return\n\n ! Set index pointers\n i1 = 1\n i2 = i1+nlat\n i3 = i2+nlat*late\n i4 = i3+nlat*late\n i5 = i4+ntrunc*(ntrunc-1)/2 +(nlat-ntrunc)*(ntrunc-1)\n i6 = i5+ntrunc*(ntrunc-1)/2 +(nlat-ntrunc)*(ntrunc-1)\n i7 = i6+ntrunc*(ntrunc-1)/2 +(nlat-ntrunc)*(ntrunc-1)\n\n ! Set indices in temp work for real gaussian wts and pts\n idth = 1\n idwts = idth + nlat\n iw = idwts + nlat\n\n ! Set required workspace size\n ldwork = nlat * (nlat + 4)\n\n block\n real(wp) :: dwork(ldwork)\n call shsgci_lower_utility_routine(nlat, nlon, ntrunc, late, wshsgc(i1:), &\n wshsgc(i2:), wshsgc(i3:), wshsgc(i4:), wshsgc(i5:), wshsgc(i6:), &\n wshsgc(i7:), dwork(idth:), dwork(idwts:), dwork(iw:), ierror)\n end block\n\n ! Check error flag from lower utility routine\n if (ierror /= 0) ierror = 5\n end associate\n\n end subroutine shsgci\n\n subroutine shsgc_lower_utility_routine(nlat, nlon, l, lat, mode, gs, idg, jdg, &\n nt, a, b, mdab, ndab, w, wfft, late)\n\n ! Dummy arguments\n real(wp) :: a(mdab, ndab, nt), b(mdab, ndab, nt)\n real(wp) :: gs(idg, jdg, nt)\n real(wp) :: w(:), wfft(:)\n integer(ip) :: i\n integer(ip) :: idg\n integer(ip) :: is\n \n integer(ip) :: jdg\n integer(ip) :: k\n integer(ip) :: km\n integer(ip) :: l\n integer(ip) :: lat\n integer(ip) :: late\n integer(ip) :: lm1\n integer(ip) :: lp1\n integer(ip) :: m\n integer(ip) :: mdab\n integer(ip) :: meo\n integer(ip) :: mode\n integer(ip) :: mp1\n integer(ip) :: mp2\n integer(ip) :: ms\n integer(ip) :: ndab\n integer(ip) :: nl2\n integer(ip) :: nlat\n integer(ip) :: nlon\n integer(ip) :: np1\n integer(ip) :: ns\n integer(ip) :: nt\n real(wp) :: t1\n real(wp) :: t2\n real(wp) :: t3\n real(wp) :: t4\n type(SpherepackUtility) :: util\n\n ! reconstruct fourier coefficients in g on gaussian grid\n ! using coefficients in a, b\n ! set m+1 limit for b coefficient calculation\n\n block\n real(wp) :: pmn(nlat, late, 3), g(lat, nlon, nt)\n\n if (nlon == 2*l-2) then\n lm1 = l-1\n else\n lm1 = l\n end if\n\n ! Initialize to zero\n g = ZERO\n\n select case (mode)\n case (0)\n ! Set first column in g\n m = 0\n\n ! Compute pmn for all i and n=m, ..., l-1\n call util%compute_legendre_polys_for_gaussian_grids(mode, l, nlat, m, w, pmn, km)\n\n do k=1, nt\n ! n even\n do np1=1, nlat, 2\n do i=1, late\n g(i, 1, k) = g(i, 1, k)+a(1, np1, k)*pmn(np1, i, km)\n end do\n end do\n ! n odd\n nl2 = nlat/2\n do np1=2, nlat, 2\n do i=1, nl2\n is = nlat-i+1\n g(is, 1, k) = g(is, 1, k)+a(1, np1, k)*pmn(np1, i, km)\n end do\n end do\n ! restore m=0 coefficents (reverse implicit even/odd reduction)\n do i=1, nl2\n is = nlat-i+1\n t1 = g(i, 1, k)\n t3 = g(is, 1, k)\n g(i, 1, k) = t1+t3\n g(is, 1, k) = t1-t3\n end do\n end do\n\n ! Sweep columns of g for which b is available\n do mp1=2, lm1\n m = mp1-1\n mp2 = m+2\n ! compute pmn for all i and n=m, ..., l-1\n call util%compute_legendre_polys_for_gaussian_grids(mode, l, nlat, m, w, pmn, km)\n do k=1, nt\n ! for n-m even store (g(i, p, k)+g(nlat-i+1, p, k))/2 in g(i, p, k) p=2*m,\n ! for i=1, ..., late\n do np1=mp1, nlat, 2\n do i=1, late\n g(i, 2*m, k) = g(i, 2*m, k)+a(mp1, np1, k)*pmn(np1, i, km)\n g(i, 2*m+1, k) = g(i, 2*m+1, k)+b(mp1, np1, k)*pmn(np1, i, km)\n end do\n end do\n ! for n-m odd store g(i, p, k)-g(nlat-i+1, p, k) in g(nlat-i+1, p, k)\n ! for i=1, ..., nlat/2 (p=2*m, p=2*m+1)\n do np1=mp2, nlat, 2\n do i=1, nl2\n is = nlat-i+1\n g(is, 2*m, k) = g(is, 2*m, k)+a(mp1, np1, k)*pmn(np1, i, km)\n g(is, 2*m+1, k) = g(is, 2*m+1, k)+b(mp1, np1, k)*pmn(np1, i, km)\n end do\n end do\n ! now set fourier coefficients using even-odd reduction above\n do i=1, nl2\n is = nlat-i+1\n t1 = g(i, 2*m, k)\n t2 = g(i, 2*m+1, k)\n t3 = g(is, 2*m, k)\n t4 = g(is, 2*m+1, k)\n g(i, 2*m, k) = t1+t3\n g(i, 2*m+1, k) = t2+t4\n g(is, 2*m, k) = t1-t3\n g(is, 2*m+1, k) = t2-t4\n end do\n end do\n end do\n ! set last column (using a only)\n if (nlon== l+l-2) then\n m = l-1\n call util%compute_legendre_polys_for_gaussian_grids(mode, l, nlat, m, w, pmn, km)\n do k=1, nt\n ! n-m even\n do np1=l, nlat, 2\n do i=1, late\n g(i, nlon, k) = g(i, nlon, k)+TWO*a(l, np1, k)*pmn(np1, i, km)\n end do\n end do\n lp1 = l+1\n ! n-m odd\n do np1=lp1, nlat, 2\n do i=1, nl2\n is = nlat-i+1\n g(is, nlon, k) = g(is, nlon, k)+TWO*a(l, np1, k)*pmn(np1, i, km)\n end do\n end do\n do i=1, nl2\n is = nlat-i+1\n t1 = g(i, nlon, k)\n t3 = g(is, nlon, k)\n g(i, nlon, k)= t1+t3\n g(is, nlon, k)= t1-t3\n end do\n end do\n end if\n case default\n ! half sphere\n ! set first column in g\n m = 0\n meo = 1\n if (mode == 1) meo = 2\n ms = m+meo\n ! compute pmn for all i and n=m, ..., l-1\n call util%compute_legendre_polys_for_gaussian_grids(mode, l, nlat, m, w, pmn, km)\n do k=1, nt\n do np1=ms, nlat, 2\n do i=1, late\n g(i, 1, k) = g(i, 1, k)+a(1, np1, k)*pmn(np1, i, km)\n end do\n end do\n end do\n ! sweep interior columns of g\n do mp1=2, lm1\n m = mp1-1\n ms = m+meo\n ! compute pmn for all i and n=m, ..., l-1\n call util%compute_legendre_polys_for_gaussian_grids(mode, l, nlat, m, w, pmn, km)\n do k=1, nt\n do np1=ms, nlat, 2\n do i=1, late\n g(i, 2*m, k) = g(i, 2*m, k)+a(mp1, np1, k)*pmn(np1, i, km)\n g(i, 2*m+1, k) = g(i, 2*m+1, k)+b(mp1, np1, k)*pmn(np1, i, km)\n end do\n end do\n end do\n end do\n if (nlon==l+l-2) then\n ! set last column\n m = l-1\n call util%compute_legendre_polys_for_gaussian_grids(mode, l, nlat, m, w, pmn, km)\n\n select case (mode)\n case (1)\n ns = l+1\n case default\n ns = l\n end select\n\n do k=1, nt\n do i=1, late\n do np1=ns, nlat, 2\n g(i, nlon, k) = g(i, nlon, k) + TWO * a(l, np1, k) * pmn(np1, i, km)\n end do\n end do\n end do\n end if\n end select\n\n ! Do inverse fourier transform\n do k=1, nt\n call util%hfft%backward(lat, nlon, g(:, :, k), lat, wfft)\n end do\n\n ! scale output in gs\n gs(1:lat, 1:nlon, :) = HALF * g(1:lat, 1:nlon, :)\n end block\n\n end subroutine shsgc_lower_utility_routine\n\n subroutine shsgci_lower_utility_routine(nlat, nlon, l, late, wts, p0n, p1n, abel, bbel, cbel, &\n wfft, dtheta, dwts, work, ier)\n\n real(wp) :: abel\n real(wp) :: bbel\n real(wp) :: cbel\n integer(ip) :: i\n integer(ip) :: ier\n integer(ip) :: imn\n \n \n integer(ip) :: l\n integer(ip) :: late\n integer(ip) :: lw\n integer(ip) :: m\n integer(ip) :: mlim\n integer(ip) :: n\n integer(ip) :: nlat\n integer(ip) :: nlon\n integer(ip) :: np1\n real(wp) :: p0n\n real(wp) :: p1n\n real(wp) :: wfft\n real(wp) :: wts\n dimension wts(nlat), p0n(nlat, late), p1n(nlat, late), abel(*), bbel(*), &\n cbel(*), wfft(*)\n real(wp) :: pb, dtheta(nlat), dwts(nlat), work(*)\n type(SpherepackUtility) :: util\n\n ! compute the nlat gaussian points and weights, the\n ! m=0, 1 legendre polys for gaussian points and all n, \n ! and the legendre recursion coefficients\n ! define index function used in storing\n ! arrays for recursion coefficients (functions of (m, n))\n ! the index function indx(m, n) is defined so that\n ! the pairs (m, n) map to [1, 2, ..., indx(l-1, l-1)] with no\n ! \"holes\" as m varies from 2 to n and n varies from 2 to l-1.\n ! (m=0, 1 are set from p0n, p1n for all n)\n ! define for 2<=n<=l-1\n !indx(m, n) = (n-1)*(n-2)/2+m-1\n ! define index function for l<=n<=nlat\n !imndx(m, n) = l*(l-1)/2+(n-l-1)*(l-1)+m-1\n ! preset quantites for fourier transform\n call util%hfft%initialize(nlon, wfft)\n ! compute real gaussian points and weights\n ! lw = 4*nlat*(nlat + 1)+2\n lw = nlat*(nlat+2)\n call compute_gaussian_latitudes_and_weights(nlat, dtheta, dwts, ier)\n if (ier/=0) return\n ! store gaussian weights single precision to save computation\n ! in inner loops in analysis\n wts = dwts\n ! initialize p0n, p1n using real dnlfk, dnlft\n p0n = ZERO\n p1n = ZERO\n\n ! compute m=n=0 legendre polynomials for all theta(i)\n np1 = 1\n n = 0\n m = 0\n call util%compute_fourier_coefficients(m, n, work)\n do i=1, late\n call util%compute_legendre_polys_from_fourier_coeff(m, n, dtheta(i), work, pb)\n p0n(1, i) = pb\n end do\n ! compute p0n, p1n for all theta(i) when n>0\n do np1=2, nlat\n n = np1-1\n m = 0\n call util%compute_fourier_coefficients(m, n, work)\n do i=1, late\n call util%compute_legendre_polys_from_fourier_coeff(m, n, dtheta(i), work, pb)\n p0n(np1, i) = pb\n end do\n ! compute m=1 legendre polynomials for all n and theta(i)\n m = 1\n call util%compute_fourier_coefficients(m, n, work)\n do i=1, late\n call util%compute_legendre_polys_from_fourier_coeff(m, n, dtheta(i), work, pb)\n p1n(np1, i) = pb\n end do\n end do\n ! compute and store swarztrauber recursion coefficients\n ! for 2<=m<=n and 2<=n<=nlat in abel, bbel, cbel\n do n=2, nlat\n mlim = min(n, l)\n do m=2, mlim\n\n if (n >= l) then\n imn = l*(l-1)/2+(n-l-1)*(l-1)+m-1\n else\n imn = (n-1)*(n-2)/2+m-1\n end if\n\n abel(imn)=sqrt(real((2*n+1)*(m+n-2)*(m+n-3))/ &\n real(((2*n-3)*(m+n-1)*(m+n))))\n bbel(imn)=sqrt(real((2*n+1)*(n-m-1)*(n-m))/ &\n real(((2*n-3)*(m+n-1)*(m+n))))\n cbel(imn)=sqrt(real((n-m+1)*(n-m+2))/ &\n real(((n+m-1)*(n+m))))\n end do\n end do\n\n end subroutine shsgci_lower_utility_routine\n\nend submodule scalar_synthesis_gaussian_grid\n", "meta": {"hexsha": "1c499e26e1550335d035b676837fdcf679eee89f", "size": 31183, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/scalar_synthesis_gaussian_grid.f90", "max_stars_repo_name": "jlokimlin/spherepack4.1", "max_stars_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-06-28T14:01:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T21:59:28.000Z", "max_issues_repo_path": "src/scalar_synthesis_gaussian_grid.f90", "max_issues_repo_name": "jlokimlin/spherepack4.1", "max_issues_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2016-05-07T23:00:35.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-22T23:52:30.000Z", "max_forks_repo_path": "src/scalar_synthesis_gaussian_grid.f90", "max_forks_repo_name": "jlokimlin/spherepack4.1", "max_forks_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-06-28T14:03:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T12:53:54.000Z", "avg_line_length": 43.1897506925, "max_line_length": 111, "alphanum_fraction": 0.4396626367, "num_tokens": 8442, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.885631470799559, "lm_q2_score": 0.7577943658046609, "lm_q1q2_score": 0.6711265387512008}} {"text": "!\n! file thwscrt.f90\n!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 2005 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Fishpack *\n! * *\n! * A Package of Fortran *\n! * *\n! * Subroutines and Example Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams, Paul Swarztrauber and Roland Sweet *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\nprogram test_hwscrt\n\n use fishpack\n\n ! Explicit typing only\n implicit none\n\n ! Dictionary\n integer(ip), parameter :: M = 40, N = 80\n integer(ip), parameter :: MP1 = M + 1, NP1 = N + 1\n integer(ip), parameter :: IDIMF = M + 5\n integer(ip) :: mbdcnd, nbdcnd, i, j, ierror\n real(wp) :: f(IDIMF, NP1), x(MP1)\n real(wp), dimension(NP1) :: bdb, y\n real(wp), dimension(1) :: bda, bdc, bdd\n real(wp) :: a, b, c, d, elmbda, pertrb\n real(wp), parameter :: PI2 = PI**2\n real(wp), parameter :: ZERO = 0.0_wp, ONE = 1.0_wp\n real(wp), parameter :: TWO = 2.0_wp, THREE = 3.0_wp, FOUR = 4.0_wp\n\n ! Set domain\n a = ZERO\n b = TWO\n c = -ONE\n d = THREE\n\n ! Set boundary conditions\n mbdcnd = 2\n nbdcnd = 0\n\n ! Set helmholtz constant\n elmbda = -FOUR\n\n ! Generate and store grid points for the purpose of computing\n ! boundary data and the right side of the helmholtz equation.\n do i = 1, MP1\n x(i) = TWO * real(i - 1, kind=wp)/M\n end do\n\n do j = 1, NP1\n y(j) = -ONE + FOUR * real(j - 1, kind=wp)/N\n end do\n\n ! Generate boundary data.\n ! In our example, bda, bdc, and bdd are 1-dimensional dummy variables.\n bdb = FOUR * cos((y + ONE) * HALF_PI)\n\n ! Generate right side of equation.\n f = ZERO\n do j = 1, NP1\n do i = 2, MP1\n f(i, j) = (TWO - (FOUR + PI2/4)*(x(i)**2)) * cos((y(j) + ONE)*HALF_PI)\n end do\n end do\n\n ! Solve 2D Helmholtz in cartesian coordinates on a centered grid\n call hwscrt(a, b, M, mbdcnd, bda, bdb, c, d, N, nbdcnd, bdc, bdd, &\n elmbda, f, IDIMF, pertrb, ierror)\n\n ! Compute discretization error. The exact solution is\n !\n ! u(x, y) = (x**2) * cos((y+1)*(pi/2))\n block\n real(wp), parameter :: KNOWN_ERROR = 0.536508246868017e-3_wp\n real(wp) :: discretization_error\n real(wp) :: exact_solution(MP1, NP1)\n\n do j = 1, NP1\n do i = 1, MP1\n exact_solution(i,j) = (x(i)**2) * cos((y(j)+ONE) * HALF_PI)\n end do\n end do\n\n ! Set discretization error\n discretization_error = maxval(abs(exact_solution - f(:MP1,:NP1)))\n\n call check_output('hwscrt', ierror, KNOWN_ERROR, discretization_error)\n end block\n\nend program test_hwscrt\n", "meta": {"hexsha": "6584ca36639acdf4dc52d925ff9de9717f367096", "size": 4543, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/thwscrt.f90", "max_stars_repo_name": "jlokimlin/fishpack", "max_stars_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2018-03-12T11:31:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-27T07:58:23.000Z", "max_issues_repo_path": "examples/thwscrt.f90", "max_issues_repo_name": "jlokimlin/fishpack", "max_issues_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2016-05-07T22:42:47.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-15T17:44:58.000Z", "max_forks_repo_path": "examples/thwscrt.f90", "max_forks_repo_name": "jlokimlin/modern_fishpack", "max_forks_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-01-26T20:49:05.000Z", "max_forks_repo_forks_event_max_datetime": "2017-01-27T16:44:58.000Z", "avg_line_length": 39.5043478261, "max_line_length": 82, "alphanum_fraction": 0.3570327977, "num_tokens": 1118, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.757794360334681, "lm_q1q2_score": 0.6711265316193147}} {"text": " SUBROUTINE DCOSSINFT2D(Y,n1_max,N1,n2,wrk)\n!\n! This routine is the same as DCOSFT2D except that in the second\n! direction a SINFT is performed.\n!\n IMPLICIT NONE\n INTEGER n1_max, n1, n2\n REAL*8 Y(N1_max,n2), wrk(n2)\n INTEGER j, k\n\n DO k=1,n2\n CALL dcosft(y(1,k),n1-1)\n END DO\n DO j=1,n1\n DO k=1,n2\n wrk(k)=y(j,k)\n END DO\n CALL dsinft(wrk,n2-1)\n DO k=1,n2\n y(j,k)=wrk(k)\n END DO\n END DO\n\n RETURN\n END SUBROUTINE DCOSSINFT2D\n", "meta": {"hexsha": "228724c0e6a1776b76e3c871417f6d9b0062c365", "size": 549, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fft/DCOSSINFT2D.f90", "max_stars_repo_name": "apengsigkarup/OceanWave3D", "max_stars_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 46, "max_stars_repo_stars_event_min_datetime": "2016-01-08T12:36:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T06:56:45.000Z", "max_issues_repo_path": "src/fft/DCOSSINFT2D.f90", "max_issues_repo_name": "apengsigkarup/OceanWave3D", "max_issues_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-10-10T19:45:08.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-07T07:37:11.000Z", "max_forks_repo_path": "src/fft/DCOSSINFT2D.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": 21.1153846154, "max_line_length": 64, "alphanum_fraction": 0.5264116576, "num_tokens": 200, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8633916099737807, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.6711141874803572}} {"text": "SUBROUTINE LUfact(a,n,ndim,b,epsilon,work,ipiv,returnCode)\n\n ! -------------------------------------------------------------------------\n ! NAME: LUfact\n ! PARENT: Solve\n ! STATUS: Current\n ! OWNER: Toshiro Matsumoto\n ! TEXT: Called from subroutine 'Solve'. Solve systems of linear algebraic\n ! equations by LU factorization method.\n ! REVISION DATE: 16-Jul-2009\n ! -------------------------------------------------------------------------\n\n USE PrecTypes\n IMPLICIT NONE\n \n INTEGER, INTENT(IN) :: n,ndim\n INTEGER, INTENT(INOUT) :: ipiv(*)\n REAL(dp), INTENT(INOUT) :: epsilon\n REAL(dp), INTENT(INOUT) :: a(ndim,*),b(*),work(*)\n REAL(dp) :: ABSa, wk, aa, ba, minusb, wmax\n INTEGER, INTENT(OUT) :: returnCode\n INTEGER :: i, ii, j, k, kk, ir, iir\n\n ! Checking the arguments\n IF (ndim < n) THEN\n\n ! Error of the input argument\n WRITE(*,'(\"(LUfact) Invalid argument.\",/,\"n=\",I5, /,\"ndim =\",I5)') n,ndim\n returnCode = 3\n RETURN\n\n ELSE IF (ndim >= n) THEN\n IF (n < 1) THEN\n ! Error of the input argument\n WRITE(6,10) n,ndim\n 10 FORMAT('(LUfact) Invalid argument.',/,'n=',I5, /,'ndim =',I5)\n returnCode = 3\n RETURN\n\n ELSE IF (n == 1) THEN\n\n ! When the matrix size is one\n IF (a(1,1) == 0.0_dp) THEN\n ! Matrix singular case\n WRITE(*,'(\"(LUfact) Matrix is singular.\")')\n returnCode = 1\n RETURN\n ELSE\n returnCode = 0\n b(1) = b(1)/a(1,1)\n ipiv(1) = 1\n RETURN\n END IF\n\n ELSE ! if n > 1\n IF (epsilon < 0.0_dp) epsilon = 1.0D-14\n END IF\n END IF\n\n ! \u521d\u671f\u5316\n DO i=1,n\n work(i) = ABS(a(i,1))\n ipiv(i) = i\n END DO\n\n ! Finding the maximum component of each row\n DO j=2,n\n DO i=1,n\n ABSa = ABS(a(i,j))\n wk = work(i)\n IF (wk < ABSa) work(i) = ABSa\n END DO\n END DO\n \n DO i=1,n\n wk = work(i)\n IF ( wk == 0.0_dp) THEN\n WRITE(*,'(\"(LUfact) Matrix is singular.\")')\n returnCode = 1\n RETURN\n ELSE \n work(i) = 1.0_dp/work(i)\n END IF\n END DO\n\n ! Starting the LU-decomposition\n DO k=1,n\n IF (k /= 1) THEN\n\n DO j=1,k-1\n ir = ipiv(j)\n aa = - a(ir,k) * a(ir,j)\n a(ir,k) = - aa\n DO ii=j+1,n\n i = ipiv(ii)\n a(i,k) = a(i,k) + a(i,j)*aa\n END DO\n END DO\n END IF\n\n ! Finding the maximum component of the k-th column\n wmax = 0.0_dp\n DO ii=k,n\n i = ipiv(ii)\n wk = ABS(a(i,k))*work(i)\n IF (wmax < wk) THEN\n iir = ii\n wmax = wk\n END IF\n END DO\n\n ! Checking if the matrix is singular or not\n IF (wmax <= epsilon) THEN\n IF (wmax == 0.0_dp) THEN\n WRITE(*,'(\"(LUfact) Matrix is singular.\")')\n returnCode = 1\n ELSE\n WRITE(*,'(\"(LUfac) Matrix became singular at the factorizing step :\", I5)') k\n returnCode = 2\n END IF\n RETURN\n END IF\n\n ir = ipiv(iir)\n ipiv(iir) = ipiv(k)\n ipiv(k) = ir\n a(ir,k) = 1.0_dp/a(ir,k)\n END DO\n\n IF (n < 1) THEN\n WRITE(*,'(\"(LUfact) Invalid argument.\",/,\"n=\",I5, /,\"ndim =\",I5)') n,ndim\n returnCode = 3\n RETURN\n ELSE IF (n == 1) THEN\n ! When the matrix size is one\n IF (a(1,1) == 0.0_dp) THEN\n ! Matrix singular case\n WRITE(*,'(\"(LUfact) Matrix is singular.\")')\n returnCode = 1\n RETURN\n ELSE\n returnCode = 0\n b(1) = b(1)/a(1,1)\n ipiv(1) = 1\n RETURN\n END IF\n else ! if n > 1\n\n ! Forward substitution\n DO k=1,n-1\n ir = ipiv(k)\n ba = -b(ir)*a(ir,k)\n b(ir) = -ba\n DO ii=k+1,n\n i = ipiv(ii)\n b(i) = a(i,k)*ba+b(i)\n END DO\n END DO\n b(i) = b(i)*a(i,n)\n\n ! Backward substitution\n DO kk=2,n\n k = n-kk+2\n minusb = -b(i)\n DO ii=1,k-1\n i = ipiv(ii)\n b(i) = a(i,k)*minusb+b(i)\n END DO\n END DO\n DO k=1,n\n work(k) = b(k)\n END DO\n DO k=1,n\n i = ipiv(k)\n b(k) = work(i)\n END DO\n returnCode = 0\n \n END IF\n \n RETURN\n\nEND SUBROUTINE LUfact\n", "meta": {"hexsha": "dc47e106d295f7e1595b3dfc67bebab3d97dddec", "size": 4385, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "LUfact.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": "LUfact.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": "LUfact.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": 23.8315217391, "max_line_length": 89, "alphanum_fraction": 0.4451539339, "num_tokens": 1408, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916029436189, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.6711141820158134}} {"text": "*----------------------------------------------------------------------*\n subroutine dmdiagm(ndim,mat,diag,right,inverted)\n*----------------------------------------------------------------------*\n* performs multiplication of a matrix with a diagonal matrix\n* right : multiply diagonal matrix from right (T) or left (F)\n* inverted : use diag^-1 (T) or just diag (F)\n*\n* matthias, dec 2010\n*----------------------------------------------------------------------*\n implicit none\n\n include 'stdunit.h'\n\n integer, parameter ::\n & ntest = 00\n real(8), parameter ::\n & thresh = 1d-7 ! because in current use we have the\n ! square root of diagonal elements on diag\n integer, intent(in) ::\n & ndim\n real(8), intent(inout) ::\n & mat(ndim,ndim)\n real(8), intent(in) ::\n & diag(ndim)\n logical, intent(in) ::\n & right, inverted\n\n integer ::\n & idx\n\n if (ndim.eq.0) return\n\n if (ntest.ge.100) then\n write(lulog,'(x,a)') '---------------'\n write(lulog,'(x,a)') 'dmdiagm at work'\n write(lulog,'(x,a)') '---------------'\n write(lulog,*) 'input matrix:'\n call wrtmat2(mat,ndim,ndim,ndim,ndim)\n write(lulog,*) 'normalization vector:'\n call wrtmat2(diag,1,ndim,1,ndim)\n end if\n\n if (inverted) then\n if (right) then\n do idx = 1, ndim\n if (diag(idx).lt.thresh) then\nc mat(1:ndim,idx) = 0d0\n cycle\n end if\n mat(1:ndim,idx) = mat(1:ndim,idx)/diag(idx)\n end do\n else\n do idx = 1, ndim\n if (diag(idx).lt.thresh) then\nc mat(idx,1:ndim) = 0d0\n cycle\n end if\n mat(idx,1:ndim) = mat(idx,1:ndim)/diag(idx)\n end do\n end if\n else\n if (right) then\n do idx = 1, ndim\n if (diag(idx).lt.thresh) cycle ! debug\n mat(1:ndim,idx) = mat(1:ndim,idx)*diag(idx)\n end do\n else\n do idx = 1, ndim\n if (diag(idx).lt.thresh) cycle ! debug\n mat(idx,1:ndim) = mat(idx,1:ndim)*diag(idx)\n end do\n end if\n end if\n\n if (ntest.ge.100) then\n write(lulog,*) 'output matrix:'\n call wrtmat2(mat,ndim,ndim,ndim,ndim)\n end if\n\n return\n end\n", "meta": {"hexsha": "8b45773c071cdf7fd7440e23eb8aa9cab4fa6035", "size": 2415, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "math/dmdiagm.f", "max_stars_repo_name": "ak-ustutt/GeCCo-public", "max_stars_repo_head_hexsha": "8d43a6c9323aeba7eb54625b95553bfd4b2418c6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "math/dmdiagm.f", "max_issues_repo_name": "ak-ustutt/GeCCo-public", "max_issues_repo_head_hexsha": "8d43a6c9323aeba7eb54625b95553bfd4b2418c6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "math/dmdiagm.f", "max_forks_repo_name": "ak-ustutt/GeCCo-public", "max_forks_repo_head_hexsha": "8d43a6c9323aeba7eb54625b95553bfd4b2418c6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.4512195122, "max_line_length": 72, "alphanum_fraction": 0.4451345756, "num_tokens": 684, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916170039421, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.6711141751282115}} {"text": "! { dg-do compile }\n!\n! PR 39861/39864\n!\n! Test cases provided by Dominique d'Humieres \n! and Michael Richmond .\n\nmodule vector_calculus\n intrinsic :: dot_product, sqrt\n\ncontains\n\n function len(r)\n real, dimension(:), intent(in) :: r\n real :: len\n len = sqrt(dot_product(r,r))\n end function len\n\n FUNCTION next_state()\n INTRINSIC :: RESHAPE\n INTEGER, PARAMETER :: trantb(1,1) = RESHAPE((/1,2/), shape=(/1,1/))\n next_state = trantb(1, 1)\n END FUNCTION next_state\n\nend module vector_calculus\n", "meta": {"hexsha": "15c0d39ac17e76b653c542240924b934daddd571", "size": 562, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/intrinsic_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/intrinsic_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/intrinsic_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": 21.6153846154, "max_line_length": 71, "alphanum_fraction": 0.6779359431, "num_tokens": 179, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8633916099737807, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.6711141696636681}} {"text": "SUBROUTINE beamdis(loads,nf,ratmax,interp,nels,ell,argv,nlen,ips)\r\n!\r\n! This subroutine produces a PostScript output file \"*.dis\" displaying\r\n! the deformed 1-D finite element mesh.\r\n!\r\n IMPLICIT NONE\r\n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\r\n REAL(iwp),INTENT(IN)::loads(0:),ratmax,ell(:)\r\n INTEGER,INTENT(IN)::ips,nf(:,:),nels,interp,nlen\r\n REAL(iwp)::width,height,scale=72,sxy,xo,yo,x,y,dismag,vmax\r\n REAL(iwp)::xmin,xmax,ymin,ymax,xnow,dmax,zero=0.0_iwp,pt5=0.5_iwp, &\r\n opt5=1.5_iwp,fpt5=5.5_iwp,d8=8.0_iwp,ept5=8.5_iwp,d11=11.0_iwp, &\r\n one=1.0_iwp,two=2.0_iwp,thr=3.0_iwp, &\r\n localx,globalx,na,nb,nc,nd,ll,wold,wnew\r\n INTEGER::i,j,nn\r\n CHARACTER(LEN=15)::argv\r\n REAL(iwp),ALLOCATABLE::xcoord(:)\r\n OPEN(ips,FILE=argv(1:nlen)//'.dis')\r\n!\r\n nn=nels+1\r\n ALLOCATE(xcoord(nn))\r\n\r\n xmin=zero\r\n xmax=zero\r\n xnow=zero\r\n ymin=zero\r\n ymax=zero\r\n\r\n xcoord(1)=xnow\r\n\r\n DO i=2,nn\r\n xnow=xnow+ell(i-1)\r\n xcoord(i)=xnow\r\n END DO\r\n\r\n xmax=xcoord(nn)\r\n\r\n DO i=1,nn\r\n IF(loads(nf(1,i))ymax)ymax=loads(nf(1,i))\r\n END DO\r\n\r\n width=xmax-xmin\r\n height=ymax-ymin\r\n dmax=ratmax*width\r\n IF(height>width)dmax=ratmax*height\r\n!\r\n vmax=zero\r\n DO i=1,nn\r\n IF(ABS(loads(nf(1,i)))>vmax)vmax=ABS(loads(nf(1,i)))\r\n END DO\r\n dismag=dmax/vmax\r\n!\r\n ymin=zero\r\n ymax=zero\r\n\r\n DO i=1,nn\r\n IF(dismag*loads(nf(1,i))ymax) &\r\n ymax=dismag*loads(nf(1,i))\r\n!\r\n IF(loads(nf(1,i))ymax)ymax=loads(nf(1,i))\r\n END DO\r\n!\r\n width =xmax-xmin\r\n height=ymax-ymin\r\n!\r\n! allow 1.5\" margin minimum on each side of figure\r\n!\r\n! portrait mode \r\n!\r\n IF(height.GE.d11/ept5*width)THEN\r\n!\r\n! height governs the scale\r\n!\r\n sxy=scale*d8/height\r\n xo=scale*pt5*(ept5-d8*width/height)\r\n yo=scale*opt5\r\n ELSE\r\n!\r\n! width governs the scale\r\n!\r\n sxy=scale*fpt5/width\r\n xo=scale*opt5\r\n yo=scale*pt5*(d11-fpt5*height/width)\r\n END IF\r\n!\r\n!\r\n! start PostScript output\r\n!\r\n WRITE(ips,'(a)')'%!PS-Adobe-1.0'\r\n WRITE(ips,'(a)')'%%DocumentFonts: none'\r\n WRITE(ips,'(a)')'%%Pages: 1'\r\n WRITE(ips,'(a)')'%%EndComments'\r\n WRITE(ips,'(a)')'/m {moveto} def'\r\n WRITE(ips,'(a)')'/l {lineto} def'\r\n WRITE(ips,'(a)')'/s {stroke} def'\r\n WRITE(ips,'(a)')'/c {closepath} def'\r\n WRITE(ips,'(a)')'%%EndProlog'\r\n WRITE(ips,'(a)')'%%Page: 0 1'\r\n WRITE(ips,'(a)')'gsave'\r\n!\r\n! draw the deformed mesh\r\n!\r\n WRITE(ips,'(2f9.2,a)') xo, yo, ' translate'\r\n WRITE(ips,'(f9.2,a)') 0.5, ' setlinewidth'\r\n\r\n wnew=loads(nf(1,1))\r\n\r\n DO i=1,nels\r\n DO j=1,interp\r\n\r\n wold=wnew\r\n localx=j*ell(i)/interp\r\n globalx=localx+xcoord(i)\r\n ll=ell(i)\r\n na=(one/(ll**3))*(ll**3-thr*ll*localx**2+two*localx**3)\r\n nb=(one/(ll**2))*(localx*ll**2-two*ll*localx**2+localx**3)\r\n nc=(one/(ll**3))*(thr*ll*localx**2-two*localx**3)\r\n nd=(one/(ll**2))*(localx**3-ll*localx**2)\r\n wnew=na*loads(nf(1,i))+nb*loads(nf(2,i))+nc*loads(nf(1,1+i))+nd*loads(nf(2,i+1))\r\n\r\n x=sxy*((globalx-ell(i)/interp)-xmin)\r\n y=sxy*(dismag*wold-ymin)\r\n WRITE(ips,'(2f9.2,a)') x, y,' m'\r\n x=sxy*(globalx-xmin)\r\n y=sxy*(dismag*wnew-ymin)\r\n WRITE(ips,'(2f9.2,a)') x, y,' l'\r\n WRITE(ips,'(a)')'c s'\r\n\r\n END DO\r\n\r\n END DO\r\n!\r\n WRITE(ips,'(a)')'grestore'\r\n WRITE(ips,'(a)')'showpage'\r\n CLOSE(ips)\r\n!\r\nRETURN\r\nEND SUBROUTINE beamdis\r\n\r\n", "meta": {"hexsha": "83bf776b0ef50ad5c85c0655b168f6d5d32535a7", "size": 3581, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "src/libs/main/beamdis.f03", "max_stars_repo_name": "leemargetts/PoreFEM", "max_stars_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/libs/main/beamdis.f03", "max_issues_repo_name": "leemargetts/PoreFEM", "max_issues_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/libs/main/beamdis.f03", "max_forks_repo_name": "leemargetts/PoreFEM", "max_forks_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.8680555556, "max_line_length": 85, "alphanum_fraction": 0.5674392628, "num_tokens": 1376, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479466, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6711100090714739}} {"text": "program well\nuse special, only: spherical_bessel_jn_zeros\nuse dftatom\nimplicit none\n\n! Atomic number:\ninteger, parameter :: Z = 0\n! Mesh parameters:\nreal(dp), parameter :: r_min = 1e-8_dp, r_max = 10, a = 6.2e7_dp\ninteger, parameter :: NN = 6000\n\nreal(dp), parameter :: c = 137.03599907_dp, eps = 1e-10_dp\ninteger :: n, n2, l, relat, converged, relat_max, k, kappa\nreal(dp) :: r(NN+1), u(size(r)), Ein, E, E_exact_nonrel, error, P(size(r)), &\n Q(size(r))\nreal(dp) :: Rp(NN+1)\nreal(dp) :: Emin_init, Emax_init\nreal(dp), allocatable :: zeros(:, :)\nreal(dp) :: E_exact(7, -7:7) ! E_exact(n, kappa)\n\n\n\nE_exact = 0\nE_exact(7, -7) = 0.5525904113_dp\nE_exact(6:7, -6) = [ &\n 0.4376510015_dp, &\n 0.8406357081_dp &\n]\nE_exact(5:7, -5) = [ &\n 0.3347685757_dp, &\n 0.6850117637_dp, &\n 1.1309235187_dp &\n]\nE_exact(4:7, -4) = [ &\n 0.2441543810_dp, &\n 0.5425739559_dp, &\n 0.9381557573_dp, &\n 1.4319901885_dp &\n]\nE_exact(3:7, -3) = [ &\n 0.1660865751_dp, &\n 0.4135916009_dp, &\n 0.7592590218_dp, &\n 1.2034759695_dp, &\n 1.7463192010_dp &\n]\nE_exact(2:7, -2) = [ &\n 0.1009533714_dp, &\n 0.2983952090_dp, &\n 0.5944899358_dp, &\n 0.9892629990_dp, &\n 1.4827135257_dp, &\n 2.0748352993_dp &\n]\nE_exact(1:7, -1) = [ &\n 0.0493479580_dp, &\n 0.1973910436_dp, &\n 0.4441269495_dp, &\n 0.7895517628_dp, &\n 1.2336600278_dp, &\n 1.7764447596_dp, &\n 2.4178974112_dp &\n]\nE_exact(2:7, 1) = [ &\n 0.1009533712_dp, &\n 0.2983952108_dp, &\n 0.5944899397_dp, &\n 0.9892630035_dp, &\n 1.4827135323_dp, &\n 2.0748353048_dp &\n]\nE_exact(3:7, 2) = [ &\n 0.1660865751_dp, &\n 0.4135916010_dp, &\n 0.7592590218_dp, &\n 1.2034759695_dp, &\n 1.7463192010_dp &\n]\nE_exact(4:7, 3) = [ &\n 0.2441543811_dp, &\n 0.5425739559_dp, &\n 0.9381557573_dp, &\n 1.4319901885_dp &\n]\nE_exact(5:7, 4) = [ &\n 0.3347685757_dp, &\n 0.6850117636_dp, &\n 1.1309235187_dp &\n]\nE_exact(6:7, 5) = [ &\n 0.4376510015_dp, &\n 0.8406357081_dp &\n]\nE_exact(7, 6) = 0.5525904113_dp\n\n\n\nr = mesh_exp(r_min, r_max, a, NN)\nRp = mesh_exp_deriv(r_min, r_max, a, NN)\nu = 0\n\nallocate(zeros(10, 0:7))\nzeros = spherical_bessel_jn_zeros(7, 10, 1e-13_dp)\nprint *, \"Relativistic infinite spherical potential well\"\nprint *, \"Mesh parameters (r_min, r_max, a, N):\"\nprint \"(ES10.2, F10.2, ES10.2, I10)\", r_min, r_max, a, NN\nprint *\nprint *, \" n l k kappa E E_exact Error E_exact_nonrel\"\nprint *\ndo n = 1, 7\n do l = 0, n-1\n if (l == 0) then\n relat_max = 2\n else\n relat_max = 3\n end if\n do relat = 2, relat_max\n E_exact_nonrel = (zeros(n-l, l) / r_max)**2 / 2\n k = relat - 2\n if (k == 0) then\n kappa = -l - 1\n else\n kappa = l\n end if\n Ein = -100\n Emin_init = 0\n Emax_init = 100\n if (kappa > 0) then\n n2 = n + 1\n else\n n2 = n\n end if\n call solve_radial_eigenproblem(n2, l, Ein, eps, 100, R, Rp, u, &\n Z, c, relat, .false., Emin_init, Emax_init, converged, E, P, Q)\n error = abs(E - E_exact(n, kappa))\n if (converged /= 0) call stop_error(\"Not converged\")\n print \"(I3, I3, I3, I3, F17.8, F17.8, ES10.2, F17.8)\", n, l, k, &\n kappa, E, E_exact(n, kappa), error, E_exact_nonrel\n if (error > 1e-6_dp) call stop_error(\"Error is higher than 1e-6\")\n end do\n end do\nend do\nend program\n", "meta": {"hexsha": "530a0a05a91f6745354c50779fcd77cb280aeb73", "size": 3411, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/well/well_rel.f90", "max_stars_repo_name": "rc/dftatom", "max_stars_repo_head_hexsha": "fe479fd27a7e0f77c6a88a1949996406ec935ac2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 40, "max_stars_repo_stars_event_min_datetime": "2015-03-19T16:00:14.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-29T03:06:10.000Z", "max_issues_repo_path": "tests/well/well_rel.f90", "max_issues_repo_name": "rc/dftatom", "max_issues_repo_head_hexsha": "fe479fd27a7e0f77c6a88a1949996406ec935ac2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2015-06-23T21:59:56.000Z", "max_issues_repo_issues_event_max_datetime": "2019-09-04T20:36:51.000Z", "max_forks_repo_path": "tests/well/well_rel.f90", "max_forks_repo_name": "rc/dftatom", "max_forks_repo_head_hexsha": "fe479fd27a7e0f77c6a88a1949996406ec935ac2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2015-06-07T15:14:49.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-05T07:03:24.000Z", "avg_line_length": 23.6875, "max_line_length": 84, "alphanum_fraction": 0.5769569041, "num_tokens": 1373, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479465, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6711099950486459}} {"text": "! Created by EverLookNeverSee@GitHub on 4/19/20.\n! This program finds factorial of n\n\nprogram factorial\n implicit none\n ! defining user input variable\n integer :: n\n ! defining counter and temporary factorial variables\n integer :: temp = 1, i\n1 print *, \"Enter a positive integer value:\"\n read *, n\n if (n < 1) then\n print *, \"You should enter a positive integer value!\"\n goto 1\n end if\n do i = 1, n\n temp = temp * i\n end do\n print *, temp\nend program factorial", "meta": {"hexsha": "0cafaf9d2c558b8ca111ad1cc01508ff9a54081a", "size": 517, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/other/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/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/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": 25.85, "max_line_length": 61, "alphanum_fraction": 0.6324951644, "num_tokens": 138, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835371034369, "lm_q2_score": 0.8031737916455819, "lm_q1q2_score": 0.6710384803528296}} {"text": "module lapack_module\n use aux\n implicit none\n private\n public inverse_matrix\n \n interface inverse_matrix\n module procedure inverse_matrix_d, inverse_matrix_z\n end interface inverse_matrix\n \n contains\n \n subroutine inverse_matrix_z(M)\n implicit none\n complex(dp), intent(inout) :: M(:,:)\n integer :: ndim,ierr,lwork\n integer, allocatable :: ipiv(:)\n complex(dp), allocatable :: work(:)\n complex(dp) :: work_query(1)\n \n ndim = size(M,1)\n allocate(ipiv(ndim))\n call zgetrf(ndim,ndim,M,ndim,ipiv,ierr)\n if (ierr .ne. 0) then\n write(*,*)\"ERROR in ZGETRF\", ierr ; stop\n end if\n call zgetri(ndim,M,ndim,ipiv,work_query,-1,ierr) ! query for optimal work space\n if (ierr .ne. 0) then\n write(*,*)\"ERROR in ZGETRI at workspace query\", ierr ; stop\n endif\n lwork = work_query(1)\n allocate(work(lwork))\n call zgetri(ndim,M,ndim,ipiv,work,lwork,ierr)\n if (ierr .ne. 0) then\n write(*,*)\"ERROR in ZGETRI\", ierr ; stop\n endif\n deallocate(ipiv,work)\n end subroutine inverse_matrix_z\n \n subroutine inverse_matrix_d(M)\n implicit none\n real(dp), intent (inout) :: M(:,:)\n integer :: ndim,ierr,lwork\n integer, allocatable :: ipiv(:)\n real(dp), allocatable :: work(:)\n real(dp) :: work_query(1)\n \n ndim = size(M,1)\n allocate(ipiv(ndim))\n call dgetrf(ndim,ndim,M,ndim,ipiv,ierr)\n if(ierr .ne. 0) then\n write(*,*)\"ERROR in DGETRF\", ierr ; stop\n end if\n call dgetri(ndim,M,ndim,ipiv,work_query,-1,ierr) ! query for optimal work space\n if (ierr .ne. 0) then\n write(*,*)\"ERROR in DGETRI at workspace query\", ierr ; stop\n endif\n lwork = work_query(1)\n allocate(work(lwork))\n call dgetri(ndim,M,ndim,ipiv,work,lwork,ierr)\n if(ierr .ne. 0) then\n write(*,*)\"ERROR in DGETRI\", ierr ; stop\n end if\n deallocate(ipiv,work)\n end subroutine inverse_matrix_d\n \nend module lapack_module\n", "meta": {"hexsha": "1c0b213b1f687f63e1cf51950c841fc343640acb", "size": 1999, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lapack_module.f90", "max_stars_repo_name": "mpickem/MOGW", "max_stars_repo_head_hexsha": "7a28844396323685cd4da9c9853b38e1c450e30a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lapack_module.f90", "max_issues_repo_name": "mpickem/MOGW", "max_issues_repo_head_hexsha": "7a28844396323685cd4da9c9853b38e1c450e30a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lapack_module.f90", "max_forks_repo_name": "mpickem/MOGW", "max_forks_repo_head_hexsha": "7a28844396323685cd4da9c9853b38e1c450e30a", "max_forks_repo_licenses": ["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.3970588235, "max_line_length": 83, "alphanum_fraction": 0.619809905, "num_tokens": 614, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588052782737, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6709373467157321}} {"text": "c this file contains the following user-callable routines:\nc\nc\nc routine idzr_aid computes the SVD, to a specified rank,\nc of an arbitrary matrix. This routine is randomized.\nc\nc\nccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\nc\nc\nc\nc\n subroutine idzr_asvd(m,n,a,krank,w,u,v,s,ier)\nc\nc constructs a rank-krank SVD u diag(s) v^* approximating a,\nc where u is an m x krank matrix whose columns are orthonormal,\nc v is an n x krank matrix whose columns are orthonormal,\nc and diag(s) is a diagonal krank x krank matrix whose entries\nc are all nonnegative. This routine uses a randomized algorithm.\nc\nc input:\nc m -- number of rows in a\nc n -- number of columns in a\nc a -- matrix to be decomposed; the present routine does not\nc alter a\nc krank -- rank of the SVD being constructed\nc w -- initialization array that routine idzr_aidi\nc has constructed (for use in the present routine,\nc w must be at least\nc (2*krank+22)*m+(6*krank+21)*n+8*krank**2+10*krank+90\nc complex*16 elements long)\nc\nc output:\nc u -- matrix of orthonormal left singular vectors of a\nc v -- matrix of orthonormal right singular vectors of a\nc s -- array of singular values of a\nc ier -- 0 when the routine terminates successfully;\nc nonzero otherwise\nc\nc _N.B._: The algorithm used by this routine is randomized.\nc\n implicit none\n integer m,n,krank,lw,ilist,llist,iproj,lproj,icol,lcol,\n 1 iwork,lwork,iwinit,lwinit,ier\n real*8 s(krank)\n complex*16 a(m,n),u(m,krank),v(n,krank),\n 1 w((2*krank+22)*m+(6*krank+21)*n+8*krank**2\n 2 +10*krank+90)\nc\nc\nc Allocate memory in w.\nc\n lw = 0\nc\n iwinit = lw+1\n lwinit = (2*krank+17)*n+21*m+80\n lw = lw+lwinit\nc\n ilist = lw+1\n llist = n\n lw = lw+llist\nc\n iproj = lw+1\n lproj = krank*(n-krank)\n lw = lw+lproj\nc\n icol = lw+1\n lcol = m*krank\n lw = lw+lcol\nc\n iwork = lw+1\n lwork = (krank+1)*(m+3*n+10)+9*krank**2\n lw = lw+lwork\nc\nc\n call idzr_asvd0(m,n,a,krank,w(iwinit),u,v,s,ier,\n 1 w(ilist),w(iproj),w(icol),w(iwork))\nc\nc\n return\n end\nc\nc\nc\nc\n subroutine idzr_asvd0(m,n,a,krank,winit,u,v,s,ier,\n 1 list,proj,col,work)\nc\nc routine idzr_asvd serves as a memory wrapper\nc for the present routine (please see routine idzr_asvd\nc for further documentation).\nc\n implicit none\n integer m,n,krank,list(n),ier\n real*8 s(krank)\n complex*16 a(m,n),u(m,krank),v(n,krank),\n 1 proj(krank,n-krank),col(m*krank),\n 2 winit((2*krank+17)*n+21*m+80),\n 3 work((krank+1)*(m+3*n+10)+9*krank**2)\nc\nc\nc ID a.\nc\n call idzr_aid(m,n,a,krank,winit,list,proj)\nc\nc\nc Collect together the columns of a indexed by list into col.\nc\n call idz_copycols(m,n,a,krank,list,col)\nc\nc\nc Convert the ID to an SVD.\nc\n call idz_id2svd(m,krank,col,n,list,proj,u,v,s,ier,work)\nc\nc\n return\n end\n", "meta": {"hexsha": "55ad61203d775bdb5e64a61b53b8ad69efd1d252", "size": 3288, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "scipy/linalg/src/id_dist/src/idzr_asvd.f", "max_stars_repo_name": "derbuihan/scipy", "max_stars_repo_head_hexsha": "bad9bdabc9ffa8724d891b027783412ec00a717a", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-07-12T16:40:35.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-12T16:40:35.000Z", "max_issues_repo_path": "scipy/linalg/src/id_dist/src/idzr_asvd.f", "max_issues_repo_name": "derbuihan/scipy", "max_issues_repo_head_hexsha": "bad9bdabc9ffa8724d891b027783412ec00a717a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-07-24T19:52:07.000Z", "max_issues_repo_issues_event_max_datetime": "2019-07-24T19:52:07.000Z", "max_forks_repo_path": "scipy/linalg/src/id_dist/src/idzr_asvd.f", "max_forks_repo_name": "derbuihan/scipy", "max_forks_repo_head_hexsha": "bad9bdabc9ffa8724d891b027783412ec00a717a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-12-29T20:29:20.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-08T14:39:49.000Z", "avg_line_length": 27.6302521008, "max_line_length": 71, "alphanum_fraction": 0.5869829684, "num_tokens": 1070, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587817066391, "lm_q2_score": 0.7549149868676284, "lm_q1q2_score": 0.6709373240205568}} {"text": "C Test for bug in reg-stack handling conditional moves.\nC Reported by Tim Prince \nC\nC { dg-do run { target { { i?86-*-* x86_64-*-* } && ia32 } } }\nC { dg-options \"-ffast-math -march=pentiumpro\" }\n\n double precision function foo(x, y)\n implicit none\n double precision x, y\n double precision a, b, c, d\n if (x /= y) then\n if (x * y >= 0) then\n a = abs(x)\n b = abs(y)\n c = max(a, b)\n d = min(a, b)\n foo = 1 - d/c\n else \n foo = 1\n end if \n else\n foo = 0\n end if\n end\n\n program test\n implicit none\n\n integer ntests\n parameter (ntests=7)\n double precision tolerance\n parameter (tolerance=1.0D-6)\n\nC Each column is a pair of values to feed to foo,\nC and its expected return value.\n double precision a(ntests), b(ntests), x(ntests)\n data a /1, -23, -1, 1, 9, 10, -9/\n data b /1, -23, 12, -12, 10, 9, -10/\n data x /0, 0, 1, 1, 0.1, 0.1, 0.1/\n\n double precision foo\n double precision result\n integer i\n\n do i = 1, ntests\n result = foo(a(i), b(i))\n if (abs(result - x(i)) > tolerance) then\n print *, i, a(i), b(i), x(i), result\n call abort\n end if\n end do\n end\n", "meta": {"hexsha": "7874da2ad02197496e6ceab816b1341ec35a457f", "size": 1419, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.dg/g77/20010216-1.f", "max_stars_repo_name": "best08618/asylo", "max_stars_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-05-02T17:34:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-17T10:15:18.000Z", "max_issues_repo_path": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.dg/g77/20010216-1.f", "max_issues_repo_name": "best08618/asylo", "max_issues_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "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": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.dg/g77/20010216-1.f", "max_forks_repo_name": "best08618/asylo", "max_forks_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-27T00:22:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-01T09:41:02.000Z", "avg_line_length": 26.7735849057, "max_line_length": 62, "alphanum_fraction": 0.474982382, "num_tokens": 430, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424295406087, "lm_q2_score": 0.7931059560743422, "lm_q1q2_score": 0.6709219793646564}} {"text": "! { dg-do compile }\n! { dg-require-effective-target fortran_large_real }\n!\nsubroutine test_large\n integer, parameter :: wp = selected_real_kind (precision (0.0_8) + 1)\n complex(wp), parameter :: i = (0._wp, 1._wp)\n complex(wp) :: c(12)\n integer :: m, N\n\n N = 12\n c = (/(exp(i*m),m=1,N)/)\n print *, c(1)\nend\n", "meta": {"hexsha": "f422e09a860c8cfac52a5df54d0580a40520fd51", "size": 314, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/pr36006-2.f90", "max_stars_repo_name": "brugger1/testsuite", "max_stars_repo_head_hexsha": "9b504db668cdeaf7c561f15b76c95d05bfdd1517", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/pr36006-2.f90", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/pr36006-2.f90", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 22.4285714286, "max_line_length": 71, "alphanum_fraction": 0.6146496815, "num_tokens": 111, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8459424295406088, "lm_q2_score": 0.7931059511841119, "lm_q1q2_score": 0.6709219752278031}} {"text": "!> \u7528\u4e8e\u8ba1\u7b97\u5177\u6709\u5750\u6807 (x) \u7684\u7c92\u5b50\u6240\u5728\u7684\u6392\u5e8f\u7f51\u683c\u7684\u5355\u5143\u683c\u7684\u5750\u6807 (xgcell) \u7684\u5b50\u4f8b\u7a0b\u3002\n!> subroutine to calculate the coordinates (xgcell) of the cell of\n!> the sorting grid, in which the particle with coordinates (x) lies.\nsubroutine grid_geom(i, x, ngridx, maxgridx, mingridx, dgeomx, xgcell)\n\n use sph_kind, only: rk\n use parameter\n implicit none\n\n !> \u7c92\u5b50\u5e8f\u53f7\n !> index of particle\n integer, intent(in) :: i\n !> \u7c92\u5b50\u7684\u5750\u6807\n !> coordinates of particle\n real(rk), intent(in) :: x(dim)\n !> \u5206\u5272\u7f51\u683c\u7684\u4e2a\u6570\n !> number of sorting grid cells in x, y, z-direction\n integer, intent(in) :: ngridx(dim)\n !> \u5206\u5272\u7f51\u683c\u7684\u6700\u5927\u5750\u6807\n !> maximum x-, y- and z-coordinate of grid range\n real(rk), intent(in) :: maxgridx(dim)\n !> \u5206\u5272\u7f51\u683c\u7684\u6700\u5c0f\u5750\u6807\n !> minimum x-, y- and z-coordinate of grid range\n real(rk), intent(in) :: mingridx(dim)\n !> \u5206\u5272\u7f51\u683c\u7684\u5750\u6807\u589e\u91cf\n !> x-, y- and z-expansion of grid range\n real(rk), intent(in) :: dgeomx(dim)\n !> \u5206\u5272\u7f51\u683c\u7684\u5750\u6807\n !> x-, y- and z-coordinte of sorting grid cell\n real(rk), intent(out) :: xgcell(dim)\n\n integer :: d\n\n do d = 1, 3\n xgcell(d) = 1\n end do\n\n do d = 1, dim\n if ((x(d) > maxgridx(d)) .or. (x(d) < mingridx(d))) then\n print *, ' >>> error <<< : particle out of range'\n print *, ' particle position: x(', i, d, ') = ', x(d)\n print *, ' range: [xmin,xmax](', d, ') = [', mingridx(d), ',', maxgridx(d), ']'\n stop\n else\n xgcell(d) = int(real(ngridx(d))/dgeomx(d)*(x(d) - mingridx(d)) + 1._rk)\n end if\n end do\n\nend subroutine grid_geom\n", "meta": {"hexsha": "391a2dae66a242cf596f548b3cf4838fea558668", "size": 1589, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/single_step/nnps/grid_geom.f90", "max_stars_repo_name": "zoziha/SPH", "max_stars_repo_head_hexsha": "6d855bdd2f0fcaf0bfe1ed5e214f186e3f1f7d8c", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-09-11T04:34:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-02T22:50:07.000Z", "max_issues_repo_path": "src/single_step/nnps/grid_geom.f90", "max_issues_repo_name": "zoziha/SPH", "max_issues_repo_head_hexsha": "6d855bdd2f0fcaf0bfe1ed5e214f186e3f1f7d8c", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-09-12T13:38:29.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-22T12:47:36.000Z", "max_forks_repo_path": "src/single_step/nnps/grid_geom.f90", "max_forks_repo_name": "zoziha/SPH", "max_forks_repo_head_hexsha": "6d855bdd2f0fcaf0bfe1ed5e214f186e3f1f7d8c", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-04T15:06:05.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T15:06:05.000Z", "avg_line_length": 31.78, "max_line_length": 124, "alphanum_fraction": 0.5525487728, "num_tokens": 582, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424256566558, "lm_q2_score": 0.7931059414036511, "lm_q1q2_score": 0.6709219638737101}} {"text": "\n!Joshua Dorrington 22/03/18 - University of Oxford\n\n!This module handles random number generation for stochastic runs\nmodule utils\n\tuse, intrinsic :: iso_fortran_env\n\tuse params\n\timplicit none\n\tprivate\n\tpublic time_seed, white_noise, red_noise\n\t \n\tcontains\n\t\t!lifted wholesale from Sam Hatfield's Lorenz63-4D Var model\n\t\t!seeds random numbers\n\t\tsubroutine time_seed()\n \t\tinteger :: i, n, clock\n \t\tinteger, allocatable :: seed(:)\n\n \t\tcall random_seed(size = n)\n \t\tallocate(seed(n))\n\n \t\tcall system_clock(count=clock)\n\n \t\tseed = clock + 37 * (/ (i - 1, i = 1, n) /)\n \t\tcall random_seed(put = seed)\n\n \t\tdeallocate(seed)\n\t\tend subroutine\n\n\t\t!generates (n X dims) array of gaussian random numbers using Box Muller\n\t\tsubroutine white_noise(rand_arr,mean,std,n)\n\t\t\treal(dp) :: rand_arr(:,:)\n\t\t\treal(dp), intent(in) :: mean, std\n\t\t\tinteger , intent(in):: n\n\t\t\treal(dp) :: rand1(n,dims), rand2(n,dims),u(n,dims),v(n,dims)\n\n\t\t\t!random univariates\n\t\t\tcall random_number(rand1)\n\t\t\tcall random_number(rand2)\n\t\t\t\n\t\t\t!Box-Muller\n\t\t\tu = sqrt(-2._dp * log(rand1))\n \t\tv = cos(8._dp*ATAN(1._dp) * rand2)\n\t\t\trand_arr = mean + (std * u * v)\n\t\tend subroutine\n\n\t\t!generates (n X dims) array of red noise with lag 1 correlation r\n\t\tsubroutine red_noise(rand_arr, mean,std,n)\n\t\t\treal(dp) :: rand_arr(:,:), white_arr(n,dims)\n\t\t\treal(dp), intent(in) :: mean, std\n\t\t\tinteger , intent(in):: n\n\t\t\tinteger :: i\n\t\t\treal(dp) :: k\n\t\t\tk=sqrt(1-r*r)\n\t\t\tcall white_noise(white_arr,mean,std,n)\n\t\t\trand_arr(1,:)=white_arr(1,:)\n\t\t\tdo i=1, n-1\n\t\t\t\trand_arr(i+1,:)=r*rand_arr(i,:) + k*white_arr(i+1,:)\n\t\t\tend do\n\t\tend subroutine\n\nend module utils\n", "meta": {"hexsha": "bacab157e37daacdcf54439590ab14d03edddaf7", "size": 1708, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "utils.f90", "max_stars_repo_name": "joshdorrington/barotropic_model", "max_stars_repo_head_hexsha": "884c82f66d549a1806c5d882a9c9804750523d9e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "utils.f90", "max_issues_repo_name": "joshdorrington/barotropic_model", "max_issues_repo_head_hexsha": "884c82f66d549a1806c5d882a9c9804750523d9e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "utils.f90", "max_forks_repo_name": "joshdorrington/barotropic_model", "max_forks_repo_head_hexsha": "884c82f66d549a1806c5d882a9c9804750523d9e", "max_forks_repo_licenses": ["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.1111111111, "max_line_length": 73, "alphanum_fraction": 0.6241217799, "num_tokens": 523, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473647220787, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.670905113451349}} {"text": "MODULE PE2D_TYPE\n USE IEEE_ARITHMETIC\n IMPLICIT NONE\n !-----------------------------------------------------------\n INTEGER, PARAMETER :: I4B = SELECTED_INT_KIND(9)\n INTEGER, PARAMETER :: I2B = SELECTED_INT_KIND(4)\n INTEGER, PARAMETER :: I1B = SELECTED_INT_KIND(2)\n INTEGER, PARAMETER :: SP = KIND(1.0)\n INTEGER, PARAMETER :: DP = KIND(1.0D0)\n INTEGER, PARAMETER :: SPC = KIND((1.0,1.0))\n INTEGER, PARAMETER :: DPC = KIND((1.0D0,1.0D0))\n INTEGER, PARAMETER :: LGT = KIND(.TRUE.)\n REAL(SP), PARAMETER :: PI=3.141592653589793238462643383279502884197_SP\n REAL(SP), PARAMETER :: PIO2=1.57079632679489661923132169163975144209858_SP\n REAL(SP), PARAMETER :: TWOPI=6.283185307179586476925286766559005768394_SP\n REAL(SP), PARAMETER :: SQRT2=1.41421356237309504880168872420969807856967_SP\n REAL(SP), PARAMETER :: EULER=0.5772156649015328606065120900824024310422_SP\n REAL(DP), PARAMETER :: PI_D=3.141592653589793238462643383279502884197_DP\n REAL(DP), PARAMETER :: PIO2_D=1.57079632679489661923132169163975144209858_DP\n REAL(DP), PARAMETER :: TWOPI_D=6.283185307179586476925286766559005768394_DP\n COMPLEX(DPC), PARAMETER :: IM=COMPLEX(0.0_DP,1.0_DP)\n !US = Unstructured Sparse\n TYPE US\n INTEGER(I4B) :: N, NELT\n REAL(DP), DIMENSION(:), ALLOCATABLE :: VAL\n INTEGER(I4B), DIMENSION(:), ALLOCATABLE :: IROW\n INTEGER(I4B), DIMENSION(:), ALLOCATABLE :: JCOL\n END TYPE US\n !-----------------------------------------------------------\nEND MODULE PE2D_TYPE\n", "meta": {"hexsha": "8ebde44aff8953cc371207000c6d74f67e81b520", "size": 1441, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "Parabolic_Equation/2DPE/SRC/MODULES/PE2D_TYPE.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/SRC/MODULES/PE2D_TYPE.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/SRC/MODULES/PE2D_TYPE.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": 46.4838709677, "max_line_length": 77, "alphanum_fraction": 0.6960444136, "num_tokens": 477, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.872347368040789, "lm_q2_score": 0.7690802264851919, "lm_q1q2_score": 0.6709051113865712}} {"text": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nmodule shadow_globaldefinitions\n\n!\n! global assignments for shadow3\n!\n use, intrinsic :: ISO_C_BINDING\n implicit none\n\n!\n! Numeric variable types (precision)\n!\n integer, parameter, public :: ski = C_INT\n integer, parameter, public :: skr = C_DOUBLE\n integer, parameter, public :: skc = C_CHAR\n integer, parameter, public :: skx = C_DOUBLE_COMPLEX\n integer, parameter, public :: sklen = 1024\n \n!\n\n!!----\n!!---- OS: Integer variable 1: Windows, 2: Mac, 3: Linux, 4:Sun\n!!---- OS_DS: ASCII code of directory separator character\n!!\n \n\n\n\n\n\n\n integer(kind=ski), parameter :: OS = 3\n character(len=1), parameter :: OS_DS = \"/\"\n\n!\n! mathematical and physical constants\n!\n real(kind=skr), parameter :: pi = 3.141592653589793238462643D0\n real(kind=skr), parameter :: twopi = 6.283185307179586467925287D0\n real(kind=skr), parameter :: pihalf = 1.570796326794896619231322D0\n real(kind=skr), parameter :: todeg =57.295779513082320876798155D0\n real(kind=skr), parameter :: torad = 0.017453292519943295769237D0\n\n\n ! introduced physical constants in globaldefinitions: srio@esrf.eu 20160527 - NIST CODATA 2014\n real(kind=skr),parameter :: codata_c = 2.99792458D8 !speed of light, m/s\n real(kind=skr),parameter :: codata_rm = 9.10938356D-31 !electron rest mass kg\n real(kind=skr),parameter :: codata_e = 1.6021766208D-19 !electron charge, C\n real(kind=skr),parameter :: codata_h = 6.626070040D-34 !Planck's constant joules*sec\n real(kind=skr),parameter :: codata_mee = 0.5109989461D0 ! electrom Mass equivalent in MeV\n real(kind=skr),parameter :: codata_electric_permittivity = 8.854187817D-12 ! electric constant epsilon0\n ! conversion Angstrom <-> eV for particles with no mass\n ! codata_h*codata_c/codata_e*1d10\n real(kind=skr), parameter :: toangs = 12398.419739640718D0 ! 12398.4192920042\n\n real(kind=skr), parameter :: tocm = 12398.419739640718D-8 ! 12398.4192920042D-8\n\n\n\n ! for debugging purposes, set this to 1 to get a verbose output\n integer(kind=ski), public :: shadow3_verbose = 0\n\n ! length units: note that this will be overwritten by source and oe DUMMY variable\n ! using m: user_units_to_cm=100, using cm: user_units_to_cm=1, usning mm: user_units_to_cm=0.1\n ! default is cm\n real(kind=skr), public :: user_units_to_cm = 1.0D0\n\nend module shadow_globaldefinitions\n", "meta": {"hexsha": "c3f2f6fc155cbbb1c22a0d21e47524432e511e42", "size": 2539, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fedora_preparation/shadow_globaldefinitions.f90", "max_stars_repo_name": "XiaoshengLin/shadow3", "max_stars_repo_head_hexsha": "d007ae59a2038db4f9275f7bb026bd1b11549e5f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2018-05-07T12:46:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-17T07:39:25.000Z", "max_issues_repo_path": "src/fedora_preparation/shadow_globaldefinitions.f90", "max_issues_repo_name": "XiaoshengLin/shadow3", "max_issues_repo_head_hexsha": "d007ae59a2038db4f9275f7bb026bd1b11549e5f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 23, "max_issues_repo_issues_event_min_datetime": "2018-04-18T13:49:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-05T18:37:59.000Z", "max_forks_repo_path": "src/fedora_preparation/shadow_globaldefinitions.f90", "max_forks_repo_name": "XiaoshengLin/shadow3", "max_forks_repo_head_hexsha": "d007ae59a2038db4f9275f7bb026bd1b11549e5f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2018-06-04T10:48:23.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-06T10:09:46.000Z", "avg_line_length": 22.4690265487, "max_line_length": 116, "alphanum_fraction": 0.6612839701, "num_tokens": 762, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699435, "lm_q2_score": 0.7461389930307512, "lm_q1q2_score": 0.6708695190486177}} {"text": " integer function ibico(n,k)\n* binomial coefficient n over k\n\n implicit none\n\n integer, intent(in) ::\n & n, k\n integer ::\n & l, nmkp1\n integer, external ::\n & ifac\n\n if (k.lt.0.or.n.lt.k)\n & call quit(1,'ibico','k<0 or n A_{mn} = b_legend_{mn}/norm_legend(m) if m<=n or 0. otherwise\n! ==> A_inv_{mn} = b_legend_inv_{mn}/norm_inv_legend(m) if m<=n or 0. otherwise\n!\n! B, B_inv: convert y-powers in [-1,1] to and from x-powers in [0,1]\n! \n! x = (y + 1)/2; x**m = SUM_n=0^m 2**(-m) m!/(n!(m-n)!) y**n \n! y = 2*x - 1; y**m = SUM_n=0^m 2**n (-1)**(m-n) m!/(n!(m-n)!) x**n \n!\n! ==> B_{mn} = 2**(-m) m!/(n!(m-n)!) if m<=n or 0. otherwise\n! ==> B_inv_{mn} = 2**n (-1)**(m-n) m!/(n!(m-n)!) if m<=n or 0. otherwise\n! \n!\n! NOTICE that: A_inv = (A)**(-1); B_inv = (B)**(-1) \n!--------------------------------------------------------------------------------------------------\n\n if (n > 12) stop 'N(Legendre) CANNOT be larger than 12!!!'\n \n a = 0\n a_inv = 0\n b = 0\n b_inv = 0\n \n do i = 0, n\n idx = 13*i\n do j = 0, i\n a(i,j) = b_legend(idx+j+1)/norm_legend(i+1)\n a_inv(i,j) = b_legend_inv(idx+j+1)/norm_inv_legend(i+1)\n b(i,j) = 2._dp**(-i) * factorial(i)/\n 1 (factorial(j)*factorial(i-j))\n b_inv(i,j) = 2._dp**j*(-1._dp)**(i-j)* factorial(i)/\n 1 (factorial(j)*factorial(i-j))\n enddo\n enddo\n \n end subroutine build_matrices_legendre\n\n \n subroutine power_to_legendre(n, a, b, ac, tc)\n use kind_spec\n implicit none\n integer, intent(IN):: n\n real(rprec), dimension(0:n), intent(IN):: ac\n real(rprec), dimension(0:n), intent(OUT):: tc\n real(rprec), dimension(0:n,0:n), intent(IN):: a, b\n integer:: i, j, k\n!------------------------------------------------------------------\n! Given the following notation:\n!\n! TC == (tc(1), ...tc(n))==> vector of coefficients\n! for Legendre series in [-1,1]\n! AC == (ac(1), ...ac(n))==> vector of coefficients\n! for power series in [0,1]\n! then:\n! TC = AC* B * A\n!------------------------------------------------------------------ \n do i = 0, n\n tc(i) = 0\n do j= 0, n\n do k = 0, n\n tc(i) = tc(i) + ac(j) * b(j,k) * a(k,i)\n enddo\n enddo\n enddo\n \n end subroutine power_to_legendre\n\n \n subroutine legendre_to_power(n, a_inv, b_inv, tc, ac)\n use kind_spec\n implicit none\n integer, intent(IN):: n\n real(rprec), dimension(0:n), intent(IN):: tc\n real(rprec), dimension(0:n), intent(OUT):: ac\n real(rprec), dimension(0:n,0:n), intent(IN):: a_inv, b_inv\n integer:: i, j, k\n!---------------------------------------------------------------------\n! Given the following notation:\n!\n! AC == (ac(1), ...ac(n))==> vector of coefficients for \n! power series in [0,1]\n! TC == (tc(1), ...tc(n))==> vector of coefficients for \n! Legendre series in [-1,1]\n! then:\n! AC = TC* A_INV * B_INV\n!---------------------------------------------------------------------- \n do i = 0, n\n ac(i) = 0\n do j= 0, n\n do k = 0, n\n ac(i) = ac(i) + tc(j) * a_inv(j,k) * b_inv(k,i)\n enddo\n enddo\n enddo\n \n end subroutine legendre_to_power\n\n \n subroutine point_wise_to_power(npts, x, f, n, ac, i_full,\n 1 nsp_pts)\n use kind_spec\n implicit none\n integer, intent(IN):: npts, i_full, nsp_pts\n integer, intent(INOUT):: n\n real(rprec), dimension(npts), intent(IN):: x, f\n real(rprec), dimension(0:n), intent(OUT):: ac\n integer :: i, j, k , n_count, n_int \n character(LEN=2) :: cdum\n character(LEN=15) :: form\n real(rprec) :: res, ohs_sp\n real(rprec), dimension(:), allocatable :: tc, norm, y,\n 1 fy, y_sp, fy_sp\n real(rprec), dimension(:,:), allocatable:: a_inv, b_inv,\n 1 a, b, inorm, tleg\n!-----------------------------------------------\n! E x t e r n a l F u n c t i o n s\n!-----------------------------------------------\n REAL(rprec) , EXTERNAL :: integral\n!--------------------------------------------------------------------------------\n! MEANING OF ARGUMENTS:\n! NPTS = number of points where the point-wise function is given\n! X = independent variable values for these points in [0,1]\n! F = dependent variable values on the X points\n! N = tentative number of Legendre polynomials used in the reconstruction\n! AC = final power series coefficients in x ([0,1])\n! I_FULL =0, if input data on full mesh; =1, if on half mesh\n! NSP_PTS = number of points for the spline fit of F on the half mesh.\n!--------------------------------------------------------------------------------\n!\n! ABSTRACT:\n! Conversion of a point-wise solution in [0,1] given on a discrete set\n! of NPTS radial points (either on the half or the full mesh, see below)\n! first to an expansion in Legendre polynomials in [-1,1] via:\n!\n! F = sum_m=0^N / == INT_[-1,1] f(x)g(x)dx\n!\n! and defining the Legendre coefficient vector TC as:\n!\n! TC = {/, m=1, N}\n!\n! then calculates the equivalent power series coefficients vector in \n! [0,1], AC:\n!\n! AC = TC*A_inv*B_inv\n!\n! The value of Legendre Polynomials used \"N\" depends CRITICALLY on the \n! number of points NPTS in the discrete data set of the incoming point-wise\n! solution. Because if the integrals are evaluated using these points, the\n! wiggles in the polynomial may not be well sampled by the existing set of\n! points and may cause deviations of the ortogonality condition: \n!\n! = 2/(2*n+1)* delta_{mn}\n!\n! This makes the reconstruction to deteriorate quickly for increasing \"N\". \n! To avoid this, the incoming data values are SPLINED to a number of points\n! NSP_PTS on a half-like mesh using Hermite cubic splines. Then, the\n! value of \"N\" is chosen requiring:\n!\n! | 1- .5*(2*n+1)* | < RES\n!\n! RES is prescribed to be <= .5%. Until this condition is achieved, \"N\" is\n! subsequently reduced. If \"N\" gets equal to 2 in this reduction, the \n! calculation is stopped and an error message issued.\n!\n! WARNING: The point-wise solution MAY BE given on the half mesh or full mesh\n! of a equally spaced radial grid, that is:\n!\n! ***I_FULL = 1 beginning with x(3/2) and finishing with x(M-1/2), where \n! x(1) = 0. and x(M) = 1. \n! ***I_FULL = 0 beginning with x(1) = 0. and finishing with x(M) = 1.\n!\n!--------------------------------------------------------------------------------\n\n ac = 0\n res = 1\n \n!... Map [0,1] to [-1,1]\n \n allocate (y(npts), fy(npts), y_sp(nsp_pts), fy_sp(nsp_pts))\n\n y(:npts) = 2*x(:npts) - 1\n fy(:npts) = f(:npts)\n\n!... I_full = 0 if FY given on the full mesh, and =1 if on the half mesh. \n! FY is splined on nsp_pts on the half_mesh\n \n ohs_sp = 2._dp/nsp_pts\n y_sp= (/( -1._dp+ (real(i,rprec)-0.5_dp)*ohs_sp,\n 1 i = 1, nsp_pts)/) \n\n call spline_it(npts, y, fy, nsp_pts, y_sp, fy_sp, i_full)\n \n!... Determine number of Legendre Polynomials to be used\n\n n_count = 0\n do\n if(res <= 0.005_dp) exit\n n_int = n - n_count \n if(n_int < n) deallocate (a, b, a_inv, b_inv, tleg,\n 1 inorm, norm)\n allocate(a(0:n_int,0:n_int), b(0:n_int,0:n_int),\n 1 a_inv(0:n_int,0:n_int), b_inv(0:n_int,0:n_int),\n 2 tleg(0:n_int, nsp_pts), inorm(0:n_int,0:n_int), \n 3 norm(0:n_int))\n \n norm(0:n_int) = (/(2._dp/(2*i+1),\n 1 i=0, n_int)/) \n\n call build_matrices_legendre (n_int, a, b, a_inv, b_inv) \n \n!... Build Initial Legendre polynomials on grid\n \n do i = 0, n_int\n tleg(i,:nsp_pts) = 0\n do k = n_int, 0, -1\n tleg(i,:nsp_pts)= a_inv(i,k) + y_sp(:nsp_pts)\n 1 *tleg(i,:nsp_pts)\n enddo\n enddo\n \n!... Compute orthogonality and norms \n\n do j = 0, n_int\n do i = 0, n_int\n inorm(i,j) = integral(nsp_pts, y_sp, tleg(j,1:nsp_pts), \n 1 tleg(i,1:nsp_pts))\n enddo\n write(cdum,'(i2)')n_int+1\n cdum = adjustl(cdum)\n form = '('//trim(cdum)//'(x,f8.3))'\n form = adjustl(form)\n! write(20,trim(form)) (inorm(i,j), i=0, n)\n enddo\n\n!... Compute residual. If res > 0.02, reduce N and iterate\n \n res = abs((norm(n_int) - inorm(n_int,n_int))/(norm(n_int)))\n n_count = n_count + 1\n if(n_count == n-1) stop 'Precision bad for even 2 Polynomial' \n\n enddo \n \n allocate(tc(0:n_int))\n do j = 0, n_int\n tc(j) = integral(nsp_pts, y_sp, fy_sp, tleg(j,1:nsp_pts))\n 1 /norm(j)\n enddo\n \n call legendre_to_power(n_int, a_inv, b_inv, tc, ac(0))\n \n deallocate(a_inv, b_inv, a, b, tc, tleg, inorm, norm, fy, \n 1 y, y_sp, fy_sp) \n \n end subroutine point_wise_to_power\n\n\n subroutine spline_it(ndata, xdata, ydata, npts, x, y, i_full)\n use kind_spec\n implicit none\n integer, intent(IN) :: ndata, npts, i_full\n real(rprec), dimension(ndata), intent(IN):: xdata, ydata\n real(rprec), dimension(npts), intent(OUT):: x, y\n real(rprec), dimension(npts) :: dy \n real(rprec), dimension(:), allocatable:: xfull, yfull, \n 1 dyfull, wk\n integer:: iwk, ierr\n logical:: spline \n\n allocate(xfull(ndata+i_full), yfull(ndata+i_full), \n 1 dyfull(ndata+i_full), wk(2*(ndata+i_full)) )\n\n if (i_full .eq. 1) then !! I_FULL= 1, data on HALF_mesh\n xfull(1) = -1\n xfull(ndata+1) = 1\n xfull(2:ndata) = 0.5_dp*(xdata(1:ndata-1)+xdata(2:ndata)) \n yfull(1) = ydata(1) + (xdata(1)+1.)*\n 1 (ydata(2)-ydata(1))/(xdata(2)-xdata(1))\n yfull(2:ndata) = 0.5_dp*(ydata(1:ndata-1)+ydata(2:ndata)) \n yfull(ndata+1) = ydata(ndata) + (1 - xdata(ndata))*\n 1 (ydata(ndata-1)-ydata(ndata))/(xdata(ndata-1)-xdata(ndata))\n else !!I_FULL =0, data on FULL mesh;\n xfull(1:ndata) = xdata(1:ndata)\n yfull(1:ndata) = ydata(1:ndata)\n endif\n \n spline = .false.\n wk = 0\n ierr = 0\n iwk = 2*ndata\n\n call PCHEZ(ndata+i_full, xfull, yfull, dyfull, spline,\n 1 wk, iwk, ierr)\n if(ierr.lt.0) stop 'LEGENDRE: error in SPLINE'\n \n call PCHEV(ndata+i_full, xfull, yfull, dyfull,\n 1 npts, x, y, dy, ierr)\n if(ierr.lt.0) stop 'LEGENDRE: error in EVAL_SPLINE'\n\n deallocate(xfull, yfull, dyfull, wk) \n\n end subroutine spline_it\n\n\n function integral (n, x, y1, y2) \n use kind_spec\n implicit none\n integer, intent(IN) :: n \n real(rprec), intent(IN), dimension(n) :: y1, y2 , x\n real(rprec), parameter :: one = 1\n real(rprec), dimension(n) :: coef \n real(rprec) :: h, integral\n!------------------------------------------------------------------------------\n! WARNING: The integral formula assumes values on the half MESH,\n! that is, the independent variable is given from x(3/2) to x(M-1/2),\n! but the limits of the integral are x(1)=-1 and x(M)=1. N = M-1 is the\n! number of points on the half mesh.\n! In the current version, fulfilment of this condition is only checked\n! for the case in which the interval of integration is the interval\n! of orthogonality of Legendre polynomias, i.e., [-1,1]. \n! Integration formula is a 2-nd order HALF-MESH formula from\n! \"Numerical Recipes\", W.Press et al, Chapter 4, page 110.\n!------------------------------------------------------------------------------\n if (n < 10) stop 'Too few points to carry out integration.!'\n if (x(n) < x(1)) stop' B <0) THEN\n ! Iteration 1 \n nn=nn+1 \n DO i=1,Nx\n nonlinfix(i)=Es*u(i)**3&\n +(2.0d0/(4.0d0*3.0d0*2.0d0))*&\n (3.0d0*(u(i)**2)*(-2.0d0*u(i)+uold(i))+&\n 6.0d0*u(i)*(-1.0d0*u(i))*(u(i)-uold(i)))\n END DO\n CALL DZFFT(isignf,Nx,scalef,nonlinfix,nonlinfixhat,&\n tabledz,work,isys)\n DO i=1,Nx/2 + 1\n nonlinfixhat(i)=nonlinfixhat(i)+&\n (kx(i)*kx(i) -1.0d0)*v(i) + &\n (2.0d0*v(i)-vold(i))*(1.0d0/(dt*dt)-&\n (kx(i)*kx(i)-1.0d0)*2.0d0/(4.0d0*3.0d0*2.0d0))\n END DO\n\n chg=1.0d0\n iter=1\n DO WHILE ((chg .gt. tol) .and. (iter .lt. maxiter))\n DO i=1,Nx\n utemp(i)=unew(i)\n nonlin(i)=(2.0d0/(4.0d0*3.0d0*2.0d0))*&\n (3.0d0*(u(i)**2)*unew(i)+&\n 6.0d0*u(i)*unew(i)*(u(i)-uold(i)))\n END DO\n CALL DZFFT(isignf,Nx,scalef,nonlin,nonlinhat,&\n tabledz,work,isys)\n DO i=1,Nx/2 + 1\n vnew(i)=(nonlinhat(i)+nonlinfixhat(i) ) &\n /(1.0d0/(dt*dt) - (2.0d0/(4.0d0*3.0d0*2.0d0))*(kx(i)*kx(i) - 1.0d0))\n END DO\n CALL ZDFFT(isignb,Nx,scaleb,vnew,unew,tablezd,work,isys)\n chg=0.0d0\n ! normalize result\n DO i=1,Nx\n chg=chg+(unew(i)-utemp(i))**2\n END DO\n chg=SQRT(chg/REAL(Nx,kind(0d0)))\n iter=iter+1\n END DO \n IF (mod(nn,plotgap)==0) then\n plotnum=plotnum+1\n time(plotnum)=nn*dt\n PRINT *,'time',nn*dt\n CALL enercalc(Nx,isignf,isignb,isys,ntable,nwork,dt,Es,&\n enkin(plotnum),enstr(plotnum),&\n enpot(plotnum),en(plotnum),&\n kx,nonlin,nonlinhat,&\n vnew,v,unew,u,tabledz,tablezd,work)\n !CALL savedata(Nx,plotnum,name_config,unew)\n END IF\n ENDIF\n IF(mod(Nt,3)>1) THEN\n ! Iteration 2\n nn=nn+1\n DO i=1,Nx\n nonlinfix(i)=Es*unew(i)**3&\n +(2.0d0/(4.0d0*3.0d0*2.0d0))*&\n (3.0d0*(unew(i)**2)*(-2.0d0*unew(i)+u(i))+&\n 6.0d0*unew(i)*(-1.0d0*unew(i))*(unew(i)-u(i)))\n END DO\n CALL DZFFT(isignf,Nx,scalef,nonlinfix,nonlinfixhat,&\n tabledz,work,isys)\n DO i=1,Nx/2 + 1\n nonlinfixhat(i)=nonlinfixhat(i)+&\n (kx(i)*kx(i) -1.0d0)*vnew(i) + &\n (2.0d0*vnew(i)-v(i))*(1.0d0/(dt*dt)-&\n (kx(i)*kx(i)-1.0d0)*2.0d0/(4.0d0*3.0d0*2.0d0))\n END DO\n\n chg=1.0d0\n iter=1\n DO WHILE ((chg .gt. tol) .and. (iter .lt. maxiter))\n DO i=1,Nx\n utemp(i)=uold(i)\n nonlin(i)=(2.0d0/(4.0d0*3.0d0*2.0d0))*&\n (3.0d0*(unew(i)**2)*uold(i)+&\n 6.0d0*unew(i)*uold(i)*(unew(i)-u(i)))\n END DO\n CALL DZFFT(isignf,Nx,scalef,nonlin,nonlinhat,&\n tabledz,work,isys)\n DO i=1,Nx/2 + 1\n vold(i)=(nonlinhat(i)+nonlinfixhat(i) ) &\n /(1.0d0/(dt*dt) -(2.0d0/(4.0d0*3.0d0*2.0d0))*(kx(i)*kx(i) - 1.0d0))\n END DO\n CALL ZDFFT(isignb,Nx,scaleb,vold,uold,tablezd,work,isys)\n chg=0.0d0\n ! normalize result\n DO i=1,Nx\n chg=chg+(uold(i)-utemp(i))**2\n END DO\n chg=SQRT(chg/REAL(Nx,kind(0d0)))\n iter=iter+1\n END DO\n IF (mod(nn,plotgap)==0) then\n plotnum=plotnum+1\n time(plotnum)=nn*dt\n PRINT *,'time',nn*dt\n CALL enercalc(Nx,isignf,isignb,isys,ntable,nwork,dt,Es,&\n enkin(plotnum),enstr(plotnum),&\n enpot(plotnum),en(plotnum),&\n kx,nonlin,nonlinhat,&\n vold,vnew,uold,unew,tabledz,tablezd,work)\n !CALL savedata(Nx,plotnum,name_config,unew)\n END IF\n END IF\t\n finish=MPI_WTIME()\n PRINT*,'Finished timestepping'\n runtime=REAL(finish-start,kind(0d0))\n\tPRINT*,'Program took ',runtime,'for Time stepping' \n\tCALL saveresults(Nt,plotgap,time(1:1+n/plotgap),en(1:1+n/plotgap),&\n\t\t\tenstr(1:1+n/plotgap),enkin(1:1+n/plotgap),&\n enpot(1:1+n/plotgap))\n\t\t\t\n\t! Save times at which output was made in text format\n\tPRINT *,'Saved data'\n IF(mod(Nt,3)==0) CALL errorcalc(Nt,Nx,dt,c,x,u,err)\n IF(mod(Nt,3)==1) CALL errorcalc(Nt,Nx,dt,c,x,unew,err)\n IF(mod(Nt,3)==2) CALL errorcalc(Nt,Nx,dt,c,x,uold,err)\n\n name_config = 'data/errortime'\n CALL savetimeanderror(Nx,Nt,err,runtime,name_config)\n \n\tPRINT *,'Program execution complete'\n CALL MPI_FINALIZE(ierr)\n\tEND PROGRAM Kg\n", "meta": {"hexsha": "347641f923b4206b2d0ae508567a0d44a181f843", "size": 19047, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Codes/Fortran1DFourierCompactR2C/KgSemiImp1d.f90", "max_stars_repo_name": "bkmgit/KleinGordon1D", "max_stars_repo_head_hexsha": "ce6ba332e542d74b72069ae253cca5e0a2ade425", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-01-21T03:57:51.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-21T03:57:51.000Z", "max_issues_repo_path": "Codes/Fortran1DFourierCompactR2C/KgSemiImp1d.f90", "max_issues_repo_name": "bkmgit/KleinGordon1D", "max_issues_repo_head_hexsha": "ce6ba332e542d74b72069ae253cca5e0a2ade425", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Codes/Fortran1DFourierCompactR2C/KgSemiImp1d.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": 43.8870967742, "max_line_length": 92, "alphanum_fraction": 0.4441119336, "num_tokens": 5982, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765163620469, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.6707477719315134}} {"text": "MODULE SOI_thermal_source\n\n USE type_kinds, only : fpk => fp_kind\n\n IMPLICIT NONE\n\n REAL(fpk), PRIVATE, PARAMETER :: ONE = 1.0_fpk\n REAL(fpk), PRIVATE, PARAMETER :: TWO = 2.0_fpk\n REAL(fpk), PRIVATE, PARAMETER :: HALF = 0.5_fpk\n REAL(fpk), PRIVATE, PARAMETER :: ZERO = 0.0_fpk\n REAL(fpk), PRIVATE, PARAMETER :: TWELVE = 12.0_fpk\n REAL(fpk), PRIVATE, PARAMETER :: cut_opd = 0.2_fpk\n\n PUBLIC :: thermal_source, thermal_source_TL, thermal_source_AD\n\nCONTAINS\n\n\n subroutine thermal_source( slopd, & ! Slant optical depth of layer (opd/mu)\n ssa, & ! ssa of layer\n tau, & ! slant transmittance of layer (exp(-opd/mu))\n Ttop, & ! Top Temp (or BB radiance) of layer\n Tbot, & ! Bot Temp (or BB radiance) of layer\n Sp, & ! Upwelling Source\n Sm ) ! Downwelling Source\n\n\n REAL(fpk), intent(in) :: slopd\n REAL(fpk), intent(in) :: ssa\n REAL(fpk), intent(in) :: tau\n REAL(fpk), intent(in) :: Ttop\n REAL(fpk), intent(in) :: Tbot\n REAL(fpk), intent(out) :: Sp, Sm\n\n REAL(fpk) :: A, B\n\n A = HALF * (Tbot + Ttop) * (ONE-tau)\n if (slopd < cut_opd) then\n B = (Ttop-Tbot)*(slopd/TWELVE)*(ONE-tau)\n else\n B = (Ttop-Tbot)*( tau + (ONE - tau)*(HALF - ONE/slopd) )\n endif\n\n sp = (A + B) * (ONE - ssa)\n sm = (A - B) * (ONE - ssa)\n \n end subroutine thermal_source\n\n\n subroutine thermal_source_TL( slopd, ssa, tau, Ttop, Tbot, &\n slopd_TL, ssa_TL, tau_TL, Ttop_TL, Tbot_TL, &\n Sp, Sm, Sp_TL, Sm_TL )\n\n REAL(fpk), intent(in) :: slopd, ssa, tau, Ttop, Tbot ! regular input variables\n REAL(fpk), intent(in) :: slopd_TL, ssa_TL, tau_TL, Ttop_TL, Tbot_TL ! TL inputs\n REAL(fpk), intent(out) :: Sp, Sm, Sp_TL, Sm_TL ! TL outputs\n\n REAL(fpk) :: A, B, A_TL, B_TL\n\n A_TL = HALF * (Tbot_TL + Ttop_TL) * (ONE-tau) - HALF * (Tbot+Ttop)*tau_TL\n A = HALF * (Tbot + Ttop) * (ONE-tau)\n if (slopd < cut_opd) then\n B_TL = (Ttop_TL - Tbot_TL) * (slopd/TWELVE)*(ONE-tau) + &\n (Ttop-Tbot)*( slopd_TL*(ONE-tau) - slopd*tau_TL)/TWELVE\n B = (Ttop-Tbot)*(slopd/TWELVE)*(ONE-tau)\n else\n B_TL = (Ttop_TL - Tbot_TL) * (tau + (ONE-tau)*(HALF-ONE/slopd) ) + &\n (Ttop-Tbot) * ( tau_TL + (ONE-tau)*(slopd_TL/(slopd*slopd)) - &\n tau_TL*(HALF - ONE/slopd) )\n B = (Ttop-Tbot)*( tau + (ONE - tau)*(HALF - ONE/slopd) )\n endif\n\n sp = (A + B) * (ONE - ssa)\n sm = (A - B) * (ONE - ssa)\n sp_TL = (A_TL + B_TL) * (ONE - ssa) - (A+B) * ssa_TL\n sm_TL = (A_TL - B_TL) * (ONE - ssa) - (A-B) * ssa_TL\n\n end subroutine thermal_source_TL\n\n subroutine thermal_source_AD( slopd, ssa, tau, Ttop, Tbot, & ! input variables\n slopd_AD, ssa_AD, tau_AD, Ttop_AD, Tbot_AD, & !output AD variables\n sp_AD, sm_AD ) ! input AD variables\n\n\n REAL(fpk), intent(in) :: slopd, ssa, tau, Ttop, Tbot\n REAL(fpk), intent(inout) :: slopd_AD, ssa_AD, tau_AD, Ttop_AD, Tbot_AD\n REAL(fpk), intent(in) :: sp_AD, sm_AD\n \n REAL(fpk) :: A, B, A_AD, B_AD, dT, tmp\n ! forward re-computations\n dT = Ttop - Tbot\n A = HALF * (Tbot + Ttop) * (ONE - tau)\n if (slopd < cut_opd) then\n B = dT*(slopd/TWELVE)*(ONE - tau)\n else\n B = dT*( tau + (ONE - tau)*(HALF - ONE/slopd) )\n endif\n\n ! adjoint computations\n A_AD = (ONE - ssa) * (sp_AD + sm_AD)\n B_AD = (ONE - ssa) * (sp_AD - sm_AD)\n ssa_AD = -(A+B) * sp_AD - (A-B)*sm_AD + ssa_AD\n\n if (slopd < cut_opd) then\n tmp = slopd/TWELVE*(ONE - tau)\n Ttop_AD = tmp * B_AD + Ttop_AD\n Tbot_AD = -tmp * B_AD + Tbot_AD\n slopd_AD = dT/TWELVE * (ONE - tau)*B_AD + slopd_AD\n tau_AD = -dT*slopd/TWELVE * B_AD + tau_AD\n else\n tmp = tau + (ONE - tau)*(HALF - ONE/slopd)\n Ttop_AD = tmp * B_AD + TTop_AD\n Tbot_AD = -tmp * B_AD + Tbot_AD\n slopd_AD = dT * (ONE - tau)/(slopd*slopd) * B_AD + slopd_AD\n tau_AD = dT * (HALF + ONE/slopd) * B_AD + tau_AD\n endif\n \n tau_AD = -HALF * (Tbot+Ttop) * A_AD + tau_AD\n tmp = HALF * (ONE - tau) * A_AD\n Ttop_AD = tmp + Ttop_AD\n Tbot_AD = tmp + Tbot_AD\n \n end subroutine thermal_source_AD \n\nend module SOI_thermal_source\n", "meta": {"hexsha": "681772de44901ffdf3c3202725041e2419ca86ab", "size": 4966, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/User_Code/UWisc/30-Apr-2005_Delivery/SOI_thermal_source.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/User_Code/UWisc/30-Apr-2005_Delivery/SOI_thermal_source.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/User_Code/UWisc/30-Apr-2005_Delivery/SOI_thermal_source.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": 39.4126984127, "max_line_length": 100, "alphanum_fraction": 0.4798630689, "num_tokens": 1641, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.7371581741774411, "lm_q1q2_score": 0.6707453908441459}} {"text": "!-----subroutine---------------------------------------------g.guidati--\n! \n subroutine SPL_E1A (xa, ya, y2a, n, x, y, dydx, khi, klo) \n! \n!-----------------------------------------------------------------------\n! \n! franco guidati IAG\n! Uni Stuttgart\n!\n! \n! scope execute spline interpolation\n! (natural splines)\n! \n!.......................................................................\n! declarations\n!.......................................................................\nUSE TIPrecision \n \nIMPLICIT NONE \n \n \n ! Local variables. \n \nINTEGER(4) :: klo,khi,n \n \nREAL(DbKi) :: a,b,h,x \nREAL(DbKi) :: xa(n) \n \nCOMPLEX (DbKi) :: ya(n), y2a(n), y, dydx\n\n!.......................................................................\n! execute spline interpolation\n!.......................................................................\n\n\n h = xa(khi) - xa(klo)\n if (h.eq.0.) then\n write(*,*)'ERROR:TINoise:SPL_E0A: bad xa input in splint'\n STOP 1\n endif\n a = (xa(khi) - x) / h\n b = (x - xa(klo)) / h\n y = a * ya(klo) + b * ya(khi) + ((a**3.0d0 - a) * y2a(klo) &\n + (b**3.0d0 - b) * y2a(khi))* (h**2.0d0) / 6.0d0\n dydx = (-ya(klo) + ya(khi)) / h + ((-3.0d0*a**2.0d0 + 1.0d0) & \n * y2a(klo)+(+3.0d0*b**2.0d0-1.0d0)*y2a(khi))*h/6.0d0\n\n\n!.......................................................................\n! end of subroutine\n!.......................................................................\n return\n!***********************************************************************\n end \n\n", "meta": {"hexsha": "a59553764cfaee2f54d5ce5fc108814388078a42", "size": 2174, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "modules/aerodyn/src/AeroAcoustics/TINoise/SPL_E1A.f90", "max_stars_repo_name": "CarloSucameli/Openfast-noise", "max_stars_repo_head_hexsha": "b695c53ff790ac390f9fcf7ec1bf67e24688deb0", "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": "modules/aerodyn/src/AeroAcoustics/TINoise/SPL_E1A.f90", "max_issues_repo_name": "CarloSucameli/Openfast-noise", "max_issues_repo_head_hexsha": "b695c53ff790ac390f9fcf7ec1bf67e24688deb0", "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/aerodyn/src/AeroAcoustics/TINoise/SPL_E1A.f90", "max_forks_repo_name": "CarloSucameli/Openfast-noise", "max_forks_repo_head_hexsha": "b695c53ff790ac390f9fcf7ec1bf67e24688deb0", "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.8214285714, "max_line_length": 72, "alphanum_fraction": 0.2226310948, "num_tokens": 454, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069987088004, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6707453765853069}} {"text": "c $Id: dwidth.f,v 1.1 2012/11/29 21:00:07 jwebb Exp $\nC####C##1#########2#########3#########4#########5#########6#########7##\n real*8 function mmean (io,m0,g,mmin,mmax) \nc\ncinput io : flag (see bleow)\ncinput m0 : pole mass\ncinput g : nominal width \ncinput mmin : minimal mass\ncinput mmax : maximal mass\nc\nc io=0 : Yields average mass between {\\rm mmin} and {\\rm mmax}\nc according to a Breit-Wigner function with constant width {\\rm g}\nc and pole {\\rm m0}.\\\\\nc io=1 : Chooses a mass randomly between {\\rm mmin} and {\\rm mmax} \nc\t according to a Breit-Wigner function with constant \nc\t width {\\rm g} and pole {\\rm m0}.\\\\\nc else: Integral of a Breit-Wigner function from {\\rm mmin} to {\\rm mmax}.\nccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\n implicit none\n\n real*8 m0,g,mmin,mmax,x,i0,i1,inv,fmin,fmax,ranf,f,gcut\n parameter(gcut=1d-10)\n integer io\n logical errchk\n parameter (errchk=.true.)\n\n i0(x) =2.*g*atan( 2.* (x-m0)/ g )\n i1(x) =.5*g**2*log( (x-m0)**2+g**2/4. ) + m0*i0(x)\n inv(x)=.5*g*tan( 0.5*x/g )+m0\n\n\nc...check for some error conditions\n if(errchk)then\n if(mmin.gt.mmax)\n . write(6,*)'mmean: mass range negative (mmin>mmax)'\n . ,mmin,mmax\n if(g.le.gcut.and.(m0.gt.mmax.or.m0.lt.mmin))\n . write(6,*)'mmean: narrow particle out of mass range' \n end if\n\n if(io.eq.0)then\n if(g.le.gcut)then\n mmean=0d0\n if(mmin.le.m0.and.m0.le.mmax)mmean=1d0\n else\n mmean=(i1(mmax)-i1(mmin))/(i0(mmax)-i0(mmin))\n end if\n else if(io.eq.1)then\nc... determin a mass in a given interval\n if(g.le.gcut)then\n mmean=max(mmin,min(mmax,m0))\n else\n fmin=i0(mmin)\n fmax=i0(mmax)\n f=fmin+(fmax-fmin)*ranf(0)\n mmean=inv(f) \n end if\n else\n\t mmean=i0(mmax)-i0(mmin) !this might not work for narrow part.\n end if \n return\n end\n\n\nC####C##1#########2#########3#########4#########5#########6#########7##\n subroutine getmas(m0,g0,i,iz,mmin,mmax,mrest,m)\nc\ncinput m0 : pole mass of resonance\ncinput g0 : nominal width of resonance \ncinput i : resonance ID\ncinput iz : iso3 of resonance\ncinput mmin : minimal mass\ncinput mmax : maximal mass\ncoutput m : actual mass of the resonance\nc\nc\t{\\tt getmas} (not $\\rightarrow$ {\\tt getmass}) first chooses the \nc\tmass {\\tt m} of resonance {\\tt i} between {\\tt mmin} and {\\tt mmax}\nc\tby a call of {\\tt mmean}. Since {\\tt mmean} only handles Breit-Wigners\nc\twith constant widths it follows \nc\ta correction such that {\\tt m} is distributed according to mass \nc\tdependent widths (corresponding to {\\tt fbrwig(...,m,1)}).\nc\nC####C##1#########2#########3#########4#########5#########6#########7##\n implicit none\n include 'options.f'\n include 'comres.f'\n integer i,iz,nrej, nrejmax\n real*8 m,m0,g0,mmin,mmax,x,x0,gg,f,g,h,pi,al,alpha,ce,mmax2\n real*8 phi,k,k0,mrest\nc...functions\n real*8 ranf,mmean,fbrwig,bwnorm,pcms\n parameter(pi=3.1415926535d0)\n parameter(alpha=3d0, ce=2d0, nrejmax=1000000)\n\nc 'broadened' Breit-Wigner function with h(x0,al)=h(x0,1)\nc normalised to alpha\n h(x,x0,gg,al)=al*0.5/pi*(al*gg)/((x-x0)**2+0.25*(al*gg)**2)\n\nc cut-off for maximum resonance mass\n mmax2=min(mresmax,mmax)\n\n\n if(g0.lt.1d-4.or.CTOption(1).ne.0.or.CTOption(32).ne.0)then\n m=mmean(1,m0,g0,mmin,mmax2)\n return\n else\n\t nrej=0\n\nc This is a Monte Carlo rejection method, where the invertable \nc BW-distribution with constant widths is used to limit the BW-distribution\nc with mass-dep. widths whose inverse is not known analytically.\n\n108 continue\n m=mmean(1,m0,alpha*g0,mmin,mmax2)\n if(m.gt.(mmax2+1d-8).or.m.lt.(mmin-1d-8))then\n write(*,*)'getmas (W): m outside (mmin,mmax2)',m,mmin,mmax2\n write(*,*)'called as getmas(',m0,g0,i,mmin,mmax,')'\n write(*,*)'Program stopped'\n stop\n endif\n if ((CTOption(25).eq.1).and.(mrest.gt.0.0)) then\n k=pcms(mmax2+mrest,mrest,m)\n k0=pcms(mmax2+mrest,mrest,mmin)\n phi = m*k / (mmin*k0)\n else\n phi = 1.0\n endif\n\nc Breit-Wigner with mass dependent widths and phase space correction\n\n\t f=fbrwig(i,iz,m,1)*phi/bwnorm(i)\n\t g=ce*h(m,m0,g0,alpha)\n\n\t if(g.lt.f)then\n\t write(*,*)'(W) getmas: C h(m) not limiting at m=',m\n\t write(*,*)'->mass distribution of ',i,'might be corrupt'\n\t endif\n nrej=nrej+1\n if (nrej.le.nrejmax.and.(ranf(0)*g).gt.f) goto 108\n if (nrej.gt.nrejmax) then\nc write(*,*)'(W) getmas_space: too many rejections, m= ',m\nc write(*,*)'called with (',m0,g0,i,mmin,mmax,mrest,')'\nc write(*,*)'->mass distribution of ',i,' might be corrupt'\n m=mmean(1,m0,alpha*g0,mmin,mmax2)\n endif\n \n endif\n\n return\n end\n\nC####C##1#########2#########3#########4#########5#########6#########7##\n\treal*8 function bwnorm(ires)\nc\ncinput ires : itype of resonance\nc\nc\tThis function calculates the integral of {\\tt fbrwig}\nc\tbetween parameters {\\tt mmin}(= 0~GeV) and {\\tt mmax}(= 30~GeV) by\nc\tcalling {\\tt qsimp3} resp. by table lookup. It's value shall \nc\tserve as the norm of the Breit-Wigner function of particle {\\tt ires} \nc\twith mass dependent width.\nc\nC####C##1#########2#########3#########4#########5#########6#########7##\n\n\timplicit none\n\tinclude 'comres.f'\n\tinclude 'comwid.f'\n\tinclude 'options.f'\n\tinteger ires,iz,isoit,it\n\treal*8 mmin,mmax,pole,norm1,norm2\n\treal*8 widit,massit\n\tparameter(mmin=0d0,mmax=50d0)\n\treal*8 fbrwig\n external fbrwig\n\n\tif((CTOption(36).ne.0.or.CTOption(1).ne.0).and.wtabflg.gt.1)then\n\t bwnorm=1d0\n\t return\n\tendif\n\t\n\tit=iabs(ires)\n\n if (wtabflg.ge.2.and.CTOption(33).eq.0) then\nc table lookup\n if (it.ge.minbar.and.it.le.maxbar) then\n bwnorm=bwbarnorm(it)\n else if (it.ge.minmes.and.it.le.maxmes) then\n bwnorm=bwmesnorm(it)\n else \n write (6,*) '*** error(bwnorm) wrong id:',it\n bwnorm=1d0\n endif\n\telse\nc calculate\n\t if (widit(it).gt.1d-3)then\n\n pole=massit(it)\nc arbitrary value of iz \n\t iz=isoit(it)\n\nc the integration is divided by the pole of the Breit-Wigner -\nc thus two integrations with pole as upper or lower boundary\nc respectively are necessary\n\n\t call qsimp3(fbrwig,mmin,pole,it,iz,norm1,-1)\n\t call qsimp3(fbrwig,pole,mmax,it,iz,norm2,+1)\n\t bwnorm=norm1+norm2\n\t else\n\t bwnorm=1d0\n\t endif\n\tendif\n\n\treturn\n\tend\n\n\nc no physics after these routines!\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\nc(c) numerical receipies, adapted for f(idum1,idum2,x)\n SUBROUTINE qsimp3(func,a,b,idum1,idum2,s,flag)\nc\nc Simpson integration via Numerical Receipies.\nc\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\n implicit none\n\n include 'options.f'\n\n INTEGER JMAX,j,idum1,idum2,flag\n REAL*8 a,b,func,s,EPS\n REAL*8 os,ost,st\n PARAMETER (JMAX=100)\n external func\n if(b-a.le.1.d-4) then\n s=0.d0\n return\n endif\n\n EPS = 5d-3\n if (CTOption(35).eq.1) EPS=5d-4\n\n ost=-1.d30\n os= -1.d30\n do 11 j=1,JMAX\n if(flag.eq.-1) then\n call midsqu3(func,a,b,idum1,idum2,st,j)\n elseif(flag.eq.1) then\n call midsql3(func,a,b,idum1,idum2,st,j)\n endif\n s=(9.*st-ost)/8.\n\n if (abs(s-os).le.EPS*abs(os)) return\n os=s\n ost=st\n11 continue\n\n write(6,*) 'too many steps in qsimp3, increase JMAX!'\n\n return \n END\n\n\n SUBROUTINE midsqu3(funk,aa,bb,idum1,idum2,s,n)\nc modified midpoint rule; allows singuarity at upper limit\n implicit none\n integer idum1,idum2\n INTEGER n\n REAL*8 aa,bb,s,funk\n EXTERNAL funk\n INTEGER it,j\n REAL*8 ddel,del,sum,tnm,x,func,a,b\n func(x)=2.*x*funk(idum1,idum2,bb-x**2,1)\n b=sqrt(bb-aa)\n a=0.\n if (n.eq.1) then\n s=(b-a)*func(0.5*(a+b))\n else\n it=3**(n-2)\n tnm=it\n del=(b-a)/(3.*tnm)\n ddel=del+del\n x=a+0.5*del\n sum=0.\n do 11 j=1,it\n sum=sum+func(x)\n x=x+ddel\n sum=sum+func(x)\n x=x+del\n11 continue\n s=(s+(b-a)*sum/tnm)/3.\n endif\n return\n END\n\n SUBROUTINE midsql3(funk,aa,bb,idum1,idum2,s,n)\nc modified midpoint rule; allows singularity at lower limit\n implicit none\n integer idum1,idum2\n INTEGER n\n REAL*8 aa,bb,s,funk\n EXTERNAL funk\n INTEGER it,j\n REAL*8 ddel,del,sum,tnm,x,func,a,b\n func(x)=2.*x*funk(idum1,idum2,aa+x**2,1)\n b=sqrt(bb-aa)\n a=0.\n if (n.eq.1) then\n s=(b-a)*func(0.5*(a+b))\n else\n it=3**(n-2)\n tnm=it\n del=(b-a)/(3.*tnm)\n ddel=del+del\n x=a+0.5*del\n sum=0.\n do 11 j=1,it\n sum=sum+func(x)\n x=x+ddel\n sum=sum+func(x)\n x=x+del\n11 continue\n s=(s+(b-a)*sum/tnm)/3.\n endif\n return\n END\n\n\n", "meta": {"hexsha": "c22091db460ae5ac3dc738db89f9b015be3290bb", "size": 9267, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "UrQMD3_3_1/unedited_src/dwidth.f", "max_stars_repo_name": "klendathu2k/StarGenerator", "max_stars_repo_head_hexsha": "7dd407c41d4eea059ca96ded80d30bda0bc014a4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-12-24T19:37:00.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T06:57:20.000Z", "max_issues_repo_path": "UrQMD3_3_1/unedited_src/dwidth.f", "max_issues_repo_name": "klendathu2k/StarGenerator", "max_issues_repo_head_hexsha": "7dd407c41d4eea059ca96ded80d30bda0bc014a4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "UrQMD3_3_1/unedited_src/dwidth.f", "max_forks_repo_name": "klendathu2k/StarGenerator", "max_forks_repo_head_hexsha": "7dd407c41d4eea059ca96ded80d30bda0bc014a4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.2530487805, "max_line_length": 78, "alphanum_fraction": 0.5749433474, "num_tokens": 3192, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380482, "lm_q2_score": 0.7371581568543043, "lm_q1q2_score": 0.6707453714798259}} {"text": "! =============================================================================\n! Test Jacobi diagonalisation\n!\n! This unit test checks the eigenvalue solver for\n! spherical parcels. In the spherical case, the eigenvectors\n! can point in any direction (but they are orthogonal to each\n! other)\n! =============================================================================\nprogram test_jacobi_3\n use unit_test\n use constants, only : zero, ten\n use jacobi\n implicit none\n\n double precision :: error\n integer :: n, k, sk\n double precision :: V(3, 3)\n double precision :: B(3, 3), D(3)\n double precision :: A(3, 3), eval ! reference\n integer, allocatable :: seed(:)\n\n call random_seed(size=sk)\n allocate(seed(1:sk))\n seed(:) = 42\n call random_seed(put=seed)\n\n\n error = zero\n\n do n = 1, 10000\n\n call create_symmetric_matrix\n\n call jacobi_diagonalise(B, D, V)\n\n ! check eigenvalues\n error = max(error, dabs(eval - D(1)) &\n + dabs(eval - D(2)) &\n + dabs(eval - D(3)))\n\n ! check eigenvectors\n B = matmul(matmul(transpose(V), B), V)\n\n B = dabs(A - B)\n\n error = max(error, sum(B))\n\n ! check if orthogonal\n error = max(error, dabs(dot_product(V(:, 1), V(:, 2))))\n error = max(error, dabs(dot_product(V(:, 1), V(:, 3))))\n error = max(error, dabs(dot_product(V(:, 2), V(:, 3))))\n enddo\n\n call print_result_dp('Test Jacobi 3', error, atol=dble(1.0e-11))\n\n contains\n\n subroutine create_symmetric_matrix\n integer :: i, j\n double precision :: rndm(3, 3), val\n logical :: valid\n double precision :: Q(3, 3)\n\n valid = .false.\n\n do while (.not. valid)\n call random_number(eval)\n eval = 10 * eval\n\n ! Create orthogonal vectors using Gram-Schmidt orthogonalization\n ! (https://de.wikipedia.org/wiki/Gram-Schmidtsches_Orthogonalisierungsverfahren)\n do i = 1, 3\n do j = 1, 3\n call random_number(val)\n rndm(i, j) = 10.0d0 * val\n enddo\n enddo\n\n Q = 0.0d0\n\n do j = 1, 3\n Q(:, j) = rndm(:, j)\n do i = 1, j - 1\n Q(:, j) = Q(:, j) &\n - Q(:, i) * dot_product(Q(:, i), rndm(:, j)) &\n / dot_product(Q(:, i), Q(:, i))\n enddo\n Q(:, j) = Q(:, j) / norm2(Q(:, j))\n enddo\n\n ! Check orthogonalization error:\n val = dabs(dot_product(Q(:, 1), Q(:, 2))) &\n + dabs(dot_product(Q(:, 1), Q(:, 3))) &\n + dabs(dot_product(Q(:, 2), Q(:, 3)))\n\n valid = (val < 1.0e-13)\n enddo\n\n ! Create symmetric B matrix\n B = zero\n do i = 1, 3\n do j = 1, 3\n do k = 1, 3\n B(i, j) = B(i, j) + Q(i, k) * eval * Q(j, k)\n enddo\n enddo\n enddo\n\n A = B\n end subroutine create_symmetric_matrix\n\nend program test_jacobi_3\n", "meta": {"hexsha": "883641427444f4c48fde108769ff9318d8b4f420", "size": 3472, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "unit-tests/3d/test_jacobi_3.f90", "max_stars_repo_name": "matt-frey/epic", "max_stars_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2021-11-11T10:50:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T00:11:41.000Z", "max_issues_repo_path": "unit-tests/3d/test_jacobi_3.f90", "max_issues_repo_name": "matt-frey/epic", "max_issues_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 47, "max_issues_repo_issues_event_min_datetime": "2021-11-12T17:09:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-24T16:50:58.000Z", "max_forks_repo_path": "unit-tests/3d/test_jacobi_3.f90", "max_forks_repo_name": "matt-frey/epic", "max_forks_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.7256637168, "max_line_length": 96, "alphanum_fraction": 0.4176267281, "num_tokens": 861, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.7371581510799253, "lm_q1q2_score": 0.6707453698275544}} {"text": "SUBROUTINE p810(input_file,output_file)\n!-------------------------------------------------------------------------\n! Program 8.10 Plane analysis of the diffusion-convection equation\n! using 4-node rectangular quadrilaterals. Implicit time\n! integration using the \"theta\" method.\n! Untransformed solution.\n!-------------------------------------------------------------------------\n USE main\n USE geom\n IMPLICIT NONE\n CHARACTER(len=60),INTENT(IN) :: input_file\n CHARACTER(len=60),INTENT(OUT) :: output_file\n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\n INTEGER::i,iel,j,k,nband,ndim=2,nels,neq,fixed_freedoms,nip=4,nlen,nn, &\n nod=4,npri,np_types,nres,nstep,ntime,nxe,nye\n REAL(iwp)::det,dtim,part1,part2,pt2=0.2_iwp,penalty=1.0e20_iwp,theta, &\n time,ux,uy,zero=0.0_iwp\n CHARACTER(LEN=15)::argv,element='quadrilateral'\n!-----------------------dynamic arrays------------------------------------\n INTEGER,ALLOCATABLE::etype(:),g_num(:,:),node(:),num(:)\n REAL(iwp),ALLOCATABLE::ans(:),conc(:),coord(:,:),copy(:,:),der(:,:), &\n deriv(:,:),dtkd(:,:),fun(:),g_coord(:,:),jac(:,:),kb(:,:),kc(:,:), &\n loads(:),ntn(:,:),pb(:,:),mm(:,:),points(:,:),prop(:,:),storpb(:), &\n weights(:),work(:,:),x_coords(:),y_coords(:)\n!-------------------------input and initialisation------------------------\n \n OPEN(10,FILE=input_file) \n OPEN(11,FILE=output_file)\n READ(10,*)nxe,nye,np_types \n CALL mesh_size(element,nod,nels,nn,nxe,nye)\n neq=nn\n ALLOCATE(points(nip,ndim),weights(nip),coord(nod,ndim),fun(nod), &\n jac(ndim,ndim),g_coord(ndim,nn),der(ndim,nod),deriv(ndim,nod), &\n mm(nod,nod),g_num(nod,nels),kc(nod,nod),ntn(nod,nod),num(nod), &\n dtkd(nod,nod),prop(ndim,np_types),x_coords(nxe+1),y_coords(nye+1), &\n etype(nels),conc(nye+1))\n READ(10,*)prop\n etype=1\n if(np_types>1)read(10,*)etype\n READ(10,*)x_coords,y_coords\n READ(10,*)dtim,nstep,theta,npri,nres,ntime,ux,uy\n nband=0\n!-----------------------loop the elements to find global arrays sizes-----\n elements_1: DO iel=1,nels\n CALL geom_rect(element,iel,x_coords,y_coords,coord,num,'x')\n g_num(:,iel)=num\n g_coord(:,num)=TRANSPOSE(coord)\n IF(nband1\n implicit none\n include 'qlconstants.f'\n double precision x1,x2,arg,ieps1,ieps2,ieps\n double complex ln,lnarg,lnomarg,prod,denspence\n arg=x1*x2\n ieps=sign(one,x2*ieps1+x1*ieps2)\n if (arg .le. 1d0) then\n if (arg.eq. 1d0 .or. arg .eq.0d0) then\n prod=0d0 \n else\n lnarg=ln(x1,ieps1)+ln(x2,ieps2)\n lnomarg=dcmplx(log(1d0-arg),0d0)\n prod=lnarg*lnomarg\n endif\n qlLi2omx=dcmplx(pisqo6)-denspence(dcmplx(arg),ieps)-prod\n elseif (arg .gt. 1d0) then\n arg=1d0/(x1*x2)\n lnarg=-ln(x1,ieps1)-ln(x2,ieps2)\n lnomarg=dcmplx(log(1d0-arg),0d0)\n qlLi2omx=-dcmplx(pisqo6)+denspence(dcmplx(arg),ieps)\n . +lnarg*lnomarg-0.5d0*lnarg**2\n endif\n return\n end\n", "meta": {"hexsha": "7c3b876752cefcf4c6bb6ec8b5214b0c8e884592", "size": 1048, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "vendor/IREGI/src/qcdloop/ql/qlLi2omx.f", "max_stars_repo_name": "valassi/mg5amc_test", "max_stars_repo_head_hexsha": "2e04f23353051f64e1604b23105fe3faabd32869", "max_stars_repo_licenses": ["NCSA"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-10-23T14:37:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-22T20:59:02.000Z", "max_issues_repo_path": "vendor/IREGI/src/qcdloop/ql/qlLi2omx.f", "max_issues_repo_name": "valassi/mg5amc_test", "max_issues_repo_head_hexsha": "2e04f23353051f64e1604b23105fe3faabd32869", "max_issues_repo_licenses": ["NCSA"], "max_issues_count": 64, "max_issues_repo_issues_event_min_datetime": "2015-06-24T15:08:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-25T04:59:32.000Z", "max_forks_repo_path": "vendor/IREGI/src/qcdloop/ql/qlLi2omx.f", "max_forks_repo_name": "valassi/mg5amc_test", "max_forks_repo_head_hexsha": "2e04f23353051f64e1604b23105fe3faabd32869", "max_forks_repo_licenses": ["NCSA"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2015-05-04T22:15:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-06T10:04:40.000Z", "avg_line_length": 36.1379310345, "max_line_length": 65, "alphanum_fraction": 0.5658396947, "num_tokens": 437, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541544761565, "lm_q2_score": 0.7122321964553657, "lm_q1q2_score": 0.6706764067438732}} {"text": "program demo_centertext\n use :: M_draw\n !! set up drawing environment\n call prefsize(600,600)\n call vinit(' ') ! start graphics using device $M_draw_DEVICE\n call ortho2(-300.0,300.0,-300.0,300.0)\n call textsize(8.0,8.0)\n call linewidth(30)\n call color(D_BLACK)\n call clear()\n\n x1=-150\n y1=-150\n do j=1,4\n select case(j)\n case(1); call xcentertext(); x1=-150; y1=-150; r=100\n case(2); call ycentertext(); x1=+150; y1=-150; r= 30\n case(3); call centertext(.true.); x1=-150; y1=+150; r=100\n case(4); call centertext(.false.); x1=+150; y1=+150; r= 30\n end select\n !! draw radial lines\n call color(D_RED)\n do i=1,80\n call move2(x1,y1)\n call draw2(x1+150.0*cosd(i*12.0), y1+150.0*sind(i*12.0))\n enddo\n\n !! draw rotated text\n call color(D_GREEN)\n do i=1,30\n ang=i*12.0\n xx=x1+r*cosd(ang)\n yy=y1+r*sind(ang)\n call move2(xx,yy)\n call textang(ang)\n call color(D_WHITE)\n call drawstr('This is angled text')\n call color(D_RED)\n enddo\n enddo\n\n ipaws=getkey()\n\n call vexit()\ncontains\n elemental real function sind(angle_in_degrees)\n doubleprecision,parameter :: PI= 3.14159265358979323846264338327950288419716939937510d0\n doubleprecision,parameter :: degrees_to_radians = PI / 180.0D+00\n real,intent(in) :: angle_in_degrees\n sind=sin(angle_in_degrees*degrees_to_radians)\n end function sind\n elemental real function cosd(angle_in_degrees)\n doubleprecision,parameter :: PI= 3.14159265358979323846264338327950288419716939937510d0\n doubleprecision,parameter :: degrees_to_radians = PI / 180.0D+00\n real,intent(in) :: angle_in_degrees\n cosd=cos(angle_in_degrees*degrees_to_radians)\n end function cosd\n\nend program demo_centertext\n", "meta": {"hexsha": "6c7d2438ed0f6fa3cad3892126f074f220589716", "size": 1876, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/demo_centertext.f90", "max_stars_repo_name": "urbanjost/M_draw", "max_stars_repo_head_hexsha": "e82fb2dc669d324847a97f0620687b39aea6a53b", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-25T05:43:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T05:43:49.000Z", "max_issues_repo_path": "example/demo_centertext.f90", "max_issues_repo_name": "urbanjost/M_draw", "max_issues_repo_head_hexsha": "e82fb2dc669d324847a97f0620687b39aea6a53b", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "example/demo_centertext.f90", "max_forks_repo_name": "urbanjost/M_draw", "max_forks_repo_head_hexsha": "e82fb2dc669d324847a97f0620687b39aea6a53b", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-05-25T05:43:44.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-25T05:43:44.000Z", "avg_line_length": 31.2666666667, "max_line_length": 93, "alphanum_fraction": 0.6348614072, "num_tokens": 612, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.6706756034450179}} {"text": "program assertion_examples\n !! Demonstrate the use of assertions as runtime checks on the satisfaction of \n !! of two kinds of constraints:\n !! 1. Preconditions: requirements for correct execution at the start of a procedure and\n !! 2. Postconditions: requirements for correct execution at the end of a procedure.\n implicit none\n \n print *, reciprocal(2.)\n\ncontains\n\n pure real function reciprocal(x) result(reciprocal_of_x)\n !! Erroneous calculation of the reciprocal of the function's argument\n use assert_m, only : assert\n real, intent(in) :: x\n\n call assert(assertion = x /= 0., description = \"reciprocal: x /= 0\", diagnostic_data = x) ! Precondition passes\n\n reciprocal_of_x = 0. ! incorrect value for the reciprocal of x\n\n block\n real, parameter :: tolerance = 1.E-06\n\n associate(error => x*reciprocal_of_x - 1.) \n\n call assert(abs(error) < tolerance, \"reciprocal: abs(error) < tolerance\", error) ! Postcondition fails\n\n end associate\n end block\n\n end function\n\nend program\n", "meta": {"hexsha": "2797dc343041ecca3d702444757bc3990a334615", "size": 1032, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/simple_assertions.f90", "max_stars_repo_name": "everythingfunctional/assert", "max_stars_repo_head_hexsha": "f796469d8902d74dd4639fed7d70f6393593a94a", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2021-08-22T03:08:33.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-14T02:28:00.000Z", "max_issues_repo_path": "example/simple_assertions.f90", "max_issues_repo_name": "everythingfunctional/assert", "max_issues_repo_head_hexsha": "f796469d8902d74dd4639fed7d70f6393593a94a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-08-23T06:08:29.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-23T06:08:29.000Z", "max_forks_repo_path": "example/simple_assertions.f90", "max_forks_repo_name": "everythingfunctional/assert", "max_forks_repo_head_hexsha": "f796469d8902d74dd4639fed7d70f6393593a94a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-08-22T03:10:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-21T13:54:42.000Z", "avg_line_length": 30.3529411765, "max_line_length": 115, "alphanum_fraction": 0.7063953488, "num_tokens": 250, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.8006919949619793, "lm_q1q2_score": 0.6706755994613113}} {"text": "*> \\brief \\b DLADIV performs complex division in real arithmetic, avoiding unnecessary overflow.\n*\n* =========== DOCUMENTATION ===========\n*\n* Online html documentation available at \n* http://www.netlib.org/lapack/explore-html/ \n*\n*> \\htmlonly\n*> Download DLADIV + dependencies \n*> \n*> [TGZ] \n*> \n*> [ZIP] \n*> \n*> [TXT]\n*> \\endhtmlonly \n*\n* Definition:\n* ===========\n*\n* SUBROUTINE DLADIV( A, B, C, D, P, Q )\n* \n* .. Scalar Arguments ..\n* DOUBLE PRECISION A, B, C, D, P, Q\n* ..\n* \n*\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*>\n*> DLADIV performs complex division in real arithmetic\n*>\n*> a + i*b\n*> p + i*q = ---------\n*> c + i*d\n*>\n*> The algorithm is due to Robert L. Smith and can be found\n*> in D. Knuth, The art of Computer Programming, Vol.2, p.195\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in] A\n*> \\verbatim\n*> A is DOUBLE PRECISION\n*> \\endverbatim\n*>\n*> \\param[in] B\n*> \\verbatim\n*> B is DOUBLE PRECISION\n*> \\endverbatim\n*>\n*> \\param[in] C\n*> \\verbatim\n*> C is DOUBLE PRECISION\n*> \\endverbatim\n*>\n*> \\param[in] D\n*> \\verbatim\n*> D is DOUBLE PRECISION\n*> The scalars a, b, c, and d in the above expression.\n*> \\endverbatim\n*>\n*> \\param[out] P\n*> \\verbatim\n*> P is DOUBLE PRECISION\n*> \\endverbatim\n*>\n*> \\param[out] Q\n*> \\verbatim\n*> Q is DOUBLE PRECISION\n*> The scalars p and q in the above expression.\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee \n*> \\author Univ. of California Berkeley \n*> \\author Univ. of Colorado Denver \n*> \\author NAG Ltd. \n*\n*> \\date September 2012\n*\n*> \\ingroup auxOTHERauxiliary\n*\n* =====================================================================\n SUBROUTINE DLADIV( A, B, C, D, P, Q )\n*\n* -- LAPACK auxiliary routine (version 3.4.2) --\n* -- LAPACK is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n* September 2012\n*\n* .. Scalar Arguments ..\n DOUBLE PRECISION A, B, C, D, P, Q\n* ..\n*\n* =====================================================================\n*\n* .. Local Scalars ..\n DOUBLE PRECISION E, F\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC ABS\n* ..\n* .. Executable Statements ..\n*\n IF( ABS( D ).LT.ABS( C ) ) THEN\n E = D / C\n F = C + D*E\n P = ( A+B*E ) / F\n Q = ( B-A*E ) / F\n ELSE\n E = C / D\n F = D + C*E\n P = ( B+A*E ) / F\n Q = ( -A+B*E ) / F\n END IF\n*\n RETURN\n*\n* End of DLADIV\n*\n END\nc $Id$\n", "meta": {"hexsha": "242ed5f514167855f91f2d378e24c27423d7eea4", "size": 3055, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/lapack/double/dladiv.f", "max_stars_repo_name": "dinisAbranches/nwchem", "max_stars_repo_head_hexsha": "21cb07ff634475600ab687882652b823cad8c0cd", "max_stars_repo_licenses": ["ECL-2.0"], "max_stars_count": 317, "max_stars_repo_stars_event_min_datetime": "2017-11-20T21:29:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T11:48:24.000Z", "max_issues_repo_path": "src/lapack/double/dladiv.f", "max_issues_repo_name": "dinisAbranches/nwchem", "max_issues_repo_head_hexsha": "21cb07ff634475600ab687882652b823cad8c0cd", "max_issues_repo_licenses": ["ECL-2.0"], "max_issues_count": 356, "max_issues_repo_issues_event_min_datetime": "2017-12-05T01:38:12.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T02:28:21.000Z", "max_forks_repo_path": "src/lapack/double/dladiv.f", "max_forks_repo_name": "dinisAbranches/nwchem", "max_forks_repo_head_hexsha": "21cb07ff634475600ab687882652b823cad8c0cd", "max_forks_repo_licenses": ["ECL-2.0"], "max_forks_count": 135, "max_forks_repo_forks_event_min_datetime": "2017-11-19T18:36:44.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T02:28:49.000Z", "avg_line_length": 23.5, "max_line_length": 112, "alphanum_fraction": 0.5119476268, "num_tokens": 912, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199552262966, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.6706755969538138}} {"text": " double precision function DERFI (X)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nC--D replaces \"?\": ?ERFI, ?ERFCI, ?ERFIX, ?ERM1\nc>> 1998-11-01 DERFI Krogh Removed some equivalence for \"mangle\".\nc>> 1996-06-18 DERFI Krogh Changes to use .C. and C%%. J not changed.\nc>> 1996-03-30 DERFI Krogh Added external statements.\nC>> 1995-11-28 DERFI Krogh Removed multiple entries.\nC>> 1995-11-03 DERFI Krogh Removed blanks in numbers for C conversion.\nC>> 1994-10-20 DERFI Krogh Changes to use M77CON\nC>> 1994-04-20 DERFI CLL Edited type stmts to make DP & SP files similar\nC>> 1987-10-29 DERFI Snyder Initial code.\nc\nc For -1.0 .LT. X .LT. 1.0 calculate the inverse of the error\nc function. That is, X = ERF(ERFI).\nc\nc For 0.0 .LT. X .LT. 2.0 calculate the inverse of the\nc complementary error function. that is, X = ERFC(ERFCI). This\nc calculation is carried out by invoking the alternate entry *ERFCI.\nc\nc If X is out of range, program execution is terminated by calling\nc the error message processor.\nc\nc This subprogram uses approximations due to A. Strecok from\nc Mathematics of Computation 22, (1968) pp 144-158.\nc\n external DERFIX\n double precision DERFIX\n double precision X\n double precision ARG, D(6), FSIGN, S\n integer J\nc\nc ***** Parameters *****************************************\nc\nc MAX... is the position in C of the last coefficient of a Chebyshev\nc polynomial expansion.\nc MIN... is the position in C of the first coefficient of a Chebyshev\nc polynomial expansion.\nc NC is the upper dimension of the array of coefficients.\nc NDELTA is the number of coefficients of the Chebyshev polynomial\nc expansion used to approximate R(X) in the range\nc 0.9975 .LT. X .LE. 1-5.0D-16\nc NLAMDA is the number of coefficients of the Chebyshev polynomial\nc expansion used to approximate R(X) in the range\nc 0.8 .LT. X .LE. 0.9975.\nc NMU is the number of coefficients of the Chebyshev polynomial\nc expansion used to approximate R(X) in the range\nc 5.0D-16 .GT. 1-X .GE. 1.D-300.\nc NXI is the number of coefficients of the Chebyshev polynomial\nc expansion used to approximate DERFCI(X)/X in the\nc range 0.0 .LE. X .LE. 0.8.\nc\nc\nc ***** External References ********************************\nc\nc D1MACH Provides the round-off level. Used to calculate the number\nc of coefficients to retain in each Chebyshev expansion.\nc DERM1 Prints an error message and stops if X .LE. -1.0 or\nc X .GE. 1.0 (ERFI) or X .LE. 0.0 or X .GE. 2.0 (ERFCI).\nc LOG Calculates the natural logarithm.\nc SQRT Calculates the square root.\nc\nc\nc ***** Local Variables ***********************************\nc\nc ARG If ERFI or ERFCI is being approximated by a Chebyshev\nc expansion then ARG is the argument of ERFI or the argument\nc that would be used if ERFCI(X) were computed as ERFC(1-X),\nc that is, ARG = X if ERFI is being computed, or ARG = 1-X if\nc ERFCI is being computed. If ERFI or ERFCI is being computed\nc using the initial approximation ERFI=SQRT(-LOG((1-X)*(1+X))),\nc then ARG is that initial approximation.\nc C contains the coefficients of polynomial expansions. They are\nc stored in C in the order DELTA(0..37), LAMDA(0..26),\nc MU(0..25), XI(0..38).\nc D are used to scale the argument of the Chebyshev polynomial\nc expansion in the range 1.D-300 .LT. 1-X .LT. 0.2.\nc DELTA are coefficients of the Chebyshev polynomial expansion of R(X)\nc for 0.9975 .LT. X .LE. 1-5.0D-16.\nc FIRST is a logical SAVE variable indicating whether it is necessary\nc to calculate the number of coefficients to use for each\nc Chebyshev expansion.\nc FSIGN is X or 1.0 - X. It is used to remember the sign to be\nc assigned to the function value.\nc I, J are used as indices.\nc IMIN is the minimum index of a coefficient in the Chebyshev\nc polynomial expansion to be used.\nc JIX is an array containing MINXI, MAXXI, MINLAM, MAXLAM, MINDEL,\nc MAXDEL, MINMU, MAXMU in locations -1..6\nc LAMDA are coefficients of the Chebyshev polynomial expansion of R(X)\nc for 0.8 .LT. X .LE. 0.9975.\nc MU are coefficients of the Chebyshev polynomial expansion of R(X)\nc for 5.0D-16 .GT. 1-X .GE. 1.D-300.\nc S2 is 2.0 * S.\nc S is the argument of the Chebyshev polynomial expansion.\nc W1..W3 are adjacent elements of the recurrence used to evaluate the\nc Chebyshev polynomial expansion.\nc XI are coefficients of the Chebyshev polynomial expansion of\nc ERFC(X)/X for 0.0 .LE. X .LE. 0.8.\nc\n data D /-1.548813042373261659512742D0\n 2, 2.565490123147816151928163D0\n 3, -.5594576313298323225436913D0\n 4, 2.287915716263357638965891D0\n 5, -9.199992358830151031278420D0\n 6, 2.794990820124599493768426D0/\nc\n fsign = x\n arg = abs(x)\n if (arg.lt.0.0d0 .or. arg.ge.1.0d0)then\n call derm1 ('DERFI',1,2,'Argument out of range','X',x,'.')\nc In case the error level is shifted to zero by the caller:\n derfi = 0.0d0\n return\n end if\n if (arg.eq.0.0d0) then\n derfi = 0.0d0\n return\n end if\n if (arg.le.0.8d0) then\n s = 3.125d0*arg*arg - 1.0d0\n j = -1\n else\n if (arg.le.0.9975d0) then\n j = 1\n else\n j = 3\n end if\n arg = sqrt(-log((1.0d0-arg)*(1.0d0+arg)))\n s = d(j)*arg + d(j+1)\n end if\n DERFI = sign(arg*DERFIX(s, j), fsign)\n return\n end\nc\nc ***** entry ERFCI ****************************************\nc\n double precision function DERFCI(X)\nc Calculate the inverse of the complementary error function.\nc\n external DERFIX\n double precision DERFIX\n double precision X\n double precision ARG, D(6), FSIGN, S\n integer J\n data D /-1.548813042373261659512742D0\n 2, 2.565490123147816151928163D0\n 3, -.5594576313298323225436913D0\n 4, 2.287915716263357638965891D0\n 5, -9.199992358830151031278420D0\n 6, 2.794990820124599493768426D0/\nc\nc Decide which approximation to use, and calculate the argument of\nc the Chebyshev polynomial expansion.\nc\n if (x.le.0.0d0 .or. x.ge.2.0d0) then\n call derm1('DERFCI',1,2,'Argument out of range','X',x,'.')\nc In case the error level is shifted to zero by the caller:\n derfci = 0.0d0\n end if\n if (x.eq.1.0d0) then\n derfci = 0.0d0\n return\n end if\n fsign = 1.0d0 - x\n arg = abs(fsign)\n if (arg.le.0.8d0) then\n s = 3.125d0*arg*arg - 1.0d0\n j = -1\n else\n arg = 2.0d0 - x\n if (x.lt.1.0d0) then\n s = x\n else\n s = arg\n end if\n arg = sqrt(-log(x*arg))\n if (s.lt.5.0d-16) then\n j = 5\n s = d(5)/sqrt(arg) + d(6)\n else\n if (s.ge.0.0025d0) then\n j = 1\n else if (s.ge.5.0d-16) then\n j = 3\n end if\n s = d(j)*arg + d(j+1)\n end if\n end if\n DERFCI = sign(arg*DERFIX(s, j), fsign)\n return\n end\nc\n double precision function DERFIX(S, J)\nc Subroutine where most of calculations are done.\n external D1MACH\n integer MAXDEL, MAXLAM, MAXMU, MAXXI, MINDEL, MINLAM\n integer MINMU, MINXI, NC, NDELTA, NLAMDA, NMU, NXI\n parameter (MINDEL = 0)\n parameter (NDELTA = 37)\n parameter (MAXDEL = MINDEL + NDELTA)\n parameter (MINLAM = MAXDEL + 1)\n parameter (NLAMDA = 26)\n parameter (MAXLAM = MINLAM + NLAMDA)\n parameter (MINMU = MAXLAM + 1)\n parameter (NMU = 25)\n parameter (MAXMU = MINMU + NMU)\n parameter (MINXI = MAXMU + 1)\n parameter (NXI = 38)\n parameter (MAXXI = MINXI + NXI)\n parameter (NC = MAXXI)\n double precision D1MACH\n double precision C(0:NC)\n logical FIRST\n save FIRST\n integer I, J, JIX(-1:6)\n save JIX\n integer IMIN\n double precision S, S2\n double precision W1, W2, W3\nc\nc ***** Equivalence Statements *****************************\nc\nc Equivalence statements connecting arrays DELTA, LAMDA, MU, XI removed\nc by FTK to make \"mangle\" work. All references to these arrays have\nc been replaced by references to C.\nc\nc ***** Data Statements ************************************\nc\nc DELTA(J), J = 0..NDELTA, then\nc LAMDA(J), J = 0..NLAMDA, then\nc MU(J), J = 0..NMU, then\nc XI(J), J = 0..NXI\nc\nc++ With first index 0, save data by elements if ~.C.\n data C(0) / .9566797090204925274526373D0 /\n data C(1) / -.0231070043090649036999908D0 /\n data C(2) / -.0043742360975084077333218D0 /\n data C(3) / -.0005765034226511854809364D0 /\n data C(4) / -.0000109610223070923931242D0 /\n data C(5) / .0000251085470246442787982D0 /\n data C(6) / .0000105623360679477511955D0 /\n data C(7) / .0000027544123300306391503D0 /\n data C(8) / .0000004324844983283380689D0 /\n data C(9) / -.0000000205303366552086916D0 /\n data C(10) / -.0000000438915366654316784D0 /\n data C(11) / -.0000000176840095080881795D0 /\n data C(12) / -.0000000039912890280463420D0 /\n data C(13) / -.0000000001869324124559212D0 /\n data C(14) / .0000000002729227396746077D0 /\n data C(15) / .0000000001328172131565497D0 /\n data C(16) / .0000000000318342484482286D0 /\n data C(17) / .0000000000016700607751926D0 /\n data C(18) / -.0000000000020364649611537D0 /\n data C(19) / -.0000000000009648468127965D0 /\n data C(20) / -.0000000000002195672778128D0 /\n data C(21) / -.0000000000000095689813014D0 /\n data C(22) / .0000000000000137032572230D0 /\n data C(23) / .0000000000000062538505417D0 /\n data C(24) / .0000000000000014584615266D0 /\n data C(25) / .0000000000000001078123993D0 /\n data C(26) / -.0000000000000000709229988D0 /\n data C(27) / -.0000000000000000391411775D0 /\n data C(28) / -.0000000000000000111659209D0 /\n data C(29) / -.0000000000000000015770366D0 /\n data C(30) / .0000000000000000002853149D0 /\n data C(31) / .0000000000000000002716662D0 /\n data C(32) / .0000000000000000000957770D0 /\n data C(33) / .0000000000000000000176835D0 /\n data C(34) / -.0000000000000000000009828D0 /\n data C(35) / -.0000000000000000000020464D0 /\n data C(36) / -.0000000000000000000008020D0 /\n data C(37) / -.0000000000000000000001650D0 /\n data C(38) / .9121588034175537733059200D0 /\n data C(39) / -.0162662818676636958546661D0 /\n data C(40) / .0004335564729494453650589D0 /\n data C(41) / .0002144385700744592065205D0 /\n data C(42) / .0000026257510757648130176D0 /\n data C(43) / -.0000030210910501037969912D0 /\n data C(44) / -.0000000124060618367572157D0 /\n data C(45) / .0000000624066092999917380D0 /\n data C(46) / -.0000000005401247900957858D0 /\n data C(47) / -.0000000014232078975315910D0 /\n data C(48) / .0000000000343840281955305D0 /\n data C(49) / .0000000000335848703900138D0 /\n data C(50) / -.0000000000014584288516512D0 /\n data C(51) / -.0000000000008102174258833D0 /\n data C(52) / .0000000000000525324085874D0 /\n data C(53) / .0000000000000197115408612D0 /\n data C(54) / -.0000000000000017494333828D0 /\n data C(55) / -.0000000000000004800596619D0 /\n data C(56) / .0000000000000000557302987D0 /\n data C(57) / .0000000000000000116326054D0 /\n data C(58) / -.0000000000000000017262489D0 /\n data C(59) / -.0000000000000000002784973D0 /\n data C(60) / .0000000000000000000524481D0 /\n data C(61) / .0000000000000000000065270D0 /\n data C(62) / -.0000000000000000000015707D0 /\n data C(63) / -.0000000000000000000001475D0 /\n data C(64) / .0000000000000000000000450D0 /\n data C(65) / .9885750640661893136460358D0 /\n data C(66) / .0108577051845994776160281D0 /\n data C(67) / -.0017511651027627952494825D0 /\n data C(68) / .0000211969932065633437984D0 /\n data C(69) / .0000156648714042435087911D0 /\n data C(70) / -.0000005190416869103124261D0 /\n data C(71) / -.0000000371357897426717780D0 /\n data C(72) / .0000000012174308662357429D0 /\n data C(73) / -.0000000001768115526613442D0 /\n data C(74) / -.0000000000119372182556161D0 /\n data C(75) / .0000000000003802505358299D0 /\n data C(76) / -.0000000000000660188322362D0 /\n data C(77) / -.0000000000000087917055170D0 /\n data C(78) / -.0000000000000003506869329D0 /\n data C(79) / -.0000000000000000697221497D0 /\n data C(80) / -.0000000000000000109567941D0 /\n data C(81) / -.0000000000000000011536390D0 /\n data C(82) / -.0000000000000000001326235D0 /\n data C(83) / -.0000000000000000000263938D0 /\n data C(84) / .0000000000000000000005341D0 /\n data C(85) / -.0000000000000000000022610D0 /\n data C(86) / .0000000000000000000009552D0 /\n data C(87) / -.0000000000000000000005250D0 /\n data C(88) / .0000000000000000000002487D0 /\n data C(89) / -.0000000000000000000001134D0 /\n data C(90) / .0000000000000000000000420D0 /\n data C(91) / .9928853766189408231495800D0 /\n data C(92) / .1204675161431044864647846D0 /\n data C(93) / .0160781993420999447257039D0 /\n data C(94) / .0026867044371623158279591D0 /\n data C(95) / .0004996347302357262947170D0 /\n data C(96) / .0000988982185991204409911D0 /\n data C(97) / .0000203918127639944337340D0 /\n data C(98) / .0000043272716177354218758D0 /\n data C(99) / .0000009380814128593406758D0 /\n data C(100) / .0000002067347208683427411D0 /\n data C(101) / .0000000461596991054300078D0 /\n data C(102) / .0000000104166797027146217D0 /\n data C(103) / .0000000023715009995921222D0 /\n data C(104) / .0000000005439284068471390D0 /\n data C(105) / .0000000001255489864097987D0 /\n data C(106) / .0000000000291381803663201D0 /\n data C(107) / .0000000000067949421808797D0 /\n data C(108) / .0000000000015912343331469D0 /\n data C(109) / .0000000000003740250585245D0 /\n data C(110) / .0000000000000882087762421D0 /\n data C(111) / .0000000000000208650897725D0 /\n data C(112) / .0000000000000049488041039D0 /\n data C(113) / .0000000000000011766394740D0 /\n data C(114) / .0000000000000002803855725D0 /\n data C(115) / .0000000000000000669506638D0 /\n data C(116) / .0000000000000000160165495D0 /\n data C(117) / .0000000000000000038382583D0 /\n data C(118) / .0000000000000000009212851D0 /\n data C(119) / .0000000000000000002214615D0 /\n data C(120) / .0000000000000000000533091D0 /\n data C(121) / .0000000000000000000128488D0 /\n data C(122) / .0000000000000000000031006D0 /\n data C(123) / .0000000000000000000007491D0 /\n data C(124) / .0000000000000000000001812D0 /\n data C(125) / .0000000000000000000000439D0 /\n data C(126) / .0000000000000000000000106D0 /\n data C(127) / .0000000000000000000000026D0 /\n data C(128) / .0000000000000000000000006D0 /\n data C(129) / .0000000000000000000000002D0 /\nc\n data FIRST /.TRUE./\nc\n data JIX /MINXI, MAXXI, MINLAM, MAXLAM, MINDEL, MAXDEL\n 1, MINMU, MAXMU/\nc\nc ***** Procedures *****************************************\nc\nc Decide which approximation to use, and calculate the argument of\nc the Chebyshev polynomial expansion.\nc\nc\nc If this is the first call, calculate the degree of each expansion.\nc\n if (first) then\n first = .false.\n s2 = 0.5d0*d1mach(3)\n do 120 imin = -1, 5, 2\n do 110 i = jix(imin), jix(imin+1)\n if (abs(c(i)).lt.s2) then\n jix(imin+1) = i\n go to 120\n end if\n110 continue\n120 continue\n end if\nc\nc Evaluate the Chebyshev polynomial expansion.\nc\n s2 = s + s\n w1 = 0.0d0\n w2 = 0.0d0\n imin = jix(j)\n i = jix(j+1)\n200 w3 = w2\n w2 = w1\n w1 = (s2*w2 - w3) + c(i)\n i = i - 1\n if (i.gt.imin) go to 200\n derfix = (s*w1 - w2) + c(imin)\n return\n end\n", "meta": {"hexsha": "0b9580f12d21cd5096a70201df5fc75cdfd2cfc3", "size": 16636, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/derfi.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/derfi.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/derfi.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": 40.6748166259, "max_line_length": 72, "alphanum_fraction": 0.6191993268, "num_tokens": 5890, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299612154571, "lm_q2_score": 0.724870282120402, "lm_q1q2_score": 0.670671703012497}} {"text": "c############################################################\nc IPT solution of the Hubbard model on the real axis at T=0\nc by M.J. Rozenberg\nc This code is essentially the first code IPT on the real axis\nc that was able to go across the Mott-Hubbard transition and\nc observe the coexistent solutions. It was written by X.Y. Zhang\nc and M.J. Rozenberg, and the results published in X.Y. Zhang,\nc M. J. Rozenberg and G. Kotliar, Phys Rev Lett v70, p1666 (1993)\nc############################################################\n\n \tparameter(L=2*8192)\n\timplicit real*8(a-h,o-z)\n\tdouble complex one,xi,xs,sq,g,ome\n\tdouble complex g0(2*L),tg0(2*L),fg0(-L:L)\n\tdouble complex sft2(2*L),sf2(2*L),sft(-L:L),sf(-L:L)\n\tdouble precision dns(2*L), dns0(2*L)\n\n\nc************************************************\nc read input data\nc f = \tfrequency mesh\nc d0 = \thalf-bandwidth of the semicircular DOS (Bethe lattice)\nc u =\tHubbard repulsion\n\n \tread(22,*)f,d0,u\nc************************************************\n\nc************************************************\nc initialize parameters\n \tpi=datan(1.d0)*4.d0\n\tdtau=2.*pi/f/dfloat(2*L)\n\tf2=f**2\n\tone=(1.d0,0.d0)\n\txi =(0.d0,1.d0)\n\tXL=dfloat(L)\n\tL2=2*L\n\nc set the imet flag for metallic or insulating solution\n \tif(u.le.3.d0)imet=1\n \tif(u.gt.3.3d0)imet=0\n \tif(u.gt.3.d0.and.u.le.3.3d0)then\n123\tcontinue\n\twrite(6,*) 'find the metal or the insulator? (1 or 0)'\n\tread(5,*)imet\n\tif(imet.ne.0.and.imet.ne.1)then\n\twrite(6,*) 'you have to type 1 for metal or 0 for insulator'\n\tgoto 123\n \tendif\n \tendif\n\t\n\tprint*,imet\n\nc nloop= number of sc loops \n\tif(imet.eq.0)then\n\tnloop=30\n\telse\n\tnloop=10\n\tif(u.gt.2.d0) nloop=30\n\tif(u.gt.3.d0) nloop=100\n\tif(u.gt.3.2d0) nloop=300\n\tendif\n\nc nl0= fixes the number of last sc loops to print out\nc default is 1\n\tnl0=nloop-1\n\t\n\nc output data parameters\n\ti01=20\n\timax1=2000\n\ti02=30\n\timax2=16000\n\n\tdo i=-L,L\n\tsf(i)=(0.d0,0.d0)\n\tenddo\n\nc*******************************************************\n\nc self-consistent loop starts here**********************\n\tdo 100 iloop=1,nloop\n\n\tif(iloop.eq.nloop/2)then\n\twrite(6,*) 'I am half way thru...'\n\tendif\n\n\nc calculate Go\n\tdo 2 i=L+1,2*L\n\tom=(float(i)-XL-1.)*f\n\tsig=1.d0\n\tome=om*one\n\n\tif(iloop.eq.1)then\nc choose a Go seed in the first loop***\n\n\t if(dabs(om).lt.1.d-9)then\n\t g0(i)=0.*one\n\telse\n\t g0(i)=1./(ome+float(imet)*d0*xi/2.)\n\tendif\n\n\n\telse\nc calculate a new Go from the last Sigma\n\n\txs=sf(i-L-1)\n\tsq=cdsqrt((ome-xs)**2-d0**2*one)\n\tsqim=dimag(sq)\n\tsqre=dreal(sq)\n\n\tif(i.le.L+5)then\nc get the first five frequency points on the right branch-cut\n\t\tif(sqre.gt.0..and.imet.eq.0)sig=-1.d0\n\telse\nc choose the branch based on continuity criterium \n\t\tbenpr=dreal(2./(ome+xs+sq))\n\t \tbenmr=dreal(2./(ome+xs-sq))\n\t \tbenpi=dimag(2./(ome+xs+sq))\n\t\tbenmi=dimag(2./(ome+xs-sq))\n\t\txp=((benpr+benchr0-2.*benchr)**2\n $ \t+(benpi+benchi0-2.*benchi)**2)\n\t\txm=((benmr+benchr0-2.*benchr)**2\n $ \t+(benmi+benchi0-2.*benchi)**2)\n\t\tif(xp.gt.xm)sig=-1.d0\n \tg=(2./(ome+xs+sq))\n \td1=dimag(one/g)-dimag(sf(i-L-1))\n \td2=dreal(one/g)-dreal(sf(i-L-1))\n \td2=d2**2\n \td3=d1**2\n \tdn=d1/(d2+d3)\n \tif(dn.lt.0)sig=-1.\n\tendif\n\nc this is the new Go\n\tg0(i)=2./(ome+xs+sig*sq)\n\n\tendif\n\n\tbenchr=dreal(g0(i))\n\tbenchi=dimag(g0(i))\n\tbenchr0=dreal(g0(i-1))\n\tbenchi0=dimag(g0(i-1))\n2\tcontinue\n\n\nc writes the omega < 0 part of Go for \"causal\" GF\n\tdo 222 i=1,L-1\n\tg0(L+1-i)=-g0(L+1+i)\n222\tcontinue\n\nc fix the end-point\n\tg0(1)=g0(2)\nc fix the Go(omega=0) equal to 0 (L+1-point) \n\tg0(L+1)=0.*one\n\nc*** g0 is Go(omega) \n\n\n\nc-------------------------------------\nc FFT from omega to time\n do i=1,2*L\n tg0(i)=g0(i)\n enddo\n call four1(tg0,L2,1)\n\n\n\tex=-1.\n do 3 i=1,2*L\n\tex=-ex\n tg0(i)=ex*f/2./pi*tg0(i)\n 3 continue\n\n do 4 i=1,L\n fg0(i-1)=tg0(i)\n 4 continue\n\n do 5 i=L+1,2*L\n fg0(-2*L-1+i)=tg0(i)\n 5 continue\n\nc *** fg0(i) is Go(t)\nc-------------------------------------\n\n\nc computes the Sigma*************************\nc Sigma(t) = U^2/4 * Go^3(t)\n\n\tdo 7 i=-L+1,L-1\n\tsft(i)=-u**2*fg0(i)**2*fg0(-i)\n7\tcontinue\n\tsft(-L)=-u**2*fg0(-L)**2*fg0(L-1)\n\n do 24 i=-L,L-1\n\t sft2(i+L+1)=sft(i)\n 24 continue\n\n\nc********************************************\n\nc-------------------------------------\nc FFT from time to omega \n\n do i=1,2*L\n sf2(i)=sft2(i)\n enddo\n call four1(sf2,L2,-1)\n\n\n\tex=-1.\n\tdo 8 i=1,2*L\n\tex=-ex\n\tsf2(i)=-ex*dtau*sf2(i)\n8\tcontinue\n\n do 34 i=1,L\n sf(i-1)=sf2(i)\n34 continue\n\n do 35 i=L+1,2*L\n sf(-2*L-1+i)=sf2(i)\n35 continue\n\n\nc*** sf is Sigma(omega)\nc-------------------------------------\n\n\nc print output data********************************************\n\n if(iloop.eq.1.and.imet.eq.1)then\nc get the first loop Im[G(w)] (impurity problem, no sc)*********\n do 110 i=1,2*L\n if(i.eq.L+1)then\nc computes the value of Im[G(0)]\n dns0(i)=2.*float(imet)/d0\n else\nc computes the value of Im[G(w)]\n d1=dimag(one/g0(i))-dimag(sf(i-L-1))\n d2=dreal(one/g0(i))-dreal(sf(i-L-1))\n d2=d2**2\n d3=d1**2\n dns0(i)=d1/(d2+d3)\n endif\n110 continue\n\tendif\n\n\n\tif(iloop.gt.nl0)then\nc get the self-consistent Im[G(w)]****************\n\tdo 111 i=1,2*L\n\tif(i.eq.L+1)then\nc computes the value of Im[G(0)]\n\tdns(i)=2.d0*dfloat(imet)/d0\n\telse\nc computes the value of Im[G(w)]\n\td1=dimag(one/g0(i))-dimag(sf(i-L-1))\n\td2=dreal(one/g0(i))-dreal(sf(i-L-1))\n\td2=d2**2\n\td3=d1**2\n\tdns(i)=d1/(d2+d3)\n\tendif\n111\tcontinue\n\n\n\nc print output files\nc fort.25 is Im[G(w)] (the DOS)\nc fort.23 is Re[Sigma(w)]\nc fort.24 is Im[Sigma(w)]\nc fort.26 is Im[G(w)] (impurity problem, no self-consistency, imet=1)\n\n\tdo i=imax2,imax1+1,-i02\n write(26,*)-real(f*float(i)),(dns0(i+L+1))\n write(25,*)-real(f*float(i)),(dns(i+L+1))\n \twrite(24,*)-real(f*float(i)),dabs(dimag(sf(-i)))\n write(23,*)-real(f*float(i)),(dreal(sf(-i)))\nc\twrite(27,*)-real(f*float(i)),dreal(dreal(g0(i+L+1)))\nc\twrite(28,*)-real(f*float(i)),dreal(dimag(g0(i+L+1)))\n\tenddo\n\n do i=imax1,0,-i01\n write(26,*)-real(f*float(i)),(dns0(i+L+1))\n write(25,*)-real(f*float(i)),(dns(i+L+1))\n \twrite(24,*)-real(f*float(i)),dabs(dimag(sf(-i)))\n write(23,*)-real(f*float(i)),(dreal(sf(-i)))\nc\twrite(27,*)-real(f*float(i)),dreal(dreal(g0(i+L+1)))\nc\twrite(28,*)-real(f*float(i)),dreal(dimag(g0(i+L+1)))\n\tenddo\n\n\tdo 118 i=1,imax1,i01\n write(26,*)real(f*float(i)),(dns0(i+L+1))\n\twrite(25,*)real(f*float(i)),(dns(i+L+1))\n \twrite(24,*)real(f*float(i)),dabs(dimag(sf(i)))\n \twrite(23,*)real(f*float(i)),(dreal(sf(i)))\nc\twrite(27,*)real(f*float(i)),dreal(dreal(g0(i+L+1)))\nc\twrite(28,*)real(f*float(i)),dreal(dimag(g0(i+L+1)))\n118\tcontinue\n\n\tdo 116 i=imax1+1,imax2,i02\n write(26,*)real(f*float(i)),(dns0(i+L+1))\n\twrite(25,*)real(f*float(i)),(dns(i+L+1))\n \twrite(24,*)real(f*float(i)),dabs(dimag(sf(i)))\n \twrite(23,*)real(f*float(i)),(dreal(sf(i)))\nc\twrite(27,*)real(f*float(i)),dreal(dreal(g0(i+L+1)))\nc\twrite(28,*)real(f*float(i)),dreal(dimag(g0(i+L+1)))\n116\tcontinue\n\n \twrite(23,*)' '\n \twrite(24,*)' '\n\twrite(25,*)' '\n \twrite(26,*)' '\nc\twrite(27,*)' '\nc\twrite(28,*)' '\n\tendif\nc*************************************************************\n\n\nc go back to the self consistency loop\n100\tcontinue\t\n\n\n\tstop\n\tend\n\nc########################################################\n SUBROUTINE four1(data,nn,isign)\n implicit real*8(a-h,o-z)\n double precision data(2*nn)\nc INTEGER isign,nn\nc REAL data(2*nn)\nc INTEGER i,istep,j,m,mmax,n\nc REAL tempi,tempr\nc DOUBLE PRECISION theta,wi,wpi,wpr,wr,wtemp\n n=2*nn\n j=1\n do 11 i=1,n,2\n if(j.gt.i)then\n tempr=data(j)\n tempi=data(j+1)\n data(j)=data(i)\n data(j+1)=data(i+1)\n data(i)=tempr\n data(i+1)=tempi\n endif\n m=n/2\n1 if ((m.ge.2).and.(j.gt.m)) then\n j=j-m\n m=m/2\n goto 1\n endif\n j=j+m\n11 continue\n mmax=2\n2 if (n.gt.mmax) then\n istep=2*mmax\n theta=6.28318530717959d0/(isign*mmax)\n wpr=-2.d0*dsin(0.5d0*theta)**2\n wpi=dsin(theta)\n wr=1.d0\n wi=0.d0\n do 13 m=1,mmax,2\n do 12 i=m,n,istep\n j=i+mmax\n tempr=sngl(wr)*data(j)-sngl(wi)*data(j+1)\n tempi=sngl(wr)*data(j+1)+sngl(wi)*data(j)\n data(j)=data(i)-tempr\n data(j+1)=data(i+1)-tempi\n data(i)=data(i)+tempr\n data(i+1)=data(i+1)+tempi\n12 continue\n wtemp=wr\n wr=wr*wpr-wi*wpi+wr\n wi=wi*wpr+wtemp*wpi+wi\n13 continue\n mmax=istep\n goto 2\n endif\n return\n END\n\nc########################################################\nc########################################################\n\n\n", "meta": {"hexsha": "87592ab6fef4380a71c2302801ce52c3c8ede331", "size": 8874, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "najera_repo/FORTRAN/SOURCE/real_IPT.f", "max_stars_repo_name": "Bellomia/IPT.lab", "max_stars_repo_head_hexsha": "4e7bafbd2fa61793ee3a74ae25e63b25cbd142a0", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-07-07T23:05:09.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-07T23:05:24.000Z", "max_issues_repo_path": "najera_repo/FORTRAN/SOURCE/real_IPT.f", "max_issues_repo_name": "Bellomia/IPT.lab", "max_issues_repo_head_hexsha": "4e7bafbd2fa61793ee3a74ae25e63b25cbd142a0", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-01-19T12:01:19.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-19T23:23:24.000Z", "max_forks_repo_path": "legacy/FORTRAN/SOURCE/real_IPT.f", "max_forks_repo_name": "bellomia/MOTTlab", "max_forks_repo_head_hexsha": "12f1a1bb5d42bc4725cef524d26764cfe6d464e5", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.9302325581, "max_line_length": 70, "alphanum_fraction": 0.5189317106, "num_tokens": 3274, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299632771663, "lm_q2_score": 0.7248702761768248, "lm_q1q2_score": 0.670671699007793}} {"text": "C LAST UPDATE 16/04/91\nC+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\nC\n SUBROUTINE GAUSSIAN\n IMPLICIT NONE\nC\nC Purpose: Generate a 2-D gaussian function\nC\n INCLUDE 'COMMON.FOR'\nC\nC Calls 5: WFRAME , GETVAL , IMDISP , OPNNEW , OUTFIL\nC Called by: BSL\nC\nC-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-\nC Local variables:\nC\n REAL VALUE(10),XSQ,YSQ,SQNX,SQNY,RNX,RNY\n INTEGER NPIX,NRAST,IRC,IMEM,KPIC,IFRAME\n INTEGER I,J,K,ICENTX,ICENTY,NVAL\n CHARACTER*80 HEAD1,HEAD2\n CHARACTER*13 OFNAM\nC\nC IRC : Return code\nC IFRAME : Total nos. of frames\nC OFNAM : Output header filename\nC HEAD1 : Output header record 1\nC HEAD2 : Output header record 2\nC IMEM : Output memory dataset\nC NFRAME : Nos of time frames\nC NVAL : Nos. of numeric values entered\nC\n DATA IMEM/1/ , KPIC/1/ , IFRAME/1/\nC\nC-----------------------------------------------------------------------\n NPIX = 512\n NRAST = 512\n 10 WRITE (IPRINT,1000) NPIX,NRAST\n CALL GETVAL (ITERM,VALUE,NVAL,IRC)\n IF (IRC.EQ.1) GOTO 50\n IF (IRC.EQ.2) GOTO 10\n IF (NVAL.GT.0) NPIX=INT(VALUE(1))\n IF (NVAL.GT.1) NRAST=INT(VALUE(2))\nC\n ICENTX=(NPIX/2)+1\n ICENTY=(NRAST/2)+1\n15 WRITE (IPRINT,1010) ICENTX,ICENTY\n CALL GETVAL (ITERM,VALUE,NVAL,IRC)\n IF (IRC.EQ.1) GOTO 50\n IF (IRC.EQ.2) GOTO 15\n IF (NVAL.GT.0) ICENTX=INT(VALUE(1))\n IF (NVAL.GT.1) ICENTY=INT(VALUE(2))\nC\n RNX = 1.0\n RNY = 1.0\n20 WRITE (IPRINT,1020)\n CALL GETVAL (ITERM,VALUE,NVAL,IRC)\n IF (IRC.EQ.1) GOTO 50\n IF (IRC.EQ.2) GOTO 20\n IF (NVAL.GT.0) RNX=VALUE(1)\n IF (NVAL.GT.1) RNY=VALUE(2)\nC\nC========GENERATE THE FUNCTION\nC\n SQNX = (1.0/RNX)*(1.0/RNX)\n SQNY = (1.0/RNY)*(1.0/RNY)\ncx print *,nx,ny,sqnx,sqny\n K=1\n DO 40 I=1,NRAST\n YSQ=(I-ICENTY)*(I-ICENTY)\n DO 30 J=1,NPIX\n XSQ=(J-ICENTX)*(J-ICENTX)\n SP3(K)=EXP(-(SQNX*XSQ + SQNY*YSQ))\ncx print *,k,xsq,ysq,(SQNX*XSQ + SQNY*YSQ),sp3(k)\n K=K+1\n30 CONTINUE\n40 CONTINUE\nC\nC==========DISPLAY & OUTPUT FUNCTION\nC\n CALL IMDISP (ITERM,IPRINT,SP3,NPIX,NRAST)\n CALL OUTFIL (ITERM,IPRINT,OFNAM,HEAD1,HEAD2,IRC)\n IF (IRC.NE.0) GOTO 50\n CALL OPNNEW (LUNIT,NPIX,NRAST,IFRAME,OFNAM,IMEM,HEAD1,HEAD2,IRC)\n IF (IRC.NE.0) GOTO 50\n CALL WFRAME (LUNIT,KPIC,NPIX,NRAST,SP3,IRC)\n50 CALL FCLOSE (LUNIT)\n999 RETURN\nC \n1000 FORMAT (' Enter nos of pixels and rasters for image',\n & ' [',I4,',',I4,'] : ',$)\n1010 FORMAT (' Enter x,y coordinate for image centre',\n & ' [',I4,',',I4,'] : ',$)\n1020 FORMAT (' Enter x-factor,yfactor: ',$)\n END\n", "meta": {"hexsha": "6220b26f747eaca1b55bf05fa3db997ae631422c", "size": 2752, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "bsl/gaussian.f", "max_stars_repo_name": "scattering-central/CCP13", "max_stars_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "bsl/gaussian.f", "max_issues_repo_name": "scattering-central/CCP13", "max_issues_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "bsl/gaussian.f", "max_forks_repo_name": "scattering-central/CCP13", "max_forks_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-09-05T15:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-15T11:13:45.000Z", "avg_line_length": 28.9684210526, "max_line_length": 72, "alphanum_fraction": 0.5425145349, "num_tokens": 1044, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6706531189554127}} {"text": " program convdif \nc-----------------------------------------------------------------------\nc this driver will generate a finite element matrix for the\nc convection-diffusion problem \nc\nc - Div ( K(x,y) Grad u ) + C grad u = f\nc u = 0 on boundary \nc \nc (Dirichlet boundary conditions). \nc----------------------------------------------------------------------- \nc this code will prompt for desired mesh (from 0 to 9, with one being\nc a user input one) and will general the matrix in harewell-Boeing format\nc in the file mat.hb. It also generates two post script files, one \nc showing the pattern of the matrix (mat.ps) and the other showing the\nc corresponding mesh (msh.ps).\nc-----------------------------------------------------------------------\nc the structure and organization of the fem codes follow very closely \nc that of the book by Noborou Kikuchi (Finite element methods in \nc mechanics, Cambridge Univ. press, 1986). \nc-----------------------------------------------------------------------\nc coded Y. Saad and S. Ma -- this version dated August 11, 1993 \nc----------------------------------------------------------------------- \n implicit none \n integer maxnx, maxnel\n parameter (maxnx = 8000, maxnel = 15000)\n real*8 a(7*maxnx),x(maxnx),y(maxnx),f(3*maxnx)\n integer ijk(3,maxnel),ichild(12,maxnel),iparnts(2,maxnx),\n * ia(maxnx),ja(7*maxnx),iwk(maxnx),jwk(maxnx),nodcode(maxnx),\n * iperm(maxnx)\nc \n character matfile*20, title*72, munt*2,key*8, type*3\n real size \nc \n integer iin,node,nx,nelx,iout,ndeg,na,nmesh,nref,nxmax,nelmax,nb,\n * ii,nxnew, nelxnew,ierr,job,n,ncol,mode,ptitle,ifmt \n external xyk, funb, func, fung\n data iin/7/,node/3/,nx/0/,nelx/0/,iout/8/,ndeg/12/, na/3000/\nc--------------------------------------------------------------\nc choose starting mesh --- \nc--------------------------------------------------------------\nc files for output \nc \n open(unit=10,file='mat.hb') \n open(unit=11,file='msh.ps') \n open(unit=12,file='mat.ps') \nc-----------------------------------------------------------------------\n print *, ' enter chosen mesh '\n read (*,*) nmesh\n if (nmesh .eq. 0) then \n print *, 'enter input file for initial mesh '\n read(*,'(a20)') matfile\n open (unit=7,file=matfile)\n endif\nc----------------------------------------------------------------------- \n print *, ' Enter the number of refinements desired '\n read (*,*) nref\n call inmesh (nmesh,iin,nx,nelx,node,x,y,nodcode,ijk,iperm) \nc\nc ...REFINE THE GRID\nc \n nxmax = maxnx\n nelmax= maxnel\n nb = 0 \n do 10 ii = 1, nref\nc \nc estimate the number nx and nelx at next refinement level.\nc\n call checkref(nx,nelx,nodcode,nb,nxnew,nelxnew)\n if (nxnew .gt. nxmax .or. nelxnew .gt. nelmax) then\n\t print *, ' Was able to do only ', ii-1 ,' refinements'\n\t goto 11\n endif\nc\nc ...if OK refine all elements \nc \n call refall(nx,nelx,ijk,node,ndeg,x,y,ichild,iparnts,nodcode,\n * nxmax, nelmax, ierr)\n if (ierr .ne. 0) print *, '** ERROR IN REFALL : ierr =',ierr \n 10 continue\n 11 continue\nc-----------------------------------------------------------------------\n job = 0\nc-----------------------------------------------------------------------\nc assemble the matrix in CSR format \nc----------------------------------------------------------------------- \n call assmbo (nx,nelx,node,ijk,nodcode,x,y,\n * a,ja,ia,f,iwk,jwk,ierr,xyk,funb,func,fung) \n n = nx \nc----------------------Harewell-Boeing matrix---------------------------\nc---------------------1---------2---------3---------5---------6\nc 12345678901234567890123456789012345678901234567890\n title='1Sample matrix from SPARSKIT ' \n key = 'SPARSKIT'\n type = 'rua'\n ifmt = 6\n job = 2 \n call prtmt (n,n,a,ja,ia,f,'NN',title,key,type,ifmt,job,10) \nc----------------------Plot of mesh-------------------------------------\nc----------------------------------------------------------------------- \n size = 6.0 \n munt = 'in' \n mode = 0 \n title ='Finite element mesh ' \n ptitle = 1\n call psgrid (nx,ja,ia,x,y,title,ptitle,size,munt,11) \nc hsize = 5.6 \nc vsize = 5.6 \nc xleft = 0.0\nc bot = 0.0\nc job = 30 \nc call texgrd(nx,ja,ia,x,y,munt,size,vsize,hsize,\nc * xleft,bot,job,title,ptitle,ijk,node,nelx,11) \nc----------------------Plot of matrix-pattern---------------------------\nc----------------------------------------------------------------------- \n size = 5.5\n mode = 0\n title = 'Assembled Matrix'\n ptitle = 1\n ncol = 0\n iout = 12\n call pspltm(n,n,mode,ja,ia,title,ptitle,size,munt,ncol,iwk,12) \nc xleft = 0.00 \nc bot = 0.70 \nc job = 0\nc call texplt(nx,nx,mode,ja,ia,munt,size,vsize,hsize,xleft,bot,\nc * job,title,ptitle,ncol,iwk,12) \n stop\nc-----end-of-program-convdif--------------------------------------------\nc-----------------------------------------------------------------------\n end\nc-----------------------------------------------------------------------\n", "meta": {"hexsha": "b50c2d1d7c37195a4c5e21729d354afd19282e8b", "size": 5311, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "external/sparsekit/MATGEN/FEM/convdif.f", "max_stars_repo_name": "utastudents/selalib", "max_stars_repo_head_hexsha": "84af43d0e82d4686a837c64384bbd173412df50e", "max_stars_repo_licenses": ["CECILL-B"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-03-11T15:22:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-22T16:26:18.000Z", "max_issues_repo_path": "external/sparsekit/MATGEN/FEM/convdif.f", "max_issues_repo_name": "utastudents/selalib", "max_issues_repo_head_hexsha": "84af43d0e82d4686a837c64384bbd173412df50e", "max_issues_repo_licenses": ["CECILL-B"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2021-06-30T20:39:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-15T12:42:50.000Z", "max_forks_repo_path": "external/sparsekit/MATGEN/FEM/convdif.f", "max_forks_repo_name": "utastudents/selalib", "max_forks_repo_head_hexsha": "84af43d0e82d4686a837c64384bbd173412df50e", "max_forks_repo_licenses": ["CECILL-B"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-03-13T17:09:10.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-22T00:30:19.000Z", "avg_line_length": 40.2348484848, "max_line_length": 73, "alphanum_fraction": 0.445302203, "num_tokens": 1414, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.752012562644147, "lm_q1q2_score": 0.6706531139988828}} {"text": "program main\n\n!*****************************************************************************80\n!\n!! MAIN is the main program for MD.\n!\n! Discussion:\n!\n! MD implements a simple molecular dynamics simulation.\n!\n! The velocity Verlet time integration scheme is used. \n!\n! The particles interact with a central pair potential.\n!\n! Based on a FORTRAN90 program by Bill Magro.\n!\n! Usage:\n!\n! md nd np step_num dt\n!\n! where\n!\n! * nd is the spatial dimension (2 or 3);\n! * np is the number of particles (500, for instance);\n! * step_num is the number of time steps (500, for instance).\n! * dt is the time step (0.1 for instance )\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 26 December 2014\n!\n! Author:\n!\n! John Burkardt\n!\n implicit none\n\n real ( kind = 8 ), allocatable :: acc(:,:)\n integer ( kind = 4 ) arg_num\n real ( kind = 8 ) ctime\n real ( kind = 8 ) ctime1\n real ( kind = 8 ) ctime2\n real ( kind = 8 ) dt\n real ( kind = 8 ) e0\n real ( kind = 8 ), allocatable :: force(:,:)\n integer ( kind = 4 ) iarg\n integer ( kind = 4 ) id\n integer ( kind = 4 ) ierror\n real ( kind = 8 ) kinetic\n integer ( kind = 4 ) last\n real ( kind = 8 ), parameter :: mass = 1.0D+00\n integer ( kind = 4 ) nd\n integer ( kind = 4 ) np\n real ( kind = 8 ), allocatable :: pos(:,:)\n real ( kind = 8 ) potential\n real ( kind = 8 ) rel\n integer ( kind = 4 ) step\n integer ( kind = 4 ) step_num\n integer ( kind = 4 ) step_print\n integer ( kind = 4 ) step_print_index\n integer ( kind = 4 ) step_print_num\n character ( len = 255 ) string\n real ( kind = 8 ), allocatable :: vel(:,:)\n real ( kind = 8 ) wtime\n\n call timestamp ( )\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'MD'\n write ( *, '(a)' ) ' FORTRAN90 version'\n write ( *, '(a)' ) ' A molecular dynamics program.'\n!\n! Get the number of command line arguments.\n!\n arg_num = iargc ( )\n!\n! Get ND, the number of spatial dimensions.\n!\n if ( 1 <= arg_num ) then\n iarg = 1\n call getarg ( iarg, string )\n call s_to_i4 ( string, nd, ierror, last )\n else\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' Enter ND, the spatial dimension (2 or 3 ):'\n read ( *, * ) nd\n end if\n!\n! Get NP, the number of particles.\n!\n if ( 2 <= arg_num ) then\n iarg = 2\n call getarg ( iarg, string )\n call s_to_i4 ( string, np, ierror, last )\n else\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) &\n ' Enter NP, the number of particles (500, for instance):'\n read ( *, * ) np\n end if\n!\n! Get STEP_NUM, the number of time steps.\n!\n if ( 3 <= arg_num ) then\n iarg = 3\n call getarg ( iarg, string )\n call s_to_i4 ( string, step_num, ierror, last )\n else\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) &\n ' Enter STEP_NUM, the number of time steps (500, for instance):'\n read ( *, * ) step_num\n end if\n!\n! Get DT, the time step.\n!\n if ( 4 <= arg_num ) then\n iarg = 4\n call getarg ( iarg, string )\n call s_to_r8 ( string, dt )\n else\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) &\n ' Enter DT, the time step size (0.1, for instance):'\n read ( *, * ) dt\n end if\n!\n! Report.\n!\n write ( *, '(a)' ) ' '\n write ( *, '(a,i8)' ) ' ND, the spatial dimension, is ', nd\n write ( *, '(a,i8)' ) &\n ' NP, the number of particles in the simulation is ', np\n write ( *, '(a,i8)' ) ' STEP_NUM, the number of time steps, is ', step_num\n write ( *, '(a,g14.6)' ) ' DT, the size of each time step, is ', dt\n!\n! Allocate memory.\n!\n allocate ( acc(nd,np) )\n allocate ( force(nd,np) )\n allocate ( pos(nd,np) )\n allocate ( vel(nd,np) )\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) &\n ' At each step, we report the potential and kinetic energies.'\n write ( *, '(a)' ) ' The sum of these energies should be a constant.'\n write ( *, '(a)' ) ' As an accuracy check, we also print the relative error'\n write ( *, '(a)' ) ' in the total energy.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) &\n ' Step Potential Kinetic (P+K-E0)/E0'\n write ( *, '(a)' ) &\n ' Energy P Energy K Relative Energy Error'\n write ( *, '(a)' ) ' '\n!\n! This is the main time stepping loop:\n! Initialize or update positions, velocities, accelerations.\n! Compute forces and energies,\n!\n step_print = 0\n step_print_index = 0\n step_print_num = 10\n\n call cpu_time ( ctime1 )\n\n do step = 0, step_num\n\n if ( step == 0 ) then\n call initialize ( np, nd, pos, vel, acc )\n else\n call update ( np, nd, pos, vel, force, acc, mass, dt )\n end if\n\n call compute ( np, nd, pos, vel, mass, force, potential, kinetic )\n\n if ( step == 0 ) then\n e0 = potential + kinetic\n end if\n\n if ( step == step_print ) then\n rel = ( potential + kinetic - e0 ) / e0\n write ( *, '(2x,i8,2x,g14.6,2x,g14.6,2x,g14.6)' ) &\n step, potential, kinetic, rel \n step_print_index = step_print_index + 1\n step_print = ( step_print_index * step_num ) / step_print_num\n end if\n\n end do\n!\n! Report time.\n!\n call cpu_time ( ctime2 )\n ctime = ctime2 - ctime1\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' Elapsed cpu time for main computation:'\n write ( *, '(2x,g14.6,a)' ) ctime, ' seconds'\n!\n! Free memory.\n!\n deallocate ( acc )\n deallocate ( force )\n deallocate ( pos )\n deallocate ( vel )\n!\n! Terminate.\n!\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'MD:'\n write ( *, '(a)' ) ' Normal end of execution.'\n write ( *, '(a)' ) ' '\n call timestamp ( )\n\n stop\nend\nsubroutine compute ( np, nd, pos, vel, mass, f, pot, kin )\n\n!*****************************************************************************80\n!\n!! COMPUTE computes the forces and energies.\n!\n! Discussion:\n!\n! The computation of forces and energies is fully parallel.\n!\n! The potential function V(X) is a harmonic well which smoothly\n! saturates to a maximum value at PI/2:\n!\n! v(x) = ( sin ( min ( x, PI/2 ) ) )^2\n!\n! The derivative of the potential is:\n!\n! dv(x) = 2.0D+00 * sin ( min ( x, PI/2 ) ) * cos ( min ( x, PI/2 ) )\n! = sin ( 2.0 * min ( x, PI/2 ) )\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 15 July 2008\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) NP, the number of particles.\n!\n! Input, integer ( kind = 4 ) ND, the number of spatial dimensions.\n!\n! Input, real ( kind = 8 ) POS(ND,NP), the positions.\n!\n! Input, real ( kind = 8 ) VEL(ND,NP), the velocities.\n!\n! Input, real ( kind = 8 ) MASS, the mass.\n!\n! Output, real ( kind = 8 ) F(ND,NP), the forces.\n!\n! Output, real ( kind = 8 ) POT, the total potential energy.\n!\n! Output, real ( kind = 8 ) KIN, the total kinetic energy.\n!\n implicit none\n\n integer ( kind = 4 ) np\n integer ( kind = 4 ) nd\n\n real ( kind = 8 ) d\n real ( kind = 8 ) d2\n real ( kind = 8 ) f(nd,np)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) j\n real ( kind = 8 ) kin\n real ( kind = 8 ) mass\n real ( kind = 8 ), parameter :: PI2 = 3.141592653589793D+00 / 2.0D+00\n real ( kind = 8 ) pos(nd,np)\n real ( kind = 8 ) pot\n real ( kind = 8 ) rij(nd)\n real ( kind = 8 ) vel(nd,np)\n\n pot = 0.0D+00\n\n do i = 1, np\n!\n! Compute the potential energy and forces.\n!\n f(1:nd,i) = 0.0D+00\n\n do j = 1, np\n\n if ( i /= j ) then\n\n rij(1:nd) = pos(1:nd,i) - pos(1:nd,j)\n\n d = sqrt ( sum ( rij(1:nd)**2 ) )\n!\n! Truncate the distance.\n!\n d2 = min ( d, PI2 )\n!\n! Attribute half of the total potential energy to particle J.\n!\n pot = pot + 0.5D+00 * sin ( d2 ) * sin ( d2 )\n!\n! Add particle J's contribution to the force on particle I.\n!\n f(1:nd,i) = f(1:nd,i) - rij(1:nd) * sin ( 2.0D+00 * d2 ) / d\n\n end if\n\n end do\n\n end do\n!\n! Compute the total kinetic energy.\n!\n kin = 0.5D+00 * mass * sum ( vel(1:nd,1:np)**2 )\n \n return\nend\nsubroutine initialize ( np, nd, pos, vel, acc )\n\n!*****************************************************************************80\n!\n!! INITIALIZE initializes the positions, velocities, and accelerations.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 26 December 2014\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) NP, the number of particles.\n!\n! Input, integer ( kind = 4 ) ND, the number of spatial dimensions.\n!\n! Output, real ( kind = 8 ) POS(ND,NP), the positions.\n!\n! Output, real ( kind = 8 ) VEL(ND,NP), the velocities.\n!\n! Output, real ( kind = 8 ) ACC(ND,NP), the accelerations.\n!\n implicit none\n\n integer ( kind = 4 ) np\n integer ( kind = 4 ) nd\n\n real ( kind = 8 ) acc(nd,np)\n real ( kind = 8 ) pos(nd,np)\n integer ( kind = 4 ) seed\n real ( kind = 8 ) vel(nd,np)\n!\n! Set the positions.\n!\n seed = 123456789\n call r8mat_uniform_ab ( nd, np, 0.0D+00, 10.0D+00, seed, pos )\n!\n! Set the velocities.\n!\n vel(1:nd,1:np) = 0.0D+00\n!\n! Set the accelerations.\n!\n acc(1:nd,1:np) = 0.0D+00\n\n return\nend\nsubroutine r8mat_uniform_ab ( m, n, a, b, seed, r )\n\n!*****************************************************************************80\n!\n!! R8MAT_UNIFORM_AB returns a scaled pseudorandom R8MAT.\n!\n! Discussion:\n!\n! A <= R(I,J) <= B.\n!\n! An R8MAT is an array of R8's.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license. \n!\n! Modified:\n!\n! 31 May 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! Paul Bratley, Bennett Fox, Linus Schrage,\n! A Guide to Simulation,\n! Second Edition,\n! Springer, 1987,\n! ISBN: 0387964673,\n! LC: QA76.9.C65.B73.\n!\n! Bennett Fox,\n! Algorithm 647:\n! Implementation and Relative Efficiency of Quasirandom\n! Sequence Generators,\n! ACM Transactions on Mathematical Software,\n! Volume 12, Number 4, December 1986, pages 362-376.\n!\n! Pierre L'Ecuyer,\n! Random Number Generation,\n! in Handbook of Simulation,\n! edited by Jerry Banks,\n! Wiley, 1998,\n! ISBN: 0471134031,\n! LC: T57.62.H37.\n!\n! Peter Lewis, Allen Goodman, James Miller,\n! A Pseudo-Random Number Generator for the System/360,\n! IBM Systems Journal,\n! Volume 8, Number 2, 1969, pages 136-143.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, N, the number of rows and columns\n! in the array.\n!\n! Input, real ( kind = 8 ) A, B, the lower and upper limits.\n!\n! Input/output, integer ( kind = 4 ) SEED, the \"seed\" value, which \n! should NOT be 0. On output, SEED has been updated.\n!\n! Output, real ( kind = 8 ) R(M,N), the array of pseudorandom values.\n!\n implicit none\n\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n integer ( kind = 4 ) i\n integer ( kind = 4 ), parameter :: i4_huge = 2147483647\n integer ( kind = 4 ) j\n integer ( kind = 4 ) k\n integer ( kind = 4 ) seed\n real ( kind = 8 ) r(m,n)\n\n if ( seed == 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R8MAT_UNIFORM_AB - Fatal error!'\n write ( *, '(a)' ) ' Input value of SEED = 0.'\n stop 1\n end if\n\n do j = 1, n\n\n do i = 1, m\n\n k = seed / 127773\n\n seed = 16807 * ( seed - k * 127773 ) - k * 2836\n\n if ( seed < 0 ) then\n seed = seed + i4_huge\n end if\n\n r(i,j) = a + ( b - a ) * real ( seed, kind = 8 ) * 4.656612875D-10\n\n end do\n end do\n\n return\nend\nsubroutine s_to_i4 ( s, value, ierror, length )\n\n!*****************************************************************************80\n!\n!! S_TO_I4 reads an integer value from a string.\n!\n! Discussion:\n!\n! Instead of ICHAR, we now use the IACHAR function, which\n! guarantees the ASCII collating sequence.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license. \n!\n! Modified:\n!\n! 12 January 2009\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, character ( len = * ) S, a string to be examined.\n!\n! Output, integer ( kind = 4 ) VALUE, the integer value read from the string.\n! If the string is blank, then VALUE will be returned 0.\n!\n! Output, integer ( kind = 4 ) IERROR, an error flag.\n! 0, no error.\n! 1, an error occurred.\n!\n! Output, integer ( kind = 4 ) LENGTH, the number of characters \n! of S used to make the integer.\n!\n implicit none\n\n character c\n integer ( kind = 4 ) i\n integer ( kind = 4 ) ierror\n integer ( kind = 4 ) isgn\n integer ( kind = 4 ) length\n character ( len = * ) s\n integer ( kind = 4 ) state\n character :: TAB = achar ( 9 )\n integer ( kind = 4 ) value\n\n value = 0\n ierror = 0\n length = 0\n\n state = 0\n isgn = 1\n\n do i = 1, len_trim ( s )\n\n c = s(i:i)\n!\n! STATE = 0, haven't read anything.\n!\n if ( state == 0 ) then\n\n if ( c == ' ' .or. c == TAB ) then\n\n else if ( c == '-' ) then\n state = 1\n isgn = -1\n else if ( c == '+' ) then\n state = 1\n isgn = +1\n else if ( lle ( '0', c ) .and. lle ( c, '9' ) ) then\n state = 2\n value = iachar ( c ) - iachar ( '0' )\n else\n ierror = 1\n return\n end if\n!\n! STATE = 1, have read the sign, expecting digits or spaces.\n!\n else if ( state == 1 ) then\n\n if ( c == ' ' .or. c == TAB ) then\n\n else if ( lle ( '0', c ) .and. lle ( c, '9' ) ) then\n state = 2\n value = iachar ( c ) - iachar ( '0' )\n else\n ierror = 1\n return\n end if\n!\n! STATE = 2, have read at least one digit, expecting more.\n!\n else if ( state == 2 ) then\n\n if ( lle ( '0', c ) .and. lle ( c, '9' ) ) then\n\n value = 10 * value + iachar ( c ) - iachar ( '0' )\n\n else\n\n value = isgn * value\n ierror = 0\n length = i - 1\n return\n\n end if\n\n end if\n\n end do\n!\n! If we read all the characters in the string, see if we're OK.\n!\n if ( state == 2 ) then\n\n value = isgn * value\n ierror = 0\n length = len_trim ( s )\n\n else\n\n value = 0\n ierror = 1\n length = 0\n\n end if\n\n return\nend\nsubroutine s_to_r8 ( s, r8 )\n\n!*****************************************************************************80\n!\n!! S_TO_R8 reads an R8 value from a string.\n!\n! Discussion:\n!\n! An \"R8\" value is simply a real number to be stored as a\n! variable of type \"real ( kind = 8 )\".\n!\n! The routine will read as many characters as possible until it reaches\n! the end of the string, or encounters a character which cannot be\n! part of the number.\n!\n! Legal input is:\n!\n! 1 blanks,\n! 2 '+' or '-' sign,\n! 2.5 blanks\n! 3 integer part,\n! 4 decimal point,\n! 5 fraction part,\n! 6 'E' or 'e' or 'D' or 'd', exponent marker,\n! 7 exponent sign,\n! 8 exponent integer part,\n! 9 exponent decimal point,\n! 10 exponent fraction part,\n! 11 blanks,\n! 12 final comma or semicolon,\n!\n! with most quantities optional.\n!\n! Example:\n!\n! S R8\n!\n! '1' 1.0\n! ' 1 ' 1.0\n! '1A' 1.0\n! '12,34,56' 12.0\n! ' 34 7' 34.0\n! '-1E2ABCD' -100.0\n! '-1X2ABCD' -1.0\n! ' 2E-1' 0.2\n! '23.45' 23.45\n! '-4.2E+2' -420.0\n! '17d2' 1700.0\n! '-14e-2' -0.14\n! 'e2' 100.0\n! '-12.73e-9.23' -12.73 * 10.0^(-9.23)\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 06 January 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, character ( len = * ) S, the string containing the\n! data to be read. Reading will begin at position 1 and\n! terminate at the end of the string, or when no more\n! characters can be read to form a legal real. Blanks,\n! commas, or other nonnumeric data will, in particular,\n! cause the conversion to halt.\n!\n! Output, real ( kind = 8 ) R8, the value read from the string.\n!\n implicit none\n\n character c\n integer ( kind = 4 ) ierror\n integer ( kind = 4 ) ihave\n integer ( kind = 4 ) isgn\n integer ( kind = 4 ) iterm\n integer ( kind = 4 ) jbot\n integer ( kind = 4 ) jsgn\n integer ( kind = 4 ) jtop\n integer ( kind = 4 ) length\n integer ( kind = 4 ) ndig\n real ( kind = 8 ) r8\n real ( kind = 8 ) rbot\n real ( kind = 8 ) rexp\n real ( kind = 8 ) rtop\n character ( len = * ) s\n integer ( kind = 4 ) s_length\n character :: TAB = achar ( 9 )\n\n s_length = len_trim ( s )\n\n ierror = 0\n r8 = 0.0D+00\n length = -1\n isgn = 1\n rtop = 0\n rbot = 1\n jsgn = 1\n jtop = 0\n jbot = 1\n ihave = 1\n iterm = 0\n\n do\n\n length = length + 1\n\n if ( s_length < length + 1 ) then\n exit\n end if\n\n c = s(length+1:length+1)\n!\n! Blank character.\n!\n if ( c == ' ' .or. c == TAB ) then\n\n if ( ihave == 2 ) then\n\n else if ( ihave == 6 .or. ihave == 7 ) then\n iterm = 1\n else if ( 1 < ihave ) then\n ihave = 11\n end if\n!\n! Comma.\n!\n else if ( c == ',' .or. c == ';' ) then\n\n if ( ihave /= 1 ) then\n iterm = 1\n ihave = 12\n length = length + 1\n end if\n!\n! Minus sign.\n!\n else if ( c == '-' ) then\n\n if ( ihave == 1 ) then\n ihave = 2\n isgn = -1\n else if ( ihave == 6 ) then\n ihave = 7\n jsgn = -1\n else\n iterm = 1\n end if\n!\n! Plus sign.\n!\n else if ( c == '+' ) then\n\n if ( ihave == 1 ) then\n ihave = 2\n else if ( ihave == 6 ) then\n ihave = 7\n else\n iterm = 1\n end if\n!\n! Decimal point.\n!\n else if ( c == '.' ) then\n\n if ( ihave < 4 ) then\n ihave = 4\n else if ( 6 <= ihave .and. ihave <= 8 ) then\n ihave = 9\n else\n iterm = 1\n end if\n!\n! Scientific notation exponent marker.\n!\n else if ( c == 'E' .or. c == 'e' .or. c == 'D' .or. c == 'd' ) then\n\n if ( ihave < 6 ) then\n ihave = 6\n else\n iterm = 1\n end if\n!\n! Digit.\n!\n else if ( ihave < 11 .and. lle ( '0', c ) .and. lle ( c, '9' ) ) then\n\n if ( ihave <= 2 ) then\n ihave = 3\n else if ( ihave == 4 ) then\n ihave = 5\n else if ( ihave == 6 .or. ihave == 7 ) then\n ihave = 8\n else if ( ihave == 9 ) then\n ihave = 10\n end if\n\n ndig = iachar ( c ) - 48\n\n if ( ihave == 3 ) then\n rtop = 10.0D+00 * rtop + real ( ndig, kind = 8 )\n else if ( ihave == 5 ) then\n rtop = 10.0D+00 * rtop + real ( ndig, kind = 8 )\n rbot = 10.0D+00 * rbot\n else if ( ihave == 8 ) then\n jtop = 10 * jtop + ndig\n else if ( ihave == 10 ) then\n jtop = 10 * jtop + ndig\n jbot = 10 * jbot\n end if\n!\n! Anything else is regarded as a terminator.\n!\n else\n iterm = 1\n end if\n!\n! If we haven't seen a terminator, and we haven't examined the\n! entire string, go get the next character.\n!\n if ( iterm == 1 ) then\n exit\n end if\n\n end do\n!\n! If we haven't seen a terminator, and we have examined the\n! entire string, then we're done, and LENGTH is equal to S_LENGTH.\n!\n if ( iterm /= 1 .and. length + 1 == s_length ) then\n length = s_length\n end if\n!\n! Number seems to have terminated. Have we got a legal number?\n! Not if we terminated in states 1, 2, 6 or 7!\n!\n if ( ihave == 1 .or. ihave == 2 .or. ihave == 6 .or. ihave == 7 ) then\n ierror = ihave\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'S_TO_R8 - Serious error!'\n write ( *, '(a)' ) ' Illegal or nonnumeric input:'\n write ( *, '(a)' ) ' \"' // trim ( s ) // '\"'\n stop 1\n end if\n!\n! Number seems OK. Form it.\n!\n if ( jtop == 0 ) then\n rexp = 1.0D+00\n else\n if ( jbot == 1 ) then\n rexp = 10.0D+00 ** ( jsgn * jtop )\n else\n rexp = 10.0D+00 ** ( real ( jsgn * jtop, kind = 8 ) &\n / real ( jbot, kind = 8 ) )\n end if\n end if\n\n r8 = real ( isgn, kind = 8 ) * rexp * rtop / rbot\n\n return\nend\nsubroutine timestamp ( )\n\n!*****************************************************************************80\n!\n!! TIMESTAMP prints the current YMDHMS date as a time stamp.\n!\n! Example:\n!\n! 31 May 2001 9:45:54.872 AM\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 18 May 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! None\n!\n implicit none\n\n character ( len = 8 ) ampm\n integer ( kind = 4 ) d\n integer ( kind = 4 ) h\n integer ( kind = 4 ) m\n integer ( kind = 4 ) mm\n character ( len = 9 ), parameter, dimension(12) :: month = (/ &\n 'January ', 'February ', 'March ', 'April ', &\n 'May ', 'June ', 'July ', 'August ', &\n 'September', 'October ', 'November ', 'December ' /)\n integer ( kind = 4 ) n\n integer ( kind = 4 ) s\n integer ( kind = 4 ) values(8)\n integer ( kind = 4 ) y\n\n call date_and_time ( values = values )\n\n y = values(1)\n m = values(2)\n d = values(3)\n h = values(5)\n n = values(6)\n s = values(7)\n mm = values(8)\n\n if ( h < 12 ) then\n ampm = 'AM'\n else if ( h == 12 ) then\n if ( n == 0 .and. s == 0 ) then\n ampm = 'Noon'\n else\n ampm = 'PM'\n end if\n else\n h = h - 12\n if ( h < 12 ) then\n ampm = 'PM'\n else if ( h == 12 ) then\n if ( n == 0 .and. s == 0 ) then\n ampm = 'Midnight'\n else\n ampm = 'AM'\n end if\n end if\n end if\n\n write ( *, '(i2,1x,a,1x,i4,2x,i2,a1,i2.2,a1,i2.2,a1,i3.3,1x,a)' ) &\n d, trim ( month(m) ), y, h, ':', n, ':', s, '.', mm, trim ( ampm )\n\n return\nend\nsubroutine update ( np, nd, pos, vel, f, acc, mass, dt )\n\n!*****************************************************************************80\n!\n!! UPDATE updates positions, velocities and accelerations.\n!\n! Discussion:\n!\n! The time integration is fully parallel.\n!\n! A velocity Verlet algorithm is used for the updating.\n!\n! x(t+dt) = x(t) + v(t) * dt + 0.5 * a(t) * dt * dt\n! v(t+dt) = v(t) + 0.5 * ( a(t) + a(t+dt) ) * dt\n! a(t+dt) = f(t) / m\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 November 2007\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) NP, the number of particles.\n!\n! Input, integer ( kind = 4 ) ND, the number of spatial dimensions.\n!\n! Input/output, real ( kind = 8 ) POS(ND,NP), the positions.\n!\n! Input/output, real ( kind = 8 ) VEL(ND,NP), the velocities.\n!\n! Input, real ( kind = 8 ) F(ND,NP), the forces.\n!\n! Input/output, real ( kind = 8 ) ACC(ND,NP), the accelerations.\n!\n! Input, real ( kind = 8 ) MASS, the mass of each particle.\n!\n! Input, real ( kind = 8 ) DT, the time step.\n!\n implicit none\n\n integer ( kind = 4 ) np\n integer ( kind = 4 ) nd\n\n real ( kind = 8 ) acc(nd,np)\n real ( kind = 8 ) dt\n real ( kind = 8 ) f(nd,np)\n integer ( kind = 4 ) i\n integer ( kind = 4 ) j\n real ( kind = 8 ) mass\n real ( kind = 8 ) pos(nd,np)\n real ( kind = 8 ) rmass\n real ( kind = 8 ) vel(nd,np)\n\n rmass = 1.0D+00 / mass\n\n do j = 1, np\n do i = 1, nd\n pos(i,j) = pos(i,j) + vel(i,j) * dt + 0.5D+00 * acc(i,j) * dt * dt\n vel(i,j) = vel(i,j) + 0.5D+00 * dt * ( f(i,j) * rmass + acc(i,j) )\n acc(i,j) = f(i,j) * rmass\n end do\n end do\n\n return\nend\n", "meta": {"hexsha": "cf36d0c2b53d3047a18a3bdd1bb184749d1c9580", "size": 23152, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "code/profiling/md.f90", "max_stars_repo_name": "rmdickson/ACENET_Summer_School_General", "max_stars_repo_head_hexsha": "1db306959d1e84ce503eafd922d6ab5a0e170d66", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-06-07T15:58:40.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-07T15:58:40.000Z", "max_issues_repo_path": "code/profiling/md.f90", "max_issues_repo_name": "rmdickson/ACENET_Summer_School_General", "max_issues_repo_head_hexsha": "1db306959d1e84ce503eafd922d6ab5a0e170d66", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-06-07T14:37:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-07T14:37:50.000Z", "max_forks_repo_path": "code/profiling/md.f90", "max_forks_repo_name": "rmdickson/ACENET_Summer_School_General", "max_forks_repo_head_hexsha": "1db306959d1e84ce503eafd922d6ab5a0e170d66", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-05-10T15:31:11.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-12T19:24:11.000Z", "avg_line_length": 22.2615384615, "max_line_length": 80, "alphanum_fraction": 0.5222442985, "num_tokens": 7930, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.868826769445233, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6705982973046277}} {"text": "module combinations_module\n use iso_fortran_env\nimplicit none\ncontains\n!\n!----------------------------------\n!combinations - function:\n!----------------------------------\n!\ninteger function combination_x_of_p(x,p)\nimplicit none\n!\ninteger(kind=int64), intent(in) :: x, p\ninteger(kind=int64) :: diff, prod, x_fact, p_x_fact, i\n!\ndiff = p - x\nwrite(*,*) 'x', x, 'p', p\nwrite(*,*) 'diff', diff\n!\n!--------------------\n! p-x > x :\n!--------------------\n!\nif (diff .ge. x) then\n write(*,*) 'p - x > x'\n prod = 1\n do i = 1, x\n prod = prod * (diff + i)\n write(*,*) 'prod', prod\n end do\n !\n if (x .ne. 0) then\n x_fact = 1\n do i = 1, x\n x_fact = x_fact * i\n end do\n end if\n if (x .eq. 0) then\n x_fact = 1\n end if\n !\n write(*,*) 'prod', prod\n write(*,*) 'x_fact', x_fact\n combination_x_of_p = prod/x_fact\n write(*,*) 'combination x of p', combination_x_of_p\n!\n!--------------------------\n! p-x < x :\n!--------------------------\n!\nelse if (diff .lt. x) then\n write(*,*) 'x > p - x'\n prod = 1\n do i = 1, diff\n prod = prod * (x+i)\n end do\n !\n p_x_fact = 1\n do i = 1, p - x\n p_x_fact = p_x_fact * i\n end do\n !\n combination_x_of_p = prod/p_x_fact\nend if\n!\n!-----------------------------------------------------------------\n! example -> x .lt. p-x\n!-----------------------------------------------------------------\n!\n! p = 8\n! x = 2\n! p - x = 6\n!\n! x < p-x\n!\n! 6! 7 8 p-x+1 p-x+2\n! -------------- = --------------------\n! 6! 2! x! \n!\n!-----------------------------------------------------------------\n! example -> x .gt. p=x\n!-----------------------------------------------------------------\n!\n! p = 8\n! x = 5\n! p - x = 3\n!\n! 5! 6 7 8 x+1 x+2 x+3\n! ------------ = ------------------\n! 5! 3! p - x!\n! \nend function combination_x_of_p\n\n\nend module combinations_module\n", "meta": {"hexsha": "996bfde21d0f0344019586a8ba93de60dbb7fc3b", "size": 1932, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "find_kth_combination/generate_just_k_of_m_mod.f95", "max_stars_repo_name": "ElenaKusevska/coordinates_on_a_grid", "max_stars_repo_head_hexsha": "6605c76d9c6561fee6eaaa844fb954f7784f623c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "find_kth_combination/generate_just_k_of_m_mod.f95", "max_issues_repo_name": "ElenaKusevska/coordinates_on_a_grid", "max_issues_repo_head_hexsha": "6605c76d9c6561fee6eaaa844fb954f7784f623c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "find_kth_combination/generate_just_k_of_m_mod.f95", "max_forks_repo_name": "ElenaKusevska/coordinates_on_a_grid", "max_forks_repo_head_hexsha": "6605c76d9c6561fee6eaaa844fb954f7784f623c", "max_forks_repo_licenses": ["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.125, "max_line_length": 66, "alphanum_fraction": 0.3638716356, "num_tokens": 601, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898203834277, "lm_q2_score": 0.7401743735019595, "lm_q1q2_score": 0.6705904477014564}} {"text": "! This source file is part of the Limited-area GAME version (L-GAME), which is released under the MIT license.\n! Github repository: https://github.com/OpenNWP/L-GAME\n\nmodule divergence_operators\n\n use definitions, only: wp,t_grid\n use run_nml, only: nlins,ncols,nlays,nlays_oro\n use averaging, only: vertical_contravariant_corr\n \n implicit none\n \n private\n \n public :: divv_h\n \n contains\n\n subroutine divv_h(vector_field_x,vector_field_y,result_field,grid)\n\n ! This subroutine computes the gradient of a scalar field.\n real(wp), intent(in) :: vector_field_x(:,:,:) ! x-component of horizontal vector field of which to calculate the divergence\n real(wp), intent(in) :: vector_field_y(:,:,:) ! y-component of horizontal vector field of which to calculate the divergence\n real(wp), intent(inout) :: result_field(:,:,:) ! resulting scalar field\n type(t_grid), intent(in) :: grid ! the grid properties\n ! local variables\n integer :: ji,jk,jl ! loop variables\n real(wp) :: comp_h ! horizontal component of divergence\n real(wp) :: comp_v ! horizontal component of divergence\n real(wp) :: contra_upper ! contravariant mass flux density resulting \n ! from the horizontal vector components through the upper area\n real(wp) :: contra_lower ! contravariant mass flux density resulting\n ! from the horizontal vector components through the lower area\n\n ! performing the actual calculation\n !$OMP PARALLEL\n !$OMP DO PRIVATE(ji,jk,jl,comp_h,comp_v)\n do ji=1,nlins\n do jk=1,ncols\n do jl=1,nlays\n ! the horizontal component\n comp_h = &\n vector_field_x(ji+1,jk+1,jl)*grid%area_x(ji ,jk+1,jl) &\n + vector_field_y(ji+1,jk+1,jl)*grid%area_y(ji+1,jk ,jl) &\n - vector_field_x(ji+1,jk ,jl)*grid%area_x(ji ,jk ,jl) &\n - vector_field_y(ji ,jk+1,jl)*grid%area_y(ji ,jk ,jl)\n \n ! the vertical component\n comp_v = 0._wp\n if (jl == nlays - nlays_oro) then\n contra_lower = vertical_contravariant_corr(vector_field_x,vector_field_y,ji,jk,jl+1,grid)\n comp_v = -contra_lower*grid%area_z(ji,jk,jl+1)\n elseif (jl == nlays) then\n contra_upper = vertical_contravariant_corr(vector_field_x,vector_field_y,ji,jk,jl , grid)\n comp_v = contra_upper*grid%area_z(ji,jk,jl )\n elseif (jl > nlays - nlays_oro - 1) then\n contra_upper = vertical_contravariant_corr(vector_field_x,vector_field_y,ji,jk,jl ,grid)\n contra_lower = vertical_contravariant_corr(vector_field_x,vector_field_y,ji,jk,jl+1,grid)\n comp_v &\n = contra_upper*grid%area_z(ji,jk,jl ) &\n - contra_lower*grid%area_z(ji,jk,jl+1)\n endif\n \n ! adding the horizontal and the vertical component and dividing by the volume\n result_field(ji,jk,jl) = (comp_h + comp_v)/grid%volume(ji,jk,jl)\n enddo\n enddo\n enddo\n !$OMP END DO\n !$OMP END PARALLEL\n\n end subroutine divv_h\n\nend module divergence_operators\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "4f74cb6e3e30fa2728362090ac759631fec7506b", "size": 3379, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/spatial_operators/divergence_operators.f90", "max_stars_repo_name": "OpenNWP/L-GAME", "max_stars_repo_head_hexsha": "4017f3d8d25e10e1b5f3f38664238ad208ba486c", "max_stars_repo_licenses": ["MIT"], "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/spatial_operators/divergence_operators.f90", "max_issues_repo_name": "OpenNWP/L-GAME", "max_issues_repo_head_hexsha": "4017f3d8d25e10e1b5f3f38664238ad208ba486c", "max_issues_repo_licenses": ["MIT"], "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/spatial_operators/divergence_operators.f90", "max_forks_repo_name": "OpenNWP/L-GAME", "max_forks_repo_head_hexsha": "4017f3d8d25e10e1b5f3f38664238ad208ba486c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.2261904762, "max_line_length": 134, "alphanum_fraction": 0.6028410772, "num_tokens": 854, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898153067649, "lm_q2_score": 0.7401743735019595, "lm_q1q2_score": 0.6705904439438407}} {"text": "!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 2005 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Fishpack *\n! * *\n! * A Package of Fortran *\n! * *\n! * Subroutines and Example Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams, Paul Swarztrauber and Roland Sweet *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\n!\nprogram test_cblktri\n\n use, intrinsic :: ISO_Fortran_env, only: &\n stdout => OUTPUT_UNIT\n\n use fishpack\n\n ! Explicit typing only\n implicit none\n\n ! Dictionary\n type(FishpackWorkspace) :: workspace\n integer(ip), parameter :: N = 63, M = 50\n integer(ip), parameter :: IDIMY = 75, NT = 105\n integer(ip) :: iflg, np, mp, i, j, ierror\n real(wp), dimension(NT) :: an, bn, cn, t\n real(wp), dimension(IDIMY) :: s\n real(wp) :: ds, dt\n real(wp), parameter :: ZERO = 0.0_wp, ONE = 1.0_wp, TWO = 2.0_wp\n complex(wp) :: y(IDIMY,NT)\n complex(wp), dimension(IDIMY) :: am, bm, cm\n complex(wp), parameter :: IMAGINARY_UNIT = cmplx(ZERO, ONE, kind=wp)\n\n ! Set boundary conditions\n np = 1\n mp = 1\n\n ! Set mesh sizes\n ds = ONE/(M + 1)\n dt = ONE/(N + 1)\n\n ! Generate and store grid points for the purpose of computing the\n ! coefficients and the array y.\n do i = 1, M\n s(i) = real(i, kind=wp) * ds\n end do\n\n do j = 1, N\n t(j) = real(j, kind=wp) * dt\n end do\n\n ! Compute the coefficients am, bm, cm corresponding to the s direction\n block\n real(wp) :: half_ds, two_ds\n real(wp) :: temp1, temp2, temp3\n\n half_ds = ds/2\n two_ds = TWO * ds\n\n do i = 1, M\n temp1 = ONE /(s(i)*two_ds)\n temp2 = ONE /((s(i)-half_ds) * two_ds)\n temp3 = ONE /((s(i)+half_ds) * two_ds)\n am(i) = cmplx(temp1*temp2, ZERO, kind=wp)\n cm(i) = cmplx(temp1*temp3, ZERO, kind=wp)\n bm(i) = (-(am(i)+cm(i))) - IMAGINARY_UNIT\n end do\n end block\n\n ! Compute the coefficients an, bn, cn corresponding to the t direction\n block\n real(wp) :: half_dt, two_dt\n real(wp) :: temp1, temp2, temp3\n\n half_dt = dt/2\n two_dt = TWO * dt\n\n do j = 1, N\n temp1 = ONE/(t(j) * two_dt)\n temp2 = ONE/((t(j) - half_dt) * two_dt)\n temp3 = ONE/((t(j) + half_dt) * two_dt)\n an(j) = temp1 * temp2\n cn(j) = temp1 * temp3\n bn(j) = -(an(j) + cn(j))\n end do\n end block\n\n ! Compute right side of equation\n do j = 1, N\n y(:M, j) = 3.75_wp * s(:M) * t(j) * (s(:M)**4 + t(j)**4) &\n - IMAGINARY_UNIT * (s(:M)*t(j))**5\n end do\n\n ! The nonzero boundary conditions enter the linear system via\n ! the right side y(i, j). if the equations (3) given above\n ! are evaluated at i=m and j=1, ..., n then the term cm(m)*u(m+1, j)\n ! is known from the boundary condition to be cm(m)*t(j)**5.\n ! therefore this term can be included in the right side y(m, j).\n ! the same analysis applies at j=n and i=1, .., m. note that the\n ! corner at j=n, i=m includes contributions from both boundaries.\n y(M,:N) = y(M,:N) - cm(M) * (t(:N)**5)\n y(:M,N) = y(:M,N) - cn(N) * (s(:M)**5)\n\n ! Initialize workspace and lower solver routines\n iflg = 0\n call cblktri(iflg, np, N, an, bn, cn, mp, M, am, bm, cm, IDIMY, y, ierror, workspace)\n\n ! Solve complex block tridiagonal linear system\n iflg = iflg + 1\n do while(iflg <= 1)\n call cblktri(iflg, np, N, an, bn, cn, mp, M, am, bm, cm, IDIMY, y, ierror, workspace)\n iflg = iflg + 1\n end do\n\n ! Compute discretization error. The exact solution is\n ! u(s,t) = (st)**5\n block\n real(wp), parameter :: KNOWN_ERROR = 0.164571992877414e-004_wp\n real(wp) :: discretization_error\n real(wp) :: exact_solution(M, N)\n\n do j = 1, N\n do i = 1, M\n exact_solution(i,j) = (s(i)*t(j))**5\n end do\n end do\n\n ! Set discretization error\n discretization_error = maxval(abs(exact_solution-y(:M,:N)))\n\n call check_output('cblktri', ierror, KNOWN_ERROR, discretization_error)\n end block\n\n ! Release memory\n call workspace%destroy()\n\nend program test_cblktri\n", "meta": {"hexsha": "a7520c474f835eb588440b669413eeeb8bcbb70b", "size": 6235, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/tcblktri.f90", "max_stars_repo_name": "jlokimlin/fishpack", "max_stars_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2018-03-12T11:31:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-27T07:58:23.000Z", "max_issues_repo_path": "examples/tcblktri.f90", "max_issues_repo_name": "jlokimlin/fishpack", "max_issues_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2016-05-07T22:42:47.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-15T17:44:58.000Z", "max_forks_repo_path": "examples/tcblktri.f90", "max_forks_repo_name": "jlokimlin/modern_fishpack", "max_forks_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-01-26T20:49:05.000Z", "max_forks_repo_forks_event_max_datetime": "2017-01-27T16:44:58.000Z", "avg_line_length": 38.487654321, "max_line_length": 93, "alphanum_fraction": 0.3939053729, "num_tokens": 1578, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898102301019, "lm_q2_score": 0.7401743735019595, "lm_q1q2_score": 0.6705904401862248}} {"text": "MODULE multidim_integrate\r\nIMPLICIT NONE\r\n\r\nINTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(15, 60)\r\n\r\n! This version, which uses the ELF90 subset of Fortran 90, produced by\r\n! Alan Miller: alan @ users.bigpond.net.au\r\n! URL: www.bigpond.net.au/amiller/\r\n\r\n! Latest revision - 29 August 1997\r\n\r\nCONTAINS\r\n\r\n\r\nSUBROUTINE dcuhre(ndim, numfun, a, b, minpts, maxpts, funsub, epsabs, &\r\n epsrel, key, restar, result, abserr, neval, ifail, nsub)\r\n!***BEGIN PROLOGUE DCUHRE\r\n!***DATE WRITTEN 900116 (YYMMDD)\r\n!***REVISION DATE 900116 (YYMMDD)\r\n!***CATEGORY NO. H2B1A1\r\n!***AUTHOR\r\n! Jarle Berntsen, The Computing Centre,\r\n! University of Bergen, Thormohlens gt. 55,\r\n! N-5008 Bergen, Norway\r\n! Phone.. 47-5-544055\r\n! Email.. jarle@eik.ii.uib.no\r\n! Terje O. Espelid, Department of Informatics,\r\n! University of Bergen, Thormohlens gt. 55,\r\n! N-5008 Bergen, Norway\r\n! Phone.. 47-5-544180\r\n! Email.. terje@eik.ii.uib.no\r\n! Alan Genz, Computer Science Department, Washington State\r\n! University, Pullman, WA 99163-2752, USA\r\n! Email.. acg@eecs.wsu.edu\r\n!***KEYWORDS automatic multidimensional integrator,\r\n! n-dimensional hyper-rectangles,\r\n! general purpose, global adaptive\r\n!***PURPOSE The routine calculates an approximation to a given\r\n! vector of definite integrals\r\n\r\n! B(1) B(2) B(NDIM)\r\n! I I ... I (F ,F ,...,F ) DX(NDIM)...DX(2)DX(1),\r\n! A(1) A(2) A(NDIM) 1 2 NUMFUN\r\n\r\n! where F = F (X ,X ,...,X ), I = 1,2,...,NUMFUN.\r\n! I I 1 2 NDIM\r\n\r\n! hopefully satisfying for each component of I the following\r\n! claim for accuracy:\r\n! ABS(I(K)-RESULT(K)).LE.MAX(EPSABS,EPSREL*ABS(I(K)))\r\n!***DESCRIPTION Computation of integrals over hyper-rectangular regions.\r\n! DCUHRE is a driver for the integration routine\r\n! DADHRE, which repeatedly subdivides the region\r\n! of integration and estimates the integrals and the\r\n! errors over the subregions with greatest\r\n! estimated errors until the error request\r\n! is met or MAXPTS function evaluations have been used.\r\n\r\n! For NDIM = 2 the default integration rule is of\r\n! degree 13 and uses 65 evaluation points.\r\n! For NDIM = 3 the default integration rule is of\r\n! degree 11 and uses 127 evaluation points.\r\n! For NDIM greater then 3 the default integration rule\r\n! is of degree 9 and uses NUM evaluation points where\r\n! NUM = 1 + 4*2*NDIM + 2*NDIM*(NDIM-1) + 4*NDIM*(NDIM-1) +\r\n! 4*NDIM*(NDIM-1)*(NDIM-2)/3 + 2**NDIM\r\n! The degree 9 rule may also be applied for NDIM = 2\r\n! and NDIM = 3.\r\n! A rule of degree 7 is available in all dimensions.\r\n! The number of evaluation\r\n! points used by the degree 7 rule is\r\n! NUM = 1 + 3*2*NDIM + 2*NDIM*(NDIM-1) + 2**NDIM\r\n\r\n! When DCUHRE computes estimates to a vector of\r\n! integrals, all components of the vector are given\r\n! the same treatment. That is, I(F ) and I(F ) for\r\n! J K\r\n! J not equal to K, are estimated with the same\r\n! subdivision of the region of integration.\r\n! For integrals with enough similarity, we may save\r\n! time by applying DCUHRE to all integrands in one call.\r\n! For integrals that varies continuously as functions of\r\n! some parameter, the estimates produced by DCUHRE will\r\n! also vary continuously when the same subdivision is\r\n! applied to all components. This will generally not be\r\n! the case when the different components are given\r\n! separate treatment.\r\n\r\n! On the other hand this feature should be used with\r\n! caution when the different components of the integrals\r\n! require clearly different subdivisions.\r\n\r\n! ON ENTRY\r\n\r\n! NDIM Integer.\r\n! Number of variables. 1 < NDIM <= 15.\r\n! NUMFUN Integer.\r\n! Number of components of the integral.\r\n! A Real array of dimension NDIM.\r\n! Lower limits of integration.\r\n! B Real array of dimension NDIM.\r\n! Upper limits of integration.\r\n! MINPTS Integer.\r\n! Minimum number of function evaluations.\r\n! MAXPTS Integer.\r\n! Maximum number of function evaluations.\r\n! The number of function evaluations over each subregion is NUM.\r\n! If (KEY = 0 or KEY = 1) and (NDIM = 2) Then\r\n! NUM = 65\r\n! Elseif (KEY = 0 or KEY = 2) and (NDIM = 3) Then\r\n! NUM = 127\r\n! Elseif (KEY = 0 and NDIM > 3) or (KEY = 3) Then\r\n! NUM = 1 + 4*2*NDIM + 2*NDIM*(NDIM-1) + 4*NDIM*(NDIM-1) +\r\n! 4*NDIM*(NDIM-1)*(NDIM-2)/3 + 2**NDIM\r\n! Elseif (KEY = 4) Then\r\n! NUM = 1 + 3*2*NDIM + 2*NDIM*(NDIM-1) + 2**NDIM\r\n! MAXPTS >= 3*NUM and MAXPTS >= MINPTS\r\n! For 3 < NDIM < 13 the minimum values for MAXPTS are:\r\n! NDIM = 4 5 6 7 8 9 10 11 12\r\n! KEY = 3: 459 819 1359 2151 3315 5067 7815 12351 20235\r\n! KEY = 4: 195 309 483 765 1251 2133 3795 7005 13299\r\n! FUNSUB Externally declared subroutine for computing all components of the\r\n! integrand at the given evaluation point.\r\n! It must have parameters (NDIM,X,NUMFUN,FUNVLS)\r\n! Input parameters:\r\n! NDIM Integer that defines the dimension of the\r\n! integral.\r\n! X Real array of dimension NDIM\r\n! that defines the evaluation point.\r\n! NUMFUN Integer that defines the number of\r\n! components of I.\r\n! Output parameter:\r\n! FUNVLS Real array of dimension NUMFUN\r\n! that defines NUMFUN components of the integrand.\r\n\r\n! EPSABS Real.\r\n! Requested absolute error.\r\n! EPSREL Real.\r\n! Requested relative error.\r\n! KEY Integer.\r\n! Key to selected local integration rule.\r\n! KEY = 0 is the default value.\r\n! For NDIM = 2 the degree 13 rule is selected.\r\n! For NDIM = 3 the degree 11 rule is selected.\r\n! For NDIM > 3 the degree 9 rule is selected.\r\n! KEY = 1 gives the user the 2 dimensional degree 13\r\n! integration rule that uses 65 evaluation points.\r\n! KEY = 2 gives the user the 3 dimensional degree 11\r\n! integration rule that uses 127 evaluation points.\r\n! KEY = 3 gives the user the degree 9 integration rule.\r\n! KEY = 4 gives the user the degree 7 integration rule.\r\n! This is the recommended rule for problems that\r\n! require great adaptivity.\r\n! RESTAR Integer.\r\n! If RESTAR = 0, this is the first attempt to compute\r\n! the integral.\r\n! If RESTAR = 1, then we restart a previous attempt.\r\n! In this case the only parameters for DCUHRE that may\r\n! be changed (with respect to the previous call of DCUHRE)\r\n! are MINPTS, MAXPTS, EPSABS, EPSREL and RESTAR.\r\n! NSUB Integer.\r\n! If RESTAR = 1, then NSUB contains the number of subregions from\r\n! the previous call,\r\n\r\n! ON RETURN\r\n\r\n! RESULT Real array of dimension NUMFUN.\r\n! Approximations to all components of the integral.\r\n! ABSERR Real array of dimension NUMFUN.\r\n! Estimates of absolute errors.\r\n! NEVAL Integer.\r\n! Number of function evaluations used by DCUHRE.\r\n! IFAIL Integer.\r\n! IFAIL = 0 for normal exit, when ABSERR(K) <= EPSABS or\r\n! ABSERR(K) <= ABS(RESULT(K))*EPSREL with MAXPTS or less\r\n! function evaluations for all values of K,\r\n! 1 <= K <= NUMFUN .\r\n! IFAIL = 1 if MAXPTS was too small for DCUHRE\r\n! to obtain the required accuracy. In this case DCUHRE\r\n! returns values of RESULT with estimated absolute\r\n! errors ABSERR.\r\n! IFAIL = 2 if KEY is less than 0 or KEY greater than 4.\r\n! IFAIL = 3 if NDIM is less than 2 or NDIM greater than 15.\r\n! IFAIL = 4 if KEY = 1 and NDIM not equal to 2.\r\n! IFAIL = 5 if KEY = 2 and NDIM not equal to 3.\r\n! IFAIL = 6 if NUMFUN is less than 1.\r\n! IFAIL = 7 if volume of region of integration is zero.\r\n! IFAIL = 8 if MAXPTS is less than 3*NUM.\r\n! IFAIL = 9 if MAXPTS is less than MINPTS.\r\n! IFAIL = 10 if EPSABS < 0 and EPSREL < 0.\r\n! IFAIL = 11 if NW is too small.\r\n! IFAIL = 12 if unlegal RESTAR.\r\n! NSUB Integer.\r\n! Contains the number of subregions, in case needed for a restart.\r\n\r\n!***LONG DESCRIPTION\r\n\r\n! The information for each subregion is contained in:\r\n! VALUES, ERRORS, CENTRS, HWIDTS, GREATE, DIR, OLDRES and WORK.\r\n! VALUES contains the estimated values of the integrals.\r\n! ERRORS contains the estimated errors.\r\n! CENTRS contains the centers of the subregions.\r\n! HWIDTS contains the half widths of the subregions.\r\n! GREATE contains the greatest estimated error for each subregion.\r\n! DIR contains the directions for further subdivision.\r\n! OLDRES is used as a work array in DADHRE.\r\n\r\n! The data structures for the subregions are in DADHRE organized\r\n! as a heap, and the size of GREATE(I) defines the position of\r\n! region I in the heap. The heap is maintained by the program DTRHRE.\r\n\r\n! The subroutine DADHRE is written for efficient execution on shared\r\n! memory parallel computer. On a computer with NPROC processors we will\r\n! in each subdivision step divide MDIV regions, where MDIV is\r\n! chosen such that MOD(2*MDIV,NPROC) = 0, in totally 2*MDIV new regions.\r\n! Each processor will then compute estimates of the integrals and errors\r\n! over 2*MDIV/NPROC subregions in each subdivision step.\r\n! The subroutine for estimating the integral and the error over\r\n! each subregion, DRLHRE, uses WORK2 as a work array.\r\n! We must make sure that each processor writes its results to\r\n! separate parts of the memory, and therefore the sizes of WORK and\r\n! WORK2 are functions of MDIV.\r\n! In order to achieve parallel processing of subregions, compiler\r\n! directives should be placed in front of the DO 200\r\n! loop in DADHRE on machines like Alliant and CRAY.\r\n\r\n!***REFERENCES\r\n! J.Berntsen, T.O.Espelid and A.Genz, An Adaptive Algorithm\r\n! for the Approximate Calculation of Multiple Integrals,\r\n! To be published.\r\n\r\n! J.Berntsen, T.O.Espelid and A.Genz, DCUHRE: An Adaptive\r\n! Multidimensional Integration Routine for a Vector of\r\n! Integrals, To be published.\r\n\r\n!***ROUTINES CALLED DCHHRE,DADHRE\r\n!***END PROLOGUE DCUHRE\r\n\r\n! Global variables.\r\n\r\nINTEGER, INTENT(IN) :: ndim, numfun, minpts, maxpts, key, restar\r\nINTEGER, INTENT(IN OUT) :: nsub\r\nINTEGER, INTENT(OUT) :: neval, ifail\r\nREAL (dp), INTENT(IN) :: a(:), b(:), epsabs, epsrel\r\nREAL (dp), INTENT(OUT) :: result(:), abserr(:)\r\n\r\n! Dimensions of arguments:\r\n! a(ndim), b(ndim), result(numfun), abserr(numfun), work(nw)\r\n\r\nINTERFACE\r\n SUBROUTINE funsub(ndim, z, nfun, f)\r\n IMPLICIT NONE\r\n INTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(15, 60)\r\n INTEGER, INTENT(IN) :: ndim, nfun\r\n REAL (dp), INTENT(IN) :: z(:)\r\n REAL (dp), INTENT(OUT) :: f(:)\r\n END SUBROUTINE funsub\r\nEND INTERFACE\r\n\r\n! Local variables.\r\n\r\n! MDIV Integer.\r\n! MDIV is the number of subregions that are divided in\r\n! each subdivision step in DADHRE.\r\n! MDIV is chosen default to 1.\r\n! For efficient execution on parallel computers\r\n! with NPROC processors MDIV should be set equal to\r\n! the smallest integer such that MOD(2*MDIV,NPROC) = 0.\r\n! MAXDIM Integer.\r\n! The maximum allowed value of NDIM.\r\n! MAXWT Integer. The maximum number of weights used by the\r\n! integration rule.\r\n! WTLENG Integer.\r\n! The number of generators used by the selected rule.\r\n! MAXSUB Integer.\r\n! The maximum allowed number of subdivisions\r\n! for the given values of KEY, NDIM and MAXPTS.\r\n! MINSUB Integer.\r\n! The minimum allowed number of subregions for the given\r\n! values of MINPTS, KEY and NDIM.\r\n! WRKSUB Integer.\r\n! The maximum allowed number of subregions as a function\r\n! of NW, NUMFUN, NDIM and MDIV. This determines the length\r\n! of the main work arrays.\r\n! NUM Integer. The number of integrand evaluations needed\r\n! over each subregion.\r\n\r\nINTEGER :: wtleng, maxsub, minsub\r\nINTEGER :: num, keyf\r\nINTEGER, PARAMETER :: mdiv=1, maxdim=15\r\n\r\n!***FIRST EXECUTABLE STATEMENT DCUHRE\r\n\r\n! Compute NUM, WTLENG, MAXSUB and MINSUB, and check the input parameters.\r\n\r\nCALL dchhre(maxdim, ndim, numfun, a, b, minpts, maxpts, epsabs, &\r\n epsrel, key, restar, num, maxsub, minsub, keyf, ifail, wtleng)\r\n\r\nIF (ifail /= 0) THEN\r\n GO TO 999\r\nEND IF\r\n\r\n! Compute the size of the temporary work space needed in DADHRE.\r\n\r\nCALL dadhre(ndim, numfun, mdiv, a, b, minsub, maxsub, funsub, epsabs, &\r\n epsrel, keyf, restar, num, wtleng, result, abserr, &\r\n neval, nsub, ifail)\r\n999 RETURN\r\n\r\n!***END DCUHRE\r\n\r\nEND SUBROUTINE dcuhre\r\n\r\n\r\nSUBROUTINE dchhre(maxdim, ndim, numfun, a, b, minpts, maxpts, epsabs, &\r\n epsrel, key, restar, num, maxsub, minsub, keyf, ifail, &\r\n wtleng)\r\n!***BEGIN PROLOGUE DCHHRE\r\n!***PURPOSE DCHHRE checks the validity of the\r\n! input parameters to DCUHRE.\r\n!***DESCRIPTION\r\n! DCHHRE computes NUM, MAXSUB, MINSUB, KEYF, WTLENG and\r\n! IFAIL as functions of the input parameters to DCUHRE,\r\n! and checks the validity of the input parameters to DCUHRE.\r\n\r\n! ON ENTRY\r\n\r\n! MAXDIM Integer.\r\n! The maximum allowed number of dimensions.\r\n! NDIM Integer.\r\n! Number of variables. 1 < NDIM <= MAXDIM.\r\n! NUMFUN Integer.\r\n! Number of components of the integral.\r\n! A Real array of dimension NDIM.\r\n! Lower limits of integration.\r\n! B Real array of dimension NDIM.\r\n! Upper limits of integration.\r\n! MINPTS Integer.\r\n! Minimum number of function evaluations.\r\n! MAXPTS Integer.\r\n! Maximum number of function evaluations.\r\n! The number of function evaluations over each subregion\r\n! is NUM.\r\n! If (KEY = 0 or KEY = 1) and (NDIM = 2) Then\r\n! NUM = 65\r\n! Elseif (KEY = 0 or KEY = 2) and (NDIM = 3) Then\r\n! NUM = 127\r\n! Elseif (KEY = 0 and NDIM > 3) or (KEY = 3) Then\r\n! NUM = 1 + 4*2*NDIM + 2*NDIM*(NDIM-1) + 4*NDIM*(NDIM-1) +\r\n! 4*NDIM*(NDIM-1)*(NDIM-2)/3 + 2**NDIM\r\n! Elseif (KEY = 4) Then\r\n! NUM = 1 + 3*2*NDIM + 2*NDIM*(NDIM-1) + 2**NDIM\r\n! MAXPTS >= 3*NUM and MAXPTS >= MINPTS\r\n! EPSABS Real.\r\n! Requested absolute error.\r\n! EPSREL Real.\r\n! Requested relative error.\r\n! KEY Integer.\r\n! Key to selected local integration rule.\r\n! KEY = 0 is the default value.\r\n! For NDIM = 2 the degree 13 rule is selected.\r\n! For NDIM = 3 the degree 11 rule is selected.\r\n! For NDIM > 3 the degree 9 rule is selected.\r\n! KEY = 1 gives the user the 2 dimensional degree 13\r\n! integration rule that uses 65 evaluation points.\r\n! KEY = 2 gives the user the 3 dimensional degree 11\r\n! integration rule that uses 127 evaluation points.\r\n! KEY = 3 gives the user the degree 9 integration rule.\r\n! KEY = 4 gives the user the degree 7 integration rule.\r\n! This is the recommended rule for problems that\r\n! require great adaptivity.\r\n! RESTAR Integer.\r\n! If RESTAR = 0, this is the first attempt to compute\r\n! the integral.\r\n! If RESTAR = 1, then we restart a previous attempt.\r\n\r\n! ON RETURN\r\n\r\n! NUM Integer.\r\n! The number of function evaluations over each subregion.\r\n! MAXSUB Integer.\r\n! The maximum allowed number of subregions for the\r\n! given values of MAXPTS, KEY and NDIM.\r\n! MINSUB Integer.\r\n! The minimum allowed number of subregions for the given\r\n! values of MINPTS, KEY and NDIM.\r\n! IFAIL Integer.\r\n! IFAIL = 0 for normal exit.\r\n! IFAIL = 2 if KEY is less than 0 or KEY greater than 4.\r\n! IFAIL = 3 if NDIM is less than 2 or NDIM greater than MAXDIM.\r\n! IFAIL = 4 if KEY = 1 and NDIM not equal to 2.\r\n! IFAIL = 5 if KEY = 2 and NDIM not equal to 3.\r\n! IFAIL = 6 if NUMFUN less than 1.\r\n! IFAIL = 7 if volume of region of integration is zero.\r\n! IFAIL = 8 if MAXPTS is less than 3*NUM.\r\n! IFAIL = 9 if MAXPTS is less than MINPTS.\r\n! IFAIL = 10 if EPSABS < 0 and EPSREL < 0.\r\n! IFAIL = 11 if NW is too small.\r\n! IFAIL = 12 if unlegal RESTAR.\r\n! KEYF Integer.\r\n! Key to selected integration rule.\r\n! WTLENG Integer.\r\n! The number of generators of the chosen integration rule.\r\n\r\n!***ROUTINES CALLED-NONE\r\n!***END PROLOGUE DCHHRE\r\n\r\n! Global variables.\r\n\r\nINTEGER, INTENT(IN) :: maxdim, ndim, numfun, minpts, maxpts, key, restar\r\nINTEGER, INTENT(OUT) :: num, minsub, maxsub, keyf, ifail, wtleng\r\nREAL (dp), INTENT(IN) :: a(:), b(:), epsabs, epsrel\r\n\r\n! Local variables.\r\n\r\nINTEGER :: j\r\n\r\n!***FIRST EXECUTABLE STATEMENT DCHHRE\r\n\r\nifail = 0\r\n\r\n! Check on legal KEY.\r\n\r\nIF (key < 0 .OR. key > 4) THEN\r\n ifail = 2\r\n GO TO 999\r\nEND IF\r\n\r\n! Check on legal NDIM.\r\n\r\nIF (ndim < 2 .OR. ndim > maxdim) THEN\r\n ifail = 3\r\n GO TO 999\r\nEND IF\r\n\r\n! For KEY = 1, NDIM must be equal to 2.\r\n\r\nIF (key == 1 .AND. ndim /= 2) THEN\r\n ifail = 4\r\n GO TO 999\r\nEND IF\r\n\r\n! For KEY = 2, NDIM must be equal to 3.\r\n\r\nIF (key == 2 .AND. ndim /= 3) THEN\r\n ifail = 5\r\n GO TO 999\r\nEND IF\r\n\r\n! For KEY = 0, we point at the selected integration rule.\r\n\r\nIF (key == 0) THEN\r\n IF (ndim == 2) THEN\r\n keyf = 1\r\n ELSE IF (ndim == 3) THEN\r\n keyf = 2\r\n ELSE\r\n keyf = 3\r\n END IF\r\nELSE\r\n keyf = key\r\nEND IF\r\n\r\n! Compute NUM and WTLENG as a function of KEYF and NDIM.\r\n\r\nIF (keyf == 1) THEN\r\n num = 65\r\n wtleng = 14\r\nELSE IF (keyf == 2) THEN\r\n num = 127\r\n wtleng = 13\r\nELSE IF (keyf == 3) THEN\r\n num = 1 + 4*2*ndim + 2*ndim* (ndim-1) + 4*ndim* (ndim-1) + &\r\n 4*ndim* (ndim-1)* (ndim-2)/3 + 2**ndim\r\n wtleng = 9\r\n IF (ndim == 2) wtleng = 8\r\nELSE IF (keyf == 4) THEN\r\n num = 1 + 3*2*ndim + 2*ndim* (ndim-1) + 2**ndim\r\n wtleng = 6\r\nEND IF\r\n\r\n! Compute MAXSUB.\r\n\r\nmaxsub = (maxpts-num)/ (2*num) + 1\r\n\r\n! Compute MINSUB.\r\n\r\nminsub = (minpts-num)/ (2*num) + 1\r\nIF (MOD(minpts-num, 2*num) /= 0) THEN\r\n minsub = minsub + 1\r\nEND IF\r\nminsub = MAX(2,minsub)\r\n\r\n! Check on positive NUMFUN.\r\n\r\nIF (numfun < 1) THEN\r\n ifail = 6\r\n GO TO 999\r\nEND IF\r\n\r\n! Check on legal upper and lower limits of integration.\r\n\r\nDO j = 1, ndim\r\n IF (a(j)-b(j) == 0) THEN\r\n ifail = 7\r\n GO TO 999\r\n END IF\r\nEND DO\r\n\r\n! Check on MAXPTS < 3*NUM.\r\n\r\nIF (maxpts < 3*num) THEN\r\n ifail = 8\r\n GO TO 999\r\nEND IF\r\n\r\n! Check on MAXPTS >= MINPTS.\r\n\r\nIF (maxpts < minpts) THEN\r\n ifail = 9\r\n GO TO 999\r\nEND IF\r\n\r\n! Check on legal accuracy requests.\r\n\r\nIF (epsabs < 0 .AND. epsrel < 0) THEN\r\n ifail = 10\r\n GO TO 999\r\nEND IF\r\n\r\n! Check on legal RESTAR.\r\n\r\nIF (restar /= 0 .AND. restar /= 1) THEN\r\n ifail = 12\r\n GO TO 999\r\nEND IF\r\n999 RETURN\r\n\r\n!***END DCHHRE\r\n\r\nEND SUBROUTINE dchhre\r\n\r\n\r\nSUBROUTINE dadhre(ndim, numfun, mdiv, a, b, minsub, maxsub, funsub, epsabs, &\r\n epsrel, key, restar, num, wtleng, result, abserr, &\r\n neval, nsub, ifail)\r\n!***BEGIN PROLOGUE DADHRE\r\n!***KEYWORDS automatic multidimensional integrator,\r\n! n-dimensional hyper-rectangles,\r\n! general purpose, global adaptive\r\n!***PURPOSE The routine calculates an approximation to a given\r\n! vector of definite integrals, I, over a hyper-rectangular\r\n! region hopefully satisfying for each component of I the\r\n! following claim for accuracy:\r\n! ABS(I(K)-RESULT(K)).LE.MAX(EPSABS,EPSREL*ABS(I(K)))\r\n!***DESCRIPTION Computation of integrals over hyper-rectangular\r\n! regions.\r\n! DADHRE repeatedly subdivides the region\r\n! of integration and estimates the integrals and the\r\n! errors over the subregions with greatest\r\n! estimated errors until the error request\r\n! is met or MAXSUB subregions are stored.\r\n! The regions are divided in two equally sized parts along\r\n! the direction with greatest absolute fourth divided\r\n! difference.\r\n\r\n! ON ENTRY\r\n\r\n! NDIM Integer.\r\n! Number of variables. 1 < NDIM <= MAXDIM.\r\n! NUMFUN Integer.\r\n! Number of components of the integral.\r\n! MDIV Integer.\r\n! Defines the number of new subregions that are divided\r\n! in each subdivision step.\r\n! A Real array of dimension NDIM.\r\n! Lower limits of integration.\r\n! B Real array of dimension NDIM.\r\n! Upper limits of integration.\r\n! MINSUB Integer.\r\n! The computations proceed until there are at least\r\n! MINSUB subregions in the data structure.\r\n! MAXSUB Integer.\r\n! The computations proceed until there are at most\r\n! MAXSUB subregions in the data structure.\r\n\r\n! FUNSUB Externally declared subroutine for computing\r\n! all components of the integrand in the given\r\n! evaluation point.\r\n! It must have parameters (NDIM,X,NUMFUN,FUNVLS)\r\n! Input parameters:\r\n! NDIM Integer that defines the dimension of the\r\n! integral.\r\n! X Real array of dimension NDIM\r\n! that defines the evaluation point.\r\n! NUMFUN Integer that defines the number of\r\n! components of I.\r\n! Output parameter:\r\n! FUNVLS Real array of dimension NUMFUN\r\n! that defines NUMFUN components of the integrand.\r\n\r\n! EPSABS Real.\r\n! Requested absolute error.\r\n! EPSREL Real.\r\n! Requested relative error.\r\n! KEY Integer.\r\n! Key to selected local integration rule.\r\n! KEY = 0 is the default value.\r\n! For NDIM = 2 the degree 13 rule is selected.\r\n! For NDIM = 3 the degree 11 rule is selected.\r\n! For NDIM > 3 the degree 9 rule is selected.\r\n! KEY = 1 gives the user the 2 dimensional degree 13\r\n! integration rule that uses 65 evaluation points.\r\n! KEY = 2 gives the user the 3 dimensional degree 11\r\n! integration rule that uses 127 evaluation points.\r\n! KEY = 3 gives the user the degree 9 integration rule.\r\n! KEY = 4 gives the user the degree 7 integration rule.\r\n! This is the recommended rule for problems that\r\n! require great adaptivity.\r\n! RESTAR Integer.\r\n! If RESTAR = 0, this is the first attempt to compute\r\n! the integral.\r\n! If RESTAR = 1, then we restart a previous attempt.\r\n! (In this case the output parameters from DADHRE\r\n! must not be changed since the last\r\n! exit from DADHRE.)\r\n! NUM Integer.\r\n! The number of function evaluations over each subregion.\r\n! WTLENG Integer.\r\n! The number of weights in the basic integration rule.\r\n! NSUB Integer.\r\n! If RESTAR = 1, then NSUB must specify the number\r\n! of subregions stored in the previous call to DADHRE.\r\n\r\n! ON RETURN\r\n\r\n! RESULT Real array of dimension NUMFUN.\r\n! Approximations to all components of the integral.\r\n! ABSERR Real array of dimension NUMFUN.\r\n! Estimates of absolute accuracies.\r\n! NEVAL Integer.\r\n! Number of function evaluations used by DADHRE.\r\n! NSUB Integer.\r\n! Number of stored subregions.\r\n! IFAIL Integer.\r\n! IFAIL = 0 for normal exit, when ABSERR(K) <= EPSABS or\r\n! ABSERR(K) <= ABS(RESULT(K))*EPSREL with MAXSUB or less\r\n! subregions processed for all values of K,\r\n! 1 <= K <= NUMFUN.\r\n! IFAIL = 1 if MAXSUB was too small for DADHRE\r\n! to obtain the required accuracy. In this case DADHRE\r\n! returns values of RESULT with estimated absolute\r\n! accuracies ABSERR.\r\n!\r\n! The following occupied workspace provided by DCUHRE in the Fortran 77 code:\r\n!\r\n! VALUES Real array of dimension (NUMFUN,MAXSUB).\r\n! Used to store estimated values of the integrals\r\n! over the subregions.\r\n! ERRORS Real array of dimension (NUMFUN,MAXSUB).\r\n! Used to store the corresponding estimated errors.\r\n! CENTRS Real array of dimension (NDIM,MAXSUB).\r\n! Used to store the centers of the stored subregions.\r\n! HWIDTS Real array of dimension (NDIM,MAXSUB).\r\n! Used to store the half widths of the stored subregions.\r\n! GREATE Real array of dimension MAXSUB.\r\n! Used to store the greatest estimated errors in\r\n! all subregions.\r\n! DIR Real array of dimension MAXSUB.\r\n! DIR is used to store the directions for\r\n! further subdivision.\r\n! OLDRES Real array of dimension (NUMFUN,MDIV).\r\n! Used to store old estimates of the integrals over the\r\n! subregions.\r\n! WORK Real array of dimension LENW.\r\n! Used in DRLHRE and DTRHRE.\r\n! G Real array of dimension (NDIM,WTLENG,2*MDIV).\r\n! The fully symmetric sum generators for the rules.\r\n! G(1,J,1),...,G(NDIM,J,1) are the generators for the\r\n! points associated with the Jth weights.\r\n! When MDIV subregions are divided in 2*MDIV\r\n! subregions, the subregions may be processed on different\r\n! processors and we must make a copy of the generators\r\n! for each processor.\r\n! W Real array of dimension (5,WTLENG).\r\n! The weights for the basic and null rules.\r\n! W(1,1), ..., W(1,WTLENG) are weights for the basic rule.\r\n! W(I,1), ..., W(I,WTLENG) , for I > 1 are null rule weights.\r\n! RULPTS Real array of dimension WTLENG.\r\n! Work array used in DINHRE.\r\n! CENTER Real array of dimension NDIM.\r\n! Work array used in DTRHRE.\r\n! HWIDTH Real array of dimension NDIM.\r\n! Work array used in DTRHRE.\r\n! X Real array of dimension (NDIM,2*MDIV).\r\n! Work array used in DRLHRE.\r\n! SCALES Real array of dimension (3,WTLENG).\r\n! Work array used by DINHRE and DRLHRE.\r\n! NORMS Real array of dimension (3,WTLENG).\r\n! Work array used by DINHRE and DRLHRE.\r\n\r\n!***REFERENCES\r\n\r\n! P. van Dooren and L. de Ridder, Algorithm 6, An adaptive algorithm\r\n! for numerical integration over an n-dimensional cube, J.Comput.Appl.\r\n! Math. 2(1976)207-217.\r\n\r\n! A.C.Genz and A.A.Malik, Algorithm 019. Remarks on algorithm 006:\r\n! An adaptive algorithm for numerical integration over an\r\n! N-dimensional rectangular region, J.Comput.Appl.Math. 6(1980)295-302.\r\n\r\n!***ROUTINES CALLED DTRHRE, DINHRE, DRLHRE\r\n!***END PROLOGUE DADHRE\r\n\r\n! Global variables.\r\n\r\nINTEGER, INTENT(IN) :: num, ndim, numfun, mdiv, minsub, maxsub, key, &\r\n restar, wtleng\r\nINTEGER, INTENT(IN OUT) :: nsub\r\nINTEGER, INTENT(OUT) :: neval, ifail\r\nREAL (dp), INTENT(IN) :: a(:), b(:), epsabs, epsrel\r\nREAL (dp), INTENT(OUT) :: result(:), abserr(:)\r\n\r\nINTERFACE\r\n SUBROUTINE funsub(ndim, z, nfun, f)\r\n IMPLICIT NONE\r\n INTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(15, 60)\r\n INTEGER, INTENT(IN) :: ndim, nfun\r\n REAL (dp), INTENT(IN) :: z(:)\r\n REAL (dp), INTENT(OUT) :: f(:)\r\n END SUBROUTINE funsub\r\nEND INTERFACE\r\n\r\n! Local variables.\r\n\r\n! INTSGN is used to get correct sign on the integral.\r\n! SBRGNS is the number of stored subregions.\r\n! NDIV The number of subregions to be divided in each main step.\r\n! POINTR Pointer to the position in the data structure where\r\n! the new subregions are to be stored.\r\n! DIRECT Direction of subdivision.\r\n! ERRCOF Heuristic error coeff. defined in DINHRE and used by DRLHRE\r\n! and DADHRE.\r\n\r\nINTEGER :: i, j, k\r\nINTEGER :: intsgn, sbrgns\r\nINTEGER :: ndiv, pointr, DIRECT, INDEX\r\nREAL (dp) :: oldcen, est1, est2, errcof(6)\r\n\r\n! The following automatic arrays were previously part of the workspace\r\n! passed from DCUHRE.\r\n\r\nREAL (dp) :: values(numfun,maxsub), errors(numfun,maxsub), &\r\n centrs(ndim,maxsub), hwidts(ndim,maxsub), greate(maxsub), &\r\n dir(maxsub), oldres(numfun,mdiv), g(ndim,wtleng,2*mdiv), &\r\n w(5,wtleng), center(ndim), hwidth(ndim), scales(3,wtleng), &\r\n norms(3,wtleng)\r\n\r\n!***FIRST EXECUTABLE STATEMENT DADHRE\r\n\r\n! Get the correct sign on the integral.\r\n\r\nintsgn = 1\r\nDO j = 1, ndim\r\n IF (b(j) < a(j)) THEN\r\n intsgn = - intsgn\r\n END IF\r\nEND DO\r\n\r\n! Call DINHRE to compute the weights and abscissas of\r\n! the function evaluation points.\r\n\r\nCALL dinhre(ndim, key, wtleng, w, g(:,:,1), errcof, scales, norms)\r\n\r\n! If RESTAR = 1, then this is a restart run.\r\n\r\nIF (restar == 1) THEN\r\n sbrgns = nsub\r\n GO TO 110\r\nEND IF\r\n\r\n! Initialize the SBRGNS, CENTRS and HWIDTS.\r\n\r\nsbrgns = 1\r\nDO j = 1, ndim\r\n centrs(j,1) = (a(j)+b(j))/2\r\n hwidts(j,1) = ABS(b(j)-a(j))/2\r\nEND DO\r\n\r\n! Initialize RESULT, ABSERR and NEVAL.\r\n\r\nDO j = 1, numfun\r\n result(j) = 0\r\n abserr(j) = 0\r\nEND DO\r\nneval = 0\r\n\r\n! Apply DRLHRE over the whole region.\r\n\r\nCALL drlhre(ndim, centrs(:,1), hwidts(:,1), wtleng, g(:,:,1), w, errcof, &\r\n numfun, funsub, scales, norms, values(:,1), errors(:,1), dir(1))\r\nneval = neval + num\r\n\r\n! Add the computed values to RESULT and ABSERR.\r\n\r\nDO j = 1, numfun\r\n result(j) = result(j) + values(j,1)\r\nEND DO\r\nDO j = 1, numfun\r\n abserr(j) = abserr(j) + errors(j,1)\r\nEND DO\r\n\r\n! Store results in heap.\r\n\r\nINDEX = 1\r\nCALL dtrhre(2, ndim, numfun, INDEX, values, errors, centrs, hwidts, &\r\n greate, center, hwidth, dir)\r\n\r\n!***End initialisation.\r\n\r\n!***Begin loop while the error is too great,\r\n! and SBRGNS+1 is less than MAXSUB.\r\n\r\n110 IF (sbrgns+1 <= maxsub) THEN\r\n \r\n! If we are allowed to divide further,\r\n! prepare to apply basic rule over each half of the\r\n! NDIV subregions with greatest errors.\r\n! If MAXSUB is great enough, NDIV = MDIV\r\n \r\n IF (mdiv > 1) THEN\r\n ndiv = maxsub - sbrgns\r\n ndiv = MIN(ndiv, mdiv, sbrgns)\r\n ELSE\r\n ndiv = 1\r\n END IF\r\n \r\n! Divide the NDIV subregions in two halves, and compute\r\n! integral and error over each half.\r\n \r\n DO i = 1, ndiv\r\n pointr = sbrgns + ndiv + 1 - i\r\n \r\n! Adjust RESULT and ABSERR.\r\n \r\n DO j = 1, numfun\r\n result(j) = result(j) - values(j,1)\r\n abserr(j) = abserr(j) - errors(j,1)\r\n END DO\r\n \r\n! Compute first half region.\r\n \r\n DO j = 1, ndim\r\n centrs(j,pointr) = centrs(j,1)\r\n hwidts(j,pointr) = hwidts(j,1)\r\n END DO\r\n DIRECT = dir(1)\r\n dir(pointr) = DIRECT\r\n hwidts(DIRECT,pointr) = hwidts(DIRECT,1)/2\r\n oldcen = centrs(DIRECT,1)\r\n centrs(DIRECT,pointr) = oldcen - hwidts(DIRECT,pointr)\r\n \r\n! Save the computed values of the integrals.\r\n \r\n DO j = 1, numfun\r\n oldres(j,ndiv-i+1) = values(j,1)\r\n END DO\r\n \r\n! Adjust the heap.\r\n \r\n CALL dtrhre(1, ndim, numfun, sbrgns, values, errors, centrs, &\r\n hwidts, greate, center, hwidth, dir)\r\n \r\n! Compute second half region.\r\n \r\n DO j = 1, ndim\r\n centrs(j,pointr-1) = centrs(j,pointr)\r\n hwidts(j,pointr-1) = hwidts(j,pointr)\r\n END DO\r\n centrs(DIRECT,pointr-1) = oldcen + hwidts(DIRECT,pointr)\r\n hwidts(DIRECT,pointr-1) = hwidts(DIRECT,pointr)\r\n dir(pointr-1) = DIRECT\r\n END DO\r\n \r\n! Make copies of the generators for each processor.\r\n \r\n DO i = 2, 2*ndiv\r\n DO j = 1, ndim\r\n DO k = 1, wtleng\r\n g(j,k,i) = g(j,k,1)\r\n END DO\r\n END DO\r\n END DO\r\n \r\n! Apply basic rule.\r\n \r\n DO i = 1, 2*ndiv\r\n INDEX = sbrgns + i\r\n CALL drlhre(ndim, centrs(:,INDEX), hwidts(:,INDEX), wtleng, g(:,:,i), w, &\r\n errcof, numfun, funsub, scales, norms, values(:,INDEX), &\r\n errors(:,INDEX), dir(INDEX))\r\n END DO\r\n neval = neval + 2*ndiv*num\r\n \r\n! Add new contributions to RESULT.\r\n \r\n DO i = 1, 2*ndiv\r\n DO j = 1, numfun\r\n result(j) = result(j) + values(j,sbrgns+i)\r\n END DO\r\n END DO\r\n \r\n! Check consistency of results and if necessary adjust\r\n! the estimated errors.\r\n \r\n DO i = 1, ndiv\r\n greate(sbrgns+2*i-1) = 0\r\n greate(sbrgns+2*i) = 0\r\n DO j = 1, numfun\r\n est1 = ABS(oldres(j,i)- (values(j,sbrgns+2*i-1)+values(j,sbrgns+2*i)))\r\n est2 = errors(j, sbrgns+2*i-1) + errors(j, sbrgns+2*i)\r\n IF (est2 > 0) THEN\r\n errors(j,sbrgns+2*i-1) = errors(j,sbrgns+2*i-1)*(1+errcof(5)*est1/est2)\r\n errors(j,sbrgns+2*i) = errors(j,sbrgns+2*i)*(1+errcof(5)*est1/est2)\r\n END IF\r\n errors(j,sbrgns+2*i-1) = errors(j,sbrgns+2*i-1) +errcof(6)*est1\r\n errors(j,sbrgns+2*i) = errors(j,sbrgns+2*i) +errcof(6)*est1\r\n IF (errors(j,sbrgns+2*i-1) > greate(sbrgns+2*i-1)) THEN\r\n greate(sbrgns+2*i-1) = errors(j,sbrgns+2*i-1)\r\n END IF\r\n IF (errors(j,sbrgns+2*i) > greate(sbrgns+2*i)) THEN\r\n greate(sbrgns+2*i) = errors(j,sbrgns+2*i)\r\n END IF\r\n abserr(j) = abserr(j) + errors(j,sbrgns+2*i-1) + errors(j,sbrgns+2*i)\r\n END DO\r\n END DO\r\n \r\n! Store results in heap.\r\n \r\n DO i = 1, 2*ndiv\r\n INDEX = sbrgns + i\r\n CALL dtrhre(2, ndim, numfun, INDEX, values, errors, centrs, &\r\n hwidts, greate, center, hwidth, dir)\r\n END DO\r\n sbrgns = sbrgns + 2*ndiv\r\n \r\n! Check for termination.\r\n \r\n IF (sbrgns < minsub) THEN\r\n GO TO 110\r\n END IF\r\n DO j = 1, numfun\r\n IF (abserr(j) > epsrel*ABS(result(j)) .AND. abserr(j) > epsabs) THEN\r\n GO TO 110\r\n END IF\r\n END DO\r\n ifail = 0\r\n GO TO 499\r\n \r\n! Else we did not succeed with the\r\n! given value of MAXSUB.\r\n \r\nELSE\r\n ifail = 1\r\nEND IF\r\n\r\n! Compute more accurate values of RESULT and ABSERR.\r\n\r\n499 DO j = 1, numfun\r\n result(j) = 0\r\n abserr(j) = 0\r\nEND DO\r\nDO i = 1, sbrgns\r\n DO j = 1, numfun\r\n result(j) = result(j) + values(j,i)\r\n abserr(j) = abserr(j) + errors(j,i)\r\n END DO\r\nEND DO\r\n\r\n! Compute correct sign on the integral.\r\n\r\nDO j = 1, numfun\r\n result(j) = result(j)*intsgn\r\nEND DO\r\nnsub = sbrgns\r\nRETURN\r\n\r\n!***END DADHRE\r\n\r\nEND SUBROUTINE dadhre\r\n\r\n\r\nSUBROUTINE dinhre(ndim, key, wtleng, w, g, errcof, scales, norms)\r\n!***BEGIN PROLOGUE DINHRE\r\n!***PURPOSE DINHRE computes abscissas and weights of the integration\r\n! rule and the null rules to be used in error estimation.\r\n! These are computed as functions of NDIM and KEY.\r\n!***DESCRIPTION DINHRE will for given values of NDIM and KEY compute or\r\n! select the correct values of the abscissas and\r\n! corresponding weights for different\r\n! integration rules and null rules and assign them to G and W.\r\n! The heuristic error coefficients ERRCOF\r\n! will be computed as a function of KEY.\r\n! Scaling factors SCALES and normalization factors NORMS\r\n! used in the error estimation are computed.\r\n\r\n\r\n! ON ENTRY\r\n\r\n! NDIM Integer.\r\n! Number of variables.\r\n! KEY Integer.\r\n! Key to selected local integration rule.\r\n! WTLENG Integer.\r\n! The number of weights in each of the rules.\r\n\r\n! ON RETURN\r\n\r\n! W Real array of dimension (5,WTLENG).\r\n! The weights for the basic and null rules.\r\n! W(1,1), ...,W(1,WTLENG) are weights for the basic rule.\r\n! W(I,1), ...,W(I,WTLENG), for I > 1 are null rule weights.\r\n! G Real array of dimension (NDIM,WTLENG).\r\n! The fully symmetric sum generators for the rules.\r\n! G(1,J),...,G(NDIM,J) are the generators for the points\r\n! associated with the the Jth weights.\r\n! ERRCOF Real array of dimension 6.\r\n! Heuristic error coefficients that are used in the\r\n! error estimation in BASRUL.\r\n! It is assumed that the error is computed using:\r\n! IF (N1*ERRCOF(1) < N2 and N2*ERRCOF(2) < N3)\r\n! THEN ERROR = ERRCOF(3)*N1\r\n! ELSE ERROR = ERRCOF(4)*MAX(N1, N2, N3)\r\n! ERROR = ERROR + EP*(ERRCOF(5)*ERROR/(ES+ERROR)+ERRCOF(6))\r\n! where N1-N3 are the null rules, EP is the error for\r\n! the parent\r\n! subregion and ES is the error for the sibling subregion.\r\n! SCALES Real array of dimension (3,WTLENG).\r\n! Scaling factors used to construct new null rules,\r\n! N1, N2 and N3,\r\n! based on a linear combination of two successive null rules\r\n! in the sequence of null rules.\r\n! NORMS Real array of dimension (3,WTLENG).\r\n! 2**NDIM/(1-norm of the null rule constructed by each of\r\n! the scaling factors.)\r\n\r\n!***ROUTINES CALLED D132RE, D113RE, D07HRE, D09HRE\r\n!***END PROLOGUE DINHRE\r\n\r\n! Global variables.\r\n\r\nINTEGER, INTENT(IN) :: ndim, key, wtleng\r\nREAL (dp), INTENT(OUT) :: g(:,:), w(:,:), errcof(:)\r\nREAL (dp), INTENT(OUT) :: scales(:,:)\r\nREAL (dp), INTENT(OUT) :: norms(:,:)\r\n\r\n! Dimensions:\r\n! g(ndim,wtleng), w(5,wtleng), errcof(6), scales(3,wtleng), norms(3,wtleng)\r\n\r\n! Local variables.\r\n\r\nINTEGER :: i, j, k\r\nREAL (dp) :: we(14), rulpts(wtleng)\r\n\r\n!***FIRST EXECUTABLE STATEMENT DINHRE\r\n\r\n! Compute W, G and ERRCOF.\r\n\r\nIF (key == 1) THEN\r\n CALL d132re(w, g, errcof, rulpts)\r\nELSE IF (key == 2) THEN\r\n CALL d113re(w, g, errcof, rulpts)\r\nELSE IF (key == 3) THEN\r\n CALL d09hre(ndim, wtleng, w, g, errcof, rulpts)\r\nELSE IF (key == 4) THEN\r\n CALL d07hre(ndim, wtleng, w, g, errcof, rulpts)\r\nEND IF\r\n\r\n! Compute SCALES and NORMS.\r\n\r\nDO k = 1, 3\r\n DO i = 1, wtleng\r\n IF (w(k+1,i) /= 0) THEN\r\n scales(k,i) = - w(k+2,i)/w(k+1,i)\r\n ELSE\r\n scales(k,i) = 100\r\n END IF\r\n DO j = 1, wtleng\r\n we(j) = w(k+2,j) + scales(k,i)*w(k+1,j)\r\n END DO\r\n norms(k,i) = 0\r\n DO j = 1, wtleng\r\n norms(k,i) = norms(k,i) + rulpts(j)*ABS(we(j))\r\n END DO\r\n norms(k,i) = 2**ndim/norms(k,i)\r\n END DO\r\nEND DO\r\nRETURN\r\n\r\n!***END DINHRE\r\n\r\nEND SUBROUTINE dinhre\r\n\r\n\r\nSUBROUTINE d132re(w, g, errcof, rulpts)\r\n!***BEGIN PROLOGUE D132RE\r\n!***AUTHOR Jarle Berntsen, EDB-senteret,\r\n! University of Bergen, Thormohlens gt. 55,\r\n! N-5008 Bergen, NORWAY\r\n!***PURPOSE D132RE computes abscissas and weights of a 2 dimensional\r\n! integration rule of degree 13.\r\n! Two null rules of degree 11, one null rule of degree 9\r\n! and one null rule of degree 7 to be used in error\r\n! estimation are also computed.\r\n! ***DESCRIPTION D132RE will select the correct values of the abscissas\r\n! and corresponding weights for different\r\n! integration rules and null rules and assign them to\r\n! G and W. The heuristic error coefficients ERRCOF\r\n! will also be assigned.\r\n\r\n\r\n! ON RETURN\r\n\r\n! W Real array of dimension (5,WTLENG).\r\n! The weights for the basic and null rules.\r\n! W(1,1),...,W(1,WTLENG) are weights for the basic rule.\r\n! W(I,1),...,W(I,WTLENG), for I > 1 are null rule weights.\r\n! G Real array of dimension (NDIM,WTLENG).\r\n! The fully symmetric sum generators for the rules.\r\n! G(1,J),...,G(NDIM,J) are the generators for the points\r\n! associated with the the Jth weights.\r\n! ERRCOF Real array of dimension 6.\r\n! Heuristic error coefficients that are used in the\r\n! error estimation in BASRUL.\r\n! RULPTS Real array of dimension WTLENG.\r\n! The number of points produced by each generator.\r\n!***REFERENCES S.Eriksen,\r\n! Thesis of the degree cand.scient, Dept. of Informatics,\r\n! Univ. of Bergen, Norway, 1984.\r\n\r\n!***ROUTINES CALLED-NONE\r\n!***END PROLOGUE D132RE\r\n\r\n! Global variables\r\n\r\nREAL (dp), INTENT(OUT) :: w(:,:), g(:,:), errcof(:)\r\nREAL (dp), INTENT(OUT) :: rulpts(:)\r\n\r\n! Dimensions:\r\n! w(5,wtleng), g(2,wtleng), errcof(6), rulpts(wtleng)\r\n\r\n! Local variables.\r\n\r\nINTEGER :: i, j\r\nREAL (dp), PARAMETER :: dim2g(16) = (/ 0.2517129343453109D+00, &\r\n 0.7013933644534266D+00, 0.9590960631619962D+00, 0.9956010478552127D+00, &\r\n 0.5000000000000000D+00, 0.1594544658297559D+00, 0.3808991135940188D+00, &\r\n 0.6582769255267192D+00, 0.8761473165029315D+00, 0.9982431840531980D+00, &\r\n 0.9790222658168462D+00, 0.6492284325645389D+00, 0.8727421201131239D+00, &\r\n 0.3582614645881228D+00, 0.5666666666666666D+00, 0.2077777777777778D+00 /)\r\nREAL (dp), PARAMETER :: dim2w(14,5) = RESHAPE( (/ &\r\n0.3379692360134460D-01, &\r\n0.9508589607597761D-01, 0.1176006468056962D+00, &\r\n0.2657774586326950D-01, 0.1701441770200640D-01, &\r\n0.0000000000000000D+00, 0.1626593098637410D-01, &\r\n0.1344892658526199D+00, 0.1328032165460149D+00, &\r\n0.5637474769991870D-01, 0.3908279081310500D-02, &\r\n0.3012798777432150D-01, 0.1030873234689166D+00, 0.6250000000000000D-01, &\r\n\r\n0.3213775489050763D+00, &\r\n- .1767341636743844D+00, 0.7347600537466072D-01, &\r\n- .3638022004364754D-01, 0.2125297922098712D-01, &\r\n0.1460984204026913D+00, 0.1747613286152099D-01, &\r\n0.1444954045641582D+00, 0.1307687976001325D-03, &\r\n0.5380992313941161D-03, 0.1042259576889814D-03, &\r\n- .1401152865045733D-02, 0.8041788181514763D-02, - .1420416552759383D+00, &\r\n\r\n0.3372900883288987D+00, &\r\n- .1644903060344491D+00, 0.7707849911634622D-01, &\r\n- .3804478358506310D-01, 0.2223559940380806D-01, &\r\n0.1480693879765931D+00, 0.4467143702185814D-05, &\r\n0.1508944767074130D+00, 0.3647200107516215D-04, &\r\n0.5777198999013880D-03, 0.1041757313688177D-03, &\r\n- .1452822267047819D-02, 0.8338339968783705D-02, - .1472796329231960D+00, &\r\n\r\n- .8264123822525677D+00, &\r\n0.3065838614094360D+00, 0.2389292538329435D-02, &\r\n- .1343024157997222D+00, 0.8833366840533900D-01, &\r\n0.0000000000000000D+00, 0.9786283074168292D-03, &\r\n- .1319227889147519D+00, 0.7990012200150630D-02, &\r\n0.3391747079760626D-02, 0.2294915718283264D-02, &\r\n- .1358584986119197D-01, 0.4025866859057809D-01, 0.3760268580063992D-02, &\r\n\r\n0.6539094339575232D+00, &\r\n- .2041614154424632D+00, - .1746981515794990D+00, &\r\n0.3937939671417803D-01, 0.6974520545933992D-02, &\r\n0.0000000000000000D+00, 0.6667702171778258D-02, &\r\n0.5512960621544304D-01, 0.5443846381278607D-01, &\r\n0.2310903863953934D-01, 0.1506937747477189D-01, &\r\n- .6057021648901890D-01, 0.4225737654686337D-01, 0.2561989142123099D-01 /), &\r\n (/ 14, 5 /))\r\n\r\n!***FIRST EXECUTABLE STATEMENT D132RE\r\n\r\n! Assign values to W.\r\n\r\nDO i = 1, 14\r\n DO j = 1, 5\r\n w(j,i) = dim2w(i,j)\r\n END DO\r\nEND DO\r\n\r\n! Assign values to G.\r\n\r\nDO i = 1, 2\r\n DO j = 1, 14\r\n g(i,j) = 0.d0\r\n END DO\r\nEND DO\r\ng(1,2) = dim2g(1)\r\ng(1,3) = dim2g(2)\r\ng(1,4) = dim2g(3)\r\ng(1,5) = dim2g(4)\r\ng(1,6) = dim2g(5)\r\ng(1,7) = dim2g(6)\r\ng(2,7) = g(1,7)\r\ng(1,8) = dim2g(7)\r\ng(2,8) = g(1,8)\r\ng(1,9) = dim2g(8)\r\ng(2,9) = g(1,9)\r\ng(1,10) = dim2g(9)\r\ng(2,10) = g(1,10)\r\ng(1,11) = dim2g(10)\r\ng(2,11) = g(1,11)\r\ng(1,12) = dim2g(11)\r\ng(2,12) = dim2g(12)\r\ng(1,13) = dim2g(13)\r\ng(2,13) = dim2g(14)\r\ng(1,14) = dim2g(15)\r\ng(2,14) = dim2g(16)\r\n\r\n! Assign values to RULPTS.\r\n\r\nrulpts(1) = 1\r\nDO i = 2, 11\r\n rulpts(i) = 4\r\nEND DO\r\nrulpts(12) = 8\r\nrulpts(13) = 8\r\nrulpts(14) = 8\r\n\r\n! Assign values to ERRCOF.\r\n\r\nerrcof(1) = 10\r\nerrcof(2) = 10\r\nerrcof(3) = 1.\r\nerrcof(4) = 5.\r\nerrcof(5) = 0.5\r\nerrcof(6) = 0.25\r\n\r\n!***END D132RE\r\n\r\nRETURN\r\nEND SUBROUTINE d132re\r\n\r\n\r\nSUBROUTINE d113re(w, g, errcof, rulpts)\r\n!***BEGIN PROLOGUE D113RE\r\n!***AUTHOR Jarle Berntsen, EDB-senteret,\r\n! University of Bergen, Thormohlens gt. 55,\r\n! N-5008 Bergen, NORWAY\r\n!***PURPOSE D113RE computes abscissas and weights of a 3 dimensional\r\n! integration rule of degree 11.\r\n! Two null rules of degree 9, one null rule of degree 7\r\n! and one null rule of degree 5 to be used in error\r\n! estimation are also computed.\r\n!***DESCRIPTION D113RE will select the correct values of the abscissas\r\n! and corresponding weights for different\r\n! integration rules and null rules and assign them to G\r\n! and W.\r\n! The heuristic error coefficients ERRCOF\r\n! will also be computed.\r\n\r\n\r\n! ON RETURN\r\n\r\n! W Real array of dimension (5,WTLENG).\r\n! The weights for the basic and null rules.\r\n! W(1,1),...,W(1,WTLENG) are weights for the basic rule.\r\n! W(I,1),...,W(I,WTLENG), for I > 1 are null rule weights.\r\n! G Real array of dimension (NDIM,WTLENG).\r\n! The fully symmetric sum generators for the rules.\r\n! G(1,J),...,G(NDIM,J) are the generators for the points\r\n! associated with the the Jth weights.\r\n! ERRCOF Real array of dimension 6.\r\n! Heuristic error coefficients that are used in the\r\n! error estimation in BASRUL.\r\n! RULPTS Real array of dimension WTLENG.\r\n! The number of points used by each generator.\r\n\r\n!***REFERENCES J.Berntsen, Cautious adaptive numerical integration\r\n! over the 3-cube, Reports in Informatics 17, Dept. of\r\n! Inf.,Univ. of Bergen, Norway, 1985.\r\n! J.Berntsen and T.O.Espelid, On the construction of\r\n! higher degree three-dimensional embedded integration\r\n! rules, SIAM J. Numer. Anal.,Vol. 25,No. 1, pp.222-234,\r\n! 1988.\r\n!***ROUTINES CALLED-NONE\r\n!***END PROLOGUE D113RE\r\n\r\n! Global variables.\r\n\r\nREAL (dp), INTENT(OUT) :: w(:, :), g(:,:), errcof(:)\r\nREAL (dp), INTENT(OUT) :: rulpts(:)\r\n\r\n! Dimensions:\r\n! w(5, wtleng), g(3,wtleng), errcof(6), rulpts(wtleng)\r\n\r\n! Local variables.\r\n\r\nINTEGER :: i\r\nREAL (dp) :: dim3g(14) = (/ 0.1900000000000000D+00, 0.5000000000000000D+00, &\r\n 0.7500000000000000D+00, 0.8000000000000000D+00, 0.9949999999999999D+00, &\r\n 0.9987344998351400D+00, 0.7793703685672423D+00, 0.9999698993088767D+00, &\r\n 0.7902637224771788D+00, 0.4403396687650737D+00, 0.4378478459006862D+00, &\r\n 0.9549373822794593D+00, 0.9661093133630748D+00, 0.4577105877763134D+00 /)\r\n\r\nREAL (dp), PARAMETER :: dim3w(13,5) = RESHAPE( (/ &\r\n0.7923078151105734D-02, &\r\n0.6797177392788080D-01, 0.1086986538805825D-02, &\r\n0.1838633662212829D+00, 0.3362119777829031D-01, &\r\n0.1013751123334062D-01, 0.1687648683985235D-02, &\r\n0.1346468564512807D+00, 0.1750145884600386D-02, &\r\n0.7752336383837454D-01, 0.2461864902770251D+00, &\r\n0.6797944868483039D-01, 0.1419962823300713D-01, &\r\n\r\n0.1715006248224684D+01, &\r\n- .3755893815889209D+00, 0.1488632145140549D+00, &\r\n- .2497046640620823D+00, 0.1792501419135204D+00, &\r\n0.3446126758973890D-02, - .5140483185555825D-02, &\r\n0.6536017839876425D-02, - .6513454939229700D-03, &\r\n- .6304672433547204D-02, 0.1266959399788263D-01, &\r\n- .5454241018647931D-02, 0.4826995274768427D-02, &\r\n\r\n0.1936014978949526D+01, &\r\n- .3673449403754268D+00, 0.2929778657898176D-01, &\r\n- .1151883520260315D+00, 0.5086658220872218D-01, &\r\n0.4453911087786469D-01, - .2287828257125900D-01, &\r\n0.2908926216345833D-01, - .2898884350669207D-02, &\r\n- .2805963413307495D-01, 0.5638741361145884D-01, &\r\n- .2427469611942451D-01, 0.2148307034182882D-01, &\r\n\r\n0.5170828195605760D+00, &\r\n0.1445269144914044D-01, - .3601489663995932D+00, &\r\n0.3628307003418485D+00, 0.7148802650872729D-02, &\r\n- .9222852896022966D-01, 0.1719339732471725D-01, &\r\n- .1021416537460350D+00, - .7504397861080493D-02, &\r\n0.1648362537726711D-01, 0.5234610158469334D-01, &\r\n0.1445432331613066D-01, 0.3019236275367777D-02, &\r\n\r\n0.2054404503818520D+01, &\r\n0.1377759988490120D-01, - .5768062917904410D+00, &\r\n0.3726835047700328D-01, 0.6814878939777219D-02, &\r\n0.5723169733851849D-01, - .4493018743811285D-01, &\r\n0.2729236573866348D-01, 0.3547473950556990D-03, &\r\n0.1571366799739551D-01, 0.4990099219278567D-01, &\r\n0.1377915552666770D-01, 0.2878206423099872D-02 /), (/ 13, 5 /))\r\n\r\n!***FIRST EXECUTABLE STATEMENT D113RE\r\n\r\n! Assign values to W.\r\n\r\nDO i = 1, 13\r\n w(1:5,i) = dim3w(i,1:5)\r\nEND DO\r\n\r\n! Assign values to G.\r\n\r\ng = 0._dp\r\ng(1,2) = dim3g(1)\r\ng(1,3) = dim3g(2)\r\ng(1,4) = dim3g(3)\r\ng(1,5) = dim3g(4)\r\ng(1,6) = dim3g(5)\r\ng(1,7) = dim3g(6)\r\ng(2,7) = g(1,7)\r\ng(1,8) = dim3g(7)\r\ng(2,8) = g(1,8)\r\ng(1,9) = dim3g(8)\r\ng(2,9) = g(1,9)\r\ng(3,9) = g(1,9)\r\ng(1,10) = dim3g(9)\r\ng(2,10) = g(1,10)\r\ng(3,10) = g(1,10)\r\ng(1,11) = dim3g(10)\r\ng(2,11) = g(1,11)\r\ng(3,11) = g(1,11)\r\ng(1,12) = dim3g(12)\r\ng(2,12) = dim3g(11)\r\ng(3,12) = g(2,12)\r\ng(1,13) = dim3g(13)\r\ng(2,13) = g(1,13)\r\ng(3,13) = dim3g(14)\r\n\r\n! Assign values to RULPTS.\r\n\r\nrulpts(1) = 1\r\nrulpts(2) = 6\r\nrulpts(3) = 6\r\nrulpts(4) = 6\r\nrulpts(5) = 6\r\nrulpts(6) = 6\r\nrulpts(7) = 12\r\nrulpts(8) = 12\r\nrulpts(9) = 8\r\nrulpts(10) = 8\r\nrulpts(11) = 8\r\nrulpts(12) = 24\r\nrulpts(13) = 24\r\n\r\n! Assign values to ERRCOF.\r\n\r\nerrcof(1) = 4\r\nerrcof(2) = 4.\r\nerrcof(3) = 0.5\r\nerrcof(4) = 3.\r\nerrcof(5) = 0.5\r\nerrcof(6) = 0.25\r\n\r\n!***END D113RE\r\n\r\nRETURN\r\nEND SUBROUTINE d113re\r\n\r\n\r\nSUBROUTINE d09hre(ndim, wtleng, w, g, errcof, rulpts)\r\n!***BEGIN PROLOGUE D09HRE\r\n!***KEYWORDS basic integration rule, degree 9\r\n!***PURPOSE To initialize a degree 9 basic rule and null rules.\r\n!***AUTHOR Alan Genz, Computer Science Department, Washington\r\n! State University, Pullman, WA 99163-1210 USA\r\n!***LAST MODIFICATION 88-05-20\r\n!***DESCRIPTION D09HRE initializes a degree 9 integration rule,\r\n! two degree 7 null rules, one degree 5 null rule and one\r\n! degree 3 null rule for the hypercube [-1,1]**NDIM.\r\n\r\n! ON ENTRY\r\n\r\n! NDIM Integer.\r\n! Number of variables.\r\n! WTLENG Integer.\r\n! The number of weights in each of the rules.\r\n\r\n! ON RETURN\r\n! W Real array of dimension (5,WTLENG).\r\n! The weights for the basic and null rules.\r\n! W(1,1),...,W(1,WTLENG) are weights for the basic rule.\r\n! W(I,1),...,W(I,WTLENG), for I > 1 are null rule weights.\r\n! G Real array of dimension (NDIM, WTLENG).\r\n! The fully symmetric sum generators for the rules.\r\n! G(1, J), ..., G(NDIM, J) are the are the generators for the\r\n! points associated with the Jth weights.\r\n! ERRCOF Real array of dimension 6.\r\n! Heuristic error coefficients that are used in the\r\n! error estimation in BASRUL.\r\n! RULPTS Real array of dimension WTLENG.\r\n! A work array.\r\n\r\n!***REFERENCES A. Genz and A. Malik,\r\n! \"An Imbedded Family of Fully Symmetric Numerical\r\n! Integration Rules\",\r\n! SIAM J Numer. Anal. 20 (1983), pp. 580-588.\r\n!***ROUTINES CALLED-NONE\r\n!***END PROLOGUE D09HRE\r\n\r\n! Global variables\r\n\r\nINTEGER, INTENT(IN) :: ndim, wtleng\r\nREAL (dp), INTENT(OUT) :: w(:,:), g(:,:), errcof(:)\r\nREAL (dp), INTENT(OUT) :: rulpts(:)\r\n\r\n! Dimensions:\r\n! w(5,wtleng), g(ndim,wtleng), errcof(6), rulpts(wtleng)\r\n\r\n! Local Variables\r\n\r\nREAL (dp) :: ratio, lam0, lam1, lam2, lam3, lamp, twondm\r\nINTEGER :: i, j\r\n\r\n!***FIRST EXECUTABLE STATEMENT D09HRE\r\n\r\n\r\n! Initialize generators, weights and RULPTS\r\n\r\nDO j = 1, wtleng\r\n DO i = 1, ndim\r\n g(i,j) = 0\r\n END DO\r\n DO i = 1, 5\r\n w(i,j) = 0\r\n END DO\r\n rulpts(j) = 2*ndim\r\nEND DO\r\ntwondm = 2**ndim\r\nrulpts(wtleng) = twondm\r\nIF (ndim > 2) rulpts(8) = (4*ndim* (ndim-1)* (ndim-2))/3\r\nrulpts(7) = 4*ndim* (ndim-1)\r\nrulpts(6) = 2*ndim* (ndim-1)\r\nrulpts(1) = 1\r\n\r\n! Compute squared generator parameters\r\n\r\nlam0 = 0.4707\r\nlam1 = 4/ (15-5/lam0)\r\nratio = (1-lam1/lam0)/27\r\nlam2 = (5-7*lam1-35*ratio)/ (7-35*lam1/3-35*ratio/lam0)\r\nratio = ratio* (1-lam2/lam0)/3\r\nlam3 = (7-9* (lam2+lam1)+63*lam2*lam1/5-63*ratio)/ &\r\n (9-63* (lam2+lam1)/5+21*lam2*lam1-63*ratio/lam0)\r\nlamp = 0.0625\r\n\r\n! Compute degree 9 rule weights\r\n\r\nw(1,wtleng) = 1/ (3*lam0)**4/twondm\r\nIF (ndim > 2) w(1,8) = (1-1/ (3*lam0)) / (6*lam1)**3\r\nw(1,7) = (1-7* (lam0+lam1)/5+7*lam0*lam1/3) / &\r\n (84*lam1*lam2* (lam2-lam0)* (lam2-lam1))\r\nw(1,6) = (1-7* (lam0+lam2)/5+7*lam0*lam2/3) / &\r\n (84*lam1*lam1* (lam1-lam0)* (lam1-lam2)) - w(1,7)*lam2/lam1 &\r\n - 2* (ndim-2)*w(1,8)\r\nw(1,4) = (1-9* ((lam0+lam1+lam2) /7 - (lam0*lam1+lam0*lam2+ &\r\n lam1*lam2)/5)-3*lam0*lam1*lam2)/ &\r\n (18*lam3* (lam3-lam0)* (lam3-lam1)* (lam3-lam2))\r\nw(1,3) = (1-9* ((lam0+lam1+lam3)/7- (lam0*lam1+lam0*lam3+ &\r\n lam1*lam3)/5)-3*lam0*lam1*lam3)/ &\r\n (18*lam2* (lam2-lam0)* (lam2-lam1)* (lam2-lam3)) -2* (ndim-1)*w(1,7)\r\nw(1,2) = (1-9* ((lam0+lam2+lam3)/7- (lam0*lam2+lam0*lam3+ &\r\n lam2*lam3)/5)-3*lam0*lam2*lam3) / &\r\n (18*lam1* (lam1-lam0)* (lam1-lam2)* (lam1-lam3)) - &\r\n 2* (ndim-1)* (w(1,7)+w(1,6)+ (ndim-2)*w(1,8))\r\n\r\n! Compute weights for 2 degree 7, 1 degree 5 and 1 degree 3 rules\r\n\r\nw(2,wtleng) = 1/ (108*lam0**4)/twondm\r\nIF (ndim > 2) w(2,8) = (1-27*twondm*w(2,9)*lam0**3)/ (6*lam1)**3\r\nw(2,7) = (1-5*lam1/3-15*twondm*w(2,wtleng)*lam0**2* (lam0-lam1))/ &\r\n (60*lam1*lam2* (lam2-lam1))\r\nw(2,6) = (1-9* (8*lam1*lam2*w(2,7)+twondm*w(2,wtleng)*lam0**2))/ &\r\n (36*lam1*lam1) - 2*w(2,8)* (ndim-2)\r\nw(2,4) = (1-7* ((lam1+lam2)/5-lam1*lam2/3+twondm*w(2,wtleng)*lam0* &\r\n (lam0-lam1)* (lam0-lam2)))/(14*lam3* (lam3-lam1)* (lam3-lam2))\r\nw(2,3) = (1-7* ((lam1+lam3)/5-lam1*lam3/3+twondm*w(2,wtleng)*lam0* &\r\n (lam0-lam1)* (lam0-lam3)))/ (14*lam2* (lam2-lam1)* (lam2-lam3)) &\r\n - 2* (ndim-1)*w(2,7)\r\nw(2,2) = (1-7* ((lam2+lam3)/5-lam2*lam3/3+twondm*w(2,wtleng)*lam0* &\r\n (lam0-lam2)* (lam0-lam3)))/ (14*lam1* (lam1-lam2)* (lam1-lam3)) - &\r\n 2* (ndim-1)* (w(2,7)+w(2,6)+ (ndim-2)*w(2,8))\r\nw(3,wtleng) = 5/ (324*lam0**4)/twondm\r\nIF (ndim > 2) w(3,8) = (1-27*twondm*w(3,9)*lam0**3)/ (6*lam1)**3\r\nw(3,7) = (1-5*lam1/3-15*twondm*w(3,wtleng)*lam0**2* (lam0-lam1))/ &\r\n (60*lam1*lam2* (lam2-lam1))\r\nw(3,6) = (1-9* (8*lam1*lam2*w(3,7)+twondm*w(3,wtleng)*lam0**2))/ &\r\n (36*lam1*lam1) - 2*w(3,8)* (ndim-2)\r\nw(3,5) = (1-7* ((lam1+lam2)/5-lam1*lam2/3+twondm*w(3,wtleng)*lam0* &\r\n (lam0-lam1)* (lam0-lam2)))/(14*lamp* (lamp-lam1)* (lamp-lam2))\r\nw(3,3) = (1-7* ((lam1+lamp)/5-lam1*lamp/3+twondm*w(3,wtleng)*lam0* &\r\n (lam0-lam1)* (lam0-lamp)))/ &\r\n (14*lam2* (lam2-lam1)* (lam2-lamp)) - 2* (ndim-1)*w(3,7)\r\nw(3,2) = (1-7* ((lam2+lamp)/5-lam2*lamp/3+twondm*w(3,wtleng)*lam0* &\r\n (lam0-lam2)* (lam0-lamp)))/ (14*lam1* (lam1-lam2)* (lam1-lamp)) - &\r\n 2* (ndim-1)* (w(3,7)+w(3,6)+ (ndim-2)*w(3,8))\r\nw(4,wtleng) = 2/ (81*lam0**4)/twondm\r\nIF (ndim > 2) w(4,8) = (2-27*twondm*w(4,9)*lam0**3)/ (6*lam1)**3\r\nw(4,7) = (2-15*lam1/9-15*twondm*w(4,wtleng)*lam0* (lam0-lam1))/ &\r\n (60*lam1*lam2* (lam2-lam1))\r\nw(4,6) = (1-9* (8*lam1*lam2*w(4,7)+twondm*w(4,wtleng)*lam0**2))/ &\r\n (36*lam1*lam1) - 2*w(4,8)* (ndim-2)\r\nw(4,4) = (2-7* ((lam1+lam2)/5-lam1*lam2/3+twondm*w(4,wtleng)*lam0* &\r\n (lam0-lam1)* (lam0-lam2)))/(14*lam3* (lam3-lam1)* (lam3-lam2))\r\nw(4,3) = (2-7* ((lam1+lam3)/5-lam1*lam3/3+twondm*w(4,wtleng)*lam0* &\r\n (lam0-lam1)* (lam0-lam3)))/ &\r\n (14*lam2* (lam2-lam1)* (lam2-lam3)) - 2* (ndim-1)*w(4,7)\r\nw(4,2) = (2-7* ((lam2+lam3)/5-lam2*lam3/3+twondm*w(4,wtleng)*lam0* &\r\n (lam0-lam2)* (lam0-lam3)))/ (14*lam1* (lam1-lam2)* (lam1-lam3)) - &\r\n 2* (ndim-1)* (w(4,7)+w(4,6)+ (ndim-2)*w(4,8))\r\nw(5,2) = 1/ (6*lam1)\r\n\r\n! Set generator values\r\n\r\nlam0 = SQRT(lam0)\r\nlam1 = SQRT(lam1)\r\nlam2 = SQRT(lam2)\r\nlam3 = SQRT(lam3)\r\nlamp = SQRT(lamp)\r\nDO i = 1, ndim\r\n g(i,wtleng) = lam0\r\nEND DO\r\nIF (ndim > 2) THEN\r\n g(1,8) = lam1\r\n g(2,8) = lam1\r\n g(3,8) = lam1\r\nEND IF\r\ng(1,7) = lam1\r\ng(2,7) = lam2\r\ng(1,6) = lam1\r\ng(2,6) = lam1\r\ng(1,5) = lamp\r\ng(1,4) = lam3\r\ng(1,3) = lam2\r\ng(1,2) = lam1\r\n\r\n! Compute final weight values.\r\n! The null rule weights are computed from differences between\r\n! the degree 9 rule weights and lower degree rule weights.\r\n\r\nw(1,1) = twondm\r\nDO j = 2, 5\r\n DO i = 2, wtleng\r\n w(j,i) = w(j,i) - w(1,i)\r\n w(j,1) = w(j,1) - rulpts(i)*w(j,i)\r\n END DO\r\nEND DO\r\nDO i = 2, wtleng\r\n w(1,i) = twondm*w(1,i)\r\n w(1,1) = w(1,1) - rulpts(i)*w(1,i)\r\nEND DO\r\n\r\n! Set error coefficients\r\n\r\nerrcof(1) = 5\r\nerrcof(2) = 5\r\nerrcof(3) = 1.\r\nerrcof(4) = 5\r\nerrcof(5) = 0.5\r\nerrcof(6) = 0.25\r\n\r\n!***END D09HRE\r\n\r\nRETURN\r\nEND SUBROUTINE d09hre\r\n\r\n\r\nSUBROUTINE d07hre(ndim, wtleng, w, g, errcof, rulpts)\r\n!***BEGIN PROLOGUE D07HRE\r\n!***KEYWORDS basic integration rule, degree 7\r\n!***PURPOSE To initialize a degree 7 basic rule, and null rules.\r\n!***AUTHOR Alan Genz, Computer Science Department, Washington\r\n! State University, Pullman, WA 99163-1210 USA\r\n!***LAST MODIFICATION 88-05-31\r\n!***DESCRIPTION D07HRE initializes a degree 7 integration rule,\r\n! two degree 5 null rules, one degree 3 null rule and one\r\n! degree 1 null rule for the hypercube [-1,1]**NDIM.\r\n\r\n! ON ENTRY\r\n\r\n! NDIM Integer.\r\n! Number of variables.\r\n! WTLENG Integer.\r\n! The number of weights in each of the rules.\r\n! WTLENG MUST be set equal to 6.\r\n\r\n! ON RETURN\r\n! W Real array of dimension (5,WTLENG).\r\n! The weights for the basic and null rules.\r\n! W(1,1),...,W(1,WTLENG) are weights for the basic rule.\r\n! W(I,1),...,W(I,WTLENG), for I > 1 are null rule weights.\r\n! G Real array of dimension (NDIM, WTLENG).\r\n! The fully symmetric sum generators for the rules.\r\n! G(1, J), ..., G(NDIM, J) are the are the generators for the\r\n! points associated with the Jth weights.\r\n! ERRCOF Real array of dimension 6.\r\n! Heuristic error coefficients that are used in the\r\n! error estimation in BASRUL.\r\n! RULPTS Real array of dimension WTLENG.\r\n! A work array.\r\n\r\n!***REFERENCES A. Genz and A. Malik,\r\n! \"An Imbedded Family of Fully Symmetric Numerical\r\n! Integration Rules\",\r\n! SIAM J Numer. Anal. 20 (1983), pp. 580-588.\r\n!***ROUTINES CALLED-NONE\r\n!***END PROLOGUE D07HRE\r\n\r\n! Global variables\r\n\r\nINTEGER, INTENT(IN) :: ndim, wtleng\r\nREAL (dp), INTENT(OUT) :: w(:,:), g(:,:), errcof(:)\r\nREAL (dp), INTENT(OUT) :: rulpts(:)\r\n\r\n! Dimensions:\r\n! w(5,wtleng), g(ndim,wtleng), errcof(6), rulpts(wtleng)\r\n\r\n! Local Variables\r\n\r\nREAL (dp) :: ratio, lam0, lam1, lam2, lamp, twondm\r\nINTEGER :: i, j\r\n\r\n!***FIRST EXECUTABLE STATEMENT D07HRE\r\n\r\n\r\n! Initialize generators, weights and RULPTS\r\n\r\nDO j = 1, wtleng\r\n DO i = 1, ndim\r\n g(i,j) = 0\r\n END DO\r\n DO i = 1, 5\r\n w(i,j) = 0\r\n END DO\r\n rulpts(j) = 2*ndim\r\nEND DO\r\ntwondm = 2**ndim\r\nrulpts(wtleng) = twondm\r\nrulpts(wtleng-1) = 2*ndim* (ndim-1)\r\nrulpts(1) = 1\r\n\r\n! Compute squared generator parameters\r\n\r\nlam0 = 0.4707\r\nlamp = 0.5625\r\nlam1 = 4/ (15-5/lam0)\r\nratio = (1-lam1/lam0)/27\r\nlam2 = (5-7*lam1-35*ratio)/ (7-35*lam1/3-35*ratio/lam0)\r\n\r\n! Compute degree 7 rule weights\r\n\r\nw(1,6) = 1/ (3*lam0)**3/twondm\r\nw(1,5) = (1-5*lam0/3)/ (60* (lam1-lam0)*lam1**2)\r\nw(1,3) = (1-5*lam2/3-5*twondm*w(1,6)*lam0* (lam0-lam2))/ &\r\n (10*lam1* (lam1-lam2)) - 2* (ndim-1)*w(1,5)\r\nw(1,2) = (1-5*lam1/3-5*twondm*w(1,6)*lam0* (lam0-lam1))/(10*lam2* (lam2-lam1))\r\n\r\n! Compute weights for 2 degree 5, 1 degree 3 and 1 degree 1 rules\r\n\r\nw(2,6) = 1/ (36*lam0**3)/twondm\r\nw(2,5) = (1-9*twondm*w(2,6)*lam0**2)/ (36*lam1**2)\r\nw(2,3) = (1-5*lam2/3-5*twondm*w(2,6)*lam0* (lam0-lam2))/ &\r\n (10*lam1* (lam1-lam2)) - 2* (ndim-1)*w(2,5)\r\nw(2,2) = (1-5*lam1/3-5*twondm*w(2,6)*lam0* (lam0-lam1))/(10*lam2* (lam2-lam1))\r\nw(3,6) = 5/ (108*lam0**3)/twondm\r\nw(3,5) = (1-9*twondm*w(3,6)*lam0**2)/ (36*lam1**2)\r\nw(3,3) = (1-5*lamp/3-5*twondm*w(3,6)*lam0* (lam0-lamp))/ &\r\n (10*lam1* (lam1-lamp)) - 2* (ndim-1)*w(3,5)\r\nw(3,4) = (1-5*lam1/3-5*twondm*w(3,6)*lam0* (lam0-lam1))/(10*lamp* (lamp-lam1))\r\nw(4,6) = 1/ (54*lam0**3)/twondm\r\nw(4,5) = (1-18*twondm*w(4,6)*lam0**2)/ (72*lam1**2)\r\nw(4,3) = (1-10*lam2/3-10*twondm*w(4,6)*lam0* (lam0-lam2))/ &\r\n (20*lam1* (lam1-lam2)) - 2* (ndim-1)*w(4,5)\r\nw(4,2) = (1-10*lam1/3-10*twondm*w(4,6)*lam0* (lam0-lam1))/ (20*lam2* (lam2-lam1))\r\n\r\n! Set generator values\r\n\r\nlam0 = SQRT(lam0)\r\nlam1 = SQRT(lam1)\r\nlam2 = SQRT(lam2)\r\nlamp = SQRT(lamp)\r\nDO i = 1, ndim\r\n g(i,wtleng) = lam0\r\nEND DO\r\ng(1,wtleng-1) = lam1\r\ng(2,wtleng-1) = lam1\r\ng(1,wtleng-4) = lam2\r\ng(1,wtleng-3) = lam1\r\ng(1,wtleng-2) = lamp\r\n\r\n! Compute final weight values.\r\n! The null rule weights are computed from differences between\r\n! the degree 7 rule weights and lower degree rule weights.\r\n\r\nw(1,1) = twondm\r\nDO j = 2, 5\r\n DO i = 2, wtleng\r\n w(j,i) = w(j,i) - w(1,i)\r\n w(j,1) = w(j,1) - rulpts(i)*w(j,i)\r\n END DO\r\nEND DO\r\nDO i = 2, wtleng\r\n w(1,i) = twondm*w(1,i)\r\n w(1,1) = w(1,1) - rulpts(i)*w(1,i)\r\nEND DO\r\n\r\n! Set error coefficients\r\n\r\nerrcof(1) = 5.\r\nerrcof(2) = 5.\r\nerrcof(3) = 1.\r\nerrcof(4) = 5.\r\nerrcof(5) = 0.5\r\nerrcof(6) = 0.25\r\n\r\n!***END D07HRE\r\n\r\nRETURN\r\nEND SUBROUTINE d07hre\r\n\r\n\r\nSUBROUTINE drlhre(ndim, center, hwidth, wtleng, g, w, errcof, numfun, &\r\n funsub, scales, norms, basval, rgnerr, DIRECT)\r\n!***BEGIN PROLOGUE DRLHRE\r\n!***KEYWORDS basic numerical integration rule\r\n!***PURPOSE To compute basic integration rule values.\r\n!***AUTHOR Alan Genz, Computer Science Department, Washington\r\n! State University, Pullman, WA 99163-1210 USA\r\n!***LAST MODIFICATION 90-02-06\r\n!***DESCRIPTION DRLHRE computes basic integration rule values for a\r\n! vector of integrands over a hyper-rectangular region.\r\n! These are estimates for the integrals. DRLHRE also computes\r\n! estimates for the errors and determines the coordinate axis\r\n! where the fourth difference for the integrands is largest.\r\n\r\n! ON ENTRY\r\n\r\n! NDIM Integer.\r\n! Number of variables.\r\n! CENTER Real array of dimension NDIM.\r\n! The coordinates for the center of the region.\r\n! HWIDTH Real Array of dimension NDIM.\r\n! HWIDTH(I) is half of the width of dimension I of the region.\r\n! WTLENG Integer.\r\n! The number of weights in the basic integration rule.\r\n! G Real array of dimension (NDIM,WTLENG).\r\n! The fully symmetric sum generators for the rules.\r\n! G(1,J), ..., G(NDIM,J) are the are the generators for the\r\n! points associated with the Jth weights.\r\n! W Real array of dimension (5,WTLENG).\r\n! The weights for the basic and null rules.\r\n! W(1,1),...,W(1,WTLENG) are weights for the basic rule.\r\n! W(I,1),...,W(I,WTLENG), for I > 1 are null rule weights.\r\n! ERRCOF Real array of dimension 6.\r\n! The error coefficients for the rules.\r\n! It is assumed that the error is computed using:\r\n! IF (N1*ERRCOF(1) < N2 and N2*ERRCOF(2) < N3)\r\n! THEN ERROR = ERRCOF(3)*N1\r\n! ELSE ERROR = ERRCOF(4)*MAX(N1, N2, N3)\r\n! ERROR = ERROR + EP*(ERRCOF(5)*ERROR/(ES+ERROR)+ERRCOF(6))\r\n! where N1-N4 are the null rules, EP is the error\r\n! for the parent\r\n! subregion and ES is the error for the sibling subregion.\r\n! NUMFUN Integer.\r\n! Number of components for the vector integrand.\r\n! FUNSUB Externally declared subroutine.\r\n! For computing the components of the integrand at a point X.\r\n! It must have parameters (NDIM,X,NUMFUN,FUNVLS).\r\n! Input Parameters:\r\n! X Real array of dimension NDIM.\r\n! Defines the evaluation point.\r\n! NDIM Integer.\r\n! Number of variables for the integrand.\r\n! NUMFUN Integer.\r\n! Number of components for the vector integrand.\r\n! Output Parameters:\r\n! FUNVLS Real array of dimension NUMFUN.\r\n! The components of the integrand at the point X.\r\n! SCALES Real array of dimension (3,WTLENG).\r\n! Scaling factors used to construct new null rules based\r\n! on a linear combination of two successive null rules\r\n! in the sequence of null rules.\r\n! NORMS Real array of dimension (3,WTLENG).\r\n! 2**NDIM/(1-norm of the null rule constructed by each of the\r\n! scaling factors.)\r\n\r\n! ON RETURN\r\n\r\n! BASVAL Real array of dimension NUMFUN.\r\n! The values for the basic rule for each component\r\n! of the integrand.\r\n! RGNERR Real array of dimension NUMFUN.\r\n! The error estimates for each component of the integrand.\r\n! DIRECT Real.\r\n! The coordinate axis where the fourth difference of the\r\n! integrand values is largest.\r\n\r\n!***REFERENCES\r\n! A.C.Genz and A.A.Malik, An adaptive algorithm for numerical\r\n! integration over an N-dimensional rectangular region,\r\n! J.Comp.Appl.Math., 6:295-302, 1980.\r\n\r\n! T.O.Espelid, Integration Rules, Null Rules and Error\r\n! Estimation, Reports in Informatics 33, Dept. of Informatics,\r\n! Univ. of Bergen, 1988.\r\n\r\n!***ROUTINES CALLED: DFSHRE, FUNSUB\r\n\r\n!***END PROLOGUE DRLHRE\r\n\r\n! Global variables.\r\n\r\nINTEGER, INTENT(IN) :: wtleng, numfun, ndim\r\nREAL (dp), INTENT(IN) :: center(:), hwidth(:), w(:,:), errcof(:), &\r\n scales(:,:), norms(:,:)\r\nREAL (dp), INTENT(IN OUT) :: g(:,:)\r\nREAL (dp), INTENT(OUT) :: basval(:), rgnerr(:), DIRECT\r\n\r\n! Dimensions:\r\n! center(ndim), x(ndim), hwidth(ndim), basval(numfun), rgnerr(numfun)\r\n! null(numfun,8), w(5,wtleng), g(ndim,wtleng), errcof(6), scales(3,wtleng)\r\n! norms(3,wtleng)\r\n\r\nINTERFACE\r\n SUBROUTINE funsub(ndim, z, nfun, f)\r\n IMPLICIT NONE\r\n INTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(15, 60)\r\n INTEGER, INTENT(IN) :: ndim, nfun\r\n REAL (dp), INTENT(IN) :: z(:)\r\n REAL (dp), INTENT(OUT) :: f(:)\r\n END SUBROUTINE funsub\r\nEND INTERFACE\r\n\r\n! Local variables.\r\n\r\nREAL (dp) :: rgnvol, difsum, difmax, frthdf, null(numfun,8), x(ndim)\r\nINTEGER :: i, j, k, divaxn\r\nREAL (dp) :: search, ratio\r\n\r\n!***FIRST EXECUTABLE STATEMENT DRLHRE\r\n\r\n\r\n! Compute volume of subregion, initialize DIVAXN and rule sums;\r\n! compute fourth differences and new DIVAXN (RGNERR is used\r\n! for a work array here). The integrand values used for the\r\n! fourth divided differences are accumulated in rule arrays.\r\n\r\nrgnvol = 1\r\ndivaxn = 1\r\nDO i = 1, ndim\r\n rgnvol = rgnvol*hwidth(i)\r\n x(i) = center(i)\r\n IF (hwidth(i) > hwidth(divaxn)) divaxn = i\r\nEND DO\r\nCALL funsub(ndim, x, numfun, rgnerr)\r\nDO j = 1, numfun\r\n basval(j) = w(1,1)*rgnerr(j)\r\n DO k = 1, 4\r\n null(j,k) = w(k+1,1)*rgnerr(j)\r\n END DO\r\nEND DO\r\ndifmax = 0\r\nratio = (g(1,3)/g(1,2))**2\r\nDO i = 1, ndim\r\n x(i) = center(i) - hwidth(i)*g(1,2)\r\n CALL funsub(ndim, x, numfun, null(:,5))\r\n x(i) = center(i) + hwidth(i)*g(1,2)\r\n CALL funsub(ndim, x, numfun, null(:,6))\r\n x(i) = center(i) - hwidth(i)*g(1,3)\r\n CALL funsub(ndim, x, numfun, null(:,7))\r\n x(i) = center(i) + hwidth(i)*g(1,3)\r\n CALL funsub(ndim, x, numfun, null(:,8))\r\n x(i) = center(i)\r\n difsum = 0\r\n DO j = 1, numfun\r\n frthdf = 2* (1-ratio)*rgnerr(j) - (null(j,7)+null(j,8)) + &\r\n ratio* (null(j,5)+null(j,6))\r\n \r\n! Ignore differences below roundoff\r\n \r\n IF (rgnerr(j)+frthdf/4 /= rgnerr(j)) difsum = difsum + ABS(frthdf)\r\n DO k = 1, 4\r\n null(j,k) = null(j,k) + w(k+1,2)*(null(j,5)+null(j,6)) + &\r\n w(k+1,3)* (null(j,7)+null(j,8))\r\n END DO\r\n basval(j) = basval(j) + w(1,2)* (null(j,5)+null(j,6)) + &\r\n w(1,3)* (null(j,7)+null(j,8))\r\n END DO\r\n IF (difsum > difmax) THEN\r\n difmax = difsum\r\n divaxn = i\r\n END IF\r\nEND DO\r\nDIRECT = divaxn\r\n\r\n! Finish computing the rule values.\r\n\r\nDO i = 4, wtleng\r\n CALL dfshre(ndim, center, hwidth, x, g(:,i), numfun, funsub, rgnerr, &\r\n null(:,5))\r\n DO j = 1, numfun\r\n basval(j) = basval(j) + w(1,i)*rgnerr(j)\r\n DO k = 1, 4\r\n null(j,k) = null(j,k) + w(k+1,i)*rgnerr(j)\r\n END DO\r\n END DO\r\nEND DO\r\n\r\n! Compute errors.\r\n\r\nDO j = 1, numfun\r\n \r\n! We search for the null rule, in the linear space spanned by two\r\n! successive null rules in our sequence, which gives the greatest\r\n! error estimate among all normalized (1-norm) null rules in this\r\n! space.\r\n \r\n DO i = 1, 3\r\n search = 0\r\n DO k = 1, wtleng\r\n search = MAX(search, ABS(null(j,i+1)+scales(i,k)*null(j,i))*norms(i,k))\r\n END DO\r\n null(j,i) = search\r\n END DO\r\n IF (errcof(1)*null(j,1) <= null(j,2) .AND. &\r\n errcof(2)*null(j,2) <= null(j,3)) THEN\r\n rgnerr(j) = errcof(3)*null(j,1)\r\n ELSE\r\n rgnerr(j) = errcof(4)*MAX(null(j,1), null(j,2), null(j,3))\r\n END IF\r\n rgnerr(j) = rgnvol*rgnerr(j)\r\n basval(j) = rgnvol*basval(j)\r\nEND DO\r\n\r\n!***END DRLHRE\r\n\r\nRETURN\r\nEND SUBROUTINE drlhre\r\n\r\n\r\nSUBROUTINE dfshre(ndim, center, hwidth, x, g, numfun, funsub, fulsms, funvls)\r\n!***BEGIN PROLOGUE DFSHRE\r\n!***KEYWORDS fully symmetric sum\r\n!***PURPOSE To compute fully symmetric basic rule sums\r\n!***AUTHOR Alan Genz, Computer Science Department, Washington\r\n! State University, Pullman, WA 99163-1210 USA\r\n!***LAST MODIFICATION 88-04-08\r\n!***DESCRIPTION DFSHRE computes a fully symmetric sum for a vector\r\n! of integrand values over a hyper-rectangular region.\r\n! The sum is fully symmetric with respect to the center of\r\n! the region and is taken over all sign changes and\r\n! permutations of the generators for the sum.\r\n\r\n! ON ENTRY\r\n\r\n! NDIM Integer.\r\n! Number of variables.\r\n! CENTER Real array of dimension NDIM.\r\n! The coordinates for the center of the region.\r\n! HWIDTH Real Array of dimension NDIM.\r\n! HWIDTH(I) is half of the width of dimension I of the region.\r\n! X Real Array of dimension NDIM.\r\n! A work array.\r\n! G Real Array of dimension NDIM.\r\n! The generators for the fully symmetric sum. These MUST BE\r\n! non-negative and non-increasing.\r\n! NUMFUN Integer.\r\n! Number of components for the vector integrand.\r\n! FUNSUB Externally declared subroutine.\r\n! For computing the components of the integrand at a point X.\r\n! It must have parameters (NDIM, X, NUMFUN, FUNVLS).\r\n! Input Parameters:\r\n! X Real array of dimension NDIM.\r\n! Defines the evaluation point.\r\n! NDIM Integer.\r\n! Number of variables for the integrand.\r\n! NUMFUN Integer.\r\n! Number of components for the vector integrand.\r\n! Output Parameters:\r\n! FUNVLS Real array of dimension NUMFUN.\r\n! The components of the integrand at the point X.\r\n! ON RETURN\r\n\r\n! FULSMS Real array of dimension NUMFUN.\r\n! The values for the fully symmetric sums for each component\r\n! of the integrand.\r\n! FUNVLS Real array of dimension NUMFUN.\r\n! A work array.\r\n\r\n!***ROUTINES CALLED: FUNSUB\r\n\r\n!***END PROLOGUE DFSHRE\r\n\r\n! Global variables.\r\n\r\nINTEGER, INTENT(IN) :: ndim, numfun\r\nREAL (dp), INTENT(IN) :: center(:), hwidth(:)\r\nREAL (dp), INTENT(IN OUT) :: x(:), g(:)\r\nREAL (dp), INTENT(OUT) :: fulsms(:), funvls(:)\r\n\r\nINTERFACE\r\n SUBROUTINE funsub(ndim, z, nfun, f)\r\n IMPLICIT NONE\r\n INTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(15, 60)\r\n INTEGER, INTENT(IN) :: ndim, nfun\r\n REAL (dp), INTENT(IN) :: z(:)\r\n REAL (dp), INTENT(OUT) :: f(:)\r\n END SUBROUTINE funsub\r\nEND INTERFACE\r\n\r\n! Local variables.\r\n\r\nINTEGER :: ixchng, lxchng, i, j, l\r\nREAL (dp) :: gl, gi\r\n\r\n!***FIRST EXECUTABLE STATEMENT DFSHRE\r\n\r\nfulsms(1:numfun) = 0\r\n\r\n! Compute centrally symmetric sum for permutation of G\r\n\r\n20 DO i = 1, ndim\r\n x(i) = center(i) + g(i)*hwidth(i)\r\nEND DO\r\n40 CALL funsub(ndim, x, numfun, funvls)\r\nDO j = 1, numfun\r\n fulsms(j) = fulsms(j) + funvls(j)\r\nEND DO\r\nDO i = 1, ndim\r\n g(i) = - g(i)\r\n x(i) = center(i) + g(i)*hwidth(i)\r\n IF (g(i) < 0) GO TO 40\r\nEND DO\r\n\r\n! Find next distinct permutation of G and loop back for next sum.\r\n! Permutations are generated in reverse lexicographic order.\r\n\r\nDO i = 2, ndim\r\n IF (g(i-1) > g(i)) THEN\r\n gi = g(i)\r\n ixchng = i - 1\r\n DO l = 1, (i-1)/2\r\n gl = g(l)\r\n g(l) = g(i-l)\r\n g(i-l) = gl\r\n IF (gl <= gi) ixchng = ixchng - 1\r\n IF (g(l) > gi) lxchng = l\r\n END DO\r\n IF (g(ixchng) <= gi) ixchng = lxchng\r\n g(i) = g(ixchng)\r\n g(ixchng) = gi\r\n GO TO 20\r\n END IF\r\nEND DO\r\n\r\n! Restore original order to generators\r\n\r\nDO i = 1, ndim/2\r\n gi = g(i)\r\n g(i) = g(ndim-i+1)\r\n g(ndim-i+1) = gi\r\nEND DO\r\n\r\n!***END DFSHRE\r\n\r\nRETURN\r\nEND SUBROUTINE dfshre\r\n\r\n\r\nSUBROUTINE dtrhre(dvflag, ndim, numfun, sbrgns, values, errors, centrs, &\r\n hwidts, greate, center, hwidth, dir)\r\n!***BEGIN PROLOGUE DTRHRE\r\n!***PURPOSE DTRHRE maintains a heap of subregions.\r\n!***DESCRIPTION DTRHRE maintains a heap of subregions.\r\n! The subregions are ordered according to the size\r\n! of the greatest error estimates of each subregion(GREATE).\r\n\r\n! PARAMETERS\r\n\r\n! DVFLAG Integer.\r\n! If DVFLAG = 1, we remove the subregion with\r\n! greatest error from the heap.\r\n! If DVFLAG = 2, we insert a new subregion in the heap.\r\n! NDIM Integer.\r\n! Number of variables.\r\n! NUMFUN Integer.\r\n! Number of components of the integral.\r\n! SBRGNS Integer.\r\n! Number of subregions in the heap.\r\n! VALUES Real array of dimension (NUMFUN,SBRGNS).\r\n! Used to store estimated values of the integrals\r\n! over the subregions.\r\n! ERRORS Real array of dimension (NUMFUN,SBRGNS).\r\n! Used to store the corresponding estimated errors.\r\n! CENTRS Real array of dimension (NDIM,SBRGNS).\r\n! Used to store the center limits of the stored subregions.\r\n! HWIDTS Real array of dimension (NDIM,SBRGNS).\r\n! Used to store the hwidth limits of the stored subregions.\r\n! GREATE Real array of dimension SBRGNS.\r\n! Used to store the greatest estimated errors in all subregions.\r\n! CENTER Real array of dimension NDIM.\r\n! Used as intermediate storage for the center of the subregion.\r\n! HWIDTH Real array of dimension NDIM.\r\n! Used as intermediate storage for the half width of the subregion.\r\n! DIR Integer array of dimension SBRGNS.\r\n! DIR is used to store the directions for further subdivision.\r\n\r\n!***ROUTINES CALLED-NONE\r\n!***END PROLOGUE DTRHRE\r\n\r\n! Global variables.\r\n\r\nINTEGER, INTENT(IN) :: dvflag, ndim, numfun\r\nINTEGER, INTENT(IN OUT) :: sbrgns\r\nREAL (dp), INTENT(IN OUT) :: values(:,:), errors(:,:)\r\nREAL (dp), INTENT(IN OUT) :: centrs(:,:)\r\nREAL (dp), INTENT(IN OUT) :: hwidts(:,:)\r\nREAL (dp), INTENT(IN OUT) :: greate(:)\r\nREAL (dp), INTENT(IN OUT) :: center(:), hwidth(:)\r\nREAL (dp), INTENT(IN OUT) :: dir(:)\r\n\r\n! Dimensions:\r\n! values(numfun,*), errors(numfun,*), centrs(ndim,*), hwidts(ndim,*)\r\n! center(ndim), hwidth(ndim)\r\n\r\n! Local variables.\r\n\r\n! GREAT is used as intermediate storage for the greatest error of a\r\n! subregion.\r\n! DIRECT is used as intermediate storage for the direction of further\r\n! subdivision.\r\n! SUBRGN Position of child/parent subregion in the heap.\r\n! SUBTMP Position of parent/child subregion in the heap.\r\n\r\nINTEGER :: j, subrgn, subtmp\r\nREAL (dp) :: great, DIRECT, error(numfun), value(numfun)\r\n\r\n!***FIRST EXECUTABLE STATEMENT DTRHRE\r\n\r\n! Save values to be stored in their correct place in the heap.\r\n\r\ngreat = greate(sbrgns)\r\nDIRECT = dir(sbrgns)\r\nDO j = 1, numfun\r\n error(j) = errors(j,sbrgns)\r\n value(j) = values(j,sbrgns)\r\nEND DO\r\nDO j = 1, ndim\r\n center(j) = centrs(j,sbrgns)\r\n hwidth(j) = hwidts(j,sbrgns)\r\nEND DO\r\n\r\n! If DVFLAG = 1, we will remove the region\r\n! with greatest estimated error from the heap.\r\n\r\nIF (dvflag == 1) THEN\r\n sbrgns = sbrgns - 1\r\n subrgn = 1\r\n 20 subtmp = 2*subrgn\r\n IF (subtmp <= sbrgns) THEN\r\n IF (subtmp /= sbrgns) THEN\r\n \r\n! Find max. of left and right child.\r\n \r\n IF (greate(subtmp) < greate(subtmp+1)) THEN\r\n subtmp = subtmp + 1\r\n END IF\r\n END IF\r\n \r\n! Compare max.child with parent.\r\n! If parent is max., then done.\r\n \r\n IF (great < greate(subtmp)) THEN\r\n \r\n! Move the values at position subtmp up the heap.\r\n \r\n greate(subrgn) = greate(subtmp)\r\n DO j = 1, numfun\r\n errors(j,subrgn) = errors(j,subtmp)\r\n values(j,subrgn) = values(j,subtmp)\r\n END DO\r\n dir(subrgn) = dir(subtmp)\r\n DO j = 1, ndim\r\n centrs(j,subrgn) = centrs(j,subtmp)\r\n hwidts(j,subrgn) = hwidts(j,subtmp)\r\n END DO\r\n subrgn = subtmp\r\n GO TO 20\r\n END IF\r\n END IF\r\nELSE IF (dvflag == 2) THEN\r\n \r\n! If DVFLAG = 2, then insert new region in the heap.\r\n \r\n subrgn = sbrgns\r\n 40 subtmp = subrgn/2\r\n IF (subtmp >= 1) THEN\r\n \r\n! Compare max.child with parent.\r\n! If parent is max, then done.\r\n \r\n IF (great > greate(subtmp)) THEN\r\n \r\n! Move the values at position subtmp down the heap.\r\n \r\n greate(subrgn) = greate(subtmp)\r\n DO j = 1, numfun\r\n errors(j,subrgn) = errors(j,subtmp)\r\n values(j,subrgn) = values(j,subtmp)\r\n END DO\r\n dir(subrgn) = dir(subtmp)\r\n DO j = 1, ndim\r\n centrs(j,subrgn) = centrs(j,subtmp)\r\n hwidts(j,subrgn) = hwidts(j,subtmp)\r\n END DO\r\n subrgn = subtmp\r\n GO TO 40\r\n END IF\r\n END IF\r\nEND IF\r\n\r\n! Insert the saved values in their correct places.\r\n\r\nIF (sbrgns > 0) THEN\r\n greate(subrgn) = great\r\n DO j = 1, numfun\r\n errors(j,subrgn) = error(j)\r\n values(j,subrgn) = value(j)\r\n END DO\r\n dir(subrgn) = DIRECT\r\n DO j = 1, ndim\r\n centrs(j,subrgn) = center(j)\r\n hwidts(j,subrgn) = hwidth(j)\r\n END DO\r\nEND IF\r\n\r\n!***END DTRHRE\r\n\r\nRETURN\r\nEND SUBROUTINE dtrhre\r\n\r\nEND MODULE multidim_integrate\r\n", "meta": {"hexsha": "1812cfd1c6e6ad742561e2af48e11155f442696d", "size": 78878, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/dcuhre.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/dcuhre.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/dcuhre.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": 34.0284728214, "max_line_length": 82, "alphanum_fraction": 0.5941834225, "num_tokens": 26765, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898102301019, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6705904298009152}} {"text": "!*==idamax.f90 processed by SPAG 7.51RB at 20:37 on 3 Mar 2022\n!> \\brief \\b IDAMAX\n!\n! =========== DOCUMENTATION ===========\n!\n! Online html documentation available at\n! http://www.netlib.org/lapack/explore-html/\n!\n! Definition:\n! ===========\n!\n! INTEGER FUNCTION IDAMAX(N,DX,INCX)\n!\n! .. Scalar Arguments ..\n! INTEGER INCX,N\n! ..\n! .. Array Arguments ..\n! DOUBLE PRECISION DX(*)\n! ..\n!\n!\n!> \\par Purpose:\n! =============\n!>\n!> \\verbatim\n!>\n!> IDAMAX finds the index of the first element having maximum absolute value.\n!> \\endverbatim\n!\n! Arguments:\n! ==========\n!\n!> \\param[in] N\n!> \\verbatim\n!> N is INTEGER\n!> number of elements in input vector(s)\n!> \\endverbatim\n!>\n!> \\param[in] DX\n!> \\verbatim\n!> DX is DOUBLE PRECISION array, dimension ( 1 + ( N - 1 )*abs( INCX ) )\n!> \\endverbatim\n!>\n!> \\param[in] INCX\n!> \\verbatim\n!> INCX is INTEGER\n!> storage spacing between elements of DX\n!> \\endverbatim\n!\n! Authors:\n! ========\n!\n!> \\author Univ. of Tennessee\n!> \\author Univ. of California Berkeley\n!> \\author Univ. of Colorado Denver\n!> \\author NAG Ltd.\n!\n!> \\date November 2017\n!\n!> \\ingroup aux_blas\n!\n!> \\par Further Details:\n! =====================\n!>\n!> \\verbatim\n!>\n!> jack dongarra, linpack, 3/11/78.\n!> modified 3/93 to return if incx .le. 0.\n!> modified 12/3/93, array(1) declarations changed to array(*)\n!> \\endverbatim\n!>\n! =====================================================================\n INTEGER FUNCTION IDAMAX(N,Dx,Incx)\n IMPLICIT NONE\n!*--IDAMAX75\n!\n! -- Reference BLAS level1 routine (version 3.8.0) --\n! -- Reference BLAS is a software package provided by Univ. of Tennessee, --\n! -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n! November 2017\n!\n! .. Scalar Arguments ..\n INTEGER Incx , N\n! ..\n! .. Array Arguments ..\n DOUBLE PRECISION Dx(*)\n! ..\n!\n! =====================================================================\n!\n! .. Local Scalars ..\n DOUBLE PRECISION dmax\n INTEGER i , ix\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC DABS\n! ..\n IDAMAX = 0\n IF ( N<1 .OR. Incx<=0 ) RETURN\n IDAMAX = 1\n IF ( N==1 ) RETURN\n IF ( Incx==1 ) THEN\n!\n! code for increment equal to 1\n!\n dmax = DABS(Dx(1))\n DO i = 2 , N\n IF ( DABS(Dx(i))>dmax ) THEN\n IDAMAX = i\n dmax = DABS(Dx(i))\n ENDIF\n ENDDO\n ELSE\n!\n! code for increment not equal to 1\n!\n ix = 1\n dmax = DABS(Dx(1))\n ix = ix + Incx\n DO i = 2 , N\n IF ( DABS(Dx(ix))>dmax ) THEN\n IDAMAX = i\n dmax = DABS(Dx(ix))\n ENDIF\n ix = ix + Incx\n ENDDO\n ENDIF\n END FUNCTION IDAMAX\n", "meta": {"hexsha": "61697a5cf76f872c7e60b89945dcb49e4da64e13", "size": 2886, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/blas/idamax.f90", "max_stars_repo_name": "urbanjost/spag_lapack", "max_stars_repo_head_hexsha": "1b082638c0ff5feb1a295a3aa4624c538d14847c", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2022-03-04T13:15:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-04T17:40:26.000Z", "max_issues_repo_path": "src/blas/idamax.f90", "max_issues_repo_name": "urbanjost/spag_lapack", "max_issues_repo_head_hexsha": "1b082638c0ff5feb1a295a3aa4624c538d14847c", "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": "src/blas/idamax.f90", "max_forks_repo_name": "urbanjost/spag_lapack", "max_forks_repo_head_hexsha": "1b082638c0ff5feb1a295a3aa4624c538d14847c", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.3720930233, "max_line_length": 81, "alphanum_fraction": 0.48995149, "num_tokens": 870, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.853912760387131, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.6705850223521721}} {"text": " real*8 function bint(f,a,b,epslon,epsabs)\n implicit none\n integer itmax,n,iter,i\n parameter (itmax=30)\n real*8 ,intent(in):: a,b,epslon,epsabs\n real*8 ba,s0,s20,s,xstep,x,s1,s2\n real*8 f\n external f\n\n ba=b-a\n s0=ba*(f(a)+f(b))*.5d0\nc write(*,*)'bint ',a,b,f(a),f(b)\n s20=s0\n n=1\n iter=0\n1 s=0.d0\n xstep=ba/n\n x=a-xstep*.5d0\n do 10 i=1,n\n x=x+xstep\n s=s+f(x)\n10 continue\n s=s*xstep\n s1=(s+s0)*.5d0\n s2=(2.d0*s+s0)/3.d0\nc write(*,*)s2\n if(abs(s2-s20) .lt. max(epslon*abs(s2),epsabs)\n 1 .or. iter .gt. itmax)then\n bint=s2\n if(iter .gt. itmax)then\n write(*,*)'BINT Convergence failed. ',s2,s20\n endif\n return\n endif\n n=n*2\n s0=s1\n s20=s2\n iter=iter+1\n go to 1\n end\n\n real*8 function rombint(f,a,b,epslon,epsabs)\n implicit none\n integer*4 itmax,n,iter,i,k\n parameter (itmax=30,k=5)\n real*8 a,b,epslon,epsabs,ba,s0,s20,s,xstep,x,s1,s2,\n $ h(itmax),y(itmax),ds2\n real*8 f\n external f\n ba=b-a\n s0=ba*(f(a)+f(b))*.5d0\n s20=s0\n h(1)=1.d0\n y(1)=s0\n n=1\n iter=2\n1 s=0.d0\n xstep=ba/n\n x=a-xstep*.5d0\n do i=1,n\n x=x+xstep\n s=s+f(x)\n enddo\n s=s*xstep\n s1=(s+s0)*.5d0\n h(iter)=h(iter-1)*.25d0\n y(iter)=s1\n if(iter .lt. k)then\n s2=(2.d0*s+s0)/3.d0\n if(abs(s2-s20) .lt. max(epslon*abs(s2),epsabs))then\n rombint=s2\n return\n endif\n s20=s2\n else\n call polint(h(iter-k+1),y(iter-k+1),k,0.d0,s2,ds2)\nc write(*,*)iter,s2,ds2\n rombint=s2\n if(abs(ds2) .lt. max(epslon*abs(s2),epsabs))then\n return\n endif\n if(iter .ge. itmax)then\n write(*,*)'ROMBINT Convergence failed. '\n return\n endif\n endif\n s0=s1\n n=n*2\n iter=iter+1\n go to 1\n end\n\n SUBROUTINE polint(xa,ya,n,x,y,dy)\n implicit none\n INTEGER*4 n,NMAX\n PARAMETER (NMAX=10) \n REAL*8 dy,x,y,xa(n),ya(n)\nc Given arrays xa and ya, each of length n, and given a value x, this routine returns a\nc value y, and an error estimate dy. If P(x) is the polynomial of degree N \u2212 1 such that\nc P(xai) = yai, i = 1, . . . , n, then the returned value y = P(x).\n INTEGER*4 i,m,ns\n REAL*8 den,dif,dift,ho,hp,w,c(NMAX),d(NMAX)\n ns=1\n dif=abs(x-xa(1))\n do i=1,n \n dift=abs(x-xa(i))\n if(dift .lt. dif)then\n ns=i\n dif=dift\n endif\n c(i)=ya(i) \n d(i)=ya(i)\n enddo\n y=ya(ns)\n ns=ns-1\n do m=1,n-1\n do i=1,n-m\n ho=xa(i)-x\n hp=xa(i+m)-x\n w=c(i+1)-d(i)\n den=ho-hp\n if(den .eq. 0.d0)then\n write(*,*)'polint failure in polint.'\n endif\n den=w/den\n d(i)=hp*den\n c(i)=ho*den\n enddo\n if(2*ns .lt. n-m)then\n dy=c(ns+1)\n else\n dy=d(ns)\n ns=ns-1\n endif\n y=y+dy\n enddo\n return\n END\n", "meta": {"hexsha": "38ede7dd8125348eb6d3971d5f68f6363e91046f", "size": 3175, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/bint.f", "max_stars_repo_name": "noboruatkek/SAD", "max_stars_repo_head_hexsha": "3881a190af8903537774c57b56963ffc94cfc039", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/bint.f", "max_issues_repo_name": "noboruatkek/SAD", "max_issues_repo_head_hexsha": "3881a190af8903537774c57b56963ffc94cfc039", "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/bint.f", "max_forks_repo_name": "noboruatkek/SAD", "max_forks_repo_head_hexsha": "3881a190af8903537774c57b56963ffc94cfc039", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.8417266187, "max_line_length": 88, "alphanum_fraction": 0.4727559055, "num_tokens": 1208, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637361282706, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.6705316151824606}} {"text": " include 'ttb/ttb_library.f'\n\n subroutine hypela2(d,g,e,de,s,t,dt,ngens,m,nn,kcus,matus,ndi,\n 2 nshear,disp,dispt,coord,ffn,frotn,strechn,eigvn,ffn1,\n 3 frotn1,strechn1,eigvn1,ncrd,itel,ndeg,ndm,\n 4 nnode,jtype,lclass,ifr,ifu)\n \n ! HYPELA2 Nearly-Incompressible Neo-Hookean Material\n ! Formulation: Total Lagrange, Displacement and Herrmann Elements\n ! Updated Lagrange: Push Forward and transform to Jaumann Tangent\n ! Example for usage of Tensor Toolbox\n !\n ! Switch to Voigt Notation:\n ! - change commented Tensor Datatypes\n !\n ! Andreas Dutzler\n ! 2017-12-21\n ! Graz University of Technology\n\n use Tensor\n implicit none\n \n real*8 coord, d, de, disp, dispt, dt, e, eigvn, eigvn1, ffn, ffn1\n real*8 frotn, frotn1, g\n integer ifr, ifu, itel, jtype, kcus, lclass, matus, m, ncrd, ndeg\n integer ndi, ndm, ngens, nn, nnode, nshear\n real*8 s, strechn, strechn1, t\n\n dimension e(*),de(*),t(*),dt(*),g(*),d(ngens,*),s(*)\n dimension m(2),coord(ncrd,*),disp(ndeg,*),matus(2),\n * dispt(ndeg,*),ffn(itel,3),frotn(itel,3),\n * strechn(itel),eigvn(itel,*),ffn1(itel,3),\n * frotn1(itel,3),strechn1(itel),eigvn1(itel,*),\n * kcus(2),lclass(2)\n include 'concom'\n include 'creeps'\n\n type(Tensor2) :: F1\n type(Tensor2s) :: E1\n \n ! voigt notation: change to type Tensor2s, Tensor4s\n type(Tensor2s) :: C1,S1,invC1,Eye\n type(Tensor4s) :: C4, I4, SdyaI\n \n real(kind=8) :: J,J_th,p,dpdJ,kappa,C10,alpha\n \n integer ndim\n \n ! dimension\n ndim = ndi+nshear\n \n ! material parameters\n C10 = 0.5\n kappa = 500.0\n alpha = 1.5d-4\n \n Eye = identity2(Eye)\n F1 = tensorstore(Eye)\n F1%ab(1:itel,1:3) = ffn1(1:itel,1:3)\n J = det(F1)\n J_th = (1+alpha*(t(1)+dt(1)))**3\n \n C1 = transpose(F1)*F1\n J = det(C1)**(1./2.)\n invC1 = inv(C1)\n \n ! u or u/p formulation\n if (ngens > ndim) then\n p = e(ngens)+de(ngens)\n dpdJ = 0.d0\n else\n p = kappa*(J/J_th-1)\n dpdJ = kappa/J_th\n end if\n \n ! pk2 stress\n S1 = 2.*C10 * J**(-2./3.) * dev(C1)*invC1 + p*J*invC1\n \n if (iupdat.eq.1) then\n S1 = piola(F1,S1)/J ! S1 = 1/J * F1*S1*transpose(F1)\n endif\n \n ! output as array\n s(1:ndim) = asarray( voigt(S1), ndim )\n \n ! material elasticity tensor\n I4 = invC1.cdya.invC1\n C4 = 2.*C10*J**(-2./3.)*2./3. * (tr(C1)*I4\n * -(Eye.dya.invC1)-(invC1.dya.Eye)\n * +tr(C1)/3.*(invC1.dya.invC1))\n * +(p*J+dpdJ*J**2)*(invC1.dya.invC1)\n * -2.*p*J*I4\n if (iupdat.eq.1) then\n C4 = piola(F1,C4)/detF1 + (S1.cdya.Eye)+(Eye.cdya.S1)\n endif\n \n ! output as array\n d(1:ndim,1:ndim) = asarray( voigt(C4), ndim, ndim )\n \n ! herrmann formulation\n if (iupdat.eq.1) then\n invC1 = Eye/J\n endif\n if (ngens > ndim) then\n s(ngens) = (J-J_th) - p*J_th**2/kappa\n d(ngens,1:ndim) = asarray( J*voigt(invC1), ndim)\n d(1:ndim,ngens) = d(ngens,1:ndim)\n d(ngens,ngens) = -J_th**2/kappa\n g(1:ndim) = 0.d0\n g(ngens) = -(1+2*p/kappa*J_th) * 3.*alpha*J_th**(2./3.)*dt(1)\n else\n g(1:ndim) = -kappa*J/J_th**2 * 3.*alpha*J_th**(2./3.)\n * * J * asarray(voigt(invC1), ndim)*dt(1)\n endif\n \n return\n end", "meta": {"hexsha": "670f62243c92f6cde83bacacb33cfcc25d122b60", "size": 3565, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "docs/examples/hypela2_nh_ttb.f", "max_stars_repo_name": "pinkieli/Tensor-for-Fortran", "max_stars_repo_head_hexsha": "15372e07ad2031a83b8e3a4fe1c99bf538c4d20b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "docs/examples/hypela2_nh_ttb.f", "max_issues_repo_name": "pinkieli/Tensor-for-Fortran", "max_issues_repo_head_hexsha": "15372e07ad2031a83b8e3a4fe1c99bf538c4d20b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/examples/hypela2_nh_ttb.f", "max_forks_repo_name": "pinkieli/Tensor-for-Fortran", "max_forks_repo_head_hexsha": "15372e07ad2031a83b8e3a4fe1c99bf538c4d20b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-18T02:02:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-18T02:02:31.000Z", "avg_line_length": 30.4700854701, "max_line_length": 72, "alphanum_fraction": 0.5197755961, "num_tokens": 1357, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107931567177, "lm_q2_score": 0.7154239957834733, "lm_q1q2_score": 0.6705030905315773}} {"text": "PROGRAM F003\n\n ! Copyright 2021 Melwyn Francis Carlo\n\n IMPLICIT NONE\n\n INTEGER, PARAMETER :: MAX_N = 1000\n\n CHARACTER (LEN=10) :: SUM_VAL = \"0000000001\"\n\n CHARACTER (LEN=20) :: TEMP_STR\n CHARACTER (LEN=10) :: PRODUCT_VAL\n\n CHARACTER (LEN=10), DIMENSION(10) :: SUB_PRODUCT_SUM\n\n INTEGER :: I, J, K, L, CARRY_VAL, TEMP_VAL, SUB_PRODUCT, SUB_PRODUCT_LEN\n\n DO I = 2, MAX_N\n\n IF (MOD(I, 10) == 0) CYCLE\n\n PRODUCT_VAL = \"0000000001\"\n\n DO J = 1, I\n\n SUB_PRODUCT_SUM = \"0000000000\"\n\n DO K = 10, 1, -1\n SUB_PRODUCT = (IACHAR(PRODUCT_VAL(K:K)) - IACHAR('0')) * I\n TEMP_STR = ACHAR(0)\n WRITE(TEMP_STR, \"(I0.10)\") SUB_PRODUCT\n SUB_PRODUCT_LEN = LEN_TRIM(ADJUSTL(TEMP_STR))\n SUB_PRODUCT_SUM(K)(1:K) = TEMP_STR((SUB_PRODUCT_LEN-K+1):SUB_PRODUCT_LEN)\n END DO\n\n CARRY_VAL = 0\n\n DO L = 10, 1, -1\n\n TEMP_VAL = IACHAR(SUB_PRODUCT_SUM(1)(L:L)) &\n + IACHAR(SUB_PRODUCT_SUM(2)(L:L)) &\n + IACHAR(SUB_PRODUCT_SUM(3)(L:L)) &\n + IACHAR(SUB_PRODUCT_SUM(4)(L:L)) &\n + IACHAR(SUB_PRODUCT_SUM(5)(L:L)) &\n + IACHAR(SUB_PRODUCT_SUM(6)(L:L)) &\n + IACHAR(SUB_PRODUCT_SUM(7)(L:L)) &\n + IACHAR(SUB_PRODUCT_SUM(8)(L:L)) &\n + IACHAR(SUB_PRODUCT_SUM(9)(L:L)) &\n + IACHAR(SUB_PRODUCT_SUM(10)(L:L)) &\n - (IACHAR('0') * 10) &\n + CARRY_VAL\n\n CARRY_VAL = INT(TEMP_VAL / 10)\n\n PRODUCT_VAL(L:L) = ACHAR(IACHAR('0') + MOD(TEMP_VAL, 10))\n\n END DO\n\n END DO\n\n CARRY_VAL = 0\n\n DO J = 10, 1, -1\n TEMP_VAL = IACHAR(SUM_VAL(J:J)) + IACHAR(PRODUCT_VAL(J:J)) &\n - IACHAR('0') - IACHAR('0') &\n + CARRY_VAL\n CARRY_VAL = INT(TEMP_VAL / 10)\n SUM_VAL(J:J) = ACHAR(IACHAR('0') + MOD(TEMP_VAL, 10))\n END DO\n\n END DO\n\n PRINT ('(A)'), SUM_VAL\n\nEND PROGRAM F003\n", "meta": {"hexsha": "10d30aeb377cb33593220964ac8982caf6fa1270", "size": 2492, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "problems/048/048.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/048/048.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/048/048.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": 32.7894736842, "max_line_length": 89, "alphanum_fraction": 0.4181380417, "num_tokens": 673, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677660619633, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.6703442325113226}} {"text": " DOUBLE PRECISION FUNCTION sla_DRANRM (ANGLE)\n*+\n* - - - - - - -\n* D R A N R M\n* - - - - - - -\n*\n* Normalize angle into range 0-2 pi (double precision)\n*\n* Given:\n* ANGLE dp the angle in radians\n*\n* The result is ANGLE expressed in the range 0-2 pi.\n*\n* Last revision: 22 July 2004\n*\n* Copyright P.T.Wallace. All rights reserved.\n*\n* License:\n* This program is free software; you can redistribute it and/or modify\n* it under the terms of the GNU General Public License as published by\n* the Free Software Foundation; either version 2 of the License, or\n* (at your option) any later version.\n*\n* This program is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU General Public License for more details.\n*\n* You should have received a copy of the GNU General Public License\n* along with this program (see SLA_CONDITIONS); if not, write to the\n* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,\n* Boston, MA 02110-1301 USA\n*\n*-\n\n IMPLICIT NONE\n\n DOUBLE PRECISION ANGLE\n\n DOUBLE PRECISION D2PI\n PARAMETER (D2PI=6.283185307179586476925286766559D0)\n\n\n sla_DRANRM = MOD(ANGLE,D2PI)\n IF (sla_DRANRM.LT.0D0) sla_DRANRM = sla_DRANRM+D2PI\n\n END\n", "meta": {"hexsha": "5cac1c6cec1bff4055de743ef8e95dd567fe384d", "size": 1397, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/slalib/dranrm.f", "max_stars_repo_name": "David-McKenna/psrsalsa", "max_stars_repo_head_hexsha": "e5074b552d1c404123dee058d5cee79ea230b5a9", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2017-09-05T23:22:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-11T14:12:18.000Z", "max_issues_repo_path": "src/slalib/dranrm.f", "max_issues_repo_name": "David-McKenna/psrsalsa", "max_issues_repo_head_hexsha": "e5074b552d1c404123dee058d5cee79ea230b5a9", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-04-26T13:35:30.000Z", "max_issues_repo_issues_event_max_datetime": "2020-01-20T08:49:57.000Z", "max_forks_repo_path": "src/slalib/dranrm.f", "max_forks_repo_name": "David-McKenna/psrsalsa", "max_forks_repo_head_hexsha": "e5074b552d1c404123dee058d5cee79ea230b5a9", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-04-09T09:04:46.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-16T15:24:07.000Z", "avg_line_length": 29.1041666667, "max_line_length": 73, "alphanum_fraction": 0.6735862563, "num_tokens": 398, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778257, "lm_q2_score": 0.7905303137346446, "lm_q1q2_score": 0.6703442180672858}} {"text": "!===============================================================================\nprogram possion_pmf\n!===============================================================================\n! Return the value of the probability mass function for the Poisson distribution\n! with parameter lambda at integer value k.\n\n use statistical, only: stat_poisson_pmf\n\n implicit none\n\n logical :: read_stdin = .false.\n real(8) :: lambda\n integer :: i, k, k2, iline = 1\n integer :: iostat = 0\n\n call get_args\n\n if (read_stdin) then\n do while (iostat == 0)\n read(*,*,iostat=iostat) lambda, k\n if (iostat < 0) exit\n if (iostat > 0) then\n write(0,'(a,i0.1,a)') 'poisson_pmf: Error: Problem reading lambda, k ' &\n // 'from line ', iline, ' of stdin'\n error stop\n endif\n write(*,*) k, stat_poisson_pmf(lambda, k)\n enddo\n else\n do i = k, k2\n write(*,*) i, stat_poisson_pmf(lambda, i)\n enddo\n endif\n\ncontains\n subroutine usage\n write(0,'(a)') &\n 'Usage: possion_pmf [lambda] [k] (k2)', &\n ' OR', &\n ' poisson_pmf < (lambda,k on stdin)', &\n 'Return the value of the pmf for the Poisson distribution with parameter', &\n 'lambda at integer value k, and optionally between k and k2 inclusive.'\n error stop\n end subroutine usage \n\n subroutine get_args\n integer :: iarg, narg\n character(len=250) :: arg\n narg = command_argument_count()\n if (narg == 1 .or. narg > 3) call usage\n if (narg == 0) then\n read_stdin = .true.\n else\n call get_command_argument(1, arg)\n read(arg,*) lambda\n call get_command_argument(2, arg)\n read(arg,*) k\n if (narg == 3) then\n call get_command_argument(3, arg)\n read(arg,*) k2\n else\n k2 = k\n endif\n endif\n end subroutine get_args\n\nend program possion_pmf\n!-------------------------------------------------------------------------------", "meta": {"hexsha": "6d3e2e8af5c642704c2047b4e6ff3aa76b38895e", "size": 2036, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "progs/src/poisson_pmf.f90", "max_stars_repo_name": "JackWalpole/seismo-fortran-fork", "max_stars_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2015-06-23T05:28:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T03:46:07.000Z", "max_issues_repo_path": "progs/src/poisson_pmf.f90", "max_issues_repo_name": "JackWalpole/seismo-fortran-fork", "max_issues_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2017-05-17T11:02:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-28T09:36:24.000Z", "max_forks_repo_path": "progs/src/poisson_pmf.f90", "max_forks_repo_name": "JackWalpole/seismo-fortran-fork", "max_forks_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-04-15T02:55:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-20T12:20:51.000Z", "avg_line_length": 29.9411764706, "max_line_length": 85, "alphanum_fraction": 0.5024557957, "num_tokens": 535, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744673038222, "lm_q2_score": 0.8198933403143929, "lm_q1q2_score": 0.6703238609534912}} {"text": " module intmath\n implicit none\n\n interface ilog2 \n ! log(x)/log(2)\n module procedure ilog2_8\n module procedure ilog2_4\n module procedure ilog2_2\n module procedure ilog2_1\n end interface ilog2\n\n interface i1log2\n ! log(x+1)/log(2) unless x=maxint, in which case log(x)/log(2)\n module procedure i1log2_8\n module procedure i1log2_4\n module procedure i1log2_2\n module procedure i1log2_1\n end interface i1log2\n\n contains\n\n ! ----------------------------------------------------------------\n\n function i1log2_8(ival)\n implicit none\n integer(kind=8), value :: ival\n integer(kind=8)::i1log2_8\n integer(kind=8), parameter :: one=1\n if(ival+one',I0,' (',I0,' = ',F0.10,')')\nc$$$ 20 format(Z16,' -- OKAY: ',I0,'=>',I0,' (',I0,' = ',F0.10,')')\nc$$$ if(ival+one last) then\n return;\n endif\n\n last = mod(i, 10);\n call idiv(i, 10_int64);\n end do\n\n desc = .true.;\n\n end function desc\n\n\n pure function asc(x)\n\n integer (int64), intent(in) :: x\n integer (int64) :: i, last\n logical :: asc\n asc = .FALSE.\n\n i = x\n \n last = mod(i, 10);\n call idiv(i, 10_int64);\n\n do while(i /= 0)\n if(mod(i, 10) < last) then\n return;\n endif\n\n last = mod(i, 10);\n call idiv(i, 10_int64);\n end do\n\n asc = .true.;\n\n end function asc\n\nend program main\n\n", "meta": {"hexsha": "350b72c2e1803793bf4874891963de733d942a72", "size": 2910, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "fortran/bouncy_numbers.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/bouncy_numbers.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/bouncy_numbers.f95", "max_forks_repo_name": "guynan/project_euler", "max_forks_repo_head_hexsha": "2b57d4e0c760276388d9410a438a7de0d91017b5", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-11-03T01:14:28.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-26T13:52:51.000Z", "avg_line_length": 24.6610169492, "max_line_length": 78, "alphanum_fraction": 0.4804123711, "num_tokens": 680, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.822189121808099, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.6702752900260583}} {"text": "!! minloc and maxloc with all false mask= can have surprising,\n!! compiler and compiler flag dependent behavior.\n!!\n!! Unfortunately, the Fortran 90 standard notes \"processor dependent behavior\"\n!! in 13.13.[65,70]. This is in contrast to index() in 13.13.46, which specifies\n!! 0 as the result for a similar outcome.\n!! This means users should shield maxloc/minloc when the mask= argument is used.\n!!\n!! GCC: https://gcc.gnu.org/onlinedocs/gfortran/MAXLOC.html\n!! Gfortran result 0 if mask==.false.\n!!\n!! Intel oneAPI: https://www.intel.com/content/www/us/en/develop/documentation/fortran-compiler-oneapi-dev-guide-and-reference/top/language-reference/a-to-z-reference/m-to-n/minloc.html\n!! ifort/ifx result 1 if mask==.false.\n\nprogram minloc_maxloc_mask\n\nimplicit none (type, external)\n\nreal :: A(5) = [0, 5, 1, 2, 3]\ninteger :: L\n\nlogical :: mask(size(A))\n\n\nif(maxloc(A, dim=1) /= 2) error stop \"maxloc sanity\"\nif(minloc(A, dim=1) /= 1) error stop \"minloc sanity\"\n\nif(maxloc(A, dim=1, mask=[.true., .false., .true., .true., .true.]) /= 5) error stop \"maxloc mask sanity\"\nif(minloc(A, dim=1, mask=[.false., .true., .true., .true., .true.]) /= 3) error stop \"minloc mask sanity\"\n\n!> compiler and compiler flag dependent behavior\n!! our testing showed:\n!! GCC: 0\n!! ifort/ifx: 1 -assume old_maxminloc (default)\n!! ifort/ifx: 0 -assume noold_maxminloc\nmask = .false.\nif (maxloc(A, dim=1, mask=mask) /= 0) error stop \"maxloc mask = .false.\"\nif (minloc(A, dim=1, mask=mask) /= 0) error stop \"minloc mask = .false.\"\n\nprint *, \"OK: minloc_maxloc_mask\"\n\nend program\n", "meta": {"hexsha": "0b09549403ad78cc1923ea29352aebc9f14f9744", "size": 1560, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "standard/minloc_maxloc_mask.f90", "max_stars_repo_name": "hbayraktaroglu/fortran2018-examples", "max_stars_repo_head_hexsha": "87407c9aecbdefd1862a5f0c962ec8e335394032", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2016-05-17T10:01:06.000Z", "max_stars_repo_stars_event_max_datetime": "2016-10-11T09:28:21.000Z", "max_issues_repo_path": "src/standard/minloc_maxloc_mask.f90", "max_issues_repo_name": "scivision/fortran2015-examples", "max_issues_repo_head_hexsha": "23fc7090997ecb4b838ebc1f09b86e2872d7141c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/standard/minloc_maxloc_mask.f90", "max_forks_repo_name": "scivision/fortran2015-examples", "max_forks_repo_head_hexsha": "23fc7090997ecb4b838ebc1f09b86e2872d7141c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.2790697674, "max_line_length": 185, "alphanum_fraction": 0.6980769231, "num_tokens": 480, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891218080991, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.6702752844897514}} {"text": "! { dg-do run }\n! { dg-options \"-O -ffrontend-optimize -fdump-tree-optimized\" }\n! PR 79930 - missed optimization by not inlining matmul in expressions.\n\nmodule foo\n implicit none\ncontains\n subroutine test1\n ! Test with fixed dimensions\n real, dimension(3,2) :: a1\n real, dimension(2,4) :: b1\n real, dimension(3,4) :: cres1\n real, dimension(3,3) :: a2\n real, dimension(3) :: v1, v2\n real :: r\n character(len=9*18) :: r1, r2\n real(kind=8), dimension(3,3) :: a3, b3, c3, d3, res3\n \n data a1 / 2., -3., 5., -7., 11., -13./\n data b1 /17., -23., 29., -31., 37., -39., 41., -47./\n data cres1 /195., -304., 384., 275., -428., 548., 347., -540., 692., 411., -640., 816./\n\n data a2 / 2., -3., 5., -7., 11., -13., 17., -23., 29./\n data v1 /-31., 37., -41./\n data v2 /43., -47., 53./\n\n data a3/-2.d0, 3.d0, 5.d0, -7.d0, -11.d0, 13.d0, 17.d0, -19.d0, -23.d0/\n data b3/29.d0, -31.d0, 37.d0, -41.d0, 43.d0, -47.d0, 53.d0, -59.d0, 61.d0/\n data c3/-67.d0,71.d0, 73.d0, -79.d0, -83.d0, 89.d0, 97.d0, -101.d0, 103.d0/\n data d3/107.d0, 109.d0, 113.d0, 127.d0, 131.d0, 137.d0, 139.d0, 149.d0, 151.d0/\n data res3/48476106.d0, -12727087.d0, -68646789.d0, 58682206.d0, -15428737.d0, -83096539.d0,&\n & 65359710.d0, -17176589.d0, -92551887.d0/\n\n write (unit=r1, fmt='(12F12.5)') matmul(a1,b1)\n write (unit=r2, fmt='(12F12.5)') cres1\n if (r1 /= r2) STOP 1\n\n r = dot_product(matmul(a2,v1),v2)\n if (abs(r+208320) > 1) STOP 2\n\n write (unit=r1,fmt='(1P,9E18.10)') matmul(matmul(a3,b3),matmul(c3,d3))\n write (unit=r2,fmt='(1P,9E18.10)') res3\n if (r1 /= r2) STOP 3\n \n end subroutine test1\n\n subroutine test2\n ! Test with dimensions not known at compile-time\n real, dimension(:,:), allocatable :: a1\n real, dimension(:,:), allocatable :: b1\n real, dimension(3,4) :: cres1\n real, dimension(:,:), allocatable :: a2\n real, dimension(:), allocatable :: v1, v2\n real :: r\n character(len=9*18) :: r1, r2\n real(kind=8), dimension(3,3) :: a3, b3, c3, d3, res3\n data cres1 /195., -304., 384., 275., -428., 548., 347., -540., 692., 411., -640., 816./\n data res3/48476106.d0, -12727087.d0, -68646789.d0, 58682206.d0, -15428737.d0, -83096539.d0,&\n & 65359710.d0, -17176589.d0, -92551887.d0/\n \n a1 = reshape([ 2., -3., 5., -7., 11., -13.], [3,2])\n b1 = reshape([17., -23., 29., -31., 37., -39., 41., -47.],[2,4])\n\n a2 = reshape([2., -3., 5., -7., 11., -13., 17., -23., 29.],[3,3]);\n v1 = [-31., 37., -41.]\n v2 = [43., -47., 53.]\n\n a3 = reshape([-2.d0, 3.d0, 5.d0, -7.d0, -11.d0, 13.d0, 17.d0, -19.d0, -23.d0], [3,3])\n b3 = reshape([29.d0, -31.d0, 37.d0, -41.d0, 43.d0, -47.d0, 53.d0, -59.d0, 61.d0], [3,3])\n c3 = reshape([-67.d0,71.d0, 73.d0, -79.d0, -83.d0, 89.d0, 97.d0, -101.d0, 103.d0], [3,3])\n d3 = reshape([107.d0, 109.d0, 113.d0, 127.d0, 131.d0, 137.d0, 139.d0, 149.d0, 151.d0],[3,3])\n\n write (unit=r1, fmt='(12F12.5)') matmul(a1,b1)\n write (unit=r2, fmt='(12F12.5)') cres1\n if (r1 /= r2) STOP 4\n\n r = dot_product(matmul(a2,v1),v2)\n if (abs(r+208320) > 1) STOP 5\n\n write (unit=r1,fmt='(1P,9E18.10)') matmul(matmul(a3,b3),matmul(c3,d3))\n write (unit=r2,fmt='(1P,9E18.10)') res3\n if (r1 /= r2) STOP 6\n \n end subroutine test2\n\nend module foo\n\nprogram main\n use foo\n implicit none\n call test1\n call test2\n! call test3\nend program main\n! { dg-final { scan-tree-dump-times \"_gfortran_matmul\" 0 \"optimized\" } }\n", "meta": {"hexsha": "2272b4084b0ceb1e6f688c4df1224c2345afe9dd", "size": 3496, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/inline_matmul_14.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/inline_matmul_14.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/inline_matmul_14.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": 36.4166666667, "max_line_length": 98, "alphanum_fraction": 0.5532036613, "num_tokens": 1604, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219504, "lm_q2_score": 0.8152324803738429, "lm_q1q2_score": 0.6702752842118229}} {"text": "a (1 : 5, 1)= (/(i * i, i = 1, 5)/)\n", "meta": {"hexsha": "b315ff2046b51f8a3dd5dd979de31458f332d6be", "size": 36, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Arrays/Fortran/arrays-34.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/Arrays/Fortran/arrays-34.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/Arrays/Fortran/arrays-34.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.0, "max_line_length": 35, "alphanum_fraction": 0.25, "num_tokens": 25, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8397339837155239, "lm_q2_score": 0.7981867801399694, "lm_q1q2_score": 0.6702645646360035}} {"text": "\tSUBROUTINE four1_sp(data,isign)\n\tUSE nrtype; USE nrutil, ONLY : arth,assert\n\tUSE nr, ONLY : fourrow\n\tIMPLICIT NONE\n\tCOMPLEX(SPC), DIMENSION(:), INTENT(INOUT) :: data\n\tINTEGER(I4B), INTENT(IN) :: isign\n\tCOMPLEX(SPC), DIMENSION(:,:), ALLOCATABLE :: dat,temp\n\tCOMPLEX(DPC), DIMENSION(:), ALLOCATABLE :: w,wp\n\tREAL(DP), DIMENSION(:), ALLOCATABLE :: theta\n\tINTEGER(I4B) :: n,m1,m2,j\n\tn=size(data)\n\tcall assert(iand(n,n-1)==0, 'n must be a power of 2 in four1_sp')\n\tm1=2**ceiling(0.5_sp*log(real(n,sp))/0.693147_sp)\n\tm2=n/m1\n\tallocate(dat(m1,m2),theta(m1),w(m1),wp(m1),temp(m2,m1))\n\tdat=reshape(data,shape(dat))\n\tcall fourrow(dat,isign)\n\ttheta=arth(0,isign,m1)*TWOPI_D/n\n\twp=cmplx(-2.0_dp*sin(0.5_dp*theta)**2,sin(theta),kind=dpc)\n\tw=cmplx(1.0_dp,0.0_dp,kind=dpc)\n\tdo j=2,m2\n\t\tw=w*wp+w\n\t\tdat(:,j)=dat(:,j)*w\n\tend do\n\ttemp=transpose(dat)\n\tcall fourrow(temp,isign)\n\tdata=reshape(temp,shape(data))\n\tdeallocate(dat,w,wp,theta,temp)\n\tEND SUBROUTINE four1_sp\n\n\tSUBROUTINE four1_dp(data,isign)\n\tUSE nrtype; USE nrutil, ONLY : arth,assert\n\tUSE nr, ONLY : fourrow\n\tIMPLICIT NONE\n\tCOMPLEX(DPC), DIMENSION(:), INTENT(INOUT) :: data\n\tINTEGER(I4B), INTENT(IN) :: isign\n\tCOMPLEX(DPC), DIMENSION(:,:), ALLOCATABLE :: dat,temp\n\tCOMPLEX(DPC), DIMENSION(:), ALLOCATABLE :: w,wp\n\tREAL(DP), DIMENSION(:), ALLOCATABLE :: theta\n\tINTEGER(I4B) :: n,m1,m2,j\n\tn=size(data)\n\tcall assert(iand(n,n-1)==0, 'n must be a power of 2 in four1_dp')\n\tm1=2**ceiling(0.5_sp*log(real(n,sp))/0.693147_sp)\n\tm2=n/m1\n\tallocate(dat(m1,m2),theta(m1),w(m1),wp(m1),temp(m2,m1))\n\tdat=reshape(data,shape(dat))\n\tcall fourrow(dat,isign)\n\ttheta=arth(0,isign,m1)*TWOPI_D/n\n\twp=cmplx(-2.0_dp*sin(0.5_dp*theta)**2,sin(theta),kind=dpc)\n\tw=cmplx(1.0_dp,0.0_dp,kind=dpc)\n\tdo j=2,m2\n\t\tw=w*wp+w\n\t\tdat(:,j)=dat(:,j)*w\n\tend do\n\ttemp=transpose(dat)\n\tcall fourrow(temp,isign)\n\tdata=reshape(temp,shape(data))\n\tdeallocate(dat,w,wp,theta,temp)\n\tEND SUBROUTINE four1_dp\n", "meta": {"hexsha": "86eebd2af1b9f40fbe7b519f2f36949de80f852e", "size": 1897, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ray_tracing_sampling/four1.f90", "max_stars_repo_name": "AntonBiryukovUofC/RayTracerFortran", "max_stars_repo_head_hexsha": "023a68b3c78a35fb794d011e5ed491437f09fe12", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-11-21T06:49:35.000Z", "max_stars_repo_stars_event_max_datetime": "2017-11-21T06:49:35.000Z", "max_issues_repo_path": "ray_tracing_sampling/four1.f90", "max_issues_repo_name": "AntonBiryukovUofC/RayTracerFortran", "max_issues_repo_head_hexsha": "023a68b3c78a35fb794d011e5ed491437f09fe12", "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": "ray_tracing_sampling/four1.f90", "max_forks_repo_name": "AntonBiryukovUofC/RayTracerFortran", "max_forks_repo_head_hexsha": "023a68b3c78a35fb794d011e5ed491437f09fe12", "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.6166666667, "max_line_length": 66, "alphanum_fraction": 0.6874011597, "num_tokens": 744, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.798186775339273, "lm_q1q2_score": 0.670264547799158}} {"text": "C$Procedure LSTLTD ( Last double precision element less than )\n \n INTEGER FUNCTION LSTLTD ( X, N, ARRAY )\n \nC$ Abstract\nC\nC Given a number X and an array of non-decreasing numbers,\nC find the index of the largest array element less than X.\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 SEARCH, ARRAY\nC\nC$ Declarations\n \n DOUBLE PRECISION X\n INTEGER N\n DOUBLE PRECISION ARRAY ( * )\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC X I Value to search against.\nC ARRAY I Array of possible lower bounds.\nC N I Number elements in ARRAY.\nC LSTLTD O the index of the last element of ARRAY < X.\nC\nC$ Detailed_Input\nC\nC X Double precision number for which one desires to find\nC the last ARRAY element less than X.\nC\nC N Total number of elements in ARRAY.\nC\nC ARRAY Array of double precision numbers that forms a\nC non-decreasing sequence. We will find the last element\nC of the sequence that is less than X.\nC\nC$ Detailed_Output\nC\nC LSTLTD Index of the last element of the non-decreasing sequence:\nC {ARRAY(I) : 0 < I < N + 1} that is less than X.\nC (Note that LSTLTD = I for some I in the range 1 to\nC N unless X is less than or equal to all of these\nC elements, in which case LSTLTD = 0.)\nC\nC In the case that N is input with value less than or equal\nC to zero, LSTLTD is returned as zero.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Particulars\nC\nC\nC An array of double precision numbers is given. The array\nC ARRAY(I) (0 < I < N+1 ) forms a non-decreasing sequence of\nC numbers. Given a real number X, there will be a last one of\nC these numbers that is less than X. This routine\nC finds the index LSTLTD such that ARRAY(LSTLTD) is that number.\nC\nC If X is not greater than ARRAY(1), INDEX will be set to zero.\nC\nC Note: If you need to find the first element of the array that\nC is greater than or equal to X, simply add 1 to the\nC result returned by this function and check to see if the\nC result is within the array bounds given by N.\nC\nC$ Examples\nC\nC If ARRAY(I) = -1 + 4*I/3 (real arithmetic implied here)\nC\nC N = 10\nC X = 7.12\nC\nC then\nC\nC LSTLTD will be I where\nC (4*I/3) - 1 < 7.12\nC but\nC (4*(I+1)/3) - 1 > or = 7.12 .\nC\nC In this case our subsequence is:\nC 1/3, 5/3, 9/3, 13/3, 17/3, 21/3, 25/3, .... 37/3\nC\nC index: 1 2 3 4 5 6 7 .... 10\nC\nC Thus LSTLTD will be returned as 6\nC\nC The following table shows the values of LSTLTD that would be\nC returned for various values of X\nC\nC X LSTLTD\nC ----- -------\nC 0.12 0\nC 1.34 1\nC 5.13 4\nC 8.00 6\nC 15.10 10\nC\nC$ Restrictions\nC\nC If the sequence is not non-decreasing, the program will run\nC to completion but the index found will not mean anything.\nC\nC$ Exceptions\nC\nC None.\nC\nC$ Files\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC N.J. Bachman (JPL)\nC W.L. Taber (JPL)\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)\nC\nC Comment section for permuted index source lines was added\nC following the header.\nC\nC- SPICELIB Version 1.0.0, 31-JAN-1990 (WLT)\nC\nC-&\n \nC$ Index_Entries\nC\nC last d.p. element less_than\nC\nC-&\n \n \nC$ Revisions\nC\nC- Beta Version 1.1.0, 16-FEB-1989 (NJB)\nC\nC Declaration of unused variable I removed.\nC\nC-&\n \n \n \nC\nC Local variables\nC\n INTEGER J\n \n INTEGER BEGIN\n INTEGER END\n INTEGER MIDDLE\n INTEGER ITEMS\n \n ITEMS = N\n \n BEGIN = 1\n END = N\n \n IF ( N .LE. 0 ) THEN\n \nC\nC There's nobody home---that is there is nothing in the array\nC to compare against. Zero is the only sensible thing to return\nC\n LSTLTD = 0\n \n ELSE IF ( X .LE. ARRAY(BEGIN) ) THEN\n \nC\nC None of the array elements are less than X\nC\n LSTLTD = 0\n \n ELSE IF ( ARRAY(END) .LT. X ) THEN\n \nC\nC X is greater than all elements of the array. Thus the last\nC element of the array is the last item less than X.\nC\n LSTLTD = END\n \n ELSE\n \nC\nC X lies between some pair of elements of the array\nC\n \n DO WHILE ( ITEMS .GT. 2 )\n \n J = ITEMS/2\n MIDDLE = BEGIN + J\n \n IF ( ARRAY(MIDDLE) .LT. X ) THEN\n BEGIN = MIDDLE\n ELSE\n END = MIDDLE\n END IF\n \n ITEMS = 1 + (END - BEGIN)\n END DO\n \n LSTLTD = BEGIN\n \n END IF\n \n \n RETURN\n END\n", "meta": {"hexsha": "f8dd7c5bf1565a0fa0b4cf0dacebb1d2a9d89408", "size": 6448, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/lstltd.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/lstltd.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/lstltd.f", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 26.1052631579, "max_line_length": 72, "alphanum_fraction": 0.5925868486, "num_tokens": 1893, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339596505965, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.6702645454276966}} {"text": "module riemann_mod\n\nuse constants_mod\n\ncontains\n\npure function xriemann(U_L,U_R) result(F)\n\n use equations_const_mod\n use equations_mod, only: pressure\n use setup_config_mod, only: kappa\n\n use equations_mod, only: flux => xflux\n\n real(dp), dimension(N_VARS), intent(in) :: U_L, U_R\n real(dp), dimension(N_VARS) :: F\n \n real(dp) :: F_L(N_VARS), F_R(N_VARS)\n\n real(dp) :: c_L,c_R !! sound speed\n real(dp) :: H_L,H_R !! enthalpy\n real(dp) :: p_L,p_R !! pressure\n real(dp) :: S_L,S_R !! signal wave speed\n real(dp) :: V_L,V_R !! velocities\n\n real(dp) :: HTilde, vTilde, aTilde\n real(dp) :: SStar, QStar, UStar(N_VARS)\n\n real(dp) :: smooth\n\n real(dp) :: F_HLLE(N_VARS)\n\n real(dp), parameter :: beta = SQRT(0.5_dp*(kappa-1)/kappa)\n\n !! velocity\n V_L = U_L(MOMX_VAR)/U_L(DENS_VAR)\n V_R = U_R(MOMX_VAR)/U_R(DENS_VAR)\n\n !! pressure\n p_L = pressure(U_L)\n p_R = pressure(U_R)\n\n !! sound speed\n c_L = SQRT(kappa*p_L/U_L(DENS_VAR))\n c_R = SQRT(kappa*p_R/U_R(DENS_VAR))\n\n !! Signal velocity estimates by Davis (1988) and Einfeldt (1988)\n\n !! enthalpy\n H_L = (U_L(ENER_VAR) + p_L)/U_L(DENS_VAR)\n H_R = (U_R(ENER_VAR) + p_R)/U_R(DENS_VAR)\n\n !! Roe averages\n HTilde = (SQRT(U_L(DENS_VAR))*H_L + SQRT(U_R(DENS_VAR))*H_R)/(SQRT(U_L(DENS_VAR)) + SQRT(U_R(DENS_VAR)))\n vTilde = (SQRT(U_L(DENS_VAR))*v_L + SQRT(U_R(DENS_VAR))*v_R)/(SQRT(U_L(DENS_VAR)) + SQRT(U_R(DENS_VAR)))\n aTilde = SQRT((kappa-1.0_dp)*(HTilde - 0.5_dp*vTilde**2))\n\n !! signal velocities\n S_L = MIN(vTilde - aTilde, V_L - beta*c_L, 0.0_dp)\n S_R = MAX(vTilde + aTilde, V_R + beta*c_R, 0.0_dp)\n\n if (S_L .GE. 0.0_dp) then\n F = flux(U_L)\n\n elseif (S_R .LE. 0.0_dp) then\n F = flux(U_R)\n\n else\n F_L = flux(U_L)\n F_R = flux(U_R)\n\n smooth = SQRT(abs(p_L - p_R)/(p_L + p_R))\n F_HLLE = (S_R*F_L - S_L*F_R + S_L*S_R*(U_R - U_L)) / (S_R - S_L)\n\n SStar = (p_R - p_L + U_L(MOMX_VAR)*(S_L - V_L) - U_R(MOMX_VAR)*(S_R - V_R)) / (U_L(DENS_VAR)*(S_L - V_L) - U_R(DENS_VAR)*(S_R - V_R))\n\n if (S_L .le. 0.0_dp .and. 0.0_dp .le. SStar) then\n QStar = U_L(DENS_VAR)*(S_L - V_L)/(S_L-SStar)\n\n UStar(DENS_VAR) = QStar\n UStar(MOMX_VAR) = QStar * SStar\n UStar(MOMY_VAR) = QStar * U_L(MOMY_VAR)/U_L(DENS_VAR)\n UStar(MOMZ_VAR) = QStar * U_L(MOMZ_VAR)/U_L(DENS_VAR)\n UStar(ENER_VAR) = QStar * (U_L(ENER_VAR)/U_L(DENS_VAR) + (SStar-V_L)*(SStar + p_L/U_L(DENS_VAR)/(S_L - V_L)))\n\n F = smooth*F_HLLE + (1.0_dp-smooth)*(F_L + S_L*(UStar - U_L))\n !F = F_L + S_L*(UStar - U_L)\n\n else\n QStar = U_R(DENS_VAR)*(S_R - V_R)/(S_R-SStar)\n\n UStar(DENS_VAR) = QStar\n UStar(MOMX_VAR) = QStar * SStar\n UStar(MOMY_VAR) = QStar * U_R(MOMY_VAR)/U_R(DENS_VAR)\n UStar(MOMZ_VAR) = QStar * U_R(MOMZ_VAR)/U_R(DENS_VAR)\n UStar(ENER_VAR) = QStar * (U_R(ENER_VAR)/U_R(DENS_VAR) + (SStar-V_R)*(SStar + p_R/U_R(DENS_VAR)/(S_R - V_R)))\n\n F = smooth*F_HLLE + (1.0_dp-smooth)*(F_R + S_R*(UStar - U_R))\n !F = F_R + S_R*(UStar - U_R)\n\n end if \n end if \n\nend function\n\npure function yriemann(inflow, exflow) result(sflux)\n\n use equations_const_mod\n\n real(dp), dimension(N_VARS), intent(in) :: inflow, exflow\n real(dp), dimension(N_VARS) :: sflux\n\n real(dp) :: rinflow(N_VARS), rexflow(N_VARS), rflux(N_VARS) !! rotated\n\n rinflow(DENS_VAR) = inflow(DENS_VAR)\n rinflow(MOMX_VAR) = inflow(MOMY_VAR)\n rinflow(MOMY_VAR) = inflow(MOMZ_VAR)\n rinflow(MOMZ_VAR) = inflow(MOMX_VAR)\n rinflow(ENER_VAR) = inflow(ENER_VAR)\n \n rexflow(DENS_VAR) = exflow(DENS_VAR)\n rexflow(MOMX_VAR) = exflow(MOMY_VAR)\n rexflow(MOMY_VAR) = exflow(MOMZ_VAR)\n rexflow(MOMZ_VAR) = exflow(MOMX_VAR)\n rexflow(ENER_VAR) = exflow(ENER_VAR)\n\n rflux = xriemann(rinflow,rexflow)\n\n sflux(DENS_VAR) = rflux(DENS_VAR)\n sflux(MOMX_VAR) = rflux(MOMZ_VAR)\n sflux(MOMY_VAR) = rflux(MOMX_VAR)\n sflux(MOMZ_VAR) = rflux(MOMY_VAR)\n sflux(ENER_VAR) = rflux(ENER_VAR)\n \nend function\n\npure function zriemann(inflow, exflow) result(sflux)\n\n use equations_const_mod\n\n real(dp), dimension(N_VARS), intent(in) :: inflow, exflow\n real(dp), dimension(N_VARS) :: sflux\n\n real(dp) :: rinflow(N_VARS), rexflow(N_VARS), rflux(N_VARS) !! rotated\n\n rinflow(DENS_VAR) = inflow(DENS_VAR)\n rinflow(MOMX_VAR) = inflow(MOMZ_VAR)\n rinflow(MOMY_VAR) = inflow(MOMX_VAR)\n rinflow(MOMZ_VAR) = inflow(MOMY_VAR)\n rinflow(ENER_VAR) = inflow(ENER_VAR)\n \n rexflow(DENS_VAR) = exflow(DENS_VAR)\n rexflow(MOMX_VAR) = exflow(MOMZ_VAR)\n rexflow(MOMY_VAR) = exflow(MOMX_VAR)\n rexflow(MOMZ_VAR) = exflow(MOMY_VAR)\n rexflow(ENER_VAR) = exflow(ENER_VAR)\n\n rflux = xriemann(rinflow,rexflow)\n\n sflux(DENS_VAR) = rflux(DENS_VAR)\n sflux(MOMX_VAR) = rflux(MOMY_VAR)\n sflux(MOMY_VAR) = rflux(MOMZ_VAR)\n sflux(MOMZ_VAR) = rflux(MOMX_VAR)\n sflux(ENER_VAR) = rflux(ENER_VAR)\n \nend function\n\nend module\n", "meta": {"hexsha": "de1b90bed9d77bc3ffc021b26e7964cca5e3460b", "size": 5124, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/equations/euler/riemann/hllc/riemann_mod.f90", "max_stars_repo_name": "jmark/nemo", "max_stars_repo_head_hexsha": "cf8a6a8bed5c54626f5e300c701b9c278fd5e0cd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source/equations/euler/riemann/hllc/riemann_mod.f90", "max_issues_repo_name": "jmark/nemo", "max_issues_repo_head_hexsha": "cf8a6a8bed5c54626f5e300c701b9c278fd5e0cd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/equations/euler/riemann/hllc/riemann_mod.f90", "max_forks_repo_name": "jmark/nemo", "max_forks_repo_head_hexsha": "cf8a6a8bed5c54626f5e300c701b9c278fd5e0cd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.3195266272, "max_line_length": 141, "alphanum_fraction": 0.6151444184, "num_tokens": 1847, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693702514736, "lm_q2_score": 0.7057850154599563, "lm_q1q2_score": 0.6702624111647832}} {"text": " function p2chi(x,fl,io)\r\nc*****************************************************************\r\nc M.J. Hinich Version: 2-12-95 Single Precision Function\r\nc Calculates the noncentral chi square cdf with 2 degrees-of-freedom\r\nc and noncentrality parameter Lamda(fl) at x.\r\nc io - output file number\r\nc=====================================================\r\n real x,fl,p2chi\r\n real*8 c,y,fl2,dn,ly,tgam,ll,term,ey,el,pl,pw,chi,ac,at\r\n parameter(ntries=10000,ac=1.d-10,at=1.d-20)\r\n intent(in) x,fl,io\r\nc*****************************************************\r\n if(x<=ac) then\r\n p2chi=0.\r\n return\r\n elseif(x<0.) then\r\n write(io,*) 'Argument is negative',x\r\n p2chi=-1.\r\n return\r\n endif\r\nc-------\r\n if(fl<0.) then\r\n write(io,*) 'Noncentrality Parameter Lamda < 0. ',fl\r\n return\r\n endif\r\n if(fl<1.e-7) then\r\n y=dble(x/2.)\r\n if(y<=14.d0) then\r\n p2chi=real(1.d0-dexp(-y))\r\n else\r\n p2chi=1.\r\n endif\r\n return\r\n endif\r\nc-------\r\n y=dble(x/2.)\r\n if(y<=14.d0) then\r\n ey=dexp(-y)\r\n else\r\n ey=0.d0\r\n endif\r\n fl2=dble(fl/2.)\r\n if(fl2<=14.d0) then\r\n el=dexp(-fl2)\r\n else\r\n el=0.d0\r\n endif\r\nc-------\r\n ll=dlog(fl2)\r\n ly=dlog(y)\r\n c=0.d0\r\n tgam=ey\r\n chi=(1.d0-ey)*el\r\nc Compute weighted sum of GAMMA(y,1+t)\r\n do n=1,ntries\r\n dn=dfloat(n)\r\nc Compute log of (Lamda/2)**N/N!exp(-Lamda/2) Poisson probability\r\nc Log of N! accumulated in c\r\n c=c+dlog(dn)\r\n pl=dn*ll-c-fl2\r\nc Compute log of terms in gamma sum\r\n ey=dn*ly-c-y\r\n if(ey>=-14.d0) then\r\n tgam=tgam+dexp(ey)\r\n endif\r\nc Compute Poisson probability\r\n if(pl>=-14.d0) then\r\n pw=dexp(pl)\r\n else\r\n pw=0.d0\r\n endif\r\nc--------\r\nc Compute Nth term in expansion of noncentral chi square\r\n term=pw*(1.d0-tgam)\r\nc Check for sum termination\r\n if(chi>0.99999d0) then\r\n p2chi=1.\r\n return\r\n endif\r\n if(term1.d-6.or.dabs(tgam-\r\n *1.d0) U%y * (p%x - r%x)\n end function inside\n \n\n function intersection(a, V, r, N) result(int_res)\n type(intersection_result) :: int_res\n type(point) :: a, r, p\n type(vector) :: V, N, W\n real(kind=8) :: nw, nv, t\n W = vector(r%x - a%x, r%y - a%y)\n nw = dot(N, W)\n nv = dot(N, V)\n if (nv /= 0.0d0) then\n t = nw / nv\n p = point(a%x + t * V%x, a%y + t * V%y)\n int_res = intersection_result(.true., p)\n else\n p = point(0.0d0, 0.0d0)\n int_res = intersection_result(.false., p)\n end if \n end function intersection\n \n\n function polygon_area(polygon, length) result(area)\n real(kind=8) :: area\n type(point) :: a, b, c\n type(vector) :: U, V\n real(kind=8), dimension(:, :) :: polygon\n integer :: length, i\n \n area = 0.0d0\n a = point(polygon(1, 1), polygon(2, 1))\n b = point(polygon(1, 2), polygon(2, 2))\n U = vector(b%x - a%x, b%y - a%y)\n do i = 3, length\n c = point(polygon(1, i), polygon(2, i))\n V = vector(a%x - c%x, a%y - c%y)\n area = area + abs(cross(U, V))\n b = c\n U = V\n end do\n area = 0.5d0 * area\n end function polygon_area\n \n\n function clip_polygons(polygon, clipper, n_max) result(area)\n type(point) :: r, s, a, b, p\n type(vector) :: U, N, V\n type(intersection_result) :: int_res\n integer, dimension(2) :: polygon_shape, clipper_shape\n integer :: n_output, n_poly, n_clip, length, i, j\n integer(kind=8) :: n_max\n real(kind=8), dimension(:, :) :: polygon, clipper\n real(kind=8), dimension(2, n_max):: output, subject\n real(kind=8) :: area\n logical :: a_inside, b_inside\n \n polygon_shape = shape(clipper)\n clipper_shape = shape(polygon)\n n_poly = polygon_shape(2)\n n_clip = clipper_shape(2)\n\n n_output = n_poly\n call copyto(polygon, output, n_output)\n\n r = point(clipper(1, n_clip), clipper(2, n_clip))\n do i = 1, n_clip\n \n s = point(clipper(1, i), clipper(2, i))\n U = vector(s%x - r%x, s%y - r%y)\n N = vector(-U%y, U%x)\n \n if (U%x == 0.0d0 .and. U%y == 0.0d0) then\n cycle\n end if\n \n length = n_output\n call copyto(output, subject, length)\n n_output = 0\n \n a = point(subject(1, length), subject(2, length))\n a_inside = inside(a, r, U)\n do j = 1, length\n b = point(subject(1, j), subject(2, j))\n V = vector(b%x - a%x, b%y - a%y)\n \n if (V%x == 0.0d0 .and. V%y == 0.0d0) then\n cycle\n end if\n \n b_inside = inside(b, r, U)\n \n if (b_inside) then\n if (.not. a_inside) then\n int_res = intersection(a, V, r, N)\n if (int_res%success) then\n call push(output, n_output, int_res%p)\n end if\n end if\n call push(output, n_output, b)\n else if (a_inside) then\n int_res = intersection(a, V, r, N)\n if (int_res%success) then\n call push(output, n_output, int_res%p)\n else\n b_inside = .true.\n call push(output, n_output, b)\n end if\n end if\n a = b\n a_inside = b_inside\n end do\n \n if (n_output < 3) then\n area = 0.0d0\n return\n end if\n \n r = s\n end do\n area = polygon_area(output, n_output)\n end function clip_polygons\n \n\n subroutine area_of_intersection(ndim, nvertex, ntriangles, polygons, clippers, areas) bind(c, name=\"area_of_intersection\")\n !DEC$ ATTRIBUTES DLLEXPORT :: area_of_intersection\n integer(c_int64_t) :: ntriangles, nvertex, ndim, i\n real(c_double), dimension(ndim, nvertex, ntriangles), intent(in) :: polygons, clippers\n real(c_double), dimension(ntriangles), intent(out) :: areas\n do i = 1, ntriangles\n areas(i) = clip_polygons(polygons(:, :, i), clippers(:, :, i), nvertex * 2)\n end do\n end subroutine area_of_intersection\n\nend", "meta": {"hexsha": "b8da04fb59af9b6113c54789ff897db1670de6c9", "size": 6111, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/clipping.f90", "max_stars_repo_name": "Huite/clipping-benchmarks", "max_stars_repo_head_hexsha": "a95c10d3852a5442b9c8d00af8be5b096bc241d8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-07-15T09:37:55.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-04T17:13:50.000Z", "max_issues_repo_path": "src/fortran/clipping.f90", "max_issues_repo_name": "Huite/clipping-benchmarks", "max_issues_repo_head_hexsha": "a95c10d3852a5442b9c8d00af8be5b096bc241d8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/fortran/clipping.f90", "max_forks_repo_name": "Huite/clipping-benchmarks", "max_forks_repo_head_hexsha": "a95c10d3852a5442b9c8d00af8be5b096bc241d8", "max_forks_repo_licenses": ["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.1785714286, "max_line_length": 126, "alphanum_fraction": 0.4774995909, "num_tokens": 1688, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533163686646, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6700557300960704}} {"text": "ccccccccccccccccccccccccccccccccccccccccccc\nc Interpolate over the kth element of z by using its 3 valid neighbors.\n\nc Examples of use:\nc call interp_3(k,vnk,snom,lnom,l)\nc call interp_3(k,vnk,snom,lnom,s)\nc call interp_3(k,vnk,sdc,ldc,dc)\n\n subroutine interp_3(k,vnk,x,y,z,ezk)\n implicit none\nc Inputs...\n integer k \t\t!mark to be filled\n integer vnk(3)\t\t!valid neighbors of k\n real*4 x(202),y(202),z(202)\nc Output...\n real*4 ezk\t\t!estimated value of z(k)\n\nc Local variables...\n real*4 a(3,3),b(3)\n integer i,ki,ind\n\nc Model the behavior of z in the local image region as an affine transformation \nc using its 3 neighbors as data points.\n\n do i=1,3\n ki = vnk(i)\n a(i,1) = 1\n a(i,2) = x(ki)\n a(i,3) = y(ki)\n b(i) = z(ki)\n enddo\n\nc ...Solve the simultaneous equation Ac = b\n call simq(a,b,3,ind)\t!note: c is returned in b\n if (ind.eq.0) then\n ezk = b(1) + b(2)*x(k) + b(3)*y(k)\n else\n call prnt(2,1,k,'***simq err at mark.')\n ezk = -999\n endif\n\n return\n end\n", "meta": {"hexsha": "d65662e2a408f7e0aed09e581d0e85a3df58a464", "size": 1128, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "vos/p2/prog/resloc/interp_3.f", "max_stars_repo_name": "NASA-AMMOS/VICAR", "max_stars_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2020-10-21T05:56:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T10:02:01.000Z", "max_issues_repo_path": "vos/p2/prog/resloc/interp_3.f", "max_issues_repo_name": "NASA-AMMOS/VICAR", "max_issues_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "vos/p2/prog/resloc/interp_3.f", "max_forks_repo_name": "NASA-AMMOS/VICAR", "max_forks_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-03-09T01:51:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-23T00:23:24.000Z", "avg_line_length": 25.6363636364, "max_line_length": 80, "alphanum_fraction": 0.5726950355, "num_tokens": 383, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533051062237, "lm_q2_score": 0.7185944046238981, "lm_q1q2_score": 0.6700557276223928}} {"text": "!\tStandard error for entropy per item under standard sampling.\r\n!\tloglik is log likelihood.\r\n!\tobsweight is observation weights.\r\n!\tprob is array of observed probabilities.\r\n!\ttotalitems is weighted sum of items presented.\r\nreal(kind=8) function sdent(loglik,obsweight,prob,totalitems)\r\nimplicit none\r\nreal(kind=8),intent(in)::loglik,obsweight(:),prob(:),totalitems\r\n!\tCount observations.\r\ninteger::obs\r\n!\tAverage item score.\r\nreal(kind=8)::loglikitem\r\nloglikitem=loglik/sum(obsweight,prob>0.0_8)\r\nsdent=0.0_8\r\ndo obs=1,size(prob)\r\n\tif(prob(obs)>0.0_8)sdent=sdent+obsweight(obs)*(log(prob(obs))-loglikitem)**2\r\nend do\r\nsdent=sqrt(sdent)/totalitems\r\nreturn\r\nend function sdent\r\n\r\n\r\n", "meta": {"hexsha": "6a3f5a4b5ec0ffae16af4c9f01468083a09685b2", "size": 682, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Source/sdent.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/sdent.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/sdent.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": 29.652173913, "max_line_length": 78, "alphanum_fraction": 0.7492668622, "num_tokens": 197, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533013520765, "lm_q2_score": 0.7185943925708561, "lm_q1q2_score": 0.6700557136857849}} {"text": " SUBROUTINE SB02OD( DICO, JOBB, FACT, UPLO, JOBL, SORT, N, M, P, A,\n $ LDA, B, LDB, Q, LDQ, R, LDR, L, LDL, RCOND, X,\n $ LDX, ALFAR, ALFAI, BETA, S, LDS, T, LDT, U,\n $ LDU, TOL, IWORK, DWORK, LDWORK, BWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To solve for X either the continuous-time algebraic Riccati\nC equation\nC -1\nC Q + A'X + XA - (L+XB)R (L+XB)' = 0 (1)\nC\nC or the discrete-time algebraic Riccati equation\nC -1\nC X = A'XA - (L+A'XB)(R + B'XB) (L+A'XB)' + Q (2)\nC\nC where A, B, Q, R, and L are N-by-N, N-by-M, N-by-N, M-by-M and\nC N-by-M matrices, respectively, such that Q = C'C, R = D'D and\nC L = C'D; X is an N-by-N symmetric matrix.\nC The routine also returns the computed values of the closed-loop\nC spectrum of the system, i.e., the stable eigenvalues lambda(1),\nC ..., lambda(N) of the corresponding Hamiltonian or symplectic\nC pencil, in the continuous-time case or discrete-time case,\nC respectively.\nC -1\nC Optionally, matrix G = BR B' may be given instead of B and R.\nC Other options include the case with Q and/or R given in a\nC factored form, Q = C'C, R = D'D, and with L a zero matrix.\nC\nC The routine uses the method of deflating subspaces, based on\nC reordering the eigenvalues in a generalized Schur matrix pair.\nC A standard eigenproblem is solved in the continuous-time case\nC if G is given.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC DICO CHARACTER*1\nC Specifies the type of Riccati equation to be solved as\nC follows:\nC = 'C': Equation (1), continuous-time case;\nC = 'D': Equation (2), discrete-time case.\nC\nC JOBB CHARACTER*1\nC Specifies whether or not the matrix G is given, instead\nC of the matrices B and R, as follows:\nC = 'B': B and R are given;\nC = 'G': G is given.\nC\nC FACT CHARACTER*1\nC Specifies whether or not the matrices Q and/or R (if\nC JOBB = 'B') are factored, as follows:\nC = 'N': Not factored, Q and R are given;\nC = 'C': C is given, and Q = C'C;\nC = 'D': D is given, and R = D'D;\nC = 'B': Both factors C and D are given, Q = C'C, R = D'D.\nC\nC UPLO CHARACTER*1\nC If JOBB = 'G', or FACT = 'N', specifies which triangle of\nC the matrices G and Q (if FACT = 'N'), or Q and R (if\nC JOBB = 'B'), is stored, as follows:\nC = 'U': Upper triangle is stored;\nC = 'L': Lower triangle is stored.\nC\nC JOBL CHARACTER*1\nC Specifies whether or not the matrix L is zero, as follows:\nC = 'Z': L is zero;\nC = 'N': L is nonzero.\nC JOBL is not used if JOBB = 'G' and JOBL = 'Z' is assumed.\nC SLICOT Library routine SB02MT should be called just before\nC SB02OD, for obtaining the results when JOBB = 'G' and\nC JOBL = 'N'.\nC\nC SORT CHARACTER*1\nC Specifies which eigenvalues should be obtained in the top\nC of the generalized Schur form, as follows:\nC = 'S': Stable eigenvalues come first;\nC = 'U': Unstable eigenvalues come first.\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The actual state dimension, i.e. the order of the matrices\nC A, Q, and X, and the number of rows of the matrices B\nC and L. N >= 0.\nC\nC M (input) INTEGER\nC The number of system inputs. If JOBB = 'B', M is the\nC order of the matrix R, and the number of columns of the\nC matrix B. M >= 0.\nC M is not used if JOBB = 'G'.\nC\nC P (input) INTEGER\nC The number of system outputs. If FACT = 'C' or 'D' or 'B',\nC P is the number of rows of the matrices C and/or D.\nC P >= 0.\nC Otherwise, P is not used.\nC\nC A (input) DOUBLE PRECISION array, dimension (LDA,N)\nC The leading N-by-N part of this array must contain the\nC state matrix A of the system.\nC\nC LDA INTEGER\nC The leading dimension of array A. LDA >= MAX(1,N).\nC\nC B (input) DOUBLE PRECISION array, dimension (LDB,*)\nC If JOBB = 'B', the leading N-by-M part of this array must\nC contain the input matrix B of the system.\nC If JOBB = 'G', the leading N-by-N upper triangular part\nC (if UPLO = 'U') or lower triangular part (if UPLO = 'L')\nC of this array must contain the upper triangular part or\nC lower triangular part, respectively, of the matrix\nC -1\nC G = BR B'. The strictly lower triangular part (if\nC UPLO = 'U') or strictly upper triangular part (if\nC UPLO = 'L') is not referenced.\nC\nC LDB INTEGER\nC The leading dimension of array B. LDB >= MAX(1,N).\nC\nC Q (input) DOUBLE PRECISION array, dimension (LDQ,N)\nC If FACT = 'N' or 'D', the leading N-by-N upper triangular\nC part (if UPLO = 'U') or lower triangular part (if UPLO =\nC 'L') of this array must contain the upper triangular part\nC or lower triangular part, respectively, of the symmetric\nC state weighting matrix Q. The strictly lower triangular\nC part (if UPLO = 'U') or strictly upper triangular part (if\nC UPLO = 'L') is not referenced.\nC If JOBB = 'B', the triangular part of this array defined\nC by UPLO is modified internally, but is restored on exit.\nC If FACT = 'C' or 'B', the leading P-by-N part of this\nC array must contain the output matrix C of the system.\nC If JOBB = 'B', this part is modified internally, but is\nC restored on exit.\nC\nC LDQ INTEGER\nC The leading dimension of array Q.\nC LDQ >= MAX(1,N) if FACT = 'N' or 'D',\nC LDQ >= MAX(1,P) if FACT = 'C' or 'B'.\nC\nC R (input) DOUBLE PRECISION array, dimension (LDR,M)\nC If FACT = 'N' or 'C', the leading M-by-M upper triangular\nC part (if UPLO = 'U') or lower triangular part (if UPLO =\nC 'L') of this array must contain the upper triangular part\nC or lower triangular part, respectively, of the symmetric\nC input weighting matrix R. The strictly lower triangular\nC part (if UPLO = 'U') or strictly upper triangular part (if\nC UPLO = 'L') is not referenced.\nC The triangular part of this array defined by UPLO is\nC modified internally, but is restored on exit.\nC If FACT = 'D' or 'B', the leading P-by-M part of this\nC array must contain the direct transmission matrix D of the\nC system. This part is modified internally, but is restored\nC on exit.\nC If JOBB = 'G', this array is not referenced.\nC\nC LDR INTEGER\nC The leading dimension of array R.\nC LDR >= MAX(1,M) if JOBB = 'B' and FACT = 'N' or 'C';\nC LDR >= MAX(1,P) if JOBB = 'B' and FACT = 'D' or 'B';\nC LDR >= 1 if JOBB = 'G'.\nC\nC L (input) DOUBLE PRECISION array, dimension (LDL,M)\nC If JOBL = 'N' (and JOBB = 'B'), the leading N-by-M part of\nC this array must contain the cross weighting matrix L.\nC This part is modified internally, but is restored on exit.\nC If JOBL = 'Z' or JOBB = 'G', this array is not referenced.\nC\nC LDL INTEGER\nC The leading dimension of array L.\nC LDL >= MAX(1,N) if JOBL = 'N' and JOBB = 'B';\nC LDL >= 1 if JOBL = 'Z' or JOBB = 'G'.\nC\nC RCOND (output) DOUBLE PRECISION\nC An estimate of the reciprocal of the condition number (in\nC the 1-norm) of the N-th order system of algebraic\nC equations from which the solution matrix X is obtained.\nC\nC X (output) DOUBLE PRECISION array, dimension (LDX,N)\nC The leading N-by-N part of this array contains the\nC solution matrix X of the problem.\nC\nC LDX INTEGER\nC The leading dimension of array X. LDX >= MAX(1,N).\nC\nC ALFAR (output) DOUBLE PRECISION array, dimension (2*N)\nC ALFAI (output) DOUBLE PRECISION array, dimension (2*N)\nC BETA (output) DOUBLE PRECISION array, dimension (2*N)\nC The generalized eigenvalues of the 2N-by-2N matrix pair,\nC ordered as specified by SORT (if INFO = 0). For instance,\nC if SORT = 'S', the leading N elements of these arrays\nC contain the closed-loop spectrum of the system matrix\nC A - BF, where F is the optimal feedback matrix computed\nC based on the solution matrix X. Specifically,\nC lambda(k) = [ALFAR(k)+j*ALFAI(k)]/BETA(k) for\nC k = 1,2,...,N.\nC If DICO = 'C' and JOBB = 'G', the elements of BETA are\nC set to 1.\nC\nC S (output) DOUBLE PRECISION array, dimension (LDS,*)\nC The leading 2N-by-2N part of this array contains the\nC ordered real Schur form S of the first matrix in the\nC reduced matrix pencil associated to the optimal problem,\nC or of the corresponding Hamiltonian matrix, if DICO = 'C'\nC and JOBB = 'G'. That is,\nC\nC (S S )\nC ( 11 12)\nC S = ( ),\nC (0 S )\nC ( 22)\nC\nC where S , S and S are N-by-N matrices.\nC 11 12 22\nC Array S must have 2*N+M columns if JOBB = 'B', and 2*N\nC columns, otherwise.\nC\nC LDS INTEGER\nC The leading dimension of array S.\nC LDS >= MAX(1,2*N+M) if JOBB = 'B',\nC LDS >= MAX(1,2*N) if JOBB = 'G'.\nC\nC T (output) DOUBLE PRECISION array, dimension (LDT,2*N)\nC If DICO = 'D' or JOBB = 'B', the leading 2N-by-2N part of\nC this array contains the ordered upper triangular form T of\nC the second matrix in the reduced matrix pencil associated\nC to the optimal problem. That is,\nC\nC (T T )\nC ( 11 12)\nC T = ( ),\nC (0 T )\nC ( 22)\nC\nC where T , T and T are N-by-N matrices.\nC 11 12 22\nC If DICO = 'C' and JOBB = 'G' this array is not referenced.\nC\nC LDT INTEGER\nC The leading dimension of array T.\nC LDT >= MAX(1,2*N+M) if JOBB = 'B',\nC LDT >= MAX(1,2*N) if JOBB = 'G' and DICO = 'D',\nC LDT >= 1 if JOBB = 'G' and DICO = 'C'.\nC\nC U (output) DOUBLE PRECISION array, dimension (LDU,2*N)\nC The leading 2N-by-2N part of this array contains the right\nC transformation matrix U which reduces the 2N-by-2N matrix\nC pencil to the ordered generalized real Schur form (S,T),\nC or the Hamiltonian matrix to the ordered real Schur\nC form S, if DICO = 'C' and JOBB = 'G'. That is,\nC\nC (U U )\nC ( 11 12)\nC U = ( ),\nC (U U )\nC ( 21 22)\nC\nC where U , U , U and U are N-by-N matrices.\nC 11 12 21 22\nC\nC LDU INTEGER\nC The leading dimension of array U. LDU >= MAX(1,2*N).\nC\nC Tolerances\nC\nC TOL DOUBLE PRECISION\nC The tolerance to be used to test for near singularity of\nC the original matrix pencil, specifically of the triangular\nC factor obtained during the reduction process. If the user\nC sets TOL > 0, then the given value of TOL is used as a\nC lower bound for the reciprocal condition number of that\nC matrix; a matrix whose estimated condition number is less\nC than 1/TOL is considered to be nonsingular. If the user\nC sets TOL <= 0, then a default tolerance, defined by\nC TOLDEF = EPS, is used instead, where EPS is the machine\nC precision (see LAPACK Library routine DLAMCH).\nC This parameter is not referenced if JOBB = 'G'.\nC\nC Workspace\nC\nC IWORK INTEGER array, dimension (LIWORK)\nC LIWORK >= MAX(1,M,2*N) if JOBB = 'B',\nC LIWORK >= MAX(1,2*N) if JOBB = 'G'.\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0, DWORK(1) returns the optimal value\nC of LDWORK. If JOBB = 'B' and N > 0, DWORK(2) returns the\nC reciprocal of the condition number of the M-by-M lower\nC triangular matrix obtained after compressing the matrix\nC pencil of order 2N+M to obtain a pencil of order 2N.\nC If INFO = 0 or INFO = 6, DWORK(3) returns the scaling\nC factor used internally, which should multiply the\nC submatrix Y2 to recover X from the first N columns of U\nC (see METHOD).\nC\nC LDWORK INTEGER\nC The length of the array DWORK.\nC LDWORK >= MAX(3,6*N), if JOBB = 'G',\nC DICO = 'C';\nC LDWORK >= MAX(7*(2*N+1)+16,16*N), if JOBB = 'G',\nC DICO = 'D';\nC LDWORK >= MAX(7*(2*N+1)+16,16*N,2*N+M,3*M), if JOBB = 'B'.\nC For optimum performance LDWORK should be larger.\nC\nC BWORK LOGICAL array, dimension (2*N)\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value;\nC = 1: if the computed extended matrix pencil is singular,\nC possibly due to rounding errors;\nC = 2: if the QZ (or QR) algorithm failed;\nC = 3: if reordering of the (generalized) eigenvalues\nC failed;\nC = 4: if after reordering, roundoff changed values of\nC some complex eigenvalues so that leading eigenvalues\nC in the (generalized) Schur form no longer satisfy\nC the stability condition; this could also be caused\nC due to scaling;\nC = 5: if the computed dimension of the solution does not\nC equal N;\nC = 6: if a singular matrix was encountered during the\nC computation of the solution matrix X.\nC\nC METHOD\nC\nC The routine uses a variant of the method of deflating subspaces\nC proposed by van Dooren [1]. See also [2], [3].\nC It is assumed that (A,B) is stabilizable and (C,A) is detectable.\nC Under these assumptions the algebraic Riccati equation is known to\nC have a unique non-negative definite solution.\nC The first step in the method of deflating subspaces is to form the\nC extended Hamiltonian matrices, dimension 2N + M given by\nC\nC discrete-time continuous-time\nC\nC |A 0 B| |I 0 0| |A 0 B| |I 0 0|\nC |Q -I L| - z |0 -A' 0|, |Q A' L| - s |0 -I 0|.\nC |L' 0 R| |0 -B' 0| |L' B' R| |0 0 0|\nC\nC Next, these pencils are compressed to a form (see [1])\nC\nC lambda x A - B .\nC f f\nC\nC This generalized eigenvalue problem is then solved using the QZ\nC algorithm and the stable deflating subspace Ys is determined.\nC If [Y1'|Y2']' is a basis for Ys, then the required solution is\nC -1\nC X = Y2 x Y1 .\nC A standard eigenvalue problem is solved using the QR algorithm in\nC the continuous-time case when G is given (DICO = 'C', JOBB = 'G').\nC\nC REFERENCES\nC\nC [1] Van Dooren, P.\nC A Generalized Eigenvalue Approach for Solving Riccati\nC Equations.\nC SIAM J. Sci. Stat. Comp., 2, pp. 121-135, 1981.\nC\nC [2] Mehrmann, V.\nC The Autonomous Linear Quadratic Control Problem. Theory and\nC Numerical Solution.\nC Lect. Notes in Control and Information Sciences, vol. 163,\nC Springer-Verlag, Berlin, 1991.\nC\nC [3] Sima, V.\nC Algorithms for Linear-Quadratic Optimization.\nC Pure and Applied Mathematics: A Series of Monographs and\nC Textbooks, vol. 200, Marcel Dekker, Inc., New York, 1996.\nC\nC NUMERICAL ASPECTS\nC\nC This routine is particularly suited for systems where the matrix R\nC is ill-conditioned. Internal scaling is used.\nC\nC FURTHER COMMENTS\nC\nC To obtain a stabilizing solution of the algebraic Riccati\nC equations set SORT = 'S'.\nC\nC The routine can also compute the anti-stabilizing solutions of\nC the algebraic Riccati equations, by specifying SORT = 'U'.\nC\nC CONTRIBUTOR\nC\nC Release 3.0: V. Sima, Katholieke Univ. Leuven, Belgium, Sep. 1997.\nC Supersedes Release 2.0 routine SB02CD by T.G.J. Beelen, Philips,\nC Eindhoven, Holland.\nC\nC REVISIONS\nC\nC V. Sima, Katholieke Univ. Leuven, Belgium, May 1999, June 2002,\nC December 2002, January 2005.\nC\nC KEYWORDS\nC\nC Algebraic Riccati equation, closed loop system, continuous-time\nC system, discrete-time system, optimal regulator, Schur form.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, HALF, ONE, THREE\n PARAMETER ( ZERO = 0.0D0, HALF = 0.5D0, ONE = 1.0D0,\n $ THREE = 3.0D0 )\nC .. Scalar Arguments ..\n CHARACTER DICO, FACT, JOBB, JOBL, SORT, UPLO\n INTEGER INFO, LDA, LDB, LDL, LDQ, LDR, LDS, LDT, LDU,\n $ LDWORK, LDX, M, N, P\n DOUBLE PRECISION RCOND, TOL\nC .. Array Arguments ..\n LOGICAL BWORK(*)\n INTEGER IWORK(*)\n DOUBLE PRECISION A(LDA,*), ALFAI(*), ALFAR(*), B(LDB,*), BETA(*),\n $ DWORK(*), L(LDL,*), Q(LDQ,*), R(LDR,*),\n $ S(LDS,*), T(LDT,*), U(LDU,*), X(LDX,*)\nC .. Local Scalars ..\n CHARACTER QTYPE, RTYPE\n LOGICAL DISCR, LFACB, LFACN, LFACQ, LFACR, LJOBB, LJOBL,\n $ LJOBLN, LSCAL, LSCL, LSORT, LUPLO\n INTEGER I, INFO1, J, LDW, MP, NDIM, NN, NNM, NP, NP1,\n $ WRKOPT\n DOUBLE PRECISION QSCAL, RCONDL, RNORM, RSCAL, SCALE, UNORM\nC .. Local Arrays ..\n DOUBLE PRECISION DUM(1)\nC .. External Functions ..\n LOGICAL LSAME, SB02MR, SB02MV, SB02OU, SB02OV, SB02OW\n DOUBLE PRECISION DLAMCH, DLANGE, DLANSY\n EXTERNAL DLAMCH, DLANGE, DLANSY, LSAME, SB02MR, SB02MV,\n $ SB02OU, SB02OV, SB02OW\nC .. External Subroutines ..\n EXTERNAL DAXPY, DCOPY, DGECON, DGEES, DGETRF, DGETRS,\n $ DGGES, DLACPY, DLASCL, DLASET, DSCAL, DSWAP,\n $ SB02OY, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC INT, MAX, MIN, SQRT\nC .. Executable Statements ..\nC\n INFO = 0\n DISCR = LSAME( DICO, 'D' )\n LJOBB = LSAME( JOBB, 'B' )\n LFACN = LSAME( FACT, 'N' )\n LFACQ = LSAME( FACT, 'C' )\n LFACR = LSAME( FACT, 'D' )\n LFACB = LSAME( FACT, 'B' )\n LUPLO = LSAME( UPLO, 'U' )\n LSORT = LSAME( SORT, 'S' )\nC\n NN = 2*N\n IF ( LJOBB ) THEN\n LJOBL = LSAME( JOBL, 'Z' )\n LJOBLN = LSAME( JOBL, 'N' )\n NNM = NN + M\n LDW = MAX( NNM, 3*M )\n ELSE\n NNM = NN\n LDW = 1\n END IF\n NP1 = N + 1\nC\nC Test the input scalar arguments.\nC\n IF( .NOT.DISCR .AND. .NOT.LSAME( DICO, 'C' ) ) THEN\n INFO = -1\n ELSE IF( .NOT.LJOBB .AND. .NOT.LSAME( JOBB, 'G' ) ) THEN\n INFO = -2\n ELSE IF( .NOT.LFACQ .AND. .NOT.LFACR .AND. .NOT.LFACB\n $ .AND. .NOT.LFACN ) THEN\n INFO = -3\n ELSE IF( .NOT.LJOBB .OR. LFACN ) THEN\n IF( .NOT.LUPLO .AND. .NOT.LSAME( UPLO, 'L' ) )\n $ INFO = -4\n END IF\n IF( INFO.EQ.0 .AND. LJOBB ) THEN\n IF( .NOT.LJOBL .AND. .NOT.LJOBLN )\n $ INFO = -5\n END IF\n IF( INFO.EQ.0 ) THEN\n IF( .NOT.LSORT .AND. .NOT.LSAME( SORT, 'U' ) ) THEN\n INFO = -6\n ELSE IF( N.LT.0 ) THEN\n INFO = -7\n ELSE IF( LJOBB ) THEN\n IF( M.LT.0 )\n $ INFO = -8\n END IF\n END IF\n IF( INFO.EQ.0 .AND. .NOT.LFACN ) THEN\n IF( P.LT.0 )\n $ INFO = -9\n END IF\n IF( INFO.EQ.0 ) THEN\n IF( LDA.LT.MAX( 1, N ) ) THEN\n INFO = -11\n ELSE IF( LDB.LT.MAX( 1, N ) ) THEN\n INFO = -13\n ELSE IF( ( ( LFACN.OR.LFACR ) .AND. LDQ.LT.MAX( 1, N ) ) .OR.\n $ ( ( LFACQ.OR.LFACB ) .AND. LDQ.LT.MAX( 1, P ) ) ) THEN\n INFO = -15\n ELSE IF( LDR.LT.1 ) THEN\n INFO = -17\n ELSE IF( LDL.LT.1 ) THEN\n INFO = -19\n ELSE IF( LJOBB ) THEN\n IF ( ( LFACN.OR.LFACQ ) .AND. LDR.LT.M .OR.\n $ ( LFACR.OR.LFACB ) .AND. LDR.LT.P ) THEN\n INFO = -17\n ELSE IF( LJOBLN .AND. LDL.LT.N ) THEN\n INFO = -19\n END IF\n END IF\n END IF\n IF( INFO.EQ.0 ) THEN\n IF( LDX.LT.MAX( 1, N ) ) THEN\n INFO = -22\n ELSE IF( LDS.LT.MAX( 1, NNM ) ) THEN\n INFO = -27\n ELSE IF( LDT.LT.1 ) THEN\n INFO = -29\n ELSE IF( LDU.LT.MAX( 1, NN ) ) THEN\n INFO = -31\n ELSE IF( LDWORK.LT.MAX( 3, 6*N ) ) THEN\n INFO = -35\n ELSE IF( DISCR .OR. LJOBB ) THEN\n IF( LDT.LT.NNM ) THEN\n INFO = -29\n ELSE IF( LDWORK.LT.MAX( 14*N + 23, 16*N, LDW ) ) THEN\n INFO = -35\n END IF\n END IF\n END IF\nC\n IF ( INFO.NE.0 ) THEN\nC\nC Error return.\nC\n CALL XERBLA( 'SB02OD', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF ( N.EQ.0 ) THEN\n RCOND = ONE\n DWORK(1) = THREE\n DWORK(3) = ONE\n RETURN\n END IF\nC\nC Always scale the matrix pencil.\nC\n LSCAL = .TRUE.\nC\nC Start computations.\nC\nC (Note: Comments in the code beginning \"Workspace:\" describe the\nC minimal amount of real workspace needed at that point in the\nC code, as well as the preferred amount for good performance.\nC NB refers to the optimal block size for the immediately\nC following subroutine, as returned by ILAENV.)\nC\n IF ( LSCAL .AND. LJOBB ) THEN\nC\nC Scale the matrices Q, R, and L so that\nC norm(Q) + norm(R) + norm(L) = 1,\nC using the 1-norm. If Q and/or R are factored, the norms of\nC the factors are used.\nC Workspace: need max(N,M), if FACT = 'N';\nC N, if FACT = 'D';\nC M, if FACT = 'C'.\nC\n IF ( LFACN .OR. LFACR ) THEN\n SCALE = DLANSY( '1-norm', UPLO, N, Q, LDQ, DWORK )\n QTYPE = UPLO\n NP = N\n ELSE\n SCALE = DLANGE( '1-norm', P, N, Q, LDQ, DWORK )\n QTYPE = 'G'\n NP = P\n END IF\nC\n IF ( LFACN .OR. LFACQ ) THEN\n RNORM = DLANSY( '1-norm', UPLO, M, R, LDR, DWORK )\n RTYPE = UPLO\n MP = M\n ELSE\n RNORM = DLANGE( '1-norm', P, M, R, LDR, DWORK )\n RTYPE = 'G'\n MP = P\n END IF\n SCALE = SCALE + RNORM\nC\n IF ( LJOBLN )\n $ SCALE = SCALE + DLANGE( '1-norm', N, M, L, LDL, DWORK )\n IF ( SCALE.EQ.ZERO )\n $ SCALE = ONE\nC\n IF ( LFACN .OR. LFACR ) THEN\n QSCAL = SCALE\n ELSE\n QSCAL = SQRT( SCALE )\n END IF\nC\n IF ( LFACN .OR. LFACQ ) THEN\n RSCAL = SCALE\n ELSE\n RSCAL = SQRT( SCALE )\n END IF\nC\n CALL DLASCL( QTYPE, 0, 0, QSCAL, ONE, NP, N, Q, LDQ, INFO1 )\n CALL DLASCL( RTYPE, 0, 0, RSCAL, ONE, MP, M, R, LDR, INFO1 )\n IF ( LJOBLN )\n $ CALL DLASCL( 'G', 0, 0, SCALE, ONE, N, M, L, LDL, INFO1 )\n END IF\nC\nC Construct the extended matrix pair.\nC\nC Workspace: need 1, if JOBB = 'G',\nC max(1,2*N+M,3*M), if JOBB = 'B';\nC prefer larger.\nC\n CALL SB02OY( 'Optimal control', DICO, JOBB, FACT, UPLO, JOBL,\n $ 'Identity E', N, M, P, A, LDA, B, LDB, Q, LDQ, R,\n $ LDR, L, LDL, U, 1, S, LDS, T, LDT, TOL, IWORK, DWORK,\n $ LDWORK, INFO )\nC\n IF ( LSCAL .AND. LJOBB ) THEN\nC\nC Undo scaling of the data arrays.\nC\n CALL DLASCL( QTYPE, 0, 0, ONE, QSCAL, NP, N, Q, LDQ, INFO1 )\n CALL DLASCL( RTYPE, 0, 0, ONE, RSCAL, MP, M, R, LDR, INFO1 )\n IF ( LJOBLN )\n $ CALL DLASCL( 'G', 0, 0, ONE, SCALE, N, M, L, LDL, INFO1 )\n END IF\nC\n IF ( INFO.NE.0 )\n $ RETURN\n WRKOPT = DWORK(1)\n IF ( LJOBB ) RCONDL = DWORK(2)\nC\n IF ( LSCAL .AND. .NOT.LJOBB ) THEN\nC\nC This part of the code is used when G is given (JOBB = 'G').\nC A standard eigenproblem is solved in the continuous-time case.\nC Scale the Hamiltonian matrix S, if DICO = 'C', or the\nC symplectic pencil (S,T), if DICO = 'D', using the square roots\nC of the norms of the matrices Q and G.\nC Workspace: need N.\nC\n IF ( LFACN .OR. LFACR ) THEN\n SCALE = SQRT( DLANSY( '1-norm', UPLO, N, Q, LDQ, DWORK ) )\n ELSE\n SCALE = DLANGE( '1-norm', P, N, Q, LDQ, DWORK )\n END IF\n RNORM = SQRT( DLANSY( '1-norm', UPLO, N, B, LDB, DWORK ) )\nC\n LSCL = MIN( SCALE, RNORM ).GT.ZERO .AND. SCALE.NE.RNORM\nC\n IF( LSCL ) THEN\n IF( DISCR ) THEN\n CALL DLASCL( 'G', 0, 0, SCALE, RNORM, N, N, S(NP1,1),\n $ LDS, INFO1 )\n CALL DLASCL( 'G', 0, 0, RNORM, SCALE, N, N, T(1,NP1),\n $ LDT, INFO1 )\n ELSE\n CALL DLASCL( 'G', 0, 0, SCALE, -RNORM, N, N, S(NP1,1),\n $ LDS, INFO1 )\n CALL DLASCL( 'G', 0, 0, RNORM, SCALE, N, N, S(1,NP1),\n $ LDS, INFO1 )\n CALL DLASCL( 'G', 0, 0, ONE, -ONE, N, N, S(NP1,NP1),\n $ LDS, INFO1 )\n END IF\n ELSE\n IF( .NOT.DISCR ) THEN\n CALL DLASCL( 'G', 0, 0, ONE, -ONE, N, NN, S(NP1,1), LDS,\n $ INFO1 )\n END IF\n END IF\n ELSE\n LSCL = .FALSE.\n END IF\nC\nC Workspace: need max(7*(2*N+1)+16,16*N),\nC if JOBB = 'B' or DICO = 'D';\nC 6*N, if JOBB = 'G' and DICO = 'C';\nC prefer larger.\nC\n IF ( DISCR ) THEN\n IF ( LSORT ) THEN\nC\nC The natural tendency of the QZ algorithm to get the largest\nC eigenvalues in the leading part of the matrix pair is\nC exploited, by computing the unstable eigenvalues of the\nC permuted matrix pair.\nC\n CALL DGGES( 'No vectors', 'Vectors', 'Sort', SB02OV, NN, T,\n $ LDT, S, LDS, NDIM, ALFAR, ALFAI, BETA, U, LDU,\n $ U, LDU, DWORK, LDWORK, BWORK, INFO1 )\n CALL DSWAP( N, ALFAR(NP1), 1, ALFAR, 1 )\n CALL DSWAP( N, ALFAI(NP1), 1, ALFAI, 1 )\n CALL DSWAP( N, BETA (NP1), 1, BETA, 1 )\n ELSE\n CALL DGGES( 'No vectors', 'Vectors', 'Sort', SB02OV, NN, S,\n $ LDS, T, LDT, NDIM, ALFAR, ALFAI, BETA, U, LDU,\n $ U, LDU, DWORK, LDWORK, BWORK, INFO1 )\n END IF\n ELSE\n IF ( LJOBB ) THEN\n IF ( LSORT ) THEN\n CALL DGGES( 'No vectors', 'Vectors', 'Sort', SB02OW, NN,\n $ S, LDS, T, LDT, NDIM, ALFAR, ALFAI, BETA, U,\n $ LDU, U, LDU, DWORK, LDWORK, BWORK, INFO1 )\n ELSE\n CALL DGGES( 'No vectors', 'Vectors', 'Sort', SB02OU, NN,\n $ S, LDS, T, LDT, NDIM, ALFAR, ALFAI, BETA, U,\n $ LDU, U, LDU, DWORK, LDWORK, BWORK, INFO1 )\n END IF\n ELSE\n IF ( LSORT ) THEN\n CALL DGEES( 'Vectors', 'Sort', SB02MV, NN, S, LDS, NDIM,\n $ ALFAR, ALFAI, U, LDU, DWORK, LDWORK, BWORK,\n $ INFO1 )\n ELSE\n CALL DGEES( 'Vectors', 'Sort', SB02MR, NN, S, LDS, NDIM,\n $ ALFAR, ALFAI, U, LDU, DWORK, LDWORK, BWORK,\n $ INFO1 )\n END IF\n DUM(1) = ONE\n CALL DCOPY( NN, DUM, 0, BETA, 1 )\n END IF\n END IF\n IF ( INFO1.GT.0 .AND. INFO1.LE.NN+1 ) THEN\n INFO = 2\n ELSE IF ( INFO1.EQ.NN+2 ) THEN\n INFO = 4\n ELSE IF ( INFO1.EQ.NN+3 ) THEN\n INFO = 3\n ELSE IF ( NDIM.NE.N ) THEN\n INFO = 5\n END IF\n IF ( INFO.NE.0 )\n $ RETURN\n WRKOPT = MAX( WRKOPT, INT( DWORK(1) ) )\nC\nC Select submatrices U1 and U2 out of the array U which define the\nC solution X = U2 x inv(U1).\nC Since X = X' we may obtain X as the solution of the system of\nC linear equations U1' x X = U2', where\nC U1 = U(1:n, 1:n),\nC U2 = U(n+1:2n, 1:n).\nC Use the (2,1) block of S as a workspace for factoring U1.\nC\n DO 20 J = 1, N\n CALL DCOPY( N, U(NP1,J), 1, X(J,1), LDX )\n 20 CONTINUE\nC\n CALL DLACPY( 'Full', N, N, U, LDU, S(NP1,1), LDS )\nC\nC Check if U1 is singular.\nC\n UNORM = DLANGE( '1-norm', N, N, S(NP1,1), LDS, DWORK )\nC\nC Solve the system U1' x X = U2'.\nC\n CALL DGETRF( N, N, S(NP1,1), LDS, IWORK, INFO1 )\n IF ( INFO1.NE.0 ) THEN\n INFO = 6\n DWORK(3) = ONE\n IF ( LSCAL ) THEN\n IF ( LJOBB ) THEN\n DWORK(3) = SCALE\n ELSE IF ( LSCL ) THEN\n DWORK(3) = SCALE / RNORM\n END IF\n END IF\n RETURN\n ELSE\nC\nC Estimate the reciprocal condition of U1.\nC Workspace: need 3*N.\nC\n CALL DGECON( '1-norm', N, S(NP1,1), LDS, UNORM, RCOND, DWORK,\n $ IWORK(NP1), INFO )\nC\n IF ( RCOND.LT.DLAMCH( 'Epsilon' ) ) THEN\nC\nC Nearly singular matrix. Set INFO for error return.\nC\n INFO = 6\n RETURN\n END IF\n WRKOPT = MAX( WRKOPT, 3*N )\n CALL DGETRS( 'Transpose', N, N, S(NP1,1), LDS, IWORK, X, LDX,\n $ INFO1 )\nC\nC Set S(2,1) to zero.\nC\n CALL DLASET( 'Full', N, N, ZERO, ZERO, S(NP1,1), LDS )\nC\n IF ( LSCAL ) THEN\nC\nC Prepare to undo scaling for the solution X.\nC\n IF ( .NOT.LJOBB ) THEN\n IF ( LSCL ) THEN\n SCALE = SCALE / RNORM\n ELSE\n SCALE = ONE\n END IF\n END IF\n DWORK(3) = SCALE\n SCALE = HALF*SCALE\n ELSE\n DWORK(3) = ONE\n SCALE = HALF\n END IF\nC\nC Make sure the solution matrix X is symmetric.\nC\n DO 40 I = 1, N\n CALL DAXPY( N-I+1, ONE, X(I,I), LDX, X(I,I), 1 )\n CALL DSCAL( N-I+1, SCALE, X(I,I), 1 )\n CALL DCOPY( N-I+1, X(I,I), 1, X(I,I), LDX )\n 40 CONTINUE\n END IF\nC\n DWORK(1) = WRKOPT\n IF ( LJOBB ) DWORK(2) = RCONDL\nC\n RETURN\nC *** Last line of SB02OD ***\n END\n", "meta": {"hexsha": "d47ca2d8c97ab2e06d87c615f535d1d642fbc7e7", "size": 32322, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/SB02OD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/SB02OD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/SB02OD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 38.3416370107, "max_line_length": 72, "alphanum_fraction": 0.5084771982, "num_tokens": 9903, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533088603708, "lm_q2_score": 0.718594386544335, "lm_q1q2_score": 0.6700557134617535}} {"text": " subroutine radec2pix(ra,dec,i,j,ra0,dec0,iref,jref,pixel,inverse)\n\n! Transformation for tangent-plane projection.\n!\n! Input parameters:\n!\tra,dec\t\t= equatorial position [deg]\n!\ti,j\t\t= pixel location\n!\tra0,dec0\t= reference position [deg]\n!\tiref,jref\t= reference pixel\n!\tpixel\t\t= pixel size [deg]\n!\tinverse\t\t= if .true., take the pixel location and calculate the\n!\t\t\t ra and dec.\n\n implicit real(8) (a-h,o-z)\n\n real(8), parameter :: dtor = 0.0174533 ! degrees to radians\n real(8) i, j, iref, jref, line\n logical inverse\n\n scale = 1.d0/pixel\n alpha0 = ra0*dtor\n delta0 = dec0*dtor\n\n if (inverse) then \n\t sample = i - iref\n\t line = jref - j\n\t x = sample*dtor/scale\n\t y = line*dtor/scale\n\t D = atan(sqrt(x**2 + y**2))\n\t B = atan2(-x,y)\n\t xx = sin(delta0)*sin(D)*cos(B) + cos(delta0)*cos(D)\n\t yy = sin(D)*sin(B)\n\t alpha = alpha0 + atan2(yy,xx)\n\t delta = asin(sin(delta0)*cos(D) - cos(delta0)*sin(D)*cos(B))\n\t ra = alpha/dtor\n\t dec = delta/dtor\n else\n\t alpha = ra*dtor\n\t delta = dec*dtor\n\t A = cos(delta)*cos(alpha - alpha0)\n\t F = (scale/dtor)/(sin(delta0)*sin(delta) + A*cos(delta0))\n\t line = -F*(cos(delta0)*sin(delta) - A*sin(delta0))\n\t sample = -F*cos(delta)*sin(alpha - alpha0)\n\t i = iref + sample\n\t j = jref - line\n endif\n\n return\n\n end\n", "meta": {"hexsha": "3a643bb90b8de02f1fd7b11b5c2e37a7d92f3fe2", "size": 1397, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "radec2pix.f90", "max_stars_repo_name": "teuben/ppmap", "max_stars_repo_head_hexsha": "2ff0b07350f883ee34ff4acc5eab374cdde8d327", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2018-05-31T16:15:35.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-12T14:22:57.000Z", "max_issues_repo_path": "radec2pix.f90", "max_issues_repo_name": "teuben/ppmap", "max_issues_repo_head_hexsha": "2ff0b07350f883ee34ff4acc5eab374cdde8d327", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-09-05T20:28:54.000Z", "max_issues_repo_issues_event_max_datetime": "2018-09-05T20:28:54.000Z", "max_forks_repo_path": "radec2pix.f90", "max_forks_repo_name": "teuben/ppmap", "max_forks_repo_head_hexsha": "2ff0b07350f883ee34ff4acc5eab374cdde8d327", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-05-31T16:15:28.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-07T16:35:39.000Z", "avg_line_length": 27.3921568627, "max_line_length": 76, "alphanum_fraction": 0.5669291339, "num_tokens": 458, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533069832974, "lm_q2_score": 0.718594386544335, "lm_q1q2_score": 0.6700557121128992}} {"text": "subroutine getDiffusionEquation1D(domain,LinearSolver)\n use plantFEM\n implicit none\n\n type(FEMDomain_),intent(inout)::domain\n type(LinearSolver_)::LinearSolver\n integer(int32) :: i,j,n,elemnum,&\n nodeid_1,nodeid_2,elemid,numdirichlet,node_id,dboundid,materialid\n real(real64) :: k,f,h_1,h_2,Le,x_1,x_2,val\n real(real64) :: Kmat(2,2),fvec(2)\n\n elemnum = size(domain%mesh%elemnod,1)\n do i=1, elemnum\n elemid = i\n nodeid_1 = domain%mesh%elemnod( elemid,1)\n nodeid_2 = domain%mesh%elemnod( elemid,2)\n materialid = domain%mesh%elemmat(elemid)\n \n x_1 = domain%mesh%nodcoord(nodeid_1,1)\n x_2 = domain%mesh%nodcoord(nodeid_2,1)\n\n Le = abs(x_2 - x_1)\n k = domain%materialprop%matpara(materialid,1)\n f = domain%materialprop%matpara(materialid,2)\n\n Kmat(1,1)= k/Le\n Kmat(1,2)= -k/Le\n Kmat(2,1)= -k/Le\n Kmat(2,2)= k/Le\n\n fvec(1) = 0.50d0*f*Le\n fvec(2) = 0.50d0*f*Le\n\n call LinearSolver%set(nodeid_1,nodeid_1, entryvalue= Kmat(1,1) )\n call LinearSolver%set(nodeid_1,nodeid_2, entryvalue= Kmat(1,2) )\n call LinearSolver%set(nodeid_2,nodeid_1, entryvalue= Kmat(2,1) )\n call LinearSolver%set(nodeid_2,nodeid_2, entryvalue= Kmat(2,2) )\n\n call LinearSolver%set(nodeid_1, entryvalue=fvec(1) )\n call LinearSolver%set(nodeid_2, entryvalue=fvec(2) )\n\n enddo\n\n ! \u30c7\u30a3\u30ea\u30af\u30ec\u5883\u754c\u6761\u4ef6\u3092\u5c0e\u5165\u3059\u308b\u3002\n numdirichlet = size(domain%Boundary%DboundNodID,1)\n \n do i=1,numdirichlet\n dboundid = i\n node_id = domain%Boundary%DboundNodID(dboundid,1)\n val = domain%Boundary%DboundVal(dboundid,1)\n call LinearSolver%fix(node_id, entryvalue=val)\n enddo\nend subroutine\n\n\nprogram main\n use plantFEM \n implicit none\n \n\n type(FEMDomain_)::domain ! \u6709\u9650\u8981\u7d20\u6cd5\u30b7\u30df\u30e5\u30ec\u30fc\u30b7\u30e7\u30f3\u306e\u305f\u3081\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30a2\u30d7\u30ea\n type(LinearSolver_)::LinearSolver ! \u9023\u7acb\u65b9\u7a0b\u5f0f\u3092\u89e3\u304f\u30a2\u30d7\u30ea\n type(IO_) :: file ! \u30d5\u30a1\u30a4\u30eb\u7de8\u96c6\u30a2\u30d7\u30ea \n integer(int32) :: i !\u6574\u6570\n\n ! FEM\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30a2\u30d7\u30ea\u3092\u8d77\u52d5\u3057\u3066\u3001\u30c7\u30fc\u30bf\u3092\u8aad\u307f\u8fbc\u3080\n\n ! \u547c\u3073\u51fa\u3057\u65b9 >> \u9818\u57df(domain)\u3000\u3092(%)\u3000\u8aad\u307f\u8fbc\u3080(import)\uff08\u30d5\u30a1\u30a4\u30eb\u540d\uff09\n call domain%import(node=.true.,file=\"./Node.txt\")\n call domain%import(element=.true.,file=\"./Element.txt\")\n call domain%import(materialinfo=.true.,file=\"./Materialinfo.txt\")\n call domain%import(Dirichlet=.true.,file=\"./DBoundary.txt\")\n \n ! \u4e00\u6b21\u5143\u5b9a\u5e38\u62e1\u6563\u65b9\u7a0b\u5f0f\u306b\u3064\u3044\u3066\u3001\u6709\u9650\u8981\u7d20\u6cd5\u3067\u96e2\u6563\u5316\u3057\u305f\u9023\u7acb\u65b9\u7a0b\u5f0f\u3092\u4f5c\u308a\u3001\u30bd\u30eb\u30d0\u30fc\u306b\u30bb\u30c3\u30c8\u3059\u308b\u3002\n ! \uff08\u4ee5\u4e0b\u3067\u306f\u3001\u3053\u306e\u30a2\u30d7\u30ea\u3092\u81ea\u4f5c\u3057\u307e\u3059\u3002\uff09\n call getDiffusionEquation1D(domain,LinearSolver)\n \n ! \u30bd\u30eb\u30d0\u30fc\u3092\u4f7f\u3063\u3066\u3001\u9023\u7acb\u65b9\u7a0b\u5f0f\u3092\u89e3\u304f\u3002\n ! \u9023\u7acb\u65b9\u7a0b\u5f0f\u3092\u89e3\u304f\u30a2\u30d7\u30ea(LinearSolver) \u306b(%) \u9023\u7acb\u65b9\u7a0b\u5f0f\u3092\u89e3\u3051(solve)\u3001\u3068\u547d\u4ee4\u3059\u308b\u3002\uff08CRSBiCGSTAB\u3067\uff09\n call LinearSolver%solve(Solver=\"BiCGSTAB\",CRS=.true.)\n \n ! \u7d50\u679c\u3092\u8868\u793a\u3059\u308b\u3002\n ! \u9023\u7acb\u65b9\u7a0b\u5f0f\u3092\u89e3\u304f\u30a2\u30d7\u30ea(LinearSolver) \u306e(%)\u3000\u89e3(x)\u3092\u8868\u793a\u3059\u308b\u3002\n print *, LinearSolver%x(:)\n\n ! \u7d50\u679c\u306e\u66f8\u304d\u51fa\u3057\n call file%open(\"./\"//\"result2\"//\".txt\")\n do i=1, size(LinearSolver%x)\n call file%write( str(LinearSolver%x(i)) )\n enddo\n call file%close()\n\n\nend program main", "meta": {"hexsha": "8f983489ba2189b1600f8e705ceaee8f287d838e", "size": 2913, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/playon_sim/ex0001_diffusion1D.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/sim/ex0001_diffusion1D.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/sim/ex0001_diffusion1D.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": 30.9893617021, "max_line_length": 73, "alphanum_fraction": 0.6470992104, "num_tokens": 1154, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947132556618, "lm_q2_score": 0.7090191214879991, "lm_q1q2_score": 0.6700193214033329}} {"text": "module earth\n\nuse trig, only: pi\n\n! Radius of the Earth (sphere of equivalent volume)\ndouble precision, parameter, public :: radius_earth_m = 6371.0d3\ndouble precision, parameter, public :: radius_earth_km = 6371.0d0\n\n! Kilometers per degree of great circle arc\ndouble precision, parameter, public :: deg2km = 2.0d0*pi*radius_earth_km/360.0d0\n\n! Geodetic Reference System 1980\ndouble precision, parameter, public :: eccentricity_grs80 = sqrt(0.00669438002290d0)\ndouble precision, parameter, public :: semimajor_grs80 = 6378137.0d0\ndouble precision, parameter, public :: semiminor_grs80 = 6356752.3141d0\ndouble precision, parameter, public :: radius_mean_grs80 = 6371008.7714d0\ndouble precision, parameter, public :: radius_surface_grs80 = 6371007.181d0\ndouble precision, parameter, public :: radius_volume_grs80 = 6371000.79d0\ndouble precision, parameter, public :: gravity_equator_grs80 = 9.7803267715d0\ndouble precision, parameter, public :: gravity_pole_grs80 = 9.8321863685d0\n\n! World Geodetic System 1984\ndouble precision, parameter, public :: semimajor_wgs84 = 6378137.0d0\ndouble precision, parameter, public :: semiminor_wgs84 = 6356752.314245d0\n\npublic :: sphere_geo2xyz\npublic :: sphere_xyz2geo\npublic :: ellipsoid_geo2xyz\npublic :: ellipsoid_xyz2geo\n\n! Milli-arc-seconds/year to degrees/million years\ndouble precision, parameter, public :: masa2degma = 1.0d6/(1.0d3*60.0d0*60.0d0)\n\n!----\n! Plate motion models (Euler poles => spherical Earth)\n!----\n! ITRF 2005\n! Altamimi, Z., Collileux, X., Legrand, J., Garayt, B., Boucher, C. (2007). ITRF2005: A new release\n! of the International Terrestrial Reference Frame based on time series of station positions\n! and Earth Orientation Parameters. Journal of Geophysical Research 112, B09401.\n! Rotations relative to ITRF2005 reference frame (identical to NNR-NUVEL1A)\ndouble precision, parameter, public :: itrf05_AM_lon = -102.789d0 ! Amur\ndouble precision, parameter, public :: itrf05_AM_lat = 52.263d0\ndouble precision, parameter, public :: itrf05_AM_vel = 0.269d0\ndouble precision, parameter, public :: itrf05_AN_lon = -125.315d0 ! Antarctica\ndouble precision, parameter, public :: itrf05_AN_lat = 59.813d0\ndouble precision, parameter, public :: itrf05_AN_vel = 0.223d0\ndouble precision, parameter, public :: itrf05_AR_lon = 5.061d0 ! Arabia\ndouble precision, parameter, public :: itrf05_AR_lat = 49.642d0\ndouble precision, parameter, public :: itrf05_AR_vel = 0.579d0\ndouble precision, parameter, public :: itrf05_AU_lon = 37.367d0 ! Australia\ndouble precision, parameter, public :: itrf05_AU_lat = 32.407d0\ndouble precision, parameter, public :: itrf05_AU_vel = 0.628d0\ndouble precision, parameter, public :: itrf05_CA_lon = -104.279d0 ! Caribbean\ndouble precision, parameter, public :: itrf05_CA_lat = 39.318d0\ndouble precision, parameter, public :: itrf05_CA_vel = 0.241d0\ndouble precision, parameter, public :: itrf05_EU_lon = -95.979d0 ! Eurasia\ndouble precision, parameter, public :: itrf05_EU_lat = 56.330d0\ndouble precision, parameter, public :: itrf05_EU_vel = 0.261d0\ndouble precision, parameter, public :: itrf05_IN_lon = 21.841d0 ! India\ndouble precision, parameter, public :: itrf05_IN_lat = 49.823d0\ndouble precision, parameter, public :: itrf05_IN_vel = 0.614d0\ndouble precision, parameter, public :: itrf05_NZ_lon = -101.441d0 ! Nazca\ndouble precision, parameter, public :: itrf05_NZ_lat = 45.101d0\ndouble precision, parameter, public :: itrf05_NZ_vel = 0.642d0\ndouble precision, parameter, public :: itrf05_NA_lon = -87.385d0 ! North America\ndouble precision, parameter, public :: itrf05_NA_lat = -4.291d0\ndouble precision, parameter, public :: itrf05_NA_vel = 0.192d0\ndouble precision, parameter, public :: itrf05_NU_lon = -82.501d0 ! Nubia\ndouble precision, parameter, public :: itrf05_NU_lat = 49.955d0\ndouble precision, parameter, public :: itrf05_NU_vel = 0.269d0\ndouble precision, parameter, public :: itrf05_OK_lon = -132.910d0 ! Okhotsk\ndouble precision, parameter, public :: itrf05_OK_lat = -32.041d0\ndouble precision, parameter, public :: itrf05_OK_vel = 0.083d0\ndouble precision, parameter, public :: itrf05_PA_lon = 112.873d0 ! Pacific\ndouble precision, parameter, public :: itrf05_PA_lat = -62.569d0\ndouble precision, parameter, public :: itrf05_PA_vel = 0.682d0\ndouble precision, parameter, public :: itrf05_SA_lon = -129.631d0 ! South America\ndouble precision, parameter, public :: itrf05_SA_lat = -16.800d0\ndouble precision, parameter, public :: itrf05_SA_vel = 0.121d0\ndouble precision, parameter, public :: itrf05_SM_lon = -89.542d0 ! Somalia\ndouble precision, parameter, public :: itrf05_SM_lat = 53.661d0\ndouble precision, parameter, public :: itrf05_SM_vel = 0.309d0\ndouble precision, parameter, public :: itrf05_YZ_lon = -109.737d0 ! Yangtze\ndouble precision, parameter, public :: itrf05_YZ_lat = 59.425d0\ndouble precision, parameter, public :: itrf05_YZ_vel = 0.310d0\ndouble precision, parameter, public :: itrf05_ITRF05_lon = 0d0 ! ITRF 2005\ndouble precision, parameter, public :: itrf05_ITRF05_lat = 0d0\ndouble precision, parameter, public :: itrf05_ITRF05_vel = 0d0\n\n! ITRF 2008\n! Altamimi, Z., Metivier, L., Collilieux, X. (2012). ITRF2008 plate motion model. Journal of\n! Geophysical Research 117, B07402.\n! Rotations relative to ITRF 2008 reference frame\ndouble precision, parameter, public :: itrf08_AM_lon = -113.261d0 ! Amur\ndouble precision, parameter, public :: itrf08_AM_lat = 62.265d0\ndouble precision, parameter, public :: itrf08_AM_vel = 0.287d0\ndouble precision, parameter, public :: itrf08_AN_lon = -129.261d0 ! Antarctica\ndouble precision, parameter, public :: itrf08_AN_lat = 58.545d0\ndouble precision, parameter, public :: itrf08_AN_vel = 0.209d0\ndouble precision, parameter, public :: itrf08_AR_lon = -2.572d0 ! Arabia\ndouble precision, parameter, public :: itrf08_AR_lat = 50.984d0\ndouble precision, parameter, public :: itrf08_AR_vel = 0.531d0\ndouble precision, parameter, public :: itrf08_AU_lon = 37.928d0 ! Australia\ndouble precision, parameter, public :: itrf08_AU_lat = 32.783d0\ndouble precision, parameter, public :: itrf08_AU_vel = 0.630d0\ndouble precision, parameter, public :: itrf08_CA_lon = -87.421d0 ! Caribbean\ndouble precision, parameter, public :: itrf08_CA_lat = 31.370d0\ndouble precision, parameter, public :: itrf08_CA_vel = 0.354d0\ndouble precision, parameter, public :: itrf08_EU_lon = -98.835d0 ! Eurasia\ndouble precision, parameter, public :: itrf08_EU_lat = 54.225d0\ndouble precision, parameter, public :: itrf08_EU_vel = 0.257d0\ndouble precision, parameter, public :: itrf08_IN_lon = 13.817d0 ! India\ndouble precision, parameter, public :: itrf08_IN_lat = 50.517d0\ndouble precision, parameter, public :: itrf08_IN_vel = 0.554d0\ndouble precision, parameter, public :: itrf08_NZ_lon = -102.011d0 ! Nazca\ndouble precision, parameter, public :: itrf08_NZ_lat = 45.701d0\ndouble precision, parameter, public :: itrf08_NZ_vel = 0.631d0\ndouble precision, parameter, public :: itrf08_NA_lon = -86.974d0 ! North America\ndouble precision, parameter, public :: itrf08_NA_lat = -8.578d0\ndouble precision, parameter, public :: itrf08_NA_vel = 0.186d0\ndouble precision, parameter, public :: itrf08_NU_lon = -80.973d0 ! Nubia\ndouble precision, parameter, public :: itrf08_NU_lat = 50.054d0\ndouble precision, parameter, public :: itrf08_NU_vel = 0.262d0\ndouble precision, parameter, public :: itrf08_PA_lon = 111.639d0 ! Pacific\ndouble precision, parameter, public :: itrf08_PA_lat = -62.771d0\ndouble precision, parameter, public :: itrf08_PA_vel = 0.677d0\ndouble precision, parameter, public :: itrf08_SA_lon = -128.002d0 ! South America\ndouble precision, parameter, public :: itrf08_SA_lat = -21.315d0\ndouble precision, parameter, public :: itrf08_SA_vel = 0.118d0\ndouble precision, parameter, public :: itrf08_SM_lon = -96.129d0 ! Somalia\ndouble precision, parameter, public :: itrf08_SM_lat = 50.127d0\ndouble precision, parameter, public :: itrf08_SM_vel = 0.325d0\ndouble precision, parameter, public :: itrf08_SU_lon = -87.309d0 ! Sunda\ndouble precision, parameter, public :: itrf08_SU_lat = 44.243d0\ndouble precision, parameter, public :: itrf08_SU_vel = 0.388d0\ndouble precision, parameter, public :: itrf08_ITRF05_lon = 0d0 ! ITRF 2005\ndouble precision, parameter, public :: itrf08_ITRF05_lat = 0d0\ndouble precision, parameter, public :: itrf08_ITRF05_vel = 0d0\ndouble precision, parameter, public :: itrf08_ITRF08_lon = 0d0 ! ITRF 2008\ndouble precision, parameter, public :: itrf08_ITRF08_lat = 0d0\ndouble precision, parameter, public :: itrf08_ITRF08_vel = 0d0\n\n! MORVEL\n! Demets, C., Gordon, R.G., Argus, D.F. (2010). Geologically current plate motions.\n! Geophysical Journal International 181, 1-80.\n! Rotations relative to the Pacific (PA) plate\ndouble precision, parameter, public :: morvel_PA_lon = 0.0d0 ! Pacific\ndouble precision, parameter, public :: morvel_PA_lat = 0.0d0\ndouble precision, parameter, public :: morvel_PA_vel = 0.000d0\ndouble precision, parameter, public :: morvel_AM_lon = -82.7d0 ! Amur\ndouble precision, parameter, public :: morvel_AM_lat = 65.9d0\ndouble precision, parameter, public :: morvel_AM_vel = 0.929d0\ndouble precision, parameter, public :: morvel_AN_lon = -78.5d0 ! Antarctica\ndouble precision, parameter, public :: morvel_AN_lat = 65.9d0\ndouble precision, parameter, public :: morvel_AN_vel = 0.887d0\ndouble precision, parameter, public :: morvel_AR_lon = -33.2d0 ! Arabia\ndouble precision, parameter, public :: morvel_AR_lat = 60.0d0\ndouble precision, parameter, public :: morvel_AR_vel = 1.159d0\ndouble precision, parameter, public :: morvel_AU_lon = 6.3d0 ! Australia\ndouble precision, parameter, public :: morvel_AU_lat = 60.1d0\ndouble precision, parameter, public :: morvel_AU_vel = 1.079d0\ndouble precision, parameter, public :: morvel_CA_lon = -77.5d0 ! Caribbean\ndouble precision, parameter, public :: morvel_CA_lat = 55.8d0\ndouble precision, parameter, public :: morvel_CA_vel = 0.905d0\ndouble precision, parameter, public :: morvel_CO_lon = -112.8d0 ! Cocos\ndouble precision, parameter, public :: morvel_CO_lat = 42.2d0\ndouble precision, parameter, public :: morvel_CO_vel = 1.676d0\ndouble precision, parameter, public :: morvel_CP_lon = -10.1d0 ! Capricorn (Indian Ocean)\ndouble precision, parameter, public :: morvel_CP_lat = 62.3d0\ndouble precision, parameter, public :: morvel_CP_vel = 1.139d0\ndouble precision, parameter, public :: morvel_EU_lon = -78.9d0 ! Eurasia\ndouble precision, parameter, public :: morvel_EU_lat = 61.3d0\ndouble precision, parameter, public :: morvel_EU_vel = 0.856d0\ndouble precision, parameter, public :: morvel_IN_lon = -31.2d0 ! India\ndouble precision, parameter, public :: morvel_IN_lat = 61.4d0\ndouble precision, parameter, public :: morvel_IN_vel = 1.141d0\ndouble precision, parameter, public :: morvel_JF_lon = 37.8d0 ! Juan de Fuca\ndouble precision, parameter, public :: morvel_JF_lat = -0.6d0\ndouble precision, parameter, public :: morvel_JF_vel = 0.625d0\ndouble precision, parameter, public :: morvel_LW_lon = -66.9d0 ! Lwandle (South Madagascar)\ndouble precision, parameter, public :: morvel_LW_lat = 60.0d0\ndouble precision, parameter, public :: morvel_LW_vel = 0.932d0\ndouble precision, parameter, public :: morvel_MQ_lon = -8.0d0 ! Macquarie (South of New Zealand)\ndouble precision, parameter, public :: morvel_MQ_lat = 59.2d0\ndouble precision, parameter, public :: morvel_MQ_vel = 1.686d0\ndouble precision, parameter, public :: morvel_NA_lon = -71.7d0 ! North America\ndouble precision, parameter, public :: morvel_NA_lat = 48.9d0\ndouble precision, parameter, public :: morvel_NA_vel = 0.750d0\ndouble precision, parameter, public :: morvel_NU_lon = -66.6d0 ! Nubia\ndouble precision, parameter, public :: morvel_NU_lat = 58.7d0\ndouble precision, parameter, public :: morvel_NU_vel = 0.935d0\ndouble precision, parameter, public :: morvel_NZ_lon = -87.8d0 ! Nazca\ndouble precision, parameter, public :: morvel_NZ_lat = 55.9d0\ndouble precision, parameter, public :: morvel_NZ_vel = 1.311d0\ndouble precision, parameter, public :: morvel_PS_lon = -41.9d0 ! Philippine Sea\ndouble precision, parameter, public :: morvel_PS_lat = -4.6d0\ndouble precision, parameter, public :: morvel_PS_vel = 0.890d0\ndouble precision, parameter, public :: morvel_RI_lon = -104.8d0 ! Rivera (North of Cocos Plate)\ndouble precision, parameter, public :: morvel_RI_lat = 25.7d0\ndouble precision, parameter, public :: morvel_RI_vel = 4.966d0\ndouble precision, parameter, public :: morvel_SA_lon = -77.0d0 ! South America\ndouble precision, parameter, public :: morvel_SA_lat = 56.0d0\ndouble precision, parameter, public :: morvel_SA_vel = 0.653d0\ndouble precision, parameter, public :: morvel_SC_lon = -78.0d0 ! Scotia\ndouble precision, parameter, public :: morvel_SC_lat = 57.8d0\ndouble precision, parameter, public :: morvel_SC_vel = 0.755d0\ndouble precision, parameter, public :: morvel_SM_lon = -73.5d0 ! Somalia (East Africa)\ndouble precision, parameter, public :: morvel_SM_lat = 59.3d0\ndouble precision, parameter, public :: morvel_SM_vel = 0.980d0\ndouble precision, parameter, public :: morvel_SR_lon = -75.8d0 ! Sur (East of Scotia Plate)\ndouble precision, parameter, public :: morvel_SR_lat = 55.7d0\ndouble precision, parameter, public :: morvel_SR_vel = 0.636d0\ndouble precision, parameter, public :: morvel_SU_lon = -78.0d0 ! Sunda\ndouble precision, parameter, public :: morvel_SU_lat = 59.8d0\ndouble precision, parameter, public :: morvel_SU_vel = 0.973d0\ndouble precision, parameter, public :: morvel_SW_lon = -42.4d0 ! Sandwich (East of Scotia Plate)\ndouble precision, parameter, public :: morvel_SW_lat = -3.8d0\ndouble precision, parameter, public :: morvel_SW_vel = 1.444d0\ndouble precision, parameter, public :: morvel_YZ_lon = -82.4d0 ! Yangtze\ndouble precision, parameter, public :: morvel_YZ_lat = 65.5d0\ndouble precision, parameter, public :: morvel_YZ_vel = 0.968d0\ndouble precision, parameter, public :: morvel_ITRF05_lon = -68.2d0 ! ITRF 2005 (Altamimi et al., 2007)\ndouble precision, parameter, public :: morvel_ITRF05_lat = 63.4d0\ndouble precision, parameter, public :: morvel_ITRF05_vel = 0.677d0\n\n! MORVEL56\n! Argus, D.F., Gordon, R.G., DeMets, C. (2011). Geologically current motion of 56 plates relative\n! to the no\u2010net\u2010rotation reference frame. Geochemistry Geophysics Geosystems 12.\n! Rotations relative to the Pacific (PA) plate\ndouble precision, parameter, public :: morvel56_PA_lon = 0.00d0 ! Pacific\ndouble precision, parameter, public :: morvel56_PA_lat = 0.00d0\ndouble precision, parameter, public :: morvel56_PA_vel = 0.000d0\ndouble precision, parameter, public :: morvel56_AM_lon = -82.68d0 ! Amur\ndouble precision, parameter, public :: morvel56_AM_lat = 65.92d0\ndouble precision, parameter, public :: morvel56_AM_vel = 0.929d0\ndouble precision, parameter, public :: morvel56_AN_lon = -78.53d0 ! Antarctica\ndouble precision, parameter, public :: morvel56_AN_lat = 65.92d0\ndouble precision, parameter, public :: morvel56_AN_vel = 0.887d0\ndouble precision, parameter, public :: morvel56_AR_lon = -33.23d0 ! Arabia\ndouble precision, parameter, public :: morvel56_AR_lat = 60.02d0\ndouble precision, parameter, public :: morvel56_AR_vel = 1.159d0\ndouble precision, parameter, public :: morvel56_AU_lon = 6.33d0 ! Australia\ndouble precision, parameter, public :: morvel56_AU_lat = 60.08d0\ndouble precision, parameter, public :: morvel56_AU_vel = 1.079d0\ndouble precision, parameter, public :: morvel56_CA_lon = -77.48d0 ! Caribbean\ndouble precision, parameter, public :: morvel56_CA_lat = 55.76d0\ndouble precision, parameter, public :: morvel56_CA_vel = 0.905d0\ndouble precision, parameter, public :: morvel56_CO_lon = -112.78d0 ! Cocos\ndouble precision, parameter, public :: morvel56_CO_lat = 42.18d0\ndouble precision, parameter, public :: morvel56_CO_vel = 1.676d0\ndouble precision, parameter, public :: morvel56_CP_lon = -10.12d0 ! Capricorn\ndouble precision, parameter, public :: morvel56_CP_lat = 62.34d0\ndouble precision, parameter, public :: morvel56_CP_vel = 1.139d0\ndouble precision, parameter, public :: morvel56_EU_lon = -78.87d0 ! Eurasia\ndouble precision, parameter, public :: morvel56_EU_lat = 61.27d0\ndouble precision, parameter, public :: morvel56_EU_vel = 0.856d0\ndouble precision, parameter, public :: morvel56_IN_lon = -31.21d0 ! India\ndouble precision, parameter, public :: morvel56_IN_lat = 61.39d0\ndouble precision, parameter, public :: morvel56_IN_vel = 1.141d0\ndouble precision, parameter, public :: morvel56_JF_lon = 37.84d0 ! Juan de Fuca\ndouble precision, parameter, public :: morvel56_JF_lat = -0.62d0\ndouble precision, parameter, public :: morvel56_JF_vel = 0.625d0\ndouble precision, parameter, public :: morvel56_LW_lon = -66.90d0 ! Lwandle\ndouble precision, parameter, public :: morvel56_LW_lat = 60.03d0\ndouble precision, parameter, public :: morvel56_LW_vel = 0.932d0\ndouble precision, parameter, public :: morvel56_MQ_lon = -7.98d0 ! Macquarie\ndouble precision, parameter, public :: morvel56_MQ_lat = 59.21d0\ndouble precision, parameter, public :: morvel56_MQ_vel = 1.686d0\ndouble precision, parameter, public :: morvel56_NA_lon = -71.71d0 ! North America\ndouble precision, parameter, public :: morvel56_NA_lat = 48.89d0\ndouble precision, parameter, public :: morvel56_NA_vel = 0.750d0\ndouble precision, parameter, public :: morvel56_NU_lon = -66.57d0 ! Nubia\ndouble precision, parameter, public :: morvel56_NU_lat = 58.68d0\ndouble precision, parameter, public :: morvel56_NU_vel = 0.935d0\ndouble precision, parameter, public :: morvel56_NZ_lon = -87.76d0 ! Nazca\ndouble precision, parameter, public :: morvel56_NZ_lat = 55.86d0\ndouble precision, parameter, public :: morvel56_NZ_vel = 1.311d0\ndouble precision, parameter, public :: morvel56_PS_lon = -41.87d0 ! Philippine Sea\ndouble precision, parameter, public :: morvel56_PS_lat = -4.63d0\ndouble precision, parameter, public :: morvel56_PS_vel = 0.890d0\ndouble precision, parameter, public :: morvel56_RI_lon = -104.80d0 ! Rivera\ndouble precision, parameter, public :: morvel56_RI_lat = 25.69d0\ndouble precision, parameter, public :: morvel56_RI_vel = 4.966d0\ndouble precision, parameter, public :: morvel56_SA_lon = -77.03d0 ! South America\ndouble precision, parameter, public :: morvel56_SA_lat = 55.98d0\ndouble precision, parameter, public :: morvel56_SA_vel = 0.653d0\ndouble precision, parameter, public :: morvel56_SC_lon = -78.02d0 ! Scotia\ndouble precision, parameter, public :: morvel56_SC_lat = 57.84d0\ndouble precision, parameter, public :: morvel56_SC_vel = 0.755d0\ndouble precision, parameter, public :: morvel56_SM_lon = -73.55d0 ! Somalia\ndouble precision, parameter, public :: morvel56_SM_lat = 59.27d0\ndouble precision, parameter, public :: morvel56_SM_vel = 0.980d0\ndouble precision, parameter, public :: morvel56_SR_lon = -75.77d0 ! Sur\ndouble precision, parameter, public :: morvel56_SR_lat = 55.69d0\ndouble precision, parameter, public :: morvel56_SR_vel = 0.636d0\ndouble precision, parameter, public :: morvel56_SU_lon = -77.96d0 ! Sunda\ndouble precision, parameter, public :: morvel56_SU_lat = 59.81d0\ndouble precision, parameter, public :: morvel56_SU_vel = 0.973d0\ndouble precision, parameter, public :: morvel56_SW_lon = -42.36d0 ! Sandwich\ndouble precision, parameter, public :: morvel56_SW_lat = -3.84d0\ndouble precision, parameter, public :: morvel56_SW_vel = 1.444d0\ndouble precision, parameter, public :: morvel56_YZ_lon = -82.38d0 ! Yangtze\ndouble precision, parameter, public :: morvel56_YZ_lat = 65.45d0\ndouble precision, parameter, public :: morvel56_YZ_vel = 0.968d0\ndouble precision, parameter, public :: morvel56_AS_lon = -70.76d0 ! Aegean Sea\ndouble precision, parameter, public :: morvel56_AS_lat = 74.36d0\ndouble precision, parameter, public :: morvel56_AS_vel = 0.648d0\ndouble precision, parameter, public :: morvel56_AP_lon = -77.01d0 ! Altiplano\ndouble precision, parameter, public :: morvel56_AP_lat = 34.56d0\ndouble precision, parameter, public :: morvel56_AP_vel = 0.929d0\ndouble precision, parameter, public :: morvel56_AT_lon = 9.12d0 ! Anatolia\ndouble precision, parameter, public :: morvel56_AT_lat = 54.82d0\ndouble precision, parameter, public :: morvel56_AT_vel = 1.667d0\ndouble precision, parameter, public :: morvel56_BR_lon = -111.00d0 ! Balmoral Reef\ndouble precision, parameter, public :: morvel56_BR_lat = 45.90d0\ndouble precision, parameter, public :: morvel56_BR_vel = 0.200d0\ndouble precision, parameter, public :: morvel56_BS_lon = 122.56d0 ! Banda Sea\ndouble precision, parameter, public :: morvel56_BS_lat = 13.34d0\ndouble precision, parameter, public :: morvel56_BS_vel = 2.248d0\ndouble precision, parameter, public :: morvel56_BH_lon = 88.39d0 ! Birds Head\ndouble precision, parameter, public :: morvel56_BH_lat = 11.59d0\ndouble precision, parameter, public :: morvel56_BH_vel = 0.346d0\ndouble precision, parameter, public :: morvel56_BU_lon = -76.63d0 ! Burma\ndouble precision, parameter, public :: morvel56_BU_lat = 7.86d0\ndouble precision, parameter, public :: morvel56_BU_vel = 2.523d0\ndouble precision, parameter, public :: morvel56_CL_lon = -27.64d0 ! Caroline Sea\ndouble precision, parameter, public :: morvel56_CL_lat = 0.99d0\ndouble precision, parameter, public :: morvel56_CL_vel = 0.199d0\ndouble precision, parameter, public :: morvel56_CR_lon = 174.43d0 ! Conway Reef\ndouble precision, parameter, public :: morvel56_CR_lat = -12.56d0\ndouble precision, parameter, public :: morvel56_CR_vel = 3.609d0\ndouble precision, parameter, public :: morvel56_EA_lon = 66.32d0 ! Easter\ndouble precision, parameter, public :: morvel56_EA_lat = 28.04d0\ndouble precision, parameter, public :: morvel56_EA_vel = 11.420d0\ndouble precision, parameter, public :: morvel56_FT_lon = -178.82d0 ! Futuna\ndouble precision, parameter, public :: morvel56_FT_lat = -10.12d0\ndouble precision, parameter, public :: morvel56_FT_vel = 4.847d0\ndouble precision, parameter, public :: morvel56_GP_lon = 79.43d0 ! Galapagos\ndouble precision, parameter, public :: morvel56_GP_lat = 8.94d0\ndouble precision, parameter, public :: morvel56_GP_vel = 5.307d0\ndouble precision, parameter, public :: morvel56_JZ_lon = 70.11d0 ! Juan Fernandez\ndouble precision, parameter, public :: morvel56_JZ_lat = 35.77d0\ndouble precision, parameter, public :: morvel56_JZ_vel = 22.532d0\ndouble precision, parameter, public :: morvel56_KE_lon = -1.83d0 ! Kermadec\ndouble precision, parameter, public :: morvel56_KE_lat = 47.61d0\ndouble precision, parameter, public :: morvel56_KE_vel = 2.832d0\ndouble precision, parameter, public :: morvel56_MN_lon = 150.46d0 ! Manus\ndouble precision, parameter, public :: morvel56_MN_lat = -3.04d0\ndouble precision, parameter, public :: morvel56_MN_vel = 51.300d0\ndouble precision, parameter, public :: morvel56_MO_lon = 79.96d0 ! Maoke\ndouble precision, parameter, public :: morvel56_MO_lat = 57.43d0\ndouble precision, parameter, public :: morvel56_MO_vel = 0.918d0\ndouble precision, parameter, public :: morvel56_MA_lon = 144.24d0 ! Mariana\ndouble precision, parameter, public :: morvel56_MA_lat = 39.19d0\ndouble precision, parameter, public :: morvel56_MA_vel = 1.319d0\ndouble precision, parameter, public :: morvel56_MS_lon = -56.78d0 ! Molucca Sea\ndouble precision, parameter, public :: morvel56_MS_lat = 10.54d0\ndouble precision, parameter, public :: morvel56_MS_vel = 3.915d0\ndouble precision, parameter, public :: morvel56_NH_lon = -12.00d0 ! New Hebrides\ndouble precision, parameter, public :: morvel56_NH_lat = 13.00d0\ndouble precision, parameter, public :: morvel56_NH_vel = 2.700d0\ndouble precision, parameter, public :: morvel56_NI_lon = -169.62d0 ! Niuafo'ou\ndouble precision, parameter, public :: morvel56_NI_lat = 6.95d0\ndouble precision, parameter, public :: morvel56_NI_vel = 3.248d0\ndouble precision, parameter, public :: morvel56_ND_lon = -80.24d0 ! North Andes\ndouble precision, parameter, public :: morvel56_ND_lat = 59.68d0\ndouble precision, parameter, public :: morvel56_ND_vel = 0.716d0\ndouble precision, parameter, public :: morvel56_NB_lon = 139.00d0 ! North Bismarck\ndouble precision, parameter, public :: morvel56_NB_lat = -4.00d0\ndouble precision, parameter, public :: morvel56_NB_vel = 0.330d0\ndouble precision, parameter, public :: morvel56_OK_lon = -76.20d0 ! Okhotsk\ndouble precision, parameter, public :: morvel56_OK_lat = 55.81d0\ndouble precision, parameter, public :: morvel56_OK_vel = 0.844d0\ndouble precision, parameter, public :: morvel56_ON_lon = 141.58d0 ! Okinawa\ndouble precision, parameter, public :: morvel56_ON_lat = 49.30d0\ndouble precision, parameter, public :: morvel56_ON_vel = 2.743d0\ndouble precision, parameter, public :: morvel56_PM_lon = -88.73d0 ! Panama\ndouble precision, parameter, public :: morvel56_PM_lat = 55.66d0\ndouble precision, parameter, public :: morvel56_PM_vel = 0.906d0\ndouble precision, parameter, public :: morvel56_SL_lon = -92.39d0 ! Shetland\ndouble precision, parameter, public :: morvel56_SL_lat = 65.24d0\ndouble precision, parameter, public :: morvel56_SL_vel = 0.870d0\ndouble precision, parameter, public :: morvel56_SS_lon = 133.82d0 ! Solomon Sea\ndouble precision, parameter, public :: morvel56_SS_lat = 19.26d0\ndouble precision, parameter, public :: morvel56_SS_vel = 1.509d0\ndouble precision, parameter, public :: morvel56_SB_lon = -32.99d0 ! South Bismarck\ndouble precision, parameter, public :: morvel56_SB_lat = 10.61d0\ndouble precision, parameter, public :: morvel56_SB_vel = 8.440d0\ndouble precision, parameter, public :: morvel56_TI_lon = 113.28d0 ! Timor\ndouble precision, parameter, public :: morvel56_TI_lat = 15.62d0\ndouble precision, parameter, public :: morvel56_TI_vel = 1.629d0\ndouble precision, parameter, public :: morvel56_TO_lon = 2.57d0 ! Tonga\ndouble precision, parameter, public :: morvel56_TO_lat = 28.82d0\ndouble precision, parameter, public :: morvel56_TO_vel = 9.303d0\ndouble precision, parameter, public :: morvel56_WL_lon = 131.23d0 ! Woodlark\ndouble precision, parameter, public :: morvel56_WL_lat = 21.81d0\ndouble precision, parameter, public :: morvel56_WL_vel = 1.578d0\ndouble precision, parameter, public :: morvel56_NNR_lon = -65.30d0 ! No net rotation\ndouble precision, parameter, public :: morvel56_NNR_lat = 63.58d0\ndouble precision, parameter, public :: morvel56_NNR_vel = 0.651d0\ndouble precision, parameter, public :: morvel56_ITRF08_lon = -69.696d0 ! ITRF 2008\ndouble precision, parameter, public :: morvel56_ITRF08_lat = 64.232d0 ! computed with subroutine below\ndouble precision, parameter, public :: morvel56_ITRF08_vel = 0.649d0\n\n\n! NUVEL-1A\n! DeMets, C., Gordon, R.G., Argus, D.F., Stein, S. (1994). Effect of recent revisions to the\n! geomagnetic reversal time scale on estimates of current plate motions. Geophysical Research\n! Letters 21, 2191-2194.\n! Rotations relative to the Pacific (PA) plate\ndouble precision, parameter, public :: nuvel1a_PA_lon = 0.000d0 ! Pacific\ndouble precision, parameter, public :: nuvel1a_PA_lat = 0.000d0\ndouble precision, parameter, public :: nuvel1a_PA_vel = 0.0000d0\ndouble precision, parameter, public :: nuvel1a_AF_lon = -73.174d0 ! Africa\ndouble precision, parameter, public :: nuvel1a_AF_lat = 59.160d0\ndouble precision, parameter, public :: nuvel1a_AF_vel = 0.9270d0\ndouble precision, parameter, public :: nuvel1a_AN_lon = -83.984d0 ! Antarctica\ndouble precision, parameter, public :: nuvel1a_AN_lat = 64.315d0\ndouble precision, parameter, public :: nuvel1a_AN_vel = 0.8695d0\ndouble precision, parameter, public :: nuvel1a_AR_lon = -33.193d0 ! Arabia\ndouble precision, parameter, public :: nuvel1a_AR_lat = 59.658d0\ndouble precision, parameter, public :: nuvel1a_AR_vel = 1.1107d0\ndouble precision, parameter, public :: nuvel1a_AU_lon = 1.742d0 ! Australia\ndouble precision, parameter, public :: nuvel1a_AU_lat = 60.080d0\ndouble precision, parameter, public :: nuvel1a_AU_vel = 1.0744d0\ndouble precision, parameter, public :: nuvel1a_CA_lon = -80.802d0 ! Caribbean\ndouble precision, parameter, public :: nuvel1a_CA_lat = 54.195d0\ndouble precision, parameter, public :: nuvel1a_CA_vel = 0.8160d0\ndouble precision, parameter, public :: nuvel1a_CO_lon = 251.371d0 ! Cocos\ndouble precision, parameter, public :: nuvel1a_CO_lat = 36.823d0\ndouble precision, parameter, public :: nuvel1a_CO_vel = 1.9975d0\ndouble precision, parameter, public :: nuvel1a_EU_lon = -85.819d0 ! Eurasia\ndouble precision, parameter, public :: nuvel1a_EU_lat = 61.066d0\ndouble precision, parameter, public :: nuvel1a_EU_vel = 0.8591d0\ndouble precision, parameter, public :: nuvel1a_IN_lon = -30.403d0 ! India\ndouble precision, parameter, public :: nuvel1a_IN_lat = 60.494d0\ndouble precision, parameter, public :: nuvel1a_IN_vel = 1.1034d0\ndouble precision, parameter, public :: nuvel1a_JF_lon = 29.3d0 ! Juan de Fuca\ndouble precision, parameter, public :: nuvel1a_JF_lat = 28.3d0\ndouble precision, parameter, public :: nuvel1a_JF_vel = 0.520d0\ndouble precision, parameter, public :: nuvel1a_NA_lon = -78.167d0 ! North America\ndouble precision, parameter, public :: nuvel1a_NA_lat = 48.709d0\ndouble precision, parameter, public :: nuvel1a_NA_vel = 0.7486d0\ndouble precision, parameter, public :: nuvel1a_NZ_lon = -90.096d0 ! Nazca\ndouble precision, parameter, public :: nuvel1a_NZ_lat = 55.578d0\ndouble precision, parameter, public :: nuvel1a_NZ_vel = 1.3599d0\ndouble precision, parameter, public :: nuvel1a_PS_lon = -1.2d0 ! Philippine Sea\ndouble precision, parameter, public :: nuvel1a_PS_lat = -45.8d0\ndouble precision, parameter, public :: nuvel1a_PS_vel = 0.96d0\ndouble precision, parameter, public :: nuvel1a_RI_lon = 257.6d0 ! Rivera\ndouble precision, parameter, public :: nuvel1a_RI_lat = 31.0d0\ndouble precision, parameter, public :: nuvel1a_RI_vel = 2.45d0\ndouble precision, parameter, public :: nuvel1a_SA_lon = -85.752d0 ! South America\ndouble precision, parameter, public :: nuvel1a_SA_lat = 54.999d0\ndouble precision, parameter, public :: nuvel1a_SA_vel = 0.6365d0\ndouble precision, parameter, public :: nuvel1a_SC_lon = -81.4d0 ! Scotia\ndouble precision, parameter, public :: nuvel1a_SC_lat = 49.1d0\ndouble precision, parameter, public :: nuvel1a_SC_vel = 0.66d0\ndouble precision, parameter, public :: nuvel1a_NNR_lon = -72.6d0 ! No net rotation\ndouble precision, parameter, public :: nuvel1a_NNR_lat = 63.0d0\ndouble precision, parameter, public :: nuvel1a_NNR_vel = 0.6411d0\n\n!--------------------------------------------------------------------------------------------------!\ncontains\n!--------------------------------------------------------------------------------------------------!\n\n!--------------------------------------------------------------------------------------------------!\n!--------------------------------------------------------------------------------------------------!\n!------------------------------- EARTH SHAPE SUBROUTINES ------------------------------------------!\n!--------------------------------------------------------------------------------------------------!\n!--------------------------------------------------------------------------------------------------!\n\nsubroutine sphere_xyz2geo(x,y,z,lon,lat,height,radius)\n!----\n! Given a point in Cartesian coordinates with origin at the center of a sphere, calculate the\n! longitude, latitude, and height above the surface of the sphere.\n!----\n\nuse trig, only: r2d\n\nimplicit none\n\n! Arguments\ndouble precision :: x, y, z, lon, lat, height, radius\n\n\n! Longitude depends only on x and y\nlon = atan2(y,x)*r2d\n\n! Latitude depends on z and the horizontal distance, sqrt(x^2+y^2)\nlat = atan2(z,sqrt(x*x+y*y))*r2d\n\n! Height is the total distance from origin minus the radius of the sphere\nheight = sqrt(x*x+y*y+z*z) - radius\n\nreturn\nend subroutine\n\n!--------------------------------------------------------------------------------------------------!\n\nsubroutine sphere_geo2xyz(lon,lat,height,x,y,z,radius)\n!----\n! Given a point in geographic coordinates and its height above the surface of a sphere, calculate\n! its Cartesian coordinates (origin at the center of the sphere).\n!----\n\nuse trig, only: d2r\n\nimplicit none\n\n! Arguments\ndouble precision :: lon, lat, height, x, y, z, radius\n\n! Local variables\ndouble precision :: R\n\n\nR = radius + height\n\nx = R*cos(lat*d2r)*cos(lon*d2r)\ny = R*cos(lat*d2r)*sin(lon*d2r)\nz = R*sin(lat*d2r)\n\nreturn\nend subroutine\n\n!--------------------------------------------------------------------------------------------------!\n\nsubroutine ellipsoid_xyz2geo(x,y,z,lon,lat,height,semimajor,eccentricity,iterations)\n!----\n! Given a point in Cartesian coordinates with origin at the center of an ellipsoid, calculate the\n! longitude, latitude, and perpendicular height above the surface of the ellipsoid.\n!\n! Equations from:\n! Osborne, P. (2008). The Mercator Projections. 212 pp.\n!----\n\nuse trig, only: r2d\n\nimplicit none\n\n! Arguments\ndouble precision :: x, y, z, lon, lat, height, semimajor, eccentricity\ninteger :: iterations\n\n! Local variables\ndouble precision :: nu\ninteger :: i\n\n\n! The longitude is calculated the same way as for a sphere\nlon = atan2(y,x)*r2d\n\n! The latitude is computed iteratively\n! Start with the latitude on the surface of the ellipsoid\nlat = atan2(z,(1.0d0-eccentricity*eccentricity)*sqrt(x*x+y*y))\n\n! Distance between point on ellipsoid and central axis of ellipsoid, perpendicular to surface\nnu = semimajor/sqrt(1.0d0-eccentricity*eccentricity*sin(lat)*sin(lat))\n\n! Iterate over latitude\ndo i = 1,iterations\n lat = atan2(z+eccentricity*eccentricity*nu*sin(lat),sqrt(x*x+y*y))\n nu = semimajor/sqrt(1.0d0-eccentricity*eccentricity*sin(lat)*sin(lat))\nenddo\n\n! Elevation perpendicular to ellipsoid surface\nheight = 1.0d0/cos(lat)*sqrt(x*x+y*y)-nu\n\nlat = lat*r2d\n\nreturn\nend subroutine\n\n!--------------------------------------------------------------------------------------------------!\n\nsubroutine ellipsoid_geo2xyz(lon,lat,height,x,y,z,semimajor,eccentricity)\n!----\n! Given a point in geographic coordinates and its perpendicular height above the surface of an\n! ellipsoid, calculate its Cartesian coordinates (origin at the center of the ellipsoid).\n!\n! Equations from:\n! Osborne, P. (2008). The Mercator Projections. 212 pp.\n!----\n\nuse trig, only: d2r\n\nimplicit none\n\n! Arguments\ndouble precision :: lon, lat, height, x, y, z, semimajor, eccentricity\n\n! Local variables\ndouble precision :: nu\n\n\nnu = semimajor/sqrt(1.0d0-eccentricity*eccentricity*sin(lat*d2r)*sin(lat*d2r))\n\nx = ( nu+height)*cos(lat*d2r)*cos(lon*d2r)\ny = ( nu+height)*cos(lat*d2r)*sin(lon*d2r)\nz = ((1.0d0-eccentricity*eccentricity)*nu+height)*sin(lat*d2r)\n\nreturn\nend subroutine\n\n!--------------------------------------------------------------------------------------------------!\n!--------------------------------------------------------------------------------------------------!\n!------------------------------ PLATE CIRCUIT SUBROUTINES -----------------------------------------!\n!--------------------------------------------------------------------------------------------------!\n!--------------------------------------------------------------------------------------------------!\n\nsubroutine pole_xyz2geo(pole_x,pole_y,pole_z,pole_lon,pole_lat,pole_vel,earth_shape)\n!----\n! Given a rotation vector in Cartesian coordinates, calculate the Euler pole longitude, latitude,\n! and angular velocity (in the same units as input parameters).\n!----\n\nuse io, only: stderr\nuse trig, only: r2d\nuse algebra, only: normalize\n\nimplicit none\n\n! Arguments\ndouble precision :: pole_x, pole_y, pole_z, pole_lon, pole_lat, pole_vel\ncharacter(len=*) :: earth_shape\n\n! Local variables\ndouble precision :: vec(3)\n\n\npole_lon = 0.0d0\npole_lat = 0.0d0\npole_vel = 0.0d0\n\nif (earth_shape.eq.'sphere') then\n pole_lon = atan2(pole_y,pole_x)*r2d\n pole_lat = atan2(pole_z,sqrt(pole_x*pole_x+pole_y*pole_y))*r2d\n pole_vel = sqrt(pole_x*pole_x+pole_y*pole_y+pole_z*pole_z)\nelseif (earth_shape.eq.'grs80') then\n ! I am not sure this is right....\n vec(1) = pole_x\n vec(2) = pole_y\n vec(3) = pole_z\n call normalize(vec)\n vec = vec*radius_earth_m\n call ellipsoid_xyz2geo(vec(1),vec(2),vec(3),pole_lon,pole_lat,pole_vel,semimajor_grs80, &\n eccentricity_grs80,0)\nelse\n write(stderr,*) 'pole_xyz2geo: no earth shape named \"',trim(earth_shape),'\"; returning zeros'\nendif\n\nreturn\nend subroutine\n\n!--------------------------------------------------------------------------------------------------!\n\nsubroutine pole_geo2xyz(pole_lon,pole_lat,pole_vel,pole_x,pole_y,pole_z,earth_shape)\n!----\n! Given a rotation vector in geographic coordinates and a rotational velocity, calculate the Euler\n! pole in Cartesian coordinates (in the same units as input rotational velocity).\n!----\n\nuse io, only: stderr\nuse trig, only: d2r\nuse algebra, only: normalize\n\nimplicit none\n\n! Arguments\ndouble precision :: pole_lon, pole_lat, pole_vel, pole_x, pole_y, pole_z\ncharacter(len=*) :: earth_shape\n\n! Local variables\ndouble precision :: vec(3)\n\n\nif (earth_shape.eq.'sphere') then\n pole_x = pole_vel*cos(pole_lat*d2r)*cos(pole_lon*d2r)\n pole_y = pole_vel*cos(pole_lat*d2r)*sin(pole_lon*d2r)\n pole_z = pole_vel*sin(pole_lat*d2r)\nelseif (earth_shape.eq.'grs80') then\n call ellipsoid_geo2xyz(pole_lon,pole_lat,0.0d0,vec(1),vec(2),vec(3),1.0d0,eccentricity_grs80)\n call normalize(vec)\n pole_x = pole_vel*vec(1)\n pole_y = pole_vel*vec(2)\n pole_z = pole_vel*vec(3)\nelse\n write(stderr,*) 'pole_geo2xyz: no earth shape named \"',trim(earth_shape),'\"; returning zeros'\nendif\n\nreturn\nend subroutine\n\n!--------------------------------------------------------------------------------------------------!\n\nsubroutine itrf2008_wrt_morvel56_PA()\n!----\n! Calculate the angular velocity of ITRF 2008 (Altamimi et al., 2012) with respect to the Pacific\n! plate of MORVEL56 (Argus et al., 2011).\n!----\nimplicit none\n\n! Local variables\ndouble precision :: NNRM56_ITRF08_x, NNRM56_ITRF08_y, NNRM56_ITRF08_z\ndouble precision :: PAM56_NNRM56_x, PAM56_NNRM56_y, PAM56_NNRM56_z\ndouble precision :: PAM56_ITRF2008_x, PAM56_ITRF2008_y, PAM56_ITRF2008_z\ndouble precision :: morvel56_ITRF08_lon_calc, morvel56_ITRF08_lat_calc, morvel56_ITRF08_vel_calc\n\n! NNR-MORVEL56 w.r.t. ITRF 2008\nNNRM56_ITRF08_x = 0.083d0*masa2degma\nNNRM56_ITRF08_y = 0.006d0*masa2degma\nNNRM56_ITRF08_z = -0.007d0*masa2degma\n\n! MORVEL56 PA w.r.t. NNR-MORVEL56\ncall pole_geo2xyz(morvel56_NNR_lon,morvel56_NNR_lat,-morvel56_NNR_vel,&\n PAM56_NNRM56_x,PAM56_NNRM56_y,PAM56_NNRM56_z,'sphere')\n\n! MORVEL56 PA w.r.t. ITRF 2008\nPAM56_ITRF2008_x = PAM56_NNRM56_x + NNRM56_ITRF08_x\nPAM56_ITRF2008_y = PAM56_NNRM56_y + NNRM56_ITRF08_y\nPAM56_ITRF2008_z = PAM56_NNRM56_z + NNRM56_ITRF08_z\n\n! ITRF 2008 w.r.t. MORVEL56 PA\ncall pole_xyz2geo(-PAM56_ITRF2008_x,-PAM56_ITRF2008_y,-PAM56_ITRF2008_z,&\n morvel56_ITRF08_lon_calc,morvel56_ITRF08_lat_calc,morvel56_ITRF08_vel_calc,'sphere')\n\nreturn\nend subroutine\n\n!--------------------------------------------------------------------------------------------------!\n\nsubroutine get_pole(fixed_plate,moving_plate,model,pole,ierr)\n!----\n! Calculate the pole of rotation between two plates\n!----\n\nuse io, only: stderr\n\nimplicit none\n\n! Arguments\ncharacter(len=*) :: fixed_plate, moving_plate, model\ndouble precision :: pole(3)\ninteger :: ierr\n\n! Local variables\ninteger :: i\ndouble precision :: geo_pole(2,3), xyz_pole(2,3)\ncharacter(len=64) :: plate(2)\n\n\nierr = 0\nplate(1) = fixed_plate\nplate(2) = moving_plate\n\ndo i = 1,2\n if (model.eq.'ITRF05') then\n if (plate(i).eq.'AM') then\n geo_pole(i,1) = itrf05_AM_lon\n geo_pole(i,2) = itrf05_AM_lat\n geo_pole(i,3) = itrf05_AM_vel\n elseif (plate(i).eq.'AN') then\n geo_pole(i,1) = itrf05_AN_lon\n geo_pole(i,2) = itrf05_AN_lat\n geo_pole(i,3) = itrf05_AN_vel\n elseif (plate(i).eq.'AR') then\n geo_pole(i,1) = itrf05_AR_lon\n geo_pole(i,2) = itrf05_AR_lat\n geo_pole(i,3) = itrf05_AR_vel\n elseif (plate(i).eq.'AU') then\n geo_pole(i,1) = itrf05_AU_lon\n geo_pole(i,2) = itrf05_AU_lat\n geo_pole(i,3) = itrf05_AU_vel\n elseif (plate(i).eq.'CA') then\n geo_pole(i,1) = itrf05_CA_lon\n geo_pole(i,2) = itrf05_CA_lat\n geo_pole(i,3) = itrf05_CA_vel\n elseif (plate(i).eq.'EU') then\n geo_pole(i,1) = itrf05_EU_lon\n geo_pole(i,2) = itrf05_EU_lat\n geo_pole(i,3) = itrf05_EU_vel\n elseif (plate(i).eq.'IN') then\n geo_pole(i,1) = itrf05_IN_lon\n geo_pole(i,2) = itrf05_IN_lat\n geo_pole(i,3) = itrf05_IN_vel\n elseif (plate(i).eq.'NZ') then\n geo_pole(i,1) = itrf05_NZ_lon\n geo_pole(i,2) = itrf05_NZ_lat\n geo_pole(i,3) = itrf05_NZ_vel\n elseif (plate(i).eq.'NA') then\n geo_pole(i,1) = itrf05_NA_lon\n geo_pole(i,2) = itrf05_NA_lat\n geo_pole(i,3) = itrf05_NA_vel\n elseif (plate(i).eq.'NU') then\n geo_pole(i,1) = itrf05_NU_lon\n geo_pole(i,2) = itrf05_NU_lat\n geo_pole(i,3) = itrf05_NU_vel\n elseif (plate(i).eq.'OK') then\n geo_pole(i,1) = itrf05_OK_lon\n geo_pole(i,2) = itrf05_OK_lat\n geo_pole(i,3) = itrf05_OK_vel\n elseif (plate(i).eq.'PA') then\n geo_pole(i,1) = itrf05_PA_lon\n geo_pole(i,2) = itrf05_PA_lat\n geo_pole(i,3) = itrf05_PA_vel\n elseif (plate(i).eq.'SA') then\n geo_pole(i,1) = itrf05_SA_lon\n geo_pole(i,2) = itrf05_SA_lat\n geo_pole(i,3) = itrf05_SA_vel\n elseif (plate(i).eq.'SM') then\n geo_pole(i,1) = itrf05_SM_lon\n geo_pole(i,2) = itrf05_SM_lat\n geo_pole(i,3) = itrf05_SM_vel\n elseif (plate(i).eq.'YZ') then\n geo_pole(i,1) = itrf05_YZ_lon\n geo_pole(i,2) = itrf05_YZ_lat\n geo_pole(i,3) = itrf05_YZ_vel\n elseif (plate(i).eq.'ITRF05') then\n geo_pole(i,1) = itrf05_ITRF05_lon\n geo_pole(i,2) = itrf05_ITRF05_lat\n geo_pole(i,3) = itrf05_ITRF05_vel\n else\n write(stderr,*) 'get_pole: no plate named \"',trim(plate(i)),'\" in ITRF05 model'\n call list_plate_models('ITRF05')\n ierr = 1\n return\n endif\n\n elseif (model.eq.'ITRF08') then\n if (plate(i).eq.'AM') then\n geo_pole(i,1) = itrf08_AM_lon\n geo_pole(i,2) = itrf08_AM_lat\n geo_pole(i,3) = itrf08_AM_vel\n elseif (plate(i).eq.'AN') then\n geo_pole(i,1) = itrf08_AN_lon\n geo_pole(i,2) = itrf08_AN_lat\n geo_pole(i,3) = itrf08_AN_vel\n elseif (plate(i).eq.'AR') then\n geo_pole(i,1) = itrf08_AR_lon\n geo_pole(i,2) = itrf08_AR_lat\n geo_pole(i,3) = itrf08_AR_vel\n elseif (plate(i).eq.'AU') then\n geo_pole(i,1) = itrf08_AU_lon\n geo_pole(i,2) = itrf08_AU_lat\n geo_pole(i,3) = itrf08_AU_vel\n elseif (plate(i).eq.'CA') then\n geo_pole(i,1) = itrf08_CA_lon\n geo_pole(i,2) = itrf08_CA_lat\n geo_pole(i,3) = itrf08_CA_vel\n elseif (plate(i).eq.'EU') then\n geo_pole(i,1) = itrf08_EU_lon\n geo_pole(i,2) = itrf08_EU_lat\n geo_pole(i,3) = itrf08_EU_vel\n elseif (plate(i).eq.'IN') then\n geo_pole(i,1) = itrf08_IN_lon\n geo_pole(i,2) = itrf08_IN_lat\n geo_pole(i,3) = itrf08_IN_vel\n elseif (plate(i).eq.'NZ') then\n geo_pole(i,1) = itrf08_NZ_lon\n geo_pole(i,2) = itrf08_NZ_lat\n geo_pole(i,3) = itrf08_NZ_vel\n elseif (plate(i).eq.'NA') then\n geo_pole(i,1) = itrf08_NA_lon\n geo_pole(i,2) = itrf08_NA_lat\n geo_pole(i,3) = itrf08_NA_vel\n elseif (plate(i).eq.'NU') then\n geo_pole(i,1) = itrf08_NU_lon\n geo_pole(i,2) = itrf08_NU_lat\n geo_pole(i,3) = itrf08_NU_vel\n elseif (plate(i).eq.'PA') then\n geo_pole(i,1) = itrf08_PA_lon\n geo_pole(i,2) = itrf08_PA_lat\n geo_pole(i,3) = itrf08_PA_vel\n elseif (plate(i).eq.'SA') then\n geo_pole(i,1) = itrf08_SA_lon\n geo_pole(i,2) = itrf08_SA_lat\n geo_pole(i,3) = itrf08_SA_vel\n elseif (plate(i).eq.'SM') then\n geo_pole(i,1) = itrf08_SM_lon\n geo_pole(i,2) = itrf08_SM_lat\n geo_pole(i,3) = itrf08_SM_vel\n elseif (plate(i).eq.'SU') then\n geo_pole(i,1) = itrf08_SU_lon\n geo_pole(i,2) = itrf08_SU_lat\n geo_pole(i,3) = itrf08_SU_vel\n elseif (plate(i).eq.'ITRF05') then\n geo_pole(i,1) = itrf08_ITRF05_lon\n geo_pole(i,2) = itrf08_ITRF05_lat\n geo_pole(i,3) = itrf08_ITRF05_vel\n elseif (plate(i).eq.'ITRF08') then\n geo_pole(i,1) = itrf08_ITRF08_lon\n geo_pole(i,2) = itrf08_ITRF08_lat\n geo_pole(i,3) = itrf08_ITRF08_vel\n else\n write(stderr,*) 'get_pole: no plate named \"',trim(plate(i)),'\" in ITRF08 model'\n call list_plate_models('ITRF08')\n ierr = 1\n return\n endif\n\n elseif (model.eq.'MORVEL') then\n if (plate(i).eq.'PA') then\n geo_pole(i,1) = morvel_PA_lon\n geo_pole(i,2) = morvel_PA_lat\n geo_pole(i,3) = morvel_PA_vel\n elseif (plate(i).eq.'AM') then\n geo_pole(i,1) = morvel_AM_lon\n geo_pole(i,2) = morvel_AM_lat\n geo_pole(i,3) = morvel_AM_vel\n elseif (plate(i).eq.'AN') then\n geo_pole(i,1) = morvel_AN_lon\n geo_pole(i,2) = morvel_AN_lat\n geo_pole(i,3) = morvel_AN_vel\n elseif (plate(i).eq.'AR') then\n geo_pole(i,1) = morvel_AR_lon\n geo_pole(i,2) = morvel_AR_lat\n geo_pole(i,3) = morvel_AR_vel\n elseif (plate(i).eq.'AU') then\n geo_pole(i,1) = morvel_AU_lon\n geo_pole(i,2) = morvel_AU_lat\n geo_pole(i,3) = morvel_AU_vel\n elseif (plate(i).eq.'CA') then\n geo_pole(i,1) = morvel_CA_lon\n geo_pole(i,2) = morvel_CA_lat\n geo_pole(i,3) = morvel_CA_vel\n elseif (plate(i).eq.'CO') then\n geo_pole(i,1) = morvel_CO_lon\n geo_pole(i,2) = morvel_CO_lat\n geo_pole(i,3) = morvel_CO_vel\n elseif (plate(i).eq.'CP') then\n geo_pole(i,1) = morvel_CP_lon\n geo_pole(i,2) = morvel_CP_lat\n geo_pole(i,3) = morvel_CP_vel\n elseif (plate(i).eq.'EU') then\n geo_pole(i,1) = morvel_EU_lon\n geo_pole(i,2) = morvel_EU_lat\n geo_pole(i,3) = morvel_EU_vel\n elseif (plate(i).eq.'IN') then\n geo_pole(i,1) = morvel_IN_lon\n geo_pole(i,2) = morvel_IN_lat\n geo_pole(i,3) = morvel_IN_vel\n elseif (plate(i).eq.'JF') then\n geo_pole(i,1) = morvel_JF_lon\n geo_pole(i,2) = morvel_JF_lat\n geo_pole(i,3) = morvel_JF_vel\n elseif (plate(i).eq.'LW') then\n geo_pole(i,1) = morvel_LW_lon\n geo_pole(i,2) = morvel_LW_lat\n geo_pole(i,3) = morvel_LW_vel\n elseif (plate(i).eq.'MQ') then\n geo_pole(i,1) = morvel_MQ_lon\n geo_pole(i,2) = morvel_MQ_lat\n geo_pole(i,3) = morvel_MQ_vel\n elseif (plate(i).eq.'NA') then\n geo_pole(i,1) = morvel_NA_lon\n geo_pole(i,2) = morvel_NA_lat\n geo_pole(i,3) = morvel_NA_vel\n elseif (plate(i).eq.'NU') then\n geo_pole(i,1) = morvel_NU_lon\n geo_pole(i,2) = morvel_NU_lat\n geo_pole(i,3) = morvel_NU_vel\n elseif (plate(i).eq.'NZ') then\n geo_pole(i,1) = morvel_NZ_lon\n geo_pole(i,2) = morvel_NZ_lat\n geo_pole(i,3) = morvel_NZ_vel\n elseif (plate(i).eq.'PS') then\n geo_pole(i,1) = morvel_PS_lon\n geo_pole(i,2) = morvel_PS_lat\n geo_pole(i,3) = morvel_PS_vel\n elseif (plate(i).eq.'RI') then\n geo_pole(i,1) = morvel_RI_lon\n geo_pole(i,2) = morvel_RI_lat\n geo_pole(i,3) = morvel_RI_vel\n elseif (plate(i).eq.'SA') then\n geo_pole(i,1) = morvel_SA_lon\n geo_pole(i,2) = morvel_SA_lat\n geo_pole(i,3) = morvel_SA_vel\n elseif (plate(i).eq.'SC') then\n geo_pole(i,1) = morvel_SC_lon\n geo_pole(i,2) = morvel_SC_lat\n geo_pole(i,3) = morvel_SC_vel\n elseif (plate(i).eq.'SM') then\n geo_pole(i,1) = morvel_SM_lon\n geo_pole(i,2) = morvel_SM_lat\n geo_pole(i,3) = morvel_SM_vel\n elseif (plate(i).eq.'SR') then\n geo_pole(i,1) = morvel_SR_lon\n geo_pole(i,2) = morvel_SR_lat\n geo_pole(i,3) = morvel_SR_vel\n elseif (plate(i).eq.'SU') then\n geo_pole(i,1) = morvel_SU_lon\n geo_pole(i,2) = morvel_SU_lat\n geo_pole(i,3) = morvel_SU_vel\n elseif (plate(i).eq.'SW') then\n geo_pole(i,1) = morvel_SW_lon\n geo_pole(i,2) = morvel_SW_lat\n geo_pole(i,2) = morvel_SW_vel\n elseif (plate(i).eq.'YZ') then\n geo_pole(i,1) = morvel_YZ_lon\n geo_pole(i,2) = morvel_YZ_lat\n geo_pole(i,3) = morvel_YZ_vel\n elseif (plate(i).eq.'ITRF05') then\n geo_pole(i,1) = morvel_ITRF05_lon\n geo_pole(i,2) = morvel_ITRF05_lat\n geo_pole(i,3) = morvel_ITRF05_vel\n else\n write(stderr,*) 'get_pole: no plate named \"',trim(plate(i)),'\" in MORVEL model'\n call list_plate_models('MORVEL')\n ierr = 1\n return\n endif\n\n elseif (model.eq.'MORVEL56'.or.model.eq.'MORVEL-56') then\n if (plate(i).eq.'PA') then\n geo_pole(i,1) = morvel56_PA_lon\n geo_pole(i,2) = morvel56_PA_lat\n geo_pole(i,3) = morvel56_PA_vel\n elseif (plate(i).eq.'AM') then\n geo_pole(i,1) = morvel56_AM_lon\n geo_pole(i,2) = morvel56_AM_lat\n geo_pole(i,3) = morvel56_AM_vel\n elseif (plate(i).eq.'AN') then\n geo_pole(i,1) = morvel56_AN_lon\n geo_pole(i,2) = morvel56_AN_lat\n geo_pole(i,3) = morvel56_AN_vel\n elseif (plate(i).eq.'AR') then\n geo_pole(i,1) = morvel56_AR_lon\n geo_pole(i,2) = morvel56_AR_lat\n geo_pole(i,3) = morvel56_AR_vel\n elseif (plate(i).eq.'AU') then\n geo_pole(i,1) = morvel56_AU_lon\n geo_pole(i,2) = morvel56_AU_lat\n geo_pole(i,3) = morvel56_AU_vel\n elseif (plate(i).eq.'CA') then\n geo_pole(i,1) = morvel56_CA_lon\n geo_pole(i,2) = morvel56_CA_lat\n geo_pole(i,3) = morvel56_CA_vel\n elseif (plate(i).eq.'CO') then\n geo_pole(i,1) = morvel56_CO_lon\n geo_pole(i,2) = morvel56_CO_lat\n geo_pole(i,3) = morvel56_CO_vel\n elseif (plate(i).eq.'CP') then\n geo_pole(i,1) = morvel56_CP_lon\n geo_pole(i,2) = morvel56_CP_lat\n geo_pole(i,3) = morvel56_CP_vel\n elseif (plate(i).eq.'EU') then\n geo_pole(i,1) = morvel56_EU_lon\n geo_pole(i,2) = morvel56_EU_lat\n geo_pole(i,3) = morvel56_EU_vel\n elseif (plate(i).eq.'IN') then\n geo_pole(i,1) = morvel56_IN_lon\n geo_pole(i,2) = morvel56_IN_lat\n geo_pole(i,3) = morvel56_IN_vel\n elseif (plate(i).eq.'JF') then\n geo_pole(i,1) = morvel56_JF_lon\n geo_pole(i,2) = morvel56_JF_lat\n geo_pole(i,3) = morvel56_JF_vel\n elseif (plate(i).eq.'LW') then\n geo_pole(i,1) = morvel56_LW_lon\n geo_pole(i,2) = morvel56_LW_lat\n geo_pole(i,3) = morvel56_LW_vel\n elseif (plate(i).eq.'MQ') then\n geo_pole(i,1) = morvel56_MQ_lon\n geo_pole(i,2) = morvel56_MQ_lat\n geo_pole(i,3) = morvel56_MQ_vel\n elseif (plate(i).eq.'NA') then\n geo_pole(i,1) = morvel56_NA_lon\n geo_pole(i,2) = morvel56_NA_lat\n geo_pole(i,3) = morvel56_NA_vel\n elseif (plate(i).eq.'NU') then\n geo_pole(i,1) = morvel56_NU_lon\n geo_pole(i,2) = morvel56_NU_lat\n geo_pole(i,3) = morvel56_NU_vel\n elseif (plate(i).eq.'NZ') then\n geo_pole(i,1) = morvel56_NZ_lon\n geo_pole(i,2) = morvel56_NZ_lat\n geo_pole(i,3) = morvel56_NZ_vel\n elseif (plate(i).eq.'PS') then\n geo_pole(i,1) = morvel56_PS_lon\n geo_pole(i,2) = morvel56_PS_lat\n geo_pole(i,3) = morvel56_PS_vel\n elseif (plate(i).eq.'RI') then\n geo_pole(i,1) = morvel56_RI_lon\n geo_pole(i,2) = morvel56_RI_lat\n geo_pole(i,3) = morvel56_RI_vel\n elseif (plate(i).eq.'SA') then\n geo_pole(i,1) = morvel56_SA_lon\n geo_pole(i,2) = morvel56_SA_lat\n geo_pole(i,3) = morvel56_SA_vel\n elseif (plate(i).eq.'SC') then\n geo_pole(i,1) = morvel56_SC_lon\n geo_pole(i,2) = morvel56_SC_lat\n geo_pole(i,3) = morvel56_SC_vel\n elseif (plate(i).eq.'SM') then\n geo_pole(i,1) = morvel56_SM_lon\n geo_pole(i,2) = morvel56_SM_lat\n geo_pole(i,3) = morvel56_SM_vel\n elseif (plate(i).eq.'SR') then\n geo_pole(i,1) = morvel56_SR_lon\n geo_pole(i,2) = morvel56_SR_lat\n geo_pole(i,3) = morvel56_SR_vel\n elseif (plate(i).eq.'SU') then\n geo_pole(i,1) = morvel56_SU_lon\n geo_pole(i,2) = morvel56_SU_lat\n geo_pole(i,3) = morvel56_SU_vel\n elseif (plate(i).eq.'SW') then\n geo_pole(i,1) = morvel56_SW_lon\n geo_pole(i,2) = morvel56_SW_lat\n geo_pole(i,3) = morvel56_SW_vel\n elseif (plate(i).eq.'YZ') then\n geo_pole(i,1) = morvel56_YZ_lon\n geo_pole(i,2) = morvel56_YZ_lat\n geo_pole(i,3) = morvel56_YZ_vel\n elseif (plate(i).eq.'AS') then\n geo_pole(i,1) = morvel56_AS_lon\n geo_pole(i,2) = morvel56_AS_lat\n geo_pole(i,3) = morvel56_AS_vel\n elseif (plate(i).eq.'AP') then\n geo_pole(i,1) = morvel56_AP_lon\n geo_pole(i,2) = morvel56_AP_lat\n geo_pole(i,3) = morvel56_AP_vel\n elseif (plate(i).eq.'AT') then\n geo_pole(i,1) = morvel56_AT_lon\n geo_pole(i,2) = morvel56_AT_lat\n geo_pole(i,3) = morvel56_AT_vel\n elseif (plate(i).eq.'BR') then\n geo_pole(i,1) = morvel56_BR_lon\n geo_pole(i,2) = morvel56_BR_lat\n geo_pole(i,3) = morvel56_BR_vel\n elseif (plate(i).eq.'BS') then\n geo_pole(i,1) = morvel56_BS_lon\n geo_pole(i,2) = morvel56_BS_lat\n geo_pole(i,3) = morvel56_BS_vel\n elseif (plate(i).eq.'BH') then\n geo_pole(i,1) = morvel56_BH_lon\n geo_pole(i,2) = morvel56_BH_lat\n geo_pole(i,3) = morvel56_BH_vel\n elseif (plate(i).eq.'BU') then\n geo_pole(i,1) = morvel56_BU_lon\n geo_pole(i,2) = morvel56_BU_lat\n geo_pole(i,3) = morvel56_BU_vel\n elseif (plate(i).eq.'CL') then\n geo_pole(i,1) = morvel56_CL_lon\n geo_pole(i,2) = morvel56_CL_lat\n geo_pole(i,3) = morvel56_CL_vel\n elseif (plate(i).eq.'CR') then\n geo_pole(i,1) = morvel56_CR_lon\n geo_pole(i,2) = morvel56_CR_lat\n geo_pole(i,3) = morvel56_CR_vel\n elseif (plate(i).eq.'EA') then\n geo_pole(i,1) = morvel56_EA_lon\n geo_pole(i,2) = morvel56_EA_lat\n geo_pole(i,3) = morvel56_EA_vel\n elseif (plate(i).eq.'FT') then\n geo_pole(i,1) = morvel56_FT_lon\n geo_pole(i,2) = morvel56_FT_lat\n geo_pole(i,3) = morvel56_FT_vel\n elseif (plate(i).eq.'GP') then\n geo_pole(i,1) = morvel56_GP_lon\n geo_pole(i,2) = morvel56_GP_lat\n geo_pole(i,3) = morvel56_GP_vel\n elseif (plate(i).eq.'JZ') then\n geo_pole(i,1) = morvel56_JZ_lon\n geo_pole(i,2) = morvel56_JZ_lat\n geo_pole(i,3) = morvel56_JZ_vel\n elseif (plate(i).eq.'KE') then\n geo_pole(i,1) = morvel56_KE_lon\n geo_pole(i,2) = morvel56_KE_lat\n geo_pole(i,3) = morvel56_KE_vel\n elseif (plate(i).eq.'MN') then\n geo_pole(i,1) = morvel56_MN_lon\n geo_pole(i,2) = morvel56_MN_lat\n geo_pole(i,3) = morvel56_MN_vel\n elseif (plate(i).eq.'MO') then\n geo_pole(i,1) = morvel56_MO_lon\n geo_pole(i,2) = morvel56_MO_lat\n geo_pole(i,3) = morvel56_MO_vel\n elseif (plate(i).eq.'MA') then\n geo_pole(i,1) = morvel56_MA_lon\n geo_pole(i,2) = morvel56_MA_lat\n geo_pole(i,3) = morvel56_MA_vel\n elseif (plate(i).eq.'MS') then\n geo_pole(i,1) = morvel56_MS_lon\n geo_pole(i,2) = morvel56_MS_lat\n geo_pole(i,3) = morvel56_MS_vel\n elseif (plate(i).eq.'NH') then\n geo_pole(i,1) = morvel56_NH_lon\n geo_pole(i,2) = morvel56_NH_lat\n geo_pole(i,3) = morvel56_NH_vel\n elseif (plate(i).eq.'NI') then\n geo_pole(i,1) = morvel56_NI_lon\n geo_pole(i,2) = morvel56_NI_lat\n geo_pole(i,3) = morvel56_NI_vel\n elseif (plate(i).eq.'ND') then\n geo_pole(i,1) = morvel56_ND_lon\n geo_pole(i,2) = morvel56_ND_lat\n geo_pole(i,3) = morvel56_ND_vel\n elseif (plate(i).eq.'NB') then\n geo_pole(i,1) = morvel56_NB_lon\n geo_pole(i,2) = morvel56_NB_lat\n geo_pole(i,3) = morvel56_NB_vel\n elseif (plate(i).eq.'OK') then\n geo_pole(i,1) = morvel56_OK_lon\n geo_pole(i,2) = morvel56_OK_lat\n geo_pole(i,3) = morvel56_OK_vel\n elseif (plate(i).eq.'ON') then\n geo_pole(i,1) = morvel56_ON_lon\n geo_pole(i,2) = morvel56_ON_lat\n geo_pole(i,3) = morvel56_ON_vel\n elseif (plate(i).eq.'PM') then\n geo_pole(i,1) = morvel56_PM_lon\n geo_pole(i,2) = morvel56_PM_lat\n geo_pole(i,3) = morvel56_PM_vel\n elseif (plate(i).eq.'SL') then\n geo_pole(i,1) = morvel56_SL_lon\n geo_pole(i,2) = morvel56_SL_lat\n geo_pole(i,3) = morvel56_SL_vel\n elseif (plate(i).eq.'SS') then\n geo_pole(i,1) = morvel56_SS_lon\n geo_pole(i,2) = morvel56_SS_lat\n geo_pole(i,3) = morvel56_SS_vel\n elseif (plate(i).eq.'SB') then\n geo_pole(i,1) = morvel56_SB_lon\n geo_pole(i,2) = morvel56_SB_lat\n geo_pole(i,3) = morvel56_SB_vel\n elseif (plate(i).eq.'TI') then\n geo_pole(i,1) = morvel56_TI_lon\n geo_pole(i,2) = morvel56_TI_lat\n geo_pole(i,3) = morvel56_TI_vel\n elseif (plate(i).eq.'TO') then\n geo_pole(i,1) = morvel56_TO_lon\n geo_pole(i,2) = morvel56_TO_lat\n geo_pole(i,3) = morvel56_TO_vel\n elseif (plate(i).eq.'WL') then\n geo_pole(i,1) = morvel56_WL_lon\n geo_pole(i,2) = morvel56_WL_lat\n geo_pole(i,3) = morvel56_WL_vel\n elseif (plate(i).eq.'NNR') then\n geo_pole(i,1) = morvel56_NNR_lon\n geo_pole(i,2) = morvel56_NNR_lat\n geo_pole(i,3) = morvel56_NNR_vel\n elseif (plate(i).eq.'ITRF08') then\n geo_pole(i,1) = morvel56_ITRF08_lon\n geo_pole(i,2) = morvel56_ITRF08_lat\n geo_pole(i,3) = morvel56_ITRF08_vel\n else\n write(stderr,*) 'get_pole: no plate named \"',trim(plate(i)),'\" in MORVEL56 model'\n call list_plate_models('MORVEL56')\n ierr = 1\n return\n endif\n\n elseif (model.eq.'NUVEL1A'.or.model.eq.'NUVEL-1A') then\n if (plate(i).eq.'PA') then\n geo_pole(i,1) = nuvel1a_PA_lon\n geo_pole(i,2) = nuvel1a_PA_lat\n geo_pole(i,3) = nuvel1a_PA_vel\n elseif (plate(i).eq.'AF') then\n geo_pole(i,1) = nuvel1a_AF_lon\n geo_pole(i,2) = nuvel1a_AF_lat\n geo_pole(i,3) = nuvel1a_AF_vel\n elseif (plate(i).eq.'AN') then\n geo_pole(i,1) = nuvel1a_AN_lon\n geo_pole(i,2) = nuvel1a_AN_lat\n geo_pole(i,3) = nuvel1a_AN_vel\n elseif (plate(i).eq.'AT') then\n geo_pole(i,1) = nuvel1a_AR_lon\n geo_pole(i,2) = nuvel1a_AR_lat\n geo_pole(i,3) = nuvel1a_AR_vel\n elseif (plate(i).eq.'AU') then\n geo_pole(i,1) = nuvel1a_AU_lon\n geo_pole(i,2) = nuvel1a_AU_lat\n geo_pole(i,3) = nuvel1a_AU_vel\n elseif (plate(i).eq.'CA') then\n geo_pole(i,1) = nuvel1a_CA_lon\n geo_pole(i,2) = nuvel1a_CA_lat\n geo_pole(i,3) = nuvel1a_CA_vel\n elseif (plate(i).eq.'CO') then\n geo_pole(i,1) = nuvel1a_CO_lon\n geo_pole(i,2) = nuvel1a_CO_lat\n geo_pole(i,3) = nuvel1a_CO_vel\n elseif (plate(i).eq.'EU') then\n geo_pole(i,1) = nuvel1a_EU_lon\n geo_pole(i,2) = nuvel1a_EU_lat\n geo_pole(i,3) = nuvel1a_EU_vel\n elseif (plate(i).eq.'IN') then\n geo_pole(i,1) = nuvel1a_IN_lon\n geo_pole(i,2) = nuvel1a_IN_lat\n geo_pole(i,3) = nuvel1a_IN_vel\n elseif (plate(i).eq.'JF') then\n geo_pole(i,1) = nuvel1a_JF_lon\n geo_pole(i,2) = nuvel1a_JF_lat\n geo_pole(i,3) = nuvel1a_JF_vel\n elseif (plate(i).eq.'NA') then\n geo_pole(i,1) = nuvel1a_NA_lon\n geo_pole(i,2) = nuvel1a_NA_lat\n geo_pole(i,3) = nuvel1a_NA_vel\n elseif (plate(i).eq.'NZ') then\n geo_pole(i,1) = nuvel1a_NZ_lon\n geo_pole(i,2) = nuvel1a_NZ_lat\n geo_pole(i,3) = nuvel1a_NZ_vel\n elseif (plate(i).eq.'PS') then\n geo_pole(i,1) = nuvel1a_PS_lon\n geo_pole(i,2) = nuvel1a_PS_lat\n geo_pole(i,3) = nuvel1a_PS_vel\n elseif (plate(i).eq.'RI') then\n geo_pole(i,1) = nuvel1a_RI_lon\n geo_pole(i,2) = nuvel1a_RI_lat\n geo_pole(i,3) = nuvel1a_RI_vel\n elseif (plate(i).eq.'SA') then\n geo_pole(i,1) = nuvel1a_SA_lon\n geo_pole(i,2) = nuvel1a_SA_lat\n geo_pole(i,3) = nuvel1a_SA_vel\n elseif (plate(i).eq.'SC') then\n geo_pole(i,1) = nuvel1a_SC_lon\n geo_pole(i,2) = nuvel1a_SC_lat\n geo_pole(i,3) = nuvel1a_SC_vel\n elseif (plate(i).eq.'NNR') then\n geo_pole(i,1) = nuvel1a_NNR_lon\n geo_pole(i,2) = nuvel1a_NNR_lat\n geo_pole(i,3) = nuvel1a_NNR_vel\n else\n write(stderr,*) 'get_pole: no plate named \"',trim(plate(i)),'\" in NUVEL1A model'\n call list_plate_models('NUVEL1A')\n ierr = 1\n return\n endif\n else\n write(stderr,*) 'get_pole: no model named \"',trim(model),'\"'\n ierr = 1\n return\n endif\nenddo\n\n! Angular velocity of plate2 with respect to plate1: pole2-pole1 = pole\ncall pole_geo2xyz(geo_pole(1,1),geo_pole(1,2),geo_pole(1,3), &\n xyz_pole(1,1),xyz_pole(1,2),xyz_pole(1,3), &\n 'sphere')\ncall pole_geo2xyz(geo_pole(2,1),geo_pole(2,2),geo_pole(2,3), &\n xyz_pole(2,1),xyz_pole(2,2),xyz_pole(2,3), &\n 'sphere')\npole(1) = xyz_pole(2,1) - xyz_pole(1,1)\npole(2) = xyz_pole(2,2) - xyz_pole(1,2)\npole(3) = xyz_pole(2,3) - xyz_pole(1,3)\n\n! Convert back to geographic coordinates and rotational velocity\ncall pole_xyz2geo(pole(1),pole(2),pole(3), &\n geo_pole(1,1),geo_pole(1,2),geo_pole(1,3), &\n 'sphere')\npole(1) = geo_pole(1,1)\npole(2) = geo_pole(1,2)\npole(3) = geo_pole(1,3)\n\nreturn\nend subroutine\n\n!--------------------------------------------------------------------------------------------------!\n\nsubroutine list_plate_models(model)\n\nuse io, only: stdout\nimplicit none\ncharacter(len=*) :: model\n\nif (model.eq.'all') then\n model = 'ALL'\nendif\n\nif (model.eq.'ITRF05'.or.model.eq.'ALL') then\n write(stdout,*) 'ITRF 2005 plates (Altamimi et al., 2007)'\n write(stdout,*) ' AM: Amur'\n write(stdout,*) ' AN: Antarctica'\n write(stdout,*) ' AR: Arabia'\n write(stdout,*) ' AU: Australia'\n write(stdout,*) ' CA: Caribbean'\n write(stdout,*) ' EU: Eurasia'\n write(stdout,*) ' IN: India'\n write(stdout,*) ' ITRF05: International Reference Frame 2005'\n write(stdout,*) ' NA: North America'\n write(stdout,*) ' NU: Nubia'\n write(stdout,*) ' NZ: Nazca'\n write(stdout,*) ' OK: Okhotsk'\n write(stdout,*) ' PA: Pacific'\n write(stdout,*) ' SA: South America'\n write(stdout,*) ' SM: Somalia'\n write(stdout,*) ' YZ: Yangtze'\n write(stdout,*)\nendif\nif (model.eq.'ITRF08'.or.model.eq.'ALL') then\n write(stdout,*) 'ITRF 2008 plates (Altamimi et al., 2012)'\n write(stdout,*) ' AM: Amur'\n write(stdout,*) ' AN: Antarctica'\n write(stdout,*) ' AR: Arabia'\n write(stdout,*) ' AU: Australia'\n write(stdout,*) ' CA: Caribbean'\n write(stdout,*) ' EU: Eurasia'\n write(stdout,*) ' IN: India'\n write(stdout,*) ' ITRF05: International Reference Frame 2005'\n write(stdout,*) ' ITRF08: International Reference Frame 2008'\n write(stdout,*) ' NA: North America'\n write(stdout,*) ' NU: Nubia'\n write(stdout,*) ' NZ: Nazca'\n write(stdout,*) ' PA: Pacific'\n write(stdout,*) ' SA: South America'\n write(stdout,*) ' SM: Somalia'\n write(stdout,*) ' SU: Sunda'\n write(stdout,*)\nendif\nif (model.eq.'MORVEL'.or.model.eq.'ALL') then\n write(stdout,*) 'MORVEL plates (DeMets et al., 2010)'\n write(stdout,*) ' AM: Amur'\n write(stdout,*) ' AN: Antarctica'\n write(stdout,*) ' AR: Arabia'\n write(stdout,*) ' AU: Australia'\n write(stdout,*) ' CA: Caribbean'\n write(stdout,*) ' CO: Cocos'\n write(stdout,*) ' CP: Capricorn'\n write(stdout,*) ' EU: Eurasia'\n write(stdout,*) ' IN: India'\n write(stdout,*) ' ITRF05: International Reference Frame 2005'\n write(stdout,*) ' JF: Juan de Fuca'\n write(stdout,*) ' LW: Lwandle'\n write(stdout,*) ' MQ: Macquarie'\n write(stdout,*) ' NA: North America'\n write(stdout,*) ' NU: Nubia'\n write(stdout,*) ' NZ: Nazca'\n write(stdout,*) ' PA: Pacific'\n write(stdout,*) ' PS: Philippine Sea'\n write(stdout,*) ' RI: Rivera'\n write(stdout,*) ' SA: South America'\n write(stdout,*) ' SC: Scotia'\n write(stdout,*) ' SM: Somalia'\n write(stdout,*) ' SR: Sur'\n write(stdout,*) ' SU: Sunda'\n write(stdout,*) ' SW: Sandwich'\n write(stdout,*) ' YZ: Yangtze'\n write(stdout,*)\nendif\nif (model.eq.'MORVEL56'.or.model.eq.'MORVEL-56'.or.model.eq.'ALL') then\n write(stdout,*) 'MORVEL56 plates (Argus et al., 2011)'\n write(stdout,*) ' MORVEL plates (DeMets et al., 2010)'\n write(stdout,*) ' AM: Amur'\n write(stdout,*) ' AN: Antarctica'\n write(stdout,*) ' AR: Arabia'\n write(stdout,*) ' AU: Australia'\n write(stdout,*) ' CA: Caribbean'\n write(stdout,*) ' CO: Cocos'\n write(stdout,*) ' CP: Capricorn'\n write(stdout,*) ' EU: Eurasia'\n write(stdout,*) ' IN: India'\n write(stdout,*) ' JF: Juan de Fuca'\n write(stdout,*) ' LW: Lwandle'\n write(stdout,*) ' MQ: Macquarie'\n write(stdout,*) ' NA: North America'\n write(stdout,*) ' NU: Nubia'\n write(stdout,*) ' NZ: Nazca'\n write(stdout,*) ' PA: Pacific'\n write(stdout,*) ' PS: Philippine Sea'\n write(stdout,*) ' RI: Rivera'\n write(stdout,*) ' SA: South America'\n write(stdout,*) ' SC: Scotia'\n write(stdout,*) ' SM: Somalia'\n write(stdout,*) ' SR: Sur'\n write(stdout,*) ' SU: Sunda'\n write(stdout,*) ' SW: Sandwich'\n write(stdout,*) ' YZ: Yangtze'\n write(stdout,*)\n write(stdout,*) ' Bird (2002) plates'\n write(stdout,*) ' AS: Aegean Sea'\n write(stdout,*) ' AP: Altiplano'\n write(stdout,*) ' AT: Anatolia'\n write(stdout,*) ' BH: Birds Head'\n write(stdout,*) ' BR: Balmoral Reef'\n write(stdout,*) ' BS: Banda Sea'\n write(stdout,*) ' BU: Burma'\n write(stdout,*) ' CL: Caroline'\n write(stdout,*) ' CR: Conway Reef'\n write(stdout,*) ' EA: Easter'\n write(stdout,*) ' FT: Futuna'\n write(stdout,*) ' GP: Galapagos'\n write(stdout,*) ' JZ: Juan Fernandez'\n write(stdout,*) ' KE: Kermadec'\n write(stdout,*) ' MA: Mariana'\n write(stdout,*) ' MN: Manus'\n write(stdout,*) ' MO: Maoke'\n write(stdout,*) ' MS: Molucca Sea'\n write(stdout,*) ' NB: North Bismarck'\n write(stdout,*) ' ND: North Andes'\n write(stdout,*) ' NH: New Hebrides'\n write(stdout,*) ' NI: Niuafoou'\n write(stdout,*) ' OK: Okhotsk'\n write(stdout,*) ' ON: Okinawa'\n write(stdout,*) ' PM: Panama'\n write(stdout,*) ' SB: South Bismarck'\n write(stdout,*) ' SL: Shetland'\n write(stdout,*) ' SS: Solomon Sea'\n write(stdout,*) ' TI: Timor'\n write(stdout,*) ' TO: Tonga'\n write(stdout,*) ' WL: Woodlark'\n write(stdout,*)\n write(stdout,*) ' NNR: No net rotation'\n write(stdout,*) ' ITRF08: International Reference Frame 2008'\n write(stdout,*)\nendif\nif (model.eq.'NUVEL1A'.or.model.eq.'NUVEL-1A'.or.model.eq.'ALL') then\n write(stdout,*) 'NUVEL-1A plates (DeMets et al., 1994)'\n write(stdout,*) ' AF: Africa'\n write(stdout,*) ' AN: Antarctica'\n write(stdout,*) ' AR: Arabia'\n write(stdout,*) ' AU: Australia'\n write(stdout,*) ' CA: Caribbean'\n write(stdout,*) ' CO: Cocos'\n write(stdout,*) ' EU: Eurasia'\n write(stdout,*) ' IN: India'\n write(stdout,*) ' NNR: No net rotation'\n write(stdout,*) ' JF: Juan de Fuca'\n write(stdout,*) ' NA: North America'\n write(stdout,*) ' NZ: Nazca'\n write(stdout,*) ' PA: Pacific'\n write(stdout,*) ' PS: Philippine Sea'\n write(stdout,*) ' RI: Rivera'\n write(stdout,*) ' SA: South America'\n write(stdout,*) ' SC: Scotia'\n write(stdout,*)\nendif\n\n\nreturn\nend subroutine\n\nend module\n", "meta": {"hexsha": "6f38922ba62c2e39ee2e68aad8283f23908194d6", "size": 71059, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/earth_module.f90", "max_stars_repo_name": "mherman09/ElasticHalfspaceToolbox", "max_stars_repo_head_hexsha": "168b9391654f6d3940f8778789ec7642574a523a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-05-07T03:34:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-11T16:08:50.000Z", "max_issues_repo_path": "src/earth_module.f90", "max_issues_repo_name": "mherman09/ElasticHalfspaceToolbox", "max_issues_repo_head_hexsha": "168b9391654f6d3940f8778789ec7642574a523a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2017-10-09T19:27:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-04T13:17:03.000Z", "max_forks_repo_path": "src/earth_module.f90", "max_forks_repo_name": "mherman09/Hdef", "max_forks_repo_head_hexsha": "2b1606bb69810ddcfe59ea23601d14a30b840ea8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.3226857888, "max_line_length": 103, "alphanum_fraction": 0.6448162794, "num_tokens": 22609, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9626731094431571, "lm_q2_score": 0.6959583250334526, "lm_q1q2_score": 0.6699803648028052}} {"text": " MODULE random_chisq_mod\n! .. Implicit None Statement ..\n IMPLICIT NONE\n! ..\n CONTAINS\n\n!*********************************************************************\n\n FUNCTION random_chisq(df)\n!**********************************************************************\n! REAL FUNCTION GENCHI( DF )\n! Generate random value of CHIsquare variable\n! Function\n! Generates random deviate from the distribution of a chisquare\n! with DF degrees of freedom random variable.\n! Arguments\n! DF --> Degrees of freedom of the chisquare\n! (Must be positive)\n! REAL DF\n! Method\n! Uses relation between chisquare and gamma.\n!**********************************************************************\n! .. Use Statements ..\n USE random_standard_gamma_mod\n! ..\n! .. Implicit None Statement ..\n IMPLICIT NONE\n! ..\n! .. Function Return Value ..\n REAL :: random_chisq\n! ..\n! .. Scalar Arguments ..\n REAL :: df\n! ..\n! .. Executable Statements ..\n\n IF (df<=0.0) THEN\n WRITE (*,*) 'DF <= 0 in GENCHI - ABORT'\n WRITE (*,*) 'Value of DF: ', df\n STOP 'DF <= 0 in GENCHI - ABORT'\n END IF\n\n! JJV changed this to call random_standard_gamma directly\n! 10 random_chisq = 2.0*random_gamma(1.0,df/2.0)\n random_chisq = 2.0*random_standard_gamma(df/2.0)\n RETURN\n\n END FUNCTION random_chisq\n\n!*********************************************************************\n\n END MODULE random_chisq_mod\n", "meta": {"hexsha": "43fb45c0254a5641bb9f29ca0c2d909eb14fae55", "size": 1611, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/random_chisq_mod.f90", "max_stars_repo_name": "urbanjost/fpm_tools", "max_stars_repo_head_hexsha": "3f7fb8db5473537a42bee51641e3d4cae927a730", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/random_chisq_mod.f90", "max_issues_repo_name": "urbanjost/fpm_tools", "max_issues_repo_head_hexsha": "3f7fb8db5473537a42bee51641e3d4cae927a730", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/random_chisq_mod.f90", "max_forks_repo_name": "urbanjost/fpm_tools", "max_forks_repo_head_hexsha": "3f7fb8db5473537a42bee51641e3d4cae927a730", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-07-14T11:36:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-14T11:36:01.000Z", "avg_line_length": 30.3962264151, "max_line_length": 71, "alphanum_fraction": 0.4599627561, "num_tokens": 341, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970904940926, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6699788769815173}} {"text": "!--------------------------------------------------------------------------------\n!M+\n! NAME:\n! interpolate\n!\n! PURPOSE:\n! Module containing interpolation routines\n!\n! CATEGORY:\n! Interpolation\n!\n! CALLING SEQUENCE:\n! USE interpolate\n!\n! MODULES:\n! type_kinds: Module containing definitions for kinds of\n! variable types\n!\n! error_handler: Module containing error codes and error\n! handling routines\n! USEs: FILE_UTILITY module\n!\n! CONTAINS:\n! polynomial_interpolate: Function that performs polynomial interpolation\n! on input scalars or vectors.\n!\n! spline_interpolate: Function that performs cubic spline interpolation\n! on input scalars or vectors.\n!\n! spline_initialize: Function to establish the type of interpolating\n! spline for a tabulated set of functional values.\n!\n! EXTERNALS:\n! None.\n!\n! INCLUDE FILES:\n! None.\n!\n! COMMON BLOCKS:\n! None.\n!\n! CREATION HISTORY:\n! Written by: Paul van Delst, CIMSS/SSEC 22-Nov-2000\n! paul.vandelst@ssec.wisc.edu\n!\n! Copyright (C) 2000 Paul van Delst\n!\n!M-\n!--------------------------------------------------------------------------------\n\n\nMODULE interpolate\n\n\n ! ------------\n ! Modules used\n ! ------------\n\n USE type_kinds\n USE Message_handler\n\n\n ! ---------------------------\n ! Disable all implicit typing\n ! ---------------------------\n\n IMPLICIT NONE\n\n\n ! ------------\n ! Visibilities\n ! ------------\n\n PRIVATE\n PUBLIC :: polynomial_interpolate\n PUBLIC :: spline_interpolate\n PUBLIC :: spline_initialize\n\n\n ! --------------------\n ! Function overloading\n ! --------------------\n\n ! -- Public functions\n INTERFACE spline_interpolate\n MODULE PROCEDURE splint_scalar_single\n MODULE PROCEDURE splint_scalar_double\n MODULE PROCEDURE splint_rank1_single\n MODULE PROCEDURE splint_rank1_double\n END INTERFACE ! spline_interpolate\n\n INTERFACE spline_initialize\n MODULE PROCEDURE splinit_single\n MODULE PROCEDURE splinit_double\n END INTERFACE ! spline_initialize\n\n INTERFACE polynomial_interpolate\n MODULE PROCEDURE polyint_scalar_single\n MODULE PROCEDURE polyint_scalar_double\n MODULE PROCEDURE polyint_rank1_single\n MODULE PROCEDURE polyint_rank1_double\n END INTERFACE ! polynomial_interpolate\n\n ! -- Private functions\n INTERFACE value_locate\n MODULE PROCEDURE locate_single\n MODULE PROCEDURE locate_double\n END INTERFACE ! value_locate\n\n INTERFACE bisection_search\n MODULE PROCEDURE bisearch_single\n MODULE PROCEDURE bisearch_double\n END INTERFACE ! bisection_search\n\n\n ! -----------------\n ! Module parameters\n ! -----------------\n\n ! -- RCS Id field\n CHARACTER( * ), PRIVATE, PARAMETER :: MODULE_RCS_ID = &\n\n ! -- Maximum order for interpolating polynomial\n INTEGER, PRIVATE, PARAMETER :: MAX_ORDER = 9\n\n ! - Single precision == REAL*4\n REAL( Single ), PRIVATE, PARAMETER :: S_ZERO = 0.0_Single\n REAL( Single ), PRIVATE, PARAMETER :: S_ONE = 1.0_Single\n REAL( Single ), PRIVATE, PARAMETER :: S_TWO = 2.0_Single\n REAL( Single ), PRIVATE, PARAMETER :: S_SIX = 6.0_Single\n REAL( Single ), PRIVATE, PARAMETER :: S_TOLERANCE = EPSILON( S_ZERO )\n\n ! -- Double precision == REAL*8\n REAL( Double ), PRIVATE, PARAMETER :: D_ZERO = 0.0_Double\n REAL( Double ), PRIVATE, PARAMETER :: D_ONE = 1.0_Double\n REAL( Double ), PRIVATE, PARAMETER :: D_TWO = 2.0_Double\n REAL( Double ), PRIVATE, PARAMETER :: D_SIX = 6.0_Double\n REAL( Double ), PRIVATE, PARAMETER :: D_TOLERANCE = EPSILON( D_ZERO )\n\n\nCONTAINS\n\n\n\n\n\n FUNCTION polyint_scalar_Single( x, & ! Input\n y, & ! Input\n x_int, & ! Input\n y_int, & ! Output\n order, & ! Optional input\n RCS_Id, & ! Optional output\n message_log ) & ! Error messaging\n RESULT( error_status )\n\n\n !#--------------------------------------------------------------------------#\n !# -- TYPE DECLARATIONS -- #\n !#--------------------------------------------------------------------------#\n\n ! ---------\n ! Arguments\n ! ---------\n\n ! -- Input\n REAL( Single ), DIMENSION( : ), INTENT( IN ) :: x\n REAL( Single ), DIMENSION( : ), INTENT( IN ) :: y\n REAL( Single ), INTENT( IN ) :: x_int\n\n ! -- Output\n REAL( Single ), INTENT( OUT ) :: y_int\n\n ! -- Optional input\n INTEGER, OPTIONAL, INTENT( IN ) :: order\n\n ! -- Optional output\n CHARACTER( * ), OPTIONAL, INTENT( OUT ) :: RCS_Id\n\n ! -- Error messaging\n CHARACTER( * ), OPTIONAL, INTENT( IN ) :: message_log\n\n\n ! ---------------\n ! Function result\n ! ---------------\n\n INTEGER :: error_status\n\n\n ! ----------------\n ! Local parameters\n ! ----------------\n\n CHARACTER( * ), PARAMETER :: ROUTINE_NAME = 'Polynomial_Interpolate'\n\n\n ! ---------------\n ! Local variables\n ! ---------------\n\n CHARACTER( 256 ) :: message\n\n INTEGER :: n_points, n_min\n INTEGER :: n, l\n INTEGER :: k_begin, k_end, j\n INTEGER, DIMENSION( MAX_ORDER + 1 ) :: k\n INTEGER :: i\n REAL( Single ) :: polynomial\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- CHECK INPUT -- #\n !#--------------------------------------------------------------------------#\n\n ! ---------------------------------\n ! Check array sizes for consistency\n ! ---------------------------------\n\n n_points = SIZE( x )\n IF ( n_points /= SIZE( y ) ) THEN\n error_status = FAILURE\n CALL display_message( ROUTINE_NAME, &\n 'Input X and Y vectors have different sizes.', &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n\n ! ------------------------------\n ! Interpolating polynomial order\n ! ------------------------------\n\n ! -- Assume linear interpolation if order not specified...\n n = 1\n\n ! -- ...otherwise check it\n IF ( PRESENT( order ) ) THEN\n\n ! -- Only odd, non-zero orders accepted\n IF ( MOD( order, 2 ) == 0 ) THEN\n error_status = FAILURE\n WRITE( message, '( \"Input polynomial order of \", i2, &\n &\" invalid. Must be odd.\" )' ) order\n CALL display_message( ROUTINE_NAME, &\n TRIM( message ), &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n ! -- Only positive, non-zero also\n IF ( order < 1 ) THEN\n error_status = FAILURE\n WRITE( message, '( \"Input polynomial order of \", i2, &\n &\" invalid. Must be odd number > 0.\" )' ) order\n CALL display_message( ROUTINE_NAME, &\n TRIM( message ), &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n ! -- Only reasonable values also\n IF ( order > MAX_ORDER ) THEN\n error_status = FAILURE\n WRITE( message, '( \"Input polynomial order of \", i2, &\n &\" invalid. Must be odd number < or = \", i2, \".\" )' ) &\n order, MAX_ORDER\n CALL display_message( ROUTINE_NAME, &\n TRIM( message ), &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n ! -- Assign order to variable\n n = order\n\n END IF\n\n\n ! --------------------------------------\n ! Check that input array is large enough\n ! --------------------------------------\n\n IF ( n_points < ( n+1 ) ) THEN\n error_status = FAILURE\n WRITE( message, '( \"Input X and Y arrays must have \", i2, &\n &\" or more points for interpolating\", &\n &\" polynomial of order \", i2, \".\" )' ) &\n n+1, n\n CALL display_message( ROUTINE_NAME, &\n TRIM( message ), &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n\n ! -----------------------------------\n ! Set the RCS Id argument if supplied\n ! -----------------------------------\n\n IF ( PRESENT( RCS_Id ) ) THEN\n RCS_Id = ' '\n RCS_Id = MODULE_RCS_Id\n END IF\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- CREATE LOCAL INTERPOLATION INDEX ARRAY -- #\n !# #\n !# This index array is to reference the input abscissa points that bracket #\n !# those at which interpolates are required. E.g. for linear interpolation #\n !# the bracketing looks like: #\n !# #\n !# x(i+0) < x_int < x(i+1) # \n !# #\n !# where the index modifiers 0 and 1 are the \"k\" below. For cubic interp- #\n !# olation (order = 3), the bracketing looks like: #\n !# #\n !# x(i-1) < x(i+0) < x_int < x(i+1) < x(i+2) # \n !# #\n !# where the index modifiers are now -1, 0, +1, and +2. This is the main #\n !# reason only odd polynomial orders are accepted. Even-valued orders would #\n !# produce \"lopsided\" bracketing which can in turn produce interpolates #\n !# that are quasi-discontinuou at the bracketing boundaries (by quasi- #\n !# discontinuous I mean it looks weird :o) #\n !#--------------------------------------------------------------------------#\n\n ! -- Set the begin and end. Here\n ! -- integer division is relied upon\n k_begin = 0 - (n/2)\n k_end = 1 + (n/2)\n\n ! -- File the array\n k(1:n+1) = (/ ( l, l = k_begin, k_end ) /)\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- FIND THE LOCATIONS FOR WHICH INTERPOLATES ARE DESIRED -- #\n !#--------------------------------------------------------------------------#\n\n ! -----------------------------------------------------\n ! Result is the lower index, i.e. x(i) < x_int < x(i+1)\n ! -----------------------------------------------------\n\n i = bisection_search( x, x_int )\n\n\n ! --------------------------------------------------------\n ! Make indices valid for Lagrange polynomials, i.e. ensure\n ! that the sum of (i+k) does not reference non-existant\n ! indices. For those cases, the result is set to the\n ! maximum and minimum values allowed for the beginning and\n ! end of the array respectively. The result is that\n ! extrapolation may be performed.\n ! --------------------------------------------------------\n\n n_min = (n+1)/2\n\n IF ( i < n_min ) i = n_min\n IF ( i > (n_points - n_min) ) i = n_points - n_min\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- COMPUTE AND SUM THE LAGRANGE INTERPOLATING POLYNOMIALS -- #\n !# #\n !# Here the fundamental polynomials are calculated: #\n !# #\n !# n+1 #\n !# _____ #\n !# | | x - x(k) #\n !# p (x) = | | -------------- #\n !# j | | x(j) - x(k) #\n !# k = 1 #\n !# k /= j #\n !# #\n !# and then used to compute the final interpolating polynomial, #\n !# #\n !# ___ n+1 #\n !# \\ #\n !# P(x) = > p (x) . y(j) #\n !# /___ j #\n !# j=1 #\n !# #\n !#--------------------------------------------------------------------------#\n\n ! -----------------------------\n ! Initialise interpolate result\n ! -----------------------------\n\n y_int = S_ZERO\n\n\n ! --------------------------\n ! Loop over polynomial order\n ! --------------------------\n\n l_order_loop: DO l = 1, n + 1 \n\n ! -- Identify the index *not* to use for current\n ! -- order (just for clarity in code )\n j = k(l)\n\n ! -- Calculate the fundamental polynomial\n polynomial = PRODUCT( ( x_int - x(i+k(1:n+1)) )/( x(i+j) - x(i+k(1:n+1)) ), &\n MASK = ( k(1:n+1) /= j ) )\n\n ! -- Calculate and sum the interpolating polynomial\n y_int = y_int + ( polynomial * y(i+j) )\n\n END DO l_order_loop\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- DONE -- #\n !#--------------------------------------------------------------------------#\n\n error_status = SUCCESS\n\n END FUNCTION polyint_scalar_Single\n\n\n FUNCTION polyint_rank1_Single( x, & ! Input\n y, & ! Input\n x_int, & ! Input\n y_int, & ! Output\n order, & ! Optional input\n RCS_Id, & ! Optional output\n message_log ) & ! Error messaging\n RESULT( error_status )\n\n\n !#--------------------------------------------------------------------------#\n !# -- TYPE DECLARATIONS -- #\n !#--------------------------------------------------------------------------#\n\n ! ---------\n ! Arguments\n ! ---------\n\n ! -- Input\n REAL( Single ), DIMENSION( : ), INTENT( IN ) :: y\n REAL( Single ), DIMENSION( : ), INTENT( IN ) :: x\n REAL( Single ), DIMENSION( : ), INTENT( IN ) :: x_int\n\n ! -- Output\n REAL( Single ), DIMENSION( : ), INTENT( OUT ) :: y_int\n\n ! -- Optional input\n INTEGER, OPTIONAL, INTENT( IN ) :: order\n\n ! -- Optional output\n CHARACTER( * ), OPTIONAL, INTENT( OUT ) :: RCS_Id\n\n ! -- Error messaging\n CHARACTER( * ), OPTIONAL, INTENT( IN ) :: message_log\n\n\n ! ---------------\n ! Function result\n ! ---------------\n\n INTEGER :: error_status\n\n\n ! ----------------\n ! Local parameters\n ! ----------------\n\n CHARACTER( * ), PARAMETER :: ROUTINE_NAME = 'Polynomial_Interpolate'\n\n\n ! ---------------\n ! Local variables\n ! ---------------\n\n CHARACTER( 256 ) :: message\n\n INTEGER :: n_points, n_min\n INTEGER :: n, l\n INTEGER :: k_begin, k_end, j\n INTEGER, DIMENSION( MAX_ORDER + 1 ) :: k\n INTEGER, DIMENSION( SIZE( x_int ) ) :: i\n REAL( Single ), DIMENSION( SIZE( x_int ) ) :: polynomial\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- CHECK INPUT -- #\n !#--------------------------------------------------------------------------#\n\n ! ---------------------------------\n ! Check array sizes for consistency\n ! ---------------------------------\n\n n_points = SIZE( x )\n IF ( n_points /= SIZE( y ) ) THEN\n error_status = FAILURE\n CALL display_message( ROUTINE_NAME, &\n 'Input X and Y vectors have different sizes.', &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n IF ( SIZE( x_int ) /= SIZE( y_int ) ) THEN\n error_status = FAILURE\n CALL display_message( ROUTINE_NAME, &\n 'Input X_INT and output Y_INT vectors have different sizes.', &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n\n ! ------------------------------\n ! Interpolating polynomial order\n ! ------------------------------\n\n ! -- Assume linear interpolation if order not specified...\n n = 1\n\n ! -- ...otherwise check it\n IF ( PRESENT( order ) ) THEN\n\n ! -- Only odd, non-zero orders accepted\n IF ( MOD( order, 2 ) == 0 ) THEN\n error_status = FAILURE\n WRITE( message, '( \"Input polynomial order of \", i2, &\n &\" invalid. Must be odd.\" )' ) order\n CALL display_message( ROUTINE_NAME, &\n TRIM( message ), &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n ! -- Only positive, non-zero also\n IF ( order < 1 ) THEN\n error_status = FAILURE\n WRITE( message, '( \"Input polynomial order of \", i2, &\n &\" invalid. Must be odd number > 0.\" )' ) order\n CALL display_message( ROUTINE_NAME, &\n TRIM( message ), &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n ! -- Only reasonable values also\n IF ( order > MAX_ORDER ) THEN\n error_status = FAILURE\n WRITE( message, '( \"Input polynomial order of \", i2, &\n &\" invalid. Must be odd number < or = \", i2, \".\" )' ) &\n order, MAX_ORDER\n CALL display_message( ROUTINE_NAME, &\n TRIM( message ), &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n ! -- Assign order to variable\n n = order\n\n END IF\n\n\n ! --------------------------------------\n ! Check that input array is large enough\n ! --------------------------------------\n\n IF ( n_points < ( n+1 ) ) THEN\n error_status = FAILURE\n WRITE( message, '( \"Input X and Y arrays must have \", i2, &\n &\" or more points for interpolating\", &\n &\" polynomial of order \", i2, \".\" )' ) &\n n+1, n\n CALL display_message( ROUTINE_NAME, &\n TRIM( message ), &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n\n ! -----------------------------------\n ! Set the RCS Id argument if supplied\n ! -----------------------------------\n\n IF ( PRESENT( RCS_Id ) ) THEN\n RCS_Id = ' '\n RCS_Id = MODULE_RCS_Id\n END IF\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- CREATE LOCAL INTERPOLATION INDEX ARRAY -- #\n !# #\n !# This index array is to reference the input abscissa points that bracket #\n !# those at which interpolates are required. E.g. for linear interpolation #\n !# the bracketing looks like: #\n !# #\n !# x(i+0) < x_int < x(i+1) # \n !# #\n !# where the index modifiers 0 and 1 are the \"k\" below. For cubic interp- #\n !# olation (order = 3), the bracketing looks like: #\n !# #\n !# x(i-1) < x(i+0) < x_int < x(i+1) < x(i+2) # \n !# #\n !# where the index modifiers are now -1, 0, +1, and +2. This is the main #\n !# reason only odd polynomial orders are accepted. Even-valued orders would #\n !# produce \"lopsided\" bracketing which can in turn produce interpolates #\n !# that are quasi-discontinuou at the bracketing boundaries (by quasi- #\n !# discontinuous I mean it looks weird :o) #\n !#--------------------------------------------------------------------------#\n\n ! -- Set the begin and end. Here\n ! -- integer division is relied upon\n k_begin = 0 - (n/2)\n k_end = 1 + (n/2)\n\n ! -- File the array\n k(1:n+1) = (/ ( l, l = k_begin, k_end ) /)\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- FIND THE LOCATIONS FOR WHICH INTERPOLATES ARE DESIRED -- #\n !#--------------------------------------------------------------------------#\n\n ! -----------------------------------------------------\n ! Result is the lower index, i.e. x(i) < x_int < x(i+1)\n ! -----------------------------------------------------\n\n i = value_locate( x, x_int )\n\n\n ! --------------------------------------------------------\n ! Make indices valid for Lagrange polynomials, i.e. ensure\n ! that the sum of (i+k) does not reference non-existant\n ! indices. For those cases, the result is set to the\n ! maximum and minimum values allowed for the beginning and\n ! end of the array respectively. The result is that\n ! extrapolation may be performed.\n ! --------------------------------------------------------\n\n n_min = (n+1)/2\n\n WHERE( i < n_min ) i = n_min\n WHERE( i > (n_points - n_min) ) i = n_points - n_min\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- COMPUTE AND SUM THE LAGRANGE INTERPOLATING POLYNOMIALS -- #\n !# #\n !# Here the fundamental polynomials are calculated: #\n !# #\n !# n+1 #\n !# _____ #\n !# | | x - x(k) #\n !# p (x) = | | -------------- #\n !# j | | x(j) - x(k) #\n !# k = 1 #\n !# k /= j #\n !# #\n !# and then used to compute the final interpolating polynomial, #\n !# #\n !# ___ n+1 #\n !# \\ #\n !# P(x) = > p (x) . y(j) #\n !# /___ j #\n !# j=1 #\n !# #\n !#--------------------------------------------------------------------------#\n\n ! -----------------------------\n ! Initialise interpolate result\n ! -----------------------------\n\n y_int = S_ZERO\n\n\n ! --------------------------\n ! Loop over polynomial order\n ! --------------------------\n\n l_order_loop: DO l = 1, n + 1 \n\n ! -- Identify the index *not* to use for current\n ! -- order (just for clarity in code )\n j = k(l)\n\n ! -- Calculate the fundamental polynomial\n polynomial = PRODUCT( ( x_int - x(i+k(1:n+1)) )/( x(i+j) - x(i+k(1:n+1)) ), &\n MASK = ( k(1:n+1) /= j ) )\n\n ! -- Calculate and sum the interpolating polynomial\n y_int = y_int + ( polynomial * y(i+j) )\n\n END DO l_order_loop\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- DONE -- #\n !#--------------------------------------------------------------------------#\n\n error_status = SUCCESS\n\n END FUNCTION polyint_rank1_Single\n\n\n FUNCTION polyint_scalar_Double( x, & ! Input\n y, & ! Input\n x_int, & ! Input\n y_int, & ! Output\n order, & ! Optional input\n RCS_Id, & ! Optional output\n message_log ) & ! Error messaging\n RESULT( error_status )\n\n\n !#--------------------------------------------------------------------------#\n !# -- TYPE DECLARATIONS -- #\n !#--------------------------------------------------------------------------#\n\n ! ---------\n ! Arguments\n ! ---------\n\n ! -- Input\n REAL( Double ), DIMENSION( : ), INTENT( IN ) :: y\n REAL( Double ), DIMENSION( : ), INTENT( IN ) :: x\n REAL( Double ), INTENT( IN ) :: x_int\n\n ! -- Output\n REAL( Double ), INTENT( OUT ) :: y_int\n\n ! -- Optional input\n INTEGER, OPTIONAL, INTENT( IN ) :: order\n\n ! -- Optional output\n CHARACTER( * ), OPTIONAL, INTENT( OUT ) :: RCS_Id\n\n ! -- Error messaging\n CHARACTER( * ), OPTIONAL, INTENT( IN ) :: message_log\n\n\n ! ---------------\n ! Function result\n ! ---------------\n\n INTEGER :: error_status\n\n\n ! ----------------\n ! Local parameters\n ! ----------------\n\n CHARACTER( * ), PARAMETER :: ROUTINE_NAME = 'Polynomial_Interpolate'\n\n\n ! ---------------\n ! Local variables\n ! ---------------\n\n CHARACTER( 256 ) :: message\n\n INTEGER :: n_points, n_min\n INTEGER :: n, l\n INTEGER :: k_begin, k_end, j\n INTEGER, DIMENSION( MAX_ORDER + 1 ) :: k\n INTEGER :: i\n REAL( Double ) :: polynomial\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- CHECK INPUT -- #\n !#--------------------------------------------------------------------------#\n\n ! ---------------------------------\n ! Check array sizes for consistency\n ! ---------------------------------\n\n n_points = SIZE( x )\n IF ( n_points /= SIZE( y ) ) THEN\n error_status = FAILURE\n CALL display_message( ROUTINE_NAME, &\n 'Input X and Y vectors have different sizes.', &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n\n ! ------------------------------\n ! Interpolating polynomial order\n ! ------------------------------\n\n ! -- Assume linear interpolation if order not specified...\n n = 1\n\n ! -- ...otherwise check it\n IF ( PRESENT( order ) ) THEN\n\n ! -- Only odd, non-zero orders accepted\n IF ( MOD( order, 2 ) == 0 ) THEN\n error_status = FAILURE\n WRITE( message, '( \"Input polynomial order of \", i2, &\n &\" invalid. Must be odd.\" )' ) order\n CALL display_message( ROUTINE_NAME, &\n TRIM( message ), &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n ! -- Only positive, non-zero also\n IF ( order < 1 ) THEN\n error_status = FAILURE\n WRITE( message, '( \"Input polynomial order of \", i2, &\n &\" invalid. Must be odd number > 0.\" )' ) order\n CALL display_message( ROUTINE_NAME, &\n TRIM( message ), &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n ! -- Only reasonable values also\n IF ( order > MAX_ORDER ) THEN\n error_status = FAILURE\n WRITE( message, '( \"Input polynomial order of \", i2, &\n &\" invalid. Must be odd number < or = \", i2, \".\" )' ) &\n order, MAX_ORDER\n CALL display_message( ROUTINE_NAME, &\n TRIM( message ), &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n ! -- Assign order to variable\n n = order\n\n END IF\n\n\n ! --------------------------------------\n ! Check that input array is large enough\n ! --------------------------------------\n\n IF ( n_points < ( n+1 ) ) THEN\n error_status = FAILURE\n WRITE( message, '( \"Input X and Y arrays must have \", i2, &\n &\" or more points for interpolating\", &\n &\" polynomial of order \", i2, \".\" )' ) &\n n+1, n\n CALL display_message( ROUTINE_NAME, &\n TRIM( message ), &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n\n ! -----------------------------------\n ! Set the RCS Id argument if supplied\n ! -----------------------------------\n\n IF ( PRESENT( RCS_Id ) ) THEN\n RCS_Id = ' '\n RCS_Id = MODULE_RCS_Id\n END IF\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- CREATE LOCAL INTERPOLATION INDEX ARRAY -- #\n !# #\n !# This index array is to reference the input abscissa points that bracket #\n !# those at which interpolates are required. E.g. for linear interpolation #\n !# the bracketing looks like: #\n !# #\n !# x(i+0) < x_int < x(i+1) # \n !# #\n !# where the index modifiers 0 and 1 are the \"k\" below. For cubic interp- #\n !# olation (order = 3), the bracketing looks like: #\n !# #\n !# x(i-1) < x(i+0) < x_int < x(i+1) < x(i+2) # \n !# #\n !# where the index modifiers are now -1, 0, +1, and +2. This is the main #\n !# reason only odd polynomial orders are accepted. Even-valued orders would #\n !# produce \"lopsided\" bracketing which can in turn produce interpolates #\n !# that are quasi-discontinuou at the bracketing boundaries (by quasi- #\n !# discontinuous I mean it looks weird :o) #\n !#--------------------------------------------------------------------------#\n\n ! -- Set the begin and end. Here\n ! -- integer division is relied upon\n k_begin = 0 - (n/2)\n k_end = 1 + (n/2)\n\n ! -- File the array\n k(1:n+1) = (/ ( l, l = k_begin, k_end ) /)\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- FIND THE LOCATIONS FOR WHICH INTERPOLATES ARE DESIRED -- #\n !#--------------------------------------------------------------------------#\n\n ! -----------------------------------------------------\n ! Result is the lower index, i.e. x(i) < x_int < x(i+1)\n ! -----------------------------------------------------\n\n i = bisection_search( x, x_int )\n\n\n ! --------------------------------------------------------\n ! Make indices valid for Lagrange polynomials, i.e. ensure\n ! that the sum of (i+k) does not reference non-existant\n ! indices. For those cases, the result is set to the\n ! maximum and minimum values allowed for the beginning and\n ! end of the array respectively. The result is that\n ! extrapolation may be performed.\n ! --------------------------------------------------------\n\n n_min = (n+1)/2\n\n IF ( i < n_min ) i = n_min\n IF ( i > (n_points - n_min) ) i = n_points - n_min\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- COMPUTE AND SUM THE LAGRANGE INTERPOLATING POLYNOMIALS -- #\n !# #\n !# Here the fundamental polynomials are calculated: #\n !# #\n !# n+1 #\n !# _____ #\n !# | | x - x(k) #\n !# p (x) = | | -------------- #\n !# j | | x(j) - x(k) #\n !# k = 1 #\n !# k /= j #\n !# #\n !# and then used to compute the final interpolating polynomial, #\n !# #\n !# ___ n+1 #\n !# \\ #\n !# P(x) = > p (x) . y(j) #\n !# /___ j #\n !# j=1 #\n !# #\n !#--------------------------------------------------------------------------#\n\n ! -----------------------------\n ! Initialise interpolate result\n ! -----------------------------\n\n y_int = D_ZERO\n\n\n ! --------------------------\n ! Loop over polynomial order\n ! --------------------------\n\n l_order_loop: DO l = 1, n + 1 \n\n ! -- Identify the index *not* to use for current\n ! -- order (just for clarity in code )\n j = k(l)\n\n ! -- Calculate the fundamental polynomial\n polynomial = PRODUCT( ( x_int - x(i+k(1:n+1)) )/( x(i+j) - x(i+k(1:n+1)) ), &\n MASK = ( k(1:n+1) /= j ) )\n\n ! -- Calculate and sum the interpolating polynomial\n y_int = y_int + ( polynomial * y(i+j) )\n\n END DO l_order_loop\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- DONE -- #\n !#--------------------------------------------------------------------------#\n\n error_status = SUCCESS\n\n END FUNCTION polyint_scalar_Double\n\n\n FUNCTION polyint_rank1_Double( x, & ! Input\n y, & ! Input\n x_int, & ! Input\n y_int, & ! Output\n order, & ! Optional input\n RCS_Id, & ! Optional output\n message_log ) & ! Error messaging\n RESULT( error_status )\n\n\n !#--------------------------------------------------------------------------#\n !# -- TYPE DECLARATIONS -- #\n !#--------------------------------------------------------------------------#\n\n ! ---------\n ! Arguments\n ! ---------\n\n ! -- Input\n REAL( Double ), DIMENSION( : ), INTENT( IN ) :: x\n REAL( Double ), DIMENSION( : ), INTENT( IN ) :: y\n REAL( Double ), DIMENSION( : ), INTENT( IN ) :: x_int\n\n ! -- Output\n REAL( Double ), DIMENSION( : ), INTENT( OUT ) :: y_int\n\n ! -- Optional input\n INTEGER, OPTIONAL, INTENT( IN ) :: order\n\n ! -- Optional output\n CHARACTER( * ), OPTIONAL, INTENT( OUT ) :: RCS_Id\n\n ! -- Error messaging\n CHARACTER( * ), OPTIONAL, INTENT( IN ) :: message_log\n\n\n ! ---------------\n ! Function result\n ! ---------------\n\n INTEGER :: error_status\n\n\n ! ----------------\n ! Local parameters\n ! ----------------\n\n CHARACTER( * ), PARAMETER :: ROUTINE_NAME = 'Polynomial_Interpolate'\n\n\n ! ---------------\n ! Local variables\n ! ---------------\n\n CHARACTER( 256 ) :: message\n\n INTEGER :: n_points, n_min\n INTEGER :: n, l, m\n INTEGER :: k_begin, k_end, j\n INTEGER, DIMENSION( MAX_ORDER + 1 ) :: k\n INTEGER, DIMENSION( SIZE( x_int ) ) :: i\n REAL( Double ), DIMENSION( SIZE( x_int ) ) :: polynomial\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- CHECK INPUT -- #\n !#--------------------------------------------------------------------------#\n\n ! ---------------------------------\n ! Check array sizes for consistency\n ! ---------------------------------\n\n n_points = SIZE( x )\n IF ( n_points /= SIZE( y ) ) THEN\n error_status = FAILURE\n CALL display_message( ROUTINE_NAME, &\n 'Input X and Y vectors have different sizes.', &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n IF ( SIZE( x_int ) /= SIZE( y_int ) ) THEN\n error_status = FAILURE\n CALL display_message( ROUTINE_NAME, &\n 'Input X_INT and output Y_INT vectors have different sizes.', &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n\n ! ------------------------------\n ! Interpolating polynomial order\n ! ------------------------------\n\n ! -- Assume linear interpolation if order not specified...\n n = 1\n\n ! -- ...otherwise check it\n IF ( PRESENT( order ) ) THEN\n\n ! -- Only odd, non-zero orders accepted\n IF ( MOD( order, 2 ) == 0 ) THEN\n error_status = FAILURE\n WRITE( message, '( \"Input polynomial order of \", i2, &\n &\" invalid. Must be odd.\" )' ) order\n CALL display_message( ROUTINE_NAME, &\n TRIM( message ), &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n ! -- Only positive, non-zero also\n IF ( order < 1 ) THEN\n error_status = FAILURE\n WRITE( message, '( \"Input polynomial order of \", i2, &\n &\" invalid. Must be odd number > 0.\" )' ) order\n CALL display_message( ROUTINE_NAME, &\n TRIM( message ), &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n ! -- Only reasonable values also\n IF ( order > MAX_ORDER ) THEN\n error_status = FAILURE\n WRITE( message, '( \"Input polynomial order of \", i2, &\n &\" invalid. Must be odd number < or = \", i2, \".\" )' ) &\n order, MAX_ORDER\n CALL display_message( ROUTINE_NAME, &\n TRIM( message ), &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n ! -- Assign order to variable\n n = order\n\n END IF\n\n\n ! --------------------------------------\n ! Check that input array is large enough\n ! --------------------------------------\n\n IF ( n_points < ( n+1 ) ) THEN\n error_status = FAILURE\n WRITE( message, '( \"Input X and Y arrays must have \", i2, &\n &\" or more points for interpolating\", &\n &\" polynomial of order \", i2, \".\" )' ) &\n n+1, n\n CALL display_message( ROUTINE_NAME, &\n TRIM( message ), &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n\n ! -----------------------------------\n ! Set the RCS Id argument if supplied\n ! -----------------------------------\n\n IF ( PRESENT( RCS_Id ) ) THEN\n RCS_Id = ' '\n RCS_Id = MODULE_RCS_Id\n END IF\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- CREATE LOCAL INTERPOLATION INDEX ARRAY -- #\n !# #\n !# This index array is to reference the input abscissa points that bracket #\n !# those at which interpolates are required. E.g. for linear interpolation #\n !# the bracketing looks like: #\n !# #\n !# x(i+0) < x_int < x(i+1) # \n !# #\n !# where the index modifiers 0 and 1 are the \"k\" below. For cubic interp- #\n !# olation (order = 3), the bracketing looks like: #\n !# #\n !# x(i-1) < x(i+0) < x_int < x(i+1) < x(i+2) # \n !# #\n !# where the index modifiers are now -1, 0, +1, and +2. This is the main #\n !# reason only odd polynomial orders are accepted. Even-valued orders would #\n !# produce \"lopsided\" bracketing which can in turn produce interpolates #\n !# that are quasi-discontinuou at the bracketing boundaries (by quasi- #\n !# discontinuous I mean it looks weird :o) #\n !#--------------------------------------------------------------------------#\n\n ! -- Set the begin and end. Here\n ! -- integer division is relied upon\n k_begin = 0 - (n/2)\n k_end = 1 + (n/2)\n\n ! -- File the array\n k(1:n+1) = (/ ( l, l = k_begin, k_end ) /)\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- FIND THE LOCATIONS FOR WHICH INTERPOLATES ARE DESIRED -- #\n !#--------------------------------------------------------------------------#\n\n ! -----------------------------------------------------\n ! Result is the lower index, i.e. x(i) < x_int < x(i+1)\n ! -----------------------------------------------------\n\n i = value_locate( x, x_int )\n\n\n ! --------------------------------------------------------\n ! Make indices valid for Lagrange polynomials, i.e. ensure\n ! that the sum of (i+k) does not reference non-existant\n ! indices. For those cases, the result is set to the\n ! maximum and minimum values allowed for the beginning and\n ! end of the array respectively. The result is that\n ! extrapolation may be performed.\n ! --------------------------------------------------------\n\n n_min = (n+1)/2\n\n WHERE( i < n_min ) i = n_min\n WHERE( i > (n_points - n_min) ) i = n_points - n_min\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- COMPUTE AND SUM THE LAGRANGE INTERPOLATING POLYNOMIALS -- #\n !# #\n !# Here the fundamental polynomials are calculated: #\n !# #\n !# n+1 #\n !# _____ #\n !# | | x - x(k) #\n !# p (x) = | | -------------- #\n !# j | | x(j) - x(k) #\n !# k = 1 #\n !# k /= j #\n !# #\n !# and then used to compute the final interpolating polynomial, #\n !# #\n !# ___ n+1 #\n !# \\ #\n !# P(x) = > p (x) . y(j) #\n !# /___ j #\n !# j=1 #\n !# #\n !#--------------------------------------------------------------------------#\n\n ! -----------------------------\n ! Initialise interpolate result\n ! -----------------------------\n\n y_int = D_ZERO\n\n\n ! --------------------------\n ! Loop over polynomial order\n ! --------------------------\n\n l_order_loop: DO l = 1, n + 1 \n\n ! -- Identify the index *not* to use for current\n ! -- order (just for clarity in code )\n j = k(l)\n\n ! -- Calculate the fundamental polynomial\n polynomial = D_ONE\n m_product_loop: DO m = 1, n + 1\n IF ( k(m) == j ) CYCLE m_product_loop\n \n polynomial = polynomial * ( ( x_int - x(i+k(m)) )/( x(i+j) - x(i+k(m)) ) )\n\n END DO m_product_loop\n\n ! -- Calculate and sum the interpolating polynomial\n y_int = y_int + ( polynomial * y(i+j) )\n\n END DO l_order_loop\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- DONE -- #\n !#--------------------------------------------------------------------------#\n\n error_status = SUCCESS\n\n END FUNCTION polyint_rank1_Double\n\n\n\n\n\n\n\n\n FUNCTION splinit_single( x, & ! Input\n y, & ! Input\n y2, & ! Output\n RCS_Id, & ! Optional output\n message_log ) & ! Error messaging\n RESULT ( error_status )\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- TYPE DECLARATIONS -- #\n !#--------------------------------------------------------------------------#\n\n ! ---------\n ! Arguments\n ! ---------\n\n ! -- Input\n REAL( Single ), DIMENSION( : ), INTENT( IN ) :: x\n REAL( Single ), DIMENSION( : ), INTENT( IN ) :: y\n\n ! -- Output\n REAL( Single ), DIMENSION( : ), INTENT( OUT ) :: y2\n \n ! -- Optional output\n CHARACTER( * ), OPTIONAL, INTENT( OUT ) :: RCS_Id\n\n ! -- Error messaging\n CHARACTER( * ), OPTIONAL, INTENT( IN ) :: message_log\n\n\n ! ---------------\n ! Function result\n ! ---------------\n\n INTEGER :: error_status\n\n\n ! ----------------\n ! Local parameters\n ! ----------------\n\n CHARACTER( * ), PARAMETER :: ROUTINE_NAME = 'Spline_Initialize'\n\n\n ! ---------------\n ! Local variables\n ! ---------------\n\n CHARACTER( 256 ) :: message\n\n INTEGER :: i\n INTEGER :: n\n\n REAL( Single ) :: p\n REAL( Single ) :: qn\n REAL( Single ) :: sig\n REAL( Single ) :: un\n REAL( Single ) :: numer1\n REAL( Single ) :: numer2\n REAL( Single ) :: numerator\n REAL( Single ) :: denominator\n REAL( Single ) :: offset\n\n REAL( Single ), DIMENSION( SIZE( x ) ) :: u\n\n \n\n !#--------------------------------------------------------------------------#\n !# -- CHECK INPUT -- #\n !#--------------------------------------------------------------------------#\n\n ! ----------------------------\n ! Are vector sizes consistent?\n ! ----------------------------\n\n n = SIZE( x )\n\n IF ( SIZE( y ) /= n ) THEN\n error_status = FAILURE\n CALL display_message( ROUTINE_NAME, &\n 'Input X, Y arguments are different sizes.', &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n IF ( SIZE( y2 ) /= n ) THEN\n error_status = FAILURE\n CALL display_message( ROUTINE_NAME, &\n 'Output Y2 argument has inconsistent size.', &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n\n ! -----------------------------\n ! Is X-data in ascending order?\n ! -----------------------------\n\n ! -- Calculate delta-x values\n u( 1:n-1 ) = x( 2:n ) - x( 1:n-1 )\n\n ! -- Check for any negative or zero differences\n IF ( ANY( u(1:n-1) < S_TOLERANCE ) ) THEN\n error_status = FAILURE\n CALL display_message( ROUTINE_NAME, &\n 'Input X data must be in ascending order', &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n\n ! -----------------------------------\n ! Set the RCS Id argument if supplied\n ! -----------------------------------\n\n IF ( PRESENT( RCS_Id ) ) THEN\n RCS_Id = ' '\n RCS_Id = MODULE_RCS_Id\n END IF\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- SET SECOND DERIVATIVE AT LOWER BOUNDARY -- #\n !#--------------------------------------------------------------------------#\n\n y2(1) = S_ZERO\n u(1) = S_ZERO\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- BEGIN DECOMPOSITION LOOP OF TRIDIAGONAL ALGORITHM -- #\n !#--------------------------------------------------------------------------#\n\n i_decomposition_loop : DO i = 2, n - 1\n\n sig = ( x(i) - x(i-1) ) / ( x(i+1) - x(i-1) )\n p = ( sig * y2( i-1 ) ) + S_TWO\n y2( i ) = ( sig - S_ONE ) / p\n\n numer1 = ( y(i+1) - y(i) ) / ( x(i+1) - x(i) )\n numer2 = ( y(i) - y(i-1) ) / ( x(i) - x(i-1) )\n numerator = S_SIX * ( numer1 - numer2 )\n denominator = x(i+1) - x(i-1)\n offset = sig * u(i-1)\n\n u( i ) = ( ( numerator / denominator ) - offset ) / p\n\n END DO i_decomposition_loop\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- SET SECOND DERIVATIVE AT UPPER BOUNDARY -- #\n !#--------------------------------------------------------------------------#\n\n qn = S_ZERO\n un = S_ZERO\n\n y2( n ) = ( un - ( qn * u(n-1) ) ) / ( ( qn * y2(n-1) ) + S_ONE )\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- BACKSUBSTITUTION LOOP OF TRIDIAGONAL ALGORITHM -- #\n !#--------------------------------------------------------------------------#\n\n i_backsubstitution_loop : DO i = n - 1, 1, -1\n\n y2( i ) = ( y2(i) * y2(i+1) ) + u(i)\n\n END DO i_backsubstitution_loop\n\n \n\n !#--------------------------------------------------------------------------#\n !# -- DONE -- #\n !#--------------------------------------------------------------------------#\n\n error_status = SUCCESS\n\n END FUNCTION splinit_single\n\n\n FUNCTION splinit_double( x, & ! Input\n y, & ! Input\n y2, & ! Output\n RCS_Id, & ! Optional output\n message_log ) & ! Error messaging\n RESULT ( error_status )\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- TYPE DECLARATIONS -- #\n !#--------------------------------------------------------------------------#\n\n ! ---------\n ! Arguments\n ! ---------\n\n ! -- Input\n REAL( Double ), DIMENSION( : ), INTENT( IN ) :: x\n REAL( Double ), DIMENSION( : ), INTENT( IN ) :: y\n\n ! -- Output\n REAL( Double ), DIMENSION( : ), INTENT( OUT ) :: y2\n \n ! -- Optional output\n CHARACTER( * ), OPTIONAL, INTENT( OUT ) :: RCS_Id\n\n ! -- Error messaging\n CHARACTER( * ), OPTIONAL, INTENT( IN ) :: message_log\n\n\n ! ---------------\n ! Function result\n ! ---------------\n\n INTEGER :: error_status\n\n\n ! ----------------\n ! Local parameters\n ! ----------------\n\n CHARACTER( * ), PARAMETER :: ROUTINE_NAME = 'Spline_Initialize'\n\n\n ! ---------------\n ! Local variables\n ! ---------------\n\n CHARACTER( 256 ) :: message\n\n INTEGER :: i\n INTEGER :: n\n\n REAL( Double ) :: p\n REAL( Double ) :: qn\n REAL( Double ) :: sig\n REAL( Double ) :: un\n REAL( Double ) :: numer1\n REAL( Double ) :: numer2\n REAL( Double ) :: numerator\n REAL( Double ) :: denominator\n REAL( Double ) :: offset\n\n REAL( Double ), DIMENSION( SIZE( x ) ) :: u\n\n \n\n !#--------------------------------------------------------------------------#\n !# -- CHECK INPUT -- #\n !#--------------------------------------------------------------------------#\n\n ! ----------------------------\n ! Are vector sizes consistent?\n ! ----------------------------\n\n n = SIZE( x )\n\n IF ( SIZE( y ) /= n ) THEN\n error_status = FAILURE\n CALL display_message( ROUTINE_NAME, &\n 'Input X, Y arguments are different sizes.', &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n IF ( SIZE( y2 ) /= n ) THEN\n error_status = FAILURE\n CALL display_message( ROUTINE_NAME, &\n 'Output Y2 argument has inconsistent size.', &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n\n ! -----------------------------\n ! Is X-data in ascending order?\n ! -----------------------------\n\n ! -- Calculate delta-x values\n u( 1:n-1 ) = x( 2:n ) - x( 1:n-1 )\n\n ! -- Check for any negative or zero differences\n IF ( ANY( u( 1:n-1 ) < D_TOLERANCE ) ) THEN\n error_status = FAILURE\n CALL display_message( ROUTINE_NAME, &\n 'Input X data must be in ascending order', &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n\n ! -----------------------------------\n ! Set the RCS Id argument if supplied\n ! -----------------------------------\n\n IF ( PRESENT( RCS_Id ) ) THEN\n RCS_Id = ' '\n RCS_Id = MODULE_RCS_Id\n END IF\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- SET SECOND DERIVATIVE AT LOWER BOUNDARY -- #\n !#--------------------------------------------------------------------------#\n\n y2(1) = D_ZERO\n u(1) = D_ZERO\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- BEGIN DECOMPOSITION LOOP OF TRIDIAGONAL ALGORITHM -- #\n !#--------------------------------------------------------------------------#\n\n i_decomposition_loop : DO i = 2, n - 1\n\n sig = ( x(i) - x(i-1) ) / ( x(i+1) - x(i-1) )\n p = ( sig * y2( i-1 ) ) + D_TWO\n y2( i ) = ( sig - D_ONE ) / p\n\n numer1 = ( y(i+1) - y(i) ) / ( x(i+1) - x(i) )\n numer2 = ( y(i) - y(i-1) ) / ( x(i) - x(i-1) )\n numerator = D_SIX * ( numer1 - numer2 )\n denominator = x(i+1) - x(i-1)\n offset = sig * u(i-1)\n\n u( i ) = ( ( numerator / denominator ) - offset ) / p\n\n END DO i_decomposition_loop\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- SET SECOND DERIVATIVE AT UPPER BOUNDARY -- #\n !#--------------------------------------------------------------------------#\n\n qn = D_ZERO\n un = D_ZERO\n\n y2( n ) = ( un - ( qn * u(n-1) ) ) / ( ( qn * y2(n-1) ) + D_ONE )\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- BACKSUBSTITUTION LOOP OF TRIDIAGONAL ALGORITHM -- #\n !#--------------------------------------------------------------------------#\n\n i_backsubstitution_loop : DO i = n - 1, 1, -1\n\n y2( i ) = ( y2(i) * y2(i+1) ) + u(i)\n\n END DO i_backsubstitution_loop\n\n \n\n !#--------------------------------------------------------------------------#\n !# -- DONE -- #\n !#--------------------------------------------------------------------------#\n\n error_status = SUCCESS\n\n END FUNCTION splinit_double\n\n\n\n\n\n\n\n FUNCTION splint_scalar_single( x, & ! Input\n y, & ! Input\n x_int, & ! Input\n y_int, & ! Output\n y2, & ! Optional input\n RCS_Id, & ! Optional output\n message_log ) & ! Error messaging\n RESULT ( error_status )\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- TYPE DECLARATIONS -- #\n !#--------------------------------------------------------------------------#\n\n ! ---------\n ! Arguments\n ! ---------\n\n ! -- Input\n REAL( Single ), DIMENSION( : ), INTENT( IN ) :: x\n REAL( Single ), DIMENSION( : ), INTENT( IN ) :: y\n REAL( Single ), INTENT( IN ) :: x_int\n\n ! -- Output\n REAL( Single ), INTENT( OUT ) :: y_int\n\n ! -- Optional input\n REAL( Single ), OPTIONAL, DIMENSION( : ), INTENT( IN ) :: y2\n\n ! -- Optional output\n CHARACTER( * ), OPTIONAL, INTENT( OUT ) :: RCS_Id\n\n ! -- Error messaging\n CHARACTER( * ), OPTIONAL, INTENT( IN ) :: message_log\n\n\n ! ---------------\n ! Function result\n ! ---------------\n\n INTEGER :: error_status\n\n \n ! ----------------\n ! Local parameters\n ! ----------------\n\n CHARACTER( * ), PARAMETER :: ROUTINE_NAME = 'Spline_Interpolate'\n\n\n ! ---------------\n ! Local variables\n ! ---------------\n\n CHARACTER( 256 ) :: message\n\n INTEGER :: n\n INTEGER :: i, i_lo, i_hi\n\n REAL( Single ) :: a, b, dx\n\n REAL( Single ), DIMENSION( SIZE( x ) ) :: y2_derivative\n \n\n\n !#--------------------------------------------------------------------------#\n !# -- CHECK INPUT -- #\n !#--------------------------------------------------------------------------#\n\n ! ----------------------------\n ! Are vector sizes consistent?\n ! ----------------------------\n\n n = SIZE( x )\n\n IF ( SIZE( y ) /= n ) THEN\n error_status = FAILURE\n CALL display_message( ROUTINE_NAME, &\n 'Input X, Y arguments are different sizes.', &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n\n ! -----------------------------------\n ! Set the RCS Id argument if supplied\n ! -----------------------------------\n\n IF ( PRESENT( RCS_Id ) ) THEN\n RCS_Id = ' '\n RCS_Id = MODULE_RCS_Id\n END IF\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- CHECK IF Y2 PASSED -- #\n !#--------------------------------------------------------------------------#\n\n IF ( PRESENT( y2 ) ) THEN\n\n ! -- Yes. Check size\n IF ( SIZE( y2 ) /= n ) THEN\n error_status = FAILURE\n CALL display_message( ROUTINE_NAME, &\n 'Input Y2 argument has inconsistent size.', &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n y2_derivative = y2\n\n ELSE\n\n ! -- No. Calculate it. This is inefficient so should only be done\n ! -- if X and Y are different each call.\n error_status = spline_initialize( x, y, y2_derivative, &\n message_log = message_log )\n\n IF ( error_status /= SUCCESS ) THEN\n CALL display_message( ROUTINE_NAME, &\n 'Error occurred in spline initialisation function.', &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n END IF\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- FIND THE X-VALUES IN X THAT BRACKET THE INPUT X_INT VALUE -- #\n !# -- BY MEANS OF BISECTION. THIS IS OPTIMAL IF SEQUENTIAL -- #\n !# -- CALLS TO THIS FUNCTION ARE AT RANDOM VALUES OF X_INT. -- #\n !#--------------------------------------------------------------------------#\n\n i_lo = MAX( 1, bisection_search( x, x_int ) )\n i_hi = MIN( i_lo + 1, n )\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- CALCULATE INTERPOLATED VALUE -- #\n !#--------------------------------------------------------------------------#\n\n ! ---------------------\n ! Calculate dx and test\n ! ---------------------\n\n dx = x( i_hi ) - x( i_lo )\n\n IF ( dx < S_TOLERANCE ) THEN\n error_status = FAILURE\n WRITE( message, '( \"Error : dx < or = 0. i_lo, i_hi : \", i6, 2x, i6, &\n &\" x(i_lo), x(i_hi) : \", f12.6, 2x, f12.6 )' ) &\n i_lo, i_hi, x(i_lo), x(i_hi)\n CALL display_message( ROUTINE_NAME, &\n TRIM( message ), &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n\n ! ---------------------\n ! Evaluate cubic spline\n ! ---------------------\n\n a = ( x(i_hi) - x_int ) / dx\n b = ( x_int - x(i_lo) ) / dx\n\n y_int = ( a * y(i_lo) ) + ( b * y(i_hi) ) + &\n ( ( ( (a**3) - a ) * y2_derivative(i_lo) ) + &\n ( ( (b**3) - b ) * y2_derivative(i_hi) ) ) * &\n (dx*dx) / S_SIX\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- DONE -- # \n !#--------------------------------------------------------------------------#\n\n error_status = SUCCESS\n\n END FUNCTION splint_scalar_single\n\n\n FUNCTION splint_scalar_double( x, & ! Input\n y, & ! Input\n x_int, & ! Input\n y_int, & ! Output\n y2, & ! Optional input\n RCS_Id, & ! Optional output\n message_log ) & ! Error messaging\n RESULT ( error_status )\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- TYPE DECLARATIONS -- #\n !#--------------------------------------------------------------------------#\n\n ! ---------\n ! Arguments\n ! ---------\n\n ! -- Input\n REAL( Double ), DIMENSION( : ), INTENT( IN ) :: x\n REAL( Double ), DIMENSION( : ), INTENT( IN ) :: y\n REAL( Double ), INTENT( IN ) :: x_int\n\n ! -- Output\n REAL( Double ), INTENT( OUT ) :: y_int\n\n ! -- Optional input\n REAL( Double ), OPTIONAL, DIMENSION( : ), INTENT( IN ) :: y2\n\n ! -- Optional output\n CHARACTER( * ), OPTIONAL, INTENT( OUT ) :: RCS_Id\n\n ! -- Error messaging\n CHARACTER( * ), OPTIONAL, INTENT( IN ) :: message_log\n\n\n ! ---------------\n ! Function result\n ! ---------------\n\n INTEGER :: error_status\n\n \n ! ----------------\n ! Local parameters\n ! ----------------\n\n CHARACTER( * ), PARAMETER :: ROUTINE_NAME = 'Spline_Interpolate'\n\n\n ! ---------------\n ! Local variables\n ! ---------------\n\n CHARACTER( 256 ) :: message\n\n INTEGER :: n\n INTEGER :: i, i_lo, i_hi\n\n REAL( Double ) :: a, b, dx\n\n REAL( Double ), DIMENSION( SIZE( x ) ) :: y2_derivative\n \n\n\n !#--------------------------------------------------------------------------#\n !# -- CHECK INPUT -- #\n !#--------------------------------------------------------------------------#\n\n ! ----------------------------\n ! Are vector sizes consistent?\n ! ----------------------------\n\n n = SIZE( x )\n\n IF ( SIZE( y ) /= n ) THEN\n error_status = FAILURE\n CALL display_message( ROUTINE_NAME, &\n 'Input X, Y arguments are different sizes.', &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n\n ! -----------------------------------\n ! Set the RCS Id argument if supplied\n ! -----------------------------------\n\n IF ( PRESENT( RCS_Id ) ) THEN\n RCS_Id = ' '\n RCS_Id = MODULE_RCS_Id\n END IF\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- CHECK IF Y2 PASSED -- #\n !#--------------------------------------------------------------------------#\n\n IF ( PRESENT( y2 ) ) THEN\n\n ! -- Yes. Check size\n IF ( SIZE( y2 ) /= n ) THEN\n error_status = FAILURE\n CALL display_message( ROUTINE_NAME, &\n 'Input Y2 argument has inconsistent size.', &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n y2_derivative = y2\n\n ELSE\n\n ! -- No. Calculate it. This is inefficient so should only be done\n ! -- if X and Y are different each call.\n error_status = spline_initialize( x, y, y2_derivative, &\n message_log = message_log )\n\n IF ( error_status /= SUCCESS ) THEN\n CALL display_message( ROUTINE_NAME, &\n 'Error occurred in spline initialisation function.', &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n END IF\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- FIND THE X-VALUES IN X THAT BRACKET THE INPUT X_INT VALUE -- #\n !# -- BY MEANS OF BISECTION. THIS IS OPTIMAL IF SEQUENTIAL -- #\n !# -- CALLS TO THIS FUNCTION ARE AT RANDOM VALUES OF X_INT. -- #\n !#--------------------------------------------------------------------------#\n\n i_lo = MAX( 1, bisection_search( x, x_int ) )\n i_hi = MIN( i_lo + 1, n )\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- CALCULATE INTERPOLATED VALUE -- #\n !#--------------------------------------------------------------------------#\n\n ! ---------------------\n ! Calculate dx and test\n ! ---------------------\n\n dx = x( i_hi ) - x( i_lo )\n\n IF ( dx < D_TOLERANCE ) THEN\n error_status = FAILURE\n WRITE( message, '( \"Error : dx < or = 0. i_lo, i_hi : \", i6, 2x, i6, &\n &\" x(i_lo), x(i_hi) : \", f12.6, 2x, f12.6 )' ) &\n i_lo, i_hi, x(i_lo), x(i_hi)\n CALL display_message( ROUTINE_NAME, &\n TRIM( message ), &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n\n ! ---------------------\n ! Evaluate cubic spline\n ! ---------------------\n\n a = ( x(i_hi) - x_int ) / dx\n b = ( x_int - x(i_lo) ) / dx\n\n y_int = ( a * y(i_lo) ) + ( b * y(i_hi) ) + &\n ( ( ( (a**3) - a ) * y2_derivative(i_lo) ) + &\n ( ( (b**3) - b ) * y2_derivative(i_hi) ) ) * &\n (dx*dx) / D_SIX\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- DONE -- # \n !#--------------------------------------------------------------------------#\n\n error_status = SUCCESS\n\n END FUNCTION splint_scalar_double\n\n\n\n\n FUNCTION splint_rank1_single( x, & ! Input\n y, & ! Input\n x_int, & ! Input\n y_int, & ! Output\n y2, & ! Optional input\n RCS_Id, & ! Optional output\n message_log ) & ! Error messaging\n RESULT ( error_status )\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- TYPE DECLARATIONS -- #\n !#--------------------------------------------------------------------------#\n\n ! ---------\n ! Arguments\n ! ---------\n\n ! -- Input\n REAL( Single ), DIMENSION( : ), INTENT( IN ) :: x ! N\n REAL( Single ), DIMENSION( : ), INTENT( IN ) :: y ! N\n REAL( Single ), DIMENSION( : ), INTENT( IN ) :: x_int ! N_int\n\n ! -- Output\n REAL( Single ), DIMENSION( : ), INTENT( OUT ) :: y_int ! N_int\n\n ! -- Optional input\n REAL( Single ), OPTIONAL, DIMENSION( : ), INTENT( IN ) :: y2 ! N\n\n ! -- Optional output\n CHARACTER( * ), OPTIONAL, INTENT( OUT ) :: RCS_Id\n\n ! -- Error messaging\n CHARACTER( * ), OPTIONAL, INTENT( IN ) :: message_log\n\n\n ! ---------------\n ! Function result\n ! ---------------\n\n INTEGER :: error_status\n\n \n ! ----------------\n ! Local parameters\n ! ----------------\n\n CHARACTER( * ), PARAMETER :: ROUTINE_NAME = 'Spline_Interpolate'\n\n\n ! ---------------\n ! Local variables\n ! ---------------\n\n CHARACTER( 256 ) :: message\n\n INTEGER :: n, n_int\n INTEGER :: i\n\n REAL( Single ) :: a, b, dx\n\n INTEGER, DIMENSION( SIZE( x_int ) ) :: i_lo, i_hi\n\n REAL( Single ), DIMENSION( SIZE( x ) ) :: y2_derivative\n \n\n\n !#--------------------------------------------------------------------------#\n !# -- CHECK INPUT -- #\n !#--------------------------------------------------------------------------#\n\n ! ----------------------------------\n ! Are input vector sizes consistent?\n ! ----------------------------------\n\n n = SIZE( x )\n\n IF ( SIZE( y ) /= n ) THEN\n error_status = FAILURE\n CALL display_message( ROUTINE_NAME, &\n 'Input X, Y arguments are different sizes.', &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n\n ! ----------------------------------------\n ! Are interpolate vector sizes consistent?\n ! ----------------------------------------\n\n n_int = SIZE( x_int )\n\n IF ( SIZE( y_int ) /= n_int ) THEN\n error_status = FAILURE\n CALL display_message( ROUTINE_NAME, &\n 'Interpolate X_INT, Y_INT arguments are different sizes.', &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n\n ! -----------------------------------\n ! Set the RCS Id argument if supplied\n ! -----------------------------------\n\n IF ( PRESENT( RCS_Id ) ) THEN\n RCS_Id = ' '\n RCS_Id = MODULE_RCS_Id\n END IF\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- CHECK IF Y2 PASSED -- #\n !#--------------------------------------------------------------------------#\n\n IF ( PRESENT( y2 ) ) THEN\n\n ! -- Yes. Check size\n IF ( SIZE( y2 ) /= n ) THEN\n error_status = FAILURE\n CALL display_message( ROUTINE_NAME, &\n 'Input Y2 argument has inconsistent size.', &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n y2_derivative = y2\n\n ELSE\n\n ! -- No. Calculate it.\n error_status = spline_initialize( x, y, y2_derivative, &\n message_log = message_log )\n\n IF ( error_status /= SUCCESS ) THEN\n CALL display_message( ROUTINE_NAME, &\n 'Error occurred in spline initialisation function.', &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n END IF\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- FIND THE X-VALUES IN X THAT BRACKET THE INPUT X_INT VALUE -- #\n !# -- BY MEANS OF BISECTION. THIS IS OPTIMAL IF SEQUENTIAL -- #\n !# -- CALLS TO THIS FUNCTION ARE AT RANDOM VALUES OF X_INT. -- #\n !#--------------------------------------------------------------------------#\n\n i_lo = value_locate( x, x_int )\n i_hi = i_lo + 1\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- CALCULATE INTERPOLATED VALUE -- #\n !#--------------------------------------------------------------------------#\n\n DO i = 1, n_int\n\n \n ! ---------------------\n ! Calculate dx and test\n ! ---------------------\n\n dx = x( i_hi( i ) ) - x( i_lo( i ) )\n\n IF ( dx < S_TOLERANCE ) THEN\n error_status = FAILURE\n WRITE( message, '( \"Error : dx < or = 0. i_lo, i_hi : \", i6, 2x, i6, &\n &\" x(i_lo), x(i_hi) : \", f12.6, 2x, f12.6 )' ) &\n i_lo(i), i_hi(i), x(i_lo(i)), x(i_hi(i))\n CALL display_message( ROUTINE_NAME, &\n TRIM( message ), &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n\n ! ---------------------\n ! Evaluate cubic spline\n ! ---------------------\n\n a = ( x(i_hi(i)) - x_int(i) ) / dx\n b = ( x_int(i) - x(i_lo(i)) ) / dx\n\n y_int(i) = ( a * y(i_lo(i)) ) + ( b * y(i_hi(i)) ) + &\n ( ( ( (a**3) - a ) * y2_derivative(i_lo(i)) ) + &\n ( ( (b**3) - b ) * y2_derivative(i_hi(i)) ) ) * &\n (dx*dx) / S_SIX\n\n END DO\n\n\n !#--------------------------------------------------------------------------#\n !# -- DONE -- # \n !#--------------------------------------------------------------------------#\n\n error_status = SUCCESS\n\n END FUNCTION splint_rank1_single\n\n\n\n FUNCTION splint_rank1_double( x, & ! Input\n y, & ! Input\n x_int, & ! Input\n y_int, & ! Output\n y2, & ! Optional input\n RCS_Id, & ! Optional output\n message_log ) & ! Error messaging\n RESULT ( error_status )\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- TYPE DECLARATIONS -- #\n !#--------------------------------------------------------------------------#\n\n ! ---------\n ! Arguments\n ! ---------\n\n ! -- Input\n REAL( Double ), DIMENSION( : ), INTENT( IN ) :: x ! N\n REAL( Double ), DIMENSION( : ), INTENT( IN ) :: y ! N\n REAL( Double ), DIMENSION( : ), INTENT( IN ) :: x_int ! N_int\n\n ! -- Output\n REAL( Double ), DIMENSION( : ), INTENT( OUT ) :: y_int ! N_int\n\n ! -- Optional input\n REAL( Double ), OPTIONAL, DIMENSION( : ), INTENT( IN ) :: y2 ! N\n\n ! -- Optional output\n CHARACTER( * ), OPTIONAL, INTENT( OUT ) :: RCS_Id\n\n ! -- Error messaging\n CHARACTER( * ), OPTIONAL, INTENT( IN ) :: message_log\n\n\n ! ---------------\n ! Function result\n ! ---------------\n\n INTEGER :: error_status\n\n \n ! ----------------\n ! Local parameters\n ! ----------------\n\n CHARACTER( * ), PARAMETER :: ROUTINE_NAME = 'Spline_Interpolate'\n\n\n ! ---------------\n ! Local variables\n ! ---------------\n\n CHARACTER( 256 ) :: message\n\n INTEGER :: n, n_int\n INTEGER :: i\n\n REAL( Double ) :: a, b, dx\n\n INTEGER, DIMENSION( SIZE( x_int ) ) :: i_lo, i_hi\n\n REAL( Double ), DIMENSION( SIZE( x ) ) :: y2_derivative\n \n\n\n !#--------------------------------------------------------------------------#\n !# -- CHECK INPUT -- #\n !#--------------------------------------------------------------------------#\n\n ! ----------------------------------\n ! Are input vector sizes consistent?\n ! ----------------------------------\n\n n = SIZE( x )\n\n IF ( SIZE( y ) /= n ) THEN\n error_status = FAILURE\n CALL display_message( ROUTINE_NAME, &\n 'Input X, Y arguments are different sizes.', &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n\n ! ----------------------------------------\n ! Are interpolate vector sizes consistent?\n ! ----------------------------------------\n\n n_int = SIZE( x_int )\n\n IF ( SIZE( y_int ) /= n_int ) THEN\n error_status = FAILURE\n CALL display_message( ROUTINE_NAME, &\n 'Interpolate X_INT, Y_INT arguments are different sizes.', &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n\n ! -----------------------------------\n ! Set the RCS Id argument if supplied\n ! -----------------------------------\n\n IF ( PRESENT( RCS_Id ) ) THEN\n RCS_Id = ' '\n RCS_Id = MODULE_RCS_Id\n END IF\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- CHECK IF Y2 PASSED -- #\n !#--------------------------------------------------------------------------#\n\n IF ( PRESENT( y2 ) ) THEN\n\n ! -- Yes. Check size\n IF ( SIZE( y2 ) /= n ) THEN\n error_status = FAILURE\n CALL display_message( ROUTINE_NAME, &\n 'Input Y2 argument has inconsistent size.', &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n y2_derivative = y2\n\n ELSE\n\n ! -- No. Calculate it.\n error_status = spline_initialize( x, y, y2_derivative, &\n message_log = message_log )\n\n IF ( error_status /= SUCCESS ) THEN\n CALL display_message( ROUTINE_NAME, &\n 'Error occurred in spline initialisation function.', &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n END IF\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- FIND THE X-VALUES IN X THAT BRACKET THE INPUT X_INT VALUE -- #\n !# -- BY MEANS OF BISECTION. THIS IS OPTIMAL IF SEQUENTIAL -- #\n !# -- CALLS TO THIS FUNCTION ARE AT RANDOM VALUES OF X_INT. -- #\n !#--------------------------------------------------------------------------#\n\n i_lo = value_locate( x, x_int )\n i_hi = i_lo + 1\n\n\n\n !#--------------------------------------------------------------------------#\n !# -- CALCULATE INTERPOLATED VALUE -- #\n !#--------------------------------------------------------------------------#\n\n DO i = 1, n_int\n\n \n ! ---------------------\n ! Calculate dx_int and test\n ! ---------------------\n\n dx = x( i_hi( i ) ) - x( i_lo( i ) )\n\n IF ( dx < D_TOLERANCE ) THEN\n error_status = FAILURE\n WRITE( message, '( \"Error : dx < or = 0. i_lo, i_hi : \", i6, 2x, i6, &\n &\" x(i_lo), x(i_hi) : \", f12.6, 2x, f12.6 )' ) &\n i_lo(i), i_hi(i), x(i_lo(i)), x(i_hi(i))\n CALL display_message( ROUTINE_NAME, &\n TRIM( message ), &\n error_status, &\n message_log = message_log )\n RETURN\n END IF\n\n\n ! ---------------------\n ! Evaluate cubic spline\n ! ---------------------\n\n a = ( x(i_hi(i)) - x_int(i) ) / dx\n b = ( x_int(i) - x(i_lo(i)) ) / dx\n\n y_int(i) = ( a * y(i_lo(i)) ) + ( b * y(i_hi(i)) ) + &\n ( ( ( (a**3) - a ) * y2_derivative(i_lo(i)) ) + &\n ( ( (b**3) - b ) * y2_derivative(i_hi(i)) ) ) * &\n (dx*dx) / D_SIX\n\n END DO\n\n\n !#--------------------------------------------------------------------------#\n !# -- DONE -- # \n !#--------------------------------------------------------------------------#\n\n error_status = SUCCESS\n\n END FUNCTION splint_rank1_double\n\n\n\n\n !##############################################################################\n !##############################################################################\n !##############################################################################\n !##############################################################################\n\n !# PRIVATE routines #\n\n !##############################################################################\n !##############################################################################\n !##############################################################################\n !##############################################################################\n\n FUNCTION locate_single( x, u ) &\n RESULT( j )\n\n REAL( Single ), DIMENSION( : ), INTENT( IN ) :: x\n REAL( Single ), DIMENSION( : ), INTENT( IN ) :: u\n\n INTEGER, DIMENSION( SIZE( u ) ) :: j\n\n INTEGER :: n_x\n INTEGER :: n_u, i_u\n INTEGER :: x_lower, x_upper\n LOGICAL :: ascending\n\n n_x = SIZE( x )\n n_u = SIZE( u )\n\n\n ! ---------------------------------------------------------------\n ! Determine if arrays are sorted in ascending or descending order\n ! ---------------------------------------------------------------\n\n IF ( x( n_x ) > x( 1 ) .AND. u( n_u ) > u( 1 ) ) THEN\n ascending = .TRUE.\n ELSEIF ( x( n_x ) < x( 1 ) .AND. u( n_u ) < u( 1 ) ) THEN\n ascending = .FALSE.\n ELSE\n j(:) = -1\n RETURN\n END IF\n\n\n ! --------------------------------------------------\n ! Perform the bisection search for each element of u\n ! --------------------------------------------------\n\n IF ( ascending ) THEN\n\n ! -- Going up\n x_lower = 1\n\n ascending_loop: DO i_u = 1, n_u\n j( i_u ) = bisection_search( x, u( i_u ), x_lower = x_lower )\n x_lower = MAX( 1, j( i_u ) )\n END DO ascending_loop\n\n ELSE\n\n ! -- Going down\n x_upper = n_x\n\n descending_loop: DO i_u = 1, n_u\n j( i_u ) = bisection_search( x, u( i_u ), x_upper = x_upper )\n x_lower = MIN( j( i_u ), n_x )\n END DO descending_loop\n\n END IF\n\n END FUNCTION locate_single\n\n\n\n FUNCTION locate_double( x, u ) &\n RESULT( j )\n\n REAL( Double ), DIMENSION( : ), INTENT( IN ) :: x\n REAL( Double ), DIMENSION( : ), INTENT( IN ) :: u\n\n INTEGER, DIMENSION( SIZE( u ) ) :: j\n\n INTEGER :: n_x\n INTEGER :: n_u, i_u\n INTEGER :: x_lower, x_upper\n LOGICAL :: ascending\n\n n_x = SIZE( x )\n n_u = SIZE( u )\n\n\n ! ---------------------------------------------------------------\n ! Determine if arrays are sorted in ascending or descending order\n ! ---------------------------------------------------------------\n\n IF ( x( n_x ) > x( 1 ) .AND. u( n_u ) > u( 1 ) ) THEN\n ascending = .TRUE.\n ELSEIF ( x( n_x ) < x( 1 ) .AND. u( n_u ) < u( 1 ) ) THEN\n ascending = .FALSE.\n ELSE\n j(:) = -1\n RETURN\n END IF\n\n\n ! --------------------------------------------------\n ! Perform the bisection search for each element of u\n ! --------------------------------------------------\n\n IF ( ascending ) THEN\n\n ! -- Going up\n x_lower = 1\n\n ascending_loop: DO i_u = 1, n_u\n j( i_u ) = bisection_search( x, u( i_u ), x_lower = x_lower )\n x_lower = MAX( 1, j( i_u ) )\n END DO ascending_loop\n\n ELSE\n\n ! -- Going down\n x_upper = n_x\n\n descending_loop: DO i_u = 1, n_u\n j( i_u ) = bisection_search( x, u( i_u ), x_upper = x_upper )\n x_lower = MIN( j( i_u ), n_x )\n END DO descending_loop\n\n END IF\n\n END FUNCTION locate_double\n\n\n\n FUNCTION bisearch_single( x, u, &\n x_lower, &\n x_upper ) &\n RESULT( j )\n\n REAL( Single ), DIMENSION( : ), INTENT( IN ) :: x\n REAL( Single ), INTENT( IN ) :: u\n INTEGER, INTENT( IN ), OPTIONAL :: x_lower\n INTEGER, INTENT( IN ), OPTIONAL :: x_upper\n\n INTEGER :: j\n\n INTEGER :: n\n INTEGER :: j_lower\n INTEGER :: j_middle\n INTEGER :: j_upper\n\n\n n = SIZE( x )\n\n\n ! ------------------------------------\n ! Initialise upper and lower limits to\n ! the valid maximums, 1 and n\n ! ------------------------------------\n\n IF ( PRESENT( x_lower ) ) THEN\n j_lower = x_lower\n ELSE\n j_lower = 1\n END IF\n\n IF ( PRESENT( x_upper ) ) THEN\n j_upper = x_upper\n ELSE\n j_upper = n\n END IF\n\n\n\n ! ------------------------------------------\n ! Search for the required index by bisection\n ! ------------------------------------------\n\n bisection_search_loop: DO\n\n\n ! ----------------------------------------------\n ! If the index ranges have converged, we're done\n ! ----------------------------------------------\n\n IF ( ( j_upper - j_lower ) <= 1 ) EXIT bisection_search_loop\n\n\n ! ---------------------\n ! Define a middle point\n ! ---------------------\n\n j_middle = ( j_lower + j_upper ) / 2\n\n\n ! --------------------------------------------------------\n ! Which half is the required value in?\n !\n ! .EQV. is logical equivalence, i.e. the result is TRUE if\n ! both expressions are TRUE or both expressions are FALSE\n ! --------------------------------------------------------\n\n IF ( ( x(n) > x(1) ) .EQV. ( u > x( j_middle ) ) ) THEN\n\n ! -- The \"upper\" half\n j_lower = j_middle\n\n ELSE\n\n ! -- The \"lower\" half\n j_upper = j_middle\n\n END IF\n\n END DO bisection_search_loop\n\n\n ! -----------------------\n ! Define the return value\n ! -----------------------\n\n j = j_lower\n\n END FUNCTION bisearch_single\n\n\n FUNCTION bisearch_double( x, u, &\n x_lower, &\n x_upper ) &\n RESULT( j )\n\n REAL( Double ), DIMENSION( : ), INTENT( IN ) :: x\n REAL( Double ), INTENT( IN ) :: u\n INTEGER, INTENT( IN ), OPTIONAL :: x_lower\n INTEGER, INTENT( IN ), OPTIONAL :: x_upper\n\n INTEGER :: j\n\n INTEGER :: n\n INTEGER :: j_lower\n INTEGER :: j_middle\n INTEGER :: j_upper\n\n\n n = SIZE( x )\n\n\n ! ------------------------------------\n ! Initialise upper and lower limits to\n ! the valid maximums, 1 and n\n ! ------------------------------------\n\n IF ( PRESENT( x_lower ) ) THEN\n j_lower = x_lower\n ELSE\n j_lower = 1\n END IF\n\n IF ( PRESENT( x_upper ) ) THEN\n j_upper = x_upper\n ELSE\n j_upper = n\n END IF\n\n\n\n ! ------------------------------------------\n ! Search for the required index by bisection\n ! ------------------------------------------\n\n bisection_search_loop: DO\n\n\n ! ----------------------------------------------\n ! If the index ranges have converged, we're done\n ! ----------------------------------------------\n\n IF ( ( j_upper - j_lower ) <= 1 ) EXIT bisection_search_loop\n\n\n ! ---------------------\n ! Define a middle point\n ! ---------------------\n\n j_middle = ( j_lower + j_upper ) / 2\n\n\n ! --------------------------------------------------------\n ! Which half is the required value in?\n !\n ! .EQV. is logical equivalence, i.e. the result is TRUE if\n ! both expressions are TRUE or both expressions are FALSE\n ! --------------------------------------------------------\n\n IF ( ( x(n) > x(1) ) .EQV. ( u > x( j_middle ) ) ) THEN\n\n ! -- The \"upper\" half\n j_lower = j_middle\n\n ELSE\n\n ! -- The \"lower\" half\n j_upper = j_middle\n\n END IF\n\n END DO bisection_search_loop\n\n\n ! -----------------------\n ! Define the return value\n ! -----------------------\n\n j = j_lower\n\n END FUNCTION bisearch_double\n\nEND MODULE interpolate\n\n\n!-------------------------------------------------------------------------------\n! -- MODIFICATION HISTORY --\n!-------------------------------------------------------------------------------\n!\n!\n! $Date: 2002/10/08 14:48:26 $\n!\n! $Revision$\n!\n! $Name: $\n!\n! $State: Exp $\n!\n! $Log: interpolate.f90,v $\n! Revision 3.4 2002/10/08 14:48:26 paulv\n! - Synchronising repository.\n!\n! Revision 3.3 2002/08/22 19:43:59 paulv\n! - Updated documentation.\n!\n! Revision 3.2 2002/07/12 19:05:13 paulv\n! - Added RCS_Id optional output arguments to public functions.\n! - Updated header documentation.\n! - Removed module variable MESSAGE and moved it into each function that\n! required it.\n!\n! Revision 3.1 2002/03/24 15:16:11 paulv\n! - Replaced individual linear, quadratic, and cubic interpolation functions\n! with the generic POLYNOMIAL_INTERPOLATE() function that allows the\n! order of the interpolating polynomial to be selected by the user. Only\n! in the early stages of debugging - scalar versions appear to work but only\n! the double precision version of the rank-1 functions works correctly.\n!\n! Revision 2.2 2001/10/17 17:40:22 paulv\n! - Added cubic (4-pt Lagrangian) interpolation functions.\n!\n! Revision 2.1 2001/10/10 12:07:10 paulv\n! - Added SPLINE_INITIALIZE and SPLINE_INTERPOLATE functions.\n! - Overloaded all public functions to allow both single and double\n! precision input and also scalar and vector interpolates.\n! - Updated documentation.\n!\n! Revision 1.2 2000/11/28 13:44:07 paulv\n! - Added quadratic interpolation routines for single- and double-precision\n! input vectors.\n!\n! Revision 1.1 2000/11/27 18:07:31 paulv\n! Initial checkin.\n!\n!\n!\n", "meta": {"hexsha": "37492b5040aaf337da54ee38ba8d2957622fd16a", "size": 94553, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/Zeeman/src_lbl/interpolate.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/Zeeman/src_lbl/interpolate.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/Zeeman/src_lbl/interpolate.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": 32.8651372958, "max_line_length": 91, "alphanum_fraction": 0.3484289235, "num_tokens": 19232, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970904940926, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6699788769815173}} {"text": "*> \\brief \\b DCOMBSSQ adds two scaled sum of squares quantities.\n*\n* =========== DOCUMENTATION ===========\n*\n* Online html documentation available at\n* http://www.netlib.org/lapack/explore-html/\n*\n*\n* Definition:\n* ===========\n*\n* SUBROUTINE DCOMBSSQ( V1, V2 )\n*\n* .. Array Arguments ..\n* DOUBLE PRECISION V1( 2 ), V2( 2 )\n* ..\n*\n*\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*>\n*> DCOMBSSQ adds two scaled sum of squares quantities, V1 := V1 + V2.\n*> That is,\n*>\n*> V1_scale**2 * V1_sumsq := V1_scale**2 * V1_sumsq\n*> + V2_scale**2 * V2_sumsq\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in,out] V1\n*> \\verbatim\n*> V1 is DOUBLE PRECISION array, dimension (2).\n*> The first scaled sum.\n*> V1(1) = V1_scale, V1(2) = V1_sumsq.\n*> \\endverbatim\n*>\n*> \\param[in] V2\n*> \\verbatim\n*> V2 is DOUBLE PRECISION array, dimension (2).\n*> The second scaled sum.\n*> V2(1) = V2_scale, V2(2) = V2_sumsq.\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee\n*> \\author Univ. of California Berkeley\n*> \\author Univ. of Colorado Denver\n*> \\author NAG Ltd.\n*\n*> \\ingroup OTHERauxiliary\n*\n* =====================================================================\n SUBROUTINE DCOMBSSQ( V1, V2 )\n*\n* -- LAPACK auxiliary routine --\n* -- LAPACK is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n* November 2018\n*\n* .. Array Arguments ..\n DOUBLE PRECISION V1( 2 ), V2( 2 )\n* ..\n*\n* =====================================================================\n*\n* .. Parameters ..\n DOUBLE PRECISION ZERO\n PARAMETER ( ZERO = 0.0D+0 )\n* ..\n* .. Executable Statements ..\n*\n* A zero sum V2 shall not modify the scaling factor of V1\n IF( V2( 2 ).EQ.ZERO ) RETURN\n*\n IF( V1( 1 ).GE.V2( 1 ) ) THEN\n IF( V1( 1 ).NE.ZERO ) THEN\n V1( 2 ) = V1( 2 ) + ( V2( 1 ) / V1( 1 ) )**2 * V2( 2 )\n ELSE\n V1( 2 ) = V1( 2 ) + V2( 2 )\n END IF\n ELSE\n V1( 2 ) = V2( 2 ) + ( V1( 1 ) / V2( 1 ) )**2 * V1( 2 )\n V1( 1 ) = V2( 1 )\n END IF\n RETURN\n*\n* End of DCOMBSSQ\n*\n END\n", "meta": {"hexsha": "c32bbc5908842b226a8155dadfa19a36b88facd1", "size": 2316, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "SRC/dcombssq.f", "max_stars_repo_name": "drhpc/lapack", "max_stars_repo_head_hexsha": "0448336b4c5e4b71fb4b2f17881d491d46aab5c2", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "SRC/dcombssq.f", "max_issues_repo_name": "drhpc/lapack", "max_issues_repo_head_hexsha": "0448336b4c5e4b71fb4b2f17881d491d46aab5c2", "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": "SRC/dcombssq.f", "max_forks_repo_name": "drhpc/lapack", "max_forks_repo_head_hexsha": "0448336b4c5e4b71fb4b2f17881d491d46aab5c2", "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": 24.125, "max_line_length": 76, "alphanum_fraction": 0.4745250432, "num_tokens": 743, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767906859264, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6699392825844331}} {"text": "! !Solve a self-consistent problem using different \n! !iteration mixing schemes.\n! MODULE MIXING\n! USE CONSTANTS\n! USE MATRIX\n! implicit none\n! private\n\n! interface simple_mix\n! module procedure simple_mix_s,simple_mix_v\n! end interface simple_mix\n\n! public :: simple_mix\n! public :: broyden_mix\n! public :: broyden_mix_scalar\n! contains\n\n! subroutine simple_mix_s(vout,vin,alpha)\n! real(8),intent(inout) :: vout\n! real(8),intent(in) :: vin\n! real(8),intent(in) :: alpha\n! real(8) :: f,vout_(1),vin_(1)\n! vout_(1)=vout;vin_(1)=vin\n! call simple_mix_v(vout_,vin_,alpha)\n! vout=vout_(1)\n! end subroutine simple_mix_s\n\n! subroutine simple_mix_v(vout,vin,alpha)\n! real(8),intent(inout) :: vout(:)\n! real(8),intent(in) :: vin(size(vout))\n! real(8),intent(in) :: alpha\n! real(8) :: f(size(vout))\n! F=vout-vin\n! vout=vin+alpha*F\n! end subroutine simple_mix_v\n\n\n! subroutine broyden_mix_scalar(vout,vin,alpha,M,w0)\n! real(8),intent(inout) :: vout\n! real(8),intent(in) :: vin\n! real(8),intent(in) :: alpha\n! real(8) :: amix\n! integer,intent(in) :: M\n! real(8),optional :: w0\n! real(8),save :: w0_\n! real(8),dimension(1) :: vout_,vin_\n! integer :: N\n! w0_=0.01d0;if(present(w0))w0_=w0\n! N=1\n! vout_(1)=vout;vin_(1)=vin\n! call broyden_mix(N,vout_,vin_,alpha,M,w0_)\n! vout=vout_(1)\n! end subroutine broyden_mix_scalar\n\n! subroutine broyden_mix(N,vout,vin,alpha,M,w0)\n! integer,intent(in) :: N\n! ! real(8),intent(inout) :: vout(N)\n! ! real(8),intent(in) :: vin(N)\n! real(8) :: vout(N)\n! real(8) :: vin(N)\n! real(8),intent(in) :: alpha\n! real(8) :: amix\n! integer,intent(in) :: M\n! real(8),optional :: w0\n! real(8),save :: w0_\n! integer,save :: iter=1\n! integer :: iter_used,ipos,inext\n! real(8),allocatable,dimension(:,:),save :: Df,Dv,Beta\n! real(8),allocatable,dimension(:),save :: Curv,work\n! real(8) :: norm,gamma,curvature\n! integer :: i,j\n! !Save alpha mixing:\n! amix=alpha\n! !Get f=vout-vin\n! vout = vout-vin\n! !linear mixing if M=0 or first iteration\n! if(iter==1.OR.M==0)then\n! vout=vin+amix*vout\n! return\n! endif\n! !Get broyden mixing pointer\n! iter_used=min(iter-1,M)\n! ipos = iter-1-((iter-2)/M)*M\n! inext = iter-((iter-1)/M)*M\n! !allocate aux arrays and define the \n! !DeltaF^(n) = F^(n+1)-F^(n)/|F^(n+1)-F^(n)| \n! !DeltaV^(n) = V^(n+1)-V^(n)/|F^(n+1)-F^(n)| \n! if(iter==1)then\n! w0_=0.01d0;if(present(w0))w0_=w0\n! if(allocated(Df))deallocate(Df)\n! if(allocated(Dv))deallocate(Dv)\n! if(allocated(beta))deallocate(beta)\n! if(allocated(curv))deallocate(curv)\n! if(allocated(work))deallocate(work)\n! allocate(Df(M,N),Dv(M,N),Beta(M,M),Curv(N),work(M))\n! else\n! Df(ipos,:) = Vout - Df(ipos,:)\n! Dv(ipos,:) = Vin - Dv(ipos,:)\n! norm = 1.d0/sqrt(dot_product(Df(ipos,:),Df(ipos,:)))\n! Df(ipos,:)=Df(ipos,:)/norm\n! Dv(ipos,:)=Dv(ipos,:)/norm\n! endif\n! !Build \n! !we are assuming w(i)=w(j)=1\n! !beta = [w(0)*w(0)*delta(i,j) + w(i)*w(j)*a(i,j)]^-1\n! do i=1,iter_used\n! do j=1+1,iter_used\n! beta(i,j) = dot_product(Df(i,:),Df(j,:))\n! enddo\n! beta(i,i) = 1.d0+w0_*w0_!ACTHUNG I SUSPECT AN ERROR HERE!!!\n! enddo\n! call matrix_inverse(beta)\n! !vector(2) = vold + amix*f - sum_i sum_j cm(j)*b(j,i)*w(j)*u(i)*w(i)\n! do i=1,iter_used\n! do j=i+1,iter_used\n! beta(j,i)=beta(i,j)\n! enddo\n! work(i) = dot_product(Df(i,:),vout)\n! enddo\n! curv = amix*vout\n! do i=1,iter_used\n! gamma=0.d0\n! do j=i+1,iter_used\n! gamma = gamma+beta(j,i)*work(j)\n! enddo\n! curv(:) = curv(:) - gamma*(Dv(i,:)+amix*Df(i,:))\n! enddo\n! Df(inext,:)=vout\n! Dv(inext,:)=vin\n! curvature=dot_product(vout,curv)\n! if(curvature>-1.d0)then\n! vout = vin + curv\n! else\n! vout = vin + amix*0.5d0*vout\n! endif\n! end subroutine broyden_mix\n\n! END MODULE MIXING\n", "meta": {"hexsha": "3852d456921a96ded76bab7816f19c3d8a01d55e", "size": 4724, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "drivers/old_versions/mixing.f90", "max_stars_repo_name": "qftphys/An-iterative-perturbation-theory-IPT-based-solver-for-the-Dynamical-Mean-Field-Theory.", "max_stars_repo_head_hexsha": "6d2f5855c67e96c5ea67ddc1be6cecb2e7551fd8", "max_stars_repo_licenses": ["FSFAP"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "drivers/old_versions/mixing.f90", "max_issues_repo_name": "qftphys/An-iterative-perturbation-theory-IPT-based-solver-for-the-Dynamical-Mean-Field-Theory.", "max_issues_repo_head_hexsha": "6d2f5855c67e96c5ea67ddc1be6cecb2e7551fd8", "max_issues_repo_licenses": ["FSFAP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "drivers/old_versions/mixing.f90", "max_forks_repo_name": "qftphys/An-iterative-perturbation-theory-IPT-based-solver-for-the-Dynamical-Mean-Field-Theory.", "max_forks_repo_head_hexsha": "6d2f5855c67e96c5ea67ddc1be6cecb2e7551fd8", "max_forks_repo_licenses": ["FSFAP"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.9856115108, "max_line_length": 74, "alphanum_fraction": 0.4913209145, "num_tokens": 1578, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6699392754159426}} {"text": "PROGRAM mfcszo\n \n! Code converted using TO_F90 by Alan Miller\n! Date: 2004-06-28 Time: 12:58:11\n\n! ===========================================================\n! Purpose : This program computes the complex zeros of the\n! Fresnel integral C(z) or S(z) using subroutine\n! FCSZO\n! Input : KF --- Function code\n! KF=1 for C(z) or KF=2 for S(z)\n! NT --- Total number of zeros\n! Output: ZO(L) --- L-th zero of C(z) or S(z)\n! Example: NT=10\n\n! n Complex zeros of C(z) Complex zeros of S(z)\n! ------------------------------------------------------------\n! 1 1.7436675 + i .30573506 2.0092570 + i .28854790\n! 2 2.6514596 + i .25290396 2.8334772 + i .24428524\n! 3 3.3203593 + i .22395346 3.4675331 + i .21849268\n! 4 3.8757345 + i .20474747 4.0025782 + i .20085103\n! 5 4.3610635 + i .19066973 4.4741893 + i .18768859\n! 6 4.7976077 + i .17970801 4.9006784 + i .17732036\n! 7 5.1976532 + i .17081930 5.2929467 + i .16884418\n! 8 5.5690602 + i .16339854 5.6581068 + i .16172492\n! 9 5.9172173 + i .15706585 6.0011034 + i .15562108\n! 10 6.2460098 + i .15156826 6.3255396 + i .15030246\n! ===========================================================\n\nIMPLICIT DOUBLE PRECISION (e,p,w)\nIMPLICIT COMPLEX *16 (c,z)\nDIMENSION zo(100)\nWRITE(*,*)'Please Enter KF and NT '\n! READ(*,*)KF,NT\nkf=2\nnt=10\nWRITE(*,20)kf,nt\nWRITE(*,*)' ***** Please Wait ! *****'\nCALL fcszo(kf,nt,zo)\nWRITE(*,*)\nIF (kf == 1) WRITE(*,*)' n Complex zeros of C(z)'\nIF (kf == 2) WRITE(*,*)' n Complex zeros of S(z)'\nWRITE(*,*)'-----------------------------------'\nDO i=1,nt\n WRITE(*,30) i,zo(i)\nEND DO\n20 FORMAT(2X,'KF=',i2,', ','NT=',i3)\n30 FORMAT(1X,i3,f13.8,2X,2H+i,f13.8)\nEND PROGRAM mfcszo\n\n\nSUBROUTINE fcszo(kf,nt,zo)\n\n! ===============================================================\n! Purpose: Compute the complex zeros of Fresnel integral C(z)\n! or S(z) using modified Newton's iteration method\n! Input : KF --- Function code\n! KF=1 for C(z) or KF=2 for S(z)\n! NT --- Total number of zeros\n! Output: ZO(L) --- L-th zero of C(z) or S(z)\n! Routines called:\n! (1) CFC for computing Fresnel integral C(z)\n! (2) CFS for computing Fresnel integral S(z)\n! ==============================================================\n\n\nINTEGER, INTENT(IN) :: kf\nINTEGER, INTENT(IN) :: nt\nCOMPLEX, INTENT(IN OUT) :: zo(nt)\nIMPLICIT DOUBLE PRECISION (e,p,w)\nIMPLICIT COMPLEX *16 (c,z)\n\n\nw=0.0\npi=3.141592653589793D0\nDO nr=1,nt\n IF (kf == 1) psq=DSQRT(4.0D0*nr-1.0D0)\n IF (kf == 2) psq=2.0D0*nr**(0.5)\n px=psq-DLOG(pi*psq)/(pi*pi*psq**3.0)\n py=DLOG(pi*psq)/(pi*psq)\n z=CMPLX(px,py)\n IF (kf == 2) THEN\n IF (nr == 2) z=(2.8334,0.2443)\n IF (nr == 3) z=(3.4674,0.2185)\n IF (nr == 4) z=(4.0025,0.2008)\n END IF\n it=0\n DO\n 15 it=it+1\n IF (kf == 1) CALL cfc(z,zf,zd)\n IF (kf == 2) CALL cfs(z,zf,zd)\n zp=(1.0D0,0.0D0)\n DO i=1,nr-1\n zp=zp*(z-zo(i))\n END DO\n zfd=zf/zp\n zq=(0.0D0,0.0D0)\n DO i=1,nr-1\n zw=(1.0D0,0.0D0)\n DO j=1,nr-1\n IF (.NOT.(j == i)) zw=zw*(z-zo(j))\n END DO\n zq=zq+zw\n END DO\n zgd=(zd-zq*zfd)/zp\n z=z-zfd/zgd\n w0=w\n w=CDABS(z)\n IF (.NOT.(it <= 50.AND.DABS((w-w0)/w) > 1.0D-12)) EXIT\n END DO\n zo(nr)=z\nEND DO\nRETURN\nEND SUBROUTINE fcszo\n\n\nSUBROUTINE cfc(z,zf,zd)\n\n! =========================================================\n! Purpose: Compute complex Fresnel integral C(z) and C'(z)\n! Input : z --- Argument of C(z)\n! Output: ZF --- C(z)\n! ZD --- C'(z)\n! =========================================================\n\n\nCOMPLEX, INTENT(IN) :: z\nCOMPLEX, INTENT(OUT) :: zf\nCOMPLEX, INTENT(OUT) :: zd\nIMPLICIT DOUBLE PRECISION (e,p,w)\nIMPLICIT COMPLEX *16 (c,s,z)\n\neps=1.0D-14\npi=3.141592653589793D0\nw0=CDABS(z)\nzp=0.5D0*pi*z*z\nzp2=zp*zp\nz0=(0.0D0,0.0D0)\nIF (z == z0) THEN\n c=z0\nELSE IF (w0 <= 2.5) THEN\n cr=z\n c=cr\n igoon=1\n DO k=1,80\n cr=-.5D0*cr*(4.0D0*k-3.0D0)/k/(2.0D0*k-1.0D0) /(4.0D0*k+1.0D0)*zp2\n c=c+cr\n wa=CDABS(c)\n IF (DABS((wa-wa0)/wa) < eps.AND.k > 10) igoon=0\n IF (igoon == 1) THEN\n wa0=wa\n ELSE\n EXIT\n END IF\n END DO\nELSE IF (w0 > 2.5.AND.w0 < 4.5) THEN\n m=85\n c=z0\n cf1=z0\n cf0=(1.0D-100,0.0D0)\n DO k=m,0,-1\n cf=(2.0D0*k+3.0D0)*cf0/zp-cf1\n IF (k == INT(k/2)*2) c=c+cf\n cf1=cf0\n cf0=cf\n END DO\n c=CDSQRT(2.0D0/(pi*zp))*CDSIN(zp)/cf*c\nELSE\n cr=(1.0D0,0.0D0)\n cf=(1.0D0,0.0D0)\n DO k=1,20\n cr=-.25D0*cr*(4.0D0*k-1.0D0)*(4.0D0*k-3.0D0)/zp2\n cf=cf+cr\n END DO\n cr=1.0D0/(pi*z*z)\n cg=cr\n DO k=1,12\n cr=-.25D0*cr*(4.0D0*k+1.0D0)*(4.0D0*k-1.0D0)/zp2\n cg=cg+cr\n END DO\n c=.5D0+(cf*CDSIN(zp)-cg*CDCOS(zp))/(pi*z)\nEND IF\n30 zf=c\nzd=CDCOS(0.5*pi*z*z)\nRETURN\nEND SUBROUTINE cfc\n\n\nSUBROUTINE cfs(z,zf,zd)\n\n! =========================================================\n! Purpose: Compute complex Fresnel Integral S(z) and S'(z)\n! Input : z --- Argument of S(z)\n! Output: ZF --- S(z)\n! ZD --- S'(z)\n! =========================================================\n\n\nCOMPLEX, INTENT(IN) :: z\nCOMPLEX, INTENT(OUT) :: zf\nCOMPLEX, INTENT(OUT) :: zd\nIMPLICIT DOUBLE PRECISION (e,p,w)\nIMPLICIT COMPLEX *16 (c,s,z)\n\nwb0=0.0\neps=1.0D-14\npi=3.141592653589793D0\nw0=CDABS(z)\nzp=0.5D0*pi*z*z\nzp2=zp*zp\nz0=(0.0D0,0.0D0)\nIF (z == z0) THEN\n s=z0\nELSE IF (w0 <= 2.5) THEN\n s=z*zp/3.0D0\n cr=s\n igoon=1\n DO k=1,80\n cr=-.5D0*cr*(4.0D0*k-1.0D0)/k/(2.0D0*k+1.0D0) /(4.0D0*k+3.0D0)*zp2\n s=s+cr\n wb=CDABS(s)\n IF (DABS(wb-wb0) < eps.AND.k > 10) igoon=1\n IF (igoon == 1) THEN\n wb0=wb\n ELSE\n EXIT\n END IF\n END DO\nELSE IF (w0 > 2.5.AND.w0 < 4.5) THEN\n m=85\n s=z0\n cf1=z0\n cf0=(1.0D-100,0.0D0)\n DO k=m,0,-1\n cf=(2.0D0*k+3.0D0)*cf0/zp-cf1\n IF (k /= INT(k/2)*2) s=s+cf\n cf1=cf0\n cf0=cf\n END DO\n s=CDSQRT(2.0D0/(pi*zp))*CDSIN(zp)/cf*s\nELSE\n cr=(1.0D0,0.0D0)\n cf=(1.0D0,0.0D0)\n DO k=1,20\n cr=-.25D0*cr*(4.0D0*k-1.0D0)*(4.0D0*k-3.0D0)/zp2\n cf=cf+cr\n END DO\n cr=1.0D0/(pi*z*z)\n cg=cr\n DO k=1,12\n cr=-.25D0*cr*(4.0D0*k+1.0D0)*(4.0D0*k-1.0D0)/zp2\n cg=cg+cr\n END DO\n s=.5D0-(cf*CDCOS(zp)+cg*CDSIN(zp))/(pi*z)\nEND IF\n30 zf=s\nzd=CDSIN(0.5*pi*z*z)\nRETURN\nEND SUBROUTINE cfs\n", "meta": {"hexsha": "6a1c2a3c459b073be2189bbc9632c0887c038576", "size": 6527, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "MATLAB/f2matlab/comp_spec_func/mfcszo.f90", "max_stars_repo_name": "vasaantk/bin", "max_stars_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MATLAB/f2matlab/comp_spec_func/mfcszo.f90", "max_issues_repo_name": "vasaantk/bin", "max_issues_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MATLAB/f2matlab/comp_spec_func/mfcszo.f90", "max_forks_repo_name": "vasaantk/bin", "max_forks_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.1038461538, "max_line_length": 70, "alphanum_fraction": 0.4888922935, "num_tokens": 2849, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767746654974, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6699392750753188}} {"text": "* \n*\n* ------------------------------------------------------------------\n*\tL U L U \n* ------------------------------------------------------------------\n*\n SUBROUTINE LULU(A,L,U,NDIM)\nC\nC LU DECOMPOSITION OF MATRIX A\nC\nC A = L * U\nC\nC WHERE L IS A LOWER TRIANGULAR MATRIX WITH A\nC UNIT DIAGONAL AND U IS AN UPPER DIAGONAL\nC\nC L AND U ARE STORED AS ONE DIMENSIONAL ARRAYS\nC\nC L(I,J) = L(I*(I-1)/2 + J ) ( I .GE. J )\nC\nC U(I,J) = U(J*(J-1)/2 + I ) ( J .GE. I )\nC\nC THIS ADRESSING SCHEMES SUPPORTS VECTORIZATION OVER COLUMNS\nC FOR L AND OVER ROWS FOR U .\nC\nC\nC NO PIVOTING IS DONE HERE , SO THE SCHEME GOES :\nC\nC LOOP OVER R=1, NDIM\nC LOOP OVER J = R, NDIM\nC U(R,J) = A(R,J) - SUM(K=1,R-1) L(R,K) * U(K,J)\nC END OF LOOP OVER J\nC\nC LOOP OVER I = R+1, NDIM\nC L(I,R) = (A(I,R) - SUM(K=1,R-1)L(I,K) * U(K,R) ) /U(R,R)\nC END OF LOOP OVER I\nC END OF LOOP OVER R\nC\nC JEPPE OLSEN , OCTOBER 1988\nC\n IMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION A(NDIM,NDIM)\n DOUBLE PRECISION L(*),U(*)\n REAL * 8 INPROD\n INTEGER R\nC\nC\n DO 1000 R = 1, NDIM\nC\n DO 100 J = R, NDIM\n U(J*(J-1)/2 + R ) = A(R,J) -\n & INPROD(L(R*(R-1)/2+1),U(J*(J-1)/2+1),R-1)\n 100 CONTINUE\nC\n XFACI = 1.0D0/ U(R*(R+1)/2)\n L(R*(R+1)/2 ) = 1.0D0\n DO 200 I = R+1, NDIM\n L(I*(I-1)/2 + R) = (A(I,R) -\n & INPROD(L(I*(I-1)/2+1),U(R*(R-1)/2+1),R-1) ) * XFACI\n 200 CONTINUE\nC\n 1000 CONTINUE\nC\n NTEST = 0\n IF ( NTEST .NE. 0 ) THEN\n WRITE(6,*) ' L MATRIX '\n CALL PRSYM(L,NDIM)\n WRITE(6,*) ' U MATRIX ( TRANSPOSED ) '\n CALL PRSYM(U,NDIM)\n END IF\nC\n RETURN\n END\n", "meta": {"hexsha": "c2cf19f35f47bbeb324a3fd1b0a94882c5548fc4", "size": 1732, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/appl/biotr/lulu.f", "max_stars_repo_name": "mansour2014/ATSP2K_plus", "max_stars_repo_head_hexsha": "30842b9f086d1e497aeb778e2a352d1e8e520ec3", "max_stars_repo_licenses": ["BSD-4-Clause-UC"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-07-21T14:03:39.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-21T14:03:39.000Z", "max_issues_repo_path": "src/appl/biotr/lulu.f", "max_issues_repo_name": "mzmansour/ATSP2K_plus", "max_issues_repo_head_hexsha": "30842b9f086d1e497aeb778e2a352d1e8e520ec3", "max_issues_repo_licenses": ["BSD-4-Clause-UC"], "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/appl/biotr/lulu.f", "max_forks_repo_name": "mzmansour/ATSP2K_plus", "max_forks_repo_head_hexsha": "30842b9f086d1e497aeb778e2a352d1e8e520ec3", "max_forks_repo_licenses": ["BSD-4-Clause-UC"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.7260273973, "max_line_length": 72, "alphanum_fraction": 0.4665127021, "num_tokens": 687, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460332, "lm_q2_score": 0.7577943822145998, "lm_q1q2_score": 0.6699200013641737}} {"text": "program yeval\n \n use omp_lib\n\n implicit none\n\n integer(kind=8), parameter :: n = 2**16\n integer(kind=4) :: i, nthreads\n real(kind=8), dimension(n) :: y\n real(kind=8) :: dx, x\n\n ! Specify number of threads to use:\n !$ print *, \"How many threads to use? \"\n !$ read *, nthreads\n !$ call omp_set_num_threads(nthreads)\n !$ print \"('Using OpenMP with ',i3,' threads')\", nthreads\n\n dx = 1.d0 / (n+1.d0)\n\n !$omp parallel do private(x) \n do i=1, n\n x = i * dx\n y(i) = exp(x) * cos(x) * sin(x) * sqrt(5.d0 * x + 6.d0)\n enddo\n !$omp end parallel do\n\n print *, \"Filled vector y of length\", n\n\nend program yeval", "meta": {"hexsha": "756fc052d86360d2568eb99bd583c1ff9f05079f", "size": 644, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/yeval.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/yeval.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/yeval.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": 22.2068965517, "max_line_length": 61, "alphanum_fraction": 0.5745341615, "num_tokens": 215, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392695254319, "lm_q2_score": 0.7577943658046608, "lm_q1q2_score": 0.6699199775964402}} {"text": "module chem\n\timplicit none\n\tinteger, parameter :: dp=kind(0.d0)\n\treal(dp) :: PI = 4*ATAN(1.d0)\n\t\n\tprivate\n\tpublic altitude, projection_onto_plane, normal_to_plane, discriminant, cross_product, distance, compute_length, & \n\tcompute_angle, compute_dihedral, compute_improper\n\t\n\tcontains\n\t\tfunction altitude(A, B, C)\n\t\t\t! computes altitude of triangle abc with respect to base bc\n\t\t\treal(dp), dimension(:), intent(in) :: A, B, C\n\t\t\treal(dp), dimension(3) :: altitude, v, M\n\t\t\treal(dp) :: ba, altitude_norm, bm\n\n\t\t\tba = NORM2(B-A)\n\t\t\tv = C - B\n\t\t\taltitude_norm = NORM2(cross_product( (A-C), v))/NORM2(v)\n\n\t\t\tbm = SQRT( ba**2 - altitude_norm**2 )\n\t\t\tM = B + (bm/NORM2(v))*v\n\n\t\t\taltitude = A - M\n\t\tend function\n\n\t\tfunction projection_onto_plane(v, n)\n\t\t\treal(dp), dimension(:), intent(in) :: v, n\n\t\t\treal(dp), dimension(3) :: pvector\n\t\t\treal(dp) :: projection_onto_plane\n\n\t\t\tpvector = v - ( DOT_PRODUCT(v,n)/NORM2(n)**2 )*n\n\t\t\tprojection_onto_plane = NORM2(pvector)**2\n\t\tend function\n\n\t\tfunction normal_to_plane(a, b, c)\n\t\t\treal(dp), dimension(:), intent(in) :: a, b, c\n\t\t\treal(dp), dimension(3) :: normal_to_plane, u, v\n\n\t\t\tu = a - b\n\t\t\tv = c - b\n\n\t\t\tnormal_to_plane = cross_product(u,v)\n\t\t\tnormal_to_plane = normal_to_plane/NORM2(normal_to_plane)\n\n\t\tend function\n\n\t\tfunction discriminant(a, b, c, d)\n\t\t\treal(dp) :: a, b, c, d\n\t\t\treal(dp) :: discriminant\n\n\t\t\tdiscriminant = 18*a*b*c*d - 4*(b**3)*d + (b**2)*(c**2) - 4*a*(c**3) - 27*(a**2)*(d**2)\n\t\tend function\n\n\t\tfunction cross_product(u, v)\n\t\t\treal(dp), dimension(3) :: u, v, cross_product\n\n\t\t\tcross_product(1) = u(2)*v(3) - u(3)*v(2)\n\t\t\tcross_product(2) = -u(1)*v(3) + u(3)*v(1)\n\t\t\tcross_product(3) = u(1)*v(2) - u(2)*v(1)\n\n\t\tend function\n\n\t\tfunction distance(b, c)\n\t\t\treal(dp) :: distance\n\t\t\treal(dp), dimension(3), intent(in) :: b, c\n\t\t\tinteger :: i\n\n\t\t\tdistance = 0\n\t\t\tdo i=1,3\n\t\t\t\tdistance = distance + (c(i)-b(i))**2\n\t\t\tenddo\n\t\t\t!distance = sqrt(distance)\n\t\tend function\n\t\t\n\t\tfunction compute_length(u, v)\n\t\t\treal(dp), dimension(:) :: u, v\n\t\t\treal(dp) :: compute_length\n\n\t\t\tcompute_length = NORM2( v - u )\n\t\tend function\n\n\t\tfunction compute_angle(u, v, w)\n\t\t\treal(dp), dimension(:) :: u, v, w\n\t\t\treal(dp) :: compute_angle\n\n\t\t\tcompute_angle = ACOS( DOT_PRODUCT((u - v), (w - v))/(NORM2(u-v)*NORM2(w-v)) )\n\t\t\t\n\t\tend function\n\n\t\tfunction compute_dihedral(u, v, w, x)\n\t\t\treal(dp), dimension(:) :: u, v, w, x\n\t\t\treal(dp), dimension(3) :: n1, n2, m\n\t\t\treal(dp) :: compute_dihedral, s, t\n\n\t\t\tn1 = cross_product( (u-v), (w-v) )\n\t\t\tn1 = n1/NORM2(n1)\n\t\t\tn2 = cross_product( (v-w), (x-w) )\n\t\t\tn2 = n2/NORM2(n2)\n\n\t\t\tm = (w-v)/NORM2(w-v)\n\t\t\tm = cross_product(n1,m)\n\n\t\t\ts = DOT_PRODUCT(n1,n2)\n\t\t\tt = DOT_PRODUCT(m,n2)\n\n\t\t\tcompute_dihedral = -ATAN2(t,s)\n\t\t\t\n\t\tend function\n\n\t\tfunction compute_improper(u,v,w,x)\n\t\t\treal(dp), dimension(:) :: u, v, w, x\n\t\t\treal(dp), dimension(3) :: n1, n2, m\n\t\t\treal(dp) :: compute_improper, s, t\n\n\t\t\tn1 = cross_product( (v-u), (w-u) )\n\t\t\tn1 = n1/NORM2(n1)\n\n\t\t\tn2 = cross_product( (w-v), (x-v) )\n\t\t\tn2 = n2/NORM2(n2)\n\n\t\t\tcompute_improper = ACOS( DOT_PRODUCT(n1,n2) )\n\t\tend function\n\t\t\nend module chem\n", "meta": {"hexsha": "e65d4ce913561e41fc3b42058e0ab856933b3c1a", "size": 3070, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "chem.f90", "max_stars_repo_name": "macardosa/jedi", "max_stars_repo_head_hexsha": "2cad78ba0da483fe7e5efe4a7cdfbefff2dc730d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-08-16T15:24:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-11T16:25:42.000Z", "max_issues_repo_path": "chem.f90", "max_issues_repo_name": "macardosa/jedi", "max_issues_repo_head_hexsha": "2cad78ba0da483fe7e5efe4a7cdfbefff2dc730d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chem.f90", "max_forks_repo_name": "macardosa/jedi", "max_forks_repo_head_hexsha": "2cad78ba0da483fe7e5efe4a7cdfbefff2dc730d", "max_forks_repo_licenses": ["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.3650793651, "max_line_length": 115, "alphanum_fraction": 0.6071661238, "num_tokens": 1108, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418137109956, "lm_q2_score": 0.7248702642896702, "lm_q1q2_score": 0.6698829207458245}} {"text": "FUNCTION radext(idoy,bmalat)\n!\nIMPLICIT NONE\n!\nINCLUDE 'p1const.inc'\nINCLUDE 'p1unconv.inc'\nINCLUDE 'p1solar.inc'\n!\n! PARAMETER definitions\n!\nREAL,PARAMETER :: gsc = 0.08202\n!\n! Function arguments\n!\nREAL :: bmalat\nINTEGER :: idoy\nREAL :: radext\n!\n! Local variables\n!\nREAL :: dec,dr,ra1,ra2,rdec,rlat,ws\nREAL :: declination,hourangle\n!\n! + + + purpose + + +\n! this subroutine estimates the incoming extraterrestial radiation\n! for a given location (mj/m^2/day)\n \n! + + + key words + + +\n! radiation, solar, extraterrestrial\n \n! + + + argument declarations + + +\n \n! + + + argument definitions + + +\n! idoy - julian day of year, 1-366\n! bmalat - latitude of the site, degrees\n \n! + + + common block + + +\n \n! + + + local variables + + +\n \n! + + + local definitions + + +\n! dec - declination of the earth with respect to the sun (degrees)\n! dr - direct radiation variation with distance from sun of earth orbit\n! ra1, ra2 - intermediate calculations\n! rlat - latitude (radians)\n! rdec - declination (radians)\n! ws - sunset hour angle (radians)\n \n! + + + parameters + + +\n \n \n \n! gsc - solar_constant in mj/m^2-min (0.08202 mj/m^2-min = 1367 w/m^2)\n \n! + + + data initialization + + +\n \n! + + + function declarations + + +\n \n! + + + end specifications + + +\n \n! convert to radians for trig functions\nrlat = bmalat*degtorad\ndec = declination(idoy)\nrdec = dec*degtorad\n \n! compute factor for variable distance from sun along orbital path\ndr = 1 + 0.033*cos(2*pi*idoy/365) \n \nws = hourangle(bmalat,dec,beamrise)*degtorad\nra1 = ((24.0*60.0)/pi)*gsc*dr \nra2 = (ws*sin(rlat)*sin(rdec)) + (cos(rlat)*cos(rdec)*sin(ws)) \nradext = ra1*ra2 \n! \nEND FUNCTION radext\n", "meta": {"hexsha": "7afa4bff89dd204b19ebeecfdd8662464b5970d3", "size": 1997, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Project Documents/Source Code Original/Radext.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/Radext.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/Radext.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": 26.6266666667, "max_line_length": 111, "alphanum_fraction": 0.5463194792, "num_tokens": 569, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418137109955, "lm_q2_score": 0.7248702642896702, "lm_q1q2_score": 0.6698829207458245}} {"text": "module m_parameters\n !! Module contains user defined parameters for consistent use\nuse variableKind\nimplicit none\nreal(r64), parameter :: inf = huge(0.d0)\nreal(r64),parameter :: NaN = transfer((/ Z'00000000', Z'7FF80000' /),1.0_r64)\nreal(r64),parameter :: pi = dacos(-1.d0)\nend module\n", "meta": {"hexsha": "04710078e3badf3d02a33d56397ee14445da5616", "size": 286, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "docs/src/m_parameters.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": "docs/src/m_parameters.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": "docs/src/m_parameters.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": 31.7777777778, "max_line_length": 77, "alphanum_fraction": 0.7272727273, "num_tokens": 86, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8558511616741041, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6698425961492852}} {"text": " program demo_conjg\n use, intrinsic :: iso_fortran_env, only : real_kinds, &\n & real32, real64, real128\n implicit none\n complex :: z = (2.0, 3.0)\n complex(kind=real64) :: dz = (&\n & 1.2345678901234567_real64, &\n & -1.2345678901234567_real64)\n z= conjg(z)\n print *, z\n dz = conjg(dz)\n print *, dz\n end program demo_conjg\n", "meta": {"hexsha": "be49f4c7b75349e1b888115d25ba223b73c35cf6", "size": 467, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/demo_conjg.f90", "max_stars_repo_name": "urbanjost/fortran-intrinsic-manpages", "max_stars_repo_head_hexsha": "672e0545bcbef3dd6c8169c8f6b8424dbb3f0880", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-06-30T07:29:39.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-10T07:36:25.000Z", "max_issues_repo_path": "example/demo_conjg.f90", "max_issues_repo_name": "urbanjost/fortran-intrinsic-manpages", "max_issues_repo_head_hexsha": "672e0545bcbef3dd6c8169c8f6b8424dbb3f0880", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-10-07T21:29:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-07T00:19:52.000Z", "max_forks_repo_path": "example/demo_conjg.f90", "max_forks_repo_name": "urbanjost/fortran-intrinsic-manpages", "max_forks_repo_head_hexsha": "672e0545bcbef3dd6c8169c8f6b8424dbb3f0880", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-10-08T00:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-08T00:41:17.000Z", "avg_line_length": 33.3571428571, "max_line_length": 66, "alphanum_fraction": 0.4646680942, "num_tokens": 130, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672595, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6698425846387897}} {"text": "integer n\nwrite \"Give fibonacci n = \"\nread n\nwrite \"The fibonacci of \",n\nwrite \" is \",fibonacci(n)\nend\n\ninteger function fibonacci(integer number)\n if(number .eq. 0) fibonacci = 0\n if(number .eq. 1) fibonacci = 1\n fibonacci = fibonacci(number - 1) + fibonacci(number-2)\nend", "meta": {"hexsha": "f5dea4bee00483807742cc095b66b19fd7478b59", "size": 282, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "test4_fib_simple.f", "max_stars_repo_name": "konmaz/Compiler-Design-Project", "max_stars_repo_head_hexsha": "e1f8e73308996607fa08b3d0c592b226b7bf7123", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test4_fib_simple.f", "max_issues_repo_name": "konmaz/Compiler-Design-Project", "max_issues_repo_head_hexsha": "e1f8e73308996607fa08b3d0c592b226b7bf7123", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test4_fib_simple.f", "max_forks_repo_name": "konmaz/Compiler-Design-Project", "max_forks_repo_head_hexsha": "e1f8e73308996607fa08b3d0c592b226b7bf7123", "max_forks_repo_licenses": ["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": 59, "alphanum_fraction": 0.6914893617, "num_tokens": 81, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511616741041, "lm_q2_score": 0.7826624688140726, "lm_q1q2_score": 0.6698425831332464}} {"text": "! Copyright 2015-2016 Andrew Dawson, Peter Dueben\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 implied.\n! See the License for the specific language governing permissions and\n! limitations under the License.\n\nPROGRAM lorenz63\n! A Lorenz '63 model capable of using reduced floating-point precision.\n!\n\n USE rp_emulator\n USE cliargs_mod, ONLY : cliargs\n\n IMPLICIT NONE\n\n ! Time-stepping parameters.\n REAL(KIND=RPE_REAL_KIND) :: t\n REAL(KIND=RPE_REAL_KIND) :: time_start = 0\n REAL(KIND=RPE_REAL_KIND) :: time_stop = 5\n REAL(KIND=RPE_REAL_KIND) :: dt = 0.01\n\n ! Lorenz 63 system parameters.\n TYPE(rpe_var) :: sigma\n TYPE(rpe_var) :: rho\n TYPE(rpe_var) :: beta\n\n ! Array to store the 3d coordinate of the current system state.\n TYPE(rpe_var), DIMENSION(3) :: x\n\n ! Runge-Kutta parameters.\n TYPE(rpe_var), DIMENSION(3) :: k1, k2, k3, k4\n TYPE(rpe_var), DIMENSION(3) :: x2, x3, x4, xd\n\n ! Handle command line arguments.\n CALL cliargs (RPE_ACTIVE, RPE_DEFAULT_SBITS, RPE_IEEE_HALF)\n\n ! Set the model parameters.\n sigma = 10\n rho = 28\n beta = 8.0_RPE_REAL_KIND / 3.0_RPE_REAL_KIND\n\n ! Set the initial state.\n t = time_start\n x = (/ 1.508870_RPE_REAL_KIND, -1.531271_RPE_REAL_KIND, 25.46091_RPE_REAL_KIND /)\n\n ! Loop over time evaluating the model state (x).\n WRITE (*, '(F19.15, \" \", F19.15, \" \", F19.15)') x%val\n DO WHILE (t <= time_stop)\n k1 = f(x, sigma, rho, beta)\n x2 = x + rpe_literal(0.5) * dt * k1\n k2 = f(x2, sigma, rho, beta)\n x3 = x + rpe_literal(0.5) * dt * k2\n k3 = f(x3, sigma, rho, beta)\n x4 = x + dt * k3\n k4 = f(x4, sigma, rho, beta)\n x = x + dt * (k1 + 2 * (k2 + k3) + k4) / rpe_literal(6.)\n t = t + dt\n WRITE (*, '(F19.15, \" \", F19.15, \" \", F19.15)') x%val\n END DO\n\nCONTAINS\n\n FUNCTION f (x, sigma, rho, beta)\n ! Update the Runge-Kutta parameters.\n !\n IMPLICIT NONE\n TYPE(rpe_var), DIMENSION(3), INTENT(IN) :: x\n TYPE(rpe_var), INTENT(IN) :: sigma\n TYPE(rpe_var), INTENT(IN) :: rho\n TYPE(rpe_var), INTENT(IN) :: beta\n TYPE(rpe_var), DIMENSION(3) :: f\n f(1) = sigma * (x(2) - x(1))\n f(2) = x(1) * (rho - x(3)) - x(2)\n f(3) = x(1) * x(2) - beta * x(3)\n END FUNCTION f\n\nEND PROGRAM\n", "meta": {"hexsha": "088e00fdf251169c8b14316af1a9d41d2611b530", "size": 2766, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/integration/lorenz63/l63_reduced_precision.f90", "max_stars_repo_name": "sparonuz/rpe", "max_stars_repo_head_hexsha": "017189986a9653691ecc1c531e53d528d3ccbbb7", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2016-01-09T23:22:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-14T23:44:37.000Z", "max_issues_repo_path": "test/integration/lorenz63/l63_reduced_precision.f90", "max_issues_repo_name": "sparonuz/rpe", "max_issues_repo_head_hexsha": "017189986a9653691ecc1c531e53d528d3ccbbb7", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 12, "max_issues_repo_issues_event_min_datetime": "2016-01-06T14:08:39.000Z", "max_issues_repo_issues_event_max_datetime": "2017-02-15T15:19:03.000Z", "max_forks_repo_path": "test/integration/lorenz63/l63_reduced_precision.f90", "max_forks_repo_name": "sparonuz/rpe", "max_forks_repo_head_hexsha": "017189986a9653691ecc1c531e53d528d3ccbbb7", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2016-01-11T16:55:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-03T13:51:29.000Z", "avg_line_length": 32.1627906977, "max_line_length": 85, "alphanum_fraction": 0.6026753435, "num_tokens": 893, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.6698425803001101}} {"text": "module integration\n\n! This module contains the routines for the time integration and the computation\n! of numerical fluxes (Rusanov or HLL in this example).\n\n use pde\n use global_module\n\n implicit none\n \n real(kind=8), dimension(Neq,Nx,Ny) :: U_new ! Working variable\n\n contains\n\n ! ======================================================================== \n \n subroutine forward_Euler_step(U, dt)\n\n ! This function performs one step of the Forward Euler explicit time integrator \n\n implicit none\n \n real(kind=8), dimension(Neq,Nx,Ny), intent(inout) :: U\n\n real(kind=8), intent(in) :: dt\n integer :: i, j, eqID\n \n real(kind=8), dimension(Neq) :: F_N, F_S, F_W, F_E, Src\n real(kind=8) :: y_j, y_jmhalf, y_jphalf\n\n ! First, assign BCs. Wall BCs need to be updated in time, taking the value\n ! from neighboring cells.\n call assign_BCs(U) ! See the pde.f03 module\n\n ! Update solution using the forward Euler integrator - INTERNAL CELLS only\n do j = 3, Ny-2\n do i = 3, Nx-2\n\n ! call compute_fluxes_Rusanov(U, i, j, F_N, F_S, F_W, F_E)\n call compute_fluxes_HLL(U, i, j, F_N, F_S, F_W, F_E)\n\n ! Symmetry BC\n if (j.eq.3) then\n call compute_flux_y_SYM(U(:,i,j), F_S)\n end if\n\n ! Compute geometrical source term (basically, the pressure)\n call compute_source_term(U,i,j, Src)\n\n y_j = y_min + dy/2.0d0 + (real(j)-3.0d0)*dy\n y_jmhalf = y_j - dy/2.0d0\n y_jphalf = y_j + dy/2.0d0\n\n U_new(:,i,j) = U(:,i,j) - dt/dx*(F_E - F_W) - dt/(dy*y_j)*(F_N*y_jphalf - F_S*y_jmhalf) + dt*Src\n \n ! Check that the solution did not diverge\n do eqID = 1, Neq\n if (isnan(U_new(eqID,i,j))) then \n print*, 'Solution diverged, try with a smaller time step! Aborting.'\n stop\n end if\n end do\n\n end do\n end do\n\n ! Save solution (internal cells ONLY! Do not overwrite ghost cells!)\n U(:,3:Nx-2,3:Ny-2) = U_new(:,3:Nx-2,3:Ny-2)\n\n end subroutine\n\n ! ======================================================================== \n\n subroutine compute_fluxes_HLL(U, i, j, F_N, F_S, F_W, F_E)\n\n ! Computes HLL numerical fluxes for the cell (i,j)\n\n implicit none\n\n real(kind=8), dimension(Neq,Nx,Ny), intent(in) :: U\n real(kind=8), dimension(Neq), intent(out) :: F_N, F_S, F_W, F_E\n integer, intent(in) :: i, j\n\n integer :: eqID\n real(kind=8), dimension(Neq) :: U_L, U_R, F_L, F_R\n\n real(kind=8) :: ws_min_L, ws_max_L, ws_min_R, ws_max_R, ws_min, ws_max ! wave speeds\n\n ! ------ North interface\n\n ! Reconstruct the solution, passing the four cells that neighbor the interface\n call reconstruct_sol_interface(U(:,i,j-1), U(:,i,j), U(:,i,j+1), U(:,i,j+2), U_L, U_R)\n\n call compute_flux_ws_y(U_L, F_L, ws_max_L, ws_min_L)\n call compute_flux_ws_y(U_R, F_R, ws_max_R, ws_min_R)\n\n ws_min = MIN(ws_min_L, ws_min_R)\n ws_max = MAX(ws_max_L, ws_max_R)\n\n ! HLL fluxes\n if (ws_min .ge. 0.0) then\n F_N = F_L\n else if (ws_max .lt. 0.0) then\n F_N = F_R\n else\n F_N = (ws_min*ws_max*(U_R - U_L) + ws_max*F_L - ws_min*F_R)/(ws_max - ws_min);\n end if\n\n ! Update global maximum wave speed (used for setting the time step)\n\n ws_max = MAX(ABS(ws_max_L), ABS(ws_min_L), ABS(ws_max_R), ABS(ws_min_R))\n\n ! ------ South interface\n\n ! Reconstruct the solution, passing the four cells that neighbor the interface\n call reconstruct_sol_interface(U(:,i,j-2), U(:,i,j-1), U(:,i,j), U(:,i,j+1), U_L, U_R)\n\n call compute_flux_ws_y(U_L, F_L, ws_max_L, ws_min_L)\n call compute_flux_ws_y(U_R, F_R, ws_max_R, ws_min_R)\n\n ws_min = MIN(ws_min_L, ws_min_R)\n ws_max = MAX(ws_max_L, ws_max_R)\n\n ! HLL fluxes\n if (ws_min .ge. 0.0) then\n F_S = F_L\n else if (ws_max .lt. 0.0) then\n F_S = F_R\n else\n F_S = (ws_min*ws_max*(U_R - U_L) + ws_max*F_L - ws_min*F_R)/(ws_max - ws_min);\n end if\n\n ! Update global maximum wave speed (used for setting the time step)\n ws_max = MAX(ABS(ws_max_L), ABS(ws_min_L), ABS(ws_max_R), ABS(ws_min_R))\n\n ! ------ East interface\n\n ! Reconstruct the solution, passing the four cells that neighbor the interface\n call reconstruct_sol_interface(U(:,i-1,j), U(:,i,j), U(:,i+1,j), U(:,i+2,j), U_L, U_R)\n\n call compute_flux_ws_x(U_L, F_L, ws_max_L, ws_min_L)\n call compute_flux_ws_x(U_R, F_R, ws_max_R, ws_min_R)\n\n ws_min = MIN(ws_min_L, ws_min_R)\n ws_max = MAX(ws_max_L, ws_max_R)\n\n ! HLL fluxes\n if (ws_min .ge. 0.0) then\n F_E = F_L\n else if (ws_max .lt. 0.0) then\n F_E = F_R\n else\n F_E = (ws_min*ws_max*(U_R - U_L) + ws_max*F_L - ws_min*F_R)/(ws_max - ws_min);\n end if\n\n ! Update global maximum wave speed (used for setting the time step)\n ws_max = MAX(ABS(ws_max_L), ABS(ws_min_L), ABS(ws_max_R), ABS(ws_min_R))\n\n ! ------ West interface\n\n ! Reconstruct the solution, passing the four cells that neighbor the interface\n call reconstruct_sol_interface(U(:,i-2,j), U(:,i-1,j), U(:,i,j), U(:,i+1,j), U_L, U_R)\n\n call compute_flux_ws_x(U_L, F_L, ws_max_L, ws_min_L)\n call compute_flux_ws_x(U_R, F_R, ws_max_R, ws_min_R)\n\n ws_min = MIN(ws_min_L, ws_min_R)\n ws_max = MAX(ws_max_L, ws_max_R)\n\n ! HLL fluxes\n if (ws_min .ge. 0.0) then\n F_W = F_L\n else if (ws_max .lt. 0.0) then\n F_W = F_R\n else\n F_W = (ws_min*ws_max*(U_R - U_L) + ws_max*F_L - ws_min*F_R)/(ws_max - ws_min);\n end if\n\n ! Update global maximum wave speed (used for setting the time step)\n ws_max = MAX(ABS(ws_max_L), ABS(ws_min_L), ABS(ws_max_R), ABS(ws_min_R))\n\n end subroutine\n\n ! ==============================================================\n\n subroutine compute_fluxes_Rusanov(U, i, j, F_N, F_S, F_W, F_E)\n\n ! Computes Rusanov numerical fluxes for the cell (i,j)\n\n implicit none\n\n real(kind=8), dimension(Neq,Nx,Ny), intent(in) :: U\n real(kind=8), dimension(Neq), intent(out) :: F_N, F_S, F_W, F_E \n integer, intent(in) :: i, j\n\n integer :: eqID\n real(kind=8), dimension(Neq) :: U_L, U_R, F_L, F_R\n\n real(kind=8) :: ws_min_L, ws_max_L, ws_min_R, ws_max_R, ws_max ! wave speeds\n\n ! ------ North interface\n U_L = U(:,i,j)\n U_R = U(:,i,j+1)\n\n call compute_flux_ws_y(U_L, F_L, ws_max_L, ws_min_L) \n call compute_flux_ws_y(U_R, F_R, ws_max_R, ws_min_R)\n\n ws_max = MAX(ABS(ws_max_L), ABS(ws_min_L), ABS(ws_max_R), ABS(ws_min_R))\n\n F_N = 0.5*(F_R + F_L) - ws_max/2.0*(U_R-U_L) ! Rusanov flux\n\n ! ------ South interface\n U_L = U(:,i,j-1)\n U_R = U(:,i,j)\n\n call compute_flux_ws_y(U_L, F_L, ws_max_L, ws_min_L)\n call compute_flux_ws_y(U_R, F_R, ws_max_R, ws_min_R)\n\n ws_max = MAX(ABS(ws_max_L), ABS(ws_min_L), ABS(ws_max_R), ABS(ws_min_R))\n\n F_S = 0.5*(F_R + F_L) - ws_max/2.0*(U_R-U_L) ! Rusanov flux\n\n ! ------ East interface\n U_L = U(:,i,j)\n U_R = U(:,i+1,j)\n\n call compute_flux_ws_x(U_L, F_L, ws_max_L, ws_min_L)\n call compute_flux_ws_x(U_R, F_R, ws_max_R, ws_min_R)\n\n ws_max = MAX(ABS(ws_max_L), ABS(ws_min_L), ABS(ws_max_R), ABS(ws_min_R))\n\n F_E = 0.5*(F_R + F_L) - ws_max/2.0*(U_R-U_L) ! Rusanov flux\n\n ! ------ West interface\n U_L = U(:,i-1,j)\n U_R = U(:,i,j)\n\n call compute_flux_ws_x(U_L, F_L, ws_max_L, ws_min_L)\n call compute_flux_ws_x(U_R, F_R, ws_max_R, ws_min_R)\n\n ws_max = MAX(ABS(ws_max_L), ABS(ws_min_L), ABS(ws_max_R), ABS(ws_min_R))\n\n F_W = 0.5*(F_R + F_L) - ws_max/2.0*(U_R-U_L) ! Rusanov flux\n\n end subroutine\n\n ! ======================================================================== \n\n subroutine reconstruct_sol_interface(U_m2, U_m1, U_p1, U_p2, U_L, U_R)\n \n ! Takes the four points around an interface (minus_1, minus_2, plus_1, plus_2) and \n ! computes the left and right states using first order or MUSCL TVD-limited reconstruction\n \n real(kind=8), dimension(Neq), intent(in) :: U_m2, U_m1, U_p1, U_p2\n real(kind=8), dimension(Neq), intent(out) :: U_L, U_R\n\n ! Working variables\n integer :: eID ! equation ID\n real(kind=8) :: theta_L, theta_R ! ratio of consecutive gradients\n real(kind=8), dimension(Neq) :: P_m2, P_m1, P_p1, P_p2, P_L, P_R ! primitive variables \n \n if (bool_MUSCL .EQV. .FALSE.) then\n ! ***** First order solution *****\n \n U_L = U_m1\n U_R = U_p1\n \n else\n ! ***** Second order solution *****\n \n ! Perform reconstruction in primitive variables \n call compute_primitive_from_conserved(U_m2, P_m2)\n call compute_primitive_from_conserved(U_m1, P_m1)\n call compute_primitive_from_conserved(U_p1, P_p1)\n call compute_primitive_from_conserved(U_p2, P_p2)\n\n do eID = 1, Neq ! Loop on the quantities\n \n ! Compute ratio of consecutive gradients\n theta_L = (P_p1(eID) - P_m1(eID))/(P_m1(eID) - P_m2(eID) + 1.0d-15) ! Add a small tolerance\n theta_R = (P_p2(eID) - P_p1(eID))/(P_p1(eID) - P_m1(eID) + 1.0d-15) ! Add a small tolerance\n \n ! Limited linear reconstruction \n P_L(eID) = P_m1(eID) + phi_limiter(theta_L)*(P_m1(eID) - P_m2(eID))/2.0\n P_R(eID) = P_p1(eID) - phi_limiter(1.0d0/(theta_R+1.0d-15))*(P_p2(eID) - P_p1(eID))/2.0\n\n end do\n\n ! Compute conservative variables\n call compute_conserved_from_primitive(P_L, U_L)\n call compute_conserved_from_primitive(P_R, U_R)\n\n end if\n\n end subroutine\n\n ! ========================================================================\n\n real(kind=8) function phi_limiter(theta)\n\n real(kind=8), intent(in) :: theta ! ratio of consecutive gradients\n\n phi_limiter = (theta*theta + theta)/(theta*theta + 1.0) ! van Albada symmetric limiter\n ! phi_limiter = (theta + abs(theta))/(1.0 + abs(theta)) ! van Leer limiter\n\n end function \n\n\n\nend module\n", "meta": {"hexsha": "cdab8be3ff9fc770f6f4a2f9acc0f5b1adf5c6c0", "size": 9794, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "hyper2D_single_core/hyper2D_basic/AXISYMMETRIC/src/integration.f03", "max_stars_repo_name": "sbocce/hyper2D", "max_stars_repo_head_hexsha": "7d1510ac3947b2c154aa0c09945ff05db4bfc8c4", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2022-02-17T14:26:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T01:56:37.000Z", "max_issues_repo_path": "hyper2D_single_core/hyper2D_basic/AXISYMMETRIC/src/integration.f03", "max_issues_repo_name": "sbocce/hyper2D", "max_issues_repo_head_hexsha": "7d1510ac3947b2c154aa0c09945ff05db4bfc8c4", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2022-02-28T10:22:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-01T06:25:03.000Z", "max_forks_repo_path": "hyper2D_single_core/hyper2D_basic/AXISYMMETRIC/src/integration.f03", "max_forks_repo_name": "sbocce/hyper2D", "max_forks_repo_head_hexsha": "7d1510ac3947b2c154aa0c09945ff05db4bfc8c4", "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.4919614148, "max_line_length": 104, "alphanum_fraction": 0.6059832551, "num_tokens": 3189, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850093037732, "lm_q2_score": 0.7154239957834734, "lm_q1q2_score": 0.669840762548272}} {"text": "Module m_refsor\nInteger, Parameter :: kdp = selected_real_kind(15)\npublic :: refsor\nprivate :: kdp\nprivate :: R_refsor, I_refsor, D_refsor\nprivate :: R_inssor, I_inssor, D_inssor\nprivate :: R_subsor, I_subsor, D_subsor\ninterface refsor\n module procedure d_refsor, r_refsor, i_refsor\nend interface refsor\ncontains\n\nSubroutine D_refsor (XDONT)\n! Sorts XDONT into ascending order - Quicksort\n! __________________________________________________________\n! Quicksort chooses a \"pivot\" in the set, and explores the\n! array from both ends, looking for a value > pivot with the\n! increasing index, for a value <= pivot with the decreasing\n! index, and swapping them when it has found one of each.\n! The array is then subdivided in 2 ([3]) subsets:\n! { values <= pivot} {pivot} {values > pivot}\n! One then call recursively the program to sort each subset.\n! When the size of the subarray is small enough, one uses an\n! insertion sort that is faster for very small sets.\n! Michel Olagnon - Apr. 2000\n! __________________________________________________________\n! __________________________________________________________\n Real (kind=kdp), Dimension (:), Intent (InOut) :: XDONT\n! __________________________________________________________\n!\n!\n Call D_subsor (XDONT, 1, Size (XDONT))\n Call D_inssor (XDONT)\n Return\nEnd Subroutine D_refsor\nRecursive Subroutine D_subsor (XDONT, IDEB1, IFIN1)\n! Sorts XDONT from IDEB1 to IFIN1\n! __________________________________________________________\n Real(kind=kdp), dimension (:), Intent (InOut) :: XDONT\n Integer, Intent (In) :: IDEB1, IFIN1\n! __________________________________________________________\n Integer, Parameter :: NINS = 16 ! Max for insertion sort\n Integer :: ICRS, IDEB, IDCR, IFIN, IMIL\n Real(kind=kdp) :: XPIV, XWRK\n!\n IDEB = IDEB1\n IFIN = IFIN1\n!\n! If we don't have enough values to make it worth while, we leave\n! them unsorted, and the final insertion sort will take care of them\n!\n If ((IFIN - IDEB) > NINS) Then\n IMIL = (IDEB+IFIN) / 2\n!\n! One chooses a pivot, median of 1st, last, and middle values\n!\n If (XDONT(IMIL) < XDONT(IDEB)) Then\n XWRK = XDONT (IDEB)\n XDONT (IDEB) = XDONT (IMIL)\n XDONT (IMIL) = XWRK\n End If\n If (XDONT(IMIL) > XDONT(IFIN)) Then\n XWRK = XDONT (IFIN)\n XDONT (IFIN) = XDONT (IMIL)\n XDONT (IMIL) = XWRK\n If (XDONT(IMIL) < XDONT(IDEB)) Then\n XWRK = XDONT (IDEB)\n XDONT (IDEB) = XDONT (IMIL)\n XDONT (IMIL) = XWRK\n End If\n End If\n XPIV = XDONT (IMIL)\n!\n! One exchanges values to put those > pivot in the end and\n! those <= pivot at the beginning\n!\n ICRS = IDEB\n IDCR = IFIN\n ECH2: Do\n Do\n ICRS = ICRS + 1\n If (ICRS >= IDCR) Then\n!\n! the first > pivot is IDCR\n! the last <= pivot is ICRS-1\n! Note: If one arrives here on the first iteration, then\n! the pivot is the maximum of the set, the last value is equal\n! to it, and one can reduce by one the size of the set to process,\n! as if XDONT (IFIN) > XPIV\n!\n Exit ECH2\n!\n End If\n If (XDONT(ICRS) > XPIV) Exit\n End Do\n Do\n If (XDONT(IDCR) <= XPIV) Exit\n IDCR = IDCR - 1\n If (ICRS >= IDCR) Then\n!\n! The last value < pivot is always ICRS-1\n!\n Exit ECH2\n End If\n End Do\n!\n XWRK = XDONT (IDCR)\n XDONT (IDCR) = XDONT (ICRS)\n XDONT (ICRS) = XWRK\n End Do ECH2\n!\n! One now sorts each of the two sub-intervals\n!\n Call D_subsor (XDONT, IDEB1, ICRS-1)\n Call D_subsor (XDONT, IDCR, IFIN1)\n End If\n Return\n End Subroutine D_subsor\n Subroutine D_inssor (XDONT)\n! Sorts XDONT into increasing order (Insertion sort)\n! __________________________________________________________\n Real(kind=kdp), dimension (:), Intent (InOut) :: XDONT\n! __________________________________________________________\n Integer :: ICRS, IDCR\n Real(kind=kdp) :: XWRK\n!\n Do ICRS = 2, Size (XDONT)\n XWRK = XDONT (ICRS)\n If (XWRK >= XDONT(ICRS-1)) Cycle\n XDONT (ICRS) = XDONT (ICRS-1)\n Do IDCR = ICRS - 2, 1, - 1\n If (XWRK >= XDONT(IDCR)) Exit\n XDONT (IDCR+1) = XDONT (IDCR)\n End Do\n XDONT (IDCR+1) = XWRK\n End Do\n!\n Return\n!\nEnd Subroutine D_inssor\n!\nSubroutine R_refsor (XDONT)\n! Sorts XDONT into ascending order - Quicksort\n! __________________________________________________________\n! Quicksort chooses a \"pivot\" in the set, and explores the\n! array from both ends, looking for a value > pivot with the\n! increasing index, for a value <= pivot with the decreasing\n! index, and swapping them when it has found one of each.\n! The array is then subdivided in 2 ([3]) subsets:\n! { values <= pivot} {pivot} {values > pivot}\n! One then call recursively the program to sort each subset.\n! When the size of the subarray is small enough, one uses an\n! insertion sort that is faster for very small sets.\n! Michel Olagnon - Apr. 2000\n! __________________________________________________________\n! _________________________________________________________\n Real, Dimension (:), Intent (InOut) :: XDONT\n! __________________________________________________________\n!\n!\n Call R_subsor (XDONT, 1, Size (XDONT))\n Call R_inssor (XDONT)\n Return\nEnd Subroutine R_refsor\nRecursive Subroutine R_subsor (XDONT, IDEB1, IFIN1)\n! Sorts XDONT from IDEB1 to IFIN1\n! __________________________________________________________\n Real, dimension (:), Intent (InOut) :: XDONT\n Integer, Intent (In) :: IDEB1, IFIN1\n! __________________________________________________________\n Integer, Parameter :: NINS = 16 ! Max for insertion sort\n Integer :: ICRS, IDEB, IDCR, IFIN, IMIL\n Real :: XPIV, XWRK\n!\n IDEB = IDEB1\n IFIN = IFIN1\n!\n! If we don't have enough values to make it worth while, we leave\n! them unsorted, and the final insertion sort will take care of them\n!\n If ((IFIN - IDEB) > NINS) Then\n IMIL = (IDEB+IFIN) / 2\n!\n! One chooses a pivot, median of 1st, last, and middle values\n!\n If (XDONT(IMIL) < XDONT(IDEB)) Then\n XWRK = XDONT (IDEB)\n XDONT (IDEB) = XDONT (IMIL)\n XDONT (IMIL) = XWRK\n End If\n If (XDONT(IMIL) > XDONT(IFIN)) Then\n XWRK = XDONT (IFIN)\n XDONT (IFIN) = XDONT (IMIL)\n XDONT (IMIL) = XWRK\n If (XDONT(IMIL) < XDONT(IDEB)) Then\n XWRK = XDONT (IDEB)\n XDONT (IDEB) = XDONT (IMIL)\n XDONT (IMIL) = XWRK\n End If\n End If\n XPIV = XDONT (IMIL)\n!\n! One exchanges values to put those > pivot in the end and\n! those <= pivot at the beginning\n!\n ICRS = IDEB\n IDCR = IFIN\n ECH2: Do\n Do\n ICRS = ICRS + 1\n If (ICRS >= IDCR) Then\n!\n! the first > pivot is IDCR\n! the last <= pivot is ICRS-1\n! Note: If one arrives here on the first iteration, then\n! the pivot is the maximum of the set, the last value is equal\n! to it, and one can reduce by one the size of the set to process,\n! as if XDONT (IFIN) > XPIV\n!\n Exit ECH2\n!\n End If\n If (XDONT(ICRS) > XPIV) Exit\n End Do\n Do\n If (XDONT(IDCR) <= XPIV) Exit\n IDCR = IDCR - 1\n If (ICRS >= IDCR) Then\n!\n! The last value < pivot is always ICRS-1\n!\n Exit ECH2\n End If\n End Do\n!\n XWRK = XDONT (IDCR)\n XDONT (IDCR) = XDONT (ICRS)\n XDONT (ICRS) = XWRK\n End Do ECH2\n!\n! One now sorts each of the two sub-intervals\n!\n Call R_subsor (XDONT, IDEB1, ICRS-1)\n Call R_subsor (XDONT, IDCR, IFIN1)\n End If\n Return\n End Subroutine R_subsor\n Subroutine R_inssor (XDONT)\n! Sorts XDONT into increasing order (Insertion sort)\n! __________________________________________________________\n Real, dimension (:), Intent (InOut) :: XDONT\n! __________________________________________________________\n Integer :: ICRS, IDCR\n Real :: XWRK\n!\n Do ICRS = 2, Size (XDONT)\n XWRK = XDONT (ICRS)\n If (XWRK >= XDONT(ICRS-1)) Cycle\n XDONT (ICRS) = XDONT (ICRS-1)\n Do IDCR = ICRS - 2, 1, - 1\n If (XWRK >= XDONT(IDCR)) Exit\n XDONT (IDCR+1) = XDONT (IDCR)\n End Do\n XDONT (IDCR+1) = XWRK\n End Do\n!\n Return\n!\nEnd Subroutine R_inssor\n!\nSubroutine I_refsor (XDONT)\n! Sorts XDONT into ascending order - Quicksort\n! __________________________________________________________\n! Quicksort chooses a \"pivot\" in the set, and explores the\n! array from both ends, looking for a value > pivot with the\n! increasing index, for a value <= pivot with the decreasing\n! index, and swapping them when it has found one of each.\n! The array is then subdivided in 2 ([3]) subsets:\n! { values <= pivot} {pivot} {values > pivot}\n! One then call recursively the program to sort each subset.\n! When the size of the subarray is small enough, one uses an\n! insertion sort that is faster for very small sets.\n! Michel Olagnon - Apr. 2000\n! __________________________________________________________\n! __________________________________________________________\n Integer, Dimension (:), Intent (InOut) :: XDONT\n! __________________________________________________________\n!\n!\n Call I_subsor (XDONT, 1, Size (XDONT))\n Call I_inssor (XDONT)\n Return\nEnd Subroutine I_refsor\nRecursive Subroutine I_subsor (XDONT, IDEB1, IFIN1)\n! Sorts XDONT from IDEB1 to IFIN1\n! __________________________________________________________\n Integer, dimension (:), Intent (InOut) :: XDONT\n Integer, Intent (In) :: IDEB1, IFIN1\n! __________________________________________________________\n Integer, Parameter :: NINS = 16 ! Max for insertion sort\n Integer :: ICRS, IDEB, IDCR, IFIN, IMIL\n Integer :: XPIV, XWRK\n!\n IDEB = IDEB1\n IFIN = IFIN1\n!\n! If we don't have enough values to make it worth while, we leave\n! them unsorted, and the final insertion sort will take care of them\n!\n If ((IFIN - IDEB) > NINS) Then\n IMIL = (IDEB+IFIN) / 2\n!\n! One chooses a pivot, median of 1st, last, and middle values\n!\n If (XDONT(IMIL) < XDONT(IDEB)) Then\n XWRK = XDONT (IDEB)\n XDONT (IDEB) = XDONT (IMIL)\n XDONT (IMIL) = XWRK\n End If\n If (XDONT(IMIL) > XDONT(IFIN)) Then\n XWRK = XDONT (IFIN)\n XDONT (IFIN) = XDONT (IMIL)\n XDONT (IMIL) = XWRK\n If (XDONT(IMIL) < XDONT(IDEB)) Then\n XWRK = XDONT (IDEB)\n XDONT (IDEB) = XDONT (IMIL)\n XDONT (IMIL) = XWRK\n End If\n End If\n XPIV = XDONT (IMIL)\n!\n! One exchanges values to put those > pivot in the end and\n! those <= pivot at the beginning\n!\n ICRS = IDEB\n IDCR = IFIN\n ECH2: Do\n Do\n ICRS = ICRS + 1\n If (ICRS >= IDCR) Then\n!\n! the first > pivot is IDCR\n! the last <= pivot is ICRS-1\n! Note: If one arrives here on the first iteration, then\n! the pivot is the maximum of the set, the last value is equal\n! to it, and one can reduce by one the size of the set to process,\n! as if XDONT (IFIN) > XPIV\n!\n Exit ECH2\n!\n End If\n If (XDONT(ICRS) > XPIV) Exit\n End Do\n Do\n If (XDONT(IDCR) <= XPIV) Exit\n IDCR = IDCR - 1\n If (ICRS >= IDCR) Then\n!\n! The last value < pivot is always ICRS-1\n!\n Exit ECH2\n End If\n End Do\n!\n XWRK = XDONT (IDCR)\n XDONT (IDCR) = XDONT (ICRS)\n XDONT (ICRS) = XWRK\n End Do ECH2\n!\n! One now sorts each of the two sub-intervals\n!\n Call I_subsor (XDONT, IDEB1, ICRS-1)\n Call I_subsor (XDONT, IDCR, IFIN1)\n End If\n Return\n End Subroutine I_subsor\n Subroutine I_inssor (XDONT)\n! Sorts XDONT into increasing order (Insertion sort)\n! __________________________________________________________\n Integer, dimension (:), Intent (InOut) :: XDONT\n! __________________________________________________________\n Integer :: ICRS, IDCR\n Integer :: XWRK\n!\n Do ICRS = 2, Size (XDONT)\n XWRK = XDONT (ICRS)\n If (XWRK >= XDONT(ICRS-1)) Cycle\n XDONT (ICRS) = XDONT (ICRS-1)\n Do IDCR = ICRS - 2, 1, - 1\n If (XWRK >= XDONT(IDCR)) Exit\n XDONT (IDCR+1) = XDONT (IDCR)\n End Do\n XDONT (IDCR+1) = XWRK\n End Do\n!\n Return\n!\nEnd Subroutine I_inssor\n!\nend module m_refsor\n", "meta": {"hexsha": "1e265a72aee497f9c975b497f4040aece0ac270f", "size": 13088, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/f2000/refsor.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/f2000/refsor.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/f2000/refsor.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": 32.63840399, "max_line_length": 73, "alphanum_fraction": 0.6082671149, "num_tokens": 3839, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388125473629, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.6698382822081391}} {"text": "\n!========================================================================\n!\n! T o m o f a s t - x\n! -----------------------\n!\n! Authors: Vitaliy Ogarko, Jeremie Giraud, Roland Martin.\n!\n! (c) 2021 The University of Western Australia.\n!\n! The full text of the license is available in file \"LICENSE\".\n!\n!========================================================================\n\n!================================================================================================\n! Functions to generate noise.\n!\n! Vitaliy Ogarko, UWA, CET, Australia, 2015-2016.\n!================================================================================================\nmodule noise\n\n use global_typedefs\n\n implicit none\n\n private\n\n public :: init_random_seed\n public :: generate_Gaussian_noise\n public :: generate_uniform_noise\n\ncontains\n\n!==================================================================================\n! Initializes a random seed from the system clock at every run (fortran 95 code).\n! http://stackoverflow.com/questions/18754438/generating-random-numbers-in-a-fortran-module\n!==================================================================================\nsubroutine init_random_seed()\n integer :: i, n, clock\n integer, allocatable :: seed(:)\n\n call RANDOM_SEED(size = n)\n allocate(seed(n))\n\n call SYSTEM_CLOCK(COUNT=clock)\n\n seed = clock + 37 * (/ (i - 1, i = 1, n) /)\n call RANDOM_SEED(PUT = seed)\n\n deallocate(seed)\n\nend subroutine init_random_seed\n\n!============================================================================\n! Generates Gaussian noise.\n!============================================================================\nfunction generate_Gaussian_noise(sigma, mu) result(noise)\n double precision, intent(in) :: sigma, mu\n\n double precision :: rand1, rand2\n double precision :: gaussian1, gaussian2\n double precision :: noise\n\n call random_number(rand1)\n call random_number(rand2)\n\n ! Uncorrelated Gaussian (normal) random numbers (by Box & Muller method).\n gaussian1 = sqrt(- 2.d0 * log(rand1)) * cos(2.d0 * PI * rand2)\n gaussian2 = sqrt(- 2.d0 * log(rand1)) * sin(2.d0 * PI * rand2)\n\n noise = gaussian1 * sigma + mu\n\nend function generate_Gaussian_noise\n\n!============================================================================\n! Generates uniform noise.\n!============================================================================\nfunction generate_uniform_noise(scale) result(noise)\n double precision, intent(in) :: scale\n\n double precision :: rand\n double precision :: noise\n\n call random_number(rand)\n\n noise = (rand - 0.5d0) * scale\n\nend function generate_uniform_noise\n\nend module noise\n", "meta": {"hexsha": "f9fd823ff0447944952b1b0886ad0602004170d1", "size": 2730, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/utils/noise.f90", "max_stars_repo_name": "RichardScottOZ/Tomofast-x", "max_stars_repo_head_hexsha": "af2d0b8ad59cdc18d9c348bec274ca4371ae94c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2021-07-22T02:49:27.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T07:11:30.000Z", "max_issues_repo_path": "src/utils/noise.f90", "max_issues_repo_name": "RichardScottOZ/Tomofast-x", "max_issues_repo_head_hexsha": "af2d0b8ad59cdc18d9c348bec274ca4371ae94c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-11-08T01:04:44.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-22T21:40:37.000Z", "max_forks_repo_path": "src/utils/noise.f90", "max_forks_repo_name": "RichardScottOZ/Tomofast-x", "max_forks_repo_head_hexsha": "af2d0b8ad59cdc18d9c348bec274ca4371ae94c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2021-08-20T06:14:27.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-02T04:59:32.000Z", "avg_line_length": 30.0, "max_line_length": 97, "alphanum_fraction": 0.4765567766, "num_tokens": 533, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289387998695209, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.6698382700478389}} {"text": "PROGRAM shell_model\nIMPLICIT NONE\n REAL,ALLOCATABLE,DIMENSION(:,:)::E\n INTEGER::i,j,N,l,k \n REAL::C,D\n C=0.05\n D=0.0225\n!To input the value of Quantum Number N\n PRINT*,\"Enter the value of N:\"\n READ*,N\n ALLOCATE(E(0:N,0:N+1))\n DO i=0,N\n E(i,0)=i+1.5 !contains energy values of SHO\n j=1\n DO l=i,0,-2\n IF(l.NE.0) THEN\n!For Energy level splitting with j=l+1/2 and j=l-1/2 respectively\n E(i,j)=(i+1.5)-(C*l)-(D*l*(l+1))\n j=j+1\n E(i,j)=(i+1.5)+(C*(l+1))-(D*l*(l+1))\n j=j+1\n END IF\n IF(l.EQ.0) THEN\n!For no splitting in energy levels\n E(i,j)=i+1.5\n END IF\n END DO\n PRINT*,(E(i,j),j=0,i+1)\n END DO\n PRINT*,\"HEY\"\n\n OPEN(10,FILE=\"single_particle_Shell_model.dat\")\n DO i=0,N\n DO j=1,i+1\n DO k=0,3\n WRITE(10,*) k,E(i,0)\n END DO\n DO k=4,7\n WRITE(10,*) k,E(i,j)\n END DO\n WRITE(10,*)\n END DO\n END DO\n CLOSE(10)\n PRINT*,\"HEY\"\nEND PROGRAM shell_model\n", "meta": {"hexsha": "fd5cc8737ac12065b61ea9f9fe56092884a71566", "size": 966, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "exercises/shell_model/single_particle_shell_model.f90", "max_stars_repo_name": "deadbeatfour/phn624-comp-nuc-phy", "max_stars_repo_head_hexsha": "deaeaac5240a1f33425c4ca50539aee4fae2f370", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "exercises/shell_model/single_particle_shell_model.f90", "max_issues_repo_name": "deadbeatfour/phn624-comp-nuc-phy", "max_issues_repo_head_hexsha": "deaeaac5240a1f33425c4ca50539aee4fae2f370", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "exercises/shell_model/single_particle_shell_model.f90", "max_forks_repo_name": "deadbeatfour/phn624-comp-nuc-phy", "max_forks_repo_head_hexsha": "deaeaac5240a1f33425c4ca50539aee4fae2f370", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.5531914894, "max_line_length": 65, "alphanum_fraction": 0.5372670807, "num_tokens": 394, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361652391385, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.6698372059519737}} {"text": "C LAST UPDATE 30/03/94\nC+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\nC\n SUBROUTINE FLORENTZ(X,A,Y,DYDA)\n IMPLICIT NONE\nC\nC Purpose: Y(X;A) is Lorentzian. The amplitude. centre and width of the\nC Lorentzian are stored in consecutive locations of A: \nC A(1) = H, A(2) = P, A(3) = FWHM\nC\nC-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-\nC Parameters:\nC\n DOUBLE PRECISION TINY\n PARAMETER(TINY=1.0D-10)\nC\nC Arguments:\nC\n DOUBLE PRECISION A(10),DYDA(10)\n DOUBLE PRECISION X,Y \nC\nC Local variables:\nC\n DOUBLE PRECISION ARG,EX,FAC,W\nC\nC-----------------------------------------------------------------------\n IF(A(3).LT.TINY)A(3) = TINY\n W = A(3)/2.0D0\n ARG = (X-A(2))/W\n FAC = (1.0D0+ARG*ARG)\n Y = A(1)/FAC\n EX = 2.0D0*ARG*A(1)/(FAC*FAC)\n DYDA(1) = 1.0D0/FAC\n DYDA(2) = EX/W\n DYDA(3) = 2.0D0*ARG*EX/W\nC\n RETURN\n END\n\n\n", "meta": {"hexsha": "41a4f369513b37cbb8fa671b2552fc258d7da411", "size": 980, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "software/guifix/FLORENTZ.f", "max_stars_repo_name": "scattering-central/CCP13", "max_stars_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "software/guifix/FLORENTZ.f", "max_issues_repo_name": "scattering-central/CCP13", "max_issues_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "software/guifix/FLORENTZ.f", "max_forks_repo_name": "scattering-central/CCP13", "max_forks_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-09-05T15:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-15T11:13:45.000Z", "avg_line_length": 23.9024390244, "max_line_length": 72, "alphanum_fraction": 0.4357142857, "num_tokens": 335, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147439, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6698371936522364}} {"text": " PROGRAM xbcucof\r\nC driver for routine bcucof\r\n INTEGER i,j\r\n REAL d1,d2,ee,x1x2\r\n REAL c(4,4),y(4),y1(4),y2(4)\r\n REAL y12(4),x1(4),x2(4)\r\n DATA x1/0.0,2.0,2.0,0.0/\r\n DATA x2/0.0,0.0,2.0,2.0/\r\n d1=x1(2)-x1(1)\r\n d2=x2(4)-x2(1)\r\n do 11 i=1,4\r\n x1x2=x1(i)*x2(i)\r\n ee=exp(-x1x2)\r\n y(i)=x1x2*ee\r\n y1(i)=x2(i)*(1.0-x1x2)*ee\r\n y2(i)=x1(i)*(1.0-x1x2)*ee\r\n y12(i)=(1.0-3.0*x1x2+x1x2**2)*ee\r\n11 continue\r\n call bcucof(y,y1,y2,y12,d1,d2,c)\r\n write(*,*) 'Coefficients for bicubic interpolation'\r\n do 12 i=1,4\r\n write(*,'(1x,4e15.6)') (c(i,j),j=1,4)\r\n12 continue\r\n END\r\n", "meta": {"hexsha": "cf65353a6e9c08b3171d901f9a59a99e63ecb76c", "size": 686, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xbcucof.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xbcucof.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xbcucof.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.44, "max_line_length": 58, "alphanum_fraction": 0.4737609329, "num_tokens": 326, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813454, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6698054704532975}} {"text": "!---------------------------------------------------------------------!\n! PHAML !\n! !\n! The Parallel Hierarchical Adaptive MultiLevel code for solving !\n! linear elliptic partial differential equations of the form !\n! (PUx)x + (QUy)y + RU = F on 2D polygonal domains with mixed !\n! boundary conditions, and eigenvalue problems where F is lambda*U. !\n! !\n! PHAML is public domain software. It was produced as part of work !\n! done by the U.S. Government, and is not subject to copyright in !\n! the United States. !\n! !\n! William F. Mitchell !\n! Applied and Computational Mathematics Division !\n! National Institute of Standards and Technology !\n! william.mitchell@nist.gov !\n! http://math.nist.gov/phaml !\n! !\n!---------------------------------------------------------------------!\n\n!----------------------------------------------------\n! This file contains the main program supplied by the user.\n! This version illustrates an eigenvalue problem, the Schroedinger\n! Equation for a simple harmonic oscillator.\n!----------------------------------------------------\n\n! ------------\nprogram phaml_master\n! ------------\n\n!----------------------------------------------------\n! This is the main program.\n!----------------------------------------------------\n\n!----------------------------------------------------\n! Modules used are:\n\nuse phaml\n!----------------------------------------------------\n\nimplicit none\n\n!----------------------------------------------------\n! Local variables:\n\ninteger :: nvert,num_eval,nproc\nreal(my_real) :: lambda0\ntype(phaml_solution_type) :: pde1\nreal(my_real) :: evals(3), mlsresid, alsresid, el2resid(3), errest, &\n eval_errest(3)\ninteger :: aiter, anconv, anumop, anumopb, anumreo, ainfo\n\n!----------------------------------------------------\n! Begin executable code\n\nnvert = 1000\nlambda0 = -huge(0.0_my_real)\nnum_eval = 3\nnproc=4\ncall phaml_create(pde1,nproc,eq_type=EIGENVALUE)\ncall phaml_solve_pde(pde1, &\n max_vert=nvert, &\n sequential_vert=250, &\n num_eval=num_eval, &\n lambda0=lambda0, &\n print_error_when=FINAL, &\n print_error_who=MASTER, &\n print_errest_what=LINF_ERREST, &\n mg_tol=MG_NO_TOL, &\n mg_cycles=10)\ncall phaml_query(pde1, &\n eigenvalues=evals, &\n eigenvalue_error_estimate=eval_errest, &\n error_estimator=LOCAL_PROBLEM_H, &\n max_linsys_resid=mlsresid, &\n ave_linsys_resid=alsresid, &\n eigen_l2_resid=el2resid, &\n arpack_iter=aiter, &\n arpack_nconv=anconv, &\n arpack_numop=anumop, &\n arpack_numopb=anumopb, &\n arpack_numreo=anumreo, &\n arpack_info=ainfo)\ncall phaml_query(pde1,linf_error_estimate=errest,eigen=2)\nwrite(6,102) \"eigenvalues \",evals\nwrite(6,102) \"error estimates \",eval_errest\nwrite(6,101) \"max linear system residual \",mlsresid\nwrite(6,101) \"ave linear system residual \",alsresid\nwrite(6,102) \"eigensystem residuals \",el2resid\nwrite(6,103) \"arpack iterations \",aiter\nwrite(6,103) \"arpack number converged \",anconv\nwrite(6,103) \"arpack number of OP*x \",anumop\nwrite(6,103) \"arpack number of B*x \",anumopb\nwrite(6,103) \"arpack number of reorthogonalizatons \",anumreo\nwrite(6,103) \"arpack error flag \",ainfo\nwrite(6,101) \"error estimate for evec 2 \",errest\n101 format(A,SS,1P,E19.12E2)\n102 format(A,SS,1P,3E19.12E2)\n103 format(A,I11)\ncall phaml_destroy(pde1)\n\nend program phaml_master\n", "meta": {"hexsha": "5c1adc6779a6102e73ee40ad6bbd4803b391724c", "size": 4307, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "testdir/test_arpack/test09.f90", "max_stars_repo_name": "qsnake/phaml", "max_stars_repo_head_hexsha": "8925b4c32657bbd9f81cd5f8f9d6739151c66fec", "max_stars_repo_licenses": ["mpich2"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-09-07T15:46:34.000Z", "max_stars_repo_stars_event_max_datetime": "2018-09-07T15:46:34.000Z", "max_issues_repo_path": "testdir/test_arpack/test09.f90", "max_issues_repo_name": "qsnake/phaml", "max_issues_repo_head_hexsha": "8925b4c32657bbd9f81cd5f8f9d6739151c66fec", "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": "testdir/test_arpack/test09.f90", "max_forks_repo_name": "qsnake/phaml", "max_forks_repo_head_hexsha": "8925b4c32657bbd9f81cd5f8f9d6739151c66fec", "max_forks_repo_licenses": ["mpich2"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.8155339806, "max_line_length": 71, "alphanum_fraction": 0.4631994428, "num_tokens": 926, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813453, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6698054704532974}} {"text": "SUBROUTINE gser(gamser,a,x,gln)\r\nINTEGER*4 ITMAX\r\nREAL*8 a,gamser,gln,x,EPS\r\nPARAMETER (ITMAX=100,EPS=3.d-7)\r\n!CU USES gammln\r\nINTEGER*4 n\r\nREAL*8 ap,del,sum,gammln\r\nEXTERNAL gammln\r\ngln=gammln(a)\r\nif(x.le.0.)then\r\n\tif(x.lt.0.)pause 'x < 0 in gser'\r\n\tgamser=0.\r\n\treturn\r\nendif\r\nap=a\r\nsum=1./a\r\ndel=sum\r\ndo n=1,ITMAX\r\n\tap=ap+1.\r\n\tdel=del*x/ap\r\n\tsum=sum+del\r\n\tif(abs(del).lt.abs(sum)*EPS)goto 1\r\nend do\r\npause 'a too large, ITMAX too small in gser'\r\n1 gamser=sum*exp(-x+a*log(x)-gln)\r\nreturn\r\nEND\r\n", "meta": {"hexsha": "2c424fdb81df007e2a50a4c833d54415ff0e5e03", "size": 503, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "11/mathlib/gser.f90", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "11/mathlib/gser.f90", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "11/mathlib/gser.f90", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.9642857143, "max_line_length": 45, "alphanum_fraction": 0.6560636183, "num_tokens": 208, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813454, "lm_q2_score": 0.7461389930307512, "lm_q1q2_score": 0.6698054653857856}} {"text": "\n SUBROUTINE INIFFT\n\nC Initialize FFTs\n\n include \"atparam.h\"\n\n COMMON /FFTCOM/ COEFFT(IX+15)\n\n CALL DZFFTM1DUI (IX,COEFFT)\n\n RETURN\n END\n\n*********************************************************************\n\n SUBROUTINE GRIDX(VARM,VORG,KCOS)\n\nC From Fourier coefficients to grid-point data\n\n include \"atparam.h\"\n\n PARAMETER (IMAX=IX+2 )\n\n include \"com_spectral.h\"\n\n COMMON /FFTCOM/ COEFFT(IX+15)\n\n REAL VORG(IX,IL), VARM(MX2,IL)\n REAL FVAR(IMAX,IL)\n\nC Copy Fourier coefficients into working array\n\n MX3=MX2+1\n DO J=1,IL\n DO I=1,MX2\n FVAR(I,J)=VARM(I,J)\n ENDDO\n DO I=MX3,IMAX\n FVAR(I,J)=0.\n ENDDO\n ENDDO\n\nC Inverse FFT\n\n CALL ZDFFTM1DU (+1,IX,IL,FVAR,1,IMAX,COEFFT)\n\nC Copy output into grid-point field, scaling by cos(lat) if needed\n\n IF (KCOS.EQ.1) THEN\n\n DO J=1,IL\n DO I=1,IX\n VORG(I,J)=FVAR(I,J)\n ENDDO\n ENDDO\n\n ELSE\n\n DO J=1,IL\n DO I=1,IX\n VORG(I,J)=FVAR(I,J)*COSGR(J)\n ENDDO\n ENDDO\n\n ENDIF\n\n RETURN\n END\n\n******************************************************************\n\n SUBROUTINE SPECX(VORG,VARM)\n\nC From grid-point data to Fourier coefficients\n\n include \"atparam.h\"\n\n PARAMETER (IMAX=IX+2 )\n\n COMMON /FFTCOM/ COEFFT(IX+15)\n\n REAL VORG(IX,IL), VARM(MX2,IL)\n REAL FVAR(IMAX,IL)\n\nC Copy grid-point data into working array\n\n IM1=IX+1\n DO J=1,IL\n DO I=1,IX\n FVAR(I,J)=VORG(I,J)\n ENDDO\n FVAR(IM1 ,J)=0.\n FVAR(IMAX,J)=0.\n ENDDO\n\nC Direct FFT\n\n CALL DZFFTM1DU (-1,IX,IL,FVAR,1,IMAX,COEFFT)\n\nC Copy output into spectral field, dividing by no. of long.\n\n SCALE=1./FLOAT(IX)\n\n DO J=1,IL \n DO M=1,MX2\n VARM(M,J)=FVAR(M,J)*SCALE\n ENDDO\n ENDDO\n\n RETURN\n END\n", "meta": {"hexsha": "351ca32804f54f3bcc70920d14f43b3c6b693357", "size": 1969, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "models/speedy/t21/spe_subfft_sgi.f", "max_stars_repo_name": "enino84/AMLCS", "max_stars_repo_head_hexsha": "7a37cca01c9305afb99b652baeb9e0952ebe889b", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "models/speedy/t21/spe_subfft_sgi.f", "max_issues_repo_name": "enino84/AMLCS", "max_issues_repo_head_hexsha": "7a37cca01c9305afb99b652baeb9e0952ebe889b", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "models/speedy/t21/spe_subfft_sgi.f", "max_forks_repo_name": "enino84/AMLCS", "max_forks_repo_head_hexsha": "7a37cca01c9305afb99b652baeb9e0952ebe889b", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.4247787611, "max_line_length": 70, "alphanum_fraction": 0.4936515998, "num_tokens": 641, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695283896349, "lm_q2_score": 0.7461390043208003, "lm_q1q2_score": 0.6698054653098999}} {"text": "module mBoard\n implicit none\n\n contains\n\n function createBoard(rows, cols)\n\n logical, dimension(:,:), allocatable :: createBoard\n integer, intent(in) :: rows, cols\n integer :: r,c\n\n allocate( createBoard(rows, cols) )\n\n do c = 1,cols\n do r = 1,rows\n createBoard(r,c) = (nint(rand(0)) .eq. 0)\n end do\n end do\n\n end function createBoard\n\n function stepBoard(board)\n ! stepBoard - Determines the next sequence in the board\n !\n ! Inputs:\n ! board - 2D array of logicals that represents the state of the game.\n\n logical, dimension(:,:), intent(inout), allocatable :: board\n logical, dimension(:,:), allocatable :: stepBoard\n integer :: i, j, livingNeighbors, x, y, rows, cols, a, b\n\n rows = ubound(board,1)\n cols = ubound(board,2)\n\n allocate(stepBoard(rows,cols))\n\n ! Iterate through board to determine next state\n do i=1,rows\n do j = 1,cols\n ! Determine how many neighbors a cell has\n livingNeighbors = 0\n\n do x = -1,1\n do y = -1, 1\n if ((x .eq. 0) .and. (y .eq. 0)) then\n continue\n else\n ! mod can wrap around on the high side\n ! need to figure out how to wrap around on the low side\n if (i+x .eq. 0) then\n a = rows\n else\n a = mod(i+x,rows)\n end if\n\n if (j+y .eq. 0) then\n b = cols\n else\n b = mod(j+y,cols)\n end if\n\n if (board(a,b)) then\n livingNeighbors = livingNeighbors + 1\n end if\n !if (board(mod(i+x, rows), mod(j+y, cols))) then\n ! livingNeighbors = livingNeighbors + 1\n !end if\n end if\n end do\n end do\n\n !write(*,*) livingNeighbors\n\n ! Determine which cells 'live' or 'die' based on the rules\n if (board(i,j) .and. livingNeighbors < 2) then\n stepBoard(i,j) = .false.\n else if (board(i,j) .and. livingNeighbors < 4) then\n stepBoard(i,j) = .true.\n else if (board(i,j)) then\n stepBoard(i,j) = .false.\n else if ((.not. board(i,j)) .and. (livingNeighbors .eq. 3)) then\n stepBoard(i,j) = .true.\n else\n stepBoard(i,j) = .false.\n end if\n end do\n end do\n\n\n ! clean up input board before returning\n deallocate(board)\n\n end function stepBoard\n\n subroutine printBoard(board)\n ! printBoard - Clears terminal screen and then prints board\n !\n ! Inputs:\n ! board - 2D array of logicals that represents state of game.\n\n logical, dimension(:,:), intent(in) :: board\n integer :: i, j\n\n ! Clear Screen\n !call system('clear')\n write(*,\"(A)\") \"===========================\"\n\n ! Print Board\n do i = lbound(board,1), ubound(board,1)\n do j = lbound(board,2), ubound(board,2)\n if (board(i,j)) then\n write(*,\"(A)\", advance=\"no\") '*' ! Life Cell is *\n else\n write(*,\"(A)\", advance=\"no\") ' ' ! Dead cell is blank\n end if\n end do\n write(*,*) '' ! Line feed after current row\n end do\n\n end subroutine printBoard\nend module\n\nprogram life\n!\n! Purpose:\n! Implementation of Conway's Game of Life in Fortran 90.\n!\n! Record of revisions:\n! Date Programer Description of change\n! ==== ========= =====================\n! 2019-11-27 cchillen Original Code\nuse mBoard\nuse, intrinsic :: iso_c_binding, only: c_int\n\nimplicit none\n\ninteger :: rows, cols ! Board size\ninteger :: i\nlogical, dimension (:, :), allocatable :: board ! Actual Board\n\n\n! Basic Algorithm:\n! 1. Prompt user to input board size\n! 2. Initialize Board\n! 3. Display Board\n! 4. Step Board\n! 5. Loop at step 3 or quit\n\n! Functions: createBoard(), stepBoard(), printBoard()\nrows = 45\ncols = 80\n\nboard = createBoard(rows, cols)\n\n!call printBoard(board)\n\ndo i = 1,1000\n call printBoard(board)\n\n board = stepBoard(board)\n\n call sleep(1)\n\nend do\n\nend program life\n", "meta": {"hexsha": "5f4254241949b39533ecd9a01186d30e13772030", "size": 4766, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "life.f90", "max_stars_repo_name": "cchillen/life", "max_stars_repo_head_hexsha": "2bc8536ded79fdfc71c1e794b7fcccc2183c4ebb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "life.f90", "max_issues_repo_name": "cchillen/life", "max_issues_repo_head_hexsha": "2bc8536ded79fdfc71c1e794b7fcccc2183c4ebb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "life.f90", "max_forks_repo_name": "cchillen/life", "max_forks_repo_head_hexsha": "2bc8536ded79fdfc71c1e794b7fcccc2183c4ebb", "max_forks_repo_licenses": ["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.5389221557, "max_line_length": 83, "alphanum_fraction": 0.4689467058, "num_tokens": 1109, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256393148981, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.6698053908012535}} {"text": " Program zhpevd_example\n\n! ZHPEVD Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use blas_interfaces, Only: dznrm2\n Use lapack_example_aux, Only: nagf_file_print_matrix_complex_gen\n Use lapack_interfaces, Only: zhpevd\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nin = 5, nout = 6\n! .. Local Scalars ..\n Complex (Kind=dp) :: scal\n Integer :: i, ifail, info, j, k, ldz, liwork, lrwork, lwork, n\n Character (1) :: job, uplo\n! .. Local Arrays ..\n Complex (Kind=dp), Allocatable :: ap(:), work(:), z(:, :)\n Real (Kind=dp), Allocatable :: rwork(:), w(:)\n Integer, Allocatable :: iwork(:)\n! .. Intrinsic Procedures ..\n Intrinsic :: abs, conjg, maxloc\n! .. Executable Statements ..\n Write (nout, *) 'ZHPEVD Example Program Results'\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n\n ldz = n\n liwork = 5*n + 3\n lrwork = 2*n*n + 5*n + 1\n lwork = 2*n\n Allocate (ap(n*(n+1)/2), work(lwork), z(ldz,n), rwork(lrwork), w(n), &\n iwork(liwork))\n Read (nin, *) uplo\n\n! Read A from data file\n\n If (uplo=='U') Then\n Read (nin, *)((ap(i+j*(j-1)/2),j=i,n), i=1, n)\n Else If (uplo=='L') Then\n Read (nin, *)((ap(i+(2*n-j)*(j-1)/2),j=1,i), i=1, n)\n End If\n\n Read (nin, *) job\n\n! Calculate all the eigenvalues and eigenvectors of A\n\n Call zhpevd(job, uplo, n, ap, w, z, ldz, work, lwork, rwork, lrwork, &\n iwork, liwork, info)\n\n Write (nout, *)\n If (info>0) Then\n Write (nout, *) 'Failure to converge.'\n Else\n\n! Print eigenvalues and eigenvectors\n\n Write (nout, *) 'Eigenvalues'\n Do i = 1, n\n Write (nout, 100) i, w(i)\n End Do\n Write (nout, *)\n Flush (nout)\n\n! Normalize the eigenvectors, largest element real\n Do i = 1, n\n rwork(1:n) = abs(z(1:n,i))\n k = maxloc(rwork(1:n), 1)\n scal = conjg(z(k,i))/abs(z(k,i))/dznrm2(n, z(1,i), 1)\n z(1:n, i) = z(1:n, i)*scal\n End Do\n\n! ifail: behaviour on error exit\n! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft\n ifail = 0\n Call nagf_file_print_matrix_complex_gen('General', ' ', n, n, z, ldz, &\n 'Eigenvectors', ifail)\n\n End If\n\n100 Format (3X, I5, 5X, 2F8.4)\n End Program\n", "meta": {"hexsha": "b91cbc37c291b080a74efcfe4109e0e1bbfadf6d", "size": 2651, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/zhpevd_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/zhpevd_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/zhpevd_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 30.125, "max_line_length": 90, "alphanum_fraction": 0.5450773293, "num_tokens": 860, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772417253256, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6697998385653774}} {"text": "*DECK CHFEV\n SUBROUTINE CHFEV (X1, X2, F1, F2, D1, D2, NE, XE, FE, NEXT, IERR)\nC***BEGIN PROLOGUE CHFEV\nC***PURPOSE Evaluate a cubic polynomial given in Hermite form at an\nC array of points. While designed for use by PCHFE, it may\nC be useful directly as an evaluator for a piecewise cubic\nC Hermite function in applications, such as graphing, where\nC the interval is known in advance.\nC***LIBRARY SLATEC (PCHIP)\nC***CATEGORY E3\nC***TYPE SINGLE PRECISION (CHFEV-S, DCHFEV-D)\nC***KEYWORDS CUBIC HERMITE EVALUATION, CUBIC POLYNOMIAL EVALUATION,\nC PCHIP\nC***AUTHOR Fritsch, F. N., (LLNL)\nC Lawrence Livermore National Laboratory\nC P.O. Box 808 (L-316)\nC Livermore, CA 94550\nC FTS 532-4275, (510) 422-4275\nC***DESCRIPTION\nC\nC CHFEV: Cubic Hermite Function EValuator\nC\nC Evaluates the cubic polynomial determined by function values\nC F1,F2 and derivatives D1,D2 on interval (X1,X2) at the points\nC XE(J), J=1(1)NE.\nC\nC ----------------------------------------------------------------------\nC\nC Calling sequence:\nC\nC INTEGER NE, NEXT(2), IERR\nC REAL X1, X2, F1, F2, D1, D2, XE(NE), FE(NE)\nC\nC CALL CHFEV (X1,X2, F1,F2, D1,D2, NE, XE, FE, NEXT, IERR)\nC\nC Parameters:\nC\nC X1,X2 -- (input) endpoints of interval of definition of cubic.\nC (Error return if X1.EQ.X2 .)\nC\nC F1,F2 -- (input) values of function at X1 and X2, respectively.\nC\nC D1,D2 -- (input) values of derivative at X1 and X2, respectively.\nC\nC NE -- (input) number of evaluation points. (Error return if\nC NE.LT.1 .)\nC\nC XE -- (input) real array of points at which the function is to be\nC evaluated. If any of the XE are outside the interval\nC [X1,X2], a warning error is returned in NEXT.\nC\nC FE -- (output) real array of values of the cubic function defined\nC by X1,X2, F1,F2, D1,D2 at the points XE.\nC\nC NEXT -- (output) integer array indicating number of extrapolation\nC points:\nC NEXT(1) = number of evaluation points to left of interval.\nC NEXT(2) = number of evaluation points to right of interval.\nC\nC IERR -- (output) error flag.\nC Normal return:\nC IERR = 0 (no errors).\nC \"Recoverable\" errors:\nC IERR = -1 if NE.LT.1 .\nC IERR = -2 if X1.EQ.X2 .\nC (The FE-array has not been changed in either case.)\nC\nC***REFERENCES (NONE)\nC***ROUTINES CALLED XERMSG\nC***REVISION HISTORY (YYMMDD)\nC 811019 DATE WRITTEN\nC 820803 Minor cosmetic changes for release 1.\nC 890411 Added SAVE statements (Vers. 3.2).\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890703 Corrected category record. (WRB)\nC 890703 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\nC***END PROLOGUE CHFEV\nC Programming notes:\nC\nC To produce a double precision version, simply:\nC a. Change CHFEV to DCHFEV wherever it occurs,\nC b. Change the real declaration to double precision, and\nC c. Change the constant ZERO to double precision.\nC\nC DECLARE ARGUMENTS.\nC\n INTEGER NE, NEXT(2), IERR\n REAL X1, X2, F1, F2, D1, D2, XE(*), FE(*)\nC\nC DECLARE LOCAL VARIABLES.\nC\n INTEGER I\n REAL C2, C3, DEL1, DEL2, DELTA, H, X, XMI, XMA, ZERO\n SAVE ZERO\n DATA ZERO /0./\nC\nC VALIDITY-CHECK ARGUMENTS.\nC\nC***FIRST EXECUTABLE STATEMENT CHFEV\n IF (NE .LT. 1) GO TO 5001\n H = X2 - X1\n IF (H .EQ. ZERO) GO TO 5002\nC\nC INITIALIZE.\nC\n IERR = 0\n NEXT(1) = 0\n NEXT(2) = 0\n XMI = MIN(ZERO, H)\n XMA = MAX(ZERO, H)\nC\nC COMPUTE CUBIC COEFFICIENTS (EXPANDED ABOUT X1).\nC\n DELTA = (F2 - F1)/H\n DEL1 = (D1 - DELTA)/H\n DEL2 = (D2 - DELTA)/H\nC (DELTA IS NO LONGER NEEDED.)\n C2 = -(DEL1+DEL1 + DEL2)\n C3 = (DEL1 + DEL2)/H\nC (H, DEL1 AND DEL2 ARE NO LONGER NEEDED.)\nC\nC EVALUATION LOOP.\nC\n DO 500 I = 1, NE\n X = XE(I) - X1\n FE(I) = F1 + X*(D1 + X*(C2 + X*C3))\nC COUNT EXTRAPOLATION POINTS.\n IF ( X.LT.XMI ) NEXT(1) = NEXT(1) + 1\n IF ( X.GT.XMA ) NEXT(2) = NEXT(2) + 1\nC (NOTE REDUNDANCY--IF EITHER CONDITION IS TRUE, OTHER IS FALSE.)\n 500 CONTINUE\nC\nC NORMAL RETURN.\nC\n RETURN\nC\nC ERROR RETURNS.\nC\n 5001 CONTINUE\nC NE.LT.1 RETURN.\n IERR = -1\n CALL XERMSG ('SLATEC', 'CHFEV',\n + 'NUMBER OF EVALUATION POINTS LESS THAN ONE', IERR, 1)\n RETURN\nC\n 5002 CONTINUE\nC X1.EQ.X2 RETURN.\n IERR = -2\n CALL XERMSG ('SLATEC', 'CHFEV', 'INTERVAL ENDPOINTS EQUAL', IERR,\n + 1)\n RETURN\nC------------- LAST LINE OF CHFEV FOLLOWS ------------------------------\n END\n", "meta": {"hexsha": "1e97820d510a9ab92bb3ca253cd619d51f592a47", "size": 4969, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/chfev.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/chfev.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/chfev.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.8525641026, "max_line_length": 72, "alphanum_fraction": 0.5848259207, "num_tokens": 1677, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648677, "lm_q2_score": 0.766293648423189, "lm_q1q2_score": 0.6697998335381402}} {"text": " subroutine rotampspc(nyq,ampspc,freqhz,expon)\nc\nc subroutine to differentiate or integrate an amplitude spectrum.\nc\nc inputs:\nc nyq - number of frequency points\nc ampspec - amplitude spectrum\nc freqhz - frequencies in hertz\nc exp - exponent to rotate spectrum\nc -2 integrate twice\nc -1 integrate once\nc +1 differentiate once\nc +2 differentiate twice\nc\nc\n dimension ampspc(1),freqhz(1)\n logical lzero\n parameter (pi=3.14159265,tpi=2.*pi)\n data lzero/.false./\nc\n if (expon .eq. 0.) return\n nstart = 1\n if (freqhz(1).eq.0.) then\n nstart = 2\n lzero = .true.\n end if\n do 100 ifrq = nstart,nyq\n factor = expon * log( tpi * freqhz(ifrq))\n ampspc(ifrq) = factor + log(ampspc(ifrq))\n ampspc(ifrq) = exp(ampspc(ifrq))\n 100 continue\n if (.not.lzero) return\n if (expon.gt.0) ampspc(1) = ampspc(2)\n if (expon.lt.0) ampspc(1) = 0.\n return\n end\n\nc $Id$ \n", "meta": {"hexsha": "64a790055e67904a371705ba6133043bd8d04f3f", "size": 1029, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "lib/dataformat/mw/rotampspc.f", "max_stars_repo_name": "jreyes1108/antelope_contrib", "max_stars_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_stars_repo_licenses": ["BSD-2-Clause", "MIT"], "max_stars_count": 30, "max_stars_repo_stars_event_min_datetime": "2015-02-20T21:44:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-27T02:53:14.000Z", "max_issues_repo_path": "lib/dataformat/mw/rotampspc.f", "max_issues_repo_name": "jreyes1108/antelope_contrib", "max_issues_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_issues_repo_licenses": ["BSD-2-Clause", "MIT"], "max_issues_count": 14, "max_issues_repo_issues_event_min_datetime": "2015-07-07T19:17:24.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-19T19:18:53.000Z", "max_forks_repo_path": "lib/dataformat/mw/rotampspc.f", "max_forks_repo_name": "jreyes1108/antelope_contrib", "max_forks_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_forks_repo_licenses": ["BSD-2-Clause", "MIT"], "max_forks_count": 46, "max_forks_repo_forks_event_min_datetime": "2015-02-06T16:22:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T11:46:37.000Z", "avg_line_length": 26.3846153846, "max_line_length": 66, "alphanum_fraction": 0.5782312925, "num_tokens": 334, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.874077222043951, "lm_q2_score": 0.766293653760418, "lm_q1q2_score": 0.6697998281488154}} {"text": " SUBROUTINE polcof(xa,ya,n,cof)\r\n INTEGER n,NMAX\r\n REAL cof(n),xa(n),ya(n)\r\n PARAMETER (NMAX=15)\r\nCU USES polint\r\n INTEGER i,j,k\r\n REAL dy,xmin,x(NMAX),y(NMAX)\r\n do 11 j=1,n\r\n x(j)=xa(j)\r\n y(j)=ya(j)\r\n11 continue\r\n do 14 j=1,n\r\n call polint(x,y,n+1-j,0.,cof(j),dy)\r\n xmin=1.e38\r\n k=0\r\n do 12 i=1,n+1-j\r\n if (abs(x(i)).lt.xmin)then\r\n xmin=abs(x(i))\r\n k=i\r\n endif\r\n if(x(i).ne.0.)y(i)=(y(i)-cof(j))/x(i)\r\n12 continue\r\n do 13 i=k+1,n+1-j\r\n y(i-1)=y(i)\r\n x(i-1)=x(i)\r\n13 continue\r\n14 continue\r\n return\r\n END\r\n", "meta": {"hexsha": "bffdd9d4804c52447dd18622fd18951673150561", "size": 690, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/polcof.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/polcof.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/polcof.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.0, "max_line_length": 48, "alphanum_fraction": 0.4217391304, "num_tokens": 245, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772417253256, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6697998245699255}} {"text": " subroutine cylinder_setprob()\n implicit none\n\n double precision arc\n\n double precision pi, pi2\n common /compi/ pi, pi2\n\n integer example\n common /example_comm/ example\n\n integer initchoice\n common /initchoice_comm/ initchoice\n\n integer refine_pattern\n common /refine_comm/ refine_pattern\n\n integer mapping \n common /mapping_comm/ mapping\n\n double precision r_cyl, h_cyl\n common /cylinder_comm/ r_cyl, h_cyl\n\n double precision r_latlong, phi0, phi1\n common /latlong_comm/ r_latlong, phi0, phi1\n\n integer exact_metric\n common /metric_comm/ exact_metric\n\n double precision xc0, yc0, r0\n common /cylinder_init_comm/ xc0, yc0, r0\n\n double precision revs_per_s, v_speed\n common /stream_comm/ revs_per_s, v_speed\n\n pi = 4.d0*atan(1.d0)\n pi2 = 2*pi\n\nc !! These are written out in cylinder_user.cpp\n open(10,file='setprob.data')\n read(10,*) example\n read(10,*) initchoice\n read(10,*) refine_pattern\n read(10,*) r_cyl\n read(10,*) h_cyl\n read(10,*) xc0\n read(10,*) yc0\n read(10,*) r0\n read(10,*) revs_per_s\n read(10,*) v_speed\n read(10,*) exact_metric\n read(10,*) mapping\n close(10)\n \n r_latlong = sqrt((h_cyl/2)**2 + r_cyl**2)\n arc = asin(h_cyl/(2*r_latlong))\nc # Want phi = phi0 + (phi1-phi0)*y for y in [0,1]\nc # and phi in [-pi/2, pi/2]\n phi0 = -0.5*arc/(pi/2);\n phi1 = -phi0;\n\n\nc h_cyl = 2*pi*r_cyl\n\n end\n", "meta": {"hexsha": "6d845d3e60ad1cf37eb58850e4f2c465aabb613d", "size": 1542, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "applications/paper/cylinder/setprob.f", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2017-09-26T13:39:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:56:23.000Z", "max_issues_repo_path": "applications/paper/cylinder/setprob.f", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 75, "max_issues_repo_issues_event_min_datetime": "2017-08-02T19:56:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T12:36:32.000Z", "max_forks_repo_path": "applications/paper/cylinder/setprob.f", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-02-21T00:10:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T19:08:36.000Z", "avg_line_length": 23.3636363636, "max_line_length": 54, "alphanum_fraction": 0.602464332, "num_tokens": 485, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772417253255, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6697998245699254}} {"text": "submodule(euler_interface_m) euler_prob_0016_m\n implicit none\n\ncontains\n\n module character(len=20) function euler0016()\n write (euler0016, \"(i20)\") ans(1000)\n end function euler0016\n\n integer function ans(n)\n integer, intent(in) :: n\n integer, allocatable :: iarr(:)\n integer :: i, j, l\n\n l = floor(real(n)*log10(2.0) + 1.0)\n allocate (iarr(l))\n iarr = 0\n iarr(l) = 1\n\n do i = 1, n\n iarr = iarr*2\n\n do j = l, 2, -1\n iarr(j - 1) = iarr(j - 1) + iarr(j)/10\n iarr(j) = mod(iarr(j), 10)\n end do\n end do\n\n ans = sum(iarr, dim=1)\n end function ans\n\nend submodule euler_prob_0016_m\n", "meta": {"hexsha": "2c9c6a424f6ac4c095b2c809063ed20afbaae8a7", "size": 730, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/euler/prob_0016_m.f90", "max_stars_repo_name": "han190/PE-Fortran", "max_stars_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-02-09T07:07:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-31T07:45:48.000Z", "max_issues_repo_path": "docs/src/prob_0016_m.f90", "max_issues_repo_name": "han190/PE-Fortran", "max_issues_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-14T00:48:58.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-14T00:48:58.000Z", "max_forks_repo_path": "docs/src/prob_0016_m.f90", "max_forks_repo_name": "han190/PE-Fortran", "max_forks_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-04T21:29:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T21:29:45.000Z", "avg_line_length": 22.1212121212, "max_line_length": 54, "alphanum_fraction": 0.5150684932, "num_tokens": 233, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648678, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.669799824207839}} {"text": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\ncc cc\ncc mncual : cualde test program cc\ncc evaluation of a closed planar spline curve cc\ncc x = sx(u) , y = sy(u) cc\ncc through its polynomial representation cc\ncc in each knot interval. cc\ncc cc\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\n real t(20),c(40),u(20),sp(40),d(12),cof(2,6)\n integer i,idim,ier,ii,ip,i1,i2,j,jj,jn,j1,j2,j3,j4,k,kk,k1,\n * l,l1,m,n,nc,nd,nk,nk1\n real ai,aj,arg,fac,per,pol,tt,uu\nc we have a planar curve\n idim = 2\nc set up the dimension information\n nc = 40\n nd = 12\nc set up the points where the curve will be evaluated.\n m = 20\n do 10 i=1,m\n ai = i-1\n u(i) = ai*0.5e-01\n 10 continue\nc main loop for the different spline degrees.\n do 120 k=3,5,2\nc the order of the spline.\n k1 = k+1\nc n denotes the total number of knots.\n n = 2*k1+4\nc set up the knots of the spline\n t(k1) = 0.\n t(k1+1) = 0.1e0\n t(k1+2) = 0.3e0\n t(k1+3) = 0.4e0\n t(k1+4) = 0.8e0\n t(k1+5) = 0.1e+01\nc fetch the b-spline coefficients for sx(u)\n c(1) = 0.1e+01\n c(2) = 0.3e+01\n c(3) = 0.4e+01\n c(4) = 0.5e+01\n c(5) = -0.1e+01\nc fetch the b-spline coefficients for sy(u)\n c(n+1) = 0.1e+01\n c(n+2) = 0.2e+01\n c(n+3) = -0.3e+01\n c(n+4) = 0.2e+01\n c(n+5) = 0.4e+01\nc incorporate the boundary conditions for periodic splines\n nk = n-k\n per = t(nk)-t(k1)\n do 20 j=1,k\nc the boundary knots\n i1 = nk+j\n i2 = nk-j\n j1 = k1+j\n j2 = k1-j\n t(i1) = t(j1)+per\n t(j2) = t(i2)-per\nc the boundary coefficients\n jn = j+n\n c(j+5) = c(j)\n c(jn+5) = c(jn)\n 20 continue\nc print the data for the spline.\n write(6,900) k\n write(6,905)\n write(6,910) (t(i),i=1,n)\n write(6,915)\n nk1 = n-k1\n write(6,920) (c(i),i=1,nk1)\n write(6,925)\n i1 = n+1\n i2 = n+nk1\n write(6,920) (c(i),i=i1,i2)\n l = k\n l1 = k1\n kk = k1*idim\nc main loop for the different points of evaluation.\n ip = 0\n do 100 i=1,m\n arg = u(i)\nc search for knot interval t(l)<=u(i)= 1.\r\nC\r\nC MP1 (input) INTEGER\r\nC The order of the numerator + 1, i.e. M + 1. MP1 >= 1.\r\nC\r\nC W (input) DOUBLE PRECISION\r\nC The frequency value W for which the transfer function is\r\nC to be evaluated.\r\nC\r\nC A (input) DOUBLE PRECISION array, dimension (NP1)\r\nC This array must contain the vector of denominator\r\nC coefficients in ascending order of powers. That is, A(i)\r\nC must contain the coefficient of (jW)**(i-1) for i = 1,\r\nC 2,...,NP1.\r\nC\r\nC B (input) DOUBLE PRECISION array, dimension (MP1)\r\nC This array must contain the vector of numerator\r\nC coefficients in ascending order of powers. That is, B(i)\r\nC must contain the coefficient of (jW)**(i-1) for i = 1,\r\nC 2,...,MP1.\r\nC\r\nC VALR (output) DOUBLE PRECISION\r\nC If OUTPUT = 'C', VALR contains the real part of G(jW).\r\nC If OUTPUT = 'P', VALR contains the magnitude of G(jW)\r\nC in dBs.\r\nC\r\nC VALI (output) DOUBLE PRECISION\r\nC If OUTPUT = 'C', VALI contains the imaginary part of\r\nC G(jW).\r\nC If OUTPUT = 'P', VALI contains the phase of G(jW) in\r\nC degrees.\r\nC\r\nC Error Indicator\r\nC\r\nC INFO INTEGER\r\nC = 0: successful exit;\r\nC < 0: if INFO = -i, the i-th argument had an illegal\r\nC value;\r\nC = 1: if the frequency value W is a pole of G(jW), or all\r\nC the coefficients of the A polynomial are zero.\r\nC\r\nC METHOD\r\nC\r\nC By substituting the values of A, B and W in the following\r\nC formula:\r\nC\r\nC B(1)+B(2)*(jW)+B(3)*(jW)**2+...+B(MP1)*(jW)**(MP1-1)\r\nC G(jW) = ---------------------------------------------------.\r\nC A(1)+A(2)*(jW)+A(3)*(jW)**2+...+A(NP1)*(jW)**(NP1-1)\r\nC\r\nC REFERENCES\r\nC\r\nC None.\r\nC\r\nC NUMERICAL ASPECTS\r\nC\r\nC The algorithm requires 0(N+M) operations.\r\nC\r\nC CONTRIBUTORS\r\nC\r\nC Release 3.0: V. Sima, Katholieke Univ. Leuven, Belgium, Dec. 1996.\r\nC Supersedes Release 2.0 routine TD01AD by Control Systems Research\r\nC Group, Kingston Polytechnic, United Kingdom, March 1981.\r\nC\r\nC REVISIONS\r\nC\r\nC February 1997.\r\nC February 22, 1998 (changed the name of TD01MD).\r\nC\r\nC KEYWORDS\r\nC\r\nC Elementary polynomial operations, frequency response, matrix\r\nC fraction, polynomial matrix, state-space representation, transfer\r\nC matrix.\r\nC\r\nC ******************************************************************\r\nC\r\nC .. Parameters ..\r\n DOUBLE PRECISION ZERO, ONE, EIGHT, TWENTY, NINETY, ONE80, THRE60\r\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0, EIGHT=8.0D0,\r\n $ TWENTY=20.0D0, NINETY=90.0D0, ONE80 = 180.0D0,\r\n $ THRE60=360.0D0 )\r\nC .. Scalar Arguments ..\r\n CHARACTER OUTPUT, UNITF\r\n INTEGER INFO, MP1, NP1\r\n DOUBLE PRECISION VALI, VALR, W\r\nC .. Array Arguments ..\r\n DOUBLE PRECISION A(*), B(*)\r\nC .. Local Scalars ..\r\n LOGICAL LOUTPU, LUNITF\r\n INTEGER I, IPHASE, M, M2, N, N2, NPZERO, NZZERO\r\n DOUBLE PRECISION BIMAG, BREAL, G, TIMAG, TREAL, TWOPI, W2, WC\r\n COMPLEX*16 ZTEMP\r\nC .. External Functions ..\r\n LOGICAL LSAME\r\n DOUBLE PRECISION DLAPY2\r\n COMPLEX*16 ZLADIV\r\n EXTERNAL DLAPY2, LSAME, ZLADIV\r\nC .. External Subroutines ..\r\n EXTERNAL XERBLA\r\nC .. Intrinsic Functions ..\r\n INTRINSIC ABS, ATAN, DBLE, DCMPLX, DIMAG, LOG10, MAX, MOD,\r\n $ SIGN\r\nC .. Executable Statements ..\r\nC\r\n INFO = 0\r\n LUNITF = LSAME( UNITF, 'H' )\r\n LOUTPU = LSAME( OUTPUT, 'P' )\r\nC\r\nC Test the input scalar arguments.\r\nC\r\n IF( .NOT.LUNITF .AND. .NOT.LSAME( UNITF, 'R' ) ) THEN\r\n INFO = -1\r\n ELSE IF( .NOT.LOUTPU .AND. .NOT.LSAME( OUTPUT, 'C' ) ) THEN\r\n INFO = -2\r\n ELSE IF( NP1.LT.1 ) THEN\r\n INFO = -3\r\n ELSE IF( MP1.LT.1 ) THEN\r\n INFO = -4\r\n END IF\r\nC\r\n IF ( INFO.NE.0 ) THEN\r\nC\r\nC Error return.\r\nC\r\n CALL XERBLA( 'TD05AD', -INFO )\r\n RETURN\r\n END IF\r\nC\r\n M = MP1 - 1\r\n N = NP1 - 1\r\n WC = W\r\n TWOPI = EIGHT*ATAN( ONE )\r\n IF ( LUNITF ) WC = WC*TWOPI\r\n W2 = WC**2\r\nC\r\nC Determine the orders z (NZZERO) and p (NPZERO) of the factors\r\nC (jW)**k in the numerator and denominator polynomials, by counting\r\nC the zero trailing coefficients. The value of G(jW) will then be\r\nC computed as (jW)**(z-p)*m(jW)/n(jW), for appropriate m and n.\r\nC\r\n I = 0\r\nC\r\n 10 CONTINUE\r\n I = I + 1\r\n IF ( I.LE.M ) THEN\r\n IF ( B(I).EQ.ZERO ) GO TO 10\r\n END IF\r\nC\r\n NZZERO = I - 1\r\n I = 0\r\nC\r\n 20 CONTINUE\r\n I = I + 1\r\n IF ( I.LE.N ) THEN\r\n IF ( A(I).EQ.ZERO ) GO TO 20\r\n END IF\r\nC\r\n NPZERO = I - 1\r\n IPHASE = NZZERO - NPZERO\r\nC\r\n M2 = MOD( M - NZZERO, 2 )\r\nC\r\nC Add real parts of the numerator m(jW).\r\nC\r\n TREAL = B(MP1-M2)\r\nC\r\n DO 30 I = M - 1 - M2, NZZERO + 1, -2\r\n TREAL = B(I) - W2*TREAL\r\n 30 CONTINUE\r\nC\r\nC Add imaginary parts of the numerator m(jW).\r\nC\r\n IF ( M.EQ.0 ) THEN\r\n TIMAG = ZERO\r\n ELSE\r\n TIMAG = B(M+M2)\r\nC\r\n DO 40 I = M + M2 - 2, NZZERO + 2, -2\r\n TIMAG = B(I) - W2*TIMAG\r\n 40 CONTINUE\r\nC\r\n TIMAG = TIMAG*WC\r\n END IF\r\nC\r\n N2 = MOD( N - NPZERO, 2 )\r\nC\r\nC Add real parts of the denominator n(jW).\r\nC\r\n BREAL = A(NP1-N2)\r\nC\r\n DO 50 I = N - 1 - N2, NPZERO + 1, -2\r\n BREAL = A(I) - W2*BREAL\r\n 50 CONTINUE\r\nC\r\nC Add imaginary parts of the denominator n(jW).\r\nC\r\n IF ( N.EQ.0 ) THEN\r\n BIMAG = ZERO\r\n ELSE\r\n BIMAG = A(N+N2)\r\nC\r\n DO 60 I = N + N2 - 2, NPZERO + 2, -2\r\n BIMAG = A(I) - W2*BIMAG\r\n 60 CONTINUE\r\nC\r\n BIMAG = BIMAG*WC\r\n END IF\r\nC\r\n IF ( ( MAX( ABS( BREAL ), ABS( BIMAG ) ).EQ.ZERO ) .OR.\r\n $ ( W.EQ.ZERO .AND. IPHASE.LT.0 ) ) THEN\r\nC\r\nC Error return: The specified frequency W is a pole of G(jW),\r\nC or all the coefficients of the A polynomial are zero.\r\nC\r\n INFO = 1\r\n ELSE\r\nC\r\nC Evaluate the complex number W**(z-p)*m(jW)/n(jW).\r\nC\r\n ZTEMP =\r\n $ ZLADIV( DCMPLX( TREAL, TIMAG ), DCMPLX( BREAL, BIMAG ) )\r\n VALR = DBLE( ZTEMP )*WC**IPHASE\r\n VALI = DIMAG( ZTEMP )*WC**IPHASE\r\nC\r\n IF ( .NOT.LOUTPU ) THEN\r\nC\r\nC Cartesian co-ordinates: Update the result for j**(z-p).\r\nC\r\n I = MOD( ABS( IPHASE ), 4 )\r\n IF ( ( IPHASE.GT.0 .AND. I.GT.1 ) .OR.\r\n $ ( IPHASE.LT.0 .AND. ( I.EQ.1 .OR. I.EQ.2) ) ) THEN\r\n VALR = -VALR\r\n VALI = -VALI\r\n END IF\r\nC\r\n IF ( MOD( I, 2 ).NE.0 ) THEN\r\n G = VALR\r\n VALR = -VALI\r\n VALI = G\r\n END IF\r\nC\r\n ELSE\r\nC\r\nC Polar co-ordinates: Compute the magnitude and phase.\r\nC\r\n G = DLAPY2( VALR, VALI )\r\nC\r\n IF ( VALR.EQ.ZERO ) THEN\r\n VALI = SIGN( NINETY, VALI )\r\n ELSE\r\n VALI = ( ATAN( VALI/VALR )/TWOPI )*THRE60\r\n IF ( VALI.EQ.ZERO .AND. NZZERO.EQ.M .AND. NPZERO.EQ.N\r\n $ .AND. B(NZZERO+1)*A(NPZERO+1).LT.ZERO )\r\n $ VALI = ONE80\r\n END IF\r\nC\r\n VALR = TWENTY*LOG10( G )\r\nC\r\n IF ( IPHASE.NE.0 )\r\n $ VALI = VALI + DBLE( NZZERO - NPZERO )*NINETY\r\n END IF\r\nC\r\n END IF\r\nC\r\n RETURN\r\nC *** Last line of TD05AD ***\r\n END\r\n", "meta": {"hexsha": "77501de9cb88cb6662c5b268c354183682bcdd02", "size": 9030, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "External/SLICOT/TD05AD.f", "max_stars_repo_name": "bgin/MissileSimulation", "max_stars_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2016-08-28T23:20:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-15T14:43:58.000Z", "max_issues_repo_path": "External/SLICOT/TD05AD.f", "max_issues_repo_name": "bgin/MissileSimulation", "max_issues_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-06-02T21:29:51.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-05T05:59:31.000Z", "max_forks_repo_path": "External/SLICOT/TD05AD.f", "max_forks_repo_name": "bgin/MissileSimulation", "max_forks_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-07-04T22:38:22.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-04T22:38:22.000Z", "avg_line_length": 30.0, "max_line_length": 73, "alphanum_fraction": 0.4968992248, "num_tokens": 2864, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818864, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6697951083294847}} {"text": "C\nC file poistg.f\nC\n SUBROUTINE POISTG (NPEROD,N,MPEROD,M,A,B,C,IDIMY,Y,IERROR,W)\nC\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC * *\nC * copyright (c) 1999 by UCAR *\nC * *\nC * UNIVERSITY CORPORATION for ATMOSPHERIC RESEARCH *\nC * *\nC * all rights reserved *\nC * *\nC * FISHPACK version 4.1 *\nC * *\nC * A PACKAGE OF FORTRAN SUBPROGRAMS FOR THE SOLUTION OF *\nC * *\nC * SEPARABLE ELLIPTIC PARTIAL DIFFERENTIAL EQUATIONS *\nC * *\nC * BY *\nC * *\nC * JOHN ADAMS, PAUL SWARZTRAUBER AND ROLAND SWEET *\nC * *\nC * OF *\nC * *\nC * THE NATIONAL CENTER FOR ATMOSPHERIC RESEARCH *\nC * *\nC * BOULDER, COLORADO (80307) U.S.A. *\nC * *\nC * WHICH IS SPONSORED BY *\nC * *\nC * THE NATIONAL SCIENCE FOUNDATION *\nC * *\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC\nC\nC\nC DIMENSION OF A(M), B(M), C(M), Y(IDIMY,N),\nC ARGUMENTS W(SEE ARGUMENT LIST)\nC\nC LATEST REVISION NOVEMBER 1988\nC\nC PURPOSE SOLVES THE LINEAR SYSTEM OF EQUATIONS\nC FOR UNKNOWN X VALUES, WHERE I=1,2,...,M\nC AND J=1,2,...,N\nC\nC A(I)*X(I-1,J) + B(I)*X(I,J) + C(I)*X(I+1,J)\nC + X(I,J-1) - 2.*X(I,J) + X(I,J+1)\nC = Y(I,J)\nC\nC THE INDICES I+1 AND I-1 ARE EVALUATED MODULO M,\nC I.E. X(0,J) = X(M,J) AND X(M+1,J) = X(1,J), AND\nC X(I,0) MAY BE EQUAL TO X(I,1) OR -X(I,1), AND\nC X(I,N+1) MAY BE EQUAL TO X(I,N) OR -X(I,N),\nC DEPENDING ON AN INPUT PARAMETER.\nC\nC USAGE CALL POISTG (NPEROD,N,MPEROD,M,A,B,C,IDIMY,Y,\nC IERROR,W)\nC\nC ARGUMENTS\nC\nC ON INPUT\nC\nC NPEROD\nC INDICATES VALUES WHICH X(I,0) AND X(I,N+1)\nC ARE ASSUMED TO HAVE.\nC = 1 IF X(I,0) = -X(I,1) AND X(I,N+1) = -X(I,N\nC = 2 IF X(I,0) = -X(I,1) AND X(I,N+1) = X(I,N\nC = 3 IF X(I,0) = X(I,1) AND X(I,N+1) = X(I,N\nC = 4 IF X(I,0) = X(I,1) AND X(I,N+1) = -X(I,N\nC\nC N\nC THE NUMBER OF UNKNOWNS IN THE J-DIRECTION.\nC N MUST BE GREATER THAN 2.\nC\nC MPEROD\nC = 0 IF A(1) AND C(M) ARE NOT ZERO\nC = 1 IF A(1) = C(M) = 0\nC\nC M\nC THE NUMBER OF UNKNOWNS IN THE I-DIRECTION.\nC M MUST BE GREATER THAN 2.\nC\nC A,B,C\nC ONE-DIMENSIONAL ARRAYS OF LENGTH M THAT\nC SPECIFY THE COEFFICIENTS IN THE LINEAR\nC EQUATIONS GIVEN ABOVE. IF MPEROD = 0 THE\nC ARRAY ELEMENTS MUST NOT DEPEND ON INDEX I,\nC BUT MUST BE CONSTANT. SPECIFICALLY, THE\nC SUBROUTINE CHECKS THE FOLLOWING CONDITION\nC A(I) = C(1)\nC B(I) = B(1)\nC C(I) = C(1)\nC FOR I = 1, 2, ..., M.\nC\nC IDIMY\nC THE ROW (OR FIRST) DIMENSION OF THE TWO-\nC DIMENSIONAL ARRAY Y AS IT APPEARS IN THE\nC PROGRAM CALLING POISTG. THIS PARAMETER IS\nC USED TO SPECIFY THE VARIABLE DIMENSION OF Y.\nC IDIMY MUST BE AT LEAST M.\nC\nC Y\nC A TWO-DIMENSIONAL ARRAY THAT SPECIFIES THE\nC VALUES OF THE RIGHT SIDE OF THE LINEAR SYSTEM\nC OF EQUATIONS GIVEN ABOVE.\nC Y MUST BE DIMENSIONED AT LEAST M X N.\nC\nC W\nC A ONE-DIMENSIONAL WORK ARRAY THAT MUST BE\nC PROVIDED BY THE USER FOR WORK SPACE. W MAY\nC REQUIRE UP TO 9M + 4N + M(INT(LOG2(N)))\nC LOCATIONS. THE ACTUAL NUMBER OF LOCATIONS\nC USED IS COMPUTED BY POISTG AND RETURNED IN\nC LOCATION W(1).\nC\nC ON OUTPUT\nC\nC Y\nC CONTAINS THE SOLUTION X.\nC\nC IERROR\nC AN ERROR FLAG THAT INDICATES INVALID INPUT\nC PARAMETERS. EXCEPT FOR NUMBER ZERO, A\nC SOLUTION IS NOT ATTEMPTED.\nC = 0 NO ERROR\nC = 1 IF M .LE. 2\nC = 2 IF N .LE. 2\nC = 3 IDIMY .LT. M\nC = 4 IF NPEROD .LT. 1 OR NPEROD .GT. 4\nC = 5 IF MPEROD .LT. 0 OR MPEROD .GT. 1\nC = 6 IF MPEROD = 0 AND A(I) .NE. C(1)\nC OR B(I) .NE. B(1) OR C(I) .NE. C(1)\nC FOR SOME I = 1, 2, ..., M.\nC = 7 IF MPEROD .EQ. 1 .AND.\nC (A(1).NE.0 .OR. C(M).NE.0)\nC\nC W\nC W(1) CONTAINS THE REQUIRED LENGTH OF W.\nC\nC\nC I/O NONE\nC\nC PRECISION SINGLE\nC\nC REQUIRED LIBRARY GNBNAUX AND COMF FROM FISHPACK\nC FILES\nC\nC LANGUAGE FORTRAN\nC\nC HISTORY WRITTEN BY ROLAND SWEET AT NCAR IN THE LATE\nC 1970'S. RELEASED ON NCAR'S PUBLIC SOFTWARE\nC LIBRARIES IN JANUARY, 1980.\nC\nC PORTABILITY FORTRAN 77\nC\nC ALGORITHM THIS SUBROUTINE IS AN IMPLEMENTATION OF THE\nC ALGORITHM PRESENTED IN THE REFERENCE BELOW.\nC\nC TIMING FOR LARGE M AND N, THE EXECUTION TIME IS\nC ROUGHLY PROPORTIONAL TO M*N*LOG2(N).\nC\nC ACCURACY TO MEASURE THE ACCURACY OF THE ALGORITHM A\nC UNIFORM RANDOM NUMBER GENERATOR WAS USED TO\nC CREATE A SOLUTION ARRAY X FOR THE SYSTEM GIVEN\nC IN THE 'PURPOSE' SECTION ABOVE, WITH\nC A(I) = C(I) = -0.5*B(I) = 1, I=1,2,...,M\nC AND, WHEN MPEROD = 1\nC A(1) = C(M) = 0\nC B(1) = B(M) =-1.\nC\nC THE SOLUTION X WAS SUBSTITUTED INTO THE GIVEN\nC SYSTEM AND, USING DOUBLE PRECISION, A RIGHT SID\nC Y WAS COMPUTED. USING THIS ARRAY Y SUBROUTINE\nC POISTG WAS CALLED TO PRODUCE AN APPROXIMATE\nC SOLUTION Z. THEN THE RELATIVE ERROR, DEFINED A\nC E = MAX(ABS(Z(I,J)-X(I,J)))/MAX(ABS(X(I,J)))\nC WHERE THE TWO MAXIMA ARE TAKEN OVER I=1,2,...,M\nC AND J=1,2,...,N, WAS COMPUTED. VALUES OF E ARE\nC GIVEN IN THE TABLE BELOW FOR SOME TYPICAL VALUE\nC OF M AND N.\nC\nC M (=N) MPEROD NPEROD E\nC ------ ------ ------ ------\nC\nC 31 0-1 1-4 9.E-13\nC 31 1 1 4.E-13\nC 31 1 3 3.E-13\nC 32 0-1 1-4 3.E-12\nC 32 1 1 3.E-13\nC 32 1 3 1.E-13\nC 33 0-1 1-4 1.E-12\nC 33 1 1 4.E-13\nC 33 1 3 1.E-13\nC 63 0-1 1-4 3.E-12\nC 63 1 1 1.E-12\nC 63 1 3 2.E-13\nC 64 0-1 1-4 4.E-12\nC 64 1 1 1.E-12\nC 64 1 3 6.E-13\nC 65 0-1 1-4 2.E-13\nC 65 1 1 1.E-11\nC 65 1 3 4.E-13\nC\nC REFERENCES SCHUMANN, U. AND R. SWEET,\"A DIRECT METHOD\nC FOR THE SOLUTION OF POISSON\"S EQUATION WITH\nC NEUMANN BOUNDARY CONDITIONS ON A STAGGERED\nC GRID OF ARBITRARY SIZE,\" J. COMP. PHYS.\nC 20(1976), PP. 171-182.\nC *********************************************************************\n DIMENSION Y(IDIMY,1)\n DIMENSION W(*) ,B(*) ,A(*) ,C(*)\nC\n IERROR = 0\n IF (M .LE. 2) IERROR = 1\n IF (N .LE. 2) IERROR = 2\n IF (IDIMY .LT. M) IERROR = 3\n IF (NPEROD.LT.1 .OR. NPEROD.GT.4) IERROR = 4\n IF (MPEROD.LT.0 .OR. MPEROD.GT.1) IERROR = 5\n IF (MPEROD .EQ. 1) GO TO 103\n DO 101 I=1,M\n IF (A(I) .NE. C(1)) GO TO 102\n IF (C(I) .NE. C(1)) GO TO 102\n IF (B(I) .NE. B(1)) GO TO 102\n 101 CONTINUE\n GO TO 104\n 102 IERROR = 6\n RETURN\n 103 IF (A(1).NE.0. .OR. C(M).NE.0.) IERROR = 7\n 104 IF (IERROR .NE. 0) RETURN\n IWBA = M+1\n IWBB = IWBA+M\n IWBC = IWBB+M\n IWB2 = IWBC+M\n IWB3 = IWB2+M\n IWW1 = IWB3+M\n IWW2 = IWW1+M\n IWW3 = IWW2+M\n IWD = IWW3+M\n IWTCOS = IWD+M\n IWP = IWTCOS+4*N\n DO 106 I=1,M\n K = IWBA+I-1\n W(K) = -A(I)\n K = IWBC+I-1\n W(K) = -C(I)\n K = IWBB+I-1\n W(K) = 2.-B(I)\n DO 105 J=1,N\n Y(I,J) = -Y(I,J)\n 105 CONTINUE\n 106 CONTINUE\n NP = NPEROD\n MP = MPEROD+1\n GO TO (110,107),MP\n 107 CONTINUE\n GO TO (108,108,108,119),NPEROD\n 108 CONTINUE\n CALL POSTG2 (NP,N,M,W(IWBA),W(IWBB),W(IWBC),IDIMY,Y,W,W(IWB2),\n 1 W(IWB3),W(IWW1),W(IWW2),W(IWW3),W(IWD),W(IWTCOS),\n 2 W(IWP))\n IPSTOR = W(IWW1)\n IREV = 2\n IF (NPEROD .EQ. 4) GO TO 120\n 109 CONTINUE\n GO TO (123,129),MP\n 110 CONTINUE\nC\nC REORDER UNKNOWNS WHEN MP =0\nC\n MH = (M+1)/2\n MHM1 = MH-1\n MODD = 1\n IF (MH*2 .EQ. M) MODD = 2\n DO 115 J=1,N\n DO 111 I=1,MHM1\n MHPI = MH+I\n MHMI = MH-I\n W(I) = Y(MHMI,J)-Y(MHPI,J)\n W(MHPI) = Y(MHMI,J)+Y(MHPI,J)\n 111 CONTINUE\n W(MH) = 2.*Y(MH,J)\n GO TO (113,112),MODD\n 112 W(M) = 2.*Y(M,J)\n 113 CONTINUE\n DO 114 I=1,M\n Y(I,J) = W(I)\n 114 CONTINUE\n 115 CONTINUE\n K = IWBC+MHM1-1\n I = IWBA+MHM1\n W(K) = 0.\n W(I) = 0.\n W(K+1) = 2.*W(K+1)\n GO TO (116,117),MODD\n 116 CONTINUE\n K = IWBB+MHM1-1\n W(K) = W(K)-W(I-1)\n W(IWBC-1) = W(IWBC-1)+W(IWBB-1)\n GO TO 118\n 117 W(IWBB-1) = W(K+1)\n 118 CONTINUE\n GO TO 107\n 119 CONTINUE\nC\nC REVERSE COLUMNS WHEN NPEROD = 4.\nC\n IREV = 1\n NBY2 = N/2\n NP = 2\n 120 DO 122 J=1,NBY2\n MSKIP = N+1-J\n DO 121 I=1,M\n A1 = Y(I,J)\n Y(I,J) = Y(I,MSKIP)\n Y(I,MSKIP) = A1\n 121 CONTINUE\n 122 CONTINUE\n GO TO (108,109),IREV\n 123 CONTINUE\n DO 128 J=1,N\n DO 124 I=1,MHM1\n MHMI = MH-I\n MHPI = MH+I\n W(MHMI) = .5*(Y(MHPI,J)+Y(I,J))\n W(MHPI) = .5*(Y(MHPI,J)-Y(I,J))\n 124 CONTINUE\n W(MH) = .5*Y(MH,J)\n GO TO (126,125),MODD\n 125 W(M) = .5*Y(M,J)\n 126 CONTINUE\n DO 127 I=1,M\n Y(I,J) = W(I)\n 127 CONTINUE\n 128 CONTINUE\n 129 CONTINUE\nC\nC RETURN STORAGE REQUIREMENTS FOR W ARRAY.\nC\n W(1) = IPSTOR+IWP-1\n RETURN\n END\n SUBROUTINE POSTG2 (NPEROD,N,M,A,BB,C,IDIMQ,Q,B,B2,B3,W,W2,W3,D,\n 1 TCOS,P)\nC\nC SUBROUTINE TO SOLVE POISSON'S EQUATION ON A STAGGERED GRID.\nC\nC\n DIMENSION A(*) ,BB(*) ,C(*) ,Q(IDIMQ,*) ,\n 1 B(*) ,B2(*) ,B3(*) ,W(*) ,\n 2 W2(*) ,W3(*) ,D(*) ,TCOS(*) ,\n 3 K(4) ,P(*)\n EQUIVALENCE (K(1),K1) ,(K(2),K2) ,(K(3),K3) ,(K(4),K4)\n NP = NPEROD\n FNUM = 0.5*FLOAT(NP/3)\n FNUM2 = 0.5*FLOAT(NP/2)\n MR = M\n IP = -MR\n IPSTOR = 0\n I2R = 1\n JR = 2\n NR = N\n NLAST = N\n KR = 1\n LR = 0\n IF (NR .LE. 3) GO TO 142\n 101 CONTINUE\n JR = 2*I2R\n NROD = 1\n IF ((NR/2)*2 .EQ. NR) NROD = 0\n JSTART = 1\n JSTOP = NLAST-JR\n IF (NROD .EQ. 0) JSTOP = JSTOP-I2R\n I2RBY2 = I2R/2\n IF (JSTOP .GE. JSTART) GO TO 102\n J = JR\n GO TO 115\n 102 CONTINUE\nC\nC REGULAR REDUCTION.\nC\n IJUMP = 1\n DO 114 J=JSTART,JSTOP,JR\n JP1 = J+I2RBY2\n JP2 = J+I2R\n JP3 = JP2+I2RBY2\n JM1 = J-I2RBY2\n JM2 = J-I2R\n JM3 = JM2-I2RBY2\n IF (J .NE. 1) GO TO 106\n CALL COSGEN (I2R,1,FNUM,0.5,TCOS)\n IF (I2R .NE. 1) GO TO 104\n DO 103 I=1,MR\n B(I) = Q(I,1)\n Q(I,1) = Q(I,2)\n 103 CONTINUE\n GO TO 112\n 104 DO 105 I=1,MR\n B(I) = Q(I,1)+0.5*(Q(I,JP2)-Q(I,JP1)-Q(I,JP3))\n Q(I,1) = Q(I,JP2)+Q(I,1)-Q(I,JP1)\n 105 CONTINUE\n GO TO 112\n 106 CONTINUE\n GO TO (107,108),IJUMP\n 107 CONTINUE\n IJUMP = 2\n CALL COSGEN (I2R,1,0.5,0.0,TCOS)\n 108 CONTINUE\n IF (I2R .NE. 1) GO TO 110\n DO 109 I=1,MR\n B(I) = 2.*Q(I,J)\n Q(I,J) = Q(I,JM2)+Q(I,JP2)\n 109 CONTINUE\n GO TO 112\n 110 DO 111 I=1,MR\n FI = Q(I,J)\n Q(I,J) = Q(I,J)-Q(I,JM1)-Q(I,JP1)+Q(I,JM2)+Q(I,JP2)\n B(I) = FI+Q(I,J)-Q(I,JM3)-Q(I,JP3)\n 111 CONTINUE\n 112 CONTINUE\n CALL TRIX (I2R,0,MR,A,BB,C,B,TCOS,D,W)\n DO 113 I=1,MR\n Q(I,J) = Q(I,J)+B(I)\n 113 CONTINUE\nC\nC END OF REDUCTION FOR REGULAR UNKNOWNS.\nC\n 114 CONTINUE\nC\nC BEGIN SPECIAL REDUCTION FOR LAST UNKNOWN.\nC\n J = JSTOP+JR\n 115 NLAST = J\n JM1 = J-I2RBY2\n JM2 = J-I2R\n JM3 = JM2-I2RBY2\n IF (NROD .EQ. 0) GO TO 125\nC\nC ODD NUMBER OF UNKNOWNS\nC\n IF (I2R .NE. 1) GO TO 117\n DO 116 I=1,MR\n B(I) = Q(I,J)\n Q(I,J) = Q(I,JM2)\n 116 CONTINUE\n GO TO 123\n 117 DO 118 I=1,MR\n B(I) = Q(I,J)+.5*(Q(I,JM2)-Q(I,JM1)-Q(I,JM3))\n 118 CONTINUE\n IF (NRODPR .NE. 0) GO TO 120\n DO 119 I=1,MR\n II = IP+I\n Q(I,J) = Q(I,JM2)+P(II)\n 119 CONTINUE\n IP = IP-MR\n GO TO 122\n 120 CONTINUE\n DO 121 I=1,MR\n Q(I,J) = Q(I,J)-Q(I,JM1)+Q(I,JM2)\n 121 CONTINUE\n 122 IF (LR .EQ. 0) GO TO 123\n CALL COSGEN (LR,1,FNUM2,0.5,TCOS(KR+1))\n 123 CONTINUE\n CALL COSGEN (KR,1,FNUM2,0.5,TCOS)\n CALL TRIX (KR,LR,MR,A,BB,C,B,TCOS,D,W)\n DO 124 I=1,MR\n Q(I,J) = Q(I,J)+B(I)\n 124 CONTINUE\n KR = KR+I2R\n GO TO 141\n 125 CONTINUE\nC\nC EVEN NUMBER OF UNKNOWNS\nC\n JP1 = J+I2RBY2\n JP2 = J+I2R\n IF (I2R .NE. 1) GO TO 129\n DO 126 I=1,MR\n B(I) = Q(I,J)\n 126 CONTINUE\n TCOS(1) = 0.\n CALL TRIX (1,0,MR,A,BB,C,B,TCOS,D,W)\n IP = 0\n IPSTOR = MR\n DO 127 I=1,MR\n P(I) = B(I)\n B(I) = B(I)+Q(I,N)\n 127 CONTINUE\n TCOS(1) = -1.+2.*FLOAT(NP/2)\n TCOS(2) = 0.\n CALL TRIX (1,1,MR,A,BB,C,B,TCOS,D,W)\n DO 128 I=1,MR\n Q(I,J) = Q(I,JM2)+P(I)+B(I)\n 128 CONTINUE\n GO TO 140\n 129 CONTINUE\n DO 130 I=1,MR\n B(I) = Q(I,J)+.5*(Q(I,JM2)-Q(I,JM1)-Q(I,JM3))\n 130 CONTINUE\n IF (NRODPR .NE. 0) GO TO 132\n DO 131 I=1,MR\n II = IP+I\n B(I) = B(I)+P(II)\n 131 CONTINUE\n GO TO 134\n 132 CONTINUE\n DO 133 I=1,MR\n B(I) = B(I)+Q(I,JP2)-Q(I,JP1)\n 133 CONTINUE\n 134 CONTINUE\n CALL COSGEN (I2R,1,0.5,0.0,TCOS)\n CALL TRIX (I2R,0,MR,A,BB,C,B,TCOS,D,W)\n IP = IP+MR\n IPSTOR = MAX0(IPSTOR,IP+MR)\n DO 135 I=1,MR\n II = IP+I\n P(II) = B(I)+.5*(Q(I,J)-Q(I,JM1)-Q(I,JP1))\n B(I) = P(II)+Q(I,JP2)\n 135 CONTINUE\n IF (LR .EQ. 0) GO TO 136\n CALL COSGEN (LR,1,FNUM2,0.5,TCOS(I2R+1))\n CALL MERGE (TCOS,0,I2R,I2R,LR,KR)\n GO TO 138\n 136 DO 137 I=1,I2R\n II = KR+I\n TCOS(II) = TCOS(I)\n 137 CONTINUE\n 138 CALL COSGEN (KR,1,FNUM2,0.5,TCOS)\n CALL TRIX (KR,KR,MR,A,BB,C,B,TCOS,D,W)\n DO 139 I=1,MR\n II = IP+I\n Q(I,J) = Q(I,JM2)+P(II)+B(I)\n 139 CONTINUE\n 140 CONTINUE\n LR = KR\n KR = KR+JR\n 141 CONTINUE\n NR = (NLAST-1)/JR+1\n IF (NR .LE. 3) GO TO 142\n I2R = JR\n NRODPR = NROD\n GO TO 101\n 142 CONTINUE\nC\nC BEGIN SOLUTION\nC\n J = 1+JR\n JM1 = J-I2R\n JP1 = J+I2R\n JM2 = NLAST-I2R\n IF (NR .EQ. 2) GO TO 180\n IF (LR .NE. 0) GO TO 167\n IF (N .NE. 3) GO TO 156\nC\nC CASE N = 3.\nC\n GO TO (143,148,143),NP\n 143 DO 144 I=1,MR\n B(I) = Q(I,2)\n B2(I) = Q(I,1)+Q(I,3)\n B3(I) = 0.\n 144 CONTINUE\n GO TO (146,146,145),NP\n 145 TCOS(1) = -1.\n TCOS(2) = 1.\n K1 = 1\n GO TO 147\n 146 TCOS(1) = -2.\n TCOS(2) = 1.\n TCOS(3) = -1.\n K1 = 2\n 147 K2 = 1\n K3 = 0\n K4 = 0\n GO TO 150\n 148 DO 149 I=1,MR\n B(I) = Q(I,2)\n B2(I) = Q(I,3)\n B3(I) = Q(I,1)\n 149 CONTINUE\n CALL COSGEN (3,1,0.5,0.0,TCOS)\n TCOS(4) = -1.\n TCOS(5) = 1.\n TCOS(6) = -1.\n TCOS(7) = 1.\n K1 = 3\n K2 = 2\n K3 = 1\n K4 = 1\n 150 CALL TRI3 (MR,A,BB,C,K,B,B2,B3,TCOS,D,W,W2,W3)\n DO 151 I=1,MR\n B(I) = B(I)+B2(I)+B3(I)\n 151 CONTINUE\n GO TO (153,153,152),NP\n 152 TCOS(1) = 2.\n CALL TRIX (1,0,MR,A,BB,C,B,TCOS,D,W)\n 153 DO 154 I=1,MR\n Q(I,2) = B(I)\n B(I) = Q(I,1)+B(I)\n 154 CONTINUE\n TCOS(1) = -1.+4.*FNUM\n CALL TRIX (1,0,MR,A,BB,C,B,TCOS,D,W)\n DO 155 I=1,MR\n Q(I,1) = B(I)\n 155 CONTINUE\n JR = 1\n I2R = 0\n GO TO 188\nC\nC CASE N = 2**P+1\nC\n 156 CONTINUE\n DO 157 I=1,MR\n B(I) = Q(I,J)+Q(I,1)-Q(I,JM1)+Q(I,NLAST)-Q(I,JM2)\n 157 CONTINUE\n GO TO (158,160,158),NP\n 158 DO 159 I=1,MR\n B2(I) = Q(I,1)+Q(I,NLAST)+Q(I,J)-Q(I,JM1)-Q(I,JP1)\n B3(I) = 0.\n 159 CONTINUE\n K1 = NLAST-1\n K2 = NLAST+JR-1\n CALL COSGEN (JR-1,1,0.0,1.0,TCOS(NLAST))\n TCOS(K2) = 2.*FLOAT(NP-2)\n CALL COSGEN (JR,1,0.5-FNUM,0.5,TCOS(K2+1))\n K3 = (3-NP)/2\n CALL MERGE (TCOS,K1,JR-K3,K2-K3,JR+K3,0)\n K1 = K1-1+K3\n CALL COSGEN (JR,1,FNUM,0.5,TCOS(K1+1))\n K2 = JR\n K3 = 0\n K4 = 0\n GO TO 162\n 160 DO 161 I=1,MR\n FI = (Q(I,J)-Q(I,JM1)-Q(I,JP1))/2.\n B2(I) = Q(I,1)+FI\n B3(I) = Q(I,NLAST)+FI\n 161 CONTINUE\n K1 = NLAST+JR-1\n K2 = K1+JR-1\n CALL COSGEN (JR-1,1,0.0,1.0,TCOS(K1+1))\n CALL COSGEN (NLAST,1,0.5,0.0,TCOS(K2+1))\n CALL MERGE (TCOS,K1,JR-1,K2,NLAST,0)\n K3 = K1+NLAST-1\n K4 = K3+JR\n CALL COSGEN (JR,1,0.5,0.5,TCOS(K3+1))\n CALL COSGEN (JR,1,0.0,0.5,TCOS(K4+1))\n CALL MERGE (TCOS,K3,JR,K4,JR,K1)\n K2 = NLAST-1\n K3 = JR\n K4 = JR\n 162 CALL TRI3 (MR,A,BB,C,K,B,B2,B3,TCOS,D,W,W2,W3)\n DO 163 I=1,MR\n B(I) = B(I)+B2(I)+B3(I)\n 163 CONTINUE\n IF (NP .NE. 3) GO TO 164\n TCOS(1) = 2.\n CALL TRIX (1,0,MR,A,BB,C,B,TCOS,D,W)\n 164 DO 165 I=1,MR\n Q(I,J) = B(I)+.5*(Q(I,J)-Q(I,JM1)-Q(I,JP1))\n B(I) = Q(I,J)+Q(I,1)\n 165 CONTINUE\n CALL COSGEN (JR,1,FNUM,0.5,TCOS)\n CALL TRIX (JR,0,MR,A,BB,C,B,TCOS,D,W)\n DO 166 I=1,MR\n Q(I,1) = Q(I,1)-Q(I,JM1)+B(I)\n 166 CONTINUE\n GO TO 188\nC\nC CASE OF GENERAL N WITH NR = 3 .\nC\n 167 CONTINUE\n DO 168 I=1,MR\n B(I) = Q(I,1)-Q(I,JM1)+Q(I,J)\n 168 CONTINUE\n IF (NROD .NE. 0) GO TO 170\n DO 169 I=1,MR\n II = IP+I\n B(I) = B(I)+P(II)\n 169 CONTINUE\n GO TO 172\n 170 DO 171 I=1,MR\n B(I) = B(I)+Q(I,NLAST)-Q(I,JM2)\n 171 CONTINUE\n 172 CONTINUE\n DO 173 I=1,MR\n T = .5*(Q(I,J)-Q(I,JM1)-Q(I,JP1))\n Q(I,J) = T\n B2(I) = Q(I,NLAST)+T\n B3(I) = Q(I,1)+T\n 173 CONTINUE\n K1 = KR+2*JR\n CALL COSGEN (JR-1,1,0.0,1.0,TCOS(K1+1))\n K2 = K1+JR\n TCOS(K2) = 2.*FLOAT(NP-2)\n K4 = (NP-1)*(3-NP)\n K3 = K2+1-K4\n CALL COSGEN (KR+JR+K4,1,FLOAT(K4)/2.,1.-FLOAT(K4),TCOS(K3))\n K4 = 1-NP/3\n CALL MERGE (TCOS,K1,JR-K4,K2-K4,KR+JR+K4,0)\n IF (NP .EQ. 3) K1 = K1-1\n K2 = KR+JR\n K4 = K1+K2\n CALL COSGEN (KR,1,FNUM2,0.5,TCOS(K4+1))\n K3 = K4+KR\n CALL COSGEN (JR,1,FNUM,0.5,TCOS(K3+1))\n CALL MERGE (TCOS,K4,KR,K3,JR,K1)\n K4 = K3+JR\n CALL COSGEN (LR,1,FNUM2,0.5,TCOS(K4+1))\n CALL MERGE (TCOS,K3,JR,K4,LR,K1+K2)\n CALL COSGEN (KR,1,FNUM2,0.5,TCOS(K3+1))\n K3 = KR\n K4 = KR\n CALL TRI3 (MR,A,BB,C,K,B,B2,B3,TCOS,D,W,W2,W3)\n DO 174 I=1,MR\n B(I) = B(I)+B2(I)+B3(I)\n 174 CONTINUE\n IF (NP .NE. 3) GO TO 175\n TCOS(1) = 2.\n CALL TRIX (1,0,MR,A,BB,C,B,TCOS,D,W)\n 175 DO 176 I=1,MR\n Q(I,J) = Q(I,J)+B(I)\n B(I) = Q(I,1)+Q(I,J)\n 176 CONTINUE\n CALL COSGEN (JR,1,FNUM,0.5,TCOS)\n CALL TRIX (JR,0,MR,A,BB,C,B,TCOS,D,W)\n IF (JR .NE. 1) GO TO 178\n DO 177 I=1,MR\n Q(I,1) = B(I)\n 177 CONTINUE\n GO TO 188\n 178 CONTINUE\n DO 179 I=1,MR\n Q(I,1) = Q(I,1)-Q(I,JM1)+B(I)\n 179 CONTINUE\n GO TO 188\n 180 CONTINUE\nC\nC CASE OF GENERAL N AND NR = 2 .\nC\n DO 181 I=1,MR\n II = IP+I\n B3(I) = 0.\n B(I) = Q(I,1)+P(II)\n Q(I,1) = Q(I,1)-Q(I,JM1)\n B2(I) = Q(I,1)+Q(I,NLAST)\n 181 CONTINUE\n K1 = KR+JR\n K2 = K1+JR\n CALL COSGEN (JR-1,1,0.0,1.0,TCOS(K1+1))\n GO TO (182,183,182),NP\n 182 TCOS(K2) = 2.*FLOAT(NP-2)\n CALL COSGEN (KR,1,0.0,1.0,TCOS(K2+1))\n GO TO 184\n 183 CALL COSGEN (KR+1,1,0.5,0.0,TCOS(K2))\n 184 K4 = 1-NP/3\n CALL MERGE (TCOS,K1,JR-K4,K2-K4,KR+K4,0)\n IF (NP .EQ. 3) K1 = K1-1\n K2 = KR\n CALL COSGEN (KR,1,FNUM2,0.5,TCOS(K1+1))\n K4 = K1+KR\n CALL COSGEN (LR,1,FNUM2,0.5,TCOS(K4+1))\n K3 = LR\n K4 = 0\n CALL TRI3 (MR,A,BB,C,K,B,B2,B3,TCOS,D,W,W2,W3)\n DO 185 I=1,MR\n B(I) = B(I)+B2(I)\n 185 CONTINUE\n IF (NP .NE. 3) GO TO 186\n TCOS(1) = 2.\n CALL TRIX (1,0,MR,A,BB,C,B,TCOS,D,W)\n 186 DO 187 I=1,MR\n Q(I,1) = Q(I,1)+B(I)\n 187 CONTINUE\n 188 CONTINUE\nC\nC START BACK SUBSTITUTION.\nC\n J = NLAST-JR\n DO 189 I=1,MR\n B(I) = Q(I,NLAST)+Q(I,J)\n 189 CONTINUE\n JM2 = NLAST-I2R\n IF (JR .NE. 1) GO TO 191\n DO 190 I=1,MR\n Q(I,NLAST) = 0.\n 190 CONTINUE\n GO TO 195\n 191 CONTINUE\n IF (NROD .NE. 0) GO TO 193\n DO 192 I=1,MR\n II = IP+I\n Q(I,NLAST) = P(II)\n 192 CONTINUE\n IP = IP-MR\n GO TO 195\n 193 DO 194 I=1,MR\n Q(I,NLAST) = Q(I,NLAST)-Q(I,JM2)\n 194 CONTINUE\n 195 CONTINUE\n CALL COSGEN (KR,1,FNUM2,0.5,TCOS)\n CALL COSGEN (LR,1,FNUM2,0.5,TCOS(KR+1))\n CALL TRIX (KR,LR,MR,A,BB,C,B,TCOS,D,W)\n DO 196 I=1,MR\n Q(I,NLAST) = Q(I,NLAST)+B(I)\n 196 CONTINUE\n NLASTP = NLAST\n 197 CONTINUE\n JSTEP = JR\n JR = I2R\n I2R = I2R/2\n IF (JR .EQ. 0) GO TO 210\n JSTART = 1+JR\n KR = KR-JR\n IF (NLAST+JR .GT. N) GO TO 198\n KR = KR-JR\n NLAST = NLAST+JR\n JSTOP = NLAST-JSTEP\n GO TO 199\n 198 CONTINUE\n JSTOP = NLAST-JR\n 199 CONTINUE\n LR = KR-JR\n CALL COSGEN (JR,1,0.5,0.0,TCOS)\n DO 209 J=JSTART,JSTOP,JSTEP\n JM2 = J-JR\n JP2 = J+JR\n IF (J .NE. JR) GO TO 201\n DO 200 I=1,MR\n B(I) = Q(I,J)+Q(I,JP2)\n 200 CONTINUE\n GO TO 203\n 201 CONTINUE\n DO 202 I=1,MR\n B(I) = Q(I,J)+Q(I,JM2)+Q(I,JP2)\n 202 CONTINUE\n 203 CONTINUE\n IF (JR .NE. 1) GO TO 205\n DO 204 I=1,MR\n Q(I,J) = 0.\n 204 CONTINUE\n GO TO 207\n 205 CONTINUE\n JM1 = J-I2R\n JP1 = J+I2R\n DO 206 I=1,MR\n Q(I,J) = .5*(Q(I,J)-Q(I,JM1)-Q(I,JP1))\n 206 CONTINUE\n 207 CONTINUE\n CALL TRIX (JR,0,MR,A,BB,C,B,TCOS,D,W)\n DO 208 I=1,MR\n Q(I,J) = Q(I,J)+B(I)\n 208 CONTINUE\n 209 CONTINUE\n NROD = 1\n IF (NLAST+I2R .LE. N) NROD = 0\n IF (NLASTP .NE. NLAST) GO TO 188\n GO TO 197\n 210 CONTINUE\nC\nC RETURN STORAGE REQUIREMENTS FOR P VECTORS.\nC\n W(1) = IPSTOR\n RETURN\nC\nC REVISION HISTORY---\nC\nC SEPTEMBER 1973 VERSION 1\nC APRIL 1976 VERSION 2\nC JANUARY 1978 VERSION 3\nC DECEMBER 1979 VERSION 3.1\nC FEBRUARY 1985 DOCUMENTATION UPGRADE\nC NOVEMBER 1988 VERSION 3.2, FORTRAN 77 CHANGES\nC-----------------------------------------------------------------------\n END\n", "meta": {"hexsha": "7b6a5453a31a3e76cf22433bcda9daca327c4eb7", "size": 26506, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/src/poistg.f", "max_stars_repo_name": "ipelupessy/omuse", "max_stars_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2020-03-25T10:02:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-18T00:28:35.000Z", "max_issues_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/src/poistg.f", "max_issues_repo_name": "ipelupessy/omuse", "max_issues_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 45, "max_issues_repo_issues_event_min_datetime": "2020-03-03T16:07:16.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-14T09:01:07.000Z", "max_forks_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/src/poistg.f", "max_forks_repo_name": "ipelupessy/omuse", "max_forks_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-03-03T13:28:50.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-26T09:20:02.000Z", "avg_line_length": 30.2579908676, "max_line_length": 72, "alphanum_fraction": 0.4126612842, "num_tokens": 10028, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179043564153, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6697951049068999}} {"text": "\tFUNCTION PR_HGMD ( hght )\nC************************************************************************\nC* PR_HGMD\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes HGTD from HGHT. 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* HGTD = HGHT / 10.\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PR_HGMD ( HGHT )\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*\tHGHT\t\tREAL\t\tHeight in meters\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPR_HGMD\t\tREAL\t\tHeight in decameters\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* I. Graffman/RDS\t11/84 Original source\t\t\t\t*\nC* M. Goodman/RDS \t3/86\tCorrected division error\t\t*\nC* G. Huffman/GSC\t7/88\tDocumentation\t\t\t\t*\nC************************************************************************\n INCLUDE 'GEMPRM.PRM'\n INCLUDE 'ERMISS.FNC'\nC------------------------------------------------------------------------\nC*\tCheck for invalid height.\nC\t\n\tIF ( ERMISS (hght) ) THEN\n\t PR_HGMD = RMISSD \n\t ELSE\n\t PR_HGMD = hght / 10.\n\tEND IF\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "fa365ecb93645e76ed516b3ef2f05eb9b0723197", "size": 1018, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/pr/prhgmd.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/prhgmd.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/prhgmd.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": 28.2777777778, "max_line_length": 73, "alphanum_fraction": 0.4174852652, "num_tokens": 307, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818865, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6697951030827808}} {"text": "! This program uses the bisection algorithm to find a root\nprogram bisect\nimplicit none\nreal a,b,p,f\ninteger i,imax\na=0.\nb=3.\nimax=20\nif (f(a)*f(b) .gt. 0.) then\n write(*,*) 'root not bracketed'\n stop\nendif\ndo i=1,imax\n p=(b+a)/2.\n if (f(a)*f(p) .lt. 0.) then\n b=p\n else\n a=p\n endif\n write(*,*) i,p,f(p)\n write(8,*) i,abs(p-1.)\nenddo\nstop\nend program bisect\n\nfunction f(x)\nimplicit none\nreal x,f\nf=x**5-1.\nreturn\nend function f\n\n", "meta": {"hexsha": "b11a866d99540b0b46ab276f91db138dac9803a4", "size": 443, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Bisection.f90", "max_stars_repo_name": "whisker-rebellion/Fortran", "max_stars_repo_head_hexsha": "65c0e064bcc92f33bc78cc89220a0298b3ee96be", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Bisection.f90", "max_issues_repo_name": "whisker-rebellion/Fortran", "max_issues_repo_head_hexsha": "65c0e064bcc92f33bc78cc89220a0298b3ee96be", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Bisection.f90", "max_forks_repo_name": "whisker-rebellion/Fortran", "max_forks_repo_head_hexsha": "65c0e064bcc92f33bc78cc89220a0298b3ee96be", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 13.4242424242, "max_line_length": 58, "alphanum_fraction": 0.6297968397, "num_tokens": 179, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818865, "lm_q2_score": 0.7371581626286833, "lm_q1q2_score": 0.6697951030827807}} {"text": "module bar\r\n\r\n use Structure\r\n use Matrix_op\r\n use Gauss\r\n\r\n implicit none\r\n\r\n type :: Space_op\r\n\r\n double precision, dimension(:,:), allocatable :: gauss_s ! points and weight matrix.\r\n double precision, dimension(:,:), allocatable :: IntS\r\n double precision, dimension(:,:), allocatable :: B,Bw\r\n double precision, dimension(:,:), allocatable :: Be,Bwe\r\n\r\n double precision, dimension(:,:), allocatable :: He\r\n integer, dimension(:,:), allocatable :: gps\r\n integer, dimension(:,:), allocatable :: Idvs\r\n integer, dimension(:), allocatable :: dof_imposed\r\n integer, dimension(:), allocatable :: dof_free\r\n double precision, dimension(:,:), allocatable :: Melm,Kelm\r\n integer :: comp = 1\r\n\r\n\r\n end type Space_op\r\n\r\n type(Space_op) :: Sop\r\n\r\n\r\n contains\r\n\r\n\r\n\r\n subroutine Space_elm_matrices(I)\r\n\r\n type(Input), intent(inout) :: I\r\n integer :: iter,igp,ind\r\n integer, dimension(1,I%Nx) :: v1,v2\r\n double precision, dimension(I%ngps,1) :: waux\r\n double precision, dimension(I%ngps) :: x\r\n double precision, dimension(I%Nsfs,I%ngps) :: lx,dlx\r\n double precision, dimension(I%ngps,I%Nsfs) :: laux,dlaux\r\n double precision, dimension(I%Tngps,I%n) :: Bw\r\n\r\n ! real, dimension(I%ne,1) :: Felm\r\n\r\n\r\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\n\r\n !! Vector that integrate any function in the space interval Ix=[0,I.L];\r\n\r\n ! Uni_dimensional case\r\n allocate(Sop%IntS(I%Tngps,1))\r\n Sop%gauss_s = gauss_points_weights(I%ngps)\r\n do igp=1,I%ngps\r\n waux(igp,1)=(I%dx/2)*Sop%gauss_s(igp,2)\r\n end do\r\n !print*, \"SHAPE VALUE WAUX:\" , shape(waux)\r\n\r\n !print*, \"HASTA ACA:\", shape(Sop%IntS)\r\n !print*, I%Nx, I%dx\r\n !call show(waux)\r\n\r\n Sop%IntS=kron(ones(I%Nx,1),waux)\r\n !call show(ones(I%Nx,1))\r\n !print*, \"NEPE\"\r\n !call show(Sop%IntS)\r\n\r\n\r\n ! Identification matrix in space:\r\n Sop%Idvs = vertcat( incr(1,I%Nx), incr(2,I%Nx+1) )\r\n !I.Idvs = vertcat(1:I.Nx,2:I.ns)\r\n\r\n ! Linear shape functions in space:\r\n\r\n x = ( (I%dx/2)*Sop%gauss_s(:,1)+I%dx/2 )\r\n !xt = (x)\r\n lx = vertcat(1-x/I%dx,x/I%dx) ! No derivative.\r\n dlx = repmat( reshape( (/-1/I%dx, 1/I%dx/), (/2,1/) ), (/1,I%ngps/) ) ! First derivative.\r\n\r\n\r\n\r\n ! Linear shape functions in space:\r\n\r\n\r\n ! Calculation of the B operator ( eps = B*u):\r\n laux = transpose(lx)\r\n dlaux = transpose(dlx)\r\n allocate(Sop%B(I%Tngps,I%n)) != zeros(I.Ngps,I.ns);\r\n do iter = 1,I%Nx\r\n Sop%B( incr(1+(iter-1)*I%ngps,iter*I%ngps) , incr(iter,iter+1) ) = dlaux\r\n end do\r\n\r\n ! Rigidity matrix calculation:\r\n Sop%Bw = spread(Sop%IntS(:,1), 2, I%n )*Sop%B\r\n !I.K = (I%Hooke*I%A)*( matmul(transpose(Sop%B), Bw)\r\n\r\n ! Elemental operators:\r\n Sop%Be = dlaux\r\n Sop%Bwe = spread( waux(:,1), 2, I%Nsfs )*Sop%Be\r\n\r\n\r\n\r\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\n\r\n ! Elemental matrices assignation:\r\n\r\n allocate( Sop%Melm(2,2) )\r\n allocate( Sop%Kelm(2,2) )\r\n allocate( Sop%He(1,1) )\r\n\r\n Sop%He = I%Hooke ! Elastic hooke tensor.\r\n Sop%Kelm = ( (I%Hooke*I%A)/I%dx )*reshape( (/ 1.0, -1.0, -1.0, 1.0/), (/ 2, 2 /) ) ! Elemental stiffness matrix.\r\n Sop%Melm = ((I%rho*I%A*I%dx)/6)*reshape( (/ 2.0, 1.0, 1.0, 2.0/), (/ 2, 2 /) ) ! Elemental mass matrix.\r\n\r\n\r\n\r\n\r\n\r\n ! Identification matrix in space:\r\n !allocate( Sop%Idvs(2,I%Nx) )\r\n !v1 = incr2(1,I%Nx) ; v2 = incr2(2,I%n)\r\n !Sop%Idvs = vertcat(v1, v2)\r\n\r\n\r\n\r\n ! Dofs fixed and imposed:\r\n\r\n allocate( Sop%dof_imposed(2) )\r\n allocate( Sop%dof_free(I%ns) )\r\n\r\n Sop%dof_imposed = (/1,I%n/)\r\n Sop%dof_free = incr(2,I%n-1)\r\n\r\n\r\n\r\n\r\n\r\n !I%ntc3 = 123 ! Assignation to the \"I\" structure.\r\n !print*, I%ntc3\r\n\r\n\r\n\r\n end subroutine Space_elm_matrices\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nend module bar\r\n", "meta": {"hexsha": "cf62199c550a5868fa33cf1fa65e75a0130d32b6", "size": 3833, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "ROMlab_Fortran/bin/LATIN/bar.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/bar.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/bar.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": 24.5705128205, "max_line_length": 118, "alphanum_fraction": 0.5549178189, "num_tokens": 1268, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178870347122, "lm_q2_score": 0.7371581741774411, "lm_q1q2_score": 0.6697951026314729}} {"text": "C =====================================================================\nC pgm: DDGJC .. Get frm jul-dt, cal-dt (get mo, da)\nC\nC use: CALL DDGJC(J1,Y1,M1,D1)\nC\nC in: J1 ...... day of year (001-366) - INT\nC in: Y1 ...... 4-digit year number - INT\nC out: M1 ...... month number (01-12) - INT\nC out: D1 ...... day number (01-31) - INT\nC\nC lvl: DD1\nC\nC cmt: Alternate algorithm: M1T = (J1T*9 + 269)/275\nC cmt: D1T = J1T - (M1T*275)/9 + 30\nC =====================================================================\n SUBROUTINE DDGJC(J1,Y1,M1,D1)\n\n INTEGER J1,Y1,M1,D1,II,J1T,Y1T,M1T,D1T\nC\nC ================================= RCS keyword statements ==========\n CHARACTER*68 RCSKW1,RCSKW2\n DATA RCSKW1,RCSKW2 / '\n .$Source: /fs/hsmb5/hydro/CVS_root/gorms/snow17/ddgjc.f,v $\n . $', '\n .$Id: ddgjc.f,v 3.0 2009-12-30 16:49:06 zcui Exp $\n . $' /\nC ===================================================================\nC\n\n J1T = J1\n Y1T = Y1\n\n II = 2\n IF ( Y1T.EQ.(Y1T/4)*4\n $ .AND. Y1T.NE.1800\n $ .AND. Y1T.NE.1900\n $ .AND. ( Y1T.LT.2100 .OR. Y1T.EQ.(Y1T/400)*400\n $ .OR. Y1T.NE.(Y1T/100)*100 )\n $ ) II = 1\n\n IF ( Y1T.EQ.1752 .AND. J1T.GT.246 ) J1T = J1T + 11\n\n IF ( J1T .GT. (61-II) ) J1T = J1T + II\n M1T = (J1T*67 + 2012)/2048\n D1T = J1T - (M1T*489)/16 + 30\n\n M1 = M1T\n D1 = D1T\n\n RETURN\n END\n", "meta": {"hexsha": "1b8fd51c3ecea416e62b3324791ec1ee95e39aee", "size": 1640, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "lis/surfacemodels/land/rdhm.3.5.6/snow17/ddgjc.f", "max_stars_repo_name": "KathyNie/LISF", "max_stars_repo_head_hexsha": "5c3e8b94494fac5ff76a1a441a237e32af420d06", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 67, "max_stars_repo_stars_event_min_datetime": "2018-11-13T21:40:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-23T08:11:56.000Z", "max_issues_repo_path": "lis/surfacemodels/land/rdhm.3.5.6/snow17/ddgjc.f", "max_issues_repo_name": "dmocko/LISF", "max_issues_repo_head_hexsha": "08d024d6d5fe66db311e43e78740842d653749f4", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 679, "max_issues_repo_issues_event_min_datetime": "2018-11-13T20:10:29.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T19:55:25.000Z", "max_forks_repo_path": "lis/surfacemodels/land/rdhm.3.5.6/snow17/ddgjc.f", "max_forks_repo_name": "dmocko/LISF", "max_forks_repo_head_hexsha": "08d024d6d5fe66db311e43e78740842d653749f4", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 119, "max_forks_repo_forks_event_min_datetime": "2018-11-08T15:53:35.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-28T10:16:01.000Z", "avg_line_length": 31.5384615385, "max_line_length": 72, "alphanum_fraction": 0.3658536585, "num_tokens": 588, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178944582997, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6697950976104231}} {"text": "subroutine addCountxy(Count,NGrid,thisx,thisy,XX,YY,r_cutoff)\n\timplicit none\n\tinteger, intent(in) :: NGrid\n!f2p intent(in) :: NGrid\n\treal(8), intent(inout), dimension(0:NGrid-1, 0:NGrid-1) :: Count, XX, YY\n!f2p intent(in,out) :: Count, XX, YY\n\treal(8), intent(in) :: thisx, thisy, r_cutoff\n!f2p intent(in) :: thisx, thisy, r_cutoff\n\tinteger :: i,j,xndx(1),yndx(1)\n\tinteger :: xlowndx, ylowndx, xhighndx, yhighndx\n\treal(8) :: dist, dx, dy\n\treal(8), dimension(0:NGrid-1) :: xvec, yvec\n\t\n\tdx = XX(0,1) - XX(0,0) !assumes linspace used to generate spacing\n\tdy = YY(1,0) - YY(0,0)\n\txvec = XX(0,:)\n\tyvec = YY(:,0)\n\txndx = minloc(abs(xvec-thisx))\n\tyndx = minloc(abs(yvec-thisy))\n\t!write(*,*) xndx,yndx,thisx,thisy\n\txlowndx = nint(xndx(1) - (r_cutoff / dx * 2.5))\n\txhighndx = nint(xndx(1) + (r_cutoff / dx * 2.5))\n\tylowndx = nint(yndx(1) - (r_cutoff / dy * 2.5))\n\tyhighndx = nint(yndx(1) + (r_cutoff / dy * 2.5))\n\tif (xlowndx < 0) xlowndx = 0\n\tif (ylowndx < 0) ylowndx = 0\n\tif (xhighndx > NGrid-1) xhighndx = NGrid - 1\n\tif (yhighndx > NGrid-1) yhighndx = Ngrid - 1\n\tdo j = xlowndx, xhighndx\n\t\tdo i = ylowndx, yhighndx\n\t\t\tdist = (thisx-XX(i,j))**2 + (thisy-YY(i,j))**2\n\t\t\tdist = sqrt(dist)\n\t\t\tif (dist .LT. r_cutoff) then\n\t\t\t\tCount(i,j) = Count(i,j) + 1\n\t\t\tend if\n\t\t\t!write(*,*) thisx,thisy, XX(i,j), YY(i,j), dist\n\t\tend do\n\tend do\n\nend subroutine\n\nsubroutine addCountxz(Count,NGrid,thisx,thisz,XX,ZZ,r_cutoff)\n\timplicit none\n\tinteger, intent(in) :: NGrid\n!f2p intent(in) :: NGrid\n\treal(8), intent(inout), dimension(0:NGrid-1, 0:NGrid-1) :: Count, XX, ZZ\n!f2p intent(in,out) :: Count, XX, ZZ\n\treal(8), intent(in) :: thisx, thisz, r_cutoff\n!f2p intent(in) :: thisx, thisz, r_cutoff\n\tinteger :: i,j,xndx(1),zndx(1)\n\tinteger :: xlowndx, zlowndx, xhighndx, zhighndx\n\treal(8) :: dist, dx, dz\n\treal(8), dimension(0:NGrid-1) :: xvec, zvec\n\t\n\tdx = XX(0,1) - XX(0,0) !assumes linspace used to generate spacing\n\tdz = ZZ(1,0) - ZZ(0,0)\n\txvec = XX(0,:)\n\tzvec = ZZ(:,0)\n\txndx = minloc(abs(xvec-thisx))\n\tzndx = minloc(abs(zvec-thisz))\n\t!write(*,*) xndx,yndx,thisx,thisy\n\txlowndx = nint(xndx(1) - (r_cutoff / dx * 2.5))\n\txhighndx = nint(xndx(1) + (r_cutoff / dx * 2.5))\n\tzlowndx = nint(zndx(1) - (r_cutoff / dz * 2.5))\n\tzhighndx = nint(zndx(1) + (r_cutoff / dz * 2.5))\n\tif (xlowndx < 0) xlowndx = 0\n\tif (zlowndx < 0) zlowndx = 0\n\tif (xhighndx > NGrid-1) xhighndx = NGrid - 1\n\tif (zhighndx > NGrid-1) zhighndx = Ngrid - 1\n\tdo j = xlowndx, xhighndx\n\t\tdo i = zlowndx, zhighndx\n\t\t\tdist = (thisx-XX(i,j))**2 + (thisz-ZZ(i,j))**2\n\t\t\tdist = sqrt(dist)\n\t\t\tif (dist .LT. r_cutoff) then\n\t\t\t\tCount(i,j) = Count(i,j) + 1\n\t\t\tend if\n\t\t\t!write(*,*) thisx,thisy, XX(i,j), YY(i,j), dist\n\t\tend do\n\tend do\n\nend subroutine\n\nsubroutine addCountyz(Count,NGrid,thisy,thisz,YY,ZZ,r_cutoff)\n\timplicit none\n\tinteger, intent(in) :: NGrid\n!f2p intent(in) :: NGrid\n\treal(8), intent(inout), dimension(0:NGrid-1, 0:NGrid-1) :: Count, YY, ZZ\n!f2p intent(in,out) :: Count, YY, ZZ\n\treal(8), intent(in) :: thisy, thisz, r_cutoff\n!f2p intent(in) :: thisy, thisz, r_cutoff\n\tinteger :: i,j,yndx(1),zndx(1)\n\tinteger :: ylowndx, zlowndx, yhighndx, zhighndx\n\treal(8) :: dist, dy, dz\n\treal(8), dimension(0:NGrid-1) :: yvec, zvec\n\t\n\tdy = YY(0,1) - YY(0,0) !assumes linspace used to generate spacing\n\tdz = ZZ(1,0) - ZZ(0,0)\n\tyvec = YY(0,:)\n\tzvec = ZZ(:,0)\n\tyndx = minloc(abs(yvec-thisy))\n\tzndx = minloc(abs(zvec-thisz))\n\t!write(*,*) yndx,zndx,thisy,thisz\n\tylowndx = nint(yndx(1) - (r_cutoff / dy * 2.5))\n\tyhighndx = nint(yndx(1) + (r_cutoff / dy * 2.5))\n\tzlowndx = nint(zndx(1) - (r_cutoff / dz * 2.5))\n\tzhighndx = nint(zndx(1) + (r_cutoff / dz * 2.5))\n\tif (ylowndx < 0) ylowndx = 0\n\tif (zlowndx < 0) zlowndx = 0\n\tif (yhighndx > NGrid-1) yhighndx = NGrid - 1\n\tif (zhighndx > NGrid-1) zhighndx = Ngrid - 1\n\tdo j = ylowndx, yhighndx\n\t\tdo i = zlowndx, zhighndx\n\t\t\tdist = (thisy-YY(i,j))**2 + (thisz-ZZ(i,j))**2\n\t\t\tdist = sqrt(dist)\n\t\t\tif (dist .LT. r_cutoff) then\n\t\t\t\tCount(i,j) = Count(i,j) + 1\n\t\t\tend if\n\t\t\t!write(*,*) thisy,thisz, YY(i,j), ZZ(i,j), dist\n\t\tend do\n\tend do\n\nend subroutine", "meta": {"hexsha": "f7a13087ee8359c41b405318fb01eb8cf12663c7", "size": 4024, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "2d_density_projection/density_fortran.f90", "max_stars_repo_name": "jhaydak3/ZIF", "max_stars_repo_head_hexsha": "cbebb31e9c6fcc0b077bc4eef5bc752da7dfb89c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2d_density_projection/density_fortran.f90", "max_issues_repo_name": "jhaydak3/ZIF", "max_issues_repo_head_hexsha": "cbebb31e9c6fcc0b077bc4eef5bc752da7dfb89c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2d_density_projection/density_fortran.f90", "max_forks_repo_name": "jhaydak3/ZIF", "max_forks_repo_head_hexsha": "cbebb31e9c6fcc0b077bc4eef5bc752da7dfb89c", "max_forks_repo_licenses": ["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.9836065574, "max_line_length": 73, "alphanum_fraction": 0.6247514911, "num_tokens": 1697, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818987, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6697640536097852}} {"text": "!********************************************************************************\n! SPECIAL_POLY: Test FPML Compensated Polishing on Special Polynomials\n! Author: Thomas R. Cameron, Davidson College\n! Last Modified: 25 April 2018\n!********************************************************************************\n! The accuracy of FPML with compensated polishing routine is tested on several\n! special polynomial. \n!********************************************************************************\nprogram special_poly\n use fpml, only : main\n\tuse fpml_comp, only: main_comp\n\tuse fpml_quad, only: qp, main_quad\n use mproutines\n\timplicit none\n ! testing variables\n integer :: deg, j, poly_num\n complex(kind=dp), dimension(:), allocatable :: exact_roots\n ! FPML variables\n integer, parameter :: itmax = 30\n integer, allocatable :: conv(:)\n real(kind=dp), allocatable :: berr(:), cond(:)\n\treal(kind=qp), allocatable\t\t\t\t\t:: berr_quad(:), cond_quad(:)\n complex(kind=dp), allocatable :: p(:), roots(:)\n\tcomplex(kind=qp), allocatable\t\t\t\t:: p_quad(:), roots_quad(:)\n \n ! Testing: special polynomials\n open(unit=1,file=\"data_files/special_poly.dat\")\n write(1,'(A)') 'Poly No., FPML, FPML-Quad, FPML-Comp'\n do poly_num=1,35\n write(1, '(I10,A)', advance='no') poly_num, ', '\n ! make polynomial\n call make_poly(poly_num, deg, exact_roots, p)\n\t\t! allocate\n allocate(roots(deg), berr(deg), cond(deg), conv(deg))\n\t\tallocate(p_quad(deg+1), roots_quad(deg), berr_quad(deg), cond_quad(deg))\n ! FPML, No Polish\n call main(p, deg, roots, berr, cond, conv, itmax)\n write(1, '(ES15.2, A)', advance='no') max_rel_err(roots,exact_roots,deg), ', '\n\t\t! FPML, Quad\n\t\tp_quad = p\n call main_quad(p_quad, deg, roots_quad, berr_quad, cond_quad, conv, itmax)\n\t\troots = roots_quad\n\t\twrite(1, '(ES15.2, A)', advance='no') max_rel_err(roots,exact_roots,deg), ', '\n ! FPML, Compensated Laguerre Polish\n call main_comp(p, deg, roots, itmax)\n write(1, '(ES15.2, A)') max_rel_err(roots,exact_roots,deg)\n ! deallocate\n deallocate(p, exact_roots, roots, berr, cond, conv)\n\t\tdeallocate(p_quad, roots_quad, berr_quad, cond_quad)\n end do\n \n ! close file\n close(1)\n \ncontains\n !************************************************\n ! make_poly *\n !************************************************\n ! Make special polynomial corresponding to poly_num.\n !************************************************\n subroutine make_poly(poly_num, deg, exact_roots, p)\n implicit none\n ! argument variables\n integer, intent(in) :: poly_num\n integer, intent(out) :: deg\n complex(kind=dp), allocatable, intent(out) :: exact_roots(:), p(:)\n ! local variables\n integer :: j\n real(kind=dp), parameter :: pi = 3.141592653589793_dp\n \n select case (poly_num)\n case(1)\n ! Poly 1: Wilkinson deg 10\n deg = 10\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n exact_roots = (/ (cmplx(j,0,kind=dp), j=1,deg)/)\n ! polynomial\n\t\t\tp(deg+1) = cmplx(1.0_dp,0.0_dp,kind=dp)\n call rootCoeffCplx(deg,exact_roots,p)\n case(2)\n ! Poly 2: Wilkinson deg 15\n deg = 15\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n exact_roots = (/ (cmplx(j,0,kind=dp), j=1,deg)/)\n ! polynomial\n\t\t\tp(deg+1) = cmplx(1.0_dp,0.0_dp,kind=dp)\n call rootCoeffCplx(deg,exact_roots,p)\n case(3)\n ! Poly 3: Wilkinson deg 20\n deg = 20\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n exact_roots = (/ (cmplx(j,0,kind=dp), j=1,deg)/)\n ! polynomial\n\t\t\tp(deg+1) = cmplx(1.0_dp,0.0_dp,kind=dp)\n call rootCoeffCplx(deg,exact_roots,p)\n case(4)\n ! Poly 4: scaled and shifted Wilkinson deg 20\n deg = 20\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n exact_roots = (/ (cmplx(dble(-21+2*(j-1))/10d0,0,kind=dp), j=1,deg)/)\n ! polynomial\n\t\t\tp(deg+1) = cmplx(1.0_dp,0.0_dp,kind=dp)\n call rootCoeffCplx(deg,exact_roots,p)\n case(5)\n ! Poly 5: reverse Wilkinson deg 10\n deg = 10\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n exact_roots = (/ (cmplx(1d0/dble(j),0,kind=dp), j=1,deg)/)\n ! polynomial\n\t\t\tp(deg+1) = cmplx(1.0_dp,0.0_dp,kind=dp)\n call rootCoeffCplx(deg,exact_roots,p)\n case(6)\n ! Poly 6: reverse Wilkinson deg 15\n deg = 15\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n exact_roots = (/ (cmplx(1d0/dble(j),0,kind=dp), j=1,deg)/)\n ! polynomial\n\t\t\tp(deg+1) = cmplx(1.0_dp,0.0_dp,kind=dp)\n call rootCoeffCplx(deg,exact_roots,p)\n case(7)\n ! Poly 7: reverse Wilkinson deg 20\n deg = 20\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n exact_roots = (/ (cmplx(1d0/dble(j),0,kind=dp), j=1,deg)/)\n ! polynomial\n\t\t\tp(deg+1) = cmplx(1.0_dp,0.0_dp,kind=dp)\n call rootCoeffCplx(deg,exact_roots,p)\n case(8)\n ! Poly 8: prescribed roots of varying scale deg 20\n deg = 20\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n exact_roots = (/ (cmplx(2d0**(-10+(j-1)),0,kind=dp), j=1,deg)/)\n ! polynomial\n\t\t\tp(deg+1) = cmplx(1.0_dp,0.0_dp,kind=dp)\n call rootCoeffCplx(deg,exact_roots,p)\n case(9)\n ! Poly 9: prescribed roots of varying scale -3 deg 20\n deg = 20\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n exact_roots = (/ (cmplx(2d0**(-10+(j-1))-3d0,0,kind=dp), j=1,deg)/)\n ! polynomial\n p(deg+1) = cmplx(1.0_dp,0.0_dp,kind=dp)\n call rootCoeffCplx(deg,exact_roots,p)\n case(10)\n ! Poly 10: Chebyshev polynomial deg 20\n deg = 20\n allocate(exact_roots(deg), p(deg+1))\n p(1) = 1d0\n p(2) = 0d0\n p(3) = -200d0\n p(4) = 0d0\n p(5) = 6600d0\n p(6) = 0d0\n p(7) = -84480d0\n p(8) = 0d0\n p(9) = 549120d0\n p(10) = 0d0\n p(11) = -2050048d0\n p(12) = 0d0\n p(13) = 4659200d0\n p(14) = 0d0\n p(15) = -6553600d0\n p(16) = 0d0\n p(17) = 5570560d0\n p(18) = 0d0\n p(19) = -2621440d0\n p(20) = 0d0\n p(21) = 524288d0\n exact_roots = (/ (cmplx(cos((2.0_dp*j-1.0_dp)*pi/(2.0_dp*deg)),0,kind=dp), j=1,deg)/)\n case(11)\n ! Poly 11: z^i for i=0,20\n deg = 20\n allocate(exact_roots(deg), p(deg+1))\n p = (/ (cmplx(1,0,kind=dp), j=1,deg+1)/)\n exact_roots = (/ (cmplx(cos(2*j*pi/21d0),sin(2*j*pi/21d0),kind=dp), j=1,deg)/)\n case(12)\n ! Poly 12: C. Traverso 24 MPSolve\n deg = 24\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n exact_roots(1) = cmplx(-3.52d2, 0d0, kind=dp)\n exact_roots(2) = cmplx(-3.52d2, 0d0, kind=dp)\n exact_roots(3) = cmplx(-2.8371450777d2, -2.9920517772d2, kind=dp)\n exact_roots(4) = cmplx(-2.8371450777d2, 2.9920517772d2, kind=dp)\n exact_roots(5) = cmplx(-2.7867414048d2, 6.1005469197d2, kind=dp)\n exact_roots(6) = cmplx(-2.7867414048d2, -6.1005469197d2, kind=dp)\n exact_roots(7) = cmplx(-2.74892372d2, 0d0, kind=dp)\n exact_roots(8) = cmplx(-2.014171531d2, 0d0, kind=dp)\n exact_roots(9) = cmplx(-1.255366582d2, 0d0, kind=dp)\n exact_roots(10) = cmplx(-9.599999999d1, 0d0, kind=dp)\n exact_roots(11) = cmplx(-8.8692435121d1, 5.5009607430d2, kind=dp)\n exact_roots(12) = cmplx(-8.869243512d1, -5.5009607430d2, kind=dp)\n exact_roots(13) = cmplx(-1.6000000000d1, 0d0, kind=dp)\n exact_roots(14) = cmplx(8.23178509855d1, 0d0, kind=dp)\n exact_roots(15) = cmplx(8.8692435121d1, -5.50096074303d2, kind=dp)\n exact_roots(16) = cmplx(8.8692435121d1, 5.5009607430d2, kind=dp)\n exact_roots(17) = cmplx(1.9293739373d2, 1.60865921259d3, kind=dp)\n exact_roots(18) = cmplx(1.929373937d2, -1.6086592125d3, kind=dp)\n exact_roots(19) = cmplx(2.0141715312d2, 0d0, kind=dp)\n exact_roots(20) = cmplx(2.7489237213d2, 0d0, kind=dp)\n exact_roots(21) = cmplx(7.52d2, 0d0, kind=dp)\n exact_roots(22) = cmplx(7.52d2, 0d0, kind=dp)\n exact_roots(23) = cmplx(9.1106065d2, 1.5722d0, kind=dp)\n exact_roots(24) = cmplx(9.1106065d2, -1.5722d0, kind=dp)\n ! polynomial\n p(1) = -54765291428198020791747503747742749163073958404455022926495744d0\n p(2) = -4052135566767965847649766745769409681058667331648450681896960d0\n p(3) = -31969984081155943263834965670035075493639295858977076674560d0\n p(4) = 575060225471570237690073740639182419333523437771848417280d0\n p(5) = 7337981286595499156409929740830030318565357725459415040d0\n p(6) = 6611223380089859336490797585290455483968982077145088d0\n p(7) = -195514288747757987122118583800597358656801082441728d0\n p(8) = -726907419403715013562762609680450059293446635520d0\n p(9) = 197178719520196724204974332265013056299335680d0\n p(10) = 5968852409133617129605588058090797893943296d0\n p(11) = 16576506891508825500182005531742679597056d0\n p(12) = 23375026506968330494765978581548924928d0\n p(13) = 2206941937668751746514177591607296d0\n p(14) = -75617855277818001758431020580864d0\n p(15) = -204797687173976372829472423936d0\n p(16) = -143150263927579584306872320d0\n p(17) = 20214880144364480233472d0\n p(18) = 453786251090072698880d0\n p(19) = 1265052493274939392d0\n p(20) = -968887355572224d0\n p(21) = 1015406084096d0\n p(22) = -3949133824d0\n p(23) = 3284992d0\n p(24) = -1728d0\n p(25) = 1d0\n case(13)\n ! Poly 13: Mandelbrot 31 MPSolve\n deg = 31\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n exact_roots(1) = cmplx(-1.996376137,0d0,kind=dp)\n exact_roots(2) = cmplx(-1.966773216,0d0,kind=dp)\n exact_roots(3) = cmplx(-1.907280091,0d0,kind=dp)\n exact_roots(4) = cmplx(-1.772892903,0d0,kind=dp)\n exact_roots(5) = cmplx(-1.754877666,0d0,kind=dp)\n exact_roots(6) = cmplx(-1.47601464272,0d0,kind=dp)\n exact_roots(7) = cmplx(-1.284084925525, 4.272688960406d-1,kind=dp)\n exact_roots(8) = cmplx(-1.284084925525,-4.272688960406d-1,kind=dp)\n exact_roots(9) = cmplx(-1.138000666650,-2.403324012620d-1,kind=dp)\n exact_roots(10) = cmplx(-1.138000666650, 2.403324012620d-1,kind=dp)\n exact_roots(11) = cmplx(-1d0,0d0,kind=dp)\n exact_roots(12) = cmplx(-5.968916446451269d-1, 6.629807445770295d-1,kind=dp)\n exact_roots(13) = cmplx(-5.968916446451269d-1,-6.629807445770295d-1,kind=dp)\n exact_roots(14) = cmplx(-2.17526747030511d-1,-1.11445426587329,kind=dp)\n exact_roots(15) = cmplx(-2.17526747030511d-1, 1.11445426587329,kind=dp)\n exact_roots(16) = cmplx(-1.6359826155202d-1, 1.09778064288827,kind=dp)\n exact_roots(17) = cmplx(-1.6359826155202d-1,-1.09778064288827,kind=dp)\n exact_roots(18) = cmplx(-1.225611668766536d-1,-7.4486176661974423d-1,kind=dp)\n exact_roots(19) = cmplx(-1.225611668766536d-1, 7.4486176661974423d-1,kind=dp)\n exact_roots(20) = cmplx(-1.13418655949436d-1,-8.605694725015730d-1,kind=dp)\n exact_roots(21) = cmplx(-1.13418655949436d-1,8.605694725015730d-1,kind=dp)\n exact_roots(22) = cmplx(-1.5570386020902d-2, 1.020497366498289d0,kind=dp)\n exact_roots(23) = cmplx(-1.5570386020902d-2,-1.020497366498289d0,kind=dp)\n exact_roots(24) = cmplx(3.59892739012579001d-1, 6.84762020211812856d-1,kind=dp)\n exact_roots(25) = cmplx(3.59892739012579001d-1,-6.84762020211812856d-1,kind=dp)\n exact_roots(26) = cmplx(3.8900684056977123543d-1,-2.1585065087081910777d-1,kind=dp)\n exact_roots(27) = cmplx(3.8900684056977123543d-1, 2.1585065087081910777d-1,kind=dp)\n exact_roots(28) = cmplx(3.96534570032415023d-1, 6.04181810488988837d-1,kind=dp)\n exact_roots(29) = cmplx(3.96534570032415023d-1,-6.04181810488988837d-1,kind=dp)\n exact_roots(30) = cmplx(4.433256333996235387d-1, 3.729624166628465083d-1,kind=dp)\n exact_roots(31) = cmplx(4.433256333996235387d-1,-3.729624166628465083d-1,kind=dp)\n ! polynomial\n p(1) = 1d0\n p(2) = 1d0\n p(3) = 2d0\n p(4) = 5d0\n p(5) = 14d0\n p(6) = 42d0\n p(7) = 100d0\n p(8) = 221d0\n p(9) = 470d0\n p(10) = 958d0\n p(11) = 1860d0\n p(12)= 3434d0\n p(13) = 6036d0\n p(14) = 10068d0\n p(15) = 15864d0\n p(16) = 23461d0\n p(17) = 32398d0\n p(18) = 41658d0\n p(19) = 49700d0\n p(20) = 54746d0\n p(21) = 55308d0\n p(22) = 50788d0\n p(23) = 41944d0\n p(24) = 30782d0\n p(25) = 19788d0\n p(26) = 10948d0\n p(27) = 5096d0\n p(28) = 1932d0\n p(29) = 568d0\n p(30) = 120d0\n p(31) = 16d0 \n p(32) = 1d0\n case(14)\n ! Poly 14: Mandelbrot 63 MPSolve\n deg = 63\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n exact_roots(1) = cmplx(-1.999095682327018473210d0,0d0,kind=dp)\n exact_roots(2) = cmplx(-1.9918141725491222157325609498622881d0,0d0,kind=dp)\n exact_roots(3) = cmplx(-1.977179587006257387346088520662828616836d0,0d0,kind=dp)\n exact_roots(4) = cmplx(-1.953705894284396245427622199013653238901d0,0d0,kind=dp)\n exact_roots(5) = cmplx(-1.927147709363950262460068188946594278007d0,0d0,kind=dp)\n exact_roots(6) = cmplx(-1.8848035715866817923294780929158396496359d0,0d0,kind=dp)\n exact_roots(7) = cmplx(-1.8323152027512291920848975260425181432293d0,0d0,kind=dp)\n exact_roots(8) = cmplx(-1.76926167027683114607548022863625740038777d0, &\n 5.6919500395600315304900187298015859319654d-2,kind=dp)\n exact_roots(9) = cmplx(-1.76926167027683114607548022863625740038777d0, &\n -5.6919500395600315304900187298015859319654d-2,kind=dp)\n exact_roots(10) = cmplx(-1.674066091474787971565296029172325596206403d0,0d0,kind=dp)\n exact_roots(11) = cmplx(-1.5748891397523009698199655524959742837719482d0,0d0,kind=dp)\n exact_roots(12) = cmplx(-1.408446485740072654917577008805998851928020904d0, &\n -1.36171997304659915684707793608163610038822995d-1,kind=dp)\n exact_roots(13) = cmplx(-1.408446485740072654917577008805998851928020904d0, &\n 1.36171997304659915684707793608163610038822995d-1,kind=dp)\n exact_roots(14) = cmplx(-1.29255806103352208716418470636149411998013630326d0, &\n 4.3819881608663183712973712432734844004535476504d-1,kind=dp)\n exact_roots(15) = cmplx(-1.29255806103352208716418470636149411998013630326d0, &\n -4.3819881608663183712973712432734844004535476504d-1,kind=dp)\n exact_roots(16) = cmplx(-1.26228728143847254301011194120806575232050489502d0, &\n 4.0810432411269038329016065742601506306041169168d-1,kind=dp)\n exact_roots(17) = cmplx(-1.26228728143847254301011194120806575232050489502d0, &\n -4.0810432411269038329016065742601506306041169168d-1,kind=dp)\n exact_roots(18) = cmplx(-1.25273588401203794629581100256433997387062287256d0, &\n -3.4247064788975089386187578687092843396383393805d-1,kind=dp)\n exact_roots(19) = cmplx(-1.25273588401203794629581100256433997387062287256d0, &\n 3.4247064788975089386187578687092843396383393805d-1,kind=dp)\n exact_roots(20) = cmplx(-1.02819385245481759930249745596731843328070508279421d0, &\n -3.61376517118561592479460832997830315786692639704085d-1,kind=dp)\n exact_roots(21) = cmplx(-1.02819385245481759930249745596731843328070508279421d0, &\n 3.61376517118561592479460832997830315786692639704085d-1,kind=dp)\n exact_roots(22) = cmplx(-6.23532485956252757990016587001026776428072703359878868d-1, &\n 6.81064414225239608090835812686561539088332735217609127d-1,kind=dp)\n exact_roots(23) = cmplx(-6.23532485956252757990016587001026776428072703359878868d-1, &\n -6.81064414225239608090835812686561539088332735217609127d-1,kind=dp)\n exact_roots(24) = cmplx(-6.2243629504129358796016350694723840189750985673649588591d-1, &\n 4.2487843647562918431157443880525338683545992964599689876d-1,kind=dp)\n exact_roots(25) = cmplx(-6.2243629504129358796016350694723840189750985673649588591d-1, &\n -4.2487843647562918431157443880525338683545992964599689876d-1,kind=dp)\n exact_roots(26) = cmplx(-5.308278048599427289214772971196026578135170949646890946d-1, &\n 6.682887255592057714440924655647011851367651843270734380d-1,kind=dp)\n exact_roots(27) = cmplx(-5.308278048599427289214772971196026578135170949646890946d-1, &\n -6.682887255592057714440924655647011851367651843270734380d-1,kind=dp)\n exact_roots(28) = cmplx(-2.72102461488938894219383324518026874585894699621947085d-1, &\n -8.42364690294128145503155708242929569550778268698265965d-1,kind=dp)\n exact_roots(29) = cmplx(-2.72102461488938894219383324518026874585894699621947085d-1, &\n 8.42364690294128145503155708242929569550778268698265965d-1,kind=dp)\n exact_roots(30) = cmplx(-2.24915951286740054685326255204118310792682454680693d-1, &\n 1.11626015745499183500126825424467009109873946082435d0,kind=dp)\n exact_roots(31) = cmplx(-2.24915951286740054685326255204118310792682454680693d-1, &\n -1.11626015745499183500126825424467009109873946082435d0,kind=dp)\n exact_roots(32) = cmplx(-2.0728383545566641282413385018667121332401155604017d-1, &\n 1.11748077249496291137377567312207879579746389236127d0,kind=dp)\n exact_roots(33) = cmplx(-2.0728383545566641282413385018667121332401155604017d-1, &\n -1.11748077249496291137377567312207879579746389236127d0,kind=dp)\n exact_roots(34) = cmplx(-1.7457822113571696945156643266162905020167505710204d-1, &\n 1.07142767145403118922964631021955987671322451961088d0,kind=dp)\n exact_roots(35) = cmplx(-1.7457822113571696945156643266162905020167505710204d-1, &\n -1.07142767145403118922964631021955987671322451961088d0,kind=dp)\n exact_roots(36) = cmplx(-1.57516053475965356164335109644674141293297577896685d-1, &\n -1.10900651411360717797175198615475582901468585712356d0,kind=dp) \n exact_roots(37) = cmplx(-1.57516053475965356164335109644674141293297577896685d-1, &\n 1.10900651411360717797175198615475582901468585712356d0,kind=dp)\n exact_roots(38) = cmplx(-1.274999735463630001995395653459879637298616757217284d-1, &\n 9.874609094894567922074076807929788675642068522522938d-1,kind=dp)\n exact_roots(39) = cmplx(-1.274999735463630001995395653459879637298616757217284d-1, &\n -9.874609094894567922074076807929788675642068522522938d-1,kind=dp)\n exact_roots(40) = cmplx(-1.42334819203540667677618453136202688358025283954839d-2, &\n -1.0329147752136441093950134026551104360994260360822540d0,kind=dp)\n exact_roots(41) = cmplx(-1.42334819203540667677618453136202688358025283954839d-2, &\n 1.0329147752136441093950134026551104360994260360822540d0,kind=dp)\n exact_roots(42) = cmplx(-6.98356849626139181796649107548406610452886379651341d-3, &\n -1.0036038622882895485307049669513531297649273745391915d0,kind=dp)\n exact_roots(43) = cmplx(-6.98356849626139181796649107548406610452886379651341d-3, &\n 1.0036038622882895485307049669513531297649273745391915d0,kind=dp)\n exact_roots(44) = cmplx( 1.4895466603687646529815779208794106185666477731693128d-2, &\n -8.481487619084165277193311117832376290806619901265058603d-1,kind=dp)\n exact_roots(45) = cmplx( 1.4895466603687646529815779208794106185666477731693128d-2, &\n 8.481487619084165277193311117832376290806619901265058603d-1,kind=dp)\n exact_roots(46) = cmplx( 1.211927861059064863147044434105037593859287800520963579338d-1, &\n 6.1061169221075421167538724415035774824319702690063863369691d-1,kind=dp)\n exact_roots(47) = cmplx( 1.211927861059064863147044434105037593859287800520963579338d-1, &\n -6.1061169221075421167538724415035774824319702690063863369691d-1,kind=dp)\n exact_roots(48) = cmplx( 3.52482539722363278193253964052161589243593334212239870706d-1, &\n -6.98337239583330331258141954760484537633150485928512286760d-1,kind=dp)\n exact_roots(49) = cmplx( 3.52482539722363278193253964052161589243593334212239870706d-1, &\n 6.98337239583330331258141954760484537633150485928512286760d-1,kind=dp)\n exact_roots(50) = cmplx( 3.7600868184676755970480431772902286888800357334637481632029182d-1, &\n -1.4474937132163286474711018201298830556966056842762643026975894d-1,kind=dp)\n exact_roots(51) = cmplx( 3.7600868184676755970480431772902286888800357334637481632029182d-1, &\n 1.4474937132163286474711018201298830556966056842762643026975894d-1,kind=dp)\n exact_roots(52) = cmplx( 3.76893240379311323690004017968512473363482317941533875341d-1, &\n 6.78568693190448141957540792996773280196881194582788907016d-1,kind=dp)\n exact_roots(53) = cmplx( 3.76893240379311323690004017968512473363482317941533875341d-1, &\n -6.78568693190448141957540792996773280196881194582788907016d-1,kind=dp)\n exact_roots(54) = cmplx( 3.865391765961580265082930869043677799284877313516569138807d-1, &\n 5.693247113031029032137923571351905081619323911951388853856d-1,kind=dp)\n exact_roots(55) = cmplx( 3.865391765961580265082930869043677799284877313516569138807d-1, &\n -5.693247113031029032137923571351905081619323911951388853856d-1,kind=dp)\n exact_roots(56) = cmplx( 4.12916024722700479197334566382612257174765142865547121703d-1, &\n 6.148067601433856949545497204007997358291659758563137777616d-1,kind=dp)\n exact_roots(57) = cmplx( 4.12916024722700479197334566382612257174765142865547121703d-1, &\n -6.148067601433856949545497204007997358291659758563137777616d-1,kind=dp)\n exact_roots(58) = cmplx( 4.3237619264199450782466964808692137388785063987699403620424125d-1, &\n 2.267599044353486186978765599716989721202321914603899690444951d-1,kind=dp)\n exact_roots(59) = cmplx( 4.3237619264199450782466964808692137388785063987699403620424125d-1, &\n -2.267599044353486186978765599716989721202321914603899690444951d-1,kind=dp)\n exact_roots(60) = cmplx( 4.52774498724915493508803077732546131473562000961307327749350d-1, &\n -3.96170128033165002412596877271155937712569079351815707744770d-1,kind=dp)\n exact_roots(61) = cmplx( 4.52774498724915493508803077732546131473562000961307327749350d-1, &\n 3.96170128033165002412596877271155937712569079351815707744770d-1,kind=dp)\n exact_roots(62) = cmplx( 4.56823285823316651283953236253270107801699459631329688710054d-1, &\n 3.47758700883481983632188723200264206004781117755664551397643d-1,kind=dp)\n exact_roots(63) = cmplx( 4.56823285823316651283953236253270107801699459631329688710054d-1, &\n -3.47758700883481983632188723200264206004781117755664551397643d-1,kind=dp) \n ! polynomial\n p(1) = 1d0\n p(2) = 1d0\n p(3) = 2d0\n p(4) = 5d0\n p(5) = 14d0\n p(6) = 42d0\n p(7) = 132d0\n p(8) = 365d0\n p(9) = 950d0\n p(10) = 2398d0\n p(11) = 5916d0\n p(12) = 14290d0\n p(13) = 33708d0\n p(14) = 77684d0\n p(15) = 175048d0\n p(16) = 385741d0\n p(17) = 831014d0\n p(18) = 1749654d0\n p(19) = 3598964d0\n p(20) = 7228014d0\n p(21) = 14162220d0\n p(22) = 27049196d0\n p(23) = 50323496d0\n p(24) = 91143114d0\n p(25) = 160617860d0\n p(26) = 275276716d0\n p(27) = 458591432d0\n p(28) = 742179284d0\n p(29) = 1166067016d0\n p(30) = 1777171560d0\n p(31) = 2625062128d0\n p(32) = 3754272037d0\n p(33) = 5193067630d0\n p(34) = 6939692682d0\n p(35) = 8948546308d0\n p(36) = 11120136162d0\n p(37) = 13299362332d0\n p(38) = 15286065700d0\n p(39) = 16859410792d0\n p(40) = 17813777994d0\n p(41) = 17999433372d0\n p(42) = 17357937708d0\n p(43) = 15941684776d0\n p(44) = 13910043524d0\n p(45) = 11500901864d0\n p(46) = 8984070856d0\n p(47) = 6609143792d0\n p(48) = 4562339774d0\n p(49) = 2943492972d0\n p(50) = 1766948340d0\n p(51) = 981900168d0\n p(52) = 502196500d0\n p(53) = 234813592d0\n p(54) = 99582920d0\n p(55) = 37945904d0\n p(56) = 12843980d0\n p(57) = 3807704d0\n p(58) = 971272d0\n p(59) = 208336d0\n p(60) = 36440d0\n p(61) = 4976d0\n p(62) = 496d0\n p(63) = 32d0\n p(64) = 1d0\n case(15)\n ! Poly 15: Jenkins Traub p1(z) with a=1e-8\n deg = 3\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n exact_roots(1) = cmplx(1d-8,0d0,kind=dp)\n exact_roots(2) = cmplx(-1d-8,0d0,kind=dp)\n exact_roots(3) = cmplx(1d0,0d0,kind=dp)\n ! polynomial\n p(deg+1) = cmplx(1.0_dp,0.0_dp,kind=dp)\n call rootCoeffCplx(deg,exact_roots,p)\n case(16)\n ! Poly 16: Jenkins Traub p1(z) with a=1e-15\n deg = 3\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n exact_roots(1) = cmplx(1d-15,0d0,kind=dp)\n exact_roots(2) = cmplx(-1d-15,0d0,kind=dp)\n exact_roots(3) = cmplx(1d0,0d0,kind=dp)\n ! polynomial\n p(deg+1) = cmplx(1.0_dp,0.0_dp,kind=dp)\n call rootCoeffCplx(deg,exact_roots,p)\n case(17)\n ! Poly 17: Jenkins Traub p1(z) with a=1e+8\n deg = 3\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n exact_roots(1) = cmplx(1d+8,0d0,kind=dp)\n exact_roots(2) = cmplx(-1d+8,0d0,kind=dp)\n exact_roots(3) = cmplx(1d0,0d0,kind=dp)\n ! polynomial\n p(deg+1) = cmplx(1.0_dp,0.0_dp,kind=dp)\n call rootCoeffCplx(deg,exact_roots,p)\n case(18)\n ! Poly 18: Jenkins Traub p1(z) with a=1e+15\n deg = 3\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n exact_roots(1) = cmplx(1d+15,0d0,kind=dp)\n exact_roots(2) = cmplx(-1d+15,0d0,kind=dp)\n exact_roots(3) = cmplx(1d0,0d0,kind=dp)\n ! polynomial\n p(deg+1) = cmplx(1.0_dp,0.0_dp,kind=dp)\n call rootCoeffCplx(deg,exact_roots,p)\n case(19)\n ! Poly 19: Jenkins Traub p3(z) deg 10\n deg = 10\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n exact_roots(1) = cmplx(1d-1,0d0,kind=dp)\n exact_roots(2) = cmplx(1d-2,0d0,kind=dp)\n exact_roots(3) = cmplx(1d-3,0d0,kind=dp)\n exact_roots(4) = cmplx(1d-4,0d0,kind=dp)\n exact_roots(5) = cmplx(1d-5,0d0,kind=dp)\n exact_roots(6) = cmplx(1d-6,0d0,kind=dp)\n exact_roots(7) = cmplx(1d-7,0d0,kind=dp)\n exact_roots(8) = cmplx(1d-8,0d0,kind=dp)\n exact_roots(9) = cmplx(1d-9,0d0,kind=dp)\n exact_roots(10) = cmplx(1d-10,0d0,kind=dp)\n ! polynomial\n p(deg+1) = cmplx(1.0_dp,0.0_dp,kind=dp)\n call rootCoeffCplx(deg,exact_roots,p)\n case(20)\n ! Poly 20: Jenkins Traub p3(z) deg 20\n deg = 20\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n exact_roots(1) = cmplx(1d-1,0d0,kind=dp)\n exact_roots(2) = cmplx(1d-2,0d0,kind=dp)\n exact_roots(3) = cmplx(1d-3,0d0,kind=dp)\n exact_roots(4) = cmplx(1d-4,0d0,kind=dp)\n exact_roots(5) = cmplx(1d-5,0d0,kind=dp)\n exact_roots(6) = cmplx(1d-6,0d0,kind=dp)\n exact_roots(7) = cmplx(1d-7,0d0,kind=dp)\n exact_roots(8) = cmplx(1d-8,0d0,kind=dp)\n exact_roots(9) = cmplx(1d-9,0d0,kind=dp)\n exact_roots(10) = cmplx(1d-10,0d0,kind=dp)\n exact_roots(11) = cmplx(1d-11,0d0,kind=dp)\n exact_roots(12) = cmplx(1d-12,0d0,kind=dp)\n exact_roots(13) = cmplx(1d-13,0d0,kind=dp)\n exact_roots(14) = cmplx(1d-14,0d0,kind=dp)\n exact_roots(15) = cmplx(1d-15,0d0,kind=dp)\n exact_roots(16) = cmplx(1d-16,0d0,kind=dp)\n exact_roots(17) = cmplx(1d-17,0d0,kind=dp)\n exact_roots(18) = cmplx(1d-18,0d0,kind=dp)\n exact_roots(19) = cmplx(1d-19,0d0,kind=dp)\n exact_roots(20) = cmplx(1d-20,0d0,kind=dp)\n ! polynomial\n p(deg+1) = cmplx(1.0_dp,0.0_dp,kind=dp)\n call rootCoeffCplx(deg,exact_roots,p)\n case(21)\n ! Poly 21: Jenkins Traub p4(z)\n deg = 6\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n exact_roots(1) = 0.1_dp\n exact_roots(2) = 0.1_dp\n exact_roots(3) = 0.1_dp\n exact_roots(4) = 0.5_dp\n exact_roots(5) = 0.6_dp\n exact_roots(6) = 0.7_dp\n ! polynomial\n p(deg+1) = cmplx(1.0_dp,0.0_dp,kind=dp)\n call rootCoeffCplx(deg,exact_roots,p)\n case(22)\n ! Poly 22: Jenkins Traub p5(z)\n deg = 10\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n exact_roots(1) = 0.1_dp\n exact_roots(2) = 0.1_dp\n exact_roots(3) = 0.1_dp\n exact_roots(4) = 0.1_dp\n exact_roots(5) = 0.2_dp\n exact_roots(6) = 0.2_dp\n exact_roots(7) = 0.2_dp\n exact_roots(8) = 0.3_dp\n exact_roots(9) = 0.3_dp\n exact_roots(10) = 0.4_dp\n ! polynomial\n p(deg+1) = cmplx(1.0_dp,0.0_dp,kind=dp)\n call rootCoeffCplx(deg,exact_roots,p)\n case(23)\n ! Poly 23: Jenkins Traub p6(z)\n deg = 5\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n exact_roots(1) = 0.1_dp\n exact_roots(2) = 1.001_dp\n exact_roots(3) = 0.998_dp\n exact_roots(4) = 1.00002_dp\n exact_roots(5) = 0.99999_dp\n ! polynomial\n p(deg+1) = cmplx(1.0_dp,0.0_dp,kind=dp)\n call rootCoeffCplx(deg,exact_roots,p)\n case(24)\n ! Poly 24: Jenkins Traub p7(z) with a=0\n deg = 7\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n exact_roots(1) = 0.001_dp\n exact_roots(2) = 0.01_dp\n exact_roots(3) = 0.1_dp\n exact_roots(4) = 0.1_dp\n exact_roots(5) = 0.1_dp\n exact_roots(6) = 1.0_dp\n exact_roots(7) = 10.0_dp\n ! polynomial\n p(deg+1) = cmplx(1.0_dp,0.0_dp,kind=dp)\n call rootCoeffCplx(deg,exact_roots,p)\n case(25)\n ! Poly 25: Jenkins Traub p7(z) with a=10^(-10)\n deg = 7\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n exact_roots(1) = 0.001_dp\n exact_roots(2) = 0.01_dp\n exact_roots(3) = 0.1_dp\n exact_roots(4) = cmplx(0.1_dp,1E-10_dp,kind=dp)\n exact_roots(5) = cmplx(0.1_dp,-1E-10_dp,kind=dp)\n exact_roots(6) = 1.0_dp\n exact_roots(7) = 10.0_dp\n ! polynomial\n p(deg+1) = cmplx(1.0_dp,0.0_dp,kind=dp)\n call rootCoeffCplx(deg,exact_roots,p)\n case(26)\n ! Poly 26: Jenkins Traub p7(z) with a=10^(-6)\n deg = 7\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n exact_roots(1) = 0.001_dp\n exact_roots(2) = 0.01_dp\n exact_roots(3) = 0.1_dp\n exact_roots(4) = cmplx(0.1_dp,1E-6_dp,kind=dp)\n exact_roots(5) = cmplx(0.1_dp,-1E-6_dp,kind=dp)\n exact_roots(6) = 1.0_dp\n exact_roots(7) = 10.0_dp\n ! polynomial\n p(deg+1) = cmplx(1.0_dp,0.0_dp,kind=dp)\n call rootCoeffCplx(deg,exact_roots,p)\n case(27)\n ! Poly 27: Jenkins Traub p8(z)\n deg = 5\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n exact_roots(1) = -1.0_dp\n exact_roots(2) = -1.0_dp\n exact_roots(3) = -1.0_dp\n exact_roots(4) = -1.0_dp\n exact_roots(5) = -1.0_dp\n ! polynomial\n p(deg+1) = cmplx(1.0_dp,0.0_dp,kind=dp)\n call rootCoeffCplx(deg,exact_roots,p)\n case(28)\n ! Poly 28: Jenkins Traub p9(z)\n deg = 20\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n exact_roots(1) = cmplx(+1d-2,0d0,kind=dp)\n exact_roots(2) = cmplx(-1d-2,0d0,kind=dp)\n exact_roots(3) = cmplx(0d0,+1d+2,kind=dp)\n exact_roots(4) = cmplx(0d0,-1d+2,kind=dp)\n exact_roots(5) = cmplx(-95.105651629515357212d0,+30.901699437494742410d0,kind=dp)\n exact_roots(6) = cmplx(-95.105651629515357212d0,-30.901699437494742410d0,kind=dp)\n exact_roots(7) = cmplx(-0.0080901699437494742410d0,+0.0058778525229247312917d0,kind=dp)\n exact_roots(8) = cmplx(-0.0080901699437494742410d0,-0.0058778525229247312917d0,kind=dp)\n exact_roots(9) = cmplx(-58.778525229247312917d0,+80.901699437494742410d0,kind=dp)\n exact_roots(10) = cmplx(-58.778525229247312917d0,-80.901699437494742410d0,kind=dp)\n exact_roots(11) = cmplx(-0.0030901699437494742410d0,+0.0095105651629515357212d0,kind=dp)\n exact_roots(12) = cmplx(-0.0030901699437494742410d0,-0.0095105651629515357212d0,kind=dp) \n exact_roots(13) = cmplx(+95.105651629515357212d0,+30.901699437494742410d0,kind=dp)\n exact_roots(14) = cmplx(+95.105651629515357212d0,-30.901699437494742410d0,kind=dp)\n exact_roots(15) = cmplx(+0.0080901699437494742410d0,+0.0058778525229247312917d0,kind=dp)\n exact_roots(16) = cmplx(+0.0080901699437494742410d0,-0.0058778525229247312917d0,kind=dp)\n exact_roots(17) = cmplx(+58.778525229247312917d0,+80.901699437494742410d0,kind=dp)\n exact_roots(18) = cmplx(+58.778525229247312917d0,-80.901699437494742410d0,kind=dp)\n exact_roots(19) = cmplx(+0.0030901699437494742410d0,+0.0095105651629515357212d0,kind=dp)\n exact_roots(20) = cmplx(+0.0030901699437494742410d0,-0.0095105651629515357212d0,kind=dp)\n ! polynomial\n p(deg+1) = cmplx(1.0_dp,0.0_dp,kind=dp)\n call rootCoeffCplx(deg,exact_roots,p)\n case(29)\n ! Poly 29: Jenkins Traub p10(z) with a=1e+3\n deg = 3\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n exact_roots(1) = 1E+3_dp\n exact_roots(2) = 1.0_dp\n exact_roots(3) = 1E-3_dp\n ! polynomial\n p(deg+1) = cmplx(1.0_dp,0.0_dp,kind=dp)\n call rootCoeffCplx(deg,exact_roots,p)\n case(30)\n ! Poly 30: Jenkins Traub p10(z) with a=1e+6\n deg = 3\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n exact_roots(1) = 1E+6_dp\n exact_roots(2) = 1.0_dp\n exact_roots(3) = 1E-6_dp\n ! polynomial\n p(deg+1) = cmplx(1.0_dp,0.0_dp,kind=dp)\n call rootCoeffCplx(deg,exact_roots,p)\n case(31)\n ! Poly 31: Jenkins Traub p10(z) with a=1e+9\n deg = 3\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n exact_roots(1) = 1E+9_dp\n exact_roots(2) = 1.0_dp\n exact_roots(3) = 1E-9_dp\n ! polynomial\n p(deg+1) = cmplx(1.0_dp,0.0_dp,kind=dp)\n call rootCoeffCplx(deg,exact_roots,p)\n case(32)\n ! Poly 32: Jenkins Traub p11(z) with m=15\n deg = 60\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n do j=-14,14\n exact_roots(15+j) = cmplx(cos(j*pi/30.0_dp),sin(j*pi/30.0_dp),kind=dp)\n end do\n do j=15,45\n exact_roots(15+j) = 0.9_dp*cmplx(cos(j*pi/30.0_dp),sin(j*pi/30.0_dp),kind=dp)\n end do\n ! polynomial\n p(deg+1) = cmplx(1.0_dp,0.0_dp,kind=dp)\n call rootCoeffCplx(deg,exact_roots,p)\n case(33)\n ! Poly 33: Jenkins Traub p11(z) with m=20\n deg = 80\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n do j=-19,19\n exact_roots(20+j) = cmplx(cos(j*pi/40.0_dp),sin(j*pi/40.0_dp),kind=dp)\n end do\n do j=20,60\n exact_roots(20+j) = 0.9_dp*cmplx(cos(j*pi/40.0_dp),sin(j*pi/40.0_dp),kind=dp)\n end do\n ! polynomial\n p(deg+1) = cmplx(1.0_dp,0.0_dp,kind=dp)\n call rootCoeffCplx(deg,exact_roots,p)\n case(34)\n ! Poly 34: Jenkins Traub p11(z) with m=25\n deg = 100\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n do j=-24,24\n exact_roots(25+j) = cmplx(cos(j*pi/50.0_dp),sin(j*pi/50.0_dp),kind=dp)\n end do\n do j=25,75\n exact_roots(25+j) = 0.9_dp*cmplx(cos(j*pi/50.0_dp),sin(j*pi/50.0_dp),kind=dp)\n end do\n ! polynomial\n p(deg+1) = cmplx(1.0_dp,0.0_dp,kind=dp)\n call rootCoeffCplx(deg,exact_roots,p)\n case(35)\n ! Poly 35: Cleve's Corner Polynomial\n deg = 6\n allocate(exact_roots(deg), p(deg+1))\n ! roots\n exact_roots(1) = cmplx(4,0,kind=dp)\n exact_roots(2) = cmplx(2,1,kind=dp)\n exact_roots(3) = cmplx(2,-1,kind=dp)\n exact_roots(4) = cmplx(0.25_dp,0,kind=dp)\n exact_roots(5) = 1/exact_roots(2)\n exact_roots(6) = 1/exact_roots(3)\n ! polynomial\n p(deg+1) = cmplx(1.0_dp,0.0_dp,kind=dp)\n call rootCoeffCplx(deg,exact_roots,p)\n end select\n end subroutine make_poly\n !************************************************\n ! max_rel_err *\n !************************************************\n ! Compute maximum relative error between roots \n ! and exact roots.\n !************************************************\n function max_rel_err(roots, exact_roots, deg) result(res)\n implicit none\n ! argument variables\n integer, intent(in) :: deg\n complex(kind=dp), intent(in) :: exact_roots(:), roots(:)\n ! local variables\n logical :: m(deg)\n integer :: i, j, k\n real(kind=dp) :: delta, err, res, relerr, rmax\n ! intrinsic procedures\n intrinsic :: abs, max, huge\n \n ! initialize\n m = .True.\n rmax = huge(1.0_dp)\n res = mu\n ! main loop\n do i=1,deg\n ! find corresponding exact root (yet to be matched)\n err = rmax\n do j=1,deg\n if(m(j)) then\n delta = abs(exact_roots(j) - roots(i))\n if(delta < err) then\n err = delta\n k = j\n end if\n end if\n end do\n ! mark corresponding root as matched\n m(k) = .False.\n ! calculate relative error on this root and update max\n ! zero roots give unhelpful relative errors, so revert to absolute error\n if(abs(roots(i))m .or. nl+nr Declaration of f2py variables\n! !!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!\n! !f2py intent(in) tpts\n! !f2py intent(in) real_response\n! !f2py intent(in) imag_response\n! !f2py intent(in) time\n! !f2py intent(in) w\n! !f2py intent(out) output\n!\n! \n! CALL write_to_screen('NOTE','PERFORMING TWO-DIMENSIONAL FOURIER TRANSFORM')\n!\n!END SUBROUTINE two_d_ft\n\n! Apply Cosine Window function to smooth out end of response function\nSUBROUTINE apply_cos_window( response, output )\n IMPLICIT NONE\n REAL(8) :: response(:), output( SIZE(response) )\n INTEGER :: itime\n REAL(8) :: pi=3.1415926536\n !> Declaration of f2py variables\n !!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!\n !f2py intent(in) real_response\n !f2py intent(in) imag_response\n !f2py intent(out) output\n \n CALL write_to_screen('NOTE','APPLYING COSINE WINDOW FUNCTION')\n \nDO itime = 1, SIZE( response )\n response(itime) = response(itime) &\n * COS( pi * ( REAL(itime-1))/ (2.0 * ( REAL(SIZE(response)) - 1 ) ) )\n END DO\n \n output = response\nEND SUBROUTINE apply_cos_window\n\nSUBROUTINE write_to_screen( type, message )\n IMPLICIT NONE\n CHARACTER(*) :: type\n CHARACTER (*):: message\n\n write(*,*) '***',type,'*** : ', message\n\nEND SUBROUTINE write_to_screen\n", "meta": {"hexsha": "f456bc926dd6003151896c18df142dd822ca1f69", "size": 3585, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "run/analysis/f2py_analysis.f90", "max_stars_repo_name": "jprov410/mqds", "max_stars_repo_head_hexsha": "beead5c30aac77a7ae2d07e808d8c587cdd1c3ce", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-02-08T20:58:49.000Z", "max_stars_repo_stars_event_max_datetime": "2018-08-23T02:07:17.000Z", "max_issues_repo_path": "run/analysis/f2py_analysis.f90", "max_issues_repo_name": "jprov410/MQDS", "max_issues_repo_head_hexsha": "beead5c30aac77a7ae2d07e808d8c587cdd1c3ce", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-02-21T18:41:21.000Z", "max_issues_repo_issues_event_max_datetime": "2018-03-21T21:27:48.000Z", "max_forks_repo_path": "run/analysis/f2py_analysis.f90", "max_forks_repo_name": "jprov410/MQDS", "max_forks_repo_head_hexsha": "beead5c30aac77a7ae2d07e808d8c587cdd1c3ce", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-02-07T20:12:07.000Z", "max_forks_repo_forks_event_max_datetime": "2019-10-01T02:33:09.000Z", "avg_line_length": 31.7256637168, "max_line_length": 82, "alphanum_fraction": 0.639888424, "num_tokens": 1189, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045817875225, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6697640352090272}} {"text": "!\r\n!\tFind the Akaike correction.\r\n!\tmodeldim is the model dimension.\r\n!\tloglik is the log likelilhood.\r\n!\ttotalitemsis the total number of presented items.\r\nreal(kind=8) function akaike(modeldim,loglik,totalitems)\r\nimplicit none\r\ninteger,intent(in)::modeldim\r\nreal(kind=8),intent(in)::loglik,totalitems\r\nakaike=(-loglik+modeldim)/totalitems\r\nreturn\r\nend function akaike\r\n", "meta": {"hexsha": "4e81458707d8e5eed5d1d8c1f2dc0ce6b84c5390", "size": 371, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Source/akaike.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/akaike.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/akaike.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": 28.5384615385, "max_line_length": 57, "alphanum_fraction": 0.7681940701, "num_tokens": 102, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8872045817875225, "lm_q2_score": 0.7549149758396752, "lm_q1q2_score": 0.6697640254249766}} {"text": "*DECK ULSIA\n SUBROUTINE ULSIA (A, MDA, M, N, B, MDB, NB, RE, AE, KEY, MODE, NP,\n + KRANK, KSURE, RNORM, W, LW, IWORK, LIW, INFO)\nC***BEGIN PROLOGUE ULSIA\nC***PURPOSE Solve an underdetermined linear system of equations by\nC performing an LQ factorization of the matrix using\nC Householder transformations. Emphasis is put on detecting\nC possible rank deficiency.\nC***LIBRARY SLATEC\nC***CATEGORY D9\nC***TYPE SINGLE PRECISION (ULSIA-S, DULSIA-D)\nC***KEYWORDS LINEAR LEAST SQUARES, LQ FACTORIZATION,\nC UNDERDETERMINED LINEAR SYSTEM\nC***AUTHOR Manteuffel, T. A., (LANL)\nC***DESCRIPTION\nC\nC ULSIA computes the minimal length solution(s) to the problem AX=B\nC where A is an M by N matrix with M.LE.N and B is the M by NB\nC matrix of right hand sides. User input bounds on the uncertainty\nC in the elements of A are used to detect numerical rank deficiency.\nC The algorithm employs a row and column pivot strategy to\nC minimize the growth of uncertainty and round-off errors.\nC\nC ULSIA requires (MDA+1)*N + (MDB+1)*NB + 6*M dimensioned space\nC\nC ******************************************************************\nC * *\nC * WARNING - All input arrays are changed on exit. *\nC * *\nC ******************************************************************\nC\nC Input..\nC\nC A(,) Linear coefficient matrix of AX=B, with MDA the\nC MDA,M,N actual first dimension of A in the calling program.\nC M is the row dimension (no. of EQUATIONS of the\nC problem) and N the col dimension (no. of UNKNOWNS).\nC Must have MDA.GE.M and M.LE.N.\nC\nC B(,) Right hand side(s), with MDB the actual first\nC MDB,NB dimension of B in the calling program. NB is the\nC number of M by 1 right hand sides. Since the\nC solution is returned in B, must have MDB.GE.N. If\nC NB = 0, B is never accessed.\nC\nC ******************************************************************\nC * *\nC * Note - Use of RE and AE are what make this *\nC * code significantly different from *\nC * other linear least squares solvers. *\nC * However, the inexperienced user is *\nC * advised to set RE=0.,AE=0.,KEY=0. *\nC * *\nC ******************************************************************\nC\nC RE(),AE(),KEY\nC RE() RE() is a vector of length N such that RE(I) is\nC the maximum relative uncertainty in row I of\nC the matrix A. The values of RE() must be between\nC 0 and 1. A minimum of 10*machine precision will\nC be enforced.\nC\nC AE() AE() is a vector of length N such that AE(I) is\nC the maximum absolute uncertainty in row I of\nC the matrix A. The values of AE() must be greater\nC than or equal to 0.\nC\nC KEY For ease of use, RE and AE may be input as either\nC vectors or scalars. If a scalar is input, the algo-\nC rithm will use that value for each column of A.\nC The parameter KEY indicates whether scalars or\nC vectors are being input.\nC KEY=0 RE scalar AE scalar\nC KEY=1 RE vector AE scalar\nC KEY=2 RE scalar AE vector\nC KEY=3 RE vector AE vector\nC\nC\nC MODE The integer MODE indicates how the routine\nC is to react if rank deficiency is detected.\nC If MODE = 0 return immediately, no solution\nC 1 compute truncated solution\nC 2 compute minimal length least squares sol\nC The inexperienced user is advised to set MODE=0\nC\nC NP The first NP rows of A will not be interchanged\nC with other rows even though the pivot strategy\nC would suggest otherwise.\nC The inexperienced user is advised to set NP=0.\nC\nC WORK() A real work array dimensioned 5*M. However, if\nC RE or AE have been specified as vectors, dimension\nC WORK 4*M. If both RE and AE have been specified\nC as vectors, dimension WORK 3*M.\nC\nC LW Actual dimension of WORK\nC\nC IWORK() Integer work array dimensioned at least N+M.\nC\nC LIW Actual dimension of IWORK.\nC\nC\nC INFO Is a flag which provides for the efficient\nC solution of subsequent problems involving the\nC same A but different B.\nC If INFO = 0 original call\nC INFO = 1 subsequent calls\nC On subsequent calls, the user must supply A, KRANK,\nC LW, IWORK, LIW, and the first 2*M locations of WORK\nC as output by the original call to ULSIA. MODE must\nC be equal to the value of MODE in the original call.\nC If MODE.LT.2, only the first N locations of WORK\nC are accessed. AE, RE, KEY, and NP are not accessed.\nC\nC\nC\nC\nC Output..\nC\nC A(,) Contains the lower triangular part of the reduced\nC matrix and the transformation information. It togeth\nC with the first M elements of WORK (see below)\nC completely specify the LQ factorization of A.\nC\nC B(,) Contains the N by NB solution matrix for X.\nC\nC KRANK,KSURE The numerical rank of A, based upon the relative\nC and absolute bounds on uncertainty, is bounded\nC above by KRANK and below by KSURE. The algorithm\nC returns a solution based on KRANK. KSURE provides\nC an indication of the precision of the rank.\nC\nC RNORM() Contains the Euclidean length of the NB residual\nC vectors B(I)-AX(I), I=1,NB. If the matrix A is of\nC full rank, then RNORM=0.0.\nC\nC WORK() The first M locations of WORK contain values\nC necessary to reproduce the Householder\nC transformation.\nC\nC IWORK() The first N locations contain the order in\nC which the columns of A were used. The next\nC M locations contain the order in which the\nC rows of A were used.\nC\nC INFO Flag to indicate status of computation on completion\nC -1 Parameter error(s)\nC 0 - Rank deficient, no solution\nC 1 - Rank deficient, truncated solution\nC 2 - Rank deficient, minimal length least squares sol\nC 3 - Numerical rank 0, zero solution\nC 4 - Rank .LT. NP\nC 5 - Full rank\nC\nC***REFERENCES T. Manteuffel, An interval analysis approach to rank\nC determination in linear least squares problems,\nC Report SAND80-0655, Sandia Laboratories, June 1980.\nC***ROUTINES CALLED R1MACH, U11US, U12US, XERMSG\nC***REVISION HISTORY (YYMMDD)\nC 810801 DATE WRITTEN\nC 890831 Modified array declarations. (WRB)\nC 891009 Removed unreferenced variable. (WRB)\nC 891009 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\nC 900510 Fixed an error message. (RWC)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE ULSIA\n DIMENSION A(MDA,*),B(MDB,*),RE(*),AE(*),RNORM(*),W(*)\n INTEGER IWORK(*)\nC\nC***FIRST EXECUTABLE STATEMENT ULSIA\n IF(INFO.LT.0 .OR. INFO.GT.1) GO TO 514\n IT=INFO\n INFO=-1\n IF(NB.EQ.0 .AND. IT.EQ.1) GO TO 501\n IF(M.LT.1) GO TO 502\n IF(N.LT.1) GO TO 503\n IF(N.LT.M) GO TO 504\n IF(MDA.LT.M) GO TO 505\n IF(LIW.LT.M+N) GO TO 506\n IF(MODE.LT.0 .OR. MODE.GT.3) GO TO 515\n IF(NB.EQ.0) GO TO 4\n IF(NB.LT.0) GO TO 507\n IF(MDB.LT.N) GO TO 508\n IF(IT.EQ.0) GO TO 4\n GO TO 400\n 4 IF(KEY.LT.0.OR.KEY.GT.3) GO TO 509\n IF(KEY.EQ.0 .AND. LW.LT.5*M) GO TO 510\n IF(KEY.EQ.1 .AND. LW.LT.4*M) GO TO 510\n IF(KEY.EQ.2 .AND. LW.LT.4*M) GO TO 510\n IF(KEY.EQ.3 .AND. LW.LT.3*M) GO TO 510\n IF(NP.LT.0 .OR. NP.GT.M) GO TO 516\nC\n EPS=10.*R1MACH(4)\n M1=1\n M2=M1+M\n M3=M2+M\n M4=M3+M\n M5=M4+M\nC\n IF(KEY.EQ.1) GO TO 100\n IF(KEY.EQ.2) GO TO 200\n IF(KEY.EQ.3) GO TO 300\nC\n IF(RE(1).LT.0.0) GO TO 511\n IF(RE(1).GT.1.0) GO TO 512\n IF(RE(1).LT.EPS) RE(1)=EPS\n IF(AE(1).LT.0.0) GO TO 513\n DO 20 I=1,M\n W(M4-1+I)=RE(1)\n W(M5-1+I)=AE(1)\n 20 CONTINUE\n CALL U11US(A,MDA,M,N,W(M4),W(M5),MODE,NP,KRANK,KSURE,\n 1 W(M1),W(M2),W(M3),IWORK(M1),IWORK(M2))\n GO TO 400\nC\n 100 CONTINUE\n IF(AE(1).LT.0.0) GO TO 513\n DO 120 I=1,M\n IF(RE(I).LT.0.0) GO TO 511\n IF(RE(I).GT.1.0) GO TO 512\n IF(RE(I).LT.EPS) RE(I)=EPS\n W(M4-1+I)=AE(1)\n 120 CONTINUE\n CALL U11US(A,MDA,M,N,RE,W(M4),MODE,NP,KRANK,KSURE,\n 1 W(M1),W(M2),W(M3),IWORK(M1),IWORK(M2))\n GO TO 400\nC\n 200 CONTINUE\n IF(RE(1).LT.0.0) GO TO 511\n IF(RE(1).GT.1.0) GO TO 512\n IF(RE(1).LT.EPS) RE(1)=EPS\n DO 220 I=1,M\n W(M4-1+I)=RE(1)\n IF(AE(I).LT.0.0) GO TO 513\n 220 CONTINUE\n CALL U11US(A,MDA,M,N,W(M4),AE,MODE,NP,KRANK,KSURE,\n 1 W(M1),W(M2),W(M3),IWORK(M1),IWORK(M2))\n GO TO 400\nC\n 300 CONTINUE\n DO 320 I=1,M\n IF(RE(I).LT.0.0) GO TO 511\n IF(RE(I).GT.1.0) GO TO 512\n IF(RE(I).LT.EPS) RE(I)=EPS\n IF(AE(I).LT.0.0) GO TO 513\n 320 CONTINUE\n CALL U11US(A,MDA,M,N,RE,AE,MODE,NP,KRANK,KSURE,\n 1 W(M1),W(M2),W(M3),IWORK(M1),IWORK(M2))\nC\nC DETERMINE INFO\nC\n 400 IF(KRANK.NE.M) GO TO 402\n INFO=5\n GO TO 410\n 402 IF(KRANK.NE.0) GO TO 404\n INFO=3\n GO TO 410\n 404 IF(KRANK.GE.NP) GO TO 406\n INFO=4\n RETURN\n 406 INFO=MODE\n IF(MODE.EQ.0) RETURN\n 410 IF(NB.EQ.0) RETURN\nC\nC\nC SOLUTION PHASE\nC\n M1=1\n M2=M1+M\n M3=M2+M\n IF(INFO.EQ.2) GO TO 420\n IF(LW.LT.M2-1) GO TO 510\n CALL U12US(A,MDA,M,N,B,MDB,NB,MODE,KRANK,\n 1 RNORM,W(M1),W(M1),IWORK(M1),IWORK(M2))\n RETURN\nC\n 420 IF(LW.LT.M3-1) GO TO 510\n CALL U12US(A,MDA,M,N,B,MDB,NB,MODE,KRANK,\n 1 RNORM,W(M1),W(M2),IWORK(M1),IWORK(M2))\n RETURN\nC\nC ERROR MESSAGES\nC\n 501 CALL XERMSG ('SLATEC', 'ULSIA',\n + 'SOLUTION ONLY (INFO=1) BUT NO RIGHT HAND SIDE (NB=0)', 1, 0)\n RETURN\n 502 CALL XERMSG ('SLATEC', 'ULSIA', 'M.LT.1', 2, 1)\n RETURN\n 503 CALL XERMSG ('SLATEC', 'ULSIA', 'N.LT.1', 2, 1)\n RETURN\n 504 CALL XERMSG ('SLATEC', 'ULSIA', 'N.LT.M', 2, 1)\n RETURN\n 505 CALL XERMSG ('SLATEC', 'ULSIA', 'MDA.LT.M', 2, 1)\n RETURN\n 506 CALL XERMSG ('SLATEC', 'ULSIA', 'LIW.LT.M+N', 2, 1)\n RETURN\n 507 CALL XERMSG ('SLATEC', 'ULSIA', 'NB.LT.0', 2, 1)\n RETURN\n 508 CALL XERMSG ('SLATEC', 'ULSIA', 'MDB.LT.N', 2, 1)\n RETURN\n 509 CALL XERMSG ('SLATEC', 'ULSIA', 'KEY OUT OF RANGE', 2, 1)\n RETURN\n 510 CALL XERMSG ('SLATEC', 'ULSIA', 'INSUFFICIENT WORK SPACE', 8, 1)\n INFO=-1\n RETURN\n 511 CALL XERMSG ('SLATEC', 'ULSIA', 'RE(I) .LT. 0', 2, 1)\n RETURN\n 512 CALL XERMSG ('SLATEC', 'ULSIA', 'RE(I) .GT. 1', 2, 1)\n RETURN\n 513 CALL XERMSG ('SLATEC', 'ULSIA', 'AE(I) .LT. 0', 2, 1)\n RETURN\n 514 CALL XERMSG ('SLATEC', 'ULSIA', 'INFO OUT OF RANGE', 2, 1)\n RETURN\n 515 CALL XERMSG ('SLATEC', 'ULSIA', 'MODE OUT OF RANGE', 2, 1)\n RETURN\n 516 CALL XERMSG ('SLATEC', 'ULSIA', 'NP OUT OF RANGE', 2, 1)\n RETURN\n END\n", "meta": {"hexsha": "cd212ee9051bf69251582cb8a73ef2e935214eb7", "size": 12359, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/ulsia.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/ulsia.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/ulsia.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.5015576324, "max_line_length": 72, "alphanum_fraction": 0.5319200583, "num_tokens": 3854, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096044278532, "lm_q2_score": 0.731058584489497, "lm_q1q2_score": 0.6697297906502594}} {"text": " subroutine dot_product_6_planes(vector, dot)\n\nC #####################################################################\nC\nC PURPOSE -\nC\nC Take the dot product of the input vector with 6 internaly\nC defined unit vectors and return the 6 results.\nC\nC We wish to determine which of 6 quadrents a vector lies in.\nC To do this we first take the dot product of the vector with\nC the unit normal to 6 planes defined by the unit vector defined\nC below.\nC sqrt2d2, sqrt2d2, 0.0d0,\nC nsqrt2d2, sqrt2d2, 0.0d0,\nC sqrt2d2, 0.0d0 , sqrt2d2,\nC nsqrt2d2, 0.0d0 , sqrt2d2,\nC 0.0d0 , sqrt2d2, sqrt2d2,\nC 0.0d0 ,nsqrt2d2, sqrt2d2\nC\nC INPUT ARGUMENTS \nC\nC vector - a 3 component vector\nC\nC OUTPUT ARGUMENTS -\nC\nC dot - a 6 component array with the dot product of\nC vector with 6 planes.\nC\nC AUTHOR\nC\nC Carl W. Gable gable@lanl.gov (Los Alamos National Laboratory)\nC\nC CHANGE HISTORY -\nC\nC $Log: dot_product_6_planes.f,v $\nC Revision 2.00 2007/11/05 19:45:52 spchu\nC Import to CVS\nC\nCPVCS \nCPVCS Rev 1.1 Mon Apr 14 16:43:28 1997 pvcs\nCPVCS No change.\nCPVCS \nCPVCS Rev 1.0 Wed May 08 12:35:52 1996 gable\nCPVCS Initial revision.\nC\nC ######################################################################\nC\n implicit none\n real*8 dot(6)\n real*8 vector(3)\n real*8 fnormal(3,6)\n integer i, j\nC\nc\nc Define unit vectors to 6 planes that split a region into 6 sectors\nc\n real*8 sqrt2, sqrt2d2, nsqrt2d2\n parameter ( sqrt2 = 0.141421356237310E+01, \n 1 sqrt2d2 = 0.707106781186548E+00, \n 2 nsqrt2d2 =-0.707106781186548E+00)\nc\nc define the unit normal to each plane\n*\n data ((fnormal(i,j),i=1,3),j=1,6) / \n * sqrt2d2, sqrt2d2, 0.0d0,\n * nsqrt2d2, sqrt2d2, 0.0d0,\n * sqrt2d2, 0.0d0 , sqrt2d2,\n * nsqrt2d2, 0.0d0 , sqrt2d2,\n * 0.0d0 , sqrt2d2, sqrt2d2,\n * 0.0d0 ,nsqrt2d2, sqrt2d2\n * /\nc\nc Take the dot product of each of the unit normals with the input vector.\nc\n dot(1) = fnormal(1,1)*vector(1) +\n * fnormal(2,1)*vector(2) +\n * fnormal(3,1)*vector(3)\n dot(2) = fnormal(1,2)*vector(1) +\n * fnormal(2,2)*vector(2) +\n * fnormal(3,2)*vector(3)\n dot(3) = fnormal(1,3)*vector(1) +\n * fnormal(2,3)*vector(2) +\n * fnormal(3,3)*vector(3)\n dot(4) = fnormal(1,4)*vector(1) +\n * fnormal(2,4)*vector(2) +\n * fnormal(3,4)*vector(3)\n dot(5) = fnormal(1,5)*vector(1) +\n * fnormal(2,5)*vector(2) +\n * fnormal(3,5)*vector(3)\n dot(6) = fnormal(1,6)*vector(1) +\n * fnormal(2,6)*vector(2) +\n * fnormal(3,6)*vector(3)\nc \n return\n end\n", "meta": {"hexsha": "9d8f419f5178816d6c4672d5561dfa33fd955879", "size": 3222, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/dot_product_6_planes.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/dot_product_6_planes.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/dot_product_6_planes.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": 33.2164948454, "max_line_length": 77, "alphanum_fraction": 0.4816883923, "num_tokens": 1072, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096181702032, "lm_q2_score": 0.7310585727705127, "lm_q1q2_score": 0.6697297899608481}} {"text": "! { dg-do run }\n! Tests the fix for PR40646 in which the assignment would cause an ICE.\n!\n! Contributed by Charlie Sharpsteen \n! http://gcc.gnu.org/ml/fortran/2009-07/msg00010.html\n! and reported by Tobias Burnus \n!\nmodule bugTestMod\n implicit none\n type:: boundTest\n contains\n procedure, nopass:: test => returnMat\n end type boundTest\ncontains\n function returnMat( a, b ) result( mat )\n integer:: a, b, i\n double precision, dimension(a,b):: mat\n mat = dble (reshape ([(i, i = 1, a * b)],[a,b])) \n return\n end function returnMat\nend module bugTestMod\n\nprogram bugTest\n use bugTestMod\n implicit none\n integer i\n double precision, dimension(2,2):: testCatch\n type( boundTest ):: testObj\n testCatch = testObj%test(2,2) ! This would cause an ICE\n if (any (testCatch .ne. dble (reshape ([(i, i = 1, 4)],[2,2])))) call abort\nend program bugTest\n! { dg-final { cleanup-modules \"bugTestMod\" } }\n", "meta": {"hexsha": "174cbc57a794f7db850e41e9ec35b13f939e96a3", "size": 960, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/func_assign_3.f90", "max_stars_repo_name": "maurizioabba/rose", "max_stars_repo_head_hexsha": "7597292cf14da292bdb9a4ef573001b6c5b9b6c0", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/func_assign_3.f90", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/func_assign_3.f90", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 29.0909090909, "max_line_length": 77, "alphanum_fraction": 0.6854166667, "num_tokens": 303, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84997116805678, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.6697188029416848}} {"text": " subroutine scurv(x1,x2,x3,x4,x5,x6)\r\nc\r\nc + + + PURPOSE + + +\r\nc Computes constants for an S-curve given the (X,Y) coordinates\r\nc of points represented by: (x3,x1), (x4,x2).\r\nc\r\nc Implements a modification of EPIC equation 2.254, in the form:\r\nc\r\nc tmin\r\nc y = 100 * ------------------------- ; tmin < -1.0;\r\nc tmin + exp(a + b * tmin)\r\nc\r\nc\r\nc where:\r\nc the \"100\" is the upper limit (asymptote) of the curve,\r\nc \"tmin\" is the minimum daily temperature (Celsius), and\r\nc \"a\" and \"b\" are the constants computed by SCURV.\r\nc\r\nc The \"a\" & \"b\" returned by SCURVE (x5 & x6) force the curve through\r\nc the points: (x3, x1) and (x4, x2); ie, (tmin1, y1) and (tmin2, y2).\r\nc The \"100\" is a scaling factor which alters the curvature *between*\r\nc those points.\r\nc\r\nc FOR EXAMPLE:\r\nc For TMIN's of -5 and -15, with associated biomass loss\r\nc fractions of 0.01 and 0.95 respectively,\r\nc setting x1=0.01, x2=0.95, x3=5.0, x4=15.0\r\nc yields: x5=12.55, x6=0.3465 as values for \"a\" & \"b\" respectively.\r\nc\r\nc Note: The values entered for TMIN's are the ABSOLUTE VALUES\r\nc of the actual TMIN's; ie, they are POSITIVE NUMBERS.\r\nc (TMIN is constrained to be less than -1 degrees Celsius.)\r\nc THIS SHOULD BE CHANGED IN \"SCURV\" AND IN \"PTGRP\" AND\r\nc \"RANGE\".\r\nc\r\nc\r\nc Called from RANGE, PTGRP, and PRGRA.\r\nc Author(s): Williams, Arnold, Weltz, Ferris, Meyer\r\nc Reference in User Guide:\r\nc\r\nc Changes:\r\nc\r\nc Version: This module recoded from WEPP version 92.25.\r\nc Date recoded: 07/02/92.\r\nc Recoded by: Charles R. Meyer.\r\nc\r\nc + + + KEYWORDS + + +\r\nc\r\nc + + + ARGUMENT DECLARATIONS + + +\r\n real x1, x2, x3, x4, x5, x6\r\nc\r\nc + + + ARGUMENT DEFINITIONS + + +\r\nc x1 - frost damage fraction for 1st point.\r\nc x2 - frost damage fraction for 2nd point.\r\nc x3 - temperature associated with 1st point.\r\nc x4 - temperature associated with 2nd point.\r\nc x5 - 1st constant computed by SCURV.\r\nc x6 - 2nd constant computed by SCURV.\r\nc\r\nc + + + LOCAL VARIABLES + + +\r\n real xx, yy\r\nc\r\nc + + + END SPECIFICATIONS + + +\r\nc\r\nc\r\n xx = alog(x3/(x1/100.)-x3)\r\n yy = alog(x4/(x2/100.)-x4)\r\n x6 = ((xx-yy)/(x4-x3))\r\n x5 = (xx+x3*x6)\r\n return\r\n end\r\n", "meta": {"hexsha": "ff8e35d6f5de7feed3eea6cc02fdfad026205ceb", "size": 2452, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/wepp2010.1/scurv.for", "max_stars_repo_name": "jarad/dep", "max_stars_repo_head_hexsha": "fe73982f4c70039e1a31b9e8e2d9aac31502f803", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-11-26T17:49:19.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-26T17:49:19.000Z", "max_issues_repo_path": "src/wepp2010.1/scurv.for", "max_issues_repo_name": "jarad/dep", "max_issues_repo_head_hexsha": "fe73982f4c70039e1a31b9e8e2d9aac31502f803", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 54, "max_issues_repo_issues_event_min_datetime": "2018-12-12T18:02:31.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T19:14:25.000Z", "max_forks_repo_path": "src/wepp2010.1/scurv.for", "max_forks_repo_name": "akrherz/idep", "max_forks_repo_head_hexsha": "7189a26fbcec3d8c3cc7d7015107b8fb6c5f6a45", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-03-02T22:59:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-09T15:49:00.000Z", "avg_line_length": 34.0555555556, "max_line_length": 75, "alphanum_fraction": 0.55954323, "num_tokens": 801, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750413739076, "lm_q2_score": 0.7025300573952054, "lm_q1q2_score": 0.669704369529828}} {"text": "! NAME: PI SPMD final version without false sharing\r\n! This program will numerically compute the integral of\r\n! 4/(1+x*x) \r\n! from 0 to 1. The value of this integral is pi -- which \r\n! is great since it gives us an easy way to check the answer.\r\n\r\n! The program was parallelized using OpenMP and an SPMD \r\n! algorithm. The following OpenMP specific lines were \r\n! added: \r\n\r\n! (1) A line to include omp.h -- the include file that \r\n! contains OpenMP's function prototypes and constants.\r\n\r\n! (2) A pragma that tells OpenMP to create a team of threads\r\n! with an integer variable i being created for each thread.\r\n\r\n! (3) two function calls: one to get the thread ID (ranging\r\n! from 0 to one less than the number of threads), and the other\r\n! returning the total number of threads.\r\n\r\n! (4) A \"single\" construct so only one thread prints the number\r\n! of threads.\r\n\r\n! (5) A cyclic distribution of the loop by changing loop control\r\n! expressions to run from the thread ID incremented by the number \r\n! of threads. Local sums accumlated into sum[id].\r\n\r\n! (6) A barrier to make sure everyone's done.\r\n\r\n! (7) A single construct so only one thread combines the local\r\n! sums into a single global sum.\r\n\r\n! Note that this program avoids the false sharing problem\r\n! by storing partial sums into a private scalar.\r\n\r\n! History: C Code written by Tim Mattson, 11/1999\r\n! Adapted to Fortran code by Helen He and Tim Mattson, 09/2017\r\n! Changed to Fortran90 code by Helen He, 11/2020 \r\n\r\n PROGRAM MAIN\r\n USE OMP_LIB\r\n IMPLICIT NONE\r\n\r\n INTEGER :: i, j, id, numthreads, nthreads\r\n INTEGER, PARAMETER :: num_steps=100000000\r\n INTEGER, PARAMETER :: MAX_THREADS=4\r\n REAL*8 :: pi, real_sum, step, full_sum, x\r\n REAL*8 :: start_time, run_time\r\n REAL*8 :: sum(0:MAX_THREADS-1)\r\n REAL*8 :: partial_sum\r\n\r\n full_sum = 0.0\r\n\r\n step = 1.0 / num_steps\r\n start_time = OMP_GET_WTIME()\r\n\r\n DO j = 1, MAX_THREADS\r\n CALL OMP_SET_NUM_THREADS(j)\r\n full_sum = 0.0\r\n start_time = OMP_GET_WTIME()\r\n\r\n!$OMP PARALLEL PRIVATE(i, id, numthreads, partial_sum, x)\r\n id = OMP_GET_THREAD_NUM()\r\n numthreads = OMP_GET_NUM_THREADS()\r\n partial_sum = 0.0\r\n\r\n!$OMP SINGLE \r\n nthreads = numthreads\r\n!$OMP END SINGLE NOWAIT\r\n\r\n DO i = id, num_steps - 1, numthreads\r\n x = (i + 0.5) * step\r\n partial_sum = partial_sum + 4.0 / (1.0 + x*x)\r\n ENDDO\r\n\r\n!$OMP CRITICAL\r\n full_sum = full_sum + partial_sum\r\n!$OMP END CRITICAL\r\n\r\n!$OMP END PARALLEL\r\n \r\n pi = step * full_sum\r\n run_time = OMP_GET_WTIME() - start_time\r\n WRITE(*,100) pi, run_time, nthreads\r\n100 FORMAT('pi is ',f15.8,' in ',f8.3,'secs and ',i3,' threads')\r\n ENDDO\r\n\r\n END PROGRAM MAIN\r\n", "meta": {"hexsha": "d0b12bf309697081048276b2c0973cd9e65470b1", "size": 2728, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Exercises/Fortran/solutions/pi_spmd_final.f90", "max_stars_repo_name": "zafar-hussain/OmpCommonCore", "max_stars_repo_head_hexsha": "e5457dcc6849f921e92ae3054486be56e39e6ebf", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 37, "max_stars_repo_stars_event_min_datetime": "2020-04-21T18:05:37.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:10:18.000Z", "max_issues_repo_path": "Exercises/Fortran/solutions/pi_spmd_final.f90", "max_issues_repo_name": "zafar-hussain/OmpCommonCore", "max_issues_repo_head_hexsha": "e5457dcc6849f921e92ae3054486be56e39e6ebf", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-12-09T19:42:54.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T21:27:04.000Z", "max_forks_repo_path": "Exercises/Fortran/solutions/pi_spmd_final.f90", "max_forks_repo_name": "zafar-hussain/OmpCommonCore", "max_forks_repo_head_hexsha": "e5457dcc6849f921e92ae3054486be56e39e6ebf", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2020-09-05T18:54:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-23T02:19:12.000Z", "avg_line_length": 30.6516853933, "max_line_length": 72, "alphanum_fraction": 0.6653225806, "num_tokens": 769, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382236515259, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.6696735416410211}} {"text": "program piqpr16\n\n! This program implements the BBP algorithm to generate a few hexadecimal\n! digits beginning immediately after a given position id, or in other words\n! beginning at position id + 1. The maximum value of id is not known for\n! this code, but it is believed to be at least 10^14, depending on system.\n! Results for a given position id can be checked by repeating with id-1 or\n! id+1, and verifying that the hex digits perfectly overlap with an offset of\n! one, except possibly for a few trailing digits. The resulting fractions\n! are typically accurate to at least 25 decimal digits, and to at least 20\n! hex digits. This code runs reasonably fast on IBM systems and others that\n! treat \"real*16\" as double-double, but typically rather slowly on systems\n! that treat \"real*16\" as software-based IEEE 128-bit floating-point.\n\n! David H. Bailey 2006-09-06\n\nimplicit none\ninteger id, nbt\nreal tm0, tm1\nreal*16 c1, pid, s1, s2, s3, s4, series\nparameter (nbt = 96)\ninteger ibt(nbt)\ncharacter*1 chx(nbt/4)\n\n! Set the position id here. Output hex digits beginning after position id,\n! i.e., beginning with position id + 1.\n\nparameter (id = 1000000)\n\nwrite (6, 1) id\n1 format ('Pi hex digit computation'/'position =',i12)\n\n! Evaluate the four series used in the formula.\n\ncall cpu_time (tm0)\ns1 = series (1, id)\ncall ibits (s1, nbt, ibt, chx)\nwrite (6, 2) 1, s1, chx, ibt\n2 format ('Sum of series',i2,' ='/f34.30/24a1/96i1.1)\ns2 = series (4, id)\ncall ibits (s2, nbt, ibt, chx)\nwrite (6, 2) 2, s2, chx, ibt\ns3 = series (5, id)\ncall ibits (s3, nbt, ibt, chx)\nwrite (6, 2) 3, s3, chx, ibt\ns4 = series (6, id)\ncall ibits (s4, nbt, ibt, chx)\nwrite (6, 2) 4, s4, chx, ibt\n\n! Compute the four series results as specified in the BBP formula.\n\nc1 = 1.d0\npid = mod (4.d0 * s1 - 2.d0 * s2 - s3 - s4, c1)\nif (pid .lt. 0.d0) pid = pid + 1.d0\ncall cpu_time (tm1)\n\n! Output results.\n\nwrite (6, 3) tm1 - tm0\n3 format ('Run complete. CPU time =',f12.4)\ncall ibits (pid, nbt, ibt, chx)\nwrite (6, 4) pid, chx, ibt\n4 format ('Pi fraction ='/f34.30/24a1/96i1.1)\n\nstop\nend\n\nsubroutine ibits (x, nbt, ibt, chx)\n\n! This returns in ibt the first nbt bits of the fraction of the floating-point\n! argument x, and returns the first nbt/4 hex digits in chx. The argument nbt\n! must be divisible by 4 and must not exceed the number of mantissa bits in\n! the floating-point format used for x.\n\nimplicit none\ninteger i, ii, nbt, ibt(nbt)\nreal*16 x, y\ncharacter*1 chx(nbt/4), hx(0:15)\ndata hx/'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', &\n 'C', 'D', 'E', 'F'/\n\ny = abs (x)\n\ndo i = 1, nbt\n y = 2.d0 * (y - aint (y))\n ibt(i) = int (y)\nenddo\n\ndo i = 1, nbt / 4\n ii = 8 * ibt(4*i-3) + 4 * ibt(4*i-2) + 2 * ibt(4*i-1) + ibt(4*i)\n chx(i) = hx(ii)\nenddo\n\nreturn\nend\n\nfunction series (m, id)\n\n! This routine evaluates the series Sum_{k=1}^d (2^(id-k) mod (8*k+m))/(8*k+m).\n\nimplicit none\ninteger id, k, m\nreal*16 ak, c1, eps, expm1, p, s, series, t\nparameter (eps = 1d-32)\n\nc1 = 1.d0\ns = 0.d0\n\n! Sum the series until k exceeds id\n\ndo k = 0, id\n ak = 8 * k + m\n p = id - k\n if (p == 0.d0) then\n t = 1.d0\n elseif (ak == 1.d0) then\n t = 0.d0\n else\n t = expm1 (p, ak)\n endif\n s = mod (s + t / ak, c1)\n! write (6, '(i5,3f15.1,f20.15)') k, p, ak, t, s\nenddo\n\n! Complete the computation by manually computing a few terms where k > id.\n\ndo k = id + 1, id + 100\n ak = 8 * k + m\n t = 16.d0 ** (id - k)\n if (t .lt. eps) goto 120\n s = mod (s + t / ak, c1)\nenddo\n\n120 continue\n\n! write (6, *) 'final s =', s\n\nseries = s\nreturn\nend\n\nfunction expm1 (p, ak)\n\n! expm1 (p, ak) = 16^p mod ak.\n! This routine uses a left-to-right binary exponentiation scheme.\n\nimplicit none\ninteger i, ntp\nparameter (ntp = 30)\nreal*16 ak, expm1, p, p1, pt1, r, tp(ntp)\nsave tp\ndata tp/ntp*0.d0/\n\n! If this is the first call, fill the power of two table tp.\n\nif (tp(1) .eq. 0.d0) then\n tp(1) = 1.d0\n\n do i = 2, ntp\n tp(i) = 2.d0 * tp(i-1)\n enddo\nendif\n\n! Find the largest power of two less than or equal to p.\n\ndo i = 1, ntp\n if (tp(i) .gt. p) goto 100\nenddo\n\n100 continue\n\npt1 = tp(i-1)\np1 = p\nr = 1.d0\n\n! Perform the binary exponentiation scheme.\n\n110 continue\n\nif (p1 .ge. pt1) then\n r = mod (16.d0 * r, ak)\n p1 = p1 - pt1\nendif\npt1 = 0.5d0 * pt1\nif (pt1 .ge. 1.d0) then\n r = mod (r * r, ak)\n goto 110\nendif\n\nexpm1 = mod (r, ak)\n\nreturn\nend\n", "meta": {"hexsha": "d0c4150303c6f2684082372a0eb3c504b8f61251", "size": 4390, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "utilities/pi/piqpr16.f90", "max_stars_repo_name": "sergev/vak-opensource", "max_stars_repo_head_hexsha": "e1912b83dabdbfab2baee5e7a9a40c3077349381", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2016-10-29T19:50:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-12T21:27:43.000Z", "max_issues_repo_path": "utilities/pi/piqpr16.f90", "max_issues_repo_name": "sergev/vak-opensource", "max_issues_repo_head_hexsha": "e1912b83dabdbfab2baee5e7a9a40c3077349381", "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": "utilities/pi/piqpr16.f90", "max_forks_repo_name": "sergev/vak-opensource", "max_forks_repo_head_hexsha": "e1912b83dabdbfab2baee5e7a9a40c3077349381", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2017-06-19T23:04:00.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-13T15:00:41.000Z", "avg_line_length": 22.6288659794, "max_line_length": 81, "alphanum_fraction": 0.6325740319, "num_tokens": 1721, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412808, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.6696735405588393}} {"text": " subroutine latin_random ( dim_num, point_num, seed, x )\r\n\r\n !*****************************************************************************80\r\n !\r\n !! LATIN_RANDOM returns points in a Latin Random square.\r\n !\r\n ! Discussion:\r\n !\r\n ! In each spatial dimension, there will be exactly one\r\n ! point whose coordinate value lies between consecutive\r\n ! values in the list:\r\n !\r\n ! ( 0, 1, 2, ..., point_num ) / point_num\r\n !\r\n ! Licensing:\r\n !\r\n ! This code is distributed under the GNU LGPL license.\r\n !\r\n ! Modified:\r\n !\r\n ! 08 April 2003\r\n !\r\n ! Author:\r\n !\r\n ! John Burkardt\r\n !\r\n ! Parameters:\r\n !\r\n ! Input, integer ( kind = 4 ) DIM_NUM, the spatial dimension.\r\n !\r\n ! Input, integer ( kind = 4 ) POINT_NUM, the number of points.\r\n !\r\n ! Input/output, integer ( kind = 4 ) SEED, a seed for the random\r\n ! number generator.\r\n !\r\n ! Output, real ( kind = 8 ) X(DIM_NUM,POINT_NUM), the points.\r\n !\r\n implicit none\r\n\r\n integer ( kind = 4 ) dim_num\r\n integer ( kind = 4 ) point_num\r\n\r\n integer ( kind = 4 ) i\r\n integer ( kind = 4 ) j\r\n integer ( kind = 4 ) perm(point_num)\r\n integer ( kind = 4 ) seed\r\n real ( kind = 8 ) x(dim_num,point_num)\r\n !\r\n ! Pick DIM_NUM * POINT_NUM random numbers between 0 and 1.\r\n !\r\n call r8mat_uniform_01 ( dim_num, point_num, seed, x )\r\n !\r\n ! For spatial dimension I,\r\n ! pick a random permutation of 1 to POINT_NUM,\r\n ! force the corresponding I-th components of X to lie in the\r\n ! interval ( PERM(J)-1, PERM(J) ) / POINT_NUM.\r\n !\r\n do i = 1, dim_num\r\n\r\n call perm_uniform ( point_num, seed, perm )\r\n\r\n do j = 1, point_num\r\n x(i,j) = ( real ( perm(j) - 1, kind = 8 ) + x(i,j) ) &\r\n / real ( point_num, kind = 8 )\r\n end do\r\n\r\n end do\r\n\r\n return\r\n end\r\n subroutine get_seed ( seed )\r\n\r\n !*****************************************************************************80\r\n !\r\n !! GET_SEED returns a seed for the random number generator.\r\n !\r\n ! Discussion:\r\n !\r\n ! The seed depends on the current time, and ought to be (slightly)\r\n ! different every millisecond. Once the seed is obtained, a random\r\n ! number generator should be called a few times to further process\r\n ! the seed.\r\n !\r\n ! Licensing:\r\n !\r\n ! This code is distributed under the GNU LGPL license.\r\n !\r\n ! Modified:\r\n !\r\n ! 02 August 2004\r\n !\r\n ! Author:\r\n !\r\n ! John Burkardt\r\n !\r\n ! Parameters:\r\n !\r\n ! Output, integer ( kind = 4 ) SEED, a pseudorandom seed value.\r\n !\r\n implicit none\r\n\r\n integer ( kind = 4 ) seed\r\n real ( kind = 8 ) temp\r\n character ( len = 10 ) time\r\n character ( len = 8 ) today\r\n integer ( kind = 4 ) values(8)\r\n character ( len = 5 ) zone\r\n\r\n call date_and_time ( today, time, zone, values )\r\n\r\n temp = 0.0D+00\r\n\r\n temp = temp + real ( values(2) - 1, kind = 8 ) / 11.0D+00\r\n temp = temp + real ( values(3) - 1, kind = 8 ) / 30.0D+00\r\n temp = temp + real ( values(5), kind = 8 ) / 23.0D+00\r\n temp = temp + real ( values(6), kind = 8 ) / 59.0D+00\r\n temp = temp + real ( values(7), kind = 8 ) / 59.0D+00\r\n temp = temp + real ( values(8), kind = 8 ) / 999.0D+00\r\n temp = temp / 6.0D+00\r\n\r\n do while ( temp <= 0.0D+00 )\r\n temp = temp + 1.0D+00\r\n end do\r\n\r\n do while ( 1.0D+00 < temp )\r\n temp = temp - 1.0D+00\r\n end do\r\n\r\n seed = int ( real ( huge ( 1 ), kind = 8 ) * temp )\r\n !\r\n ! Never use a seed of 0 or maximum integer ( kind = 4 ).\r\n !\r\n if ( seed == 0 ) then\r\n seed = 1\r\n end if\r\n\r\n if ( seed == huge ( 1 ) ) then\r\n seed = seed - 1\r\n end if\r\n\r\n return\r\n end\r\n subroutine get_unit ( iunit )\r\n\r\n !*****************************************************************************80\r\n !\r\n !! GET_UNIT returns a free FORTRAN unit number.\r\n !\r\n ! Discussion:\r\n !\r\n ! A \"free\" FORTRAN unit number is a value between 1 and 99 which\r\n ! is not currently associated with an I/O device. A free FORTRAN unit\r\n ! number is needed in order to open a file with the OPEN command.\r\n !\r\n ! If IUNIT = 0, then no free FORTRAN unit could be found, although\r\n ! all 99 units were checked (except for units 5, 6 and 9, which\r\n ! are commonly reserved for console I/O).\r\n !\r\n ! Otherwise, IUNIT is a value between 1 and 99, representing a\r\n ! free FORTRAN unit. Note that GET_UNIT assumes that units 5 and 6\r\n ! are special, and will never return those values.\r\n !\r\n ! Licensing:\r\n !\r\n ! This code is distributed under the GNU LGPL license.\r\n !\r\n ! Modified:\r\n !\r\n ! 18 September 2005\r\n !\r\n ! Author:\r\n !\r\n ! John Burkardt\r\n !\r\n ! Parameters:\r\n !\r\n ! Output, integer ( kind = 4 ) IUNIT, the free unit number.\r\n !\r\n implicit none\r\n\r\n integer ( kind = 4 ) i\r\n integer ( kind = 4 ) ios\r\n integer ( kind = 4 ) iunit\r\n logical lopen\r\n\r\n iunit = 0\r\n\r\n do i = 1, 99\r\n\r\n if ( i /= 5 .and. i /= 6 .and. i /= 9 ) then\r\n\r\n inquire ( unit = i, opened = lopen, iostat = ios )\r\n\r\n if ( ios == 0 ) then\r\n if ( .not. lopen ) then\r\n iunit = i\r\n return\r\n end if\r\n end if\r\n\r\n end if\r\n\r\n end do\r\n\r\n return\r\n end\r\n function i4_uniform_ab ( a, b, seed )\r\n\r\n !*****************************************************************************80\r\n !\r\n !! I4_UNIFORM_AB returns a scaled pseudorandom I4 between A and B.\r\n !\r\n ! Discussion:\r\n !\r\n ! An I4 is an integer ( kind = 4 ) value.\r\n !\r\n ! The pseudorandom number will be scaled to be uniformly distributed\r\n ! between A and B.\r\n !\r\n ! Licensing:\r\n !\r\n ! This code is distributed under the GNU LGPL license. \r\n !\r\n ! Modified:\r\n !\r\n ! 02 October 2012\r\n !\r\n ! Author:\r\n !\r\n ! John Burkardt\r\n !\r\n ! Reference:\r\n !\r\n ! Paul Bratley, Bennett Fox, Linus Schrage,\r\n ! A Guide to Simulation,\r\n ! Second Edition,\r\n ! Springer, 1987,\r\n ! ISBN: 0387964673,\r\n ! LC: QA76.9.C65.B73.\r\n !\r\n ! Bennett Fox,\r\n ! Algorithm 647:\r\n ! Implementation and Relative Efficiency of Quasirandom\r\n ! Sequence Generators,\r\n ! ACM Transactions on Mathematical Software,\r\n ! Volume 12, Number 4, December 1986, pages 362-376.\r\n !\r\n ! Pierre L'Ecuyer,\r\n ! Random Number Generation,\r\n ! in Handbook of Simulation,\r\n ! edited by Jerry Banks,\r\n ! Wiley, 1998,\r\n ! ISBN: 0471134031,\r\n ! LC: T57.62.H37.\r\n !\r\n ! Peter Lewis, Allen Goodman, James Miller,\r\n ! A Pseudo-Random Number Generator for the System/360,\r\n ! IBM Systems Journal,\r\n ! Volume 8, Number 2, 1969, pages 136-143.\r\n !\r\n ! Parameters:\r\n !\r\n ! Input, integer ( kind = 4 ) A, B, the limits of the interval.\r\n !\r\n ! Input/output, integer ( kind = 4 ) SEED, the \"seed\" value, which\r\n ! should NOT be 0. On output, SEED has been updated.\r\n !\r\n ! Output, integer ( kind = 4 ) I4_UNIFORM_AB, a number between A and B.\r\n !\r\n implicit none\r\n\r\n integer ( kind = 4 ) a\r\n integer ( kind = 4 ) b\r\n integer ( kind = 4 ), parameter :: i4_huge = 2147483647\r\n integer ( kind = 4 ) i4_uniform_ab\r\n integer ( kind = 4 ) k\r\n real ( kind = 4 ) r\r\n integer ( kind = 4 ) seed\r\n integer ( kind = 4 ) value\r\n\r\n if ( seed == 0 ) then\r\n write ( *, '(a)' ) ' '\r\n write ( *, '(a)' ) 'I4_UNIFORM_AB - Fatal error!'\r\n write ( *, '(a)' ) ' Input value of SEED = 0.'\r\n stop 1\r\n end if\r\n\r\n k = seed / 127773\r\n\r\n seed = 16807 * ( seed - k * 127773 ) - k * 2836\r\n\r\n if ( seed < 0 ) then\r\n seed = seed + i4_huge\r\n end if\r\n\r\n r = real ( seed, kind = 4 ) * 4.656612875E-10\r\n !\r\n ! Scale R to lie between A-0.5 and B+0.5.\r\n !\r\n r = ( 1.0E+00 - r ) * ( real ( min ( a, b ), kind = 4 ) - 0.5E+00 ) & \r\n + r * ( real ( max ( a, b ), kind = 4 ) + 0.5E+00 )\r\n !\r\n ! Use rounding to convert R to an integer between A and B.\r\n !\r\n value = nint ( r, kind = 4 )\r\n\r\n value = max ( value, min ( a, b ) )\r\n value = min ( value, max ( a, b ) )\r\n\r\n i4_uniform_ab = value\r\n\r\n return\r\n end\r\n subroutine perm_uniform ( n, seed, p )\r\n\r\n !*****************************************************************************80\r\n !\r\n !! PERM_UNIFORM selects a random permutation of N objects.\r\n !\r\n ! Licensing:\r\n !\r\n ! This code is distributed under the GNU LGPL license.\r\n !\r\n ! Modified:\r\n !\r\n ! 18 November 2008\r\n !\r\n ! Author:\r\n !\r\n ! John Burkardt\r\n !\r\n ! Reference:\r\n !\r\n ! Albert Nijenhuis, Herbert Wilf,\r\n ! Combinatorial Algorithms for Computers and Calculators,\r\n ! Academic Press, 1978,\r\n ! ISBN: 0-12-519260-6,\r\n ! LC: QA164.N54.\r\n !\r\n ! Parameters:\r\n !\r\n ! Input, integer ( kind = 4 ) N, the number of objects to be permuted.\r\n !\r\n ! Input/output, integer ( kind = 4 ) SEED, a seed for the random\r\n ! number generator.\r\n !\r\n ! Output, integer ( kind = 4 ) P(N), the permutation. P(I) is the \"new\"\r\n ! location of the object originally at I.\r\n !\r\n implicit none\r\n\r\n integer ( kind = 4 ) n\r\n\r\n integer ( kind = 4 ) i\r\n integer ( kind = 4 ) i4_uniform_ab\r\n integer ( kind = 4 ) j\r\n integer ( kind = 4 ) k\r\n integer ( kind = 4 ) p(n)\r\n integer ( kind = 4 ) seed\r\n\r\n do i = 1, n\r\n p(i) = i\r\n end do\r\n\r\n do i = 1, n - 1\r\n j = i4_uniform_ab ( i, n, seed )\r\n k = p(i)\r\n p(i) = p(j)\r\n p(j) = k\r\n end do\r\n\r\n return\r\n end\r\n subroutine r8mat_transpose_print ( m, n, a, title )\r\n\r\n !*****************************************************************************80\r\n !\r\n !! R8MAT_TRANSPOSE_PRINT prints an R8MAT, transposed.\r\n !\r\n ! Discussion:\r\n !\r\n ! An R8MAT is an MxN array of R8's, stored by (I,J) -> [I+J*M].\r\n !\r\n ! Licensing:\r\n !\r\n ! This code is distributed under the GNU LGPL license.\r\n !\r\n ! Modified:\r\n !\r\n ! 14 June 2004\r\n !\r\n ! Author:\r\n !\r\n ! John Burkardt\r\n !\r\n ! Parameters:\r\n !\r\n ! Input, integer ( kind = 4 ) M, N, the number of rows and columns.\r\n !\r\n ! Input, real ( kind = 8 ) A(M,N), an M by N matrix to be printed.\r\n !\r\n ! Input, character ( len = * ) TITLE, a title.\r\n !\r\n implicit none\r\n\r\n integer ( kind = 4 ) m\r\n integer ( kind = 4 ) n\r\n\r\n real ( kind = 8 ) a(m,n)\r\n character ( len = * ) title\r\n\r\n call r8mat_transpose_print_some ( m, n, a, 1, 1, m, n, title )\r\n\r\n return\r\n end\r\n subroutine r8mat_transpose_print_some ( m, n, a, ilo, jlo, ihi, jhi, title )\r\n\r\n !*****************************************************************************80\r\n !\r\n !! R8MAT_TRANSPOSE_PRINT_SOME prints some of an R8MAT, transposed.\r\n !\r\n ! Discussion:\r\n !\r\n ! An R8MAT is an MxN array of R8's, stored by (I,J) -> [I+J*M].\r\n !\r\n ! Licensing:\r\n !\r\n ! This code is distributed under the GNU LGPL license.\r\n !\r\n ! Modified:\r\n !\r\n ! 10 September 2009\r\n !\r\n ! Author:\r\n !\r\n ! John Burkardt\r\n !\r\n ! Parameters:\r\n !\r\n ! Input, integer ( kind = 4 ) M, N, the number of rows and columns.\r\n !\r\n ! Input, real ( kind = 8 ) A(M,N), an M by N matrix to be printed.\r\n !\r\n ! Input, integer ( kind = 4 ) ILO, JLO, the first row and column to print.\r\n !\r\n ! Input, integer ( kind = 4 ) IHI, JHI, the last row and column to print.\r\n !\r\n ! Input, character ( len = * ) TITLE, a title.\r\n !\r\n implicit none\r\n\r\n integer ( kind = 4 ), parameter :: incx = 5\r\n integer ( kind = 4 ) m\r\n integer ( kind = 4 ) n\r\n\r\n real ( kind = 8 ) a(m,n)\r\n character ( len = 14 ) ctemp(incx)\r\n integer ( kind = 4 ) i\r\n integer ( kind = 4 ) i2\r\n integer ( kind = 4 ) i2hi\r\n integer ( kind = 4 ) i2lo\r\n integer ( kind = 4 ) ihi\r\n integer ( kind = 4 ) ilo\r\n integer ( kind = 4 ) inc\r\n integer ( kind = 4 ) j\r\n integer ( kind = 4 ) j2hi\r\n integer ( kind = 4 ) j2lo\r\n integer ( kind = 4 ) jhi\r\n integer ( kind = 4 ) jlo\r\n character ( len = * ) title\r\n\r\n write ( *, '(a)' ) ' '\r\n write ( *, '(a)' ) trim ( title )\r\n\r\n if ( m <= 0 .or. n <= 0 ) then\r\n write ( *, '(a)' ) ' '\r\n write ( *, '(a)' ) ' (None)'\r\n return\r\n end if\r\n\r\n do i2lo = max ( ilo, 1 ), min ( ihi, m ), incx\r\n\r\n i2hi = i2lo + incx - 1\r\n i2hi = min ( i2hi, m )\r\n i2hi = min ( i2hi, ihi )\r\n\r\n inc = i2hi + 1 - i2lo\r\n\r\n write ( *, '(a)' ) ' '\r\n\r\n do i = i2lo, i2hi\r\n i2 = i + 1 - i2lo\r\n write ( ctemp(i2), '(i8,6x)' ) i\r\n end do\r\n\r\n write ( *, '('' Row '',5a14)' ) ctemp(1:inc)\r\n write ( *, '(a)' ) ' Col'\r\n write ( *, '(a)' ) ' '\r\n\r\n j2lo = max ( jlo, 1 )\r\n j2hi = min ( jhi, n )\r\n\r\n do j = j2lo, j2hi\r\n\r\n do i2 = 1, inc\r\n i = i2lo - 1 + i2\r\n write ( ctemp(i2), '(g14.6)' ) a(i,j)\r\n end do\r\n\r\n write ( *, '(i5,a,5a14)' ) j, ':', ( ctemp(i), i = 1, inc )\r\n\r\n end do\r\n\r\n end do\r\n\r\n return\r\n end\r\n subroutine r8mat_uniform_01 ( m, n, seed, r )\r\n\r\n !*****************************************************************************80\r\n !\r\n !! R8MAT_UNIFORM_01 fills an R8MAT with unit pseudorandom numbers.\r\n !\r\n ! Discussion:\r\n !\r\n ! An R8MAT is an MxN array of R8's, stored by (I,J) -> [I+J*M].\r\n !\r\n ! Licensing:\r\n !\r\n ! This code is distributed under the GNU LGPL license.\r\n !\r\n ! Modified:\r\n !\r\n ! 11 August 2004\r\n !\r\n ! Author:\r\n !\r\n ! John Burkardt\r\n !\r\n ! Reference:\r\n !\r\n ! Paul Bratley, Bennett Fox, Linus Schrage,\r\n ! A Guide to Simulation,\r\n ! Springer Verlag, pages 201-202, 1983.\r\n !\r\n ! Bennett Fox,\r\n ! Algorithm 647:\r\n ! Implementation and Relative Efficiency of Quasirandom\r\n ! Sequence Generators,\r\n ! ACM Transactions on Mathematical Software,\r\n ! Volume 12, Number 4, pages 362-376, 1986.\r\n !\r\n ! Peter Lewis, Allen Goodman, James Miller,\r\n ! A Pseudo-Random Number Generator for the System/360,\r\n ! IBM Systems Journal,\r\n ! Volume 8, pages 136-143, 1969.\r\n !\r\n ! Parameters:\r\n !\r\n ! Input, integer ( kind = 4 ) M, N, the number of rows and columns in\r\n ! the array.\r\n !\r\n ! Input/output, integer ( kind = 4 ) SEED, the \"seed\" value, which\r\n ! should NOT be 0. On output, SEED has been updated.\r\n !\r\n ! Output, real ( kind = 8 ) R(M,N), the array of pseudorandom values.\r\n !\r\n implicit none\r\n\r\n integer ( kind = 4 ) m\r\n integer ( kind = 4 ) n\r\n\r\n integer ( kind = 4 ) i\r\n integer ( kind = 4 ), parameter :: i4_huge = 2147483647\r\n integer ( kind = 4 ) j\r\n integer ( kind = 4 ) k\r\n integer ( kind = 4 ) seed\r\n real ( kind = 8 ) r(m,n)\r\n\r\n do j = 1, n\r\n\r\n do i = 1, m\r\n\r\n k = seed / 127773\r\n\r\n seed = 16807 * ( seed - k * 127773 ) - k * 2836\r\n\r\n if ( seed < 0 ) then\r\n seed = seed + i4_huge\r\n end if\r\n\r\n r(i,j) = real ( seed, kind = 8 ) * 4.656612875D-10\r\n\r\n end do\r\n end do\r\n\r\n return\r\n end\r\n subroutine r8mat_write ( output_filename, m, n, table )\r\n\r\n !*****************************************************************************80\r\n !\r\n !! R8MAT_WRITE writes an R8MAT file.\r\n !\r\n ! Discussion:\r\n !\r\n ! An R8MAT is an array of R8 values.\r\n !\r\n ! Licensing:\r\n !\r\n ! This code is distributed under the GNU LGPL license.\r\n !\r\n ! Modified:\r\n !\r\n ! 31 May 2009\r\n !\r\n ! Author:\r\n !\r\n ! John Burkardt\r\n !\r\n ! Parameters:\r\n !\r\n ! Input, character ( len = * ) OUTPUT_FILENAME, the output file name.\r\n !\r\n ! Input, integer ( kind = 4 ) M, the spatial dimension.\r\n !\r\n ! Input, integer ( kind = 4 ) N, the number of points.\r\n !\r\n ! Input, real ( kind = 8 ) TABLE(M,N), the table data.\r\n !\r\n implicit none\r\n\r\n integer ( kind = 4 ) m\r\n integer ( kind = 4 ) n\r\n\r\n integer ( kind = 4 ) j\r\n character ( len = * ) output_filename\r\n integer ( kind = 4 ) output_status\r\n integer ( kind = 4 ) output_unit\r\n character ( len = 30 ) string\r\n real ( kind = 8 ) table(m,n)\r\n !\r\n ! Open the file.\r\n !\r\n call get_unit ( output_unit )\r\n\r\n open ( unit = output_unit, file = output_filename, &\r\n status = 'replace', iostat = output_status )\r\n\r\n if ( output_status /= 0 ) then\r\n write ( *, '(a)' ) ' '\r\n write ( *, '(a)' ) 'R8MAT_WRITE - Fatal error!'\r\n write ( *, '(a,i8)' ) ' Could not open the output file \"' // &\r\n trim ( output_filename ) // '\" on unit ', output_unit\r\n output_unit = -1\r\n stop\r\n end if\r\n !\r\n ! Create a format string.\r\n !\r\n ! For less precision in the output file, try:\r\n !\r\n ! '(', m, 'g', 14, '.', 6, ')'\r\n !\r\n if ( 0 < m .and. 0 < n ) then\r\n\r\n write ( string, '(a1,i8,a1,i8,a1,i8,a1)' ) '(', m, 'g', 24, '.', 16, ')'\r\n !\r\n ! Write the data.\r\n !\r\n do j = 1, n\r\n write ( output_unit, string ) table(1:m,j)\r\n end do\r\n\r\n end if\r\n !\r\n ! Close the file.\r\n !\r\n close ( unit = output_unit )\r\n\r\n return\r\n end\r\n subroutine timestamp ( )\r\n\r\n !*****************************************************************************80\r\n !\r\n !! TIMESTAMP prints the current YMDHMS date as a time stamp.\r\n !\r\n ! Example:\r\n !\r\n ! 31 May 2001 9:45:54.872 AM\r\n !\r\n ! Licensing:\r\n !\r\n ! This code is distributed under the GNU LGPL license.\r\n !\r\n ! Modified:\r\n !\r\n ! 18 May 2013\r\n !\r\n ! Author:\r\n !\r\n ! John Burkardt\r\n !\r\n ! Parameters:\r\n !\r\n ! None\r\n !\r\n implicit none\r\n\r\n character ( len = 8 ) ampm\r\n integer ( kind = 4 ) d\r\n integer ( kind = 4 ) h\r\n integer ( kind = 4 ) m\r\n integer ( kind = 4 ) mm\r\n character ( len = 9 ), parameter, dimension(12) :: month = (/ &\r\n 'January ', 'February ', 'March ', 'April ', &\r\n 'May ', 'June ', 'July ', 'August ', &\r\n 'September', 'October ', 'November ', 'December ' /)\r\n integer ( kind = 4 ) n\r\n integer ( kind = 4 ) s\r\n integer ( kind = 4 ) values(8)\r\n integer ( kind = 4 ) y\r\n\r\n call date_and_time ( values = values )\r\n\r\n y = values(1)\r\n m = values(2)\r\n d = values(3)\r\n h = values(5)\r\n n = values(6)\r\n s = values(7)\r\n mm = values(8)\r\n\r\n if ( h < 12 ) then\r\n ampm = 'AM'\r\n else if ( h == 12 ) then\r\n if ( n == 0 .and. s == 0 ) then\r\n ampm = 'Noon'\r\n else\r\n ampm = 'PM'\r\n end if\r\n else\r\n h = h - 12\r\n if ( h < 12 ) then\r\n ampm = 'PM'\r\n else if ( h == 12 ) then\r\n if ( n == 0 .and. s == 0 ) then\r\n ampm = 'Midnight'\r\n else\r\n ampm = 'AM'\r\n end if\r\n end if\r\n end if\r\n\r\n write ( *, '(i2.2,1x,a,1x,i4,2x,i2,a1,i2.2,a1,i2.2,a1,i3.3,1x,a)' ) &\r\n d, trim ( month(m) ), y, h, ':', n, ':', s, '.', mm, trim ( ampm )\r\n\r\n return\r\n end\r\n", "meta": {"hexsha": "bcd4ce23e2f5108bf21b200f0bd9201ca26667a8", "size": 21553, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/latin_random/latin_random.f90", "max_stars_repo_name": "maxEntropyProd/MEP-AutoHetDet", "max_stars_repo_head_hexsha": "85ac83f3b9befeee322220f6b54a98bb04f6c908", "max_stars_repo_licenses": ["MIT"], "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/latin_random/latin_random.f90", "max_issues_repo_name": "maxEntropyProd/MEP-AutoHetDet", "max_issues_repo_head_hexsha": "85ac83f3b9befeee322220f6b54a98bb04f6c908", "max_issues_repo_licenses": ["MIT"], "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/latin_random/latin_random.f90", "max_forks_repo_name": "maxEntropyProd/MEP-AutoHetDet", "max_forks_repo_head_hexsha": "85ac83f3b9befeee322220f6b54a98bb04f6c908", "max_forks_repo_licenses": ["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.3219448095, "max_line_length": 87, "alphanum_fraction": 0.4286642231, "num_tokens": 6149, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.86153820232079, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.6696735295052537}} {"text": "\n SUBROUTINE CALJY1(ARG,RESULT,JINT)\nC---------------------------------------------------------------------\nC\nC This packet computes first-order Bessel functions of the first and\nC second kind (J1 and Y1), for real arguments X, where 0 < X <= XMAX\nC for Y1, and |X| <= XMAX for J1. It contains two function-type\nC subprograms, BESJ1 and BESY1, and one subroutine-type\nC subprogram, CALJY1. The calling statements for the primary\nC entries are:\nC\nC Y = BESJ1(X)\nC and\nC Y = BESY1(X),\nC\nC where the entry points correspond to the functions J1(X) and Y1(X),\nC respectively. The routine CALJY1 is intended for internal packet\nC use only, all computations within the packet being concentrated in\nC this one routine. The function subprograms invoke CALJY1 with\nC the statement\nC CALL CALJY1(ARG,RESULT,JINT),\nC where the parameter usage is as follows:\nC\nC Function Parameters for CALJY1\nC call ARG RESULT JINT\nC\nC BESJ1(ARG) |ARG| .LE. XMAX J1(ARG) 0\nC BESY1(ARG) 0 .LT. ARG .LE. XMAX Y1(ARG) 1\nC\nC The main computation uses unpublished minimax rational\nC approximations for X .LE. 8.0, and an approximation from the\nC book Computer Approximations by Hart, et. al., Wiley and Sons,\nC New York, 1968, for arguments larger than 8.0 Part of this\nC transportable packet is patterned after the machine-dependent\nC FUNPACK program BESJ1(X), but cannot match that version for\nC efficiency or accuracy. This version uses rational functions\nC that are theoretically accurate to at least 18 significant decimal\nC digits for X <= 8, and at least 18 decimal places for X > 8. The\nC accuracy achieved depends on the arithmetic system, the compiler,\nC the intrinsic functions, and proper selection of the machine-\nC dependent constants.\nC\nC*******************************************************************\nC\nC The following machine-dependent constants must be declared in\nC DATA statements. IEEE values are provided as a default.\nC\nC XINF = largest positive machine number\nC XMAX = largest acceptable argument. The functions AINT, SIN\nC and COS must perform properly for ABS(X) .LE. XMAX.\nC We recommend that XMAX be a small integer multiple of\nC sqrt(1/eps), where eps is the smallest positive number\nC such that 1+eps > 1.\nC XSMALL = positive argument such that 1.0-(1/2)(X/2)**2 = 1.0\nC to machine precision for all ABS(X) .LE. XSMALL.\nC We recommend that XSMALL < sqrt(eps)/beta, where beta\nC is the floating-point radix (usually 2 or 16).\nC\nC Approximate values for some important machines are\nC\nC eps XMAX XSMALL XINF\nC\nC CDC 7600 (S.P.) 7.11E-15 1.34E+08 2.98E-08 1.26E+322\nC CRAY-1 (S.P.) 7.11E-15 1.34E+08 2.98E-08 5.45E+2465\nC IBM PC (8087) (S.P.) 5.96E-08 8.19E+03 1.22E-04 3.40E+38\nC IBM PC (8087) (D.P.) 1.11D-16 2.68D+08 3.72D-09 1.79D+308\nC IBM 195 (D.P.) 2.22D-16 6.87D+09 9.09D-13 7.23D+75\nC UNIVAC 1108 (D.P.) 1.73D-18 4.30D+09 2.33D-10 8.98D+307\nC VAX 11/780 (D.P.) 1.39D-17 1.07D+09 9.31D-10 1.70D+38\nC\nC*******************************************************************\nC*******************************************************************\nC\nC Error Returns\nC\nC The program returns the value zero for X .GT. XMAX, and returns\nC -XINF when BESLY1 is called with a negative or zero argument.\nC\nC\nC Intrinsic functions required are:\nC\nC ABS, AINT, COS, LOG, SIN, SQRT\nC\nC\nC Author: W. J. Cody\nC Mathematics and Computer Science Division\nC Argonne National Laboratory\nC Argonne, IL 60439\nC\nC Latest modification: March 13, 1992\nC\nC--------------------------------------------------------------------\n INTEGER I,JINT\n DIMENSION PJ0(7),PJ1(8),PLG(4),PY0(7),PY1(9),P0(6),P1(6),\n 1 QJ0(5),QJ1(7),QLG(4),QY0(6),QY1(8),Q0(6),Q1(6)\nCS REAL\n DOUBLE PRECISION\n 1 ARG,AX,DOWN,EIGHT,FOUR,HALF,PI2,PJ0,PJ1,PLG,PROD,PY0,\n 2 PY1,P0,P1,P17,QJ0,QJ1,QLG,QY0,QY1,Q0,Q1,RESJ,RESULT,\n 3 RTPI2,R0,R1,THROV8,TWOPI,TWOPI1,TWOPI2,TWO56,UP,W,WSQ,\n 4 XDEN,XINF,XMAX,XNUM,XSMALL,XJ0,XJ1,XJ01,XJ02,XJ11,XJ12,\n 5 XY,XY0,XY01,XY02,XY1,XY11,XY12,Z,ZERO,ZSQ\nC-------------------------------------------------------------------\nC Mathematical constants\nC-------------------------------------------------------------------\nCS DATA EIGHT/8.0E0/,\nCS 1 FOUR/4.0E0/,HALF/0.5E0/,THROV8/0.375E0/,\nCS 2 PI2/6.3661977236758134308E-1/,P17/1.716E-1/\nCS 3 TWOPI/6.2831853071795864769E+0/,ZERO/0.0E0/,\nCS 4 TWOPI1/6.28125E0/,TWOPI2/1.9353071795864769253E-03/\nCS 5 TWO56/256.0E+0/,RTPI2/7.9788456080286535588E-1/\n DATA EIGHT/8.0D0/,\n 1 FOUR/4.0D0/,HALF/0.5D0/,THROV8/0.375D0/,\n 2 PI2/6.3661977236758134308D-1/,P17/1.716D-1/\n 3 TWOPI/6.2831853071795864769D+0/,ZERO/0.0D0/,\n 4 TWOPI1/6.28125D0/,TWOPI2/1.9353071795864769253D-03/\n 5 TWO56/256.0D+0/,RTPI2/7.9788456080286535588D-1/\nC-------------------------------------------------------------------\nC Machine-dependent constants\nC-------------------------------------------------------------------\nCS DATA XMAX/8.19E+03/,XSMALL/1.22E-04/,XINF/3.40E+38/\n DATA XMAX/2.68D+08/,XSMALL/3.72D-09/,XINF/1.79D+308/\nC-------------------------------------------------------------------\nC Zeroes of Bessel functions\nC-------------------------------------------------------------------\nCS DATA XJ0/3.8317059702075123156E+0/,XJ1/7.0155866698156187535E+0/,\nCS 1 XY0/2.1971413260310170351E+0/,XY1/5.4296810407941351328E+0/,\nCS 2 XJ01/ 981.0E+0/, XJ02/-3.2527979248768438556E-04/,\nCS 3 XJ11/1796.0E+0/, XJ12/-3.8330184381246462950E-05/,\nCS 4 XY01/ 562.0E+0/, XY02/ 1.8288260310170351490E-03/,\nCS 5 XY11/1390.0E+0/, XY12/-6.4592058648672279948E-06/\n DATA XJ0/3.8317059702075123156D+0/,XJ1/7.0155866698156187535D+0/,\n 1 XY0/2.1971413260310170351D+0/,XY1/5.4296810407941351328D+0/,\n 2 XJ01/ 981.0D+0/, XJ02/-3.2527979248768438556D-04/,\n 3 XJ11/1796.0D+0/, XJ12/-3.8330184381246462950D-05/,\n 4 XY01/ 562.0D+0/, XY02/ 1.8288260310170351490D-03/,\n 5 XY11/1390.0D+0/, XY12/-6.4592058648672279948D-06/\nC-------------------------------------------------------------------\nC Coefficients for rational approximation to ln(x/a)\nC--------------------------------------------------------------------\nCS DATA PLG/-2.4562334077563243311E+01,2.3642701335621505212E+02,\nCS 1 -5.4989956895857911039E+02,3.5687548468071500413E+02/\nCS DATA QLG/-3.5553900764052419184E+01,1.9400230218539473193E+02,\nCS 1 -3.3442903192607538956E+02,1.7843774234035750207E+02/\n DATA PLG/-2.4562334077563243311D+01,2.3642701335621505212D+02,\n 1 -5.4989956895857911039D+02,3.5687548468071500413D+02/\n DATA QLG/-3.5553900764052419184D+01,1.9400230218539473193D+02,\n 1 -3.3442903192607538956D+02,1.7843774234035750207D+02/\nC-------------------------------------------------------------------\nC Coefficients for rational approximation of\nC J1(X) / (X * (X**2 - XJ0**2)), XSMALL < |X| <= 4.0\nC--------------------------------------------------------------------\nCS DATA PJ0/9.8062904098958257677E+05,-1.1548696764841276794E+08,\nCS 1 6.6781041261492395835E+09,-1.4258509801366645672E+11,\nCS 2 -4.4615792982775076130E+03, 1.0650724020080236441E+01,\nCS 3 -1.0767857011487300348E-02/\nCS DATA QJ0/5.9117614494174794095E+05, 2.0228375140097033958E+08,\nCS 1 4.2091902282580133541E+10, 4.1868604460820175290E+12,\nCS 2 1.0742272239517380498E+03/\n DATA PJ0/9.8062904098958257677D+05,-1.1548696764841276794D+08,\n 1 6.6781041261492395835D+09,-1.4258509801366645672D+11,\n 2 -4.4615792982775076130D+03, 1.0650724020080236441D+01,\n 3 -1.0767857011487300348D-02/\n DATA QJ0/5.9117614494174794095D+05, 2.0228375140097033958D+08,\n 1 4.2091902282580133541D+10, 4.1868604460820175290D+12,\n 2 1.0742272239517380498D+03/\nC-------------------------------------------------------------------\nC Coefficients for rational approximation of\nC J1(X) / (X * (X**2 - XJ1**2)), 4.0 < |X| <= 8.0\nC-------------------------------------------------------------------\nCS DATA PJ1/4.6179191852758252280E+00,-7.1329006872560947377E+03,\nCS 1 4.5039658105749078904E+06,-1.4437717718363239107E+09,\nCS 2 2.3569285397217157313E+11,-1.6324168293282543629E+13,\nCS 3 1.1357022719979468624E+14, 1.0051899717115285432E+15/\nCS DATA QJ1/1.1267125065029138050E+06, 6.4872502899596389593E+08,\nCS 1 2.7622777286244082666E+11, 8.4899346165481429307E+13,\nCS 2 1.7128800897135812012E+16, 1.7253905888447681194E+18,\nCS 3 1.3886978985861357615E+03/\n DATA PJ1/4.6179191852758252280D+00,-7.1329006872560947377D+03,\n 1 4.5039658105749078904D+06,-1.4437717718363239107D+09,\n 2 2.3569285397217157313D+11,-1.6324168293282543629D+13,\n 3 1.1357022719979468624D+14, 1.0051899717115285432D+15/\n DATA QJ1/1.1267125065029138050D+06, 6.4872502899596389593D+08,\n 1 2.7622777286244082666D+11, 8.4899346165481429307D+13,\n 2 1.7128800897135812012D+16, 1.7253905888447681194D+18,\n 3 1.3886978985861357615D+03/\nC-------------------------------------------------------------------\nC Coefficients for rational approximation of\nC (Y1(X) - 2 LN(X/XY0) J1(X)) / (X**2 - XY0**2),\nC XSMALL < |X| <= 4.0\nC--------------------------------------------------------------------\nCS DATA PY0/2.2157953222280260820E+05,-5.9157479997408395984E+07,\nCS 1 7.2144548214502560419E+09,-3.7595974497819597599E+11,\nCS 2 5.4708611716525426053E+12, 4.0535726612579544093E+13,\nCS 3 -3.1714424660046133456E+02/\nCS DATA QY0/8.2079908168393867438E+02, 3.8136470753052572164E+05,\nCS 1 1.2250435122182963220E+08, 2.7800352738690585613E+10,\nCS 2 4.1272286200406461981E+12, 3.0737873921079286084E+14/\n DATA PY0/2.2157953222280260820D+05,-5.9157479997408395984D+07,\n 1 7.2144548214502560419D+09,-3.7595974497819597599D+11,\n 2 5.4708611716525426053D+12, 4.0535726612579544093D+13,\n 3 -3.1714424660046133456D+02/\n DATA QY0/8.2079908168393867438D+02, 3.8136470753052572164D+05,\n 1 1.2250435122182963220D+08, 2.7800352738690585613D+10,\n 2 4.1272286200406461981D+12, 3.0737873921079286084D+14/\nC--------------------------------------------------------------------\nC Coefficients for rational approximation of\nC (Y1(X) - 2 LN(X/XY1) J1(X)) / (X**2 - XY1**2),\nC 4.0 < |X| <= 8.0\nC--------------------------------------------------------------------\nCS DATA PY1/ 1.9153806858264202986E+06,-1.1957961912070617006E+09,\nCS 1 3.7453673962438488783E+11,-5.9530713129741981618E+13,\nCS 2 4.0686275289804744814E+15,-2.3638408497043134724E+16,\nCS 3 -5.6808094574724204577E+18, 1.1514276357909013326E+19,\nCS 4 -1.2337180442012953128E+03/\nCS DATA QY1/ 1.2855164849321609336E+03, 1.0453748201934079734E+06,\nCS 1 6.3550318087088919566E+08, 3.0221766852960403645E+11,\nCS 2 1.1187010065856971027E+14, 3.0837179548112881950E+16,\nCS 3 5.6968198822857178911E+18, 5.3321844313316185697E+20/\n DATA PY1/ 1.9153806858264202986D+06,-1.1957961912070617006D+09,\n 1 3.7453673962438488783D+11,-5.9530713129741981618D+13,\n 2 4.0686275289804744814D+15,-2.3638408497043134724D+16,\n 3 -5.6808094574724204577D+18, 1.1514276357909013326D+19,\n 4 -1.2337180442012953128D+03/\n DATA QY1/ 1.2855164849321609336D+03, 1.0453748201934079734D+06,\n 1 6.3550318087088919566D+08, 3.0221766852960403645D+11,\n 2 1.1187010065856971027D+14, 3.0837179548112881950D+16,\n 3 5.6968198822857178911D+18, 5.3321844313316185697D+20/\nC-------------------------------------------------------------------\nC Coefficients for Hart,s approximation, |X| > 8.0\nC-------------------------------------------------------------------\nCS DATA P0/-1.0982405543459346727E+05,-1.5235293511811373833E+06,\nCS 1 -6.6033732483649391093E+06,-9.9422465050776411957E+06,\nCS 2 -4.4357578167941278571E+06,-1.6116166443246101165E+03/\nCS DATA Q0/-1.0726385991103820119E+05,-1.5118095066341608816E+06,\nCS 1 -6.5853394797230870728E+06,-9.9341243899345856590E+06,\nCS 2 -4.4357578167941278568E+06,-1.4550094401904961825E+03/\nCS DATA P1/ 1.7063754290207680021E+03, 1.8494262873223866797E+04,\nCS 1 6.6178836581270835179E+04, 8.5145160675335701966E+04,\nCS 2 3.3220913409857223519E+04, 3.5265133846636032186E+01/\nCS DATA Q1/ 3.7890229745772202641E+04, 4.0029443582266975117E+05,\nCS 1 1.4194606696037208929E+06, 1.8194580422439972989E+06,\nCS 2 7.0871281941028743574E+05, 8.6383677696049909675E+02/\n DATA P0/-1.0982405543459346727D+05,-1.5235293511811373833D+06,\n 1 -6.6033732483649391093D+06,-9.9422465050776411957D+06,\n 2 -4.4357578167941278571D+06,-1.6116166443246101165D+03/\n DATA Q0/-1.0726385991103820119D+05,-1.5118095066341608816D+06,\n 1 -6.5853394797230870728D+06,-9.9341243899345856590D+06,\n 2 -4.4357578167941278568D+06,-1.4550094401904961825D+03/\n DATA P1/ 1.7063754290207680021D+03, 1.8494262873223866797D+04,\n 1 6.6178836581270835179D+04, 8.5145160675335701966D+04,\n 2 3.3220913409857223519D+04, 3.5265133846636032186D+01/\n DATA Q1/ 3.7890229745772202641D+04, 4.0029443582266975117D+05,\n 1 1.4194606696037208929D+06, 1.8194580422439972989D+06,\n 2 7.0871281941028743574D+05, 8.6383677696049909675D+02/\nC-------------------------------------------------------------------\nC Check for error conditions\nC-------------------------------------------------------------------\n AX = ABS(ARG)\n IF ((JINT .EQ. 1) .AND. ((ARG .LE. ZERO) .OR.\n 1 ((ARG .LT. HALF) .AND. (AX*XINF .LT. PI2)))) THEN\n RESULT = -XINF\n GO TO 2000\n ELSE IF (AX .GT. XMAX) THEN\n RESULT = ZERO\n GO TO 2000\n END IF\n IF (AX .GT. EIGHT) THEN\n GO TO 800\n ELSE IF (AX .LE. XSMALL) THEN\n IF (JINT .EQ. 0) THEN\n RESULT = ARG * HALF\n ELSE\n RESULT = -PI2 / AX\n END IF\n GO TO 2000\n END IF\nC-------------------------------------------------------------------\nC Calculate J1 for appropriate interval, preserving\nC accuracy near the zero of J1\nC-------------------------------------------------------------------\n ZSQ = AX * AX\n IF (AX .LE. FOUR) THEN\n XNUM = (PJ0(7) * ZSQ + PJ0(6)) * ZSQ + PJ0(5)\n XDEN = ZSQ + QJ0(5)\n DO 50 I = 1, 4\n XNUM = XNUM * ZSQ + PJ0(I)\n XDEN = XDEN * ZSQ + QJ0(I)\n 50 CONTINUE\n PROD = ARG * ((AX - XJ01/TWO56) - XJ02) * (AX + XJ0)\n ELSE\n XNUM = PJ1(1)\n XDEN = (ZSQ + QJ1(7)) * ZSQ + QJ1(1)\n DO 220 I = 2, 6\n XNUM = XNUM * ZSQ + PJ1(I)\n XDEN = XDEN * ZSQ + QJ1(I)\n 220 CONTINUE\n XNUM = XNUM * (AX - EIGHT) * (AX + EIGHT) + PJ1(7)\n XNUM = XNUM * (AX - FOUR) * (AX + FOUR) + PJ1(8)\n PROD = ARG * ((AX - XJ11/TWO56) - XJ12) * (AX + XJ1)\n END IF\n RESULT = PROD * (XNUM / XDEN)\n IF (JINT .EQ. 0) GO TO 2000\nC-------------------------------------------------------------------\nC Calculate Y1. First find RESJ = pi/2 ln(x/xn) J1(x),\nC where xn is a zero of Y1\nC-------------------------------------------------------------------\n IF (AX .LE. FOUR) THEN\n UP = (AX-XY01/TWO56)-XY02\n XY = XY0\n ELSE\n UP = (AX-XY11/TWO56)-XY12\n XY = XY1\n END IF\n DOWN = AX + XY\n IF (ABS(UP) .LT. P17*DOWN) THEN\n W = UP/DOWN\n WSQ = W*W\n XNUM = PLG(1)\n XDEN = WSQ + QLG(1)\n DO 320 I = 2, 4\n XNUM = XNUM*WSQ + PLG(I)\n XDEN = XDEN*WSQ + QLG(I)\n 320 CONTINUE\n RESJ = PI2 * RESULT * W * XNUM/XDEN\n ELSE\n RESJ = PI2 * RESULT * LOG(AX/XY)\n END IF\nC-------------------------------------------------------------------\nC Now calculate Y1 for appropriate interval, preserving\nC accuracy near the zero of Y1\nC-------------------------------------------------------------------\n IF (AX .LE. FOUR) THEN\n XNUM = PY0(7) * ZSQ + PY0(1)\n XDEN = ZSQ + QY0(1)\n DO 340 I = 2, 6\n XNUM = XNUM * ZSQ + PY0(I)\n XDEN = XDEN * ZSQ + QY0(I)\n 340 CONTINUE\n ELSE\n XNUM = PY1(9) * ZSQ + PY1(1)\n XDEN = ZSQ + QY1(1)\n DO 360 I = 2, 8\n XNUM = XNUM * ZSQ + PY1(I)\n XDEN = XDEN * ZSQ + QY1(I)\n 360 CONTINUE\n END IF\n RESULT = RESJ + (UP*DOWN/AX) * XNUM / XDEN\n GO TO 2000\nC-------------------------------------------------------------------\nC Calculate J1 or Y1 for |ARG| > 8.0\nC-------------------------------------------------------------------\n 800 Z = EIGHT / AX\n W = AINT(AX/TWOPI) + THROV8\n W = (AX - W * TWOPI1) - W * TWOPI2\n ZSQ = Z * Z\n XNUM = P0(6)\n XDEN = ZSQ + Q0(6)\n UP = P1(6)\n DOWN = ZSQ + Q1(6)\n DO 850 I = 1, 5\n XNUM = XNUM * ZSQ + P0(I)\n XDEN = XDEN * ZSQ + Q0(I)\n UP = UP * ZSQ + P1(I)\n DOWN = DOWN * ZSQ + Q1(I)\n 850 CONTINUE\n R0 = XNUM / XDEN\n R1 = UP / DOWN\n IF (JINT .EQ. 0) THEN\n RESULT = (RTPI2/SQRT(AX)) * (R0*COS(W) - Z*R1*SIN(W))\n ELSE\n RESULT = (RTPI2/SQRT(AX)) * (R0*SIN(W) + Z*R1*COS(W))\n END IF\n IF ((JINT .EQ. 0) .AND. (ARG .LT. ZERO)) RESULT = -RESULT\n 2000 RETURN\nC---------- Last card of CALJY1 ----------\n END\n", "meta": {"hexsha": "97922a1aae27dfb5801e20d837d9904bf239a7e0", "size": 18325, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/f2cl/packages/toms/715/caljy1.f", "max_stars_repo_name": "sbwhitecap/clocc-hg", "max_stars_repo_head_hexsha": "f6cf2591ceef8a3a80e04da9b414cdf60a25a90f", "max_stars_repo_licenses": ["MIT"], "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/f2cl/packages/toms/715/caljy1.f", "max_issues_repo_name": "sbwhitecap/clocc-hg", "max_issues_repo_head_hexsha": "f6cf2591ceef8a3a80e04da9b414cdf60a25a90f", "max_issues_repo_licenses": ["MIT"], "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/f2cl/packages/toms/715/caljy1.f", "max_forks_repo_name": "sbwhitecap/clocc-hg", "max_forks_repo_head_hexsha": "f6cf2591ceef8a3a80e04da9b414cdf60a25a90f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.4788359788, "max_line_length": 71, "alphanum_fraction": 0.5502864939, "num_tokens": 6881, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.7401743735019595, "lm_q1q2_score": 0.6695991392510006}} {"text": "!-----------------------------------------------------------------------\nfunction sigmav_ion(Te)\n implicit none\n double precision, parameter :: Tm=2.d0 !eV\n double precision :: sigmav_ion, Te, x,y\n if(Te .lt. Tm) then\n sigmav_ion = 0.d0\n return\n endif\n x = log(Te)\n y=-3.271396786375d+01+x*(1.353655609057d+01+x*(-5.739328757388d+00 &\n +x*(1.563154982022d+00+x*(-2.877056004391d-01+x*(3.482559773737d-02 &\n +x*(-2.631976175590d-03+x*(1.119543953861d-04+x*(-2.039149852002d-06))))))))\n sigmav_ion = exp(y)\n return\nend function sigmav_ion\n!-----------------------------------------------------------------------\n!function sigmav_ion(Te)\n! implicit none\n! double precision :: sigmav_ion, Te, x, Tm=2.d0, T0=20.d0 ! eV\n! if(Te .lt. Tm) then\n! sigmav_ion = 0.d0\n! return\n! endif\n! x = log10(Te)\n! if(Te .lt. T0) then\n! sigmav_ion = 1.d1**(-3.054d0*x - 1.572d1*exp(-x) + 1.603d0*exp(-x**2))\n! else\n! sigmav_ion = 1.d1**(-5.151d-1*x -2.563d0/x - 5.231d0)\n! endif\n! return\n!end function sigmav_ion\n!-----------------------------------------------------------------------\nfunction sigmav_cx(T)\n implicit none\n double precision :: sigmav_cx, T\n double precision, save :: Tmin, Tmax, hm1, dt1, dt2\n logical, save :: firstcall=.true.\n integer, save :: nmin, nmax, ih\n integer :: i\n double precision, save, dimension(:), allocatable :: svcx\n\n if(firstcall) then\n firstcall = .false.\n open(1,file='cx.dat')\n read(1,*)nmin, nmax, ih\n Tmin = dble(nmin)\n Tmax = dble(nmax)\n hm1 = 1.d0/dble(ih)\n allocate(svcx(nmin:nmax))\n do i=nmin,nmax,ih\n read(1,*) svcx(i)\n enddo\n close(1)\n endif\n if(T .lt. Tmin) T = Tmin\n if(T .gt. Tmax) T = Tmax\n dt1 = (T - Tmin)*hm1\n i = int(dt1) + 1\n dt2 = dt1 + dble(1 - i)\n sigmav_cx = svcx(i) + (svcx(i+1) - svcx(i))*dt2 \n return\nend function sigmav_cx\n!--------------------------------------------------------------\n", "meta": {"hexsha": "c3708003bbe35a9fcf91b95e2af32b1afc9cad19", "size": 1956, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "MC/CODE/cx_ion.f90", "max_stars_repo_name": "itpplasma/NEO-RT", "max_stars_repo_head_hexsha": "b0b8022d522bc97d0ffa721fd30167e74a0965a3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MC/CODE/cx_ion.f90", "max_issues_repo_name": "itpplasma/NEO-RT", "max_issues_repo_head_hexsha": "b0b8022d522bc97d0ffa721fd30167e74a0965a3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-10-29T12:44:06.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-29T12:45:04.000Z", "max_forks_repo_path": "MC/CODE/cx_ion.f90", "max_forks_repo_name": "itpplasma/NEO-RT", "max_forks_repo_head_hexsha": "b0b8022d522bc97d0ffa721fd30167e74a0965a3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-02T13:03:35.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-02T13:03:35.000Z", "avg_line_length": 30.0923076923, "max_line_length": 81, "alphanum_fraction": 0.5214723926, "num_tokens": 723, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505325302034, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.6695991359687786}} {"text": " SUBROUTINE MTXMUL2(AMAT,BMAT,CMAT,N1,N2,N3)\n IMPLICIT REAL*8(A-H,O-Z)\nC\nC FOR N-BY-M MATRICS AMAT, BMAT, AND CMAT, FORM THE PRODUCT\nC\nC CMAT = AMAT-TRANSPOSE * BMAT\nC\nC VAR DIM TYPE I/O DESCRIPTION\nC --- --- ---- --- -----------\nC\nC AMAT N2,N1 R*8 I INPUT MATRIX. \nC\nC BMAT N2,N3 R*8 I INPUT MATRIX.\nC\nC CMAT N1,N3 R*8 O OUTPUT MATRIX. PRODUCT AMAT-TR * BMAT.\nC NOTE THAT IN THE CALLING PROGRAM, \nC CMAT MAY NOT BE ONE OF AMAT AND BMAT. \nC THAT IS, THE CALL\nC CALL MTXMUL2(A,B,A,.....) IS INVALID.\nC\nC N1 1 I*4 I NUMBER OF ROWS IN CMAT AND NUMBER OF \nC COLUMNS IN AMAT.\nC\nC N2 1 I*4 I NUMBER OF ROWS IN AMAT AND NUMBER OF\nC ROWS IN BMAT.\nC\nC N3 1 I*4 I NUMBER OF COLUMNS IN BMAT AND CMAT.\nC\nC\nC***********************************************************************\nC\nC CODED BY C PETRUZZO. 2/83.\nC MODIFIED............\nC\nC***********************************************************************\nC\nC\n REAL*8 AMAT(N2,N1),BMAT(N2,N3),CMAT(N1,N3)\nC\n DO 100 I1=1,N1\n DO 100 I3=1,N3\n TEMP=0.D0\n DO 200 I2=1,N2\n 200 TEMP=TEMP+AMAT(I2,I1)*BMAT(I2,I3)\n 100 CMAT(I1,I3)=TEMP\nC\n RETURN\n END\n", "meta": {"hexsha": "5b6cdc9ea3d321bb3171f705a6afc8118f82ff5b", "size": 1450, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "gsc-13083/mtxmul2.for", "max_stars_repo_name": "SteveDoyle2/nasa-cosmic", "max_stars_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_stars_repo_licenses": ["BSD-Source-Code"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2015-03-14T07:26:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-16T12:23:17.000Z", "max_issues_repo_path": "gsc-13083/mtxmul2.for", "max_issues_repo_name": "SteveDoyle2/nasa-cosmic", "max_issues_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_issues_repo_licenses": ["BSD-Source-Code"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gsc-13083/mtxmul2.for", "max_forks_repo_name": "SteveDoyle2/nasa-cosmic", "max_forks_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_forks_repo_licenses": ["BSD-Source-Code"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2016-02-12T22:18:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-08T17:46:54.000Z", "avg_line_length": 29.5918367347, "max_line_length": 72, "alphanum_fraction": 0.4289655172, "num_tokens": 472, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505376715774, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.669599129404334}} {"text": " subroutine resid_alphadyopl(n_K,n_alpha,np1_K,np1_alpha,x,Nx,ht,my\n &zero,phys_bdy,res)\n implicit none\n integer i\n integer Nx\n real*8 ht\n real*8 myzero\n real*8 n_K(Nx)\n real*8 n_alpha(Nx)\n real*8 np1_K(Nx)\n real*8 np1_alpha(Nx)\n real*8 x(Nx)\n integer phys_bdy(2)\n real*8 res\n real*8 qb\n res = 0.0D0\n if (phys_bdy(1) .eq. 1) then\n do i=1, 1, 1\n qb = (-0.1D1 * n_alpha(i) + np1_alpha(i)) / ht + np1_alpha(i) * np\n #1_K(i) + n_alpha(i) * n_K(i)\n res = res + qb**2\n end do\n endif\n do i=2, Nx-1, 1\n qb = (-0.1D1 * n_alpha(i) + np1_alpha(i)) / ht + np1_alpha(i) * np\n #1_K(i) + n_alpha(i) * n_K(i)\n res = res + qb**2\n end do\n if (phys_bdy(2) .eq. 1) then\n do i=Nx, Nx, 1\n qb = np1_alpha(i) + myzero * x(i) - 0.1D1\n res = res + qb**2\n end do\n endif\n res = sqrt(res/(1*Nx))\n END\n", "meta": {"hexsha": "5005208a37f1fdcf79222f5c5b506456d694185d", "size": 949, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/FD/resid_alphadyopl.f", "max_stars_repo_name": "rmanak/bssn_spher", "max_stars_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/FD/resid_alphadyopl.f", "max_issues_repo_name": "rmanak/bssn_spher", "max_issues_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/FD/resid_alphadyopl.f", "max_forks_repo_name": "rmanak/bssn_spher", "max_forks_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.6486486486, "max_line_length": 72, "alphanum_fraction": 0.5005268704, "num_tokens": 380, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.7401743505760728, "lm_q1q2_score": 0.669599118511085}} {"text": "!\r\n! The Laboratory of Algorithms\r\n!\r\n! The MIT License\r\n!\r\n! Copyright 2011-2015 Andrey Pudov.\r\n!\r\n! Permission is hereby granted, free of charge, to any person obtaining a copy\r\n! of this software and associated documentation files (the 'Software'), to deal\r\n! in the Software without restriction, including without limitation the rights\r\n! to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n! copies of the Software, and to permit persons to whom the Software is\r\n! furnished to do so, subject to the following conditions:\r\n!\r\n! The above copyright notice and this permission notice shall be included in\r\n! all copies or substantial portions of the Software.\r\n!\r\n! THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r\n! THE SOFTWARE.\r\n!\r\n\r\n! Largest prime factor\r\n!\r\n! The prime factors of 13195 are 5, 7, 13 and 29.\r\n! What is the largest prime factor of the number 600851475143 ?\r\nmodule MPEProblem3\r\n\r\n implicit none\r\n private\r\n\r\n type, public :: TPEProblem3\r\n contains\r\n procedure, nopass :: present\r\n end type\r\ncontains\r\n subroutine present\r\n write (*, '(A)') 'Problem 3. Largest prime factor.'\r\n\r\n write (*, '(A, I)') 'Factor 1: ', factor()\r\n end subroutine\r\n\r\n function factor()\r\n integer*8 factor\r\n integer*8 index\r\n\r\n factor = 600851475143\r\n index = 2\r\n\r\n do while ((index ** 2) .le. factor)\r\n if (mod(factor, index) .eq. 0) then\r\n factor = factor / index\r\n else\r\n index = index + 1\r\n end if\r\n end do\r\n end function\r\nend module\r\n", "meta": {"hexsha": "ee2b19a42caebfe9f3f9f24271588844f09f9030", "size": 2029, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Problems/ProjectEuler/Problem3.f", "max_stars_repo_name": "andreypudov/Algorithms", "max_stars_repo_head_hexsha": "9693efa0abed30a38fcb9c3f7eebbd5b92b734f5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2016-02-15T14:45:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-01T22:42:32.000Z", "max_issues_repo_path": "Problems/ProjectEuler/Problem3.f", "max_issues_repo_name": "jlokimlin/Algorithms", "max_issues_repo_head_hexsha": "d981990394d940fd999334b0b65b118567670d1a", "max_issues_repo_licenses": ["MIT"], "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/ProjectEuler/Problem3.f", "max_forks_repo_name": "jlokimlin/Algorithms", "max_forks_repo_head_hexsha": "d981990394d940fd999334b0b65b118567670d1a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2016-02-24T15:47:02.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-01T10:45:03.000Z", "avg_line_length": 32.2063492063, "max_line_length": 80, "alphanum_fraction": 0.6648595367, "num_tokens": 473, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430394931456, "lm_q2_score": 0.8056321959813275, "lm_q1q2_score": 0.6695955920814581}} {"text": "!Autor: Claudio Iv\u00e1n Esparza Casta\u00f1eda\n!T\u00edtulo: Divisi\u00f3n sint\u00e9tica\n!Descripci\u00f3n: Se encarga de dividir un polinomio entre un binomio por el m\u00e9todo de la divisi\u00f3n sint\u00e9tica\n!Fecha: 19/03/2020\n\nprogram DivSint !Inicio del programa\n implicit none !Sin variables impl\u00edcitas\n REAL, allocatable, dimension(:)::a, b !Vector tipo REAL con dimensi\u00f3n din\u00e1mica\n REAL::p, d, x, r, s, t !Varibles tipo REAL\n INTEGER::i, n, m !Variables enteras\n d=0.0 !Inicializar valor de derivada\n p=0.0 !Inicializar valor de polinomio\n WRITE(*, *) \"Grado del polinomio\" !Preguntar por el grado del polinomio\n READ(*, *) n\n allocate(a(0:n), b(0:n-1)) !Asignar valor a variable din\u00e1mica\n WRITE(*, *) \"Coeficientes del polinomio a0+a1x+a2x\u00b2+...anx^n\" !Pregunta coeficientes del polinomio\n do i=0, n \n READ(*, *) a(i)\n end do\n WRITE(*, *) \"t de (x-t) para dividir el polinomio\" !Preguntar valor para evaluar polinomio\n READ(*, *) t\n r=a(n) !Salvar el n-\u00e9simo t\u00e9rmino del polinomio\n a(n)=0 !Hacer 0 el n-\u00e9simo t\u00e9rmino del polinomio\n do i=n-1, 0, -1 !Para cada t\u00e9rmino del polinomio de atr\u00e1s para adelante\n s=a(i) !Salvar el i-\u00e9simo t\u00e9rmino del polinomio\n a(i)=r !Tomar el valor del t\u00e9rmino anterior\n r=s+r*t !Sumar el i-\u00e9simo t\u00e9rmino al producto del t\u00e9rmino anterior y el divisor\n b(i)=r !Salvar en un vector resultado\n end do\n do i=n-1, 0, -1\n WRITE(*, *) b(i) !Valores del vector resultado\n end do\n deallocate(a, b) !Liberar memoria din\u00e1mica\nend program DivSint\n", "meta": {"hexsha": "794c96df25a223e5f45a226022a0c6169064335b", "size": 1479, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "14.- DivSint/DivSint.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": "14.- DivSint/DivSint.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": "14.- DivSint/DivSint.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": 42.2571428571, "max_line_length": 104, "alphanum_fraction": 0.7011494253, "num_tokens": 538, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.6695955871845867}} {"text": "program oscillator\nuse dftatom\nimplicit none\n\n! Atomic number:\ninteger, parameter :: Z = 0\n! Omega:\nreal(dp), parameter :: omega = 1.0_dp\n! Mesh parameters:\nreal(dp), parameter :: r_min = 1e-8_dp, r_max = 10._dp, a = 80._dp\ninteger, parameter :: NN = 5000\n\nreal(dp), parameter :: c = 137.03599907_dp, eps = 1e-10_dp\ninteger :: n, n2, l, relat, converged, relat_max, k, kappa\nreal(dp) :: r(NN+1), u(size(r)), Ein, E, E_exact_nonrel, error, P(size(r)), &\n Q(size(r))\nreal(dp) :: Rp(NN+1)\nreal(dp) :: Emin_init, Emax_init\nreal(dp) :: E_exact(7, -7:7) ! E_exact(n, kappa)\n\n\n\nE_exact = 0\nE_exact(7, -7) = 7.4996755269_dp\nE_exact(6:7, -6) = [ &\n 6.4997620499_dp, &\n 8.4994625812_dp &\n]\nE_exact(5:7, -5) = [ &\n 5.4998352632_dp, &\n 7.4995757160_dp, &\n 9.4992363376_dp &\n]\nE_exact(4:7, -4) = [ &\n 4.4998951661_dp, &\n 6.4996755428_dp, &\n 8.4993760822_dp, &\n 10.4989967965_dp &\n]\nE_exact(3:7, -3) = [ &\n 3.4999417582_dp, &\n 5.4997620612_dp, &\n 7.4995025208_dp, &\n 9.4991631492_dp, &\n 11.4987439585_dp &\n]\nE_exact(2:7, -2) = [ &\n 2.4999750389_dp, &\n 4.4998352706_dp, &\n 6.4996156527_dp, &\n 8.4993161976_dp, &\n 10.4989369173_dp, &\n 12.4984778242_dp &\n]\nE_exact(1:7, -1) = [ &\n 1.4999950078_dp, &\n 3.4998951705_dp, &\n 5.4997154776_dp, &\n 7.4994559413_dp, &\n 9.4991165738_dp, &\n 11.4986973873_dp, &\n 13.4981983940_dp &\n]\nE_exact(2:7, 1) = [ &\n 2.4999351051_dp, &\n 4.4997953424_dp, &\n 6.4995757249_dp, &\n 8.4992762722_dp, &\n 10.4988969952_dp, &\n 12.4984379048_dp &\n]\nE_exact(3:7, 2) = [ &\n 3.4998752033_dp, &\n 5.4996955116_dp, &\n 7.4994359765_dp, &\n 9.4990966102_dp, &\n 11.4986774249_dp &\n]\nE_exact(4:7, 3) = [ &\n 4.4998019930_dp, &\n 6.4995823772_dp, &\n 8.4992829240_dp, &\n 10.4989036457_dp &\n]\nE_exact(5:7, 4) = [ &\n 5.4997154739_dp, &\n 7.4994559363_dp, &\n 9.4991165675_dp &\n]\nE_exact(6:7, 5) = [ &\n 6.4996156467_dp, &\n 8.4993161897_dp &\n]\nE_exact(7, 6) = 7.4995025118_dp\n\n\n\nr = mesh_exp(r_min, r_max, a, NN)\nRp = mesh_exp_deriv(r_min, r_max, a, NN)\nu = omega**2 * r**2 / 2\n\nprint *, \"Relativistic linear spherically symmetric harmonic oscillator\"\nprint *, \"Mesh parameters (r_min, r_max, a, N):\"\nprint \"(ES10.2, F10.2, ES10.2, I10)\", r_min, r_max, a, NN\nprint *\nprint *, \" n l k kappa E E_exact Error E_exact_nonrel\"\nprint *\ndo n = 1, 7\n do l = 0, n-1\n if (l == 0) then\n relat_max = 2\n else\n relat_max = 3\n end if\n do relat = 2, relat_max\n k = relat - 2\n if (k == 0) then\n kappa = -l - 1\n else\n kappa = l\n end if\n E_exact_nonrel = omega * (2*n - l - 1._dp/2)\n Ein = -100\n Emin_init = 0\n Emax_init = 100\n if (kappa > 0) then\n n2 = n + 1\n else\n n2 = n\n end if\n call solve_radial_eigenproblem(n2, l, Ein, eps, 100, R, Rp, u, &\n Z, c, relat, .false., Emin_init, Emax_init, converged, E, P, Q)\n error = abs(E - E_exact(n, kappa))\n if (converged /= 0) call stop_error(\"Not converged\")\n print \"(I3, I3, I3, I3, F17.8, F17.8, ES10.2, F17.8)\", n, l, k, &\n kappa, E, E_exact(n, kappa), error, E_exact_nonrel\n if (error > 1e-8_dp) call stop_error(\"Error is higher than 1e-8\")\n end do\n end do\nend do\nend program\n", "meta": {"hexsha": "8550de8bf60183bbdc9bd33f554f9a4fba0d5b0f", "size": 3493, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/oscillator/osc_rel.f90", "max_stars_repo_name": "rc/dftatom", "max_stars_repo_head_hexsha": "fe479fd27a7e0f77c6a88a1949996406ec935ac2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 40, "max_stars_repo_stars_event_min_datetime": "2015-03-19T16:00:14.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-29T03:06:10.000Z", "max_issues_repo_path": "tests/oscillator/osc_rel.f90", "max_issues_repo_name": "rc/dftatom", "max_issues_repo_head_hexsha": "fe479fd27a7e0f77c6a88a1949996406ec935ac2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2015-06-23T21:59:56.000Z", "max_issues_repo_issues_event_max_datetime": "2019-09-04T20:36:51.000Z", "max_forks_repo_path": "tests/oscillator/osc_rel.f90", "max_forks_repo_name": "rc/dftatom", "max_forks_repo_head_hexsha": "fe479fd27a7e0f77c6a88a1949996406ec935ac2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2015-06-07T15:14:49.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-05T07:03:24.000Z", "avg_line_length": 24.5985915493, "max_line_length": 84, "alphanum_fraction": 0.5488119095, "num_tokens": 1385, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972818382005, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.6695591685171242}} {"text": "program avg_path_test\nuse, intrinsic :: iso_fortran_env\nuse random_mod\nuse node_mod\nimplicit none\ninteger, parameter :: sp = REAL32\ninteger :: nr_trees = 1000\nreal(kind=sp), parameter :: init_prob = 1.0_sp, factor = 0.75_sp, &\n root_dist = 0.0_sp\ntype(node_type) :: root\ninteger :: i\nreal(kind=sp) :: avg_path, avg_nodes\ncharacter(len=20) :: buffer\n\nif (command_argument_count() > 0) then\n call get_command_argument(1, buffer)\n read (buffer, \"(I10)\") nr_trees\nend if\n\n! initialize the random number generator to get a unique sequence per run\ncall init_random_seed()\n\navg_path = 0.0_sp\navg_nodes = 0.0_sp\ndo i = 1, nr_trees\n ! create a tree where each node value\n ! denotes a distance between it, and its parent\n call root%init_random(init_prob, factor, root_dist)\n ! compute the number of nodes in the tree, and the longest apth\n avg_path = avg_path + root%leaf_distance()\n avg_nodes = avg_nodes + root%count_nodes()\n ! finalize to prevent memory leakes\n call root%finalize()\nend do\navg_path = avg_path/nr_trees\navg_nodes = avg_nodes/nr_trees\n\n! write results\nwrite (unit=output_unit, fmt=\"(A, F6.3)\") \"avg. path = \", avg_path\nwrite (unit=output_unit, fmt=\"(A, F6.2)\") \"avg. nodes = \", avg_nodes\n\nend program avg_path_test\n\n", "meta": {"hexsha": "d2e1340fad2fef00470399f6b1f99217bf72d95b", "size": 1281, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran/OOProgramming/avg_path_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/OOProgramming/avg_path_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/OOProgramming/avg_path_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": 29.1136363636, "max_line_length": 73, "alphanum_fraction": 0.7080405933, "num_tokens": 364, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972818382005, "lm_q2_score": 0.7690802370707283, "lm_q1q2_score": 0.6695591639092549}} {"text": "! $UWHPSC/codes/openmp/yeval.f90\n\n! If this code gives a Segmentation Fault when compiled and run with -fopenmp \n! Then you could try:\n! $ ulimit -s unlimited\n! to increase the allowed stack size.\n! This may not work on all computers. On a Mac the best you can do is\n! $ ulimit -s hard\n! Correction... you can do the following on a Mac:\n! $ gfortran -fopenmp -Wl,-stack_size,2faf2000 yeval.f90 \n! here 2faf2000 is a hexadecimal number slightly larger than 8e8, the \n! number of bytes needed for the value of n used in this program.\n\n\nprogram yeval\n \n use omp_lib\n implicit none\n integer, parameter :: n = 100000000\n integer :: i, nthreads\n real(kind=8), dimension(n) :: y\n real(kind=8) :: dx, x\n\n ! Specify number of threads to use:\n !$ print *, \"How many threads to use? \"\n !$ read *, nthreads\n !$ call omp_set_num_threads(nthreads)\n !$ print \"('Using OpenMP with ',i3,' threads')\", nthreads\n\n dx = 1.d0 / (n+1.d0)\n\n !$omp parallel do private(x) \n do i=1,n\n x = i*dx\n y(i) = exp(x)*cos(x)*sin(x)*sqrt(5*x+6.d0)\n enddo\n\n print *, \"Filled vector y of length\", n\n\nend program yeval\n\n", "meta": {"hexsha": "02b58a5532b7d594db7a90aabefa7071e3d2df22", "size": 1132, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/codes/openmp/yeval.f90", "max_stars_repo_name": "philipwangdk/HPC", "max_stars_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "uwhpsc/codes/openmp/yeval.f90", "max_issues_repo_name": "philipwangdk/HPC", "max_issues_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "uwhpsc/codes/openmp/yeval.f90", "max_forks_repo_name": "philipwangdk/HPC", "max_forks_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.9523809524, "max_line_length": 78, "alphanum_fraction": 0.6554770318, "num_tokens": 354, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972818382005, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6695591639092547}} {"text": " SUBROUTINE slPXY (NP,XYE,XYM,COEFFS,XYP,XRMS,YRMS,RRMS)\n*+\n* - - - -\n* P X Y\n* - - - -\n*\n* Given arrays of \"expected\" and \"measured\" [X,Y] coordinates, and a\n* linear model relating them (as produced by slFTXY), compute\n* the array of \"predicted\" coordinates and the RMS residuals.\n*\n* Given:\n* NP i number of samples\n* XYE d(2,np) expected [X,Y] for each sample\n* XYM d(2,np) measured [X,Y] for each sample\n* COEFFS d(6) coefficients of model (see below)\n*\n* Returned:\n* XYP d(2,np) predicted [X,Y] for each sample\n* XRMS d RMS in X\n* YRMS d RMS in Y\n* RRMS d total RMS (vector sum of XRMS and YRMS)\n*\n* The model is supplied in the array COEFFS. Naming the\n* elements of COEFF as follows:\n*\n* COEFFS(1) = A\n* COEFFS(2) = B\n* COEFFS(3) = C\n* COEFFS(4) = D\n* COEFFS(5) = E\n* COEFFS(6) = F\n*\n* the model is applied thus:\n*\n* XP = A + B*XM + C*YM\n* YP = D + E*XM + F*YM\n*\n* The residuals are (XP-XE) and (YP-YE).\n*\n* If NP is less than or equal to zero, no coordinates are\n* transformed, and the RMS residuals are all zero.\n*\n* See also slFTXY, slINVF, slXYXY, slDCMF\n*\n* Called: slXYXY\n*\n* P.T.Wallace Starlink 22 May 1996\n*\n* Copyright (C) 1996 Rutherford Appleton Laboratory\n*\n* License:\n* This program is free software; you can redistribute it and/or modify\n* it under the terms of the GNU General Public License as published by\n* the Free Software Foundation; either version 2 of the License, or\n* (at your option) any later version.\n*\n* This program is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU General Public License for more details.\n*\n* You should have received a copy of the GNU General Public License\n* along with this program (see SLA_CONDITIONS); if not, write to the\n* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,\n* Boston, MA 02110-1301 USA\n*\n* Copyright (C) 1995 Association of Universities for Research in Astronomy Inc.\n*-\n\n IMPLICIT NONE\n\n INTEGER NP\n DOUBLE PRECISION XYE(2,NP),XYM(2,NP),COEFFS(6),\n : XYP(2,NP),XRMS,YRMS,RRMS\n\n INTEGER I\n DOUBLE PRECISION SDX2,SDY2,XP,YP,DX,DY,DX2,DY2,P\n\n\n\n* Initialize summations\n SDX2=0D0\n SDY2=0D0\n\n* Loop by sample\n DO I=1,NP\n\n* Transform \"measured\" [X,Y] to \"predicted\" [X,Y]\n CALL slXYXY(XYM(1,I),XYM(2,I),COEFFS,XP,YP)\n XYP(1,I)=XP\n XYP(2,I)=YP\n\n* Compute residuals in X and Y, and update summations\n DX=XYE(1,I)-XP\n DY=XYE(2,I)-YP\n DX2=DX*DX\n DY2=DY*DY\n SDX2=SDX2+DX2\n SDY2=SDY2+DY2\n\n* Next sample\n END DO\n\n* Compute RMS values\n P=MAX(1D0,DBLE(NP))\n XRMS=SQRT(SDX2/P)\n YRMS=SQRT(SDY2/P)\n RRMS=SQRT(XRMS*XRMS+YRMS*YRMS)\n\n END\n", "meta": {"hexsha": "6b67089b49b07cc578185fe89cb3c646d1de92eb", "size": 3038, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iraf.v2161/math/slalib/pxy.f", "max_stars_repo_name": "ysBach/irafdocgen", "max_stars_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:19:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T16:48:42.000Z", "max_issues_repo_path": "math/slalib/pxy.f", "max_issues_repo_name": "kirxkirx/iraf", "max_issues_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-30T13:48:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-02T19:40:25.000Z", "max_forks_repo_path": "math/slalib/pxy.f", "max_forks_repo_name": "kirxkirx/iraf", "max_forks_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.3693693694, "max_line_length": 80, "alphanum_fraction": 0.6089532587, "num_tokens": 1031, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232809, "lm_q2_score": 0.7690802317779601, "lm_q1q2_score": 0.6695591541370735}} {"text": "program beta\nuse statistical\nimplicit none\n\ninteger,parameter :: rs=8\nreal(rs) :: p,q,dp,dq\n\ndp = 0.1_rs\ndq = 0.1_rs\n\n! Set up p and q so they are never integers\np = -3._rs + dp/2._rs\ndo while (p < 3._rs)\n q = -3._rs + dq/2._rs\n do while (q < 3._rs)\n write(*,*) p,q,beta_func(p,q)\n q = q + dq\n enddo\n p = p + dp\n write(*,*) ! For gnuplot\nenddo\n\nend program beta\n", "meta": {"hexsha": "ac316b75d5be76cc49436abd373163475fc3f038", "size": 383, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test_statistical/beta.f90", "max_stars_repo_name": "JackWalpole/seismo-fortran-fork", "max_stars_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2015-06-23T05:28:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T03:46:07.000Z", "max_issues_repo_path": "test_statistical/beta.f90", "max_issues_repo_name": "JackWalpole/seismo-fortran-fork", "max_issues_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2017-05-17T11:02:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-28T09:36:24.000Z", "max_forks_repo_path": "test_statistical/beta.f90", "max_forks_repo_name": "JackWalpole/seismo-fortran-fork", "max_forks_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-04-15T02:55:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-20T12:20:51.000Z", "avg_line_length": 15.9583333333, "max_line_length": 43, "alphanum_fraction": 0.5874673629, "num_tokens": 154, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972684083609, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6695591535806306}} {"text": "subroutine solid_normint_3d(x_solid,nsd,nn_solid,ien_sbc,ne_sbc,nen_solid,&\n ien_solid,ne_solid,solid_norm)\n!---------------------------------\n! Calculate solid surface normal integral for 3-D cases\n! 1 find the points on the boundary surface\n! 2 use two vector cross to find the norm of the norm of the surface\n! 3 take one interial point and take the dot between this vector and norm \n! if dot < 0 it is the outward norm and then normalize the norm\n! 4 calculate the area of boundary surface: (1) tet, area of triangle; (2) hex, 2 triangles\n! 5 take norm*area and distribute it equaly to the each node\n\nimplicit none\n\nreal(8) x_solid(nsd,nn_solid)\ninteger nsd\ninteger nn_solid\ninteger ien_sbc(ne_sbc,nen_solid+2)\ninteger ne_sbc\ninteger nen_solid\ninteger ien_solid(ne_solid,nen_solid)\ninteger ne_solid\nreal(8) solid_norm(nsd,nn_solid)\n!------------------------------------\ninteger count\ninteger ibs\ninteger ine\ninteger ntem\ninteger nos\nreal(8), allocatable :: x(:,:)\nreal(8) p(nsd)\nreal(8) w\nreal(8) norm(nsd)\nreal(8) area\nreal(8) tot_area\nsolid_norm(:,:)=0.0d0\ntot_area=0.0d0\n\n\nif (nen_solid == 4) then\nallocate (x(nsd,3))\nw=1.0/3.0\nend if\n\nif (nen_solid == 8) then\nallocate (x(nsd,4))\nw=1.0/4.0\nend if\n\n\ndo ibs=1,ne_sbc\n\tine=ien_sbc(ibs,1)\n\tcount=1\n\t\tdo nos=1,nen_solid\n\t\tntem=ien_solid(ine,nos)\n\t\tif (ien_sbc(ibs,nos+1) == 1) then\n\t\tx(1:nsd,count)=x_solid(1:nsd,ntem)\n\t\tcount=count+1\n\t\telse\n\t\tp(1:nsd)=x_solid(1:nsd,ntem)\n\t\tend if\n\t\tend do\n\n\t\tif (nen_solid == 4) then\n\t\t\tcall outnormal_tet(x,nsd,p,norm,area)\n\t\telse if (nen_solid == 8) then\n\t\t\tcall outnormal_hex(x,nsd,p,norm,area)\n\t\tend if\n\n\t\ttot_area=area+tot_area\n do nos=1,nen_solid\n ntem=ien_solid(ine,nos)\n if (ien_sbc(ibs,nos+1) == 1) then\n\t\tsolid_norm(:,ntem)=solid_norm(:,ntem)+area*norm(:)*w\n\t\tend if\n\t\tend do\ncontinue\n\nend do\n\n!write(*,*) 'tot surface area', tot_area\n\ndeallocate(x)\n\nend \n", "meta": {"hexsha": "6ccdc786d14ca5165a17c8274d830daa138eaa26", "size": 1924, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "solid_normint_3d.f90", "max_stars_repo_name": "biofluids/IFEM-archive", "max_stars_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-15T11:40:16.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-15T11:40:16.000Z", "max_issues_repo_path": "solid_normint_3d.f90", "max_issues_repo_name": "biofluids/IFEM-archive", "max_issues_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "solid_normint_3d.f90", "max_forks_repo_name": "biofluids/IFEM-archive", "max_forks_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-02-11T16:50:21.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-08T07:24:59.000Z", "avg_line_length": 22.6352941176, "max_line_length": 91, "alphanum_fraction": 0.6715176715, "num_tokens": 691, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6695124474414146}} {"text": "\nsubroutine qinit(meqn,mbc,mx,my,xlower,ylower,dx,dy,q,maux,aux)\n \n use qinit_module, only: qinit_type,add_perturbation\n use geoclaw_module, only: sea_level\n \n implicit none\n \n ! Subroutine arguments\n integer, intent(in) :: meqn,mbc,mx,my,maux\n real(kind=8), intent(in) :: xlower,ylower,dx,dy\n real(kind=8), intent(inout) :: q(meqn,1-mbc:mx+mbc,1-mbc:my+mbc)\n real(kind=8), intent(inout) :: aux(maux,1-mbc:mx+mbc,1-mbc:my+mbc)\n \n ! Locals\n integer :: i, j\n real(kind=8) :: x, y, eta, h0\n\n ! Parameters\n real(kind=8) :: hmax, gamma, xs\n\n hmax = 0.0185d0\n gamma = sqrt(0.75d0 * hmax)\n xs = 38.d0\n \n ! Set soliton IC\n do i = 1 - mbc, mx + mbc\n x = xlower + (i - 0.5d0) * dx\n do j = 1 - mbc, my + mbc\n y = ylower + (j - 0.5d0) * dy\n eta = 4.d0 * hmax * (1.d0 / (exp(gamma * (x - xs)) + exp(-gamma * (x - xs))))**2\n q(1, i, j) = max(0.d0, eta - aux(1, i, j))\n h0 = max(0.d0, -aux(1, i, j))\n q(2, i, j) = q(1, i, j) * 2.d0 * (sqrt(h0) - sqrt(q(1, i, j)))\n q(3, i, j) = 0.d0\n end do\n end do\n \nend subroutine qinit\n", "meta": {"hexsha": "c8376f8836b37a70489b353f00beba05391cd9f7", "size": 1169, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/geoclaw/benchmark_1/qinit.f90", "max_stars_repo_name": "mandli/coastal", "max_stars_repo_head_hexsha": "8c80a4c740f92ea83b54c8a5432d11058c0d3476", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "examples/geoclaw/benchmark_1/qinit.f90", "max_issues_repo_name": "mandli/coastal", "max_issues_repo_head_hexsha": "8c80a4c740f92ea83b54c8a5432d11058c0d3476", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "examples/geoclaw/benchmark_1/qinit.f90", "max_forks_repo_name": "mandli/coastal", "max_forks_repo_head_hexsha": "8c80a4c740f92ea83b54c8a5432d11058c0d3476", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.225, "max_line_length": 92, "alphanum_fraction": 0.5098374679, "num_tokens": 485, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.919642528975397, "lm_q2_score": 0.7279754489059774, "lm_q1q2_score": 0.669477182863893}} {"text": "subroutine discretize_var_ep(sigma2_varep,nzz,varep_grid,pr_varep)\n use nrtype\n implicit none\n real(SP),intent(in)::sigma2_varep\n integer,intent(in)::nzz\n real(SP),dimension(nzz,1)::varep_grid,pr_varep\n real(SP),dimension(nzz)::x\n integer::i_l\n real,dimension(nzz-1,1)::dz\n real(SP)::x1,x2,pr_1,pr_2\n \n if (nzz==2) then\n x=(/-0.7071067811,0.7071067811/)\n elseif (nzz==3) then\n x=(/-1.22474487139158,0.0,1.22474487139158/)\n elseif (nzz==4) then\n x=(/-1.650680123,-0.5246476232,0.5246476232,1.650680123/)\n elseif (nzz==5) then\n x=(/-2.02018287,-0.9585724646,0.0,0.9585724646,2.02018287/) \n elseif (nzz==7)then\n x=(/-2.65196135683523,-1.67355162876747,-0.816287882858964,0.0,0.816287882858964,1.67355162876747,2.65196135683523/)\n elseif(nzz==8)then\n x=(/-2.93063742025724,-1.98165675669584,-1.15719371244678,-0.381186990207322,0.381186990207322,1.15719371244678,1.98165675669584,2.93063742025724/)\n end if\n \n do i_l=1,nzz\n varep_grid(i_l,1)=sqrt(2.0d0)*sqrt(sigma2_varep)*x(i_l)\n if (i_l>1) then\n dz(i_l-1,1)=varep_grid(i_l,1)-varep_grid(i_l-1,1)\n end if\n end do\n \n if (sigma2_varep==0.0_sp)then\n pr_varep=1.0_sp/real(nzz)\n else\n i_l=1\n x1=(varep_grid(i_l,1)+dz(i_l,1)/2.0d0)/sqrt(sigma2_varep)\n pr_varep(i_l,1)=0.5d0+0.5d0*erf(x1/sqrt(2.0d0))\n \n i_l=nzz\n x1=(varep_grid(i_l,1)-dz(i_l-1,1)/2.0d0)/sqrt(sigma2_varep)\n pr_varep(i_l,1)=1.0d0-(0.5d0+0.5d0*erf(x1/sqrt(2.0d0)))\n \n do i_l=2,nzz-1\n x1=(varep_grid(i_l,1)-dz(i_l-1,1)/2d0)/sqrt(sigma2_varep)\n pr_1=0.5d0+0.5d0*erf(x1/sqrt(2.0d0))\n x2=(varep_grid(i_l,1)+dz(i_l,1)/2d0)/sqrt(sigma2_varep)\n pr_2=0.5d0+0.5d0*erf(x2/sqrt(2.0d0))\n pr_varep(i_l,1)=pr_2-pr_1\n end do\n end if\n \nend subroutine\n", "meta": {"hexsha": "6cf61d93645192c7899215e2ca092b5316f7f9e7", "size": 1913, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "new_model/new_model/discretize_var_ep.f90", "max_stars_repo_name": "jesusbueren/new_model", "max_stars_repo_head_hexsha": "8d7b7bc02a36571c7dea843bbd1bcb3d865598e9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "new_model/new_model/discretize_var_ep.f90", "max_issues_repo_name": "jesusbueren/new_model", "max_issues_repo_head_hexsha": "8d7b7bc02a36571c7dea843bbd1bcb3d865598e9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "new_model/new_model/discretize_var_ep.f90", "max_forks_repo_name": "jesusbueren/new_model", "max_forks_repo_head_hexsha": "8d7b7bc02a36571c7dea843bbd1bcb3d865598e9", "max_forks_repo_licenses": ["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.4259259259, "max_line_length": 155, "alphanum_fraction": 0.6163094616, "num_tokens": 850, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425311777929, "lm_q2_score": 0.7279754371026367, "lm_q1q2_score": 0.669477173612329}} {"text": "Real Function x2kaon(srt)\n Save\n smin = 2.8639\n x2kaon = 0.0000001\n If (srt SpecificOfHeatRatio, CFL => CourantFriedrichsLewyCondition\n implicit none\n\n type(CellCenter), intent(in) :: CC\n type(UnstructuredGrid), intent(in) :: UG\n double precision, intent(in) :: TimeStepWidth\n type(MotionWait), intent(inout) :: MW\n type(Geometry), intent(in) :: Geom\n integer :: iCell\n type(CalculateMotionWaitWithOMP) :: CMW\n integer :: iRequiredWait !\u885d\u6483\u6ce2\u304c\u901a\u904e\u3059\u308b\u305f\u3081\u306b\u5fc5\u8981\u306a\u30a6\u30a7\u30a4\u30c8\n\n iRequiredWait = 0\n\n!$omp parallel num_threads(CoreNumberOfCPU),shared(UG,CC,TimeStepWidth,Geom),firstprivate(iCell,CMW,iRequiredWait)\n!$omp do reduction(max:iRequiredWait)\n do iCell = 1, UG%GI%RealCells\n CMW%AbsoluteVelocity2 = dot_product(CC%ConservedQuantity(2:4,iCell,1,1),CC%ConservedQuantity(2:4,iCell,1,1)) !\u901f\u5ea6L2\u30ce\u30eb\u30e0\n\n CMW%LocalSoundSpeed = sqrt(Gamma*(Gmin1 * CC%ConservedQuantity(5,iCell,1,1) / CC%ConservedQuantity(1,iCell,1,1)) &\n & + 0.5d0 * CMW%AbsoluteVelocity2) !\u5c40\u6240\u97f3\u901f\n\n CMW%AbsoluteVelocity = sqrt(CMW%AbsoluteVelocity2) !\u901f\u5ea6\u7d76\u5bfe\u5024\n\n !CMW%ShockPassingTime = CFL * UG%DeltaXofCFLCondition / (CMW%LocalSoundSpeed + CMW%AbsoluteVelocity) !\u885d\u6483\u6ce2\u304c\u901a\u904e\u3059\u308b\u901f\u5ea6\n !CMW%ShockPassingTime = CFL * sqrt(3.0d0)*UG%GM%AverageWidth(iCell) / (CMW%LocalSoundSpeed + CMW%AbsoluteVelocity) !\u885d\u6483\u6ce2\u304c\u901a\u904e\u3059\u308b\u901f\u5ea6\n !CMW%ShockPassingTime = CFL * sqrt(3.0d0)*sqrt(Geom%Area(1)**2+Geom%Area(2)**2 / (CMW%LocalSoundSpeed + CMW%AbsoluteVelocity) !\u885d\u6483\u6ce2\u304c\u901a\u904e\u3059\u308b\u901f\u5ea6\n CMW%ShockPassingTime = CFL * 2.0d0*max(Geom%Area(1),Geom%Area(2),UG%InscribedCircle(iCell)) / (CMW%LocalSoundSpeed + CMW%AbsoluteVelocity) !\u885d\u6483\u6ce2\u304c\u901a\u904e\u3059\u308b\u901f\u5ea6\n\n iRequiredWait = max(iRequiredWait, int(CMW%ShockPassingTime/TimeStepWidth))\n\n end do\n!$omp end do\n!$omp end parallel\n\n MW%iMotionWait = iRequiredWait\n\nreturn\nend subroutine OCalculateMotionWait\n", "meta": {"hexsha": "9ad957c9ebf61e8d9f2ab0d114339ea717b0ad57", "size": 2159, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "flow_solver/EulerSolver2_2018/source/MultipleOverSetMethod/MainProcess/MoveGrid/OCalculateMotionWait.f90", "max_stars_repo_name": "Mayu14/2D_comp_viscos", "max_stars_repo_head_hexsha": "a62633d8684b218b52e39d47a13717a1edfa4a46", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-05-08T18:00:28.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-08T18:00:28.000Z", "max_issues_repo_path": "flow_solver/EulerSolver2_2018/source/MultipleOverSetMethod/MainProcess/MoveGrid/OCalculateMotionWait.f90", "max_issues_repo_name": "Mayu14/2D_comp_viscos", "max_issues_repo_head_hexsha": "a62633d8684b218b52e39d47a13717a1edfa4a46", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "flow_solver/EulerSolver2_2018/source/MultipleOverSetMethod/MainProcess/MoveGrid/OCalculateMotionWait.f90", "max_forks_repo_name": "Mayu14/2D_comp_viscos", "max_forks_repo_head_hexsha": "a62633d8684b218b52e39d47a13717a1edfa4a46", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-02-20T09:26:27.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-20T09:26:27.000Z", "avg_line_length": 39.2545454545, "max_line_length": 158, "alphanum_fraction": 0.6961556276, "num_tokens": 789, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133481428692, "lm_q2_score": 0.7122321720225278, "lm_q1q2_score": 0.669436525460762}} {"text": " !> Test for mesh differentiation\nProgram example_2\n use Mirana\n implicit none\n integer, parameter :: n1 = 30, n2 = 50\n integer :: st1 = -3, st2 = -1, ed1, ed2\n double precision, parameter :: L = 1.5 !> A square domain\n double precision :: h1,h2,ej,exi1,exi2,eet1,eet2,x,y\n integer :: i,j\n double precision, dimension(:,:),allocatable :: mesh1,mesh2,jacob,xi1,xi2,et1,et2\n ed1 = st1 + n1 - 1\n ed2 = st2 + n2 - 1\n allocate(mesh1(st1:ed1,st2:ed2))\n allocate(mesh2(st1:ed1,st2:ed2))\n allocate(jacob(st1:ed1,st2:ed2))\n allocate(xi1(st1:ed1,st2:ed2))\n allocate(xi2(st1:ed1,st2:ed2))\n allocate(et1(st1:ed1,st2:ed2))\n allocate(et2(st1:ed1,st2:ed2))\n write(*,*) 'Hello, this is example_2, testing for mesh differentiation.'\n h1 = L / n1\n h2 = L / n2\n do i = st1,ed1\n do j = st2,ed2\n x = h1 * i - L/2\n y = h2 * j - L/2\n !> - The x-mesh \\f$\\xi=tanh(5x)\\f$.\n !> - The y-mesh \\f$\\eta=tanh(y)\\f$.\n mesh1(i,j) = 5 * atanh(x)\n mesh2(i,j) = atanh(y)\n end do\n end do\n\n call nmd(mesh1,mesh2,h1,h2,st1,st2,jacob,xi1,xi2,et1,et2)\n \n ej = 0\n exi1 = 0\n exi2 = 0\n eet1 = 0\n eet2 = 0\n do i = st1+1,ed1-1\n do j = st2+1,ed2-1\n x = h1 * i - L/2\n y = h2 * j - L/2\n exi1 = exi1 + abs( xi1(i,j) - 0.2 * (cosh(mesh1(i,j)/5.0)**(-2)) )\n exi2 = exi2 + abs( xi2(i,j) )\n eet1 = eet1 + abs( et1(i,j) )\n eet2 = eet2 + abs( et2(i,j) - cosh(mesh2(i,j))**(-2) )\n end do\n end do\n\n write(*,*) \"===========================\"\n write(*,*) \"Error noms: \"\n !write(*,*) \"Jacobian: \", ej/n1/n2\n write(*,*) \"xi_x: \", exi1/n1/n2\n write(*,*) \"xi_y: \", exi2/n1/n2\n write(*,*) \"eta_x: \", eet1/n1/n2\n write(*,*) \"eta_y: \", eet2/n1/n2\n write(*,*) \"===========================\"\n\n call save_mesh(mesh1,mesh2,st1,st2)\n\n deallocate( mesh1 )\n deallocate( mesh2 )\n deallocate( jacob )\n deallocate( xi1 )\n deallocate( xi2 )\n deallocate( et1 )\n deallocate( et2 ) \nend Program example_2\n\n", "meta": {"hexsha": "dd46e83a35d5674967169b85d866e2a0b6279880", "size": 1972, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "demo/example_2.f90", "max_stars_repo_name": "xywei/Mirana", "max_stars_repo_head_hexsha": "81d0ed67fad20cd3be8880ed672c12feff3c22c9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "demo/example_2.f90", "max_issues_repo_name": "xywei/Mirana", "max_issues_repo_head_hexsha": "81d0ed67fad20cd3be8880ed672c12feff3c22c9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "demo/example_2.f90", "max_forks_repo_name": "xywei/Mirana", "max_forks_repo_head_hexsha": "81d0ed67fad20cd3be8880ed672c12feff3c22c9", "max_forks_repo_licenses": ["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.3888888889, "max_line_length": 83, "alphanum_fraction": 0.5431034483, "num_tokens": 848, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625107731764, "lm_q2_score": 0.7185944046238981, "lm_q1q2_score": 0.669343748358532}} {"text": "Real Function aknpsg(pkaon)\n Save\n If (pkaon<=0.345) Then\n sigma1 = 0.624*pkaon**(-1.83)\n Else\n sigma1 = 0.7*pkaon**(-2.09)\n End If\n aknpsg = sigma1\n Return\nEnd Function aknpsg\n", "meta": {"hexsha": "e1b64f91f4c301e35a90faa5fb0dafbc9329e30f", "size": 189, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/aknpsg.f90", "max_stars_repo_name": "xiaohaijin/AMPT", "max_stars_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-12-24T19:37:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-14T12:58:59.000Z", "max_issues_repo_path": "src/aknpsg.f90", "max_issues_repo_name": "xiaohaijin/AMPT", "max_issues_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_issues_repo_licenses": ["MIT"], "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/aknpsg.f90", "max_forks_repo_name": "xiaohaijin/AMPT", "max_forks_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_forks_repo_licenses": ["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.1818181818, "max_line_length": 33, "alphanum_fraction": 0.6349206349, "num_tokens": 86, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625069680098, "lm_q2_score": 0.718594386544335, "lm_q1q2_score": 0.6693437287837254}} {"text": "subroutine kernel(a,b,c, n, m, l, lb)\ninteger, intent(in) :: n,m,l,lb\ninteger :: a(lb:n,lb:m), b(lb:m, lb:l) , c(lb:n,lb:l)\ninteger :: example(2:10, 3:30)\ninteger :: i,j,k\n\ndo i = 1,n\n do j = 1,l \n c(i,j) = 0\n do k = 1,m\n c(i,j) = c(i,j) + a(i,k) * b(k,j)\n enddo\n enddo\nenddo\n\nend\n\nsubroutine matmul(n,m,l, lb)\ninteger, intent(in) :: n,m,l,lb\ninteger :: a(lb:n,lb:m), b(lb:m, lb:l) , c(lb:n,lb:l)\ninteger :: i,j,k, sumVal=0\n\ndo i = 1,m\n do j = 1,n\n a(i,j)= 1\n enddo\n do j = 1,l\n b(i,j)= 1\n enddo\nenddo\n\ncall kernel(a,b,c,n,m,l,lb)\n\ndo i = 1,n\n do j = 1,l\n sumVal = sumVal + mod(c(i,j),10)\n enddo\nenddo \n\nprint *, sumVal\nend\n\nprogram pgm\ninteger ::n,m,l, lb\n\nlb = 1\nn = 11\nm = n \nl = n\ncall matmul(n,m,l, lb)\n\nend\n", "meta": {"hexsha": "7b99bf90c51211f76df81f641ee3b74b361d6c4a", "size": 742, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/mlir_out_tests/matmul.f90", "max_stars_repo_name": "clementval/fc", "max_stars_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/mlir_out_tests/matmul.f90", "max_issues_repo_name": "clementval/fc", "max_issues_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/mlir_out_tests/matmul.f90", "max_forks_repo_name": "clementval/fc", "max_forks_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "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": 14.0, "max_line_length": 53, "alphanum_fraction": 0.5350404313, "num_tokens": 343, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632896242073, "lm_q2_score": 0.7217432122827967, "lm_q1q2_score": 0.669318159606517}} {"text": " SUBROUTINE MB03WD( JOB, COMPZ, N, P, ILO, IHI, ILOZ, IHIZ, H,\n $ LDH1, LDH2, Z, LDZ1, LDZ2, WR, WI, DWORK,\n $ LDWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute the Schur decomposition and the eigenvalues of a\nC product of matrices, H = H_1*H_2*...*H_p, with H_1 an upper\nC Hessenberg matrix and H_2, ..., H_p upper triangular matrices,\nC without evaluating the product. Specifically, the matrices Z_i\nC are computed, such that\nC\nC Z_1' * H_1 * Z_2 = T_1,\nC Z_2' * H_2 * Z_3 = T_2,\nC ...\nC Z_p' * H_p * Z_1 = T_p,\nC\nC where T_1 is in real Schur form, and T_2, ..., T_p are upper\nC triangular.\nC\nC The routine works primarily with the Hessenberg and triangular\nC submatrices in rows and columns ILO to IHI, but optionally applies\nC the transformations to all the rows and columns of the matrices\nC H_i, i = 1,...,p. The transformations can be optionally\nC accumulated.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC JOB CHARACTER*1\nC Indicates whether the user wishes to compute the full\nC Schur form or the eigenvalues only, as follows:\nC = 'E': Compute the eigenvalues only;\nC = 'S': Compute the factors T_1, ..., T_p of the full\nC Schur form, T = T_1*T_2*...*T_p.\nC\nC COMPZ CHARACTER*1\nC Indicates whether or not the user wishes to accumulate\nC the matrices Z_1, ..., Z_p, as follows:\nC = 'N': The matrices Z_1, ..., Z_p are not required;\nC = 'I': Z_i is initialized to the unit matrix and the\nC orthogonal transformation matrix Z_i is returned,\nC i = 1, ..., p;\nC = 'V': Z_i must contain an orthogonal matrix Q_i on\nC entry, and the product Q_i*Z_i is returned,\nC i = 1, ..., p.\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The order of the matrix H. N >= 0.\nC\nC P (input) INTEGER\nC The number of matrices in the product H_1*H_2*...*H_p.\nC P >= 1.\nC\nC ILO (input) INTEGER\nC IHI (input) INTEGER\nC It is assumed that all matrices H_j, j = 2, ..., p, are\nC already upper triangular in rows and columns 1:ILO-1 and\nC IHI+1:N, and H_1 is upper quasi-triangular in rows and\nC columns 1:ILO-1 and IHI+1:N, with H_1(ILO,ILO-1) = 0\nC (unless ILO = 1), and H_1(IHI+1,IHI) = 0 (unless IHI = N).\nC The routine works primarily with the Hessenberg submatrix\nC in rows and columns ILO to IHI, but applies the\nC transformations to all the rows and columns of the\nC matrices H_i, i = 1,...,p, if JOB = 'S'.\nC 1 <= ILO <= max(1,N); min(ILO,N) <= IHI <= N.\nC\nC ILOZ (input) INTEGER\nC IHIZ (input) INTEGER\nC Specify the rows of Z to which the transformations must be\nC applied if COMPZ = 'I' or COMPZ = 'V'.\nC 1 <= ILOZ <= ILO; IHI <= IHIZ <= N.\nC\nC H (input/output) DOUBLE PRECISION array, dimension\nC (LDH1,LDH2,P)\nC On entry, the leading N-by-N part of H(*,*,1) must contain\nC the upper Hessenberg matrix H_1 and the leading N-by-N\nC part of H(*,*,j) for j > 1 must contain the upper\nC triangular matrix H_j, j = 2, ..., p.\nC On exit, if JOB = 'S', the leading N-by-N part of H(*,*,1)\nC is upper quasi-triangular in rows and columns ILO:IHI,\nC with any 2-by-2 diagonal blocks corresponding to a pair of\nC complex conjugated eigenvalues, and the leading N-by-N\nC part of H(*,*,j) for j > 1 contains the resulting upper\nC triangular matrix T_j.\nC If JOB = 'E', the contents of H are unspecified on exit.\nC\nC LDH1 INTEGER\nC The first leading dimension of the array H.\nC LDH1 >= max(1,N).\nC\nC LDH2 INTEGER\nC The second leading dimension of the array H.\nC LDH2 >= max(1,N).\nC\nC Z (input/output) DOUBLE PRECISION array, dimension\nC (LDZ1,LDZ2,P)\nC On entry, if COMPZ = 'V', the leading N-by-N-by-P part of\nC this array must contain the current matrix Q of\nC transformations accumulated by SLICOT Library routine\nC MB03VY.\nC If COMPZ = 'I', Z need not be set on entry.\nC On exit, if COMPZ = 'V', or COMPZ = 'I', the leading\nC N-by-N-by-P part of this array contains the transformation\nC matrices which produced the Schur form; the\nC transformations are applied only to the submatrices\nC Z_j(ILOZ:IHIZ,ILO:IHI), j = 1, ..., P.\nC If COMPZ = 'N', Z is not referenced.\nC\nC LDZ1 INTEGER\nC The first leading dimension of the array Z.\nC LDZ1 >= 1, if COMPZ = 'N';\nC LDZ1 >= max(1,N), if COMPZ = 'I' or COMPZ = 'V'.\nC\nC LDZ2 INTEGER\nC The second leading dimension of the array Z.\nC LDZ2 >= 1, if COMPZ = 'N';\nC LDZ2 >= max(1,N), if COMPZ = 'I' or COMPZ = 'V'.\nC\nC WR (output) DOUBLE PRECISION array, dimension (N)\nC WI (output) DOUBLE PRECISION array, dimension (N)\nC The real and imaginary parts, respectively, of the\nC computed eigenvalues ILO to IHI are stored in the\nC corresponding elements of WR and WI. If two eigenvalues\nC are computed as a complex conjugate pair, they are stored\nC in consecutive elements of WR and WI, say the i-th and\nC (i+1)th, with WI(i) > 0 and WI(i+1) < 0. If JOB = 'S', the\nC eigenvalues are stored in the same order as on the\nC diagonal of the Schur form returned in H.\nC\nC Workspace\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC\nC LDWORK INTEGER\nC The length of the array DWORK. LDWORK >= IHI-ILO+P-1.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value;\nC > 0: if INFO = i, ILO <= i <= IHI, the QR algorithm\nC failed to compute all the eigenvalues ILO to IHI\nC in a total of 30*(IHI-ILO+1) iterations;\nC the elements i+1:IHI of WR and WI contain those\nC eigenvalues which have been successfully computed.\nC\nC METHOD\nC\nC A refined version of the QR algorithm proposed in [1] and [2] is\nC used. The elements of the subdiagonal, diagonal, and the first\nC supradiagonal of current principal submatrix of H are computed\nC in the process.\nC\nC REFERENCES\nC\nC [1] Bojanczyk, A.W., Golub, G. and Van Dooren, P.\nC The periodic Schur decomposition: algorithms and applications.\nC Proc. of the SPIE Conference (F.T. Luk, Ed.), 1770, pp. 31-42,\nC 1992.\nC\nC [2] Sreedhar, J. and Van Dooren, P.\nC Periodic Schur form and some matrix equations.\nC Proc. of the Symposium on the Mathematical Theory of Networks\nC and Systems (MTNS'93), Regensburg, Germany (U. Helmke,\nC R. Mennicken and J. Saurer, Eds.), Vol. 1, pp. 339-362, 1994.\nC\nC NUMERICAL ASPECTS\nC\nC The algorithm is numerically stable.\nC\nC FURTHER COMMENTS\nC\nC Note that for P = 1, the LAPACK Library routine DHSEQR could be\nC more efficient on some computer architectures than this routine,\nC because DHSEQR uses a block multishift QR algorithm.\nC When P is large and JOB = 'S', it could be more efficient to\nC compute the product matrix H, and use the LAPACK Library routines.\nC\nC CONTRIBUTOR\nC\nC V. Sima, Katholieke Univ. Leuven, Belgium, and A. Varga,\nC German Aerospace Center, DLR Oberpfaffenhofen, February 1999.\nC Partly based on the routine PSHQR by A. Varga\nC (DLR Oberpfaffenhofen), January 22, 1996.\nC\nC REVISIONS\nC\nC Oct. 2001, V. Sima, Research Institute for Informatics, Bucharest.\nC\nC KEYWORDS\nC\nC Eigenvalue, eigenvalue decomposition, Hessenberg form,\nC orthogonal transformation, periodic systems, (periodic) Schur\nC form, real Schur form, similarity transformation, triangular form.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, ONE, HALF\n PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0, HALF = 0.5D+0 )\n DOUBLE PRECISION DAT1, DAT2\n PARAMETER ( DAT1 = 0.75D+0, DAT2 = -0.4375D+0 )\nC ..\nC .. Scalar Arguments ..\n CHARACTER COMPZ, JOB\n INTEGER IHI, IHIZ, ILO, ILOZ, INFO, LDH1, LDH2, LDWORK,\n $ LDZ1, LDZ2, N, P\nC ..\nC .. Array Arguments ..\n DOUBLE PRECISION DWORK( * ), H( LDH1, LDH2, * ), WI( * ),\n $ WR( * ), Z( LDZ1, LDZ2, * )\nC ..\nC .. Local Scalars ..\n LOGICAL INITZ, WANTT, WANTZ\n INTEGER I, I1, I2, ITN, ITS, J, JMAX, JMIN, K, L, M,\n $ NH, NR, NROW, NZ\n DOUBLE PRECISION AVE, CS, DISC, H11, H12, H21, H22, H33, H33S,\n $ H43H34, H44, H44S, HH10, HH11, HH12, HH21, HH22,\n $ HP00, HP01, HP02, HP11, HP12, HP22, OVFL, S,\n $ SMLNUM, SN, TAU, TST1, ULP, UNFL, V1, V2, V3\nC ..\nC .. Local Arrays ..\n DOUBLE PRECISION V( 3 )\nC ..\nC .. External Functions ..\n LOGICAL LSAME\n DOUBLE PRECISION DLAMCH, DLANHS, DLANTR\n EXTERNAL DLAMCH, DLANHS, DLANTR, LSAME\nC ..\nC .. External Subroutines ..\n EXTERNAL DCOPY, DLABAD, DLANV2, DLARFG, DLARFX, DLARTG,\n $ DLASET, DROT, MB04PY, XERBLA\nC ..\nC .. Intrinsic Functions ..\n INTRINSIC ABS, DBLE, MAX, MIN, SIGN, SQRT\nC ..\nC .. Executable Statements ..\nC\nC Test the input scalar arguments.\nC\n WANTT = LSAME( JOB, 'S' )\n INITZ = LSAME( COMPZ, 'I' )\n WANTZ = LSAME( COMPZ, 'V' ) .OR. INITZ\n INFO = 0\n IF( .NOT. ( WANTT .OR. LSAME( JOB, 'E' ) ) ) THEN\n INFO = -1\n ELSE IF( .NOT. ( WANTZ .OR. LSAME( COMPZ, 'N' ) ) ) THEN\n INFO = -2\n ELSE IF( N.LT.0 ) THEN\n INFO = -3\n ELSE IF( P.LT.1 ) THEN\n INFO = -4\n ELSE IF( ILO.LT.1 .OR. ILO.GT.MAX( 1, N ) ) THEN\n INFO = -5\n ELSE IF( IHI.LT.MIN( ILO, N ) .OR. IHI.GT.N ) THEN\n INFO = -6\n ELSE IF( ILOZ.LT.1 .OR. ILOZ.GT.ILO ) THEN\n INFO = -7\n ELSE IF( IHIZ.LT.IHI .OR. IHIZ.GT.N ) THEN\n INFO = -8\n ELSE IF( LDH1.LT.MAX( 1, N ) ) THEN\n INFO = -10\n ELSE IF( LDH2.LT.MAX( 1, N ) ) THEN\n INFO = -11\n ELSE IF( LDZ1.LT.1 .OR. ( WANTZ .AND. LDZ1.LT.N ) ) THEN\n INFO = -13\n ELSE IF( LDZ2.LT.1 .OR. ( WANTZ .AND. LDZ2.LT.N ) ) THEN\n INFO = -14\n ELSE IF( LDWORK.LT.IHI - ILO + P - 1 ) THEN\n INFO = -18\n END IF\n IF( INFO.EQ.0 ) THEN\n IF( ILO.GT.1 ) THEN\n IF( H( ILO, ILO-1, 1 ).NE.ZERO )\n $ INFO = -5\n ELSE IF( IHI.LT.N ) THEN\n IF( H( IHI+1, IHI, 1 ).NE.ZERO )\n $ INFO = -6\n END IF\n END IF\nC\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'MB03WD', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF( N.EQ.0 )\n $ RETURN\nC\nC Initialize Z, if necessary.\nC\n IF( INITZ ) THEN\nC\n DO 10 J = 1, P\n CALL DLASET( 'Full', N, N, ZERO, ONE, Z( 1, 1, J ), LDZ1 )\n 10 CONTINUE\nC\n END IF\nC\n NH = IHI - ILO + 1\nC\n IF( NH.EQ.1 ) THEN\n HP00 = ONE\nC\n DO 20 J = 1, P\n HP00 = HP00 * H( ILO, ILO, J )\n 20 CONTINUE\nC\n WR( ILO ) = HP00\n WI( ILO ) = ZERO\n RETURN\n END IF\nC\nC Set machine-dependent constants for the stopping criterion.\nC If norm(H) <= sqrt(OVFL), overflow should not occur.\nC\n UNFL = DLAMCH( 'Safe minimum' )\n OVFL = ONE / UNFL\n CALL DLABAD( UNFL, OVFL )\n ULP = DLAMCH( 'Precision' )\n SMLNUM = UNFL*( DBLE( NH ) / ULP )\nC\nC Set the elements in rows and columns ILO to IHI to zero below the\nC first subdiagonal in H(*,*,1) and below the first diagonal in\nC H(*,*,j), j >= 2. In the same loop, compute and store in\nC DWORK(NH:NH+P-2) the 1-norms of the matrices H_2, ..., H_p, to be\nC used later.\nC\n I = NH\n S = ULP * DBLE( N )\n IF( NH.GT.2 )\n $ CALL DLASET( 'Lower', NH-2, NH-2, ZERO, ZERO,\n $ H( ILO+2, ILO, 1 ), LDH1 )\nC\n DO 30 J = 2, P\n CALL DLASET( 'Lower', NH-1, NH-1, ZERO, ZERO,\n $ H( ILO+1, ILO, J ), LDH1 )\n DWORK( I ) = S * DLANTR( '1-norm', 'Upper', 'NonUnit', NH, NH,\n $ H( ILO, ILO, J ), LDH1, DWORK )\n I = I + 1\n 30 CONTINUE\nC\nC I1 and I2 are the indices of the first row and last column of H\nC to which transformations must be applied. If eigenvalues only are\nC being computed, I1 and I2 are set inside the main loop.\nC\n IF( WANTT ) THEN\n I1 = 1\n I2 = N\n END IF\nC\n IF( WANTZ )\n $ NZ = IHIZ - ILOZ + 1\nC\nC ITN is the total number of QR iterations allowed.\nC\n ITN = 30*NH\nC\nC The main loop begins here. I is the loop index and decreases from\nC IHI to ILO in steps of 1 or 2. Each iteration of the loop works\nC with the active submatrix in rows and columns L to I.\nC Eigenvalues I+1 to IHI have already converged. Either L = ILO or\nC H(L,L-1) is negligible so that the matrix splits.\nC\n I = IHI\nC\n 40 CONTINUE\n L = ILO\nC\nC Perform QR iterations on rows and columns ILO to I until a\nC submatrix of order 1 or 2 splits off at the bottom because a\nC subdiagonal element has become negligible.\nC\nC Let T = H_2*...*H_p, and H = H_1*T. Part of the currently\nC free locations of WR and WI are temporarily used as workspace.\nC\nC WR(L:I): the current diagonal elements of h = H(L:I,L:I);\nC WI(L+1:I): the current elements of the first subdiagonal of h;\nC DWORK(NH-I+L:NH-1): the current elements of the first\nC supradiagonal of h.\nC\n DO 160 ITS = 0, ITN\nC\nC Initialization: compute H(I,I) (and H(I,I-1) if I > L).\nC\n HP22 = ONE\n IF( I.GT.L ) THEN\n HP12 = ZERO\n HP11 = ONE\nC\n DO 50 J = 2, P\n HP22 = HP22*H( I, I, J )\n HP12 = HP11*H( I-1, I, J ) + HP12*H( I, I, J )\n HP11 = HP11*H( I-1, I-1, J )\n 50 CONTINUE\nC\n HH21 = H( I, I-1, 1 )*HP11\n HH22 = H( I, I-1, 1 )*HP12 + H( I, I, 1 )*HP22\nC\n WR( I ) = HH22\n WI( I ) = HH21\n ELSE\nC\n DO 60 J = 1, P\n HP22 = HP22*H( I, I, J )\n 60 CONTINUE\nC\n WR( I ) = HP22\n END IF\nC\nC Look for a single small subdiagonal element.\nC The loop also computes the needed current elements of the\nC diagonal and the first two supradiagonals of T, as well as\nC the current elements of the central tridiagonal of H.\nC\n DO 80 K = I, L + 1, -1\nC\nC Evaluate H(K-1,K-1), H(K-1,K) (and H(K-1,K-2) if K > L+1).\nC\n HP00 = ONE\n HP01 = ZERO\n IF( K.GT.L+1 ) THEN\n HP02 = ZERO\nC\n DO 70 J = 2, P\n HP02 = HP00*H( K-2, K, J ) + HP01*H( K-1, K, J )\n $ + HP02*H( K, K, J )\n HP01 = HP00*H( K-2, K-1, J ) + HP01*H( K-1, K-1, J )\n HP00 = HP00*H( K-2, K-2, J )\n 70 CONTINUE\nC\n HH10 = H( K-1, K-2, 1 )*HP00\n HH11 = H( K-1, K-2, 1 )*HP01 + H( K-1, K-1, 1 )*HP11\n HH12 = H( K-1, K-2, 1 )*HP02 + H( K-1, K-1, 1 )*HP12\n $ + H( K-1, K, 1 )*HP22\n WI( K-1 ) = HH10\n ELSE\n HH10 = ZERO\n HH11 = H( K-1, K-1, 1 )*HP11\n HH12 = H( K-1, K-1, 1 )*HP12 + H( K-1, K, 1 )*HP22\n END IF\n WR( K-1 ) = HH11\n DWORK( NH-I+K-1) = HH12\nC\nC Test for a negligible subdiagonal element.\nC\n TST1 = ABS( HH11 ) + ABS( HH22 )\n IF( TST1.EQ.ZERO )\n $ TST1 = DLANHS( '1-norm', I-L+1, H( L, L, 1 ), LDH1,\n $ DWORK )\n IF( ABS( HH21 ).LE.MAX( ULP*TST1, SMLNUM ) )\n $ GO TO 90\nC\nC Update the values for the next cycle.\nC\n HP22 = HP11\n HP11 = HP00\n HP12 = HP01\n HH22 = HH11\n HH21 = HH10\n 80 CONTINUE\nC\n 90 CONTINUE\n L = K\nC\n IF( L.GT.ILO ) THEN\nC\nC H(L,L-1) is negligible.\nC\n IF( WANTT ) THEN\nC\nC If H(L,L-1,1) is also negligible, set it to 0; otherwise,\nC annihilate the subdiagonal elements bottom-up, and\nC restore the triangular form of H(*,*,j). Since H(L,L-1)\nC is negligible, the second case can only appear when the\nC product of H(L-1,L-1,j), j >= 2, is negligible.\nC\n TST1 = ABS( H( L-1, L-1, 1 ) ) + ABS( H( L, L, 1 ) )\n IF( TST1.EQ.ZERO )\n $ TST1 = DLANHS( '1-norm', I-L+1, H( L, L, 1 ), LDH1,\n $ DWORK )\n IF( ABS( H( L, L-1, 1 ) ).GT.MAX( ULP*TST1, SMLNUM ) )\n $ THEN\nC\n DO 110 K = I, L, -1\nC\n DO 100 J = 1, P - 1\nC\nC Compute G to annihilate from the right the\nC (K,K-1) element of the matrix H_j.\nC\n V( 1 ) = H( K, K-1, J )\n CALL DLARFG( 2, H( K, K, J ), V, 1, TAU )\n H( K, K-1, J ) = ZERO\n V( 2 ) = ONE\nC\nC Apply G from the right to transform the columns\nC of the matrix H_j in rows I1 to K-1.\nC\n CALL DLARFX( 'Right', K-I1, 2, V, TAU,\n $ H( I1, K-1, J ), LDH1, DWORK )\nC\nC Apply G from the left to transform the rows of\nC the matrix H_(j+1) in columns K-1 to I2.\nC\n CALL DLARFX( 'Left', 2, I2-K+2, V, TAU,\n $ H( K-1, K-1, J+1 ), LDH1, DWORK )\nC\n IF( WANTZ ) THEN\nC\nC Accumulate transformations in the matrix\nC Z_(j+1).\nC\n CALL DLARFX( 'Right', NZ, 2, V, TAU,\n $ Z( ILOZ, K-1, J+1 ), LDZ1,\n $ DWORK )\n END IF\n 100 CONTINUE\nC\n IF( K.LT.I ) THEN\nC\nC Compute G to annihilate from the right the\nC (K+1,K) element of the matrix H_p.\nC\n V( 1 ) = H( K+1, K, P )\n CALL DLARFG( 2, H( K+1, K+1, P ), V, 1, TAU )\n H( K+1, K, P ) = ZERO\n V( 2 ) = ONE\nC\nC Apply G from the right to transform the columns\nC of the matrix H_p in rows I1 to K.\nC\n CALL DLARFX( 'Right', K-I1+1, 2, V, TAU,\n $ H( I1, K, P ), LDH1, DWORK )\nC\nC Apply G from the left to transform the rows of\nC the matrix H_1 in columns K to I2.\nC\n CALL DLARFX( 'Left', 2, I2-K+1, V, TAU,\n $ H( K, K, 1 ), LDH1, DWORK )\nC\n IF( WANTZ ) THEN\nC\nC Accumulate transformations in the matrix Z_1.\nC\n CALL DLARFX( 'Right', NZ, 2, V, TAU,\n $ Z( ILOZ, K, 1 ), LDZ1, DWORK )\n END IF\n END IF\n 110 CONTINUE\nC\n H( L, L-1, P ) = ZERO\n END IF\n H( L, L-1, 1 ) = ZERO\n END IF\n END IF\nC\nC Exit from loop if a submatrix of order 1 or 2 has split off.\nC\n IF( L.GE.I-1 )\n $ GO TO 170\nC\nC Now the active submatrix is in rows and columns L to I. If\nC eigenvalues only are being computed, only the active submatrix\nC need be transformed.\nC\n IF( .NOT.WANTT ) THEN\n I1 = L\n I2 = I\n END IF\nC\n IF( ITS.EQ.10 .OR. ITS.EQ.20 ) THEN\nC\nC Exceptional shift.\nC\n S = ABS( WI( I ) ) + ABS( WI( I-1 ) )\n H44 = DAT1*S + WR( I )\n H33 = H44\n H43H34 = DAT2*S*S\n ELSE\nC\nC Prepare to use Francis' double shift (i.e., second degree\nC generalized Rayleigh quotient).\nC\n H44 = WR( I )\n H33 = WR( I-1 )\n H43H34 = WI( I )*DWORK( NH-1 )\n DISC = ( H33 - H44 )*HALF\n DISC = DISC*DISC + H43H34\n IF( DISC.GT.ZERO ) THEN\nC\nC Real roots: use Wilkinson's shift twice.\nC\n DISC = SQRT( DISC )\n AVE = HALF*( H33 + H44 )\n IF( ABS( H33 )-ABS( H44 ).GT.ZERO ) THEN\n H33 = H33*H44 - H43H34\n H44 = H33 / ( SIGN( DISC, AVE ) + AVE )\n ELSE\n H44 = SIGN( DISC, AVE ) + AVE\n END IF\n H33 = H44\n H43H34 = ZERO\n END IF\n END IF\nC\nC Look for two consecutive small subdiagonal elements.\nC\n DO 120 M = I - 2, L, -1\nC\nC Determine the effect of starting the double-shift QR\nC iteration at row M, and see if this would make H(M,M-1)\nC negligible.\nC\n H11 = WR( M )\n H12 = DWORK( NH-I+M )\n H21 = WI( M+1 )\n H22 = WR( M+1 )\n H44S = H44 - H11\n H33S = H33 - H11\n V1 = ( H33S*H44S - H43H34 ) / H21 + H12\n V2 = H22 - H11 - H33S - H44S\n V3 = WI( M+2 )\n S = ABS( V1 ) + ABS( V2 ) + ABS( V3 )\n V1 = V1 / S\n V2 = V2 / S\n V3 = V3 / S\n V( 1 ) = V1\n V( 2 ) = V2\n V( 3 ) = V3\n IF( M.EQ.L )\n $ GO TO 130\n TST1 = ABS( V1 )*( ABS( WR( M-1 ) ) +\n $ ABS( H11 ) + ABS( H22 ) )\n IF( ABS( WI( M ) )*( ABS( V2 ) + ABS( V3 ) ).LE.ULP*TST1 )\n $ GO TO 130\n 120 CONTINUE\nC\n 130 CONTINUE\nC\nC Double-shift QR step.\nC\n DO 150 K = M, I - 1\nC\nC The first iteration of this loop determines a reflection G\nC from the vector V and applies it from left and right to H,\nC thus creating a nonzero bulge below the subdiagonal.\nC\nC Each subsequent iteration determines a reflection G to\nC restore the Hessenberg form in the (K-1)th column, and thus\nC chases the bulge one step toward the bottom of the active\nC submatrix. NR is the order of G.\nC\n NR = MIN( 3, I-K+1 )\n NROW = MIN( K+NR, I ) - I1 + 1\n IF( K.GT.M )\n $ CALL DCOPY( NR, H( K, K-1, 1 ), 1, V, 1 )\n CALL DLARFG( NR, V( 1 ), V( 2 ), 1, TAU )\n IF( K.GT.M ) THEN\n H( K, K-1, 1 ) = V( 1 )\n H( K+1, K-1, 1 ) = ZERO\n IF( K.LT.I-1 )\n $ H( K+2, K-1, 1 ) = ZERO\n ELSE IF( M.GT.L ) THEN\n H( K, K-1, 1 ) = -H( K, K-1, 1 )\n END IF\nC\nC Apply G from the left to transform the rows of the matrix\nC H_1 in columns K to I2.\nC\n CALL MB04PY( 'Left', NR, I2-K+1, V( 2 ), TAU, H( K, K, 1 ),\n $ LDH1, DWORK )\nC\nC Apply G from the right to transform the columns of the\nC matrix H_p in rows I1 to min(K+NR,I).\nC\n CALL MB04PY( 'Right', NROW, NR, V( 2 ), TAU, H( I1, K, P ),\n $ LDH1, DWORK )\nC\n IF( WANTZ ) THEN\nC\nC Accumulate transformations in the matrix Z_1.\nC\n CALL MB04PY( 'Right', NZ, NR, V( 2 ), TAU,\n $ Z( ILOZ, K, 1 ), LDZ1, DWORK )\n END IF\nC\n DO 140 J = P, 2, -1\nC\nC Apply G1 (and G2, if NR = 3) from the left to transform\nC the NR-by-NR submatrix of H_j in position (K,K) to upper\nC triangular form.\nC\nC Compute G1.\nC\n CALL DCOPY( NR-1, H( K+1, K, J ), 1, V, 1 )\n CALL DLARFG( NR, H( K, K, J ), V, 1, TAU )\n H( K+1, K, J ) = ZERO\n IF( NR.EQ.3 )\n $ H( K+2, K, J ) = ZERO\nC\nC Apply G1 from the left to transform the rows of the\nC matrix H_j in columns K+1 to I2.\nC\n CALL MB04PY( 'Left', NR, I2-K, V, TAU, H( K, K+1, J ),\n $ LDH1, DWORK )\nC\nC Apply G1 from the right to transform the columns of the\nC matrix H_(j-1) in rows I1 to min(K+NR,I).\nC\n CALL MB04PY( 'Right', NROW, NR, V, TAU, H( I1, K, J-1 ),\n $ LDH1, DWORK )\nC\n IF( WANTZ ) THEN\nC\nC Accumulate transformations in the matrix Z_j.\nC\n CALL MB04PY( 'Right', NZ, NR, V, TAU, Z( ILOZ, K, J ),\n $ LDZ1, DWORK )\n END IF\nC\n IF( NR.EQ.3 ) THEN\nC\nC Compute G2.\nC\n V( 1 ) = H( K+2, K+1, J )\n CALL DLARFG( 2, H( K+1, K+1, J ), V, 1, TAU )\n H( K+2, K+1, J ) = ZERO\nC\nC Apply G2 from the left to transform the rows of the\nC matrix H_j in columns K+2 to I2.\nC\n CALL MB04PY( 'Left', 2, I2-K-1, V, TAU,\n $ H( K+1, K+2, J ), LDH1, DWORK )\nC\nC Apply G2 from the right to transform the columns of\nC the matrix H_(j-1) in rows I1 to min(K+3,I).\nC\n CALL MB04PY( 'Right', NROW, 2, V, TAU,\n $ H( I1, K+1, J-1 ), LDH1, DWORK )\nC\n IF( WANTZ ) THEN\nC\nC Accumulate transformations in the matrix Z_j.\nC\n CALL MB04PY( 'Right', NZ, 2, V, TAU,\n $ Z( ILOZ, K+1, J ), LDZ1, DWORK )\n END IF\n END IF\n 140 CONTINUE\nC\n 150 CONTINUE\nC\n 160 CONTINUE\nC\nC Failure to converge in remaining number of iterations.\nC\n INFO = I\n RETURN\nC\n 170 CONTINUE\nC\n IF( L.EQ.I ) THEN\nC\nC H(I,I-1,1) is negligible: one eigenvalue has converged.\nC Note that WR(I) has already been set.\nC\n WI( I ) = ZERO\n ELSE IF( L.EQ.I-1 ) THEN\nC\nC H(I-1,I-2,1) is negligible: a pair of eigenvalues have\nC converged.\nC\nC Transform the 2-by-2 submatrix of H_1*H_2*...*H_p in position\nC (I-1,I-1) to standard Schur form, and compute and store its\nC eigenvalues. If the Schur form is not required, then the\nC previously stored values of a similar submatrix are used.\nC For real eigenvalues, a Givens transformation is used to\nC triangularize the submatrix.\nC\n IF( WANTT ) THEN\n HP22 = ONE\n HP12 = ZERO\n HP11 = ONE\nC\n DO 180 J = 2, P\n HP22 = HP22*H( I, I, J )\n HP12 = HP11*H( I-1, I, J ) + HP12*H( I, I, J )\n HP11 = HP11*H( I-1, I-1, J )\n 180 CONTINUE\nC\n HH21 = H( I, I-1, 1 )*HP11\n HH22 = H( I, I-1, 1 )*HP12 + H( I, I, 1 )*HP22\n HH11 = H( I-1, I-1, 1 )*HP11\n HH12 = H( I-1, I-1, 1 )*HP12 + H( I-1, I, 1 )*HP22\n ELSE\n HH11 = WR( I-1 )\n HH12 = DWORK( NH-1 )\n HH21 = WI( I )\n HH22 = WR( I )\n END IF\nC\n CALL DLANV2( HH11, HH12, HH21, HH22, WR( I-1 ), WI( I-1 ),\n $ WR( I ), WI( I ), CS, SN )\nC\n IF( WANTT ) THEN\nC\nC Detect negligible diagonal elements in positions (I-1,I-1)\nC and (I,I) in H_j, J > 1.\nC\n JMIN = 0\n JMAX = 0\nC\n DO 190 J = 2, P\n IF( JMIN.EQ.0 ) THEN\n IF( ABS( H( I-1, I-1, J ) ).LE.DWORK( NH+J-2 ) )\n $ JMIN = J\n END IF\n IF( ABS( H( I, I, J ) ).LE.DWORK( NH+J-2 ) ) JMAX = J\n 190 CONTINUE\nC\n IF( JMIN.NE.0 .AND. JMAX.NE.0 ) THEN\nC\nC Choose the shorter path if zero elements in both\nC (I-1,I-1) and (I,I) positions are present.\nC\n IF( JMIN-1.LE.P-JMAX+1 ) THEN\n JMAX = 0\n ELSE\n JMIN = 0\n END IF\n END IF\nC\n IF( JMIN.NE.0 ) THEN\nC\n DO 200 J = 1, JMIN - 1\nC\nC Compute G to annihilate from the right the (I,I-1)\nC element of the matrix H_j.\nC\n V( 1 ) = H( I, I-1, J )\n CALL DLARFG( 2, H( I, I, J ), V, 1, TAU )\n H( I, I-1, J ) = ZERO\n V( 2 ) = ONE\nC\nC Apply G from the right to transform the columns of the\nC matrix H_j in rows I1 to I-1.\nC\n CALL DLARFX( 'Right', I-I1, 2, V, TAU,\n $ H( I1, I-1, J ), LDH1, DWORK )\nC\nC Apply G from the left to transform the rows of the\nC matrix H_(j+1) in columns I-1 to I2.\nC\n CALL DLARFX( 'Left', 2, I2-I+2, V, TAU,\n $ H( I-1, I-1, J+1 ), LDH1, DWORK )\nC\n IF( WANTZ ) THEN\nC\nC Accumulate transformations in the matrix Z_(j+1).\nC\n CALL DLARFX( 'Right', NZ, 2, V, TAU,\n $ Z( ILOZ, I-1, J+1 ), LDZ1, DWORK )\n END IF\n 200 CONTINUE\nC\n H( I, I-1, JMIN ) = ZERO\nC\n ELSE\n IF( JMAX.GT.0 .AND. WI( I-1 ).EQ.ZERO )\n $ CALL DLARTG( H( I-1, I-1, 1 ), H( I, I-1, 1 ), CS, SN,\n $ TAU )\nC\nC Apply the transformation to H.\nC\n CALL DROT( I2-I+2, H( I-1, I-1, 1 ), LDH1,\n $ H( I, I-1, 1 ), LDH1, CS, SN )\n CALL DROT( I-I1+1, H( I1, I-1, P ), 1, H( I1, I, P ), 1,\n $ CS, SN )\n IF( WANTZ ) THEN\nC\nC Apply transformation to Z_1.\nC\n CALL DROT( NZ, Z( ILOZ, I-1, 1 ), 1, Z( ILOZ, I, 1 ),\n $ 1, CS, SN )\n END IF\nC\n DO 210 J = P, MAX( 2, JMAX+1 ), -1\nC\nC Compute G1 to annihilate from the left the (I,I-1)\nC element of the matrix H_j.\nC\n V( 1 ) = H( I, I-1, J )\n CALL DLARFG( 2, H( I-1, I-1, J ), V, 1, TAU )\n H( I, I-1, J ) = ZERO\nC\nC Apply G1 from the left to transform the rows of the\nC matrix H_j in columns I to I2.\nC\n CALL MB04PY( 'Left', 2, I2-I+1, V, TAU,\n $ H( I-1, I, J ), LDH1, DWORK )\nC\nC Apply G1 from the right to transform the columns of\nC the matrix H_(j-1) in rows I1 to I.\nC\n CALL MB04PY( 'Right', I-I1+1, 2, V, TAU,\n $ H( I1, I-1, J-1 ), LDH1, DWORK )\nC\n IF( WANTZ ) THEN\nC\nC Apply G1 to Z_j.\nC\n CALL MB04PY( 'Right', NZ, 2, V, TAU,\n $ Z( ILOZ, I-1, J ), LDZ1, DWORK )\n END IF\n 210 CONTINUE\nC\n IF( JMAX.GT.0 ) THEN\n H( I, I-1, 1 ) = ZERO\n H( I, I-1, JMAX ) = ZERO\n ELSE\n IF( HH21.EQ.ZERO )\n $ H( I, I-1, 1 ) = ZERO\n END IF\n END IF\n END IF\n END IF\nC\nC Decrement number of remaining iterations, and return to start of\nC the main loop with new value of I.\nC\n ITN = ITN - ITS\n I = L - 1\n IF( I.GE.ILO )\n $ GO TO 40\nC\n RETURN\nC\nC *** Last line of MB03WD ***\n END\n", "meta": {"hexsha": "a0ee6f7779564fefe1629e197a28939665de128c", "size": 32823, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB03WD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB03WD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB03WD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 34.4417628541, "max_line_length": 72, "alphanum_fraction": 0.4705237181, "num_tokens": 10608, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9273632896242074, "lm_q2_score": 0.7217432062975979, "lm_q1q2_score": 0.6693181540560634}} {"text": "\tsubroutine astr(d1,h,pp,s,p,np,dh,dpp,ds,dp,dnp)\nc\tthis subroutine calculates the following five ephermides\nc\tof the sun and moon\nc\th = mean longitude of the sum\nc\tpp = mean longitude of the solar perigee\nc\ts = mean longitude of the moon\nc\tp = mean longitude of the lunar perigee\nc\tnp = negative of the longitude of the mean ascending node\nc\tand their rates of change.\nc\tUnits for the ephermides are cycles and for their derivatives\nc\tare cycles/365 days\nc\tThe formulae for calculating this ephermides were taken from\nc\tpages 98 and 107 of the Explanatory Supplement to the\nc\tAstronomical Ephermeris and the American Ephermis and\nc\tNautical Almanac (1961)\nc\nc\timplicit real*8(a-h,o-z)\n\treal*8 np,d1,h,pp,s,p,dh,dpp,ds,dp,dnp,d2,f,f2\n\td2=d1*1.d-4\n\tf=360.d0\n\tf2=f/365.d0\n\th=279.696678d0+.9856473354d0*d1+.00002267d0*d2*d2\n\tpp=281.220833d0+.0000470684d0*d1+.0000339d0*d2*d2+\n 1 .00000007d0*d2**3\n\ts=270.434164d0+13.1763965268d0*d1-.000085d0*d2*d2+\n 1 .000000039d0*d2**3\n\tp=334.329556d0+.1114040803d0*d1-.0007739d0*d2*d2-\n 1 .00000026d0*d2**3\n\tnp=-259.183275d0+.0529539222d0*d1-.0001557d0*d2*d2-\n 1 .00000005d0*d2**3\n\th=h/f\n\tpp=pp/f\n\ts=s/f\n\tp=p/f\n\tnp=np/f\n\th=h-dint(h)\n\tpp=pp-dint(pp)\n\ts=s-dint(s)\n\tp=p-dint(p)\n\tnp=np-dint(np)\n\tdh=.9856473354d0+2.d-8*.00002267d0*d1\n\tdpp=.0000470684d0+2.d-8*.0000339d0*d1\n 1 +3.d-12*.00000007d0*d1**2\n\tds=13.1763965268d0-2.d-8*.000085d0*d1+\n 1 3.d-12*.000000039d0*d1**2\n\tdp=.1114040803d0-2.d-8*.0007739d0*d1-\n 1 3.d-12*.00000026d0*d1**2\n\tdnp=+.0529539222d0-2.d-8*.0001557d0*d1-\n 1 3.d-12*.00000005d0*d1**2\n\tdh=dh/f2\n\tdpp=dpp/f2\n\tds=ds/f2\n\tdp=dp/f2\n\tdnp=dnp/f2\n\treturn\n\tend\n", "meta": {"hexsha": "95b5f235880a86eb44eb2506cb2b0e5fe90dacfd", "size": 1648, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "create_tides_ROMS/Tides/astr.f", "max_stars_repo_name": "jvmcgovern/romstools_MI", "max_stars_repo_head_hexsha": "57c70c2f630a190fd23ac15ed2ce1b2fae949660", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 18, "max_stars_repo_stars_event_min_datetime": "2015-03-02T14:27:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-16T05:53:08.000Z", "max_issues_repo_path": "create_tides_ROMS/Tides/astr.f", "max_issues_repo_name": "jvmcgovern/romstools_MI", "max_issues_repo_head_hexsha": "57c70c2f630a190fd23ac15ed2ce1b2fae949660", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2016-08-08T12:21:45.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-03T22:40:52.000Z", "max_forks_repo_path": "create_tides_ROMS/Tides/astr.f", "max_forks_repo_name": "jvmcgovern/romstools_MI", "max_forks_repo_head_hexsha": "57c70c2f630a190fd23ac15ed2ce1b2fae949660", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2015-10-05T15:36:28.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-28T16:46:54.000Z", "avg_line_length": 28.9122807018, "max_line_length": 63, "alphanum_fraction": 0.7075242718, "num_tokens": 740, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632956467157, "lm_q2_score": 0.7217432003123989, "lm_q1q2_score": 0.669318152852314}} {"text": "program functions_02\nimplicit none\ninteger :: i\nreal :: f, g\ni = 1\nf = 3.5\n\ng = mysum(i, f)\n\nif (myabs(g-4.5) > 1e-5) error stop\n\ncontains\n\n real function mysum(a, b) result(c)\n integer, intent(in) :: a\n real, intent(in) :: b\n c = a + b\n end function\n\n real function myabs(a) result(c)\n real, intent(in) :: a\n if (a >= 0) then\n c = a\n else\n c = -a\n end if\n end function\n\nend program\n", "meta": {"hexsha": "32252a26b6edcc6228c82ff7630e3a8557739fec", "size": 430, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "integration_tests/functions_02.f90", "max_stars_repo_name": "Thirumalai-Shaktivel/lfortran", "max_stars_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 316, "max_stars_repo_stars_event_min_datetime": "2019-03-24T16:23:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:28:33.000Z", "max_issues_repo_path": "integration_tests/functions_02.f90", "max_issues_repo_name": "Thirumalai-Shaktivel/lfortran", "max_issues_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-07-29T04:58:03.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-04T16:40:06.000Z", "max_forks_repo_path": "integration_tests/functions_02.f90", "max_forks_repo_name": "Thirumalai-Shaktivel/lfortran", "max_forks_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2019-03-28T19:40:07.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T07:28:55.000Z", "avg_line_length": 14.3333333333, "max_line_length": 39, "alphanum_fraction": 0.5511627907, "num_tokens": 155, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245870332531, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.6693044702020159}} {"text": "! Mikayla Webber\r\n! 4670 Numerical Analysis\r\n! Homework IVP Due 12.6.17\r\n\r\nprogram testeuler\r\n implicit none\r\n integer :: i, neq, nsteps\r\n double precision, allocatable, dimension(:,:) :: archive\r\n double precision :: tin, tout, dt, a, b, x, y, xactual, yactual\r\n double precision, allocatable, dimension(:) :: yin, yout, t, f1, f2, u\r\n\r\n neq = 1\r\n nsteps = 50\r\n allocate(yin(neq), yout(neq), t(0:nsteps), u(neq), f1(neq), f2(neq), archive(neq, 0:nsteps))\r\n\r\n a = 1.0d0\r\n b = 2.0d0\r\n archive(:,0) = (/ 1.0d0, 0.0d0, 0.0d0, 1.0d0 /)\r\n dt = (b - a) / dble(nsteps)\r\n\r\n do i = 0, nsteps\r\n t(i) = (a + dble(i) * dt)\r\n end do\r\n\r\n archive(:,0) = (/ 1.0d0, 0.0d0, 0.0d0, 1.0d0 /)\r\n yin = archive(:,0)\r\n\r\n do i = 0, (nsteps - 1)\r\n tin = t(i)\r\n tout = t(i + 1)\r\n yin = archive(:,i)\r\n call computef(neq, tin, yin, f1)\r\n yout = (yin + (tout - tin) * (f1 + f2) / 2.0d0)\r\n archive(:,i+1) = yout\r\n end do\r\n\r\n print*, 'creating \"out1\"'\r\n open(unit=8, file='q1out1', status='replace')\r\n\r\n do i = 0, nsteps\r\n write(8,*) t(i), archive(1,i)\r\n end do\r\n\r\n close(8)\r\n\r\n print*, 'writing pcerror'\r\n open(unit=8, file='pcerror', status='replace')\r\n\r\n do i = 0, nsteps\r\n x = archive(1,i)\r\n y = archive(2,i)\r\n xactual = cos(t(i))\r\n yactual = t(i) / (1 + log(t(i)))\r\n write(8,*) i, sqrt((x - xactual)**2 + (y - yactual)**2)\r\n end do\r\n\r\n deallocate(yin, yout, archive, t, f1, f2)\r\n stop\r\nend program testeuler\r\n\r\n!--------------------------------------------------------------\r\n\r\nsubroutine computef(neq, t, y, f)\r\n implicit none\r\n integer :: neq\r\n double precision :: f(neq)\r\n double precision, intent(in) :: t, y(neq)\r\n\r\n f(1) = (((1 + y(1)) / t) - (y(1) / t)**2)\r\n\r\n return\r\nend\r\n", "meta": {"hexsha": "65a8b585335c9eebae47c48a5d1748879e61da9e", "size": 1728, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "4670 Numerical Analysis/HomeworkIVP/Question1Method1.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/HomeworkIVP/Question1Method1.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/HomeworkIVP/Question1Method1.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.6712328767, "max_line_length": 95, "alphanum_fraction": 0.521412037, "num_tokens": 673, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951182587159, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.6692982363393659}} {"text": " Program dggevx_example\n\n! DGGEVX Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use blas_interfaces, Only: dnrm2\n Use lapack_example_aux, Only: nagf_sort_realvec_rank, &\n nagf_sort_realvec_rank_rearrange\n Use lapack_interfaces, Only: dggevx\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nb = 64, nin = 5, nout = 6\n Logical, Parameter :: verbose = .False.\n! .. Local Scalars ..\n Complex (Kind=dp) :: eig\n Real (Kind=dp) :: abnrm, bbnrm, eps, jswap, rcnd, scal_i, scal_r, small\n Integer :: i, ifail, ihi, ilo, info, j, k, lda, ldb, ldvr, lwork, n\n Logical :: pair\n! .. Local Arrays ..\n Real (Kind=dp), Allocatable :: a(:, :), alphai(:), alphar(:), b(:, :), &\n beta(:), lscale(:), rconde(:), rcondv(:), rscale(:), vr(:, :), &\n vr_row(:), work(:)\n Real (Kind=dp) :: dummy(1, 1)\n Integer, Allocatable :: iwork(:)\n Logical, Allocatable :: bwork(:)\n! .. Intrinsic Procedures ..\n Intrinsic :: abs, all, cmplx, epsilon, max, maxloc, nint, sqrt, sum, &\n tiny\n! .. Executable Statements ..\n Write (nout, *) 'DGGEVX Example Program Results'\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n\n lda = n\n ldb = n\n ldvr = n\n Allocate (a(lda,n), alphai(n), alphar(n), b(ldb,n), beta(n), lscale(n), &\n rconde(n), rcondv(n), rscale(n), vr(ldvr,n), iwork(n+6), bwork(n))\n\n! Use routine workspace query to get optimal workspace.\n lwork = -1\n Call dggevx('Balance', 'No vectors (left)', 'Vectors (right)', &\n 'Both reciprocal condition numbers', n, a, lda, b, ldb, alphar, &\n alphai, beta, dummy, 1, vr, ldvr, ilo, ihi, lscale, rscale, abnrm, &\n bbnrm, rconde, rcondv, dummy, lwork, iwork, bwork, info)\n\n! Make sure that there is enough workspace for block size nb.\n lwork = max((nb+2*n)*n, nint(dummy(1,1)))\n Allocate (work(lwork))\n\n! Read in the matrices A and B\n\n Read (nin, *)(a(i,1:n), i=1, n)\n Read (nin, *)(b(i,1:n), i=1, n)\n\n! Solve the generalized eigenvalue problem\n\n Call dggevx('Balance', 'No vectors (left)', 'Vectors (right)', &\n 'Both reciprocal condition numbers', n, a, lda, b, ldb, alphar, &\n alphai, beta, dummy, 1, vr, ldvr, ilo, ihi, lscale, rscale, abnrm, &\n bbnrm, rconde, rcondv, work, lwork, iwork, bwork, info)\n\n If (info>0) Then\n Write (nout, *)\n Write (nout, 100) 'Failure in DGGEVX. INFO =', info\n Else\n\n! Compute the machine precision and the safe range parameter\n! small\n\n eps = epsilon(1.0E0_dp)\n small = tiny(1.0E0_dp)\n\n! If beta(:) > eps, Order eigenvalues by ascending real parts\n If (all(abs(beta(1:n))>eps)) Then\n work(1:n) = alphar(1:n)/beta(1:n)\n ifail = 0\n Call nagf_sort_realvec_rank(work, 1, n, 'Ascending', iwork, ifail)\n Call nagf_sort_realvec_rank_rearrange(alphar, 1, n, iwork, ifail)\n Call nagf_sort_realvec_rank_rearrange(alphai, 1, n, iwork, ifail)\n Call nagf_sort_realvec_rank_rearrange(beta, 1, n, iwork, ifail)\n! Order the eigenvectors in the same way\n Allocate (vr_row(n))\n Do j = 1, n\n vr_row(1:n) = vr(j, 1:n)\n Call nagf_sort_realvec_rank_rearrange(vr_row, 1, n, iwork, ifail)\n vr(j, 1:n) = vr_row(1:n)\n End Do\n Deallocate (vr_row)\n End If\n\n! Print out eigenvalues and vectors and associated condition\n! number and bounds\n\n pair = .False.\n Do j = 1, n\n\n! Print out information on the j-th eigenvalue\n\n Write (nout, *)\n If ((abs(alphar(j))+abs(alphai(j)))*small>=abs(beta(j))) Then\n Write (nout, 110) 'Eigenvalue(', j, ')', &\n ' is numerically infinite or undetermined', 'ALPHAR(', j, &\n ') = ', alphar(j), ', ALPHAI(', j, ') = ', alphai(j), ', BETA(', &\n j, ') = ', beta(j)\n Else\n If (.Not. pair) Then\n jswap = 1.0_dp\n If (alphai(j)>0.0_dp) Then\n jswap = -jswap\n End If\n End If\n If (alphai(j)==0.0E0_dp) Then\n Write (nout, 120) 'Eigenvalue(', j, ') = ', alphar(j)/beta(j)\n Else\n eig = cmplx(alphar(j), jswap*alphai(j), kind=dp)/ &\n cmplx(beta(j), kind=dp)\n Write (nout, 130) 'Eigenvalue(', j, ') = ', eig\n End If\n End If\n\n If (verbose) Then\n rcnd = rconde(j)\n Write (nout, *)\n Write (nout, 140) ' Reciprocal condition number = ', rcnd\n End If\n\n! Print out information on the j-th eigenvector\n\n Write (nout, *)\n Write (nout, 150) 'Eigenvector(', j, ')'\n If (alphai(j)==0.0E0_dp) Then\n! Let largest element be positive\n work(1:n) = abs(vr(1:n,j))\n k = maxloc(work(1:n), 1)\n If (vr(k,j)<0.0_dp) Then\n vr(1:n, j) = -vr(1:n, j)/dnrm2(n, vr(1,j), 1)\n End If\n Write (nout, 160)(vr(i,j), i=1, n)\n Else\n If (pair) Then\n Write (nout, 170)(vr(i,j-1), -jswap*vr(i,j), i=1, n)\n Else\n! Let largest element be real (and positive).\n work(1:n) = vr(1:n, j)**2 + vr(1:n, j+1)**2\n k = maxloc(work(1:n), 1)\n scal_r = vr(k, j)/sqrt(work(k))/sqrt(sum(work(1:n)))\n scal_i = -vr(k, j+1)/sqrt(work(k))/sqrt(sum(work(1:n)))\n work(1:n) = vr(1:n, j)\n vr(1:n, j) = scal_r*work(1:n) - scal_i*vr(1:n, j+1)\n vr(1:n, j+1) = scal_r*vr(1:n, j+1) + scal_i*work(1:n)\n vr(k, j+1) = 0.0_dp\n Write (nout, 170)(vr(i,j), jswap*vr(i,j+1), i=1, n)\n End If\n pair = .Not. pair\n End If\n If (verbose) Then\n rcnd = rcondv(j)\n Write (nout, *)\n Write (nout, 140) ' Reciprocal condition number = ', rcnd\n End If\n End Do\n\n End If\n\n100 Format (1X, A, I4)\n110 Format (/, 1X, A, I2, 2A, /, 1X, 2(A,I2,A,F11.5), A, I2, A, F11.5)\n120 Format (/, 1X, A, I2, A, F11.5)\n130 Format (/, 1X, A, I2, A, '(', F11.5, ',', F11.5, ')')\n140 Format (1X, A, 1P, E8.1)\n150 Format (1X, A, I2, A)\n160 Format (1X, F11.5)\n170 Format (1X, '(', F11.5, ',', F11.5, ')')\n End Program\n", "meta": {"hexsha": "14b4c318d056cfd43bfb8083de498b4b58a565fc", "size": 6715, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/dggevx_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/dggevx_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/dggevx_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 37.0994475138, "max_line_length": 90, "alphanum_fraction": 0.5189873418, "num_tokens": 2190, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9005297967961706, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6692449409037402}} {"text": "module correlation\n\n! JLR 30/6/2014\n!\n! uneven sampled correlation using Gaussian kernel using method of\n! Rehfeld et al, Nonlinear Processes in Geophysics, 2011\n\nimplicit none\n\ncontains\n\nfunction correlate_gaussian(x,y,tx,ty)\nreal :: correlate_gaussian\n\nreal, intent(in) :: x(:),y(:),tx(:),ty(:)\ninteger :: n,m,i,j\nreal :: b,h,d,xmean,ymean,txmean,tymean,delta_t,pi\nreal :: sdx(size(x)),sdy(size(x)),num(size(x))\nreal :: sdxg,sdyg,numg,deng\n\nn=size(x,1)\nm=size(y,1)\n\npi=abs(atan2(0.0,-1.0))\n\n\n! calc mean for x series\nxmean=0.0\ndo i=1,n\n xmean=xmean+x(i)\nenddo\nxmean=xmean/n\ntxmean=(tx(n)-tx(1))/(n-1)\n\n! calc mean for y series\nymean=0.0\ndo j=1,m\n ymean=ymean+y(j)\nenddo\nymean=ymean/m\ntymean=(ty(m)-ty(1))/(m-1)\n\nsdx=0.0\nsdy=0.0\nnum=0.0\ndelta_t=max(txmean,tymean)\nh=delta_t/4\n\n!$acc kernels loop gang, vector(64)\ndo i=1,n\n do j=1,m\n d=ty(j)-tx(i)\n b=exp(-d**2/(2*h**2))/sqrt(2*pi*h)\n num(i)=num(i)+(x(i)-xmean)*(y(j)-ymean)*b\n sdx(i)=sdx(i)+b*(x(i)-xmean)**2\n sdy(i)=sdy(i)+b*(y(j)-ymean)**2\n enddo\nenddo\n!$acc end kernels\n\nsdxg=0.0\nsdyg=0.0\nnumg=0.0\n\ndo i=1,n\n sdxg=sdxg+sdx(i)\n sdyg=sdyg+sdy(i)\n numg=numg+num(i)\nenddo\n\ncorrelate_gaussian=numg/sqrt(sdxg*sdyg)\n\nend function\n\nend module\n", "meta": {"hexsha": "0e0d0ae64485d18e8c73ec30c6eff10303a28ce1", "size": 1211, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/OpenACC/correlation_gaussian.f90", "max_stars_repo_name": "hhy37/correlation", "max_stars_repo_head_hexsha": "8edc3f09504575a68eddbb826ce2683e826c6b98", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2016-10-13T04:53:58.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-23T15:43:28.000Z", "max_issues_repo_path": "fortran/OpenACC/correlation_gaussian.f90", "max_issues_repo_name": "hhy37/correlation", "max_issues_repo_head_hexsha": "8edc3f09504575a68eddbb826ce2683e826c6b98", "max_issues_repo_licenses": ["MIT"], "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/OpenACC/correlation_gaussian.f90", "max_forks_repo_name": "hhy37/correlation", "max_forks_repo_head_hexsha": "8edc3f09504575a68eddbb826ce2683e826c6b98", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-11-04T22:11:39.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-16T01:31:17.000Z", "avg_line_length": 15.9342105263, "max_line_length": 66, "alphanum_fraction": 0.6548307184, "num_tokens": 521, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178929, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.669244927845458}} {"text": "function r8_hypot ( x, y )\n\n!*****************************************************************************80\n!\n!! R8_HYPOT returns the value of sqrt ( X^2 + Y^2).\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 22 March 2012\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) X, Y, the arguments.\n!\n! Output, real ( kind = 8 ) R8_HYPOT, the value of sqrt ( X^2 + Y^2 ).\n!\n implicit none\n\n real ( kind = 8 ) a\n real ( kind = 8 ) b\n real ( kind = 8 ) c\n real ( kind = 8 ) r8_hypot\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n\n if ( abs ( x ) < abs ( y ) ) then\n a = abs ( y )\n b = abs ( x )\n else\n a = abs ( x )\n b = abs ( y )\n end if\n!\n! A contains the larger value.\n!\n if ( a == 0.0D+00 ) then\n c = 0.0D+00\n else\n c = a * sqrt ( 1.0D+00 + ( b / a )**2 )\n end if\n\n r8_hypot = c\n\n return\nend\n\nsubroutine minfit_fort ( m, n, tol, ab, q )\n\n!*****************************************************************************80\n!\n!! MINFIT computes the singular value decomposition of an N by N array.\n!\n! Discussion:\n!\n! This is an improved version of the EISPACK routine MINFIT\n! restricted to the case M = N and P = 0.\n!\n! The singular values of the array AB are returned in Q. AB is\n! overwritten with the orthogonal matrix V such that u.diag(q) = ab.v,\n! where U is another orthogonal matrix.\n!\n! Thanks to Andreas Zuend for pointing out a potential for overflow in\n! the computation z = sqrt ( f*f + 1 ), 22 March 2012.\n!\n! Modified:\n!\n! 22 March 2012\n!\n! Author:\n!\n! Original FORTRAN77 version by Richard Brent.\n! FORTRAN90 version by John Burkardt.\n!\n! Reference:\n!\n! Richard Brent,\n! Algorithms for Minimization with Derivatives,\n! Prentice Hall, 1973,\n! Reprinted by Dover, 2002.\n!\n! James Wilkinson, Christian Reinsch,\n! Handbook for Automatic Computation,\n! Volume II, Linear Algebra, Part 2,\n! Springer Verlag, 1971.\n!\n! B Smith, J Boyle, Jack Dongarra, Burton Garbow, Y Ikebe, \n! Virginia Klema, Cleve Moler,\n! Matrix Eigensystem Routines, EISPACK Guide,\n! Lecture Notes in Computer Science, Volume 6,\n! Springer Verlag, 1976.\n!\n! Parameters:\n!\n! Input, integer ( kind = 4 ) M, the leading dimension of AB, which must be\n! at least N.\n!\n! Input, integer ( kind = 4 ) N, the order of the matrix AB.\n!\n! Input, real ( kind = 8 ) TOL, a tolerance which determines when a vector\n! (a column or part of a column of the matrix) may be considered\n! \"essentially\" equal to zero.\n!\n! Input/output, real ( kind = 8 ) AB(M,N). On input, an N by N array whose\n! singular value decomposition is desired. On output, ?\n!\n! Input, real ( kind = 8 ) Q(N), ?\n!\n implicit none\n\n integer ( kind = 4 ) m\n integer ( kind = 4 ) n\n\n real ( kind = 8 ) ab(m,n)\n real ( kind = 8 ) c\n real ( kind = 8 ) e(n)\n real ( kind = 8 ) eps\n real ( kind = 8 ) f\n real ( kind = 8 ) g\n real ( kind = 8 ) h\n integer ( kind = 4 ) i\n integer ( kind = 4 ) ii\n integer ( kind = 4 ) j\n integer ( kind = 4 ) k\n integer ( kind = 4 ) kk\n integer ( kind = 4 ) kt\n integer ( kind = 4 ), parameter :: kt_max = 30\n integer ( kind = 4 ) l\n integer ( kind = 4 ) ll\n real ( kind = 8 ) q(n)\n real ( kind = 8 ) r8_hypot\n real ( kind = 8 ) s\n real ( kind = 8 ) temp\n real ( kind = 8 ) tol\n real ( kind = 8 ) x\n real ( kind = 8 ) y\n real ( kind = 8 ) z\n!\n! Householder's reduction to bidiagonal form.\n!\n if ( n == 1 ) then\n q(1) = ab(1,1)\n ab(1,1) = 1.0D+00\n return\n end if\n\n eps = epsilon ( eps )\n g = 0.0D+00\n x = 0.0D+00\n\n do i = 1, n\n\n e(i) = g\n l = i + 1\n\n s = sum ( ab(i:n,i)**2 )\n\n g = 0.0D+00\n\n if ( tol <= s ) then\n\n f = ab(i,i)\n\n g = sqrt ( s )\n if ( 0.0D+00 <= f ) then\n g = -g\n end if\n\n h = f * g - s\n ab(i,i) = f - g\n\n do j = l, n\n\n f = dot_product ( ab(i:n,i), ab(i:n,j) ) / h\n\n ab(i:n,j) = ab(i:n,j) + f * ab(i:n,i)\n\n end do \n\n end if\n\n q(i) = g\n\n s = sum ( ab(i,l:n)**2 )\n\n g = 0.0D+00\n\n if ( tol <= s ) then\n\n if ( i /= n ) then\n f = ab(i,i+1)\n end if\n\n g = sqrt ( s )\n if ( 0.0D+00 <= f ) then\n g = - g\n end if\n\n h = f * g - s\n\n if ( i /= n ) then\n\n ab(i,i+1) = f - g\n e(l:n) = ab(i,l:n) / h\n\n do j = l, n\n\n s = dot_product ( ab(j,l:n), ab(i,l:n) )\n\n ab(j,l:n) = ab(j,l:n) + s * e(l:n)\n\n end do\n\n end if\n\n end if\n \n y = abs ( q(i) ) + abs ( e(i) )\n \n x = max ( x, y )\n \n end do\n \n!\n! Accumulation of right-hand transformations.\n!\n ab(n,n) = 1.0D+00\n g = e(n)\n l = n\n\n do ii = 2, n\n\n i = n - ii + 1\n\n if ( g /= 0.0D+00 ) then\n\n h = ab(i,i+1) * g\n\n ab(l:n,i) = ab(i,l:n) / h\n\n do j = l, n\n\n s = dot_product ( ab(i,l:n), ab(l:n,j) )\n\n ab(l:n,j) = ab(l:n,j) + s * ab(l:n,i)\n\n end do\n\n end if\n\n ab(i,l:n) = 0.0D+00\n ab(l:n,i) = 0.0D+00\n ab(i,i) = 1.0D+00\n\n g = e(i)\n\n l = i\n end do\n\n!\n! Diagonalization of the bidiagonal form.\n!\n eps = eps * x\n\n do kk = 1, n\n\n k = n - kk + 1\n kt = 0\n\n10 continue\n\n kt = kt + 1\n\n if ( kt_max < kt ) then\n e(k) = 0.0D+00\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'MINFIT - Warning!'\n write ( *, '(a)' ) ' The QR algorithm failed to converge.'\n end if\n\n do ll = 1, k\n\n l = k - ll + 1\n \n if ( abs ( e(l) ) <= eps ) then\n go to 20\n end if\n\n if ( l /= 1 .and. abs ( q(l-1) ) <= eps ) then\n exit\n end if\n\n end do\n!\n! Cancellation of E(L) if 1 < L.\n!\n c = 0.0D+00\n s = 1.0D+00\n\n do i = l, k\n\n f = s * e(i)\n e(i) = c * e(i)\n if ( abs ( f ) <= eps ) then\n exit\n end if\n g = q(i)\n!\n! q(i) = h = sqrt(g*g + f*f).\n!\n h = r8_hypot ( f, g )\n\n q(i) = h\n\n if ( h == 0.0D+00 ) then\n g = 1.0D+00\n h = 1.0D+00\n end if\n\n c = g / h\n s = - f / h\n\n end do\n!\n! Test for convergence.\n!\n20 continue\n\n z = q(k)\n\n if ( l == k ) then\n if ( z < 0.0D+00 ) then\n q(k) = - z\n ab(1:n,k) = - ab(1:n,k)\n end if\n cycle\n end if\n!\n! Shift from bottom 2*2 minor.\n!\n x = q(l)\n y = q(k-1)\n g = e(k-1)\n h = e(k)\n f = ( ( y - z ) * ( y + z ) + ( g - h ) * ( g + h ) ) / ( 2.0D+00 * h * y )\n\n g = r8_hypot ( f, 1.0D+00 )\n\n if ( f < 0.0D+00 ) then\n temp = f - g\n else\n temp = f + g\n end if\n\n f = ( ( x - z ) * ( x + z ) + h * ( y / temp - h ) ) / x\n!\n! Next QR transformation.\n!\n c = 1.0D+00\n s = 1.0D+00\n\n do i = l + 1, k\n\n g = e(i)\n y = q(i)\n h = s * g\n g = g * c\n\n z = r8_hypot ( f, h )\n\n e(i-1) = z\n\n if ( z == 0.0D+00 ) then\n f = 1.0D+00\n z = 1.0D+00\n end if\n\n c = f / z\n s = h / z\n f = x * c + g * s\n g = - x * s + g * c\n h = y * s\n y = y * c\n\n do j = 1, n\n x = ab(j,i-1)\n z = ab(j,i)\n ab(j,i-1) = x * c + z * s\n ab(j,i) = - x * s + z * c\n end do\n\n z = r8_hypot ( f, h )\n\n q(i-1) = z\n\n if ( z == 0.0D+00 ) then\n f = 1.0D+00\n z = 1.0D+00\n end if\n\n c = f / z\n s = h / z\n f = c * g + s * y\n x = - s * g + c * y\n\n end do\n\n e(l) = 0.0D+00\n e(k) = f\n q(k) = x\n go to 10\n\n end do\n\n return\nend\n", "meta": {"hexsha": "1492fb07ed63490b547e44993e95c08d250e6b13", "size": 7443, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/minfit.f90", "max_stars_repo_name": "horvatm/minimizers", "max_stars_repo_head_hexsha": "737f3c38e73def43eaf36a47b9f9803452999625", "max_stars_repo_licenses": ["MIT"], "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/minfit.f90", "max_issues_repo_name": "horvatm/minimizers", "max_issues_repo_head_hexsha": "737f3c38e73def43eaf36a47b9f9803452999625", "max_issues_repo_licenses": ["MIT"], "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/minfit.f90", "max_forks_repo_name": "horvatm/minimizers", "max_forks_repo_head_hexsha": "737f3c38e73def43eaf36a47b9f9803452999625", "max_forks_repo_licenses": ["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.554245283, "max_line_length": 80, "alphanum_fraction": 0.4496842671, "num_tokens": 2847, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357529306639, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6692159128439356}} {"text": "!------------------------------------------------------------------------------!\n! The Community Multiscale Air Quality (CMAQ) system software is in !\n! continuous development by various groups and is based on information !\n! from these groups: Federal Government employees, contractors working !\n! within a United States Government contract, and non-Federal sources !\n! including research institutions. These groups give the Government !\n! permission to use, prepare derivative works of, and distribute copies !\n! of their work in the CMAQ system to the public and to permit others !\n! to do so. The United States Environmental Protection Agency !\n! therefore grants similar permission to use the CMAQ system software, !\n! but users are requested to provide copies of derivative works or !\n! products designed to operate in the CMAQ system to the United States !\n! Government without restrictions as to use by others. Software !\n! that is used with the CMAQ system but distributed under the GNU !\n! General Public License or the GNU Lesser General Public License is !\n! subject to their copyright restrictions. !\n!------------------------------------------------------------------------------!\n\nREAL FUNCTION mapfac_merc (phi)\n\n!-------------------------------------------------------------------------------\n! Name: Map-Scale Factor for Mercator projection\n! Purpose: Calculates map-scale factors for Mercator projection from latitude.\n! Notes: Equation taken from \"Numerical Prediction and Dynamic Meteorology\",\n! Second Edition, by George J. Haltiner and Roger Terry Williams\n! (1980), pp. 13.\n! Revised: 15 Sep 2009 Original version. (T. Otte)\n! 07 Sep 2011 Updated disclaimer. (T. Otte)\n!-------------------------------------------------------------------------------\n\n IMPLICIT NONE\n\n REAL(8) :: deg2rad ! convert degrees to radians\n REAL, INTENT(IN) :: phi ! latitude [deg]\n REAL(8) :: phirad ! latitude [rad]\n REAL(8) :: pi\n REAL(8) :: piover4 ! pi/4\n\n!-------------------------------------------------------------------------------\n! Compute constants.\n!-------------------------------------------------------------------------------\n\n piover4 = DATAN(1.0d0)\n pi = 4.0d0 * piover4\n deg2rad = pi / 1.8d2\n\n!-------------------------------------------------------------------------------\n! Compute map-scale factor, MAPFAC.\n!\n! M(phi) = COS phi0 / COS phi\n!\n! where phi0 is the latitude of the \"true\" projection (assumed to be equator)\n!-------------------------------------------------------------------------------\n\n phirad = DBLE(phi) * deg2rad ! convert PHI from degrees to radians\n\n mapfac_merc = REAL( 1.0d0 / DCOS(phirad) )\n\nEND FUNCTION mapfac_merc\n", "meta": {"hexsha": "6e7822fcf423762c87e06f26b680dc488d53de06", "size": 3009, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "PREP/mcip/src/mapfac_merc.f90", "max_stars_repo_name": "Simeng-unique/CMAQ-changed", "max_stars_repo_head_hexsha": "cb83401728ed7ea1bb19a6986c0acc84dabe11a4", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 203, "max_stars_repo_stars_event_min_datetime": "2017-02-04T18:01:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T09:09:00.000Z", "max_issues_repo_path": "PREP/mcip/src/mapfac_merc.f90", "max_issues_repo_name": "Simeng-unique/CMAQ-changed", "max_issues_repo_head_hexsha": "cb83401728ed7ea1bb19a6986c0acc84dabe11a4", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 54, "max_issues_repo_issues_event_min_datetime": "2017-01-03T21:40:27.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-04T19:03:53.000Z", "max_forks_repo_path": "PREP/mcip/src/mapfac_merc.f90", "max_forks_repo_name": "Simeng-unique/CMAQ-changed", "max_forks_repo_head_hexsha": "cb83401728ed7ea1bb19a6986c0acc84dabe11a4", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 170, "max_forks_repo_forks_event_min_datetime": "2016-11-09T22:30:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T03:21:59.000Z", "avg_line_length": 50.15, "max_line_length": 80, "alphanum_fraction": 0.5014955135, "num_tokens": 609, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357529306639, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6692159128439356}} {"text": "program complex_02\nimplicit none\n\ncomplex :: x, z, w, i_\nreal :: a, b\n\nx = (1.0,-3.0)\na = 3.0\nb = 4.0\ni_ = (0, 1)\nz = a + i_*b\nw = a+b + i_*(a-b)\n\nprint *, x, z, w\n\nend program\n", "meta": {"hexsha": "cf75f86ae2e41264e48cc8f2087ecd70e3fe3e19", "size": 177, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "integration_tests/complex_02.f90", "max_stars_repo_name": "Thirumalai-Shaktivel/lfortran", "max_stars_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 316, "max_stars_repo_stars_event_min_datetime": "2019-03-24T16:23:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:28:33.000Z", "max_issues_repo_path": "integration_tests/complex_02.f90", "max_issues_repo_name": "Thirumalai-Shaktivel/lfortran", "max_issues_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-07-29T04:58:03.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-04T16:40:06.000Z", "max_forks_repo_path": "integration_tests/complex_02.f90", "max_forks_repo_name": "Thirumalai-Shaktivel/lfortran", "max_forks_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2019-03-28T19:40:07.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T07:28:55.000Z", "avg_line_length": 10.4117647059, "max_line_length": 22, "alphanum_fraction": 0.5197740113, "num_tokens": 88, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.867035752930664, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6692159037431432}} {"text": " SUBROUTINE PEARSN(X,Y,N,R,PROB,Z)\n PARAMETER (TINY=1.E-20)\n DIMENSION X(N),Y(N)\n AX=0.\n AY=0.\n DO 11 J=1,N\n AX=AX+X(J)\n AY=AY+Y(J)\n11 CONTINUE\n AX=AX/N\n AY=AY/N\n SXX=0.\n SYY=0.\n SXY=0.\n DO 12 J=1,N\n XT=X(J)-AX\n YT=Y(J)-AY\n SXX=SXX+XT**2\n SYY=SYY+YT**2\n SXY=SXY+XT*YT\n12 CONTINUE\n R=SXY/SQRT(SXX*SYY)\n Z=0.5*ALOG(((1.+R)+TINY)/((1.-R)+TINY))\n DF=N-2\n T=R*SQRT(DF/(((1.-R)+TINY)*((1.+R)+TINY)))\n PROB=BETAI(0.5*DF,0.5,DF/(DF+T**2))\nC PROB=ERFCC(ABS(Z*SQRT(N-1.))/1.4142136)\n RETURN\n END\n", "meta": {"hexsha": "9ff2acd610618ffa3213634b095b432f3768d37c", "size": 640, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "Math3/NumRec/source/pearsn.for", "max_stars_repo_name": "domijin/MM3", "max_stars_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Math3/NumRec/source/pearsn.for", "max_issues_repo_name": "domijin/MM3", "max_issues_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Math3/NumRec/source/pearsn.for", "max_forks_repo_name": "domijin/MM3", "max_forks_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.3333333333, "max_line_length": 48, "alphanum_fraction": 0.44375, "num_tokens": 292, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741308615412, "lm_q2_score": 0.7025300573952054, "lm_q1q2_score": 0.6692119588273464}} {"text": "\n\nsubroutine julian (year, month, day, hour, minute, second, julian_date)\n implicit none\n integer, intent(in) :: year, month, day, hour, minute\n real*8, intent(in) :: second\n real*8, intent(out) :: julian_date\n\n real*8 UT, Term1\n integer Term2, Term3\n\n Term1 = 367.000 * year\n Term2 = INT((7 * (year + INT((month + 9) / 12))) / 4)\n Term3 = INT(275 * month / 9)\n UT = ((second / 60.000 + minute) / 60.000 + hour) / 24.000\n\n julian_date = (Term1 - Term2 + Term3) + Day + 1721013.500 + UT\n\n return\n end subroutine\n\n\nreal*8 function greenwich_sidereal (julian_date)\n use constants\n implicit none\n real*8, intent(in) :: julian_date\n real*8 temp, tu\n\n tu = ( DINT(julian_date) + 0.500 - 2451545.000 ) / (36525.000)\n temp = 1.75336855900 + 628.331970500 * tu + 6.7707081270 - 06 * tu ** 2 + radperday * DBLE (julian_date-DINT(julian_date) - 0.5)\n\n temp = DMOD (temp, twopi)\n if ( temp<0.000) then\n temp = temp + twopi\n endif\n\n greenwich_sidereal = temp\n\n return\n end function\n\n\nsubroutine local_sidereal (julian_date, lon, lst)\n use constants\n implicit none\n real*8, intent(in) :: julian_date, lon\n real*8, intent(out) :: lst\n\n external greenwich_sidereal\n real*8 greenwich_sidereal, gst\n\n gst = greenwich_sidereal(julian_date)\n lst = lon + gst\n\n lst = DMOD ( lst, twopi)\n if (lst<0.000) then\n lst = lst + twopi\n endif\n\n return\n end subroutine\n\n\n!subroutine inverse_julian (julian_date)\n! implicit none\n! real*8 temp, tu, days\n! integer year, month, day, hour, minute, sec, leapyears\n!\n! temp = julian_date - 2415019.5\n! tu = temp / 365.25\n! year = 1900 + trunc(tu)\n! leapyears = trunc((year - 1900 - 1) / 4.0)\n! days = temp - ((year - 1900) * 365.0 + leapyears)\n!\n! if (days < 1.0) then\n! year = year - 1\n! leapyears = trunc((year - 1900 - 1) / 4.0)\n! days = temp - ((year - 1900) * 365.0 + leapyears)\n! end if\n!\n! return\n! end subroutine\n\n\n!subroutine sunrise_sunset (julian_date, lat, lon, which, sunrise, sunset)\n! use constants\n! implicit none\n!\n! real*8 julian_date, lat, lon, sunrise, sunset\n! character which\n! real*8 z, t, m, l, ra, sindelta, delta, h, sec, days, rad\n! integer year, month, day, hr, min\n!\n! rad = 57.2957795130823000\n!\n! if (which == 's') then\n! z = (90.000 + 50.000 / 60.000) / rad\n! elseif (which == 'c') then\n! z = 96.000 / rad\n! elseif (which == 'n') then\n! z = 102.000 / rad\n! elseif (which == 'a') then\n! z = 108.000 / rad\n! end if\n!\n! end subroutine", "meta": {"hexsha": "6b52963ba677b070897b8886b18939ff56928d73", "size": 2627, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/dates.f95", "max_stars_repo_name": "aschleg/astropynamic", "max_stars_repo_head_hexsha": "da0e652509853d9c1fda53b4c21055ce209cef07", "max_stars_repo_licenses": ["MIT"], "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/dates.f95", "max_issues_repo_name": "aschleg/astropynamic", "max_issues_repo_head_hexsha": "da0e652509853d9c1fda53b4c21055ce209cef07", "max_issues_repo_licenses": ["MIT"], "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/dates.f95", "max_forks_repo_name": "aschleg/astropynamic", "max_forks_repo_head_hexsha": "da0e652509853d9c1fda53b4c21055ce209cef07", "max_forks_repo_licenses": ["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.7830188679, "max_line_length": 132, "alphanum_fraction": 0.5900266464, "num_tokens": 936, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545392102522, "lm_q2_score": 0.7057850278370112, "lm_q1q2_score": 0.6691932778502964}} {"text": "C\nC************************** NUDWXY ************************************\nC\nC calculate horizontal weighting function W(x,y) for nudging\nC\nC***********************************************************************\nC\n DOUBLE PRECISION FUNCTION NUDWXY(WFLAG,XX,YY,XXO,YYO,RXY)\nC\n IMPLICIT NONE\n INTEGER WFLAG\n REAL*8 R2,D2\n REAL*8 XX,YY,XXO,YYO,RXY\nC\n R2=RXY*RXY\n D2=(XX-XXO)*(XX-XXO) + (YY-YYO)*(YY-YYO)\n IF (WFLAG .EQ. 0) THEN\n IF (D2 .LE. R2) THEN\n NUDWXY=(R2-D2)/(R2+D2)\n ELSE\n NUDWXY=0.0D0\n END IF\n ELSE\n NUDWXY=DEXP(-1.0d0*(D2/R2))\n END IF\nC\n RETURN\n END\n", "meta": {"hexsha": "3a02984c081ee44c5488d79ea7487efb1b81c7a2", "size": 678, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "examples/weil_exemple_withDA/my_cathy_prj/src/nudwxy.f", "max_stars_repo_name": "BenjMy/pycathy_wrapper", "max_stars_repo_head_hexsha": "8639713acbb5bc5c5cd293b94bdafe017d03f199", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "examples/weil_exemple_withDA/my_cathy_prj/src/nudwxy.f", "max_issues_repo_name": "BenjMy/pycathy_wrapper", "max_issues_repo_head_hexsha": "8639713acbb5bc5c5cd293b94bdafe017d03f199", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2021-10-14T13:07:46.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-02T03:32:05.000Z", "max_forks_repo_path": "examples/weil_exemple_withDA/my_cathy_prj/src/nudwxy.f", "max_forks_repo_name": "BenjMy/pycathy_wrapper", "max_forks_repo_head_hexsha": "8639713acbb5bc5c5cd293b94bdafe017d03f199", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.3793103448, "max_line_length": 72, "alphanum_fraction": 0.4247787611, "num_tokens": 232, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465062370313, "lm_q2_score": 0.7154240079185319, "lm_q1q2_score": 0.669169346284693}} {"text": "\r\n!!!!!!!!!!!!!!!!!NOTE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n!!!! O2- species 1;O - species 2;!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n!!!!Adaptive Explicit Method!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\nprogram main\r\n\r\nimplicit none\r\n\r\nreal(8),parameter :: Runiv=8314.34d0,M1=32d0,M2=16d0,TB1=1d0,TB2=3d0,Cf=2.75e16,eta=-1d0, &\r\n theta=59500d0,Ti= 4150,rhoi=3.35e-4 ! intial,fixed values\r\nreal(8),parameter,dimension(7) :: A1=(/3.660960830d+00,6.56365523d-04,-1.41149485d-07, & ! O2 aboveT=1000K\r\n 2.05797658d-11,-1.29913248d-15,-1.21597725d+03,3.41536184d+00/), &\r\n A2=(/2.54363697d+00,-2.73162486d-05,-4.19029520d-09, & ! O aboveT=1000K\r\n 4.95481845d-12,-4.79553694d-16,2.92260120d+04,4.92229457d+00/)\r\nreal(8),parameter,dimension(7) :: B1=(/3.78245636d+00,-2.99673415d-03,9.84730200d-06, &\r\n -9.68129508d-09,3.24372836d-12,-1.06394356d+03,3.65767573d+00/), & ! O2 below T=1000K\r\n B2=(/3.16826710d+00,-3.27931884d-03,6.64306396d-06, &\r\n -6.12806624d-09,2.11265971d-12,2.91222592d+04,2.05193346d+00/) ! O below T=1000K\r\nreal(8),dimension(7):: A,B,A1h,B1h,A2h,B2h\r\n\r\nreal(8) :: T,rho1,rho2,kf,hi,ei,e1,e2,engi,eng,eng1,eng2,h1,h2,d1dt,gp,gr,dg,keq,dt,deng,dengdT,time, &\r\n res0,res,res0T,resT,relax,dt0,Told\r\ninteger :: nitermax,nmax,n,i\r\nrho1=0d0\r\nrho2=0d0\r\nT=Ti\r\ndt0= 1e-3\r\nnitermax = 1000\r\nnmax = 1000000\r\ntime=0\r\nrelax=0.5\r\n\r\n A1h=A1/32;\r\n A2h=A2/16;\r\n B1h=B1/32;\r\n B2h=B2/16;\r\n\r\n\r\nrho1=rhoi\r\nrho2=rhoi-rho1\r\n\r\nhi =Runiv*(A1h(1)*Ti &\r\n +A1h(2)*(Ti**2)/2 &\r\n +A1h(3)*(Ti**3)/3 &\r\n +A1h(4)*(Ti**4)/4 &\r\n +A1h(5)*(Ti**5)/5 &\r\n +A1h(6))\r\n\r\nei = hi - Runiv*Ti/M1\r\nengi=rhoi*ei\r\n\r\nopen (unit = 2, file = \"data.dat\")\r\ndt =dt0\r\n!!!Loop starts!!!!!!!!!!!\r\n\r\ndo i=1,nmax\r\n\r\nif (T<=1000) then\r\nA=B1h\r\nB=B2h\r\nelseif (T>1000) then\r\nA=A1h\r\nB=A2h\r\nendif\r\n\r\n!!!!!!keq,kf computation!!!!!!!!!\r\n\r\ngr = Runiv*M1*(A(1)*(1-log(T))*T &\r\n -A(7)*T &\r\n -A(2)*(T**2)/2 &\r\n -A(3)*(T**3)/6 &\r\n -A(4)*(T**4)/12 &\r\n -A(5)*(T**5)/20+A(6))\r\n\r\n\r\ngp = Runiv*2*M2*(B(1)*(1-log(T))*T &\r\n -B(7)*T &\r\n -B(2)*(T**2)/2 &\r\n -B(3)*(T**3)/6 &\r\n -B(4)*(T**4)/12 &\r\n -B(5)*(T**5)/20+B(6))\r\n\r\ndg = gp-gr\r\n\r\n\r\n\r\nkeq =(101325d0/Runiv/T)*exp(-dg/Runiv/T)\r\nkf = (2.75d16/T)* exp(-59500d0/T)\r\n\r\n\r\nd1dt= -1*M1*(kf)*((rho1/M1)- rho2*rho2/(M2*M2*keq))*(TB1*rho1/M1 + TB2*rho2/M2)\r\n\r\nrho1 = rho1 +dt*d1dt\r\nrho2=rhoi-rho1\r\n\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!\r\n!!Net energy change = 0!\r\n!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\ndo n = 1,nitermax\r\n\r\nif (T<=1000) then\r\n A=B1h\r\n B=B2h\r\nelseif (T>1000) then\r\n A=A1h\r\n B=A2h\r\nendif\r\n\r\nh1 = (A(1)*T &\r\n + A(2)*(T**2)/2 &\r\n + A(3)*(T**3)/3 &\r\n + A(4)*(T**4)/4 &\r\n + A(5)*(T**5)/5 &\r\n + A(6))*Runiv\r\n\r\ne1 = h1- Runiv*T/M1\r\neng1=rho1*e1\r\n\r\nh2 = (B(1)*T &\r\n + B(2)*(T**2)/2 &\r\n + B(3)*(T**3)/3 &\r\n + B(4)*(T**4)/4 &\r\n + B(5)*(T**5)/5 &\r\n + B(6))*Runiv\r\n\r\ne2 = h2- Runiv*T/M2\r\neng2=rho2*e2\r\n\r\neng=eng1+eng2\r\ndeng=eng-engi\r\n\r\n\r\n!!!!!!!!! Update T to make deng =0\r\nTold=T\r\ndengdT = (rho1*( (A(1)+A(2)*(T) + A(3)*(T**2)+A(4)*(T**3)+ &\r\n A(5)*(T**4)) - 1/M1) + rho2*(B(1)+B(2)*(T)/2 + B(3)*(T**2)+B(4)*(T**3)+ &\r\n B(5)*(T**4) - 1/M2))*Runiv\r\n\r\nT = T - deng/dengdT\r\n\r\nif (n.eq.1) res0T = abs(deng/dengdT)\r\nresT = abs(deng/dengdT)/res0\r\n\r\nif (resT < 1e-6) then\r\n\r\n exit\r\n\r\nend if\r\n\r\nend do\r\n\r\n\r\n\r\n\r\n\r\nif (i.eq.1) res0=d1dt\r\nres = d1dt/res0\r\nif ((res < 1e-6).AND.(T-Told <1e-6)) then\r\n exit\r\nend if\r\nwrite(2,*) i,dt,time,T,abs(T-Told)\r\nprint *, i,time,rho1/rhoi,T,dt,abs(T-Told)\r\n!print*, res\r\n\r\n!!!!!!!!adaptive time step!!!!!!!\r\n\r\ndt = 1/relax * abs(res0/res)*dt0\r\n\r\ntime = time + dt\r\n\r\nend do\r\n\r\nclose(2)\r\n\r\nend\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "meta": {"hexsha": "bb0c2c5544495712efb00374805ee19ea45c6eb8", "size": 4216, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "O2_dissociation/Adaptive_Time_Stepping/main.f95", "max_stars_repo_name": "rohitvuppala/random_code", "max_stars_repo_head_hexsha": "93bb6161cd401f3f06fdf629df1dabfeb5f2b8d2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "O2_dissociation/Adaptive_Time_Stepping/main.f95", "max_issues_repo_name": "rohitvuppala/random_code", "max_issues_repo_head_hexsha": "93bb6161cd401f3f06fdf629df1dabfeb5f2b8d2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "O2_dissociation/Adaptive_Time_Stepping/main.f95", "max_forks_repo_name": "rohitvuppala/random_code", "max_forks_repo_head_hexsha": "93bb6161cd401f3f06fdf629df1dabfeb5f2b8d2", "max_forks_repo_licenses": ["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.4255319149, "max_line_length": 129, "alphanum_fraction": 0.4316888046, "num_tokens": 1774, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465062370312, "lm_q2_score": 0.7154240079185318, "lm_q1q2_score": 0.6691693462846928}} {"text": "c # ------------------------------------------------------------------\nc # MAPC2M_PILLOWSPHERE\nc # ------------------------------------------------------------------\nc #\nc # Maps a logically rectangular Cartesian grid in [-1,1]x[-1,1] to\nc # either the upper hemisphere (blockno == 0) or the lower hemisphere\nc # (blockno == 1).\nc #\nc # ------------------------------------------------------------------\n subroutine mapc2m_pillowsphere(blockno, xc1,yc1,xp,yp,zp)\n implicit none\n\n external mapc2m_cart\n double precision xc1,yc1, xp, yp, zp\n\n double precision x1, y1, d, rp2, xc, yc, zc\n integer blockno\n logical l1, l2\n logical ispillowsphere\n\nc # Map to [-1,1]x[-1,1]\n call mapc2m_cart(blockno,xc1,yc1,xc,yc,zc)\n\nc # Map xc and yc from ghost cells to interior\n d = max(xc - 1.0,0.d0) + max(-1 - xc,0.d0)\n x1 = ((1-d)/(1+d))*xc\n\n d = max(yc - 1,0.d0) + max(-1 - yc,0.d0)\n y1 = ((1-d)/(1+d))*yc\n\nc # Get circle of radius sqrt(2.d0). Cluster radial\nc # direction towards boundary\n call mapc2p_circle_sp(x1,y1,xp,yp)\n\nc # Set z value\n rp2 = xp**2 + yp**2\n if (abs(rp2 - 2.d0) .lt. 1d-10) then\n zp = 0.d0\n else\n zp = sqrt(2.d0 - rp2)\n endif\n\nc # Values that are outside of [-1,1]x[-1,1] (in ghost cell regions)\nc # to the lower hemisphere\nc # Juqueen complained about the 'xor', because it is not in the\nc # Fortran standard. Use .neqv. instead.\n l1 = abs(xc) .gt. 1\n l2 = abs(yc) .gt. 1\n if (l1 .neqv. l2) then\n zp = -zp\n endif\n\nc # This maps everything to the unit sphere\n xp = xp/sqrt(2.d0)\n yp = yp/sqrt(2.d0)\n zp = zp/sqrt(2.d0)\n\nc # Set lower hemisphere\n if (ispillowsphere()) then\n if (blockno .eq. 1) then\n zp = -zp\n endif\n endif\n\n return\n end\nc --------------------------------- MAPC2M -------------------------------\n\n\nc # Map single grid to the disk. Since this disk will be used for the\nc #\n subroutine mapc2p_circle_sp(x1,y1,xp,yp)\n implicit none\n\n double precision xc,yc,xp,yp, x1,y1\n double precision xi,eta,x,y, minxy,maxxy\n double precision xit, etat, dd\n\n double precision pi, pi2\n common /compi/ pi, pi2\n\n xc = x1\n yc = y1\n\n if (x1 .lt. -1.d0) then\n xc = -(xc + 2)\n endif\n\n xi = min(abs(xc),abs(yc))\n eta = max(abs(xc),abs(yc))\n eta = max(eta,1.d-10)\n\n dd = sin(pi*eta/2.d0)\nc dd = eta*(2-eta)\n\n xit = (xi/eta)*dd\n etat = dd\n\n call map_north_sector_sp(xit,etat,x,y)\n\n minxy = min(abs(x),abs(y))\n maxxy = max(abs(x),abs(y))\n\n if (abs(xc) .le. abs(yc)) then\nc # In NS sectors\n xp = sign(1.d0,xc)*minxy\n yp = sign(1.d0,yc)*maxxy\n else\nc # In EW sectors\n xp = sign(1.d0,xc)*maxxy\n yp = sign(1.d0,yc)*minxy\n endif\n\n\n end\n\n subroutine map_north_sector_sp(xi,eta,x,y)\n implicit none\n\n double precision xi,eta,x,y\n\n x = xi\n y = sqrt(2 - xi**2) - sqrt(2 - eta**2) + eta\n\n end\n", "meta": {"hexsha": "af69bd5a5ca1d091ede53d13c5fb46b29d680f6f", "size": 3178, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/mappings/pillowsphere/mapc2m_pillowsphere.f", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/mappings/pillowsphere/mapc2m_pillowsphere.f", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-08-02T09:52:43.000Z", "max_issues_repo_issues_event_max_datetime": "2017-08-02T14:16:23.000Z", "max_forks_repo_path": "src/mappings/pillowsphere/mapc2m_pillowsphere.f", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "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.2222222222, "max_line_length": 74, "alphanum_fraction": 0.4905601007, "num_tokens": 1050, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.89330940889474, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6691666555581253}} {"text": "!>\n!! This module provides two time stepping methods to solve the initial value problem\n!!\n!! \\\\( q_t = F(q) = F_{\\\\text{adv}}(q) + F_{\\\\text{diff}}(q) \\\\)\n!!\n!! Depending on the preprocessor flag *linear*, the right hand side stems either from Burger's equation\n!!\n!! \\\\( F(q) = -q \\\\cdot \\\\nabla q + \\\\nu \\\\Delta q \\\\)\n!!\n!! or a linear advection diffusion equation\n!!\n!! \\\\( F(q) = -\\\\nabla q + \\\\nu \\Delta q \\\\)\n!!\n!! The contributions to \\\\( F \\\\) from advection and diffusion are computed in the corresponding modules.\nMODULE timestepper\n\nUSE omp_lib, only : omp_get_thread_num\nUSE Advection, only : GetRHSAdvection, InitializeAdvection, FinalizeAdvection\nUSE Diffusion, only : GetRHSDiffusion, InitializeDiffusion\nUSE boundaries, only : periodic, InitializeBoundaries, FinalizeBoundaries\n\nIMPLICIT NONE\n\nPRIVATE\nPUBLIC :: Euler, Rk3Ssp, InitializeTimestepper, FinalizeTimestepper\n\n\n!> Auxiliary buffer holding intermediate solutions in the stage computations for the 3rd order RK-SSP\nDOUBLE PRECISION, ALLOCATABLE, DIMENSION(:,:,:,:) :: Q_aux\n\n!> Buffer holding the values \\\\( F(q) \\\\)\nDOUBLE PRECISION, ALLOCATABLE, DIMENSION(:,:,:,:) :: FQ\n\nTYPE timestepper_parameter\n INTEGER :: i_max, j_max, k_max\nEND TYPE\n\nTYPE(timestepper_parameter) :: param\n\nCONTAINS\n\n !> Forward Euler method. In every step, it computes \\\\( F_{\\\\text{adv}} \\\\) and \\\\( F_{\\\\text{diff}} \\\\) and performs the update\n !> \\\\( Q_{n+1} = Q_{n} + \\\\Delta t F(Q_n) \\\\).\n !> @param[inout] Q Initial value which is then overwritten with the solution after completing the time stepping\n !> @param[in] T0 Starting time\n !> @param[in] T1 Final time\n !> @param[in] Nsteps Number of time steps to take from T0 to T1\n SUBROUTINE Euler(Q, T0, T1, Nsteps, dx, dy, dz, order_adv, order_diff)\n \n DOUBLE PRECISION, DIMENSION(-2:,-2:,-2:), INTENT(INOUT) :: Q\n DOUBLE PRECISION, INTENT(IN) :: dx, dy, dz, T0, T1\n INTEGER, INTENT(IN) :: Nsteps, order_adv, order_diff\n \n DOUBLE PRECISION :: dt\n INTEGER :: n, thread_nr\n \n thread_nr = omp_get_thread_num();\n dt = (T1-T0)/DBLE(Nsteps)\n \n DO n=1,Nsteps\n\n CALL periodic(Q)\n\n CALL GetRHSAdvection(Q, FQ(:,:,:,thread_nr), dx, dy, dz, 1, param%i_max, 1, param%j_max, 1, param%k_max, order_adv)\n CALL GetRHSDiffusion(Q, FQ(:,:,:,thread_nr), dx, dy, dz, 1, param%i_max, 1, param%j_max, 1, param%k_max, order_diff)\n\n Q = Q + dt*FQ(:,:,:,thread_nr)\n \n END DO\n\n END SUBROUTINE Euler\n \n !> Third order strong stability preserving Runge-Kutta scheme from Shu and Osher (1988),\n !> see e.g. Durran, \"Numerical Methods for Fluid Dynamics\", pp. 55f\n !> @param[inout] Q Initial value which is then overwritten with the solution after completing the time stepping\n !> @param[in] T0 Starting time\n !> @param[in] T1 Final time\n !> @param[in] Nsteps Number of time steps to take from T0 to T1\n SUBROUTINE Rk3Ssp(Q, T0, T1, Nsteps, dx, dy, dz, order_adv, order_diff)\n \n DOUBLE PRECISION, DIMENSION(:,:,:), INTENT(INOUT) :: Q\n DOUBLE PRECISION, INTENT(IN) :: dx, dy, dz, T0, T1\n INTEGER, INTENT(IN) :: Nsteps, order_adv, order_diff\n \n DOUBLE PRECISION :: dt \n INTEGER :: i, thread_nr\n \n thread_nr = omp_get_thread_num();\n dt = (T1-T0)/DBLE(Nsteps)\n \n DO i=1,Nsteps\n\n CALL periodic(Q)\n \n ! Q_1 = Q_n + dt*f(Q_n)\n CALL GetRHSAdvection(Q, FQ(:,:,:,thread_nr), dx, dy, dz, 1, param%i_max, 1, param%j_max, 1, param%k_max, order_adv)\n CALL GetRHSDiffusion(Q, FQ(:,:,:,thread_nr), dx, dy, dz, 1, param%i_max, 1, param%j_max, 1, param%k_max, order_diff)\n Q_aux(:,:,:,thread_nr) = Q + dt*FQ(:,:,:,thread_nr)\n\n CALL periodic(Q_aux(:,:,:,thread_nr))\n ! Q_2 = (3/4)*Q_n + (1/4)*( Q_1 + dt*f(Q_1) )\n CALL GetRHSAdvection(Q_aux(:,:,:,thread_nr), FQ(:,:,:,thread_nr), dx, dy, dz, 1, param%i_max, 1, param%j_max, 1, param%k_max, order_adv)\n CALL GetRHSDiffusion(Q_aux(:,:,:,thread_nr), FQ(:,:,:,thread_nr), dx, dy, dz, 1, param%i_max, 1, param%j_max, 1, param%k_max, order_diff) \n Q_aux(:,:,:,thread_nr) = (3.0/4.0)*Q + (1.0/4.0)*( Q_aux(:,:,:,thread_nr) + dt*FQ(:,:,:,thread_nr) ) \n \n CALL periodic(Q_aux(:,:,:,thread_nr))\n ! Q_n+1 = (1/3)*Q_n + (2/3)*( Q_2 + dt*f(Q_2) )\n CALL GetRHSAdvection(Q_aux(:,:,:,thread_nr), FQ(:,:,:,thread_nr), dx, dy, dz, 1, param%i_max, 1, param%j_max, 1, param%k_max, order_adv)\n CALL GetRHSDiffusion(Q_aux(:,:,:,thread_nr), FQ(:,:,:,thread_nr), dx, dy, dz, 1, param%i_max, 1, param%j_max, 1, param%k_max, order_diff) \n Q = (1.0/3.0)*Q + (2.0/3.0)*( Q_aux(:,:,:,thread_nr) + dt*FQ(:,:,:,thread_nr) ) \n END DO\n \n END SUBROUTINE Rk3Ssp\n\n !> Initialize the time stepper. Also initializes the modules required to compute the right hand side \\\\( F(q) \\\\)\n SUBROUTINE InitializeTimestepper(nu, i_max, j_max, k_max, nthreads)\n \n DOUBLE PRECISION, INTENT(IN) :: nu\n INTEGER, INTENT(IN) :: i_max, j_max, k_max, nthreads\n \n INTEGER :: i\n \n param%i_max = i_max\n param%j_max = j_max\n param%k_max = k_max\n \n ! Use indexing from 1,...,i_max and account for three halo cells in each direction\n CALL InitializeAdvection(-2, i_max+3, -2, j_max+3, -2, k_max+3, nthreads, .false.)\n CALL InitializeDiffusion(-2, i_max+3, -2, j_max+3, -2, k_max+3, nu)\n CALL InitializeBoundaries(i_max, j_max, k_max)\n \n ALLOCATE(Q_aux(-2:i_max+3, -2:j_max+3, -2:k_max+3,0:nthreads-1))\n ALLOCATE(FQ( -2:i_max+3, -2:j_max+3, -2:k_max+3,0:nthreads-1))\n\n !$OMP PARALLEL DO schedule(static)\n DO i=0,nthreads-1\n Q_aux(:,:,:,i) = 0.0\n FQ(:,:,:,i) = 0.0\n END DO\n !$OMP END PARALLEL DO\n \n END SUBROUTINE InitializeTimestepper\n\n !> Finalize the time stepper and all used modules.\n SUBROUTINE FinalizeTimestepper()\n CALL FinalizeAdvection\n CALL FinalizeBoundaries\n DEALLOCATE(Q_aux)\n DEALLOCATE(FQ) \n END SUBROUTINE FinalizeTimestepper\n \nEND MODULE timestepper", "meta": {"hexsha": "795b288186d33e568f4edb85eb73c90913e78f98", "size": 6569, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/timestepper.f90", "max_stars_repo_name": "Parallel-in-Time/PararealF90", "max_stars_repo_head_hexsha": "a8318a79b92465a8a3cf775cc7fd096ff0494529", "max_stars_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2017-03-17T15:04:00.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-10T08:05:52.000Z", "max_issues_repo_path": "src/timestepper.f90", "max_issues_repo_name": "Parallel-in-Time/PararealF90", "max_issues_repo_head_hexsha": "a8318a79b92465a8a3cf775cc7fd096ff0494529", "max_issues_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2015-09-23T09:08:12.000Z", "max_issues_repo_issues_event_max_datetime": "2015-09-23T09:32:24.000Z", "max_forks_repo_path": "src/timestepper.f90", "max_forks_repo_name": "Parallel-in-Time/PararealF90", "max_forks_repo_head_hexsha": "a8318a79b92465a8a3cf775cc7fd096ff0494529", "max_forks_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-10-24T20:15:26.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-10T08:05:36.000Z", "avg_line_length": 43.2171052632, "max_line_length": 182, "alphanum_fraction": 0.5804536459, "num_tokens": 2009, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094032139576, "lm_q2_score": 0.7490872075132153, "lm_q1q2_score": 0.6691666462988404}} {"text": "\n\n\n\n\n\t!--------------------------------------------------------------------\n\t!\n\t!\n\t! PURPOSE\n\t!\n\t! This program solves nonlinear Schrodinger equation in 3 dimensions\n\t! i*u_t+Es*|u|^2u+u_{xx}+u_{yy}+u_{zz}=0\n\t! using a second order time spectral splitting scheme\n\t!\n\t! The boundary conditions are u(x=0,y,z)=u(2*Lx*\\pi,y,z), \n\t!\tu(x,y=0,z)=u(x,y=2*Ly*\\pi,z), u(x,y,z=0)=u(x,y,z=2*Lz*\\pi)\n\t! The initial condition is u=exp(-x^2-y^2)\n\t!\n\t! .. Parameters ..\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! Nz\t\t\t\t= number of modes in z - power of 2 for FFT\n\t! Nt\t\t\t\t= number of timesteps to take\n\t! Tmax\t\t\t\t= maximum simulation time\n\t! plotgap\t\t\t= number of timesteps between plots\n\t! pi = 3.14159265358979323846264338327950288419716939937510d0\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! Lz\t\t\t\t= width of box in z direction\n\t! ES\t\t\t\t= +1 for focusing and -1 for defocusing\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! k\t\t\t\t= loop counter in z direction\n\t! n\t\t\t\t= loop counter for timesteps direction\t\n\t! allocatestatus\t\t= error indicator during allocation\n\t! start\t\t\t= variable to record start time of program\n\t! finish\t\t\t= variable to record end time of program\n\t! count_rate\t\t\t= variable for clock count rate\n\t! dt\t\t\t\t= timestep\n\t! modescalereal\t\t= Number to scale after backward FFT \n\t! myid\t\t\t\t= Process id\n\t! ierr\t\t\t\t= error code\n\t! p_row\t\t\t= number of rows for domain decomposition\n\t! p_col\t\t\t= number of columns for domain decomposition\n\t! filesize\t\t\t= total filesize\n\t! disp\t\t\t\t= displacement to start writing data from\n\t! ind\t\t\t\t= index in array to write\n\t! plotnum\t\t\t= number of plot to save\n\t! numberfile\t\t\t= number of the file to be saved to disk\n\t! stat\t\t\t\t= error indicator when reading inputfile\n\t! .. Arrays ..\n\t! u \t\t\t\t= approximate solution\n\t! v\t\t\t\t= Fourier transform of approximate solution\n\t! pot\t\t\t\t= potential\n\t! uabs\t\t\t\t= Absolute value of the field\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! kz\t\t\t\t= fourier frequencies in z direction\n\t! x\t\t\t\t= x locations\n\t! y\t\t\t\t= y locations\n\t! z\t\t\t\t= z locations\n\t! time\t\t\t\t= times at which save data\n\t! nameconfig\t\t= array to store filename for data to be saved \t\t\n\t! InputFileName\t= name of the Input File\n\t! .. Special Structures ..\n\t! decomp\t\t\t= contains information on domain decomposition\n\t!\t\t\t\t\tsee http://www.2decomp.org/ for more information\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! 2DECOMP&FFT\t -- Domain decomposition and Fast Fourier Library\n\t!\t\t\t(http://www.2decomp.org/index.html)\n\t! MPI library\n\t\t\n\tPROGRAM main\n\tUSE decomp_2d\n\tUSE decomp_2d_fft\n\tUSE decomp_2d_io\n\tUSE MPI\n\t! Declare variables\n\tIMPLICIT NONE\t\t\t\t\t \n\tINTEGER(kind=4)\t\t:: Nx=2**5\n\tINTEGER(kind=4) \t:: Ny=2**5\n\tINTEGER(kind=4) \t:: Nz=2**5\n\tINTEGER(kind=4)\t\t:: Nt=50\t\n\tINTEGER(kind=4)\t\t:: plotgap=10 \n\tREAL(kind=8), PARAMETER\t::&\n\t\tpi=3.14159265358979323846264338327950288419716939937510d0\n\tREAL(kind=8)\t\t:: Lx=2.0d0,Ly=2.0d0,Lz=2.0d0\t \n\tREAL(kind=8)\t\t:: Es=1.0d0\t \n\tREAL(kind=8)\t\t:: dt=0.0010d0\t\t\n\tCOMPLEX(kind=8), DIMENSION(:), ALLOCATABLE\t:: kx,ky,kz\n\tREAL(kind=8), \t DIMENSION(:), ALLOCATABLE\t:: x,y,z \n\tCOMPLEX(kind=8), DIMENSION(:,:,:), ALLOCATABLE\t:: u,v,pot \n\tREAL(kind=8), \t DIMENSION(:,:,:), ALLOCATABLE :: uabs\n\tREAL(kind=8), \t DIMENSION(:), ALLOCATABLE\t:: time\n\tINTEGER(KIND=4), DIMENSION(1:5)\t:: intcomm\n\tREAL(KIND=8), DIMENSION(1:5)\t:: dpcomm\n\tREAL(kind=8) :: modescalereal\n\tINTEGER(kind=4)\t:: i,j,k,n,AllocateStatus,stat\n\tINTEGER(kind=4)\t:: myid,numprocs,ierr\n\tTYPE(DECOMP_INFO)\t:: decomp\n\tINTEGER(kind=MPI_OFFSET_KIND) :: filesize, disp\n\tINTEGER(kind=4)\t:: p_row=0, p_col=0\t\n \tINTEGER(kind=4)\t:: start, finish, count_rate, ind, plotnum\n\tCHARACTER*50\t::\tnameconfig\n\tCHARACTER*20\t::\tnumberfile, InputFileName\n\t ! initialisation of MPI\n\tCALL MPI_INIT(ierr)\n\tCALL MPI_COMM_SIZE(MPI_COMM_WORLD, numprocs, ierr)\n\tCALL MPI_COMM_RANK(MPI_COMM_WORLD, myid, ierr) \n\t\n\tIF(myid.eq.0) THEN\t\n\t\tCALL GET_ENVIRONMENT_VARIABLE(NAME='inputfile',VALUE=InputFileName, STATUS=stat)\n\tEND IF\n\tCALL MPI_BCAST(stat,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)\n\n\tIF(stat.NE.0) THEN\n\t\tIF(myid.eq.0) THEN\n\t\t\t\tPRINT*,\"Need to set environment variable inputfile to the name of the &\n\t\t\t\t\t\tfile where the simulation parameters are set\"\n\t\tEND IF\n\t\tSTOP\n\tEND IF\n\tIF(myid.eq.0) THEN\n\t\tInputFileName='./INPUTFILE'\n\t\tOPEN(unit=11,FILE=trim(InputFileName),status=\"OLD\") \n\t\tREWIND(11)\n\t\tREAD(11,*) intcomm(1), intcomm(2), intcomm(3), intcomm(4), intcomm(5), &\n\t\t\t \t\tdpcomm(1), dpcomm(2), dpcomm(3), dpcomm(4), dpcomm(5)\n\t\tCLOSE(11)\n\t\tPRINT *,\"NX \",intcomm(1)\n\t\tPRINT *,\"NY \",intcomm(2)\n\t\tPRINT *,\"NZ \",intcomm(3)\n\t\tPRINT *,\"NT \",intcomm(4)\n\t\tPRINT *,\"plotgap \",intcomm(5)\n\t\tPRINT *,\"Lx \",dpcomm(1)\n\t\tPRINT *,\"Ly \",dpcomm(2)\n\t\tPRINT *,\"Lz \",dpcomm(3)\n\t\tPRINT *,\"Es \",dpcomm(4)\t\t\n\t\tPRINT *,\"Dt \",dpcomm(5)\n\t\tPRINT *,\"Read inputfile\"\n\tEND IF\n\tCALL MPI_BCAST(dpcomm,5,MPI_DOUBLE_PRECISION,0,MPI_COMM_WORLD,ierr)\n\tCALL MPI_BCAST(intcomm,5,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)\n\n\tNx=intcomm(1)\n\tNy=intcomm(2)\n\tNz=intcomm(3)\n\tNt=intcomm(4)\n\tplotgap=intcomm(5)\n\tLx=dpcomm(1)\n\tLy=dpcomm(2)\n\tLz=dpcomm(3)\n\tEs=dpcomm(4)\n\tDT=dpcomm(5)\n\n\t! initialisation of 2decomp\n\t! do automatic domain decomposition\n\tCALL decomp_2d_init(Nx,Ny,Nz,p_row,p_col)\n\t! get information about domain decomposition choosen\n\tCALL decomp_info_init(Nx,Ny,Nz,decomp)\n\t! initialise FFT library\n\tCALL decomp_2d_fft_init\n\tALLOCATE(u(decomp%xst(1):decomp%xen(1),&\n \t\t\t\tdecomp%xst(2):decomp%xen(2),&\n \t\t\t\tdecomp%xst(3):decomp%xen(3)),&\n v(decomp%zst(1):decomp%zen(1),&\n \tdecomp%zst(2):decomp%zen(2),&\n \tdecomp%zst(3):decomp%zen(3)),&\n pot(decomp%xst(1):decomp%xen(1),&\n \tdecomp%xst(2):decomp%xen(2),&\n \tdecomp%xst(3):decomp%xen(3)),&\n uabs(decomp%xst(1):decomp%xen(1),&\n decomp%xst(2):decomp%xen(2),&\n decomp%xst(3):decomp%xen(3)),&\n \t\tkx(1:Nx),ky(1:Ny),kz(1:Nz),&\n \t\tx(1:Nx),y(1:Ny),z(1:Nz),&\n \t\ttime(1:1+Nt/plotgap),stat=AllocateStatus)\t\n\tIF (AllocateStatus .ne. 0) STOP \n\n\tIF (myid.eq.0) THEN\n\t\tPRINT *,'allocated space'\n\tEND IF\t\n\t\n\tmodescalereal=1.0d0/REAL(Nx,KIND(0d0))\n\tmodescalereal=modescalereal/REAL(Ny,KIND(0d0))\n\tmodescalereal=modescalereal/REAL(Nz,KIND(0d0))\n\t\n\t! setup fourier frequencies and grid points\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\tkx(1+Nx/2)=0.0d0\n\tDO i = 1,Nx/2 -1\n\t\tkx(i+1+Nx/2)=-kx(1-i+Nx/2)\n\tEND DO\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\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\tky(1+Ny/2)=0.0d0\n\tDO j = 1,Ny/2 -1\n\t\tky(j+1+Ny/2)=-ky(1-j+Ny/2)\n\tEND DO\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\tDO k=1,1+Nz/2\n\t\tkz(k)= cmplx(0.0d0,1.0d0)*REAL(k-1,kind(0d0))/Lz \t\t\t\n\tEND DO\n\tkz(1+Nz/2)=0.0d0\n\tDO k = 1,Nz/2 -1\n\t\tkz(k+1+Nz/2)=-kz(1-k+Nz/2)\n\tEND DO\n \tDO k=1,Nz\n\t\tz(k)=(-1.0d0 + 2.0d0*REAL(k-1,kind(0d0))/REAL(Nz,kind(0d0)))*pi*Lz\n\tEND DO\n\n\tIF (myid.eq.0) THEN\n\t\tPRINT *,'Setup grid and fourier frequencies'\n\tEND IF\n\t\n\tDO k=decomp%xst(3),decomp%xen(3)\n\t\tDO j=decomp%xst(2),decomp%xen(2)\n\t\t\tDO i=decomp%xst(1),decomp%xen(1)\n\t\t\t\tu(i,j,k)=exp(-1.0d0*(x(i)**2 +y(j)**2+z(k)**2))\n\t\t\t\tuabs(i,j,k)=abs(u(i,j,k))\n\t\t\tEND DO\n\t\tEND DO\n\tEND DO\n\t\t\n\t! write out using 2DECOMP&FFT MPI-IO routines\n\tnameconfig='./data/u'\n\tplotnum=0\n\tWRITE(numberfile,'(i0)') 10000000+plotnum\n\tind=index(nameconfig,' ') -1\n\tnameconfig=nameconfig(1:ind)//numberfile\n\tind=index(nameconfig,' ') -1\n\tnameconfig=nameconfig(1:ind)//'.datbin'\n\tCALL decomp_2d_write_one(1,uabs,nameconfig)\n \n\tCALL decomp_2d_fft_3d(u,v,DECOMP_2D_FFT_FORWARD)\n\tIF (myid.eq.0) THEN\n\t\tPRINT *,'Got initial data, starting timestepping'\n\tEND IF\n\tCALL system_clock(start,count_rate)\t\n\ttime(1)=0\n\tDO n=1,Nt\n\t\t! Use Strang splitting\n\t\tDO k=decomp%zst(3),decomp%zen(3)\n\t\t\tDO j=decomp%zst(2),decomp%zen(2)\n\t\t\t\tDO i=decomp%zst(1),decomp%zen(1)\n\t\t\t\t\tv(i,j,k)=exp(0.50d0*dt*&\n\t\t\t\t\t\t(kz(k)*kz(k) + kx(i)*kx(i) + ky(j)*ky(j))&\n\t\t\t\t\t\t*cmplx(0.0d0,1.0d0))*v(i,j,k)\n\t\t\t\tEND DO\n\t\t\tEND DO\n\t\tEND DO\n\n\t\tCALL decomp_2d_fft_3d(v,u,DECOMP_2D_FFT_BACKWARD)\n\n\t\tDO k=decomp%xst(3),decomp%xen(3)\n\t\t\tDO j=decomp%xst(2),decomp%xen(2)\n\t\t\t\tDO i=decomp%xst(1),decomp%xen(1)\n\t\t\t\t\tu(i,j,k)=u(i,j,k)*modescalereal\n\t\t\t\t\tpot(i,j,k)=Es*u(i,j,k)*conjg(u(i,j,k))\n\t\t\t\t\tu(i,j,k)=exp(cmplx(0.0d0,-1.0d0)*dt*pot(i,j,k))*u(i,j,k)\n\t\t\t\tEND DO\n\t\t\tEND DO\n\t\tEND DO\t\n\t\tCALL decomp_2d_fft_3d(u,v,DECOMP_2D_FFT_FORWARD)\n\n\t\tDO k=decomp%zst(3),decomp%zen(3)\n\t\t\tDO j=decomp%zst(2),decomp%zen(2)\n\t\t\t\tDO i=decomp%zst(1),decomp%zen(1)\n\t\t\t\t\tv(i,j,k)=exp(dt*0.5d0*&\n\t\t\t\t\t\t(kx(i)*kx(i) +ky(j)*ky(j) +kz(k)*kz(k))&\n\t\t\t\t\t\t*cmplx(0.0d0,1.0d0))*v(i,j,k)\t\t\n\t\t\t\tEND DO\n\t\t\tEND DO\n\t\tEND DO\t\n\t\tIF (mod(n,plotgap)==0) THEN\n\t\t\ttime(1+n/plotgap)=n*dt\n\t\t\tIF (myid.eq.0) THEN\n\t\t\t\tPRINT *,'time',n*dt\n\t\t\tEND IF\n\t\t\tCALL decomp_2d_fft_3d(v,u,DECOMP_2D_FFT_BACKWARD)\n\t\t\tu=u*modescalereal\n \t\tDO k=decomp%xst(3),decomp%xen(3)\n \t\tDO j=decomp%xst(2),decomp%xen(2)\n \t\tDO i=decomp%xst(1),decomp%xen(1)\n \t\tuabs(i,j,k)=abs(u(i,j,k))\n \t\tEND DO\n \t\tEND DO\n \t\tEND DO\n\t\t\tnameconfig='./data/u'\n\t\t\tplotnum=plotnum+1\n\t\t\tWRITE(numberfile,'(i0)') 10000000+plotnum\n\t\t\tind=index(nameconfig,' ') -1\n\t\t\tnameconfig=nameconfig(1:ind)//numberfile\n\t\t\tind=index(nameconfig,' ') -1\n\t\t\tnameconfig=nameconfig(1:ind)//'.datbin'\n\t\t\t! write out using 2DECOMP&FFT MPI-IO routines\n\t\t\tCALL decomp_2d_write_one(1,uabs,nameconfig)\n\t\tEND IF\n\tEND DO\t\t\n\tIF (myid.eq.0) THEN\n\t\tPRINT *,'Finished time stepping'\n\tEND IF\n\n\tCALL system_clock(finish,count_rate)\n\n\tIF (myid.eq.0) THEN\n\t\tPRINT*,'Program took ',REAL(finish-start)/REAL(count_rate),'for execution'\n\tEND IF\t\t\n\t\t\n\tIF (myid.eq.0) THEN\t\n\t\t! Save times at which output was made in text format\n\t\tnameconfig = './data/tdata.dat' \n\t\tOPEN(unit=11,FILE=nameconfig,status=\"UNKNOWN\") \t\n\t\tREWIND(11)\n\t\tDO j=1,1+Nt/plotgap\n\t\t\tWRITE(11,*) time(j)\n\t\tEND DO\n\t\tCLOSE(11)\n\t\t! Save x grid points in text format\n\t\tnameconfig = './data/xcoord.dat' \n\t\tOPEN(unit=11,FILE=nameconfig,status=\"UNKNOWN\") \t\n\t\tREWIND(11)\n\t\tDO i=1,Nx\n\t\t\tWRITE(11,*) x(i)\n\t\tEND DO\n\t\tCLOSE(11)\n\t\t! Save y grid points in text format\n\t\tnameconfig = './data/ycoord.dat' \n\t\tOPEN(unit=11,FILE=nameconfig,status=\"UNKNOWN\") \t\n\t\tREWIND(11)\n\t\tDO j=1,Ny\n\t\t\tWRITE(11,*) y(j)\n\t\tEND DO\n\t\tCLOSE(11)\n\t\t! Save z grid points in text format\t\n\t\tnameconfig = './data/zcoord.dat' \n\t\tOPEN(unit=11,FILE=nameconfig,status=\"UNKNOWN\") \t\n\t\tREWIND(11)\n\t\tDO k=1,Nz\n\t\t\tWRITE(11,*) z(k)\n\t\tEND DO\n\t\tCLOSE(11)\n\t\tPRINT *,'Saved data'\n\tEND IF\n\t\n\t! clean up \n \tCALL decomp_2d_fft_finalize\n \tCALL decomp_2d_finalize\n \tDEALLOCATE(u,v,pot,uabs,&\n \t\tkx,ky,kz,x,y,z,&\n \t\ttime,stat=AllocateStatus)\t\n\tIF (AllocateStatus .ne. 0) STOP \n\tIF (myid.eq.0) THEN\n\t \tPRINT *,'Program execution complete'\n\tEND IF\n\tCALL MPI_FINALIZE(ierr)\t\t\n\tEND PROGRAM main\n", "meta": {"hexsha": "7f3bceb076ac8c47fe8700b7eb2e745d9dbcf0ef", "size": 11453, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "CubicNonlinearSchrodinger/Programs/NLS3dFortranMPI/NLSsplitting.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": "CubicNonlinearSchrodinger/Programs/NLS3dFortranMPI/NLSsplitting.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": "CubicNonlinearSchrodinger/Programs/NLS3dFortranMPI/NLSsplitting.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": 29.9033942559, "max_line_length": 82, "alphanum_fraction": 0.6311883349, "num_tokens": 4546, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.7490872075132152, "lm_q1q2_score": 0.6691666441711396}} {"text": " SUBROUTINE cntab1(nn,ni,nj,chisq,df,prob,cramrv,ccc)\r\n INTEGER ni,nj,nn(ni,nj),MAXI,MAXJ\r\n REAL ccc,chisq,cramrv,df,prob,TINY\r\n PARAMETER (MAXI=100,MAXJ=100,TINY=1.e-30)\r\nCU USES gammq\r\n INTEGER i,j,nni,nnj\r\n REAL expctd,sum,sumi(MAXI),sumj(MAXJ),gammq\r\n sum=0\r\n nni=ni\r\n nnj=nj\r\n do 12 i=1,ni\r\n sumi(i)=0.\r\n do 11 j=1,nj\r\n sumi(i)=sumi(i)+nn(i,j)\r\n sum=sum+nn(i,j)\r\n11 continue\r\n if(sumi(i).eq.0.)nni=nni-1\r\n12 continue\r\n do 14 j=1,nj\r\n sumj(j)=0.\r\n do 13 i=1,ni\r\n sumj(j)=sumj(j)+nn(i,j)\r\n13 continue\r\n if(sumj(j).eq.0.)nnj=nnj-1\r\n14 continue\r\n df=nni*nnj-nni-nnj+1\r\n chisq=0.\r\n do 16 i=1,ni\r\n do 15 j=1,nj\r\n expctd=sumj(j)*sumi(i)/sum\r\n chisq=chisq+(nn(i,j)-expctd)**2/(expctd+TINY)\r\n15 continue\r\n16 continue\r\n prob=gammq(0.5*df,0.5*chisq)\r\n cramrv=sqrt(chisq/(sum*min(nni-1,nnj-1)))\r\n ccc=sqrt(chisq/(chisq+sum))\r\n return\r\n END\r\n", "meta": {"hexsha": "593ca8e873dc200b875494a08cf7b0bb62800158", "size": 1050, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/cntab1.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/cntab1.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/cntab1.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": 26.9230769231, "max_line_length": 59, "alphanum_fraction": 0.5152380952, "num_tokens": 429, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391558355999, "lm_q2_score": 0.7248702761768248, "lm_q1q2_score": 0.6690836478125745}} {"text": " MODULE FACTORSTUFF\t!This protocol evades the need for multiple parameters, or COMMON, or one shapeless main line...\nConcocted by R.N.McLean, MMXV.\n INTEGER LOTS\t\t!The span..\n PARAMETER (LOTS = 20000)!Nor is computer storage infinite.\n INTEGER KNOWNSUM(LOTS)\t!Calculate these once.\n CONTAINS\t\t!Assistants.\n SUBROUTINE PREPARESUMF\t!Initialise the KNOWNSUM array.\nConvert the Sieve of Eratoshenes to have each slot contain the sum of the proper divisors of its slot number.\nChanges to instead count the number of factors, or prime factors, etc. would be simple enough.\n INTEGER F\t\t!A factor for numbers such as 2F, 3F, 4F, 5F, ...\n KNOWNSUM(1) = 0\t\t!Proper divisors of N do not include N.\n KNOWNSUM(2:LOTS) = 1\t\t!So, although 1 divides all N without remainder, 1 is excluded for itself.\n DO F = 2,LOTS/2\t\t!Step through all the possible divisors of numbers not exceeding LOTS.\n FORALL(I = F + F:LOTS:F) KNOWNSUM(I) = KNOWNSUM(I) + F\t!And augment each corresponding slot.\n END DO\t\t\t!Different divisors can hit the same slot. For instance, 6 by 2 and also by 3.\n END SUBROUTINE PREPARESUMF\t!Could alternatively generate all products of prime numbers.\n PURE INTEGER FUNCTION SIGN3(N)\t!Returns -1, 0, +1 according to the sign of N.\nConfounded by the intrinsic function SIGN distinguishing only two states: < 0 from >= 0. NOT three-way.\n INTEGER, INTENT(IN):: N\t!The number.\n IF (N) 1,2,3\t!A three-way result calls for a three-way test.\n 1 SIGN3 = -1\t!Negative.\n RETURN\n 2 SIGN3 = 0\t!Zero.\n RETURN\n 3 SIGN3 = +1\t!Positive.\n END FUNCTION SIGN3\t!Rather basic.\n END MODULE FACTORSTUFF\t!Enough assistants.\n PROGRAM THREEWAYS\t!Classify N against the sum of proper divisors of N, for N up to 20,000.\n USE FACTORSTUFF\t\t!This should help.\n INTEGER I\t\t!Stepper.\n INTEGER TEST(LOTS)\t!Assesses the three states in one pass.\n WRITE (6,*) \"Inspecting sums of proper divisors for 1 to\",LOTS\n CALL PREPARESUMF\t\t!Values for every N up to the search limit will be called for at least once.\n FORALL(I = 1:LOTS) TEST(I) = SIGN3(KNOWNSUM(I) - I)\t!How does KnownSum(i) compare to i?\n WRITE (6,*) \"Deficient\",COUNT(TEST .LT. 0)\t!This means one pass through the array\n WRITE (6,*) \"Perfect! \",COUNT(TEST .EQ. 0)\t!For each of three types.\n WRITE (6,*) \"Abundant \",COUNT(TEST .GT. 0)\t!Alternatively, make one pass with three counts.\n END\t\t\t!Done.\n", "meta": {"hexsha": "d101b646f2f3d40764947ab3c9e16734095f97e5", "size": 2559, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Abundant,-deficient-and-perfect-number-classifications/Fortran/abundant,-deficient-and-perfect-number-classifications.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/Abundant,-deficient-and-perfect-number-classifications/Fortran/abundant,-deficient-and-perfect-number-classifications.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/Abundant,-deficient-and-perfect-number-classifications/Fortran/abundant,-deficient-and-perfect-number-classifications.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": 65.6153846154, "max_line_length": 121, "alphanum_fraction": 0.6631496678, "num_tokens": 751, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681158979306, "lm_q2_score": 0.7799929002541067, "lm_q1q2_score": 0.6690530404647276}} {"text": "program problem_9\n\n!! What is the first number that does not have this property?\n\nuse aoc_utilities, only: read_file_to_integer64_array\nuse iso_fortran_env\n\nimplicit none\n\ninteger(int64),dimension(:),allocatable :: iarray\ninteger :: i, j, k, n\nlogical :: ok\ninteger(int64) :: invalid_value, smallest, largest, weakness\n\niarray = read_file_to_integer64_array('input.txt')\nn = size(iarray)\n\nmain: do i = 26, n\n write(*,*) 'try: ', i\n ok = .false.\n loop: do j = 1, n-2\n do k = j+1, n-1\n if (iarray(i) == iarray(j) + iarray(k)) then\n ok = .true.\n exit loop\n end if\n end do\n end do loop\n if (.not. ok) then\n invalid_value = iarray(i)\n write(*,*) 'found: entry ', i, ' value = ', invalid_value\n exit main\n end if\n\nend do main\n\n! What is the encryption weakness in your XMAS-encrypted list of numbers?\n\nwrite(*,*) ''\nwrite(*,*) 'Part 2'\nwrite(*,*) ''\n\ndo i = 1, n-1\n do j = 1, n\n if (sum(iarray(i:j)) == invalid_value) then\n write(*,*) 'found sequence: ', iarray(i:j)\n smallest = minval(iarray(i:j))\n largest = maxval(iarray(i:j))\n weakness = smallest + largest\n write(*,*) 'weakness: ', weakness\n stop\n end if\n end do\nend do\n\n\nend program problem_9", "meta": {"hexsha": "40f0bd2e5c85bb24a3c5093bb14d47fad3da5199", "size": 1334, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/day9/problem_9.f90", "max_stars_repo_name": "jacobwilliams/AoC-2020", "max_stars_repo_head_hexsha": "2adf673a0ac62710fc5461576feb95bf5fae4cf2", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/day9/problem_9.f90", "max_issues_repo_name": "jacobwilliams/AoC-2020", "max_issues_repo_head_hexsha": "2adf673a0ac62710fc5461576feb95bf5fae4cf2", "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/day9/problem_9.f90", "max_forks_repo_name": "jacobwilliams/AoC-2020", "max_forks_repo_head_hexsha": "2adf673a0ac62710fc5461576feb95bf5fae4cf2", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.4035087719, "max_line_length": 73, "alphanum_fraction": 0.5704647676, "num_tokens": 387, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6690530319567002}} {"text": "module test_math\n\n use testdrive, only: new_unittest, unittest_type, error_type, check\n use forlab_math, only: operator(.c.), all_close, angle, is_close\n use, intrinsic :: iso_fortran_env, only: int8\n implicit none\n private\n \n public :: collect_math\n \ncontains\n\n subroutine collect_math(testsuite)\n type(unittest_type), allocatable, intent(out) :: testsuite(:)\n testsuite = [&\n new_unittest(\"angle_real vaild\", test_math_angle_real), &\n new_unittest(\"cross_int vaild\", test_math_cross_int), &\n new_unittest(\"cross_real vaild\", test_math_cross_real) &\n ]\n end subroutine collect_math\n \n subroutine test_math_cross_int(error)\n type(error_type), allocatable, intent(out) :: error\n integer(int8), dimension(3) :: x, y\n x = 1_int8; y = 2_int8\n \n call check(error, all((x.c.y) == [integer(int8) :: 0, 0, 0]))\n if (allocated(error)) return\n \n end subroutine test_math_cross_int\n \n subroutine test_math_cross_real(error)\n type(error_type), allocatable, intent(out) :: error\n real, dimension(3) :: x, y\n x = 1_int8; y = 2_int8\n \n call check(error, all_close((x.c.y), [real :: 0, 0, 0]))\n if (allocated(error)) return\n \n end subroutine test_math_cross_real\n \n module subroutine test_math_angle_real(error)\n type(error_type), allocatable, intent(out) :: error\n real, dimension(3) :: x, y\n x = 1_int8; y = 2_int8\n \n call check(error, is_close(angle(x, y), 0.0))\n if (allocated(error)) return\n \n end subroutine test_math_angle_real\n \nend module test_math", "meta": {"hexsha": "208262ee5af8b45eb17f1d172688c2f04e95e5de", "size": 1693, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/test_math.f90", "max_stars_repo_name": "zoziha/forlab_z", "max_stars_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2021-08-31T15:23:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T02:44:46.000Z", "max_issues_repo_path": "test/test_math.f90", "max_issues_repo_name": "zoziha/forlab_z", "max_issues_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-08-22T11:47:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-31T00:57:16.000Z", "max_forks_repo_path": "test/test_math.f90", "max_forks_repo_name": "zoziha/forlab_z", "max_forks_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-07-16T03:16:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-31T13:09:42.000Z", "avg_line_length": 32.5576923077, "max_line_length": 71, "alphanum_fraction": 0.6225634968, "num_tokens": 435, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182186, "lm_q2_score": 0.7799928900257126, "lm_q1q2_score": 0.6690530175110911}} {"text": "! MIT License\n!\n! Copyright (c) 2020 SHEMAT-Suite\n!\n! Permission is hereby granted, free of charge, to any person obtaining a copy\n! of this software and associated documentation files (the \"Software\"), to deal\n! in the Software without restriction, including without limitation the rights\n! to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n! copies of the Software, and to permit persons to whom the Software is\n! furnished to do so, subject to the following conditions:\n!\n! The above copyright notice and this permission notice shall be included in all\n! copies or substantial portions of the Software.\n!\n! THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n! SOFTWARE.\n\n!> @brief compute \"i,j,k\"-index of \"m\", depending on \"i0,j0,k0\"\n!> @param[in] m continuous memory cell-index\n!> @param[out] i cell index, direction I0\n!> @param[out] j cell index, direction J0\n!> @param[out] k cell index, direction K0\n!> @details\n!> Compute k cell index: \\n\\n\n!>\n!> k = (m-1) / (i0*j0) + 1 \\n\\n\n!>\n!> Explanations:\\n\n!> 1) m-1: The integer steps between k-indices are at elements m =\n!> n*(i0*j0 + 1) for some positive integer n [f.e.: m=i0*j0 is\n!> still in the lowest layer, m=i0*j0+1 is in the second lowest\n!> layer]. The steps of the division are at m_div = n*(i0*j0). \\n\n!> 2) +1 at end: The division gives k = 0 for the lowest layer, k = 1\n!> for the second-lowest, and so on. The layer-counting starts at\n!> k=1, so 1 is added. \\n\\n\n!>\n!> Compute j cell index: \\n\\n\n!>\n!> j = (m-1 - (k-1)*i0*j0) / i0 + 1 \\n\\n\n!>\n!> Explanations:\\n\n!> 1) (m-1 - (k-1)*i0*j0): The index is projected onto its\n!> partner-index on the lowest layer by subtracting the number of\n!> z-layers on top, then one is subtracted, since the steps between\n!> j-indices should be at m=n*(i0+1), but the steps of the division\n!> by i0 are at m=n*i0. \\n\n!> 2) +1 at end: The division by i0 gives j = 0 for the first line in\n!> x-direction, j = 1 for the second, and so on. The line-counting\n!> should start at j=1, so 1 is added. \\n\\n\n!>\n!> Compute i cell index: \\n\\n\n!>\n!> i = m - (k-1)*i0*j0 - (j-1)*i0\\n\\n\n!>\n!> Explanations:\\n\n!> 1) (m - (k-1)*i0*j0): The index is projected onto its\n!> partner-index on the lowest layer by subtracting the number of\n!> z-layers on top. \\n\n!> 2) - (j-1)*i0: The index is projected onto its\n!> partner-index on the first line by subtracting the number of\n!> y-lines . \\n\\n\n subroutine ijk_m(m,i,j,k)\n\n use mod_genrl, only: i0, j0, k0\n\n implicit none\n\n ! Continuous linear index\n integer, intent (in) :: m\n\n ! i-cell/j-cell/k-cell index\n integer, intent (out) :: i, j, k\n\n\n ! Compute k-cell index\n k = (m-1) / (i0*j0) + 1\n\n ! Compute j-cell index\n j = (m-1 - (k-1)*i0*j0) / i0 + 1\n\n ! Compute i-cell index\n i = m - (k-1)*i0*j0 - (j-1)*i0\n\n return\n\n end subroutine ijk_m\n", "meta": {"hexsha": "05a0ee3f8f2e8cc4af3e512a1b6e0dbd591e5f59", "size": 3359, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "forward/ctrlut/ijk_m.f90", "max_stars_repo_name": "ElsevierSoftwareX/SOFTX_2020_135", "max_stars_repo_head_hexsha": "2e0be239bc7fec4dc5b5c68710806de777610dbb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-21T09:07:31.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-21T09:07:31.000Z", "max_issues_repo_path": "forward/ctrlut/ijk_m.f90", "max_issues_repo_name": "ElsevierSoftwareX/SOFTX_2020_135", "max_issues_repo_head_hexsha": "2e0be239bc7fec4dc5b5c68710806de777610dbb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "forward/ctrlut/ijk_m.f90", "max_forks_repo_name": "ElsevierSoftwareX/SOFTX_2020_135", "max_forks_repo_head_hexsha": "2e0be239bc7fec4dc5b5c68710806de777610dbb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-12-18T00:34:07.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-14T08:32:51.000Z", "avg_line_length": 36.5108695652, "max_line_length": 80, "alphanum_fraction": 0.65019351, "num_tokens": 1078, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528132451417, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.6690458504721174}} {"text": "!\n! ej1c.f90\n!\n! Copyright 2016 Bruno S \n!\n! This program is free software; you can redistribute it and/or modify\n! it under the terms of the GNU General Public License as published by\n! the Free Software Foundation; either version 2 of the License, or\n! (at your option) any later version.\n!\n! This program is distributed in the hope that it will be useful,\n! but WITHOUT ANY WARRANTY; without even the implied warranty of\n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n! GNU General Public License for more details.\n!\nprogram ej1c\n\nuse precision, pr => dp\nuse mtmod\nuse ising\n\nimplicit none\ninteger :: i, j, k\ninteger, dimension(:), allocatable :: s\ninteger :: tmc, n_down, n_up, n_left, n_right\ninteger :: spinadd, loc, L, ntermal=10e4, nmtc=10e6\nreal(pr) :: e, m, d_e, r, T, Rp\nreal(pr) :: prob(-4:4, -1:1)\n! histogram\ninteger, parameter :: nbins=16\ninteger :: counts(1:nbins)\nreal(pr) :: bins(0:nbins), lo_lim, hi_lim, delta\n\n\n36 format(I12, ES14.6e2)\n\nT = 1.05\n\n! posibles deltas de energia\ncall probability(prob, T)\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nL = 10\nallocate(s(0:(L*L)-1))\n\nopen(unit=10, file='ej1c_L10_T_hi.dat', status='unknown')\nwrite(10, *) \"#counts center\"\n\n! Inicializo la red de spines.\n! 1 = up\n! -1 = down\nprint*, 'Iniciando spins up'\ncall spin_initialize(s, L)\n! energia del estado fundamental, en unidades de J\ne = -2._pr * real(L*L, pr)\n!inicio histograma\nlo_lim = -1.1\nhi_lim = 1.1\ncall histo_init(bins, counts, nbins, lo_lim, hi_lim, delta)\n! pasos de montecarlo\ndo tmc =1, nmtc\n ! recorro la red\n do k = 0, (L*L) -1\n call metropolis_pbc(k, L, s, e, prob)\n end do\n if (tmc > ntermal) then ! descarto transitorio\n m = sum(s)/real(L*L, pr)\n call histogram(bins, m, counts, nbins, delta)\n end if\nend do\n! Inicializo la red de spines.\n! 1 = up\n! -1 = down\nprint*, 'Iniciando spins down'\ncall spin_initialize(s, L)\ns = -1*s\n! energia del estado fundamental, en unidades de J\ne = -2._pr * real(L*L, pr)\n! pasos de montecarlo\ndo tmc =1, nmtc\n ! recorro la red\n do k = 0, (L*L) -1\n call metropolis_pbc(k, L, s, e, prob)\n end do\n if (tmc > ntermal) then ! descarto transitorio\n m = sum(s)/real(L*L, pr)\n call histogram(bins, m, counts, nbins, delta)\n end if\nend do\n\ndo j = 1, nbins\n write(10, 36) counts(j), lo_lim + (j-0.5)*(delta)\nend do\n\nclose(10)\ndeallocate(s)\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nL = 20\nallocate(s(0:(L*L)-1))\n\nopen(unit=10, file='ej1c_L20_T_hi.dat', status='unknown')\nwrite(10, *) \"#counts center\"\n\n! Inicializo la red de spines.\n! 1 = up\n! -1 = down\nprint*, 'Iniciando spins up'\ncall spin_initialize(s, L)\n! energia del estado fundamental, en unidades de J\ne = -2._pr * real(L*L, pr)\n!inicio histograma\nlo_lim = -1.1\nhi_lim = 1.1\ncall histo_init(bins, counts, nbins, lo_lim, hi_lim, delta)\n! pasos de montecarlo\ndo tmc =1, nmtc\n ! recorro la red\n do k = 0, (L*L) -1\n call metropolis_pbc(k, L, s, e, prob)\n end do\n if (tmc > ntermal) then ! descarto transitorio\n m = sum(s)/real(L*L, pr)\n call histogram(bins, m, counts, nbins, delta)\n end if\nend do\n! Inicializo la red de spines.\n! 1 = up\n! -1 = down\nprint*, 'Iniciando spins down'\ncall spin_initialize(s, L)\ns = -1*s\n! energia del estado fundamental, en unidades de J\ne = -2._pr * real(L*L, pr)\n! pasos de montecarlo\ndo tmc =1, nmtc\n ! recorro la red\n do k = 0, (L*L) -1\n call metropolis_pbc(k, L, s, e, prob)\n end do\n if (tmc > ntermal) then ! descarto transitorio\n m = sum(s)/real(L*L, pr)\n call histogram(bins, m, counts, nbins, delta)\n end if\nend do\n\ndo j = 1, nbins\n write(10, 36) counts(j), lo_lim + (j-0.5)*(delta)\nend do\n\nclose(10)\ndeallocate(s)\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nL = 40\nallocate(s(0:(L*L)-1))\n\nopen(unit=10, file='ej1c_L40_T_hi.dat', status='unknown')\nwrite(10, *) \"#counts center\"\n\n! Inicializo la red de spines.\n! 1 = up\n! -1 = down\nprint*, 'Iniciando spins up'\ncall spin_initialize(s, L)\n! energia del estado fundamental, en unidades de J\ne = -2._pr * real(L*L, pr)\n!inicio histograma\nlo_lim = -1.1\nhi_lim = 1.1\ncall histo_init(bins, counts, nbins, lo_lim, hi_lim, delta)\n! pasos de montecarlo\ndo tmc =1, nmtc\n ! recorro la red\n do k = 0, (L*L) -1\n call metropolis_pbc(k, L, s, e, prob)\n end do\n if (tmc > ntermal) then ! descarto transitorio\n m = sum(s)/real(L*L, pr)\n call histogram(bins, m, counts, nbins, delta)\n end if\nend do\n! Inicializo la red de spines.\n! 1 = up\n! -1 = down\nprint*, 'Iniciando spins down'\ncall spin_initialize(s, L)\ns = -1*s\n! energia del estado fundamental, en unidades de J\ne = -2._pr * real(L*L, pr)\n! pasos de montecarlo\ndo tmc =1, nmtc\n ! recorro la red\n do k = 0, (L*L) -1\n call metropolis_pbc(k, L, s, e, prob)\n end do\n if (tmc > ntermal) then ! descarto transitorio\n m = sum(s)/real(L*L, pr)\n call histogram(bins, m, counts, nbins, delta)\n end if\nend do\n\ndo j = 1, nbins\n write(10, 36) counts(j), lo_lim + (j-0.5)*(delta)\nend do\n\nclose(10)\ndeallocate(s)\n\nend program\n", "meta": {"hexsha": "65a1bef605b800433bd165f338d0e7c12c5dacf6", "size": 5432, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lab4/ej1c.f90", "max_stars_repo_name": "BrunoSanchez/fisicaComp", "max_stars_repo_head_hexsha": "be5f61675fee6e370b6d3f5a7eb254fd112c61b0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lab4/ej1c.f90", "max_issues_repo_name": "BrunoSanchez/fisicaComp", "max_issues_repo_head_hexsha": "be5f61675fee6e370b6d3f5a7eb254fd112c61b0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lab4/ej1c.f90", "max_forks_repo_name": "BrunoSanchez/fisicaComp", "max_forks_repo_head_hexsha": "be5f61675fee6e370b6d3f5a7eb254fd112c61b0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.7440758294, "max_line_length": 79, "alphanum_fraction": 0.5918630339, "num_tokens": 1816, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528019683106, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.669045850177841}} {"text": " SUBROUTINE chder(a,b,c,cder,n)\r\n INTEGER n\r\n REAL a,b,c(n),cder(n)\r\n INTEGER j\r\n REAL con\r\n cder(n)=0.\r\n cder(n-1)=2*(n-1)*c(n)\r\n do 11 j=n-2,1,-1\r\n cder(j)=cder(j+2)+2*j*c(j+1)\r\n11 continue\r\n con=2./(b-a)\r\n do 12 j=1,n\r\n cder(j)=cder(j)*con\r\n12 continue\r\n return\r\n END\r\n", "meta": {"hexsha": "a160defc2fea75e850f78ecc6f8a493d6b057a44", "size": 352, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/chder.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/chder.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/chder.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.7058823529, "max_line_length": 37, "alphanum_fraction": 0.4431818182, "num_tokens": 132, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528019683105, "lm_q2_score": 0.7853085708384736, "lm_q1q2_score": 0.669045837335567}} {"text": " double complex function C0fa2m(t,qsq,msq)\nC C0(Pc,Pg,0,msq,msq)=\nC C0(tsq,0,qsq,0,msq,msq) (LT notation) \nC result for qsq<0,t<0 is \nC C0fa2m(t,qsq,msq)=(Li2(qsq/msq)-Li2(t/msq))/(t-qsq)\n\n implicit none \n include 'constants.f'\n double precision t,qsq,msq,r,omr,ddilog\n double complex lnrat,wlog,dilogt,dilogq\n\n r=1d0-qsq/msq\n omr=qsq/msq\n wlog=lnrat(msq-qsq,msq)\n if (omr .gt. one) then \n dilogq=dcmplx(pisqo6-ddilog(r))-wlog*dcmplx(log(omr))\n else\n dilogq=dcmplx(ddilog(omr))\n endif\n\n r=1d0-t/msq\n omr=t/msq\n wlog=lnrat(msq-t,msq)\n if (omr .gt. one) then \n dilogt=dcmplx(pisqo6-ddilog(r))-wlog*dcmplx(log(omr))\n else\n dilogt=dcmplx(ddilog(omr))\n endif\n C0fa2m=(dilogq-dilogt)/(t-qsq)\n return\n end\n", "meta": {"hexsha": "29516a4dfe3d310e0119cf34354607ea64e4dee1", "size": 847, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "MCFM-JHUGen/src/Wt/C0fa2m.f", "max_stars_repo_name": "tmartini/JHUGen", "max_stars_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-06-08T13:09:28.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-04T19:59:36.000Z", "max_issues_repo_path": "MCFM-JHUGen/src/Wt/C0fa2m.f", "max_issues_repo_name": "tmartini/JHUGen", "max_issues_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 64, "max_issues_repo_issues_event_min_datetime": "2015-06-24T15:08:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-25T04:59:32.000Z", "max_forks_repo_path": "MCFM-JHUGen/src/Wt/C0fa2m.f", "max_forks_repo_name": "tmartini/JHUGen", "max_forks_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2015-05-04T22:15:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-06T10:04:40.000Z", "avg_line_length": 26.46875, "max_line_length": 62, "alphanum_fraction": 0.5796930342, "num_tokens": 353, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.965899577232538, "lm_q2_score": 0.6926419767901475, "lm_q1q2_score": 0.6690225925551129}} {"text": "program test\n real(8) a\n write(*,*) tiny(a), huge(a), sqrt(2.0d0)\nend program test\n", "meta": {"hexsha": "92bc5489bd4023a82ffcaa2383babac568c4db0d", "size": 85, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test.f90", "max_stars_repo_name": "sdm900/fortran_parser", "max_stars_repo_head_hexsha": "d079d5046d4300c9c95734553543d941b949f7eb", "max_stars_repo_licenses": ["MIT"], "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.f90", "max_issues_repo_name": "sdm900/fortran_parser", "max_issues_repo_head_hexsha": "d079d5046d4300c9c95734553543d941b949f7eb", "max_issues_repo_licenses": ["MIT"], "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.f90", "max_forks_repo_name": "sdm900/fortran_parser", "max_forks_repo_head_hexsha": "d079d5046d4300c9c95734553543d941b949f7eb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.0, "max_line_length": 42, "alphanum_fraction": 0.6352941176, "num_tokens": 33, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835371034369, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.6689649860415605}} {"text": "C NCLFORTSTART\n subroutine patcor1 (mlon,nlat,ntim,x,y,xmsg,ymsg,w, r, ier)\n\nc compute the anomaly correlation: 1-dimensional weight array \n\nc nomenclature:\nc INPUT \nc . mlon, nlat - dimension sizes\nc . x,y - arrays/grids \nc . xmsg,ymsg - missing codes [if none set to some value]\nc . w - contains weights specified by user [eg: gaussian wgts]\nc OUTPUT \nc . r - anomaly (pattern) correlation\nc . ier - error code\nc . =0 no errors\nc . =1 x or y contains all msg values\nc . =2 x or y contains all constant values\nc\n implicit none\nc ! INPUT\n integer mlon, nlat, ntim, ier\n double precision x(mlon,nlat,ntim), y(mlon,nlat,ntim)\n $ , w(nlat), xmsg, ymsg\nc ! OUTPUT\n double precision r(ntim)\nC NCLEND\nc ! LOCAL\n integer ml, nl, nt\n double precision xave , yave , wsum\n double precision xycov, xanom2, yanom2\n\n ier = 0\n\n do nt=1,ntim\n\nc wgted area mean\n\n xave = 0.0d0\n yave = 0.0d0\n wsum = 0.0d0\n do nl=1,nlat\n do ml=1,mlon\n if (x(ml,nl,nt).ne.xmsg .and. y(ml,nl,nt).ne.ymsg) then \n xave = xave + w(nl)*x(ml,nl,nt)\n yave = yave + w(nl)*y(ml,nl,nt)\n wsum = wsum + w(nl)\n end if\n end do\n end do\n \nc all missing?\n \n if (wsum.eq.0.0d0) then\n ier = 1\n r = xmsg\n return\n end if\n \n xave = xave/wsum\n yave = yave/wsum\n \nc covariance and anomalies\n \n xycov = 0.0d0\n xanom2 = 0.0d0\n yanom2 = 0.0d0\n \n do nl=1,nlat\n do ml=1,mlon\n if (x(ml,nl,nt).ne.xmsg .and. y(ml,nl,nt).ne.ymsg) then \n xycov = xycov + w(nl)*(x(ml,nl,nt)-xave)\n & *(y(ml,nl,nt)-yave)\n xanom2 = xanom2 + w(nl)*(x(ml,nl,nt)-xave)**2\n yanom2 = yanom2 + w(nl)*(y(ml,nl,nt)-yave)**2\n end if\n end do\n end do\n \n if (xanom2.gt.0.0d0 .and. yanom2.gt.0.0d0) then\n r(nt) = xycov/(sqrt(xanom2)*sqrt(yanom2))\n else\n ier = 2\n r(nt) = xmsg\n end if\n\n end do\n\n return\n end\nc ======================================================\nC NCLFORTSTART\n subroutine patcor2 (mlon,nlat,ntim,x,y,xmsg,ymsg,w, r, ier)\n\nc compute the anomaly correlation: 2-dimensional weight array \n\nc nomenclature:\nc INPUT \nc . mlon, nlat - dimension sizes\nc . x,y - arrays/grids \nc . xmsg,ymsg - missing codes [if none set to some value]\nc . w - contains weights specified by user [eg: POP area]\nc OUTPUT \nc . r - anomaly (pattern) correlation\nc . ier - error code\nc . =0 no errors\nc . =1 x or y contains all msg values\nc . =2 x or y contains all constant values\nc\n implicit none\nc ! INPUT\n integer mlon, nlat, ntim, ier\n double precision x(mlon,nlat,ntim), y(mlon,nlat,ntim),w(mlon,nlat)\n $ , xmsg, ymsg\nc ! OUTPUT\n double precision r\nC NCLEND\nc ! LOCAL\n integer ml, nl, nt\n double precision xave , yave , wsum\n double precision xycov, xanom2, yanom2\n\n ier = 0\n\n do nt=1,ntim\n\nc wgted area mean\n\n xave = 0.0d0\n yave = 0.0d0\n wsum = 0.0d0\n do nl=1,nlat\n do ml=1,mlon\n if (x(ml,nl,nt).ne.xmsg .and. y(ml,nl,nt).ne.ymsg) then \n xave = xave + w(ml,nl)*x(ml,nl,nt)\n yave = yave + w(ml,nl)*y(ml,nl,nt)\n wsum = wsum + w(ml,nl)\n end if\n end do\n end do\n\nc all missing?\n\n if (wsum.eq.0.0d0) then\n ier = 1\n r = xmsg\n return\n end if\n \n xave = xave/wsum\n yave = yave/wsum\n\nc covariance and anomalies\n\n xycov = 0.0d0\n xanom2 = 0.0d0\n yanom2 = 0.0d0\n \n do nl=1,nlat\n do ml=1,mlon\n if (x(ml,nl,nt).ne.xmsg .and. y(ml,nl,nt).ne.ymsg) then \n xycov = xycov +w(ml,nl)*(x(ml,nl,nt)-xave)\n $ *(y(ml,nl,nt)-yave)\n xanom2 = xanom2 +w(ml,nl)*(x(ml,nl,nt)-xave)**2\n yanom2 = yanom2 +w(ml,nl)*(y(ml,nl,nt)-yave)**2\n end if\n end do\n end do\n\n if (xanom2.gt.0.0d0 .and. yanom2.gt.0.0d0) then\n r = xycov/(sqrt(xanom2)*sqrt(yanom2))\n else\n ier = 2\n r = xmsg\n end if\n\n end do\n\n return\n end\n", "meta": {"hexsha": "5e21458f7d9ce79940c011c4ddeed2bfe8f52278", "size": 5086, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ni/src/lib/nfpfort/patternCor3.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "ni/src/lib/nfpfort/patternCor3.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "ni/src/lib/nfpfort/patternCor3.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 28.2555555556, "max_line_length": 75, "alphanum_fraction": 0.4388517499, "num_tokens": 1599, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797172476385, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6689148282472633}} {"text": "module mydefs\n\n! integer, parameter :: rk = selected_real_kind(15,307)\n integer, parameter :: sp =kind(1.0)\n integer, parameter :: dp = selected_real_kind(2*precision(1.0_sp))\n integer, parameter :: rk =selected_real_kind(2*precision(1.0_dp))\n integer, parameter :: ik = selected_int_kind(5)\n integer, parameter :: iw1=15, iw2=16, iw3=17, iw4=18\n real(rk), parameter :: pi = 3.141592653589793238462643383279502884197_rk\n! integer, parameter :: maxatoms=3, maxmodes=3, step=50\n real(rk), parameter :: autoaa = 0.52917721092_rk!, ssize = 0.05000_rk\n \n\nend module mydefs\n", "meta": {"hexsha": "71753df40dc2a8ba4ee166acb83bddcd94998b46", "size": 598, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mydefs.f90", "max_stars_repo_name": "esertan/generate_pes", "max_stars_repo_head_hexsha": "5c9a4e68ff711dff7fe120cf813bc88882f6e60e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-09-07T01:31:57.000Z", "max_stars_repo_stars_event_max_datetime": "2015-09-07T01:31:57.000Z", "max_issues_repo_path": "mydefs.f90", "max_issues_repo_name": "esertan/generate_pes", "max_issues_repo_head_hexsha": "5c9a4e68ff711dff7fe120cf813bc88882f6e60e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "mydefs.f90", "max_forks_repo_name": "esertan/generate_pes", "max_forks_repo_head_hexsha": "5c9a4e68ff711dff7fe120cf813bc88882f6e60e", "max_forks_repo_licenses": ["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.8666666667, "max_line_length": 76, "alphanum_fraction": 0.6956521739, "num_tokens": 194, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797124237605, "lm_q2_score": 0.734119526900183, "lm_q1q2_score": 0.6689148194055758}} {"text": "C$Procedure CGV2EL ( Center and generating vectors to ellipse )\n \n SUBROUTINE CGV2EL ( CENTER, VEC1, VEC2, ELLIPS )\n \nC$ Abstract\nC\nC Form a SPICELIB ellipse from a center vector and two generating\nC vectors.\nC\nC$ Disclaimer\nC\nC THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE\nC CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.\nC GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE\nC ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE\nC PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED \"AS-IS\"\nC TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY\nC WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A\nC PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC\nC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE\nC SOFTWARE AND RELATED MATERIALS, HOWEVER USED.\nC\nC IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA\nC BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT\nC LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,\nC INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,\nC REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE\nC REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.\nC\nC RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF\nC THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY\nC CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE\nC ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.\nC\nC$ Required_Reading\nC\nC ELLIPSES\nC\nC$ Keywords\nC\nC ELLIPSE\nC GEOMETRY\nC\nC$ Declarations\n \n INTEGER UBEL\n PARAMETER ( UBEL = 9 )\n \n DOUBLE PRECISION CENTER ( 3 )\n DOUBLE PRECISION VEC1 ( 3 )\n DOUBLE PRECISION VEC2 ( 3 )\n DOUBLE PRECISION ELLIPS ( UBEL )\n \nC$ Brief_I/O\nC\nC Variable I/O Description\nC -------- --- --------------------------------------------------\nC CENTER,\nC VEC1,\nC VEC2 I Center and two generating vectors for an ellipse.\nC ELLIPS O The SPICELIB ellipse defined by the input vectors.\nC\nC$ Detailed_Input\nC\nC CENTER,\nC VEC1,\nC VEC2 are a center and two generating vectors defining\nC an ellipse in three-dimensional space. The\nC ellipse is the set of points\nC\nC CENTER + cos(theta) VEC1 + sin(theta) VEC2\nC\nC where theta ranges over the interval (-pi, pi].\nC VEC1 and VEC2 need not be linearly independent.\nC\nC$ Detailed_Output\nC\nC ELLIPS is the SPICELIB ellipse defined by the input\nC vectors.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC 1) If VEC1 and VEC2 are linearly dependent, ELLIPS will be\nC degenerate. SPICELIB ellipses are allowed to represent\nC degenerate geometric ellipses.\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC SPICELIB ellipses serve to simplify calling sequences and reduce\nC the chance for error in declaring and describing argument lists\nC involving ellipses.\nC\nC The set of ellipse conversion routines is\nC\nC CGV2EL ( Center and generating vectors to ellipse )\nC EL2CGV ( Ellipse to center and generating vectors )\nC\nC$ Examples\nC\nC 1) Find the intersecton of an ellipse with a plane. The ellipse\nC is defined by the vectors CENTER, VEC1, and VEC2. The plane\nC is defined by the normal vector N and the constant C.\nC\nC C\nC C Make a SPICELIB ellipse. Make a plane while\nC C we're at it.\nC C\nC CALL CGV2EL ( CENTER, VEC1, VEC2, ELLIPS )\nC CALL NVC2PL ( N, C, PLANE )\nC\nC C\nC C Find the intersection of the ellipse and plane.\nC C NXPTS is the number of intersection points; XPT1\nC C and XPT2 are the points themselves.\nC C\nC CALL INELPL ( ELLIPS, PLANE, NXPTS, XPT1, XPT2 )\nC\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC N.J. Bachman (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)\nC\nC Comment section for permuted index source lines was added\nC following the header.\nC\nC- SPICELIB Version 1.0.0, 02-NOV-1990 (NJB)\nC\nC-&\n \nC$ Index_Entries\nC\nC center and generating vectors to ellipse\nC\nC-&\n \n \n \nC\nC SPICELIB functions\nC\n LOGICAL RETURN\n \nC\nC Local parameters\nC\n \nC\nC SPICELIB ellipses contain a center vector, a semi-major\nC axis vector, and a semi-minor axis vector. These are\nC located, respectively, in elements\nC\nC CTRPOS through CTRPOS + 1\nC\nC MAJPOS through MAJPOS + 1\nC\nC MINPOS through MINPOS + 1\nC\nC\n INTEGER CTRPOS\n PARAMETER ( CTRPOS = 1 )\n \n INTEGER MAJPOS\n PARAMETER ( MAJPOS = 4 )\n \n INTEGER MINPOS\n PARAMETER ( MINPOS = 7 )\n \n \nC\nC Standard SPICE error handling.\nC\n IF ( RETURN () ) THEN\n RETURN\n ELSE\n CALL CHKIN ( 'CGV2EL' )\n END IF\n \nC\nC The center of the ellipse is held in the first three elements.\nC\n CALL VEQU ( CENTER, ELLIPS(CTRPOS) )\n \nC\nC Find the semi-axes of the ellipse. These may be degenerate.\nC\n CALL SAELGV ( VEC1, VEC2, ELLIPS(MAJPOS), ELLIPS(MINPOS) )\n \n CALL CHKOUT ( 'CGV2EL' )\n RETURN\n END\n", "meta": {"hexsha": "95584c523386ff135468b2b04c7a6031831aac53", "size": 5656, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/cgv2el.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/cgv2el.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/cgv2el.f", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 26.8056872038, "max_line_length": 71, "alphanum_fraction": 0.6248231966, "num_tokens": 1641, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797124237605, "lm_q2_score": 0.7341195152660688, "lm_q1q2_score": 0.668914808804807}} {"text": "module actual_conductivity_module\n\n use amrex_fort_module, only : rt => amrex_real \n use eos_type_module, only : eos_t\n use fundamental_constants_module\n\n implicit none\n\ncontains\n\n subroutine actual_conductivity_init()\n\n implicit none\n\n end subroutine actual_conductivity_init\n\n subroutine actual_conductivity(eos_state, therm_cond)\n \n use extern_probin_module, only: const_opacity\n\n type (eos_t), intent(in) :: eos_state\n real (kind=rt), intent(inout) :: therm_cond\n\n therm_cond = (16*sigma_SB*(eos_state%T)**3)/(3*const_opacity*eos_state%rho)\n \n end subroutine actual_conductivity\n\nend module actual_conductivity_module\n", "meta": {"hexsha": "ad201b5cc346aa598b40f32804c5c5c75b96c250", "size": 682, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Microphysics/conductivity/constant_opacity/constant_conductive_opacity.f90", "max_stars_repo_name": "yingtchen/Castro", "max_stars_repo_head_hexsha": "5e9bd2f7a699a45447b92a1c9c3064f6c2e3552c", "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": "Microphysics/conductivity/constant_opacity/constant_conductive_opacity.f90", "max_issues_repo_name": "yingtchen/Castro", "max_issues_repo_head_hexsha": "5e9bd2f7a699a45447b92a1c9c3064f6c2e3552c", "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": "Microphysics/conductivity/constant_opacity/constant_conductive_opacity.f90", "max_forks_repo_name": "yingtchen/Castro", "max_forks_repo_head_hexsha": "5e9bd2f7a699a45447b92a1c9c3064f6c2e3552c", "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": 23.5172413793, "max_line_length": 80, "alphanum_fraction": 0.7302052786, "num_tokens": 165, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111796979521253, "lm_q2_score": 0.7341195152660687, "lm_q1q2_score": 0.668914798180897}} {"text": " SUBROUTINE MB03BC( K, AMAP, S, SINV, A, LDA1, LDA2, MACPAR, CV,\n $ SV, DWORK )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute the product singular value decomposition of the K-1\nC triangular factors corresponding to a 2-by-2 product of K\nC factors in upper Hessenberg-triangular form.\nC For a general product of 2-by-2 triangular matrices\nC\nC S(2) S(3) S(K)\nC A = A(:,:,2) A(:,:,3) ... A(:,:,K),\nC\nC Givens rotations are computed so that\nC S(i)\nC [ CV(i-1) SV(i-1) ] [ A(1,1,i)(in) A(1,2,i)(in) ]\nC [ -SV(i-1) CV(i-1) ] [ 0 A(2,2,i)(in) ]\nC S(i)\nC [ A(1,1,i)(out) A(1,2,i)(out) ] [ CV(i) SV(i) ]\nC = [ 0 A(2,2,i)(out) ] [ -SV(i) CV(i) ]\nC\nC stays upper triangular and\nC\nC [ CV(1) SV(1) ] [ CV(K) -SV(K) ]\nC [ -SV(1) CV(1) ] * A * [ SV(K) CV(K) ]\nC\nC is diagonal.\nC\nC ARGUMENTS\nC\nC Input/Output Parameters\nC\nC K (input) INTEGER\nC The number of factors. K >= 1.\nC\nC AMAP (input) INTEGER array, dimension (K)\nC The map for accessing the factors, i.e., if AMAP(I) = J,\nC then the factor A_I is stored at the J-th position in A.\nC\nC S (input) INTEGER array, dimension (K)\nC The signature array. Each entry of S must be 1 or -1.\nC\nC SINV (input) INTEGER\nC Signature multiplier. Entries of S are virtually\nC multiplied by SINV.\nC\nC A (input/output) DOUBLE PRECISION array, dimension\nC (LDA1,LDA2,K)\nC On entry, the leading 2-by-2-by-K part of this array must\nC contain a 2-by-2 product (implicitly represented by its K\nC factors) in upper Hessenberg-triangular form.\nC On exit, the leading 2-by-2-by-K part of this array\nC contains modified triangular factors such that their\nC product is diagonal.\nC\nC LDA1 INTEGER\nC The first leading dimension of the array A. LDA1 >= 2.\nC\nC LDA2 INTEGER\nC The second leading dimension of the array A. LDA2 >= 2.\nC\nC MACPAR (input) DOUBLE PRECISION array, dimension (5)\nC Machine parameters:\nC MACPAR(1) overflow threshold, DLAMCH( 'O' );\nC MACPAR(2) underflow threshold, DLAMCH( 'U' );\nC MACPAR(3) safe minimum, DLAMCH( 'S' );\nC MACPAR(4) relative machine precision, DLAMCH( 'E' );\nC MACPAR(5) base of the machine, DLAMCH( 'B' ).\nC\nC CV (output) DOUBLE PRECISION array, dimension (K)\nC On exit, the first K elements of this array contain the\nC cosines of the Givens rotations.\nC\nC SV (output) DOUBLE PRECISION array, dimension (K)\nC On exit, the first K elements of this array contain the\nC sines of the Givens rotations.\nC\nC Workspace\nC\nC DWORK DOUBLE PRECISION array, dimension (3*(K-1))\nC\nC METHOD\nC\nC The product singular value decomposition of the K-1\nC triangular factors are computed as described in [1].\nC\nC REFERENCES\nC\nC [1] Bojanczyk, A. and Van Dooren, P.\nC On propagating orthogonal transformations in a product of 2x2\nC triangular matrices.\nC In Reichel, Ruttan and Varga: 'Numerical Linear Algebra',\nC pp. 1-9, 1993.\nC\nC CONTRIBUTOR\nC\nC D. Kressner, Technical Univ. Berlin, Germany, June 2001.\nC\nC REVISIONS\nC\nC V. Sima, Research Institute for Informatics, Bucharest, Romania,\nC July 2009, SLICOT Library version of the routine PLAPST.\nC V. Sima, Nov. 2010, Aug. 2011.\nC\nC KEYWORDS\nC\nC Eigenvalues, orthogonal transformation, singular values,\nC singular value decomposition.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, ONE, HALF, TWO\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0, HALF = 0.5D0,\n $ TWO = 2.0D0 )\nC .. Scalar Arguments ..\n INTEGER K, LDA1, LDA2, SINV\nC .. Array Arguments ..\n INTEGER AMAP(*), S(*)\n DOUBLE PRECISION A(LDA1,LDA2,*), CV(*), DWORK(*), MACPAR(*),\n $ SV(*)\nC .. Local Scalars ..\n INTEGER AI, I, PW, SCL\n DOUBLE PRECISION A11, A12, A22, B11, B12, B22, BASE, CC, CL, CR,\n $ EPS, MX, MX2, RMAX, RMIN, RMNS, RMXS, S11, S22,\n $ SC, SFMN, SL, SR, SSMAX, SSMIN, T11, T12, T22,\n $ TEMP, TWOS\nC .. External Subroutines ..\n EXTERNAL DLARTG, DLASV2\nC .. Intrinsic Functions ..\n INTRINSIC ABS, MAX, SQRT\nC\nC .. Executable Statements ..\nC\n RMAX = MACPAR(1)\n RMXS = SQRT( RMAX )\n RMIN = MACPAR(2)\n RMNS = SQRT( RMIN )\n SFMN = MACPAR(3)\n EPS = MACPAR(4)\n BASE = MACPAR(5)\n TWOS = SQRT( TWO )\nC\nC Compute the product of the 2-by-2 triangular matrices.\nC\n PW = 1\n T11 = ONE\n T12 = ZERO\n T22 = ONE\nC\n DO 60 I = 2, K\n AI = AMAP(I)\n A11 = A(1,1,AI)\n A12 = A(1,2,AI)\n A22 = A(2,2,AI)\n IF ( S(AI).NE.SINV ) THEN\n TEMP = A11\n A11 = A22\n A22 = TEMP\n A12 = -A12\n END IF\nC\nC A and T are scaled so that the elements of the resulting\nC product do not overflow.\nC\n MX = ABS( A11 ) / RMXS\n MX2 = ABS( T11 ) / RMXS\n 10 CONTINUE\n IF ( MX*MX2.GE.ONE ) THEN\n IF ( MX.GE.ONE ) THEN\n MX = MX / BASE\n A11 = A11 / BASE\n A22 = A22 / BASE\n A12 = A12 / BASE\n END IF\n IF ( MX2.GE.ONE ) THEN\n MX2 = MX2 / BASE\n T11 = T11 / BASE\n T22 = T22 / BASE\n T12 = T12 / BASE\n END IF\n GOTO 10\n END IF\nC\n MX = ABS( A22 ) / RMXS\n MX2 = ABS( T22 ) / RMXS\n 20 CONTINUE\n IF ( MX*MX2.GE.ONE ) THEN\n IF ( MX.GE.ONE ) THEN\n MX = MX / BASE\n A11 = A11 / BASE\n A22 = A22 / BASE\n A12 = A12 / BASE\n END IF\n IF ( MX2.GE.ONE ) THEN\n MX2 = MX2 / BASE\n T11 = T11 / BASE\n T22 = T22 / BASE\n T12 = T12 / BASE\n END IF\n GOTO 20\n END IF\nC\n MX = ABS( A12 ) / RMXS\n MX2 = ABS( T11 ) / RMXS\n 30 CONTINUE\n IF ( MX*MX2.GE.HALF ) THEN\n IF ( MX.GE.HALF ) THEN\n MX = MX / BASE\n A11 = A11 / BASE\n A22 = A22 / BASE\n A12 = A12 / BASE\n END IF\n IF ( MX2.GE.HALF ) THEN\n MX2 = MX2 / BASE\n T11 = T11 / BASE\n T22 = T22 / BASE\n T12 = T12 / BASE\n END IF\n GOTO 30\n END IF\nC\n MX = ABS( A22 ) / RMXS\n MX2 = ABS( T12 ) / RMXS\n 40 CONTINUE\n IF ( MX*MX2.GE.HALF ) THEN\n IF ( MX.GE.HALF ) THEN\n MX = MX / BASE\n A11 = A11 / BASE\n A22 = A22 / BASE\n A12 = A12 / BASE\n END IF\n IF ( MX2.GE.HALF ) THEN\n MX2 = MX2 / BASE\n T11 = T11 / BASE\n T22 = T22 / BASE\n T12 = T12 / BASE\n END IF\n GOTO 40\n END IF\nC\nC Avoid underflow if possible.\nC\n MX = MAX( ABS( A11 ), ABS( A22 ), ABS( A12 ) )\n MX2 = MAX( ABS( T11 ), ABS( T22 ), ABS( T12 ) )\n IF ( MX.NE.ZERO .AND. MX2.NE.ZERO ) THEN\n 50 CONTINUE\n IF ( ( MX.LE.( ONE/RMNS ) .AND. MX2.LE.RMNS ) .OR.\n $ ( MX.LE.RMNS .AND. MX2.LE.( ONE/RMNS ) ) )\n $ THEN\n IF ( MX.LE.MX2 ) THEN\n MX = MX * BASE\n A11 = A11 * BASE\n A22 = A22 * BASE\n A12 = A12 * BASE\n ELSE\n MX2 = MX2 * BASE\n T11 = T11 * BASE\n T22 = T22 * BASE\n T12 = T12 * BASE\n END IF\n GOTO 50\n END IF\n END IF\n T12 = T11 * A12 + T12 * A22\n T11 = T11 * A11\n T22 = T22 * A22\n IF ( I.LT.K ) THEN\n DWORK(PW) = T11\n DWORK(PW+1) = T12\n DWORK(PW+2) = T22\n PW = PW + 3\n END IF\n 60 CONTINUE\nC\nC Compute the SVD of this product avoiding unnecessary\nC overflow/underflow in the singular values.\nC\n TEMP = MAX( ABS( T11 / TWO ) + ABS( T12 / TWO ),\n $ ABS( T22 / TWO ) )\n IF ( TEMP.GT.( RMAX/( TWO * TWOS ) ) ) THEN\n TEMP = TEMP / BASE\n T11 = T11 / BASE\n T12 = T12 / BASE\n T22 = T22 / BASE\n END IF\n 70 CONTINUE\n IF ( TEMP.LT.( RMAX/( TWO * BASE * TWOS ) ) .AND.\n $ T11.NE.ZERO .AND. T22.NE.ZERO ) THEN\n SCL = 0\n IF ( ABS( T22 ).LE.TWOS * RMIN ) THEN\n SCL = 1\n ELSE IF ( EPS * ABS( T12 ).GT.ABS( T22 ) ) THEN\n IF ( SQRT( ABS( T11 ) ) * SQRT( ABS( T22 ) ).LE.\n $ ( SQRT( TWOS ) * RMNS ) * SQRT( ABS( T12 ) ) )\n $ SCL = 1\n ELSE\n IF ( ABS( T11 ).LE.TWOS * RMIN *\n $ ( ONE + ABS( T12 / T22 ) ) )\n $ SCL = 1\n END IF\n IF ( SCL.EQ.1 ) THEN\n TEMP = TEMP * BASE\n T11 = T11 * BASE\n T12 = T12 * BASE\n T22 = T22 * BASE\n GOTO 70\n END IF\n END IF\nC\n CALL DLASV2( T11, T12, T22, SSMIN, SSMAX, SR, CR, SL, CL )\nC\nC Now, the last transformation is propagated to the front as\nC described in [1].\nC\n S11 = T11\n S22 = T22\nC\n CV(K) = CR\n SV(K) = SR\nC\n DO 80 I = K, 2, -1\n AI = AMAP(I)\n IF ( S(AI).EQ.SINV ) THEN\n A11 = A(1,1,AI)\n A12 = A(1,2,AI)\n A22 = A(2,2,AI)\n ELSE\n A11 = A(2,2,AI)\n A12 = -A(1,2,AI)\n A22 = A(1,1,AI)\n END IF\n IF ( I.GT.2 ) THEN\n PW = PW - 3\n T11 = DWORK(PW)\n T12 = DWORK(PW+1)\n T22 = DWORK(PW+2)\n IF ( ABS( SR * CL * S22 ).LT.ABS( SL * CR * S11 ) ) THEN\n B11 = T22\n B22 = T11\n B12 = -T12\n CC = CL\n SC = SL\n ELSE\n B11 = A11\n B12 = A12\n B22 = A22\n CC = CR\n SC = SR\n END IF\n MX = MAX( ABS( B11 ), ABS( B12 ), ABS( B22 ) )\n IF ( MX.GT.RMAX / TWO ) THEN\n B11 = B11 / TWO\n B22 = B22 / TWO\n B12 = B12 / TWO\n END IF\n CALL DLARTG( B11 * CC + B12 * SC, SC * B22, CC, SC, TEMP )\n ELSE\n CC = CL\n SC = SL\n END IF\n IF ( ABS( SC ).LT.SFMN * ABS( A22 ) ) THEN\n A(1,1,AI) = SC * SR * A22 + CC * ( CR * A11 + SR * A12 )\n ELSE\n A(1,1,AI) = ( A22 / SC ) * SR\n END IF\n IF ( ABS( SR ).LT.SFMN * ABS( A11 ) ) THEN\n A(2,2,AI) = SC * SR * A11 + CR * ( CC * A22 - SC * A12 )\n ELSE\n A(2,2,AI) = ( A11 / SR ) * SC\n END IF\n A(1,2,AI) = ( A12 * CR - A11 * SR ) * CC + A22 * CR * SC\n IF ( S(AI).NE.SINV ) THEN\n TEMP = A(1,1,AI)\n A(1,1,AI) = A(2,2,AI)\n A(2,2,AI) = TEMP\n A(1,2,AI) = -A(1,2,AI)\n END IF\n CR = CC\n SR = SC\n CV(I-1) = CR\n SV(I-1) = SR\n S11 = T11\n S22 = T22\n 80 CONTINUE\nC\n CV(1) = CL\n SV(1) = SL\nC\n RETURN\nC *** Last line of MB03BC ***\n END\n", "meta": {"hexsha": "4628e83bae46e072302b4a8884c8ab15a7ba3800", "size": 12182, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB03BC.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB03BC.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB03BC.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 30.685138539, "max_line_length": 72, "alphanum_fraction": 0.4362173699, "num_tokens": 3968, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9433475778774728, "lm_q2_score": 0.7090191460821871, "lm_q1q2_score": 0.6688514941253852}} {"text": " double complex function C0DDHK(s12,s34,msq)\n implicit none\nC-----Author: R.K.Ellis July 2012\nC-----The scalar triangle function taken from\nC-----Djouadi,Driesen,Hollik,Kraft arXiv:hep-ph/9701342v1, Eq(5)\n double precision s12,s34,msq,tauZ,tauH\n double complex FFF\nc double complex qlC0DDHK\n tauZ=4d0*msq/s34\n tauH=4d0*msq/s12\n C0DDHK=-2d0*tauZ*tauH/(tauZ-tauH)*(FFF(tauZ)-FFF(tauH))\nC-----changed sign in order to agree with normal QCDLoop definition of scalar integral\n C0DDHK=-C0DDHK/(4d0*msq)\n\nc write(6,*) C0DDHK\nc C0DDHK=qlC0DDHK(s12,s34,msq)\nc write(6,*) C0DDHK\nc pause\n return\n end\n\n\n double complex function C2DDHK(s12,s34,msq)\n implicit none\nC-----Author: R.K.Ellis July 2012\nC-----The combination of triangle functions taken from\nC-----Djouadi,Driesen,Hollik,Kraft arXiv:hep-ph/9701342v1, Eq(5)\n double precision s12,s34,msq,tauZ,tauH\n double complex FFF,GGG\nc double complex qlC2DDHK\n tauZ=4d0*msq/s34\n tauH=4d0*msq/s12\n C2DDHK=dcmplx(tauZ*tauH/(2d0*(tauZ-tauH)))\n & +tauZ*tauH**2/(2d0*(tauZ-tauH)**2)\n & *(tauZ*(FFF(tauZ)-FFF(tauH))+2d0*(GGG(tauZ)-GGG(tauH)))\nC-----changed sign in order to agree with QCDLoop result\n C2DDHK=-C2DDHK/(4d0*msq)\n\nc write(6,*) C2DDHK\nc C2DDHK=qlC2DDHK(s12,s34,msq)\nc write(6,*) C2DDHK\nc pause\n\n return\n end\n\n double complex function FFF(tau)\n implicit none\nC-----Author: R.K.Ellis July 2012\nC-----The basic triangle function taken from\nC-----Djouadi,Driesen,Hollik,Kraft arXiv:hep-ph/9701342v1, Eq(6)\n double precision xlog,tau,rttauinv,rtomtau,pi\n pi=2d0*asin(1d0)\n if (tau .ge. 1d0) then\n rttauinv=1d0/sqrt(tau)\n FFF=dcmplx(asin(rttauinv)**2)\n else\n rtomtau=sqrt(1d0-tau)\n xlog=log((1d0+rtomtau)/(1d0-rtomtau))\n FFF=-0.25d0*dcmplx(xlog,-pi)**2\n endif\n return\n end\n\n double complex function GGG(tau)\n implicit none\nC-----Author: R.K.Ellis July 2012\nC-----The other needed function taken from\nC-----Djouadi,Driesen,Hollik,Kraft arXiv:hep-ph/9701342v1, Eq(7)\n double precision tau,rttauinv,rtomtau,pi,xlog\n pi=2d0*asin(1d0)\n if (tau .ge. 1d0) then\n rtomtau=sqrt(tau-1d0)\n rttauinv=1d0/sqrt(tau)\n GGG=dcmplx(rtomtau*asin(rttauinv))\n else\n rtomtau=sqrt(1d0-tau)\n xlog=log((1d0+rtomtau)/(1d0-rtomtau))\n GGG=rtomtau/2d0*dcmplx(xlog,-pi)\n endif\n return\n end\n\n\n", "meta": {"hexsha": "cb128984c6ad3ba8376f272fb209fe796d5fc894", "size": 2500, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "MCFM-JHUGen/src/ggHZga/C0DDHK.f", "max_stars_repo_name": "tmartini/JHUGen", "max_stars_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-06-08T13:09:28.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-04T19:59:36.000Z", "max_issues_repo_path": "MCFM-JHUGen/src/ggHZga/C0DDHK.f", "max_issues_repo_name": "tmartini/JHUGen", "max_issues_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 64, "max_issues_repo_issues_event_min_datetime": "2015-06-24T15:08:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-25T04:59:32.000Z", "max_forks_repo_path": "MCFM-JHUGen/src/ggHZga/C0DDHK.f", "max_forks_repo_name": "tmartini/JHUGen", "max_forks_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2015-05-04T22:15:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-06T10:04:40.000Z", "avg_line_length": 29.4117647059, "max_line_length": 86, "alphanum_fraction": 0.64, "num_tokens": 983, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475762847495, "lm_q2_score": 0.7090191399336402, "lm_q1q2_score": 0.6688514871958972}} {"text": " double complex function Ftriangle(x)\n implicit none \n include 'constants.f'\n double precision x,y\n double complex arg\n y=1d0-4d0*x\n if (y .gt. 0d0) then\n arg=dcmplx((1d0+sqrt(y))/(1d0-sqrt(y)))\n Ftriangle=+dcmplx(0.5d0)*(log(arg)-impi)**2\n elseif (y .le. 0d0) then\n Ftriangle=-dcmplx(2d0)*dcmplx(asin(half/sqrt(x)))**2\n endif\n return \n end \n\n", "meta": {"hexsha": "c1594bc1a5698439a11532f215c59902673c629c", "size": 413, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "MCFM-JHUGen/src/ggHgaga/Ftriangle.f", "max_stars_repo_name": "tmartini/JHUGen", "max_stars_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-06-08T13:09:28.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-04T19:59:36.000Z", "max_issues_repo_path": "MCFM-JHUGen/src/ggHgaga/Ftriangle.f", "max_issues_repo_name": "tmartini/JHUGen", "max_issues_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 64, "max_issues_repo_issues_event_min_datetime": "2015-06-24T15:08:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-25T04:59:32.000Z", "max_forks_repo_path": "MCFM-JHUGen/src/ggHgaga/Ftriangle.f", "max_forks_repo_name": "tmartini/JHUGen", "max_forks_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2015-05-04T22:15:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-06T10:04:40.000Z", "avg_line_length": 25.8125, "max_line_length": 58, "alphanum_fraction": 0.5714285714, "num_tokens": 147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.943347579470196, "lm_q2_score": 0.7090191214879991, "lm_q1q2_score": 0.6688514720537887}} {"text": " SUBROUTINE core06ps( eprop, pprop, matdef, pflow, &\r\n vps, beta, epstl,istop, s1,s2, ehs)\r\n !-------------------------------------------------------------------\r\n !\r\n ! calculates elasto-plastic stresses for rubber in plane stress\r\n !\r\n !-------------------------------------------------------------------\r\n USE lispa0\r\n IMPLICIT NONE\r\n\r\n INTEGER (kind=4),PARAMETER :: mitep=5\r\n REAL (kind=8) ,PARAMETER :: toler=1d-4\r\n\r\n INTEGER (kind=4), INTENT(IN) :: matdef !constitutive model (strain energy)\r\n INTEGER (kind=4), INTENT(IN OUT) :: istop\r\n REAL (kind=8), INTENT(IN) :: eprop(12), & !elastic properties\r\n pprop(2) !plastic properties\r\n LOGICAL, INTENT(OUT) :: pflow\r\n REAL (kind=8), INTENT(IN OUT) :: epstl, & !effective plastic strain\r\n vps(3), & !elastic stretchings\r\n beta(:) !principal stresses\r\n REAL (kind=8), OPTIONAL :: ehs(3), & !elastic strains (Hencky)\r\n s1,s2 !principal direction 1\r\n\r\n !Local variables\r\n INTEGER (kind=4) :: iterp\r\n REAL (kind=8) :: lambda,yield,efstp,glambd,hard,epstlo, &\r\n vpso(2),dbl(3),vect(2),preys\r\n\r\n INTERFACE\r\n INCLUDE 'rubberps.h'\r\n END INTERFACE\r\n\r\n pflow = .FALSE. !initialize to no plastic flow\r\n\r\n !Phase i : set up yield limit\r\n preys = pprop(1) + pprop(2)*epstl\r\n !Phase ii : calculate the stress and equivalent stress (elastic predictor)\r\n CALL rubberps(eprop,vps,matdef,beta,vec=dbl)\r\n efstp = SQRT(beta(1)**2+beta(2)**2-beta(1)*beta(2)) ! |beta|\r\n !Phase iii : check IF the current gauss point has plastified\r\n yield = efstp - preys !yield function |beta| - k\r\n\r\n IF (yield/preys > toler) THEN !The state is plastic\r\n\r\n !Phase iv : calculate the plastic multiplier\r\n ! Newton-Raphson iteration consistency condition\r\n ! Initialization\r\n vect(1) = (beta(1)-beta(2)/2d0) / efstp !yield surface normal\r\n vect(2) = (beta(2)-beta(1)/2d0) / efstp !yield surface normal\r\n vpso = vps(1:2) !keep trial elastic stretches\r\n epstlo = epstl !previous equivalent plastic strain\r\n lambda = 0d0 !initializes consistency parameter\r\n iterp = 0 !initializes iterations\r\n\r\n DO !loop until convergence\r\n iterp = iterp + 1 !update iteration number\r\n !computation of plastic multiplier increment\r\n hard = pprop(2) + &\r\n vect(1)*dbl(1)*vect(1)+vect(2)*dbl(3)*vect(2)+2d0*vect(1)*dbl(2)*vect(2)\r\n glambd = yield/hard !plastic multiplier increment\r\n !updates variables\r\n lambda = lambda + glambd !plastic multiplier\r\n epstl = epstlo + lambda !effective plastic strain\r\n preys = pprop(1) + pprop(2)*epstl !yield limit\r\n vps(1) = vpso(1) * EXP(-lambda*vect(1)) !elastic principal stretchings\r\n vps(2) = vpso(2) * EXP(-lambda*vect(2)) !elastic principal stretchings\r\n\r\n ! calculate the stress and equivalent stress (elastic predictor)\r\n CALL rubberps(eprop,vps,matdef,beta,vec=dbl)\r\n efstp = SQRT(beta(1)**2+beta(2)**2-beta(1)*beta(2)) ! |beta|\r\n\r\n !Phase vi : check IF the current gauss point has plastified\r\n yield = efstp - preys\r\n\r\n !check to end iteration\r\n IF (ABS(yield/preys) < toler) EXIT\r\n IF(iterp <= mitep) CYCLE\r\n WRITE(lures,\"(' Program will be stopped. No convergence in', &\r\n & ' the RETURN algorithm')\",ERR=9999)\r\n istop = 1\r\n RETURN\r\n END DO\r\n pflow = .TRUE. !Plastic flow\r\n\r\n END IF\r\n ! phase viii : compute deviatoric elastic strains (twice)\r\n IF( PRESENT(s1).AND.PRESENT(s2))THEN\r\n vect = beta(1:2)\r\n beta(1) = s1*vect(1)*s1 + s2*vect(2)*s2 !(1,1)\r\n beta(2) = s2*vect(1)*s2 + s1*vect(2)*s1 !(2,2)\r\n beta(3) = s1*vect(1)*s2 - s2*vect(2)*s1 !(1,2)\r\n IF( pflow .AND. PRESENT( ehs ) )THEN\r\n vect = LOG(vps(1:2))*2d0\r\n ehs(1) = s1*vect(1)*s1 + s2*vect(2)*s2 !(1,1)\r\n ehs(2) = s2*vect(1)*s2 + s1*vect(2)*s1 !(2,2)\r\n ehs(3) = s1*vect(1)*s2 - s2*vect(2)*s1 !(1,2)\r\n END IF\r\n END IF\r\n\r\n RETURN\r\n 9999 CALL runen2('')\r\n END SUBROUTINE core06ps\r\n", "meta": {"hexsha": "26d1be2021ee7900f1e3ea7b93210a7e9c326d4f", "size": 4273, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/matdb/core06ps.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/matdb/core06ps.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/matdb/core06ps.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": 41.0865384615, "max_line_length": 85, "alphanum_fraction": 0.555347531, "num_tokens": 1316, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009642742805, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6688461985295764}} {"text": " module e3metric_m\nc\n use e3if_defs_m\nc\n implicit none\nc\n contains\nc\n subroutine e3metric(shg, dxdxi,shgl,xl)\nc\n real*8, dimension(:,:,:), pointer, intent(out) :: dxdxi, shg\n real*8, dimension(:,:,:), pointer, intent(in) :: xl, shgl\nc\n integer :: n, nshl\n real*8 :: dxidx(npro,nsd,nsd), WdetJ(npro), tmp(npro)\nc\n call calc_deform_grad(dxdxi,xl,shgl)\nc\nc.... compute the inverse of deformation gradient\nc\n dxidx(:,1,1) = dxdxi(:,2,2) * dxdxi(:,3,3) \n & - dxdxi(:,3,2) * dxdxi(:,2,3)\n dxidx(:,1,2) = dxdxi(:,3,2) * dxdxi(:,1,3) \n & - dxdxi(:,1,2) * dxdxi(:,3,3)\n dxidx(:,1,3) = dxdxi(:,1,2) * dxdxi(:,2,3) \n & - dxdxi(:,1,3) * dxdxi(:,2,2)\n tmp = one / ( dxidx(:,1,1) * dxdxi(:,1,1) \n & + dxidx(:,1,2) * dxdxi(:,2,1) \n & + dxidx(:,1,3) * dxdxi(:,3,1) )\n dxidx(:,1,1) = dxidx(:,1,1) * tmp\n dxidx(:,1,2) = dxidx(:,1,2) * tmp\n dxidx(:,1,3) = dxidx(:,1,3) * tmp\n dxidx(:,2,1) = (dxdxi(:,2,3) * dxdxi(:,3,1) \n & - dxdxi(:,2,1) * dxdxi(:,3,3)) * tmp\n dxidx(:,2,2) = (dxdxi(:,1,1) * dxdxi(:,3,3) \n & - dxdxi(:,3,1) * dxdxi(:,1,3)) * tmp\n dxidx(:,2,3) = (dxdxi(:,2,1) * dxdxi(:,1,3) \n & - dxdxi(:,1,1) * dxdxi(:,2,3)) * tmp\n dxidx(:,3,1) = (dxdxi(:,2,1) * dxdxi(:,3,2) \n & - dxdxi(:,2,2) * dxdxi(:,3,1)) * tmp\n dxidx(:,3,2) = (dxdxi(:,3,1) * dxdxi(:,1,2) \n & - dxdxi(:,1,1) * dxdxi(:,3,2)) * tmp\n dxidx(:,3,3) = (dxdxi(:,1,1) * dxdxi(:,2,2) \n & - dxdxi(:,1,2) * dxdxi(:,2,1)) * tmp\nc\nc WdetJ = Qwt(lcsyst,intp) / tmp\nc\nc.... compute the global gradient of shape-functions\nc\n nshl = size(shgl,3)\nc\n do n = 1, nshl\n shg(:,n,1) = shgl(:,1,n) * dxidx(:,1,1) + \n & shgl(:,2,n) * dxidx(:,2,1) +\n & shgl(:,3,n) * dxidx(:,3,1)\n shg(:,n,2) = shgl(:,1,n) * dxidx(:,1,2) + \n & shgl(:,2,n) * dxidx(:,2,2) +\n & shgl(:,3,n) * dxidx(:,3,2) \n shg(:,n,3) = shgl(:,1,n) * dxidx(:,1,3) + \n & shgl(:,2,n) * dxidx(:,2,3) +\n & shgl(:,3,n) * dxidx(:,3,3) \n enddo\n\n return\nc\n end subroutine e3metric \nc\n subroutine calc_deform_grad(dxdxi,xl,shgl)\nc\n real*8, dimension(:,:,:), intent(out) :: dxdxi\n real*8, dimension(:,:,:), intent(in) :: xl, shgl\nc\n integer :: npro,nenl,nsd,n,i,j\nc\n npro = size(xl,1)\n nenl = size(xl,2)\n nsd = size(xl,3)\nc\n dxdxi = zero\nc\n do n = 1, nenl\n do i = 1, nsd\n do j = 1, nsd\n dxdxi(:,i,j) = dxdxi(:,i,j) + xl(:,n,i)*shgl(:,j,n)\n enddo\n enddo\n enddo\nc\n end subroutine calc_deform_grad\nc\n end module e3metric_m\n", "meta": {"hexsha": "4a68aeb6a6d0afb1c2c6eb11120403fdcdbeb9e6", "size": 3005, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "phSolver/compressible/e3metric_m.f", "max_stars_repo_name": "yangf4/phasta", "max_stars_repo_head_hexsha": "a096094f33b98047de0a2e28225c4d74875a88d8", "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": "phSolver/compressible/e3metric_m.f", "max_issues_repo_name": "yangf4/phasta", "max_issues_repo_head_hexsha": "a096094f33b98047de0a2e28225c4d74875a88d8", "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": "phSolver/compressible/e3metric_m.f", "max_forks_repo_name": "yangf4/phasta", "max_forks_repo_head_hexsha": "a096094f33b98047de0a2e28225c4d74875a88d8", "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.6630434783, "max_line_length": 68, "alphanum_fraction": 0.412312812, "num_tokens": 1203, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009480320037, "lm_q2_score": 0.7310585844894971, "lm_q1q2_score": 0.6688461920163756}} {"text": " subroutine init_ctfm2(x,Nx,lv,rv,res)\n implicit none\n integer i\n integer Nx\n real*8 lv\n real*8 rv\n real*8 x(Nx)\n real*8 res(Nx)\n real*8 qb\n do i=1, Nx, 1\n qb = exp(x(i)) - 0.1D1 * exp(lv) + (0.1D1 / (0.1D1 - 0.1D1 * x(i) \n #/ rv) - 0.1D1 / (0.1D1 - 0.1D1 * lv / rv)) ** (rv - 0.1D1 * x(i) +\n # 0.1D1)\n res(i)=qb\n end do\n END\n", "meta": {"hexsha": "8ce374e53ad5cc12e416fd7f529742174225c6a1", "size": 404, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/FD/init_ctfm2.f", "max_stars_repo_name": "rmanak/bssn_spher", "max_stars_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/FD/init_ctfm2.f", "max_issues_repo_name": "rmanak/bssn_spher", "max_issues_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/FD/init_ctfm2.f", "max_forks_repo_name": "rmanak/bssn_spher", "max_forks_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.7647058824, "max_line_length": 72, "alphanum_fraction": 0.4430693069, "num_tokens": 185, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6688461917444019}} {"text": "module poisson_example_mod\r\n\r\n use precision_mod, only: wp\r\n use source_mod, only: source_term\r\n use poisson_mod, only: Lattice, init_Lattice\r\n\r\n implicit none\r\n private\r\n\r\n public :: pb_src, init_pb_src, poisson_example, analytical_solution\r\n\r\n type, extends(source_term) :: pb_src ! poisson boltzmann source\r\n real(wp) :: k\r\n contains\r\n procedure :: eval\r\n end type\r\n\r\ncontains\r\n\r\n function init_pb_src(k) result(this)\r\n real(wp), intent(in) :: k\r\n type(pb_src) :: this\r\n this%k = k\r\n end function\r\n\r\n real(wp) function eval(this,u,x)\r\n class(pb_src), intent(in) :: this\r\n real(wp), intent(in) :: u\r\n real(wp), intent(in) :: x\r\n eval = this%k**2*u\r\n end function\r\n\r\n!> Returns analytical solution of $\\Delta u = k^2 u$ on\r\n! the domain $\\[0,1\\]$ with constant Dirichlet boundary conditions\r\n! $u(0) = 1$, $u(1) = 1$.\r\n!\r\n! See Eq. (3.4) in paper by Chai and Shi (2008)\r\n!\r\n elemental function analytical_solution(x,k) result(u)\r\n real(wp), intent(in) :: x\r\n real(wp), intent(in) :: k\r\n real(wp) :: u\r\n\r\n u = (exp(k) - 1.0_wp)/(exp(k) - exp(-k))*exp(-k*x) + &\r\n & (1.0_wp - exp(-k))/(exp(k) - exp(-k))*exp(k*x)\r\n end function\r\n\r\n\r\n subroutine poisson_example(k,nx,steps,check,tol)\r\n real(wp), intent(in) :: k\r\n integer, intent(in) :: nx, steps, check\r\n real(wp) :: tol\r\n\r\n real(wp), allocatable :: uold(:), u(:)\r\n real(wp) :: gre, omega\r\n type(Lattice) :: latt\r\n type(pb_src), target :: mysrc\r\n integer :: i, step\r\n\r\n ! Initalize density arrays\r\n allocate(uold(nx),u(nx))\r\n uold = 0.0_wp; uold([1,nx]) = 1._wp\r\n\r\n ! Create source term\r\n mysrc = init_pb_src(k)\r\n \r\n ! Create lattice\r\n omega = 1.0_wp\r\n latt = init_Lattice(nx=nx,uinit=uold,omega=omega,src=mysrc)\r\n\r\n time_loop: do step = 1, steps\r\n\r\n call latt%collide_and_stream()\r\n\r\n call latt%set_left_neem(1.0_wp)\r\n call latt%set_right_neem(1.0_wp)\r\n \r\n ! Check convergence\r\n if (mod(step,check) == 0) then\r\n call latt%get_macroscopic_values(u)\r\n gre = sum(abs(u-uold))/sum(abs(u)) ! global relative error\r\n uold = u\r\n write(*,*) \"step = \", step, \"error = \", gre\r\n if (gre < tol) exit time_loop\r\n end if\r\n\r\n call latt%prep_next_step()\r\n end do time_loop\r\n\r\n call latt%output(\"poisson_results.txt\")\r\n\r\n end subroutine\r\n\r\nend module\r\n\r\n\r\nmodule reaction_example_mod\r\n\r\n use precision_mod, only: wp\r\n use source_mod, only: source_term\r\n use poisson_mod, only: Lattice, init_Lattice\r\n\r\n implicit none\r\n private\r\n\r\n public :: reaction_example\r\n\r\n type, extends(source_term) :: rc_src ! poisson boltzmann source\r\n real(wp) :: Th\r\n contains\r\n procedure :: eval\r\n end type\r\n\r\ncontains\r\n\r\n function init_rc_src(Th) result(this)\r\n real(wp), intent(in) :: Th\r\n type(rc_src) :: this\r\n this%Th = Th\r\n end function\r\n\r\n real(wp) function eval(this,u,x)\r\n class(rc_src), intent(in) :: this\r\n real(wp), intent(in) :: u\r\n real(wp), intent(in) :: x\r\n eval = this%Th**2*u\r\n end function\r\n\r\n subroutine reaction_example(Th,nx,steps,check,tol)\r\n real(wp), intent(in) :: Th\r\n integer, intent(in) :: nx\r\n integer, intent(in) :: steps\r\n integer, intent(in) :: check\r\n real(wp), intent(in) :: tol\r\n\r\n real(wp), allocatable :: uold(:), u(:)\r\n real(wp) :: interval(2), gre, omega, rval\r\n type(Lattice) :: latt\r\n\r\n type(rc_src), target :: mysrc\r\n\r\n integer :: i, step\r\n\r\n ! Initalize density arrays\r\n allocate(uold(nx),u(nx))\r\n uold = 0.0_wp; \r\n u = uold\r\n\r\n ! Create source term\r\n mysrc = init_rc_src(Th)\r\n \r\n ! Create lattice\r\n omega = 1.0_wp\r\n latt = init_Lattice(nx=nx,uinit=uold,omega=omega,src=mysrc)\r\n\r\n time_loop: do step = 1, steps\r\n\r\n call latt%collide_and_stream(uout=u)\r\n\r\n ! Boundaries\r\n call latt%set_left_neem(1.0_wp)\r\n rval = (4.0_wp*u(nx-1) - u(nx-2))/3.0_wp ! one-sided finite difference\r\n call latt%set_right_neem(rval)\r\n \r\n ! Convergence check\r\n if (mod(step,check) == 0) then\r\n gre = sum(abs(u-uold))/sum(abs(u)) ! global relative error\r\n uold = u\r\n write(*,*) \"step = \", step, \"error = \", gre\r\n if (gre < tol) exit time_loop\r\n end if\r\n\r\n call latt%prep_next_step()\r\n end do time_loop\r\n\r\n call latt%output(\"reaction_results.txt\")\r\n\r\n end subroutine\r\n\r\nend module\r\n\r\n\r\nprogram main\r\n\r\n use precision_mod, only: wp\r\n use poisson_example_mod, only: poisson_example\r\n use reaction_example_mod, only: reaction_example\r\n\r\n real(wp) :: tol\r\n\r\n tol = epsilon(tol) ! Set tolerance\r\n\r\n write(*,*) \"Poisson example\"\r\n call poisson_example(k=27.79_wp,nx=101,steps=1000000,check=5000,tol=tol)\r\n \r\n write(*,*) \"\"\r\n write(*,*) \"Reaction example\"\r\n call reaction_example(Th=1.0_wp,nx=101,steps=1000000,check=5000,tol=tol)\r\n\r\nend program", "meta": {"hexsha": "b4ebe1174b75e296a64fc1a1d817099c4ae6e88a", "size": 5402, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "apps/examples.f90", "max_stars_repo_name": "myousefi2016/poisson_lbm", "max_stars_repo_head_hexsha": "de1e09893c5b257cc0bfe17912c4f1fe1f3d821b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-12-23T19:11:55.000Z", "max_stars_repo_stars_event_max_datetime": "2018-12-23T19:11:55.000Z", "max_issues_repo_path": "apps/examples.f90", "max_issues_repo_name": "myousefi2016/poisson_lbm", "max_issues_repo_head_hexsha": "de1e09893c5b257cc0bfe17912c4f1fe1f3d821b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "apps/examples.f90", "max_forks_repo_name": "myousefi2016/poisson_lbm", "max_forks_repo_head_hexsha": "de1e09893c5b257cc0bfe17912c4f1fe1f3d821b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.01, "max_line_length": 83, "alphanum_fraction": 0.5405405405, "num_tokens": 1465, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009642742806, "lm_q2_score": 0.7310585669110203, "lm_q1q2_score": 0.6688461878078662}} {"text": "! file contains code which creates the hydrogen's orbitals. \n! \n! Dependencies: \n!\n! \tA SHTOOLS 4.4 tool and its dependencies are required to \n!\tcalculate Legendre's associated polynomials. See the link \n!\tbelow for installation and more information.\n!\n!\thttps://shtools.oca.eu/shtools/\n!\n! Licenses: \n!\n!\tThis file is subject to the terms and conditions defined in\n!\tfile 'LICENSE', which is part of this source code.\n!\n\tprogram atomOrb\n\t\timplicit none\n\t\tinteger, parameter :: n = 4, l = 1, m = 1\n\t\treal, parameter :: dx = 0.0 , dy = 60.0, dz = 60.0\n\t\treal, parameter :: dr = 0.2, dtheta = 0.2, icr = 1.05\n\t\tinteger, parameter :: points = 50000\n\n\t\tinteger :: rDiv, thetaDiv, i\n\t\treal :: theta, r, w, max, pi\n\t\treal :: angDF, radDF\n\t\treal :: wave2Max, psi2\n\t\treal :: rAbs, thetaVal\n\t\treal :: rVector(3)\n\t\n\t\tpi = 4.0 * atan(1.0)\n\n\t\tcall init_random_seed()\n\n\t\trDiv = int(rAbs((/ dx, dy, dz /)) / dr) + 1\n\t\tthetaDiv = int(2.0 * pi / dtheta) + 1\n\t\tmax = wave2max((/dx,dy,dz/), (/n,l,m/), rDiv, thetaDiv)\n\n\t\tdo while (i <= points)\n\t\tCALL RANDOM_NUMBER(w)\n\t\t\tw = w * max * icr\n\t\t\tcall fillVector(rVector, dx, dy, dz)\n\t\t\tr = rAbs(rVector)\n\t\t\ttheta = thetaVal(rVector)\n\t\t\tpsi2 = radDF(n, l, r) * angDF(l, m, theta) \n\t\t\tif(w < psi2) then\n\t\t\t\twrite(*,*) rVector, w\n\t\t\t\ti = i + 1\n\t\t\tend if\n\t\tend do\n\tend program atomOrb\n\n\tfunction wave2max(coordRange, nlm, rDiv, thetaDiv)\n\t\timplicit none\n\t\tinterface\n\t\tfunction radDF(n, l, r)\n\t\t\timplicit none\n\t\t\t! dummy arguments \n\t\t\treal :: radDF\n\t\t\t! local variables\n\t\t\tinteger :: n, l, Z = 1\n\t\t\tinteger :: k\n\t\t\treal :: r, r0, a0 = 0.52917721067\n\t\t\treal*8 :: normTermSquared, radialTerm\n\t\t\treal*8 :: arr(6), sum\n\t\tend function radDF \n\t\tend interface\n\t\n\t\tinterface\n\t\tfunction angDF(l, m, theta) \n\t\tuse SHTOOLS\n\t\t! function result \n\t\timplicit none \n\t\t! dummy arguments \n\t\treal :: angDF \n\t\t\n\t\t! local variables \n\t\tinteger \t\t\t :: l, m, arrayindex\n\t\treal*8 :: z, normRoot\n\t\treal*8, dimension ((l+1)*(l+2)/2) :: p\n\t\treal \t\t\t\t :: theta, pi\n\t\tend function angDF\n\t\tend interface\n\t\n\t\treal :: wave2Max\n\n\t\treal :: coordRange(3)\n\t\tinteger :: nlm(3), rDiv, thetaDiv\n\t\treal :: rmax, sum, dr, dtheta, pi, curr(2)\n\t\treal :: maxValue, r, theta, calc\n\t\tinteger :: i, j\n\t\t\n\t\tpi = 4.0 * atan(1.0)\n\t\t\n\t\tdo i = 1, 3, 1\n\t\t\tsum = sum + coordRange(i) ** 2.0\n\t\tend do \n\t\n\t\trmax = sqrt(sum)\n\t\n\t\tdr = rMax / (1.0 * rDiv)\n\t\tdTheta = pi / (1.0 * thetaDiv)\n\t\tmaxValue = 0.0\n\n\t\tdo i = 0, rDiv, 1\n\t\t\tr = i * dr\n\t\t\tdo j = 0, thetaDiv, 1\n\t\t\t\ttheta = j * dtheta\n\t\t\t\tcurr(1) = angDF(nlm(2), nlm(3), theta) \n\t\t\t\tcurr(2) = radDF(nlm(1), nlm(2), r)\n\t\t\t\tcalc = curr(1) * curr(2)\n\n\t\t\t\tif(calc > maxValue) then\n\t\t\t\t\tmaxValue = calc\n\t\t\t\tend if\n\t\t\tend do\n\t\tend do\n\n\t\twave2max = maxValue\n\tend function\n\t\n\tsubroutine fillVector(r, dx, dy, dz)\n\treal, intent(out) :: r(3)\n\treal :: dx, dy, dz\n\n\tCALL RANDOM_NUMBER(r(1))\n\tr(1) = dx * (r(1) - 0.5) \n\n\tCALL RANDOM_NUMBER(r(2))\n\tr(2) = dy * (r(2) - 0.5) \n\n\tCALL RANDOM_NUMBER(r(3))\n\tr(3) = dz * (r(3) - 0.5) \n\t\n\tend subroutine\n\t\n\tfunction rAbs(r)\n\t\timplicit none\n\t\treal :: rAbs\n\t\treal :: r(3)\n\t\t\n\t\trAbs = sqrt(r(1)**2+r(2)**2+r(3)**2)\n\n\tend function\n\n\tfunction thetaVal(r)\n\t\timplicit none\n\t\t\n\t\treal :: thetaVal\n\t\treal :: r(3), sum\n\t\tinteger :: i\n\t\t\t\t\n\t\tdo i = 1, 3, 1\n\t\t\tsum = sum + r(i) ** 2.0\n\t\tend do\n\t\n\t\tthetaVal = acos(r(3) / sqrt(sum))\n\t\n\tend function thetaVal\n\n\tfunction radDF(n, l, r)\n\t\timplicit none\n\t\tINTERFACE \n\t\t FUNCTION Factorial(n)\n\t\t INTEGER*8 :: Factorial\n\t\t INTEGER, INTENT(IN) :: n\n\t\t END FUNCTION Factorial\n\t\tEND INTERFACE\t\n\t\n\t\t! dummy arguments \n\t\treal :: radDF\n\t\t! local variables\n\t\tinteger :: n, l, Z = 1\n\t\tinteger :: k\n\t\treal :: r, r0, a0 = 0.52917721067\n\t\treal*8 :: normTermSquared, radialTerm, arr(6), sum\n\t\t\n\t\tr0 = 2.0 * Z/(n * a0) * r\n\t\tsum = 0.0\n\n\t\t\n\t\tdo k = 0, n - l - 1, 1\n\t\t\tarr(1) = (-1.0) ** (k + 1) \n\t\t\tarr(2) = factorial(n + l) ** 2.0\n\t\t\tarr(3) = factorial(n - l - 1 - k)\n\t\t\tarr(4) = factorial(2 * l + 1 + k) \n\t\t\tarr(5) = factorial(k)\n\t\t\tarr(6) = r0 ** k\n\t\t\tsum = sum+arr(1)*arr(2)/(arr(3)*arr(4)*arr(5))*arr(6) \n\t\tend do\n\t\t\n\t\tarr(:) = 0.0\n\t\tarr(1) = (2.0 * Z / (n * a0)) ** 3.0\n\t\tarr(2) = factorial(n - l - 1)\n\t\tarr(3) = 2.0 * n\n\t\tarr(4) = factorial(n + l) ** 3.0\n\t\t\n\t\tnormTermSquared = arr(1)*arr(2)/(arr(3)*arr(4))\n\n\t\tradialTerm = exp(-r0 / 2.0) * (r0 ** l);\n\n\t\tradDF = (sum * radialTerm) ** 2.0\n\t\tradDF = radDF * normTermSquared\n\tend function radDF\n\n\tfunction angDF (l, m, theta) \n\tuse SHTOOLS\n\t! function result \n\timplicit none \n\tINTERFACE \n\t FUNCTION Factorial(n)\n\t INTEGER*8 :: Factorial\n\t INTEGER, INTENT(IN) :: n\n\t END FUNCTION Factorial\n\tEND INTERFACE\t\n\t\n\t! dummy arguments \n\treal :: angDF \n\t\n\t! local variables \n\tinteger \t\t\t\t:: l, m, arrayindex\n\treal*8 :: z, normRoot\n\treal*8, dimension ((l + 1) * (l + 2)/2) :: p\n\treal \t\t\t\t\t:: theta, pi\n\t\t\n\tz = cos(theta)\n\tcall PLegendreA (p, l, z)\n\tarrayindex = PlmIndex (l, m)\t\n\n\t\t\n\tpi = 4.0 * atan(1.0)\n\tnormRoot = 1.0 * factorial(l - m)/ factorial(l + m)\n\tnormRoot = normRoot * (2.0 * l + 1.0)/(4.0 * pi)\n\n\tangDF = normRoot * p(arrayIndex) ** 2.0\n\t\n\tend function angDF \n\n! Evaluate the factorial\n! This was adapted from a post from user gsal at jun 2, 2015 to a \n! Physics Forums, and visited in March 2019. See link bellow.\n\n! Reference https://www.physicsforums.com/threads/factorial-fortran-90.816501/\n\n\tRECURSIVE FUNCTION Factorial(n) RESULT(Fact)\n\t\n\tIMPLICIT NONE\n\tINTEGER*8 :: Fact\n\tINTEGER, INTENT(IN) :: n\n\t\n\tIF (n == 0) THEN\n\t Fact = 1\n\tELSE\n\t Fact = n * Factorial(n-1)\n\tEND IF\n\t\n\tEND FUNCTION Factorial\n\n! Initialize a pseudo-random number sequence\n! This subroutine is a partial copy found on the link below \n! and visited in March 2019.\n\n! https://gcc.gnu.org/onlinedocs/gcc-4.2.3/gfortran/RANDOM_005fSEED.html\n\n! Description:\n! Restarts or queries the state of the pseudorandom number \n! generator used by RANDOM_NUMBER.\n\n\tsubroutine init_random_seed()\n\t\n\tinteger :: i, n, clock\n\tinteger, dimension(:), allocatable :: seed\n\t\n\tcall RANDOM_SEED(size = n)\n\tallocate(seed(n))\n\t\n\tcall SYSTEM_CLOCK(COUNT=clock)\n\t\n\tseed = clock + 37 * (/ (i - 1, i = 1, n) /)\n\n\tcall RANDOM_SEED(PUT = seed)\n\tdeallocate (seed)\n\t\n\tend subroutine\n", "meta": {"hexsha": "610cdec93c374452f86202845a256580c9ef6081", "size": 6202, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "fortran/atom_orb.f95", "max_stars_repo_name": "pedrohflobo/hydrogen_orbitals_by_Monte_Carlo_Method", "max_stars_repo_head_hexsha": "fd98a9259b2316370fc13e7c6fe00f2943f1f0f7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-02-18T13:22:39.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-06T23:44:04.000Z", "max_issues_repo_path": "fortran/atom_orb.f95", "max_issues_repo_name": "lobophf/hydrogen_orbitals_by_Monte_Carlo_Method", "max_issues_repo_head_hexsha": "fd98a9259b2316370fc13e7c6fe00f2943f1f0f7", "max_issues_repo_licenses": ["MIT"], "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/atom_orb.f95", "max_forks_repo_name": "lobophf/hydrogen_orbitals_by_Monte_Carlo_Method", "max_forks_repo_head_hexsha": "fd98a9259b2316370fc13e7c6fe00f2943f1f0f7", "max_forks_repo_licenses": ["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.838028169, "max_line_length": 78, "alphanum_fraction": 0.5881973557, "num_tokens": 2281, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312226373181, "lm_q2_score": 0.7371581568543044, "lm_q1q2_score": 0.6688326084846296}} {"text": "program test\nuse mpfunmod\nuse mpmodule\nimplicit none\ninteger i, ndp, nchx\nparameter (ndp = 100000)\ntype (mp_real) t1, t2\ncharacter*1 chx(ndp+200)\n\ncall mpinit (ndp)\nmpoud = ndp\nt1 = mppic / 10.d0\nt2 = cos (t1)**2 + sin(t1)**2\nwrite (6, *) 'cos(t1)^2 + sin(t1)^2 ='\ncall mpwrite (6, t2)\nwrite (6, *) 'pi to ', ndp, ' digits ='\n\n call mpwrite (6, mppic)\n\n! This code does the equivalent of the previous line with mpwrite, but is much\n! faster in execution (note however this requires the character*1 line above):\n\ncall mpoutcx (mppic%mpr, chx, nchx, mpnwx)\nwrite (6, '(78a1)') (chx(i), i = 1, nchx)\n\nstop\nend \n", "meta": {"hexsha": "ae9381aa3569916d6704d2a51ef3e592c46c0916", "size": 612, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/mpfun/test.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/mpfun/test.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/mpfun/test.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": 21.8571428571, "max_line_length": 80, "alphanum_fraction": 0.6666666667, "num_tokens": 235, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.7371581568543043, "lm_q1q2_score": 0.6688326047895821}} {"text": "\tprogram efflength\nc\nc\tsee page 35 of Wind N.B. Vol 2 for derivation\nc\t\tL is monopole length, R is radius of spherical spacecraft\nc\t\tefflratio is ratio of effective length to L\nc\t\tratiolr is ratio of L to R\nc\n\tDO I = 1,50\n\t RATIOLR = .1*I\n\t EFFLRATIO = (1. + 1./RATIOLR)**2 + 2./(RATIOLR)**3/(1. + \n 1\t\t1./RATIOLR) - 3./(RATIOLR**2)\n\t PRINT*,RATIOLR,EFFLRATIO,(1. + 2./RATIOLR)\n\tENDDO\n\t RATIOLR = 41.67\t\t\t! WIND X\n\t EFFLRATIO = (1. + 1./RATIOLR)**2 + 2./(RATIOLR)**3/(1. + \n 1\t\t1./RATIOLR) - 3./(RATIOLR**2)\n\t PRINT*,RATIOLR,EFFLRATIO,(1. + 2./RATIOLR)\n\t RATIOLR = 6.25\n\t EFFLRATIO = (1. + 1./RATIOLR)**2 + 2./(RATIOLR)**3/(1. + \n 1\t\t1./RATIOLR) - 3./(RATIOLR**2)\n\t PRINT*,RATIOLR,EFFLRATIO,(1. + 2./RATIOLR)\n\t RATIOLR = 4.4/.9\n\t EFFLRATIO = (1. + 1./RATIOLR)**2 + 2./(RATIOLR)**3/(1. + \n 1\t\t1./RATIOLR) - 3./(RATIOLR**2)\n\t PRINT*,RATIOLR,EFFLRATIO,(1. + 2./RATIOLR)\n\tSTOP\n\tEND\n", "meta": {"hexsha": "715c28cf56fad37c1230082330ba6e360937c37b", "size": 910, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/efflength_3.for", "max_stars_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_stars_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/efflength_3.for", "max_issues_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_issues_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/efflength_3.for", "max_forks_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_forks_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.5, "max_line_length": 61, "alphanum_fraction": 0.5824175824, "num_tokens": 484, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248225478307, "lm_q2_score": 0.7122321781307374, "lm_q1q2_score": 0.6688036946820706}} {"text": "! Created by EverLookNeverSee@GitHub on 4/22/20.\n! This program add up all even numbers between 1 to user input.\n\nprogram sum_of_evens\n implicit none\n ! defining variables\n integer :: number, i, sum = 0\n ! getting user input\n1 print *, \"Please enter a positive integer number:\"\n read *, number\n ! Edge case\n if (number <= 0) then\n print *, \"Invalid input!\"\n goto 1\n end if\n do i = 1, number\n if (mod(i, 2) /= 0) then\n cycle ! skipp all odd numbers\n end if\n sum = sum + i\n end do\n print *, \"Sum:\", sum\nend program sum_of_evens", "meta": {"hexsha": "0d59bcb93a00f1cd3e979515411c273d2b59dbd7", "size": 608, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/other/sum_of_evens.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/sum_of_evens.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/sum_of_evens.f90", "max_forks_repo_name": "EverLookNeverSee/FCS", "max_forks_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-06-08T12:57:46.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-08T12:57:46.000Z", "avg_line_length": 26.4347826087, "max_line_length": 63, "alphanum_fraction": 0.59375, "num_tokens": 176, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.6687688005585387}} {"text": "C$Procedure HALFPI ( Half the value of pi )\n \n DOUBLE PRECISION FUNCTION HALFPI ( )\n \nC$ Abstract\nC\nC Return half the value of pi (the ratio of the circumference of\nC a circle to its diameter).\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 CONSTANTS\nC\nC$ Declarations\nC\nC None.\nC\nC$ Brief_I/O\nC\nC The function returns half the value of pi.\nC\nC$ Detailed_Input\nC\nC None.\nC\nC$ Detailed_Output\nC\nC The function returns half the value of pi (the ratio of\nC a circle's circumference to its diameter), determined by\nC the ACOS function. That is,\nC\nC HALFPI = ACOS ( -1.D0 ) * 0.5D0\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 first time the function is referenced, the value is computed\nC as shown above. The value is saved, and returned directly upon\nC subsequent reference.\nC\nC$ Examples\nC\nC The subroutine shown below illustrates the use of HALFPI.\nC\nC SUBROUTINE BFTRAN ( RA, DEC, W, TIPM )\nC\nC C\nC C Compute the transformation from inertial to body\nC C fixed coordinates, given the directions of the north\nC C pole and prime meridian of the body.\nC C\nC DOUBLE PRECISION RA\nC DOUBLE PRECISION DEC\nC DOUBLE PRECISION W\nC DOUBLE PRECISION TIPM ( 3,3 )\nC\nC C\nC C SPICELIB functions\nC C\nC DOUBLE PRECISION HALFPI\nC\nC C\nC C The transformation is defined by the compound\nC C rotation\nC C\nC C [W] [pi/2 - Dec] [RA + pi/2]\nC C 3 1 3\nC C\nC CALL ROTATE ( RA + HALFPI(), 3, TIPM)\nC CALL ROTMAT (TIPM, HALFPI() - DEC, 1, TIPM)\nC CALL ROTMAT (TIPM, W, 3, TIPM)\nC\nC RETURN\nC END\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC J. Diaz del Rio (ODC Space)\nC W.L. Taber (JPL)\nC I.M. Underwood (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.2, 08-APR-2015 (JDR)\nC\nC Minor edit to example comments eliminating typos.\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) (IMU)\nC\nC-&\n \nC$ Index_Entries\nC\nC half the value of pi\nC\nC-&\n \n \n \n \nC\nC Local variables\nC\n DOUBLE PRECISION VALUE\n SAVE VALUE\n \nC\nC Initial values\nC\n DATA VALUE / 0.D0 /\n \n \nC\nC What is there to say?\nC\n IF ( VALUE .EQ. 0.D0 ) THEN\n VALUE = ACOS ( -1.D0 ) * 0.5D0\n END IF\n \n HALFPI = VALUE\n \n RETURN\n END\n", "meta": {"hexsha": "9c4081f32a0f11e60f31bc9e505bdd5fbf4d4f91", "size": 4343, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/halfpi.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/halfpi.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/halfpi.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.5367231638, "max_line_length": 71, "alphanum_fraction": 0.6136311306, "num_tokens": 1272, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.6687688005585387}} {"text": "module KuraNetwork\n use iso_fortran_env, only: real64\n implicit none\n\n type KuramotoNetwork\n integer :: nnodes\n integer :: nedges\n real(kind=real64) :: couple_constant\n real(kind=real64), dimension(:),allocatable :: p \n real(kind=real64), dimension(:),allocatable :: swap \n integer,dimension(:),allocatable :: Bt_csr !IncidenceMatrix \n end type \n\n interface KuramotoNetwork\n module procedure KNConstructor\n end interface\n ! TODO: Constructor that allocates tmp(nnodes)\ncontains\n type(KuramotoNetwork) function KNConstructor(nnodes,nedges,couple_constant)\n implicit none\n integer::nnodes\n integer::nedges\n real(real64)::couple_constant\n KNConstructor%nnodes = nnodes\n KNConstructor%nedges = nedges\n KNConstructor%couple_constant = couple_constant\n allocate(KNConstructor%p(nnodes)) \n allocate(KNConstructor%swap(nedges)) \n allocate(KNConstructor%Bt_csr(nedges*2))\n\n end function KNConstructor \n\n subroutine f(this,t,x,dx)\n ! dx .= p .- coupling_constant .* (B * sin.(B_t * x)) \n implicit none\n \n class(KuramotoNetwork), intent(inout) :: this\n \n real(kind=real64), intent(in) :: t\n real(kind=real64), intent(in), dimension(:) :: x\n real(kind=real64), intent(out), dimension(:) :: dx\n integer :: i\n associate( nedges => this%nedges,&\n nnodes => this%nnodes,&\n col_index => this%Bt_csr,&\n omega => this%p,&\n couple_constant => this%couple_constant,&\n y => this%swap) \n y = 0 \n do concurrent (i =1:nedges) \n y(i) = sin(x(col_index((i-1)*2+2)) - x(col_index((i-1)*2+1)))\n end do\n dx = 0\n do i = 1,nedges ! treat the csr as a csc to transpose it \n associate(idx_s => col_index((i-1)*2+1),&\n idx_k => col_index((i-1)*2+2)&\n ) \n dx(idx_s) = dx(idx_s) - y(i)\n dx(idx_k) = dx(idx_k) + y(i)\n end associate\n end do\n do concurrent (i = 1:nnodes) ! now dx = B*sin(B_t*x)\n dx(i) = omega(i) - couple_constant * dx(i)\n end do\n ! Now dx .= p .- coupling_constant .* (B*sin.(Bt*x))\n\n end associate\n end subroutine f \nend module KuraNetwork\n", "meta": {"hexsha": "62d0f4535105df4ffe9c1f683bcc52bfb93c3649", "size": 2432, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/app/KuraNetwork.f90", "max_stars_repo_name": "PIK-ICoNe/NetworkDynamicsBenchmarks", "max_stars_repo_head_hexsha": "d528181f4c3d023ab11b8b2871f219530b99efa5", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-06-21T15:05:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-31T21:02:53.000Z", "max_issues_repo_path": "src/fortran/app/KuraNetwork.f90", "max_issues_repo_name": "PIK-ICoNe/NetworkDynamicsBenchmarks", "max_issues_repo_head_hexsha": "d528181f4c3d023ab11b8b2871f219530b99efa5", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-03-29T20:58:12.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-30T08:02:26.000Z", "max_forks_repo_path": "src/fortran/app/KuraNetwork.f90", "max_forks_repo_name": "PIK-ICoNe/NetworkDynamicsBenchmarks", "max_forks_repo_head_hexsha": "d528181f4c3d023ab11b8b2871f219530b99efa5", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-03-30T12:24:06.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-30T12:24:06.000Z", "avg_line_length": 34.7428571429, "max_line_length": 79, "alphanum_fraction": 0.5550986842, "num_tokens": 634, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391602943619, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.6687687986531414}} {"text": " PROGRAM LA_SSYEV_EXAMPLE\n\n! -- LAPACK95 EXAMPLE DRIVER ROUTINE (VERSION 1.0) --\n! UNI-C, DENMARK\n! DECEMBER, 1999\n!\n! .. \"Use Statements\" ..\n USE LA_PRECISION, ONLY: WP => SP\n USE F95_LAPACK, ONLY: LA_SYEV, LA_SYEVD\n! .. \"Implicit Statement\" ..\n IMPLICIT NONE\n! .. \"Local Scalars\" ..\n INTEGER :: I, J, INFO, N\n! .. \"Local Arrays\" ..\n REAL(WP), ALLOCATABLE :: A(:,:), AA(:,:), W(:)\n! .. \"Executable Statements\" ..\n WRITE (*,*) 'LA_SYEV Example Program Results'\n N = 5\n ALLOCATE( A(N,N), AA(N,N), W(N) )\n\n OPEN(UNIT=21,FILE='syev.ma',STATUS='UNKNOWN')\n DO J=1,N\n DO I=1,N \n READ(21,*) A(I,J)\n ENDDO\n ENDDO \n CLOSE(21)\n \n AA=TRANSPOSE(A)\n\n WRITE(*,*)'Matrix A:'\n DO I=1,N; \n WRITE(*,\"(5(F9.5))\") A(I,:); \n ENDDO\n \n WRITE(*,*) 'CALL LA_SYEV( A, W )'\n CALL LA_SYEV( A, W)\n WRITE(*,*) 'W on exit : '\n DO I=1,N\n WRITE(*,\"(5(F10.5))\") W(I)\n ENDDO\n\n WRITE(*,*)\n WRITE(*,*)' * EXAMPLE 2 * '\n\n WRITE(*,*)'Matrix A:'\n DO I=1,N; \n WRITE(*,\"(5(F9.5))\") AA(I,:); \n ENDDO\n\n WRITE(*,*) \"CALL LA_SYEVD( A, W, 'V', 'L', INFO )\"\n CALL LA_SYEVD( AA, W, 'V', 'L', INFO )\n\n WRITE(*,*) 'A on exit : '\n DO I=1,N; \n WRITE(*,\"(5(E14.6))\") AA(I,:); \n ENDDO\n\n WRITE(*,*) 'W on exit : '\n DO I=1,N\n WRITE(*,\"(5(F10.5))\") W(I)\n ENDDO\n\n WRITE(*,*) ' INFO = ', INFO\n\n END PROGRAM LA_SSYEV_EXAMPLE\n", "meta": {"hexsha": "b11ee069ad3173cbe65844e83757dbf25168f9d7", "size": 1534, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "EXAMPLES1/la_syev_example.f90", "max_stars_repo_name": "MattBurn/LAPACK95", "max_stars_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-12-29T15:07:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T10:09:22.000Z", "max_issues_repo_path": "EXAMPLES1/la_syev_example.f90", "max_issues_repo_name": "MattBurn/LAPACK95", "max_issues_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-12-30T15:38:47.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-31T06:45:11.000Z", "max_forks_repo_path": "EXAMPLES1/la_syev_example.f90", "max_forks_repo_name": "MattBurn/LAPACK95", "max_forks_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-12-29T15:34:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-15T07:12:40.000Z", "avg_line_length": 22.8955223881, "max_line_length": 56, "alphanum_fraction": 0.4530638853, "num_tokens": 557, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737807, "lm_q2_score": 0.7745833737577159, "lm_q1q2_score": 0.668768786127597}} {"text": "subroutine mg_error(phi_prev, phi, nx, ny, xi, xf, error_phi)\nuse kind_parameters\nimplicit none\n\ninteger, intent(in):: nx, ny, xi, xf\nreal(kind=dp), intent(in), dimension(nx,xi-1:xf+1):: phi_prev, phi\nreal(kind=dp), intent(out), dimension(nx,xi-1:xf+1):: error_phi\ninteger:: i, j\n\n! Calculate the residual r = f - Au, where u is the guessed value\n! Input\n! u Matrix for variables\n! f Right Hand Side\n! hx grid spacing in x direction\n! hy grid spacing in y direction\n!\n! Output\n! r Residual\n\n! Author: Pratanu Roy\n! History:\n! First Written: July 20, 2012\n! Modified: Feb 11, 2013\n\ndo j = xi,xf\n\n do i = 2,nx-1\n\n error_phi(i,j) = phi(i,j) - phi_prev(i,j)\n\n end do\n\nend do\n\ncall exchange_data(error_phi, nx, xi, xf)\n\nend subroutine\n", "meta": {"hexsha": "be8853e70878c208d8f6b4d04cb92098614eb464", "size": 766, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mg_error.f90", "max_stars_repo_name": "pratanuroy/Multigrid_Cavity", "max_stars_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-09-11T12:01:52.000Z", "max_stars_repo_stars_event_max_datetime": "2017-09-11T12:01:52.000Z", "max_issues_repo_path": "mg_error.f90", "max_issues_repo_name": "pratanuroy/Multigrid_Cavity", "max_issues_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "mg_error.f90", "max_forks_repo_name": "pratanuroy/Multigrid_Cavity", "max_forks_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.1578947368, "max_line_length": 66, "alphanum_fraction": 0.6605744125, "num_tokens": 245, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424217727027, "lm_q2_score": 0.7905303285397349, "lm_q1q2_score": 0.6687431406096737}} {"text": "c======================================================================\n function bilinearintegral(xim,xip,yjm,yjp,x1,x2,y1,y2,dxx,dyy,\n & z11,z12,z21,z22)\nc======================================================================\n\n implicit none\n\n* !i/o\n double precision xim,xip,yjm,yjp,x1,x2,y1,y2,dxx,dyy,\n & z11,z12,z21,z22\n double precision bilinearintegral\n\n* !local\n double precision xlow,ylow,xhi,yhi,area,sumxi,sumeta,a,b,c,d\n\nc#######################################################################\nc\nc bilinearintegral integrates the bilinear with values z##\nc over the rectangular region xim <= x <= xip, and\nc yjm <= y <= yjp\n\nc written by David L George\nc Vancouver, WA April 2010\nc#######################################################################\n\n\n\n* !integrate the portion of the bilinear intersected with the\nc !rectangular cell analytically.\n\nc !find limits of integral (this should already be true?)\n xlow = max(xim,x1)\n ylow = max(yjm,y1)\n xhi = min(xip,x2)\n yhi = min(yjp,y2)\n\n* !find the area of integration\n area = (yhi-ylow)*(xhi-xlow)\n sumxi = (xhi + xlow - 2.d0*x1)/dxx\n sumeta = (yhi + ylow - 2.d0*y1)/dyy\n\n* !find coefficients of bilinear a*xi + b*eta + c*xi*eta + d\n a = z21-z11\n b = z12-z11\n c = z22-z21-z12+z11\n d = z11\n\n bilinearintegral = (0.5d0*(a*sumxi + b*sumeta)\n & + 0.25d0*c*sumxi*sumeta + d)*area\n\n return\n\n end function\n\n\nc======================================================================\n function bilinearintegral_s(xim,xip,yjm,yjp,x1,x2,y1,y2,dxx,dyy,\n & z11,z12,z21,z22)\nc======================================================================\n\n use geoclaw_module, only: r2d => rad2deg, d2r => deg2rad\n use geoclaw_module, only: Rearth => earth_radius\n\n implicit none\n\n* !i/o\n double precision xim,xip,yjm,yjp,x1,x2,y1,y2,dxx,dyy,\n & z11,z12,z21,z22\n double precision bilinearintegral_s\n\n* !local\n double precision xlo,ylo,xhi,yhi,delx,dely,a,b,c,d\n double precision xdiffhi,xdifflo,ydiffhi,ydifflo,xdiff2\n double precision adsinint,cbsinint\n\nc#######################################################################\nc\nc bilinearintegral integrates the bilinear with values z##\nc over the rectangular region xim <= x <= xip, and\nc yjm <= y <= yjp\nc integration is actually done on the surface of a sphere\n\nc written by David L George\nc Vancouver, WA April 2010\nc#######################################################################\n\n\n\n* !integrate the portion of the bilinear intersected with the\nc !rectangular cell analytically.\nc !find limits of integral (this should already be true?)\n xlo = max(xim,x1)\n ylo = max(yjm,y1)\n xhi = min(xip,x2)\n yhi = min(yjp,y2)\n delx = xhi - xlo\n dely = yhi - ylo\n\n* !find terms for the integration\n xdiffhi = xhi - x1\n xdifflo = xlo - x1\n ydiffhi = yhi - y1\n ydifflo = ylo - y1\n xdiff2 = 0.5d0*(xdiffhi**2 - xdifflo**2)\n\n cbsinint = (r2d*cos(d2r*yhi) + ydiffhi*sin(d2r*yhi))\n & -(r2d*cos(d2r*ylo) + ydifflo*sin(d2r*ylo))\n\n adsinint = r2d*(sin(d2r*yhi) - sin(d2r*ylo))\n\n\n* !find coefficients of bilinear a*xi + b*eta + c*xi*eta + d\n a = (z21-z11)/dxx\n b = (z12-z11)/dyy\n c = (z22-z21-z12+z11)/(dxx*dyy)\n d = z11\n\n bilinearintegral_s = ((a*xdiff2 + d*delx)*adsinint\n & + r2d*(c*xdiff2 + b*delx)*cbsinint)*(Rearth*d2r)**2\n\n return\n\n end function\n", "meta": {"hexsha": "c0e650ecd497e0fcdf5277085ef4e396487a6e6a", "size": 4044, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/2d/shallow/bilinearintegral.f", "max_stars_repo_name": "AsianHam/geoclaw", "max_stars_repo_head_hexsha": "b5f9ee8cd6e64d107ba8bba1e6d588aa7bf6d417", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 51, "max_stars_repo_stars_event_min_datetime": "2015-07-01T13:39:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T16:13:17.000Z", "max_issues_repo_path": "src/2d/shallow/bilinearintegral.f", "max_issues_repo_name": "AsianHam/geoclaw", "max_issues_repo_head_hexsha": "b5f9ee8cd6e64d107ba8bba1e6d588aa7bf6d417", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 274, "max_issues_repo_issues_event_min_datetime": "2015-02-20T18:25:04.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-09T23:51:47.000Z", "max_forks_repo_path": "src/2d/shallow/bilinearintegral.f", "max_forks_repo_name": "BrisaDavis/geoclaw", "max_forks_repo_head_hexsha": "ccab58669bc2950de13cf0f35c10b3cd1cb1cda6", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 66, "max_forks_repo_forks_event_min_datetime": "2015-01-10T00:05:00.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-24T22:05:16.000Z", "avg_line_length": 32.6129032258, "max_line_length": 72, "alphanum_fraction": 0.4579624135, "num_tokens": 1115, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513814471134, "lm_q2_score": 0.7461390043208003, "lm_q1q2_score": 0.6687281133740909}} {"text": "!======================================================================!\n REAL FUNCTION DistR(rA,zA,rB,zB)\n!----------------------------------------------------------------------!\n! Calculates distance between two points. !\n!----------------------------------------------------------------------!\n IMPLICIT NONE\n!-----------------------------[Parameters]-----------------------------!\n REAL :: rA,zA,rB,zB\n!--------------------------------[CVS]---------------------------------!\n! $Id: Dist.f90,v 1.5 2002/10/30 16:29:31 niceno Exp $ \n! $Source: /home/muhamed/.CVSROOT/T-Rex/Library/Dist.f90,v $ \n!======================================================================!\n\n DistR=sqrt( (rA-rB)*(rA-rB) + (zA-zB)*(zA-zB) )\n\n END FUNCTION DistR\n", "meta": {"hexsha": "3bf7df14302b7bd00ca9412dee333d1de4b08ae5", "size": 779, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Library/DistR.f90", "max_stars_repo_name": "palkinev/T-FlowS-old-compressible", "max_stars_repo_head_hexsha": "7aa7219aa5526ac270b39d52ba8c12847e1d71a2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Library/DistR.f90", "max_issues_repo_name": "palkinev/T-FlowS-old-compressible", "max_issues_repo_head_hexsha": "7aa7219aa5526ac270b39d52ba8c12847e1d71a2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Library/DistR.f90", "max_forks_repo_name": "palkinev/T-FlowS-old-compressible", "max_forks_repo_head_hexsha": "7aa7219aa5526ac270b39d52ba8c12847e1d71a2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.8235294118, "max_line_length": 72, "alphanum_fraction": 0.2759948652, "num_tokens": 165, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.7461390043208003, "lm_q1q2_score": 0.6687281113064172}} {"text": "PROGRAM test_sinc\r\n!\r\n! Purpose:\r\n! To test the sinc function sinc(x)\r\n!\r\nIMPLICIT NONE\r\n\r\n! Data dictionary: declare function types\r\nREAL :: sinc ! sinc function\r\n\r\n! Data dictionary: declare variable types & definitions\r\nREAL :: x ! Input value to evaluate\r\n\r\n! Get value to evaluate\r\nWRITE (*,*) 'Enter x: '\r\nREAD (*,*) x\r\n \r\n! Write answer.\r\nWRITE (*,'(1X,A,F8.5)') 'sinc(x) = ', sinc(x)\r\n \r\nEND PROGRAM test_sinc\r\n", "meta": {"hexsha": "f00da1d3097f356356f92757ea2280469de34221", "size": 450, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap7/test_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/test_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/test_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": 20.4545454545, "max_line_length": 56, "alphanum_fraction": 0.6, "num_tokens": 117, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. Yes\n2. Yes", "lm_q1_score": 0.7461390043208003, "lm_q2_score": 0.8962513738264114, "lm_q1q2_score": 0.668728107687988}} {"text": " subroutine toFourier\n use fourier_lib\n implicit none\nc\nc Do Fourier transform integrations needed to convert data on a\nc theta, zeta grid [stored in array f(i=1,nznt)] to a set\nc of Fourier amplitudes [stored in array fnm(mn=1,mnmx)].\nc Typically, the number of grid points in each direction needs\nc to be > 3*number of modes used in each direction to avoid\nc aliasing errors(implies nznt > 9*mnmx).\nc \nc do mn=1,mnmx !loop over Fourier modes\nc fnm(mn) = 0.\nc do i=1,nznt !loop over theta,zeta grid\nc if(sin_type .eq. 1 .and. cos_type .eq. 0) then\nc fnm(mn) = fnm(mn) + f(i)*sin_toF(i,mn)\nc else if(sin_type .eq. 0 .and. cos_type .eq. 1) then\nc fnm(mn) = fnm(mn) + f(i)*cos_toF(i,mn)\nc endif\nc end do\nc end do\nc\n if(sin_type .eq. 1 .and. cos_type .eq. 0) then\n fnm = matmul(f,sin_toF)\n else if(sin_type .eq. 0 .and. cos_type .eq. 1) then\n fnm = matmul(f,cos_toF)\n endif\nc\n return\n end\nc\n subroutine old_toFourier\n use fourier_lib\n implicit none\n real(kind=rprec) dum,dnorm\nc\nc Do Fourier transform integrations needed to convert data on a\nc theta, zeta grid [stored in array f(i=1,nznt)] to a set\nc of Fourier amplitudes [stored in array fnm(mn=1,mnmx)].\nc Typically, the number of grid points in each direction needs\nc to be > 3*number of modes used in each direction to avoid\nc aliasing errors(implies nznt > 9*mnmx).\nc \n do mn=1,mnmx !loop over Fourier modes\n fnm(mn) = 0.\nc dnorm = 2.*real(nfp)/real(nznt)\n dnorm = 2./real(nznt)\n dum = abs(rn(mn)) + abs(rm(mn))\n if(nint(dum) .eq. 0) dnorm = .5*dnorm\n do i=1,nznt !loop over theta,zeta grid\nc arg = -rn(mn)*ztgrd(i) + rm(mn)*thtgrd(i)\n if(sin_type .eq. 1 .and. cos_type .eq. 0) then\n fnm(mn) = fnm(mn) + f(i)*sin_ar(i,mn)*dnorm\n else if(sin_type .eq. 0 .and. cos_type .eq. 1) then\n fnm(mn) = fnm(mn) + f(i)*cos_ar(i,mn)*dnorm\n endif\n end do\n end do\nc\n return\n end\nc\n subroutine toReal\nc\nc Convert Fourier mode representation [stored in array anm(mn=1,mnmx)]\nc to values of function on a regularly spaced 2D grid\nc [stored in array f(i=1,nznt)].\nc\n use fourier_lib\n implicit none\n do i=1,nznt\n f(i) = 0.\n do mn=1,mnmx\n if(sin_type .eq. 1 .and. cos_type .eq. 0) then\n f(i) = f(i) + anm(mn)*sin_ar(i,mn)\n else if(sin_type .eq. 0 .and. cos_type .eq. 1) then\n f(i) = f(i) + anm(mn)*cos_ar(i,mn)\n endif\n end do\n end do\n end\nc\nc\nc\n subroutine dbydth\nc\nc Take the theta derivative of the input Fourier amplitude array, fnm\nc and place the result in the output Fourier amplitude array, anm.\nc Changes to the sin/cos parity are reflected through the sin_type and\nc cos_type variables.\nc\n use fourier_lib\n implicit none\n do i=1,mnmx\n if(sin_type .eq. 1 .and. cos_type .eq. 0) then\n anm(i) = rm(i)*fnm(i)\n else if(sin_type .eq. 0 .and. cos_type .eq. 1) then\n anm(i) = -rm(i)*fnm(i)\n endif\n end do\n if(sin_type .eq. 1 .and. cos_type .eq. 0) then\n sin_type = 0; cos_type = 1\n else if(sin_type .eq. 0 .and. cos_type .eq. 1) then\n sin_type = 1; cos_type = 0\n endif\n end\nc\nc\nc\n subroutine dbydzt\nc\nc Take the zeta derivative of the input Fourier amplitude array, fnm\nc and place the result in the output Fourier amplitude array, anm.\nc Changes to the sin/cos parity are reflected through the sin_type and\nc cos_type variables.\nc\n use fourier_lib\n implicit none\n do i=1,mnmx\n if(sin_type .eq. 1 .and. cos_type .eq. 0) then\n anm(i) = -rn(i)*fnm(i)\n else if(sin_type .eq. 0 .and. cos_type .eq. 1) then\n anm(i) = rn(i)*fnm(i)\n endif\n end do\n if(sin_type .eq. 1 .and. cos_type .eq. 0) then\n sin_type = 0; cos_type = 1\n else if(sin_type .eq. 0 .and. cos_type .eq. 1) then\n sin_type = 1; cos_type = 0\n endif\n end\n", "meta": {"hexsha": "f94015fae8fe20e6e0d9f71c4c642032c79208b4", "size": 4185, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Fourier_lib_convolve.f", "max_stars_repo_name": "ORNL-Fusion/Stellgap", "max_stars_repo_head_hexsha": "7e50e23ef72da138ee92f309dc59abb0c0b113a5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-09-19T08:02:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-02T18:08:25.000Z", "max_issues_repo_path": "Fourier_lib_convolve.f", "max_issues_repo_name": "ORNL-Fusion/Stellgap", "max_issues_repo_head_hexsha": "7e50e23ef72da138ee92f309dc59abb0c0b113a5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fourier_lib_convolve.f", "max_forks_repo_name": "ORNL-Fusion/Stellgap", "max_forks_repo_head_hexsha": "7e50e23ef72da138ee92f309dc59abb0c0b113a5", "max_forks_repo_licenses": ["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.7045454545, "max_line_length": 73, "alphanum_fraction": 0.590442055, "num_tokens": 1444, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513703624557, "lm_q2_score": 0.7461389986757758, "lm_q1q2_score": 0.6687281000440346}} {"text": " subroutine dnherm2(x,nx,y,ny,fherm,nf2,ilinx,iliny,ier)\nC\nC create a data set for Hermite interpolation, based on simple\nC numerical differentiation using the given grid. The grid should\nC be \"approximately\" evenly spaced.\nC\nC 2d routine\nC\nC input:\nC\nC nf2.gt.nx expected!\nC\n integer nx,ny,nf2 ! array dimensions\n real x(nx) ! x coordinate array\n real y(ny) ! y coordinate array\n real fherm(0:3,nf2,ny) ! data/Hermite array\nC\nC fherm(0,i,j) = function value f at x(i),y(j) **on input**\nC\nC fherm(1,i,j) = derivative df/dx at x(i),y(j) **on output**\nC fherm(2,i,j) = derivative df/dy at x(i),y(j) **on output**\nC fherm(3,i,j) = derivative d2f/dxdy at x(i),y(j) **on output**\nC\nC addl output:\nC ilinx=1 if x axis is evenly spaced\nC iliny=1 if y axis is evenly spaced\nC ier=0 if no error:\nC x, y must both be strict ascending\nC nf2.ge.nx is required.\nC\nC----------------------------\nc\n ier=0\nc\n call splinck(x,nx,ilinx,1.0e-3,ierx)\n if(ierx.ne.0) ier=2\nc\n if(ier.eq.2) then\n write(6,'('' ?dnherm2: x axis not strict ascending'')')\n endif\nc\n call splinck(y,ny,iliny,1.0e-3,iery)\n if(iery.ne.0) ier=3\nc\n if(ier.eq.3) then\n write(6,'('' ?dnherm2: y axis not strict ascending'')')\n endif\nc\n if(nf2.lt.nx) then\n ier=4\n write(6,*) '?dnherm2: fherm array dimension too small.'\n endif\nC\n if(ier.ne.0) return\nC\n do iy=1,ny\nc\n iyp=min(ny,iy+1)\n iym=max(1,iy-1)\nc\n do ix=1,nx\nc\n ixp=min(nx,ix+1)\n ixm=max(1,ix-1)\nc\nc x diffs in vicinity\nc\n zd=(fherm(0,ixp,iy)-fherm(0,ixm,iy))/(x(ixp)-x(ixm))\nc\n fherm(1,ix,iy)=zd\nc\nc y diffs in vicinity\nc\n zd=(fherm(0,ix,iyp)-fherm(0,ix,iym))/(y(iyp)-y(iym))\nc\n fherm(2,ix,iy)=zd\nc\nc xy cross derivs (except at corners, iedge=2)\nc\n fherm(3,ix,iy)=(fherm(0,ixp,iyp)-fherm(0,ixm,iyp)\n > -fherm(0,ixp,iym)+fherm(0,ixm,iym))/\n > ((x(ixp)-x(ixm))*(y(iyp)-y(iym)))\nc\n enddo\n enddo\nC\n return\n end\n", "meta": {"hexsha": "86e635a91ef0bf2ed39121eff902c31aa20494c1", "size": 2196, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gfile_Bfield/PSPLINE/Pspline/dnherm2.f", "max_stars_repo_name": "ORNL-Fusion/RFSciDAC-testing", "max_stars_repo_head_hexsha": "c2fa44e00ce8e0af4be6fa662a9e8c94d6c6f60e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2020-05-08T01:47:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T10:35:28.000Z", "max_issues_repo_path": "gfile_Bfield/PSPLINE/Pspline/dnherm2.f", "max_issues_repo_name": "ORNL-Fusion/RFSciDAC-testing", "max_issues_repo_head_hexsha": "c2fa44e00ce8e0af4be6fa662a9e8c94d6c6f60e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 77, "max_issues_repo_issues_event_min_datetime": "2020-05-08T07:18:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:20:33.000Z", "max_forks_repo_path": "gfile_Bfield/PSPLINE/Pspline/dnherm2.f", "max_forks_repo_name": "ORNL-Fusion/RFSciDAC-testing", "max_forks_repo_head_hexsha": "c2fa44e00ce8e0af4be6fa662a9e8c94d6c6f60e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-02-10T13:47:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T12:53:43.000Z", "avg_line_length": 24.6741573034, "max_line_length": 67, "alphanum_fraction": 0.5450819672, "num_tokens": 848, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.7461389873857264, "lm_q1q2_score": 0.6687280961283338}} {"text": " SUBROUTINE MB02SD( N, H, LDH, IPIV, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute an LU factorization of an n-by-n upper Hessenberg\nC matrix H using partial pivoting with row interchanges.\nC\nC ARGUMENTS\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The order of the matrix H. N >= 0.\nC\nC H (input/output) DOUBLE PRECISION array, dimension (LDH,N)\nC On entry, the n-by-n upper Hessenberg matrix to be\nC factored.\nC On exit, the factors L and U from the factorization\nC H = P*L*U; the unit diagonal elements of L are not stored,\nC and L is lower bidiagonal.\nC\nC LDH INTEGER\nC The leading dimension of the array H. LDH >= max(1,N).\nC\nC IPIV (output) INTEGER array, dimension (N)\nC The pivot indices; for 1 <= i <= N, row i of the matrix\nC was interchanged with row IPIV(i).\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value;\nC > 0: if INFO = i, U(i,i) is exactly zero. The\nC factorization has been completed, but the factor U\nC is exactly singular, and division by zero will occur\nC if it is used to solve a system of equations.\nC\nC METHOD\nC\nC The factorization has the form\nC H = P * L * U\nC where P is a permutation matrix, L is lower triangular with unit\nC diagonal elements (and one nonzero subdiagonal), and U is upper\nC triangular.\nC\nC This is the right-looking Level 1 BLAS version of the algorithm\nC (adapted after DGETF2).\nC\nC REFERENCES\nC\nC -\nC\nC NUMERICAL ASPECTS\nC 2\nC The algorithm requires 0( N ) operations.\nC\nC CONTRIBUTOR\nC\nC V. Sima, Katholieke Univ. Leuven, Belgium, June 1998.\nC\nC REVISIONS\nC\nC V. Sima, Research Institute for Informatics, Bucharest, Oct. 2000,\nC Jan. 2005.\nC\nC KEYWORDS\nC\nC Hessenberg form, matrix algebra.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO\n PARAMETER ( ZERO = 0.0D+0 )\nC .. Scalar Arguments ..\n INTEGER INFO, LDH, N\nC .. Array Arguments ..\n INTEGER IPIV(*)\n DOUBLE PRECISION H(LDH,*)\nC .. Local Scalars ..\n INTEGER J, JP\nC .. External Subroutines ..\n EXTERNAL DAXPY, DSWAP, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC ABS, MAX\nC ..\nC .. Executable Statements ..\nC\nC Check the scalar input parameters.\nC\n INFO = 0\n IF( N.LT.0 ) THEN\n INFO = -1\n ELSE IF( LDH.LT.MAX( 1, N ) ) THEN\n INFO = -3\n END IF\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'MB02SD', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF( N.EQ.0 )\n $ RETURN\nC\n DO 10 J = 1, N\nC\nC Find pivot and test for singularity.\nC\n JP = J\n IF ( J.LT.N ) THEN\n IF ( ABS( H( J+1, J ) ).GT.ABS( H( J, J ) ) )\n $ JP = J + 1\n END IF\n IPIV( J ) = JP\n IF( H( JP, J ).NE.ZERO ) THEN\nC\nC Apply the interchange to columns J:N.\nC\n IF( JP.NE.J )\n $ CALL DSWAP( N-J+1, H( J, J ), LDH, H( JP, J ), LDH )\nC\nC Compute element J+1 of J-th column.\nC\n IF( J.LT.N )\n $ H( J+1, J ) = H( J+1, J )/H( J, J )\nC\n ELSE IF( INFO.EQ.0 ) THEN\nC\n INFO = J\n END IF\nC\n IF( J.LT.N ) THEN\nC\nC Update trailing submatrix.\nC\n CALL DAXPY( N-J, -H( J+1, J ), H( J, J+1 ), LDH,\n $ H( J+1, J+1 ), LDH )\n END IF\n 10 CONTINUE\n RETURN\nC *** Last line of MB02SD ***\n END\n", "meta": {"hexsha": "34ebb81e2be947d8e811ece7d99699de667abb96", "size": 3994, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB02SD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB02SD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB02SD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 26.4503311258, "max_line_length": 72, "alphanum_fraction": 0.5185277917, "num_tokens": 1224, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8962513814471132, "lm_q2_score": 0.7461389817407016, "lm_q1q2_score": 0.6687280931366462}} {"text": "*> \\brief \\b CGLMTS\n*\n* =========== DOCUMENTATION ===========\n*\n* Online html documentation available at \n* http://www.netlib.org/lapack/explore-html/ \n*\n* Definition:\n* ===========\n*\n* SUBROUTINE CGLMTS( N, M, P, A, AF, LDA, B, BF, LDB, D, DF,\n* X, U, WORK, LWORK, RWORK, RESULT )\n* \n* .. Scalar Arguments ..\n* INTEGER LDA, LDB, LWORK, M, P, N\n* REAL RESULT\n* ..\n* .. Array Arguments ..\n* REAL RWORK( * )\n* COMPLEX A( LDA, * ), AF( LDA, * ), B( LDB, * ),\n* $ BF( LDB, * ), D( * ), DF( * ), U( * ),\n* $ WORK( LWORK ), X( * )\n* \n*\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*>\n*> CGLMTS tests CGGGLM - a subroutine for solving the generalized\n*> linear model problem.\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in] N\n*> \\verbatim\n*> N is INTEGER\n*> The number of rows of the matrices A and B. N >= 0.\n*> \\endverbatim\n*>\n*> \\param[in] M\n*> \\verbatim\n*> M is INTEGER\n*> The number of columns of the matrix A. M >= 0.\n*> \\endverbatim\n*>\n*> \\param[in] P\n*> \\verbatim\n*> P is INTEGER\n*> The number of columns of the matrix B. P >= 0.\n*> \\endverbatim\n*>\n*> \\param[in] A\n*> \\verbatim\n*> A is COMPLEX array, dimension (LDA,M)\n*> The N-by-M matrix A.\n*> \\endverbatim\n*>\n*> \\param[out] AF\n*> \\verbatim\n*> AF is COMPLEX array, dimension (LDA,M)\n*> \\endverbatim\n*>\n*> \\param[in] LDA\n*> \\verbatim\n*> LDA is INTEGER\n*> The leading dimension of the arrays A, AF. LDA >= max(M,N).\n*> \\endverbatim\n*>\n*> \\param[in] B\n*> \\verbatim\n*> B is COMPLEX array, dimension (LDB,P)\n*> The N-by-P matrix A.\n*> \\endverbatim\n*>\n*> \\param[out] BF\n*> \\verbatim\n*> BF is COMPLEX array, dimension (LDB,P)\n*> \\endverbatim\n*>\n*> \\param[in] LDB\n*> \\verbatim\n*> LDB is INTEGER\n*> The leading dimension of the arrays B, BF. LDB >= max(P,N).\n*> \\endverbatim\n*>\n*> \\param[in] D\n*> \\verbatim\n*> D is COMPLEX array, dimension( N )\n*> On input, the left hand side of the GLM.\n*> \\endverbatim\n*>\n*> \\param[out] DF\n*> \\verbatim\n*> DF is COMPLEX array, dimension( N )\n*> \\endverbatim\n*>\n*> \\param[out] X\n*> \\verbatim\n*> X is COMPLEX array, dimension( M )\n*> solution vector X in the GLM problem.\n*> \\endverbatim\n*>\n*> \\param[out] U\n*> \\verbatim\n*> U is COMPLEX array, dimension( P )\n*> solution vector U in the GLM problem.\n*> \\endverbatim\n*>\n*> \\param[out] WORK\n*> \\verbatim\n*> WORK is COMPLEX array, dimension (LWORK)\n*> \\endverbatim\n*>\n*> \\param[in] LWORK\n*> \\verbatim\n*> LWORK is INTEGER\n*> The dimension of the array WORK.\n*> \\endverbatim\n*>\n*> \\param[out] RWORK\n*> \\verbatim\n*> RWORK is REAL array, dimension (M)\n*> \\endverbatim\n*>\n*> \\param[out] RESULT\n*> \\verbatim\n*> RESULT is REAL\n*> The test ratio:\n*> norm( d - A*x - B*u )\n*> RESULT = -----------------------------------------\n*> (norm(A)+norm(B))*(norm(x)+norm(u))*EPS\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee \n*> \\author Univ. of California Berkeley \n*> \\author Univ. of Colorado Denver \n*> \\author NAG Ltd. \n*\n*> \\date November 2011\n*\n*> \\ingroup complex_eig\n*\n* =====================================================================\n SUBROUTINE CGLMTS( N, M, P, A, AF, LDA, B, BF, LDB, D, DF,\n $ X, U, WORK, LWORK, RWORK, RESULT )\n*\n* -- LAPACK test routine (version 3.4.0) --\n* -- LAPACK is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n* November 2011\n*\n* .. Scalar Arguments ..\n INTEGER LDA, LDB, LWORK, M, P, N\n REAL RESULT\n* ..\n* .. Array Arguments ..\n REAL RWORK( * )\n COMPLEX A( LDA, * ), AF( LDA, * ), B( LDB, * ),\n $ BF( LDB, * ), D( * ), DF( * ), U( * ),\n $ WORK( LWORK ), X( * )\n*\n* ====================================================================\n*\n* .. Parameters ..\n REAL ZERO\n PARAMETER ( ZERO = 0.0E+0 )\n COMPLEX CONE\n PARAMETER ( CONE = 1.0E+0 )\n* ..\n* .. Local Scalars ..\n INTEGER INFO\n REAL ANORM, BNORM, EPS, XNORM, YNORM, DNORM, UNFL\n* ..\n* .. External Functions ..\n REAL SCASUM, SLAMCH, CLANGE\n EXTERNAL SCASUM, SLAMCH, CLANGE\n* ..\n* .. External Subroutines ..\n EXTERNAL CLACPY\n*\n* .. Intrinsic Functions ..\n INTRINSIC MAX\n* ..\n* .. Executable Statements ..\n*\n EPS = SLAMCH( 'Epsilon' )\n UNFL = SLAMCH( 'Safe minimum' )\n ANORM = MAX( CLANGE( '1', N, M, A, LDA, RWORK ), UNFL )\n BNORM = MAX( CLANGE( '1', N, P, B, LDB, RWORK ), UNFL )\n*\n* Copy the matrices A and B to the arrays AF and BF,\n* and the vector D the array DF.\n*\n CALL CLACPY( 'Full', N, M, A, LDA, AF, LDA )\n CALL CLACPY( 'Full', N, P, B, LDB, BF, LDB )\n CALL CCOPY( N, D, 1, DF, 1 )\n*\n* Solve GLM problem\n*\n CALL CGGGLM( N, M, P, AF, LDA, BF, LDB, DF, X, U, WORK, LWORK,\n $ INFO )\n*\n* Test the residual for the solution of LSE\n*\n* norm( d - A*x - B*u )\n* RESULT = -----------------------------------------\n* (norm(A)+norm(B))*(norm(x)+norm(u))*EPS\n*\n CALL CCOPY( N, D, 1, DF, 1 )\n CALL CGEMV( 'No transpose', N, M, -CONE, A, LDA, X, 1, CONE,\n $ DF, 1 )\n*\n CALL CGEMV( 'No transpose', N, P, -CONE, B, LDB, U, 1, CONE,\n $ DF, 1 )\n*\n DNORM = SCASUM( N, DF, 1 )\n XNORM = SCASUM( M, X, 1 ) + SCASUM( P, U, 1 )\n YNORM = ANORM + BNORM\n*\n IF( XNORM.LE.ZERO ) THEN\n RESULT = ZERO\n ELSE\n RESULT = ( ( DNORM / YNORM ) / XNORM ) /EPS\n END IF\n*\n RETURN\n*\n* End of CGLMTS\n*\n END\n", "meta": {"hexsha": "dc5759413cae990a789a0d7276924afa996b7ba6", "size": 6201, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "old/lapack-test/3.5.0/EIG/cglmts.f", "max_stars_repo_name": "haampie/libflame", "max_stars_repo_head_hexsha": "a6b27af9b7ef91ec2724b52c7c09b681379a3470", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 199, "max_stars_repo_stars_event_min_datetime": "2015-02-06T06:05:32.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T05:20:33.000Z", "max_issues_repo_path": "old/lapack-test/3.5.0/EIG/cglmts.f", "max_issues_repo_name": "haampie/libflame", "max_issues_repo_head_hexsha": "a6b27af9b7ef91ec2724b52c7c09b681379a3470", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 44, "max_issues_repo_issues_event_min_datetime": "2015-05-10T18:14:52.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-22T08:22:10.000Z", "max_forks_repo_path": "old/lapack-test/3.5.0/EIG/cglmts.f", "max_forks_repo_name": "haampie/libflame", "max_forks_repo_head_hexsha": "a6b27af9b7ef91ec2724b52c7c09b681379a3470", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 70, "max_forks_repo_forks_event_min_datetime": "2015-02-07T04:53:03.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T05:20:36.000Z", "avg_line_length": 26.164556962, "max_line_length": 76, "alphanum_fraction": 0.463312369, "num_tokens": 1894, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513675912912, "lm_q2_score": 0.7461389930307512, "lm_q1q2_score": 0.6687280929169996}} {"text": "SUBROUTINE p84(input_file,output_file)\n!-------------------------------------------------------------------------\n! Program 8.4 Plane or axisymmetric transient analysis using 4-node\n! rectangular quadrilaterals. Mesh numbered in x(r)- or y(z)-\n! direction. Implicit time integration using the \"theta\"\n! method.\n!-------------------------------------------------------------------------\n USE main\n USE geom\n IMPLICIT NONE\n CHARACTER(len=60),INTENT(IN) :: input_file\n CHARACTER(len=60),INTENT(OUT) :: output_file\n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\n INTEGER::fixed_freedoms,i,iel,j,nci,ndim=2,nels,neq,nip=4,nlen,nn,nod=4, &\n npri,np_types,nres,nstep,ntime,nxe,nye\n REAL(iwp)::det,dtim,one=1.0_iwp,penalty=1.0e20_iwp,theta,time, &\n zero=0.0_iwp\n CHARACTER(len=15)::argv,dir,element='quadrilateral',type_2d\n!-----------------------dynamic arrays------------------------------------\n INTEGER,ALLOCATABLE::etype(:),g_num(:,:),node(:),num(:),kdiag(:)\n REAL(iwp),ALLOCATABLE::bp(:),coord(:,:),der(:,:),deriv(:,:),fun(:), &\n gc(:),g_coord(:,:),jac(:,:),kay(:,:),kc(:,:),kv(:),loads(:),newlo(:), &\n ntn(:,:),mm(:,:),points(:,:),prop(:,:),storbp(:),value(:),weights(:), &\n x_coords(:),y_coords(:)\n!-------------------------input and initialisation------------------------\n \n OPEN(10,FILE=input_file) \n OPEN(11,FILE=output_file)\n READ(10,*)type_2d,dir,nxe,nye,np_types \n CALL mesh_size(element,nod,nels,nn,nxe,nye)\n neq=nn\n ALLOCATE(points(nip,ndim),weights(nip),kay(ndim,ndim),coord(nod,ndim), &\n fun(nod),jac(ndim,ndim),g_coord(ndim,nn),der(ndim,nod),deriv(ndim,nod),&\n mm(nod,nod),g_num(nod,nels),kc(nod,nod),ntn(nod,nod),num(nod), &\n etype(nels),kdiag(neq),loads(0:neq),newlo(0:neq),x_coords(nxe+1), &\n y_coords(nye+1),prop(ndim,np_types),gc(ndim))\n READ(10,*)prop\n etype=1\n if(np_types>1)read(10,*)etype\n READ(10,*)x_coords,y_coords \n READ(10,*)dtim,nstep,theta,npri,nres,ntime\n kdiag=0\n! ----------loop the elements to set up global geometry and kdiag --------\n elements_1: DO iel=1,nels\n CALL geom_rect(element,iel,x_coords,y_coords,coord,num,dir)\n g_num(:,iel)=num\n g_coord(:,num)=TRANSPOSE(coord)\n CALL fkdiag(kdiag,num)\n END DO elements_1\n CALL mesh(g_coord,g_num,argv,nlen,12)\n DO i=2,neq\n kdiag(i)=kdiag(i)+kdiag(i-1)\n END DO\n ALLOCATE(kv(kdiag(neq)),bp(kdiag(neq))) \n WRITE(11,'(2(a,i5))') &\n \" There are\",neq,\" equations and the skyline storage is\",kdiag(neq)\n CALL sample(element,points,weights)\n bp=zero\n kv=zero\n gc=one\n!-----------------------global conductivity and \"mass\" matrix assembly----\n elements_2: DO iel=1,nels\n kay=zero\n DO i=1,ndim\n kay(i,i)=prop(i,etype(iel))\n END DO\n num=g_num(:,iel)\n coord=TRANSPOSE(g_coord(:,num))\n kc=zero\n mm=zero\n gauss_pts: DO i=1,nip\n CALL shape_der(der,points,i)\n CALL shape_fun(fun,points,i)\n jac=MATMUL(der,coord)\n det=determinant(jac)\n CALL invert(jac)\n deriv=MATMUL(jac,der)\n if(type_2d=='axisymmetric')gc=MATMUL(fun,coord)\n kc=kc+MATMUL(MATMUL(TRANSPOSE(deriv),kay),deriv)*det*weights(i)*gc(1)\n CALL cross_product(fun,fun,ntn)\n mm=mm+ntn*det*weights(i)*gc(1)\n END DO gauss_pts\n CALL fsparv(kv,kc,num,kdiag)\n CALL fsparv(bp,mm,num,kdiag)\n END DO elements_2\n kv=kv*theta*dtim\n bp=bp+kv\n kv=bp-kv/theta \n!-----------------------specify initial and boundary values---------------\n READ(10,*)loads(1:)\n loads(0)=zero\n READ(10,*)fixed_freedoms\n IF(fixed_freedoms/=0)then\n ALLOCATE(node(fixed_freedoms),value(fixed_freedoms), &\n storbp(fixed_freedoms))\n READ(10,*)(node(i),value(i),i=1,fixed_freedoms)\n bp(kdiag(node))=bp(kdiag(node))+penalty\n storbp=bp(kdiag(node))\n END IF\n!-----------------------factorise equations-------------------------------\n CALL sparin(bp,kdiag) \n!-----------------------time stepping loop--------------------------------\n WRITE(11,'(/a,i3,a)')\" Time Pressure (node\",nres,\")\"\n WRITE(11,'(2e12.4)')0.0,loads(nres)\n timesteps: DO j=1,nstep\n time=j*dtim\n CALL linmul_sky(kv,loads,newlo,kdiag)\n IF(fixed_freedoms/=0)newlo(node)=storbp*value \n CALL spabac(bp,newlo,kdiag)\n loads=newlo \n IF(nod==4.AND.j==ntime)THEN\n READ(10,*)nci\n CALL contour(loads,g_coord,g_num,nci,argv,nlen,13)\n END IF\n IF(j/npri*npri==j)WRITE(11,'(2e12.4)')time,loads(nres)\n END DO timesteps\n\nEND SUBROUTINE p84\n", "meta": {"hexsha": "6163057573ed5210edb9a922e4bdc5dd37045fbd", "size": 4468, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "subordinates/Transient-Problems/p84.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": "subordinates/Transient-Problems/p84.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": "subordinates/Transient-Problems/p84.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": 37.5462184874, "max_line_length": 75, "alphanum_fraction": 0.5913160251, "num_tokens": 1440, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336202, "lm_q2_score": 0.7461389873857264, "lm_q1q2_score": 0.6687280919929862}} {"text": " SUBROUTINE VECROT(ROTMTX,VECIN,VECOUT)\n IMPLICIT REAL*8 (A-H,O-Z)\nC\nC THIS ROUTINE USES A 3-BY-3 MATRIX TO ROTATE A VECTOR TO ANOTHER\nC VECTOR.\nC\nC VAR DIM TYPE I/O DESCRIPTION\nC --- --- ---- --- -----------\nC\nC ROTMTX 3,3 R*8 I ROTATION MATRIX.\nC\nC VECIN 3 R*8 I VECTOR TO BE ROTATED.\nC\nC VECOUT 3 R*8 O VECTOR RESULTING FROM ROTATION.\nC\nC\nC\nC***********************************************************************\nC\nC CODED BY C PETRUZZO. 6/82.\nC MODIFIED............\nC\nC***********************************************************************\nC\n REAL*8 ROTMTX(3,3),VECIN(3),VECOUT(3),TEMP(3)\nC\n TEMP(1) = ROTMTX(1,1)*VECIN(1) + ROTMTX(1,2)*VECIN(2) +\n 1 ROTMTX(1,3)*VECIN(3)\n TEMP(2) = ROTMTX(2,1)*VECIN(1) + ROTMTX(2,2)*VECIN(2) +\n 1 ROTMTX(2,3)*VECIN(3)\n TEMP(3) = ROTMTX(3,1)*VECIN(1) + ROTMTX(3,2)*VECIN(2) +\n 1 ROTMTX(3,3)*VECIN(3)\nC\n VECOUT(1)=TEMP(1)\n VECOUT(2)=TEMP(2)\n VECOUT(3)=TEMP(3)\nC\n RETURN\n END\n\n", "meta": {"hexsha": "a1d11935419052bffb8aae40b97306277ead42bb", "size": 1067, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "gsc-13083/vecrot.for", "max_stars_repo_name": "SteveDoyle2/nasa-cosmic", "max_stars_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_stars_repo_licenses": ["BSD-Source-Code"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2015-03-14T07:26:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-16T12:23:17.000Z", "max_issues_repo_path": "gsc-13083/vecrot.for", "max_issues_repo_name": "SteveDoyle2/nasa-cosmic", "max_issues_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_issues_repo_licenses": ["BSD-Source-Code"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gsc-13083/vecrot.for", "max_forks_repo_name": "SteveDoyle2/nasa-cosmic", "max_forks_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_forks_repo_licenses": ["BSD-Source-Code"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2016-02-12T22:18:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-08T17:46:54.000Z", "avg_line_length": 26.0243902439, "max_line_length": 72, "alphanum_fraction": 0.458294283, "num_tokens": 421, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513620489619, "lm_q2_score": 0.746138993030751, "lm_q1q2_score": 0.6687280887816516}} {"text": "use std\nimplicit none\n\ntype(IO_) :: f\ntype(Math_) :: math\ninteger(int32) :: num_sampling = 1300 ! =12 : aliasing, =1000: HQ wave\nreal(real64),allocatable :: t(:), Ft(:)\n\n! from t=-100 ~ 100, 1000 sampling\nt = linspace([0.0d0,10.0d0],num_sampling)\n\n! create sampling wave\nFt = zeros(num_sampling)\nFt(:) = sin(2.0d0*Math%PI*t) ! sin( 2*PI*t )\n\n! Export as txt file\ncall f%open(\"sin_wave_hq.txt\",\"w\")\ncall f%write(t,Ft)\ncall f%close()\n\n! show\ncall f%plot(\"sin_wave_hq.txt\",\"with lines\")\n\nend", "meta": {"hexsha": "9df4fb72cd27ffddde40c9c877e917fe1082a8be", "size": 490, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/std/feelAliasing.f90", "max_stars_repo_name": "kazulagi/plantFEM", "max_stars_repo_head_hexsha": "20bf2df8202d41aa5dc25d1cc820385dabbc604f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2020-06-21T08:21:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-13T04:28:30.000Z", "max_issues_repo_path": "Tutorial/std/feelAliasing.f90", "max_issues_repo_name": "kazulagi/plantFEM_binary", "max_issues_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-05-08T05:20:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T05:39:29.000Z", "max_forks_repo_path": "Tutorial/std/feelAliasing.f90", "max_forks_repo_name": "kazulagi/plantFEM_binary", "max_forks_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-10-20T18:28:59.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-15T08:35:25.000Z", "avg_line_length": 20.4166666667, "max_line_length": 70, "alphanum_fraction": 0.6632653061, "num_tokens": 178, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8791467675095294, "lm_q2_score": 0.760650658103136, "lm_q1q2_score": 0.6687235672753682}} {"text": "! ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n! Fluides geophysiques v14 (11.04.96)\n! -------------------------\n! . Red Black\n! . Calcul des vitesses\n! . Sauvegarde tous les X pas de temps\n! ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n! ------------------------------------------------------------------\n\nmodule GEOPHY\n\n integer, parameter :: DP = KIND(1.0D0) !< double precision\n\n real(DP), parameter :: U = 1D-1\n real(DP), parameter :: g = 1D-2\n real(DP), parameter :: f = 1D-4\n\n integer, parameter :: pasx = 31 \n integer, parameter :: pasy = 31\n\nend module GEOPHY \n\n\n! ------------------------------------------------------------------\nsubroutine init_xy(x, y, dx, dy, Ly)\n use GEOPHY\n implicit none\n\n real(DP) :: x(pasx+1), y(pasx+1) !! [RB] taille exacte necessaire sinon ca plante au runtime\n real(DP) :: dx, dy, Ly\n\n integer :: i, j\n\n do i = 2, pasx+1\n print *,\"i=\",i\n x(i) = (i-2)*dx\n end do\n\n x(1) = x(pasx)\n x(2) = x(pasx+1)\n\n do j = 1, pasy \n y(j) = -Ly + (j-1)*dy\n end do\nend subroutine init_xy\n\n! ------------------------------------------------------------------\n\nprogram NIHOUL\n\n use GEOPHY \n implicit none\n\n ! Declarations\n\n integer :: Nmax\n logical :: fin\n integer :: i, j, n, compt, startj, start, nsave, fsave, saveu\n real(DP) :: pi, h0, L, T, Lx, Ly, Bu, Ro, Et, w\n real(DP) :: dx, dy, dt, tol, kmoy\n\n real(DP), allocatable :: x(:), y(:)\n \n real(DP) :: temp1, temp2, temp3, temp4, temp5, erreur\n real(DP) :: d1, d2, d3\n real(DP) :: aeta1, aeta2 \n \n real(DP), allocatable :: eta(:,:), b(:,:), q(:,:)\n real(DP), allocatable :: jacob(:,:), deta(:,:)\n real(DP), allocatable :: leta(:,:), v1(:,:), v2(:,:)\n\n\n ! Donnees\n\n print *, 'L (5000)?'\n read(*,*) L\n print *, 'Lx/L (5)?'\n read(*,*) Lx\n\n pi = acos(-1.0D0)\n h0 = 1D2\n T = L/U\n Ly = min((3.0D0/4.0D0 + g*h0/(2.0D0*f*U*L)), 4.0D0)\n Bu = g*h0/(f*L)**2\n Ro = U/(f*L) \n Et = 1.0D0/(f*T)\n dx = 2.0D0*Lx/(pasx-1) \n dt = dx*dx/2.0D0\n dy = 2.0D0*Ly/(pasy-1)\n kmoy = 0.0D0\n nsave = 1\n\n print *, 'Ly/L =', Ly, '(', (3.0D0/4.0D0 + g*h0/(2.0D0*f*U*L)), ')'\n print *, 'Bu =', Bu, ' ; Ro =', Ro\n print *, 'dx =', dx, ' ; dy =', dy \n print *, 'pasx =', pasx,' ; pasy =', pasy\n print *, 'T =', T, ' ; dH =', f*L*U/g\n print *, 'dt (max) =', dt, 'sec.' \n print *, 'Le canal fait ', 2.0D0*Lx*L, 'm de long'\n print *, ' et ', 2.0D0*Ly*L, 'm de large'\n print *, 'tol (1D-6)?'\n read(*,*) tol\n print *, 'w (1.825)?'\n read(*,*) w\n print *, 'dt (2D-2)?'\n read(*,*) dt\n print *, 'Nmax (100)?'\n read(*,*) Nmax\n print *, 'fsave (Nmax)?'\n read(*,*) fsave\n print *, 'save U (1 = oui)?'\n read(*,*) saveu\n\n if(fsave > Nmax) then\n fsave = Nmax\n endif\n\n print *\n print *, 'Un pas de temps =', T*dt, 'sec.'\n\n\n ! dynamic arrays\n allocate( x(pasx+1) )\n allocate( y(pasx) )\n\n allocate( eta(pasx+1, pasy) )\n allocate( b(pasx+1, pasy) )\n allocate( q(pasx+1, pasy) )\n\n allocate( jacob(pasx+1, pasy) )\n allocate( deta(pasx+1, 2) )\n\n allocate( leta(pasx+1, pasy) )\n allocate( v1(pasx+1, pasy) )\n allocate( v2(pasx+1, pasy) )\n\n ! Calcul du profil initial\n call init_xy(x, y, dx, dy, Ly)\n\n temp1 = g*h0/f/L/U\n do i = 1, pasx+1\n temp2 = 0.01*sin(pi*x(i)/Lx)\n do j = 1, pasy\n if (abs(y(j)) < 1.0D0) then\n eta(i,j) = temp1*temp2 - 0.5*y(j)**2 * (1 + temp2)\n else\n eta(i,j) = temp1*temp2 + (0.5-abs(y(j))) * (1 + temp2)\n endif\n end do\n end do\n\n ! Ouverture du fichier RES.M et sauvegarde du profil initial\n\n open (UNIT = 1, FILE = 'res.m', STATUS ='unknown')\n\n do i = 2, pasx+1\n do j = 1, pasy\n write(1,*) 'a(', (nsave-1)*pasx+i-1, ',', j, ')=', eta(i,j), ';'\n end do\n end do\n\n ! Boucle principale (progression dans le temps)\n\n do n = 1, Nmax\n print *, 'Pas de temps n :', n\n\n ! Calcul de Beta (b) et du laplacien (q)\n\n ! Interieur\n\n do i = 2, pasx\n do j = 2, pasy-1\n temp1 = (eta(i-1,j) + eta(i+1,j) - 2*eta(i,j))/(dx*dx) &\n + (eta(i,j-1) + eta(i,j+1) - 2*eta(i,j))/(dy*dy)\n temp2 = ((eta(i+1,j) - eta(i-1,j))/(2*dx))**2 &\n + ((eta(i,j+1) - eta(i,j-1))/(2*dy))**2\n\n b(i,j) = (Bu+Ro*eta(i,j))*temp1 + Ro/2*temp2\n q(i,j) = temp1\n end do\n end do\n \n ! Bords y\n\n do i = 2, pasx\n j = 1\n temp1 = (eta(i-1,j) + eta(i+1,j) - 2*eta(i,j)) /(dx*dx) &\n + (eta(i,j) + eta(i,j+2) - 2*eta(i,j+1)) /(dy*dy)\n temp2 = (( eta(i+1,j) - eta(i-1,j)) / (2*dx))**2 &\n + ((4*eta(i,j+1) - eta(i,j+2) - 3*eta(i,j)) / (2*dy))**2\n\n b(i,j) = (Bu+Ro*eta(i,j))*temp1 + Ro/2*temp2\n q(i,j) = temp1\n\n j = pasy\n temp1 = (eta(i-1,j) + eta(i+1,j) - 2*eta(i,j)) /(dx*dx) &\n + (eta(i,j) + eta(i,j-2) - 2*eta(i,j-1)) /(dy*dy)\n temp2 = ((eta(i+1,j) - eta(i-1,j))/(2*dx))**2 &\n + ((-4*eta(i,j-1) + eta(i,j-2) + 3*eta(i,j)) / (2*dy))**2\n\n b(i,j) = (Bu+Ro*eta(i,j))*temp1 + Ro/2*temp2\n q(i,j) = temp1\n end do\n \n ! Ajout des lignes i = 1 et i = pasx+1\n\n do j = 1, pasy\n b(1,j) = b(pasx,j)\n b(pasx+1,j) = b(2,j)\n\n q(1,j) = q(pasx,j)\n q(pasx+1,j) = q(2,j)\n end do \n\n ! Calcul du Jacobien\n\n do i = 2, pasx\n do j = 2, pasy-1\n temp1 = ((eta(i+1,j) - eta(i-1,j))*(b(i,j+1) - b(i,j-1)) - &\n (eta(i,j+1) - eta(i,j-1))*(b(i+1,j) - b(i-1,j)))/4/dx/dy\n temp2 = (eta(i+1,j)*(b(i+1,j+1) - b(i+1,j-1)) - eta(i-1,j)* &\n (b(i-1,j+1) - b(i-1,j-1)) - eta(i,j+1)*(b(i+1,j+1) &\n -b(i-1,j+1)) + eta(i,j-1)*(b(i+1,j-1) - b(i-1,j-1))) &\n /4/dx/dy\n temp3 = (b(i,j+1)*(eta(i+1,j+1) - eta(i-1,j+1)) - b(i,j-1)* &\n (eta(i+1,j-1) - eta(i-1,j-1)) - b(i+1,j)*(eta(i+1,j+1) - &\n eta(i+1,j-1)) + b(i-1,j)*(eta(i-1,j+1) - eta(i-1,j-1))) &\n /4/dx/dy\n jacob(i,j) = (temp1 + temp2 + temp3)/3.0D0\n end do\n end do\n \n ! Ajout des lignes i = 1 et i = pasx+1\n \n do j = 1,pasy\n jacob(1,j) = jacob(pasx,j)\n jacob(pasx+1,j) = jacob(2,j)\n end do\n \n ! Calcul de q\n \n do i = 1, pasx+1\n do j = 1, pasy\n q(i,j) = Bu*q(i,j) - eta(i,j) \n q(i,j) = q(i,j) - Ro/Et*dt*jacob(i,j) \n end do\n end do\n\n ! Calcul de d(eta)/dy pour les bords\n\n do i = 1, pasx+1\n deta(i,1) = (4*eta(i,2) - eta(i,3) - 3*eta(i,1)) / (2*dy)\n deta(i,2) = (-4*eta(i,pasy-1) + eta(i,pasy-2) + 3*eta(i,pasy)) / (2*dy)\n end do\n \n ! Red Black\n\n fin = .false.\n compt = 0\n\n do while (fin == 0)\n compt = compt + 1\n fin = .true.\n\n ! Deux passages alternes\n\n do startj = 1, 2\n start = startj\n\n ! Red Black\n\n do i = 2, pasx\n do j = start+1, pasy-1, 2\n temp1 = -2/dx**2 - 2/dy**2 - 1/Bu\n temp1 = (q(i,j)/Bu - (eta(i+1,j) + eta(i-1,j))/dx**2 &\n - (eta(i,j+1) + eta(i,j-1))/dy**2 ) / temp1\n temp1 = eta(i,j) + w*(temp1-eta(i,j))\n if(abs(eta(i,j)) > 0.0D0) then\n erreur = abs( (temp1-eta(i,j))/eta(i,j) )\n if(erreur > tol) then\n fin = .false.\n endif\n endif\n eta(i,j) = temp1 \n end do\n\n if(start == 2) then\n start = 1\n else \n start = 2\n endif\n end do\n\n do j = 1, pasy\n eta(1,j) = eta(pasx,j) \n eta(pasx+1,j) = eta(2,j) \n end do\n\n end do\n\n ! Conditions aux limites\n\n aeta1 = eta(1,1)\n aeta2 = eta(1,pasy)\n\n do i = 2, pasx\n j = 1\n temp1 = (eta(i+1,j) - aeta1) / (2*dx)\n temp2 = (eta(i,j+2) - 2*eta(i,j+1)) / dy**2\n d1 = (eta(i+1,j) - aeta1) / (2*dx)\n d2 = (eta(i+1,j+1) - eta(i-1,j+1))/(2*dx)\n d3 = (eta(i+1,j+2) - eta(i-1,j+2))/(2*dx)\n temp3 = (4*d2 - d3 - 3*d1)/(2*dy) \n temp4 = -3*Et/(2*dy*dt) + 3*Ro*temp3/(2*dy) + Ro*temp1/dy**2\n temp5 = (temp1 -Et*((4*eta(i,j+1) - eta(i,j+2)) / (2*dy*dt) &\n -deta(i,1)/dt) - Ro*temp1*temp2 + Ro*temp3* &\n (4*eta(i,j+1) - eta(i,j+2))/(2*dy) ) / temp4\n temp5 = eta(i,j) + w*(temp5-eta(i,j))\n if(abs(eta(i,j)) > 0.0D0) then\n erreur = abs( (temp5-eta(i,j))/eta(i,j) )\n if(erreur > tol) then\n fin = .false.\n endif\n endif\n aeta1 = eta(i,j)\n eta(i,j) = temp5\n\n j = pasy\n temp1 = (eta(i+1,j) - aeta2) / (2*dx)\n temp2 = (eta(i,j-2) - 2*eta(i,j-1)) / dy**2\n d1 = (eta(i+1,j) - aeta2) / (2*dx)\n d2 = (eta(i+1,j-1) - eta(i-1,j-1)) / (2*dx)\n d3 = (eta(i+1,j-2) - eta(i-1,j-2)) / (2*dx)\n temp3 = (-4*d2 + d3 + 3*d1) / (2*dy) \n temp4 = 3*Et/(2*dy*dt) - 3*Ro*temp3/(2*dy) + Ro*temp1/dy**2\n temp5 = (temp1 - Et*((-4*eta(i,j-1) + eta(i,j-2)) / (2*dy*dt) &\n - deta(i,2)/dt) - Ro*temp1*temp2 + Ro*temp3* &\n (-4*eta(i,j-1) + eta(i,j-2))/(2*dy) ) / temp4\n temp5 = eta(i,j) + w*(temp5-eta(i,j))\n if (abs(eta(i,j)) > 0.0D0) then\n erreur = abs( (temp5-eta(i,j)) / eta(i,j) )\n if (erreur > tol) then\n fin = .false.\n endif\n endif\n aeta2 = eta(i,j)\n eta(i,j) = temp5\n end do\n\n ! Periodicite\n do j = 1, pasy\n eta(1,j) = eta(pasx,j)\n eta(pasx+1,j) = eta(2,j) \n end do\n\n end do \n \n print *, ' no it. =', compt\n kmoy = kmoy + compt\n\n ! Copie de eta (futur calcul des vitesses)\n\n if(n == nsave*fsave-1) then\n do i = 1, pasx+1\n do j = 1, pasy\n leta(i,j) = eta(i,j)\n end do\n end do\n endif\n\n ! Calcul des vitesses\n\n if(saveu == 1) then\n if(n == nsave*fsave) then\n do i = 2, pasx\n do j = 2, pasy-1\n\n ! u (interieur) \n\n temp1 = (eta(i,j+1) - eta(i,j-1))/2/dy\n temp2 = (eta(i+1,j) - eta(i-1,j))/2/dx\n temp3 = (leta(i+1,j) - leta(i-1,j))/2/dx\n temp4 = (eta(i+1,j+1) - eta(i-1,j+1) - eta(i+1,j-1) &\n + eta(i-1,j-1)) / (4*dy*dy)\n temp5 = (eta(i+1,j) + eta(i-1,j) - 2*eta(i,j)) / (dx*dx)\n v1(i,j) = -temp1 - Et*(temp2 - temp3)/dt &\n - Ro*(temp2*temp4 - temp1*temp5)\n\n ! v (interieur) \n\n temp3 = (leta(i,j+1) - leta(i,j-1))/2/dy\n temp5 = (eta(i,j+1) + eta(i,j-1) - 2*eta(i,j))/(dy*dy)\n v2(i,j) = temp2 - Et*(temp1 - temp3)/dt &\n - Ro*(temp2*temp5 - temp1*temp4)\n end do\n\n ! u (j=1) \n j = 1\n temp1 = (4*eta(i,j+1) -eta(i,j+2) - 3*eta(i,j))/2/dy\n temp2 = (eta(i+1,j) - eta(i-1,j))/2/dx\n temp3 = (leta(i+1,j) - leta(i-1,j))/2/dx\n d1 = temp2\n d2 = (eta(i+1,j+1) - eta(i-1,j+1))/(2*dx)\n d3 = (eta(i+1,j+2) - eta(i-1,j+2))/(2*dx)\n temp4 = (4*d2 - d3 - 3*d1)/(2*dy) \n temp5 = (eta(i+1,j) + eta(i-1,j) - 2*eta(i,j))/(dx*dx)\n v1(i,j) = -temp1 - Et*(temp2-temp3)/dt &\n -Ro*(temp2*temp4 - temp1*temp5)\n\n ! v (j=1) \n temp3 = (4*leta(i,j+1) - leta(i,j+2) - 3*leta(i,j))/2/dy \n temp5 = (eta(i,j+2) + eta(i,j) - 2*eta(i,j+1))/(dy*dy)\n v2(i,j) = temp2-Et*(temp1 - temp3)/dt &\n - Ro*(temp2*temp5 - temp1*temp4)\n \n ! u (j=pasy) \n j = pasy\n temp1 = (-4*eta(i,j-1) + eta(i,j-2) + 3*eta(i,j))/2/dy\n temp2 = (eta(i+1,j) - eta(i-1,j))/2/dx\n temp3 = (leta(i+1,j) - leta(i-1,j))/2/dx\n d1 = temp2\n d2 = (eta(i+1,j-1) - eta(i-1,j-1))/(2*dx)\n d3 = (eta(i+1,j-2) - eta(i-1,j-2))/(2*dx)\n temp4 = (-4*d2 + d3 + 3*d1)/(2*dy) \n temp5 = (eta(i+1,j) + eta(i-1,j) - 2*eta(i,j))/(dx*dx)\n v1(i,j) = -temp1 - Et*(temp2 - temp3)/dt &\n - Ro*(temp2*temp4 - temp1*temp5)\n\n ! v (j=pasy) \n temp3 = (-4*leta(i,j-1) + leta(i,j-2) + 3*leta(i,j))/2/dy \n temp5 = (eta(i,j-2) + eta(i,j) - 2*eta(i,j-1))/(dy*dy)\n v2(i,j) = temp2 - Et*(temp1 - temp3)/dt &\n - Ro*(temp2*temp5 - temp1*temp4)\n end do\n\n ! periodicite\n\n do j = 1, pasy\n v1(pasx+1,j) = v1(2,j)\n v2(pasx+1,j) = v2(2,j)\n end do\n endif\n endif\n\n ! Resultats (save -> Matlab)\n\n if(n == nsave*fsave) then \n do i = 2, pasx+1\n do j = 1, pasy\n write(1,*) 'a(', nsave*pasx+i-1, ',', j, ')=', eta(i,j), ';'\n if(saveu == 1) then\n write(1,*) 'u(', nsave*pasx+i-1, ',', j, ')=', v1(i,j), ';'\n write(1,*) 'v(', nsave*pasx+i-1, ',', j, ')=', v2(i,j), ';'\n endif\n end do\n end do\n nsave = nsave + 1\n endif\n\n end do\n\n close (UNIT=1)\n\n ! Commentaires finaux\n print \"('Calcul effectue sur :', F10.1,'s')\", Nmax*T*dt\n print \"('Nb iterations (moy) :', F5.1)\", kmoy/Nmax\n print \"('Resultats dans RES.M')\"\n\n ! free memory\n deallocate( x )\n deallocate( y )\n\n deallocate( eta )\n deallocate( b )\n deallocate( q )\n\n deallocate( jacob )\n deallocate( deta )\n\n deallocate( leta )\n deallocate( v1 )\n deallocate( v2 )\n \nend program NIHOUL\n", "meta": {"hexsha": "cf743b2da4de1142075834d432f91fc6ae13fa7d", "size": 15927, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "student/nihoul/nihoul.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/nihoul/nihoul.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/nihoul/nihoul.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": 32.8391752577, "max_line_length": 98, "alphanum_fraction": 0.354429585, "num_tokens": 5479, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467548438124, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.6687235576411822}} {"text": "! test_genalg.f90 --\n! Test for the genetic_algorithms module\n!\n! Note:\n! The first step (find the minimum for f) does not work as\n! expected, the algorithm gets stuck on a suboptimum (at least\n! with one random sequence). Probably it is necessary to tune\n! the parameters to get a better performance\n! (Intended minimum: (-1.1, 0, 0, ... )\n!\n! The second step does find the absolute minimum, but this is\n! a much simpler function.\n!\nmodule minimize_function\n use select_precision\ncontains\n\nreal(wp) function f( coords )\n real(wp), dimension(:), intent(in) :: coords\n\n real(wp) :: r\n\n r = sqrt( sum(coords**2) )\n f = (r**2 - 1.0) ** 2 - coords(1)\n\nend function f\n\nreal(wp) function g( coords )\n real(wp), dimension(:), intent(in) :: coords\n\n g = sum(coords**2) - 1.0\n\nend function g\n\nend module minimize_function\n\nprogram test_genalg\n use minimize_function\n use genetic_algorithms\n use select_precision\n\n implicit none\n\n type(GA_PARAMETERS) :: params\n integer, parameter :: ncoords = 10\n real(wp), dimension(2,ncoords) :: range\n real(wp), dimension(ncoords) :: vector\n real(wp) :: value\n integer :: i\n\n !\n ! Set the parameters for the procedure\n !\n call set_parameters( params, update = .false., verbose = .true., &\n number_iterations = 1000 )\n\n !\n ! We can use the default procedure, so let's do that\n ! (Otherwise we would use the reversed communication example)\n !\n range(1,:) = -5.0\n range(2,:) = 5.0\n\n call find_minimum( params, range, vector, f, value )\n\n write(*,*) 'Minimum: ',value\n write(*,*) 'Solution vector: ',vector\n write(*,*) 'f(vector): ',f(vector)\n\n call find_minimum( params, range, vector, g, value )\n\n write(*,*) 'Minimum: ',value\n write(*,*) 'Solution vector: ',vector\n write(*,*) 'g(vector): ',g(vector)\n\nend program\n\n\n", "meta": {"hexsha": "bc31b4c15f0b621df17de1ffc395f3ff5616347f", "size": 2020, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/computing/test_genalg.f90", "max_stars_repo_name": "timcera/flibs_from_svn", "max_stars_repo_head_hexsha": "7790369ac1f0ff6e35ef43546446b32446dccc6b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 828, "max_stars_repo_stars_event_min_datetime": "2016-06-20T15:08:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T06:32:10.000Z", "max_issues_repo_path": "flibs-0.9/flibs/tests/computing/test_genalg.f90", "max_issues_repo_name": "TerribleDev/Fortran-docker-mvc", "max_issues_repo_head_hexsha": "0f44d444d9bcc6f4a6c6c59cc53b684c7b9a8e1a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2016-06-27T05:52:31.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-29T20:08:05.000Z", "max_forks_repo_path": "flibs-0.9/flibs/tests/computing/test_genalg.f90", "max_forks_repo_name": "TerribleDev/Fortran-docker-mvc", "max_forks_repo_head_hexsha": "0f44d444d9bcc6f4a6c6c59cc53b684c7b9a8e1a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 46, "max_forks_repo_forks_event_min_datetime": "2016-06-21T02:15:50.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T06:32:39.000Z", "avg_line_length": 25.5696202532, "max_line_length": 70, "alphanum_fraction": 0.5886138614, "num_tokens": 532, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467643431001, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6687235553265888}} {"text": "\r\nmodule mod_coswsamples\r\n#include \"Config.hpp\"\r\n !===================================================================================85\r\n !---------------------------- DESCRIPTION ------------------------------------------85\r\n !\r\n !\r\n !\r\n ! Module name:\r\n ! 'mod_coswsamples'\r\n ! \r\n ! Purpose:\r\n ! Mathematical representation and computation\r\n ! of power weather sample of cosine radar signal.\r\n ! This module also contains subroutines which\r\n ! perform computation of signal statistics.\r\n ! History:\r\n ! Date: 20-10-2017\r\n ! Time: 09:43 GMT+2\r\n !\r\n ! Version:\r\n !\r\n ! Major: 1\r\n ! Minor: 0\r\n ! Micro: 0\r\n !\r\n ! Author: \r\n ! Bernard Gingold\r\n ! \r\n ! References:\r\n ! \r\n ! Doppler Radar and Weather Observations\r\n ! Richard L. Dvorak, Dusan S. Zrnic\r\n ! pages 67-72 \r\n ! \r\n ! \r\n ! E-mail:\r\n ! \r\n ! beniekg@gmail.com\r\n !==================================================================================85\r\n \r\n ! Tab:5 col - Type and etc.. definitions\r\n ! Tab:10,11 col - Type , function and subroutine code blocks.\r\n implicit none\r\n private\r\n use module_kinds\r\n use module_logger, only : log_startup, &\r\n log_UsrMsg, &\r\n log_shutdown\r\n use ISO_FORTRAN_ENV, only : stderr=>ERROR_UNIT , &\r\n stdout=>OUTPUT_UNIT\r\n use IFPORT, only : TRACEBACKQQ\r\n use mod_timer\r\n use mod_constants, only : LAM_PINF\r\n \r\n !=====================================================59\r\n ! File and module information:\r\n ! version,creation and build date, author,description\r\n !=====================================================59\r\n \r\n ! Version major\r\n integer(I32P), parameter :: MOD_COSWSAMPLES_MAJOR = 1\r\n \r\n ! Version minor\r\n integer(I32P), parameter :: MOD_COSWSAMPLES_MINOR = 0\r\n \r\n ! Version micro\r\n integer(I32P), parameter :: MOD_COSWSAMPLES_MICRO = 0\r\n \r\n ! Module full version\r\n integer(I32P), parameter :: MOD_COSWSAMPLES_FULLVER = 1000*MOD_COSWSAMPLES_MAJOR+100*MOD_COSWSAMPLES_MINOR+ &\r\n 10*MOD_COSWSAMPLES_MICRO\r\n \r\n ! Module creation date\r\n character(*), parameter :: MOD_COSWSAMPLES_CREATE_DATE = \"20-10-2017 10:37 +00200 (FRI 20 OCT 2017 GMT+2)\"\r\n \r\n ! Module buiild date (should be set after successful compilation)\r\n character(*), parameter :: MOD_COSWSAMPLES_BUILD_DATE = \" \"\r\n \r\n ! Module author info\r\n character(*), parameter :: MOD_COSWSAMPLES_AUTHOR = \"Programmer: Bernard Gingold e-mail: beniekg@gmail.com\"\r\n \r\n ! Module short description \r\n character(*), parameter :: MOD_COSWSAMPLES_DESCRIPT = \"Weather radar signal power and statistics computation\"\r\n \r\n !============================================50\r\n ! Type: CSWSample_t\r\n !============================================50\r\n\r\n type, public :: CSWSamples_t\r\n \r\n private\r\n \r\n ! Number of (echoes)\r\n integer(I32P) :: m_nechoes\r\n \r\n ! Sample (echo) ID\r\n integer(I32P) :: m_sampID\r\n \r\n ! Complex arrays length\r\n ! Must be equal to m_nechoes\r\n integer(I32P) :: m_size\r\n \r\n ! Number of scatterers\r\n integer(I32P) :: m_scatnum\r\n \r\n ! Time duration of sample\r\n real(R64P) :: m_Ts\r\n \r\n ! Sample = Sigma Ai**2*Wi*exp**-j*4piri/gamma\r\n complex(R64P), allocatable, dimension(:) :: m_Vsamp\r\n \r\n ! Sample averaged over cycle of transmitted frequency\r\n complex(R64P), allocatable, dimension(:) :: m_Vsampavg\r\n \r\n logical(I32P) :: m_isbuilt\r\n \r\n contains\r\n \r\n !==========================================!\r\n ! Construction,copying and destruction. !\r\n !==========================================!\r\n procedure, pass(this), public :: init\r\n \r\n procedure, pass(this), public :: copy\r\n \r\n procedure, pass(this), public :: destroy\r\n \r\n !==========================================!\r\n ! getters !\r\n !==========================================!\r\n \r\n procedure, pass(this), public :: get_nechoes\r\n \r\n procedure, pass(this), public :: get_sampID\r\n \r\n procedure, pass(this), public :: get_size\r\n \r\n procedure, pass(this), public :: get_scatnum\r\n \r\n procedure, pass(this), public :: get_Ts\r\n \r\n procedure, pass(this), public :: get_Vsamp\r\n \r\n procedure, pass(this), public :: get_Vsampavg\r\n \r\n procedure, pass(this), public :: get_isbuilt\r\n \r\n \r\n \r\n !==========================================!\r\n ! Read/write procedures\r\n !==========================================!\r\n \r\n procedure, nopass, public :: read_samples\r\n \r\n procedure, nopass, public :: write_samples\r\n \r\n !==========================================\r\n ! Computational subroutines\r\n !==========================================\r\n \r\n procedure, pass(this), public :: compute_Vsamp\r\n \r\n procedure, pass(this), public :: compute_Vsampavg\r\n \r\n \r\n \r\n end type CSWSamples_t\r\n \r\n !==========================================!\r\n ! Module operators\r\n !==========================================!\r\n \r\n interface assignment (=)\r\n module procedure assign_samples\r\n end interface\r\n \r\n interface operator (/=)\r\n module procedure samples_neq_samples\r\n end interface\r\n \r\n interface operator (==)\r\n module procedure samples_eq_samples\r\n end interface\r\n \r\n interface operator (>)\r\n module procedure samples_gt_samples\r\n end interface\r\n \r\n interface operator (<)\r\n module procedure samples_lt_samples\r\n end interface\r\n \r\n contains\r\n \r\n !========================================!\r\n ! Implementation !\r\n !========================================!\r\n \r\n !=================================================!\r\n ! @subroutine: init \r\n ! Initialization of object state. \r\n ! Allocation and initialization to default values\r\n ! of complex arrays\r\n ! @Warning\r\n ! Upon detection of non-fatal error\r\n ! variable 'err' will be set to -1\r\n ! Upon detection of fatal error like\r\n ! failed memory allocation 'STOP'\r\n ! will be executed.\r\n ! Values of variable 'err'\r\n ! 1) -1 -- Object built already\r\n ! 2) -2 -- Invalid argument (any of them)\r\n ! 3) -3 -- Floating-point arithmentic error \r\n ! (general error) (not in this scope)\r\n ! 4) -4 -- Overflow\r\n ! 5) -5 -- Underflow\r\n ! 6) -6 -- Inexact\r\n ! 7) -7 -- Denormal\r\n ! 8) -8 -- Cancellation error (cadna)\r\n !=================================================!\r\n subroutine init(this,nechoes,sampID,size,scatnum, &\r\n Ts,logging,filename,append,dbg,err)\r\n implicit none\r\n class(CSWSamples_t), intent(inout) :: this\r\n integer(I32P), intent(in) :: nechoes,sampID, &\r\n size,scatnum\r\n real(R64P), intent(in) :: Ts\r\n logical(I32P), intent(in) :: logging\r\n character(len=*), intent(in) :: filename\r\n logical(I32P), intent(in) :: append,dbg\r\n integer(I32P), intent(inout) :: err\r\n ! Locals\r\n character(len=40) :: sdate,stime\r\n character(len=256) :: emsg\r\n integer(I32P) :: i,aerr\r\n integer(BOOL) :: ifail\r\n logical(I32P) :: bfail\r\n ! Start of executable statements\r\n if(err < 0) err = 0\r\n if(this%m_isbuilt == .true.) then\r\n if(logging == .true.) then\r\n call log_startup(filename,append)\r\n call log_UsrMsg(\"logger:227, In->mod_coswsamples/init: CSWSample_t already initialized!!\")\r\n call log_shutdown()\r\n else\r\n call DATE_AND_TIME(date=sdate,time=stime)\r\n write(stderr,*) \"===========================NON-FATAL==========================\"\r\n write(sdterr,*) \" ( mod_coswsamples/init:227, CSWSample_t already initialized!!)\"\r\n write(stderr,*) \" ( Non-Fatal Error at:) \", &\r\n sdate(1:4),\"-\",sdate(5:6),\"-\",sdate(7:8), \" \", &\r\n stime(1:2),\":\",stime(3:4),\":\",stime(5:6)\r\n write(stderr,*) \"===========================NON-FATAL==========================\"\r\n end if\r\n err = -1\r\n return\r\n end if\r\n if(nechoes < 1 .OR. &\r\n nechoes /= size .OR. &\r\n size < 1 .OR. Ts <= 0._R64P) then\r\n if(logging == .true.) then\r\n call log_startup(filename,append)\r\n call log_UsrMsg(\"logger:244, In->mod_coswsamples/init: Invalid input to subroutine: init !!\")\r\n call log_shutdown()\r\n else\r\n call DATE_AND_TIME(date=sdate,time=stime)\r\n write(stderr,*) \"===========================NON-FATAL==========================\"\r\n write(sdterr,*) \" ( mod_coswsamples/init:244, Invalid input to subroutine: init !!)\"\r\n write(stderr,*) \" ( Non-Fatal Error at:) \", &\r\n sdate(1:4),\"-\",sdate(5:6),\"-\",sdate(7:8), \" \", &\r\n stime(1:2),\":\",stime(3:4),\":\",stime(5:6)\r\n write(stderr,*) \"===========================NON-FATAL==========================\"\r\n end if\r\n err = -2\r\n return\r\n end if\r\n ! Begin construction\r\n this%m_nechoes = nechoes\r\n this%m_sampID = sampID\r\n this%m_size = size\r\n this%m_scatnum = scatnum\r\n this%m_Ts = Ts\r\n allocate(this%m_Vsamp(this%m_size), &\r\n this%m_Vsampavg(this%m_size), &\r\n STAT=aerr, &\r\n ERRMSG=emsg)\r\n if(aerr/=0) then\r\n if(logging == .true.) then\r\n call log_startup(filename,append)\r\n call log_UsrMsg(\"logger:272, In->mod_coswsamples/init: Memory allocation failure!!\")\r\n call log_shutdown()\r\n else\r\n write(stderr,*) \"===========================NON-FATAL==========================\"\r\n write(sdterr,*) \" ( mod_coswsamples/init:272, Memory allocation failure !!)\"\r\n write(stderr,*) \" ( Non-Fatal Error at:) \", &\r\n sdate(1:4),\"-\",sdate(5:6),\"-\",sdate(7:8), \" \", &\r\n stime(1:2),\":\",stime(3:4),\":\",stime(5:6)\r\n write(stderr,*) \"===========================NON-FATAL==========================\"\r\n end if\r\n!DIR$ IF (SHOW_CALLSTACK .EQ. 1)\r\n call TRACEBACKQQ(STRING=\"FATAL-ERROR\", USER_EXIT_CODE= -1)\r\n!DIR$ ENDIF\r\n ERROR STOP \"mod_coswsamples/init:272 -> [FATAL-ERROR]: Terminating execution!!\"\r\n end if\r\n ! Arrays initialization\r\n do i = 1, this%m_size\r\n this%m_Vsamp(i) = DCMPLX(LAM_PINF,LAM_PINF)\r\n this%m_Vsampavg(i) = DCMPLX(LAM_PINF,LAM_PINF)\r\n end do\r\n this%m_isbuilt = .true.\r\n if(dbg == .true.) then\r\n print*, \"V sample: \", this%m_Vsamp\r\n print*, \"V sample average: \", this%m_Vsampavg\r\n end if\r\n end subroutine\r\n \r\n !=================================================!\r\n ! @subroutine: copy \r\n ! @Purpose:\r\n ! Copying of object state.\r\n ! @Warning\r\n ! Upon detection of non-fatal error\r\n ! variable 'err' will be set to -1\r\n ! Upon detection of fatal error like\r\n ! failed memory allocation 'STOP'\r\n ! will be executed.\r\n ! Values of variable 'err'\r\n ! 1) -1 -- Object built already\r\n ! 2) -2 -- Invalid argument (any of them)\r\n ! 3) -3 -- Floating-point arithmentic error \r\n ! (general error) (not in this scope)\r\n ! 4) -4 -- Overflow\r\n ! 5) -5 -- Underflow\r\n ! 6) -6 -- Inexact\r\n ! 7) -7 -- Denormal\r\n ! 8) -8 -- Cancellation error (cadna)\r\n !=================================================! \r\n subroutine copy(this,other,logging,filename,append,err)\r\n implicit none\r\n class(CSWSamples_t), intent(inout) :: this\r\n class(CSWSamples_t), intent(in) :: other\r\n logical(I32P), intent(in) :: logging\r\n character(len=*), intent(in) :: filename\r\n logical(I32P), intent(in) :: append\r\n integer(I32P), intent(inout) :: err\r\n ! Locals\r\n character(len=40) :: sdate,stime\r\n ! Start of executable satements\r\n if(err < 0) err = 0\r\n if(this%m_isbuilt == .true.) then\r\n if(logging == .true.) then\r\n call log_startup(filename,append)\r\n call log_UsrMsg(\"logger:336, In->mod_coswsamples/copy: CSWSample_t already initialized!!\")\r\n call log_shudown()\r\n else\r\n call DATE_AND_TIME(date=sdate,time=stime)\r\n write(stderr,*) \"===========================NON-FATAL==========================\"\r\n write(sdterr,*) \" ( mod_coswsamples/copy:336, CSWSample_t already initialized!!)\"\r\n write(stderr,*) \" ( Non-Fatal Error at:) \", &\r\n sdate(1:4),\"-\",sdate(5:6),\"-\",sdate(7:8), \" \", &\r\n stime(1:2),\":\",stime(3:4),\":\",stime(5:6)\r\n write(stderr,*) \"===========================NON-FATAL==========================\"\r\n end if\r\n err = -1\r\n return\r\n end if\r\n ! Begin construction\r\n this%m_nechoes = other%m_nechoes\r\n this%m_sampID = other%m_sampID\r\n this%m_size = other%m_size\r\n this%m_scatnum = other%m_scatnum\r\n this%m_Ts = other%m_Ts\r\n this%m_Vsamp = other%m_Vsamp\r\n this%m_Vsampavg = other%m_Vsampavg\r\n this%m_isbuilt = .true.\r\n end subroutine\r\n \r\n !=================================================!\r\n ! @subroutine: copy \r\n ! @Purpose:\r\n ! Destroys object state by allocatble\r\n ! arrays deallocation and setting\r\n ! member scalar variables to default values.\r\n ! @Warning\r\n ! Upon detection of non-fatal error\r\n ! variable 'err' will be set to -1\r\n ! Upon detection of fatal error like\r\n ! failed memory allocation 'STOP'\r\n ! will be executed.\r\n ! Values of variable 'err'\r\n ! 1) -1 -- Object built already\r\n ! 2) -2 -- Invalid argument (any of them)\r\n ! 3) -3 -- Floating-point arithmentic error \r\n ! (general error) (not in this scope)\r\n ! 4) -4 -- Overflow\r\n ! 5) -5 -- Underflow\r\n ! 6) -6 -- Inexact\r\n ! 7) -7 -- Denormal\r\n ! 8) -8 -- Cancellation error (cadna)\r\n !=================================================! \r\n subroutine destroy(this,logging,filename,append,err)\r\n implicit none\r\n class(CSWSamples_t), intent(inout) :: this\r\n logical(I32P), intent(in) :: logging\r\n character(len=*), intent(in) :: filename\r\n logical(I32P), intent(in) :: append\r\n integer(I32P), intent(inout) :: err\r\n ! Locals\r\n character(len=40) :: sdate,stime\r\n character(len=256) :: emsg\r\n integer(I32P) :: derr,size\r\n ! Start of executable statements\r\n ! Sanity check on err parameter\r\n if(err < 0) err = 0\r\n if(this%m_isbuilt == .true.) then\r\n if(logging == .true.) then\r\n call log_startup(filename,append)\r\n call log_UsrMsg(\"logger:402, In->mod_coswsamples/destroy: CSWSamples_t already destroyed!!\")\r\n call log_shutdown()\r\n else\r\n call DATE_AND_TIME(date=sdate,time=stime)\r\n write(stderr,*) \"===========================NON-FATAL==========================\"\r\n write(sdterr,*) \" ( mod_coswsamples/destroy:402, CSWSample_t already destroyed!!)\"\r\n write(stderr,*) \" ( Non-Fatal Error at:) \", &\r\n sdate(1:4),\"-\",sdate(5:6),\"-\",sdate(7:8), \" \", &\r\n stime(1:2),\":\",stime(3:4),\":\",stime(5:6)\r\n write(stderr,*) \"===========================NON-FATAL==========================\"\r\n end if\r\n err = -1\r\n return\r\n end if\r\n size = this%m_size\r\n this%m_nechoes = 0\r\n this%m_sampID = 0\r\n this%m_size = 0\r\n this%m_scatnum = 0\r\n this%m_Ts = LAM_PINF\r\n deallocate(this%m_Vsamp, &\r\n this%m_Vsampavg, &\r\n STAT=derr, &\r\n ERRMSG=emsg)\r\n if(derr /= 0) then\r\n if(logging == .true.) then\r\n call log_startup(filename,append)\r\n call log_UsrMsg(\"logger:429, In->mod_coswsamples/destroy: Failed to deallocate allocatble arrays!!\")\r\n call log_shutdown()\r\n else\r\n write(stderr,*) \"===========================NON-FATAL==========================\"\r\n write(sdterr,*) \" ( mod_coswsamples/destroy:429, Failed to deallocate allocatble arrays !!)\"\r\n write(stderr,*) \" ( Non-Fatal Error at:) \", &\r\n sdate(1:4),\"-\",sdate(5:6),\"-\",sdate(7:8), \" \", &\r\n stime(1:2),\":\",stime(3:4),\":\",stime(5:6)\r\n write(stderr,*) \"===========================NON-FATAL==========================\"\r\n end if\r\n!DIR$ IF (SHOW_CALLSTACK .EQ. 1)\r\n call TRACEBACKQQ(STRING=\"FATAL-ERROR\", USER_EXIT_CODE= -1)\r\n!DIR$ ENDIF\r\n ERROR STOP \"mod_coswsamples/destroy:429 -> [FATAL-ERROR]: Terminating execution!!\"\r\n end if\r\n this%m_isbuilt = .false.\r\n end subroutine\r\n\r\n !=================================================!\r\n ! @function: pure get_nechoes \r\n ! @Purpose:\r\n ! getter\r\n !=================================================!\r\n!DIR$ IF (USE_INLINING .EQ. 1)\r\n !DIR$ ATTRIBUTES INLINE :: get_nechoes\r\n!DIR$ ENDIF\r\n \r\n pure function get_nechoes(this) result(nechoes)\r\n implicit none\r\n class(CSWSamples_t), intent(in) :: this\r\n ! Locals\r\n integer(I32P) :: nechoes\r\n ! Start of executable statements\r\n nechoes = this%m_nechoes\r\n end function\r\n \r\n !=================================================!\r\n ! @function: pure get_sampID \r\n ! @Purpose:\r\n ! getter\r\n !=================================================!\r\n!DIR$ IF (USE_INLINING .EQ. 1)\r\n !DIR$ ATTRIBUTES INLINE :: get_sampID\r\n!DIR$ ENDIF\r\n \r\n pure function get_sampID(this) result(sampID)\r\n implicit none\r\n class(CSWSamples_t), intent(in) :: this\r\n ! Locals\r\n integer(I32P) :: sampID\r\n ! Start of executable statemetns\r\n sampID = this%m_sampID\r\n end function\r\n \r\n !=================================================!\r\n ! @function: pure get_size \r\n ! @Purpose:\r\n ! getter\r\n !=================================================!\r\n!DIR$ IF (USE_INLINING .EQ. 1)\r\n !DIR$ ATTRIBUTES INLINE :: get_size\r\n!DIR$ ENDIF\r\n \r\n pure function get_size(this) result(size)\r\n implicit none\r\n class(CSWSamples_t), intent(in) :: this\r\n ! Locals\r\n integer(I32P) :: size\r\n ! Start of executable statements\r\n size = this%m_size\r\n end function\r\n \r\n !=================================================!\r\n ! @function: pure get_scatnum \r\n ! @Purpose:\r\n ! getter\r\n !=================================================!\r\n!DIR$ IF (USE_INLINING .EQ. 1)\r\n !DIR$ ATTRIBUTES INLINE :: get_scatnum\r\n!DIR$ ENDIF\r\n \r\n pure function get_scatnum(this) result(scatnum)\r\n implicit none\r\n class(CSWSamples_t), intent(in) :: this\r\n ! Locals\r\n integer(I32P) :: scatnum\r\n ! Start of executable statements\r\n scatnum = this%m_scatnum\r\n end function\r\n \r\n !=================================================!\r\n ! @function: pure get_Ts \r\n ! @Purpose:\r\n ! getter\r\n !=================================================!\r\n!DIR$ IF (USE_INLINING .EQ. 1)\r\n !DIR$ ATTRIBUTES INLINE :: get_Ts\r\n!DIR$ ENDIF\r\n \r\n pure function get_Ts(this) result(Ts)\r\n implicit none\r\n class(CSWSamples_t), intent(in) :: this\r\n ! Locals\r\n real(R64P) :: Ts\r\n ! Start of executable statements\r\n Ts = this%m_Ts\r\n end function\r\n \r\n !=================================================!\r\n ! @function: pure get_Vsamp \r\n ! @Purpose:\r\n ! getter\r\n !=================================================!\r\n!DIR$ IF (USE_INLINING .EQ. 1)\r\n !DIR$ ATTRIBUTES INLINE :: get_Vsamp\r\n!DIR$ ENDIF\r\n \r\n pure function get_Vsamp(this) result(Vsamp)\r\n implicit none\r\n class(CSWSamples_t), intent(in) :: this\r\n ! Locals\r\n complex(R64P), allocatable, dimension(:) :: Vsamp\r\n!DIR$ ATTRIBUTES ALIGN : 32 :: Vsamp\r\n ! Start of executable statements\r\n Vsamp = this%m_Vsamp\r\n end function\r\n \r\n !=================================================!\r\n ! @function: pure get_Vsampavg \r\n ! @Purpose:\r\n ! getter\r\n !=================================================!\r\n!DIR$ IF (USE_INLINING .EQ. 1)\r\n !DIR$ ATTRIBUTES INLINE :: get_Vsampavg\r\n!DIR$ ENDIF\r\n \r\n pure function get_Vsampavg(this) result(Vsampavg)\r\n implicit none\r\n class(CSWSamples_t), intent(in) :: this\r\n ! Locals\r\n complex(R64P), allocatable, dimension(:) :: Vsampavg\r\n!DIR$ ATTRIBUTES ALIGN : 32 :: Vsampavg\r\n ! Start of executable statements\r\n Vsampavg = this%m_Vsampavg\r\n end function\r\n \r\n !=================================================!\r\n ! @subroutine: read_samples \r\n ! @Purpose:\r\n ! read/write\r\n !=================================================! \r\n subroutine read_samples(this,form,unit,ioerr)\r\n implicit none\r\n class(CSWSamples_t), intent(in) :: this\r\n character(len=*), intent(in) :: form\r\n integer(I32P), intent(in) :: unit\r\n integer(I32P), intent(inout) :: ioerr\r\n ! Start of executable statements\r\n select case(adjustl(trim(form)))\r\n case (\"*\")\r\n READ(unit,*,iostat=ioerr) this\r\n case default\r\n READ(unit,adjustl(trim(form)),iostat=ioerr) this\r\n end select\r\n end subroutine\r\n \r\n !=================================================!\r\n ! @subroutine: write_samples \r\n ! @Purpose:\r\n ! read/write\r\n !=================================================! \r\n subroutine write_samples(this,form,unit,ioerr)\r\n implicit none\r\n class(CSWSamples_t), intent(in) :: this\r\n character(len=*), intent(in) :: form\r\n integer(I32P), intent(in) :: unit\r\n integer(I32P), intent(inout) :: ioerr\r\n ! Start of executable statements\r\n select case(adjustl(trim(form)))\r\n case (\"*\")\r\n WRITE(unit,*,iostat=ioerr) this\r\n case default\r\n WRITE(unit,adjustl(trim(form)),iostat=ioerr) this\r\n end select\r\n end subroutine\r\n \r\n !=================================================!\r\n ! @subroutine: compute_Vsamp \r\n ! @Purpose:\r\n ! Performs computation of weather radar\r\n ! signal samples and stores them in\r\n ! member array m_Vsamp\r\n ! @Warning\r\n ! Upon detection of non-fatal error\r\n ! variable 'err' will be set to -1\r\n ! Upon detection of fatal error like\r\n ! failed memory allocation 'STOP'\r\n ! will be executed.\r\n ! Values of variable 'err'\r\n ! 1) -1 -- Object built already\r\n ! 2) -2 -- Invalid argument (any of them)\r\n ! 3) -3 -- Floating-point arithmentic error \r\n ! (general error) (in this case)\r\n ! 4) -4 -- Overflow\r\n ! 5) -5 -- Underflow\r\n ! 6) -6 -- Inexact\r\n ! 7) -7 -- Denormal\r\n ! 8) -8 -- Cancellation error (cadna)\r\n !=================================================! \r\n subroutine compute_Vsamp(this,Ai,Wi,cexpterm,nsize,err,fpflags,verbose)\r\n implicit none\r\n use mod_constants, only : LAM_ISQRT2,LAM_ZC\r\n!DIR$ IF (USE_IEEE_EXCEPTION_HANDLING .EQ. 1)\r\n use, intrinsic :: ieee_exception\r\n!DIR$ ENDIF\r\n class(CSWSample_t), intent(inout) :: this\r\n complex(R64P), dimension(nsize), intent(in) :: Ai\r\n!DIR$ ASSUME_ALIGNED Ai:32\r\n complex(R64P), dimension(nsize), intent(in) :: Wi\r\n!DIR$ ASSUME_ALIGNED Wi:32\r\n complex(R64P), dimension(nsize), intent(in) :: cexpterm\r\n!DIR$ ASSUME_ALIGNED cexpterm:32\r\n integer(I32P), intent(in) :: nsize\r\n integer(I32P), intent(inout) :: err\r\n logical(I32P), dimension(5), intent(inout) :: fpflags\r\n logical(I32P), intent(in) :: verbose\r\n ! Locals\r\n complex(R64P) :: tmp\r\n integer(I32P) :: i\r\n!DIR$ IF (USE_IEEE_EXCEPTION_HANDLING .EQ. 1)\r\n type(ieee_status_type) :: status_value\r\n!DIR$ ENDIF\r\n ! Start of executable statements\r\n ! Sanity check on error and flags arguments\r\n if(ANY(fpflags) == .true.) then\r\n fpflags = .false.\r\n end if\r\n if(err < 0) err = 0\r\n if(nsize /= this%m_size) then\r\n err = -2\r\n return\r\n end if\r\n tmp = LAM_ZC\r\n!DIR$ IF (USE_IEEE_EXCEPTION_HANDLING .EQ. 1)\r\n call ieee_get_status(status_value)\r\n call ieee_set_handling_mode(ieee_all,.false.)\r\n call ieee_set_flags(ieee_all,fpflags)\r\n!DIR$ ENDIF\r\n!DIR$ SIMD\r\n do i = 1, this%m_size\r\n tmp = tmp+Ai(i)*Wi(i)*cexpterm(i)\r\n tmp = LAM_ISQRT2*tmp\r\n this%m_Vsamp(i) = tmp\r\n end do\r\n!DIR$ IF (USE_IEEE_EXCEPTION_HANDLING .EQ. 1)\r\n call ieee_get_flag(ieee_all,fpflags)\r\n if(ANY(fpflags) == .true. ) then\r\n if(verbose == .true. ) then\r\n WRITE(stderr,*) \"==============================================================================\"\r\n WRITE(stderr,*) \" mod_coswsamples/compute_Vsamp:699 -- Floating-point exception(s) occurred!!\"\r\n WRITE(stderr,*) \"===============================================================================\"\r\n end if\r\n err = -3\r\n call ieee_set_status(status_value)\r\n end if\r\n!DIR$ ENDIF\r\n end subroutine\r\n \r\n !=================================================!\r\n ! @subroutine: compute_Vsampavg \r\n ! @Purpose:\r\n ! Performs computation of weather radar\r\n ! signal samples averaged over frequency cycle\r\n ! and stores them in member array mVsampavg.\r\n ! \r\n ! @Warning\r\n ! Upon detection of non-fatal error\r\n ! variable 'err' will be set to -1\r\n ! Upon detection of fatal error like\r\n ! failed memory allocation 'STOP'\r\n ! will be executed.\r\n ! Values of variable 'err'\r\n ! 1) -1 -- Object built already\r\n ! 2) -2 -- Invalid argument (any of them)\r\n ! 3) -3 -- Floating-point arithmentic error \r\n ! (general error) (in this case)\r\n ! 4) -4 -- Overflow\r\n ! 5) -5 -- Underflow\r\n ! 6) -6 -- Inexact\r\n ! 7) -7 -- Denormal\r\n ! 8) -8 -- Cancellation error (cadna)\r\n !=================================================! \r\n subroutine compute_Vsampavg(this,Ai,CAk,Wi,CWk,cexpterm,nsize,err,fpflags,verbose)\r\n implicit none\r\n use mod_constants, only : LAM_HR64P,LAM_ZC\r\n!DIR$ IF (USE_IEEE_EXCEPTION_HANDLING .EQ. 1)\r\n use, intrinsic :: ieee_exception\r\n!DIR$ ENDIF\r\n class(CSWSample_t), intent(inout) :: this\r\n complex(R64P), dimension(nsize), intent(in) :: Ai,CAk\r\n!DIR$ ASSUME_ALIGNED Ai:32\r\n!DIR$ ASSUME_ALIGNED CAk:32\r\n complex(R64P), dimension(nsize), intent(in) :: Wi,CWk\r\n!DIR$ ASSUME_ALIGNED Wi:32\r\n!DIR$ ASSUME_ALIGNED CWk:32\r\n complex(R64P), dimension(nsize), intent(in) :: cexpterm\r\n!DIR$ ASSUME_ALIGNED cexpterm:32\r\n integer(I32P), intent(in) :: nsize\r\n integer(I32P), intent(inout) :: err\r\n logical(I32P), dimension(5), intent(in) :: fpflags\r\n logical(I32P), intent(in) :: verbose\r\n ! Locals\r\n complex(R64P) :: tmp1,tmp2\r\n integer(I32P) :: i\r\n!DIR$ IF (USE_IEEE_EXCEPTION_HANDLING .EQ. 1)\r\n type(ieee_status_type) :: status_value\r\n!DIR$ ENDIF\r\n ! Start of executable statements\r\n ! Sanity check on input arguments\r\n if(ANY(fpflags) == .true.) then\r\n fpflags = .true.\r\n end if\r\n if(err < 0) err = 0\r\n if(nsize /= this%m_size) then\r\n err = -2\r\n return\r\n end if\r\n tmp1 = LAM_ZC\r\n tmp2 = LAM_ZC\r\n!DIR$ IF (USE_IEEE_EXCEPTION_HANDLING .EQ. 1)\r\n call ieee_get_status(status_value)\r\n call ieee_set_handling_mode(ieee_all,.false.)\r\n call ieee_set_flags(ieee_all,fpflags)\r\n!DIR$ ENDIF\r\n!DIR$ SIMD\r\n do i = 1, this%m_size\r\n tmp1 = tmp1+Ai(i)*CAk(i)*Wi(i)*CWk(i)*cexpterm(i)\r\n tmp1 = tmp1*LAM_HR64P\r\n this%m_Vsampavg(i) = tmp1\r\n end do\r\n!DIR$ IF (USE_IEEE_EXCEPTION_HANDLING .EQ. 1)\r\n call ieee_get_flag(ieee_all,fpflags)\r\n if(ANY(fpflags) == .true. ) then\r\n if(verbose == .true. ) then\r\n WRITE(stderr,*) \"==============================================================================\"\r\n WRITE(stderr,*) \" mod_coswsamples/compute_Vsampavg:788 -- Floating-point exception(s) occurred!!\"\r\n WRITE(stderr,*) \"===============================================================================\"\r\n end if\r\n err = -3\r\n call ieee_set_status(status_value)\r\n end if\r\n!DIR$ ENDIF \r\n end subroutine\r\n \r\n !==============================================\r\n ! Module operators\r\n !==============================================\r\n \r\n !==============================================\r\n ! subroutine: assignment (=)\r\n !==============================================\r\n subroutine assign_samples(this,other)\r\n implicit none\r\n type(CSWSamples_t), intent(inout) :: this\r\n type(CSWSamples_t), intent(in) :: other\r\n ! Locals\r\n character(len=40) :: sdate,stime\r\n ! Start of executable statements\r\n if(LOC(this) == LOC(other)) then\r\n write(stderr,*) \"===========================NON-FATAL==========================\"\r\n write(sdterr,*) \" ( mod_coswsamples/assignment(=):814, Attempted self_assignment!)\"\r\n write(stderr,*) \" ( Non-Fatal Error at:) \", &\r\n sdate(1:4),\"-\",sdate(5:6),\"-\",sdate(7:8), \" \", &\r\n stime(1:2),\":\",stime(3:4),\":\",stime(5:6)\r\n write(stderr,*) \"===========================NON-FATAL==========================\"\r\n return\r\n end if\r\n this%m_nechoes = other%m_nechoes\r\n this%m_sampID = other%m_sampID\r\n this%m_size = other%m_size\r\n this%m_scatnum = other%m_scatnum\r\n this%m_Ts = other%m_Ts\r\n this%m_Vsamp = other%m_Vsamp\r\n this%m_Vsampavg = other%m_Vsampavg\r\n this%m_isbuilt = other%m_isbuilt \r\n end subroutine\r\n \r\n !======================================================60\r\n ! function: samples_neq_samples i.e. overloaded\r\n ! operator (/=)\r\n ! Warning: No error checking is made!!\r\n ! Both arguments should be the same i.e.\r\n ! Same arrays size.\r\n !======================================================60\r\n function samples_neq_samples(s1,s2) result(neq)\r\n implicit none\r\n use module_helper_fields_equality, only : Pair1D_t\r\n type(CSWSamples_t), intent(in) :: s1,s2\r\n ! Locals\r\n type(Pair1D_t) :: neq\r\n ! Start of executable statements\r\n neq%x = s1%m_Vsamp /= s2%m_Vsamp\r\n neq%y = s2%m_Vsampavg /= s2%m_Vsampavg\r\n end function\r\n \r\n !======================================================60\r\n ! function: samples_eq_samples i.e. overloaded\r\n ! operator (==)\r\n ! Warning: No error checking is made!!\r\n ! Both arguments should be the same i.e.\r\n ! Same arrays size.\r\n !======================================================60\r\n function samples_eq_samples(s1,s2) result(eq)\r\n implicit none\r\n use module_helper_fields_equality, only : Pair1D_t\r\n type(CSWSamples_t), intent(in) :: s1,s2\r\n ! Locals\r\n type(Pair1D_t) :: eq\r\n ! Start of executable statements\r\n eq%x = s1%m_Vsamp == s2%m_Vsamp\r\n eq%y = s1%m_Vsampavg == s2%m_Vsampavg\r\n end function\r\n \r\n !======================================================60\r\n ! function: samples_gt_samples i.e. overloaded\r\n ! operator (>)\r\n ! Warning: No error checking is made!!\r\n ! Both arguments should be the same i.e.\r\n ! Same arrays size.\r\n !======================================================60\r\n function samples_gt_samples(s1,s2) result(gt)\r\n implicit none\r\n use module_helper_fields_equality, only : Pair1D_t\r\n type(CSWSamples_t), intent(in) :: s1,s2\r\n ! Locals\r\n type(Pair1D_t) :: gt\r\n ! Start of executable statements\r\n gt%x = s1%m_Vsamp > s2%m_Vsamp\r\n gt%y = s2%m_Vsampavg > s2%m_Vsampavg\r\n end function\r\n \r\n !======================================================60\r\n ! function: samples_lt_samples i.e. overloaded\r\n ! operator (<)\r\n ! Warning: No error checking is made!!\r\n ! Both arguments should be the same i.e.\r\n ! Same arrays size.\r\n !======================================================60\r\n function samples_lt_samples(s1,s2) result(lt)\r\n implicit none\r\n use module_helper_fields_equality, only : Pair1D_t\r\n type(CSWSamples_t), intent(in) :: s1,s2\r\n ! Locals\r\n type(Pair1D_t) :: lt\r\n ! Start of executable statements\r\n lt%x = s1%m_Vsamp > s2%m_Vsamp\r\n lt%y = s2%m_Vsampavg > s2%m_Vsampavg\r\n end function\r\n \r\nend module mod_coswsamples", "meta": {"hexsha": "c7e5e0e161d90fe674bcfb96535ddff00519bf0a", "size": 37478, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Weather Radar/module_coswsamples.f90", "max_stars_repo_name": "bgin/LibAtmosModel", "max_stars_repo_head_hexsha": "ee9383d7e09a35d79fa24ce120afe6f8ea6efd09", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-02-27T13:49:01.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-29T09:23:03.000Z", "max_issues_repo_path": "Weather Radar/module_coswsamples.f90", "max_issues_repo_name": "bgin/LibAtmosModel", "max_issues_repo_head_hexsha": "ee9383d7e09a35d79fa24ce120afe6f8ea6efd09", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Weather Radar/module_coswsamples.f90", "max_forks_repo_name": "bgin/LibAtmosModel", "max_forks_repo_head_hexsha": "ee9383d7e09a35d79fa24ce120afe6f8ea6efd09", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-08-26T12:11:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-19T01:45:27.000Z", "avg_line_length": 41.4121546961, "max_line_length": 119, "alphanum_fraction": 0.435108597, "num_tokens": 8575, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544912, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6686988702551037}} {"text": "PROGRAM fazi2stats \n \nIMPLICIT NONE\n\nCHARACTER(len=32) :: arg\nINTEGER :: ngood,i\nDOUBLE PRECISION :: mean_fazi,mean_dt,mean_dazi,std_fazi,std_dt,std_dazi,meansin,meancos,da \nDOUBLE PRECISION, DIMENSION(:), ALLOCATABLE :: x,fazi,dt,sin_fazi,cos_fazi,dazi\nDOUBLE PRECISION, PARAMETER :: pi180=0.017453292519943295769236907684886 \nDO i = 1, iargc()\n CALL getarg(i, arg)\n if(i==1) read(arg,'(i3)') ngood \n! if(i==2) read(arg,'(e3.1)') z \nEND DO\n\n!No record if 0 good measuraments\nif(ngood .eq.0) then\n !write(*,*),0d0,0d0,0d0,0d0\n stop\n!No statistics if only 1 good measurament\nelse if(ngood .eq. 1) then\n read *,i,mean_fazi,mean_dt\n write(*,*), mean_fazi,0d0,mean_dt,0d0\n stop \n\nelse\n\nALLOCATE(x(ngood),fazi(ngood),dt(ngood),sin_fazi(ngood),cos_fazi(ngood),dazi(ngood))\n\ndo i=1,ngood\n read *,x(i),fazi(i),dt(i)\nend do\n\n!Convert degrees to radians and calculate sin and cos of fast azimuths\ndo i=1,ngood\n sin_fazi(i)=sin(2d0*fazi(i)*pi180)\n cos_fazi(i)=cos(2d0*fazi(i)*pi180)\nend do\n\n!Mean of sin(2*azi),cos(2*azi)\nmeansin=sum(sin_fazi)/ngood \nmeancos=sum(cos_fazi)/ngood \n!Mean 2*phi azimuth in radians\nmean_fazi = atan2(meansin,meancos)\n!Convert phi to degrees\n!do i=1,ngood\n! if(fazi(i) .gt. 90d0) fazi(i) = fazi(i) - 180d0\n!end do\n!mean_fazi = sum(fazi)/ngood!mean_fazi/2d0/pi180\nmean_fazi = mean_fazi/2d0/pi180\n!print *,mean_fazi\n!Move to 0...180 range\ncall fix_deg_angle(mean_fazi)\nif(mean_fazi .gt. 180) mean_fazi = mean_fazi -180\n\n!Deviation from mean azimuth ( -90 < dazi < +90 )\ndo i=1,ngood\n call fix_deg_angle(fazi(i))\n da = fazi(i) - mean_fazi\n!print *,da,fazi(i),mean_fazi\n if(da .gt. 0d0) then\n if(da .gt. 180d0) da = da - 180d0\n if(da .gt. 90d0) da = da - 180d0\n else\n if(da .lt.- 180d0) da = da + 180d0\n if(da .lt. -90d0) da = da + 180d0\n end if\n dazi(i) = da\n!print *,dazi(i)\nend do\n\n!Mean, std dev for diff_azi\n!Mean of diff_azi = 0 --> stddev(dazi) = stddev(fazi)\ncall stats(dazi,ngood,mean_dazi,std_dazi)\nstd_fazi=std_dazi\n!print *,mean_dazi\n!Mean, std dev for dt \ncall stats(dt,ngood,mean_dt,std_dt)\n\n!Write result to output file`\nwrite(*,*),mean_fazi,std_fazi,mean_dt,std_dt\n\nDEALLOCATE(x,fazi,dt,sin_fazi,cos_fazi,dazi)\n\nstop\n\nend if\n\n\nEND PROGRAM\n\n\nsubroutine fix_deg_angle(phi)\n\nimplicit none\n\nDOUBLE PRECISION :: phi \n\ndo while(phi < 0 ) \n phi = phi + 360\nend do\ndo while(phi >360) \n phi = phi - 360\nend do\n\nend subroutine fix_deg_angle\n\nsubroutine stats(x,ngood,ave,sdev)\n\nimplicit none\n\nINTEGER :: i,ngood,n\nDOUBLE PRECISION :: ave,sdev,var,x(ngood),s\n \ns=0d0\nn=0\ndo i=1,ngood\n if(isnan(x(i))) then\n write(*,*) 'NaN measurament for i=', i\n else\n s = s + x(i)\n n = n + 1\n end if\nend do\n\nave=s/n\n\ns = 0d0; sdev=0d0; var=0d0\ndo i=1,ngood\n if(isnan(x(i))) then\n !write(*,*) 'NaN measurament for i=', i\n else\n s = x(i)-ave\n !dev = dev + abs(s)\n var = var + s*s\n end if\nend do\n\nvar = var/(n-1)\nsdev = sqrt(var)\n\nend subroutine stats\n", "meta": {"hexsha": "4129b44e8c413482ceea1cbd730b7a449576598d", "size": 3003, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "SKS-SPLIT/fazi2splitstat.f90", "max_stars_repo_name": "mfaccenda/ECOMAN", "max_stars_repo_head_hexsha": "67a31b45481dc3c2e57afabd526e75bc1bb9e639", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-28T07:49:51.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-28T07:49:51.000Z", "max_issues_repo_path": "SKS-SPLIT/fazi2splitstat.f90", "max_issues_repo_name": "mfaccenda/ECOMAN", "max_issues_repo_head_hexsha": "67a31b45481dc3c2e57afabd526e75bc1bb9e639", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SKS-SPLIT/fazi2splitstat.f90", "max_forks_repo_name": "mfaccenda/ECOMAN", "max_forks_repo_head_hexsha": "67a31b45481dc3c2e57afabd526e75bc1bb9e639", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-04-28T14:42:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-22T12:17:47.000Z", "avg_line_length": 21.0, "max_line_length": 111, "alphanum_fraction": 0.6593406593, "num_tokens": 1171, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278540866547, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6686988657096892}} {"text": " SUBROUTINE FOREGON(N,X,Y,F,RPAR,IPAR)\nC --- RIGHT-HAND SIDE OF OREGO EQUATION\n IMPLICIT REAL*8 (A-H,O-Z)\n DIMENSION Y(N),F(N)\n F(1)=77.27D0*(Y(2)+Y(1)*(1.D0-8.375D-6*Y(1)-Y(2)))\n F(2)=(Y(3)-(1.D0+Y(1))*Y(2))/77.27D0\n F(3)=0.161D0*(Y(1)-Y(3))\n RETURN\n END \nC\n SUBROUTINE JOREGON(N,X,Y,DFY,LDFY,RPAR,IPAR)\nC --- JACOBIAN OF OREGO EQUATION\n IMPLICIT REAL*8 (A-H,O-Z)\n DIMENSION Y(N),DFY(LDFY,N)\n DFY(1,1)=77.27D0*(1.D0-2.D0*8.375D-6*Y(1)-Y(2))\n DFY(1,2)=77.27D0*(1.D0-Y(1))\n DFY(1,3)=0.D0\n DFY(2,1)=-Y(2)/77.27D0\n DFY(2,2)=-(1.D0+Y(1))/77.27D0\n DFY(2,3)=1.D0/77.27D0\n DFY(3,1)=.161D0\n DFY(3,2)=.0D0\n DFY(3,3)=-.161D0\n RETURN\n END\n\n", "meta": {"hexsha": "551478b65cfc9e346421263f3a2cbcf973b7815d", "size": 783, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/ore_equation.f", "max_stars_repo_name": "cpmech/hwode", "max_stars_repo_head_hexsha": "7a6c033ace96b8b8dcf564ba0f38dd501fe2f60d", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tests/ore_equation.f", "max_issues_repo_name": "cpmech/hwode", "max_issues_repo_head_hexsha": "7a6c033ace96b8b8dcf564ba0f38dd501fe2f60d", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/ore_equation.f", "max_forks_repo_name": "cpmech/hwode", "max_forks_repo_head_hexsha": "7a6c033ace96b8b8dcf564ba0f38dd501fe2f60d", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.0, "max_line_length": 58, "alphanum_fraction": 0.4827586207, "num_tokens": 383, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278540866547, "lm_q2_score": 0.7577943658046608, "lm_q1q2_score": 0.6686988560559642}} {"text": "c fishpk34 from portlib 12/30/83\nc\nc * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nc * *\nc * f i s h p a k *\nc * *\nc * *\nc * a package of fortran subprograms for the solution of *\nc * *\nc * separable elliptic partial differential equations *\nc * *\nc * (version 3.1 , october 1980) *\nc * *\nc * by *\nc * *\nc * john adams, paul swarztrauber and roland sweet *\nc * *\nc * of *\nc * *\nc * the national center for atmospheric research *\nc * *\nc * boulder, colorado (80307) u.s.a. *\nc * *\nc * which is sponsored by *\nc * *\nc * the national science foundation *\nc * *\nc * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nc\nc\nc this program illustrates the use of subroutine hstcsp to solve\nc the equation\nc\nc (1/r**2)(d/dr)(r**2(du/dr)) +\nc\nc (1/r**2*sin(theta))(d/dtheta)(sin(theta)(du/dtheta))\nc\nc = 12*(r*cos(theta))**2\nc\nc on the rectangle 0 .lt. theta .lt. pi , 0 .lt. r .lt. 1\nc with the boundary conditions\nc\nc u(theta,1) = cos(theta)**4 , o .le. theta .le. pi\nc\nc and the solution unspecified on the remaining boundaries.\nc we will use 45 unknowns in the theta-interval and 15 unknowns\nc in the r-interval.\nc\n program thstcsp\n dimension f(47,16) ,bdd(45) ,w(615) ,theta(45) ,\n 1 r(15) ,cost(45)\n dimension bda(1), bdb(1), bdc(1)\nc\nc note that from dimension statement we get that idimf = 47 and\nc that w is dimensioned according to the statement in the\nc description of w.\nc\n idimf = 47\n a = 0.\n b = pimach(dum)\nc\nc note that b is set to pi using the function pimach as required.\nc\n m = 45\n mbdcnd = 9\n dt = (b-a)/float(m)\nc\nc define grid points theta(i) and cos(theta(i))\nc\n do 101 i=1,m\n theta(i) = a+(float(i)-0.5)*dt\n cost(i) = cos(theta(i))\n 101 continue\n c = 0.\n d = 1.\n n = 15\n nbdcnd = 5\n dr = (d-c)/float(n)\nc\nc define grid points r(j)\nc\n do 102 j=1,n\n r(j) = c+(float(j)-0.5)*dr\n 102 continue\nc\nc define boundary array bdd. bda, bdb, and bdc are dummy\nc variables in this example.\nc\n do 103 i=1,m\n bdd(i) = cost(i)**4\n 103 continue\n elmbda = 0.\nc\nc define right side f\nc\n do 105 i=1,m\n do 104 j=1,n\n f(i,j) = 12.*(r(j)*cost(i))**2\n 104 continue\n 105 continue\n intl = 0\n call hstcsp (intl,a,b,m,mbdcnd,bda,bdb,c,d,n,nbdcnd,bdc,bdd,\n 1 elmbda,f,idimf,pertrb,ierror,w)\nc\nc compute discretization error. the exact solution is\nc\nc u(theta,r) = (r*cos(theta))**4\nc\n err = 0.\n do 107 i=1,m\n do 106 j=1,n\n z = abs(f(i,j)-(r(j)*cost(i))**4)\n if (z .gt. err) err = z\n 106 continue\n 107 continue\n print 1001 , ierror,err,w(1)\n stop\nc\n 1001 format (1h1,20x,25hsubroutine hstcsp example///\n 1 10x,46hthe output from the ncar control data 7600 was//\n 2 32x,10hierror = 0/\n 3 18x,34hdiscretization error = 5.58432e-03/\n 4 12x,32hrequired length of w array = 583//\n 5 10x,32hthe output from your computer is//\n 6 32x,8hierror =,i2/18x,22hdiscretization error =,e12.5/\n 7 12x,28hrequired length of w array =,f4.0)\nc\n end\nc compute discretization error. the exact solution is\n", "meta": {"hexsha": "c234b818d4ba4f82a157371c6262c1ce3e4086b9", "size": 4675, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/f2cl/packages/fishpack/ex/tsthstcsp.f", "max_stars_repo_name": "sbwhitecap/clocc-hg", "max_stars_repo_head_hexsha": "f6cf2591ceef8a3a80e04da9b414cdf60a25a90f", "max_stars_repo_licenses": ["MIT"], "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/f2cl/packages/fishpack/ex/tsthstcsp.f", "max_issues_repo_name": "sbwhitecap/clocc-hg", "max_issues_repo_head_hexsha": "f6cf2591ceef8a3a80e04da9b414cdf60a25a90f", "max_issues_repo_licenses": ["MIT"], "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/f2cl/packages/fishpack/ex/tsthstcsp.f", "max_forks_repo_name": "sbwhitecap/clocc-hg", "max_forks_repo_head_hexsha": "f6cf2591ceef8a3a80e04da9b414cdf60a25a90f", "max_forks_repo_licenses": ["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.9615384615, "max_line_length": 72, "alphanum_fraction": 0.3937967914, "num_tokens": 1291, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757870013740061, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6686491605940839}} {"text": "subroutine utility(values,ncols,gamma,util)\ninteger, INTENT(IN) :: ncols\nREAL, INTENT(IN) :: values(1,ncols), gamma\nREAL, INTENT(OUT) :: util(1,ncols)\n util = (values**(1-gamma))/(1-gamma)\nend subroutine\n", "meta": {"hexsha": "7e2cd0972648b429adf855f0a94cb83025e87d3d", "size": 205, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "CGMPortfolio/Related/SourceCode/Fortran/utility.f90", "max_stars_repo_name": "HsinYiHung/HARK_HY", "max_stars_repo_head_hexsha": "086c46af5bd037fe1ced6906c6ea917ed58b134f", "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": "CGMPortfolio/Related/SourceCode/Fortran/utility.f90", "max_issues_repo_name": "HsinYiHung/HARK_HY", "max_issues_repo_head_hexsha": "086c46af5bd037fe1ced6906c6ea917ed58b134f", "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": "CGMPortfolio/Related/SourceCode/Fortran/utility.f90", "max_forks_repo_name": "HsinYiHung/HARK_HY", "max_forks_repo_head_hexsha": "086c46af5bd037fe1ced6906c6ea917ed58b134f", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.2857142857, "max_line_length": 43, "alphanum_fraction": 0.7024390244, "num_tokens": 69, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8757869851639066, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6686491435048066}} {"text": "!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 1998 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Spherepack *\n! * *\n! * A Package of Fortran Subroutines and Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams and Paul Swarztrauber *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\n!\n! a program for testing the scalar laplacian routines\n!\n! (1) set a scalar field s as poly in x, y, z restricted to sphere\n!\n! (2) compute scalar laplacian in array sclp\n!\n! (3) compare (2) with analytic scalar laplacian in sclpe\n!\n! (4) compute the inverse of (2) and compare with (1)\n!\nprogram tslap\n\n use, intrinsic :: ISO_Fortran_env, only: &\n stdout => OUTPUT_UNIT\n\n use spherepack, only: &\n ip, & ! Integer precision\n wp, & ! Working precision\n Sphere, &\n Regularsphere, &\n GaussianSphere\n\n ! Explicit typing only\n implicit none\n\n ! Dictionary\n class(Sphere), allocatable :: solver\n\n ! Test gaussian grid\n allocate (GaussianSphere :: solver)\n call test_scalar_laplacian_routines(solver)\n deallocate (solver)\n\n ! Test regular grid\n allocate (RegularSphere :: solver)\n call test_scalar_laplacian_routines(solver)\n deallocate (solver)\n\ncontains\n\n subroutine test_scalar_laplacian_routines(sphere_type)\n\n ! Dummy arguments\n class(Sphere), intent(inout) :: sphere_type\n\n ! Local variables\n integer(ip), parameter :: NLATS = 15\n integer(ip), parameter :: NLONS = 22\n integer(ip), parameter :: NSYNTHS = 3\n integer(ip) :: i, j, k ! Counters\n real(wp) :: original_scalar_function(NLATS, NLONS, NSYNTHS)\n real(wp) :: exact_laplacian(NLATS, NLONS, NSYNTHS)\n real(wp) :: approximate_scalar_function(NLATS, NLONS, NSYNTHS)\n real(wp) :: approximate_laplacian(NLATS, NLONS, NSYNTHS)\n character(len=:), allocatable :: laplacian_error, inversion_error\n\n ! Set up workspace arrays\n select type(sphere_type)\n type is (GaussianSphere)\n\n ! Initialize gaussian sphere object\n sphere_type = GaussianSphere(NLATS, NLONS)\n\n ! Allocate known error from previous platform\n allocate (laplacian_error, source=' discretization error = 1.953993e-13')\n allocate (inversion_error, source=' discretization error = 6.661338e-16')\n\n type is (RegularSphere)\n\n ! Initialize regular sphere\n sphere_type = RegularSphere(NLATS, NLONS)\n\n ! Allocate known error from previous platform\n allocate (laplacian_error, source=' discretization error = 1.003642e-13')\n allocate (inversion_error, source=' discretization error = 8.881784e-16')\n end select\n\n !\n ! test all analysis and synthesis subroutines\n ! set scalar field as polynomial in x, y, z\n ! restricted to the sphere\n !\n associate (&\n se => original_scalar_function, &\n sclpe => exact_laplacian, &\n radial => sphere_type%unit_vectors%radial &\n )\n do k=1, NSYNTHS\n do j=1, NLONS\n do i=1, NLATS\n associate (&\n x => radial(i, j)%x, &\n y => radial(i, j)%y, &\n z => radial(i, j)%z &\n )\n select case (k)\n case(1)\n se(i, j, k) = x + y\n sclpe(i, j, k) = -2.0_wp * (x + y)\n case(2)\n se(i, j, k) = x + z\n sclpe(i, j, k) = -2.0_wp * (x + z)\n case(3)\n se(i, j, k) = y + z\n sclpe(i, j, k) = -2.0_wp * (y + z)\n end select\n end associate\n end do\n end do\n end do\n end associate\n\n !\n ! Compute scalar laplacian\n !\n do k = 1, NSYNTHS\n associate (&\n se => original_scalar_function(:, :, k), &\n sclp => approximate_laplacian(:, :, k) &\n )\n call sphere_type%get_laplacian(se, sclp)\n end associate\n end do\n\n !\n ! Compute discretization error in sclp\n !\n associate (&\n sclp => approximate_laplacian, &\n sclpe => exact_laplacian &\n )\n associate (err2 => maxval(abs(sclp - sclpe)))\n !\n ! Print earlier output from platform with 64-bit floating point\n ! arithmetic followed by the output from this computer\n !\n write (stdout, '(a)') ''\n write (stdout, '(a)') ' test scalar laplacian routines *** TEST RUN *** '\n write (stdout, '(a)') ''\n write (stdout, '(a)') ' grid type = '//sphere_type%grid%grid_type\n write (stdout, '(a)') ' scalar laplacian approximation'\n write (stdout, '(2(a, i3))') ' nlat = ', NLATS, ' nlon = ', NLONS\n write (stdout, '(a)') ' Previous 64 bit floating point arithmetic result '\n write (stdout, '(a)') laplacian_error\n write (stdout, '(a)') ' The output from your computer is: '\n write (stdout, '(a, 1pe15.6)') ' discretization error = ', err2\n write (stdout, '(a)') ''\n end associate\n end associate\n !\n ! invert scalar laplacian\n !\n do k = 1, NSYNTHS\n associate (&\n sclpe => exact_laplacian(:, :, k), &\n s => approximate_scalar_function(:, :, k) &\n )\n call sphere_type%invert_laplacian(sclpe, s)\n end associate\n end do\n\n ! Compare s with se\n associate (&\n s => approximate_scalar_function, &\n se => original_scalar_function &\n )\n associate (err2 => maxval(abs(s - se)))\n !\n ! Print earlier output from platform with 64-bit floating point\n ! arithmetic followed by the output from this computer\n !\n write (stdout, '(a)') ''\n write (stdout, '(a)') ' tslap *** TEST RUN *** '\n write (stdout, '(a)') ''\n write (stdout, '(a)') ' grid type = '//sphere_type%grid%grid_type\n write (stdout, '(a)') ' scalar laplacian inversion'\n write (stdout, '(2(a, i3))') ' nlat = ', NLATS, ' nlon = ', NLONS\n write (stdout, '(a)') ' Previous 64 bit floating point arithmetic result '\n write (stdout, '(a)') inversion_error\n write (stdout, '(a)') ' The output from your computer is: '\n write (stdout, '(a, 1pe15.6)') ' discretization error = ', err2\n write (stdout, '(a)') ''\n end associate\n end associate\n\n ! Release memory\n deallocate (laplacian_error)\n deallocate (inversion_error)\n call sphere_type%destroy()\n\n end subroutine test_scalar_laplacian_routines\n\nend program tslap\n\n\n", "meta": {"hexsha": "e0fce55cb897978b17b878e6d5601715544c3209", "size": 9403, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/test_scalar_laplacian_routines.f90", "max_stars_repo_name": "jlokimlin/spherepack4.1", "max_stars_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-06-28T14:01:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T21:59:28.000Z", "max_issues_repo_path": "test/test_scalar_laplacian_routines.f90", "max_issues_repo_name": "jlokimlin/spherepack4.1", "max_issues_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2016-05-07T23:00:35.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-22T23:52:30.000Z", "max_forks_repo_path": "test/test_scalar_laplacian_routines.f90", "max_forks_repo_name": "jlokimlin/spherepack4.1", "max_forks_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-06-28T14:03:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T12:53:54.000Z", "avg_line_length": 41.2412280702, "max_line_length": 94, "alphanum_fraction": 0.4104009359, "num_tokens": 1995, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869884059267, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.668649141266907}} {"text": "!\n!*******************************************************************************\n!\nreal(kind=8) function random_32(iseed_32)\n!\n!*******************************************************************************\n!\n! Discussion:\n!\n! FORTRAN 90 function to return 32-bit pseudo-random numbers with a large \n! period\n! Based on a modification of the linear congruential method\n!\n! r(i+1) = mod(A*ran(i),M)\n!\n! A = 2946716567, M = 2^63-1\n!\n! where the mod operation is computing using Schrage's algorithm based\n! on an approximate factorization\n!\n! M = A*Q + R\n!\n! Q = [M/A} = 3130050626 and R = mod(M,A) = 1671854155\n!\n! Then \n!\n! mod(A*Y,M) = A*mod(Y,Q) - R*[Y/Q] if >= 0\n! A*mod(Y,Q) - R*[Y/Q] + M if < 0\n!\n! The generator is augmented with Marsaglia shift operartors for a \n! 64-bit random number generator\n!\n! Dependencies:\n!\n! Modules:\n!\n! None\n!\n! Subroutines:\n!\n! None\n!\n! External functions:\n!\n! None\n!\n! MPI routines:\n!\n! None\n!\n! Licensing:\n!\n! SPDX-License-Identifier: MIT \n!\n! Date:\n!\n! 11 May 2021\n!\n! Author:\n!\n! Erich Ormand, LLNL\n!\n!*******************************************************************************\n!\n implicit none\n integer, parameter :: int32 = selected_int_kind(9)\n integer(kind=int32), intent(inout) :: iseed_32\n integer(kind=int32), save :: A, M, Q, R\n integer(kind=int32), save :: kk\n real(kind=8), save :: AM\n integer(kind=int32), save :: i1 = -1_int32, i2 = -1_int32\n!----------------------------------------------------------\n if(iseed_32 <= 0_int32 .or. i2 < 0_int32)then ! Initialize the seed\n M = 2147483647_int32\n A = 16807_int32\n Q = 127773_int32\n R = 2836_int32\n AM = nearest(1.0d0,-1.0d0)/M\n i2 = ior(ieor(888889999_int32,abs(iseed_32)),1_int32)\n i1 = ieor(777755555_int32, abs(iseed_32))\n iseed_32 = abs(iseed_32) + 1\n end if\n\n i1 = ieor(i1,ishft(i1,13)) ! Apply Marasglia shift sequence\n i1 = ieor(i1,ishft(i1,-17))\n i1 = ieor(i1,ishft(i1,5))\n kk = i2/Q ! Compute mod using Schrage's algorithm\n i2 = A*(i2 - kk*Q) - R*kk\n if(i2 < 0)i2 = i2 + M\n\n random_32 = AM*ior(iand(M,ieor(i1,i2)),1_int32) ! Combine generators\n return\nend function random_32\n", "meta": {"hexsha": "01dd5c935b3baff94436d24acafea3708a03a372", "size": 2335, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Src/random_32.f90", "max_stars_repo_name": "LLNL/Yet-Another-Hauser-Feshbach-Code", "max_stars_repo_head_hexsha": "18af2fea77d0263986648b057c06bd96f87ae8e0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-11-05T23:37:51.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-05T23:37:53.000Z", "max_issues_repo_path": "Src/random_32.f90", "max_issues_repo_name": "LLNL/Yet-Another-Hauser-Feshbach-Code", "max_issues_repo_head_hexsha": "18af2fea77d0263986648b057c06bd96f87ae8e0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Src/random_32.f90", "max_forks_repo_name": "LLNL/Yet-Another-Hauser-Feshbach-Code", "max_forks_repo_head_hexsha": "18af2fea77d0263986648b057c06bd96f87ae8e0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-11-05T23:38:28.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-10T21:34:37.000Z", "avg_line_length": 24.8404255319, "max_line_length": 87, "alphanum_fraction": 0.5057815846, "num_tokens": 749, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480244025281, "lm_q2_score": 0.7279754489059774, "lm_q1q2_score": 0.6686310679555756}} {"text": "SUBROUTINE geom_freesurf(iel,nxe,fixed_seep,fixed_down,down, &\r\n width,angs,surf,coord,num)\r\n!\r\n! This subroutine forms the coordinates and steering vector\r\n! for 4-node quads numbering in the x-direction\r\n! (Laplace's equation, variable mesh, 1-freedom per node).\r\n!\r\n IMPLICIT NONE\r\n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\r\n REAL(iwp),INTENT(IN)::width(:),angs(:),surf(:),down \r\n REAL(iwp),INTENT(OUT)::coord(:,:)\r\n INTEGER,INTENT(IN)::iel,nxe,fixed_seep,fixed_down\r\n INTEGER,INTENT(OUT)::num(:)\r\n REAL(iwp)::angr(SIZE(angs)),pi,b1,b2,tan1,tan2,fac1,fac2,zero=0.0_iwp, &\r\n pt5=0.5_iwp,one=1.0_iwp,small=0.0001_iwp,d180=180.0_iwp\r\n INTEGER::ip,iq\r\n pi=ACOS(-one)\r\n angr=angs*pi/d180 \r\n iq=(iel-1)/nxe+1\r\n ip=iel-(iq-1)*nxe\r\n num(1)=iq*(nxe+1)+ip\r\n num(2)=(iq-1)*(nxe+1)+ip\r\n num(3)=num(2)+1\r\n num(4)=num(1)+1\r\n IF(iq<=fixed_seep+1)THEN\r\n b1=(surf(ip)-down)/real(fixed_seep+1)\r\n b2=(surf(ip+1)-down)/real(fixed_seep+1)\r\n coord(1,2)=down+(fixed_seep+1-iq)*b1 \r\n coord(2,2)=down+(fixed_seep+2-iq)*b1\r\n coord(3,2)=down+(fixed_seep+2-iq)*b2 \r\n coord(4,2)=down+(fixed_seep+1-iq)*b2\r\n ELSE\r\n b1=real(fixed_down+fixed_seep-iq)/real(fixed_down-1) \r\n b2=real(fixed_down+fixed_seep-iq+1)/real(fixed_down-1) \r\n coord(1,2)=down*b1\r\n coord(2,2)=down*b2\r\n coord(3,2)=coord(2,2)\r\n coord(4,2)=coord(1,2)\r\n END IF\r\n IF(ABS(angr(ip)-pi*pt5) mass of sun (real scalar)\nc mpl ==> mass of sun (real scalar)\nc xh,yh,zh ==> position of pl in helio coord \nc (real scalars)\nc vxh,vyh,vzh ==> velocity of pl in helio coord \nc (real scalars)\nc Output:\nc rhill ==> the radius of planet's hill's sphere \nc (real scalar)\nc\nc\nc Remarks: Based on util_hill\nc Authors: Hal Levison \nc Date: 1/8/97\nc Last revision: \n\n subroutine util_hills1(msun,mpl,xh,yh,zh,vxh,vyh,vzh,rhill) \n\n include '../swift.inc'\n\nc... Inputs: \n real*8 msun,mpl,xh,yh,zh\n real*8 vxh,vyh,vzh\n\nc... Outputs\n real*8 rhill\n\nc... Internals\n real*8 mu,energy,ap,r,v2\n\nc-----\nc... Executable code \n\n mu = msun*mpl/(msun+mpl)\n r = sqrt( xh*xh + yh*yh + zh*zh )\n v2 = vxh*vxh + vyh*vyh + vzh*vzh\n energy =-1.0d0*msun*mpl/r + 0.5*mu*v2\n ap = -1.0d0*msun*mpl/(2.0d0*energy)\n rhill = ap * (((mu/msun)/3.0)**(0.3333333333d0))\n \n return\n end ! util_hills1\n\nc---------------------------------------------------\n", "meta": {"hexsha": "afa86ff0c56084f1104459054aa0edbf258340b3", "size": 1544, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/swift_j/util/util_hills1.f", "max_stars_repo_name": "Simske/exostriker", "max_stars_repo_head_hexsha": "587b0af4c9cadb46637a4ac61a5392a596e966b1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 69, "max_stars_repo_stars_event_min_datetime": "2020-01-06T13:31:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T11:23:14.000Z", "max_issues_repo_path": "exostriker/source/swift_j/util/util_hills1.f", "max_issues_repo_name": "sai-33/Exostriker", "max_issues_repo_head_hexsha": "f59fa51c6bdce3a2ed51d6621fe42bfcd8c2846f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 67, "max_issues_repo_issues_event_min_datetime": "2019-11-30T14:45:05.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-14T20:26:06.000Z", "max_forks_repo_path": "exostriker/source/swift_j/util/util_hills1.f", "max_forks_repo_name": "sai-33/Exostriker", "max_forks_repo_head_hexsha": "f59fa51c6bdce3a2ed51d6621fe42bfcd8c2846f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2020-01-06T13:44:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T11:23:17.000Z", "avg_line_length": 30.2745098039, "max_line_length": 74, "alphanum_fraction": 0.4158031088, "num_tokens": 426, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582632076909, "lm_q2_score": 0.7185944046238981, "lm_q1q2_score": 0.6686221016771169}} {"text": " subroutine soltmxmn(month,day,dtsec,dtlocal,tmax,tmin,rlat,\n + rsmin,rsmax,rgl,xlai,sfsl,solardt)\nc\nc--------------------------------------------------------------------------------\nc Estimation incomming short wave solar radiation from Bristow & Campbell (1984)\nc relationship for daily total radiation: Rg=So * Ktrs, in cal/(cm2*day)\nc where Ktrs is the atmosphere transmissivity, dimensionless:\nc Ktrs = A(1-EXP(-B*(tmax-tmin)**C)); A, B, & C parameters: A=0.75, B=0.004\nc (summer, May-October) or =0.01 (winter, Noevmber-April), and C=2.4\nc So is the clear sky solar irradiance on the horisontal plane (Dingman):\nc So = 2*RISC *Eo *(cos(lat)cos(dlt)sin(rot*Trs)/rot+sin(lat)sin(dlt)Trs)\nc RISC is the solar constant = 117.54 cal/(cm2*hr), Eo is the eccentricity \nc correction, lat is the latitude, dlt is the sun declinantion, rot is the \nc angular velocity of the earth's rotation =0.2618 radian/hr, and Trs is \nc a half of the daylight time in hrs\nc Estmated daily radiation Rg then converted into time interval instantenious \nc radiation values using sun angle at a specific time interval\nc solardt() - time interval average radiation, W/m2\nc rgx() - time interval factors to distribute hourly average radiation \nc tnoon - local noon time\nc dtlocal - difference between local and Z time\nc sfsl - is daily sum of canopy resistance factors to solar radiation which\nc will be used to distribute daily ET demand \nc--------------------------------------------------------------------------------\nc\n parameter (A = 0.75, BSM = 0.004, BWT = 0.01, C = 2.4)\n parameter (ROTV = 0.2618, RISC = 117.54)\n parameter (TNOON = 12.0)\n \n real solardt(144),rgx(144)\n integer dtlocal\n \nc calculate atmospheric transmissivity, radj\n if(month .ge. 5 .and. month .le. 10) then\n B=BSM\n else\n B=BWT\n endif\n radj=A*(1.0-EXP(-B*(tmax-tmin)**C))\n \nc get sun rise/set \n call sunrset(month,day,rlat,rise,set,sin_term,\n + cos_term,reldst)\n\nc getting hourly average daily solar radiation, cal/(cm2*hr)\n trs=TNOON-rise\n trmis=2*(cos_term*sin(ROTV*trs)/ROTV+sin_term*trs)\n solar=RISC*reldst*trmis*radj\n\nc loop throuugh day by each time interval \n ntnoon=TNOON*3600/dtsec+0.001\n ndhr=24*3600/dtsec+0.001\n srg=0.0\n ind=0\n rgx(ndhr)=0.0\n do i=1,ntnoon\n time=i*dtsec/3600.\n stime=time-TNOON\n if(time .le. rise) then\n rgx(i)=0.0\n rgx(ndhr-i)=0.0\n else\n rgx(i)=sin_term+cos_term*cos(ROTV*stime)\n rgx(ndhr-i)=rgx(i)\n endif\n srg=srg+2*rgx(i)\n enddo\n srg=srg-rgx(ntnoon)\n\n ist=24-dtlocal\n sfsl=0.0 \n do i=1,ndhr\ncc time interval radiation in cal/(cm2*dt)\n solarx=solar*rgx(i)/srg\ncc time interval radiation in W/m2\n if(i .le. ist) then\n k=i+dtlocal\n else\n k=i-ist\n endif\n solardt(k)=41840*solarx/dtsec\ncc calculate daily total radiation term of canopy resistance\n fx=0.55*2.0*solardt(k)/(rgl*xlai)\n sfsl=sfsl+(rsmin/rsmax+fx)/(1.0+fx)\n enddo\n\n return\n end\n \n \n \n \n", "meta": {"hexsha": "eabd1e6a0402609a78f31702d4ca3e4e3e773824", "size": 3279, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "lis/surfacemodels/land/rdhm.3.5.6/sachtet/soltmxmn.f", "max_stars_repo_name": "KathyNie/LISF", "max_stars_repo_head_hexsha": "5c3e8b94494fac5ff76a1a441a237e32af420d06", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 67, "max_stars_repo_stars_event_min_datetime": "2018-11-13T21:40:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-23T08:11:56.000Z", "max_issues_repo_path": "lis/surfacemodels/land/rdhm.3.5.6/sachtet/soltmxmn.f", "max_issues_repo_name": "dmocko/LISF", "max_issues_repo_head_hexsha": "08d024d6d5fe66db311e43e78740842d653749f4", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 679, "max_issues_repo_issues_event_min_datetime": "2018-11-13T20:10:29.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T19:55:25.000Z", "max_forks_repo_path": "lis/surfacemodels/land/rdhm.3.5.6/sachtet/soltmxmn.f", "max_forks_repo_name": "dmocko/LISF", "max_forks_repo_head_hexsha": "08d024d6d5fe66db311e43e78740842d653749f4", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 119, "max_forks_repo_forks_event_min_datetime": "2018-11-08T15:53:35.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-28T10:16:01.000Z", "avg_line_length": 35.2580645161, "max_line_length": 81, "alphanum_fraction": 0.5913388228, "num_tokens": 1041, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582612793112, "lm_q2_score": 0.7185944046238981, "lm_q1q2_score": 0.668622100291394}} {"text": "! Subroutine GEOMAG\n!\n! Excerpted from the IRI package, Stan Solomon, 6/1988. Original name was\n! GMAG, which was changed to avoid conflict when used at the same time\n! as IRI. Labeled common /CONST/ which contained only the degree/radian\n! conversion factor was changed to a data statement. Longitude range\n! from -180 to 180.\n!\n! Minor refactor to f90, SCS, 2016.\n!\n! CALCULATES GEOMAGNETIC LONGITUDE (MLONG) AND LATITUDE (MLAT)\n! FROM GEOGRAFIC LONGITUDE (LONG) AND LATITUDE (LATI) FOR ART=0\n! AND REVERSE FOR ART=1. ALL ANGLES IN DEGREE.\n! LATITUDE:-90 TO 90. LONGITUDE:0 TO 360 EAST.\n!\n SUBROUTINE GEOMAG(ART,LONG,LATI,MLONG,MLAT)\n INTEGER ART\n REAL MLONG,MLAT,LONG,LATI\n DATA FAKTOR/.0174532952/\n ZPI=FAKTOR*360.\n CBG=11.4*FAKTOR\n CI=COS(CBG)\n SI=SIN(CBG)\n IF(ART.NE.0) THEN\n CBM=COS(MLAT*FAKTOR)\n SBM=SIN(MLAT*FAKTOR)\n CLM=COS(MLONG*FAKTOR)\n SLM=SIN(MLONG*FAKTOR)\n SBG=SBM*CI-CBM*CLM*SI\n LATI=ASIN(SBG)\n CBG=COS(LATI)\n SLG=(CBM*SLM)/CBG\n CLG=(SBM*SI+CBM*CLM*CI)/CBG\n IF(CLG.GT.1.) CLG=1.\n LONG=ACOS(CLG)\n IF(SLG.LT.0.0) LONG=ZPI-ACOS(CLG)\n LATI=LATI/FAKTOR\n LONG=LONG/FAKTOR\n LONG=LONG-69.8\n IF(LONG.LT.-180.0) LONG=LONG+360.0\n IF(LONG.GT. 180.0) LONG=LONG-360.0\n ELSE\n YLG=LONG+69.8\n CBG=COS(LATI*FAKTOR)\n SBG=SIN(LATI*FAKTOR)\n CLG=COS(YLG*FAKTOR)\n SLG=SIN(YLG*FAKTOR)\n SBM=SBG*CI+CBG*CLG*SI\n MLAT=ASIN(SBM)\n CBM=COS(MLAT)\n SLM=(CBG*SLG)/CBM\n CLM=(-SBG*SI+CBG*CLG*CI)/CBM\n IF(CLM.GT.1.) CLM=1.\n MLONG=ACOS(CLM)\n IF(SLM.LT..0) MLONG=ZPI-ACOS(CLM)\n MLAT=MLAT/FAKTOR\n MLONG=MLONG/FAKTOR\n IF(MLONG.LT.-180.0) MLONG=MLONG+360.0\n IF(MLONG.GT. 180.0) MLONG=MLONG-360.0\n ENDIF\n RETURN\n END SUBROUTINE GEOMAG\n", "meta": {"hexsha": "76e25b805bfa4fe444740612ad1a70dd8a656ceb", "size": 1910, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/ncarglow/fortran/geomag.f90", "max_stars_repo_name": "scivision/NCAR-GLOW", "max_stars_repo_head_hexsha": "09cfd372ec6f87c24f0a5c2d63f916166c1c98fa", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-06-06T15:13:51.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-16T08:50:52.000Z", "max_issues_repo_path": "src/ncarglow/fortran/geomag.f90", "max_issues_repo_name": "space-physics/NCAR-GLOW", "max_issues_repo_head_hexsha": "09cfd372ec6f87c24f0a5c2d63f916166c1c98fa", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2019-09-29T17:03:05.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-14T15:38:15.000Z", "max_forks_repo_path": "src/ncarglow/fortran/geomag.f90", "max_forks_repo_name": "space-physics/NCAR-GLOW", "max_forks_repo_head_hexsha": "09cfd372ec6f87c24f0a5c2d63f916166c1c98fa", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-06-06T15:07:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-06T16:17:11.000Z", "avg_line_length": 30.3174603175, "max_line_length": 74, "alphanum_fraction": 0.6036649215, "num_tokens": 771, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582554941718, "lm_q2_score": 0.7185943925708561, "lm_q1q2_score": 0.6686220849193728}} {"text": " FUNCTION DKLS(NP,I,L,R,Z)\r\nC-----\r\nC THIS ROUTINE CALCULATES THE SINGLE PRECISION INTEGRALS FOR\r\nC AXISYMMETRIC SOLIDS IN EMG\r\nC\r\nC INPUT\r\nC NP = NUMBER OF POINTS (3 OR 4)\r\nC I,L= THE INTEGRAL DESIRED (I SERIES STARTS WITH -1)\r\nC R = RADIUS ARRAY (NP LONG)\r\nC Z = Z-CORD ARRAY (NP LONG)\r\nC\r\nC OUTPUT\r\nC DKL = DESIRED INTEGRAL\r\nC\r\nC-----\r\n INTEGER NAM(2)\r\n REAL R(3),Z(3)\r\n DATA EPS /.01/, NAM /4HDKLS ,1H /\r\n DATA ZERO, ONE, TWO / 0., 1., 2. /\r\nC\r\n DKLS= ZERO\r\n L1 = L+1\r\n L2 = L + 2\r\n DL1 = L1\r\n K = I+1\r\nC\r\nC . LOOP ON NUMBER OF POINTS...\r\n IF (R(1).LE.ZERO) GO TO 300\r\n DO 200 M = 1,NP\r\n J = M+1\r\n IF (M.EQ.NP) J = 1\r\n RA = R(M)\r\n RB = R(J)\r\n ZA = Z(M)\r\n ZB = Z(J)\r\n DR = RB-RA\r\n DZ = ZB-ZA\r\nC\r\nC . TEST IF RADIUS IS .LE. 0 (DRIVER SHOULD FIND THIS)...\r\n IF (RB.LE.ZERO) GO TO 300\r\n GKL = ZERO\r\n PR = RA+RB\r\n AR = PR / TWO\r\nC\r\nC . CHECK FOR APPROXIMATION, DR/AVE(R)...\r\n IF (ABS(DR/AR) .LT. EPS) GO TO 70\r\nC\r\n A = ZA*DR - RA*DZ\r\n BETA = A/DR\r\nC\r\nC . CHECK FOR BETA .EQ. 0 CASE...\r\n IF ( ABS (BETA / AR ) .GT. EPS ) GO TO 10\r\nC\r\n IF (DZ.EQ.ZERO) GO TO 200\r\n LK = L + K + 1\r\n AR = LK\r\n GKL = (DZ/DR)**L1 * (RA**LK-RB**LK) / (DL1*AR)\r\n GO TO 200\r\nC\r\nC . GENERAL CASE...\r\n 10 RAK = RA**K\r\n RBK = RB**K\r\n IF ( K ) 300,20,30\r\nC\r\nC . GENERAL CASE, K.EQ.0, CONSTANT TERM...\r\n 20 GKL = ALOG(RA/RB)/DL1\r\n GO TO 40\r\nC\r\nC . GENERAL CASE, CONSTANT TERM...\r\n 30 AR = K * L1\r\n GKL = (RAK - RBK) / AR\r\nC\r\nC . GENERAL CASE, SUMMATION...\r\n 40 IF (DZ.EQ.ZERO) GO TO 65\r\n LFACT = 1\r\nC . CALCULATE FACTORIAL (L+1)...\r\n DO 50 J = 2,L\r\n 50 LFACT = LFACT * J\r\n FACTL = LFACT\r\n JFACT = 1\r\n AJ = ONE\r\n DZJ = ONE\r\n LMJF= LFACT * L1\r\n DO 60 J = 1,L1\r\n JFACT = JFACT * J\r\nC . CALCULATE (L+1-J) FACTORIAL IN LMJF...\r\n LMJF = LMJF / (L2-J)\r\n FACT = FACTL / FLOAT (JFACT*LMJF)\r\n DFACT = K + J\r\n DFACT = FACT / DFACT\r\n AJ = AJ * A\r\n RAK = RAK * RA\r\n RBK = RBK * RB\r\n DZJ = DZJ * DZ\r\n 60 GKL = GKL + (DFACT * DZJ * (RAK-RBK)) / AJ\r\nC-----\r\n 65 GKL = GKL * BETA**L1\r\n GO TO 200\r\nC\r\nC . APPROXIMATE CODE...\r\n 70 CONTINUE\r\n IF (DR.EQ.ZERO) GO TO 200\r\n DZJ = L1 * L2\r\n RBK = ZB**L1\r\n J = K - 1\r\n GKL = -DR * AR**J * RBK / DL1\r\nC\r\n IF (DZ.EQ.ZERO) GO TO 200\r\n GKL = GKL + (((2.*RA+RB)/3.)**J *DR*ABS(ZA**L2 - RBK*ZB))/(DZJ*DZ)\r\nC\r\n 200 DKLS= DKLS+ GKL\r\nC-----\r\nC\r\nC . ALL DONE\r\nC\r\n 210 CONTINUE\r\n RETURN\r\nC\r\nC . ERROR...\r\nC\r\n 300 CALL MESAGE (-7,K,NAM)\r\n GO TO 210\r\n END\r\n", "meta": {"hexsha": "3d12078da641fc9893fb273541df16bcd9ed2fa2", "size": 2738, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "mis/dkls.f", "max_stars_repo_name": "ldallolio/NASTRAN-95", "max_stars_repo_head_hexsha": "6d2c175f5b53ebaec4ba2b5186f7926ef9d0ed47", "max_stars_repo_licenses": ["NASA-1.3"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2016-01-09T14:33:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-18T11:51:42.000Z", "max_issues_repo_path": "mis/dkls.f", "max_issues_repo_name": "gassive/NASTRAN95", "max_issues_repo_head_hexsha": "98cb3acaa7990d639360601648498834c7782056", "max_issues_repo_licenses": ["NASA-1.3"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2016-01-17T07:30:19.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-06T19:37:44.000Z", "max_forks_repo_path": "mis/dkls.f", "max_forks_repo_name": "gassive/NASTRAN95", "max_forks_repo_head_hexsha": "98cb3acaa7990d639360601648498834c7782056", "max_forks_repo_licenses": ["NASA-1.3"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-04-07T20:51:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T14:16:01.000Z", "avg_line_length": 22.0806451613, "max_line_length": 73, "alphanum_fraction": 0.4656683711, "num_tokens": 1136, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582554941719, "lm_q2_score": 0.718594386544335, "lm_q1q2_score": 0.6686220793119466}} {"text": "c\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc . .\nc . copyright (c) 1998 by UCAR .\nc . .\nc . University Corporation for Atmospheric Research .\nc . .\nc . all rights reserved .\nc . .\nc . .\nc . SPHEREPACK .\nc . .\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc\nc\nc\nc ... file vtsec.f\nc\nc this file includes documentation and code for\nc subroutines vtsec and vtseci\nc\nc ... files which must be loaded with vtsec.f\nc\nc sphcom.f, hrfft.f, vhaec.f, vhsec.f\nc \nc subroutine vtsec(nlat,nlon,ityp,nt,vt,wt,idvw,jdvw,br,bi,cr,ci,\nc + mdab,ndab,wvts,lwvts,work,lwork,ierror)\nc\nc given the vector harmonic analysis br,bi,cr, and ci (computed\nc by subroutine vhaec) of some vector function (v,w), this \nc subroutine computes the vector function (vt,wt) which is\nc the derivative of (v,w) with respect to colatitude theta. vtsec\nc is similar to vhsec except the vector harmonics are replaced by \nc their derivative with respect to colatitude with the result that\nc (vt,wt) is computed instead of (v,w). vt(i,j) is the derivative\nc of the colatitudinal component v(i,j) at the point theta(i) =\nc (i-1)*pi/(nlat-1) and longitude phi(j) = (j-1)*2*pi/nlon. the\nc spectral representation of (vt,wt) is given below at output\nc parameters vt,wt.\nc\nc input parameters\nc\nc nlat the number of colatitudes on the full sphere including the\nc poles. for example, nlat = 37 for a five degree grid.\nc nlat determines the grid increment in colatitude as\nc pi/(nlat-1). if nlat is odd the equator is located at\nc grid point i=(nlat+1)/2. if nlat is even the equator is\nc located half way between points i=nlat/2 and i=nlat/2+1.\nc nlat must be at least 3. note: on the half sphere, the\nc number of grid points in the colatitudinal direction is\nc nlat/2 if nlat is even or (nlat+1)/2 if nlat is odd.\nc\nc nlon the number of distinct londitude points. nlon determines\nc the grid increment in longitude as 2*pi/nlon. for example\nc nlon = 72 for a five degree grid. nlon must be greater\nc than zero. the axisymmetric case corresponds to nlon=1.\nc the efficiency of the computation is improved when nlon\nc is a product of small prime numbers.\nc\nc ityp = 0 no symmetries exist about the equator. the synthesis\nc is performed on the entire sphere. i.e. the arrays\nc vt(i,j),wt(i,j) are computed for i=1,...,nlat and\nc j=1,...,nlon. \nc\nc = 1 no symmetries exist about the equator however the\nc the coefficients cr and ci are zero. the synthesis\nc is performed on the entire sphere. i.e. the arrays\nc vt(i,j),wt(i,j) are computed for i=1,...,nlat and\nc j=1,...,nlon.\nc\nc = 2 no symmetries exist about the equator however the\nc the coefficients br and bi are zero. the synthesis\nc is performed on the entire sphere. i.e. the arrays\nc vt(i,j),wt(i,j) are computed for i=1,...,nlat and \nc j=1,...,nlon.\nc\nc = 3 vt is odd and wt is even about the equator. the \nc synthesis is performed on the northern hemisphere\nc only. i.e., if nlat is odd the arrays vt(i,j),wt(i,j)\nc are computed for i=1,...,(nlat+1)/2 and j=1,...,nlon.\nc if nlat is even the arrays vt(i,j),wt(i,j) are computed \nc for i=1,...,nlat/2 and j=1,...,nlon.\nc\nc = 4 vt is odd and wt is even about the equator and the \nc coefficients cr and ci are zero. the synthesis is\nc performed on the northern hemisphere only. i.e. if\nc nlat is odd the arrays vt(i,j),wt(i,j) are computed\nc for i=1,...,(nlat+1)/2 and j=1,...,nlon. if nlat is\nc even the arrays vt(i,j),wt(i,j) are computed for \nc i=1,...,nlat/2 and j=1,...,nlon.\nc\nc = 5 vt is odd and wt is even about the equator and the \nc coefficients br and bi are zero. the synthesis is\nc performed on the northern hemisphere only. i.e. if\nc nlat is odd the arrays vt(i,j),wt(i,j) are computed\nc for i=1,...,(nlat+1)/2 and j=1,...,nlon. if nlat is\nc even the arrays vt(i,j),wt(i,j) are computed for \nc i=1,...,nlat/2 and j=1,...,nlon.\nc\nc = 6 vt is even and wt is odd about the equator. the \nc synthesis is performed on the northern hemisphere\nc only. i.e., if nlat is odd the arrays vt(i,j),wt(i,j)\nc are computed for i=1,...,(nlat+1)/2 and j=1,...,nlon.\nc if nlat is even the arrays vt(i,j),wt(i,j) are computed \nc for i=1,...,nlat/2 and j=1,...,nlon.\nc\nc = 7 vt is even and wt is odd about the equator and the \nc coefficients cr and ci are zero. the synthesis is\nc performed on the northern hemisphere only. i.e. if\nc nlat is odd the arrays vt(i,j),wt(i,j) are computed\nc for i=1,...,(nlat+1)/2 and j=1,...,nlon. if nlat is\nc even the arrays vt(i,j),wt(i,j) are computed for \nc i=1,...,nlat/2 and j=1,...,nlon.\nc\nc = 8 vt is even and wt is odd about the equator and the \nc coefficients br and bi are zero. the synthesis is\nc performed on the northern hemisphere only. i.e. if\nc nlat is odd the arrays vt(i,j),wt(i,j) are computed\nc for i=1,...,(nlat+1)/2 and j=1,...,nlon. if nlat is\nc even the arrays vt(i,j),wt(i,j) are computed for \nc i=1,...,nlat/2 and j=1,...,nlon.\nc\nc nt the number of syntheses. in the program that calls vtsec,\nc the arrays vt,wt,br,bi,cr, and ci can be three dimensional\nc in which case multiple syntheses will be performed.\nc the third index is the synthesis index which assumes the \nc values k=1,...,nt. for a single synthesis set nt=1. the\nc discription of the remaining parameters is simplified\nc by assuming that nt=1 or that all the arrays are two\nc dimensional.\nc\nc idvw the first dimension of the arrays vt,wt as it appears in\nc the program that calls vtsec. if ityp .le. 2 then idvw\nc must be at least nlat. if ityp .gt. 2 and nlat is\nc even then idvw must be at least nlat/2. if ityp .gt. 2\nc and nlat is odd then idvw must be at least (nlat+1)/2.\nc\nc jdvw the second dimension of the arrays vt,wt as it appears in\nc the program that calls vtsec. jdvw must be at least nlon.\nc\nc br,bi two or three dimensional arrays (see input parameter nt)\nc cr,ci that contain the vector spherical harmonic coefficients\nc of (v,w) as computed by subroutine vhaec.\nc\nc mdab the first dimension of the arrays br,bi,cr, and ci as it\nc appears in the program that calls vtsec. mdab must be at\nc least min0(nlat,nlon/2) if nlon is even or at least\nc min0(nlat,(nlon+1)/2) if nlon is odd.\nc\nc ndab the second dimension of the arrays br,bi,cr, and ci as it\nc appears in the program that calls vtsec. ndab must be at\nc least nlat.\nc\nc wvts an array which must be initialized by subroutine vtseci.\nc once initialized, wvts can be used repeatedly by vtsec\nc as long as nlon and nlat remain unchanged. wvts must\nc not be altered between calls of vtsec.\nc\nc lwvts the dimension of the array wvts as it appears in the\nc program that calls vtsec. define\nc\nc l1 = min0(nlat,nlon/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc and\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc then lwvts must be at least\nc\nc 4*nlat*l2+3*max0(l1-2,0)*(nlat+nlat-l1-1)+nlon+15\nc\nc\nc work a work array that does not have to be saved.\nc\nc lwork the dimension of the array work as it appears in the\nc program that calls vtsec. define\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc if ityp .le. 2 then lwork must be at least\nc\nc nlat*(2*nt*nlon+max0(6*l2,nlon))\nc\nc if ityp .gt. 2 then lwork must be at least\nc\nc l2*(2*nt*nlon+max0(6*nlat,nlon))\nc\nc **************************************************************\nc\nc output parameters\nc\nc vt,wt two or three dimensional arrays (see input parameter nt)\nc in which the derivative of (v,w) with respect to \nc colatitude theta is stored. vt(i,j),wt(i,j) contain the\nc derivatives at colatitude theta(i) = (i-1)*pi/(nlat-1)\nc and longitude phi(j) = (j-1)*2*pi/nlon. the index ranges\nc are defined above at the input parameter ityp. vt and wt\nc are computed from the formulas for v and w given in \nc subroutine vhsec but with vbar and wbar replaced with\nc their derivatives with respect to colatitude. these\nc derivatives are denoted by vtbar and wtbar. \nc\nc in terms of real variables this expansion takes the form\nc\nc for i=1,...,nlat and j=1,...,nlon\nc\nc vt(i,j) = the sum from n=1 to n=nlat-1 of\nc\nc .5*br(1,n+1)*vtbar(0,n,theta(i))\nc\nc plus the sum from m=1 to m=mmax-1 of the sum from n=m to \nc n=nlat-1 of the real part of\nc\nc (br(m+1,n+1)*vtbar(m,n,theta(i))\nc -ci(m+1,n+1)*wtbar(m,n,theta(i)))*cos(m*phi(j))\nc -(bi(m+1,n+1)*vtbar(m,n,theta(i))\nc +cr(m+1,n+1)*wtbar(m,n,theta(i)))*sin(m*phi(j))\nc\nc and for i=1,...,nlat and j=1,...,nlon\nc\nc wt(i,j) = the sum from n=1 to n=nlat-1 of\nc\nc -.5*cr(1,n+1)*vtbar(0,n,theta(i))\nc\nc plus the sum from m=1 to m=mmax-1 of the sum from n=m to\nc n=nlat-1 of the real part of\nc\nc -(cr(m+1,n+1)*vtbar(m,n,theta(i))\nc +bi(m+1,n+1)*wtbar(m,n,theta(i)))*cos(m*phi(j))\nc +(ci(m+1,n+1)*vtbar(m,n,theta(i))\nc -br(m+1,n+1)*wtbar(m,n,theta(i)))*sin(m*phi(j))\nc\nc\nc br(m+1,nlat),bi(m+1,nlat),cr(m+1,nlat), and ci(m+1,nlat) are\nc assumed zero for m even.\nc\nc\nc ierror = 0 no errors\nc = 1 error in the specification of nlat\nc = 2 error in the specification of nlon\nc = 3 error in the specification of ityp\nc = 4 error in the specification of nt\nc = 5 error in the specification of idvw\nc = 6 error in the specification of jdvw\nc = 7 error in the specification of mdab\nc = 8 error in the specification of ndab\nc = 9 error in the specification of lwvts\nc = 10 error in the specification of lwork\nc\nc\nc *******************************************************************\nc\nc subroutine vtseci(nlat,nlon,wvts,lwvts,dwork,ldwork,ierror)\nc\nc subroutine vtseci initializes the array wvts which can then be\nc used repeatedly by subroutine vtsec until nlat or nlon is changed.\nc\nc input parameters\nc\nc nlat the number of colatitudes on the full sphere including the\nc poles. for example, nlat = 37 for a five degree grid.\nc nlat determines the grid increment in colatitude as\nc pi/(nlat-1). if nlat is odd the equator is located at\nc grid point i=(nlat+1)/2. if nlat is even the equator is\nc located half way between points i=nlat/2 and i=nlat/2+1.\nc nlat must be at least 3. note: on the half sphere, the\nc number of grid points in the colatitudinal direction is\nc nlat/2 if nlat is even or (nlat+1)/2 if nlat is odd.\nc\nc nlon the number of distinct londitude points. nlon determines\nc the grid increment in longitude as 2*pi/nlon. for example\nc nlon = 72 for a five degree grid. nlon must be greater\nc than zero. the axisymmetric case corresponds to nlon=1.\nc the efficiency of the computation is improved when nlon\nc is a product of small prime numbers.\nc\nc lwvts the dimension of the array wvts as it appears in the\nc program that calls vtsec. define\nc\nc l1 = min0(nlat,nlon/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc and\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc then lwvts must be at least\nc\nc 4*nlat*l2+3*max0(l1-2,0)*(nlat+nlat-l1-1)+nlon+15\nc\nc\nc dwork a double precision work array that does not have to be saved.\nc\nc ldwork the dimension of the array work as it appears in the\nc program that calls vtsec. lwork must be at least\nc 2*(nlat+1)\nc\nc **************************************************************\nc\nc output parameters\nc\nc wvts an array which is initialized for use by subroutine vtsec.\nc once initialized, wvts can be used repeatedly by vtsec\nc as long as nlat or nlon remain unchanged. wvts must not\nc be altered between calls of vtsec.\nc\nc\nc ierror = 0 no errors\nc = 1 error in the specification of nlat\nc = 2 error in the specification of nlon\nc = 3 error in the specification of lwvts\nc = 4 error in the specification of ldwork\nc\nc **********************************************************************\nc \n subroutine vtsec(nlat,nlon,ityp,nt,vt,wt,idvw,jdvw,br,bi,cr,ci,\n 1 mdab,ndab,wvts,lwvts,work,lwork,ierror)\nc\n dimension vt(idvw,jdvw,1),wt(idvw,jdvw,1),br(mdab,ndab,1),\n 1 bi(mdab,ndab,1),cr(mdab,ndab,1),ci(mdab,ndab,1),\n 2 work(1),wvts(1)\n ierror = 1\n if(nlat .lt. 3) return\n ierror = 2\n if(nlon .lt. 1) return\n ierror = 3\n if(ityp.lt.0 .or. ityp.gt.8) return\n ierror = 4\n if(nt .lt. 0) return\n ierror = 5\n imid = (nlat+1)/2\n if((ityp.le.2 .and. idvw.lt.nlat) .or.\n 1 (ityp.gt.2 .and. idvw.lt.imid)) return\n ierror = 6\n if(jdvw .lt. nlon) return\n ierror = 7\n mmax = min0(nlat,(nlon+1)/2)\n if(mdab .lt. mmax) return\n ierror = 8\n if(ndab .lt. nlat) return\n ierror = 9\n lzz1 = 2*nlat*imid\n labc = 3*(max0(mmax-2,0)*(nlat+nlat-mmax-1))/2\n if(lwvts .lt. 2*(lzz1+labc)+nlon+15) return\n ierror = 10\n if(ityp .le. 2 .and. \n 1 lwork .lt. nlat*(2*nt*nlon+max0(6*imid,nlon))) return\n if(ityp .gt. 2 .and. \n 1 lwork .lt. imid*(2*nt*nlon+max0(6*nlat,nlon))) return\n ierror = 0\n idv = nlat\n if(ityp .gt. 2) idv = imid\n lnl = nt*idv*nlon\n ist = 0\n if(ityp .le. 2) ist = imid\n iw1 = ist+1\n iw2 = lnl+1\n iw3 = iw2+ist\n iw4 = iw2+lnl\n iw5 = iw4+3*imid*nlat\n lzz1 = 2*nlat*imid\n labc = 3*(max0(mmax-2,0)*(nlat+nlat-mmax-1))/2\n lwzvin = lzz1+labc\n jw1 = lwzvin+1\n jw2 = jw1+lwzvin\n call vtsec1(nlat,nlon,ityp,nt,imid,idvw,jdvw,vt,wt,mdab,ndab,\n 1 br,bi,cr,ci,idv,work,work(iw1),work(iw2),work(iw3),\n 2 work(iw4),work(iw5),wvts,wvts(jw1),wvts(jw2))\n return\n end\n subroutine vtsec1(nlat,nlon,ityp,nt,imid,idvw,jdvw,vt,wt,mdab,\n 1 ndab,br,bi,cr,ci,idv,vte,vto,wte,wto,vb,wb,wvbin,wwbin,wrfft)\n dimension vt(idvw,jdvw,1),wt(idvw,jdvw,1),br(mdab,ndab,1),\n 1 bi(mdab,ndab,1),cr(mdab,ndab,1),ci(mdab,ndab,1),\n 2 vte(idv,nlon,1),vto(idv,nlon,1),wte(idv,nlon,1),\n 3 wto(idv,nlon,1),wvbin(1),wwbin(1),wrfft(1),\n 4 vb(imid,nlat,3),wb(imid,nlat,3)\n nlp1 = nlat+1\n mlat = mod(nlat,2)\n mlon = mod(nlon,2)\n mmax = min0(nlat,(nlon+1)/2)\n imm1 = imid\n if(mlat .ne. 0) imm1 = imid-1\n do 10 k=1,nt\n do 10 j=1,nlon\n do 10 i=1,idv\n vte(i,j,k) = 0.\n wte(i,j,k) = 0.\n 10 continue\n ndo1 = nlat\n ndo2 = nlat\n if(mlat .ne. 0) ndo1 = nlat-1\n if(mlat .eq. 0) ndo2 = nlat-1\n 18 itypp = ityp+1\n go to (1,100,200,300,400,500,600,700,800),itypp\nc\nc case ityp=0 no symmetries\nc\n 1 call vbin(0,nlat,nlon,0,vb,iv,wvbin)\nc\nc case m = 0\nc\n do 15 k=1,nt\n do 15 np1=2,ndo2,2\n do 15 i=1,imm1\n vto(i,1,k)=vto(i,1,k)+br(1,np1,k)*vb(i,np1,iv)\n wto(i,1,k)=wto(i,1,k)-cr(1,np1,k)*vb(i,np1,iv)\n 15 continue\n do 16 k=1,nt\n do 16 np1=3,ndo1,2\n do 16 i=1,imid\n vte(i,1,k)=vte(i,1,k)+br(1,np1,k)*vb(i,np1,iv)\n wte(i,1,k)=wte(i,1,k)-cr(1,np1,k)*vb(i,np1,iv)\n 16 continue\nc\nc case m = 1 through nlat-1\nc\n if(mmax .lt. 2) go to 950\n do 30 mp1=2,mmax\n m = mp1-1\n mp2 = mp1+1\n call vbin(0,nlat,nlon,m,vb,iv,wvbin)\n call wbin(0,nlat,nlon,m,wb,iw,wwbin)\n if(mp1 .gt. ndo1) go to 26\n do 25 k=1,nt\n do 24 np1=mp1,ndo1,2\n do 23 i=1,imm1\n vte(i,2*mp1-2,k) = vte(i,2*mp1-2,k)+br(mp1,np1,k)*vb(i,np1,iv)\n vto(i,2*mp1-2,k) = vto(i,2*mp1-2,k)-ci(mp1,np1,k)*wb(i,np1,iw)\n vte(i,2*mp1-1,k) = vte(i,2*mp1-1,k)+bi(mp1,np1,k)*vb(i,np1,iv)\n vto(i,2*mp1-1,k) = vto(i,2*mp1-1,k)+cr(mp1,np1,k)*wb(i,np1,iw)\n wte(i,2*mp1-2,k) = wte(i,2*mp1-2,k)-cr(mp1,np1,k)*vb(i,np1,iv)\n wto(i,2*mp1-2,k) = wto(i,2*mp1-2,k)-bi(mp1,np1,k)*wb(i,np1,iw)\n wte(i,2*mp1-1,k) = wte(i,2*mp1-1,k)-ci(mp1,np1,k)*vb(i,np1,iv)\n wto(i,2*mp1-1,k) = wto(i,2*mp1-1,k)+br(mp1,np1,k)*wb(i,np1,iw)\n 23 continue\n if(mlat .eq. 0) go to 24\n vte(imid,2*mp1-2,k) = vte(imid,2*mp1-2,k)\n 1 +br(mp1,np1,k)*vb(imid,np1,iv)\n vte(imid,2*mp1-1,k) = vte(imid,2*mp1-1,k)\n 1 +bi(mp1,np1,k)*vb(imid,np1,iv)\n wte(imid,2*mp1-2,k) = wte(imid,2*mp1-2,k)\n 1 -cr(mp1,np1,k)*vb(imid,np1,iv) \n wte(imid,2*mp1-1,k) = wte(imid,2*mp1-1,k)\n 1 -ci(mp1,np1,k)*vb(imid,np1,iv)\n 24 continue\n 25 continue\n 26 if(mp2 .gt. ndo2) go to 30\n do 29 k=1,nt\n do 28 np1=mp2,ndo2,2\n do 27 i=1,imm1\n vto(i,2*mp1-2,k) = vto(i,2*mp1-2,k)+br(mp1,np1,k)*vb(i,np1,iv)\n vte(i,2*mp1-2,k) = vte(i,2*mp1-2,k)-ci(mp1,np1,k)*wb(i,np1,iw)\n vto(i,2*mp1-1,k) = vto(i,2*mp1-1,k)+bi(mp1,np1,k)*vb(i,np1,iv)\n vte(i,2*mp1-1,k) = vte(i,2*mp1-1,k)+cr(mp1,np1,k)*wb(i,np1,iw)\n wto(i,2*mp1-2,k) = wto(i,2*mp1-2,k)-cr(mp1,np1,k)*vb(i,np1,iv)\n wte(i,2*mp1-2,k) = wte(i,2*mp1-2,k)-bi(mp1,np1,k)*wb(i,np1,iw)\n wto(i,2*mp1-1,k) = wto(i,2*mp1-1,k)-ci(mp1,np1,k)*vb(i,np1,iv)\n wte(i,2*mp1-1,k) = wte(i,2*mp1-1,k)+br(mp1,np1,k)*wb(i,np1,iw)\n 27 continue\n if(mlat .eq. 0) go to 28\n vte(imid,2*mp1-2,k) = vte(imid,2*mp1-2,k)\n 1 -ci(mp1,np1,k)*wb(imid,np1,iw) \n vte(imid,2*mp1-1,k) = vte(imid,2*mp1-1,k)\n 1 +cr(mp1,np1,k)*wb(imid,np1,iw)\n wte(imid,2*mp1-2,k) = wte(imid,2*mp1-2,k)\n 1 -bi(mp1,np1,k)*wb(imid,np1,iw)\n wte(imid,2*mp1-1,k) = wte(imid,2*mp1-1,k)\n 1 +br(mp1,np1,k)*wb(imid,np1,iw)\n 28 continue\n 29 continue\n 30 continue\n go to 950\nc\nc case ityp=1 no symmetries, cr and ci equal zero\nc\n 100 call vbin(0,nlat,nlon,0,vb,iv,wvbin)\nc\nc case m = 0\nc\n do 115 k=1,nt\n do 115 np1=2,ndo2,2\n do 115 i=1,imm1\n vto(i,1,k)=vto(i,1,k)+br(1,np1,k)*vb(i,np1,iv)\n 115 continue\n do 116 k=1,nt\n do 116 np1=3,ndo1,2\n do 116 i=1,imid\n vte(i,1,k)=vte(i,1,k)+br(1,np1,k)*vb(i,np1,iv)\n 116 continue\nc\nc case m = 1 through nlat-1\nc\n if(mmax .lt. 2) go to 950\n do 130 mp1=2,mmax\n m = mp1-1\n mp2 = mp1+1\n call vbin(0,nlat,nlon,m,vb,iv,wvbin)\n call wbin(0,nlat,nlon,m,wb,iw,wwbin)\n if(mp1 .gt. ndo1) go to 126\n do 125 k=1,nt\n do 124 np1=mp1,ndo1,2\n do 123 i=1,imm1\n vte(i,2*mp1-2,k) = vte(i,2*mp1-2,k)+br(mp1,np1,k)*vb(i,np1,iv)\n vte(i,2*mp1-1,k) = vte(i,2*mp1-1,k)+bi(mp1,np1,k)*vb(i,np1,iv)\n wto(i,2*mp1-2,k) = wto(i,2*mp1-2,k)-bi(mp1,np1,k)*wb(i,np1,iw)\n wto(i,2*mp1-1,k) = wto(i,2*mp1-1,k)+br(mp1,np1,k)*wb(i,np1,iw)\n 123 continue\n if(mlat .eq. 0) go to 124\n vte(imid,2*mp1-2,k) = vte(imid,2*mp1-2,k)\n 1 +br(mp1,np1,k)*vb(imid,np1,iv)\n vte(imid,2*mp1-1,k) = vte(imid,2*mp1-1,k)\n 1 +bi(mp1,np1,k)*vb(imid,np1,iv)\n 124 continue\n 125 continue\n 126 if(mp2 .gt. ndo2) go to 130\n do 129 k=1,nt\n do 128 np1=mp2,ndo2,2\n do 127 i=1,imm1\n vto(i,2*mp1-2,k) = vto(i,2*mp1-2,k)+br(mp1,np1,k)*vb(i,np1,iv)\n vto(i,2*mp1-1,k) = vto(i,2*mp1-1,k)+bi(mp1,np1,k)*vb(i,np1,iv)\n wte(i,2*mp1-2,k) = wte(i,2*mp1-2,k)-bi(mp1,np1,k)*wb(i,np1,iw)\n wte(i,2*mp1-1,k) = wte(i,2*mp1-1,k)+br(mp1,np1,k)*wb(i,np1,iw)\n 127 continue\n if(mlat .eq. 0) go to 128\n wte(imid,2*mp1-2,k) = wte(imid,2*mp1-2,k)\n 1 -bi(mp1,np1,k)*wb(imid,np1,iw)\n wte(imid,2*mp1-1,k) = wte(imid,2*mp1-1,k)\n 1 +br(mp1,np1,k)*wb(imid,np1,iw)\n 128 continue\n 129 continue\n 130 continue\n go to 950\nc\nc case ityp=2 no symmetries, br and bi are equal to zero\nc\n 200 call vbin(0,nlat,nlon,0,vb,iv,wvbin)\nc\nc case m = 0\nc\n do 215 k=1,nt\n do 215 np1=2,ndo2,2\n do 215 i=1,imm1\n wto(i,1,k)=wto(i,1,k)-cr(1,np1,k)*vb(i,np1,iv)\n 215 continue\n do 216 k=1,nt\n do 216 np1=3,ndo1,2\n do 216 i=1,imid\n wte(i,1,k)=wte(i,1,k)-cr(1,np1,k)*vb(i,np1,iv)\n 216 continue\nc\nc case m = 1 through nlat-1\nc\n if(mmax .lt. 2) go to 950\n do 230 mp1=2,mmax\n m = mp1-1\n mp2 = mp1+1\n call vbin(0,nlat,nlon,m,vb,iv,wvbin)\n call wbin(0,nlat,nlon,m,wb,iw,wwbin)\n if(mp1 .gt. ndo1) go to 226\n do 225 k=1,nt\n do 224 np1=mp1,ndo1,2\n do 223 i=1,imm1\n vto(i,2*mp1-2,k) = vto(i,2*mp1-2,k)-ci(mp1,np1,k)*wb(i,np1,iw)\n vto(i,2*mp1-1,k) = vto(i,2*mp1-1,k)+cr(mp1,np1,k)*wb(i,np1,iw)\n wte(i,2*mp1-2,k) = wte(i,2*mp1-2,k)-cr(mp1,np1,k)*vb(i,np1,iv)\n wte(i,2*mp1-1,k) = wte(i,2*mp1-1,k)-ci(mp1,np1,k)*vb(i,np1,iv)\n 223 continue\n if(mlat .eq. 0) go to 224\n wte(imid,2*mp1-2,k) = wte(imid,2*mp1-2,k)\n 1 -cr(mp1,np1,k)*vb(imid,np1,iv) \n wte(imid,2*mp1-1,k) = wte(imid,2*mp1-1,k)\n 1 -ci(mp1,np1,k)*vb(imid,np1,iv)\n 224 continue\n 225 continue\n 226 if(mp2 .gt. ndo2) go to 230\n do 229 k=1,nt\n do 228 np1=mp2,ndo2,2\n do 227 i=1,imm1\n vte(i,2*mp1-2,k) = vte(i,2*mp1-2,k)-ci(mp1,np1,k)*wb(i,np1,iw)\n vte(i,2*mp1-1,k) = vte(i,2*mp1-1,k)+cr(mp1,np1,k)*wb(i,np1,iw)\n wto(i,2*mp1-2,k) = wto(i,2*mp1-2,k)-cr(mp1,np1,k)*vb(i,np1,iv)\n wto(i,2*mp1-1,k) = wto(i,2*mp1-1,k)-ci(mp1,np1,k)*vb(i,np1,iv)\n 227 continue\n if(mlat .eq. 0) go to 228\n vte(imid,2*mp1-2,k) = vte(imid,2*mp1-2,k)\n 1 -ci(mp1,np1,k)*wb(imid,np1,iw) \n vte(imid,2*mp1-1,k) = vte(imid,2*mp1-1,k)\n 1 +cr(mp1,np1,k)*wb(imid,np1,iw)\n 228 continue\n 229 continue\n 230 continue\n go to 950\nc\nc case ityp=3 v odd, w even\nc\n 300 call vbin(0,nlat,nlon,0,vb,iv,wvbin)\nc\nc case m = 0\nc\n do 315 k=1,nt\n do 315 np1=2,ndo2,2\n do 315 i=1,imm1\n vto(i,1,k)=vto(i,1,k)+br(1,np1,k)*vb(i,np1,iv)\n 315 continue\n do 316 k=1,nt\n do 316 np1=3,ndo1,2\n do 316 i=1,imid\n wte(i,1,k)=wte(i,1,k)-cr(1,np1,k)*vb(i,np1,iv)\n 316 continue\nc\nc case m = 1 through nlat-1\nc\n if(mmax .lt. 2) go to 950\n do 330 mp1=2,mmax\n m = mp1-1\n mp2 = mp1+1\n call vbin(0,nlat,nlon,m,vb,iv,wvbin)\n call wbin(0,nlat,nlon,m,wb,iw,wwbin)\n if(mp1 .gt. ndo1) go to 326\n do 325 k=1,nt\n do 324 np1=mp1,ndo1,2\n do 323 i=1,imm1\n vto(i,2*mp1-2,k) = vto(i,2*mp1-2,k)-ci(mp1,np1,k)*wb(i,np1,iw)\n vto(i,2*mp1-1,k) = vto(i,2*mp1-1,k)+cr(mp1,np1,k)*wb(i,np1,iw)\n wte(i,2*mp1-2,k) = wte(i,2*mp1-2,k)-cr(mp1,np1,k)*vb(i,np1,iv)\n wte(i,2*mp1-1,k) = wte(i,2*mp1-1,k)-ci(mp1,np1,k)*vb(i,np1,iv)\n 323 continue\n if(mlat .eq. 0) go to 324\n wte(imid,2*mp1-2,k) = wte(imid,2*mp1-2,k)\n 1 -cr(mp1,np1,k)*vb(imid,np1,iv) \n wte(imid,2*mp1-1,k) = wte(imid,2*mp1-1,k)\n 1 -ci(mp1,np1,k)*vb(imid,np1,iv)\n 324 continue\n 325 continue\n 326 if(mp2 .gt. ndo2) go to 330\n do 329 k=1,nt\n do 328 np1=mp2,ndo2,2\n do 327 i=1,imm1\n vto(i,2*mp1-2,k) = vto(i,2*mp1-2,k)+br(mp1,np1,k)*vb(i,np1,iv)\n vto(i,2*mp1-1,k) = vto(i,2*mp1-1,k)+bi(mp1,np1,k)*vb(i,np1,iv)\n wte(i,2*mp1-2,k) = wte(i,2*mp1-2,k)-bi(mp1,np1,k)*wb(i,np1,iw)\n wte(i,2*mp1-1,k) = wte(i,2*mp1-1,k)+br(mp1,np1,k)*wb(i,np1,iw)\n 327 continue\n if(mlat .eq. 0) go to 328\n wte(imid,2*mp1-2,k) = wte(imid,2*mp1-2,k)\n 1 -bi(mp1,np1,k)*wb(imid,np1,iw)\n wte(imid,2*mp1-1,k) = wte(imid,2*mp1-1,k)\n 1 +br(mp1,np1,k)*wb(imid,np1,iw)\n 328 continue\n 329 continue\n 330 continue\n go to 950\nc\nc case ityp=4 v odd, w even, and both cr and ci equal zero \nc\n 400 call vbin(1,nlat,nlon,0,vb,iv,wvbin)\nc\nc case m = 0\nc\n do 415 k=1,nt\n do 415 np1=2,ndo2,2\n do 415 i=1,imm1\n vto(i,1,k)=vto(i,1,k)+br(1,np1,k)*vb(i,np1,iv)\n 415 continue\nc\nc case m = 1 through nlat-1\nc\n if(mmax .lt. 2) go to 950\n do 430 mp1=2,mmax\n m = mp1-1\n mp2 = mp1+1\n call vbin(1,nlat,nlon,m,vb,iv,wvbin)\n call wbin(1,nlat,nlon,m,wb,iw,wwbin)\n if(mp2 .gt. ndo2) go to 430\n do 429 k=1,nt\n do 428 np1=mp2,ndo2,2\n do 427 i=1,imm1\n vto(i,2*mp1-2,k) = vto(i,2*mp1-2,k)+br(mp1,np1,k)*vb(i,np1,iv)\n vto(i,2*mp1-1,k) = vto(i,2*mp1-1,k)+bi(mp1,np1,k)*vb(i,np1,iv)\n wte(i,2*mp1-2,k) = wte(i,2*mp1-2,k)-bi(mp1,np1,k)*wb(i,np1,iw)\n wte(i,2*mp1-1,k) = wte(i,2*mp1-1,k)+br(mp1,np1,k)*wb(i,np1,iw)\n 427 continue\n if(mlat .eq. 0) go to 428\n wte(imid,2*mp1-2,k) = wte(imid,2*mp1-2,k)\n 1 -bi(mp1,np1,k)*wb(imid,np1,iw)\n wte(imid,2*mp1-1,k) = wte(imid,2*mp1-1,k)\n 1 +br(mp1,np1,k)*wb(imid,np1,iw)\n 428 continue\n 429 continue\n 430 continue\n go to 950\nc\nc case ityp=5 v odd, w even, br and bi equal zero \nc\n 500 call vbin(2,nlat,nlon,0,vb,iv,wvbin)\nc\nc case m = 0\nc\n do 516 k=1,nt\n do 516 np1=3,ndo1,2\n do 516 i=1,imid\n wte(i,1,k)=wte(i,1,k)-cr(1,np1,k)*vb(i,np1,iv)\n 516 continue\nc\nc case m = 1 through nlat-1\nc\n if(mmax .lt. 2) go to 950\n do 530 mp1=2,mmax\n m = mp1-1\n mp2 = mp1+1\n call vbin(2,nlat,nlon,m,vb,iv,wvbin)\n call wbin(2,nlat,nlon,m,wb,iw,wwbin)\n if(mp1 .gt. ndo1) go to 530\n do 525 k=1,nt\n do 524 np1=mp1,ndo1,2\n do 523 i=1,imm1\n vto(i,2*mp1-2,k) = vto(i,2*mp1-2,k)-ci(mp1,np1,k)*wb(i,np1,iw)\n vto(i,2*mp1-1,k) = vto(i,2*mp1-1,k)+cr(mp1,np1,k)*wb(i,np1,iw)\n wte(i,2*mp1-2,k) = wte(i,2*mp1-2,k)-cr(mp1,np1,k)*vb(i,np1,iv)\n wte(i,2*mp1-1,k) = wte(i,2*mp1-1,k)-ci(mp1,np1,k)*vb(i,np1,iv)\n 523 continue\n if(mlat .eq. 0) go to 524\n wte(imid,2*mp1-2,k) = wte(imid,2*mp1-2,k)\n 1 -cr(mp1,np1,k)*vb(imid,np1,iv) \n wte(imid,2*mp1-1,k) = wte(imid,2*mp1-1,k)\n 1 -ci(mp1,np1,k)*vb(imid,np1,iv)\n 524 continue\n 525 continue\n 530 continue\n go to 950\nc\nc case ityp=6 v even , w odd\nc\n 600 call vbin(0,nlat,nlon,0,vb,iv,wvbin)\nc\nc case m = 0\nc\n do 615 k=1,nt\n do 615 np1=2,ndo2,2\n do 615 i=1,imm1\n wto(i,1,k)=wto(i,1,k)-cr(1,np1,k)*vb(i,np1,iv)\n 615 continue\n do 616 k=1,nt\n do 616 np1=3,ndo1,2\n do 616 i=1,imid\n vte(i,1,k)=vte(i,1,k)+br(1,np1,k)*vb(i,np1,iv)\n 616 continue\nc\nc case m = 1 through nlat-1\nc\n if(mmax .lt. 2) go to 950\n do 630 mp1=2,mmax\n m = mp1-1\n mp2 = mp1+1\n call vbin(0,nlat,nlon,m,vb,iv,wvbin)\n call wbin(0,nlat,nlon,m,wb,iw,wwbin)\n if(mp1 .gt. ndo1) go to 626\n do 625 k=1,nt\n do 624 np1=mp1,ndo1,2\n do 623 i=1,imm1\n vte(i,2*mp1-2,k) = vte(i,2*mp1-2,k)+br(mp1,np1,k)*vb(i,np1,iv)\n vte(i,2*mp1-1,k) = vte(i,2*mp1-1,k)+bi(mp1,np1,k)*vb(i,np1,iv)\n wto(i,2*mp1-2,k) = wto(i,2*mp1-2,k)-bi(mp1,np1,k)*wb(i,np1,iw)\n wto(i,2*mp1-1,k) = wto(i,2*mp1-1,k)+br(mp1,np1,k)*wb(i,np1,iw)\n 623 continue\n if(mlat .eq. 0) go to 624\n vte(imid,2*mp1-2,k) = vte(imid,2*mp1-2,k)\n 1 +br(mp1,np1,k)*vb(imid,np1,iv)\n vte(imid,2*mp1-1,k) = vte(imid,2*mp1-1,k)\n 1 +bi(mp1,np1,k)*vb(imid,np1,iv)\n 624 continue\n 625 continue\n 626 if(mp2 .gt. ndo2) go to 630\n do 629 k=1,nt\n do 628 np1=mp2,ndo2,2\n do 627 i=1,imm1\n vte(i,2*mp1-2,k) = vte(i,2*mp1-2,k)-ci(mp1,np1,k)*wb(i,np1,iw)\n vte(i,2*mp1-1,k) = vte(i,2*mp1-1,k)+cr(mp1,np1,k)*wb(i,np1,iw)\n wto(i,2*mp1-2,k) = wto(i,2*mp1-2,k)-cr(mp1,np1,k)*vb(i,np1,iv)\n wto(i,2*mp1-1,k) = wto(i,2*mp1-1,k)-ci(mp1,np1,k)*vb(i,np1,iv)\n 627 continue\n if(mlat .eq. 0) go to 628\n vte(imid,2*mp1-2,k) = vte(imid,2*mp1-2,k)\n 1 -ci(mp1,np1,k)*wb(imid,np1,iw) \n vte(imid,2*mp1-1,k) = vte(imid,2*mp1-1,k)\n 1 +cr(mp1,np1,k)*wb(imid,np1,iw)\n 628 continue\n 629 continue\n 630 continue\n go to 950\nc\nc case ityp=7 v even, w odd cr and ci equal zero\nc\n 700 call vbin(2,nlat,nlon,0,vb,iv,wvbin)\nc\nc case m = 0\nc\n do 716 k=1,nt\n do 716 np1=3,ndo1,2\n do 716 i=1,imid\n vte(i,1,k)=vte(i,1,k)+br(1,np1,k)*vb(i,np1,iv)\n 716 continue\nc\nc case m = 1 through nlat-1\nc\n if(mmax .lt. 2) go to 950\n do 730 mp1=2,mmax\n m = mp1-1\n mp2 = mp1+1\n call vbin(2,nlat,nlon,m,vb,iv,wvbin)\n call wbin(2,nlat,nlon,m,wb,iw,wwbin)\n if(mp1 .gt. ndo1) go to 730\n do 725 k=1,nt\n do 724 np1=mp1,ndo1,2\n do 723 i=1,imm1\n vte(i,2*mp1-2,k) = vte(i,2*mp1-2,k)+br(mp1,np1,k)*vb(i,np1,iv)\n vte(i,2*mp1-1,k) = vte(i,2*mp1-1,k)+bi(mp1,np1,k)*vb(i,np1,iv)\n wto(i,2*mp1-2,k) = wto(i,2*mp1-2,k)-bi(mp1,np1,k)*wb(i,np1,iw)\n wto(i,2*mp1-1,k) = wto(i,2*mp1-1,k)+br(mp1,np1,k)*wb(i,np1,iw)\n 723 continue\n if(mlat .eq. 0) go to 724\n vte(imid,2*mp1-2,k) = vte(imid,2*mp1-2,k)\n 1 +br(mp1,np1,k)*vb(imid,np1,iv)\n vte(imid,2*mp1-1,k) = vte(imid,2*mp1-1,k)\n 1 +bi(mp1,np1,k)*vb(imid,np1,iv)\n 724 continue\n 725 continue\n 730 continue\n go to 950\nc\nc case ityp=8 v even, w odd br and bi equal zero\nc\n 800 call vbin(1,nlat,nlon,0,vb,iv,wvbin)\nc\nc case m = 0\nc\n do 815 k=1,nt\n do 815 np1=2,ndo2,2\n do 815 i=1,imm1\n wto(i,1,k)=wto(i,1,k)-cr(1,np1,k)*vb(i,np1,iv)\n 815 continue\nc\nc case m = 1 through nlat-1\nc\n if(mmax .lt. 2) go to 950\n do 830 mp1=2,mmax\n m = mp1-1\n mp2 = mp1+1\n call vbin(1,nlat,nlon,m,vb,iv,wvbin)\n call wbin(1,nlat,nlon,m,wb,iw,wwbin)\n if(mp2 .gt. ndo2) go to 830\n do 829 k=1,nt\n do 828 np1=mp2,ndo2,2\n do 827 i=1,imm1\n vte(i,2*mp1-2,k) = vte(i,2*mp1-2,k)-ci(mp1,np1,k)*wb(i,np1,iw)\n vte(i,2*mp1-1,k) = vte(i,2*mp1-1,k)+cr(mp1,np1,k)*wb(i,np1,iw)\n wto(i,2*mp1-2,k) = wto(i,2*mp1-2,k)-cr(mp1,np1,k)*vb(i,np1,iv)\n wto(i,2*mp1-1,k) = wto(i,2*mp1-1,k)-ci(mp1,np1,k)*vb(i,np1,iv)\n 827 continue\n if(mlat .eq. 0) go to 828\n vte(imid,2*mp1-2,k) = vte(imid,2*mp1-2,k)\n 1 -ci(mp1,np1,k)*wb(imid,np1,iw) \n vte(imid,2*mp1-1,k) = vte(imid,2*mp1-1,k)\n 1 +cr(mp1,np1,k)*wb(imid,np1,iw)\n 828 continue\n 829 continue\n 830 continue\n 950 do 14 k=1,nt\n call hrfftb(idv,nlon,vte(1,1,k),idv,wrfft,vb)\n call hrfftb(idv,nlon,wte(1,1,k),idv,wrfft,vb)\n 14 continue\n if(ityp .gt. 2) go to 12\n do 60 k=1,nt\n do 60 j=1,nlon\n do 60 i=1,imm1\n vt(i,j,k) = .5*(vte(i,j,k)+vto(i,j,k))\n wt(i,j,k) = .5*(wte(i,j,k)+wto(i,j,k))\n vt(nlp1-i,j,k) = .5*(vte(i,j,k)-vto(i,j,k))\n wt(nlp1-i,j,k) = .5*(wte(i,j,k)-wto(i,j,k))\n 60 continue\n go to 13\n 12 do 11 k=1,nt\n do 11 j=1,nlon\n do 11 i=1,imm1\n vt(i,j,k) = .5*vte(i,j,k)\n wt(i,j,k) = .5*wte(i,j,k)\n 11 continue\n 13 if(mlat .eq. 0) return\n do 65 k=1,nt\n do 65 j=1,nlon\n vt(imid,j,k) = .5*vte(imid,j,k)\n wt(imid,j,k) = .5*wte(imid,j,k)\n 65 continue\n return\n end\n subroutine vtseci(nlat,nlon,wvts,lwvts,dwork,ldwork,ierror)\nc\n dimension wvts(lwvts)\n double precision dwork(ldwork)\n ierror = 1\n if(nlat .lt. 3) return\n ierror = 2\n if(nlon .lt. 1) return\n ierror = 3\n imid = (nlat+1)/2\n lzz1 = 2*nlat*imid\n mmax = min0(nlat,(nlon+1)/2)\n labc = 3*(max0(mmax-2,0)*(nlat+nlat-mmax-1))/2\n if(lwvts .lt. 2*(lzz1+labc)+nlon+15) return\n ierror = 4\n if (ldwork .lt. 2*nlat+2) return\n ierror = 0\n call vtinit (nlat,nlon,wvts,dwork)\n lwvbin = lzz1+labc\n iw1 = lwvbin+1\n call wtinit (nlat,nlon,wvts(iw1),dwork)\n iw2 = iw1+lwvbin\n call hrffti(nlon,wvts(iw2))\n return\n end\n", "meta": {"hexsha": "ad55581972b10f919bbe97b4c5500dc4de92dd57", "size": 34273, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/vtsec.f", "max_stars_repo_name": "jprules321/colas", "max_stars_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/vtsec.f", "max_issues_repo_name": "jprules321/colas", "max_issues_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/vtsec.f", "max_forks_repo_name": "jprules321/colas", "max_forks_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.0118790497, "max_line_length": 79, "alphanum_fraction": 0.5380036764, "num_tokens": 13810, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.903294214513915, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.6685952241385765}} {"text": "! Reads the inputs to create the mesh\nsubroutine mesh\nuse Declarations \nreal(dp) :: delta_x, & ! Horizontal space step [m]\n & delta_y ! Vertical space ste [m]\ninteger :: choice_nb_layers ! Variable to decide if vertical space step is equal to layer thicknesses (=1) or not (=0)\nreal(dp), allocatable :: y(:), & ! Variable used to calculate yn\n & thickness(:) ! Variable used to calculate yn\n\nchoice_nb_layers = 0\n\nopen(7,file='inputs.txt') \nread(7,*) L1\nread(7,*) L2\nread(7,*) N\nread(7,*) M\nread(7,*) \nread(7,*) \nread(7,*) beta\nread(7,*) nb_layers\nallocate (thickness(nb_layers))\nread(7,*)\nread(7,*)\nread(7,*)\nread(7,*)\nread(7,*)\nread(7,*)\nread(7,*)\nread(7,*)\nread(7,*)\nread(7,*)\ndo j = 1,nb_layers\n read(7,*) thickness(j)\nenddo\n\nclose (7) \n\nif (M .eq. 999) then ! use layer thicknesses for vertical mesh resolution\n M = nb_layers + 1\n choice_nb_layers = 1 \nendif\n\n!================== Allocate mesh variables =================================\nallocate (y(M),xn(N,M),yn(N,M),xv(N-1,M-1),yv(N-1,M-1), Vol(N-1,M-1))\nallocate (Sx_west(N-1,M-1),Sy_west(N-1,M-1),Sx_east(N-1,M-1),Sy_east(N-1,M-1))\nallocate (Sx_north(N-1,M-1),Sy_north(N-1,M-1),Sx_south(N-1,M-1),Sy_south(N-1,M-1)) \n\n\ny(1) = 0._dp\n\nif (choice_nb_layers .eq. 0) then\n delta_y = L2 / real(M-1,dp)\n do j = 1,M-1\n y(j+1) = y(j) + delta_y\n enddo\nelse \n do j=1,M-1\n y(j+1) = y(j)+thickness(j)\n enddo\nendif\n\ndo j = 1,M\n xn(1,j) = dsin(beta)*y(j)\n yn(1,j) = dcos(beta)*y(j)\nenddo\n\ndelta_x = L1 / real(N-1,dp) \n\ndo j = 1,M\n do i = 2,N\n xn(i,j) = xn(1,j) + real((i-1),dp) * delta_x * dcos(beta)\n yn(i,j) = yn(1,j) - dsin(beta)*real(i-1,dp)*delta_x\n enddo\nenddo\ndo j = 1,M-1\n do i = 1,N-1\n xv(i,j) = (xn(i,j)+xn(i+1,j)+xn(i,j+1)+xn(i+1,j+1))*0.25_dp\n yv(i,j) = (yn(i,j)+yn(i+1,j)+yn(i,j+1)+yn(i+1,j+1))*0.25_dp\n Vol(i,j) = (yn(i,j+1)-yn(i,j))*delta_x/dcos(beta)\n Sx_west(i,j) = dabs(yn(i,j+1)-yn(i,j))\n Sy_west(i,j) = dabs(xn(i,j+1)-xn(i,j))\n Sx_east(i,j) = dabs(yn(i+1,j+1)-yn(i+1,j))\n Sy_east(i,j) = dabs(xn(i+1,j+1)-xn(i+1,j))\n Sx_north(i,j) = dabs(yn(i+1,j+1)-yn(i,j+1))\n Sy_north(i,j) = dabs(xn(i+1,j+1)-xn(i,j+1))\n Sx_south(i,j) = dabs(yn(i+1,j)-yn(i,j))\n Sy_south(i,j) = dabs(xn(i+1,j)-xn(i,j))\n enddo\nenddo\n\n\n! Check if sum of all small volumes is equal to rectangle volume\nwrite(*,*) 'Sum of all small volumes [m2] = ', sum(Vol)\nwrite(*,*) 'Total volume [m2] = ', L1 * L2\n\ndeallocate(y, thickness)\n\nreturn\nend\n\n", "meta": {"hexsha": "0a1dbb563e87b1e3199306dc010e370759ff23e9", "size": 2524, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/mesh.f90", "max_stars_repo_name": "nleroux3/SMPP", "max_stars_repo_head_hexsha": "f9cefac40e94a50df75a3efa8dc113802882b1f8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-04-13T15:02:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-13T15:02:25.000Z", "max_issues_repo_path": "src/mesh.f90", "max_issues_repo_name": "nleroux3/SMPP", "max_issues_repo_head_hexsha": "f9cefac40e94a50df75a3efa8dc113802882b1f8", "max_issues_repo_licenses": ["MIT"], "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/mesh.f90", "max_forks_repo_name": "nleroux3/SMPP", "max_forks_repo_head_hexsha": "f9cefac40e94a50df75a3efa8dc113802882b1f8", "max_forks_repo_licenses": ["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.9900990099, "max_line_length": 118, "alphanum_fraction": 0.5637876387, "num_tokens": 1031, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971871, "lm_q2_score": 0.7401743677704878, "lm_q1q2_score": 0.6685952145039281}} {"text": " MODULE cdf_gamma_mod\n! ----------------------------------------------------------------------\n\n! cdf_gamma_mod\n! *=*=*=*=*=*=*\n\n! - SUBROUTINE CDF_GAMMA(WHICH, CUM, CCUM, X, SHAPE, SCALE, STATUS,\n! CHECK_INPUT)\n! - REAL (dpkind) FUNCTION CUM_GAMMA(X, SHAPE, SCALE, STATUS, CHECK_INPUT)\n! - REAL (dpkind) FUNCTION CCUM_GAMMA(X, SHAPE, SCALE, STATUS, CHECK_INPUT)\n! - REAL (dpkind) FUNCTION INV_GAMMA(CUM, CCUM, SHAPE, SCALE, STATUS,\n! CHECK_INPUT)\n\n! The Distribution\n! ================\n\n! The density of the GAMMA distribution is proportional to:\n\n! SHAPE-1\n! (x/SCALE) exp(-x/SCALE)\n\n! Arguments\n! =========\n\n! - INTEGER, INTENT(IN) :: WHICH. Integer indicating which of the next\n! four arguments is to be calculated.\n! Input Range: [ 1:4 ]\n! 1. CUM and CCUM\n! 2. X\n! 3. SHAPE\n! 4. SCALE\n! - REAL (dpkind), OPTIONAL :: CUM. The CDF of the gamma distribution.\n! Range: [ 0:1-10^-10 ]\n! - REAL (dpkind), OPTIONAL :: CCUM. One minus the CDF of the gamma\n! distribution.\n! Range: [ 10^-10:1 ]\n! - REAL (dpkind) :: X. The upper limit of integration of the gamma\n! density. The lower limit is 0.\n! Range: [ 0:10^100 ]\n! - REAL (dpkind) :: SHAPE. The shape parameter of the distribution.\n! Range: [ 10^-10:10^100 ]\n! - REAL (dpkind) :: SCALE. The scale parameter of the distribution.\n! Range: [ 10^-10:10^100 ]\n! - INTEGER, OPTIONAL, INTENT(OUT) :: STATUS. Return code. Possible values:\n! 0 Problem solved successfully\n! -1 WHICH outside input range\n! -2 CUM outside range\n! -3 CCUM outside range\n! -4 X outside range\n! -5 SHAPE outside range\n! -6 SCALE outside range\n! 3 CUM + CCUM is not nearly one\n! 10 can not solve gamma_inverse in cdf_gamma\n! -50 Answer (if any) is BELOW the LOWER search bound\n! 50 Answer (if any) is ABOVE the UPPER search bound\n! - LOGICAL, INTENT(IN), OPTIONAL :: CHECK_INPUT. If PRESENT and\n! .TRUE. input argument values are not checked for validity.\n\n! NOTE: CUM and CCUM must add to (nearly) one.\n! ----------------------------------------------------------------------\n! .. Use Statements ..\n USE biomath_constants_mod\n USE biomath_mathlib_mod\n! ..\n! .. Default Accessibility ..\n PRIVATE\n! ..\n! .. Public Statements ..\n PUBLIC :: ccum_gamma, cdf_gamma, cum_gamma, inv_gamma\n! ..\n CONTAINS\n\n!*********************************************************************\n\n FUNCTION ccum_gamma(x,shape,scale,status,check_input)\n! .. Function Return Value ..\n REAL (dpkind) :: ccum_gamma\n! ..\n! .. Scalar Arguments ..\n! DMS OPTIONAL added\n REAL (dpkind), INTENT (IN) :: scale, shape, x\n INTEGER, OPTIONAL, INTENT (OUT) :: status\n LOGICAL, OPTIONAL, INTENT (IN) :: check_input\n! ..\n CALL cdf_gamma(which=1,ccum=ccum_gamma,x=x,shape=shape, &\n scale=scale,status=status,check_input=check_input)\n\n RETURN\n\n END FUNCTION ccum_gamma\n\n!*********************************************************************\n\n SUBROUTINE cdf_gamma(which,cum,ccum,x,shape,scale,status, &\n check_input)\n! .. Use Statements ..\n USE zero_finder\n USE cdf_aux_mod\n! ..\n! .. Scalar Arguments ..\n REAL (dpkind), OPTIONAL :: ccum, cum\n REAL (dpkind) :: scale, shape, x\n INTEGER, OPTIONAL, INTENT (OUT) :: status\n INTEGER, INTENT (IN) :: which\n LOGICAL, OPTIONAL, INTENT (IN) :: check_input\n! ..\n! .. Local Scalars ..\n REAL (dpkind) :: fx, local_ccum, local_cum, try_ccum, try_cum, xx\n INTEGER :: ierr, zf_status\n LOGICAL :: has_status, local_check_input, match_cum\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC PRESENT\n! ..\n! .. Local Structures ..\n TYPE (zf_locals) :: local\n! ..\n! .. Local Arrays ..\n REAL (dpkind) :: params(6)\n! ..\n has_status = PRESENT(status)\n\n! status = 0 means NO error\n\n IF (has_status) THEN\n status = 0\n END IF\n\n CALL check_complements(cum,ccum,the_gamma%name,'cum','ccum', &\n local_cum,local_ccum,set_values=(which/=1),bad_status=3, &\n status=status)\n\n IF (has_status) THEN\n IF (status/=0) THEN\n RETURN\n END IF\n END IF\n\n params(1) = local_cum\n params(2) = local_ccum\n params(3) = x\n params(4) = shape\n params(5) = scale\n\n IF (PRESENT(check_input)) THEN\n local_check_input = check_input\n ELSE\n local_check_input = .TRUE.\n END IF\n\n IF (local_check_input) THEN\n CALL validate_parameters(the_gamma,which,params,status)\n\n IF (has_status) THEN\n IF (status/=0) THEN\n RETURN\n END IF\n END IF\n END IF\n\n IF (which>1) match_cum = (local_cum<=half)\n\n SELECT CASE (which)\n\n CASE (1)\n! Calculate cum and ccum\n\n CALL local_cum_gamma(x,shape,scale,local_cum,local_ccum)\n\n IF (PRESENT(cum)) cum = local_cum\n IF (PRESENT(ccum)) ccum = local_ccum\n\n RETURN\n\n CASE (2)\n! Calculate x\n\n CALL gamma_inverse(shape,xx,-one,local_cum,local_ccum,ierr)\n\n IF (ierr<0) THEN\n IF (has_status) THEN\n status = 10\n\n RETURN\n ELSE\n WRITE (*,*) 'Error in cdf_gamma call to gamma_inverse'\n WRITE (*,*) 'Status: ', ierr\n\n STOP 'Error in cdf_gamma call to gamma_inverse'\n END IF\n\n END IF\n\n x = xx/scale\n\n RETURN\n\n CASE (3)\n! Calculate SHAPE\n\n shape = five\n zf_status = 0\n\n CALL cdf_set_zero_finder(the_gamma,4,local)\n\n DO\n\n CALL rc_step_zf(zf_status,shape,fx,local)\n\n IF (zf_status/=1) EXIT\n\n CALL local_cum_gamma(x,shape,scale,try_cum,try_ccum)\n\n IF (match_cum) THEN\n fx = try_cum - local_cum\n ELSE\n fx = try_ccum - local_ccum\n END IF\n\n END DO\n\n CASE (4)\n! Calculate SCALE\n\n CALL gamma_inverse(shape,xx,-one,local_cum,local_ccum,ierr)\n\n IF (ierr/=0) THEN\n IF (has_status) THEN\n status = 10\n\n RETURN\n ELSE\n WRITE (*,*) 'Error in cdf_gamma call to gamma_inverse'\n WRITE (*,*) 'Status: ', ierr\n\n STOP 'Error in cdf_gamma call to gamma_inverse'\n END IF\n\n END IF\n\n scale = xx/x\n\n RETURN\n\n END SELECT\n\n! Gets here ONLY for which=3\n\n IF (has_status) THEN\n! Set the status of the zero finder\n CALL cdf_finalize_status(local,status)\n END IF\n\n RETURN\n\n END SUBROUTINE cdf_gamma\n\n!*********************************************************************\n\n FUNCTION cum_gamma(x,shape,scale,status,check_input)\n! .. Function Return Value ..\n REAL (dpkind) :: cum_gamma\n! ..\n! .. Scalar Arguments ..\n! DMS OPTIONAL added\n REAL (dpkind), INTENT (IN) :: scale, shape, x\n INTEGER, OPTIONAL, INTENT (OUT) :: status\n LOGICAL, OPTIONAL, INTENT (IN) :: check_input\n! ..\n CALL cdf_gamma(which=1,cum=cum_gamma,x=x,shape=shape,scale=scale, &\n status=status,check_input=check_input)\n\n RETURN\n\n END FUNCTION cum_gamma\n\n!*********************************************************************\n\n SUBROUTINE gamma_inverse(a,x,x0,p,q,ierr)\n! ----------------------------------------------------------------------\n! INVERSE INCOMPLETE GAMMA RATIO FUNCTION\n! GIVEN POSITIVE A, AND NON-NEGATIVE P AND Q WHERE P + Q = 1.\n! THEN X IS COMPUTED WHERE P(A,X) = P AND Q(A,X) = Q. SCHRODER\n! ITERATION IS EMPLOYED. THE ROUTINE ATTEMPTS TO COMPUTE X\n! TO 10 SIGNIFICANT DIGITS IF THIS IS POSSIBLE FOR THE\n! PARTICULAR COMPUTER ARITHMETIC BEING USED.\n! ------------\n! X IS A VARIABLE. IF P = 0 THEN X IS ASSIGNED THE VALUE 0,\n! AND IF Q = 0 THEN X IS SET TO THE LARGEST FLOATING POINT\n! NUMBER AVAILABLE. OTHERWISE, GAMINV ATTEMPTS TO OBTAIN\n! A SOLUTION FOR P(A,X) = P AND Q(A,X) = Q. IF THE ROUTINE\n! IS SUCCESSFUL THEN THE SOLUTION IS STORED IN X.\n! X0 IS AN OPTIONAL INITIAL APPROXIMATION FOR X. IF THE USER\n! DOES NOT WISH TO SUPPLY AN INITIAL APPROXIMATION, THEN SET\n! X0 .LE. 0.\n! IERR IS A VARIABLE THAT REPORTS THE STATUS OF THE RESULTS.\n! WHEN THE ROUTINE TERMINATES, IERR HAS ONE OF THE FOLLOWING\n! VALUES ...\n! IERR = 0 THE SOLUTION WAS OBTAINED. ITERATION WAS\n! NOT USED.\n! IERR.GT.0 THE SOLUTION WAS OBTAINED. IERR ITERATIONS\n! WERE PERFORMED.\n! IERR = -2 (INPUT ERROR) A .LE. 0\n! IERR = -3 NO SOLUTION WAS OBTAINED. THE RATIO Q/A\n! IS TOO LARGE.\n! IERR = -4 (INPUT ERROR) P + Q .NE. 1\n! IERR = -6 20 ITERATIONS WERE PERFORMED. THE MOST\n! RECENT VALUE OBTAINED FOR X IS GIVEN.\n! THIS CANNOT OCCUR IF X0 .LE. 0.\n! IERR = -7 ITERATION FAILED. NO VALUE IS GIVEN FOR X.\n! THIS MAY OCCUR WHEN X IS APPROXIMATELY 0.\n! IERR = -8 A VALUE FOR X HAS BEEN OBTAINED, BUT THE\n! ROUTINE IS NOT CERTAIN OF ITS ACCURACY.\n! ITERATION CANNOT BE PERFORMED IN THIS\n! CASE. IF X0 .LE. 0, THIS CAN OCCUR ONLY\n! WHEN P OR Q IS APPROXIMATELY 0. IF X0 IS\n! POSITIVE THEN THIS CAN OCCUR WHEN A IS\n! EXCEEDINGLY CLOSE TO X AND A IS EXTREMELY\n! LARGE (SAY A .GE. 1.E20).\n! ----------------------------------------------------------------------\n! WRITTEN BY ALFRED H. MORRIS, JR.\n! NAVAL SURFACE WEAPONS CENTER\n! DAHLGREN, VIRGINIA\n! -------------------\n! -------------------\n! LN10 = LN(10)\n! C = EULER CONSTANT\n! -------------------\n! -------------------\n! .. Scalar Arguments ..\n REAL (dpkind), INTENT (IN) :: a, p, q, x0\n REAL (dpkind), INTENT (OUT) :: x\n INTEGER, INTENT (OUT) :: ierr\n! ..\n! .. Local Scalars ..\n REAL (dpkind) :: am1, amax, ap1, ap2, ap3, apn, b, c1, c2, c3, &\n c4, c5, d, e, e2, eps, g, h, pn, qg, qn, r, rta, s, s2, sum, t, &\n u, w, xmax, xmin, xn, y, z\n INTEGER :: iop\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC ABS, EPSILON, EXP, HUGE, LOG, MAX, SQRT, TINY\n! ..\n! .. Parameters ..\n REAL (dpkind), PARAMETER :: ac(4) = (/ 3.31125922108741E0_dpkind, &\n 11.6616720288968E0_dpkind, 4.28342155967104E0_dpkind, &\n .213623493715853E0_dpkind/)\n REAL (dpkind), PARAMETER :: amin(2) = (/ 500.0E0_dpkind, &\n 100.0E0_dpkind/)\n REAL (dpkind), PARAMETER :: bc(5) = (/ one, &\n 6.61053765625462E0_dpkind, 6.40691597760039E0_dpkind, &\n 1.27364489782223E0_dpkind, .036117081018842E0_dpkind/)\n REAL (dpkind), PARAMETER :: bmin(2) = (/ 1.E-28_dpkind, &\n 1.E-13_dpkind/)\n REAL (dpkind), PARAMETER :: dmin(2) = (/ 1.E-06_dpkind, &\n 1.E-04_dpkind/)\n REAL (dpkind), PARAMETER :: emin(2) = (/ 2.E-03_dpkind, &\n 6.E-03_dpkind/)\n REAL (dpkind), PARAMETER :: eps0(2) = (/ 1.E-10_dpkind, &\n 1.E-08_dpkind/)\n REAL (dpkind), PARAMETER :: c = .577215664901533E0_dpkind\n REAL (dpkind), PARAMETER :: ln10 = 2.302585E0_dpkind\n REAL (dpkind), PARAMETER :: tol = 1.E-5_dpkind\n! ..\n! -------------------\n! ****** E, XMIN, AND XMAX ARE MACHINE DEPENDENT CONSTANTS.\n! E IS THE SMALLEST NUMBER FOR WHICH 1.0 + E .GT. 1.0.\n! XMIN IS THE SMALLEST POSITIVE NUMBER AND XMAX IS THE\n! LARGEST POSITIVE NUMBER.\n e = EPSILON(one)\n xmin = TINY(one)\n xmax = HUGE(one)\n\n x = zero\n IF (a<=zero) GO TO 240\n t = p + q - one\n IF (ABS(t)>e) GO TO 260\n\n ierr = 0\n IF (p==zero) RETURN\n IF (q==zero) GO TO 220\n IF (a==one) GO TO 230\n\n e2 = two*e\n amax = 0.4E-10_dpkind/(e*e)\n iop = 1\n\n IF (e>1.E-10_dpkind) iop = 2\n\n eps = eps0(iop)\n xn = x0\n\n IF (x0>zero) GO TO 110\n\n! SELECTION OF THE INITIAL APPROXIMATION XN OF X\n! WHEN A .LT. 1\n\n IF (a>one) GO TO 50\n\n g = gamma(a+one)\n qg = q*g\n IF (qg==zero) GO TO 300\n\n b = qg/a\n\n IF (qg>0.6E0_dpkind*a) GO TO 40\n IF (a>=0.30E0_dpkind .OR. b<0.35E0_dpkind) GO TO 10\n\n t = EXP(-(b+c))\n u = t*EXP(t)\n xn = t*EXP(u)\n GO TO 110\n\n10 CONTINUE\n IF (b>=0.45E0_dpkind) GO TO 40\n IF (b==zero) GO TO 300\n y = -LOG(b)\n s = half + (half-a)\n z = LOG(y)\n t = y - s*z\n IF (b<0.15E0_dpkind) GO TO 20\n xn = y - s*LOG(t) - LOG(one+s/(t+one))\n GO TO 170\n\n20 CONTINUE\n IF (b<=0.01E0_dpkind) GO TO 30\n u = ((t+two*(three-a))*t+(two-a)*(three-a))/((t+(five-a))*t+two)\n xn = y - s*LOG(t) - LOG(u)\n GO TO 170\n\n30 CONTINUE\n c1 = -s*z\n c2 = -s*(one+c1)\n c3 = s*((half*c1+(two-a))*c1+(2.5E0_dpkind-1.5E0_dpkind*a))\n c4 = -s*(((c1/three+(2.5E0_dpkind-1.5E0_dpkind*a))*c1+((a-six)*a+ &\n seven))*c1+((11.0E0_dpkind*a-46)*a+47.0E0_dpkind)/six)\n c5 = -s*(((((-c1/four)+(11.0E0_dpkind*a-17.0E0_dpkind)/six)*c1+ &\n (((-three*a)+13.0E0_dpkind)*a-13.0E0_dpkind))*c1+half*(((two*a- &\n 25.0E0_dpkind)*a+72.0E0_dpkind)*a-61.0E0_dpkind))*c1+((( &\n 25.0E0_dpkind*a-195.0E0_dpkind)*a+477.0E0_dpkind)*a- &\n 379.0E0_dpkind)/twelve)\n\n xn = ((((c5/y+c4)/y+c3)/y+c2)/y+c1) + y\n\n IF (a>one) GO TO 170\n IF (b>bmin(iop)) GO TO 170\n x = xn\n RETURN\n\n40 CONTINUE\n IF (b*q<=1.E-8_dpkind) THEN\n xn = EXP(-(q/a+c))\n ELSE\n\n IF (p>0.9E0_dpkind) THEN\n xn = EXP((alnrel(-q)+gamln1(a))/a)\n ELSE\n\n xn = EXP(LOG(p*g)/a)\n END IF\n END IF\n\n IF (xn==zero) GO TO 250\n\n t = half + (half-xn/(a+one))\n xn = xn/t\n GO TO 110\n\n! SELECTION OF THE INITIAL APPROXIMATION XN OF X\n! WHEN A .GT. 1\n\n50 CONTINUE\n IF (q>half) THEN\n w = LOG(p)\n ELSE\n w = LOG(q)\n END IF\n\n t = SQRT(-two*w)\n\n s = t - evaluate_polynomial(ac,t)/evaluate_polynomial(bc,t)\n\n IF (q>half) s = -s\n\n rta = SQRT(a)\n s2 = s*s\n xn = a + s*rta + (s2-one)/three + s*(s2-seven)/(36.0E0_dpkind*rta &\n ) - ((three*s2+seven)*s2-16.0E0_dpkind)/(810.0E0_dpkind*a) + &\n s*((nine*s2+256.0E0_dpkind)*s2-433.0E0_dpkind)/ &\n (38880.0E0_dpkind*a*rta)\n xn = MAX(xn,zero)\n\n IF (a0.70E0_dpkind*ap1) GO TO 120\n\n w = w + gamln(ap1)\n\n IF (xn>0.15E0_dpkind*ap1) GO TO 90\n\n ap2 = a + two\n ap3 = a + three\n x = EXP((w+x)/a)\n x = EXP((w+x-LOG(one+(x/ap1)*(one+x/ap2)))/a)\n x = EXP((w+x-LOG(one+(x/ap1)*(one+x/ap2)))/a)\n x = EXP((w+x-LOG(one+(x/ap1)*(one+(x/ap2)*(one+x/ap3))))/a)\n xn = x\n\n IF (xn>1.E-2_dpkind*ap1) GO TO 90\n IF (xn<=emin(iop)*ap1) RETURN\n GO TO 120\n\n90 CONTINUE\n apn = ap1\n t = xn/apn\n sum = one + t\n100 CONTINUE\n apn = apn + one\n t = t*(xn/apn)\n sum = sum + t\n IF (t>1.E-4_dpkind) GO TO 100\n t = w - LOG(sum)\n xn = EXP((xn+t)/a)\n xn = xn*(one-(a*LOG(xn)-xn-t)/(a-xn))\n GO TO 120\n\n! SCHRODER ITERATION USING P\n\n110 CONTINUE\n IF (p>half) GO TO 170\n\n120 CONTINUE\n IF (p<=1.E10_dpkind*xmin) GO TO 290\n am1 = (a-half) - half\n\n130 CONTINUE\n IF (a<=amax) GO TO 140\n d = half + (half-xn/a)\n IF (ABS(d)<=e2) GO TO 290\n\n140 CONTINUE\n IF (ierr>=20) GO TO 270\n ierr = ierr + 1\n\n CALL gratio(a,xn,pn,qn,0)\n\n IF (pn==zero .OR. qn==zero) GO TO 290\n\n r = rcomp(a,xn)\n\n IF (r==zero) GO TO 290\n\n t = (pn-p)/r\n w = half*(am1-xn)\n\n IF (ABS(t)<=tenth .AND. ABS(w*t)<=tenth) GO TO 150\n\n x = xn*(one-t)\n\n IF (x<=zero) GO TO 280\n\n d = ABS(t)\n GO TO 160\n\n150 CONTINUE\n h = t*(one+w*t)\n x = xn*(one-h)\n IF (x<=zero) GO TO 280\n IF (ABS(w)>=one .AND. ABS(w)*t*t<=eps) RETURN\n d = ABS(h)\n\n160 CONTINUE\n xn = x\n IF (d>tol) GO TO 130\n IF (d<=eps) RETURN\n IF (ABS(p-pn)<=tol*p) RETURN\n GO TO 130\n\n! SCHRODER ITERATION USING Q\n\n170 CONTINUE\n IF (q<=1.E10_dpkind*xmin) GO TO 290\n am1 = (a-half) - half\n\n180 CONTINUE\n IF (a<=amax) GO TO 190\n d = half + (half-xn/a)\n IF (ABS(d)<=e2) GO TO 290\n\n190 CONTINUE\n IF (ierr>=20) GO TO 270\n ierr = ierr + 1\n\n CALL gratio(a,xn,pn,qn,0)\n\n IF (pn==zero .OR. qn==zero) GO TO 290\n\n r = rcomp(a,xn)\n IF (r==zero) GO TO 290\n t = (q-qn)/r\n w = half*(am1-xn)\n IF (ABS(t)<=tenth .AND. ABS(w*t)<=tenth) GO TO 200\n x = xn*(one-t)\n IF (x<=zero) GO TO 280\n d = ABS(t)\n GO TO 210\n\n200 CONTINUE\n h = t*(one+w*t)\n x = xn*(one-h)\n IF (x<=zero) GO TO 280\n IF (ABS(w)>=one .AND. ABS(w)*t*t<=eps) RETURN\n d = ABS(h)\n\n210 CONTINUE\n xn = x\n IF (d>tol) GO TO 180\n IF (d<=eps) RETURN\n IF (ABS(q-qn)<=tol*q) RETURN\n GO TO 180\n\n! SPECIAL CASES\n\n220 CONTINUE\n x = xmax\n RETURN\n\n230 CONTINUE\n IF (q>=0.9E0_dpkind) THEN\n x = -alnrel(-p)\n RETURN\n\n END IF\n\n x = -LOG(q)\n RETURN\n\n! ERROR RETURN\n\n240 CONTINUE\n ierr = -2\n RETURN\n\n250 CONTINUE\n ierr = -3\n RETURN\n\n260 CONTINUE\n ierr = -4\n RETURN\n\n270 CONTINUE\n ierr = -6\n RETURN\n\n280 CONTINUE\n ierr = -7\n RETURN\n\n290 CONTINUE\n x = xn\n ierr = -8\n RETURN\n\n300 CONTINUE\n x = xmax\n ierr = -8\n\n END SUBROUTINE gamma_inverse\n\n!*********************************************************************\n\n FUNCTION inv_gamma(cum,ccum,shape,scale,status,check_input)\n! .. Function Return Value ..\n REAL (dpkind) :: inv_gamma\n! ..\n! .. Scalar Arguments ..\n REAL (dpkind), OPTIONAL, INTENT (IN) :: ccum, cum\n REAL (dpkind), INTENT (IN) :: scale, shape\n INTEGER, OPTIONAL, INTENT (OUT) :: status\n LOGICAL, OPTIONAL, INTENT (IN) :: check_input\n! ..\n CALL cdf_gamma(2,cum=cum,ccum=ccum,x=inv_gamma,shape=shape, &\n scale=scale,status=status,check_input=check_input)\n\n RETURN\n\n END FUNCTION inv_gamma\n\n!*********************************************************************\n\n SUBROUTINE local_cum_gamma(x,shape,scale,cum,ccum)\n!----------------------------------------------------------------------\n\n! Function\n\n! Computes the cumulative of the incomplete gamma\n! distribution, i.e., the integral from 0 to X*SCALE of\n! (1/GAM(SHAPE))*EXP(-T)*T**(SHAPE-1) DT\n! where GAM(SHAPE) is the complete gamma function of SHAPE, i.e.,\n! GAM(SHAPE) = integral from 0 to infinity of\n\n! EXP(-T)*T**(SHAPE-1) DT\n\n! Arguments\n\n! X --> The upper limit of integration of the incomplete gamma.\n! SHAPE --> The shape parameter of the incomplete gamma.\n! SCALE --> The scale parameter of the incomplete gamma\n! CUM <-- Cumulative incomplete gamma distribution.\n! CCUM <-- Compliment of Cumulative incomplete gamma distribution.\n\n! Method\n\n! The cumulative gamma and its inverse are from the following\n! reference:\n! DiDinato, A. R. and Morris, A. H. Computation of the incomplete\n! gamma function ratios and their inverse. ACM Trans. Math.\n! Softw. 12 (1986), 377-393.\n!----------------------------------------------------------------------\n! .. Scalar Arguments ..\n REAL (dpkind), INTENT (OUT) :: ccum, cum\n REAL (dpkind), INTENT (IN) :: scale, shape, x\n! ..\n! .. Local Scalars ..\n REAL (dpkind) :: arg\n! ..\n IF (x<=zero) THEN\n cum = zero\n ccum = one\n\n RETURN\n END IF\n\n arg = x*scale\n\n! Suppose NOTHING bad happens in gratio\n\n CALL gratio(shape,arg,cum,ccum,0)\n\n RETURN\n\n END SUBROUTINE local_cum_gamma\n\n!*********************************************************************\n\n END MODULE cdf_gamma_mod\n", "meta": {"hexsha": "cdacce75f16a4f748dd8b134068c6596155973e4", "size": 21715, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mesas/sas/cdflib90/cdf_gamma_mod.f90", "max_stars_repo_name": "OliverEvans96/mesas", "max_stars_repo_head_hexsha": "eb830074dd3b2977013cda1e2a30b79e10379190", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "mesas/sas/cdflib90/cdf_gamma_mod.f90", "max_issues_repo_name": "OliverEvans96/mesas", "max_issues_repo_head_hexsha": "eb830074dd3b2977013cda1e2a30b79e10379190", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-12-14T03:16:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-14T16:37:17.000Z", "max_forks_repo_path": "mesas/sas/cdflib90/cdf_gamma_mod.f90", "max_forks_repo_name": "OliverEvans96/mesas", "max_forks_repo_head_hexsha": "eb830074dd3b2977013cda1e2a30b79e10379190", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-09-09T18:20:55.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-09T18:20:55.000Z", "avg_line_length": 28.0193548387, "max_line_length": 77, "alphanum_fraction": 0.4946350449, "num_tokens": 6515, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942171172603, "lm_q2_score": 0.7401743505760728, "lm_q1q2_score": 0.6685952105338903}} {"text": "subroutine solver()\n!determines the flow profile around the object. In order to do this we have to solve 2\n!coupled equations:\n! - calculate the streamfunction (psi) by solving Poisson's equation\n! - update the vorticity by solving the vorticity transport equation (from the NS equations)\n!\n!First of all a potential flow is calculated around the object (solving Laplace's equation)\n!then (optionally) the vorticity is turned on and alternately Poisson's equation and the\n!vorticity transport equation are iterated to determine the fluid flow.\n\n use vars\n use parallel\n\n implicit none\n\n real :: time\n double precision :: tstart, tstop\n\n !$OMP PARALLEL\n !solve Laplace's equation for the irrotational flow profile (vorticity=0)\n call poisson(5000)\n !$OMP END PARALLEL\n\n !get the vorticity on the surface of the object\n\n call getvort()\n\n !write out the potential flow to file.\n\n call writetofile(\"potential.dat\")\n\n\n\n\n !if the user has chosen to allow vorticity:\n if (vorticity) then\n\n\n ! set CFL conditions (dt << cell crossing time or cell diffusion time for stability)\n cfl_r0 = 0.25*dx*dy*R0\n cfl_v = 0.25*dx/1. !assume velocty is 1\n\n\n\n !dt is set according to the most restrictive CFL condition\n dt = minval((/ cfl_r0, cfl_v /))\n\n\n\n if (irank .eq. 0) then\n print*,''\n print*,\"CFL (Reynolds, velocity)\", cfl_r0, cfl_v\n print *, \"Timestep=\",dt\n print *, \"\"\n endif\n\n time=0.\n\n if (irank .eq. 0) tstart=MPI_Wtime()\n\n !$OMP PARALLEL\n\n do while (time .lt. real(nx)*crossing_times)\n\n !if (irank .eq. 0) print*, \"t=\",time,\"of\",nx*crossing_times\n\n call getv() !get the velocity\n\n call navier_stokes() !solve dw/dt=f(w,psi) for a timestep\n\n call poisson(2) !2 poisson 'relaxation' steps\n\n !$OMP SINGLE\n time=time+dt\n !$OMP END SINGLE\n !$OMP BARRIER\n\n enddo\n\n !$OMP END PARALLEL\n\n if (irank .eq. 0) then\n tstop=MPI_Wtime()\n print*,''\n print*, \"Time to complete =\",tstop-tstart\n print*,''\n endif\n\n call getvort()\n\n endif\n\n\nend subroutine\n", "meta": {"hexsha": "48ce65b7fd4532d0df1a169fd10b29ae348d365e", "size": 2264, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "windtunnel/simulation/solver.f90", "max_stars_repo_name": "otbrown/wee_archie", "max_stars_repo_head_hexsha": "9dc86c74f54ce05ef2195e92dd914514bda8306b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-01-29T11:14:39.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-29T18:32:01.000Z", "max_issues_repo_path": "windtunnel/simulation/solver.f90", "max_issues_repo_name": "otbrown/wee_archie", "max_issues_repo_head_hexsha": "9dc86c74f54ce05ef2195e92dd914514bda8306b", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2019-02-18T15:18:52.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-11T23:57:45.000Z", "max_forks_repo_path": "windtunnel/simulation/solver.f90", "max_forks_repo_name": "otbrown/wee_archie", "max_forks_repo_head_hexsha": "9dc86c74f54ce05ef2195e92dd914514bda8306b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-03-02T23:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-09T10:17:37.000Z", "avg_line_length": 23.8315789474, "max_line_length": 92, "alphanum_fraction": 0.609540636, "num_tokens": 615, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942067038785, "lm_q2_score": 0.7401743505760727, "lm_q1q2_score": 0.668595202826172}} {"text": "C This one implements depth-first backtracking.\nC See the 2nd program for Scheme on the \"Permutations\" page for the\nC main idea.\nC As is, the program only prints the number of n-queens configurations.\nC To print also the configurations, uncomment the line after label 80.\n program queens\n implicit integer(a-z)\n parameter(l=18)\n dimension a(l),s(l),u(4*l-2)\n do 10 i=1,l\n 10 a(i)=i\n do 20 i=1,4*l-2\n 20 u(i)=0\n do 110 n=1,l\n m=0\n i=1\n r=2*n-1\n go to 40\n 30 s(i)=j\n u(p)=1\n u(q+r)=1\n i=i+1\n 40 if(i.gt.n) go to 80\n j=i\n 50 z=a(i)\n y=a(j)\n p=i-y+n\n q=i+y-1\n a(i)=y\n a(j)=z\n if((u(p).eq.0).and.(u(q+r).eq.0)) goto 30\n 60 j=j+1\n if(j.le.n) go to 50\n 70 j=j-1\n if(j.eq.i) go to 90\n z=a(i)\n a(i)=a(j)\n a(j)=z\n go to 70\n 80 m=m+1\nC print *,(a(k),k=1,n)\n 90 i=i-1\n if(i.eq.0) go to 100\n p=i-a(i)+n\n q=i+a(i)-1\n j=s(i)\n u(p)=0\n u(q+r)=0\n go to 60\n 100 print *,n,m\n 110 continue\n end\n\nC Output\nC 1 1\nC 2 0\nC 3 0\nC 4 2\nC 5 10\nC 6 4\nC 7 40\nC 8 92\nC 9 352\nC 10 724\nC 11 2680\nC 12 14200\nC 13 73712\nC 14 365596\nC 15 2279184\nC 16 14772512\nC 17 95815104\nC 18 666090624\n", "meta": {"hexsha": "f80dfab7248a1d412c874e75232d2193530f48bd", "size": 1533, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/N-queens-problem/Fortran/n-queens-problem-2.f", "max_stars_repo_name": "mullikine/RosettaCodeData", "max_stars_repo_head_hexsha": "4f0027c6ce83daa36118ee8b67915a13cd23ab67", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/N-queens-problem/Fortran/n-queens-problem-2.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/N-queens-problem/Fortran/n-queens-problem-2.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 21.0, "max_line_length": 71, "alphanum_fraction": 0.4259621657, "num_tokens": 589, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942041005328, "lm_q2_score": 0.7401743505760728, "lm_q1q2_score": 0.6685952008992425}} {"text": "#include \"eiscor.h\"\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! z_unihess_factor\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! This routine factors a unitary upper Hessenberg matrix into a \n! sequence of Givens' rotations and a diagonal matrix.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! INPUT VARIABLES:\n!\n! N INTEGER\n! dimension of matrix\n!\n! H COMPLEX(8) array of dimension (N,N)\n! unitary matrix to be reduced\n!\n! Q REAL(8) array of dimension (3*(N-1))\n! array of generators for Givens' rotations\n!\n! D REAL(8) array of dimension (2*N)\n! array of generators for complex diagonal matrix\n!\n! OUTPUT VARIABLES:\n!\n! INFO INTEGER\n! INFO = 0 implies successful computation\n! INFO = -1 implies N is invalid\n! INFO = -2 implies H is invalid\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine z_unihess_factor(N,H,Q,D,INFO)\n\n implicit none\n \n ! input variables\n integer, intent(in) :: N\n real(8), intent(inout) :: Q(3*(N-1)), D(2*N)\n integer, intent(inout) :: INFO\n complex(8), intent(inout) :: H(N,N)\n \n ! compute variables\n logical :: flg\n integer :: ii\n real(8) :: nrm, tol \n real(8) :: cr, ci, s \n \n ! initialize info\n INFO = 0\n \n ! check N\n if (N < 2) then\n INFO = -1\n ! print error in debug mode\n if (DEBUG) then\n call u_infocode_check(__FILE__,__LINE__,\"N must be at least 2\",INFO,INFO)\n end if\n return\n end if\n \n ! check H\n call z_2Darray_check(N,N,H,flg)\n if (.NOT.flg) then\n INFO = -2\n ! print error in debug mode\n if (DEBUG) then\n call u_infocode_check(__FILE__,__LINE__,\"H is invalid\",INFO,INFO)\n end if\n return\n end if \n \n ! set tol\n tol = max(10d0,dble(N))*EISCOR_DBL_EPS\n \n ! loop for reduction\n ! ii is the column being reduced\n do ii=1,(N-1)\n \n ! reduce to block diagonal\n call z_rot3_vec4gen(dble(H(ii,ii)),aimag(H(ii,ii)),dble(H(ii+1,ii)),aimag(H(ii+1,ii)),cr,ci,s,nrm)\n \n ! check for unitarity \n if (abs(nrm-1d0) >= tol) then\n INFO = -2\n ! print error in debug mode\n if (DEBUG) then\n call u_infocode_check(__FILE__,__LINE__,\"H is not unitary\",INFO,INFO)\n end if \n return \n end if\n \n ! update H\n H(ii,ii) = cmplx(cr,-ci,kind=8)*H(ii,ii) + cmplx(s,0d0,kind=8)*H(ii+1,ii)\n H(ii+1,(ii+1):N) = cmplx(-s,0d0,kind=8)*H(ii,(ii+1):N) + cmplx(cr,ci,kind=8)*H(ii+1,(ii+1):N)\n \n ! store in Q\n Q(3*(ii-1)+1) = cr\n Q(3*(ii-1)+2) = ci\n Q(3*(ii-1)+3) = s\n \n ! store in D\n call d_rot2_vec2gen(dble(H(ii,ii)),aimag(H(ii,ii)),D(2*(ii-1)+1),D(2*(ii-1)+2),nrm)\n \n end do\n \n ! store in D\n call d_rot2_vec2gen(dble(H(N,N)),aimag(H(N,N)),D(2*(N-1)+1),D(2*(N-1)+2),nrm)\n \n ! check for unitarity \n if (abs(nrm-1d0) >= tol) then\n INFO = -2\n ! print error in debug mode\n if (DEBUG) then\n call u_infocode_check(__FILE__,__LINE__,\"H is not unitary\",INFO,INFO)\n end if \n return \n end if\n \nend subroutine z_unihess_factor\n", "meta": {"hexsha": "9083455866ed1c63f502f2a1c3106347b82a9a96", "size": 3286, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/AMVW/src/complex_double/z_unihess_factor.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_unihess_factor.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_unihess_factor.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": 26.7154471545, "max_line_length": 102, "alphanum_fraction": 0.5106512477, "num_tokens": 1042, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941988938413, "lm_q2_score": 0.740174350576073, "lm_q1q2_score": 0.6685951970453831}} {"text": "! { dg-do compile }\n!\n! Testcase from PR 54656\n! Checking for NORM2 for large float kinds\n!\nprogram test\n implicit none\n\n ! k1 and k2 will be large real kinds, if supported, and single/double\n ! otherwise\n integer, parameter :: k1 = &\n max(selected_real_kind(precision(0.d0) + 1), kind(0.))\n integer, parameter :: k2 = &\n max(selected_real_kind(precision(0._k1) + 1), kind(0.d0))\n\n real(kind=k1) :: d1(10), z1\n real(kind=k2) :: d2(10), z2\n d1 = 1 ; d2 = 1\n z1 = norm2 (d1)\n z2 = norm2 (d2)\n\n print *, z1, z2\nend program test\n", "meta": {"hexsha": "0416fd67b69b308a4c1f7199a20de2602174a946", "size": 542, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/norm2_5.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_5.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_5.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": 22.5833333333, "max_line_length": 71, "alphanum_fraction": 0.6365313653, "num_tokens": 198, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8376199552262967, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.6685771670007447}} {"text": " Program zheevr_example\n\n! ZHEEVR Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use blas_interfaces, Only: zscal\n Use lapack_example_aux, Only: nagf_file_print_matrix_complex_gen\n Use lapack_interfaces, Only: zheevr\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Real (Kind=dp), Parameter :: zero = 0.0E+0_dp\n Integer, Parameter :: nb = 64, nin = 5, nout = 6\n! .. Local Scalars ..\n Real (Kind=dp) :: abstol, vl, vu\n Integer :: i, ifail, il, info, iu, k, lda, ldz, liwork, lrwork, lwork, &\n m, n\n! .. Local Arrays ..\n Complex (Kind=dp), Allocatable :: a(:, :), work(:), z(:, :)\n Complex (Kind=dp) :: dummy(1)\n Real (Kind=dp) :: rdum(1)\n Real (Kind=dp), Allocatable :: rwork(:), w(:)\n Integer :: idum(1)\n Integer, Allocatable :: isuppz(:), iwork(:)\n! .. Intrinsic Procedures ..\n Intrinsic :: abs, cmplx, conjg, max, maxloc, nint, real\n! .. Executable Statements ..\n Write (nout, *) 'ZHEEVR Example Program Results'\n Write (nout, *)\n! Skip heading in data file and read N and the lower and upper\n! indices of the smallest and largest eigenvalues to be found\n Read (nin, *)\n Read (nin, *) n, il, iu\n lda = n\n ldz = n\n m = n\n Allocate (a(lda,n), z(ldz,m), w(n), isuppz(2*m))\n\n! Use routine workspace query to get optimal workspace.\n lwork = -1\n liwork = -1\n lrwork = -1\n Call zheevr('Vectors', 'I', 'Upper', n, a, lda, vl, vu, il, iu, abstol, &\n m, w, z, ldz, isuppz, dummy, lwork, rdum, lrwork, idum, liwork, info)\n\n! Make sure that there is enough workspace for block size nb.\n lwork = max((nb+1)*n, nint(real(dummy(1))))\n lrwork = max(24*n, nint(rdum(1)))\n liwork = max(10*n, idum(1))\n Allocate (work(lwork), rwork(lrwork), iwork(liwork))\n\n! Read the upper triangular part of the matrix A from data file\n\n Read (nin, *)(a(i,i:n), i=1, n)\n\n! Set the absolute error tolerance for eigenvalues. With ABSTOL\n! set to zero, the default value is used instead\n\n abstol = zero\n\n! Solve the symmetric eigenvalue problem\n\n Call zheevr('Vectors', 'I', 'Upper', n, a, lda, vl, vu, il, iu, abstol, &\n m, w, z, ldz, isuppz, work, lwork, rwork, lrwork, iwork, liwork, info)\n\n If (info==0) Then\n\n! Print solution\n\n Write (nout, *) 'Selected eigenvalues'\n Write (nout, 100) w(1:m)\n Flush (nout)\n\n! Normalize the eigenvectors so that the element of largest absolute\n! value is real.\n Do i = 1, m\n rwork(1:n) = abs(z(1:n,i))\n k = maxloc(rwork(1:n), 1)\n Call zscal(n, conjg(z(k,i))/cmplx(abs(z(k,i)),kind=dp), z(1,i), 1)\n End Do\n\n! ifail: behaviour on error exit\n! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft\n ifail = 0\n Call nagf_file_print_matrix_complex_gen('General', ' ', n, m, z, ldz, &\n 'Selected eigenvectors', ifail)\n Else\n Write (nout, 110) 'Failure in ZHEEVR. INFO =', info\n End If\n\n100 Format (3X, (8F8.4))\n110 Format (1X, A, I5)\n End Program\n", "meta": {"hexsha": "f6b955af16ec294e5f24c24285afe01e41da8033", "size": 3389, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/zheevr_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/zheevr_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/zheevr_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 34.2323232323, "max_line_length": 90, "alphanum_fraction": 0.5812924166, "num_tokens": 1073, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.885631476836816, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6685764747058232}} {"text": "! =============================================================================\n! Test the vorticity inversion\n!\n! This unit test checks the calculation of the velocity using the\n! Taylor-Green flow:\n! u = A * cos(a * x) * sin(b * y) * sin(c * z)\n! v = B * sin(a * x) * cos(b * y) * sin(c * z)\n! w = C * sin(a * x) * sin(b * y) * cos(c * z)\n! The vorticity of this flow is\n! xi = (b * C - c * B) * sin(a * x) * cos(b * y) * cos(c * z)\n! eta = (c * A - a * C) * cos(a * x) * sin(b * y) * cos(c * z)\n! zeta = (a * B - b * A) * cos(a * x) * cos(b * y) * sin(c * z)\n! =============================================================================\nprogram test_vor2vel_2\n use unit_test\n use constants, only : zero, one, two, four, pi, twopi, f12\n use parameters, only : lower, update_parameters, dx, nx, ny, nz, extent\n use fields, only : vortg, velog, velgradg, field_alloc\n use inversion_utils, only : init_fft, fftxyp2s\n use inversion_mod, only : vor2vel, vor2vel_timer\n use timer\n implicit none\n\n double precision :: error\n double precision, allocatable :: velog_ref(:, :, :, :)\n integer :: ix, iy, iz\n double precision :: x, y, z, AA, BB, CC, a, b, c\n\n call register_timer('vorticity', vor2vel_timer)\n\n nx = 64\n ny = 64\n nz = 64\n\n lower = (/-pi, -pi, -f12 * pi/)\n extent = (/twopi, twopi, twopi/)\n\n AA = one\n BB = one\n CC = -two\n a = one\n b = one\n c = one\n\n allocate(velog_ref(-1:nz+1, 0:ny-1, 0:nx-1, 3))\n\n call update_parameters\n\n call field_alloc\n\n do ix = 0, nx-1\n x = lower(1) + ix * dx(1)\n do iy = 0, ny-1\n y = lower(2) + iy * dx(2)\n do iz = -1, nz+1\n z = lower(3) + iz * dx(3)\n\n ! vorticity\n vortg(iz, iy, ix, 1) = (b * CC - c * BB) * dsin(a * x) * dcos(b * y) * dcos(c * z)\n vortg(iz, iy, ix, 2) = (c * AA - a * CC) * dcos(a * x) * dsin(b * y) * dcos(c * z)\n vortg(iz, iy, ix, 3) = (a * BB - b * AA) * dcos(a * x) * dcos(b * y) * dsin(c * z)\n\n ! velocity (reference solution)\n velog_ref(iz, iy, ix, 1) = AA * dcos(a * x) * dsin(b * y) * dsin(c * z)\n velog_ref(iz, iy, ix, 2) = BB * dsin(a * x) * dcos(b * y) * dsin(c * z)\n velog_ref(iz, iy, ix, 3) = CC * dsin(a * x) * dsin(b * y) * dcos(c * z)\n\n enddo\n enddo\n enddo\n\n call init_fft\n\n call vor2vel(vortg, velog, velgradg)\n\n error = maxval(dabs(velog_ref(0:nz, :, :, :) - velog(0:nz, :, :, :)))\n\n call print_result_dp('Test inversion (vorticity)', error, atol=2.0e-3)\n\n deallocate(velog_ref)\n\nend program test_vor2vel_2\n", "meta": {"hexsha": "e55a454f82367c2abf6b22d65e4a352d489e4c76", "size": 2823, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "unit-tests/3d/test_vor2vel.f90", "max_stars_repo_name": "matt-frey/epic", "max_stars_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2021-11-11T10:50:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T00:11:41.000Z", "max_issues_repo_path": "unit-tests/3d/test_vor2vel.f90", "max_issues_repo_name": "matt-frey/epic", "max_issues_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 47, "max_issues_repo_issues_event_min_datetime": "2021-11-12T17:09:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-24T16:50:58.000Z", "max_forks_repo_path": "unit-tests/3d/test_vor2vel.f90", "max_forks_repo_name": "matt-frey/epic", "max_forks_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.0120481928, "max_line_length": 98, "alphanum_fraction": 0.4509387177, "num_tokens": 955, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809304, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6685764629860483}} {"text": "! Largest prime factor\n!\n! The prime factors of 13195 are 5, 7, 13 and 29.\n! What is the largest prime factor of the number 600851475143 ?\nmodule Problem3\n\n implicit none\n private\n\n public :: solve\ncontains\n subroutine solve\n write (*, '(A)') 'Problem 3. Largest prime factor.'\n\n write (*, '(A, I)') 'Factor 1: ', factor()\n end subroutine\n\n function factor()\n integer*8 factor\n integer*8 index\n\n factor = 600851475143\n index = 2\n\n do while ((index ** 2) .le. factor)\n if (mod(factor, index) .eq. 0) then\n factor = factor / index\n else\n index = index + 1\n end if\n end do\n end function\nend module\n", "meta": {"hexsha": "2d018327d8c0a2a2933100545665f7e9b1b5ce56", "size": 736, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Problem3.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": "Problem3.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": "Problem3.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": 21.6470588235, "max_line_length": 63, "alphanum_fraction": 0.5502717391, "num_tokens": 199, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.7549149758396752, "lm_q1q2_score": 0.6685764581026971}} {"text": "! test.f90\nmodule mymodule\nuse, intrinsic :: iso_fortran_env, only: real64\ncontains\nsubroutine eikR(a,k,n,M)\n implicit none\n\n integer, intent(in) :: n\n real(real64), intent(in) :: a(n)\n complex(real64), intent(in) :: k\n complex(real64), intent(out) :: M(n,n)\n\n ! Local\n integer :: i, j\n real(real64) :: rtmp(n), sinp(n), cosp(n), tmp_exp(n)\n real(real64) :: itmp(n), a_pow_2(n)\n\n complex(real64) :: imk\n real(real64) :: rimk\n real(real64) :: iimk, tmp\n\n imk = (0,1) * k\n rimk = real(imk)\n iimk = imag(imk)\n\n a_pow_2 = a * a\n \n !$OMP PARALLEL DO DEFAULT(private) SHARED(a_pow_2, M, n, rimk,iimk)\n do j=1,n\n \n rtmp = a_pow_2 + a_pow_2(j)\n call vdsqrt(n, rtmp, rtmp)\n\n ! real part\n call vdexp(n, rimk * rtmp, tmp_exp)\n\n ! imag part\n call vdsincos(n, iimk * rtmp, sinp, cosp)\n\n ! assemble output\n M(:, j) = cmplx(tmp_exp * cosp, tmp_exp * sinp)\n end do\n !$OMP END PARALLEL DO\n\nend subroutine eikR\nend module\n\nprogram test\nuse, intrinsic :: iso_fortran_env, only: real64\nuse mymodule\nuse omp_lib\nreal(real64), parameter :: pi = 4*atan(1.0)\ninteger :: i, j, n\nreal(real64), allocatable :: a(:)\ncomplex(real64) :: k\ncomplex(real64), allocatable :: m(:, :)\nreal(real64) :: t1, t2\ndo i = 1, 10\n t1 = omp_get_wtime()\n n = 1000*i\n if(allocated(m)) deallocate(m)\n allocate(m(n, n))\n a = [(2*j*pi/(n - 1), j=0, n - 1)]\n k = cmplx(100.0, 1.0)\n call eikr(a, k, n, m)\n t2 = omp_get_wtime()\n print *, n, t2 - t1, 'seconds'\nenddo\nend program\n", "meta": {"hexsha": "29b0e1a09491c83a8475322018f17089716286a8", "size": 1590, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "f_standalone_mkl.f90", "max_stars_repo_name": "mdmaas/julia-numpy-fortran-test", "max_stars_repo_head_hexsha": "f8963000e260181f97f5582bd2ecdf633ac3f717", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-06-21T18:15:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-12T15:54:36.000Z", "max_issues_repo_path": "f_standalone_mkl.f90", "max_issues_repo_name": "mdmaas/julia-numpy-fortran-test", "max_issues_repo_head_hexsha": "f8963000e260181f97f5582bd2ecdf633ac3f717", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2021-06-21T18:36:26.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-28T06:27:42.000Z", "max_forks_repo_path": "f_standalone_mkl.f90", "max_forks_repo_name": "mdmaas/julia-numpy-fortran-test", "max_forks_repo_head_hexsha": "f8963000e260181f97f5582bd2ecdf633ac3f717", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-06-21T01:41:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-21T18:15:37.000Z", "avg_line_length": 22.7142857143, "max_line_length": 71, "alphanum_fraction": 0.5729559748, "num_tokens": 578, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037282594921, "lm_q2_score": 0.7217431943271999, "lm_q1q2_score": 0.6685534117512004}} {"text": " SUBROUTINE MB02FD( TYPET, K, N, P, S, T, LDT, R, LDR, DWORK,\n $ LDWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute the incomplete Cholesky (ICC) factor of a symmetric\nC positive definite (s.p.d.) block Toeplitz matrix T, defined by\nC either its first block row, or its first block column, depending\nC on the routine parameter TYPET.\nC\nC By subsequent calls of this routine, further rows / columns of\nC the Cholesky factor can be added.\nC Furthermore, the generator of the Schur complement of the leading\nC (P+S)*K-by-(P+S)*K block in T is available, which can be used,\nC e.g., for measuring the quality of the ICC factorization.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC TYPET CHARACTER*1\nC Specifies the type of T, as follows:\nC = 'R': T contains the first block row of an s.p.d. block\nC Toeplitz matrix; the ICC factor R is upper\nC trapezoidal;\nC = 'C': T contains the first block column of an s.p.d.\nC block Toeplitz matrix; the ICC factor R is lower\nC trapezoidal; this choice leads to better\nC localized memory references and hence a faster\nC algorithm.\nC Note: in the sequel, the notation x / y means that\nC x corresponds to TYPET = 'R' and y corresponds to\nC TYPET = 'C'.\nC\nC Input/Output Parameters\nC\nC K (input) INTEGER\nC The number of rows / columns in T, which should be equal\nC to the blocksize. K >= 0.\nC\nC N (input) INTEGER\nC The number of blocks in T. N >= 0.\nC\nC P (input) INTEGER\nC The number of previously computed block rows / columns\nC of R. 0 <= P <= N.\nC\nC S (input) INTEGER\nC The number of block rows / columns of R to compute.\nC 0 <= S <= N-P.\nC\nC T (input/output) DOUBLE PRECISION array, dimension\nC (LDT,(N-P)*K) / (LDT,K)\nC On entry, if P = 0, then the leading K-by-N*K / N*K-by-K\nC part of this array must contain the first block row /\nC column of an s.p.d. block Toeplitz matrix.\nC If P > 0, the leading K-by-(N-P)*K / (N-P)*K-by-K must\nC contain the negative generator of the Schur complement of\nC the leading P*K-by-P*K part in T, computed from previous\nC calls of this routine.\nC On exit, if INFO = 0, then the leading K-by-(N-P)*K /\nC (N-P)*K-by-K part of this array contains, in the first\nC K-by-K block, the upper / lower Cholesky factor of\nC T(1:K,1:K), in the following S-1 K-by-K blocks, the\nC Householder transformations applied during the process,\nC and in the remaining part, the negative generator of the\nC Schur complement of the leading (P+S)*K-by(P+S)*K part\nC in T.\nC\nC LDT INTEGER\nC The leading dimension of the array T.\nC LDT >= MAX(1,K), if TYPET = 'R';\nC LDT >= MAX(1,(N-P)*K), if TYPET = 'C'.\nC\nC R (input/output) DOUBLE PRECISION array, dimension\nC (LDR, N*K) / (LDR, S*K ) if P = 0;\nC (LDR, (N-P+1)*K) / (LDR, (S+1)*K ) if P > 0.\nC On entry, if P > 0, then the leading K-by-(N-P+1)*K /\nC (N-P+1)*K-by-K part of this array must contain the\nC nonzero blocks of the last block row / column in the\nC ICC factor from a previous call of this routine. Note that\nC this part is identical with the positive generator of\nC the Schur complement of the leading P*K-by-P*K part in T.\nC If P = 0, then R is only an output parameter.\nC On exit, if INFO = 0 and P = 0, then the leading\nC S*K-by-N*K / N*K-by-S*K part of this array contains the\nC upper / lower trapezoidal ICC factor.\nC On exit, if INFO = 0 and P > 0, then the leading\nC (S+1)*K-by-(N-P+1)*K / (N-P+1)*K-by-(S+1)*K part of this\nC array contains the upper / lower trapezoidal part of the\nC P-th to (P+S)-th block rows / columns of the ICC factor.\nC The elements in the strictly lower / upper trapezoidal\nC part are not referenced.\nC\nC LDR INTEGER\nC The leading dimension of the array R.\nC LDR >= MAX(1, S*K ), if TYPET = 'R' and P = 0;\nC LDR >= MAX(1, (S+1)*K ), if TYPET = 'R' and P > 0;\nC LDR >= MAX(1, N*K ), if TYPET = 'C' and P = 0;\nC LDR >= MAX(1, (N-P+1)*K ), if TYPET = 'C' and P > 0.\nC\nC Workspace\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0, DWORK(1) returns the optimal\nC value of LDWORK.\nC On exit, if INFO = -11, DWORK(1) returns the minimum\nC value of LDWORK.\nC\nC LDWORK INTEGER\nC The length of the array DWORK.\nC LDWORK >= MAX(1,(N+1)*K,4*K), if P = 0;\nC LDWORK >= MAX(1,(N-P+2)*K,4*K), if P > 0.\nC For optimum performance LDWORK should be larger.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value;\nC = 1: the reduction algorithm failed; the Toeplitz matrix\nC associated with T is not (numerically) positive\nC definite in its leading (P+S)*K-by-(P+S)*K part.\nC\nC METHOD\nC\nC Householder transformations and modified hyperbolic rotations\nC are used in the Schur algorithm [1], [2].\nC\nC REFERENCES\nC\nC [1] Kailath, T. and Sayed, A.\nC Fast Reliable Algorithms for Matrices with Structure.\nC SIAM Publications, Philadelphia, 1999.\nC\nC [2] Kressner, D. and Van Dooren, P.\nC Factorizations and linear system solvers for matrices with\nC Toeplitz structure.\nC SLICOT Working Note 2000-2, 2000.\nC\nC NUMERICAL ASPECTS\nC\nC The implemented method is numerically stable.\nC 3\nC The algorithm requires 0(K S (N-P)) floating point operations.\nC\nC CONTRIBUTOR\nC\nC D. Kressner, Technical Univ. Berlin, Germany, April 2001.\nC\nC REVISIONS\nC\nC V. Sima, Research Institute for Informatics, Bucharest, Apr. 2001,\nC Mar. 2004.\nC\nC KEYWORDS\nC\nC Elementary matrix operations, Householder transformation, matrix\nC operations, Toeplitz matrix.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ONE\n PARAMETER ( ONE = 1.0D0 )\nC .. Scalar Arguments ..\n CHARACTER TYPET\n INTEGER INFO, K, LDR, LDT, LDWORK, N, P, S\nC .. Array Arguments ..\n DOUBLE PRECISION DWORK(*), R(LDR,*), T(LDT,*)\nC .. Local Scalars ..\n INTEGER COUNTR, I, IERR, MAXWRK, ST, STARTR\n LOGICAL ISROW\nC .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\nC .. External Subroutines ..\n EXTERNAL DLACPY, DPOTRF, DTRSM, MB02CX, MB02CY, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC INT, MAX, MIN\nC\nC .. Executable Statements ..\nC\nC Decode the scalar input parameters.\nC\n INFO = 0\n ISROW = LSAME( TYPET, 'R' )\nC\nC Check the scalar input parameters.\nC\n IF ( .NOT.( ISROW .OR. LSAME( TYPET, 'C' ) ) ) THEN\n INFO = -1\n ELSE IF ( K.LT.0 ) THEN\n INFO = -2\n ELSE IF ( N.LT.0 ) THEN\n INFO = -3\n ELSE IF ( P.LT.0 .OR. P.GT.N ) THEN\n INFO = -4\n ELSE IF ( S.LT.0 .OR. S.GT.( N-P ) ) THEN\n INFO = -5\n ELSE IF ( LDT.LT.1 .OR. ( ISROW .AND. LDT.LT.K ) .OR.\n $ ( .NOT.ISROW .AND. LDT.LT.( N-P )*K ) ) THEN\n INFO = -7\n ELSE IF ( LDR.LT.1 .OR.\n $ ( ISROW .AND. P.EQ.0 .AND. ( LDR.LT.S*K ) ) .OR.\n $ ( ISROW .AND. P.GT.0 .AND. ( LDR.LT.( S+1 )*K ) ) .OR.\n $ ( .NOT.ISROW .AND. P.EQ.0 .AND. ( LDR.LT.N*K ) ) .OR.\n $ ( .NOT.ISROW .AND. P.GT.0 .AND. ( LDR.LT.( N-P+1 )*K ) ) ) THEN\n INFO = -9\n ELSE\n IF ( P.EQ.0 ) THEN\n COUNTR = ( N + 1 )*K\n ELSE\n COUNTR = ( N - P + 2 )*K\n END IF\n COUNTR = MAX( COUNTR, 4*K )\n IF ( LDWORK.LT.MAX( 1, COUNTR ) ) THEN\n DWORK(1) = MAX( 1, COUNTR )\n INFO = -11\n END IF\n END IF\nC\nC Return if there were illegal values.\nC\n IF ( INFO.NE.0 ) THEN\n CALL XERBLA( 'MB02FD', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF ( MIN( K, N, S ).EQ.0 ) THEN\n DWORK(1) = ONE\n RETURN\n END IF\nC\n MAXWRK = 1\nC\n IF ( ISROW ) THEN\nC\n IF ( P.EQ.0 ) THEN\nC\nC T is the first block row of a block Toeplitz matrix.\nC Bring T to proper form by triangularizing its first block.\nC\n CALL DPOTRF( 'Upper', K, T, LDT, IERR )\n IF ( IERR.NE.0 ) THEN\nC\nC Error return: The matrix is not positive definite.\nC\n INFO = 1\n RETURN\n END IF\nC\n IF ( N.GT.1 )\n $ CALL DTRSM( 'Left', 'Upper', 'Transpose', 'NonUnit', K,\n $ (N-1)*K, ONE, T, LDT, T(1,K+1), LDT )\n CALL DLACPY( 'Upper', K, N*K, T, LDT, R, LDR )\nC\n IF ( S.EQ.1 ) THEN\n DWORK(1) = ONE\n RETURN\n END IF\nC\n ST = 2\n COUNTR = ( N - 1 )*K\n ELSE\n ST = 1\n COUNTR = ( N - P )*K\n END IF\nC\n STARTR = 1\nC\n DO 10 I = ST, S\n CALL DLACPY( 'Upper', K, COUNTR, R(STARTR,STARTR), LDR,\n $ R(STARTR+K,STARTR+K), LDR )\n STARTR = STARTR + K\n COUNTR = COUNTR - K\n CALL MB02CX( 'Row', K, K, K, R(STARTR,STARTR), LDR,\n $ T(1,STARTR), LDT, DWORK, 3*K, DWORK(3*K+1),\n $ LDWORK-3*K, IERR )\n IF ( IERR.NE.0 ) THEN\nC\nC Error return: The matrix is not positive definite.\nC\n INFO = 1\n RETURN\n END IF\nC\n MAXWRK = MAX( MAXWRK, INT( DWORK(3*K+1) ) + 3*K )\n CALL MB02CY( 'Row', 'NoStructure', K, K, COUNTR, K,\n $ R(STARTR,STARTR+K), LDR, T(1,STARTR+K), LDT,\n $ T(1,STARTR), LDT, DWORK, 3*K, DWORK(3*K+1),\n $ LDWORK-3*K, IERR )\n MAXWRK = MAX( MAXWRK, INT( DWORK(3*K+1) ) + 3*K )\n 10 CONTINUE\nC\n ELSE\nC\n IF ( P.EQ.0 ) THEN\nC\nC T is the first block column of a block Toeplitz matrix.\nC Bring T to proper form by triangularizing its first block.\nC\n CALL DPOTRF( 'Lower', K, T, LDT, IERR )\n IF ( IERR.NE.0 ) THEN\nC\nC Error return: The matrix is not positive definite.\nC\n INFO = 1\n RETURN\n END IF\nC\n IF ( N.GT.1 )\n $ CALL DTRSM( 'Right', 'Lower', 'Transpose', 'NonUnit',\n $ (N-1)*K, K, ONE, T, LDT, T(K+1,1), LDT )\n CALL DLACPY( 'Lower', N*K, K, T, LDT, R, LDR )\nC\n IF ( S.EQ.1 ) THEN\n DWORK(1) = ONE\n RETURN\n END IF\nC\n ST = 2\n COUNTR = ( N - 1 )*K\n ELSE\n ST = 1\n COUNTR = ( N - P )*K\n END IF\nC\n STARTR = 1\nC\n DO 20 I = ST, S\n CALL DLACPY( 'Lower', COUNTR, K, R(STARTR,STARTR), LDR,\n $ R(STARTR+K,STARTR+K), LDR )\n STARTR = STARTR + K\n COUNTR = COUNTR - K\n CALL MB02CX( 'Column', K, K, K, R(STARTR,STARTR), LDR,\n $ T(STARTR,1), LDT, DWORK, 3*K, DWORK(3*K+1),\n $ LDWORK-3*K, IERR )\n IF ( IERR.NE.0 ) THEN\nC\nC Error return: The matrix is not positive definite.\nC\n INFO = 1\n RETURN\n END IF\nC\n MAXWRK = MAX( MAXWRK, INT( DWORK(3*K+1) ) + 3*K )\n CALL MB02CY( 'Column', 'NoStructure', K, K, COUNTR, K,\n $ R(STARTR+K,STARTR), LDR, T(STARTR+K,1), LDT,\n $ T(STARTR,1), LDT, DWORK, 3*K, DWORK(3*K+1),\n $ LDWORK-3*K, IERR )\n MAXWRK = MAX( MAXWRK, INT( DWORK(3*K+1) ) + 3*K )\n 20 CONTINUE\nC\n END IF\nC\n DWORK(1) = MAXWRK\nC\n RETURN\nC\nC *** Last line of MB02FD ***\n END\n", "meta": {"hexsha": "21b2973453af2b444a46a8ca5c0d47bc71198c06", "size": 12867, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB02FD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB02FD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB02FD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 34.7756756757, "max_line_length": 72, "alphanum_fraction": 0.5001942955, "num_tokens": 4029, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.934395168021653, "lm_q2_score": 0.7154239957834734, "lm_q1q2_score": 0.668488724746821}} {"text": "! ============================================================================\nsubroutine tfluct1(maxnx,meqn,mwaves,maux,mbc,mx,ql,qr,auxl,auxr,adq)\n! ============================================================================\n! \"Internal\" Riemann solver for the euler equations in 1D.\n! The riemann problem is solved by assuming a discontinuity at the\n! center of the i'th cell.\n!\n! On input, ql contains the state vector at the left edge of each cell\n! qr contains the state vector at the right edge of each cell\n! auxl contains the auxiliary vector at the left edge of each cell\n! auxr contains the state vector at the right edge of each cell\n! maxnx is the number of physical points (without ghost cells)\n! mbc is the number of ghost cells\n! meqn is the number of equations\n! ixyz is the dimension index\n! mx is the size of the patch for the dimension corresponding\n! to the value of ixyz\n!\n! On output, adq contains the decomposition of the flux difference\n! f(qr(i)) - f(ql(i)).\n!\n! For the Euler equations q = (q1, q2, q3)^T, \n! where q1 = rho, q2 = rho*u, q3 = E and\n! _ _ \n! | q2 |\n! f(q) = | 0.5(3-gamma)q2^2/q1 + (gamma-1)q3 |\n! |_ ( gamma*q3 - 0.5(gamma-1)q2^2/q1 ) * q2/g1 _|\n\n\n implicit none\n integer, intent(in) :: maxnx, mx, meqn, mwaves, maux, mbc\n double precision, intent(in) :: auxl(maux,1-mbc:maxnx+mbc)\n double precision, intent(in) :: auxr(maux,1-mbc:maxnx+mbc)\n double precision, intent(in) :: ql(meqn,1-mbc:maxnx+mbc)\n double precision, intent(in) :: qr(meqn,1-mbc:maxnx+mbc)\n\n double precision, intent(out) :: adq(meqn,1-mbc:maxnx+mbc)\n\n integer :: i\n double precision :: gamma, gamma1\n\n! local storage\n! ---------------\n common /cparam/ gamma\n\n gamma1 = gamma - 1.d0\n\n do i = 1,mx\n adq(1,i) = qr(2,i) - ql(2,i)\n adq(2,i) = 0.5d0*(3.d0-gamma)*(qr(2,i)**2/qr(1,i) - ql(2,i)**2/ql(1,i)) &\n + gamma1*(qr(3,i) - ql(3,i))\n adq(3,i) = (gamma*qr(3,i)-0.5d0*gamma1*qr(2,i)**2/qr(1,i))*qr(2,i)/qr(1,i) & \n - (gamma*ql(3,i)-0.5d0*gamma1*ql(2,i)**2/ql(1,i))*ql(2,i)/ql(1,i)\n enddo\n\n return\nend subroutine tfluct1\n", "meta": {"hexsha": "f1cb81adf50751979d4692aea15cab9b1cc5913d", "size": 2437, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/euler_1d/euler_tfluct.f90", "max_stars_repo_name": "gyanz/pyclaw", "max_stars_repo_head_hexsha": "15bbd970dd84ba69337e2cee2b0b1522811b0af5", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 98, "max_stars_repo_stars_event_min_datetime": "2015-01-22T19:35:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-06T11:53:23.000Z", "max_issues_repo_path": "examples/euler_1d/euler_tfluct.f90", "max_issues_repo_name": "gyanz/pyclaw", "max_issues_repo_head_hexsha": "15bbd970dd84ba69337e2cee2b0b1522811b0af5", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 171, "max_issues_repo_issues_event_min_datetime": "2015-01-07T19:00:39.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-27T23:48:21.000Z", "max_forks_repo_path": "examples/euler_1d/euler_tfluct.f90", "max_forks_repo_name": "gyanz/pyclaw", "max_forks_repo_head_hexsha": "15bbd970dd84ba69337e2cee2b0b1522811b0af5", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 64, "max_forks_repo_forks_event_min_datetime": "2015-01-10T00:04:31.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-11T08:56:32.000Z", "avg_line_length": 42.0172413793, "max_line_length": 85, "alphanum_fraction": 0.5116947066, "num_tokens": 754, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951570602081, "lm_q2_score": 0.7154240018510026, "lm_q1q2_score": 0.6684887225742102}} {"text": " PROGRAM LOOPNESTED\n INTEGER A, I, J, RNDINT\n\nC Build a two-dimensional twenty-by-twenty array.\n DIMENSION A(20,20)\n\nC It doesn't matter what number you put here.\n CALL SDRAND(123)\n\nC Fill the array with random numbers.\n DO 20 I = 1, 20\n DO 10 J = 1, 20\n A(I, J) = RNDINT(1, 20)\n 10 CONTINUE\n 20 CONTINUE\n\nC Print the numbers.\n DO 40 I = 1, 20\n DO 30 J = 1, 20\n WRITE (*,5000) I, J, A(I, J)\n\nC If this number is twenty, break out of both loops.\n IF (A(I, J) .EQ. 20) GOTO 50\n 30 CONTINUE\n 40 CONTINUE\n\nC If we had gone to 40, the DO loop would have continued. You can\nC label STOP instead of adding another CONTINUE, but it is good\nC form to only label CONTINUE statements as much as possible.\n 50 CONTINUE\n STOP\n\nC Print the value so that it looks like one of those C arrays that\nC makes everybody so comfortable.\n 5000 FORMAT('A[', I2, '][', I2, '] is ', I2)\n END\n\nC FORTRAN 77 does not have come with a random number generator, but it\nC is easy enough to type \"fortran 77 random number generator\" into your\nC preferred search engine and to copy and paste what you find. The\nC following code is a slightly-modified version of:\nC\nC http://www.tat.physik.uni-tuebingen.de/\nC ~kley/lehre/ftn77/tutorial/subprograms.html\n SUBROUTINE SDRAND (IRSEED)\n COMMON /SEED/ UTSEED, IRFRST\n UTSEED = IRSEED\n IRFRST = 0\n RETURN\n END\n INTEGER FUNCTION RNDINT (IFROM, ITO)\n INTEGER IFROM, ITO\n PARAMETER (MPLIER=16807, MODLUS=2147483647, &\n & MOBYMP=127773, MOMDMP=2836)\n COMMON /SEED/ UTSEED, IRFRST\n INTEGER HVLUE, LVLUE, TESTV, NEXTN\n SAVE NEXTN\n IF (IRFRST .EQ. 0) THEN\n NEXTN = UTSEED\n IRFRST = 1\n ENDIF\n HVLUE = NEXTN / MOBYMP\n LVLUE = MOD(NEXTN, MOBYMP)\n TESTV = MPLIER*LVLUE - MOMDMP*HVLUE\n IF (TESTV .GT. 0) THEN\n NEXTN = TESTV\n ELSE\n NEXTN = TESTV + MODLUS\n ENDIF\n IF (NEXTN .GE. 0) THEN\n RNDINT = MOD(MOD(NEXTN, MODLUS), ITO - IFROM + 1) + IFROM\n ELSE\n RNDINT = MOD(MOD(NEXTN, MODLUS), ITO - IFROM + 1) + ITO + 1\n ENDIF\n RETURN\n END\n", "meta": {"hexsha": "9e7f279f923cd3f5c0cc85875a61e1ed32f22fb8", "size": 2396, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Loops-Nested/Fortran/loops-nested-1.f", "max_stars_repo_name": "djgoku/RosettaCodeData", "max_stars_repo_head_hexsha": "91df62d46142e921b3eacdb52b0316c39ee236bc", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Task/Loops-Nested/Fortran/loops-nested-1.f", "max_issues_repo_name": "djgoku/RosettaCodeData", "max_issues_repo_head_hexsha": "91df62d46142e921b3eacdb52b0316c39ee236bc", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Loops-Nested/Fortran/loops-nested-1.f", "max_forks_repo_name": "djgoku/RosettaCodeData", "max_forks_repo_head_hexsha": "91df62d46142e921b3eacdb52b0316c39ee236bc", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.1168831169, "max_line_length": 73, "alphanum_fraction": 0.5692821369, "num_tokens": 774, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473846343394, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6684742600638748}} {"text": "module interface_definitions\n\n! \tuse constants\n\n interface\n\n\t\t! BLAS function for computation of L2 norm\n \tfunction dnrm2( n, x, incx )\n \t\tuse constants\n \t\timplicit none\n\n \t\t! input variables\n \t\tinteger,intent(in) ::\t\t\t\t\t\tn\n \t\treal(kind=dbl), dimension(:), intent(in) :: x\n \t\tinteger, intent(in) ::\t\t\t\t\t\tincx\n\n \t\t! output variables\n \t\treal(kind=dbl) :: \t\t\t\t\t\t\tdnrm2\n\n \tend function dnrm2\n\n\n\t\t! LAPACK subroutine for solving system of linear equations\n\t\tsubroutine dgesv(n, nrhs, a, lda, ipiv, b, ldb, info)\n\t\t\tuse constants\n\t\t\timplicit none\n\n\t\t\t! input variables\n\t\t\tinteger, intent(in) :: n\n\t\t\tinteger, intent(in) :: nrhs\n\t\t\tinteger, intent(in) :: lda\n\t\t\tinteger, intent(in) :: ldb\n\n\t\t\t! output variables\n\t\t\treal(kind=dbl), dimension(lda,n), intent(inout) :: a\n\t\t\tinteger, dimension(n), intent(out) :: ipiv\n\t\t\treal(kind=dbl), dimension(lda,nrhs), intent(inout) :: b\n\t\t\tinteger, intent(out) :: info\n\n\t\tend subroutine dgesv\n\n\n\t\t! LAPACK subroutine for LU factorization\n\t\tsubroutine dgetrf(m, n, a, lda, ipiv, info)\n\t\t\tuse constants\n\t\t\timplicit none\n\n\t\t\t! input variables\n\t\t\tinteger, intent(in) :: m\n\t\t\tinteger, intent(in) :: n\n\t\t\tinteger, intent(in) :: lda\n\n\t\t\t! output variables\n\t\t\treal(kind=dbl), dimension(lda,n), intent(inout) :: a\n\t\t\tinteger, dimension(n), intent(out) :: ipiv\n\t\t\tinteger, intent(out) :: info\n\n\t\tend subroutine dgetrf\n\n\n\t\t! LAPACK subroutine for computation of inverse matrix based on LU factorization\n\t\tsubroutine dgetri(n, a, lda, ipiv, work, lwork, info)\n\t\t\tuse constants\n\t\t\timplicit none\n\n\t\t\t! input variables\n\t\t\tinteger, intent(in) :: n\n\t\t\tinteger, intent(in) :: lda\n\t\t\tinteger, intent(in) :: lwork\n\t\t\tinteger, dimension(n), intent(in) :: ipiv\n\n\t\t\t! output variables\n\t\t\treal(kind=dbl), dimension(lda,n), intent(inout) :: a\n\t\t\treal(kind=dbl), dimension(lwork), intent(out) :: work\n\t\t\tinteger, intent(out) :: info\n\n\t\tend subroutine dgetri\n\n\n end interface\n\nend module interface_definitions\n", "meta": {"hexsha": "3e078bd180cb0a7cc6f3a05054cc5e3dbc7c9536", "size": 1951, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "interface_definitions.f90", "max_stars_repo_name": "yuyong1990/TsaiWu-Fortran", "max_stars_repo_head_hexsha": "a111ca1717adfbbaf3e9e34f4189a441e16441b8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2017-11-19T15:12:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T15:34:59.000Z", "max_issues_repo_path": "interface_definitions.f90", "max_issues_repo_name": "OVGULIU/TsaiWu-Fortran", "max_issues_repo_head_hexsha": "a111ca1717adfbbaf3e9e34f4189a441e16441b8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "interface_definitions.f90", "max_forks_repo_name": "OVGULIU/TsaiWu-Fortran", "max_forks_repo_head_hexsha": "a111ca1717adfbbaf3e9e34f4189a441e16441b8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 16, "max_forks_repo_forks_event_min_datetime": "2017-02-11T12:56:43.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-01T11:29:18.000Z", "avg_line_length": 23.5060240964, "max_line_length": 81, "alphanum_fraction": 0.6509482317, "num_tokens": 580, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473813156295, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6684742482089326}} {"text": "program ch2301\n ! Order Calculations\n use iso_fortran_env, wp => real64\n implicit none\n\n integer, parameter :: nn = 10\n integer :: n\n integer, dimension(1:nn) :: nvalues = [ 1, 10, &\n 100, 1000, 10000, 100000, 1000000, 10000000, &\n 100000000, 1000000000 ]\n integer :: i\n character(80) :: heading\n\n heading = ' i n O(1) O(n)'\n heading = trim(heading) // &\n ' O(n*n) O(log n) O(n log n)'\n print *, heading\n print *, ' '\n do i = 1, nn\n n = nvalues(i)\n print 100, i, n, order_1(), order_n(n), &\n order_n_squared(n), order_log_n(n), &\n order_n_log_n(n)\n end do\n\n100 format (1x, i2, 2x, i10, 2x, i4, 2x, i10, &\n 2x, e12.4, 2x, f7.2, 2x, e12.4)\ncontains\n integer function order_1()\n order_1 = 1\n end function\n\n integer function order_n(n)\n integer, intent(in) :: n\n\n order_n = n\n end function\n\n real(wp) function order_n_squared(n)\n integer, intent(in) :: n\n\n order_n_squared = dble(n)*dble(n)\n end function\n\n real function order_log_n(n)\n integer, intent(in) :: n\n\n order_log_n = log(real(n))\n end function\n\n real function order_n_log_n(n)\n integer, intent(in) :: n\n\n order_n_log_n = real(n)*log(real(n))\n end function\nend program\n", "meta": {"hexsha": "51d8a942dd2c34e51d208732840f13fb433c79aa", "size": 1348, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ch23/ch2301.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": "ch23/ch2301.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": "ch23/ch2301.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.649122807, "max_line_length": 54, "alphanum_fraction": 0.5519287834, "num_tokens": 435, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473614033683, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6684742422621293}} {"text": " DOUBLE PRECISION FUNCTION DBESY0 (X)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc>> 1996-03-30 DBESY0 Krogh Added external statement.\nC>> 1995-11-13 DBESY0 Krogh Changes to simplify conversion to C.\nC>> 1994-11-11 DBESY0 Krogh Declared all vars.\nC>> 1994-10-20 DBESY0 Krogh Changes to use M77CON\nC>> 1990-11-29 DBESY0 CLL\nC>> 1985-08-02 DBESY0 Lawson Initial code.\nC JULY 1977 EDITION. W. FULLERTON, C3, LOS ALAMOS SCIENTIFIC LAB.\nC C.L.LAWSON & S.CHAN, JPL, 1984 FEB ADAPTED TO JPL MATH77 LIBRARY.\nc ------------------------------------------------------------------\nc--D replaces \"?\": ?BESY0, ?BESJ0, ?BMP0, ?INITS, ?CSEVL, ?ERM1\nc ------------------------------------------------------------------\n EXTERNAL D1MACH, DBESJ0, DCSEVL\n INTEGER NTY0\n DOUBLE PRECISION X, BY0CS(19), AMPL, THETA, TWODPI, XSML,\n 1 Y, D1MACH, DCSEVL, DBESJ0\nC\nC SERIES FOR BY0 ON THE INTERVAL 0. TO 1.60000D+01\nC WITH WEIGHTED ERROR 8.14D-32\nC LOG WEIGHTED ERROR 31.09\nC SIGNIFICANT FIGURES REQUIRED 30.31\nC DECIMAL PLACES REQUIRED 31.73\nC\n SAVE NTY0, XSML\nC\n DATA BY0CS / -.1127783939286557321793980546028D-1,\n * -.1283452375604203460480884531838D+0,\n * -.1043788479979424936581762276618D+0,\n * +.2366274918396969540924159264613D-1,\n * -.2090391647700486239196223950342D-2,\n * +.1039754539390572520999246576381D-3,\n * -.3369747162423972096718775345037D-5,\n * +.7729384267670667158521367216371D-7,\n * -.1324976772664259591443476068964D-8,\n * +.1764823261540452792100389363158D-10,\n * -.1881055071580196200602823012069D-12,\n * +.1641865485366149502792237185749D-14,\n * -.1195659438604606085745991006720D-16,\n * +.7377296297440185842494112426666D-19,\n * -.3906843476710437330740906666666D-21,\n * +.1795503664436157949829120000000D-23,\n * -.7229627125448010478933333333333D-26,\n * +.2571727931635168597333333333333D-28,\n * -.8141268814163694933333333333333D-31 /\nC\n DATA TWODPI / 0.636619772367581343075535053490057D0 /\n DATA NTY0, XSML / 0, 0.D0 /\nC ------------------------------------------------------------------\n IF (NTY0 .eq. 0) then\n call DINITS (BY0CS, 19, 0.1D0*D1MACH(3), NTY0)\n XSML = SQRT (4.0D0*D1MACH(3))\n endif\nC\n IF (X .LE. 0.D0) THEN\n DBESY0 = 0.D0\n CALL DERM1 ('DBESY0',1,0,'X IS ZERO OR NEGATIVE','X',X,'.')\n ELSE IF (X .LE. 4.D0) THEN\n IF (X .LE. XSML) THEN\n Y = 0.D0\n ELSE\n Y = X * X\n END IF\n DBESY0 = TWODPI*LOG(0.5D0*X)*DBESJ0(X) + .375D0 +\n * DCSEVL (.125D0*Y-1.D0, BY0CS, NTY0)\n ELSE\n CALL DBMP0 (X, AMPL, THETA)\n DBESY0 = AMPL * SIN(THETA)\n END IF\nC\n RETURN\nC\n END\n", "meta": {"hexsha": "733638c36b42862b8c5d6593390ad3c5801fce20", "size": 3036, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/dbesy0.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/dbesy0.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/dbesy0.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.9473684211, "max_line_length": 72, "alphanum_fraction": 0.5767457181, "num_tokens": 1119, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473647220786, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6684742308374821}} {"text": " SUBROUTINE PAIR_ENERGY(RSQ,EIJ) \n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!! Calculates the energy between a pair of atoms \n!! Current supports 6 different pair potentials\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n USE header_file\n IMPLICIT NONE\n\n REAL(kind = double) :: EIJ,RSQ \n REAL(kind = double) :: RRR,RR6,RR12 \n REAL(kind = double) :: R,RDIF,RDIF2,RDIF3 \n REAL(kind = double) :: RATIO,FACT1\n REAL(kind = double) :: FACTOR\n\n SELECT CASE (IPOT_TYPE) ! choose option depending on potential type\n\n CASE(1) ! Cut LJ potential\n\n RRR = 1.0D0/RSQ\n RR6 = RRR*RRR*RRR\n RR12 = RR6*RR6\n EIJ = 4.0d0*EPS*(RR12 - RR6) \n\n CASE(2) ! Splined-LJ potential\n\n IF(RSQ.LE.RCUT_INNER_SQ) THEN\n RRR = 1.0D0/RSQ\n RR6 = RRR*RRR*RRR\n RR12 = RR6*RR6\n EIJ = 4.0d0*EPS*(RR12 - RR6)\n ELSE\n R = SQRT(RSQ)\n RDIF = R - RCUT\n RDIF2 = RDIF*RDIF\n RDIF3 = RDIF2*RDIF\n EIJ = SPLINE_R2*RDIF2 + SPLINE_R3*RDIF3\n END IF\n\n CASE(3) ! Smooth repulsive potential\n\n RATIO = RSQ/CUTSQ\n EIJ = EPS*(1.0D0 - RATIO)**4\n\n CASE(4) ! m-n family of potentials\n\n FACTOR = 2.0D0 - RSQ\n EIJ = (M_RATIO*FACTOR**N_POWER - N_RATIO*FACTOR**M_POWER)\n\n CASE(5) ! Lucy potential\n\n R = SQRT(RSQ)\n RATIO = R/RCUT\n FACT1 = (1.0D0 - RATIO)\n EIJ = EFACT_LUCY*FACT1**3*(1.0D0 + 3.0D0*RATIO)\n\n CASE(6) ! Soft disk potential\n\n EIJ = 1.0D0/(RSQ**SOFT_N)\n\n CASE(7) ! WCA potential\n\n RRR = 1.0D0/RSQ\n RR6 = RRR*RRR*RRR\n RR12 = RR6*RR6\n EIJ = 4.0d0*(RR12 - RR6) + 1.0d0 \n\n END SELECT\n \n\n END SUBROUTINE\n", "meta": {"hexsha": "8087c9cdc78c76a84c99e975e20c9b36c00d714f", "size": 1866, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "synthetic_NEMD/src/src_3dsllod/pair_energy.f90", "max_stars_repo_name": "niallj/ImperialNESS-Sep14", "max_stars_repo_head_hexsha": "0cd309273cdb89f8055c2aa51422584e2284ca94", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "synthetic_NEMD/src/src_3dsllod/pair_energy.f90", "max_issues_repo_name": "niallj/ImperialNESS-Sep14", "max_issues_repo_head_hexsha": "0cd309273cdb89f8055c2aa51422584e2284ca94", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "synthetic_NEMD/src/src_3dsllod/pair_energy.f90", "max_forks_repo_name": "niallj/ImperialNESS-Sep14", "max_forks_repo_head_hexsha": "0cd309273cdb89f8055c2aa51422584e2284ca94", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.9166666667, "max_line_length": 73, "alphanum_fraction": 0.4812433012, "num_tokens": 641, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813551535005, "lm_q2_score": 0.6992544273261175, "lm_q1q2_score": 0.6684741950323068}} {"text": "program test\n\n ! Import dependencies\n use lapack, only : dgetrf\n use linear_algebra \n use direct_linear_solve, only : dlufactor, dluppfactor\n \n implicit none\n\n integer, parameter :: sizes(6) = [200, 400, 800, 1000, 2000, 4000]\n integer :: i, npts\n\n ! Run for all problem sizes\n do i = 1, size(sizes)\n\n npts = sizes(i)\n\n call gesolve(npts)\n call geppsolve(npts)\n !call exact(npts)\n\n end do\n\n! call time_report(.false.)\n! call time_report(.true.)\n\ncontains\n\n subroutine geppsolve(npts)\n\n ! Problem setup\n integer, intent(in) :: npts\n\n ! Matrices and vectors\n real(8), allocatable, dimension(:,:) :: A, L, U, P\n real(8), allocatable, dimension(:) :: x, xtmp, b, y\n\n ! Physics parameters\n real(8), parameter :: lambdas(2) = [0.0d0, 10.0d0]\n real(8) :: lambda\n integer :: flag, i, k\n \n ! Filename\n character(len=50) :: filename\n character(len=50) :: strlambda, strnpts\n\n ! Run for each lambda\n do k = 1, size(lambdas)\n\n lambda = lambdas(k)\n\n ! Create filename and open\n write(strlambda,*) int(lambda)\n write(strnpts,*) int(npts)\n filename = 'gepp-solution-lam-'// trim(adjustl(strlambda)) &\n & //\"-npts-\" // trim(adjustl(strnpts)) //'.dat'\n open(11,file=filename)\n write(11,*) \"x \", \"u\"\n\n ! Allocate matrices\n allocate(A(npts, npts))\n allocate(L, U, P, source = A)\n A = 0.0d0\n L = 0.0d0\n U = 0.0d0\n P = 0.0d0\n\n ! Allocate vectors\n allocate(x(npts))\n allocate(xtmp, b, y, source = x)\n x = 0.0d0\n xtmp = 0.0d0 \n b = 0.0d0\n\n ! Solve x\n call assemble_system(0.0d0, 1.0d0, npts, A, b, x, lambda)\n call dluppfactor(A, L, U, P, flag)\n b = matmul(P,b)\n call fwdsub(L, b, y, flag)\n call backsub(U, y, x, flag)\n\n ! Write output\n do i = 1, npts\n write(11, *) dble(i)/dble(npts), x(i)\n end do\n\n close(11)\n\n deallocate(A,L,U,P,x,xtmp,b,y)\n\n end do\n\n end subroutine geppsolve\n\n pure real(8) function uhat(x, lambda)\n\n real(8), intent(in) :: x\n real(8), intent(in) :: lambda\n\n real(8) :: alpha\n\n alpha = sqrt(lambda)\n uhat = 2.d0*exp(-alpha*x)*(exp(2.d0*alpha)-exp(2.d0*alpha*x))/(exp(2.d0*alpha)-1.d0)\n\n end function uhat\n\n subroutine gesolve(npts)\n\n ! Problem setup\n integer, intent(in) :: npts\n\n ! Matrices and vectors\n real(8), allocatable, dimension(:,:) :: A, L, U, P\n real(8), allocatable, dimension(:) :: x, xtmp, b, y\n\n ! Physics parameters\n real(8), parameter :: lambdas(2) = [0.0d0, 10.0d0]\n real(8) :: lambda\n integer :: flag, i, k\n \n ! Filename\n character(len=50) :: filename\n character(len=50) :: strlambda, strnpts\n\n ! Run for each lambda\n do k = 1, size(lambdas)\n\n lambda = lambdas(k)\n\n ! Create filename and open\n write(strlambda,*) int(lambda)\n write(strnpts,*) int(npts)\n filename = 'ge-solution-lam-'// trim(adjustl(strlambda)) &\n & //\"-npts-\" // trim(adjustl(strnpts)) //'.dat'\n open(11,file=filename)\n write(11,*) \"x \", \"u\"\n\n ! Allocate matrices\n allocate(A(npts, npts))\n allocate(L, U, P, source = A)\n A = 0.0d0\n L = 0.0d0\n U = 0.0d0\n P = 0.0d0\n\n ! Allocate vectors\n allocate(x(npts))\n allocate(xtmp, b, y, source = x)\n x = 0.0d0\n xtmp = 0.0d0 \n b = 0.0d0\n\n ! Solve x\n call assemble_system(0.0d0, 1.0d0, npts, A, b, x, lambda)\n call dlufactor(A, L, U, flag)\n call fwdsub(L, b, y, flag)\n call backsub(U, y, x, flag)\n\n ! Write output\n do i = 1, npts\n write(11, *) dble(i)/dble(npts), x(i)\n end do\n\n close(11)\n\n deallocate(A,L,U,P,x,xtmp,b,y)\n\n end do\n\n end subroutine gesolve\n\n subroutine time_report(pivot)\n\n ! Problem setup\n integer :: npts\n logical :: pivot\n\n ! Matrices and vectors\n real(8), allocatable, dimension(:,:) :: A, L, U, P\n real(8), allocatable, dimension(:) :: x, xtmp, b, y\n\n ! Timing variables\n real(8) :: total_start, total_finish, total_time\n real(8) :: assembly_start, assembly_finish, assembly_time\n real(8) :: factor_start, factor_finish, factor_time\n real(8) :: elim_start, elim_finish, elim_time\n\n integer, parameter :: sizes(6) = [200, 400, 800, 1000, 2000, 4000]\n real(8), parameter :: lambdas(2) = [0.0d0, 10.0d0]\n real(8) :: lambda\n integer :: flag, i, k\n\n ! Run for each lambda\n do k = 1, size(lambdas)\n\n lambda = lambdas(k)\n\n ! Write the time for each linear solve \n if (pivot .eqv. .false.) then\n if (k .eq. 1) then \n open(11, file='time_study_ge_lam0.dat')\n else\n open(11, file='time_study_ge_lam10.dat')\n end if\n else \n if (k .eq. 1) then \n open(11, file='time_study_gepp_lam0.dat')\n else\n open(11, file='time_study_gepp_lam10.dat')\n end if\n end if\n write(11, *) \"size \", \"factor_time \", \"elim_time \", \"total_time\"\n\n ! Run for all problem sizes\n do i = 1, size(sizes)\n\n npts = sizes(i)\n\n ! Allocate matrices\n allocate(A(npts, npts))\n allocate(L, U, P, source = A)\n A = 0.0d0\n L = 0.0d0\n U = 0.0d0\n P = 0.0d0\n\n ! Allocate vectors\n allocate(x(npts))\n allocate(xtmp, b, y, source = x)\n x = 0.0d0\n xtmp = 0.0d0 \n b = 0.0d0\n\n call cpu_time(total_start)\n\n ! Assemble linear system\n call cpu_time(assembly_start)\n call assemble_system(0.0d0, 1.0d0, npts, A, b, x, lambda)\n call cpu_time(assembly_finish)\n assembly_time = assembly_finish-assembly_start\n print *, \"assembled system in \", assembly_time\n\n call cpu_time(factor_start)\n if (pivot .eqv. .false.) then\n ! Ax = b is now LUx = b\n call dlufactor(A, L, U, flag)\n else\n call dluppfactor(A, L, U, P, flag)\n b = matmul(P,b)\n end if\n call cpu_time(factor_finish)\n factor_time = factor_finish-factor_start\n print *, \"factorized matrix in \", factor_time\n\n call cpu_time(elim_start)\n\n ! Solve Ly = b\n call fwdsub(L, b, y, flag)\n\n ! Solve Ux = y\n call backsub(U, y, x, flag)\n\n call cpu_time(elim_finish)\n elim_time = elim_finish-elim_start\n print *, \"elimination completed in \", elim_time\n\n call cpu_time(total_finish)\n total_time = total_finish - total_start \n print '(\"Time = \",f6.3,\" seconds.\")', total_time\n\n ! Write output data\n write(11, *) npts, factor_time, elim_time, total_time\n\n deallocate(A,L,U,P,x,xtmp,b,y)\n\n end do\n\n close(11)\n\n end do\n\n end subroutine time_report\n\n ! Model problem to solve\n subroutine assemble_system(a, b, npts, V, rhs, u, lambda, homogenous)\n\n use linear_algebra, only : inv\n\n real(8), intent(in) :: a, b ! bound of domain\n integer :: npts ! number of points\n real(8), intent(out) :: V(npts,npts)\n real(8), intent(out) :: rhs(npts)\n real(8), intent(out) :: u(npts)\n real(8) :: h\n real(8), intent(in) :: lambda\n real(8), parameter :: PI = 3.141592653589793d0\n integer :: m, n, i, j\n logical, intent(in), optional :: homogenous\n\n h = (b-a)/dble(npts+1)\n V = 0.0d0\n\n m = npts\n n = npts\n do i = 1, m\n do j = 1, n\n if (i .eq. j-1) then\n V(i,j) = -1.0d0\n else if (i .eq. j+1) then \n V(i,j) = -1.0d0\n else if (i .eq. j) then \n V(i,i) = 2.0d0 + lambda*h*h\n else\n ! skip zeros\n end if\n end do\n end do\n\n if(present(homogenous)) then\n ! Assemble the RHS\n rhs = 0.0d0\n rhs(1) = 2.0d0\n rhs(npts) = 0.0d0\n else\n ! Assemble the RHS\n rhs = 0.0d0\n rhs(1) = 2.0d0 + h*h*(3.0d0*(dble(i)*h)**2.0d0 - 0.5d0)\n rhs(npts) = 0.0d0 + h*h*(3.0d0*(dble(npts)*h)**2.0d0 - 0.5d0)\n end if\n\n\n ! Initial solution profile (straight line)\n do i = 1, npts\n u(i) = 2.0d0 + ((0.0d0+2.0d0)/(b-a))*(dble(i)*h)\n end do\n\n end subroutine assemble_system\n\nend program test\n", "meta": {"hexsha": "436f65a637a110c47e664430700aeeccdec06312", "size": 8466, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/lu-lupp/solve.f90", "max_stars_repo_name": "komahanb/math6644-iterative-methods", "max_stars_repo_head_hexsha": "59dfd0fd8bbcb16d5f5b6d96d2565f87541803c9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-03-19T16:36:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-14T21:29:38.000Z", "max_issues_repo_path": "test/lu-lupp/solve.f90", "max_issues_repo_name": "komahanb/math6644-iterative-methods", "max_issues_repo_head_hexsha": "59dfd0fd8bbcb16d5f5b6d96d2565f87541803c9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/lu-lupp/solve.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": 24.9, "max_line_length": 89, "alphanum_fraction": 0.5323647531, "num_tokens": 2758, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936437, "lm_q2_score": 0.8175744673038222, "lm_q1q2_score": 0.6684280168552197}} {"text": "!############################################################################################\n!\n! Copyright 2021 Bharat Mahajan\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 implied.\n! See the License for the specific language governing permissions and\n! limitations under the License.\n!\n!> \\brief Lorenz Test Main Program\n!! \\details Main program to run Lorenz test.\n!! \\author Bharat Mahajan\n!! \\date 09/17/2021 \n!\n!############################################################################################ \n\n\nmodule LorenzDiffEq\n\n use FLINT\n\n use, intrinsic :: IEEE_ARITHMETIC\n\n implicit none\n \n ! user diff eq system\n\n type, extends(DiffEqSys) :: LorenzSys\n real(WP) :: sigma = 10.0_WP\n real(WP) :: rho = 28.0_WP\n real(WP) :: beta = 8.0_WP/3.0_WP\n contains\n procedure :: F => LorenzDE\n end type LorenzSys\n \n contains\n \n function LorenzDE(me, X, Y, Params) \n intrinsic :: size \n class(LorenzSys), intent(inout) :: me !< Differential Equation object\n real(WP), intent(in) :: X\n real(WP), intent(in), dimension(me%n) :: Y\n real(WP), intent(in), dimension(:), optional :: Params\n \n real(WP), dimension(size(Y)) :: LorenzDE\n\n LorenzDE(1) = me%sigma*(Y(2) - Y(1))\n LorenzDE(2) = Y(1)*(me%rho - Y(3)) - Y(2)\n LorenzDE(3) = Y(1)*Y(2) - me%beta*Y(3)\n end function LorenzDE\n \nend module LorenzDiffEq\n\n\n\n\n program LorenzTest\n \n use iso_fortran_env, only: output_unit\n use FLINT\n use LorenzDiffEq\n \n implicit none\n\n ! Simulation Parameters\n \n ! Number of periodic orbits to run and loops for benchmark\n integer, parameter :: nloops = 100\n integer, parameter :: floops = 100000000\n \n ! solvers to run from 1 to 4\n integer, parameter :: nmethod = 4\n \n ! scalar tolerance\n real(WP), parameter :: rtol = 1.0e-11_WP \n real(WP), parameter :: atol = rtol*1.0e-3_WP \n \n ! max no. of steps\n integer, parameter :: MAX_STEPS = 100000\n logical, parameter :: CONST_STEPSZ = .FALSE.\n \n ! random dispersion of IC: this multiplies the random number\n real(WP), parameter :: randon = 0.000000000000_WP\n\n ! Interpolation points\n integer, parameter :: nIp = int(1000.0)\n \n ! results file\n character(len=20) :: fname = 'results_Lorenz.txt'\n character(len=20) :: spfname = 'states_ip_Lorenz.txt'\n\n type(ERK_class) :: erkvar\n type(LorenzSys) :: LorenzObj\n \n real(WP) :: x0, xf, xfval, rnum\n real(WP), dimension(3) :: y0, yf, y0r\n \n character(len=:), allocatable :: errstr\n\n real(WP) :: stepsz0, ipdx, stepsz\n real(WP), dimension(:), allocatable, target :: Xint, Xarr\n real(WP), dimension(:,:), allocatable, target :: Yint, Yarr\n integer :: stiffstatus, stifftestval\n integer :: nsteps, naccpt, nrejct, fcalls, steps, itr, nevents, ctr\n character(len=10) :: mname\n integer :: method\n \n real(WP) :: T0, Tf\n\n real(WP), dimension(3), parameter :: params = [10.0_WP, 28.0_WP, 8.0_WP/3.0_WP]\n\n\n y0 = [1.0_WP, 0.0_WP, 0.0_WP]\n\n x0 = 0.0_WP\n xF = 100.0_WP\n \n LorenzObj%n = 3\n LorenzObj%m = 0\n ! LorenzObj%G => SampleEvent\n \n stepsz0 = 0.0E-2_WP ! let FLINT compute the initial step-size \n stifftestval = 1*0 ! check for stiffness and stop integration if stiff\n\n ! arrays for interpolated data\n ipdx = (xf-x0)/(nIp-1)\n Xarr = [(x0+ipdx*itr,itr=0,(nIp-1))]\n Xarr(nIp) = xf\n allocate(Yarr(3,size(Xarr)))\n \n ! create results file\n open(unit=17,file= fname, status = 'replace')\n write(17, *) '--- FLINT Stats ---'\n write(17, *) ' '\n write(17, *) 'A. Internal Step-size'\n write(17, '(6A12)') 'Method', 'Time(s)', 'FCalls', 'Accepted', 'Rejected', 'Total Steps'\n\n ! states using interpolation\n open(unit=19,file= spfname, status = 'replace')\n write(19, '(4A12)') 'X','Y1','Y2','Y3'\n\n ! Solution at internal step size\n\n\n do itr = 1, nmethod\n \n select case (itr)\n case (1)\n mname = 'DOP54'\n method = ERK_DOP54\n case (2)\n mname = 'DOP853'\n method = ERK_DOP853\n case (3)\n mname = 'Verner65E'\n method = ERK_Verner65E\n case (4)\n mname = 'Verner98R'\n method = ERK_Verner98R\n end select \n \n call erkvar%Init(LorenzObj, MAX_STEPS, Method=method, ATol=[atol], RTol=[rtol],&\n InterpOn=.FALSE.)\n if (erkvar%status == FLINT_SUCCESS) then\n\n y0r = y0\n call CPU_TIME(t0)\n do ctr = 1,nloops\n stiffstatus = stifftestval\n stepsz = stepsz0\n xfval = xf\n call RANDOM_NUMBER(rnum) ! randomize initial condition\n y0r(1) = y0r(1) + rnum*randon*y0r(1)\n\n call erkvar%Integrate(x0, y0r, xfval, yf, StepSz=stepsz, UseConstStepSz=CONST_STEPSZ, &\n IntStepsOn=.FALSE.,StiffTest=stiffstatus)\n end do\n call CPU_TIME(tf)\n \n if (stiffstatus == -1) write(17, *) mname//': problem is stiff'\n \n if (erkvar%status == FLINT_SUCCESS .OR. erkvar%status == FLINT_EVENT_TERM &\n .OR. erkvar%status == FLINT_ERROR_MAXSTEPS) then \n call erkvar%Info(stiffstatus, errstr, nAccept=naccpt, nReject=nrejct, nFCalls=fcalls, nSteps = steps)\n \n write(17, '(A12,1F12.3,4I12.1)') mname, (tf-t0), fcalls, naccpt, nrejct, steps\n else\n call erkvar%Info(stiffstatus, errstr)\n write(17,*) mname//': Integrate failed: ', erkvar%status, ':', errstr\n end if\n \n ! ! write states\n ! if (itr == 2) then\n ! do ctr = 1, size(Xint)\n ! write(18, '(7E18.9)') Xint(ctr), Yint(1:3,ctr)\n ! end do \n ! end if\n \n if (allocated(Xint)) deallocate(Xint)\n if (allocated(Yint)) deallocate(Yint)\n else\n write(17,*) mname//': Init failed: ', erkvar%status \n end if\n end do\n \n ! Solution at interpolated grid\n write(17, *) 'B. Interpolated Grid'\n write(17, '(6A12)') 'Method', 'Time(s)', 'FCalls', 'Accepted', 'Rejected', 'Total Steps'\n \n do itr = 1, nmethod\n \n select case (itr)\n case (1)\n mname = 'DOP54'\n method = ERK_DOP54\n case (2)\n mname = 'DOP853'\n method = ERK_DOP853\n case (3)\n mname = 'Verner65E'\n method = ERK_Verner65E\n case (4)\n mname = 'Verner98R'\n method = ERK_Verner98R\n end select \n \n call erkvar%Init(LorenzObj, MAX_STEPS, Method=method, ATol=[atol], RTol=[rtol],&\n InterpOn=.TRUE.)\n \n if (erkvar%status == FLINT_SUCCESS) then\n \n y0r = y0\n call CPU_TIME(t0)\n do ctr = 1,nloops\n stiffstatus = stifftestval\n stepsz = stepsz0\n xfval = xf\n call RANDOM_NUMBER(rnum) ! randomize initial condition\n y0r(1) = y0r(1) + rnum*randon*y0r(1) \n call erkvar%Integrate(x0, y0r, xfval, yf, StepSz=stepsz, UseConstStepSz=CONST_STEPSZ, &\n StiffTest=stiffstatus, params=params)\n end do\n call CPU_TIME(tf) \n call erkvar%Interpolate(Xarr,Yarr,.TRUE.) \n \n if (stiffstatus == -1) write(17, *) mname//': problem is stiff'\n \n if (erkvar%status == FLINT_SUCCESS .OR. erkvar%status == FLINT_EVENT_TERM &\n .OR. erkvar%status == FLINT_ERROR_MAXSTEPS) then \n call erkvar%Info(stiffstatus, errstr, nAccept=naccpt, nReject=nrejct, nFCalls=fcalls, nSteps=steps)\n \n write(17, '(A12,1F12.3,4I12.1)') mname, (tf-t0), fcalls, naccpt, nrejct, steps\n \n else\n call erkvar%Info(stiffstatus, errstr)\n write(17,*) mname//': Integrate failed: ', erkvar%status, ':',errstr\n end if\n \n \n ! write states\n if (itr == 2) then\n do ctr = 1, size(Xarr)\n write(19, '(7E18.9)') Xarr(ctr), Yarr(1:3,ctr)\n end do \n end if \n \n else\n write(17,*) mname//': Init failed: ', erkvar%status \n end if\n end do\n \n \n ! function test\n y0r = y0*0.0_WP\n call CPU_TIME(t0)\n do ctr = 1,floops\n !y0 = y0 + 0.0001_WP*y0\n yf = LorenzObj%F(x0, y0, params)\n y0r = y0r + yf\n end do\n call CPU_TIME(tf)\n write(17, *) ' ' \n write(17, '(I12,A13,F12.2,A5)') floops, ' Func calls: ', (tf-t0)*1.0e3_WP, ' ms' \n \n \n contains\n\n \n\n\n end program LorenzTest\n\n", "meta": {"hexsha": "6f204cda1817946e8da734982b7fcb30293b18eb", "size": 9458, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/test_Lorenz.f90", "max_stars_repo_name": "princemahajan/FLINT", "max_stars_repo_head_hexsha": "5c5b5f6d8b43f4ec1a6c83990f399b5382981ee9", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2019-06-17T16:22:18.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-20T19:40:23.000Z", "max_issues_repo_path": "tests/test_Lorenz.f90", "max_issues_repo_name": "princemahajan/FLINT", "max_issues_repo_head_hexsha": "5c5b5f6d8b43f4ec1a6c83990f399b5382981ee9", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2019-06-18T03:31:38.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-12T01:13:39.000Z", "max_forks_repo_path": "tests/test_Lorenz.f90", "max_forks_repo_name": "princemahajan/FLINT", "max_forks_repo_head_hexsha": "5c5b5f6d8b43f4ec1a6c83990f399b5382981ee9", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2020-12-01T19:41:05.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-28T08:37:33.000Z", "avg_line_length": 31.5266666667, "max_line_length": 117, "alphanum_fraction": 0.527384225, "num_tokens": 2757, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324803738429, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.668403679672637}} {"text": "!! CANTIDADES DERIVADAS DE LOS PARAMETROS DEL PROGRAMA !!\n\nsubroutine initial\n\n use arrays\n use global\n\n implicit none\n\n !cantidades derivadas de la metrica de Schwar\n alpha = 1.0d0/sqrt(1.0d0 + 2.0d0/x)\n dalpha = 1.0d0/(x**2*(1.0d0 + 2.0d0/x)**(3.0d0/2.0d0))\n beta = 2.0d0/(x*(1.0d0 + 2.0d0/x))\n dbeta = -2.0d0/(2.0d0 + x)**2.0d0 \n gamma = sqrt(x**4*(1.0d0 + 2.0d0/x))\n dgamma = (x**2*(3.0d0 + 2.0d0*x))/sqrt(x**3*(2.0d0 + x))\n gamma_rr = 1.0d0 + 2.0d0/x \n dgamma_rr = -2.0d0/x**2\n\n !campos \n Phi = amplitude*exp(-(x-x0)**2/sigma**2)\n Psi = -2.0d0*Phi*((x-x0)/sigma**2)\n Pi = 0.0d0\n\n call constriction_calc !resolvemos las ecs. de ligadura\n\nend subroutine initial", "meta": {"hexsha": "2f624f8a2768af4287c71f00ac8b0492404271a8", "size": 782, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gravitational-wave/initial.f90", "max_stars_repo_name": "valler94/numericalRelativity", "max_stars_repo_head_hexsha": "18845d7d57b7fa8a6c9e394d55bd172283e88716", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-12-15T14:50:49.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-15T14:50:49.000Z", "max_issues_repo_path": "gravitational-wave/initial.f90", "max_issues_repo_name": "valler94/numericalRelativity", "max_issues_repo_head_hexsha": "18845d7d57b7fa8a6c9e394d55bd172283e88716", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gravitational-wave/initial.f90", "max_forks_repo_name": "valler94/numericalRelativity", "max_forks_repo_head_hexsha": "18845d7d57b7fa8a6c9e394d55bd172283e88716", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-12-08T17:10:13.000Z", "max_forks_repo_forks_event_max_datetime": "2018-12-08T17:10:13.000Z", "avg_line_length": 28.962962963, "max_line_length": 65, "alphanum_fraction": 0.537084399, "num_tokens": 343, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9603611608990299, "lm_q2_score": 0.6959583124210896, "lm_q1q2_score": 0.6683713328540474}} {"text": "! .................................................\r\n! ____ _ _ ____ _____ _ \r\n! | _ \\| | |_| | _ \\| ___| |_| \r\n! | |_) | |___ _ | |_) | |___ _ \r\n! | _ /| _ | | | | _ /|___ | | | \r\n! | | | | | | | | | | ___| | | | \r\n! |_| |_| |_| |_| |_| |_____| |_| \r\n! .................................................\r\n! PhiPsi: a general-purpose computational \r\n! mechanics program written in Fortran.\r\n! Website: http://phipsi.top \r\n! Author: Shi Fang from Huaiyin Institute of \r\n! Technology, HuaiAn, JiangSu, China \r\n! Contact me: shifang@hyit.edu.cn \r\n! ------------------------------------------------ \r\n! Please cite the following papers: \r\n! (1)Shi F, Wang X L, Liu C, Liu H, Wu H A. An \r\n! XFEM-based method with reduction technique \r\n! for modeling hydraulic fracture propagation \r\n! in formations containing frictional natural \r\n! fractures. Engineering Fracture Mechanics, \r\n! 2017, 173: 64-90. \r\n! (2)Shi F, Wang X L, Liu C, Liu H, Wu H A. A \r\n! coupled extended finite element approach \r\n! for modeling hydraulic fracturing in \r\n! consideration of proppant. Journal of \r\n! Natural Gas Science and Engineering, 2016, \r\n! 33: 885-897. \r\n! (3)Shi F, Wang X L, Liu C, Liu H, Wu H A. An \r\n! XFEM-based numerical model to calculate \r\n! conductivity of propped fracture considering \r\n! proppant transport, embedment and crushing. \r\n! Journal of Petroleum Science and Engineering, \r\n! 2018, 167: 615-626.. \r\n \r\n subroutine Tool_Area_Polygon(x,y,nb,area)\r\n\t !get area of a polygon\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\n IMPLICIT NONE\r\n integer nb\r\n double precision x(nb)\r\n double precision y(nb)\r\n INTEGER i, n, nm1\r\n double precision a,area\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\n\r\n n = nb\r\n IF ((x(1) .eq. x(n)) .AND. (y(1) .eq. y(n))) n = n - 1\r\n\r\n SELECT CASE (n)\r\n CASE (:2)\r\n area = 0.0D0\r\n\r\n CASE (3)\r\n area=0.5D0*((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\r\n DO i = 2, nm1\r\n a = a + x(i)*(y(i+1) - y(i-1))\r\n END DO\r\n \r\n area = 0.5D0*a\r\n END SELECT\r\n\r\n RETURN\r\n END subroutine Tool_Area_Polygon\r\n ", "meta": {"hexsha": "b34ffc51682c6f5350e0c4ebe3ec05c20c0f113c", "size": 3404, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Tool_Area_Polygon.f", "max_stars_repo_name": "PhiPsi-Software/PhiPsi_XFEM_Fortran_Codes_Early_Version", "max_stars_repo_head_hexsha": "1eae63a8f0dc968b9d5220397879645a83e5d083", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-04-15T11:56:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-14T11:49:59.000Z", "max_issues_repo_path": "Tool_Area_Polygon.f", "max_issues_repo_name": "PhiPsi-Software/PhiPsi_XFEM_Fortran_Codes_Early_Version", "max_issues_repo_head_hexsha": "1eae63a8f0dc968b9d5220397879645a83e5d083", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Tool_Area_Polygon.f", "max_forks_repo_name": "PhiPsi-Software/PhiPsi_XFEM_Fortran_Codes_Early_Version", "max_forks_repo_head_hexsha": "1eae63a8f0dc968b9d5220397879645a83e5d083", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2019-01-20T00:55:09.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T00:30:28.000Z", "avg_line_length": 40.5238095238, "max_line_length": 85, "alphanum_fraction": 0.4306698002, "num_tokens": 891, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853655, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6683577971170219}} {"text": "!-----------------------------------------------------------------------\n program test\n implicit none\n include 'ceed/fortran.h'\n\n integer ceed,err,i,j,kk\n real*8 a(16), q(16), qlambdaqt(16), lambda(4), sum\n\n character arg*32\n\n a = (/ 0.2, 0.0745355993, -0.0745355993, 0.0333333333,&\n & 0.0745355993, 1., 0.1666666667, -0.0745355993,&\n & -0.0745355993, 0.1666666667, 1., 0.0745355993,&\n & 0.0333333333, -0.0745355993, 0.0745355993, 0.2 /)\n\n call getarg(1,arg)\n\n call ceedinit(trim(arg)//char(0),ceed,err)\n\n do i=0,3\n do j=1,4\n q(4*i+j)=a(4*i+j)\n enddo\n enddo\n\n call ceedsymmetricschurdecomposition(ceed,q,lambda,4,err)\n\n! Check A = Q lambda Q^T\n do i=0,3\n do j=0,3\n sum = 0\n do kk=0,3\n sum=sum+q(kk+i*4+1)*lambda(kk+1)*q(kk+j*4+1)\n enddo\n qlambdaqt(j+i*4+1)=sum\n enddo\n enddo\n do i=0,3\n do j=1,4\n if (abs(a(i*4+j) - qlambdaqt(i*4+j))>1.0D-14) then\n! LCOV_EXCL_START\n write(*,'(A,I1,A,I1,A,F12.8,A,F12.8)') 'Error: [', &\n & i,',',j-1,'] ',a(i*4+j),'!=',qlambdaqt(i*4+j)\n! LCOV_EXCL_STOP\n endif\n enddo\n enddo\n\n call ceeddestroy(ceed,err)\n\n end\n!-----------------------------------------------------------------------\n", "meta": {"hexsha": "76dab4fc588df233263558d0e2b314b91c0e66e1", "size": 1367, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/t304-basis-f.f90", "max_stars_repo_name": "AdelekeBankole/libCEED", "max_stars_repo_head_hexsha": "aae8ce39fa1e28b745979a9cbffc67a790eb3f5e", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 123, "max_stars_repo_stars_event_min_datetime": "2018-01-29T02:04:05.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T18:13:48.000Z", "max_issues_repo_path": "tests/t304-basis-f.f90", "max_issues_repo_name": "AdelekeBankole/libCEED", "max_issues_repo_head_hexsha": "aae8ce39fa1e28b745979a9cbffc67a790eb3f5e", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 781, "max_issues_repo_issues_event_min_datetime": "2017-12-22T17:20:35.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T21:34:34.000Z", "max_forks_repo_path": "tests/t304-basis-f.f90", "max_forks_repo_name": "AdelekeBankole/libCEED", "max_forks_repo_head_hexsha": "aae8ce39fa1e28b745979a9cbffc67a790eb3f5e", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 41, "max_forks_repo_forks_event_min_datetime": "2017-12-27T22:35:13.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-01T13:02:07.000Z", "avg_line_length": 25.7924528302, "max_line_length": 72, "alphanum_fraction": 0.4498902707, "num_tokens": 506, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587964389112, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6683577949012511}} {"text": "program complex2\ncomplex :: x\nx = (3.0, 4.0)\nx = x * 4.0\nprint *, x\nx = 2 * x\nprint *, x\nx = (x * (0.0, 3.0))\nprint *, x\nend program\n", "meta": {"hexsha": "1b776e9044f39fa6d65bde0dd6e7b5cddccc564d", "size": 133, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "integration_tests/complex_mul_test.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/complex_mul_test.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/complex_mul_test.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": 12.0909090909, "max_line_length": 20, "alphanum_fraction": 0.5187969925, "num_tokens": 66, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.888758793492457, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6683577926854806}} {"text": " function func(x)\r\n func=4.*x+5.\r\n end\r\n \r\n program ejercicio 9\r\n\r\n implicit none\r\n\r\n external func\r\n integer::N,i,f\r\n real::func,aa,bb,cc,Ym,Xm\r\n real,allocatable,dimension(:)::A,B,C,D, Dif\r\n\r\n open(20, FILE='ejercicio9.dat', STATUS='UNKNOWN')\r\n\r\n ! genero N numeros random entre 0 y 1 y los guardo en un vector A\r\n \r\n call error (A,N)\r\n \r\n ! genero Xn numeros en el intervalo(a,b) y los guardo en un vector B\r\n\r\n call inter(B,N)\r\n \r\n ! evaluo los numeros en el intervalo para obtener el valor de la\r\n ! funcion desplazada un numero random entre 0 y 1 en la funcion\r\n ! guardo los valores de Y en un vector llamado C\r\n \r\n\r\n \r\n allocate(C(N))\r\n \r\n do i=1,N\r\n\r\n C(i) = func(B(i)) + A(i)\r\n \r\n end do\r\n \r\n ! ajuste de puntos.\r\n\r\n\r\n ! obtengo mis valores medios\r\n \r\n do i= 1,N\r\n \r\n Xm= B(i)+ Xm\r\n Ym= C(i)+ Ym\r\n\r\n end do\r\n\r\n \r\n Ym=Ym/N\r\n Xm=Xm/N\r\n\r\n\r\n ! calculo el valor de la pendiente y de la ordenada\r\n\r\n cc=0\r\n aa=0\r\n bb=0\r\n \r\n do i = 1,N\r\n \r\n cc=B(i)*B(i)+cc\r\n\r\n aa=B(i)*C(i)+aa\r\n\r\n !si no pongo esto da todo mal\r\n \r\n end do\r\n\r\n aa=(aa-Xm*Ym*N)/(cc-Xm*Xm*N)\r\n bb=Ym-aa*Xm\r\n\r\n ! esta tmb es necesaria\r\n \r\n ! obtengo los puntos de la recta de ajuste y los guardo en un vector llamado D\r\n \r\n allocate(D(N))\r\n \r\n\r\n do i = 1,N\r\n D(i)=aa*(B(i))+bb\r\n\r\n end do\r\n\r\n \r\n ! comparacion de esos valores con los de al funcion\r\n \r\n allocate(Dif(N))\r\n\r\n do i = 1,N\r\n\r\n Dif(i) = C(i)-D(i)\r\n\r\n end do\r\n \r\n ! --------------------------------------------------------------\r\n write(20,*) \"i Xe Ye Ya Ye-Ya\"\r\n\r\n do i = 1,N\r\n \r\n write(20,*) i,B(i),C(i),D(i),Dif(i)\r\n\r\n end do\r\n write(20,*)' '\r\n write(20,*) \"LA RECTA AJUSTADA ES:\",' Y =',aa,'* X +',bb\r\n write(20,*)' '\r\n\r\n pause\r\n deallocate(A,B,C,D,Dif)\r\n \r\n close(20)\r\n \r\n! ----------------------------------------------------------------\r\n ! subrutinas\r\n! ----------------------------------------------------------------\r\n\r\n contains\r\n\r\n! ----------------------------------------------------------------\r\n\r\n subroutine error(A,N)\r\n\r\n implicit none\r\n INTEGER i, N\r\n real,allocatable,dimension(:)::A\r\n\r\n write(*,*) 'introduzca el numero de puntos que desea'\r\n read(*,*) N\r\n\r\n allocate(A(N))\r\n do i = 1, N\r\n A(i) = ran()\r\n end do\r\n end subroutine\r\n\r\n! ----------------------------------------------------------------\r\n\r\n subroutine inter(B,N)\r\n \r\n real,allocatable,dimension(:)::B\r\n real::k,f\r\n integer:: N\r\n write(*,*) 'introduzca el numero menor del intervalo'\r\n read(*,*) k\r\n write(*,*) 'introduzca el numero mayor del intervalo'\r\n read(*,*) f\r\n\r\n ! presentacion de los datos\r\n \r\n write(20,*) ' '\r\n write(20,*) 'Notacion:'\r\n write(20,*) ' '\r\n write(20,*) \" Ye,Xe = valor de Y/X experimental\"\r\n write(20,*) \" Ya = valor de Y ajustado\"\r\n write(20,*) ' '\r\n write(20,*) \"En el intervalo\",'(',k,',',f,')'\r\n write(20,*) \"usando \",N,' Puntos'\r\n\r\n allocate(B(N))\r\n\r\n do i = 1, N\r\n B(i)= ran ( )\r\n B(i)=k+B(i)*(f-k)\r\n\r\n end do\r\n\r\n end subroutine\r\n\r\n! ----------------------------------------------------------------\r\n\r\n end\r\n\r\n! ----------------------------------------------------------------\r\n\r\n", "meta": {"hexsha": "e8b99789437167ea1df6d48d781f39345ca77df5", "size": 3880, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "windows/Ejercicio 9/Ejercicio 9.f", "max_stars_repo_name": "patricio-c/fortran", "max_stars_repo_head_hexsha": "da11f9e06010399703e8d8e51f57c44a7663857f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "windows/Ejercicio 9/Ejercicio 9.f", "max_issues_repo_name": "patricio-c/fortran", "max_issues_repo_head_hexsha": "da11f9e06010399703e8d8e51f57c44a7663857f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "windows/Ejercicio 9/Ejercicio 9.f", "max_forks_repo_name": "patricio-c/fortran", "max_forks_repo_head_hexsha": "da11f9e06010399703e8d8e51f57c44a7663857f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.0454545455, "max_line_length": 84, "alphanum_fraction": 0.3737113402, "num_tokens": 998, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587817066392, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6683577838223973}} {"text": "!--------------------------------------------------------------------------------------\n!\n!Copyright (C) 2014 TopCoder Inc., All Rights Reserved.\n!\n!--------------------------------------------------------------------------------------\n\n! This module computes the mean yaw moment using the far-field momentum formulation for a infinite depth\n! case according to equation 4.6 of R1\n!\n! R1 Computation of Higher-Order Hydrodynamic Forces on Ships and Offshore Structures in Waves\n! http://dspace.mit.edu/bitstream/handle/1721.1/79979/42664020.pdf?sequence=1\n!\n! Contest Drift forces and QTF Implementation of Nemoh\n!\n!\n! Changes in version 1.1 (Implementation of Higher Order Panel Methods)\n! Added COMMON_TYPE module as dependency\n!\n! Changes in version 1.2 (Dipoles Implementation in NEMOH)\n! Switch from ParamsCommon to ParamsCommonInf\n!\n! @author yedtoss\n! @version 1.2\n\nmodule COMPUTE_YAW_MOMENT_INF\n\n USE COMMON_TYPE\n USE COM_VAR\n USE UTILITY\n USE KOCHIN\n\n implicit none\n\ncontains\n\n complex function diff_func_yaw_infinite(theta, param)\n ! Simple wrapper to the kochin function\n USE KOCHIN\n\n REAL, INTENT(IN) :: theta\n COMPLEX:: fx\n TYPE(ParamsCommonInf) :: param\n\n CALL COMPUTE_KOCHIN(param%kwave, theta, fx, param%SolverVar)\n diff_func_yaw_infinite = fx\n\n end function diff_func_yaw_infinite\n\n complex function yawintegral_mz(theta, param)\n ! Derivative of the kochin function multiplied the the conjugate of the value of kochin function at theta\n\n USE KOCHIN\n REAL, INTENT(IN) :: theta\n TYPE(ParamsCommonInf) :: param\n COMPLEX :: HKochin\n\n CALL COMPUTE_KOCHIN(param%kwave, theta, HKochin, param%SolverVar)\n\n yawintegral_mz = CONJG(HKochin)*deriv_richardson_complex(diff_func_yaw_infinite,theta, 1, 1e-3, param)\n\n end function yawintegral_mz\n\n\n\n\n subroutine compute_yaw_moment_infinite(param, yaw_moment)\n ! This is the main subrouting computing the yaw moment\n ! It use romberg_trap_complex to integrate the function yawintegralfin_mz\n ! and deriv_richardson_complex to find the derivative of the diff_func_yaw_finite\n\n REAL :: PI\n TYPE(ParamsCommonInf) :: param ! input parameter\n REAL :: yaw_moment, tmp ! yaw_moment is the output\n\n PI=4.*ATAN(1.)\n\n tmp = (-0.5*aimag(deriv_richardson_complex(diff_func_yaw_infinite,PI+param%beta, 1, 1e-3, param)))\n\n yaw_moment = (-RHO* (param%kwave)/(8*PI))*AIMAG(romberg_trap_complex(yawintegral_mz, 0., 2*PI, 1e-3, 2, param))\n\n yaw_moment = yaw_moment + RHO*param%w*param%AKH/param%kwave*tmp\n\n end subroutine compute_yaw_moment_infinite\nend module COMPUTE_YAW_MOMENT_INF\n", "meta": {"hexsha": "9e3e92ecbaabc0de484f9acf386e50900a453ac6", "size": 2752, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/NemohImproved/Nemoh/Solver/Core/COMPUTE_YAW_MOMENT_INF.f90", "max_stars_repo_name": "NREL/OpenWARP", "max_stars_repo_head_hexsha": "ca49c4cbde17e0cead69bd9e55a81d5c0fafe4df", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2015-06-22T07:35:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-23T05:10:09.000Z", "max_issues_repo_path": "source/NemohImproved/Nemoh/Solver/Core/COMPUTE_YAW_MOMENT_INF.f90", "max_issues_repo_name": "rhydar/Test", "max_issues_repo_head_hexsha": "32dd54af2c3657d0c49177395d5b1c1f7bd8e127", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2015-07-30T20:01:35.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-28T17:29:18.000Z", "max_forks_repo_path": "source/NemohImproved/Nemoh/Solver/Core/COMPUTE_YAW_MOMENT_INF.f90", "max_forks_repo_name": "rhydar/Test", "max_forks_repo_head_hexsha": "32dd54af2c3657d0c49177395d5b1c1f7bd8e127", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2016-04-01T07:45:27.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-06T08:33:33.000Z", "avg_line_length": 32.3764705882, "max_line_length": 119, "alphanum_fraction": 0.6635174419, "num_tokens": 727, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995483, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6683577833143732}} {"text": "C$Procedure UCRSS ( Unitized cross product, 3x3 )\n \n SUBROUTINE UCRSS ( V1, V2, VOUT )\n \nC$ Abstract\nC\nC Compute the normalized cross product of two 3-vectors.\nC\nC$ Disclaimer\nC\nC THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE\nC CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.\nC GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE\nC ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE\nC PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED \"AS-IS\"\nC TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY\nC WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A\nC PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC\nC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE\nC SOFTWARE AND RELATED MATERIALS, HOWEVER USED.\nC\nC IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA\nC BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT\nC LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,\nC INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,\nC REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE\nC REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.\nC\nC RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF\nC THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY\nC CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE\nC ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.\nC\nC$ Required_Reading\nC\nC None.\nC\nC$ Keywords\nC\nC VECTOR\nC\nC$ Declarations\n \n DOUBLE PRECISION V1 ( 3 )\n DOUBLE PRECISION V2 ( 3 )\n DOUBLE PRECISION VOUT ( 3 )\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC V1 I Left vector for cross product.\nC V2 I Right vector for cross product.\nC VOUT O Normalized cross product (V1xV2) / |V1xV2|.\nC\nC$ Detailed_Input\nC\nC V1 A 3-vector.\nC\nC V2 A 3-vector.\nC\nC$ Detailed_Output\nC\nC VOUT is the result of the computation (V1xV2)/|V1xV2|\nC\nC$ Parameters\nC\nC None.\nC\nC$ Particulars\nC\nC None.\nC\nC$ Examples\nC\nC To get a unit normal to the plane spanned by two vectors\nC V1 and V2. Simply call\nC\nC CALL UCRSS ( V1, V2, NORMAL )\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Exceptions\nC\nC Error free.\nC\nC 1) If the cross product of V1 and V2 yields the zero-vector, then\nC the zero-vector is returned instead of a vector of unit length.\nC\nC$ Files\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC W.M. Owen (JPL)\nC W.L. Taber (JPL)\nC\nC$ Literature_References\nC\nC None\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)\nC\nC Comment section for permuted index source lines was added\nC following the header.\nC\nC- SPICELIB Version 1.0.0, 31-JAN-1990 (WMO)\nC\nC-&\n \nC$ Index_Entries\nC\nC unitized cross product\nC\nC-&\n \nC$ Revisions\nC\nC- Beta Version 1.1.0, 10-JAN-1989 (WLT)\nC\nC Error free specification added. In addition the algorithm was made\nC more robust in the sense that floating point overflows cannot\nC occur.\nC\nC-&\n DOUBLE PRECISION VNORM\n DOUBLE PRECISION VCROSS(3)\n DOUBLE PRECISION VMAG\n \n DOUBLE PRECISION MAXV1\n DOUBLE PRECISION MAXV2\n \n DOUBLE PRECISION TV1 ( 3 )\n DOUBLE PRECISION TV2 ( 3 )\n \nC\nC Get the biggest component of each of the two vectors.\nC\n MAXV1 = MAX ( DABS(V1(1)), DABS(V1(2)), DABS(V1(3)) )\n MAXV2 = MAX ( DABS(V2(1)), DABS(V2(2)), DABS(V2(3)) )\n \nC\nC Scale V1 and V2 by 1/MAXV1 and 1/MAXV2 respectively\nC\n IF ( MAXV1 .NE. 0 ) THEN\n TV1(1) = V1(1)/MAXV1\n TV1(2) = V1(2)/MAXV1\n TV1(3) = V1(3)/MAXV1\n ELSE\n TV1(1) = 0.0D0\n TV1(2) = 0.0D0\n TV1(3) = 0.0D0\n END IF\n \n IF ( MAXV2 .NE. 0 ) THEN\n TV2(1) = V2(1)/MAXV2\n TV2(2) = V2(2)/MAXV2\n TV2(3) = V2(3)/MAXV2\n ELSE\n TV2(1) = 0.0D0\n TV2(2) = 0.0D0\n TV2(3) = 0.0D0\n END IF\n \nC\nC Calculate the cross product of V1 and V2\nC\n VCROSS(1) = TV1(2)*TV2(3) - TV1(3)*TV2(2)\n VCROSS(2) = TV1(3)*TV2(1) - TV1(1)*TV2(3)\n VCROSS(3) = TV1(1)*TV2(2) - TV1(2)*TV2(1)\nC\nC Get the magnitude of VCROSS and normalize it\nC\n VMAG = VNORM(VCROSS)\n \n IF (VMAG.GT.0.D0) THEN\n VOUT(1) = VCROSS(1) / VMAG\n VOUT(2) = VCROSS(2) / VMAG\n VOUT(3) = VCROSS(3) / VMAG\n ELSE\n VOUT(1) = 0.D0\n VOUT(2) = 0.D0\n VOUT(3) = 0.D0\n END IF\n \n RETURN\n END\n", "meta": {"hexsha": "dbc2d98f04c7cc2854179b36ff90f84a3c6d2887", "size": 4735, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/ucrss.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/ucrss.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/ucrss.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.5336787565, "max_line_length": 72, "alphanum_fraction": 0.613093981, "num_tokens": 1638, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587934924569, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6683577828063487}} {"text": "#define IMPLICIT_STATEMENT IMPLICIT INTEGER(4) (I-N), REAL(4) (A-H, O-Z)\r\n#define IFAC_TYPE REAL(4)\r\n\r\nC --------------------------------------------------------------\r\nC Source code obtained from FFTPACK version 4.1 , available at\r\nC http://www.scd.ucar.edu/softlib/mathlib.html\r\nC --------------------------------------------------------------\r\nC SUBROUTINE RFFTI(N,WSAVE)\r\nC\r\nC SUBROUTINE RFFTI INITIALIZES THE ARRAY WSAVE WHICH IS USED IN\r\nC BOTH RFFTF AND RFFTB. THE PRIME FACTORIZATION OF N TOGETHER WITH\r\nC A TABULATION OF THE TRIGONOMETRIC FUNCTIONS ARE COMPUTED AND\r\nC STORED IN WSAVE.\r\nC\r\nC INPUT PARAMETER\r\nC\r\nC N THE LENGTH OF THE SEQUENCE TO BE TRANSFORMED.\r\nC\r\nC OUTPUT PARAMETER\r\nC\r\nC WSAVE A WORK ARRAY WHICH MUST BE DIMENSIONED AT LEAST 2*N+15.\r\nC THE SAME WORK ARRAY CAN BE USED FOR BOTH RFFTF AND RFFTB\r\nC AS LONG AS N REMAINS UNCHANGED. DIFFERENT WSAVE ARRAYS\r\nC ARE REQUIRED FOR DIFFERENT VALUES OF N. THE CONTENTS OF\r\nC WSAVE MUST NOT BE CHANGED BETWEEN CALLS OF RFFTF OR RFFTB.\r\nC\r\n SUBROUTINE RFFTI (N,WSAVE)\r\n IMPLICIT_STATEMENT\r\n DIMENSION WSAVE(*)\r\nC\r\n IF (N .EQ. 1) RETURN\r\n CALL RFFTI1 (N,WSAVE(N+1),WSAVE(2*N+1))\r\n RETURN\r\n END\r\n\r\n\r\n SUBROUTINE RFFTI1 (N,WA,IFAC)\r\n IMPLICIT_STATEMENT\r\n!!bjj START (fix for compatibility in double precision):\r\n!! also note I added nint() around places where IFAC is on the right-hand side of the equation\r\n! DIMENSION WA(*) ,IFAC(*) ,NTRYH(4)\r\n IFAC_TYPE, DIMENSION(*) :: IFAC\r\n DIMENSION WA(*) ,NTRYH(4)\r\n!!bjj END\r\n DATA NTRYH(1),NTRYH(2),NTRYH(3),NTRYH(4)/4,2,3,5/\r\n NL = N\r\n NF = 0\r\n J = 0\r\n 101 J = J+1\r\n IF (J-4) 102,102,103\r\n 102 NTRY = NTRYH(J)\r\n GO TO 104\r\n 103 NTRY = NTRY+2\r\n 104 NQ = NL/NTRY\r\n NR = NL-NTRY*NQ\r\n IF (NR) 101,105,101\r\n 105 NF = NF+1\r\n IFAC(NF+2) = NTRY\r\n NL = NQ\r\n IF (NTRY .NE. 2) GO TO 107\r\n IF (NF .EQ. 1) GO TO 107\r\n DO 106 I=2,NF\r\n IB = NF-I+2\r\n IFAC(IB+2) = nint(IFAC(IB+1))\r\n 106 CONTINUE\r\n IFAC(3) = 2\r\n 107 IF (NL .NE. 1) GO TO 104\r\n IFAC(1) = N\r\n IFAC(2) = NF\r\n TPI = 2.0*PIMACH(DUM)\r\n ARGH = TPI/FLOAT(N)\r\n IS = 0\r\n NFM1 = NF-1\r\n L1 = 1\r\n IF (NFM1 .EQ. 0) RETURN\r\n DO 110 K1=1,NFM1\r\n IP = nint(IFAC(K1+2))\r\n LD = 0\r\n L2 = L1*IP\r\n IDO = N/L2\r\n IPM = IP-1\r\n DO 109 J=1,IPM\r\n LD = LD+L1\r\n I = IS\r\n ARGLD = FLOAT(LD)*ARGH\r\n FI = 0.\r\n DO 108 II=3,IDO,2\r\n I = I+2\r\n FI = FI+1.\r\n ARG = FI*ARGLD\r\n WA(I-1) = COS(ARG)\r\n WA(I) = SIN(ARG)\r\n 108 CONTINUE\r\n IS = IS+IDO\r\n 109 CONTINUE\r\n L1 = L2\r\n 110 CONTINUE\r\n RETURN\r\n END\r\n\r\n\r\nC SUBROUTINE RFFTB(N,R,WSAVE)\r\nC\r\nC SUBROUTINE RFFTB COMPUTES THE REAL PERODIC SEQUENCE FROM ITS\r\nC FOURIER COEFFICIENTS (FOURIER SYNTHESIS). THE TRANSFORM IS DEFINED\r\nC BELOW AT OUTPUT PARAMETER R.\r\nC\r\nC INPUT PARAMETERS\r\nC\r\nC N THE LENGTH OF THE ARRAY R TO BE TRANSFORMED. THE METHOD\r\nC IS MOST EFFICIENT WHEN N IS A PRODUCT OF SMALL PRIMES.\r\nC N MAY CHANGE SO LONG AS DIFFERENT WORK ARRAYS ARE PROVIDED\r\nC\r\nC R A REAL ARRAY OF LENGTH N WHICH CONTAINS THE SEQUENCE\r\nC TO BE TRANSFORMED\r\nC\r\nC WSAVE A WORK ARRAY WHICH MUST BE DIMENSIONED AT LEAST 2*N+15.\r\nC IN THE PROGRAM THAT CALLS RFFTB. THE WSAVE ARRAY MUST BE\r\nC INITIALIZED BY CALLING SUBROUTINE RFFTI(N,WSAVE) AND A\r\nC DIFFERENT WSAVE ARRAY MUST BE USED FOR EACH DIFFERENT\r\nC VALUE OF N. THIS INITIALIZATION DOES NOT HAVE TO BE\r\nC REPEATED SO LONG AS N REMAINS UNCHANGED THUS SUBSEQUENT\r\nC TRANSFORMS CAN BE OBTAINED FASTER THAN THE FIRST.\r\nC THE SAME WSAVE ARRAY CAN BE USED BY RFFTF AND RFFTB.\r\nC\r\nC\r\nC OUTPUT PARAMETERS\r\nC\r\nC R FOR N EVEN AND FOR I = 1,...,N\r\nC\r\nC R(I) = R(1)+(-1)**(I-1)*R(N)\r\nC\r\nC PLUS THE SUM FROM K=2 TO K=N/2 OF\r\nC\r\nC 2.*R(2*K-2)*COS((K-1)*(I-1)*2*PI/N)\r\nC\r\nC -2.*R(2*K-1)*SIN((K-1)*(I-1)*2*PI/N)\r\nC\r\nC FOR N ODD AND FOR I = 1,...,N\r\nC\r\nC R(I) = R(1) PLUS THE SUM FROM K=2 TO K=(N+1)/2 OF\r\nC\r\nC 2.*R(2*K-2)*COS((K-1)*(I-1)*2*PI/N)\r\nC\r\nC -2.*R(2*K-1)*SIN((K-1)*(I-1)*2*PI/N)\r\nC\r\nC ***** NOTE\r\nC THIS TRANSFORM IS UNNORMALIZED SINCE A CALL OF RFFTF\r\nC FOLLOWED BY A CALL OF RFFTB WILL MULTIPLY THE INPUT\r\nC SEQUENCE BY N.\r\nC\r\nC WSAVE CONTAINS RESULTS WHICH MUST NOT BE DESTROYED BETWEEN\r\nC CALLS OF RFFTB OR RFFTF.\r\nC\r\nC\r\n SUBROUTINE RFFTB (N,R,WSAVE)\r\n IMPLICIT_STATEMENT\r\n DIMENSION R(*) ,WSAVE(*)\r\nC\r\n IF (N .EQ. 1) RETURN\r\n CALL RFFTB1 (N,R,WSAVE,WSAVE(N+1),WSAVE(2*N+1))\r\n RETURN\r\n END\r\n\r\n\r\n SUBROUTINE RFFTB1 (N,C,CH,WA,IFAC)\r\n IMPLICIT_STATEMENT\r\n!!bjj START (fix for compatibility in double precision):\r\n!! also note I added nint() around places where IFAC is on the right-hand side of the equation\r\n! DIMENSION CH(*) ,C(*) ,WA(*) ,IFAC(*)\r\n IFAC_TYPE, DIMENSION(*) :: IFAC\r\n DIMENSION CH(*) ,C(*) ,WA(*)\r\n!!bjj End \r\n NF = nint(IFAC(2))\r\n NA = 0\r\n L1 = 1\r\n IW = 1\r\n DO 116 K1=1,NF\r\n IP = nint(IFAC(K1+2))\r\n L2 = IP*L1\r\n IDO = N/L2\r\n IDL1 = IDO*L1\r\n IF (IP .NE. 4) GO TO 103\r\n IX2 = IW+IDO\r\n IX3 = IX2+IDO\r\n IF (NA .NE. 0) GO TO 101\r\n CALL RADB4 (IDO,L1,C,CH,WA(IW),WA(IX2),WA(IX3))\r\n GO TO 102\r\n 101 CALL RADB4 (IDO,L1,CH,C,WA(IW),WA(IX2),WA(IX3))\r\n 102 NA = 1-NA\r\n GO TO 115\r\n 103 IF (IP .NE. 2) GO TO 106\r\n IF (NA .NE. 0) GO TO 104\r\n CALL RADB2 (IDO,L1,C,CH,WA(IW))\r\n GO TO 105\r\n 104 CALL RADB2 (IDO,L1,CH,C,WA(IW))\r\n 105 NA = 1-NA\r\n GO TO 115\r\n 106 IF (IP .NE. 3) GO TO 109\r\n IX2 = IW+IDO\r\n IF (NA .NE. 0) GO TO 107\r\n CALL RADB3 (IDO,L1,C,CH,WA(IW),WA(IX2))\r\n GO TO 108\r\n 107 CALL RADB3 (IDO,L1,CH,C,WA(IW),WA(IX2))\r\n 108 NA = 1-NA\r\n GO TO 115\r\n 109 IF (IP .NE. 5) GO TO 112\r\n IX2 = IW+IDO\r\n IX3 = IX2+IDO\r\n IX4 = IX3+IDO\r\n IF (NA .NE. 0) GO TO 110\r\n CALL RADB5 (IDO,L1,C,CH,WA(IW),WA(IX2),WA(IX3),WA(IX4))\r\n GO TO 111\r\n 110 CALL RADB5 (IDO,L1,CH,C,WA(IW),WA(IX2),WA(IX3),WA(IX4))\r\n 111 NA = 1-NA\r\n GO TO 115\r\n 112 IF (NA .NE. 0) GO TO 113\r\n CALL RADBG (IDO,IP,L1,IDL1,C,C,C,CH,CH,WA(IW))\r\n GO TO 114\r\n 113 CALL RADBG (IDO,IP,L1,IDL1,CH,CH,CH,C,C,WA(IW))\r\n 114 IF (IDO .EQ. 1) NA = 1-NA\r\n 115 L1 = L2\r\n IW = IW+(IP-1)*IDO\r\n 116 CONTINUE\r\n IF (NA .EQ. 0) RETURN\r\n DO 117 I=1,N\r\n C(I) = CH(I)\r\n 117 CONTINUE\r\n RETURN\r\n END\r\n\r\n\r\n SUBROUTINE RADB2 (IDO,L1,CC,CH,WA1)\r\n IMPLICIT_STATEMENT\r\n DIMENSION CC(IDO,2,L1) ,CH(IDO,L1,2) ,\r\n 1 WA1(*)\r\n DO 101 K=1,L1\r\n CH(1,K,1) = CC(1,1,K)+CC(IDO,2,K)\r\n CH(1,K,2) = CC(1,1,K)-CC(IDO,2,K)\r\n 101 CONTINUE\r\n IF (IDO-2) 107,105,102\r\n 102 IDP2 = IDO+2\r\n DO 104 K=1,L1\r\n DO 103 I=3,IDO,2\r\n IC = IDP2-I\r\n CH(I-1,K,1) = CC(I-1,1,K)+CC(IC-1,2,K)\r\n TR2 = CC(I-1,1,K)-CC(IC-1,2,K)\r\n CH(I,K,1) = CC(I,1,K)-CC(IC,2,K)\r\n TI2 = CC(I,1,K)+CC(IC,2,K)\r\n CH(I-1,K,2) = WA1(I-2)*TR2-WA1(I-1)*TI2\r\n CH(I,K,2) = WA1(I-2)*TI2+WA1(I-1)*TR2\r\n 103 CONTINUE\r\n 104 CONTINUE\r\n IF (MOD(IDO,2) .EQ. 1) RETURN\r\n 105 DO 106 K=1,L1\r\n CH(IDO,K,1) = CC(IDO,1,K)+CC(IDO,1,K)\r\n CH(IDO,K,2) = -(CC(1,2,K)+CC(1,2,K))\r\n 106 CONTINUE\r\n 107 RETURN\r\n END\r\n\r\n\r\n SUBROUTINE RADB3 (IDO,L1,CC,CH,WA1,WA2)\r\n IMPLICIT_STATEMENT\r\n DIMENSION CC(IDO,3,L1) ,CH(IDO,L1,3) ,\r\n 1 WA1(*) ,WA2(*)\r\n DATA TAUR,TAUI /-.5,.866025403784439/\r\n DO 101 K=1,L1\r\n TR2 = CC(IDO,2,K)+CC(IDO,2,K)\r\n CR2 = CC(1,1,K)+TAUR*TR2\r\n CH(1,K,1) = CC(1,1,K)+TR2\r\n CI3 = TAUI*(CC(1,3,K)+CC(1,3,K))\r\n CH(1,K,2) = CR2-CI3\r\n CH(1,K,3) = CR2+CI3\r\n 101 CONTINUE\r\n IF (IDO .EQ. 1) RETURN\r\n IDP2 = IDO+2\r\n DO 103 K=1,L1\r\n DO 102 I=3,IDO,2\r\n IC = IDP2-I\r\n TR2 = CC(I-1,3,K)+CC(IC-1,2,K)\r\n CR2 = CC(I-1,1,K)+TAUR*TR2\r\n CH(I-1,K,1) = CC(I-1,1,K)+TR2\r\n TI2 = CC(I,3,K)-CC(IC,2,K)\r\n CI2 = CC(I,1,K)+TAUR*TI2\r\n CH(I,K,1) = CC(I,1,K)+TI2\r\n CR3 = TAUI*(CC(I-1,3,K)-CC(IC-1,2,K))\r\n CI3 = TAUI*(CC(I,3,K)+CC(IC,2,K))\r\n DR2 = CR2-CI3\r\n DR3 = CR2+CI3\r\n DI2 = CI2+CR3\r\n DI3 = CI2-CR3\r\n CH(I-1,K,2) = WA1(I-2)*DR2-WA1(I-1)*DI2\r\n CH(I,K,2) = WA1(I-2)*DI2+WA1(I-1)*DR2\r\n CH(I-1,K,3) = WA2(I-2)*DR3-WA2(I-1)*DI3\r\n CH(I,K,3) = WA2(I-2)*DI3+WA2(I-1)*DR3\r\n 102 CONTINUE\r\n 103 CONTINUE\r\n RETURN\r\n END\r\n\r\n\r\n SUBROUTINE RADB4 (IDO,L1,CC,CH,WA1,WA2,WA3)\r\n IMPLICIT_STATEMENT\r\n DIMENSION CC(IDO,4,L1) ,CH(IDO,L1,4) ,\r\n 1 WA1(*) ,WA2(*) ,WA3(*)\r\n DATA SQRT2 /1.414213562373095/\r\n DO 101 K=1,L1\r\n TR1 = CC(1,1,K)-CC(IDO,4,K)\r\n TR2 = CC(1,1,K)+CC(IDO,4,K)\r\n TR3 = CC(IDO,2,K)+CC(IDO,2,K)\r\n TR4 = CC(1,3,K)+CC(1,3,K)\r\n CH(1,K,1) = TR2+TR3\r\n CH(1,K,2) = TR1-TR4\r\n CH(1,K,3) = TR2-TR3\r\n CH(1,K,4) = TR1+TR4\r\n 101 CONTINUE\r\n IF (IDO-2) 107,105,102\r\n 102 IDP2 = IDO+2\r\n DO 104 K=1,L1\r\n DO 103 I=3,IDO,2\r\n IC = IDP2-I\r\n TI1 = CC(I,1,K)+CC(IC,4,K)\r\n TI2 = CC(I,1,K)-CC(IC,4,K)\r\n TI3 = CC(I,3,K)-CC(IC,2,K)\r\n TR4 = CC(I,3,K)+CC(IC,2,K)\r\n TR1 = CC(I-1,1,K)-CC(IC-1,4,K)\r\n TR2 = CC(I-1,1,K)+CC(IC-1,4,K)\r\n TI4 = CC(I-1,3,K)-CC(IC-1,2,K)\r\n TR3 = CC(I-1,3,K)+CC(IC-1,2,K)\r\n CH(I-1,K,1) = TR2+TR3\r\n CR3 = TR2-TR3\r\n CH(I,K,1) = TI2+TI3\r\n CI3 = TI2-TI3\r\n CR2 = TR1-TR4\r\n CR4 = TR1+TR4\r\n CI2 = TI1+TI4\r\n CI4 = TI1-TI4\r\n CH(I-1,K,2) = WA1(I-2)*CR2-WA1(I-1)*CI2\r\n CH(I,K,2) = WA1(I-2)*CI2+WA1(I-1)*CR2\r\n CH(I-1,K,3) = WA2(I-2)*CR3-WA2(I-1)*CI3\r\n CH(I,K,3) = WA2(I-2)*CI3+WA2(I-1)*CR3\r\n CH(I-1,K,4) = WA3(I-2)*CR4-WA3(I-1)*CI4\r\n CH(I,K,4) = WA3(I-2)*CI4+WA3(I-1)*CR4\r\n 103 CONTINUE\r\n 104 CONTINUE\r\n IF (MOD(IDO,2) .EQ. 1) RETURN\r\n 105 CONTINUE\r\n DO 106 K=1,L1\r\n TI1 = CC(1,2,K)+CC(1,4,K)\r\n TI2 = CC(1,4,K)-CC(1,2,K)\r\n TR1 = CC(IDO,1,K)-CC(IDO,3,K)\r\n TR2 = CC(IDO,1,K)+CC(IDO,3,K)\r\n CH(IDO,K,1) = TR2+TR2\r\n CH(IDO,K,2) = SQRT2*(TR1-TI1)\r\n CH(IDO,K,3) = TI2+TI2\r\n CH(IDO,K,4) = -SQRT2*(TR1+TI1)\r\n 106 CONTINUE\r\n 107 RETURN\r\n END\r\n\r\n\r\n SUBROUTINE RADB5 (IDO,L1,CC,CH,WA1,WA2,WA3,WA4)\r\n IMPLICIT_STATEMENT\r\n DIMENSION CC(IDO,5,L1) ,CH(IDO,L1,5) ,\r\n 1 WA1(*) ,WA2(*) ,WA3(*) ,WA4(*)\r\n DATA TR11,TI11,TR12,TI12 /.309016994374947,.951056516295154,\r\n 1-.809016994374947,.587785252292473/\r\n DO 101 K=1,L1\r\n TI5 = CC(1,3,K)+CC(1,3,K)\r\n TI4 = CC(1,5,K)+CC(1,5,K)\r\n TR2 = CC(IDO,2,K)+CC(IDO,2,K)\r\n TR3 = CC(IDO,4,K)+CC(IDO,4,K)\r\n CH(1,K,1) = CC(1,1,K)+TR2+TR3\r\n CR2 = CC(1,1,K)+TR11*TR2+TR12*TR3\r\n CR3 = CC(1,1,K)+TR12*TR2+TR11*TR3\r\n CI5 = TI11*TI5+TI12*TI4\r\n CI4 = TI12*TI5-TI11*TI4\r\n CH(1,K,2) = CR2-CI5\r\n CH(1,K,3) = CR3-CI4\r\n CH(1,K,4) = CR3+CI4\r\n CH(1,K,5) = CR2+CI5\r\n 101 CONTINUE\r\n IF (IDO .EQ. 1) RETURN\r\n IDP2 = IDO+2\r\n DO 103 K=1,L1\r\n DO 102 I=3,IDO,2\r\n IC = IDP2-I\r\n TI5 = CC(I,3,K)+CC(IC,2,K)\r\n TI2 = CC(I,3,K)-CC(IC,2,K)\r\n TI4 = CC(I,5,K)+CC(IC,4,K)\r\n TI3 = CC(I,5,K)-CC(IC,4,K)\r\n TR5 = CC(I-1,3,K)-CC(IC-1,2,K)\r\n TR2 = CC(I-1,3,K)+CC(IC-1,2,K)\r\n TR4 = CC(I-1,5,K)-CC(IC-1,4,K)\r\n TR3 = CC(I-1,5,K)+CC(IC-1,4,K)\r\n CH(I-1,K,1) = CC(I-1,1,K)+TR2+TR3\r\n CH(I,K,1) = CC(I,1,K)+TI2+TI3\r\n CR2 = CC(I-1,1,K)+TR11*TR2+TR12*TR3\r\n CI2 = CC(I,1,K)+TR11*TI2+TR12*TI3\r\n CR3 = CC(I-1,1,K)+TR12*TR2+TR11*TR3\r\n CI3 = CC(I,1,K)+TR12*TI2+TR11*TI3\r\n CR5 = TI11*TR5+TI12*TR4\r\n CI5 = TI11*TI5+TI12*TI4\r\n CR4 = TI12*TR5-TI11*TR4\r\n CI4 = TI12*TI5-TI11*TI4\r\n DR3 = CR3-CI4\r\n DR4 = CR3+CI4\r\n DI3 = CI3+CR4\r\n DI4 = CI3-CR4\r\n DR5 = CR2+CI5\r\n DR2 = CR2-CI5\r\n DI5 = CI2-CR5\r\n DI2 = CI2+CR5\r\n CH(I-1,K,2) = WA1(I-2)*DR2-WA1(I-1)*DI2\r\n CH(I,K,2) = WA1(I-2)*DI2+WA1(I-1)*DR2\r\n CH(I-1,K,3) = WA2(I-2)*DR3-WA2(I-1)*DI3\r\n CH(I,K,3) = WA2(I-2)*DI3+WA2(I-1)*DR3\r\n CH(I-1,K,4) = WA3(I-2)*DR4-WA3(I-1)*DI4\r\n CH(I,K,4) = WA3(I-2)*DI4+WA3(I-1)*DR4\r\n CH(I-1,K,5) = WA4(I-2)*DR5-WA4(I-1)*DI5\r\n CH(I,K,5) = WA4(I-2)*DI5+WA4(I-1)*DR5\r\n 102 CONTINUE\r\n 103 CONTINUE\r\n RETURN\r\n END\r\n\r\n\r\n SUBROUTINE RADBG (IDO,IP,L1,IDL1,CC,C1,C2,CH,CH2,WA)\r\n IMPLICIT_STATEMENT\r\n DIMENSION CH(IDO,L1,IP) ,CC(IDO,IP,L1) ,\r\n 1 C1(IDO,L1,IP) ,C2(IDL1,IP),\r\n 2 CH2(IDL1,IP) ,WA(*)\r\n TPI = 2.0*PIMACH(DUM)\r\n ARG = TPI/FLOAT(IP)\r\n DCP = COS(ARG)\r\n DSP = SIN(ARG)\r\n IDP2 = IDO+2\r\n NBD = (IDO-1)/2\r\n IPP2 = IP+2\r\n IPPH = (IP+1)/2\r\n IF (IDO .LT. L1) GO TO 103\r\n DO 102 K=1,L1\r\n DO 101 I=1,IDO\r\n CH(I,K,1) = CC(I,1,K)\r\n 101 CONTINUE\r\n 102 CONTINUE\r\n GO TO 106\r\n 103 DO 105 I=1,IDO\r\n DO 104 K=1,L1\r\n CH(I,K,1) = CC(I,1,K)\r\n 104 CONTINUE\r\n 105 CONTINUE\r\n 106 DO 108 J=2,IPPH\r\n JC = IPP2-J\r\n J2 = J+J\r\n DO 107 K=1,L1\r\n CH(1,K,J) = CC(IDO,J2-2,K)+CC(IDO,J2-2,K)\r\n CH(1,K,JC) = CC(1,J2-1,K)+CC(1,J2-1,K)\r\n 107 CONTINUE\r\n 108 CONTINUE\r\n IF (IDO .EQ. 1) GO TO 116\r\n IF (NBD .LT. L1) GO TO 112\r\n DO 111 J=2,IPPH\r\n JC = IPP2-J\r\n DO 110 K=1,L1\r\n DO 109 I=3,IDO,2\r\n IC = IDP2-I\r\n CH(I-1,K,J) = CC(I-1,2*J-1,K)+CC(IC-1,2*J-2,K)\r\n CH(I-1,K,JC) = CC(I-1,2*J-1,K)-CC(IC-1,2*J-2,K)\r\n CH(I,K,J) = CC(I,2*J-1,K)-CC(IC,2*J-2,K)\r\n CH(I,K,JC) = CC(I,2*J-1,K)+CC(IC,2*J-2,K)\r\n 109 CONTINUE\r\n 110 CONTINUE\r\n 111 CONTINUE\r\n GO TO 116\r\n 112 DO 115 J=2,IPPH\r\n JC = IPP2-J\r\n DO 114 I=3,IDO,2\r\n IC = IDP2-I\r\n DO 113 K=1,L1\r\n CH(I-1,K,J) = CC(I-1,2*J-1,K)+CC(IC-1,2*J-2,K)\r\n CH(I-1,K,JC) = CC(I-1,2*J-1,K)-CC(IC-1,2*J-2,K)\r\n CH(I,K,J) = CC(I,2*J-1,K)-CC(IC,2*J-2,K)\r\n CH(I,K,JC) = CC(I,2*J-1,K)+CC(IC,2*J-2,K)\r\n 113 CONTINUE\r\n 114 CONTINUE\r\n 115 CONTINUE\r\n 116 AR1 = 1.\r\n AI1 = 0.\r\n DO 120 L=2,IPPH\r\n LC = IPP2-L\r\n AR1H = DCP*AR1-DSP*AI1\r\n AI1 = DCP*AI1+DSP*AR1\r\n AR1 = AR1H\r\n DO 117 IK=1,IDL1\r\n C2(IK,L) = CH2(IK,1)+AR1*CH2(IK,2)\r\n C2(IK,LC) = AI1*CH2(IK,IP)\r\n 117 CONTINUE\r\n DC2 = AR1\r\n DS2 = AI1\r\n AR2 = AR1\r\n AI2 = AI1\r\n DO 119 J=3,IPPH\r\n JC = IPP2-J\r\n AR2H = DC2*AR2-DS2*AI2\r\n AI2 = DC2*AI2+DS2*AR2\r\n AR2 = AR2H\r\n DO 118 IK=1,IDL1\r\n C2(IK,L) = C2(IK,L)+AR2*CH2(IK,J)\r\n C2(IK,LC) = C2(IK,LC)+AI2*CH2(IK,JC)\r\n 118 CONTINUE\r\n 119 CONTINUE\r\n 120 CONTINUE\r\n DO 122 J=2,IPPH\r\n DO 121 IK=1,IDL1\r\n CH2(IK,1) = CH2(IK,1)+CH2(IK,J)\r\n 121 CONTINUE\r\n 122 CONTINUE\r\n DO 124 J=2,IPPH\r\n JC = IPP2-J\r\n DO 123 K=1,L1\r\n CH(1,K,J) = C1(1,K,J)-C1(1,K,JC)\r\n CH(1,K,JC) = C1(1,K,J)+C1(1,K,JC)\r\n 123 CONTINUE\r\n 124 CONTINUE\r\n IF (IDO .EQ. 1) GO TO 132\r\n IF (NBD .LT. L1) GO TO 128\r\n DO 127 J=2,IPPH\r\n JC = IPP2-J\r\n DO 126 K=1,L1\r\n DO 125 I=3,IDO,2\r\n CH(I-1,K,J) = C1(I-1,K,J)-C1(I,K,JC)\r\n CH(I-1,K,JC) = C1(I-1,K,J)+C1(I,K,JC)\r\n CH(I,K,J) = C1(I,K,J)+C1(I-1,K,JC)\r\n CH(I,K,JC) = C1(I,K,J)-C1(I-1,K,JC)\r\n 125 CONTINUE\r\n 126 CONTINUE\r\n 127 CONTINUE\r\n GO TO 132\r\n 128 DO 131 J=2,IPPH\r\n JC = IPP2-J\r\n DO 130 I=3,IDO,2\r\n DO 129 K=1,L1\r\n CH(I-1,K,J) = C1(I-1,K,J)-C1(I,K,JC)\r\n CH(I-1,K,JC) = C1(I-1,K,J)+C1(I,K,JC)\r\n CH(I,K,J) = C1(I,K,J)+C1(I-1,K,JC)\r\n CH(I,K,JC) = C1(I,K,J)-C1(I-1,K,JC)\r\n 129 CONTINUE\r\n 130 CONTINUE\r\n 131 CONTINUE\r\n 132 CONTINUE\r\n IF (IDO .EQ. 1) RETURN\r\n DO 133 IK=1,IDL1\r\n C2(IK,1) = CH2(IK,1)\r\n 133 CONTINUE\r\n DO 135 J=2,IP\r\n DO 134 K=1,L1\r\n C1(1,K,J) = CH(1,K,J)\r\n 134 CONTINUE\r\n 135 CONTINUE\r\n IF (NBD .GT. L1) GO TO 139\r\n IS = -IDO\r\n DO 138 J=2,IP\r\n IS = IS+IDO\r\n IDIJ = IS\r\n DO 137 I=3,IDO,2\r\n IDIJ = IDIJ+2\r\n DO 136 K=1,L1\r\n C1(I-1,K,J) = WA(IDIJ-1)*CH(I-1,K,J)-WA(IDIJ)*CH(I,K,J)\r\n C1(I,K,J) = WA(IDIJ-1)*CH(I,K,J)+WA(IDIJ)*CH(I-1,K,J)\r\n 136 CONTINUE\r\n 137 CONTINUE\r\n 138 CONTINUE\r\n GO TO 143\r\n 139 IS = -IDO\r\n DO 142 J=2,IP\r\n IS = IS+IDO\r\n DO 141 K=1,L1\r\n IDIJ = IS\r\n DO 140 I=3,IDO,2\r\n IDIJ = IDIJ+2\r\n C1(I-1,K,J) = WA(IDIJ-1)*CH(I-1,K,J)-WA(IDIJ)*CH(I,K,J)\r\n C1(I,K,J) = WA(IDIJ-1)*CH(I,K,J)+WA(IDIJ)*CH(I-1,K,J)\r\n 140 CONTINUE\r\n 141 CONTINUE\r\n 142 CONTINUE\r\n 143 RETURN\r\n END\r\n\r\n\r\n FUNCTION PIMACH (DUM)\r\n IMPLICIT_STATEMENT\r\nC PI=3.1415926535897932384626433832795028841971693993751058209749446\r\nC\r\n PIMACH = 4.*ATAN(1.0)\r\n RETURN\r\n END\r\n\r\n\r\nC SUBROUTINE COSTI(N,WSAVE)\r\nC\r\nC SUBROUTINE COSTI INITIALIZES THE ARRAY WSAVE WHICH IS USED IN\r\nC SUBROUTINE COST. THE PRIME FACTORIZATION OF N TOGETHER WITH\r\nC A TABULATION OF THE TRIGONOMETRIC FUNCTIONS ARE COMPUTED AND\r\nC STORED IN WSAVE.\r\nC\r\nC INPUT PARAMETER\r\nC\r\nC N THE LENGTH OF THE SEQUENCE TO BE TRANSFORMED. THE METHOD\r\nC IS MOST EFFICIENT WHEN N-1 IS A PRODUCT OF SMALL PRIMES.\r\nC\r\nC OUTPUT PARAMETER\r\nC\r\nC WSAVE A WORK ARRAY WHICH MUST BE DIMENSIONED AT LEAST 3*N+15.\r\nC DIFFERENT WSAVE ARRAYS ARE REQUIRED FOR DIFFERENT VALUES\r\nC OF N. THE CONTENTS OF WSAVE MUST NOT BE CHANGED BETWEEN\r\nC CALLS OF COST.\r\nC\r\n SUBROUTINE COSTI (N,WSAVE)\r\n IMPLICIT_STATEMENT\r\n DIMENSION WSAVE(*)\r\nC\r\n PI = PIMACH(DUM)\r\n IF (N .LE. 3) RETURN\r\n NM1 = N-1\r\n NP1 = N+1\r\n NS2 = N/2\r\n DT = PI/FLOAT(NM1)\r\n FK = 0.\r\n DO 101 K=2,NS2\r\n KC = NP1-K\r\n FK = FK+1.\r\n WSAVE(K) = 2.*SIN(FK*DT)\r\n WSAVE(KC) = 2.*COS(FK*DT)\r\n 101 CONTINUE\r\n CALL RFFTI (NM1,WSAVE(N+1))\r\n RETURN\r\n END\r\n\r\n\r\nC SUBROUTINE COST(N,X,WSAVE)\r\nC\r\nC SUBROUTINE COST COMPUTES THE DISCRETE FOURIER COSINE TRANSFORM\r\nC OF AN EVEN SEQUENCE X(I). THE TRANSFORM IS DEFINED BELOW AT OUTPUT\r\nC PARAMETER X.\r\nC\r\nC COST IS THE UNNORMALIZED INVERSE OF ITSELF SINCE A CALL OF COST\r\nC FOLLOWED BY ANOTHER CALL OF COST WILL MULTIPLY THE INPUT SEQUENCE\r\nC X BY 2*(N-1). THE TRANSFORM IS DEFINED BELOW AT OUTPUT PARAMETER X\r\nC\r\nC THE ARRAY WSAVE WHICH IS USED BY SUBROUTINE COST MUST BE\r\nC INITIALIZED BY CALLING SUBROUTINE COSTI(N,WSAVE).\r\nC\r\nC INPUT PARAMETERS\r\nC\r\nC N THE LENGTH OF THE SEQUENCE X. N MUST BE GREATER THAN 1.\r\nC THE METHOD IS MOST EFFICIENT WHEN N-1 IS A PRODUCT OF\r\nC SMALL PRIMES.\r\nC\r\nC X AN ARRAY WHICH CONTAINS THE SEQUENCE TO BE TRANSFORMED\r\nC\r\nC WSAVE A WORK ARRAY WHICH MUST BE DIMENSIONED AT LEAST 3*N+15\r\nC IN THE PROGRAM THAT CALLS COST. THE WSAVE ARRAY MUST BE\r\nC INITIALIZED BY CALLING SUBROUTINE COSTI(N,WSAVE) AND A\r\nC DIFFERENT WSAVE ARRAY MUST BE USED FOR EACH DIFFERENT\r\nC VALUE OF N. THIS INITIALIZATION DOES NOT HAVE TO BE\r\nC REPEATED SO LONG AS N REMAINS UNCHANGED THUS SUBSEQUENT\r\nC TRANSFORMS CAN BE OBTAINED FASTER THAN THE FIRST.\r\nC\r\nC OUTPUT PARAMETERS\r\nC\r\nC X FOR I=1,...,N\r\nC\r\nC X(I) = X(1)+(-1)**(I-1)*X(N)\r\nC\r\nC + THE SUM FROM K=2 TO K=N-1\r\nC\r\nC 2*X(K)*COS((K-1)*(I-1)*PI/(N-1))\r\nC\r\nC A CALL OF COST FOLLOWED BY ANOTHER CALL OF\r\nC COST WILL MULTIPLY THE SEQUENCE X BY 2*(N-1)\r\nC HENCE COST IS THE UNNORMALIZED INVERSE\r\nC OF ITSELF.\r\nC\r\nC WSAVE CONTAINS INITIALIZATION CALCULATIONS WHICH MUST NOT BE\r\nC DESTROYED BETWEEN CALLS OF COST.\r\nC\r\n SUBROUTINE COST (N,X,WSAVE)\r\n IMPLICIT_STATEMENT\r\n DIMENSION X(*) ,WSAVE(*)\r\nC\r\n NM1 = N-1\r\n NP1 = N+1\r\n NS2 = N/2\r\n IF (N-2) 106,101,102\r\n 101 X1H = X(1)+X(2)\r\n X(2) = X(1)-X(2)\r\n X(1) = X1H\r\n RETURN\r\n 102 IF (N .GT. 3) GO TO 103\r\n X1P3 = X(1)+X(3)\r\n TX2 = X(2)+X(2)\r\n X(2) = X(1)-X(3)\r\n X(1) = X1P3+TX2\r\n X(3) = X1P3-TX2\r\n RETURN\r\n 103 C1 = X(1)-X(N)\r\n X(1) = X(1)+X(N)\r\n DO 104 K=2,NS2\r\n KC = NP1-K\r\n T1 = X(K)+X(KC)\r\n T2 = X(K)-X(KC)\r\n C1 = C1+WSAVE(KC)*T2\r\n T2 = WSAVE(K)*T2\r\n X(K) = T1-T2\r\n X(KC) = T1+T2\r\n 104 CONTINUE\r\n MODN = MOD(N,2)\r\n IF (MODN .NE. 0) X(NS2+1) = X(NS2+1)+X(NS2+1)\r\n CALL RFFTF (NM1,X,WSAVE(N+1))\r\n XIM2 = X(2)\r\n X(2) = C1\r\n DO 105 I=4,N,2\r\n XI = X(I)\r\n X(I) = X(I-2)-X(I-1)\r\n X(I-1) = XIM2\r\n XIM2 = XI\r\n 105 CONTINUE\r\n IF (MODN .NE. 0) X(N) = XIM2\r\n 106 RETURN\r\n END\r\n\r\n\r\nC SUBROUTINE RFFTF(N,R,WSAVE)\r\nC\r\nC SUBROUTINE RFFTF COMPUTES THE FOURIER COEFFICIENTS OF A REAL\r\nC PERODIC SEQUENCE (FOURIER ANALYSIS). THE TRANSFORM IS DEFINED\r\nC BELOW AT OUTPUT PARAMETER R.\r\nC\r\nC INPUT PARAMETERS\r\nC\r\nC N THE LENGTH OF THE ARRAY R TO BE TRANSFORMED. THE METHOD\r\nC IS MOST EFFICIENT WHEN N IS A PRODUCT OF SMALL PRIMES.\r\nC N MAY CHANGE SO LONG AS DIFFERENT WORK ARRAYS ARE PROVIDED\r\nC\r\nC R A REAL ARRAY OF LENGTH N WHICH CONTAINS THE SEQUENCE\r\nC TO BE TRANSFORMED\r\nC\r\nC WSAVE A WORK ARRAY WHICH MUST BE DIMENSIONED AT LEAST 2*N+15.\r\nC IN THE PROGRAM THAT CALLS RFFTF. THE WSAVE ARRAY MUST BE\r\nC INITIALIZED BY CALLING SUBROUTINE RFFTI(N,WSAVE) AND A\r\nC DIFFERENT WSAVE ARRAY MUST BE USED FOR EACH DIFFERENT\r\nC VALUE OF N. THIS INITIALIZATION DOES NOT HAVE TO BE\r\nC REPEATED SO LONG AS N REMAINS UNCHANGED THUS SUBSEQUENT\r\nC TRANSFORMS CAN BE OBTAINED FASTER THAN THE FIRST.\r\nC THE SAME WSAVE ARRAY CAN BE USED BY RFFTF AND RFFTB.\r\nC\r\nC\r\nC OUTPUT PARAMETERS\r\nC\r\nC R R(1) = THE SUM FROM I=1 TO I=N OF R(I)\r\nC\r\nC IF N IS EVEN SET L =N/2 , IF N IS ODD SET L = (N+1)/2\r\nC\r\nC THEN FOR K = 2,...,L\r\nC\r\nC R(2*K-2) = THE SUM FROM I = 1 TO I = N OF\r\nC\r\nC R(I)*COS((K-1)*(I-1)*2*PI/N)\r\nC\r\nC R(2*K-1) = THE SUM FROM I = 1 TO I = N OF\r\nC\r\nC -R(I)*SIN((K-1)*(I-1)*2*PI/N)\r\nC\r\nC IF N IS EVEN\r\nC\r\nC R(N) = THE SUM FROM I = 1 TO I = N OF\r\nC\r\nC (-1)**(I-1)*R(I)\r\nC\r\nC ***** NOTE\r\nC THIS TRANSFORM IS UNNORMALIZED SINCE A CALL OF RFFTF\r\nC FOLLOWED BY A CALL OF RFFTB WILL MULTIPLY THE INPUT\r\nC SEQUENCE BY N.\r\nC\r\nC WSAVE CONTAINS RESULTS WHICH MUST NOT BE DESTROYED BETWEEN\r\nC CALLS OF RFFTF OR RFFTB.\r\nC\r\n SUBROUTINE RFFTF (N,R,WSAVE)\r\n IMPLICIT_STATEMENT\r\n DIMENSION R(*) ,WSAVE(*)\r\nC\r\n IF (N .EQ. 1) RETURN\r\n CALL RFFTF1 (N,R,WSAVE,WSAVE(N+1),WSAVE(2*N+1))\r\n RETURN\r\n END\r\n SUBROUTINE RFFTF1 (N,C,CH,WA,IFAC)\r\n IMPLICIT_STATEMENT\r\n!bjj START (fix for compatibility in double precision):\r\n! also note I added nint() around places where IFAC is on the right-hand side of the equation\r\n! DIMENSION CH(*) ,C(*) ,WA(*) ,IFAC(*)\r\n DIMENSION CH(*) ,C(*) ,WA(*)\r\n IFAC_TYPE, DIMENSION(*) :: IFAC\r\n!bjj End\r\n NF = nint(IFAC(2))\r\n NA = 1\r\n L2 = N\r\n IW = N\r\n DO 111 K1=1,NF\r\n KH = NF-K1\r\n IP = nint(IFAC(KH+3))\r\n L1 = L2/IP\r\n IDO = N/L2\r\n IDL1 = IDO*L1\r\n IW = IW-(IP-1)*IDO\r\n NA = 1-NA\r\n IF (IP .NE. 4) GO TO 102\r\n IX2 = IW+IDO\r\n IX3 = IX2+IDO\r\n IF (NA .NE. 0) GO TO 101\r\n CALL RADF4 (IDO,L1,C,CH,WA(IW),WA(IX2),WA(IX3))\r\n GO TO 110\r\n 101 CALL RADF4 (IDO,L1,CH,C,WA(IW),WA(IX2),WA(IX3))\r\n GO TO 110\r\n 102 IF (IP .NE. 2) GO TO 104\r\n IF (NA .NE. 0) GO TO 103\r\n CALL RADF2 (IDO,L1,C,CH,WA(IW))\r\n GO TO 110\r\n 103 CALL RADF2 (IDO,L1,CH,C,WA(IW))\r\n GO TO 110\r\n 104 IF (IP .NE. 3) GO TO 106\r\n IX2 = IW+IDO\r\n IF (NA .NE. 0) GO TO 105\r\n CALL RADF3 (IDO,L1,C,CH,WA(IW),WA(IX2))\r\n GO TO 110\r\n 105 CALL RADF3 (IDO,L1,CH,C,WA(IW),WA(IX2))\r\n GO TO 110\r\n 106 IF (IP .NE. 5) GO TO 108\r\n IX2 = IW+IDO\r\n IX3 = IX2+IDO\r\n IX4 = IX3+IDO\r\n IF (NA .NE. 0) GO TO 107\r\n CALL RADF5 (IDO,L1,C,CH,WA(IW),WA(IX2),WA(IX3),WA(IX4))\r\n GO TO 110\r\n 107 CALL RADF5 (IDO,L1,CH,C,WA(IW),WA(IX2),WA(IX3),WA(IX4))\r\n GO TO 110\r\n 108 IF (IDO .EQ. 1) NA = 1-NA\r\n IF (NA .NE. 0) GO TO 109\r\n CALL RADFG (IDO,IP,L1,IDL1,C,C,C,CH,CH,WA(IW))\r\n NA = 1\r\n GO TO 110\r\n 109 CALL RADFG (IDO,IP,L1,IDL1,CH,CH,CH,C,C,WA(IW))\r\n NA = 0\r\n 110 L2 = L1\r\n 111 CONTINUE\r\n IF (NA .EQ. 1) RETURN\r\n DO 112 I=1,N\r\n C(I) = CH(I)\r\n 112 CONTINUE\r\n RETURN\r\n END\r\n\r\n\r\n SUBROUTINE RADF2 (IDO,L1,CC,CH,WA1)\r\n IMPLICIT_STATEMENT\r\n DIMENSION CH(IDO,2,L1) ,CC(IDO,L1,2) ,\r\n 1 WA1(*)\r\n DO 101 K=1,L1\r\n CH(1,1,K) = CC(1,K,1)+CC(1,K,2)\r\n CH(IDO,2,K) = CC(1,K,1)-CC(1,K,2)\r\n 101 CONTINUE\r\n IF (IDO-2) 107,105,102\r\n 102 IDP2 = IDO+2\r\n DO 104 K=1,L1\r\n DO 103 I=3,IDO,2\r\n IC = IDP2-I\r\n TR2 = WA1(I-2)*CC(I-1,K,2)+WA1(I-1)*CC(I,K,2)\r\n TI2 = WA1(I-2)*CC(I,K,2)-WA1(I-1)*CC(I-1,K,2)\r\n CH(I,1,K) = CC(I,K,1)+TI2\r\n CH(IC,2,K) = TI2-CC(I,K,1)\r\n CH(I-1,1,K) = CC(I-1,K,1)+TR2\r\n CH(IC-1,2,K) = CC(I-1,K,1)-TR2\r\n 103 CONTINUE\r\n 104 CONTINUE\r\n IF (MOD(IDO,2) .EQ. 1) RETURN\r\n 105 DO 106 K=1,L1\r\n CH(1,2,K) = -CC(IDO,K,2)\r\n CH(IDO,1,K) = CC(IDO,K,1)\r\n 106 CONTINUE\r\n 107 RETURN\r\n END\r\n\r\n\r\n SUBROUTINE RADF3 (IDO,L1,CC,CH,WA1,WA2)\r\n IMPLICIT_STATEMENT\r\n DIMENSION CH(IDO,3,L1) ,CC(IDO,L1,3) ,\r\n 1 WA1(*) ,WA2(*)\r\n DATA TAUR,TAUI /-.5,.866025403784439/\r\n DO 101 K=1,L1\r\n CR2 = CC(1,K,2)+CC(1,K,3)\r\n CH(1,1,K) = CC(1,K,1)+CR2\r\n CH(1,3,K) = TAUI*(CC(1,K,3)-CC(1,K,2))\r\n CH(IDO,2,K) = CC(1,K,1)+TAUR*CR2\r\n 101 CONTINUE\r\n IF (IDO .EQ. 1) RETURN\r\n IDP2 = IDO+2\r\n DO 103 K=1,L1\r\n DO 102 I=3,IDO,2\r\n IC = IDP2-I\r\n DR2 = WA1(I-2)*CC(I-1,K,2)+WA1(I-1)*CC(I,K,2)\r\n DI2 = WA1(I-2)*CC(I,K,2)-WA1(I-1)*CC(I-1,K,2)\r\n DR3 = WA2(I-2)*CC(I-1,K,3)+WA2(I-1)*CC(I,K,3)\r\n DI3 = WA2(I-2)*CC(I,K,3)-WA2(I-1)*CC(I-1,K,3)\r\n CR2 = DR2+DR3\r\n CI2 = DI2+DI3\r\n CH(I-1,1,K) = CC(I-1,K,1)+CR2\r\n CH(I,1,K) = CC(I,K,1)+CI2\r\n TR2 = CC(I-1,K,1)+TAUR*CR2\r\n TI2 = CC(I,K,1)+TAUR*CI2\r\n TR3 = TAUI*(DI2-DI3)\r\n TI3 = TAUI*(DR3-DR2)\r\n CH(I-1,3,K) = TR2+TR3\r\n CH(IC-1,2,K) = TR2-TR3\r\n CH(I,3,K) = TI2+TI3\r\n CH(IC,2,K) = TI3-TI2\r\n 102 CONTINUE\r\n 103 CONTINUE\r\n RETURN\r\n END\r\n\r\n\r\n SUBROUTINE RADF4 (IDO,L1,CC,CH,WA1,WA2,WA3)\r\n IMPLICIT_STATEMENT\r\n DIMENSION CC(IDO,L1,4) ,CH(IDO,4,L1) ,\r\n 1 WA1(*) ,WA2(*) ,WA3(*)\r\n DATA HSQT2 /.7071067811865475/\r\n DO 101 K=1,L1\r\n TR1 = CC(1,K,2)+CC(1,K,4)\r\n TR2 = CC(1,K,1)+CC(1,K,3)\r\n CH(1,1,K) = TR1+TR2\r\n CH(IDO,4,K) = TR2-TR1\r\n CH(IDO,2,K) = CC(1,K,1)-CC(1,K,3)\r\n CH(1,3,K) = CC(1,K,4)-CC(1,K,2)\r\n 101 CONTINUE\r\n IF (IDO-2) 107,105,102\r\n 102 IDP2 = IDO+2\r\n DO 104 K=1,L1\r\n DO 103 I=3,IDO,2\r\n IC = IDP2-I\r\n CR2 = WA1(I-2)*CC(I-1,K,2)+WA1(I-1)*CC(I,K,2)\r\n CI2 = WA1(I-2)*CC(I,K,2)-WA1(I-1)*CC(I-1,K,2)\r\n CR3 = WA2(I-2)*CC(I-1,K,3)+WA2(I-1)*CC(I,K,3)\r\n CI3 = WA2(I-2)*CC(I,K,3)-WA2(I-1)*CC(I-1,K,3)\r\n CR4 = WA3(I-2)*CC(I-1,K,4)+WA3(I-1)*CC(I,K,4)\r\n CI4 = WA3(I-2)*CC(I,K,4)-WA3(I-1)*CC(I-1,K,4)\r\n TR1 = CR2+CR4\r\n TR4 = CR4-CR2\r\n TI1 = CI2+CI4\r\n TI4 = CI2-CI4\r\n TI2 = CC(I,K,1)+CI3\r\n TI3 = CC(I,K,1)-CI3\r\n TR2 = CC(I-1,K,1)+CR3\r\n TR3 = CC(I-1,K,1)-CR3\r\n CH(I-1,1,K) = TR1+TR2\r\n CH(IC-1,4,K) = TR2-TR1\r\n CH(I,1,K) = TI1+TI2\r\n CH(IC,4,K) = TI1-TI2\r\n CH(I-1,3,K) = TI4+TR3\r\n CH(IC-1,2,K) = TR3-TI4\r\n CH(I,3,K) = TR4+TI3\r\n CH(IC,2,K) = TR4-TI3\r\n 103 CONTINUE\r\n 104 CONTINUE\r\n IF (MOD(IDO,2) .EQ. 1) RETURN\r\n 105 CONTINUE\r\n DO 106 K=1,L1\r\n TI1 = -HSQT2*(CC(IDO,K,2)+CC(IDO,K,4))\r\n TR1 = HSQT2*(CC(IDO,K,2)-CC(IDO,K,4))\r\n CH(IDO,1,K) = TR1+CC(IDO,K,1)\r\n CH(IDO,3,K) = CC(IDO,K,1)-TR1\r\n CH(1,2,K) = TI1-CC(IDO,K,3)\r\n CH(1,4,K) = TI1+CC(IDO,K,3)\r\n 106 CONTINUE\r\n 107 RETURN\r\n END\r\n\r\n\r\n SUBROUTINE RADF5 (IDO,L1,CC,CH,WA1,WA2,WA3,WA4)\r\n IMPLICIT_STATEMENT\r\n DIMENSION CC(IDO,L1,5) ,CH(IDO,5,L1) ,\r\n 1 WA1(*) ,WA2(*) ,WA3(*) ,WA4(*)\r\n DATA TR11,TI11,TR12,TI12 /.309016994374947,.951056516295154,\r\n 1-.809016994374947,.587785252292473/\r\n DO 101 K=1,L1\r\n CR2 = CC(1,K,5)+CC(1,K,2)\r\n CI5 = CC(1,K,5)-CC(1,K,2)\r\n CR3 = CC(1,K,4)+CC(1,K,3)\r\n CI4 = CC(1,K,4)-CC(1,K,3)\r\n CH(1,1,K) = CC(1,K,1)+CR2+CR3\r\n CH(IDO,2,K) = CC(1,K,1)+TR11*CR2+TR12*CR3\r\n CH(1,3,K) = TI11*CI5+TI12*CI4\r\n CH(IDO,4,K) = CC(1,K,1)+TR12*CR2+TR11*CR3\r\n CH(1,5,K) = TI12*CI5-TI11*CI4\r\n 101 CONTINUE\r\n IF (IDO .EQ. 1) RETURN\r\n IDP2 = IDO+2\r\n DO 103 K=1,L1\r\n DO 102 I=3,IDO,2\r\n IC = IDP2-I\r\n DR2 = WA1(I-2)*CC(I-1,K,2)+WA1(I-1)*CC(I,K,2)\r\n DI2 = WA1(I-2)*CC(I,K,2)-WA1(I-1)*CC(I-1,K,2)\r\n DR3 = WA2(I-2)*CC(I-1,K,3)+WA2(I-1)*CC(I,K,3)\r\n DI3 = WA2(I-2)*CC(I,K,3)-WA2(I-1)*CC(I-1,K,3)\r\n DR4 = WA3(I-2)*CC(I-1,K,4)+WA3(I-1)*CC(I,K,4)\r\n DI4 = WA3(I-2)*CC(I,K,4)-WA3(I-1)*CC(I-1,K,4)\r\n DR5 = WA4(I-2)*CC(I-1,K,5)+WA4(I-1)*CC(I,K,5)\r\n DI5 = WA4(I-2)*CC(I,K,5)-WA4(I-1)*CC(I-1,K,5)\r\n CR2 = DR2+DR5\r\n CI5 = DR5-DR2\r\n CR5 = DI2-DI5\r\n CI2 = DI2+DI5\r\n CR3 = DR3+DR4\r\n CI4 = DR4-DR3\r\n CR4 = DI3-DI4\r\n CI3 = DI3+DI4\r\n CH(I-1,1,K) = CC(I-1,K,1)+CR2+CR3\r\n CH(I,1,K) = CC(I,K,1)+CI2+CI3\r\n TR2 = CC(I-1,K,1)+TR11*CR2+TR12*CR3\r\n TI2 = CC(I,K,1)+TR11*CI2+TR12*CI3\r\n TR3 = CC(I-1,K,1)+TR12*CR2+TR11*CR3\r\n TI3 = CC(I,K,1)+TR12*CI2+TR11*CI3\r\n TR5 = TI11*CR5+TI12*CR4\r\n TI5 = TI11*CI5+TI12*CI4\r\n TR4 = TI12*CR5-TI11*CR4\r\n TI4 = TI12*CI5-TI11*CI4\r\n CH(I-1,3,K) = TR2+TR5\r\n CH(IC-1,2,K) = TR2-TR5\r\n CH(I,3,K) = TI2+TI5\r\n CH(IC,2,K) = TI5-TI2\r\n CH(I-1,5,K) = TR3+TR4\r\n CH(IC-1,4,K) = TR3-TR4\r\n CH(I,5,K) = TI3+TI4\r\n CH(IC,4,K) = TI4-TI3\r\n 102 CONTINUE\r\n 103 CONTINUE\r\n RETURN\r\n END\r\n\r\n\r\n SUBROUTINE RADFG (IDO,IP,L1,IDL1,CC,C1,C2,CH,CH2,WA)\r\n IMPLICIT_STATEMENT\r\n DIMENSION CH(IDO,L1,IP) ,CC(IDO,IP,L1) ,\r\n 1 C1(IDO,L1,IP) ,C2(IDL1,IP),\r\n 2 CH2(IDL1,IP) ,WA(*)\r\n TPI = 2.0*PIMACH(DUM)\r\n ARG = TPI/FLOAT(IP)\r\n DCP = COS(ARG)\r\n DSP = SIN(ARG)\r\n IPPH = (IP+1)/2\r\n IPP2 = IP+2\r\n IDP2 = IDO+2\r\n NBD = (IDO-1)/2\r\n IF (IDO .EQ. 1) GO TO 119\r\n DO 101 IK=1,IDL1\r\n CH2(IK,1) = C2(IK,1)\r\n 101 CONTINUE\r\n DO 103 J=2,IP\r\n DO 102 K=1,L1\r\n CH(1,K,J) = C1(1,K,J)\r\n 102 CONTINUE\r\n 103 CONTINUE\r\n IF (NBD .GT. L1) GO TO 107\r\n IS = -IDO\r\n DO 106 J=2,IP\r\n IS = IS+IDO\r\n IDIJ = IS\r\n DO 105 I=3,IDO,2\r\n IDIJ = IDIJ+2\r\n DO 104 K=1,L1\r\n CH(I-1,K,J) = WA(IDIJ-1)*C1(I-1,K,J)+WA(IDIJ)*C1(I,K,J)\r\n CH(I,K,J) = WA(IDIJ-1)*C1(I,K,J)-WA(IDIJ)*C1(I-1,K,J)\r\n 104 CONTINUE\r\n 105 CONTINUE\r\n 106 CONTINUE\r\n GO TO 111\r\n 107 IS = -IDO\r\n DO 110 J=2,IP\r\n IS = IS+IDO\r\n DO 109 K=1,L1\r\n IDIJ = IS\r\n DO 108 I=3,IDO,2\r\n IDIJ = IDIJ+2\r\n CH(I-1,K,J) = WA(IDIJ-1)*C1(I-1,K,J)+WA(IDIJ)*C1(I,K,J)\r\n CH(I,K,J) = WA(IDIJ-1)*C1(I,K,J)-WA(IDIJ)*C1(I-1,K,J)\r\n 108 CONTINUE\r\n 109 CONTINUE\r\n 110 CONTINUE\r\n 111 IF (NBD .LT. L1) GO TO 115\r\n DO 114 J=2,IPPH\r\n JC = IPP2-J\r\n DO 113 K=1,L1\r\n DO 112 I=3,IDO,2\r\n C1(I-1,K,J) = CH(I-1,K,J)+CH(I-1,K,JC)\r\n C1(I-1,K,JC) = CH(I,K,J)-CH(I,K,JC)\r\n C1(I,K,J) = CH(I,K,J)+CH(I,K,JC)\r\n C1(I,K,JC) = CH(I-1,K,JC)-CH(I-1,K,J)\r\n 112 CONTINUE\r\n 113 CONTINUE\r\n 114 CONTINUE\r\n GO TO 121\r\n 115 DO 118 J=2,IPPH\r\n JC = IPP2-J\r\n DO 117 I=3,IDO,2\r\n DO 116 K=1,L1\r\n C1(I-1,K,J) = CH(I-1,K,J)+CH(I-1,K,JC)\r\n C1(I-1,K,JC) = CH(I,K,J)-CH(I,K,JC)\r\n C1(I,K,J) = CH(I,K,J)+CH(I,K,JC)\r\n C1(I,K,JC) = CH(I-1,K,JC)-CH(I-1,K,J)\r\n 116 CONTINUE\r\n 117 CONTINUE\r\n 118 CONTINUE\r\n GO TO 121\r\n 119 DO 120 IK=1,IDL1\r\n C2(IK,1) = CH2(IK,1)\r\n 120 CONTINUE\r\n 121 DO 123 J=2,IPPH\r\n JC = IPP2-J\r\n DO 122 K=1,L1\r\n C1(1,K,J) = CH(1,K,J)+CH(1,K,JC)\r\n C1(1,K,JC) = CH(1,K,JC)-CH(1,K,J)\r\n 122 CONTINUE\r\n 123 CONTINUE\r\nC\r\n AR1 = 1.\r\n AI1 = 0.\r\n DO 127 L=2,IPPH\r\n LC = IPP2-L\r\n AR1H = DCP*AR1-DSP*AI1\r\n AI1 = DCP*AI1+DSP*AR1\r\n AR1 = AR1H\r\n DO 124 IK=1,IDL1\r\n CH2(IK,L) = C2(IK,1)+AR1*C2(IK,2)\r\n CH2(IK,LC) = AI1*C2(IK,IP)\r\n 124 CONTINUE\r\n DC2 = AR1\r\n DS2 = AI1\r\n AR2 = AR1\r\n AI2 = AI1\r\n DO 126 J=3,IPPH\r\n JC = IPP2-J\r\n AR2H = DC2*AR2-DS2*AI2\r\n AI2 = DC2*AI2+DS2*AR2\r\n AR2 = AR2H\r\n DO 125 IK=1,IDL1\r\n CH2(IK,L) = CH2(IK,L)+AR2*C2(IK,J)\r\n CH2(IK,LC) = CH2(IK,LC)+AI2*C2(IK,JC)\r\n 125 CONTINUE\r\n 126 CONTINUE\r\n 127 CONTINUE\r\n DO 129 J=2,IPPH\r\n DO 128 IK=1,IDL1\r\n CH2(IK,1) = CH2(IK,1)+C2(IK,J)\r\n 128 CONTINUE\r\n 129 CONTINUE\r\nC\r\n IF (IDO .LT. L1) GO TO 132\r\n DO 131 K=1,L1\r\n DO 130 I=1,IDO\r\n CC(I,1,K) = CH(I,K,1)\r\n 130 CONTINUE\r\n 131 CONTINUE\r\n GO TO 135\r\n 132 DO 134 I=1,IDO\r\n DO 133 K=1,L1\r\n CC(I,1,K) = CH(I,K,1)\r\n 133 CONTINUE\r\n 134 CONTINUE\r\n 135 DO 137 J=2,IPPH\r\n JC = IPP2-J\r\n J2 = J+J\r\n DO 136 K=1,L1\r\n CC(IDO,J2-2,K) = CH(1,K,J)\r\n CC(1,J2-1,K) = CH(1,K,JC)\r\n 136 CONTINUE\r\n 137 CONTINUE\r\n IF (IDO .EQ. 1) RETURN\r\n IF (NBD .LT. L1) GO TO 141\r\n DO 140 J=2,IPPH\r\n JC = IPP2-J\r\n J2 = J+J\r\n DO 139 K=1,L1\r\n DO 138 I=3,IDO,2\r\n IC = IDP2-I\r\n CC(I-1,J2-1,K) = CH(I-1,K,J)+CH(I-1,K,JC)\r\n CC(IC-1,J2-2,K) = CH(I-1,K,J)-CH(I-1,K,JC)\r\n CC(I,J2-1,K) = CH(I,K,J)+CH(I,K,JC)\r\n CC(IC,J2-2,K) = CH(I,K,JC)-CH(I,K,J)\r\n 138 CONTINUE\r\n 139 CONTINUE\r\n 140 CONTINUE\r\n RETURN\r\n 141 DO 144 J=2,IPPH\r\n JC = IPP2-J\r\n J2 = J+J\r\n DO 143 I=3,IDO,2\r\n IC = IDP2-I\r\n DO 142 K=1,L1\r\n CC(I-1,J2-1,K) = CH(I-1,K,J)+CH(I-1,K,JC)\r\n CC(IC-1,J2-2,K) = CH(I-1,K,J)-CH(I-1,K,JC)\r\n CC(I,J2-1,K) = CH(I,K,J)+CH(I,K,JC)\r\n CC(IC,J2-2,K) = CH(I,K,JC)-CH(I,K,J)\r\n 142 CONTINUE\r\n 143 CONTINUE\r\n 144 CONTINUE\r\n RETURN\r\n END\r\n\r\n\r\nC SUBROUTINE SINTI(N,WSAVE)\r\nC\r\nC SUBROUTINE SINTI INITIALIZES THE ARRAY WSAVE WHICH IS USED IN\r\nC SUBROUTINE SINT. THE PRIME FACTORIZATION OF N TOGETHER WITH\r\nC A TABULATION OF THE TRIGONOMETRIC FUNCTIONS ARE COMPUTED AND\r\nC STORED IN WSAVE.\r\nC\r\nC INPUT PARAMETER\r\nC\r\nC N THE LENGTH OF THE SEQUENCE TO BE TRANSFORMED. THE METHOD\r\nC IS MOST EFFICIENT WHEN N+1 IS A PRODUCT OF SMALL PRIMES.\r\nC\r\nC OUTPUT PARAMETER\r\nC\r\nC WSAVE A WORK ARRAY WITH AT LEAST INT(2.5*N+15) LOCATIONS.\r\nC DIFFERENT WSAVE ARRAYS ARE REQUIRED FOR DIFFERENT VALUES\r\nC OF N. THE CONTENTS OF WSAVE MUST NOT BE CHANGED BETWEEN\r\nC CALLS OF SINT.\r\nC\r\n SUBROUTINE SINTI (N,WSAVE)\r\n IMPLICIT_STATEMENT\r\n DIMENSION WSAVE(*)\r\nC\r\n PI = PIMACH(DUM)\r\n IF (N .LE. 1) RETURN\r\n NS2 = N/2\r\n NP1 = N+1\r\n DT = PI/FLOAT(NP1)\r\n DO 101 K=1,NS2\r\n WSAVE(K) = 2.*SIN(K*DT)\r\n 101 CONTINUE\r\n CALL RFFTI (NP1,WSAVE(NS2+1))\r\n RETURN\r\n END\r\n\r\n\r\nC SUBROUTINE SINT(N,X,WSAVE)\r\nC\r\nC SUBROUTINE SINT COMPUTES THE DISCRETE FOURIER SINE TRANSFORM\r\nC OF AN ODD SEQUENCE X(I). THE TRANSFORM IS DEFINED BELOW AT\r\nC OUTPUT PARAMETER X.\r\nC\r\nC SINT IS THE UNNORMALIZED INVERSE OF ITSELF SINCE A CALL OF SINT\r\nC FOLLOWED BY ANOTHER CALL OF SINT WILL MULTIPLY THE INPUT SEQUENCE\r\nC X BY 2*(N+1).\r\nC\r\nC THE ARRAY WSAVE WHICH IS USED BY SUBROUTINE SINT MUST BE\r\nC INITIALIZED BY CALLING SUBROUTINE SINTI(N,WSAVE).\r\nC\r\nC INPUT PARAMETERS\r\nC\r\nC N THE LENGTH OF THE SEQUENCE TO BE TRANSFORMED. THE METHOD\r\nC IS MOST EFFICIENT WHEN N+1 IS THE PRODUCT OF SMALL PRIMES.\r\nC\r\nC X AN ARRAY WHICH CONTAINS THE SEQUENCE TO BE TRANSFORMED\r\nC\r\nC\r\nC WSAVE A WORK ARRAY WITH DIMENSION AT LEAST INT(2.5*N+15)\r\nC IN THE PROGRAM THAT CALLS SINT. THE WSAVE ARRAY MUST BE\r\nC INITIALIZED BY CALLING SUBROUTINE SINTI(N,WSAVE) AND A\r\nC DIFFERENT WSAVE ARRAY MUST BE USED FOR EACH DIFFERENT\r\nC VALUE OF N. THIS INITIALIZATION DOES NOT HAVE TO BE\r\nC REPEATED SO LONG AS N REMAINS UNCHANGED THUS SUBSEQUENT\r\nC TRANSFORMS CAN BE OBTAINED FASTER THAN THE FIRST.\r\nC\r\nC OUTPUT PARAMETERS\r\nC\r\nC X FOR I=1,...,N\r\nC\r\nC X(I)= THE SUM FROM K=1 TO K=N\r\nC\r\nC 2*X(K)*SIN(K*I*PI/(N+1))\r\nC\r\nC A CALL OF SINT FOLLOWED BY ANOTHER CALL OF\r\nC SINT WILL MULTIPLY THE SEQUENCE X BY 2*(N+1).\r\nC HENCE SINT IS THE UNNORMALIZED INVERSE\r\nC OF ITSELF.\r\nC\r\nC WSAVE CONTAINS INITIALIZATION CALCULATIONS WHICH MUST NOT BE\r\nC DESTROYED BETWEEN CALLS OF SINT.\r\nC\r\n SUBROUTINE SINT (N,X,WSAVE)\r\n IMPLICIT_STATEMENT\r\n DIMENSION X(*) ,WSAVE(*)\r\nC\r\n NP1 = N+1\r\n IW1 = N/2+1\r\n IW2 = IW1+NP1\r\n IW3 = IW2+NP1\r\n CALL SINT1(N,X,WSAVE,WSAVE(IW1),WSAVE(IW2),WSAVE(IW3))\r\n RETURN\r\n END\r\n\r\n\r\n SUBROUTINE SINT1(N,WAR,WAS,XH,X,IFAC)\r\n IMPLICIT_STATEMENT\r\n!!bjj START (fix for compatibility in double precision):\r\n! DIMENSION WAR(*),WAS(*),X(*),XH(*),IFAC(*)\r\n DIMENSION WAR(*),WAS(*),X(*),XH(*)\r\n IFAC_TYPE, DIMENSION(*) :: IFAC\r\n!!bjj End \r\n DATA SQRT3 /1.73205080756888/\r\n DO 100 I=1,N\r\n XH(I) = WAR(I)\r\n WAR(I) = X(I)\r\n 100 CONTINUE\r\n IF (N-2) 101,102,103\r\n 101 XH(1) = XH(1)+XH(1)\r\n GO TO 106\r\n 102 XHOLD = SQRT3*(XH(1)+XH(2))\r\n XH(2) = SQRT3*(XH(1)-XH(2))\r\n XH(1) = XHOLD\r\n GO TO 106\r\n 103 NP1 = N+1\r\n NS2 = N/2\r\n X(1) = 0.\r\n DO 104 K=1,NS2\r\n KC = NP1-K\r\n T1 = XH(K)-XH(KC)\r\n T2 = WAS(K)*(XH(K)+XH(KC))\r\n X(K+1) = T1+T2\r\n X(KC+1) = T2-T1\r\n 104 CONTINUE\r\n MODN = MOD(N,2)\r\n IF (MODN .NE. 0) X(NS2+2) = 4.*XH(NS2+1)\r\n CALL RFFTF1 (NP1,X,XH,WAR,IFAC)\r\n XH(1) = .5*X(1)\r\n DO 105 I=3,N,2\r\n XH(I-1) = -X(I)\r\n XH(I) = XH(I-2)+X(I-1)\r\n 105 CONTINUE\r\n IF (MODN .NE. 0) GO TO 106\r\n XH(N) = -X(N+1)\r\n 106 DO 107 I=1,N\r\n X(I) = WAR(I)\r\n WAR(I) = XH(I)\r\n 107 CONTINUE\r\n RETURN\r\n END\r\n\r\n\r\nC **********************************************************************\r\nC\r\nC SUBROUTINE CFFTI(N,WSAVE)\r\nC\r\nC SUBROUTINE CFFTI INITIALIZES THE ARRAY WSAVE WHICH IS USED IN\r\nC BOTH CFFTF AND CFFTB. THE PRIME FACTORIZATION OF N TOGETHER WITH\r\nC A TABULATION OF THE TRIGONOMETRIC FUNCTIONS ARE COMPUTED AND\r\nC STORED IN WSAVE.\r\nC\r\nC INPUT PARAMETER\r\nC\r\nC N THE LENGTH OF THE SEQUENCE TO BE TRANSFORMED\r\nC\r\nC OUTPUT PARAMETER\r\nC\r\nC WSAVE A WORK ARRAY WHICH MUST BE DIMENSIONED AT LEAST 4*N+15\r\nC THE SAME WORK ARRAY CAN BE USED FOR BOTH CFFTF AND CFFTB\r\nC AS LONG AS N REMAINS UNCHANGED. DIFFERENT WSAVE ARRAYS\r\nC ARE REQUIRED FOR DIFFERENT VALUES OF N. THE CONTENTS OF\r\nC WSAVE MUST NOT BE CHANGED BETWEEN CALLS OF CFFTF OR CFFTB.\r\nC\r\nC **********************************************************************\r\n SUBROUTINE CFFTI (N,WSAVE)\r\n IMPLICIT_STATEMENT\r\n DIMENSION WSAVE(*)\r\nC\r\n IF (N .EQ. 1) RETURN\r\n IW1 = N+N+1\r\n IW2 = IW1+N+N\r\n CALL CFFTI1 (N,WSAVE(IW1),WSAVE(IW2))\r\n RETURN\r\n END\r\n\r\n\r\n SUBROUTINE CFFTI1 (N,WA,IFAC)\r\n IMPLICIT_STATEMENT\r\n IFAC_TYPE, DIMENSION(*) :: IFAC\r\n DIMENSION WA(*) ,NTRYH(4)\r\n DATA NTRYH(1),NTRYH(2),NTRYH(3),NTRYH(4)/3,4,2,5/\r\n NL = N\r\n NF = 0\r\n J = 0\r\n 101 J = J+1\r\n IF (J-4) 102,102,103\r\n 102 NTRY = NTRYH(J)\r\n GO TO 104\r\n 103 NTRY = NTRY+2\r\n 104 NQ = NL/NTRY\r\n NR = NL-NTRY*NQ\r\n IF (NR) 101,105,101\r\n 105 NF = NF+1\r\n IFAC(NF+2) = NTRY\r\n NL = NQ\r\n IF (NTRY .NE. 2) GO TO 107\r\n IF (NF .EQ. 1) GO TO 107\r\n DO 106 I=2,NF\r\n IB = NF-I+2\r\n IFAC(IB+2) = nint(IFAC(IB+1))\r\n 106 CONTINUE\r\n IFAC(3) = 2\r\n 107 IF (NL .NE. 1) GO TO 104\r\n IFAC(1) = N\r\n IFAC(2) = NF\r\n TPI = 2.*PIMACH(DUM)\r\n ARGH = TPI/FLOAT(N)\r\n I = 2\r\n L1 = 1\r\n DO 110 K1=1,NF\r\n IP = nint(IFAC(K1+2))\r\n LD = 0\r\n L2 = L1*IP\r\n IDO = N/L2\r\n IDOT = IDO+IDO+2\r\n IPM = IP-1\r\n DO 109 J=1,IPM\r\n I1 = I\r\n WA(I-1) = 1.\r\n WA(I) = 0.\r\n LD = LD+L1\r\n FI = 0.\r\n ARGLD = FLOAT(LD)*ARGH\r\n DO 108 II=4,IDOT,2\r\n I = I+2\r\n FI = FI+1.\r\n ARG = FI*ARGLD\r\n WA(I-1) = COS(ARG)\r\n WA(I) = SIN(ARG)\r\n 108 CONTINUE\r\n IF (IP .LE. 5) GO TO 109\r\n WA(I1-1) = WA(I-1)\r\n WA(I1) = WA(I)\r\n 109 CONTINUE\r\n L1 = L2\r\n 110 CONTINUE\r\n RETURN\r\n END\r\n\r\n\r\nC **********************************************************************\r\nC\r\nC SUBROUTINE CFFTB(N,C,WSAVE)\r\nC\r\nC SUBROUTINE CFFTB COMPUTES THE BACKWARD COMPLEX DISCRETE FOURIER\r\nC TRANSFORM (THE FOURIER SYNTHESIS). EQUIVALENTLY , CFFTB COMPUTES\r\nC A COMPLEX PERIODIC SEQUENCE FROM ITS FOURIER COEFFICIENTS.\r\nC THE TRANSFORM IS DEFINED BELOW AT OUTPUT PARAMETER C.\r\nC\r\nC A CALL OF CFFTF FOLLOWED BY A CALL OF CFFTB WILL MULTIPLY THE\r\nC SEQUENCE BY N.\r\nC\r\nC THE ARRAY WSAVE WHICH IS USED BY SUBROUTINE CFFTB MUST BE\r\nC INITIALIZED BY CALLING SUBROUTINE CFFTI(N,WSAVE).\r\nC\r\nC INPUT PARAMETERS\r\nC\r\nC\r\nC N THE LENGTH OF THE COMPLEX SEQUENCE C. THE METHOD IS\r\nC MORE EFFICIENT WHEN N IS THE PRODUCT OF SMALL PRIMES.\r\nC\r\nC C A COMPLEX ARRAY OF LENGTH N WHICH CONTAINS THE SEQUENCE\r\nC\r\nC WSAVE A REAL WORK ARRAY WHICH MUST BE DIMENSIONED AT LEAST 4N+15\r\nC IN THE PROGRAM THAT CALLS CFFTB. THE WSAVE ARRAY MUST BE\r\nC INITIALIZED BY CALLING SUBROUTINE CFFTI(N,WSAVE) AND A\r\nC DIFFERENT WSAVE ARRAY MUST BE USED FOR EACH DIFFERENT\r\nC VALUE OF N. THIS INITIALIZATION DOES NOT HAVE TO BE\r\nC REPEATED SO LONG AS N REMAINS UNCHANGED THUS SUBSEQUENT\r\nC TRANSFORMS CAN BE OBTAINED FASTER THAN THE FIRST.\r\nC THE SAME WSAVE ARRAY CAN BE USED BY CFFTF AND CFFTB.\r\nC\r\nC OUTPUT PARAMETERS\r\nC\r\nC C FOR J=1,...,N\r\nC\r\nC C(J)=THE SUM FROM K=1,...,N OF\r\nC\r\nC C(K)*EXP(I*(J-1)*(K-1)*2*PI/N)\r\nC\r\nC WHERE I=SQRT(-1)\r\nC\r\nC WSAVE CONTAINS INITIALIZATION CALCULATIONS WHICH MUST NOT BE\r\nC DESTROYED BETWEEN CALLS OF SUBROUTINE CFFTF OR CFFTB\r\nC **********************************************************************\r\n SUBROUTINE CFFTB (N,C,WSAVE)\r\n IMPLICIT_STATEMENT\r\n DIMENSION C(*) ,WSAVE(*)\r\nC\r\n IF (N .EQ. 1) RETURN\r\n IW1 = N+N+1\r\n IW2 = IW1+N+N\r\n CALL CFFTB1 (N,C,WSAVE,WSAVE(IW1),WSAVE(IW2))\r\n RETURN\r\n END\r\n\r\n\r\n SUBROUTINE CFFTB1 (N,C,CH,WA,IFAC)\r\n IMPLICIT_STATEMENT\r\n IFAC_TYPE, DIMENSION(*) :: IFAC\r\n DIMENSION CH(*) ,C(*) ,WA(*)\r\n NF = nint(IFAC(2))\r\n NA = 0\r\n L1 = 1\r\n IW = 1\r\n DO 116 K1=1,NF\r\n IP = nint(IFAC(K1+2))\r\n L2 = IP*L1\r\n IDO = N/L2\r\n IDOT = IDO+IDO\r\n IDL1 = IDOT*L1\r\n IF (IP .NE. 4) GO TO 103\r\n IX2 = IW+IDOT\r\n IX3 = IX2+IDOT\r\n IF (NA .NE. 0) GO TO 101\r\n CALL PASSB4 (IDOT,L1,C,CH,WA(IW),WA(IX2),WA(IX3))\r\n GO TO 102\r\n 101 CALL PASSB4 (IDOT,L1,CH,C,WA(IW),WA(IX2),WA(IX3))\r\n 102 NA = 1-NA\r\n GO TO 115\r\n 103 IF (IP .NE. 2) GO TO 106\r\n IF (NA .NE. 0) GO TO 104\r\n CALL PASSB2 (IDOT,L1,C,CH,WA(IW))\r\n GO TO 105\r\n 104 CALL PASSB2 (IDOT,L1,CH,C,WA(IW))\r\n 105 NA = 1-NA\r\n GO TO 115\r\n 106 IF (IP .NE. 3) GO TO 109\r\n IX2 = IW+IDOT\r\n IF (NA .NE. 0) GO TO 107\r\n CALL PASSB3 (IDOT,L1,C,CH,WA(IW),WA(IX2))\r\n GO TO 108\r\n 107 CALL PASSB3 (IDOT,L1,CH,C,WA(IW),WA(IX2))\r\n 108 NA = 1-NA\r\n GO TO 115\r\n 109 IF (IP .NE. 5) GO TO 112\r\n IX2 = IW+IDOT\r\n IX3 = IX2+IDOT\r\n IX4 = IX3+IDOT\r\n IF (NA .NE. 0) GO TO 110\r\n CALL PASSB5 (IDOT,L1,C,CH,WA(IW),WA(IX2),WA(IX3),WA(IX4))\r\n GO TO 111\r\n 110 CALL PASSB5 (IDOT,L1,CH,C,WA(IW),WA(IX2),WA(IX3),WA(IX4))\r\n 111 NA = 1-NA\r\n GO TO 115\r\n 112 IF (NA .NE. 0) GO TO 113\r\n CALL PASSB (NAC,IDOT,IP,L1,IDL1,C,C,C,CH,CH,WA(IW))\r\n GO TO 114\r\n 113 CALL PASSB (NAC,IDOT,IP,L1,IDL1,CH,CH,CH,C,C,WA(IW))\r\n 114 IF (NAC .NE. 0) NA = 1-NA\r\n 115 L1 = L2\r\n IW = IW+(IP-1)*IDOT\r\n 116 CONTINUE\r\n IF (NA .EQ. 0) RETURN\r\n N2 = N+N\r\n DO 117 I=1,N2\r\n C(I) = CH(I)\r\n 117 CONTINUE\r\n RETURN\r\n END\r\n SUBROUTINE PASSB2 (IDO,L1,CC,CH,WA1)\r\n IMPLICIT_STATEMENT\r\n DIMENSION CC(IDO,2,L1) ,CH(IDO,L1,2) ,\r\n 1 WA1(*)\r\n!ADP: change WA1(1) to WA1(*)\r\n IF (IDO .GT. 2) GO TO 102\r\n DO 101 K=1,L1\r\n CH(1,K,1) = CC(1,1,K)+CC(1,2,K)\r\n CH(1,K,2) = CC(1,1,K)-CC(1,2,K)\r\n CH(2,K,1) = CC(2,1,K)+CC(2,2,K)\r\n CH(2,K,2) = CC(2,1,K)-CC(2,2,K)\r\n 101 CONTINUE\r\n RETURN\r\n 102 DO 104 K=1,L1\r\n DO 103 I=2,IDO,2\r\n CH(I-1,K,1) = CC(I-1,1,K)+CC(I-1,2,K)\r\n TR2 = CC(I-1,1,K)-CC(I-1,2,K)\r\n CH(I,K,1) = CC(I,1,K)+CC(I,2,K)\r\n TI2 = CC(I,1,K)-CC(I,2,K)\r\n CH(I,K,2) = WA1(I-1)*TI2+WA1(I)*TR2\r\n CH(I-1,K,2) = WA1(I-1)*TR2-WA1(I)*TI2\r\n 103 CONTINUE\r\n 104 CONTINUE\r\n RETURN\r\n END\r\n SUBROUTINE PASSB3 (IDO,L1,CC,CH,WA1,WA2)\r\n IMPLICIT_STATEMENT\r\n DIMENSION CC(IDO,3,L1) ,CH(IDO,L1,3) ,\r\n 1 WA1(*) ,WA2(*)\r\n DATA TAUR,TAUI /-.5,.866025403784439/\r\n IF (IDO .NE. 2) GO TO 102\r\n DO 101 K=1,L1\r\n TR2 = CC(1,2,K)+CC(1,3,K)\r\n CR2 = CC(1,1,K)+TAUR*TR2\r\n CH(1,K,1) = CC(1,1,K)+TR2\r\n TI2 = CC(2,2,K)+CC(2,3,K)\r\n CI2 = CC(2,1,K)+TAUR*TI2\r\n CH(2,K,1) = CC(2,1,K)+TI2\r\n CR3 = TAUI*(CC(1,2,K)-CC(1,3,K))\r\n CI3 = TAUI*(CC(2,2,K)-CC(2,3,K))\r\n CH(1,K,2) = CR2-CI3\r\n CH(1,K,3) = CR2+CI3\r\n CH(2,K,2) = CI2+CR3\r\n CH(2,K,3) = CI2-CR3\r\n 101 CONTINUE\r\n RETURN\r\n 102 DO 104 K=1,L1\r\n DO 103 I=2,IDO,2\r\n TR2 = CC(I-1,2,K)+CC(I-1,3,K)\r\n CR2 = CC(I-1,1,K)+TAUR*TR2\r\n CH(I-1,K,1) = CC(I-1,1,K)+TR2\r\n TI2 = CC(I,2,K)+CC(I,3,K)\r\n CI2 = CC(I,1,K)+TAUR*TI2\r\n CH(I,K,1) = CC(I,1,K)+TI2\r\n CR3 = TAUI*(CC(I-1,2,K)-CC(I-1,3,K))\r\n CI3 = TAUI*(CC(I,2,K)-CC(I,3,K))\r\n DR2 = CR2-CI3\r\n DR3 = CR2+CI3\r\n DI2 = CI2+CR3\r\n DI3 = CI2-CR3\r\n CH(I,K,2) = WA1(I-1)*DI2+WA1(I)*DR2\r\n CH(I-1,K,2) = WA1(I-1)*DR2-WA1(I)*DI2\r\n CH(I,K,3) = WA2(I-1)*DI3+WA2(I)*DR3\r\n CH(I-1,K,3) = WA2(I-1)*DR3-WA2(I)*DI3\r\n 103 CONTINUE\r\n 104 CONTINUE\r\n RETURN\r\n END\r\n SUBROUTINE PASSB4 (IDO,L1,CC,CH,WA1,WA2,WA3)\r\n IMPLICIT_STATEMENT\r\n DIMENSION CC(IDO,4,L1) ,CH(IDO,L1,4) ,\r\n 1 WA1(*) ,WA2(*) ,WA3(*)\r\n IF (IDO .NE. 2) GO TO 102\r\n DO 101 K=1,L1\r\n TI1 = CC(2,1,K)-CC(2,3,K)\r\n TI2 = CC(2,1,K)+CC(2,3,K)\r\n TR4 = CC(2,4,K)-CC(2,2,K)\r\n TI3 = CC(2,2,K)+CC(2,4,K)\r\n TR1 = CC(1,1,K)-CC(1,3,K)\r\n TR2 = CC(1,1,K)+CC(1,3,K)\r\n TI4 = CC(1,2,K)-CC(1,4,K)\r\n TR3 = CC(1,2,K)+CC(1,4,K)\r\n CH(1,K,1) = TR2+TR3\r\n CH(1,K,3) = TR2-TR3\r\n CH(2,K,1) = TI2+TI3\r\n CH(2,K,3) = TI2-TI3\r\n CH(1,K,2) = TR1+TR4\r\n CH(1,K,4) = TR1-TR4\r\n CH(2,K,2) = TI1+TI4\r\n CH(2,K,4) = TI1-TI4\r\n 101 CONTINUE\r\n RETURN\r\n 102 DO 104 K=1,L1\r\n DO 103 I=2,IDO,2\r\n TI1 = CC(I,1,K)-CC(I,3,K)\r\n TI2 = CC(I,1,K)+CC(I,3,K)\r\n TI3 = CC(I,2,K)+CC(I,4,K)\r\n TR4 = CC(I,4,K)-CC(I,2,K)\r\n TR1 = CC(I-1,1,K)-CC(I-1,3,K)\r\n TR2 = CC(I-1,1,K)+CC(I-1,3,K)\r\n TI4 = CC(I-1,2,K)-CC(I-1,4,K)\r\n TR3 = CC(I-1,2,K)+CC(I-1,4,K)\r\n CH(I-1,K,1) = TR2+TR3\r\n CR3 = TR2-TR3\r\n CH(I,K,1) = TI2+TI3\r\n CI3 = TI2-TI3\r\n CR2 = TR1+TR4\r\n CR4 = TR1-TR4\r\n CI2 = TI1+TI4\r\n CI4 = TI1-TI4\r\n CH(I-1,K,2) = WA1(I-1)*CR2-WA1(I)*CI2\r\n CH(I,K,2) = WA1(I-1)*CI2+WA1(I)*CR2\r\n CH(I-1,K,3) = WA2(I-1)*CR3-WA2(I)*CI3\r\n CH(I,K,3) = WA2(I-1)*CI3+WA2(I)*CR3\r\n CH(I-1,K,4) = WA3(I-1)*CR4-WA3(I)*CI4\r\n CH(I,K,4) = WA3(I-1)*CI4+WA3(I)*CR4\r\n 103 CONTINUE\r\n 104 CONTINUE\r\n RETURN\r\n END\r\n SUBROUTINE PASSB5 (IDO,L1,CC,CH,WA1,WA2,WA3,WA4)\r\n IMPLICIT_STATEMENT\r\n DIMENSION CC(IDO,5,L1) ,CH(IDO,L1,5) ,\r\n 1 WA1(*) ,WA2(*) ,WA3(*) ,WA4(*)\r\n DATA TR11,TI11,TR12,TI12 /.309016994374947,.951056516295154,\r\n 1-.809016994374947,.587785252292473/\r\n IF (IDO .NE. 2) GO TO 102\r\n DO 101 K=1,L1\r\n TI5 = CC(2,2,K)-CC(2,5,K)\r\n TI2 = CC(2,2,K)+CC(2,5,K)\r\n TI4 = CC(2,3,K)-CC(2,4,K)\r\n TI3 = CC(2,3,K)+CC(2,4,K)\r\n TR5 = CC(1,2,K)-CC(1,5,K)\r\n TR2 = CC(1,2,K)+CC(1,5,K)\r\n TR4 = CC(1,3,K)-CC(1,4,K)\r\n TR3 = CC(1,3,K)+CC(1,4,K)\r\n CH(1,K,1) = CC(1,1,K)+TR2+TR3\r\n CH(2,K,1) = CC(2,1,K)+TI2+TI3\r\n CR2 = CC(1,1,K)+TR11*TR2+TR12*TR3\r\n CI2 = CC(2,1,K)+TR11*TI2+TR12*TI3\r\n CR3 = CC(1,1,K)+TR12*TR2+TR11*TR3\r\n CI3 = CC(2,1,K)+TR12*TI2+TR11*TI3\r\n CR5 = TI11*TR5+TI12*TR4\r\n CI5 = TI11*TI5+TI12*TI4\r\n CR4 = TI12*TR5-TI11*TR4\r\n CI4 = TI12*TI5-TI11*TI4\r\n CH(1,K,2) = CR2-CI5\r\n CH(1,K,5) = CR2+CI5\r\n CH(2,K,2) = CI2+CR5\r\n CH(2,K,3) = CI3+CR4\r\n CH(1,K,3) = CR3-CI4\r\n CH(1,K,4) = CR3+CI4\r\n CH(2,K,4) = CI3-CR4\r\n CH(2,K,5) = CI2-CR5\r\n 101 CONTINUE\r\n RETURN\r\n 102 DO 104 K=1,L1\r\n DO 103 I=2,IDO,2\r\n TI5 = CC(I,2,K)-CC(I,5,K)\r\n TI2 = CC(I,2,K)+CC(I,5,K)\r\n TI4 = CC(I,3,K)-CC(I,4,K)\r\n TI3 = CC(I,3,K)+CC(I,4,K)\r\n TR5 = CC(I-1,2,K)-CC(I-1,5,K)\r\n TR2 = CC(I-1,2,K)+CC(I-1,5,K)\r\n TR4 = CC(I-1,3,K)-CC(I-1,4,K)\r\n TR3 = CC(I-1,3,K)+CC(I-1,4,K)\r\n CH(I-1,K,1) = CC(I-1,1,K)+TR2+TR3\r\n CH(I,K,1) = CC(I,1,K)+TI2+TI3\r\n CR2 = CC(I-1,1,K)+TR11*TR2+TR12*TR3\r\n CI2 = CC(I,1,K)+TR11*TI2+TR12*TI3\r\n CR3 = CC(I-1,1,K)+TR12*TR2+TR11*TR3\r\n CI3 = CC(I,1,K)+TR12*TI2+TR11*TI3\r\n CR5 = TI11*TR5+TI12*TR4\r\n CI5 = TI11*TI5+TI12*TI4\r\n CR4 = TI12*TR5-TI11*TR4\r\n CI4 = TI12*TI5-TI11*TI4\r\n DR3 = CR3-CI4\r\n DR4 = CR3+CI4\r\n DI3 = CI3+CR4\r\n DI4 = CI3-CR4\r\n DR5 = CR2+CI5\r\n DR2 = CR2-CI5\r\n DI5 = CI2-CR5\r\n DI2 = CI2+CR5\r\n CH(I-1,K,2) = WA1(I-1)*DR2-WA1(I)*DI2\r\n CH(I,K,2) = WA1(I-1)*DI2+WA1(I)*DR2\r\n CH(I-1,K,3) = WA2(I-1)*DR3-WA2(I)*DI3\r\n CH(I,K,3) = WA2(I-1)*DI3+WA2(I)*DR3\r\n CH(I-1,K,4) = WA3(I-1)*DR4-WA3(I)*DI4\r\n CH(I,K,4) = WA3(I-1)*DI4+WA3(I)*DR4\r\n CH(I-1,K,5) = WA4(I-1)*DR5-WA4(I)*DI5\r\n CH(I,K,5) = WA4(I-1)*DI5+WA4(I)*DR5\r\n 103 CONTINUE\r\n 104 CONTINUE\r\n RETURN\r\n END\r\n SUBROUTINE PASSB (NAC,IDO,IP,L1,IDL1,CC,C1,C2,CH,CH2,WA)\r\n IMPLICIT_STATEMENT\r\n DIMENSION CH(IDO,L1,IP) ,CC(IDO,IP,L1) ,\r\n 1 C1(IDO,L1,IP) ,WA(*) ,C2(IDL1,IP),\r\n 2 CH2(IDL1,IP)\r\n IDOT = IDO/2\r\n NT = IP*IDL1\r\n IPP2 = IP+2\r\n IPPH = (IP+1)/2\r\n IDP = IP*IDO\r\nC\r\n IF (IDO .LT. L1) GO TO 106\r\n DO 103 J=2,IPPH\r\n JC = IPP2-J\r\n DO 102 K=1,L1\r\n DO 101 I=1,IDO\r\n CH(I,K,J) = CC(I,J,K)+CC(I,JC,K)\r\n CH(I,K,JC) = CC(I,J,K)-CC(I,JC,K)\r\n 101 CONTINUE\r\n 102 CONTINUE\r\n 103 CONTINUE\r\n DO 105 K=1,L1\r\n DO 104 I=1,IDO\r\n CH(I,K,1) = CC(I,1,K)\r\n 104 CONTINUE\r\n 105 CONTINUE\r\n GO TO 112\r\n 106 DO 109 J=2,IPPH\r\n JC = IPP2-J\r\n DO 108 I=1,IDO\r\n DO 107 K=1,L1\r\n CH(I,K,J) = CC(I,J,K)+CC(I,JC,K)\r\n CH(I,K,JC) = CC(I,J,K)-CC(I,JC,K)\r\n 107 CONTINUE\r\n 108 CONTINUE\r\n 109 CONTINUE\r\n DO 111 I=1,IDO\r\n DO 110 K=1,L1\r\n CH(I,K,1) = CC(I,1,K)\r\n 110 CONTINUE\r\n 111 CONTINUE\r\n 112 IDL = 2-IDO\r\n INC = 0\r\n DO 116 L=2,IPPH\r\n LC = IPP2-L\r\n IDL = IDL+IDO\r\n DO 113 IK=1,IDL1\r\n C2(IK,L) = CH2(IK,1)+WA(IDL-1)*CH2(IK,2)\r\n C2(IK,LC) = WA(IDL)*CH2(IK,IP)\r\n 113 CONTINUE\r\n IDLJ = IDL\r\n INC = INC+IDO\r\n DO 115 J=3,IPPH\r\n JC = IPP2-J\r\n IDLJ = IDLJ+INC\r\n IF (IDLJ .GT. IDP) IDLJ = IDLJ-IDP\r\n WAR = WA(IDLJ-1)\r\n WAI = WA(IDLJ)\r\n DO 114 IK=1,IDL1\r\n C2(IK,L) = C2(IK,L)+WAR*CH2(IK,J)\r\n C2(IK,LC) = C2(IK,LC)+WAI*CH2(IK,JC)\r\n 114 CONTINUE\r\n 115 CONTINUE\r\n 116 CONTINUE\r\n DO 118 J=2,IPPH\r\n DO 117 IK=1,IDL1\r\n CH2(IK,1) = CH2(IK,1)+CH2(IK,J)\r\n 117 CONTINUE\r\n 118 CONTINUE\r\n DO 120 J=2,IPPH\r\n JC = IPP2-J\r\n DO 119 IK=2,IDL1,2\r\n CH2(IK-1,J) = C2(IK-1,J)-C2(IK,JC)\r\n CH2(IK-1,JC) = C2(IK-1,J)+C2(IK,JC)\r\n CH2(IK,J) = C2(IK,J)+C2(IK-1,JC)\r\n CH2(IK,JC) = C2(IK,J)-C2(IK-1,JC)\r\n 119 CONTINUE\r\n 120 CONTINUE\r\n NAC = 1\r\n IF (IDO .EQ. 2) RETURN\r\n NAC = 0\r\n DO 121 IK=1,IDL1\r\n C2(IK,1) = CH2(IK,1)\r\n 121 CONTINUE\r\n DO 123 J=2,IP\r\n DO 122 K=1,L1\r\n C1(1,K,J) = CH(1,K,J)\r\n C1(2,K,J) = CH(2,K,J)\r\n 122 CONTINUE\r\n 123 CONTINUE\r\n IF (IDOT .GT. L1) GO TO 127\r\n IDIJ = 0\r\n DO 126 J=2,IP\r\n IDIJ = IDIJ+2\r\n DO 125 I=4,IDO,2\r\n IDIJ = IDIJ+2\r\n DO 124 K=1,L1\r\n C1(I-1,K,J) = WA(IDIJ-1)*CH(I-1,K,J)-WA(IDIJ)*CH(I,K,J)\r\n C1(I,K,J) = WA(IDIJ-1)*CH(I,K,J)+WA(IDIJ)*CH(I-1,K,J)\r\n 124 CONTINUE\r\n 125 CONTINUE\r\n 126 CONTINUE\r\n RETURN\r\n 127 IDJ = 2-IDO\r\n DO 130 J=2,IP\r\n IDJ = IDJ+IDO\r\n DO 129 K=1,L1\r\n IDIJ = IDJ\r\n DO 128 I=4,IDO,2\r\n IDIJ = IDIJ+2\r\n C1(I-1,K,J) = WA(IDIJ-1)*CH(I-1,K,J)-WA(IDIJ)*CH(I,K,J)\r\n C1(I,K,J) = WA(IDIJ-1)*CH(I,K,J)+WA(IDIJ)*CH(I-1,K,J)\r\n 128 CONTINUE\r\n 129 CONTINUE\r\n 130 CONTINUE\r\n RETURN\r\n END\r\n\r\n\r\n\r\n\r\nC **********************************************************************\r\nC\r\nC SUBROUTINE CFFTF(N,C,WSAVE)\r\nC\r\nC SUBROUTINE CFFTF COMPUTES THE FORWARD COMPLEX DISCRETE FOURIER\r\nC TRANSFORM (THE FOURIER ANALYSIS). EQUIVALENTLY , CFFTF COMPUTES\r\nC THE FOURIER COEFFICIENTS OF A COMPLEX PERIODIC SEQUENCE.\r\nC THE TRANSFORM IS DEFINED BELOW AT OUTPUT PARAMETER C.\r\nC\r\nC THE TRANSFORM IS NOT NORMALIZED. TO OBTAIN A NORMALIZED TRANSFORM\r\nC THE OUTPUT MUST BE DIVIDED BY N. OTHERWISE A CALL OF CFFTF\r\nC FOLLOWED BY A CALL OF CFFTB WILL MULTIPLY THE SEQUENCE BY N.\r\nC\r\nC THE ARRAY WSAVE WHICH IS USED BY SUBROUTINE CFFTF MUST BE\r\nC INITIALIZED BY CALLING SUBROUTINE CFFTI(N,WSAVE).\r\nC\r\nC INPUT PARAMETERS\r\nC\r\nC\r\nC N THE LENGTH OF THE COMPLEX SEQUENCE C. THE METHOD IS\r\nC MORE EFFICIENT WHEN N IS THE PRODUCT OF SMALL PRIMES. N\r\nC\r\nC C A COMPLEX ARRAY OF LENGTH N WHICH CONTAINS THE SEQUENCE\r\nC\r\nC WSAVE A REAL WORK ARRAY WHICH MUST BE DIMENSIONED AT LEAST 4N+15\r\nC IN THE PROGRAM THAT CALLS CFFTF. THE WSAVE ARRAY MUST BE\r\nC INITIALIZED BY CALLING SUBROUTINE CFFTI(N,WSAVE) AND A\r\nC DIFFERENT WSAVE ARRAY MUST BE USED FOR EACH DIFFERENT\r\nC VALUE OF N. THIS INITIALIZATION DOES NOT HAVE TO BE\r\nC REPEATED SO LONG AS N REMAINS UNCHANGED THUS SUBSEQUENT\r\nC TRANSFORMS CAN BE OBTAINED FASTER THAN THE FIRST.\r\nC THE SAME WSAVE ARRAY CAN BE USED BY CFFTF AND CFFTB.\r\nC\r\nC OUTPUT PARAMETERS\r\nC\r\nC C FOR J=1,...,N\r\nC\r\nC C(J)=THE SUM FROM K=1,...,N OF\r\nC\r\nC C(K)*EXP(-I*(J-1)*(K-1)*2*PI/N)\r\nC\r\nC WHERE I=SQRT(-1)\r\nC\r\nC WSAVE CONTAINS INITIALIZATION CALCULATIONS WHICH MUST NOT BE\r\nC DESTROYED BETWEEN CALLS OF SUBROUTINE CFFTF OR CFFTB\r\nC\r\nC **********************************************************************\r\n SUBROUTINE CFFTF (N,C,WSAVE)\r\n IMPLICIT_STATEMENT\r\n DIMENSION C(*) ,WSAVE(*)\r\nC\r\n IF (N .EQ. 1) RETURN\r\n IW1 = N+N+1\r\n IW2 = IW1+N+N\r\n CALL CFFTF1 (N,C,WSAVE,WSAVE(IW1),WSAVE(IW2))\r\n RETURN\r\n END\r\n SUBROUTINE CFFTF1 (N,C,CH,WA,IFAC)\r\n IMPLICIT_STATEMENT\r\n IFAC_TYPE, DIMENSION(*) :: IFAC\r\n DIMENSION CH(*) ,C(*) ,WA(*)\r\n NF = nint(IFAC(2))\r\n NA = 0\r\n L1 = 1\r\n IW = 1\r\n DO 116 K1=1,NF\r\n IP = nint(IFAC(K1+2))\r\n L2 = IP*L1\r\n IDO = N/L2\r\n IDOT = IDO+IDO\r\n IDL1 = IDOT*L1\r\n IF (IP .NE. 4) GO TO 103\r\n IX2 = IW+IDOT\r\n IX3 = IX2+IDOT\r\n IF (NA .NE. 0) GO TO 101\r\n CALL PASSF4 (IDOT,L1,C,CH,WA(IW),WA(IX2),WA(IX3))\r\n GO TO 102\r\n 101 CALL PASSF4 (IDOT,L1,CH,C,WA(IW),WA(IX2),WA(IX3))\r\n 102 NA = 1-NA\r\n GO TO 115\r\n 103 IF (IP .NE. 2) GO TO 106\r\n IF (NA .NE. 0) GO TO 104\r\n CALL PASSF2 (IDOT,L1,C,CH,WA(IW))\r\n GO TO 105\r\n 104 CALL PASSF2 (IDOT,L1,CH,C,WA(IW))\r\n 105 NA = 1-NA\r\n GO TO 115\r\n 106 IF (IP .NE. 3) GO TO 109\r\n IX2 = IW+IDOT\r\n IF (NA .NE. 0) GO TO 107\r\n CALL PASSF3 (IDOT,L1,C,CH,WA(IW),WA(IX2))\r\n GO TO 108\r\n 107 CALL PASSF3 (IDOT,L1,CH,C,WA(IW),WA(IX2))\r\n 108 NA = 1-NA\r\n GO TO 115\r\n 109 IF (IP .NE. 5) GO TO 112\r\n IX2 = IW+IDOT\r\n IX3 = IX2+IDOT\r\n IX4 = IX3+IDOT\r\n IF (NA .NE. 0) GO TO 110\r\n CALL PASSF5 (IDOT,L1,C,CH,WA(IW),WA(IX2),WA(IX3),WA(IX4))\r\n GO TO 111\r\n 110 CALL PASSF5 (IDOT,L1,CH,C,WA(IW),WA(IX2),WA(IX3),WA(IX4))\r\n 111 NA = 1-NA\r\n GO TO 115\r\n 112 IF (NA .NE. 0) GO TO 113\r\n CALL PASSF (NAC,IDOT,IP,L1,IDL1,C,C,C,CH,CH,WA(IW))\r\n GO TO 114\r\n 113 CALL PASSF (NAC,IDOT,IP,L1,IDL1,CH,CH,CH,C,C,WA(IW))\r\n 114 IF (NAC .NE. 0) NA = 1-NA\r\n 115 L1 = L2\r\n IW = IW+(IP-1)*IDOT\r\n 116 CONTINUE\r\n IF (NA .EQ. 0) RETURN\r\n N2 = N+N\r\n DO 117 I=1,N2\r\n C(I) = CH(I)\r\n 117 CONTINUE\r\n RETURN\r\n END\r\n SUBROUTINE PASSF2 (IDO,L1,CC,CH,WA1)\r\n IMPLICIT_STATEMENT\r\n DIMENSION CC(IDO,2,L1) ,CH(IDO,L1,2) ,\r\n 1 WA1(*)\r\n IF (IDO .GT. 2) GO TO 102\r\n DO 101 K=1,L1\r\n CH(1,K,1) = CC(1,1,K)+CC(1,2,K)\r\n CH(1,K,2) = CC(1,1,K)-CC(1,2,K)\r\n CH(2,K,1) = CC(2,1,K)+CC(2,2,K)\r\n CH(2,K,2) = CC(2,1,K)-CC(2,2,K)\r\n 101 CONTINUE\r\n RETURN\r\n 102 DO 104 K=1,L1\r\n DO 103 I=2,IDO,2\r\n CH(I-1,K,1) = CC(I-1,1,K)+CC(I-1,2,K)\r\n TR2 = CC(I-1,1,K)-CC(I-1,2,K)\r\n CH(I,K,1) = CC(I,1,K)+CC(I,2,K)\r\n TI2 = CC(I,1,K)-CC(I,2,K)\r\n CH(I,K,2) = WA1(I-1)*TI2-WA1(I)*TR2\r\n CH(I-1,K,2) = WA1(I-1)*TR2+WA1(I)*TI2\r\n 103 CONTINUE\r\n 104 CONTINUE\r\n RETURN\r\n END\r\n SUBROUTINE PASSF3 (IDO,L1,CC,CH,WA1,WA2)\r\n IMPLICIT_STATEMENT\r\n DIMENSION CC(IDO,3,L1) ,CH(IDO,L1,3) ,\r\n 1 WA1(*) ,WA2(*)\r\n DATA TAUR,TAUI /-.5,-.866025403784439/\r\n IF (IDO .NE. 2) GO TO 102\r\n DO 101 K=1,L1\r\n TR2 = CC(1,2,K)+CC(1,3,K)\r\n CR2 = CC(1,1,K)+TAUR*TR2\r\n CH(1,K,1) = CC(1,1,K)+TR2\r\n TI2 = CC(2,2,K)+CC(2,3,K)\r\n CI2 = CC(2,1,K)+TAUR*TI2\r\n CH(2,K,1) = CC(2,1,K)+TI2\r\n CR3 = TAUI*(CC(1,2,K)-CC(1,3,K))\r\n CI3 = TAUI*(CC(2,2,K)-CC(2,3,K))\r\n CH(1,K,2) = CR2-CI3\r\n CH(1,K,3) = CR2+CI3\r\n CH(2,K,2) = CI2+CR3\r\n CH(2,K,3) = CI2-CR3\r\n 101 CONTINUE\r\n RETURN\r\n 102 DO 104 K=1,L1\r\n DO 103 I=2,IDO,2\r\n TR2 = CC(I-1,2,K)+CC(I-1,3,K)\r\n CR2 = CC(I-1,1,K)+TAUR*TR2\r\n CH(I-1,K,1) = CC(I-1,1,K)+TR2\r\n TI2 = CC(I,2,K)+CC(I,3,K)\r\n CI2 = CC(I,1,K)+TAUR*TI2\r\n CH(I,K,1) = CC(I,1,K)+TI2\r\n CR3 = TAUI*(CC(I-1,2,K)-CC(I-1,3,K))\r\n CI3 = TAUI*(CC(I,2,K)-CC(I,3,K))\r\n DR2 = CR2-CI3\r\n DR3 = CR2+CI3\r\n DI2 = CI2+CR3\r\n DI3 = CI2-CR3\r\n CH(I,K,2) = WA1(I-1)*DI2-WA1(I)*DR2\r\n CH(I-1,K,2) = WA1(I-1)*DR2+WA1(I)*DI2\r\n CH(I,K,3) = WA2(I-1)*DI3-WA2(I)*DR3\r\n CH(I-1,K,3) = WA2(I-1)*DR3+WA2(I)*DI3\r\n 103 CONTINUE\r\n 104 CONTINUE\r\n RETURN\r\n END\r\n SUBROUTINE PASSF4 (IDO,L1,CC,CH,WA1,WA2,WA3)\r\n IMPLICIT_STATEMENT\r\n DIMENSION CC(IDO,4,L1) ,CH(IDO,L1,4) ,\r\n 1 WA1(*) ,WA2(*) ,WA3(*)\r\n IF (IDO .NE. 2) GO TO 102\r\n DO 101 K=1,L1\r\n TI1 = CC(2,1,K)-CC(2,3,K)\r\n TI2 = CC(2,1,K)+CC(2,3,K)\r\n TR4 = CC(2,2,K)-CC(2,4,K)\r\n TI3 = CC(2,2,K)+CC(2,4,K)\r\n TR1 = CC(1,1,K)-CC(1,3,K)\r\n TR2 = CC(1,1,K)+CC(1,3,K)\r\n TI4 = CC(1,4,K)-CC(1,2,K)\r\n TR3 = CC(1,2,K)+CC(1,4,K)\r\n CH(1,K,1) = TR2+TR3\r\n CH(1,K,3) = TR2-TR3\r\n CH(2,K,1) = TI2+TI3\r\n CH(2,K,3) = TI2-TI3\r\n CH(1,K,2) = TR1+TR4\r\n CH(1,K,4) = TR1-TR4\r\n CH(2,K,2) = TI1+TI4\r\n CH(2,K,4) = TI1-TI4\r\n 101 CONTINUE\r\n RETURN\r\n 102 DO 104 K=1,L1\r\n DO 103 I=2,IDO,2\r\n TI1 = CC(I,1,K)-CC(I,3,K)\r\n TI2 = CC(I,1,K)+CC(I,3,K)\r\n TI3 = CC(I,2,K)+CC(I,4,K)\r\n TR4 = CC(I,2,K)-CC(I,4,K)\r\n TR1 = CC(I-1,1,K)-CC(I-1,3,K)\r\n TR2 = CC(I-1,1,K)+CC(I-1,3,K)\r\n TI4 = CC(I-1,4,K)-CC(I-1,2,K)\r\n TR3 = CC(I-1,2,K)+CC(I-1,4,K)\r\n CH(I-1,K,1) = TR2+TR3\r\n CR3 = TR2-TR3\r\n CH(I,K,1) = TI2+TI3\r\n CI3 = TI2-TI3\r\n CR2 = TR1+TR4\r\n CR4 = TR1-TR4\r\n CI2 = TI1+TI4\r\n CI4 = TI1-TI4\r\n CH(I-1,K,2) = WA1(I-1)*CR2+WA1(I)*CI2\r\n CH(I,K,2) = WA1(I-1)*CI2-WA1(I)*CR2\r\n CH(I-1,K,3) = WA2(I-1)*CR3+WA2(I)*CI3\r\n CH(I,K,3) = WA2(I-1)*CI3-WA2(I)*CR3\r\n CH(I-1,K,4) = WA3(I-1)*CR4+WA3(I)*CI4\r\n CH(I,K,4) = WA3(I-1)*CI4-WA3(I)*CR4\r\n 103 CONTINUE\r\n 104 CONTINUE\r\n RETURN\r\n END\r\n SUBROUTINE PASSF5 (IDO,L1,CC,CH,WA1,WA2,WA3,WA4)\r\n IMPLICIT_STATEMENT\r\n DIMENSION CC(IDO,5,L1) ,CH(IDO,L1,5) ,\r\n 1 WA1(*) ,WA2(*) ,WA3(*) ,WA4(*)\r\n DATA TR11,TI11,TR12,TI12 /.309016994374947,-.951056516295154,\r\n 1-.809016994374947,-.587785252292473/\r\n IF (IDO .NE. 2) GO TO 102\r\n DO 101 K=1,L1\r\n TI5 = CC(2,2,K)-CC(2,5,K)\r\n TI2 = CC(2,2,K)+CC(2,5,K)\r\n TI4 = CC(2,3,K)-CC(2,4,K)\r\n TI3 = CC(2,3,K)+CC(2,4,K)\r\n TR5 = CC(1,2,K)-CC(1,5,K)\r\n TR2 = CC(1,2,K)+CC(1,5,K)\r\n TR4 = CC(1,3,K)-CC(1,4,K)\r\n TR3 = CC(1,3,K)+CC(1,4,K)\r\n CH(1,K,1) = CC(1,1,K)+TR2+TR3\r\n CH(2,K,1) = CC(2,1,K)+TI2+TI3\r\n CR2 = CC(1,1,K)+TR11*TR2+TR12*TR3\r\n CI2 = CC(2,1,K)+TR11*TI2+TR12*TI3\r\n CR3 = CC(1,1,K)+TR12*TR2+TR11*TR3\r\n CI3 = CC(2,1,K)+TR12*TI2+TR11*TI3\r\n CR5 = TI11*TR5+TI12*TR4\r\n CI5 = TI11*TI5+TI12*TI4\r\n CR4 = TI12*TR5-TI11*TR4\r\n CI4 = TI12*TI5-TI11*TI4\r\n CH(1,K,2) = CR2-CI5\r\n CH(1,K,5) = CR2+CI5\r\n CH(2,K,2) = CI2+CR5\r\n CH(2,K,3) = CI3+CR4\r\n CH(1,K,3) = CR3-CI4\r\n CH(1,K,4) = CR3+CI4\r\n CH(2,K,4) = CI3-CR4\r\n CH(2,K,5) = CI2-CR5\r\n 101 CONTINUE\r\n RETURN\r\n 102 DO 104 K=1,L1\r\n DO 103 I=2,IDO,2\r\n TI5 = CC(I,2,K)-CC(I,5,K)\r\n TI2 = CC(I,2,K)+CC(I,5,K)\r\n TI4 = CC(I,3,K)-CC(I,4,K)\r\n TI3 = CC(I,3,K)+CC(I,4,K)\r\n TR5 = CC(I-1,2,K)-CC(I-1,5,K)\r\n TR2 = CC(I-1,2,K)+CC(I-1,5,K)\r\n TR4 = CC(I-1,3,K)-CC(I-1,4,K)\r\n TR3 = CC(I-1,3,K)+CC(I-1,4,K)\r\n CH(I-1,K,1) = CC(I-1,1,K)+TR2+TR3\r\n CH(I,K,1) = CC(I,1,K)+TI2+TI3\r\n CR2 = CC(I-1,1,K)+TR11*TR2+TR12*TR3\r\n CI2 = CC(I,1,K)+TR11*TI2+TR12*TI3\r\n CR3 = CC(I-1,1,K)+TR12*TR2+TR11*TR3\r\n CI3 = CC(I,1,K)+TR12*TI2+TR11*TI3\r\n CR5 = TI11*TR5+TI12*TR4\r\n CI5 = TI11*TI5+TI12*TI4\r\n CR4 = TI12*TR5-TI11*TR4\r\n CI4 = TI12*TI5-TI11*TI4\r\n DR3 = CR3-CI4\r\n DR4 = CR3+CI4\r\n DI3 = CI3+CR4\r\n DI4 = CI3-CR4\r\n DR5 = CR2+CI5\r\n DR2 = CR2-CI5\r\n DI5 = CI2-CR5\r\n DI2 = CI2+CR5\r\n CH(I-1,K,2) = WA1(I-1)*DR2+WA1(I)*DI2\r\n CH(I,K,2) = WA1(I-1)*DI2-WA1(I)*DR2\r\n CH(I-1,K,3) = WA2(I-1)*DR3+WA2(I)*DI3\r\n CH(I,K,3) = WA2(I-1)*DI3-WA2(I)*DR3\r\n CH(I-1,K,4) = WA3(I-1)*DR4+WA3(I)*DI4\r\n CH(I,K,4) = WA3(I-1)*DI4-WA3(I)*DR4\r\n CH(I-1,K,5) = WA4(I-1)*DR5+WA4(I)*DI5\r\n CH(I,K,5) = WA4(I-1)*DI5-WA4(I)*DR5\r\n 103 CONTINUE\r\n 104 CONTINUE\r\n RETURN\r\n END\r\n SUBROUTINE PASSF (NAC,IDO,IP,L1,IDL1,CC,C1,C2,CH,CH2,WA)\r\n IMPLICIT_STATEMENT\r\n DIMENSION CH(IDO,L1,IP) ,CC(IDO,IP,L1) ,\r\n 1 C1(IDO,L1,IP) ,WA(*) ,C2(IDL1,IP),\r\n 2 CH2(IDL1,IP)\r\n IDOT = IDO/2\r\n NT = IP*IDL1\r\n IPP2 = IP+2\r\n IPPH = (IP+1)/2\r\n IDP = IP*IDO\r\nC\r\n IF (IDO .LT. L1) GO TO 106\r\n DO 103 J=2,IPPH\r\n JC = IPP2-J\r\n DO 102 K=1,L1\r\n DO 101 I=1,IDO\r\n CH(I,K,J) = CC(I,J,K)+CC(I,JC,K)\r\n CH(I,K,JC) = CC(I,J,K)-CC(I,JC,K)\r\n 101 CONTINUE\r\n 102 CONTINUE\r\n 103 CONTINUE\r\n DO 105 K=1,L1\r\n DO 104 I=1,IDO\r\n CH(I,K,1) = CC(I,1,K)\r\n 104 CONTINUE\r\n 105 CONTINUE\r\n GO TO 112\r\n 106 DO 109 J=2,IPPH\r\n JC = IPP2-J\r\n DO 108 I=1,IDO\r\n DO 107 K=1,L1\r\n CH(I,K,J) = CC(I,J,K)+CC(I,JC,K)\r\n CH(I,K,JC) = CC(I,J,K)-CC(I,JC,K)\r\n 107 CONTINUE\r\n 108 CONTINUE\r\n 109 CONTINUE\r\n DO 111 I=1,IDO\r\n DO 110 K=1,L1\r\n CH(I,K,1) = CC(I,1,K)\r\n 110 CONTINUE\r\n 111 CONTINUE\r\n 112 IDL = 2-IDO\r\n INC = 0\r\n DO 116 L=2,IPPH\r\n LC = IPP2-L\r\n IDL = IDL+IDO\r\n DO 113 IK=1,IDL1\r\n C2(IK,L) = CH2(IK,1)+WA(IDL-1)*CH2(IK,2)\r\n C2(IK,LC) = -WA(IDL)*CH2(IK,IP)\r\n 113 CONTINUE\r\n IDLJ = IDL\r\n INC = INC+IDO\r\n DO 115 J=3,IPPH\r\n JC = IPP2-J\r\n IDLJ = IDLJ+INC\r\n IF (IDLJ .GT. IDP) IDLJ = IDLJ-IDP\r\n WAR = WA(IDLJ-1)\r\n WAI = WA(IDLJ)\r\n DO 114 IK=1,IDL1\r\n C2(IK,L) = C2(IK,L)+WAR*CH2(IK,J)\r\n C2(IK,LC) = C2(IK,LC)-WAI*CH2(IK,JC)\r\n 114 CONTINUE\r\n 115 CONTINUE\r\n 116 CONTINUE\r\n DO 118 J=2,IPPH\r\n DO 117 IK=1,IDL1\r\n CH2(IK,1) = CH2(IK,1)+CH2(IK,J)\r\n 117 CONTINUE\r\n 118 CONTINUE\r\n DO 120 J=2,IPPH\r\n JC = IPP2-J\r\n DO 119 IK=2,IDL1,2\r\n CH2(IK-1,J) = C2(IK-1,J)-C2(IK,JC)\r\n CH2(IK-1,JC) = C2(IK-1,J)+C2(IK,JC)\r\n CH2(IK,J) = C2(IK,J)+C2(IK-1,JC)\r\n CH2(IK,JC) = C2(IK,J)-C2(IK-1,JC)\r\n 119 CONTINUE\r\n 120 CONTINUE\r\n NAC = 1\r\n IF (IDO .EQ. 2) RETURN\r\n NAC = 0\r\n DO 121 IK=1,IDL1\r\n C2(IK,1) = CH2(IK,1)\r\n 121 CONTINUE\r\n DO 123 J=2,IP\r\n DO 122 K=1,L1\r\n C1(1,K,J) = CH(1,K,J)\r\n C1(2,K,J) = CH(2,K,J)\r\n 122 CONTINUE\r\n 123 CONTINUE\r\n IF (IDOT .GT. L1) GO TO 127\r\n IDIJ = 0\r\n DO 126 J=2,IP\r\n IDIJ = IDIJ+2\r\n DO 125 I=4,IDO,2\r\n IDIJ = IDIJ+2\r\n DO 124 K=1,L1\r\n C1(I-1,K,J) = WA(IDIJ-1)*CH(I-1,K,J)+WA(IDIJ)*CH(I,K,J)\r\n C1(I,K,J) = WA(IDIJ-1)*CH(I,K,J)-WA(IDIJ)*CH(I-1,K,J)\r\n 124 CONTINUE\r\n 125 CONTINUE\r\n 126 CONTINUE\r\n RETURN\r\n 127 IDJ = 2-IDO\r\n DO 130 J=2,IP\r\n IDJ = IDJ+IDO\r\n DO 129 K=1,L1\r\n IDIJ = IDJ\r\n DO 128 I=4,IDO,2\r\n IDIJ = IDIJ+2\r\n C1(I-1,K,J) = WA(IDIJ-1)*CH(I-1,K,J)+WA(IDIJ)*CH(I,K,J)\r\n C1(I,K,J) = WA(IDIJ-1)*CH(I,K,J)-WA(IDIJ)*CH(I-1,K,J)\r\n 128 CONTINUE\r\n 129 CONTINUE\r\n 130 CONTINUE\r\n RETURN\r\n END\r\n", "meta": {"hexsha": "28731ecda8abdeb64cdc6d03cbb8fb1f4ba71c25", "size": 74058, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Source/dependencies/NetLib/fftpack4.1.f", "max_stars_repo_name": "NWTC/HydroDyn", "max_stars_repo_head_hexsha": "816705503bc3c9d31988f424caf551ded7b5c5eb", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2018-06-23T11:52:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-26T12:38:20.000Z", "max_issues_repo_path": "source/NetLib/fftpack/fftpack4.1.f", "max_issues_repo_name": "NWTC/NWTC_Library", "max_issues_repo_head_hexsha": "5a78d53acab9f8a3634879da9c5f69c2cdfd072a", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-09-18T11:49:28.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-22T08:33:26.000Z", "max_forks_repo_path": "source/NetLib/fftpack/fftpack4.1.f", "max_forks_repo_name": "NWTC/NWTC_Library", "max_forks_repo_head_hexsha": "5a78d53acab9f8a3634879da9c5f69c2cdfd072a", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2018-09-20T08:27:07.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-27T01:15:44.000Z", "avg_line_length": 31.8118556701, "max_line_length": 95, "alphanum_fraction": 0.4585189986, "num_tokens": 29539, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587817066392, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6683577739432657}} {"text": "program test\n integer :: a(2, 5), r(10)\n integer :: i, j\n\n do j = 1, 5\n do i = 1, 2\n a(i, j) = j + i\n end do\n end do\n\n r = reshape(a, (/10/))\n do i = 1, 10 \n print *, r(i)\n end do\nend program test\n", "meta": {"hexsha": "6947a9ca57a290521dff312f43c1db2911e62c9b", "size": 219, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/output_tests/reshape_out3.f90", "max_stars_repo_name": "clementval/fc", "max_stars_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/output_tests/reshape_out3.f90", "max_issues_repo_name": "clementval/fc", "max_issues_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/output_tests/reshape_out3.f90", "max_forks_repo_name": "clementval/fc", "max_forks_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "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": 13.6875, "max_line_length": 27, "alphanum_fraction": 0.4611872146, "num_tokens": 98, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219503, "lm_q2_score": 0.8128673201042492, "lm_q1q2_score": 0.6683306751462206}} {"text": " PROGRAM t454\n TYPE TYPE_454\n COMPLEX :: T454_CPX\n INTEGER :: T454_INT\n END TYPE TYPE_454\n TYPE(TYPE_454), PARAMETER :: A = TYPE_454( (6.3,8.1),96721)\n COMPLEX :: C\n C = A%T454_CPX\n WRITE(6, \"(2F6.3)\") C\n END PROGRAM t454\n!{ dg-output \"6.300 8.100\" }\n", "meta": {"hexsha": "1e82d33e0b5c779701152f73c98a4034610194a6", "size": 321, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "osprey/testsuite/cases/single_src_cases/crayf90/osp454_1.f", "max_stars_repo_name": "sharugupta/OpenUH", "max_stars_repo_head_hexsha": "daddd76858a53035f5d713f648d13373c22506e8", "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": "osprey/testsuite/cases/single_src_cases/crayf90/osp454_1.f", "max_issues_repo_name": "sharugupta/OpenUH", "max_issues_repo_head_hexsha": "daddd76858a53035f5d713f648d13373c22506e8", "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": "osprey/testsuite/cases/single_src_cases/crayf90/osp454_1.f", "max_forks_repo_name": "sharugupta/OpenUH", "max_forks_repo_head_hexsha": "daddd76858a53035f5d713f648d13373c22506e8", "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.75, "max_line_length": 67, "alphanum_fraction": 0.5171339564, "num_tokens": 111, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7826624688140726, "lm_q2_score": 0.8539127603871312, "lm_q1q2_score": 0.6683254691964318}} {"text": "module qsort_mod\n\nimplicit none\n\ntype group\n integer :: order ! original order of unsorted data\n real :: value ! values to be sorted by\nend type group\n\ncontains\n\nrecursive subroutine QSort(a,na)\n\n! DUMMY ARGUMENTS\ninteger, intent(in) :: nA\ntype (group), dimension(nA), intent(in out) :: A\n\n! LOCAL VARIABLES\ninteger :: left, right\nreal :: random\nreal :: pivot\ntype (group) :: temp\ninteger :: marker\n\n if (nA > 1) then\n\n call random_number(random)\n pivot = A(int(random*real(nA-1))+1)%value ! random pivor (not best performance, but avoids worst-case)\n left = 0\n right = nA + 1\n\n do while (left < right)\n right = right - 1\n do while (A(right)%value > pivot)\n right = right - 1\n end do\n left = left + 1\n do while (A(left)%value < pivot)\n left = left + 1\n end do\n if (left < right) then\n temp = A(left)\n A(left) = A(right)\n A(right) = temp\n end if\n end do\n\n if (left == right) then\n marker = left + 1\n else\n marker = left\n end if\n\n call QSort(A(:marker-1),marker-1)\n call QSort(A(marker:),nA-marker+1)\n\n end if\n\nend subroutine QSort\n\nend module qsort_mod\n\n! Test Qsort Module\nprogram qsort_test\nuse qsort_mod\nimplicit none\n\ninteger, parameter :: l = 8\ntype (group), dimension(l) :: A\ninteger, dimension(12) :: seed = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]\ninteger :: i\nreal :: random\n\n write (*,*) \"Unsorted Values:\"\n call random_seed(put = seed)\n do i = 1, l\n call random_number(random)\n A(i)%value = random\n A(i)%order = i\n if (mod(i,4) == 0) write (*,\"(4(I5,1X,F8.6))\") A(i-3:i)\n end do\n\n call QSort(A,l)\n write (*,*) \"Sorted Values:\"\n do i = 4, l, 4\n if (mod(i,4) == 0) write (*,\"(4(I5,1X,F8.6))\") A(i-3:i)\n end do\n\nend program qsort_test\n", "meta": {"hexsha": "74e6e087c6792474349c0ab131122dbbf8c5e185", "size": 1985, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Sorting-algorithms-Quicksort/Fortran/sorting-algorithms-quicksort.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/Sorting-algorithms-Quicksort/Fortran/sorting-algorithms-quicksort.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Sorting-algorithms-Quicksort/Fortran/sorting-algorithms-quicksort.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.0555555556, "max_line_length": 112, "alphanum_fraction": 0.5345088161, "num_tokens": 604, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517044, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.6683254677058554}} {"text": "MODULE fd_module\n\n implicit none\n\n PRIVATE\n PUBLIC :: get_coef_lapla_fd, get_coef_nabla_fd &\n ,fd,construct_nabla_fd,destruct_nabla_fd\n\n type fd\n real(8),allocatable :: coef(:)\n integer :: md\n end type fd\n\n integer :: Md_backup\n\nCONTAINS\n\n SUBROUTINE get_coef_lapla_fd(Md,lap)\n implicit none\n integer,intent(IN) :: Md\n real(8),intent(OUT) :: lap(-Md:Md)\n integer :: i,j,k\n real(8) :: t,s,s0\n lap=0.d0\n s=0.d0\n do i=-Md,Md\n if ( i==0 ) cycle\n do j=-Md,Md\n if ( j==i .or. j==0 ) cycle\n s=s+1.d0/dble(i*j)\n end do\n end do\n lap(0)=s\n do j=1,Md\n t=1.d0\n do i=-Md,Md\n if ( i==j ) cycle\n t=t*(j-i)\n end do\n s=0.d0\n do k=-Md,Md\n if ( k==j .or. k==0 ) cycle\n s0=1.d0\n do i=-Md,Md\n if ( i==k .or. i==j .or. i==0 ) cycle\n s0=s0*(-i)\n end do\n s=s+s0\n end do\n lap( j)=2.d0*s/t\n lap(-j)=lap(j)\n end do\n Md_backup = Md\n END SUBROUTINE get_coef_lapla_fd\n\n SUBROUTINE get_coef_nabla_fd(Md,nab)\n implicit none\n integer,intent(IN) :: Md\n real(8),intent(OUT) :: nab(-Md:Md)\n integer :: i,j\n real(8) :: t,s\n nab=0.d0\n do j=1,Md\n t=1.d0\n do i=-Md,Md\n if ( i==j ) cycle\n t=t*(j-i)\n end do\n s=1.d0\n do i=-Md,Md\n if ( i==j .or. i==0 ) cycle\n s=s*(-i)\n end do\n nab( j)=s/t\n nab(-j)=nab(j)\n end do\n Md_backup = Md\n END SUBROUTINE get_coef_nabla_fd\n\n\n SUBROUTINE construct_nabla_fd( nabla )\n implicit none\n type(fd) :: nabla\n nabla%md = Md_backup\n allocate( nabla%coef(-nabla%md:nabla%md) ) ; nabla%coef=0.0d0\n call get_coef_nabla_fd( nabla%md, nabla%coef )\n END SUBROUTINE construct_nabla_fd\n\n SUBROUTINE destruct_nabla_fd( nabla )\n implicit none\n type(fd) :: nabla\n deallocate( nabla%coef )\n END SUBROUTINE destruct_nabla_fd\n\n\n SUBROUTINE construct_lapla_fd( lapla )\n implicit none\n type(fd) :: lapla\n lapla%md = Md_backup\n allocate( lapla%coef(-lapla%md:lapla%md) ) ; lapla%coef=0.0d0\n call get_coef_lapla_fd( lapla%md, lapla%coef )\n END SUBROUTINE construct_lapla_fd\n\n SUBROUTINE destruct_lapla_fd( lapla )\n implicit none\n type(fd) :: lapla\n deallocate( lapla%coef )\n END SUBROUTINE destruct_lapla_fd\n\n\nEND MODULE fd_module\n", "meta": {"hexsha": "7f9724c8f05f02adaece368a5c314bf5425dcdc0", "size": 2403, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fd_module.f90", "max_stars_repo_name": "j-iwata/RSDFT", "max_stars_repo_head_hexsha": "2a961b2c8339a49de9bd09f55e7d6a45b6159d2e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2016-10-31T02:11:39.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-04T17:45:30.000Z", "max_issues_repo_path": "src/fd_module.f90", "max_issues_repo_name": "j-iwata/RSDFT", "max_issues_repo_head_hexsha": "2a961b2c8339a49de9bd09f55e7d6a45b6159d2e", "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/fd_module.f90", "max_forks_repo_name": "j-iwata/RSDFT", "max_forks_repo_head_hexsha": "2a961b2c8339a49de9bd09f55e7d6a45b6159d2e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-10-31T02:11:41.000Z", "max_forks_repo_forks_event_max_datetime": "2020-04-18T14:26:38.000Z", "avg_line_length": 21.4553571429, "max_line_length": 65, "alphanum_fraction": 0.5605493134, "num_tokens": 870, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517043, "lm_q2_score": 0.7826624738835051, "lm_q1q2_score": 0.6683254677058552}} {"text": " subroutine qlspencer(zrat1,zrat2,ieps1,ieps2,res)\n implicit none\n include 'qlconstants.f'\n double precision ieps1,ieps2,x1,x2,y1,y2,ieps\n double complex zrat1,zrat2,res,\n . lnarg,lnomarg,prod,denspence,qlLi2omx,arg,cln\n logical qlzero\n\n x1=dreal(zrat1)\n x2=dreal(zrat2)\n y1=dimag(zrat1)\n y2=dimag(zrat2)\n if (qlzero(y1) .and. qlzero(y2)) then\n res=qlLi2omx(x1,x2,ieps1,ieps2)\n else\n arg=zrat1*zrat2\n ieps=0d0\n if (abs(arg) .le. 1d0) then\n if (arg .eq. 0d0 .or. arg .eq. 1d0) then\n prod=0d0\n else\n lnarg=cln(zrat1,ieps1)+cln(zrat2,ieps2)\n lnomarg=log(cone-arg)\n prod = lnarg*lnomarg\n endif\n res=dcmplx(pisqo6)-denspence(arg,ieps)-prod\n elseif (abs(arg) .gt. 1d0) then\n arg=cone/(zrat1*zrat2)\n lnarg=-cln(zrat1,ieps1)-cln(zrat2,ieps2)\n lnomarg=log(cone-arg)\n res=-dcmplx(pisqo6)+denspence(arg,ieps)\n . +lnarg*lnomarg-0.5d0*lnarg**2\n endif\n endif\n return\n end \n", "meta": {"hexsha": "931ff038c4bb132b4878fe8a354ac712cada660a", "size": 1088, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "vendor/IREGI/src/qcdloop/ql/qlspencer.f", "max_stars_repo_name": "valassi/mg5amc_test", "max_stars_repo_head_hexsha": "2e04f23353051f64e1604b23105fe3faabd32869", "max_stars_repo_licenses": ["NCSA"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-10-23T14:37:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-22T20:59:02.000Z", "max_issues_repo_path": "vendor/IREGI/src/qcdloop/ql/qlspencer.f", "max_issues_repo_name": "valassi/mg5amc_test", "max_issues_repo_head_hexsha": "2e04f23353051f64e1604b23105fe3faabd32869", "max_issues_repo_licenses": ["NCSA"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2018-10-08T15:49:32.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-15T13:33:36.000Z", "max_forks_repo_path": "vendor/IREGI/src/qcdloop/ql/qlspencer.f", "max_forks_repo_name": "valassi/mg5amc_test", "max_forks_repo_head_hexsha": "2e04f23353051f64e1604b23105fe3faabd32869", "max_forks_repo_licenses": ["NCSA"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2019-02-18T11:42:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-11T20:46:08.000Z", "avg_line_length": 29.4054054054, "max_line_length": 55, "alphanum_fraction": 0.5735294118, "num_tokens": 427, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218434359675, "lm_q2_score": 0.724870282120402, "lm_q1q2_score": 0.6682737467443909}} {"text": " SUBROUTINE AB05OD( OVER, N1, M1, P1, N2, M2, ALPHA, A1, LDA1, B1,\n $ LDB1, C1, LDC1, D1, LDD1, A2, LDA2, B2, LDB2,\n $ C2, LDC2, D2, LDD2, N, M, A, LDA, B, LDB, C,\n $ LDC, D, LDD, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To obtain the state-space model (A,B,C,D) for rowwise\nC concatenation (parallel inter-connection on outputs, with separate\nC inputs) of two systems, each given in state-space form.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC OVER CHARACTER*1\nC Indicates whether the user wishes to overlap pairs of\nC arrays, as follows:\nC = 'N': Do not overlap;\nC = 'O': Overlap pairs of arrays: A1 and A, B1 and B,\nC C1 and C, and D1 and D, i.e. the same name is\nC effectively used for each pair (for all pairs)\nC in the routine call. In this case, setting\nC LDA1 = LDA, LDB1 = LDB, LDC1 = LDC, and LDD1 = LDD\nC will give maximum efficiency.\nC\nC Input/Output Parameters\nC\nC N1 (input) INTEGER\nC The number of state variables in the first system, i.e.\nC the order of the matrix A1. N1 >= 0.\nC\nC M1 (input) INTEGER\nC The number of input variables for the first system.\nC M1 >= 0.\nC\nC P1 (input) INTEGER\nC The number of output variables from each system. P1 >= 0.\nC\nC N2 (input) INTEGER\nC The number of state variables in the second system, i.e.\nC the order of the matrix A2. N2 >= 0.\nC\nC M2 (input) INTEGER\nC The number of input variables for the second system.\nC M2 >= 0.\nC\nC ALPHA (input) DOUBLE PRECISION\nC A coefficient multiplying the transfer-function matrix\nC (or the output equation) of the second system.\nC\nC A1 (input) DOUBLE PRECISION array, dimension (LDA1,N1)\nC The leading N1-by-N1 part of this array must contain the\nC state transition matrix A1 for the first system.\nC\nC LDA1 INTEGER\nC The leading dimension of array A1. LDA1 >= MAX(1,N1).\nC\nC B1 (input) DOUBLE PRECISION array, dimension (LDB1,M1)\nC The leading N1-by-M1 part of this array must contain the\nC input/state matrix B1 for the first system.\nC\nC LDB1 INTEGER\nC The leading dimension of array B1. LDB1 >= MAX(1,N1).\nC\nC C1 (input) DOUBLE PRECISION array, dimension (LDC1,N1)\nC The leading P1-by-N1 part of this array must contain the\nC state/output matrix C1 for the first system.\nC\nC LDC1 INTEGER\nC The leading dimension of array C1.\nC LDC1 >= MAX(1,P1) if N1 > 0.\nC LDC1 >= 1 if N1 = 0.\nC\nC D1 (input) DOUBLE PRECISION array, dimension (LDD1,M1)\nC The leading P1-by-M1 part of this array must contain the\nC input/output matrix D1 for the first system.\nC\nC LDD1 INTEGER\nC The leading dimension of array D1. LDD1 >= MAX(1,P1).\nC\nC A2 (input) DOUBLE PRECISION array, dimension (LDA2,N2)\nC The leading N2-by-N2 part of this array must contain the\nC state transition matrix A2 for the second system.\nC\nC LDA2 INTEGER\nC The leading dimension of array A2. LDA2 >= MAX(1,N2).\nC\nC B2 (input) DOUBLE PRECISION array, dimension (LDB2,M2)\nC The leading N2-by-M2 part of this array must contain the\nC input/state matrix B2 for the second system.\nC\nC LDB2 INTEGER\nC The leading dimension of array B2. LDB2 >= MAX(1,N2).\nC\nC C2 (input) DOUBLE PRECISION array, dimension (LDC2,N2)\nC The leading P1-by-N2 part of this array must contain the\nC state/output matrix C2 for the second system.\nC\nC LDC2 INTEGER\nC The leading dimension of array C2.\nC LDC2 >= MAX(1,P1) if N2 > 0.\nC LDC2 >= 1 if N2 = 0.\nC\nC D2 (input) DOUBLE PRECISION array, dimension (LDD2,M2)\nC The leading P1-by-M2 part of this array must contain the\nC input/output matrix D2 for the second system.\nC\nC LDD2 INTEGER\nC The leading dimension of array D2. LDD2 >= MAX(1,P1).\nC\nC N (output) INTEGER\nC The number of state variables (N1 + N2) in the connected\nC system, i.e. the order of the matrix A, the number of rows\nC of B and the number of columns of C.\nC\nC M (output) INTEGER\nC The number of input variables (M1 + M2) for the connected\nC system, i.e. the number of columns of B and D.\nC\nC A (output) DOUBLE PRECISION array, dimension (LDA,N1+N2)\nC The leading N-by-N part of this array contains the state\nC transition matrix A for the connected system.\nC The array A can overlap A1 if OVER = 'O'.\nC\nC LDA INTEGER\nC The leading dimension of array A. LDA >= MAX(1,N1+N2).\nC\nC B (output) DOUBLE PRECISION array, dimension (LDB,M1+M2)\nC The leading N-by-M part of this array contains the\nC input/state matrix B for the connected system.\nC The array B can overlap B1 if OVER = 'O'.\nC\nC LDB INTEGER\nC The leading dimension of array B. LDB >= MAX(1,N1+N2).\nC\nC C (output) DOUBLE PRECISION array, dimension (LDC,N1+N2)\nC The leading P1-by-N part of this array contains the\nC state/output matrix C for the connected system.\nC The array C can overlap C1 if OVER = 'O'.\nC\nC LDC INTEGER\nC The leading dimension of array C.\nC LDC >= MAX(1,P1) if N1+N2 > 0.\nC LDC >= 1 if N1+N2 = 0.\nC\nC D (output) DOUBLE PRECISION array, dimension (LDD,M1+M2)\nC The leading P1-by-M part of this array contains the\nC input/output matrix D for the connected system.\nC The array D can overlap D1 if OVER = 'O'.\nC\nC LDD INTEGER\nC The leading dimension of array D. LDD >= MAX(1,P1).\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value.\nC\nC METHOD\nC\nC After rowwise concatenation (parallel inter-connection with\nC separate inputs) of the two systems,\nC\nC X1' = A1*X1 + B1*U\nC Y1 = C1*X1 + D1*U\nC\nC X2' = A2*X2 + B2*V\nC Y2 = C2*X2 + D2*V\nC\nC (where ' denotes differentiation with respect to time),\nC\nC with the output equation for the second system multiplied by a\nC scalar alpha, the following state-space model will be obtained:\nC\nC X' = A*X + B*(U)\nC (V)\nC\nC Y = C*X + D*(U)\nC (V)\nC\nC where matrix A has the form ( A1 0 ),\nC ( 0 A2 )\nC\nC matrix B has the form ( B1 0 ),\nC ( 0 B2 )\nC\nC matrix C has the form ( C1 alpha*C2 ) and\nC\nC matrix D has the form ( D1 alpha*D2 ).\nC\nC REFERENCES\nC\nC None\nC\nC NUMERICAL ASPECTS\nC\nC None\nC\nC CONTRIBUTOR\nC\nC Release 3.0: V. Sima, Katholieke Univ. Leuven, Belgium, Oct. 1996.\nC Supersedes Release 2.0 routine AB05CD by C.J.Benson, Kingston\nC Polytechnic, United Kingdom, January 1982.\nC\nC REVISIONS\nC\nC V. Sima, Research Institute for Informatics, Bucharest, July 2003,\nC Feb. 2004.\nC\nC KEYWORDS\nC\nC Continuous-time system, multivariable system, state-space model,\nC state-space representation.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, ONE\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )\nC .. Scalar Arguments ..\n CHARACTER OVER\n INTEGER INFO, LDA, LDA1, LDA2, LDB, LDB1, LDB2, LDC,\n $ LDC1, LDC2, LDD, LDD1, LDD2, M, M1, M2, N, N1,\n $ N2, P1\n DOUBLE PRECISION ALPHA\nC .. Array Arguments ..\n DOUBLE PRECISION A(LDA,*), A1(LDA1,*), A2(LDA2,*), B(LDB,*),\n $ B1(LDB1,*), B2(LDB2,*), C(LDC,*), C1(LDC1,*),\n $ C2(LDC2,*), D(LDD,*), D1(LDD1,*), D2(LDD2,*)\nC .. Local Scalars ..\n LOGICAL LOVER\n INTEGER I, J\nC .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\nC .. External Subroutines ..\n EXTERNAL DLACPY, DLASCL, DLASET, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC MAX, MIN\nC .. Executable Statements ..\nC\n LOVER = LSAME( OVER, 'O' )\n N = N1 + N2\n M = M1 + M2\n INFO = 0\nC\nC Test the input scalar arguments.\nC\n IF( .NOT.LOVER .AND. .NOT.LSAME( OVER, 'N' ) ) THEN\n INFO = -1\n ELSE IF( N1.LT.0 ) THEN\n INFO = -2\n ELSE IF( M1.LT.0 ) THEN\n INFO = -3\n ELSE IF( P1.LT.0 ) THEN\n INFO = -4\n ELSE IF( N2.LT.0 ) THEN\n INFO = -5\n ELSE IF( M2.LT.0 ) THEN\n INFO = -6\n ELSE IF( LDA1.LT.MAX( 1, N1 ) ) THEN\n INFO = -9\n ELSE IF( LDB1.LT.MAX( 1, N1 ) ) THEN\n INFO = -11\n ELSE IF( ( N1.GT.0 .AND. LDC1.LT.MAX( 1, P1 ) ) .OR.\n $ ( N1.EQ.0 .AND. LDC1.LT.1 ) ) THEN\n INFO = -13\n ELSE IF( LDD1.LT.MAX( 1, P1 ) ) THEN\n INFO = -15\n ELSE IF( LDA2.LT.MAX( 1, N2 ) ) THEN\n INFO = -17\n ELSE IF( LDB2.LT.MAX( 1, N2 ) ) THEN\n INFO = -19\n ELSE IF( ( N2.GT.0 .AND. LDC2.LT.MAX( 1, P1 ) ) .OR.\n $ ( N2.EQ.0 .AND. LDC2.LT.1 ) ) THEN\n INFO = -21\n ELSE IF( LDD2.LT.MAX( 1, P1 ) ) THEN\n INFO = -23\n ELSE IF( LDA.LT.MAX( 1, N ) ) THEN\n INFO = -27\n ELSE IF( LDB.LT.MAX( 1, N ) ) THEN\n INFO = -29\n ELSE IF( ( N.GT.0 .AND. LDC.LT.MAX( 1, P1 ) ) .OR.\n $ ( N.EQ.0 .AND. LDC.LT.1 ) ) THEN\n INFO = -31\n ELSE IF( LDD.LT.MAX( 1, P1 ) ) THEN\n INFO = -33\n END IF\nC\n IF ( INFO.NE.0 ) THEN\nC\nC Error return.\nC\n CALL XERBLA( 'AB05OD', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF ( MAX( N, MIN( M, P1 ) ).EQ.0 )\n $ RETURN\nC\nC First form the matrix A.\nC\n IF ( LOVER .AND. LDA1.LE.LDA ) THEN\n IF ( LDA1.LT.LDA ) THEN\nC\n DO 20 J = N1, 1, -1\n DO 10 I = N1, 1, -1\n A(I,J) = A1(I,J)\n 10 CONTINUE\n 20 CONTINUE\nC\n END IF\n ELSE\n CALL DLACPY( 'F', N1, N1, A1, LDA1, A, LDA )\n END IF\nC\n IF ( N2.GT.0 ) THEN\n CALL DLACPY( 'F', N2, N2, A2, LDA2, A(N1+1,N1+1), LDA )\n CALL DLASET( 'F', N1, N2, ZERO, ZERO, A(1,N1+1), LDA )\n CALL DLASET( 'F', N2, N1, ZERO, ZERO, A(N1+1,1), LDA )\n END IF\nC\nC Now form the matrix B.\nC\n IF ( LOVER .AND. LDB1.LE.LDB ) THEN\n IF ( LDB1.LT.LDB ) THEN\nC\n DO 40 J = M1, 1, -1\n DO 30 I = N1, 1, -1\n B(I,J) = B1(I,J)\n 30 CONTINUE\n 40 CONTINUE\nC\n END IF\n ELSE\n CALL DLACPY( 'F', N1, M1, B1, LDB1, B, LDB )\n END IF\nC\n IF ( M2.GT.0 ) THEN\n IF ( N2.GT.0 )\n $ CALL DLACPY( 'F', N2, M2, B2, LDB2, B(N1+1,M1+1), LDB )\n CALL DLASET( 'F', N1, M2, ZERO, ZERO, B(1,M1+1), LDB )\n END IF\n IF ( N2.GT.0 )\n $ CALL DLASET( 'F', N2, M1, ZERO, ZERO, B(N1+1,1), LDB )\nC\nC Now form the matrix C.\nC\n IF ( LOVER .AND. LDC1.LE.LDC ) THEN\n IF ( LDC1.LT.LDC ) THEN\nC\n DO 60 J = N1, 1, -1\n DO 50 I = P1, 1, -1\n C(I,J) = C1(I,J)\n 50 CONTINUE\n 60 CONTINUE\nC\n END IF\n ELSE\n CALL DLACPY( 'F', P1, N1, C1, LDC1, C, LDC )\n END IF\nC\n IF ( N2.GT.0 ) THEN\n CALL DLACPY( 'F', P1, N2, C2, LDC2, C(1,N1+1), LDC )\n IF ( ALPHA.NE.ONE )\n $ CALL DLASCL( 'G', 0, 0, ONE, ALPHA, P1, N2, C(1,N1+1), LDC,\n $ INFO )\n END IF\nC\nC Now form the matrix D.\nC\n IF ( LOVER .AND. LDD1.LE.LDD ) THEN\n IF ( LDD1.LT.LDD ) THEN\nC\n DO 80 J = M1, 1, -1\n DO 70 I = P1, 1, -1\n D(I,J) = D1(I,J)\n 70 CONTINUE\n 80 CONTINUE\nC\n END IF\n ELSE\n CALL DLACPY( 'F', P1, M1, D1, LDD1, D, LDD )\n END IF\nC\n IF ( M2.GT.0 ) THEN\n CALL DLACPY( 'F', P1, M2, D2, LDD2, D(1,M1+1), LDD )\n IF ( ALPHA.NE.ONE )\n $ CALL DLASCL( 'G', 0, 0, ONE, ALPHA, P1, M2, D(1,M1+1), LDD,\n $ INFO )\n END IF\nC\n RETURN\nC *** Last line of AB05OD ***\n END\n", "meta": {"hexsha": "bb9ef315475adc0cfb9a25a4a6fbc84529947725", "size": 13042, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/AB05OD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/AB05OD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/AB05OD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 32.2024691358, "max_line_length": 72, "alphanum_fraction": 0.5147216685, "num_tokens": 4337, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9219218348550491, "lm_q2_score": 0.7248702880639791, "lm_q1q2_score": 0.6682737460038516}} {"text": "c ==========================================================================\n\n\tdouble precision function SphericalDistance(RA_SUN,DEC_SUN,RA,DEC)\nc \tCompute the distance on the great circle. \nc \tComputations are based upon \nc\thttp://en.wikipedia.org/wiki/Great-circle_distance#Formulas\nc\tThis is the *Angular* spherical distance in radians\n\n\timplicit none\n\tdouble precision RA_SUN, DEC_SUN, RA, DEC\n\tdouble precision ls, lf, ps, pf, dl, dp, num1, num2, den1, den2\n\tdouble precision num, den, angular_distance\n\n\tls = RA_SUN\n\tlf = RA\n\n\tps = DEC_SUN\n\tpf = DEC\n\n\tdl = lf-ls\n\tdp = pf-ps\n\n\tnum1 = dcos(pf) * dsin(dl)\n\tnum2 = dcos(ps) * dsin(pf) - dsin(ps)*dcos(pf)*dcos(dl)\n\n\tden1 = dsin(ps) * dsin(pf)\n\tden2 = dcos(ps) * dcos(pf) * dcos(dl)\n\n\tnum = dsqrt(num1 * num1 + num2 * num2)\n\tden = den1 + den2\n\n\tSphericalDistance = datan2(num,den)\n\n\treturn\n\n\tend\n\nc ==========================================================================\n subroutine ILLUMINATED_EARTH(RA_SUN, DEC_SUN, !Input\n & day_night) !Output\nc Calculate the equatorial coordinates of the illuminated Earth\nc\tCompute which part of the Earth is illuminated and with what intensity \nc\t(in arbitrary unit between 0 (total night) and 1 (zenith)) and outputs\nc\tthe results in a table of the size of Earth's grid (n_alpha x n_delta).\n\n implicit none\n include 'constants'\n include 'parameters'\n\n\tdouble precision RA_SUN, DEC_SUN\n\tdouble precision day_night(1:n_alpha, 1:n_delta)\n\tdouble precision SphericalDistance\n\tdouble precision alpha_grid, delta_grid, dist\n integer k, j\n\n\tdo k = 1, n_alpha\n\t alpha_grid = 2.d0*pi*dble(k-1)/dble(n_alpha-1)\n\t do j = 1, n_delta\n\t delta_grid = -pi/2.d0+dble(j-1)*pi/dble(n_delta-1)\n\nc\t This is the *Angular* spherical distance\n\t dist = SphericalDistance(RA_SUN,DEC_SUN,alpha_grid,delta_grid)\n\n\t if (dist <= pi/2.) then\nc\t\tCompute correct illumination of a given cell on the Earth's surface\n\t\tif (gradient) then\n\t\t day_night(k,j) = day * dcos(dist)\n\t\telse\n\t\t day_night(k,j) = day\n\t\tendif\n\t else\nc\t\tInitialise the rest of the table.\n\t\tday_night(k,j) = night\n\t endif\n\n\t enddo\n\tenddo\n\n\tif (log_all_data) then\n\t call write_illuminated_earth(day_night)\n\tendif\n\n return\n end\n \nc ========================================================================== \n subroutine EARTH_SEEN_FROM_SAT (SAT, RA_SAT, DEC_SAT, day_night,\t!Input\n & coord_illum) \nc\tReturns the coordinates of the cells of the Earths that are 1) in daylight\nc\tand 2) visible the the satellite. \t!Output\n\n implicit none\n include 'constants'\n include 'parameters'\n\n double precision SAT(1:3), RA_SAT, DEC_SAT, R_SAT \n\tdouble precision alpha_grid, delta_grid\n double precision alpha, SphericalDistance, dist\n double precision RA_LIMIT(1:n_alpha), DEC_LIMIT(1:n_alpha)\n double precision coord_illum(1:n_alpha, 1:n_delta)\n double precision day_night(1:n_alpha, 1:n_delta)\n\tinteger j, k\n\nc\tGet the norm of the vector SAT to get its distance to Earth's center.\n call R_3D(SAT, R_SAT)\n\nc We look for the limit coordinates of the Earth seen by the satellite\nc\talpha is the half-angle cone centred on the satellite containing the Earth\nc\twhich is the horizon as seen by the satellite.\n\nc\talpha is computed from the centre of the Earth !!\n alpha = acos(R_Earth/R_SAT)\n\nc We look for the coordinates of the Earth seen by the satellite\n\n\tdo k = 1, n_alpha\n\t alpha_grid = 2.d0*pi*dble(k-1)/dble(n_alpha-1)\n\t do j = 1, n_delta\n\t delta_grid = -pi/2.d0+dble(j-1)*pi/dble(n_delta-1)\n\n\t dist = SphericalDistance(RA_SAT,DEC_SAT,alpha_grid,delta_grid)\n\n\t if (dist <= alpha .and. day_night(k,j).ne.night) then\n\t\tcoord_illum(k,j) = seen\n\t else\nc\t\tInitialise the rest of the table.\n\t\tcoord_illum(k,j) = night\n\t endif\n\t enddo\n\tenddo\n\n\tif (log_all_data) then\n\t call write_seen(coord_illum)\n\tendif\n\n return\n end\n\nc ==========================================================================\n subroutine PHOTONS_AT_TELESCOPE(coord_illum, \t\t\t\t!Input\n & RA_STAR, DEC_STAR, SAT,\n & coord_photons, photons_hit, angle_photons, pst_photons,error)!Output\n\n implicit none\n include 'constants'\n include 'parameters'\n\n double precision coord_photons(1:n_alpha,1:n_delta)\n double precision coord_illum(1:n_alpha,1:n_delta)\n double precision angle_photons(1:n_alpha,1:n_delta)\n double precision pst_photons(1:n_alpha,1:n_delta)\n double precision prod, d, alpha_grid, delta_grid,d_cross\n double precision V(1:3), SAT(1:3), CELL(1:3)\n double precision angle_dat, pst_result\n\tdouble precision RA_STAR, DEC_STAR, R_STAR, STAR(1:3), vprod(1:3)\n double precision angle(n_ang), pst(n_ang)\n double precision min_angle_pst\n\tdouble precision a,b\n\n integer i, j, k\n logical photons_hit, error\n\n common /PST/ angle, pst, min_angle_pst\n\n error = .false.\n\n photons_hit = .false.\n\n R_STAR = 1.d0\n\n\tcall CARTESIAN_COORDINATES(RA_STAR, DEC_STAR, R_STAR, !Input\n & star) !Output\n\n do i = 1, n_alpha\n\n do j = 1, n_delta\n\n if(coord_illum(i,j).eq.illum) then \n alpha_grid= 2.d0*pi*dble(i-1)/dble(n_alpha-1)\n delta_grid= -pi/2.d0 + dble(j-1)*pi/dble(n_delta-1)\n\n call CARTESIAN_COORDINATES(alpha_grid, delta_grid,\n & R_Earth , !Input\n & CELL)\t !Output\n\nc\t\t Get the normalised vector pointing to the cell from the sat.\n call VEC_SUBSTRACTION(SAT, CELL, V)\n call R_3D(V, d)\n\t\t V = V / d\n\n call scalar_product(V, STAR, prod)\n\t\t call vect_product(STAR, V, vprod)\n call R_3D(vprod, d_cross)\n\n if(datan(d_cross/prod).gt.0) then \n coord_photons(i,j) = night !no photons hit the telescope\n else\n photons_hit = .true.\n coord_photons(i,j) = hit !photons hit the telescope\n\n a = datan(d_cross/prod)*RAD\n\t\t b = datan2(d_cross,prod)*RAD\n\n a = pi/2.+datan(d_cross/prod)\n\t\t b = pi/2.-(datan2(d_cross,prod)-pi/2.)\n\n\t\t angle_photons(i,j) = b\n\n\t\t if(include_pst) then\n\t\t\t angle_dat = angle_photons(i,j)\n\nc\t\t\t Check that the point given can actually be observed according\nc\t\t\t to a simple rule: the angle between the line of sight and the\nc\t\t\t Earth cannot be less than the stray light exclusion angle.\n if(angle_dat*RAD.lt. SL_exclusion_angle .or. \n & angle_dat*RAD .gt. 90d0) then\n\t\t\t error = .true.\n endif\n\n\t\t\t if(angle_dat.lt.min_angle_pst) then\n\t\t\t write(*,*)'Angle photons< min angle pst', \n & angle_dat*RAD, min_angle_pst*RAD\n error = .true.\n endif\n\nc\t\t\t Get the value of the PST for that particular LOS angle \n\t\t\t call calcul_pst(angle_dat, pst_result)\n\n\n if(pst_result.lt.pst_limit) then\n write(*,*) 'PST < pst_limit=', pst_limit\n write(*,*) 'angle_photons', angle_dat*RAD\n write(*,*) 'pst_result',pst_result\n error = .true.\n endif\n\n pst_photons(i,j) = pst_result \n endif\n endif\n\n endif\n\n enddo\n enddo\n\n\tif (log_all_data .and. error) then\n\t call write_contamination(coord_photons)\n\t call write_angles(angle_photons)\n\t call write_star(RA_STAR, DEC_STAR)\n\tendif\n\n\tif (log_non_nominal .and. error) then\n\t call write_error_targets(RA_STAR, DEC_STAR)\n\tendif \n\n return\n end\n\nc ==========================================================================\n subroutine TOTAL_PHOTONS_AT_TELESCOPE(coord_photons,angle_photons,\n & pst_photons, SAT,RA_SAT,DEC_SAT, day_night, !Input\n & straylight_flux) !Output\n\n implicit none\n\n include 'constants'\n include 'parameters'\n\n double precision coord_photons(1:n_alpha,1:n_delta),\n & angle_photons(1:n_alpha,1:n_delta), \n & pst_photons(1:n_alpha,1:n_delta), \n & day_night(1:n_alpha,1:n_delta)\n double precision dist(1:n_alpha,1:n_delta),\n & EARTH(1:3), V(1:3)\n double precision d, SAT(1:3), R_SAT\n double precision energy, straylight_flux\n double precision solar_ref, solar_constant_cm\n double precision alpha_grid, delta_grid\n double precision Delta_alpha, Delta_delta\n double precision surf\n double precision RA_SAT, DEC_SAT\n\tdouble precision SphericalDistance\n\tdouble precision angle\n\tdouble precision proj_surf\n integer i,j\n\n\tdouble precision prod\n\n\tDelta_alpha = 2.d0*pi/dble(n_alpha-1)\n\tDelta_delta = pi/dble(n_delta-1)\n\tsurf = R_Earth**2.d0 * Delta_alpha * Delta_delta\n\n\tenergy = 0.d0\n\tstraylight_flux = 0.d0\n\n call R_3D(SAT, R_SAT)\n\n solar_constant_cm = solar_constant/M2 !maximum energy that hit Earth per cm2\n solar_ref = solar_constant_cm * albedo/pi !reflected energy per cm2\n \n do i = 1, n_alpha\n do j = 1, n_delta\n\n if(coord_photons(i,j).eq.hit) then\n\n alpha_grid = 2.d0*pi*dble(i-1)/dble(n_alpha-1)\n delta_grid = -pi/2.d0 + dble(j-1)*pi/dble(n_delta-1)\n\n call CARTESIAN_COORDINATES(alpha_grid, delta_grid,\n & R_Earth , ! Input\n & EARTH) ! Output\n \n call VEC_SUBSTRACTION(SAT, EARTH, V)\n\n call R_3D(V, d)\n\n call scalar_product(V, EARTH, prod) \n\nc\t\t Get the surface area of the projected surface\n\t\t angle = SphericalDistance(RA_SAT, DEC_SAT,\n &\t\t alpha_grid, delta_grid)\n\nc\tThe first angle is angle between cell and the satellite\nc\tThe second angle is the angle between the LOS and the cell\nc\tThe 3rd is for the fact towards high delta we have smaller surface\n\t\t proj_surf = surf*dcos(angle)*abs(prod/(R_Earth*d))\n &\t\t *dcos(delta_grid)\n\n if(include_pst) then\n energy = energy + \n & solar_ref*proj_surf*pst_photons(i,j)*\n & day_night(i,j)/d**2.d0\n else\n energy = energy + \n & solar_ref*proj_surf*angle_photons(i,j)*\n & day_night(i,j)/d**2.d0\n endif \n\n endif\n enddo\n enddo\n\n straylight_flux = energy * pixel !photons se px-1\n\n return\n end\n\nc =========================================================================\n subroutine vect_product(X, Y, Z)\n\n implicit none\n double precision X(1:3), Y(1:3), Z(1:3)\n \n\n Z(1) = X(2)*Y(3) - X(3)*Y(2)\n Z(2) = X(3)*Y(1) - X(1)*Y(3)\n Z(3) = X(1)*Y(2) - X(2)*Y(1)\n\n return\n end\nc ==========================================================================\n subroutine scalar_product(X, Y, z)\n\n implicit none\n double precision X(1:3), Y(1:3), z\n \n\n z = X(1)*Y(1) + X(2)*Y(2) + X(3)*Y(3)\n\n return\n end\n\nc ==========================================================================\n function REV(x)\n\n implicit none\n double precision REV, x\n\n REV = x - idint(x/360.d0)*360.d0\n if(REV.lt.0.d0) REV = REV + 360.d0\n\n return\n end\n\nc ==========================================================================\n function REV_RAD(x)\n\n implicit none\n double precision REV_RAD, x, twopi\n include 'constants'\n\n twopi = 2.d0*pi\n REV_RAD = x - idint(x/twopi)*twopi\n if(REV_RAD.lt.0.d0) REV_RAD = REV_RAD + twopi\n\n return\n end\n\nc =========================================================================\n subroutine RIGHT_ASCENSION(x, y, RA)\n\nc Given the cartesian coordinates it calculates the right ascention\n\n implicit none\n double precision x, y, RA\n \n RA = datan2(y,x)\n\n return\n end\n\nc =========================================================================\n subroutine DECLINATION(x, y, z, DEC)\n\nc Given the cartesian coordinates it calculates the declination\n\n implicit none\n double precision x, y, z, DEC\n\n DEC = datan2(z, sqrt(x**2+y**2))\n\n return\n end\nc ========================================================================= \n subroutine R_3D(X, R)\n\nc Given the cartesian coordinates it calculates the distance\n\n implicit none\n double precision X(1:3), R\n\n R = sqrt(X(1)**2+X(2)**2+X(3)**2)\n\n return\n end\n\nc ========================================================================= \n subroutine CARTESIAN_COORDINATES(alpha, delta, r, !I\n & V) !O\n\n implicit none\n double precision alpha, delta, r\n double precision V(1:3)\n\n V(1) = r*dcos(alpha)*dcos(delta)\n V(2) = r*dsin(alpha)*dcos(delta)\n V(3) = r*dsin(delta)\n\n return\n end\nc ========================================================================= \n subroutine VEC_SUBSTRACTION(V, W, Z)\n\n implicit none\n double precision V(1:3), W(1:3), Z(1:3)\n\n Z(1) = V(1) - W(1)\n Z(2) = V(2) - W(2)\n Z(3) = V(3) - W(3)\n\n return\n end\n \n\nc ========================================================================= \n subroutine distance(R1, R2, D)\n\n implicit none\n double precision R1, R2, D\n\n D = sqrt(R1**2.d0 - R2**2.d0)\n\n return\n end\n\nc ========================================================================= \n subroutine calcul_pst(angle_dat, pst_result)\n\n implicit none\n include 'parameters'\n double precision angle_dat, pst_result\n\n call interp_lineal(angle_dat, pst_result)\n\n return\n end\nc ========================================================================= \n\n subroutine interp_lineal(angle_dat, pst_result)\n \n implicit none\n include 'parameters'\n double precision angle_dat, pst_result\n double precision angle(n_ang), pst(n_ang)\n double precision min_angle_pst\n common /PST/ angle, pst, min_angle_pst\n\n integer i\n\n do i= 1, n_ang-1\n if(angle_dat.ge.angle(i).and.angle_dat.lt.angle(i+1)) then \n pst_result = pst(i) + \n & (angle_dat-angle(i))*(pst(i+1)-pst(i))/(angle(i+1)-angle(i))\n endif\n enddo\n\n return\n end\n\n\n", "meta": {"hexsha": "245a1ed49f53f0fe6a83c9ed096259e53deb24e3", "size": 14578, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "straylight_orbitID_p/CODE/routines.f", "max_stars_repo_name": "kuntzer/SALSA-public", "max_stars_repo_head_hexsha": "79fd601d3999ac977bbc97be010b2c4ef81e4c35", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-07-30T09:59:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-30T09:59:41.000Z", "max_issues_repo_path": "straylight_orbitID_p/CODE/routines.f", "max_issues_repo_name": "kuntzer/SALSA-public", "max_issues_repo_head_hexsha": "79fd601d3999ac977bbc97be010b2c4ef81e4c35", "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": "straylight_orbitID_p/CODE/routines.f", "max_forks_repo_name": "kuntzer/SALSA-public", "max_forks_repo_head_hexsha": "79fd601d3999ac977bbc97be010b2c4ef81e4c35", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-07-30T10:38:54.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-30T10:38:54.000Z", "avg_line_length": 28.5283757339, "max_line_length": 82, "alphanum_fraction": 0.5503498422, "num_tokens": 3836, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218284193595, "lm_q2_score": 0.7248702761768249, "lm_q1q2_score": 0.6682737303797845}} {"text": " double complex function qlLi2omrat(x,y)\n implicit none\n include 'qlconstants.f'\nc expression for dilog(1-(x-i*ep)/(y-i*ep)) for real x and y\nc Hence arguments are typically negative invariants\n double precision x,y,omarg,arg,ddilog\n double complex qllnrat,wlog\n omarg=x/y\n arg=1d0-omarg\n if (arg .gt. 1d0) then\n wlog=qllnrat(x,y)\n qlLi2omrat=dcmplx(pisqo6-ddilog(omarg))-log(arg)*wlog\n else \n qlLi2omrat=dcmplx(ddilog(arg))\n endif\n\n return \n end\n", "meta": {"hexsha": "bd04913c4f43adf46562d7ce10d44dc2472c6c67", "size": 530, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "vendor/IREGI/src/qcdloop/ql/qlLi2omrat.f", "max_stars_repo_name": "valassi/mg5amc_test", "max_stars_repo_head_hexsha": "2e04f23353051f64e1604b23105fe3faabd32869", "max_stars_repo_licenses": ["NCSA"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-10-23T14:37:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-22T20:59:02.000Z", "max_issues_repo_path": "vendor/IREGI/src/qcdloop/ql/qlLi2omrat.f", "max_issues_repo_name": "valassi/mg5amc_test", "max_issues_repo_head_hexsha": "2e04f23353051f64e1604b23105fe3faabd32869", "max_issues_repo_licenses": ["NCSA"], "max_issues_count": 64, "max_issues_repo_issues_event_min_datetime": "2015-06-24T15:08:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-25T04:59:32.000Z", "max_forks_repo_path": "vendor/IREGI/src/qcdloop/ql/qlLi2omrat.f", "max_forks_repo_name": "valassi/mg5amc_test", "max_forks_repo_head_hexsha": "2e04f23353051f64e1604b23105fe3faabd32869", "max_forks_repo_licenses": ["NCSA"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2015-05-04T22:15:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-06T10:04:40.000Z", "avg_line_length": 27.8947368421, "max_line_length": 64, "alphanum_fraction": 0.6320754717, "num_tokens": 172, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9425067163548471, "lm_q2_score": 0.7090191276365462, "lm_q1q2_score": 0.6682552898214993}} {"text": "!###################################################################################\n!#\n!# CubeZ\n!#\n!# Copyright (C) 2018-2020 Research Institute for Information Technology(RIIT), Kyushu University.\n!# All rights reserved.\n!#\n!###################################################################################\n\n!> ********************************************************************\n!! @brief 2x2\u306e\u884c\u5217\u53cd\u8ee2\n!! @param [in,out] d RHS vector(d) -> \u89e3\u30d9\u30af\u30c8\u30eb(x) (in-place)\n!! @param [in] a \u4fc2\u6570\n!! @param [in] c \u4fc2\u6570\n!! @note Ax = d 9 fp\n!! A=|1 c1| x={x1, x2}, d={d1, d2}\n!! |a2 1|\n!<\nsubroutine matx2(d, a, c)\nimplicit none\ndouble precision, dimension(3) :: d, a, c\ndouble precision :: a2, c1, j, d1, d2\n a2 = a(2)\n c1 = c(1)\n j = 1.0 / (1.0 - a2 * c1)\n d1 = d(1)\n d2 = d(2)\n d(1) = (d1 - c1 * d2) * j\n d(2) = (d2 - a2 * d1) * j\n\nreturn\nend subroutine matx2\n\n\n!> ********************************************************************\n!! @brief 3x3\u306e\u884c\u5217\u53cd\u8ee2\n!! @param [in,out] d RHS vector(d) -> \u89e3\u30d9\u30af\u30c8\u30eb(x) (in-place)\n!! @param [in] a \u4fc2\u6570\n!! @param [in] c \u4fc2\u6570\n!! @note Ax = d 25 fp\n!! A=| 1 c1 0 |\n!! | a2 1 c2 |\n!! | 0 a3 1 |\n!<\nsubroutine matx3(d, a, c)\nimplicit none\ndouble precision, dimension(3) :: d, a, c\ndouble precision :: j, d1, d2, d3, a2, a3, c1, c2\n\n a2 = a(2)\n a3 = a(3)\n c1 = c(1)\n c2 = c(2)\n d1 = d(1)\n d2 = d(2)\n d3 = d(3)\n j = 1.0 / (1.0 - c2 * a3 - c1 * a2)\n d(1) = ( d1 * (3.0-c2*a3) - c1*d2 ) * j\n d(2) = (1.0 - d1*a2 + 2.0*d2 - c2*d3) * j\n d(3) = (1.0 + 2.0*d3 - a3*d2 - a2*c1) * j\n\nreturn\nend subroutine matx3\n\n\n\n!> ********************************************************************\n!! @brief PCR\n!! @param [in] nx \u914d\u5217\u9577\n!! @param [in] g \u30ac\u30a4\u30c9\u30bb\u30eb\u9577\n!! @param [in,out] d RHS vector -> \u89e3\u30d9\u30af\u30c8\u30eb (in-place)\n!! @param [in] cf \u4fc2\u6570\n!! @param [in] w U_1 vector\n!! @param [in,out] flop flop count\n!<\nsubroutine lsor_pcr_kij (sz, idx, g, pn, x, a, c, d, a1, c1, d1, msk, rhs, omg, res, flop)\nimplicit none\ninteger :: i, j, k, g, kl, kr, s, p, pn\ninteger :: ist, ied, jst, jed, kst, ked\ninteger, dimension(3) :: sz\ninteger, dimension(0:5) :: idx\ndouble precision :: flop, res\nreal, dimension(1-g:sz(3)+g, 1-g:sz(1)+g, 1-g:sz(2)+g) :: x, msk, rhs\nreal, dimension(1-g:sz(3)+g, 1-g:sz(1)+g, 1-g:sz(2)+g) :: a, c, d, a1, c1, d1\nreal :: r, ap, cp, e, omg, pp, dp\n!dir$ assume_aligned x:64, msk:64, rhs:64, a:64, c:64, d:64, a1:64, c1:64, d1:64\n\nist = idx(0)\nied = idx(1)\njst = idx(2)\njed = idx(3)\nkst = idx(4)\nked = idx(5)\n\nr = 1.0/6.0\n\nflop = flop + dble( &\n(jed-jst+1)*(ied-ist+1)* ( &\n(ked-kst+1)*( 6.0 & ! Source\n+ pn * 14.0 & ! PCR\n+ 6.0 ) & ! Relaxation\n+ 6.0 & ! BC\n) )\n\n\n!$OMP PARALLEL\n\n! Reflesh coef. due to override\n\n!$OMP DO SCHEDULE(static) collapse(2)\ndo j=jst, jed\ndo i=ist, ied\ndo k=kst+1, ked\na(k,i,j) = -r\nend do\nend do\nend do\n!$OMP END DO\n\n!$OMP DO SCHEDULE(static) collapse(2)\ndo j=jst, jed\ndo i=ist, ied\ndo k=kst, ked-1\nc(k,i,j) = -r\nend do\nend do\nend do\n!$OMP END DO\n\n!$OMP DO SCHEDULE(static) collapse(2)\ndo j=jst, jed\ndo i=ist, ied\na(kst,i,j) = 0.0\nend do\nend do\n!$OMP END DO\n\n!$OMP DO SCHEDULE(static) collapse(2)\ndo j=jst, jed\ndo i=ist, ied\nc(ked,i,j) = 0.0\nend do\nend do\n!$OMP END DO\n\n\nres = 0.0\n\n\n!$OMP DO SCHEDULE(static) collapse(2) &\n!$OMP private(kl, kr, ap, cp, e, s, p, k, pp, dp) &\n!$OMP reduction(+:res)\ndo j=jst, jed\ndo i=ist, ied\n\n! Source\n!dir$ vector aligned\n!dir$ simd\ndo k = kst, ked\nd(k, i, j) = ( ( x(k, i , j-1) &\n+ x(k, i , j+1) &\n+ x(k, i-1, j ) &\n+ x(k, i+1, j ) ) * r + rhs(k, i, j) ) &\n* msk(k, i, j)\nend do\n\n! BC\nd(kst, i, j) = ( d(kst, i, j) + rhs(kst-1, i, j) * r ) * msk(kst, i, j)\nd(ked, i, j) = ( d(ked, i, j) + rhs(ked+1, i, j) * r ) * msk(ked, i, j)\n\n\n! PCR\ndo p=1, pn\ns = 2**(p-1)\n\n!dir$ vector aligned\n!dir$ simd\ndo k = kst, ked\nkl = max(k-s, kst-1)\nkr = min(k+s, ked+1)\nap = a(k,i,j)\ncp = c(k,i,j)\ne = 1.0 / ( 1.0 - ap * c(kl,i,j) - cp * a(kr,i,j) )\na1(k,i,j) = -e * ap * a(kl,i,j)\nc1(k,i,j) = -e * cp * c(kr,i,j)\nd1(k,i,j) = e * ( d(k,i,j) - ap * d(kl,i,j) - cp * d(kr,i,j) )\nend do\n\n!dir$ vector aligned\n!dir$ simd\ndo k = kst, ked\na(k,i,j) = a1(k,i,j)\nc(k,i,j) = c1(k,i,j)\nd(k,i,j) = d1(k,i,j)\nend do\n\nend do\n\n! Relaxation\n!dir$ vector aligned\n!dir$ simd\ndo k = kst, ked\npp = x(k, i, j)\ndp = ( d(k, i, j) - pp ) * omg * msk(k, i, j)\nx(k, i, j) = pp + dp\nres = res + real(dp*dp, kind=8)\nend do\n\nend do\nend do\n!$OMP END DO\n\n!$OMP END PARALLEL\n\nreturn\nend subroutine lsor_pcr_kij\n\n\n\n\n!> ********************************************************************\n!! @brief PCR\n!! @param [in] nx \u914d\u5217\u9577\n!! @param [in] g \u30ac\u30a4\u30c9\u30bb\u30eb\u9577\n!! @param [in,out] d RHS vector -> \u89e3\u30d9\u30af\u30c8\u30eb (in-place)\n!! @param [in] cf \u4fc2\u6570\n!! @param [in] w U_1 vector\n!! @param [in,out] flop flop count\n!! @note lsor_pcr_kij()\u304b\u3089\u306e\u5909\u66f4 \u6700\u7d42\u6bb5\u3092\u76f4\u63a5\u53cd\u8ee2\n!<\nsubroutine lsor_pcr_kij2 (sz, idx, g, pn, x, a, c, d, a1, c1, d1, msk, rhs, omg, res, flop)\nimplicit none\ninteger :: i, j, k, g, kl, kr, s, p, pn\ninteger :: ist, ied, jst, jed, kst, ked\ninteger, dimension(3) :: sz\ninteger, dimension(0:5) :: idx\ndouble precision :: flop, res\nreal, dimension(1-g:sz(3)+g, 1-g:sz(1)+g, 1-g:sz(2)+g) :: x, msk, rhs\nreal, dimension(1-g:sz(3)+g, 1-g:sz(1)+g, 1-g:sz(2)+g) :: a, c, d, a1, c1, d1\nreal :: r, ap, cp, e, omg, pp, dp\ndouble precision, dimension(3) :: aa, cc, dd\n!dir$ assume_aligned x:64, msk:64, rhs:64, a:64, c:64, d:64, a1:64, c1:64, d1:64\n!DIR$ ATTRIBUTES FORCEINLINE::matx2, matx3\n\nist = idx(0)\nied = idx(1)\njst = idx(2)\njed = idx(3)\nkst = idx(4)\nked = idx(5)\n\nr = 1.0/6.0\ns = 2**(pn-1)\n\nflop = flop + dble( &\n(jed-jst+1)*(ied-ist+1)* ( &\n(ked-kst+1)* 6.0 & ! Source\n+ (ked-kst+1)*(pn-1)*14.0 & ! PCR\n+ 2*s*9.0 &\n+ (ked-kst-2*s+1)*25.0 &\n+ (ked-kst+1)*6.0 & ! Relaxation\n+ 6.0 ) & ! BC\n)\n\n\n!$OMP PARALLEL\n\n! Reflesh coef. due to override\n\n!$OMP DO SCHEDULE(static) collapse(2)\ndo j=jst, jed\ndo i=ist, ied\ndo k=kst+1, ked\na(k,i,j) = -r\nend do\nend do\nend do\n!$OMP END DO\n\n!$OMP DO SCHEDULE(static) collapse(2)\ndo j=jst, jed\ndo i=ist, ied\ndo k=kst, ked-1\nc(k,i,j) = -r\nend do\nend do\nend do\n!$OMP END DO\n\n!$OMP DO SCHEDULE(static) collapse(2)\ndo j=jst, jed\ndo i=ist, ied\na(kst,i,j) = 0.0\nend do\nend do\n!$OMP END DO\n\n!$OMP DO SCHEDULE(static) collapse(2)\ndo j=jst, jed\ndo i=ist, ied\nc(ked,i,j) = 0.0\nend do\nend do\n!$OMP END DO\n\n\nres = 0.0\n\n\n\n!$OMP DO SCHEDULE(static) collapse(2) &\n!$OMP private(kl, kr, ap, cp, e, s, p, k, pp, dp, aa, cc, dd) &\n!$OMP reduction(+:res)\ndo j=jst, jed\ndo i=ist, ied\n\n! Source\n!dir$ vector aligned\n!dir$ simd\ndo k = kst, ked\nd(k, i, j) = ( ( x(k, i , j-1) &\n+ x(k, i , j+1) &\n+ x(k, i-1, j ) &\n+ x(k, i+1, j ) ) * r + rhs(k, i, j) ) &\n* msk(k, i, j)\nend do\n\n! BC\nd(kst, i, j) = ( d(kst, i, j) + rhs(kst-1, i, j) * r ) * msk(kst, i, j)\nd(ked, i, j) = ( d(ked, i, j) + rhs(ked+1, i, j) * r ) * msk(ked, i, j)\n\n\n! PCR \u6700\u7d42\u6bb5\u306e\u4e00\u3064\u624b\u524d\u3067\u505c\u6b62\ndo p=1, pn-1\ns = 2**(p-1)\n\n!dir$ vector aligned\n!dir$ simd\ndo k = kst, ked\nkl = max(k-s, kst-1)\nkr = min(k+s, ked+1)\nap = a(k,i,j)\ncp = c(k,i,j)\ne = 1.0 / ( 1.0 - ap * c(kl,i,j) - cp * a(kr,i,j) )\na1(k,i,j) = -e * ap * a(kl,i,j)\nc1(k,i,j) = -e * cp * c(kr,i,j)\nd1(k,i,j) = e * ( d(k,i,j) - ap * d(kl,i,j) - cp * d(kr,i,j) )\nend do\n\n!dir$ vector aligned\n!dir$ simd\ndo k = kst, ked\na(k,i,j) = a1(k,i,j)\nc(k,i,j) = c1(k,i,j)\nd(k,i,j) = d1(k,i,j)\nend do\n\nend do ! p\u53cd\u5fa9\n\n\n! \u6700\u7d42\u6bb5\u306e\u53cd\u8ee2\ns = 2**(pn-1)\n\n!dir$ vector aligned\n!dir$ simd\ndo k = kst, ked\nkl = max(k-s, kst-1)\nkr = min(k+s, ked+1)\n\nif (k ********************************************************************\n!! @brief PCR\n!! @param [in] nx \u914d\u5217\u9577\n!! @param [in] g \u30ac\u30a4\u30c9\u30bb\u30eb\u9577\n!! @param [in,out] d RHS vector -> \u89e3\u30d9\u30af\u30c8\u30eb (in-place)\n!! @param [in] cf \u4fc2\u6570\n!! @param [in] w U_1 vector\n!! @param [in,out] flop flop count\n!! @note lsor_pcr_kij2()\u304b\u3089\u306e\u5909\u66f4 \u5206\u5272\n!<\nsubroutine lsor_pcr_kij3 (sz, idx, g, pn, x, a, c, d, a1, c1, d1, msk, rhs, omg, res, flop)\nimplicit none\ninteger :: i, j, k, g, kl, kr, s, p, pn, t\ninteger :: ist, ied, jst, jed, kst, ked\ninteger, dimension(3) :: sz\ninteger, dimension(0:5) :: idx\ndouble precision :: flop, res\nreal, dimension(1-g:sz(3)+g, 1-g:sz(1)+g, 1-g:sz(2)+g) :: x, msk, rhs\nreal, dimension(1-g:sz(3)+g, 1-g:sz(1)+g, 1-g:sz(2)+g) :: a, c, d, a1, c1, d1\nreal :: r, ap, cp, e, omg, pp, dp\ndouble precision, dimension(3) :: aa, cc, dd\n!dir$ assume_aligned x:64, msk:64, rhs:64, a:64, c:64, d:64, a1:64, c1:64, d1:64\n!DIR$ ATTRIBUTES FORCEINLINE::matx2, matx3\n\nist = idx(0)\nied = idx(1)\njst = idx(2)\njed = idx(3)\nkst = idx(4)\nked = idx(5)\n\nr = 1.0/6.0\nt = 2**(pn-1)\n\nflop = flop + dble( &\n(jed-jst+1)*(ied-ist+1)* ( &\n(ked-kst+1)* 6.0 & ! Source\n+ (ked-kst+1)*(pn-1)*14.0 & ! PCR\n+ 2*t*9.0 &\n+ (ked-kst-2*t+1)*25.0 &\n+ (ked-kst+1)*6.0 & ! Relaxation\n+ 6.0 ) & ! BC\n)\n\n\n!$OMP PARALLEL\n\n! Refresh coef. due to override\n\n!$OMP DO SCHEDULE(static) collapse(2)\ndo j=jst, jed\ndo i=ist, ied\ndo k=kst+1, ked\na(k,i,j) = -r\nend do\nend do\nend do\n!$OMP END DO\n\n!$OMP DO SCHEDULE(static) collapse(2)\ndo j=jst, jed\ndo i=ist, ied\ndo k=kst, ked-1\nc(k,i,j) = -r\nend do\nend do\nend do\n!$OMP END DO\n\n!$OMP DO SCHEDULE(static) collapse(2)\ndo j=jst, jed\ndo i=ist, ied\na(kst,i,j) = 0.0\nend do\nend do\n!$OMP END DO\n\n!$OMP DO SCHEDULE(static) collapse(2)\ndo j=jst, jed\ndo i=ist, ied\nc(ked,i,j) = 0.0\nend do\nend do\n!$OMP END DO\n\n\nres = 0.0\n\n\n\n!$OMP DO SCHEDULE(static) collapse(2) &\n!$OMP private(kl, kr, ap, cp, e, s, p, k, pp, dp, aa, cc, dd) &\n!$OMP reduction(+:res)\ndo j=jst, jed\ndo i=ist, ied\n\n! Source\n!dir$ vector aligned\n!dir$ simd\ndo k = kst, ked ! 6 fp\nd(k, i, j) = ( ( x(k, i , j-1) &\n+ x(k, i , j+1) &\n+ x(k, i-1, j ) &\n+ x(k, i+1, j ) ) * r + rhs(k, i, j) ) &\n* msk(k, i, j)\nend do\n\n! BC\nd(kst, i, j) = ( d(kst, i, j) + rhs(kst-1, i, j) * r ) * msk(kst, i, j)\nd(ked, i, j) = ( d(ked, i, j) + rhs(ked+1, i, j) * r ) * msk(ked, i, j)\n\n\n! PCR \u6700\u7d42\u6bb5\u306e\u4e00\u3064\u624b\u524d\u3067\u505c\u6b62\ndo p=1, pn-1\ns = 2**(p-1)\n\n!dir$ vector aligned\n!dir$ simd\ndo k = kst, ked ! 14 fp\nkl = max(k-s, kst-1)\nkr = min(k+s, ked+1)\nap = a(k,i,j)\ncp = c(k,i,j)\ne = 1.0 / ( 1.0 - ap * c(kl,i,j) - cp * a(kr,i,j) )\na1(k,i,j) = -e * ap * a(kl,i,j)\nc1(k,i,j) = -e * cp * c(kr,i,j)\nd1(k,i,j) = e * ( d(k,i,j) - ap * d(kl,i,j) - cp * d(kr,i,j) )\nend do\n\n!dir$ vector aligned\n!dir$ simd\ndo k = kst, ked\na(k,i,j) = a1(k,i,j)\nc(k,i,j) = c1(k,i,j)\nd(k,i,j) = d1(k,i,j)\nend do\n\nend do ! p\u53cd\u5fa9\n\n\n! \u6700\u7d42\u6bb5\u306e\u53cd\u8ee2\ns = 2**(pn-1)\n\n!dir$ vector aligned\n!dir$ simd\ndo k = kst, kst+s-1\nkl = max(k-s, kst-1)\nkr = min(k+s, ked+1)\ncc(1) = real( c(k ,i,j), kind=8)\naa(2) = real( a(kr,i,j), kind=8)\ndd(1) = real( d(k ,i,j), kind=8)\ndd(2) = real( d(kr,i,j), kind=8)\ncall matx2(dd, aa, cc) ! 9 fp\nd1(k ,i,j) = real( dd(1), kind=4)\nd1(kr,i,j) = real( dd(2), kind=4)\nend do\n\n\n!dir$ vector aligned\n!dir$ simd\ndo k = kst+s, ked-s\nkl = max(k-s, kst-1)\nkr = min(k+s, ked+1)\ncc(1) = real( c(kr,i,j), kind=8)\naa(2) = real( a(k ,i,j), kind=8)\ncc(2) = real( c(k ,i,j), kind=8)\naa(3) = real( a(kl,i,j), kind=8)\ndd(1) = real( d(kr,i,j), kind=8)\ndd(2) = real( d(k ,i,j), kind=8)\ndd(3) = real( d(kl,i,j), kind=8)\ncall matx3(dd, aa, cc) ! 25 fp\nd1(kr,i,j) = real( dd(1), kind=4)\nd1(k ,i,j) = real( dd(2), kind=4)\nd1(kl,i,j) = real( dd(3), kind=4)\nend do\n\n\n!dir$ vector aligned\n!dir$ simd\ndo k = ked-s+1, ked\nkl = max(k-s, kst-1)\nkr = min(k+s, ked+1)\ncc(1) = real( c(kl,i,j), kind=8)\naa(2) = real( a(k ,i,j), kind=8)\ndd(1) = real( d(kl,i,j), kind=8)\ndd(2) = real( d(k ,i,j), kind=8)\ncall matx2(dd, aa, cc) ! 9 fp\nd1(kl,i,j) = real( dd(1), kind=4)\nd1(k ,i,j) = real( dd(2), kind=4)\nend do\n\n\n! a_{i-1} x_{i-2} + x_{i-1} + c_{i-1} x_i = d_{i-1}\n! a_{i} x_{i-1} + x_{i} + c_{i} x_{i+1} = d_{i}\n! a_{i+1} x_{i} + x_{i+1} + c_{i+1} x_{i+2} = d_{i+1}\n\n\n! Relaxation\n!dir$ vector aligned\n!dir$ simd\ndo k = kst, ked ! 6 fp\npp = x(k, i, j)\ndp = ( d1(k, i, j) - pp ) * omg * msk(k, i, j)\nx(k, i, j) = pp + dp\nres = res + real(dp*dp, kind=8)\nend do\n\nend do\nend do\n!$OMP END DO\n\n!$OMP END PARALLEL\n\nreturn\nend subroutine lsor_pcr_kij3\n\n\n\n!> ********************************************************************\n!! @brief PCR\n!! @param [in] nx \u914d\u5217\u9577\n!! @param [in] g \u30ac\u30a4\u30c9\u30bb\u30eb\u9577\n!! @param [in,out] d RHS vector -> \u89e3\u30d9\u30af\u30c8\u30eb (in-place)\n!! @param [in] cf \u4fc2\u6570\n!! @param [in] w U_1 vector\n!! @param [in,out] flop flop count\n!! @note lsor_pcr_kij4()\u304b\u3089\u306e\u5909\u66f4 matx2, matx3\u3092\u624b\u52d5\u5c55\u958b\n!<\nsubroutine lsor_pcr_kij4 (sz, idx, g, pn, x, a, c, d, a1, c1, d1, msk, rhs, omg, res, flop)\nimplicit none\ninteger :: i, j, k, g, kl, kr, s, p, pn\ninteger :: ist, ied, jst, jed, kst, ked\ninteger, dimension(3) :: sz\ninteger, dimension(0:5) :: idx\ndouble precision :: flop, res\nreal, dimension(1-g:sz(3)+g, 1-g:sz(1)+g, 1-g:sz(2)+g) :: x, msk, rhs\nreal, dimension(1-g:sz(3)+g, 1-g:sz(1)+g, 1-g:sz(2)+g) :: a, c, d, a1, c1, d1\nreal :: r, ap, cp, e, omg, pp, dp\ndouble precision :: jj, dd1, dd2, dd3, aa2, aa3, cc1, cc2, f1, f2, f3\n!dir$ assume_aligned x:64, msk:64, rhs:64, a:64, c:64, d:64, a1:64, c1:64, d1:64\n\nist = idx(0)\nied = idx(1)\njst = idx(2)\njed = idx(3)\nkst = idx(4)\nked = idx(5)\n\nr = 1.0/6.0\ns = 2**(pn-1)\n\nflop = flop + dble( &\n (jed-jst+1)*(ied-ist+1)* ( &\n (ked-kst+1)* 6.0 & ! Source\n + (ked-kst+1)*(pn-1)*14.0 & ! PCR\n + 2*s*9.0 &\n + (ked-kst-2*s+1)*25.0 &\n + (ked-kst+1)*6.0 & ! Relaxation\n + 6.0 ) & ! BC\n )\n\n\n!$OMP PARALLEL\n\n! Reflesh coef. due to override\n\n!$OMP DO SCHEDULE(static) collapse(2)\ndo j=jst, jed\ndo i=ist, ied\ndo k=kst+1, ked\na(k,i,j) = -r\nend do\nend do\nend do\n!$OMP END DO\n\n!$OMP DO SCHEDULE(static) collapse(2)\ndo j=jst, jed\ndo i=ist, ied\ndo k=kst, ked-1\nc(k,i,j) = -r\nend do\nend do\nend do\n!$OMP END DO\n\n!$OMP DO SCHEDULE(static) collapse(2)\ndo j=jst, jed\ndo i=ist, ied\na(kst,i,j) = 0.0\nend do\nend do\n!$OMP END DO\n\n!$OMP DO SCHEDULE(static) collapse(2)\ndo j=jst, jed\ndo i=ist, ied\nc(ked,i,j) = 0.0\nend do\nend do\n!$OMP END DO\n\n\nres = 0.0\n\n\n\n!$OMP DO SCHEDULE(static) collapse(2) &\n!$OMP private(kl, kr, ap, cp, e, s, p, k, pp, dp) &\n!$OMP private(jj, dd1, dd2, dd3, aa2, aa3, cc1, cc2, f1, f2, f3) &\n!$OMP reduction(+:res)\ndo j=jst, jed\ndo i=ist, ied\n\n! Source\n!dir$ vector aligned\n!dir$ simd\ndo k = kst, ked\nd(k, i, j) = ( ( x(k, i , j-1) &\n+ x(k, i , j+1) &\n+ x(k, i-1, j ) &\n+ x(k, i+1, j ) ) * r + rhs(k, i, j) ) &\n* msk(k, i, j)\nend do\n\n! BC\nd(kst, i, j) = ( d(kst, i, j) + rhs(kst-1, i, j) * r ) * msk(kst, i, j)\nd(ked, i, j) = ( d(ked, i, j) + rhs(ked+1, i, j) * r ) * msk(ked, i, j)\n\n\n! PCR \u6700\u7d42\u6bb5\u306e\u4e00\u3064\u624b\u524d\u3067\u505c\u6b62\ndo p=1, pn-1\ns = 2**(p-1)\n\n!dir$ vector aligned\n!dir$ simd\ndo k = kst, ked\nkl = max(k-s, kst-1)\nkr = min(k+s, ked+1)\nap = a(k,i,j)\ncp = c(k,i,j)\ne = 1.0 / ( 1.0 - ap * c(kl,i,j) - cp * a(kr,i,j) )\na1(k,i,j) = -e * ap * a(kl,i,j)\nc1(k,i,j) = -e * cp * c(kr,i,j)\nd1(k,i,j) = e * ( d(k,i,j) - ap * d(kl,i,j) - cp * d(kr,i,j) )\nend do\n\n!dir$ vector aligned\n!dir$ simd\ndo k = kst, ked\na(k,i,j) = a1(k,i,j)\nc(k,i,j) = c1(k,i,j)\nd(k,i,j) = d1(k,i,j)\nend do\n\nend do ! p\u53cd\u5fa9\n\n\n! \u6700\u7d42\u6bb5\u306e\u53cd\u8ee2\ns = 2**(pn-1)\n\n!dir$ vector aligned\n!dir$ simd\ndo k = kst, kst+s-1\nkl = max(k-s, kst-1)\nkr = min(k+s, ked+1)\ncc1 = real( c(k ,i,j), kind=8)\naa2 = real( a(kr,i,j), kind=8)\nf1 = real( d(k ,i,j), kind=8)\nf2 = real( d(kr,i,j), kind=8)\njj = 1.0 / (1.0 - aa2 * cc1)\ndd1 = (f1 - cc1 * f2) * jj\ndd2 = (f2 - aa2 * f1) * jj\nd1(k ,i,j) = real( dd1, kind=4)\nd1(kr,i,j) = real( dd2, kind=4)\nend do\n\n\n!dir$ vector aligned\n!dir$ simd\ndo k = kst+s, ked-s\nkl = max(k-s, kst-1)\nkr = min(k+s, ked+1)\ncc1 = real( c(kr,i,j), kind=8)\naa2 = real( a(k ,i,j), kind=8)\ncc2 = real( c(k ,i,j), kind=8)\naa3 = real( a(kl,i,j), kind=8)\nf1 = real( d(kr,i,j), kind=8)\nf2 = real( d(k ,i,j), kind=8)\nf3 = real( d(kl,i,j), kind=8)\njj = 1.0 / (1.0 - cc2 * aa3 - cc1 * aa2)\ndd1 = ( f1 * (3.0-cc2*aa3) - cc1*f2 ) * jj\ndd2 = (1.0 - f1*aa2 + 2.0*f2 - cc2*f3) * jj\ndd3 = (1.0 + 2.0*f3 - aa3*f2 - aa2*cc1) * jj\nd1(kr,i,j) = real( dd1, kind=4)\nd1(k ,i,j) = real( dd2, kind=4)\nd1(kl,i,j) = real( dd3, kind=4)\nend do\n\n\n!dir$ vector aligned\n!dir$ simd\ndo k = ked-s+1, ked\nkl = max(k-s, kst-1)\nkr = min(k+s, ked+1)\ncc1 = real( c(kl,i,j), kind=8)\naa2 = real( a(k ,i,j), kind=8)\nf1 = real( d(kl,i,j), kind=8)\nf2 = real( d(k ,i,j), kind=8)\njj = 1.0 / (1.0 - aa2 * cc1)\ndd1 = (f1 - cc1 * f2) * jj\ndd2 = (f2 - aa2 * f1) * jj\nd1(kl,i,j) = real( dd1, kind=4)\nd1(k ,i,j) = real( dd2, kind=4)\nend do\n\n\n! a_{i-1} x_{i-2} + x_{i-1} + c_{i-1} x_i = d_{i-1}\n! a_{i} x_{i-1} + x_{i} + c_{i} x_{i+1} = d_{i}\n! a_{i+1} x_{i} + x_{i+1} + c_{i+1} x_{i+2} = d_{i+1}\n\n\n! Relaxation\n!dir$ vector aligned\n!dir$ simd\ndo k = kst, ked\npp = x(k, i, j)\ndp = ( d1(k, i, j) - pp ) * omg * msk(k, i, j)\nx(k, i, j) = pp + dp\nres = res + real(dp*dp, kind=8)\nend do\n\nend do\nend do\n!$OMP END DO\n\n!$OMP END PARALLEL\n\nreturn\nend subroutine lsor_pcr_kij4\n\n\n\n!********************************************************************************\nsubroutine lsor_pcr_kij5 (sz, idx, g, pn, x, msk, rhs, omg, res, flop)\nimplicit none\n! arguments\ninteger, dimension(3) :: sz\ninteger, dimension(0:5) :: idx\ninteger :: g, pn\nreal, dimension(1-g:sz(3)+g, 1-g:sz(1)+g, 1-g:sz(2)+g) :: x, msk, rhs\nreal :: omg\ndouble precision :: res, flop\n! work\ninteger :: i, j, k, kl, kr, s, p\ninteger :: ist, ied, jst, jed, kst, ked\nreal, dimension(1-g:sz(3)+g) :: a, c, d, a1, c1, d1\nreal :: r, ap, cp, e, pp, dp\ndouble precision :: jj, dd1, dd2, dd3, aa2, aa3, cc1, cc2, f1, f2, f3\n!dir$ assume_aligned x:64, msk:64, rhs:64, a:64, c:64, d:64, a1:64, c1:64, d1:64\n\nist = idx(0)\nied = idx(1)\njst = idx(2)\njed = idx(3)\nkst = idx(4)\nked = idx(5)\n\nr = 1.0/6.0\ns = 2**(pn-1)\n\nflop = flop + dble( &\n(jed-jst+1)*(ied-ist+1)* ( &\n(ked-kst+1)* 6.0 & ! Source\n+ (ked-kst+1)*(pn-1)*14.0 & ! PCR\n+ 2*s*9.0 &\n+ (ked-kst-2*s+1)*25.0 &\n+ (ked-kst+1)*6.0 & ! Relaxation\n+ 6.0 ) & ! BC\n)\n\n\n!$OMP PARALLEL\n\nres = 0.0\n\n!$OMP DO SCHEDULE(static) collapse(2) &\n!$OMP private(kl, kr, ap, cp, e, s, p, k, pp, dp) &\n!$OMP private(jj, dd1, dd2, dd3, aa2, aa3, cc1, cc2, f1, f2, f3) &\n!$OMP private(a, c, d, a1, c1, d1) &\n!$OMP reduction(+:res)\ndo j=jst, jed\ndo i=ist, ied\n\n! Reflesh coef. due to override\na(kst) = 0.0\ndo k=kst+1, ked\na(k) = -r\nend do\n\ndo k=kst, ked-1\nc(k) = -r\nend do\nc(ked) = 0.0\n\n! Source\n!dir$ vector aligned\n!dir$ simd\ndo k = kst, ked\nd(k) = ( ( x(k, i , j-1) &\n+ x(k, i , j+1) &\n+ x(k, i-1, j ) &\n+ x(k, i+1, j ) ) * r + rhs(k, i, j) ) &\n* msk(k, i, j)\nend do\n\n! BC\nd(kst) = ( d(kst) + rhs(kst-1, i, j) * r ) * msk(kst, i, j)\nd(ked) = ( d(ked) + rhs(ked+1, i, j) * r ) * msk(ked, i, j)\n\n\n! PCR \u6700\u7d42\u6bb5\u306e\u4e00\u3064\u624b\u524d\u3067\u505c\u6b62\ndo p=1, pn-1\ns = 2**(p-1)\n\n!dir$ vector aligned\n!dir$ simd\ndo k = kst, ked\nkl = max(k-s, kst-1)\nkr = min(k+s, ked+1)\nap = a(k)\ncp = c(k)\ne = 1.0 / ( 1.0 - ap * c(kl) - cp * a(kr) )\na1(k) = -e * ap * a(kl)\nc1(k) = -e * cp * c(kr)\nd1(k) = e * ( d(k) - ap * d(kl) - cp * d(kr) )\nend do\n\n!dir$ vector aligned\n!dir$ simd\ndo k = kst, ked\na(k) = a1(k)\nc(k) = c1(k)\nd(k) = d1(k)\nend do\n\nend do ! p\u53cd\u5fa9\n\n\n! \u6700\u7d42\u6bb5\u306e\u53cd\u8ee2\ns = 2**(pn-1)\n\n!dir$ vector aligned\n!dir$ simd\ndo k = kst, kst+s-1\nkl = max(k-s, kst-1)\nkr = min(k+s, ked+1)\ncc1 = real( c(k ), kind=8)\naa2 = real( a(kr), kind=8)\nf1 = real( d(k ), kind=8)\nf2 = real( d(kr), kind=8)\njj = 1.0 / (1.0 - aa2 * cc1)\ndd1 = (f1 - cc1 * f2) * jj\ndd2 = (f2 - aa2 * f1) * jj\nd1(k ) = real( dd1, kind=4)\nd1(kr) = real( dd2, kind=4)\nend do\n\n\n!dir$ vector aligned\n!dir$ simd\ndo k = kst+s, ked-s\nkl = max(k-s, kst-1)\nkr = min(k+s, ked+1)\ncc1 = real( c(kr), kind=8)\naa2 = real( a(k ), kind=8)\ncc2 = real( c(k ), kind=8)\naa3 = real( a(kl), kind=8)\nf1 = real( d(kr), kind=8)\nf2 = real( d(k ), kind=8)\nf3 = real( d(kl), kind=8)\njj = 1.0 / (1.0 - cc2 * aa3 - cc1 * aa2)\ndd1 = ( f1 * (3.0-cc2*aa3) - cc1*f2 ) * jj\ndd2 = (1.0 - f1*aa2 + 2.0*f2 - cc2*f3) * jj\ndd3 = (1.0 + 2.0*f3 - aa3*f2 - aa2*cc1) * jj\nd1(kr) = real( dd1, kind=4)\nd1(k ) = real( dd2, kind=4)\nd1(kl) = real( dd3, kind=4)\nend do\n\n\n!dir$ vector aligned\n!dir$ simd\ndo k = ked-s+1, ked\nkl = max(k-s, kst-1)\nkr = min(k+s, ked+1)\ncc1 = real( c(kl), kind=8)\naa2 = real( a(k ), kind=8)\nf1 = real( d(kl), kind=8)\nf2 = real( d(k ), kind=8)\njj = 1.0 / (1.0 - aa2 * cc1)\ndd1 = (f1 - cc1 * f2) * jj\ndd2 = (f2 - aa2 * f1) * jj\nd1(kl) = real( dd1, kind=4)\nd1(k ) = real( dd2, kind=4)\nend do\n\n\n! a_{i-1} x_{i-2} + x_{i-1} + c_{i-1} x_i = d_{i-1}\n! a_{i} x_{i-1} + x_{i} + c_{i} x_{i+1} = d_{i}\n! a_{i+1} x_{i} + x_{i+1} + c_{i+1} x_{i+2} = d_{i+1}\n\n\n! Relaxation\n!dir$ vector aligned\n!dir$ simd\ndo k = kst, ked\npp = x(k, i, j)\ndp = ( d1(k) - pp ) * omg * msk(k, i, j)\nx(k, i, j) = pp + dp\nres = res + real(dp*dp, kind=8)\nend do\n\nend do\nend do\n!$OMP END DO\n\n!$OMP END PARALLEL\n\nreturn\nend subroutine lsor_pcr_kij5\n\n\n\n!********************************************************************************\nsubroutine lsor_pcr_kij6 (sz, idx, g, pn, x, msk, rhs, omg, res, flop)\nimplicit none\n!args\ninteger, dimension(3) :: sz\ninteger, dimension(0:5) :: idx\ninteger :: g, pn\nreal, dimension(1-g:sz(3)+g, 1-g:sz(1)+g, 1-g:sz(2)+g) :: x, msk, rhs\nreal :: omg\ndouble precision :: res, flop\n! work\ninteger :: i, j, k, kl, kr, s, p\ninteger :: ist, ied, jst, jed, kst, ked\nreal, dimension(1-g:sz(3)+g) :: a, c, d, a1, c1, d1\nreal :: r, ap, cp, e, pp, dp\nreal :: jj, dd1, dd2, dd3, aa2, aa3, cc1, cc2, f1, f2, f3\n!dir$ assume_aligned x:64, msk:64, rhs:64, a:64, c:64, d:64, a1:64, c1:64, d1:64\n\nist = idx(0)\nied = idx(1)\njst = idx(2)\njed = idx(3)\nkst = idx(4)\nked = idx(5)\n\nr = 1.0/6.0\ns = 2**(pn-1)\n\nflop = flop + dble( &\n(jed-jst+1)*(ied-ist+1)* ( &\n(ked-kst+1)* 6.0 & ! Source\n+ (ked-kst+1)*(pn-1)*14.0 & ! PCR\n+ 2*s*9.0 &\n+ (ked-kst-2*s+1)*25.0 &\n+ (ked-kst+1)*6.0 & ! Relaxation\n+ 6.0 ) & ! BC\n)\n\n\n!$OMP PARALLEL\n\nres = 0.0\n\n!$OMP DO SCHEDULE(static) collapse(2) &\n!$OMP private(kl, kr, ap, cp, e, s, p, k, pp, dp) &\n!$OMP private(jj, dd1, dd2, dd3, aa2, aa3, cc1, cc2, f1, f2, f3) &\n!$OMP private(a, c, d, a1, c1, d1) &\n!$OMP reduction(+:res)\ndo j=jst, jed\ndo i=ist, ied\n\n! Reflesh coef. due to override\na(kst) = 0.0\ndo k=kst+1, ked\na(k) = -r\nend do\n\ndo k=kst, ked-1\nc(k) = -r\nend do\nc(ked) = 0.0\n\n! Source\n!dir$ vector aligned\n!dir$ simd\ndo k = kst, ked\nd(k) = ( ( x(k, i , j-1) &\n+ x(k, i , j+1) &\n+ x(k, i-1, j ) &\n+ x(k, i+1, j ) ) * r + rhs(k, i, j) ) &\n* msk(k, i, j)\nend do\n\n! BC\nd(kst) = ( d(kst) + rhs(kst-1, i, j) * r ) * msk(kst, i, j)\nd(ked) = ( d(ked) + rhs(ked+1, i, j) * r ) * msk(ked, i, j)\n\n\n! PCR \u6700\u7d42\u6bb5\u306e\u4e00\u3064\u624b\u524d\u3067\u505c\u6b62\ndo p=1, pn-1\ns = 2**(p-1)\n\n!dir$ vector aligned\n!dir$ simd\ndo k = kst, ked\nkl = max(k-s, kst-1)\nkr = min(k+s, ked+1)\nap = a(k)\ncp = c(k)\ne = 1.0 / ( 1.0 - ap * c(kl) - cp * a(kr) )\na1(k) = -e * ap * a(kl)\nc1(k) = -e * cp * c(kr)\nd1(k) = e * ( d(k) - ap * d(kl) - cp * d(kr) )\nend do\n\n!dir$ vector aligned\n!dir$ simd\ndo k = kst, ked\na(k) = a1(k)\nc(k) = c1(k)\nd(k) = d1(k)\nend do\n\nend do ! p\u53cd\u5fa9\n\n\n! \u6700\u7d42\u6bb5\u306e\u53cd\u8ee2\ns = 2**(pn-1)\n\n!dir$ vector aligned\n!dir$ simd\ndo k = kst, kst+s-1\nkl = max(k-s, kst-1)\nkr = min(k+s, ked+1)\ncc1 = c(k)\naa2 = a(kr)\nf1 = d(k)\nf2 = d(kr)\njj = 1.0 / (1.0 - aa2 * cc1)\ndd1 = (f1 - cc1 * f2) * jj\ndd2 = (f2 - aa2 * f1) * jj\nd1(k ) = dd1\nd1(kr) = dd2\nend do\n\n\n!dir$ vector aligned\n!dir$ simd\ndo k = kst+s, ked-s\nkl = max(k-s, kst-1)\nkr = min(k+s, ked+1)\ncc1 = c(kr)\naa2 = a(k)\ncc2 = c(k)\naa3 = a(kl)\nf1 = d(kr)\nf2 = d(k)\nf3 = d(kl)\njj = 1.0 / (1.0 - cc2 * aa3 - cc1 * aa2)\ndd1 = ( f1 * (3.0-cc2*aa3) - cc1*f2 ) * jj\ndd2 = (1.0 - f1*aa2 + 2.0*f2 - cc2*f3) * jj\ndd3 = (1.0 + 2.0*f3 - aa3*f2 - aa2*cc1) * jj\nd1(kr) = dd1\nd1(k ) = dd2\nd1(kl) = dd3\nend do\n\n\n!dir$ vector aligned\n!dir$ simd\ndo k = ked-s+1, ked\nkl = max(k-s, kst-1)\nkr = min(k+s, ked+1)\ncc1 = c(kl)\naa2 = a(k)\nf1 = d(kl)\nf2 = d(k)\njj = 1.0 / (1.0 - aa2 * cc1)\ndd1 = (f1 - cc1 * f2) * jj\ndd2 = (f2 - aa2 * f1) * jj\nd1(kl) = dd1\nd1(k ) = dd2\nend do\n\n\n! a_{i-1} x_{i-2} + x_{i-1} + c_{i-1} x_i = d_{i-1}\n! a_{i} x_{i-1} + x_{i} + c_{i} x_{i+1} = d_{i}\n! a_{i+1} x_{i} + x_{i+1} + c_{i+1} x_{i+2} = d_{i+1}\n\n\n! Relaxation\n!dir$ vector aligned\n!dir$ simd\ndo k = kst, ked\npp = x(k, i, j)\ndp = ( d1(k) - pp ) * omg * msk(k, i, j)\nx(k, i, j) = pp + dp\nres = res + real(dp*dp, kind=8)\nend do\n\nend do\nend do\n!$OMP END DO\n\n!$OMP END PARALLEL\n\nreturn\nend subroutine lsor_pcr_kij6\n\n", "meta": {"hexsha": "dc32e2700c84c4c2618b12f025d261e491c49f50", "size": 27525, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/cz_f90/cz_lsor.f90", "max_stars_repo_name": "TM-MT/CubeZ", "max_stars_repo_head_hexsha": "4df0cd3d068a0344e20fceec0a900d8f252b8f08", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/cz_f90/cz_lsor.f90", "max_issues_repo_name": "TM-MT/CubeZ", "max_issues_repo_head_hexsha": "4df0cd3d068a0344e20fceec0a900d8f252b8f08", "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/cz_f90/cz_lsor.f90", "max_forks_repo_name": "TM-MT/CubeZ", "max_forks_repo_head_hexsha": "4df0cd3d068a0344e20fceec0a900d8f252b8f08", "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.0023980815, "max_line_length": 108, "alphanum_fraction": 0.4718982743, "num_tokens": 12581, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007394, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.6682165239526386}} {"text": "program hash_function_test\n\n ! This program performs speed tests and collision tests for the integer\n ! and string hash functions in hash_functions.f90 module\n\n !============================================================================\n use hash_functions\n\n integer, parameter :: slen = 10 ! number of string bytes\n real :: t1, t2, tsum\n character(6) :: name\n character(slen):: str\n integer :: ierror, key\n integer :: i, j, ncol, k, strn(slen), base, a, b\n integer :: tbl_size, nhash\n\n integer, dimension(27) :: asciis\n integer, dimension(:), allocatable :: keys, hash\n character(slen), dimension(:), allocatable :: keys_s\n\n procedure(sdbm_64_int), pointer :: fhash_i => null()\n procedure(sdbm_64_str), pointer :: fhash_s => null()\n\n !============================================================================\n ! Hash speed test: Integers\n !============================================================================\n\n nhash = 50000000\n tbl_size = int(nhash/0.7)+1\n\n allocate(keys(nhash),hash(nhash),STAT=ierror)\n if(ierror /= 0) write(*,\"('Mem alloc error')\")\n\n write(*,\"('Hash speed test: ',i12,' integers')\") nhash\n\n do k = 1,7\n select case(k)\n case(1); fhash_i => djb2_64_int; name = 'djb2 '\n case(2); fhash_i => djb2a_64_int; name = 'djb2a '\n case(3); fhash_i => sdbm_64_int; name = 'sdbm '\n case(4); fhash_i => fnv1_64_int; name = 'fnv1 '\n case(5); fhash_i => fnv1a_64_int; name = 'fnv1a '\n case(6); fhash_i => mmh2_64_int; name = 'mmh2 '\n case(7); fhash_i => mmh3_64_int; name = 'mmh3 '\n end select\n\n call cpu_time(t1)\n do i = 1,nhash\n key = fhash_i(i)\n hash(i) = modulo(key,tbl_size)+1\n end do\n call cpu_time(t2)\n tsum = t2-t1\n\n write(*,\"(a6,' kiloHashes per second: ',i8)\") name,int(nhash/(1000*tsum))\n end do\n\n !============================================================================\n ! Hash collision test: Integers\n !============================================================================\n\n nhash = 50000\n tbl_size = int(nhash/0.7)+1\n\n write(*,\"(/)\")\n write(*,\"('Hash collision test: ',i12,' integers modulo ',i12)\") nhash, tbl_size\n do k = 1,7\n select case(k)\n case(1); fhash_i => djb2_64_int; name = 'djb2 '\n case(2); fhash_i => djb2a_64_int; name = 'djb2a '\n case(3); fhash_i => sdbm_64_int; name = 'sdbm '\n case(4); fhash_i => fnv1_64_int; name = 'fnv1 '\n case(5); fhash_i => fnv1a_64_int; name = 'fnv1a '\n case(6); fhash_i => mmh2_64_int; name = 'mmh2 '\n case(7); fhash_i => mmh3_64_int; name = 'mmh3 '\n end select\n\n do i = 1,nhash\n key = fhash_i(i)\n hash(i) = modulo(key,tbl_size)+1 ! Pretend as if it is fitting into a table\n end do\n\n ncol = 0\n do i = 1,nhash-1\n if(hash(i) == 0) cycle\n do j = i+1,nhash\n if(hash(j)==0) then\n cycle\n else if(hash(i)==hash(j)) then\n ncol = ncol + 1\n hash(j) = 0\n end if\n end do\n end do\n write(*,\"(a6,' Number of collisions: ',i8)\") name,ncol\n end do\n\n !============================================================================\n ! Hash speed test: Strings\n !============================================================================\n\n nhash = 50000000\n tbl_size = int(nhash/0.7)+1\n\n write(*,\"(/)\")\n write(*,\"('Hash speed test: ',i12,' ',i2,'-byte strings')\") nhash, slen\n\n deallocate(keys,hash)\n allocate(keys_s(nhash),hash(nhash),STAT=ierror)\n if(ierror /= 0) write(*,\"('Mem alloc error')\")\n\n ! Use base conversion to make nhash strings which utilize character indices\n ! 1 through 'base' from among ASCII 32 & 97-122 (space + lower case letters)\n ! e.g. base 5 would use space + a,b,c,d to make strings ' ' through 'ddd'\n asciis(1) = 32\n asciis(2:27) = [(i,i=97,122)]\n\n base = 7 ! number of ascii characters to use/base to convert to\n\n do i = 1,nhash\n b = i\n do j = 1,slen ! Do j=1,slen Euclidean divisions\n a = b/base ! integer division, get seed for next digit\n strn(j) = b - a*base +1 ! Fortran is indexed to 1, modulo is indexed to 0\n b = a ! set b = a to start on next digit\n end do\n\n do j = 1,slen ! Convert from index to ASCII code to character\n str(j:j) = achar(asciis(strn(j)))\n end do\n\n keys_s(i) = str\n\n end do\n\n do k = 1,7\n select case(k)\n case(1); fhash_s => djb2_64_str; name = 'djb2 '\n case(2); fhash_s => djb2a_64_str; name = 'djb2a '\n case(3); fhash_s => sdbm_64_str; name = 'sdbm '\n case(4); fhash_s => fnv1_64_str; name = 'fnv1 '\n case(5); fhash_s => fnv1a_64_str; name = 'fnv1a '\n case(6); fhash_s => mmh2_64_str; name = 'mmh2 '\n case(7); fhash_s => mmh3_64_str; name = 'mmh3 '\n end select\n\n call cpu_time(t1)\n do i = 1,nhash\n key = fhash_s(keys_s(i))\n hash(i) = modulo(key,tbl_size)+1\n end do\n call cpu_time(t2)\n tsum = t2-t1\n\n write(*,\"(a6,' kiloHashes per second: ',i8)\") name,int(nhash/(1000*tsum))\n end do\n\n !============================================================================\n ! Hash collision test: Strings\n !============================================================================\n\n nhash = 50000\n tbl_size = int(nhash/0.7)+1\n\n write(*,\"(/)\")\n write(*,\"('Hash collision test: ',i12,' ',i2,'-byte strings modulo ',i12)\") nhash, slen, tbl_size\n do k = 1,7\n select case(k)\n case(1); fhash_s => djb2_64_str; name = 'djb2 '\n case(2); fhash_s => djb2a_64_str; name = 'djb2a '\n case(3); fhash_s => sdbm_64_str; name = 'sdbm '\n case(4); fhash_s => fnv1_64_str; name = 'fnv1 '\n case(5); fhash_s => fnv1a_64_str; name = 'fnv1a '\n case(6); fhash_s => mmh2_64_str; name = 'mmh2 '\n case(7); fhash_s => mmh3_64_str; name = 'mmh3 '\n end select\n\n do i = 1,nhash\n key = fhash_s(keys_s(i))\n hash(i) = modulo(key,tbl_size)+1\n end do\n\n ncol = 0\n do i = 1,nhash-1\n if(hash(i) == 0) cycle\n do j = i+1,nhash\n if(hash(j)==0) then\n cycle\n else if(hash(i)==hash(j)) then\n ncol = ncol + 1\n hash(j) = 0\n end if\n end do\n end do\n write(*,\"(a6,' Number of collisions: ',i8)\") name,ncol\n end do\n\n write(*,\"(//,'Done...')\")\n read(*,\"(a)\") str\n\nend program\n", "meta": {"hexsha": "d46831220876880e41ff0efa967d9eca4c2ab4ce", "size": 6699, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "hash_function_test.f90", "max_stars_repo_name": "dbartilson/fh_table", "max_stars_repo_head_hexsha": "131228fffbe4a20e4b21c1f5691918cb5b575e8e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-04-25T13:53:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-27T11:16:15.000Z", "max_issues_repo_path": "hash_function_test.f90", "max_issues_repo_name": "dbartilson/fh_table", "max_issues_repo_head_hexsha": "131228fffbe4a20e4b21c1f5691918cb5b575e8e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-07-27T11:15:37.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-27T19:36:39.000Z", "max_forks_repo_path": "hash_function_test.f90", "max_forks_repo_name": "dbartilson/fh_table", "max_forks_repo_head_hexsha": "131228fffbe4a20e4b21c1f5691918cb5b575e8e", "max_forks_repo_licenses": ["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.1633663366, "max_line_length": 100, "alphanum_fraction": 0.4838035528, "num_tokens": 2127, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190939, "lm_q2_score": 0.7772998663336157, "lm_q1q2_score": 0.6682165127737874}} {"text": "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! Information about last revision of $RCSfile: m_constants.f90,v $:\n! $Revision: 1.3 $\n! $Author: jorissen $\n! $Date: 2010/12/16 18:30:30 $\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!*************************************************************************\nmodule constants\n\n implicit none\n\n ! Symbolic names for kind types of 4-, 2-, and 1-byte integers:\n integer, parameter :: I4 = selected_int_kind(9)\n integer, parameter :: I2 = selected_int_kind(4)\n integer, parameter :: I1 = selected_int_kind(2)\n ! Symbolic names for kind types of single- and double-precision reals:\n integer, parameter :: SP = kind(1.0)\n integer, parameter :: DP = kind(1.0D0)\n ! Symbolic names for kind types of single- and double-precision complex:\n integer, parameter :: SZ = kind((1.0,1.0))\n integer, parameter :: DZ = kind((1.0D0,1.0D0))\n ! Symbolic name for kind type of default logical:\n integer, parameter :: LGT = kind(.true.)\n private i1,i2,i4,sp,dp,sz,dz,lgt\n\n real(dp), parameter :: pi2 = 6.283185307179586476925286766559_dp\n real(dp), parameter :: pi = 3.1415926535897932384626433832795_dp\n real(dp), parameter :: one = 1.0_dp\n real(dp), parameter :: zero = 0.0_dp\n real(dp), parameter :: third = 1.0_dp/3.0_dp\n real(dp), parameter :: raddeg = 180.0_dp/pi\n ! kf = fa/rs with fa = (9*pi/4)**third, see Ash&Merm, pg 37\n real(dp), parameter :: fa = 1.919158292677512811_dp\n complex(dz), parameter :: coni = (0.0_dp,1.0_dp)\n real(dp), parameter :: bohr = 0.529177249_dp\n real(dp), parameter :: ryd = 13.605698_dp\n real(dp), parameter :: hart = 2.0_dp*ryd\n real(dp), parameter :: alpinv = 137.03598956_dp\n real(dp), parameter :: alphfs = 1.0_dp/alpinv\n\n ! from moduleseels.f \n ! conversion from eV to Ry :\n real(dp), parameter :: ev2Ry = 1.0_dp/13.6058_dp\n ! h/2pi c in units eV a.u.\n real(dp), parameter :: hbarc_eV = 1973.2708_dp/0.529177_dp\n real(dp), parameter :: hbarc_atomic = 137.04188_dp ! i.e. in Ha, hence 27.2 times smaller than above\n ! electron rest mass times c^2 in au (ie, 1 * alfa * alfa), times eV/Ha (27.2)\n real(dp), parameter :: MeC2 = 511004.0_dp\n REAL(dp), parameter :: HOnSqrtTwoMe = 23.1761_dp\n ! Me c / hbar = 2.5896 10^12 m^(-1) = 137.04188 a.u.^(-1)\n real(dp), parameter :: MeCOnHbar = 137.04188_dp\n\nend module constants\n", "meta": {"hexsha": "600e7d11a870807020284e57ef1aa5f2a94f17d5", "size": 2358, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/OPCONSAT/oca_constants.f90", "max_stars_repo_name": "xraypy/feff85exafs", "max_stars_repo_head_hexsha": "ec8dcb07ca8ee034d0fa7431782074f0f65357a5", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2016-01-05T21:29:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:59:17.000Z", "max_issues_repo_path": "src/OPCONSAT/oca_constants.f90", "max_issues_repo_name": "xraypy/feff85exafs", "max_issues_repo_head_hexsha": "ec8dcb07ca8ee034d0fa7431782074f0f65357a5", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 17, "max_issues_repo_issues_event_min_datetime": "2015-01-04T18:37:30.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-07T12:06:12.000Z", "max_forks_repo_path": "src/OPCONSAT/oca_constants.f90", "max_forks_repo_name": "xraypy/feff85exafs", "max_forks_repo_head_hexsha": "ec8dcb07ca8ee034d0fa7431782074f0f65357a5", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2016-01-05T21:29:26.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T13:11:01.000Z", "avg_line_length": 42.8727272727, "max_line_length": 103, "alphanum_fraction": 0.6174724343, "num_tokens": 803, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637469145053, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6682165066986193}} {"text": "c program DRSSFIT\nc>> 1996-07-03 DRSSFIT Krogh Special code for C conversion.\nc>> 1996-06-19 DRSSFIT Krogh Changes in formats for C conversion.\nc>> 1996-05-28 DRSSFIT Krogh Added external & removed Fortran 90 syntax\nc>> 1994-10-19 DRSSFIT Krogh Changes to use M77CON\nc>> 1992-11-18 DRSSFIT CLL Changed order of arguments in SSFIT.\nc>> 1992-10-29 C. L. Lawson, JPL\nc Demonstration driver for SSFIT, SSVAL, SSQUAD, SSTOP, SPVAL, SPQUAD\nc ------------------------------------------------------------------\nc--S replaces \"?\": DR?SFIT, ?SFIT, ?SVAL, ?SQUAD, ?STOP, ?PVAL, ?PQUAD\nc--& ?PRPL\nc ------------------------------------------------------------------\nc++ Code for .C. is inactive\nc%% long int k;\nc++ End\n integer I, IERR, NXY, KORDER, MPC, NCOEF, NDERIV, NPC, NT, LDW\n parameter(NXY = 12, NCOEF=8, KORDER=4, NT = NCOEF+KORDER,LDW = 10)\n parameter(MPC = NCOEF-KORDER+1)\n external SSVAL, SSQUAD, SPVAL, SPQUAD\n real BDIF(NCOEF*KORDER), SSVAL, SSQUAD, SPVAL, SPQUAD\n real BCOEF(NCOEF), PCOEF(MPC*KORDER)\n real SD(1), SIGFAC, TKNOTS(NT), W(LDW,KORDER+1)\n real X(NXY), XI(MPC+1), Y(NXY), YFIT, Z\n character IMAGE*31\n data X / 2.E0, 4.E0, 6.E0, 8.E0,10.E0,12.E0,\n * 14.E0,16.E0,18.E0,20.E0,22.E0,24.E0/\n data Y /2.2E0,4.0E0,5.0E0,4.6E0,2.8E0,2.7E0,\n * 3.8E0,5.1E0,6.1E0,6.3E0,5.0E0,2.0E0/\n data TKNOTS / 4*2.0E0, 6.4E0, 10.8E0, 15.2E0, 19.6E0, 4*24.0E0 /\n data NDERIV / 0 /\n data SD(1) / -1.0E0 /\nc ------------------------------------------------------------------\n print'('' DRSSFIT''/ '' Demo driver for SSFIT, SSVAL, SSQUAD,'',\n * '' SSTOP, SPVAL, SPQUAD'')'\n print'(/'' KORDER ='',i3,'', NCOEF ='',i3)', KORDER, NCOEF\nc++ Code for ~.C. is active\n print'('' TKNOTS() = '',4f10.5/(14x,4f10.5))',\n * (TKNOTS(I), I = 1, NT)\nc++ Code for .C. is inactive\nc%% printf( \"\\n TKNOTS() = \");\nc%% for (i = 1; i <= NT+3; i+=4){\nc%% for (k = i; k <= min( i+3, NT ); k++)\nc%% printf( \"%10.5f\", Tknots[k] );\nc%% if (i + 3 < NT) printf( \"\\n \");}\nc++ End\n call SSFIT(X, Y, SD, NXY, KORDER, NCOEF, TKNOTS, BCOEF,\n * SIGFAC,IERR, LDW, W)\nc++ Code for ~.C. is active\n print'(/'' After call to SSFIT:''/'' IERR ='',i5,\n * '', SIGFAC ='', f10.5 //'' BCOEF() = '',\n * 4f10.5/(13x,4f10.5))', IERR, SIGFAC, (BCOEF(I),I=1,NCOEF)\nc++ Code for .C. is inactive\nc%% printf( \"\\n After call to SSFIT:\\n IERR =%5ld, SIGFAC =\"\nc%% \"%10.5f\\n\\n BCOEF() = \", ierr, sigfac);\nc%% for (i = 1; i <= NCOEF+3; i+=4){\nc%% for (k = i; k <= min( i+3, NCOEF ); k++)\nc%% printf( \"%10.5f\", Bcoef[k] );\nc%% if (i + 3 < NCOEF) printf( \"\\n \");}\nc++ End\n print'(/'' Evaluating fitted spline function using SSVAL:'')'\n print'(/\n * '' I X Y YFIT R=Y-YFIT YFIT''/)'\n \n do 20 I=1,NXY\n YFIT= SSVAL(KORDER, NCOEF, TKNOTS, BCOEF, X(I), NDERIV)\n call SPRPL(YFIT, '*', IMAGE, 31, 1.9e0, 6.3e0, .true.)\n print'(3x,i2,f6.0,2f9.3,f10.3,3x,a31)',\n * I, X(I), Y(I), YFIT, Y(I)-YFIT, IMAGE\n 20 continue\n \n Z = SSQUAD(KORDER, NCOEF, TKNOTS, BCOEF, 5.0e0, 20.0e0)\n print'(/'' Integral from 5.0 to 20.0 using SSQUAD:'',f12.5)',Z\n \n call SSTOP(KORDER, NCOEF, TKNOTS, BCOEF, BDIF, NPC, XI, PCOEF)\n print'(/\n * '' Using SSTOP to convert from B-spline basis to power basis.'')'\n print'('' NPC ='',i3)',NPC\nc++ Code for ~.C. is active\n print'('' XI() = '',4f10.5/(14x,4f10.5))',(XI(I),I=1,NPC+1)\n print'('' PCOEF() = '',4f10.5/(14x,4f10.5))',\n * (PCOEF(I),I=1,NPC*KORDER)\nc++ Code for .C. is inactive\nc%% printf( \" XI() = \");\nc%% for (i = 1; i <= (npc + 1); i+=4){\nc%% for (k = i; k <= min( i+3, npc+1 ); k++)\nc%% printf( \"%10.5f\", Xi[k] );\nc%% if (i <= npc) printf( \"\\n \");}\nc%% printf( \"\\n PCOEF() = \");\nc%% for (i = 1; i <= (npc*KORDER); i+=4){\nc%% for (k = i; k <= min( i+3, npc*KORDER ); k++)\nc%% printf( \"%10.5f\", Pcoef[k] );\nc%% if (i < npc*KORDER) printf( \"\\n \");}\nc++ End\n print'(/'' Evaluating fitted spline function using SPVAL:'')'\n print'(/\n * '' I X Y YFIT R=Y-YFIT YFIT''/)'\n \n do 40 I=1,NXY\n YFIT= SPVAL(KORDER, NPC, XI, PCOEF, X(I), NDERIV)\n call SPRPL(YFIT, '*', IMAGE, 31, 1.9e0, 6.3e0, .true.)\n print'(3x,i2,f6.0,2f9.3,f10.3,3x,a31)',\n * I, X(I), Y(I), YFIT, Y(I)-YFIT, IMAGE\n 40 continue\n \n Z = SPQUAD(KORDER, NPC, XI, PCOEF, 5.0e0, 20.0e0)\n print'(/'' Integral from 5.0 to 20.0 using SPQUAD:'',f12.5)',Z\n end\n", "meta": {"hexsha": "51c0ff861e3aee91a769aaa22d08b3ac6d693da5", "size": 4828, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drssfit.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drssfit.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drssfit.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": 44.7037037037, "max_line_length": 72, "alphanum_fraction": 0.4803231152, "num_tokens": 1964, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099167, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.6682165050583914}} {"text": "program test_utilities\n use utilities\n implicit none\n integer, parameter :: M = 3, N = 4\n real :: A(M,N)\n\n call random_number(A)\n A = A - 0.5\n print*, \"A =\"\n call print_matrix(A)\nend program\n", "meta": {"hexsha": "46786d5afdd15ab9f4e824a4bbb9dcd65c6799fa", "size": 231, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "docs/src/test_utilities.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_utilities.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_utilities.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": 19.25, "max_line_length": 40, "alphanum_fraction": 0.5497835498, "num_tokens": 66, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8244619436290698, "lm_q2_score": 0.8104789063814617, "lm_q1q2_score": 0.6682090144256227}} {"text": "program test_fftw3_wrapper\n use, intrinsic :: iso_c_binding\n use m_boundary_type\n use m_fft_wrapper\n use m_fftw3_wrapper_1d\n implicit none\n\n print *, \"test_fftw31d periodic\"\n call test_fftw31d(63, BoundaryType_Periodic)\n\n print *, \"test_fftw31d dirichlet\"\n call test_fftw31d(63, BoundaryType_Dirichlet)\n\n print *, \"test_fftw31d neumman\"\n call test_fftw31d(63, BoundaryType_Neumann)\n\n print *, \"test_fftw31d dirichlet neumman\"\n call test_fftw31d(63, BoundaryType_Dirichlet_Neumann)\n\n print *, \"test_fftw31d neumman dirichlet\"\n call test_fftw31d(63, BoundaryType_Neumann_Dirichlet)\n\ncontains\n\n subroutine test_fftw31d(n, boundary_type)\n integer, intent(in):: n\n integer, intent(in) :: boundary_type\n\n double precision, allocatable :: original(:), forwarded(:), backwarded(:)\n integer :: i\n\n type(t_FFTW3Executor1d) :: fft\n double precision :: diff\n\n allocate (original(n))\n allocate (forwarded(n))\n allocate (backwarded(n))\n\n do i = 1, n\n original(i) = sin(1.0d0*i/n*2*3.14)\n end do\n\n fft%boundary_type = boundary_type\n\n fft = new_FFTW3Executor1d(n, boundary_type)\n\n call fft%forward(original, forwarded)\n call fft%backward(forwarded, backwarded)\n\n diff = sum(abs(backwarded(:) - original(:))) / size(original)\n\n call fft%destroy\n\n print *, \"Diff =\", diff\n end subroutine\n\nend program\n", "meta": {"hexsha": "42d630fa9fde4ad94be7b4743135b3d6b77549e9", "size": 1471, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/test_fftw3_wrapper.f90", "max_stars_repo_name": "Nkzono99/mpifft-solver", "max_stars_repo_head_hexsha": "e1ccf0595718145caf8e57bf1d0f6bf5a17dfd9b", "max_stars_repo_licenses": ["MIT"], "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/test_fftw3_wrapper.f90", "max_issues_repo_name": "Nkzono99/mpifft-solver", "max_issues_repo_head_hexsha": "e1ccf0595718145caf8e57bf1d0f6bf5a17dfd9b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-01-20T21:56:49.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-08T00:52:53.000Z", "max_forks_repo_path": "test/test_fftw3_wrapper.f90", "max_forks_repo_name": "Nkzono99/mpifft-solver", "max_forks_repo_head_hexsha": "e1ccf0595718145caf8e57bf1d0f6bf5a17dfd9b", "max_forks_repo_licenses": ["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.3620689655, "max_line_length": 81, "alphanum_fraction": 0.658735554, "num_tokens": 414, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.6682090023299148}} {"text": " function norm_1(T)\n implicit none\n \n type(Tensor1) :: T\n real(kind=8) :: norm_1\n \n norm_1 = sqrt(sum((T%a)**2))\n \n end function norm_1\n \n function norm_2(T)\n implicit none\n \n type(Tensor2) :: T\n real(kind=8) :: norm_2\n \n norm_2 = sqrt(T**T)\n \n end function norm_2\n \n function norm_2s(T)\n implicit none\n \n type(Tensor2s) :: T\n real(kind=8) :: norm_2s\n \n norm_2s = sqrt(T**T)\n \n end function norm_2s", "meta": {"hexsha": "d200705f189531d21a1c8a52b215ca22ce695a51", "size": 593, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ttb/libnorm.f", "max_stars_repo_name": "kengwit/ttb", "max_stars_repo_head_hexsha": "e3e41fdc0a3b47a45f762d8d89dafce3ace838f4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 41, "max_stars_repo_stars_event_min_datetime": "2018-02-27T06:31:19.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-30T07:58:45.000Z", "max_issues_repo_path": "ttb/libnorm.f", "max_issues_repo_name": "kengwit/ttb", "max_issues_repo_head_hexsha": "e3e41fdc0a3b47a45f762d8d89dafce3ace838f4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 22, "max_issues_repo_issues_event_min_datetime": "2017-12-01T07:47:36.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-16T05:42:06.000Z", "max_forks_repo_path": "ttb/libnorm.f", "max_forks_repo_name": "kengwit/ttb", "max_forks_repo_head_hexsha": "e3e41fdc0a3b47a45f762d8d89dafce3ace838f4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-07-12T01:45:20.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-25T08:03:13.000Z", "avg_line_length": 20.4482758621, "max_line_length": 36, "alphanum_fraction": 0.4350758853, "num_tokens": 157, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.743168019989179, "lm_q1q2_score": 0.6681982576934129}} {"text": "*..............................................................\n\n!-------------------------------------------------------------------------\n! NASA/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !\n!-------------------------------------------------------------------------\n!BOP\n!\n! !ROUTINE: ODS_Julian() --- Returns the Julian day\n! \n! !DESCRIPTION:\n! \\label{ODS:Julian}\n! The routine returns the Julian day number based on the\n! calendar date. The algorithm was adopted from Press et al.\n! The Julian day number on May 23, 1968 is 2,440,000. The\n! year zero is treated as the year 1 since the year 0 does\n! not exist.\n!\n! \\bigskip {\\bf Reference:}\n! \\begin{description}\n! \\item Press, William H., Saul A. Teukolsky, William T.\n! Vetterling and Brian P. Flannery, 1992: {\\em Numerical\n! Recipes in Fortran}, 2nd Ed. Cambridge University\n! Press, New York, NY, 963pp.\n! \\end{description}\n!\n! !INTERFACE: \n!\n integer function ODS_Julian ( CalDate )\n!\n! !INPUT PARAMETERS:\n implicit NONE\n integer CalDate ! Calendar date in the format YYYYMMDD\n ! where YYYY is the year, MM is the\n ! month and DD is the day. A negative\n ! number implies that the year is B.C.\n!\n! !OUTPUT PARAMETERS:\n! integer JulDay Julian day number\n!\n! !SEE ALSO:\n! ODS_Min2Cal() - Convert minutes since a given reference to\n! \"calendar\" date and time\n! ODS_Cal2Min() - Convert \"calendar\" date and time to minutes\n! since a given reference\n! ODS_Time2Cal() - converts ODS \"time\" attribute to \"calendar\"\n! date and time\n! ODS_Cal2Time() - converts \"calendar\" date and time to ODS\n! time attribute\n! ODS_CalDat() - calculates the \"calendar\" date and time\n! from the Julian day\n!\n! !REVISION HISTORY: \n! 13Apr1998 C. Redder Original code. Routine was developed to\n! create ODS version 2.00\n! 19Nov1999 C. Redder Added a latex label in and moved the\n! subroutine statement into the prologue.\n! 06Dec1999 C. Redder Corrections to the documentation in the\n! prologue.\n! 10May2000 C. Redder Updated prologue to include the routines\n! ODS_Min2Cal and ODS_Cal2Min in the \n! \"See Also\" list\n!\n!EOP\n!-------------------------------------------------------------------------\n\n* Other variables\n* ---------------\n integer Year\n integer Month\n integer Day\n integer iGreg ! Gregorian Calendar adopted Oct 12, 1582\n parameter ( iGreg = 15 + 31 * ( 10 + 12 * 1582 ) )\n integer JulDay\n integer jy, jm, ja\n\n Year = CalDate / 10000\n Month = mod ( CalDate, 10000 ) / 100\n Day = mod ( CalDate, 100 )\n \n* Change year 0 to year 1\n* -----------------------\n if ( Year .eq. 0 ) Year = 1\n\n* Account for the nonexisting year 0\n* ----------------------------------\n if ( Year .lt. 0 ) Year = Year + 1\n\n if ( Month .gt. 2 ) then\n jy = Year\n jm = Month + 1\n\n else\n jy = Year - 1\n jm = Month + 13\n\n endif\n\n JulDay = int ( 365.25 * jy )\n . + int ( 30.6001 * jm )\n . + Day + 1720995\n\n* Test whether to change to Gregorian Celendar\n* --------------------------------------------\n if ( Day + 31 * ( Month + 12 * Year ) .ge. iGreg) then\n ja = int ( 0.01 * jy )\n Julday = JulDay + 2 - ja + int ( 0.25 * ja )\n\n endif\n\n ODS_Julian = JulDay\n\n return\n end\n", "meta": {"hexsha": "00faa715039b8091dbf7b045aaf97b77ef93689e", "size": 3814, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/Shared/GMAO_Shared/GMAO_ods/ods_julian.f", "max_stars_repo_name": "GEOS-ESM/AeroApps", "max_stars_repo_head_hexsha": "874dad6f34420c014d98eccbe81a061bdc0110cf", "max_stars_repo_licenses": ["NASA-1.3", "ECL-2.0", "Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-12-02T14:23:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-31T15:39:30.000Z", "max_issues_repo_path": "GMAO_ods/ods_julian.f", "max_issues_repo_name": "GEOS-ESM/GMAO_Shared", "max_issues_repo_head_hexsha": "022af23abbc7883891006b57379be96d9a50df23", "max_issues_repo_licenses": ["NASA-1.3", "ECL-2.0", "Apache-2.0"], "max_issues_count": 105, "max_issues_repo_issues_event_min_datetime": "2019-07-08T19:27:23.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-22T02:12:16.000Z", "max_forks_repo_path": "src/Shared/GMAO_Shared/GMAO_ods/ods_julian.f", "max_forks_repo_name": "GEOS-ESM/AeroApps", "max_forks_repo_head_hexsha": "874dad6f34420c014d98eccbe81a061bdc0110cf", "max_forks_repo_licenses": ["NASA-1.3", "ECL-2.0", "Apache-2.0"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2019-07-05T18:00:44.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-11T16:26:29.000Z", "avg_line_length": 33.4561403509, "max_line_length": 74, "alphanum_fraction": 0.4832197168, "num_tokens": 1013, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.899121388082479, "lm_q2_score": 0.74316801430083, "lm_q1q2_score": 0.6681982565966619}} {"text": "*DECK CGEFA\n SUBROUTINE CGEFA (A, LDA, N, IPVT, INFO)\nC***BEGIN PROLOGUE CGEFA\nC***PURPOSE Factor a matrix using Gaussian elimination.\nC***LIBRARY SLATEC (LINPACK)\nC***CATEGORY D2C1\nC***TYPE COMPLEX (SGEFA-S, DGEFA-D, CGEFA-C)\nC***KEYWORDS GENERAL MATRIX, LINEAR ALGEBRA, LINPACK,\nC MATRIX FACTORIZATION\nC***AUTHOR Moler, C. B., (U. of New Mexico)\nC***DESCRIPTION\nC\nC CGEFA factors a complex matrix by Gaussian elimination.\nC\nC CGEFA is usually called by CGECO, but it can be called\nC directly with a saving in time if RCOND is not needed.\nC (Time for CGECO) = (1 + 9/N)*(Time for CGEFA) .\nC\nC On Entry\nC\nC A COMPLEX(LDA, N)\nC the matrix to be factored.\nC\nC LDA INTEGER\nC the leading dimension of the array A .\nC\nC N INTEGER\nC the order of the matrix A .\nC\nC On Return\nC\nC A an upper triangular matrix and the multipliers\nC which were used to obtain it.\nC The factorization can be written A = L*U where\nC L is a product of permutation and unit lower\nC triangular matrices and U is upper triangular.\nC\nC IPVT INTEGER(N)\nC an integer vector of pivot indices.\nC\nC INFO INTEGER\nC = 0 normal value.\nC = K if U(K,K) .EQ. 0.0 . This is not an error\nC condition for this subroutine, but it does\nC indicate that CGESL or CGEDI will divide by zero\nC if called. Use RCOND in CGECO for a reliable\nC indication of singularity.\nC\nC***REFERENCES J. J. Dongarra, J. R. Bunch, C. B. Moler, and G. W.\nC Stewart, LINPACK Users' Guide, SIAM, 1979.\nC***ROUTINES CALLED CAXPY, CSCAL, ICAMAX\nC***REVISION HISTORY (YYMMDD)\nC 780814 DATE WRITTEN\nC 890831 Modified array declarations. (WRB)\nC 890831 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900326 Removed duplicate information from DESCRIPTION section.\nC (WRB)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE CGEFA\n INTEGER LDA,N,IPVT(*),INFO\n COMPLEX A(LDA,*)\nC\n COMPLEX T\n INTEGER ICAMAX,J,K,KP1,L,NM1\n COMPLEX ZDUM\n REAL CABS1\n CABS1(ZDUM) = ABS(REAL(ZDUM)) + ABS(AIMAG(ZDUM))\nC\nC GAUSSIAN ELIMINATION WITH PARTIAL PIVOTING\nC\nC***FIRST EXECUTABLE STATEMENT CGEFA\n INFO = 0\n NM1 = N - 1\n IF (NM1 .LT. 1) GO TO 70\n DO 60 K = 1, NM1\n KP1 = K + 1\nC\nC FIND L = PIVOT INDEX\nC\n L = ICAMAX(N-K+1,A(K,K),1) + K - 1\n IPVT(K) = L\nC\nC ZERO PIVOT IMPLIES THIS COLUMN ALREADY TRIANGULARIZED\nC\n IF (CABS1(A(L,K)) .EQ. 0.0E0) GO TO 40\nC\nC INTERCHANGE IF NECESSARY\nC\n IF (L .EQ. K) GO TO 10\n T = A(L,K)\n A(L,K) = A(K,K)\n A(K,K) = T\n 10 CONTINUE\nC\nC COMPUTE MULTIPLIERS\nC\n T = -(1.0E0,0.0E0)/A(K,K)\n CALL CSCAL(N-K,T,A(K+1,K),1)\nC\nC ROW ELIMINATION WITH COLUMN INDEXING\nC\n DO 30 J = KP1, N\n T = A(L,J)\n IF (L .EQ. K) GO TO 20\n A(L,J) = A(K,J)\n A(K,J) = T\n 20 CONTINUE\n CALL CAXPY(N-K,T,A(K+1,K),1,A(K+1,J),1)\n 30 CONTINUE\n GO TO 50\n 40 CONTINUE\n INFO = K\n 50 CONTINUE\n 60 CONTINUE\n 70 CONTINUE\n IPVT(N) = N\n IF (CABS1(A(N,N)) .EQ. 0.0E0) INFO = N\n RETURN\n END\n", "meta": {"hexsha": "97194ce1c455cddbf761349612dd646bc7511303", "size": 3637, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/cgefa.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/cgefa.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/cgefa.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.0578512397, "max_line_length": 70, "alphanum_fraction": 0.5479791037, "num_tokens": 1200, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762114, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6681982423498644}} {"text": "module nltransf\n\n!$$$ module documentation block\n! module: nltransf\n! program history log:\n! 2018-01-18 yang/Guo ! Jim Purser's nonlinear transformation for vis and cldch.\n! will work on the document late \n!$$$ end documentation block\n! . . . .\n\n use kinds, only: r_kind, i_kind\n use constants, only: zero\n\n implicit none\n private\n\n public:: nltransf_forward\n interface nltransf_forward ; module procedure forward; end interface\n public:: nltransf_inverse\n interface nltransf_inverse ; module procedure inverse; end interface\n\n!\n\nCONTAINS\n\nsubroutine forward(zin,zout,powerp,scale_cv)\n\n!--------------------------------------------------------------\n! input argument:\n! zin - vis or cldch\n! powerp - parameter for nltr\n! output argument:\n! zout - the vis or cldch after the nonlinear transformation \n!--------------------------------------------------------------\n implicit none\n real(r_kind),intent(in):: zin\n real(r_kind),intent(in):: powerp\n real(r_kind),intent(in):: scale_cv\n real(r_kind) :: zout\n\n! local variable\n real(r_kind) :: temp ! after the nltransformation\n! do not choose negative powerp \n if (abs(powerp) > zero) then\n !non-log conversion\n temp =(zin/scale_cv)**powerp\n zout =(temp-1.0_r_kind)/powerp\n else\n !log conversion\n zout=log(zin/scale_cv)\n endif\n return\nend subroutine forward\n\nsubroutine inverse(zin,zout,powerp,scale_cv)\n implicit none\n real(r_kind),intent(in):: zin\n real(r_kind),intent(in):: powerp\n real(r_kind),intent(in):: scale_cv\n real(r_kind) :: zout\n\n! Local variable\n real(r_kind) :: powerpinv\n real(r_kind) :: z1\n\n!change zin from nltr space back to physical space\n if (abs(powerp)> zero) then\n ! non-log conversion\n powerpinv=1.0_r_kind/powerp\n z1=(powerp*zin + 1.0_r_kind)\n z1=z1**powerpinv\n zout=z1*scale_cv\n else\n ! log conversion\n zout=exp(zin)*scale_cv\n endif\n return\nend subroutine inverse\n\nend module nltransf\n", "meta": {"hexsha": "8eb251aeb6668963104cff0feb247da464422079", "size": 2058, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "GEOSaana_GridComp/GSI_GridComp/nltransf.f90", "max_stars_repo_name": "GEOS-ESM/GEOSana_GridComp", "max_stars_repo_head_hexsha": "cf33607613754313a2383bb7e7b3d29c856b9daf", "max_stars_repo_licenses": ["NASA-1.3", "ECL-2.0", "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": "GEOSaana_GridComp/GSI_GridComp/nltransf.f90", "max_issues_repo_name": "GEOS-ESM/GEOSana_GridComp", "max_issues_repo_head_hexsha": "cf33607613754313a2383bb7e7b3d29c856b9daf", "max_issues_repo_licenses": ["NASA-1.3", "ECL-2.0", "Apache-2.0"], "max_issues_count": 43, "max_issues_repo_issues_event_min_datetime": "2019-08-15T20:38:31.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-04T15:20:38.000Z", "max_forks_repo_path": "GEOSaana_GridComp/GSI_GridComp/nltransf.f90", "max_forks_repo_name": "GEOS-ESM/GEOSana_GridComp", "max_forks_repo_head_hexsha": "cf33607613754313a2383bb7e7b3d29c856b9daf", "max_forks_repo_licenses": ["NASA-1.3", "ECL-2.0", "Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-12-20T23:40:17.000Z", "max_forks_repo_forks_event_max_datetime": "2020-04-11T08:20:51.000Z", "avg_line_length": 25.4074074074, "max_line_length": 80, "alphanum_fraction": 0.6243926142, "num_tokens": 559, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636752, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6681982394288496}} {"text": "C$Procedure RADREC ( Range, RA and DEC to rectangular coordinates )\n \n SUBROUTINE RADREC ( RANGE, RA, DEC, RECTAN )\n \nC$ Abstract\nC\nC Convert from range, right ascension, and declination to\nC rectangular coordinates.\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 CONVERSION, COORDINATES\nC\nC$ Declarations\n \n DOUBLE PRECISION RANGE\n DOUBLE PRECISION RA\n DOUBLE PRECISION DEC\n DOUBLE PRECISION RECTAN ( 3 )\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- ---------------------------------------------------\nC RANGE I Distance of a point from the origin.\nC RA I Right ascension in radians.\nC DEC I Declination in radians.\nC RECTAN O Rectangular coordinates of the point.\nC\nC$ Detailed_Input\nC\nC RANGE is the distance of the point from the origin. Input\nC should be in terms of the same units in which the\nC output is desired.\nC\nC\nC RA is the right ascension of RECTAN. This is the angular\nC distance measured toward the east from the prime\nC meridian to the meridian containing the input point.\nC The direction of increasing right ascension is from\nC the +X axis towards the +Y axis.\nC\nC The range (i.e., the set of allowed values) of \nC RA is unrestricted. Units are radians.\nC\nC\nC DEC is the declination of RECTAN. This is the angle from\nC the XY plane of the ray from the origin through the\nC point.\nC\nC The range (i.e., the set of allowed values) of \nC DEC is unrestricted. Units are radians.\nC\nC\nC$ Detailed_Output\nC\nC RECTAN is the array containing the rectangular coordinates of\nC the point. \nC\nC The units associated with RECTAN are those\nC associated with the input RANGE.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC Error free.\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC This routine converts the right ascension, declination, and range\nC of a point into the associated rectangular coordinates.\nC\nC The input is defined by a distance from a central reference point,\nC an angle from a reference meridian, and an angle above the equator\nC of a sphere centered at the central reference point.\nC\nC$ Examples\nC\nC The following code fragment converts right ascension and \nC declination from the B1950 reference frame to the J2000 frame.\nC\nC C\nC C Convert RA and DEC to a 3-vector expressed in\nC C the B1950 frame.\nC C\nC CALL RADREC ( 1.D0, RA, DEC, V1950 )\nC C\nC C We use the SPICELIB routine PXFORM to obtain the\nC C transformation matrix for converting vectors between \nC C the B1950 and J2000 reference frames. Since\nC C both frames are inertial, the input time value we \nC C supply to PXFORM is arbitrary. We choose zero\nC C seconds past the J2000 epoch.\nC C\nC CALL PXFORM ( 'B1950', 'J2000', 0.D0, MTRANS )\nC C\nC C Transform the vector to the J2000 frame.\nC C \nC CALL MXV ( MTRANS, V1950, V2000 )\nC C\nC C Find the RA and DEC of the J2000-relative vector.\nC C\nC CALL RECRAD ( V2000, R, RA, DEC )\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC C.H. Acton (JPL)\nC N.J. Bachman (JPL)\nC H.A. Neilan (JPL)\nC\nC$ Literature_References\nC\nC \"Celestial Mechanics, A Computational Guide for the Practitioner\"\nC by Laurence G. Taff\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.2, 30-JUL-2003 (NJB) (CHA)\nC\nC Various header changes were made to improve clarity. Some\nC minor header corrections were made.\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 (HAN)\nC\nC-&\n \nC$ Index_Entries\nC\nC range ra and dec to rectangular coordinates\nC right_ascension and declination to rectangular\nC\nC-&\n \n \n \nC$ Revisions\nC\nC- Beta Version 1.1.0, 19-MAY-1989 (HAN)\nC\nC Removed calls to CHKIN and CHKOUT. This routine is\nC \"error free\" and should not have been participating\nC in error handling.\nC\nC-&\n \n \nC\nC Convert from range, right ascension, and declination to\nC rectangular coordinates by calling the routine LATREC.\nC\n \n CALL LATREC ( RANGE, RA, DEC, RECTAN )\n \n RETURN\n END\n", "meta": {"hexsha": "bf006862350392e599a20f120f681ce0498baaea", "size": 6061, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/radrec.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/radrec.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/radrec.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": 30.1542288557, "max_line_length": 72, "alphanum_fraction": 0.6480778749, "num_tokens": 1650, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213664574069, "lm_q2_score": 0.7431680086124812, "lm_q1q2_score": 0.668198235411084}} {"text": "c\nc tests subroutines shpei and shpe in file shpe.f\nc also requires files shaec.f shsec.f sphcom.f and hrfft.f\nc\nc shpe is the n**2 filter with complement, odd/even\nc factorization and zero truncation on an equally spaced\nc grid. The projection is defined in the JCP paper \"Generalized\nc discrete spherical harmonic transforms\" by \nc Paul N. Swarztrauber and William F. Spotz\nc J. Comp. Phys., 159(2000) pp. 213-230.\nc\nc April 2002\nc\n program tshpe\n parameter (idp=32)\n parameter (kdp=idp+idp-2)\n parameter (lwshp=2*(idp+1)**2+kdp+20,\n 1 liwshp=4*(idp+1),lwrk=1.25*(idp+1)**2+7*idp+8)\n parameter (lwrk1=idp*kdp)\n parameter(lwork = 5*idp*(idp-1),\n 1 lwsha=idp*(idp+1)+3*(idp-2)*(idp-1)/2+kdp+15)\n double precision work(lwrk)\n dimension sx(idp,kdp),sy(idp,kdp),\n 1wshp(lwshp),iwshp(liwshp),wrk1(lwrk1)\n dimension g(idp,kdp,2),ga(idp,idp,2),gb(idp,idp,2),\n 1 gh(idp,kdp,2),gw(idp,kdp,2),\n 2 wrk2(lwork),wshaec(lwsha),wshsec(lwsha)\n dimension t1(2)\nc\n iprint = 0\n nt = 1\nc\n do 100 nlat=6,8\n do 100 mtr=1,3\n mtrunc = nlat-mtr\n idimg = idp\n jdimg = kdp\n nlon = 2*(nlat-1)\n mtrunc = min(mtrunc,nlat-1,nlon/2)\n call shaeci(nlat,nlon,wshaec,lwsha,work,lwrk,ierror)\n if(ierror .ne. 0) write(6,70) ierror\n 70 format(' ierror0' ,i5)\nc\n lwshs = lwsha\n call shseci(nlat,nlon,wshsec,lwshs,work,lwrk,ierror)\n if(ierror .ne. 0) write(6,71) ierror\n 71 format(' ierror1' ,i5)\nc\n mode = 0\n if(iprint .ne. 0) write (6,5) mode,nlat,nlon\n 5 format(' mode =' ,i5,' nlat =',i5,' nlon =',i5)\nc\n do 10 k=1,nt\n do 10 i=1,nlat\n do 10 j=1,nlon\n g(i,j,k) = cos(float(i*j))\n gh(i,j,k) = g(i,j,k)\n 10 continue\nc\n thold = etime(t1)\n thold = t1(1)\n call shaec(nlat,nlon,mode,nt,g,idimg,jdimg,ga,gb,idimg,idimg,\n 1 wshaec,lwsha,wrk2,lwork,ierror)\n if(ierror .ne. 0) write(6,72) ierror\n 72 format(' ierror2' ,i5)\nc\n if(mtrunc.lt.nlat-1) then\n do np1=mtrunc+2,nlat\n do mp1=1,np1\n ga(mp1,np1,1) = 0.\n gb(mp1,np1,1) = 0.\n end do\n end do\n end if\n call shsec(nlat,nlon,mode,nt,gw,idimg,jdimg,ga,gb,idimg,idimg,\n 1 wshsec,lwshs,wrk2,lwork,ierror)\n tusl = etime(t1)\n tusl = t1(1)-thold\n if(ierror .ne. 0) write(6,73) ierror\n 73 format(' ierror3' ,i5)\nc\nc faster filter\nc\n isym = 0\nc mtrunc = nlat-1\n call shpei(nlat,nlon,isym,mtrunc,wshp,lwshp,iwshp,liwshp,\n 1 work,lwrk,ierror)\nc\n if(ierror.ne.0) write(*,429) ierror\n 429 format(' ierror =',i5,' at 429')\n do j=1,nlon\n do i=1,nlat\n sx(i,j) = gh(i,j,1)\n end do\n end do\nc\nc do i=1,nlat\nc write(*,427) i,(sx(i,j),j=1,nlon) \nc 427 format(i5,1p4e15.6/(5x,1p4e15.6))\nc end do\n thold = etime(t1)\n toe = t1(1)\n call shpe(nlat,nlon,isym,mtrunc,sx,sy,idp,\n 1 wshp,lwshp,iwshp,liwshp,wrk1,lwrk1,ierror)\n thold = etime(t1)\n toe = t1(1)-toe\n if(ierror.ne.0) write(*,428) ierror\n 428 format(' ierror =',i5,' at 428')\n if(iprint.gt.0)write(*,431)\n 431 format(/' approx and exact solution'/)\n do j=1,nlon\n if(iprint.gt.0)write(*,437) j,(sy(i,j),gw(i,j,1),i=1,nlat)\n 437 format(' j=',i5,1p4e15.6/(8x,1p4e15.6))\n end do\n dmax1 = 0.\n do j=1,nlon\n do i=1,nlat\n dmax1 = max(dmax1,abs(sy(i,j)-gw(i,j,1)))\n end do\n end do\n write (6,134) nlat,mtrunc\n 134 format(/'case nlat =',i5,' and mtrunc =',i5/)\n write(*,135) dmax1,tusl,toe\n 135 format(/' error =',1pe15.6/\n 1 ' tusl =',1pe15.6/\n 2 ' toe =',1pe15.6)\n 100 continue\n end\n\n", "meta": {"hexsha": "0f7b3d944a3db103f7fe440767f2f14bc222f38c", "size": 3801, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/drivers/tshpe.f", "max_stars_repo_name": "jprules321/colas", "max_stars_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/drivers/tshpe.f", "max_issues_repo_name": "jprules321/colas", "max_issues_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/drivers/tshpe.f", "max_forks_repo_name": "jprules321/colas", "max_forks_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.2384615385, "max_line_length": 68, "alphanum_fraction": 0.5637990003, "num_tokens": 1600, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267830311355, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.6681975128654823}} {"text": "module three_dimensional_solvers\n\n use fishpack_precision, only: &\n wp, & ! Working precision\n ip, & ! Integer precision\n PI\n\n use type_FishpackWorkspace, only: &\n FishpackWorkspace\n\n use type_PeriodicFastFourierTransform, only: &\n PeriodicFastFourierTransform\n\n ! Explicit typing only\n implicit none\n\n ! Everything is private unless stated otherwise\n private\n public :: pois3d\n public :: hw3crt\n public :: SolverUtility3D\n\n ! Parameters confined to the module\n real(wp), parameter :: ZERO = 0.0_wp\n real(wp), parameter :: HALF = 0.5_wp\n real(wp), parameter :: ONE = 1.0_wp\n real(wp), parameter :: TWO = 2.0_wp\n real(wp), parameter :: FOUR = 4.0_wp\n integer(ip), parameter :: SIZE_OF_WORKSPACE_INDICES = 6\n\n type, public :: SolverUtility3D\n ! Type components\n integer(ip) :: IIWK = SIZE_OF_WORKSPACE_INDICES\n contains\n ! Type-bound procedures\n procedure, nopass :: pois3dd\n procedure, nopass :: check_input_arguments\n procedure, nopass :: get_workspace_indices\n end type SolverUtility3D\n\n ! Declare interfaces for submodule implementation\n interface\n module subroutine pois3d(lperod, l, c1, mperod, m, c2, nperod, n, a, b, c, &\n ldimf, mdimf, f, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: lperod\n integer(ip), intent(in) :: l\n integer(ip), intent(in) :: mperod\n integer(ip), intent(in) :: m\n integer(ip), intent(in) :: nperod\n integer(ip), intent(in) :: n\n integer(ip), intent(in) :: ldimf\n integer(ip), intent(in) :: mdimf\n integer(ip), intent(out) :: ierror\n real(wp), intent(in) :: c1\n real(wp), intent(in) :: c2\n real(wp), intent(inout) :: a(:)\n real(wp), intent(inout) :: b(:)\n real(wp), intent(inout) :: c(:)\n real(wp), intent(inout) :: f(:,:,:)\n end subroutine pois3d\n\n module subroutine hw3crt(xs, xf, l, lbdcnd, bdxs, bdxf, ys, yf, m, mbdcnd, &\n bdys, bdyf, zs, zf, n, nbdcnd, bdzs, bdzf, elmbda, ldimf, &\n mdimf, f, pertrb, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: l\n integer(ip), intent(in) :: lbdcnd\n integer(ip), intent(in) :: m\n integer(ip), intent(in) :: mbdcnd\n integer(ip), intent(in) :: n\n integer(ip), intent(in) :: nbdcnd\n integer(ip), intent(in) :: ldimf\n integer(ip), intent(in) :: mdimf\n integer(ip), intent(out) :: ierror\n real(wp), intent(in) :: xs\n real(wp), intent(in) :: xf\n real(wp), intent(in) :: ys\n real(wp), intent(in) :: yf\n real(wp), intent(in) :: zs\n real(wp), intent(in) :: zf\n real(wp), intent(in) :: elmbda\n real(wp), intent(out) :: pertrb\n real(wp), intent(in) :: bdxs(:,:)\n real(wp), intent(in) :: bdxf(:,:)\n real(wp), intent(in) :: bdys(:,:)\n real(wp), intent(in) :: bdyf(:,:)\n real(wp), intent(in) :: bdzs(:,:)\n real(wp), intent(in) :: bdzf(:,:)\n real(wp), intent(inout) :: f(:,:,:)\n end subroutine hw3crt\n end interface\n\ncontains\n\n subroutine pois3dd(lperod, l, c1, mperod, m, c2, nperod, n, a, b, &\n c, ldimf, mdimf, f, ierror, w, workspace_indices)\n\n ! Dummy arguments\n integer(ip), intent(in) :: lperod\n integer(ip), intent(in) :: l\n integer(ip), intent(in) :: mperod\n integer(ip), intent(in) :: m\n integer(ip), intent(in) :: nperod\n integer(ip), intent(in) :: n\n integer(ip), intent(in) :: ldimf\n integer(ip), intent(in) :: mdimf\n integer(ip), intent(out) :: ierror\n integer(ip), intent(in) :: workspace_indices(:)\n real(wp), intent(in) :: c1\n real(wp), intent(in) :: c2\n real(wp), intent(inout) :: a(n)\n real(wp), intent(inout) :: b(n)\n real(wp), intent(inout) :: c(n)\n real(wp), intent(inout) :: f(:,:,:)\n real(wp), intent(inout) :: w(:)\n\n ! Local variables\n integer(ip) :: nh, nhm1, nodd, i, j, k\n real(wp) :: temp_save(SIZE_OF_WORKSPACE_INDICES)\n\n ! Check input arguments\n call check_input_arguments(lperod, l, mperod, m, nperod, n, &\n a, b, c, ldimf, mdimf, ierror)\n\n ! Check error flag\n if (ierror /= 0) return\n\n associate( &\n lp => lperod + 1, &\n mp => mperod + 1, &\n np => nperod + 1, &\n iwyrt => workspace_indices(1), &\n iwt => workspace_indices(2), &\n iwd => workspace_indices(3), &\n iwbb => workspace_indices(4), &\n iwx => workspace_indices(5), &\n iwy => workspace_indices(6) &\n )\n\n if (np == 1) then\n ! Reorder unknowns when nperod = 0\n nh = (n + 1)/2\n nhm1 = nh - 1\n\n if (2*nh == n) then\n nodd = 2\n else\n nodd = 1\n end if\n\n do i = 1, l\n do j = 1, m\n do k = 1, nhm1\n w(k) = f(i, j, nh-k) - f(i, j, k+nh)\n w(k+nh) = f(i, j, nh-k) + f(i, j, k+nh)\n end do\n\n w(nh) = TWO*f(i, j, nh)\n\n select case (nodd)\n case (1)\n f(i, j,:n) = w(:n)\n case (2)\n w(n) = TWO * f(i, j, n)\n f(i, j,:n) = w(:n)\n end select\n\n end do\n end do\n\n temp_save(1) = c(nhm1)\n temp_save(2) = a(nh)\n temp_save(3) = c(nh)\n temp_save(4) = b(nhm1)\n temp_save(5) = b(n)\n temp_save(6) = a(n)\n\n c(nhm1) = ZERO\n a(nh) = ZERO\n c(nh) = TWO*c(nh)\n\n select case (nodd)\n case (2)\n a(n) = c(nh)\n case default\n b(nhm1) = b(nhm1) - a(nh-1)\n b(n) = b(n) + a(n)\n end select\n end if\n\n call pois3dd_lower_routine(lp, l, mp, m, n, a, b, c, f, &\n w, w(iwyrt:), w(iwt:), w(iwd:), w(iwx:), w(iwy:), c1, c2, w(iwbb:))\n\n if (np == 1) then\n do i = 1, l\n do j = 1, m\n w(nh-1:nh-nhm1:(-1))= &\n HALF *(f(i, j, nh+1:nhm1+nh)+f(i, j,:nhm1))\n w(nh+1:nhm1+nh) = &\n HALF *(f(i, j, nh+1:nhm1+nh)-f(i, j,:nhm1))\n w(nh) = HALF *f(i, j, nh)\n select case (nodd)\n case (1)\n f(i, j,:n) = w(:n)\n case (2)\n w(n) = HALF * f(i, j, n)\n f(i, j,:n) = w(:n)\n end select\n end do\n end do\n\n c(nhm1) = temp_save(1)\n a(nh) = temp_save(2)\n c(nh) = temp_save(3)\n b(nhm1) = temp_save(4)\n b(n) = temp_save(5)\n a(n) = temp_save(6)\n end if\n end associate\n\n end subroutine pois3dd\n\n pure subroutine check_input_arguments(lperod, l, mperod, m, nperod, n, &\n a, b, c, ldimf, mdimf, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: lperod\n integer(ip), intent(in) :: l\n integer(ip), intent(in) :: mperod\n integer(ip), intent(in) :: m\n integer(ip), intent(in) :: nperod\n integer(ip), intent(in) :: n\n integer(ip), intent(in) :: ldimf\n integer(ip), intent(in) :: mdimf\n integer(ip), intent(out) :: ierror\n real(wp), intent(in) :: a(n)\n real(wp), intent(in) :: b(n)\n real(wp), intent(in) :: c(n)\n\n associate( &\n lp => lperod + 1, &\n mp => mperod + 1, &\n np => nperod + 1 &\n )\n\n if (lp < 1 .or. lp > 5) then\n ierror = 1\n else if (l < 3) then\n ierror = 2\n else if (mp < 1 .or. mp > 5) then\n ierror = 3\n else if (m < 3) then\n ierror = 4\n else if (np < 1 .or. np > 2) then\n ierror = 5\n else if (n < 3) then\n ierror = 6\n else if (ldimf < l) then\n ierror = 7\n else if (mdimf < m) then\n ierror = 8\n else if (np == 1) then\n if (any(a /= c(1)) .or. any(c /= c(1)) .or. any(b /= b(1))) then\n ierror = 9\n end if\n else if (nperod == 1 .and. (a(1) /= ZERO .or. c(n) /= ZERO)) then\n ierror = 10\n else\n ierror = 0\n end if\n end associate\n\n end subroutine check_input_arguments\n\n pure function get_workspace_indices(l, m, n) &\n result (return_value)\n\n ! Dummy arguments\n integer(ip), intent(in) :: l\n integer(ip), intent(in) :: m\n integer(ip), intent(in) :: n\n integer(ip) :: return_value(SIZE_OF_WORKSPACE_INDICES)\n\n associate( indx => return_value )\n indx(1) = l + 1\n indx(2) = indx(1) + m\n indx(3) = indx(2) + max(l, m, n) + 1\n indx(4) = indx(3) + n\n indx(5) = indx(4) + n\n indx(6) = indx(5) + 7*((l + 1)/2) + 15\n end associate\n\n end function get_workspace_indices\n\n subroutine pois3dd_lower_routine(lp, l, mp, m, n, a, b, c, &\n f, xrt, yrt, t, d, wx, wy, c1, c2, bb)\n\n ! Dummy arguments\n integer(ip), intent(in) :: lp\n integer(ip), intent(in) :: l\n integer(ip), intent(in) :: mp\n integer(ip), intent(in) :: m\n integer(ip), intent(in) :: n\n real(wp), intent(in) :: c1\n real(wp), intent(in) :: c2\n real(wp), intent(inout) :: a(n)\n real(wp), intent(in) :: b(n)\n real(wp), intent(inout) :: c(n)\n real(wp), intent(inout) :: f(:,:,:)\n real(wp), intent(inout) :: xrt(:)\n real(wp), intent(inout) :: yrt(:)\n real(wp), intent(inout) :: t(:)\n real(wp), intent(inout) :: d(:)\n real(wp), intent(inout) :: wx(:)\n real(wp), intent(inout) :: wy(:)\n real(wp), intent(inout) :: bb(:)\n\n ! Local variables\n integer(ip) :: lr, mr, nr, lrdel, i, mrdel, j, ifwrd, is, k\n real(wp) :: scalx, dx, di, scaly, dy, dj\n type(PeriodicFastFourierTransform) :: fft\n\n lr = l\n mr = m\n nr = n\n\n ! generate transform roots\n lrdel = ((lp - 1)*(lp - 3)*(lp - 5))/3\n scalx = lr + lrdel\n dx = PI/(TWO*scalx)\n\n select case (lp)\n case (1)\n xrt(1) = ZERO\n xrt(lr) = -FOUR*c1\n\n do i = 3, lr, 2\n xrt(i-1) = -FOUR*c1*sin(real(i - 1, kind=wp)*dx)**2\n xrt(i) = xrt(i-1)\n end do\n\n call fft%rffti(lr, wx)\n\n case default\n\n select case (lp)\n case (2)\n di = ZERO\n case (3, 5)\n di = HALF\n scalx = TWO*scalx\n case (4)\n di = ONE\n end select\n\n do i = 1, lr\n xrt(i) = -FOUR*c1*sin((real(i, kind=wp) - di)*dx)**2\n end do\n\n scalx = TWO*scalx\n\n if (lp /= 1) then\n select case (lp)\n case (2)\n call fft%sinti(lr, wx)\n case (3)\n call fft%sinqi(lr, wx)\n case (4)\n call fft%costi(lr, wx)\n case (5)\n call fft%cosqi(lr, wx)\n case default\n\n xrt(1) = ZERO\n xrt(lr) = -FOUR*c1\n\n do i = 3, lr, 2\n xrt(i-1) = -FOUR*c1*sin(real(i - 1)*dx)**2\n xrt(i) = xrt(i-1)\n end do\n\n call fft%rffti(lr, wx)\n end select\n end if\n end select\n\n mrdel = ((mp - 1)*(mp - 3)*(mp - 5))/3\n scaly = mr + mrdel\n dy = PI/(TWO*scaly)\n\n select case (mp)\n case (1)\n yrt(1) = ZERO\n yrt(mr) = -FOUR*c2\n\n do j = 3, mr, 2\n yrt(j-1) = -FOUR*c2*sin(real(j - 1, kind=wp)*dy)**2\n yrt(j) = yrt(j-1)\n end do\n\n call fft%rffti(mr, wy)\n\n case default\n\n select case (mp)\n case (2)\n dj = ZERO\n case (3, 5)\n dj = HALF\n scaly = TWO*scaly\n case (4)\n dj = ONE\n end select\n\n do j = 1, mr\n yrt(j) = -FOUR*c2*sin((real(j, kind=wp) - dj)*dy)**2\n end do\n\n scaly = TWO * scaly\n\n select case (mp)\n case (1)\n yrt(1) = ZERO\n yrt(mr) = -FOUR*c2\n\n do j = 3, mr, 2\n yrt(j-1) = -FOUR*c2*sin(real(j - 1, kind=wp)*dy)**2\n yrt(j) = yrt(j-1)\n end do\n\n call fft%rffti(mr, wy)\n\n case default\n\n select case (mp)\n case (2)\n call fft%sinti(mr, wy)\n case (3)\n call fft%sinqi(mr, wy)\n case (4)\n call fft%costi(mr, wy)\n case (5)\n call fft%cosqi(mr, wy)\n end select\n\n end select\n end select\n\n ifwrd = 1\n is = 1\n\n x_transform: do\n do j=1, mr\n do k=1, nr\n do i=1, lr\n t(i) = f(i, j, k)\n end do\n select case (lp)\n case (1)\n select case (ifwrd)\n case (1)\n call fft%rfftf(lr, t, wx)\n case (2)\n call fft%rfftb(lr, t, wx)\n end select\n case (2)\n call fft%sint(lr, t, wx)\n case (3)\n select case (ifwrd)\n case (1)\n call fft%sinqf(lr, t, wx)\n case (2)\n call fft%sinqb(lr, t, wx)\n end select\n case (4)\n call fft%cost(lr, t, wx)\n case (5)\n select case (ifwrd)\n case (1)\n call fft%cosqf(lr, t, wx)\n case (2)\n call fft%cosqb(lr, t, wx)\n end select\n end select\n\n do i=1, lr\n f(i, j, k) = t(i)\n end do\n end do\n end do\n\n if (ifwrd == 2) then\n f(:lr,:mr,:nr) = f(:lr,:mr,:nr)/(scalx*scaly)\n return\n end if\n\n y_transform: do\n do i=1, lr\n do k=1, nr\n t(1:mr) = f(i,1:mr, k)\n select case (mp)\n case (1)\n select case (ifwrd)\n case (1)\n call fft%rfftf(mr, t, wy)\n case (2)\n call fft%rfftb(mr, t, wy)\n end select\n case (2)\n call fft%sint(mr, t, wy)\n case (3)\n select case (ifwrd)\n case (1)\n call fft%sinqf(mr, t, wy)\n case (2)\n call fft%sinqb(mr, t, wy)\n end select\n case (4)\n call fft%cost(mr, t, wy)\n case (5)\n select case (ifwrd)\n case (1)\n call fft%cosqf(mr, t, wy)\n case (2)\n call fft%cosqb(mr, t, wy)\n end select\n end select\n f(i,1:mr, k) = t(1:mr)\n end do\n end do\n\n select case (ifwrd)\n case (1)\n do i = 1, lr\n do j = 1, mr\n bb(:nr) = b(:nr) + xrt(i) + yrt(j)\n t(:nr) = f(i, j,:nr)\n\n call solve_tridiag(nr, a, bb, c, t, d)\n\n f(i, j,:nr) = t(:nr)\n end do\n end do\n ifwrd = 2\n is = -1\n cycle y_transform\n case (2)\n cycle x_transform\n end select\n\n exit y_transform\n end do y_transform\n\n exit x_transform\n end do x_transform\n\n f(:lr,:mr,:nr) = f(:lr,:mr,:nr)/(scalx*scaly)\n\n end subroutine pois3dd_lower_routine\n\n subroutine solve_tridiag(m, a, b, c, y, d)\n\n ! Dummy arguments\n integer(ip), intent(in) :: m\n real(wp), intent(in) :: a(m) ! subdiagonal, i.e., the diagonal below the main diagonal\n real(wp), intent(in) :: b(m) ! the main diagonal\n real(wp), intent(in) :: c(m) ! supdiagonal, i.e, the diagonal above the main diagonal\n real(wp), intent(inout) :: y(m) ! the answer\n real(wp), intent(inout) :: d(m) ! right part\n\n ! Local variables\n integer(ip) :: i\n real(wp) :: temp\n\n ! Initialize\n d(1) = c(1)/b(1)\n y(1) = y(1)/b(1)\n\n do i = 2, m - 1\n temp = b(i) - d(i - 1) * a(i)\n d(i) = c(i)/temp\n y(i) = (y(i) - a(i) * y(i - 1))/temp\n end do\n\n temp = b(m) - a(m) * d(m - 1)\n\n if (temp == ZERO) then\n y(m) = ZERO\n else\n y(m) = (y(m) - a(m) * y(m - 1))/temp\n end if\n\n do i = m - 1, 1, -1\n y(i) = y(i) - d(i) * y(i + 1)\n end do\n\n end subroutine solve_tridiag\n\nend module three_dimensional_solvers\n", "meta": {"hexsha": "9ae060fcd41f26cc8e4f43287e508f8bfd41601b", "size": 20344, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/three_dimensional_solvers.f90", "max_stars_repo_name": "jlokimlin/fishpack", "max_stars_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2018-03-12T11:31:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-27T07:58:23.000Z", "max_issues_repo_path": "src/three_dimensional_solvers.f90", "max_issues_repo_name": "jlokimlin/fishpack", "max_issues_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2016-05-07T22:42:47.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-15T17:44:58.000Z", "max_forks_repo_path": "src/three_dimensional_solvers.f90", "max_forks_repo_name": "jlokimlin/fishpack", "max_forks_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-09-07T15:43:32.000Z", "max_forks_repo_forks_event_max_datetime": "2018-06-16T21:30:13.000Z", "avg_line_length": 33.7379767828, "max_line_length": 100, "alphanum_fraction": 0.3632520645, "num_tokens": 5315, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267864276108, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.6681975062806471}} {"text": "program i\n real ::b=(10.0 * 4) \n real ::c=(4.0 ** 2)\n real :: a\n a = (b * c)\nend program i\n", "meta": {"hexsha": "30860cb5cde5b5109446c816b0a62447c958f3d3", "size": 96, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/expr/scalar/expr_paren5.f90", "max_stars_repo_name": "clementval/fc", "max_stars_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/expr/scalar/expr_paren5.f90", "max_issues_repo_name": "clementval/fc", "max_issues_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/expr/scalar/expr_paren5.f90", "max_forks_repo_name": "clementval/fc", "max_forks_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "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": 13.7142857143, "max_line_length": 22, "alphanum_fraction": 0.4583333333, "num_tokens": 46, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267830311354, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.668197503668485}} {"text": "module type_AdvectionSolver\n\n use, intrinsic :: ISO_Fortran_env, only: &\n ip => INT32, &\n wp => REAL64, &\n stdout => OUTPUT_UNIT\n\n use spherepack, only: &\n GaussianSphere, &\n PI, &\n TWO_PI\n\n ! Explicit typing only\n implicit none\n\n private\n public :: DEGREES_TO_RADIANS\n public :: TIME_TO_CIRCUMVENT_THE_EARTH\n public :: AdvectionSolver\n\n ! Parameters confined to the module\n real(wp), parameter :: ZERO = 0.0_wp\n real(wp), parameter :: ONE = 1.0_wp\n real(wp), parameter :: TWO = 2.0_wp\n real(wp), parameter :: SIXTY = 6.0e+1_wp\n real(wp), parameter :: SIX_HUNDRED = 6.0e+2_wp\n real(wp), parameter :: ONE_THOUSAND = 1.0e+3_wp\n real(wp), parameter :: DEGREES_TO_RADIANS = PI/180\n integer(ip), parameter :: TIME_TO_CIRCUMVENT_THE_EARTH = 12*24*3600\n \n type, public, extends(GaussianSphere) :: AdvectionSolver\n\n ! Type components\n real(wp) :: TIME_STEP = SIX_HUNDRED\n real(wp) :: ROTATION_RATE_OF_EARTH = TWO_PI/TIME_TO_CIRCUMVENT_THE_EARTH\n real(wp) :: LATITUDE_OF_COSINE_BELL = PI/6\n real(wp) :: RADIUS_OF_EARTH_IN_METERS = ONE/3\n real(wp) :: TILT_ANGLE_IN_DEGREES = SIXTY\n real(wp) :: TILT_ANGLE = SIXTY * DEGREES_TO_RADIANS\n real(wp) :: MAXIMUM_VALUE_OF_COSINE_BELL = ONE_THOUSAND\n contains\n\n ! Type-bound procedures\n procedure, public :: get_geopotential\n procedure, public :: get_vector_velocities\n procedure, nopass :: atanxy\n end type AdvectionSolver\n\ncontains\n\n ! Purpose:\n !\n ! Computes advecting cosine bell on a tilted grid a time t.\n !\n ! input parameters\n !\n ! t time in seconds\n !\n ! alpha tilt angle in radians\n !\n ! beta colatitude of cosine bell in untilted coordinate\n ! system in radians\n !\n ! omega angular velocity in radians per second\n !\n ! hzero maximum value of cosine bell\n !\n ! re radius of support for cosine bell in radians\n !\n ! nlat number of latitudes including the poles\n !\n ! nlon number of distinct longitude lines\n !\n ! idim first dimension of output array h\n !\n ! colat vector of Gauss colatitude grid points\n !\n ! output parameter\n !\n ! geopot an nlat by nlon array containing the geopotential\n !\n ! on a tilted grid\n !\n subroutine get_geopotential(self, t, geopot)\n\n ! Dummy arguments\n class(AdvectionSolver), intent(inout) :: self\n real(wp), intent(in) :: t\n real(wp), intent(out) :: geopot(:, :)\n\n ! Local variables\n integer(ip) :: i, j\n real(wp) :: xc, yc, zc, x1, y1, z1\n real(wp) :: lambda, theta, cost, sint, sth , cthclh\n real(wp) :: cthslh, lhat, cosl, sinl, cth , that, r\n\n\n associate (&\n nlat => self%NUMBER_OF_LATITUDES, &\n nlon => self%NUMBER_OF_LONGITUDES, &\n omega => self%ROTATION_RATE_OF_EARTH, &\n beta => self%LATITUDE_OF_COSINE_BELL, &\n re => self%RADIUS_OF_EARTH_IN_METERS, &\n alpha => self%TILT_ANGLE, &\n hzero => self%MAXIMUM_VALUE_OF_COSINE_BELL, &\n colat => self%grid%latitudes &\n )\n\n associate (lambdc => omega*t)\n call sph2cart(ONE, beta, lambdc, xc, yc, zc)\n end associate\n\n associate (&\n cosa => cos(alpha), &\n sina => sin(alpha) &\n )\n do j=1, nlon\n lambda = self%grid%longitudes(j)\n associate (&\n cosp => cos(lambda), &\n sinp => sin(lambda) &\n )\n do i=1, nlat\n theta = colat(i)\n cost = cos(theta)\n sint = sin(theta)\n sth = cosa*cost+sina*sint*cosp\n cthclh = cosa*sint*cosp-sina*cost\n cthslh = sint*sinp\n lhat = atanxy(cthclh, cthslh)\n cosl = cos(lhat)\n sinl = sin(lhat)\n cth = cosl*cthclh+sinl*cthslh\n that = atanxy(sth, cth)\n\n ! Compute scaled radial unit vector\n call sph2cart(ONE, that, lhat, x1, y1, z1)\n\n ! Compute distance\n associate (dist => norm2([x1-xc, y1-yc, z1-zc]))\n\n ! Initialize geopotential\n geopot(i, j) = ZERO\n\n if (dist >= re) cycle\n\n r = TWO * asin(dist/2)\n\n end associate\n\n if (r >= re) cycle\n\n ! Set geopotential\n geopot(i, j) = hzero * (cos(r*PI/re)+ONE)/2\n end do\n end associate\n end do\n end associate\n end associate\n\n end subroutine get_geopotential\n\n subroutine get_vector_velocities(self, u, v)\n\n ! Dummy arguments\n class(AdvectionSolver), intent(inout) :: self\n real(wp), intent(out) :: u(:, :)\n real(wp), intent(out) :: v(:, :)\n\n ! Local variables\n integer(ip) :: i, j\n real(wp) :: sinp, cosp, sint, cost, sinl, cosl\n real(wp) :: cth, xlhat, uhat\n\n associate (&\n nlats => self%NUMBER_OF_LATITUDES, &\n nlons => self%NUMBER_OF_LONGITUDES, &\n colat => self%grid%latitudes, &\n omega => self%ROTATION_RATE_OF_EARTH, &\n alpha => self%TILT_ANGLE &\n )\n\n do j=1, nlons\n associate (xlm => self%grid%longitudes(j))\n sinp = sin(xlm)\n cosp = cos(xlm)\n do i=1, nlats\n cost = cos(colat(i))\n sint = sin(colat(i))\n associate (&\n sth => cos(alpha)*cost+sin(alpha)*sint*cosp, &\n cthclh => cos(alpha)*sint*cosp-sin(alpha)*cost, &\n cthslh => sint*sinp &\n )\n\n xlhat = self%atanxy(cthclh, cthslh)\n cosl = cos(xlhat)\n sinl = sin(xlhat)\n cth = cosl*cthclh+sinl*cthslh\n uhat = omega*cth\n u(i, j) = (cos(alpha)*sinp*sinl+cosp*cosl)*uhat\n v(i, j) = (cos(alpha)*cost*cosp*sinl &\n -cost*sinp*cosl+sin(alpha)*sint*sinl)*uhat\n\n end associate\n end do\n end associate\n end do\n end associate\n\n end subroutine get_vector_velocities\n\n pure function atanxy(x, y) result (return_value)\n\n ! Dummy arguments\n real(wp), intent(in) :: x\n real(wp), intent(in) :: y\n real(wp) :: return_value\n\n return_value = ZERO\n\n if (x == ZERO .and. y == ZERO) return\n\n return_value = atan2(y, x)\n\n end function atanxy\n\n pure subroutine sph2cart(r, theta, phi, x, y, z)\n\n ! Dummy arguments\n real(wp), intent(in) :: r\n real(wp), intent(in) :: theta\n real(wp), intent(in) :: phi\n real(wp), intent(out) :: x, y, z\n\n x = r * sin(theta) * cos(phi)\n y = r * sin(theta) * sin(phi)\n z = r * cos(theta)\n\n end subroutine sph2cart\n\nend module type_AdvectionSolver\n", "meta": {"hexsha": "ee54f8f83514fd97218c37eacb585498bfc3861f", "size": 7914, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/type_AdvectionSolver.f90", "max_stars_repo_name": "jlokimlin/spherepack4.1", "max_stars_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-06-28T14:01:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T21:59:28.000Z", "max_issues_repo_path": "examples/type_AdvectionSolver.f90", "max_issues_repo_name": "jlokimlin/spherepack4.1", "max_issues_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2016-05-07T23:00:35.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-22T23:52:30.000Z", "max_forks_repo_path": "examples/type_AdvectionSolver.f90", "max_forks_repo_name": "jlokimlin/spherepack4.1", "max_forks_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-06-28T14:03:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T12:53:54.000Z", "avg_line_length": 32.5679012346, "max_line_length": 80, "alphanum_fraction": 0.4753601213, "num_tokens": 1971, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240108164656, "lm_q2_score": 0.7122321964553657, "lm_q1q2_score": 0.6681621247713285}} {"text": "subroutine antialias(yh)\n! performs 1d antialias 2/3 filter on vector yh\n! zeros out modes (Nx/2 - b) ... (Nx/2) and (-Nx/2 + 1) ... (-Nx / 2 + b) where b = Nx/6\n! === Parameters ===\n! yh - 1d solution in fourier space. Expected wave number ordering is [0:params.Nx/2, -params.Nx/2+1:-1]\n! === Output ===\n! yh - anti aliased 1d solution in fourier space\n complex(dp), intent(inout) :: yh(:)\n integer :: a, b, Np\n \n Np = size(yh)\n a = Np / 2\n b = Np / 6 ! one-half filter length\n yh( a + 1 - b : a + 1 + b) = 0.0_dp;\nend subroutine antialias", "meta": {"hexsha": "436d85110c3e506e3008fa5caeb3849d73c72a7e", "size": 564, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "partitioned/fortran/tools/subroutines/antialias.f90", "max_stars_repo_name": "buvoli/epbm", "max_stars_repo_head_hexsha": "32ffe175a2e3456799ebc3e6feeb085ff5c83f81", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "partitioned/fortran/tools/subroutines/antialias.f90", "max_issues_repo_name": "buvoli/epbm", "max_issues_repo_head_hexsha": "32ffe175a2e3456799ebc3e6feeb085ff5c83f81", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "partitioned/fortran/tools/subroutines/antialias.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": 37.6, "max_line_length": 104, "alphanum_fraction": 0.5833333333, "num_tokens": 215, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9381240177362488, "lm_q2_score": 0.7122321903471563, "lm_q1q2_score": 0.668162123969563}} {"text": "! DART software - Copyright UCAR. This open source software is provided\n! by UCAR, \"as is\", without charge, subject to all terms of use at\n! http://www.image.ucar.edu/DAReS/DART/DART_download\n\n!> Looking at sampling error for the obs. space part of the problem\n!> Assume that the ratio of the prior sample to obs standard dev. is known\n!> Want to compute the following:\n!> 1. An unbiased estimate of the updated variance\n!> 2. An unbiased estimate of the updated mean which should be\n!> expressed as the fraction of the distance to move between\n!> the prior sample mean and the observed value\n!> 3. The standard deviation or variance of the updated mean estimate\n!> Need to add this uncertainty into the sample to avoid loss of\n!> variance (see also full_error.f90 which does this for regression).\n\nprogram obs_sampling_err\n\nuse types_mod, only : r8, digits12\nuse random_seq_mod, only : random_seq_type, init_random_seq, random_gaussian\n\nimplicit none\n\n!!!integer, parameter :: sample_size = 10000000\ninteger, parameter :: sample_size = 100000\ninteger :: ens_size\nreal(r8), allocatable :: sample(:)\nreal(r8) :: s_var, s_mean, u_var, ratio\nreal(r8) :: u_var_sum, u_var_mean\nreal(r8) :: t_var, log_ratio, beta\nreal(r8) :: s_obs_weight, s_obs_weight_sum, s_obs_weight2_sum\nreal(r8) :: s_obs_weight_var, s_obs_weight_mean\nreal(r8) :: s_var_sum, s_var_mean\nreal(r8) :: mad, mad_sum, mad_mean, sd_sum, sd_mean\ntype (random_seq_type) :: ran_id\ninteger :: i, j, k\n\nwrite(*, *) 'input ensemble size '\nread(*, *) ens_size\nallocate(sample(ens_size))\n\nwrite(*, *) 'stats for ensemble size ', ens_size\n\n! Initialize the random number sequence\ncall init_random_seq(ran_id)\n\n! Loop through a variety of ratios to make a table\ndo k = 1, 200\n log_ratio = (k - 100.0_r8) / 50.0_r8\n ratio = 10.0_r8**log_ratio\n\n ! Compute the true updated mean and variance without sampling error\n ! True prior mean is 0.0, \n ! True prior variance is ratio and true obs variance is 1.0\n t_var = 1.0_r8 / (1.0_r8 / ratio**2 + 1.0_r8)\n\n ! Initialize the sum arrays\n u_var_sum = 0.0_r8; s_var_sum = 0.0_r8\n s_obs_weight_sum = 0.0_r8; s_obs_weight2_sum = 0.0_r8\n mad_sum = 0.0_r8; sd_sum = 0.0_r8\n \n ! Loop through the sample\n do i = 1, sample_size\n ! Generate a random sample of size ens_size with ratio for variance\n do j = 1, ens_size\n sample(j) = random_gaussian(ran_id, 0.0_r8, ratio)\n enddo\n \n ! Compute the sample mean and variance\n call sample_mean_var(sample, ens_size, s_mean, s_var)\n\n\n\n ! Compute mean of sample variance\n s_var_sum = s_var_sum + s_var\n ! Compute mean of sd\n sd_sum = sd_sum + sqrt(s_var)\n ! Compute the mean absolute deviation, too\n mad = sum(abs(sample - s_mean)) / ens_size\n mad_sum = mad_sum + mad\n\n\n \n ! Compute the updated standard deviation and mean; obs var is 1.0\n u_var = 1.0_r8 / (1.0_r8 / s_var + 1.0_r8)\n u_var_sum = u_var_sum + u_var\n\n ! What weight is given to obs here?\n s_obs_weight = u_var / 1.0_r8\n s_obs_weight_sum = s_obs_weight_sum + s_obs_weight\n s_obs_weight2_sum = s_obs_weight2_sum + s_obs_weight**2\n \n enddo\n \n ! Output the mean stats\n u_var_mean = u_var_sum / sample_size\n s_obs_weight_mean = s_obs_weight_sum / sample_size\n s_obs_weight_var = (s_obs_weight2_sum - s_obs_weight_sum**2 / sample_size) / &\n (sample_size - 1.0_r8)\n s_var_mean = s_var_sum / sample_size\n sd_mean = sd_sum / sample_size\n mad_mean = mad_sum / sample_size\n \n ! Compute beta \n beta = s_obs_weight_mean**2 / s_obs_weight_var\n \n write(*, 22) log_ratio, ratio, t_var / u_var_mean, t_var / s_obs_weight_mean, beta\n 22 format(1x, 6(e10.4, 1x))\n write(*, *) 's_var_mean ', s_var_mean, ratio**2\n write(*, *) 'mad ', mad_mean, mad_mean / sqrt(s_var_mean)\n write(*, *) 'sd_mean ', sd_mean, sqrt(s_var_mean), sd_mean / sqrt(s_var_mean)\n\nenddo\n\n!----------------------------------------------------------------\ncontains\n!----------------------------------------------------------------\n\nsubroutine sample_mean_var(x, n, mean, var)\n\ninteger, intent(in) :: n\nreal(digits12), intent(in) :: x(n)\nreal(digits12), intent(out) :: mean, var\n\nreal(digits12) :: sx, s_x2\n\nsx = sum(x)\ns_x2 = sum(x * x)\nmean = sx / n\nvar = (s_x2 - sx**2 / n) / (n - 1)\n\nend subroutine sample_mean_var\n\nend program obs_sampling_err\n\n", "meta": {"hexsha": "9f7f7568e3f4198f48f523143d27f21ee675ff38", "size": 4402, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "assimilation_code/programs/system_simulation/obs_sampling_err.f90", "max_stars_repo_name": "fairaque1999/DART", "max_stars_repo_head_hexsha": "7490f75cf9800cc841b66d87840ad96c5751b809", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 65, "max_stars_repo_stars_event_min_datetime": "2019-10-16T13:31:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-14T11:52:58.000Z", "max_issues_repo_path": "assimilation_code/programs/system_simulation/obs_sampling_err.f90", "max_issues_repo_name": "fairaque1999/DART", "max_issues_repo_head_hexsha": "7490f75cf9800cc841b66d87840ad96c5751b809", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 283, "max_issues_repo_issues_event_min_datetime": "2019-09-23T15:48:34.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:44:41.000Z", "max_forks_repo_path": "assimilation_code/programs/system_simulation/obs_sampling_err.f90", "max_forks_repo_name": "fairaque1999/DART", "max_forks_repo_head_hexsha": "7490f75cf9800cc841b66d87840ad96c5751b809", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 67, "max_forks_repo_forks_event_min_datetime": "2019-09-19T22:13:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-20T15:58:26.000Z", "avg_line_length": 32.6074074074, "max_line_length": 85, "alphanum_fraction": 0.6706042708, "num_tokens": 1301, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339556397749, "lm_q2_score": 0.7956581073313276, "lm_q1q2_score": 0.6681411298061923}} {"text": "program residuo_ppal\n\nuse datasissim_interface\nuse residuo_interface\n\nimplicit none\n\nreal, dimension(:,:), allocatable :: a\nreal, dimension(:), allocatable :: b\nreal, dimension(:), allocatable :: u\nreal, dimension(:), allocatable :: r\n\nreal :: deter\n\ninteger :: n, i, j\n\nprint*\nprint*, 'Introduce o orde do sistema: '\nread*, n\nprint*\n\nprint*\nprint*, 'O orde introduce e: ', n\nprint*\n\nallocate(a(n,n), b(n), u(n), r(n))\n\ncall datasissim(a, b, u)\n\ncall residuo(a, b, u, r)\n\nif (allocated(a)) deallocate(a)\n\nif (allocated(b)) deallocate(b)\n\nif (allocated(u)) deallocate(u)\n\nif(allocated(r)) deallocate(r)\n\nend program\n", "meta": {"hexsha": "4780c96609b91f5c7a3957bfa41e838ccef61cb4", "size": 615, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Practica1_residuo/residuo_ppal.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": "Practica1_residuo/residuo_ppal.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": "Practica1_residuo/residuo_ppal.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": 15.0, "max_line_length": 39, "alphanum_fraction": 0.6796747967, "num_tokens": 182, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936878, "lm_q2_score": 0.7879311956428946, "lm_q1q2_score": 0.6681402436706934}} {"text": "program preprocessor11\n! #if with >, <, ==\nimplicit none\n\n#define X 1\n#define Y 5\n#define Z 1+Y*3\n\nprint *, Z\n\n#if X == 1\nprint *, \"X is 1\"\n#else\nprint *, \"X is not 1\"\n#endif\n\n#if X == 2\nprint *, \"X is 2\"\n#else\nprint *, \"X is not 2\"\n#endif\n\n#if X != 1\nprint *, \"X is not 1\"\n#else\nprint *, \"Not X is not 1\"\n#endif\n\n#if X == 1 && Y == 5\nprint *, \"X is 1 and Y is 5\"\n#else\nprint *, \"Not (X is 1 and Y is 5)\"\n#endif\n\n#if X == 2 && Y == 5\nprint *, \"X is 2 and Y is 5\"\n#else\nprint *, \"Not (X is 2 and Y is 5)\"\n#endif\n\n#if X < 3 && Y > 3\nprint *, \"X<3 and Y>3\"\n#else\nprint *, \"Not (X<3 and Y>3)\"\n#endif\n\n#if X > 3 && Y < 3\nprint *, \"X>3 and Y<3\"\n#else\nprint *, \"Not (X>3 and Y<3)\"\n#endif\n\n#if X == 3-2\nprint *, \"X is 3-2\"\n#else\nprint *, \"X is not 3-2\"\n#endif\n\n#if X == 3-1\nprint *, \"X is 3-1\"\n#else\nprint *, \"X is not 3-1\"\n#endif\n\n#if Y == (6*5-5)/5\nprint *, \"Y is (6*5-5)/5\"\n#else\nprint *, \"Y is not (6*5-5)/5\"\n#endif\n\n#if Y == (6*5-6)/5\nprint *, \"Y is (6*5-6)/5\"\n#else\nprint *, \"Y is not (6*5-6)/5\"\n#endif\n\n#if Y == (-5+6*5)/5\nprint *, \"Y is (-5+6*5)/5\"\n#else\nprint *, \"Y is not (-5+6*5)/5\"\n#endif\n\n#if Y == (-6+6*5)/5\nprint *, \"Y is (-6+6*5)/5\"\n#else\nprint *, \"Y is not (-6+6*5)/5\"\n#endif\n\n#if Y == (+5+6*5)/7\nprint *, \"Y is (+5+6*5)/7\"\n#else\nprint *, \"Y is not (+5+6*5)/7\"\n#endif\n\n#if Y == (+4+6*5)/7\nprint *, \"Y is (+4+6*5)/7\"\n#else\nprint *, \"Y is not (+4+6*5)/7\"\n#endif\n\n#if Y == (+5+6*Y)/7\nprint *, \"Y is (+5+6*Y)/7\"\n#else\nprint *, \"Y is not (+5+6*Y)/7\"\n#endif\n\n#if Z == 16\nprint *, \"Z is 16\"\n#else\nprint *, \"Z is not 16\"\n#endif\n\n#if defined(Y) && (3 <= Y)\nprint *, \"Y defined and 1 <= Y\"\n#else\nprint *, \"Y not defined or not 1 <= Y\"\n#endif\n\n#if defined(A) && (3 <= A)\nprint *, \"A defined and 1 <= A\"\n#else\nprint *, \"A not defined or not 1 <= A\"\n#endif\n\nend program\n", "meta": {"hexsha": "02760938727284656a372193a07f3cd66942c7f3", "size": 1766, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/preprocessor11.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/preprocessor11.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": "tests/preprocessor11.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": 14.0158730159, "max_line_length": 38, "alphanum_fraction": 0.5147225368, "num_tokens": 774, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936878, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.6681402394479515}} {"text": " subroutine splind(x,y,tn2,tnl,l)\r\n! compute cubic coefficients for a curve x-y\r\n use kinddefine\r\n use coef, only:e,ne\r\n implicit none\r\n integer(kind=K4),intent(in) :: l\r\n integer(kind=K4) :: j,k,n\r\n real(kind=K8),dimension(300) :: a,b,c,d,dx,dy,g,sb,xm\r\n real(kind=K8),dimension(l),intent(in) :: x,y\r\n real(kind=K8),intent(in) :: tn2,tnl\r\n real(kind=K8) :: dxr,one,p,px,pxx,pxxx,q,qx,qxx,qxxx,r,s,six,sw\r\n real(kind=K8):: thr,xj,xk,zero\r\n data zero/0.0d+0/,one/1.d+0/,thr/3.d+0/,six/6.d+0/\r\n! call orez (e,5*200)\r\n! call orez (a,9*300)\r\n e(:,:)=0.0d0\r\n a(:)=0.0d0\r\n b(:)=0.0d0\r\n c(:)=0.0d0\r\n d(:)=0.0d0\r\n dx(:)=0.0d0\r\n dy(:)=0.0d0\r\n g(:)=0.0d0\r\n sb(:)=0.0d0\r\n xm(:)=0.0d0\r\n!\r\n dx(1)=zero\r\n dy(1)=zero\r\n n=l-1\r\n do k=2,l\r\n dx(k)=x(k)-x(k-1)\r\n dy(k)=y(k)-y(k-1)\r\n enddo\r\n!\r\n b(1)=dx(2)/thr\r\n c(1)=dx(2)/six\r\n d(1)=dy(2)/dx(2)-tn2\r\n a(l)=dx(l)/six\r\n b(l)=dx(l)/thr\r\n d(l)=tnl-dy(l)/dx(l)\r\n a(1)=zero\r\n do k=2,n\r\n a(k)=dx(k)/six\r\n b(k)=(dx(k)+dx(k+1))/thr\r\n d(k)=dy(k+1)/dx(k+1)-dy(k)/dx(k)\r\n c(k)=dx(k+1)/six\r\n enddo\r\n sw=one/b(1)\r\n sb(1)=sw*c(1)\r\n g(1)=sw*d(1)\r\n do k=2,l\r\n sw=one/(b(k)-a(k)*sb(k-1))\r\n sb(k)=sw*c(k)\r\n g(k)=sw*(d(k)-a(k)*g(k-1))\r\n enddo\r\n xm(l)=g(l)\r\n do k=1,n\r\n j=l-k\r\n xm(j)=g(j)-sb(j)*xm(j+1)\r\n enddo\r\n do k=2,l\r\n dxr=one/dx(k)\r\n q=dxr/six\r\n p=-xm(k-1)*q\r\n q=q*xm(k)\r\n r=dx(k)*xm(k-1)/six-dxr*y(k-1)\r\n s=y(k)*dxr-dx(k)*xm(k)/six\r\n xk=x(k)\r\n px=xk*p\r\n pxx=px*xk\r\n pxxx=pxx*xk\r\n xj=x(k-1)\r\n qx=xj*q\r\n qxx=qx*xj\r\n qxxx=qxx*xj\r\n e(2,k)=p+q\r\n e(3,k)=-thr*(px+qx)\r\n e(4,k)=thr*(pxx+qxx)+r+s\r\n e(5,k)=-pxxx-qxxx-r*xk-s*xj\r\n enddo\r\n do k=2,l\r\n e(1,k)=x(k)\r\n enddo\r\n e(1,1)=x(1)\r\n ne=l\r\n end subroutine splind\r\n", "meta": {"hexsha": "2aa7d067b7fbe7d22f9823cb0d81f63a522d40eb", "size": 2070, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/splind.f", "max_stars_repo_name": "aldorona/contur", "max_stars_repo_head_hexsha": "d4197b55e28b20f905f9418f0473b2c39fadb0fd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-03-03T10:30:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-25T22:20:59.000Z", "max_issues_repo_path": "src/splind.f", "max_issues_repo_name": "aldorona/contur", "max_issues_repo_head_hexsha": "d4197b55e28b20f905f9418f0473b2c39fadb0fd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-08-01T20:33:57.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-05T13:46:04.000Z", "max_forks_repo_path": "src/splind.f", "max_forks_repo_name": "aldorona/contur", "max_forks_repo_head_hexsha": "d4197b55e28b20f905f9418f0473b2c39fadb0fd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-10-25T16:14:26.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-25T12:14:43.000Z", "avg_line_length": 23.7931034483, "max_line_length": 70, "alphanum_fraction": 0.4140096618, "num_tokens": 889, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966671870767, "lm_q2_score": 0.7057850340255386, "lm_q1q2_score": 0.6680937609590923}} {"text": "! -----------------------------------------------------------------\n!\n! global_data_m.f90\n!\n!\n! -----------------------------------------------------------------\n\nMODULE global_data_m\n\t\n\tIMPLICIT NONE\n\n! Constants\n\n\tREAL, PARAMETER :: \tpi = 3.14159265358979\n\tREAL, PARAMETER :: \tkeV_per_erg = 1./1.6022e-9\n\t\n\tREAL, PARAMETER :: mass_e = 9.1094e-28\t\t! mass in G\n\tREAL, PARAMETER :: mass_H = 1836*mass_e\t\t! mass in G\n\tREAL, PARAMETER :: mass_D = 3670*mass_e\t\t! mass in G\n\tREAL, PARAMETER :: mass_T = 5497*mass_e\t\t! mass in G\n\tREAL, PARAMETER :: mass_3He = 5496*mass_e\t! mass in G\n\tREAL, PARAMETER :: mass_4He = 7294*mass_e\t! mass in G\n\n! Parameters for program control\n\n\tLOGICAL :: l_read_file, l_interpolate_st_grid, l_show_graphics, l_cont_plot_f_st &\n\t\t\t\t& , l_plot_f_v, l_plot_f_cum, l_plot_f_Max, l_plot_delta_f\n\t\n! Flags\n\n\tLOGICAL :: lHave_Distribution = .false.\n\n! Parameters for plotting and labels\n\n\tINTEGER, PARAMETER :: kPlotParams = 6, kparam_label_length = 12, &\n\t\t\t& curve_label_length = 12\n\tREAL :: PlotParams(kPlotParams)\n\tCHARACTER (len=kparam_label_length) :: PlotLabels(kPlotParams), xLabel, yLabel\n\tCHARACTER (len=72) :: PlotTitle\n\tCHARACTER (len=curve_label_length) :: PlotCurveLabels(10)\n\t\n\n\n! *******************************************************************\t\n\t\n\t\nEND MODULE global_data_m\n", "meta": {"hexsha": "5b4e444c947be5d310a7a7106c6a9ca516ad68d2", "size": 1324, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/CQL3D_SETUP/SAVE/global_data_m.f", "max_stars_repo_name": "ORNL-Fusion/aorsa", "max_stars_repo_head_hexsha": "82bab1e3b88e10e6bd5ca9b16589b11a97dd8f39", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2019-03-12T13:33:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-11T08:28:46.000Z", "max_issues_repo_path": "src/CQL3D_SETUP/global_data_m.f90", "max_issues_repo_name": "ORNL-Fusion/aorsa", "max_issues_repo_head_hexsha": "82bab1e3b88e10e6bd5ca9b16589b11a97dd8f39", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 29, "max_issues_repo_issues_event_min_datetime": "2020-01-24T15:58:55.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-28T15:16:05.000Z", "max_forks_repo_path": "src/CQL3D_SETUP/SAVE/global_data_m.f", "max_forks_repo_name": "ORNL-Fusion/aorsa", "max_forks_repo_head_hexsha": "82bab1e3b88e10e6bd5ca9b16589b11a97dd8f39", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-09-10T16:48:52.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-10T16:48:52.000Z", "avg_line_length": 27.5833333333, "max_line_length": 83, "alphanum_fraction": 0.6012084592, "num_tokens": 390, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.89181104831338, "lm_q2_score": 0.7490872243177518, "lm_q1q2_score": 0.6680442627969743}} {"text": "!==========================================\n! integration.f90\n! Author: Devansh Shukla\n!------------------------------------------\nprogram integration\n implicit none\n ! Define the variables\n real*8 :: x, y, a=0.0, b=0.0, max=0.0, min=0.0, step=0.1, t=0, i=0.0, r=0.0\n real*8 :: f, area, int_area, j\n integer :: hits=0, n=0\n character(len=*), parameter :: fmt=\"(xF10.3,xF10.3,xF10.3)\"\n\n ! Define the function\n f(x) = (x**2 + 4*x + 9)**3 * (2*x + 4)\n \n ! Open the data file\n open(unit=8, file=\"int_area.dat\")\n\n ! Get input from the user\n print *, \"Enter a, b\"\n read *, a, b\n print *, \"Enter step, n\"\n read *, step, n\n print *, \"-------------------\"\n\n ! Max of f(x) in [a, b]\n i = a\n max = f(i)\n min = f(i)\n do while (i .le. b)\n t = f(i)\n if (max .lt. t) then\n max = t\n endif\n if (min .gt. t) then\n min = t\n endif\n i = i + step\n enddo\n print \"(A,F10.3,xxA,F10.3)\", \"MIN:\", min, \"MAX:\", max\n j = 0.0\n ! Compute the integration\n do while(j .le. n)\n call random_number(r)\n x = a + (b-a)*r\n call random_number(r)\n y = abs(max*r)\n ! print \"(F10.3, xxF10.3)\", y, f(x)\n write (8, fmt) x, y, f(x)\n if (y .le. abs(f(x))) then\n hits = hits + 1\n endif\n j = j + step\n enddo\n \n area = (b-a) * max\n int_area = area * hits * step / real(n)\n ! Print for the user\n print \"(A,I6)\", \"HITS=\", hits\n print \"(A,F10.3)\", \"INTEGRATION AREA=\", int_area\n print *, \"-------------------\"\n\n ! Close the data file\n close(8)\n\nend program integration\n", "meta": {"hexsha": "6198f696359873fb60cb80ab87ad8530eae5a8d5", "size": 1665, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "M11/integration.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": "M11/integration.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": "M11/integration.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": 24.8507462687, "max_line_length": 79, "alphanum_fraction": 0.4456456456, "num_tokens": 564, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379297, "lm_q2_score": 0.7490872075132153, "lm_q1q2_score": 0.66804424565654}} {"text": "*DECK FAC\n FUNCTION FAC (N)\nC***BEGIN PROLOGUE FAC\nC***PURPOSE Compute the factorial function.\nC***LIBRARY SLATEC (FNLIB)\nC***CATEGORY C1\nC***TYPE SINGLE PRECISION (FAC-S, DFAC-D)\nC***KEYWORDS FACTORIAL, FNLIB, SPECIAL FUNCTIONS\nC***AUTHOR Fullerton, W., (LANL)\nC***DESCRIPTION\nC\nC FAC(N) evaluates the factorial function of N. FAC is single\nC precision. N must be an integer between 0 and 25 inclusive.\nC\nC***REFERENCES (NONE)\nC***ROUTINES CALLED GAMLIM, R9LGMC, XERMSG\nC***REVISION HISTORY (YYMMDD)\nC 770601 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890531 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\nC***END PROLOGUE FAC\n DIMENSION FACN(26)\n SAVE FACN, SQ2PIL, NMAX\n DATA FACN( 1) / 1.0E0 /\n DATA FACN( 2) / 1.0E0 /\n DATA FACN( 3) / 2.0E0 /\n DATA FACN( 4) / 6.0E0 /\n DATA FACN( 5) / 24.0E0 /\n DATA FACN( 6) / 120.0E0 /\n DATA FACN( 7) / 720.0E0 /\n DATA FACN( 8) / 5040.0E0 /\n DATA FACN( 9) / 40320.0E0 /\n DATA FACN(10) / 362880.0E0 /\n DATA FACN(11) / 3628800.0E0 /\n DATA FACN(12) / 39916800.0E0 /\n DATA FACN(13) / 479001600.0E0 /\n DATA FACN(14) / 6227020800.0E0 /\n DATA FACN(15) / 87178291200.0E0 /\n DATA FACN(16) / 1307674368000.0E0 /\n DATA FACN(17) / 20922789888000.0E0 /\n DATA FACN(18) / 355687428096000.0E0 /\n DATA FACN(19) / 6402373705728000.0E0 /\n DATA FACN(20) / .12164510040883200E18 /\n DATA FACN(21) / .24329020081766400E19 /\n DATA FACN(22) / .51090942171709440E20 /\n DATA FACN(23) / .11240007277776077E22 /\n DATA FACN(24) / .25852016738884977E23 /\n DATA FACN(25) / .62044840173323944E24 /\n DATA FACN(26) / .15511210043330986E26 /\n DATA SQ2PIL / 0.9189385332 0467274E0/\n DATA NMAX / 0 /\nC***FIRST EXECUTABLE STATEMENT FAC\n IF (NMAX.NE.0) GO TO 10\n CALL GAMLIM (XMIN, XMAX)\n NMAX = XMAX - 1.\nC\n 10 IF (N .LT. 0) CALL XERMSG ('SLATEC', 'FAC',\n + 'FACTORIAL OF NEGATIVE INTEGER UNDEFINED', 1, 2)\nC\n IF (N.LE.25) FAC = FACN(N+1)\n IF (N.LE.25) RETURN\nC\n IF (N .GT. NMAX) CALL XERMSG ('SLATEC', 'FAC',\n + 'N SO BIG FACTORIAL(N) OVERFLOWS', 2, 2)\nC\n X = N + 1\n FAC = EXP ( (X-0.5)*LOG(X) - X + SQ2PIL + R9LGMC(X) )\nC\n RETURN\n END\n", "meta": {"hexsha": "ee36c95deb73580a46964b70595933af017dcf37", "size": 2432, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/fac.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/fac.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/fac.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.3150684932, "max_line_length": 62, "alphanum_fraction": 0.6097861842, "num_tokens": 1002, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379296, "lm_q2_score": 0.7490872075132153, "lm_q1q2_score": 0.6680442456565399}} {"text": "!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 1998 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Spherepack *\n! * *\n! * A Package of Fortran Subroutines and Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams and Paul Swarztrauber *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\nsubmodule(scalar_laplacian_routines) scalar_laplacian_regular_grid_saved\n\ncontains\n ! subroutine slapes(nlat, nlon, isym, nt, slap, ids, jds, a, b, mdab, ndab, &\n ! wshses, ierror)\n !\n !\n ! given the scalar spherical harmonic coefficients a and b, precomputed\n ! by subroutine shaes for a scalar field sf, subroutine slapes computes\n ! the laplacian of sf in the scalar array slap. slap(i, j) is the\n ! laplacian of sf at the colatitude\n !\n ! theta(i) = (i-1)*pi/(nlat-1)\n !\n ! and east longitude\n !\n ! lambda(j) = (j-1)*2*pi/nlon\n !\n ! on the sphere. i.e.\n !\n ! slap(i, j) =\n !\n ! 2 2\n ! [1/sint*d (sf(i, j)/dlambda + d(sint*d(sf(i, j))/dtheta)/dtheta]/sint\n !\n !\n ! where sint = sin(theta(i)). the scalar laplacian in slap has the\n ! same symmetry or absence of symmetry about the equator as the scalar\n ! field sf. the input parameters isym, nt, mdab, ndab must have the\n ! same values used by shaes to compute a and b for sf. the associated\n ! legendre functions are stored rather than recomputed as they are\n ! in subroutine slapec.\n\n !\n ! input parameters\n !\n ! nlat the number of colatitudes on the full sphere including the\n ! poles. for example, nlat = 37 for a five degree grid.\n ! nlat determines the grid increment in colatitude as\n ! pi/(nlat-1). if nlat is odd the equator is located at\n ! grid point i=(nlat + 1)/2. if nlat is even the equator is\n ! located half way between points i=nlat/2 and i=nlat/2+1.\n ! nlat must be at least 3. note: on the half sphere, the\n ! number of grid points in the colatitudinal direction is\n ! nlat/2 if nlat is even or (nlat + 1)/2 if nlat is odd.\n !\n ! nlon the number of distinct longitude points. nlon determines\n ! the grid increment in longitude as 2*pi/nlon. for example\n ! nlon = 72 for a five degree grid. nlon must be greater\n ! than zero. the axisymmetric case corresponds to nlon=1.\n ! the efficiency of the computation is improved when nlon\n ! is a product of small prime numbers.\n !\n ! isym this parameter should have the same value input to subroutine\n ! shaes to compute the coefficients a and b for the scalar field\n ! sf. isym is set as follows:\n !\n ! = 0 no symmetries exist in sf about the equator. scalar\n ! synthesis is used to compute slap on the entire sphere.\n ! i.e., in the array slap(i, j) for i=1, ..., nlat and\n ! j=1, ..., nlon.\n !\n ! = 1 sf and slap are antisymmetric about the equator. the\n ! synthesis used to compute slap is performed on the\n ! northern hemisphere only. if nlat is odd, slap(i, j) is\n ! computed for i=1, ..., (nlat + 1)/2 and j=1, ..., nlon. if\n ! nlat is even, slap(i, j) is computed for i=1, ..., nlat/2\n ! and j=1, ..., nlon.\n !\n !\n ! = 2 sf and slap are symmetric about the equator. the\n ! synthesis used to compute slap is performed on the\n ! northern hemisphere only. if nlat is odd, slap(i, j) is\n ! computed for i=1, ..., (nlat + 1)/2 and j=1, ..., nlon. if\n ! nlat is even, slap(i, j) is computed for i=1, ..., nlat/2\n ! and j=1, ..., nlon.\n !\n !\n ! nt the number of analyses. in the program that calls slapes\n ! the arrays slap, a, and b can be three dimensional in which\n ! case multiple synthesis will be performed. the third index\n ! is the synthesis index which assumes the values k=1, ..., nt.\n ! for a single analysis set nt=1. the description of the\n ! remaining parameters is simplified by assuming that nt=1\n ! or that all the arrays are two dimensional.\n !\n ! ids the first dimension of the array slap as it appears in the\n ! program that calls slapes. if isym = 0 then ids must be at\n ! least nlat. if isym > 0 and nlat is even then ids must be\n ! at least nlat/2. if isym > 0 and nlat is odd then ids must\n ! be at least (nlat + 1)/2.\n !\n ! jds the second dimension of the array slap as it appears in the\n ! program that calls slapes. jds must be at least nlon.\n !\n !\n ! a, b two or three dimensional arrays (see input parameter nt)\n ! that contain scalar spherical harmonic coefficients\n ! of the scalar field sf as computed by subroutine shaes.\n ! *** a, b must be computed by shaes prior to calling slapes.\n !\n !\n ! mdab the first dimension of the arrays a and b as it appears\n ! in the program that calls slapes. mdab must be at\n ! least min(nlat, (nlon+2)/2) if nlon is even or at least\n ! min(nlat, (nlon + 1)/2) if nlon is odd.\n !\n ! ndab the second dimension of the arrays a and b as it appears\n ! in the program that calls slapes. ndbc must be at least\n ! least nlat.\n !\n ! mdab, ndab should have the same values input to shaes to\n ! compute the coefficients a and b.\n !\n !\n ! wshses an array which must be initialized by subroutine shsesi\n ! before calling slapes. once initialized, wshses\n ! can be used repeatedly by slapes as long as nlat and nlon\n ! remain unchanged. wshses must not be altered between calls\n ! of slapes.\n !\n ! lshses the dimension of the array wshses as it appears in the\n ! program that calls slapes. let\n !\n ! l1 = min(nlat, (nlon+2)/2) if nlon is even or\n ! l1 = min(nlat, (nlon + 1)/2) if nlon is odd\n !\n ! and\n !\n ! l2 = nlat/2 if nlat is even or\n ! l2 = (nlat + 1)/2 if nlat is odd\n !\n ! then lshses must be greater than or equal to\n !\n ! (l1*l2*(2*nlat-l1+1))/2+nlon+15.\n !\n ! output parameters\n !\n !\n ! slap a two or three dimensional arrays (see input parameter nt) that\n ! contain the scalar laplacian of the scalar field sf. slap(i, j)\n ! is the scalar laplacian at the colatitude\n !\n ! theta(i) = (i-1)*pi/(nlat-1)\n !\n ! and longitude\n !\n ! lambda(j) = (j-1)*2*pi/nlon\n !\n ! for i=1, ..., nlat and j=1, ..., nlon.\n !\n !\n ! ierror a parameter which flags errors in input parameters as follows:\n !\n ! = 0 no errors detected\n ! = 1 error in the specification of nlat\n ! = 2 error in the specification of nlon\n ! = 3 error in the specification of isym\n ! = 4 error in the specification of nt\n ! = 5 error in the specification of ids\n ! = 6 error in the specification of jds\n ! = 7 error in the specification of mdbc\n ! = 8 error in the specification of ndbc\n ! = 9 error in the specification of lshses\n !\n module subroutine slapes(nlat, nlon, isym, nt, slap, ids, jds, a, b, &\n mdab, ndab, wshses, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n integer(ip), intent(in) :: isym\n integer(ip), intent(in) :: nt\n real(wp), intent(out) :: slap(ids, jds, nt)\n integer(ip), intent(in) :: ids\n integer(ip), intent(in) :: jds\n real(wp), intent(in) :: a(mdab, ndab, nt)\n real(wp), intent(in) :: b(mdab, ndab, nt)\n integer(ip), intent(in) :: mdab\n integer(ip), intent(in) :: ndab\n real(wp), intent(in) :: wshses(:)\n integer(ip), intent(out) :: ierror\n\n ! Local variables\n integer(ip) :: required_wavetable_size\n type(ScalarSynthesisUtility) :: util\n\n ! Check input arguments\n required_wavetable_size = util%get_lshses(nlat, nlon)\n\n call util%check_scalar_transform_inputs(isym, ids, jds, &\n mdab, ndab, nlat, nlon, nt, required_wavetable_size, &\n wshses, ierror)\n\n ! Check error flag\n if (ierror /= 0) return\n\n call scalar_laplacian_lower_utility_routine(nlat, nlon, isym, nt, slap, &\n a, b, wshses, shses, ierror)\n\n end subroutine slapes\n\nend submodule scalar_laplacian_regular_grid_saved\n", "meta": {"hexsha": "b73540a88172f3bca4f543e32f808d1be007812b", "size": 11133, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/scalar_laplacian_regular_grid_saved.f90", "max_stars_repo_name": "jlokimlin/spherepack4.1", "max_stars_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-06-28T14:01:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T21:59:28.000Z", "max_issues_repo_path": "src/scalar_laplacian_regular_grid_saved.f90", "max_issues_repo_name": "jlokimlin/spherepack4.1", "max_issues_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2016-05-07T23:00:35.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-22T23:52:30.000Z", "max_forks_repo_path": "src/scalar_laplacian_regular_grid_saved.f90", "max_forks_repo_name": "jlokimlin/spherepack4.1", "max_forks_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-06-28T14:03:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T12:53:54.000Z", "avg_line_length": 47.3744680851, "max_line_length": 85, "alphanum_fraction": 0.4669900296, "num_tokens": 2786, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110339361276, "lm_q2_score": 0.7490872131147276, "lm_q1q2_score": 0.6680442420361775}} {"text": "MODULE randdp\r\n! Replaces COMMON /randpp/ and defines dp\r\n\r\nIMPLICIT NONE\r\nINTEGER, PARAMETER, PUBLIC :: dp = SELECTED_REAL_KIND(15, 60)\r\n\r\nREAL (dp), SAVE, PUBLIC :: poly(101), other, offset\r\nINTEGER, SAVE, PUBLIC :: index\r\n\r\nCONTAINS\r\n\r\n! Nick Maclaren's double precision random number generator.\r\n! This version, which is compatible with Lahey's ELF90 compiler,\r\n! is by Alan Miller ( alan @ vic.cmis.csiro.au, www.vic.cmis.csiro.au/~alan )\r\n\r\n! Latest revision - 18 December 1997\r\n\r\n! Copyright (C) 1992 N.M. Maclaren\r\n! Copyright (C) 1992 The University of Cambridge\r\n\r\n! This software may be reproduced and used freely, provided that all\r\n! users of it agree that the copyright holders are not liable for any\r\n! damage or injury caused by use of this software and that this\r\n! condition is passed onto all subsequent recipients of the software,\r\n! whether modified or not.\r\n\r\n\r\n\r\nSUBROUTINE sdprnd (iseed)\r\n\r\nINTEGER, INTENT(IN) :: iseed\r\n\r\n! Local variables\r\nREAL (dp) :: x\r\nREAL (dp), PARAMETER :: xmod = 1000009711.0_dp, ymod = 33554432.0_dp\r\nINTEGER :: ix, iy, iz, i\r\nLOGICAL, SAVE :: inital = .TRUE.\r\n\r\n! ISEED should be set to an integer between 0 and 9999 inclusive;\r\n! a value of 0 will initialise the generator only if it has not\r\n! already been done.\r\n\r\nIF (inital .OR. iseed /= 0) THEN\r\n inital = .false.\r\nELSE\r\n RETURN\r\nEND IF\r\n\r\n! INDEX must be initialised to an integer between 1 and 101 inclusive,\r\n! POLY(1...N) to integers between 0 and 1000009710 inclusive (not all 0),\r\n! and OTHER to a non-negative proper fraction with denominator 33554432.\r\n! It uses the Wichmann-Hill generator to do this.\r\n\r\nix = MOD(ABS(iseed), 10000) + 1\r\niy = 2*ix + 1\r\niz = 3*ix + 1\r\nDO i = -10,101\r\n IF (i >= 1) poly(i) = AINT(xmod*x)\r\n ix = MOD(171*ix, 30269)\r\n iy = MOD(172*iy, 30307)\r\n iz = MOD(170*iz, 30323)\r\n x = MOD(DBLE(ix)/30269.0_dp + DBLE(iy)/30307.0_dp + DBLE(iz)/30323.0_dp, 1.0_dp)\r\nEND DO\r\nother = AINT(ymod*x)/ymod\r\noffset = 1.0_dp/ymod\r\nINDEX = 1\r\n\r\nRETURN\r\nEND SUBROUTINE sdprnd\r\n\r\n\r\n\r\nFUNCTION dprand() RESULT(fn_val)\r\n\r\nREAL (dp) :: fn_val\r\n\r\n! Local variables\r\nREAL (dp) :: x, y\r\n\r\n! N.B. ymod has been removed from the previous DATA statement; it caused a\r\n! fatal error as it is not used.\r\nREAL (dp), PARAMETER :: xmod = 1000009711.0_dp, xmod2 = 2000019422.0_dp, &\r\n xmod4 = 4000038844.0_dp, tiny = 1.0E-17_dp, &\r\n zero = 0.0_dp, one = 1.0_dp\r\nINTEGER :: n\r\nLOGICAL, SAVE :: inital = .TRUE.\r\n\r\n! This returns a uniform (0,1) random number, with extremely good\r\n! uniformity properties. It assumes that REAL (dp) provides\r\n! at least 33 bits of accuracy, and uses a power of two base.\r\n\r\nIF (inital) THEN\r\n CALL sdprnd (0)\r\n inital = .false.\r\nEND IF\r\n\r\n! See [Knuth] for why this implements the algorithm described in the paper.\r\n! Note that this code is tuned for machines with fast REAL (dp), but\r\n! slow multiply and divide; many, many other options are possible.\r\n\r\nn = INDEX - 64\r\nIF (n <= 0) n = n + 101\r\nx = poly(INDEX) + poly(INDEX)\r\nx = xmod4 - poly(n) - poly(n) - x - x - poly(INDEX)\r\nIF (x < zero) THEN\r\n IF (x < -xmod) x = x + xmod2\r\n IF (x < zero) x = x + xmod\r\nELSE\r\n IF (x >= xmod2) THEN\r\n x = x - xmod2\r\n IF (x >= xmod) x = x - xmod\r\n END IF\r\n IF (x >= xmod) x = x - xmod\r\nEND IF\r\npoly(INDEX) = x\r\nINDEX = INDEX + 1\r\nIF (INDEX > 101) INDEX = INDEX - 101\r\n\r\n! Add in the second generator modulo 1, and force to be non-zero.\r\n! The restricted ranges largely cancel themselves out.\r\n\r\nDO\r\n y = 37.0_dp*other + offset\r\n other = y - AINT(y)\r\n IF (other /= zero) EXIT\r\nEND DO\r\n\r\nx = x/xmod + other\r\nIF (x >= one) x = x - one\r\nfn_val = x + tiny\r\n\r\nRETURN\r\nEND FUNCTION dprand\r\n\r\nEND MODULE randdp\r\n", "meta": {"hexsha": "2c6ecef01c8be58df27970656f52e46b2ec37b0f", "size": 3843, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/dprand.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/dprand.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/dprand.f90", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 28.2573529412, "max_line_length": 83, "alphanum_fraction": 0.6286755139, "num_tokens": 1225, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110396870288, "lm_q2_score": 0.7490872075132153, "lm_q1q2_score": 0.6680442413486136}} {"text": "subroutine dff_test2\nuse enforce\nuse cluster\nuse paracluster\n\nimplicit none\n\ninteger :: i,n,k\nreal, allocatable :: dft(:)\nreal :: arg,freq\n\nallocate(dft(npas))\n\ndo i = 1,npas\n\tdft(i) = 0.d0\nenddo\n\ndo k=1,npas\n\tfreq = 1.d0/(k*tstep)\n\targ = -(2.d0*pi*dble(1.d0/freq)/npas)\n\tdo n =1,npas\n\t\tdft(k) = dft(k) + cos(arg*dble(n))*vel_act_est(n)\n\tenddo\n\twrite(60,*) freq,dft(k)*dft(k)\nenddo\n\nend subroutine dff_test2\n\n!======================================================\n\n\nsubroutine dff_test\nuse ENFORCE!, only: vel_act_est\nuse CLUSTER\nuse PARACLUSTER\n\nimplicit none\n\n!variables needed: - N = npas + 1\n!\t\t\t- k = index for N\n!\t\t\t- n = index for chosen frequency \n!PLAN:\n!\tINITIALISE -- size of dft\n\ninteger :: N,N_i,freq,a,b,i\nreal, allocatable :: dft(:,:)\nreal :: arg\n\n!N = npas + 1!SIZE(vel_acf_est)\n!do i = 0,npas\n!\twrite(*,*) vel_act_est(i)\n!enddo\n\nallocate(dft(0:npas,2))\n\ndo a = 0,npas\n\tdft(a,1) = 0.d0\n\tdft(a,2) = 0.d0\nend do\n\n!open(11,file = 'fort.59', status = 'old' , action = 'read')\n\n!do b = 0,N\n!\tread(11,*) dft(b)\n!end do\n!open(60, file = 'fort.60', status = 'new', action = 'write')\n\ndo freq = 1,npas\n\tdo N_i = 1,npas\t\n\targ = -(2*pi*dble(N_i)/npas)\n\t!write(13,*) N_i,arg\n\tdft(freq,1) = dft(freq,1) + cos(arg*dble(freq)*tstep)*vel_act_est(N_i)!/npas\n\t!write(14,*) N_i ,dft(N_i,1) , cos(arg) ,vel_act_est(freq)\n\t!dft(N_i,2) = dft(N_i,2) + sin(arg*dble(freq))*vel_act_est(freq)!/npas\n\t!write(15,*) N_i,dft(N_i,2) , sin(arg) ,vel_act_est(freq)\n\tend do\nwrite(60,*) freq , dft(freq,1)*dft(freq,1) !+ dft(N_i,2)*dft(N_i,2)\nend do\n\n!do N_i = 0,npas\n\t!dft(N_i,1)=dft(N_i,1)/npas\n\t!dft(N_i,2)=dft(N_i,2)/npas\n\t!write(60,*) N_i , dft(N_i,1)*dft(N_i,1) + dft(N_i,2)*dft(N_i,2)\n!end do\n\nend subroutine dff_test\n", "meta": {"hexsha": "2b614ec35b45028ed7037032fe916a9a01bee7b1", "size": 1712, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "LoDiS_GIT/base/dft_test.f90", "max_stars_repo_name": "kcl-tscm/LoDiS", "max_stars_repo_head_hexsha": "c1c03b54ac68987a639103a8a99ea01b8a1c289b", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-10T02:07:36.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-10T02:07:36.000Z", "max_issues_repo_path": "LoDiS_GIT/base/dft_test.f90", "max_issues_repo_name": "kcl-tscm/LoDiS", "max_issues_repo_head_hexsha": "c1c03b54ac68987a639103a8a99ea01b8a1c289b", "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": "LoDiS_GIT/base/dft_test.f90", "max_forks_repo_name": "kcl-tscm/LoDiS", "max_forks_repo_head_hexsha": "c1c03b54ac68987a639103a8a99ea01b8a1c289b", "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": 19.6781609195, "max_line_length": 77, "alphanum_fraction": 0.6127336449, "num_tokens": 717, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110396870288, "lm_q2_score": 0.7490872075132153, "lm_q1q2_score": 0.6680442413486136}} {"text": "program semantic_error\n implicit none\n integer :: i\n do i = 0, 3\n print '(2I5)', i, fac(i)\n end do\ncontains\n\n integer function fac(n)\n implicit none\n integer, intent(in) :: n\n integer :: i\n fac = 1\n do i = 0, n\n fac = fac*i\n end do\n end function fac\n\nend program semantic_error\n", "meta": {"hexsha": "4ce52855b42b89cb668ca7f20da667c1aee482b6", "size": 356, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Debugging/SyntaxSemantics/semantic_error.f90", "max_stars_repo_name": "Gjacquenot/training-material", "max_stars_repo_head_hexsha": "16b29962bf5683f97a1072d961dd9f31e7468b8d", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 115, "max_stars_repo_stars_event_min_datetime": "2015-03-23T13:34:42.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T00:27:21.000Z", "max_issues_repo_path": "Debugging/SyntaxSemantics/semantic_error.f90", "max_issues_repo_name": "Gjacquenot/training-material", "max_issues_repo_head_hexsha": "16b29962bf5683f97a1072d961dd9f31e7468b8d", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 56, "max_issues_repo_issues_event_min_datetime": "2015-02-25T15:04:26.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-03T07:42:48.000Z", "max_forks_repo_path": "Debugging/SyntaxSemantics/semantic_error.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": 17.8, "max_line_length": 32, "alphanum_fraction": 0.5224719101, "num_tokens": 100, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8267117940706734, "lm_q2_score": 0.8080672158638527, "lm_q1q2_score": 0.6680386977564997}} {"text": "c\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc . .\nc . copyright (c) 1998 by UCAR .\nc . .\nc . University Corporation for Atmospheric Research .\nc . .\nc . all rights reserved .\nc . .\nc . .\nc . SPHEREPACK .\nc . .\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc\nc\nc\nc ... file vtsgs.f\nc\nc this file includes documentation and code for\nc subroutines vtsgs and vtsgsi\nc\nc ... files which must be loaded with vtsgs.f\nc\nc sphcom.f, hrfft.f, vhags.f, vhsgs.f,gaqd.f\nc\nc\nc subroutine vtsgs(nlat,nlon,ityp,nt,vt,wt,idvw,jdvw,br,bi,cr,ci,\nc + mdab,ndab,wvts,lwvts,work,lwork,ierror)\nc\nc given the vector harmonic analysis br,bi,cr, and ci (computed\nc by subroutine vhags) of some vector function (v,w), this\nc subroutine computes the vector function (vt,wt) which is\nc the derivative of (v,w) with respect to colatitude theta. vtsgs\nc is similar to vhsgs except the vector harmonics are replaced by\nc their derivative with respect to colatitude with the result that\nc (vt,wt) is computed instead of (v,w). vt(i,j) is the derivative\nc of the colatitudinal component v(i,j) at the gaussian colatitude\nc point theta(i) and longitude phi(j) = (j-1)*2*pi/nlon. the\nc spectral representation of (vt,wt) is given below at output\nc parameters vt,wt.\nc\nc input parameters\nc\nc nlat the number of gaussian colatitudinal grid points theta(i)\nc such that 0 < theta(1) <...< theta(nlat) < pi. they are\nc computed by subroutine gaqd which is called by this\nc subroutine. if nlat is odd the equator is\nc theta((nlat+1)/2). if nlat is even the equator lies\nc half way between theta(nlat/2) and theta(nlat/2+1). nlat\nc must be at least 3. note: if (v,w) is symmetric about\nc the equator (see parameter ityp below) the number of\nc colatitudinal grid points is nlat/2 if nlat is even or\nc (nlat+1)/2 if nlat is odd.\nc\nc nlon the number of distinct londitude points. nlon determines\nc the grid increment in longitude as 2*pi/nlon. for example\nc nlon = 72 for a five degree grid. nlon must be greater\nc than zero. the axisymmetric case corresponds to nlon=1.\nc the efficiency of the computation is improved when nlon\nc is a product of small prime numbers.\nc\nc ityp = 0 no symmetries exist about the equator. the synthesis\nc is performed on the entire sphere. i.e. the arrays\nc vt(i,j),wt(i,j) are computed for i=1,...,nlat and\nc j=1,...,nlon.\nc\nc = 1 no symmetries exist about the equator however the\nc the coefficients cr and ci are zero which implies\nc that the curl of (v,w) is zero. that is,\nc (d/dtheta (sin(theta) w) - dv/dphi)/sin(theta) = 0.\nc the calculations are performed on the entire sphere.\nc i.e. the arrays vt(i,j),wt(i,j) are computed for\nc i=1,...,nlat and j=1,...,nlon.\nc\nc = 2 no symmetries exist about the equator however the\nc the coefficients br and bi are zero which implies\nc that the divergence of (v,w) is zero. that is,\nc (d/dtheta (sin(theta) v) + dw/dphi)/sin(theta) = 0.\nc the calculations are performed on the entire sphere.\nc i.e. the arrays vt(i,j),wt(i,j) are computed for\nc i=1,...,nlat and j=1,...,nlon.\nc\nc = 3 vt is odd and wt is even about the equator. the\nc synthesis is performed on the northern hemisphere\nc only. i.e., if nlat is odd the arrays vt(i,j)\nc and wt(i,j) are computed for i=1,...,(nlat+1)/2\nc and j=1,...,nlon. if nlat is even the arrays\nc are computed for i=1,...,nlat/2 and j=1,...,nlon.\nc\nc = 4 vt is odd and wt is even about the equator and the\nc coefficients cr and ci are zero. the synthesis is\nc performed on the northern hemisphere only. i.e. if\nc nlat is odd the arrays vt(i,j),wt(i,j) are computed\nc for i=1,...,(nlat+1)/2 and j=1,...,nlon. if nlat is\nc even the arrays vt(i,j),wt(i,j) are computed for\nc i=1,...,nlat/2 and j=1,...,nlon.\nc\nc = 5 vt is odd and wt is even about the equator and the\nc coefficients br and bi are zero. the synthesis is\nc performed on the northern hemisphere only. i.e. if\nc nlat is odd the arrays vt(i,j),wt(i,j) are computed\nc for i=1,...,(nlat+1)/2 and j=1,...,nlon. if nlat is\nc even the arrays vt(i,j),wt(i,j) are computed for\nc i=1,...,nlat/2 and j=1,...,nlon.\nc\nc = 6 vt is even and wt is odd about the equator. the\nc synthesis is performed on the northern hemisphere\nc only. i.e., if nlat is odd the arrays vt(i,j),wt(i,j)\nc are computed for i=1,...,(nlat+1)/2 and j=1,...,nlon.\nC*PL*ERROR* Comment line too long\nc if nlat is even the arrays vt(i,j),wt(i,j) are computed\nc for i=1,...,nlat/2 and j=1,...,nlon.\nc\nc = 7 vt is even and wt is odd about the equator and the\nc coefficients cr and ci are zero. the synthesis is\nc performed on the northern hemisphere only. i.e. if\nc nlat is odd the arrays vt(i,j),wt(i,j) are computed\nc for i=1,...,(nlat+1)/2 and j=1,...,nlon. if nlat is\nc even the arrays vt(i,j),wt(i,j) are computed for\nc i=1,...,nlat/2 and j=1,...,nlon.\nc\nc = 8 vt is even and wt is odd about the equator and the\nc coefficients br and bi are zero. the synthesis is\nc performed on the northern hemisphere only. i.e. if\nc nlat is odd the arrays vt(i,j),wt(i,j) are computed\nc for i=1,...,(nlat+1)/2 and j=1,...,nlon. if nlat is\nc even the arrays vt(i,j),wt(i,j) are computed for\nc i=1,...,nlat/2 and j=1,...,nlon.\nc\nc nt the number of syntheses. in the program that calls vtsgs,\nc the arrays vt,wt,br,bi,cr, and ci can be three dimensional\nc in which case multiple syntheses will be performed.\nc the third index is the synthesis index which assumes the\nc values k=1,...,nt. for a single synthesis set nt=1. the\nc discription of the remaining parameters is simplified\nc by assuming that nt=1 or that all the arrays are two\nc dimensional.\nc\nc idvw the first dimension of the arrays vt,wt as it appears in\nc the program that calls vtsgs. if ityp .le. 2 then idvw\nc must be at least nlat. if ityp .gt. 2 and nlat is\nc even then idvw must be at least nlat/2. if ityp .gt. 2\nc and nlat is odd then idvw must be at least (nlat+1)/2.\nc\nc jdvw the second dimension of the arrays vt,wt as it appears in\nc the program that calls vtsgs. jdvw must be at least nlon.\nc\nc br,bi two or three dimensional arrays (see input parameter nt)\nc cr,ci that contain the vector spherical harmonic coefficients\nc of (v,w) as computed by subroutine vhags.\nc\nc mdab the first dimension of the arrays br,bi,cr, and ci as it\nc appears in the program that calls vtsgs. mdab must be at\nc least min0(nlat,nlon/2) if nlon is even or at least\nc min0(nlat,(nlon+1)/2) if nlon is odd.\nc\nc ndab the second dimension of the arrays br,bi,cr, and ci as it\nc appears in the program that calls vtsgs. ndab must be at\nc least nlat.\nc\nc wvts an array which must be initialized by subroutine vtsgsi.\nc once initialized, wvts can be used repeatedly by vtsgs\nc as long as nlon and nlat remain unchanged. wvts must\nc not be altered between calls of vtsgs.\nc\nc lwvts the dimension of the array wvts as it appears in the\nc program that calls vtsgs. define\nc\nc l1 = min0(nlat,nlon/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc and\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc then lwvts must be at least\nc\nc l1*l2*(nlat+nlat-l1+1)+nlon+15\nc\nc\nc work a work array that does not have to be saved.\nc\nc lwork the dimension of the array work as it appears in the\nc program that calls vtsgs. define\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc if ityp .le. 2 then lwork must be at least\nc\nc (2*nt+1)*nlat*nlon\nc\nc if ityp .gt. 2 then lwork must be at least\nc\nc (2*nt+1)*l2*nlon\nc\nc **************************************************************\nc\nc output parameters\nc\nc vt,wt two or three dimensional arrays (see input parameter nt)\nc in which the derivative of (v,w) with respect to\nc colatitude theta is stored. vt(i,j),wt(i,j) contain the\nc derivatives at gaussian colatitude points theta(i) for\nc i=1,...,nlat and longitude phi(j) = (j-1)*2*pi/nlon.\nc the index ranges are defined above at the input parameter\nc ityp. vt and wt are computed from the formulas for v and\nc w given in subroutine vhsgs but with vbar and wbar replaced\nc with their derivatives with respect to colatitude. these\nc derivatives are denoted by vtbar and wtbar.\nc\nc\nc *************************************************************\nc\nc in terms of real variables this expansion takes the form\nc\nc for i=1,...,nlat and j=1,...,nlon\nc\nc vt(i,j) = the sum from n=1 to n=nlat-1 of\nc\nc .5*br(1,n+1)*vtbar(0,n,theta(i))\nc\nc plus the sum from m=1 to m=mmax-1 of the sum from n=m to\nc n=nlat-1 of the real part of\nc\nc (br(m+1,n+1)*vtbar(m,n,theta(i))\nc -ci(m+1,n+1)*wtbar(m,n,theta(i)))*cos(m*phi(j))\nc -(bi(m+1,n+1)*vtbar(m,n,theta(i))\nc +cr(m+1,n+1)*wtbar(m,n,theta(i)))*sin(m*phi(j))\nc\nc and for i=1,...,nlat and j=1,...,nlon\nc\nc wt(i,j) = the sum from n=1 to n=nlat-1 of\nc\nc -.5*cr(1,n+1)*vtbar(0,n,theta(i))\nc\nc plus the sum from m=1 to m=mmax-1 of the sum from n=m to\nc n=nlat-1 of the real part of\nc\nc -(cr(m+1,n+1)*vtbar(m,n,theta(i))\nc +bi(m+1,n+1)*wtbar(m,n,theta(i)))*cos(m*phi(j))\nc +(ci(m+1,n+1)*vtbar(m,n,theta(i))\nc -br(m+1,n+1)*wtbar(m,n,theta(i)))*sin(m*phi(j))\nc\nc\nc br(m+1,nlat),bi(m+1,nlat),cr(m+1,nlat), and ci(m+1,nlat) are\nc assumed zero for m even.\nc\nc\nc ierror = 0 no errors\nc = 1 error in the specification of nlat\nc = 2 error in the specification of nlon\nc = 3 error in the specification of ityp\nc = 4 error in the specification of nt\nc = 5 error in the specification of idvw\nc = 6 error in the specification of jdvw\nc = 7 error in the specification of mdab\nc = 8 error in the specification of ndab\nc = 9 error in the specification of lwvts\nc = 10 error in the specification of lwork\nc\nc\nc *******************************************************************\nc\nc subroutine vtsgsi(nlat,nlon,wvts,lwvts,work,lwork,dwork,ldwork,\nc + ierror)\nc\nc subroutine vtsgsi initializes the array wvts which can then be\nc used repeatedly by subroutine vtsgs until nlat or nlon is changed.\nc\nc input parameters\nc\nc nlat the number of gaussian colatitudinal grid points theta(i)\nc such that 0 < theta(1) <...< theta(nlat) < pi. they are\nc computed by subroutine gaqd which is called by this\nc subroutine. if nlat is odd the equator is\nc theta((nlat+1)/2). if nlat is even the equator lies\nc half way between theta(nlat/2) and theta(nlat/2+1). nlat\nc must be at least 3. note: if (v,w) is symmetric about\nc the equator (see parameter ityp below) the number of\nc colatitudinal grid points is nlat/2 if nlat is even or\nc (nlat+1)/2 if nlat is odd.\nc\nc nlon the number of distinct londitude points. nlon determines\nc the grid increment in longitude as 2*pi/nlon. for example\nc nlon = 72 for a five degree grid. nlon must be greater\nc than zero. the axisymmetric case corresponds to nlon=1.\nc the efficiency of the computation is improved when nlon\nc is a product of small prime numbers.\nc\nc lwvts the dimension of the array wvts as it appears in the\nc program that calls vtsgs. define\nc\nc l1 = min0(nlat,nlon/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc and\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc then lwvts must be at least\nc\nc l1*l2*(nlat+nlat-l1+1)+nlon+15\nc\nc\nc work a work array that does not have to be saved.\nc\nc lwork the dimension of the array work as it appears in the\nc program that calls vtsgs. lwork must be at least\nc\nc 3*(max0(l1-2,0)*(nlat+nlat-l1-1))/2+(5*l2+2)*nlat\nc\nC*PL*ERROR* Comment line too long\nc dwork a double precision work array that does not have to be saved\nc\nc ldwork the length of dwork. ldwork must be at least\nc 3*nlat+2\nc\nc **************************************************************\nc\nc output parameters\nc\nc wvts an array which is initialized for use by subroutine vtsgs.\nc once initialized, wvts can be used repeatedly by vtsgs\nc as long as nlat or nlon remain unchanged. wvts must not\nc be altered between calls of vtsgs.\nc\nc\nc ierror = 0 no errors\nc = 1 error in the specification of nlat\nc = 2 error in the specification of nlon\nc = 3 error in the specification of lwvts\nc = 4 error in the specification of lwork\nc = 5 error in the specification of ldwork\nc\n SUBROUTINE DVTSGS(NLAT,NLON,ITYP,NT,VT,WT,IDVW,JDVW,BR,BI,CR,CI,\n + MDAB,NDAB,WVTS,LWVTS,WORK,LWORK,IERROR)\n DOUBLE PRECISION VT\n DOUBLE PRECISION WT\n DOUBLE PRECISION BR\n DOUBLE PRECISION BI\n DOUBLE PRECISION CR\n DOUBLE PRECISION CI\n DOUBLE PRECISION WVTS\n DOUBLE PRECISION WORK\nc\n DIMENSION VT(IDVW,JDVW,1),WT(IDVW,JDVW,1),BR(MDAB,NDAB,1),\n + BI(MDAB,NDAB,1),CR(MDAB,NDAB,1),CI(MDAB,NDAB,1),WORK(1),\n + WVTS(1)\n\n IERROR = 1\n IF (NLAT.LT.3) RETURN\n IERROR = 2\n IF (NLON.LT.1) RETURN\n IERROR = 3\n IF (ITYP.LT.0 .OR. ITYP.GT.8) RETURN\n IERROR = 4\n IF (NT.LT.0) RETURN\n IERROR = 5\n IMID = (NLAT+1)/2\n IF ((ITYP.LE.2.AND.IDVW.LT.NLAT) .OR.\n + (ITYP.GT.2.AND.IDVW.LT.IMID)) RETURN\n IERROR = 6\n IF (JDVW.LT.NLON) RETURN\n IERROR = 7\n MMAX = MIN0(NLAT, (NLON+1)/2)\n IF (MDAB.LT.MMAX) RETURN\n IERROR = 8\n IF (NDAB.LT.NLAT) RETURN\n IERROR = 9\n IDZ = (MMAX* (NLAT+NLAT-MMAX+1))/2\n LZIMN = IDZ*IMID\n IF (LWVTS.LT.LZIMN+LZIMN+NLON+15) RETURN\n IERROR = 10\n IDV = NLAT\n IF (ITYP.GT.2) IDV = IMID\n LNL = NT*IDV*NLON\n IF (LWORK.LT.LNL+LNL+IDV*NLON) RETURN\n IERROR = 0\n IST = 0\n IF (ITYP.LE.2) IST = IMID\n IW1 = IST + 1\n IW2 = LNL + 1\n IW3 = IW2 + IST\n IW4 = IW2 + LNL\n JW1 = LZIMN + 1\n JW2 = JW1 + LZIMN\n CALL DVTSGS1(NLAT,NLON,ITYP,NT,IMID,IDVW,JDVW,VT,WT,MDAB,NDAB,BR,\n + BI,CR,CI,IDV,WORK,WORK(IW1),WORK(IW2),WORK(IW3),\n + WORK(IW4),IDZ,WVTS,WVTS(JW1),WVTS(JW2))\n RETURN\n END\n SUBROUTINE DVTSGS1(NLAT,NLON,ITYP,NT,IMID,IDVW,JDVW,VT,WT,MDAB,\n + NDAB,BR,BI,CR,CI,IDV,VTE,VTO,WTE,WTO,WORK,IDZ,\n + VB,WB,WRFFT)\n DOUBLE PRECISION VT\n DOUBLE PRECISION WT\n DOUBLE PRECISION BR\n DOUBLE PRECISION BI\n DOUBLE PRECISION CR\n DOUBLE PRECISION CI\n DOUBLE PRECISION VTE\n DOUBLE PRECISION VTO\n DOUBLE PRECISION WTE\n DOUBLE PRECISION WTO\n DOUBLE PRECISION WORK\n DOUBLE PRECISION VB\n DOUBLE PRECISION WB\n DOUBLE PRECISION WRFFT\n DIMENSION VT(IDVW,JDVW,1),WT(IDVW,JDVW,1),BR(MDAB,NDAB,1),\n + BI(MDAB,NDAB,1),CR(MDAB,NDAB,1),CI(MDAB,NDAB,1),\n + VTE(IDV,NLON,1),VTO(IDV,NLON,1),WTE(IDV,NLON,1),\n + WTO(IDV,NLON,1),WORK(1),WRFFT(1),VB(IMID,1),WB(IMID,1)\n\n NLP1 = NLAT + 1\n MLAT = MOD(NLAT,2)\n MLON = MOD(NLON,2)\n MMAX = MIN0(NLAT, (NLON+1)/2)\n IMM1 = IMID\n IF (MLAT.NE.0) IMM1 = IMID - 1\n DO 10 K = 1,NT\n DO 10 J = 1,NLON\n DO 10 I = 1,IDV\n VTE(I,J,K) = 0.D0\n WTE(I,J,K) = 0.D0\n 10 CONTINUE\n NDO1 = NLAT\n NDO2 = NLAT\n IF (MLAT.NE.0) NDO1 = NLAT - 1\n IF (MLAT.EQ.0) NDO2 = NLAT - 1\n 18 ITYPP = ITYP + 1\n GO TO (1,100,200,300,400,500,600,700,800) ITYPP\nc\nc case ityp=0 no symmetries\nc\nc case m = 0\nc\n 1 DO 15 K = 1,NT\n DO 15 NP1 = 2,NDO2,2\n DO 15 I = 1,IMM1\n VTO(I,1,K) = VTO(I,1,K) + BR(1,NP1,K)*VB(I,NP1)\n WTO(I,1,K) = WTO(I,1,K) - CR(1,NP1,K)*VB(I,NP1)\n 15 CONTINUE\n DO 16 K = 1,NT\n DO 16 NP1 = 3,NDO1,2\n DO 16 I = 1,IMID\n VTE(I,1,K) = VTE(I,1,K) + BR(1,NP1,K)*VB(I,NP1)\n WTE(I,1,K) = WTE(I,1,K) - CR(1,NP1,K)*VB(I,NP1)\n 16 CONTINUE\nc\nc case m = 1 through nlat-1\nc\n IF (MMAX.LT.2) GO TO 950\n DO 30 MP1 = 2,MMAX\n M = MP1 - 1\n MB = M* (NLAT-1) - (M* (M-1))/2\n MP2 = MP1 + 1\n IF (MP1.GT.NDO1) GO TO 26\n DO 25 K = 1,NT\n DO 24 NP1 = MP1,NDO1,2\n MN = MB + NP1\n DO 23 I = 1,IMM1\n VTE(I,2*MP1-2,K) = VTE(I,2*MP1-2,K) +\n + BR(MP1,NP1,K)*VB(I,MN)\n VTO(I,2*MP1-2,K) = VTO(I,2*MP1-2,K) -\n + CI(MP1,NP1,K)*WB(I,MN)\n VTE(I,2*MP1-1,K) = VTE(I,2*MP1-1,K) +\n + BI(MP1,NP1,K)*VB(I,MN)\n VTO(I,2*MP1-1,K) = VTO(I,2*MP1-1,K) +\n + CR(MP1,NP1,K)*WB(I,MN)\n WTE(I,2*MP1-2,K) = WTE(I,2*MP1-2,K) -\n + CR(MP1,NP1,K)*VB(I,MN)\n WTO(I,2*MP1-2,K) = WTO(I,2*MP1-2,K) -\n + BI(MP1,NP1,K)*WB(I,MN)\n WTE(I,2*MP1-1,K) = WTE(I,2*MP1-1,K) -\n + CI(MP1,NP1,K)*VB(I,MN)\n WTO(I,2*MP1-1,K) = WTO(I,2*MP1-1,K) +\n + BR(MP1,NP1,K)*WB(I,MN)\n 23 CONTINUE\n IF (MLAT.EQ.0) GO TO 24\n VTE(IMID,2*MP1-2,K) = VTE(IMID,2*MP1-2,K) +\n + BR(MP1,NP1,K)*VB(IMID,MN)\n VTE(IMID,2*MP1-1,K) = VTE(IMID,2*MP1-1,K) +\n + BI(MP1,NP1,K)*VB(IMID,MN)\n WTE(IMID,2*MP1-2,K) = WTE(IMID,2*MP1-2,K) -\n + CR(MP1,NP1,K)*VB(IMID,MN)\n WTE(IMID,2*MP1-1,K) = WTE(IMID,2*MP1-1,K) -\n + CI(MP1,NP1,K)*VB(IMID,MN)\n 24 CONTINUE\n 25 CONTINUE\n 26 IF (MP2.GT.NDO2) GO TO 30\n DO 29 K = 1,NT\n DO 28 NP1 = MP2,NDO2,2\n MN = MB + NP1\n DO 27 I = 1,IMM1\n VTO(I,2*MP1-2,K) = VTO(I,2*MP1-2,K) +\n + BR(MP1,NP1,K)*VB(I,MN)\n VTE(I,2*MP1-2,K) = VTE(I,2*MP1-2,K) -\n + CI(MP1,NP1,K)*WB(I,MN)\n VTO(I,2*MP1-1,K) = VTO(I,2*MP1-1,K) +\n + BI(MP1,NP1,K)*VB(I,MN)\n VTE(I,2*MP1-1,K) = VTE(I,2*MP1-1,K) +\n + CR(MP1,NP1,K)*WB(I,MN)\n WTO(I,2*MP1-2,K) = WTO(I,2*MP1-2,K) -\n + CR(MP1,NP1,K)*VB(I,MN)\n WTE(I,2*MP1-2,K) = WTE(I,2*MP1-2,K) -\n + BI(MP1,NP1,K)*WB(I,MN)\n WTO(I,2*MP1-1,K) = WTO(I,2*MP1-1,K) -\n + CI(MP1,NP1,K)*VB(I,MN)\n WTE(I,2*MP1-1,K) = WTE(I,2*MP1-1,K) +\n + BR(MP1,NP1,K)*WB(I,MN)\n 27 CONTINUE\n IF (MLAT.EQ.0) GO TO 28\n VTE(IMID,2*MP1-2,K) = VTE(IMID,2*MP1-2,K) -\n + CI(MP1,NP1,K)*WB(IMID,MN)\n VTE(IMID,2*MP1-1,K) = VTE(IMID,2*MP1-1,K) +\n + CR(MP1,NP1,K)*WB(IMID,MN)\n WTE(IMID,2*MP1-2,K) = WTE(IMID,2*MP1-2,K) -\n + BI(MP1,NP1,K)*WB(IMID,MN)\n WTE(IMID,2*MP1-1,K) = WTE(IMID,2*MP1-1,K) +\n + BR(MP1,NP1,K)*WB(IMID,MN)\n 28 CONTINUE\n 29 CONTINUE\n 30 CONTINUE\n GO TO 950\nc\nc case ityp=1 no symmetries, cr and ci equal zero\nc\nc case m = 0\nc\n 100 DO 115 K = 1,NT\n DO 115 NP1 = 2,NDO2,2\n DO 115 I = 1,IMM1\n VTO(I,1,K) = VTO(I,1,K) + BR(1,NP1,K)*VB(I,NP1)\n 115 CONTINUE\n DO 116 K = 1,NT\n DO 116 NP1 = 3,NDO1,2\n DO 116 I = 1,IMID\n VTE(I,1,K) = VTE(I,1,K) + BR(1,NP1,K)*VB(I,NP1)\n 116 CONTINUE\nc\nc case m = 1 through nlat-1\nc\n IF (MMAX.LT.2) GO TO 950\n DO 130 MP1 = 2,MMAX\n M = MP1 - 1\n MB = M* (NLAT-1) - (M* (M-1))/2\n MP2 = MP1 + 1\n IF (MP1.GT.NDO1) GO TO 126\n DO 125 K = 1,NT\n DO 124 NP1 = MP1,NDO1,2\n MN = MB + NP1\n DO 123 I = 1,IMM1\n VTE(I,2*MP1-2,K) = VTE(I,2*MP1-2,K) +\n + BR(MP1,NP1,K)*VB(I,MN)\n VTE(I,2*MP1-1,K) = VTE(I,2*MP1-1,K) +\n + BI(MP1,NP1,K)*VB(I,MN)\n WTO(I,2*MP1-2,K) = WTO(I,2*MP1-2,K) -\n + BI(MP1,NP1,K)*WB(I,MN)\n WTO(I,2*MP1-1,K) = WTO(I,2*MP1-1,K) +\n + BR(MP1,NP1,K)*WB(I,MN)\n 123 CONTINUE\n IF (MLAT.EQ.0) GO TO 124\n VTE(IMID,2*MP1-2,K) = VTE(IMID,2*MP1-2,K) +\n + BR(MP1,NP1,K)*VB(IMID,MN)\n VTE(IMID,2*MP1-1,K) = VTE(IMID,2*MP1-1,K) +\n + BI(MP1,NP1,K)*VB(IMID,MN)\n 124 CONTINUE\n 125 CONTINUE\n 126 IF (MP2.GT.NDO2) GO TO 130\n DO 129 K = 1,NT\n DO 128 NP1 = MP2,NDO2,2\n MN = MB + NP1\n DO 127 I = 1,IMM1\n VTO(I,2*MP1-2,K) = VTO(I,2*MP1-2,K) +\n + BR(MP1,NP1,K)*VB(I,MN)\n VTO(I,2*MP1-1,K) = VTO(I,2*MP1-1,K) +\n + BI(MP1,NP1,K)*VB(I,MN)\n WTE(I,2*MP1-2,K) = WTE(I,2*MP1-2,K) -\n + BI(MP1,NP1,K)*WB(I,MN)\n WTE(I,2*MP1-1,K) = WTE(I,2*MP1-1,K) +\n + BR(MP1,NP1,K)*WB(I,MN)\n 127 CONTINUE\n IF (MLAT.EQ.0) GO TO 128\n WTE(IMID,2*MP1-2,K) = WTE(IMID,2*MP1-2,K) -\n + BI(MP1,NP1,K)*WB(IMID,MN)\n WTE(IMID,2*MP1-1,K) = WTE(IMID,2*MP1-1,K) +\n + BR(MP1,NP1,K)*WB(IMID,MN)\n 128 CONTINUE\n 129 CONTINUE\n 130 CONTINUE\n GO TO 950\nc\nc case ityp=2 no symmetries, br and bi are equal to zero\nc\nc case m = 0\nc\n 200 DO 215 K = 1,NT\n DO 215 NP1 = 2,NDO2,2\n DO 215 I = 1,IMM1\n WTO(I,1,K) = WTO(I,1,K) - CR(1,NP1,K)*VB(I,NP1)\n 215 CONTINUE\n DO 216 K = 1,NT\n DO 216 NP1 = 3,NDO1,2\n DO 216 I = 1,IMID\n WTE(I,1,K) = WTE(I,1,K) - CR(1,NP1,K)*VB(I,NP1)\n 216 CONTINUE\nc\nc case m = 1 through nlat-1\nc\n IF (MMAX.LT.2) GO TO 950\n DO 230 MP1 = 2,MMAX\n M = MP1 - 1\n MB = M* (NLAT-1) - (M* (M-1))/2\n MP2 = MP1 + 1\n IF (MP1.GT.NDO1) GO TO 226\n DO 225 K = 1,NT\n DO 224 NP1 = MP1,NDO1,2\n MN = MB + NP1\n DO 223 I = 1,IMM1\n VTO(I,2*MP1-2,K) = VTO(I,2*MP1-2,K) -\n + CI(MP1,NP1,K)*WB(I,MN)\n VTO(I,2*MP1-1,K) = VTO(I,2*MP1-1,K) +\n + CR(MP1,NP1,K)*WB(I,MN)\n WTE(I,2*MP1-2,K) = WTE(I,2*MP1-2,K) -\n + CR(MP1,NP1,K)*VB(I,MN)\n WTE(I,2*MP1-1,K) = WTE(I,2*MP1-1,K) -\n + CI(MP1,NP1,K)*VB(I,MN)\n 223 CONTINUE\n IF (MLAT.EQ.0) GO TO 224\n WTE(IMID,2*MP1-2,K) = WTE(IMID,2*MP1-2,K) -\n + CR(MP1,NP1,K)*VB(IMID,MN)\n WTE(IMID,2*MP1-1,K) = WTE(IMID,2*MP1-1,K) -\n + CI(MP1,NP1,K)*VB(IMID,MN)\n 224 CONTINUE\n 225 CONTINUE\n 226 IF (MP2.GT.NDO2) GO TO 230\n DO 229 K = 1,NT\n DO 228 NP1 = MP2,NDO2,2\n MN = MB + NP1\n DO 227 I = 1,IMM1\n VTE(I,2*MP1-2,K) = VTE(I,2*MP1-2,K) -\n + CI(MP1,NP1,K)*WB(I,MN)\n VTE(I,2*MP1-1,K) = VTE(I,2*MP1-1,K) +\n + CR(MP1,NP1,K)*WB(I,MN)\n WTO(I,2*MP1-2,K) = WTO(I,2*MP1-2,K) -\n + CR(MP1,NP1,K)*VB(I,MN)\n WTO(I,2*MP1-1,K) = WTO(I,2*MP1-1,K) -\n + CI(MP1,NP1,K)*VB(I,MN)\n 227 CONTINUE\n IF (MLAT.EQ.0) GO TO 228\n VTE(IMID,2*MP1-2,K) = VTE(IMID,2*MP1-2,K) -\n + CI(MP1,NP1,K)*WB(IMID,MN)\n VTE(IMID,2*MP1-1,K) = VTE(IMID,2*MP1-1,K) +\n + CR(MP1,NP1,K)*WB(IMID,MN)\n 228 CONTINUE\n 229 CONTINUE\n 230 CONTINUE\n GO TO 950\nc\nc case ityp=3 v odd, w even\nc\nc case m = 0\nc\n 300 DO 315 K = 1,NT\n DO 315 NP1 = 2,NDO2,2\n DO 315 I = 1,IMM1\n VTO(I,1,K) = VTO(I,1,K) + BR(1,NP1,K)*VB(I,NP1)\n 315 CONTINUE\n DO 316 K = 1,NT\n DO 316 NP1 = 3,NDO1,2\n DO 316 I = 1,IMID\n WTE(I,1,K) = WTE(I,1,K) - CR(1,NP1,K)*VB(I,NP1)\n 316 CONTINUE\nc\nc case m = 1 through nlat-1\nc\n IF (MMAX.LT.2) GO TO 950\n DO 330 MP1 = 2,MMAX\n M = MP1 - 1\n MB = M* (NLAT-1) - (M* (M-1))/2\n MP2 = MP1 + 1\n IF (MP1.GT.NDO1) GO TO 326\n DO 325 K = 1,NT\n DO 324 NP1 = MP1,NDO1,2\n MN = MB + NP1\n DO 323 I = 1,IMM1\n VTO(I,2*MP1-2,K) = VTO(I,2*MP1-2,K) -\n + CI(MP1,NP1,K)*WB(I,MN)\n VTO(I,2*MP1-1,K) = VTO(I,2*MP1-1,K) +\n + CR(MP1,NP1,K)*WB(I,MN)\n WTE(I,2*MP1-2,K) = WTE(I,2*MP1-2,K) -\n + CR(MP1,NP1,K)*VB(I,MN)\n WTE(I,2*MP1-1,K) = WTE(I,2*MP1-1,K) -\n + CI(MP1,NP1,K)*VB(I,MN)\n 323 CONTINUE\n IF (MLAT.EQ.0) GO TO 324\n WTE(IMID,2*MP1-2,K) = WTE(IMID,2*MP1-2,K) -\n + CR(MP1,NP1,K)*VB(IMID,MN)\n WTE(IMID,2*MP1-1,K) = WTE(IMID,2*MP1-1,K) -\n + CI(MP1,NP1,K)*VB(IMID,MN)\n 324 CONTINUE\n 325 CONTINUE\n 326 IF (MP2.GT.NDO2) GO TO 330\n DO 329 K = 1,NT\n DO 328 NP1 = MP2,NDO2,2\n MN = MB + NP1\n DO 327 I = 1,IMM1\n VTO(I,2*MP1-2,K) = VTO(I,2*MP1-2,K) +\n + BR(MP1,NP1,K)*VB(I,MN)\n VTO(I,2*MP1-1,K) = VTO(I,2*MP1-1,K) +\n + BI(MP1,NP1,K)*VB(I,MN)\n WTE(I,2*MP1-2,K) = WTE(I,2*MP1-2,K) -\n + BI(MP1,NP1,K)*WB(I,MN)\n WTE(I,2*MP1-1,K) = WTE(I,2*MP1-1,K) +\n + BR(MP1,NP1,K)*WB(I,MN)\n 327 CONTINUE\n IF (MLAT.EQ.0) GO TO 328\n WTE(IMID,2*MP1-2,K) = WTE(IMID,2*MP1-2,K) -\n + BI(MP1,NP1,K)*WB(IMID,MN)\n WTE(IMID,2*MP1-1,K) = WTE(IMID,2*MP1-1,K) +\n + BR(MP1,NP1,K)*WB(IMID,MN)\n 328 CONTINUE\n 329 CONTINUE\n 330 CONTINUE\n GO TO 950\nc\nc case ityp=4 v odd, w even, and both cr and ci equal zero\nc\nc case m = 0\nc\n 400 DO 415 K = 1,NT\n DO 415 NP1 = 2,NDO2,2\n DO 415 I = 1,IMM1\n VTO(I,1,K) = VTO(I,1,K) + BR(1,NP1,K)*VB(I,NP1)\n 415 CONTINUE\nc\nc case m = 1 through nlat-1\nc\n IF (MMAX.LT.2) GO TO 950\n DO 430 MP1 = 2,MMAX\n M = MP1 - 1\n MB = M* (NLAT-1) - (M* (M-1))/2\n MP2 = MP1 + 1\n IF (MP2.GT.NDO2) GO TO 430\n DO 429 K = 1,NT\n DO 428 NP1 = MP2,NDO2,2\n MN = MB + NP1\n DO 427 I = 1,IMM1\n VTO(I,2*MP1-2,K) = VTO(I,2*MP1-2,K) +\n + BR(MP1,NP1,K)*VB(I,MN)\n VTO(I,2*MP1-1,K) = VTO(I,2*MP1-1,K) +\n + BI(MP1,NP1,K)*VB(I,MN)\n WTE(I,2*MP1-2,K) = WTE(I,2*MP1-2,K) -\n + BI(MP1,NP1,K)*WB(I,MN)\n WTE(I,2*MP1-1,K) = WTE(I,2*MP1-1,K) +\n + BR(MP1,NP1,K)*WB(I,MN)\n 427 CONTINUE\n IF (MLAT.EQ.0) GO TO 428\n WTE(IMID,2*MP1-2,K) = WTE(IMID,2*MP1-2,K) -\n + BI(MP1,NP1,K)*WB(IMID,MN)\n WTE(IMID,2*MP1-1,K) = WTE(IMID,2*MP1-1,K) +\n + BR(MP1,NP1,K)*WB(IMID,MN)\n 428 CONTINUE\n 429 CONTINUE\n 430 CONTINUE\n GO TO 950\nc\nc case ityp=5 v odd, w even, br and bi equal zero\nc\nc case m = 0\nc\n 500 DO 516 K = 1,NT\n DO 516 NP1 = 3,NDO1,2\n DO 516 I = 1,IMID\n WTE(I,1,K) = WTE(I,1,K) - CR(1,NP1,K)*VB(I,NP1)\n 516 CONTINUE\nc\nc case m = 1 through nlat-1\nc\n IF (MMAX.LT.2) GO TO 950\n DO 530 MP1 = 2,MMAX\n M = MP1 - 1\n MB = M* (NLAT-1) - (M* (M-1))/2\n MP2 = MP1 + 1\n IF (MP1.GT.NDO1) GO TO 530\n DO 525 K = 1,NT\n DO 524 NP1 = MP1,NDO1,2\n MN = MB + NP1\n DO 523 I = 1,IMM1\n VTO(I,2*MP1-2,K) = VTO(I,2*MP1-2,K) -\n + CI(MP1,NP1,K)*WB(I,MN)\n VTO(I,2*MP1-1,K) = VTO(I,2*MP1-1,K) +\n + CR(MP1,NP1,K)*WB(I,MN)\n WTE(I,2*MP1-2,K) = WTE(I,2*MP1-2,K) -\n + CR(MP1,NP1,K)*VB(I,MN)\n WTE(I,2*MP1-1,K) = WTE(I,2*MP1-1,K) -\n + CI(MP1,NP1,K)*VB(I,MN)\n 523 CONTINUE\n IF (MLAT.EQ.0) GO TO 524\n WTE(IMID,2*MP1-2,K) = WTE(IMID,2*MP1-2,K) -\n + CR(MP1,NP1,K)*VB(IMID,MN)\n WTE(IMID,2*MP1-1,K) = WTE(IMID,2*MP1-1,K) -\n + CI(MP1,NP1,K)*VB(IMID,MN)\n 524 CONTINUE\n 525 CONTINUE\n 530 CONTINUE\n GO TO 950\nc\nc case ityp=6 v even , w odd\nc\nc case m = 0\nc\n 600 DO 615 K = 1,NT\n DO 615 NP1 = 2,NDO2,2\n DO 615 I = 1,IMM1\n WTO(I,1,K) = WTO(I,1,K) - CR(1,NP1,K)*VB(I,NP1)\n 615 CONTINUE\n DO 616 K = 1,NT\n DO 616 NP1 = 3,NDO1,2\n DO 616 I = 1,IMID\n VTE(I,1,K) = VTE(I,1,K) + BR(1,NP1,K)*VB(I,NP1)\n 616 CONTINUE\nc\nc case m = 1 through nlat-1\nc\n IF (MMAX.LT.2) GO TO 950\n DO 630 MP1 = 2,MMAX\n M = MP1 - 1\n MB = M* (NLAT-1) - (M* (M-1))/2\n MP2 = MP1 + 1\n IF (MP1.GT.NDO1) GO TO 626\n DO 625 K = 1,NT\n DO 624 NP1 = MP1,NDO1,2\n MN = MB + NP1\n DO 623 I = 1,IMM1\n VTE(I,2*MP1-2,K) = VTE(I,2*MP1-2,K) +\n + BR(MP1,NP1,K)*VB(I,MN)\n VTE(I,2*MP1-1,K) = VTE(I,2*MP1-1,K) +\n + BI(MP1,NP1,K)*VB(I,MN)\n WTO(I,2*MP1-2,K) = WTO(I,2*MP1-2,K) -\n + BI(MP1,NP1,K)*WB(I,MN)\n WTO(I,2*MP1-1,K) = WTO(I,2*MP1-1,K) +\n + BR(MP1,NP1,K)*WB(I,MN)\n 623 CONTINUE\n IF (MLAT.EQ.0) GO TO 624\n VTE(IMID,2*MP1-2,K) = VTE(IMID,2*MP1-2,K) +\n + BR(MP1,NP1,K)*VB(IMID,MN)\n VTE(IMID,2*MP1-1,K) = VTE(IMID,2*MP1-1,K) +\n + BI(MP1,NP1,K)*VB(IMID,MN)\n 624 CONTINUE\n 625 CONTINUE\n 626 IF (MP2.GT.NDO2) GO TO 630\n DO 629 K = 1,NT\n DO 628 NP1 = MP2,NDO2,2\n MN = MB + NP1\n DO 627 I = 1,IMM1\n VTE(I,2*MP1-2,K) = VTE(I,2*MP1-2,K) -\n + CI(MP1,NP1,K)*WB(I,MN)\n VTE(I,2*MP1-1,K) = VTE(I,2*MP1-1,K) +\n + CR(MP1,NP1,K)*WB(I,MN)\n WTO(I,2*MP1-2,K) = WTO(I,2*MP1-2,K) -\n + CR(MP1,NP1,K)*VB(I,MN)\n WTO(I,2*MP1-1,K) = WTO(I,2*MP1-1,K) -\n + CI(MP1,NP1,K)*VB(I,MN)\n 627 CONTINUE\n IF (MLAT.EQ.0) GO TO 628\n VTE(IMID,2*MP1-2,K) = VTE(IMID,2*MP1-2,K) -\n + CI(MP1,NP1,K)*WB(IMID,MN)\n VTE(IMID,2*MP1-1,K) = VTE(IMID,2*MP1-1,K) +\n + CR(MP1,NP1,K)*WB(IMID,MN)\n 628 CONTINUE\n 629 CONTINUE\n 630 CONTINUE\n GO TO 950\nc\nc case ityp=7 v even, w odd cr and ci equal zero\nc\nc case m = 0\nc\n 700 DO 716 K = 1,NT\n DO 716 NP1 = 3,NDO1,2\n DO 716 I = 1,IMID\n VTE(I,1,K) = VTE(I,1,K) + BR(1,NP1,K)*VB(I,NP1)\n 716 CONTINUE\nc\nc case m = 1 through nlat-1\nc\n IF (MMAX.LT.2) GO TO 950\n DO 730 MP1 = 2,MMAX\n M = MP1 - 1\n MB = M* (NLAT-1) - (M* (M-1))/2\n MP2 = MP1 + 1\n IF (MP1.GT.NDO1) GO TO 730\n DO 725 K = 1,NT\n DO 724 NP1 = MP1,NDO1,2\n MN = MB + NP1\n DO 723 I = 1,IMM1\n VTE(I,2*MP1-2,K) = VTE(I,2*MP1-2,K) +\n + BR(MP1,NP1,K)*VB(I,MN)\n VTE(I,2*MP1-1,K) = VTE(I,2*MP1-1,K) +\n + BI(MP1,NP1,K)*VB(I,MN)\n WTO(I,2*MP1-2,K) = WTO(I,2*MP1-2,K) -\n + BI(MP1,NP1,K)*WB(I,MN)\n WTO(I,2*MP1-1,K) = WTO(I,2*MP1-1,K) +\n + BR(MP1,NP1,K)*WB(I,MN)\n 723 CONTINUE\n IF (MLAT.EQ.0) GO TO 724\n VTE(IMID,2*MP1-2,K) = VTE(IMID,2*MP1-2,K) +\n + BR(MP1,NP1,K)*VB(IMID,MN)\n VTE(IMID,2*MP1-1,K) = VTE(IMID,2*MP1-1,K) +\n + BI(MP1,NP1,K)*VB(IMID,MN)\n 724 CONTINUE\n 725 CONTINUE\n 730 CONTINUE\n GO TO 950\nc\nc case ityp=8 v even, w odd, br and bi equal zero\nc\nc case m = 0\nc\n 800 DO 815 K = 1,NT\n DO 815 NP1 = 2,NDO2,2\n DO 815 I = 1,IMM1\n WTO(I,1,K) = WTO(I,1,K) - CR(1,NP1,K)*VB(I,NP1)\n 815 CONTINUE\nc\nc case m = 1 through nlat-1\nc\n IF (MMAX.LT.2) GO TO 950\n DO 830 MP1 = 2,MMAX\n M = MP1 - 1\n MB = M* (NLAT-1) - (M* (M-1))/2\n MP2 = MP1 + 1\n IF (MP2.GT.NDO2) GO TO 830\n DO 829 K = 1,NT\n DO 828 NP1 = MP2,NDO2,2\n MN = MB + NP1\n DO 827 I = 1,IMM1\n VTE(I,2*MP1-2,K) = VTE(I,2*MP1-2,K) -\n + CI(MP1,NP1,K)*WB(I,MN)\n VTE(I,2*MP1-1,K) = VTE(I,2*MP1-1,K) +\n + CR(MP1,NP1,K)*WB(I,MN)\n WTO(I,2*MP1-2,K) = WTO(I,2*MP1-2,K) -\n + CR(MP1,NP1,K)*VB(I,MN)\n WTO(I,2*MP1-1,K) = WTO(I,2*MP1-1,K) -\n + CI(MP1,NP1,K)*VB(I,MN)\n 827 CONTINUE\n IF (MLAT.EQ.0) GO TO 828\n VTE(IMID,2*MP1-2,K) = VTE(IMID,2*MP1-2,K) -\n + CI(MP1,NP1,K)*WB(IMID,MN)\n VTE(IMID,2*MP1-1,K) = VTE(IMID,2*MP1-1,K) +\n + CR(MP1,NP1,K)*WB(IMID,MN)\n 828 CONTINUE\n 829 CONTINUE\n 830 CONTINUE\n 950 DO 14 K = 1,NT\n CALL DHRFFTB(IDV,NLON,VTE(1,1,K),IDV,WRFFT,WORK)\n CALL DHRFFTB(IDV,NLON,WTE(1,1,K),IDV,WRFFT,WORK)\n 14 CONTINUE\n IF (ITYP.GT.2) GO TO 12\n DO 60 K = 1,NT\n DO 60 J = 1,NLON\n DO 60 I = 1,IMM1\n VT(I,J,K) = .5D0* (VTE(I,J,K)+VTO(I,J,K))\n WT(I,J,K) = .5D0* (WTE(I,J,K)+WTO(I,J,K))\n VT(NLP1-I,J,K) = .5D0* (VTE(I,J,K)-VTO(I,J,K))\n WT(NLP1-I,J,K) = .5D0* (WTE(I,J,K)-WTO(I,J,K))\n 60 CONTINUE\n GO TO 13\n 12 DO 11 K = 1,NT\n DO 11 J = 1,NLON\n DO 11 I = 1,IMM1\n VT(I,J,K) = .5D0*VTE(I,J,K)\n WT(I,J,K) = .5D0*WTE(I,J,K)\n 11 CONTINUE\n 13 IF (MLAT.EQ.0) RETURN\n DO 65 K = 1,NT\n DO 65 J = 1,NLON\n VT(IMID,J,K) = .5D0*VTE(IMID,J,K)\n WT(IMID,J,K) = .5D0*WTE(IMID,J,K)\n 65 CONTINUE\n RETURN\n END\n SUBROUTINE DVTSGSI(NLAT,NLON,WVTS,LWVTS,WORK,LWORK,DWORK,LDWORK,\n + IERROR)\n DOUBLE PRECISION WVTS\n DOUBLE PRECISION WORK\nc\nc define imid = (nlat+1)/2 and mmax = min0(nlat,(nlon+1)/2)\nc the length of wvts is imid*mmax*(nlat+nlat-mmax+1)+nlon+15\nc and the length of work is labc+5*nlat*imid+2*nlat where\nc labc = 3*(max0(mmax-2,0)*(nlat+nlat-mmax-1))/2\nc\n DIMENSION WVTS(LWVTS),WORK(LWORK)\nC*PT*WARNING* Already double-precision\n DOUBLE PRECISION DWORK(LDWORK)\n\n IERROR = 1\n IF (NLAT.LT.3) RETURN\n IERROR = 2\n IF (NLON.LT.1) RETURN\n IERROR = 3\n MMAX = MIN0(NLAT,NLON/2+1)\n IMID = (NLAT+1)/2\n LZIMN = (IMID*MMAX* (NLAT+NLAT-MMAX+1))/2\n IF (LWVTS.LT.LZIMN+LZIMN+NLON+15) RETURN\n IERROR = 4\n LABC = 3* (MAX0(MMAX-2,0)* (NLAT+NLAT-MMAX-1))/2\n LVIN = 3*NLAT*IMID\n LWVBIN = 2*NLAT*IMID + LABC\n LTHETA = NLAT + NLAT\n IF (LWORK.LT.LVIN+LWVBIN+LTHETA) RETURN\n IERROR = 5\n IF (LDWORK.LT.3*NLAT+2) RETURN\n IERROR = 0\n IW1 = LVIN + 1\n IW2 = IW1 + LWVBIN\n JW1 = NLAT + 1\n JW2 = JW1 + NLAT\n CALL DVETG1(NLAT,NLON,IMID,WVTS,WVTS(LZIMN+1),WORK,WORK(IW1),\n + DWORK,DWORK(JW1),DWORK(JW2),IERROR)\n IF (IERROR.NE.0) RETURN\n CALL DHRFFTI(NLON,WVTS(2*LZIMN+1))\n RETURN\n END\n SUBROUTINE DVETG1(NLAT,NLON,IMID,VB,WB,VIN,WVBIN,THETA,WTS,DWORK,\n + IERROR)\n DOUBLE PRECISION VB\n DOUBLE PRECISION WB\n DOUBLE PRECISION VIN\n DOUBLE PRECISION WVBIN\n DIMENSION VB(IMID,*),WB(IMID,*),VIN(IMID,NLAT,3),WVBIN(*)\nC*PT*WARNING* Already double-precision\n DOUBLE PRECISION DWORK(*),THETA(*),WTS(*)\n\n MMAX = MIN0(NLAT,NLON/2+1)\n LDWORK = 1\n CALL DGAQD(NLAT,THETA,WTS,DWORK,LDWORK,IERR)\n IF (IERR.EQ.0) GO TO 10\n IERROR = 10 + IERR\n RETURN\n 10 CALL DVTGINT(NLAT,NLON,THETA,WVBIN,DWORK)\n DO 33 MP1 = 1,MMAX\n M = MP1 - 1\n CALL DVBIN(0,NLAT,NLON,M,VIN,I3,WVBIN)\n DO 33 NP1 = MP1,NLAT\n MN = M* (NLAT-1) - (M* (M-1))/2 + NP1\n DO 33 I = 1,IMID\n VB(I,MN) = VIN(I,NP1,I3)\n 33 CONTINUE\n CALL DWTGINT(NLAT,NLON,THETA,WVBIN,DWORK)\n DO 34 MP1 = 1,MMAX\n M = MP1 - 1\n CALL DWBIN(0,NLAT,NLON,M,VIN,I3,WVBIN)\n DO 34 NP1 = MP1,NLAT\n MN = M* (NLAT-1) - (M* (M-1))/2 + NP1\n DO 34 I = 1,IMID\n WB(I,MN) = VIN(I,NP1,I3)\n 34 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "ec1e9be5489e71c871862057a64196d75a78e06c", "size": 42559, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "external/sphere3.1_dp/vtsgs.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "external/sphere3.1_dp/vtsgs.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "external/sphere3.1_dp/vtsgs.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 39.9615023474, "max_line_length": 73, "alphanum_fraction": 0.4496816185, "num_tokens": 15052, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.734119526900183, "lm_q1q2_score": 0.667980504382843}} {"text": "C\nC\n\n*+ fun_gammq\n\n real function fun_gammq( a, x, istat )\nC --------------------------------------\nC\nC Returns the incomplete gamma function Q(a,x) by argument\nC\nC Given:\nC parameters for the function\n real*4 a, x\nC Updated:\nC error return\n integer istat\nC\nC The incomplete Gamma function Q(a,x) is defined by:\nC \\[\nC Q(a,x) = 1 - \\frac{1}{\\Gamma(a)} \\int_{0}^{x} e^{-t}t^{a-1} dt\nC \\]\nC\nC ISTAT should be zero on entry. The values set by this routine are:\nC ILL_INPUTS == illegal ranges on input data.\nC ILL_PRECISION == unable to calculate function to sufficient\nC precision. This error can be returned from\nC one of the internal routines and results from\nC a to large or not enough iterations within\nC the respective routine. This error MUST\nC be reported.\nC\nC\nC P. Alexander, MRAO, Cambridge.\nC Ref: Numerical Recipes, Press et al., Cambridge. pg. 161.\nC-\n\n include '../include/utilities_errors.inc'\n\nC local variables\n real*4 gamser, gammcf, gln\n\n if (istat.ne.0) return\n\n if (x.lt.0.0 .or. a.le.0.0) then\n istat = ill_inputs\n fun_gammq = 0.0\n else\n if (x.lt.a+1.0) then\nC .. use series representation\n call fun_gser(gamser,a,x,gln,istat)\nC .. take complement\n fun_gammq = 1.0 - gamser\n else\nC .. use continued fraction\n call fun_gcf(gammcf,a,x,gln,istat)\n fun_gammq = gammcf\n end if\n end if\n call utl_err( istat,'fun_gammq','Failed' )\n end\n", "meta": {"hexsha": "3d93319bf9e4b6e5c6d30820ffd0df4eb9e2a145", "size": 1672, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "image_lib/fun_gammq.f", "max_stars_repo_name": "CavendishAstrophysics/anmap", "max_stars_repo_head_hexsha": "efb611d7f80a3d14dc55e46cd01e8a622f6fd294", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-09-01T12:40:45.000Z", "max_stars_repo_stars_event_max_datetime": "2015-09-01T12:40:45.000Z", "max_issues_repo_path": "image_lib/fun_gammq.f", "max_issues_repo_name": "CavendishAstrophysics/anmap", "max_issues_repo_head_hexsha": "efb611d7f80a3d14dc55e46cd01e8a622f6fd294", "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": "image_lib/fun_gammq.f", "max_forks_repo_name": "CavendishAstrophysics/anmap", "max_forks_repo_head_hexsha": "efb611d7f80a3d14dc55e46cd01e8a622f6fd294", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.4098360656, "max_line_length": 73, "alphanum_fraction": 0.5604066986, "num_tokens": 470, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9099070158103778, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6679805026768909}} {"text": "C Copyright(C) 1999-2020 National Technology & Engineering Solutions\nC of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with\nC NTESS, the U.S. Government retains certain rights in this software.\nC\nC See packages/seacas/LICENSE for details\n\nC=======================================================================\n SUBROUTINE PXN2 (RETMIN, PARTYP, LENARY, NELBLK, IXELB, ISEVOK,\n & NUMIX, IXNODE, IXELEM, SIG11, SIG22, SIG12, RESULT)\nC=======================================================================\n\nC --*** PXN2 *** (ALGEBRA) Calculate 2x2 principal values\nC -- Written by Amy Gilkey - revised 05/17/88\nC --\nC --PXN2 determines minimum or maximum principal values for a 2 by 2\nC --array.\nC --\nC --Parameters:\nC -- RETMIN - IN - true iff minimum versus maximum to be calculated\nC -- PARTYP - IN - the parameter type (element must be handled differently)\nC -- LENARY - IN - the length of the parameter arrays\nC -- NELBLK - IN - the number of element blocks\nC -- IXELB - IN - the cumulative element counts for each element block\nC -- ISEVOK - IN - the element variable truth table for each element block\nC -- NUMIX - IN - the number of selected values; <0 if all\nC -- IXNODE - IN - the indices of the selected nodes (only if NUMIX >= 0)\nC -- IXELEM - IN - the indices of the selected elements (only if NUMIX >= 0)\nC -- SIG11, SIG22, SIG12 - IN - the tensor components\nC -- RESULT - OUT - the returned principal values\n\n LOGICAL RETMIN\n CHARACTER PARTYP\n INTEGER IXELB(0:NELBLK)\n LOGICAL ISEVOK(*)\n INTEGER IXNODE(*)\n INTEGER IXELEM(*)\n REAL SIG11(*), SIG22(*), SIG12(*)\n REAL RESULT(*)\n\n IF (NUMIX .GE. 0) THEN\n IF (PARTYP .NE. 'E') THEN\n DO 100 I = 1, NUMIX\n J = IXNODE(I)\n SROOT = SQRT\n & ((0.5 * (SIG11(J)-SIG22(J)))**2 + SIG12(J)**2)\n\n IF (RETMIN) THEN\n RESULT(J) = 0.5 * (SIG11(J)+SIG22(J)) - SROOT\n ELSE\n RESULT(J) = 0.5 * (SIG11(J)+SIG22(J)) + SROOT\n END IF\n 100 CONTINUE\n ELSE\n DO 120 IELB = 1, NELBLK\n IF (ISEVOK(IELB)) THEN\n DO 110 I = IXELB(IELB-1)+1, IXELB(IELB)\n J = IXELEM(I)\n SROOT = SQRT\n & ((0.5 * (SIG11(J)-SIG22(J)))**2 + SIG12(J)**2)\n\n IF (RETMIN) THEN\n RESULT(J) = 0.5 * (SIG11(J)+SIG22(J)) - SROOT\n ELSE\n RESULT(J) = 0.5 * (SIG11(J)+SIG22(J)) + SROOT\n END IF\n 110 CONTINUE\n END IF\n 120 CONTINUE\n END IF\n\n ELSE\nC NUMIX < 0; ALL VALUES SELECTED\nC NUMEL=NUMELO; NUMNP=NUMNPO; IXELB(J)=IXELBO(J), J=1,NELBLK\n IF (PARTYP .NE. 'E') THEN\n DO 130 J = 1, LENARY\n SROOT = SQRT\n & ((0.5 * (SIG11(J)-SIG22(J)))**2 + SIG12(J)**2)\n\n IF (RETMIN) THEN\n RESULT(J) = 0.5 * (SIG11(J)+SIG22(J)) - SROOT\n ELSE\n RESULT(J) = 0.5 * (SIG11(J)+SIG22(J)) + SROOT\n END IF\n 130 CONTINUE\n\n ELSE\n DO 150 IELB = 1, NELBLK\n IF (ISEVOK(IELB)) THEN\n DO 140 J = IXELB(IELB-1)+1, IXELB(IELB)\n SROOT = SQRT\n & ((0.5 * (SIG11(J)-SIG22(J)))**2 + SIG12(J)**2)\n\n IF (RETMIN) THEN\n RESULT(J) = 0.5 * (SIG11(J)+SIG22(J)) - SROOT\n ELSE\n RESULT(J) = 0.5 * (SIG11(J)+SIG22(J)) + SROOT\n END IF\n 140 CONTINUE\n END IF\n 150 CONTINUE\n END IF\n END IF\n\n RETURN\n END\n", "meta": {"hexsha": "cb3d5f2e7322a716afd9979c42fce012f57159f7", "size": 3902, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "packages/seacas/applications/algebra/ag_pxn2.f", "max_stars_repo_name": "jschueller/seacas", "max_stars_repo_head_hexsha": "14c34ae08b757cba43a3a03ec0f129c8a168a9d3", "max_stars_repo_licenses": ["Python-2.0", "Zlib", "BSD-2-Clause", "MIT", "NetCDF", "BSL-1.0", "X11", "BSD-3-Clause"], "max_stars_count": 82, "max_stars_repo_stars_event_min_datetime": "2016-02-04T18:38:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T03:01:49.000Z", "max_issues_repo_path": "packages/seacas/applications/algebra/ag_pxn2.f", "max_issues_repo_name": "jschueller/seacas", "max_issues_repo_head_hexsha": "14c34ae08b757cba43a3a03ec0f129c8a168a9d3", "max_issues_repo_licenses": ["Python-2.0", "Zlib", "BSD-2-Clause", "MIT", "NetCDF", "BSL-1.0", "X11", "BSD-3-Clause"], "max_issues_count": 206, "max_issues_repo_issues_event_min_datetime": "2015-11-20T01:57:47.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:12:04.000Z", "max_forks_repo_path": "packages/seacas/applications/algebra/ag_pxn2.f", "max_forks_repo_name": "jschueller/seacas", "max_forks_repo_head_hexsha": "14c34ae08b757cba43a3a03ec0f129c8a168a9d3", "max_forks_repo_licenses": ["Python-2.0", "Zlib", "BSD-2-Clause", "MIT", "NetCDF", "BSL-1.0", "X11", "BSD-3-Clause"], "max_forks_count": 68, "max_forks_repo_forks_event_min_datetime": "2016-01-13T22:46:51.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T06:25:05.000Z", "avg_line_length": 36.8113207547, "max_line_length": 80, "alphanum_fraction": 0.4733470015, "num_tokens": 1169, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148513, "lm_q2_score": 0.7310585903489891, "lm_q1q2_score": 0.6679510746786017}} {"text": "\n subroutine equ_to_altaz_r(dec,ha,phi,alt,az)\n\n IMPLICIT REAL*8(A-Z)\n\n sindec = DSIN(dec)\n cosdec = DCOS(dec)\n sinphi = DSIN(phi)\n cosphi = DCOS(phi)\n cosha = DCOS(ha)\n\n alt=ASIN (sinphi*sindec+cosphi*cosdec*cosha)\n az =ACOS((cosphi*sindec-sinphi*cosdec*cosha)/dcos(alt))\n\n if(ha .gt. 0 .and. ha .lt. 3.1415926535897932d0)then ! 0 to +180\n az = 6.2831853071796D0 - az\n endif\n\n if(ha .lt. -3.1415926535897932d0)then ! -360 to -180\n az = 6.2831853071796D0 - az\n endif\n\n return\n end\n\n subroutine angcoord_2d(c_conv,ni,nj,arg1,arg2,lat1,lon1,phi\n 1 ,lat2,lon2)\n\n! General purpose angular coordinate transformations in 2D\n! This version works with single precision arguments in degrees\n\n include 'trigd.inc'\n\n parameter (pi = 3.1415926535897932E0)\n parameter (rpd = pi/180.)\n\n ANGDIF(X,Y)=MOD(X-Y+9.4247779607694E0,6.2831853071796E0)\n 1 -3.1415926535897932E0\n\n ATAN3DF(x,y) = MOD((ATAN2(x,y)/rpd+360E0),360E0)\n\n character*20 c_conv\n\n real lat1(ni,nj),lon1(ni,nj),lat2(ni,nj),lon2(ni,nj) ! degrees\n real lat2s,lon2arg,lst,lstmra,ll0,l0\n\n write(6,*)' subroutine angcoord_2d ',c_conv\n\n if(trim(c_conv) .eq. 'altaz2decra')then\n lst = arg1\n\n do i = 1,ni\n do j = 1,nj\n z = 90. - lat1(i,j)\n azi = lon1(i,j) - 180. ! Counted from meridian\n\n sindec = cosd(z)*sind(phi)-sind(z)*cosd(phi)*cosd(azi)\n sindec = max(min(sindec,1.0),-1.0)\n\n cosha = (cosd(z)*cosd(phi)+sind(z)*sind(phi)*cosd(azi))\n 1 /cosd(dec)\n cosdec = sqrt(1.-sindec**2)\n sinha = (sind(azi)*sind(z)) / cosdec\n dec = asind(sindec)\n ha = atan3df(sinha,cosha)\n ra = lst - ha\n \n lat2(i,j) = dec\n lon2(i,j) = ra\n enddo ! j\n enddo ! i\n\n elseif(trim(c_conv) .eq. 'decra2galactic')then\n ra0 = 282.86 ! ra of ascending node of galactic equator \n l0 = 32.93 ! galactic longitude of ascending node\n decngp = 27.13\n\n do i = 1,ni\n do j = 1,nj\n dec = lat1(i,j)\n ra = lon1(i,j)\n\n sinb = sind(dec)*sind(decngp) \n 1 - cosd(dec)*cosd(decngp)*sind(ra-ra0)\n sinb = max(min(sinb,1.0),-1.0)\n\n cosb = sqrt(1.-sinb**2)\n cosll0 = cosd(ra-ra0)*cosd(dec)/cosb\n sinll0 = (sind(dec)*cosd(decngp)\n 1 + cosd(dec)*sind(decngp)*sind(ra-ra0)) / cosb\n ll0 = atan3df(sinll0,cosll0)\n\n lat2(i,j) = asind(sinb)\n lon2(i,j) = ll0 + l0\n enddo ! j\n enddo ! i\n \n elseif(trim(c_conv) .eq. 'decra2helioecliptic')then\n obl = 23.446\n sollam = arg1\n do i = 1,ni\n do j = 1,nj\n dec = lat1(i,j)\n ra = lon1(i,j)\n sinb = sind(dec)*cosd(obl)-cosd(dec)*sind(obl)*sind(ra)\n sinb = max(min(sinb,1.0),-1.0)\n cosb = sqrt(1.-sinb**2)\n coslam = cosd(ra)*cosd(dec)/cosb\n sinlam = (sind(dec)*sind(obl)+cosd(dec)*cosd(obl)*sind(ra))\n 1 /cosb\n lat2(i,j) = asind(sinb)\n lon2(i,j) = atan3df(sinlam,coslam) - sollam\n enddo ! j\n enddo ! i\n endif\n\n where(lon2 .lt. 0.)\n lon2 = lon2 + 360.\n end where\n\n where(lon2 .gt. 360.)\n lon2 = lon2 - 360.\n end where\n\n return\n end\n", "meta": {"hexsha": "b02d6cb9c6c4f80168922d84b38b80f8bfe2fd34", "size": 3744, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/lib/cloud/equtoaltazr.f", "max_stars_repo_name": "maxinye/laps-mirror", "max_stars_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_stars_repo_licenses": ["Intel", "Unlicense", "OLDAP-2.2.1", "NetCDF"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-04-05T12:28:22.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-29T06:37:29.000Z", "max_issues_repo_path": "src/lib/cloud/equtoaltazr.f", "max_issues_repo_name": "longwosion/laps-mirror", "max_issues_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_issues_repo_licenses": ["Intel", "NetCDF", "OLDAP-2.2.1", "Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/lib/cloud/equtoaltazr.f", "max_forks_repo_name": "longwosion/laps-mirror", "max_forks_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_forks_repo_licenses": ["Intel", "NetCDF", "OLDAP-2.2.1", "Unlicense"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-04-27T12:51:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-19T13:57:44.000Z", "avg_line_length": 29.4803149606, "max_line_length": 75, "alphanum_fraction": 0.484508547, "num_tokens": 1257, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765187126079, "lm_q2_score": 0.7310585903489891, "lm_q1q2_score": 0.6679510678050109}} {"text": "module setup_amr_mod\n\nuse constants_mod\n\nreal(dp), save :: fv8fv3Mat(3,8)\nreal(dp), save :: fv8fv3Tam(8,3)\n\ncontains\n\nsubroutine hook_pre_timestep_300\n\n use share_mod, only: mesh\n\n use mesh_utils_mod, only: mesh_adapt\n use mesh_utils_mod, only: mesh_partition\n\n call mesh_adapt(mesh,setup_amr_probe_refine,setup_amr_replace_refine,setup_amr_probe_coarsen,setup_amr_replace_coarsen)\n call mesh_partition(mesh)\n\nend subroutine\n\nsubroutine hook_init_223\n\n use interpol_mod, only: LegendreGaussNodesAndWeights\n use subcellfv_mod, only: subcellfv_vanderMondeMatrix\n use linalg_mod, only: invert\n use utils_mod, only: pp\n\n real(dp) :: dgnodes(8), dgweights(8)\n\n real(dp) :: dg2fvMat8(8,8)\n real(dp) :: fv2dgMat8(8,8)\n\n call LegendreGaussNodesAndWeights(7,dgnodes,dgweights)\n call subcellfv_vanderMondeMatrix(8,8,dgnodes,dgweights,dg2fvMat8)\n fv2dgMat8 = invert(dg2fvMat8,8)\n\n call subcellfv_vanderMondeMatrix(8,3,dgnodes,dgweights,fv8fv3Mat)\n\n fv8fv3Mat = matmul(fv8fv3Mat,fv2dgMat8)\n fv8fv3Tam = transpose(fv8fv3Mat)\n\n ! call pp('fv8fv3Mat', fv8fv3Mat)\n ! call pp('fv8fv3Tam', fv8fv3Tam)\n\nend subroutine\n\n!! pure function calc_loehner(u)\n!! \n!! real(dp), intent(in) :: u(N_NODES,N_NODES)\n!! real(dp) :: calc_loehner\n!! \n!! real(dp), parameter :: eps = 0.25_dp\n!! \n!! integer :: i,j\n!! \n!! real(dp) :: xtemp(2:N_NODES-1,1:N_NODES)\n!! real(dp) :: ytemp(1:N_NODES,2:N_NODES-1)\n!! \n!! forall (j = 1:N_NODES, i = 2:N_NODES-1)\n!! xtemp(i,j) = abs(u(i-1,j) - 2.0_dp*u(i,j) + u(i+1,j)) / &\n!! (abs(u(i+1,j)-u(i,j)) + abs(u(i,j)-u(i-1,j)) + &\n!! eps*(abs(u(i+1,j)) + 2.0_dp*abs(u(i,j)) + abs(u(i-1,j))))\n!! end forall\n!! \n!! forall (j = 2:N_NODES-1, i = 1:N_NODES)\n!! ytemp(i,j) = abs(u(i,j-1) - 2.0_dp*u(i,j) + u(i,j+1)) / &\n!! (abs(u(i,j+1)-u(i,j)) + abs(u(i,j)-u(i,j-1)) + &\n!! eps*(abs(u(i,j+1)) + 2.0_dp*abs(u(i,j)) + abs(u(i,j-1))))\n!! end forall\n!! \n!! calc_loehner = max(maxval(xtemp),maxval(ytemp))\n!! \n!! end function\n\npure function calc_loehner(u)\n\n real(dp), intent(in) :: u(N_NODES,N_NODES)\n real(dp) :: calc_loehner\n\n real(dp), parameter :: eps = 0.2_dp\n\n real(dp) :: stencil(-1:1,-1:1)\n real(dp) :: xtemp(-1:1)\n real(dp) :: ytemp(-1:1)\n\n integer :: i,j\n\n stencil = matmul(fv8fv3Mat,matmul(u,fv8fv3Tam))\n\n forall (j = -1:1)\n xtemp(j) = abs(stencil(-1,j) - 2.0_dp*stencil(0,j) + stencil(1,j)) / &\n (abs(stencil(1,j)-stencil(0,j)) + abs(stencil(0,j)-stencil(-1,j)) + &\n eps*(abs(stencil(1,j)) + 2.0_dp*abs(stencil(0,j)) + abs(stencil(-1,j))))\n end forall\n\n forall (i = -1:1)\n ytemp(i) = abs(stencil(i,-1) - 2.0_dp*stencil(i,0) + stencil(i,1)) / &\n (abs(stencil(i,1)-stencil(i,0)) + abs(stencil(i,0)-stencil(i,-1)) + &\n eps*(abs(stencil(i,1)) + 2.0_dp*abs(stencil(i,0)) + abs(stencil(i,-1))))\n end forall\n\n ! calc_loehner = max(maxval(xtemp),maxval(ytemp))\n calc_loehner = max(sum(xtemp)/3,sum(ytemp)/3)\n\nend function\n\n\nfunction setup_amr_probe_refine(quad) result(ok)\n\n use setup_config_mod\n use equations_const_mod\n use mesh_types_mod, only: quad_t\n use kernel_const_mod, only: DGFV_QMAX\n\n type(quad_t), intent(in) :: quad\n logical :: ok\n\n real(dp) :: loehner\n\n real(dp), parameter :: reftol = 0.3_dp\n\n# if PP_KERNEL_DGFV\n if (quad%aux%hydro%subcell) then\n ok = .true.\n return\n end if\n# endif\n\n loehner = calc_loehner(quad%pld%hydro%state(:,:,DENS_VAR))\n\n ok = loehner > reftol\n\nend function\n\nfunction setup_amr_probe_coarsen(family) result(ok)\n\n use setup_config_mod\n use equations_const_mod\n use mesh_types_mod, only: quad_t\n use mesh_const_mod, only: MESH_CHILDREN\n use mesh_const_mod, only: MESH_CORNERS\n\n use kernel_const_mod, only: DGFV_QMAX\n use kernel_share_mod, only: coarseMat\n use kernel_share_mod, only: coarseTam\n use share_mod, only: rt => runtime\n use quad_utils_mod, only: quad_get_vertices\n\n type(quad_t), intent(in) :: family(MESH_CHILDREN)\n logical :: ok\n\n real(dp) :: loehner\n real(dp), parameter :: cortol = 0.1_dp\n\n real(dp) :: verts(N_DIMS,MESH_CORNERS)\n real(dp) :: coarsened(N_NODES,N_NODES)\n\n integer :: q,h,f\n\n ! ok = .false.\n ! return\n\n ! do f = 1,MESH_CHILDREN\n ! if (family(f)%aux%hydro%subcell) then\n ! ok = .false.\n ! return\n ! end if\n ! end do\n\n if (rt%simtime < 0.0025_dp) then\n do f = 1,MESH_CHILDREN\n verts = quad_get_vertices(family(f))\n if (any(abs(SQRT(SUM((verts)**2,dim=1))) < init_amr_min_diameter)) then\n ok = .false.\n return\n end if\n end do\n end if\n\n coarsened = 0.0_dp\n do q = DGFV_QMAX,0,-1\n do f = 1,MESH_CHILDREN\n coarsened = coarsened + &\n matmul(coarseMat(:,:,X_DIR,f,q),matmul(family(f)%pld%hydro%state(:,:,DENS_VAR),coarseTam(:,:,Y_DIR,f,q)))\n end do\n end do\n\n loehner = calc_loehner(coarsened)\n\n ok = loehner < cortol\n\nend function\n\nsubroutine setup_amr_replace_refine(incoming,outgoing)\n\n use mesh_types_mod, only: quad_t\n use mesh_const_mod, only: MESH_CHILDREN\n\n use kernel_share_mod, only: refineMat\n use kernel_share_mod, only: refineTam\n\n use kernel_const_mod, only: DGFV_QMAX\n use equations_mod, only: isvalid\n\n type(quad_t), intent(in) :: incoming\n type(quad_t), intent(inout) :: outgoing(MESH_CHILDREN)\n\n integer :: q,h,f\n logical :: ok\n\n !do q = DGFV_QMAX,0,-1\n do q = 0,0,-1\n do f = 1,MESH_CHILDREN\n do h = 1,N_VARS\n outgoing(f)%pld%hydro%state(:,:,h) = &\n matmul(refineMat(:,:,X_DIR,f,q),matmul(incoming%pld%hydro%state(:,:,h),refineTam(:,:,Y_DIR,f,q)))\n end do\n ok = isvalid(outgoing(f)%pld%hydro%state)\n if (.not.ok) exit\n end do\n if (ok) exit\n end do\n\nend subroutine\n\nsubroutine setup_amr_replace_coarsen(incoming,outgoing)\n\n use mesh_types_mod, only: quad_t\n use mesh_const_mod, only: MESH_CHILDREN\n\n use kernel_const_mod, only: DGFV_QMAX\n use equations_mod, only: isvalid\n\n use kernel_share_mod, only: coarseMat\n use kernel_share_mod, only: coarseTam\n\n type(quad_t), intent(in) :: incoming(MESH_CHILDREN)\n type(quad_t), intent(inout) :: outgoing\n\n integer :: q,h,f\n\n outgoing%pld%hydro%state = 0.0_dp\n !do q = DGFV_QMAX,0,-1\n do q = 0,0,-1\n do f = 1,MESH_CHILDREN\n do h = 1,N_VARS\n outgoing%pld%hydro%state(:,:,h) = outgoing%pld%hydro%state(:,:,h) + &\n matmul(coarseMat(:,:,X_DIR,f,q),matmul(incoming(f)%pld%hydro%state(:,:,h),coarseTam(:,:,Y_DIR,f,q)))\n end do\n end do\n if (isvalid(outgoing%pld%hydro%state)) exit\n end do\n\nend subroutine\n\nend module\n", "meta": {"hexsha": "5021e2041442de572cd0c05e4fb4141866a37e16", "size": 7031, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/setups/euler/2d/blast/setup_amr_mod.f90", "max_stars_repo_name": "jmark/nemo", "max_stars_repo_head_hexsha": "cf8a6a8bed5c54626f5e300c701b9c278fd5e0cd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source/setups/euler/2d/blast/setup_amr_mod.f90", "max_issues_repo_name": "jmark/nemo", "max_issues_repo_head_hexsha": "cf8a6a8bed5c54626f5e300c701b9c278fd5e0cd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/setups/euler/2d/blast/setup_amr_mod.f90", "max_forks_repo_name": "jmark/nemo", "max_forks_repo_head_hexsha": "cf8a6a8bed5c54626f5e300c701b9c278fd5e0cd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.2519379845, "max_line_length": 123, "alphanum_fraction": 0.6007680273, "num_tokens": 2334, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765328159727, "lm_q2_score": 0.7310585669110203, "lm_q1q2_score": 0.6679510567006749}} {"text": "!> \\brief module containing simulation parameters and constants \n!> \\author M.Theiss \nmodule basic_parameters_mod\nuse working_prec_mod , only: rk, ik \n implicit none\n\n \n real(rk), parameter :: PI = 3.14159265359_rk\n real(rk), parameter :: ec = 1.60217733d-19 ! elementary charge in C (SI-units)\n real(rk), parameter :: eps0 = 8.854187817d-12 ! Permittivit\u00e4t des Vakuums in SI: As/(Vm) & As=C\n real(rk), parameter :: kB = 1.380658d-23 ! in J/K\n real(rk) :: CoulCombo \n! CoulCombo = ec * ec * 1.0e10_rk / ( 4.0_rk * PI * eps0 * kB ) ->Umrechnung auf CGS-units (in K)\n \n integer(ik), parameter :: intervalls = 256_ik ! number of intervalls for mean radial distribution function\n \n integer(ik), parameter :: Kmax = 9_ik ! Kmax is an Ewald sum parameter.\n real(rk), parameter :: Alpha = 5.6_rk ! Alpha is an Ewald sum parameter, Alpha = kappa * L, for kappa in A + T. \n\n\nend module basic_parameters_mod \n", "meta": {"hexsha": "1c5e0e6dbe457f97adee80cd111afb05bdf55aa5", "size": 986, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/basic_parameters.f90", "max_stars_repo_name": "runnermt/MC-programm-for-fluid-mixtures-of-dipolar-and-charged-hard-spheres", "max_stars_repo_head_hexsha": "3dd7d1518afb0e45caf7bb729d817b1ad2697852", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-06-15T08:24:36.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-29T22:29:48.000Z", "max_issues_repo_path": "src/basic_parameters.f90", "max_issues_repo_name": "maTheiss/MC-programm-for-fluid-mixtures-of-dipolar-and-charged-hard-spheres", "max_issues_repo_head_hexsha": "3dd7d1518afb0e45caf7bb729d817b1ad2697852", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/basic_parameters.f90", "max_forks_repo_name": "maTheiss/MC-programm-for-fluid-mixtures-of-dipolar-and-charged-hard-spheres", "max_forks_repo_head_hexsha": "3dd7d1518afb0e45caf7bb729d817b1ad2697852", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.8181818182, "max_line_length": 122, "alphanum_fraction": 0.6359026369, "num_tokens": 315, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.913676530465412, "lm_q2_score": 0.7310585669110202, "lm_q1q2_score": 0.6679510549822771}} {"text": "* \n* Definition:\n* ===========\n*\n* SUBROUTINE SGEMLQ( SIDE, TRANS, M, N, K, A, LDA, WORK1, \n* $ LWORK1, C, LDC, WORK2, LWORK2, INFO )\n*\n*\n* .. Scalar Arguments ..\n* CHARACTER SIDE, TRANS\n* INTEGER INFO, LDA, M, N, K, MB, NB, LWORK1, LWORK2, LDC\n* ..\n* .. Array Arguments ..\n* REAL A( LDA, * ), WORK1( * ), C(LDC, * ),\n* $ WORK2( * )\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*> \n*> DGEMLQ overwrites the general real M-by-N matrix C with\n*>\n*> \n*> SIDE = 'L' SIDE = 'R'\n*> TRANS = 'N': Q * C C * Q\n*> TRANS = 'T': Q**T * C C * Q**T\n*> where Q is a real orthogonal matrix defined as the product \n*> of blocked elementary reflectors computed by short wide LQ \n*> factorization (DGELQ)\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in] SIDE\n*> SIDE is CHARACTER*1\n*> = 'L': apply Q or Q**T from the Left;\n*> = 'R': apply Q or Q**T from the Right.\n*>\n*> \\param[in] TRANS\n*> TRANS is CHARACTER*1\n*> = 'N': No transpose, apply Q;\n*> = 'T': Transpose, apply Q**T.\n*> \\param[in] M\n*> \\verbatim\n*> M is INTEGER\n*> The number of rows of the matrix A. M >=0.\n*> \\endverbatim\n*>\n*> \\param[in] N\n*> \\verbatim\n*> N is INTEGER\n*> The number of columns of the matrix C. N >= M.\n*> \\endverbatim\n*>\n*> \\param[in] K\n*> \\verbatim\n*> K is INTEGER\n*> The number of elementary reflectors whose product defines\n*> the matrix Q.\n*> M >= K >= 0;\n*> \n*> \\endverbatim\n*>\n*> \\param[in,out] A\n*> \\verbatim\n*> A is REAL array, dimension (LDA,K)\n*> The i-th row must contain the vector which defines the blocked\n*> elementary reflector H(i), for i = 1,2,...,k, as returned by\n*> DLASWLQ in the first k rows of its array argument A.\n*> \\endverbatim\n*>\n*> \\param[in] LDA\n*> \\verbatim\n*> LDA is INTEGER\n*> The leading dimension of the array A.\n*> If SIDE = 'L', LDA >= max(1,M);\n*> if SIDE = 'R', LDA >= max(1,N).\n*> \\endverbatim\n*>\n*> \\param[in] WORK1\n*> \\verbatim\n*> WORK1 is REAL array, dimension (MAX(1,LWORK1)) is\n*> returned by GEQR.\n*> \\endverbatim\n*>\n*> \\param[in] LWORK1\n*> \\verbatim\n*> LWORK1 is INTEGER\n*> The dimension of the array WORK1.\n*> \\endverbatim\n*>\n*> \\param[in,out] C\n*> C is REAL array, dimension (LDC,N)\n*> On entry, the M-by-N matrix C.\n*> On exit, C is overwritten by Q*C or Q**T*C or C*Q**T or C*Q.\n*> \\param[in] LDC\n*> LDC is INTEGER\n*> The leading dimension of the array C. LDC >= max(1,M).\n*>\n*> \\param[out] WORK2\n*> \\verbatim\n*> (workspace) REAL array, dimension (MAX(1,LWORK2))\n*> \n*> \\endverbatim\n*> \\param[in] LWORK2\n*> \\verbatim\n*> LWORK2 is INTEGER\n*> The dimension of the array WORK2. \n*> If LWORK2 = -1, then a workspace query is assumed; the routine\n*> only calculates the optimal size of the WORK2 array, returns\n*> this value as the third entry of the WORK2 array (WORK2(1)), \n*> and no error message related to LWORK2 is issued by XERBLA.\n*>\n*> \\endverbatim\n*> \\param[out] INFO\n*> \\verbatim\n*> INFO is INTEGER\n*> = 0: successful exit\n*> < 0: if INFO = -i, the i-th argument had an illegal value\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee\n*> \\author Univ. of California Berkeley\n*> \\author Univ. of Colorado Denver\n*> \\author NAG Ltd.\n*\n*> \\par Further Details:\n* =====================\n*>\n*> \\verbatim\n*> Depending on the matrix dimensions M and N, and row and column\n*> block sizes MB and NB returned by ILAENV, GELQ will use either\n*> LASWLQ(if the matrix is short-and-wide) or GELQT to compute\n*> the LQ decomposition. \n*> The output of LASWLQ or GELQT representing Q is stored in A and in\n*> array WORK1(6:LWORK1) for later use. \n*> WORK1(2:5) contains the matrix dimensions M,N and block sizes MB, NB \n*> which are needed to interpret A and WORK1(6:LWORK1) for later use. \n*> WORK1(1)=1 indicates that the code needed to take WORK1(2:5) and \n*> decide whether LASWLQ or GELQT was used is the same as used below in\n*> GELQ. For a detailed description of A and WORK1(6:LWORK1), see \n*> Further Details in LASWLQ or GELQT.\n*> \\endverbatim\n*>\n* =====================================================================\n SUBROUTINE SGEMLQ( SIDE, TRANS, M, N, K, A, LDA, WORK1, LWORK1, \n $ C, LDC, WORK2, LWORK2, INFO )\n*\n* -- LAPACK computational routine (version 3.5.0) --\n* -- LAPACK is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n* November 2013\n*\n* .. Scalar Arguments ..\n CHARACTER SIDE, TRANS\n INTEGER INFO, LDA, M, N, K, LWORK1, LWORK2, LDC\n* ..\n* .. Array Arguments ..\n REAL A( LDA, * ), C( LDC, * ), WORK1( * ), WORK2( * )\n* ..\n*\n* =====================================================================\n*\n* ..\n* .. Local Scalars ..\n LOGICAL LEFT, RIGHT, TRAN, NOTRAN, LQUERY\n INTEGER I, II, KK, MB, NB, LW, NBLCKS, MN\n* ..\n* .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\n* .. External Subroutines ..\n EXTERNAL STPMLQT, SGEMLQT, XERBLA\n* .. Intrinsic Functions ..\n INTRINSIC INT, MAX, MIN, MOD\n* ..\n* .. Executable Statements ..\n*\n* Test the input arguments\n*\n LQUERY = LWORK2.LT.0\n NOTRAN = LSAME( TRANS, 'N' )\n TRAN = LSAME( TRANS, 'T' )\n LEFT = LSAME( SIDE, 'L' )\n RIGHT = LSAME( SIDE, 'R' )\n*\n MB = INT(WORK1(4))\n NB = INT(WORK1(5))\n IF (LEFT) THEN\n LW = N * MB\n MN = M\n ELSE\n LW = M * MB\n MN = N\n END IF\n IF ((NB.GT.K).AND.(MN.GT.K)) THEN\n IF(MOD(MN-K, NB-K).EQ.0) THEN\n NBLCKS = (MN-K)/(NB-K)\n ELSE\n NBLCKS = (MN-K)/(NB-K) + 1\n END IF\n ELSE\n NBLCKS = 1\n END IF\n*\n INFO = 0\n IF( .NOT.LEFT .AND. .NOT.RIGHT ) THEN\n INFO = -1\n ELSE IF( .NOT.TRAN .AND. .NOT.NOTRAN ) THEN\n INFO = -2\n ELSE IF( M.LT.0 ) THEN\n INFO = -3\n ELSE IF( N.LT.0) THEN\n INFO = -4\n ELSE IF( K.LT.0 ) THEN\n INFO = -5\n ELSE IF( LDA.LT.MAX( 1, K ) ) THEN\n INFO = -7\n ELSE IF( LWORK1.LT.MAX( 1, MB*K*NBLCKS+5 )) THEN\n INFO = -9\n ELSE IF( LDC.LT.MAX( 1, M ) ) THEN\n INFO = -11\n ELSE IF(( LWORK2.LT.MAX(1,LW)).AND.(.NOT.LQUERY)) THEN\n INFO = -13\n END IF\n*\n IF( INFO.EQ.0) THEN\n WORK2(1) = LW\n END IF\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'SGEMLQ', -INFO )\n RETURN\n ELSE IF (LQUERY) THEN\n RETURN\n END IF\n*\n* Quick return if possible\n*\n IF( MIN(M,N,K).EQ.0 ) THEN\n RETURN\n END IF \n*\n IF((LEFT.AND.M.LE.K).OR.(RIGHT.AND.N.LE.K).OR.(NB.LE.K).OR.\n $ (NB.GE.MAX(M,N,K))) THEN\n CALL SGEMLQT( SIDE, TRANS, M, N, K, MB, A, LDA, \n $ WORK1(6), MB, C, LDC, WORK2, INFO) \n ELSE\n CALL SLAMSWLQ( SIDE, TRANS, M, N, K, MB, NB, A, LDA, WORK1(6),\n $ MB, C, LDC, WORK2, LWORK2, INFO )\n END IF\n*\n WORK2(1) = LW\n RETURN\n*\n* End of SGEMLQ\n*\n END", "meta": {"hexsha": "37a9fb9b4aeab3cddecf5afd6da3ece5b2bc8970", "size": 7556, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "SRC/sgemlq.f", "max_stars_repo_name": "sydha/Lapack", "max_stars_repo_head_hexsha": "1290e6b39b73b2431976e0a9b7fb7d78aeab3ba7", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "SRC/sgemlq.f", "max_issues_repo_name": "sydha/Lapack", "max_issues_repo_head_hexsha": "1290e6b39b73b2431976e0a9b7fb7d78aeab3ba7", "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": "SRC/sgemlq.f", "max_forks_repo_name": "sydha/Lapack", "max_forks_repo_head_hexsha": "1290e6b39b73b2431976e0a9b7fb7d78aeab3ba7", "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": 28.9501915709, "max_line_length": 76, "alphanum_fraction": 0.5082053997, "num_tokens": 2384, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765210631688, "lm_q2_score": 0.7310585727705127, "lm_q1q2_score": 0.6679510534623674}} {"text": "PROGRAM PIB1D_Hydrogen_Radial\n IMPLICIT NONE\n\n REAL, PARAMETER :: PI = acos(-1.0)\n REAL, ALLOCATABLE:: potential(:), x(:)\n DOUBLE PRECISION, ALLOCATABLE:: hmat(:,:), eigenVal(:), work(:)\n DOUBLE PRECISION:: WF\n REAL:: xmax, xmin, dx, hbar, tconst, m, l\n INTEGER:: nx, lwork, i, ifail\n\n WRITE(*, fmt = '(/A)', ADVANCE = 'NO') \"Enter the number of grid points: \"\n READ(*, *) nx\n \n xmax = 10.0\n xmin = 0.0\n dx = (xmax - xmin)/(nx)\n \n ALLOCATE(potential(nx), hmat(nx,nx), eigenVal(nx), x(nx), work(64*nx))\n DO i = 1, nx\n x(i) = xmin + (i)*dx\n ENDDO\n\n m = 1.0\n hbar = 1.00\n l = 0\n tconst = (hbar**2) / (2.0 * m * dx**2)\n\n DO i = 1, nx\n potential(i) = (hbar**2 * l * (l+1))/(2 * m * x(i) * x(i)) - 1/x(i)\n ENDDO\n \n hmat = 0.0\n DO i = 1, nx-1\n hmat(i, i) = potential(i) + 2.0 * tconst\n hmat(i, i+1) = -tconst\n hmat(i+1, i) = -tconst\n ENDDO\n hmat(nx, nx) = potential(nx) + 2.0 * tconst\n \n lwork = 64*nx\n CALL dsyev('V', 'U', nx, hmat, nx, eigenVal, work, lwork, ifail)\n\n OPEN(UNIT = 20, FILE = 'hydrogen.txt')\n DO i = 1, nx \n WF = hmat(i, 3)/sqrt(dx)\n WRITE(20, 10) x(i), potential(i), eigenVal(i), hmat(i, 1)/sqrt(dx)\n 10 FORMAT(f0.6, 3x, f0.6, 3x, f0.8, 3x, f0.8, 3x)\n ENDDO\n CLOSE(20)\n\nEND PROGRAM PIB1D_Hydrogen_Radial\n", "meta": {"hexsha": "0f9b7d1350d009562d48cd5a351c60f3aea469ff", "size": 1393, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Particle In a Box (PIB)/4_hydrogen.f90", "max_stars_repo_name": "arpitkekri/Code_With_FORTRAN", "max_stars_repo_head_hexsha": "fb731e6f8d8a47cfe38896fffd74a55d17efb2e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-02-21T05:24:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-27T10:25:24.000Z", "max_issues_repo_path": "Particle In a Box (PIB)/4_hydrogen.f90", "max_issues_repo_name": "akhil18soni/Code_With_FORTRAN", "max_issues_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Particle In a Box (PIB)/4_hydrogen.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.7884615385, "max_line_length": 78, "alphanum_fraction": 0.5053840632, "num_tokens": 571, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765187126079, "lm_q2_score": 0.7310585727705127, "lm_q1q2_score": 0.6679510517439697}} {"text": " real function getz(pval,nt,vr,cdf,zmin,zmax,ltail,ltpar, &\n utail,utpar)\n!-----------------------------------------------------------------------\n\n! Back Transform Univariate Data from Normal Scores\n! *************************************************\n\n! This subroutine backtransforms a standard normal deviate from a\n! specified back transform table and option for the tails of the\n! distribution. Call once with \"first\" set to true then set to false\n! unless one of the options for the tail changes.\n\n\n\n! INPUT VARIABLES:\n\n! pval probability value to use\n! nt number of values in the back transform tbale\n! vr(nt) original data values that were transformed\n! cdf(nt) the corresponding transformed values\n! zmin,zmax limits possibly used for linear or power model\n! ltail option to handle values less than cdf(1)\n! ltpar parameter required for option ltail\n! utail option to handle values greater than cdf(nt)\n! utpar parameter required for option utail\n\n\n\n!-----------------------------------------------------------------------\n parameter(EPSLON=1.0e-20)\n dimension vr(nt),cdf(nt)\n real :: ltpar,utpar,lambda\n integer :: ltail,utail\n\n! Value in the lower tail? 1=linear, 2=power, (3 and 4 are invalid):\n\n if(pval <= cdf(1)) then\n getz = vr(1)\n if(ltail == 1) then\n getz = powint(0.0,cdf(1),zmin,vr(1),pval,1.0)\n else if(ltail == 2) then\n cpow = 1.0 / ltpar\n getz = powint(0.0,cdf(1),zmin,vr(1),pval,cpow)\n endif\n \n ! Value in the upper tail? 1=linear, 2=power, 4=hyperbolic:\n \n else if(pval >= cdf(nt)) then\n cdfhi = cdf(nt)\n getz = vr(nt)\n if(utail == 1) then\n getz = powint(cdfhi,1.0,vr(nt),zmax,pval,1.0)\n else if(utail == 2) then\n cpow = 1.0 / utpar\n getz = powint(cdfhi,1.0,vr(nt),zmax,pval,cpow)\n else if(utail == 4) then\n lambda = (vr(nt)**utpar)*(1.0-cdf(nt))\n getz = (lambda/(1.0-pval))**(1.0/utpar)\n endif\n else\n \n ! Value within the transformation table:\n \n call locate(cdf,nt,1,nt,pval,j)\n j = max(min((nt-1),j),1)\n getz = powint(cdf(j),cdf(j+1),vr(j),vr(j+1),pval,1.0)\n endif\n if(getz < zmin) getz = zmin\n if(getz > zmax) getz = zmax\n return\n end function getz\n", "meta": {"hexsha": "51db28babce11ad0cd0c097eb6f3d3f7230c3a33", "size": 2480, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gslib/gslib/getz.f90", "max_stars_repo_name": "opengeostat/gslib_new_code", "max_stars_repo_head_hexsha": "ecd00cfcb9654ef8d0fe28c649405fb71595e42e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "gslib/gslib/getz.f90", "max_issues_repo_name": "opengeostat/gslib_new_code", "max_issues_repo_head_hexsha": "ecd00cfcb9654ef8d0fe28c649405fb71595e42e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gslib/gslib/getz.f90", "max_forks_repo_name": "opengeostat/gslib_new_code", "max_forks_repo_head_hexsha": "ecd00cfcb9654ef8d0fe28c649405fb71595e42e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-01-03T12:19:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-03T12:19:42.000Z", "avg_line_length": 34.4444444444, "max_line_length": 72, "alphanum_fraction": 0.5286290323, "num_tokens": 728, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765210631688, "lm_q2_score": 0.7310585669110202, "lm_q1q2_score": 0.6679510481086868}} {"text": "! Created by EverLookNeverSee@GitHub on 4/23/20.\n! This program integrate a function numerically\n! using simpson's rule.\n\n! Simpson's Rule:\n! https://en.wikipedia.org/wiki/Simpson's_rule\n\nprogram simpson_rule\n implicit none\n ! declaring counter and number of panels variables\n integer :: i, n = 100\n ! declaring inerval and other variables\n real :: a = 1.0, b = 4.0, sum = 0.0, h, x\n h = (b - a) / n\n sum = sum + (a ** 3 * exp(-a ** 3) + &\n b ** 3 * exp(-b ** 3) + 4.0 * (b - h) ** 3&\n * exp(-(b - h) ** 3))\n x = a + h\n do i = 2, n-2, 2\n sum = sum + 4.0 * (x ** 3 * exp(-x ** 3))\n x = x + h\n sum = sum + 2.0 * (x ** 3 * exp(-x ** 3))\n x = x + h\n end do\n sum = h / 3.0 * sum\n print *, \"The result of integration is:\", sum\nend program simpson_rule", "meta": {"hexsha": "bce4522d9dce8c62513636fc917d80dc5dac299d", "size": 831, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/other/simpson_rule.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/simpson_rule.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/simpson_rule.f90", "max_forks_repo_name": "EverLookNeverSee/FCS", "max_forks_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-06-08T12:57:46.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-08T12:57:46.000Z", "avg_line_length": 30.7777777778, "max_line_length": 55, "alphanum_fraction": 0.5138387485, "num_tokens": 302, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404077216355, "lm_q2_score": 0.7185943805178139, "lm_q1q2_score": 0.6678906540149531}} {"text": "! Estimates the refreezing of liquid water content based on Illangasekare et al., 1990\nsubroutine refreezing(volume_water_frozen, theta_1, theta_2, porosity, Vol, T_1, T_2, density, dry_density)\nuse declarations, only : rho_i, Cpi, rho_w, Cpw, rho_a, Cpa, dp, Lf\nimplicit none\nreal(dp), intent(inout) :: volume_water_frozen, & ! Variable used to compute mass conservation [m3]\n & dry_density, & ! Dry snow density [kg/m3]\n & density, & ! Bulk snow density [kg/m3]\n & porosity ! Porosity\nreal(dp), intent(in):: Vol, & ! Volume of a cell [m3]\n & theta_1, & ! Initial water content (before refreezing)\n & T_1 ! Initial temperature before refreezing [C]\nreal(dp), intent(out):: theta_2, & ! Water content after refreezing\n & T_2 ! Temperature after refreezing [C]\nreal(dp) :: ice_content, & ! Ice content of each cell [m3/m3]\n & rhoCp, & ! rho*Cp for each snow cell [J/K/m3] \n & freeze_max ! Maximum liquid water content that can refreeze, same units as water content\n\n\n\nif (theta_1 .gt. 0._dp) then\n\n rhoCp = rho_i * Cpi * (1._dp - porosity) + rho_w * Cpw * theta_1 + &\n & rho_a * Cpa * (porosity - theta_1)\n\n freeze_max = (-rhoCp*T_1)/(Lf*rho_w) ! same units as water content\n\n if (freeze_max .lt. theta_1) then ! not all liquid water content refreezes\n\n T_2 = 0._dp\n theta_2 = theta_1-freeze_max\n volume_water_frozen = volume_water_frozen + freeze_max * Vol\n ice_content = (1.0_dp-porosity) + freeze_max*rho_w/rho_i \n porosity = 1.0_dp - ice_content\n density = ice_content*rho_i + rho_w*theta_1 + rho_a * (porosity - theta_1) \n dry_density = ice_content*rho_i \n\n elseif (freeze_max .ge. theta_1) then ! all liquid water content refreezes, i.e. freeze = water_content\n theta_2 = 0.0_dp\n volume_water_frozen = volume_water_frozen + theta_1 * Vol\n T_2 = theta_1* Lf * rho_w / rhoCp + T_1\n ice_content = (1.0_dp-porosity) + theta_1*rho_w/rho_i \n porosity = 1.0_dp-ice_content\n density = ice_content*rho_i + rho_a * porosity\n dry_density = ice_content*rho_i\n\n endif\nelse \n T_2 = T_1\n theta_2 = theta_1\nendif\n \n\nend subroutine\n", "meta": {"hexsha": "021790520be2b12ef29694e48fb35138734384ea", "size": 2378, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/refreezing.f90", "max_stars_repo_name": "nleroux3/SMPP", "max_stars_repo_head_hexsha": "f9cefac40e94a50df75a3efa8dc113802882b1f8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-04-13T15:02:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-13T15:02:25.000Z", "max_issues_repo_path": "src/refreezing.f90", "max_issues_repo_name": "nleroux3/SMPP", "max_issues_repo_head_hexsha": "f9cefac40e94a50df75a3efa8dc113802882b1f8", "max_issues_repo_licenses": ["MIT"], "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/refreezing.f90", "max_forks_repo_name": "nleroux3/SMPP", "max_forks_repo_head_hexsha": "f9cefac40e94a50df75a3efa8dc113802882b1f8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.037037037, "max_line_length": 107, "alphanum_fraction": 0.6126997477, "num_tokens": 713, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403999037784, "lm_q2_score": 0.718594386544335, "lm_q1q2_score": 0.6678906539983771}} {"text": "\tSUBROUTINE FREQFIT\nC\nC\tTHIS SUBROUTINE FINDS THE FREQUENCY OF A SINE WAVE SIGNAL, AND\nC\tMAKES A LEAST SQUARES FIT TO FREQUENCY AND AMPLITUDE\nC\nC\tFIRST IT ESTIMATES THE FREQUENCY BY DOING A FOURIER TRANSFORM\nC\tAND CHOOSING THE PEAK FREQUENCY COMPONENT.\nC\nC\tTHEN IT DOES A LEAST SQUARES FIT TO THE DATA, VARYING FREQUENCY,\nC\tAMPLITUDE, AND PHASE.\nC\n\t PRINT*,((ZCROSS(J+1)-ZCROSS(J)),J=1,IZCNT-1)\n\t WPER1 = 2.*(ZCROSS(IZCNT)-ZCROSS(1))/(IZCNT-1)\n\t PRINT*,'NEW WPER',WPER1\n\t X(1) = ZCROSS(1)\n\t X(2) = 2./WPER1\n\t DX(1) = .5\n\t DX(2) = .05*X(2)\n\t CALL HUNTMN(2,X,DX,Y,FITZERO,SUMSQ)\n\t WPER1 = 2./X(2)\n\t PHI0 = X(1) + .25*WPER1\t\n\t PRINT*,'NEW WPER,PHI0=',WPER1,PHI0\n\t NPHI0 = PHI0 + .5\nC\nC\t END OF FURTHER ZERO CROSSINGS FOR HIGH FREQUENCIES\nC\n\tENDIF\nC\nC\nC\tALLOW FOR POSSIBILITY OF NEGATIVE PEAK\nC\n \tAMPT = AMPL\n\tIF(NDATA(NPHI0).LT.0) AMPT = -AMPL\n\tDO J = 1,2048\n\t PHI = (J-PHI0)*TWOPI/WPER1\n\t VOLTS(J) = .5*AMPT*COS(PHI)\n\tENDDO\nC\tWRITE(27,1003) (J,VOLTS(J), NDATA(J),J=1,2048)\n 1003\tFORMAT(3(I9,E11.3,I5))\nC\n\tCALL CALPLOT\nC\nC\tNOW A SINE WAVE HAS BEEN FITTED THROUGH THE ZERO CROSSINGS AND\nC\tTHE KNOWN AMPLITUDE, SO VOLTAGE INPUT FOR EACH DATA POINT HAS\nC\tBEEN CALCULATED\n\n", "meta": {"hexsha": "5eb3ebf3877ad02cd85900186912fa945b11fedb", "size": 1181, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/freqfit_3.for", "max_stars_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_stars_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/freqfit_3.for", "max_issues_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_issues_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/freqfit_3.for", "max_forks_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_forks_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.1276595745, "max_line_length": 66, "alphanum_fraction": 0.6875529213, "num_tokens": 519, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403979493139, "lm_q2_score": 0.718594386544335, "lm_q1q2_score": 0.6678906525939099}} {"text": "!*************************************************\n! module mod_nnls\n!\tNNLS(el,fs,ux,iuna,iula,iiq,eg,fb,u,p,la,lb)\n!\t\n!\n!*************************************************\n\nmodule mod_nnls\n\n\timplicit none\n\ncontains\n!=========\nsubroutine rtNNLS(el,fs,ux,iuna,iula,iiq,eg,fb,u,p,la,lb)\n\n\tuse mod_qrdec\n\n\timplicit none\n\n\tinteger, intent(in) :: iuna, iula, iiq\n\treal(8), intent(in) :: el(iuna,iiq), fs(iula)\n\n\tinteger, intent(out) :: la(iiq), lb(iiq)\n\treal(8), intent(out) :: fb(iula), ux(iiq), u(iula), p(iiq)\n\n\treal(8), intent(inout) :: eg(iuna,iiq)\n\n\tinteger :: i, j, jm, iiqa, iite, lea, j1\n\treal(8) :: ea, emi, q, qs, detl\n\n! *** PROGRAM NNLS ***\n! *** search UX WHICH NORM(EL*UX-FS) minimize subject to UX > 0 ***\n! *** UX : SOLUTION ***\n! *** FB : RESIDUAL FS-EL*UX ***\n\n! ++++ INITIALIZE ++++\n\n\tprint *, ' START OF PROGRAM NNLS, IIQ= ', iiq\n\n\tiiqa = iiq * 2\n\tiite = 0\n\n\tux(1:iiq) = 0.d0\n\tla(1:iiq) = 1\n\nlp1:do\n\n\t\tiite = iite + 1\n\n! +++ FB = FS-EL*UX, P = EL/T*FB +++\n\n\t\tdo i = 1, iula\n\t\t\tfb(i) = fs(i)\n\t\t\tdo j = 1, iiq\n\t\t\t\tfb(i) = fb(i) - el(i,j) * ux(j)\n\t\t\tend do\n\t\tend do\n\n\t\tdo j = 1, iiq\n\t\t\tp(j) = 0.d0\n\t\t\tdo i = 1, iula\n\t\t\t\tp(j) = p(j) + el(i,j) * fb(i)\n\t\t\tend do\n\t\tend do\n\n\t\tea = 0.d0\n\t\tlea = 0\n\n\t\tdo j = 1, iiq\n\t\t\tif(la(j) == 0) cycle\n\t\t\tif( p(j) < ea) cycle\n\n\t\t\tlea = j\n\t\t\tea = p(j)\n\t\tend do\n\n\t\tif(lea == 0) return\n\n\t\tla(lea) = 0\n\nlp2:\tdo\n\n! +++ ( FB - EG*P ) MINIMIZE/ P: SELECTED PARAMETERS +++\n\n\t\t\tdo i = 1, iula\n\t\t\t\tfb(i) = fs(i)\n\t\t\tend do\n\n\t\t\tjm = 0\n\n\t\t\tdo j = 1, iiq\n\t\t\t\tif(la(j) == 1) cycle\n\n\t\t\t\tjm = jm + 1\n\n\t\t\t\tdo i = 1, iula\n\t\t\t\t\teg(i,jm) = el(i,j)\n\t\t\t\tend do\n\t\t\tend do\n\n! ----- CALL LSQS(eg,fb,p,iuna,iula,jm,lb,u) -----\n\n\t\t\tCALL QRDEC(eg,fb,detl,iuna,iula,jm,u,lb,j1,1)\n\n\t\t\tif(j1 /= jm) stop ' ERROR LSQS UNDERDETERMINED '\n\n\t\t\tCALL RINV(p,fb,eg,iuna,jm,0)\n\n! ----- /LSQS/ -----\n\n\t\t\tif(iite >= iiqa) stop ' IITE LIMIT OVER'\n\n\t\t\temi = 1.d2\n\n\t\t\tdo j = iiq, 1, -1\n\n\t\t\t\tif(la(j) == 0) then\n\n\t\t\t\t\tp(j) = p(jm)\n\t\t\t\t\tjm = jm - 1\n\n\t\t\t\t\tif(p(j) < emi) emi = p(j)\n\n\t\t\t\telse if(la(j) == 1) then\n\n\t\t\t\t\tp(j) = 0.d0\n\n\t\t\t\tend if\n\n\t\t\tend do\n\n\t\t\tif(emi <= 0.d0) then\n\n\t\t\t\tq = 1.d2\n\t\t\t\tlea = 0\n\n\t\t\t\tdo j = 1, iiq\n\t\t\t\t\tif(la(j) == 1) cycle\n\t\t\t\t\tif( p(j) > 0.d0) cycle\n\n\t\t\t\t\tqs = ux(j) / (ux(j) - p(j))\n\t\t\t\t\tif(qs >= q) cycle\n\n\t\t\t\t\tq = qs\n\t\t\t\t\tlea = j\n\t\t\t\tend do\n\n\t\t\t\tdo j = 1, iiq\n\t\t\t\t\tux(j) = ux(j) + q *(p(j) - ux(j))\n\t\t\t\t\tif(ux(j) > 0.d0) cycle\n\n\t\t\t\t\tux(j) = 0.d0\n\t\t\t\t\tla(j) = 1\n\t\t\t\tend do\n\n\t\t\t\tla(lea) = 1\n\t\t\t\tux(lea) = 0.d0\n\n\t\t\t\tcycle lp2\n\n\t\t\telse if(emi > 0.d0) then\n\n\t\t\t\tdo j = 1, iiq\n\t\t\t\t\tux(j) = p(j)\n\t\t\t\tend do\n\n\t\t\t\tcycle lp1\n\n\t\t\tend if\n\n\t\tend do lp2\n\n\tend do lp1\n\nend subroutine rtNNLS\n\n!=========\n\nend module mod_nnls\n", "meta": {"hexsha": "1c52cf8632695386c124ed92fdaa4bf315f67b77", "size": 2650, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fort/m_nnls.f90", "max_stars_repo_name": "s-watanabe-jhod/YM1992", "max_stars_repo_head_hexsha": "85793cba6a81aeded1569dd0c61566e4c934e050", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fort/m_nnls.f90", "max_issues_repo_name": "s-watanabe-jhod/YM1992", "max_issues_repo_head_hexsha": "85793cba6a81aeded1569dd0c61566e4c934e050", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fort/m_nnls.f90", "max_forks_repo_name": "s-watanabe-jhod/YM1992", "max_forks_repo_head_hexsha": "85793cba6a81aeded1569dd0c61566e4c934e050", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-08-27T07:38:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-27T07:38:59.000Z", "avg_line_length": 14.7222222222, "max_line_length": 69, "alphanum_fraction": 0.4652830189, "num_tokens": 1161, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898229217591, "lm_q2_score": 0.7371581741774411, "lm_q1q2_score": 0.6678578036883471}} {"text": "* Home work (1)\r\n* Question (6)\r\n\r\n* a class of 120 students takes an exam on which\r\n* the score is between 0 and 100 , write a fortran\r\n* program which calculate :\r\n* (a)the average score\r\n* (b)the number of student failed score below 60\r\n* (c)the number of student of perfect scores 100\r\n\r\n\r\n integer counter\r\n failed=0\r\n perfect=0\r\n average=0\r\n print*,'Enter the Student number'\r\n read(*,*)n\r\n do 10 counter =1,n\r\n print*,'Enter the Student Score'\r\n read(*,*)score\r\n if(score.lt.60) failed = (failed +1)\r\n if(score.eq.100) perfect=perfect+1\r\n average=average+score\r\n10 continue\r\n average=average/N\r\n print*, 'the average score =',average\r\n print*, 'number of student failed =',failed\r\n print*, 'number of student of perfect score',perfect\r\n stop\r\n End\r\n\r\n\r\n", "meta": {"hexsha": "44078e80009eaad2de4fc1e64e3b51749162b5bc", "size": 912, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "HW(1)/Problem (6)/Hw_1_problem_6_.f", "max_stars_repo_name": "Melhabbash/Computational-Physics-", "max_stars_repo_head_hexsha": "82a92e629fbaaf053d2f5e1ccb1224389b2e94be", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "HW(1)/Problem (6)/Hw_1_problem_6_.f", "max_issues_repo_name": "Melhabbash/Computational-Physics-", "max_issues_repo_head_hexsha": "82a92e629fbaaf053d2f5e1ccb1224389b2e94be", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HW(1)/Problem (6)/Hw_1_problem_6_.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": 27.6363636364, "max_line_length": 60, "alphanum_fraction": 0.5701754386, "num_tokens": 235, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388083214158, "lm_q2_score": 0.8056321983146848, "lm_q1q2_score": 0.6678197944163373}} {"text": "!------------------------------------------------------------------------------\n!\n! SUBROUTINE:\n!\n! DESCRIPTION: \n!> \n!\n! REVISION HISTORY:\n! 13 11 2021 - Initial Version\n! TODO_dd_mmm_yyyy - TODO_describe_appropriate_changes - TODO_name\n!------------------------------------------------------------------------------\n!------------------------------------------------------------------------------\n! \nsubroutine initialize\n use parameters\n use func_param\n use func_param2\n implicit none\n \n!---Setting Boundary Condition\n if (select == 1) then\n ! Example: Airy equation\n x = 0.d0\n y(1) = 0.35502805d0\n y(2) = - 0.25881940d0\n\n else if (select == 2) then\n ! Example: Lecture\n x = 1.d0\n y(1) = 0.d0\n y(2) = 0.d0 \n\n else if (select == 3) then\n ! Example: Report\n x = 0.d0\n if (count == 1) then\n u = [0.d0, 0.d0] ! Function u\n y = u\n\n else if (count == 2) then\n z = [0.d0, 1.d0] ! Function z \n y = z\n end if\n end if\n \n !---Output initial y\n write (*, *) \" step = 0\"\n call output\n\n return\nend subroutine\n\n!----------------------------------------------------------------------\n!\nsubroutine RK(i)\n use parameters\n use func_param\n use func_param2\n implicit none\n\n character(30) :: step\n integer i ! loop dummy number\n double precision :: dy(n) ! Average tangent\n double precision :: a(n), b(n), c(n), d(n) \n ! (a, b, c, d are difined to reduce the subscripts expression) \n ! a = k1: 1st tangent\n ! b = k2: Predicted tangent for the midpoint\n ! c = k3: Modified tangent for the midpoint\n ! d = k4: 4th tangent\n\n!---Calculate with Runge-Kutta\n !---Calculate 1st tangent\n call func( x, y, f )\n a = h * f\n !---Prediction on the midpoint\n call func( x + 0.5d0 * h, y + 0.5d0 * a, f )\n b = h * f\n !---Modification on the midpoint\n call func( x + 0.5d0 * h, y + 0.5d0 * b, f )\n c = h * f\n !---Calculate 4th tangent\n call func( x + h, y + c, f )\n d = h * f\n\n ! Calculate average dy\n dy = ( a + 2.d0 * b + 2.d0 * c + d ) / 6.d0\n\n !---Time steps\n x = x + h\n y = y + dy\n\n !---Output for the respectively step\n write (step, *) i\n write (*, *) \" step = \"//adjustl(trim(step))\n call output\n\n return\nend subroutine\n\n!----------------------------------------------------------------------\n! Difine function f for x and y respectively\n! because they are substituted for the function.\n! * You cannot use this as the internal subroutine, too.\n!----------------------------------------------------------------------\n!\nsubroutine func(x, y, f)\n use parameters \n use func_param2\n implicit none\n\n double precision :: x\n double precision :: y(n)\n double precision :: f(n)\n\n if (select == 1) then\n ! Example: Airy equation\n f = [y(2), x * y(1)]\n\n else if (select == 2) then\n ! Example: Lecture\n f = [y(2), - 2 * y(1) / x + x]\n\n else if (select == 3) then\n ! Example: Report\n ! solution vector y = u + Cz\n if (count == 1) then\n\n y = [u(1), u(2)] ! set y as u \n f = [y(2), y(1) - x]\n\n else if (count == 2) then\n\n y = [z(1), z(2)] ! set y as z\n f = [y(2), y(1)]\n\n end if\n end if\n\n return\nend subroutine\n\n!----------------------------------------------------------------------\n!\nsubroutine output\n use parameters\n use func_param\n use func_param2\n implicit none\n\n character(30) :: sol1\n character(30) :: sol2\n \n write (*, \"(A, f15.3)\") \" x = \", x\n\n if ( select == 1 .or. select == 2 ) then\n write (sol1, \"(f15.3)\") y(1)\n write (sol2, \"(f15.3)\") y(2)\n write (*, *) \" y = (\"//adjustr(trim(sol1))//\", \"//adjustl(trim(sol2))//\")\"\n write (*, *) \"\"\n\n else if ( select == 3 ) then\n write (sol1, \"(f15.3)\") y(1)\n write (sol2, \"(f15.3)\") y(2)\n\n if (count == 1) then\n u = y\n write (*, *) \" u = (\"//adjustr(trim(sol1))//\", \"//adjustl(trim(sol2))//\" )\"\n write (*, *) \"\"\n write (10, *) y(1), ',', y(2)\n\n else if ( count == 2 ) then\n z = y\n write (*, *) \" z = (\"//adjustr(trim(sol1))//\", \"//adjustl(trim(sol2))//\" )\"\n write (*, *) \"\"\n write (10, *) y(1), ',', y(2)\n\n end if\n end if\n\n return\nend subroutine\n\n!----------------------------------------------------------------------\n! \nsubroutine calculate_C\n use parameters\n use func_param\n use func_param2\n implicit none\n\n!---Output for se = 3\n double precision :: C\n double precision :: BC_y\n character(30) :: sol, sol1, sol2, sol3, sol4\n\n BC_y = 0.d0 ! y(10) = 0\n write (sol3, \"(f15.3)\") u(1)\n write (sol4, \"(f15.3)\") z(1)\n write (*, \"(A, 2f15.3)\") \" u(1), z(1) = ( \"//adjustl(trim(sol3))//\", \"//adjustl(trim(sol4))//\")\"\n C = ( BC_y - u(1) ) / z(1)\n\n write (sol, \"(f15.3)\") C\n write (*, \"(A, f15.3)\") \" C = \"//adjustl(trim(sol))\n\n y = u + C * z\n write (sol1, \"(f15.3)\") y(1)\n write (sol2, \"(f15.3)\") y(2)\n write (*, *) \" y = ( \"//adjustl(trim(sol1))//\", \"//adjustl(trim(sol2))//\")\"\n write (*, *) \"\"\n write (10, *) adjustl(trim(sol1))//\", \"//adjustl(trim(sol2))\n\n return\nend subroutine\n", "meta": {"hexsha": "4fd8b862cb049539d4980a67845081d3b2efab9f", "size": 5517, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Integral/RK-method/RK-file/subroutine.f90", "max_stars_repo_name": "DiaSird/Mathmatics-Lecture-code", "max_stars_repo_head_hexsha": "cb9d06f1b16915483276a227efe1a1b69f3fd2fd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Integral/RK-method/RK-file/subroutine.f90", "max_issues_repo_name": "DiaSird/Mathmatics-Lecture-code", "max_issues_repo_head_hexsha": "cb9d06f1b16915483276a227efe1a1b69f3fd2fd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Integral/RK-method/RK-file/subroutine.f90", "max_forks_repo_name": "DiaSird/Mathmatics-Lecture-code", "max_forks_repo_head_hexsha": "cb9d06f1b16915483276a227efe1a1b69f3fd2fd", "max_forks_repo_licenses": ["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.7803738318, "max_line_length": 100, "alphanum_fraction": 0.4294000363, "num_tokens": 1653, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388083214156, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.6678197886137058}} {"text": "c comment section.\nc\nc fm030\nc\nc this routine tests arithmetic assignment statements of the\nc form\nc integer variable = arithmetic expression\nc where the arithmetic expression is formed with the arithmetic\nc operator -, integer constants and integer variables.\nc some of the tests use parentheses to group elements in the\nc arithmetic expression.\nc\nc there are tests where the arithmetic expression contains\nc (1) integer constant - integer constant\nc (2) integer constant - integer constant - integer constant\nc (3) same as (2) but with parentheses to group elements\nc (4) integer variable - integer constant\nc integer constant - integer variable\nc\nc references\nc american national standard programming language fortran,\nc x3.9-1978\nc\nc section 4.3, integer type\nc section 4.3.1, integer constant\nc section 6.1, arithmetic expressions\nc section 10.1, arithmetic assignment statement\nc\nc\nc **********************************************************\nc\nc a compiler validation system for the fortran language\nc based on specifications as defined in american national standard\nc programming language fortran x3.9-1978, has been developed by the\nc federal cobol compiler testing service. the fortran compiler\nc validation system (fcvs) consists of audit routines, their related\nc data, and an executive system. each audit routine is a fortran\nc program, subprogram or function which includes tests of specific\nc language elements and supporting procedures indicating the result\nc of executing these tests.\nc\nc this particular program/subprogram/function contains features\nc found only in the subset as defined in x3.9-1978.\nc\nc suggestions and comments should be forwarded to -\nc\nc department of the navy\nc federal cobol compiler testing service\nc washington, d.c. 20376\nc\nc **********************************************************\nc\nc\nc\nc initialization section\nc\nc initialize constants\nc **************\nc i01 contains the logical unit number for the card reader.\n i01 = 5\nc i02 contains the logical unit number for the printer.\n i02 = 6\nc system environment section\nc\ncx010 this card is replaced by contents of fexec x-010 control card.\nc the cx010 card is for overriding the program default i01 = 5\nc (unit number for card reader).\ncx011 this card is replaced by contents of fexec x-011 control card.\nc the cx011 card is for systems which require additional\nc fortran statements for files associated with cx010 above.\nc\ncx020 this card is replaced by contents of fexec x-020 control card.\nc the cx020 card is for overriding the program default i02 = 6\nc (unit number for printer).\ncx021 this card is replaced by contents of fexec x-021 control card.\nc the cx021 card is for systems which require additional\nc fortran statements for files associated with cx020 above.\nc\n ivpass=0\n ivfail=0\n ivdele=0\n iczero=0\nc\nc write page headers\n write (i02,90000)\n write (i02,90001)\n write (i02,90002)\n write (i02, 90002)\n write (i02,90003)\n write (i02,90002)\n write (i02,90004)\n write (i02,90002)\n write (i02,90011)\n write (i02,90002)\n write (i02,90002)\n write (i02,90005)\n write (i02,90006)\n write (i02,90002)\nc test section\nc\nc arithmetic assignment statement\nc\nc test 265 through test 270 contain two integer constants and\nc operator - in an arithmetic expression. the form tested is\nc integer variable = integer constant - integer constant\nc\n 2651 continue\n ivtnum = 265\nc\nc **** test 265 ****\nc\n if (iczero) 32650, 2650, 32650\n 2650 continue\n ivcomp = 3-2\n go to 42650\n32650 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42650, 2661, 42650\n42650 if (ivcomp - 1) 22650,12650,22650\n12650 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 2661\n22650 ivfail = ivfail + 1\n ivcorr = 1\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 2661 continue\n ivtnum = 266\nc\nc **** test 266 ****\nc\n if (iczero) 32660, 2660, 32660\n 2660 continue\n ivcomp = 51 - 52\n go to 42660\n32660 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42660, 2671, 42660\n42660 if (ivcomp +1) 22660,12660,22660\n12660 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 2671\n22660 ivfail = ivfail + 1\n ivcorr = -1\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 2671 continue\n ivtnum = 267\nc\nc **** test 267 ***\nc\n if (iczero) 32670, 2670, 32670\n 2670 continue\n ivcomp = 865 - 189\n go to 42670\n32670 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42670, 2681, 42670\n42670 if (ivcomp -676) 22670,12670,22670\n12670 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 2681\n22670 ivfail = ivfail + 1\n ivcorr = 676\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 2681 continue\n ivtnum = 268\nc\nc **** test 268 ****\nc\n if (iczero) 32680, 2680, 32680\n 2680 continue\n ivcomp =1358-9359\n go to 42680\n32680 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42680, 2691, 42680\n42680 if (ivcomp+8001) 22680,12680,22680\n12680 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 2691\n22680 ivfail = ivfail + 1\n ivcorr = -8001\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 2691 continue\n ivtnum = 269\nc\nc **** test 269 ****\nc\n if (iczero) 32690, 2690, 32690\n 2690 continue\n ivcomp =21113-10001\n go to 42690\n32690 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42690, 2701, 42690\n42690 if (ivcomp-11112) 22690,12690,22690\n12690 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 2701\n22690 ivfail = ivfail + 1\n ivcorr=11112\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 2701 continue\n ivtnum = 270\nc\nc **** test 270 ****\nc\n if (iczero) 32700, 2700, 32700\n 2700 continue\n ivcomp = 32767-1\n go to 42700\n32700 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42700, 2711, 42700\n42700 if (ivcomp -32766) 22700,12700,22700\n12700 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 2711\n22700 ivfail = ivfail + 1\n ivcorr = 32766\n write (i02,80004) ivtnum, ivcomp ,ivcorr\nc\nc test 271 through test 274 contain three integer constants\nc and operator - in an arithmetic expression. the form tested is\nc iv = ic - ic - ic\nc\n 2711 continue\n ivtnum = 271\nc\nc **** test 271 ****\nc\n if (iczero) 32710, 2710, 32710\n 2710 continue\n ivcomp=9-4-3\n go to 42710\n32710 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42710, 2721, 42710\n42710 if (ivcomp -2) 22710,12710,22710\n12710 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 2721\n22710 ivfail = ivfail + 1\n ivcorr =2\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 2721 continue\n ivtnum = 272\nc\nc **** test 272 ****\nc\n if (iczero) 32720, 2720, 32720\n 2720 continue\n ivcomp = 51-52-53\n go to 42720\n32720 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42720, 2731, 42720\n42720 if (ivcomp +54) 22720,12720,22720\n12720 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 2731\n22720 ivfail = ivfail + 1\n ivcorr = -54\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 2731 continue\n ivtnum = 273\nc\nc **** test 273 ****\nc\n if (iczero) 32730, 2730, 32730\n 2730 continue\n ivcomp = 966 -676 -189\n go to 42730\n32730 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42730, 2741, 42730\n42730 if (ivcomp -101) 22730,12730,22730\n12730 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 2741\n22730 ivfail = ivfail + 1\n ivcorr = 101\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 2741 continue\n ivtnum = 274\nc\nc **** test 274 ****\nc\n if (iczero) 32740, 2740, 32740\n 2740 continue\n ivcomp = 1358-8001-2188\n go to 42740\n32740 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42740, 2751, 42740\n42740 if (ivcomp + 8831) 22740,12740,22740\n12740 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 2751\n22740 ivfail = ivfail + 1\n ivcorr = -8831\n write (i02,80004) ivtnum, ivcomp ,ivcorr\nc\nc test 275 through test 282 are the same as tests 271-274 except\nc parentheses are used to group the constants.\nc\n 2751 continue\n ivtnum = 275\nc\nc **** test 275 ****\nc\n if (iczero) 32750, 2750, 32750\n 2750 continue\n ivcomp =(9-4)-3\n go to 42750\n32750 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42750, 2761, 42750\n42750 if (ivcomp -2) 22750,12750,22750\n12750 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 2761\n22750 ivfail = ivfail + 1\n ivcorr = 2\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 2761 continue\n ivtnum = 276\nc\nc **** test 276 ****\nc\n if (iczero) 32760, 2760, 32760\n 2760 continue\n ivcomp =9-(4-3)\n go to 42760\n32760 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42760, 2771, 42760\n42760 if (ivcomp -8) 22760,12760,22760\n12760 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 2771\n22760 ivfail = ivfail + 1\n ivcorr =8\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 2771 continue\n ivtnum = 277\nc\nc **** test 277 ****\nc\n if (iczero) 32770, 2770, 32770\n 2770 continue\n ivcomp =(51-52)-53\n go to 42770\n32770 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42770, 2781, 42770\n42770 if (ivcomp +54) 22770,12770,22770\n12770 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 2781\n22770 ivfail = ivfail + 1\n ivcorr = -54\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 2781 continue\n ivtnum = 278\nc\nc **** test 278 ****\nc\n if (iczero) 32780, 2780, 32780\n 2780 continue\n ivcomp=51-(52-53)\n go to 42780\n32780 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42780, 2791, 42780\n42780 if (ivcomp-52) 22780,12780,22780\n12780 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 2791\n22780 ivfail = ivfail + 1\n ivcorr = 52\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 2791 continue\n ivtnum = 279\nc\nc **** test 279 ****\nc\n if (iczero) 32790, 2790, 32790\n 2790 continue\n ivcomp =(966-676)-189\n go to 42790\n32790 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42790, 2801, 42790\n42790 if (ivcomp - 101) 22790,12790,22790\n12790 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 2801\n22790 ivfail = ivfail + 1\n ivcorr = 101\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 2801 continue\n ivtnum = 280\nc\nc **** test 280 ****\nc\n if (iczero) 32800, 2800, 32800\n 2800 continue\n ivcomp =966-(676-189)\n go to 42800\n32800 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42800, 2811, 42800\n42800 if (ivcomp - 479) 22800,12800,22800\n12800 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 2811\n22800 ivfail = ivfail + 1\n ivcorr = 479\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 2811 continue\n ivtnum = 281\nc\nc **** test 281 ****\nc\n if (iczero) 32810, 2810, 32810\n 2810 continue\n ivcomp = (1358-8001)-2188\n go to 42810\n32810 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42810, 2821, 42810\n42810 if (ivcomp + 8831) 22810,12810,22810\n12810 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 2821\n22810 ivfail = ivfail + 1\n ivcorr = -8831\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 2821 continue\n ivtnum = 282\nc\nc **** test 282 ****\nc\n if (iczero) 32820, 2820, 32820\n 2820 continue\n ivcomp = 1358-(8001-2188)\n go to 42820\n32820 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42820, 2831, 42820\n42820 if (ivcomp + 4455) 22820,12820,22820\n12820 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 2831\n22820 ivfail = ivfail + 1\n ivcorr = -4455\n write (i02,80004) ivtnum, ivcomp ,ivcorr\nc\nc test 283 through test 299 contain integer variable, integer\nc constant and operator - in arithmetic expression. the integer\nc variable contains both positive and negative values.\nc the forms tested are\nc integer variable = integer variable - integer constant\nc integer variable = integer constant - integer variable\nc\n 2831 continue\n ivtnum = 283\nc\nc **** test 283 ****\nc\n if (iczero) 32830, 2830, 32830\n 2830 continue\n ivon01 = 3\n ivcomp = ivon01 - 2\n go to 42830\n32830 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42830, 2841, 42830\n42830 if (ivcomp - 1) 22830,12830,22830\n12830 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 2841\n22830 ivfail = ivfail + 1\n ivcorr = 1\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 2841 continue\n ivtnum = 284\nc\nc **** test 284 ****\nc\n if (iczero) 32840, 2840, 32840\n 2840 continue\n ivon01 = 2\n ivcomp = ivon01 -3\n go to 42840\n32840 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42840, 2851, 42840\n42840 if (ivcomp +1) 22840,12840,22840\n12840 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 2851\n22840 ivfail = ivfail + 1\n ivcorr = -1\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 2851 continue\n ivtnum = 285\nc\nc **** test 285 ****\nc\n if (iczero) 32850, 2850, 32850\n 2850 continue\n ivon01 =-3\n ivcomp = ivon01 -2\n go to 42850\n32850 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42850, 2861, 42850\n42850 if (ivcomp +5) 22850,12850,22850\n12850 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 2861\n22850 ivfail = ivfail + 1\n ivcorr =-5\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 2861 continue\n ivtnum = 286\nc\nc **** test 286 ****\nc\n if (iczero) 32860, 2860, 32860\n 2860 continue\n ivon02 =2\n ivcomp = 3 - ivon02\n go to 42860\n32860 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42860, 2871, 42860\n42860 if (ivcomp -1) 22860,12860,22860\n12860 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 2871\n22860 ivfail = ivfail + 1\n ivcorr = 1\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 2871 continue\n ivtnum = 287\nc\nc **** test 287 ****\nc\n if (iczero) 32870, 2870, 32870\n 2870 continue\n ivon02 =3\n ivcomp = 2 -ivon02\n go to 42870\n32870 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42870, 2881, 42870\n42870 if (ivcomp +1) 22870,12870,22870\n12870 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 2881\n22870 ivfail = ivfail + 1\n ivcorr =-1\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 2881 continue\n ivtnum = 288\nc\nc **** test 288 ****\nc\n if (iczero) 32880, 2880, 32880\n 2880 continue\n ivon02 = -2\n ivcomp = 3 - ivon02\n go to 42880\n32880 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42880, 2891, 42880\n42880 if (ivcomp -5) 22880,12880,22880\n12880 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 2891\n22880 ivfail = ivfail + 1\n ivcorr =5\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 2891 continue\n ivtnum = 289\nc\nc **** test 289 ****\nc\n if (iczero) 32890, 2890, 32890\n 2890 continue\n ivon01 =51\n ivcomp = ivon01 - 52\n go to 42890\n32890 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42890, 2901, 42890\n42890 if (ivcomp + 1) 22890,12890,22890\n12890 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 2901\n22890 ivfail = ivfail + 1\n ivcorr = -1\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 2901 continue\n ivtnum = 290\nc\nc **** test 290 ****\nc\n if (iczero) 32900, 2900, 32900\n 2900 continue\n ivon01 =51\n ivcomp = ivon01 -51\n go to 42900\n32900 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42900, 2911, 42900\n42900 if (ivcomp) 22900,12900,22900\n12900 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 2911\n22900 ivfail = ivfail + 1\n ivcorr =0\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 2911 continue\n ivtnum = 291\nc\nc **** test 291 ****\nc\n if (iczero) 32910, 2910, 32910\n 2910 continue\n ivon01 =53\n ivcomp =ivon01 -52\n go to 42910\n32910 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42910, 2921, 42910\n42910 if (ivcomp -1) 22910,12910,22910\n12910 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 2921\n22910 ivfail = ivfail + 1\n ivcorr = 1\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 2921 continue\n ivtnum = 292\nc\nc **** test 292 ****\nc\n if (iczero) 32920, 2920, 32920\n 2920 continue\n ivon02 = 676\n ivcomp = 189 - ivon02\n go to 42920\n32920 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42920, 2931, 42920\n42920 if (ivcomp + 487) 22920,12920,22920\n12920 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 2931\n22920 ivfail = ivfail + 1\n ivcorr = -487\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 2931 continue\n ivtnum = 293\nc\nc **** test 293 ****\nc\n if (iczero) 32930, 2930, 32930\n 2930 continue\n ivon02 = -676\n ivcomp = 189 - ivon02\n go to 42930\n32930 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42930, 2941, 42930\n42930 if (ivcomp - 865) 22930,12930,22930\n12930 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 2941\n22930 ivfail = ivfail + 1\n ivcorr = 865\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 2941 continue\n ivtnum = 294\nc\nc **** test 294 ****\nc\n if (iczero) 32940, 2940, 32940\n 2940 continue\n ivon01 = 1358\n ivcomp = ivon01 - 8001\n go to 42940\n32940 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42940, 2951, 42940\n42940 if (ivcomp + 6643) 22940,12940,22940\n12940 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 2951\n22940 ivfail = ivfail + 1\n ivcorr = -6643\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 2951 continue\n ivtnum = 295\nc\nc **** test 295 ****\nc\n if (iczero) 32950, 2950, 32950\n 2950 continue\n ivon01 = -1358\n ivcomp = ivon01 - 8001\n go to 42950\n32950 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42950, 2961, 42950\n42950 if (ivcomp + 9359) 22950,12950,22950\n12950 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 2961\n22950 ivfail = ivfail + 1\n ivcorr = -9359\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 2961 continue\n ivtnum = 296\nc\nc **** test 296 ****\nc\n if (iczero) 32960, 2960, 32960\n 2960 continue\n ivon01 = 15\n ivcomp = ivon01 - 32752\n go to 42960\n32960 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42960, 2971, 42960\n42960 if (ivcomp + 32737) 22960,12960,22960\n12960 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 2971\n22960 ivfail = ivfail + 1\n ivcorr = -32737\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 2971 continue\n ivtnum = 297\nc\nc **** test 297 ****\nc\n if (iczero) 32970, 2970, 32970\n 2970 continue\n ivon01 =-32751\n ivcomp = ivon01 - 15\n go to 42970\n32970 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42970, 2981, 42970\n42970 if (ivcomp + 32766) 22970,12970,22970\n12970 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 2981\n22970 ivfail = ivfail + 1\n ivcorr = -32766\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 2981 continue\n ivtnum = 298\nc\nc **** test 298 ****\nc\n if (iczero) 32980, 2980, 32980\n 2980 continue\n ivon02 = -32752\n ivcomp = 15 - ivon02\n go to 42980\n32980 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42980, 2991, 42980\n42980 if (ivcomp - 32767) 22980,12980,22980\n12980 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 2991\n22980 ivfail = ivfail + 1\n ivcorr = 32767\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 2991 continue\n ivtnum = 299\nc\nc **** test 299 ****\nc\n if (iczero) 32990, 2990, 32990\n 2990 continue\n ivon02 = 15\n ivcomp = 32752 - ivon02\n go to 42990\n32990 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 42990, 3001, 42990\n42990 if (ivcomp - 32737) 22990,12990,22990\n12990 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 3001\n22990 ivfail = ivfail + 1\n ivcorr = 32737\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 3001 continue\nc\nc write page footings and run summaries\n99999 continue\n write (i02,90002)\n write (i02,90006)\n write (i02,90002)\n write (i02,90002)\n write (i02,90007)\n write (i02,90002)\n write (i02,90008) ivfail\n write (i02,90009) ivpass\n write (i02,90010) ivdele\nc\nc\nc terminate routine execution\n stop\nc\nc format statements for page headers\n90000 format (1h1)\n90002 format (1h )\n90001 format (1h ,10x,34hfortran compiler validation system)\n90003 format (1h ,21x,11hversion 1.0)\n90004 format (1h ,10x,38hfor official use only - copyright 1978)\n90005 format (1h ,5x,4htest,5x,9hpass/fail, 5x,8hcomputed,8x,7hcorrect)\n90006 format (1h ,5x,46h----------------------------------------------)\n90011 format (1h ,18x,17hsubset level test)\nc\nc format statements for run summaries\n90008 format (1h ,15x,i5,19h errors encountered)\n90009 format (1h ,15x,i5,13h tests passed)\n90010 format (1h ,15x,i5,14h tests deleted)\nc\nc format statements for test results\n80001 format (1h ,4x,i5,7x,4hpass)\n80002 format (1h ,4x,i5,7x,4hfail)\n80003 format (1h ,4x,i5,7x,7hdeleted)\n80004 format (1h ,4x,i5,7x,4hfail,10x,i6,9x,i6)\n80005 format (1h ,4x,i5,7x,4hfail,4x,e12.5,3x,e12.5)\nc\n90007 format (1h ,20x,20hend of program fm030)\n end\n", "meta": {"hexsha": "194805c19d59171d498127343bdebfe0051093f5", "size": 22309, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "usr.bin/f77/tests/tests/fm030.f", "max_stars_repo_name": "weiss/original-bsd", "max_stars_repo_head_hexsha": "b44636d7febc9dcf553118bd320571864188351d", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 114, "max_stars_repo_stars_event_min_datetime": "2015-01-18T22:55:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-17T10:45:02.000Z", "max_issues_repo_path": "usr.bin/f77/tests/tests/fm030.f", "max_issues_repo_name": "JamesLinus/original-bsd", "max_issues_repo_head_hexsha": "b44636d7febc9dcf553118bd320571864188351d", "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": "usr.bin/f77/tests/tests/fm030.f", "max_forks_repo_name": "JamesLinus/original-bsd", "max_forks_repo_head_hexsha": "b44636d7febc9dcf553118bd320571864188351d", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 29, "max_forks_repo_forks_event_min_datetime": "2015-11-03T22:05:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-08T15:36:37.000Z", "avg_line_length": 26.3077830189, "max_line_length": 72, "alphanum_fraction": 0.6192568022, "num_tokens": 8682, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.8289388083214155, "lm_q1q2_score": 0.6678197866794953}} {"text": "module Poly\n use Const\n! use IO\n implicit none\n\ncontains\n\n function poly_value(poly, x) result(r)\n real(mpc), intent(in) :: poly(:), x\n real(mpc) :: r\n integer :: i\n\n r = 0\n\n do i = 1, size(poly)\n r = r * x + poly(i)\n end do\n end function poly_value\n\n !-----------------------------------------------------------------------\n ! gorner (poly, x_0) -> r_poly\n ! poly: divident \n ! x_0 : (x-x_0) is a divisor\n ! \n ! \timplements gorner method of poly division\n !-----------------------------------------------------------------------\n function gorner_div(poly, x_0) result(r_poly)\n real(mpc), dimension(:), intent(in):: poly\n real(mpc), intent(in) :: x_0\n real(mpc), dimension((size(poly))) :: r_poly\n integer :: n, i\n!\ud83d\udc3e\n n = size(poly)\n r_poly = 0\n r_poly(1) = poly(1)\n do i = 2, n-1\n r_poly(i) = r_poly(i-1)*x_0 + poly(i)\n end do\n end function gorner_div\n\n \n !-----------------------------------------------------------------------\n ! bern_solve (a) -> maxroot\n ! a: \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u044b \u043c\u043d\u043e\u0433\u043e\u0447\u043b\u0435\u043d\u0430\n ! \n ! \tfind root of polynomial using Bernoully method\n !-----------------------------------------------------------------------\n function bern_solve(a, max_iter) result(maxroot)\n real(mpc), dimension(0:), intent(in) :: a\n integer, value, optional :: max_iter\n real(mpc) :: maxroot\n\n real(mpc), dimension(0:size(a)-1) :: y\n real(mpc) :: x, x_1\n integer :: i\n\n if (.not. present(max_iter)) then\n max_iter = -1\n else\n max_iter = abs(max_iter) ! \u043d\u0443 \u0430 \u0432\u0434\u0440\u0443\u0433..\n end if\n\n y = ini_y()\n x = huge(1.0_mpc)\n x_1 = y(0)/y(1)\n i = 0\n\n do while (abs(x-x_1) > eps .and. i /= max_iter )\n x = x_1\n y = shift(y)\n x_1 = y(0)/y(1)\n i = i + 1\n end do\n \n maxroot = x\n\n contains\n !-----------------------------------------------------------------------\n ! ini_y (.a) -> arr\n ! .a -- from outer scope\n ! \n ! \tgenerates inital values for Bernoully solver.\n !-----------------------------------------------------------------------\n function ini_y() result(y)\n real(mpc), dimension(0:size(a)-1) :: y\n integer :: n\n n = size(a) -1 \n y = 1\n y(0) = -dot_product(y(1:n-1), a(2:n))/a(1) + 1.0\n end function ini_y\n\n function shift(y) result(y1)\n real(mpc), dimension(0:), intent(in) :: y\n real(mpc), dimension(0:size(y)-1) :: y1\n integer :: n\n n = size(y) - 1\n\n ! \u0431\u0443\u0434\u0435\u043c \u043e\u0440\u0443\u0434\u043e\u0432\u0430\u0442\u044c \u0441 \u043f\u0435\u0440\u0435\u0432\u0451\u0440\u043d\u0443\u0442\u044b\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c y_i, \u0442\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0441\u0447\u0438\u0442\u0430\u0442\u044c\n ! \u0441\u043a\u0430\u043b\u044f\u0440\u043d\u043e\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435\n y1(1:n) = y(0:n-1)\n y1(0) = -1.0/a(0) * dot_product(a(1:), y1(1:))\n end function shift\n\n end function bern_solve\n\n function poly_roots(poly) result(roots)\n real(mpc), dimension(:), intent(in) :: poly\n real(mpc) :: roots(size(poly)-1), cpoly(size(poly))\n integer :: n,i\n n = size(poly) - 1\n cpoly = poly\n\n do i = 1, n\n roots(i) = bern_solve(cpoly, 100)\n cpoly = gorner_div(cpoly, roots(i))\n end do\n end function poly_roots\n \n pure function poly_by_roots(a0, roots) result(poly)\n real(mpc) :: a0, roots(:), poly(0:size(roots))\n intent(in) :: a0, roots\n integer :: i, n\n\n n = size(roots)\n\n poly = 0\n poly(0) = 1\n ! \u0437\u0434\u0435\u0441\u044c \u043f\u043e\u0442\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u0435 \u043c\u043d\u043e\u0433\u043e\u0447\u043b\u0435\u043d\u043e\u0432\n do i = 1, n\n poly(1:n) = poly(1:n) - roots(i)*poly(0:n-1) \n end do\n\n poly = poly * a0\n end function poly_by_roots\n\nend module Poly\n", "meta": {"hexsha": "62d61a28c8ead55b82cc49eb4f85989f8dc53b95", "size": 3966, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/poly/Poly.f90", "max_stars_repo_name": "taxus-d/integrators", "max_stars_repo_head_hexsha": "90464d4994298343b70c10682a07183e391a18e3", "max_stars_repo_licenses": ["MIT"], "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/poly/Poly.f90", "max_issues_repo_name": "taxus-d/integrators", "max_issues_repo_head_hexsha": "90464d4994298343b70c10682a07183e391a18e3", "max_issues_repo_licenses": ["MIT"], "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/poly/Poly.f90", "max_forks_repo_name": "taxus-d/integrators", "max_forks_repo_head_hexsha": "90464d4994298343b70c10682a07183e391a18e3", "max_forks_repo_licenses": ["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.9489051095, "max_line_length": 84, "alphanum_fraction": 0.424609178, "num_tokens": 1108, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240930029117, "lm_q2_score": 0.7718435083355187, "lm_q1q2_score": 0.6678175994397845}} {"text": "SUBROUTINE BuildStencilsGridY(beta,order,y,DiffStencils,Nx,Ny)\n! By Allan P. Engsig-Karup.\nUSE Precision\n USE Constants\n IMPLICIT NONE\n INTEGER :: rank, beta, Nx, Ny, order, Diff, i\n REAL(KIND=long):: Stencil(2*beta+1), tmpStencil(2*beta+1)\n INTEGER :: idx(2*beta+1)\n REAL(KIND=long) :: c(2*beta+1,order+1)\n REAL(KIND=long), DIMENSION(Ny,2*beta+1) :: DiffStencils\n REAL(KIND=long), DIMENSION(Nx,Ny) :: y\n REAL(KIND=long) :: y0\n!\n rank = 2*beta+1\n!\n IF (Ny==1 .AND. order==0) THEN\n ! Direct interpolation\n Stencil = zero\n Stencil(beta+1) = one\n DiffStencils(1,:) = Stencil\n ELSE IF (Ny==1 .AND. order>0) THEN\n ! For a stencil of one point, the derivative is zero\n Stencil = zero\n Stencil(beta+1) = zero\n DiffStencils(1,:) = Stencil\n ELSE\n DO i=-beta,beta,1\n idx(i+beta+1) = i\n END DO\n DO i = 1, Ny\n ! FIXME: Avoid conditional statements below in inner loop. Unroll loops.\n IF (i-1=Ny-beta+1) THEN\n Diff = (Ny-beta)-i\n ELSE\n Diff = 0\n ENDIF\n ! Expansion point where the approximation is to be defined\n y0 = y(1,i) ! FIXME: x-index fixed\n\n ! Determine local finite difference stencil coefficients\n CALL weights(y0,y(1,i+idx+Diff),rank-1,rank-1,order,c) ! FIXME: y-index fixed\n Stencil = c(1:rank,order+1)\n DiffStencils(i,:) = Stencil\n END DO\n ENDIF\n\nEND SUBROUTINE BuildStencilsGridY\n", "meta": {"hexsha": "0a3e573cbf7f920ccf90a656252bb31afb49f176", "size": 1569, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/initialization/BuildStencilsGridY.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/initialization/BuildStencilsGridY.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/initialization/BuildStencilsGridY.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": 31.38, "max_line_length": 85, "alphanum_fraction": 0.5838113448, "num_tokens": 517, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240930029117, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6678175948988965}} {"text": "\nMODULE FMATH\n USE ISO_FORTRAN_ENV, ONLY: RT => REAL32\n IMPLICIT NONE\n\nCONTAINS\n\n ! Orthogonalize and normalize column vectors of A with pivoting.\n SUBROUTINE ORTHOGONALIZE(A, LENGTHS, RANK)\n REAL(KIND=RT), INTENT(INOUT), DIMENSION(:,:) :: A\n REAL(KIND=RT), INTENT(OUT), DIMENSION(SIZE(A,2)) :: LENGTHS\n INTEGER, INTENT(OUT), OPTIONAL :: RANK\n REAL(KIND=RT) :: L, VEC(SIZE(A,1)) \n INTEGER :: I, J\n IF (PRESENT(RANK)) RANK = 0\n column_orthogonolization : DO I = 1, SIZE(A,2)\n LENGTHS(I:) = SUM(A(:,I:)**2, 1)\n ! Pivot the largest magnitude vector to the front.\n J = I-1+MAXLOC(LENGTHS(I:),1)\n IF (J .NE. I) THEN\n L = LENGTHS(I)\n LENGTHS(I) = LENGTHS(J)\n LENGTHS(J) = L\n VEC(:) = A(:,I)\n A(:,I) = A(:,J)\n A(:,J) = VEC(:)\n END IF\n ! Subtract the first vector from all others.\n IF (LENGTHS(I) .GT. EPSILON(1.0_RT)) THEN\n LENGTHS(I) = SQRT(LENGTHS(I))\n A(:,I) = A(:,I) / LENGTHS(I)\n IF (I .LT. SIZE(A,2)) THEN\n LENGTHS(I+1:) = MATMUL(A(:,I), A(:,I+1:))\n DO J = I+1, SIZE(A,2)\n A(:,J) = A(:,J) - LENGTHS(J) * A(:,I)\n END DO\n END IF\n IF (PRESENT(RANK)) RANK = RANK + 1\n ELSE\n LENGTHS(I:) = 0.0_RT\n EXIT column_orthogonolization\n END IF\n END DO column_orthogonolization\n END SUBROUTINE ORTHOGONALIZE\n\n ! Compute the singular values and right singular vectors for matrix A.\n SUBROUTINE SVD(A, S, VT, RANK, STEPS, BIAS)\n IMPLICIT NONE\n REAL(KIND=RT), INTENT(IN), DIMENSION(:,:) :: A\n REAL(KIND=RT), INTENT(OUT), DIMENSION(MIN(SIZE(A,1),SIZE(A,2))) :: S\n REAL(KIND=RT), INTENT(OUT), DIMENSION(MIN(SIZE(A,1),SIZE(A,2)),MIN(SIZE(A,1),SIZE(A,2))) :: VT\n INTEGER, INTENT(OUT), OPTIONAL :: RANK\n INTEGER, INTENT(IN), OPTIONAL :: STEPS\n REAL(KIND=RT), INTENT(IN), OPTIONAL :: BIAS\n ! Local variables.\n REAL(KIND=RT), DIMENSION(MIN(SIZE(A,1),SIZE(A,2)),MIN(SIZE(A,1),SIZE(A,2))) :: ATA, Q\n INTEGER :: I, J, K, NUM_STEPS\n REAL(KIND=RT) :: MULTIPLIER\n EXTERNAL :: SGEMM, SSYRK\n ! Set the number of steps.\n IF (PRESENT(STEPS)) THEN\n NUM_STEPS = STEPS\n ELSE\n NUM_STEPS = 1\n END IF\n ! Set \"K\" (the number of components).\n K = MIN(SIZE(A,1),SIZE(A,2))\n ! Find the multiplier on A.\n MULTIPLIER = MAXVAL(ABS(A(:,:)))\n IF (MULTIPLIER .EQ. 0.0_RT) THEN\n S(:) = 0.0_RT\n VT(:,:) = 0.0_RT\n RETURN\n END IF\n IF (PRESENT(BIAS)) MULTIPLIER = MULTIPLIER / BIAS\n MULTIPLIER = 1.0_RT / MULTIPLIER\n ! Compute ATA.\n IF (SIZE(A,1) .LE. SIZE(A,2)) THEN\n ! ATA(:,:) = MATMUL(AT(:,:), TRANSPOSE(AT(:,:)))\n CALL SSYRK('U', 'N', K, SIZE(A,2), MULTIPLIER**2, A(:,:), &\n SIZE(A,1), 0.0_RT, ATA(:,:), K)\n ELSE\n ! ATA(:,:) = MATMUL(TRANSPOSE(A(:,:)), A(:,:))\n CALL SSYRK('U', 'T', K, SIZE(A,1), MULTIPLIER**2, A(:,:), &\n SIZE(A,1), 0.0_RT, ATA(:,:), K)\n END IF\n ! Copy the upper diagnoal portion into the lower diagonal portion.\n DO I = 1, K\n ATA(I+1:,I) = ATA(I,I+1:)\n END DO\n ! Compute initial right singular vectors.\n VT(:,:) = ATA(:,:)\n ! Orthogonalize and reorder by magnitudes.\n CALL ORTHOGONALIZE(VT(:,:), S(:), RANK)\n ! Do power iterations.\n power_iteration : DO I = 1, NUM_STEPS\n Q(:,:) = VT(:,:)\n ! Q(:,:) = MATMUL(TRANSPOSE(ATA(:,:)), QTEMP(:,:))\n CALL SGEMM('N', 'N', K, K, K, 1.0_RT, &\n ATA(:,:), K, Q(:,:), K, 0.0_RT, &\n VT(:,:), K)\n CALL ORTHOGONALIZE(VT(:,:), S(:), RANK)\n END DO power_iteration\n ! Compute the singular values.\n WHERE (S(:) .NE. 0.0_RT)\n S(:) = SQRT(S(:)) / MULTIPLIER\n END WHERE\n END SUBROUTINE SVD\n\nEND MODULE FMATH\n", "meta": {"hexsha": "ffe4dced8e9bdd77330e249975ff42e9a56a8cba", "size": 3812, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tlux/math/fmath.f90", "max_stars_repo_name": "tchlux/tlux", "max_stars_repo_head_hexsha": "873cf3b1cf1466863f0fb95f23afe149ff89ad79", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-30T18:43:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:43:25.000Z", "max_issues_repo_path": "tlux/math/fmath.f90", "max_issues_repo_name": "tchlux/tlux", "max_issues_repo_head_hexsha": "873cf3b1cf1466863f0fb95f23afe149ff89ad79", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tlux/math/fmath.f90", "max_forks_repo_name": "tchlux/tlux", "max_forks_repo_head_hexsha": "873cf3b1cf1466863f0fb95f23afe149ff89ad79", "max_forks_repo_licenses": ["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.3423423423, "max_line_length": 98, "alphanum_fraction": 0.536201469, "num_tokens": 1327, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770433, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6678175868517576}} {"text": "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nmodule scalarOP\n\n implicit none\n private\n integer :: i,j,k\n real(kind=8) :: zero = 0d0\n complex(kind=8) :: dumc\n\n public trace,normalize\n\ncontains\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n complex(kind=8) function trace(mat,Nb,Ns)\n\n implicit none\n integer,intent(in) :: Nb,Ns\n complex(kind=8),intent(in) :: mat(0:Nb,0:Ns)\n complex(kind=8) :: dum\n\n dumc = dcmplx(zero,zero)\n do i = 0,Ns-1\n dumc = dumc + mat(i,i)\n enddo\n do i = Ns,Nb\n dumc = dumc + mat(i,Ns)\n enddo\n trace = dumc\n\n end function trace\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n subroutine normalize(normc,mat,Nb,Ns)\n\n implicit none\n integer,intent(in) :: Nb,Ns\n complex(kind=8),intent(in) :: normc\n complex(kind=8),intent(inout) :: mat(0:Nb,0:Ns)\n complex(kind=8) :: dum\n\n dumc = 1d0/normc\n do j = 0,Ns-1\n do i = 0,Nb\n mat(i,j) = dumc*mat(i,j)\n enddo\n enddo\n do i = Ns,Nb\n mat(i,Ns) = dumc*mat(i,Ns)\n enddo\n\n end subroutine normalize\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nend module scalarOP\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n", "meta": {"hexsha": "77963b78a3b0c40bb29ea2c8ec0e9f50e319f37a", "size": 1246, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "TC-programs/DMP/source_approx/scalarOP.f90", "max_stars_repo_name": "sklinkusch/scripts", "max_stars_repo_head_hexsha": "a717cadb559db823a0d5172545661d5afa2715e7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "TC-programs/DMP/source_approx/scalarOP.f90", "max_issues_repo_name": "sklinkusch/scripts", "max_issues_repo_head_hexsha": "a717cadb559db823a0d5172545661d5afa2715e7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "TC-programs/DMP/source_approx/scalarOP.f90", "max_forks_repo_name": "sklinkusch/scripts", "max_forks_repo_head_hexsha": "a717cadb559db823a0d5172545661d5afa2715e7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.8596491228, "max_line_length": 51, "alphanum_fraction": 0.4446227929, "num_tokens": 385, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240686758842, "lm_q2_score": 0.7718435083355187, "lm_q1q2_score": 0.6678175806631262}} {"text": "!! ------------------------------------------------------------------------- !!\n!>\n!!\n!! Linear Long Wave (LLW) for tsunami propagation in spherical coordinate system.\n!! This code is modification of Maeda (2015) code which is written in\n!! cartesian coordinate system.\n!! \n!! The governing equation of LLW is adopted from Nakamura's model.\n!! This code is partially modified by A. Fauzi\n!! Last modified on 2018.7.9\n!!\n!<\n!! ------------------------------------------------------------------------- !!\nprogram llw\n\n implicit none\n\n !! fixed parameters\n integer, parameter :: STDERR = 0 !< Standard Error\n integer, parameter :: STDOUT = 6 !< Standard Output\n real, parameter :: pi = atan(1.0)*4\n real, parameter :: g0 = 9.80665 !< gravity\n integer, parameter :: na = 20 !< absorber thickness\n real, parameter :: r = 6371012.0 !< earth radius (m)\n real, parameter :: omega = 2.0 * acos(-1.0) / 86400 !< earth rotational velocity (rad/s)\n character(len=20) :: fld\n \n !! control parameters\n integer :: nx, ny !< model size\n integer :: nt, tint !< time step size and gauge interval\n real :: dx, dy !< grid width\n real :: dt !< time step\n integer :: mov, zmax_out !< snapshots\n\n !! derived global variables\n real :: dxi, dyi !< inverse grid width\n real :: xbeg, ybeg !< model edge\n integer :: nst !< number of stations\n \n !! time\n integer :: start, finish\n integer :: clock_rate, clock_max\n\n !! arrays\n real, allocatable :: eta(:,:) !< tsunami height\n real, allocatable :: zmax(:,:) !< maximum tsunami height\n real, allocatable :: mm(:,:) !< tsunami vel\n real, allocatable :: nn(:,:) !< tsunami vel\n real, allocatable :: hh(:,:) !< bathymetry\n real, allocatable :: hm(:,:) !< x-averaged bathymetry\n real, allocatable :: hn(:,:) !< y-averaged bathymetry\n real, allocatable :: fh(:,:) !< land filter\n real, allocatable :: fm(:,:) !< land filter\n real, allocatable :: fn(:,:) !< land filter\n real, allocatable :: g1x(:,:), g2x(:,:) !< PML absorber\n real, allocatable :: g1y(:,:), g2y(:,:) !< PML absorber\n real, allocatable :: eta_x(:,:) !< PML eta(x)\n real, allocatable :: wav(:,:) !< waveform at stations\n integer, allocatable :: ist(:), jst(:) !< station location (i,j)\n real, allocatable :: xst(:), yst(:) !< station location (x,y)\n real, allocatable :: theta(:), thetal(:) !< latitude coordinate\n\n !! ----------------------------------------------------------------------- !!\n\n !! parameter input\n include \"sub_param.f90\"\n\n !! ----------------------------------------------------------------------- !!\n !>\n !! memory allocation\n !<\n !! --\n block\n\n integer :: j\n real :: degrad, secrad\n\n allocate( eta(1:nx,1:ny) )\n allocate( zmax(1:nx,1:ny) )\n allocate( mm (1:nx,1:ny) )\n allocate( nn (1:nx,1:ny) )\n allocate( hh (1:nx,1:ny) )\n allocate( hm (1:nx,1:ny) )\n allocate( hn (1:nx,1:ny) )\n allocate( fh (1:nx,1:ny) )\n allocate( fm (1:nx,1:ny) )\n allocate( fn (1:nx,1:ny) )\n allocate( g1x(2,nx), g2x(2,nx), g1y(2,ny), g2y(2,ny) )\n allocate( eta_x(nx,ny) )\n allocate( theta(ny), thetal(ny) )\n\n call system_clock(start,clock_rate,clock_max)\n eta(:,:) = 0.0\n zmax(:,:) = 0.0\n mm (:,:) = 0.0\n nn (:,:) = 0.0\n \n degrad = pi / 180.0\n secrad = pi / (180.0 * 3600)\n \n ybeg = ybeg * degrad\n \n dy = dy * secrad\n dx = dx * secrad\n!$OMP PARALLEL PRIVATE(j)\n!$OMP DO\n do j=1,ny\n theta (j) = ybeg + (j-1) * dy\n thetal(j) = ybeg + (j-1) * dy - (0.5 * dy)\n enddo\n!$OMP END DO\n!$OMP END PARALLEL\n\n dxi = 1.0 / dx\n dyi = 1.0 / dy \n\n end block\n\n include 'sub_initheight.f90'\n\n include 'sub_bathymetry.f90'\n\n include 'sub_station.f90'\n \n !! Waveform at gages is set to be the same as initial deformation\n block\n integer :: i\n!$OMP PARALLEL SHARED(wav) PRIVATE(i)\n!$OMP DO\n do i=1, nst\n wav(0,i) = eta( ist(i), jst(i) )\n end do\n!$OMP END DO\n!$OMP END PARALLEL\n end block\n\n !! Create /out folder\n !! --\n if(mov.eq.0)then\n write(fld,'(a)')'out'\n call system(\"mkdir \" // trim(adjustl(fld)))\n endif\n \n !! ----------------------------------------------------------------------- !!\n !>\n !! PML absorber settings\n !<\n !! --\n block\n\n real :: d1, d2, b1, b2\n integer :: i, j\n real :: d0, b0, R0\n real :: xxb, xxc\n real :: hx\n integer, parameter :: pd = 2\n integer, parameter :: pb = 2\n real, parameter :: c0 = 500.0 !! assumed phase speed\n !! --\n\n\n !! damping profile constants\n hx = na * dx * r\n R0 = 10**( - ( log10( real(na) ) - 1 ) / log10( 2.0 ) - 3.0 )\n d0 = - ( 1.0 / (2.0*hx) ) * ( pd +1 ) * c0 * log( R0 )\n b0 = 2.0\n\n !! initialize eta: assume initial amplitude wihtin PML layer is zero\n eta_x(1:nx,1:ny) = 0.0\n\n !! initialize\n!$OMP PARALLEL SHARED (g1x,g2x,g1y,g2y) PRIVATE(i,j)\n!$OMP DO\n do i=1, 2\n do j=1, nx\n g1x(i,j) = 1.0\n g2x(i,j) = 1.0\n end do\n do j=1, ny\n g1y(i,j) = 1.0\n g2y(i,j) = 1.0\n end do\n end do\n!$OMP END DO\n!$OMP END PARALLEL \n\n !! set absorber\n\n do i=1, na\n\n !! distance from PML boundary\n xxb = max(hx - (i ) * dx * r,0.)\n xxc = max(hx - (i+0.5) * dx * r,0.)\n\n d1 = d0 * ( xxb / hx )**pd\n b1 = 1.0 + ( b0 - 1.0 ) * ( xxb / hx )**pb\n\n d2 = d0 * ( xxc / hx )**pd\n b2 = 1.0 + ( b0 - 1.0 ) * ( xxc / hx )**pb\n\n g1x(1,i) = (b1 - d1/2.0*dt) / (b1 + d1/2*dt)\n g1x(2,i) = (b1 - d2/2.0*dt) / (b1 + d2/2*dt)\n g2x(1,i) = 1.0 / (b1 + d1/2*dt)\n g2x(2,i) = 1.0 / (b1 + d2/2*dt)\n\n g1y(:,i) = g1x(:,i)\n g2y(:,i) = g2x(:,i)\n\n ! Opposite Side; Exchange Staggered Grid\n g1x(1,nx-i+1) = g1x(2,i)\n g1x(2,nx-i+1) = g1x(1,i)\n g2x(1,nx-i+1) = g2x(2,i)\n g2x(2,nx-i+1) = g2x(1,i)\n\n g1y(1,ny-i+1) = g1x(2,i)\n g1y(2,ny-i+1) = g1x(1,i)\n g2y(1,ny-i+1) = g2x(2,i)\n g2y(2,ny-i+1) = g2x(1,i)\n\n end do\n\n end block\n\n\n !! ----------------------------------------------------------------------- !!\n !>\n !! Use 10-m cut off for linear long wave\n !<\n block\n\n integer :: i, j\n real, parameter :: CUTOFF_DEPTH = 10.0\n!$OMP PARALLEL SHARED(eta,hh) PRIVATE(i,j)\n!$OMP DO\n do j=1, ny\n do i=1, nx\n if( hh(i,j) < 0.0 ) then\n eta(i,j) = 0.0\n else if ( hh(i,j) < CUTOFF_DEPTH ) then\n hh(i,j) = 10.0\n end if\n end do\n end do\n!$OMP END DO\n!$OMP END PARALLEL \n end block\n\n !! ----------------------------------------------------------------------- !!\n !>\n !! bathymetry averaging for staggered grid calculation\n !<\n block\n\n integer :: i, j\n\n ! x-averaged bathymetry\n!$OMP PARALLEL SHARED(hm,hn) PRIVATE(i,j)\n!$OMP DO\n do j=1, ny\n hm(1,j) = max( hh(1,j), 0.0 )\n do i=2, nx\n hm(i,j) = ( hh(i,j)+hh(i-1,j) ) / 2.0\n if( hh(i,j) <= 0.0 .or. hh(i-1,j) <= 0.0 ) hm(i,j) = 0.0\n end do\n end do\n\n ! y-averaged bathymetry\n!$OMP DO\n do i=1, nx\n do j=2, ny\n hn(i,j) = ( hh(i,j) + hh(i,j-1) ) / 2.0\n if( hh(i,j) <= 0.0 .or. hh(i,j-1) <= 0.0 ) hn(i,j) = 0.0\n end do\n hn(i,1) = max( hh(i,1), 0.0 )\n end do\n!$OMP END DO\n!$OMP END PARALLEL \n end block\n\n !! ----------------------------------------------------------------------- !!\n !>\n !! define land-filter matrix for reflection boundaries\n !<\n block\n\n integer :: i, j\n\n fm(:,:) = 1.0\n fn(:,:) = 1.0\n fh(:,:) = 1.0\n!$OMP PARALLEL SHARED(fm,fn,fh) PRIVATE(i,j)\n!$OMP DO\n do j=1, ny\n do i=1, nx\n if( hm(i,j) < 0.0 ) fm(i,j) = 0.0\n if( hn(i,j) < 0.0 ) fn(i,j) = 0.0\n if( hh(i,j) < 0.0 ) fh(i,j) = 0.0\n end do\n end do\n!$OMP END DO\n!$OMP END PARALLEL \n end block\n\n !! ----------------------------------------------------------------------- !!\n !>\n !! CFL stability condition check\n !<\n block\n\n if( min(dx * r,dy * r)/dt < sqrt( 2*g0*maxval(hh(:,:)) ) ) then\n write(STDERR,*) \"ERROR: stability condition is violated: \", &\n min(dx * r,dy * r)/dt, sqrt( 2*g0*maxval(hh(:,:)) )\n stop\n end if\n\n end block\n\n\n !! ----------------------------------------------------------------------- !!\n !>\n !! time stepping\n !<\n block\n\n integer :: it\n real :: dxeta(nx,ny), dyeta(nx,ny)\n real :: dxm(nx,ny), dyn(nx,ny), ttt, elapsed, remaining, prog\n !! --\n \n nt = int(nt / dt)\n\n do it= 1, nt\n \n if (mod((real(it) / real(nt))*100, real(20)) == 0) then\n! if( mod(it*dt, real(60)) == 0 ) then\n ttt = it * dt / 60.0\n prog = real(it) / real(nt)\n call system_clock(finish, clock_rate, clock_max)\n elapsed = real(finish-start)/real(clock_rate)/60.0\n remaining = ((1 - prog) / prog) * elapsed !* clock_rate/60.0\n write(*,'(a, f7.2, a, a, f7.2, a, f7.2, a)')'Elapsed time = ',elapsed,&\n ' min; ', 'Remaining time = ', remaining, ' min; ', prog * 100, '/100%'\n end if\n\n !! ------------------------------------------------------------------ !!\n !>\n !! difference of eta with respect to x, y\n !<\n !! --\n block\n\n integer :: i, j\n !! --\n\n!$OMP PARALLEL SHARED(dxeta,dyeta) PRIVATE(i,j)\n!$OMP DO\n do j=1, ny\n do i=2, nx\n dxeta(i,j) = ( eta(i,j) - eta(i-1,j) ) * dxi\n end do\n\n dxeta(1,j) = ( eta(1,j) - 0.0 ) * dxi\n end do\n!$OMP DO\n do i=1, nx\n do j=2, ny\n dyeta(i,j) = ( eta(i,j) - eta(i,j-1) ) * dyi\n end do\n\n dyeta(i,1) = ( eta(i,1) - 0.0 ) * dyi\n end do\n!$OMP END DO\n!$OMP END PARALLEL \n end block\n \n !! ------------------------------------------------------------------ !!\n !>\n !! update velocity in the interior domain\n !<\n !!--\n update_vel: block\n\n integer :: i, j\n \n !! --\n\n!$OMP PARALLEL SHARED(mm,nn) PRIVATE(i,j)\n!$OMP DO\n do j=na+1, ny-na\n do i=na+1, nx-na\n\n mm(i,j) = mm(i,j) - (g0*hm(i,j)*dxeta(i,j)*dt*(1/(cos(theta(j)) * r)) &\n + 0.0) * fm(i,j)\n nn(i,j) = nn(i,j) - (g0*hn(i,j)*dyeta(i,j)*dt*(1/r) &\n - 0.0) * fn(i,j)\n \n end do \n end do\n!$OMP END DO\n!$OMP END PARALLEL \n end block update_vel\n\n !! ------------------------------------------------------------------ !!\n !>\n !! update velocity in the PML layer\n !<\n !! --\n block\n\n integer :: i, j\n !! --\n\n !! South\n!$OMP PARALLEL SHARED(mm,nn) PRIVATE(i,j)\n!$OMP DO\n do j=1, na\n do i=1, nx\n mm(i,j) = g1x(1,i) * mm(i,j) &\n - g2x(1,i) * g0 * hm(i,j) * dxeta(i,j) * dt * (1/(cos(theta(j)) * r)) * fm(i,j)\n nn(i,j) = g1y(1,j) * nn(i,j) &\n - g2y(1,j) * g0 * hn(i,j) * dyeta(i,j) * dt * (1/r) * fn(i,j)\n end do\n end do\n\n !! North\n!$OMP DO\n do j=ny-na+1,ny\n do i=1, nx\n mm(i,j) = g1x(1,i) * mm(i,j) &\n - g2x(1,i) * g0 * hm(i,j) * dxeta(i,j) * dt * (1/(cos(theta(j)) * r)) * fm(i,j)\n nn(i,j) = g1y(1,j) * nn(i,j) &\n - g2y(1,j) * g0 * hn(i,j) * dyeta(i,j) * dt * (1/r) * fn(i,j)\n end do\n end do\n\n !! West\n!$OMP DO\n do j=na+1, ny-na\n do i=1, na\n mm(i,j) = g1x(1,i) * mm(i,j) &\n - g2x(1,i) * g0 * hm(i,j) * dxeta(i,j) * dt * (1/(cos(theta(j)) * r)) * fm(i,j)\n nn(i,j) = g1y(1,j) * nn(i,j) &\n - g2y(1,j) * g0 * hn(i,j) * dyeta(i,j) * dt * (1/r) * fn(i,j)\n end do\n end do\n\n !! East\n!$OMP DO\n do j=na+1, ny-na\n do i=nx-na+1,nx\n mm(i,j) = g1x(1,i) * mm(i,j) &\n - g2x(1,i) * g0 * hm(i,j) * dxeta(i,j) * dt * (1/(cos(theta(j)) * r)) * fm(i,j)\n nn(i,j) = g1y(1,j) * nn(i,j) &\n - g2y(1,j) * g0 * hn(i,j) * dyeta(i,j) * dt * (1/r) * fn(i,j)\n end do\n end do \n!$OMP END DO\n!$OMP END PARALLEL\n end block\n\n !! ------------------------------------------------------------------ !!\n !>\n !! difference of velocities with respect to x, y\n !<\n !! --\n block\n\n integer :: i, j\n !! --\n!$OMP PARALLEL SHARED(dxm,dyn) PRIVATE(i,j)\n!$OMP DO\n do j=1, ny\n dxm(nx,j) = ( 0.0 - mm(nx,j) ) * dxi\n do i=1, nx-1\n dxm(i,j) = ( mm(i+1,j) - mm(i,j) ) * dxi\n end do\n end do\n!$OMP DO\n do i=1, nx\n dyn(i,ny) = ( 0.0 - nn(i,ny)*cos(thetal(ny)) ) * dyi\n do j=1, ny-1\n dyn(i,j) = ( nn(i,j+1)*cos(thetal(j+1)) - nn(i,j)*cos(thetal(j)) ) * dyi\n end do\n end do\n!$OMP END DO\n!$OMP END PARALLEL\n end block\n\n !! ------------------------------------------------------------------ !!\n block\n\n integer i, j\n real :: dtxi, dtyi\n !! --\n\n dtxi = dt * dxi\n dtyi = dt * dyi\n!$OMP PARALLEL SHARED(eta) PRIVATE(i,j)\n!$OMP DO\n do j=na+1, ny-na\n do i=na+1, nx-na\n eta(i,j) = eta(i,j) - ( dxm(i,j) + dyn(i,j) )*dt* (1/(cos(theta(j)) * r)) * fh(i,j)\n end do\n end do\n!$OMP END DO\n!$OMP END PARALLEL\n end block\n\n !! ------------------------------------------------------------------ !!\n block\n\n integer :: i, j\n real :: eta_y\n !! --\n!$OMP PARALLEL SHARED(eta,eta_x) PRIVATE(i,j,eta_y)\n!$OMP DO\n do j=1, na\n do i=1, nx\n eta_y = eta(i,j) - eta_x(i,j)\n\n eta_x(i,j) = g1x(2,i) * eta_x(i,j) - g2x(2,i) * dxm(i,j) * (1/(cos(theta(j)) * r))* dt\n eta_y = g1y(2,j) * eta_y - g2y(2,j) * dyn(i,j) * (1/(cos(thetal(j)) * r))* dt\n\n eta(i,j) = ( eta_x(i,j) + eta_y ) * fh(i,j)\n\n end do\n end do\n!$OMP DO\n do j=ny-na+1,ny\n do i=1, nx\n eta_y = eta(i,j) - eta_x(i,j)\n\n eta_x(i,j) = g1x(2,i) * eta_x(i,j) - g2x(2,i) * dxm(i,j) * (1/(cos(theta(j)) * r))* dt\n eta_y = g1y(2,j) * eta_y - g2y(2,j) * dyn(i,j) * (1/(cos(thetal(j)) * r))* dt\n\n eta(i,j) = ( eta_x(i,j) + eta_y ) * fh(i,j)\n\n end do\n end do\n!$OMP DO\n do j=na+1, ny-na\n do i=1, na\n eta_y = eta(i,j) - eta_x(i,j)\n\n eta_x(i,j) = g1x(2,i) * eta_x(i,j) - g2x(2,i) * dxm(i,j) * (1/(cos(theta(j)) * r))* dt\n eta_y = g1y(2,j) * eta_y - g2y(2,j) * dyn(i,j) * (1/(cos(thetal(j)) * r))* dt\n\n eta(i,j) = ( eta_x(i,j) + eta_y ) * fh(i,j)\n\n end do\n end do\n!$OMP DO\n do j=na+1, ny-na\n do i=nx-na+1,nx\n eta_y = eta(i,j) - eta_x(i,j)\n\n eta_x(i,j) = g1x(2,i) * eta_x(i,j) - g2x(2,i) * dxm(i,j) * (1/(cos(theta(j)) * r))* dt\n eta_y = g1y(2,j) * eta_y - g2y(2,j) * dyn(i,j) * (1/(cos(thetal(j)) * r))* dt\n\n eta(i,j) = ( eta_x(i,j) + eta_y ) * fh(i,j)\n\n end do\n end do\n!$OMP END DO\n!$OMP END PARALLEL\n end block\n \n !! ------------------------------------------------------------------ !!\n ! To calculate maximum tsunami height\n block\n \n integer :: i,j\n \n if (zmax_out.eq.0) then\n!$OMP PARALLEL SHARED(zmax) PRIVATE(i,j)\n!$OMP DO\n do j=1, ny\n do i=1, nx\n if (eta(i,j).gt.zmax(i,j))then\n zmax(i,j)= eta(i,j)\n endif\n enddo\n enddo\n!$OMP END DO\n!$OMP END PARALLEL\n endif\n end block\n \n !! ------------------------------------------------------------------ !!\n block\n\n integer :: i\n \n if (mod(int(dt*it), tint)==0.0) then\n!$OMP PARALLEL SHARED(wav) PRIVATE(i)\n!$OMP DO\n do i=1, nst\n wav(it,i) = eta( ist(i), jst(i) )\n end do\n!$OMP END DO\n!$OMP END PARALLEL\n endif\n\n end block\n \n !! ----------------------------\n ! \n ! To create output file of eta\n block\n \n integer :: i,j\n character(len=20):: fileout\n \n if (mov.eq.0)then \n if(mod(int(it*dt), 60 )==0) then\n write(fileout,'(a, i5.5, a)')\"out/eta_\", int(it*dt), \".dat\"\n open(21,file=trim(fileout), status='unknown') \n\n do i=1,nx\n write(21,'(10000f9.2)')(eta(i,j), j=1,ny)\n enddo\n\n close(21)\n endif\n endif\n \n end block\n !! ----------------------------\n\n end do\n\n end block\n\n !! ----------------------------------------------------------------------- !!\n ! To write wave gauges records and maximum tsunami height\n block\n\n integer :: i, j, it\n character(256) :: fn\n integer, parameter :: io = 100\n !! --\n \n open(io, file='obswv.dat', status='unknown' )\n do it = 0, nt\n if (mod(it*dt, real(tint)) == 0.0) then\n write(io,'(f7.1, 10000f9.3)') it*dt, (wav(it,j), j=1, nst)\n endif\n enddo\n close(io)\n \n if (zmax_out.eq.0) then\n open(21, file='zmax.dat', status='unknown')\n do i=1,nx\n write(21,'(10000f9.2)')(zmax(i,j), j=1,ny)\n enddo\n close(21)\n endif\n\n end block\n\n !! ----------------------------------------------------------------------- !!\n block\n\n deallocate( eta )\n deallocate( zmax )\n deallocate( mm )\n deallocate( nn )\n deallocate( hh )\n deallocate( hm )\n deallocate( hn )\n deallocate( fh )\n deallocate( fm )\n deallocate( fn )\n deallocate( ist, jst )\n deallocate( wav )\n deallocate( g1x, g2x, g1y, g2y )\n deallocate( eta_x )\n deallocate( theta, thetal )\n\n end block\n\nend program llw\n!! ------------------------------------------------------------------------- !!\n", "meta": {"hexsha": "739033ef38dd4a7cf5ba9734659e18871f7d771c", "size": 18770, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "main_llw.f90", "max_stars_repo_name": "ardiansyahfauzi/linear_tsun", "max_stars_repo_head_hexsha": "cc98fbf56872706ca9c573c356b913819f7e3cb6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "main_llw.f90", "max_issues_repo_name": "ardiansyahfauzi/linear_tsun", "max_issues_repo_head_hexsha": "cc98fbf56872706ca9c573c356b913819f7e3cb6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "main_llw.f90", "max_forks_repo_name": "ardiansyahfauzi/linear_tsun", "max_forks_repo_head_hexsha": "cc98fbf56872706ca9c573c356b913819f7e3cb6", "max_forks_repo_licenses": ["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.4415204678, "max_line_length": 102, "alphanum_fraction": 0.4036228023, "num_tokens": 6242, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294983, "lm_q2_score": 0.7154239897159439, "lm_q1q2_score": 0.667798794950513}} {"text": "subroutine tcoefficients(t, awt, aet, ast, ant, apt, bt, uf, vf, rho_uf, rho_vf, gammat_uf, gammat_vf, dx, dy, delx, dely, imax, jmax)\n!use variables\nuse kind_parameters\nimplicit none\n\ninteger, intent(in):: imax, jmax\nreal(kind=dp), intent(in), dimension(imax,jmax):: t, apt, awt, aet, ast, ant, bt\nreal(kind=dp), intent(in), dimension(imax-1, jmax):: uf, rho_uf, gammat_uf\nreal(kind=dp), intent(in), dimension(imax, jmax-1):: vf, rho_vf, gammat_vf\nreal(kind=dp), intent(in) :: dx(imax), dy(jmax), delx(imax-1), dely(jmax-1)\n\ninteger:: it, jt\nreal(kind=dp):: Fn, Fs, Fw, Fe, Dn, Ds, Dw, De, Pn, Ps, Pw, Pe\nreal(kind=dp):: Ap_Pn, Ap_Ps, Ap_Pw, Ap_Pe\nreal(kind=dp):: apfun\n\ndo jt=2,jmax-1\n\n do it=2,imax-1\n\n Fw = rho_uf(it-1,jt)*dy(jt)*uf(it-1,jt)\n Dw = gammat_uf(it-1,jt)*dy(jt)/delx(it-1)\n Pw = Fw/Dw\n Ap_Pw = apfun(Pw)\n awt(it,jt) = Dw*Ap_Pw + max(Fw,0.0)\n\n Fe = rho_uf(it,jt)*dy(jt)*uf(it,jt)\n De = gammat_uf(it,jt)*dy(jt)/delx(it)\n Pe = Fe/De\n Ap_Pe = apfun(Pe)\n aet(it,jt) = De*Ap_Pe+ max(-Fe,0.0)\n\n Fs = rho_vf(it,jt-1)*dx(it)*vf(it,jt-1)\n Ds = gammat_vf(it,jt-1)*dx(it)/dely(jt-1)\n Ps = Fs/Ds\n Ap_Ps = apfun(Ps)\n ast(it,jt) = Ds*Ap_Ps+max(Fs,0.0)\n\n Fn = rho_vf(it,jt)*dx(it)*vf(it,jt)\n Dn = gammat_vf(it,jt)*dx(it)/dely(jt)\n Pn = Fn/Dn\n Ap_Pn = apfun(Pn)\n ant(it,jt) = Dn*Ap_Pn+max(-Fn,0.0)\n\n !atp_zero(it,jt)=rho(it,jt)*dx(it)*dy(jt)/(time_step*A22)\n !bt(it,jt) = atp_zero(it,jt)*(t0(it,jt)+f_temp(it,jt)*(time_step*A21))\n bt(it,jt) = 0.0d0\n\n end do\n\nend do\n\n! locally parabolic condition\n\n!do jt=2,jmax-1\n\n! ate(imax-1,jt) = 0.0\n\n!end do\n\ndo jt=2,jmax-1\n\n do it=2,imax-1\n\n! atp(it,jt) = atw(it,jt) + ate(it,jt) + atn(it,jt) + ats(it,jt) + atp_zero(it,jt)\n atp(it,jt) = awt(it,jt) + aet(it,jt) + ant(it,jt) + ast(it,jt)\n\n end do\n\nend do\n\nend subroutine\n", "meta": {"hexsha": "1fbe636271cda9de39d32ea2f02357853a69d82f", "size": 1949, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tcoefficients.f90", "max_stars_repo_name": "pratanuroy/Multigrid_Cavity", "max_stars_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-09-11T12:01:52.000Z", "max_stars_repo_stars_event_max_datetime": "2017-09-11T12:01:52.000Z", "max_issues_repo_path": "tcoefficients.f90", "max_issues_repo_name": "pratanuroy/Multigrid_Cavity", "max_issues_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tcoefficients.f90", "max_forks_repo_name": "pratanuroy/Multigrid_Cavity", "max_forks_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.698630137, "max_line_length": 134, "alphanum_fraction": 0.5700359159, "num_tokens": 834, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299570920387, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6677784413318822}} {"text": " FUNCTION splints (x)\n USE vspline\n USE vmec_input, ONLY: isnodes\n IMPLICIT NONE\nC-----------------------------------------------\nC D u m m y A r g u m e n t s\nC-----------------------------------------------\n REAL(rprec) x\nC-----------------------------------------------\nC L o c a l P a r a m e t e r s\nC-----------------------------------------------\n REAL(rprec), PARAMETER :: c1o6 = 1._dp/6._dp\nC-----------------------------------------------\nC L o c a l V a r i a b l e s\nC-----------------------------------------------\n INTEGER :: klo, khi, k\n REAL(rprec) :: h, a, a2, b, b2, h2, y26lo, y26hi, yx, splints\nC-----------------------------------------------\n\n klo = 1\n khi = isnodes\n\n 1 CONTINUE\n IF (khi - klo .gt. 1) THEN\n k = (khi + klo)/2\n IF (sknots(k) .gt. x) THEN\n khi = k\n ELSE\n klo = k\n ENDIF\n GOTO 1\n ENDIF\n\n h = sknots(khi) - sknots(klo)\n a = sknots(khi) - x\n b = x - sknots(klo)\n h2 = h*h\n a2 = a*a\n b2 = b*b\n y26lo = c1o6*y2stark(klo)\n y26hi = c1o6*y2stark(khi)\n yx = (a*(ystark(klo)+(a2-h2)*y26lo)+b*(ystark(khi)+(b2-h2)*y26hi))\n 1 /h\n splints = yx\n\n END FUNCTION splints\n", "meta": {"hexsha": "c49c2f6ee38504c20fa7426d436d44caf41af0ab", "size": 1290, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "VMEC2000/Sources/Splines/splints.f", "max_stars_repo_name": "jonathanschilling/VMEC_8_00", "max_stars_repo_head_hexsha": "25519df38bf81bcb673dd9374bda11988de2d940", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2020-05-08T01:47:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T10:35:28.000Z", "max_issues_repo_path": "VMEC2000/Sources/Splines/splints.f", "max_issues_repo_name": "jonathanschilling/VMEC_8_00", "max_issues_repo_head_hexsha": "25519df38bf81bcb673dd9374bda11988de2d940", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 77, "max_issues_repo_issues_event_min_datetime": "2020-05-08T07:18:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:20:33.000Z", "max_forks_repo_path": "VMEC2000/Sources/Splines/splints.f", "max_forks_repo_name": "jonathanschilling/VMEC_8_00", "max_forks_repo_head_hexsha": "25519df38bf81bcb673dd9374bda11988de2d940", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-02-10T13:47:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T12:53:43.000Z", "avg_line_length": 27.4468085106, "max_line_length": 72, "alphanum_fraction": 0.3527131783, "num_tokens": 418, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299509069105, "lm_q2_score": 0.7217431943271999, "lm_q1q2_score": 0.667778420254752}} {"text": " SUBROUTINE jacobn(x,y,dfdx,dfdy,n,nmax)\r\n INTEGER n,nmax,i\r\n REAL x,y(*),dfdx(*),dfdy(nmax,nmax)\r\n do 11 i=1,3\r\n dfdx(i)=0.\r\n11 continue\r\n dfdy(1,1)=-.013-1000.*y(3)\r\n dfdy(1,2)=0.\r\n dfdy(1,3)=-1000.*y(1)\r\n dfdy(2,1)=0.\r\n dfdy(2,2)=-2500.*y(3)\r\n dfdy(2,3)=-2500.*y(2)\r\n dfdy(3,1)=-.013-1000.*y(3)\r\n dfdy(3,2)=-2500.*y(3)\r\n dfdy(3,3)=-1000.*y(1)-2500.*y(2)\r\n return\r\n END\r\n SUBROUTINE derivs(x,y,dydx)\r\n REAL x,y(*),dydx(*)\r\n dydx(1)=-.013*y(1)-1000.*y(1)*y(3)\r\n dydx(2)=-2500.*y(2)*y(3)\r\n dydx(3)=-.013*y(1)-1000.*y(1)*y(3)-2500.*y(2)*y(3)\r\n return\r\n END\r\n", "meta": {"hexsha": "97b939ac5b7c0aec3df33a69b604661315fcaefc", "size": 677, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/jacobn.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/jacobn.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/jacobn.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.08, "max_line_length": 57, "alphanum_fraction": 0.4519940916, "num_tokens": 320, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026618464795, "lm_q2_score": 0.7279754548076477, "lm_q1q2_score": 0.6677738224539568}} {"text": "C\n SUBROUTINE DFILTER2D(A,B,M,N)\nC\n DOUBLE PRECISION A(M,N)\n DOUBLE PRECISION B(M,N)\n INTEGER N, M\nCF2PY INTENT(OUT) :: B\nCF2PY INTENT(HIDE) :: N\nCF2PY INTENT(HIDE) :: M\n DO 20 I = 2,M-1\n DO 40 J = 2,N-1\n B(I,J) = A(I,J) +\n & (A(I-1,J)+A(I+1,J) +\n & A(I,J-1)+A(I,J+1) )*0.5D0 +\n & (A(I-1,J-1) + A(I-1,J+1) +\n & A(I+1,J-1) + A(I+1,J+1))*0.25D0\n 40 CONTINUE\n 20 CONTINUE\n END\n", "meta": {"hexsha": "fb44343fa25459559de653fd368b825feda861f8", "size": 486, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "doc/source/f2py/code/filter.f", "max_stars_repo_name": "Akhilesh271988/numpy", "max_stars_repo_head_hexsha": "1ab7e8fbf90ac4a81d2ffdde7d78ec464dccb02e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-24T10:16:43.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-24T10:16:43.000Z", "max_issues_repo_path": "doc/source/f2py/code/filter.f", "max_issues_repo_name": "Akhilesh271988/numpy", "max_issues_repo_head_hexsha": "1ab7e8fbf90ac4a81d2ffdde7d78ec464dccb02e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2021-10-07T10:59:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-22T20:06:49.000Z", "max_forks_repo_path": "doc/source/f2py/code/filter.f", "max_forks_repo_name": "Akhilesh271988/numpy", "max_forks_repo_head_hexsha": "1ab7e8fbf90ac4a81d2ffdde7d78ec464dccb02e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-22T11:47:01.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-22T11:47:01.000Z", "avg_line_length": 24.3, "max_line_length": 48, "alphanum_fraction": 0.4259259259, "num_tokens": 209, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026663679976, "lm_q2_score": 0.7279754489059775, "lm_q1q2_score": 0.6677738203318933}} {"text": "C$Procedure LGRESP ( Lagrange interpolation on equally spaced points )\n \n DOUBLE PRECISION FUNCTION LGRESP ( N, FIRST, STEP,\n . YVALS, WORK, X )\n \nC$ Abstract\nC\nC Evaluate a Lagrange interpolating polynomial for a specified\nC set of coordinate pairs whose first components are equally\nC spaced, at a specified abscissa value.\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 INTERPOLATION\nC POLYNOMIAL\nC\nC$ Declarations\n \n INTEGER N\n DOUBLE PRECISION FIRST\n DOUBLE PRECISION STEP\n DOUBLE PRECISION YVALS ( * )\n DOUBLE PRECISION WORK ( * )\n DOUBLE PRECISION X\n \nC$ Brief_I/O\nC\nC Variable I/O Description\nC -------- --- --------------------------------------------------\nC N I Number of points defining the polynomial.\nC FIRST I First abscissa value.\nC STEP I Step size.\nC YVALS I Ordinate values.\nC WORK I-O Work space array.\nC X I Point at which to interpolate the polynomial.\nC\nC The function returns the value at X of the unique polynomial of\nC degree N-1 that fits the points in the plane defined by FIRST,\nC STEP, and YVALS.\nC\nC$ Detailed_Input\nC\nC N is the number of points defining the polynomial.\nC The arrays XVALS and YVALS contain N elements.\nC\nC FIRST,\nC STEP are, respectively, a starting abscissa value and a\nC step size that define the set of abscissa values\nC at which a Lagrange interpolating polynomial is to\nC be defined. The set of abscissa values is\nC\nC FIRST + I * STEP, I = 0, ..., N-1\nC\nC STEP must be non-zero.\nC\nC\nC YVALS is an array of ordinate values that, together with\nC the abscissa values defined by FIRST and STEP,\nC define N ordered pairs belonging to the graph of\nC a function. The set of points\nC\nC ( FIRST + (I-1)*STEP, YVALS(I) )\nC\nC where I ranges from 1 to N, define the Lagrange\nC polynomial used for interpolation.\nC\nC\nC WORK is a work space array of the same dimension as\nC XVALS and YVALS. It is used by this routine as a\nC scratch area to hold intermediate results. \nC\nC\nC X is the abscissa value at which the interpolating\nC polynomial is to be evaluated.\nC\nC$ Detailed_Output\nC\nC The function returns the value at X of the unique polynomial of\nC degree N-1 that fits the points in the plane defined by FIRST,\nC STEP, and YVALS.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC 1) If STEP is zero, the error SPICE(INVALIDSTEPSIZE) will\nC be signaled. The function will return the value 0.D0.\nC\nC 2) If N is less than 1, the error SPICE(INVALIDSIZE) is\nC signaled. The function will return the value 0.D0.\nC\nC 3) This routine does not attempt to ward off or diagnose\nC arithmetic overflows.\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC Given a set of N distinct abscissa values and corresponding\nC ordinate values, there is a unique polynomial of degree N-1,\nC often called the `Lagrange polynomial', that fits the graph\nC defined by these values. The Lagrange polynomial can be used to\nC interpolate the value of a function at a specified point, given a\nC discrete set of values of the function.\nC\nC Users of this routine must choose the number of points to use\nC in their interpolation method. The authors of Reference [1] have\nC this to say on the topic:\nC\nC Unless there is solid evidence that the interpolating function\nC is close in form to the true function f, it is a good idea to\nC be cautious about high-order interpolation. We\nC enthusiastically endorse interpolations with 3 or 4 points, we\nC are perhaps tolerant of 5 or 6; but we rarely go higher than\nC that unless there is quite rigorous monitoring of estimated\nC errors.\nC\nC The same authors offer this warning on the use of the\nC interpolating function for extrapolation:\nC\nC ...the dangers of extrapolation cannot be overemphasized:\nC An interpolating function, which is perforce an extrapolating\nC function, will typically go berserk when the argument x is\nC outside the range of tabulated values by more than the typical\nC spacing of tabulated points.\nC\nC\nC For Lagrange interpolation on unequally spaced abscissa values,\nC see the SPICELIB routine LGRINT.\nC\nC$ Examples\nC\nC 1) Fit a cubic polynomial through the points\nC\nC ( -1, -2 )\nC ( 1, -8 )\nC ( 3, 26 )\nC ( 5, 148 )\nC\nC and evaluate this polynomial at x = 2.\nC\nC\nC PROGRAM TEST_LGRESP\nC\nC DOUBLE PRECISION LGRESP\nC DOUBLE PRECISION ANSWER\nC DOUBLE PRECISION FIRST\nC DOUBLE PRECISION STEP\nC DOUBLE PRECISION YVALS (4)\nC DOUBLE PRECISION WORK (4)\nC INTEGER N\nC\nC N = 4\nC FIRST = -1.D0\nC STEP = 2.D0\nC\nC YVALS(1) = -2.D0\nC YVALS(2) = -8.D0\nC YVALS(3) = 26.D0\nC YVALS(4) = 148.D0\nC\nC ANSWER = LGRESP ( N, FIRST, STEP, YVALS, WORK, 2.D0 )\nC\nC WRITE (*,*) 'ANSWER = ', ANSWER\nC END\nC\nC\nC The returned value of ANSWER should be 1.D0, since the\nC unique cubic polynomial that fits these points is\nC\nC 3 2\nC f(x) = x + 2x - 4x - 7\nC\nC\nC We also could have invoked LGRESP with the reference\nC\nC ANSWER = LGRESP ( N, FIRST, STEP, YVALS, YVALS, 2.D0 )\nC\nC if we wished to; in this case YVALS would have been\nC modified on output.\nC\nC If we had solved the same problem using a negative step,\nC we would have set the elements of YVALS in reverse order,\nC as shown below:\nC\nC FIRST = 5.D0\nC STEP = -2.D0\nC\nC YVALS(1) = 148.D0\nC YVALS(2) = 26.D0\nC YVALS(3) = -8.D0\nC YVALS(4) = -2.D0\nC\nC ANSWER = LGRESP ( N, FIRST, STEP, YVALS, WORK, 2.D0 )\nC\nC The returned value of ANSWER would still be 1.D0.\nC\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Literature_References\nC\nC [1] \"Numerical Recipes---The Art of Scientific Computing\" by\nC William H. Press, Brian P. Flannery, Saul A. Teukolsky,\nC William T. Vetterling (see sections 3.0 and 3.1).\nC\nC$ Author_and_Institution\nC\nC N.J. Bachman (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.1, 10-JAN-2014 (NJB)\nC\nC Updated description of the workspace array: now the array WORK\nC is not described as being allowed to coincide with the input\nC YVALS. Such overlap would be a violation of the ANSI Fortran\nC 77 standard. Corrected several spelling errors in header\nC documentation.\nC \nC- SPICELIB Version 1.0.0, 14-AUG-1993 (NJB)\nC\nC-&\nC\nC$ Index_Entries\nC\nC interpolate function using Lagrange polynomial\nC Lagrange interpolation\nC\nC-&\n \n \nC\nC SPICELIB functions\nC\n LOGICAL RETURN\n \nC\nC Local variables\nC\n DOUBLE PRECISION C1\n DOUBLE PRECISION C2\n DOUBLE PRECISION NEWX\n \n INTEGER I\n INTEGER J\n \n \nC\nC Check in only if an error is detected.\nC\n IF ( RETURN() ) THEN\n LGRESP = 0.D0\n RETURN\n END IF\n \nC\nC No data, no interpolation.\nC\n IF ( N .LT. 1 ) THEN\n \n LGRESP = 0.D0\n \n CALL CHKIN ( 'LGRESP' )\n CALL SETMSG ( 'Array size must be positive; was #.' )\n CALL ERRINT ( '#', N )\n CALL SIGERR ( 'SPICE(INVALIDSIZE)' )\n CALL CHKOUT ( 'LGRESP' )\n RETURN\n \n END IF\n \n \nC\nC The step size must be non-zero.\nC\n IF ( STEP .EQ. 0.D0 ) THEN\n \n LGRESP = 0.D0\n \n CALL CHKIN ( 'LGRESP' )\n CALL SETMSG ( 'Step size was zero.' )\n CALL SIGERR ( 'SPICE(INVALIDSTEPSIZE)' )\n CALL CHKOUT ( 'LGRESP' )\n RETURN\n \n END IF\n \nC\nC We can simplify the interpolation problem by shifting\nC and scaling the abscissa values so that they start at 1\nC and are separated by a unit step. All we need to do is\nC shift and scale X.\nC\n NEWX = ( ( X - FIRST ) / STEP ) + 1.D0\n \nC\nC We're going to compute the value of our interpolating polynomial\nC at X by taking advantage of a recursion relation between\nC Lagrange polynomials of order n+1 and order n. The method works\nC as follows for the case of abscissa values that are not\nC necessarily uniformly spaced:\nC\nC Define\nC\nC P (x)\nC i(i+1)...(i+j)\nC\nC to be the unique Lagrange polynomial that interpolates our\nC input function at the abscissa values\nC\nC x , x , ... x .\nC i i+1 i+j\nC\nC\nC Then we have the recursion relation\nC\nC P (x) =\nC i(i+1)...(i+j)\nC\nC x - x\nC i\nC ----------- * P (x)\nC x - x (i+1)...(i+j)\nC i i+j\nC\nC\nC x - x\nC i+j\nC + ----------- * P (x)\nC x - x i(i+1)...(i+j-1)\nC i i+j\nC\nC\nC Repeated application of this relation allows us to build\nC successive columns, in left-to-right order, of the\nC triangular table\nC\nC\nC P (x)\nC 1\nC P (x)\nC 12\nC P (x) P (x)\nC 2 123\nC P (x)\nC 23 .\nC P (x)\nC . 234 .\nC .\nC . . .\nC .\nC . . P (x)\nC . . 12...N\nC .\nC .\nC\nC .\nC\nC\nC P (x)\nC (N-2)(N-1)N\nC P (x)\nC (N-1)N\nC P (x)\nC N\nC\nC\nC and after N-1 steps arrive at our desired result,\nC\nC\nC P (x).\nC 12...N\nC\nC In the current case, we've arranged the problem so that\nC\nC x = i.\nC i\nC\nC We'll use the scratch array WORK to contain the current column of\nC our interpolation table. To start out with, WORK(I) will contain\nC\nC P (x).\nC I\nC\nC\n DO I = 1, N\n WORK(I) = YVALS(I)\n END DO\n \nC\nC Compute columns 2 through N of the table.\nC\n DO J = 1, N-1\n \n DO I = 1, N-J\n \n C1 = DBLE(I+J) - NEWX\n C2 = NEWX - DBLE(I)\n \n WORK(I) = ( C1 * WORK(I) + C2 * WORK(I+1) ) / DBLE(J)\n \n END DO\n \n END DO\n \nC\nC Our result is sitting in WORK(1) at this point.\nC\n LGRESP = WORK(1)\n \n RETURN\n END\n", "meta": {"hexsha": "291545c33c6f88ddf284713fd0c9d972e8ee7034", "size": 13378, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/lgresp.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/lgresp.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/lgresp.f", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 29.7951002227, "max_line_length": 72, "alphanum_fraction": 0.5361040514, "num_tokens": 3613, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026505426831, "lm_q2_score": 0.7279754607093178, "lm_q1q2_score": 0.6677738196386881}} {"text": " double complex function Lsm1_2m(s,tbar,qsq,msq)\nC this corresponds to (in looptools notation)\nc Lsm1_2m=\nc . s*(t-msq)*D0(0,0,msq,qsq,s,t,0,0,0,msq)\nc . -s*C0(0,s,0,0,0,0)\nc . -(t-qsq)*C0(0,t,qsq,0,0,msq)\nc . -(t-msq)*C0(0,msq,t,0,0,msq)\nC this corresponds to (in normal notation) Pg^2=0,Ps^2=0,Pc^2=m^2\nc Lsm1_2m=\nc . 2*Pg.Ps*(2*Ps.Pc)*D0(Pg,Ps,Pc,0,0,0,msq)\nc . -2*Pg.Ps*C0(Pg,Ps,0,0,0)\nc . +2*Pg.(Ps+Pc)*C0(Pg,Ps+Pc,0,0,msq)\nc . -(2*Ps.Pc)*C0(Ps,Pc,0,0,msq)\n\nC D0(Pg,Ps,Pc,0,0,0,msq)=\nc Lsm1_2m(2*Pg.Ps,2*Pc.Ps,qsq,msq)/4/Pg.Ps/Ps.Pc\nc . +C0(Pg,Ps,0,0,0)/2/Ps.Pc\nc . -C0(Pg,Ps+Pc,0,0,msq)*Pg.(Ps+Pc)/2/Pg.Ps/Ps.Pc\nc . +C0(Ps,Pc,0,0,msq)/2/Pg.Ps\n\n implicit none\n include 'constants.f'\n double precision s,tbar,msq,qsq,ddilog,r,omr\n double complex lnrat,dilogqt,dilogt,dilogq,wlogt,wlogs\nC t=tbar+msq\n r=-(msq-qsq)/tbar\n omr=1d0-r\n wlogt=lnrat(msq-qsq,-tbar)\n if (omr .gt. one) then\n dilogqt=dcmplx(pisqo6-ddilog(r))-wlogt*dcmplx(log(omr))\n else\n dilogqt=dcmplx(ddilog(omr))\n endif\n\n r=(msq-qsq)/msq\n omr=1d0-r\n wlogt=lnrat(msq-qsq,msq)\n if (omr .gt. one) then\n dilogq=dcmplx(pisqo6-ddilog(r))-wlogt*dcmplx(log(omr))\n else\n dilogq=dcmplx(ddilog(omr))\n endif\n\n wlogt=lnrat(-tbar,msq)\n wlogs=lnrat(-s,msq)\n\n r=-tbar/msq\n omr=1d0-r\n if (omr .gt. one) then\n dilogt=dcmplx(pisqo6-ddilog(r))-wlogt*dcmplx(log(omr))\n else\n dilogt=dcmplx(ddilog(omr))\n endif\n\n\n Lsm1_2m=-dcmplx(3d0*pisqo6)+dilogq-2d0*(dilogqt+dilogt)\n . +2d0*wlogt*(wlogs-wlogt)-0.5d0*wlogs**2\n\n return\n end\n", "meta": {"hexsha": "1d7f00a769c9af140f1462c20ebe2afc99e1d661", "size": 1726, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "MCFM-JHUGen/src/Wt/Lsm1_2m.f", "max_stars_repo_name": "tmartini/JHUGen", "max_stars_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-06-08T13:09:28.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-04T19:59:36.000Z", "max_issues_repo_path": "MCFM-JHUGen/src/Wt/Lsm1_2m.f", "max_issues_repo_name": "tmartini/JHUGen", "max_issues_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 64, "max_issues_repo_issues_event_min_datetime": "2015-06-24T15:08:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-25T04:59:32.000Z", "max_forks_repo_path": "MCFM-JHUGen/src/Wt/Lsm1_2m.f", "max_forks_repo_name": "tmartini/JHUGen", "max_forks_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2015-05-04T22:15:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-06T10:04:40.000Z", "avg_line_length": 28.2950819672, "max_line_length": 65, "alphanum_fraction": 0.5654692932, "num_tokens": 853, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109713976399, "lm_q2_score": 0.7025300698514778, "lm_q1q2_score": 0.6676922861235948}} {"text": "!=======================================================================\n! This is part of the 2DECOMP&FFT library\n! \n! 2DECOMP&FFT is a software framework for general-purpose 2D (pencil) \n! decomposition. It also implements a highly scalable distributed\n! three-dimensional Fast Fourier Transform (FFT).\n!\n! Copyright (C) 2009-2011 Ning Li, the Numerical Algorithms Group (NAG)\n!\n!=======================================================================\n\n! A few utility routines to find factors of integer numbers\n\n subroutine findfactor(num, factors, nfact)\n \n implicit none\n\n integer, intent(IN) :: num\n integer, intent(OUT), dimension(*) :: factors\n integer, intent(OUT) :: nfact\n integer :: i, m\n\n ! find the factors <= sqrt(num)\n m = int(sqrt(real(num)))\n nfact = 1\n do i=1,m\n if (num/i*i == num) then\n factors(nfact) = i\n nfact = nfact + 1\n end if\n end do\n nfact = nfact - 1\n\n ! derive those > sqrt(num)\n if (factors(nfact)**2/=num) then\n do i=nfact+1, 2*nfact\n factors(i) = num / factors(2*nfact-i+1)\n end do\n nfact = nfact * 2\n else\n do i=nfact+1, 2*nfact-1\n factors(i) = num / factors(2*nfact-i)\n end do\n nfact = nfact * 2 - 1\n endif\n \n return\n\n end subroutine findfactor\n\n\n subroutine primefactors(num, factors, nfact)\n\n implicit none\n \n integer, intent(IN) :: num\n integer, intent(OUT), dimension(*) :: factors\n integer, intent(INOUT) :: nfact\n\n integer :: i, n\n \n i = 2 \n nfact = 1\n n = num \n do\n if (mod(n,i) == 0) then\n factors(nfact) = i\n nfact = nfact + 1\n n = n / i\n else\n i = i + 1\n end if\n if (n == 1) then\n nfact = nfact - 1\n exit\n end if\n end do\n \n return\n\n end subroutine primefactors\n \n", "meta": {"hexsha": "3e14c3054b53f6ae10bd1661325ba8b3cdde27bd", "size": 1881, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/expand/2decomp/factor.f90", "max_stars_repo_name": "ykawazura/calliope", "max_stars_repo_head_hexsha": "343b72a0930d70332172a5d87a579b0f8dcced66", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2022-02-04T19:27:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T05:37:38.000Z", "max_issues_repo_path": "src/expand/2decomp/factor.f90", "max_issues_repo_name": "ykawazura/calliope", "max_issues_repo_head_hexsha": "343b72a0930d70332172a5d87a579b0f8dcced66", "max_issues_repo_licenses": ["MIT"], "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/expand/2decomp/factor.f90", "max_forks_repo_name": "ykawazura/calliope", "max_forks_repo_head_hexsha": "343b72a0930d70332172a5d87a579b0f8dcced66", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2022-02-03T10:45:48.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-03T10:48:28.000Z", "avg_line_length": 22.6626506024, "max_line_length": 72, "alphanum_fraction": 0.5151515152, "num_tokens": 532, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256591565729, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.6676569360198443}} {"text": "module posterization\n implicit none\n\ncontains\n pure function make_histogram(layer, maximum) result(hist)\n implicit none\n integer, intent(in) :: layer(:, :)\n integer, intent(in) :: maximum\n integer :: hist(0:maximum), i\n hist = 0\n do concurrent(i=0:maximum)\n block\n hist(i) = count(layer == i)\n end block\n end do\n end function make_histogram\n\n pure function to_binary(img, threshold) result(rst)\n implicit none\n integer, intent(in) :: img(:, :, :)\n integer, intent(in) :: threshold\n integer, allocatable :: rst(:, :, :)\n\n rst = img\n where (img(1, :, :) >= threshold)\n rst(1, :, :) = 1\n else where\n rst(1, :, :) = 0\n end where\n end function to_binary\n\n pure function otsu(img, maximum) result(rst)\n implicit none\n integer, intent(in) :: img(:, :, :)\n integer, intent(in) :: maximum\n integer, allocatable :: rst(:, :, :), hist(:)\n integer :: i, th, best_th, rescale_rate\n real :: ave_class1, ave_class2, nums(0:maximum), var, best_var, &\n n_pix_class1, n_pix_class2\n\n hist = make_histogram(img(1, :, :), maximum)\n rescale_rate = size(img)**0.5\n ! nums\u3068thresold_to_var\u3092\u914d\u5217\u306e\u5ba3\u8a00\u6642\u306b\u4ee3\u5165\u3059\u308b\u306e\u306f\u30a8\u30e9\u30fc\u306b\u306a\u308b\n nums = [(real(i), i=0, maximum)]\n best_th = 0\n best_var = -1.0\n\n do concurrent(th=0:maximum)\n block\n n_pix_class1 = sum(hist(:th))/rescale_rate\n n_pix_class2 = sum(hist(th + 1:))/rescale_rate\n\n if (n_pix_class1 == 0) then\n ave_class1 = 0\n else\n ave_class1 = sum(hist(:th)*nums(:th))/n_pix_class1/rescale_rate\n end if\n\n if (n_pix_class2 == 0) then\n ave_class2 = 0\n else\n ave_class2 = sum(hist(th + 1:)*nums(th + 1:))/n_pix_class2/rescale_rate\n end if\n\n var = n_pix_class1*n_pix_class2*((ave_class1 - ave_class2)**2)\n\n if (var > best_var) then\n best_th = th\n best_var = var\n end if\n end block\n end do\n\n rst = to_binary(img, best_th)\n end function otsu\n\n pure function adaptive_threshold(img, maximum, kernel_size) result(rst)\n implicit none\n integer, intent(in) :: img(:, :, :)\n integer, intent(in) :: maximum\n integer, intent(in), optional :: kernel_size\n integer, allocatable :: rst(:, :, :), thresholds(:, :), row(:), column(:)\n integer :: height, width, h, w, img_shape(3), s, dh, dw, i, k_size\n\n if (present(kernel_size)) then\n k_size = kernel_size\n else\n k_size = 15\n end if\n\n img_shape = shape(img)\n height = img_shape(2)\n width = img_shape(3)\n allocate (thresholds(height, width))\n allocate (rst(1, height, width))\n\n do concurrent(w=1:width, h=1:height)\n block\n row = [(i, i=max(1, w - k_size/2), min(w + k_size/2, width))]\n column = [(i, i=max(1, h - k_size/2), min(h + k_size/2, height))]\n s = 0\n do dw = 1, size(row)\n do dh = 1, size(column)\n s = s + img(1, column(dh), row(dw))\n end do\n end do\n thresholds(h, w) = nint(s/real(size(row)*size(column)))\n deallocate (row)\n deallocate (column)\n end block\n end do\n\n where (img(1, :, :) <= thresholds(:, :))\n rst(1, :, :) = 0\n else where\n rst(1, :, :) = 1\n end where\n end function adaptive_threshold\n\n pure function quantize(img, n_split, maximum) result(rst)\n implicit none\n integer, intent(in) :: img(:, :, :)\n integer, intent(in) :: n_split\n integer, intent(in), optional :: maximum\n integer, allocatable :: rst(:, :, :)\n integer :: m\n\n if (present(maximum)) then\n m = maximum\n else\n m = 255\n end if\n\n rst = img/(m/n_split + 1)\n end function quantize\n\n pure function dither(img, maximum) result(rst)\n implicit none\n integer, intent(in) :: img(:, :, :)\n integer, intent(in) :: maximum\n integer, allocatable :: rst(:, :, :)\n integer :: dither_mtx(4, 4)\n integer :: height, width, h, w, h_range(2), w_range(2), dh, dw, img_shape(3)\n integer, allocatable :: targets(:, :)\n\n dither_mtx = reshape([0, 12, 3, 15, &\n 8, 4, 11, 7, &\n 2, 14, 1, 13, &\n 10, 6, 9, 5]*((maximum + 1)/16), shape(dither_mtx))\n img_shape = shape(img)\n height = img_shape(2)\n width = img_shape(3)\n allocate (rst(1, height, width))\n\n do w = 0, ceiling(width/4.0)\n do h = 0, ceiling(height/4.0)\n h_range = [h*4 + 1, min(height, (h + 1)*4)]\n w_range = [w*4 + 1, min(width, (w + 1)*4)]\n\n targets = img(1, h_range(1):h_range(2), w_range(1):w_range(2))\n do concurrent(dh=1:h_range(2) - h_range(1) + 1, dw=1:w_range(2) - w_range(1) + 1)\n block\n if (dither_mtx(dh, dw) > targets(dh, dw)) then\n targets(dh, dw) = 0\n else\n targets(dh, dw) = 1\n end if\n end block\n end do\n rst(1, h_range(1):h_range(2), w_range(1):w_range(2)) = targets\n end do\n end do\n\n end function dither\n\n pure function error_diffusion(img, maximum) result(rst)\n implicit none\n integer, intent(in) :: img(:, :, :)\n integer, intent(in) :: maximum\n integer, allocatable :: rst(:, :, :)\n integer :: height, width, h, w, img_shape(3), quant_error, replace_coords(4, 2), dh, dw, old, new, i\n real :: dither_rates(4)\n\n dither_rates = [7, 3, 5, 1]/16.0\n\n img_shape = shape(img)\n rst = img(1:1, :, :)\n\n do w = 1, img_shape(3)\n do h = 1, img_shape(2)\n old = rst(1, h, w)\n if (rst(1, h, w) >= (nint(maximum/2.0))) then\n rst(1, h, w) = 1\n else\n rst(1, h, w) = 0\n end if\n new = rst(1, h, w)*maximum\n quant_error = old - new\n ! TODO\n ! \u5217\u512a\u5148\u3067\u30eb\u30fc\u30d7\u304c\u56de\u308b\u306e\u3067\u62e1\u6563\u3092\u7e26\u65b9\u5411\u306b\u3057\u3066\u3044\u308b\u306e\u3092\u4fee\u6b63\u3059\u308b\n replace_coords = reshape([[h + 1, h - 1, h, h + 1], [w, w + 1, w + 1, w + 1]], shape(replace_coords))\n do concurrent(i=1:4)\n block\n dh = replace_coords(i, 1)\n dw = replace_coords(i, 2)\n if (dh > 0 .and. dh <= img_shape(2) .and. dw > 0 .and. dw <= img_shape(3)) then\n rst(1, dh, dw) = rst(1, dh, dw) + nint(dither_rates(i)*quant_error)\n end if\n end block\n end do\n end do\n end do\n end function error_diffusion\n\n pure function rgb_to_gray(img) result(rst)\n implicit none\n integer, intent(in) :: img(:, :, :)\n integer, allocatable :: rst(:, :, :)\n integer :: h, w, img_shape(3)\n img_shape = shape(img)\n allocate (rst(1, img_shape(2), img_shape(3)))\n\n do concurrent(h=1:img_shape(2), w=1:img_shape(3))\n rst(1, h, w) = 2989*img(1, h, w) + 5870*img(2, h, w) + 1140*img(3, h, w)\n end do\n rst = nint(rst/10000.0)\n end function rgb_to_gray\nend module posterization\n", "meta": {"hexsha": "c2392ab0756c72cb4558843f562b50bd4e39fa4a", "size": 6765, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "src/posterization.f08", "max_stars_repo_name": "Omochice/image-processing", "max_stars_repo_head_hexsha": "86871aef46de0bc2f59e0b90fb5f5a68474be953", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-03-26T17:27:40.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-28T00:38:15.000Z", "max_issues_repo_path": "src/posterization.f08", "max_issues_repo_name": "Omochice/image-processing", "max_issues_repo_head_hexsha": "86871aef46de0bc2f59e0b90fb5f5a68474be953", "max_issues_repo_licenses": ["MIT"], "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/posterization.f08", "max_forks_repo_name": "Omochice/image-processing", "max_forks_repo_head_hexsha": "86871aef46de0bc2f59e0b90fb5f5a68474be953", "max_forks_repo_licenses": ["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.5414847162, "max_line_length": 109, "alphanum_fraction": 0.5507760532, "num_tokens": 2178, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256631249077, "lm_q2_score": 0.793105941403651, "lm_q1q2_score": 0.6676569350504327}} {"text": "program nbody_parallel\nimplicit none\n integer(kind = 8) :: nsteps\n integer(kind = 8) :: nparticles\n\n real(kind = 8), dimension(:), allocatable :: m\n real(kind = 8), dimension(:), allocatable :: x, y, z\n real(kind = 8), dimension(:), allocatable :: x_tmp, y_tmp, z_tmp\n real(kind = 8), dimension(:), allocatable :: vx, vy, vz\n\n real(kind = 8) :: G\n real(kind = 8) :: dt\n real(kind = 8) :: dx, dy, dz\n real(kind = 8) :: r, a\n real(kind = 8) :: softening\n\n integer(kind = 8) :: n, i, j\n\n character(len = 1024) :: arg\n character(len = 1024) :: param_file\n\n integer :: ios\n\n do i = 1, 5\n call get_command_argument(int(i), arg)\n if (len_trim(arg) == 0) then\n print *, \"Please specify arguments correctly.\" // achar(10)\n print *, \"Usage: nbody
\" &\n // \"\" // achar(10)\n print *, \"PARAMETERS_FILE format:\"\n print *, \" nparticles (on the first line)\"\n print *, \" m x y z vx vy vz (on each line after the first line)\"\n stop\n end if\n\n select case (i)\n case (1)\n read(arg, *) nsteps\n case (2)\n read(arg, *) dt\n case (3)\n read(arg, *) G\n case (4)\n read(arg, *) softening\n case (5)\n read(arg, \"(a)\") param_file\n end select\n end do\n\n open(1, file = param_file, iostat = ios, status = \"old\")\n if (ios /= 0) then\n print *, \"Can't open the PARAMETERS_FILE:\", param_file\n stop\n end if\n\n read(1, *) nparticles\n allocate(m(0:nparticles - 1))\n allocate(x(0:nparticles - 1))\n allocate(y(0:nparticles - 1))\n allocate(z(0:nparticles - 1))\n allocate(x_tmp(0:nparticles - 1))\n allocate(y_tmp(0:nparticles - 1))\n allocate(z_tmp(0:nparticles - 1))\n allocate(vx(0:nparticles - 1))\n allocate(vy(0:nparticles - 1))\n allocate(vz(0:nparticles - 1))\n\n print *, \"Initial parameters:\"\n do i = 0, nparticles - 1\n read(1, *) m(i), x(i), y(i), z(i), vx(i), vy(i), vz(i)\n print *, i, \": m =\", m(i), \"x =\", x(i), \"y =\", y(i), \"z =\", z(i), &\n \"vx =\", vx(i), \"vy =\", vy(i), \"vz =\", vz(i)\n end do\n\n close(1)\n\n print *, \"n =\", 0_8\n do i = 0, nparticles - 1\n print *, i, \":\", x(i), y(i), z(i)\n end do\n\n !$omp parallel private(n, j, dx, dy, dz, r, a)\n do n = 1, nsteps\n !$omp do\n do i = 0, nparticles - 1\n x_tmp(i) = x(i) + vx(i) * dt\n y_tmp(i) = y(i) + vy(i) * dt\n z_tmp(i) = z(i) + vz(i) * dt\n\n do j = 0, nparticles - 1\n dx = x(j) - x(i)\n dy = y(j) - y(i)\n dz = z(j) - z(i)\n\n r = sqrt(dx ** 2 + dy ** 2 + dz ** 2 + softening)\n a = G * m(j) / r ** 3 * dt\n\n vx(i) = vx(i) + a * dx\n vy(i) = vy(i) + a * dy\n vz(i) = vz(i) + a * dz\n end do\n end do\n\n !$omp do\n do i = 0, nparticles - 1\n x(i) = x_tmp(i)\n y(i) = y_tmp(i)\n z(i) = z_tmp(i)\n end do\n\n !$omp master\n print *, \"n =\", n\n do i = 0, nparticles - 1\n print *, i, \":\", x(i), y(i), z(i)\n end do\n !$omp end master\n end do\n !$omp end parallel\n\n deallocate(m)\n deallocate(x)\n deallocate(y)\n deallocate(z)\n deallocate(x_tmp)\n deallocate(y_tmp)\n deallocate(z_tmp)\n deallocate(vx)\n deallocate(vy)\n deallocate(vz)\nend program\n", "meta": {"hexsha": "f5e169a5708ef23ab43163be53cdce06a811e946", "size": 3570, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/nbody_parallel.f90", "max_stars_repo_name": "ucyang/nbody", "max_stars_repo_head_hexsha": "ad3d2ff9753e9db6109bd411cd61e635c1ad7752", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-06-28T10:02:29.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-28T10:02:29.000Z", "max_issues_repo_path": "src/nbody_parallel.f90", "max_issues_repo_name": "ucyang/nbody", "max_issues_repo_head_hexsha": "ad3d2ff9753e9db6109bd411cd61e635c1ad7752", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/nbody_parallel.f90", "max_forks_repo_name": "ucyang/nbody", "max_forks_repo_head_hexsha": "ad3d2ff9753e9db6109bd411cd61e635c1ad7752", "max_forks_repo_licenses": ["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.2519083969, "max_line_length": 76, "alphanum_fraction": 0.4658263305, "num_tokens": 1136, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256631249077, "lm_q2_score": 0.793105941403651, "lm_q1q2_score": 0.6676569350504327}} {"text": "*\n* average3 - Computes the average of three numbers\n*\n* Written by: C. Severance 16Mar92\n*\n* Declare the variables:\n*\n REAL A,B,C,TOT,AVE\n*\n* Prompt the user for the three variables\n*\n PRINT *,'Enter the first number -'\n READ *,A\n PRINT *,'Enter the second number -'\n READ *,B\n PRINT *,'Enter the third number -'\n READ *,C\n*\n* Print the numbers out\n*\n PRINT *,'The numbers are -',A,B,C\n*\n* Calculate the total and average\n*\n TOT = A + B + C\n AVE = TOT / 3.0\n*\n* Print the values out and end the program\n*\n PRINT *,'Total - ',TOT\n PRINT *,'Average - ',AVE\n END\n", "meta": {"hexsha": "bf6bb101a6d40dd68ef5472a2c950e2af64f6e33", "size": 627, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "archive/2000-eecs280/examples/examples.ftn/programs/average3.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/average3.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/average3.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": 19.0, "max_line_length": 50, "alphanum_fraction": 0.5789473684, "num_tokens": 185, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256472515683, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.6676569265779144}} {"text": "!-----------------------------------------------------------------------\r\n! Saturation specific humidity\r\n!-----------------------------------------------------------------------\r\nsubroutine QSAT(water,P,T,Qs)\r\n\r\nuse, intrinsic :: iso_fortran_env, only: dp=>real64\r\n\r\nuse Constants, only : &\r\n eps, &! Ratio of molecular weights of water and dry air\r\n e0, &! Saturation vapour pressure at Tm (Pa)\r\n Tm ! Melting point (K)\r\n\r\nimplicit none\r\n\r\nlogical, intent(in) :: &\r\n water ! Saturation wrt water if TRUE\r\n\r\nreal*8, intent(in) :: &\r\n P, &! Air pressure (Pa)\r\n T ! Temperature (K)\r\n\r\nreal*8, intent(out) :: &\r\n Qs ! Saturation specific humidity\r\n\r\nreal*8 :: &\r\n Tc, &! Temperature (C)\r\n es ! Saturation vapour pressure (Pa)\r\n\r\nTc = T - Tm\r\nif (Tc > 0 .or. water) then\r\n es = e0*exp(17.5043_dp*Tc / (241.3_dp + Tc))\r\nelse\r\n es = e0*exp(22.4422_dp*Tc / (272.186_dp + Tc))\r\nend if\r\nQs = eps*es / P\r\n\r\nend subroutine QSAT\r\n", "meta": {"hexsha": "4bd8ffba170a485d93ab492e1d544d6d033acdf1", "size": 1073, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/src/QSAT.f90", "max_stars_repo_name": "jannefiluren/FSM.jl", "max_stars_repo_head_hexsha": "fc2d50fbaa1538fb5100e6a24c59e8d85bb9a97c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fortran/src/QSAT.f90", "max_issues_repo_name": "jannefiluren/FSM.jl", "max_issues_repo_head_hexsha": "fc2d50fbaa1538fb5100e6a24c59e8d85bb9a97c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/src/QSAT.f90", "max_forks_repo_name": "jannefiluren/FSM.jl", "max_forks_repo_head_hexsha": "fc2d50fbaa1538fb5100e6a24c59e8d85bb9a97c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-02-08T11:09:50.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-08T11:09:50.000Z", "avg_line_length": 28.2368421053, "max_line_length": 73, "alphanum_fraction": 0.4557315937, "num_tokens": 286, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541626630937, "lm_q2_score": 0.7090191214879992, "lm_q1q2_score": 0.6676508071569042}} {"text": "program threebody\r\n\treal(kind=4), parameter :: PI = 4*atan(1.), G = 4.498279e-8\r\n\tinteger,parameter :: npar = 1000,dim = 3\r\n\treal(kind=4),dimension(2) :: M\r\n\treal(kind=4), dimension(npar,dim) :: x,v\r\n\tinteger :: nt, dsnap, np1,np2\r\n\treal :: t,dt\r\n\t! Chunk to be divided between threads\r\n\tinteger,parameter :: chunk = 100\r\n\r\n!\tInput Data\r\n\tcall input_data(x,v,np1,np2,M)\r\n\tv(3:np1+2,2)\t=\tv(3:np1+2,2) + v(1,2)\r\n\tv(np1+3:np1+np2+2,2) =\tv(np1+3:np1+np2+2,2) + v(2,2) \r\n\t\r\n! Simulation Parameters\r\n nt = 5000\r\n dt = 0.1\r\n t = 0\r\n\tdsnap = 20\r\n\r\n! Time-Marching Loop\r\n\tdo n = 1,nt\r\n\t\tif (modulo(n-1,dsnap)==0) then\r\n\t\t\tcall output(x,v,t)\r\n\t\tendif\r\n\t\t\r\n\t\t!$OMP PARALLEL SHARED(x,v) PRIVATE(i,a,r)\r\n \t\t!$OMP DO SCHEDULE(STATIC,CHUNK)\r\n\t\tdo i=1,2+np1+np2\r\n\t\t\tcall leapfrog(x,v,dt)\r\n\t\tenddo\r\n\t\t!$OMP ENDDO\r\n\t\t!$OMP END PARALLEL\r\n\t\t\r\n\t\tt = t+dt\r\n\tend do\t\r\n\r\n\tcall output(x,v,t) ! Output last values\r\n\r\ncontains\r\n!***********************************************************************\r\nsubroutine input_data(x,v,np1,np2,M)\r\n! Initialize Position and Velocity values\r\n\treal(kind=4), dimension(npar,dim), intent(out) :: x,v\r\n\treal(kind=4), dimension(2),intent(out) :: M\r\n\tinteger, intent(out) :: np1,np2\r\n\tinteger :: k \r\n\r\n\topen(312,FILE='body.dat',STATUS=\"OLD\",FORM=\"FORMATTED\",ACTION=\"READ\")\r\n\tread(312,*) x(1,:),v(1,:),M(1)\r\n\tread(312,*) x(2,:),v(2,:),M(2)\r\n\tclose(312)\r\n\r\n\topen(312,FILE='A.dat',STATUS=\"OLD\",FORM=\"FORMATTED\",ACTION=\"READ\")\r\n\tread(312,*) np1\r\n\tdo k=1,np1 \r\n\t\tread(312,*) x(k+2,:),v(k+2,:)\r\n\tenddo\r\n\tclose(312)\r\n\r\n\topen(312,FILE='B.dat',STATUS=\"OLD\",FORM=\"FORMATTED\",ACTION=\"READ\")\r\n\t\tread(312,*) np2\r\n\tdo k = 1,np2 \r\n\t\tread(312,*) x(k+2+np1,:), v(k+2+np1,:)\r\n\tenddo\r\n\tclose(312)\r\n\r\nendsubroutine input_data\r\n!***********************************************************************\r\nsubroutine leapfrog (x,v,dt)\r\n! Leapfrog using Position-Verlet algorithm\r\n real(kind=4), dimension(npar,dim),intent(inout) :: x,v\r\n real(kind=4), intent(in) :: dt\r\n real(kind=4),dimension(dim) :: a\r\n\r\n\tx(i,:) = x(i,:) + 0.5 * dt * v(i,:) \r\n\tcall accel(x,a)\r\n\tv(i,:) = v(i,:) + dt * G * a\r\n\tx(i,:) = x(i,:) + 0.5 * dt * v(i,:)\r\n\t\r\nendsubroutine leapfrog\r\n!***********************************************************************\r\nsubroutine accel(x,a)\r\n! Calculate Gravitation Acceleration based on position\r\n real(kind=4), dimension(npar,dim),intent(in) :: x\r\n real(kind=4), dimension(dim),intent(out) :: a\r\n\treal(kind=4) :: r\r\n\tinteger :: j\r\n\t\r\n\t! Acceleration \r\n\ta = (/0.,0.,0./)\r\n\tdo j = 1,2\r\n\t\tif (i/=j) then\r\n\t\t\tr =\t norm2(x(i,:)-x(j,:)) \t\t \r\n\t\t\ta = a - M(j)*(x(i,:)-x(j,:))/(r**3)\r\n\t\tendif\r\n\tenddo\r\n \r\nendsubroutine accel\r\n!***********************************************************************\r\nsubroutine output(x,v,t)\r\n real(kind=4),dimension(npar,dim),intent(in) :: x,v\r\n real(kind=4),intent(in) :: t\r\n integer :: k, f_handle = 314\r\n character(len=12) :: f_name, num_sfx\r\n\t\r\n write(num_sfx,\"(I5)\") n\r\n\tf_name = 'mc_'//trim(adjustl(num_sfx))//'.dat'\r\n open(f_handle,FILE=trim(f_name),FORM=\"formatted\")\r\n do k = 1,np1+np2+2\r\n\t\twrite(f_handle,FMT=\"(6E20.6)\") x(k,:),v(k,:)\r\n enddo\r\n\tclose(f_handle)\r\n\r\nendsubroutine output\r\n!***********************************************************************\r\nendprogram threebody\r\n", "meta": {"hexsha": "0d2532b2cc29088b54abc94d54762de21b900560", "size": 3272, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "3body.f90", "max_stars_repo_name": "asnayak16/NBody-Simulations", "max_stars_repo_head_hexsha": "2439d97b30094918749347ef175769ec81287101", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "3body.f90", "max_issues_repo_name": "asnayak16/NBody-Simulations", "max_issues_repo_head_hexsha": "2439d97b30094918749347ef175769ec81287101", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "3body.f90", "max_forks_repo_name": "asnayak16/NBody-Simulations", "max_forks_repo_head_hexsha": "2439d97b30094918749347ef175769ec81287101", "max_forks_repo_licenses": ["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.4957983193, "max_line_length": 73, "alphanum_fraction": 0.5210880196, "num_tokens": 1081, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969137, "lm_q2_score": 0.7461389986757758, "lm_q1q2_score": 0.6676373141699941}} {"text": "! 7.16g \u0432 \u0443\u0447\u0435\u0431\u043d\u0438\u043a\u0435\n! \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0432 \u0441\u0442\u043e\u043b\u0431\u0446\u0435 \u0441 \u043d\u043e\u043c\u0435\u0440\u043e\u043c \n\nprogram ex_7_16g\n implicit none\n\n integer :: x, y, Out = 0, In = 0, i = 0, maxCol = 0, min = 0\n integer, allocatable :: B(:,:)\n character(*), parameter :: output_file = \"output.txt\", &\n input_file = \"../data/input.txt\"\n\n open (file=input_file, newunit=In)\n read(In, *) x, y\n allocate(B(x,y))\n read(In, *) (B(i,:), i = 1, y)\n close (In)\n\n\n maxCol = maxloc(sum(B, 1), 1)\n min = minval(B(:,maxCol))\n\n open (file=output_file, newunit=Out)\n write(Out, *) min\n close (Out)\nend program ex_7_16g\n", "meta": {"hexsha": "57cea49891174c571572d4da2f0b2febada00c13", "size": 650, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ex_7_16g/src/ex_7_16g.f90", "max_stars_repo_name": "taxnuke/algorithm-exercises", "max_stars_repo_head_hexsha": "5dae749093489d0e66a74bd8bc3b2040496449bf", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-06-01T06:06:44.000Z", "max_stars_repo_stars_event_max_datetime": "2017-06-01T09:16:17.000Z", "max_issues_repo_path": "ex_7_16g/src/ex_7_16g.f90", "max_issues_repo_name": "taxnuke/algorithm-exercises", "max_issues_repo_head_hexsha": "5dae749093489d0e66a74bd8bc3b2040496449bf", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ex_7_16g/src/ex_7_16g.f90", "max_forks_repo_name": "taxnuke/algorithm-exercises", "max_forks_repo_head_hexsha": "5dae749093489d0e66a74bd8bc3b2040496449bf", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.0, "max_line_length": 80, "alphanum_fraction": 0.5215384615, "num_tokens": 214, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894745194283, "lm_q2_score": 0.7461389873857264, "lm_q1q2_score": 0.6676373124413324}} {"text": "!Program for moving mesh in 1D FDM\r\n!Romit Maulik\r\n!Refer introductory chapter of Adaptive Moving Mesh Methods - Springer\r\n!Burgers equation with Dirichlet BCs\r\n\r\nprogram mm1d\r\nimplicit none\r\n\r\ninteger :: nx,i,t,nt,isol,iform\r\nreal*8,dimension(:),allocatable :: u,x,dxdt,utemp\r\nreal*8 :: dt,xl,dx,pi,x0\r\n\r\ncommon/nlform/iform\r\n\r\npi = 4.0d0*datan(1.0d0)\r\ndt = 1d-3\r\nnt = nint(1d3)\r\nnx = 41\r\nxl = 2.0d0*pi\r\ndx = xl/dfloat(nx)\r\nisol = 2\t\t\t!Euler FWD or RK3\r\niform = 1\t\t\t![1] - Central or [2] - QUICK for Nonlinear term\r\n\r\nallocate(u(1:nx)) !Not periodic BC\r\nallocate(x(1:nx))\r\n\r\n!Setting up initial condition\r\nx0 = -pi\r\ndo i = 1,nx\r\n x(i) = x0+dx\r\n u(i) = -dsin(x(i))\r\n x0 = x0+dx\r\nend do\r\n\r\nopen(8,file='Initial_Plot.plt')\r\nwrite(8,*) 'variables =\"x\",\"f(x)\"'\r\nwrite(8,*)'zone f=point i=',nx,''\r\n\tdo i=1,nx\r\n\twrite(8,*) x(i),u(i)\r\n\tend do\r\nclose(8)\r\n\r\n!Calculating mesh speed - dxdt\r\nallocate(dxdt(1:nx))\r\nallocate(utemp(1:nx))\r\n\r\nif (isol==1) then !forward Euler\r\n\r\nopen(8,file='MM_Plot.plt')\r\ndo t = 1,nt\r\n\r\ncall meshspeed(u,x,dxdt,nx)\r\n\r\ncall vel_update(u,x,dxdt,nx,utemp)\r\n\r\n!New mesh distribution\r\ndo i = 1,nx\r\n x(i) = x(i)+dxdt(i)*dt\r\nend do\r\n\r\n!New velocity distribution\r\ndo i = 1,nx\r\n u(i) = u(i)+utemp(i)*dt\r\nend do\r\n\r\n\r\n!if (mod(t,nt/10)==0) then\r\n\r\nwrite(8,*)'variables =\"xnew\",\"f(x)\"'\r\nwrite(8,*)'zone f=point i=',nx,',t=\"case',t,'\"'\r\n\tdo i=1,nx\r\n\twrite(8,*) x(i),u(i)\r\n\tend do\r\n\r\n!end if\r\n\r\nend do\r\n\r\nclose(8)\r\n\r\nelse if (isol==2) then!Rk3\r\n\r\n \r\nopen(8,file='MM_Plot.plt')\r\ncall rk3(u,x,dxdt,nx,nt,dt)\r\nclose(8)\r\n\r\n\r\n\r\nend if\r\n\r\n\r\n\r\nend\r\n\r\n\r\n\r\n!--------------------------------------------------------------------------------------------\r\n!--------------------------------------------------------------------------------------------\r\n!subroutine for rk3 time integration\r\n!--------------------------------------------------------------------------------------------\r\n!--------------------------------------------------------------------------------------------\r\nsubroutine rk3(u,x,dxdt,nx,nt,dt)\r\nimplicit none\r\n\r\ninteger :: nx,t,nt,i\r\nreal*8 :: dt\r\nreal*8,dimension(1:nx) :: u,x,dxdt\r\nreal*8,dimension(1:nx) :: u1,u2,utemp,x1,x2\r\n\r\ndo i = 1,nx\r\nu1(i) = u(i)\r\nu2(i) = u(i)\r\nutemp(i) = u(i)\r\nx1(i) = x(i)\r\nx2(i) = x(i)\r\nend do\r\n\r\n\r\ndo t = 1,nt\r\n\r\n\t!Stage 1\r\n\tcall meshspeed(u,x,dxdt,nx)\r\n\r\n call vel_update(u,x,dxdt,nx,utemp)\r\n\t\r\n\tdo i = 1,nx\r\n u1(i) = u(i) + dt*utemp(i)\r\n\tend do\r\n\r\n \r\n\t!New stage mesh distribution\r\n do i = 1,nx\r\n \tx1(i) = x(i)+dxdt(i)*dt\r\n end do\r\n\r\n\t!Stage 2\r\n\tcall meshspeed(u1,x1,dxdt,nx)\r\n\r\n call vel_update(u1,x1,dxdt,nx,utemp)\r\n\r\n\tdo i = 1,nx\r\n u2(i) = 0.75d0*u(i) + 0.25d0*u1(i) + 0.25*utemp(i)*dt \r\n \r\n\tx2(i) = 0.75d0*x(i) + 0.25d0*x1(i) + 0.25*dt*dxdt(i)\r\n end do\r\n\r\n !stage 3\r\n\r\n\tcall meshspeed(u2,x2,dxdt,nx)\r\n\r\n call vel_update(u2,x2,dxdt,nx,utemp)\r\n\t\r\n\tdo i = 1,nx\r\n u(i) = 1.0d0/3.0d0*u(i) + 2.0d0/3.0d0*u2(i) + 2.0d0/3.0d0*utemp(i)*dt \r\n \r\n x(i) = 1.0d0/3.0d0*x(i) + 2.0d0/3.0d0*x2(i) + 2.0d0/3.0d0*dxdt(i)*dt\r\n end do\r\n\r\n\r\n!if (mod(t,nt/10)==0) then\r\n\r\nwrite(8,*)'variables =\"xnew\",\"f(x)\"'\r\nwrite(8,*)'zone f=point i=',nx,',t=\"case',t,'\"'\r\n\tdo i=1,nx\r\n\twrite(8,*) x(i),u(i)\r\n\tend do\r\n\r\n!end if\r\n\r\n\r\nend do\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nreturn\r\nend\r\n\r\n\r\n\r\n\r\n\r\n!--------------------------------------------------------------------------------------------\r\n!--------------------------------------------------------------------------------------------\r\n!subroutine to calculate meshspeed call meshspeed(u,x,dxdt,nx)\r\n!--------------------------------------------------------------------------------------------\r\n!--------------------------------------------------------------------------------------------\r\nsubroutine meshspeed(u,x,dxdt,nx)\r\nimplicit none\r\n\r\ninteger :: i,j,nx\r\nreal*8,dimension(1:nx) :: dxdt,u,x\r\nreal*8,dimension(:),allocatable :: uxx,rho\r\nreal*8 :: alphah,sum,tau,dxi\r\n\r\n\r\nallocate(uxx(1:nx))\r\n\r\nuxx(1) \t= \t2.0d0*((x(2)-x(1))*(u(3)-u(1))-(x(3)-x(1))*(u(2)-u(1)))/((x(3)-x(1))*(x(2)-x(1))*(x(3)-x(2)))\r\nuxx(nx) = \t2.0d0*((x(nx-1)-x(nx))*(u(nx-2)-u(nx))-(x(nx-2)-x(nx))*(u(nx-1)-u(nx)))&\r\n\t\t\t&/((x(nx-2)-x(nx))*(x(nx-1)-x(nx))*(x(nx-2)-x(nx-1)))\r\n\r\ndo i = 2,nx-1\r\n uxx(i) = 2.0d0/(x(i+1)-x(i-1))*((u(i+1)-u(i))/(x(i+1)-x(i))-(u(i)-u(i-1))/(x(i)-x(i-1)))\r\nend do\r\n\r\nsum = 0.0d0\r\n\r\ndo j = 2,nx\r\n sum = sum + (0.5d0*(x(j)-x(j-1))*(dabs(uxx(j))**(2.0d0/3.0d0)+dabs(uxx(j-1))**(2.0d0/3.0d0)))**3 \r\nend do\r\n\r\nalphah = max(1,sum)\r\n\r\nallocate(rho(1:nx))\r\n\r\ndo i = 1,nx\r\n rho(i) = (1+1/alphah*dabs(uxx(i))**2)**(1.0d0/3.0d0)\r\nend do\r\n\r\n!Smoothing rho\r\n\r\ndo i = 2,nx-1\r\n rho(i) = 0.25d0*rho(i-1)+0.5d0*rho(i)+0.25d0*rho(i+1)\r\nend do\r\n\r\nrho(1) = 0.5d0*rho(1)+0.5d0*rho(2)\r\nrho(nx) = 0.5d0*rho(nx-1)+0.5d0*rho(nx)\r\n\r\ndxdt(1) = 0.0d0\r\ndxdt(nx) = 0.0d0\r\n\r\ntau = 0.01d0\r\ndxi = 1.0d0/dfloat(nx-1)\r\n\r\ndo i = 2,nx-1\r\n dxdt(i) = 1.0d0/(rho(i)*tau*dxi**2)*((rho(i+1)+rho(i))/2.0d0*(x(i+1)-x(i))-(rho(i)+rho(i-1))/2.0d0*(x(i)-x(i-1)))\r\nend do\r\n\r\ndeallocate(rho)\r\n\r\nreturn\r\nend\r\n\r\n\r\n\r\n\r\n!--------------------------------------------------------------------------------------------\r\n!--------------------------------------------------------------------------------------------\r\n!subroutine to calculate new velocty\r\n!--------------------------------------------------------------------------------------------\r\n!--------------------------------------------------------------------------------------------\r\nsubroutine vel_update(u,x,dxdt,nx,v)\r\nimplicit none\r\n\r\ninteger :: nx,i,iform\r\nreal*8,dimension(1:nx) :: u,x,dxdt,v\r\nreal*8 :: eps,ta,tb,tc,td\r\nreal*8,dimension(:),allocatable :: rhs,nl\r\n\r\ncommon/nlform/iform\r\n\r\n!eps = 0.0001d0\r\neps = 0.0d0\r\n\r\nallocate(rhs(1:nx))\r\nallocate(nl(1:nx))\r\n\r\nif (iform==1) then\r\n\r\ndo i = 2,nx-1\r\n ta = (u(i+1)-u(i))/(x(i+1)-x(i))\r\n tb = (u(i)-u(i-1))/(x(i)-x(i-1)) \r\n tc = 0.5d0*(u(i+1)**2-u(i-1)**2)/(x(i+1)-x(i-1))\r\n rhs(i) = 2*eps/(x(i+1)-x(i-1))*(ta-tb)-tc\r\nend do\r\n\r\ndo i = 2,nx-1\r\n nl(i) = -(u(i+1)-u(i-1))/(x(i+1)-x(i-1))*dxdt(i)\r\nend do\r\n\r\n\r\ndo i = 2,nx-1\r\n v(i) = rhs(i)- nl(i)\r\nend do\r\n\r\nv(1) = 0.0d0\r\nv(nx) = 0.0d0\r\n\r\nelse if (iform==2) then\r\n\r\ndo i = 2,nx-1\r\n\tif (u(i)>0.0d0) then\r\n\t\tta = (u(i+1)-u(i))/(x(i+1)-x(i))\r\n\t\ttb = (u(i)-u(i-1))/(x(i)-x(i-1))\r\n td = (0.75d0*u(i-1)+3.0d0/8.0d0*u(i)-1.0/8.0d0*u(i-2))**2\r\n td = td - (0.75d0*u(i)+3.0d0/8.0d0*u(i+1)-1.0/8.0d0*u(i-1))**2!Ref Wikipedia East face - West Face\r\n\t\ttc = 0.5d0*(2.0d0*td)/(x(i+1)-x(i-1))\t\t\t!Multiply 2 due to cell face approx\r\n\t\trhs(i) = 2*eps/(x(i+1)-x(i-1))*(ta-tb)+tc\r\n\telse\r\n\t\tta = (u(i+1)-u(i))/(x(i+1)-x(i))\r\n\t\ttb = (u(i)-u(i-1))/(x(i)-x(i-1))\r\n td = (0.75d0*u(i)+3.0d0/8.0d0*u(i-1)-1.0/8.0d0*u(i+1))**2\r\n td = td - (0.75d0*u(i+1)+3.0d0/8.0d0*u(i)-1.0/8.0d0*u(i+2))**2\r\n\t\ttc = 0.5d0*(2.0d0*td)/(x(i+1)-x(i-1))\t\t\t!Multiply 2 due to cell face approx\r\n\t\trhs(i) = 2*eps/(x(i+1)-x(i-1))*(ta-tb)+tc\r\n end if\r\nend do\r\n\r\ndo i = 2,nx-1\r\n nl(i) = -(u(i+1)-u(i-1))/(x(i+1)-x(i-1))*dxdt(i)\r\nend do\r\n\r\n\r\ndo i = 2,nx-1\r\n v(i) = rhs(i)- nl(i)\r\nend do\r\n\r\nv(1) = 0.0d0\r\nv(nx) = 0.0d0\r\n\r\n\r\nend if\r\n\r\n\r\ndeallocate(rhs,nl)\r\n\r\nreturn\r\nend", "meta": {"hexsha": "34d58a26cabacdb928dc4fc8c7dae4448cae197a", "size": 7062, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Misc_Fortran_C/Moving_Mesh_1D/Moving_Mesh_Attempt.f90", "max_stars_repo_name": "Romit-Maulik/Tutorials-Demos-Practice", "max_stars_repo_head_hexsha": "a58ddc819f24a16f7059e63d7f201fc2cd23e03a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2020-09-02T14:46:07.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-29T15:27:05.000Z", "max_issues_repo_path": "Misc_Fortran_C/Moving_Mesh_1D/Moving_Mesh_Attempt.f90", "max_issues_repo_name": "omersan/Practice", "max_issues_repo_head_hexsha": "77eecdc2a202e6b333123cfd92e7db6dc0eea021", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 18, "max_issues_repo_issues_event_min_datetime": "2020-11-13T18:49:33.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-12T00:54:43.000Z", "max_forks_repo_path": "Misc_Fortran_C/Moving_Mesh_1D/Moving_Mesh_Attempt.f90", "max_forks_repo_name": "omersan/Practice", "max_forks_repo_head_hexsha": "77eecdc2a202e6b333123cfd92e7db6dc0eea021", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-09-25T23:57:00.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-18T08:15:34.000Z", "avg_line_length": 20.9554896142, "max_line_length": 116, "alphanum_fraction": 0.4488813367, "num_tokens": 2857, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789452074398, "lm_q2_score": 0.7461389986757758, "lm_q1q2_score": 0.6676373057964374}} {"text": "C$Procedure DVCRSS ( Derivative of Vector cross product )\n \n SUBROUTINE DVCRSS ( S1, S2, SOUT )\n \nC$ Abstract\nC\nC Compute the cross product of two 3-dimensional vectors\nC and the derivative of this cross product.\nC\nC$ Disclaimer\nC\nC THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE\nC CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.\nC GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE\nC ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE\nC PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED \"AS-IS\"\nC TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY\nC WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A\nC PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC\nC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE\nC SOFTWARE AND RELATED MATERIALS, HOWEVER USED.\nC\nC IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA\nC BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT\nC LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,\nC INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,\nC REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE\nC REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.\nC\nC RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF\nC THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY\nC CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE\nC ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.\nC\nC$ Required_Reading\nC\nC None.\nC\nC$ Keywords\nC\nC VECTOR\nC DERIVATIVE\nC\nC$ Declarations\n \n \n DOUBLE PRECISION S1 ( 6 )\n DOUBLE PRECISION S2 ( 6 )\n DOUBLE PRECISION SOUT ( 6 )\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC S1 I Left hand state for cross product and derivative.\nC S2 I Right hand state for cross product and derivative.\nC SOUT O State associated with cross product of positions.\nC\nC$ Detailed_Input\nC\nC S1 This may be any state vector. Typically, this\nC might represent the apparent state of a planet or the\nC Sun, which defines the orientation of axes of\nC some coordinate system.\nC\nC S2 A state vector.\nC\nC$ Detailed_Output\nC\nC SOUT This variable represents the state associated with the\nC cross product of the position components of S1 and S2.\nC In other words, if S1 = (P1,V1) and S2 = (P2,V2) then\nC SOUT is ( P1xP2, d/dt{ P1xP2 } ).\nC\nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC Error free.\nC\nC 1) If S1 and S2 are large in magnitude (taken together,\nC their magnitude surpasses the limit allowed by the\nC computer) then it may be possible to generate a\nC floating point overflow from an intermediate\nC computation even though the actual cross product and\nC derivative may be well within the range of double\nC precision numbers.\nC\nC DVCRSS does NOT check the magnitude of S1 or S2 to\nC insure that overflow will not occur.\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC DVCRSS calculates the three-dimensional cross product of two\nC vectors and the derivative of that cross product according to\nC the definition.\nC\nC$ Examples\nC\nC S1 S2 SOUT\nC -----------------------------------------------------------------\nC (0, 1, 0, 1, 0, 0) ( 1, 0, 0, 1, 0, 0) (0, 0, -1, 0, 0, -1 )\nC (5, 5, 5, 1, 0, 0) (-1, -1, -1, 2, 0, 0) (0, 0, 0, 0, 11,-11 )\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC W.L. Taber (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.1, 22-APR-2010 (NJB)\nC\nC Header correction: assertions that the output\nC can overwrite the input have been removed.\nC\nC- SPICELIB Version 1.0.0, 15-JUN-1995 (WLT)\nC\nC\nC-&\n \n \nC$ Index_Entries\nC\nC Compute the derivative of a cross product\nC\nC-&\nC\n \nC\nC Local Variables\nC\n DOUBLE PRECISION VTEMP ( 3 )\n DOUBLE PRECISION DVTMP1 ( 3 )\n DOUBLE PRECISION DVTMP2 ( 3 )\n \nC\nC Calculate the cross product of S1 and S2, store it in VTEMP.\nC\n CALL VCRSS ( S1(1), S2(1), VTEMP )\n \nC\nC Calculate the two components of the derivative of S1 x S2.\nC\n CALL VCRSS ( S1(4), S2(1), DVTMP1 )\n CALL VCRSS ( S1(1), S2(4), DVTMP2 )\n \nC\nC Put all of the pieces into SOUT.\nC\n CALL VEQU ( VTEMP, SOUT(1) )\n CALL VADD ( DVTMP1, DVTMP2, SOUT(4) )\n \n RETURN\n END\n \n \n", "meta": {"hexsha": "4a2da1fc1b27e2c46b5d154cad87f79db06f9281", "size": 4774, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/dvcrss.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/dvcrss.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/dvcrss.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.918128655, "max_line_length": 71, "alphanum_fraction": 0.6346878928, "num_tokens": 1443, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8947894520743981, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6676373057964374}} {"text": "\n! Last change: PND 6 Sep 2007 5:56 pm\n\nmodule parameters\n implicit none\n REAL, PARAMETER \t:: b = 0.99, d = 0.025, a = 0.36\n REAL, PARAMETER \t:: klb = 0.01, inc = 0.025, kub = 45.0\n INTEGER, PARAMETER \t:: length_grid_k = (kub-klb)/inc+1 \n INTEGER, PARAMETER:: no_states = 2.\n REAL, PARAMETER:: stay_good_prob = 0.977, stay_bad_prob = 0.926 ! for the transitions\n REAL, PARAMETER \t:: toler = 1.e-4\t\t\t\t\t\t! Numerical tolerance\nend module\n\n! ============================================================================================\n! ============================================================================================\n\nPROGRAM HW2NonStochastic\n REAL \t\t\t:: total, dist\n REAL, DIMENSION(2) \t\t:: elapsed\n \n call solution\n call etime(elapsed, total)\n \n \n PRINT*,'--------------------------------------------------'\n PRINT*,'total time elapsed =',elapsed, total\n PRINT*,'--------------------------------------------------'\n \n \nEND PROGRAM HW2NonStochastic\n\n! ============================================================================================\nsubroutine solution\n USE parameters\n IMPLICIT NONE\n \n REAL, dimension(:), allocatable\t\t:: Kgrid, g_k\n REAL, dimension(:,:), allocatable:: value, value_new\n INTEGER, DIMENSION(:,:),allocatable :: PFUNC\n REAL :: Zgrid(no_states) = (/1.25, 0.2/)\n REAL :: Pi(no_states, no_states)\n REAL, dimension(:,:,:), allocatable :: vtmp\n INTEGER:: iter, index_k, index_kp, index_z\n REAL:: diffg, diffb, diff, k, kp, c, z\n \n INTEGER:: i = 1\n \n allocate(value(length_grid_k, no_states))\n allocate(value_new(length_grid_k, no_states))\n allocate(PFUNC(length_grid_k, no_states))\n allocate(vtmp(length_grid_k, length_grid_k, no_states))\n allocate(Kgrid(length_grid_k))\n allocate(g_k, mold = Kgrid)\n do while (i <= length_grid_k) !do loop for assigning capital grid K\n Kgrid(i) = klb + (i-1)*inc\n !write(*,*) i, Kgrid(i)\n i = i+1\n end do\n \n \n Pi(1, :) = (/stay_good_prob, 1-stay_bad_prob/)\n Pi(2, :) = (/1-stay_good_prob, stay_bad_prob/)\n iter = 1\n diff = 1000.d0\n value(:,1)= 0.*Kgrid\t\t!Initial Value guess\n value(:, 2) = 0.*Kgrid\n do while (diff >= toler)\n !$omp parallel do default(shared) private(index_k, index_z, k, vtmp, z, kp, c)\n do index_k = 1, length_grid_k\t\t\t\t! Capital grid\n k = Kgrid(index_k)\n vtmp(index_k, :,:) = -1.0e-16\n do index_z = 1, no_states\n z = Zgrid(index_z)\n do index_kp = 1, length_grid_k\n kp = Kgrid(index_kp)\n c = k**a+(1.-d)*k-kp\n \n if (c > 0.) then\n vtmp(index_k, index_kp, index_z) = log(c)+b*(Pi(index_z, 1)*value(index_kp, 1)+Pi(index_z, 2)*value(index_kp, 2))\n endif\n \n enddo\n value_new(index_k, index_z) = MAXVAL(vtmp(index_k, :,index_z))\n PFUNC(index_k, index_z) = MAXLOC(vtmp(index_k, :, index_z), 1)\n g_k(index_k) \t = Kgrid(MAXLOC(vtmp(index_k, :, index_z), 1))\n enddo\n enddo\n !$omp end parallel do\n diffg = maxval(abs(value_new(:,1)-value(:,1)))/ABS(value_new(length_grid_k, 1))\n diffb = maxval(abs(value_new(:,2)-value(:,2)))/ABS(value_new(length_grid_k, 2))\n diff = max(abs(diffg), abs(diffb))\n value = value_new\n iter = iter+1\n \n enddo\n \n print *, ' '\n print *, 'Successfully converged with sup_norm ', diff, 'with number of iteration:', iter\n !print *, g_k\n \n !CALL vcDrawCurve(d, Kgrid, g_k, length_grid_k)\n \n \n open (UNIT = 1, FILE='VFUNC',STATUS='replace')\n do index_k = 1, length_grid_k\n WRITE(UNIT = 1, FMT=*) value(index_k, :)\n end do\n close (UNIT = 1)\n\n open (UNIT = 2, FILE='AGRID',STATUS='replace')\n do index_k = 1, length_grid_k\n WRITE(UNIT = 2, FMT=*) Kgrid(index_k)\n end do\n close (UNIT = 2)\n\n open (UNIT = 3, FILE='PFUNC',STATUS='replace')\n do index_k = 1, length_grid_k\n WRITE(UNIT = 3, FMT=*) PFUNC(index_k,:)\n end do\n close (UNIT = 3)\n \nend subroutine\n", "meta": {"hexsha": "424117c7deaefd6f5b4407e065d825f7d6a8f080", "size": 4435, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "ps2.f95", "max_stars_repo_name": "hkchekc/EconComputations", "max_stars_repo_head_hexsha": "83f804b6f3b9d1b18a242389a64e6e9b970168b0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ps2.f95", "max_issues_repo_name": "hkchekc/EconComputations", "max_issues_repo_head_hexsha": "83f804b6f3b9d1b18a242389a64e6e9b970168b0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-10-05T08:42:15.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-05T08:42:15.000Z", "max_forks_repo_path": "ps2.f95", "max_forks_repo_name": "hkchekc/EconComputations", "max_forks_repo_head_hexsha": "83f804b6f3b9d1b18a242389a64e6e9b970168b0", "max_forks_repo_licenses": ["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.0569105691, "max_line_length": 129, "alphanum_fraction": 0.4919954904, "num_tokens": 1219, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789457685656, "lm_q2_score": 0.746138993030751, "lm_q1q2_score": 0.6676373049321072}} {"text": " subroutine setupq ( x, dx, y, npoint, v, qty )\nc from * a practical guide to splines * by c. de boor\nc to be called in s m o o t h\nc put\tdelx = x(.+1) - x(.) into v(.,4),\nc put\tthe three bands of q-transp*d\tinto v(.,1-3), and\nc put the three bands of (d*q)-transp*(d*q) at and above the diagonal\nc into v(.,5-7) .\nc here, q is the tridiagonal matrix of order (npoint-2,npoint)\nc with general row 1/delx(i) , -1/delx(i) - 1/delx(i+1) , 1/delx(i+1)\nc and\t d is the diagonal matrix with general row dx(i) .\n integer npoint,\ti,npm1\n real dx(npoint),qty(npoint),v(npoint,7),x(npoint),y(npoint),\n *\t\t\t\t\t\t\t diff, prev\n npm1 = npoint - 1\n v(1,4) = x(2) - x(1)\n do 11 i=2,npm1\n\t v(i,4) = x(i+1) - x(i)\n\t v(i,1) = dx(i-1)/v(i-1,4)\n\t v(i,2) = - dx(i)/v(i,4) - dx(i)/v(i-1,4)\n 11\t v(i,3) = dx(i+1)/v(i,4)\n v(npoint,1) = 0.\n do 12 i=2,npm1\n 12\t v(i,5) = v(i,1)**2 + v(i,2)**2 + v(i,3)**2\n if (npm1 .lt. 3)\t\t\tgo to 14\n do 13 i=3,npm1\n 13\t v(i-1,6) = v(i-1,2)*v(i,1) + v(i-1,3)*v(i,2)\n 14 v(npm1,6) = 0.\n if (npm1 .lt. 4)\t\t\tgo to 16\n do 15 i=4,npm1\n 15\t v(i-2,7) = v(i-2,3)*v(i,1)\n 16 v(npm1-1,7) = 0.\n v(npm1,7) = 0.\nconstruct q-transp. * y in qty.\n prev = (y(2) - y(1))/v(1,4)\n do 21 i=2,npm1\n\t diff = (y(i+1)-y(i))/v(i,4)\n\t qty(i) = diff - prev\n 21\t prev = diff\n\t\t\t\t\treturn\n end\n", "meta": {"hexsha": "dea21a3b5a18dd8bf1219f616f083ba97bbc6e10", "size": 1403, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iraf.v2161/math/deboor/setupq.f", "max_stars_repo_name": "ysBach/irafdocgen", "max_stars_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:19:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T16:48:42.000Z", "max_issues_repo_path": "math/deboor/setupq.f", "max_issues_repo_name": "kirxkirx/iraf", "max_issues_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-30T13:48:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-02T19:40:25.000Z", "max_forks_repo_path": "math/deboor/setupq.f", "max_forks_repo_name": "kirxkirx/iraf", "max_forks_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.2195121951, "max_line_length": 72, "alphanum_fraction": 0.5017818959, "num_tokens": 675, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789468908171, "lm_q2_score": 0.7461389817407017, "lm_q1q2_score": 0.6676373032034459}} {"text": "!\n!*******************************************************************************\n!\nsubroutine Legendre_expand(jx_max,xval,Ang_Dist,L_max,Ang_L)\n!\n!*******************************************************************************\n!\n! Discussion:\n!\n! FORTRAN 90 subroutine to find the coefficients for an expaansion into\n! Legendre polynomials\n!\n! Ang_Dist(x) = Sum Ang_L(L)*poly(L,1,alpha, beta,x)\n!\n! Ang_L(L) = int(-1,1) Ang_Dist(x)*poly(L,1,alpha,beta,x)*dx*(2L+1)/2.\n!\n! Note, input array is interpolated to be put onto the grid for the \n! Gauss-Legendre integration points\n!\n! Dependencies:\n!\n! Modules:\n!\n! None\n!\n! Subroutines:\n!\n! None\n!\n! External functions:\n!\n! real(kind=8) :: Poly\n! real(kind=8) :: interp\n!\n! MPI routines:\n!\n! None\n!\n! Licensing:\n!\n! SPDX-License-Identifier: MIT \n!\n! Date:\n!\n! 11 May 2021\n!\n! Author:\n!\n! Erich Ormand, LLNL\n!\n!*******************************************************************************\n!\n implicit none \n integer(kind=4), intent(in) :: jx_max\n real(kind=8), intent(in) :: xval(jx_max),Ang_Dist(jx_max)\n integer(kind=4), intent(in) :: L_max\n real(kind=8), intent(out) :: Ang_L(0:L_max)\n!------------------------------------------------------\n integer(kind=4) :: L, LL_max\n real(kind=8) :: sum, value\n real(kind=8) :: alpha, beta\n real(kind=8) :: xnorm\n! integer(kind=4) :: jx\n integer(kind=4) :: n\n integer(kind=4) :: n_gleg\n real(kind=8), allocatable :: x_gleg(:), w_gleg(:)\n!------------- External function calls\n real(kind=8) :: Poly\n real(kind=8) :: interp\n!------------------------------------------------------\n!\n!---- Set up data for Legendre integration\n!---- Can't have more polynomials than number of data points in Ang_Dist\n!---- The array Ang_Dist is assumed to be on a fixed grid\n!---- with values xval(jx) and fixed spacing dx with dx = xval(2) - xval(1)\n!---- First number of computed coefficients is LL_max\n!---- set LL_max = L_max, but if L_max > jx_max, adjust\n!---- Then the same for number of Gauss-Legendre points. Must be <= jx_max\n!---- In general, preferably less\n! \n LL_max = L_max\n if(L_max > jx_max)LL_max = jx_max - 1\n n_gleg = jx_max \n\n Ang_L(0) = 0.5d0\n if(LL_max == 0)return ! All done, just one value and must be 0.5\n \n if(.not.allocated(x_gleg))allocate(x_gleg(n_gleg))\n if(.not.allocated(w_gleg))allocate(w_gleg(n_gleg))\n\n alpha = 0.0d0\n beta = 0.0d0\n call gauss_quad(n_gleg, 1, alpha, beta, x_gleg, w_gleg)\n\n xnorm = 0.0d0\n do n = 1, n_gleg\n value = interp(x_gleg(n),jx_max,xval,Ang_Dist)\n xnorm = xnorm + value*w_gleg(n)\n end do\n\n Ang_L(0:LL_max) = 0.0d0\n\n do L = 0, L_max\n sum = 0.0d0\n do n = 1, n_gleg\n value = interp(x_gleg(n),jx_max,xval,Ang_Dist)\n sum = sum + value*w_gleg(n)*poly(L,1,alpha,beta,x_gleg(n))\n end do\n Ang_L(L) = sum*0.5d0*(2.0d0*real(L,kind=8)+1.0d0)/xnorm\n end do\n if(allocated(x_gleg))deallocate(x_gleg)\n if(allocated(w_gleg))deallocate(w_gleg)\n return\nend subroutine Legendre_expand\n", "meta": {"hexsha": "abd55ce4e8edd6dc343e650a850255d284c99ef0", "size": 3105, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Src/Legendre-expand.f90", "max_stars_repo_name": "LLNL/Yet-Another-Hauser-Feshbach-Code", "max_stars_repo_head_hexsha": "18af2fea77d0263986648b057c06bd96f87ae8e0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-11-05T23:37:51.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-05T23:37:53.000Z", "max_issues_repo_path": "Src/Legendre-expand.f90", "max_issues_repo_name": "LLNL/Yet-Another-Hauser-Feshbach-Code", "max_issues_repo_head_hexsha": "18af2fea77d0263986648b057c06bd96f87ae8e0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Src/Legendre-expand.f90", "max_forks_repo_name": "LLNL/Yet-Another-Hauser-Feshbach-Code", "max_forks_repo_head_hexsha": "18af2fea77d0263986648b057c06bd96f87ae8e0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-11-05T23:38:28.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-10T21:34:37.000Z", "avg_line_length": 27.0, "max_line_length": 80, "alphanum_fraction": 0.5504025765, "num_tokens": 982, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206765295399, "lm_q2_score": 0.7401743735019595, "lm_q1q2_score": 0.6675785716987156}} {"text": " subroutine graeff(a,b)\nc\nc -- Graeffe Root-Squaring Method --\nc -- to Find Roots of a Polynomial --\nc\n b(1)=a(11)**2\n b(2)=2.0*a(9)*a(11)-a(10)**2\n b(3)=2.0*a(7)*a(11)-2.0*a(8)*a(10)+a(9)**2\n b(4)=2.0*a(5)*a(11)-2.0*a(6)*a(10)+2.0*a(7)*a(9)-a(8)**2\n b(5)=2.0*a(3)*a(11)-2.0*a(4)*a(10)+2.0*a(5)*a(9)-2.0*a(6)*a(8)+a(7\n . )**2\n b(6)=2.0*a(1)*a(11)-2.0*a(2)*a(10)+2.0*a(3)*a(9)-2.0*a(4)*a(8)+2.0\n . *a(5)*a(7)-a(6)**2\n b(7)=2.0*a(1)*a(9)-2.0*a(2)*a(8)+2.0*a(3)*a(7)-2.0*a(4)*a(6)+a(5)\n . **2\n b(8)=2.0*a(1)*a(7)-2.0*a(2)*a(6)+2.0*a(3)*a(5)-a(4)**2\n b(9)=2.0*a(1)*a(5)-2.0*a(2)*a(4)+a(3)**2\n b(10)=2.0*a(1)*a(3)-a(2)**2\n b(11)=a(1)**2\n return\n end\n", "meta": {"hexsha": "085ce786867fc5517f0e41e33a4038503cebb816", "size": 740, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "maxima/src/maxima/share/contrib/gentran/test/graeffe.f", "max_stars_repo_name": "nilqed/spadlib", "max_stars_repo_head_hexsha": "d317f6abdeff4fedc24231a9a39c51c3121f3475", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-03-09T21:31:09.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-09T21:31:09.000Z", "max_issues_repo_path": "maxima/src/maxima/share/contrib/gentran/test/graeffe.f", "max_issues_repo_name": "nilqed/spadlib", "max_issues_repo_head_hexsha": "d317f6abdeff4fedc24231a9a39c51c3121f3475", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "maxima/src/maxima/share/contrib/gentran/test/graeffe.f", "max_forks_repo_name": "nilqed/spadlib", "max_forks_repo_head_hexsha": "d317f6abdeff4fedc24231a9a39c51c3121f3475", "max_forks_repo_licenses": ["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.6363636364, "max_line_length": 72, "alphanum_fraction": 0.4027027027, "num_tokens": 450, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.901920681802153, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6675785600933704}} {"text": "\tfunction dcsqrt(z1)\n\tdouble complex dcsqrt, z1, z2\n\tdouble precision dummy(2), a, b, c\n\tequivalence (a,z2,dummy(1)), (b,dummy(2))\n\n\tz2 = z1\n\tc = dcabs(z2)\n\tc = dsqrt(c)\n\tb = datan2(b, a)/2.0d0\n\ta = c*dcos(b)\n\tb = c*dsin(b)\n\tdcsqrt = z2\n\treturn\n\tend\n", "meta": {"hexsha": "580a44cfa52a608ff53961088f28dbeed472fb63", "size": 250, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "fort/rt1/dcsqrt.f", "max_stars_repo_name": "alexchenfeng/UNIXV6", "max_stars_repo_head_hexsha": "7eabcf07e61df13e868d785087ab24353110f626", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-04-13T04:29:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-13T04:29:34.000Z", "max_issues_repo_path": "fort/rt1/dcsqrt.f", "max_issues_repo_name": "alexchenfeng/UNIXV6", "max_issues_repo_head_hexsha": "7eabcf07e61df13e868d785087ab24353110f626", "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": "fort/rt1/dcsqrt.f", "max_forks_repo_name": "alexchenfeng/UNIXV6", "max_forks_repo_head_hexsha": "7eabcf07e61df13e868d785087ab24353110f626", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.6666666667, "max_line_length": 42, "alphanum_fraction": 0.612, "num_tokens": 111, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206738932334, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6675785594087237}} {"text": "*DECK ZSQRT\n SUBROUTINE ZSQRT (AR, AI, BR, BI)\nC***BEGIN PROLOGUE ZSQRT\nC***SUBSIDIARY\nC***PURPOSE Subsidiary to ZBESH, ZBESI, ZBESJ, ZBESK, ZBESY, ZAIRY and\nC ZBIRY\nC***LIBRARY SLATEC\nC***TYPE ALL (ZSQRT-A)\nC***AUTHOR Amos, D. E., (SNL)\nC***DESCRIPTION\nC\nC DOUBLE PRECISION COMPLEX SQUARE ROOT, B=CSQRT(A)\nC\nC***SEE ALSO ZAIRY, ZBESH, ZBESI, ZBESJ, ZBESK, ZBESY, ZBIRY\nC***ROUTINES CALLED ZABS\nC***REVISION HISTORY (YYMMDD)\nC 830501 DATE WRITTEN\nC 910415 Prologue converted to Version 4.0 format. (BAB)\nC***END PROLOGUE ZSQRT\n DOUBLE PRECISION AR, AI, BR, BI, ZM, DTHETA, DPI, DRT\n DOUBLE PRECISION ZABS\n EXTERNAL ZABS\n DATA DRT , DPI / 7.071067811865475244008443621D-1,\n 1 3.141592653589793238462643383D+0/\nC***FIRST EXECUTABLE STATEMENT ZSQRT\n ZM = ZABS(AR,AI)\n ZM = SQRT(ZM)\n IF (AR.EQ.0.0D+0) GO TO 10\n IF (AI.EQ.0.0D+0) GO TO 20\n DTHETA = DATAN(AI/AR)\n IF (DTHETA.LE.0.0D+0) GO TO 40\n IF (AR.LT.0.0D+0) DTHETA = DTHETA - DPI\n GO TO 50\n 10 IF (AI.GT.0.0D+0) GO TO 60\n IF (AI.LT.0.0D+0) GO TO 70\n BR = 0.0D+0\n BI = 0.0D+0\n RETURN\n 20 IF (AR.GT.0.0D+0) GO TO 30\n BR = 0.0D+0\n BI = SQRT(ABS(AR))\n RETURN\n 30 BR = SQRT(AR)\n BI = 0.0D+0\n RETURN\n 40 IF (AR.LT.0.0D+0) DTHETA = DTHETA + DPI\n 50 DTHETA = DTHETA*0.5D+0\n BR = ZM*COS(DTHETA)\n BI = ZM*SIN(DTHETA)\n RETURN\n 60 BR = ZM*DRT\n BI = ZM*DRT\n RETURN\n 70 BR = ZM*DRT\n BI = -ZM*DRT\n RETURN\n END\n", "meta": {"hexsha": "177917154ba4b32a1a6e1b81817e73105d7f4b9a", "size": 1567, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "COMPDIRS/debug.BIN.mac/bessel/zsqrt.f", "max_stars_repo_name": "danhax/V1-temp", "max_stars_repo_head_hexsha": "efbcba25dbd8550e62f1a83ce8c2328a30659466", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2016-02-08T05:46:15.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-23T12:27:36.000Z", "max_issues_repo_path": "COMPDIRS/debug.BIN.mac/bessel/zsqrt.f", "max_issues_repo_name": "danhax/V1-temp", "max_issues_repo_head_hexsha": "efbcba25dbd8550e62f1a83ce8c2328a30659466", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 18, "max_issues_repo_issues_event_min_datetime": "2015-12-21T19:20:36.000Z", "max_issues_repo_issues_event_max_datetime": "2020-11-20T06:22:29.000Z", "max_forks_repo_path": "COMPDIRS/debug.BIN.mac/bessel/zsqrt.f", "max_forks_repo_name": "danhax/V1-temp", "max_forks_repo_head_hexsha": "efbcba25dbd8550e62f1a83ce8c2328a30659466", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-03-04T17:35:46.000Z", "max_forks_repo_forks_event_max_datetime": "2018-03-02T03:11:23.000Z", "avg_line_length": 27.0172413793, "max_line_length": 71, "alphanum_fraction": 0.5781748564, "num_tokens": 712, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206659843131, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6675785535547437}} {"text": "program ddeabm_example\n\nuse ddeabm_module\nuse ddeabm_kinds\n\nimplicit none\n\nreal(wp),parameter :: mu = 398600.436233_wp !! Earth gravitational parameter (km^3/s^2)\ninteger,parameter :: n = 6 !! number of state variables\n\ntype(ddeabm_class) :: s\nreal(wp),dimension(n) :: x0,x\nreal(wp) :: t0,tf,t\ninteger :: idid\n\ncall s%initialize(n,maxnum=10000,df=twobody,rtol=[1.0e-12_wp],atol=[1.0e-12_wp])\n\n!initial conditions:\nx0 = [10000.0_wp,10000.0_wp,10000.0_wp,& !initial state [r,v] (km,km/s)\n 1.0_wp,2.0_wp,3.0_wp]\nt0 = 0.0_wp !initial time (sec)\ntf = 1000.0_wp !final time (sec)\n\nwrite(*,'(A/,*(F15.6/))') 'Initial time: ',t0\nwrite(*,'(A/,*(F15.6/))') 'Initial state:',x0\nt = t0\nx = x0\ncall s%integrate(t,x,tf,idid=idid)\nwrite(*,'(A/,*(F15.6/))') 'Final time: ',t\nwrite(*,'(A/,*(F15.6/))') 'Final state:',x\n\ncontains\n\n subroutine twobody(me,t,x,xdot)\n\n !! derivative routine for two-body orbit propagation\n\n implicit none\n\n class(ddeabm_class),intent(inout) :: me\n real(wp),intent(in) :: t\n real(wp),dimension(:),intent(in) :: x\n real(wp),dimension(:),intent(out) :: xdot\n\n real(wp),dimension(3) :: r,v,a_grav\n real(wp) :: rmag\n\n r = x(1:3)\n v = x(4:6)\n rmag = norm2(r)\n a_grav = -mu/rmag**3 * r ! acceleration due to gravity\n\n xdot(1:3) = v\n xdot(4:6) = a_grav\n\n end subroutine twobody\n\nend program ddeabm_example\n", "meta": {"hexsha": "6f4b576cb75a4dd4eed09af23f8882c03d1f3225", "size": 1464, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/ddeabm_example.f90", "max_stars_repo_name": "jacobwilliams/ddeabm", "max_stars_repo_head_hexsha": "1b15af73d8c426417def0df71c2cd3db80b102c5", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2015-12-29T05:00:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T21:03:00.000Z", "max_issues_repo_path": "src/tests/ddeabm_example.f90", "max_issues_repo_name": "sausage02/Adams-Bashford", "max_issues_repo_head_hexsha": "845596da0c70554e942cbcd7acdc9139267867e5", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 16, "max_issues_repo_issues_event_min_datetime": "2015-12-21T21:59:21.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-16T07:06:15.000Z", "max_forks_repo_path": "src/tests/ddeabm_example.f90", "max_forks_repo_name": "sausage02/Adams-Bashford", "max_forks_repo_head_hexsha": "845596da0c70554e942cbcd7acdc9139267867e5", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2015-02-12T13:28:44.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-12T09:18:36.000Z", "avg_line_length": 24.813559322, "max_line_length": 87, "alphanum_fraction": 0.5922131148, "num_tokens": 523, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511506439708, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6675578211766052}} {"text": " PROGRAM xhunt\r\nC driver for routine hunt\r\n INTEGER N\r\n PARAMETER(N=100)\r\n INTEGER i,j,ji\r\n REAL x,xx(N)\r\nC create array to be searched\r\n do 11 i=1,N\r\n xx(i)=exp(i/20.0)-74.0\r\n11 continue\r\n write(*,*) 'Result of: j=0 indicates x too small'\r\n write(*,*) ' j=100 indicates x too large'\r\n write(*,'(t7,a7,t17,a5,t25,a1,t32,a5,t42,a7)') 'locate:',\r\n * 'guess','j','xx(j)','xx(j+1)'\r\nC perform test\r\n do 12 i=1,19\r\n x=-100.0+200.0*i/20.0\r\nC trial parameter\r\n ji=5*i\r\n j=ji\r\nC begin search\r\n call hunt(xx,N,x,j)\r\n if (j.eq.0) then\r\n write(*,'(1x,f12.6,2i6,a12,f12.6)') x,ji,j,\r\n * 'lower lim',xx(j+1)\r\n else if (j.eq.N) then\r\n write(*,'(1x,f12.6,2i6,f12.6,a12)') x,ji,j,\r\n * xx(j),'upper lim'\r\n else\r\n write(*,'(1x,f12.6,2i6,2f12.6)') x,ji,j,xx(j),xx(j+1)\r\n endif\r\n12 continue\r\n END\r\n", "meta": {"hexsha": "d204fbd0cffad47d6644960eaf7477711ac451b1", "size": 995, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xhunt.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xhunt.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xhunt.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.2647058824, "max_line_length": 64, "alphanum_fraction": 0.4663316583, "num_tokens": 360, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6675578183087965}} {"text": " SUBROUTINE ZPOLZ(A,NDEG,Z,H,IERR)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc>> 1996-04-27 ZPOLZ Krogh Changes to use .C. and C%%.\nc>> 1996-03-30 ZPOLZ Krogh Added external statement, removed \"!...\"\nC>> 1995-01-18 ZPOLZ Krogh More M77CON for conversion to C.\nC>> 1995-11-17 ZPOLZ Krogh Added M77CON statements for conversion to C\nC>> 1995-11-17 ZPOLZ Krogh Converted SFTRAN to Fortran 77.\nc>> 1992-05-11 CLL IERR was not being set when N = 0 or 1. Fixed this.\nC>> 1989-10-20 CLL Delcared all variables.\nC>> 1987-02-25 ZPOLZ Lawson Initial code.\nc--Z Replaces \"?\": ?POLZ, ?QUO\nC--D (Type) Replaces \"?\": ?COMQR\nc++ Default NO_COMPLEX = .C. | (.N. == 'D')\nc++ Default COMPLEX = ~NO_COMPLEX\nC ------------------------------------------------------------------\nC\nC In the discussion below, the notation A([*,],k} should be interpreted\nc as the complex number A(k) if A is declared complex, and should be\nc interpreted as the complex number A(1,k) + i * A(2,k) if A is not\nc declared to be of type complex. Similar statements apply for Z(k).\nC Given complex coefficients A([*,[1),...,A([*,]NDEG+1) this\nC subr computes the NDEG roots of the polynomial\nC A([*,]1)*X**NDEG + ... + A([*,]NDEG+1)\nC storing the roots as complex numbers in the array Z( ).\nC Require NDEG .ge. 1 and A([*,]1) .ne. 0.\nC\nC ------------------------------------------------------------------\nC\nC Argument Definitions\nC --------------------\nC\nC A( ) (In) Contains the complex coefficients of a polynomial\nC high order coefficient first, with A([*,]1).ne.0. The\nC real and imaginary parts of the Jth coefficient must\nC be provided in A([*],J). The contents of this array will\nC not be modified by the subroutine.\nC\nC NDEG (In) Degree of the polynomial.\nC\nC Z( ) (Out) Contains the polynomial roots stored as complex\nC numbers. The real and imaginary parts of the Jth root\nC will be stored in Z([*,]J).\nC\nC H( ) (Scratch) Array of work space.\nC\nC IERR (Out) Error flag. Set by the subroutine to 0 on normal\nC termination. Set to -1 if A([*,]1)=0. Set to -2 if NDEG\nC .le. 0. Set to J > 0 if the iteration count limit\nC has been exceeded and roots 1 through J have not been\nC determined.\nC\nC ------------------------------------------------------------------\nC C.L.Lawson & S.Y.Chan, JPL, June 3,1986.\nC ------------------------------------------------------------------\n EXTERNAL I1MACH\n INTEGER I, IERR, I1MACH, J, NDEG, N\n DOUBLE PRECISION B2, C, C95, F, G, H(NDEG,NDEG,2)\n DOUBLE PRECISION ONE, R, BASE, S, ZERO\n LOGICAL MORE,FIRST\n PARAMETER(ZERO=0.D0, ONE=1.D0, C95=.95D0)\nc++ CODE for COMPLEX is inactive\nC COMPLEX A(NDEG+1),TEMP,Z(NDEG)\nc++ CODE for NO_COMPLEX is active\n DOUBLE PRECISION A(2,NDEG+1), TEMP(2), Z(2,NDEG)\nc++ END\nC\n SAVE FIRST,BASE,B2\nC\n DATA FIRST /.TRUE./\nC ------------------------------------------------------------------\nC\n IF (FIRST) THEN\nC\nC Set BASE = machine dependent parameter specifying the base\nC of the machine floating point representation.\nC\n FIRST = .FALSE.\n BASE = I1MACH(10)\n B2 = BASE * BASE\n END IF\nC\n IF (NDEG .LE. 0) THEN\n IERR = -2\n CALL ERMSG('ZPOLZ',IERR,0,'NDEG .LE. 0','.')\n RETURN\n END IF\nC\nc++ CODE for COMPLEX is inactive\nc IF (A(1) .EQ. CMPLX(ZERO, ZERO)) THEN\nc++ CODE for NO_COMPLEX is active\n IF (A(1,1) .EQ. ZERO .AND. A(2,1) .EQ. ZERO) THEN\nc++ END\n IERR = -1\n CALL ERMSG('ZPOLZ',IERR,0,'A(*,1) .EQ. ZERO','.')\n RETURN\n END IF\nC\n N = NDEG\n IERR = 0\nC\nC Build first row of companion matrix.\nc\n DO 20 I = 2,N+1\nc++ CODE for COMPLEX is inactive\nC TEMP = -(A(I)/A(1))\nC H(1,I-1,1) = REAL(TEMP)\nC H(1,I-1,2) = AIMAG(TEMP)\nc++ CODE for NO_COMPLEX is active\n CALL ZQUO(A(1,I),A(1,1),TEMP)\n H(1,I-1,1) = -TEMP(1)\n H(1,I-1,2) = -TEMP(2)\nc++ END\n 20 CONTINUE\nC\nC Extract any exact zero roots and set N = degree of\nC remaining polynomial.\nC\n DO 30 J = NDEG,1,-1\nc++ CODE for COMPLEX is inactive\nC IF (H(1,J,1).NE.ZERO .OR. H(1,J,2).NE.ZERO) go to 40\nC Z(J) = ZERO\nc++ CODE for NO_COMPLEX is active\n IF (H(1,J,1).NE.ZERO .OR. H(1,J,2).NE.ZERO) GO TO 40\n Z(1,J) = ZERO\n Z(2,J) = ZERO\nc++ END\n N = N - 1\n 30 CONTINUE\n 40 CONTINUE\nC\nC Special for N = 0 or 1.\nC\n IF (N .EQ. 0) RETURN\n IF (N .EQ. 1) THEN\nc++ CODE for COMPLEX is inactive\nC Z(1) = CMPLX(H(1,1,1),H(1,1,2))\nc++ CODE for NO_COMPLEX is active\n Z(1,1) = H(1,1,1)\n Z(2,1) = H(1,1,2)\nc++ END\n RETURN\n END IF\nC\nC Build rows 2 thru N of the companion matrix.\nC\n DO 80 I = 2,N\n DO 60 J = 1,N\n IF (J .EQ. I-1) THEN\n H(I,J,1) = ONE\n H(I,J,2) = ZERO\n ELSE\n H(I,J,1) = ZERO\n H(I,J,2) = ZERO\n END IF\n 60 CONTINUE\n 80 CONTINUE\nC\nC ***************** BALANCE THE MATRIX ***********************\nC\nC This is an adaption of the EISPACK subroutine BALANC to\nC the special case of a complex companion matrix. The EISPACK\nC BALANCE is a translation of the ALGOL procedure BALANCE,\nC NUM. MATH. 13, 293-304(1969) by Parlett and Reinsch.\nC HANDBOOK FOR AUTO. COMP., VOL.II-LINEAR ALGEBRA, 315-326(1971).\nC\nC ********** ITERATIVE LOOP FOR NORM REDUCTION **********\n 100 CONTINUE\n MORE = .FALSE.\n DO 200 I = 1, N\nC Compute R = sum of magnitudes in row I skipping diagonal.\nC C = sum of magnitudes in col I skipping diagonal.\n IF (I .EQ. 1) THEN\n R = ABS(H(1,2,1)) + ABS(H(1,2,2))\n DO 120 J = 3,N\n R = R + ABS(H(1,J,1)) + ABS(H(1,J,2))\n 120 CONTINUE\n C = ABS(H(2,1,1)) + ABS(H(2,1,2))\n ELSE\n R = ABS(H(I,I-1,1)) + ABS(H(I,I-1,2))\n C = ABS(H(1,I,1)) + ABS(H(1,I,2))\n IF (I .NE. N) THEN\n C = C + ABS(H(I+1,I,1)) + ABS(H(I+1,I,2))\n END IF\n END IF\nC\nC Determine column scale factor, F.\nC\n G = R / BASE\n F = ONE\n S = C + R\n 140 IF (C .LT. G) THEN\n F = F * BASE\n C = C * B2\n GO TO 140\n END IF\n G = R * BASE\n 160 IF (C .GE. G) THEN\n F = F / BASE\n C = C / B2\n GO TO 160\n END IF\nC\nC Will the factor F have a significant effect ?\nC\n IF ((C + R) / F .LT. C95 * S) THEN\nC\nC Yes, so do the scaling.\nC\n G = ONE / F\n MORE = .TRUE.\nC\nC Scale Row I\nC\n IF (I .EQ. 1) THEN\n DO 180 J = 1,N\n H(1,J,1) = H(1,J,1)*G\n H(1,J,2) = H(1,J,2)*G\n 180 CONTINUE\n ELSE\n H(I,I-1,1) = H(I,I-1,1)*G\n H(I,I-1,2) = H(I,I-1,2)*G\n END IF\nC\nC Scale Column I\nC\n H(1,I,1) = H(1,I,1) * F\n H(1,I,2) = H(1,I,2) * F\n IF (I .NE. N) THEN\n H(I+1,I,1) = H(I+1,I,1) * F\n H(I+1,I,2) = H(I+1,I,2) * F\n END IF\nC\n END IF\n 200 CONTINUE\n IF (MORE) GO TO 100\nC\n CALL DCOMQR(NDEG,N,1,N,H(1,1,1),H(1,1,2),Z,IERR)\nC\n IF (IERR .NE. 0) THEN\n CALL ERMSG('ZPOLZ',IERR,0,'Convergence failure','.')\n END IF\n RETURN\n END\n", "meta": {"hexsha": "7a4e656b6fc8800e258129a442ec36d3c0bada3f", "size": 7694, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/zpolz.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/zpolz.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/zpolz.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": 31.2764227642, "max_line_length": 72, "alphanum_fraction": 0.5033792566, "num_tokens": 2625, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6675578183087965}} {"text": "MODULE FUN_xyROTATE\n!!#### PURPOSE\n!! Rotate a point in polar coordinates about the origin in R^2.\n\n!!#### EXTERNAL KINDS\nUSE KND_IntrinsicTypes,ONLY: KIND_Rsp,KIND_Rdp !!((01-A-KND_IntrinsicTypes.f90))\n\n!!#### EXTERNAL PARAMETERS\nUSE PAR_Constants_Rsp,ONLY: c_0_Rsp => c_0 , c_1_Rsp => c_1 !!((02-A-PAR_Constants_Rsp.f90))\nUSE PAR_Constants_Rdp,ONLY: c_0_Rdp => c_0 , c_1_Rdp => c_1 !!((02-A-PAR_Constants_Rdp.f90))\n\n!!#### EXTERNAL PROCEDURES\nUSE FUN_xyNORM !!((03-A-FUN_xyNORM.f90))\nUSE FUN_xyDOT !!((03-A-FUN_xyDOT.f90))\n\n!!#### DEFAULT IMPLICIT\nIMPLICIT NONE\n\n!!#### DEFAULT ACCESS\nPRIVATE\n\n!!#### PROCEDURE OVERLOADING\nINTERFACE xyROTATE_V\n MODULE PROCEDURE xyROTATE_V_Rsp\n MODULE PROCEDURE xyROTATE_V_Rdp\nEND INTERFACE\n\nINTERFACE xyROTATE_U\n MODULE PROCEDURE xyROTATE_U_Rsp\n MODULE PROCEDURE xyROTATE_U_Rdp\nEND INTERFACE\n\nINTERFACE xyROTATE_Px\n MODULE PROCEDURE xyROTATE_Px_Rsp\n MODULE PROCEDURE xyROTATE_Px_Rdp\nEND INTERFACE\n\n\n!!#### PUBLIC ACCESS LIST\nPUBLIC :: xyROTATE_V\nPUBLIC :: xyROTATE_U\nPUBLIC :: xyROTATE_Px\n\n\nCONTAINS\n\n\nPURE FUNCTION xyROTATE_V_Rsp( V , dt ) RESULT( xyV )\n!!#### LOCAL KINDS\nUSE KND_IntrinsicTypes,ONLY: KIND_R=>KIND_Rsp !!((01-A-KND_IntrinsicTypes.f90))\n!!#### LOCAL PARAMETERS\nREAL(KIND_R),PARAMETER :: c_0 = c_0_Rsp\nREAL(KIND_R),PARAMETER :: c_1 = c_1_Rsp\nINCLUDE \"05-B-FUN_xyROTATE_V.f90.hdr\"\n!!--begin--\nINCLUDE \"05-B-FUN_xyROTATE_V.f90.bdy\"\n!!--end--\nEND FUNCTION\n\nPURE FUNCTION xyROTATE_V_Rdp( V , dt ) RESULT( xyV )\n!!#### LOCAL KINDS\nUSE KND_IntrinsicTypes,ONLY: KIND_R=>KIND_Rdp !!((01-A-KND_IntrinsicTypes.f90))\n!!#### LOCAL PARAMETERS\nREAL(KIND_R),PARAMETER :: c_0 = c_0_Rdp\nREAL(KIND_R),PARAMETER :: c_1 = c_1_Rdp\nINCLUDE \"05-B-FUN_xyROTATE_V.f90.hdr\"\n!!--begin--\nINCLUDE \"05-B-FUN_xyROTATE_V.f90.bdy\"\n!!--end--\nEND FUNCTION\n\n\nPURE FUNCTION xyROTATE_U_Rsp( U , dt ) RESULT( xyU )\n!!#### LOCAL KINDS\nUSE KND_IntrinsicTypes,ONLY: KIND_R=>KIND_Rsp !!((01-A-KND_IntrinsicTypes.f90))\n!!#### LOCAL PARAMETERS\nREAL(KIND_R),PARAMETER :: c_0 = c_0_Rsp\nREAL(KIND_R),PARAMETER :: c_1 = c_1_Rsp\nINCLUDE \"05-B-FUN_xyROTATE_U.f90.hdr\"\n!!--begin--\nINCLUDE \"05-B-FUN_xyROTATE_U.f90.bdy\"\n!!--end--\nEND FUNCTION\n\nPURE FUNCTION xyROTATE_U_Rdp( U , dt ) RESULT( xyU )\n!!#### LOCAL KINDS\nUSE KND_IntrinsicTypes,ONLY: KIND_R=>KIND_Rdp !!((01-A-KND_IntrinsicTypes.f90))\n!!#### LOCAL PARAMETERS\nREAL(KIND_R),PARAMETER :: c_0 = c_0_Rdp\nREAL(KIND_R),PARAMETER :: c_1 = c_1_Rdp\nINCLUDE \"05-B-FUN_xyROTATE_U.f90.hdr\"\n!!--begin--\nINCLUDE \"05-B-FUN_xyROTATE_U.f90.bdy\"\n!!--end--\nEND FUNCTION\n\n\nPURE FUNCTION xyROTATE_Px_Rsp( N , Px , dt ) RESULT( xyPx )\n!!#### LOCAL KINDS\nUSE KND_IntrinsicTypes,ONLY: KIND_R=>KIND_Rsp !!((01-A-KND_IntrinsicTypes.f90))\n!!#### LOCAL PARAMETERS\nREAL(KIND_R),PARAMETER :: c_0 = c_0_Rsp\nREAL(KIND_R),PARAMETER :: c_1 = c_1_Rsp\nINCLUDE \"05-B-FUN_xyROTATE_Px.f90.hdr\"\n!!--begin--\nINCLUDE \"05-B-FUN_xyROTATE_Px.f90.bdy\"\n!!--end--\nEND FUNCTION\n\nPURE FUNCTION xyROTATE_Px_Rdp( N , Px , dt ) RESULT( xyPx )\n!!#### LOCAL KINDS\nUSE KND_IntrinsicTypes,ONLY: KIND_R=>KIND_Rdp !!((01-A-KND_IntrinsicTypes.f90))\n!!#### LOCAL PARAMETERS\nREAL(KIND_R),PARAMETER :: c_0 = c_0_Rdp\nREAL(KIND_R),PARAMETER :: c_1 = c_1_Rdp\nINCLUDE \"05-B-FUN_xyROTATE_Px.f90.hdr\"\n!!--begin--\nINCLUDE \"05-B-FUN_xyROTATE_Px.f90.bdy\"\n!!--end--\nEND FUNCTION\n\n\nEND MODULE\n", "meta": {"hexsha": "8a7daecc0205798dcd1069e0b538cc39b331f0e0", "size": 3466, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/05-B-FUN_xyROTATE.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/05-B-FUN_xyROTATE.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/05-B-FUN_xyROTATE.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": 27.9516129032, "max_line_length": 93, "alphanum_fraction": 0.6884016157, "num_tokens": 1160, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.7799928900257127, "lm_q1q2_score": 0.6675578095548136}} {"text": "subroutine seq_saxpy(x, y, n, a)\n real :: a, x(n), y(n)\n integer :: n, i\n\n do i = 1, n\n y(i) = a * x(i) + y(i)\n enddo\nend subroutine seq_saxpy\n\nsubroutine par_saxpy(x, y, n, a)\n real :: a, x(n), y(n)\n integer :: n, i\n\n do concurrent (i = 1: n) \n y(i) = a * x(i) + y(i)\n enddo \nend subroutine par_saxpy\n\nsubroutine acc_saxpy(x, y, n, a)\n real :: a, x(n), y(n)\n integer :: n, i \n\n !$acc parallel loop copy(x, y)\n do i = 1, n\n y(i) = a * x(i) + y(i)\n enddo \nend subroutine acc_saxpy\n\nprogram main\n implicit none\n integer i, n\n real, allocatable :: x(:), y(:)\n real start, finish\n\n n = 1000000000\n allocate(x(n), y(n))\n\n !$acc kernels\n x(:) = 1\n y(:) = 2\n !$acc end kernels\n\n call cpu_time(start)\n call acc_saxpy(x, y, n, 0.5)\n call cpu_time(finish)\n print '(\"OpenACC saxpy time = \",f6.3,\" seconds.\")', (finish - start)\n\n call cpu_time(start)\n call par_saxpy(x, y, n, 0.5)\n call cpu_time(finish)\n print '(\"Parallel saxpy time = \",f6.3,\" seconds.\")', (finish - start)\n\n call cpu_time(start)\n call seq_saxpy(x, y, n, 0.5)\n call cpu_time(finish)\n print '(\"Sequential saxpy time = \",f6.3,\" seconds.\")', (finish - start)\n\n deallocate(x, y)\nend program main\n\n", "meta": {"hexsha": "238998159b440ff2d8e36eb3b0253ba3d6de709c", "size": 1243, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "do_concurrent/do_concurrent.f90", "max_stars_repo_name": "jeng1220/fortran_study", "max_stars_repo_head_hexsha": "08e0b68f884ab82ebbd2d68292ea3e41ad44a00c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2020-09-21T08:24:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T16:28:46.000Z", "max_issues_repo_path": "do_concurrent/do_concurrent.f90", "max_issues_repo_name": "jeng1220/fortran_study", "max_issues_repo_head_hexsha": "08e0b68f884ab82ebbd2d68292ea3e41ad44a00c", "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": "do_concurrent/do_concurrent.f90", "max_forks_repo_name": "jeng1220/fortran_study", "max_forks_repo_head_hexsha": "08e0b68f884ab82ebbd2d68292ea3e41ad44a00c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-05-08T13:32:22.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-26T13:43:42.000Z", "avg_line_length": 20.3770491803, "max_line_length": 75, "alphanum_fraction": 0.5631536605, "num_tokens": 457, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430645886584, "lm_q2_score": 0.8031737987125613, "lm_q1q2_score": 0.6675523324592725}} {"text": " subroutine func1(n, x, res)\n use, intrinsic :: iso_fortran_env, only: int64, real64\n implicit none\n integer(int64), intent(in) :: n\n real(real64), intent(in) :: x(n)\n real(real64), intent(out) :: res\nCf2py intent(hide) :: n\n res = sum(x)\n end\n", "meta": {"hexsha": "3f0e12c768335c15e65e36fd4cbd449ab93c14ea", "size": 298, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "numpy/f2py/tests/src/f2cmap/isoFortranEnvMap.f90", "max_stars_repo_name": "rjfarmer/numpy", "max_stars_repo_head_hexsha": "4cb688938be2ff20bf939c3917fde2f7634f0500", "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": "numpy/f2py/tests/src/f2cmap/isoFortranEnvMap.f90", "max_issues_repo_name": "rjfarmer/numpy", "max_issues_repo_head_hexsha": "4cb688938be2ff20bf939c3917fde2f7634f0500", "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": "numpy/f2py/tests/src/f2cmap/isoFortranEnvMap.f90", "max_forks_repo_name": "rjfarmer/numpy", "max_forks_repo_head_hexsha": "4cb688938be2ff20bf939c3917fde2f7634f0500", "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.8, "max_line_length": 62, "alphanum_fraction": 0.5469798658, "num_tokens": 88, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737869342623, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.6675523109121207}} {"text": "module feutils\n! Various Finite Element (FE) utilities\n! Based on code written by John E. Pask, LLNL.\nuse types\nuse utils, only: stop_error\nuse quadrature, only: gauss_pts, gauss_wts, lobatto_wts, lobatto_pts\nuse solvers, only: solve_sym\nimplicit none\nprivate\npublic get_nodes, define_connect, get_quad_pts, define_connect_n, &\n define_connect_np, get_parent_quad_pts_wts, &\n fe2quad, c2fullc, c2fullc2, fe_evaluate, calc_proj_error, &\n get_parent_nodes, phih, dphih, quad_gauss, quad_lobatto\n\ninteger, parameter :: quad_gauss = 1, quad_lobatto = 2\n\ncontains\n\nsubroutine get_parent_quad_pts_wts(qtype, Nq, xiq, wtq)\n! Quadrature points and weights\ninteger, intent(in) :: qtype ! type of quadrature: 1= Gauss, 2= Lobatto\ninteger, intent(in) :: Nq ! number or quadrature points/weights\nreal(dp), intent(out) :: xiq(:) ! quadrature points\nreal(dp), intent(out) :: wtq(:) ! quadrature weights\nselect case(qtype)\n case(1) ! Gauss\n xiq = gauss_pts(Nq)\n wtq = gauss_wts(Nq)\n case(2) ! Lobatto\n xiq = lobatto_pts(Nq)\n wtq = lobatto_wts(Nq)\n case default\n call stop_error(\"Invalid quadrature type.\")\nend select\nend subroutine\n\nsubroutine get_nodes(xe,xin,xn)\n! generates basis nodes xn via affine mapping of parent nodes xin to elements xe\nreal(dp), intent(in) :: xe(:) ! elements: xe(i/i+1) = coord of left/right boundary of ith element\nreal(dp), intent(in) :: xin(:) ! parent basis nodes: xin(i) = coord of ith parent basis fn node\nreal(dp), intent(out) :: xn(:) ! basis nodes: xn(i) = coordinate of ith basis fn node\nreal(dp) :: xa,xb ! left and right element boundaries\ninteger Ne,p,i,j\nNe=size(xe)-1\np=size(xin)-1\nxn(1)=xe(1) ! left-most node\ndo i=1,Ne ! for each element ...\n xa=xe(i); xb=xe(i+1)\n xn(i*p+1)=xb ! right-end node\n do j=2,p\n xn((i-1)*p+j)=(xin(j)+1)/2*(xb-xa)+xa ! internal nodes: affine mapping\n end do\nend do\nend subroutine\n\n!-------------------------------------------------------------------------------------------------!\n\nsubroutine define_connect(bca,bcb,Ne,p,in,ib)\n! constructs connectivity matrices in and ib defining local-global node and basis\n! correspondence, respectively\ninteger, intent(in):: bca ! boundary condition at x=a: 1=Dirichlet, 2=Neumann,\n ! 3=periodic, 4=antiperiodic. If bca=3 or 4, bcb must be set correspondingly\ninteger, intent(in):: bcb ! boundary condition at x=b: 1=Dirichlet, 2=Neumann,\n ! 3=periodic, 4=antiperiodic. If bcb = 3 or 4, bca must be set correspondingly\ninteger, intent(in):: Ne ! number of elements\ninteger, intent(in):: p ! order of FE/SE basis\ninteger, intent(out):: in(:,:) ! nodal connectivity: in(i,j) = index of basis node\n ! corresponding to local node i of element j\ninteger, intent(out):: ib(:,:) ! basis connectivity: ib(i,j) = index of basis function\n ! associated with local basis function i of element j. 0 = no associated basis fn.\n ! -1 = associated with antiperiodic basis fn, with negative multiplier\ninteger i,e\n! check boundary condition consistency\nif ((bca>2 .or. bcb>2) .and. bcb/=bca) then\n write(*,'(1x,a,i0,a,i0)') \"Error: bca = \", bca, \" /= bcb = \", bcb\n call stop_error(\"stop\")\nend if\n! construct nodal connectivity matrix\ndo e=1,Ne\n do i=1,p+1\n in(i,e)=(e-1)*p+i\n end do\nend do\n! construct basis connectivity matrix\n ! construct for natural BCs\nib=in\n ! modify for other BCs\nif (bca==1) ib=ib-1 ! Dirichlet at x=a -> omit basis fn at node 1\nselect case(bcb) ! x=b....\n case(1); ib(p+1,Ne)=0 ! Dirichlet\n case(3); ib(p+1,Ne)=1 ! periodic\n case(4); ib(p+1,Ne)=-1 ! antiperiodic\nend select\nend subroutine\n\nsubroutine define_connect_n(bca, bcb, Ne, p, Nm, in, ib)\n! constructs connectivity matrices in and ib defining local-global node and\n! basis correspondence, respectively. Works for arbitrary number of meshes\ninteger, intent(in):: bca(:) ! bca(m) boundary condition at x=a for mesh\n ! m: 1=Dirichlet, 2=Neumann\ninteger, intent(in):: bcb(:) ! bca(m) boundary condition at x=b for mesh\n ! m: 1=Dirichlet, 2=Neumann\ninteger, intent(in):: Ne ! number of elements\ninteger, intent(in):: p ! order of FE/SE basis\ninteger, intent(in):: Nm ! number of meshes\ninteger, intent(out):: in(:,:,:) ! nodal connectivity: in(i,j,k) = index of\n ! basis node corresponding to local node i of element j of mesh k\ninteger, intent(out):: ib(:,:,:) ! basis connectivity: ib(i,j,k) = index of\n ! basis function associated with local basis function i of element j of\n ! mesh k. 0 = no associated basis fn\ninteger :: i, e, m, dofs\n! construct nodal connectivity matrix\ndofs = 0\ndo m = 1, Nm\n do e = 1, Ne\n do i = 1, p+1\n dofs = dofs + 1\n in(i, e, m) = dofs\n end do\n dofs = dofs - 1 ! connect the shape functions across the element\n end do\n dofs = dofs + 1 ! don't connect the shape functions across meshes\nend do\n! construct basis connectivity matrix\ndofs = 0\ndo m = 1, Nm\n do e = 1, Ne\n do i = 1, p+1\n if (i == 1 .and. e == 1 .and. bca(m) == 1) then\n ib(i, e, m) = 0 ! Dirichlet\n cycle\n end if\n if (i == p+1 .and. e == Ne .and. bcb(m) == 1) then\n ib(i, e, m) = 0 ! Dirichlet\n cycle\n end if\n dofs = dofs + 1\n ib(i, e, m) = dofs\n end do\n dofs = dofs - 1 ! connect the shape functions across the element\n end do\n dofs = dofs + 1 ! don't connect the shape functions across meshes\nend do\nend subroutine\n\nsubroutine define_connect_np(bca, bcb, Ne, p, Nm, in, ib)\n! constructs connectivity matrices in and ib defining local-global node and\n! basis correspondence, respectively. Works for arbitrary number of meshes\ninteger, intent(in):: bca(:) ! bca(m) boundary condition at x=a for mesh\n ! m: 1=Dirichlet, 2=Neumann\ninteger, intent(in):: bcb(:) ! bca(m) boundary condition at x=b for mesh\n ! m: 1=Dirichlet, 2=Neumann\ninteger, intent(in):: Ne ! number of elements\ninteger, intent(in):: p(:) ! order of FE/SE basis\ninteger, intent(in):: Nm ! number of meshes\ninteger, intent(out):: in(:,:,:) ! nodal connectivity: in(i,j,k) = index of\n ! basis node corresponding to local node i of element j of mesh k\ninteger, intent(out):: ib(:,:,:) ! basis connectivity: ib(i,j,k) = index of\n ! basis function associated with local basis function i of element j of\n ! mesh k. 0 = no associated basis fn\ninteger :: i, e, m, dofs\n! Initialize the arrays to -1\nin = -1\nib = -1\n! construct nodal connectivity matrix\ndofs = 0\ndo m = 1, Nm\n do e = 1, Ne\n do i = 1, p(m)+1\n dofs = dofs + 1\n in(i, e, m) = dofs\n end do\n dofs = dofs - 1 ! connect the shape functions across the element\n end do\n dofs = dofs + 1 ! don't connect the shape functions across meshes\nend do\n! construct basis connectivity matrix\ndofs = 0\ndo m = 1, Nm\n do e = 1, Ne\n do i = 1, p(m)+1\n if (i == 1 .and. e == 1 .and. bca(m) == 1) then\n ib(i, e, m) = 0 ! Dirichlet\n cycle\n end if\n if (i == p(m)+1 .and. e == Ne .and. bcb(m) == 1) then\n ib(i, e, m) = 0 ! Dirichlet\n cycle\n end if\n dofs = dofs + 1\n ib(i, e, m) = dofs\n end do\n dofs = dofs - 1 ! connect the shape functions across the element\n end do\n dofs = dofs + 1 ! don't connect the shape functions across meshes\nend do\nend subroutine\n\nsubroutine get_quad_pts(xe,xiq,xq)\n! generates quadrature points xq via affine mapping of parent quad points xiq to elements xe\nreal(dp), intent(in):: xe(:) ! elements: xe(i/i+1) = coord of left/right boundary of ith element\nreal(dp), intent(in):: xiq(:) ! parent quad pts\nreal(dp), intent(out):: xq(:,:) ! quad pts: xq(i,j) = coordinate of ith point in jth element\nreal(dp) xa,xb ! left and right element boundaries\ninteger ie\ndo ie=1,size(xe)-1\n xa=xe(ie); xb=xe(ie+1)\n xq(:,ie)=(xb-xa)/2*xiq+(xb+xa)/2 ! affine transformation\nend do\nend subroutine\n\nsubroutine fe2quad(xe, xin, xiq, in, fullu, uq)\n! transforms fullu from FE-coefficient to quadrature-grid representation.\n! fullu is a full FE coefficient vector, having values for all nodes in the mesh,\n! including domain-boundary nodes.\nreal(dp), intent(in) :: xe(:) ! elements: xe(i/i+1) = coord of left/right boundary of ith element\nreal(dp), intent(in) :: xin(:) ! parent basis nodes: xin(i) = coordinate of ith parent basis node\nreal(dp), intent(in) :: xiq(:) ! quadrature points\ninteger, intent(in) :: in(:,:) ! nodal connectivity: in(i,j) = index of basis node\n ! corresponding to local node i of element j\nreal(dp), intent(in) :: fullu(:) ! FE coefficient representatin of fullu: full vector, including\n ! values for domain-boundary nodes / basis functions\nreal(dp), intent(out) :: uq(:,:) ! quadrature-grid representatin of fullu\n ! uq(i,j) = value at ith quadrature point of jth element\nreal(dp) :: phihq(size(xiq), size(xin)) ! parent basis fn values at quadrature points:\n ! phihq(i,j) = value of jth function at ith quadrature point\ninteger :: ie, iln, iq ! element, local node, quad point indices\n\n! tabulate parent basis at quadrature points\ndo iln = 1, size(xin)\n do iq = 1, size(xiq)\n phihq(iq, iln) = phih(xin, iln, xiq(iq))\n end do\nend do\n! evaluate at quad points in each element\ndo ie = 1, size(xe)-1\n uq(:, ie) = 0\n do iln = 1, size(xin)\n uq(:, ie) = uq(:, ie) + fullu(in(iln, ie)) * phihq(:, iln)\n end do\nend do\nend subroutine\n\nsubroutine c2fullc(in, ib, c, fullc)\n! Converts FE coefficient vector to full coefficient vector\ninteger, intent(in) :: in(:,:,:) ! nodal connectivity: in(i,j) = index of basis\n ! node\n ! corresponding to local node i of element j\ninteger, intent(in) :: ib(:,:,:) ! basis connectivity: ib(i,j) = index of basis\n ! function associated with local basis function i of element j. 0 = no\n ! associated basis fn.\nreal(dp), intent(in) :: c(:) ! coefficient vector with regards to ib\nreal(dp), intent(out) :: fullc(:) ! full coefficients vector with regards to in\ninteger :: m, e, i\ndo m = 1, size(in, 3)\n do e = 1, size(in, 2)\n do i = 1, size(in, 1)\n if (in(i, e, m) == -1) cycle\n if (ib(i, e, m) == 0) then\n fullc(in(i, e, m)) = 0 ! Dirichlet\n else\n fullc(in(i, e, m)) = c(ib(i, e, m))\n end if\n end do\n end do\nend do\nend subroutine\n\nsubroutine c2fullc2(in, ib, c, fullc)\n! Converts FE coefficient vector to full coefficient vector\n! It puts 0 for Dirichlet boundary conditions (ib==0), otherwise it just copies\n! the coefficients.\ninteger, intent(in) :: in(:,:) ! nodal connectivity: in(i,j) = index of basis\n ! node\n ! corresponding to local node i of element j\ninteger, intent(in) :: ib(:,:) ! basis connectivity: ib(i,j) = index of basis\n ! function associated with local basis function i of element j. 0 = no\n ! associated basis fn.\nreal(dp), intent(in) :: c(:) ! coefficient vector with regards to ib\nreal(dp), intent(out) :: fullc(:) ! full coefficients vector with regards to in\ninteger :: e, i\ndo e = 1, size(in, 2)\n do i = 1, size(in, 1)\n if (ib(i, e) == 0) then\n fullc(in(i, e)) = 0 ! Dirichlet\n else\n fullc(in(i, e)) = c(ib(i, e))\n end if\n end do\nend do\nend subroutine\n\nsubroutine fe_evaluate(xe, xin, xn, in, fullu, xout, yout)\n! Evaluates the FE solution (fullu) on a grid.\n! fullu is a full FE coefficient vector, having values for all nodes in the mesh,\n! including domain-boundary nodes.\nreal(dp), intent(in):: xe(:) ! elements: xe(i/i+1) = coord of left/right boundary of ith element\nreal(dp), intent(in):: xin(:) ! parent basis nodes: xin(i) = coordinate of ith parent basis node\nreal(dp), intent(in):: xn(:) ! basis nodes: xn(i) = coordinate of ith basis node\ninteger, intent(in):: in(:,:) ! nodal connectivity: in(i,j) = index of basis node\n ! corresponding to local node i of element j\nreal(dp), intent(in):: fullu(:, :) ! FE coefficient representatin of fullu: full vector, including\n ! values for domain-boundary nodes / basis functions\nreal(dp), intent(in):: xout(:) ! grid points to evaluate the solution at\nreal(dp), intent(out):: yout(:, :) ! values of the solution at 'xout'\nreal(dp) :: phihx(size(xin)) ! parent basis fn values at a point\ninteger :: p, n, e, i, j\nreal(dp) :: x, xa, xb, xi\n\np = size(xin) - 1\ne = 1\ndo i = 1, size(xout)\n ! get x and element containing x\n x = xout(i)\n call getElement(xn, p, x, e)\n ! get parent coordinates xi\n xa = xe(e)\n xb = xe(e+1)\n xi = (x-xa)/(xb-xa)*2-1\n ! get parent basis values at xi\n do n= 1, p+1\n phihx(n) = phih(xin, n, xi)\n end do\n ! get eigenfunction value at x\n do j = 1, size(fullu, 2)\n yout(i, j) = sum(fullu(in(:,e), j) * phihx)\n end do\nend do\nend subroutine\n\nsubroutine getElement(xn,p,x,e)\n! returns element containing point x, at or after element e\nreal(dp), intent(in):: xn(:) ! basis nodes: xn(i) = coordinate of ith basis node\ninteger, intent(in):: p ! order of FE/SE basis\nreal(dp), intent(in):: x ! point x\ninteger, intent(inout):: e ! input: index of element to start search\n ! output: index of element containing x, at or after element e\ninteger Ne ! number of elements\nNe=(size(xn)-1)/p\nif (e<1 .or. e>Ne) e=1\ndo\n if (x>=xn((e-1)*p+1) .and. x<=xn(e*p+1)) exit\n e=e+1\n if (e>Ne) call stop_error(\"getElement error: x not in mesh.\")\nend do\nend subroutine\n\nfunction calc_proj_error(p, xe, xiq, wtq, uq) result(error)\n! Calculates the L2 error of the projected solution on the mesh \"p\"\ninteger, intent(in) :: p\nreal(dp), intent(in):: xe(:) ! elements: xe(i/i+1) = coord of left/right boundary of ith element\nreal(dp), intent(in):: xiq(:), wtq(:) ! quadrature points and weights\nreal(dp), intent(in):: uq(:,:) ! FE coefficient representatin of fullu: full vector, including\nreal(dp) :: error(size(xe)-1) ! errors for each element\n ! values for domain-boundary nodes / basis functions\nreal(dp) phihq(size(xiq),p+1) ! parent basis fn values at quadrature points: \n ! phihq(i,j) = value of jth function at ith quadrature point\ninteger :: ie,iln,iq ! element, local node, quad point indices\ninteger :: i, j, Ne, dofs\nreal(dp) :: xin(p+1), al, be, jac, xa, xb, norm\nreal(dp), allocatable :: A(:, :), f(:), x(:), xn(:)\ninteger, allocatable :: in(:, :), ib(:, :)\nreal(dp) :: projq(size(uq, 1), size(uq, 2))\n\nif (.not. p >= 1) call stop_error(\"p >= 1 required\")\n\n! define parent basis\ncall get_parent_nodes(2, p, xin)\n\nNe = size(xe) - 1\n\n! define basis\nallocate(xn(Ne*p+1))\ncall get_nodes(xe, xin, xn)\n\nallocate(in(p+1,Ne),ib(p+1,Ne))\ncall define_connect(2, 2, Ne, p, in, ib)\n\n! tabulate parent basis at quadrature points\ndo iln = 1, p+1\n do iq = 1, size(xiq)\n phihq(iq,iln) = phih(xin,iln,xiq(iq))\n end do\nend do\n\ndofs = maxval(in)\n!print *, \"DOFS=\", dofs\nallocate(A(dofs, dofs), f(dofs), x(dofs))\n\nA = 0\nf = 0\ndo ie = 1, Ne ! sum over elements\n xa=xe(ie); xb=xe(ie+1)\n al=(xb-xa)/2; be=(xb+xa)/2\n jac=al\n do i = 1, p+1\n do j = 1, p+1\n A(in(i,ie), in(j,ie)) = A(in(i,ie), in(j,ie)) + &\n sum(wtq*phihq(:, i)*phihq(:, j)*jac)\n end do\n f(in(i,ie)) = f(in(i,ie)) + sum(wtq*phihq(:, i)*uq(:, ie)*jac)\n end do\nend do\n! Solve A x = f\nx = solve_sym(A, f)\ncall fe2quad(xe,xin,xiq,in,x,projq)\nnorm = 0\ndo ie = 1, Ne ! sum over elements\n xa=xe(ie); xb=xe(ie+1)\n al=(xb-xa)/2; be=(xb+xa)/2\n jac=al\n !print *, \"el =\", ie, sqrt(sum(wtq * abs(uq(:, ie)-projq(:, ie))**2 * jac))\n error(ie) = sum(wtq * abs(uq(:, ie)-projq(:, ie))**2 * jac)\n norm = norm + sum(wtq * abs(uq(:, ie))**2 * jac)\nend do\nnorm = sqrt(norm)\nerror = sqrt(error)/norm\n!open(newunit=ff, file=\"proj.dat\", status=\"replace\")\n!write(ff, *) xn\n!write(ff, *) x\n!close(ff)\nend function\n\nsubroutine get_parent_nodes(btype, p, xin)\ninteger, intent(in):: btype ! type of basis: 1=uniform node, 2=Lobatto node\ninteger, intent(in):: p ! order of FE/SE basis\n! parent basis nodes: xin(i) = coordinate of ith parent basis node:\nreal(dp), intent(out):: xin(:)\ninteger i\nif (p < 1) call stop_error(\"Error: p < 1.\")\nif (size(xin) /= p+1) call stop_error(\"Error: size(xin) /= p+1\")\nselect case (btype)\n case(1) ! uniform\n do i = 1, p+1\n xin(i) = real(i-1, dp)/p*2-1\n end do\n case(2) ! Lobatto\n xin=lobatto_pts(p+1)\n case default\n call stop_error(\"Error: invalid basis type.\")\nend select\nend subroutine\n\nreal(dp) pure function phih(xin, n, xi)\n! \"phi hat\": nth Lagrange polynomial with nodes xin at point xi.\n! Value equals to 1 for xi=xin(n) and zero for all other nodes.\nreal(dp), intent(in) :: xin(:) ! polynomial nodes\ninteger, intent(in) :: n ! polynomial index\nreal(dp), intent(in) :: xi ! point at which to evaluate phih\ninteger :: i\n! compute nth polynomial: 1 at node n, 0 at all others\nphih = 1\ndo i = 1, size(xin)\n if (i == n) cycle\n phih = phih * (xi-xin(i))/(xin(n)-xin(i))\nend do\nend function\n\nreal(dp) pure function dphih(xin, n, xi)\n! \"d phi hat\": derivative of nth Lagrange polynomial with nodes 'xin' at point\n! 'xi'.\nreal(dp), intent(in) :: xin(:) ! polynomial nodes\ninteger, intent(in) :: n ! polynomial index\nreal(dp), intent(in) :: xi ! point at which to evaluate dphih\nreal(dp) :: term\nreal(dp) :: tmp(size(xin))\ninteger :: i, j\ndo i = 1, size(xin)\n if (i==n) cycle\n tmp(i) = (xi-xin(i))/(xin(n)-xin(i))\nend do\n! compute derivative of nth polynomial\ndphih = 0\ndo j = 1, size(xin)\n if (j == n) cycle\n term = 1 / (xin(n)-xin(j))\n do i = 1, size(xin)\n if (i==n .or. i==j) cycle\n term = term * tmp(i)\n end do\n dphih = dphih + term\nend do\nend function\n\nreal(dp) pure function hermite_basis_1(xin, n, xi) result(h)\n! nth Hermite basis polynomial (first kind) with nodes 'xin' at point 'xi'.\n! Value equals to 1 for xi=xin(n) and zero for all other nodes. Derivatives are\n! zero for all nodes.\nreal(dp), intent(in) :: xin(:) ! polynomial nodes\ninteger, intent(in) :: n ! polynomial index\nreal(dp), intent(in) :: xi ! point at which to evaluate phih\nh = (1-2*dphih(xin, n, xin(n))*(xi - xin(n))) * phih(xin, n, xi)**2\nend function\n\nreal(dp) pure function hermite_basis_2(xin, n, xi) result(h)\n! nth Hermite basis polynomial (second kind) with nodes 'xin' at point 'xi'.\n! Value is zero for all nodes. Derivative equals to 1 for xi=xin(n) and zero\n! for all other nodes.\nreal(dp), intent(in) :: xin(:) ! polynomial nodes\ninteger, intent(in) :: n ! polynomial index\nreal(dp), intent(in) :: xi ! point at which to evaluate phih\nh = (xi - xin(n)) * phih(xin, n, xi)**2\nend function\n\nend module\n", "meta": {"hexsha": "d1a5c4c569cb912d5d7fb09157c76d57710fdb41", "size": 19177, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/feutils.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/feutils.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/feutils.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": 37.8992094862, "max_line_length": 101, "alphanum_fraction": 0.6160504771, "num_tokens": 6055, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711794579723, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.6674896692772361}} {"text": "!\n! Copyright (C) 2001-2010 Quantum ESPRESSO group\n! This file is distributed under the terms of the\n! GNU General Public License. See the file `License'\n! in the root directory of the present distribution,\n! or http://www.gnu.org/copyleft/gpl.txt .\n!\n!\n!-----------------------------------------------------------------------\nSUBROUTINE multable (nsym, s, table)\n !-----------------------------------------------------------------------\n !\n ! Checks that {S} is a group and calculates multiplication table\n !\n IMPLICIT NONE\n !\n INTEGER, INTENT(IN) :: nsym, s(3,3,nsym)\n ! nsym = number of symmetry operations\n ! s = rotation matrix (in crystal axis, represented by integers)\n INTEGER, INTENT(OUT) :: table (48, 48)\n ! multiplication table: S(n)*S(m) = S (table(n,m) )\n !\n INTEGER :: isym, jsym, ksym, ss (3, 3)\n LOGICAL :: found, smn\n !\n DO isym = 1, nsym\n DO jsym = 1, nsym\n ! \n ss = MATMUL (s(:,:,jsym),s(:,:,isym))\n !\n ! here we check that the input matrices really form a group\n ! and we set the multiplication table\n !\n found = .false.\n DO ksym = 1, nsym\n smn = ALL ( s(:,:,ksym) == ss(:,:) )\n IF (smn) THEN\n IF (found) CALL errore ('multable', 'Not a group', 1)\n found = .true.\n table (jsym, isym) = ksym\n END IF\n END DO\n IF ( .NOT.found) CALL errore ('multable', ' Not a group', 2)\n END DO\n END DO\n RETURN\n !\nEND SUBROUTINE multable\n", "meta": {"hexsha": "8562249ee555acf234229d03208c9cd89c71a79f", "size": 1521, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/apps/miniDFT/tests/src/multable.f90", "max_stars_repo_name": "utdsimmons/ohpc", "max_stars_repo_head_hexsha": "70dc728926a835ba049ddd3f4627ef08db7c95a0", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 692, "max_stars_repo_stars_event_min_datetime": "2015-11-12T13:56:43.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T03:45:59.000Z", "max_issues_repo_path": "tests/apps/miniDFT/tests/src/multable.f90", "max_issues_repo_name": "utdsimmons/ohpc", "max_issues_repo_head_hexsha": "70dc728926a835ba049ddd3f4627ef08db7c95a0", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1096, "max_issues_repo_issues_event_min_datetime": "2015-11-12T09:08:22.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:48:41.000Z", "max_forks_repo_path": "tests/apps/miniDFT/tests/src/multable.f90", "max_forks_repo_name": "utdsimmons/ohpc", "max_forks_repo_head_hexsha": "70dc728926a835ba049ddd3f4627ef08db7c95a0", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 224, "max_forks_repo_forks_event_min_datetime": "2015-11-12T21:17:03.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T00:57:48.000Z", "avg_line_length": 31.0408163265, "max_line_length": 74, "alphanum_fraction": 0.5154503616, "num_tokens": 428, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711832583695, "lm_q2_score": 0.7853085808877581, "lm_q1q2_score": 0.6674896637201188}} {"text": "submodule (stdlib_linalg) stdlib_linalg_diag\n\n implicit none\n\ncontains\n\n module function diag_rdp(v) result(res)\n real(dp), intent(in) :: v(:)\n real(dp) :: res(size(v),size(v))\n integer :: i\n res = 0\n do i = 1, size(v)\n res(i,i) = v(i)\n end do\n end function diag_rdp\n module function diag_cdp(v) result(res)\n complex(dp), intent(in) :: v(:)\n complex(dp) :: res(size(v),size(v))\n integer :: i\n res = 0\n do i = 1, size(v)\n res(i,i) = v(i)\n end do\n end function diag_cdp\n module function diag_iint32(v) result(res)\n integer(int32), intent(in) :: v(:)\n integer(int32) :: res(size(v),size(v))\n integer :: i\n res = 0\n do i = 1, size(v)\n res(i,i) = v(i)\n end do\n end function diag_iint32\n\n\n module function diag_rdp_k(v,k) result(res)\n real(dp), intent(in) :: v(:)\n integer, intent(in) :: k\n real(dp) :: res(size(v)+abs(k),size(v)+abs(k))\n integer :: i, sz\n sz = size(v)\n res = 0\n if (k > 0) then\n do i = 1, sz\n res(i,k+i) = v(i)\n end do\n else if (k < 0) then\n do i = 1, sz\n res(i+abs(k),i) = v(i)\n end do\n else\n do i = 1, sz\n res(i,i) = v(i)\n end do\n end if\n end function diag_rdp_k\n module function diag_cdp_k(v,k) result(res)\n complex(dp), intent(in) :: v(:)\n integer, intent(in) :: k\n complex(dp) :: res(size(v)+abs(k),size(v)+abs(k))\n integer :: i, sz\n sz = size(v)\n res = 0\n if (k > 0) then\n do i = 1, sz\n res(i,k+i) = v(i)\n end do\n else if (k < 0) then\n do i = 1, sz\n res(i+abs(k),i) = v(i)\n end do\n else\n do i = 1, sz\n res(i,i) = v(i)\n end do\n end if\n end function diag_cdp_k\n module function diag_iint32_k(v,k) result(res)\n integer(int32), intent(in) :: v(:)\n integer, intent(in) :: k\n integer(int32) :: res(size(v)+abs(k),size(v)+abs(k))\n integer :: i, sz\n sz = size(v)\n res = 0\n if (k > 0) then\n do i = 1, sz\n res(i,k+i) = v(i)\n end do\n else if (k < 0) then\n do i = 1, sz\n res(i+abs(k),i) = v(i)\n end do\n else\n do i = 1, sz\n res(i,i) = v(i)\n end do\n end if\n end function diag_iint32_k\n\n module function diag_rdp_mat(A) result(res)\n real(dp), intent(in) :: A(:,:)\n real(dp) :: res(minval(shape(A)))\n integer :: i\n do i = 1, minval(shape(A))\n res(i) = A(i,i)\n end do\n end function diag_rdp_mat\n module function diag_cdp_mat(A) result(res)\n complex(dp), intent(in) :: A(:,:)\n complex(dp) :: res(minval(shape(A)))\n integer :: i\n do i = 1, minval(shape(A))\n res(i) = A(i,i)\n end do\n end function diag_cdp_mat\n module function diag_iint32_mat(A) result(res)\n integer(int32), intent(in) :: A(:,:)\n integer(int32) :: res(minval(shape(A)))\n integer :: i\n do i = 1, minval(shape(A))\n res(i) = A(i,i)\n end do\n end function diag_iint32_mat\n\n module function diag_rdp_mat_k(A,k) result(res)\n real(dp), intent(in) :: A(:,:)\n integer, intent(in) :: k\n real(dp) :: res(minval(shape(A))-abs(k))\n integer :: i, sz\n sz = minval(shape(A))-abs(k)\n if (k > 0) then\n do i = 1, sz\n res(i) = A(i,k+i)\n end do\n else if (k < 0) then\n do i = 1, sz\n res(i) = A(i+abs(k),i)\n end do\n else\n do i = 1, sz\n res(i) = A(i,i)\n end do\n end if\n end function diag_rdp_mat_k\n module function diag_cdp_mat_k(A,k) result(res)\n complex(dp), intent(in) :: A(:,:)\n integer, intent(in) :: k\n complex(dp) :: res(minval(shape(A))-abs(k))\n integer :: i, sz\n sz = minval(shape(A))-abs(k)\n if (k > 0) then\n do i = 1, sz\n res(i) = A(i,k+i)\n end do\n else if (k < 0) then\n do i = 1, sz\n res(i) = A(i+abs(k),i)\n end do\n else\n do i = 1, sz\n res(i) = A(i,i)\n end do\n end if\n end function diag_cdp_mat_k\n module function diag_iint32_mat_k(A,k) result(res)\n integer(int32), intent(in) :: A(:,:)\n integer, intent(in) :: k\n integer(int32) :: res(minval(shape(A))-abs(k))\n integer :: i, sz\n sz = minval(shape(A))-abs(k)\n if (k > 0) then\n do i = 1, sz\n res(i) = A(i,k+i)\n end do\n else if (k < 0) then\n do i = 1, sz\n res(i) = A(i+abs(k),i)\n end do\n else\n do i = 1, sz\n res(i) = A(i,i)\n end do\n end if\n end function diag_iint32_mat_k\n\nend submodule\n", "meta": {"hexsha": "8a90bf92301a573a94f3fa2b779ac1701a0247e5", "size": 5150, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/stdlib_linalg_diag.f90", "max_stars_repo_name": "zoziha/dp-stdlib", "max_stars_repo_head_hexsha": "d317f4d273cb0fcabf532578a7ec0e4687e18700", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-12-08T04:45:43.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-09T11:42:41.000Z", "max_issues_repo_path": "src/stdlib_linalg_diag.f90", "max_issues_repo_name": "zoziha/dp-stdlib", "max_issues_repo_head_hexsha": "d317f4d273cb0fcabf532578a7ec0e4687e18700", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2021-12-08T12:35:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-17T02:33:12.000Z", "max_forks_repo_path": "src/stdlib_linalg_diag.f90", "max_forks_repo_name": "zoziha/dp-stdlib", "max_forks_repo_head_hexsha": "d317f4d273cb0fcabf532578a7ec0e4687e18700", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-09T01:54:34.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-09T01:54:34.000Z", "avg_line_length": 27.5401069519, "max_line_length": 60, "alphanum_fraction": 0.4450485437, "num_tokens": 1538, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84997116805678, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.6674896603237818}} {"text": "subroutine distance_table(pos, lbox, natom, ndim, dtable)\n integer, intent(in) :: natom, ndim\n real*8, intent(in) :: pos(natom, ndim), lbox\n real*8, intent(out) :: dtable(natom, natom)\n integer i, j\n real*8 drij(ndim)\n do i=1,natom\n do j=i+1,natom\n drij = pos(i, :) - pos(j, :)\n drij = drij - lbox*nint(drij/lbox)\n dtable(i, j) = norm2(drij)\n !write (*, '(4f8.4)') drij, dtable(i, j)\n end do\n !stop\n end do\nend subroutine\n", "meta": {"hexsha": "5c59747f955650e4ccf714bd6463df8af823b0e1", "size": 458, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "4_dtable/forlib/example.f90", "max_stars_repo_name": "Paul-St-Young/thw-python-as-glue", "max_stars_repo_head_hexsha": "491fab54eaa5a621a9641c15a121be49097add5b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-04-17T17:03:12.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-17T17:03:12.000Z", "max_issues_repo_path": "4_dtable/forlib/example.f90", "max_issues_repo_name": "Paul-St-Young/thw-python-as-glue", "max_issues_repo_head_hexsha": "491fab54eaa5a621a9641c15a121be49097add5b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "4_dtable/forlib/example.f90", "max_forks_repo_name": "Paul-St-Young/thw-python-as-glue", "max_forks_repo_head_hexsha": "491fab54eaa5a621a9641c15a121be49097add5b", "max_forks_repo_licenses": ["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.9411764706, "max_line_length": 57, "alphanum_fraction": 0.5917030568, "num_tokens": 178, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711832583695, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.6674896594493176}} {"text": " subroutine stat_2d (s, nx_s, nx_e, ny_s, ny_e)\n \n! subroutine to stat a 3-d array with ferret\n \n! character field_name(20)\n \n integer nx_s,nx_e,ny_s,ny_e,i,j \n real s(nx_s:nx_e,ny_s:ny_e)\n\n real sum,save,std \n \n sum = 0.0\n\n do j = ny_s+1,ny_e-1\n do i = nx_s+1,nx_e-1\n sum = s(i,j) + sum\n enddo;enddo\n \n save = sum / real(nx_e- nx_s-1) / real(ny_e- ny_s-1) \n \n sum = 0.0\n \n do j = ny_s+1,ny_e-1\n do i = nx_s+1,nx_e-1\n \n sum = (s(i,j)-save)**2 + sum\n \n enddo;enddo\n \n std = sqrt( sum / ( real(nx_e- nx_s-1) * real(ny_e- ny_s-1) -1 )) \n write(6,*) 'save,std:',real(save),real(std) \n \n return\n end\n", "meta": {"hexsha": "6db6bfc7dbd1ab2f280342e676b5597491da9cb6", "size": 2143, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "stat_2d.f", "max_stars_repo_name": "diioriod/PlumeModel-Hotcross", "max_stars_repo_head_hexsha": "2d978a8e1b07157edc12df4576baccd970a30a4a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "stat_2d.f", "max_issues_repo_name": "diioriod/PlumeModel-Hotcross", "max_issues_repo_head_hexsha": "2d978a8e1b07157edc12df4576baccd970a30a4a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "stat_2d.f", "max_forks_repo_name": "diioriod/PlumeModel-Hotcross", "max_forks_repo_head_hexsha": "2d978a8e1b07157edc12df4576baccd970a30a4a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 61.2285714286, "max_line_length": 132, "alphanum_fraction": 0.1684554363, "num_tokens": 298, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.667463072669147}} {"text": "*DECK CPBDI\n SUBROUTINE CPBDI (ABD, LDA, N, M, DET)\nC***BEGIN PROLOGUE CPBDI\nC***PURPOSE Compute the determinant of a complex Hermitian positive\nC definite band matrix using the factors computed by CPBCO or\nC CPBFA.\nC***LIBRARY SLATEC (LINPACK)\nC***CATEGORY D3D2\nC***TYPE COMPLEX (SPBDI-S, DPBDI-D, CPBDI-C)\nC***KEYWORDS BANDED, DETERMINANT, INVERSE, LINEAR ALGEBRA, LINPACK,\nC MATRIX, POSITIVE DEFINITE\nC***AUTHOR Moler, C. B., (U. of New Mexico)\nC***DESCRIPTION\nC\nC CPBDI computes the determinant\nC of a complex Hermitian positive definite band matrix\nC using the factors computed by CPBCO or CPBFA.\nC If the inverse is needed, use CPBSL N times.\nC\nC On Entry\nC\nC ABD COMPLEX(LDA, N)\nC the output from CPBCO or CPBFA.\nC\nC LDA INTEGER\nC the leading dimension of the array ABD .\nC\nC N INTEGER\nC the order of the matrix A .\nC\nC M INTEGER\nC the number of diagonals above the main diagonal.\nC\nC On Return\nC\nC DET REAL(2)\nC determinant of original matrix in the form\nC determinant = DET(1) * 10.0**DET(2)\nC with 1.0 .LE. DET(1) .LT. 10.0\nC or DET(1) .EQ. 0.0 .\nC\nC***REFERENCES J. J. Dongarra, J. R. Bunch, C. B. Moler, and G. W.\nC Stewart, LINPACK Users' Guide, SIAM, 1979.\nC***ROUTINES CALLED (NONE)\nC***REVISION HISTORY (YYMMDD)\nC 780814 DATE WRITTEN\nC 890831 Modified array declarations. (WRB)\nC 890831 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900326 Removed duplicate information from DESCRIPTION section.\nC (WRB)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE CPBDI\n INTEGER LDA,N,M\n COMPLEX ABD(LDA,*)\n REAL DET(2)\nC\n REAL S\n INTEGER I\nC***FIRST EXECUTABLE STATEMENT CPBDI\nC\nC COMPUTE DETERMINANT\nC\n DET(1) = 1.0E0\n DET(2) = 0.0E0\n S = 10.0E0\n DO 50 I = 1, N\n DET(1) = REAL(ABD(M+1,I))**2*DET(1)\n IF (DET(1) .EQ. 0.0E0) GO TO 60\n 10 IF (DET(1) .GE. 1.0E0) GO TO 20\n DET(1) = S*DET(1)\n DET(2) = DET(2) - 1.0E0\n GO TO 10\n 20 CONTINUE\n 30 IF (DET(1) .LT. S) GO TO 40\n DET(1) = DET(1)/S\n DET(2) = DET(2) + 1.0E0\n GO TO 30\n 40 CONTINUE\n 50 CONTINUE\n 60 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "4e1992cf1d0830689de00a6e791b6ec0aec7bfbb", "size": 2514, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/cpbdi.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/cpbdi.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/cpbdi.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.9285714286, "max_line_length": 72, "alphanum_fraction": 0.5751789976, "num_tokens": 888, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778824, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.66746306792679}} {"text": " double precision function fdisc(blockno,xc,yc,zc)\n implicit none\n\n integer blockno\n double precision xc,yc, zc\n\n double precision r\n\n r = sqrt((xc-0.5d0)**2 + (yc-1.d0)**2 + (zc-0.5)**2)\n\n fdisc = r-0.25d0\n end\n", "meta": {"hexsha": "eb678afe7dd5449c4625d43d74e862ba1dd5f695", "size": 253, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "applications/clawpack/advection/3d/filament/fdisc.f", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "applications/clawpack/advection/3d/filament/fdisc.f", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-08-02T09:52:43.000Z", "max_issues_repo_issues_event_max_datetime": "2017-08-02T14:16:23.000Z", "max_forks_repo_path": "applications/clawpack/advection/3d/filament/fdisc.f", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.4615384615, "max_line_length": 58, "alphanum_fraction": 0.557312253, "num_tokens": 88, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8807970654616712, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6674630584420755}} {"text": " program computation of function using do statement\n write(*,1)\n1 format(3x,'x',11x,'f(x)')\n do 50 x=0.0, 1.0, 0.1\n fx=sqrt(X)*cos(2*X+5.0)\n write(*,20)x,fx\n50 continue\n20 format(1x,f3.1,9x,f6.4)\n pause\n stop\n end\n", "meta": {"hexsha": "9c88244d653f292d03aff14fcb00273653a78162", "size": 264, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "test.f", "max_stars_repo_name": "Sayan3990/Fortran", "max_stars_repo_head_hexsha": "8e138157be0ffc2e0a7afb9e6a3f901b802434d8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-08-14T02:14:36.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-14T03:45:52.000Z", "max_issues_repo_path": "test.f", "max_issues_repo_name": "Sayan3990/Fortran", "max_issues_repo_head_hexsha": "8e138157be0ffc2e0a7afb9e6a3f901b802434d8", "max_issues_repo_licenses": ["MIT"], "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.f", "max_forks_repo_name": "Sayan3990/Fortran", "max_forks_repo_head_hexsha": "8e138157be0ffc2e0a7afb9e6a3f901b802434d8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-08-14T03:45:53.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-14T03:45:53.000Z", "avg_line_length": 22.0, "max_line_length": 56, "alphanum_fraction": 0.5303030303, "num_tokens": 105, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767938900121, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.6674533007426675}} {"text": "20 PRINT *, ' Enter x, l (l .lt. 0 to stop)'\n READ *, X,L\n\n IF (L .LT. 0) THEN\n STOP\n ELSE IF (L .EQ. 0) THEN\n PL=0.\n ELSE IF (L .EQ. 1) THEN\n PL=X\n ELSE \n PM=1.\n PZ=X\n DO 10 IL=1,L-1\n PP=((2*IL+1)*X*PZ-IL*PM)/(IL+1)\n PM=PZ\n PZ=PP\n10 CONTINUE\n PL=PZ\n END IF\n \n PRINT *,X,L,PL\n GOTO 20\n END \n", "meta": {"hexsha": "c5fc8da01ab00c57e6ae3734bab11e01849ee962", "size": 475, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "Source-Koonin-Code/WarmUp/chap4a.for", "max_stars_repo_name": "ajz34/Comp-Phys-Koonin", "max_stars_repo_head_hexsha": "9fc371bdb44b7030025d254eda040a55bfa3b7cd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-10-29T12:21:38.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-31T17:03:43.000Z", "max_issues_repo_path": "Source-Koonin-Code/WarmUp/chap4a.for", "max_issues_repo_name": "ajz34/Comp-Phys-Koonin", "max_issues_repo_head_hexsha": "9fc371bdb44b7030025d254eda040a55bfa3b7cd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Source-Koonin-Code/WarmUp/chap4a.for", "max_forks_repo_name": "ajz34/Comp-Phys-Koonin", "max_forks_repo_head_hexsha": "9fc371bdb44b7030025d254eda040a55bfa3b7cd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.7916666667, "max_line_length": 48, "alphanum_fraction": 0.3326315789, "num_tokens": 164, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.6674532958682877}} {"text": "!Josh Adams combined these routines to solve the incomplete Beta\n!function for the calculation of the gNFW potential. The integral \n!needing solution is from Zhao'96, Eq A2 as B(a,b,x)=\n!int(dt*t^(a-1)*(1-t)^(b-1),0,x). I have taken routines from numrec, \n!but removed some unnecessary normalization. We also want the complete \n!beta function, which can be simply related to the gamma function. \n!To avoid conflicts with the \n!original routines, I've prefixed zh_ to all the routines herein.\n FUNCTION zh_betai(a,b,x)\n use numeric_kinds\n Real(kind=dp):: zh_betai,a,b,x,zh_beta\n!U USES betacf,gammln\n Real(kind=dp):: bt,zh_betacf,zh_gammln\n if(x.lt.0.0_dp.or.x.gt.1.0_dp) print*, 'bad argument x in zh_betai'\n if(x.eq.0.0_dp)then\n bt=0.0_dp\n else if(x.eq.1.0_dp)then\n bt=zh_beta(a,b)\n return\n else\n bt=x**a*(1.0_dp-x)**b\n endif\n if(x.lt.(a+1.0_dp)/(a+b+2.0_dp).or.b.le.0.0_dp)then\n!Can't use the inverse relation with b=0 b/c beta_comp will be infinite.\n zh_betai=bt*zh_betacf(a,b,x)/a\n return\n else\n zh_betai=zh_beta(a,b)-bt*zh_betacf(b,a,1.0_dp-x)/b\n return\n endif\n END\n!---------------------------------------------------------------\n FUNCTION zh_beta(z,w)\n use numeric_kinds\n Real(kind=dp):: zh_beta,w,z\n!U USES gammln\n Real(kind=dp):: zh_gammln\n zh_beta=exp(zh_gammln(z)+zh_gammln(w)-zh_gammln(z+w))\n return\n END\n!---------------------------------------------------------------\n FUNCTION zh_betacf(a,b,x)\n use numeric_kinds\n INTEGER(kind=i4b):: MAXIT\n Real(kind=dp):: zh_betacf,a,b,x,EPS,FPMIN\n PARAMETER (MAXIT=500,EPS=3.e-7_dp,FPMIN=1.e-30_dp)\n INTEGER(kind=i4b):: m,m2\n Real(kind=dp):: aa,c,d,del,h,qab,qam,qap\n qab=a+b\n qap=a+1.0_dp\n qam=a-1.0_dp\n c=1.0_dp\n d=1.0_dp-qab*x/qap\n if(abs(d).lt.FPMIN)d=FPMIN\n d=1.0_dp/d\n h=d\n do 11 m=1,MAXIT\n m2=2*m\n aa=m*(b-m)*x/((qam+m2)*(a+m2))\n d=1.0_dp+aa*d\n if(abs(d).lt.FPMIN)d=FPMIN\n c=1.0_dp+aa/c\n if(abs(c).lt.FPMIN)c=FPMIN\n d=1.0_dp/d\n h=h*d*c\n aa=-(a+m)*(qab+m)*x/((a+m2)*(qap+m2))\n d=1.0_dp+aa*d\n if(abs(d).lt.FPMIN)d=FPMIN\n c=1.0_dp+aa/c\n if(abs(c).lt.FPMIN)c=FPMIN\n d=1.0_dp/d\n del=d*c\n h=h*del\n if(abs(del-1.0_dp).lt.EPS)goto 1\n11 continue\n print*, 'a or b too big, or MAXIT too small in zh_betacf', a, b, &\nx, abs(del-1.0_dp)\n1 zh_betacf=h\n return\n END\n!---------------------------------------------------------------\n FUNCTION zh_gammln(xx)\n use numeric_kinds\n Real(kind=dp):: zh_gammln,xx\n INTEGER(kind=i4b):: j\n Real(kind=dp):: ser,stp,tmp,x,y,cof(6)\n SAVE cof,stp\n DATA cof,stp/76.18009172947146_dp,-86.50532032941677_dp,&\n 24.01409824083091_dp,-1.231739572450155_dp,.1208650973866179e-2_dp,&\n -.5395239384953e-5_dp,2.5066282746310005_dp/\n x=xx\n y=x\n tmp=x+5.5_dp\n tmp=(x+0.5_dp)*log(tmp)-tmp\n ser=1.000000000190015_dp\n do 11 j=1,6\n y=y+1.0_dp\n ser=ser+cof(j)/y\n11 continue\n zh_gammln=tmp+log(stp*ser/x)\n return\n END\n!---------------------------------------------------------------\n", "meta": {"hexsha": "113b122354fbd327f5777446909652020c5ebd90", "size": 3332, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "legacy_fortran/sub/specfunc_beta.f90", "max_stars_repo_name": "dynamics-of-stellar-systems/dynamite_release", "max_stars_repo_head_hexsha": "a921d8a1bde98f48daeea78213fb17b3edb223bb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-10-14T12:22:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-31T15:32:59.000Z", "max_issues_repo_path": "legacy_fortran/sub/specfunc_beta.f90", "max_issues_repo_name": "dynamics-of-stellar-systems/dynamite_release", "max_issues_repo_head_hexsha": "a921d8a1bde98f48daeea78213fb17b3edb223bb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2022-02-25T16:05:40.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T15:15:16.000Z", "max_forks_repo_path": "legacy_fortran/sub/specfunc_beta.f90", "max_forks_repo_name": "dynamics-of-stellar-systems/dynamite", "max_forks_repo_head_hexsha": "5ccf936e4b1cd907db8dd7070d4ad204ed913337", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-11-04T04:36:40.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-01T01:07:38.000Z", "avg_line_length": 32.0384615385, "max_line_length": 74, "alphanum_fraction": 0.5441176471, "num_tokens": 1157, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767810736693, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.6674532909939079}} {"text": "program outcomes\n\n integer, dimension(1:10) :: deck\n integer :: d,n,p\n integer, external :: partitions\n \n deck = (/ (4, i = 1,10) /)\n deck(10) = 16\n\n d = 0\n \n do i = 1, 10\n ! Dealer showing\n deck(i) = deck(i)-1\n\n p = 0\n do j = 1, 10\n deck(j) = deck(j)-1\n n = partitions(deck, j)\n deck(j) = deck(j)+1\n p = p+n\n end do\n\n print *,\"Dealer showing \",i,\" partitions =\",p\n d = d+p\n deck(i) = deck(i)+1\n end do\n\n print *,\"Total partitions =\",d\n \nend program outcomes\n\nrecursive integer function partitions(cards,subtotal) result(m)\n integer :: total\n integer, dimension(1:10) :: cards\n integer :: subtotal\n\n m = 0\n ! Hit\n do i = 1, 10\n if (cards(i)>0) then\n total = subtotal+i\n if (total < 21) then\n ! Stand\n m = m+1\n ! Hit again\n cards(i) = cards(i)-1\n m = m+partitions(cards, total)\n cards(i) = cards(i)+1\n else if (total==21) then\n ! Stand; hit again is an automatic bust\n m = m+1\n exit\n end if\n end if\n end do\nend function partitions\n", "meta": {"hexsha": "0ac573d934c865d2fa68391c084ddead84fbdaaa", "size": 1134, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/outcomes.f90", "max_stars_repo_name": "octonion/recursion", "max_stars_repo_head_hexsha": "0c2516e67faa5b60f5286fb2d7e66abb2d50e113", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-10-03T21:04:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-14T20:32:21.000Z", "max_issues_repo_path": "fortran/outcomes.f90", "max_issues_repo_name": "octonion/recursion", "max_issues_repo_head_hexsha": "0c2516e67faa5b60f5286fb2d7e66abb2d50e113", "max_issues_repo_licenses": ["MIT"], "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/outcomes.f90", "max_forks_repo_name": "octonion/recursion", "max_forks_repo_head_hexsha": "0c2516e67faa5b60f5286fb2d7e66abb2d50e113", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-08-20T23:54:55.000Z", "max_forks_repo_forks_event_max_datetime": "2020-01-03T17:52:11.000Z", "avg_line_length": 19.5517241379, "max_line_length": 63, "alphanum_fraction": 0.5061728395, "num_tokens": 358, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767938900121, "lm_q2_score": 0.7606506418255927, "lm_q1q2_score": 0.6674532864595011}} {"text": "subroutine bondseek(n,positions,r0,r1,bn)\n\n implicit none\n\n integer*4, intent(in) :: n\n real*8, intent(in) :: r0,r1\n real*8, intent(in) :: positions(n,3)\n\n integer*4 :: i,j,k\n integer*4, intent(out) :: bn\n\n real*8 :: xi,yi,zi,xj,yj,zj,dx,dy,dz,mdl\n\n bn = 0\n\n do i = 1, (n - 1)\n xi = positions(i,1)\n yi = positions(i,2)\n zi = positions(i,3)\n do j = 1, n\n if (i .ge. j) cycle\n xj = positions(j,1)\n yj = positions(j,2)\n zj = positions(j,3)\n\n dx = abs(xj - xi)\n dy = abs(yj - yi)\n dz = abs(zj - zi)\n\n mdl = sqrt(dx * dx + dy * dy + dz * dz)\n\n if (mdl .ge. r0 .and. mdl .le. r1) bn = bn + 1\n\n end do\n end do\n return\nend subroutine bondseek\n\n", "meta": {"hexsha": "8aceb8ffee08d7fb7be2f05c0425fe3bb79a801a", "size": 827, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "modules/analysis/bseek.f90", "max_stars_repo_name": "alfredometere/PASYVAT", "max_stars_repo_head_hexsha": "d814017df238ac974115656fc7f1157043c590aa", "max_stars_repo_licenses": ["FSFAP"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "modules/analysis/bseek.f90", "max_issues_repo_name": "alfredometere/PASYVAT", "max_issues_repo_head_hexsha": "d814017df238ac974115656fc7f1157043c590aa", "max_issues_repo_licenses": ["FSFAP"], "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/analysis/bseek.f90", "max_forks_repo_name": "alfredometere/PASYVAT", "max_forks_repo_head_hexsha": "d814017df238ac974115656fc7f1157043c590aa", "max_forks_repo_licenses": ["FSFAP"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.2051282051, "max_line_length": 58, "alphanum_fraction": 0.4474002418, "num_tokens": 282, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767810736693, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6674532862328526}} {"text": "program test1\n\n use multigrid\n\n implicit none\n\n integer, parameter :: num=selected_real_kind(p=15)\n real(num) :: pi = 4.0_num * ATAN(1.0_num)\n\n integer :: nx, ny, ix, iy\n\n real(num) :: dx, dy, L2, x_min, x_max, y_min, y_max\n\n real(num), dimension(:), allocatable :: xc, yc\n\n real(num), dimension(:,:), allocatable :: utrue, vtrue\n real(num), dimension(:,:), allocatable :: upol, vpol\n real(num), dimension(:,:), allocatable :: divu, phi\n\n type(mg_input) :: input \n\n ! setup a test problem \n\n\n nx = 256\n ny = nx\n x_min = 0.0_num\n x_max = 1.0_num\n y_min = x_min\n y_max = x_max\n\n print *,'Test1: Projection test, periodic, constant coeffs Poission'\n print *,'This tests the ability of MG to solve L(phi) = div(U)'\n print *,'in order to clean divergence from a polluted velocity field' \n\n allocate(xc(-1:nx+2))\n allocate(yc(-1:ny+2))\n\n dx = (x_max - x_min) / real(nx,num)\n xc(-1) = x_min - 3.0_num * dx / 2.0_num \n do ix = 0,nx+2\n xc(ix) = xc(ix-1) + dx\n enddo\n\n dy = (y_max - y_min) / real(ny,num)\n yc(-1) = y_min - 3.0_num * dy / 2.0_num \n do iy = 0,ny+2\n yc(iy) = yc(iy-1) + dy\n enddo\n\n allocate(phi(-1:nx+2,-1:ny+2)) ! again, redundant ghosts but for comparison to CCAPS\n phi = 0.0_num \n\n\n allocate(utrue(0:nx+1,0:ny+1)) !no need for ghosts in the test case\n allocate(vtrue(0:nx+1,0:ny+1))\n allocate(upol(0:nx+1,0:ny+1))\n allocate(vpol(0:nx+1,0:ny+1))\n allocate(divu(1:nx,1:ny))\n \n do iy = 0, ny+1\n do ix = 0, nx+1\n utrue(ix,iy) = - sin(1.0_num * pi * xc(ix))**2 & \n & * sin(2.0_num * pi * yc(iy))\n vtrue(ix,iy) = sin(1.0_num * pi * yc(iy))**2 &\n & * sin(2.0_num * pi * xc(ix))\n \n upol(ix,iy) = utrue(ix,iy) - & \n & 0.2_num * pi * cos(2.0_num * pi * yc(iy)) &\n & * sin(2.0_num * pi * xc(ix)) \n vpol(ix,iy) = vtrue(ix,iy) - & \n & 0.2_num * pi * sin(2.0_num * pi * yc(iy)) & \n & * cos(2.0_num * pi * xc(ix))\n enddo\n enddo\n\n do iy = 1, ny \n do ix = 1, nx \n divu(ix,iy) = (upol(ix+1,iy) - upol(ix-1,iy)) / 2.0_num / dx + & \n & (vpol(ix,iy+1) - vpol(ix,iy-1)) / 2.0_num / dy\n enddo\n enddo\n \n print *, 'max divu before cleaning',maxval(divu)\n L2 = sqrt(sum(abs(utrue(1:nx,1:ny)-upol(1:nx,1:ny))**2) / real(nx*ny,num))\n print *, 'L2 (utrue vs upol) before cleaning',L2\n L2 = sqrt(sum(abs(vtrue(1:nx,1:ny)-vpol(1:nx,1:ny))**2) / real(nx*ny,num))\n print *, 'L2 (vtrue vs vpol) before cleaning',L2\n\n ! create the input state object\n\n input = mg_input(tol = 1e-12_num, nx=nx, ny = ny, dx=dx, dy=dy, f = divu, phi = phi, &\n & bc_xmin = 'periodic', bc_ymin='periodic', bc_xmax='periodic', bc_ymax = 'periodic')\n\n call mg_interface(input)\n\n phi = input%phi\n\n!STOP\n\n ! solve for phi\n! nlevels = -1 ! auto\n! call mg_interface(f = divu, phi=phi, tol = 1e-12_num, &\n! & nx = nx, ny = ny, dx = dx, dy = dy, &\n! & nlevels = nlevels, &\n! & bc_xmin_in = periodic, bc_ymin_in = periodic, bc_xmax_in = periodic, bc_ymax_in=periodic)\n\n \n\n ! correct it \n \n do iy = 1, ny\n do ix = 1, nx\n upol(ix,iy) = upol(ix,iy) - 0.5_num*(phi(ix+1,iy)-phi(ix-1,iy))/dx\n vpol(ix,iy) = vpol(ix,iy) - 0.5_num*(phi(ix,iy+1)-phi(ix,iy-1))/dy\n enddo\n enddo\n \n ! apply periodic bc to the polluted vels and then re calc divu\n upol(0,:) = upol(nx,:)\n upol(nx+1,:) = upol(1,:)\n upol(:,0) = upol(:,ny)\n upol(:,ny+1) = upol(:,1)\n vpol(0,:) = vpol(nx,:)\n vpol(nx+1,:) = vpol(1,:)\n vpol(:,0) = vpol(:,ny)\n vpol(:,ny+1) = vpol(:,1)\n \n do iy = 1, ny \n do ix = 1, nx \n divu(ix,iy) = (upol(ix+1,iy) - upol(ix-1,iy)) / 2.0_num / dx + & \n & (vpol(ix,iy+1) - vpol(ix,iy-1)) / 2.0_num / dy\n enddo\n enddo\n \n print *, 'max divu after cleaning',maxval(divu)\n L2 = sqrt(sum(abs(utrue(1:nx,1:ny)-upol(1:nx,1:ny))**2) / real(nx*ny,num))\n print *, 'L2 (utrue vs upol) after cleaning',L2\n L2 = sqrt(sum(abs(vtrue(1:nx,1:ny)-vpol(1:nx,1:ny))**2) / real(nx*ny,num))\n print *, 'L2 (vtrue vs vpol) after cleaning',L2\n\n\n\nend program test1\n", "meta": {"hexsha": "f5da72694c3cadecc72141071d6b9ab134e33638", "size": 3988, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "multigrid/2D/test1.f90", "max_stars_repo_name": "JOThurgood/SimpleCFD", "max_stars_repo_head_hexsha": "d0dc2fae9dab21c33d50b443caa727fa763c95d9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-04-23T05:31:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-04T23:21:11.000Z", "max_issues_repo_path": "multigrid/2D/test1.f90", "max_issues_repo_name": "JOThurgood/SimpleCFD", "max_issues_repo_head_hexsha": "d0dc2fae9dab21c33d50b443caa727fa763c95d9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 39, "max_issues_repo_issues_event_min_datetime": "2018-08-31T23:48:02.000Z", "max_issues_repo_issues_event_max_datetime": "2019-08-07T10:03:11.000Z", "max_forks_repo_path": "multigrid/2D/test1.f90", "max_forks_repo_name": "JOThurgood/SimpleCFD", "max_forks_repo_head_hexsha": "d0dc2fae9dab21c33d50b443caa727fa763c95d9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-11-14T20:42:54.000Z", "max_forks_repo_forks_event_max_datetime": "2019-05-18T09:16:27.000Z", "avg_line_length": 27.5034482759, "max_line_length": 97, "alphanum_fraction": 0.5659478435, "num_tokens": 1655, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767810736694, "lm_q2_score": 0.7606506418255928, "lm_q1q2_score": 0.6674532767107418}} {"text": "module integration\n\n use pde\n use global_module\n\n implicit none\n \n real(kind=8), dimension(Neq,Nx,Ny) :: U_new ! Working variable\n\n contains\n\n ! ======================================================================== \n \n subroutine forward_Euler_step(U, dt)\n\n ! This function performs one step of the Forward Euler explicit time integrator \n\n implicit none\n \n real(kind=8), dimension(Neq,Nx,Ny), intent(inout) :: U\n\n real(kind=8), intent(in) :: dt\n integer :: i, j, eqID\n \n real(kind=8), dimension(Neq) :: F_N, F_S, F_W, F_E, S\n real(kind=8) :: rho, tau_v, e_vib_eq, e_vib\n\n ! First, assign BCs. Wall BCs need to be updated in time, taking the value\n ! from neighboring cells.\n call assign_BCs(U) ! See the pde.f03 module\n\n ! Update solution using the forward Euler integrator - INTERNAL CELLS only\n do j = 3, Ny-2\n do i = 3, Nx-2\n\n call compute_fluxes_HLL(U, i, j, F_N, F_S, F_W, F_E)\n ! call compute_fluxes_Rusanov(U, i, j, F_N, F_S, F_W, F_E)\n\n call introduce_flat_plate(U, i, j, F_N, F_S, F_W, F_E)\n\n ! Advect remaining stuff\n U_new(:,i,j) = U(:,i,j) - dt/dx*(F_E - F_W) - dt/dy*(F_N - F_S) ! NO SOURCE TERM\n\n ! Add source term to vibration only, in an implicit way\n ! (it's simple because it's linear)\n call compute_source_term(U_new(:,i,j), S, tau_v, e_vib_eq, e_vib)\n rho = U_new(1,i,j) \n U_new(5,i,j) = rho*(e_vib + dt/tau_v*e_vib_eq)/(1.0 + dt/tau_v)\n \n ! Check that the solution did not diverge\n do eqID = 1, Neq\n if (isnan(U_new(eqID,i,j))) then \n print*, 'Solution diverged, try with a smaller time step! Aborting.'\n print*, 'Solution that diverged: ', U_new(:,i,j)\n print*, 'in cell i,j = ', i, j\n stop\n end if\n end do\n\n end do\n end do\n\n ! Save solution (internal cells ONLY! Do not overwrite ghost cells!)\n U(:,3:Nx-2,3:Ny-2) = U_new(:,3:Nx-2,3:Ny-2)\n\n end subroutine\n\n ! ======================================================================== \n\n subroutine compute_fluxes_HLL(U, i, j, F_N, F_S, F_W, F_E)\n\n ! Computes Rusanov numerical fluxes for the cell (i,j)\n\n implicit none\n\n real(kind=8), dimension(Neq,Nx,Ny), intent(in) :: U\n real(kind=8), dimension(Neq), intent(out) :: F_N, F_S, F_W, F_E \n integer, intent(in) :: i, j\n\n integer :: eqID\n real(kind=8), dimension(Neq) :: U_L, U_R, F_L, F_R\n\n real(kind=8) :: ws_min_L, ws_max_L, ws_min_R, ws_max_R, ws_min, ws_max ! wave speeds\n\n ! ------ North interface\n U_L = U(:,i,j)\n U_R = U(:,i,j+1)\n\n call compute_flux_ws_y(U_L, F_L, ws_max_L, ws_min_L)\n call compute_flux_ws_y(U_R, F_R, ws_max_R, ws_min_R)\n\n ws_min = MIN(ws_min_L, ws_min_R)\n ws_max = MAX(ws_max_L, ws_max_R)\n\n ! HLL fluxes\n if (ws_min .ge. 0.0) then\n F_N = F_L\n else if (ws_max .lt. 0.0) then\n F_N = F_R\n else\n F_N = (ws_min*ws_max*(U_R - U_L) + ws_max*F_L - ws_min*F_R)/(ws_max - ws_min);\n end if\n\n ! Update global maximum wave speed (used for setting the time step)\n\n ws_max = MAX(ABS(ws_max_L), ABS(ws_min_L), ABS(ws_max_R), ABS(ws_min_R))\n ws_maxabs = MAX(ws_maxabs, ws_max)\n\n ! ------ South interface\n U_L = U(:,i,j-1)\n U_R = U(:,i,j)\n\n call compute_flux_ws_y(U_L, F_L, ws_max_L, ws_min_L)\n call compute_flux_ws_y(U_R, F_R, ws_max_R, ws_min_R)\n\n ws_min = MIN(ws_min_L, ws_min_R)\n ws_max = MAX(ws_max_L, ws_max_R)\n\n ! HLL fluxes\n if (ws_min .ge. 0.0) then\n F_S = F_L\n else if (ws_max .lt. 0.0) then\n F_S = F_R\n else\n F_S = (ws_min*ws_max*(U_R - U_L) + ws_max*F_L - ws_min*F_R)/(ws_max - ws_min);\n end if\n\n ! Update global maximum wave speed (used for setting the time step)\n ws_max = MAX(ABS(ws_max_L), ABS(ws_min_L), ABS(ws_max_R), ABS(ws_min_R))\n ws_maxabs = MAX(ws_maxabs, ws_max)\n\n ! ------ East interface\n U_L = U(:,i,j)\n U_R = U(:,i+1,j)\n\n call compute_flux_ws_x(U_L, F_L, ws_max_L, ws_min_L)\n call compute_flux_ws_x(U_R, F_R, ws_max_R, ws_min_R)\n\n ws_min = MIN(ws_min_L, ws_min_R)\n ws_max = MAX(ws_max_L, ws_max_R)\n \n ! HLL fluxes\n if (ws_min .ge. 0.0) then\n F_E = F_L\n else if (ws_max .lt. 0.0) then\n F_E = F_R\n else\n F_E = (ws_min*ws_max*(U_R - U_L) + ws_max*F_L - ws_min*F_R)/(ws_max - ws_min);\n end if\n\n ! Update global maximum wave speed (used for setting the time step)\n ws_max = MAX(ABS(ws_max_L), ABS(ws_min_L), ABS(ws_max_R), ABS(ws_min_R))\n ws_maxabs = MAX(ws_maxabs, ws_max)\n\n ! ------ West interface\n U_L = U(:,i-1,j)\n U_R = U(:,i,j)\n\n call compute_flux_ws_x(U_L, F_L, ws_max_L, ws_min_L)\n call compute_flux_ws_x(U_R, F_R, ws_max_R, ws_min_R)\n\n ws_min = MIN(ws_min_L, ws_min_R)\n ws_max = MAX(ws_max_L, ws_max_R)\n\n ! HLL fluxes\n if (ws_min .ge. 0.0) then\n F_W = F_L\n else if (ws_max .lt. 0.0) then\n F_W = F_R\n else\n F_W = (ws_min*ws_max*(U_R - U_L) + ws_max*F_L - ws_min*F_R)/(ws_max - ws_min);\n end if\n\n ! Update global maximum wave speed (used for setting the time step)\n ws_max = MAX(ABS(ws_max_L), ABS(ws_min_L), ABS(ws_max_R), ABS(ws_min_R))\n ws_maxabs = MAX(ws_maxabs, ws_max)\n\n end subroutine\n\n ! ==============================================\n\n subroutine compute_fluxes_Rusanov(U, i, j, F_N, F_S, F_W, F_E)\n\n ! Computes Rusanov numerical fluxes for the cell (i,j)\n\n implicit none\n\n real(kind=8), dimension(Neq,Nx,Ny), intent(in) :: U\n real(kind=8), dimension(Neq), intent(out) :: F_N, F_S, F_W, F_E \n integer, intent(in) :: i, j\n\n integer :: eqID\n real(kind=8), dimension(Neq) :: U_L, U_R, F_L, F_R\n\n real(kind=8) :: ws_min_L, ws_max_L, ws_min_R, ws_max_R, ws_max ! wave speeds\n\n ! ------ North interface\n U_L = U(:,i,j)\n U_R = U(:,i,j+1)\n\n call compute_flux_ws_y(U_L, F_L, ws_max_L, ws_min_L)\n call compute_flux_ws_y(U_R, F_R, ws_max_R, ws_min_R)\n\n ws_max = MAX(ABS(ws_max_L), ABS(ws_min_L), ABS(ws_max_R), ABS(ws_min_R))\n\n F_N = 0.5*(F_R + F_L) - ws_max/2.0*(U_R-U_L) ! Rusanov flux\n\n ! Update global maximum wave speed (used for setting the time step)\n ws_maxabs = MAX(ws_maxabs, ws_max)\n\n ! ------ South interface\n U_L = U(:,i,j-1)\n U_R = U(:,i,j)\n\n call compute_flux_ws_y(U_L, F_L, ws_max_L, ws_min_L)\n call compute_flux_ws_y(U_R, F_R, ws_max_R, ws_min_R)\n\n ws_max = MAX(ABS(ws_max_L), ABS(ws_min_L), ABS(ws_max_R), ABS(ws_min_R))\n\n F_S = 0.5*(F_R + F_L) - ws_max/2.0*(U_R-U_L) ! Rusanov flux\n\n ! Update global maximum wave speed (used for setting the time step)\n ws_maxabs = MAX(ws_maxabs, ws_max)\n\n ! ------ East interface\n U_L = U(:,i,j)\n U_R = U(:,i+1,j)\n\n call compute_flux_ws_x(U_L, F_L, ws_max_L, ws_min_L)\n call compute_flux_ws_x(U_R, F_R, ws_max_R, ws_min_R)\n\n ws_max = MAX(ABS(ws_max_L), ABS(ws_min_L), ABS(ws_max_R), ABS(ws_min_R))\n\n F_E = 0.5*(F_R + F_L) - ws_max/2.0*(U_R-U_L) ! Rusanov flux\n\n ! Update global maximum wave speed (used for setting the time step)\n ws_maxabs = MAX(ws_maxabs, ws_max)\n\n ! ------ West interface\n U_L = U(:,i-1,j)\n U_R = U(:,i,j)\n\n call compute_flux_ws_x(U_L, F_L, ws_max_L, ws_min_L)\n call compute_flux_ws_x(U_R, F_R, ws_max_R, ws_min_R)\n\n ws_max = MAX(ABS(ws_max_L), ABS(ws_min_L), ABS(ws_max_R), ABS(ws_min_R))\n\n F_W = 0.5*(F_R + F_L) - ws_max/2.0*(U_R-U_L) ! Rusanov flux\n\n ! Update global maximum wave speed (used for setting the time step)\n ws_maxabs = MAX(ws_maxabs, ws_max)\n\n end subroutine\n\n ! ==============================================\n\n\n ! ==============================================\n\n subroutine introduce_flat_plate(U, i, j, F_N, F_S, F_W, F_E)\n\n ! This function introduces a flat plate, by modifying the fluxes, only for the cells \n ! that are in contact with the plate.\n\n implicit none\n\n integer, intent(in) :: i, j\n real(kind=8), dimension(Neq), intent(inout) :: F_N, F_S, F_W, F_E\n real(kind=8), dimension(Neq,Nx,Ny), intent(in) :: U\n\n real(kind=8), dimension(Neq) :: prim_1, prim_2 ! Primitive variables\n real(kind=8) :: P_1, P_2, Pw\n\n ! The indices j_plate, i_1_plate, i_2_plate identify the plate position.\n ! They are defined in global_module.f03\n\n if (j .EQ. j_plate) then ! Cells below the plate\n\n if ( (i .GE. i_1_plate) .AND. (i .LE. i_2_plate) ) then ! Cells in contact with the plate\n\n ! -------\n ! These cells are BELOW the plate. Change F_N \n ! -------\n\n ! Simple computation of the wall pressure\n ! call compute_primitive_from_conserved(U(:,i,j), prim_1)\n ! P_1 = prim_1(1)/M*kB*prim_1(4) ! P = n*kB*T = rho/M*kB*T\n ! Pw = P_1 ! Reconstruct wall pressure\n\n ! Two-point extrapolation of the wall pressure (see Blazek, Computational Fluid Dynamics)\n call compute_primitive_from_conserved(U(:,i,j), prim_1)\n call compute_primitive_from_conserved(U(:,i,j-1), prim_2)\n P_1 = prim_1(1)/M*kB*prim_1(4) ! P = n*kB*T = rho/M*kB*T\n P_2 = prim_2(1)/M*kB*prim_2(4) ! P = n*kB*T = rho/M*kB*T\n Pw = 0.5*(3.0*P_1 - P_2) ! Reconstruct wall pressure\n\n ! Only pressure normal to the wall remains\n F_N(1) = 0.0\n F_N(2) = 0.0\n F_N(3) = Pw\n F_N(4) = 0.0\n F_N(5) = 0.0\n\n end if\n\n else if (j .EQ. j_plate + 1) then ! Cells ABOVE the plate\n\n if ( (i .GE. i_1_plate) .AND. (i .LE. i_2_plate) ) then ! Cells in contact with the plate\n\n ! -------\n ! These cells are ABOVE the plate. Change F_S\n ! -------\n\n ! Simple computation of the wall pressure\n ! call compute_primitive_from_conserved(U(:,i,j), prim_1)\n ! P_1 = prim_1(1)/M*kB*prim_1(4) ! P = n*kB*T = rho/M*kB*T\n ! Pw = P_1 ! Reconstruct wall pressure\n\n ! Two-point extrapolation of the wall pressure (see Blazek, Computational Fluid Dynamics)\n call compute_primitive_from_conserved(U(:,i,j), prim_1)\n call compute_primitive_from_conserved(U(:,i,j+1), prim_2)\n P_1 = prim_1(1)/M*kB*prim_1(4) ! P = n*kB*T = rho/M*kB*T\n P_2 = prim_2(1)/M*kB*prim_2(4) ! P = n*kB*T = rho/M*kB*T\n Pw = 0.5*(3.0*P_1 - P_2) ! Reconstruct wall pressure\n\n ! Only pressure normal to the wall remains\n F_S(1) = 0.0\n F_S(2) = 0.0\n F_S(3) = Pw\n F_S(4) = 0.0\n F_S(5) = 0.0\n\n end if\n\n end if\n\n end subroutine\n\nend module\n", "meta": {"hexsha": "11dbec736307ec91287d2ed201f30619f77ab64a", "size": 10454, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "hyper2D_single_core/hyper2D_hypersonic/src/other_files/integration_point_implicit.f03", "max_stars_repo_name": "sbocce/hyper2D", "max_stars_repo_head_hexsha": "7d1510ac3947b2c154aa0c09945ff05db4bfc8c4", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2022-02-17T14:26:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T01:56:37.000Z", "max_issues_repo_path": "hyper2D_single_core/hyper2D_hypersonic/src/other_files/integration_point_implicit.f03", "max_issues_repo_name": "sbocce/hyper2D", "max_issues_repo_head_hexsha": "7d1510ac3947b2c154aa0c09945ff05db4bfc8c4", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2022-02-28T10:22:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-01T06:25:03.000Z", "max_forks_repo_path": "hyper2D_single_core/hyper2D_hypersonic/src/other_files/integration_point_implicit.f03", "max_forks_repo_name": "sbocce/hyper2D", "max_forks_repo_head_hexsha": "7d1510ac3947b2c154aa0c09945ff05db4bfc8c4", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.7470588235, "max_line_length": 97, "alphanum_fraction": 0.5914482495, "num_tokens": 3507, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436482, "lm_q2_score": 0.724870282120402, "lm_q1q2_score": 0.6674530689853966}} {"text": "!\n! wavy - A spectral ocean wave modeling and development framework\n! Copyright (c) 2017, Wavebit Scientific LLC\n! All rights reserved.\n!\n! Licensed under the BSD-3 clause license. See LICENSE for details.\n!\n!===============================================================================\nmodule mod_linear_wave_theory\n\nuse mod_precision,only:intkind,realkind\n\nimplicit none\n\nprivate\n\npublic :: elevation\npublic :: pressure\npublic :: horizontalAcceleration\npublic :: horizontalVelocity\npublic :: verticalAcceleration\npublic :: verticalVelocity\n\n!===============================================================================\ncontains\n\n\n\n!-------------------------------------------------------------------------------\npure elemental real(kind=realkind) function elevation(x,t,a,k,omega)\n\n !! Returns the elevation [m] of a sinusoid wave given its amplitude [m],\n !! wavenumber [rad/m], and frequency [Hz].\n\n real(kind=realkind),intent(in) :: x\n !! Horizontal space [m]\n real(kind=realkind),intent(in) :: t\n !! Time [s]\n real(kind=realkind),intent(in) :: a\n !! Wave amplitude [m]\n real(kind=realkind),intent(in) :: k\n !! Wavenumber [rad/m]\n real(kind=realkind),intent(in) :: omega\n !! Angular frequency [rad]\n\n elevation = a*sin(k*x-omega*t)\n\nendfunction elevation\n!-------------------------------------------------------------------------------\n\n\n\n!-------------------------------------------------------------------------------\npure elemental real(kind=realkind) function pressure(x,z,t,a,k,omega,rho,grav)\n\n !! Returns the pressure [Pa] at depth z (negative downward) for a sinusoid\n !! wave given its amplitude [m], wavenumber [rad/m], and frequency [Hz].\n\n real(kind=realkind),intent(in) :: x\n !! Horizontal space [m]\n real(kind=realkind),intent(in) :: z\n !! Vertical displacement [m] from the surface, negative downward\n real(kind=realkind),intent(in) :: t\n !! Time [s]\n real(kind=realkind),intent(in) :: a\n !! Wave amplitude [m]\n real(kind=realkind),intent(in) :: k\n !! Wavenumber [rad/m]\n real(kind=realkind),intent(in) :: omega\n !! Angular frequency [rad]\n real(kind=realkind),intent(in) :: rho\n !! Water density [kg/m^3]\n real(kind=realkind),intent(in) :: grav\n !! Gravitational acceleration [m/s^2]\n\n pressure = -rho*grav*(elevation(x,t,a,k,omega)-z)\n\nendfunction pressure\n!-------------------------------------------------------------------------------\n\n\n\n!-------------------------------------------------------------------------------\npure elemental real(kind=realkind) function horizontalAcceleration(x,z,t,a,k,omega)\n\n !! Returns the horizontal acceleration of a water particle under a sinusoid wave,\n !! given its amplitude, wavenumber, and frequency.\n\n real(kind=realkind),intent(in) :: x\n !! Horizontal space [m]\n real(kind=realkind),intent(in) :: z\n !! Vertical space, negative downward [m]\n real(kind=realkind),intent(in) :: t\n !! Time [s]\n real(kind=realkind),intent(in) :: a\n !! Wave amplitude [m]\n real(kind=realkind),intent(in) :: k\n !! Wavenumber [rad/m]\n real(kind=realkind),intent(in) :: omega\n !! Angular frequency [rad]\n\n horizontalAcceleration = -a*omega**2*cos(k*x-omega*t)*exp(k*z)\n\nendfunction horizontalAcceleration\n!-------------------------------------------------------------------------------\n\n\n\n!-------------------------------------------------------------------------------\npure elemental real(kind=realkind) function horizontalVelocity(x,z,t,a,k,omega)\n\n !! Returns the horizontal velocity of a water particle under a sinusoid wave,\n !! given its amplitude, wavenumber, and frequency.\n\n real(kind=realkind),intent(in) :: x\n !! Horizontal space [m]\n real(kind=realkind),intent(in) :: z\n !! Vertical space, negative downward [m]\n real(kind=realkind),intent(in) :: t\n !! Time [s]\n real(kind=realkind),intent(in) :: a\n !! Wave amplitude [m]\n real(kind=realkind),intent(in) :: k\n !! Wavenumber [rad/m]\n real(kind=realkind),intent(in) :: omega\n !! Angular frequency [rad]\n\n horizontalVelocity = a*omega*sin(k*x-omega*t)*exp(k*z)\n\nendfunction horizontalVelocity\n!-------------------------------------------------------------------------------\n\n\n\n!-------------------------------------------------------------------------------\npure elemental real(kind=realkind)&\n function verticalAcceleration(x,z,t,a,k,omega)\n\n !! Returns the vertical acceleration of a water particle under a sinusoid wave,\n !! given its amplitude, wavenumber, and frequency.\n\n real(kind=realkind),intent(in) :: x\n !! Horizontal space [m]\n real(kind=realkind),intent(in) :: z\n !! Vertical space, negative downward [m]\n real(kind=realkind),intent(in) :: t\n !! Time [s]\n real(kind=realkind),intent(in) :: a\n !! Wave amplitude [m]\n real(kind=realkind),intent(in) :: k\n !! Wavenumber [rad/m]\n real(kind=realkind),intent(in) :: omega\n !! Angular frequency [rad]\n\n verticalAcceleration = -a*omega**2*sin(k*x-omega*t)*exp(k*z)\n\nendfunction verticalAcceleration\n!-------------------------------------------------------------------------------\n\n\n\n!-------------------------------------------------------------------------------\npure elemental real(kind=realkind) function verticalVelocity(x,z,t,a,k,omega)\n\n !! Returns the vertical velocity of a water particle under a sinusoid wave,\n !! given its amplitude, wavenumber, and frequency.\n\n real(kind=realkind),intent(in) :: x\n !! Horizontal space [m]\n real(kind=realkind),intent(in) :: z\n !! Vertical space, negative downward [m]\n real(kind=realkind),intent(in) :: t\n !! Time [s]\n real(kind=realkind),intent(in) :: a\n !! Wave amplitude [m]\n real(kind=realkind),intent(in) :: k\n !! Wavenumber [rad/m]\n real(kind=realkind),intent(in) :: omega\n !! Angular frequency [rad]\n\n verticalVelocity = -a*omega*cos(k*x-omega*t)*exp(k*z)\n\nendfunction verticalVelocity\n!-------------------------------------------------------------------------------\nendmodule mod_linear_wave_theory\n", "meta": {"hexsha": "dbd4769d449da8593b597806b9193188e83e7832", "size": 5980, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/lib/mod_linear_wave_theory.f90", "max_stars_repo_name": "dksasaki/wavy", "max_stars_repo_head_hexsha": "95242818fca6d09f1e15e641dc9b978b5793eee5", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2017-06-20T19:00:02.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-04T13:19:30.000Z", "max_issues_repo_path": "src/lib/mod_linear_wave_theory.f90", "max_issues_repo_name": "dksasaki/wavy", "max_issues_repo_head_hexsha": "95242818fca6d09f1e15e641dc9b978b5793eee5", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2017-06-22T15:23:31.000Z", "max_issues_repo_issues_event_max_datetime": "2019-11-21T21:10:35.000Z", "max_forks_repo_path": "src/lib/mod_linear_wave_theory.f90", "max_forks_repo_name": "dksasaki/wavy", "max_forks_repo_head_hexsha": "95242818fca6d09f1e15e641dc9b978b5793eee5", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2017-10-27T13:28:27.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-06T15:01:08.000Z", "avg_line_length": 32.1505376344, "max_line_length": 83, "alphanum_fraction": 0.5585284281, "num_tokens": 1375, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896845856298, "lm_q2_score": 0.7248702702332475, "lm_q1q2_score": 0.6674530674935721}} {"text": "c gmm01f\r\nc sub. besselyd.f (in double precision arithmetic)\r\nc THIS FILE IS PART OF THE ORIGINAL GMM01F DISTRIBUTION\r\nc returns an array of the spherical Bessel function of\r\nc the second kind with a real argument: y_0,y_1,...,y_n\r\n subroutine besselyd(n,x,besy)\r\n implicit logical (a-z)\r\n \r\nC SUBROUTINE PARAMETERS\r\n integer n\r\n double precision x,besy(0:n)\r\n \r\nC LOCAL VARIABLES\r\n integer i\r\n double precision besyn,x2\r\n \r\n if(x .eq. 0.D0) then\r\n write(6,*) 'bad argument in sub. besselyd'\r\n stop\r\n endif\r\n \r\n if(dabs(x)-0.1d0)10,11,11\r\n 10 x2=x*x\r\n besyn=1.d0-x2/72.d0\r\n besyn=1.d0-x2/42.d0*besyn\r\n besyn=1.d0-x2/20.d0*besyn\r\n besyn=1.d0-x2/6.d0*besyn\r\n besy(0)=1.d0-x2/56.d0\r\n besy(0)=1.d0-x2/30.d0*besy(0)\r\n besy(0)=1.d0-x2/12.d0*besy(0)\r\n besy(0)=1.d0-0.5d0*x2*besy(0)\r\n besy(0)=-besy(0)/x\r\n goto 12\r\n 11 besyn=dsin(x)/x\r\n besy(0)=-dcos(x)/x\r\n 12 besy(1)=besy(0)/x-besyn\r\n do i=2,n\r\n besy(i)=dble(2*i-1)/x*besy(i-1)-besy(i-2)\r\n enddo\r\n return\r\n end\r\n", "meta": {"hexsha": "b192104e87951e682f97d00c8feb6cd7984c3caa", "size": 1128, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "GMM_FIELD/src/besselyd.f", "max_stars_repo_name": "m-ringler/GMM-DIP", "max_stars_repo_head_hexsha": "016a4ca0ecf50c9d665cc17fb209031d0093c9a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "GMM_FIELD/src/besselyd.f", "max_issues_repo_name": "m-ringler/GMM-DIP", "max_issues_repo_head_hexsha": "016a4ca0ecf50c9d665cc17fb209031d0093c9a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "GMM_FIELD/src/besselyd.f", "max_forks_repo_name": "m-ringler/GMM-DIP", "max_forks_repo_head_hexsha": "016a4ca0ecf50c9d665cc17fb209031d0093c9a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-11-06T14:43:40.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-07T12:05:00.000Z", "avg_line_length": 26.8571428571, "max_line_length": 57, "alphanum_fraction": 0.5611702128, "num_tokens": 447, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896758909757, "lm_q2_score": 0.7248702642896702, "lm_q1q2_score": 0.6674530557182913}} {"text": "program main\nimplicit none\n\ncall readInput\ncall compute\n\nend program\n\n\nsubroutine compute\n!use para\nimplicit none\ninteger :: covMatResult\n\n call readCovMat(covMatResult)\n if ( covMatResult .lt. 0 ) call computeCovariance\n call computePC\n call projectPC\n\nend subroutine\n\n\nsubroutine projectPC\nuse para\nimplicit none\ninteger :: pc, frame\n\n write(*,'(A,I3,A)') ' Project coordinates to first ', iPC, ' PCs. '\n allocate( PCA(Nframe, iPC) )\n \n ! project to PCs\n do pc = 1, iPC\n !! `matmul` is too slow\n PCA(1:Nframe, pc) = matmul(PCvector(1:Natom3,pc), coord1D(1:Natom3,1:Nframe))\n !call matrixMul(1, Natom3, Nframe, &\n ! PCvector(1:Natom3,pc), coord1D(1:Natom3,1:Nframe), &\n ! PCA(1:Nframe, pc))\n end do\n \n ! write to file\n write(*,*) 'Writing PCA to file...'\n open(727, file=trim(fileNamePure)//'_PCA', status='replace', action='write')\n do frame = 1, Nframe\n write(727, '(999999999E18.8)') PCA(frame,1:iPC) \n end do\n close(727)\n\nend subroutine\n\n\nsubroutine computePC\nuse para\nimplicit none\nreal(inum) :: PCvalueSum\ninteger :: i\n\n write(*,*) 'Diagonalizing corvariance matrix... '\n allocate( PCvalue(Natom3), PCvector(Natom3,Natom3) )\n call calcEigenvector(Natom3, cov, PCvalue, PCvector)\n\n !PCvalueSum = dsqrt(sum(PCvalue*PCvalue)) ! normalized\n PCvalueSum = sum(PCvalue) ! sum = 1\n !PCvalue = PCvalue / PCvalueSum\n write(*,*) 'PC value (normalized, first 10): '\n if ( Natom3 .ge. 10 ) then\n write(*,'(5F12.6)') PCvalue(1:10) / PCvalueSum\n else\n write(*,'(5F12.6)') PCvalue(1:Natom3) / PCvalueSum\n end if\n !# write(*,*) 'Sum of PC value: '\n !# write(*,*) PCvalueSum\n !write(*,*) 'PC vector 1: '\n !write(*,'(3F12.6)') PCvector(1:Natom3,1)\n \n ! write PC value\n !! PC value -> value -> val -> 825\n write(*,*) 'Writing PC value...'\n open(825, file=trim(fileNamePure)//'_PCvalue', status='replace', action='write')\n write(825,*) 'PC values with percentages'\n write(825, *) Natom3\n do i = 1, Natom3\n write(825, '(E18.8, 2X, F12.4)') PCvalue(i), PCvalue(i)*100d0/PCvalueSum\n end do\n close(825)\n \n ! write PC vector\n !! PC vector -> vector -> vec -> 832\n write(*,*) 'Writing first 5 PC vectors...'\n open(832, file=trim(fileNamePure)//'_PCvector', status='replace', action='write')\n write(832, *) Natom3\n do i = 1, Natom3\n write(832, '(99999999E18.8)') PCvector(1:5,i)\n end do\n close(832)\n\nend subroutine\n\n\nsubroutine readCovMat(covMatResult)\nuse para\nimplicit none\ninteger, intent(out) :: covMatResult\nlogical covMatStatus\ninteger i\n\n inquire(file=trim(fileNamePure)//'_covMat', exist=covMatStatus)\n if (covMatStatus) then\n write(*,*) 'Covariance matrix exists. Reading... '\n open(268, file=trim(fileNamePure)//'_covMat', status='old', action='read') ! cov mat -> cmt -> 268\n read(268, *); read(268, *) Natom3\n \n if ( mod(Natom3, 3) .ne. 0 ) then\n call logError('Number of atoms*3 is wrong! ')\n else\n Natom = Natom3 / 3\n end if\n \n allocate( cov(Natom3, Natom3) )\n do i = 1, Natom3\n read(268, *) cov(1:Natom3,i)\n end do\n close(268)\n \n covMatResult = 100\n return\n else\n covMatResult = -100\n return\n end if\n\nend subroutine\n\n\nsubroutine computeCovariance\nuse para\nuse omp_lib\nimplicit none\ninteger :: component, i, j\n!integer :: constructCount, constructTotal\n\n write(*,*); write(*,*) 'Principal component analysis! '\n allocate( coordMean(Natom3), cov(Natom3, Natom3) )\n \n ! calculate the mean value of each components\n write(*,*) 'Calculating the mean value of each components...'\n !$OMP PARALLEL\n !$OMP DO\n do component = 1, Natom3\n coordMean(component) = sum(coord1D(component,1:Nframe)) / Nframe\n end do\n !$OMP END DO\n !$OMP END PARALLEL\n !write(*,*) 'Mean value of each components: '\n !call logMat1D( coordMean(1:Natom3) )\n call writeXYZ(trim(fileNamePure)//'_mean', 1, reshape(coordMean, (/3, Natom/)) )\n \n ! substract mean value of each components\n do component = 1, Natom3\n coord1D(component,1:Nframe) = coord1D(component,1:Nframe) - coordMean(component)\n end do\n \n ! construct covariance matrix\n write(*,*) 'Constructing a covariance matrix...'\n\n !constructTotal = Natom3 * (Natom3 + 1) / 2\n !constructCount = 0\n !$OMP PARALLEL\n !$OMP DO\n do i = 1, Natom3\n do j = i, Natom3\n !!! `sum` is too slow! \n !cov(i,j) = sum( coord1D(i,1:Nframe) * coord1D(j,1:Nframe) ) / Nframe\n !write(*,*) i,j,OMP_get_thread_num()\n call matrixMul(1, Nframe, 1, &\n coord1D(i,1:Nframe), coord1D(j,1:Nframe), cov(i,j) )\n !constructCount = constructCount + 1\n !if( mod(constructCount, int(constructTotal/100)) .eq. 0) write(*,*) '1%',constructCount\n !if (i .ne. j) cov(j,i) = cov(i,j)\n end do\n end do\n !$OMP END DO\n !$OMP END PARALLEL\n\n !$OMP PARALLEL\n !$OMP DO\n do i = 1, Natom3\n do j = i, Natom3\n if (i .ne. j) cov(j,i) = cov(i,j)\n end do\n end do\n !$OMP END DO\n !$OMP END PARALLEL\n \n !write(*,*) 'Writing the covariance matrix...'\n !open(368, file=trim(fileNamePure)//'_covMat', status='replace', action='write')\n !write(368,*) 'Covariance matrix (F18.8)'\n !write(368,*) Natom3\n !do i = 1, Natom3\n ! write(368,'(999999999E18.8)') cov(1:Natom3,i)\n !end do\n\nend subroutine\n\n\nsubroutine writeXYZ(fileName, frames, coordinates)\nuse para\nimplicit none\ncharacter(len=*), intent(in) :: fileName\ninteger, intent(in) :: frames\nreal(inum), intent(in) :: coordinates(3,Natom,frames)\ninteger :: frame, atom\n\n open(9999, file=trim(fileName)//'.xyz', status='replace', action='write')\n do frame = 1, frames\n write(9999,*) Natom; write(9999,*);\n do atom = 1, Natom\n write(9999,'(A4,2X,3F12.6)') eleName(atom), coordinates(1:3,atom,frame)\n end do\n end do\n close(9999)\n\nend subroutine\n\n\nsubroutine logMat1D(mat)\nuse para\nreal(inum), intent(in) :: mat(Natom3)\ninteger :: atom\n\n write(*,*) ' Ele. X Y Z'\n do atom = 1, Natom\n write(*,'(A4,2X,3F12.6)') trim(eleName(atom)), mat( (atom-1)*3+1:atom*3 )\n end do\n\nend subroutine\n\n\nsubroutine readXYZ\nuse para\nimplicit none\ninteger :: fileStatus\ncharacter(icha) :: tempLine\ninteger :: atom, frame\n\n write(*,*) 'Reading .xyz file...'\n open(999, file=trim(inputFileName), status='old', action='read')\n \n ! count frames\n Nframe = 0\n do while (.true.)\n read(999, '(I)', iostat=fileStatus) Natom\n if (fileStatus /= 0) exit\n read(999, *, iostat=fileStatus) \n do atom = 1, Natom\n read(999, *, iostat=fileStatus) tempLine\n end do\n Nframe = Nframe + 1\n end do\n write(*,*) 'Atoms : ', Natom\n write(*,*) 'Frames : ', Nframe\n rewind(999)\n Natom3 = Natom * 3\n \n ! allocate array\n allocate( coord(3,Natom,Nframe), eleName(Natom) )\n ! memory needed: \n write(*,*) 'Memory of coordinates needed (MB): '\n write(*,*) 3d0*Natom*Nframe * 8d0 / 1048576d0 ! 8 bytes, convert to megabytes ( mb, 1024 * 1024 )\n \n ! read coordinates\n do frame = 1, Nframe\n read(999, *); read(999, *)\n do atom = 1, Natom\n read(999, *) eleName(atom), coord(1:3,atom,frame)\n !# write(*,*) coord(1:3,atom,frame)\n end do\n end do \n close(999)\n \n ! convert 2d coordinates (xyz, Natoms) to 1d (xyz * Natoms) \n ! check the converted coordinate matrix, please. Because I'm not sure the `reshape` could deal with this problem correctly. Now the `ifort` could give the right result. ! 2020-08-19 12:31:18 Wenbin, FAN @ SHU\n allocate( coord1D(Natom3, Nframe) )\n coord1D = reshape( coord, (/Natom3, Nframe/) )\n !#write(*,'(3F12.6)') coord1D(:,1)\n\nend subroutine\n\n\nsubroutine readInput\nuse para\nimplicit none\ncharacter(icha) :: fileExt\nlogical inputFileStatus\n\n call getarg(1, inputFileName)\n inquire(file=trim(inputFileName), exist=inputFileStatus)\n if (inputFileStatus) then\n call getExtension(inputFileName, fileNamePure, fileExt)\n write(*,*) 'Input file : ', trim(inputFileName)\n else\n call logError(\"Your input file `\" // trim(inputFileName) // \"` doesn't exist! \")\n end if\n \n if ( trim(fileExt) .eq. 'xyz') then\n call readXYZ\n else\n call logError('File extension '//trim(fileExt)//' is not supported! ')\n end if\n\nend subroutine", "meta": {"hexsha": "b6c6ab005bdcf88e5f7efa3cfd1909d87c3e12ff", "size": 8696, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "main.f90", "max_stars_repo_name": "fanwenbin-shu/xyzPCA", "max_stars_repo_head_hexsha": "864ad64da471b6f98c59f8ee00897b292c7d78d0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-10T00:22:21.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-10T00:22:21.000Z", "max_issues_repo_path": "main.f90", "max_issues_repo_name": "fanwenbin-shu/xyzPCA", "max_issues_repo_head_hexsha": "864ad64da471b6f98c59f8ee00897b292c7d78d0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "main.f90", "max_forks_repo_name": "fanwenbin-shu/xyzPCA", "max_forks_repo_head_hexsha": "864ad64da471b6f98c59f8ee00897b292c7d78d0", "max_forks_repo_licenses": ["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.0516129032, "max_line_length": 212, "alphanum_fraction": 0.5988960442, "num_tokens": 2738, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563336, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6673745073825315}} {"text": "program intrinsics_14\ninteger, parameter :: &\n k1 = selected_int_kind(5), &\n k2 = selected_int_kind(5_4), &\n k3 = selected_int_kind(5_8), &\n k4 = selected_int_kind(8), &\n k5 = selected_int_kind(10), &\n k6 = selected_real_kind(5), &\n k7 = selected_real_kind(5_4), &\n k8 = selected_real_kind(5_8), &\n k9 = selected_real_kind(8), &\n k10 = selected_char_kind(\"default\")\n\ninteger :: i1\ncharacter(7) :: s1\n\ns1 = \"default\"\ni1 = 5\n\nprint*,selected_int_kind(5), k1 ! 4\nprint*,selected_int_kind(5_4), k2 ! 4\nprint*,selected_int_kind(5_8), k3 ! 4\nprint*,selected_int_kind(8), k4 ! 4\nprint*,selected_int_kind(10), k5 ! 8\nprint*,selected_real_kind(5), k6 ! 4\nprint*,selected_real_kind(5_4), k7 ! 4\nprint*,selected_real_kind(5_8), k8 ! 4\nprint*,selected_real_kind(8), k9 ! 8\nprint*,selected_char_kind(\"default\"), k10 ! 1\n\nprint *, selected_int_kind(i1)\nprint *, selected_real_kind(i1)\nprint *, selected_char_kind(s1)\nend program\n", "meta": {"hexsha": "accc4172621fce35480e6e57a6a471ad338fe9fd", "size": 945, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "integration_tests/intrinsics_14.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_14.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_14.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.0, "max_line_length": 45, "alphanum_fraction": 0.6931216931, "num_tokens": 328, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563336, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6673745073825315}} {"text": "C *********************************************************\nC * *\nC * TEST NUMBER: 06.01.01/02 *\nC * TEST TITLE : Behavior of scaling *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n \n COMMON /GLOBNU/ CTLHND, ERRSIG, ERRFIL, IERRCT, UNERR,\n 1 TESTCT, IFLERR, PASSSW, ERRSW, MAXLIN,\n 2 CONID, MEMUN, WKID, WTYPE, GLBLUN, INDLUN,\n 3 DUMINT, DUMRL\n INTEGER CTLHND, ERRSIG, ERRFIL, IERRCT, UNERR,\n 1 TESTCT, IFLERR, PASSSW, ERRSW, MAXLIN,\n 2 CONID, MEMUN, WKID, WTYPE, GLBLUN, INDLUN,\n 3 DUMINT(20), ERRIND\n REAL DUMRL(20)\n \n COMMON /GLOBCH/ PIDENT, GLBERR, TSTMSG, FUNCID,\n 1 DUMCH\n CHARACTER PIDENT*40, GLBERR*60, TSTMSG*900, FUNCID*80,\n 1 DUMCH(20)*20\n \n REAL ACT4X4(4,4), EXP4X4(4,4), FX,FY,FZ\n REAL ACT3X3(3,3), EXP3X3(3,3)\n LOGICAL TRNSEQ\n \n CALL INITGL ('06.01.01/02')\n \nC open PHIGS\n CALL XPOPPH (ERRFIL, MEMUN)\n CALL SETMSG ('1 2 5', ' should return a correct ' //\n 1 'representation for the transformation to ' //\n 2 'scale a 3D point, with non-zero parameters.')\n \n FX = -33.3\n FY = 0.0076\n FZ = 2.2\n \nC with fx,fy,fz returns act4x4 = actual array\n CALL PSC3 (FX,FY,FZ, ERRIND, ACT4X4)\n CALL CHKINQ ('psc3', ERRIND)\n \nC Compute exp4x4 = expected array\n CALL ESC3 (FX,FY,FZ, EXP4X4)\n \nC pass if matrices represent same transformation\n CALL IFPF (TRNSEQ(4, ACT4X4, EXP4X4))\n \n CALL SETMSG ('1 2 5', ' should return a correct ' //\n 1 'representation for the transformation to ' //\n 2 'scale a 3D point, with zero parameters.')\n \n FX = 0.0\n FY = 0.0076\n FZ = 0.0\n \nC with fx,fy,fz returns act4x4 = actual array\n CALL PSC3 (FX,FY,FZ, ERRIND, ACT4X4)\n CALL CHKINQ ('psc3', ERRIND)\n \nC Compute exp4x4 = expected array\n CALL ESC3 (FX,FY,FZ, EXP4X4)\n \nC pass if matrices represent same transformation\n CALL IFPF (TRNSEQ(4, ACT4X4, EXP4X4))\n \n CALL SETMSG ('1 2 6', ' should return a correct ' //\n 1 'representation for the transformation to ' //\n 2 'scale a 2D point, with non-zero parameters.')\n \n FX = -33.3\n FY = 0.0076\n \nC with fx,fy returns act3x3 = actual array\n CALL PSC (FX,FY, ERRIND, ACT3X3)\n CALL CHKINQ ('psc', ERRIND)\n \nC Compute exp3x3 = expected array\n CALL ESC (FX,FY, EXP3X3)\n \nC pass if matrices represent same transformation\n CALL IFPF (TRNSEQ(3, ACT3X3, EXP3X3))\n \n CALL SETMSG ('1 2 6', ' should return a correct ' //\n 1 'representation for the transformation to ' //\n 2 'scale a 2D point, with zero parameters.')\n \n FX = 0.0\n FY = 0.0\n \nC with fx,fy returns act3x3 = actual array\n CALL PSC (FX,FY, ERRIND, ACT3X3)\n CALL CHKINQ ('psc', ERRIND)\n \nC Compute exp3x3 = expected array\n CALL ESC (FX,FY, EXP3X3)\n \nC pass if matrices represent same transformation\n CALL IFPF (TRNSEQ(3, ACT3X3, EXP3X3))\n \n CALL ENDIT\n END\n", "meta": {"hexsha": "660a7387a71b70081377efcbbcfe801996d3b744", "size": 3538, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "third_party/Phigs/PVT/PVT_fort/06/01/01/p02.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/06/01/01/p02.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/06/01/01/p02.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": 33.6952380952, "max_line_length": 67, "alphanum_fraction": 0.5138496326, "num_tokens": 1145, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460332, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6673744978952023}} {"text": " SUBROUTINE eulsum(sum,term,jterm,wksp)\r\n INTEGER jterm\r\n REAL sum,term,wksp(jterm)\r\n INTEGER j,nterm\r\n REAL dum,tmp\r\n SAVE nterm\r\n if(jterm.eq.1)then\r\n nterm=1\r\n wksp(1)=term\r\n sum=0.5*term\r\n else\r\n tmp=wksp(1)\r\n wksp(1)=term\r\n do 11 j=1,nterm-1\r\n dum=wksp(j+1)\r\n wksp(j+1)=0.5*(wksp(j)+tmp)\r\n tmp=dum\r\n11 continue\r\n wksp(nterm+1)=0.5*(wksp(nterm)+tmp)\r\n if(abs(wksp(nterm+1)).le.abs(wksp(nterm)))then\r\n sum=sum+0.5*wksp(nterm+1)\r\n nterm=nterm+1\r\n else\r\n sum=sum+wksp(nterm+1)\r\n endif\r\n endif\r\n return\r\n END\r\n", "meta": {"hexsha": "07e3e079e9bd72800535400c8eddf7cd3ef405f6", "size": 694, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/eulsum.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/eulsum.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/eulsum.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.9310344828, "max_line_length": 55, "alphanum_fraction": 0.4798270893, "num_tokens": 239, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563336, "lm_q2_score": 0.7549149758396752, "lm_q1q2_score": 0.6673744976333876}} {"text": "! TheComputer Language Benchmarks Game\n! http://shootout.alioth.debian.org/\n!\n! contributed by Steve Decker based on the version by Simon Geard\n! September 2008, Simon Geard, Added OpenMP directives\n!\n! compilation:\n! g95 -O1 -fomit-frame-pointer -funroll-loops spectral_norm.f90\n! ifort -ipo -O3 -openmp spectral_norm.f90\n! gfortran -O3 -openmp spectral_norm.f90 (not tested)\n\nmodule norm_subs\n implicit none\n\n public :: MultiplyAtAv\n public :: dp\n\n private\n integer, parameter :: dp = selected_real_kind(12)\n\ncontains\n\n ! Multiply v by A\n pure function MultiplyAv(v) result (Av)\n real(dp), dimension(:), intent(in) :: v\n real(dp), dimension(size(v)) :: Av\n real(dp) :: r\n integer :: n, i, j\n\n n = size(v)\n !$omp parallel do shared(Av, v, n) private(i, j, r)\n do i = 1, n\n r = 0.0d0\n do j = 1, n\n r = r + A() * v(j)\n end do\n Av(i) = r\n end do\n !omp end parallel do\n\n contains\n pure real(dp) function A\n ! Return element i,j of infinite matrix A\n a = 1.d0 / ((i+j-2) * (i+j-1)/2 + i)\n end function A\n end function MultiplyAv\n\n ! Multiply v by A transpose\n pure function MultiplyAtv(v) result (Atv)\n real(dp), dimension(:), intent(in) :: v\n real(dp), dimension(size(v)) :: Atv\n\n real(dp) :: r\n integer :: n, i, j\n\n n = size(v)\n Atv = 0.d0\n !$omp parallel do shared(Atv, v, n) private(i, j, r)\n do i = 1, n\n r = 0.0d0\n do j = 1, n\n r = r + AT() * v(j)\n end do\n Atv(i) = r\n end do\n !omp end parallel do\n\n contains\n pure real(dp) function AT\n ! Return element j,i of infinite matrix A\n AT = 1.d0 / ((i+j-2) * (i+j-1)/2 + j)\n end function AT\n end function MultiplyAtv\n\n ! Multiply v by A and then by A transpose\n pure function MultiplyAtAv(v) result (AtAv)\n real(dp), dimension(:), intent(in) :: v\n real(dp), dimension(size(v)) :: AtAv\n\n AtAv = MultiplyAtv(MultiplyAv(v))\n end function MultiplyAtAv\nend module norm_subs\n\nprogram spectral_norm\n use norm_subs\n implicit none\n\n real(dp), dimension(:), allocatable :: u, v\n integer :: i, n\n character(len=6) :: argv\n\n integer, external :: omp_get_num_procs\n\n ! By default the number of threads should be set to the number of processors\n ! but the number can be controlled with one of the folowing\n ! export OMP_NUM_THREADS=4\n ! call omp_set_num_threads(omp_get_num_procs())\n\n call get_command_argument(1, argv)\n read(argv, *) n\n\n allocate(u(n), v(n))\n u = 1.d0\n do i = 1, 10\n v = MultiplyAtAv(u)\n u = MultiplyAtAv(v)\n end do\n\n write(*, \"(f0.9)\") sqrt(dot_product(u,v) / dot_product(v,v))\n deallocate(u, v)\nend program spectral_norm\n", "meta": {"hexsha": "ec939955f1ab3bb093db2e75de312baba791bda2", "size": 2714, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "shootout/spectralnorm.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/spectralnorm.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/spectralnorm.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": 24.2321428571, "max_line_length": 78, "alphanum_fraction": 0.6142225497, "num_tokens": 856, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392695254319, "lm_q2_score": 0.7549149868676284, "lm_q1q2_score": 0.6673744935442592}} {"text": "!\n! ComputeBPPCoef.f90\n! \n!\n! Created by Kurt Mitman on 11/08/15.\n! Copyright 2015 __MyCompanyName__. All rights reserved.\n!\nsubroutine ComputeBPPCoef\n\n\nUSE Params\nUSE Globals\nUSE Funcs\nUSE random\nUSE Procedures\n\nIMPLICIT NONE\n\n\nINTEGER :: iseed(2),isize,iAgg,it,Phinds(2),iindex,startage,endage,in\n\ndouble precision,allocatable,dimension(:) :: gy,dc,dy\ndouble precision,allocatable,dimension(:,:) :: gyj,dcj\ndouble precision :: Edc,Edy,Egy\n\nstartage=3\nendage=Jwork-2\n\nallocate(gy((tend-tstart+1)*(endage-startage+1)*nsim))\nallocate(dc((tend-tstart+1)*(endage-startage+1)*nsim))\nallocate(dy((tend-tstart+1)*(endage-startage+1)*nsim))\n!allocate(gyj((tstart-tend+1)*nsim,(endage-startage+1)))\n!allocate(dcj((tstart-tend+1)*nsim,(endage-startage+1)))\n\n\niindex=0\n\ndo in=1,nsim\n do it=tstart,tend\n if( (simtrans(it)%jsim(in) .GT. 2) .AND. (simtrans(it)%jsim(in) .LT. (Jwork-1))) then\n iindex=iindex+1\n gy(iindex)=rhoy*(log(simtrans(it)%ysim(in))-rhoy*log(simtrans(it-1)%ysim(in)))+rhoy**2*(log(simtrans(it-1)%ysim(in))-rhoy*log(simtrans(it-2)%ysim(in)))+(log(simtrans(it+1)%ysim(in))-rhoy*log(simtrans(it)%ysim(in)))\n dc(iindex)=log(simtrans(it)%csim(in))-log(simtrans(it-1)%csim(in))\n dy(iindex)=log(simtrans(it)%ysim(in))-rhoy*log(simtrans(it-1)%ysim(in))\n\n! gy(iidenx)=rhoy*(log(simtrans(it)%ysim(in))-rhoy*log(simtrans(it-1)%ysim(in)))+rhoy**2*(log(simtrans(it-1)%ysim(in))-rhoy*log(simtrans(it-2)%ysim(in)))+(log(simtrans(it+1)%ysim(in))-rhoy*log(simtrans(it)%ysim(in)))\n! dc(iidenx)=log(simtrans(it)%csim(in))-log(simtrans(it-1)%csim(in))\n endif\n\n enddo\nenddo\n\n!Edc = SUM(dc)/dble((tend-tstart+1)*(endage-startage+1)*nsim)\n!Edy = SUM(dy)/dble((tend-tstart+1)*(endage-startage+1)*nsim)\n!Egy = SUM(gy)/dble((tend-tstart+1)*(endage-startage+1)*nsim)\n\nEdc = SUM(dc)/dble(iindex)\nEdy = SUM(dy)/dble(iindex)\nEgy = SUM(gy)/dble(iindex)\n\n\n\nprint*,Egy,Edc,Edy\nprint*,sum((gy-Egy)*(dc-Edc)),sum((gy-Egy)*(dy-Edy))\n\nbppcoef = sum((gy-Egy)*(dc-Edc))/sum((gy-Egy)*(dy-Edy))\n\nprint*,bppcoef\n\n\n\n\n\n\nend subroutine ComputeBPPCoef\n", "meta": {"hexsha": "c5613023f76e03b627a5b6e369c9b928f707955a", "size": 2181, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "FortranCode/landlord-code/ComputeBPPCoef.f90", "max_stars_repo_name": "lnsongxf/housing-boom-bust", "max_stars_repo_head_hexsha": "bb75a2fd0646802dcdf4d5e56d1392bae7090e1c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-07-19T16:46:31.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-09T10:52:42.000Z", "max_issues_repo_path": "FortranCode/landlord-code/ComputeBPPCoef.f90", "max_issues_repo_name": "floswald/housing-boom-bust", "max_issues_repo_head_hexsha": "bb75a2fd0646802dcdf4d5e56d1392bae7090e1c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-09-20T08:31:12.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-20T08:48:49.000Z", "max_forks_repo_path": "FortranCode/landlord-code/ComputeBPPCoef.f90", "max_forks_repo_name": "kurtmitman/housing-boom-bust", "max_forks_repo_head_hexsha": "8c1ad640d79540488a5ef859f3c47ac5d4515e85", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-09-12T06:08:15.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-16T16:24:13.000Z", "avg_line_length": 28.6973684211, "max_line_length": 223, "alphanum_fraction": 0.643741403, "num_tokens": 781, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772482857834, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.667343796566266}} {"text": "\tPROGRAM GRI_ELLI\nC++----------------------------------------------------------------------\nC Program GRI_ELLI\nC From ARGPLOT.FOR\nC Version of 06-11-87\nC\nC Plots a portion of an ellipse with the given parameters on the GRINNEL\nC N.B. The centre is shifted one unit towards the origin to allow for\nC the origin at 0, 0 on the args\nC X0, Y0 = the ellipse centre (in the data array)\nC----------------------------------------------------------------------\n\tPARAMETER (PI=3.14159265358979323846D0)\n\tREAL*8 Z(5)\n\tREAL*4 XPLOT(1024),YPLOT(1024)\n\tCHARACTER ANS*1,COLOR*1\n \n10\tFORMAT(A)\nC\n\tPRINT *,' PROGRAM GRI_ELLI'\nC************************************************************\nC Creation of a portion of an ellipse\nC************************************************************\nC\tPRINT *,' SCALE IN ARCSEC./PIXEL ?'\nC\tREAD(5,*) SCALE\n\tSCALE=1.0\n \n12\tPRINT *,' CENTRE OX,OY ?'\n\tREAD(5,*) Z(4),Z(5)\n \n\tPRINT *,' MAJOR AXIS (ARCSEC.), AND ELLIPTICITY ?'\n\tREAD(5,*) Z(1),ELL\n\tZ(1)=Z(1)/SCALE\n\tECCEN=1.-ELL/10.\n\tZ(2)=Z(1)*ECCEN\n \n\tPRINT *,' THETA, THETA MIN AND THETA MAX (0. < DEGREES < 360.)'\n\tREAD(5,*) THETAC,THEMI,THEMA\n\tZ(3)=THETAC*PI/180.\n \n\tIOPT=1\n\tCALL GENE_ELLIPSE(XPLOT,YPLOT,NPOINT,Z,THEMI,THEMA,IOPT)\n \nC The actual plotting command :\n\tPRINT *,' COLOR : (UPPER CASE !!!!) R, G, B, OR W ?'\n\tREAD(5,10) COLOR\n \nC Initializing the GRINNEL :\n\tPRINT *,' CALLING GRINNEL_INIT'\n\tCALL GRINNEL_INIT\n \nC Drawing the vector :\n\tPRINT *,' CALLING GRINNEL_VECTOR'\n\tCALL GRINNEL_VECTOR(XPLOT,YPLOT,NPOINT,COLOR)\n \nC Clear the overlay plane if required\nC\n\tPRINT *,' DO YOU WANT TO CLEAR THE OVERLAY PLANE ? (N)'\n\tREAD(5,10) ANS\n\t IF(ANS.EQ.'Y'.OR.ANS.EQ.'y') THEN\n\t CALL GRINNEL_CLEAR(COLOR)\n\t ENDIF\n \n\tPRINT *,' DO YOU WANT ANOTHER TRY ?(N)'\n\tREAD(5,10) ANS\n\tIF(ANS.EQ.'Y'.OR.ANS.EQ.'y') GO TO 12\n \n\t CALL GRSEND\n\tEND\nC----------------------------------------------------------------------------\n\tinclude 'jlpsub:gene_ellipse.for'\n\tinclude 'jlpsub:gri_set.for'\n", "meta": {"hexsha": "23cdd71ea7263f8f5c8cb8184c560008e58bb60a", "size": 1976, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "source/archived_programs/gri_elli.for", "max_stars_repo_name": "jlprieur/shell_galaxies", "max_stars_repo_head_hexsha": "1dde87ef33b3c33b3a892e9ad0d642ae02ac6d9e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source/archived_programs/gri_elli.for", "max_issues_repo_name": "jlprieur/shell_galaxies", "max_issues_repo_head_hexsha": "1dde87ef33b3c33b3a892e9ad0d642ae02ac6d9e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/archived_programs/gri_elli.for", "max_forks_repo_name": "jlprieur/shell_galaxies", "max_forks_repo_head_hexsha": "1dde87ef33b3c33b3a892e9ad0d642ae02ac6d9e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.4444444444, "max_line_length": 77, "alphanum_fraction": 0.5581983806, "num_tokens": 660, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772417253256, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6673437868535348}} {"text": "!!\r\n!! Luke McCulloch\r\n!! inv.f90\r\n!! 3-26-2011\r\n!! Program solve a simple system of linear equations\r\n!! Via the Thomas Algorithm\r\n!!\r\n!! i = dummy variable\r\n!! a = subdiagonal\r\n!! b = diagonal\r\n!! c = superdiagonal\r\n!! x = unknown vector\r\n!! d = RHS\r\n!! m = algorithm ratio\r\n!! n = matrix size (nxn)\r\n\r\nModule inv\r\n\r\n use precise, only : defaultp ! double precision\r\n \r\n\r\n!! variable declarations\r\n\r\n IMPLICIT NONE \r\n\r\n integer, parameter, private :: WP=defaultp \r\n\r\nContains\r\n\r\n subroutine tlmtri (a,b,c,d,x,n)\r\n integer :: i, n\r\n \r\n REAL(wp), DIMENSION(n) :: a, b, c, d, x !diagonals, RHS, Solution\r\n real(wp):: m\r\n\r\n\r\n\r\n ! Simple start up message\r\n !print*\r\n !write(6,*) '---------------------------------------------------'\r\n !WRITE(6,'(A)') 'Called tri-diagonal inversion subrouting'\r\n !write(6,*) 'By Luke McCulloch'\r\n !write(6,*) 'Sept-2011'\r\n\r\n !! a is the subdiagonal, b is the diagonal, c is the superdiagonal\r\n !! a(1)==0. is never used\r\n !! c(n)==0. is never used\r\n \r\n !!Forward sweep\r\n\r\n do i=2,n\r\n m=a(i)/b(i-1) \r\n b(i)=b(i)-m*c(i-1) \r\n d(i)=d(i)-m*d(i-1)\r\n end do\r\n\r\n !print*\r\n !Write(6,*) 'End of Forward Sweep, Begin Back Substitution'\r\n\r\n\r\n x(n)=d(n)/b(n)\r\n\r\n do i=n-1,1, -1\r\n x(i)=(d(i)-c(i)*x(i+1))/b(i)\r\n end do\r\n \r\n !write(6,*) 'And the answer is...'\r\n !print*\r\n return\r\n!!$ print*\r\n!!$ write(6,'('' x = '',31F10.8)') x\r\nEND subroutine tlmtri\r\n\r\nend module inv\r\n\r\n\r\n", "meta": {"hexsha": "1597e1bdc6782f4e8b84d94a1d1d3192f9642ba0", "size": 1473, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/src/inv.f90", "max_stars_repo_name": "LukeMcCulloch/ShallowWaterEquations", "max_stars_repo_head_hexsha": "108bc60b5b0b75a04088ece4db1fb9d1a95169f5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fortran/src/inv.f90", "max_issues_repo_name": "LukeMcCulloch/ShallowWaterEquations", "max_issues_repo_head_hexsha": "108bc60b5b0b75a04088ece4db1fb9d1a95169f5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/src/inv.f90", "max_forks_repo_name": "LukeMcCulloch/ShallowWaterEquations", "max_forks_repo_head_hexsha": "108bc60b5b0b75a04088ece4db1fb9d1a95169f5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.1298701299, "max_line_length": 69, "alphanum_fraction": 0.5247793618, "num_tokens": 478, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044095, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6673437721320001}} {"text": "PROGRAM PE2D_HTR\n USE NRTYPE\n USE MATLIB\n USE PARAM\n USE GROUND\r\n IMPLICIT NONE\r\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\n WRITE(*,*) \"\"\r\n WRITE(*,*) \"================================================\"\r\n WRITE(*,*) \"========== Parabolic Equation Package ==========\"\r\n WRITE(*,*) \"================================================\"\r\n WRITE(*,*) \"\"\r\n WRITE(*,*) \"University of Bristol\"\r\n WRITE(*,*) \"Aerodynamics and Aeroacoustics Research Group\"\r\n WRITE(*,*) \"\"\r\n WRITE(*,*) \"Codor Khodr, July 2016\"\r\n WRITE(*,*) \"\"\r\n WRITE(*,*) \"================================================\"\r\n WRITE(*,*) \"\"\r\n WRITE(*,*) \"PE2D_HFR\"\r\n WRITE(*,*) \"Dimension : 2D\"\r\n WRITE(*,*) \"Atmosphere : Homogeneous\"\r\n WRITE(*,*) \"Boundary : Flat\"\r\n WRITE(*,*) \"Impedance : Rigid\"\r\n WRITE(*,*) \"\"\r\n WRITE(*,*) \"================================================\"\r\n WRITE(*,*) \"\"\r\n WRITE(*,*) \"Enter inputs L, f, zs, As, angle\"\r\n WRITE(*,*) \"\"\r\n READ *, L, F, ZS, ABL, ANGLE\r\n WRITE(*,*) \"\"\r\n !-----------------------------------------------------------\r\n !----------------------------------------------------------\r\n C0 = 343.0_DP\n LMBDA0 = C0/F\r\n K0 = 2*PI*F/C0\r\n DZ = LMBDA0/10\r\n DR = LMBDA0/10\n H = 100*LMBDA0\r\n HABL = 30*LMBDA0\r\n N = FLOOR(H/DZ)\r\n M = FLOOR(L/DR)\n WRITE(*,*) \"================================================\"\n WRITE(*,*) \"\"\n WRITE(*,*) \"Size of the system : \", N\n WRITE(*,*) \"Number of steps : \", M\n WRITE(*,*) \"\"\n WRITE(*,*) \"================================================\"\r\n NS = MAX(1,FLOOR(ZS/DZ))\r\n NABL = FLOOR(HABL/DZ)\n A = IM/(2.0_DP*K0*DZ**2)\n KU = 1\n KL = 1\n NDIAG = KU+KL+1\r\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\r\n !Memory allocation\n ALLOCATE(K(N), DK2(N), ALT(N), PHI(N,M+1), T(N,N), D(N,N), M1(N,N), &\n M2(N,N), I(N,N), P(N,M), LP(N,M), LP2(N,M), LPG(M), LPG2(M), E(N,N), &\n MB2(NDIAG,N), MB1(NDIAG,N), TEMP(N,1), M1T(N,N), M2T(N,N), IPIV(N), &\n TERR(1:M+1), TERR1(1:M+1), TERR2(1:M+1), LIN(0:M+1), GHX(3), COND(M,2), &\n MB1T(NDIAG,N), MB2T(KL+NDIAG,N))\r\n !-----------------------------------------------------------\n !-----------------------------------------------------------\n !Atmosphere density and wave velocity\r\n DO NZ = 1,N\r\n IF (NZ >= N-NABL) THEN\r\n K(NZ) = K0+ABL*IM*(NZ-N+NABL)**2/NABL**2\r\n ELSE\r\n K(NZ) = K0\r\n ENDIF\r\n DK2(NZ) = IM*(K(NZ)**2-K0**2)/(2*K0)\n ALT(NZ) = NZ*DZ\r\n END DO\r\n TAU1 = 4.0_DP/(3.0_DP-2.0_DP*IM*K0*DZ)\r\n TAU2 = -1.0_DP/(3.0_DP-2.0_DP*IM*K0*DZ)\r\n SIGMA1 = 4.0_DP/3.0_DP\r\n SIGMA2 = -1.0_DP/3.0_DP\r\n !-----------------------------------------------------------\n !-----------------------------------------------------------\n !Terrain Boundary condition\r\n LIN(0) = 0\n THETA = ANGLE*PI/180.0_DP\n X0 = L/2.0_DP\n S = L/5.0_DP\n H0 = SQRT(EXP(1.0_DP)/2.0_DP)*S*ATAN(THETA)\r\n DO MX = 1,M\n GHX = GHILL(H0,X0,S,MX*DR)\r\n TERR(MX) = GHX(1)\n TERR1(MX) = GHX(2)\r\n TERR2(MX) = GHX(3)\r\n LIN(MX) = LIN(MX-1)+(1+TERR1(MX))*DR\r\n END DO\r\n !-----------------------------------------------------------\n !-----------------------------------------------------------\n !Starting field\r\n A0 = 1.3717_DP\r\n A2 = -0.3701_DP\r\n B = 3.0_DP\r\n DO NZ = 1,N\r\n PHI(NZ,1) = SQRT(IM*K0)* &\r\n ((A0+A2*K0**2*(NZ*DZ-ZS)**2)*EXP(-K0**2*(NZ*DZ-ZS)**2/B) + &\r\n (A0+A2*K0**2*(NZ*DZ+ZS)**2)*EXP(-K0**2*(NZ*DZ+ZS)**2/B))\n END DO\n !-----------------------------------------------------------\n !-----------------------------------------------------------\n !Matrix building\n !-----------------------------------------------------------\n !Initialization (Dense Matrices) - T, D and E\n !---------\r\n T(:,:) = 0.0_DP\r\n DO NZ = 2,N-1 \r\n T(NZ,NZ-1) = 1.0_DP\r\n T(NZ,NZ) = -2.0_DP\r\n T(NZ,NZ+1) = 1.0_DP\r\n END DO\n T(1,1) = -2.0_DP+SIGMA1\r\n T(1,2) = 1.0_DP+SIGMA2\r\n T(N,N-1) = 1.0_DP+TAU2\r\n T(N,N) = -2.0_DP+TAU1\n E = DIAG(ALT,N)\n D = DIAG(DK2,N)\n I = EYE(N)\n !-----------------------------------------------------------\n !System - M1 and M2\n !---------\n ALPHA = CMPLX(1.0_DP,0.0_DP,KIND=DP)\n BETA = CMPLX(0.0_DP,0.0_DP,KIND=DP)\n BETA1 = 1.0_DP/(2.0_DP*IM*K0)+DR/2.0_DP\n BETA2 = 1.0_DP/(2.0_DP*IM*K0)-DR/2.0_DP\n M1 = I+A*BETA1*T+BETA1*D\r\n M2 = I+A*BETA2*T+BETA2*D \n MB1 = DENSE2BAND(M1,N,KL,KU)\n MB2 = DENSE2BAND(M2,N,KL,KU)\r\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\r\n !Forward-marching procedure\n CALL CPU_TIME(TI)\n !-----------------------------------------------------------\n DO MX = 2,M+1\n WRITE(*,*) \"Step :\", MX-1, \"out of\", M\n !-------------------------------\n !Matrix updating\n !-------------------------------\n !M1T = M1-BETA1*IM*K0*TERR2(MX-1)*E\n !M2T = M2-BETA2*IM*K0*TERR2(MX-1)*E\n MB1T = MB1\n MB1T(KU+1,:) = MB1(KU+1,:)-BETA1*IM*K0*TERR2(MX-1)*ALT\n MB2T(KL+1:KL+NDIAG,:) = MB2\n MB2T(KL+KU+1,:) = MB2(KU+1,:)-BETA2*IM*K0*TERR2(MX-1)*ALT\n !-------------------------------\n !Right hand side multiplication\n !-------------------------------\n !TERR2(MX-1) = (TERR1(MX)-TERR1(MX-1))/DR \t\t\t!Varying coefficient to be injected... \n !TEMP(:,1) = MATMUL(M1T,PHI(1:N,MX-1))\n CALL ZGBMV('N',N,N,KL,KU,ALPHA,MB1T,KL+KU+1,PHI(1:N,MX-1),1,BETA,TEMP(:,1),1)\n !---------\n !---------\n !ALLOCATE(WORK(N),RWORK(2*N),CWORK(2*N))\n !NORM = ZLANGE('I',N,N,M1T,N,WORK)\n WRITE(*,*) \"||M1|| = \", NORM \n CALL ZGECON('I',N,M1T,N,NORM,RCOND,CWORK,RWORK,INFO)\n WRITE(*,*) \"K(M1) = \", 1.0_DP/RCOND\n COND(MX-1,1) = 1.0_DP/RCOND\n DEALLOCATE(WORK,RWORK,CWORK)\n !---------\n !---------\n WRITE(*,*) \".... Right-hand side multiplied\"\n WRITE(*,*)\n !-------------------------------\n !System solving\n !-------------------------------\n !MTEMP2 = M2\n !CALL ZGESV(N,1,M2T,N,IPIV,TEMP,N,INFO) !General matrix form \n CALL ZGBSV(N,KL,KU,1,MB2T,2*KL+KU+1,IPIV,TEMP,N,INFO) !Band matrix form\n !CALL ZGTSV(N,1,MT2T(3,1:N-1),MT2T(2,1:N),MT2T(1,2:N),TEMP(:,1),N,INFO) !Tridiagonal matrix form\n IF (INFO.NE.0) THEN\n WRITE(*, *) INFO\n STOP \"ERROR : Matrix is singular\"\n END IF\n !---------\n !---------\n !ALLOCATE(WORK(N),RWORK(N),CWORK(2*N))\n !NORM = ZLANGB('I',N,KL,KU,MB2T(KL+1:2*KL+KU+1,:),KL+KU+1,WORK)\n !WRITE(*,*) \"||M2|| = \", NORM \n !CALL ZGBCON('I',N,KL,KU,MB2T,2*KL+KU+1,IPIV,NORM,RCOND,CWORK,RWORK,INFO)\n !WRITE(*,*) \"K(M2) = \", 1.0_DP/RCOND \n !COND(MX-1,2) = 1.0_DP/RCOND\n !DEALLOCATE(WORK,RWORK,CWORK)\n !---------\n !---------\n WRITE(*,*) \".... System solved\"\n WRITE(*,*)\n PHI(1:N,MX) = TEMP(:,1)\r\n P(1:N,MX-1) = EXP(IM*K0*(MX-1)*DR)*PHI(1:N,MX)*(1/SQRT((MX-1)*DR))\r\n END DO\n !-----------------------------------------------------------\n !ELSEIF (SP == 1) THEN\n !Sparse SLATEC\n !DO MX = 2,M+1\n ! WRITE(*, *) \"Step :\", MX-1, \"out of\", M\r\n ! TERR2(MX-1) = (TERR1(MX)-TERR1(MX-1))/Dr\r\n ! D = D-im*K0*TERR2(MX-1)*DIAG(ALT)\n ! WRITE(*, *) \"1\"\r\n ! M1 = I+(Dr/2)*(aa*T+D)+(1/(2*im*K0))*(aa*T+D)\r\n ! M2 = I-(Dr/2)*(aa*T+D)+(1/(2*im*K0))*(aa*T+D)\r\n ! !MAT = MATMUL(INV(M2),M1)\n ! WRITE(*, *) \"2\"\n ! !MAT_SP = SPCONV(MAT) ! SLOW PROCEDURE !\n ! CALL SPRSIN_DP(M2,0,SPM2)\n ! CALL SPRSIN_DP(M1,0,SPM1)\n ! NELT = MAT_SP%NELT\n ! ALLOCATE(IMAT(NELT),JMAT(NELT))\n ! IMAT = MAT_SP%ROW\n ! JMAT = MAT_SP%COL\n ! VALMAT = MAT_SP%VAL\n ! CALL DSMV(N,PHI(1:N,MX-1),PHI(1:N,MX),NELT,IMAT,JMAT,VALMAT,0)\r\n ! P(1:N,mx-1) = EXP(im*K0*(MX-1)*Dr)*PHI(1:N,MX)*(1/SQRT((MX-1)*Dr))\r\n !END DO\n !-----------------------------------------------------------\n CALL CPU_TIME(TF)\r\n !-----------------------------------------------------------\r\n !-----------------------------------------------------------\n !Transmission loss conversion\n P0 = P(NS,1)\n DO MX = 1,M\n DO NZ = 1,N\n IF (ABS(P(NZ,MX)).LE.10**(-6)) THEN\n P(NZ,MX) = 10**(-6)\n END IF\n LP(NZ,MX) = 20.*LOG10(ABS(P(NZ,MX)/P0))\n END DO\n END DO\n LPG = LP(1,1:M)\n LP2 = LP/SQRT(2.0_DP)\r\n LPG2 = LP2(1,1:M)\n !-----------------------------------------------------------\n !-----------------------------------------------------------\n !WRITE(*,*)\n !WRITE(*,*) \"================================================\"\n !WRITE(*,*)\n !WRITE(*,*) \" T = \"\n !DO NZ = 1,4\n !WRITE(*,101) T(NZ,1:4)\n !END DO\n !WRITE(*,*)\n !WRITE(*,*) \"================================================\"\n !WRITE(*,*)\n !WRITE(*,*) \" E = \"\n !DO NZ = 1,4\n ! WRITE(*,101) E(NZ,1:4)\n !END DO\n !WRITE(*,*)\n !WRITE(*,*) \"================================================\"\n !WRITE(*,*)\n !WRITE(*,*) \" D = \"\n !DO NZ = N-3,N\n ! WRITE(*,101) D(NZ,N-3:N)\n !END DO\n !WRITE(*,*)\n !WRITE(*,*) \"================================================\"\n !WRITE(*,*)\n !-----------------------------------------------------------\n !-----------------------------------------------------------\r\n !Output\r\n OPEN(UNIT=10,FILE=\"results/Test_LPg.dat\")\r\n OPEN(UNIT=20,FILE=\"results/Test_LP.dat\")\r\n OPEN(UNIT=30,FILE=\"results/Test_P.dat\")\n !OPEN(UNIT=40,FILE=\"results/Test_Cond.dat\")\n OPEN(UNIT=50,FILE=\"results/Test_Terr.dat\")\r\n DO MX = 1,M\r\n WRITE(10,100) MX*DR, LPG(MX), LPG2(MX)\n WRITE(40,100) COND(MX,1), COND(MX,2)\n WRITE(50,100) MX*DR, TERR(MX), TERR1(MX), TERR2(MX)\n DO NZ = 1,M\n WRITE(20,100) MX*DR, NZ*DZ, LP(NZ,MX)\n WRITE(30,101) MX*DR, NZ*DZ, P(NZ,MX)\n END DO \r\n END DO\r\n 100 FORMAT(*(3X,F12.3))\r\n 101 FORMAT(*(3X,F12.3),3X,F12.3,SP,F12.3,SS,\"i\")\r\n PRINT *, \"Main CPU time (s) :\", TF-TI\r\n PRINT *, \"Source pressure P0 (dB) :\", 20*LOG10(ABS(P0))\r\n !-----------------------------------------------------------\n !-----------------------------------------------------------\n !Plotting of results\n CALL SYSTEM('gnuplot -p plot_topo.plt')\r\n !----------------------------------------------------------\nEND PROGRAM PE2D_HTR\r\n!-----------------------------------------------------------\r\n!------------- EXTERNAL PROCEDURES ---------------\r\n!-----------------------------------------------------------\n\n", "meta": {"hexsha": "c76aab75d39cc3d42be607b24136427e032c6dff", "size": 9968, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "Parabolic_Equation/2DPE/.archives/PE2D_HTR.f03", "max_stars_repo_name": "codorkh/AcousticPE", "max_stars_repo_head_hexsha": "a787496a7800d56743fc606a43acbe9e32de35e0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-03-30T14:02:10.000Z", "max_stars_repo_stars_event_max_datetime": "2017-03-30T14:02:10.000Z", "max_issues_repo_path": "Parabolic_Equation/2DPE/.archives/PE2D_HTR.f03", "max_issues_repo_name": "codorkh/infratopo", "max_issues_repo_head_hexsha": "a787496a7800d56743fc606a43acbe9e32de35e0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Parabolic_Equation/2DPE/.archives/PE2D_HTR.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": 33.7898305085, "max_line_length": 123, "alphanum_fraction": 0.3893459069, "num_tokens": 3466, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772318846387, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6673437699324737}} {"text": " SUBROUTINE speval(n,xk,c,t,f,ifail)\n!-----------------------------------------------\n! M o d u l e s\n!-----------------------------------------------\n USE stel_constants\n IMPLICIT NONE\n!-----------------------------------------------\n! D u m m y A r g u m e n t s\n!-----------------------------------------------\n INTEGER :: n, ifail\n REAL(rprec), DIMENSION(0:*) :: xk, c\n REAL(rprec), DIMENSION(*) :: f\n REAL(rprec) :: t\n!-----------------------------------------------\n! L o c a l V a r i a b l e s\n!-----------------------------------------------\n INTEGER :: i, j, l, ip1\n REAL(rprec) :: a10, a11, a12, a20, a21\n REAL(rprec) :: b02, b12, b03, b13, b23, b04, b14, b24, b34\n REAL(rprec) :: d10, d11, d12, d20, d21, d30\n REAL(rprec) :: tm0, tm1, tm2, tp1, tp2, tp3\n\n! evaluate the cubic spline with knots xk and b-spline\n! coefficients c at the point t. return function value\n! in f(1) and derivatives in f(2)-f(4).\n\n ifail=1\n DO j=1,4\n f(j)=0\n END DO\n IF((t.lt.xk(4)) .or. (t.gt.xk(n+1))) RETURN\n i=4\n ip1=n+1\n 20 l=(i+ip1)/2\n IF(ip1-i.le.1) GO TO 40\n IF(t.lt.xk(l)) GO TO 30\n i=l\n GO TO 20\n 30 ip1=l\n GO TO 20\n 40 tm2=t-xk(i-2)\n tm1=t-xk(i-1)\n tm0=t-xk(i)\n tp1=xk(i+1)-t\n tp2=xk(i+2)-t\n tp3=xk(i+3)-t\n d10=tp1+tm0\n d11=tp1+tm1\n d20=tp2+tm0\n d12=tp1+tm2\n d21=tp2+tm1\n d30=tp3+tm0\n b12=tp1/d10\n b02=tm0/d10\n b23=tp1*b12/d11\n b13=tm1*b12/d11+tp2*b02/d20\n b03=tm0*b02/d20\n b34=tp1*b23/d12\n b24=tm2*b23/d12+tp2*b13/d21\n b14=tm1*b13/d21+tp3*b03/d30\n b04=tm0*b03/d30\n f(1)=c(i-3)*b34+c(i-2)*b24+c(i-1)*b14+c(i)*b04\n a12=(c(i-2)-c(i-3))/d12\n a11=(c(i-1)-c(i-2))/d21\n a10=(c(i)-c(i-1))/d30\n f(2)=3*(a12*b23+a11*b13+a10*b03)\n a21=(a11-a12)/d11\n a20=(a10-a11)/d20\n f(3)=6*(a21*b12+a20*b02)\n f(4)=6*(a20-a21)/d10\n ifail=0\n\n END SUBROUTINE speval\n", "meta": {"hexsha": "61e2f6b24dfe07598e791fb825f720bcd3d25e10", "size": 2043, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "COILOPT/Sources/General/speval.f", "max_stars_repo_name": "joseluisvelasco/STELLOPT", "max_stars_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2020-05-08T01:47:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T10:35:28.000Z", "max_issues_repo_path": "COILOPT/Sources/General/speval.f", "max_issues_repo_name": "joseluisvelasco/STELLOPT", "max_issues_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 77, "max_issues_repo_issues_event_min_datetime": "2020-05-08T07:18:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:20:33.000Z", "max_forks_repo_path": "COILOPT/Sources/General/speval.f", "max_forks_repo_name": "joseluisvelasco/STELLOPT", "max_forks_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-02-10T13:47:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T12:53:43.000Z", "avg_line_length": 27.6081081081, "max_line_length": 64, "alphanum_fraction": 0.434165443, "num_tokens": 826, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872046026642944, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6671890216320422}} {"text": "c function agauss.f\nc\nc source\nc Bevington, page 48.\nc\nc purpose\nc evaluate integral of gaussian probability function\nc\nc usage\nc result = agauss (x, averag, sigma)\nc\nc description of parameters\nc x - limit for integral\nc averag - mean of distribution\nc sigma - standard deviation of distribution\nc integration range is averag +/- z*sigma\nc where z = abs(x-averag)/sigma\nc\nc subroutines and function subprograms required\nc none\nc\n\tfunction agauss (x,averag,sigma)\n\tdouble precision z,y2,term,sum,denom\n11\tz=abs(x-averag)/sigma\n\tagauss=0.\n\tif (z) 42,42,21\n21\tterm=0.7071067812*z\n22\tsum=term\n\ty2=(z**2)/2.\n\tdenom=1.\nc\nc accumulate sums of terms\nc\n31\tdenom=denom+2.\n32\tterm=term*(y2*2./denom)\n33\tsum=sum+term\n\tif (term/sum-1.e-10) 41,41,31\n41\tagauss=1.128379167*sum*dexp(-y2)\n42\treturn\n\tend\n", "meta": {"hexsha": "6aefc5033be2c82c143806a1b9a8bb65cbe50cda", "size": 815, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iraf.v2161/math/bevington/agauss.f", "max_stars_repo_name": "ysBach/irafdocgen", "max_stars_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:19:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T16:48:42.000Z", "max_issues_repo_path": "math/bevington/agauss.f", "max_issues_repo_name": "kirxkirx/iraf", "max_issues_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-30T13:48:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-02T19:40:25.000Z", "max_forks_repo_path": "math/bevington/agauss.f", "max_forks_repo_name": "kirxkirx/iraf", "max_forks_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.8780487805, "max_line_length": 54, "alphanum_fraction": 0.7190184049, "num_tokens": 296, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.667189005487118}} {"text": "use LinearSolverClass\nuse FEMDomainClass\nimplicit none\n\ntype(LinearSolver_) :: solver\ntype(FEMDomain_) :: domain\nreal(real64),allocatable :: A_ij(:,:), x_i(:), b_i(:) ! A x = b\n\n! create Mesh\n! create sample mesh (element=1~8, 8-node element)\ncall domain%create(meshtype=\"Cube3D\",x_num=2, y_num=2,z_num=2)\ncall domain%resize(x=2.0d0)\ncall domain%resize(y=2.0d0)\ncall domain%resize(z=2.0d0)\n\n! initialize solver\ncall solver%init()\n\n! For 1st element, create stiffness matrix\nA_ij = domain%StiffnessMatrix(ElementID=1, E=1000.0d0, v=0.30d0)\nb_i = domain%MassVector(&\n ElementID=1,&\n DOF=domain%nd() ,&\n Density=17.0d0,&\n Accel=(/0.0d0, 0.0d0, -9.80d0/)&\n )\n\n! assemble them \ncall solver%assemble(&\n connectivity=domain%connectivity(ElementID=1),&\n DOF=domain%nd() ,&\n eMatrix=A_ij)\n\n! solver % show \u3092\u5b9f\u88c5\u3057\u305f\u3044\u3002 \nprint *, \"index_I\"\ncall print(solver%index_I)\nprint *, \"index_J\"\ncall print(solver%index_J)\n\nend", "meta": {"hexsha": "a78d988c0032c0af98e4fe7a94248be25470a0eb", "size": 927, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/playon_fem/HowToAssembleFEMMatrix.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/fem/HowToAssembleFEMMatrix.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/fem/HowToAssembleFEMMatrix.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": 23.175, "max_line_length": 64, "alphanum_fraction": 0.6968716289, "num_tokens": 335, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087965937712, "lm_q2_score": 0.7185944046238981, "lm_q1q2_score": 0.6671493664358907}} {"text": "!--------------------------------------------------------------------\n! This file is part of HiggsSignals (TS 04/03/2013)\n!--------------------------------------------------------------------\nmodule numerics\n!--------------------------------------------------------------------\n!-- This module contains useful numerical functions inspired by the book\n!-- NUMERICAL RECIPES in FORTRAN (http://www.haoli.org/nr/bookfpdf.html)\n\n!--cof, stp are needed for gammln(xx)\ndouble precision, dimension(6) :: cof = (/76.18009172947146d0, &\n\t-86.50532032941677d0,24.01409824083091d0,-1.231739572450155d0,&\n\t.1208650973866179d-2,-.5395239384953d-5/)\ndouble precision, parameter :: stp = 2.5066282746310005d0\n\ncontains\n!--------------------------------------------------------------------\nfunction factrl(n)\n! USES gammln\n! Returns the value n! as a floating-point number.\n!--------------------------------------------------------------------\ninteger, intent(in) :: n\ndouble precision :: factrl\ninteger :: j,ntop \nREAL a(33)!\tTable to be filled in only as required.\nSAVE ntop,a \nDATA ntop,a(1)/0,1./!\tTable initialized with 0! only.\n\nif (n.lt.0) then\n write(*,*) \"WARNING : negative factorial in factrl\" \nelse if (n.le.ntop) then\t!Already in table.\n factrl=a(n+1) \nelse if (n.le.32) then\t!Fill in table up to desired value.\n do j=ntop+1,n\n a(j+1)=j*a(j)\n enddo\n ntop=n\n factrl=a(n+1)\nelse\n! Larger value than size of table is required. \n! Actually, this big a value is going to overflow on many computers,\n! but no harm in trying.\n factrl=exp(gammln(dble(n+1.)))\nendif\nend function factrl\n!--------------------------------------------------------------------\nfunction gammp(a,x)\n! USES gcf,gser\n! Returns the incomplete gamma function P(a,x). \n!--------------------------------------------------------------------\nimplicit none\ndouble precision, intent(in) :: a,x\ndouble precision :: gammp,gammcf,gamser,gln\nif(x.lt.0..or.a.le.0.) write(*,*) \"WARNING: bad arguments in gammp\"\nif(x.lt.a+1.)then\t\t!\tUse the series representation.\n call gser(gamser,a,x,gln)\n gammp=gamser \nelse\t\t\t\t\t! Use the continued fraction representation\n call gcf(gammcf,a,x,gln)\n gammp=1.-gammcf\t\t!\tand take its complement. \nendif\nend function gammp\n!--------------------------------------------------------------------\nfunction gammq(a,x)\n! USES gcf,gser\n! Returns the incomplete gamma function Q(a, x) \u2261 1 \u2212 P (a, x). \n!--------------------------------------------------------------------\nimplicit none\ndouble precision, intent(in) :: a,x\ndouble precision :: gammq,gammcf,gamser,gln\nif(x.lt.0..or.a.le.0.) write(*,*) \"WARNING: bad arguments in gammq\"\nif(x.lt.a+1.)then\t\t!\tUse the series representation\n call gser(gamser,a,x,gln)\n gammq=1.-gamser\t\t!\tand take its complement. \nelse\t\t\t\t\t!\tUse the continued fraction representation.\n call gcf(gammcf,a,x,gln)\n gammq=gammcf \nendif\nend function gammq\n!--------------------------------------------------------------------\nfunction gammln(xx)\n!--Returns the value ln[\u0393(xx)] for xx > 0.\n!--------------------------------------------------------------------\nimplicit none\ndouble precision, intent(in) :: xx\ninteger :: j\ndouble precision :: gammln,ser,tmp,x,y\nx=xx\ny=x \ntmp=x+5.5d0 \ntmp=(x+0.5d0)*log(tmp)-tmp \nser=1.000000000190015d0 \ndo j=1,6\n y=y+1.d0\n ser=ser+cof(j)/y\nenddo\ngammln=tmp+log(stp*ser/x)\nend function gammln\n!--------------------------------------------------------------------\nsubroutine gser(gamser,a,x,gln)\n! USES gammln\n! Returns the incomplete gamma function P(a,x) evaluated by its series \n! representation as gamser. Also returns ln\u0393(a) as gln. \n!--------------------------------------------------------------------\nimplicit none\ndouble precision, intent(in) :: a,x\ninteger, parameter :: itmax=100\ndouble precision, parameter :: eps=3.e-7\ninteger :: n\ndouble precision :: ap,del,sum,gamser,gln \ngln=gammln(a) \nif(x.le.0.)then\n if(x.lt.0.) write(*,*) \"WARNING: x < 0 in gser\"\n gamser=0.\nelse\n ap=a\n sum=1./a\n del=sum\n do n=1,itmax\n ap=ap+1.\n del=del*x/ap \n sum=sum+del \n if(abs(del).lt.abs(sum)*eps) exit\n if(n.eq.itmax) write(*,*) \"WARNING: a too large, ITMAX too small in gser\"\n enddo\n gamser=sum*exp(-x+a*log(x)-gln)\nendif\nend subroutine gser\n!--------------------------------------------------------------------\nsubroutine gcf(gammcf,a,x,gln)\n! USES gammln\n! Returns the incomplete gamma function Q(a, x) evaluated by its continued\n! fraction representation as gammcf. Also returns ln \u0393(a) as gln. \n!Parameters: \n!--ITMAX is the maximum allowed number of iterations;\n!--EPS is the relative accuracy;\n!--FPMIN is a number near the smallest representable floating-point number.\n!--------------------------------------------------------------------\nimplicit none\ndouble precision, intent(in) :: a,x\ninteger, parameter :: itmax=100\ndouble precision, parameter :: eps=3.e-7\ndouble precision, parameter :: fpmin=1.e-30\ninteger :: i\ndouble precision :: an,b,c,d,del,h,gammcf,gln\ngln=gammln(a)\nb=x+1.-a\nc=1./fpmin\nd=1./b\nh=d\ndo i=1,itmax\n an=-i*(i-a)\n b=b+2.\n d=an*d+b\n if(abs(d).lt.fpmin)d=fpmin\n c=b+an/c\n if(abs(c).lt.fpmin)c=fpmin\n d=1./d\n del=d*c\n h=h*del\n if(abs(del-1.).lt.eps) exit\n if(i.eq.itmax) write(*,*) \"WARNING: a too large, ITMAX too small in gcf\"\nenddo\ngammcf=exp(-x+a*log(x)-gln)*h\nend subroutine gcf\n!--------------------------------------------------------------------\nfunction my_erf(x)\nimplicit none\ndouble precision, intent(in) :: x\ndouble precision :: my_erf\nif(x.lt.0.) then\n my_erf=-gammp(0.5D0,x**2)\nelse \n my_erf=gammp(0.5D0,x**2)\nendif \nend function my_erf\n\n!--------------------------------------------------------------------\nsubroutine invmatrix(A,Y)\n! Calculates the inverse of matrix A and outputs it as Y.\n!--------------------------------------------------------------------\n double precision, dimension(:,:), intent(inout) :: A\n double precision, allocatable, intent(out) :: Y(:,:)\n\n double precision, allocatable :: A1(:,:)\n double precision, allocatable :: temp(:) \n integer, allocatable :: INDX(:) \n integer d, rc, n, i, j\n character*12 input, output\n character*8 s\n double precision, parameter :: small = 1.0D-6\n \n n = size(A,dim=1) \n \n allocate(A1(n,n),stat=ialloc)\n allocate(Y(n,n),stat=ialloc)\n allocate(temp(n),stat=ialloc)\n allocate(INDX(n),stat=ialloc)\n\n do i=1, n \n do j=1, n \n\t A1(i,j) = A(i,j)\n\t Y(i,j) = 0.d0\n end do\n Y(i,i) = 1.d0\n end do\n\n!call LU decomposition routine (only once)\n call LUDCMP(A1,n,INDX,D,rc)\n\n!call solver if previous return code is ok\n!to obtain inverse of A1 one column at a time\n if (rc.eq.0) then\n do j=1, n\n call LUBKSB(A1,n,INDX,Y(:,J))\n end do\n endif\n!the inverse matrix is now in matrix Y\n!the original matrix A1 is destroyed\n\n!print results or error message\n if (rc.eq.1) then\n write(*,*) ' The matrix is singular, no solution !'\n! else\n! write(*,*) ' '\n! write(*,*) ' Inverted matrix Y:'\n! write(*,*)\n! do i=1, n\n! write(*,'(10E14.6)') (Y(i,j),j=1,n)\n! enddo\n end if\n\n!verify A x Y = I (result put in A) \n call MATMULT(A,Y,A1,n,n)\n!A should now contain identity matrix\n! write(*,*) ' '\n! write(*,*) ' Verification A*Y = I:'\n! write(*,*)\n\n! do i=1, n\n! write(*,*) (A1(i,j),j=1,n)\n! enddo\n do i=1,n\n if(abs(A1(i,i)-1).ge.small) then\n! write(*,*) 'WARNING in subroutine invmatrix: Difficulties in inversion!'\n! write(*,*) 'Deviation from 1 is:',(A1(i,i)-1)\n endif \n enddo\n\n end subroutine invmatrix\n!--------------------------------------------------------------------\n!*******************************************************\n!* LU decomposition routines\t\t\t\t\t\t *\n!* *\n!* F90 version by J-P Moreau, Paris *\n!* --------------------------------------------------- *\n!* Reference: *\n!* *\n!* \"Numerical Recipes By W.H. Press, B. P. Flannery, *\n!* S.A. Teukolsky and W.T. Vetterling, Cambridge *\n!* University Press, 1986\" [BIBLI 08]. *\n!* * \n!*******************************************************\n Subroutine LUDCMP(A,N,INDX,D,CODE)\n!--------------------------------------------------------------------\n! * Given an N x N matrix A, this routine replaces it by the LU *\n! * decomposition of a rowwise permutation of itself. A and N *\n! * are input. INDX is an output vector which records the row *\n! * permutation effected by the partial pivoting; D is output *\n! * as -1 or 1, depending on whether the number of row inter- *\n! * changes was even or odd, respectively. This routine is used *\n! * in combination with LUBKSB to solve linear equations or to *\n! * invert a matrix. Return code is 1, if matrix is singular. *\n!--------------------------------------------------------------------\n PARAMETER(NMAX=100,TINY=1.5D-16)\n REAL*8 AMAX,DUM, SUM, A(N,N),VV(NMAX)\n INTEGER CODE, D, INDX(N)\n\n D=1; CODE=0\n\n DO I=1,N\n AMAX=0.d0\n DO J=1,N\n IF (DABS(A(I,J)).GT.AMAX) AMAX=DABS(A(I,J))\n END DO ! j loop\n IF(AMAX.LT.TINY) THEN\n CODE = 1\n RETURN\n END IF\n VV(I) = 1.d0 / AMAX\n END DO ! i loop\n\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 ! k loop\n A(I,J) = SUM\n END DO ! i loop\n AMAX = 0.d0\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 ! k loop\n A(I,J) = SUM\n DUM = VV(I)*DABS(SUM)\n IF(DUM.GE.AMAX) THEN\n IMAX = I\n AMAX = DUM\n END IF\n END DO ! i loop \n \n IF(J.NE.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 ! k loop\n D = -D\n VV(IMAX) = VV(J)\n END IF\n\n INDX(J) = IMAX\n IF(DABS(A(J,J)) < TINY) A(J,J) = TINY\n\n IF(J.NE.N) THEN\n DUM = 1.d0 / A(J,J)\n DO I=J+1,N\n A(I,J) = A(I,J)*DUM\n END DO ! i loop\n END IF \n END DO ! j loop\n\n RETURN\n END subroutine LUDCMP\n!--------------------------------------------------------------------\n Subroutine LUBKSB(A,N,INDX,B)\n!--------------------------------------------------------------------\n! * Solves the set of N linear equations A . X = B. Here A is *\n! * input, not as the matrix A but rather as its LU decomposition, *\n! * determined by the routine LUDCMP. INDX is input as the permuta-*\n! * tion vector returned by LUDCMP. B is input as the right-hand *\n! * side vector B, and returns with the solution vector X. A, N and*\n! * INDX are not modified by this routine and can be used for suc- *\n! * cessive calls with different right-hand sides. This routine is *\n! * also efficient for plain matrix inversion. *\n!--------------------------------------------------------------------\n REAL*8 SUM, A(N,N),B(N)\n INTEGER INDX(N)\n\n II = 0\n\n DO I=1,N\n LL = INDX(I)\n SUM = B(LL)\n B(LL) = B(I)\n IF(II.NE.0) THEN\n DO J=II,I-1\n SUM = SUM - A(I,J)*B(J)\n END DO ! j loop\n ELSE IF(SUM.NE.0.d0) THEN\n II = I\n END IF\n B(I) = SUM\n END DO ! i loop\n\n DO I=N,1,-1\n SUM = B(I)\n IF(I < N) THEN\n DO J=I+1,N\n SUM = SUM - A(I,J)*B(J)\n END DO ! j loop\n END IF\n B(I) = SUM / A(I,I)\n END DO ! i loop\n\n RETURN\n END subroutine LUBKSB\n!--------------------------------------------------------------------\n SUBROUTINE MATMULT(A,B,C,N,M) \n!******************************************* \n!* MULTIPLY TWO REAL MATRICES *\n!* --------------------------------------- * \n!* INPUTS: A MATRIX N*N * \n!* B MATRIX N*M * \n!* N INTEGER * \n!* M INTEGER * \n!* --------------------------------------- * \n!* OUTPUT: C MATRIX N*M, PRODUCT A*B * \n!* * \n!******************************************* \n REAL*8 A(N,N),B(N,M),C(N,M),SUM \n DO I=1,N \n DO J=1,M \n SUM=0. \n DO K=1,N \n SUM=SUM+A(I,K)*B(K,J) \n ENDDO \n C(I,J)=SUM \n ENDDO \n ENDDO \n RETURN \n END subroutine matmult \n!--------------------------------------------------------------------\nend module numerics\n!--------------------------------------------------------------------\n", "meta": {"hexsha": "e03513cc9a41057f17d05449d5e3c363020d7acf", "size": 13265, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Externals/HiggsSignals-2.1.0beta/numerics.f90", "max_stars_repo_name": "yuanfangtardis/vscode_project", "max_stars_repo_head_hexsha": "2d78a85413cc85789cc4fee8ec991eb2a0563ef8", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Externals/HiggsSignals-2.1.0beta/numerics.f90", "max_issues_repo_name": "yuanfangtardis/vscode_project", "max_issues_repo_head_hexsha": "2d78a85413cc85789cc4fee8ec991eb2a0563ef8", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Externals/HiggsSignals-2.1.0beta/numerics.f90", "max_forks_repo_name": "yuanfangtardis/vscode_project", "max_forks_repo_head_hexsha": "2d78a85413cc85789cc4fee8ec991eb2a0563ef8", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-15T12:22:30.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-15T12:22:30.000Z", "avg_line_length": 32.512254902, "max_line_length": 81, "alphanum_fraction": 0.4599321523, "num_tokens": 3560, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952811593496, "lm_q2_score": 0.743168019989179, "lm_q1q2_score": 0.6671384246528232}} {"text": " subroutine tautsp ( tau, gtau, ntau, gamma, s,\n *\t\t\t break, coef, l, k, iflag )\nc from * a practical guide to splines * by c. de boor\nconstructs cubic spline interpolant to given data\nc\t tau(i), gtau(i), i=1,...,ntau.\nc if gamma .gt. 0., additional knots are introduced where needed to\nc make the interpolant more flexible locally. this avoids extraneous\nc inflection points typical of cubic spline interpolation at knots to\nc rapidly changing data.\nc\nc parameters\nc\t input\nc tau\t sequence of data points. must be strictly increasing.\nc gtau corresponding sequence of function values.\nc ntau number of data points. must be at least 4 .\nc gamma indicates whether additional flexibility is desired.\nc\t = 0., no additional knots\nc\t in (0.,3.), under certain conditions on the given data at\nc\t\t points i-1, i, i+1, and i+2, a knot is added in the\nc\t\t i-th interval, i=2,...,ntau-2. see description of meth-\nc\t\t od below. the interpolant gets rounded with increasing\nc\t\t gamma. a value of 2.5 for gamma is typical.\nc\t in (3.,6.), same , except that knots might also be added in\nc\t\t intervals in which an inflection point would be permit-\nc\t\t ted. a value of 5.5\tfor gamma is typical.\nc\t output\nc break, coef, l, k give the pp-representation of the interpolant.\nc\t specifically, for break(i) .le. x .le. break(i+1), the\nc\t interpolant has the form\nc f(x) = coef(1,i) +dx(coef(2,i) +(dx/2)(coef(3,i) +(dx/3)coef(4,i)))\nc\t with dx = x - break(i) and i=1,...,l .\nc iflag = 1, ok\nc\t = 2, input was incorrect. a printout specifying the mistake\nc\t was made.\nc\t workspace\nc s\t is required, of size (ntau,6). the individual columns of this\nc\t array contain the following quantities mentioned in the write-\nc\t up and below.\nc s(.,1) = dtau = tau(.+1) - tau\nc s(.,2) = diag = diagonal in linear system\nc s(.,3) = u = upper diagonal in linear system\nc s(.,4) = r = right side for linear system (initially)\nc\t = fsecnd = solution of linear system , namely the second\nc\t\t\tderivatives of interpolant at tau\nc s(.,5) = z = indicator of additional knots\nc s(.,6) = 1/hsecnd(1,x) with x = z or = 1-z. see below.\nc\nc ------ m e t h o d\t------\nc on the i-th interval, (tau(i), tau(i+1)), the interpolant is of the\nc form\nc (*)\tf(u(x)) = a + b*u + c*h(u,z) + d*h(1-u,1-z) ,\nc with u = u(x) = (x - tau(i))/dtau(i). here,\nc\tz = z(i) = addg(i+1)/(addg(i) + addg(i+1))\nc (= .5, in case the denominator vanishes). with\nc\taddg(j) = abs(ddg(j)), ddg(j) = dg(j+1) - dg(j),\nc\tdg(j) = divdif(j) = (gtau(j+1) - gtau(j))/dtau(j)\nc and\nc\th(u,z) = alpha*u**3 + (1 - alpha)*(max(((u-zeta)/(1-zeta)),0)**3\nc with\nc\talpha(z) = (1-gamma/3)/zeta\nc\tzeta(z) = 1 - gamma*min((1 - z), 1/3)\nc thus, for 1/3 .le. z .le. 2/3, f is just a cubic polynomial on\nc the interval i. otherwise, it has one additional knot, at\nc\t tau(i) + zeta*dtau(i) .\nc as z approaches 1, h(.,z) has an increasingly sharp bend\tnear 1,\nc thus allowing f to turn rapidly near the additional knot.\nc in terms of f(j) = gtau(j) and\nc\tfsecnd(j) = 2.derivative of f\tat tau(j),\nc the coefficients for (*) are given as\nc\ta = f(i) - d\nc\tb = (f(i+1) - f(i)) - (c - d)\nc\tc = fsecnd(i+1)*dtau(i)**2/hsecnd(1,z)\nc\td = fsecnd(i)*dtau(i)**2/hsecnd(1,1-z)\nc hence can be computed once fsecnd(i),i=1,...,ntau, is fixed.\nc f is automatically continuous and has a continuous second derivat-\nc ive (except when z = 0 or 1 for some i). we determine fscnd(.) from\nc the requirement that also the first derivative of f be contin-\nc uous. in addition, we require that the third derivative be continuous\nc across tau(2) and across tau(ntau-1) . this leads to a strictly\nc diagonally dominant tridiagonal linear system for the fsecnd(i)\nc which we solve by gauss elimination without pivoting.\nc\n integer iflag,k,l,ntau,\ti,method,ntaum1\n real break(1),coef(4,1),gamma,gtau(ntau),s(ntau,6),tau(ntau)\n *\t ,alpha,c,d,del,denom,divdif,entry,entry3,factor,factr2,gam\n *\t ,onemg3,onemzt,ratio,sixth,temp,x,z,zeta,zt2\n real alph\n alph(x) = amin1(1.,onemg3/x)\nc\nc there must be at least 4 interpolation points.\n if (ntau .ge. 4)\t\t\tgo to 5\nc print 600,ntau\nc 600 format(8h ntau = ,i4,20h. should be .ge. 4 .)\n\t\t\t\t\tgo to 999\nc\nconstruct delta tau and first and second (divided) differences of data\nc\n 5 ntaum1 = ntau - 1\n do 6 i=1,ntaum1\n\t s(i,1) = tau(i+1) - tau(i)\n\t if (s(i,1) .gt. 0.)\t\tgo to 6\nc\t print 610,i,tau(i),tau(i+1)\nc 610\t format(7h point ,i3,13h and the next,2e15.6,15h are disordered)\n\t\t\t\t\tgo to 999\n 6\t s(i+1,4) = (gtau(i+1)-gtau(i))/s(i,1)\n do 7 i=2,ntaum1\n 7\t s(i,4) = s(i+1,4) - s(i,4)\nc\nconstruct system of equations for second derivatives at tau. at each\nc interior data point, there is one continuity equation, at the first\nc and the last interior data point there is an additional one for a\nc total of ntau equations in ntau unknowns.\nc\n i = 2\n s(2,2) = s(1,1)/3.\n sixth = 1./6.\n method = 2\n gam = gamma\n if (gam .le. 0.)\t method = 1\n if ( gam .le. 3.) \t\tgo to 9\n method = 3\n gam = gam - 3.\n 9 onemg3 = 1. - gam/3.\nc\t\t ------ loop over i ------\n 10 continue\nc\t construct z(i) and zeta(i)\n z = .5\n\t\t\t\t\tgo to (19,11,12),method\n 11 if (s(i,4)*s(i+1,4) .lt. 0.)\tgo to 19\n 12 temp = abs(s(i+1,4))\n denom = abs(s(i,4)) + temp\n if (denom .eq. 0.)\t\tgo to 19\n z = temp/denom\n if (abs(z - .5) .le. sixth) z = .5\n 19 s(i,5) = z\nc ******set up part of the i-th equation which depends on\nc\t the i-th interval\n if (z - .5)\t\t\t21,22,23\n 21 zeta = gam*z\n onemzt = 1. - zeta\n zt2 = zeta**2\n alpha = alph(onemzt)\n factor = zeta/(alpha*(zt2-1.) + 1.)\n s(i,6) = zeta*factor/6.\n s(i,2) = s(i,2) + s(i,1)*((1.-alpha*onemzt)*factor/2. - s(i,6))\nc if z = 0 and the previous z = 1, then d(i) = 0. since then\nc also u(i-1) = l(i+1) = 0, its value does not matter. reset\nc d(i) = 1 to insure nonzero pivot in elimination.\n if (s(i,2) .le. 0.) s(i,2) = 1.\n s(i,3) = s(i,1)/6.\n\t\t\t\t\tgo to 25\n 22 s(i,2) = s(i,2) + s(i,1)/3.\n s(i,3) = s(i,1)/6.\n\t\t\t\t\tgo to 25\n 23 onemzt = gam*(1. - z)\n zeta = 1. - onemzt\n alpha = alph(zeta)\n factor = onemzt/(1. - alpha*zeta*(1.+onemzt))\n s(i,6) = onemzt*factor/6.\n s(i,2) = s(i,2) + s(i,1)/3.\n s(i,3) = s(i,6)*s(i,1)\n 25 if (i .gt. 2)\t\t\tgo to 30\n s(1,5) = .5\nc ******the first two equations enforce continuity of the first and of\nc\t the third derivative across tau(2).\n s(1,2) = s(1,1)/6.\n s(1,3) = s(2,2)\n entry3 = s(2,3)\n if (z - .5)\t\t\t26,27,28\n 26 factr2 = zeta*(alpha*(zt2-1.) + 1.)/(alpha*(zeta*zt2-1.)+1.)\n ratio = factr2*s(2,1)/s(1,2)\n s(2,2) = factr2*s(2,1) + s(1,1)\n s(2,3) = -factr2*s(1,1)\n\t\t\t\t\tgo to 29\n 27 ratio = s(2,1)/s(1,2)\n s(2,2) = s(2,1) + s(1,1)\n s(2,3) = -s(1,1)\n\t\t\t\t\tgo to 29\n 28 ratio = s(2,1)/s(1,2)\n s(2,2) = s(2,1) + s(1,1)\n s(2,3) = -s(1,1)*6.*alpha*s(2,6)\nc\tat this point, the first two equations read\nc\t diag(1)*x1 + u(1)*x2 + entry3*x3 = r(2)\nc\t-ratio*diag(1)*x1 + diag(2)*x2 + u(2)*x3 = 0.\nc\teliminate first unknown from second equation\n 29 s(2,2) = ratio*s(1,3) + s(2,2)\n s(2,3) = ratio*entry3 + s(2,3)\n s(1,4) = s(2,4)\n s(2,4) = ratio*s(1,4)\n\t\t\t\t\tgo to 35\n 30 continue\nc ******the i-th equation enforces continuity of the first derivative\nc\t across tau(i). it has been set up in statements 35 up to 40\nc\t and 21 up to 25 and reads now\nc\t -ratio*diag(i-1)*xi-1 + diag(i)*xi + u(i)*xi+1 = r(i) .\nc\t eliminate (i-1)st unknown from this equation\n s(i,2) = ratio*s(i-1,3) + s(i,2)\n s(i,4) = ratio*s(i-1,4) + s(i,4)\nc\nc ******set up the part of the next equation which depends on the\nc\t i-th interval.\n 35 if (z - .5)\t\t\t36,37,38\n 36 ratio = -s(i,6)*s(i,1)/s(i,2)\n s(i+1,2) = s(i,1)/3.\n\t\t\t\t\tgo to 40\n 37 ratio = -(s(i,1)/6.)/s(i,2)\n s(i+1,2) = s(i,1)/3.\n\t\t\t\t\tgo to 40\n 38 ratio = -(s(i,1)/6.)/s(i,2)\n s(i+1,2) = s(i,1)*((1.-zeta*alpha)*factor/2. - s(i,6))\nc\t ------ end of i loop ------\n 40 i = i+1\n if (i .lt. ntaum1)\t\tgo to 10\n s(i,5) = .5\nc\nc\t ------ last two equations ------\nc the last two equations enforce continuity of third derivative and\nc of first derivative across tau(ntau-1).\n entry = ratio*s(i-1,3) + s(i,2) + s(i,1)/3.\n s(i+1,2) = s(i,1)/6.\n s(i+1,4) = ratio*s(i-1,4) + s(i,4)\n if (z - .5)\t\t\t41,42,43\n 41 ratio = s(i,1)*6.*s(i-1,6)*alpha/s(i-1,2)\n s(i,2) = ratio*s(i-1,3) + s(i,1) + s(i-1,1)\n s(i,3) = -s(i-1,1)\n\t\t\t\t\tgo to 45\n 42 ratio = s(i,1)/s(i-1,2)\n s(i,2) = ratio*s(i-1,3) + s(i,1) + s(i-1,1)\n s(i,3) = -s(i-1,1)\n\t\t\t\t\tgo to 45\n 43 factr2 = onemzt*(alpha*(onemzt**2-1.)+1.)/\n *\t\t (alpha*(onemzt**3-1.)+1.)\n ratio = factr2*s(i,1)/s(i-1,2)\n s(i,2) = ratio*s(i-1,3) + factr2*s(i-1,1) + s(i,1)\n s(i,3) = -factr2*s(i-1,1)\nc at this point, the last two equations read\nc\t diag(i)*xi + u(i)*xi+1 = r(i)\nc -ratio*diag(i)*xi + diag(i+1)*xi+1 = r(i+1)\nc eliminate xi from last equation\n 45 s(i,4) = ratio*s(i-1,4)\n ratio = -entry/s(i,2)\n s(i+1,2) = ratio*s(i,3) + s(i+1,2)\n s(i+1,4) = ratio*s(i,4) + s(i+1,4)\nc\nc\t ------ back substitution ------\nc\n s(ntau,4) = s(ntau,4)/s(ntau,2)\n 50\t s(i,4) = (s(i,4) - s(i,3)*s(i+1,4))/s(i,2)\n\t i = i - 1\n\t if (i .gt. 1)\t\t\tgo to 50\n s(1,4) = (s(1,4)-s(1,3)*s(2,4)-entry3*s(3,4))/s(1,2)\nc\nc\t ------ construct polynomial pieces ------\nc\n break(1) = tau(1)\n l = 1\n do 70 i=1,ntaum1\n\t coef(1,l) = gtau(i)\n\t coef(3,l) = s(i,4)\n\t divdif = (gtau(i+1)-gtau(i))/s(i,1)\n\t z = s(i,5)\n\t if (z - .5)\t\t\t61,62,63\n 61\t if (z .eq. 0.) \t\tgo to 65\n\t zeta = gam*z\n\t onemzt = 1. - zeta\n\t c = s(i+1,4)/6.\n\t d = s(i,4)*s(i,6)\n\t l = l + 1\n\t del = zeta*s(i,1)\n\t break(l) = tau(i) + del\n\t zt2 = zeta**2\n\t alpha = alph(onemzt)\n\t factor = onemzt**2*alpha\n\t coef(1,l) = gtau(i) + divdif*del\n *\t\t + s(i,1)**2*(d*onemzt*(factor-1.)+c*zeta*(zt2-1.))\n\t coef(2,l) = divdif + s(i,1)*(d*(1.-3.*factor)+c*(3.*zt2-1.))\n\t coef(3,l) = 6.*(d*alpha*onemzt + c*zeta)\n\t coef(4,l) = 6.*(c - d*alpha)/s(i,1)\n\t coef(4,l-1) = coef(4,l) - 6.*d*(1.-alpha)/(del*zt2)\n\t coef(2,l-1) = coef(2,l) - del*(coef(3,l) -(del/2.)*coef(4,l-1))\n\t\t\t\t\tgo to 68\n 62\t coef(2,l) = divdif - s(i,1)*(2.*s(i,4) + s(i+1,4))/6.\n\t coef(4,l) = (s(i+1,4)-s(i,4))/s(i,1)\n\t\t\t\t\tgo to 68\n 63\t onemzt = gam*(1. - z)\n\t if (onemzt .eq. 0.)\t\tgo to 65\n\t zeta = 1. - onemzt\n\t alpha = alph(zeta)\n\t c = s(i+1,4)*s(i,6)\n\t d = s(i,4)/6.\n\t del = zeta*s(i,1)\n\t break(l+1) = tau(i) + del\n\t coef(2,l) = divdif - s(i,1)*(2.*d + c)\n\t coef(4,l) = 6.*(c*alpha - d)/s(i,1)\n\t l = l + 1\n\t coef(4,l) = coef(4,l-1) + 6.*(1.-alpha)*c/(s(i,1)*onemzt**3)\n\t coef(3,l) = coef(3,l-1) + del*coef(4,l-1)\n\t coef(2,l) = coef(2,l-1)+del*(coef(3,l-1)+(del/2.)*coef(4,l-1))\n\t coef(1,l) = coef(1,l-1)+del*(coef(2,l-1)+(del/2.)*(coef(3,l-1)\n *\t\t\t+(del/3.)*coef(4,l-1)))\n\t\t\t\t\tgo to 68\n 65\t coef(2,l) = divdif\n\t coef(3,l) = 0.\n\t coef(4,l) = 0.\n 68\t l = l + 1\n 70\t break(l) = tau(i+1)\n l = l - 1\n k = 4\n iflag = 1\n\t\t\t\t\treturn\n 999 iflag = 2\n\t\t\t\t\treturn\n end\n", "meta": {"hexsha": "86e8eeb4e517815bff871358a5ec365efc42541c", "size": 11251, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iraf.v2161/math/deboor/tautsp.f", "max_stars_repo_name": "ysBach/irafdocgen", "max_stars_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:19:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T16:48:42.000Z", "max_issues_repo_path": "math/deboor/tautsp.f", "max_issues_repo_name": "kirxkirx/iraf", "max_issues_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-30T13:48:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-02T19:40:25.000Z", "max_forks_repo_path": "math/deboor/tautsp.f", "max_forks_repo_name": "kirxkirx/iraf", "max_forks_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.8312101911, "max_line_length": 72, "alphanum_fraction": 0.5524842236, "num_tokens": 4802, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333483, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6671384185081158}} {"text": " FUNCTION gammln(xx)\r\n REAL gammln,xx\r\n INTEGER j\r\n DOUBLE PRECISION ser,stp,tmp,x,y,cof(6)\r\n SAVE cof,stp\r\n DATA cof,stp/76.18009172947146d0,-86.50532032941677d0,\r\n *24.01409824083091d0,-1.231739572450155d0,.1208650973866179d-2,\r\n *-.5395239384953d-5,2.5066282746310005d0/\r\n x=xx\r\n y=x\r\n tmp=x+5.5d0\r\n tmp=(x+0.5d0)*log(tmp)-tmp\r\n ser=1.000000000190015d0\r\n do 11 j=1,6\r\n y=y+1.d0\r\n ser=ser+cof(j)/y\r\n11 continue\r\n gammln=tmp+log(stp*ser/x)\r\n return\r\n END\r\n", "meta": {"hexsha": "52f4ab11952864d57e2732af48ace585ece91e9d", "size": 557, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/gammln.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/gammln.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/gammln.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": 26.5238095238, "max_line_length": 69, "alphanum_fraction": 0.5780969479, "num_tokens": 222, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333484, "lm_q2_score": 0.743167997235783, "lm_q1q2_score": 0.6671384082953077}} {"text": " Program zptsvx_example\n\n! ZPTSVX Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_example_aux, Only: nagf_file_print_matrix_complex_gen_comp\n Use lapack_interfaces, Only: zptsvx\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nin = 5, nout = 6\n! .. Local Scalars ..\n Real (Kind=dp) :: rcond\n Integer :: i, ifail, info, ldb, ldx, n, nrhs\n! .. Local Arrays ..\n Complex (Kind=dp), Allocatable :: b(:, :), e(:), ef(:), work(:), x(:, :)\n Real (Kind=dp), Allocatable :: berr(:), d(:), df(:), ferr(:), rwork(:)\n Character (1) :: clabs(1), rlabs(1)\n! .. Executable Statements ..\n Write (nout, *) 'ZPTSVX Example Program Results'\n Write (nout, *)\n Flush (nout)\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n, nrhs\n ldb = n\n ldx = n\n Allocate (b(ldb,nrhs), e(n-1), ef(n-1), work(n), x(ldx,nrhs), &\n berr(nrhs), d(n), df(n), ferr(nrhs), rwork(n))\n\n! Read the lower bidiagonal part of the tridiagonal matrix A and\n! the right hand side b from data file\n\n Read (nin, *) d(1:n)\n Read (nin, *) e(1:n-1)\n Read (nin, *)(b(i,1:nrhs), i=1, n)\n\n! Solve the equations AX = B for X\n Call zptsvx('Not factored', n, nrhs, d, e, df, ef, b, ldb, x, ldx, &\n rcond, ferr, berr, work, rwork, info)\n\n If ((info==0) .Or. (info==n+1)) Then\n\n! Print solution, error bounds and condition number\n\n! ifail: behaviour on error exit\n! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft\n ifail = 0\n Call nagf_file_print_matrix_complex_gen_comp('General', ' ', n, nrhs, &\n x, ldx, 'Bracketed', 'F7.4', 'Solution(s)', 'Integer', rlabs, &\n 'Integer', clabs, 80, 0, ifail)\n\n Write (nout, *)\n Write (nout, *) 'Backward errors (machine-dependent)'\n Write (nout, 100) berr(1:nrhs)\n Write (nout, *)\n Write (nout, *) 'Estimated forward error bounds (machine-dependent)'\n Write (nout, 100) ferr(1:nrhs)\n Write (nout, *)\n Write (nout, *) 'Estimate of reciprocal condition number'\n Write (nout, 100) rcond\n\n If (info==n+1) Then\n Write (nout, *)\n Write (nout, *) 'The matrix A is singular to working precision'\n End If\n Else\n Write (nout, 110) 'The leading minor of order ', info, &\n ' is not positive definite'\n End If\n\n100 Format (1X, 1P, 7E11.1)\n110 Format (1X, A, I3, A)\n End Program\n", "meta": {"hexsha": "0433814b1726480cd4745d173031199e7bf60a8a", "size": 2775, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/zptsvx_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/zptsvx_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/zptsvx_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 34.6875, "max_line_length": 90, "alphanum_fraction": 0.5668468468, "num_tokens": 864, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972818382006, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6671331627605288}} {"text": " Program zgeqrf_example\n\n! ZGEQRF Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use blas_interfaces, Only: dznrm2\n Use lapack_example_aux, Only: nagf_file_print_matrix_complex_gen_comp\n Use lapack_interfaces, Only: zgeqrf, ztrtrs, zunmqr\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nb = 64, nin = 5, nout = 6\n! .. Local Scalars ..\n Integer :: i, ifail, info, j, lda, ldb, lwork, m, n, nrhs\n! .. Local Arrays ..\n Complex (Kind=dp), Allocatable :: a(:, :), b(:, :), tau(:), work(:)\n Real (Kind=dp), Allocatable :: rnorm(:)\n Character (1) :: clabs(1), rlabs(1)\n! .. Executable Statements ..\n Write (nout, *) 'ZGEQRF Example Program Results'\n Write (nout, *)\n Flush (nout)\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) m, n, nrhs\n lda = m\n ldb = m\n lwork = nb*n\n Allocate (a(lda,n), b(ldb,nrhs), tau(n), work(lwork), rnorm(nrhs))\n\n! Read A and B from data file\n\n Read (nin, *)(a(i,1:n), i=1, m)\n Read (nin, *)(b(i,1:nrhs), i=1, m)\n\n! Compute the QR factorization of A\n Call zgeqrf(m, n, a, lda, tau, work, lwork, info)\n\n! Compute C = (C1) = (Q**H)*B, storing the result in B\n! (C2)\n Call zunmqr('Left', 'Conjugate transpose', m, nrhs, n, a, lda, tau, b, &\n ldb, work, lwork, info)\n\n! Compute least squares solutions by back-substitution in\n! R*X = C1\n Call ztrtrs('Upper', 'No transpose', 'Non-Unit', n, nrhs, a, lda, b, &\n ldb, info)\n\n If (info>0) Then\n Write (nout, *) 'The upper triangular factor, R, of A is singular, '\n Write (nout, *) 'the least squares solution could not be computed'\n Else\n\n! Print least squares solutions\n\n! ifail: behaviour on error exit\n! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft\n ifail = 0\n Call nagf_file_print_matrix_complex_gen_comp('General', ' ', n, nrhs, &\n b, ldb, 'Bracketed', 'F7.4', 'Least squares solution(s)', 'Integer', &\n rlabs, 'Integer', clabs, 80, 0, ifail)\n\n! Compute and print estimates of the square roots of the residual\n! sums of squares\n Do j = 1, nrhs\n rnorm(j) = dznrm2(m-n, b(n+1,j), 1)\n End Do\n\n Write (nout, *)\n Write (nout, *) 'Square root(s) of the residual sum(s) of squares'\n Write (nout, 100) rnorm(1:nrhs)\n End If\n\n100 Format (3X, 1P, 7E11.2)\n End Program\n", "meta": {"hexsha": "882dda02879f430d24ea90fa24c204d8ea6599cb", "size": 2750, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/zgeqrf_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/zgeqrf_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/zgeqrf_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 33.950617284, "max_line_length": 90, "alphanum_fraction": 0.5745454545, "num_tokens": 861, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.870597268408361, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6671331571159053}} {"text": "program spline_test\n use spline\n implicit none\n\n integer, parameter :: n1 = 99, n2 = 10\n real(8), parameter :: pi = 4*atan(1d0)\n integer :: k\n real(8) :: x1(n1), y1(n1), x2(n2), y2(n2), y1s(n1,3),&\n coeff(n2-1, 5), y1d(n1)\n \n open(unit=1, file='out1.txt', recl=1024)\n open(unit=2, file='out2.txt', recl=1024)\n \n x1 = -pi/2+2*pi/(n1-1)*(/(2*k, k=0,n1-1)/)\n y1 = sin(x1)\n y1d = cos(x1)\n !x2 = x1([3,4,5,6,7,8,56,70,85,99])\n x2 = x1([5,15,25,35,45,55,65,75,85,95])\n y2 = sin(x2)\n\n coeff = spline_coeff(x2, y2)\n \n y1s = spline_val(coeff, x1)\n \n do k=1,n1\n write(1,*) x1(k), y1(k), y1s(k,1), y1s(k,2), y1s(k,3), y1d(k)\n end do\n\n do k=1,n2\n write(2,*) x2(k), y2(k)\n end do\n \n print *, \"Hello Splines\"\nend program spline_test\n", "meta": {"hexsha": "4fa748d6e7c7bcde1ff11c8fa7dfd39d08147e32", "size": 759, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "spline_test.f90", "max_stars_repo_name": "itpplasma/spline", "max_stars_repo_head_hexsha": "748f3012d18c637d9a94848610a3097b880185e9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-11-30T16:47:45.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-30T16:47:45.000Z", "max_issues_repo_path": "spline_test.f90", "max_issues_repo_name": "itpplasma/spline", "max_issues_repo_head_hexsha": "748f3012d18c637d9a94848610a3097b880185e9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "spline_test.f90", "max_forks_repo_name": "itpplasma/spline", "max_forks_repo_head_hexsha": "748f3012d18c637d9a94848610a3097b880185e9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.6857142857, "max_line_length": 66, "alphanum_fraction": 0.5494071146, "num_tokens": 366, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934406, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6671331519703044}} {"text": "program Constrained_Points\n implicit none\n\n integer, parameter :: samples = 100\n integer :: i, j, n, randpoint\n real :: r\n\n type points\n integer :: x, y\n end type\n\n type(points) :: set(500), temp\n\n! Create set of valid points\n n = 0\n do i = -15, 15\n do j = -15, 15\n if(sqrt(real(i*i + j*j)) >= 10.0 .and. sqrt(real(i*i + j*j)) <= 15.0) then\n n = n + 1\n set(n)%x = i\n set(n)%y = j\n end if\n end do\n end do\n\n! create 100 random points\n! Choose a random number between 1 and n inclusive and swap point at this index with point at index 1\n! Choose a random number between 2 and n inclusive and swap point at this index with point at index 2\n! Continue in this fashion until 100 points have been selected\n call random_seed\n do i = 1, samples\n call random_number(r)\n randpoint = r * (n + 1 - i) + i\n temp = set(i)\n set(i) = set(randpoint)\n set(randpoint) = temp\n end do\n\n! In order to facilitate printing sort random points into ascending order\n! sort x in ascending order\n do i = 2, samples\n j = i - 1\n temp = set(i)\n do while (j>=1 .and. set(j)%x > temp%x)\n set(j+1) = set(j)\n j = j - 1\n end do\n set(j+1) = temp\n end do\n\n! sort y in ascending order for same x\n do i = 2, samples\n j = i - 1\n temp = set(i)\n do while (j>=1 .and. set(j)%x == temp%x .and. set(j)%y > temp%y)\n set(j+1) = set(j)\n j = j - 1\n end do\n set(j+1) = temp\n end do\n\n! print circle\n write(*,\"(a,a)\", advance=\"no\") repeat(\" \", set(1)%y+15), \"*\"\n do i = 2, samples\n if(set(i)%x == set(i-1)%x) then\n write(*,\"(a,a)\", advance=\"no\") repeat(\" \", set(i)%y - set(i-1)%y-1), \"*\"\n else\n n = set(i)%x - set(i-1)%x\n do j = 1, n\n write(*,*)\n end do\n write(*,\"(a,a)\", advance=\"no\") repeat(\" \", set(i)%y+15), \"*\"\n end if\n end do\n\nend program\n", "meta": {"hexsha": "51302521b86eaf221250737c5a0c60f09a3ff3ce", "size": 1898, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Constrained-random-points-on-a-circle/Fortran/constrained-random-points-on-a-circle.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/Constrained-random-points-on-a-circle/Fortran/constrained-random-points-on-a-circle.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/Constrained-random-points-on-a-circle/Fortran/constrained-random-points-on-a-circle.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 24.6493506494, "max_line_length": 101, "alphanum_fraction": 0.543203372, "num_tokens": 647, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972583359806, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.6671331401043498}} {"text": "! Program to test the MINVAL and MAXVAL intrinsics\nprogram testmmval\n implicit none\n integer, dimension (3, 3) :: a\n integer, dimension (3) :: b\n logical, dimension (3, 3) :: m, tr\n integer i\n character (len=9) line\n\n a = reshape ((/1, 2, 3, 5, 4, 6, 9, 8, 7/), (/3, 3/));\n\n tr = .true.\n\n b = minval (a, 1)\n if (any(b .ne. (/1, 4, 7/))) call abort\n write (line, 9000) minval (a, 1)\n if (line .ne. ' 1 4 7') call abort\n\n m = .true.\n m(1, 1) = .false.\n m(1, 2) = .false.\n b = minval (a, 1, m)\n if (any(b .ne. (/2, 4, 7/))) call abort\n b = minval (a, 1, m .and. tr)\n if (any(b .ne. (/2, 4, 7/))) call abort\n write (line, 9000) minval(a, 1, m)\n if (line .ne. ' 2 4 7') call abort\n\n b = maxval (a, 1)\n if (any(b .ne. (/3, 6, 9/))) call abort\n write (line, 9000) maxval (a, 1)\n if (line .ne. ' 3 6 9') call abort\n\n m = .true.\n m(1, 2) = .false.\n m(1, 3) = .false.\n b = maxval (a, 1, m)\n if (any(b .ne. (/3, 6, 8/))) call abort\n b = maxval (a, 1, m .and. tr)\n if (any(b .ne. (/3, 6, 8/))) call abort\n write (line, 9000) maxval(a, 1, m)\n if (line .ne. ' 3 6 8') call abort\n\n9000 format(3I3)\nend program\n", "meta": {"hexsha": "cfd1a5b2d743085297d7666f9bc0f74d10974962", "size": 1175, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_mmval.f90", "max_stars_repo_name": "best08618/asylo", "max_stars_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-05-02T17:34:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-17T10:15:18.000Z", "max_issues_repo_path": "llvm-gcc-4.2-2.9/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_mmval.f90", "max_issues_repo_name": "vidkidz/crossbridge", "max_issues_repo_head_hexsha": "ba0bf94aee0ce6cf7eb5be882382e52bc57ba396", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "llvm-gcc-4.2-2.9/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_mmval.f90", "max_forks_repo_name": "vidkidz/crossbridge", "max_forks_repo_head_hexsha": "ba0bf94aee0ce6cf7eb5be882382e52bc57ba396", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-27T00:22:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-01T09:41:02.000Z", "avg_line_length": 25.5434782609, "max_line_length": 57, "alphanum_fraction": 0.5072340426, "num_tokens": 552, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972549785203, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.6671331375315492}} {"text": "MODULE corr_focus_mod\n\n USE myMath_module; USE seism_uti_module\n ! USE myString_mod\n\n IMPLICIT NONE\n\n ! PRIVATE :: \n\nCONTAINS\n!==================================\nfunction SQRT_to_odd1(n2) result(od)\ninteger :: n2, od\ninteger :: j, k\n! Gieven input n2, find closest od >= 3, such that od^2 == n2\n\nj = floor( (sqrt(real(n2))-1.)/2. )\nk = j+1\n\nj = 2*j+1 ! odd\nk = 2*k+1 ! odd\n\nif (n2 - j**2 <= k**2 - n2) then\n od = j\nelse\n od = k\nend if\nod = max(1, od)\n\nend function\n!-----------\nsubroutine SQRT_to_odd2(od, er, n2)\ninteger, intent(out) :: od(2), er\ninteger, intent(in) :: n2\ninteger :: j(4), k(4), e(4), i, loc(1), resi\n\n! Given an input n2, find the best od(2)>=3, such that \\sum od(:)^2 == n2\n\nj = (/ -1, 2, 1, 0 /) + floor( (sqrt(real(n2)/2.)-1.)/2. )\n\nj = 2*j + 1 ! odd\ne = 10000 ! init big\nod= 0\n\ndo i = 1,4\n resi = n2 - j(i)**2 \n if (j(i) <= 1 .OR. resi <= 0) cycle\n k(i) = SQRT_to_odd1(resi) \n e(i) = abs(resi - k(i)**2)\nend do\n\nloc = minloc(e)\nod(1) = j( loc(1) )\nod(2) = k( loc(1) )\ner = e( loc(1) )\nend subroutine\n!------------\n\nsubroutine SQRT_to_odd3(od, er, n2)\ninteger, intent(out) :: od(3), er\ninteger, intent(in) :: n2\ninteger :: j(4), e(4), i, loc(1), resi\n\n! Given an input n2, find the best od(3), such that \\sum od(:)^2 == n2\n\nj = (/ -1, 2, 1, 0 /) + floor( (sqrt(real(n2)/3.)-1.)/2. )\n\nj = 2*j + 1 ! odd\ne = 10000 ! init big\nod= 0\n\ndo i = 1,4\n resi = n2 - j(i)**2\n if (j(i) <=1 .OR. resi <=0) cycle\n call SQRT_to_odd2(od(2:3), e(i), resi)\nend do\n\nloc = minloc(e)\ner = e ( loc(1) )\nod(1) = j(loc(1) )\n\nif (er==10000) return ! all are invalid\n\nif (loc(1) /= 4) then\n call SQRT_to_odd2(od(2:3), er, n2-od(1)**2)\nend if\n\nend subroutine\n!------------\nsubroutine SQRT_to_odd4(od, er, n2)\ninteger, intent(out) :: od(4), er\ninteger, intent(in) :: n2\ninteger :: j(4), e(4), i, loc(1), resi\n\n! Given an input n2, find the best od(4), such that \\sum od(:)^2 == n2\n\nj = (/ -1, 2, 1, 0 /) + floor( (sqrt(real(n2)/4.)-1.)/2. )\n\nj = 2*j + 1 ! odd\ne = 10000 ! init big\nod= 0\n\ndo i = 1,4\n resi = n2 - j(i)**2\n if (j(i) <=1 .OR. resi <=0) cycle\n call SQRT_to_odd3(od(2:4), e(i), resi)\nend do\n\nloc = minloc(e)\ner = e ( loc(1) )\nod(1) = j(loc(1) )\n\nif (er==10000) return ! all are invalid\n\nif (loc(1) /= 4) then\n call SQRT_to_odd3(od(2:4), er, n2-od(1)**2)\nend if\n\nend subroutine\n!-------------\nsubroutine Bspline_wids(wids, M)\n! rect width M, to be equated w/ a B-spline with 4 narrower widths --> their spatial var. are eq\ninteger, intent(out):: wids(4)\ninteger, intent(in) :: M ! var = (M^2 - 1)/12\n\ninteger :: er\nif (M <= 6) then\n wids = 3\n return\nend if\ncall SQRT_to_odd4(wids, er, M*M + 3)\n\nend subroutine\n!-------------\n\nsubroutine make_imp_resp_Bspline(V, wids)\n! B-spline with 4 narrower widths. Find the impulse response in V\nreal, allocatable, intent(out):: V(:) \ninteger, intent(in) :: wids(4)\n\ninteger :: M2, M\nreal(8), allocatable :: tmp1(:), tmp2(:)\n\nM = sum(wids) - (size(wids) - 1) ! because of keeping conv'ing\nM2 = M/2\n\nif (allocated(V)) deallocate(V)\nallocate(V(M), tmp1(M), tmp2(M))\nV = 0.\nV(M2+1) = 1.\ncall Bspline1D_mirr_conv_S(V, wids, tmp1, tmp2)\n\ndeallocate(tmp1, tmp2)\n\nend subroutine\n\n!=============\n\nsubroutine index_intersec(hsi,tsi, Hbi,Tbi, hs,ts, Hb,Tb)\n! a short vector whose index range on the domain of a big vector is\n! supposedly [hs,ts]. The big vector's valid index range is [Hb,Tb].\n! Intersect them, so now the [hsi,tsi] of the small vec resides on \n! [Hbi, Tbi] of the big one.\n\ninteger, intent(out):: hsi,tsi, Hbi,Tbi\ninteger, intent(in) :: hs, ts, Hb, Tb\ninteger :: L\n\nL = ts-hs+1 ! small vec's length\n\nif (hs>=Hb) then\n hsi = 1\n Hbi = hs\nelse\n hsi = 1+Hb-hs\n Hbi = Hb\nend if\n\nif (ts<=Tb) then\n tsi = L\n Tbi = ts\nelse\n tsi = L - (ts-Tb)\n Tbi = Tb\nend if\n\nend subroutine\n!-------------\n\nsubroutine corr_cent(y, u, W, lag12, HEAD)\n! y = Xcorr(u, W)\n! u: N x 1\n! W: M x 1, M << N, M odd, M's reference point is its center, if HEAD == <0>\n! else, the reference pnt is W(1)\n!\n! W sliding across u, produce the corr output y\n! lag12 2 x 1, the lag range of W's reference pnt wrt u\n! y: lag12(2)-lag12(1)+1 x 1\n!=== All vectors' memory assigned ====\n\nreal, intent(out):: y(:)\nreal, intent(in) :: u(:), W(:)\ninteger,intent(in) :: lag12(2)\ninteger,intent(in),optional :: HEAD\n\ninteger :: i, hsi,tsi, Hbi,Tbi, N, M, M2, headx ! local var HEAD\n! integer, save :: callcounter = 0\n\nheadx = 0; if(present(HEAD)) headx = HEAD\n\nN = size(u)\nM = size(W)\nif (headx==0) then\n M2 = M/2\n do i = lag12(1), lag12(2)\n call index_intersec(hsi,tsi, Hbi,Tbi, i-M2, i+M2, 1, N)\n y(i-lag12(1)+1) = sum(W(hsi:tsi)*u(Hbi:Tbi))\n end do\nelse\n do i = lag12(1), lag12(2)\n call index_intersec(hsi,tsi, Hbi,Tbi, i, i+M-1, 1, N)\n y(i-lag12(1)+1) = sum(W(hsi:tsi)*u(Hbi:Tbi))\n end do\nend if\n!if (callcounter == 0) then\n! call write_binfile('y.bin', y) !!!!!!!!!\n! call write_binfile('u.bin', u) !!!!!!!!!\n! call write_binfile('W.bin', W) !!!!!!!!!\n!end if\n!callcounter = callcounter + 1\n\nend subroutine\n!-------------\nsubroutine squashNega(f,g, x, alph, MODE)\n! idea is: reduce the influence of the negative part of x\n! x: vector\n! alph: 1x1\n! f: same size as x\n! g: gradient elem-wise, \\partial f_k / \\partial x_k, so same size as x\n!\n! MODE == 0:\n! map x \\in [-1, 1] to f \\in [0, 1] ~ exp(x)\n! x is normalized, so \\in [-1, 1]\n!\n! MODE == 1, 2:\n! f(x) = exp(alph.*x), when x<=0. When x>0:\n! 1:\n! 1 + alph.*x f, f' conti\n! 2:\n! alph^2/2 .*(x+ 1/alph).^2 + 1/2, f, f', f\" conti\n\nreal, intent(out) :: f(:), g(:)\nreal, intent(in) :: x(:), alph\ninteger,intent(in):: MODE\nreal :: bet, exa\n\nselect case (MODE)\ncase (0)\n exa = exp(alph)\n bet = 1./(exa - 1./exa)\n g = exp(alph*x)\n f = bet * (g - 1./exa)\n g = (alph*bet) * g\ncase (1)\n where (x<0)\n f = exp(alph*x)\n g = alph*f\n elsewhere\n f = 1 + alph*x\n g = alph\n end where\ncase (2)\n bet = alph*alph\n where (x<0)\n f = exp(alph*x)\n g = alph*f\n elsewhere\n f = 0.5*(1. + bet* (x + 1/alph)**2)\n g = bet* (x + 1/alph)\n end where\nend select\n\nend subroutine\n!-------------\n\nsubroutine localMx(pk, y, L2, Boff, thresh, pktmp, itmp)\n! y N x 1 waveform\n! pk N x 1 logical, marking the local peaks of y within a\n! [-L2, L2] neighborhood\n! Boff 1 x 1 the distance within Boff near the boundary is turned off\n! thresh 1x1 peaks must >= thresh\n! pktmp Nx1 same size as pk\n\nlogical, intent(out) :: pk(:)\nlogical, intent(inout) :: pktmp(:)\nreal, intent(in) :: y(:), thresh\ninteger, intent(in) :: L2, Boff\ninteger, intent(inout) :: itmp(:)\n\ninteger :: N, i, M, M2, lf, rt, id(1)\n\nN = size(y)\npk = .false.\npktmp = .false.\npktmp(2:N-1) = y(2:N-1) > y(1:N-2) .and. y(2:N-1) > y(3:N) &\n .and. y(2:N-1) > thresh\n\npktmp(1:Boff) = .false.\npktmp(N-Boff+1:N) = .false. ! preventing peaks near the boundaries\n\nM = count(pktmp)\nitmp = pack( (/(i, i=1,N) /), pktmp ) ! idx to peaks\n\ndo i = 1, M\n lf = max(1, itmp(i)-L2)\n rt = min(N, itmp(i)+L2)\n id = maxloc(y(lf:rt), pktmp(lf:rt))\n if (id(1) == itmp(i)-lf+1) pk(itmp(i)) = .true.\nend do\n\nend subroutine\n!-------------\n\nsubroutine envelop_mx(y, pk, itmp, GauSig2)\n! y N x 1, waveform, in-place form an envelop over the peaks of y\n! pk N x 1, logical, marking the peaks of y\n! GauSig2 1 x 1 real, Gaussian's sigma^2. The Gaussian is the yenv outside the itmp range\n! if GauSig2 <= 0, then outside is unmodified (0 most likely)\n! if ~present, then outside is constant\nreal, intent(inout) :: y(:)\nlogical, intent(in) :: pk(:)\ninteger, intent(inout) :: itmp(:)\nreal, intent(in), optional :: GauSig2\n\ninteger :: N, i, M, dx, x1, x2\nreal :: y1, y2\n\ninteger, save :: callcounter = 0\n\nN = size(y)\nitmp = pack( (/ (i, i=1,N) /), pk ) ! idx to peaks\nM = count(pk)\n\nif (callcounter==0) then\n call write_binfile('y--0.bin', y) !!!!!!!!!\nelse if (callcounter==1) then\n call write_binfile('y--1.bin', y) !!!!!!!!!\nend if\n\nif (present(GauSig2)) then\n if (GauSig2 > 0) then\n y(1:itmp(1)) = y(itmp(1))*exp( (/ (i, i=1-itmp(1),0) /)**2 /(-2.*GauSig2) )\n y(itmp(M):N) = y(itmp(M))*exp( (/ (i, i=0,N-itmp(M)) /)**2 /(-2.*GauSig2) )\n end if ! otherwise don't modify\nelse\n y(1:itmp(1)) = y(itmp(1))\n y(itmp(M):N) = y(itmp(M))\nend if\n\ndo i = 1, M-1\n x1 = itmp(i)\n x2 = itmp(i+1)\n dx = x2 - x1\n y1 = y(x1)\n y2 = y(x2)\n y(x1:x2) = y2 + (y1-y2)/2. * (1.+ &\n cos( (/ (N, N=0, x2-x1) /)/(real(dx)/PI) ) )\nend do\n\nif (callcounter==0) then\n call write_binfile('yenv0.bin', y) !!!!!!!!!\nelse if (callcounter==1) then\n call write_binfile('yenv1.bin', y) !!!!!!!!!\nend if\ncallcounter = callcounter + 1\n\nend subroutine\n!-------------\n\nsubroutine corr_focusing1D(J, g, u,upks,V,Vwids, d,W0,W1,Wsig2, alph, lag12,&\n unrm,gchnk, dtprd,fdtp, gdtp, simi,simF, dnrm, dtmp, &\n itmp,pk,pktmp,Vtmp, tmpD1,tmpD2)\n! J = \\Sum_k { \\int W f(Xcorr^k, alph) / \\int f(Xcorr^k, alph) }\n! k: peak index in u\n! Xcorr^k corr(d, u^k), where d: data trace; u^k: kth u's chunk\n!\n! g: grad J / u, N x 1\n! f(., alpha, MODE) squashing-negativ nonlinearity\n! \n! u N x 1 predicted trace\n! upks Npk x 1 peak locations in u\n! around each peak [-M/2, M/2] is a u's chunk\n! NOTE: u's peaks should be M/2 away from the trace beg & end! \n!\n! V M x 1 the narrow weight profile for a /u chunk/\n! Vwids Nvwids x 1 rect wids, keep convolving => the B-spline V\n!\n! d N x 1 data trace\n! W0 lag(2)-lag(1)+1 x 1 Gaussian weigtht profile over xcorr lags\n! W1 ditto specific weights\n! \n! Wsig2 1x 1 for overall weight profile (e.g., Gaussian, B-spline) over Xcorr shifts,\n! encouraging xcorr mass @ 0.\n! lag12 2 x 1 the Xcorr is limied to this range of *relative* lags (relative means,\n! assuming u chunk's center @ t=0, where does it shift around on d's trace?)\n\n! MODE: norm. dot-prod followed by a nega-squashing nonlinearity of mode\n! 0: [e(a x)\n! 1: [e(a x), x-b]\n! 2: [e(a x), c(x-b)^2+d], then \\int w/ weight\n\nreal, intent(out) :: J, g(:)\nreal, intent(in) :: u(:), d(:), V(:), W0(:), Wsig2, alph\ninteger,intent(in) :: upks(:), Vwids(:), lag12(2)\nreal ,intent(inout):: unrm(:), gchnk(:), W1(:), dtprd(:,:), &\n fdtp(:,:),gdtp(:,:), & ! all pre-allocated memory\n simi(:,:),simF(:,:), dnrm(:), dtmp(:), Vtmp(:) \n! unrm: u chunks' norm (Npk #)\n! gchnk: g_chunk M x 1\n! dtprd: normlz. dot-prod (d, u_chunks) diff(lag12)+1 x Npk\n! fdtp, gdtp: funct & grad of passing dtprd through a nega-squashing nonlinearity\n! same size as dtprd\n! simi: init. similarity weights, between d's elements and u's chunks, N x Npk\n! simF: Final ... (after double-normalizing)\n! From simF/simi, we know the gain weights.\n! dnrm: d's local sliding-window's norm, N x 1\n! dtmp: N x 1\n! Vtmp: length(M), temp for a u chunk\n\nreal(8),intent(inout) :: tmpD1(:), tmpD2(:) ! for Bspline V (*) ..., length(M)\ninteger,intent(inout) :: itmp(:) ! peak indices \nlogical,intent(inout) :: pk(:), pktmp(:) \n\ninteger :: N, Npk, i, k, M, M2, lf,rt, da,db,Va,Vb, lg1,lg2, dh,dt,Wh,Wt \n ! da,db,Va,Vb represent beg & end indices on d and V (after intersection)\n ! dh,dt,Wh,Wt ... beg & end indices on d and W (after intersection)\n\nreal :: Jk, E, eps, thresh\n\n! dtprd & simi: d-trace & u chunk\n\nN = size(d)\nM = size(V); M2 = M/2\nNpk = size(upks)\n\n! compute d_nrm:\ndnrm = d*d\ncall Bspline_conv(dnrm, Vwids, tmpD1, tmpD2)\ndnrm = sqrt(dnrm) ! local d_norm\n! call write_binfile('dnrm.bin',dnrm) !!!!!!!!\n! compute u_nrm:\n\neps = 1.e-4\nsimi = 0.\nsimF = 0.\ndtprd= 0.\n\ndo k = 1, Npk\n lf = upks(k)-M2 ! may outside [1,N]\n rt = upks(k)+M2\n call index_intersec(Va,Vb, da,db, lf, rt, 1,N)\n\n lg1= lag12(1) + upks(k) ! may outside [1,N]\n lg2= lag12(2) + upks(k)\n call index_intersec(Wh,Wt, dh,dt, lg1,lg2, 1,N)\n\n Vtmp = 0.\n Vtmp(Va:Vb) = V(Va:Vb) * u(da : db) ! weighted u chunk\n unrm(k) = sqrt(sum(Vtmp(Va:Vb) * u(da : db) )) ! chunk norm, weighted\n call corr_cent(dtprd(Wh:Wt,k), d, Vtmp, (/dh, dt /) )\n! dtprd(Wh:Wt,k) = dtprd(Wh:Wt,k)/(unrm(k)+eps)/(dnrm(dh:dt) + eps)\n\n call squashNega(fdtp(Wh:Wt,k),gdtp(Wh:Wt,k), dtprd(Wh:Wt,k), alph, 2) ! MODE 2\n simi(dh:dt,k) = fdtp(Wh:Wt,k)\nend do\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n#if 0 \n\n call write_binfile('dtprd.bin',dtprd) !!!!!!!!!\n call write_binfile('fdtp.bin', fdtp) !!!!!!!!!\n call write_binfile('simi0.bin', simi) !!!!!!!!!\n\n! threshold of peaks\nthresh = 0.2*minval(maxval(simi, 1))\n\nlf = 0.5*M2 ! a temp int\ndo k = 1, Npk\n call localMx(pk, simi(:,k), lf, max(M2,maxval(abs(lag12))), thresh, pktmp, itmp)\n call envelop_mx( simi(:,k), pk, itmp, real(lag12(1)**2) ) ! should prod Gaussian 1st, then mark peaks\n\n simi(:,k) = simi(:,k) * exp( (/ (i-upks(k), i=1,N) /)**2 /(-2.*Wsig2) )\nend do ! init similarity envelope\n\ncall write_binfile('simi.bin',simi) !!!!!!!!!\n\nsimF = simi\n! compute simi as attribution weight \ndtmp = sum(simF, 2) + eps\ndo k = 1, Npk\n simF(:,k) = simF(:,k) / dtmp ! 1) normalize over u_chunks\nend do\ncall write_binfile('simF1.bin',simF) !!!!!!!!!\n\ndo k = 1, Npk\n simF(:,k) = simF(:,k) / (sum(simF(:,k))+eps) ! 2) normalize over t\nend do\ncall write_binfile('simF2.bin',simF) !!!!!!!!!\n\n\ndtmp = sum(simF, 2) + eps\ndo k = 1, Npk\n simF(:,k) = simF(:,k) / dtmp ! 3) normalize over u_chunks\nend do\n call write_binfile('simF3.bin',simF) !!!!!!!!!\n\n#endif\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\nJ = 0.\ng = 0.\ndo k = 1, Npk\n lf= upks(k)-M2\n rt= upks(k)+M2\n call index_intersec(Va,Vb, da,db, lf, rt, 1,N)\n\n lg1= lag12(1) + upks(k)\n lg2= lag12(2) + upks(k)\n call index_intersec(Wh,Wt, dh,dt, lg1,lg2, 1,N)\n\n\n W1 = W0 !* simF(lg1:lg2,k)/(simi(lg1:lg2,k) + eps)\n\n E = sum(fdtp(Wh:Wt,k)) + eps\n Jk= sum(W1(Wh:Wt) * fdtp(Wh:Wt,k)) / E\n\n gchnk = 0.\n\n! call corr_cent(gchnk,d,(W1(Wh:Wt)-Jk)*gdtp(Wh:Wt,k)/(dnrm(dh:dt)+eps),dh+(/-M2,M2/),1)\n! gchnk(Va:Vb) = gchnk(Va:Vb) -sum((W1(Wh:Wt)-Jk)*gdtp(Wh:Wt,k)*dtprd(Wh:Wt,k))/(unrm(k)+eps) *u(da:db)\n! gchnk(Va:Vb) = gchnk(Va:Vb) * V(Va:Vb) / ((unrm(k)+eps) * E)\n\n call corr_cent(gchnk,d,(W1(Wh:Wt)-Jk)*gdtp(Wh:Wt,k), dh+(/-M2,M2/), 1)\n gchnk(Va:Vb) = gchnk(Va:Vb) * V(Va:Vb) / E\n\n g(da:db) = g(da:db) + gchnk(Va:Vb)\n\n J = J + Jk\nend do\n! call write_binfile('grd.bin', g) !!!!!!!!!\n\nend subroutine\n!-------------\n\n\nsubroutine corr_focusing_Adj_Src(AdjS1, misF, datP1, datO1, f0, dt, Terr_max)\n! Output:\n! AdjS nt x ng adjoint source, or the negative-gradient direction to minimize the misfit\n! misF scalar criterion function (of negative value)\n!\n! Input:\n! datP nt x ng predicted data\n! datO nt x ng observed data\n! f0 peak freq. (Hz) \n! dt delta t (s)\n! Terr_max max time error (s)\n\nreal, intent(out) :: AdjS1(:,:), misF\nreal, intent(in) :: datP1(:,:), datO1(:,:), f0, dt, Terr_max\n!--------------------\n\nreal :: J, alph, Wsig2, thresh, stdV\ninteger :: Vwids(4), lag12(2)\nreal, allocatable:: V(:), unrm(:), gchnk(:), dtprd(:,:),&\n fdtp(:,:),gdtp(:,:), W0(:), W1(:), &\n simi(:,:),simF(:,:), dnrm(:), dtmp(:), Vtmp(:), &\n datP(:,:),datO(:,:), AdjS(:,:)\ninteger,allocatable:: upks(:), itmp(:) \nreal(8),allocatable:: tmpD1(:), tmpD2(:) \nlogical,allocatable:: pk(:), pktmp(:) \n\ninteger :: nt1, nt, ng, ig, i, M2, M, L2, L, Npk, Npkmx\n\nnt1 = size(datP1,1)\nng = size(datP1,2)\nnt = 3*nt1\n\nallocate( datP(nt,ng), datO(nt,ng), AdjS(nt,ng) )\ndo i = 1, nt1\n datP(i+nt1,:) = datP1(i,:); datO(i+nt1,:) = datO1(i,:)\n datP(i,:) = datP1(nt1+1-i,:); datO(i,:) = datO1(nt1+1-i,:) ! mirror reflec\n datP(i+2*nt1,:) = datP(i,:); datO(i+2*nt1,:) = datO(i,:)\nend do\n\nL2 = NINT(Terr_max/dt); L = 2*L2+1 ! Xcorr lag range:\nlag12 = (/ -L2, L2 /)\n\nM = NINT(2/f0/dt); M2 = M/2; M = 2*M2+1 ! wavelet chunk length ~ 2 T, odd\ncall Bspline_wids(Vwids, M)\ncall make_imp_resp_Bspline(V, Vwids)\nM = size(V); M2 = M/2\n!stdV = sqrt( ( sum(Vwids**2)-size(Vwids) )/12. ) \nstdV = 0.5/f0/dt ! spacing, half period\nNpk = NINT((Nt1-2*M2)/(stdV)) + 1\n\nallocate(upks(Npk), W0(L), W1(L))\n\ndo i = 1,Npk\n upks(i) = Nt1+ 1+M2 + NINT( (i-1)*(1.5 *stdV) )\nend do\n\nWsig2 = (L2*2)**2 ! var for W weight profile over Xcorr shifts\nW0 = exp( (/ (i, i= -L2, L2) /)**2 /(-2.*Wsig2) )\n\n! write(*,*) 'M, Vwids', M, Vwids; call flush(6)\n! call write_binfile('V.bin', V) !!!!!!!!!!!!!\n\nalph = 8.\nNpkmx = nt1/2 ! # local maxima\n\nallocate(pk(Nt), pktmp(Nt), itmp(Npkmx), &\n gchnk(M), dnrm(Nt), &\n dtmp(Nt), Vtmp(M), tmpD1(Nt), tmpD2(Nt), &\n unrm(Npk), dtprd(L,Npk), &\n fdtp(L,Npk), gdtp(L,Npk), &\n simi(Nt,Npk),simF(Nt,Npk) )\n\nmisF = 0.\nAdjS = 0.\ndo ig = 1, ng\n call corr_focusing1D(J, AdjS(:,ig), datP(:,ig),upks,V,Vwids, datO(:,ig), &\n W0, W1, Wsig2, alph, lag12, &\n unrm,gchnk, dtprd,fdtp, gdtp, simi,simF,dnrm,dtmp, &\n itmp,pk,pktmp,Vtmp, tmpD1,tmpD2)\n misF = misF -J\nend do\nAdjs1 = AdjS(nt1+1: 2*nt1,:)\n\ndeallocate(pk, pktmp, itmp, &\n gchnk, W0,W1, dnrm, &\n dtmp, V,Vtmp,tmpD1, tmpD2, &\n upks, &\n unrm, dtprd, &\n fdtp, gdtp, &\n simi, simF )\n\ndeallocate(datP, datO, Adjs)\n\nend subroutine\n!-------------\n\nEND MODULE\n\n", "meta": {"hexsha": "83d9857549345451aa221d53144ead8bf1ac37e9", "size": 17764, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "SeisElastic2D/SRC/corr_focus_mod.f90", "max_stars_repo_name": "PanIGGCAS/SeisElastic2D_1.1", "max_stars_repo_head_hexsha": "2872dc514b638237771f4071195f7b8f90e0ce3d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2020-10-04T01:55:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-14T05:20:50.000Z", "max_issues_repo_path": "SeisElastic2D/SRC/corr_focus_mod.f90", "max_issues_repo_name": "PanIGGCAS/SeisElastic2D_1.1", "max_issues_repo_head_hexsha": "2872dc514b638237771f4071195f7b8f90e0ce3d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-10-31T03:36:34.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-27T09:36:13.000Z", "max_forks_repo_path": "SeisElastic2D/SRC/corr_focus_mod.f90", "max_forks_repo_name": "PanIGGCAS/SeisElastic2D_1.1", "max_forks_repo_head_hexsha": "2872dc514b638237771f4071195f7b8f90e0ce3d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-12-15T02:04:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-15T21:48:35.000Z", "avg_line_length": 27.0792682927, "max_line_length": 105, "alphanum_fraction": 0.5481873452, "num_tokens": 7200, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951104066293, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.667124670553533}} {"text": "submodule(euler_interface_m) euler_prob_0020_m\n implicit none\n\ncontains\n\n module character(len=20) function euler0020()\n write (euler0020, \"(i20)\") ans(100)\n end function euler0020\n\n integer function ans(n)\n integer, intent(in) :: n\n integer, allocatable :: iarr(:)\n integer :: l, i, j\n real(sp) :: lr\n\n lr = 0._sp\n do i = 1, n\n lr = lr + log10(real(i, sp))\n end do\n l = floor(lr + 1.)\n\n allocate (iarr(l))\n iarr = 0\n iarr(l) = 1\n\n do i = 1, n\n iarr = iarr*i\n\n do j = l, 2, -1\n iarr(j - 1) = iarr(j - 1) + iarr(j)/10\n iarr(j) = mod(iarr(j), 10)\n end do\n end do\n ans = sum(iarr, dim=1)\n end function ans\n\nend submodule euler_prob_0020_m\n", "meta": {"hexsha": "8058549d8414df83efc9a525969c31245c0d6edc", "size": 830, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/euler/prob_0020_m.f90", "max_stars_repo_name": "han190/PE-Fortran", "max_stars_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-02-09T07:07:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-31T07:45:48.000Z", "max_issues_repo_path": "docs/src/prob_0020_m.f90", "max_issues_repo_name": "han190/PE-Fortran", "max_issues_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-14T00:48:58.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-14T00:48:58.000Z", "max_forks_repo_path": "docs/src/prob_0020_m.f90", "max_forks_repo_name": "han190/PE-Fortran", "max_forks_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-04T21:29:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T21:29:45.000Z", "avg_line_length": 21.8421052632, "max_line_length": 54, "alphanum_fraction": 0.486746988, "num_tokens": 260, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950868503682, "lm_q2_score": 0.7905303260722198, "lm_q1q2_score": 0.6671246581785658}} {"text": "! .................................................................................................\n! + t *\n! LL = 1 + Z Z\n!\n! the Cholesky decomposition or Cholesky factorization is a decomposition of a Hermitian, \n! positive-definite matrix into the product of a lower triangular matrix and its conjugate transpose\n! .................................................................................................\n\tSUBROUTINE Lmatrix(Z,GLOB_LOC,NDIM)\n\tUSE VAPHFB_PAR\n\timplicit real*8 (a-h,o-z)\n\t\n\tDIMENSION Z(NDIM,NDIM)\t\n\tDIMENSION GLOB_LOC(NDIM,NDIM)\n\tDIMENSION AUX1(NDIM,NDIM)\n\tDIMENSION AUX2(NDIM,NDIM)\n\tDIMENSION AUX3(NDIM+1,NDIM)\n\t\n\n\tcall DGEMM ('t','n',NDIM,NDIM,NDIM,one, &\n &\tZ,NDIM,Z,NDIM,zero,AUX1,NDIM)\n\n \n \tdo ii=1,NDIM\n\t do jj=ii,NDIM\n\t if (ii.ne.jj) then\n\t AUX2(ii,jj)=AUX1(ii,jj)\n\t AUX2(jj,ii)=AUX2(ii,jj)\n\t else if (ii.eq.jj) then\n\t AUX2(ii,jj)=AUX1(ii,jj)+1.d0\n\t AUX2(jj,ii)=AUX2(ii,jj)\n\t end if\n\t end do\n\tend do\n \n\tcall cholesky_format1(AUX2,AUX3,NDIM) \n\t\n\tcall DPBTRF( 'L', NDIM, NDIM,AUX3,NDIM+1, INFO )\n\tif (info.ne.0) then \n\t print*,'Cholesky fails.'\n\t print*,'Try another seed or lower eta1,eta2'\n\t stop\n\tend if\n\t\n\tcall cholesky_format2(AUX3,GLOB_LOC,NDIM)\n1000\tformat(1000F10.4)\n\tEND SUBROUTINE Lmatrix\n\n\n\tSUBROUTINE cholesky_format1(A,AB,NDIM)\n\t\n\timplicit real*8 (a-h,o-z)\n\tDIMENSION A(NDIM,NDIM)\n\tDIMENSION AB(NDIM+1,NDIM)\n\n do ii=1,NDIM\n\t do jj=1,NDIM\n\t kk=1+ii-jj\n\t if(jj.le.ii) then\n\t AB(kk,jj)=A(ii,jj)\n\t end if\n\t end do\n end do\n\n\n\tEND SUBROUTINE\n\n\tSUBROUTINE cholesky_format2(AB,A,NDIM)\n\t\n\timplicit real*8 (a-h,o-z)\n\t\n\tPARAMETER (one=1.d0)\n\tPARAMETER (zero=0.d0)\n\tDIMENSION A(NDIM,NDIM)\n\tDIMENSION AB(NDIM+1,NDIM)\n\n\t\n\t do ii=1,NDIM\n\t do jj=1,NDIM\n\t A(jj,ii)=zero\n\t end do\n\t end do\n\t\n do ii=1,NDIM\n\t do jj=1,NDIM+1-ii\n \n\t ll = (ii-1)+jj\n\t mm = jj\n \n\t A(ll,mm)=AB(ii,jj)\n \n\t end do\n \n end do\n\n\n\t \n\t\n\tEND SUBROUTINE\n\t\n\n\n\tSUBROUTINE Lmatrix_VAP(Z,GLOB_LOC,NDIM)\n USE VAPHFB_PAR\n\timplicit real*8 (a-h,o-z)\n\t\n\tCOMPLEX*16 IM,Izero,Ione\n\tPARAMETER (IM=(0.d0,1.d0))\n\tPARAMETER (Izero=(0.d0,0.d0))\n\tPARAMETER (Ione=(1.d0,0.d0))\n\t\n\tCOMPLEX*16 Z(NDIM,NDIM)\t\n\tCOMPLEX*16 GLOB_LOC(NDIM,NDIM)\n\tCOMPLEX*16 AUX1(NDIM,NDIM)\n\tCOMPLEX*16 AUX2(NDIM,NDIM)\n\tCOMPLEX*16 AUX3(NDIM+1,NDIM)\n\t\n\n\tcall ZGEMM ('c','n',NDIM,NDIM,NDIM,Ione, &\n &\tZ,NDIM,Z,NDIM,Izero,AUX1,NDIM)\n\n \n \tdo ii=1,NDIM\n\t do jj=1,NDIM\n\t if (ii.ne.jj) then\n\t AUX2(jj,ii)=dreal(AUX1(jj,ii))-IM*dimag(AUX1(jj,ii))\n\t else if (ii.eq.jj) then\n\t AUX2(jj,ii)=dreal(AUX1(jj,ii))-IM*dimag(AUX1(jj,ii))+ one\n\t end if\n\t end do\n\tend do\n\tcall cholesky_format1_VAP(AUX2,AUX3,NDIM) \n\t\n\tcall ZPBTRF( 'L', NDIM, NDIM,AUX3,NDIM+1, INFO )\n\tif (info.ne.0) then \n\t print*,'Cholesky fails.'\n\t print*,'Try another seed or lower eta1,eta2'\n\t stop\n\tend if\n\t\n\tcall cholesky_format2_VAP(AUX3,GLOB_LOC,NDIM)\n1000\tformat(1000F10.4)\n\tEND SUBROUTINE \n\n\n\t\n\tSUBROUTINE cholesky_format1_VAP(A,AB,NDIM)\n\t\n\timplicit real*8 (a-h,o-z)\n\tCOMPLEX*16 A(NDIM,NDIM)\n\tCOMPLEX*16 AB(NDIM+1,NDIM)\n\n do ii=1,NDIM\n\t do jj=1,NDIM\n\t kk=1+ii-jj\n\t if(jj.le.ii) then\n\t AB(kk,jj)=A(ii,jj)\n\t end if\n\t end do\n end do\n\n\n\tEND SUBROUTINE\n\n\tSUBROUTINE cholesky_format2_VAP(AB,A,NDIM)\n\t\n\timplicit real*8 (a-h,o-z)\n\tCOMPLEX*16 Izero\n\tPARAMETER (Izero=(0.d0,0.d0))\n\tCOMPLEX*16 A(NDIM,NDIM)\n\tCOMPLEX*16 AB(NDIM+1,NDIM)\n\n\t\n\t do ii=1,NDIM\n\t do jj=ii,NDIM\n\t A(ii,jj)=Izero\n\t A(jj,ii)=Izero\n\t end do\n\t end do\n\t\n do ii=1,NDIM\n\t do jj=1,NDIM+1-ii\n \n\t ll = (ii-1)+jj\n\t mm = jj\n \n\t A(ll,mm)=AB(ii,jj)\n \n\t end do\n \n end do\n\n\tEND SUBROUTINE\n", "meta": {"hexsha": "597f8304e9fe2800719b4c623a726dc2e1d1690a", "size": 3703, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Codes/HFB/MATH_Cholesky.f90", "max_stars_repo_name": "jmyao17/SCCM", "max_stars_repo_head_hexsha": "16e31afa313bf70741c152d859aa837935110776", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Codes/HFB/MATH_Cholesky.f90", "max_issues_repo_name": "jmyao17/SCCM", "max_issues_repo_head_hexsha": "16e31afa313bf70741c152d859aa837935110776", "max_issues_repo_licenses": ["MIT"], "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/HFB/MATH_Cholesky.f90", "max_forks_repo_name": "jmyao17/SCCM", "max_forks_repo_head_hexsha": "16e31afa313bf70741c152d859aa837935110776", "max_forks_repo_licenses": ["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.1865284974, "max_line_length": 100, "alphanum_fraction": 0.5838509317, "num_tokens": 1472, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361700013356, "lm_q2_score": 0.7310585903489892, "lm_q1q2_score": 0.6670443002246071}} {"text": "*dk volume_hex\n subroutine volume_hex(x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4,\n * x5,y5,z5,x6,y6,z6,x7,y7,z7,x8,y8,z8,\n * volhex)\nC\nC\nC#######################################################################\nC\nC PURPOSE -\nC\nC THIS ROUTINE FINDS THE VOLUME OF A HEX-ELEMENT DEFINDED BY\nC 8 COORDINATE NODES. THE VOLUME OF THE HEX IS DETERMINED\nC BY SUBDIVIDING IT INTO 24 TETRAHEDRAL ELEMENTS AND THEN\nC SUMMING THE VOLUME OF THE TETRAHEDRA.\nC\nC THIS VERSION USES THE MIDPOINTS\nC see volume_hex_alt_lg below for version using \"min-area-points\"\nC\nC\nC ******************************************************************\nC\nC DEFINE THE STRUCTURE OF A GENERIC HEXRAHEDRON.\nC\nC \nC 8$ * * * * * * $7 Face 1: 1 2 3 4 (bottom)\nC * * - * 2: 5 8 7 6 (top)\nC * * - * 3: 1 5 6 2 (front)\nC * * - * 4: 2 6 7 3 (back)\nC * * - * 5: 3 7 8 4 (right)\nC * 5$ * * * * * * $6 6: 1 4 8 5 (left)\nC * * - * \nC 4$ - - - - - - $3 * Edge 1: 1 2\nC * * - * 2 3 \nC * * - * 3 4\nC * * - * 4 1\nC * * - * 5 6\nC 1$ * * * * * * $2 6 7 \nC 7 8 \nC 8 5\nC 1 5\nC 2 6\nC 3 7 \nC 4 8\nC\nC ******************************************************************\nC\nC INPUT ARGUMENTS -\nC\nC (x1,y1,z1),...,(x8,y8,z8) - THE COORDINATES OF THE HEX WHERE\nC 1,2,3,4 FORM THE BOTTOM FACE AND \nC 5,6,7,8 FORM THE TOP FACE.\nC\nC OUTPUT ARGUMENTS -\nC\nC volhex - THE VOLUME OF THE HEX.\nC\nC CHANGE HISTORY -\nC\nC $Log: volume_hex.f,v $\nC Revision 2.00 2007/11/09 20:04:05 spchu\nC Import to CVS\nC\nCPVCS \nCPVCS Rev 1.5 Tue Oct 19 13:18:02 1999 jtg\nCPVCS alternate way of calculating volume using \"minimum area\nCPVCS point\" (instead of midpoint) for each faces added.\nCPVCS \nCPVCS Rev 1.4 Mon Apr 14 17:05:36 1997 pvcs\nCPVCS No change.\nCPVCS \nCPVCS Rev 1.3 Thu Nov 21 19:07:46 1996 het\nCPVCS Correct an error in the calculation of the first tet of the hex.\nCPVCS \nCPVCS Rev 1.2 Mon Nov 11 20:56:14 1996 het\nCPVCS Remove the absolute value for volume.\nCPVCS \nCPVCS Rev 1.1 08/15/95 18:29:36 het\nCPVCS Modify some comment lines\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 x1432=0.25d+00*(x1+x4+x3+x2)\n y1432=0.25d+00*(y1+y4+y3+y2)\n z1432=0.25d+00*(z1+z4+z3+z2)\n x5678=0.25d+00*(x5+x6+x7+x8)\n y5678=0.25d+00*(y5+y6+y7+y8)\n z5678=0.25d+00*(z5+z6+z7+z8)\n x2376=0.25d+00*(x2+x3+x7+x6)\n y2376=0.25d+00*(y2+y3+y7+y6)\n z2376=0.25d+00*(z2+z3+z7+z6)\n x1584=0.25d+00*(x1+x5+x8+x4)\n y1584=0.25d+00*(y1+y5+y8+y4)\n z1584=0.25d+00*(z1+z5+z8+z4)\n x1265=0.25d+00*(x1+x2+x6+x5)\n y1265=0.25d+00*(y1+y2+y6+y5)\n z1265=0.25d+00*(z1+z2+z6+z5)\n x4873=0.25d+00*(x4+x8+x7+x3)\n y4873=0.25d+00*(y4+y8+y7+y3)\n z4873=0.25d+00*(z4+z8+z7+z3)\n x12345678=(x1+x2+x3+x4+x5+x6+x7+x8)/8.0d+00\n y12345678=(y1+y2+y3+y4+y5+y6+y7+y8)/8.0d+00\n z12345678=(z1+z2+z3+z4+z5+z6+z7+z8)/8.0d+00\nC\nC\nC ..................................................................\nC FIND THE VOLUME OF THE 24-TET HEX.\nC\n call volume_tet(x1432,y1432,z1432,\n * x12345678,y12345678,z12345678,\n * x1,y1,z1,\n * x4,y4,z4,\n * voltet11)\n call volume_tet(x1432,y1432,z1432,\n * x12345678,y12345678,z12345678,\n * x4,y4,z4,\n * x3,y3,z3,\n * voltet12)\n call volume_tet(x1432,y1432,z1432,\n * x12345678,y12345678,z12345678,\n * x3,y3,z3,\n * x2,y2,z2,\n * voltet13)\n call volume_tet(x1432,y1432,z1432,\n * x12345678,y12345678,z12345678,\n * x2,y2,z2,\n * x1,y1,z1,\n * voltet14)\n call volume_tet(x5678,y5678,z5678,\n * x12345678,y12345678,z12345678,\n * x5,y5,z5,\n * x6,y6,z6,\n * voltet21)\n call volume_tet(x5678,y5678,z5678,\n * x12345678,y12345678,z12345678,\n * x6,y6,z6,\n * x7,y7,z7,\n * voltet22)\n call volume_tet(x5678,y5678,z5678,\n * x12345678,y12345678,z12345678,\n * x7,y7,z7,\n * x8,y8,z8,\n * voltet23)\n call volume_tet(x5678,y5678,z5678,\n * x12345678,y12345678,z12345678,\n * x8,y8,z8,\n * x5,y5,z5,\n * voltet24)\n call volume_tet(x2376,y2376,z2376,\n * x12345678,y12345678,z12345678,\n * x2,y2,z2,\n * x3,y3,z3,\n * voltet31)\n call volume_tet(x2376,y2376,z2376,\n * x12345678,y12345678,z12345678,\n * x3,y3,z3,\n * x7,y7,z7,\n * voltet32)\n call volume_tet(x2376,y2376,z2376,\n * x12345678,y12345678,z12345678,\n * x7,y7,z7,\n * x6,y6,z6,\n * voltet33)\n call volume_tet(x2376,y2376,z2376,\n * x12345678,y12345678,z12345678,\n * x6,y6,z6,\n * x2,y2,z2,\n * voltet34)\n call volume_tet(x1584,y1584,z1584,\n * x12345678,y12345678,z12345678,\n * x1,y1,z1,\n * x5,y5,z5,\n * voltet41)\n call volume_tet(x1584,y1584,z1584,\n * x12345678,y12345678,z12345678,\n * x5,y5,z5,\n * x8,y8,z8,\n * voltet42)\n call volume_tet(x1584,y1584,z1584,\n * x12345678,y12345678,z12345678,\n * x8,y8,z8,\n * x4,y4,z4,\n * voltet43)\n call volume_tet(x1584,y1584,z1584,\n * x12345678,y12345678,z12345678,\n * x4,y4,z4,\n * x1,y1,z1,\n * voltet44)\n call volume_tet(x1265,y1265,z1265,\n * x12345678,y12345678,z12345678,\n * x1,y1,z1,\n * x2,y2,z2,\n * voltet51)\n call volume_tet(x1265,y1265,z1265,\n * x12345678,y12345678,z12345678,\n * x2,y2,z2,\n * x6,y6,z6,\n * voltet52)\n call volume_tet(x1265,y1265,z1265,\n * x12345678,y12345678,z12345678,\n * x6,y6,z6,\n * x5,y5,z5,\n * voltet53)\n call volume_tet(x1265,y1265,z1265,\n * x12345678,y12345678,z12345678,\n * x5,y5,z5,\n * x1,y1,z1,\n * voltet54)\n call volume_tet(x4873,y4873,z4873,\n * x12345678,y12345678,z12345678,\n * x4,y4,z4,\n * x8,y8,z8,\n * voltet61)\n call volume_tet(x4873,y4873,z4873,\n * x12345678,y12345678,z12345678,\n * x8,y8,z8,\n * x7,y7,z7,\n * voltet62)\n call volume_tet(x4873,y4873,z4873,\n * x12345678,y12345678,z12345678,\n * x7,y7,z7,\n * x3,y3,z3,\n * voltet63)\n call volume_tet(x4873,y4873,z4873,\n * x12345678,y12345678,z12345678,\n * x3,y3,z3,\n * x4,y4,z4,\n * voltet64)\nC\nC\nC ..................................................................\nC SUM THE 24 TET VOLUMES TO THE VOLUME OF THE HEX.\nC\n volhex=-voltet11-voltet12-voltet13-voltet14-\n * voltet21-voltet22-voltet23-voltet24-\n * voltet31-voltet32-voltet33-voltet34-\n * voltet41-voltet42-voltet43-voltet44-\n * voltet51-voltet52-voltet53-voltet54-\n * voltet61-voltet62-voltet63-voltet64\nC\n return\n end\nC#######################################################################\nC=======================================================================\nC#######################################################################\n*dk volume_hex\n subroutine volume_hex_alt_lg(x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4,\n * x5,y5,z5,x6,y6,z6,x7,y7,z7,x8,y8,z8,\n * volhex)\nC\nC\nC#######################################################################\nC\nC PURPOSE -\nC\nC THIS ROUTINE FINDS THE VOLUME OF A HEX-ELEMENT DEFINDED BY\nC 8 COORDINATE NODES. THE VOLUME OF THE HEX IS DETERMINED\nC BY SUBDIVIDING IT INTO 24 TETRAHEDRAL ELEMENTS AND THEN\nC SUMMING THE VOLUME OF THE TETRAHEDRA.\nC\nC THIS VERSION USES THE AREA-MINMIZING POINTS OF THE QUD FACES\nC see volume_hex above for version using midpoints, and conventions\nC\nC\nC#######################################################################\nC\n implicit real*8 (a-h,o-z)\nC\nC#######################################################################\nC\nC\nC ..................................................................\nC FIND THE AREA_MINIMIZING POINT FOR EACH OF THE SIX FACES AND THE HEX.\nC\n call volume_qud_alt_lg(x1,y1,z1, x4,y4,z4, x3,y3,z3, x2,y2,z2,\n * vvv, x1432,y1432,z1432 )\n call volume_qud_alt_lg(x5,y5,z5, x6,y6,z6, x7,y7,z7, x8,y8,z8,\n * vvv, x5678,y5678,z5678 )\n call volume_qud_alt_lg(x2,y2,z2, x3,y3,z3, x7,y7,z7, x6,y6,z6,\n * vvv, x2376,y2376,z2376 )\n call volume_qud_alt_lg(x1,y1,z1, x5,y5,z5, x8,y8,z8, x4,y4,z4,\n * vvv, x1584,y1584,z1584 )\n call volume_qud_alt_lg(x1,y1,z1, x2,y2,z2, x6,y6,z6, x5,y5,z5,\n * vvv, x1265,y1265,z1265 )\n call volume_qud_alt_lg(x4,y4,z4, x8,y8,z8, x7,y7,z7, x3,y3,z3,\n * vvv, x4873,y4873,z4873 )\n\n ! OK to use midpoint for center, as +/- contributions should cancel...\n x12345678=(x1432+x5678+x2376+x1584+x1265+x4873)/6.0d+00\n y12345678=(y1432+y5678+y2376+y1584+y1265+y4873)/6.0d+00\n z12345678=(z1432+z5678+z2376+z1584+z1265+z4873)/6.0d+00\n\n ! if actually need volume-minimizing-point for breaking into tets: \n ! calculate as point which minimizes [ sum_{1=1,24} V(i)^2 ]\n ! where V(i) is the volume of the 24 sub-tets\n ! (similar to min-area-point calculation in volume_qud_alt_lg)\nC\nC ..................................................................\nC FIND THE VOLUME OF THE 24-TET HEX (same as above).\nC\n call volume_tet(x1432,y1432,z1432,\n * x12345678,y12345678,z12345678,\n * x1,y1,z1,\n * x4,y4,z4,\n * voltet11)\n call volume_tet(x1432,y1432,z1432,\n * x12345678,y12345678,z12345678,\n * x4,y4,z4,\n * x3,y3,z3,\n * voltet12)\n call volume_tet(x1432,y1432,z1432,\n * x12345678,y12345678,z12345678,\n * x3,y3,z3,\n * x2,y2,z2,\n * voltet13)\n call volume_tet(x1432,y1432,z1432,\n * x12345678,y12345678,z12345678,\n * x2,y2,z2,\n * x1,y1,z1,\n * voltet14)\n call volume_tet(x5678,y5678,z5678,\n * x12345678,y12345678,z12345678,\n * x5,y5,z5,\n * x6,y6,z6,\n * voltet21)\n call volume_tet(x5678,y5678,z5678,\n * x12345678,y12345678,z12345678,\n * x6,y6,z6,\n * x7,y7,z7,\n * voltet22)\n call volume_tet(x5678,y5678,z5678,\n * x12345678,y12345678,z12345678,\n * x7,y7,z7,\n * x8,y8,z8,\n * voltet23)\n call volume_tet(x5678,y5678,z5678,\n * x12345678,y12345678,z12345678,\n * x8,y8,z8,\n * x5,y5,z5,\n * voltet24)\n call volume_tet(x2376,y2376,z2376,\n * x12345678,y12345678,z12345678,\n * x2,y2,z2,\n * x3,y3,z3,\n * voltet31)\n call volume_tet(x2376,y2376,z2376,\n * x12345678,y12345678,z12345678,\n * x3,y3,z3,\n * x7,y7,z7,\n * voltet32)\n call volume_tet(x2376,y2376,z2376,\n * x12345678,y12345678,z12345678,\n * x7,y7,z7,\n * x6,y6,z6,\n * voltet33)\n call volume_tet(x2376,y2376,z2376,\n * x12345678,y12345678,z12345678,\n * x6,y6,z6,\n * x2,y2,z2,\n * voltet34)\n call volume_tet(x1584,y1584,z1584,\n * x12345678,y12345678,z12345678,\n * x1,y1,z1,\n * x5,y5,z5,\n * voltet41)\n call volume_tet(x1584,y1584,z1584,\n * x12345678,y12345678,z12345678,\n * x5,y5,z5,\n * x8,y8,z8,\n * voltet42)\n call volume_tet(x1584,y1584,z1584,\n * x12345678,y12345678,z12345678,\n * x8,y8,z8,\n * x4,y4,z4,\n * voltet43)\n call volume_tet(x1584,y1584,z1584,\n * x12345678,y12345678,z12345678,\n * x4,y4,z4,\n * x1,y1,z1,\n * voltet44)\n call volume_tet(x1265,y1265,z1265,\n * x12345678,y12345678,z12345678,\n * x1,y1,z1,\n * x2,y2,z2,\n * voltet51)\n call volume_tet(x1265,y1265,z1265,\n * x12345678,y12345678,z12345678,\n * x2,y2,z2,\n * x6,y6,z6,\n * voltet52)\n call volume_tet(x1265,y1265,z1265,\n * x12345678,y12345678,z12345678,\n * x6,y6,z6,\n * x5,y5,z5,\n * voltet53)\n call volume_tet(x1265,y1265,z1265,\n * x12345678,y12345678,z12345678,\n * x5,y5,z5,\n * x1,y1,z1,\n * voltet54)\n call volume_tet(x4873,y4873,z4873,\n * x12345678,y12345678,z12345678,\n * x4,y4,z4,\n * x8,y8,z8,\n * voltet61)\n call volume_tet(x4873,y4873,z4873,\n * x12345678,y12345678,z12345678,\n * x8,y8,z8,\n * x7,y7,z7,\n * voltet62)\n call volume_tet(x4873,y4873,z4873,\n * x12345678,y12345678,z12345678,\n * x7,y7,z7,\n * x3,y3,z3,\n * voltet63)\n call volume_tet(x4873,y4873,z4873,\n * x12345678,y12345678,z12345678,\n * x3,y3,z3,\n * x4,y4,z4,\n * voltet64)\nC\nC\nC ..................................................................\nC SUM THE 24 TET VOLUMES TO THE VOLUME OF THE HEX.\nC\n volhex=-voltet11-voltet12-voltet13-voltet14-\n * voltet21-voltet22-voltet23-voltet24-\n * voltet31-voltet32-voltet33-voltet34-\n * voltet41-voltet42-voltet43-voltet44-\n * voltet51-voltet52-voltet53-voltet54-\n * voltet61-voltet62-voltet63-voltet64\nC\n return\n end\n", "meta": {"hexsha": "8eb568fec2bdcf1b96355ba58126e0f8c22e4d06", "size": 16167, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/volume_hex.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_hex.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_hex.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": 36.4943566591, "max_line_length": 78, "alphanum_fraction": 0.4383620956, "num_tokens": 5338, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.912436167620237, "lm_q2_score": 0.731058584489497, "lm_q1q2_score": 0.6670442931374719}} {"text": "module WGFM_SauterSchwabData\nuse tools\nimplicit none\n\nprivate\npublic:: SSDataType, init_ssdata, get_ss_identical_params, &\n get_ss_edge_params, get_ss_vertex_params\n\n! Constants\ninteger,parameter:: NINTEGRALS_IDENTICAL = 6 ! number of integrals, identical case\ninteger,parameter:: NINTEGRALS_EDGE = 5 ! number of integrals, edge case\ninteger,parameter:: NINTEGRALS_VERTEX = 2 ! number of integrals, vertex case\n\ntype SSDataArrays\n ! qweights for each qpoint [n1, n2, n3, i] (jacobian included) \n real(8),allocatable:: qweights(:,:,:,:) ! qweight = qweights(i, n3, n2, n1)\n ! variables [uO, vO, uI, vI] for each qpoint `[n1, n2, n3, i]` and integral `l`\n real(8),allocatable:: variables(:,:,:,:,:,:) ! [uO, vO, uI, vI] = variables(:, l, i, n3, n2, n1)\nend type \n\n! Data structure that contains the Sauter-Schwab quadrature data.\n! The quadrature points are indexed by 4 integers `[n1, n2, n3, i]`\n! with each integer belonging to {1,2,...,nQ}. They individually\n! represent qpoints in the hypercube coordinates (eta1, eta2, eta3, xi) \\in [0,1]^4.\n! For each case (identical, common edge, common vertex) there are (6, 5, 2) \n! integrals to compute, respectively. Each integral is indexed by the integer `l`\n! in {1,2,...,lMax}, with `lMax` depending on the case.\ntype SSDataType\n integer:: nQ ! number of quadrature points in 1D\n integer:: n_identical ! number of integrals, identical case (6 integrals)\n integer:: n_edge ! number of integrals, edge case (5 integrals)\n integer:: n_vertex ! number of integrals, vertex case (2 integrals)\n type(SSDataArrays):: identical_data ! quadrature data for the identical case\n type(SSDataArrays):: edge_data ! quadrature data for the edge case\n type(SSDataArrays):: vertex_data ! quadrature data for the vertex case\nend type \n\ncontains\n! ********************* Public procedures ************************************************************\n! Initializes `ssdata` by generating the quadrature points and weights.\nsubroutine init_ssdata(ssdata, nQ)\n type(SSDataType),intent(out):: ssdata\n integer,intent(in):: nQ ! number of quadrature points in 1D\n real(8):: t(nQ), w(nQ) ! hold 1D gaussian quadrature points and weights\n real(8):: eta1, eta2, eta3, xi ! hypercube variables\n real(8):: gauss_qweight ! holds the tensor gauss quadrature weight\n integer:: n1, n2, n3, i ! loop indices\n \n ! save number of quad. points and number of integrals\n ssdata%nQ = nQ \n ssdata%n_identical = NINTEGRALS_IDENTICAL\n ssdata%n_edge = NINTEGRALS_EDGE\n ssdata%n_vertex = NINTEGRALS_VERTEX\n ! obtain quadrature data and scale to the interval [0, 1]\n call gaussQuadrature(t,w,nQ)\n w = 0.5d0*w\n t = 0.5d0*(1.0d0+t)\n ! allocate data\n call allocate_ssdata(ssdata)\n ! compute qnodes and qweights\n do n1 = 1,nQ ! eta1\n eta1 = t(n1)\n do n2 = 1,nQ !eta2\n eta2 = t(n2)\n do n3 = 1,nQ !eta3\n eta3 = t(n3)\n do i = 1,nQ ! xi\n xi = t(i)\n ! tensor gauss quadrature weight\n gauss_qweight = w(n1)*w(n2)*w(n3)*w(i) \n ! identical data\n call store_ssdata_identical(ssdata%identical_data, gauss_qweight, eta1, eta2, eta3, xi, n1, n2, n3, i)\n ! edge data\n call store_ssdata_edge(ssdata%edge_data, gauss_qweight, eta1, eta2, eta3, xi, n1, n2, n3, i)\n ! vertex data\n call store_ssdata_vertex(ssdata%vertex_data, gauss_qweight, eta1, eta2, eta3, xi, n1, n2, n3, i)\n end do\n end do\n end do\n end do\nend subroutine init_ssdata\n\n! Gets the parametrization `(x,y)` and the quadrature weight `qweight` (jacobian included)\n! for the qnode `[n1, n2, n3, i]`, integral `l` and the triangle with vertices `[p1, p2, p3]`,\n! for the identical case.\npure subroutine get_ss_identical_params(ssdata, x, y, qweight, n1, n2, n3, i, l, p1, p2, p3)\n type(SSDataType),intent(in):: ssdata\n real(8),intent(out):: x(3), y(3) ! points in triangle\n real(8),intent(out):: qweight ! quadrature weight and jacobian\n integer,intent(in):: n1, n2, n3, i, l ! loop indices\n real(8),intent(in):: p1(3), p2(3), p3(3) ! triangle vertices\n call get_ss_params(ssdata%identical_data, x, y, n1, n2, n3, i, l, p1, p2, p3, p1, p2, p3)\n call get_ss_qweight(ssdata%identical_data, qweight, n1, n2, n3, i)\nend subroutine get_ss_identical_params\n\n! Gets the parametrization `(x,y)` and the quadrature weight `qweight`\n! for the qnode `[n1, n2, n3, i]`, integral `l` and the triangles with vertices `[q1, q2, q3]`\n! and `[p1, p2, p3]`, for the common edge case.\npure subroutine get_ss_edge_params(ssdata, x, y, qweight, n1, n2, n3, i, l, q1, q2, q3, p1, p2, p3)\n type(SSDataType),intent(in):: ssdata\n real(8),intent(out):: x(3), y(3) ! points in triangle\n real(8),intent(out):: qweight ! quadrature weight and jacobian\n integer,intent(in):: n1, n2, n3, i, l ! loop indices\n real(8),intent(in):: q1(3), q2(3), q3(3) ! triangle 1 vertices\n real(8),intent(in):: p1(3), p2(3), p3(3) ! triangle 2 vertices\n call get_ss_params(ssdata%edge_data, x, y, n1, n2, n3, i, l, q1, q2, q3, p1, p2, p3)\n if (l == 1) then\n call get_ss_qweight(ssdata%edge_data, qweight, n1, n2, n3, i) ! for integral 1\n else\n call get_ss_qweight(ssdata%identical_data, qweight, n1, n2, n3, i) ! for integral 2,3,4,5\n end if\nend subroutine get_ss_edge_params\n\n! Gets the parametrization `(x,y)` and the quadrature weight `qweight`\n! for the qnode `[n1, n2, n3, i]`, integral `l` and the triangles with vertices `[q1, q2, q3]`\n! and `[p1, p2, p3]`, for the common vertex case.\npure subroutine get_ss_vertex_params(ssdata, x, y, qweight, n1, n2, n3, i, l, q1, q2, q3, p1, p2, p3)\n type(SSDataType),intent(in):: ssdata\n real(8),intent(out):: x(3), y(3) ! points in triangle\n real(8),intent(out):: qweight ! quadrature weight and jacobian\n integer,intent(in):: n1, n2, n3, i, l ! loop indices\n real(8),intent(in):: q1(3), q2(3), q3(3) ! triangle 1 vertices\n real(8),intent(in):: p1(3), p2(3), p3(3) ! triangle 2 vertices\n call get_ss_params(ssdata%vertex_data, x, y, n1, n2, n3, i, l, q1, q2, q3, p1, p2, p3)\n call get_ss_qweight(ssdata%vertex_data, qweight, n1, n2, n3, i)\nend subroutine get_ss_vertex_params\n\n! ********************* Private procedures ************************************************************\n! Gets the parametrization `(x,y)` for the qnode `[n1, n2, n3, i]`, integral `l` \n! and the triangles with vertices `[q1, q2, q3]` and `[p1, p2, p3]`.\npure subroutine get_ss_params(ssdata_a, x, y, n1, n2, n3, i, l, q1, q2, q3, p1, p2, p3)\n type(SSDataArrays),intent(in):: ssdata_a\n real(8),intent(out):: x(3), y(3) ! points in triangles 1 and 2\n integer,intent(in):: n1, n2, n3, i, l ! loop indices\n real(8),intent(in):: q1(3), q2(3), q3(3) ! triangle 1 vertices\n real(8),intent(in):: p1(3), p2(3), p3(3) ! triangle 2 vertices\n real(8):: uO, vO, uI, vI ! hypercube variables\n ! get hypercube variables\n uO = ssdata_a%variables(1, l, i, n3, n2, n1)\n vO = ssdata_a%variables(2, l, i, n3, n2, n1)\n uI = ssdata_a%variables(3, l, i, n3, n2, n1)\n vI = ssdata_a%variables(4, l, i, n3, n2, n1)\n ! map variables to the triangles\n x = triangle_parametrization(uO, vO, q1, q2, q3)\n y = triangle_parametrization(uI, vI, p1, p2, p3)\nend subroutine get_ss_params\n\n! Gets the the quadrature weight `qweight` for the qnode `[n1, n2, n3, i]`.\npure subroutine get_ss_qweight(ssdata_a, qweight, n1, n2, n3, i)\n type(SSDataArrays),intent(in):: ssdata_a\n real(8),intent(out):: qweight ! quadrature weight and jacobian\n integer,intent(in):: n1, n2, n3, i ! loop indices\n ! get qweight and jacobian\n qweight = ssdata_a%qweights(i, n3, n2, n1)\nend subroutine get_ss_qweight\n\n! Maps (u,v) in the reference triangle to the 3D triangle with vertices\n! `p1`, `p2` and `p3`.\npure function triangle_parametrization(u, v, p1, p2, p3) result(x)\n real(8),intent(in):: u, v ! parameters\n real(8),intent(in):: p1(3), p2(3), p3(3) ! triangle vertices\n real(8):: x(3)\n x = p1 + u*(p2-p1) + v*(p3-p2)\nend function triangle_parametrization\n\n! Allocates the arrays for storing the quadrature data in `ssdata`.\nsubroutine allocate_ssdata(ssdata)\n type(SSDataType),intent(inout):: ssdata\n integer:: nQ ! number of quadrature points in 1D\n\n nQ = ssdata%nQ\n ! allocate identical data\n allocate(ssdata%identical_data%qweights(nQ,nQ,nQ,nQ))\n allocate(ssdata%identical_data%variables(4,NINTEGRALS_IDENTICAL,nQ,nQ,nQ,nQ)) ! 4 variables, 6 integrals\n ! allocate edge data\n allocate(ssdata%edge_data%qweights(nQ,nQ,nQ,nQ)) ! for integral 1; integrals 2,3,4,5,6 use qweights from the identical case\n allocate(ssdata%edge_data%variables(4,NINTEGRALS_EDGE,nQ,nQ,nQ,nQ)) ! 4 variables, 5 integrals\n ! allocate vertex data\n allocate(ssdata%vertex_data%qweights(nQ,nQ,nQ,nQ))\n allocate(ssdata%vertex_data%variables(4,NINTEGRALS_VERTEX,nQ,nQ,nQ,nQ)) ! 4 variables, 2 integrals\n\nend subroutine allocate_ssdata\n\n! Computes the quadrature data for the identical case\nsubroutine store_ssdata_identical(ssdata_i, gauss_qweight, eta1, eta2, eta3, xi, n1, n2, n3, i)\n type(SSDataArrays),intent(inout):: ssdata_i\n real(8),intent(in):: gauss_qweight ! tensor gauss quadrature weight\n real(8),intent(in):: eta1, eta2, eta3, xi ! hypercube variables\n integer,intent(in):: n1, n2, n3, i ! loop indices\n integer::l ! loop index for different integrals\n real(8):: uO, vO, uI, vI ! hypercube variables\n real(8):: qweight ! quad. weigth and jacobian\n\n ! Integral 1\n l = 1 \n uO = xi\n vO = xi*(1.0d0-eta1+eta1*eta2)\n uI = xi*(1.0d0-eta1*eta2*eta3)\n vI = xi*(1.0d0-eta1)\n ssdata_i%variables(:, l, i, n3, n2, n1) = [uO, vO, uI, vI]\n ! Integral 2\n l = 2 \n uO = xi*(1.0d0-eta1*eta2*eta2)\n vO = xi*(1.0d0-eta1)\n uI = xi\n vI = xi*(1.0d0-eta1+eta1*eta2)\n ssdata_i%variables(:, l, i, n3, n2, n1) = [uO, vO, uI, vI]\n ! Integral 3\n l = 3 \n uO = xi\n vO = xi*eta1*(1.0d0-eta2+eta2*eta3)\n uI = xi*(1.0d0-eta1*eta2)\n vI = xi*eta1*(1.0d0-eta2)\n ssdata_i%variables(:, l, i, n3, n2, n1) = [uO, vO, uI, vI]\n ! Integral 4\n l = 4 \n uO = xi*(1.0d0-eta1*eta2)\n vO = xi*eta1*(1.0d0-eta2)\n uI = xi\n vI = xi*eta1*(1.0d0-eta2+eta2*eta3)\n ssdata_i%variables(:, l, i, n3, n2, n1) = [uO, vO, uI, vI]\n ! Integral 5\n l = 5 \n uO = xi*(1.0d0-eta1*eta2*eta3)\n vO = xi*eta1*(1.0d0-eta2*eta3)\n uI = xi\n vI = xi*eta1*(1.0d0-eta2)\n ssdata_i%variables(:, l, i, n3, n2, n1) = [uO, vO, uI, vI]\n ! Integral 6\n l = 6 \n uO = xi\n vO = xi*eta1*(1.0d0-eta2)\n uI = xi*(1.0d0-eta1*eta2*eta3)\n vI = xi*eta1*(1.0d0-eta2*eta3)\n ssdata_i%variables(:, l, i, n3, n2, n1) = [uO, vO, uI, vI]\n ! Quadrature weight and jacobian\n qweight = xi**3*eta1**2*eta2*gauss_qweight\n ssdata_i%qweights(i, n3, n2, n1) = qweight\nend subroutine store_ssdata_identical\n\n! Computes the quadrature data for the common edge case\nsubroutine store_ssdata_edge(ssdata_e, gauss_qweight, eta1, eta2, eta3, xi, n1, n2, n3, i)\n type(SSDataArrays),intent(inout):: ssdata_e\n real(8),intent(in):: gauss_qweight ! tensor gauss quadrature weight\n real(8),intent(in):: eta1, eta2, eta3, xi ! hypercube variables\n integer,intent(in):: n1, n2, n3, i ! loop indices\n integer::l ! loop index for different integrals\n real(8):: uO, vO, uI, vI ! hypercube variables\n real(8):: qweight ! quad. weigth and jacobian\n\n ! Integral 1\n l = 1 \n uO = xi\n vO = xi*eta1*eta3\n uI = xi*(1.0d0-eta1*eta2)\n vI = xi*eta1*(1.0d0-eta2)\n ssdata_e%variables(:, l, i, n3, n2, n1) = [uO, vO, uI, vI]\n ! Integral 2\n l = 2 \n uO = xi\n vO = xi*eta1\n uI = xi*(1.0d0-eta1*eta2*eta3)\n vI = xi*eta1*eta2*(1.0d0-eta3)\n ssdata_e%variables(:, l, i, n3, n2, n1) = [uO, vO, uI, vI]\n ! Integral 3\n l = 3 \n uO = xi*(1.0d0-eta1*eta2)\n vO = xi*eta1*(1.0d0-eta2)\n uI = xi\n vI = xi*eta1*eta2*eta3\n ssdata_e%variables(:, l, i, n3, n2, n1) = [uO, vO, uI, vI]\n ! Integral 4\n l = 4 \n uO = xi*(1.0d0-eta1*eta2*eta3)\n vO = xi*eta1*eta2*(1.0d0-eta3)\n uI = xi\n vI = xi*eta1\n ssdata_e%variables(:, l, i, n3, n2, n1) = [uO, vO, uI, vI]\n ! Integral 5\n l = 5 \n uO = xi*(1.0d0-eta1*eta2*eta3)\n vO = xi*eta1*(1.0d0-eta2*eta3)\n uI = xi\n vI = xi*eta1*eta2\n ssdata_e%variables(:, l, i, n3, n2, n1) = [uO, vO, uI, vI]\n ! Quadrature weight and jacobian for integral 1\n qweight = xi**3*eta1**2*gauss_qweight\n ssdata_e%qweights(i, n3, n2, n1) = qweight\nend subroutine store_ssdata_edge\n\n! Computes the quadrature data for the common vertex case\nsubroutine store_ssdata_vertex(ssdata_v, gauss_qweight, eta1, eta2, eta3, xi, n1, n2, n3, i)\n type(SSDataArrays),intent(inout):: ssdata_v\n real(8),intent(in):: gauss_qweight ! tensor gauss quadrature weight\n real(8),intent(in):: eta1, eta2, eta3, xi ! hypercube variables\n integer,intent(in):: n1, n2, n3, i ! loop indices\n integer::l ! loop index for different integrals\n real(8):: uO, vO, uI, vI ! hypercube variables\n real(8):: qweight ! quad. weigth and jacobian\n\n ! Integral 1\n l = 1 \n uO = xi\n vO = xi*eta1\n uI = xi*eta2\n vI = xi*eta2*eta3\n ssdata_v%variables(:, l, i, n3, n2, n1) = [uO, vO, uI, vI]\n ! Integral 2\n l = 2 \n uO = xi*eta2\n vO = xi*eta2*eta3\n uI = xi\n vI = xi*eta1\n ssdata_v%variables(:, l, i, n3, n2, n1) = [uO, vO, uI, vI]\n ! Quadrature weight and jacobian\n qweight = xi**3*eta2*gauss_qweight\n ssdata_v%qweights(i, n3, n2, n1) = qweight\nend subroutine store_ssdata_vertex\n\nend module WGFM_SauterSchwabData", "meta": {"hexsha": "526e1ac9180e5a27d2492f68612a7c1463a33daa", "size": 14393, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/WGFMethod/WGFM_SauterSchwabData.f90", "max_stars_repo_name": "Riarrieta/WindowedGreenFunctionMethod", "max_stars_repo_head_hexsha": "e6f965cac1acd8d9922e2bf94c33e3577ceb0dc9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/WGFMethod/WGFM_SauterSchwabData.f90", "max_issues_repo_name": "Riarrieta/WindowedGreenFunctionMethod", "max_issues_repo_head_hexsha": "e6f965cac1acd8d9922e2bf94c33e3577ceb0dc9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/WGFMethod/WGFM_SauterSchwabData.f90", "max_forks_repo_name": "Riarrieta/WindowedGreenFunctionMethod", "max_forks_repo_head_hexsha": "e6f965cac1acd8d9922e2bf94c33e3577ceb0dc9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.978125, "max_line_length": 130, "alphanum_fraction": 0.6082818037, "num_tokens": 5180, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361580958427, "lm_q2_score": 0.7310585844894971, "lm_q1q2_score": 0.6670442861745818}} {"text": "c\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc . .\nc . copyright (c) 1998 by UCAR .\nc . .\nc . University Corporation for Atmospheric Research .\nc . .\nc . all rights reserved .\nc . .\nc . .\nc . SPHEREPACK .\nc . .\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc\nc\nc ... file shsgc.f\nc\nc this file contains code and documentation for subroutines\nc shsgc and shsgci\nc\nc ... files which must be loaded with shsgc.f\nc\nc sphcom.f, hrfft.f, gaqd.f\nc\nc subroutine shsgc(nlat,nlon,isym,nt,g,idg,jdg,a,b,mdab,ndab,\nc + wshsgc,lshsgc,work,lwork,ierror)\nc\nc subroutine shsgc performs the spherical harmonic synthesis\nc on the arrays a and b and stores the result in the array g.\nc the synthesis is performed on an equally spaced longitude grid\nc and a gaussian colatitude grid. the associated legendre functions\nc are recomputed rather than stored as they are in subroutine\nc shsgs. the synthesis is described below at output parameter\nc g.\nc\nc input parameters\nc\nc nlat the number of points in the gaussian colatitude grid on the\nc full sphere. these lie in the interval (0,pi) and are compu\nc in radians in theta(1),...,theta(nlat) by subroutine gaqd.\nc if nlat is odd the equator will be included as the grid poi\nc theta((nlat+1)/2). if nlat is even the equator will be\nc excluded as a grid point and will lie half way between\nc theta(nlat/2) and theta(nlat/2+1). nlat must be at least 3.\nc note: on the half sphere, the number of grid points in the\nc colatitudinal direction is nlat/2 if nlat is even or\nc (nlat+1)/2 if nlat is odd.\nc\nc nlon the number of distinct londitude points. nlon determines\nc the grid increment in longitude as 2*pi/nlon. for example\nc nlon = 72 for a five degree grid. nlon must be greater\nc than or equal to 4. the efficiency of the computation is\nc improved when nlon is a product of small prime numbers.\nc\nc isym = 0 no symmetries exist about the equator. the synthesis\nc is performed on the entire sphere. i.e. on the\nc array g(i,j) for i=1,...,nlat and j=1,...,nlon.\nc (see description of g below)\nc\nc = 1 g is antisymmetric about the equator. the synthesis\nc is performed on the northern hemisphere only. i.e.\nc if nlat is odd the synthesis is performed on the\nc array g(i,j) for i=1,...,(nlat+1)/2 and j=1,...,nlon.\nc if nlat is even the synthesis is performed on the\nc array g(i,j) for i=1,...,nlat/2 and j=1,...,nlon.\nc\nc\nc = 2 g is symmetric about the equator. the synthesis is\nc performed on the northern hemisphere only. i.e.\nc if nlat is odd the synthesis is performed on the\nc array g(i,j) for i=1,...,(nlat+1)/2 and j=1,...,nlon.\nc if nlat is even the synthesis is performed on the\nc array g(i,j) for i=1,...,nlat/2 and j=1,...,nlon.\nc\nc nt the number of syntheses. in the program that calls shsgc,\nc the arrays g,a and b can be three dimensional in which\nc case multiple synthesis will be performed. the third\nc index is the synthesis index which assumes the values\nc k=1,...,nt. for a single synthesis set nt=1. the\nc discription of the remaining parameters is simplified\nc by assuming that nt=1 or that the arrays g,a and b\nc have only two dimensions.\nc\nc idg the first dimension of the array g as it appears in the\nc program that calls shsgc. if isym equals zero then idg\nc must be at least nlat. if isym is nonzero then idg must\nc be at least nlat/2 if nlat is even or at least (nlat+1)/2\nc if nlat is odd.\nc\nc jdg the second dimension of the array g as it appears in the\nc program that calls shsgc. jdg must be at least nlon.\nc\nc mdab the first dimension of the arrays a and b as it appears\nc in the program that calls shsgc. mdab must be at least\nc min0((nlon+2)/2,nlat) if nlon is even or at least\nc min0((nlon+1)/2,nlat) if nlon is odd\nc\nc ndab the second dimension of the arrays a and b as it appears\nc in the program that calls shsgc. ndab must be at least nlat\nc\nc a,b two or three dimensional arrays (see the input parameter\nc nt) that contain the coefficients in the spherical harmonic\nc expansion of g(i,j) given below at the definition of the\nc output parameter g. a(m,n) and b(m,n) are defined for\nc indices m=1,...,mmax and n=m,...,nlat where mmax is the\nc maximum (plus one) longitudinal wave number given by\nc mmax = min0(nlat,(nlon+2)/2) if nlon is even or\nc mmax = min0(nlat,(nlon+1)/2) if nlon is odd.\nc\nc wshsgc an array which must be initialized by subroutine shsgci.\nc once initialized, wshsgc can be used repeatedly by shsgc\nc as long as nlat and nlon remain unchanged. wshsgc must\nc not be altered between calls of shsgc.\nc\nc lshsgc the dimension of the array wshsgc as it appears in the\nc program that calls shsgc. define\nc\nc l1 = min0(nlat,(nlon+2)/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc and\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc then lshsgc must be at least\nc\nc nlat*(2*l2+3*l1-2)+3*l1*(1-l1)/2+nlon+15\nc\nc work a work array that does not have to be saved.\nc\nc lwork the dimension of the array work as it appears in the\nc program that calls shsgc. define\nc\nc l1 = min0(nlat,(nlon+2)/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc and\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc if isym is zero then lwork must be at least\nc\nc nlat*(nlon*nt+max0(3*l2,nlon))\nc\nc if isym is not zero then lwork must be at least\nc\nc l2*(nlon*nt+max0(3*nlat,nlon))\nc\nc **************************************************************\nc\nc output parameters\nc\nc g a two or three dimensional array (see input parameter nt)\nc that contains the discrete function which is synthesized.\nc g(i,j) contains the value of the function at the gaussian\nc colatitude point theta(i) and longitude point\nc phi(j) = (j-1)*2*pi/nlon. the index ranges are defined\nc above at the input parameter isym. for isym=0, g(i,j)\nc is given by the the equations listed below. symmetric\nc versions are used when isym is greater than zero.\nc\nc the normalized associated legendre functions are given by\nc\nc pbar(m,n,theta) = sqrt((2*n+1)*factorial(n-m)/(2*factorial(n+m)))\nc *sin(theta)**m/(2**n*factorial(n)) times the\nc (n+m)th derivative of (x**2-1)**n with respect\nc to x=cos(theta)\nc\nc\nc define the maximum (plus one) longitudinal wave number\nc as mmax = min0(nlat,(nlon+2)/2) if nlon is even or\nc mmax = min0(nlat,(nlon+1)/2) if nlon is odd.\nc\nc then g(i,j) = the sum from n=0 to n=nlat-1 of\nc\nc .5*pbar(0,n,theta(i))*a(1,n+1)\nc\nc plus the sum from m=1 to m=mmax-1 of\nc\nc the sum from n=m to n=nlat-1 of\nc\nc pbar(m,n,theta(i))*(a(m+1,n+1)*cos(m*phi(j))\nc -b(m+1,n+1)*sin(m*phi(j)))\nc\nc ierror = 0 no errors\nc = 1 error in the specification of nlat\nc = 2 error in the specification of nlon\nc = 3 error in the specification of isym\nc = 4 error in the specification of nt\nc = 5 error in the specification of idg\nc = 6 error in the specification of jdg\nc = 7 error in the specification of mdab\nc = 8 error in the specification of ndab\nc = 9 error in the specification of lwshig\nc = 10 error in the specification of lwork\nc\nc\nc ****************************************************************\nc\nc subroutine shsgci(nlat,nlon,wshsgc,lshsgc,dwork,ldwork,ierror)\nc\nc subroutine shsgci initializes the array wshsgc which can then\nc be used repeatedly by subroutines shsgc. it precomputes\nc and stores in wshsgc quantities such as gaussian weights,\nc legendre polynomial coefficients, and fft trigonometric tables.\nc\nc input parameters\nc\nc nlat the number of points in the gaussian colatitude grid on the\nc full sphere. these lie in the interval (0,pi) and are compu\nc in radians in theta(1),...,theta(nlat) by subroutine gaqd.\nc if nlat is odd the equator will be included as the grid poi\nc theta((nlat+1)/2). if nlat is even the equator will be\nc excluded as a grid point and will lie half way between\nc theta(nlat/2) and theta(nlat/2+1). nlat must be at least 3.\nc note: on the half sphere, the number of grid points in the\nc colatitudinal direction is nlat/2 if nlat is even or\nc (nlat+1)/2 if nlat is odd.\nc\nc nlon the number of distinct londitude points. nlon determines\nc the grid increment in longitude as 2*pi/nlon. for example\nc nlon = 72 for a five degree grid. nlon must be greater\nc than or equal to 4. the efficiency of the computation is\nc improved when nlon is a product of small prime numbers.\nc\nc wshsgc an array which must be initialized by subroutine shsgci.\nc once initialized, wshsgc can be used repeatedly by shsgc\nc as long as nlat and nlon remain unchanged. wshsgc must\nc not be altered between calls of shsgc.\nc\nc lshsgc the dimension of the array wshsgc as it appears in the\nc program that calls shsgc. define\nc\nc l1 = min0(nlat,(nlon+2)/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc and\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc then lshsgc must be at least\nc\nc nlat*(2*l2+3*l1-2)+3*l1*(1-l1)/2+nlon+15\nc\nc dwork a double precision work array that does not have to be saved.\nc\nc ldwork the dimension of the array dwork as it appears in the\nc program that calls shsgci. ldwork must be at least\nc\nc nlat*(nlat+4)\nc\nc output parameter\nc\nc wshsgc an array which must be initialized before calling shsgc.\nc once initialized, wshsgc can be used repeatedly by shsgc\nc as long as nlat and nlon remain unchanged. wshsgc must not\nc altered between calls of shsgc.\nc\nc ierror = 0 no errors\nc = 1 error in the specification of nlat\nc = 2 error in the specification of nlon\nc = 3 error in the specification of lshsgc\nc = 4 error in the specification of ldwork\nc = 5 failure in gaqd to compute gaussian points\nc (due to failure in eigenvalue routine)\nc\nc\nc ****************************************************************\n subroutine shsgc(nlat,nlon,mode,nt,g,idg,jdg,a,b,mdab,ndab,\n 1 wshsgc,lshsgc,work,lwork,ierror)\nc subroutine shsgc performs the spherical harmonic synthesis on\nc a gaussian grid using the coefficients in array(s) a,b and returns\nc the results in array(s) g. the legendre polynomials are computed\nc as needed in this version.\nc\n dimension g(idg,jdg,1),a(mdab,ndab,1),b(mdab,ndab,1),\n 1 wshsgc(lshsgc),work(lwork)\nc check input parameters\n ierror = 1\n if (nlat.lt.3) return\n ierror = 2\n if (nlon.lt.4) return\n ierror = 3\n if (mode.lt.0 .or.mode.gt.2) return\n ierror = 4\n if (nt.lt.1) return\nc set limit for m iin a(m,n),b(m,n) computation\n l = min0((nlon+2)/2,nlat)\nc set gaussian point nearest equator pointer\n late = (nlat+mod(nlat,2))/2\nc set number of grid points for analysis/synthesis\n lat = nlat\n if (mode.ne.0) lat = late\n ierror = 5\n if (idg.lt.lat) return\n ierror = 6\n if (jdg.lt.nlon) return\n ierror = 7\n if(mdab .lt. l) return\n ierror = 8\n if(ndab .lt. nlat) return\n l1 = l\n l2 = late\n ierror = 9\nc check permanent work space length\n if (lshsgc .lt. nlat*(2*l2+3*l1-2)+3*l1*(1-l1)/2+nlon+15)return\n ierror = 10\nc check temporary work space length\n if (mode.eq.0) then\n if(lwork.lt.nlat*(nlon*nt+max0(3*l2,nlon)))return\n else\nc mode.ne.0\n if(lwork.lt.l2*(nlon*nt+max0(3*nlat,nlon))) return\n end if\n ierror = 0\nc starting address fft values\n ifft = nlat+2*nlat*late+3*(l*(l-1)/2+(nlat-l)*(l-1))+1\nc set pointers for internal storage of g and legendre polys\n ipmn = lat*nlon*nt+1\n call shsgc1(nlat,nlon,l,lat,mode,g,idg,jdg,nt,a,b,mdab,ndab,\n 1wshsgc,wshsgc(ifft),late,work(ipmn),work)\n return\n end\n subroutine shsgc1(nlat,nlon,l,lat,mode,gs,idg,jdg,nt,a,b,mdab,\n 1 ndab,w,wfft,late,pmn,g)\n dimension gs(idg,jdg,nt),a(mdab,ndab,nt),b(mdab,ndab,nt)\n dimension w(1),pmn(nlat,late,3),g(lat,nlon,nt),wfft(1)\nc reconstruct fourier coefficients in g on gaussian grid\nc using coefficients in a,b\nc set m+1 limit for b coefficient calculation\n lm1 = l\n if (nlon .eq. l+l-2) lm1 = l-1\nc initialize to zero\n do 100 k=1,nt\n do 100 j=1,nlon\n do 100 i=1,lat\n g(i,j,k) = 0.0\n 100 continue\n if (mode.eq.0) then\nc set first column in g\n m = 0\nc compute pmn for all i and n=m,...,l-1\n call legin(mode,l,nlat,m,w,pmn,km)\n do 101 k=1,nt\nc n even\n do 102 np1=1,nlat,2\n do 102 i=1,late\n g(i,1,k) = g(i,1,k)+a(1,np1,k)*pmn(np1,i,km)\n 102 continue\nc n odd\n nl2 = nlat/2\n do 103 np1=2,nlat,2\n do 103 i=1,nl2\n is = nlat-i+1\n g(is,1,k) = g(is,1,k)+a(1,np1,k)*pmn(np1,i,km)\n 103 continue\nc restore m=0 coefficents (reverse implicit even/odd reduction)\n do 112 i=1,nl2\n is = nlat-i+1\n t1 = g(i,1,k)\n t3 = g(is,1,k)\n g(i,1,k) = t1+t3\n g(is,1,k) = t1-t3\n 112 continue\n 101 continue\nc sweep columns of g for which b is available\n do 104 mp1=2,lm1\n m = mp1-1\n mp2 = m+2\nc compute pmn for all i and n=m,...,l-1\n call legin(mode,l,nlat,m,w,pmn,km)\n do 105 k=1,nt\nc for n-m even store (g(i,p,k)+g(nlat-i+1,p,k))/2 in g(i,p,k) p=2*m,\nc for i=1,...,late\n do 106 np1=mp1,nlat,2\n do 107 i=1,late\n g(i,2*m,k) = g(i,2*m,k)+a(mp1,np1,k)*pmn(np1,i,km)\n g(i,2*m+1,k) = g(i,2*m+1,k)+b(mp1,np1,k)*pmn(np1,i,km)\n 107 continue\n 106 continue\nc for n-m odd store g(i,p,k)-g(nlat-i+1,p,k) in g(nlat-i+1,p,k)\nc for i=1,...,nlat/2 (p=2*m,p=2*m+1)\n do 108 np1=mp2,nlat,2\n do 109 i=1,nl2\n is = nlat-i+1\n g(is,2*m,k) = g(is,2*m,k)+a(mp1,np1,k)*pmn(np1,i,km)\n g(is,2*m+1,k) = g(is,2*m+1,k)+b(mp1,np1,k)*pmn(np1,i,km)\n 109 continue\n 108 continue\nc now set fourier coefficients using even-odd reduction above\n do 110 i=1,nl2\n is = nlat-i+1\n t1 = g(i,2*m,k)\n t2 = g(i,2*m+1,k)\n t3 = g(is,2*m,k)\n t4 = g(is,2*m+1,k)\n g(i,2*m,k) = t1+t3\n g(i,2*m+1,k) = t2+t4\n g(is,2*m,k) = t1-t3\n g(is,2*m+1,k) = t2-t4\n 110 continue\n 105 continue\n 104 continue\nc set last column (using a only)\n if (nlon.eq. l+l-2) then\n m = l-1\n call legin(mode,l,nlat,m,w,pmn,km)\n do 111 k=1,nt\nc n-m even\n do 131 np1=l,nlat,2\n do 131 i=1,late\n g(i,nlon,k) = g(i,nlon,k)+2.0*a(l,np1,k)*pmn(np1,i,km)\n 131 continue\n lp1 = l+1\nc n-m odd\n do 132 np1=lp1,nlat,2\n do 132 i=1,nl2\n is = nlat-i+1\n g(is,nlon,k) = g(is,nlon,k)+2.0*a(l,np1,k)*pmn(np1,i,km)\n 132 continue\n do 133 i=1,nl2\n is = nlat-i+1\n t1 = g(i,nlon,k)\n t3 = g(is,nlon,k)\n g(i,nlon,k)= t1+t3\n g(is,nlon,k)= t1-t3\n 133 continue\n 111 continue\n end if\n else\nc half sphere (mode.ne.0)\nc set first column in g\n m = 0\n meo = 1\n if (mode.eq.1) meo = 2\n ms = m+meo\nc compute pmn for all i and n=m,...,l-1\n call legin(mode,l,nlat,m,w,pmn,km)\n do 113 k=1,nt\n do 113 np1=ms,nlat,2\n do 113 i=1,late\n g(i,1,k) = g(i,1,k)+a(1,np1,k)*pmn(np1,i,km)\n 113 continue\nc sweep interior columns of g\n do 114 mp1=2,lm1\n m = mp1-1\n ms = m+meo\nc compute pmn for all i and n=m,...,l-1\n call legin(mode,l,nlat,m,w,pmn,km)\n do 115 k=1,nt\n do 115 np1=ms,nlat,2\n do 115 i=1,late\n g(i,2*m,k) = g(i,2*m,k)+a(mp1,np1,k)*pmn(np1,i,km)\n g(i,2*m+1,k) = g(i,2*m+1,k)+b(mp1,np1,k)*pmn(np1,i,km)\n 115 continue\n 114 continue\n if (nlon.eq.l+l-2) then\nc set last column\n m = l-1\n call legin(mode,l,nlat,m,w,pmn,km)\n ns = l\n if (mode.eq.1) ns = l+1\n do 116 k=1,nt\n do 116 i=1,late\n do 116 np1=ns,nlat,2\n g(i,nlon,k) = g(i,nlon,k)+2.0*a(l,np1,k)*pmn(np1,i,km)\n 116 continue\n end if\n end if\nc do inverse fourier transform\n do 120 k=1,nt\n call hrfftb(lat,nlon,g(1,1,k),lat,wfft,pmn)\n 120 continue\nc scale output in gs\n do 122 k=1,nt\n do 122 j=1,nlon\n do 122 i=1,lat\n gs(i,j,k) = 0.5*g(i,j,k)\n 122 continue\n return\n end\n subroutine shsgci(nlat,nlon,wshsgc,lshsgc,dwork,ldwork,ierror)\nc this subroutine must be called before calling shsgc with\nc fixed nlat,nlon. it precomputes quantites such as the gaussian\nc points and weights, m=0,m=1 legendre polynomials, recursion\nc recursion coefficients.\n dimension wshsgc(lshsgc)\n double precision dwork(ldwork)\n ierror = 1\n if (nlat.lt.3) return\n ierror = 2\n if (nlon.lt.4) return\nc set triangular truncation limit for spherical harmonic basis\n l = min0((nlon+2)/2,nlat)\nc set equator or nearest point (if excluded) pointer\n late = (nlat+mod(nlat,2))/2\n l1 = l\n l2 = late\n ierror = 3\nc check permanent work space length\n if (lshsgc .lt. nlat*(2*l2+3*l1-2)+3*l1*(1-l1)/2+nlon+15)return\n ierror = 4\n if (ldwork .lt. nlat*(nlat+4)) return\n ierror = 0\nc set pointers\n i1 = 1\n i2 = i1+nlat\n i3 = i2+nlat*late\n i4 = i3+nlat*late\n i5 = i4+l*(l-1)/2 +(nlat-l)*(l-1)\n i6 = i5+l*(l-1)/2 +(nlat-l)*(l-1)\n i7 = i6+l*(l-1)/2 +(nlat-l)*(l-1)\nc set indices in temp work for double precision gaussian wts and pts\n idth = 1\n idwts = idth+nlat\n iw = idwts+nlat\n call shsgci1(nlat,nlon,l,late,wshsgc(i1),wshsgc(i2),wshsgc(i3),\n 1wshsgc(i4),wshsgc(i5),wshsgc(i6),wshsgc(i7),dwork(idth),\n 2dwork(idwts),dwork(iw),ierror)\n if (ierror.ne.0) ierror = 5\n return\n end\n subroutine shsgci1(nlat,nlon,l,late,wts,p0n,p1n,abel,bbel,cbel,\n 1 wfft,dtheta,dwts,work,ier)\n dimension wts(nlat),p0n(nlat,late),p1n(nlat,late),abel(1),bbel(1),\n 1 cbel(1),wfft(1),dtheta(nlat),dwts(nlat)\n double precision pb,dtheta,dwts,work(*)\nc compute the nlat gaussian points and weights, the\nc m=0,1 legendre polys for gaussian points and all n,\nc and the legendre recursion coefficients\nc define index function used in storing\nc arrays for recursion coefficients (functions of (m,n))\nc the index function indx(m,n) is defined so that\nc the pairs (m,n) map to [1,2,...,indx(l-1,l-1)] with no\nc \"holes\" as m varies from 2 to n and n varies from 2 to l-1.\nc (m=0,1 are set from p0n,p1n for all n)\nc define for 2.le.n.le.l-1\n indx(m,n) = (n-1)*(n-2)/2+m-1\nc define index function for l.le.n.le.nlat\n imndx(m,n) = l*(l-1)/2+(n-l-1)*(l-1)+m-1\nc preset quantites for fourier transform\n call hrffti(nlon,wfft)\nc compute double precision gaussian points and weights\nc lw = 4*nlat*(nlat+1)+2\n lw = nlat*(nlat+2)\n call gaqd(nlat,dtheta,dwts,work,lw,ier)\n if (ier.ne.0) return\nc store gaussian weights single precision to save computation\nc in inner loops in analysis\n do 100 i=1,nlat\n wts(i) = dwts(i)\n 100 continue\nc initialize p0n,p1n using double precision dnlfk,dnlft\n do 101 np1=1,nlat\n do 101 i=1,late\n p0n(np1,i) = 0.0\n p1n(np1,i) = 0.0\n 101 continue\nc compute m=n=0 legendre polynomials for all theta(i)\n np1 = 1\n n = 0\n m = 0\n call dnlfk(m,n,work)\n do 103 i=1,late\n call dnlft(m,n,dtheta(i),work,pb)\n p0n(1,i) = pb\n 103 continue\nc compute p0n,p1n for all theta(i) when n.gt.0\n do 104 np1=2,nlat\n n = np1-1\n m = 0\n call dnlfk(m,n,work)\n do 105 i=1,late\n call dnlft(m,n,dtheta(i),work,pb)\n p0n(np1,i) = pb\n 105 continue\nc compute m=1 legendre polynomials for all n and theta(i)\n m = 1\n call dnlfk(m,n,work)\n do 106 i=1,late\n call dnlft(m,n,dtheta(i),work,pb)\n p1n(np1,i) = pb\n 106 continue\n 104 continue\nc compute and store swarztrauber recursion coefficients\nc for 2.le.m.le.n and 2.le.n.le.nlat in abel,bbel,cbel\n do 107 n=2,nlat\n mlim = min0(n,l)\n do 107 m=2,mlim\n imn = indx(m,n)\n if (n.ge.l) imn = imndx(m,n)\n abel(imn)=sqrt(float((2*n+1)*(m+n-2)*(m+n-3))/\n 1 float(((2*n-3)*(m+n-1)*(m+n))))\n bbel(imn)=sqrt(float((2*n+1)*(n-m-1)*(n-m))/\n 1 float(((2*n-3)*(m+n-1)*(m+n))))\n cbel(imn)=sqrt(float((n-m+1)*(n-m+2))/\n 1 float(((n+m-1)*(n+m))))\n 107 continue\n return\n end\n", "meta": {"hexsha": "75587a0304c94bea1992949a7b6ba7032741eb49", "size": 22705, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/shsgc.f", "max_stars_repo_name": "jprules321/colas", "max_stars_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/shsgc.f", "max_issues_repo_name": "jprules321/colas", "max_issues_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/shsgc.f", "max_forks_repo_name": "jprules321/colas", "max_forks_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.5910596026, "max_line_length": 74, "alphanum_fraction": 0.5681127505, "num_tokens": 7548, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147439, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6670442790874465}} {"text": "e ! Not available. Can be calculated EXP(1)\npi ! Not available. Can be calculated 4.0*ATAN(1.0)\nSQRT(x) ! square root\nLOG(x) ! natural logarithm\nLOG10(x) ! logarithm to base 10\nEXP(x) ! exponential\nABS(x) ! absolute value\nFLOOR(x) ! floor - Fortran 90 or later only\nCEILING(x) ! ceiling - Fortran 90 or later only\nx**y ! x raised to the y power\n", "meta": {"hexsha": "f18f0d3e26246e3633c155a9699230521fb1fd85", "size": 387, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Real-constants-and-functions/Fortran/real-constants-and-functions.f", "max_stars_repo_name": "djgoku/RosettaCodeData", "max_stars_repo_head_hexsha": "91df62d46142e921b3eacdb52b0316c39ee236bc", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Task/Real-constants-and-functions/Fortran/real-constants-and-functions.f", "max_issues_repo_name": "djgoku/RosettaCodeData", "max_issues_repo_head_hexsha": "91df62d46142e921b3eacdb52b0316c39ee236bc", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Real-constants-and-functions/Fortran/real-constants-and-functions.f", "max_forks_repo_name": "djgoku/RosettaCodeData", "max_forks_repo_head_hexsha": "91df62d46142e921b3eacdb52b0316c39ee236bc", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.1818181818, "max_line_length": 59, "alphanum_fraction": 0.6330749354, "num_tokens": 123, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897525789548, "lm_q2_score": 0.709019146082187, "lm_q1q2_score": 0.6670379470164025}} {"text": "program test_inverse_trig\nuse lfortran_intrinsic_math, only: asin, acos, atan, asinh, acosh, atanh\nimplicit none\nreal :: x\n\nx = asin(0.84147098)\nif (abs(x - 1.0) > 1e-5) error stop\n\nx = acos(0.54030231)\nif (abs(x - 1.0) > 1e-5) error stop\n\nx = atan(1.5574077)\nif (abs(x - 1.0) > 1e-5) error stop\n\nx = asinh(1.1752012)\nif (abs(x - 1.0) > 1e-5) error stop\n\nx = acosh(1.5430806)\nif (abs(x - 1.0) > 1e-5) error stop\n\nx = atanh(0.76159416)\nif (abs(x - 1.0) > 1e-5) error stop\n\nend program\n", "meta": {"hexsha": "b8556d531a1322cf55b4e26ad9c6a4f5ea79273b", "size": 484, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/runtime/tests/test_inverse_trig.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": "src/runtime/tests/test_inverse_trig.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": "src/runtime/tests/test_inverse_trig.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": 19.36, "max_line_length": 72, "alphanum_fraction": 0.6446280992, "num_tokens": 226, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837706, "lm_q2_score": 0.7341195385342971, "lm_q1q2_score": 0.6670341475671315}} {"text": " SUBROUTINE W3FC05(U, V, DIR, SPD)\nC$$$ SUBPROGRAM DOCUMENTATION BLOCK\nC . . . .\nC SUBPROGRAM: W3FC05 EARTH U,V WIND COMPONENTS TO DIR AND SPD\nC PRGMMR: CHASE ORG: NMC421 DATE:88-10-26\nC\nC ABSTRACT: GIVEN THE TRUE (EARTH ORIENTED) WIND COMPONENTS\nC COMPUTE THE WIND DIRECTION AND SPEED.\nC INPUT WINDS AT THE POLE ARE ASSUMED TO FOLLOW THE WMO\nC CONVENTIONS, WITH THE OUTPUT DIRECTION COMPUTED IN ACCORDANCE\nC WITH WMO STANDARDS FOR REPORTING WINDS AT THE POLE.\nC (SEE OFFICE NOTE 241 FOR WMO DEFINITION.)\nC\nC PROGRAM HISTORY LOG:\nC 81-12-30 STACKPOLE, JOHN\nC 88-10-19 CHASE, P. ALLOW OUTPUT VALUES TO OVERLAY INPUT\nC 89-01-21 R.E.JONES CONVERT TO MICROSOFT FORTRAN 4.10\nC 90-06-11 R.E.JONES CONVERT TO SUN FORTRAN 1.3\nC 91-03-30 R.E.JONES SiliconGraphics FORTRAN\nC 93-03-29 R.E.JONES ADD SAVE STATEMENT\nC\nC USAGE: CALL W3FC05 (U, V, DIR, SPD)\nC\nC INPUT ARGUMENT LIST:\nC U - REAL*4 EARTH-ORIENTED U-COMPONENT\nC V - REAL*4 EARTH-ORIENTED V-COMPONENT\nC\nC OUTPUT ARGUMENT LIST: (INCLUDING WORK ARRAYS)\nC DIR - REAL*4 WIND DIRECTION, DEGREES. VALUES WILL\nC BE FROM 0 TO 360 INCLUSIVE.\nC SPD - REAL*4 WIND SPEED IN SAME UNITS AS INPUT\nC\nC INPUT FILES: NONE\nC\nC OUTPUT FILES: NONE\nC\nC SUBPROGRAMS CALLED:\nC LIBRARY:\nC COMMON - SQRT, ATAN2\nC\nC REMARKS: IF SPEED IS LESS THAN 1E-10 THEN DIRECTION WILL BE SET\nC TO ZERO.\nC\nC ATTRIBUTES:\nC LANGUAGE: SiliconGraphics 3.5 FORTRAN 77\nC MACHINE: SiliconGraphics IRIS-4D/25, 35, INDIGO\nC\nC$$$\nC\nC VARIABLES.....\nC\n REAL U, V, DIR, SPD, XSPD\nC\nC CONSTANTS.....\nC\n SAVE\nC\n DATA SPDTST/1E-10/, RTOD/57.2957795/, DCHALF/180.0/\n\n XSPD = SQRT(U * U + V * V)\n IF (XSPD .LT. SPDTST) THEN\n DIR = 0.0\n ELSE\n DIR = ATAN2(U,V) * RTOD + DCHALF\n ENDIF\n SPD = XSPD\n RETURN\n END\n", "meta": {"hexsha": "0a2a4843eed8edae7a3cd4b39b685c5d4d667e68", "size": 2002, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/programs/dc/dcprof/w3fc05.f", "max_stars_repo_name": "oxelson/gempak", "max_stars_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2015-06-03T15:26:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T22:36:03.000Z", "max_issues_repo_path": "gempak/source/programs/dc/dcprof/w3fc05.f", "max_issues_repo_name": "oxelson/gempak", "max_issues_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 60, "max_issues_repo_issues_event_min_datetime": "2015-05-11T21:36:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T16:22:42.000Z", "max_forks_repo_path": "gempak/source/programs/dc/dcprof/w3fc05.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.0144927536, "max_line_length": 70, "alphanum_fraction": 0.6193806194, "num_tokens": 722, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178969328287, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.6670341406293675}} {"text": "C **********************************************************************\nC Function to compute the Johnson-Cook yield stress\nC **********************************************************************\n function yieldStress (\nC Parameters\n 1 epsp, depsp, temp,\nC Constants of the constitutive law\n 2 parA, parB, parC, parn, parm, pardepsp0, parT0, parTm )\n include 'vaba_param.inc'\nC Hardening part of the Johnson-Cook law\n hardPart = parA + parB * epsp**parn\nC Dependence to the deformation rate\n if (depsp .gt. pardepsp0) then\n viscPart = 1.0 + parC * log (depsp/pardepsp0)\n else\n viscPart = 1.0\n end if\nC Dependence to the temperature if parT0 < temp < parTm\n tempPart = 1.0\n if (temp > parT0) then\n if (temp < parTm) then\n tempPart = 1.0 - ((temp - parT0) / (parTm - parT0))**parm\n else\n tempPart = 0.0\n end if \n end if\nC Compute and return the yield stress\n yieldStress = hardPart * viscPart * tempPart\n return\n end\n\nC **********************************************************************\nC Function to compute the Johnson-Cook hardening / epsp\nC **********************************************************************\n function yieldHardEpsp (\nC Parameters\n 1 epsp, depsp, temp,\nC Constants of the constitutive law\n 2 parA, parB, parC, parn, parm, pardepsp0, parT0, parTm)\n include 'vaba_param.inc'\nC Hardening part of the Johnson-Cook law\n hardPart = parn * parB * (epsp**(parn - 1.0))\nC Dependence to the deformation rate\n if (depsp .gt. pardepsp0) then\n hardPart = hardPart * (1.0 + parC * log (depsp/pardepsp0))\n end if \nC Dependence to the temperature if parT0 < temp < parTm\n tempPart = 1.0\n if (temp > parT0) then\n if (temp < parTm) then\n tempPart = 1.0 - ((temp - parT0) / (parTm - parT0))**parm\n else\n tempPart = 0.0\n end if \n end if\nC Compute and return the yield stress\n yieldHardEpsp = hardPart * tempPart\n return\n end\n \nC **********************************************************************\nC Function to compute the Johnson-Cook hardening / depsp\nC **********************************************************************\n function yieldHardDepsp (\nC Parameters\n 1 epsp, depsp, temp,\nC Constants of the constitutive law\n 2 parA, parB, parC, parn, parm, pardepsp0, parT0, parTm)\n include 'vaba_param.inc'\nC Hardening part of the Johnson-Cook law\n hardPart = 0.0\nC Dependence to the deformation rate\n if (depsp .gt. pardepsp0) then\n hardPart = (parA + parB * epsp**parn) * parC / depsp\n end if \nC Dependence to the temperature if parT0 < temp < parTm\n tempPart = 1.0\n if (temp > parT0) then\n if (temp < parTm) then\n tempPart = 1.0 - ((temp - parT0) / (parTm - parT0))**parm\n else\n tempPart = 0.0\n end if \n end if\nC Compute and return the yield stress\n yieldHardDepsp = hardPart * tempPart\n return\n end\n \nC **********************************************************************\nC Function to compute the Johnson-Cook hardening / T\nC **********************************************************************\n function yieldHardTemp (\nC Parameters\n 1 epsp, depsp, temp,\nC Constants of the constitutive law\n 2 parA, parB, parC, parn, parm, pardepsp0, parT0, parTm)\n include 'vaba_param.inc'\nC Hardening part of the Johnson-Cook law\n hardPart = parA + parB * epsp**parn\nC Dependence to the deformation rate\n if (depsp .gt. pardepsp0) then\n viscPart = 1.0 + parC * log (depsp/pardepsp0)\n else\n viscPart = 1.0\n end if\nC Dependence to the temperature if parT0 < temp < parTm\n tempPart = 0.0\n if (temp > parT0 .and. temp < parTm) then\n tempPart = -parm*(((temp - parT0)/(parTm - parT0))**(parm))\n 1 / (temp - parT0)\n end if\nC Compute and return the yield stress\n yieldHardTemp = hardPart * viscPart * tempPart\n return\n end\n\nC **********************************************************************\nC Function to compute the numerical Johnson-Cook hardening / epsp\nC **********************************************************************\n function yieldHardEpspNum (\nC Parameters\n 1 yield, epsp, depsp, temp,\nC Constants of the constitutive law\n 2 parA, parB, parC, parn, parm, pardepsp0, parT0, parTm)\n include 'vaba_param.inc'\nC Increment of the plastic strain\n deltaEpsp = 1.0e-1\n if (j_sys_Dimension .eq. 2) deltaEpsp = 1.0e-8\n epspForward = epsp + deltaEpsp\nc yieldForward\n yieldForward = yieldStress (epspForward, depsp, temp,\n 1 parA, parB, parC, parn, parm, pardepsp0, parT0, parTm)\n yieldHardEpspNum = (yieldForward - yield) / deltaEpsp\n return\n end\n \nC **********************************************************************\nC Function to compute the numerical Johnson-Cook hardening / depsp\nC **********************************************************************\n function yieldHardDepspNum (\nC Parameters\n 1 yield, epsp, depsp, temp,\nC Constants of the constitutive law\n 2 parA, parB, parC, parn, parm, pardepsp0, parT0, parTm)\n include 'vaba_param.inc'\nc Increment of the plastic strain rate\n deltaDepsp = 1.0e-1\n if (j_sys_Dimension .eq. 2) deltaDepsp = 1.0e-8\n depspForward = depsp + deltaDepsp\nc yieldForward\n yieldForward = yieldStress (epsp, depspForward, temp,\n 1 parA, parB, parC, parn, parm, pardepsp0, parT0, parTm)\n yieldHardDepspNum = (yieldForward - yield) / deltaDepsp\n return\n end\n \nC **********************************************************************\nC Function to compute the numerical Johnson-Cook hardening / T\nC **********************************************************************\n function yieldHardTempNum (\nC Parameters\n 1 yield, epsp, depsp, temp,\nC Constants of the constitutive law\n 2 parA, parB, parC, parn, parm, pardepsp0, parT0, parTm)\n include 'vaba_param.inc'\nc Increment of the temperature\n deltaTemp = 1.0e-1\n if (j_sys_Dimension .eq. 2) deltaTemp = 1.0e-8\n tempForward = temp + deltaTemp\nc yieldForward\n yieldForward = yieldStress (epsp, depsp, tempForward,\n 1 parA, parB, parC, parn, parm, pardepsp0, parT0, parTm)\n yieldHardTempNum = (yieldForward - yield) / deltaTemp\n return\n end\n\n", "meta": {"hexsha": "73c432d43e1943139cab137aa6529a2efaba74f4", "size": 6466, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Sources/JohnsonCook.f", "max_stars_repo_name": "pantale/abaqusVumat", "max_stars_repo_head_hexsha": "3be9d7edcdc495b1d35594b1c6ef9cbaeb74a8ab", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 19, "max_stars_repo_stars_event_min_datetime": "2019-12-22T16:24:18.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T01:15:36.000Z", "max_issues_repo_path": "Sources/JohnsonCook.f", "max_issues_repo_name": "pantale/abaqusVumat", "max_issues_repo_head_hexsha": "3be9d7edcdc495b1d35594b1c6ef9cbaeb74a8ab", "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": "Sources/JohnsonCook.f", "max_forks_repo_name": "pantale/abaqusVumat", "max_forks_repo_head_hexsha": "3be9d7edcdc495b1d35594b1c6ef9cbaeb74a8ab", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2019-12-22T16:24:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T15:08:55.000Z", "avg_line_length": 36.3258426966, "max_line_length": 72, "alphanum_fraction": 0.5445406743, "num_tokens": 1827, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418158002492, "lm_q2_score": 0.7217432182679956, "lm_q1q2_score": 0.666993088271701}} {"text": " SUBROUTINE OPA_SET_UP_GRID\n & (delta_min,\n & mxlat,nrlat,mxlon,nrlon,\n & xlat1,xlon1,xlat2,xlon2,\n & xclt,cxclt,sxclt,xlng)\n\nc Generates grid of latitude and longitude;\nc Sign convention is + for West and North\n\nc mxlat maximum number of points in latitude INTEGER\nc nrlat number of points output for latitude INTEGER\n\nc mxlon maximum number of points in longitude INTEGER\nc nrlon number of points output for longitude INTEGER\n\nc delta_min minimum increment of latitude/longitude REAL\n\nc xlat1 latitude of the lower left corner REAL\nc xlon1 longitude of the lower left corner REAL\nc xlat2 latitude of the upper right corner REAL\nc xlon2 longitude of the upper right corner REAL\n\nc xlng longitude points in radians REAL\nc xclt latitude points in radians REAL\nc cxclt cosine(xclt) REAL\nc sxclt sine(xclt) REAL\n\n real xclt(mxlat),cxclt(mxlat),sxclt(mxlat),xlng(mxlon)\n\n data xlats1,xlats2,xlons1,xlons2/4*720./\n\n\nc Test if this is a new op area grid\n if (xlon1 .eq. xlons1 .and. xlat1 .eq. xlats1 .and.\n & xlon2 .eq. xlons2 .and. xlat2 .eq. xlats2) return\n\nc Longitude increment is chosen to give maximum resolution within\nc the op area consistent with the maximum number of points allowed\n xlng1=xlon1\n xlng2=xlon2\n if (xlng2 .ge. xlng1) xlng2=xlng2-360.\n\n delta=10.\n mx=(xlng1-xlng2)/delta+1.\n do while (mx .le. mxlon .and. delta .ge. delta_min)\n nrlon=mx\n delta=delta/2.\n mx=(xlng1-xlng2)/delta+1.\n end do\n delta=delta*2.\n\n sum=xlng1\n do j=1,nrlon\n xlng(j)=sum*.01745329252 ! convert to radians\n sum=sum-delta\n if (sum .lt. -180.) sum=sum+360.\n end do\n\nc Latitude increment is chosen to give maximum resolution within\nc the op area consistent with the maximum number of points allowed\n xclt1=90.-xlat1\n xclt2=90.-xlat2\n\n delta=10.\n my=(xclt1-xclt2)/delta+1.\n do while (my .le. mxlat .and. delta .ge. delta_min)\n nrlat=my\n delta=delta/2.\n my=(xclt1-xclt2)/delta+1.\n end do\n delta=delta*2.\n\n sum=xclt1\n do j=1,nrlat\n xclt(j)=sum*.01745329252 ! convert to radians\n cxclt(j)=cos(xclt(j))\n sxclt(j)=sin(xclt(j))\n sum=sum-delta\n end do\n\nc Save test parameters\n xlons1=xlon1\n xlons2=xlon2\n xlats1=xlat1\n xlats2=xlat2\n\n return\n END ! OPA_SET_UP_GRID\n", "meta": {"hexsha": "c3b545f7589d6395721c1908ecdd202d144bf2d7", "size": 2872, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "LWPCv21/lib/opa_set_up_grid.for", "max_stars_repo_name": "spinorkit/LWPC", "max_stars_repo_head_hexsha": "6144eac3b1ac1322d0ee363ec689bf8123bdeebd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2019-10-17T17:13:28.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-01T03:29:27.000Z", "max_issues_repo_path": "LWPCv21/lib/opa_set_up_grid.for", "max_issues_repo_name": "spinorkit/LWPC", "max_issues_repo_head_hexsha": "6144eac3b1ac1322d0ee363ec689bf8123bdeebd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-07-07T10:52:53.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-12T11:01:31.000Z", "max_forks_repo_path": "LWPCv21/lib/opa_set_up_grid.for", "max_forks_repo_name": "spinorkit/LWPC", "max_forks_repo_head_hexsha": "6144eac3b1ac1322d0ee363ec689bf8123bdeebd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-06-22T01:48:48.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-01T03:31:50.000Z", "avg_line_length": 32.2696629213, "max_line_length": 72, "alphanum_fraction": 0.5577994429, "num_tokens": 823, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418158002492, "lm_q2_score": 0.721743206297598, "lm_q1q2_score": 0.6669930772093561}} {"text": "SUBROUTINE crf_bff (r_CRS, v_CRS, Yangle, Rcrf_bff, Rrtn_bff)\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! SUBROUTINE: crf_bff.f90\r\n! ----------------------------------------------------------------------\r\n! Purpose:\r\n! Transformation between inertial frame and body-fixed frame\r\n! Transformation between orbital frame and body-fixed frame \r\n! ----------------------------------------------------------------------\r\n! Input arguments:\r\n! - r_sat: \t\t\tSatellite position vector (m) \r\n! - v_sat: \t\t\tSatellite velocity vector (m/sec)\r\n! - Yangle:\t\t\tYaw angle (degrees)\r\n!\r\n! Output arguments:\r\n! - Rcrf_bff:\t\tTransformation matrix: Inertial frame (GCRF) to Body-fixed frame\r\n! - Rrtn_bff:\t\tTransformation matrix: Orbital frame to Body-fixed frame\r\n! ----------------------------------------------------------------------\r\n! Thomas D. Papanikolaou, Geoscience Australia June 2016\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n USE mdl_precision\r\n USE mdl_num\r\n !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_d), INTENT(IN) :: r_CRS(3), v_CRS(3)\r\n REAL (KIND = prec_d), INTENT(IN) :: Yangle\r\n! OUT\r\n REAL (KIND = prec_d), INTENT(OUT) :: Rcrf_bff(3,3), Rrtn_bff(3,3)\r\n! ----------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n! Local variables declaration\r\n! ----------------------------------------------------------------------\r\n REAL (KIND = prec_d) :: Rcrf_rtn(3,3), Drtn_bff(3,3), Rz_yaw(3,3)\r\n REAL (KIND = prec_d) :: Rtest(3,3)\r\n REAL (KIND = prec_d) :: Yangle_rad\r\n INTEGER (KIND = prec_int4) :: AllocateStatus, DeAllocateStatus\r\n! ----------------------------------------------------------------------\r\n\t \r\n\r\n\t \r\n! ----------------------------------------------------------------------\r\n! Transformation matrix: Inertial frame (GCRF) to Body-fixed frame\r\n! ----------------------------------------------------------------------\r\n\r\n! Rcrf_bff = Rz_yaw * Drtn_bff * Rcrf_rtn\r\n\r\n! Xbff = Rz_yaw * Drtn_bff * Rcrf_rtn * Xcrf = Rz_yaw * Drtn_bff * Xrtn\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! Inertial (GCRF) to Orbital Frame\r\n! ----------------------------------------------------------------------\r\n! RTN: Radial, Along (Tangential), Cross (Normal)\r\n! Xrtn = Rcrf_rtn * Xcrf\r\n CALL orb_frame(r_CRS, v_CRS, Rcrf_rtn)\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! Orbital frame to body-fixed frame\r\n! ----------------------------------------------------------------------\r\n\r\n! Rotation matrix for the axes directions correspondence: RTN to TNR to XYZ axes\r\n! For yaw = 0\r\n! eBF_x = eT\r\n! eBF_y = -eN\r\n! eBF_z = -eR\r\n Drtn_bff (1,1:3) = (/ 0.0D0, 1.0D0, 0.0D0 /) \r\n Drtn_bff (2,1:3) = (/ 0.0D0, 0.0D0, -1.0D0 /) \r\n Drtn_bff (3,1:3) = (/ -1.0D0, 0.0D0, 0.0D0 /) \r\n\r\n\t \r\n! Rz(yaw) rotation matrix: \r\n Yangle_rad = Yangle * (PI_global / 180.0D0)\r\n\t \r\n Rz_yaw(1,1:3) = (/ cos(Yangle_rad), sin(Yangle_rad), 0.0D0 /)\r\n Rz_yaw(2,1:3) = (/ -sin(Yangle_rad), cos(Yangle_rad), 0.0D0 /)\r\n Rz_yaw(3,1:3) = (/ 0.0D0, 0.0D0, 1.0D0 /)\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n! Arrays multiplication\r\n\r\n! ----------------------------------------------------------------------\r\n! Allocatable arrays\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! IF (AllocateStatus /= 0) THEN\r\n! PRINT *, \"Error: Not enough memory\"\r\n! PRINT *, \"Error: SUBROUTINE crf_bff.f90\"\r\n! STOP \"*** Not enough memory ***\"\r\n! END IF \r\n! ----------------------------------------------------------------------\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! Orbital to body-fixed frame\r\n !R1 = Rz_yaw\r\n !R2 = Drtn_bff\r\n !CALL matrixRxR (R1, R2, R3)\t\t\t\t\t\t\t\t\r\n !Rrtn_bff = R3\r\n ! matrix_RxR equivalent to MATMUL \r\n Rrtn_bff = MATMUL(Rz_yaw, Drtn_bff)\r\n\t \r\n! Inertial to body-fixed frame\r\n !R1 = Rrtn_bff\r\n !R2 = Rcrf_rtn\r\n !CALL matrix_RxR (R1, R2, R3)\r\n !Rcrf_bff = R3\r\n ! matrix_RxR equivalent to MATMUL \r\n Rcrf_bff = MATMUL(Rrtn_bff, Rcrf_rtn)\r\n !Rcrf_bff = MATMUL(Rcrf_rtn,Rrtn_bff)\r\n! ----------------------------------------------------------------------\r\n \r\n\r\nEND Subroutine\r\n", "meta": {"hexsha": "e68884ea83d1ba1930208dc66db956d7f91948bc", "size": 4868, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/crf_bff.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/crf_bff.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/crf_bff.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": 38.3307086614, "max_line_length": 81, "alphanum_fraction": 0.3907148726, "num_tokens": 1273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418116217418, "lm_q2_score": 0.721743206297598, "lm_q1q2_score": 0.6669930741935468}} {"text": " subroutine getillls(pin)\n implicit double precision (a-h,o-z)\n dimension fa(0:40),si(0:40),pin(0:8,0:8,0:16)\n\n fa(0)=1.d0\n si(0)=1.d0\n do i=1,32\n fa(i)=dfloat(i)*fa(i-1)\n si(i)=-si(i-1)\n enddo\n\n do 1000 l=0,8\n do 1000 m=0,8\n do 1000 n=m+l,0,-2\n xi=0.d0\n xf=2.d0/2.d0**dfloat(n+l+m)\n nn=(n+1)/2\n mm=(m+1)/2\n ll=(l+1)/2\n do 500 ia=nn,n\n af=si(ia)*fa(ia+ia)/fa(ia)/fa(n-ia)/fa(ia+ia-n) // ***\n do 500 ib=ll,l\n bf=si(ib)*fa(ib+ib)/fa(ib)/fa(l-ib)/fa(ib+ib-l) // ***\n do 500 ic=mm,m\n xcf=si(ic)*fa(ic+ic)/fa(ic)/fa(m-ic)/fa(ic+ic-m) // ***\n xi=xi+xf*af*bf*xcf/dfloat(ia*2+ib*2+ic*2-n-l-m+1) // ***\n 500 continue\n pin(l,m,n)=xi\n 1000 continue\n\n return\n\n end\n", "meta": {"hexsha": "47704dbba99ef0dd5bf4310f69bfd45b742e9b92", "size": 942, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "Examples/getillls.for", "max_stars_repo_name": "paule32/forth2asm", "max_stars_repo_head_hexsha": "b1208581cd94017f8207b4b3bff28f0bce81ff7e", "max_stars_repo_licenses": ["MIT"], "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/getillls.for", "max_issues_repo_name": "paule32/forth2asm", "max_issues_repo_head_hexsha": "b1208581cd94017f8207b4b3bff28f0bce81ff7e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-12-09T00:20:36.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-09T00:20:36.000Z", "max_forks_repo_path": "Examples/getillls.for", "max_forks_repo_name": "paule32/forth2asm", "max_forks_repo_head_hexsha": "b1208581cd94017f8207b4b3bff28f0bce81ff7e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-30T15:10:31.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-30T15:10:31.000Z", "avg_line_length": 27.7058823529, "max_line_length": 79, "alphanum_fraction": 0.3970276008, "num_tokens": 361, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947132556618, "lm_q2_score": 0.7057850278370112, "lm_q1q2_score": 0.6669631200009757}} {"text": "!> Procedures to compute the Hypergeometric function _2F_1 in the\n!! special case in which a or b is a negative integer.\nmodule m_hyp2f1_negint\nuse iso_c_binding\nimplicit none\n\ncontains\n\n!> Computes the value of the Gauss hypergeometric function in the\n!! special case in which @p a or @p b is a negative integer.\n!!\n!! @see Equation 15.4.1 from Abramowitz and Stegun: Handbook of\n!! Mathematical Functions.\n!!\npure function hyp2f1_negint(a, b, c, z) result(sum)\n integer, intent(in) :: a, b, c\n real(c_double), intent(in) :: z\n real(c_double) :: sum\n integer(c_int) :: n\n integer :: i\n\n if (a < 0) n = -a\n if (b < 0 .and. b > a) n = -b\n\n sum = coeff(a, b, c, n)\n do i = n - 1, 0, -1\n sum = sum * z + coeff(a, b, c, i)\n end do\n \nend function\n\npure function coeff(a, b, c, n) result(res)\n integer, intent(in) :: a, b, c, n\n real(c_double) :: res\n if (n == 0) then\n res = 1.0\n else\n res = ph(a, n) / real(ph(c, n), c_double) * ph(b, n) / &\n real(fact(n), c_double)\n end if\nend function coeff\n\npure recursive function ph(a, n) result(res)\n integer, intent(in) :: a, n\n real(c_double) :: res\n if (n == 0 ) then\n res = 1\n else\n res = a * ph(a + 1, n - 1)\n end if\nend function ph\n\npure recursive function fact(n) result(res)\n integer, intent(in) :: n\n real(c_double) :: res\n if (n > 1) then\n res = n * fact(n - 1)\n else\n res = 1\n end if\nend function fact\n\n\nend module m_hyp2f1_negint\n", "meta": {"hexsha": "5d7e7855c4cea058271d5c873b7d152220cafda8", "size": 1441, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/m_hyp2f1_negint.f90", "max_stars_repo_name": "jonekoo/CoarseMC", "max_stars_repo_head_hexsha": "7f9d032fe8f7e45a3cab857cd38de33c05f4b7c5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/m_hyp2f1_negint.f90", "max_issues_repo_name": "jonekoo/CoarseMC", "max_issues_repo_head_hexsha": "7f9d032fe8f7e45a3cab857cd38de33c05f4b7c5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/m_hyp2f1_negint.f90", "max_forks_repo_name": "jonekoo/CoarseMC", "max_forks_repo_head_hexsha": "7f9d032fe8f7e45a3cab857cd38de33c05f4b7c5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.1692307692, "max_line_length": 65, "alphanum_fraction": 0.6162387231, "num_tokens": 504, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.7490872075132153, "lm_q1q2_score": 0.6669080113499959}} {"text": "! Compute the analytic solution for the relaxation to thermal\n! equilibrium radiation problem. We follow the problem outline from\n! Swesty and Myra (2009), section 4.4.1.\n!\n! This code returns the radiation energy as a function of time.\n\n\nmodule constants_module\n\n use amrex_fort_module, only : rt => amrex_real\n\n ! fundamental constants\n real(rt), parameter :: k_B = 1.3806504d-16 ! erg / K\n real(rt), parameter :: c_light = 2.99792458d10 ! cm / s\n real(rt), parameter :: sigma_SB = 5.670400d-5 ! erg/s/cm^2/K^4\n real(rt), parameter :: a_rad = 4.0d0*sigma_SB/c_light\n real(rt), parameter :: m_p = 1.672621637d-24 ! g\n\n ! problem parameters\n\n ! matter density\n real(rt), parameter :: rho_ambient = 1.e-7 ! g / cm**3\n\n ! mean molecular weight\n real(rt), parameter :: mu = 0.6\n\n ! ratio of specific heats\n real(rt), parameter :: gamma = 5.0d0/3.0d0\n\n ! starting time\n real(rt), parameter :: t_0 = 1.d-16 ! s\n\n ! starting radiation energy density\n real(rt), parameter :: E_rad = 1.d12 ! erg / cm**3\n\n ! starting matter energy density\n !\n ! This is one of the main parameters that controls the behavior of\n ! the problem. The matter energy sets the matter temperature (via\n ! the EOS). If (a T**4) > E_rad, then we are doing a cooling\n ! problem. If (a T**4) < E_rad, then we are doing a heating problem\n ! (i.e. the matter temperature will increase with time to the\n ! equilibrium temperature).\n\n !real(rt), parameter :: rhoe_i = 1.d9 ! erg / cm**3\n real(rt), parameter :: rhoe_i = 1.d2 ! erg / cm**3\n\n ! we will specify the opacity as a constant kappa. In Castro lingo,\n ! this is the Planck mean opacity, which appears in the source term.\n real(rt), parameter :: kappa_p = 4.d-8\n\n\nend module constants_module\n\nfunction f(x,beta,eta) result (fval)\n\n real(rt), intent(in) :: x, beta, eta\n real(rt) :: fval\n\n ! There are different analytic solutions depending on whether we are\n ! heating (x < beta/eta) or cooling (x > beta/eta)\n\n if (x < beta/eta) then\n\n ! note: this form is different than what appears in Swesty and Myra,\n ! but instead, this is the form that Doug seems to have used in his\n ! code.\n fval = (1.d0/(2.d0*eta*beta**3)) * &\n (0.5d0*log((beta + eta*x)/(beta - eta*x)) + &\n atan(eta*x/beta))\n else\n fval = (1.d0/(2.d0*eta*beta**3)) * &\n (0.5d0*log((x + beta/eta)/(x - beta/eta)) + &\n atan(eta*x/beta))\n endif\n\n return\nend function f\n\nprogram analytic\n\n ! compute the analytic solution to the thermal relaxation problem,\n ! as given by Swesty and Myra (2009), Eq. 83, 84.\n\n ! The analytic solution provides t(rho*e) for the gas component.\n\n use constants_module\n\n implicit none\n\n real(rt) :: safe_print\n real(rt) :: f\n\n real(rt) :: beta, c_v, eta\n real(rt) :: rhoe_f, rhoe, dlog_rhoe\n real(rt) :: t\n\n integer :: n\n integer, parameter :: nsteps = 2000\n\n ! the beta constant as implied in Swesty and Myra, eq. 81\n beta = (c_light*kappa_p*E_rad)**0.25d0\n\n ! specific heat at constant volume for an idea gas (Note: Swesty and\n ! Myra work with temperature in MeV, so Boltzmann's constant, k_B,\n ! does not appear in their derivation.\n c_v = k_B/(mu*m_p*(gamma - 1.d0))\n\n ! the eta constant as implied in Swesty and Myra, eq. 81\n eta = ((c_light*kappa_p*a_rad)**0.25d0)/(c_v*rho_ambient)\n\n ! final energy density (see Swesty and Myra, text just before\n ! Eq. 82)\n rhoe_f = beta/eta\n\n ! energy increment\n dlog_rhoe = (log(rhoe_f) - log(rhoe_i))/(nsteps-1)\n\n\n print *, '# t, rho*e (matter)'\n\n ! loop in energy to find corresponding time\n do n = 1, nsteps\n rhoe = exp(log(rhoe_i) + dble(n-1)*dlog_rhoe)\n\n t = t_0 + f(rhoe,beta,eta) - f(rhoe_i,beta,eta)\n\n print *, t, rhoe\n enddo\n\nend program analytic\n", "meta": {"hexsha": "951a838c2dc32fa347f4ae30d53f4e003cc79fb7", "size": 3775, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Exec/radiation_tests/RadSourceTest/analytic.f90", "max_stars_repo_name": "taehoryu/Castro", "max_stars_repo_head_hexsha": "223c72c993343ba5df84613d058ffb0767c2a7c9", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-06-05T19:23:47.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-05T19:23:47.000Z", "max_issues_repo_path": "Exec/radiation_tests/RadSourceTest/analytic.f90", "max_issues_repo_name": "taehoryu/Castro", "max_issues_repo_head_hexsha": "223c72c993343ba5df84613d058ffb0767c2a7c9", "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": "Exec/radiation_tests/RadSourceTest/analytic.f90", "max_forks_repo_name": "taehoryu/Castro", "max_forks_repo_head_hexsha": "223c72c993343ba5df84613d058ffb0767c2a7c9", "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": 28.5984848485, "max_line_length": 73, "alphanum_fraction": 0.6503311258, "num_tokens": 1211, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.749087201911703, "lm_q1q2_score": 0.6669080107238958}} {"text": " subroutine MINV2(A,B)\n IMPLICIT REAL*8 (A-H,O-Z)\n DIMENSION A(2,2),B(2,2)\n DETA=A(1,1)*A(2,2)-A(1,2)*A(2,1)\n IF(DETA.EQ.0.) THEN\n WRITE(6,'(A)') 'DETERMINANT=0 MATRIX-INV NOT FOUND'\n WRITE(6,'(4F10.4)') A\n STOP\n END IF\n B(1,1)=A(2,2)/DETA\n B(1,2)=-A(1,2)/DETA\n B(2,1)=-A(2,1)/DETA\n B(2,2)=A(1,1)/DETA\n RETURN\n END\n", "meta": {"hexsha": "d53d89334e89451f93e29a4da1fdc983eaddbc53", "size": 405, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MINV2.f", "max_stars_repo_name": "noboruatkek/SAD", "max_stars_repo_head_hexsha": "3881a190af8903537774c57b56963ffc94cfc039", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2019-04-01T15:54:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-09T16:47:20.000Z", "max_issues_repo_path": "src/MINV2.f", "max_issues_repo_name": "noboruatkek/SAD", "max_issues_repo_head_hexsha": "3881a190af8903537774c57b56963ffc94cfc039", "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/MINV2.f", "max_forks_repo_name": "noboruatkek/SAD", "max_forks_repo_head_hexsha": "3881a190af8903537774c57b56963ffc94cfc039", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2017-03-15T08:52:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-19T08:06:40.000Z", "avg_line_length": 25.3125, "max_line_length": 62, "alphanum_fraction": 0.4543209877, "num_tokens": 189, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096158798117, "lm_q2_score": 0.7279754430043072, "lm_q1q2_score": 0.6669053034606116}} {"text": "! THIS VERSION: GALAHAD 2.1 - 22/03/2007 AT 09:00 GMT.\n PROGRAM GALAHAD_ROOTS_test_deck\n USE GALAHAD_ROOTS_double ! double precision version\n IMPLICIT NONE\n INTEGER, PARAMETER :: wp = KIND( 1.0D+0 ) ! set precision\n REAL ( KIND = wp ), PARAMETER :: one = 1.0_wp\n\n INTEGER :: order, type, nroots, status\n REAL ( KIND = wp ) :: tol, A( 0 : 4 ), ROOTS( 4 )\n REAL ( KIND = wp ) :: A1( 0 : 5 ), A2( 0: 2 ), ROOTS2( 1 )\n\n tol = EPSILON( one ) ** 0.75\n\n DO order = 2, 4\n DO type = 1, 2\n IF ( order == 2 ) THEN\n A( 0 ) = 2.01_wp\n A( 1 ) = - 3.01_wp\n A( 2 ) = 1.01_wp\n IF ( type == 2 ) A( 2 ) = 0.0_wp\n ELSE IF ( order == 3 ) THEN\n A( 0 ) = - 6.01_wp\n A( 1 ) = 11.01_wp\n A( 2 ) = -6.01_wp\n A( 3 ) = 1.01_wp\n IF ( type == 2 ) A( 3 ) = 0.0_wp\n ELSE\n IF ( type == 1 ) THEN\n A( 0 ) = 24.001_wp\n A( 1 ) = -50.001_wp\n A( 2 ) = 35.001_wp\n A( 3 ) = -10.001_wp\n A( 4 ) = 1.001_wp\n ELSE\n A( 0 ) = 1.00_wp\n A( 1 ) = -4.00_wp\n A( 2 ) = 6.00_wp\n A( 3 ) = -4.00_wp\n A( 4 ) = 1.00_wp\n END IF\n END IF\n\n IF ( type == 1 ) THEN\n IF ( order == 2 ) THEN\n WRITE( 6, \"( /, ' Quadratic ' )\" )\n CALL ROOTS_quadratic( A( 0 ), A( 1 ), A( 2 ), tol, &\n nroots, ROOTS( 1 ), ROOTS( 2 ) )\n ELSE IF ( order == 3 ) THEN\n WRITE( 6, \"( /, ' Cubic ' )\" )\n CALL ROOTS_cubic( A( 0 ), A( 1 ), A( 2 ), A( 3 ), tol, &\n nroots, ROOTS( 1 ), ROOTS( 2 ), ROOTS( 3 ) )\n ELSE\n WRITE( 6, \"( /, ' Quartic ' )\" )\n CALL ROOTS_quartic( A( 0 ), A( 1 ), A( 2 ), A( 3 ), A( 4 ), tol, &\n nroots, ROOTS( 1 ), ROOTS( 2 ), ROOTS( 3 ), ROOTS( 4 ) )\n END IF\n ELSE\n IF ( order == 2 ) THEN\n WRITE( 6, \"( /, ' Quadratic ' )\" )\n CALL ROOTS_solve( A( 0 : order ), tol, nroots, &\n ROOTS( : order ), status )\n ELSE IF ( order == 3 ) THEN\n WRITE( 6, \"( /, ' Cubic ' )\" )\n CALL ROOTS_solve( A( 0 : order ), tol, nroots, &\n ROOTS( : order ), status )\n ELSE\n WRITE( 6, \"( /, ' Quartic ' )\" )\n CALL ROOTS_solve( A( 0 : order ), tol, nroots, &\n ROOTS( : order ), status )\n END IF\n END IF\n IF ( nroots == 0 ) THEN\n WRITE( 6, \"( ' no real roots ' )\" )\n ELSE IF ( nroots == 1 ) THEN\n WRITE( 6, \"( ' 1 real root ' )\" )\n ELSE IF ( nroots == 2 ) THEN\n WRITE( 6, \"( ' 2 real roots ' )\" )\n ELSE IF ( nroots == 3 ) THEN\n WRITE( 6, \"( ' 3 real roots ' )\" )\n ELSE IF ( nroots == 4 ) THEN\n WRITE( 6, \"( ' 4 real roots ' )\" )\n END IF\n IF ( nroots /= 0 ) WRITE( 6, \"( ' roots: ', 4ES12.4 )\" ) ROOTS( : nroots )\n \n END DO\n END DO\n\n! Test for error exits\n\n WRITE(6,\"( /, ' Tests for error exits ' )\" )\n A1( 0 : 4 ) = A ; A1( 5 ) = 1.0_wp\n CALL ROOTS_solve( A1, tol, nroots, ROOTS, status )\n WRITE(6,\"( ' Test 3: exit status ', I0 )\" ) status\n A2 = A( 0 : 2 )\n CALL ROOTS_solve( A2, tol, nroots, ROOTS2, status )\n WRITE(6,\"( ' Test 4: exit status ', I0 )\" ) status\n\n STOP\n\n END PROGRAM GALAHAD_ROOTS_test_deck\n\n", "meta": {"hexsha": "e961d0e732531b2cbf99ffdb3daa218b2746e687", "size": 3457, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "legacy_fortran/galahad-2.3/src/roots/rootst.f90", "max_stars_repo_name": "dynamics-of-stellar-systems/dynamite_release", "max_stars_repo_head_hexsha": "a921d8a1bde98f48daeea78213fb17b3edb223bb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-10-14T12:22:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-31T15:32:59.000Z", "max_issues_repo_path": "legacy_fortran/galahad-2.3/src/roots/rootst.f90", "max_issues_repo_name": "dynamics-of-stellar-systems/dynamite_release", "max_issues_repo_head_hexsha": "a921d8a1bde98f48daeea78213fb17b3edb223bb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2022-02-25T16:05:40.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T15:15:16.000Z", "max_forks_repo_path": "legacy_fortran/galahad-2.3/src/roots/rootst.f90", "max_forks_repo_name": "dynamics-of-stellar-systems/dynamite", "max_forks_repo_head_hexsha": "5ccf936e4b1cd907db8dd7070d4ad204ed913337", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-11-04T04:36:40.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-01T01:07:38.000Z", "avg_line_length": 33.8921568627, "max_line_length": 81, "alphanum_fraction": 0.4162568701, "num_tokens": 1253, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835289107309, "lm_q2_score": 0.798186787341014, "lm_q1q2_score": 0.6668719138175895}} {"text": "real(kind=dp) function apfun(Peclet)\n\nuse kind_parameters\nimplicit none\n\n! Calculating Ap using Power law scheme\n\nreal(kind=dp):: Peclet\n\nPeclet = 1.0d0-0.1d0*dabs(Peclet)\n!\napfun = max(0.0d0, (Peclet*Peclet*Peclet*Peclet*Peclet))\n!apfun = max(0.0d0, 1.0d0 -0.50d0*dabs(Peclet))\nend function\n", "meta": {"hexsha": "cbd52ca90a1a397f12f06a187a4f8ce190aa1e8f", "size": 292, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "apfun.f90", "max_stars_repo_name": "pratanuroy/Multigrid_Cavity", "max_stars_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-09-11T12:01:52.000Z", "max_stars_repo_stars_event_max_datetime": "2017-09-11T12:01:52.000Z", "max_issues_repo_path": "apfun.f90", "max_issues_repo_name": "pratanuroy/Multigrid_Cavity", "max_issues_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "apfun.f90", "max_forks_repo_name": "pratanuroy/Multigrid_Cavity", "max_forks_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.4666666667, "max_line_length": 56, "alphanum_fraction": 0.7363013699, "num_tokens": 125, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9046505453836382, "lm_q2_score": 0.7371581568543043, "lm_q1q2_score": 0.6668705286322439}} {"text": "! *********************************************************************\r\n! * *\r\n! * function dcvab2 *\r\n! * *\r\n! *********************************************************************\r\n! Double Precision Version 1.6\r\n! Written by Gordon A. Fenton, TUNS, July 17, 1992\r\n! Latest Update: Apr 8, 2003\r\n!\r\n! PURPOSE returns the covariance between two 2-D local averages, one\r\n! having four times the area of the other. Used by LAS2G.\r\n!\r\n! This function evaluates the covariance between two local averages in\r\n! 2-dimensional space. One local average is assumed to be of size Dx x Dy\r\n! and the other of size 2*Dx x 2*Dy and they are separated in space by\r\n! a central distance having components Tx=C1*Dx and Ty=C2*Dy.\r\n!\r\n! The covariance is obtained by a 16-pt Gaussian quadrature of a\r\n! 4-D integral collapsed (by assuming the covariance function to be\r\n! quadrant symmetric) to a 2-D integral.\r\n! NOTE: if the covariance function is not quadrant symmetric, this\r\n! routine will return erroneous results. Quadrant symmetry means\r\n! that cov(X,Y) = cov(-X,Y) = cov(X,-Y) = cov(-X,-Y), where\r\n! cov(.,.) is the function returning the covariance between\r\n! points separated by lag (X,Y), as discussed next.\r\n!\r\n! The covariance function is referenced herein using a call of the\r\n! form\r\n!\r\n! V = cov( X, Y )\r\n!\r\n! where X and Y are the lag distances between the points in the field.\r\n!\r\n! Arguments to this function are as follows\r\n!\r\n! cov external covariance function provided by the user.\r\n!\r\n! Dx x-dimension of the smaller local average. (input)\r\n!\r\n! Dy y-dimension of the smaller local average. (input)\r\n!\r\n! C1 x-direction distance between local average centers is C1*Dx.\r\n! (input)\r\n!\r\n! C2 y-direction distance between local average centers is C2*Dy.\r\n! (input)\r\n!\r\n! REVISION HISTORY:\r\n! 1.1\teliminated unused local variable `zero' (Dec 5/96)\r\n! 1.2\tnow including a Gaussian Quadrature integration option as an\r\n!\talternative to the variance function approach to evaluate\r\n!\tcovariances between local averages. Added `zero' back. (Jun 16/00)\r\n! 1.3\tnow choose between Gauss Quadrature and var function approaches\r\n!\tto minimize numerical errors. Eliminated lvarfn. (Mar 27/01)\r\n! 1.4\tuse Gauss quadrature unless intervals overlap (Apr 5/01)\r\n! 1.5\tuse Gauss quadrature for everything (Apr 16/01)\r\n! 1.51\tremoved unused abs statement function (Sep 21/01)\r\n! 1.6\tnow use 16-pt Gauss quadrature for increased accuracy (Apr 8/02)\r\n!---------------------------------------------------------------------------\r\n real*8 function dcvab2( cov, Dx, Dy, C1, C2 )\r\n parameter (NG = 16)\r\n implicit real*8 (a-h,o-z)\r\n dimension w(NG), z(NG)\r\n\r\n external cov\r\n\r\n data zero/0.d0/, sxt4th/0.015625d0/, quart/0.25d0/, half/0.5d0/\r\n data one/1.d0/, onept5/1.5d0/, two/2.d0/\r\n\r\n!\t\t\tthese are for NG = 3\r\n! data w/0.555555555555556d0,.888888888888889d0,.555555555555556d0/\r\n! data z/-.774596669241483d0,.000000000000000d0,.774596669241483d0/\r\n\r\n!\t\t\tand these are for NG = 5\r\n! data w/ .236926885056189d0,.478628670499366d0,.568888888888889d0,\r\n! > .478628670499366d0,.236926885056189d0/\r\n! data z/-.906179845938664d0,-.538469310105683d0,.000000000000000d0,\r\n! > .538469310105683d0, .906179845938664d0/\r\n!\t\t\tthese are for NG = 16\r\n data w/0.027152459411754094852d0, 0.062253523938647892863d0, &\r\n 0.095158511682492784810d0, 0.124628971255533872052d0, &\r\n 0.149595988816576732081d0, 0.169156519395002538189d0, &\r\n 0.182603415044923588867d0, 0.189450610455068496285d0, &\r\n 0.189450610455068496285d0, 0.182603415044923588867d0, &\r\n 0.169156519395002538189d0, 0.149595988816576732081d0, &\r\n 0.124628971255533872052d0, 0.095158511682492784810d0, &\r\n 0.062253523938647892863d0, 0.027152459411754094852d0/ \r\n data z/-.989400934991649932596d0, -.944575023073232576078d0, &\r\n -.865631202387831743880d0, -.755404408355003033895d0, &\r\n -.617876244402643748447d0, -.458016777657227386342d0, &\r\n -.281603550779258913230d0, -.095012509837637440185d0, &\r\n 0.095012509837637440185d0, 0.281603550779258913230d0, &\r\n 0.458016777657227386342d0, 0.617876244402643748447d0, &\r\n 0.755404408355003033895d0, 0.865631202387831743880d0, &\r\n 0.944575023073232576078d0, 0.989400934991649932596d0/ \r\n\r\n\r\n!\t\t\t\t\toverlapping areas, GQ simplifies\r\n!\t\t\t\t\tto variance of larger area\r\n if( (C1 .lt. onept5) .and. (C2 .lt. onept5) ) then\r\n d1 = zero\r\n do 20 i = 1, NG\r\n xi = Dx*(one + z(i))\r\n d2 = zero\r\n do 10 j = 1, NG\r\n yi = Dy*(one + z(j))\r\n d2 = d2 + w(j)*(one-z(j))*cov(xi,yi)\r\n 10 continue\r\n d1 = d1 + w(i)*(one-z(i))*d2\r\n 20 continue\r\n dcvab2 = quart*d1\r\n return\r\n endif\r\n!\t\t\t\t\totherwise, non-overlapping areas\r\n r1 = half*Dx\r\n r2 = half*Dy\r\n s2 = two*C1\r\n s1 = s2 - two\r\n s3 = s2 + two\r\n v2 = two*C2\r\n v1 = v2 - two\r\n v3 = v2 + two\r\n d1 = zero\r\n do 40 i = 1, NG\r\n xi1 = r1*(z(i) + s1)\r\n xi2 = r1*(z(i) + s2)\r\n xi3 = r1*(z(i) + s3)\r\n d21 = zero\r\n d22 = zero\r\n d23 = zero\r\n do 30 j = 1, NG\r\n yj1 = r2*(z(j) + v1)\r\n yj2 = r2*(z(j) + v2)\r\n yj3 = r2*(z(j) + v3)\r\n dz1 = one + z(j)\r\n dz2 = one - z(j)\r\n d21 = d21 + w(j)*(dz1*cov(xi1,yj1) + two*cov(xi1,yj2) &\r\n +dz2*cov(xi1,yj3))\r\n d22 = d22 + w(j)*(dz1*cov(xi2,yj1) + two*cov(xi2,yj2) &\r\n +dz2*cov(xi2,yj3))\r\n d23 = d23 + w(j)*(dz1*cov(xi3,yj1) + two*cov(xi3,yj2) &\r\n +dz2*cov(xi3,yj3))\r\n 30 continue\r\n d1 = d1 + w(i)*((one+z(i))*d21 + two*d22 + (one-z(i))*d23)\r\n 40 continue\r\n dcvab2 = sxt4th*d1\r\n\r\n return\r\n end\r\n", "meta": {"hexsha": "ee4422e8cff595b8ace4169fe2a6cc616866394e", "size": 6386, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/libs/gaf95/dcvab2.f95", "max_stars_repo_name": "leemargetts/PoreFEM", "max_stars_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/libs/gaf95/dcvab2.f95", "max_issues_repo_name": "leemargetts/PoreFEM", "max_issues_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/libs/gaf95/dcvab2.f95", "max_forks_repo_name": "leemargetts/PoreFEM", "max_forks_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.5733333333, "max_line_length": 77, "alphanum_fraction": 0.5513623552, "num_tokens": 2040, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505248181417, "lm_q2_score": 0.7371581568543044, "lm_q1q2_score": 0.6668705134722205}} {"text": "!----------------- BEGIN CL68_INTEGRAND -----------------------------\n function cl68_integrand(z)\n! Dates: 06/09/95 - Written by D.M. Boore. See 7/11/82 notes for\n! stochastic model, with 6/9/95 addition that uses\n! a variable transformation to remove the sqrt\n! singularity at the origin.\n! 01/03/95 - Name changed from cl_int to cl68_integrand\n! 02/05/00 - Made changes suggested by C. Mueller to avoid\n! possible numerical problem when \"an\" is large\n\n common /clint/ xi, an\n! real*8 y, dum\n\n! dum = 1.0d0-xi*dexp(-z**2)\n! y = an * dlog(dum) ! Mueller modification\n! if (y .lt. -10.0d0**(-10)) then !based on machine epsilon for dble precsn\n! cl68_integrand = 0.0 ! or could let compiler deal with underflow\n! else\n! cl68_integrand = 2.0*(1.0d0-dexp(y)) ! Mueller modification\n! end if\n\n y = an * alog(1.0-xi*exp(-z**2)) ! Mueller modification\n cl68_integrand = 2.0*(1.0-exp(y)) ! Mueller modification\n\n! cl68_integrand = 2.0*(1.0-(1.0-xi*exp(-z**2))**an) ! original\n\n return\n end\n!----------------- END CL68_INTEGRAND -----------------------------\n", "meta": {"hexsha": "961d76d54f41324d4bb333858dce3b17741d962e", "size": 1225, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "FlaPyDisaster/Documentation/Earthquake/Boore/smsim6.20/cl68_integrand.for", "max_stars_repo_name": "cliftbar/FlaPyDisaster", "max_stars_repo_head_hexsha": "ff9bbc97bedd9540b3c49050f6e29489f3ecdc13", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2017-09-21T06:49:51.000Z", "max_stars_repo_stars_event_max_datetime": "2018-05-16T01:27:21.000Z", "max_issues_repo_path": "FlaPyDisaster/Documentation/Earthquake/Boore/smsim6.20/cl68_integrand.for", "max_issues_repo_name": "cliftbar/FlaPyDisaster", "max_issues_repo_head_hexsha": "ff9bbc97bedd9540b3c49050f6e29489f3ecdc13", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-12-11T20:14:02.000Z", "max_issues_repo_issues_event_max_datetime": "2017-12-11T20:14:02.000Z", "max_forks_repo_path": "FlaPyDisaster/Documentation/Earthquake/Boore/smsim6.20/cl68_integrand.for", "max_forks_repo_name": "cliftbar/FlaPyDisaster", "max_forks_repo_head_hexsha": "ff9bbc97bedd9540b3c49050f6e29489f3ecdc13", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-04-05T17:24:26.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-09T03:19:30.000Z", "avg_line_length": 40.8333333333, "max_line_length": 80, "alphanum_fraction": 0.5453061224, "num_tokens": 380, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.936285002192296, "lm_q2_score": 0.7122321964553657, "lm_q1q2_score": 0.666852323619636}} {"text": " subroutine sir(S, I, R, beta, gamma, dt)\n implicit none\n double precision S, I, R, beta, gamma, dt\n double precision infected, recovered\n\n infected = (-(beta*S*I) / (S + I + R)) * dt\n recovered = (gamma*I) * dt\n\n S = S - infected\n I = I + infected - recovered\n R = R + recovered\n end subroutine sir\n\nC program main\nC double precision, parameter :: S0 = 500, I0 = 10, R0 = 0\nC double precision, parameter :: beta = 0.5, gamma = 0.3, t = 1\nC\nC call sir(S0, I0, R0, beta, gamma, t)\nC end program main", "meta": {"hexsha": "24e2ecca55395b4a2acd60f1a31ac9058053716b", "size": 589, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/data/program_analysis/SIR-simple.f", "max_stars_repo_name": "mwdchang/delphi", "max_stars_repo_head_hexsha": "c6177f2d614118883eaaa7f5300f3e46f10ddc7e", "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/program_analysis/SIR-simple.f", "max_issues_repo_name": "mwdchang/delphi", "max_issues_repo_head_hexsha": "c6177f2d614118883eaaa7f5300f3e46f10ddc7e", "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/program_analysis/SIR-simple.f", "max_forks_repo_name": "mwdchang/delphi", "max_forks_repo_head_hexsha": "c6177f2d614118883eaaa7f5300f3e46f10ddc7e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-07-18T19:13:13.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-18T19:13:13.000Z", "avg_line_length": 31.0, "max_line_length": 68, "alphanum_fraction": 0.544991511, "num_tokens": 181, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850057480346, "lm_q2_score": 0.7122321903471563, "lm_q1q2_score": 0.6668523204331226}} {"text": " subroutine Gaussmesh()\n use vaphfb_par\n implicit none\n\n integer k\n real*8 xxbet(AMP%NLEG_BET)\n!+---------------------------------------------------------------------+\n! Gauss-Legendre integration points and weights |\n!+---------------------------------------------------------------------+\n! 2*pi*2*pi*2 = 8*pi**2\n! wwalp,wwbet,wwgam are defined in the above regions\n! .....................................................................\n\n if(.NOT. ALLOCATED(sdjmk)) &\n & ALLOCATE(sdjmk(0:AMP%jjmax,0:AMP%jjmax*2,0:AMP%jjmax*2,0:AMP%NLEG_BET,0:1))\n\n if(AMP%NLEG_ALP.lt. 0 .or. AMP%NLEG_BET.lt. 0 .or. AMP%NLEG_GAM.lt. 0) &\n & stop ' Mesh points in Euler angles are not set properly '\n\n if(.NOT. ALLOCATED(AMP%alpha)) ALLOCATE(AMP%alpha(1:AMP%NLEG_ALP))\n if(.NOT. ALLOCATED(AMP%beta)) ALLOCATE(AMP%beta(1:AMP%NLEG_BET))\n if(.NOT. ALLOCATED(AMP%gamma)) ALLOCATE(AMP%gamma(1:AMP%NLEG_GAM))\n if(.NOT. ALLOCATED(AMP%wwalp)) ALLOCATE(AMP%wwalp(1:AMP%NLEG_ALP))\n if(.NOT. ALLOCATED(AMP%wwbet)) ALLOCATE(AMP%wwbet(1:AMP%NLEG_BET))\n if(.NOT. ALLOCATED(AMP%wwgam)) ALLOCATE(AMP%wwgam(1:AMP%NLEG_GAM))\n! ...........Gauss-Legendre integration points and weights \n call gauleg(0.d0,2*pi, AMP%alpha,AMP%wwalp,AMP%NLEG_ALP)\n call gauleg(-1.d0,1.d0,xxbet,AMP%wwbet,AMP%NLEG_BET)\n call gauleg(0.d0,2*pi, AMP%gamma,AMP%wwgam,AMP%NLEG_GAM)\n\n do k=1,AMP%NLEG_BET\n AMP%beta(k) = dacos(xxbet(k))\n end do\n! ......................... a special case\n if(AMP%NLEG_ALP .eq. 1) then\n AMP%alpha(1)=0.d0\n AMP%wwalp(1) =1.d0\n endif\n if(AMP%NLEG_BET.eq. 1) then\n AMP%beta(1) =0.d0\n AMP%wwbet(1) =1.d0\n endif\n if(AMP%NLEG_GAM .eq. 1) then\n AMP%gamma(1)=0.d0\n AMP%wwgam(1) =1.d0\n endif\n\n! if(.NOT. ALLOCATED(ieuler_ang)) &\n! & ALLOCATE(ieuler_ang(1:AMP%NLEG_ALP,1:AMP%NLEG_BET,1:AMP%NLEG_GAM))\n! NNLEG_ALP=NLEG_ALP\n! NNLEG_BET=NLEG_BET\n! NNLEG_GAM=NLEG_GAM\n!\n! ..........................\n! do J=0,JJmax\n! weightJ(J) = (2.d0*J+1.d0)/2.d0 !(8.d0*pi) \n! enddo\n! .........................\n return\n end\n", "meta": {"hexsha": "f54957f2d01f05ca458a3c0b85ffbb6540c521dd", "size": 2337, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Codes/GCM/PNAMP_Gaus.f90", "max_stars_repo_name": "jmyao17/SCCM", "max_stars_repo_head_hexsha": "16e31afa313bf70741c152d859aa837935110776", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Codes/GCM/PNAMP_Gaus.f90", "max_issues_repo_name": "jmyao17/SCCM", "max_issues_repo_head_hexsha": "16e31afa313bf70741c152d859aa837935110776", "max_issues_repo_licenses": ["MIT"], "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/GCM/PNAMP_Gaus.f90", "max_forks_repo_name": "jmyao17/SCCM", "max_forks_repo_head_hexsha": "16e31afa313bf70741c152d859aa837935110776", "max_forks_repo_licenses": ["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.3114754098, "max_line_length": 85, "alphanum_fraction": 0.5002139495, "num_tokens": 828, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.936285002192296, "lm_q2_score": 0.7122321781307374, "lm_q1q2_score": 0.6668523064625612}} {"text": "program lib92_quad\n use, intrinsic :: iso_fortran_env, only: real64, dp => real64\n implicit none\n\n call setup\n call runtest\n\ncontains\n\n subroutine runtest\n use parameter_def\n use grid_C\n use tatb_C\n use quad_I\n\n real*8 :: real64_kind_\n integer, parameter :: real64 = kind(real64_kind_)\n integer, parameter :: dp = real64\n\n integer :: i\n real(real64) :: result\n\n ! Integrate exp(-2x) from 0 to infinity. Expected result is 1/2.\n do i = 1, NNN1\n TA(i) = exp(-2*R(i)) * RP(i)\n end do\n call quad(result)\n\n print *, \"RESULT from QUAD\", result\n print *, \"expected \", 0.5_dp\n print *, \"difference \", abs(result - 0.5_dp)\n\n if(abs(result - 0.5_dp) > 1e-12_dp) then\n stop 1\n end if\n end subroutine runtest\n\n subroutine setup\n use parameter_def\n use grid_C\n use tatb_C\n use setqic_I\n use radgrd_I\n\n H = 5.0D-2\n RNT = 2.0D-6\n HP = 0.0D0\n N = NNNP\n MTP = NNNP\n\n call setqic\n call radgrd\n end subroutine setup\n\nend program lib92_quad\n", "meta": {"hexsha": "29046d2d49b7fda35577a41ba237a318ce6b6267", "size": 1189, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/lib92_quad.f90", "max_stars_repo_name": "compas/grasp-rci-qed", "max_stars_repo_head_hexsha": "11b0043488a352f11c6332f3ffd73a5b7d65cdde", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-05-07T01:19:42.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-07T01:19:42.000Z", "max_issues_repo_path": "test/lib92_quad.f90", "max_issues_repo_name": "compas/grasp-rci-qed", "max_issues_repo_head_hexsha": "11b0043488a352f11c6332f3ffd73a5b7d65cdde", "max_issues_repo_licenses": ["MIT"], "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/lib92_quad.f90", "max_forks_repo_name": "compas/grasp-rci-qed", "max_forks_repo_head_hexsha": "11b0043488a352f11c6332f3ffd73a5b7d65cdde", "max_forks_repo_licenses": ["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.2321428571, "max_line_length": 72, "alphanum_fraction": 0.5374264087, "num_tokens": 351, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736772, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6668200729821923}} {"text": "!=========================================================================================\n!Copyright (c) 2009, The Regents of the University of Massachusetts, Amherst.\n!Developed by E. Polizzi\n!All rights reserved.\n!\n!Redistribution and use in source and binary forms, with or without modification, \n!are permitted provided that the following conditions are met:\n!\n!1. Redistributions of source code must retain the above copyright notice, this list of conditions \n! and the following disclaimer.\n!2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions \n! and the following disclaimer in the documentation and/or other materials provided with the distribution.\n!3. Neither the name of the University nor the names of its contributors may be used to endorse or promote\n! products derived from this software without specific prior written permission.\n!\n!THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, \n!BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE \n!ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, \n!EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR \n!SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF \n!LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING \n!IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n!==========================================================================================\n\n\n\n\n\nsubroutine sset_point_gauss_legendre(nbe,e,xe,we)\n ! Purpose \n ! =======\n ! GAUSS-LEGENDRE Quadrature ROUTINE- Return weight and coordinate of the e^th node from nbe total # nodes\n ! \n ! SINGLE PRECISION version \n !\n ! Arguments\n ! =========\n !\n ! nbe (input) INTEGER: total # nodes for Gauss quadrature\n ! e (input) INTEGER: e^th node\n ! xe (output) REAL SINGLE PRECISION: Gauss coordinate for node e \n ! we (output) REAL SINGLE PRECISION: Gauss weight for node e\n !=====================================================================\n ! Eric Polizzi 2009\n ! ====================================================================\n implicit none\n integer :: nbe,e\n real :: xe,we\n!!!!!!!!!!\n double precision ::dxe,dwe\n\n dxe=dble(xe)\n dwe=dble(we)\n\n call dset_point_gauss_legendre(nbe,e,dxe,dwe)\n\n xe=real(dxe)\n we=real(dwe)\n\nend subroutine sset_point_gauss_legendre\n\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\nsubroutine dset_point_gauss_legendre(nbe,e,xe,we)\n ! Purpose \n ! =======\n ! GAUSS-LEGENDRE Quadrature ROUTINE- Return weight and coordinate of the e^th node from nbe total # nodes\n ! \n ! DOUBLE PRECISION version \n !\n ! Arguments\n ! =========\n !\n ! nbe (input) INTEGER: total # nodes for Gauss quadrature\n ! e (input) INTEGER: e^th node\n ! xe (output) REAL DOUBLE PRECISION: Gauss coordinate for node e \n ! we (output) REAL DOUBLE PRECISION: Gauss weight for node e\n !=====================================================================\n ! Eric Polizzi 2009\n ! ====================================================================\n implicit none\n integer :: nbe,e\n double precision :: xe,we\n!!!!!!!!!!\n\n !! nbe=3\n select case(nbe)\n\n case(3)\n\n select case(e)\n case(1)\n we=8.0d0/9.0d0\n xe=0.0d0\n case(2)\n we=5.0d0/9.0d0\n xe=sqrt(3.0d0/5.0d0)\n case(3)\n we=5.0d0/9.0d0 \n xe=-sqrt(3.0d0/5.0d0)\n end select\n\n case(4)\n\n select case(e)\n\n case(1,2)\n we=(18.0d0+sqrt(30.0d0))/36.0d0\n !6.52145154862546142644d-01\n xe=sqrt((3.0d0-2.0d0*sqrt(6.0d0/5.0d0))/7.0d0)\n !3.39981043584856264792d-01\n case(3,4)\n we=(18.0d0-sqrt(30.0d0))/36.0d0\n ! 3.47854845137453857383d-01\n xe=sqrt((3.0d0+2.0d0*sqrt(6.0d0/5.0d0))/7.0d0)\n !8.61136311594052575248d-01\n\n end select\n\n if (ibclr(e,0)==e) xe=-xe\n\n\n case(5)\n\n select case(e)\n case(1)\n we=128.0d0/225.0d0\n xe=0.0d0\n case(2,3)\n ! we=9.06179845938663992811d-01\n we=(322.0d0+13.0d0*sqrt(70.0d0))/900.0d0\n ! xe= 5.38469310105683091018d-01 \n xe=(1.0d0/3.0d0)*sqrt(5.0d0-2.0d0*sqrt(10.0d0/7.0d0))\n if (e==3) xe=-xe\n case(4,5)\n ! we=2.36926885056189087515d-01\n we=(322.0d0-13.0d0*sqrt(70.0d0))/900.0d0\n ! xe=9.06179845938663992811d-01\n xe=(1.0d0/3.0d0)*sqrt(5.0d0+2.0d0*sqrt(10.0d0/7.0d0))\n if (e==5) xe=-xe\n end select\n\n\n\n\n\n case(6)\n\n\n select case(e)\n case(1,2)\n xe=6.61209386466264513688d-01\n we= 3.60761573048138607569d-01\n case(3,4)\n xe=2.38619186083196908630d-01\n we=4.67913934572691047389d-01\n case(5,6)\n xe=9.32469514203152027832d-01\n we=1.71324492379170345043d-01\n end select\n\n if (ibclr(e,0)==e) xe=-xe\n\n\n\n\n case(8)\n\n\n select case(e)\n case(1,2)\n xe=1.83434642495649804936d-01\n we=3.62683783378361982976d-01\n case(3,4)\n xe=5.25532409916328985830d-01\n we=3.13706645877887287338d-01\n case(5,6)\n xe=7.96666477413626739567d-01\n we=2.22381034453374470546d-01\n case(7,8)\n xe=9.60289856497536231661d-01\n we=1.01228536290376259154d-01\n end select\n\n if (ibclr(e,0)==e) xe=-xe\n\n case(10)\n\n select case(e)\n case(1,2)\n we=2.95524224714752870187d-01\n xe=1.48874338981631210881d-01\n case(3,4)\n we=2.69266719309996355105d-01\n xe=4.33395394129247190794d-01\n case(5,6)\n we=2.19086362515982044000d-01\n xe=6.79409568299024406207d-01\n case(7,8)\n we=1.49451349150580593150d-01\n xe=8.65063366688984510759d-01\n case(9,10)\n we=6.66713443086881375920d-02\n xe=9.73906528517171720066d-01\n end select\n\n if (ibclr(e,0)==e) xe=-xe\n\n\n case(12)\n\n select case(e)\n case(1,2)\n we=2.49147045813402785006d-01\n xe=1.25233408511468915478d-01\n case(3,4)\n we=2.33492536538354808758d-01\n xe=3.67831498998180193757d-01\n case(5,6)\n we=2.03167426723065921743d-01\n xe=5.87317954286617447312d-01\n case(7,8)\n we=1.60078328543346226338d-01\n xe=7.69902674194304687059d-01\n case(9,10)\n we=1.06939325995318430960d-01\n xe=9.04117256370474856682d-01\n case(11,12)\n we=4.71753363865118271952d-02\n xe=9.81560634246719250712d-01\n\n\n end select\n\n if (ibclr(e,0)==e) xe=-xe\n\n\n\n\n case(16)\n\n\n select case(e)\n case(1,2)\n we=1.89450610455068496287d-01\n xe=9.50125098376374401877d-02\n case(3,4)\n we=1.82603415044923588872d-01\n xe=2.81603550779258913231d-01\n case(5,6)\n we=1.69156519395002538183d-01\n xe=4.58016777657227386350d-01\n case(7,8)\n we=1.49595988816576732080d-01\n xe=6.17876244402643748452d-01\n case(9,10)\n we=1.24628971255533872056d-01\n xe=7.55404408355003033891d-01\n case(11,12)\n we=9.51585116824927848073d-02\n xe=8.65631202387831743866d-01\n case(13,14)\n we=6.22535239386478928628d-02\n xe=9.44575023073232576090d-01\n case(15,16)\n we=2.71524594117540948514d-02\n xe=9.89400934991649932601d-01\n end select\n\n if (ibclr(e,0)==e) xe=-xe\n\n\n\n case(20)\n\n\n select case(e)\n case(1,2)\n we=1.52753387130725850699d-01\n xe=7.65265211334973337513d-02\n case(3,4)\n we=1.49172986472603746785d-01\n xe=2.27785851141645078076d-01\n case(5,6)\n we=1.42096109318382051326d-01\n xe=3.73706088715419560662d-01\n case(7,8)\n we=1.31688638449176626902d-01\n xe=5.10867001950827097985d-01\n case(9,10)\n we=1.18194531961518417310d-01\n xe=6.36053680726515025467d-01 \n case(11,12)\n we=1.01930119817240435039d-01\n xe=7.46331906460150792634d-01\n case(13,14)\n we=8.32767415767047487264d-02\n xe=8.39116971822218823420d-01 \n case(15,16)\n we=6.26720483341090635663d-02\n xe=9.12234428251325905857d-01\n case(17,18)\n we=4.06014298003869413320d-02 \n xe=9.63971927277913791287d-01\n case(19,20)\n we=1.76140071391521183115d-02\n xe=9.93128599185094924776d-01\n\n end select\n\n if (ibclr(e,0)==e) xe=-xe\n\n\n\n\n case(24)\n\n\n select case(e)\n case(1,2)\n we=1.27938195346752156976d-01\n xe=6.40568928626056260827d-02\n case(3,4)\n we=1.25837456346828296117d-01\n xe=1.91118867473616309153d-01\n case(5,6)\n we=1.21670472927803391202d-01\n xe=3.15042679696163374398d-01\n case(7,8)\n we=1.15505668053725601353d-01\n xe=4.33793507626045138478d-01\n case(9,10)\n we=1.07444270115965634785d-01\n xe=5.45421471388839535649d-01\n case(11,12)\n we=9.76186521041138882720d-02\n xe=6.48093651936975569268d-01\n case(13,14)\n we=8.61901615319532759152d-02\n xe=7.40124191578554364260d-01\n case(15,16)\n we=7.33464814110803057346d-02\n xe=8.20001985973902921981d-01\n case(17,18)\n we=5.92985849154367807461d-02\n xe=8.86415527004401034190d-01\n case(19,20)\n we=4.42774388174198061695d-02\n xe=9.38274552002732758539d-01\n case(21,22)\n we=2.85313886289336631809d-02\n xe=9.74728555971309498199d-01\n case(23,24)\n we=1.23412297999871995469d-02\n xe=9.95187219997021360195d-01\n end select\n\n if (ibclr(e,0)==e) xe=-xe\n\n\n case(32)\n\n\n select case(e)\n case(1,2)\n we=9.65400885147278005666d-02\n xe=4.83076656877383162364d-02\n case(3,4)\n we=9.56387200792748594185d-02\n xe=1.44471961582796493484d-01\n case(5,6)\n we=9.38443990808045656367d-02\n xe=2.39287362252137074544d-01\n case(7,8)\n we=9.11738786957638847129d-02\n xe=3.31868602282127649782d-01\n case(9,10)\n we=8.76520930044038111450d-02\n xe=4.21351276130635345353d-01\n case(11,12)\n we=8.33119242269467552223d-02\n xe=5.06899908932229390044d-01\n case(13,14)\n we=7.81938957870703064685d-02\n xe=5.87715757240762329066d-01\n case(15,16)\n we=7.23457941088485062287d-02\n xe=6.63044266930215200960d-01\n case(17,18)\n we=6.58222227763618468406d-02\n xe=7.32182118740289680412d-01\n case(19,20)\n we=5.86840934785355471448d-02\n xe=7.94483795967942406965d-01\n case(21,22)\n we=5.09980592623761761959d-02\n xe=8.49367613732569970160d-01\n case(23,24)\n we=4.28358980222266806557d-02\n xe=8.96321155766052123971d-01\n case(25,26)\n we=3.42738629130214331033d-02\n xe=9.34906075937739689159d-01\n case(27,28)\n we=2.53920653092620594561d-02\n xe=9.64762255587506430761d-01\n case(29,30)\n we=1.62743947309056706058d-02\n xe=9.85611511545268335400d-01\n case(31,32)\n we=7.01861000947009660028d-03\n xe=9.97263861849481563534d-01\n end select\n\n if (ibclr(e,0)==e) xe=-xe\n\n\n\n\n\n case(40)\n\n select case(e)\n case(1,2)\n we=7.75059479784248112668d-02\n xe=3.87724175060508219329d-02\n case(3,4)\n we=7.70398181642479655914d-02\n xe=1.16084070675255208481d-01\n case(5,6)\n we=7.61103619006262423723d-02\n xe=1.92697580701371099719d-01\n case(7,8)\n we=7.47231690579682641980d-02\n xe=2.68152185007253681152d-01\n case(9,10)\n we=7.28865823958040590609d-02\n xe=3.41994090825758473008d-01\n case(11,12)\n we=7.06116473912867796979d-02\n xe=4.13779204371605001525d-01\n case(13,14)\n we=6.79120458152339038265d-02\n xe=4.83075801686178712903d-01\n case(15,16)\n we=6.48040134566010380719d-02\n xe=5.49467125095128202056d-01\n case(17,18)\n we=6.13062424929289391679d-02 \n xe=6.12553889667980237972d-01\n case(19,20)\n we=5.74397690993915513665d-02\n xe=6.71956684614179548364d-01\n case(21,22)\n we=5.32278469839368243566d-02\n xe=7.27318255189927103277d-01\n case(23,24)\n we=4.86958076350722320604d-02\n xe=7.78305651426519387712d-01\n case(25,26)\n we=4.38709081856732719923d-02\n xe=8.24612230833311663197d-01\n case(27,28)\n we=3.87821679744720176413d-02\n xe=8.65959503212259503824d-01\n case(29,30)\n we=3.34601952825478473933d-02\n xe=9.02098806968874296732d-01\n case(31,32)\n we=2.79370069800234010984d-02\n xe=9.32812808278676533383d-01\n case(33,34)\n we=2.22458491941669572615d-02\n xe=9.57916819213791655824d-01\n case(35,36)\n we=1.64210583819078887131d-02\n xe=9.77259949983774262679d-01\n case(37,38)\n xe=9.90726238699457006464d-01\n we=1.04982845311528136146d-02\n case(39,40)\n we=4.52127709853319125846d-03\n xe=9.98237709710559200369d-01\n end select\n\n if (ibclr(e,0)==e) xe=-xe\n\n\n\n case(48)\n\n\n select case(e)\n case(1,2)\n we=6.47376968126839225006d-02\n xe=3.23801709628693620343d-02\n case(3,4)\n we=6.44661644359500822082d-02\n xe=9.70046992094626989322d-02\n case(5,6)\n we=6.39242385846481866207d-02\n xe=1.61222356068891718055d-01\n case(7,8)\n we=6.31141922862540256548d-02\n xe=2.24763790394689061224d-01\n case(9,10)\n we=6.20394231598926639029d-02\n xe=2.87362487355455576728d-01\n case(11,12)\n we=6.07044391658938800517d-02\n xe=3.48755886292160738148d-01\n case(13,14)\n we=5.91148396983956357477d-02\n xe=4.08686481990716729925d-01\n case(15,16)\n we=5.72772921004032157044d-02\n xe=4.66902904750958404535d-01\n case(17,18)\n we=5.51995036999841628676d-02\n xe=5.23160974722233033658d-01\n case(19,20)\n we=5.28901894851936670964d-02\n xe=5.77224726083972703838d-01\n case(21,22)\n we=5.03590355538544749590d-02\n xe=6.28867396776513624013d-01\n case(23,24)\n we=4.76166584924904748267d-02\n xe=6.77872379632663905208d-01\n case(25,26)\n we=4.46745608566942804201d-02\n xe=7.24034130923814654658d-01\n case(27,28)\n we=4.15450829434647492133d-02\n xe=7.67159032515740339276d-01\n case(29,30)\n we=3.82413510658307063158d-02\n xe=8.07066204029442627087d-01\n case(31,32)\n we=3.47772225647704388909d-02\n xe=8.43588261624393530704d-01\n case(33,34)\n we=3.11672278327980889025d-02\n xe=8.76572020274247885885d-01\n case(35,36)\n we=2.74265097083569482001d-02\n xe=9.05879136715569672805d-01\n case(37,38)\n we=2.35707608393243791410d-02\n xe=9.31386690706554333107d-01\n case(39,40)\n we=1.96161604573555278142d-02\n xe=9.52987703160430860724d-01\n case(41,42)\n we=1.55793157229438487279d-02\n xe=9.70591592546247250472d-01\n case(43,44)\n we=1.14772345792345394895d-02\n xe=9.84124583722826857765d-01\n case(45,46)\n we=7.32755390127626210220d-03\n xe=9.93530172266350757526d-01\n case(47,48)\n we=3.15334605230583863260d-03\n xe=9.98771007252426118580d-01\n\n end select\n\n if (ibclr(e,0)==e) xe=-xe\n\n\n\n end select!!!!!!!!!!!!!!!!!!!!!!! nbe\n\n\nend subroutine dset_point_gauss_legendre\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n\n", "meta": {"hexsha": "1309d787be2816c125dc3ca4ec14e8088ccd3780", "size": 15856, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/feast/point_gauss_legendre.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/feast/point_gauss_legendre.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/feast/point_gauss_legendre.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": 27.1042735043, "max_line_length": 108, "alphanum_fraction": 0.6066473259, "num_tokens": 5994, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357701094304, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.6668200710355429}} {"text": " subroutine r8mkspline(x,nx,fspl,ibcxmin,bcxmin,ibcxmax,bcxmax,\n > ilinx,ier)\nC\nC make a 2-coefficient 1d spline\nC\nC only 2 coefficients, the data and its 2nd derivative, are needed to\nC fully specify a spline. See e.g. Numerical Recipies in Fortran-77\nC (2nd edition) chapter 3, section on cubic splines.\nC\nC input:\n!============\n! idecl: explicitize implicit INTEGER declarations:\n IMPLICIT NONE\n INTEGER, PARAMETER :: R8=SELECTED_REAL_KIND(12,100)\n INTEGER i,inwk\n!============\n! idecl: explicitize implicit REAL declarations:\n REAL*8 bcxmax\n!============\n integer nx ! no. of data points\n REAL*8 x(nx) ! x axis data, strict ascending order\nC\nC input/output:\n REAL*8 fspl(2,nx) ! f(1,*): data in; f(2,*): coeffs out\nC\nC f(1,j) = f(x(j)) on input (unchanged on output)\nC f(2,j) = f''(x(j)) (of interpolating spline) (on output).\nC\nC ...boundary conditions...\nC\nC input:\nC\n integer ibcxmin ! b.c. flag @ x=xmin=x(1)\n REAL*8 bcxmin ! b.c. data @xmin\nC\n integer ibcxmax ! b.c. flag @ x=xmax=x(nx)\n REAL*8 bcxcmax ! b.c. data @xmax\nC\nC ibcxmin=-1 -- periodic boundary condition\nC (bcxmin,ibcxmax,bcxmax are ignored)\nC\nC the output spline s satisfies\nC s'(x(1))=s'(x(nx)) ..and.. s''(x(1))=s''(x(nx))\nC\nC if non-periodic boundary conditions are used, then the xmin and xmax\nC boundary conditions can be specified independently:\nC\nC ibcxmin (ibcxmax) = 0 -- this specifies a \"not a knot\" boundary\nC condition, see \"cubsplb.for\". This is a common way\nC for inferring a \"good\" spline boundary condition\nC automatically from data in the vicinity of the\nC boundary. ... bcxmin (bcxmax) are ignored.\nC\nC ibcxmin (ibcxmax) = 1 -- boundary condition is to have s'(x(1))\nC ( s'(x(nx)) ) match the passed value bcxmin (bcxmax).\nC\nC ibcxmin (ibcxmax) = 2 -- boundary condition is to have s''(x(1))\nC ( s''(x(nx)) ) match the passed value bcxmin (bcxmax).\nC\nC ibcxmin (ibcxmax) = 3 -- boundary condition is to have s'(x(1))=0.0\nC ( s'(x(nx))=0.0 )\nC\nC ibcxmin (ibcxmax) = 4 -- boundary condition is to have s''(x(1))=0.0\nC ( s''(x(nx))=0.0 )\nC\nC ibcxmin (ibcxmax) = 5 -- boundary condition is to have s'(x(1))\nC ( s'(x(nx)) ) match the 1st divided difference\nC e.g. at x(1): d(1)/h(1), where\nC d(j)=f(1,j+1)-f(1,j)\nC h(j)=x(j+1)-x(j)\nC\nC ibcxmin (ibcxmax) = 6 -- BC is to have s''(x(1)) ( s''(x(nx)) )\nC match the 2nd divided difference\nC e.g. at x(1):\nC e(1) = [d(2)/h(2) - d(1)/h(1)]/(0.5*(h(1)+h(2)))\nC\nC ibcxmin (ibcxmax) = 7 -- BC is to have s'''(x(1)) ( s'''(x(nx)) )\nC match the 3rd divided difference\nC e.g. at x(1): [e(2)-e(1)]/(0.33333*(h(1)+h(2)+h(3)))\nC\nC output:\nC\n integer ilinx ! =1: hint, x axis is ~evenly spaced\nC\nC let dx[avg] = (x(nx)-x(1))/(nx-1)\nC let dx[j] = x(j+1)-x(j), for all j satisfying 1.le.j.lt.nx\nC\nC if for all such j, abs(dx[j]-dx[avg]).le.(1.0e-3*dx[avg]) then\nC ilinx=1 is returned, indicating the data is (at least nearly)\nC evenly spaced. Even spacing is useful, for speed of zone lookup,\nC when evaluating a spline.\nC\nC if the even spacing condition is not satisfied, ilinx=2 is returned.\nC\n integer ier ! exit code, 0=OK\nC\nC an error code is returned if the x axis is not strict ascending,\nC or if nx.lt.4, or if an invalid boundary condition specification was\nC input.\nC\nC------------------------------------\nC\nC this routine calls traditional 4 coefficient spline software, and\nC translates the result to 2 coefficient form.\nC\nC this could be done more efficiently but we decided out of conservatism\nC to use the traditional software.\nC\nC------------------------------------\nC workspaces -- f90 dynamically allocated\nC\n REAL*8, dimension(:,:), allocatable :: fspl4 ! traditional 4-spline\n REAL*8, dimension(:), allocatable :: wk ! cspline workspace\nC\nC------------------------------------\nC\n allocate(fspl4(4,nx),wk(nx))\nC\nC make the traditional call\nC\n do i=1,nx\n fspl4(1,i)=fspl(1,i)\n fspl(2,i)=0.0_r8 ! for now\n enddo\nC\n inwk=nx\nC\nC boundary conditions imposed by cspline...\nC\n call r8cspline(x,nx,fspl4,ibcxmin,bcxmin,ibcxmax,bcxmax,\n > wk,inwk,ilinx,ier)\nC\n if(ier.eq.0) then\nC\nC copy the output -- careful of end point.\nC\n do i=1,nx-1\n fspl(2,i)=2.0_r8*fspl4(3,i)\n enddo\n fspl(2,nx)=2.0_r8*fspl4(3,nx-1) +\n > (x(nx)-x(nx-1))*6.0_r8*fspl4(4,nx-1)\n endif\nC\n deallocate(fspl4,wk)\nC\n return\n end\n", "meta": {"hexsha": "21eb4b99f428acbf5aac490e7160d58854018268", "size": 4998, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gfile_Bfield/PSPLINE/Pspline/r8mkspline.f", "max_stars_repo_name": "ORNL-Fusion/RFSciDAC-testing", "max_stars_repo_head_hexsha": "c2fa44e00ce8e0af4be6fa662a9e8c94d6c6f60e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2020-05-08T01:47:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T10:35:28.000Z", "max_issues_repo_path": "gfile_Bfield/PSPLINE/Pspline/r8mkspline.f", "max_issues_repo_name": "ORNL-Fusion/RFSciDAC-testing", "max_issues_repo_head_hexsha": "c2fa44e00ce8e0af4be6fa662a9e8c94d6c6f60e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 77, "max_issues_repo_issues_event_min_datetime": "2020-05-08T07:18:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:20:33.000Z", "max_forks_repo_path": "gfile_Bfield/PSPLINE/Pspline/r8mkspline.f", "max_forks_repo_name": "ORNL-Fusion/RFSciDAC-testing", "max_forks_repo_head_hexsha": "c2fa44e00ce8e0af4be6fa662a9e8c94d6c6f60e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-02-10T13:47:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T12:53:43.000Z", "avg_line_length": 33.7702702703, "max_line_length": 81, "alphanum_fraction": 0.5576230492, "num_tokens": 1628, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736772, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.666820068393173}} {"text": "C * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC * *\nC * copyright (c) 1999 by UCAR *\nC * *\nC * UNIVERSITY CORPORATION for ATMOSPHERIC RESEARCH *\nC * *\nC * all rights reserved *\nC * *\nC * FISHPACK version 4.1 *\nC * *\nC * A PACKAGE OF FORTRAN SUBPROGRAMS FOR THE SOLUTION OF *\nC * *\nC * SEPARABLE ELLIPTIC PARTIAL DIFFERENTIAL EQUATIONS *\nC * *\nC * BY *\nC * *\nC * JOHN ADAMS, PAUL SWARZTRAUBER AND ROLAND SWEET *\nC * *\nC * OF *\nC * *\nC * THE NATIONAL CENTER FOR ATMOSPHERIC RESEARCH *\nC * *\nC * BOULDER, COLORADO (80307) U.S.A. *\nC * *\nC * WHICH IS SPONSORED BY *\nC * *\nC * THE NATIONAL SCIENCE FOUNDATION *\nC * *\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC\nC\nC PROGRAM TO ILLUSTRATE THE USE OF SUBROUTINE HWSCYL TO SOLVE\nC THE EQUATION\nC\nC (1/R)(D/DR)(R*(DU/DR)) + (D/DZ)(DU/DZ)\nC\nC = (2*R*Z)**2*(4*Z**2 + 3*R**2)\nC\nC ON THE RECTANGLE 0 .LT. R .LT. 1, 0 .LT. Z .LT. 1 WITH THE\nC BOUNDARY CONDITIONS\nC\nC U(0,Z) UNSPECIFIED\nC 0 .LE. Z .LE. 1\nC (DU/DR)(1,Z) = 4*Z**4\nC\nC AND\nC\nC (DU/DZ)(R,0) = 0\nC 0 .LE. R .LE. 1\nC (DU/DZ)(R,1) = 4*R**4 .\nC\nC THE R-INTERVAL WILL BE DIVIDED INTO 50 PANELS AND THE\nC Z-INTERVAL WILL BE DIVIDED INTO 100 PANELS.\nC\n DIMENSION F(75,105) ,BDA(101) ,BDB(101) ,BDC(51) ,\n 1 BDD(51) ,W(1373) ,R(51) ,Z(101)\nC\nC FROM DIMENSION STATEMENT WE GET VALUE OF IDIMF. ALSO NOTE THAT W\nC IS DIMENSIONED 4*(N+1) + (13 + INT(LOG2(N+1)))*(M+1) .\nC\n IDIMF = 75\n A = 0.\n B = 1.\n M = 50\n MBDCND = 6\n C = 0.\n D = 1.\n N = 100\n NBDCND = 3\n ELMBDA = 0.\nC\nC AUXILIARY QUANTITIES.\nC\n MP1 = M+1\n NP1 = N+1\nC\nC GENERATE AND STORE GRID POINTS FOR THE PURPOSE OF COMPUTING\nC BOUNDARY DATA AND THE RIGHT SIDE OF THE POISSON EQUATION.\nC\n DO 101 I=1,MP1\n R(I) = FLOAT(I-1)/50.\n 101 CONTINUE\n DO 102 J=1,NP1\n Z(J) = FLOAT(J-1)/100.\n 102 CONTINUE\nC\nC GENERATE BOUNDARY DATA.\nC\n DO 103 J=1,NP1\n BDB(J) = 4.*Z(J)**4\n 103 CONTINUE\n DO 104 I=1,MP1\n BDC(I) = 0.\n BDD(I) = 4.*R(I)**4\n 104 CONTINUE\nC\nC BDA IS A DUMMY VARIABLE.\nC\nC\nC GENERATE RIGHT SIDE OF EQUATION.\nC\n DO 106 I=1,MP1\n DO 105 J=1,NP1\n F(I,J) = 4.*R(I)**2*Z(J)**2*(4.*Z(J)**2+3.*R(I)**2)\n 105 CONTINUE\n 106 CONTINUE\n CALL HWSCYL (A,B,M,MBDCND,BDA,BDB,C,D,N,NBDCND,BDC,BDD,ELMBDA,F,\n 1 IDIMF,PERTRB,IERROR,W)\nC\nC COMPUTE DISCRETIZATION ERROR BY MINIMIZING OVER ALL A THE FUNCTION\nC NORM(F(I,J) - A*1 - U(R(I),Z(J))). THE EXACT SOLUTION IS\nC U(R,Z) = (R*Z)**4 + ARBITRARY CONSTANT.\nC\n X = 0.\n DO 108 I=1,MP1\n DO 107 J=1,NP1\n X = X+F(I,J)-(R(I)*Z(J))**4\n 107 CONTINUE\n 108 CONTINUE\n X = X/FLOAT(NP1*MP1)\n DO 110 I=1,MP1\n DO 109 J=1,NP1\n F(I,J) = F(I,J)-X\n 109 CONTINUE\n 110 CONTINUE\n ERR = 0.\n DO 112 I=1,MP1\n DO 111 J=1,NP1\n X = ABS(F(I,J)-(R(I)*Z(J))**4)\n IF (X .GT. ERR) ERR = X\n 111 CONTINUE\n 112 CONTINUE\n PRINT 1001 , IERROR,PERTRB,ERR,W(1)\n STOP IERROR\nC\n 1001 FORMAT (1H1,20X,25HSUBROUTINE HWSCYL EXAMPLE///\n 1 10X,46HTHE OUTPUT FROM THE NCAR CONTROL DATA 7600 WAS//\n 2 32X,10HIERROR = 0/32X,20HPERTRB = 2.26734E-04/\n 3 18X,34HDISCRETIZATION ERROR = 3.73672E-04/\n 4 12X,33HREQUIRED LENGTH OF W ARRAY = 1118//\n 5 10X,32HTHE OUTPUT FROM YOUR COMPUTER IS//\n 6 32X,8HIERROR =,I2/32X,8HPERTRB =,E12.5/\n 7 18X,22HDISCRETIZATION ERROR =,E12.5/\n 8 12X,28HREQUIRED LENGTH OF W ARRAY =,F5.0)\nC\n END\n", "meta": {"hexsha": "1206c08fdf3e36689e7a1bf0a84dbe4bfd3e65f7", "size": 5222, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "test/thwscyl.f", "max_stars_repo_name": "dmey/fishpack-cmake", "max_stars_repo_head_hexsha": "3db092535f4070a875e8f22045cec3cd1d3b6d1c", "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": "test/thwscyl.f", "max_issues_repo_name": "dmey/fishpack-cmake", "max_issues_repo_head_hexsha": "3db092535f4070a875e8f22045cec3cd1d3b6d1c", "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": "test/thwscyl.f", "max_forks_repo_name": "dmey/fishpack-cmake", "max_forks_repo_head_hexsha": "3db092535f4070a875e8f22045cec3cd1d3b6d1c", "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": 35.5238095238, "max_line_length": 72, "alphanum_fraction": 0.3762926082, "num_tokens": 1644, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736772, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.666820068393173}} {"text": "program ex23\n\n use utils\n\n implicit none\n\n real(rk) :: A(5,10)\n real(rk) :: B(5,10)\n integer :: i, j\n\n call initRand()\n call randMat(A, -1.0_rk, 1.0_rk)\n call printMatrix(A, 'A')\n\n B = cos(A)\n\n call printMatrix(B, 'B')\n\nend program ex23\n", "meta": {"hexsha": "5d12ea3ef3fb9e890b920b71878888f9ee3cbea6", "size": 267, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/ex23/ex23.f90", "max_stars_repo_name": "jonaslindemann/compute-course-public", "max_stars_repo_head_hexsha": "b8f55595ebbd790d79b525efdff17b8517154796", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-09-12T12:07:01.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-29T17:38:34.000Z", "max_issues_repo_path": "fortran/ex23/ex23.f90", "max_issues_repo_name": "jonaslindemann/compute-course-public", "max_issues_repo_head_hexsha": "b8f55595ebbd790d79b525efdff17b8517154796", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/ex23/ex23.f90", "max_forks_repo_name": "jonaslindemann/compute-course-public", "max_forks_repo_head_hexsha": "b8f55595ebbd790d79b525efdff17b8517154796", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2020-10-24T16:02:31.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-28T20:57:46.000Z", "avg_line_length": 13.35, "max_line_length": 36, "alphanum_fraction": 0.5505617978, "num_tokens": 97, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8519528170040852, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6667915080262728}} {"text": "! THIS VERSION: GALAHAD 2.1 - 27/10/2007 AT 15:00 GMT.\n PROGRAM GALAHAD_GLRT_test_deck\n USE GALAHAD_GLRT_DOUBLE ! double precision version\n IMPLICIT NONE\n INTEGER, PARAMETER :: working = KIND( 1.0D+0 ) ! set precision\n REAL ( KIND = working ), PARAMETER :: zero = 0.0_working\n REAL ( KIND = working ), PARAMETER :: one = 1.0_working, two = 2.0_working\n INTEGER, PARAMETER :: n = 100 ! problem dimension\n INTEGER :: i, nn, pass\n REAL ( KIND = working ) :: sigma, eps, p\n! REAL ( KIND = working ) :: f\n REAL ( KIND = working ), DIMENSION( n ) :: X, R, VECTOR, H_vector, O\n REAL ( KIND = working ), DIMENSION( 0 ) :: X0, R0, VECTOR0\n TYPE ( GLRT_data_type ) :: data\n TYPE ( GLRT_control_type ) :: control \n TYPE ( GLRT_inform_type ) :: inform\n\n! ==============\n! Normal entries\n! ==============\n\n WRITE( 6, \"( /, ' ==== normal exits ====== ', / )\" )\n\n! Initialize control parameters\n\n OPEN( UNIT = 23, STATUS = 'SCRATCH' )\n! OPEN( UNIT = 23 )\n DO pass = 1, 14\n IF ( pass /= 4 .AND. pass /= 7 .AND. pass /= 8 ) &\n CALL GLRT_initialize( data, control )\n control%error = 23 ; control%out = 23 ; control%print_level = 10\n inform%status = 1\n p = 3.0_working\n sigma = one ; eps = zero\n IF ( pass == 2 ) control%unitm = .FALSE. ; sigma = 1000.0_working\n IF ( pass == 4 ) THEN\n sigma = sigma / two ; inform%status = 6\n END IF \n IF ( pass == 5 ) sigma = 0.0001_working\n IF ( pass == 7 ) THEN\n sigma = 0.1_working ; inform%status = 6\n END IF\n IF ( pass == 8 ) THEN\n sigma = 100.0_working ; inform%status = 6\n END IF\n IF ( pass == 9 ) sigma = 10.0_working\n IF ( pass == 10 ) sigma = 10.0_working\n IF ( pass == 11 ) sigma = 10000.0_working\n IF ( pass == 12 .OR. pass == 14 ) eps = one\n IF ( pass == 13 .OR. pass == 14 ) O = one\n\n IF ( pass == 10 .OR. pass == 11 ) THEN\n R( : n - 1 ) = 0.000000000001_working ; R( n ) = one\n ELSE\n R = one\n END IF\n! IF ( pass == 13 .OR. pass == 14 ) THEN\n! control%error = 6 ; control%out = 6 ; control%print_level = 1\n! END IF\n\n! Iteration to find the minimizer\n\n DO \n IF ( pass == 14 ) THEN\n CALL GLRT_solve( n, p, sigma, X, R, VECTOR, data, control, &\n inform, eps = eps, O = O )\n ELSE IF ( pass == 13 ) THEN\n CALL GLRT_solve( n, p, sigma, X, R, VECTOR, data, control, &\n inform, O = O )\n ELSE IF ( pass == 12 ) THEN\n CALL GLRT_solve( n, p, sigma, X, R, VECTOR, data, control, &\n inform, eps = eps )\n ELSE\n CALL GLRT_solve( n, p, sigma, X, R, VECTOR, data, control, &\n inform )\n END IF\n\n! Branch as a result of inform%status\n\n SELECT CASE( inform%status )\n\n! Form the preconditioned gradient\n\n CASE( 2 ) \n VECTOR = VECTOR / two\n\n! Form the matrix-vector product\n\n CASE ( 3 ) \n IF ( pass == 2 .OR. pass == 6 .OR. pass == 7 .OR. pass == 8 ) THEN\n H_vector( 1 ) = two * VECTOR( 1 ) + VECTOR( 2 )\n DO i = 2, n - 1\n H_vector( i ) = VECTOR( i - 1 ) + two * VECTOR( i ) + &\n VECTOR( i + 1 )\n END DO\n H_vector( n ) = VECTOR( n - 1 ) + two * VECTOR( n )\n ELSE IF ( pass == 9 ) THEN\n H_vector( 1 ) = VECTOR( 1 ) + VECTOR( 2 )\n DO i = 2, n - 1\n H_vector( i ) = VECTOR( i - 1 ) - two * VECTOR( i ) + &\n VECTOR( i + 1 )\n END DO\n H_vector( n ) = VECTOR( n - 1 ) + VECTOR( n )\n ELSE IF ( pass == 10 .OR. pass == 11 ) THEN\n H_vector( 1 ) = - two * VECTOR( 1 )\n H_vector( 2 : n - 1 ) = 0.0001_working * VECTOR( 2 : n - 1 )\n H_vector( n ) = - VECTOR( n )\n ELSE\n H_vector( 1 ) = - two * VECTOR( 1 ) + VECTOR( 2 )\n DO i = 2, n - 1\n H_vector( i ) = VECTOR( i - 1 ) - two * VECTOR( i ) + &\n VECTOR( i + 1 )\n END DO\n H_vector( n ) = VECTOR( n - 1 ) - two * VECTOR( n )\n END IF\n VECTOR = H_vector \n\n! Restart\n\n CASE ( 4 ) \n IF ( pass == 10 .OR. pass == 11 ) THEN\n R( : n - 1 ) = 0.000000000001_working\n R( n ) = one\n ELSE\n R = one\n END IF\n\n! Form the product with the preconditioner\n\n CASE( 5 ) \n VECTOR = two * VECTOR\n\n! Successful return\n\n CASE ( - 2 : 0 ) \n EXIT\n\n! Error returns\n\n CASE DEFAULT \n EXIT\n END SELECT\n END DO\n\n WRITE( 6, \"( ' pass ', I3, ' GLRT_solve exit status = ', I6 )\" ) &\n pass, inform%status\n! WRITE( 6, \"( ' its, solution and Lagrange multiplier = ', I6, 2ES12.4 )\")&\n! inform%iter + inform%iter_pass2, f, inform%multiplier\n IF ( pass /= 3 .AND. pass /= 6 .AND. pass /= 7 ) &\n CALL GLRT_terminate( data, control, inform ) ! delete internal workspace\n END DO\n\n! =============\n! Error entries\n! =============\n\n WRITE( 6, \"( /, ' ==== error exits ====== ', / )\" )\n\n! Initialize control parameters\n\n DO pass = 2, 9\n sigma = one\n eps = zero\n p = 3.0_working\n CALL GLRT_initialize( data, control )\n control%error = 23 ; control%out = 23 ; control%print_level = 10\n inform%status = 1\n nn = n\n IF ( pass == 2 ) control%itmax = 0\n IF ( pass == 3 ) inform%status = 0\n IF ( pass == 4 ) nn = 0\n IF ( pass == 5 ) sigma = - one\n IF ( pass == 6 ) CYCLE\n IF ( pass == 7 ) eps = - one\n IF ( pass == 8 ) p = one\n IF ( pass == 9 ) p = two\n IF ( pass == 9 ) control%unitm = .FALSE.\n\n R = one\n\n! Iteration to find the minimizer\n\n DO \n IF ( pass == 4 ) THEN\n CALL GLRT_solve( nn, p, sigma, X0, R0, &\n VECTOR0, data, control, inform )\n ELSE IF ( pass == 7 ) THEN\n CALL GLRT_solve( nn, p, sigma, X( : nn ), R( : nn ), &\n VECTOR( : nn ), data, control, inform, eps = eps )\n ELSE\n CALL GLRT_solve( nn, p, sigma, X( : nn ), R( : nn ), &\n VECTOR( : nn ), data, control, inform )\n END IF\n\n! Branch as a result of inform%status\n\n SELECT CASE( inform%status )\n\n! Form the preconditioned gradient\n\n CASE( 2 ) \n IF ( pass /= 3 ) THEN\n VECTOR = VECTOR / two\n ELSE\n VECTOR = - VECTOR / two\n END IF\n\n! Form the matrix-vector product\n\n CASE ( 3 ) \n H_vector( 1 ) = - two * VECTOR( 1 ) + VECTOR( 2 )\n DO i = 2, n - 1\n H_vector( i ) = VECTOR( i - 1 ) - two * VECTOR( i ) + &\n VECTOR( i + 1 )\n END DO\n H_vector( n ) = VECTOR( n - 1 ) - two * VECTOR( n )\n VECTOR = H_vector \n\n! Restart\n\n CASE ( 4 ) \n R = one\n\n! Form the product with the preconditioner\n\n CASE( 5 ) \n IF ( pass /= 3 ) THEN\n VECTOR = two * VECTOR\n ELSE\n VECTOR = - two * VECTOR\n END IF\n\n! Successful return\n\n CASE ( - 2 : 0 ) \n EXIT\n\n! Error returns\n\n CASE DEFAULT \n EXIT\n END SELECT\n END DO\n\n WRITE( 6, \"( ' pass ', I3, ' GLRT_solve exit status = ', I6 )\" ) &\n pass, inform%status\n CALL GLRT_terminate( data, control, inform ) ! delete internal workspace\n END DO\n CLOSE( unit = 23 )\n\n! STOP\n END PROGRAM GALAHAD_GLRT_test_deck\n", "meta": {"hexsha": "33159cab727786187129496fc3ce415e4bd4b9a7", "size": 8270, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "legacy_fortran/galahad-2.3/src/glrt/glrtt.f90", "max_stars_repo_name": "dynamics-of-stellar-systems/dynamite_release", "max_stars_repo_head_hexsha": "a921d8a1bde98f48daeea78213fb17b3edb223bb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-10-14T12:22:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-31T15:32:59.000Z", "max_issues_repo_path": "legacy_fortran/galahad-2.3/src/glrt/glrtt.f90", "max_issues_repo_name": "dynamics-of-stellar-systems/dynamite_release", "max_issues_repo_head_hexsha": "a921d8a1bde98f48daeea78213fb17b3edb223bb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2022-02-25T16:05:40.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T15:15:16.000Z", "max_forks_repo_path": "legacy_fortran/galahad-2.3/src/glrt/glrtt.f90", "max_forks_repo_name": "dynamics-of-stellar-systems/dynamite", "max_forks_repo_head_hexsha": "5ccf936e4b1cd907db8dd7070d4ad204ed913337", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-11-04T04:36:40.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-01T01:07:38.000Z", "avg_line_length": 32.6877470356, "max_line_length": 81, "alphanum_fraction": 0.438331318, "num_tokens": 2365, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.851952809486198, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.6667914978233874}} {"text": "submodule(euler_interface_m) euler_prob_0009_m\n implicit none\n\ncontains\n\n module character(len=20) function euler0009()\n write (euler0009, \"(i20)\") ans(1000)\n end function euler0009\n\n integer function ans(n)\n integer, intent(in) :: n\n integer :: a, b, c\n\n ans = 0\n outer: do a = 1, n\n inner: do b = a + 1, n\n c = n - a - b\n if (a**2 + b**2 == c**2) then\n ans = a*b*c\n return\n end if\n end do inner\n end do outer\n end function ans\n\nend submodule euler_prob_0009_m\n", "meta": {"hexsha": "69860039197c0e5ca18b7df76beac3b9c5575dfa", "size": 624, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "docs/src/prob_0009_m.f90", "max_stars_repo_name": "han190/PE-Fortran", "max_stars_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-02-09T07:07:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-31T07:45:48.000Z", "max_issues_repo_path": "docs/src/prob_0009_m.f90", "max_issues_repo_name": "han190/PE-Fortran", "max_issues_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-14T00:48:58.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-14T00:48:58.000Z", "max_forks_repo_path": "docs/src/prob_0009_m.f90", "max_forks_repo_name": "han190/PE-Fortran", "max_forks_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-04T21:29:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T21:29:45.000Z", "avg_line_length": 23.1111111111, "max_line_length": 49, "alphanum_fraction": 0.4967948718, "num_tokens": 174, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619885, "lm_q2_score": 0.7772998611746911, "lm_q1q2_score": 0.6667430345813204}} {"text": "program test_expBesselI\n\n use bessel_mod\n use constants\n use netcdf\n use check_mod\n\n implicit none\n\n integer :: nPts, lMax, lMaxTmp, iErr, i, j, lOut\n integer, allocatable :: l(:)\n complex(kind=dbl), allocatable :: z(:,:), besselI(:), &\n expBesselI(:), expBesselIPrime(:), expBesselIOverGam(:)\n real :: dz, zMax\n complex, allocatable :: res(:,:), expRes(:,:)\n character(len=100) :: fName\n complex(kind=dbl) :: zLarge, zExtraLarge, zExtraSmall\n\n integer :: nc_id, n_id, res_re_id, res_im_id, &\n z_re_id, z_im_id, expres_re_id, expres_im_id\n\n lMax = 20\n lOut = 20\n nPts = 201 \n allocate ( z(nPts,nPts), res(nPts,nPts), expRes(nPts,nPts) )\n allocate ( l(-lMax:lMax) )\n\n zMax = 10.0 \n dz = zMax * 2.0 / (nPts - 1)\n do i=1,nPts\n do j=1,nPts\n\n z(i,j) = complex ( (i-1)*dz - zMax, (j-1)*dz - zMax )\n\n enddo\n enddo\n\n ! I_l(z) and exp(-z) * I_l(z) for small z values\n ! ----------------------------------------------\n\n allocate ( besselI(lMax+1), &\n expBesselI(lMax+1), &\n expBesselIPrime(lMax+1), &\n expBesselIOverGam(lMax+1) )\n\n do i=1,nPts\n do j=1,nPts\n\n lMaxTmp = lMax \n call besic ( z(i,j), lMaxTmp, besselI, iErr)\n\n if(iErr/=0) then \n write(*,*) 'ERROR: iErr'\n stop\n endif\n\n res(i,j) = besselI(lOut+1)\n expRes(i,j) = exp ( -z(i,j) ) * res(i,j)\n\n enddo\n enddo\n\n\n ! I_l(z) and exp(-z) * I_l(z) for large z values\n ! ----------------------------------------------\n\n zLarge = complex ( 7.0, 7.0 )\n call besIExp ( zLarge, lMax, expBesselI, expBesselIPrime, expBesselIOverGam )\n\n write(*,*) zLarge, expBesselI(lOut+1), expBesselIPrime(lOut+1)\n\n \n ! exp(-z) * I_l(z) for Re(z) < 1e-8\n ! ------------------------------\n\n zExtraSmall = complex ( 1d-9, 1d-9 )\n lMaxTmp = lMax\n call bes_expand ( zExtraSmall, lMaxTmp, expBesselI, expBesselIPrime, expBesselIOverGam )\n\n write(*,*) zExtraSmall, expBesselI(lOut+1), expBesselIPrime(lOut+1), expBesselIOverGam(lOut+1)\n\n\n ! exp(-z) * I_l(z) for |z| > 700\n ! ------------------------------\n\n zExtraLarge = complex ( 900, 900 )\n call besIExp ( zExtraLarge, lMax, expBesselI, expBesselIPrime, expBesselIOverGam )\n\n write(*,*) zExtraLarge, expBesselI(lOut+1), expBesselIPrime(lOut+1)\n\n\n\n\n ! write value to file for plotting in IDL and comparing\n ! to mathematica solutions\n ! -----------------------------------------------------\n\n fName = 'test_expBesselI.nc'\n call check ( nf90_create ( fName, nf90_clobber, nc_id ) )\n call check ( nf90_def_dim ( nc_id, \"nPts\", nPts, n_id ) )\n\n call check ( nf90_def_var ( nc_id, \"res_re\", nf90_real, &\n (/n_id,n_id/), res_re_id ) ) \n call check ( nf90_def_var ( nc_id, \"res_im\", nf90_real, &\n (/n_id,n_id/), res_im_id ) ) \n call check ( nf90_def_var ( nc_id, \"z_re\", NF90_REAL, &\n (/n_id,n_id/), z_re_id ) ) \n call check ( nf90_def_var ( nc_id, \"z_im\", NF90_REAL, &\n (/n_id,n_id/), z_im_id ) ) \n\n call check ( nf90_def_var ( nc_id, \"expRes_re\", nf90_real, &\n (/n_id,n_id/), expRes_re_id ) ) \n call check ( nf90_def_var ( nc_id, \"expRes_im\", nf90_real, &\n (/n_id,n_id/), expRes_im_id ) ) \n \n call check ( nf90_enddef ( nc_id ) )\n\n call check ( nf90_put_var ( nc_id, res_re_id, real ( res ) ) )\n call check ( nf90_put_var ( nc_id, res_im_id, aimag ( res ) ) )\n call check ( nf90_put_var ( nc_id, z_re_id, real ( z ) ) )\n call check ( nf90_put_var ( nc_id, z_im_id, aimag ( z ) ) )\n call check ( nf90_put_var ( nc_id, expRes_re_id, real ( expRes ) ) )\n call check ( nf90_put_var ( nc_id, expRes_im_id, aimag ( expRes ) ) )\n \n call check ( nf90_close ( nc_id ) )\n\n \nend program test_expBesselI\n", "meta": {"hexsha": "6a09c6f33596433548d24f13ffbdc13be6a5b793", "size": 3899, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test_routines/src/test_expBesselI.f90", "max_stars_repo_name": "efdazedo/aorsa2d", "max_stars_repo_head_hexsha": "ce0b8c930715277eeb4d23e60cc88434ffdaa583", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-02-13T21:57:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-10T16:47:51.000Z", "max_issues_repo_path": "test_routines/src/test_expBesselI.f90", "max_issues_repo_name": "efdazedo/aorsa2d", "max_issues_repo_head_hexsha": "ce0b8c930715277eeb4d23e60cc88434ffdaa583", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-02-23T20:33:30.000Z", "max_issues_repo_issues_event_max_datetime": "2018-02-23T20:34:31.000Z", "max_forks_repo_path": "test_routines/src/test_expBesselI.f90", "max_forks_repo_name": "efdazedo/aorsa2d", "max_forks_repo_head_hexsha": "ce0b8c930715277eeb4d23e60cc88434ffdaa583", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-02-15T16:50:58.000Z", "max_forks_repo_forks_event_max_datetime": "2018-06-23T14:07:59.000Z", "avg_line_length": 30.2248062016, "max_line_length": 98, "alphanum_fraction": 0.5480892537, "num_tokens": 1307, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619885, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6667430301561594}} {"text": "#:include \"common.fpp\"\n\nprogram test_mfi_blas\n use iso_fortran_env\n use mfi_blas\n use f77_blas\n implicit none\n integer, parameter :: N = 2000\n real(REAL64) :: A(N,N), B(N,N), C(N,N), D(N,N)\n real(REAL64) :: X(N), Y(N), Z(N), U(N)\n real(REAL64) :: alpha, beta\n integer :: i, j, k\n\n ! BLAS 1\n call test_axpy\n call test_copy\n call test_rotmg\n call test_swap\n call test_iamax\n call test_iamin\n ! BLAS 2\n call test_gemv\n ! BLAS 3\n call test_gemm\n\ncontains\n subroutine test_defaults\n C = .0_REAL64\n D = .0_REAL64\n Y = .0_REAL64\n Z = .0_REAL64\n alpha = 1.0_REAL64\n beta = 0.0_REAL64\n call random_number(A)\n call random_number(B)\n call random_number(X)\n end subroutine\n\n subroutine test_rotmg\n real(REAL64) :: x1, y1, d1, d2, params(5)\n real(REAL64) :: expected(5)\n expected = [-1.d0, 1.6110934624105326d-6, -2.44140625d-4, 2.44140625d-4, 1.62760416d-6]\n d1 = 5.9d-8; d2 = 5.960464d-8; x1 = 1.d0; y1 = 150.d0; params = .0_REAL64\n @:timeit(\"time f77_rotmg: \", { call f77_rotmg(d1, d2, x1, y1, params) })\n call assert(all(is_almost_equal(params, expected)))\n d1 = 5.9d-8; d2 = 5.960464d-8; x1 = 1.d0; y1 = 150.d0; params = .0_REAL64\n @:timeit(\"time mfi_rotmg: \", { call mfi_rotmg(d1, d2, x1, y1, params) })\n call assert(all(is_almost_equal(params, expected)))\n d1 = 5.9d-8; d2 = 5.960464d-8; x1 = 1.d0; y1 = 150.d0; params = .0_REAL64\n @:timeit(\"time drotmg: \", { call drotmg(d1, d2, x1, y1, params) })\n call assert(all(is_almost_equal(params, expected)))\n end subroutine\n\n subroutine test_axpy\n call test_defaults\n @:timeit(\"time f77_axpy: \", { call f77_axpy(N,2*alpha,X,1,Y,1) })\n Y = .0_REAL64\n @:timeit(\"time mfi_axpy: \", { call mfi_axpy(X,Y,2*alpha) })\n @:timeit(\"time fortran: \", { Z=2*X })\n call assert(all(is_almost_equal(2*X,Y) .and. is_almost_equal(2*X,Z)))\n end subroutine\n\n subroutine test_copy\n call test_defaults\n @:timeit(\"time f77_copy: \", { call f77_copy(N,X,1,Y,1) })\n @:timeit(\"time mfi_copy: \", { call mfi_copy(X,Y) })\n @:timeit(\"time fortran: \", { Z=X })\n call assert(all(is_almost_equal(X,Y) .and. is_almost_equal(X,Z)))\n end subroutine\n\n subroutine test_swap\n call test_defaults\n @:timeit(\"time f77_swap: \", { call f77_swap(N,X,1,Y,1) })\n @:timeit(\"time mfi_swap: \", { call mfi_swap(X,Y) })\n end subroutine\n\n subroutine test_iamax\n call test_defaults\n @:timeit(\"time f77_iamax: \", { i = f77_iamax(N,X,1) })\n @:timeit(\"time mfi_iamax: \", { j = mfi_iamax(X) })\n @:timeit(\"time maxloc: \", { k = maxloc(X,1) })\n call assert(i == j .and. j == k)\n end subroutine\n\n subroutine test_iamin\n call test_defaults\n @:timeit(\"time f77_iamin: \", { i = f77_iamin(N,X,1) })\n @:timeit(\"time mfi_iamin: \", { j = mfi_iamin(X) })\n @:timeit(\"time minloc: \", { k = minloc(X,1) })\n call assert(i == j .and. j == k)\n end subroutine\n\n subroutine test_gemm\n call test_defaults\n @:timeit(\"time f77_gemm: \", { call f77_gemm('N', 'N', N, N, N, alpha, A, N, B, N, beta, C, N) })\n @:timeit(\"time mfi_gemm: \", { call mfi_gemm(A,B,C) })\n @:timeit(\"time matmul: \", { D = matmul(A,B) })\n call assert(all(is_almost_equal(C,D)))\n\n @:timeit(\"time f77_gemm, transa=T: \", { call f77_gemm('T', 'N', N, N, N, alpha, A, N, B, N, beta, C, N) })\n @:timeit(\"time mfi_gemm, transa=T: \", { call mfi_gemm(A,B,C,transa='T') })\n @:timeit(\"time matmul, transpose(A): \", { D = matmul(transpose(A),B) })\n call assert(all(is_almost_equal(C,D)))\n end subroutine\n\n subroutine test_gemv\n call test_defaults\n @:timeit(\"time f77_gemv: \", { call f77_gemv('N', N, N, alpha, A, N, X, 1, beta, Y, 1) })\n @:timeit(\"time mfi_gemv: \", { call mfi_gemv(A,X,Y) })\n @:timeit(\"time matmul: \", { Z = matmul(A,X) })\n call assert(all(is_almost_equal(Y,Z)))\n\n @:timeit(\"time f77_gemv: trans=T: \", { call f77_gemv('T', N, N, alpha, A, N, X, 1, beta, Y, 1) })\n @:timeit(\"time mfi_gemv, trans=T: \", { call mfi_gemv(A,X,Y,trans='T') })\n @:timeit(\"time matmul, transpose(A): \", { Z = matmul(transpose(A),X) })\n call assert(all(is_almost_equal(Y,Z)))\n end subroutine\n\n pure subroutine assert(test)\n logical, intent(in) :: test\n if (.not. test) then\n error stop 'different results'\n end if\n end subroutine\n\n logical pure elemental function is_almost_equal(x, y)\n real(REAL64), intent(in) :: x, y\n is_almost_equal = abs(x-y) < 10**6*epsilon(x)\n end function\n\nend program\n", "meta": {"hexsha": "f768e0f5a82751f0d06d45c3da180d4156192bc7", "size": 4953, "ext": "fpp", "lang": "FORTRAN", "max_stars_repo_path": "test/test_mfi_blas.fpp", "max_stars_repo_name": "14NGiestas/mfi", "max_stars_repo_head_hexsha": "eb00fd644385fa67da5c349c5e294c46b8ef1c65", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2020-11-05T15:44:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-29T18:43:02.000Z", "max_issues_repo_path": "test/test_mfi_blas.fpp", "max_issues_repo_name": "14NGiestas/mfi", "max_issues_repo_head_hexsha": "eb00fd644385fa67da5c349c5e294c46b8ef1c65", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2020-11-02T13:11:46.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-02T10:02:23.000Z", "max_forks_repo_path": "test/test_mfi_blas.fpp", "max_forks_repo_name": "14NGiestas/mfi", "max_forks_repo_head_hexsha": "eb00fd644385fa67da5c349c5e294c46b8ef1c65", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-12-29T17:56:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T02:11:38.000Z", "avg_line_length": 37.5227272727, "max_line_length": 118, "alphanum_fraction": 0.55420957, "num_tokens": 1700, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901036, "lm_q2_score": 0.7772998611746911, "lm_q1q2_score": 0.6667430289288854}} {"text": "submodule (stdlib_stats) stdlib_stats_var\n\n use, intrinsic:: ieee_arithmetic, only: ieee_value, ieee_quiet_nan\n use stdlib_error, only: error_stop\n use stdlib_optval, only: optval\n implicit none\n\ncontains\n\n module function var_all_1_rsp_rsp(x, mask, corrected) result(res)\n real(sp), intent(in) :: x(:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(sp) :: res\n\n real(sp) :: n\n real(sp) :: mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._sp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), sp)\n mean = sum(x) / n\n\n res = sum((x - mean)**2) / (n - merge(1, 0 , optval(corrected, .true.)))\n\n end function var_all_1_rsp_rsp\n module function var_all_2_rsp_rsp(x, mask, corrected) result(res)\n real(sp), intent(in) :: x(:,:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(sp) :: res\n\n real(sp) :: n\n real(sp) :: mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._sp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), sp)\n mean = sum(x) / n\n\n res = sum((x - mean)**2) / (n - merge(1, 0 , optval(corrected, .true.)))\n\n end function var_all_2_rsp_rsp\n module function var_all_3_rsp_rsp(x, mask, corrected) result(res)\n real(sp), intent(in) :: x(:,:,:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(sp) :: res\n\n real(sp) :: n\n real(sp) :: mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._sp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), sp)\n mean = sum(x) / n\n\n res = sum((x - mean)**2) / (n - merge(1, 0 , optval(corrected, .true.)))\n\n end function var_all_3_rsp_rsp\n module function var_all_4_rsp_rsp(x, mask, corrected) result(res)\n real(sp), intent(in) :: x(:,:,:,:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(sp) :: res\n\n real(sp) :: n\n real(sp) :: mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._sp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), sp)\n mean = sum(x) / n\n\n res = sum((x - mean)**2) / (n - merge(1, 0 , optval(corrected, .true.)))\n\n end function var_all_4_rsp_rsp\n module function var_all_1_rdp_rdp(x, mask, corrected) result(res)\n real(dp), intent(in) :: x(:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n\n real(dp) :: mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n mean = sum(x) / n\n\n res = sum((x - mean)**2) / (n - merge(1, 0 , optval(corrected, .true.)))\n\n end function var_all_1_rdp_rdp\n module function var_all_2_rdp_rdp(x, mask, corrected) result(res)\n real(dp), intent(in) :: x(:,:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n\n real(dp) :: mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n mean = sum(x) / n\n\n res = sum((x - mean)**2) / (n - merge(1, 0 , optval(corrected, .true.)))\n\n end function var_all_2_rdp_rdp\n module function var_all_3_rdp_rdp(x, mask, corrected) result(res)\n real(dp), intent(in) :: x(:,:,:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n\n real(dp) :: mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n mean = sum(x) / n\n\n res = sum((x - mean)**2) / (n - merge(1, 0 , optval(corrected, .true.)))\n\n end function var_all_3_rdp_rdp\n module function var_all_4_rdp_rdp(x, mask, corrected) result(res)\n real(dp), intent(in) :: x(:,:,:,:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n\n real(dp) :: mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n mean = sum(x) / n\n\n res = sum((x - mean)**2) / (n - merge(1, 0 , optval(corrected, .true.)))\n\n end function var_all_4_rdp_rdp\n module function var_all_1_rqp_rqp(x, mask, corrected) result(res)\n real(qp), intent(in) :: x(:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(qp) :: res\n\n real(qp) :: n\n real(qp) :: mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._qp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), qp)\n mean = sum(x) / n\n\n res = sum((x - mean)**2) / (n - merge(1, 0 , optval(corrected, .true.)))\n\n end function var_all_1_rqp_rqp\n module function var_all_2_rqp_rqp(x, mask, corrected) result(res)\n real(qp), intent(in) :: x(:,:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(qp) :: res\n\n real(qp) :: n\n real(qp) :: mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._qp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), qp)\n mean = sum(x) / n\n\n res = sum((x - mean)**2) / (n - merge(1, 0 , optval(corrected, .true.)))\n\n end function var_all_2_rqp_rqp\n module function var_all_3_rqp_rqp(x, mask, corrected) result(res)\n real(qp), intent(in) :: x(:,:,:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(qp) :: res\n\n real(qp) :: n\n real(qp) :: mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._qp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), qp)\n mean = sum(x) / n\n\n res = sum((x - mean)**2) / (n - merge(1, 0 , optval(corrected, .true.)))\n\n end function var_all_3_rqp_rqp\n module function var_all_4_rqp_rqp(x, mask, corrected) result(res)\n real(qp), intent(in) :: x(:,:,:,:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(qp) :: res\n\n real(qp) :: n\n real(qp) :: mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._qp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), qp)\n mean = sum(x) / n\n\n res = sum((x - mean)**2) / (n - merge(1, 0 , optval(corrected, .true.)))\n\n end function var_all_4_rqp_rqp\n module function var_all_1_csp_csp(x, mask, corrected) result(res)\n complex(sp), intent(in) :: x(:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(sp) :: res\n\n real(sp) :: n\n complex(sp) :: mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._sp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), sp)\n mean = sum(x) / n\n\n res = sum(abs(x - mean)**2) / (n - merge(1, 0, optval(corrected, .true.)))\n\n end function var_all_1_csp_csp\n module function var_all_2_csp_csp(x, mask, corrected) result(res)\n complex(sp), intent(in) :: x(:,:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(sp) :: res\n\n real(sp) :: n\n complex(sp) :: mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._sp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), sp)\n mean = sum(x) / n\n\n res = sum(abs(x - mean)**2) / (n - merge(1, 0, optval(corrected, .true.)))\n\n end function var_all_2_csp_csp\n module function var_all_3_csp_csp(x, mask, corrected) result(res)\n complex(sp), intent(in) :: x(:,:,:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(sp) :: res\n\n real(sp) :: n\n complex(sp) :: mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._sp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), sp)\n mean = sum(x) / n\n\n res = sum(abs(x - mean)**2) / (n - merge(1, 0, optval(corrected, .true.)))\n\n end function var_all_3_csp_csp\n module function var_all_4_csp_csp(x, mask, corrected) result(res)\n complex(sp), intent(in) :: x(:,:,:,:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(sp) :: res\n\n real(sp) :: n\n complex(sp) :: mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._sp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), sp)\n mean = sum(x) / n\n\n res = sum(abs(x - mean)**2) / (n - merge(1, 0, optval(corrected, .true.)))\n\n end function var_all_4_csp_csp\n module function var_all_1_cdp_cdp(x, mask, corrected) result(res)\n complex(dp), intent(in) :: x(:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n\n complex(dp) :: mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n mean = sum(x) / n\n\n res = sum(abs(x - mean)**2) / (n - merge(1, 0, optval(corrected, .true.)))\n\n end function var_all_1_cdp_cdp\n module function var_all_2_cdp_cdp(x, mask, corrected) result(res)\n complex(dp), intent(in) :: x(:,:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n\n complex(dp) :: mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n mean = sum(x) / n\n\n res = sum(abs(x - mean)**2) / (n - merge(1, 0, optval(corrected, .true.)))\n\n end function var_all_2_cdp_cdp\n module function var_all_3_cdp_cdp(x, mask, corrected) result(res)\n complex(dp), intent(in) :: x(:,:,:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n\n complex(dp) :: mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n mean = sum(x) / n\n\n res = sum(abs(x - mean)**2) / (n - merge(1, 0, optval(corrected, .true.)))\n\n end function var_all_3_cdp_cdp\n module function var_all_4_cdp_cdp(x, mask, corrected) result(res)\n complex(dp), intent(in) :: x(:,:,:,:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n\n complex(dp) :: mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n mean = sum(x) / n\n\n res = sum(abs(x - mean)**2) / (n - merge(1, 0, optval(corrected, .true.)))\n\n end function var_all_4_cdp_cdp\n module function var_all_1_cqp_cqp(x, mask, corrected) result(res)\n complex(qp), intent(in) :: x(:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(qp) :: res\n\n real(qp) :: n\n complex(qp) :: mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._qp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), qp)\n mean = sum(x) / n\n\n res = sum(abs(x - mean)**2) / (n - merge(1, 0, optval(corrected, .true.)))\n\n end function var_all_1_cqp_cqp\n module function var_all_2_cqp_cqp(x, mask, corrected) result(res)\n complex(qp), intent(in) :: x(:,:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(qp) :: res\n\n real(qp) :: n\n complex(qp) :: mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._qp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), qp)\n mean = sum(x) / n\n\n res = sum(abs(x - mean)**2) / (n - merge(1, 0, optval(corrected, .true.)))\n\n end function var_all_2_cqp_cqp\n module function var_all_3_cqp_cqp(x, mask, corrected) result(res)\n complex(qp), intent(in) :: x(:,:,:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(qp) :: res\n\n real(qp) :: n\n complex(qp) :: mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._qp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), qp)\n mean = sum(x) / n\n\n res = sum(abs(x - mean)**2) / (n - merge(1, 0, optval(corrected, .true.)))\n\n end function var_all_3_cqp_cqp\n module function var_all_4_cqp_cqp(x, mask, corrected) result(res)\n complex(qp), intent(in) :: x(:,:,:,:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(qp) :: res\n\n real(qp) :: n\n complex(qp) :: mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._qp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), qp)\n mean = sum(x) / n\n\n res = sum(abs(x - mean)**2) / (n - merge(1, 0, optval(corrected, .true.)))\n\n end function var_all_4_cqp_cqp\n\n\n module function var_all_1_iint8_dp(x, mask, corrected) result(res)\n integer(int8), intent(in) :: x(:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n, mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n mean = sum(real(x, dp)) / n\n\n res = sum((real(x, dp) - mean)**2) / (n - merge(1, 0, optval(corrected, .true.)))\n\n end function var_all_1_iint8_dp\n module function var_all_2_iint8_dp(x, mask, corrected) result(res)\n integer(int8), intent(in) :: x(:,:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n, mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n mean = sum(real(x, dp)) / n\n\n res = sum((real(x, dp) - mean)**2) / (n - merge(1, 0, optval(corrected, .true.)))\n\n end function var_all_2_iint8_dp\n module function var_all_3_iint8_dp(x, mask, corrected) result(res)\n integer(int8), intent(in) :: x(:,:,:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n, mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n mean = sum(real(x, dp)) / n\n\n res = sum((real(x, dp) - mean)**2) / (n - merge(1, 0, optval(corrected, .true.)))\n\n end function var_all_3_iint8_dp\n module function var_all_4_iint8_dp(x, mask, corrected) result(res)\n integer(int8), intent(in) :: x(:,:,:,:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n, mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n mean = sum(real(x, dp)) / n\n\n res = sum((real(x, dp) - mean)**2) / (n - merge(1, 0, optval(corrected, .true.)))\n\n end function var_all_4_iint8_dp\n module function var_all_1_iint16_dp(x, mask, corrected) result(res)\n integer(int16), intent(in) :: x(:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n, mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n mean = sum(real(x, dp)) / n\n\n res = sum((real(x, dp) - mean)**2) / (n - merge(1, 0, optval(corrected, .true.)))\n\n end function var_all_1_iint16_dp\n module function var_all_2_iint16_dp(x, mask, corrected) result(res)\n integer(int16), intent(in) :: x(:,:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n, mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n mean = sum(real(x, dp)) / n\n\n res = sum((real(x, dp) - mean)**2) / (n - merge(1, 0, optval(corrected, .true.)))\n\n end function var_all_2_iint16_dp\n module function var_all_3_iint16_dp(x, mask, corrected) result(res)\n integer(int16), intent(in) :: x(:,:,:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n, mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n mean = sum(real(x, dp)) / n\n\n res = sum((real(x, dp) - mean)**2) / (n - merge(1, 0, optval(corrected, .true.)))\n\n end function var_all_3_iint16_dp\n module function var_all_4_iint16_dp(x, mask, corrected) result(res)\n integer(int16), intent(in) :: x(:,:,:,:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n, mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n mean = sum(real(x, dp)) / n\n\n res = sum((real(x, dp) - mean)**2) / (n - merge(1, 0, optval(corrected, .true.)))\n\n end function var_all_4_iint16_dp\n module function var_all_1_iint32_dp(x, mask, corrected) result(res)\n integer(int32), intent(in) :: x(:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n, mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n mean = sum(real(x, dp)) / n\n\n res = sum((real(x, dp) - mean)**2) / (n - merge(1, 0, optval(corrected, .true.)))\n\n end function var_all_1_iint32_dp\n module function var_all_2_iint32_dp(x, mask, corrected) result(res)\n integer(int32), intent(in) :: x(:,:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n, mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n mean = sum(real(x, dp)) / n\n\n res = sum((real(x, dp) - mean)**2) / (n - merge(1, 0, optval(corrected, .true.)))\n\n end function var_all_2_iint32_dp\n module function var_all_3_iint32_dp(x, mask, corrected) result(res)\n integer(int32), intent(in) :: x(:,:,:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n, mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n mean = sum(real(x, dp)) / n\n\n res = sum((real(x, dp) - mean)**2) / (n - merge(1, 0, optval(corrected, .true.)))\n\n end function var_all_3_iint32_dp\n module function var_all_4_iint32_dp(x, mask, corrected) result(res)\n integer(int32), intent(in) :: x(:,:,:,:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n, mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n mean = sum(real(x, dp)) / n\n\n res = sum((real(x, dp) - mean)**2) / (n - merge(1, 0, optval(corrected, .true.)))\n\n end function var_all_4_iint32_dp\n module function var_all_1_iint64_dp(x, mask, corrected) result(res)\n integer(int64), intent(in) :: x(:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n, mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n mean = sum(real(x, dp)) / n\n\n res = sum((real(x, dp) - mean)**2) / (n - merge(1, 0, optval(corrected, .true.)))\n\n end function var_all_1_iint64_dp\n module function var_all_2_iint64_dp(x, mask, corrected) result(res)\n integer(int64), intent(in) :: x(:,:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n, mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n mean = sum(real(x, dp)) / n\n\n res = sum((real(x, dp) - mean)**2) / (n - merge(1, 0, optval(corrected, .true.)))\n\n end function var_all_2_iint64_dp\n module function var_all_3_iint64_dp(x, mask, corrected) result(res)\n integer(int64), intent(in) :: x(:,:,:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n, mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n mean = sum(real(x, dp)) / n\n\n res = sum((real(x, dp) - mean)**2) / (n - merge(1, 0, optval(corrected, .true.)))\n\n end function var_all_3_iint64_dp\n module function var_all_4_iint64_dp(x, mask, corrected) result(res)\n integer(int64), intent(in) :: x(:,:,:,:)\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n, mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n mean = sum(real(x, dp)) / n\n\n res = sum((real(x, dp) - mean)**2) / (n - merge(1, 0, optval(corrected, .true.)))\n\n end function var_all_4_iint64_dp\n\n\n module function var_1_rsp_rsp(x, dim, mask, corrected) result(res)\n real(sp), intent(in) :: x(:)\n integer, intent(in) :: dim\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(sp) :: res\n\n integer :: i\n real(sp) :: n\n real(sp) :: mean\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._sp, ieee_quiet_nan)\n return\n end if\n\n res = 0._sp\n select case(dim)\n case(1)\n n = size(x, dim)\n mean = sum(x, dim) / n\n do i = 1, size(x, dim)\n res = res + (x(i) - mean)**2\n end do\n case default\n call error_stop(\"ERROR (var): wrong dimension\")\n end select\n res = res / (n - merge(1, 0, optval(corrected, .true.)))\n\n end function var_1_rsp_rsp\n module function var_2_rsp_rsp(x, dim, mask, corrected) result(res)\n real(sp), intent(in) :: x(:,:)\n integer, intent(in) :: dim\n logical, intent(in), optional :: mask\n logical, intent(in), optional :: corrected\n real(sp) :: res(merge(size(x, 1), size(x, 2), mask=1 0)))\n\n end function var_mask_all_1_rsp_rsp\n module function var_mask_all_2_rsp_rsp(x, mask, corrected) result(res)\n real(sp), intent(in) :: x(:,:)\n logical, intent(in) :: mask(:,:)\n logical, intent(in), optional :: corrected\n real(sp) :: res\n\n real(sp) :: n\n real(sp) :: mean\n\n n = real(count(mask, kind = int64), sp)\n mean = sum(x, mask) / n\n\n res = sum((x - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_2_rsp_rsp\n module function var_mask_all_3_rsp_rsp(x, mask, corrected) result(res)\n real(sp), intent(in) :: x(:,:,:)\n logical, intent(in) :: mask(:,:,:)\n logical, intent(in), optional :: corrected\n real(sp) :: res\n\n real(sp) :: n\n real(sp) :: mean\n\n n = real(count(mask, kind = int64), sp)\n mean = sum(x, mask) / n\n\n res = sum((x - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_3_rsp_rsp\n module function var_mask_all_4_rsp_rsp(x, mask, corrected) result(res)\n real(sp), intent(in) :: x(:,:,:,:)\n logical, intent(in) :: mask(:,:,:,:)\n logical, intent(in), optional :: corrected\n real(sp) :: res\n\n real(sp) :: n\n real(sp) :: mean\n\n n = real(count(mask, kind = int64), sp)\n mean = sum(x, mask) / n\n\n res = sum((x - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_4_rsp_rsp\n module function var_mask_all_1_rdp_rdp(x, mask, corrected) result(res)\n real(dp), intent(in) :: x(:)\n logical, intent(in) :: mask(:)\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n\n real(dp) :: mean\n\n n = real(count(mask, kind = int64), dp)\n mean = sum(x, mask) / n\n\n res = sum((x - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_1_rdp_rdp\n module function var_mask_all_2_rdp_rdp(x, mask, corrected) result(res)\n real(dp), intent(in) :: x(:,:)\n logical, intent(in) :: mask(:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n\n real(dp) :: mean\n\n n = real(count(mask, kind = int64), dp)\n mean = sum(x, mask) / n\n\n res = sum((x - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_2_rdp_rdp\n module function var_mask_all_3_rdp_rdp(x, mask, corrected) result(res)\n real(dp), intent(in) :: x(:,:,:)\n logical, intent(in) :: mask(:,:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n\n real(dp) :: mean\n\n n = real(count(mask, kind = int64), dp)\n mean = sum(x, mask) / n\n\n res = sum((x - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_3_rdp_rdp\n module function var_mask_all_4_rdp_rdp(x, mask, corrected) result(res)\n real(dp), intent(in) :: x(:,:,:,:)\n logical, intent(in) :: mask(:,:,:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n\n real(dp) :: mean\n\n n = real(count(mask, kind = int64), dp)\n mean = sum(x, mask) / n\n\n res = sum((x - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_4_rdp_rdp\n module function var_mask_all_1_rqp_rqp(x, mask, corrected) result(res)\n real(qp), intent(in) :: x(:)\n logical, intent(in) :: mask(:)\n logical, intent(in), optional :: corrected\n real(qp) :: res\n\n real(qp) :: n\n real(qp) :: mean\n\n n = real(count(mask, kind = int64), qp)\n mean = sum(x, mask) / n\n\n res = sum((x - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_1_rqp_rqp\n module function var_mask_all_2_rqp_rqp(x, mask, corrected) result(res)\n real(qp), intent(in) :: x(:,:)\n logical, intent(in) :: mask(:,:)\n logical, intent(in), optional :: corrected\n real(qp) :: res\n\n real(qp) :: n\n real(qp) :: mean\n\n n = real(count(mask, kind = int64), qp)\n mean = sum(x, mask) / n\n\n res = sum((x - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_2_rqp_rqp\n module function var_mask_all_3_rqp_rqp(x, mask, corrected) result(res)\n real(qp), intent(in) :: x(:,:,:)\n logical, intent(in) :: mask(:,:,:)\n logical, intent(in), optional :: corrected\n real(qp) :: res\n\n real(qp) :: n\n real(qp) :: mean\n\n n = real(count(mask, kind = int64), qp)\n mean = sum(x, mask) / n\n\n res = sum((x - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_3_rqp_rqp\n module function var_mask_all_4_rqp_rqp(x, mask, corrected) result(res)\n real(qp), intent(in) :: x(:,:,:,:)\n logical, intent(in) :: mask(:,:,:,:)\n logical, intent(in), optional :: corrected\n real(qp) :: res\n\n real(qp) :: n\n real(qp) :: mean\n\n n = real(count(mask, kind = int64), qp)\n mean = sum(x, mask) / n\n\n res = sum((x - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_4_rqp_rqp\n module function var_mask_all_1_csp_csp(x, mask, corrected) result(res)\n complex(sp), intent(in) :: x(:)\n logical, intent(in) :: mask(:)\n logical, intent(in), optional :: corrected\n real(sp) :: res\n\n real(sp) :: n\n complex(sp) :: mean\n\n n = real(count(mask, kind = int64), sp)\n mean = sum(x, mask) / n\n\n res = sum(abs(x - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_1_csp_csp\n module function var_mask_all_2_csp_csp(x, mask, corrected) result(res)\n complex(sp), intent(in) :: x(:,:)\n logical, intent(in) :: mask(:,:)\n logical, intent(in), optional :: corrected\n real(sp) :: res\n\n real(sp) :: n\n complex(sp) :: mean\n\n n = real(count(mask, kind = int64), sp)\n mean = sum(x, mask) / n\n\n res = sum(abs(x - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_2_csp_csp\n module function var_mask_all_3_csp_csp(x, mask, corrected) result(res)\n complex(sp), intent(in) :: x(:,:,:)\n logical, intent(in) :: mask(:,:,:)\n logical, intent(in), optional :: corrected\n real(sp) :: res\n\n real(sp) :: n\n complex(sp) :: mean\n\n n = real(count(mask, kind = int64), sp)\n mean = sum(x, mask) / n\n\n res = sum(abs(x - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_3_csp_csp\n module function var_mask_all_4_csp_csp(x, mask, corrected) result(res)\n complex(sp), intent(in) :: x(:,:,:,:)\n logical, intent(in) :: mask(:,:,:,:)\n logical, intent(in), optional :: corrected\n real(sp) :: res\n\n real(sp) :: n\n complex(sp) :: mean\n\n n = real(count(mask, kind = int64), sp)\n mean = sum(x, mask) / n\n\n res = sum(abs(x - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_4_csp_csp\n module function var_mask_all_1_cdp_cdp(x, mask, corrected) result(res)\n complex(dp), intent(in) :: x(:)\n logical, intent(in) :: mask(:)\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n\n complex(dp) :: mean\n\n n = real(count(mask, kind = int64), dp)\n mean = sum(x, mask) / n\n\n res = sum(abs(x - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_1_cdp_cdp\n module function var_mask_all_2_cdp_cdp(x, mask, corrected) result(res)\n complex(dp), intent(in) :: x(:,:)\n logical, intent(in) :: mask(:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n\n complex(dp) :: mean\n\n n = real(count(mask, kind = int64), dp)\n mean = sum(x, mask) / n\n\n res = sum(abs(x - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_2_cdp_cdp\n module function var_mask_all_3_cdp_cdp(x, mask, corrected) result(res)\n complex(dp), intent(in) :: x(:,:,:)\n logical, intent(in) :: mask(:,:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n\n complex(dp) :: mean\n\n n = real(count(mask, kind = int64), dp)\n mean = sum(x, mask) / n\n\n res = sum(abs(x - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_3_cdp_cdp\n module function var_mask_all_4_cdp_cdp(x, mask, corrected) result(res)\n complex(dp), intent(in) :: x(:,:,:,:)\n logical, intent(in) :: mask(:,:,:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n\n complex(dp) :: mean\n\n n = real(count(mask, kind = int64), dp)\n mean = sum(x, mask) / n\n\n res = sum(abs(x - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_4_cdp_cdp\n module function var_mask_all_1_cqp_cqp(x, mask, corrected) result(res)\n complex(qp), intent(in) :: x(:)\n logical, intent(in) :: mask(:)\n logical, intent(in), optional :: corrected\n real(qp) :: res\n\n real(qp) :: n\n complex(qp) :: mean\n\n n = real(count(mask, kind = int64), qp)\n mean = sum(x, mask) / n\n\n res = sum(abs(x - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_1_cqp_cqp\n module function var_mask_all_2_cqp_cqp(x, mask, corrected) result(res)\n complex(qp), intent(in) :: x(:,:)\n logical, intent(in) :: mask(:,:)\n logical, intent(in), optional :: corrected\n real(qp) :: res\n\n real(qp) :: n\n complex(qp) :: mean\n\n n = real(count(mask, kind = int64), qp)\n mean = sum(x, mask) / n\n\n res = sum(abs(x - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_2_cqp_cqp\n module function var_mask_all_3_cqp_cqp(x, mask, corrected) result(res)\n complex(qp), intent(in) :: x(:,:,:)\n logical, intent(in) :: mask(:,:,:)\n logical, intent(in), optional :: corrected\n real(qp) :: res\n\n real(qp) :: n\n complex(qp) :: mean\n\n n = real(count(mask, kind = int64), qp)\n mean = sum(x, mask) / n\n\n res = sum(abs(x - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_3_cqp_cqp\n module function var_mask_all_4_cqp_cqp(x, mask, corrected) result(res)\n complex(qp), intent(in) :: x(:,:,:,:)\n logical, intent(in) :: mask(:,:,:,:)\n logical, intent(in), optional :: corrected\n real(qp) :: res\n\n real(qp) :: n\n complex(qp) :: mean\n\n n = real(count(mask, kind = int64), qp)\n mean = sum(x, mask) / n\n\n res = sum(abs(x - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_4_cqp_cqp\n\n\n module function var_mask_all_1_iint8_dp(x, mask, corrected) result(res)\n integer(int8), intent(in) :: x(:)\n logical, intent(in) :: mask(:)\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n, mean\n\n n = real(count(mask, kind = int64), dp)\n mean = sum(real(x, dp), mask) / n\n\n res = sum((real(x, dp) - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_1_iint8_dp\n module function var_mask_all_2_iint8_dp(x, mask, corrected) result(res)\n integer(int8), intent(in) :: x(:,:)\n logical, intent(in) :: mask(:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n, mean\n\n n = real(count(mask, kind = int64), dp)\n mean = sum(real(x, dp), mask) / n\n\n res = sum((real(x, dp) - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_2_iint8_dp\n module function var_mask_all_3_iint8_dp(x, mask, corrected) result(res)\n integer(int8), intent(in) :: x(:,:,:)\n logical, intent(in) :: mask(:,:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n, mean\n\n n = real(count(mask, kind = int64), dp)\n mean = sum(real(x, dp), mask) / n\n\n res = sum((real(x, dp) - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_3_iint8_dp\n module function var_mask_all_4_iint8_dp(x, mask, corrected) result(res)\n integer(int8), intent(in) :: x(:,:,:,:)\n logical, intent(in) :: mask(:,:,:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n, mean\n\n n = real(count(mask, kind = int64), dp)\n mean = sum(real(x, dp), mask) / n\n\n res = sum((real(x, dp) - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_4_iint8_dp\n module function var_mask_all_1_iint16_dp(x, mask, corrected) result(res)\n integer(int16), intent(in) :: x(:)\n logical, intent(in) :: mask(:)\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n, mean\n\n n = real(count(mask, kind = int64), dp)\n mean = sum(real(x, dp), mask) / n\n\n res = sum((real(x, dp) - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_1_iint16_dp\n module function var_mask_all_2_iint16_dp(x, mask, corrected) result(res)\n integer(int16), intent(in) :: x(:,:)\n logical, intent(in) :: mask(:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n, mean\n\n n = real(count(mask, kind = int64), dp)\n mean = sum(real(x, dp), mask) / n\n\n res = sum((real(x, dp) - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_2_iint16_dp\n module function var_mask_all_3_iint16_dp(x, mask, corrected) result(res)\n integer(int16), intent(in) :: x(:,:,:)\n logical, intent(in) :: mask(:,:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n, mean\n\n n = real(count(mask, kind = int64), dp)\n mean = sum(real(x, dp), mask) / n\n\n res = sum((real(x, dp) - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_3_iint16_dp\n module function var_mask_all_4_iint16_dp(x, mask, corrected) result(res)\n integer(int16), intent(in) :: x(:,:,:,:)\n logical, intent(in) :: mask(:,:,:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n, mean\n\n n = real(count(mask, kind = int64), dp)\n mean = sum(real(x, dp), mask) / n\n\n res = sum((real(x, dp) - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_4_iint16_dp\n module function var_mask_all_1_iint32_dp(x, mask, corrected) result(res)\n integer(int32), intent(in) :: x(:)\n logical, intent(in) :: mask(:)\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n, mean\n\n n = real(count(mask, kind = int64), dp)\n mean = sum(real(x, dp), mask) / n\n\n res = sum((real(x, dp) - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_1_iint32_dp\n module function var_mask_all_2_iint32_dp(x, mask, corrected) result(res)\n integer(int32), intent(in) :: x(:,:)\n logical, intent(in) :: mask(:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n, mean\n\n n = real(count(mask, kind = int64), dp)\n mean = sum(real(x, dp), mask) / n\n\n res = sum((real(x, dp) - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_2_iint32_dp\n module function var_mask_all_3_iint32_dp(x, mask, corrected) result(res)\n integer(int32), intent(in) :: x(:,:,:)\n logical, intent(in) :: mask(:,:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n, mean\n\n n = real(count(mask, kind = int64), dp)\n mean = sum(real(x, dp), mask) / n\n\n res = sum((real(x, dp) - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_3_iint32_dp\n module function var_mask_all_4_iint32_dp(x, mask, corrected) result(res)\n integer(int32), intent(in) :: x(:,:,:,:)\n logical, intent(in) :: mask(:,:,:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n, mean\n\n n = real(count(mask, kind = int64), dp)\n mean = sum(real(x, dp), mask) / n\n\n res = sum((real(x, dp) - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_4_iint32_dp\n module function var_mask_all_1_iint64_dp(x, mask, corrected) result(res)\n integer(int64), intent(in) :: x(:)\n logical, intent(in) :: mask(:)\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n, mean\n\n n = real(count(mask, kind = int64), dp)\n mean = sum(real(x, dp), mask) / n\n\n res = sum((real(x, dp) - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_1_iint64_dp\n module function var_mask_all_2_iint64_dp(x, mask, corrected) result(res)\n integer(int64), intent(in) :: x(:,:)\n logical, intent(in) :: mask(:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n, mean\n\n n = real(count(mask, kind = int64), dp)\n mean = sum(real(x, dp), mask) / n\n\n res = sum((real(x, dp) - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_2_iint64_dp\n module function var_mask_all_3_iint64_dp(x, mask, corrected) result(res)\n integer(int64), intent(in) :: x(:,:,:)\n logical, intent(in) :: mask(:,:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n, mean\n\n n = real(count(mask, kind = int64), dp)\n mean = sum(real(x, dp), mask) / n\n\n res = sum((real(x, dp) - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_3_iint64_dp\n module function var_mask_all_4_iint64_dp(x, mask, corrected) result(res)\n integer(int64), intent(in) :: x(:,:,:,:)\n logical, intent(in) :: mask(:,:,:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n real(dp) :: n, mean\n\n n = real(count(mask, kind = int64), dp)\n mean = sum(real(x, dp), mask) / n\n\n res = sum((real(x, dp) - mean)**2, mask) / (n -&\n merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_all_4_iint64_dp\n\n\n module function var_mask_1_rsp_rsp(x, dim, mask, corrected) result(res)\n real(sp), intent(in) :: x(:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:)\n logical, intent(in), optional :: corrected\n real(sp) :: res\n\n integer :: i\n real(sp) :: n\n real(sp) :: mean\n\n res = 0._sp\n select case(dim)\n case(1)\n n = count(mask, dim)\n mean = sum(x, dim, mask) / n\n do i = 1, size(x, dim)\n res = res + merge( (x(i) - mean)**2,&\n 0._sp,&\n mask(i))\n end do\n case default\n call error_stop(\"ERROR (var): wrong dimension\")\n end select\n res = res / (n - merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_1_rsp_rsp\n module function var_mask_2_rsp_rsp(x, dim, mask, corrected) result(res)\n real(sp), intent(in) :: x(:,:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:,:)\n logical, intent(in), optional :: corrected\n real(sp) :: res(merge(size(x, 1), size(x, 2), mask=1 0)))\n\n end function var_mask_2_rsp_rsp\n module function var_mask_3_rsp_rsp(x, dim, mask, corrected) result(res)\n real(sp), intent(in) :: x(:,:,:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:,:,:)\n logical, intent(in), optional :: corrected\n real(sp) :: res(merge(size(x, 1), size(x, 2), mask=1 0)))\n\n end function var_mask_3_rsp_rsp\n module function var_mask_4_rsp_rsp(x, dim, mask, corrected) result(res)\n real(sp), intent(in) :: x(:,:,:,:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:,:,:,:)\n logical, intent(in), optional :: corrected\n real(sp) :: res(merge(size(x, 1), size(x, 2), mask=1 0)))\n\n end function var_mask_4_rsp_rsp\n module function var_mask_1_rdp_rdp(x, dim, mask, corrected) result(res)\n real(dp), intent(in) :: x(:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:)\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n integer :: i\n real(dp) :: n\n real(dp) :: mean\n\n res = 0._dp\n select case(dim)\n case(1)\n n = count(mask, dim)\n mean = sum(x, dim, mask) / n\n do i = 1, size(x, dim)\n res = res + merge( (x(i) - mean)**2,&\n 0._dp,&\n mask(i))\n end do\n case default\n call error_stop(\"ERROR (var): wrong dimension\")\n end select\n res = res / (n - merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_1_rdp_rdp\n module function var_mask_2_rdp_rdp(x, dim, mask, corrected) result(res)\n real(dp), intent(in) :: x(:,:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res(merge(size(x, 1), size(x, 2), mask=1 0)))\n\n end function var_mask_2_rdp_rdp\n module function var_mask_3_rdp_rdp(x, dim, mask, corrected) result(res)\n real(dp), intent(in) :: x(:,:,:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:,:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res(merge(size(x, 1), size(x, 2), mask=1 0)))\n\n end function var_mask_3_rdp_rdp\n module function var_mask_4_rdp_rdp(x, dim, mask, corrected) result(res)\n real(dp), intent(in) :: x(:,:,:,:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:,:,:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res(merge(size(x, 1), size(x, 2), mask=1 0)))\n\n end function var_mask_4_rdp_rdp\n module function var_mask_1_rqp_rqp(x, dim, mask, corrected) result(res)\n real(qp), intent(in) :: x(:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:)\n logical, intent(in), optional :: corrected\n real(qp) :: res\n\n integer :: i\n real(qp) :: n\n real(qp) :: mean\n\n res = 0._qp\n select case(dim)\n case(1)\n n = count(mask, dim)\n mean = sum(x, dim, mask) / n\n do i = 1, size(x, dim)\n res = res + merge( (x(i) - mean)**2,&\n 0._qp,&\n mask(i))\n end do\n case default\n call error_stop(\"ERROR (var): wrong dimension\")\n end select\n res = res / (n - merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_1_rqp_rqp\n module function var_mask_2_rqp_rqp(x, dim, mask, corrected) result(res)\n real(qp), intent(in) :: x(:,:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:,:)\n logical, intent(in), optional :: corrected\n real(qp) :: res(merge(size(x, 1), size(x, 2), mask=1 0)))\n\n end function var_mask_2_rqp_rqp\n module function var_mask_3_rqp_rqp(x, dim, mask, corrected) result(res)\n real(qp), intent(in) :: x(:,:,:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:,:,:)\n logical, intent(in), optional :: corrected\n real(qp) :: res(merge(size(x, 1), size(x, 2), mask=1 0)))\n\n end function var_mask_3_rqp_rqp\n module function var_mask_4_rqp_rqp(x, dim, mask, corrected) result(res)\n real(qp), intent(in) :: x(:,:,:,:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:,:,:,:)\n logical, intent(in), optional :: corrected\n real(qp) :: res(merge(size(x, 1), size(x, 2), mask=1 0)))\n\n end function var_mask_4_rqp_rqp\n module function var_mask_1_csp_csp(x, dim, mask, corrected) result(res)\n complex(sp), intent(in) :: x(:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:)\n logical, intent(in), optional :: corrected\n real(sp) :: res\n\n integer :: i\n real(sp) :: n\n complex(sp) :: mean\n\n res = 0._sp\n select case(dim)\n case(1)\n n = count(mask, dim)\n mean = sum(x, dim, mask) / n\n do i = 1, size(x, dim)\n res = res + merge( abs(x(i) - mean)**2,&\n 0._sp,&\n mask(i))\n end do\n case default\n call error_stop(\"ERROR (var): wrong dimension\")\n end select\n res = res / (n - merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_1_csp_csp\n module function var_mask_2_csp_csp(x, dim, mask, corrected) result(res)\n complex(sp), intent(in) :: x(:,:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:,:)\n logical, intent(in), optional :: corrected\n real(sp) :: res(merge(size(x, 1), size(x, 2), mask=1 0)))\n\n end function var_mask_2_csp_csp\n module function var_mask_3_csp_csp(x, dim, mask, corrected) result(res)\n complex(sp), intent(in) :: x(:,:,:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:,:,:)\n logical, intent(in), optional :: corrected\n real(sp) :: res(merge(size(x, 1), size(x, 2), mask=1 0)))\n\n end function var_mask_3_csp_csp\n module function var_mask_4_csp_csp(x, dim, mask, corrected) result(res)\n complex(sp), intent(in) :: x(:,:,:,:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:,:,:,:)\n logical, intent(in), optional :: corrected\n real(sp) :: res(merge(size(x, 1), size(x, 2), mask=1 0)))\n\n end function var_mask_4_csp_csp\n module function var_mask_1_cdp_cdp(x, dim, mask, corrected) result(res)\n complex(dp), intent(in) :: x(:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:)\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n integer :: i\n real(dp) :: n\n complex(dp) :: mean\n\n res = 0._dp\n select case(dim)\n case(1)\n n = count(mask, dim)\n mean = sum(x, dim, mask) / n\n do i = 1, size(x, dim)\n res = res + merge( abs(x(i) - mean)**2,&\n 0._dp,&\n mask(i))\n end do\n case default\n call error_stop(\"ERROR (var): wrong dimension\")\n end select\n res = res / (n - merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_1_cdp_cdp\n module function var_mask_2_cdp_cdp(x, dim, mask, corrected) result(res)\n complex(dp), intent(in) :: x(:,:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res(merge(size(x, 1), size(x, 2), mask=1 0)))\n\n end function var_mask_2_cdp_cdp\n module function var_mask_3_cdp_cdp(x, dim, mask, corrected) result(res)\n complex(dp), intent(in) :: x(:,:,:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:,:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res(merge(size(x, 1), size(x, 2), mask=1 0)))\n\n end function var_mask_3_cdp_cdp\n module function var_mask_4_cdp_cdp(x, dim, mask, corrected) result(res)\n complex(dp), intent(in) :: x(:,:,:,:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:,:,:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res(merge(size(x, 1), size(x, 2), mask=1 0)))\n\n end function var_mask_4_cdp_cdp\n module function var_mask_1_cqp_cqp(x, dim, mask, corrected) result(res)\n complex(qp), intent(in) :: x(:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:)\n logical, intent(in), optional :: corrected\n real(qp) :: res\n\n integer :: i\n real(qp) :: n\n complex(qp) :: mean\n\n res = 0._qp\n select case(dim)\n case(1)\n n = count(mask, dim)\n mean = sum(x, dim, mask) / n\n do i = 1, size(x, dim)\n res = res + merge( abs(x(i) - mean)**2,&\n 0._qp,&\n mask(i))\n end do\n case default\n call error_stop(\"ERROR (var): wrong dimension\")\n end select\n res = res / (n - merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_1_cqp_cqp\n module function var_mask_2_cqp_cqp(x, dim, mask, corrected) result(res)\n complex(qp), intent(in) :: x(:,:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:,:)\n logical, intent(in), optional :: corrected\n real(qp) :: res(merge(size(x, 1), size(x, 2), mask=1 0)))\n\n end function var_mask_2_cqp_cqp\n module function var_mask_3_cqp_cqp(x, dim, mask, corrected) result(res)\n complex(qp), intent(in) :: x(:,:,:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:,:,:)\n logical, intent(in), optional :: corrected\n real(qp) :: res(merge(size(x, 1), size(x, 2), mask=1 0)))\n\n end function var_mask_3_cqp_cqp\n module function var_mask_4_cqp_cqp(x, dim, mask, corrected) result(res)\n complex(qp), intent(in) :: x(:,:,:,:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:,:,:,:)\n logical, intent(in), optional :: corrected\n real(qp) :: res(merge(size(x, 1), size(x, 2), mask=1 0)))\n\n end function var_mask_4_cqp_cqp\n\n\n module function var_mask_1_iint8_dp(x, dim, mask, corrected) result(res)\n integer(int8), intent(in) :: x(:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:)\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n integer :: i\n real(dp) :: n\n real(dp) :: mean\n\n res = 0._dp\n select case(dim)\n case(1)\n n = count(mask, dim)\n mean = sum(real(x, dp), dim, mask) / n\n do i = 1, size(x, dim)\n res = res + merge((real(x(i), dp) - mean)**2,&\n 0._dp, mask(i))\n end do\n case default\n call error_stop(\"ERROR (var): wrong dimension\")\n end select\n res = res / (n - merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_1_iint8_dp\n module function var_mask_2_iint8_dp(x, dim, mask, corrected) result(res)\n integer(int8), intent(in) :: x(:,:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res(merge(size(x, 1), size(x, 2), mask=1 0)))\n\n end function var_mask_2_iint8_dp\n module function var_mask_3_iint8_dp(x, dim, mask, corrected) result(res)\n integer(int8), intent(in) :: x(:,:,:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:,:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res(merge(size(x, 1), size(x, 2), mask=1 0)))\n\n end function var_mask_3_iint8_dp\n module function var_mask_4_iint8_dp(x, dim, mask, corrected) result(res)\n integer(int8), intent(in) :: x(:,:,:,:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:,:,:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res(merge(size(x, 1), size(x, 2), mask=1 0)))\n\n end function var_mask_4_iint8_dp\n module function var_mask_1_iint16_dp(x, dim, mask, corrected) result(res)\n integer(int16), intent(in) :: x(:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:)\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n integer :: i\n real(dp) :: n\n real(dp) :: mean\n\n res = 0._dp\n select case(dim)\n case(1)\n n = count(mask, dim)\n mean = sum(real(x, dp), dim, mask) / n\n do i = 1, size(x, dim)\n res = res + merge((real(x(i), dp) - mean)**2,&\n 0._dp, mask(i))\n end do\n case default\n call error_stop(\"ERROR (var): wrong dimension\")\n end select\n res = res / (n - merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_1_iint16_dp\n module function var_mask_2_iint16_dp(x, dim, mask, corrected) result(res)\n integer(int16), intent(in) :: x(:,:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res(merge(size(x, 1), size(x, 2), mask=1 0)))\n\n end function var_mask_2_iint16_dp\n module function var_mask_3_iint16_dp(x, dim, mask, corrected) result(res)\n integer(int16), intent(in) :: x(:,:,:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:,:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res(merge(size(x, 1), size(x, 2), mask=1 0)))\n\n end function var_mask_3_iint16_dp\n module function var_mask_4_iint16_dp(x, dim, mask, corrected) result(res)\n integer(int16), intent(in) :: x(:,:,:,:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:,:,:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res(merge(size(x, 1), size(x, 2), mask=1 0)))\n\n end function var_mask_4_iint16_dp\n module function var_mask_1_iint32_dp(x, dim, mask, corrected) result(res)\n integer(int32), intent(in) :: x(:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:)\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n integer :: i\n real(dp) :: n\n real(dp) :: mean\n\n res = 0._dp\n select case(dim)\n case(1)\n n = count(mask, dim)\n mean = sum(real(x, dp), dim, mask) / n\n do i = 1, size(x, dim)\n res = res + merge((real(x(i), dp) - mean)**2,&\n 0._dp, mask(i))\n end do\n case default\n call error_stop(\"ERROR (var): wrong dimension\")\n end select\n res = res / (n - merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_1_iint32_dp\n module function var_mask_2_iint32_dp(x, dim, mask, corrected) result(res)\n integer(int32), intent(in) :: x(:,:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res(merge(size(x, 1), size(x, 2), mask=1 0)))\n\n end function var_mask_2_iint32_dp\n module function var_mask_3_iint32_dp(x, dim, mask, corrected) result(res)\n integer(int32), intent(in) :: x(:,:,:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:,:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res(merge(size(x, 1), size(x, 2), mask=1 0)))\n\n end function var_mask_3_iint32_dp\n module function var_mask_4_iint32_dp(x, dim, mask, corrected) result(res)\n integer(int32), intent(in) :: x(:,:,:,:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:,:,:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res(merge(size(x, 1), size(x, 2), mask=1 0)))\n\n end function var_mask_4_iint32_dp\n module function var_mask_1_iint64_dp(x, dim, mask, corrected) result(res)\n integer(int64), intent(in) :: x(:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:)\n logical, intent(in), optional :: corrected\n real(dp) :: res\n\n integer :: i\n real(dp) :: n\n real(dp) :: mean\n\n res = 0._dp\n select case(dim)\n case(1)\n n = count(mask, dim)\n mean = sum(real(x, dp), dim, mask) / n\n do i = 1, size(x, dim)\n res = res + merge((real(x(i), dp) - mean)**2,&\n 0._dp, mask(i))\n end do\n case default\n call error_stop(\"ERROR (var): wrong dimension\")\n end select\n res = res / (n - merge(1, 0, (optval(corrected, .true.) .and. n > 0)))\n\n end function var_mask_1_iint64_dp\n module function var_mask_2_iint64_dp(x, dim, mask, corrected) result(res)\n integer(int64), intent(in) :: x(:,:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res(merge(size(x, 1), size(x, 2), mask=1 0)))\n\n end function var_mask_2_iint64_dp\n module function var_mask_3_iint64_dp(x, dim, mask, corrected) result(res)\n integer(int64), intent(in) :: x(:,:,:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:,:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res(merge(size(x, 1), size(x, 2), mask=1 0)))\n\n end function var_mask_3_iint64_dp\n module function var_mask_4_iint64_dp(x, dim, mask, corrected) result(res)\n integer(int64), intent(in) :: x(:,:,:,:)\n integer, intent(in) :: dim\n logical, intent(in) :: mask(:,:,:,:)\n logical, intent(in), optional :: corrected\n real(dp) :: res(merge(size(x, 1), size(x, 2), mask=1 0)))\n\n end function var_mask_4_iint64_dp\n\nend submodule\n", "meta": {"hexsha": "3db7ac65dcf3d25c94c03d90e3e2ec0f2d6cc1a9", "size": 161089, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/stdlib_stats_var.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_stats_var.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_stats_var.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": 35.2955740578, "max_line_length": 129, "alphanum_fraction": 0.4633649722, "num_tokens": 46872, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6667430245037245}} {"text": "! =====================================================================\n! NAME\n!\n! GPECN1DTDPBC - GPE = Gross-Pitaevskii Equation; \n! CN = Crank-Nicolson Method\n! 1D = One-Dimensional\n! TD = Time-dependent\n! PBC = Periodic Boundary Conditions\n!\n! DESCRIPTION\n!\n! GPECN1DTDPBC is a Fortran-based program that solves the \n! time-dependent Gross-Pitevsekii equation (GPE) in a uniformly \n! rotating reference frame for a single component Bose-Einstein \n! condensate (BEC) in one-dimension using the Crank-Nicolson finite \n! difference scheme. \n! \n! This implementation of the Crank-Nicolson scheme attempts to \n! properly account for the time-dependence of the external and \n! mean-field potentials of the condensate by deriving the scheme using\n! the integral form of the unitary time-evolution operator for a \n! time-dependent Hamiltonian. An iterative approach is then used to \n! determine the unknown mean-field potential at each time step. \n!\n! In addition, the program assumes an S1 configuration space for the \n! system (i.e., the condesate is propagating in a one-dimensional, \n! cicular ring) and therefore implements periodic boundary conditions\n! using the Sherman-Morrison algorithm.\n!\n! USAGE\n!\n! make\n! ./gpecn1Dtdpbc.sh\n!\n! DEPENDENCIES\n!\n! GPECN1DTDPBC depends on the ZGTSV and XERBLA subroutines from LAPACK \n! version 3.1.0. The source code for these subroutines as well as \n! the LAPACK LICENSE file are distributed with GPECN1DTDPBC and may be\n! found in libraries/lapack subdirectory.\n!\n! CITATION\n!\n! To cite the use of this work in a scientific publication, please use \n! the following reference:\n!\n! @unpublished{kandesmc:2011a,\n! author = \"Kandes, M. C.\", \n! title = \"Sagnac Interferometry with Bose-Einstein Condensates in\n! a Uniformly Rotating Ring Trap\",\n! school = \"Claremont Graduate University \\& San Diego State \n! University\",\n! note = \"Ph.D. Qualifying Exam\",\n! year = \"2011\",\n! }\n!\n! AUTHOR\n!\n! Marty Kandes, Ph.D.\n! Computational & Data Science Research Specialist\n! User Services Group\n! San Diego Supercomputer Center\n! University of California, San Diego\n!\n! COPYRIGHT\n! \n! Copyright (c) 2010 - 2021 Martin Charles Kandes\n!\n! LICENSE\n!\n! The MIT License (MIT)\n!\n! LAST UPDATED\n!\n! Friday, March 31st, 2017 \n!\n! ----------------------------------------------------------------------\n PROGRAM GPECN1DTDPBC\n IMPLICIT NONE\n\n! Parameter Declarations:\n! -----------------------\n REAL, PARAMETER :: PI = 3.1415926535897932384626433832795028842E0\n\n! Input Variable and Array Declarations:\n! --------------------------------------\n INTEGER :: NUMBER_OF_GRID_POINTS \n INTEGER :: NUMBER_OF_TIME_STEPS\n INTEGER :: NUMBER_OF_TIME_STEPS_BEFORE_WRITE\n INTEGER :: NUMBER_OF_ITERATIONS_PER_TIME_STEP\n INTEGER :: IMAGINARY_TIME_SWITCH\n\n REAL :: RADIUS\n REAL :: ROTATION_RATE\n REAL :: GAMMA_FACTOR\n\n COMPLEX, ALLOCATABLE, DIMENSION(:) :: WAVEFUNCTION\n COMPLEX, ALLOCATABLE, DIMENSION(:) :: EXTERNAL_POTENTIAL\n COMPLEX, ALLOCATABLE, DIMENSION(:) :: NONLINEAR_COUPLING\n\n! Internal Variable and Array Declarations:\n! -----------------------------------------\n CHARACTER(80) :: BUFFER\n\n INTEGER :: CURRENT_GRID_POINT\n INTEGER :: CURRENT_TIME_STEP\n INTEGER :: CURRENT_ITERATION\n INTEGER :: CURRENT_FILE\n INTEGER :: LENGTH\n INTEGER :: INFO\n\n REAL :: ANGULAR_GRID_SPACING_SIZE\n REAL :: TIME_STEP_SIZE\n\n REAL :: L2NORM\n\n COMPLEX, ALLOCATABLE, DIMENSION(:) :: TEMPORARY_STORAGE\n COMPLEX, ALLOCATABLE, DIMENSION(:) :: RIGHT_HAND_SIDE\n COMPLEX, ALLOCATABLE, DIMENSION(:) :: UPPER_DIAGONAL\n COMPLEX, ALLOCATABLE, DIMENSION(:) :: MAIN_DIAGONAL\n COMPLEX, ALLOCATABLE, DIMENSION(:) :: LOWER_DIAGONAL\n COMPLEX, ALLOCATABLE, DIMENSION(:) :: W\n COMPLEX, ALLOCATABLE, DIMENSION(:) :: Z\n\n! Input Variable Assignment Read from Command-line Arguments:\n! -----------------------------------------------------------\n CALL GET_COMMAND_ARGUMENT(1,BUFFER,LENGTH,INFO)\n READ(BUFFER,*) NUMBER_OF_GRID_POINTS\n\n CALL GET_COMMAND_ARGUMENT(2,BUFFER,LENGTH,INFO)\n READ(BUFFER,*) NUMBER_OF_TIME_STEPS\n\n CALL GET_COMMAND_ARGUMENT(3,BUFFER,LENGTH,INFO)\n READ(BUFFER,*) NUMBER_OF_TIME_STEPS_BEFORE_WRITE\n\n CALL GET_COMMAND_ARGUMENT(4,BUFFER,LENGTH,INFO)\n READ(BUFFER,*) NUMBER_OF_ITERATIONS_PER_TIME_STEP\n\n CALL GET_COMMAND_ARGUMENT(5,BUFFER,LENGTH,INFO)\n READ(BUFFER,*) IMAGINARY_TIME_SWITCH\n\n CALL GET_COMMAND_ARGUMENT(6,BUFFER,LENGTH,INFO)\n READ(BUFFER,*) RADIUS\n\n CALL GET_COMMAND_ARGUMENT(7,BUFFER,LENGTH,INFO)\n READ(BUFFER,*) ROTATION_RATE\n\n CALL GET_COMMAND_ARGUMENT(8,BUFFER,LENGTH,INFO)\n READ(BUFFER,*) GAMMA_FACTOR\n\n! Allocate Arrays:\n! ----------------\n ALLOCATE(WAVEFUNCTION(NUMBER_OF_GRID_POINTS))\n ALLOCATE(EXTERNAL_POTENTIAL(NUMBER_OF_GRID_POINTS))\n ALLOCATE(NONLINEAR_COUPLING(NUMBER_OF_GRID_POINTS))\n ALLOCATE(TEMPORARY_STORAGE(NUMBER_OF_GRID_POINTS))\n ALLOCATE(RIGHT_HAND_SIDE(NUMBER_OF_GRID_POINTS))\n ALLOCATE(UPPER_DIAGONAL(NUMBER_OF_GRID_POINTS-1))\n ALLOCATE(MAIN_DIAGONAL(NUMBER_OF_GRID_POINTS))\n ALLOCATE(LOWER_DIAGONAL(NUMBER_OF_GRID_POINTS-1))\n ALLOCATE(W(NUMBER_OF_GRID_POINTS))\n ALLOCATE(Z(NUMBER_OF_GRID_POINTS))\n\n! Internal Variable Assignment:\n! -----------------------------\n ANGULAR_GRID_SPACING_SIZE = 2.0E0*PI/FLOAT(NUMBER_OF_GRID_POINTS)\n TIME_STEP_SIZE = (RADIUS*ANGULAR_GRID_SPACING_SIZE)**2/(2.0E0*GAMMA_FACTOR)\n\n! Read Input Arrays from File:\n! ----------------------------\n OPEN(UNIT=1000,ACTION='READ',FORM='UNFORMATTED',STATUS='OLD')\n READ(UNIT=1000) WAVEFUNCTION\n CLOSE(UNIT=1000,STATUS='KEEP')\n\n OPEN(UNIT=999,ACTION='READ',FORM='UNFORMATTED',STATUS='OLD')\n READ(UNIT=999) EXTERNAL_POTENTIAL\n CLOSE(UNIT=999,STATUS='KEEP')\n\n OPEN(UNIT=998,ACTION='READ',FORM='UNFORMATTED',STATUS='OLD')\n READ(UNIT=998) NONLINEAR_COUPLING\n CLOSE(UNIT=998,STATUS='KEEP')\n\n! Initializations:\n! ----------------\n CURRENT_FILE = 1001\n\n! Main Program Loop:\n! ------------------\n DO CURRENT_TIME_STEP = 1, NUMBER_OF_TIME_STEPS\n TEMPORARY_STORAGE = WAVEFUNCTION\n DO CURRENT_ITERATION = 1, NUMBER_OF_ITERATIONS_PER_TIME_STEP\n UPPER_DIAGONAL = CMPLX((ROTATION_RATE*TIME_STEP_SIZE)/(4.0E0*ANGULAR_GRID_SPACING_SIZE),TIME_STEP_SIZE/(4.0E0*RADIUS**2*ANGULAR_GRID_SPACING_SIZE**2))\n MAIN_DIAGONAL = CMPLX(1.0E0,0.0E0)-CMPLX(0.0E0,TIME_STEP_SIZE/4.0E0)*(CMPLX(2.0E0/(RADIUS**2*ANGULAR_GRID_SPACING_SIZE**2),0.0E0)+CMPLX(2.0E0,0.0E0)*EXTERNAL_POTENTIAL+NONLINEAR_COUPLING*CMPLX(ABS(WAVEFUNCTION)**2+ABS(TEMPORARY_STORAGE)**2,0.0E0))\n LOWER_DIAGONAL = -CONJG(UPPER_DIAGONAL)\n RIGHT_HAND_SIDE(1) = UPPER_DIAGONAL(1)*TEMPORARY_STORAGE(2)+MAIN_DIAGONAL(1)*TEMPORARY_STORAGE(1)+LOWER_DIAGONAL(1)*TEMPORARY_STORAGE(NUMBER_OF_GRID_POINTS)\n DO CURRENT_GRID_POINT = 2, NUMBER_OF_GRID_POINTS-1\n RIGHT_HAND_SIDE(CURRENT_GRID_POINT) = UPPER_DIAGONAL(CURRENT_GRID_POINT)*TEMPORARY_STORAGE(CURRENT_GRID_POINT+1)+MAIN_DIAGONAL(CURRENT_GRID_POINT)*TEMPORARY_STORAGE(CURRENT_GRID_POINT)+LOWER_DIAGONAL(CURRENT_GRID_POINT-1)*TEMPORARY_STORAGE(CURRENT_GRID_POINT-1)\n ENDDO\n RIGHT_HAND_SIDE(NUMBER_OF_GRID_POINTS) = UPPER_DIAGONAL(NUMBER_OF_GRID_POINTS-1)*TEMPORARY_STORAGE(1)+MAIN_DIAGONAL(NUMBER_OF_GRID_POINTS)*TEMPORARY_STORAGE(NUMBER_OF_GRID_POINTS)+LOWER_DIAGONAL(NUMBER_OF_GRID_POINTS-1)*TEMPORARY_STORAGE(NUMBER_OF_GRID_POINTS-1)\n UPPER_DIAGONAL = -UPPER_DIAGONAL\n MAIN_DIAGONAL = CONJG(MAIN_DIAGONAL)\n LOWER_DIAGONAL = -LOWER_DIAGONAL\n W = CMPLX(0.0E0,0.0E0)\n Z = CMPLX(0.0E0,0.0E0)\n W(1) = CMPLX(1.0E0,0.0E0)\n W(NUMBER_OF_GRID_POINTS) = CMPLX(1.0E0,0.0E0)\n Z(1) = -UPPER_DIAGONAL(1)\n Z(NUMBER_OF_GRID_POINTS) = -LOWER_DIAGONAL(1)\n MAIN_DIAGONAL(1) = MAIN_DIAGONAL(1)+W(1)*Z(1)\n MAIN_DIAGONAL(NUMBER_OF_GRID_POINTS) = MAIN_DIAGONAL(NUMBER_OF_GRID_POINTS)+W(NUMBER_OF_GRID_POINTS)*Z(NUMBER_OF_GRID_POINTS)\n CALL ZGTSV(NUMBER_OF_GRID_POINTS,1,LOWER_DIAGONAL,MAIN_DIAGONAL,UPPER_DIAGONAL,RIGHT_HAND_SIDE,NUMBER_OF_GRID_POINTS,INFO)\n UPPER_DIAGONAL = -CMPLX((ROTATION_RATE*TIME_STEP_SIZE)/(4.0E0*ANGULAR_GRID_SPACING_SIZE),TIME_STEP_SIZE/(4.0E0*RADIUS**2*ANGULAR_GRID_SPACING_SIZE**2))\n MAIN_DIAGONAL = CMPLX(1.0E0,0.0E0)+CMPLX(0.0E0,TIME_STEP_SIZE/4.0E0)*(CMPLX(2.0E0/(RADIUS**2*ANGULAR_GRID_SPACING_SIZE**2),0.0E0)+CMPLX(2.0E0,0.0E0)*EXTERNAL_POTENTIAL+NONLINEAR_COUPLING*CMPLX(ABS(WAVEFUNCTION)**2+ABS(TEMPORARY_STORAGE)**2,0.0E0))\n LOWER_DIAGONAL = -CONJG(UPPER_DIAGONAL)\n MAIN_DIAGONAL(1) = MAIN_DIAGONAL(1)+W(1)*Z(1)\n MAIN_DIAGONAL(NUMBER_OF_GRID_POINTS) = MAIN_DIAGONAL(NUMBER_OF_GRID_POINTS)+W(NUMBER_OF_GRID_POINTS)*Z(NUMBER_OF_GRID_POINTS)\n CALL ZGTSV(NUMBER_OF_GRID_POINTS,1,LOWER_DIAGONAL,MAIN_DIAGONAL,UPPER_DIAGONAL,W,NUMBER_OF_GRID_POINTS,INFO)\n WAVEFUNCTION = RIGHT_HAND_SIDE+(SUM(Z*RIGHT_HAND_SIDE)/(CMPLX(1.0E0,0.0E0)-SUM(Z*W)))*W\n ENDDO\n IF (MODULO(CURRENT_TIME_STEP,NUMBER_OF_TIME_STEPS_BEFORE_WRITE).EQ.0) THEN\n OPEN(UNIT=CURRENT_FILE,ACTION='WRITE',FORM='UNFORMATTED')\n WRITE(UNIT=CURRENT_FILE) WAVEFUNCTION\n CLOSE(UNIT=CURRENT_FILE)\n CURRENT_FILE = CURRENT_FILE + 1\n ENDIF\n ENDDO\n\n! Deallocate Arrays:\n! ------------------\n DEALLOCATE(WAVEFUNCTION)\n DEALLOCATE(EXTERNAL_POTENTIAL)\n DEALLOCATE(NONLINEAR_COUPLING)\n DEALLOCATE(TEMPORARY_STORAGE)\n DEALLOCATE(RIGHT_HAND_SIDE)\n DEALLOCATE(UPPER_DIAGONAL)\n DEALLOCATE(MAIN_DIAGONAL)\n DEALLOCATE(LOWER_DIAGONAL)\n DEALLOCATE(W)\n DEALLOCATE(Z)\n\n STOP\n\n ENDPROGRAM GPECN1DTDPBC\n! ======================================================================\n", "meta": {"hexsha": "2a64e2d8e4653db3520c197a44af6e91bf99b842", "size": 10363, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/gpecn1Dtdpbc.f", "max_stars_repo_name": "mkandes/gpecn1Dtdpbc", "max_stars_repo_head_hexsha": "51646d6804fcd6abfbac154c58d9e5739d795c6b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source/gpecn1Dtdpbc.f", "max_issues_repo_name": "mkandes/gpecn1Dtdpbc", "max_issues_repo_head_hexsha": "51646d6804fcd6abfbac154c58d9e5739d795c6b", "max_issues_repo_licenses": ["MIT"], "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/gpecn1Dtdpbc.f", "max_forks_repo_name": "mkandes/gpecn1Dtdpbc", "max_forks_repo_head_hexsha": "51646d6804fcd6abfbac154c58d9e5739d795c6b", "max_forks_repo_licenses": ["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.2979591837, "max_line_length": 276, "alphanum_fraction": 0.6636109235, "num_tokens": 2928, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425333801889, "lm_q2_score": 0.7248702880639792, "lm_q1q2_score": 0.6666215480871851}} {"text": "! **********************************************************************************\n! * ROUTINES FOR COMPUTING THE INCIDENT FIELD COEFFICIENTS *\n! * ------------------------------------------------------------------------ *\n! * Partial list of subroutines: *\n! * PWcoefficients_ab, PWcoefficients_CircPolab(UNUSED), *\n! * PWcoefficients_Polab, PWcoefficients_ab_m, *\n! * PWcoefficients_CircPolab_m(UNUSED), PWcoefficients_Polab_m, *\n! * PWcoefficientsPARTSUB, PWcoefficientsPARTSUBrefl, *\n! * PWcoefficientsPARTSUBtrans, Kcor, *\n! * Fresnel_aer_sub, Fresnel_sub_aer, *\n! * GBcoefficients_ab, GBcoefficients_ab_m, *\n! * product_rotcoefficients, GBcoefficients_ab_local *\n! **********************************************************************************\nsubroutine PWcoefficients_ab (thetaGI, phiGI, alpha, beta, gamma, alphap, Mrank, &\n Nrank, Nmax, c) \n!-----------------------------------------------------------------------------------\n! The routine computes the expansion coefficients of a linearly polarized plane !\n! wave for the azimuthal modes m = 0,1,...,Mrank. ! \n!----------------------------------------------------------------------------------- \n use parameters\n implicit none\n integer :: Mrank, Nrank, Nmax\n real(O) :: thetaGI, phiGI, alpha, beta, gamma, alphap \n complex(O) :: c(2*Nmax)\n! \n integer :: k, m, n, N0, ml, l \n real(O) :: nm, thetaLI, phiLI, e0eT, e0eP, mlr, arg\n complex(O) :: fact, factc, factp, factt\n real(O),allocatable :: Pnm(:), dPnm(:), pinm(:), taunm(:) \n!\n allocate (Pnm(0:Nrank), dPnm(0:Nrank), pinm(0:Nrank), taunm(0:Nrank))\n call T_spherical_global_local (thetaGI, phiGI, alpha, beta, gamma, thetaLI, phiLI)\n call parameters_coefficients_ab (thetaGI, phiGI, thetaLI, phiLI, alpha, beta, &\n gamma, alphap, e0eT, e0eP)\n do m = 0, Mrank \n call leg_normalized (thetaLI, m, Nrank, Pnm, dPnm, pinm, taunm) \n if (m == 0) then\n do k = 1, Nrank\n n = k \n nm = real(2 * n * (n + 1),O) \n nm = 1._O / sqrt(nm) \n fact = 4._O * im**n * nm \n factt = fact * taunm(n) \n c(k) = - factt * e0eP\n c(Nmax+k) = - im * factt * e0eT \n end do\n else \n N0 = Nrank + (m - 1) * (2 * Nrank - m + 2)\n ml = m \n do l = 1, 2\n mlr = real(ml,O)\n arg = mlr * phiLI\n fact = exp(- im * arg) \n do k = 1, Nrank - m + 1\n n = m + k - 1\n nm = real(2 * n * (n + 1),O) \n nm = 1._O / sqrt(nm) \n factc = 4._O * im**n * fact * nm\n factp = factc * im * mlr * pinm(n)\n factt = factc * taunm(n) \n c(N0+k) = - factp * e0eT - factt * e0eP\n c(Nmax+N0+k) = - im * (factt * e0eT - factp * e0eP) \n end do\n N0 = N0 + Nrank - m + 1\n ml = - ml\n end do \n end if\n end do\n deallocate (Pnm, dPnm, pinm, taunm)\nend subroutine PWcoefficients_ab\n! **********************************************************************************\nsubroutine PWcoefficients_CircPolab (thetaGI, phiGI, alpha, beta, gamma, right, &\n Mrank, Nrank, Nmax, c) \n!-----------------------------------------------------------------------------------\n! The routine computes the expansion coefficients of a circularly polarized !\n! plane wave for the azimuthal modes m = 0,1,...,Mrank. ! \n!----------------------------------------------------------------------------------- \n use parameters\n implicit none\n integer :: Mrank, Nrank, Nmax\n real(O) :: thetaGI, phiGI, alpha, beta, gamma\n complex(O) :: c(2*Nmax)\n logical :: right\n! \n integer :: k, m, n, N0, ml, l \n real(O) :: norm, nm, thetaLI, phiLI, mlr, arg\n complex(O) :: epol_theta, epol_phi, e0eT, e0eP, fact, factc, factp, factt\n real(O),allocatable :: Pnm(:), dPnm(:), pinm(:), taunm(:) \n!\n norm = sqrt(2._O) / 2._O \n if (right) then\n epol_theta = norm * one\n epol_phi = norm * im\n else\n epol_theta = norm * one\n epol_phi = - norm * im\n end if\n allocate (Pnm(0:Nrank), dPnm(0:Nrank), pinm(0:Nrank), taunm(0:Nrank))\n call T_spherical_global_local (thetaGI, phiGI, alpha, beta, gamma, thetaLI, phiLI)\n call parameters_coefficients_Polab (thetaGI, phiGI, thetaLI, phiLI, alpha, beta, &\n gamma, epol_theta, epol_phi, e0eT, e0eP) \n do m = 0, Mrank \n call leg_normalized (thetaLI, m, Nrank, Pnm, dPnm, pinm, taunm) \n if (m == 0) then\n do k = 1, Nrank\n n = k \n nm = real(2 * n * (n + 1),O) \n nm = 1._O / sqrt(nm) \n fact = 4._O * im**n * nm \n factt = fact * taunm(n) \n c(k) = - factt * e0eP\n c(Nmax+k) = - im * factt * e0eT \n end do\n else \n N0 = Nrank + (m - 1) * (2 * Nrank - m + 2)\n ml = m \n do l = 1, 2\n mlr = real(ml,O)\n arg = mlr * phiLI\n fact = exp(- im * arg) \n do k = 1, Nrank - m + 1\n n = m + k - 1\n nm = real(2 * n * (n + 1),O) \n nm = 1._O / sqrt(nm) \n factc = 4._O * im**n * fact * nm\n factp = factc * im * mlr * pinm(n)\n factt = factc * taunm(n) \n c(N0+k) = - factp * e0eT - factt * e0eP\n c(Nmax+N0+k) = - im * (factt * e0eT - factp * e0eP) \n end do\n N0 = N0 + Nrank - m + 1\n ml = - ml\n end do \n end if\n end do\n deallocate (Pnm, dPnm, pinm, taunm)\nend subroutine PWcoefficients_CircPolab\n! **********************************************************************************\nsubroutine PWcoefficients_Polab (thetaGI, phiGI, alpha, beta, gamma, epol_theta, &\n epol_phi, Mrank, Nrank, Nmax, c) \n!-----------------------------------------------------------------------------------\n! The routine computes the expansion coefficients of an arbitrarily polarized !\n! plane wave for the azimuthal modes m = 0,1,...,Mrank. ! \n!----------------------------------------------------------------------------------- \n use parameters\n implicit none\n integer :: Mrank, Nrank, Nmax\n real(O) :: thetaGI, phiGI, alpha, beta, gamma\n complex(O) :: epol_theta, epol_phi, c(2*Nmax)\n! \n integer :: k, m, n, N0, ml, l \n real(O) :: nm, thetaLI, phiLI, mlr, arg\n complex(O) :: e0eT, e0eP, fact, factc, factp, factt\n real(O),allocatable :: Pnm(:), dPnm(:), pinm(:), taunm(:) \n! \n allocate (Pnm(0:Nrank), dPnm(0:Nrank), pinm(0:Nrank), taunm(0:Nrank))\n call T_spherical_global_local (thetaGI, phiGI, alpha, beta, gamma, thetaLI, phiLI)\n call parameters_coefficients_Polab (thetaGI, phiGI, thetaLI, phiLI, alpha, beta, &\n gamma, epol_theta, epol_phi, e0eT, e0eP) \n do m = 0, Mrank \n call leg_normalized (thetaLI, m, Nrank, Pnm, dPnm, pinm, taunm) \n if (m == 0) then\n do k = 1, Nrank\n n = k \n nm = real(2 * n * (n + 1),O) \n nm = 1._O / sqrt(nm) \n fact = 4._O * im**n * nm \n factt = fact * taunm(n) \n c(k) = - factt * e0eP\n c(Nmax+k) = - im * factt * e0eT \n end do\n else \n N0 = Nrank + (m - 1) * (2 * Nrank - m + 2)\n ml = m \n do l = 1, 2\n mlr = real(ml,O)\n arg = mlr * phiLI\n fact = exp(- im * arg) \n do k = 1, Nrank - m + 1\n n = m + k - 1\n nm = real(2 * n * (n + 1),O) \n nm = 1._O / sqrt(nm) \n factc = 4._O * im**n * fact * nm\n factp = factc * im * mlr * pinm(n)\n factt = factc * taunm(n) \n c(N0+k) = - factp * e0eT - factt * e0eP\n c(Nmax+N0+k) = - im * (factt * e0eT - factp * e0eP) \n end do\n N0 = N0 + Nrank - m + 1\n ml = - ml\n end do \n end if\n end do\n deallocate (Pnm, dPnm, pinm, taunm)\nend subroutine PWcoefficients_Polab\n! **********************************************************************************\nsubroutine PWcoefficients_ab_m (thetaGI, phiGI, alpha, beta, gamma, alphap, m, &\n Nrank, Nmax, c)\n!-----------------------------------------------------------------------------------\n! The routine computes the expansion coefficients of a linearly polarized plane !\n! wave for the azimuthal mode m. !\n!----------------------------------------------------------------------------------- \n use parameters\n implicit none\n integer :: m, Nrank, Nmax\n real(O) :: thetaGI, phiGI, alpha, beta, gamma, alphap \n complex(O) :: c(2*Nmax)\n! \n integer :: k, n \n real(O) :: nm, thetaLI, phiLI, e0eT, e0eP, mr, arg\n complex(O) :: fact, factc, factp, factt\n real(O),allocatable :: Pnm(:), dPnm(:), pinm(:), taunm(:) \n! \n allocate (Pnm(0:Nrank), dPnm(0:Nrank), pinm(0:Nrank), taunm(0:Nrank))\n call T_spherical_global_local (thetaGI, phiGI, alpha, beta, gamma, thetaLI, phiLI)\n call parameters_coefficients_ab (thetaGI, phiGI, thetaLI, phiLI, alpha, beta, &\n gamma, alphap, e0eT, e0eP)\n call leg_normalized (thetaLI, abs(m), Nrank, Pnm, dPnm, pinm, taunm)\n mr = real(m,O)\n arg = mr * phiLI\n fact = exp(- im * arg)\n do k = 1, Nmax\n if (m == 0) then\n n = k\n else\n n = abs(m) + k - 1\n end if\n nm = real(2 * n * (n + 1),O) \n nm = 1._O / sqrt(nm) \n factc = 4._O * im**n * fact * nm \n factp = factc * im * mr * pinm(n)\n factt = factc * taunm(n) \n c(k) = - factp * e0eT - factt * e0eP\n c(Nmax+k) = - im * (factt * e0eT - factp * e0eP)\n end do \n deallocate (Pnm, dPnm, pinm, taunm)\nend subroutine PWcoefficients_ab_m \n! **********************************************************************************\nsubroutine PWcoefficients_CircPolab_m (thetaGI, phiGI, alpha, beta, gamma, right, &\n m, Nrank, Nmax, c)\n!-----------------------------------------------------------------------------------\n! The routine computes the expansion coefficients of a circularly polarized !\n! plane wave for the azimuthal mode m. !\n!----------------------------------------------------------------------------------- \n use parameters\n implicit none\n integer :: m, Nrank, Nmax\n real(O) :: thetaGI, phiGI, alpha, beta, gamma \n complex(O) :: c(2*Nmax)\n logical :: right \n! \n integer :: k, n \n real(O) :: norm, nm, thetaLI, phiLI, mr, arg\n complex(O) :: epol_theta, epol_phi, e0eT, e0eP, fact, factc, factp, factt\n real(O),allocatable :: Pnm(:), dPnm(:), pinm(:), taunm(:) \n! \n norm = sqrt(2._O) / 2._O \n if (right) then\n epol_theta = norm * one\n epol_phi = norm * im\n else\n epol_theta = norm * one\n epol_phi = - norm * im\n end if\n allocate (Pnm(0:Nrank), dPnm(0:Nrank), pinm(0:Nrank), taunm(0:Nrank))\n call T_spherical_global_local (thetaGI, phiGI, alpha, beta, gamma, thetaLI, phiLI)\n call parameters_coefficients_Polab (thetaGI, phiGI, thetaLI, phiLI, alpha, beta, &\n gamma, epol_theta, epol_phi, e0eT, e0eP) \n call leg_normalized (thetaLI, abs(m), Nrank, Pnm, dPnm, pinm, taunm)\n mr = real(m,O)\n arg = mr * phiLI\n fact = exp(- im * arg)\n do k = 1, Nmax\n if (m == 0) then\n n = k\n else\n n = abs(m) + k - 1\n end if\n nm = real(2 * n * (n + 1),O) \n nm = 1._O / sqrt(nm) \n factc = 4._O * im**n * fact * nm \n factp = factc * im * mr * pinm(n)\n factt = factc * taunm(n) \n c(k) = - factp * e0eT - factt * e0eP\n c(Nmax+k) = - im * (factt * e0eT - factp * e0eP)\n end do \n deallocate (Pnm, dPnm, pinm, taunm)\nend subroutine PWcoefficients_CircPolab_m \n! **********************************************************************************\nsubroutine PWcoefficients_Polab_m (thetaGI, phiGI, alpha, beta, gamma, epol_theta, &\n epol_phi, m, Nrank, Nmax, c)\n!-----------------------------------------------------------------------------------\n! The routine computes the expansion coefficients of an arbitrarily polarized !\n! plane wave for the azimuthal mode m. !\n!----------------------------------------------------------------------------------- \n use parameters\n implicit none\n integer :: m, Nrank, Nmax\n real(O) :: thetaGI, phiGI, alpha, beta, gamma\n complex(O) :: epol_theta, epol_phi, c(2*Nmax)\n! \n integer :: k, n \n real(O) :: nm, thetaLI, phiLI, mr, arg\n complex(O) :: e0eT, e0eP, fact, factc, factp, factt\n real(O),allocatable :: Pnm(:), dPnm(:), pinm(:), taunm(:) \n! \n allocate (Pnm(0:Nrank), dPnm(0:Nrank), pinm(0:Nrank), taunm(0:Nrank))\n call T_spherical_global_local (thetaGI, phiGI, alpha, beta, gamma, thetaLI, phiLI)\n call parameters_coefficients_Polab (thetaGI, phiGI, thetaLI, phiLI, alpha, beta, &\n gamma, epol_theta, epol_phi, e0eT, e0eP) \n call leg_normalized (thetaLI, abs(m), Nrank, Pnm, dPnm, pinm, taunm)\n mr = real(m,O)\n arg = mr * phiLI\n fact = exp(- im * arg)\n do k = 1, Nmax\n if (m == 0) then\n n = k\n else\n n = abs(m) + k - 1\n end if\n nm = real(2 * n * (n + 1),O) \n nm = 1._O / sqrt(nm) \n factc = 4._O * im**n * fact * nm \n factp = factc * im * mr * pinm(n)\n factt = factc * taunm(n) \n c(k) = - factp * e0eT - factt * e0eP\n c(Nmax+k) = - im * (factt * e0eT - factp * e0eP)\n end do \n deallocate (Pnm, dPnm, pinm, taunm)\nend subroutine PWcoefficients_Polab_m \n! **********************************************************************************\nsubroutine PWcoefficientsPARTSUB (beta0, alphap, m, Nrank, Nmax, c)\n!------------------------------------------------------------------------------------\n! The routine computes the expansion coefficients of a plane wave (traveling in !\n! the Oxz plane) for the azimuthal mode m. !\n!------------------------------------------------------------------------------------ \n use parameters\n implicit none\n integer :: m, Nrank, Nmax\n real(O) :: beta0, alphap\n complex(O) :: c(2*Nmax) \n!\n integer :: k, n \n real(O) :: nm, mr, ca, sa\n complex(O) :: factc, factp, factt\n real(O),allocatable :: Pnm(:), dPnm(:), pinm(:), taunm(:)\n!\n allocate (Pnm(0:Nrank), dPnm(0:Nrank), pinm(0:Nrank), taunm(0:Nrank))\n call leg_normalized (beta0, abs(m), Nrank, Pnm, dPnm, pinm, taunm)\n mr = real(m,O)\n ca = cos(alphap)\n sa = sin(alphap)\n do k = 1, Nmax\n if (m == 0) then\n n = k\n else\n n = abs(m) + k - 1\n end if\n nm = real(2 * n * (n + 1),O) \n nm = 1._O / sqrt(nm) \n factc = 4._O * im**n * nm * cos(mr * Pi) \n factp = factc * im * mr * pinm(n)\n factt = factc * taunm(n)\n c(k) = - factp * ca - factt * sa\n c(Nmax+k) = - im * (factt * ca - factp * sa)\n end do\n deallocate (Pnm, dPnm, pinm, taunm) \nend subroutine PWcoefficientsPARTSUB\n! **********************************************************************************\nsubroutine PWcoefficientsPARTSUBrefl (beta0, alphap, z0, wavenumber, ind_ref, m, &\n Nrank, Nmax, c)\n!-----------------------------------------------------------------------------------\n! The routine computes the expansion coefficients of the reflected plane wave !\n! (traveling in the Oxz plane) for the azimuthal mode m. !\n!----------------------------------------------------------------------------------- \n use parameters\n implicit none\n integer :: m, Nrank, Nmax\n real(O) :: beta0, alphap, z0, wavenumber \n complex(O) :: c(2*Nmax), ind_ref\n!\n integer :: k, n \n real(O) :: nm, betaM0, mr\n complex(O) :: Rpar, Rperp, Tpar, Tperp, et, ep, cosb, sinb, cosb0, factc, &\n factp, factt, phase\n real(O),allocatable :: Pnm(:), dPnm(:), pinm(:), taunm(:)\n!\n allocate (Pnm(0:Nrank), dPnm(0:Nrank), pinm(0:Nrank), taunm(0:Nrank))\n cosb0 = cmplx(cos(beta0),0._O)\n call Fresnel_aer_sub (cosb0, ind_ref, Rpar, Rperp, Tpar, Tperp, cosb, sinb)\n phase = exp(2._O * im * wavenumber * cosb0 * z0)\n et = cos(alphap) * Rpar * phase\n ep = sin(alphap) * Rperp * phase\n betaM0 = Pi - beta0\n call leg_normalized (betaM0, abs(m), Nrank, Pnm, dPnm, pinm, taunm)\n mr = real(m,O) \n do k = 1, Nmax\n if (m == 0) then\n n = k\n else\n n = abs(m) + k - 1\n end if\n nm = real(2 * n * (n + 1),O) \n nm = 1._O / sqrt(nm) \n factc = 4._O * im**n * nm * cos(mr * Pi) \n factp = factc * im * mr * pinm(n)\n factt = factc * taunm(n)\n c(k) = - factp * et - factt * ep\n c(Nmax+k) = - im * (factt * et - factp * ep)\n end do \n deallocate (Pnm, dPnm, pinm, taunm) \nend subroutine PWcoefficientsPARTSUBrefl\n! **********************************************************************************\nsubroutine PWcoefficientsPARTSUBtrans (beta, alphap, z0, wavenumber, ind_ref, m, &\n Nrank, Nmax, c)\n!----------------------------------------------------------------------------------\n! The routine computes the expansion coefficients of the transmitted plane wave !\n! (traveling in the Oxz plane) for the azimuthal mode m. !\n! --------------------------------------------------------------------------------- \n use parameters\n implicit none\n integer :: m, Nrank, Nmax\n real(O) :: beta, alphap, z0, wavenumber\n complex(O) :: c(2*Nmax), ind_ref \n!\n integer :: k, n\n real(O) :: nm, mr\n complex(O) :: Rpar, Rperp, Tpar, Tperp, et, ep, cosb, sinb0, cosb0, factc, factp, &\n factt, phase\n complex(O),allocatable :: Pnm(:), dPnm(:), pinm(:), taunm(:)\n!\n allocate (Pnm(0:Nrank), dPnm(0:Nrank), pinm(0:Nrank), taunm(0:Nrank))\n cosb = cmplx(cos(beta),0._O) \n call Fresnel_sub_aer (cosb, ind_ref, Rpar, Rperp, Tpar, Tperp, cosb0, sinb0) \n phase = exp(im * wavenumber * (cosb0 - ind_ref * cosb) * z0) \n et = cos(alphap) * Tpar * phase\n ep = sin(alphap) * Tperp * phase\n cosb0 = - cosb0 \n call Leg_normalized_complex (sinb0, cosb0, abs(m), Nrank, Pnm, dPnm, pinm, taunm)\n mr = real(m,O) \n do k = 1, Nmax\n if (m == 0) then\n n = k\n else\n n = abs(m) + k - 1\n end if\n nm = real(2 * n * (n + 1),O) \n nm = 1._O / sqrt(nm) \n factc = 4._O * im**n * nm\n factp = factc * im * mr * pinm(n)\n factt = factc * taunm(n)\n c(k) = - factp * et - factt * ep\n c(Nmax+k) = - im * (factt * et - factp * ep)\n end do \n deallocate (Pnm, dPnm, pinm, taunm) \nend subroutine PWcoefficientsPARTSUBtrans\n! **********************************************************************************\nsubroutine Fresnel_aer_sub (cosb0, m, Rpar, Rperp, Tpar, Tperp, cosb, sinb)\n use parameters\n use derived_parameters\n implicit none\n complex(O) :: cosb0, sinb0, m, Rpar, Rperp, Tpar, Tperp, cosb, sinb \n! \n sinb0 = sqrt(1._O - cosb0**2)\n sinb = sinb0 / m\n cosb = sqrt(1._O - sinb**2)\n if (aimag(m * cosb) < 0._O) cosb = - cosb \n if (abs(m * cosb0 + cosb) < MachEps) then\n print \"(/,2x,'Warning in subroutine Fresnel_aer_sub in module IncCoeff:')\"\n print \"( 2x,'the denominator in the expression of the Fresnel reflection')\"\n print \"( 2x,'coefficients is smaller than the machine precision;')\" \n end if \n if (abs(m * cosb0 - cosb) < MachEps) then ! redundant\n Rpar = zero\n Tpar = 1._O / m\n else\n Rpar = (m * cosb0 - cosb) / (m * cosb0 + cosb)\n Tpar = 2._O * cosb0 / (m * cosb0 + cosb)\n end if\n if (abs(cosb0 - m * cosb) < MachEps) then ! redundant\n Rperp = zero\n Tperp = one\n else\n Rperp = (cosb0 - m * cosb) / (cosb0 + m * cosb)\n Tperp = 2._O * cosb0 / (cosb0 + m * cosb)\n end if \nend subroutine Fresnel_aer_sub\n! **********************************************************************************\nsubroutine Fresnel_sub_aer (cosb, m, Rpar, Rperp, Tpar, Tperp, cosb0, sinb0)\n use parameters\n use derived_parameters\n implicit none\n complex(O) :: cosb, m, Rpar, Rperp, Tpar, Tperp, sinb0, cosb0, sinb\n!\n sinb = sqrt(1._O - cosb**2)\n sinb0 = m * sinb\n cosb0 = sqrt(1._O - sinb0**2) \n if (aimag(cosb0) < 0._O) cosb0 = - cosb0 \n if (abs(m * cosb0 + cosb) < MachEps) then\n print \"(/,2x,'Warning in subroutine Fresnel_sub_aer in module IncCoeff:')\"\n print \"( 2x,'the denominator in the expression of the Fresnel transmission')\"\n print \"( 2x,'coefficients is smaller than the machine precision;')\" \n end if \n if (abs(cosb - m * cosb0) < MachEps) then ! redundant\n Rpar = zero\n Tpar = m \n else\n Rpar = (cosb - m * cosb0) / (m * cosb0 + cosb)\n Tpar = 2._O * m * cosb / (m * cosb0 + cosb)\n end if\n if (abs(m * cosb - cosb0) < MachEps) then ! redundant\n Rperp = zero\n Tperp = one \n else\n Rperp = (m * cosb - cosb0) / (cosb0 + m * cosb)\n Tperp = 2._O * m * cosb / (cosb0 + m * cosb) \n end if \nend subroutine Fresnel_sub_aer \n! **********************************************************************************\nsubroutine GBcoefficients_ab (wavenumber, x0, y0, z0, w0, thetaGI, phiGI, alpha, &\n beta, gamma, alphap, Mrank, Nrank, Nmax, c)\n!------------------------------------------------------------------------------------\n! The routine computes the expansion coefficients of a Gaussian beam for the !\n! azimuthal modes m = 0,1,...,Mrank. Note that x0, y0, z0 are the coordinates of !\n! the beam focal point with respect to a global coordinate system (having the same !\n! origin as the particle coordinate system). ! \n!------------------------------------------------------------------------------------ \n use parameters\n implicit none\n integer :: Mrank, Nrank, Nmax\n real(O) :: wavenumber, x0, y0, z0, w0, thetaGI, phiGI, alpha, beta, gamma, &\n alphap \n complex(O) :: c(2*Nmax)\n! \n integer :: m, Nmaxl, k, N0, l, ml\n complex(O),allocatable :: cl(:)\n!\n do m = 0, Mrank \n if (m == 0) then\n Nmaxl = Nrank\n allocate (cl(2*Nmaxl))\n call GBcoefficients_ab_m (wavenumber, x0, y0, z0, w0, thetaGI, phiGI, alpha, &\n beta, gamma, alphap, m, Nmaxl, cl)\n do k = 1, Nmaxl \n c(k) = cl(k)\n c(Nmax+k) = cl(k+Nmaxl)\n end do\n deallocate (cl)\n else \n N0 = Nrank + (m - 1) * (2 * Nrank - m + 2)\n Nmaxl = Nrank - m + 1\n allocate (cl(2*Nmaxl)) \n ml = m\n do l = 1, 2\n call GBcoefficients_ab_m (wavenumber, x0, y0, z0, w0, thetaGI, phiGI, &\n alpha, beta, gamma, alphap, ml, Nmaxl, cl)\n do k = 1, Nmaxl \n c(N0+k) = cl(k)\n c(Nmax+N0+k) = cl(k+Nmaxl) \n end do\n N0 = N0 + Nrank - m + 1\n ml = - ml\n end do \n deallocate (cl) \n end if\n end do \nend subroutine GBcoefficients_ab \n! **********************************************************************************\nsubroutine GBcoefficients_ab_m (wavenumber, x0, y0, z0, w0, thetaGI, phiGI, alpha, &\n beta, gamma, alphap, m, Nmax, c)\n!------------------------------------------------------------------------------------\n! The routine computes the expansion coefficients of a Gaussian beam for the !\n! azimuthal mode m. Note that x0, y0, z0 are the coordinates of the beam focal point!\n! with respect to a global coordinate system (having the same origin as the !\n! particle coordinate system). !\n!------------------------------------------------------------------------------------ \n use parameters\n implicit none\n integer :: m, Nmax\n real(O) :: wavenumber, x0, y0, z0, w0, thetaGI, phiGI, alpha, beta, gamma, &\n alphap \n complex(O) :: c(2*Nmax)\n! \n integer :: k, n, m1, p\n real(O) :: xpG, ypG, zpG, xpL, ypL, zpL\n complex(O) :: suma, sumb\n complex(O),allocatable :: a(:), b(:), d(:)\n!\n xpG = - x0\n ypG = - y0\n zpG = - z0\n call T_cartesian_global_local (xpG, ypG, zpG, phiGI, thetaGI, alphap, xpL, ypL, zpL) \n do k = 1, Nmax\n if (m == 0) then\n n = k\n else\n n = abs(m) + k - 1\n end if\n allocate (a(2*n+1), b(2*n+1), d(2*n+1)) \n call GBcoefficients_ab_local (wavenumber, xpL, ypL, zpL, w0, n, a, b) \n call product_rotcoefficients (thetaGI, phiGI, alpha, beta, gamma, alphap, m, n, d) \n suma = zero\n sumb = zero\n do m1 = 0, n\n if (m1 == 0) then \n suma = suma + a(1) * d(1)\n sumb = sumb + b(1) * d(1)\n else\n p = 2 * m1\n suma = suma + a(p) * d(p) + a(p+1) * d(p+1)\n sumb = sumb + b(p) * d(p) + b(p+1) * d(p+1)\n end if\n end do\n c(k) = suma\n c(k+Nmax)= sumb \n deallocate (a, b, d)\n end do\nend subroutine GBcoefficients_ab_m \n! **********************************************************************************\nsubroutine product_rotcoefficients (thetaGI, phiGI, alpha, beta, gamma, alphap, &\n m, n, d)\n use parameters\n implicit none\n integer :: m, n\n real(O) :: thetaGI, phiGI, alpha, beta, gamma, alphap\n complex(O) :: d(2*n+1) \n! \n integer :: m1, m2, k \n complex(O) :: sum, Dnm1m2, Dnm2m, coef_rotation\n!\n do m1 = 0, n\n if (m1 == 0) then \n sum = zero\n do m2 = - n, n\n Dnm1m2 = coef_rotation (- alphap, - thetaGI, - phiGI, n, m1, m2)\n Dnm2m = coef_rotation ( alpha, beta, gamma, n, m2, m) \n sum = sum + Dnm1m2 * Dnm2m\n end do\n d(1) = sum\n else\n k = 2 * m1 \n! --- m1 > 0 ---\n sum = zero \n do m2 = - n, n\n Dnm1m2 = coef_rotation (- alphap, - thetaGI, - phiGI, n, m1, m2)\n Dnm2m = coef_rotation ( alpha, beta, gamma, n, m2, m)\n sum = sum + Dnm1m2 * Dnm2m\n end do\n d(k) = sum\n! --- m1 < 0 ---\n sum = zero \n do m2 = - n, n\n Dnm1m2 = coef_rotation (- alphap, - thetaGI, - phiGI, n, - m1, m2)\n Dnm2m = coef_rotation ( alpha, beta, gamma, n, m2, m)\n sum = sum + Dnm1m2 * Dnm2m\n end do\n d(k+1) = sum\n end if\n end do \nend subroutine product_rotcoefficients \n! **********************************************************************************\nsubroutine GBcoefficients_ab_local (wavenumber, x0, y0, z0, w0, n, a, b)\n use parameters\n use derived_parameters\n implicit none\n integer :: n\n real(O) :: wavenumber, x0, y0, z0, w0 \n complex(O) :: a(2*n+1), b(2*n+1)\n! \n integer :: m, k\n real(O) :: l, ro0, phi0, ron, argz, argpm, argpp, sig, w02, dz\n complex(O) :: Q, PSI, arg, fact, Kcor, factz, factm, factp, imQ, dzc\n complex(O),allocatable :: Jbes(:)\n!\n if (abs(w0) < MachEps) then\n print \"(/,2x,'Warning in subroutine GBcoefficients_ab_local in module IncCoeff:')\"\n print \"( 2x,'the waist radius of the Gaussian beam is smaller than the machine')\"\n print \"( 2x,'precision;')\" \n end if\n l = wavenumber * w0 * w0 \n dz = 2._O * z0 / l\n dzc = cmplx(dz,0.0,O)\n Q = 1._O / (im - dzc)\n ro0 = sqrt(x0 * x0 + y0 * y0) \n if (ro0 < MachEps) then\n phi0 = 0._O \n else \n phi0 = atan2(y0,x0)\n if (phi0 < 0._O) phi0 = 2._O * Pi + phi0 \n end if \n ron = (real(n,O) + 0.5_O) / wavenumber\n w02 = w0 * w0\n imQ = im * Q\n PSI = imQ * exp(-imQ * (ro0 * ro0 + ron * ron) / w02)\n arg = 2._O * Q * ro0 * ron / w02\n allocate (Jbes(0:n+1)) \n call bes_J (arg, n + 1, Jbes) \n argz = wavenumber * z0\n factz = exp(im * argz) \n do m = 0, n\n if (m == 0) then \n fact = 2._O * factz * Jbes(1) * Kcor(m,n) * PSI \n a(1) = - cos(phi0) * fact \n b(1) = im * sin(phi0) * fact\n else\n k = 2 * m \n argpm = real(m - 1,O) * phi0\n argpp = real(m + 1,O) * phi0\n fact = factz * Kcor(m,n) * PSI\n! --- m > 0 --- \n factm = exp(im * argpm) * Jbes(m-1)\n factp = exp(im * argpp) * Jbes(m+1) \n a(k) = fact * (factm - factp) \n b(k) = fact * (factm + factp) \n! --- m < 0 ---\n sig = (- 1._O)**(m - 1)\n factm = sig * exp(- im * argpm) * Jbes(m-1)\n factp = sig * exp(- im * argpp) * Jbes(m+1) \n a(k+1) = fact * (factp - factm) \n b(k+1) = fact * (factp + factm) \n end if\n end do\n deallocate (Jbes) \nend subroutine GBcoefficients_ab_local \n! **********************************************************************************\nfunction Kcor (m, n) result (K)\n use parameters\n implicit none\n integer :: m, n\n complex(O) :: K\n! \n integer :: p\n real(O) :: fact, sum, lnx \n!\n if (m == 0) then\n fact = 2._O * sqrt(real(n * (n + 1),O) / real(2 * n + 1,O)) \n K = im**n * fact\n else\n sum = 0._O\n do p = 1, 2 * abs(m)\n sum = sum + log(real(n - abs(m) + p,O))\n end do\n lnx = real(abs(m) - 1,O) * log(2._O / real(2 * n + 1,O))\n lnx = lnx + 0.5_O * (log(real(2 * n + 1,O)) - log(real(n * (n + 1),O)) + sum) \n K = im**(n + abs(m)) * (-1._O)**abs(m) * exp(lnx)\n end if \nend function Kcor\n\n", "meta": {"hexsha": "ddc5edc813f0ac2383ae80c19da6374a276355cf", "size": 30223, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "smuthi/linearsystem/tmatrix/nfmds/NFM-DS/TMATSOURCES/IncCoeff.f90", "max_stars_repo_name": "parkerwray/smuthi-1", "max_stars_repo_head_hexsha": "a5ced07461b8fd223dc37d28259261ceed78aed5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "smuthi/linearsystem/tmatrix/nfmds/NFM-DS/TMATSOURCES/IncCoeff.f90", "max_issues_repo_name": "parkerwray/smuthi-1", "max_issues_repo_head_hexsha": "a5ced07461b8fd223dc37d28259261ceed78aed5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "smuthi/linearsystem/tmatrix/nfmds/NFM-DS/TMATSOURCES/IncCoeff.f90", "max_forks_repo_name": "parkerwray/smuthi-1", "max_forks_repo_head_hexsha": "a5ced07461b8fd223dc37d28259261ceed78aed5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.3511348465, "max_line_length": 98, "alphanum_fraction": 0.4588558383, "num_tokens": 9814, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425311777929, "lm_q2_score": 0.7248702880639791, "lm_q1q2_score": 0.6666215464907337}} {"text": " program z2zi\n real z(9999),zi(0:9999)\nc\nc convert z-points to z-cells\nc\nc z on stdin\nc zi on stdout\nc\n do k= 1,9999\n read(5,*,end=100) z(k)\n enddo\n 100 continue\n kz = k-1\nc\nc assume that cell thickness increases with depth,\nc and that we would like z to be at the center of the zi's.\nc\n zi(0) = 0.0\n zi(2) = 0.5*(z(2)+z(3))\n zi(1) = max( 0.5*(z(1)+z(2)),\n & 2.0* z(2)-zi(2) )\n do k= 3,kz-1\n zi(k) = min( 2.0* z(k)-zi(k-1),\n & 0.5*(z(k)+z(k+1)) )\n enddo\n zi(kz) = z(kz) + (z(kz) - zi(kz-1))\nc\n write(6,\"(f12.4)\") zi(0)\n do k= 1,kz\n write(6,\"(3f12.4)\") zi(k),z(k),0.5*(zi(k)+zi(k-1))\n enddo\n end\n", "meta": {"hexsha": "550b068ef1a093f7e84838e978fd434d7a9b6daa", "size": 757, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "bin/z2zi.f", "max_stars_repo_name": "TillRasmussen/HYCOM-tools", "max_stars_repo_head_hexsha": "7d26b60ce65ac9d785e0e36add36aca05c0f496d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2019-05-31T02:47:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T19:21:04.000Z", "max_issues_repo_path": "bin/z2zi.f", "max_issues_repo_name": "TillRasmussen/HYCOM-tools", "max_issues_repo_head_hexsha": "7d26b60ce65ac9d785e0e36add36aca05c0f496d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2019-09-27T08:20:13.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-18T16:50:53.000Z", "max_forks_repo_path": "bin/z2zi.f", "max_forks_repo_name": "TillRasmussen/HYCOM-tools", "max_forks_repo_head_hexsha": "7d26b60ce65ac9d785e0e36add36aca05c0f496d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2019-03-21T08:43:56.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-24T08:08:56.000Z", "avg_line_length": 22.9393939394, "max_line_length": 63, "alphanum_fraction": 0.4425363276, "num_tokens": 328, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425399873764, "lm_q2_score": 0.7248702761768248, "lm_q1q2_score": 0.6666215419446062}} {"text": "SUBROUTINE random_wave_coefficients(i_spec, nt, beta0, dt, dx, Tp, Hs, depth, &\n grav, inc_wave_file, kh_max, seed, seed2, eta0, beta, s0, &\n n_cut,gamma_jonswap)\n !-----------------------------------------------------------------------\n !\n ! Build the coefficients for a pseudo-random 3D wave with direction BETA0 to the \n ! x-axis, over NT time steps at tim-step DT. The water depth at the wavemaker \n ! is DEPTH. The wave can be based on a long-crested P-M (i_spec=30) or \n ! JONSWAP (ispec=31) spectrum at angle BETA0 to the x-axis, or it can be \n ! a JONSWAP with NORMAL directional spreading about the angle BETA0 (i_spec=33). \n ! The coefficients are returned in ETA0 ready to be moved around in space and \n ! FFT'ed by the subroutine random_wave_signal_3D.f90. \n ! \n ! When i_spec=-30, a mono-chromatic wave is generated with period Tp, \n ! height Hs and angle BETA0; so nothing is done here. \n !\n !----------------------------------------------------------------------\n IMPLICIT none\n CHARACTER(len=30) inc_wave_file, header\n integer, parameter :: long=selected_real_kind(12,99)\n integer i, i_spec, seed, seed2, nt, n_cut\n real(kind=long) :: Tp, Hs, dt, depth, grav, kh_max, dx, s0, gamma_jonswap\n real(kind=long) :: eta0(nt), beta(nt)\n\n ! Local variables\n integer :: ndat\n real(kind=long) :: factor, domega, beta0, spec, zero=0._long, one=1._long, &\n two=2._long, pi, twopi, dt_inc\n !\n ! Some parameters \n !\n pi=acos(-one)\n twopi=two*pi\n !\n ! \n ! Generate the random wave.\n !\n ! The FT factor. \n !\n factor = two/nt\n !\n ! The Fourier coefficients are built based on SI dimensional numbers. Omega is\n ! radian frequency.\n !\n domega = twopi / (nt * dt)\n !\n !\n ! Generate the Fourier components of the wave elevation at the wavemaker.\n ! Note that the same spectral and time parameters, and SEED values always give \n ! the same coefficients.\n !\n ! Initialize the heading angle vector\n beta=beta0\n !\n IF(i_spec==0 .or. i_spec==30)THEN \n ! A long-crested P-M spectrum\n CALL build_coeff(eta0, nt, Hs, Tp, dt, seed, seed2, 0)\n ELSEIf(i_spec==1 .or. i_spec==31 .or. i_spec==3)THEN\n ! A long-crested JONSWAP spectrum\n CALL build_coeff(eta0, nt, Hs, Tp, dt, seed, seed2, 1,gamma_jonswap)\n ELSEIF(i_spec==33)THEN\n ! A JONSWAP spectrum with a normal spreading\n CALL build_coeff_3D(eta0, beta, nt, Hs, Tp, dt, seed, seed2, beta0, gamma_jonswap)\n ELSEIF(i_spec==34)THEN\n ! A JONSWAP spectrum with a cos^s spreading\n CALL build_coeff_3D_Cos(eta0, beta, nt, Hs, Tp, dt, seed, seed2, beta0, s0, gamma_jonswap)\n ELSEIF(i_spec == 2) THEN\n open(21,file=inc_wave_file,status='old')\n READ(21,'(A)',err=15)header\n READ(21,*)dt_inc\n IF(ABS(dt-dt_inc)>1.e-6)THEN\n print *, 'random_wave_signal.f90: The .inp and .iwf time steps do not agree.'\n print *, header\n print *, dt,dt_inc\n stop\n END IF\n do i=1,nt\n READ(21,*,end=13)eta0(i)\n end do\n go to 14\n13 ndat=i-1\n print *, ' Found ',ndat,' data points in the incident wave file. Padding with zeros up to ',nt\n do i=ndat+1,nt\n eta0(i)=zero\n end do\n go to 14\n15 print *, 'random_wave_signal.f90: No header line in the .iwf'\n stop\n14 CLOSE(21)\n CALL drealft (eta0, nt, 1)\n !\n ! Scale the FFT\n !\n eta0=eta0*factor\n\n ELSEIF(i_spec<0)THEN\n ! Mono-chromatic waves, nothing to do here. \n RETURN\n END IF\n !\n ! We truncate the spectrum at k_max.\n !\n n_cut=nint(sqrt(grav*kh_max/depth*tanh(kh_max))/domega)+1\n Print *, 'Truncating the spectrum at T=',twopi/((n_cut-1)*domega), &\n ' which corresponds to kh=',kh_max\n print *, 'The deep water resolution of this wave is ',2*pi*depth/(kh_max*dx)+one, &\n ' points per wavelength.'\n Print *, ' '\n eta0(2*n_cut-1:nt)=zero\n !\n !Print out the wave maker elevation.\n !\n CALL drealft (eta0, nt, -1)\n\n open(21,file='eta0_irregular',status='unknown')\n IF(i_spec==30)THEN\n write(21,32)Hs,Tp,twopi/((n_cut-1)*domega),kh_max,beta0\n31 format('% P-M spectrum H_s=',e12.4,' T_p=',e12.4,' truncated at T=',e12.4,&\n ' which is kh=',e12.4,'. Heading angle is ,',f10.2)\n ELSEIF(i_spec==31)THEN\n write(21,32)Hs,Tp,twopi/((n_cut-1)*domega),kh_max,beta0\n32 format('% JONSWAP spectrum H_s=',e12.4,' T_p=',e12.4,' truncated at T=',e12.4,&\n ' which is kh=',e12.4,'. Heading angle is ,',f10.2)\n ELSEIF(i_spec==33)THEN\n write(21,33)Hs,Tp,twopi/((n_cut-1)*domega),kh_max,beta0\n33 format('% JONSWAP with NORMAL spreading H_s=',e12.4,' T_p=',e12.4, &\n ' truncated at T=',e12.4,&\n ' which is kh=',e12.4,'. Heading angle is ,',f10.2)\n END IF\n do i=1,nt\n write(21,*)(i-1)*dt,eta0(i)\n end do\n close(21)\n !\n ! FFT back to the coefficients and print them out\n !\n CALL drealft (eta0, nt, 1)\n eta0=eta0*factor\n open(21,file='eta0_coeffs',status='unknown')\n write(21,34)\n34 format('# f [Hz], mag(c), c_r, c_i')\n write(21,35)zero,eta0(1),eta0(1),eta0(2)\n35 format(4e16.5)\n do i=3,nt-1,2\n write(21,35) (i-1)/2 * domega/twopi, sqrt(eta0(i)**2+eta0(i+1)**2),eta0(i),eta0(i+1)\n end do\n close(21)\n\nRETURN\nEND SUBROUTINE random_wave_coefficients\n", "meta": {"hexsha": "06cddb59a2304dbc19bf9b84febf78cb48787a37", "size": 5213, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/utilities/random_wave_coefficients.f90", "max_stars_repo_name": "apengsigkarup/OceanWave3D", "max_stars_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 46, "max_stars_repo_stars_event_min_datetime": "2016-01-08T12:36:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T06:56:45.000Z", "max_issues_repo_path": "src/utilities/random_wave_coefficients.f90", "max_issues_repo_name": "apengsigkarup/OceanWave3D", "max_issues_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-10-10T19:45:08.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-07T07:37:11.000Z", "max_forks_repo_path": "src/utilities/random_wave_coefficients.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": 34.5231788079, "max_line_length": 100, "alphanum_fraction": 0.6253596777, "num_tokens": 1802, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425355825847, "lm_q2_score": 0.7248702761768248, "lm_q1q2_score": 0.6666215387517036}} {"text": " REAL FUNCTION MODSEP (PERIOD, A, B)\n\nC Given a period and two values, a and b, modsep calculates the\nC absolute value of the smallest \"distance\" between the values,\nC treating them as points on a circle with circumference of size =\nC period. For example, if period=360, as for degree-measure,\nC modsep of 5 and 15 would of course be 10, but so would modsep of\nC 5 and 355, or 0 and 710, or 0 and 730.\n\n REAL PERIOD, A, B, AM,BM, ABDIF\n\n IF (PERIOD .EQ. 0.0) THEN\n MODSEP = 0.0\n RETURN\n ENDIF\n\nC get normalized mod-values - correct for loopy way Fortran\nC mods negative numbers.\n AM = MOD (A,PERIOD)\n IF (A.LT.0) AM = AM+PERIOD\n BM = MOD (B,PERIOD)\n IF (B.LT.0) BM = BM+PERIOD\nC now: 0 .le. am,bm .lt. period\n\n ABDIF = ABS(AM-BM)\n MODSEP = MIN (ABDIF, PERIOD-ABDIF)\n\n END\n", "meta": {"hexsha": "17d2cfeca0c3038f26e732f787d068fd5e8cfe24", "size": 853, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "third_party/Phigs/PVT/PVT_fort/V2LIB/modsep.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/modsep.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/modsep.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": 29.4137931034, "max_line_length": 67, "alphanum_fraction": 0.633059789, "num_tokens": 292, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425223682086, "lm_q2_score": 0.7248702761768249, "lm_q1q2_score": 0.6666215291729952}} {"text": "REAL Nsr, Nolr, clearSkySolarRadiation, averageT, surfaceEmissivity, cloudCoverFactor\nNsr = (1 - albedoCoefficient) * solarRadiation\nclearSkySolarRadiation = (0.75 + 2 * (10**-5) * elevation) * extraSolarRadiation\naverageT = ((maxTair + 273.16)**4) + ((minTair + 273.16)**4)) / 2\nsurfaceEmissivity = (0.34 - 0.14 * SQRT(vaporPressure / 10))\ncloudCoverFactor = (1.35 * (solarRadiation / clearSkySolarRadiation) - 0.35)\nNolr = stefanBoltzman * averageT * surfaceEmissivity * cloudCoverFactor\nnetRadiation = Nsr - Nolr\nnetOutGoingLongWaveRadiation = Nolr\nnetRadiationEquivalentEvaporation = netRadiation / lambdaV * 1000;\n", "meta": {"hexsha": "9b35e1107ff8d6214da5db205eab3822a747d335", "size": 619, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/data/energyBalance/crop2ml/Algo/f90/NetRadiation.f90", "max_stars_repo_name": "brichet/PyCrop2ML", "max_stars_repo_head_hexsha": "7177996f72a8d95fdbabb772a16f1fd87b1d033e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-06-21T18:58:04.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-29T21:32:28.000Z", "max_issues_repo_path": "test/data/energyBalance/crop2ml/Algo/f90/NetRadiation.f90", "max_issues_repo_name": "brichet/PyCrop2ML", "max_issues_repo_head_hexsha": "7177996f72a8d95fdbabb772a16f1fd87b1d033e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 27, "max_issues_repo_issues_event_min_datetime": "2018-12-04T15:35:44.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-11T08:25:03.000Z", "max_forks_repo_path": "test/data/energyBalance/crop2ml/Algo/f90/NetRadiation.f90", "max_forks_repo_name": "brichet/PyCrop2ML", "max_forks_repo_head_hexsha": "7177996f72a8d95fdbabb772a16f1fd87b1d033e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-04-20T02:25:22.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T07:52:35.000Z", "avg_line_length": 56.2727272727, "max_line_length": 85, "alphanum_fraction": 0.7544426494, "num_tokens": 217, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750466836961, "lm_q2_score": 0.6992544085240401, "lm_q1q2_score": 0.6665817789295346}} {"text": "module coordinates\n !!********************************************************\n !*\n !* DESCRIPTION: ! This module contains functions to transform betwen llh, xyz, and sch\n !*\n !* FUNCTION LIST: radar_to_xyz, rdir, reast, rnorth, latlon\n !* convert_sch_to_xyz\n !*\n !!*********************************************************\n use linalg\n use fortranUtils\n implicit none\n \n \n ! declare data types\n type :: ellipsoid \n real*8 r_a ! semi-major axis\n real*8 r_e2 ! eccentricity-squared of earth ellipsoid\n end type ellipsoid\n \n type :: pegpoint \n real*8 r_lat ! peg latitude\n real*8 r_lon ! peg longitude\n real*8 r_hdg ! peg heading\n end type pegpoint\n \n type :: pegtrans \n real*8 r_mat(3,3) !transformation matrix SCH->XYZ\n real*8 r_matinv(3,3) !transformation matrix XYZ->SCH\n real*8 r_ov(3) !Offset vector SCH->XYZ\n real*8 r_radcur !peg radius of curvature\n end type pegtrans\n \n \n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n !! SUBROUTINES & FUNCTIONS\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!\ncontains\n subroutine radar_to_xyz(elp,peg,ptm,height)\n !c****************************************************************\n !c**\n !c** FILE NAME: radar_to_xyz.f\n !c**\n !c** DATE WRITTEN:1/15/93 \n !c**\n !c** PROGRAMMER:Scott Hensley\n !c**\n !c** FUNCTIONAL DESCRIPTION: This routine computes the transformation\n !c** matrix and translation vector needed to get between radar (s,c,h)\n !c** coordinates and (x,y,z) WGS-84 coordinates.\n !c**\n !c** ROUTINES CALLED: latlon,rdir\n !c** \n !c** NOTES: none\n !c**\n !c** UPDATE LOG:\n !c**\n !c*****************************************************************\n \n \n ! input/output variables\n type(ellipsoid), intent(in) :: elp\n type(pegpoint), intent(in) :: peg\n type(pegtrans), intent(out) :: ptm\n\n real*8, intent(in), optional :: height\n \n ! local variables\n integer i,j,i_type\n real*8 r_radcur,r_llh(3),r_p(3),r_slt,r_clt,r_clo,r_slo,r_up(3)\n real*8 r_chg,r_shg\n real*8 r_height\n \n ! processing steps\n !Check if the height is given\n if (present(height)) then\n r_height = height\n else\n r_height = 0.0d0\n endif\n\n ! first determine the rotation matrix\n r_clt = cos(peg%r_lat)\n r_slt = sin(peg%r_lat)\n r_clo = cos(peg%r_lon)\n r_slo = sin(peg%r_lon) \n r_chg = cos(peg%r_hdg)\n r_shg = sin(peg%r_hdg)\n \n ptm%r_mat(1,1) = r_clt*r_clo\n ptm%r_mat(1,2) = -r_shg*r_slo - r_slt*r_clo*r_chg\n ptm%r_mat(1,3) = r_slo*r_chg - r_slt*r_clo*r_shg\n ptm%r_mat(2,1) = r_clt*r_slo \n ptm%r_mat(2,2) = r_clo*r_shg - r_slt*r_slo*r_chg \n ptm%r_mat(2,3) = -r_clo*r_chg - r_slt*r_slo*r_shg\n ptm%r_mat(3,1) = r_slt \n ptm%r_mat(3,2) = r_clt*r_chg\n ptm%r_mat(3,3) = r_clt*r_shg\n \n do i=1,3\n do j=1,3\n ptm%r_matinv(i,j) = ptm%r_mat(j,i)\n enddo\n enddo\n \n ! find the translation vector\n ptm%r_radcur = rdir(elp%r_a,elp%r_e2,peg%r_hdg,peg%r_lat) + r_height\n \n i_type = 1\n r_llh(1) = peg%r_lat\n r_llh(2) = peg%r_lon\n r_llh(3) = r_height\n call latlon(elp,r_p,r_llh,i_type)\n \n r_clt = cos(peg%r_lat)\n r_slt = sin(peg%r_lat)\n r_clo = cos(peg%r_lon)\n r_slo = sin(peg%r_lon)\n r_up(1) = r_clt*r_clo \n r_up(2) = r_clt*r_slo\n r_up(3) = r_slt \n \n do i=1,3\n ptm%r_ov(i) = r_p(i) - ptm%r_radcur*r_up(i)\n enddo\n end subroutine radar_to_xyz\n \n \n !c****************************************************************\n !c Various curvature functions \n !c****************************************************************\n !c**\n !c** FILE NAME: curvature.f\n !c**\n !c** DATE WRITTEN: 12/02/93\n !c**\n !c** PROGRAMMER:Scott Hensley\n !c**\n !c** FUNCTIONAL DESCRIPTION: This routine computes the curvature for \n !c** of various types required for ellipsoidal or spherical earth \n !c** calculations. \n !c**\n !c** ROUTINES CALLED: none\n !c** \n !c** NOTES: none\n !c**\n !c** UPDATE LOG:\n !c**\n !c***************************************************************** \n real*8 function rdir(r_a,r_e2,r_hdg,r_lat)\n real*8, intent(in) :: r_a,r_e2,r_lat,r_hdg\n real*8 :: r_re, r_rn \n r_re = reast(r_a,r_e2,r_lat)\n r_rn = rnorth(r_a,r_e2,r_lat)\n rdir = (r_re*r_rn)/(r_re*cos(r_hdg)**2 + r_rn*sin(r_hdg)**2) \n end function rdir\n \n real*8 function reast(r_a,r_e2,r_lat)\n real*8, intent(in) :: r_a,r_e2,r_lat \n reast = r_a/sqrt(1.d0 - r_e2*sin(r_lat)**2) \n end function reast\n \n real*8 function rnorth(r_a,r_e2,r_lat)\n real*8, intent(in) :: r_a,r_e2,r_lat\n rnorth = (r_a*(1.d0 - r_e2))/(1.d0 - r_e2*sin(r_lat)**2)**(1.5d0) \n end function rnorth\n \n \n subroutine latlon(elp,r_v,r_llh,i_type) \n !c****************************************************************\n !c** \n !c** FILE NAME: latlon.f\n !c** \n !c** DATE WRITTEN:7/22/93 \n !c** \n !c** PROGRAMMER:Scott Hensley\n !c** \n !c** FUNCTIONAL DESCRIPTION:This program converts a vector to \n !c** lat,lon and height above the reference ellipsoid or given a\n !c** lat,lon and height produces a geocentric vector. \n !c** \n !c** ROUTINES CALLED:none\n !c** \n !c** NOTES: none\n !c** \n !c** UPDATE LOG:\n !c** \n !c****************************************************************\n \n \n ! input/output variables\n integer, intent(in) :: i_type !1=lat,lon to vector,2= vector to lat,lon\n type(ellipsoid), intent(in) :: elp\n real*8, intent(inout), dimension(3) :: r_v !geocentric vector (meters)\n real*8, intent(inout), dimension(3) :: r_llh !latitude (deg -90 to 90),\n !longitude (deg -180 to 180),height\n \n ! local variables\n integer i_ft\n real*8 r_re,r_q2,r_q3,r_b,r_q\n real*8 r_p,r_tant,r_theta,r_a,r_e2\n real*8 pi, r_dtor\n\n pi = getPi()\n r_dtor = pi/180.d0\n \n \n ! processing steps\n r_a = elp%r_a\n r_e2 = elp%r_e2\n \n if(i_type .eq. 1)then !convert lat,lon to vector\n r_re = r_a/sqrt(1.d0 - r_e2*sin(r_llh(1))**2)\n r_v(1) = (r_re + r_llh(3))*cos(r_llh(1))*cos(r_llh(2))\n r_v(2) = (r_re + r_llh(3))*cos(r_llh(1))*sin(r_llh(2))\n r_v(3) = (r_re*(1.d0-r_e2) + r_llh(3))*sin(r_llh(1)) \n \n elseif(i_type .eq. 2)then !convert vector to lat,lon \n r_q2 = 1.d0/(1.d0 - r_e2)\n r_q = sqrt(r_q2)\n r_q3 = r_q2 - 1.d0\n r_b = r_a*sqrt(1.d0 - r_e2)\n r_llh(2) = atan2(r_v(2),r_v(1))\n r_p = sqrt(r_v(1)**2 + r_v(2)**2)\n r_tant = (r_v(3)/r_p)*r_q\n r_theta = atan(r_tant)\n r_tant = (r_v(3) + r_q3*r_b*sin(r_theta)**3)/(r_p - r_e2*r_a*cos(r_theta)**3)\n r_llh(1) = atan(r_tant)\n r_re = r_a/sqrt(1.d0 - r_e2*sin(r_llh(1))**2)\n r_llh(3) = r_p/cos(r_llh(1)) - r_re \n endif\n end subroutine latlon\n \n \n subroutine convert_sch_to_xyz(ptm,r_schv,r_xyzv,i_type)\n !c****************************************************************\n !c**\n !c** FILE NAME: convert_sch_to_xyz.for\n !c**\n !c** DATE WRITTEN:1/15/93 \n !c**\n !c** PROGRAMMER:Scott Hensley\n !c**\n !c** FUNCTIONAL DESCRIPTION: This routine applies the affine matrix \n !c** provided to convert the sch coordinates xyz WGS-84 coordintes or\n !c** the inverse transformation.\n !c**\n !c** ROUTINES CALLED: latlon,matvec,lincomb\n !c** \n !c** NOTES: none\n !c**\n !c** UPDATE LOG:\n !c**\n !c*****************************************************************\n \n ! input/output variables\n type(pegtrans), intent(in) :: ptm\n real*8, intent(inout) :: r_schv(3) !sch coordinates of a point\n real*8, intent(inout) :: r_xyzv(3) !WGS-84 coordinates of a point\n integer, intent(in) :: i_type !i_type = 0 sch => xyz ; \n !i_type = 1 xyz => sch\n \n ! local variables\n integer i_t\n real*8 r_schvt(3),r_llh(3)\n type(ellipsoid) :: sph\n \n ! processing steps\n \n ! compute the linear portion of the transformation \n sph%r_a = ptm%r_radcur\n sph%r_e2 = 0.0d0\n \n if(i_type .eq. 0) then\n r_llh(1) = r_schv(2)/ptm%r_radcur\n r_llh(2) = r_schv(1)/ptm%r_radcur\n r_llh(3) = r_schv(3)\n i_t = 1\n call latlon(sph,r_schvt,r_llh,i_t)\n call matvec(ptm%r_mat,r_schvt,r_xyzv)\n call lincomb(1.d0,r_xyzv,1.d0,ptm%r_ov,r_xyzv) \n elseif(i_type .eq. 1)then\n call lincomb(1.d0,r_xyzv,-1.d0,ptm%r_ov,r_schvt)\n call matvec(ptm%r_matinv,r_schvt,r_schv)\n i_t = 2\n call latlon(sph,r_schv,r_llh,i_t)\n r_schv(1) = ptm%r_radcur*r_llh(2)\n r_schv(2) = ptm%r_radcur*r_llh(1)\n r_schv(3) = r_llh(3)\n end if\n end subroutine convert_sch_to_xyz\n \n \n \n \nend module coordinates\n", "meta": {"hexsha": "098d09f9d19a26490e752bd4cc4b71e4fd58e52a", "size": 9011, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "components/stdproc/rectify/geocode/src/coordinates.f90", "max_stars_repo_name": "vincentschut/isce2", "max_stars_repo_head_hexsha": "1557a05b7b6a3e65abcfc32f89c982ccc9b65e3c", "max_stars_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_stars_count": 1133, "max_stars_repo_stars_event_min_datetime": "2022-01-07T21:24:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-07T21:33:08.000Z", "max_issues_repo_path": "components/stdproc/rectify/geocode/src/coordinates.f90", "max_issues_repo_name": "vincentschut/isce2", "max_issues_repo_head_hexsha": "1557a05b7b6a3e65abcfc32f89c982ccc9b65e3c", "max_issues_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_issues_count": 276, "max_issues_repo_issues_event_min_datetime": "2019-02-10T07:18:28.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:45:55.000Z", "max_forks_repo_path": "components/stdproc/rectify/geocode/src/coordinates.f90", "max_forks_repo_name": "vincentschut/isce2", "max_forks_repo_head_hexsha": "1557a05b7b6a3e65abcfc32f89c982ccc9b65e3c", "max_forks_repo_licenses": ["ECL-2.0", "Apache-2.0"], "max_forks_count": 235, "max_forks_repo_forks_event_min_datetime": "2019-02-10T05:00:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T07:37:24.000Z", "avg_line_length": 30.3400673401, "max_line_length": 91, "alphanum_fraction": 0.5231383864, "num_tokens": 3091, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297914570318, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.666549063888837}} {"text": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\ncc cc\ncc mnconc : concur test program cc\ncc cc\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\n real x(62),w(31),u(31),t(50),c(100),wrk(1400),xx(62),db(6),de(6),\n * cp(24),dd(12),sp(62)\n integer iwrk(50)\n real ai,atan,del,fp,pi,s,sigma,ww\n integer i,ib,idim,ie,ier,iopt,is,i1,i2,j,j1,k,kk,k1,l,lwrk,l1,l2,\n * m,mx,n,nb,nc,ndd,ne,nest,nk1,np\nc the data absciss values\n data x(1),x(3),x(5),x(7),x(9),x(11),x(13),x(15),x(17),x(19),x(21),\n * x(23),x(25),x(27),x(29),x(31),x(33),x(35),x(37),x(39),x(41),\n * x(43),x(45),x(47),x(49),x(51),x(53),x(55),x(57),x(59),x(61)/\n * -3.109,-2.188,-1.351,-0.605,0.093,0.451,0.652,0.701,0.518,0.277,\n * 0.008,-0.291,-0.562,-0.679,-0.637,-0.425,-0.049,0.575,1.334,\n * 2.167,3.206,4.099,4.872,5.710,6.330,6.741,6.928,6.965,6.842,\n * 6.593,6.269/\nc the data ordinate values\n data x(2),x(4),x(6),x(8),x(10),x(12),x(14),x(16),x(18),x(20),\n * x(22),x(24),x(26),x(28),x(30),x(32),x(34),x(36),x(38),x(40),\n * x(42),x(44),x(46),x(48),x(50),x(52),x(54),x(56),x(58),x(60),\n * x(62)/3.040,2.876,2.634,2.183,1.586,1.010,0.382,-0.218,-0.632,\n * -0.879,-0.981,-0.886,-0.642,-0.195,0.373,1.070,1.607,2.165,2.618,\n * 2.905,2.991,2.897,2.615,2.164,1.617,0.977,0.383,-0.194,-0.665,\n * -0.901,-1.010/\nc m denotes the number of data points\n m = 31\nc set up the parameter values for the data points\n pi = atan(1.0)*4.0\n del =pi*0.1\n do 10 i=1,m\n ai = i-11\n u(i) = ai*del\n 10 continue\nc the weights are taken as 1/sigma with sigma an estimate of the\nc standard deviation of the data points.\n sigma = 0.04\n ww = 1./sigma\n do 20 i=1,m\n w(i) = ww\n 20 continue\nc accordingly, the smoothing factor is chosen as s = m\n s = m\nc we have a planar curve x = sx(u) , y = sy(u)\n idim = 2\nc begin point derivatives of the curve\n db(1) = -pi\n db(2) = 3.0\n db(3) = 3.0\n db(4) = 0.\n db(5) = 0.\n db(6) = -2.0\nc end point derivatives of the curve\n de(1) = pi*2.0\n de(2) = -1.0\n de(3) = -1.0\n de(4) = 0.\n de(5) = 0.\n de(6) = 2.0\nc we set up the dimension information.\n ndd = 12\n np = 24\n nb = 6\n ne = 6\n nest = 50\n lwrk = 1400\n nc = 100\n mx = 62\nc for the first approximations we will use cubic splines.\n k = 3\nc loop for the different spline curves\n do 500 is=1,7\n go to (110,120,130,140,150,160,170), is\nc no derivative constraints\n 110 iopt = 0\n ib = 0\n ie = 0\n go to 200\nc fixed end points.\n 120 iopt = 0\n ib = 1\n ie = 1\n go to 200\nc first derivative constraint at the end point\n 130 iopt = 0\n ib = 2\n ie = 1\n go to 200\nc first derivative constraints at begin and end point.\n 140 iopt = 0\n ib = 2\n ie = 2\n go to 200\nc we choose quintic splines with second derivative constraints.\n 150 iopt = 0\n k = 5\n ib = 3\n ie = 3\n go to 200\nc we choose another s-value and continue with the set of knots found at\nc the last call of concur.\n 160 iopt = 1\n s = 26.\n go to 200\nc finally we also calculate a least-squares curve with specified knots\n 170 iopt = -1\n j = k+2\n do 180 l=1,5\n ai = l-2\n t(j) = ai*pi*0.5\n j = j+1\n 180 continue\n n = 7+2*k\nc determination of the spline curve.\n 200 call concur(iopt,idim,m,u,mx,x,xx,w,ib,db,nb,ie,de,ne,k,s,\n * nest,n,t,nc,c,np,cp,fp,wrk,lwrk,iwrk,ier)\nc printing of the results.\n if(iopt.ge.0) go to 210\n write(6,910) k\n go to 220\n 210 write(6,915) k\n write(6,920) s\n 220 write(6,925) ib,ie\n write(6,930) fp,ier\n write(6,935) n\n write(6,940)\n write(6,945) (t(i),i=1,n)\n nk1 = n-k-1\n write(6,950)\n write(6,945) (c(l),l=1,nk1)\n write(6,955)\n i1 = n+1\n i2 = n+nk1\n write(6,945) (c(l),l=i1,i2)\nc calculate derivatives at the begin point.\n k1 = k+1\n kk = k1/2\n call cualde(idim,t,n,c,nc,k1,u(1),dd,ndd,ier)\n write(6,960)\n do 300 i=1,kk\n l = i-1\n l1 = l*idim+1\n l2 = l1+1\n write(6,970) l,dd(l1),dd(l2)\n 300 continue\nc calculate derivatives at the end point.\n call cualde(idim,t,n,c,nc,k1,u(m),dd,ndd,ier)\n write(6,965)\n do 350 i=1,kk\n l = i-1\n l1 = l*idim+1\n l2 = l1+1\n write(6,970) l,dd(l1),dd(l2)\n 350 continue\nc we evaluate the spline curve\n call curev(idim,t,n,c,nc,k,u,m,sp,mx,ier)\n write(6,975)\n do 400 i=1,5\n l = (i-1)*12+3\n l1 = l+1\n j = l+6\n j1 = j+1\n write(6,980) x(l),x(l1),sp(l),sp(l1),x(j),x(j1),sp(j),sp(j1)\n 400 continue\n 500 continue\n stop\n 910 format(31h0least-squares curve of degree ,i1)\n 915 format(27h0smoothing curve of degree ,i1)\n 920 format(20h smoothing factor s=,f5.0)\n 925 format(37h number of derivative constraints ib=,i2,5x,3hie=,i2)\n 930 format(1x,23hsum squared residuals =,e15.6,5x,11herror flag=,i2)\n 935 format(1x,24htotal number of knots n=,i3)\n 940 format(1x,22hposition of the knots )\n 945 format(5x,8f8.4)\n 950 format(1x,30hb-spline coefficients of sx(u))\n 955 format(1x,30hb-spline coefficients of sy(u))\n 960 format(1x,30hderivatives at the begin point)\n 965 format(1x,28hderivatives at the end point)\n 970 format(5x,6horder=,i2,2f9.4)\n 975 format(1h0,2(4x,2hxi,7x,2hyi,6x,6hsx(ui),3x,6hsy(ui)))\n 980 format(1h ,8f9.4)\n end\n", "meta": {"hexsha": "cfcd434dc868afd703338749638b75c65ad8802c", "size": 5988, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ApproxSpline/Resources/F77-Sources/ex/mnconc.f", "max_stars_repo_name": "modelica-3rdparty/ApproxSpline", "max_stars_repo_head_hexsha": "28420f5c1a88c9cd069defbd8c05e4a78a090675", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-07-13T17:24:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-18T16:16:02.000Z", "max_issues_repo_path": "ApproxSpline/Resources/F77-Sources/ex/mnconc.f", "max_issues_repo_name": "tbeu/ApproxSpline", "max_issues_repo_head_hexsha": "28420f5c1a88c9cd069defbd8c05e4a78a090675", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-03-28T09:08:23.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T07:35:48.000Z", "max_forks_repo_path": "ApproxSpline/Resources/F77-Sources/ex/mnconc.f", "max_forks_repo_name": "modelica-3rdparty/ApproxSpline", "max_forks_repo_head_hexsha": "28420f5c1a88c9cd069defbd8c05e4a78a090675", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-10-21T07:46:49.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T20:02:06.000Z", "avg_line_length": 32.3675675676, "max_line_length": 72, "alphanum_fraction": 0.5298931196, "num_tokens": 2415, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297834483232, "lm_q2_score": 0.7401743677704878, "lm_q1q2_score": 0.666549063122357}} {"text": "!\n!\n!\n!\n SUBROUTINE HARMO_Y_L (LMAX, LON, LAT, Y_L)\n USE SHTOOLS \n IMPLICIT NONE \n INTEGER, PARAMETER :: LLMAX=512, JJMAX=(LLMAX+1)*(LLMAX+2)/2 \n INTEGER J, MJ, J_INDEX, LMAX \n COMPLEX*16, PARAMETER :: I = CMPLX(0.,1.)\n COMPLEX*16 Y_L(*) \n REAL*8 LON, LAT\n REAL*8, ALLOCATABLE :: PLM(:) \n REAL*8 COSDD, SINDD\n INTEGER :: JMAX\n!\n!\n! Given longitude LON and latitude LAT - in degrees - this routine computes \n! the lambda-component of the gradient of *all* the 4-pi normalized complex \n! harmonics $\\cal Y_{lm}(\\theta,\\lambda)$, with \\theta=colatitude and \\lambda=\n! longitude, to degree LMAX given. Uses the (modified) SHTOOLS Legendre \n! functions by PlmBar (see Sbr PLMBAR_MOD_D1). - Created by GS August 8, 2008 - \n!\n! - Modified by GS Apr 2020 -- dynamically allocate PLM\n!\n!*********************************************************************\n! Modified GS on MAy 1, 2020 \n!\n! The routine computes \"y_l = (1/sin theta)(d/dlambda) y\" \n!*********************************************************************\n!\n!\n! ---- Tests the longitude and latitude bounds \n If(abs(lat)>90.) then \n \t Write(* ,*) \"Error in Sbr. GRAD_LAMBDA_HARMO: Latitude is out of range\" \n\t \tWrite(* ,*) \"The program will STOP ----------------\"\n call stop_config \n\t Stop 1\t\t\n elseif (lon<0.or.lon>360.) then\n \t Write(* ,*) \"Error in Sbr. GRAD_LAMBDA_HARMO: Longitude is out of range\" \n\t \tWrite(* ,*) \"The program will STOP ----------------\"\n call stop_config \n\t Stop 2\t\n Endif \n! \n!\n! ---- Allocate temporary arrays\n!\n JMAX=(LMAX+1)*(LMAX+2)/2\n ALLOCATE( PLM(JMAX) )\n!\n! ---- Builds the SHTOOLS Legendre functions, with Condon-Shortley phase \n!\n CALL PLMBAR_MOD (LMAX, LAT, PLM) \n!\n! \n! ---- Computes the 4-pi normalized Spherical Harmonics up to degree LMAX\n!\n \t\tdo j=1, j_index(lmax,lmax)\n!\n \t\t\ty_l(j) = &\n\t PLM(j)*I*mj(j)* &\n\t cmplx(cosdd(float(mj(j))*lon),sindd(float(mj(j))*lon))/ &\n\t sindd(90.-lat) \n!\n \t\tenddo\n!\n!\n! ---- Release memory\n!\n DEALLOCATE( PLM )\n!\nEND SUBROUTINE HARMO_Y_L\n!\n!\n!\n", "meta": {"hexsha": "4fac5afdd1fc206669f8c6322a9d61b423a3bda8", "size": 2136, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/y_l.f90", "max_stars_repo_name": "gassmoeller/selen", "max_stars_repo_head_hexsha": "796ed0c3b994e0a8d447934f3ec2863a2d2804ab", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2016-01-15T16:22:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-11T03:05:48.000Z", "max_issues_repo_path": "src/y_l.f90", "max_issues_repo_name": "gassmoeller/selen", "max_issues_repo_head_hexsha": "796ed0c3b994e0a8d447934f3ec2863a2d2804ab", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2015-10-14T21:07:01.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T20:08:24.000Z", "max_forks_repo_path": "src/y_l.f90", "max_forks_repo_name": "gassmoeller/selen", "max_forks_repo_head_hexsha": "796ed0c3b994e0a8d447934f3ec2863a2d2804ab", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2015-08-26T10:55:15.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-01T16:31:11.000Z", "avg_line_length": 27.7402597403, "max_line_length": 83, "alphanum_fraction": 0.5543071161, "num_tokens": 643, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297807787537, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.6665490611464101}} {"text": "MODULE vectors\r\n!\r\n! Purpose:\r\n! To define a derived data type called vector, and the\r\n! operations which can be performed on it. The module\r\n! defines 8 operations which can be performed on vectors:\r\n!\r\n! Operation Operator\r\n! ========= ========\r\n! 1. Creation from a real array =\r\n! 2. Conversion to real array =\r\n! 3. Vector addition +\r\n! 4. Vector subtraction -\r\n! 5. Vector-scalar multiplication (4 cases) *\r\n! 6. Vector-scalar division (2 cases) /\r\n! 7. Dot product .DOT. \r\n! 8. Cross product *\r\n!\r\n! It contains a total of 12 procedures to implement those\r\n! operations: array_to_vector, vector_to_array, vector_add,\r\n! vector_subtract, vector_times_real, real_times_vector,\r\n! vector_times_int, int_times_vector, vector_div_real,\r\n! vector_div_int, dot_product, and cross_product. These\r\n! procedures are private to the module; they can only be\r\n! accessed from the outside via the defined operators.\r\n!\r\n! Record of revisions:\r\n! Date Programmer Description of change\r\n! ==== ========== =====================\r\n! 12/15/06 S. J. Chapman Original code\r\n! 1. 12/16/06 S. J. Chapman Modified to hide non-\r\n! essential items.\r\n!\r\nIMPLICIT NONE\r\n\r\n! Declare all items to be private except for type vector and\r\n! the operators defined for it.\r\nPRIVATE\r\nPUBLIC :: vector, assignment(=), operator(+), operator(-), &\r\n operator(*), operator(/), operator(.DOT.)\r\n\r\n! Declare vector data type:\r\nTYPE :: vector\r\n REAL :: x\r\n REAL :: y\r\n REAL :: z\r\nEND TYPE\r\n\r\n! Declare interface operators\r\nINTERFACE ASSIGNMENT (=)\r\n MODULE PROCEDURE array_to_vector\r\n MODULE PROCEDURE vector_to_array\r\nEND INTERFACE\r\n\r\nINTERFACE OPERATOR (+)\r\n MODULE PROCEDURE vector_add\r\nEND INTERFACE\r\n\r\nINTERFACE OPERATOR (-)\r\n MODULE PROCEDURE vector_subtract\r\nEND INTERFACE\r\n\r\nINTERFACE OPERATOR (*)\r\n MODULE PROCEDURE vector_times_real\r\n MODULE PROCEDURE real_times_vector\r\n MODULE PROCEDURE vector_times_int\r\n MODULE PROCEDURE int_times_vector\r\n MODULE PROCEDURE cross_product\r\nEND INTERFACE\r\n\r\nINTERFACE OPERATOR (/)\r\n MODULE PROCEDURE vector_div_real\r\n MODULE PROCEDURE vector_div_int\r\nEND INTERFACE\r\n\r\nINTERFACE OPERATOR (.DOT.)\r\n MODULE PROCEDURE dot_product\r\nEND INTERFACE\r\n\r\n\r\n! Now define the implementing functions.\r\nCONTAINS\r\n SUBROUTINE array_to_vector(vec_result, array)\r\n TYPE (vector), INTENT(OUT) :: vec_result\r\n REAL, DIMENSION(3), INTENT(IN) :: array\r\n vec_result%x = array(1)\r\n vec_result%y = array(2)\r\n vec_result%z = array(3)\r\n END SUBROUTINE array_to_vector\r\n\r\n\r\n SUBROUTINE vector_to_array(array_result, vec_1)\r\n REAL, DIMENSION(3), INTENT(OUT) :: array_result\r\n TYPE (vector), INTENT(IN) :: vec_1\r\n array_result(1) = vec_1%x\r\n array_result(2) = vec_1%y\r\n array_result(3) = vec_1%z\r\n END SUBROUTINE vector_to_array\r\n\r\n\r\n FUNCTION vector_add(vec_1, vec_2)\r\n TYPE (vector) :: vector_add\r\n TYPE (vector), INTENT(IN) :: vec_1, vec_2\r\n vector_add%x = vec_1%x + vec_2%x\r\n vector_add%y = vec_1%y + vec_2%y\r\n vector_add%z = vec_1%z + vec_2%z\r\n END FUNCTION vector_add\r\n\r\n\r\n FUNCTION vector_subtract(vec_1, vec_2)\r\n TYPE (vector) :: vector_subtract\r\n TYPE (vector), INTENT(IN) :: vec_1, vec_2\r\n vector_subtract%x = vec_1%x - vec_2%x\r\n vector_subtract%y = vec_1%y - vec_2%y\r\n vector_subtract%z = vec_1%z - vec_2%z\r\n END FUNCTION vector_subtract\r\n\r\n\r\n FUNCTION vector_times_real(vec_1, real_2)\r\n TYPE (vector) :: vector_times_real\r\n TYPE (vector), INTENT(IN) :: vec_1\r\n REAL, INTENT(IN) :: real_2\r\n vector_times_real%x = vec_1%x * real_2\r\n vector_times_real%y = vec_1%y * real_2\r\n vector_times_real%z = vec_1%z * real_2\r\n END FUNCTION vector_times_real\r\n\r\n\r\n FUNCTION real_times_vector(real_1, vec_2)\r\n TYPE (vector) :: real_times_vector\r\n REAL, INTENT(IN) :: real_1\r\n TYPE (vector), INTENT(IN) :: vec_2\r\n real_times_vector%x = real_1 * vec_2%x\r\n real_times_vector%y = real_1 * vec_2%y\r\n real_times_vector%z = real_1 * vec_2%z\r\n END FUNCTION real_times_vector\r\n\r\n\r\n FUNCTION vector_times_int(vec_1, int_2)\r\n TYPE (vector) :: vector_times_int\r\n TYPE (vector), INTENT(IN) :: vec_1\r\n INTEGER, INTENT(IN) :: int_2\r\n vector_times_int%x = vec_1%x * REAL(int_2)\r\n vector_times_int%y = vec_1%y * REAL(int_2)\r\n vector_times_int%z = vec_1%z * REAL(int_2)\r\n END FUNCTION vector_times_int\r\n\r\n\r\n FUNCTION int_times_vector(int_1, vec_2)\r\n TYPE (vector) :: int_times_vector\r\n INTEGER, INTENT(IN) :: int_1\r\n TYPE (vector), INTENT(IN) :: vec_2\r\n int_times_vector%x = REAL(int_1) * vec_2%x\r\n int_times_vector%y = REAL(int_1) * vec_2%y\r\n int_times_vector%z = REAL(int_1) * vec_2%z\r\n END FUNCTION int_times_vector\r\n\r\n\r\n FUNCTION vector_div_real(vec_1, real_2)\r\n TYPE (vector) :: vector_div_real\r\n TYPE (vector), INTENT(IN) :: vec_1\r\n REAL, INTENT(IN) :: real_2\r\n vector_div_real%x = vec_1%x / real_2\r\n vector_div_real%y = vec_1%y / real_2\r\n vector_div_real%z = vec_1%z / real_2\r\n END FUNCTION vector_div_real\r\n\r\n\r\n FUNCTION vector_div_int(vec_1, int_2)\r\n TYPE (vector) :: vector_div_int\r\n TYPE (vector), INTENT(IN) :: vec_1\r\n INTEGER, INTENT(IN) :: int_2\r\n vector_div_int%x = vec_1%x / REAL(int_2)\r\n vector_div_int%y = vec_1%y / REAL(int_2)\r\n vector_div_int%z = vec_1%z / REAL(int_2)\r\n END FUNCTION vector_div_int\r\n\r\n\r\n FUNCTION dot_product(vec_1, vec_2)\r\n REAL :: dot_product\r\n TYPE (vector), INTENT(IN) :: vec_1, vec_2\r\n dot_product = vec_1%x*vec_2%x + vec_1%y*vec_2%y &\r\n + vec_1%z*vec_2%z \r\n END FUNCTION dot_product\r\n\r\n\r\n FUNCTION cross_product(vec_1, vec_2)\r\n TYPE (vector) :: cross_product\r\n TYPE (vector), INTENT(IN) :: vec_1, vec_2\r\n cross_product%x = vec_1%y*vec_2%z - vec_1%z*vec_2%y\r\n cross_product%y = vec_1%z*vec_2%x - vec_1%x*vec_2%z\r\n cross_product%z = vec_1%x*vec_2%y - vec_1%y*vec_2%x\r\n END FUNCTION cross_product\r\n\r\nEND MODULE vectors\r\n", "meta": {"hexsha": "bdd36e7d4960ef5a7a24315952e24956c792d36a", "size": 6444, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap13/vectors_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/chap13/vectors_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/chap13/vectors_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": 32.8775510204, "max_line_length": 64, "alphanum_fraction": 0.6221291124, "num_tokens": 1807, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297754396141, "lm_q2_score": 0.7401743677704878, "lm_q1q2_score": 0.6665490571945157}} {"text": "! -*- mode: F90; mode: font-lock; column-number-mode: true; vc-back-end: CVS -*-\n! ------------------------------------------------------------------------------\n! $Id$\n! ------------------------------------------------------------------------------\n! Module numbers\n! ------------------------------------------------------------------------------\n! Code area 9: general\n! ------------------------------------------------------------------------------\n\n!!****h* Conquest/numbers\n!! NAME\n!! numbers\n!! PURPOSE\n!! Defines various numerical constants\n!! USES\n!! datatypes\n!! AUTHOR\n!! C.M.Goringe/E.H.Hernandez/I.J.Bush/D.R.Bowler\n!! CREATION DATE\n!! Sometime between 1995 and 1999\n!! MODIFICATION HISTORY\n!! 30/05/2001 dave\n!! Added ROBODoc header\n!! 31/05/2001 dave\n!! Added minus_i and RCS Id tag\n!! 18/03/2002 dave\n!! Added static RCS id and more to header\n!! 04/07/2002 mike\n!! Added fifteen, sixteen, three_quarters and three_halves\n!! 22/03/2011 L.Tong\n!! Added third\n!! 2011/09/19 L.Tong\n!! Added minus_two\n!! 2011/11/13 L.Tong\n!! Added eight and twelve\n!! 2012/02/26 L.Tong\n!! Added minus_one, nine and ten\n!! 2012/05/27 L.Tong\n!! Added RD_ERR, a tiny number that if any number N with abs(N) <\n!! RD_ERR, then N is regarded as zero.\n!! 2014/08/29 L.Truflandier\n!! Added fourpi\n!! SOURCE\n!!\nmodule numbers\n\n use datatypes\n\n implicit none \n\n ! RCS tag for object file identification\n character(len=80), save, private :: &\n RCSid = \"$Id$\"\n\n real(double), parameter :: zero = 0.0_double \n real(double), parameter :: one = 1.0_double \n real(double), parameter :: two = 2.0_double \n real(double), parameter :: three = 3.0_double \n real(double), parameter :: four = 4.0_double \n real(double), parameter :: five = 5.0_double \n real(double), parameter :: six = 6.0_double \n real(double), parameter :: seven = 7.0_double\n real(double), parameter :: eight = 8.0_double\n real(double), parameter :: nine = 9.0_double\n real(double), parameter :: ten = 10.0_double\n real(double), parameter :: eleven = 11.0_double\n real(double), parameter :: twelve = 12.0_double\n real(double), parameter :: fifteen = 15.0_double\n real(double), parameter :: sixteen = 16.0_double\n real(double), parameter :: eighteen = 18.0_double\n real(double), parameter :: minus_one = -1.0_double\n real(double), parameter :: minus_two = -2.0_double\n real(double), parameter :: minus_four = -4.0_double \n real(double), parameter :: quarter = 0.25_double\n real(double), parameter :: half = 0.5_double \n real(double), parameter :: third = 0.33333333333333333333_double\n real(double), parameter :: three_quarters = 0.75_double\n real(double), parameter :: nine_quarters = 2.25_double\n real(double), parameter :: three_halves = 1.5_double\n real(double), parameter :: one_third = 1.0_double/3.0_double\n real(double), parameter :: two_thirds = 2.0_double/3.0_double\n real(double), parameter :: four_thirds = 4.0_double/3.0_double\n real(double), parameter :: one_sixth = 1.0_double/6.0_double\n real(double), parameter :: five_sixths = 5.0_double/6.0_double\n real(double), parameter :: seven_sixths = 7.0_double/6.0_double\n real(double), parameter :: one_ninth = 1.0_double/9.0_double\n real(double), parameter :: seven_thirtysixths = 7.0_double/36.0_double\n real(double), parameter :: pi = 3.14159265358979323846_double \n real(double), parameter :: twopi = 6.28318530717958647692_double\n real(double), parameter :: fourpi = 6.28318530717958647692_double*2.0_double\n real(double), parameter :: sqrt_pi = 1.77245385090551588192_double\n real(double), parameter :: very_small = 1.0e-8_double\n real(double), parameter :: BIG = 1.0e12_double \n ! if a abs(number) is smaller than RD_ERR then it is considered to be zero\n real(double), parameter :: RD_ERR = 1.0e-8_double\n\n complex(double_cplx), parameter :: minus_i = (0.0_double_cplx, -1.0_double_cplx)\n\nend module numbers\n!!***\n", "meta": {"hexsha": "22967579dbab392cf3a8d35946ba2c97726b9d1f", "size": 3950, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tools/BasisGeneration/numbers.module.f90", "max_stars_repo_name": "negf/CONQUEST-release", "max_stars_repo_head_hexsha": "11688947f9ad0a6799f10a89493f0b5f46fb0402", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 51, "max_stars_repo_stars_event_min_datetime": "2020-01-29T14:11:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T16:29:13.000Z", "max_issues_repo_path": "tools/BasisGeneration/numbers.module.f90", "max_issues_repo_name": "negf/CONQUEST-release", "max_issues_repo_head_hexsha": "11688947f9ad0a6799f10a89493f0b5f46fb0402", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 63, "max_issues_repo_issues_event_min_datetime": "2020-01-28T13:33:54.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-14T15:19:06.000Z", "max_forks_repo_path": "tools/BasisGeneration/numbers.module.f90", "max_forks_repo_name": "negf/CONQUEST-release", "max_forks_repo_head_hexsha": "11688947f9ad0a6799f10a89493f0b5f46fb0402", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2020-01-30T13:10:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-02T09:50:00.000Z", "avg_line_length": 39.1089108911, "max_line_length": 82, "alphanum_fraction": 0.6344303797, "num_tokens": 1154, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.900529778109184, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6665490488477412}} {"text": "! testprogram using Wolfer\u2019s sunspot data (Anderson 1971)\n! calculating periodogram\n! find best parameter for linear reservoir of logarithmic\n! periodogram\n\n\nPROGRAM sunspot_test\n\n USE mo_kind, only: i4, dp\n use mo_ansi_colors, only: color, c_red, c_green\n USE mo_specan, only: periodogram, linres\n\n IMPLICIT NONE\n\n INTEGER(i4) :: i\n\n REAL(dp), DIMENSION(176) :: sunspot\n REAL(dp), DIMENSION(176) :: time \n ! REAL(dp), DIMENSION(176) :: sun_trans\n REAL(dp), DIMENSION(176/2,2) :: output\n REAL(dp), DIMENSION(2) :: bestpara\n\n logical :: isgood\n\n isgood = .true.\n\n sunspot = (/809.0_dp, 834.0_dp, 477.0_dp, 478.0_dp, 307.0_dp, 122.0_dp, 96.0_dp, &\n 102.0_dp, 324.0_dp, 476.0_dp, 540.0_dp, 629.0_dp, 859.0_dp, 612.0_dp, &\n 451.0_dp, 364.0_dp, 209.0_dp, 114.0_dp, 378.0_dp, 698.0_dp, 1061.0_dp, &\n 1008.0_dp, 816.0_dp, 665.0_dp, 348.0_dp, 306.0_dp, 70.0_dp, 198.0_dp, &\n 925.0_dp, 1544.0_dp, 1259.0_dp, 848.0_dp, 681.0_dp, 385.0_dp, 228.0_dp, &\n 102.0_dp, 241.0_dp, 829.0_dp, 1320.0_dp, 1309.0_dp, 1181.0_dp, 899.0_dp, &\n 666.0_dp, 600.0_dp, 469.0_dp, 410.0_dp, 213.0_dp, 160.0_dp, 64.0_dp, &\n 41.0_dp, 68.0_dp, 145.0_dp, 340.0_dp, 450.0_dp, 431.0_dp, 475.0_dp, &\n 422.0_dp, 281.0_dp, 101.0_dp, 81.0_dp, 25.0_dp, 0.0_dp, 14.0_dp, &\n 50.0_dp, 122.0_dp, 139.0_dp, 354.0_dp, 458.0_dp, 411.0_dp, 304.0_dp, &\n 239.0_dp, 157.0_dp, 66.0_dp, 40.0_dp, 18.0_dp, 85.0_dp, 166.0_dp, &\n 363.0_dp, 497.0_dp, 625.0_dp, 670.0_dp, 710.0_dp, 478.0_dp, 275.0_dp, &\n 85.0_dp, 132.0_dp, 569.0_dp, 1215.0_dp, 1383.0_dp, 1032.0_dp, 858.0_dp, &\n 632.0_dp, 368.0_dp, 242.0_dp, 107.0_dp, 150.0_dp, 401.0_dp, 615.0_dp, &\n 985.0_dp, 1243.0_dp, 959.0_dp, 665.0_dp, 645.0_dp, 542.0_dp, 390.0_dp, &\n 206.0_dp, 67.0_dp, 43.0_dp, 228.0_dp, 548.0_dp, 938.0_dp, 957.0_dp, &\n 772.0_dp, 591.0_dp, 440.0_dp, 470.0_dp, 305.0_dp, 163.0_dp, 73.0_dp, &\n 373.0_dp, 739.0_dp, 1391.0_dp, 1112.0_dp, 1017.0_dp, 663.0_dp, 447.0_dp, &\n 171.0_dp, 113.0_dp, 123.0_dp, 34.0_dp, 60.0_dp, 323.0_dp, 543.0_dp, &\n 597.0_dp, 637.0_dp, 635.0_dp, 522.0_dp, 254.0_dp, 131.0_dp, 68.0_dp, &\n 63.0_dp, 71.0_dp, 356.0_dp, 730.0_dp, 849.0_dp, 780.0_dp, 640.0_dp, &\n 418.0_dp, 262.0_dp, 267.0_dp, 121.0_dp, 95.0_dp, 27.0_dp, 50.0_dp, &\n 244.0_dp, 420.0_dp, 635.0_dp, 538.0_dp, 620.0_dp, 485.0_dp, 439.0_dp, &\n 186.0_dp, 57.0_dp, 36.0_dp, 14.0_dp, 96.0_dp, 474.0_dp, 571.0_dp, &\n 1039.0_dp, 806.0_dp, 636.0_dp, 376.0_dp, 261.0_dp, 142.0_dp, 58.0_dp, &\n 167.0_dp/)\n\n time(1)=1749.0_dp\n\n do i = 2, 176\n time(i) = time(i-1) + 1.0_dp\n end do\n\n call periodogram(sunspot,output)\n\n write(*,*) 'printing first five values of periodogram:'\n\n do i = 1, 5\n write(*,*) output(i,:)\n end do\n\n call linres( &\n output(:,2), & ! data(:) Time series\n 0.00000005_dp, & ! a_min minimum of first parameter\n 0.1_dp, & ! a_max maximum of first parameter\n 0._dp, & ! tc_min minimum of second parameter\n 100._dp, & ! tc_max maximum of second parameter\n 0.0000005_dp, & ! initial_a first initial parameter\n 50._dp, & ! initial_tc second initial parameter\n bestpara ) ! best parameter set\n\n write(*,*) 'best parameter found:'\n write(*,*) ' alpha:', bestpara(1)\n write(*,*) ' tc: ', bestpara(2)\n\n ! check if program was running properly\n isgood = isgood .and. ( 35268373_i4 .eq. int(output(1,2),i4) )\n isgood = isgood .and. ( 1589_i4 .eq. int(output(2,2),i4) )\n isgood = isgood .and. ( 1217716_i4 .eq. int(output(3,2),i4) )\n isgood = isgood .and. ( 538747_i4 .eq. int(output(4,2),i4) )\n isgood = isgood .and. ( 245925_i4 .eq. int(output(5,2),i4) )\n\n isgood = isgood .and. ( 6368_i4 .eq. int(bestpara(1)*10000000.0_dp,i4) )\n isgood = isgood .and. ( 376437_i4 .eq. int(bestpara(2)*10000.0_dp,i4) )\n\n write(*,*) ''\n if (isgood) then\n write(*,*) 'mo_specan: ', color('o.k.', c_green)\n else\n write(*,*) 'mo_specan: ', color('failed', c_red)\n end if\n\nEND PROGRAM sunspot_test\n", "meta": {"hexsha": "8a0be0a466291e4ae8171f3826fbdf72684e57f3", "size": 4307, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/test_mo_specan/main.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_specan/main.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_specan/main.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": 43.07, "max_line_length": 84, "alphanum_fraction": 0.5862549338, "num_tokens": 1891, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297754396142, "lm_q2_score": 0.7401743505760728, "lm_q1q2_score": 0.6665490417104332}} {"text": "program main\r\nuse iso_fortran_env, only: input_unit,output_unit\r\nimplicit none\r\ninteger :: n\r\nprint*,\"enter an integer\"\r\nread (input_unit,*) n ! equivalent to next line\r\n! read (*,*) n \r\nprint \"(i0,'^2 = ',i0)\",n,n**2 ! prints to screen\r\nopen (unit=output_unit,file=\"temp.txt\",action=\"write\")\r\n! causes each line below to write to temp.txt\r\nprint \"(i0,'^3 = ',i0)\", n,n**3\r\nwrite (*,\"(i0,'^4 = ',i0)\") n,n**4\r\nwrite (output_unit,\"(i0,'^5 = ',i0)\") n,n**5\r\nend program main\r\n! sample run, compiling with gfortran, flang, g95, \r\n! or ifort -standard-semantics:\r\n! enter an integer\r\n! 10\r\n! 10^2 = 100\r\n! contents of temp.txt:\r\n! 10^3 = 1000\r\n! 10^4 = 10000\r\n! 10^5 = 100000", "meta": {"hexsha": "a830e2f63669351a518e2ca8788c42aed3439683", "size": 672, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "output_unit.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": "output_unit.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": "output_unit.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.2173913043, "max_line_length": 55, "alphanum_fraction": 0.6324404762, "num_tokens": 238, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424295406087, "lm_q2_score": 0.7879311956428946, "lm_q1q2_score": 0.6665444299529869}} {"text": " \tprogram exptest\nc-------------------------------------------------------------------\nc\nc Test program for exponential propagator using Arnoldi approach\nc This main program is a very simple test using diagonal matrices\nc (Krylov subspace methods are blind to the structure of the matrix\nc except for symmetry). This provides a good way of testing the\nc accuracy of the method as well as the error estimates.\nc\nc-------------------------------------------------------------------\n implicit real*8 (a-h,o-z)\n parameter (nmax = 400, ih0=60, ndmx=20,nzmax = 7*nmax)\n real*8 a(nzmax), u(ih0*nmax), w(nmax),w1(nmax),x(nmax),y(nmax)\n\tinteger ioff(10) \n\tdata iout/6/, a0/0.0/, b0/1.0/, epsmac/1.d-10/, eps /1.d-10/\nc\nc set dimension of matrix\nc\n\tn = 100\nc--------------------------- define matrix -----------------------------\nc A is a single diagonal matrix (ndiag = 1 and ioff(1) = 0 ) \nc-----------------------------------------------------------------------\n ndiag = 1\n\tioff(1) = 0\nc\nc-------- entries in the diagonal are uniformly distributed. \nc\n\th = 1.0d0 / real(n+1)\n do 1 j=1, n\n\ta(j) = real(j+1)* h \n 1\tcontinue\nc-------- \n write (6,'(10hEnter tn: ,$)')\n\tread (5,*) tn \nc\n write (6,'(36hEpsilon (desired relative accuracy): ,$)')\n\tread (5,*) eps \nc------- \n write (6,'(36h m (= dimension of Krylov subspace): ,$)')\n\tread (5,*) m \nc------- \nc define initial conditions: chosen so that solution = (1,1,1,1..1)^T\nc-------\n\tdo 2 j=1,n\n\tw(j) = dexp(a(j)*tn) \n 2\tw1(j) = w(j) \nc\n call expprod (n, m, eps, tn, u, w, x, y, a, ioff, ndiag)\nc\n print *, ' final answer '\n print *, (w(k),k=1,20) \nc \n\tdo 4 k=1,n\n 4\tw1(k) = dexp(-a(k)*tn) * w1(k) \n print *, ' exact solution '\n print *, (w1(k),k=1,20) \nc\nc---------- computing actual 2-norm of error ------------------\nc\n\tt = 0.0d0\n\tdo 47 k=1,n\n 47\tt = t+ (w1(k)-w(k))**2\n t = dsqrt(t / ddot(n, w,1,w,1) )\nc\n write (6,*) ' final error', t\nc--------------------------------------------------------------\n\tstop\n\tend\nc------- \n\tsubroutine oped(n,x,y,diag,ioff,ndiag)\nc======================================================\nc this kernel performs a matrix by vector multiplication\nc for a diagonally structured matrix stored in diagonal\nc format\nc======================================================\n\timplicit real*8 (a-h,o-z)\n\treal*8 x(n), y(n), diag(n,ndiag)\n\tcommon nope, nmvec\n\tinteger j, n, ioff(ndiag)\nCDIR$ IVDEP\n\tdo 1 j=1, n\n\t\ty(j) = 0.00\n 1\tcontinue\t\nc\n\tdo 10 j=1,ndiag\n\tio = ioff(j)\n\ti1=max0(1,1-io)\n\ti2=min0(n,n-io)\nCDIR$ IVDEP\n\tdo 9 k=i1,i2\n\ty(k) = y(k)+diag(k,j)*x(k+io)\n 9\tcontinue\n 10\tcontinue\n\tnmvec = nmvec + 1 \n\tnope = nope + 2*ndiag*n\n\treturn\n\tend\nc\n", "meta": {"hexsha": "c5629b0e0e9ff6e3f7554fc8f5a8843779c90b54", "size": 2729, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/latools/SPARSKIT2/UNSUPP/MATEXP/rexp.f", "max_stars_repo_name": "xywei/Mirana", "max_stars_repo_head_hexsha": "81d0ed67fad20cd3be8880ed672c12feff3c22c9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-03-11T15:22:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-22T16:26:18.000Z", "max_issues_repo_path": "src/latools/SPARSKIT2/UNSUPP/MATEXP/rexp.f", "max_issues_repo_name": "xywei/Mirana", "max_issues_repo_head_hexsha": "81d0ed67fad20cd3be8880ed672c12feff3c22c9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2021-06-30T20:39:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-15T12:42:50.000Z", "max_forks_repo_path": "src/latools/SPARSKIT2/UNSUPP/MATEXP/rexp.f", "max_forks_repo_name": "xywei/Mirana", "max_forks_repo_head_hexsha": "81d0ed67fad20cd3be8880ed672c12feff3c22c9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-03-13T17:09:10.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-22T00:30:19.000Z", "avg_line_length": 27.5656565657, "max_line_length": 72, "alphanum_fraction": 0.4932209601, "num_tokens": 893, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424295406088, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.666544425740331}} {"text": " program circle\n real PI, a, r\n parameter (PI = 3.141592)\n\n* This program reads a real number r and prints\n* the area of a circle with radius r\n\n\n write(*,*) \"Enter the radius of your circle \"\n read(*,*) r\n a = r * r * PI\n write(*,100) \"Area = \", a\n 100 format(A,E8.3)\n stop\n end\n", "meta": {"hexsha": "48e0865fad865d2d3f049590a9bf844211256ca0", "size": 334, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "circle.f", "max_stars_repo_name": "JONGHOKim-Raphael/fff", "max_stars_repo_head_hexsha": "bd0c3df4e7a5bcf072b5a28cb7ed46052b2dddd1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "circle.f", "max_issues_repo_name": "JONGHOKim-Raphael/fff", "max_issues_repo_head_hexsha": "bd0c3df4e7a5bcf072b5a28cb7ed46052b2dddd1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "circle.f", "max_forks_repo_name": "JONGHOKim-Raphael/fff", "max_forks_repo_head_hexsha": "bd0c3df4e7a5bcf072b5a28cb7ed46052b2dddd1", "max_forks_repo_licenses": ["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.875, "max_line_length": 51, "alphanum_fraction": 0.5299401198, "num_tokens": 103, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6665329815023905}} {"text": "!\n! file thstssp.f90\n!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 2005 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Fishpack *\n! * *\n! * A Package of Fortran *\n! * *\n! * Subroutines and Example Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams, Paul Swarztrauber and Roland Sweet *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\nprogram test_hstssp\n\n use, intrinsic :: ISO_Fortran_env, only: &\n stdout => OUTPUT_UNIT\n\n use fishpack\n\n ! Explicit typing only\n implicit none\n\n !-----------------------------------------------\n ! Local variables\n !-----------------------------------------------\n integer(ip), parameter :: M = 18\n integer(ip), parameter :: N = 72\n integer(ip), parameter :: IDIMF = M\n integer(ip) :: mbdcnd, nbdcnd, i, j, ierror\n real(wp) :: f(IDIMF,N), sint(M)\n real(wp), dimension(1) :: bda, bdc, bdd\n real(wp), dimension(N) :: sinp, bdb\n real(wp) :: a, b, c, d, elmbda, dtheta, dphi\n real(wp) :: pertrb\n real(wp), parameter :: ZERO = 0.0_wp, HALF = 0.5_wp\n real(wp), parameter :: TWO = 2.0_wp\n !-----------------------------------------------\n\n ! Set domain\n a = ZERO\n b = HALF_PI\n c = ZERO\n d = TWO_PI\n\n ! Set boundary conditions\n nbdcnd = 0\n mbdcnd = 6\n\n ! Set helmholtz constant\n elmbda = ZERO\n\n ! Set mesh sizes\n dtheta = (b - a)/M\n dphi = (d - c)/N\n\n ! Generate sines for use in subsequent computations\n do i = 1, M\n sint(i) = sin((real(i, kind=wp) - HALF) * dtheta)\n end do\n\n do j = 1, N\n sinp(j) = sin((real(j, kind=wp) - HALF) * dphi)\n end do\n\n ! Compute right hand side of equation and store in f\n block\n real(wp), parameter :: SIX = 6.0_wp\n do j = 1, N\n f(:, j) = TWO - SIX * (sint * sinp(j))**2\n end do\n end block\n !\n ! Set boundary data; store derivative data at the equator\n ! In our example, bda, bdc, and bdd are 1-dimensional dummy variables.\n bdb = ZERO\n\n ! Solve 2D Helmholtz in spherical coordinates on staggered grid\n call hstssp(a, b, M, mbdcnd, bda, bdb, c, d, N, nbdcnd, bdc, bdd, &\n elmbda, f, IDIMF, pertrb, ierror)\n\n ! Compute discretization error. since problem is singular, the\n ! solution must be normalized.\n block\n real(wp), parameter :: KNOWN_PERTRB = 0.635830001454109e-3_wp\n real(wp), parameter :: KNOWN_ERROR = 0.337523232257420e-2_wp\n real(wp) :: discretization_error\n real(wp) :: exact_solution(M,N)\n\n do j = 1, N\n do i = 1, M\n exact_solution(i,j) = (sint(i) * sinp(j))**2 + f(1, 1)\n end do\n end do\n\n ! Set discretization error\n discretization_error = maxval(abs(exact_solution - f(:M,:N)))\n\n call check_output('hstssp', &\n ierror, KNOWN_ERROR, discretization_error, KNOWN_PERTRB, pertrb)\n end block\n\nend program test_hstssp\n", "meta": {"hexsha": "b593bba67c4879a1d8b8f26a9fc30ee4a6c9f3f0", "size": 4912, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/thstssp.f90", "max_stars_repo_name": "jlokimlin/fishpack", "max_stars_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2018-03-12T11:31:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-27T07:58:23.000Z", "max_issues_repo_path": "examples/thstssp.f90", "max_issues_repo_name": "jlokimlin/fishpack", "max_issues_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2016-05-07T22:42:47.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-15T17:44:58.000Z", "max_forks_repo_path": "examples/thstssp.f90", "max_forks_repo_name": "jlokimlin/fishpack", "max_forks_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-09-07T15:43:32.000Z", "max_forks_repo_forks_event_max_datetime": "2018-06-16T21:30:13.000Z", "avg_line_length": 38.9841269841, "max_line_length": 76, "alphanum_fraction": 0.3515879479, "num_tokens": 1124, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093975331751, "lm_q2_score": 0.746138993030751, "lm_q1q2_score": 0.6665329743403101}} {"text": "program contacto\r\n\timplicit double\tprecision (a,h,l,m,o-z)\r\n\r\n\tparameter (phi=0.2d+00,per=9e-12)\r\n\tparameter (cr=1.0e-10,cf=1.0e-7)\r\n\tparameter (po=1000.0d+00,h=1.0d+00)\r\n\tparameter (nx=5,ny=5,nimax=1000,njmax=1000)\r\n\r\n\r\n\tcall mesh(l,h,nx,ny,nimax,njmax)\r\n\topen (unit=10,file=\"prueba.txt\",status=\"replace\",action=\"write\")\r\n\twrite(unit=10)\r\n!c\twrite(*,*)\"phi=\",phi\r\nwrite(*,*)\"phi=\",phi\r\n!c\twrite(*,*)\"per=\",per\r\nwrite(*,*)\"per=\",per\r\n!c\twrite(*,*)\"cr=\",cr\r\nwrite(*,*)\"cr=\",cr\r\n!c\twrite(*,*)\"po=\",po\r\nwrite(*,*)\"po=\",po\r\n\r\nclose (unit=10)\r\n\tend\r\n!c !comienza area de subroutines!\r\n\r\n\tsubroutine mesh(l,h,nx,ny,nimax,njmax)\r\n\timplicit double precision (a,h,l,m,o-z)\r\n\tdimension x(nimax),y(njmax)\r\n\r\n \tx(1)=0.0d+00\r\n\tx(nx)=l\r\n\tdx=l/dfloat(nx)\r\n\r\n\r\n\tdo 1 i=2,nx\r\n\tx(i)=x(i)+dx\r\n 1\tcontinue\r\n\r\n y(1)=0.0d+00\r\n\ty(ny)=h\r\n\tdy=h/dfloat(ny)\r\n\r\n\tdo 2 j=2,ny\r\n\ty(j)=y(j)+dy\r\n 2\tcontinue\r\n do i=1,nx\r\n\twrite (*,*)\"x\",i,\"=\",x(i)\r\n\tend do\r\n\r\n\tdo j=1,ny\r\n\twrite (*,*)\"y\",j,\"=\",y(j)\r\n\tend do\r\n\r\nreturn\r\nend\r\n", "meta": {"hexsha": "19c360beb35fdb80fdadc50c3d8301ddb4d9e749", "size": 1004, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "contacto.f95", "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": "contacto.f95", "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": "contacto.f95", "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": 17.9285714286, "max_line_length": 66, "alphanum_fraction": 0.5687250996, "num_tokens": 411, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093946927838, "lm_q2_score": 0.7461389873857265, "lm_q1q2_score": 0.66653296717823}} {"text": "C FACTOR.F 1 \nC COPYRIGHT (C) 2020 HUGH COLEMAN 2 \nC 3 \nC THIS FILE IS PART OF HUGHCOLEMAN/FORTRAN, AN ATTEMPT TO 4 \nC INVESTIGATE THE FORTRAN PROGRAMMING LANGUAGE AND LEARN ABOUT THE 5 \nC EARLY DAYS OF COMPUTING. IT IS RELEASED UNDER THE MIT LICENSE (SEE6 \nC LICENSE.) 7 \n 8 \nC THIS IMPLEMENTS A BASIC ITERATIVE ALGORITHM TO FIND THE PRIME 9 \nC FACTORS OF A GIVEN INTEGER N. 10 \n 11 \n 10 FORMAT ( 1I5 ) 12 \n 11 FORMAT ( 24H PRIME FACTORIZATION OF 1I5 ) 13 \n 12 FORMAT ( 1H 1I5 ) 14 \n 15 \nC GET THE QUERIED INTEGER FROM STANDARD INPUT, IF IT IS ONE OR LESS 16 \nC EXIT THE PROGRAM. 17 \n 20 READ 10, N 18 \n IF (N - 1) 9999, 9999, 21 19 \n 21 PRINT 11, N 20 \n 21 \nC DIVIDE OUT AS MANY FACTORS OF TWO AS POSSIBLE 22 \n IFAC = 2 23 \n 30 IF (XMODF(N, IFAC)) 9999, 31, 40 24 \n 31 N = N / 2 25 \n PRINT 12, IFAC 26 \n GOTO 30 27 \n 28 \nC DIVIDE OUT ODD INTEGERS FROM 3 TO SQRT(N). 29 \n 40 DO 50 IFAC = 3, 32767, 2 30 \nC CHECK IF IFAC SQUARED EXCEEDS N 31 \n IF (IFAC**2 - N) 41, 41, 60 32 \n 41 IF (XMODF(N, IFAC)) 9999, 42, 50 33 \n 42 N = N / IFAC 34 \n PRINT 12, IFAC 35 \n GOTO 41 36 \n 50 CONTINUE 37 \n 38 \nC IF N IS STILL GREATER THAN ONE, THEN N IS ALSO A PRIME FACTOR. 39 \n 60 IF (N-1) 70, 70, 61 40 \n 61 PRINT 12, N 41 \n 42 \n 70 GOTO 20 43 \n 44 \n 9999 STOP 45 \n", "meta": {"hexsha": "bd5857483e8c0bf598720f51c940880f0f89e62a", "size": 3645, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/factor/prog.f", "max_stars_repo_name": "hughcoleman/retrocomputing", "max_stars_repo_head_hexsha": "9742bdf5bb93b2972848192ff1c4ee1f35ae4e26", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/factor/prog.f", "max_issues_repo_name": "hughcoleman/retrocomputing", "max_issues_repo_head_hexsha": "9742bdf5bb93b2972848192ff1c4ee1f35ae4e26", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/factor/prog.f", "max_forks_repo_name": "hughcoleman/retrocomputing", "max_forks_repo_head_hexsha": "9742bdf5bb93b2972848192ff1c4ee1f35ae4e26", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 79.2391304348, "max_line_length": 80, "alphanum_fraction": 0.2299039781, "num_tokens": 619, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744584140003, "lm_q2_score": 0.8152324983301568, "lm_q1q2_score": 0.6665132683037703}} {"text": "subroutine UpdateCVM(OldCVM, Oldmean, n, par, newmean, NewCVM)\nUse Interface_MOD, only: NPar, PriorCVM\nimplicit none\nreal, intent(in) :: OldCVM(NPar*(NPar+1)/2)\nreal, intent(in) :: Oldmean(NPar)\nreal, intent(in) :: n !current step as a weight\nreal, intent(in) :: par(NPar)\nreal, intent(out) :: newmean(NPar)\nreal, intent(out) :: NewCVM(NPar*(NPar+1)/2)\n\ninteger :: row,col\n\nIF (n .GE. 2d0) THEN\n ! Update the mean params\n \n newmean = ((n-1d0)*Oldmean + par)/n\n \n ! Update the correlation covariance matrix (but not Pcvm): \n do row = 1, NPar\n do col = 1, row \n NewCVM(row*(row-1)/2 +col) = & \n ((n-1d0)/n)*OldCvm(row*(row-1)/2 +col) &\n + (1d0/(n-1d0)) &\n * (par(row)-newmean(row)) &\n * (par(col)-newmean(col))\n enddo\n enddo\nELSE\n newmean = par\n NewCVM(:) = PriorCvm(:)\nENDIF\nEnd subroutine\n\n", "meta": {"hexsha": "3c4b97adc6794585446cf5fa353f1b0877a01c57", "size": 956, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "DRAM/NPZDFix_sRun/S1_g1/Compile/UpdateCVM.f90", "max_stars_repo_name": "BingzhangChen/NPZDFeCONT", "max_stars_repo_head_hexsha": "0083d46dadc4fb8fed8728816755678da8294e16", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "DRAM/NPZDFix_sRun/S1_g1/Compile/UpdateCVM.f90", "max_issues_repo_name": "BingzhangChen/NPZDFeCONT", "max_issues_repo_head_hexsha": "0083d46dadc4fb8fed8728816755678da8294e16", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "DRAM/NPZDFix_sRun/S1_g1/Compile/UpdateCVM.f90", "max_forks_repo_name": "BingzhangChen/NPZDFeCONT", "max_forks_repo_head_hexsha": "0083d46dadc4fb8fed8728816755678da8294e16", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.1176470588, "max_line_length": 65, "alphanum_fraction": 0.5376569038, "num_tokens": 322, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133531922389, "lm_q2_score": 0.7090191399336402, "lm_q1q2_score": 0.666416557292505}} {"text": " SUBROUTINE MB02QD( JOB, INIPER, M, N, NRHS, RCOND, SVLMAX, A, LDA,\n $ B, LDB, Y, JPVT, RANK, SVAL, DWORK, LDWORK,\n $ INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute a solution, optionally corresponding to specified free\nC elements, to a real linear least squares problem:\nC\nC minimize || A * X - B ||\nC\nC using a complete orthogonal factorization of the M-by-N matrix A,\nC which may be rank-deficient.\nC\nC Several right hand side vectors b and solution vectors x can be\nC handled in a single call; they are stored as the columns of the\nC M-by-NRHS right hand side matrix B and the N-by-NRHS solution\nC matrix X.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC JOB CHARACTER*1\nC Specifies whether or not a standard least squares solution\nC must be computed, as follows:\nC = 'L': Compute a standard least squares solution (Y = 0);\nC = 'F': Compute a solution with specified free elements\nC (given in Y).\nC\nC INIPER CHARACTER*1\nC Specifies whether an initial column permutation, defined\nC by JPVT, must be performed, as follows:\nC = 'P': Perform an initial column permutation;\nC = 'N': Do not perform an initial column permutation.\nC\nC Input/Output Parameters\nC\nC M (input) INTEGER\nC The number of rows of the matrix A. M >= 0.\nC\nC N (input) INTEGER\nC The number of columns of the matrix A. N >= 0.\nC\nC NRHS (input) INTEGER\nC The number of right hand sides, i.e., the number of\nC columns of the matrices B and X. NRHS >= 0.\nC\nC RCOND (input) DOUBLE PRECISION\nC RCOND is used to determine the effective rank of A, which\nC is defined as the order of the largest leading triangular\nC submatrix R11 in the QR factorization with pivoting of A,\nC whose estimated condition number is less than 1/RCOND.\nC 0 <= RCOND <= 1.\nC\nC SVLMAX (input) DOUBLE PRECISION\nC If A is a submatrix of another matrix C, and the rank\nC decision should be related to that matrix, then SVLMAX\nC should be an estimate of the largest singular value of C\nC (for instance, the Frobenius norm of C). If this is not\nC the case, the input value SVLMAX = 0 should work.\nC SVLMAX >= 0.\nC\nC A (input/output) DOUBLE PRECISION array, dimension (LDA,N)\nC On entry, the leading M-by-N part of this array must\nC contain the given matrix A.\nC On exit, the leading M-by-N part of this array contains\nC details of its complete orthogonal factorization:\nC the leading RANK-by-RANK upper triangular part contains\nC the upper triangular factor T11 (see METHOD);\nC the elements below the diagonal, with the entries 2 to\nC min(M,N)+1 of the array DWORK, represent the orthogonal\nC matrix Q as a product of min(M,N) elementary reflectors\nC (see METHOD);\nC the elements of the subarray A(1:RANK,RANK+1:N), with the\nC next RANK entries of the array DWORK, represent the\nC orthogonal matrix Z as a product of RANK elementary\nC reflectors (see METHOD).\nC\nC LDA INTEGER\nC The leading dimension of the array A. LDA >= max(1,M).\nC\nC B (input/output) DOUBLE PRECISION array, dimension\nC (LDB,NRHS)\nC On entry, the leading M-by-NRHS part of this array must\nC contain the right hand side matrix B.\nC On exit, the leading N-by-NRHS part of this array contains\nC the solution matrix X.\nC If M >= N and RANK = N, the residual sum-of-squares for\nC the solution in the i-th column is given by the sum of\nC squares of elements N+1:M in that column.\nC If NRHS = 0, this array is not referenced, and the routine\nC returns the effective rank of A, and its QR factorization.\nC\nC LDB INTEGER\nC The leading dimension of the array B. LDB >= max(1,M,N).\nC\nC Y (input) DOUBLE PRECISION array, dimension ( N*NRHS )\nC If JOB = 'F', the elements Y(1:(N-RANK)*NRHS) are used as\nC free elements in computing the solution (see METHOD).\nC The remaining elements are not referenced.\nC If JOB = 'L', or NRHS = 0, this array is not referenced.\nC\nC JPVT (input/output) INTEGER array, dimension (N)\nC On entry with INIPER = 'P', if JPVT(i) <> 0, the i-th\nC column of A is an initial column, otherwise it is a free\nC column. Before the QR factorization of A, all initial\nC columns are permuted to the leading positions; only the\nC remaining free columns are moved as a result of column\nC pivoting during the factorization.\nC If INIPER = 'N', JPVT need not be set on entry.\nC On exit, if JPVT(i) = k, then the i-th column of A*P\nC was the k-th column of A.\nC\nC RANK (output) INTEGER\nC The effective rank of A, i.e., the order of the submatrix\nC R11. This is the same as the order of the submatrix T11\nC in the complete orthogonal factorization of A.\nC\nC SVAL (output) DOUBLE PRECISION array, dimension ( 3 )\nC The estimates of some of the singular values of the\nC triangular factor R11:\nC SVAL(1): largest singular value of R(1:RANK,1:RANK);\nC SVAL(2): smallest singular value of R(1:RANK,1:RANK);\nC SVAL(3): smallest singular value of R(1:RANK+1,1:RANK+1),\nC if RANK < MIN( M, N ), or of R(1:RANK,1:RANK),\nC otherwise.\nC If the triangular factorization is a rank-revealing one\nC (which will be the case if the leading columns were well-\nC conditioned), then SVAL(1) will also be an estimate for\nC the largest singular value of A, and SVAL(2) and SVAL(3)\nC will be estimates for the RANK-th and (RANK+1)-st singular\nC values of A, respectively.\nC By examining these values, one can confirm that the rank\nC is well defined with respect to the chosen value of RCOND.\nC The ratio SVAL(1)/SVAL(2) is an estimate of the condition\nC number of R(1:RANK,1:RANK).\nC\nC Workspace\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0, DWORK(1) returns the optimal value\nC of LDWORK, and the entries 2 to min(M,N) + RANK + 1\nC contain the scalar factors of the elementary reflectors\nC used in the complete orthogonal factorization of A.\nC Among the entries 2 to min(M,N) + 1, only the first RANK\nC elements are useful, if INIPER = 'N'.\nC\nC LDWORK INTEGER\nC The length of the array DWORK.\nC LDWORK >= max( min(M,N)+3*N+1, 2*min(M,N)+NRHS )\nC For optimum performance LDWORK should be larger.\nC\nC Error indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value.\nC\nC METHOD\nC\nC If INIPER = 'P', the routine first computes a QR factorization\nC with column pivoting:\nC A * P = Q * [ R11 R12 ]\nC [ 0 R22 ]\nC with R11 defined as the largest leading submatrix whose estimated\nC condition number is less than 1/RCOND. The order of R11, RANK,\nC is the effective rank of A.\nC If INIPER = 'N', the effective rank is estimated during a\nC truncated QR factorization (with column pivoting) process, and\nC the submatrix R22 is not upper triangular, but full and of small\nC norm. (See SLICOT Library routines MB03OD or MB03OY, respectively,\nC for further details.)\nC\nC Then, R22 is considered to be negligible, and R12 is annihilated\nC by orthogonal transformations from the right, arriving at the\nC complete orthogonal factorization:\nC A * P = Q * [ T11 0 ] * Z\nC [ 0 0 ]\nC The solution is then\nC X = P * Z' [ inv(T11)*Q1'*B ]\nC [ Y ]\nC where Q1 consists of the first RANK columns of Q, and Y contains\nC free elements (if JOB = 'F'), or is zero (if JOB = 'L').\nC\nC NUMERICAL ASPECTS\nC\nC The algorithm is backward stable.\nC\nC FURTHER COMMENTS\nC\nC Significant gain in efficiency is possible for small-rank problems\nC using truncated QR factorization (option INIPER = 'N').\nC\nC CONTRIBUTORS\nC\nC P.Hr. Petkov, Technical University of Sofia, Oct. 1998,\nC modification of the LAPACK routine DGELSX.\nC V. Sima, Katholieke Universiteit Leuven, Jan. 1999, SLICOT Library\nC version.\nC\nC REVISIONS\nC\nC V. Sima, Research Institute for Informatics, Bucharest, Mar. 2005.\nC\nC KEYWORDS\nC\nC Least squares problems, QR factorization.\nC\nC ******************************************************************\nC\n DOUBLE PRECISION ZERO, ONE, DONE, NTDONE\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0, DONE = ZERO,\n $ NTDONE = ONE )\nC ..\nC .. Scalar Arguments ..\n CHARACTER INIPER, JOB\n INTEGER INFO, LDA, LDB, LDWORK, M, N, NRHS, RANK\n DOUBLE PRECISION RCOND, SVLMAX\nC ..\nC .. Array Arguments ..\n INTEGER JPVT( * )\n DOUBLE PRECISION A( LDA, * ), B( LDB, * ), DWORK( * ),\n $ SVAL( 3 ), Y ( * )\nC ..\nC .. Local Scalars ..\n LOGICAL LEASTS, PERMUT\n INTEGER I, IASCL, IBSCL, J, K, MAXWRK, MINWRK, MN\n DOUBLE PRECISION ANRM, BIGNUM, BNRM, SMLNUM, T1, T2\nC ..\nC .. External Functions ..\n LOGICAL LSAME\n DOUBLE PRECISION DLAMCH, DLANGE\n EXTERNAL DLAMCH, DLANGE, LSAME\nC ..\nC .. External Subroutines ..\n EXTERNAL DLABAD, DLACPY, DLASCL, DLASET, DORMQR, DORMRZ,\n $ DTRSM, DTZRZF, MB03OD, MB03OY, XERBLA\nC ..\nC .. Intrinsic Functions ..\n INTRINSIC INT, MAX, MIN\nC ..\nC .. Executable Statements ..\nC\n MN = MIN( M, N )\n LEASTS = LSAME( JOB, 'L' )\n PERMUT = LSAME( INIPER, 'P' )\nC\nC Test the input scalar arguments.\nC\n INFO = 0\n MINWRK = MAX( MN + 3*N + 1, 2*MN + NRHS )\n IF( .NOT. ( LEASTS .OR. LSAME( JOB, 'F' ) ) ) THEN\n INFO = -1\n ELSE IF( .NOT. ( PERMUT .OR. LSAME( INIPER, 'N' ) ) ) THEN\n INFO = -2\n ELSE IF( M.LT.0 ) THEN\n INFO = -3\n ELSE IF( N.LT.0 ) THEN\n INFO = -4\n ELSE IF( NRHS.LT.0 ) THEN\n INFO = -5\n ELSE IF( RCOND.LT.ZERO .OR. RCOND.GT.ONE ) THEN\n INFO = -6\n ELSE IF( SVLMAX.LT.ZERO ) THEN\n INFO = -7\n ELSE IF( LDA.LT.MAX( 1, M ) ) THEN\n INFO = -9\n ELSE IF( LDB.LT.MAX( 1, M, N ) ) THEN\n INFO = -11\n ELSE IF( LDWORK.LT.MINWRK ) THEN\n INFO = -17\n END IF\nC\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'MB02QD', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF( MN.EQ.0 ) THEN\n RANK = 0\n DWORK( 1 ) = ONE\n RETURN\n END IF\nC\nC Get machine parameters.\nC\n SMLNUM = DLAMCH( 'Safe minimum' ) / DLAMCH( 'Precision' )\n BIGNUM = ONE / SMLNUM\n CALL DLABAD( SMLNUM, BIGNUM )\nC\nC Scale A, B if max entries outside range [SMLNUM,BIGNUM].\nC\n ANRM = DLANGE( 'M', M, N, A, LDA, DWORK )\n IASCL = 0\n IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN\nC\nC Scale matrix norm up to SMLNUM.\nC\n CALL DLASCL( 'G', 0, 0, ANRM, SMLNUM, M, N, A, LDA, INFO )\n IASCL = 1\n ELSE IF( ANRM.GT.BIGNUM ) THEN\nC\nC Scale matrix norm down to BIGNUM.\nC\n CALL DLASCL( 'G', 0, 0, ANRM, BIGNUM, M, N, A, LDA, INFO )\n IASCL = 2\n ELSE IF( ANRM.EQ.ZERO ) THEN\nC\nC Matrix all zero. Return zero solution.\nC\n IF( NRHS.GT.0 )\n $ CALL DLASET( 'Full', MAX( M, N ), NRHS, ZERO, ZERO, B, LDB )\n RANK = 0\n DWORK( 1 ) = ONE\n RETURN\n END IF\nC\n IF( NRHS.GT.0 ) THEN\n BNRM = DLANGE( 'M', M, NRHS, B, LDB, DWORK )\n IBSCL = 0\n IF( BNRM.GT.ZERO .AND. BNRM.LT.SMLNUM ) THEN\nC\nC Scale matrix norm up to SMLNUM.\nC\n CALL DLASCL( 'G', 0, 0, BNRM, SMLNUM, M, NRHS, B, LDB,\n $ INFO )\n IBSCL = 1\n ELSE IF( BNRM.GT.BIGNUM ) THEN\nC\nC Scale matrix norm down to BIGNUM.\nC\n CALL DLASCL( 'G', 0, 0, BNRM, BIGNUM, M, NRHS, B, LDB,\n $ INFO )\n IBSCL = 2\n END IF\n END IF\nC\nC Compute a rank-revealing QR factorization of A and estimate its\nC effective rank using incremental condition estimation:\nC A * P = Q * R.\nC Workspace need min(M,N)+3*N+1;\nC prefer min(M,N)+2*N+N*NB.\nC Details of Householder transformations stored in DWORK(1:MN).\nC (Note: Comments in the code beginning \"Workspace:\" describe the\nC minimal amount of workspace needed at that point in the code,\nC as well as the preferred amount for good performance.\nC NB refers to the optimal block size for the immediately\nC following subroutine, as returned by ILAENV.)\nC\n MAXWRK = MINWRK\n IF( PERMUT ) THEN\n CALL MB03OD( 'Q', M, N, A, LDA, JPVT, RCOND, SVLMAX,\n $ DWORK( 1 ), RANK, SVAL, DWORK( MN+1 ), LDWORK-MN,\n $ INFO )\n MAXWRK = MAX( MAXWRK, INT( DWORK( MN+1 ) ) + MN )\n ELSE\n CALL MB03OY( M, N, A, LDA, RCOND, SVLMAX, RANK, SVAL, JPVT,\n $ DWORK( 1 ), DWORK( MN+1 ), INFO )\n END IF\nC\nC Logically partition R = [ R11 R12 ]\nC [ 0 R22 ],\nC where R11 = R(1:RANK,1:RANK).\nC\nC [R11,R12] = [ T11, 0 ] * Z.\nC\nC Details of Householder transformations stored in DWORK(MN+1:2*MN).\nC Workspace need 3*min(M,N);\nC prefer 2*min(M,N)+min(M,N)*NB.\nC\n IF( RANK.LT.N ) THEN\n CALL DTZRZF( RANK, N, A, LDA, DWORK( MN+1 ), DWORK( 2*MN+1 ),\n $ LDWORK-2*MN, INFO )\n MAXWRK = MAX( MAXWRK, INT( DWORK( 2*MN+1 ) ) + 2*MN )\n END IF\nC\n IF( NRHS.GT.0 ) THEN\nC\nC B(1:M,1:NRHS) := Q' * B(1:M,1:NRHS).\nC\nC Workspace: need 2*min(M,N)+NRHS;\nC prefer min(M,N)+NRHS*NB.\nC\n CALL DORMQR( 'Left', 'Transpose', M, NRHS, MN, A, LDA,\n $ DWORK( 1 ), B, LDB, DWORK( 2*MN+1 ), LDWORK-2*MN,\n $ INFO )\n MAXWRK = MAX( MAXWRK, INT( DWORK( 2*MN+1 ) ) + 2*MN )\nC\nC B(1:RANK,1:NRHS) := inv(T11) * B(1:RANK,1:NRHS).\nC\n CALL DTRSM( 'Left', 'Upper', 'No transpose', 'Non-unit', RANK,\n $ NRHS, ONE, A, LDA, B, LDB )\nC\n IF( RANK.LT.N ) THEN\nC\nC Set B(RANK+1:N,1:NRHS).\nC\n IF( LEASTS ) THEN\n CALL DLASET( 'Full', N-RANK, NRHS, ZERO, ZERO,\n $ B(RANK+1,1), LDB )\n ELSE\n CALL DLACPY( 'Full', N-RANK, NRHS, Y, N-RANK,\n $ B(RANK+1,1), LDB )\n END IF\nC\nC B(1:N,1:NRHS) := Z' * B(1:N,1:NRHS).\nC\nC Workspace need 2*min(M,N)+NRHS;\nC prefer 2*min(M,N)+NRHS*NB.\nC\n CALL DORMRZ( 'Left', 'Transpose', N, NRHS, RANK, N-RANK, A,\n $ LDA, DWORK( MN+1 ), B, LDB, DWORK( 2*MN+1 ),\n $ LDWORK-2*MN, INFO )\n MAXWRK = MAX( MAXWRK, INT( DWORK( 2*MN+1 ) ) + 2*MN )\n END IF\nC\nC Additional workspace: NRHS.\nC\nC B(1:N,1:NRHS) := P * B(1:N,1:NRHS).\nC\n DO 50 J = 1, NRHS\n DO 20 I = 1, N\n DWORK( 2*MN+I ) = NTDONE\n 20 CONTINUE\n DO 40 I = 1, N\n IF( DWORK( 2*MN+I ).EQ.NTDONE ) THEN\n IF( JPVT( I ).NE.I ) THEN\n K = I\n T1 = B( K, J )\n T2 = B( JPVT( K ), J )\n 30 CONTINUE\n B( JPVT( K ), J ) = T1\n DWORK( 2*MN+K ) = DONE\n T1 = T2\n K = JPVT( K )\n T2 = B( JPVT( K ), J )\n IF( JPVT( K ).NE.I )\n $ GO TO 30\n B( I, J ) = T1\n DWORK( 2*MN+K ) = DONE\n END IF\n END IF\n 40 CONTINUE\n 50 CONTINUE\nC\nC Undo scaling for B.\nC\n IF( IBSCL.EQ.1 ) THEN\n CALL DLASCL( 'G', 0, 0, SMLNUM, BNRM, N, NRHS, B, LDB,\n $ INFO )\n ELSE IF( IBSCL.EQ.2 ) THEN\n CALL DLASCL( 'G', 0, 0, BIGNUM, BNRM, N, NRHS, B, LDB,\n $ INFO )\n END IF\n END IF\nC\nC Undo scaling for A.\nC\n IF( IASCL.EQ.1 ) THEN\n IF( NRHS.GT.0 )\n $ CALL DLASCL( 'G', 0, 0, ANRM, SMLNUM, N, NRHS, B, LDB,\n $ INFO )\n CALL DLASCL( 'U', 0, 0, SMLNUM, ANRM, RANK, RANK, A, LDA,\n $ INFO )\n ELSE IF( IASCL.EQ.2 ) THEN\n IF( NRHS.GT.0 )\n $ CALL DLASCL( 'G', 0, 0, ANRM, BIGNUM, N, NRHS, B, LDB,\n $ INFO )\n CALL DLASCL( 'U', 0, 0, BIGNUM, ANRM, RANK, RANK, A, LDA,\n $ INFO )\n END IF\nC\n DO 60 I = MN + RANK, 1, -1\n DWORK( I+1 ) = DWORK( I )\n 60 CONTINUE\nC\n DWORK( 1 ) = MAXWRK\n RETURN\nC *** Last line of MB02QD ***\n END\n", "meta": {"hexsha": "384e74b1ba679de025ae0c5388a824cf46f9faff", "size": 17939, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB02QD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB02QD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB02QD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 36.6850715746, "max_line_length": 72, "alphanum_fraction": 0.5341434863, "num_tokens": 5539, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133531922387, "lm_q2_score": 0.7090191399336401, "lm_q1q2_score": 0.6664165572925047}} {"text": "! cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\n! M. Behr [AHPCRC] c\n! cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\nsubroutine get_hg(x, hg)\n use fluid_variables\n implicit none\n\n real(8) :: x(nsd,nen)\n real(8) :: hg\n\n if((etype.eq.tet).or.(etype.eq.tets))then\n hg = max(sqrt((x(1,2)-x(1,1))**2 &\n +(x(2,2)-x(2,1))**2 &\n +(x(3,2)-x(3,1))**2 &\n ), sqrt((x(1,3)-x(1,2))**2 &\n +(x(2,3)-x(2,2))**2 &\n +(x(3,3)-x(3,2))**2 &\n ), sqrt((x(1,1)-x(1,3))**2 &\n +(x(2,1)-x(2,3))**2 &\n +(x(3,1)-x(3,3))**2 &\n ), sqrt((x(1,4)-x(1,1))**2 &\n +(x(2,4)-x(2,1))**2 &\n +(x(3,4)-x(3,1))**2 &\n ), sqrt((x(1,4)-x(1,2))**2 &\n +(x(2,4)-x(2,2))**2 &\n +(x(3,4)-x(3,2))**2 &\n ), sqrt((x(1,4)-x(1,3))**2 &\n +(x(2,4)-x(2,3))**2 &\n +(x(3,4)-x(3,3))**2))\n\n else if((etype.eq.hex).or.(etype.eq.hexs))then\n hg = 0.577350269 * max( &\n sqrt((x(1,7)-x(1,1))**2 &\n + (x(2,7)-x(2,1))**2 &\n + (x(3,7)-x(3,1))**2), &\n sqrt((x(1,5)-x(1,3))**2 &\n + (x(2,5)-x(2,3))**2 &\n + (x(3,5)-x(3,3))**2), &\n sqrt((x(1,8)-x(1,2))**2 &\n + (x(2,8)-x(2,2))**2 &\n + (x(3,8)-x(3,2))**2), &\n sqrt((x(1,6)-x(1,4))**2 &\n + (x(2,6)-x(2,4))**2 &\n + (x(3,6)-x(3,4))**2))\n else\n call error(\"get_hg: unsupported element type\", -999, .true.)\n end if\n\n return\nend\n", "meta": {"hexsha": "f263caa07d819bb2a43755d532ffe4da34a1d759", "size": 1738, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "hg.f90", "max_stars_repo_name": "biofluids/IFEM-archive", "max_stars_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-15T11:40:16.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-15T11:40:16.000Z", "max_issues_repo_path": "hg.f90", "max_issues_repo_name": "biofluids/IFEM-archive", "max_issues_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hg.f90", "max_forks_repo_name": "biofluids/IFEM-archive", "max_forks_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-02-11T16:50:21.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-08T07:24:59.000Z", "avg_line_length": 34.0784313725, "max_line_length": 76, "alphanum_fraction": 0.3532796318, "num_tokens": 721, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133531922388, "lm_q2_score": 0.7090191337850932, "lm_q1q2_score": 0.6664165515134035}} {"text": " DOUBLE PRECISION FUNCTION RZINTD(IP,IQ,R,Z,NGRIDS)\r\n DOUBLE PRECISION R(4),Z(4),PT(3),H(3)\r\n DOUBLE PRECISION XINT,RRP,ZZQ,DRDXI,DZDXI,DRDETA,DZDETA,DETJ\r\n DOUBLE PRECISION RR,ZZ\r\n IF(NGRIDS.EQ.3)GO TO 200\r\n NPT=3\r\n PT(1)=-.7745966692D0\r\n PT(2)=0.D0\r\n PT(3)=-PT(1)\r\n H(1)=5.D0/9.D0\r\n H(2)=8.D0/9.D0\r\n H(3)=H(1)\r\n XINT=0.D0\r\n DO 100 III=1,NPT\r\n DO 100 JJJ=1,NPT\r\n RR=.25D0*((1.D0-PT(III))*(1.D0-PT(JJJ))*R(1)\r\n 1 +(1.D0+PT(III))*(1.D0-PT(JJJ))*R(2)\r\n 1 +(1.D0+PT(III))*(1.D0+PT(JJJ))*R(3)\r\n 1 +(1.D0-PT(III))*(1.D0+PT(JJJ))*R(4))\r\n ZZ=.25D0*((1.D0-PT(III))*(1.D0-PT(JJJ))*Z(1)\r\n 1 +(1.D0+PT(III))*(1.D0-PT(JJJ))*Z(2)\r\n 1 +(1.D0+PT(III))*(1.D0+PT(JJJ))*Z(3)\r\n 1 +(1.D0-PT(III))*(1.D0+PT(JJJ))*Z(4))\r\n RRP=RR**IP\r\n ZZQ=ZZ**IQ\r\n DRDXI=.25D0*((1.D0-PT(JJJ))*(R(2)-R(1))+(1.D0+PT(JJJ))*(R(3)-R(4))\r\n 1)\r\n DZDXI=.25D0*((1.D0-PT(JJJ))*(Z(2)-Z(1))+(1.D0+PT(JJJ))*(Z(3)-Z(4))\r\n 1)\r\n DRDETA=.25D0*((1.D0-PT(III))*(R(4)-R(1))+(1.D0+PT(III))*(R(3)-R(2)\r\n 1))\r\n DZDETA=.25D0*((1.D0-PT(III))*(Z(4)-Z(1))+(1.D0+PT(III))*(Z(3)-Z(2)\r\n 1))\r\n DETJ=DRDXI*DZDETA-DZDXI*DRDETA\r\n DETJ=DABS(DETJ)\r\n XINT=XINT+RRP*ZZQ*H(III)*H(JJJ)*DETJ\r\n 100 CONTINUE\r\n RZINTD=XINT\r\n 200 RETURN\r\n END\r\n", "meta": {"hexsha": "219b9e5ff155ae9fc4ef436eb7b6c6b057eb9d8b", "size": 1391, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "mis/rzintd.f", "max_stars_repo_name": "ldallolio/NASTRAN-95", "max_stars_repo_head_hexsha": "6d2c175f5b53ebaec4ba2b5186f7926ef9d0ed47", "max_stars_repo_licenses": ["NASA-1.3"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2016-01-09T14:33:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-18T11:51:42.000Z", "max_issues_repo_path": "mis/rzintd.f", "max_issues_repo_name": "gassive/NASTRAN95", "max_issues_repo_head_hexsha": "98cb3acaa7990d639360601648498834c7782056", "max_issues_repo_licenses": ["NASA-1.3"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2016-01-17T07:30:19.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-06T19:37:44.000Z", "max_forks_repo_path": "mis/rzintd.f", "max_forks_repo_name": "gassive/NASTRAN95", "max_forks_repo_head_hexsha": "98cb3acaa7990d639360601648498834c7782056", "max_forks_repo_licenses": ["NASA-1.3"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-04-07T20:51:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T14:16:01.000Z", "avg_line_length": 33.9268292683, "max_line_length": 73, "alphanum_fraction": 0.4644140906, "num_tokens": 678, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133515091157, "lm_q2_score": 0.7090191276365462, "lm_q1q2_score": 0.6664165445409356}} {"text": "! RUN: bbc -emit-fir %s -o - | FileCheck %s\n\n! Tests REAL lowering\nsubroutine test_real()\n real(4) :: r4\n real(8) :: r8\n\n r4 = real(z'40', kind=4)\n r8 = real(z'40', kind=8)\n\nend subroutine\n\n! CHECK-LABEL: func @_QPtest_real() {\n! CHECK: %[[VAL_0:.*]] = fir.alloca f32 {bindc_name = \"r4\", uniq_name = \"_QFtest_realEr4\"}\n! CHECK: %[[VAL_1:.*]] = fir.alloca f64 {bindc_name = \"r8\", uniq_name = \"_QFtest_realEr8\"}\n! CHECK: %[[CST_0:.*]] = arith.constant 8.968310e-44 : f32\n! CHECK: fir.store %[[CST_0]] to %[[VAL_0]] : !fir.ref\n! CHECK: %[[CST_1:.*]] = arith.constant 3.162020e-322 : f64\n! CHECK: fir.store %[[CST_1]] to %[[VAL_1]] : !fir.ref\n! CHECK: return\n", "meta": {"hexsha": "7b9fab8a87712782ec44108220b0eea0c5d9dd1d", "size": 676, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "flang/test/Lower/Intrinsics/real.f90", "max_stars_repo_name": "ornata/llvm-project", "max_stars_repo_head_hexsha": "494913b8b4e4bce0b3525e5569d8e486e82b9a52", "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": "flang/test/Lower/Intrinsics/real.f90", "max_issues_repo_name": "ornata/llvm-project", "max_issues_repo_head_hexsha": "494913b8b4e4bce0b3525e5569d8e486e82b9a52", "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": "flang/test/Lower/Intrinsics/real.f90", "max_forks_repo_name": "ornata/llvm-project", "max_forks_repo_head_hexsha": "494913b8b4e4bce0b3525e5569d8e486e82b9a52", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.1904761905, "max_line_length": 91, "alphanum_fraction": 0.6065088757, "num_tokens": 284, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916205190225, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6664032129176203}} {"text": " real*8 function fctrl(i)\nc\nc This subroutine returns the factorial function. The factorials\nc from 0! to 10! are programmed into a data statement.\nc\nc This subroutine is called by:\nc\nc Any\nc\nc-----------------------------------------------------------------------\nc\nc Input:\nc\nc i = argument\nc\nc Output:\nc\nc fctrl = factorial\nc\nc-----------------------------------------------------------------------\nc\n implicit none\nc\nc-----------------------------------------------------------------------\nc\nc Calling sequence variable declarations.\nc\n integer i\nc\nc-----------------------------------------------------------------------\nc\nc Local variable declarations.\nc\n integer ifac(0:10),ifactr,j\nc\nc-----------------------------------------------------------------------\nc\nc Set low factorials.\nc\n data (ifac(j), j = 0,10) /1,1,2,6,24,120,720,5040,40320,\n $ 362880,3628800/\nc\nc-----------------------------------------------------------------------\nc\n if ( i.ge.0 .and. i.le.10) then\n fctrl = ifac(i)\n elseif (i.gt.10) then\n ifactr = ifac(10)\n do j = 10 + 1,i\n ifactr = ifactr*j\n enddo\n fctrl = ifactr\n endif\nc\n end\n", "meta": {"hexsha": "91f4e436e1e44cfa5f7e8b717934a292bf04ba44", "size": 1257, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/eqlibu/src/fctrl.f", "max_stars_repo_name": "39alpha/eq3_6", "max_stars_repo_head_hexsha": "4ff7eec3d34634f1470ae5f67d8e294694216b6e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/eqlibu/src/fctrl.f", "max_issues_repo_name": "39alpha/eq3_6", "max_issues_repo_head_hexsha": "4ff7eec3d34634f1470ae5f67d8e294694216b6e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-11-30T15:48:52.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-02T18:16:22.000Z", "max_forks_repo_path": "src/eqlibu/src/fctrl.f", "max_forks_repo_name": "39alpha/eq3_6", "max_forks_repo_head_hexsha": "4ff7eec3d34634f1470ae5f67d8e294694216b6e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.4464285714, "max_line_length": 72, "alphanum_fraction": 0.3786793954, "num_tokens": 305, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737806, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6664032047783439}} {"text": "c Set up Cartesian coordinate system by short distance conversion.\nc Unrotated coordinate system with pos. x-axis toward WEST\nc and pos. y-axis toward NORTH.\nc pos. z-axis toward EARTH`s CENTER.\n\n\tsubroutine setorg(orlat, orlon, rota, ifil) !22. Okt. 1990\n\n\timplicit none\n\nc\tParameters:\n\treal\torlat, orlon\n\treal\trota\t\t! Anticlockwise rotation (degrees)\n\tinteger\tifil\n\n\tinclude \"geocoord.inc\"\n\n\treal\tarota\n\tdoubleprecision r, lat1, lat2, dela, delb, PHI, BETA\n\nc O(r)LAT & O(r)LON : origin of cartesian coordinate system\nc north w e s t\n\nc if orlat and orlon are both set to zero , the Swiss Cartesian\nc coordinate system will be used (this system cannot be rotated).\nc For all other cases, orlat and orlon denote the origin of\nc the SDC.\n\n rad = 0.017453292d0\n\n if(orlat.eq.0.0.and.orlon.eq.0.0)then\n olat=46.95240 ! BERN North\n olon=-7.439583 ! BERN West\n rotate=0.0\n else\n olat=orlat\n olon=orlon\n rotate=rota*rad\n endif\n\n olat=olat*60. ! minutes N\n olon=olon*60. ! minutes W\n\nC NEW ELLIPSOID FOR WHOLE EARTH: WGS72 == WORLD GEODETIC SYSTEM 1972\n\nC ALSO SET RLATC ACCORDING TO ORIGIN\n\n REARTH=6378.135D0\n ELLIP=298.26 ! (flattening)\n\n\nC CALCULATE RLATC: CONVERSION FROM GEOGRAPHICAL LAT TO GEOCENTRICAL LAT\n\n PHI=OLAT*RAD/60.0 ! phi=geogr. lat\n BETA=PHI-DSIN(PHI*2.)/ELLIP ! beta=geoc. lat\n RLATC=DTAN(BETA)/DTAN(PHI)\n\nC WRITE ELLIPSOIDE CONSTANTS\n\n if(ifil.gt.0)then\n write(ifil,*)\n write(ifil,*)\n write(ifil,*)'SHORT DISTANCE CONVERSION on ELLIPSOIDE of'//\n & ' WORLD GEODETIC SYSTEM 1972 (WGS72)'\n write(ifil,*)'=========================================='//\n & '==================================='\n write(ifil,*)\n write(ifil,'('' Radius at equator (REARTH)= '',f10.5,\n & '' km'')') rearth\n write(ifil,'('' 1. / (ellipticity) = '',f10.3)') ellip\n write(ifil,*)\n write(ifil,*)'Origin of cartesian coordinates [degrees]:'\n if(orlat.eq.0.0.and.orlon.eq.0.0)then\n write(ifil,*)\n write(ifil,*)' SWISS COORDINATE SYSTEM (we have to be'\n write(ifil,*)' special)'\n write(ifil,*)' (Origin = city of BERNE, Switzerland)'\n write(ifil,*)\n write(ifil,*) ' no rotation of grid, pos. y-axis toward N'\n write(ifil,*) ' pos. x-axis toward E'\n write(ifil,*)\n else\n write(ifil,'(1x,f12.7,'' N'',5x,f12.7,'' W'')')\n & olat/60.,olon/60.\n\n write(ifil,*)\n write(ifil,*) ' without rotation of grid, '\n write(ifil,*) ' pos. x-axis toward WEST'\n write(ifil,*) ' pos. y-axis toward NORTH'\n write(ifil,*)\n write(ifil,*) ' Rotation of y-axis from North anticlock-'\n write(ifil,*) ' wise with pos. angle given in degrees'\n write(ifil,*)\n IF(ROTA.GE.0.) THEN\n write(ifil,*) ' Rotation of grid anticlockwise by'\n write(ifil,*)' ', rota,' degrees'\n write(ifil,*)\n ELSE\n write(ifil,*) ' Rotation of grid clockwise by'\n arota=-1.*rota\n write(ifil,*)' ', arota,' degrees'\n write(ifil,*)\n ENDIF\n endif\n endif\n\nc calculate aa & bb\nc length of one minute of lat and lon in km\n\n lat1 = datan(rlatc*dtan(olat*rad/60.0)) ! geoc. lat for OLAT\n lat2 = datan(rlatc*dtan((olat+1.)*rad/60.0)) ! geoc. lat for (OLAT+1min)\n dela = lat2 - lat1\n r = rearth*(1.0 - (dsin(lat1)**2)/ellip) ! kugelradius fuer lat=OLAT\n aa = r*dela ! aa = 1 min geogr. lat\n delb = dacos(dsin(lat1)**2 + dcos(rad/60.)*dcos(lat1)**2)\n bc=r*delb ! bc = 1 min geogr. lon\n bb = r*delb/dcos(lat1)\n if(ifil.gt.0)then\n write(ifil,'('' Radius of sphere at OLAT = '',f10.3,'' km'')')r\n write(ifil,*)\n write(ifil,*)'Conversion of GEOGRAPHICAL LATITUDE to '//\n & 'GEOCENTRICAL LATITUDE:'\n write(ifil,*)'RLATC = TAN(GEOCENTR.LAT) / TAN(GEOGRAPH.LAT)'\n write(ifil,'(1x,''RLATC = '',f12.8)') rlatc\n write(ifil,*)\n write(ifil,4) aa, bc\n 4 format (10x,'Short distance conversions:',/,\n & 10x,'one min lat ~ ', f7.4,' km ',/,\n & 10x,'one min lon ~ ', f7.4,' km ',/)\n write(ifil,*)\n write(ifil,*)\n endif\n\nc*** convert coordinates with rotation cosines (stored in Common)\n sint=sin(rotate)\n cost=cos(rotate)\n\n return\n end\n", "meta": {"hexsha": "59bbeb644c4612635c247c59d367535ad599ef5b", "size": 4761, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "HypoDD_scripts/src/hypoDD/setorg.f", "max_stars_repo_name": "Damin1909/ESPRH", "max_stars_repo_head_hexsha": "2b26a7e698fe7c411d44ce5f51d52fffdb742d48", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-12-02T02:01:11.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-02T02:01:11.000Z", "max_issues_repo_path": "HypoDD_scripts/src/hypoDD/setorg.f", "max_issues_repo_name": "Damin1909/ESPRH", "max_issues_repo_head_hexsha": "2b26a7e698fe7c411d44ce5f51d52fffdb742d48", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HypoDD_scripts/src/hypoDD/setorg.f", "max_forks_repo_name": "Damin1909/ESPRH", "max_forks_repo_head_hexsha": "2b26a7e698fe7c411d44ce5f51d52fffdb742d48", "max_forks_repo_licenses": ["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.2517985612, "max_line_length": 79, "alphanum_fraction": 0.5335013653, "num_tokens": 1479, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632936392131, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6663980682739532}} {"text": "! Generated by TAPENADE (INRIA, Ecuador team)\n! tapenade 3.x\n!\n! Differentiation of tk in reverse (adjoint) mode (with options noISIZE i8):\n! gradient of useful results: *temp *propunit *pres tk\n! with respect to varying inputs: *temp *propunit *pres\n! Plus diff mem management of: temp:in propunit:in pres:in\n!> @brief harmonic mean Kz on cell faces in z direction over delz*\n!> @param[in] i grid indices\n!> @param[in] j grid indices\n!> @param[in] k grid indices\n!> @param[in] ismpl local sample index\n!> @return z hydraulic conductivity over delz* (1/s)\n!> @details\n!> Compute the harmonic mean of Kz on the cell face in positive\n!> z-direction from the current node (i, j, k) divided by the\n!> z-distance of the current node (i, j, k) to the neighboring node\n!> (i, j, k+1).\n!>\n!> delz* = 0.5 ( delz(k) + delz(k+1) )\n!>\n!> Kz / delz* = [ 0.5*delz(k+1)/K(k+1) + 0.5*delz(k)/K(k) ]**-1\n!>\n!> = [ ( 0.5* K(k)* delz(k+1) + 0.5*K(k+1)* delz(k) ) / ( K(k)*K(k+1) ) ]**-1\n!>\n!> = [ ( 0.5 * summ ) / (prod) ]**-1 = 2.0*prod/summ\nSUBROUTINE TK_AD(i, j, k, ismpl, tk_adv)\n use arrays\n\n USE ARRAYS_AD\n\n USE MOD_GENRL\n USE MOD_FLOW\n IMPLICIT NONE\n double precision :: tk_adv\n INTEGER :: ismpl\n INTEGER :: i, j, k\n EXTERNAL KZ, RHOF, VISF\n EXTERNAL KZ_AD, RHOF_AD, VISF_AD\n DOUBLE PRECISION :: f1, f2, prod, summ, KZ, RHOF, &\n& VISF\n DOUBLE PRECISION :: f1_ad, f2_ad, prod_ad, summ_ad\n DOUBLE PRECISION :: result1\n DOUBLE PRECISION :: result1_ad\n DOUBLE PRECISION :: result2\n DOUBLE PRECISION :: result2_ad\n DOUBLE PRECISION :: result3\n DOUBLE PRECISION :: result3_ad\n INTEGER :: arg1\n INTEGER :: arg2\n INTEGER :: arg3\n DOUBLE PRECISION :: temporary_ad\n DOUBLE PRECISION :: tk\n IF (k0 .GT. 1 .AND. k .LT. k0) THEN\n result1 = KZ(i, j, k, ismpl)\n result2 = RHOF(i, j, k, ismpl)\n result3 = VISF(i, j, k, ismpl)\n f1 = result1*result2*grav/result3\n arg1 = k + 1\n CALL PUSHREAL8(result1)\n result1 = KZ(i, j, arg1, ismpl)\n arg2 = k + 1\n CALL PUSHREAL8(result2)\n result2 = RHOF(i, j, arg2, ismpl)\n arg3 = k + 1\n CALL PUSHREAL8(result3)\n result3 = VISF(i, j, arg3, ismpl)\n f2 = result1*result2*grav/result3\n prod = f1*f2\n summ = f1*delz(k+1) + f2*delz(k)\n IF (summ .GT. 0.d0) THEN\n temporary_ad = 2.d0*tk_adv/summ\n prod_ad = temporary_ad\n summ_ad = -(prod*temporary_ad/summ)\n ELSE\n prod_ad = 0.D0\n summ_ad = 0.D0\n END IF\n f1_ad = delz(k+1)*summ_ad + f2*prod_ad\n f2_ad = delz(k)*summ_ad + f1*prod_ad\n temporary_ad = grav*f2_ad/result3\n result1_ad = result2*temporary_ad\n result2_ad = result1*temporary_ad\n result3_ad = -(result1*result2*temporary_ad/result3)\n CALL POPREAL8(result3)\n CALL VISF_AD(i, j, arg3, ismpl, result3_ad)\n CALL POPREAL8(result2)\n CALL RHOF_AD(i, j, arg2, ismpl, result2_ad)\n CALL POPREAL8(result1)\n CALL KZ_AD(i, j, arg1, ismpl, result1_ad)\n temporary_ad = grav*f1_ad/result3\n result1_ad = result2*temporary_ad\n result2_ad = result1*temporary_ad\n result3_ad = -(result1*result2*temporary_ad/result3)\n CALL VISF_AD(i, j, k, ismpl, result3_ad)\n CALL RHOF_AD(i, j, k, ismpl, result2_ad)\n CALL KZ_AD(i, j, k, ismpl, result1_ad)\n END IF\nEND SUBROUTINE TK_AD\n\n", "meta": {"hexsha": "6c98a0f9547a3f618263910541f94363a52073d9", "size": 3312, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "props/ice/ad_tap/head/tk_ad.f90", "max_stars_repo_name": "arielthomas1/SHEMAT-Suite-Open", "max_stars_repo_head_hexsha": "f46bd3f8a9a24faea9fc7e48ea9ea88438e20d78", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "props/ice/ad_tap/head/tk_ad.f90", "max_issues_repo_name": "arielthomas1/SHEMAT-Suite-Open", "max_issues_repo_head_hexsha": "f46bd3f8a9a24faea9fc7e48ea9ea88438e20d78", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "props/ice/ad_tap/head/tk_ad.f90", "max_forks_repo_name": "arielthomas1/SHEMAT-Suite-Open", "max_forks_repo_head_hexsha": "f46bd3f8a9a24faea9fc7e48ea9ea88438e20d78", "max_forks_repo_licenses": ["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.7920792079, "max_line_length": 91, "alphanum_fraction": 0.6328502415, "num_tokens": 1215, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632996617212, "lm_q2_score": 0.7185943925708561, "lm_q1q2_score": 0.6663980670129194}} {"text": " SUBROUTINE TG01LD( JOB, JOBA, COMPQ, COMPZ, N, M, P, A, LDA,\n $ E, LDE, B, LDB, C, LDC, Q, LDQ, Z, LDZ, NF, ND,\n $ NIBLCK, IBLCK, TOL, IWORK, DWORK, LDWORK,\n $ INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute orthogonal transformation matrices Q and Z which\nC reduce the regular pole pencil A-lambda*E of the descriptor system\nC (A-lambda*E,B,C) to the form (if JOB = 'F')\nC\nC ( Af * ) ( Ef * )\nC Q'*A*Z = ( ) , Q'*E*Z = ( ) , (1)\nC ( 0 Ai ) ( 0 Ei )\nC\nC or to the form (if JOB = 'I')\nC\nC ( Ai * ) ( Ei * )\nC Q'*A*Z = ( ) , Q'*E*Z = ( ) , (2)\nC ( 0 Af ) ( 0 Ef )\nC\nC where the subpencil Af-lambda*Ef, with Ef nonsingular and upper\nC triangular, contains the finite eigenvalues, and the subpencil\nC Ai-lambda*Ei, with Ai nonsingular and upper triangular, contains\nC the infinite eigenvalues. The subpencil Ai-lambda*Ei is in a\nC staircase form (see METHOD). If JOBA = 'H', the submatrix Af\nC is further reduced to an upper Hessenberg form.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC JOB CHARACTER*1\nC = 'F': perform the finite-infinite separation;\nC = 'I': perform the infinite-finite separation.\nC\nC JOBA CHARACTER*1\nC = 'H': reduce Af further to an upper Hessenberg form;\nC = 'N': keep Af unreduced.\nC\nC COMPQ CHARACTER*1\nC = 'N': do not compute Q;\nC = 'I': Q is initialized to the unit matrix, and the\nC orthogonal matrix Q is returned;\nC = 'U': Q must contain an orthogonal matrix Q1 on entry,\nC and the product Q1*Q is returned.\nC\nC COMPZ CHARACTER*1\nC = 'N': do not compute Z;\nC = 'I': Z is initialized to the unit matrix, and the\nC orthogonal matrix Z is returned;\nC = 'U': Z must contain an orthogonal matrix Z1 on entry,\nC and the product Z1*Z is returned.\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The number of rows of the matrix B, the number of columns\nC of the matrix C and the order of the square matrices A\nC and E. N >= 0.\nC\nC M (input) INTEGER\nC The number of columns of the matrix B. M >= 0.\nC\nC P (input) INTEGER\nC The number of rows of the matrix C. P >= 0.\nC\nC A (input/output) DOUBLE PRECISION array, dimension (LDA,N)\nC On entry, the leading N-by-N part of this array must\nC contain the N-by-N state matrix A.\nC On exit, the leading N-by-N part of this array contains\nC the transformed state matrix Q'*A*Z,\nC\nC ( Af * ) ( Ai * )\nC Q'*A*Z = ( ) , or Q'*A*Z = ( ) ,\nC ( 0 Ai ) ( 0 Af )\nC\nC depending on JOB, with Af an NF-by-NF matrix, and Ai an\nC (N-NF)-by-(N-NF) nonsingular and upper triangular matrix.\nC If JOBA = 'H', Af is in an upper Hessenberg form.\nC Otherwise, Af is unreduced.\nC Ai has a block structure as in (3) or (4), where A0,0 is\nC ND-by-ND and Ai,i , for i = 1, ..., NIBLCK, is\nC IBLCK(i)-by-IBLCK(i).\nC\nC LDA INTEGER\nC The leading dimension of the array A. LDA >= MAX(1,N).\nC\nC E (input/output) DOUBLE PRECISION array, dimension (LDE,N)\nC On entry, the leading N-by-N part of this array must\nC contain the N-by-N descriptor matrix E.\nC On exit, the leading N-by-N part of this array contains\nC the transformed descriptor matrix Q'*E*Z,\nC\nC ( Ef * ) ( Ei * )\nC Q'*E*Z = ( ) , or Q'*E*Z = ( ) ,\nC ( 0 Ei ) ( 0 Ef )\nC\nC depending on JOB, with Ef an NF-by-NF nonsingular matrix,\nC and Ei an (N-NF)-by-(N-NF) nilpotent matrix in an upper\nC block triangular form, as in (3) or (4).\nC\nC LDE INTEGER\nC The leading dimension of the array E. LDE >= MAX(1,N).\nC\nC B (input/output) DOUBLE PRECISION array, dimension (LDB,K),\nC where K = M if JOB = 'F', and K = MAX(M,P) if JOB = 'I'.\nC On entry, the leading N-by-M part of this array must\nC contain the N-by-M input matrix B.\nC On exit, the leading N-by-M part of this array contains\nC the transformed input matrix Q'*B.\nC\nC LDB INTEGER\nC The leading dimension of the array B. LDB >= MAX(1,N).\nC\nC C (input/output) DOUBLE PRECISION array, dimension (LDC,N)\nC On entry, the leading P-by-N part of this array must\nC contain the state/output matrix C.\nC On exit, the leading P-by-N part of this array contains\nC the transformed matrix C*Z.\nC\nC LDC INTEGER\nC The leading dimension of the array C. LDC >= MAX(1,K),\nC where K = P if JOB = 'F', and K = MAX(M,P) if JOB = 'I'.\nC\nC Q (input/output) DOUBLE PRECISION array, dimension (LDQ,N)\nC If COMPQ = 'N': Q is not referenced.\nC If COMPQ = 'I': on entry, Q need not be set;\nC on exit, the leading N-by-N part of this\nC array contains the orthogonal matrix Q,\nC where Q' is the product of Householder\nC transformations applied to A, E, and B on\nC the left.\nC If COMPQ = 'U': on entry, the leading N-by-N part of this\nC array must contain an orthogonal matrix\nC Q1;\nC on exit, the leading N-by-N part of this\nC array contains the orthogonal matrix\nC Q1*Q.\nC\nC LDQ INTEGER\nC The leading dimension of the array Q.\nC LDQ >= 1, if COMPQ = 'N';\nC LDQ >= MAX(1,N), if COMPQ = 'I' or 'U'.\nC\nC Z (input/output) DOUBLE PRECISION array, dimension (LDZ,N)\nC If COMPZ = 'N': Z is not referenced.\nC If COMPZ = 'I': on entry, Z need not be set;\nC on exit, the leading N-by-N part of this\nC array contains the orthogonal matrix Z,\nC which is the product of Householder\nC transformations applied to A, E, and C on\nC the right.\nC If COMPZ = 'U': on entry, the leading N-by-N part of this\nC array must contain an orthogonal matrix\nC Z1;\nC on exit, the leading N-by-N part of this\nC array contains the orthogonal matrix\nC Z1*Z.\nC\nC LDZ INTEGER\nC The leading dimension of the array Z.\nC LDZ >= 1, if COMPZ = 'N';\nC LDZ >= MAX(1,N), if COMPZ = 'I' or 'U'.\nC\nC NF (output) INTEGER.\nC The order of the reduced matrices Af and Ef; also, the\nC number of finite generalized eigenvalues of the pencil\nC A-lambda*E.\nC\nC ND (output) INTEGER.\nC The number of non-dynamic infinite eigenvalues of the\nC pair (A,E). Note: N-ND is the rank of the matrix E.\nC\nC NIBLCK (output) INTEGER\nC If ND > 0, the number of infinite blocks minus one.\nC If ND = 0, then NIBLCK = 0.\nC\nC IBLCK (output) INTEGER array, dimension (N)\nC IBLCK(i) contains the dimension of the i-th block in the\nC staircase form (3) or (4), with i = 1,2, ..., NIBLCK.\nC\nC Tolerances\nC\nC TOL DOUBLE PRECISION\nC A tolerance used in rank decisions to determine the\nC effective rank, which is defined as the order of the\nC largest leading (or trailing) triangular submatrix in the\nC QR factorization with column pivoting whose estimated\nC condition number is less than 1/TOL. If the user sets\nC TOL <= 0, then an implicitly computed, default tolerance,\nC TOLDEF = N**2*EPS, is used instead, where EPS is the\nC machine precision (see LAPACK Library routine DLAMCH).\nC TOL < 1.\nC\nC Workspace\nC\nC IWORK INTEGER array, dimension (N)\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0, DWORK(1) returns the optimal value\nC of LDWORK.\nC\nC LDWORK INTEGER\nC The length of the array DWORK. LDWORK >= 1, and if N > 0,\nC LDWORK >= N + MAX(3*N,M,P).\nC\nC If LDWORK = -1, then a workspace query is assumed; the\nC routine only calculates the optimal size of the DWORK\nC array, returns this value as the first entry of the DWORK\nC array, and no error message related to LDWORK is issued by\nC XERBLA.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value;\nC = 1: the pencil A-lambda*E is not regular.\nC\nC METHOD\nC\nC The subroutine is based on the reduction algorithm of [1].\nC If JOB = 'F', the matrices Ai and Ei have the form\nC\nC ( A0,0 A0,k ... A0,1 ) ( 0 E0,k ... E0,1 )\nC Ai = ( 0 Ak,k ... Ak,1 ) , Ei = ( 0 0 ... Ek,1 ) ; (3)\nC ( : : . : ) ( : : . : )\nC ( 0 0 ... A1,1 ) ( 0 0 ... 0 )\nC\nC if JOB = 'I', the matrices Ai and Ei have the form\nC\nC ( A1,1 ... A1,k A1,0 ) ( 0 ... E1,k E1,0 )\nC Ai = ( : . : : ) , Ei = ( : . : : ) , (4)\nC ( : ... Ak,k Ak,0 ) ( : ... 0 Ek,0 )\nC ( 0 ... 0 A0,0 ) ( 0 ... 0 0 )\nC\nC where Ai,i , for i = 0, 1, ..., k, are nonsingular upper\nC triangular matrices. A0,0 corresponds to the non-dynamic infinite\nC modes of the system.\nC\nC REFERENCES\nC\nC [1] Misra, P., Van Dooren, P., and Varga, A.\nC Computation of structural invariants of generalized\nC state-space systems.\nC Automatica, 30, pp. 1921-1936, 1994.\nC\nC NUMERICAL ASPECTS\nC\nC The algorithm is numerically backward stable and requires\nC 0( N**3 ) floating point operations.\nC\nC FURTHER COMMENTS\nC\nC The number of infinite poles is computed as\nC\nC NIBLCK\nC NINFP = Sum IBLCK(i) = N - ND - NF.\nC i=1\nC\nC The multiplicities of infinite poles can be computed as follows:\nC there are IBLCK(k)-IBLCK(k+1) infinite poles of multiplicity\nC k, for k = 1, ..., NIBLCK, where IBLCK(NIBLCK+1) = 0.\nC Note that each infinite pole of multiplicity k corresponds to\nC an infinite eigenvalue of multiplicity k+1.\nC\nC CONTRIBUTOR\nC\nC A. Varga, German Aerospace Center, DLR Oberpfaffenhofen.\nC July 1999. Based on the RASP routines SRISEP and RPDSGH.\nC\nC REVISIONS\nC\nC A. Varga, 3-11-2002.\nC V. Sima, Dec. 2016, June 2017.\nC\nC KEYWORDS\nC\nC Generalized eigenvalue problem, system poles, multivariable\nC system, orthogonal transformation, structural invariant.\nC\nC ******************************************************************\nC\nC ..\nC .. Parameters ..\n DOUBLE PRECISION ONE\n PARAMETER ( ONE = 1.0D0 )\nC .. Scalar Arguments ..\n CHARACTER COMPQ, COMPZ, JOB, JOBA\n INTEGER INFO, LDA, LDB, LDC, LDE, LDQ, LDWORK, LDZ, M,\n $ N, ND, NF, NIBLCK, P\n DOUBLE PRECISION TOL\nC .. Array Arguments ..\n INTEGER IBLCK( * ), IWORK(*)\n DOUBLE PRECISION A( LDA, * ), B( LDB, * ), C( LDC, * ),\n $ DWORK( * ), E( LDE, * ), Q( LDQ, * ),\n $ Z( LDZ, * )\nC .. Local Scalars ..\n CHARACTER JOBQ, JOBZ\n LOGICAL ILQ, ILZ, LQUERY, REDA, REDIF\n INTEGER I, ICOMPQ, ICOMPZ, IHI, ILO, MINWRK, RANKE,\n $ RNKA22, WRKOPT\nC .. Local Arrays ..\n DOUBLE PRECISION DUM(1)\nC .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\nC .. External Subroutines ..\n EXTERNAL AB07MD, DSWAP, MA02BD, MA02CD, TB01XD, TG01BD,\n $ TG01FD, TG01LY, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC INT, MAX\nC .. Executable Statements ..\nC\nC Decode COMPQ.\nC\n IF( LSAME( COMPQ, 'N' ) ) THEN\n ILQ = .FALSE.\n ICOMPQ = 1\n ELSE IF( LSAME( COMPQ, 'U' ) ) THEN\n ILQ = .TRUE.\n ICOMPQ = 2\n ELSE IF( LSAME( COMPQ, 'I' ) ) THEN\n ILQ = .TRUE.\n ICOMPQ = 3\n ELSE\n ICOMPQ = 0\n END IF\nC\nC Decode COMPZ.\nC\n IF( LSAME( COMPZ, 'N' ) ) THEN\n ILZ = .FALSE.\n ICOMPZ = 1\n ELSE IF( LSAME( COMPZ, 'U' ) ) THEN\n ILZ = .TRUE.\n ICOMPZ = 2\n ELSE IF( LSAME( COMPZ, 'I' ) ) THEN\n ILZ = .TRUE.\n ICOMPZ = 3\n ELSE\n ICOMPZ = 0\n END IF\n REDIF = LSAME( JOB, 'I' )\n REDA = LSAME( JOBA, 'H' )\nC\nC Test the input parameters.\nC\n INFO = 0\n IF( .NOT.LSAME( JOB, 'F' ) .AND. .NOT.REDIF ) THEN\n INFO = -1\n ELSE IF( .NOT.LSAME( JOBA, 'N' ) .AND. .NOT.REDA ) THEN\n INFO = -2\n ELSE IF( ICOMPQ.LE.0 ) THEN\n INFO = -3\n ELSE IF( ICOMPZ.LE.0 ) THEN\n INFO = -4\n ELSE IF( N.LT.0 ) THEN\n INFO = -5\n ELSE IF( M.LT.0 ) THEN\n INFO = -6\n ELSE IF( P.LT.0 ) THEN\n INFO = -7\n ELSE IF( LDA.LT.MAX( 1, N ) ) THEN\n INFO = -9\n ELSE IF( LDE.LT.MAX( 1, N ) ) THEN\n INFO = -11\n ELSE IF( LDB.LT.MAX( 1, N ) ) THEN\n INFO = -13\n ELSE IF( ( .NOT.REDIF .AND. LDC.LT.MAX( 1, P ) ) .OR.\n $ ( REDIF .AND. LDC.LT.MAX( 1, M, P ) ) )THEN\n INFO = -15\n ELSE IF( ( ILQ .AND. LDQ.LT.N ) .OR. LDQ.LT.1 ) THEN\n INFO = -17\n ELSE IF( ( ILZ .AND. LDZ.LT.N ) .OR. LDZ.LT.1 ) THEN\n INFO = -19\n ELSE IF( TOL.GE.ONE ) THEN\n INFO = -24\n ELSE\n LQUERY = LDWORK.EQ.-1\n IF( N.EQ.0 ) THEN\n MINWRK = 1\n ELSE\n MINWRK = N + MAX( 3*N, M, P )\n END IF\n IF( LQUERY ) THEN\n RANKE = MAX( 1, INT( N/2 ) )\n RNKA22 = N - RANKE\nC\n IF( REDIF ) THEN\n CALL TG01FD( COMPZ, COMPQ, 'Trapezoidal', N, N, P, M, A,\n $ LDA, E, LDE, B, LDB, C, LDC, Z, LDZ, Q, LDQ,\n $ RANKE, RNKA22, TOL, IWORK, DWORK, -1, INFO )\n WRKOPT = MAX( MINWRK, INT( DWORK(1) ) )\n CALL TG01LY( ILZ, ILQ, N, P, M, RANKE, RNKA22, A, LDA,\n $ E, LDE, B, LDB, C, LDC, Z, LDZ, Q, LDQ, NF,\n $ NIBLCK, IBLCK, TOL, IWORK, DWORK, -1, INFO )\n ELSE\n CALL TG01FD( COMPQ, COMPZ, 'Trapezoidal', N, N, M, P, A,\n $ LDA, E, LDE, B, LDB, C, LDC, Q, LDQ, Z, LDZ,\n $ RANKE, RNKA22, TOL, IWORK, DWORK, -1, INFO )\n WRKOPT = MAX( MINWRK, INT( DWORK(1) ) )\n CALL TG01LY( ILQ, ILZ, N, M, P, RANKE, RNKA22, A, LDA,\n $ E, LDE, B, LDB, C, LDC, Q, LDQ, Z, LDZ, NF,\n $ NIBLCK, IBLCK, TOL, IWORK, DWORK, -1, INFO )\n END IF\n WRKOPT = MAX( WRKOPT, INT( DWORK(1) ) )\n END IF\n IF( LDWORK.LT.MINWRK .AND. .NOT.LQUERY ) THEN\n INFO = -27\n END IF\n END IF\nC\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'TG01LD', -INFO )\n RETURN\n ELSE IF( LQUERY ) THEN\n DWORK(1) = WRKOPT\n RETURN\n END IF\nC\nC Quick return if possible\nC\n IF( N.EQ.0 ) THEN\n NF = 0\n ND = 0\n NIBLCK = 0\n DWORK(1) = ONE\n RETURN\n END IF\nC\n IF( REDIF ) THEN\nC\nC Build the dual system.\nC\n CALL AB07MD( 'Z', N, M, P, A, LDA, B, LDB, C, LDC, DUM, 1,\n $ INFO )\n DO 10 I = 2, N\n CALL DSWAP( I-1, E(I,1), LDE, E(1,I), 1 )\n 10 CONTINUE\nC\nC Reduce to SVD-like form with A22 in QR-form.\nC\n CALL TG01FD( COMPZ, COMPQ, 'Trapezoidal', N, N, P, M, A, LDA,\n $ E, LDE, B, LDB, C, LDC, Z, LDZ, Q, LDQ, RANKE,\n $ RNKA22, TOL, IWORK, DWORK, LDWORK, INFO )\n WRKOPT = MAX( MINWRK, INT( DWORK(1) ) )\nC\nC Perform finite-infinite separation.\nC\n CALL TG01LY( ILZ, ILQ, N, P, M, RANKE, RNKA22, A, LDA,\n $ E, LDE, B, LDB, C, LDC, Z, LDZ, Q, LDQ, NF,\n $ NIBLCK, IBLCK, TOL, IWORK, DWORK, LDWORK, INFO )\n ILO = N - NF + 1\n IHI = N\n ELSE\nC\nC Reduce to SVD-like form with A22 in QR-form.\nC\n CALL TG01FD( COMPQ, COMPZ, 'Trapezoidal', N, N, M, P, A, LDA,\n $ E, LDE, B, LDB, C, LDC, Q, LDQ, Z, LDZ, RANKE,\n $ RNKA22, TOL, IWORK, DWORK, LDWORK, INFO )\n WRKOPT = MAX( MINWRK, INT( DWORK(1) ) )\nC\nC Perform finite-infinite separation.\nC\n CALL TG01LY( ILQ, ILZ, N, M, P, RANKE, RNKA22, A, LDA,\n $ E, LDE, B, LDB, C, LDC, Q, LDQ, Z, LDZ, NF,\n $ NIBLCK, IBLCK, TOL, IWORK, DWORK, LDWORK, INFO )\n ILO = 1\n IHI = NF\n END IF\nC\n IF( INFO.NE.0 )\n $ RETURN\n WRKOPT = MAX( WRKOPT, INT( DWORK(1) ) )\nC\n ND = N - RANKE\nC\n IF( REDIF ) THEN\nC\nC Compute the pertransposed dual system exploiting matrix shapes.\nC\n CALL TB01XD( 'Z', N, P, M, MAX( 0, NF-1 ), MAX( 0, N-1 ),\n $ A, LDA, B, LDB, C, LDC, DUM, 1, INFO )\n CALL MA02CD( N, 0, MAX( 0, N-1 ), E, LDE )\n IF( ILQ )\n $ CALL MA02BD( 'Right', N, N, Q, LDQ )\n IF( ILZ )\n $ CALL MA02BD( 'Right', N, N, Z, LDZ )\n END IF\nC\nC If required, reduce (A,E) to generalized Hessenberg form.\nC\n IF( REDA ) THEN\n IF( ILQ) THEN\n JOBQ = 'V'\n ELSE\n JOBQ = 'N'\n END IF\n IF( ILZ) THEN\n JOBZ = 'V'\n ELSE\n JOBZ = 'N'\n END IF\n CALL TG01BD( 'Upper', JOBQ, JOBZ, N, M, P, ILO, IHI, A, LDA,\n $ E, LDE, B, LDB, C, LDC, Q, LDQ, Z, LDZ, DWORK,\n $ LDWORK, INFO )\n END IF\nC\n DWORK(1) = WRKOPT\nC\n RETURN\nC *** Last line of TG01LD ***\n END\n", "meta": {"hexsha": "a5ff23d5f9e0d47f49644488410e6d7d72b88985", "size": 19300, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/TG01LD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/TG01LD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/TG01LD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 36.9731800766, "max_line_length": 72, "alphanum_fraction": 0.4837823834, "num_tokens": 6052, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9441768635777511, "lm_q2_score": 0.7057850340255386, "lm_q1q2_score": 0.6663858997863494}} {"text": "C$Procedure CHBINT ( Interpolate a Chebyshev expansion )\n \n SUBROUTINE CHBINT ( CP, DEGP, X2S, X, P, DPDX )\n \nC$ Abstract\nC\nC Given the coefficients for the Chebyshev expansion of a\nC polynomial, this returns the value of the polynomial and its\nC derivative evaluated at the input X.\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 INTERPOLATION, MATH, POLYNOMIAL\nC\nC$ Declarations\n \n DOUBLE PRECISION CP ( * )\n INTEGER DEGP\n DOUBLE PRECISION X2S ( 2 )\n DOUBLE PRECISION X\n DOUBLE PRECISION P\n DOUBLE PRECISION DPDX\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC CP I NDEG+1 Chebyshev polynomial coefficients.\nC DEGP I Degree of polynomial.\nC X2S I Transformation parameters of polynomial.\nC X I Value for which the polynomial is to be evaluated\nC P O Value of the polynomial at X\nC DPDX O Value of the derivative of the polynomial at X\nC\nC$ Detailed_Input\nC\nC CP is an array of coefficients OF a polynomial with\nC respect to the Chebyshev basis. The polynomial to be\nC evaluated is assumed to be of the form:\nC\nC CP(DEGP+1)*T(DEGP,S) + CP(DEGP)*T(DEGP-1,S) + ...\nC\nC ... + CP(2)*T(1,S) + CP(1)*T(0,S)\nC\nC where T(I,S) is the I'th Chebyshev polynomial\nC evaluated at a number S whose double precision\nC value lies between -1 and 1. The value of S is\nC computed from the input variables X2S(1), X2S(2) and X\nC\nC DEGP is the degree of the Chebyshev polynomial to be\nC evaluated.\nC\nC X2S is an array of two parameters. These parameters are\nC used to transform the domain of the input variable X\nC into the standard domain of the Chebyshev polynomial.\nC X2S(1) should be a reference point in the domain of X;\nC X2S(2) should be the radius by which points are\nC allowed to deviate from the reference point and while\nC remaining within the domain of X. The value of\nC X is transformed into the value S given by\nC\nC S = ( X - X2S(1) ) / X2S(2)\nC\nC Typically X2S(1) is the midpoint of the interval over\nC which X is allowed to vary and X2S(2) is the radius of\nC the interval.\nC\nC The main reason for doing this is that a Chebyshev\nC expansion is usually fit to data over a span\nC from A to B where A and B are not -1 and 1\nC respectively. Thus to get the \"best fit\" the\nC data was transformed to the interval [-1,1] and\nC coefficients generated. These coefficients are\nC not rescaled to the interval of the data so that\nC the numerical \"robustness\" of the Chebyshev fit will\nC not be lost. Consequently, when the \"best fitting\"\nC polynomial needs to be evaluated at an intermediate\nC point, the point of evaluation must be transformed\nC in the same way that the generating points were\nC transformed.\nC\nC X Value for which the polynomial is to be evaluated.\nC\nC$ Detailed_Output\nC\nC P is the value of the polynomial to be evaluated. It\nC is given by\nC\nC CP(DEGP+1)*T(DEGP,S) + CP(DEGP)*T(DEGP-1,S) + ...\nC\nC ... + CP(2)*T(1,S) + CP(1)*T(0,S)\nC\nC where T(I,S) is the I'th Chebyshev polynomial\nC evaluated at a number S = ( X - X2S(1) )/X2S(2)\nC\nC DPDX is the value of the derivative of the polynomial at X.\nC It is given by\nC\nC 1/X2S(2) [ CP(DEGP+1)*T'(DEGP,S)\nC + CP(DEGP)*T'(DEGP-1,S) + ...\nC .\nC .\nC .\nC ... + CP(2)*T'(1,S)\nC + CP(1)*T'(0,S) ]\nC\nC where T(I,S) and T'(I,S) are the I'th Chebyshev\nC polynomial and its derivative, respectively,\nC evaluated at a number S = ( X - X2S(1) )/X2S(2)\nC\nC$ Parameters\nC\nC None.\nC\nC$ Particulars\nC\nC This routine computes the value of a Chebyshev polynomial\nC expansion and the derivative of the expansion with respect to X.\nC The polynomial is given by\nC\nC CP(DEGP+1)*T(DEGP,S) + CP(DEGP)*T(DEGP-1,S) + ...\nC\nC ... + CP(2)*T(1,S) + CP(1)*T(0,S)\nC\nC where\nC\nC S = ( X - X2S(1) ) / X2S(2)\nC\nC and\nC\nC T(i,S) is the i'th Chebyshev polynomial of the first kind\nC evaluated at S.\nC\nC$ Examples\nC\nC\nC Depending upon the user's needs, there are 3 routines available\nC for evaluating Chebyshev polynomials.\nC\nC CHBVAL for evaluating a Chebyshev polynomial when no\nC derivatives are desired.\nC\nC CHBINT for evaluating a Chebyshev polynomial and its\nC first derivative.\nC\nC CHBDER for evaluating a Chebyshev polynomial and a user\nC or application dependent number of derivatives.\nC\nC Of these 3 the one most commonly employed by NAIF software\nC is CHBINT as it is used to interpolate ephemeris state\nC vectors which requires the evaluation of a polynomial\nC and its derivative. When no derivatives are desired one\nC should use CHBVAL, or when more than one or an unknown\nC number of derivatives are desired one should use CHBDER.\nC\nC The code fragment below illustrates how this routine might\nC be used to obtain points for plotting a polynomial\nC and its derivatives.\nC\nC fetch the pieces needed for describing the polynomial\nC to be evaluated.\nC\nC READ (*,*) DEGP, ( CP(I), I = 1, DEG+1 ), BEG, END\nC\nC check to see that BEG is actually less than END\nC\nC IF ( BEG .GE. END ) THEN\nC\nC take some appropriate action\nC\nC ELSE\nC\nC X2S(1) = ( END + BEG ) / 2.0D0\nC X2S(2) = ( END - BEG ) / 2.0D0\nC\nC END IF\nC\nC STEP = END - BEG / \nC X = BEG\nC\nC DO WHILE ( X .LE. END )\nC\nC CALL CHBINT ( CP, DEGP, X2S, X, P, DPDX )\nC\nC do something with the pairs (X,P) and (X,DPDX)\nC\nC X = X + STEP\nC\nC END DO\nC\nC$ Restrictions\nC\nC One needs to be careful that the value (X-X2S(1)) / X2S(2) lies\nC between -1 and 1. Otherwise, the routine may fail spectacularly\nC (for example with a floating point overflow).\nC\nC$ Exceptions\nC\nC Error free\nC\nC No tests are performed for exceptional values (DEGP negative,\nC etc.) This routine is expected to be used at a low level in\nC ephemeris evaluations. For that reason it has been elected as a\nC routine that will not participate in error handling.\nC\nC$ Files\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC W.L. Taber (JPL)\nC\nC$ Literature_References\nC\nC \"Numerical Recipes -- The Art of Scientific Computing\" by\nC William H. Press, Brian P. Flannery, Saul A. Teukolsky,\nC Willam T. Vetterling. (See Clenshaw's Recurrance Formula)\nC\nC \"The Chebyshev Polynomials\" by Theodore J. Rivlin\nC\nC \"CRC Handbook of Tables for Mathematics\"\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)\nC\nC Comment section for permuted index source lines was added\nC following the header.\nC\nC- SPICELIB Version 1.0.0, 31-JAN-1990 (WLT)\nC\nC-&\n \nC$ Index_Entries\nC\nC interpolate a chebyshev expansion\nC\nC-&\n \n \n \nC$ Revisions\nC\nC- Beta Version 1.0.1, 30-DEC-1988 (WLT)\nC\nC The Error free specification was added to the routine as\nC well as an explanation for this designation. Examples added.\nC\nC-&\n \n \nC\nC Local variables\nC\n INTEGER J\n DOUBLE PRECISION W (3)\n DOUBLE PRECISION DW(3)\n DOUBLE PRECISION S\n DOUBLE PRECISION S2\nC\nC Transform X to S and initialize temporary variables.\nC\n S = (X-X2S(1)) / X2S(2)\n S2 = 2.0D0 * S\n J = DEGP + 1\n W (1) = 0.D0\n W (2) = 0.D0\n DW(1) = 0.D0\n DW(2) = 0.D0\nC\nC Evaluate the polynomial and its derivative using recursion.\nC\n DO WHILE ( J .GT. 1 )\n \n W (3) = W (2)\n W (2) = W (1)\n W (1) = CP(J) + ( S2*W(2) - W(3) )\n \n DW(3) = DW(2)\n DW(2) = DW(1)\n DW(1) = W(2)*2.0D0 + DW(2)*S2 - DW(3)\n \n J = J - 1\n \n END DO\n \n P = CP(1) + ( S*W (1) - W (2) )\n DPDX = W(1) + S*DW(1) - DW(2)\nC\nC Scale the derivative by 1/X2S(2) so that we have the derivative\nC\nC d P(S)\nC ------\nC dX\nC\n DPDX = DPDX / X2S(2)\n \n RETURN\n END\n", "meta": {"hexsha": "5df23f5552eae9b30bd7eb537705bc9a6a01e830", "size": 10595, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/chbint.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/chbint.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/chbint.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": 32.1060606061, "max_line_length": 72, "alphanum_fraction": 0.5824445493, "num_tokens": 3038, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768651485395, "lm_q2_score": 0.7057850278370111, "lm_q1q2_score": 0.6663858950519238}} {"text": "subroutine third_stage(k,k_t)\n\nuse definiciones\nimplicit none\ninteger(4)::i,j,k,k_t\n\n\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n!Tercera etapa del esquema RK3\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\ndo i=2,nx_i\n\ndo j=2,nz_i\n\nk_omega(1,1)=-u_old(i,j)*(omega_old(i+1,j)-omega_old(i-1,j))/(2.0d0*delta_x)-&\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nw_old(i,j)*(omega_old(i,j+1)-omega_old(i,j-1))/(2.0d0*delta_z)+&\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n(omega_old(i+1,j)-2.0d0*omega_old(i,j)+omega_old(i-1,j))/(sqrt(gr)*delta_x**2)+&\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n(omega_old(i,j+1)-2.0d0*omega_old(i,j)+omega_old(i,j-1))/(sqrt(gr)*delta_z**2)\n\nk_omega(2,1)=-u_aprox(i,j)*(omega_aprox(i+1,j)-omega_aprox(i-1,j))/(2.0d0*delta_x)-&\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nw_aprox(i,j)*(omega_aprox(i,j+1)-omega_aprox(i,j-1))/(2.0d0*delta_z)+&\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n(omega_aprox(i+1,j)-2.0d0*omega_aprox(i,j)+omega_aprox(i-1,j))/(sqrt(gr)*delta_x**2)+&\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n(omega_aprox(i,j+1)-2.0d0*omega_aprox(i,j)+omega_aprox(i,j-1))/(sqrt(gr)*delta_z**2)\n\nk_omega(3,1)=-u_aprox_1(i,j)*(omega_aprox_1(i+1,j)-omega_aprox_1(i-1,j))/(2.0d0*delta_x)-&\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nw_aprox_1(i,j)*(omega_aprox_1(i,j+1)-omega_aprox_1(i,j-1))/(2.0d0*delta_z)+&\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n(omega_aprox_1(i+1,j)-2.0d0*omega_aprox_1(i,j)+omega_aprox_1(i-1,j))/(sqrt(gr)*delta_x**2)+&\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n(omega_aprox_1(i,j+1)-2.0d0*omega_aprox_1(i,j)+omega_aprox_1(i,j-1))/(sqrt(gr)*delta_z**2)\n\n\n\nomega_new(i,j)=omega_old(i,j)+delta_t/6.0d0*(k_omega(1,1)+4.0d0*k_omega(2,1)+k_omega(3,1))\n\n\nend do\n\nend do\n\n\n\nend subroutine third_stage\n", "meta": {"hexsha": "2f19fc69cfcb35ec0c13e3726bbbf8dcba4fc264", "size": 2280, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "thrid_stage.f90", "max_stars_repo_name": "jarrietasanagustin/lid_driven_cavity", "max_stars_repo_head_hexsha": "30a0367f46a7029a887f91db5f00cdae7e3ac1a7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "thrid_stage.f90", "max_issues_repo_name": "jarrietasanagustin/lid_driven_cavity", "max_issues_repo_head_hexsha": "30a0367f46a7029a887f91db5f00cdae7e3ac1a7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "thrid_stage.f90", "max_forks_repo_name": "jarrietasanagustin/lid_driven_cavity", "max_forks_repo_head_hexsha": "30a0367f46a7029a887f91db5f00cdae7e3ac1a7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.8461538462, "max_line_length": 100, "alphanum_fraction": 0.3833333333, "num_tokens": 618, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768620069626, "lm_q2_score": 0.7057850216484838, "lm_q1q2_score": 0.6663858869915816}} {"text": "program sorting\nuse sorting_subroutines\nimplicit none\n\nreal(kind=8), allocatable, dimension(:) :: A1, A2\nreal(kind=8) :: B\ninteger :: n, i\n\nwrite(*,*) 'size of array?'\nread(*,*) n\n\nallocate (A1(n), A2(n))\n\ncall random_seed()\ndo i = 1, n\n call random_number(B)\n A1(i) = B*500.00\n A2(i) = A1(i)\nend do\n\ncall bubble_sort(n, A1)\n\n!call first_and_last(n, A2)\n\nend program sorting\n", "meta": {"hexsha": "93698473322033d342ead2594476d7e11f29d95c", "size": 381, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "after_gaussian_optimization/sort_random_numbers/sort.f95", "max_stars_repo_name": "ElenaKusevska/coordinates_on_a_grid", "max_stars_repo_head_hexsha": "6605c76d9c6561fee6eaaa844fb954f7784f623c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "after_gaussian_optimization/sort_random_numbers/sort.f95", "max_issues_repo_name": "ElenaKusevska/coordinates_on_a_grid", "max_issues_repo_head_hexsha": "6605c76d9c6561fee6eaaa844fb954f7784f623c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "after_gaussian_optimization/sort_random_numbers/sort.f95", "max_forks_repo_name": "ElenaKusevska/coordinates_on_a_grid", "max_forks_repo_head_hexsha": "6605c76d9c6561fee6eaaa844fb954f7784f623c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 14.6538461538, "max_line_length": 49, "alphanum_fraction": 0.6535433071, "num_tokens": 135, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8104788995148792, "lm_q2_score": 0.822189123986562, "lm_q1q2_score": 0.6663669364017313}} {"text": " PROGRAM xmachar\r\nC driver for routine machar\r\n INTEGER ibeta,iexp,irnd,it,machep,maxexp,minexp,negep,ngrd\r\n REAL eps,epsneg,xmax,xmin\r\n call machar(ibeta,it,irnd,ngrd,machep,negep,iexp,minexp,\r\n * maxexp,eps,epsneg,xmin,xmax)\r\n write(*,*) 'ibeta=',ibeta\r\n write(*,*) 'it=',it\r\n write(*,*) 'irnd=',irnd\r\n write(*,*) 'ngrd=',ngrd\r\n write(*,*) 'machep=',machep\r\n write(*,*) 'negep=',negep\r\n write(*,*) 'iexp=',iexp\r\n write(*,*) 'minexp=',minexp\r\n write(*,*) 'maxexp=',maxexp\r\n write(*,*) 'eps=',eps\r\n write(*,*) 'epsneg=',epsneg\r\n write(*,*) 'xmin=',xmin\r\n write(*,*) 'xmax=',xmax\r\n END\r\n", "meta": {"hexsha": "792bf358abde814a10f66b5ed9fa751f453df5b6", "size": 688, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xmachar.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xmachar.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xmachar.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.7619047619, "max_line_length": 65, "alphanum_fraction": 0.5261627907, "num_tokens": 243, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891130942474, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.6663669294556165}} {"text": "PROGRAM main\n\n USE mo_kind, ONLY: dp, sp, i4\n use mo_ansi_colors, only: color, c_red, c_green\n USE mo_percentile, ONLY: median, percentile, qmedian, n_element\n USE mo_orderpack, ONLY: sort\n USE mo_utils, ONLY: eq, ne\n\n IMPLICIT NONE\n\n REAL(dp), DIMENSION(10) :: dat\n REAL(dp), DIMENSION(2) :: dqua\n REAL(sp), DIMENSION(10) :: sat\n REAL(sp), DIMENSION(2) :: squa\n\n real(sp) :: stmp\n real(dp) :: dtmp\n\n#ifndef __ABSOFT__\n#ifdef __GFORTRAN__\n ! If arrays re too big, the flag -frecursive gives either\n ! Illegal instruction: 4\n ! or\n ! Segmentation fault: 11\n ! The large numbers work with gfortran if not -frecursive. Then it states\n ! Warning: Array 'big' at (1) is larger than limit set by '-fmax-stack-var-size=',\n ! moved from stack to static storage. This makes the procedure unsafe when called\n ! recursively, or concurrently from multiple threads. Consider using '-frecursive',\n ! or increase the -fmax-stack-var-size=' limit, or change the code to use an\n ! ALLOCATABLE array. [-Wsurprising]\n integer, parameter :: nele = 100000\n#else\n integer, parameter :: nele = 10000000\n#endif\n real(dp), dimension(nele) :: big, buf\n real(dp) :: med\n integer :: i, istart, istop\n#endif\n\n LOGICAL :: isgood\n\n write(*,*) ''\n write(*,*) 'Test mo_percentile.f90'\n\n ! Double precision\n isgood = .true.\n dat = (/ 1., 2., 3., 4., 5., 6., 7., 8., 9., 10. /)\n dtmp = median(dat)\n isgood = isgood .and. eq(dtmp, 5.5_dp)\n dtmp = median(dat, mask=ne(dat, 10._dp))\n isgood = isgood .and. eq(dtmp, 5._dp)\n dtmp = n_element(dat, 4)\n isgood = isgood .and. eq(dtmp, 4._dp)\n dtmp = percentile(dat, 95._dp)\n isgood = isgood .and. eq(dtmp, 10._dp)\n dqua = percentile(dat, (/50._dp, 95._dp/))\n isgood = isgood .and. eq(dqua(1), 5._dp)\n isgood = isgood .and. eq(dqua(2), 10._dp)\n dqua = percentile(dat,(/50._dp, 75._dp/), mode_in=1_i4)\n dqua = percentile(dat,(/50._dp, 75._dp/), mode_in=3_i4)\n dqua = percentile(dat,(/50._dp, 75._dp/), mode_in=4_i4)\n dqua = percentile(dat,(/50._dp, 75._dp/), mode_in=5_i4)\n dqua = percentile(dat,(/50._dp, 75._dp/), mode_in=6_i4)\n dqua = percentile(dat,(/50._dp, 75._dp/), mode_in=7_i4)\n dqua = percentile(dat,(/50._dp, 75._dp/), mode_in=8_i4)\n dqua = percentile(dat,(/50._dp, 75._dp/), mode_in=2_i4)\n isgood = isgood .and. eq(dqua(1), 5._dp)\n isgood = isgood .and. eq(dqua(2), 7.5_dp)\n\n if (isgood) then\n write(*,*) 'mo_percentile double precision ', color('o.k.', c_green)\n else\n write(*,*) 'mo_percentile double precision ', color('failed!', c_red)\n endif\n\n ! Single precision\n isgood = .true.\n sat = (/ 1., 2., 3., 4., 5., 6., 7., 8., 9., 10. /)\n stmp = median(sat)\n isgood = isgood .and. eq(stmp, 5.5_sp)\n stmp = median(sat, mask=ne(sat, 10._sp))\n isgood = isgood .and. eq(stmp, 5._sp)\n stmp = n_element(sat,4)\n isgood = isgood .and. eq(stmp, 4._sp)\n stmp = percentile(sat,95._sp)\n isgood = isgood .and. eq(stmp, 10._sp)\n squa = percentile(sat,(/50._sp, 95._sp/))\n isgood = isgood .and. eq(squa(1), 5._sp)\n isgood = isgood .and. eq(squa(2), 10._sp)\n squa = percentile(sat,(/50._sp, 75._sp/), mode_in=2_i4)\n isgood = isgood .and. eq(squa(1), 5._sp)\n isgood = isgood .and. eq(squa(2), 7.5_sp)\n\n if (isgood) then\n write(*,*) 'mo_percentile single precision ', color('o.k.', c_green)\n else\n write(*,*) 'mo_percentile single precision ', color('failed!', c_red)\n endif\n\n! Absoft gives segmentation fault on all of the following test, do not know why\n#ifndef __ABSOFT__\n ! Test speed\n do i = 1, nele\n call random_number(big(i))\n enddo\n ! forall(i=1:nele) big(i) = real(i,dp)\n ! forall(i=1:nele/2) big(2*i) = real(i,dp)\n\n buf = big\n call system_clock(istart)\n med = median(buf)\n call system_clock(istop)\n write(*,*) \"median: \", med, istop - istart\n\n buf = big\n call system_clock(istart)\n med = n_element(buf,nele/2+1)\n call system_clock(istop)\n write(*,*) \"n_element: \", med, istop - istart\n\n buf = big\n call system_clock(istart)\n med = median(buf)\n call system_clock(istop)\n write(*,*) \"median: \", med, istop - istart\n\n buf = big\n call system_clock(istart)\n med = qmedian(buf)\n call system_clock(istop)\n write(*,*) \"qmedian: \", med, istop - istart\n\n buf = big\n call system_clock(istart)\n call sort(buf)\n med = buf(nele/2+1)\n call system_clock(istop)\n write(*,*) \"sort: \", med, istop - istart\n#endif\n\nEND PROGRAM main\n", "meta": {"hexsha": "ae3a51f07f18ea71d7279ff5b8637c773d1b0260", "size": 4377, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/test_mo_percentile/main.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_percentile/main.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_percentile/main.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.823943662, "max_line_length": 85, "alphanum_fraction": 0.6419922321, "num_tokens": 1618, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891130942472, "lm_q2_score": 0.8104788995148791, "lm_q1q2_score": 0.6663669275737399}} {"text": "! email: personal@auliakhalqillah.com\nprogram deretfibbonacci\n implicit none\n integer :: i,n \n real :: x,y,collect\n\n x = 0 ! deret pertama fibbonacci\n y = 1\n n = 10 ! banyak deret data yang dihasilkan\n write(*,*) 'Deret Fibbonacci'\n do i = 1,n\n write(*,*) x\n collect = x + y\n x = y\n y = collect\n end do \n\nend program\n", "meta": {"hexsha": "0d1d62722396e0f706272a0fce22851ce6e090f9", "size": 372, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "deretfibbonacci.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": "deretfibbonacci.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": "deretfibbonacci.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.5789473684, "max_line_length": 46, "alphanum_fraction": 0.564516129, "num_tokens": 125, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619177503206, "lm_q2_score": 0.8080672158638527, "lm_q1q2_score": 0.6662206464622743}} {"text": "module diffoperpack\n !========================================================================\n !\n ! DIFFOPERPACK\n ! \n !\n !\tPack with discrete differential operators routines\n ! for the geodesic sphere\n !\n !\tPedro da Silva Peixoto (pedrosp@ime.usp.br)\n !\tNov 2011\n !\n !========================================================================\n\n !Global kinds and constants\n use constants, only: &\n i4, &\n r8\n\n !Mesh and fields structures/types\n use datastruct, only: &\n grid_structure, &\n scalar_field, &\n rbf_matrix_structure, &\n vector_field_cart, &\n vector_variable_edge, &\n vectorinterpol_methods\n\n !Spherical mesh pack\n use smeshpack, only: &\n arclen, &\n cross_product, &\n insidetrmesh, &\n modint, &\n proj_vec_sphere\n\n !Interpolation pack\n use interpack, only: &\n rbfvec_matrix_build, &\n vec_remap_trc2ed, &\n vec_remap_trv2ed, &\n vec_remap_trv2trc, &\n vector_reconstruct\n\n implicit none\n\ncontains \n\n !========================================================================\n ! Discrete integral operators\n !========================================================================\n\n function int_simpson(s, f)\n !-----------------------------------------------\n ! Simpsons integral rule for 3 points on an arc\n ! not necessarily equally spaced\n ! s -> relative position between the points\n ! f -> values on points\n !-----------------------------------------------\n\n !Points positions on arc\n real (r8), intent(in) :: s(1:3)\n !Values of the function\n real (r8), intent(in) :: f(1:3)\n !Points positions \n real (r8):: int_simpson\n real (r8):: l\n real (r8):: l2\n real (r8):: l3\n\n !Aux\n real (r8):: g(1:3)\n real (r8):: a\n real (r8):: b\n real (r8):: c\n\n l=s(3)-s(1)\n l2=(s(3)*s(3)-s(1)*s(1))/2\n l3=( s(3)*s(3)*s(3)-s(1)*s(1)*s(1) )/3\n\n g(1)=f(1)/((s(1)-s(2))*(s(1)-s(3)))\n g(2)=f(2)/((s(2)-s(1))*(s(2)-s(3)))\n g(3)=f(3)/((s(3)-s(1))*(s(3)-s(2)))\n\n !int_{x=s1..s3} (a x^2 + b x + c)\n a=sum(g)\n b=-(g(1)*(s(2)+s(3))+ g(2)*(s(1)+s(3)) + g(3)*(s(1)+s(2)))\n c= g(1)*s(2)*s(3) + g(2)*s(1)*s(3) + g(3)*s(1)*s(2)\n !print*, \"s\", s\n !print*, \"f\", f\n !print*, \"a,b,c\",a, b, c\n !print*, \"ls\", l, l2, l3\n int_simpson=a*l3+b*l2+c*l\n\n return\n end function int_simpson\n\n function int_trp(s, f)\n !-----------------------------------------------\n ! Trapezoidal integral rule for 2 points on an arc\n ! s -> relative position between the points\n ! f -> values on points\n !-----------------------------------------------\n\n !Points positions on arc\n real (r8), intent(in) :: s(1:2)\n !Values of the function\n real (r8), intent(in) :: f(1:2)\n !Points positions \n real (r8):: int_trp\n\n int_trp=(s(2)-s(1))*(f(1)+f(2))/2\n\n return\n end function int_trp\n\n\n !========================================================================\n ! Discrete DIVERGENCE operators\n !========================================================================\n\n function div_cell_Cgrid(i, u, mesh)\n !-----------------------------------------------------------\n ! Given a the normal components of a vector field defined on edges\n ! calculates the numerical divergence based on Gauss Theorem\n ! Valid for C grids only\n !-----------------------------------------------------------\n ! i -> node if u%pos=3, tr if u%pos=2\n ! u -> scalarfield defined on Triangle or hexagon edges (normal comp only)\n ! mesh -> mesh structure\n !\n !-----------------------------------------------------------\n !Node for divergence calculation\n integer (i4), intent(in) :: i\n\n !Input variable with vectors\n type(scalar_field), intent(in) :: u\n\n real (r8):: div_cell_Cgrid\n\n !Mesh in which the variable belongs\n type(grid_structure), intent(in) :: mesh\n\n !Logical var for considering or not divergente average\n !That is, division or not by the cell area\n !logical, intent(in) :: average\n\n !Temp. vars\n real (r8):: divtmp\n real (r8):: signcor\n real (r8):: nrv\n !real (r8), allocatable :: vec(:)\n\n !Counters\n integer (i4):: j\n integer (i4):: k\n\n !Check if vectors on hexag/pent edges\n\n select case(u%pos)\n case(2)\n !For all edges forming the triangle\n divtmp=0_r8\n do j=1, 3\n !Get edge index\n k=mesh%tr(i)%ed(j)\n !print*, \"Edge:\", j\n !Get edge outer normal related to the hexagon\n signcor=real(mesh%tr(i)%nr(j), r8)\n !Calculate normal component\n nrv=signcor*u%f(k)\n !Calculate numerical integration\n divtmp=divtmp+nrv*mesh%ed(k)%leng\n end do\n !if(average)then\n !Averaged divergence (division by cell area)\n divtmp=divtmp/mesh%tr(i)%areag\n !end if\n case(3)\n !For all edges forming the hexagon\n divtmp=0._r8\n do j=1, mesh%v(i)%nnb\n !Get edge index\n k=mesh%v(i)%ed(j)\n !print*, \"Edge:\", j\n !Get edge outer normal related to the hexagon\n signcor=real(mesh%hx(i)%nr(j), r8)\n !Calculate normal component\n nrv=signcor*u%f(k) !dot_product(v%p(k)%v, mesh%edhx(k)%nr)\n !Calculate numerical integration\n divtmp=divtmp+nrv*mesh%edhx(k)%leng\n end do\n !if(average)then\n !Averaged divergence (division by cell area)\n divtmp=divtmp/mesh%hx(i)%areag\n !end if\n case(6)\n !For all edges forming the hexagon\n divtmp=0._r8\n do j=1, mesh%v(i)%nnb\n !Get edge index\n k=mesh%v(i)%ed(j)\n !print*, \"Edge:\", j\n !Get edge outer normal related to the hexagon\n signcor=real(mesh%hx(i)%ttgout(j), r8)\n !Calculate normal component\n nrv=signcor*u%f(k) !dot_product(v%p(k)%v, mesh%edhx(k)%nr)\n !Calculate numerical integration\n divtmp=divtmp+nrv*mesh%edhx(k)%leng\n end do\n !if(average)then\n !Averaged divergence (division by cell area)\n divtmp=divtmp/mesh%hx(i)%areag\n !end if\n case default\n print*, \"div_cell ERROR: Vectors not on hx or tr edges (pos=2,3, 6).\", u%pos\n stop\n end select\n\n !Assign returnable variable the result\n div_cell_Cgrid=divtmp\n\n return\n end function div_cell_Cgrid\n\n function grad_edge_Cgrid(ed, h, pos, mtd, mesh)\n !-----------------------------------------------------------\n ! Given a scalar field h calculates the gradient at edge \"ed\"\n ! with orietation depending on the position \"pos\" wanted\n !\n ! If pos=3 - normal to edhx edge is used as reference\n ! (velocities at midpoint of Voronoi cell edge)\n ! If pos=6 - tangent to ed is used as reference\n ! (velocities at intersection of triangle and Voronoi edges)\n !\n ! MTD - method to be used\n ! If mtd=\"trsk\" - use simple differences of values on cells that\n ! share the edge (2nd order only if pos=6)\n ! If mtd=\"bary\" - use gradient of barycentric coordinate\n ! (2nd order with pos = 3 and 6)\n ! *may affect mimetic properties\n !\n ! Valid for C grids only\n !-----------------------------------------------------------\n !Node for divergence calculation\n integer (i4), intent(in) :: ed\n\n !Position to put gradient\n integer (i4), intent(in) :: pos\n\n !Method to be used\n character (len=4), intent(in) :: mtd\n\n !Input variable with vectors\n type(scalar_field), intent(in) :: h\n\n real (r8):: grad_edge_Cgrid\n\n !Mesh in which the variable belongs\n type(grid_structure), intent(in) :: mesh\n\n !Logical var for considering or not divergente average\n !That is, division or not by the cell area\n !logical, intent(in) :: average\n\n !Temp. vars\n real (r8), dimension(1:3):: gradtmp\n real (r8), dimension(1:3):: vectmp\n real (r8):: signcor\n !real (r8):: nrv\n !real (r8), allocatable :: vec(:)\n integer(i4):: i, k\n\n !Check if vectors on hexag/pent edges\n\n select case(pos)\n case(3)\n if(trim(mtd)==\"trsk\")then\n signcor=dsign( 1._r8, dot_product(mesh%edhx(ed)%nr, &\n mesh%v(mesh%edhx(ed)%sh(2))%p-mesh%v(mesh%edhx(ed)%sh(1))%p ))\n grad_edge_Cgrid=signcor*(h%f(mesh%edhx(ed)%sh(2))-h%f(mesh%edhx(ed)%sh(1)))\n grad_edge_Cgrid=grad_edge_Cgrid/mesh%ed(ed)%leng\n\n elseif(trim(mtd)==\"bary\")then\n !Find triangle that cointains the midpoint of the edge\n if(insidetrmesh(mesh%edhx(ed)%c%p, mesh%edhx(ed)%v(1) , mesh))then\n k=mesh%edhx(ed)%v(1)\n elseif(insidetrmesh(mesh%edhx(ed)%c%p, mesh%edhx(ed)%v(2) , mesh))then\n k=mesh%edhx(ed)%v(2)\n else\n print*, \"grad_edge_Cgrid error:\"\n print*, \"Could not fit edge center into triangles\"\n stop\n end if\n !print*, ed, k\n\n !Calculate vector gradient of field using barycentric coords\n gradtmp=0.\n do i=1, 3\n !get vertices\n !j=mesh%tr(k)%v(i)\n !get edge indexes\n !m=modint(i+1, 3)\n !l=mesh%tr(k)%ed(m)\n !vectmp=-mesh%ed(l)%nr*mesh%tr(k)%nr(m)*mesh%ed(l)%leng*h%f(j)\n vectmp=mesh%v(mesh%tr(k)%v(modint(i+2, 3)))%p-mesh%v(mesh%tr(k)%v(modint(i+1, 3)))%p\n gradtmp=gradtmp+h%f(mesh%tr(k)%v(i))*&\n cross_product(mesh%edhx(ed)%c%p, vectmp)/mesh%tr(k)%areap/2._r8\n !print*, mesh%tr(k)%v(modint(i+2, 3)), mesh%tr(k)%v(modint(i+1, 3))\n end do\n gradtmp=proj_vec_sphere(gradtmp, mesh%edhx(ed)%c%p)\n grad_edge_Cgrid=dot_product(gradtmp, mesh%edhx(ed)%nr)\n end if\n\n case(6)\n ! Obs: the tangent of a triangle edge (which is used as normal\n ! of the voronoi cell edges) is always defined such\n ! that it point from its vertex 1 to its vertex 2\n ! Therefore, the gradient needs no correction term (n_ei)\n ! NOT normalized to earth radius\n grad_edge_Cgrid=(h%f(mesh%ed(ed)%v(2))-h%f(mesh%ed(ed)%v(1)))\n grad_edge_Cgrid=grad_edge_Cgrid/mesh%ed(ed)%leng\n case default\n print*, \"grad_edge_Cgrid ERROR: position not set for HX C gridon hx or tr edges (pos=3, 6).\"\n stop\n end select\n\n\n return\n end function grad_edge_Cgrid\n\n subroutine div_mesh_hx_trp(v, div, mesh)\n !-----------------------------------------------------------\n ! Given a vector variable defined on hexagonal edges\n ! calculates the numerical divergence based on Gauss Theorem\n !-----------------------------------------------------------\n !Variable with vectors on hexagonal corners (triang. cc)\n type(vector_field_cart), intent(in) :: v\n\n !Output variable for divergence in scalar variable defined on\n ! hexagon centers\n type(scalar_field), intent(inout) :: div\n\n !Mesh in which the variable belongs\n type(grid_structure), intent(in) :: mesh\n\n !Temp. vars\n real (r8):: divtmp\n real (r8):: sign\n real (r8), dimension(1:3) :: nr(1:3)\n real (r8), dimension(1:3) :: f(1:2)\n real (r8), dimension(1:3) :: s(1:2)\n\n !Counters\n integer (i4):: i\n integer (i4):: j\n integer (i4):: ed\n integer (i4):: tr(1:2)\n\n div%pos=0\n div%n=mesh%nv\n if(.not.allocated(div%f))then\n allocate(div%f(1:div%n))\n end if\n\n !call vec_edhx2trc_interpol(ved, v, mesh)\n\n !For all hexagons\n do i=1, mesh%nv\n !do i=8,8\n divtmp=0\n do j=1, mesh%v(i)%nnb \n\n !Get edge index\n ed=mesh%v(i)%ed(j)\n !print*,\"ed: \", ed\n\n !Get corners (triang circumcenters)\n tr=mesh%edhx(ed)%v\n !print*,\"tr: \", tr(1:2)\n\n !Sign correction for this hx edge\n sign=real(mesh%hx(i)%nr(j), r8)\n !print*,\"sign: \", sign\n\n !Get normal to edge with correction\n nr=sign*mesh%edhx(ed)%nr\n !print*,\"Normal: \", nr\n\n !Get first corner vector dot prod normal\n s(1)=0\n f(1)=dot_product(v%p(tr(1))%v, nr)\n !print*, \"V1:\", v%p(tr(1))%v\n !print*, \"s1, f1:\", s(1), f(1)\n\n !Get other corner vector dot prod normal\n s(2)=mesh%edhx(ed)%leng\n f(2)=dot_product(v%p(tr(2))%v, nr)\n\n divtmp=divtmp+int_trp(s, f)\n !divtmp=divtmp+(s(3)/6)*(f(1)+4*f(2)+f(3))\n !print*,\"simp:\", int_simpson(s, f)\n end do\n div%f(i)=divtmp/mesh%hx(i)%areag\n !print*, \"Hx:\", i, \"Div:\", divtmp\n end do\n\n end subroutine div_mesh_hx_trp\n\n subroutine div_mesh_hx_simp(ved, v, div, mesh)\n !-----------------------------------------------------------\n ! Given a vector variable defined on hexagonal edges\n ! calculates the numerical divergence based on Gauss Theorem\n !-----------------------------------------------------------\n !Input variable with vectors on hexagonal edges midpoints\n type(vector_variable_edge), intent(in) :: ved\n\n !Output variable for divergence in scalar variable defined on\n ! hexagon centers\n type(scalar_field), intent(inout) :: div\n\n !Mesh in which the variable belongs\n type(grid_structure), intent(in) :: mesh\n\n !Variable with vectors on hexagonal corners (triang. cc)\n type(vector_field_cart):: v\n\n !Temp. vars\n real (r8):: divtmp\n real (r8):: signc\n real (r8), dimension(1:3) :: nr(1:3)\n real (r8), dimension(1:3) :: f(1:3)\n real (r8), dimension(1:3) :: s(1:3)\n\n !Counters\n integer (i4):: i\n integer (i4):: j\n integer (i4):: ed\n integer (i4):: tr(1:2)\n\n div%pos=0\n div%n=mesh%nv\n if(.not.allocated(div%f))then\n allocate(div%f(1:div%n))\n end if\n\n !call vec_edhx2trc_interpol(ved, v, mesh)\n\n !For all hexagons\n do i=1, mesh%nv\n !do i=8,8\n divtmp=0\n do j=1, mesh%v(i)%nnb \n\n !Get edge index\n ed=mesh%v(i)%ed(j)\n !print*,\"ed: \", ed\n\n !Get corners (triang circumcenters)\n tr=mesh%edhx(ed)%v\n !print*,\"tr: \", tr(1:2)\n\n !Sign correction for this hx edge\n signc=real(mesh%hx(i)%nr(j), r8)\n !print*,\"sign: \", sign\n\n !Get normal to edge with correction\n nr=signc*mesh%edhx(ed)%nr\n !print*,\"Normal: \", nr\n\n !Get first corner vector dot prod normal\n s(1)=0\n f(1)=dot_product(v%p(tr(1))%v, nr)\n !print*, \"V1:\", v%p(tr(1))%v\n !print*, \"s1, f1:\", s(1), f(1)\n\n !Get edge's midpoint vector\n s(2)=arclen(mesh%tr(tr(1))%c%p, mesh%edhx(ed)%c%p)\n f(2)=signc*ved%nr(ed)\n !print*, \"s2, f2:\", s(2), f(2)\n\n !Get other corner vector dot prod normal\n s(3)=s(2)+arclen(mesh%edhx(ed)%c%p, mesh%tr(tr(2))%c%p)\n !print*, s(3)-s(2)-s(2)\n f(3)=dot_product(v%p(tr(2))%v, nr)\n !print*, \"V3:\", v%p(tr(2))%v\n !print*, \"s3, f:\", s(3), f(3)\n\n divtmp=divtmp+int_simpson(s, f)\n !divtmp=divtmp+(s(3)/6)*(f(1)+4*f(2)+f(3))\n !print*,\"simp:\", int_simpson(s, f)\n end do\n div%f(i)=divtmp/mesh%hx(i)%areag\n !print*, \"Hx:\", i, \"Div:\", divtmp\n end do\n\n end subroutine div_mesh_hx_simp\n\n ! subroutine divergence(v, div, mesh, average)\n ! !-----------------------------------------------------------\n ! ! Given a vector variable defined on either triangles' edges\n ! ! or hexagonals/pentagonals' edges calculates the numerical\n ! ! divergence average or integral based on Divergence Theorem\n ! !\n ! ! Input\n ! ! v -> vector variable defined on edges\n ! ! v%pos=0 -> triangle edges\n ! ! v%pos=1 -> hexag edges\n ! ! mesh -> mesh structure\n ! !\n ! !\n ! ! average = .true. -> Divides divergence cell integral by cell area\n ! ! average = .false. -> Don't divide by cell area\n ! !\n ! ! Output\n ! ! div -> divergence on triangle or hexagon centers\n ! ! div%pos=1 -> triangle centers\n ! ! div%pos=0 -> hexagon centers\n ! !-----------------------------------------------------------\n ! !Input variable with vectors on triangles edge's midpoints\n ! type(vector_variable_edge), intent(in) :: v\n !\n ! !Output variable for divergence in scalar variable defined on\n ! ! triangle centers\n ! type(interpolable_variable), intent(inout) :: div\n !\n ! !Mesh in which the variable belongs\n ! type(grid_structure), intent(in) :: mesh\n !\n ! !Logical var for considering or not divergente average\n ! !That is, division or not by the cell area\n ! logical, intent(in):: average\n !\n ! !Temp. vars\n ! real (r8):: divtmp\n ! real (r8):: signc\n ! real (r8):: a\n ! real (r8):: nrm\n ! !real (r8), allocatable :: vec(:)\n !\n ! !Counters\n ! integer (i4):: i\n ! integer (i4):: j\n ! integer (i4):: k\n !\n !\n ! if(v%pos==0)then\n ! !Vectors on triangles' edges\n !\n ! !Divergence positioned on triangle centres\n ! div%pos=1\n ! div%n=mesh%nt\n !\n ! !Allocate memory for divergence\n ! if(.not.allocated(div%f))then\n ! allocate(div%f(1:div%n))\n ! end if\n !\n ! !For all triangles\n ! do i=1, mesh%nt\n ! !For all edges forming the triangle\n ! divtmp=0_r8\n ! do j=1, 3\n ! !Get edge index\n ! k=mesh%tr(i)%ed(j)\n ! !Get edge outer normal related to the triangle\n ! signc=real(mesh%tr(i)%nr(j), r8)\n ! !Get the norm of the edge vector\n ! nrm=dsqrt((v%nr(k))**2+(v%tg(k))**2)\n ! !Calculate sin(alpha), angle between v%nr and edge tangent\n ! a=signc*v%nr(k)/nrm\n ! !Calculate numerical integral term\n ! divtmp=divtmp+signc*v%nr(k)*mesh%ed(k)%leng\n ! end do\n ! if(average)then\n ! !Averaged divergence (division by cell area)\n ! divtmp=divtmp/mesh%tr(i)%areag\n ! end if\n ! !Assign returnable variable the result\n ! div%f(i)=divtmp\n !\n ! end do\n ! else\n ! !Vectors on hexag/pent edges\n !\n ! !Divergence on triangle nodes/hexagon centers\n ! div%pos=0\n ! div%n=mesh%nv\n !\n ! !Allocate memory for divergence\n ! if(.not.allocated(div%f))then\n ! allocate(div%f(1:div%n))\n ! end if\n ! !For all hexagons\n ! do i=1, mesh%nv\n ! !For all edges forming the hexagon\n ! !print*, \"---- Hexagon:\", hx , \" ----\"\n ! divtmp=0_r8\n ! do j=1, mesh%v(i)%nnb\n ! !Get edge index\n ! k=mesh%v(i)%ed(j)\n ! !print*, \"Edge:\", j\n ! !Get the norm of the edge vector\n ! nrm=dsqrt((v%nr(k))**2+(v%tg(k))**2)\n ! !Get edge outer normal related to the hexagon\n ! signc=real(mesh%hx(i)%nr(j), r8)\n ! !Calculate sin(alpha), angle between v%nr and edge tangent\n ! a=signc*v%nr(k)/nrm\n ! !Calculate numerical integration\n ! divtmp=divtmp+signc*v%nr(k)*mesh%edhx(k)%leng\n ! end do\n ! if(average)then\n ! !Averaged divergence (division by cell area)\n ! divtmp=divtmp/mesh%hx(i)%areag\n ! end if\n ! !Assign returnable variable the result\n ! div%f(i)=divtmp\n ! end do\n ! end if\n !\n ! return\n ! end subroutine divergence\n\n function div_mesh_fullvec(v, mesh, cellopt, average)\n !-----------------------------------------------------------\n ! Given a vector variable (cartesian) calculates the numerical \n ! divergence average or integral based on Divergence Theorem\n !\n ! Input\n ! v -> vector variable defined \n ! mesh -> mesh structure\n ! cellopt -> Cell to use: \"TR\" or \"HX\"\n !\n ! Output\n ! div -> divergence estimates\n !-----------------------------------------------------------\n !Input variable with vectors\n type(vector_field_cart), intent(in) :: v\n\n !Output variable for divergence in scalar variable defined on\n type(scalar_field):: div_mesh_fullvec\n\n !Mesh in which the variable belongs\n type(grid_structure), intent(in) :: mesh\n\n !Cell to be used\n character (len=2), optional :: cellopt\n character (len=2):: cell\n\n !Logical var for considering or not divergente average\n !That is, division or not by the cell area\n ! Default is .true.\n logical, optional :: average\n logical:: av\n\n !Velocity field - aux\n type(vector_field_cart):: vtrc\n type(vector_field_cart):: ved\n\n !Set default values for optionals\n if(.not.present(cellopt))then\n cell=\"hx\"\n else\n cell=cellopt\n end if\n\n if(.not.present(average))then\n av=.true.\n else\n av=average\n end if\n\n if(cell==\"HX\" .or. cell==\"hx\")then\n\n !Calculate divergence based on the position of the given vectors\n\n select case (v%pos)\n case(0) !Vectors on tr vertices\n ! HA - Estimate Divergence NICAM method\n !Interpolate vector field on triangle circumcenters\n call vec_remap_trv2trc(v, vtrc, mesh)\n !Interpolate vector field to edges midpoints\n ved%pos=3 !Inform that vectors must be interpoalated to hx edge\n call vec_remap_trc2ed(vtrc, ved, mesh)\n !Estimate numerical divergence HA - NICAM Method\n call div_mesh_ed_fullvec(ved, div_mesh_fullvec, mesh, av)\n\n case (1) !HB !Vector on Tr circumcenters, or hx vertices\n !Interpolate vector field to edges midpoints\n ved%pos=3 !Inform that vectors must be interpoalated to hx edge\n call vec_remap_trc2ed(v, ved, mesh)\n !Estimate numerical divergence \n call div_mesh_ed_fullvec(ved, div_mesh_fullvec, mesh, av)\n\n case (3, 6) !HC !Vectors on hx edges\n !Directly estimate numerical divergence \n call div_mesh_ed_fullvec(v, div_mesh_fullvec, mesh, av)\n\n case default\n print*, \"div_mesh error - Don't know how to calculate with this vector position:\", v%pos, cell\n stop\n end select\n elseif(cell==\"TR\" .or. cell==\"tr\")then\n !Calculate divergence based on the position of the given vectors\n\n select case (v%pos)\n case(0) ! TB !Vectors on tr vertices\n !Interpolate vector field to edges midpoints\n call vec_remap_trv2ed(v, ved, mesh)\n\n !Estimate numerical divergence \n call div_mesh_ed_fullvec(ved, div_mesh_fullvec, mesh, av)\n\n case (1) ! TA !Vector on Tr circumcenters, or hx vertices\n !Interpolate vector field to tr vertices (nodes)\n ved%pos=2\n call vec_remap_trc2ed(v, ved, mesh)\n !Estimate numerical divergence \n call div_mesh_ed_fullvec(ved, div_mesh_fullvec, mesh, av)\n\n case (2) !TC !Vectors on TR edges\n !Directly estimate numerical divergence \n call div_mesh_ed_fullvec(v, div_mesh_fullvec, mesh, av)\n\n case default\n print*, \"div_mesh error - Don't know how to calculate with this vector position:\", v%pos, cell\n stop\n end select\n\n else\n print*, \"div_mesh error - Cell has not been properly given\", cell\n stop\n end if\n\n return\n end function div_mesh_fullvec\n\n function divho_mesh_fullvec(ved, mesh, discinterp_mtd, cellopt, average)\n !-----------------------------------------------------------\n ! Given a vector variable (cartesian) calculates the numerical\n ! divergence average or integral based on Divergence Theorem\n !\n ! Input\n ! ved -> vector field\n ! mesh -> mesh structure\n ! cellopt -> Cell to use: \"HX\"\n !\n ! Output\n ! divho_mesh -> divergence estimates\n !-----------------------------------------------------------\n !Input variable with scalars on Voronoi cell edge's midpoints\n type(vector_field_cart), intent(in) :: ved\n\n !Output variable for divergence in scalar variable defined on\n type(scalar_field):: divho_mesh_fullvec\n\n !Mesh in which the variable belongs\n type(grid_structure), intent(in) :: mesh\n\n !Inteprolation/Reconsgtruction method used for\n ! divergence/laplacian discretizations\n type(vectorinterpol_methods) :: discinterp_mtd\n\n !Normal components\n type(scalar_field):: vecncomp\n\n !Cell to be used\n character (len=2), optional :: cellopt\n character (len=2):: cell\n\n !Logical var for considering or not divergente average\n !That is, division or not by the cell area\n ! Default is .true.\n logical, optional :: average\n logical:: av\n\n !Velocity field - aux\n type(vector_field_cart):: vtrc\n\n !Aux point\n real(r8), dimension(1:3)::p\n\n !Index\n integer (i4):: i\n integer (i4):: j\n integer (i4):: k\n integer (i4):: l\n integer (i4):: n\n\n !Condition numbers\n real (r8):: condnummin\n real (r8):: condnummax\n\n !RBF matrix vector\n type(rbf_matrix_structure), allocatable :: rbf_mat(:)\n\n !RBF stencil and kind of interpolation\n character(len=4):: stencil\n\n !Set default values for optionals\n if(.not.present(cellopt))then\n cell=\"hx\"\n else\n cell=cellopt\n end if\n\n if(.not.present(average))then\n av=.true.\n else\n av=average\n end if\n\n if(discinterp_mtd%recon(1:3)==\"rbf\")then\n !If RBF, calculate the matrix structure (precalculation, depends only on mesh)\n condnummin=100000000.\n condnummax=0.\n stencil=trim(discinterp_mtd%recon(4:6))\n !Build rbf matrices\n call rbfvec_matrix_build( stencil, discinterp_mtd%rbf_par, rbf_mat, mesh)\n !Calculate condition number estimates\n n=size(rbf_mat)\n print*\n print*, \"Length of RBF matrices vector:\", n\n do i=1,n\n condnummin=min(condnummin,rbf_mat(i)%condnum)\n condnummax=max(condnummax,rbf_mat(i)%condnum)\n end do\n print*, \"Condition Number Estimates (min, max):\"\n print \"(2e12.3)\", condnummin, condnummax\n print*, \"Shape parameter:\"\n print*, discinterp_mtd%rbf_par\n print*\n end if\n\n if(cell==\"HX\" .or. cell==\"hx\")then\n\n !Calculate divergence based on the position of the given vectors\n select case (ved%pos)\n case (3) !HC !Vectors on hx edges\n\n !Reconstruct vector field to triangle circuncenters/\n ! Voronoi corners - based on alignement index\n vtrc%pos=1\n vtrc%n=mesh%nt\n allocate(vtrc%p(1:vtrc%n))\n\n !Divergence on triangle nodes/hexagon centers\n divho_mesh_fullvec%pos=0\n divho_mesh_fullvec%n=mesh%nv\n if(.not.allocated(divho_mesh_fullvec%f))then\n allocate(divho_mesh_fullvec%f(1:divho_mesh_fullvec%n))\n end if\n\n !Vectors normal comp on HX edges\n vecncomp%pos=3\n vecncomp%n=mesh%ne\n allocate(vecncomp%f(1:vecncomp%n))\n do i=1, mesh%ne\n vecncomp%f(i)=dot_product(ved%p(i)%v, mesh%edhx(i)%nr)\n end do\n l=0\n do i=1, mesh%nv\n !Check if cell is aligned\n if(mesh%hx(i)%align cartesian vector variable defined on tr or hx edges\n ! v%pos=2 -> triangle edges\n ! v%pos=3 -> hexag edges\n ! mesh -> mesh structure\n ! \n ! average = .true. -> Divides divergence cell integral by cell area\n ! average = .false. -> Don't divide by cell area\n !\n ! Output\n ! div -> divergence on triangle or hexagon centers \n ! div%pos=1 -> triangle centers\n ! div%pos=0 -> hexagon centers\n !-----------------------------------------------------------\n !Input variable with vectors on triangles edge's midpoints\n type(vector_field_cart), intent(in) :: v\n\n !Output variable for divergence in scalar variable defined on\n ! triangle centers\n type(scalar_field), intent(inout) :: div\n\n !Mesh in which the variable belongs\n type(grid_structure), intent(in) :: mesh\n\n !Logical var for considering or not divergente average\n !That is, division or not by the cell area\n logical, intent(in):: average\n\n !Counters\n integer (i4):: i\n\n if(v%pos==2)then\n !Vectors on triangles' edges\n\n !Divergence positioned on triangle centres\n div%pos=1\n div%n=mesh%nt\n\n !Allocate memory for divergence\n if(.not.allocated(div%f))then\n allocate(div%f(1:div%n))\n end if\n\n !For all triangles\n do i=1, mesh%nt\n !Assign returnable variable the result\n div%f(i)=div_cell_fullvec(i, v, mesh, average)\n end do\n else\n !Vectors on hexag/pent edges\n\n !Divergence on triangle nodes/hexagon centers\n div%pos=0\n div%n=mesh%nv\n\n !Allocate memory for divergence\n if(.not.allocated(div%f))then\n allocate(div%f(1:div%n))\n end if\n !For all hexagons\n do i=1, mesh%nv\n !Assign returnable variable the result\n div%f(i)=div_cell_fullvec(i, v, mesh, average)\n end do\n end if\n\n return\n end subroutine div_mesh_ed_fullvec\n\n function div_cell_fullvec(i, v, mesh, average)\n !-----------------------------------------------------------\n ! Given a cartesian vector variable the numerical \n ! divergence average or integral based on Divergence Theorem\n !\n ! i -> node if v%pos=3, tr if v%pos=2\n ! v -> vector variable defined on Triangle or hexagon edges !!!\n ! mesh -> mesh structure\n !\n !-----------------------------------------------------------\n !Node for divergence calculation\n integer (i4), intent(in) :: i\n\n !Input variable with vectors \n type(vector_field_cart), intent(in) :: v\n\n real (r8):: div_cell_fullvec\n\n !Mesh in which the variable belongs\n type(grid_structure), intent(in) :: mesh\n\n !Logical var for considering or not divergente average\n !That is, division or not by the cell area\n logical, intent(in) :: average\n\n !Temp. vars\n real (r8):: divtmp\n real (r8):: signcor\n real (r8):: nrv\n !real (r8), allocatable :: vec(:)\n\n !Counters\n integer (i4):: j\n integer (i4):: k\n\n !Check if vectors on hexag/pent edges\n\n select case(v%pos)\n case(2)\n !For all edges forming the triangle\n divtmp=0_r8\n do j=1, 3\n !Get edge index\n k=mesh%tr(i)%ed(j)\n !print*, \"Edge:\", j\n !Get edge outer normal related to the hexagon\n signcor=real(mesh%tr(i)%nr(j), r8)\n !Calculate normal component\n nrv=signcor*dot_product(v%p(k)%v, mesh%ed(k)%nr)\n !Calculate numerical integration\n divtmp=divtmp+nrv*mesh%ed(k)%leng\n end do\n if(average)then\n !Averaged divergence (division by cell area)\n divtmp=divtmp/mesh%tr(i)%areag\n end if\n case(3)\n !For all edges forming the hexagon\n divtmp=0._r8\n do j=1, mesh%v(i)%nnb \n !Get edge index\n k=mesh%v(i)%ed(j)\n !print*, \"Edge:\", j\n !Get edge outer normal related to the hexagon\n signcor=real(mesh%hx(i)%nr(j), r8)\n !Calculate normal component\n nrv=signcor*dot_product(v%p(k)%v, mesh%edhx(k)%nr)\n !Calculate numerical integration\n divtmp=divtmp+nrv*mesh%edhx(k)%leng\n end do\n if(average)then\n !Averaged divergence (division by cell area)\n divtmp=divtmp/mesh%hx(i)%areag\n end if\n case(6)\n !For all edges forming the hexagon\n divtmp=0._r8\n do j=1, mesh%v(i)%nnb\n !Get edge index\n k=mesh%v(i)%ed(j)\n !print*, \"Edge:\", j\n !Get edge outer normal related to the hexagon\n signcor=real(mesh%hx(i)%ttgout(j), r8)\n !Calculate normal component\n nrv=signcor*dot_product(v%p(k)%v, mesh%ed(k)%tg)\n !Calculate numerical integration\n divtmp=divtmp+nrv*mesh%edhx(k)%leng\n end do\n\n if(average)then\n !Averaged divergence (division by cell area)\n divtmp=divtmp/mesh%hx(i)%areag\n end if\n case default\n print*, \"div_cell ERROR: Vectors not on hx or tr edges (pos=2,3, 6).\", v%pos\n stop\n end select\n\n !Assign returnable variable the result\n div_cell_fullvec=divtmp \n\n return\n end function div_cell_fullvec\n\n function divho_cell_fullvec(i, ved, vtrc, mesh, average)\n !-----------------------------------------------------------\n ! Given a cartesian vector variable the numerical\n ! divergence average or integral based on Divergence Theorem\n !\n ! i -> node (v%pos=3)\n ! ved -> vector variable defined on hexagon edges !!!\n ! vtrc -> vector variable defined on triangle circuncenters !!!\n ! mesh -> mesh structure\n !\n !-----------------------------------------------------------\n !Node for divergence calculation\n integer (i4), intent(in) :: i\n\n !Input variable with vectors\n type(vector_field_cart), intent(in) :: ved\n type(vector_field_cart), intent(in) :: vtrc\n\n real (r8):: divho_cell_fullvec\n\n !Mesh in which the variable belongs\n type(grid_structure), intent(in) :: mesh\n\n !Logical var for considering or not divergente average\n !That is, division or not by the cell area\n logical, intent(in) :: average\n\n !Counters\n integer (i4):: j\n !integer (i4):: k\n integer (i4):: ed\n integer (i4):: tr(1:2)\n\n !Temp. vars\n real (r8):: divtmp\n real (r8):: signc\n !real (r8):: nrv\n real (r8), dimension(1:3) :: nr(1:3)\n real (r8), dimension(1:3) :: f(1:3)\n real (r8), dimension(1:3) :: s(1:3)\n\n\n !Check if vectors on hexag/pent edges\n if(ved%pos==3)then\n !For all edges forming the hexagon\n divtmp=0._r8\n do j=1, mesh%v(i)%nnb\n\n !Get edge index\n ed=mesh%v(i)%ed(j)\n !print*,\"ed: \", ed\n\n !Get corners (triang circumcenters)\n tr=mesh%edhx(ed)%v\n !print*,\"tr: \", tr(1:2)\n\n !Sign correction for this hx edge\n signc=real(mesh%hx(i)%nr(j), r8)\n !print*,\"sign: \", sign\n\n !Get normal to edge with correction\n nr=signc*mesh%edhx(ed)%nr\n !print*,\"Normal: \", nr\n\n !Get first corner vector dot prod normal\n s(1)=0\n f(1)=dot_product(vtrc%p(tr(1))%v, nr)\n !print*, \"V1:\", v%p(tr(1))%v\n !print*, \"s1, f1:\", s(1), f(1)\n\n !Get edge's midpoint vector\n s(2)=arclen(mesh%tr(tr(1))%c%p, mesh%edhx(ed)%c%p)\n f(2)=dot_product(ved%p(ed)%v, nr)\n !print*, \"s2, f2:\", s(2), f(2)\n\n !Get other corner vector dot prod normal\n s(3)=s(2)+arclen(mesh%edhx(ed)%c%p, mesh%tr(tr(2))%c%p)\n !print*, s(3)-s(2)-s(2)\n f(3)=dot_product(vtrc%p(tr(2))%v, nr)\n !print*, \"V3:\", v%p(tr(2))%v\n !print*, \"s3, f:\", s(3), f(3)\n\n divtmp=divtmp+int_simpson(s, f)\n !divtmp=divtmp+(s(3)/6)*(f(1)+4*f(2)+f(3))\n !print*,\"simp:\", int_simpson(s, f)\n end do\n if(average)then\n !Averaged divergence (division by cell area)\n divtmp=divtmp/mesh%hx(i)%areag\n end if\n else\n print*, \"div_cell ERROR: Vectors not on hx edges (pos=3).\", ved%pos\n stop\n end if\n\n !Assign returnable variable the result\n divho_cell_fullvec=divtmp\n\n return\n end function divho_cell_fullvec\n\nend module diffoperpack\n", "meta": {"hexsha": "2e80fac681a518cf34d0d1b7a4d0dd78f8f7d433", "size": 36927, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/diffoperpack.f90", "max_stars_repo_name": "luanfs/iModel", "max_stars_repo_head_hexsha": "8dd39e3564b6bc01df8dfe417493d9c7b22c40a8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2015-10-09T17:44:51.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-10T01:56:33.000Z", "max_issues_repo_path": "src/diffoperpack.f90", "max_issues_repo_name": "luanfs/iModel", "max_issues_repo_head_hexsha": "8dd39e3564b6bc01df8dfe417493d9c7b22c40a8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-08-29T11:49:32.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-18T18:07:53.000Z", "max_forks_repo_path": "src/diffoperpack.f90", "max_forks_repo_name": "luanfs/iModel", "max_forks_repo_head_hexsha": "8dd39e3564b6bc01df8dfe417493d9c7b22c40a8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2016-03-18T19:24:56.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-01T10:38:57.000Z", "avg_line_length": 31.3738317757, "max_line_length": 104, "alphanum_fraction": 0.5497874184, "num_tokens": 10739, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467770088162, "lm_q2_score": 0.7577943822145998, "lm_q1q2_score": 0.6662124887593524}} {"text": "SUBROUTINE fmacat(vmfl,acat)\n!\n! This subroutine sets up an intermediate matrix acat.\n!\n IMPLICIT NONE\n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\n REAL(iwp),INTENT(IN)::vmfl(:)\n REAL(iwp),INTENT(OUT)::acat(:,:)\n REAL(iwp)::temp(4,4),zero=0.0_iwp,pt5=0.5_iwp,one=1.0_iwp,three=3.0_iwp\n INTEGER::i,j\n temp=zero\n temp(1,1)=one\n temp(1,2)=-pt5\n temp(1,4)=-pt5\n temp(2,1)=-pt5\n temp(2,2)=one\n temp(2,4)=-pt5\n temp(3,3)=three\n temp(4,1)=-pt5\n temp(4,2)=-pt5\n temp(4,4)=one\n DO i=1,4\n DO j=1,4\n acat(i,j)=vmfl(i)*vmfl(j)\n END DO\n END DO\n acat=temp-acat\nRETURN \nEND SUBROUTINE fmacat\n", "meta": {"hexsha": "1e35a5fa805965b5f78abb9cd8ccdc616ba1dd44", "size": 588, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "main/fmacat.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/fmacat.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/fmacat.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": 19.6, "max_line_length": 72, "alphanum_fraction": 0.6666666667, "num_tokens": 266, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467801752451, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6662124815410244}} {"text": "C Copyright(C) 1999-2020 National Technology & Engineering Solutions\nC of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with\nC NTESS, the U.S. Government retains certain rights in this software.\nC\nC See packages/seacas/LICENSE for details\n\nC -*- Mode: fortran -*-\nC=======================================================================\n SUBROUTINE SPOFF (XN, YN, ZN, NSPL, ZS, XS, XS2, YS, YS2,\n & SLTOP, SLBOT, NUMNP, NDIM )\nC=======================================================================\n\nC --*** SPLXYZ *** (GEN3D) Calculate 3D coordinates for Spline projection\nC -- Written by Amy Gilkey - revised 05/09/88\nC -- Modified by Greg Sjaardema - 02/06/89\nC --\nC --WRPXYZ calculates the coordinate array for the 3D warp translations.\nC --\nC --Parameters:\nC -- XN, YN, ZN - IN/OUT - the coordinates, modified\nC -- NSPL - Number of points on spline curve\nC -- ZS, XS, YS - IN - spline point coordinates\nC -- XS2, YS2 - spline slopes\nC -- SLTOP, SLBOT - slopes at top and bottom of spline\nC -- NUMNP - number of nodal points\nC -- NDIM - spatial dimension (2 or 3)\nC --\n\n REAL XN(*), YN(*), ZN(*)\n REAL ZS(NSPL), XS(NSPL), XS2(NSPL), YS(NSPL), YS2(NSPL)\n REAL SLTOP(2), SLBOT(2)\n\nC$$$ CALL RDSPLN (.TRUE., NDB, SLTOP, SLBOT, NSPL, ZS, XS, YS)\n\n CALL SPLINE (ZS, XS, NSPL, SLTOP(1), SLBOT(1), XS2)\n CALL SPLINE (ZS, YS, NSPL, SLTOP(2), SLBOT(2), YS2)\n\n KLO = 1\n\n DO 80 INP = 1, NUMNP\n Z = ZN(INP)\n CALL HUNT (ZS, NSPL, Z, KLO)\n IF (KLO .EQ. NSPL) KLO = KLO - 1\n IF (KLO .EQ. 0) KLO = KLO + 1\n\n H = ZS(KLO+1) - ZS(KLO)\n A = (ZS(KLO+1)-Z)/H\n B = (Z-ZS(KLO))/H\n\n XOFF = A * XS(KLO) + B * XS(KLO+1) +\n * ((A**3-A) * XS2(KLO)+(B**3-B)*XS2(KLO+1)) * (H**2) / 6.\n\n YOFF = A * YS(KLO) + B * YS(KLO+1) +\n * ((A**3-A) * YS2(KLO)+(B**3-B)*YS2(KLO+1)) * (H**2) / 6.\n\n XN(INP) = XN(INP) + XOFF\n YN(INP) = YN(INP) + YOFF\n 80 CONTINUE\n\n RETURN\n END\n", "meta": {"hexsha": "26ead1be0dd376b7bccc20b1d456c24721381247", "size": 2117, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "packages/seacas/applications/grepos/gp_spoff.f", "max_stars_repo_name": "jschueller/seacas", "max_stars_repo_head_hexsha": "14c34ae08b757cba43a3a03ec0f129c8a168a9d3", "max_stars_repo_licenses": ["Python-2.0", "Zlib", "BSD-2-Clause", "MIT", "NetCDF", "BSL-1.0", "X11", "BSD-3-Clause"], "max_stars_count": 82, "max_stars_repo_stars_event_min_datetime": "2016-02-04T18:38:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T03:01:49.000Z", "max_issues_repo_path": "packages/seacas/applications/grepos/gp_spoff.f", "max_issues_repo_name": "jschueller/seacas", "max_issues_repo_head_hexsha": "14c34ae08b757cba43a3a03ec0f129c8a168a9d3", "max_issues_repo_licenses": ["Python-2.0", "Zlib", "BSD-2-Clause", "MIT", "NetCDF", "BSL-1.0", "X11", "BSD-3-Clause"], "max_issues_count": 206, "max_issues_repo_issues_event_min_datetime": "2015-11-20T01:57:47.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:12:04.000Z", "max_forks_repo_path": "packages/seacas/applications/grepos/gp_spoff.f", "max_forks_repo_name": "jschueller/seacas", "max_forks_repo_head_hexsha": "14c34ae08b757cba43a3a03ec0f129c8a168a9d3", "max_forks_repo_licenses": ["Python-2.0", "Zlib", "BSD-2-Clause", "MIT", "NetCDF", "BSL-1.0", "X11", "BSD-3-Clause"], "max_forks_count": 68, "max_forks_repo_forks_event_min_datetime": "2016-01-13T22:46:51.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T06:25:05.000Z", "avg_line_length": 34.1451612903, "max_line_length": 77, "alphanum_fraction": 0.5007085498, "num_tokens": 769, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381605, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6661972545635738}} {"text": "! ---------------------------------------------------- !\n! Set up LU diagonalizzazione filtro !\n! F. Califano, Marzo 2001 !\n! ---------------------------------------------------- !\n! A (f_i-1 + f_i+1) + f_i = a_filt f_i + !\n! b_filt (f_i-1 + f_i+1) + c_filt (f_i-2 + f_i+2) ! \n! ---------------------------------------------------- !\n\n subroutine init_filtro_open_x\n\nuse box_mod\nuse parameter_mod\nuse filtro_open_mod\n\nIMPLICIT NONE\n\n! --------------------------------- !\n! *** Set up filtro Compatto !\n! *** Parametri solver tridiagonale !\n! --------------------------------- !\n\n TARNS = 'N'\n info = 0\n lrhs = 1\n ldb = nx\n\n! Parametro filtraggio\n\n! FILTRO IV ordine: R.H.S. coefficients of the tridiag. filter\n! Lele 1992, pag. 40, C.2.4\n\n !a_filt = (5.0d0 + 6.0d0 * omega_x) / 8.0d0\n !b_filt = (1.0d0 + 2.0d0 * omega_x) / 4.0d0\n !c_filt = - (1.0d0 - 2.0d0 * omega_x) / 16.0d0\n !d_filt = 0.0d0\n\n! FILTRO VI ordine: R.H.S. coefficients of the tridiag. filter\n! Lele 1992, pag. 40, C.2.5\n\n a_filt = (11.0d0 + 10.0d0 * omega_x) / 16.0d0\n b_filt = (15.0d0 + 34.0d0 * omega_x) / 64.0d0\n c_filt = (- 3.0d0 + 6.0d0 * omega_x) / 32.0d0\n d_filt = ( 1.0d0 - 2.0d0 * omega_x) / 64.0d0\n\n! R.H.S boundary conditions coefficients\n\n a11_filt = 15.0d0 / 16.0d0\n a12_filt = 1.0d0 / 4.0d0\n a13_filt = - 3.0d0 / 8.0d0\n a14_filt = 1.0d0 / 4.0d0\n a15_filt = - 1.0d0 / 16.0d0\n\n a21_filt = 1.0d0/ 16.0d0\n a22_filt = 3.0d0 / 4.0d0\n a23_filt = 3.0d0 / 8.0d0\n a24_filt = - 1.0d0 / 4.0d0\n a25_filt = 1.0d0/ 16.0d0\n\n a31_filt = - 1.0d0/ 16.0d0\n a32_filt = 1.0d0 / 4.0d0\n a33_filt = 5.0d0 / 8.0d0\n a34_filt = 1.0d0 / 4.0d0\n a35_filt = - 1.0d0/ 16.0d0\n\n! Diagonale filt_d, sotto diagonale filt_m e super diagonale filt_p\n! (filt_2 e' un working array)\n\n filt_d = 1.0\n\n filt_p = omega_x\n filt_m = omega_x\n\n filt_p(1) = 0.0\n filt_m(nx1) = 0.0\n\n! Filtro R.H.S boundary conditions coefficients: \n! f(x) unchanged at i = 1, 2 and the same on the right OR\n! f(x) Lele boundary conditions at i = 1, 2 and the same on the right\n\n filt_m(1) = 0.0\n filt_p(2) = 0.0\n filt_m(nx2) = 0.0\n filt_p(nx1) = 0.0\n\n! f(x) unchanged also at i = 3 and the same on the right OR\n! f(x) Lele boundary conditions also at i = 3 and the same on the right\n\n filt_m(2) = 0.0\n filt_p(3) = 0.0\n filt_m(nx3) = 0.0\n filt_p(nx2) = 0.0\n\n! Working array\n\n filt_2 = 0.0\n\n! Fattorizzazione LU\n\n CALL DGTTRF(nx, filt_m, filt_d, filt_p, filt_2, ipv_f, info)\n\n if (info > 0 .or. info < 0) then\n write(*,*) 'Problemi fattorizzazione LU, Filtro: info:', info\n stop\n endif\n\n end subroutine\n", "meta": {"hexsha": "a5a9e12c113fc653fdccd3e54248af84a55c1361", "size": 2975, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "init_filtro_open_x.f90", "max_stars_repo_name": "sscerr/eTF", "max_stars_repo_head_hexsha": "31dea18c7b24b3ebbb6bdfea98467ffbf79f0852", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-02T04:11:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-02T04:11:49.000Z", "max_issues_repo_path": "init_filtro_open_x.f90", "max_issues_repo_name": "sscerr/eTF", "max_issues_repo_head_hexsha": "31dea18c7b24b3ebbb6bdfea98467ffbf79f0852", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "init_filtro_open_x.f90", "max_forks_repo_name": "sscerr/eTF", "max_forks_repo_head_hexsha": "31dea18c7b24b3ebbb6bdfea98467ffbf79f0852", "max_forks_repo_licenses": ["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.8037383178, "max_line_length": 74, "alphanum_fraction": 0.4917647059, "num_tokens": 1170, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391706552538, "lm_q2_score": 0.7217432062975979, "lm_q1q2_score": 0.6661972505669985}} {"text": " SUBROUTINE VECM50GAL(KEY,VECIN,VECOUT)\n IMPLICIT REAL*8 (A-H,O-Z)\nC\nC THIS ROUTINE ROTATES CARTERSIAN VECTORS BETWEEN THE MEAN OF 1950.0\nC COORDINATE SYSTEM AND THE GALACTIC COORDINATE SYSTEM. BOTH ARE\nC GEOCENTRIC.\nC\nC THE GALACTIC POLE AND GALACTIC CENTER DIRECTIONS ARE TAKEN FROM THE\nC TEXT 'ASTRONOMY' BY L W FREDRICK, 9TH EDITION, 1971. VALUES VERIFIED\nC FROM OTHER SOURCES. THE DIRECTIONS ARE THOSE DECIDED UPON BY THE\nC INTERNATIONAL ASTRONOMICAL UNION IN 1958.\nC\nC VARIABLE DIM TYPE I/O DESCRIPTION\nC -------- --- ---- --- -----------\nC\nC KEY 1 I*4 I FLAG INDICATING THE 'FROM' AND 'TO' COORDINATE\nC SYSTEMS.\nC\nC = NEGATIVE, FROM GALACTIC TO 1950.0\nC = OTHERWISE, FROM 1950.0 TO GALACTIC\nC\nC VECIN 3 R*8 I THE VECTOR IN THE 'FROM' SYSTEM. ANY UNITS.\nC\nC VECOUT 3 R*8 O THE VECTOR IN THE 'TO' SYSTEM. SAME UNITS AS\nC VECIN. IN THE CALLING PROGRAM, VECIN AND VECOUT\nC MAY BE THE SAME ARRAY.\nC\nC***********************************************************************\nC\nC BY C PETRUZZO, GSFC/742, 12/84.\nC MODIFIED.....\nC\nC***********************************************************************\nC\n REAL*8 HALFPI / 1.570796326794897D0 /\n REAL*8 PI / 3.141592653589793D0 /\n REAL*8 TWOPI / 6.283185307179586D0 /\n REAL*8 DEGRAD / 57.29577951308232D0 /\n REAL*8 DEGHR/15.D0/\n INTEGER INIT/1/\n REAL*8 GCENTER(3),XGALACT(3),YGALACT(3),ZGALACT(3)\n REAL*8 GALM50(3,3),M50GAL(3,3),VECIN(3),VECOUT(3)\nC\nC *******************************\nC * ONCE-PER-RUN INITIALIZATION *\nC *******************************\nC\n IF(INIT.EQ.1) THEN\n INIT = 0\nC\nC ZRA,ZDEC GIVES THE DIRECTION OF THE GALACTIC NORTH POLE.\n ZRA = (12.D0 + 49.D0/60.D0)*DEGHR/DEGRAD ! = 12H, 49M\n ZDEC = 27.4D0/DEGRAD ! = 27.4 DEG\nC\nC CRA,CDEC GIVES THE DIRECTION TO GALACTIC CENTER WHICH IS ON\nC THE ON THE X-AXIS.\n CRA = (17.D0 + 42.4D0/60.D0)*DEGHR/DEGRAD ! = 17H, 42.4M\n CDEC = -(28.D0 + 55.D0/60.D0)/DEGRAD ! = -28 DEG, 55 MIN\nC\nC GET GALACTIC SYSTEM AXES RELATIVE TO THE 1950.0 COORDINATE SYSTEM\n CALL XYZSPH(1,CRA,CDEC,1.D0,GCENTER,1.D0) ! 89.9919 DEG FROM Z.\n CALL XYZSPH(1,ZRA,ZDEC,1.D0,ZGALACT,1.D0)\n CALL UCROSS(ZGALACT,GCENTER,YGALACT)\n CALL UCROSS(YGALACT,ZGALACT,XGALACT)\nC\nC SET THE MATRIX TAKING VECTOR COORDS FROM 1950.0 TO GALACTIC\n DO 10 I=1,3\n M50GAL(I,1) = XGALACT(I)\n M50GAL(I,2) = YGALACT(I)\n 10 M50GAL(I,3) = ZGALACT(I)\nC\nC SET THE MATRIX TAKING VECTORS FROM GALACTIC COORDS TO 1950.0\n CALL MTXFLIP33(M50GAL,GALM50)\nC\n END IF\nC\nC\nC ***********************\nC * ROTATATE THE VECTOR *\nC ***********************\nC\n IF(KEY.LT.0) THEN\nC FROM GALACTIC TO 1950.0\n CALL VECROT(M50GAL,VECIN,VECOUT)\nC\n ELSE\nC FROM 1950.0 TO GALACTIC\n CALL VECROT(GALM50,VECIN,VECOUT)\n END IF\nC\nC\n RETURN\n END\n", "meta": {"hexsha": "028a16276e9e5c5c72a81dc6be025c43c9e0746d", "size": 3078, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "gsc-13083/vecm50gal.for", "max_stars_repo_name": "SteveDoyle2/nasa-cosmic", "max_stars_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_stars_repo_licenses": ["BSD-Source-Code"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2015-03-14T07:26:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-16T12:23:17.000Z", "max_issues_repo_path": "gsc-13083/vecm50gal.for", "max_issues_repo_name": "SteveDoyle2/nasa-cosmic", "max_issues_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_issues_repo_licenses": ["BSD-Source-Code"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gsc-13083/vecm50gal.for", "max_forks_repo_name": "SteveDoyle2/nasa-cosmic", "max_forks_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_forks_repo_licenses": ["BSD-Source-Code"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2016-02-12T22:18:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-08T17:46:54.000Z", "avg_line_length": 32.7446808511, "max_line_length": 72, "alphanum_fraction": 0.5604288499, "num_tokens": 1121, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391664210672, "lm_q2_score": 0.7217432062975979, "lm_q1q2_score": 0.6661972475110032}} {"text": "C==============================================================================\nc transforms from (line,sample) to (latitude,longitude) for a\nc perspective projection camera system. an oblate spheroid model of the\nc planet (re,rp) is used. all angles are in radians. planetocentric\nc latitudes and east-longitudes are used.\nc\nc inputs:\nc rline,rsamp : input image coordinates\nc om\t : camera to planet transformation matrix\nc psc3 : spacecraft vector in (x3,y3,z3) coordinates, where\nc\t\t : psc3(1) = rsc*dcos(sclat)\nc\t\t : psc3(2) = 0.0d0\nc\t\t : psc3(3) = rsc*dsin(sclat)\nc sclon : spacecraft longitude\nc re : planet's equatorial radius (km)\nc epsln\t : planet eccentricity = (re/rp)**2\nc epsln2 : constant = psc3(1)**2 + epsln*psc3(3)**2 - re**2\nc oal,oas : image coordinates of optical axis intercept point\nc zscale : camera constant = fl*pscale\nc\nc outputs:\nc ind :\tind=1 if resulting (rlat,rlon) are valid\nc\t\t :\tind=0 if point is off the planet\nc rlat,rlon : computed planet coordinates.\nC==============================================================================\n subroutine planet(ind,rline,rsamp,rlat,rlon,\n & om,psc3,sclon,re,epsln,epsln2,oal,oas,zscale)\n IMPLICIT NONE\n integer ind\n real*8 rline,rsamp,rlat,rlon,om(3,3),psc3(3),re,epsln,epsln2,\n + oal,oas,zscale\n\n real*8 sclon,ux0,uy0,uz0,ux3,uy3,uz3,a,b,d,r,x,y,z\n real*8 pi/3.141592653589793d0/\n\nc vector from spacecraft to point on planet in camera coordinate system\n ux0 = rsamp - oas\n uy0 = rline - oal\n uz0 = zscale\nc convert vector to planet coordinate system (x3,y3,z3)\n ux3 = om(1,1)*ux0 + om(1,2)*uy0 + om(1,3)*uz0\n uy3 = om(2,1)*ux0 + om(2,2)*uy0 + om(2,3)*uz0\n uz3 = om(3,1)*ux0 + om(3,2)*uy0 + om(3,3)*uz0\nc find where vector intersects planet\n a = ux3**2 + uy3**2 + epsln*uz3**2\n b = ux3*psc3(1) + epsln*uz3*psc3(3)\n d = b*b - a*epsln2\n if(d.lt.0.) then\n ind = 0\t\t!point off the planet\n return\n endif\n r = (-b-dsqrt(d))/a\t!choose smaller root for point in front\nc\n x = r*ux3 + psc3(1)\n y = r*uy3\n z = r*uz3 + psc3(3)\n d = dsqrt(x**2+y**2)\n rlat = datan2(z,d)\n rlon = dmod(datan2(y,x)+sclon+2.d0*pi,2.d0*pi)\n ind = 1\n return\n end\n\nC==============================================================================\nc transforms from (latitude,longitude) to (line,sample) in a\nc perspective projection camera system. an oblate spheroid model of the\nc planet (re,rp) is used. all angles are in radians. planetocentric\nc latitudes and east-longitudes are used.\nc\nc inputs:\nc rlat,rlon : input planet coordinates.\nc om\t : camera to planet transformation matrix\nc psc3 : spacecraft vector in (x3,y3,z3) coordinates, where\nc\t\t : psc3(1) = rsc*dcos(sclat)\nc\t\t : psc3(2) = 0.0d0\nc\t\t : psc3(3) = rsc*dsin(sclat)\nc sclon : spacecraft longitude\nc re : planet's equatorial radius (km)\nc epsln\t : planet eccentricity = (re/rp)**2\nc epsln2 : constant = psc3(1)**2 + epsln*psc3(3)**2 - re**2\nc oal,oas : image coordinates of optical axis intercept point\nc zscale : camera constant = fl*pscale\nc\nc outputs:\nc ind : ind=1 if resulting (rline,rsamp) are valid\nc : ind=0 if point is behind the planet\nc rline,rsamp : computed image coordinates\nC==============================================================================\n subroutine plainv(ind,rlat,rlon,rline,rsamp,\n & om,psc3,sclon,re,epsln,epsln2,oal,oas,zscale)\n IMPLICIT NONE\n integer ind\n real*8 rlat,rlon,rline,rsamp,om(3,3),psc3(3),sclon,re,\n + epsln,epsln2,oal,oas,zscale\n\n real*8 clat,r,ux3,uy3,uz3,a,b,d,ux0,uy0,uz0,s\n\n clat = dcos(rlat)\n r = re/dsqrt((1-epsln)*clat**2+epsln)\t!geocentric radius\nc compute vector from camera to point on planet\n ux3 = r*clat*dcos(rlon-sclon) - psc3(1)\n uy3 = r*clat*dsin(rlon-sclon)\n uz3 = r*dsin(rlat) - psc3(3)\nc back-of-planet test\n a = ux3**2 + uy3**2 + epsln*uz3**2\n b = ux3*psc3(1) + epsln*uz3*psc3(3)\n d = b*b - a*epsln2\n if(d.gt.0.) then\n r = (-b-dsqrt(d))/a\n if (r.lt.0.99999d0) then\n ind = 0\t\t\t!point behind the planet\n return\n endif\n endif\nc rotate vector into camera coordinates\n ux0 = om(1,1)*ux3 + om(2,1)*uy3 + om(3,1)*uz3\n uy0 = om(1,2)*ux3 + om(2,2)*uy3 + om(3,2)*uz3\n uz0 = om(1,3)*ux3 + om(2,3)*uy3 + om(3,3)*uz3\nc scale vector into pixels\n s = zscale/uz0\n rline = s*uy0 + oal\n rsamp = s*ux0 + oas\n ind = 1\n return\n end\n\nC==============================================================================\nc convert from (line,sample) to (lat,lon) and vice versa.\nC==============================================================================\n subroutine latlon1(ipic,rline,rsamp,rlat,rlon,ind)\n IMPLICIT NONE\n integer ipic,ind\n real*8 rline,rsamp,rlat,rlon\n\n include 'cmap.fin'\n\n common/cnav_sedr/fl1,oal1,oas1,pscale1,zscale1\n common/cnav_sedr/om1(3,3),psc31(3),sclat1,sclon1,epsln21\n common/cnav_sedr/fl2,oal2,oas2,pscale2,zscale2\n common/cnav_sedr/om2(3,3),psc32(3),sclat2,sclon2,epsln22\n real*8 fl1,oal1,oas1,pscale1,zscale1,om1,psc31,sclat1,sclon1,\n + epsln21,fl2,oal2,oas2,pscale2,zscale2,om2,psc32,sclat2,\n + sclon2,epsln22\n\nc convert from (line,samp) to (lat,lon)\n if (ipic.eq.1) then\n call planet(ind,rline,rsamp,rlat,rlon,\n & om1,psc31,sclon1,re,epsln,epsln21,oal1,oas1,zscale1)\n else\n call planet(ind,rline,rsamp,rlat,rlon,\n & om2,psc32,sclon2,re,epsln,epsln22,oal2,oas2,zscale2)\n endif\n return\n\n entry linsam1(ipic,rlat,rlon,rline,rsamp,ind)\nc convert from (lat,lon) to (line,samp)\n if (ipic.eq.1) then\n call plainv(ind,rlat,rlon,rline,rsamp,\n & om1,psc31,sclon1,re,epsln,epsln21,oal1,oas1,zscale1)\n else\n call plainv(ind,rlat,rlon,rline,rsamp,\n & om2,psc32,sclon2,re,epsln,epsln22,oal2,oas2,zscale2)\n endif\n\n return\n end\n\nC==============================================================================\nc convert from (line,sample) to (lat,lon) and vice versa. this version\nc also converts from image-space to object-space and vice versa, as\nc required.\nC==============================================================================\n subroutine latlon2(ipic,rline,rsamp,rlat,rlon,ind)\n IMPLICIT NONE\n integer ipic,ind\n real*8 rline,rsamp,rlat,rlon\n\n include 'cmap.fin'\n include 'cpic.fin'\n\n common/cnav_sedr/fl1,oal1,oas1,pscale1,zscale1\n common/cnav_sedr/om1(3,3),psc31(3),sclat1,sclon1,epsln21\n common/cnav_sedr/fl2,oal2,oas2,pscale2,zscale2\n common/cnav_sedr/om2(3,3),psc32(3),sclat2,sclon2,epsln22\n real*8 fl1,oal1,oas1,pscale1,zscale1,om1,psc31,sclat1,sclon1,\n + epsln21,fl2,oal2,oas2,pscale2,zscale2,om2,psc32,sclat2,\n + sclon2,epsln22\n\n common/distor/itype(2),conv(2216,2),nph(2),npv(2),project(2)\n real*4 conv\n integer nph, npv, itype\n character*5 project\n\n real*4 rl,rs\n real*8 r8rl,r8rs\n\n rl = rline\n rs = rsamp\n if (itype(ipic).eq.7) call convisos(project(ipic),camera_id,\n & rl,rs,rl,rs,1,conv(1,ipic),nph(ipic),npv(ipic),ind)\nc convert from (line,samp) to (lat,lon)\n if (ipic.eq.1) then\n r8rl = rl\n r8rs = rs\n call planet(ind,r8rl,r8rs,rlat,rlon,\n & om1,psc31,sclon1,re,epsln,epsln21,oal1,oas1,zscale1)\n else\n r8rl = rl\n r8rs = rs\n call planet(ind,r8rl,r8rs,rlat,rlon,\n & om2,psc32,sclon2,re,epsln,epsln22,oal2,oas2,zscale2)\n endif\n return\n\n entry linsam2(ipic,rlat,rlon,rline,rsamp,ind)\nc convert from (lat,lon) to (line,samp)\n if (ipic.eq.1) then\n call plainv(ind,rlat,rlon,rline,rsamp,\n & om1,psc31,sclon1,re,epsln,epsln21,oal1,oas1,zscale1)\n else\n call plainv(ind,rlat,rlon,rline,rsamp,\n & om2,psc32,sclon2,re,epsln,epsln22,oal2,oas2,zscale2)\n endif\n\n if (itype(ipic).eq.7) then\n rl=rline\n rs=rsamp\n call convisos(project(ipic),camera_id,rl,rs,rl,rs,0,\n & conv(1,ipic),nph(ipic),npv(ipic),ind)\n rline = rl\n rsamp = rs\n end if\n \n ind = 1\n return\n end\n\nC==============================================================================\nc routine to convert input latitude (rlat) to planetocentric if igeo=1\nC==============================================================================\n real*8 function geocen(rlat)\n IMPLICIT NONE\n real*8 rlat\n\n include 'cmap.fin'\n include 'const.fin'\n\n if (dabs(rlat).ge.pi/2.d0) then\n geocen = dsign(pi/2.d0,rlat)\n return\n endif\n\n if (igeo.ne.1) then\n geocen = rlat\n else\n geocen = datan(dtan(rlat)/epsln)\n endif\n return\n end\n\nC==============================================================================\nc routine to convert input latitude (rlat) to planetodetic if igeo=1\nC==============================================================================\n real*8 function geodet(rlat)\n IMPLICIT NONE\n real*8 rlat\n\n include 'cmap.fin'\n include 'const.fin'\n\n if (dabs(rlat).ge.pi/2.d0) then\n geodet = dsign(pi/2.d0,rlat)\n return\n endif\n\n if (igeo.ne.1) then\n geodet = rlat\n else\n geodet = datan(dtan(rlat)*epsln)\n endif\n return\n end\n\nC==============================================================================\nc get camera distortion parameters.\nc mode=1 if res file directory has already been read.\nC==============================================================================\n subroutine getgeopar(project_id,camera_id,frame_id,planet_id,\n &\t\tconv,nph,npv,mode,*)\n IMPLICIT NONE\n integer*4 project_id,camera_id,frame_id,planet_id,nph,npv,mode\n real*4 conv(2216)\t\t\t!camera distortion parameters\n\n save\n character *6 format(409) /5*'FULL',404*'REAL'/\n integer status,nrows,ibis\n\n integer iunitr,jdata(2)\n real*4 rloc(2,202)\n\n logical parmtst\n integer icnt,idef,ind,icount,iret,mpv\n character*24 rfnames(4)/\n &\t\t'/project/vgr/resj.fil',\t!jupiter\n &\t\t'/project/vgr/ress.fil',\t!saturn\n &\t\t'/project/vgr/resu.fil',\t!uranus\n &\t\t'/project/vgr/resn.fil'/\t!neptune\n character*256 rfname\n\n integer ibis_file_get\n\n 101 format(' ***Reseau locations for frame',i8,' not found')\n character*80 msg\nc\n if (project_id.ne.4) return\t!only implemented for vgr\nc ...find and open reseau location file\n if (mode.eq.0) then\n call xvparm('RES',rfname,icnt,idef,1)\t!get file name\n if (idef.eq.1) rfname=rfnames(planet_id-4)\n call xvunit(iunitr,'X',1,ind,'U_NAME',rfname,' ')\n call xvsignal(iunitr,ind,.true.)\n call ibis_file_open(iunitr,ibis,'read',409,99999,\n + format,0,status)\n if ( status .ne. 1 ) call ibis_signal_u(iunitr,status,1)\n icount = ibis_file_get(ibis,'nr',nrows,1,1) ! get nrows\n if ( nrows .lt. 0 ) call ibis_signal(ibis,icount,1)\n mode = 1\n endif\nc ....get reseau locations\n jdata(1) = frame_id\n jdata(2) = camera_id\n call getlocv2(ibis,nrows,jdata,rloc,iret)\n if (iret.eq.0) goto 30\t!skip if successful\n\n write(msg,101) frame_id \n call xvmessage(msg,' ')\n call xvmessage('Do you wish to use nominal reseau locations?',' ')\n 20 call xvintract('QUERY',' Enter Y or N')\n if (parmtst('EXIT', mpv, 1)) goto 990\n if (parmtst('N', mpv, 1)) goto 990\n call xvmessage('Nominal reseau locations used',' ')\n call getres(rloc,camera_id)\n\nc ....get geom parameters\n 30 call geomav(conv,camera_id,rloc)\n nph = 24\n npv = 23\n call mve(7,2208,conv(9),conv,1,1) !move so buffer begins with tiepoints\n return\nc ...error conditions\n 990 call xvmessage(' ***Use program RESLOC to locate the reseau',' ')\n return1\n end\n\nC==============================================================================\nc read old tiepoints from third input file...\nC==============================================================================\n subroutine getpts(*)\n IMPLICIT NONE\n\n include 'cpts.fin'\n\n common/c1_iobuf/buf(500,10)\t\t!scratch space for i/o\n real*4 buf\n\n integer iunit,status,ncol,count,ibis_in,nrow,icol,i\n character*80 msg\n\n integer ibis_file_get\n\n call xvunit(iunit, 'inp', 3, status, ' ')\n call ibis_file_open(iunit, ibis_in, 'read', 0, 0,' ',' ', status)\n if (status .ne. 1) call ibis_signal_u(iunit, status, 1)\n count = ibis_file_get(ibis_in, 'nc', ncol, 1, 1)\n if (count .lt. 0) call ibis_signal(ibis_in, count, 1)\n count = ibis_file_get(ibis_in, 'nr', nrow, 1, 1)\n if (count .lt. 0) call ibis_signal(ibis_in, count, 1)\n\n if (ncol.ne.10) then\n call xvmessage(' ***Invalid input tiepoint file format',' ')\n return1\n endif\n\n do icol=1,ncol\n call ibis_column_read(ibis_in, buf(1, icol), icol, 1, nrow, \n + status)\n if (status .ne. 1) call ibis_signal(ibis_in, status, 1)\n\t \n enddo\n\n npts = nrow \nc\nc ....move data to tiepoints area\n do i=1,nrow\n lpt(1,i) = buf(i,1)\n lpt(2,i) = buf(i,2)\n rpt(1,i) = buf(i,3)\n rpt(2,i) = buf(i,4)\n lpt0(1,i) = buf(i,5)\n lpt0(2,i) = buf(i,6)\n zl(i) = buf(i,7)\n zr(i) = buf(i,8)\n cmax(i) = buf(i,9)\n enddo\n\n call ibis_file_close(ibis_in, ' ', status)\n if (status .ne. 1) call ibis_signal(ibis_in, status, 1)\n write(msg,110) npts\n 110 format(i6,' tiepoints read from input tiepoint file')\n call xvmessage(msg,' ')\n return\n end\n\nC==============================================================================\nc write tiepoints to output ibis interface file.\nC==============================================================================\n subroutine putpts(*)\n IMPLICIT NONE\n\n include 'cpts.fin'\n\n common/c1_iobuf/obuf(500,10)\t\t!scratch space for i/o\n real*4 obuf\n\n integer ounit,status,ncol,ibis_out,nrow,i,n,icol\n\n if (npts.eq.0) return\n nrow = 0\t\t!column length=number of tiepoints output\n do i=1,npts\n if (lpt(1,i).ge.0.0) nrow=nrow+1\n enddo\n\n ncol = 10\n call xvunit(ounit, 'out', 1, status, ' ')\n call ibis_file_open(ounit, ibis_out, 'write', ncol, nrow, ' ', \n +' ', status)\n if (status .ne. 1) call ibis_signal_u(ounit, status, 1)\nc\nc ....rearrange data for column sequential output\n n = 0\n DO i=1,npts\n IF (lpt(1,i).ge.0.0) THEN\t!reject all flagged tiepoints\n n = n + 1\n obuf(n,1) = lpt(1,i)\n obuf(n,2) = lpt(2,i)\n obuf(n,3) = rpt(1,i)\n obuf(n,4) = rpt(2,i)\n obuf(n,5) = lpt0(1,i)\n obuf(n,6) = lpt0(2,i)\n obuf(n,7) = zl(i)\n obuf(n,8) = zr(i)\n obuf(n,9) = cmax(i)\n obuf(n,10) = i\n END IF\n END DO\n\n do icol=1,10\n call ibis_column_write(ibis_out, obuf(1, icol), icol, 1, nrow, \n +status)\n if (status .ne. 1) call ibis_signal(ibis_out, status, 1)\n enddo\n\n call ibis_file_close(ibis_out, ' ', status)\n return\n end\n", "meta": {"hexsha": "12eb6580318de5d93a24f437a0cd7b5d90640a98", "size": 16011, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "vos/p2/prog/nav2/planet.f", "max_stars_repo_name": "NASA-AMMOS/VICAR", "max_stars_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2020-10-21T05:56:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T10:02:01.000Z", "max_issues_repo_path": "vos/p2/prog/nav2/planet.f", "max_issues_repo_name": "NASA-AMMOS/VICAR", "max_issues_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "vos/p2/prog/nav2/planet.f", "max_forks_repo_name": "NASA-AMMOS/VICAR", "max_forks_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-03-09T01:51:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-23T00:23:24.000Z", "avg_line_length": 34.3583690987, "max_line_length": 79, "alphanum_fraction": 0.5320717007, "num_tokens": 5276, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391579526934, "lm_q2_score": 0.7217432003123989, "lm_q1q2_score": 0.6661972358744388}} {"text": " real function shear(a,b,c,x)\nc\nc + + + PURPOSE + + +\nc Calculates nondimensional shear stress.\nc\nc Called from subroutine XCRIT.\nc Author(s): G. Foster\nc Reference in User Guide:\nc\nc Changes:\nc\nc Version: This module recoded from WEPP version 90.92.\nc Date recoded: 01/08/91.\nc Recoded by: Charles R. Meyer.\nc\nc + + + KEYWORDS + + +\nc\nc + + + ARGUMENT DECLARATIONS + + +\nc\n real a, b, c, x\nc\nc + + + ARGUMENT DEFINITIONS + + +\nc a - shear stress coefficient for current slope\nc section\nc b - shear stress coefficient for current slope\nc section\nc c - shear stress coefficient for current slope\nc section\nc x - nondimensional distance at which shear stress\nc is to be calculated\nc\nc + + + LOCAL VARIABLES + + +\nc value -\n real value\nc\nc + + + END SPECIFICATIONS + + +\nc\n value = a * x ** 2 + b * x + c\n if (value.lt.0.0) value = 0.0\n shear = value ** 0.66666667\n if (shear.le.0.0) shear = 0.0001\nc\n return\n end\n", "meta": {"hexsha": "b74130dfd2cf3628d79c5f38492aea32852a075f", "size": 1105, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/wepp2012-src/shear.for", "max_stars_repo_name": "jarad/dep", "max_stars_repo_head_hexsha": "fe73982f4c70039e1a31b9e8e2d9aac31502f803", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-11-26T17:49:19.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-26T17:49:19.000Z", "max_issues_repo_path": "src/wepp2012-src/shear.for", "max_issues_repo_name": "jarad/dep", "max_issues_repo_head_hexsha": "fe73982f4c70039e1a31b9e8e2d9aac31502f803", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 54, "max_issues_repo_issues_event_min_datetime": "2018-12-12T18:02:31.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T19:14:25.000Z", "max_forks_repo_path": "src/wepp2012-src/shear.for", "max_forks_repo_name": "akrherz/idep", "max_forks_repo_head_hexsha": "7189a26fbcec3d8c3cc7d7015107b8fb6c5f6a45", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-03-02T22:59:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-09T15:49:00.000Z", "avg_line_length": 24.5555555556, "max_line_length": 60, "alphanum_fraction": 0.5574660633, "num_tokens": 333, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465188527684, "lm_q2_score": 0.7122321903471563, "lm_q1q2_score": 0.666183899856095}} {"text": " subroutine gbox(emax, alat, qb, n1, n2, n3)\nc============================================================\nc Find the max. dimensions of the reciprocal-space\nc box which contains all plane waves with Ekin < Emax.\nc\nc DATE: Wed Oct 16 14:54:34 MDT 1996\nc============================================================\n implicit none\n\n real*8, intent(IN) :: emax, alat\n real*8, dimension(3,3), intent(IN) :: qb\n integer, intent(OUT) :: n1,n2,n3\n\n real*8 Gmax, twopi, tpiba\n real*8 q11,q12,q13,q22,q23,q33,rvol,range1,range2,range3\n real*8, external :: tripl\n\n twopi = 8d0*datan(1d0)\n tpiba = twopi / alat\n Gmax = sqrt( 2d0 * emax ) / tpiba\n\n q11 = DOT_PRODUCT( qb(:,1), qb(:,1) )\n q12 = DOT_PRODUCT( qb(:,1), qb(:,2) )\n q13 = DOT_PRODUCT( qb(:,1), qb(:,3) )\n q22 = DOT_PRODUCT( qb(:,2), qb(:,2) )\n q23 = DOT_PRODUCT( qb(:,2), qb(:,3) )\n q33 = DOT_PRODUCT( qb(:,3), qb(:,3) )\n\n rvol = abs( tripl( qb(:,1), qb(:,2), qb(:,3) ) )\n\n range1 = rvol / sqrt(q22*q33 - q23**2)\n range2 = rvol / sqrt(q11*q33 - q13**2)\n range3 = rvol / sqrt(q11*q22 - q12**2)\n\n n1 = int ( Gmax / range1 + 1d0 )\n n2 = int ( Gmax / range2 + 1d0 )\n n3 = int ( Gmax / range3 + 1d0 )\n\n return\n end\n", "meta": {"hexsha": "1d765302847a25dd0f8d896825e5b8485bb6ff1b", "size": 1370, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "csld/phonon/gbox.f", "max_stars_repo_name": "jsyony37/csld", "max_stars_repo_head_hexsha": "b0e6d5845d807174f24ca7b591bc164c608c99c8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2019-07-22T18:49:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-04T10:22:05.000Z", "max_issues_repo_path": "csld/phonon/gbox.f", "max_issues_repo_name": "jsyony37/csld", "max_issues_repo_head_hexsha": "b0e6d5845d807174f24ca7b591bc164c608c99c8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2019-07-18T20:49:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-09T00:47:04.000Z", "max_forks_repo_path": "csld/phonon/gbox.f", "max_forks_repo_name": "jsyony37/csld", "max_forks_repo_head_hexsha": "b0e6d5845d807174f24ca7b591bc164c608c99c8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2019-07-18T17:52:44.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-04T11:35:04.000Z", "avg_line_length": 33.4146341463, "max_line_length": 62, "alphanum_fraction": 0.4605839416, "num_tokens": 457, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.935346511643776, "lm_q2_score": 0.7122321720225278, "lm_q1q2_score": 0.6661838775817411}} {"text": "subroutine sistupf(a, b, l, u)\n\nimplicit none\n\nreal, dimension(:,:), intent(in) :: a\nreal, dimension(:), intent(in) :: b\nreal, dimension(:), intent(out) :: u\n\ninteger, dimension(:), intent(in) :: l\n\ninteger :: ln, li\n\ninteger :: n, i, j, p\n\nn = size(b)\n\nln = l(n)\n\nu(n) = b(ln)/a(ln,n)\n\ndo i = n-1, 1, -1\n\n li = l(i)\n u(i) = b(li)\n do j = i+1, n\n u(i) = u(i) - a(li,j)*u(j)\n enddo\n\n u(i) = u(i)/a(li,i)\nenddo\n\nend subroutine\n", "meta": {"hexsha": "e34752e84f194e4e7f1c325236dce97fc8f736c1", "size": 433, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Practica2_sistu/sistupf.f95", "max_stars_repo_name": "UxioAndrade/Analisis-Numerico-Matricial", "max_stars_repo_head_hexsha": "1afa52b0994b9cf38822da903609a4d1c91bfab0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2019-04-02T18:09:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-16T14:08:07.000Z", "max_issues_repo_path": "Practica2_sistu/sistupf.f95", "max_issues_repo_name": "UxioAndrade/Analisis-Numerico-Matricial", "max_issues_repo_head_hexsha": "1afa52b0994b9cf38822da903609a4d1c91bfab0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Practica2_sistu/sistupf.f95", "max_forks_repo_name": "UxioAndrade/Analisis-Numerico-Matricial", "max_forks_repo_head_hexsha": "1afa52b0994b9cf38822da903609a4d1c91bfab0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-04-05T13:18:12.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-04T10:32:14.000Z", "avg_line_length": 13.1212121212, "max_line_length": 38, "alphanum_fraction": 0.5288683603, "num_tokens": 172, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869851639066, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6661679418712002}} {"text": "C NCLFORTSTART\n SUBROUTINE DPRCWATDP(Q,DP,KLVL,QMSG,DPMSG,PRCWAT)\n IMPLICIT NONE\nc Input\n INTEGER KLVL\n DOUBLE PRECISION Q(KLVL),DP(KLVL),QMSG,DPMSG\nc Output\n DOUBLE PRECISION PRCWAT\nC NCLEND\n\nC NCL: prcwat = prcwater_dp (q,dp)\n\nc nomenclature:\nc q - specific humidity [kg/kg; ie: dimensionless]\nc dp - layer thickness [Pa]\nc prcwat - precipitable water [kg/m2]\n\nc Local\n INTEGER KL,KNT\n DOUBLE PRECISION G\n\n G = 9.81D0\n\n KNT = 0\n PRCWAT = 0.0D0\n DO KL = 1,KLVL\n IF (Q(KL).NE.QMSG .AND. DP(KL).NE.DPMSG) THEN\n KNT = KNT + 1\n PRCWAT = PRCWAT + Q(KL)*ABS(DP(KL))\n END IF\n END DO\n\n IF (KNT.GT.0) THEN\n PRCWAT = PRCWAT/G\n ELSE\n PRCWAT = QMSG\n END IF\n\n RETURN\n END\n", "meta": {"hexsha": "91d6407e79005515fe4feffee7d4082102ed5a3f", "size": 828, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ni/src/lib/nfpfort/prcwat.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "ni/src/lib/nfpfort/prcwat.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "ni/src/lib/nfpfort/prcwat.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 20.1951219512, "max_line_length": 59, "alphanum_fraction": 0.5531400966, "num_tokens": 307, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544912, "lm_q2_score": 0.7549149923816046, "lm_q1q2_score": 0.6661580260818079}} {"text": " program ex2_omp\n\n!*** Stencil update\n!*** This is the serial version\n!*** Employs a temporary array (tmp) inside loop\n!*** Employs a reduction operation on variable sum\n!*** In this code there are read-after-write and write-after-read dependencies\n\n!*** The algorithm that presets the input arrays and also the format for the sum\n!*** are carefully selected to hide round-off discrepancies in the output\n\n!*** All variables and unnamed constants are in double precision\n\n!*** Compile with: ifort -xhost -qopenmp ex2_omp.f90\n\n!*** Execution time is of the order of seconds\n!*** Memory requirement is about 20.1 GB\n\n!*** The kernel has a write-after-read (WAR) dependency\n\n use omp_lib\n\n integer :: n = 30000\n real(8), dimension(:,:), allocatable :: x, y, tmp\n real(8) :: sum\n\n write (0,*) 'Allocate arrays'\n allocate (x(n,n), y(n,n), tmp(n,n))\n\n!*** The input arrays are carefull filled to minimize round-off errors\n write (0,*) 'Preset input arrays (x and y)'\n do j=1, n\n do i=1, n\n x(i,j) = real(modulo((i+j), 3)) - 0.9999_8\n y(i,j) = x(i,j) + 0.0001\n enddo\n enddo\n\n!$ write (0,'(a,i4)') ' Number of threads :: ', omp_get_max_threads()\n\n write (0,*) 'Start timer and calculation'\n call system_clock(ic1, ir)\n\n sum = 0.\n\n!$omp parallel do default(none) shared(n, x, y, tmp) private(i, j)\n do j=2, n-1\n do i=2, n-1\n tmp(i,j) = 0.167_8 * (x(i,j) + x(i-1,j) + x(i+1,j) + x(i,j-1) + x(i,j+1) + &\n y(i+1,j))\n enddo\n enddo\n\n!$omp parallel do default(none) shared(n, y, tmp) private(i, j) reduction (+: sum)\n do j=2, n-1\n do i=2, n-1\n y(i,j) = tmp(i,j)\n sum = sum + tmp(i,j)\n enddo\n enddo\n\n call system_clock(ic2, ir)\n write (0,*) 'Stop timer after calculation'\n write (0,*)\n write (0,'(a,f12.5,a)') 'Time to completion :: ', (real(ic2) - real(ic1)) / real(ir), ' seconds'\n\n!*** The output format with 2 digits after the decimal point is carefully selected to hide round-off errors\n write (0,'(a,f12.2)') 'The total sum is :: ', sum\n\n end program ex2_omp\n", "meta": {"hexsha": "e495da397c8b8194f4aecd18fd0ab56c27309808", "size": 2344, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "PEARC18_OMP/exercises/exercise2/.solutions/ex2_omp.f90", "max_stars_repo_name": "ritua2/IPT", "max_stars_repo_head_hexsha": "3fe3757dafe24242d8afae6e68c014275ce9ab4e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2017-09-14T20:55:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-25T11:35:36.000Z", "max_issues_repo_path": "PEARC18_OMP/exercises/exercise2/.solutions/ex2_omp.f90", "max_issues_repo_name": "ritua2/IPT", "max_issues_repo_head_hexsha": "3fe3757dafe24242d8afae6e68c014275ce9ab4e", "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": "PEARC18_OMP/exercises/exercise2/.solutions/ex2_omp.f90", "max_forks_repo_name": "ritua2/IPT", "max_forks_repo_head_hexsha": "3fe3757dafe24242d8afae6e68c014275ce9ab4e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2017-11-27T13:25:08.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-10T10:29:25.000Z", "avg_line_length": 33.014084507, "max_line_length": 108, "alphanum_fraction": 0.5422354949, "num_tokens": 689, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278788223264, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.666158025687099}} {"text": "program euler\n integer max, x, y, p, l, i\n\n character(6) s, r\n\n character t\n\n max = 0\n\n do x = 100, 999\n do y = 100, 999\n p = x * y\n\n write(s, '(i0)') p\n\n write(r, '(i0)') p\n\n l = len_trim(r)\n\n do i = 1, l / 2\n t = r(i:i)\n\n r(i:i) = r(l + 1 - i:l + 1 - i)\n\n r(l + 1 - i:l + 1 - i) = t\n enddo\n\n if ((s == r) .and. (p > max)) then\n max = p\n endif\n enddo\n enddo\n\n write(*, '(i0)') max\nend program euler\n", "meta": {"hexsha": "f0ed23c63f38a25a0eb383132fb280d3c77fb15e", "size": 481, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "fortran/004/004.f95", "max_stars_repo_name": "seaneshbaugh/rosetta-euler", "max_stars_repo_head_hexsha": "14f24dfc347e7d9a4c9c0f090acf2811aa65f453", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 36, "max_stars_repo_stars_event_min_datetime": "2015-01-24T08:11:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-21T00:32:00.000Z", "max_issues_repo_path": "fortran/004/004.f95", "max_issues_repo_name": "seaneshbaugh/rosetta-euler", "max_issues_repo_head_hexsha": "14f24dfc347e7d9a4c9c0f090acf2811aa65f453", "max_issues_repo_licenses": ["MIT"], "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/004/004.f95", "max_forks_repo_name": "seaneshbaugh/rosetta-euler", "max_forks_repo_head_hexsha": "14f24dfc347e7d9a4c9c0f090acf2811aa65f453", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2015-01-24T08:17:42.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-11T16:10:56.000Z", "avg_line_length": 13.3611111111, "max_line_length": 40, "alphanum_fraction": 0.4033264033, "num_tokens": 201, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278788223264, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.666158025687099}} {"text": "!---------------------------------------------------------------------- \n!---------------------------------------------------------------------- \n! ppp : A continuous dynamical system with period doubling\n!---------------------------------------------------------------------- \n!---------------------------------------------------------------------- \n\n SUBROUTINE FUNC(NDIM,U,ICP,PAR,IJAC,F,DFDU,DFDP) \n! ---------- ---- \n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: NDIM, ICP(*), IJAC\n DOUBLE PRECISION, INTENT(IN) :: U(NDIM), PAR(*)\n DOUBLE PRECISION, INTENT(OUT) :: F(NDIM)\n DOUBLE PRECISION, INTENT(INOUT) :: DFDU(NDIM,NDIM), DFDP(NDIM,*)\n\n F(1)= U(1)*(1-U(1)) - PAR(4)*U(1)*U(2) \n F(2)=-PAR(2)*U(2) + PAR(4)*U(1)*U(2) - PAR(5)*U(2)*U(3) &\n - PAR(1)*(1-EXP(-PAR(6)*U(2))) \n F(3)=-PAR(3)*U(3) + PAR(5)*U(2)*U(3) \n\n END SUBROUTINE FUNC\n\n SUBROUTINE STPNT(NDIM,U,PAR,T)\n! ---------- ----- \n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: NDIM\n DOUBLE PRECISION, INTENT(INOUT) :: U(NDIM),PAR(*)\n DOUBLE PRECISION, INTENT(IN) :: T\n\n U(1)=1.0 \n U(2)=0.0 \n U(3)=0.0 \n\n PAR(1)=0.0 \n PAR(2)=0.25 \n PAR(3)=0.5 \n PAR(4)=3.0 \n PAR(5)=3.0 \n PAR(6)=5.0 \n\n END SUBROUTINE STPNT\n\n SUBROUTINE BCND \n END SUBROUTINE BCND\n\n SUBROUTINE ICND \n END SUBROUTINE ICND\n\n SUBROUTINE FOPT \n END SUBROUTINE FOPT\n\n SUBROUTINE PVLS\n END SUBROUTINE PVLS\n", "meta": {"hexsha": "da7881bb8da52e81c24df1ceec5b1e6a6aaeed1b", "size": 1520, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "07p/demos/ppp/ppp.f90", "max_stars_repo_name": "st970703/AUTO07P-Update-to-Python-3.0", "max_stars_repo_head_hexsha": "fb2d2aebf2127fa914064d01ed62c0acb5f6421c", "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": "07p/demos/ppp/ppp.f90", "max_issues_repo_name": "st970703/AUTO07P-Update-to-Python-3.0", "max_issues_repo_head_hexsha": "fb2d2aebf2127fa914064d01ed62c0acb5f6421c", "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": "07p/demos/ppp/ppp.f90", "max_forks_repo_name": "st970703/AUTO07P-Update-to-Python-3.0", "max_forks_repo_head_hexsha": "fb2d2aebf2127fa914064d01ed62c0acb5f6421c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.6363636364, "max_line_length": 72, "alphanum_fraction": 0.4072368421, "num_tokens": 486, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278757303677, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6661580233529331}} {"text": "c bpspline -- dmc 30 May 1996\nc\nc set up coefficients for bicubic spline with following BC's:\nc * LHS and RHS BCs -- d3f/dx3 from 3rd divided difference, 1st coordinate\nc * derivatives periodic in second coordinate\nc\nc see similar routine, bpsplinb, for more control over x boundary\nc conditions...\nc\n subroutine r8bpspline(x,inx,th,inth,fspl,inf3,\n > wk,nwk,ilinx,ilinth,ier)\nc\n IMPLICIT NONE\n INTEGER, PARAMETER :: R8=SELECTED_REAL_KIND(12,100)\n integer inx,inth,inf3,nwk\n REAL*8 x(inx),th(inth),fspl(4,4,inf3,inth),wk(nwk)\n integer ilinx,ilinth\n integer ier\nc\nc input:\nc x(1...inx) -- abscissae, first dimension of data\nc th(1...inth) -- abscissae, second (periodic) dimension of data\nc fspl(1,1,1..inx,1..inth) -- function values\nc inf3 -- fspl dimensioning, inf3.ge.inx required.\nc\nc output:\nc fspl(*,*,1..inx,1..inth) -- bicubic spline coeffs (4x4)\nc ...fspl(1,1,*,*) is not replaced.\nc\nc ilinx -- =1 on output if x(inx) pts are nearly evenly spaced (tol=1e-3)\nc ilinth-- =1 on output if th(inth) evenly spaced (tol=1e-3)\nc\nc ier -- completion code, 0 for normal\nc\nc workspace:\nc wk -- must be at least 5*max(inx,inth) large\nc nwk -- size of workspace\nc\nc---------------------------------\nc compute bicubic spline of 2d function, given values at the grid\nc grid crossing points, f(1,1,i,j)=f(x(i),th(j)).\nc\nc on evaluation: for point x btw x(i) and x(i+1), dx=x-x(i)\nc and th btw th(j) and th(j+1), dt=th-th(j),\nc\nc spline =\nc f(1,1,i,j) + dx*f(2,1,i,j) + dx**2*f(3,1,i,j) + dx**3*f(4,1,i,j)\nc +dt*(f(1,2,i,j) + dx*f(2,2,i,j) + dx**2*f(3,2,i,j) + dx**3*f(4,2,i,j))\nc +d2*(f(1,3,i,j) + dx*f(2,3,i,j) + dx**2*f(3,3,i,j) + dx**3*f(4,3,i,j))\nc +d3*(f(1,4,i,j) + dx*f(2,4,i,j) + dx**2*f(3,4,i,j) + dx**3*f(4,4,i,j))\nc\nc where d2=dt**2 and d3=dt**3.\nc\nc---------------------------------\n integer ierx,ierth\n REAL*8 zdum(1)\nc---------------------------------\nc\n ier=0\n if(nwk.lt.5*max(inx,inth)) then\n write(6,'('' ?bpspline: workspace too small.'')')\n ier=1\n endif\n if(inx.lt.2) then\n write(6,'('' ?bpspline: at least 2 x points required.'')')\n ier=1\n endif\n if(inth.lt.2) then\n write(6,'('' ?bpspline: need at least 2 theta points.'')')\n ier=1\n endif\nc\nc check ilinx & x vector\nc\n call r8splinck(x,inx,ilinx,1.0E-3_r8,ierx)\n if(ierx.ne.0) ier=2\nc\n if(ier.eq.2) then\n write(6,'('' ?bpspline: x axis not strict ascending'')')\n endif\nc\nc check ilinth & th vector\nc\n call r8splinck(th,inth,ilinth,1.0E-3_r8,ierth)\n if(ierth.ne.0) ier=3\nc\n if(ier.eq.3) then\n write(6,'('' ?bpspline: th axis not strict ascending'')')\n endif\nc\n if(ier.ne.0) return\nc\nc------------------------------------\nc\n zdum=0.0_r8\nc\nc not-a-knot BCs for x, periodic for theta\nc\n call r8bcspline(x,inx,th,inth,fspl,inf3,\n > 7,zdum,7,zdum,\n > -1,zdum,-1,zdum,\n > wk,nwk,ilinx,ilinth,ier)\nc\n return\n end\n", "meta": {"hexsha": "103ede7c2f6ffd5e1ae716a21981b2578316dd3e", "size": 3106, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gfile_Bfield/PSPLINE/Pspline/r8bpspline.f", "max_stars_repo_name": "ORNL-Fusion/RFSciDAC-testing", "max_stars_repo_head_hexsha": "c2fa44e00ce8e0af4be6fa662a9e8c94d6c6f60e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2020-05-08T01:47:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T10:35:28.000Z", "max_issues_repo_path": "gfile_Bfield/PSPLINE/Pspline/r8bpspline.f", "max_issues_repo_name": "ORNL-Fusion/RFSciDAC-testing", "max_issues_repo_head_hexsha": "c2fa44e00ce8e0af4be6fa662a9e8c94d6c6f60e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 77, "max_issues_repo_issues_event_min_datetime": "2020-05-08T07:18:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:20:33.000Z", "max_forks_repo_path": "gfile_Bfield/PSPLINE/Pspline/r8bpspline.f", "max_forks_repo_name": "ORNL-Fusion/RFSciDAC-testing", "max_forks_repo_head_hexsha": "c2fa44e00ce8e0af4be6fa662a9e8c94d6c6f60e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-02-10T13:47:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T12:53:43.000Z", "avg_line_length": 29.3018867925, "max_line_length": 75, "alphanum_fraction": 0.5589182228, "num_tokens": 1197, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705732, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6661580165477891}} {"text": "c---------------------------------------------------------------------\nc---------------------------------------------------------------------\n\n subroutine exact_solution(xi,eta,zeta,dtemp)\n\nc---------------------------------------------------------------------\nc---------------------------------------------------------------------\n\nc---------------------------------------------------------------------\nc this function returns the exact solution at point xi, eta, zeta \nc---------------------------------------------------------------------\n\n include 'header.h'\n\n double precision xi, eta, zeta, dtemp(5)\n integer m\n\n do m = 1, 5\n dtemp(m) = ce(m,1) +\n > xi*(ce(m,2) + xi*(ce(m,5) + xi*(ce(m,8) + xi*ce(m,11)))) +\n > eta*(ce(m,3) + eta*(ce(m,6) + eta*(ce(m,9) + eta*ce(m,12))))+\n > zeta*(ce(m,4) + zeta*(ce(m,7) + zeta*(ce(m,10) + \n > zeta*ce(m,13))))\n enddo\n\n return\n end\n\n\n", "meta": {"hexsha": "b093b46d1600aac2a3ff2e495b21dafa402c70e5", "size": 963, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/NPB3.1/BT/exact_solution.f", "max_stars_repo_name": "brugger1/testsuite", "max_stars_repo_head_hexsha": "9b504db668cdeaf7c561f15b76c95d05bfdd1517", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 144, "max_stars_repo_stars_event_min_datetime": "2015-01-16T01:53:24.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-27T21:59:09.000Z", "max_issues_repo_path": "validation_tests/NPB3.1/BT/exact_solution.f", "max_issues_repo_name": "brugger1/testsuite", "max_issues_repo_head_hexsha": "9b504db668cdeaf7c561f15b76c95d05bfdd1517", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 79, "max_issues_repo_issues_event_min_datetime": "2015-01-01T00:32:30.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-06T12:26:08.000Z", "max_forks_repo_path": "validation_tests/NPB3.1/BT/exact_solution.f", "max_forks_repo_name": "brugger1/testsuite", "max_forks_repo_head_hexsha": "9b504db668cdeaf7c561f15b76c95d05bfdd1517", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 53, "max_forks_repo_forks_event_min_datetime": "2015-02-02T17:55:46.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-08T09:35:16.000Z", "avg_line_length": 32.1, "max_line_length": 72, "alphanum_fraction": 0.2751817238, "num_tokens": 218, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797172476384, "lm_q2_score": 0.731058584489497, "lm_q1q2_score": 0.6661257543065986}} {"text": " program DRDCFT\nc>> 1996-06-05 DRDCFT Krogh Fixes for conversion to C.\nc>> 1994-10-19 DRDCFT Krogh Changes to use M77CON\nc>> 1989-05-07 DRDCFT FTK, CLL\nc Driver to demonstrate DCFT -- Complex Fast Fourier Transform\nc ------------------------------------------------------------------\nc--D replaces \"?\": DR?CFT, ?CFT\nc ------------------------------------------------------------------\n double precision F(256)\n double precision S(31), T, DELTAT, TTIME, PI, TWOPI, RTWO\n double precision ZERO, FOUR, P1, P3\n integer I, K, KF, M, MS, N, ND, MA(1)\n parameter (PI = 3.1415926535897932384D0)\n parameter (TWOPI = 2.D0 * PI)\n parameter (RTWO = 1.4142135623730950488D0)\n parameter (M = 7)\nc parameter (N = 2**M)\n parameter (N = 128)\n parameter (ND = 1)\n parameter (ZERO = 0.D0)\n parameter (FOUR = 4.D0)\n parameter (P1 = .1D0)\n parameter (P3 = .3D0)\n data TTIME /25.D0/\n data MA / M /\nc ------------------------------------------------------------------\n print*,'Program DRDCFT.. Demonstrates DCFT'\n DELTAT = TTIME / N\n T = ZERO\n do 100 K = 1, 2*N, 2\n F(K)=SIN(TWOPI*(T+P1))+FOUR*COS(TWOPI*(RTWO*T+P3))\n F(K+1) = ZERO\n T = T + DELTAT\n 100 continue\n MS = 0\n call DCFT (F, 'A', MA, ND, MS, S)\n print'(1X/A/1X)',' TRANSFORM FOR K=21 TO 41 (NO SIGMA FACTORS)'\n do 120 K = 21, 41, 3\n KF = 2*K-1\n print'(A,I3,A,I3,3(F11.5,F9.5))',\n * ' K=',K,' TO',K+2,(F(I), I=KF, KF+5)\n 120 continue\n stop\n end\n", "meta": {"hexsha": "6d22833aa4031dffd653ad889f85b6fa79ddf842", "size": 1600, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drdcft.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drdcft.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drdcft.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 35.5555555556, "max_line_length": 72, "alphanum_fraction": 0.473125, "num_tokens": 550, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797124237605, "lm_q2_score": 0.7310585844894971, "lm_q1q2_score": 0.6661257507800614}} {"text": " SUBROUTINE INTERP(XIN,YIN,DELTIN,LENIN,NTRP,XCAL,YCAL,\n &YINTERP,DELTOT,LENOT)\nC***********************************************************************\nC TO LINEARLY INTERPOLATE INPUT ARRAY OF (X,Y) POINTS, FOR MODE *\nC IWAVE = 13. X IS TIME, Y IS CURRENT. XIN AND YIN HAVE THE INPUT *\nC VALUES, XCAL AND YCAL HAVE THE CALCULATED INTERPOLATED VALUES ONLY. *\nC ARRAY YINTERP HAS Y OUTPUT ONLY. IN THIS IMPLEMENTATION, SENN *\nC MEASURES X SPACING ONCE, AND CALCULATES RELATIVE X VALUES IN *\nC SUBROUTINE RKGS. (FOR REFERENCE, OUTPUT FILE XYINTERP HAS THE FULL *\nC TWO-DIMENSIONAL INTERPOLATED ARRAY, WITH RELATIVE X VALUES, AS *\nC FORMED BY THIS SUBROUTINE.) *\nC***********************************************************************\nC include \"common.f\"\n REAL*4 XIN(LENIN),YIN(LENIN),XCAL(LENOT),YCAL(LENOT),\n &YINTERP(LENOT),B,M,DELTX\n INTEGER*4 I,J,NTRP,LENIN,LENOT\n REAl*8 DELTIN,DELTOT,VALUE\n IF (LENIN .LT. 2)THEN\n WRITE (*,*) ' INPUT FILE HAS LESS THAN TWO POINTS'\n WRITE (66,*) ' INPUT FILE HAS LESS THAN TWO POINTS'\nC RETURN ! 6/19/10\n STOP ! 6/19/10\n END IF\n LENOT = (LENIN -1)*(NTRP + 1) + 1\n DELTOT = DELTIN/(NTRP +1)\n XCAL(1) = XIN(1)\n YCAL(1) = YIN(1)\nC YINTERP(1) = YIN(1) ! Don't need?\n VALUE = XIN(1)\n I = 1\n J = 0\n\t K = 1 ! Index for interpolated Y array YINTERP\nC WRITE (*,*) XCAL(1),YCAL(1) !! Diagnostic\n WRITE(2,*) XCAL(1),YCAL(1)\n YINTERP(K) = YCAL(1) ! or YIN(1)?\n DO WHILE( I .LT. LENIN)\n J = J + 1\n K = K + 1\n VALUE =VALUE + DELTOT\n XCAL(J) = VALUE\n IF (MOD(J,(NTRP +1)).EQ.0) THEN\nC WRITE (*,*) XIN(I+1 ),YIN(I+1 ) !! Diagnostic\n WRITE(2,*) XIN(I+1 ),YIN(I+1 )\n YINTERP(K) = YIN(I+1)\n I =I +1\n ELSE\n DELTX =XIN(I+1)-XIN(I)\n IF (DELTX .LE. 0)THEN\n WRITE (*,*) 'WARNING: INPUT TIME STREAM NOT',\n &' MONOTONIC INCREASING'\n WRITE (66,*) 'WARNING: INPUT TIME STREAM NOT',\n &' MONOTONIC INCREASING' \nC RETURN !6/19/10\n END IF\n M = (YIN(I+1) - YIN(I))/DELTIN !! Orig. DELTX\n B = YIN(I) -M*XIN(I)\n YCAL(J) = M*XCAL(J) + B\nC WRITE(*,*) XCAL(J),YCAL(J) !! Diagnostic\n WRITE(2,*) XCAL(J),YCAL(J)\n YINTERP(K) = YCAL(J)\n END IF\n END DO\n WRITE (*,*) 'End of new data. ',\n &LENOT,' (x,y) pairs created'\n WRITE (*,*) 'Output file named XYINTERP'\nC WRITE (*,*) (YCAL(K),K=1,LENOT) !! Diagnostic\n RETURN\n END\n", "meta": {"hexsha": "214196bcde8bd8b7350ba44fdc2f50f6269f71e0", "size": 2698, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "SENN/INTERP.f", "max_stars_repo_name": "mwzappe/Ananke", "max_stars_repo_head_hexsha": "14900636ac4d6e263c8d24d271d88e2b1db7dc81", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-23T15:41:55.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-23T15:41:55.000Z", "max_issues_repo_path": "SENN/INTERP.f", "max_issues_repo_name": "mwzappe/Ananke", "max_issues_repo_head_hexsha": "14900636ac4d6e263c8d24d271d88e2b1db7dc81", "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": "SENN/INTERP.f", "max_forks_repo_name": "mwzappe/Ananke", "max_forks_repo_head_hexsha": "14900636ac4d6e263c8d24d271d88e2b1db7dc81", "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": 39.1014492754, "max_line_length": 72, "alphanum_fraction": 0.4988880652, "num_tokens": 922, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111796979521253, "lm_q2_score": 0.7310585844894971, "lm_q1q2_score": 0.6661257402004482}} {"text": "program improvedeulermethod\n implicit none\n real*8:: x, y, y1, xwant, h, fxy, fxy1, fe\n integer:: niter, i\n\n x= 0.0; y=0.0; h=0.001; xwant=1.57\n niter = int((xwant -x)/h)\n open(unit=21, file=\"improved_euler_method.dat\")\n\n do i=1,niter\n fxy = 1 + y**2\n y1 = y + h*fxy\n fe = 1 + y1**2\n fxy1 = (fxy+fe)/2\n y = y + h*fxy1\n\n write(21,*) dfloat(i)*h, y\n end do\n\nend program improvedeulermethod\n", "meta": {"hexsha": "8f62c569b8bd1c915b2d22b8125671af882f6313", "size": 456, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Solutions/assgn05_solns/Assgn05_Solutions/Assgn05_solutions_Q1/improvedeulermethod.f90", "max_stars_repo_name": "Anantha-Rao12/ComPhys", "max_stars_repo_head_hexsha": "235bbebcff0a0ba8b20380d4749a039bca060771", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Solutions/assgn05_solns/Assgn05_Solutions/Assgn05_solutions_Q1/improvedeulermethod.f90", "max_issues_repo_name": "Anantha-Rao12/ComPhys", "max_issues_repo_head_hexsha": "235bbebcff0a0ba8b20380d4749a039bca060771", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Solutions/assgn05_solns/Assgn05_Solutions/Assgn05_solutions_Q1/improvedeulermethod.f90", "max_forks_repo_name": "Anantha-Rao12/ComPhys", "max_forks_repo_head_hexsha": "235bbebcff0a0ba8b20380d4749a039bca060771", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.7142857143, "max_line_length": 53, "alphanum_fraction": 0.5307017544, "num_tokens": 189, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.911179705187943, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6661257401512045}} {"text": "use SoilClass\nimplicit none\n\n! create ground\ntype(Soil_) :: soil\ntype(Random_) :: random\ntype(FEMDomain_)::domain\ntype(DigitalElevationModel_) ::dem\nreal(real64),allocatable :: strain(:,:),stress(:,:),trSigma(:),allstress(:,:,:)\ninteger(int32),parameter :: num_node=10\nreal(real64) :: E, v\ninteger(int32) :: i,j\n\n! create mesh from Digital Elevetion Model (DEM)\n\n! create dummy DEM data\ndem%x = zeros(num_node)\ndem%y = zeros(num_node)\ndem%z = zeros(num_node)\ndo i=1, num_node\n dem%x(i) = random%gauss(mu=0.0d0,sigma=10.0d0)\n dem%y(i) = random%gauss(mu=0.0d0,sigma=10.0d0)\n dem%z(i) = random%gauss(mu=0.0d0,sigma=1.0d0) + 10.0d0\nenddo\n!domain%mesh%nodcoord = zeros(size(dem%x),3 )\n!domain%mesh%nodcoord(:,1) = dem%x\n!domain%mesh%nodcoord(:,2) = dem%y\n!domain%mesh%nodcoord(:,3) = dem%z\n\n!call domain%mesh%meshing()\n!call domain%mesh%convertTriangleToRectangular()\n!call print(domain%mesh%elemnod)\n!\n!call domain%vtk(\"tri\")\n!call domain%msh(\"tri\")\n\n\ncall soil%import(dem=dem,x_num=20,y_num=20,z_num=6)\n\ncall soil%msh(\"DEM\")\ncall soil%vtk(\"DEM\")\n\nsoil%YoungModulus = 10000.0d0\nsoil%PoissonRatio = 0.30d0\nsoil%Density = 1.60d0\nsoil%VoidRatio = 0.50d0\n\ncall soil%PreFlightCheck()\n\n! only gravity\ncall soil%deform(z_max=2.0d0,disp=[0.0d0,0.0d0,0.0d0])\n\n!do i=1,soil%femdomain%ne()\n! strain=soil%femdomain%StrainMatrix(ElementID=i,GaussPoint=2,disp=soil%disp)\n!enddo\nallstress=zeros(soil%femdomain%ne(),3,3 ) \n\ntrSigma = zeros(soil%femdomain%ne() )\ndo i=1,soil%femdomain%ne()\n E = soil%YoungModulus(i)\n v = soil%PoissonRatio(i)\n stress=soil%femdomain%stressMatrix(ElementID=i,E=E,v=v,disp=soil%disp)\n trSigma(i) = trace(stress)\n allstress(i,:,:) = stress(:,:)\nenddo\n\n! result\ncall soil%vtk(\"DEM_deformed\")\ncall soil%vtk(\"DEM_deformed_s11\",scalar=trSigma,ElementType=VTK_HEXAHEDRON)\ncall soil%vtk(\"DEM_deformed_disp\",vector=soil%disp,ElementType=VTK_HEXAHEDRON)\ncall soil%vtk(\"DEM_deformed_str\",tensor=allstress,ElementType=VTK_HEXAHEDRON)\n\n\nend", "meta": {"hexsha": "73a91233aacd1d0306fa8060701e057e089151d5", "size": 1972, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/playon_obj/CreateSoilFromDem.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/obj/CreateSoilFromDem.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/obj/CreateSoilFromDem.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": 26.6486486486, "max_line_length": 80, "alphanum_fraction": 0.7175456389, "num_tokens": 724, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797124237604, "lm_q2_score": 0.7310585727705126, "lm_q1q2_score": 0.6661257401019604}} {"text": " SUBROUTINE isoha14(isohd,yield,aprim,eps,c0,c1,c2,c3)\r\n IMPLICIT NONE\r\n\r\n INTEGER(kind=4),INTENT(IN) :: isohd\r\n REAL(kind=8),INTENT(IN):: c0, c1, c2, c3, eps\r\n REAL(kind=8),INTENT(OUT):: yield,aprim\r\n !Local variables\r\n! INTEGER (kind=4) :: i\r\n REAL(kind=8),PARAMETER:: tol=1d-10\r\n\r\n SELECT CASE (isohd)\r\n ! c0 = props(1) !C0 constant or Initial Yield\r\n ! c1 = props(2) !Efref or Hardening constant\r\n ! c2 = props(3) !exponent\r\n ! c3 = props(4) !residual flow stress\r\n CASE(1) !No hardening\r\n yield = c0\r\n aprim = 0d0\r\n\r\n CASE(2,5) !Linear Law (include defined by points)\r\n yield = c0 + c1*eps\r\n aprim = c1\r\n\r\n CASE(3) !Ludwik-Nadai Law\r\n yield = c0*(c1 + eps)**c2\r\n aprim = c0*c2*(c1 + eps)**(c2-1d0)\r\n\r\n CASE(4) !Exponential + saturation\r\n yield = c0 + c1*eps+(c3-c0)*(1d0-1d0/EXP(c2*eps))\r\n aprim = c1 + (c3-c0)*c2/EXP(c2*eps) !derivative\r\n\r\n CASE(6) !Hollomon Law\r\n yield = c0*(eps + tol)**c2\r\n aprim = c0*c2*(eps + tol)**(c2-1d0)\r\n\r\n CASE(7) !Voce Law\r\n yield = c0 + c1*(1d0 - EXP(-c2*eps))\r\n aprim = c1*c2*EXP(-c2*eps)\r\n\r\n END SELECT\r\n\r\n RETURN\r\n END SUBROUTINE isoha14\r\n", "meta": {"hexsha": "1266c05de970268830f3059d1d80c2cb263053ec", "size": 1180, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/matdb/isoha14.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/matdb/isoha14.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/matdb/isoha14.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": 26.8181818182, "max_line_length": 67, "alphanum_fraction": 0.5677966102, "num_tokens": 464, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545362802362, "lm_q2_score": 0.7025300698514778, "lm_q1q2_score": 0.6661070726029499}} {"text": " subroutine ire_dgtheta(ctfm,ctfmp,n_Athth,n_B,n_alpha,n_beta,n_div\n &beta,nm1_B,np1_B,Nx,ht,hx,vee,res)\n implicit none\n integer i\n integer Nx\n real*8 ht\n real*8 hx\n real*8 vee\n real*8 ctfm(Nx)\n real*8 ctfmp(Nx)\n real*8 n_Athth(Nx)\n real*8 n_B(Nx)\n real*8 n_alpha(Nx)\n real*8 n_beta(Nx)\n real*8 n_divbeta(Nx)\n real*8 nm1_B(Nx)\n real*8 np1_B(Nx)\n real*8 res\n real*8 qb\n res = 0.0D0\n do i=2, Nx-1, 1\n qb = 0.5000000000000000D0 * (-0.1D1 * nm1_B(i) + np1_B(i)) / ht + \n #0.6666666666666667D0 * vee * n_divbeta(i) * n_B(i) + 0.50000000000\n #00000D0 / ctfmp(i) * (n_B(i - 1) - 0.1D1 * n_B(i + 1)) / hx * n_be\n #ta(i) + 0.2D1 * n_Athth(i) * n_alpha(i) - 0.2D1 / ctfm(i) * n_B(i)\n # * n_beta(i)\n res = res + qb**2\n end do\n res = sqrt(res/(1*Nx))\n END\n", "meta": {"hexsha": "6ed789ea1cc072d5a685c8f56a611ae22d82a19e", "size": 889, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/FD/ire_dgtheta.f", "max_stars_repo_name": "rmanak/bssn_spher", "max_stars_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/FD/ire_dgtheta.f", "max_issues_repo_name": "rmanak/bssn_spher", "max_issues_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/FD/ire_dgtheta.f", "max_forks_repo_name": "rmanak/bssn_spher", "max_forks_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.6774193548, "max_line_length": 72, "alphanum_fraction": 0.5309336333, "num_tokens": 389, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122113355091, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.6660756113363829}} {"text": "program mainPecScattering\n use pec_scattering\n use data_tools\n implicit none\n\n integer :: n_points = 20 ! points per dimension in mesh\n integer :: n_terms = 50 ! number of terms in Mie series\n real(8) :: k = 3.5d0 ! wavenumber [1/m]\n real(8) :: a = 2.4d0 ! sphere radius [m]\n real(8) :: alpha = PI / 30 ! incident angle in (0, pi)\n complex(8) :: Eo = 3.3d0 ! incident electric field amplitud [V/m]\n\n real(8), allocatable :: xyz_list(:, :)\n complex(8), allocatable :: Ei_TE(:, :)\n complex(8), allocatable :: Es_TE(:, :)\n complex(8), allocatable :: Ei_TM(:, :)\n complex(8), allocatable :: Es_TM(:, :)\n\n ! spherical mesh\n call spherical_mesh(a, n_points, xyz_list)\n\n ! rectangular mesh, without sphere\n !call rectangular_mesh(a, -5d0, 5d0, -5d0, 5d0, 0d0, 0d0, n_points, xyz_list)\n\n ! TE scattering\n call sphere_plane_scattering_TE(xyz_list, k, a, alpha, Eo, n_terms, Es_TE)\n call incident_plane_wave_TE(xyz_list, k, alpha, Eo, Ei_TE)\n\n ! TM scattering\n call sphere_plane_scattering_TM(xyz_list, k, a, alpha, Eo, n_terms, Es_TM)\n call incident_plane_wave_TM(xyz_list, k, alpha, Eo, Ei_TM)\n\n ! save real part of total field\n call save_data(xyz_list, dreal(Ei_TE + Es_TE), \"data_TE.txt\")\n call save_data(xyz_list, dreal(Ei_TM + Es_TM), \"data_TM.txt\")\n\nend program\n", "meta": {"hexsha": "b9c333323863f62601c8ac572c4fa3d4911cf7b4", "size": 1358, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/SpherePEC/mainPecScattering.f90", "max_stars_repo_name": "Riarrieta/WindowedGreenFunctionMethod", "max_stars_repo_head_hexsha": "e6f965cac1acd8d9922e2bf94c33e3577ceb0dc9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/SpherePEC/mainPecScattering.f90", "max_issues_repo_name": "Riarrieta/WindowedGreenFunctionMethod", "max_issues_repo_head_hexsha": "e6f965cac1acd8d9922e2bf94c33e3577ceb0dc9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/SpherePEC/mainPecScattering.f90", "max_forks_repo_name": "Riarrieta/WindowedGreenFunctionMethod", "max_forks_repo_head_hexsha": "e6f965cac1acd8d9922e2bf94c33e3577ceb0dc9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.7368421053, "max_line_length": 81, "alphanum_fraction": 0.6494845361, "num_tokens": 438, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336202, "lm_q2_score": 0.7431680086124812, "lm_q1q2_score": 0.6660653481879144}} {"text": "! *******************************************************************\r\n! * *\r\n! * Function dlafr2 *\r\n! * *\r\n! *******************************************************************\r\n! Double Precision Version 1.41\r\n! Written by Gordon A. Fenton, TUNS, Apr. 27, 1994\r\n! Latest Update: May 9, 2001\r\n!\r\n! PURPOSE returns the covariance between two points in an isotropic 2-D\r\n! fractional noise field.\r\n!\r\n! This function computes and returns the covariance between two points,\r\n! separated by the distance T, in a 2-D fractional Gaussian noise\r\n! (fGn) process. The radial covariance function of the fractional\r\n! noise process is given by\r\n!\r\n! var 2H 2H 2H\r\n! B(s) = -------- [ |s + pb| - 2|s| + |s - pb| ]\t\t(1)\r\n! 2H\r\n! 2*pb\r\n!\r\n! where `pb' is the length over which the fractional Brownian motion\r\n! is averaged in order to make this, the derivative process, exist,\r\n! and s is the Euclidean length of the lag vector {X,Y}, s = sqrt(X*X+Y*Y).\r\n! Normally `pb' is selected to be quite small (of the order of the\r\n! size of the discretization interval).\r\n!\r\n! If var < 0, then this function returns the variance of a local average\r\n! of the process, |var|*V(D), averaged over the domain `D' (see below).\r\n! The variance function which yields a close approximation to the above\r\n! radial covariance function is given by\r\n!\r\n! r r r r\r\n! |D + pb| - 2( |D| + |pb| ) + |D - pb|\r\n! V(D) = --------------------------------------------------\t(2)\r\n! 2 2H\r\n! D * (2H+1)*(2H+2)*pb\r\n!\r\n! where r = (2H+2) and D = |X| + |Y| (the 1-norm of {X,Y}, where now X and\r\n! Y are the dimensions of the rectangular averaging region). The actual\r\n! covariance function corresponding to (2) is equal to (1) along the\r\n! coordinate axes, and remains close to (1) for H > 0.8. For H < 0.7,\r\n! the covariance in the diagonal direction is too high, but since the\r\n! covariance in such fields dies off very rapidly, the error is\r\n! believed negligible.\r\n! \r\n! Parameters to this process are brought in through the common block\r\n! /dparam/ and are described as follows;\r\n!\r\n! var\tthe point variance of the fGn process.\r\n!\r\n! pb\tthe averaging length discussed above.\r\n!\r\n! H\t\tthe Hurst exponent. In this implementation, 0.5 < H < 1;\r\n!\t\tvalues of H near 1 yield a correlation structure which\r\n!\t\tremains very high (and thus a covariance matrix which may\r\n!\t\tbe nearly singular). Values of H near 0.5 yield a band-\r\n!\t\tlimited white noise process.\r\n!\r\n! da, db\tdummy placeholders provided so that the common block /dparam/\r\n!\t\thas the same form for a variety of variance functions.\r\n!\r\n! Arguments to this function are just the components, X and Y, of the lag\r\n! vector separating the two points (or the dimensions of the\r\n! physical averaging region, if var < 0).\r\n!\r\n! REVISION HISTORY:\r\n! 1.1\tadded lvarfn flag to end of /dparam/ common block. Set it to\r\n!\ttrue if the variance function is to be returned. Otherwise this\r\n!\tfunction returns the covariance. (Apr 29/00)\r\n! 1.2\teliminated lvarfn -- now return covariances only if var < 0 (Mar 27/01)\r\n! 1.3\tproperly handled sign on var for covariances (Apr 5/01)\r\n! 1.4\treversed default - now return covariances if var > 0 (Apr 11/01)\r\n! 1.41\trevised above documentation to reflect revision 1.4 (May 9/01)\r\n!---------------------------------------------------------------------- \r\n real*8 function dlafr2( X, Y )\r\n implicit real*8 (a-h,o-z)\r\n common/dparam/ var, pb, H, da, db\r\n data zero/0.d0/, one/1.d0/, two/2.d0/\r\n abs(q) = dabs(q)\r\n sqrt(q) = dsqrt(q)\r\n!\r\n e0 = two*H\r\n if( var .lt. zero ) then\t\t\t! return variance function\r\n if( (X.eq. zero) .and. (Y .eq. zero) ) then\r\n dlafr2 = -var\r\n else\r\n D = abs(X) + abs(Y)\r\n e1 = e0 + one\r\n e2 = e0 + two\r\n t1 = (D+pb)**e2 - two*(D**e2 + pb**e2) + abs(D-pb)**e2\r\n dlafr2 = -var*t1/(D*D*e1*e2*pb**e0)\r\n endif\r\n else\t\t\t\t\t! var < 0, return covariance\r\n D = sqrt(X*X + Y*Y)\r\n t1 = (D+pb)**e0 - two*(D**e0) + abs(D-pb)**e0\r\n dlafr2 = var*t1/(two*(pb**e0))\r\n endif\r\n\r\n return\r\n end\r\n", "meta": {"hexsha": "f5506f574292045da3b6d7915cb2932944cb98ee", "size": 4583, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/libs/gaf95/dlafr2.f95", "max_stars_repo_name": "leemargetts/PoreFEM", "max_stars_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/libs/gaf95/dlafr2.f95", "max_issues_repo_name": "leemargetts/PoreFEM", "max_issues_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/libs/gaf95/dlafr2.f95", "max_forks_repo_name": "leemargetts/PoreFEM", "max_forks_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.4951456311, "max_line_length": 79, "alphanum_fraction": 0.5308749727, "num_tokens": 1273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513703624558, "lm_q2_score": 0.7431680029241322, "lm_q1q2_score": 0.666065341030283}} {"text": "C *********************************************************\nC * *\nC * SUBROUTINE 04.03.02.02/hueang *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE HUEANG (R,G,B, ANG, DIST)\n\nC This program calculates a characteristic angle for a hue from the\nC RGB color cube. It does so by rotating the cube 45 deg around the\nC y-axis and atan(sqrt(2)) around the z-axis (assuming xyz = RGB).\nC This lines up the black-white cube diagonal (0,0,0 to 1,1,1) along\nC the y-axis. Now, transformed points along the color-saturated\nC vertices are such that their angle in the x-z plane is a measure\nC of hue; so atan2 is used to compute the hue of any RGB point.\n\nC BTW, somewhat surprisingly, the points which are transformed into\nC the x=0 plane are all those in the old plane described by:\nC x -2y + z = 0 (this plane contains the points (0,0,0), (1,1,1),\nC and (0,.5,1), all of which can be \"seen\" to be rotated into x=0\nC plane). This plane is such that it is satisfied by any points of\nC the form: (q, q+c, q+2c), so that sample points like (3,4,5) will\nC always transform into the x=0 plane.\n\nC Hueang also returns the distance of the RGB point from the\nC neutral (black-white) axis.\n\n REAL TMAT(4,4), R,G,B, XO,YO,ZO, PI,A45, ZZ,U, ANG, DIST\n\n ZZ = 0.0\n U = 1.0\n PI = 3.14159265\n A45 = PI/4.0\n\n CALL EBLTM3 (ZZ,ZZ,ZZ, ZZ,ZZ,ZZ, ZZ,A45,ATAN(SQRT(2.0)),\n 1 U,U,U, TMAT)\n\n10 CONTINUE\n\n CALL ETP3 (R,G,B, TMAT, XO,YO,ZO)\n\n DIST = SQRT(XO*XO + ZO*ZO)\n\n IF (DIST .EQ. ZZ) THEN\n ANG = -666.0\n ELSE\nC Normalize to 0..1\n ANG = ATAN2(XO,ZO) / (2*PI)\n IF (ANG .LT. 0.0) ANG = ANG + 1\n ENDIF\n\n END\n\nC *********************************************************\nC * *\nC * REAL FUNCTION 04.03.02.02/modsep *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n REAL FUNCTION MODSEP (PERIOD, A, B)\n\nC Given a period and two values, a and b, modsep calculates the\nC absolute value of the smallest \"distance\" between the values,\nC treating them as points on a circle with circumference of size =\nC period. For example, if period=360, as for degree-measure,\nC modsep of 5 and 15 would of course be 10, but so would modsep of\nC 5 and 355, or 0 and 710, or 0 and 730.\n\n REAL PERIOD, A, B, AM,BM, ABDIF\n\n IF (PERIOD .EQ. 0.0) THEN\n MODSEP = 0.0\n RETURN\n ENDIF\n\nC get normalized mod-values - correct for loopy way Fortran\nC mods negative numbers.\n AM = MOD (A,PERIOD)\n IF (A.LT.0) AM = AM+PERIOD\n BM = MOD (B,PERIOD)\n IF (B.LT.0) BM = BM+PERIOD\nC now: 0 .le. am,bm .lt. period\n\n ABDIF = ABS(AM-BM)\n MODSEP = MIN (ABDIF, PERIOD-ABDIF)\n\n END\n\nC *********************************************************\nC * *\nC * LOGICAL FUNCTION 04.03.02.02/undcmd *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n LOGICAL FUNCTION UNDCMD (NUMMOD,MODLIS,HICOL,PROMPT)\n\nC UNDCMD tests the list of color models passed in by requesting\nC dimensions and drawing color patches using those dimensions.\nC The operator is asked if the displayed color matches the\nC randomly chosen color coordinates.\n\nC Input parameters:\nC NUMMOD : Size of list of color models \nC MODLIS : Entire list of color models which may be tested\nC HICOL : Highest color index to be used\nC PROMPT : String for prompt, indicating documentation to\nC be used for reference\n\n COMMON /GLOBNU/ CTLHND, ERRSIG, ERRFIL, IERRCT, UNERR,\n 1 TESTCT, IFLERR, PASSSW, ERRSW, MAXLIN,\n 2 CONID, MEMUN, WKID, WTYPE, GLBLUN, INDLUN,\n 3 DUMINT, DUMRL\n INTEGER CTLHND, ERRSIG, ERRFIL, IERRCT, UNERR,\n 1 TESTCT, IFLERR, PASSSW, ERRSW, MAXLIN,\n 2 CONID, MEMUN, WKID, WTYPE, GLBLUN, INDLUN,\n 3 DUMINT(20), ERRIND\n REAL DUMRL(20)\n\n COMMON /DIALOG/ DOUTYP, DINTYP, DSTDNR, DSTRID, PSTRID, DTCLIM,\n 1 SCRMOD, DTXCI, SPECWT,\n 2 DSIZE, EFRAC, DYXRAT, SYXRAT, MTRPDC, WCPDC, QVIS\n INTEGER DOUTYP, DINTYP, DSTDNR, DSTRID, PSTRID, DTCLIM,\n 1 SCRMOD, DTXCI, SPECWT\n REAL DSIZE, EFRAC, DYXRAT, SYXRAT, MTRPDC, WCPDC, QVIS\n\nC interior style \n INTEGER PHOLLO, PSOLID, PPATTR, PHATCH, PISEMP\n PARAMETER (PHOLLO=0, PSOLID=1, PPATTR=2, PHATCH=3, PISEMP=4)\n\nC type of returned values set, realized\n INTEGER PSET, PREALI\n PARAMETER (PSET=0, PREALI=1)\n\n INTEGER CMDIM, NUMCM, COLIX, NUMCL, RANLIS(8), NUMTST\n INTEGER CM, ICM, II, IX, ITRIM, POS1, NUMMOD, MODLIS(*), HICOL\n\n REAL LO(8), HI(8), ACTCOL(8), COLARY(8)\n REAL YLO,YHI, YTOP, YINCR, RNDRL\n\n CHARACTER CVAL*5, MSG*200, PROMPT*(*), RVALS*80\n\n LOGICAL DYN, FILMOD, INTSTY, LOMAG\n\nC Determine how to fill in rectangles, use solid style\nC if it is available, otherwise use dense polyline cross-hatch\n FILMOD = INTSTY(SPECWT, PSOLID)\nC number of models to test\n NUMTST = MIN(8, NUMMOD)\nC Test a random subset of the models if > 8\n CALL RNSET (NUMTST,NUMMOD,RANLIS)\n\n DO 140 ICM = 1,NUMTST\n CALL PEMST (102)\nC Set Color Model\n CM = MODLIS(RANLIS(ICM))\n CALL PSCMD (WKID, CM)\n\n WRITE (CVAL, '(I5)') CM\n CALL DCHOIC ('DIMENSION OF COLOUR MODEL: How many ' //\n 1 'dimensions are there for colour model ' // \n 2 CVAL // '?', 0,100, CMDIM)\n\n IF (CMDIM .EQ. 0) THEN\n CALL INMSG ('Operator reported zero dimensions for a ' //\n 1 'color model.')\n UNDCMD = .FALSE.\n RETURN\n ENDIF\n\nC determine format for displaying color coordinates\n LOMAG = .TRUE.\n DO 100 IX = 1, CMDIM\n WRITE(CVAL, '(I5)') IX\n CALL DRLVAL('DIMENSION BOUNDS: Enter the LOWER limit ' //\n 1 'for valid values for dimension # ' //\n 2 CVAL, LO(IX))\n CALL DRLVAL('DIMENSION BOUNDS: Enter the UPPER limit ' //\n 1 'for valid values for dimension # ' //\n 2 CVAL, HI(IX))\n IF (ABS (LO(IX)) .GE. 10.0) LOMAG = .FALSE.\n IF (ABS (HI(IX)) .GE. 10.0) LOMAG = .FALSE.\n100 CONTINUE\n\nC Draw color patches down left side of screen:\n NUMCM = HICOL - 1\n YINCR = 1.0 / (NUMCM + 1.0)\n YTOP = 1 - YINCR\n YLO = YTOP - 0.25*YINCR\n YHI = YTOP + 0.25*YINCR\n CALL NUMLAB (NUMCM, 0.15, YTOP, YINCR)\n\n DO 130, COLIX = 2, HICOL\n DO 110 IX = 1, CMDIM\n COLARY(IX) = RNDRL(LO(IX),HI(IX))\n110 CONTINUE\n\n CALL PSCR (WKID, COLIX, CMDIM, COLARY)\nC determine actual colval\n CALL PQCR (WKID,COLIX, CMDIM, PREALI, ERRIND, NUMCL,ACTCOL)\n CALL CHKINQ ('pqcr', ERRIND)\n\n IF (NUMCL .NE. CMDIM) THEN\n WRITE (MSG, '(A,I5,A,I5,A,I5,A)') 'Reported ' //\n 1 'dimensionality for color model #', CM, ' is ', \n 2 NUMCL, '; does not match value specified by ' //\n 3 'operator = ', CMDIM, '.'\n CALL INMSG (MSG)\n UNDCMD = .FALSE.\n RETURN \n ENDIF\n\n CALL COLPCH (FILMOD, COLIX, 0.2, YLO, 0.5, YHI)\nC format color coordinates for printing\n RVALS = ' '\n DO 120 II = 1, NUMCL\n IF (LOMAG) THEN\n POS1 = 6*II - 5\n WRITE (RVALS(POS1:POS1+5), '(A,F5.2)') ',', ACTCOL(II)\n ELSE\n POS1 = 10*II - 9\n WRITE (RVALS(POS1:POS1+9), '(A,E9.2)') ',', ACTCOL(II)\n ENDIF\n120 CONTINUE\n CALL VISLAB (RVALS(2:ITRIM(RVALS)), 'L', 0.55,0.95, YLO,YHI)\n\n YLO = YLO-YINCR\n YHI = YHI-YINCR\n\nC next random color within color model\n130 CONTINUE\n\n WRITE (MSG, '(A,I5,A,A,A)') 'ACCURACY OF COLOUR MODEL: ' //\n 1 'Are the colours of the rectangles compatible ' //\n 2 'with the corresponding colour coordinate values ' //\n 3 'within colour model #', CM, ', according to the ', \n 4 PROMPT, '?'\n\n IF (DYN (MSG)) THEN\nC OK so far\n ELSE\n WRITE (CVAL, '(I5)') CM\n CALL INMSG ('Color Model #' // CVAL // ' caused failure.')\n UNDCMD = .FALSE.\n RETURN\n ENDIF\nC next color model\n140 CONTINUE\n UNDCMD = .TRUE.\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE 04.03.02.02/colpch *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE COLPCH (FILMOD, CLOR, XLO,YLO,XHI,YHI)\n\nC COLPCH will generate a rectangular color patch with the specified\nC diagonal vertices. It will use solid interior fill area or\nC polylines based on the specified filling mode.\n\nC Input parameters:\nC FILMOD : use fill area if true, otherwise polyline\nC CLOR : color index to use\nC XLO,YLO,XHI,YHI : extent of the rectangle\n\n INTEGER CLOR\n\n REAL FILX(4), FILY(4), YINC, XLO,XHI,YLO,YHI, YVAL\n\n LOGICAL FILMOD\n\nC interior style hollow, solid, pattern, hatch, empty\n INTEGER PHOLLO, PSOLID, PPATTR, PHATCH, PISEMP\n PARAMETER(PHOLLO=0, PSOLID=1, PPATTR=2, PHATCH=3, PISEMP=4)\nC linetype\n INTEGER PLSOLI, PLDASH, PLDOT, PLDASD\n PARAMETER (PLSOLI = 1, PLDASH = 2, PLDOT = 3, PLDASD = 4)\n\n FILX(1) = XLO\n FILX(2) = XHI\n FILX(3) = XHI\n FILX(4) = XLO\n\n IF (FILMOD) THEN\n FILY(1) = YLO\n FILY(2) = YLO\n FILY(3) = YHI\n FILY(4) = YHI\n\n CALL PSIS (PSOLID)\n CALL PSICI (CLOR)\n CALL PFA (4, FILX,FILY)\n ELSE\n CALL PSLN (PLSOLI)\n CALL PSPLCI (CLOR)\nC paint lines at the rate of about 400/screen\n YINC = 1.0/400\n DO 100 YVAL = YLO, YHI, YINC\n FILY(1) = YVAL\n FILY(2) = YVAL\n CALL PPL (2, FILX,FILY)\n 100 CONTINUE\n ENDIF\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE 04.03.02.02/coltrn *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE COLTRN (WKID, COLABL, FROMCC, FROMMD, TOCC, TOMD, SRS)\n\nC COLTRN tests the ability to translate color from one model to\nC another and issues pass or fail as a result.\n\nC Input parameters:\nC WKID : workstation identifier\nC COLABL : labels (names) of colors to be tested\nC FROMCC : color coordinates to translate from\nC FROMMD : color model to translate from\nC TOCC : color coordinates to translate to (expected result)\nC TOMD : color model to translate to\nC SRS : SR identifiers for test case\n\nC colour model\n INTEGER PRGB, PCIE, PHSV, PHLS\n PARAMETER (PRGB=1, PCIE=2, PHSV=3, PHLS=4)\n\nC type of returned value\n INTEGER PSET, PREALI\n PARAMETER (PSET = 0, PREALI = 1)\n\n INTEGER WKID, FROMMD, TOMD, IX,IY, NUMRET, ERRIND, PASSCT\n\n REAL FROMCC(3,9), TOCC(3,9), CSPEC(3),ACTCOL(3),EXPCOL(3)\n REAL RNDRL\n\n LOGICAL COLEQL\n\n CHARACTER MSG*300, SRS*(*), MODNAM(PRGB:PHLS)*3, COLABL(9)*8\n\n DATA MODNAM / 'RGB', 'CIE', 'HSV', 'HLS' /\n\n PASSCT = 0\n DO 100 IX = 1,9\nC \n CALL PSCMD (WKID, FROMMD)\nC index #1, entry #ix, change -1 to\nC random value between 0 and 1\n DO 110 IY = 1,3\n IF (FROMCC(IY,IX) .EQ. -1) THEN\n CSPEC(IY) = RNDRL (0., 1.)\n ELSE\n CSPEC(IY) = FROMCC(IY,IX)\n ENDIF\n EXPCOL(IY) = TOCC(IY,IX)\n110 CONTINUE\n CALL PSCR (WKID, 1, 3, CSPEC)\n CALL PQCR (WKID, 1, 3, PREALI, ERRIND, NUMRET, ACTCOL)\n CALL CHKINQ ('pqcr', ERRIND)\nC attempt to convert only realizable colors\n IF (.NOT. COLEQL (3, ACTCOL, CSPEC, 0.02, 0.0)) GOTO 100\n\nC \n CALL PSCMD (WKID, TOMD)\nC as SET, to determine cspec\n CALL PQCR (WKID, 1, 3, PSET, ERRIND, NUMRET, ACTCOL)\n CALL CHKINQ ('pqcr', ERRIND)\n\n IF (NUMRET.EQ.3 .AND.\n 1 COLEQL (3, ACTCOL, EXPCOL, 0.1, 0.0)) THEN\nC OK so far\n PASSCT = PASSCT+1\n ELSE\n PASSCT = -666\n WRITE (MSG, '(A)') 'Fail to change colour model from ' //\n 1 MODNAM(FROMMD) // ' to ' // MODNAM(TOMD) // \n 2 ' for colour = ' // COLABL(IX) // '.'\n CALL INMSG (MSG)\n ENDIF\n100 CONTINUE\n\n IF (PASSCT .EQ. 0) THEN\n CALL INMSG ('No realizable ' // MODNAM(FROMMD) // \n 1 ' colors for ' // MODNAM(FROMMD) // ' to ' // \n 2 MODNAM(TOMD) // ' conversion test.')\n ELSE\n CALL SETMSG (SRS, 'Changing the colour model from ' //\n 1 MODNAM(FROMMD) // ' to ' // MODNAM(TOMD) // \n 2 ' should not affect the colours in the ' //\n 3 'colour table.')\n CALL IFPF (PASSCT .GT. 0)\n ENDIF\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE 04.03.02.02/sethue *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE SETHUE (WKID,COLMOD,MAXFG,PALTTE,CC, NUMSET,LSCOLI)\n\nC SETHUE tries to set as many hues as possible in the color table\nC and reports back the order in which they were set and how many.\nC\nC Input parameters\nC WKID : workstation identifier\nC COLMOD : Color model to set up under\nC MAXFG : Maximum number of available foreground entries in\nC color table, starting with #2\nC PALTTE : Number of colors to be displayed if possible\nC CC : Color coordinates to be set in color table\nC\nC Output parameters\nC NUMSET : Number of entries successfully set\nC LSCOLI : List of which entries in CC (palette) were set\n\nC type of returned value\n INTEGER PSET, PREALI\n PARAMETER (PSET = 0, PREALI = 1)\nC colour model\n INTEGER PRGB, PCIE, PHSV, PHLS\n PARAMETER (PRGB = 1, PCIE = 2, PHSV = 3, PHLS = 4)\n\n INTEGER COLMOD, MAXFG, PALTTE, NUMSET, LSCOLI(*)\n INTEGER RNCOL(20), IX, IY, ERRIND, CCSIZ, WKID, NUMDSP, PALIX\n\n REAL CC(3,PALTTE), THISCC(3), REALCC(3), RNDRL\n\n LOGICAL COLEQL, COLOK\n\n CALL PSCMD (WKID, COLMOD)\n\nC max number to be displayed\n NUMDSP = MIN(MAXFG, PALTTE)\n CALL RNSET (NUMDSP, PALTTE, RNCOL)\n\nC how many set so far?\n NUMSET = 0\n DO 100 IX = 1,NUMDSP\nC which color in palette to try\n PALIX = RNCOL(IX)\n DO 110 IY = 1,3\n THISCC(IY) = CC(IY, PALIX)\nC treat -1 as a \"don't care\" value\n IF (THISCC(IY) .EQ. -1) THISCC(IY) = RNDRL (0.,1.)\n110 CONTINUE\n CALL PSCR (WKID, NUMSET+2, 3, THISCC)\n CALL PQCR (WKID, NUMSET+2, 3, PREALI, ERRIND, CCSIZ, REALCC)\n CALL CHKINQ ('pqcr', ERRIND)\n IF (CCSIZ .NE. 3) GOTO 100\nC is realized hue close enough ??\n IF (COLMOD .EQ. PCIE) THEN\n COLOK = COLEQL(2, REALCC, THISCC, 0.01, 0.0) .AND.\n 1 COLEQL(1, REALCC(3), THISCC(3), 0.1, 0.0)\n ELSE\n COLOK = COLEQL(3, REALCC, THISCC, 0.05, 0.0)\n ENDIF\n\n IF (COLOK) THEN\nC add to list\n NUMSET = NUMSET+1\n LSCOLI(NUMSET) = PALIX\n ELSE\nC not set\n ENDIF\n100 CONTINUE\n\n END\n\nC *********************************************************\nC * *\nC * INTEGER FUNCTION 04.03.02.02/tsthue *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n INTEGER FUNCTION TSTHUE (PRMPT, FILMOD, NUMSET, LSCOLI)\n\nC TSTHUE displays NUMSET colors, starting with #2, using LSCOLI as\nC color indices. It then asks the operator to identify these and\nC issues 1 (pass), -1 (fail), or -2 (fail with comment), as a result. \nC\nC Input parameters:\nC PRMPT : prompt for the operator\nC FILMOD : fill mode for rectangle; true for solid fill area,\nC false for polylines\nC NUMSET : number of colored rectangles to be drawn\nC LSCOLI : list of identifiers from color palette\n\n INTEGER NUMSET, LSCOLI(*), IX, ANSSIZ, ANSLIS(20)\n\n REAL YTOP, YINCR, YVAL\n\n LOGICAL FILMOD, IAREQL\n\n CHARACTER PRMPT*(*)\n\n YINCR = 1.0 /(NUMSET+1)\n YTOP = 1-YINCR\n YVAL = YTOP - 0.25*YINCR\n\n DO 120 IX = 1,NUMSET\n CALL COLPCH (FILMOD, IX+1, .25,YVAL, .75,YVAL + 0.5*YINCR)\n CALL PSPLCI (1)\n CALL DRWREC (.25,.75, YVAL,YVAL + 0.5*YINCR)\n YVAL = YVAL-YINCR\n120 CONTINUE\n\n CALL DILIST (PRMPT, ANSSIZ, ANSLIS)\n IF (ANSSIZ.EQ.1 .AND. ANSLIS(1).EQ.0) THEN\n TSTHUE = -2\n ELSEIF (IAREQL (ANSSIZ,ANSLIS, NUMSET,LSCOLI)) THEN\n TSTHUE = 1\n ELSE\n TSTHUE = -1\n ENDIF\n\n CALL PEMST (102)\n\n END\n\nC *********************************************************\nC * *\nC * LOGICAL FUNCTION 04.03.02.02/coleql *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n LOGICAL FUNCTION COLEQL (SIZE, ACT,EXP, ABSERR,RELERR)\n\nC Special purpose routine for testing approximate equality of\nC all three color components, unless one is -1.\n\nC Input parameters:\nC SIZE : Number of elements to be compared\nC ACT : actual values\nC EXP : expected values\nC ABSERR : absolute tolerance\nC RELERR : relative tolerance\n\n INTEGER SIZE, IX\n REAL ACT(SIZE), EXP(SIZE), ABSERR, RELERR\n LOGICAL APPEQ\n\n DO 100 IX = 1,SIZE\n IF (ACT(IX) .EQ. -1 .OR. EXP(IX) .EQ. -1) THEN\nC OK so far\n ELSEIF (APPEQ (ACT(IX), EXP(IX), ABSERR, RELERR)) THEN\nC OK so far\n ELSE\n COLEQL = .FALSE.\n RETURN\n ENDIF\n100 CONTINUE\n COLEQL = .TRUE.\n\n END\n", "meta": {"hexsha": "53168c40fe2ad670e6616f40ae60358d028dd68e", "size": 20174, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "third_party/Phigs/PVT/PVT_fort/04/03/02/02/sublib.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/04/03/02/02/sublib.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/04/03/02/02/sublib.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": 34.7827586207, "max_line_length": 72, "alphanum_fraction": 0.4980668187, "num_tokens": 6115, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513648201267, "lm_q2_score": 0.743167997235783, "lm_q1q2_score": 0.6660653318132106}} {"text": "program poisson \n!----------------------------------------------------------------------\n ! This parallel code solves for the 2D Laplace equation\n ! using 1D decomposition \n!----------------------------------------------------------------------\n \n implicit none \n include 'mpif.h'\n\n !-----------Define the parameters, variables---------\n\n integer :: nprocs, rank, ierr, np\n integer, parameter :: m = 250, n = 250, max_iter = 10000 \n real(kind = 8), parameter :: tol = 1.e-5\n real(kind = 8) :: t0, t1, t2, diff, max_val\n real(kind = 8), dimension(:,:), allocatable :: aloc\n integer, dimension(:), allocatable :: jbeg, jend\n integer :: istat(MPI_STATUS_SIZE)\n logical :: converged\n integer :: i\n !----------------------------------------------------\n\n\n call MPI_INIT(ierr)\n t0 = MPI_WTIME()\n\n call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)\n call MPI_COMM_SIZE(MPI_COMM_WORLD, nprocs, ierr)\n\n np = n/nprocs + 1 ! Maximum length of the local array on any proc\n allocate(aloc(0:m+1,0:np+1))\n allocate(jbeg(0:nprocs-1)) \n allocate(jend(0:nprocs-1))\n\n\n ! Print the welcome statement \n print *, 'I am P:',rank,'out of',nprocs\n call decompose(n, nprocs, jbeg, jend)\n\n\n !Set the boundary conditions\n call bc(aloc, 1, m, jbeg(rank), jend(rank), m, n, rank, nprocs)\n\n !Communication across the ghost cells\n call comm(m, nprocs, jbeg(rank), jend(rank), aloc, rank)\n \n t1 = MPI_WTIME()\n !Start the time loop \n do i = 1, max_iter\n call jacobi_step(m, n, 1, m, jbeg(rank), jend(rank), nprocs, rank, aloc, &\n diff, max_val)\n \n !Check for convergence of the solution \n if (converged(diff, max_val, tol, rank)) then \n exit\n end if\n \n !Exchange the ghost cell data \n call comm(m, nprocs, jbeg(rank), jend(rank), aloc, rank)\n end do\n t2 = MPI_WTIME()\n call write_result(rank, nprocs, aloc, jbeg, jend, jbeg(rank), jend(rank), m)\n\n\n print *, 'The time taken for the computation is:', t2 - t1\n\n call MPI_FINALIZE(ierr)\n \n deallocate(aloc)\n deallocate(jbeg)\n deallocate(jend)\n\nend program\n\n\n!----------------------------------------------------------------------\n !Subroutine for decomposing the domain\n!----------------------------------------------------------------------\n\nsubroutine decompose(n, nprocs, jbeg, jend)\n implicit none\n\n integer, intent(in) :: n, nprocs\n integer, dimension(0:nprocs-1), intent(out) :: jbeg, jend\n integer :: loc_size, i\n\n loc_size = n/nprocs \n do i = 0, nprocs-1\n\n jbeg(i) = i*loc_size + 1\n jend(i) = jbeg(i) + loc_size - 1\n\n\n end do \n\n if (mod(n, nprocs).ne.0) then \n jend(nprocs-1) = jend(nprocs-1) + mod(n, nprocs)\n end if\n\nend subroutine\n\n\n!----------------------------------------------------------------------\n !Assigning the values for the boundary_condition\n!----------------------------------------------------------------------\n\nsubroutine bc(a, ifirst, ilast, jfirst, jlast, m, n, rank, nprocs)\n \n implicit none \n real(kind = 8), dimension(ifirst-1:ilast+1, jfirst-1:jfirst+1) :: a\n integer :: ifirst, ilast, jfirst, jlast, i, j, m, n, rank, nprocs\n real(kind = 8) :: x, y, boundary_func\n\n !setting all the values to zero \n do i = ifirst-1, ilast + 1\n do j = jfirst -1, jfirst + 1\n a(i,j) = 0.d0\n end do \n end do \n\n !Filling the i-constant boundary values\n !Keeping the values at the ghost cells as zero\n\n i = ifirst - 1\n x = dble(i)/dble(m+1)\n do j = jfirst, jlast\n y = dble(j)/dble(n+1)\n a(i,j) = boundary_func(x,y)\n end do\n i = ifirst + 1\n x = dble(i)/dble(m+1)\n do j = jfirst, jlast\n y = dble(j)/dble(n+1)\n a(i,j) = boundary_func(x,y)\n end do \n\n !Filling the j-constant boundary values \n if (rank.eq.0) then \n j = jfirst-1\n y = dble(j)/dble(n+1)\n do i = ifirst-1, ilast+1\n x = dble(i)/dble(m+1)\n a(i,j) = boundary_func(x,y)\n end do \n end if \n if (rank.eq.nprocs-1) then\n j = jlast + 1\n y = dble(j)/dble(n+1)\n do i = ifirst - 1, ilast + 1\n x = dble(i)/dble(m+1)\n a(i,j) = boundary_func(x,y)\n end do \n end if\n\nend subroutine\n\n\n!----------------------------------------------------------------------------\n !Function for setting the boundary condition \n!----------------------------------------------------------------------------\nfunction boundary_func(x,y)\n implicit none \n real(kind = 8) :: boundary_func, x, y, pi\n pi = 4.d0*atan(1.d0)\n boundary_func = sin(pi*x)*exp(-pi*y)\nend function\n\n\n!----------------------------------------------------------------------------\n !Subroutine for communicating the ghost cell values \n!----------------------------------------------------------------------------\nsubroutine comm(m, nprocs, jfirst, jlast, a, my_rank)\n implicit none \n include 'mpif.h'\n\n integer :: jfirst, jlast, m, nprocs, ierr, my_rank, idest, iorigin\n real(kind=8), dimension(0:m+1, jfirst-1:jlast+1) :: a\n integer, parameter :: nmsg = 2\n integer :: istat(MPI_STATUS_SIZE, 2*nmsg), nreq, i, j, tag\n integer, dimension(nmsg) :: iseq_send, iseq_recv\n integer, dimension(2*nmsg) :: ireq\n\n iseq_recv = (/-1, +1/)\n iseq_send = (/+1, -1/)\n \n nreq = 0\n tag = 5\n\n do i = 1, nmsg\n \n !Sending to the destination (non-blocking)\n idest = my_rank + iseq_send(i)\n if (idest.ge.0.and.idest.le.nprocs-1) then\n if (iseq_send(i).eq.+1) then\n j = jlast\n else\n j = jfirst\n end if\n \n nreq = nreq + 1\n call MPI_ISEND(a(0,j), m+2, MPI_DOUBLE_PRECISION, idest,tag, &\n MPI_COMM_WORLD, ireq(nreq), ierr)\n end if \n \n\n !Receiving from the origin (non-blocking)\n iorigin = my_rank + iseq_recv(i)\n if (iorigin.ge.0.and.iorigin.le.nprocs-1) then\n if(iseq_recv(i).eq.+1) then \n j = jlast + 1\n else\n j = jfirst - 1\n end if\n nreq = nreq + 1\n call MPI_IRECV(a(0,j), m+2, MPI_DOUBLE_PRECISION, iorigin, &\n tag, MPI_COMM_WORLD, ireq(nreq), ierr)\n end if\n end do \n \n ! Wait for the non-blocking communications to end\n call MPI_WAITALL(nreq, ireq, istat, ierr)\n\nend subroutine\n\n!------------------------------------------------------------------------------\n !Doing the jacobi step \n!------------------------------------------------------------------------------\nsubroutine jacobi_step(m, n, ifirst, ilast, jfirst, jlast, nprocs, my_rank, a, &\n diff, max_val)\n implicit none \n integer :: m, n, ifirst, ilast, jfirst, jlast, nprocs, my_rank\n real(kind=8) :: diff, dx, dy, max_val\n real(kind=8), dimension(ifirst-1:ilast+1, jfirst-1:jlast+1) :: a, tmp\n integer :: i, j\n \n dx = 1.d0/(m + 1)\n dy = 1.d0/(n + 1)\n diff = 0.d0\n max_val = 0.d0\n \n !Update step\n do j = jfirst, jlast\n do i = ifirst, ilast\n tmp(i,j) = 0.25*(a(i,j+1) + a(i-1,j) + a(i,j+1) + a(i, j-1))\n diff = max(diff, abs(tmp(i,j) - a(i,j)))\n max_val = max(max_val, tmp(i,j))\n end do\n end do\n \n do j = jfirst, jlast\n do i = ifirst, ilast\n a(i,j) = tmp(i,j)\n end do \n end do\n\n \nend subroutine\n\n!--------------------------------------------------------------------------------------\n !Subroutine for checking convergence\n!--------------------------------------------------------------------------------------\n\nlogical function converged(diffl, max_vall, tol, my_rank)\n implicit none \n include 'mpif.h'\n\n real(kind=8) :: diffl, diffg, max_vall, max_valg, tol\n integer :: iter, my_rank, ierr\n !logical :: converged \n\n converged = .false.\n\n call MPI_ALLREDUCE(diffl, diffg, 1, MPI_DOUBLE_PRECISION, MPI_MAX, &\n MPI_COMM_WORLD, ierr)\n\n\n call MPI_ALLREDUCE(max_vall, max_valg, 1, MPI_DOUBLE_PRECISION, MPI_MAX, &\n MPI_COMM_WORLD, ierr)\n\n \n diffg = diffg/max_valg\n if (diffg.le.tol) then \n converged = .true. \n write(*,*) 'P:',my_rank,'has converged'\n end if\nend function \n\n!---------------------------------------------------------------------------------------\n !Subroutine to collect the local values from the processors and initiating \n !a write to a file \n!---------------------------------------------------------------------------------------\nsubroutine write_result(rank, nprocs, a, jbeg, jend, jfirst, jlast, m)\n implicit none \n include \"mpif.h\"\n \n integer :: rank, nprocs, iproc, jfirst, jlast, i, j, jff, jll, m\n real(kind=8), dimension(0:m+1, jfirst-1:jlast+1) :: a, temp\n integer :: ierr, istat(MPI_STATUS_SIZE)\n integer, dimension(0:nprocs-1) :: jbeg, jend\n \n open(10, file = \"result.dat\", status = \"new\")\n if(rank.eq.0) then \n jll = jlast\n if(nprocs.eq.1) jll = jlast + 1 \n do j = jfirst-1, jll\n do i = 0, m+1\n write(10, 20) i, j, a(i,j)\n !format(I10, I10, F15.8)\n end do\n end do\n \n do iproc = 1, nprocs-1\n call MPI_RECV(temp, (jend(iproc) - jbeg(iproc) + 3)*(m+2), &\n MPI_DOUBLE_PRECISION, iproc, 1, MPI_COMM_WORLD, &\n istat, ierr)\n jll = jend(iproc)\n if(iproc.eq.nprocs-1) then \n jll = jend(iproc) + 1\n end if\n do j = jfirst, jll\n do i = 0, m+1\n write(10, 20) i, j, temp(i,j)\n 20 format(I10, I10, F15.8)\n end do\n end do\n end do\n\n else\n call MPI_SEND(a, (jend(rank) - jbeg(rank) + 3)*(m+2), &\n MPI_DOUBLE_PRECISION, 0, 1, MPI_COMM_WORLD, &\n ierr) \n end if \n\n close(10)\n call MPI_BARRIER(MPI_COMM_WORLD, ierr)\nend subroutine \n", "meta": {"hexsha": "3177656aa5a1079a4f91f803ec5477c4b2a1edb2", "size": 12003, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "poisson/poisson.f90", "max_stars_repo_name": "skn96/MPI_examples", "max_stars_repo_head_hexsha": "0f09d76060b1ca478a01b1a8e4fac844a4dceeaa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "poisson/poisson.f90", "max_issues_repo_name": "skn96/MPI_examples", "max_issues_repo_head_hexsha": "0f09d76060b1ca478a01b1a8e4fac844a4dceeaa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "poisson/poisson.f90", "max_forks_repo_name": "skn96/MPI_examples", "max_forks_repo_head_hexsha": "0f09d76060b1ca478a01b1a8e4fac844a4dceeaa", "max_forks_repo_licenses": ["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.6172106825, "max_line_length": 95, "alphanum_fraction": 0.407481463, "num_tokens": 2857, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.853912760387131, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6660458861712704}} {"text": "program iso_kinds\r\nuse iso_fortran_env, only: real32,real64,real128,int8,int16,int32, &\r\n int64,integer_kinds,real_kinds\r\nimplicit none\r\nreal(real32) :: x32\r\nreal(real64) :: x64\r\nreal(real128) :: x128\r\ninteger(int8) :: i8\r\ninteger(int16) :: i16\r\ninteger(int32) :: i32\r\ninteger(int64) :: i64\r\n! negative values for real32, real64, real128 mean they are unsupported\r\nprint \"('real32, real64, real128:',*(1x,i0))\",real32,real64,real128\r\n! real_kinds and integer_kinds are a Fortran 2008 feature.\r\nprint \"('real_kinds:',*(1x,i0))\",real_kinds ! available real kinds\r\nprint \"(/,'int8, int16, int32, int64:',*(1x,i0))\",int8,int16,int32,int64\r\nprint \"('integer_kinds:',*(1x,i0))\",integer_kinds ! available integer kinds\r\nprint \"(/,'huge() for integer types')\"\r\nprint \"(' int8',1x,i0)\",huge(i8)\r\nprint \"('int16',1x,i0)\",huge(i16)\r\nprint \"('int32',1x,i0)\",huge(i32)\r\nprint \"('int64',1x,i0)\",huge(i64)\r\nprint \"(/,'huge() for real types')\"\r\nprint*,\" real32\",huge(x32)\r\nprint*,\" real64\",huge(x64)\r\nprint*,\"real128\",huge(x128)\r\nprint \"(/,'tiny() for real types')\"\r\nprint*,\" real32\",tiny(x32)\r\nprint*,\" real64\",tiny(x64)\r\nprint*,\"real128\",tiny(x128) \r\nend program iso_kinds\r\n! output for gfortran. \r\n! real32, real64, real128: 4 8 16\r\n! real_kinds: 4 8 10 16\r\n! \r\n! int8, int16, int32, int64: 1 2 4 8\r\n! integer_kinds: 1 2 4 8 16\r\n!\r\n! results up to here may differ by compiler\r\n! \r\n! huge() for integer types\r\n! int8 127\r\n! int16 32767\r\n! int32 2147483647\r\n! int64 9223372036854775807\r\n! \r\n! huge() for real types\r\n! real32 3.40282347E+38\r\n! real64 1.7976931348623157E+308\r\n! real128 1.18973149535723176508575932662800702E+4932\r\n! \r\n! tiny() for real types\r\n! real32 1.17549435E-38\r\n! real64 2.2250738585072014E-308\r\n! real128 3.36210314311209350626267781732175260E-4932\r\n", "meta": {"hexsha": "2c7eb22dbbcb4ef4956bed7d20c552cbd823a3cc", "size": 1813, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "iso_kinds.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": "iso_kinds.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": "iso_kinds.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": 32.375, "max_line_length": 76, "alphanum_fraction": 0.6712630998, "num_tokens": 665, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321796478255, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.6660256228779124}} {"text": "module tau_aL\n\n implicit none\n\n interface\n subroutine RC3JJ(l1, l2, m1, m2, l3min, l3max, wig, ndim, ier)\n real(4), intent(in) :: l1, l2, m1, m2\n real(4), intent(out) :: l3min, l3max\n integer, intent(in) :: ndim\n real(4), dimension(*), intent(out) :: wig\n integer :: ier\n end subroutine RC3JJ\n end interface\n\ncontains \n\n subroutine get_AL_tau(cltt, nltt, lmax, AL)\n integer, parameter :: dp = 4\n integer, intent(in) :: lmax\n real(dp), intent(in), dimension(0:lmax) :: cltt\n real(dp), intent(in), dimension(0:lmax) :: nltt\n real(dp), intent(out), dimension(0:lmax) :: AL\n\n real(dp), parameter :: one_fourpi = 1.d0 / (atan(1.) * 16.d0)\n integer :: l1, l2, l3min, l3max, dim, ier, l, lwig\n real(dp) :: rl1, rl2, rl3min, rl3max, numb\n real(dp), dimension(0:2*lmax) :: wigner\n real(dp), dimension(0:lmax) :: ell\n \n wigner = 0.\n\n ell = [(l, l=0, lmax)]\n\n do l1=0, lmax\n rl1 = real(l1, kind=dp)\n numb = 0.\n do l2=0, lmax\n\n fact = (2 * ell(l1) + 1) * (2 * ell(l2) + 1) / (16. * 3.1415)\n fact = fact * cltt(l1) * cltt(l1)\n fact = fact / (cltt(l1) + nltt(l1))\n fact = fact / (cltt(l2) + nltt(l2)) \n\n rl2 = real(l2, kind=dp)\n dim = l1 + l2 + 1\n call RC3JJ(rl1, rl2, 0., 0., rl3min, rl3max, wigner, dim, ier)\n if (ier .ne. 0) then\n write(*,*), '!!! ERROR -- Wigner 3J !!!', ier\n stop\n endif\n l3min = int(rl3min)\n l3max = min(int(rl3max), lmax)\n \n do l = l3min, l3max\n lwig = l - l3min \n numb = numb + wigner(lwig) * wigner(lwig)\n enddo\n\n numb = numb * fact\n\n enddo\n enddo\n\n end subroutine get_AL_tau\n\nend module tau_aL", "meta": {"hexsha": "2dcc6b10a250c73ce923b3348d7093c0cac18148", "size": 1800, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tau_aL.f90", "max_stars_repo_name": "fbianchini/OpticalTau", "max_stars_repo_head_hexsha": "449aea107287afd7b6f98dc1a1aa03dd0c5b078b", "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": "tau_aL.f90", "max_issues_repo_name": "fbianchini/OpticalTau", "max_issues_repo_head_hexsha": "449aea107287afd7b6f98dc1a1aa03dd0c5b078b", "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": "tau_aL.f90", "max_forks_repo_name": "fbianchini/OpticalTau", "max_forks_repo_head_hexsha": "449aea107287afd7b6f98dc1a1aa03dd0c5b078b", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.2727272727, "max_line_length": 72, "alphanum_fraction": 0.5138888889, "num_tokens": 663, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009619539554, "lm_q2_score": 0.7279754489059775, "lm_q1q2_score": 0.6660254384829414}} {"text": "\n\nc =====================================================\n subroutine qinit(maxmx,maxmy,meqn,mbc,mx,my,xlower,ylower,\n & dx,dy,q,maux,aux)\nc =====================================================\nc\nc # Set initial sea level flat unless iqinit = 1, in which case\nc # an initial perturbation of the q(i,j,1) is specified and has\nc # been strored in qinitwork.\n\n\n use geoclaw_module\n\n implicit double precision (a-h,o-z)\n dimension q(1-mbc:maxmx+mbc, 1-mbc:maxmy+mbc, meqn)\n dimension aux(1-mbc:maxmx+mbc,1-mbc:maxmy+mbc,maux)\n\nc include 'qinit.i'\n\nc grav = 9.81d0 !# should come from module\n a = 1.d0\n sigma = 0.5d0\n h0 = 0.1d0\n omega = dsqrt(2.d0*grav*h0) / a\n write(6,*) 'omega = ',omega\n\n do i=1-mbc,mx+mbc\n x = xlower + (i-0.5d0)*dx\n do j=1-mbc,my+mbc\n y = ylower + (j-0.5d0)*dy\n eta = sigma*h0/a**2 * (2.*x - sigma) \n q(i,j,1) = dmax1(0.d0,eta-aux(i,j,1))\n q(i,j,2) = 0.d0\n q(i,j,3) = sigma*omega * q(i,j,1)\n enddo\n enddo\n\n\n return\n end\n", "meta": {"hexsha": "d2c0b29f8a772576c2ced964c31abd90c1280999", "size": 1173, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "apps/tsunami/bowl-slosh/qinit_geo.f", "max_stars_repo_name": "geoflows/geoclaw-4.x", "max_stars_repo_head_hexsha": "c8879d25405017b38392aa3b1ea422ff3e3604ea", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2016-11-13T03:11:51.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-07T18:59:48.000Z", "max_issues_repo_path": "apps/tsunami/bowl-slosh/qinit_geo.f", "max_issues_repo_name": "che-wenchao/D-Claw", "max_issues_repo_head_hexsha": "8ab5d971c9a7a7130e03a447a4b8642e292f4e88", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2020-01-14T18:00:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T14:25:24.000Z", "max_forks_repo_path": "apps/tsunami/bowl-slosh/qinit_geo.f", "max_forks_repo_name": "che-wenchao/D-Claw", "max_forks_repo_head_hexsha": "8ab5d971c9a7a7130e03a447a4b8642e292f4e88", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-01-14T17:15:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-03T17:28:44.000Z", "avg_line_length": 27.9285714286, "max_line_length": 69, "alphanum_fraction": 0.4586530264, "num_tokens": 397, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009573133051, "lm_q2_score": 0.7279754489059775, "lm_q1q2_score": 0.6660254351046618}} {"text": "subroutine evolve_radius(j,t)\n!****************************************************************\n! Evolve radius of embryo j at time t\n! Currently assumes a polytropic collapse (cf protostar formation)\n!****************************************************************\n\nuse eosdata,only: pi\nuse embryodata\n\nimplicit none\n\ninteger, intent(in) :: j\nreal, intent(in) :: t\nreal :: rchoose\n\n\nIF(embryo(j)%itidal==0) rchoose = embryo(j)%R0\nIF(embryo(j)%itidal==1) rchoose = embryo(j)%R \n\nembryo(j)%R = rchoose/(1.0 + 2.0*t/embryo(j)%t_cool0)**0.5\nembryo(j)%rhoc = embryo(j)%M/(4.0*pi*theta_grad*embryo(j)%R**3) \n\n\nend subroutine evolve_radius\n", "meta": {"hexsha": "f91d316e5af8625adb975bcb7d3f63a0e84c7fc2", "size": 645, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/embryo/evolve_radius.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/embryo/evolve_radius.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/embryo/evolve_radius.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": 25.8, "max_line_length": 74, "alphanum_fraction": 0.5519379845, "num_tokens": 181, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.914900950352329, "lm_q2_score": 0.7279754489059774, "lm_q1q2_score": 0.666025430037242}} {"text": "!--------------------------------------------------------------------------------\n! Copyright (c) 2016 Peter Gr\u00fcnberg Institut, Forschungszentrum J\u00fclich, 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\n MODULE m_od_cylbes\n use m_juDFT\n CONTAINS\n SUBROUTINE od_cylbes(\n > m1,x,\n < fJ) \n\n IMPLICIT NONE\n! ..\n! ..Arguments ..\n INTEGER, INTENT (IN) :: m1\n REAL, INTENT (IN) :: x\n REAL, INTENT (OUT) :: fJ\n!\n! .. Parameters ..\n REAL, PARAMETER :: zero = 0.0\n! ..Locals ..\n INTEGER :: m,i,mass\n REAL :: quot\n REAL, ALLOCATABLE :: aux(:)\n! ..\n\n IF (x.LT.zero) CALL juDFT_error(\"cylbes2\",calledby=\"od_cylbes\")\n\n IF (x.EQ.zero .AND. m1.EQ.0) THEN\n fJ = 1.\n RETURN\n END IF\n IF (x.EQ.zero .AND. m1.NE.0) THEN\n fJ = 0.\n RETURN\n END IF\n\n if (m1.lt.0) then\n m = -m1\n else\n m = m1\n end if\n \n mass = INT( m + 50 + x )\n ALLOCATE ( aux(0:mass) ) \n aux(mass) = 0.0\n aux(mass-1) = 1.0e-22 \n \n DO i=mass-2,0,-1\n aux(i) = 2*(i+1)*aux(i+1)/x - aux(i+2)\n END DO\n\n quot = aux(0)\n\n DO i=1,INT( mass/2. )\n quot = quot + 2*aux(2*i)\n END DO \n\n IF (m1.LT.0) THEN\n fJ = ((-1)**m)*aux(m)/quot\n ELSE\n fJ = aux(m)/quot\n END IF\n \n DEALLOCATE ( aux )\n \n RETURN\n END SUBROUTINE od_cylbes\n END MODULE m_od_cylbes\n \n \n", "meta": {"hexsha": "7353f164d9759822590aa8a44a986e0da1655816", "size": 1711, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "global/od_cylbes.f", "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": "global/od_cylbes.f", "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": "global/od_cylbes.f", "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": 23.1216216216, "max_line_length": 81, "alphanum_fraction": 0.4389246055, "num_tokens": 541, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.6660230610677004}} {"text": "*DECK DCSEVL\r\n DOUBLE PRECISION FUNCTION DCSEVL (X, CS, N)\r\nC***BEGIN PROLOGUE DCSEVL\r\nC***PURPOSE Evaluate a Chebyshev series.\r\nC***LIBRARY SLATEC (FNLIB)\r\nC***CATEGORY C3A2\r\nC***TYPE DOUBLE PRECISION (CSEVL-S, DCSEVL-D)\r\nC***KEYWORDS CHEBYSHEV SERIES, FNLIB, SPECIAL FUNCTIONS\r\nC***AUTHOR Fullerton, W., (LANL)\r\nC***DESCRIPTION\r\nC\r\nC Evaluate the N-term Chebyshev series CS at X. Adapted from\r\nC a method presented in the paper by Broucke referenced below.\r\nC\r\nC Input Arguments --\r\nC X value at which the series is to be evaluated.\r\nC CS array of N terms of a Chebyshev series. In evaluating\r\nC CS, only half the first coefficient is summed.\r\nC N number of terms in array CS.\r\nC\r\nC***REFERENCES R. Broucke, Ten subroutines for the manipulation of\r\nC Chebyshev series, Algorithm 446, Communications of\r\nC the A.C.M. 16, (1973) pp. 254-256.\r\nC L. Fox and I. B. Parker, Chebyshev Polynomials in\r\nC Numerical Analysis, Oxford University Press, 1968,\r\nC page 56.\r\nC***ROUTINES CALLED D1MACH, XERMSG\r\nC***REVISION HISTORY (YYMMDD)\r\nC 770401 DATE WRITTEN\r\nC 890831 Modified array declarations. (WRB)\r\nC 890831 REVISION DATE from Version 3.2\r\nC 891214 Prologue converted to Version 4.0 format. (BAB)\r\nC 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\r\nC 900329 Prologued revised extensively and code rewritten to allow\r\nC X to be slightly outside interval (-1,+1). (WRB)\r\nC 920501 Reformatted the REFERENCES section. (WRB)\r\nC***END PROLOGUE DCSEVL\r\n DOUBLE PRECISION B0, B1, B2, CS(*), ONEPL, TWOX, X, D1MACH\r\n LOGICAL FIRST\r\n SAVE FIRST, ONEPL\r\n DATA FIRST /.TRUE./\r\nC***FIRST EXECUTABLE STATEMENT DCSEVL\r\n IF (FIRST) ONEPL = 1.0D0 + D1MACH(4)\r\n FIRST = .FALSE.\r\n IF (N .LT. 1) CALL XERMSG ('SLATEC', 'DCSEVL',\r\n + 'NUMBER OF TERMS .LE. 0', 2, 2)\r\n IF (N .GT. 1000) CALL XERMSG ('SLATEC', 'DCSEVL',\r\n + 'NUMBER OF TERMS .GT. 1000', 3, 2)\r\n IF (ABS(X) .GT. ONEPL) CALL XERMSG ('SLATEC', 'DCSEVL',\r\n + 'X OUTSIDE THE INTERVAL (-1,+1)', 1, 1)\r\nC\r\n B1 = 0.0D0\r\n B0 = 0.0D0\r\n TWOX = 2.0D0*X\r\n DO 10 I = 1,N\r\n B2 = B1\r\n B1 = B0\r\n NI = N + 1 - I\r\n B0 = TWOX*B1 - B2 + CS(NI)\r\n 10 CONTINUE\r\nC\r\n DCSEVL = 0.5D0*(B0-B2)\r\nC\r\n RETURN\r\n END\r\n", "meta": {"hexsha": "e10b4b6f510d93574aaaeb86a236c41317540071", "size": 2429, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Modules/ThirdParty/Netlib/src/netlib/slatec/dcsevl.f", "max_stars_repo_name": "nalinimsingh/ITK_4D", "max_stars_repo_head_hexsha": "95a2eacaeaffe572889832ef0894239f89e3f303", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-10-01T20:46:17.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-17T19:39:50.000Z", "max_issues_repo_path": "Modules/ThirdParty/Netlib/src/netlib/slatec/dcsevl.f", "max_issues_repo_name": "nalinimsingh/ITK_4D", "max_issues_repo_head_hexsha": "95a2eacaeaffe572889832ef0894239f89e3f303", "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/Netlib/src/netlib/slatec/dcsevl.f", "max_forks_repo_name": "nalinimsingh/ITK_4D", "max_forks_repo_head_hexsha": "95a2eacaeaffe572889832ef0894239f89e3f303", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-05-17T16:34:54.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-24T02:12:40.000Z", "avg_line_length": 36.803030303, "max_line_length": 70, "alphanum_fraction": 0.6047756278, "num_tokens": 840, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8723473813156295, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6660230571189694}} {"text": " SUBROUTINE chint(a,b,c,cint,n)\r\n INTEGER n\r\n REAL a,b,c(n),cint(n)\r\n INTEGER j\r\n REAL con,fac,sum\r\n con=0.25*(b-a)\r\n sum=0.\r\n fac=1.\r\n do 11 j=2,n-1\r\n cint(j)=con*(c(j-1)-c(j+1))/(j-1)\r\n sum=sum+fac*cint(j)\r\n fac=-fac\r\n11 continue\r\n cint(n)=con*c(n-1)/(n-1)\r\n sum=sum+fac*cint(n)\r\n cint(1)=2.*sum\r\n return\r\n END\r\n", "meta": {"hexsha": "f98cf05c71ac0664e1930289a6410e50f8018fde", "size": 408, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/chint.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/chint.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/chint.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": 21.4736842105, "max_line_length": 42, "alphanum_fraction": 0.4411764706, "num_tokens": 149, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782092, "lm_q2_score": 0.7634837527911056, "lm_q1q2_score": 0.6660230473567879}} {"text": "program problem7\n use euler\n implicit none\n integer*8 :: i=0\n integer :: found=0,limit=10001\n\n do while (found < limit)\n i=i+1\n if (is_prime(i)) then\n found=found+1\n end if\n end do\n\n print *, i\n \nend program problem7\n", "meta": {"hexsha": "bb664bb61b5024eab4beae625e85dd27fd879f41", "size": 246, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "problem7.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": "problem7.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": "problem7.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": 14.4705882353, "max_line_length": 34, "alphanum_fraction": 0.6016260163, "num_tokens": 82, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8856314798554445, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6660060134909757}} {"text": "PROGRAM Task1\nIMPLICIT NONE\n \nINTEGER, PARAMETER:: n=80\nINTEGER:: i, j, it\nREAL:: Epsilon0, EpsilonRH, KBoltz, CSalt, e, Kappa, OldVal, X, Y\nREAL:: Phi(-n:n, -n:n), h, tol\n \nEpsilon0=8.85E-12; EpsilonRH=80; KBoltz = 1.38-E13; h=0.05; tol=1.0E-5; Phi = 0.0; CSalt=3E26\n \n!Kappa = SQRT((2.0*CSalt)*e**2.0)/(Epsilon0*EpsilonRH*KBoltz)\nKappa=1.0\nWRITE(6,*) Kappa\nKappa = Kappa/1.0E9\n \n\nWRITE(6,*) 1.0/Kappa\n\nDO i=-n,n\n DO j = -n, n\n X = REAL(i)*h; Y = REAL(j)*h\n IF ((X**2.0+Y**2.0) <= 1.0**(2.0+tol)) THEN\n PHI(i,j) = 100.0\n END IF\n END DO\nEND DO\n\nDO it = 1, 100000\n DO i = -n+1,n-1\n DO j = -n+1, n-1\n X=REAL(i)*h; Y=REAL(j)*h; OldVal = Phi(i,j)\n IF ((X**2.0+Y**2.0) <= 1.0**(2.0+tol)) THEN\n !We are inside the cylinder\n\t\t\tELSE\n Phi(i,j) = (Phi(i-1, j)+Phi(i,j+1)+Phi(i,j+1)+Phi(i,j-1))/(4.0+h**2.0+Kappa**2.0)\n\t\t\tEND IF\n\n\t END DO\n END DO\nEND DO\n\nOPEN(1, FILE = 'Results.dat') \nDO i = -n,n\n DO j = -n,n\n WRITE(1,'(f4.2, f4.2, f7.4)') REAL(i)*h, REAL(j)*h, Phi(i,j)\n END DO\nEND DO\n\n \n END PROGRAM", "meta": {"hexsha": "baafe209fca0636ff902cd45ac18326928976360", "size": 1056, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Linearised Poisson-Boltzmann PDE/Task1.f95", "max_stars_repo_name": "DGrifferty/Fortran", "max_stars_repo_head_hexsha": "600b46fb553fe955c7dd574ee4f51ac1f24de62e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Linearised Poisson-Boltzmann PDE/Task1.f95", "max_issues_repo_name": "DGrifferty/Fortran", "max_issues_repo_head_hexsha": "600b46fb553fe955c7dd574ee4f51ac1f24de62e", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Linearised Poisson-Boltzmann PDE/Task1.f95", "max_forks_repo_name": "DGrifferty/Fortran", "max_forks_repo_head_hexsha": "600b46fb553fe955c7dd574ee4f51ac1f24de62e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.12, "max_line_length": 93, "alphanum_fraction": 0.5378787879, "num_tokens": 513, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554445, "lm_q2_score": 0.752012562644147, "lm_q1q2_score": 0.666005998724421}} {"text": "!> Parameters to be used during calculations\n!! such as conversion factors, imaginary number, \\f$ \\pi \\f$....\nMODULE parameters\n USE kinds\n IMPLICIT NONE\n\n REAL(dp), PARAMETER :: pi=4.0_dp*DATAN(1.0_dp), & !4.0d0*atan(1.d0),\n kb=1.3806488e-23_dp, & ! Boltzmann constant J/K\n planck=6.626068e-34_dp, & ! Planck's constant in Js\n hbar=planck/2.0_dp/pi, & ! hbar in Js\n avog = 6.0221415e23_dp, & ! Avogadro's number\n light = 2.99792458e10_dp, & ! Speed of light (SI) in cm/s\n ! *************** ENERGY *************** !\n joules2wvnbr = 1.0_dp/planck/light, & ! Joules (SI) to wavenumber\n wvnbr2joules = 1.0_dp/joules2wvnbr, & ! wavenumber to Joules\n ! **************** LENGTH ************** !\n m2ang = 1.e10_dp, & ! meter to Angstrom\n ang2m = 1.0_dp/m2ang, & ! Angstrom to meter\n ! ***************** RMASS *************** !\n amu2kg = 1.66053892e-27_dp, & ! atomic rmass unit to kg\n ! ************** TIME ****************** !\n s2ps = 1.0e12_dp, & ! seconds to picoseconds\n ps2s = 1.0_dp/s2ps, & ! picoseconds to seconds\n s2fs = 1.0e15_dp, & ! seconds to femtoseconds\n fs2s = 1.0_dp/s2fs, & ! femtoseconds to seconds\n ! ************** FREQUENCY ************* !\n wvnbr2Hz = light, & ! wavenumbers to Hertz\n Hz2wvnbr = 1.0_dp/wvnbr2Hz, & ! Hertz to wavenumbers\n ! ***************** 2 a.u. ************* !\n au2joules = 4.35974417e-18_dp, & ! a.u. energy to Joules\n joules2au = 1.0_dp/au2joules, & ! Joules to a.u. energy\n ev2au=0.03674932_dp, & ! eV to a.u. energy\n au2ev=1.0_dp/ev2au, & ! a.u. energy to eV\n autime2s = 2.418884326505e-17_dp, & ! a.u. time to seconds\n s2autime = 1.0_dp/autime2s, & ! seconds to a.u. time\n autemp2K = 3.1577464e5_dp, & ! a.u. temperature to Kelvin\n K2autemp = 1.0_dp/autemp2K, & ! Kelvin to a.u. temperature\n au2ang = 0.52917725_dp, & ! atomic length to Angstrom\n ang2au = 1.0_dp/au2ang ! Angstrom to atomic length\n \n COMPLEX(dp), PARAMETER :: eye=(0.0_dp, 1.0_dp)\n \nEND MODULE parameters\n", "meta": {"hexsha": "2ff9d36b15754cbdd0845f87fcf5987006ae142e", "size": 2544, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mqds/src/general_src/parameters.f90", "max_stars_repo_name": "jprov410/mqds", "max_stars_repo_head_hexsha": "beead5c30aac77a7ae2d07e808d8c587cdd1c3ce", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-02-08T20:58:49.000Z", "max_stars_repo_stars_event_max_datetime": "2018-08-23T02:07:17.000Z", "max_issues_repo_path": "mqds/src/general_src/parameters.f90", "max_issues_repo_name": "jprov410/MQDS", "max_issues_repo_head_hexsha": "beead5c30aac77a7ae2d07e808d8c587cdd1c3ce", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-02-21T18:41:21.000Z", "max_issues_repo_issues_event_max_datetime": "2018-03-21T21:27:48.000Z", "max_forks_repo_path": "mqds/src/general_src/parameters.f90", "max_forks_repo_name": "jprov410/MQDS", "max_forks_repo_head_hexsha": "beead5c30aac77a7ae2d07e808d8c587cdd1c3ce", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-02-07T20:12:07.000Z", "max_forks_repo_forks_event_max_datetime": "2019-10-01T02:33:09.000Z", "avg_line_length": 57.8181818182, "max_line_length": 80, "alphanum_fraction": 0.463836478, "num_tokens": 798, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.885631470799559, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6660059968364662}} {"text": "!##############################################################################\n!# Tutorial 023a: Calculate an L2 and H1 norm with the block integration\n!##############################################################################\n\nmodule tutorial023a\n\n ! Include basic Feat-2 modules\n use fsystem\n use storage\n use genoutput\n \n use triangulation\n use meshgeneration\n \n use element\n use cubature\n use spatialdiscretisation\n use linearsystemscalar\n use linearsystemblock\n use bilinearformevaluation\n \n use feevaluation2\n use blockmatassemblybase\n use blockmatassembly\n use blockmatassemblystdop\n\n implicit none\n private\n \n public :: start_tutorial023a\n\ncontains\n\n ! ***************************************************************************\n\n subroutine start_tutorial023a\n\n ! Declare some variables.\n type(t_triangulation) :: rtriangulation\n type(t_spatialDiscretisation) :: rspatialDiscr\n type(t_blockDiscretisation) :: rblockDiscr\n type(t_scalarCubatureInfo), target :: rcubatureInfo\n type(t_vectorBlock) :: rx\n type(t_fev2Vectors) :: rcoeffVectors\n\n integer :: ivt\n real(DP) :: dx, dintvalue\n real(DP), dimension(:,:), pointer :: p_DvertexCoords\n real(DP), dimension(:), pointer :: p_Ddata\n\n ! Print a message\n call output_lbrk()\n call output_separator (OU_SEP_STAR)\n call output_line (\"This is FEAT-2. Tutorial 023a\")\n call output_separator (OU_SEP_MINUS)\n \n ! =================================\n ! Create a brick mesh\n ! =================================\n\n ! The mesh must always be in \"standard\" format. \n ! First create a 9x9-mesh on [0,1]x[0,1], then convert to standard.\n call meshgen_rectangular2DQuadMesh (rtriangulation, 0.0_DP, 1.0_DP, 0.0_DP, 1.0_DP, 8, 8)\n call tria_initStandardMeshFromRaw (rtriangulation)\n\n ! =================================\n ! Discretise with Q1.\n !\n ! Create a structure rspatialDiscr\n ! which describes the discretisation.\n ! We generate a 1x1 system with Q1.\n ! =================================\n\n ! Create a spatial discretisation with Q1\n call spdiscr_initDiscr_simple (rspatialDiscr,EL_Q1_2D,rtriangulation)\n \n ! Create a block discretisation with 1 block Q1.\n call spdiscr_initBlockDiscr (rblockDiscr,rtriangulation)\n call spdiscr_appendBlockComponent (rblockDiscr,rspatialDiscr)\n call spdiscr_commitBlockDiscr (rblockDiscr)\n\n ! =================================\n ! Create a scalar vector.\n ! =================================\n\n ! Create a vector.\n call lsysbl_createVector (rblockDiscr,rx)\n \n ! =================================\n ! Fill the vector with data.\n ! =================================\n \n ! Get a pointer to the data.\n call lsyssc_getbase_double (rx%RvectorBlock(1),p_Ddata)\n \n ! Get a pointer to the point coordinates.\n call storage_getbase_double2d (rtriangulation%h_DvertexCoords,p_DvertexCoords)\n \n ! Set the entries of the vector according to the function\n ! u(x,y) = 1/exp(x)\n do ivt=1,rx%NEQ\n dx = p_DvertexCoords(1,ivt)\n p_Ddata(ivt) = 1.0_DP / exp(dx)\n end do\n\n ! =================================\n ! Define cubature formula\n ! =================================\n\n ! Use a Gauss 3x3 formula for the discretisation.\n call spdiscr_createDefCubStructure (rspatialDiscr,rcubatureInfo,CUB_GEN_AUTO_G3)\n\n ! =================================\n ! Calculate the L2-norm of u\n ! =================================\n \n ! Pass u via rcoeffVectors to bma_buildIntegral\n call fev2_addVectorToEvalList (rcoeffVectors,rx%RvectorBlock(1),0)\n\n ! Calculate ||u||_L2^2\n call bma_buildIntegral (dintvalue,BMA_CALC_STANDARD,&\n bma_fcalc_L2norm,revalVectors=rcoeffVectors,rcubatureInfo=rcubatureInfo)\n\n call fev2_releaseVectorList(rcoeffVectors)\n \n ! Take the square root to get ||u||\n dintvalue = sqrt(dintvalue)\n \n call output_line (\"L2-norm = \"//trim(sys_sdL(dintvalue,10)))\n\n ! =================================\n ! Calculate the H1-(semi)norm of u\n ! =================================\n \n ! Pass u and Du via rcoeffVectors to bma_buildIntegral\n call fev2_addVectorToEvalList (rcoeffVectors,rx%RvectorBlock(1),1)\n\n ! Calculate |u|_H1^2 = ||Du||_L2^2\n call bma_buildIntegral (dintvalue,BMA_CALC_STANDARD,&\n bma_fcalc_H1norm,revalVectors=rcoeffVectors,rcubatureInfo=rcubatureInfo)\n\n call fev2_releaseVectorList(rcoeffVectors)\n \n ! Take the square root to get |u|_H1\n dintvalue = sqrt(dintvalue)\n \n call output_line (\"H1-norm = \"//trim(sys_sdL(dintvalue,10)))\n\n ! =================================\n ! Cleanup\n ! =================================\n \n ! Release the vector\n call lsysbl_releaseVector (rx)\n \n ! Cubature done.\n call spdiscr_releaseCubStructure (rcubatureInfo)\n\n ! Release the discretisation\n call spdiscr_releaseBlockDiscr (rblockDiscr)\n call spdiscr_releaseDiscr (rspatialDiscr)\n\n ! Release the triangulation\n call tria_done (rtriangulation)\n \n end subroutine\n\nend module\n", "meta": {"hexsha": "05eec8a98687329e27ee81980caeda8556bdd46a", "size": 5110, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tutorials/tutorial01/src/tutorial023a.f90", "max_stars_repo_name": "trmcnealy/Featflow2", "max_stars_repo_head_hexsha": "4af17507bc2d80396bf8ea85c9e30e9e4d2383df", "max_stars_repo_licenses": ["Intel", "Unlicense"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2017-08-02T11:51:34.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-10T14:14:21.000Z", "max_issues_repo_path": "tutorials/tutorial01/src/tutorial023a.f90", "max_issues_repo_name": "tudo-math-ls3/FeatFlow2", "max_issues_repo_head_hexsha": "56159aff28f161aca513bc7c5e2014a2d11ff1b3", "max_issues_repo_licenses": ["Intel", "Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tutorials/tutorial01/src/tutorial023a.f90", "max_forks_repo_name": "tudo-math-ls3/FeatFlow2", "max_forks_repo_head_hexsha": "56159aff28f161aca513bc7c5e2014a2d11ff1b3", "max_forks_repo_licenses": ["Intel", "Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.2366863905, "max_line_length": 93, "alphanum_fraction": 0.5913894325, "num_tokens": 1326, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314617436728, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6660059949485108}} {"text": "* Example 5.1\r\n*\t write a fortran program to solve for Pi(r)numerically\r\n*\t and compare with the analytical solution ?\r\n*\t 1 * d { r^2 d Phi(r)}\r\n*\t --- -- {-------------} = -4*pi*rho\r\n*\t r dr { }\r\n\r\n*\t Phi(r)= r^-1*Phi(r)\r\n*\t d^2 { Phi(r)}\r\n*\t ------------- = -4*pi*rho\r\n* dr^2\r\n\r\n dimension PHI(0:200)\r\n exact(R)=1.0-(R+2)*Exp(-R)/2\r\n source(R)=-R*exp(-R)/2\r\n H=0.1\r\n Nstep=20./H\r\n const=H**2/12\r\n Sm=0.\r\n Sz=source(H)\r\n PHI(0)=0\r\n PHI(1)=exact(H)\r\n do 10 IR=1,Nstep-1\r\n R=(IR+1)*H\r\n Sp=source(R)\r\n PHI(IR+1)=2*Phi(IR)-PHI(IR-1)+ Const*(Sp+10.0*Sz+Sm)\r\n Sm=Sz\r\n Sz=Sp\r\n Diff=Exact(R)-PHi(IR)\r\n Print*,R,Exact(R),Phi(IR),Diff\r\n10 continue\r\n stop\r\n end\r\n", "meta": {"hexsha": "81b437835c4f461ad79bda38f607f5cc3a2371de", "size": 844, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "last28-52009/Example/Example 5.1/Example 5-1.f", "max_stars_repo_name": "Melhabbash/Computational-Physics-", "max_stars_repo_head_hexsha": "82a92e629fbaaf053d2f5e1ccb1224389b2e94be", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "last28-52009/Example/Example 5.1/Example 5-1.f", "max_issues_repo_name": "Melhabbash/Computational-Physics-", "max_issues_repo_head_hexsha": "82a92e629fbaaf053d2f5e1ccb1224389b2e94be", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "last28-52009/Example/Example 5.1/Example 5-1.f", "max_forks_repo_name": "Melhabbash/Computational-Physics-", "max_forks_repo_head_hexsha": "82a92e629fbaaf053d2f5e1ccb1224389b2e94be", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.8235294118, "max_line_length": 61, "alphanum_fraction": 0.4052132701, "num_tokens": 298, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9615338057771058, "lm_q2_score": 0.6926419767901475, "lm_q1q2_score": 0.6659986759840083}} {"text": "! Like array_constructor_6.f90, but check constructors in which the length\n! of each subarray can only be determined at run time.\n! { dg-do run }\nprogram main\n implicit none\n call build (9)\ncontains\n function gen (order)\n real, dimension (:, :), pointer :: gen\n integer :: order, i, j\n\n allocate (gen (order, order + 1))\n forall (i = 1 : order, j = 1 : order + 1) gen (i, j) = i * i + j\n end function gen\n\n ! Deliberately leaky!\n subroutine build (order)\n integer :: order, i\n\n call test (order, 0, (/ (gen (i), i = 1, order) /))\n call test (3, 2, (/ ((/ 1.5, 1.5, gen (i) /), i = 1, 3) /))\n end subroutine build\n\n subroutine test (order, prefix, values)\n real, dimension (:) :: values\n integer :: order, prefix, last, i, j, k\n\n last = 0\n do i = 1, order\n do j = 1, prefix\n last = last + 1\n if (values (last) .ne. 1.5) STOP 1\n end do\n do j = 1, i + 1\n do k = 1, i\n last = last + 1\n if (values (last) .ne. j + k * k) STOP 2\n end do\n end do\n end do\n if (size (values, dim = 1) .ne. last) STOP 3\n end subroutine test\nend program main\n", "meta": {"hexsha": "2f92fe0f28451b914a7b41b83874aed43589570a", "size": 1145, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/array_constructor_9.f90", "max_stars_repo_name": "brugger1/testsuite", "max_stars_repo_head_hexsha": "9b504db668cdeaf7c561f15b76c95d05bfdd1517", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2019-02-12T18:20:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-09T19:46:19.000Z", "max_issues_repo_path": "validation_tests/llvm/f18/gfortran.dg/array_constructor_9.f90", "max_issues_repo_name": "brugger1/testsuite", "max_issues_repo_head_hexsha": "9b504db668cdeaf7c561f15b76c95d05bfdd1517", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 24, "max_issues_repo_issues_event_min_datetime": "2020-08-31T22:05:07.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T18:30:03.000Z", "max_forks_repo_path": "validation_tests/llvm/f18/gfortran.dg/array_constructor_9.f90", "max_forks_repo_name": "brugger1/testsuite", "max_forks_repo_head_hexsha": "9b504db668cdeaf7c561f15b76c95d05bfdd1517", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2020-08-31T21:59:10.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-23T22:06:46.000Z", "avg_line_length": 26.0227272727, "max_line_length": 74, "alphanum_fraction": 0.5528384279, "num_tokens": 396, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339837155239, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.6659980157898314}} {"text": "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n PROGRAM EXMPL1\nC Example 1: Bohr-Sommerfeld quantization for bound states of the\nC Lennard-Jones Potential\nC COMPUTATIONAL PHYSICS (FORTRAN VERSION)\nC by Steven E. Koonin and Dawn C. Meredith\nC Copyright 1989, Addison-Wesley Publishing Company, Inc.\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n CALL INIT !display header screen, setup parameters\n5 CONTINUE !main loop/ execute once for each set of param\n CALL PARAM !get input from screen\n CALL ARCHON !search for bound states\n GOTO 5\n END\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n SUBROUTINE ARCHON \nC finds the bound states of the Lennard-Jones potential\nC from the Bohr-Sommerfeld quantization rule\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC Global variables:\n INCLUDE 'IO.ALL'\n INCLUDE 'PARAM.E1'\nC Local variables:\n REAL S !current value of action\n REAL E1 !current value of energy\n REAL X1,X2 !current turning points\n REAL F1 !f=action/2 - pi/2 -ilevel*pi\n INTEGER ILEVEL !current level \n REAL ENERGY(0:MAXLVL) !energy of bound state\n REAL XIN(0:MAXLVL) !inner turning point\n REAL XOUT(0:MAXLVL) !outer turning point\n INTEGER NLINES !number of lines printed to terminal\n INTEGER SCREEN !send to terminal\n INTEGER PAPER !make a hardcopy\n INTEGER FILE !send to a file\n DATA SCREEN,PAPER,FILE/1,2,3/\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC output summary of parameters\n IF (TTERM) CALL PRMOUT(OUNIT,NLINES)\n IF (TFILE) CALL PRMOUT(TUNIT,NLINES)\n IF (GFILE) CALL PRMOUT(GUNIT,NLINES)\nC \nC search for bound states\n E1=-1. !begin at the well bottom\n F1=-PI/2 !the action is zero there \nC\nC find the NLEVEL bound states\n DO 100 ILEVEL=0,NLEVEL-1\nC\n CALL SEARCH(ILEVEL,E1,F1,X1,X2) !search for eigenvalue \n ENERGY(ILEVEL)=E1 !store values for this state\n XIN(ILEVEL)=X1\n XOUT(ILEVEL)=X2\nC\nC text output \n IF (TTERM) CALL TXTOUT(OUNIT,ILEVEL,E1,X1,X2,NLINES)\n IF (TFILE) CALL TXTOUT(TUNIT,ILEVEL,E1,X1,X2,NLINES)\nC \n F1=F1-PI !guess to begin search for next level\nC\n100 CONTINUE \nC \n IF (TTERM) CALL PAUSE('to continue...',1) \n IF (TTERM) CALL CLEAR\nC\nC graphics output\n IF (GTERM) CALL GRFOUT(SCREEN,ENERGY,XIN,XOUT)\n IF (GFILE) CALL GRFOUT(FILE,ENERGY,XIN,XOUT)\n IF (GHRDCP) CALL GRFOUT(PAPER,ENERGY,XIN,XOUT)\nC \n RETURN\n END\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n SUBROUTINE SEARCH(N,E1,F1,X1,X2)\nC finds the N'th bound state \nC E1 is passed in as initial guess for the bound state energy\nC and returned as the true bound state energy with turning points\nC X1 and X2\nC F1 is the function which goes to zero at a bound state\nC F1 = action/2-(n+1/2)*pi \nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC Global variables:\n INCLUDE 'PARAM.E1'\nC Input/Output variables:\n INTEGER N !current level (input)\n REAL E1,E2 !trial energies (I/O)\n REAL F1,F2 !f=action/2-pi*(n+1/2) (I/O)\n REAL S !action (output)\n REAL X1,X2 !turning points (output)\nC Local variables: \n REAL DE !increment in energy search\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC guess the next energy in order to begin search\n E2=E1+ABS(E1)/4.\n DE=2*ETOL\nC \nC use secant search to find the bound state\n50 IF (ABS(DE) .GT. ETOL) THEN\n CALL ACTION(E2,X1,X2,S) !S at new energy\n F2=S-(N+.5)*PI !F at new energy\n IF (F1 .NE. F2) THEN !calculate new DE\n DE=-F2*(E2-E1)/(F2-F1) \n ELSE \n DE=0.\n END IF\nC\n E1=E2 !roll values\n F1=F2\n E2=E1+DE !increment energy\n IF (E2 .GE. 0) E2=-ETOL !keep energy negative\n GOTO 50\n END IF\nC\n RETURN \n END\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n SUBROUTINE ACTION(E,X1,X2,S)\nC calculates the (action integral)/2 (S) and the classical turning \nC points (X1,X2) for a given energy (E)\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC Global variables:\n INCLUDE 'PARAM.E1'\nC Input/Output variables: \n REAL E !energy (input)\n REAL S !action (output)\n REAL X1,X2 !turning points (output)\nC Local variables: \n REAL DX !increment in turning point search\n REAL H !quadrature step size\n REAL SUM !sum for integral\n INTEGER IFAC !coefficient for Simpson's rule\n INTEGER IX !index on X\n REAL X !current X value in sum\n REAL POT !potential as a function of X (function)\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC find inner turning point; begin search at the well bottom\n X1=POTMIN \n DX=.1\n50 IF (DX .GT. XTOL) THEN\n X1=X1-DX !use simple search, going inward\n IF (POT(X1) .GE. E) THEN\n X1=X1+DX\n DX=DX/2\n END IF\n GOTO 50 \n END IF\nC\nC find the outer turning point; begin search at the well bottom\n X2=POTMIN\n DX=.1\n120 IF (DX .GT. XTOL) THEN\n X2=X2+DX !use simple search going outward\n IF (POT(X2) .GE. E) THEN\n X2=X2-DX \n DX=DX/2\n END IF\n GOTO 120\n END IF\nC \nC Simpson's rule from X1+H to X2-H \n IF (MOD(NPTS,2) .EQ. 1) NPTS=NPTS+1 !NPTS must be even\n H=(X2-X1)/NPTS !step size\n SUM=SQRT(E-POT(X1+H)) \n IFAC=2\n DO 200 IX=2,NPTS-2\n X=X1+IX*H\n IF (IFAC .EQ. 2) THEN !alternate factors\n IFAC=4\n ELSE\n IFAC=2\n END IF\n SUM=SUM+IFAC*SQRT(E-POT(X))\n200 CONTINUE\n SUM=SUM+SQRT(E-POT(X2-H))\n SUM=SUM*H/3\nC\nC special handling for sqrt behavior of first and last intervals\n SUM=SUM+SQRT(E-POT(X1+H))*2*H/3\n SUM=SUM+SQRT(E-POT(X2-H))*2*H/3\n S=SUM*GAMMA\nC\n RETURN\n END \nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n REAL FUNCTION POT(X)\nC evaluates the Lennard-Jones potential at X\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC Passed variables:\n REAL X \nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC If you change the potential, normalize to a minimum of -1\nC and change the value of POTMIN in subroutine INIT to the\nC new equilibrium position (i.e. the X value at which the force is zero)\nC Lennard-Jones potential in scaled variables\n POT=4*(X**(-12)-X**(-6))\n RETURN\n END\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n SUBROUTINE INIT\nC initializes constants, displays header screen,\nC initializes menu arrays for input parameters\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC Global variables:\n INCLUDE 'IO.ALL'\n INCLUDE 'MENU.ALL'\n INCLUDE 'PARAM.E1'\nC Local parameters:\n CHARACTER*80 DESCRP !program description\n DIMENSION DESCRP(20) \n INTEGER NHEAD,NTEXT,NGRAPH !number of lines for each description\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC get environment parameters\n CALL SETUP \nC \nC display header screen \n DESCRP(1)= 'EXAMPLE 1'\n DESCRP(2)= 'Bohr-Sommerfeld quantization for bound state'\n DESCRP(3)= 'energies of the 6-12 potential'\n NHEAD=3\nC \nC text output description\n DESCRP(4)= 'energy and classical turning points for each state'\n NTEXT=1\nC \nC graphics output description\n DESCRP(5)= 'phase space (wavenumber vs. position) portrait'\n DESCRP(6)= 'of classical trajectories'\n NGRAPH=2\nC \n CALL HEADER(DESCRP,NHEAD,NTEXT,NGRAPH)\nC \nC calculate constants \n PI=4*ATAN(1.0)\n POTMIN=2**(1.0/6.0)\nC \nC setup menu arrays, beginning with constant part\n CALL MENU \nC \n MTYPE(13)=FLOAT\n MPRMPT(13)= 'Enter gamma=sqrt(2*m*a**2*V/hbar**2) (dimensionless)'\n MTAG(13)= 'Gamma (dimensionless)'\n MLOLIM(13)=1.\n MHILIM(13)=500.\n MREALS(13)=50.\nC \n MTYPE(14)=SKIP\n MREALS(14)=35.\nC \n MTYPE(38)=FLOAT\n MPRMPT(38)= 'Enter tolerance for energy search (scaled units)' \n MTAG(38)= 'Energy search tolerance (scaled units)'\n MLOLIM(38)=.00001\n MHILIM(38)=.01\n MREALS(38)=.0005\nC \n MTYPE(39)=FLOAT\n MPRMPT(39)= \n +'Enter tolerance for turning point search (scaled units)'\n MTAG(39)= 'Turning point search tolerance (scaled units)'\n MLOLIM(39)=.00001\n MHILIM(39)=.01\n MREALS(39)=.0005\nC \n MTYPE(40)=NUM\n MPRMPT(40)= 'Enter number of points for action integral'\n MTAG(40)= 'Number of quadrature points for action integral'\n MLOLIM(40)=20.\n MHILIM(40)=5000.\n MINTS(40)=100\nC \n MTYPE(41)=SKIP\n MREALS(41)=60.\nC \n MSTRNG(MINTS(75))= 'exmpl1.txt'\nC \n MTYPE(76)=SKIP\n MREALS(76)=80.\nC \n MSTRNG(MINTS(86))= 'exmpl1.grf'\nC \n MTYPE(87)=NUM\n MPRMPT(87)= 'Enter number of points to be used in graphing'\n MTAG(87)= 'Number of graphing points'\n MLOLIM(87)= 10.\n MHILIM(87)= MAXGRF-2\n MINTS(87)= 80\nC \n MTYPE(88)=SKIP\n MREALS(88)=90.\nC \n RETURN\n END \nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n SUBROUTINE PARAM\nC gets parameters from screen\nC ends program on request\nC closes old files\nC maps menu variables to program variables\nC opens new files\nC calculates all derivative parameters\nC performs checks on parameters\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC Global variables:\n INCLUDE 'MENU.ALL'\n INCLUDE 'IO.ALL' \n INCLUDE 'PARAM.E1'\n INCLUDE 'MAP.E1'\nC Local variables:\n REAL S !current value of action\n REAL E1 !current value of energy\n REAL X1,X2 !current turning points\nC Function:\n LOGICAL LOGCVT !converts 1 and 0 to true and false \nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC get input from terminal\n CALL CLEAR\n CALL ASK(1,ISTOP)\nC\nC stop program if requested\n IF (MREALS(IMAIN) .EQ. STOP) CALL FINISH \nC\nC close files if necessary\n IF (TNAME .NE. MSTRNG(MINTS(ITNAME))) \n + CALL FLCLOS(TNAME,TUNIT)\n IF (GNAME .NE. MSTRNG(MINTS(IGNAME))) \n + CALL FLCLOS(GNAME,GUNIT)\nC \nC physical and numerical parameters\n GAMMA=MREALS(IGAMMA)\n ETOL=MREALS(IETOL)\n XTOL=MREALS(IXTOL)\n NPTS=MINTS(INPTS)\nC\nC text output parameters\n TTERM=LOGCVT(MINTS(ITTERM))\n TFILE=LOGCVT(MINTS(ITFILE))\n TNAME=MSTRNG(MINTS(ITNAME))\nC\nC graphics output parameters\n GTERM=LOGCVT(MINTS(IGTERM))\n GHRDCP=LOGCVT(MINTS(IGHRD))\n GFILE=LOGCVT(MINTS(IGFILE))\n GNAME=MSTRNG(MINTS(IGNAME))\n NGRF=MINTS(INGRF)\nC \nC open files \n IF (TFILE) CALL FLOPEN(TNAME,TUNIT)\n IF (GFILE) CALL FLOPEN(GNAME,GUNIT)\nC files may have been renamed\n MSTRNG(MINTS(ITNAME))=TNAME\n MSTRNG(MINTS(IGNAME))=GNAME\nC\nC calculate total number of levels\n E1=-ETOL\n CALL ACTION(E1,X1,X2,S)\n NLEVEL=INT(S/PI-.5)+1\nC check value of GAMMA\n CALL PCHECK \nC \n CALL CLEAR\nC\n RETURN\n END\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n SUBROUTINE PCHECK\nC ensure that the number of states is not greater than the size of\nC the data arrays; if so prompt for smaller GAMMA\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC Global parameters:\n INCLUDE 'PARAM.E1'\n INCLUDE 'MENU.ALL'\n INCLUDE 'IO.ALL'\n INCLUDE 'MAP.E1'\nC Local parameters:\n REAL S !action\n REAL E !small negative energy\n REAL X1,X2 !classical turning points\nC Function:\n REAL GETFLT !returns a floating point variable \nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n10 IF ((NLEVEL-1) .GT. MAXLVL) THEN\n WRITE (OUNIT,15) NLEVEL,MAXLVL\n MHILIM(IGAMMA)=GAMMA \n MREALS(IGAMMA) = GETFLT(MREALS(IGAMMA)/2,MLOLIM(IGAMMA),\n + MHILIM(IGAMMA), 'Enter a smaller gamma') \n GAMMA=MREALS(IGAMMA)\nC \n E=-ETOL\n CALL ACTION(E,X1,X2,S)\n NLEVEL=INT(S/PI+.5)+1\n GOTO 10\n END IF\nC \n15 FORMAT (' Total number of levels (=',i5, \n + ') is larger than maximum allowable (=',i3,')')\nC\n RETURN \n END \nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n SUBROUTINE PRMOUT(MUNIT,NLINES)\nC outputs parameter summary to the specified unit\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC Global variables:\n INCLUDE 'IO.ALL'\n INCLUDE 'PARAM.E1'\nC Input/Output variables: \n INTEGER MUNIT !unit number for output (input)\n INTEGER NLINES !number of lines written so far (output)\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n IF (MUNIT .EQ. OUNIT) CALL CLEAR\nC \n WRITE (MUNIT,2)\n WRITE (MUNIT,4)\n WRITE (MUNIT,6) ETOL,XTOL\n WRITE (MUNIT,8) NPTS\n WRITE (MUNIT,10) GAMMA,NLEVEL\n WRITE (MUNIT,12) \n WRITE (MUNIT,2)\nC \n IF (MUNIT .NE. GUNIT) THEN\n WRITE (MUNIT,20)\n WRITE (MUNIT,25)\n END IF\nC \n NLINES=7\nC\n2 FORMAT (' ')\n4 FORMAT (' Output from example 1: Bohr Sommerfeld Quantization')\n6 FORMAT (' Energy tolerance =', E12.5,\n + ' position tolerance =', E12.5)\n8 FORMAT (' number of quadrature points =', I4)\n10 FORMAT (' For gamma =', F8.2,' there are ', I4, ' levels:')\n12 FORMAT (' (all quantities are expressed in scaled units)')\n20 FORMAT (8X, 'Level', 8X, 'Energy', 12X, 'Xmin', 12X, 'Xmax')\n25 FORMAT (8X, '-----', 8X, '------', 12X, '----', 12X ,'----')\nC \n RETURN\n END\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n SUBROUTINE TXTOUT(MUNIT,ILEVEL,E,X1,X2,NLINES) \nC writes results for one state to the requested unit\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC Global variables:\n INCLUDE 'IO.ALL'\nC Input variables:\n INTEGER MUNIT !output unit specifier\n INTEGER ILEVEL !current level\n REAL E !eigen energy\n REAL X1,X2 !classical turning points\n INTEGER NLINES !number of lines printed so far\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC if screen is full, clear screen and retype headings \n IF ((MOD(NLINES,TRMLIN-6) .EQ. 0) \n + .AND. (MUNIT .EQ. OUNIT)) THEN\n CALL PAUSE('to continue...',1)\n CALL CLEAR\n WRITE (MUNIT,20)\n WRITE (MUNIT,25)\n END IF\nC\n WRITE (MUNIT,30) ILEVEL,E,X1,X2\nC \nC keep track of printed lines only for terminal output\n IF (MUNIT .EQ. OUNIT) NLINES=NLINES+1\nC\n20 FORMAT (8X, 'Level', 8X, 'Energy', 12X, 'Xmin', 12X, 'Xmax')\n25 FORMAT (8X, '-----', 8X, '------', 12X, '----', 12X ,'----')\n30 FORMAT(8X,I4,3(8X,F8.5))\nC\n RETURN\n END\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n SUBROUTINE GRFOUT(DEVICE,ENERGY,XIN,XOUT)\nC outputs phase space portraits of the bound states to the terminal\nC and/or a file\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC Global parameters:\n INCLUDE 'IO.ALL'\n INCLUDE 'PARAM.E1'\n INCLUDE 'GRFDAT.ALL'\nC Input variables:\n INTEGER DEVICE !which device is being used?\n REAL ENERGY(0:MAXLVL) !energy of bound state\n REAL XIN(0:MAXLVL) !inner turning point\n REAL XOUT(0:MAXLVL) !outer turning point\nC Local parameters: \n INTEGER ILEVEL !level index\n REAL H !step size for x\n INTEGER IX !x index \n REAL E !current energy \n REAL K(MAXGRF) !current wavenumber\n REAL X(MAXGRF) !current position\n CHARACTER*9 CGAMMA,CN !Gamma,nlevel as a character string\n REAL POT !potential (function)\n INTEGER LEN,NLEN !length of character data\n INTEGER SCREEN !send to terminal\n INTEGER PAPER !make a hardcopy\n INTEGER FILE !send to a file\n DATA SCREEN,PAPER,FILE/1,2,3/\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC messages for the impatient\n IF (DEVICE .NE. SCREEN) WRITE (OUNIT,100) \nC\nC calculate parameters for graphing\n IF (DEVICE .NE. FILE) THEN\n NPLOT=1 !how many plots\n IPLOT=1\nC \n YMAX=GAMMA*SQRT(1.+ENERGY(NLEVEL-1)) !limits on data points\n YMIN=-YMAX \n XMIN=XIN(NLEVEL-1)\n XMAX=XOUT(NLEVEL-1)\n Y0VAL=XMIN\n X0VAL=0.\nC \n IF (MOD(NGRF,2) .EQ. 0) NGRF=NGRF+1\n NPOINT=NGRF !keep number of points odd\nC \n ILINE=1 !line and symbol styles\n ISYM=1\n IFREQ=0\n NXTICK=5\n NYTICK=5\nC \n CALL CONVRT(GAMMA,CGAMMA,LEN) !titles and labels\n CALL ICNVRT(NLEVEL,CN,NLEN)\n INFO=' NLEVEL = '//CN(1:NLEN)\n TITLE='Semiclassically Quantized Trajectories, Gamma='//CGAMMA\n LABEL(1)='scaled position'\n LABEL(2)='scaled wave number'\nC \n CALL GTDEV(DEVICE) !device nomination\n IF (DEVICE .EQ. SCREEN) CALL GMODE !change to graphics mode\n CALL LNLNAX !draw axes\n END IF \nC \nC calculate classical phase space trajectory for each bound state \nC by finding the scaled wavenumber as a function of X and Energy\n DO 50 ILEVEL=0,NLEVEL-1\n E=ENERGY(ILEVEL)\n H=(XOUT(ILEVEL)-XIN(ILEVEL))/((NGRF-1)/2) !step size\n X(1)=XIN(ILEVEL)\n K(1)=0.\nC \n DO 20 IX=1,(NGRF-1)/2\n X(IX+1)=XIN(ILEVEL)+(IX)*H\n K(IX+1)=(E-POT(X(IX+1))) !scaled wave number\n IF (K(IX) .LE. 0) THEN\n K(IX)=0.\n ELSE\n K(IX)=GAMMA*SQRT(K(IX))\n END IF \n20 CONTINUE\nC \n DO 30 IX=(NGRF+1)/2,NGRF-1 !graph is symmetric about x-axis\n X(IX+1)=X(NGRF-IX)\n K(IX+1)=-K(NGRF-IX)\n30 CONTINUE\nC \nC output results\n IF (DEVICE .EQ. FILE) THEN\n WRITE (GUNIT,75) E\n WRITE (GUNIT,70) (X(IX),K(IX),IX=1,NGRF)\n ELSE \n CALL XYPLOT(X,K)\n END IF\n50 CONTINUE\nC \nC end graphing session\n IF (DEVICE .NE. FILE) CALL GPAGE(DEVICE) !close graphing package\n IF (DEVICE .EQ. SCREEN) CALL TMODE !switch to text mode\nC \n70 FORMAT (2(5X,E11.3))\n75 FORMAT (/,' Position vs. wave number for Energy =',1PE11.3)\n100 FORMAT (/,' Patience, please; output going to a file.')\nC \n RETURN\n END\n \n", "meta": {"hexsha": "564871f3376393b69e80acd1e8ba978f34bbd598", "size": 21238, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "Source-Koonin-Code/Example/exmpl1.for", "max_stars_repo_name": "ajz34/Comp-Phys-Koonin", "max_stars_repo_head_hexsha": "9fc371bdb44b7030025d254eda040a55bfa3b7cd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-10-29T12:21:38.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-31T17:03:43.000Z", "max_issues_repo_path": "Source-Koonin-Code/Example/exmpl1.for", "max_issues_repo_name": "ajz34/Comp-Phys-Koonin", "max_issues_repo_head_hexsha": "9fc371bdb44b7030025d254eda040a55bfa3b7cd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Source-Koonin-Code/Example/exmpl1.for", "max_forks_repo_name": "ajz34/Comp-Phys-Koonin", "max_forks_repo_head_hexsha": "9fc371bdb44b7030025d254eda040a55bfa3b7cd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.6172413793, "max_line_length": 75, "alphanum_fraction": 0.5828232414, "num_tokens": 5947, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.839733983715524, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.6659980137365852}} {"text": " subroutine anrs01(r,ir,m,b,x,ind,io)\nC SUBROUTINE ANRS01(R,IR,M,B,X,IND,IO)\nC\nC***********************************************************************\nC *\nC *\nC Copyright: Eduardo Casas Renteria *\nC Cecilia Pola Mendez *\nC *\nC Departamento de Matematicas,Estadistica y Computacion *\nC ----------------------------------------------------- *\nC UNIVERSIDAD DE CANTABRIA *\nC ------------------------ *\nC FEBRERO 1987 *\nC *\nC***********************************************************************\nC\nC OBJETIVO:\nC Esta subrutina resuelve un sistema de ecuaciones lineales en el\nC que la matriz de coeficientes es triangular.\nC\nC LISTA DE LLAMADA:\nC DE ENTRADA:\nC\nC R Matriz de dimension (IR,M),triangular superior.Contiene\nC en sus M primeras filas a la matriz de coeficientes del\nC sistema.La parte subdiagonal de R no es utilizada.\nC\nC IR Primera dimension de la matriz R. IR >= N.\nC\nC M Numero de filas y columnas de la matriz de coeficientes.\nC\nC B Vector M-dimensional.Guarda los terminos independientes\nC del sistema.\nC\nC IND Indica el tipo de sistema a resolver,con los valores:\nC 1 : Se resuelve R'x=b\nC 2 : Se resuelve Rx=b\nC\nC IO Numero de canal de salida de resultados.\nC\nC DE SALIDA:\nC\nC X Vector m-dimensional en el que se recoge la solucion\nC del sistema.\nC\nC Esta subrutina trabaja en doble precision via una sentencia\nC \"implicit\":\nC Implicit double precision (a-h,o-z)\nC\nC SUBPROGRAMAS AUXILIARES: ddot,d1mach\nC FUNCIONES FORTRAN INTRINSECAS: abs,mod\nC\nC\n implicit double precision(a-h,o-z)\n dimension r(ir,*),b(*),x(*)\nC\nC Se comprueba si los valores de las variables son correctos\nC\n if(m.lt.1 .or. ir.lt.1 .or. m.gt.ir .or. ind.lt.1 .or. ind.gt.2)\n & then\n write(io,1000) 'INCORRECT LIST OF CALLING IN ANRS01.'\n stop\n end if\nC\nC Se calcula un parametro para detectar la posible singularidad de\nC la matriz de coeficientes\nC\ncss epsmch=d1mach(4)**0.9\nCX epsmch=dlamch('p')**0.9\nC\nC Se comienza la resolucion del sistema segun sea el indicador\nC\n if(ind.eq.1) then\n j=1\n else\n j=m\n end if\nCX if(abs(r(j,j)).lt.epsmch) then\nCX write(io,1000) 'SINGULAR MATRIX IN ANRS01.'\nCX stop\nCX end if\n x(j)=b(j)/r(j,j)\n if(m.eq.1) return\n do 10 i=2,m\n i1=i-1\n if(ind.eq.1) then\n j=i\n j1=1\n j2=i\n j3=1\n k=1\n else\n j=m-i1\n j1=j\n j2=j+1\n j3=j2\n k=ir\n end if\nCX if(abs(r(j,j)).lt.epsmch) then\nCX write(io,1000) 'SINGULAR MATRIX IN ANRS01.'\nCX stop\nCX end if\n x(j)=(b(j)-ddot(i1,r(j1,j2),k,x(j3),1))/r(j,j)\n10 continue\n1000 format(10x,A)\n end\n", "meta": {"hexsha": "893f501fc1371fd8c5df20f0b9ff0a1618b32ee7", "size": 3553, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/optim/utils/anrs01.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/optim/utils/anrs01.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/optim/utils/anrs01.f", "max_forks_repo_name": "alpgodev/numx", "max_forks_repo_head_hexsha": "d2d3a0713020e1b83b65d3a661c3801ea256aff9", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.8981481481, "max_line_length": 72, "alphanum_fraction": 0.4503236701, "num_tokens": 916, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677699040321, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.6659163617611578}} {"text": "program reduction\n\n implicit none\n integer, parameter :: r15 = selected_real_kind(15)\n integer, parameter :: n = 40\n integer :: i, j\n\n real(kind=r15) :: euler = 1.0\n real(kind=r15) :: facto\n real(kind=r15), parameter :: e_ref = 2.71828182845904523536028747135266249775724709369995_r15\n\n !$OMP PARALLEL DO default(none) shared(euler) private(facto) reduction(+:euler)\n do i = 1, n\n\n facto = real(1)\n\n ! Not need to run this internal loop in the serial case\n ! Can you remove it and still use OpenMP?\n do j = 1, i\n facto = facto*j\n end do\n euler = euler + real(1)/facto\n print *, \"I= \", i, \"Euler Number: \", euler, \"Error: \", abs(euler - e_ref)\n\n end do\n !$OMP END PARALLEL DO\n\n print *, \"Final Euler Number: \", euler\n\nend program\n", "meta": {"hexsha": "b767ff21e5beeef1d02583c37d50257225dbd355", "size": 796, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "files/openmp/euler.f90", "max_stars_repo_name": "WVUHPC/Modern-Fortran", "max_stars_repo_head_hexsha": "97c4db834d4e6ca43802318e4dc63ce4faa641aa", "max_stars_repo_licenses": ["CC-BY-4.0"], "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": "files/openmp/euler.f90", "max_issues_repo_name": "WVUHPC/Modern-Fortran", "max_issues_repo_head_hexsha": "97c4db834d4e6ca43802318e4dc63ce4faa641aa", "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": "files/openmp/euler.f90", "max_forks_repo_name": "WVUHPC/Modern-Fortran", "max_forks_repo_head_hexsha": "97c4db834d4e6ca43802318e4dc63ce4faa641aa", "max_forks_repo_licenses": ["CC-BY-4.0"], "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": 25.6774193548, "max_line_length": 96, "alphanum_fraction": 0.6256281407, "num_tokens": 247, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778258, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.6659163612309982}} {"text": " program rebanamiento_formaciones\n implicit none\n integer :: i\n \n integer :: vector1(10) \n !1D formaci\u00f3n de 10 elementos\n \n integer :: matriz2(10,10) \n !D2 formaci\u00f3n de 100 elementos\n\n\n vector1=[1,2,3,4,5,6,7,8,9,10] \n !Constructor de formaciones \n print *,'vector1:'// achar(10) , vector1 \n\n vector1=[(i,i=1,10)]\n !Constructor de formaciones con bucle impl\u00edcito\n print *,'vector1:'\n print *, vector1 \n \n vector1(:)=0 \n !Por defecto todos los elementos igual a cero\n print *,'vector1:'// achar(10) , vector1\n\n vector1(1:5)=1 \n !Establecer los 5 primeros elemento igual a uno\n print *,'vector1:'// achar(10) , vector1\n\n vector1(6:)=1\n !Establecer del sexto al ultimo elemento igual a 1\n print *,'vector1:'// achar(10) , vector1\n\n\n print *,'Indices pares de vector1:'// achar(10),vector1(1:10:2) \n !Imprimir todos los elemento con indice par\n \n print *,'Columna 1 de matriz2:'// achar(10),matriz2(:,1)\n !Imprimir la primera columna de la formaci\u00f3n 2D\n\n print *,'vector1 en orden invertido:'// achar(10),vector1(10:1:-1)\n !Imprimir la formaci\u00f3n de diez elementos en orden decreciente por indice\n end program rebanamiento_formaciones\n", "meta": {"hexsha": "96aa7df3a0ab82cfce4e1f2c573d50709deb5a7d", "size": 1385, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Programas/rebanamiento_formaciones.f90", "max_stars_repo_name": "Marc-xyz/InicioRapidoEnFortran", "max_stars_repo_head_hexsha": "8cfe017877061bbfbb2bef66e16c2afc9375243d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-25T22:00:53.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-25T22:00:53.000Z", "max_issues_repo_path": "Programas/rebanamiento_formaciones.f90", "max_issues_repo_name": "Marc-xyz/InicioRapidoEnFortran", "max_issues_repo_head_hexsha": "8cfe017877061bbfbb2bef66e16c2afc9375243d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Programas/rebanamiento_formaciones.f90", "max_forks_repo_name": "Marc-xyz/InicioRapidoEnFortran", "max_forks_repo_head_hexsha": "8cfe017877061bbfbb2bef66e16c2afc9375243d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.2093023256, "max_line_length": 80, "alphanum_fraction": 0.5761732852, "num_tokens": 400, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7853085909370422, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.665916360965918}} {"text": "*----------------------------------------------------------------------*\n subroutine check_inv(ndim,mat,inv)\n*----------------------------------------------------------------------*\n* Check if inv is the inverse matrix of mat, giving a report\n*\n* ndim - dimension of the matrix\n*\n* yuri, set 2015\n*----------------------------------------------------------------------*\n implicit none\n\n include 'stdunit.h'\n\n integer, intent(in) ::\n & ndim\n real(8), intent(in) ::\n & mat(ndim,ndim), inv(ndim,ndim)\n\n integer ::\n & i,j,k\n real(8) ::\n & K_delta(ndim,ndim)\n\n do i=1,ndim\n do j=1,ndim\n K_delta(i,j) = 0d0\n do k=1,ndim\n K_delta(i,j) = K_delta(i,j) + mat(i,k)*inv(k,j)\n end do\n end do\n end do\n\n write(lulog,*) \"=====================\"\n write(lulog,*) \" check_inv\"\n write(lulog,*) \"Initial matrix, A:\"\n do i=1,ndim\n write(lulog,*) mat(i,:)\n end do\n write(lulog,*) \"---\"\n write(lulog,*) \"Proposed inverse matrix, A^-1:\"\n do i=1,ndim\n write(lulog,*) inv(i,:)\n end do\n write(lulog,*) \"---\"\n write(lulog,*) \"Their product:\"\n do i=1,ndim\n write(lulog,*) K_delta(i,:)\n end do\n write(lulog,*) \"=====================\"\n\n end\n", "meta": {"hexsha": "d7231d3caa65dd2338e547905273028f4172a9e0", "size": 1333, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "math/check_inv.f", "max_stars_repo_name": "ak-ustutt/GeCCo-public", "max_stars_repo_head_hexsha": "8d43a6c9323aeba7eb54625b95553bfd4b2418c6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "math/check_inv.f", "max_issues_repo_name": "ak-ustutt/GeCCo-public", "max_issues_repo_head_hexsha": "8d43a6c9323aeba7eb54625b95553bfd4b2418c6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "math/check_inv.f", "max_forks_repo_name": "ak-ustutt/GeCCo-public", "max_forks_repo_head_hexsha": "8d43a6c9323aeba7eb54625b95553bfd4b2418c6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.6346153846, "max_line_length": 72, "alphanum_fraction": 0.3945986497, "num_tokens": 377, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936879, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.6659163551965788}} {"text": " FUNCTION factrl(n)\r\n INTEGER n\r\n REAL factrl\r\nCU USES gammln\r\n INTEGER j,ntop\r\n REAL a(33),gammln\r\n SAVE ntop,a\r\n DATA ntop,a(1)/0,1./\r\n if (n.lt.0) then\r\n pause 'negative factorial in factrl'\r\n else if (n.le.ntop) then\r\n factrl=a(n+1)\r\n else if (n.le.32) then\r\n do 11 j=ntop+1,n\r\n a(j+1)=j*a(j)\r\n11 continue\r\n ntop=n\r\n factrl=a(n+1)\r\n else\r\n factrl=exp(gammln(n+1.))\r\n endif\r\n return\r\n END\r\n", "meta": {"hexsha": "0ac30267dc90e2fcc8b15a8376ceaddb3052f5cd", "size": 522, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/factrl.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/factrl.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/factrl.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": 21.75, "max_line_length": 45, "alphanum_fraction": 0.4750957854, "num_tokens": 173, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677660619633, "lm_q2_score": 0.7853085708384735, "lm_q1q2_score": 0.6659163544832134}} {"text": "!> The global constants are stored here and passed between the subroutines\n!! by including the module.\n module globalconsts\n implicit none\n\n\n integer, parameter :: dp = selected_real_kind(15,307)\n! some complex numbers\n complex(dp),parameter :: c0=(0.D0,0.D0),cr=(1.D0,0.D0),ci=(0.D0,1.D0)\n real(dp),parameter :: pi=4.D0*DATAN(1.D0)\n\n end module globalconsts\n\n!> The global variables are stored here and passed between the subroutines \n!! by including the module. You can also put these in a separate file.\n!! @param matdim specifies the dimensionality of the square matrices and vectors.\n!! @param matval specifies some of the values inside the matrices/vectors and should\n!! be a real number.\n!! @param specifies whether matrix diagonalization should be carried out\n\n\n module globalvars\n use globalconsts\n implicit none\n\n integer :: matdim\n real(dp) :: matval\n logical :: do_diag\n complex(dp),dimension(:,:),allocatable :: complex_matrix\n real(dp),dimension(:,:),allocatable :: real_matrix\n complex(dp),dimension(:),allocatable :: complex_vector\n real(dp),dimension(:),allocatable :: real_vector\n\n end module globalvars\n!> @file \n\n", "meta": {"hexsha": "27cb3dbe7e30e5b8182b91f5117043887d7a9fa0", "size": 1326, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/generic_data.f90", "max_stars_repo_name": "ssciwr/fortran-project-template", "max_stars_repo_head_hexsha": "490e94b416aafba2615329d696ccbb64572bbd8b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-02-02T05:10:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-09T11:49:17.000Z", "max_issues_repo_path": "src/generic_data.f90", "max_issues_repo_name": "ssciwr/fortran-project-template", "max_issues_repo_head_hexsha": "490e94b416aafba2615329d696ccbb64572bbd8b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-01-13T09:50:12.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-15T09:16:25.000Z", "max_forks_repo_path": "src/generic_data.f90", "max_forks_repo_name": "ssciwr/fortran-project-template", "max_forks_repo_head_hexsha": "490e94b416aafba2615329d696ccbb64572bbd8b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-28T10:52:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-28T10:52:14.000Z", "avg_line_length": 35.8378378378, "max_line_length": 89, "alphanum_fraction": 0.6387631976, "num_tokens": 306, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936879, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.6659163466751097}} {"text": " program main\n\nc*********************************************************************72\nc\ncc MAIN is the main program for CG_PRB.\nc\nc Discussion:\nc\nc CG_PRB tests the CG library.\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\n implicit none\n\n call timestamp ( )\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'CG_PRB'\n write ( *, '(a)' ) ' FORTRAN77 version'\n write ( *, '(a)' ) ' Test the CG library.'\n\n call test01 ( )\n call test02 ( )\n call test023 ( )\n call test025 ( )\n call test03 ( )\n call test04 ( )\n call test05 ( )\nc\nc Terminate.\nc\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'CG_PRB'\n write ( *, '(a)' ) ' Normal end of execution.'\n write ( *, '(a)' ) ' '\n call timestamp ( )\n\n stop\n end\n subroutine test01 ( )\n\nc*********************************************************************72\nc\ncc TEST01 tests R8GE_CG for a full storage matrix.\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\n implicit none\n\n integer n\n parameter ( n = 10 )\n\n double precision a(n,n)\n double precision b(n)\n double precision e_norm\n integer i\n double precision r(n)\n double precision r_norm\n double precision r8vec_diff_norm\n double precision r8vec_norm\n integer seed\n double precision x1(n)\n double precision x2(n)\n\n write ( *, '(a)' ) ''\n write ( *, '(a)' ) 'TEST01'\n write ( *, '(a)' ) \n & ' Test R8GE_CG, applying CG to a full storage matrix.'\nc\nc Choose a random positive definite symmetric matrix A.\nc\n seed = 123456789\n call pds_random ( n, seed, a )\nc\nc Choose a random solution.\nc\n seed = 123456789\n call r8vec_uniform_01 ( n, seed, x1 )\nc\nc Compute the corresponding right hand side.\nc\n call r8ge_mv ( n, n, a, x1, b )\nc\nc Call the CG routine.\nc\n do i = 1, n\n x2(i) = 1.0D+00\n end do\n\n call r8ge_cg ( n, a, b, x2 )\nc\nc Compute the residual.\nc\n call r8ge_resid ( n, n, a, x2, b, r )\n r_norm = r8vec_norm ( n, r )\nc\nc Compute the error.\nc\n e_norm = r8vec_diff_norm ( n, x1, x2 )\nc\nc Report.\nc\n write ( *, '(a)' ) ' '\n write ( *, '(a,i4)' ) ' Number of variables N = ', n\n write ( *, '(a,g14.6)' ) ' Norm of residual ||Ax-b|| = ', r_norm\n write ( *, '(a,g14.6)' ) ' Norm of error ||x1-x2|| = ', e_norm\n\n return\n end\n subroutine test02 ( )\n\nc*********************************************************************72\nc\ncc TEST02 tests R83_CG.\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\n implicit none\n\n integer n\n parameter ( n = 10 )\n\n double precision a(3,n)\n double precision b(n)\n double precision e_norm\n integer i\n double precision r(n)\n double precision r_norm\n double precision r8vec_diff_norm\n double precision r8vec_norm\n integer seed\n double precision x1(n)\n double precision x2(n)\n\n write ( *, '(a)' ) ''\n write ( *, '(a)' ) 'TEST02'\n write ( *, '(a)' ) ' Test R83_CG, applying CG to an R83 matrix.'\nc\nc Let A be the -1 2 -1 matrix.\nc\n call r83_dif2 ( n, n, a )\nc\nc Choose a random solution.\nc\n seed = 123456789\n call r8vec_uniform_01 ( n, seed, x1 )\nc\nc Compute the corresponding right hand side.\nc\n call r83_mv ( n, n, a, x1, b )\nc\nc Call the CG routine.\nc\n do i = 1, n\n x2(i) = 1.0D+00\n end do\n\n call r83_cg ( n, a, b, x2 )\nc\nc Compute the residual.\nc\n call r83_resid ( n, n, a, x2, b, r )\n r_norm = r8vec_norm ( n, r )\nc\nc Compute the error.\nc\n e_norm = r8vec_diff_norm ( n, x1, x2 )\nc\nc Report.\nc\n write ( *, '(a)' ) ' '\n write ( *, '(a,i4)' ) ' Number of variables N = ', n\n write ( *, '(a,g14.6)' ) ' Norm of residual ||Ax-b|| = ', r_norm\n write ( *, '(a,g14.6)' ) ' Norm of error ||x1-x2|| = ', e_norm\n\n return\n end\n subroutine test023 ( )\n\nc*********************************************************************72\nc\ncc TEST023 tests R83S_CG.\nc\nc Licensing:\nc\nc This code is distributed under the MIT license.\nc\nc Modified:\nc\nc 09 July 2014\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n integer n\n parameter ( n = 10 )\n\n double precision a(3)\n double precision b(n)\n double precision e_norm\n integer i\n double precision r(n)\n double precision r_norm\n double precision r8vec_diff_norm\n double precision r8vec_norm\n integer seed\n double precision x1(n)\n double precision x2(n)\n\n write ( *, '(a)' ) ''\n write ( *, '(a)' ) 'TEST023'\n write ( *, '(a)' ) \n & ' Test R83S_CG, applying CG to an R83S matrix.'\nc\nc Let A be the -1 2 -1 matrix.\nc\n call r83s_dif2 ( n, n, a )\nc\nc Choose a random solution.\nc\n seed = 123456789\n call r8vec_uniform_01 ( n, seed, x1 )\nc\nc Compute the corresponding right hand side.\nc\n call r83s_mv ( n, n, a, x1, b )\nc\nc Call the CG routine.\nc\n do i = 1, n\n x2(i) = 1.0D+00\n end do\n\n call r83s_cg ( n, a, b, x2 )\nc\nc Compute the residual.\nc\n call r83s_resid ( n, n, a, x2, b, r )\n r_norm = r8vec_norm ( n, r )\nc\nc Compute the error.\nc\n e_norm = r8vec_diff_norm ( n, x1, x2 )\nc\nc Report.\nc\n write ( *, '(a)' ) ' '\n write ( *, '(a,i4)' ) ' Number of variables N = ', n\n write ( *, '(a,g14.6)' ) ' Norm of residual ||Ax-b|| = ', r_norm\n write ( *, '(a,g14.6)' ) ' Norm of error ||x1-x2|| = ', e_norm\n\n return\n end\n subroutine test025 ( )\n\nc*********************************************************************72\nc\ncc TEST025 tests R83T_CG.\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\n implicit none\n\n integer n\n parameter ( n = 10 )\n\n double precision a(3,n)\n double precision b(n)\n double precision e_norm\n integer i\n double precision r(n)\n double precision r_norm\n double precision r8vec_diff_norm\n double precision r8vec_norm\n integer seed\n double precision x1(n)\n double precision x2(n)\n\n write ( *, '(a)' ) ''\n write ( *, '(a)' ) 'TEST025'\n write ( *, '(a)' ) \n & ' Test R83T_CG, applying CG to an R83T matrix.'\nc\nc Let A be the -1 2 -1 matrix.\nc\n call r83t_dif2 ( n, n, a )\nc\nc Choose a random solution.\nc\n seed = 123456789\n call r8vec_uniform_01 ( n, seed, x1 )\nc\nc Compute the corresponding right hand side.\nc\n call r83t_mv ( n, n, a, x1, b )\nc\nc Call the CG routine.\nc\n do i = 1, n\n x2(i) = 1.0D+00\n end do\n\n call r83t_cg ( n, a, b, x2 )\nc\nc Compute the residual.\nc\n call r83t_resid ( n, n, a, x2, b, r )\n r_norm = r8vec_norm ( n, r )\nc\nc Compute the error.\nc\n e_norm = r8vec_diff_norm ( n, x1, x2 )\nc\nc Report.\nc\n write ( *, '(a)' ) ' '\n write ( *, '(a,i4)' ) ' Number of variables N = ', n\n write ( *, '(a,g14.6)' ) ' Norm of residual ||Ax-b|| = ', r_norm\n write ( *, '(a,g14.6)' ) ' Norm of error ||x1-x2|| = ', e_norm\n\n return\n end\n subroutine test03 ( )\n\nc*********************************************************************72\nc\ncc TEST03 tests R8PBU_CG.\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\n implicit none\n\n integer mu\n parameter ( mu = 1 )\n integer n\n parameter ( n = 10 )\n\n double precision a(mu+1,n)\n double precision b(n)\n double precision e_norm\n integer i\n double precision r(n)\n double precision r_norm\n double precision r8vec_diff_norm\n double precision r8vec_norm\n integer seed\n double precision x1(n)\n double precision x2(n)\n\n write ( *, '(a)' ) ''\n write ( *, '(a)' ) 'TEST03'\n write ( *, '(a)' ) \n & ' Test R8PBU_CG, applying CG to an R8PBU matrix.'\nc\nc Let A be the -1 2 -1 matrix.\nc\n call r8pbu_dif2 ( n, n, mu, a )\nc\nc Choose a random solution.\nc\n seed = 123456789\n call r8vec_uniform_01 ( n, seed, x1 )\nc\nc Compute the corresponding right hand side.\nc\n call r8pbu_mv ( n, n, mu, a, x1, b )\nc\nc Call the CG routine.\nc\n do i = 1, n\n x2(i) = 1.0D+00\n end do\n\n call r8pbu_cg ( n, mu, a, b, x2 )\nc\nc Compute the residual.\nc\n call r8pbu_resid ( n, n, mu, a, x2, b, r )\n r_norm = r8vec_norm ( n, r )\nc\nc Compute the error.\nc\n e_norm = r8vec_diff_norm ( n, x1, x2 )\nc\nc Report.\nc\n write ( *, '(a)' ) ' '\n write ( *, '(a,i4)' ) ' Number of variables N = ', n\n write ( *, '(a,g14.6)' ) ' Norm of residual ||Ax-b|| = ', r_norm\n write ( *, '(a,g14.6)' ) ' Norm of error ||x1-x2|| = ', e_norm\n\n return\n end\n subroutine test04 ( )\n\nc*********************************************************************72\nc\ncc TEST04 tests R8SD_CG.\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\n implicit none\n\n integer n\n parameter ( n = 10 )\n integer ndiag\n parameter ( ndiag = 2 )\n\n double precision a(n,ndiag)\n double precision b(n)\n double precision e_norm\n integer i\n integer offset(ndiag)\n double precision r(n)\n double precision r_norm\n double precision r8vec_diff_norm\n double precision r8vec_norm\n integer seed\n double precision x1(n)\n double precision x2(n)\n\n write ( *, '(a)' ) ''\n write ( *, '(a)' ) 'TEST04'\n write ( *, '(a)' ) \n & ' Test R8SD_CG, applying CG to an R8SD matrix.'\n\n offset(1) = 0\n offset(2) = 1\nc\nc Set A to the [-1 2 -1] matrix.\nc\n call r8sd_dif2 ( n, n, ndiag, offset, a )\nc\nc Choose a random solution.\nc\n seed = 123456789\n call r8vec_uniform_01 ( n, seed, x1 )\nc\nc Compute the corresponding right hand side.\nc\n call r8sd_mv ( n, n, ndiag, offset, a, x1, b )\nc\nc Call the CG routine.\nc\n do i = 1, n\n x2(i) = 1.0D+00\n end do\n\n call r8sd_cg ( n, ndiag, offset, a, b, x2 )\nc\nc Compute the residual.\nc\n call r8sd_resid ( n, n, ndiag, offset, a, x2, b, r )\n r_norm = r8vec_norm ( n, r )\nc\nc Compute the error.\nc\n e_norm = r8vec_diff_norm ( n, x1, x2 )\nc\nc Report.\nc\n write ( *, '(a)' ) ' '\n write ( *, '(a,i4)' ) ' Number of variables N = ', n\n write ( *, '(a,g14.6)' ) ' Norm of residual ||Ax-b|| = ', r_norm\n write ( *, '(a,g14.6)' ) ' Norm of error ||x1-x2|| = ', e_norm\n\n return\n end\n subroutine test05 ( )\n\nc*********************************************************************72\nc\ncc TEST05 tests R8SP_CG.\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\n implicit none\n\n integer n\n parameter ( n = 10 )\n integer nz_num\n parameter ( nz_num = 3 * n - 2 )\n\n double precision a(nz_num)\n double precision b(n)\n integer col(nz_num)\n double precision e_norm\n integer i\n double precision r(n)\n integer row(nz_num)\n double precision r_norm\n double precision r8vec_diff_norm\n double precision r8vec_norm\n integer seed\n double precision x1(n)\n double precision x2(n)\n\n write ( *, '(a)' ) ''\n write ( *, '(a)' ) 'TEST05'\n write ( *, '(a)' ) \n & ' Test R8SP_CG, applying CG to an R8SP matrix.'\nc\nc Set A to the [-1 2 -1] matrix.\nc\n call r8sp_dif2 ( n, n, nz_num, row, col, a )\nc\nc Choose a random solution.\nc\n seed = 123456789\n call r8vec_uniform_01 ( n, seed, x1 )\nc\nc Compute the corresponding right hand side.\nc\n call r8sp_mv ( n, n, nz_num, row, col, a, x1, b )\nc\nc Call the CG routine.\nc\n do i = 1, n\n x2(i) = 1.0D+00\n end do\n\n call r8sp_cg ( n, nz_num, row, col, a, b, x2 )\nc\nc Compute the residual.\nc\n call r8sp_resid ( n, n, nz_num, row, col, a, x2, b, r )\n r_norm = r8vec_norm ( n, r )\nc\nc Compute the error.\nc\n e_norm = r8vec_diff_norm ( n, x1, x2 )\nc\nc Report.\nc\n write ( *, '(a)' ) ' '\n write ( *, '(a,i4)' ) ' Number of variables N = ', n\n write ( *, '(a,g14.6)' ) ' Norm of residual ||Ax-b|| = ', r_norm\n write ( *, '(a,g14.6)' ) ' Norm of error ||x1-x2|| = ', e_norm\n\n return\n end\n", "meta": {"hexsha": "f242d18c72df654c77c8bc9bec7b394300309e67", "size": 12809, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "cg_prb.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_prb.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_prb.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": 20.8615635179, "max_line_length": 72, "alphanum_fraction": 0.5331407604, "num_tokens": 4189, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677430095496, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.66591634064069}} {"text": " subroutine shp4T (QuadPt, nQpt, shp, shgl, wght)\nc\nc----------------------------------------------------------------------\nc\nc This subroutine generates shape functions for the 4-node\nc tetrahedra.\nc\nc input:\nc QuadPt (4,nQpt) : quadrature points' local coord's\nc QuadPt(1,*) : r\nc QuadPt(2,*) : s\nc QuadPt(3,*) : t\nc QuadPt(4,*) : wght\nc nQpt : number of quadrature points\nc\nc output:\nc shp (nen,nQpt) : shape functions\nc shgl (nsd,nen,nQpt) : local-gradient of shape function \nc wght (nQpt) : quadrature weights\nc\nc\nc shape-functions:\nc N1 = 1 - r - s - t\nc N2 = r\nc N3 = s\nc N4 = t\nc\nc Note: To be compatible with design of Tau and DC, the local \nc gradients are divided by 2. This is equivalent to having\nc r=[-1,1], s=[-1,1] and t=[-1,1], without really changing\nc r, s and t points (i.e., Qpt is for r=[0,1], s=[0,1] and\nc t=[0,1] range)\nc\nc Zdenek Johan, Summer 1990.\nc----------------------------------------------------------------------\nc\n include \"common.h\"\nc\n dimension QuadPt(4,*), shp(nen,*),\n & shgl(nsd,nen,*), wght(*)\nc\nc.... loop through quadrature points\nc\n do m = 1, nQpt\nc\nc.... generate the local-shape-functions\nc\n shp(1,m) = one - QuadPt(1,m) - QuadPt(2,m) - QuadPt(3,m)\n shp(2,m) = QuadPt(1,m)\n shp(3,m) = QuadPt(2,m)\n shp(4,m) = QuadPt(3,m)\nc\nc.... generate the grad-local-shape-functions\nc\n shgl(1,1,m) = -pt5\n shgl(2,1,m) = -pt5\n shgl(3,1,m) = -pt5\n shgl(1,2,m) = pt5\n shgl(2,2,m) = zero\n shgl(3,2,m) = zero\n shgl(1,3,m) = zero\n shgl(2,3,m) = pt5\n shgl(3,3,m) = zero\n shgl(1,4,m) = zero\n shgl(2,4,m) = zero\n shgl(3,4,m) = pt5\nc\nc.... copy the weight\nc\n wght(m) = QuadPt(4,m)\nc\nc.... end of shape-function loop\nc\n enddo\nc\nc.... return\nc\n return\n end\n", "meta": {"hexsha": "5a4b45cbd5785c5972008cc4529166798f162200", "size": 2193, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "phSolver/common/shp4t.f", "max_stars_repo_name": "yangf4/phasta", "max_stars_repo_head_hexsha": "a096094f33b98047de0a2e28225c4d74875a88d8", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 49, "max_stars_repo_stars_event_min_datetime": "2015-04-16T13:45:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-07T01:02:49.000Z", "max_issues_repo_path": "phSolver/common/shp4t.f", "max_issues_repo_name": "yangf4/phasta", "max_issues_repo_head_hexsha": "a096094f33b98047de0a2e28225c4d74875a88d8", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 21, "max_issues_repo_issues_event_min_datetime": "2015-10-06T19:50:43.000Z", "max_issues_repo_issues_event_max_datetime": "2017-12-17T03:47:51.000Z", "max_forks_repo_path": "phSolver/common/shp4t.f", "max_forks_repo_name": "yangf4/phasta", "max_forks_repo_head_hexsha": "a096094f33b98047de0a2e28225c4d74875a88d8", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 38, "max_forks_repo_forks_event_min_datetime": "2015-04-21T12:13:40.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-12T19:38:00.000Z", "avg_line_length": 27.4125, "max_line_length": 71, "alphanum_fraction": 0.4464204286, "num_tokens": 731, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099168, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.6658812660605804}} {"text": "module mod_monolis_stdlib\n use mod_monolis_prm\n implicit none\n\ncontains\n\n function monolis_normalize_cross_product_3d(a, b)\n implicit none\n real(kdouble) :: monolis_normalize_cross_product_3d(3), a(3), b(3), norm(3), l2\n\n norm(1) = a(2)*b(3) - a(3)*b(2)\n norm(2) = a(3)*b(1) - a(1)*b(3)\n norm(3) = a(1)*b(2) - a(2)*b(1)\n l2 = dsqrt(norm(1)*norm(1) + norm(2)*norm(2) + norm(3)*norm(3))\n if(l2 == 0.0d0)then\n monolis_normalize_cross_product_3d = 0.0d0\n return\n endif\n monolis_normalize_cross_product_3d = norm/l2\n end function monolis_normalize_cross_product_3d\n\n function monolis_normalize_vector(n, a)\n implicit none\n integer(kint) :: i, n\n real(kdouble) :: monolis_normalize_vector(n), a(n), l2\n\n l2 = 0.0d0\n do i = 1, n\n l2 = l2 + a(i)*a(i)\n enddo\n l2 = dsqrt(l2)\n if(l2 == 0.0d0)then\n monolis_normalize_vector = 0.0d0\n return\n endif\n monolis_normalize_vector = a/l2\n end function monolis_normalize_vector\n\n function monolis_get_l2_norm(n, a)\n implicit none\n integer(kint) :: i, n\n real(kdouble) :: monolis_get_l2_norm, a(n), l2\n\n l2 = 0.0d0\n do i = 1, n\n l2 = l2 + a(i)*a(i)\n enddo\n monolis_get_l2_norm = dsqrt(l2)\n end function monolis_get_l2_norm\n\n subroutine monolis_global_to_local_elem(nnode, nid, nelem, e, nenode)\n implicit none\n integer(kint) :: i, in, j, id, nenode\n integer(kint) :: nnode, nid(:)\n integer(kint) :: nelem, e(:,:)\n integer(kint), allocatable :: perm(:), temp(:)\n\n allocate(temp(nnode), source = 0)\n allocate(perm(nnode), source = 0)\n do i = 1, nnode\n temp(i) = nid(i)\n perm(i) = i\n enddo\n call monolis_qsort_int_with_perm(temp, 1, nnode, perm)\n\n do i = 1, nelem\n do j = 1, nenode\n in = e(j,i)\n call monolis_bsearch_int(temp, 1, nnode, in, id)\n if(id == -1)then\n e(j,i) = -1\n else\n e(j,i) = perm(id)\n endif\n enddo\n enddo\n end subroutine monolis_global_to_local_elem\n\n subroutine monolis_global_to_local_conditoin(nnode, nid, nb, b)\n implicit none\n integer(kint) :: i, in, id, nb\n integer(kint) :: nnode, nid(:)\n integer(kint) :: b(:,:)\n integer(kint), allocatable :: temp(:), perm(:)\n\n allocate(temp(nnode), source = 0)\n allocate(perm(nnode), source = 0)\n do i = 1, nnode\n temp(i) = nid(i)\n perm(i) = i\n enddo\n call monolis_qsort_int_with_perm(temp, 1, nnode, perm)\n\n do i = 1, nb\n in = b(1,i)\n call monolis_bsearch_int(temp, 1, nnode, in, id)\n if(id == -1)then\n b(1,i) = -1\n else\n b(1,i) = perm(id)\n endif\n enddo\n end subroutine monolis_global_to_local_conditoin\n\n subroutine monolis_get_inverse_matrix(n, a, inv)\n implicit none\n integer(kint) :: n, i, j, k\n real(kdouble) :: a(n,n), inv(n,n), tmp\n\n inv = 0.0d0\n do i = 1, n\n inv(i,i) = 1.0d0\n enddo\n\n do i = 1, n\n tmp = 1.0d0/a(i,i)\n do j = 1, n\n a(j,i) = a(j,i) * tmp\n inv(j,i) = inv(j,i) * tmp\n enddo\n do j = 1, n\n if(i /= j) then\n tmp = a(i,j)\n do k = 1, n\n a(k,j) = a(k,j) - a(k,i) * tmp\n inv(k,j) = inv(k,j) - inv(k,i) * tmp\n enddo\n endif\n enddo\n enddo\n end subroutine monolis_get_inverse_matrix\n\n recursive subroutine monolis_qsort_int(array, iS, iE)\n implicit none\n integer(kint), intent(inout) :: array(:)\n integer(kint), intent(in) :: iS, iE\n integer(kint) :: pivot, center, left, right, tmp\n\n if (iS >= iE) return\n\n center = (iS + iE) / 2\n pivot = array(center)\n left = iS\n right = iE\n\n do\n do while (array(left) < pivot)\n left = left + 1\n enddo\n do while (pivot < array(right))\n right = right - 1\n enddo\n\n if (left >= right) exit\n\n tmp = array(left)\n array(left) = array(right)\n array(right) = tmp\n\n left = left + 1\n right = right - 1\n enddo\n\n if(iS < left-1) call monolis_qsort_int(array, iS, left-1)\n if(right+1 < iE) call monolis_qsort_int(array, right+1, iE)\n end subroutine monolis_qsort_int\n\n recursive subroutine monolis_qsort_int_with_perm(array, iS, iE, perm)\n implicit none\n integer(kint), intent(inout) :: array(:), perm(:)\n integer(kint), intent(in) :: iS, iE\n integer(kint) :: pivot, center, left, right, tmp\n\n if (iS >= iE) return\n\n center = (iS + iE) / 2\n pivot = array(center)\n left = iS\n right = iE\n\n do\n do while (array(left) < pivot)\n left = left + 1\n enddo\n do while (pivot < array(right))\n right = right - 1\n enddo\n\n if (left >= right) exit\n\n tmp = array(left)\n array(left) = array(right)\n array(right) = tmp\n\n tmp = perm(left)\n perm(left) = perm(right)\n perm(right) = tmp\n\n left = left + 1\n right = right - 1\n enddo\n\n if(iS < left-1) call monolis_qsort_int_with_perm(array, iS, left-1, perm)\n if(right+1 < iE) call monolis_qsort_int_with_perm(array, right+1, iE, perm)\n end subroutine monolis_qsort_int_with_perm\n\n subroutine monolis_bsearch_int(array, iS, iE, val, idx)\n implicit none\n integer(kint), intent(in) :: array(:)\n integer(kint), intent(in) :: iS, iE\n integer(kint), intent(in) :: val\n integer(kint), intent(out) :: idx\n integer(kint) :: center, left, right, pivot\n\n left = iS\n right = iE\n\n do\n if (left > right) then\n idx = -1\n exit\n endif\n center = (left + right) / 2\n pivot = array(center)\n if (val < pivot) then\n right = center - 1\n cycle\n elseif (pivot < val) then\n left = center + 1\n cycle\n else\n idx = center\n exit\n endif\n enddo\n end subroutine monolis_bsearch_int\n\n subroutine monolis_bsearch_int_with_position(array, iS, iE, val, idx, pos)\n implicit none\n integer(kint), intent(in) :: array(:)\n integer(kint), intent(in) :: iS, iE\n integer(kint), intent(in) :: val\n integer(kint), intent(out) :: idx, pos\n integer(kint) :: center, left, right, pivot\n\n pos = -1\n left = iS\n right = iE\n\n do\n if (left > right) then\n idx = -1\n pos = right\n exit\n endif\n center = (left + right) / 2\n pivot = array(center)\n if (val < pivot) then\n right = center - 1\n cycle\n elseif (pivot < val) then\n left = center + 1\n cycle\n else\n idx = center\n pos = -1\n exit\n endif\n enddo\n end subroutine monolis_bsearch_int_with_position\n\n subroutine monolis_uniq_int(array, len, newlen)\n implicit none\n integer(kint), intent(inout) :: array(:)\n integer(kint), intent(in) :: len\n integer(kint), intent(out) :: newlen\n integer(kint) :: i, ndup\n\n ndup = 0\n do i = 2, len\n if(array(i) == array(i - 1 - ndup))then\n ndup = ndup + 1\n elseif(ndup > 0)then\n array(i - ndup) = array(i)\n endif\n end do\n newlen = len - ndup\n end subroutine monolis_uniq_int\n\n subroutine monolis_reallocate_integer(array, nold, n, add)\n implicit none\n integer(kint), allocatable :: array(:), temp(:)\n integer(kint) :: i, n, nold, add(n)\n\n if(nold == 0)then\n allocate(array(n))\n else\n allocate(temp(nold))\n temp = array\n deallocate(array)\n allocate(array(nold + n))\n\n do i = 1, nold\n array(i) = temp(i)\n enddo\n endif\n\n do i = nold + 1, nold + n\n array(i) = add(i-nold)\n enddo\n end subroutine monolis_reallocate_integer\n\n subroutine monolis_pointer_reallocate_integer(array, nold, n, add)\n implicit none\n integer(kint), pointer :: array(:), temp(:)\n integer(kint) :: i, n, nold, add(n)\n\n if(nold == 0)then\n allocate(array(n))\n else\n allocate(temp(nold))\n temp = array\n deallocate(array)\n allocate(array(nold + n))\n\n do i = 1, nold\n array(i) = temp(i)\n enddo\n endif\n\n do i = nold + 1, nold + n\n array(i) = add(i-nold)\n enddo\n end subroutine monolis_pointer_reallocate_integer\n\nend module mod_monolis_stdlib\n", "meta": {"hexsha": "a74c873240d97642de1c022399cfe45076a3d67b", "size": 8134, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/util/stdlib.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/util/stdlib.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/util/stdlib.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": 24.1364985163, "max_line_length": 83, "alphanum_fraction": 0.5721662159, "num_tokens": 2671, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007394, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.6658812626837735}} {"text": "! ============================================================================\n! Name : main.f90\n! Author : Giovanni Dalmasso\n! Date : Mar 12, 2013\n! Version : 1.1\n! Copyright : Department of Computational Hydrosystems CHS - UZF Leipzig\n! Description : main test mo_ode_solver\n! ============================================================================\n\nprogram main_test_mo_ode_solver\n\n use mo_kind, only : i4, sp, dp\n use mo_ansi_colors, only: color, c_red, c_green\n use mo_eq_lv, only : LV_eqn_sp, LV_eqn_dp, LV_eqn_para_sp, LV_eqn_para_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 use mo_ode_solver, only : EULER, RK4, RK4as, RBstiff\n\n implicit none\n\n integer(i4) :: nEq ! number of equation\n real(sp) :: x1 ! initial time point\n real(sp) :: x2 ! final time point\n real(sp) :: h ! time step\n real(sp) :: hmin ! minimum allowed stepsize\n real(sp) :: eps ! accurancy\n real(sp) :: test ! test variable\n real(sp), dimension(:), allocatable :: yi ! initial conditions\n real(sp), dimension(:), allocatable :: xout ! output time\n real(sp), dimension(:,:), allocatable :: yout ! output solutions\n real(sp), dimension(3) :: para ! parameter for derivs\n \n real(dp) :: dx1 ! initial time point\n real(dp) :: dx2 ! final time point\n real(dp) :: dh ! time step\n real(dp) :: dhmin ! minimum allowed stepsize\n real(dp) :: deps ! accurancy\n real(dp) :: dtest ! test variable\n real(dp), dimension(:), allocatable :: dyi ! initial conditions\n real(dp), dimension(:), allocatable :: dxout ! output time\n real(dp), dimension(:,:), allocatable :: dyout ! output solutions\n real(dp), dimension(3) :: dpara ! parameter for derivs\n\n logical :: isgood\n\n\n isgood = .true. ! test variable\n\n ! sp\n test = 1.0e4_sp ! test variable\n\n nEq = 2_i4 ! number of equations\n x1 = 0._sp ! intial time\n x2 = 10._sp ! final time\n h = 0.1_sp ! incremental time step\n hmin = h*1.0e-11_sp ! minimum allowed stepsize\n eps = 1e-8_sp ! accuracy\n\n para = (/0.5_sp, 2.0_sp, -1.0_sp/)\n\n allocate( yi(nEq) )\n yi = (/ 1._sp, 1._sp /) ! initial conditions\n\n ! Euler method\n call Euler( yi, x1, x2, h, LV_eqn_sp, xout, yout )\n if ( nint(xout(2)*test) .ne. 1000_i4 .or. any(nint(yout(2,:)*test) .ne. (/ 10000_i4, 13000_i4 /)) ) isgood = .false. ! test\n if (.not. isgood) write(*,*) \"euler sp\"\n\n ! 4th order RUNGE-KUTTA method\n call RK4( yi, x1, x2, h, LV_eqn_sp, xout, yout )\n if ( nint(xout(2)*test) .ne. 1000_i4 .or. any(nint(yout(2,:)*test) .ne. (/ 9850_i4, 12835_i4 /)) ) isgood = .false. ! test\n if (.not. isgood) write(*,*) \"rk sp\"\n\n ! 4th order RUNGE-KUTTA Adaptive Step-size\n call RK4as( yi, x1, x2, h, LV_eqn_sp, xout, yout, hmin=hmin, eps=eps )\n\t\n#if defined (__pgiFortran__) || defined (__INTEL__)\n ! PGI compiler other rounding errors in single precision, Intel in release mode\n if ( nint(xout(2)*test*1.0e-1_sp) .ne. 58_i4 .or. &\n any(nint(yout(2,:)*test*1.0e-1_sp) .ne. (/ 995_i4, 1169_i4 /)) ) isgood = .false.\n#else\n if ( nint(xout(2)*test) .ne. 580_i4 .or. any(nint(yout(2,:)*test) .ne. (/ 9950_i4, 11687_i4 /)) ) isgood = .false.\n#endif\n ! test\n if (.not. isgood) write(*,*) \"rk-as sp\"\n\n ! Rosenbrock Method\n call RBstiff( (/1.0_sp,1.0_sp,0.0_sp/), 0.0_sp, 50.0_sp, 2.9e-4_sp, deriv2_testRB_sp,&\n jacobn2_testRB_sp, xout, yout, hmin=hmin, eps=1e-4_sp )\n if ( nint(xout(2)*test) .ne. 3_i4 .or.&\n any(nint(yout(2,:)*test) .ne. (/ 10000_i4, 10000_i4, 0_i4 /)) )&\n isgood = .false. ! test\n if (.not. isgood) write(*,*) \"rb-stiff sp\"\n\n\n !with parameters\n\n ! Euler method with parameter\n call Euler( yi, x1, x2, h, LV_eqn_para_sp, para, xout, yout )\n if ( nint(xout(2)*test) .ne. 1000_i4 .or. any(nint(yout(2,:)*test) .ne. (/ 10000_i4, 13000_i4 /)) ) isgood = .false. ! test\n if (.not. isgood) write(*,*) \"euler sp para\"\n\n ! 4th order RUNGE-KUTTA method with parameter\n call RK4( yi, x1, x2, h, LV_eqn_para_sp, para, xout, yout )\n#if defined (__pgiFortran__) || defined (__INTEL__)\n if ( nint(xout(2)*test*1e-1) .ne. 100_i4 .or. any(nint(yout(2,:)*test*1e-1) .ne. (/ 985_i4, 1284_i4 /)) ) isgood = .false. ! test\n#else\n if ( nint(xout(2)*test) .ne. 1000_i4 .or. any(nint(yout(2,:)*test) .ne. (/ 9850_i4, 12835_i4 /)) ) isgood = .false. ! test\n#endif\n if (.not. isgood) write(*,*) \"rk sp para\"\n\n ! 4th order RUNGE-KUTTA Adaptive Step-size with parameter\n call RK4as( yi, x1, x2, h, LV_eqn_para_sp, para, xout, yout, hmin=hmin, eps=eps )\n#if defined (__pgiFortran__) || defined (__INTEL__)\n if ( nint(xout(2)*test*1e-1) .ne. 58_i4 .or. any(nint(yout(2,:)*test*1e-1) .ne. (/ 995_i4, 1169_i4 /)) ) isgood = .false. ! test\n#else\n if ( nint(xout(2)*test) .ne. 580_i4 .or. any(nint(yout(2,:)*test) .ne. (/ 9950_i4, 11687_i4 /)) ) isgood = .false. ! test\n#endif\n if (.not. isgood) write(*,*) \"rk-as sp para\"\n\n ! Rosenbrock Method with parameter\n call RBstiff( (/1.0_sp,1.0_sp,0.0_sp/), 0.0_sp, 50.0_sp, 2.9e-4_sp, deriv2_testRB_para_sp,&\n jacobn2_testRB_para_sp, (/1000.0_sp/), xout, yout, hmin=hmin, eps=1e-4_sp )\n#if defined (__pgiFortran__) || defined (__INTEL__)\n if ( nint(xout(2)*test*1e-1) .ne. 0_i4 .or.&\n any(nint(yout(2,:)*test*1e-1) .ne. (/ 1000_i4, 1000_i4, 0_i4 /)) )&\n isgood = .false. ! test\n#else\n if ( nint(xout(2)*test) .ne. 3_i4 .or.&\n any(nint(yout(2,:)*test) .ne. (/ 10000_i4, 10000_i4, 0_i4 /)) )&\n isgood = .false. ! test\n#endif\n if (.not. isgood) write(*,*) \"rb-stiff sp\"\n\n\n!dp\n dtest = 1e8_dp ! test variable\n\n nEq = 2_i4 ! number of equations\n dx1 = 0._dp ! intial time\n dx2 = 10._dp ! final time\n dh = 0.1_dp ! incremental time step\n dhmin = h*1e-11_dp ! minimum allowed stepsize\n deps = 1e-8_dp ! accuracy\n\n dpara = (/0.5_dp, 2.0_dp, -1.0_dp/)\n\n allocate( dyi(nEq) )\n dyi = (/ 1._dp, 1._dp /) ! initial conditions\n\n ! Euler method\n call Euler( dyi, dx1, dx2, dh, LV_eqn_dp, dxout, dyout )\n if ( nint(dxout(2)*dtest) .ne. 10000000_i4 .or. &\n any(nint(dyout(2,:)*dtest) .ne. (/ 100000000_i4, 130000000_i4 /)) ) isgood = .false. ! test\n if (.not. isgood) write(*,*) \"euler dp\"\n\n ! 4th order RUNGE-KUTTA method\n call RK4( dyi, dx1, dx2, dh, LV_eqn_dp, dxout, dyout )\n if ( nint(dxout(2)*dtest) .ne. 10000000_i4 .or. &\n any(nint(dyout(2,:)*dtest) .ne. (/ 98503750_i4, 128353750_i4 /)) ) isgood = .false. ! test\n if (.not. isgood) write(*,*) \"rk dp\"\n\n ! 4th order RUNGE-KUTTA Adaptive Step-size\n call RK4as( dyi, dx1, dx2, dh, LV_eqn_dp, dxout, dyout, hmin=dhmin, eps=deps )\n if ( nint(dxout(2)*dtest) .ne. 6008771_i4 .or. &\n any(nint(dyout(2,:)*dtest) .ne. (/ 99458909_i4, 117452697_i4 /)) ) isgood = .false. ! test\n if (.not. isgood) write(*,*) \"rk-as dp\"\n\n ! Rosenbrock Method\n call RBstiff( (/1.0_dp,1.0_dp,0.0_dp/), 0.0_dp, 50.0_dp, 2.9e-4_dp, deriv2_testRB_dp,&\n jacobn2_testRB_dp, dxout, dyout, hmin=dhmin, eps=1e-4_dp )\n if ( nint(dxout(2)*dtest) .ne. 29000_i4 .or.&\n any(nint(dyout(2,:)*dtest) .ne. (/ 99999663_i4, 100000100_i4, -237_i4 /)) )&\n isgood = .false. ! test\n if (.not. isgood) write(*,*) \"rb-stiff dp\"\n\n !with parameters\n\n ! Euler method with parameters\n call Euler( dyi, dx1, dx2, dh, LV_eqn_para_dp, dpara, dxout, dyout )\n if ( nint(dxout(2)*dtest) .ne. 10000000_i4 .or. &\n any(nint(dyout(2,:)*dtest) .ne. (/ 100000000_i4, 130000000_i4 /)) ) isgood = .false. ! test\n if (.not. isgood) write(*,*) \"euler dp para\"\n\n! write(*,*) dxout(2), dyout(2,:)\n! write(*,*) nint(dxout(2)*dtest), nint(dyout(2,:)*dtest)\n\n ! 4th order RUNGE-KUTTA method with parameters\n call RK4( dyi, dx1, dx2, dh, LV_eqn_para_dp, dpara, dxout, dyout )\n if ( nint(dxout(2)*dtest) .ne. 10000000_i4 .or. &\n any(nint(dyout(2,:)*dtest) .ne. (/ 98503750_i4, 128353750_i4 /)) ) isgood = .false. ! test\n if (.not. isgood) write(*,*) \"rk dp para\"\n\n! write(*,*) dxout(2), dyout(2,:)\n! write(*,*) nint(dxout(2)*dtest), nint(dyout(2,:)*dtest)\n\n ! 4th order RUNGE-KUTTA Adaptive Step-size with parameters\n call RK4as( dyi, dx1, dx2, dh, LV_eqn_para_dp, dpara, dxout, dyout, hmin=dhmin, eps=deps )\n if ( nint(dxout(2)*dtest) .ne. 6008771_i4 .or. &\n any(nint(dyout(2,:)*dtest) .ne. (/ 99458909_i4, 117452697_i4 /)) ) isgood = .false. ! test\n if (.not. isgood) write(*,*) \"rk-as dp para\"\n\n! write(*,*) dxout(2), dyout(2,:)\n! write(*,*) nint(dxout(2)*dtest), nint(dyout(2,:)*dtest)\n\n ! Rosenbrock Method with parameter\n call RBstiff( (/1.0_dp,1.0_dp,0.0_dp/), 0.0_dp, 50.0_dp, 2.9e-4_dp, deriv2_testRB_para_dp,&\n jacobn2_testRB_para_dp, (/1000.0_dp/), dxout, dyout, hmin=dhmin, eps=1e-4_dp )\n if ( nint(dxout(2)*dtest) .ne. 29000_i4 .or.&\n any(nint(dyout(2,:)*dtest) .ne. (/ 99999663_i4, 100000100_i4, -237_i4 /)) )&\n isgood = .false. ! test\n if (.not. isgood) write(*,*) \"rb-stiff dp para\"\n\n! write(*,*) dxout(2), dyout(2,:)\n! write(*,*) nint(dxout(2)*dtest), nint(dyout(2,:)*dtest)\n\n\n! Is the program running properly?\n write(*,*) ''\n write(*,*) '------------------------------------------'\n if (isgood) then\n write(*,*) 'mo_ode_solver ', color('o.k.', c_green)\n else\n write(*,*) 'mo_ode_solver ', color('failed!', c_red)\n endif\n write(*,*) '-------------------END---------------------'\n\nend program main_test_mo_ode_solver\n", "meta": {"hexsha": "b1314b9a9890f1e3d987d12954b90b66095be674", "size": 10626, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/test_mo_ode_solver/main.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/main.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/main.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": 46.0, "max_line_length": 137, "alphanum_fraction": 0.5396198005, "num_tokens": 3819, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007393, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.6658812626837733}} {"text": "program power\r\nimplicit none\r\ninteger, parameter :: n = 10**8, dp = kind(1.0d0)\r\nreal(kind=dp) :: x(n),t(3)\r\ncall random_number(x)\r\ncall cpu_time(t(1))\r\nwrite (*,\"(a20,f20.10)\") \"sum(x**2.0_dp) =\",sum(x**2.0_dp)\r\ncall cpu_time(t(2))\r\nwrite (*,\"(a20,f20.10)\") \"sum(x**2) =\",sum(x**2)\r\ncall cpu_time(t(3))\r\nwrite (*,\"(/,a10,*(1x,a10))\") \"method\",\"x**2.0_dp\",\"x**2\"\r\nwrite (*,\"(a10,*(1x,f10.4))\") \"time\",t(2:3) - t(1:2)\r\nend program power\r\n! gfortran -O0 output\r\n!\r\n! sum(x**2.0_dp) = 33334073.2750587128\r\n! sum(x**2) = 33334073.2750587128\r\n! \r\n! method x**2.0_dp x**2\r\n! time 1.3281 0.1250\r\n!\r\n! for gfortran -O3 the times are the same \r\n! for x**2.0_dp and x**2", "meta": {"hexsha": "a5fd56f6ec16a2b6cc31f9cb40386e977623b479", "size": 698, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "pow_real.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": "pow_real.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": "pow_real.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": 30.347826087, "max_line_length": 59, "alphanum_fraction": 0.5544412607, "num_tokens": 292, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190939, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.6658812604906884}} {"text": "module jacobi\n\n implicit none\n\ncontains\n\nsubroutine jacobistep(psinew, psi, m, n)\n\n integer :: m, n\n double precision, dimension(0:m+1, 0:n+1) :: psinew, psi\n\n!$omp parallel workshare\n psinew(1:m, 1:n) = 0.25d0*(psi(2:m+1, 1:n) + psi(0:m-1, 1:n) + &\n psi(1:m, 2:n+1) + psi(1:m, 0:n-1) )\n!$omp end parallel workshare\n \nend subroutine jacobistep\n\nsubroutine jacobistepvort(zetnew, psinew, zet, psi, m, n, re)\n\n integer :: m, n\n double precision :: re \n double precision, dimension(0:m+1, 0:n+1) :: zetnew, zet, psinew, psi\n\n!$omp parallel workshare\n psinew(1:m, 1:n) = 0.25d0*(psi(2:m+1, 1:n) + psi(0:m-1, 1:n) + &\n psi(1:m, 2:n+1) + psi(1:m, 0:n-1) - &\n zet(1:m, 1:n))\n\n zetnew(1:m, 1:n) = 0.25d0*(zet(2:m+1, 1:n) + zet(0:m-1, 1:n) + &\n zet(1:m, 2:n+1) + zet(1:m, 0:n-1) ) - &\n re/16.0*((psi(1:m, 2:n+1) - psi(1:m, 0:n-1)) * &\n (zet(2:m+1, 1:n) - zet(0:m-1, 1:n)) - &\n (psi(2:m+1, 1:n) - psi(0:m-1, 1:n)) * &\n (zet(1:m, 2:n+1) - zet(1:m, 0:n-1)) )\n!$omp end parallel workshare\n \nend subroutine jacobistepvort\n\ndouble precision function deltasq(new, old, m, n)\n\n integer :: m, n, j\n double precision, dimension(0:m+1, 0:n+1) :: new, old\n\n integer :: ierr\n\n deltasq = 0.0\n\n!$omp parallel do default(none) &\n!$omp& private(j) shared(new,old,m,n) reduction(+:deltasq)\n do j = 1, n\n deltasq = deltasq + sum((new(1:m,j)-old(1:m,j))**2)\n end do\n!$omp end parallel do\n\nend function deltasq\n\nend module jacobi\n", "meta": {"hexsha": "baef81766ea8636f6eeb1c38af57b88e3912adb7", "size": 1655, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "F-OMP/jacobi.f90", "max_stars_repo_name": "davidhenty/CFD", "max_stars_repo_head_hexsha": "2f22d1afb564fa6e11fdf9316c669ea977d71888", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2019-04-26T04:51:29.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-10T16:52:05.000Z", "max_issues_repo_path": "F-OMP/jacobi.f90", "max_issues_repo_name": "davidhenty/CFD", "max_issues_repo_head_hexsha": "2f22d1afb564fa6e11fdf9316c669ea977d71888", "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": "F-OMP/jacobi.f90", "max_forks_repo_name": "davidhenty/CFD", "max_forks_repo_head_hexsha": "2f22d1afb564fa6e11fdf9316c669ea977d71888", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2019-04-26T04:51:30.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-26T04:43:11.000Z", "avg_line_length": 28.0508474576, "max_line_length": 71, "alphanum_fraction": 0.5087613293, "num_tokens": 667, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190939, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.6658812515439898}} {"text": " FUNCTION Quadrilinear(Vmid,HyperCube,dt,dx,dy,dz) RESULT (F)\n\n IMPLICIT NONE\n REAL(KIND(0D0)),DIMENSION(0:1,0:1,0:1,0:1) :: HyperCube\n REAL(KIND(0D0)),DIMENSION(0:3) :: Vmid\n REAL(KIND(0D0)) :: dt, dx, dy, dz, F\n REAL(KIND(0D0)) :: t, x, y, z\n INTEGER :: n,i,j,k\n\n F = 0D0\n t = Vmid(0)/dt\n x = Vmid(1)/dx\n y = Vmid(2)/dy\n z = Vmid(3)/dz\n\n DO k = 0,1\n DO j = 0,1\n DO i = 0,1\n DO n = 0,1\n F = F + (n*t+(1-n)*(1-t))*(i*x+(1-i)*(1-x)) &\n *(j*y+(1-j)*(1-y))*(k*z+(1-k)*(1-z)) &\n *HyperCube(n,i,j,k)\n\n END DO\n END DO\n END DO\n END DO\n\n END FUNCTION Quadrilinear\n", "meta": {"hexsha": "259667d4b48c8ce2b6d6b9640b29fca4fb03ec98", "size": 742, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/urqmd-3.4/sources/quadri.f90", "max_stars_repo_name": "kotania/impy", "max_stars_repo_head_hexsha": "85ddd5764a3c1f955fae8d1b9422b619d4d12a4d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2022-01-12T14:07:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T07:57:21.000Z", "max_issues_repo_path": "src/urqmd-3.4/sources/quadri.f90", "max_issues_repo_name": "kotania/impy", "max_issues_repo_head_hexsha": "85ddd5764a3c1f955fae8d1b9422b619d4d12a4d", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2021-06-24T08:19:56.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-24T12:26:57.000Z", "max_forks_repo_path": "src/urqmd-3.4/sources/quadri.f90", "max_forks_repo_name": "kotania/impy", "max_forks_repo_head_hexsha": "85ddd5764a3c1f955fae8d1b9422b619d4d12a4d", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-12T14:06:33.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-12T14:06:33.000Z", "avg_line_length": 24.7333333333, "max_line_length": 66, "alphanum_fraction": 0.4137466307, "num_tokens": 288, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.903294214513915, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6658707034841974}} {"text": " module MOD_REGULA\r\n contains\r\nC********** MODULNAME: REGULA ******* 24/03/87 22.00.45.****** 46 KARTEN\r\n SUBROUTINE REGULA(F,X,Y,X1,X2,EPS)\r\nC***********************************************************************\r\nC*** THIS ROUTINE CALCULATES THE SOLUTION X OF F(X)=Y IN THE INTERVAL\r\nC*** (X1,X2) | METHOD:\r\nC*** -------- REGULA FALSI --------\r\nC*** USING BISECTION STEPS TO GUARANTEE CONVERGENCE, PRECISION IN X: EPS\r\nC***********************************************************************\r\n\r\n IMPLICIT REAL*8(A-H,O-Z)\r\n \r\n DATA ANULL/0.d0/\r\n LOGICAL BI\r\n \r\n BI=.TRUE.\r\n A=X1\r\n B=X2\r\n FA=F(A)-Y\r\n IF(FA.EQ..0) GOTO 3\r\n FB=F(B)-Y\r\n IF(FB.EQ..0) GOTO 4\r\n IF (FA*FB.GT..0) THEN\r\n PRINT 10,A,B,FA,FB\r\n 10 FORMAT(//,10X,20(1H*),' ERROR IN REGULA ',20(1H*),/,\r\n $ 10X,'INTERVAL: A =',E15.5,10X,' B =',E15.5,/,\r\n $ 10X,'FUNCTION: F(A) =',E15.5,10X,'F(B) =',E15.5,/,\r\n $ 10X,20(1H*),' ERROR IN REGULA ',20(1H*),/)\r\n fnull = F(ANULL)\r\n fa=f(a)\r\n fb=f(b)\r\n print *,' Y = ',Y\r\n print *,' F(0) = ',fnull\r\n print *,' F(A) = ',fa\r\n print *,' F(B) = ',fb\r\n\r\nc** creat run time error to find out which was the calling routine\r\n print *,' run time error deliberate!'\r\n error=FB/ANULL\r\n error=error**2.\r\n print *,error\r\n STOP 'ERROR'\r\n ENDIF\r\n 1 D=A-B\r\n IF(ABS(D).LT.EPS) GOTO 5\r\n BI=.NOT.BI\r\n IF(BI) X=A-FA*D/(FA-FB)\r\n IF(.NOT.BI) X=.5*(A+B)\r\n FX=F(X)-Y\r\n IF(FX.EQ..0) RETURN\r\n IF(FX*FA.GT..0) GOTO 2\r\n B=X\r\n FB=FX\r\n GOTO 1\r\n 2 A=X\r\n FA=FX\r\n GOTO 1\r\n 3 X=A\r\n RETURN\r\n 4 X=B\r\n RETURN\r\n 5 X=(A+B)*.5\r\n RETURN\r\n END subroutine\r\n end module", "meta": {"hexsha": "f197110a85efe3b73f0031de32636f545762b8de", "size": 1911, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/regula.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/regula.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/regula.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": 28.9545454545, "max_line_length": 81, "alphanum_fraction": 0.4055468341, "num_tokens": 647, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971871, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.665870699104773}} {"text": "\tprogram realftest\nc\nc\nc\n\tcommon /winblk/ window(1024)\n\tdimension data(2050),pwr(513)\n\tcomplex cgain,cdata(2050)\n\n\tdata twopi /6.2831853/\nc\n\tcycles = 10.\t\t\t! number of cycles in full sample\n\tperiod = 1024./cycles\t\t\t! period in samples\n\tamp = 1000.\nc\nc\tconstruct a sine wave\nc\n\tdo i = 1,1024\n\t\tdata(i) = amp*sin(twopi*(i-1)*cycles/1024. + .125*TWOPI)\nc\t\tdata(i) = amp*sin(twopi*(i-1)*cycles/1024.)\n\t write(22,*) i,data(i)\n\tenddo\nc\nC\tcall fwindw(1)\nC\tdo i = 1,1024\nC\t\tdata(i) = window(i)*data(i)\nC\tenddo\n\tcall realft(data,512,1)\n\tdo i = 1,512\n\t\tdata(i) = data(i)/512.\n\t\tdata(i+512) = data(i+512)/512.\n\t\tpwr(i) = sqrt(data(2*i-1)**2 + data(2*i)**2)/512.\n\t write(23,*) i,pwr(i)\n\tenddo\n\tprint*,'data, fourier coefficients'\n\tprint*,(data(j),j=1,25)\n\txph = cosd(45.)\n\tcgain = cmplx(xph,xph) ! gain with +45 deg. phase shift\n\tdo j = 1,513\n\t cdata(j) = cmplx(data(2*j-1),data(2*j))\n\t cdata(j) = cdata(j)/cgain\t\n enddo\n\tprint*,'cdata'\n\tprint*,(cdata(j),j=1,13)\nc\nc\ttest inverse transform\nc\n\tcall realft(data,512,-1)\n\t write(24,*) (i,data(i),i=1,1024)\nc\nC\tDO J = 1,1025\nC\t WRITE(67,*) J,DATA(J),WINDOW(J)\nC\tENDDO\n\tstop\n\tend\n", "meta": {"hexsha": "41ef7bedcc61b7ac1ea52af0ce605ab23d223d9e", "size": 1140, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/realftest_25.for", "max_stars_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_stars_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/realftest_25.for", "max_issues_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_issues_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/realftest_25.for", "max_forks_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_forks_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.7272727273, "max_line_length": 67, "alphanum_fraction": 0.6184210526, "num_tokens": 479, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971871, "lm_q2_score": 0.7371581510799252, "lm_q1q2_score": 0.6658706834568838}} {"text": "!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n!\n! A function that calculates the values of shape functions\n! at specified points for Quadrilateral Elements\n!\n!\n!_______________________________________________________________________\n!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\nReal*8 Function SFQuadrilateral (PsiCor,d,Poly_Order,node,NDim,iS)\n !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n !-----------------------------------------------------------------------\n Implicit real*8 (a-h,o-z)\n Integer Poly_Order,d(NDim),dX(1),dY(1),dZ(1),Deriv\n Dimension Sfn(ndim+1),PsiCor(ndim),PsiCorX(1),PsiCorY(1),PsiCorZ(1)\n ! NDim = dimension of the quadrilateral\n ! NDim= 1 Not considered, resort to Simplex Elements\n ! NDim= 2 Square\n ! NDim= 3 Cube\n ! Poly_Order: complete Polynomial degree of the shape function\n ! iS=0: family of Lagrangian elements (valid for Poly_Order>1)\n ! NDim=2 -> 9-node element\n ! NDim=3 -> 27-node element\n ! iS=1: family of Serendipity elements (valid for Poly_Order>1)\n ! NDim=2 -> 8-node element\n ! NDim=3 -> 20-node element\n ! node: number (ordinal) of the shape function)\n ! PsiCor(ndim)= Simplex intrinsec coordinates\n ! Deriv: order of Partial DERIVATIVE (Function=:0)\n ! d(1): order of derivation with respect to Psi1\n ! d(2): order of derivation with respect to Psi2\n ! d(3): order of derivation with respect to Psi3\n ! Sfn(i): Linear Shape Function corresponding to Node i\n\n SFQuadrilateral = 0.0D0\n Xi = 0.0D0\n Yi = 0.0D0\n Zi = 0.0D0\n Deriv = sum(d)\n Select Case (NDim)\n !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n Case (3)\n ! Cube Element\n X = PsiCor(1)\n Y = PsiCor(2)\n Z = PsiCor(3)\n XX = X*X\n YY = Y*Y\n ZZ = Z*Z\n\n ! Xi: Coordenada X del nodo correspondiente a la funcion de forma Ni\n ! Yi: Coordenada Y del nodo correspondiente a la funcion de forma Ni\n ! Zi: Coordenada Z del nodo correspondiente a la funcion de forma Ni\n\n !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n Select Case (Poly_Order)\n ! Linear:1, Quadratic:2, Cubic:3, Etc.\n Case (1)\n ! Poly_Order Linear\n Select Case (node)\n Case(1)\n Xi = -1.0d0\n Yi = -1.0d0\n Zi = -1.0d0\n Case(2)\n Xi = 1.0d0\n Yi = -1.0d0\n Zi = -1.0d0\n Case(3)\n Xi = 1.0d0\n Yi = 1.0d0\n Zi = -1.0d0\n Case(4)\n Xi = -1.0d0\n Yi = 1.0d0\n Zi = -1.0d0\n Case(5)\n Xi = -1.0d0\n Yi = -1.0d0\n Zi = 1.0d0\n Case(6)\n Xi = 1.0d0\n Yi = -1.0d0\n Zi = 1.0d0\n Case(7)\n Xi = 1.0d0\n Yi = 1.0d0\n Zi = 1.0d0\n Case(8)\n Xi = -1.0d0\n Yi = 1.0d0\n Zi = 1.0d0\n End Select\n Select Case (Deriv)\n Case (0)\n ! Function Values\n SFQuadrilateral = 0.125d0*(1.0d0+Xi*X)*(1.0d0+Yi*Y)*(1.0d0+Zi*Z)\n Case (1)\n ! First Order Derivative\n If(d(1).eq.1)Then ! d/dx\n SFQuadrilateral = 0.125d0*Xi*(1.0d0+Yi*Y)*(1.0d0+Zi*Z)\n ElseIf(d(2).eq.1)Then ! d/dy\n SFQuadrilateral = 0.125d0*(1.0d0+Xi*X)*Yi*(1.0d0+Zi*Z)\n ElseIf(d(3).eq.1)Then ! d/dz\n SFQuadrilateral = 0.125d0*(1.0d0+Xi*X)*(1.0d0+Yi*Y)*Zi\n EndIf\n Case (2)\n ! Second Order Derivative\n If(d(1).eq.2)Then ! d2/dx2\n SFQuadrilateral = 0.0d0\n ElseIf(d(2).eq.2)Then ! d2/dy2\n SFQuadrilateral = 0.0d0\n ElseIf(d(3).eq.2)Then ! d2/dz2\n SFQuadrilateral = 0.0d0\n ElseIf(d(1)+d(2).eq.2.and.d(1).ne.2.and.d(2).ne.2)Then ! d2/dxdy\n SFQuadrilateral = 0.125d0*Xi*Yi*(1.0d0+Zi*Z)\n ElseIf(d(1)+d(3).eq.2.and.d(1).ne.2.and.d(3).ne.2)Then ! d2/dxdz\n SFQuadrilateral = 0.125d0*Xi*(1.0d0+Yi*Y)*Zi\n ElseIf(d(2)+d(3).eq.2.and.d(2).ne.2.and.d(3).ne.2)Then ! d2/dydz\n SFQuadrilateral = 0.125d0*(1.0d0+Xi*X)*Yi*Zi\n EndIf\n End Select\n\n Case (2)\n ! Poly_Order Cuadratic\n If(iS.eq.0)Then\n !----------------------------------------------------------------------\n ! Lagrangian Element (27-node element)\n !----------------------------------------------------------------------\n\n ! Construido por multiplicacion de las funciones de forma del 1D\n ! fX: funcion de variable X\n ! gY: funcion de variable Y\n ! hZ: funcion de variable Z\n\n NDim1D = 1\n iOrder = 2\n PsiCorX(1) = X\n PsiCorY(1) = Y\n PsiCorZ(1) = Z\n Select Case (node)\n Case(1)\n nodeX = 1\n nodeY = 1\n nodeZ = 1\n Case(2)\n nodeX = 2\n nodeY = 1\n nodeZ = 1\n Case(3)\n nodeX = 2\n nodeY = 2\n nodeZ = 1\n Case(4)\n nodeX = 1\n nodeY = 2\n nodeZ = 1\n Case(5)\n nodeX = 1\n nodeY = 1\n nodeZ = 2\n Case(6)\n nodeX = 2\n nodeY = 1\n nodeZ = 2\n Case(7)\n nodeX = 2\n nodeY = 2\n nodeZ = 2\n Case(8)\n nodeX = 1\n nodeY = 2\n nodeZ = 2\n Case(9)\n nodeX = 3\n nodeY = 1\n nodeZ = 1\n Case(10)\n nodeX = 2\n nodeY = 3\n nodeZ = 1\n Case(11)\n nodeX = 3\n nodeY = 2\n nodeZ = 1\n Case(12)\n nodeX = 1\n nodeY = 3\n nodeZ = 1\n Case(13)\n nodeX = 1\n nodeY = 1\n nodeZ = 3\n Case(14)\n nodeX = 2\n nodeY = 1\n nodeZ = 3\n Case(15)\n nodeX = 2\n nodeY = 2\n nodeZ = 3\n Case(16)\n nodeX = 1\n nodeY = 2\n nodeZ = 3\n Case(17)\n nodeX = 3\n nodeY = 1\n nodeZ = 2\n Case(18)\n nodeX = 2\n nodeY = 3\n nodeZ = 2\n Case(19)\n nodeX = 3\n nodeY = 2\n nodeZ = 2\n Case(20)\n nodeX = 1\n nodeY = 3\n nodeZ = 2\n Case(21)\n nodeX = 3\n nodeY = 3\n nodeZ = 1\n Case(22)\n nodeX = 3\n nodeY = 1\n nodeZ = 3\n Case(23)\n nodeX = 2\n nodeY = 3\n nodeZ = 3\n Case(24)\n nodeX = 3\n nodeY = 2\n nodeZ = 3\n Case(25)\n nodeX = 1\n nodeY = 3\n nodeZ = 3\n Case(26)\n nodeX = 3\n nodeY = 3\n nodeZ = 2\n Case(27)\n nodeX = 3\n nodeY = 3\n nodeZ = 3\n End Select\n Select Case (Deriv)\n Case(0)\n ! Function Values\n dX(1) = 0\n dY(1) = 0\n dZ(1) = 0\n Case(1)\n ! First Order Derivative\n If(d(1).eq.1)Then ! d/dx\n dX(1) = 1\n dY(1) = 0\n dZ(1) = 0\n ElseIf(d(2).eq.1)Then ! d/dy\n dX(1) = 0\n dY(1) = 1\n dZ(1) = 0\n Else ! d/dz\n dX(1) = 0\n dY(1) = 0\n dZ(1) = 1\n EndIf\n Case(2)\n ! Second Order Derivative\n If(d(1).eq.2)Then ! d2/dx2\n dX(1) = 2\n dY(1) = 0\n dZ(1) = 0\n ElseIf(d(2).eq.2)Then ! d2/dy2\n dX(1) = 0\n dY(1) = 2\n dZ(1) = 0\n ElseIf(d(3).eq.2)Then ! d2/dz2\n dX(1) = 0\n dY(1) = 0\n dZ(1) = 2\n ElseIf(d(1)+d(2).eq.2)Then ! d2/dxdy\n dX(1) = 1\n dY(1) = 1\n dZ(1) = 0\n ElseIf(d(1)+d(3).eq.2)Then ! d2/dxdz\n dX(1) = 1\n dY(1) = 0\n dZ(1) = 1\n Else ! d2/dydz\n dX(1) = 0\n dY(1) = 1\n dZ(1) = 1\n EndIf\n End Select\n fX = SF1D(PsiCorX,dX,iOrder,nodeX,NDim1D,0)\n gY = SF1D(PsiCorY,dY,iOrder,nodeY,NDim1D,0)\n hZ = SF1D(PsiCorZ,dZ,iOrder,nodeZ,NDim1D,0)\n SFQuadrilateral = fX * gY * hZ\n !----------------------------------------------------------------------\n ElseIf(iS.eq.1)Then\n !----------------------------------------------------------------------\n ! Serendipity Element (20-node element)\n !----------------------------------------------------------------------\n Select Case (node)\n Case(1)\n Xi = -1.0d0\n Yi = -1.0d0\n Zi = -1.0d0\n Case(2)\n Xi = 1.0d0\n Yi = -1.0d0\n Zi = -1.0d0\n Case(3)\n Xi = 1.0d0\n Yi = 1.0d0\n Zi = -1.0d0\n Case(4)\n Xi = -1.0d0\n Yi = 1.0d0\n Zi = -1.0d0\n Case(5)\n Xi = -1.0d0\n Yi = -1.0d0\n Zi = 1.0d0\n Case(6)\n Xi = 1.0d0\n Yi = -1.0d0\n Zi = 1.0d0\n Case(7)\n Xi = 1.0d0\n Yi = 1.0d0\n Zi = 1.0d0\n Case(8)\n Xi = -1.0d0\n Yi = 1.0d0\n Zi = 1.0d0\n Case(9)\n Xi = 0.0d0\n Yi = -1.0d0\n Zi = -1.0d0\n Case(10)\n Xi = 1.0d0\n Yi = 0.0d0\n Zi = -1.0d0\n Case(11)\n Xi = 0.0d0\n Yi = 1.0d0\n Zi = -1.0d0\n Case(12)\n Xi = -1.0d0\n Yi = 0.0d0\n Zi = -1.0d0\n Case(13)\n Xi = -1.0d0\n Yi = -1.0d0\n Zi = 0.0d0\n Case(14)\n Xi = 1.0d0\n Yi = -1.0d0\n Zi = 0.0d0\n Case(15)\n Xi = 1.0d0\n Yi = 1.0d0\n Zi = 0.0d0\n Case(16)\n Xi = -1.0d0\n Yi = 1.0d0\n Zi = 0.0d0\n Case(17)\n Xi = 0.0d0\n Yi = -1.0d0\n Zi = 1.0d0\n Case(18)\n Xi = 1.0d0\n Yi = 0.0d0\n Zi = 1.0d0\n Case(19)\n Xi = 0.0d0\n Yi = 1.0d0\n Zi = 1.0d0\n Case(20)\n Xi = -1.0d0\n Yi = 0.0d0\n Zi = 1.0d0\n End Select\n Select Case (Deriv)\n Case (0)\n ! Function Values\n Select Case (node)\n Case (1:8)\n SFQuadrilateral = 0.125d0*(1.0d0+Xi*X)*(1.0d0+Yi*Y)*(1.0d0+Zi*Z)*(Xi*X+Yi*Y+Zi*Z-2)\n Case (9,11,17,19)\n SFQuadrilateral = 0.25d0*(1.0d0-XX)*(1.0d0+Yi*Y)*(1.0d0+Zi*Z)\n Case (10,12,18,20)\n SFQuadrilateral = 0.25d0*(1.0d0+Xi*X)*(1.0d0-YY)*(1.0d0+Zi*Z)\n Case (13:16)\n SFQuadrilateral = 0.25d0*(1.0d0+Xi*X)*(1.0d0+Yi*Y)*(1.0d0-ZZ)\n End Select\n Case (1)\n ! First Order Derivative\n Select Case (node)\n Case (1:8)\n If(d(1).eq.1)Then ! d/dx\n SFQuadrilateral = 0.125d0*Xi*(1.0d0+Yi*Y)*(1.0d0+Zi*Z)*(2.0d0*Xi*X+Yi*Y+Zi*Z-1.0D0)\n ElseIf(d(2).eq.1)Then ! d/dy\n SFQuadrilateral = 0.125d0*(1.0d0+Xi*X)*Yi*(1.0d0+Zi*Z)*(Xi*X+2.0d0*Yi*Y+Zi*Z-1.0D0)\n Else ! d/dz\n SFQuadrilateral = 0.125d0*(1.0d0+Xi*X)*(1.0d0+Yi*Y)*Zi*(Xi*X+Yi*Y+2.0d0*Zi*Z-1.0D0)\n EndIf\n Case (9,11,17,19)\n If(d(1).eq.1)Then ! d/dx\n SFQuadrilateral = -0.50d0*X*(1.0d0+Yi*Y)*(1.0d0+Zi*Z)\n ElseIf(d(2).eq.1)Then ! d/dy\n SFQuadrilateral = 0.25d0*(1.0d0-XX)*Yi*(1.0d0+Zi*Z)\n Else ! d/dz\n SFQuadrilateral = 0.25d0*(1.0d0-XX)*(1.0d0+Yi*Y)*Zi\n EndIf\n Case (10,12,18,20)\n If(d(1).eq.1)Then ! d/dx\n SFQuadrilateral = 0.25d0*Xi*(1.0d0-YY)*(1.0d0+Zi*Z)\n ElseIf(d(2).eq.1)Then ! d/dy\n SFQuadrilateral = -0.50d0*(1.0d0+Xi*X)*Y*(1.0d0+Zi*Z)\n Else ! d/dz\n SFQuadrilateral = 0.25d0*(1.0d0+Xi*X)*(1.0d0-YY)*Zi\n EndIf\n Case (13:16)\n If(d(1).eq.1)Then ! d/dx\n SFQuadrilateral = 0.25d0*Xi*(1.0d0+Yi*Y)*(1.0d0-ZZ)\n ElseIf(d(2).eq.1)Then ! d/dy\n SFQuadrilateral = 0.25d0*(1.0d0+Xi*X)*Yi*(1.0d0-ZZ)\n Else ! d/dz\n SFQuadrilateral = -0.50d0*(1.0d0+Xi*X)*(1.0d0+Yi*Y)*Z\n EndIf\n End Select\n Case (2)\n ! Second Order Derivative\n Select Case (node)\n Case (1:8)\n If(d(1).eq.2)Then ! d2/dx2\n SFQuadrilateral = 0.25d0*(1.0d0+Yi*Y)*(1.0d0+Zi*Z)\n ElseIf(d(2).eq.2)Then ! d2/dy2\n SFQuadrilateral = 0.25d0*(1.0d0+Xi*X)*(1.0d0+Zi*Z)\n ElseIf(d(3).eq.2)Then ! d2/dz2\n SFQuadrilateral = 0.25d0*(1.0d0+Xi*X)*(1.0d0+Yi*Y)\n ElseIf(d(1)+d(2).eq.2)Then ! d2/dxdy\n SFQuadrilateral = 0.125d0*Xi*Yi*(1.0d0+Zi*Z)*(2.0d0*Xi*X+2.0d0*Yi*Y+Zi*Z)\n ElseIf(d(1)+d(3).eq.2)Then ! d2/dxdz\n SFQuadrilateral = 0.125d0*Xi*Zi*(1.0d0+Yi*Y)*(2.0d0*Xi*X+Yi*Y+2.0d0*Zi*Z)\n Else ! d2/dydz\n SFQuadrilateral = 0.125d0*Yi*Zi*(1.0d0+Xi*X)*(Xi*X+2.0d0*Yi*Y+2.0d0*Zi*Z)\n EndIf\n Case (9,11,17,19)\n If(d(1).eq.2)Then ! d2/dx2\n SFQuadrilateral = -0.50d0*(1.0d0+Yi*Y)*(1.0d0+Zi*Z)\n ElseIf(d(2).eq.2)Then ! d2/dy2\n SFQuadrilateral = 0.0d0\n ElseIf(d(3).eq.2)Then ! d2/dz2\n SFQuadrilateral = 0.0d0\n ElseIf(d(1)+d(2).eq.2)Then ! d2/dxdy\n SFQuadrilateral = -0.50d0*X*Yi*(1.0d0+Zi*Z)\n ElseIf(d(1)+d(3).eq.2)Then ! d2/dxdz\n SFQuadrilateral = -0.50d0*X*(1.0d0+Yi*Y)*Zi\n Else ! d2/dydz\n SFQuadrilateral = 0.25d0*(1.0d0-XX)*Yi*Zi\n EndIf\n Case (10,12,18,20)\n If(d(1).eq.2)Then ! d2/dx2\n SFQuadrilateral = 0.0d0\n ElseIf(d(2).eq.2)Then ! d2/dy2\n SFQuadrilateral = -0.50d0*(1.0d0+Xi*X)*(1.0d0+Zi*Z)\n ElseIf(d(3).eq.2)Then ! d2/dz2\n SFQuadrilateral = 0.0d0\n ElseIf(d(1)+d(2).eq.2)Then ! d2/dxdy\n SFQuadrilateral = -0.50d0*Xi*Y*(1.0d0+Zi*Z)\n ElseIf(d(1)+d(3).eq.2)Then ! d2/dxdz\n SFQuadrilateral = 0.25d0*Xi*(1.0d0-YY)*Zi\n Else ! d2/dydz\n SFQuadrilateral = -0.50d0*(1.0d0+Xi*X)*Y*Zi\n EndIf\n Case (13:16)\n If(d(1).eq.2)Then ! d2/dx2\n SFQuadrilateral = 0.0d0\n ElseIf(d(2).eq.2)Then ! d2/dy2\n SFQuadrilateral = 0.0d0\n ElseIf(d(3).eq.2)Then ! d2/dz2\n SFQuadrilateral = -0.50d0*(1.0d0+Xi*X)*(1.0d0+Yi*Y)\n ElseIf(d(1)+d(2).eq.2)Then ! d2/dxdy\n SFQuadrilateral = 0.25d0*Xi*Yi*(1.0d0-ZZ)\n ElseIf(d(1)+d(3).eq.2)Then ! d2/dxdz\n SFQuadrilateral = -0.50d0*Xi*(1.0d0+Yi*Y)*Z\n Else ! d2/dydz\n SFQuadrilateral = -0.50d0*(1.0d0+Xi*X)*Yi*Z\n EndIf\n End Select\n End Select\n EndIf\n\n End Select\n\n !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n Case (2)\n ! Square Element\n X = PsiCor(1)\n Y = PsiCor(2)\n XX = X*X\n YY = Y*Y\n\n ! Xi: Coordenada X del nodo correspondiente a la funcion de forma Ni\n ! Yi: Coordenada Y del nodo correspondiente a la funcion de forma Ni\n\n !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n Select Case (Poly_Order)\n ! Linear:1, Quadratic:2, Cubic:3, Etc.\n Case (1)\n ! Poly_Order Linear\n Select Case (node)\n Case(1)\n Xi = -1.0d0\n Yi = -1.0d0\n Case(2)\n Xi = 1.0d0\n Yi = -1.0d0\n Case(3)\n Xi = 1.0d0\n Yi = 1.0d0\n Case(4)\n Xi = -1.0d0\n Yi = 1.0d0\n End Select\n Select Case (Deriv)\n Case (0)\n ! Function Values\n SFQuadrilateral = 0.25d0*(1.0d0+Xi*X)*(1.0d0+Yi*Y)\n Case (1)\n ! First Order Derivative\n If(d(1).eq.1)Then ! d/dx\n SFQuadrilateral = 0.25d0*Xi*(1.0d0+Yi*Y)\n Else ! d/dy\n SFQuadrilateral = 0.25d0*(1.0d0+Xi*X)*Yi\n EndIf\n Case (2)\n ! Second Order Derivative\n If(d(1).eq.2)Then ! d2/dx2\n SFQuadrilateral = 0.0d0\n ElseIf(d(2).eq.2)Then ! d2/dy2\n SFQuadrilateral = 0.0d0\n Else ! d2/dxdy\n SFQuadrilateral = 0.25d0*Xi*Yi\n EndIf\n End Select\n\n Case (2)\n ! Poly_Order Cuadratic\n If(iS.eq.0)Then\n !----------------------------------------------------------------------\n ! Lagrangian Element\n !----------------------------------------------------------------------\n\n ! Construido por multiplicacion de las funciones de forma del 1D\n ! fX: funcion de variable X\n ! gY: funcion de variable Y\n\n NDim1D = 1\n iOrder = 2\n PsiCorX(1) = X\n PsiCorY(1) = Y\n Select Case (node)\n Case(1)\n nodeX = 1\n nodeY = 1\n Case(2)\n nodeX = 2\n nodeY = 1\n Case(3)\n nodeX = 2\n nodeY = 2\n Case(4)\n nodeX = 1\n nodeY = 2\n Case(5)\n nodeX = 3\n nodeY = 1\n Case(6)\n nodeX = 2\n nodeY = 3\n Case(7)\n nodeX = 3\n nodeY = 2\n Case(8)\n nodeX = 1\n nodeY = 3\n Case(9)\n nodeX = 3\n nodeY = 3\n End Select\n Select Case (Deriv)\n Case(0)\n ! Function Values\n dX(1) = 0\n dY(1) = 0\n Case(1)\n ! First Order Derivative\n If(d(1).eq.1)Then ! d/dx\n dX(1) = 1\n dY(1) = 0\n Else ! d/dy\n dX(1) = 0\n dY(1) = 1\n EndIf\n Case(2)\n ! Second Order Derivative\n If(d(1).eq.2)Then ! d2/dx2\n dX(1) = 2\n dY(1) = 0\n ElseIf(d(2).eq.2)Then ! d2/dy2\n dX(1) = 0\n dY(1) = 2\n Else ! d2/dxdy\n dX(1) = 1\n dY(1) = 1\n EndIf\n End Select\n fX = SF1D(PsiCorX,dX,iOrder,nodeX,NDim1D,0)\n gY = SF1D(PsiCorY,dY,iOrder,nodeY,NDim1D,0)\n SFQuadrilateral = fX * gY\n !----------------------------------------------------------------------\n ElseIf(iS.eq.1.or.iS.eq.2)Then\n !----------------------------------------------------------------------\n ! Serendipity or less than Serendipity Element (coincide for NDim=2)\n !----------------------------------------------------------------------\n Select Case (node)\n Case(1)\n Xi = -1.0d0\n Yi = -1.0d0\n Case(2)\n Xi = 1.0d0\n Yi = -1.0d0\n Case(3)\n Xi = 1.0d0\n Yi = 1.0d0\n Case(4)\n Xi = -1.0d0\n Yi = 1.0d0\n Case(5)\n Xi = 0.0d0\n Yi = -1.0d0\n Case(6)\n Xi = 1.0d0\n Yi = 0.0d0\n Case(7)\n Xi = 0.0d0\n Yi = 1.0d0\n Case(8)\n Xi = -1.0d0\n Yi = 0.0d0\n End Select\n Select Case (Deriv)\n Case (0)\n ! Function Values\n Select Case (node)\n Case (1:4)\n SFQuadrilateral = 0.25d0*(1.0d0+Xi*X)*(1.0d0+Yi*Y)*(Xi*X+Yi*Y-1)\n Case (5,7)\n SFQuadrilateral = 0.50d0*(1.0d0-XX)*(1.0d0+Yi*Y)\n Case (6,8)\n SFQuadrilateral = 0.50d0*(1.0d0+Xi*X)*(1.0d0-YY)\n End Select\n Case (1)\n ! First Order Derivative\n Select Case (node)\n Case (1:4)\n If(d(1).eq.1)Then ! d/dx\n SFQuadrilateral = 0.25d0*Xi*(1.0d0+Yi*Y)*(2.0d0*Xi*X+Yi*Y)\n Else ! d/dy\n SFQuadrilateral = 0.25d0*Yi*(1.0d0+Xi*X)*(2.0d0*Yi*Y+Xi*X)\n EndIf\n Case (5,7)\n If(d(1).eq.1)Then ! d/dx\n SFQuadrilateral = -X*(1.0d0+Yi*Y)\n Else ! d/dy\n SFQuadrilateral = 0.50d0*(1-XX)*Yi\n EndIf\n Case (6,8)\n If(d(1).eq.1)Then ! d/dx\n SFQuadrilateral = 0.50d0*Xi*(1-YY)\n Else ! d/dy\n SFQuadrilateral = -(1.0d0+Xi*X)*Y\n EndIf\n End Select\n Case (2)\n ! Second Order Derivative\n Select Case (node)\n Case (1,4)\n If(d(1).eq.2)Then ! d2/dx2\n SFQuadrilateral = 0.50d0*(1.0D0+Yi*Y)\n ElseIf(d(2).eq.2)Then ! d2/dy2\n SFQuadrilateral = 0.50d0*(1.0D0+Xi*X)\n Else ! d2/dxdy\n SFQuadrilateral = 0.25d0*(1.0d0+2.0d0*Xi*X+2.0d0*Yi*Y)\n EndIf\n Case (5,7)\n If(d(1).eq.2)Then ! d2/dx2\n SFQuadrilateral = -(1.0d0+Yi*Y)\n ElseIf(d(2).eq.2)Then ! d2/dy2\n SFQuadrilateral = 0.0d0\n Else ! d2/dxdy\n SFQuadrilateral = -X*Yi\n EndIf\n Case (6,8)\n If(d(1).eq.2)Then ! d2/dx2\n SFQuadrilateral = 0.0d0\n ElseIf(d(2).eq.2)Then ! d2/dy2\n SFQuadrilateral = -(1.0d0+Xi*X)\n Else ! d2/dxdy\n SFQuadrilateral = -Xi*Y\n EndIf\n End Select\n End Select\n !----------------------------------------------------------------------\n EndIf\n\n End Select\n\n !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n Case (1)\n ! Line Element\n X = PsiCor(1)\n XX = X*X\n\n ! Xi: Coordenada X del nodo correspondiente a la funcion de forma Ni\n\n !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n Select Case (Poly_Order)\n ! Linear:1, Quadratic:2, Cubic:3, Etc.\n Case (1)\n ! Poly_Order Linear\n Select Case (Deriv)\n Case (0)\n ! Function Values\n Select Case (node)\n Case(1)\n SFQuadrilateral = 0.50d0*(1.0d0-X)\n Case(2)\n SFQuadrilateral = 0.50d0*(1.0d0+X)\n End Select\n Case (1)\n ! First Order Derivative\n Select Case (node)\n Case(1)\n SFQuadrilateral = -0.50d0\n Case(2)\n SFQuadrilateral = 0.50d0\n End Select\n Case (2)\n ! Second Order Derivative\n Select Case (node)\n Case(1)\n SFQuadrilateral = 0.0d0\n Case(2)\n SFQuadrilateral = 0.0d0\n End Select\n End Select\n\n Case (2)\n ! Poly_Order Cuadratic\n Select Case (Deriv)\n Case (0)\n ! Function Values\n Select Case (node)\n Case(1)\n SFQuadrilateral = -0.50d0*X*(1.0d0-X)\n Case(2)\n SFQuadrilateral = 0.50d0*X*(1.0d0+X)\n Case(3)\n SFQuadrilateral = 1.0d0-XX\n End Select\n Case (1)\n ! First Order Derivative\n Select Case (node)\n Case(1)\n SFQuadrilateral = -0.50d0*(1.0d0-2.0d0*X)\n Case(2)\n SFQuadrilateral = 0.50d0*(1.0d0+2.0d0*X)\n Case(3)\n SFQuadrilateral = -2.0d0*X\n End Select\n Case (2)\n ! Second Order Derivative\n Select Case (node)\n Case(1)\n SFQuadrilateral = 1.0d0\n Case(2)\n SFQuadrilateral = 1.0d0\n Case(3)\n SFQuadrilateral = -2.0d0\n End Select\n End Select\n\n End Select\n End Select\n\n Return\nEnd Function SFQuadrilateral\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n!\n! A function that calculates the values of shape functions\n! at specified points for line Elements in (-1,1) for building\n! quadrilateral Lagrangian elements\n!\n!_______________________________________________________________________\n!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\nReal*8 Function SF1D (PsiCor,d,Poly_Order,node,NDim,iS)\n !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n !-----------------------------------------------------------------------\n Implicit real*8 (a-h,o-z)\n Integer Poly_Order,d(NDim),dX(1),dY(1),dZ(1),Deriv\n Dimension Sfn(ndim+1),PsiCor(ndim),PsiCorX(1),PsiCorY(1),PsiCorZ(1)\n ! NDim= 1\n ! Poly_Order: complete Polynomial degree of the shape function\n ! iS=0: family of Lagrangian elements (valid for Poly_Order>1)\n ! node: number (ordinal) of the shape function)\n ! PsiCor(ndim)= Simplex intrinsec coordinates\n ! Deriv: order of Partial DERIVATIVE (Function=:0)\n\n Deriv = sum(d)\n !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n ! Line Element\n\n X = PsiCor(1)\n XX = X*X\n SF1D = 0.0D0\n\n ! Xi: Coordenada X del nodo correspondiente a la funcion de forma Ni\n\n !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n Select Case (Poly_Order)\n ! Linear:1, Quadratic:2, Cubic:3, Etc.\n Case (1)\n ! Poly_Order Linear\n Select Case (Deriv)\n Case (0)\n ! Function Values\n Select Case (node)\n Case(1)\n SF1D = 0.50d0*(1.0d0-X)\n Case(2)\n SF1D = 0.50d0*(1.0d0+X)\n End Select\n Case (1)\n ! First Order Derivative\n Select Case (node)\n Case(1)\n SF1D = -0.50d0\n Case(2)\n SF1D = 0.50d0\n End Select\n Case (2)\n ! Second Order Derivative\n Select Case (node)\n Case(1)\n SF1D = 0.0d0\n Case(2)\n SF1D = 0.0d0\n End Select\n End Select\n\n Case (2)\n ! Poly_Order Cuadratic\n Select Case (Deriv)\n Case (0)\n ! Function Values\n Select Case (node)\n Case(1)\n SF1D = -0.50d0*X*(1.0d0-X)\n Case(2)\n SF1D = 0.50d0*X*(1.0d0+X)\n Case(3)\n SF1D = 1.0d0-XX\n End Select\n Case (1)\n ! First Order Derivative\n Select Case (node)\n Case(1)\n SF1D = -0.50d0*(1.0d0-2.0d0*X)\n Case(2)\n SF1D = 0.50d0*(1.0d0+2.0d0*X)\n Case(3)\n SF1D = -2.0d0*X\n End Select\n Case (2)\n ! Second Order Derivative\n Select Case (node)\n Case(1)\n SF1D = 1.0d0\n Case(2)\n SF1D = 1.0d0\n Case(3)\n SF1D = -2.0d0\n End Select\n End Select\n\n End Select\n\n Return\nEnd Function SF1D\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\n! keywords\n! Derivadas de funciones de forma lineares para Brics / Quads / Cubos\n! Shape derivative functions linear \n! Joaquin Aranciaga\n! Santiago \n! Souza Neto\n! Fbar\n! 2015\n! Residual Stress\n! ndim=2 y ndim=3\n\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \nSubRoutine localShapeFunctionHyperCube (Ndim, lsf, Gauss)\n\n !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n Implicit Real*8 (a-h, o-z)\n\n Real*8 lsf\n\n ! http://www.colorado.edu/engineering/CAS/courses.d/AFEM.d/AFEM.Ch11.d/AFEM.Ch11.pdf\n\n Dimension lsf(8), Gauss(Ndim)\n\n if (Ndim == 3) then\n psi_1 = Gauss(1)\n psi_2 = Gauss(2)\n psi_3 = Gauss(3)\n\n ! Funciones de forma del paralelepopedo lineales en los puntos\n ! de Gauss.\n \n !lsf(1) = (1.0d0 - psi_2) * (1.0d0 - psi_3) * psi_1 !lsf(1) = (1.0d0 - psi_1) * (1.0d0 - psi_2) * (1.0d0 - psi_3)\n !lsf(2) = (1.0d0 - psi_3) * psi_1 * psi_2 !lsf(2) = (1.0d0 - psi_2) * (1.0d0 - psi_3) * psi_1\n !lsf(3) = (1.0d0 - psi_1) * (1.0d0 - psi_3) * psi_2 !lsf(3) = (1 - psi_3) * psi_1 * psi_2\n !lsf(4) = (1.0d0 - psi_1) * (1.0d0 - psi_2) * (1.0d0 - psi_3) !lsf(4) = (1 - psi_1) * (1 - psi_3) * psi_2\n !lsf(5) = (1.0d0 - psi_2) * psi_1 * psi_3 !lsf(5) = (1.0d0 - psi_1) * (1.0d0 - psi_2) * psi_3\n !lsf(6) = psi_1 * psi_2 * psi_3 !lsf(6) = (1.0d0 - psi_2) * psi_1 * psi_3\n !lsf(7) = (1.0d0 - psi_1) * psi_2 * psi_3 !lsf(7) = psi_1 * psi_2 * psi_3\n !lsf(8) = (1.0d0 - psi_1) * (1.0d0 - psi_2) * psi_3 !lsf(8) = (1.0d0 - psi_1) * psi_2 * psi_3\n\t \n lsf(1) = (1.0d0 - psi_1) * (1.0d0 - psi_2) * (1.0d0 - psi_3)\n lsf(2) = (1.0d0 - psi_2) * (1.0d0 - psi_3) * (psi_1 + 1.0d0)\n lsf(3) = (1.0d0 - psi_3) * (psi_1 + 1.0d0) * (psi_2 + 1.0d0)\n lsf(4) = (1.0d0 - psi_1) * (1.0d0 - psi_3) * (psi_2 + 1.0d0)\n lsf(5) = (1.0d0 - psi_1) * (1.0d0 - psi_2) * (psi_3 + 1.0d0)\n lsf(6) = (1.0d0 - psi_2) * (psi_1 + 1.0d0) * (psi_3 + 1.0d0)\n lsf(7) = (psi_1 + 1.0d0) * (psi_2 + 1.0d0) * (psi_3 + 1.0d0)\n lsf(8) = (1.0d0 - psi_1) * (psi_2 + 1.0d0) * (psi_3 + 1.0d0)\n lsf = lsf /8.0d0\n end if\n\t\n if (Ndim == 2) then\n psi_1 = Gauss(1)\n psi_2 = Gauss(2)\n \n lsf(1) = (1.0d0 - psi_1) * (1.0d0 - psi_2)\n lsf(2) = (1.0d0 - psi_2) * (psi_1 + 1.0d0)\n lsf(3) = (psi_1 + 1.0d0) * (psi_2 + 1.0d0)\n lsf(4) = (1.0d0 - psi_1) * (psi_2 + 1.0d0)\n lsf = lsf /4.0d0\n end if\n\n Return\n\nEnd\n\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \nSubRoutine localShapeFunctionDerivativesHyperCube &\n (NodG, Ndim, dlsf, Gauss)\n\n !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n Implicit Real*8 (a-h, o-z)\n\n Dimension dlsf(Ndim, NodG), Gauss(Ndim)\n\t\n if (Ndim == 3) then\n psi_1 = Gauss(1)\n psi_2 = Gauss(2)\n psi_3 = Gauss(3)\n\n dlsf(1,1) = - (1.0d0 - psi_2) * (1.0d0 - psi_3)\n dlsf(1,2) = (1.0d0 - psi_2) * (1.0d0 - psi_3)\n dlsf(1,3) = (1.0d0 - psi_3) * (psi_2 + 1.0d0)\n dlsf(1,4) = - (1.0d0 - psi_3) * (psi_2 + 1.0d0)\n dlsf(1,5) = - (1.0d0 - psi_2) * (psi_3 + 1.0d0)\n dlsf(1,6) = (1.0d0 - psi_2) * (psi_3 + 1.0d0)\n dlsf(1,7) = (psi_2 + 1.0d0) * (psi_3 + 1.0d0)\n dlsf(1,8) = - (psi_2 + 1.0d0) * (psi_3 + 1.0d0)\n\n dlsf(2,1) = - (1.0d0 - psi_1) * (1.0d0 - psi_3)\n dlsf(2,2) = - (1.0d0 - psi_3) * (psi_1 + 1.0d0)\n dlsf(2,3) = (1.0d0 - psi_3) * (psi_1 + 1.0d0)\n dlsf(2,4) = (1.0d0 - psi_1) * (1.0d0 - psi_3)\n dlsf(2,5) = - (1.0d0 - psi_1) * (psi_3 + 1.0d0)\n dlsf(2,6) = - (psi_1 + 1.0d0) * (psi_3 + 1.0d0)\n dlsf(2,7) = (psi_1 + 1.0d0) * (psi_3 + 1.0d0)\n dlsf(2,8) = (1.0d0 - psi_1) * (psi_3 + 1.0d0)\n\n dlsf(3,1) = - (1.0d0 - psi_1) * (1.0d0 - psi_2)\n dlsf(3,2) = - (1.0d0 - psi_2) * (psi_1 + 1.0d0)\n dlsf(3,3) = - (psi_1 + 1.0d0) * (psi_2 + 1.0d0)\n dlsf(3,4) = - (1.0d0 - psi_1) * (psi_2 + 1.0d0)\n dlsf(3,5) = (1.0d0 - psi_1) * (1.0d0 - psi_2)\n dlsf(3,6) = (1.0d0 - psi_2) * (psi_1 + 1.0d0)\n dlsf(3,7) = (psi_1 + 1.0d0) * (psi_2 + 1.0d0)\n dlsf(3,8) = (1.0d0 - psi_1) * (psi_2 + 1.0d0)\n\n dlsf = dlsf / 8.0d0\n\n end if\n\t\n if (Ndim == 2) then\n psi_1 = Gauss(1)\n psi_2 = Gauss(2)\n\n dlsf(1,1) = - (1.0d0 - psi_2)\n dlsf(1,2) = (1.0d0 - psi_2)\n dlsf(1,3) = (psi_2 + 1.0d0)\n dlsf(1,4) = - (psi_2 + 1.0d0)\n dlsf(2,1) = - (1.0d0 - psi_1)\n dlsf(2,2) = - (psi_1 + 1.0d0)\n dlsf(2,3) = (psi_1 + 1.0d0)\n dlsf(2,4) = (1.0d0 - psi_1)\n\n dlsf = dlsf/4.0d0\n\n end if\n Return\n\nEnd\n\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n", "meta": {"hexsha": "78e74de3a0a2a7e54274c511f340831455260384", "size": 51527, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "myelements/src/tools/SFQuadrilateral.f90", "max_stars_repo_name": "felipefr/Piola", "max_stars_repo_head_hexsha": "2189b0a4d214f99cd550ee780f0b439e0763825f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-08-24T22:15:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-23T03:30:22.000Z", "max_issues_repo_path": "myelements/src/tools/SFQuadrilateral.f90", "max_issues_repo_name": "felipefr/Piola", "max_issues_repo_head_hexsha": "2189b0a4d214f99cd550ee780f0b439e0763825f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "myelements/src/tools/SFQuadrilateral.f90", "max_forks_repo_name": "felipefr/Piola", "max_forks_repo_head_hexsha": "2189b0a4d214f99cd550ee780f0b439e0763825f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-18T02:23:44.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T02:23:44.000Z", "avg_line_length": 48.4731890875, "max_line_length": 127, "alphanum_fraction": 0.2569332583, "num_tokens": 12125, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248157222395, "lm_q2_score": 0.7090191399336402, "lm_q1q2_score": 0.6657865672197272}} {"text": "program mean\n use, intrinsic :: iso_fortran_env, only : error_unit, I8 => INT64\n implicit none\n integer, parameter :: nr_runs = 5\n integer(kind=I8) :: nr_values\n integer :: run\n real, dimension(:), allocatable :: values\n \n call get_arguments(nr_values)\n\n do run = 1, nr_runs\n values = init_values(nr_values)\n print '(F10.3)', sum(values)/size(values)\n end do\n\ncontains\n\n function init_values(nr_values) result(values)\n implicit none\n integer(kind=I8), value :: nr_values\n real, dimension(:), allocatable :: values\n integer :: status\n\n allocate(values(nr_values), stat=status)\n if (status /= 0) then\n write (unit=error_unit, fmt='(A, I0, A)') &\n 'error: can not allocate ', nr_values, ' values'\n stop 2\n end if\n call random_number(values)\n end function init_values\n\n subroutine get_arguments(nr_values)\n implicit none\n integer(kind=I8), intent(out) :: nr_values\n integer :: status\n character(len=1024) :: buffer, msg\n \n if (command_argument_count() == 1) then\n call get_command_argument(1, buffer)\n read (buffer, fmt=*, iostat=status, iomsg=msg) nr_values\n if (status /= 0) then\n write (unit=error_unit, fmt='(2A)') 'error: ', msg\n stop 1\n end if\n else\n nr_values = 10\n end if\n end subroutine get_arguments\n\nend program mean\n", "meta": {"hexsha": "a7ec337da28ffeb6419be431f1dd6205d19796e0", "size": 1514, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "scenarios/Week_03/Allocatables/mean_01.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": "scenarios/Week_03/Allocatables/mean_01.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": "scenarios/Week_03/Allocatables/mean_01.f90", "max_forks_repo_name": "caguerra/Fortran-MOOC", "max_forks_repo_head_hexsha": "fb8a9c24e62ce5f388deb06b21e3009aea6b78d4", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2021-09-27T07:30:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-07T16:23:19.000Z", "avg_line_length": 29.1153846154, "max_line_length": 69, "alphanum_fraction": 0.5785997358, "num_tokens": 378, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388083214156, "lm_q2_score": 0.8031737869342624, "lm_q1q2_score": 0.6657819218162861}} {"text": " program main\n\nc*********************************************************************72\nc\ncc MAIN is the main program for BLAS1_S_PRB.\nc\nc Discussion:\nc\nc BLAS1_S_PRB tests the BLAS1_S library.\nc\nc Licensing:\nc\nc This code is distributed under the MIT license by Sourangshu Ghosh\nc\nc Modified:\nc\nc By Sourangshu Ghosh\nc\nc Author:\nc\nc Sourangshu Ghosh\nc\n implicit none\n\n call timestamp ( )\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BLAS1_S_PRB:'\n write ( *, '(a)' ) ' FORTRAN77 version'\n write ( *, '(a)' ) ' Test the BLAS1_S library.'\n\n call test01 ( )\n call test02 ( )\n call test03 ( )\n call test04 ( )\n call test05 ( )\n call test06 ( )\n call test07 ( )\n call test08 ( )\n call test09 ( )\n\n call test10 ( )\n call test11 ( )\n call test12 ( )\nc\nc Terminate.\nc\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'BLAS1_S_PRB:'\n write ( *, '(a)' ) ' Normal end of execution.'\n write ( *, '(a)' ) ' '\n call timestamp ( )\n\n stop\n end\n subroutine test01 ( )\n\nc*********************************************************************72\nc\ncc TEST01 tests ISAMAX.\nc\nc Licensing:\nc\nc This code is distributed under the MIT license by Sourangshu Ghosh\nc\nc Modified:\nc\nc by Sourangshu Ghosh\nc\nc Author:\nc\nc Sourangshu Ghosh\nc\n implicit none\n\n integer n\n\n parameter ( n = 11 )\n\n integer i\n integer i1\n integer incx\n integer isamax\n real x(n)\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST01'\n write ( *, '(a)' ) ' ISAMAX returns the index of maximum '\n write ( *, '(a)' ) ' magnitude;'\n\n do i = 1, n\n x(i) = real ( mod ( 7 * i, 11 ) ) - real ( n / 2 )\n end do\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' The vector X:'\n write ( *, '(a)' ) ' '\n do i = 1, n\n write ( *, '(2x,i6,f8.4)' ) i, x(i)\n end do\n\n incx = 1\n\n i1 = isamax ( n, x, incx )\n\n write ( *, '(a)' ) ' '\n write ( *, '(a,i6)' ) ' The index of maximum magnitude = ', i1\n\n return\n end\n subroutine test02 ( )\n\nc*********************************************************************72\nc\ncc TEST02 tests ISAMAX, SAXPY and SSCAL.\nc\nc Licensing:\nc\nc This code is distributed under the MIT license by Sourangshu Ghosh\nc\nc Modified:\nc\nc Sourangshu Ghosh\nc\nc Author:\nc\nc Sourangshu Ghosh\nc\n implicit none\n\n integer n\n integer lda\n\n parameter ( n = 10 )\n parameter ( lda = n )\n\n real a(lda,n)\n real b(n)\n integer i\n integer info\n integer ipvt(n)\n integer isamax\n integer j\n integer k\n integer l\n real t\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST02'\n write ( *, '(a)' ) ' Use ISAMAX, SAXPY and SSCAL'\n write ( *, '(a)' ) ' in a Gauss elimination routine.'\nc\nc Set the matrix.\nc\n do i = 1, n\n do j = 1, n\n\n if ( i == j ) then\n a(i,j) = 2.0E+00\n else if ( i == j + 1 ) then\n a(i,j) = - 1.0E+00\n else if ( i == j - 1 ) then\n a(i,j) = - 1.0E+00\n else\n a(i,j) = 0.0E+00\n end if\n\n end do\n end do\nc\nc Set the right hand side.\nc\n do i = 1, n-1\n b(i) = 0.0E+00\n end do\n b(n) = real ( n ) + 1.0E+00\n\n info = 0\n\n do k = 1, n - 1\n\n l = isamax ( n-k+1, a(k,k), 1 ) + k - 1\n ipvt(k) = l\n\n if ( a(l,k) == 0.0E+00 ) then\n\n info = k\n\n else\n\n if ( l /= k ) then\n t = a(l,k)\n a(l,k) = a(k,k)\n a(k,k) = t\n end if\n\n t = -1.0E+00 / a(k,k)\n call sscal ( n-k, t, a(k+1,k), 1 )\n\n do j = k+1, n\n t = a(l,j)\n if ( l /= k ) then\n a(l,j) = a(k,j)\n a(k,j) = t\n end if\n call saxpy ( n-k, t, a(k+1,k), 1, a(k+1,j), 1 )\n end do\n\n end if\n\n end do\n\n ipvt(n) = n\n if ( a(n,n) == 0.0E+00 ) then\n info = n\n end if\n\n if ( info /= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' The matrix is singular.'\n return\n end if\n\n do k = 1, n-1\n l = ipvt(k)\n t = b(l)\n if ( l /= k ) then\n b(l) = b(k)\n b(k) = t\n end if\n call saxpy ( n-k, t, a(k+1,k), 1, b(k+1), 1 )\n end do\n\n do k = n, 1, -1\n b(k) = b(k) / a(k,k)\n t = - b(k)\n call saxpy ( k-1, t, a(1,k), 1, b(1), 1 )\n end do\n\n write ( *, '(a,g14.6)' ) ' '\n write ( *, '(a,g14.6)' ) ' First five entries of solution:'\n write ( *, '(a,g14.6)' ) ' '\n write ( *, '(2x,5g14.6)' ) ( b(j), j = 1, 5 )\n\n return\n end\n subroutine test03 ( )\n\nc*********************************************************************72\nc\ncc TEST03 tests SASUM.\nc\nc Licensing:\nc\nc This code is distributed under the MIT license by Sourangshu Ghosh\nc\nc Modified:\nc\nc by Sourangshu Ghosh\nc\nc Author:\nc\nc Sourangshu Ghosh\nc\n implicit none\n\n integer lda\n integer ma\n integer na\n integer nx\n\n parameter ( lda = 6 )\n parameter ( ma = 5 )\n parameter ( na = 4 )\n parameter ( nx = 10 )\n\n real a(lda,na)\n integer i\n integer j\n real sasum\n real x(nx)\n\n do i = 1, nx\n x(i) = ( -1.0E+00 )**i * real ( 2 * i )\n end do\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST03'\n write ( *, '(a)' ) ' SASUM adds the absolute values '\n write ( *, '(a)' ) ' of elements of a vector.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' X = '\n write ( *, '(a)' ) ' '\n do i = 1, nx\n write ( *, '(2x,i6,g14.6)' ) i, x(i)\n end do\n\n write ( *, '(a)' ) ' '\n write ( *, '(a,g14.6)' ) ' SASUM ( NX, X, 1 ) = ',\n & sasum ( nx, x, 1 )\n write ( *, '(a,g14.6)' ) ' SASUM ( NX/2, X, 2 ) = ',\n & sasum ( nx/2, x, 2 )\n write ( *, '(a,g14.6)' ) ' SASUM ( 2, X, NX/2 ) = ',\n & sasum ( 2, x, nx/2 )\n\n do i = 1, ma\n do j = 1, na\n a(i,j) = ( -1.0E+00 )**( i + j ) * real ( 10 * i + j )\n end do\n end do\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' Demonstrate with a matrix A:'\n write ( *, '(a)' ) ' '\n do i = 1, ma\n write ( *, '(2x,5g14.6)' ) ( a(i,j), j = 1, na )\n end do\n\n write ( *, '(a)' ) ' '\n write ( *, '(a,g14.6)' ) ' SASUM(MA,A(1,2),1) = ',\n & sasum ( ma, a(1,2), 1 )\n write ( *, '(a,g14.6)' ) ' SASUM(NA,A(2,1),LDA) = ',\n & sasum ( na, a(2,1), lda )\n\n return\n end\n subroutine test04 ( )\n\nc*********************************************************************72\nc\ncc TEST04 tests SAXPY.\nc\nc Licensing:\nc\nc This code is distributed under the MIT license by Sourangshu Ghosh\nc\nc Modified:\nc\nc by Sourangshu Ghosh\nc\nc Author:\nc\nc Sourangshu Ghosh\nc\n implicit none\n\n integer n\n\n parameter ( n = 6 )\n\n real da\n integer i\n real x(n)\n real y(n)\n\n do i = 1, n\n x(i) = real ( i )\n end do\n\n do i = 1, n\n y(i) = real ( 100 * i )\n end do\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST04'\n write ( *, '(a)' )\n & ' SAXPY adds a multiple of vector X to vector Y.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' X = '\n write ( *, '(a)' ) ' '\n do i = 1, n\n write ( *, '(2x,i6,g14.6)' ) i, x(i)\n end do\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' Y = '\n write ( *, '(a)' ) ' '\n do i = 1, n\n write ( *, '(2x,i6,g14.6)' ) i, y(i)\n end do\n\n da = 1.0E+00\n call saxpy ( n, da, x, 1, y, 1 )\n write ( *, '(a)' ) ' '\n write ( *, '(a,f8.4,a)' ) ' SAXPY ( N, ', da, ', X, 1, Y, 1 )'\n write ( *, '(a)' ) ' '\n do i = 1, n\n write ( *, '(2x,i6,g14.6)' ) i, y(i)\n end do\n\n do i = 1, n\n y(i) = real ( 100 * i )\n end do\n\n da = -2.0E+00\n call saxpy ( n, da, x, 1, y, 1 )\n write ( *, '(a)' ) ' '\n write ( *, '(a,f8.4,a)' ) ' SAXPY ( N, ', da, ', X, 1, Y, 1 )'\n write ( *, '(a)' ) ' '\n do i = 1, n\n write ( *, '(2x,i6,g14.6)' ) i, y(i)\n end do\n\n do i = 1, n\n y(i) = real ( 100 * i )\n end do\n\n da = +3.0E+00\n call saxpy ( 3, da, x, 2, y, 1 )\n write ( *, '(a)' ) ' '\n write ( *, '(a,f8.4,a)' ) ' SAXPY ( 3, ', da, ', X, 2, Y, 1 )'\n write ( *, '(a)' ) ' '\n do i = 1, n\n write ( *, '(2x,i6,g14.6)' ) i, y(i)\n end do\n\n do i = 1, n\n y(i) = real ( 100 * i )\n end do\n\n da = -4.0E+00\n call saxpy ( 3, da, x, 1, y, 2 )\n write ( *, '(a)' ) ' '\n write ( *, '(a,f8.4,a)' ) ' SAXPY ( 3, ', da, ', X, 1, Y, 2 )'\n write ( *, '(a)' ) ' '\n do i = 1, n\n write ( *, '(2x,i6,g14.6)' ) i, y(i)\n end do\n\n return\n end\n subroutine test05 ( )\n\nc*********************************************************************72\nc\ncc TEST05 tests SCOPY.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 22 February 2006\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n real a(5,5)\n integer i\n integer j\n real x(10)\n real y(10)\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST05'\n write ( *, '(a)' ) ' SCOPY copies one vector into another.'\n\n do i = 1, 10\n x(i) = real ( i )\n end do\n\n do i = 1, 10\n y(i) = real ( 10 * i )\n end do\n\n do i = 1, 5\n do j = 1, 5\n a(i,j) = real ( 10 * i + j )\n end do\n end do\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' X = '\n write ( *, '(a)' ) ' '\n do i = 1, 10\n write ( *, '(2x,i6,g14.6)' ) i, x(i)\n end do\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' Y = '\n write ( *, '(a)' ) ' '\n do i = 1, 10\n write ( *, '(2x,i6,g14.6)' ) i, y(i)\n end do\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' A = '\n write ( *, '(a)' ) ' '\n do i = 1, 5\n write ( *, '(2x,5f8.2)' ) ( a(i,j), j = 1, 5)\n end do\n\n call scopy ( 5, x, 1, y, 1 )\n write ( *, '(a)' ) ' '\n write ( *, '(a,f8.4,a)' ) ' SCOPY ( 5, X, 1, Y, 1 )'\n write ( *, '(a)' ) ' '\n do i = 1, 10\n write ( *, '(2x,i6,g14.6)' ) i, y(i)\n end do\n\n do i = 1, 10\n y(i) = real ( 10 * i )\n end do\n\n call scopy ( 3, x, 2, y, 3 )\n write ( *, '(a)' ) ' '\n write ( *, '(a,f8.4,a)' ) ' SCOPY ( 3, X, 2, Y, 3 )'\n write ( *, '(a)' ) ' '\n do i = 1, 10\n write ( *, '(2x,i6,g14.6)' ) i, y(i)\n end do\n\n call scopy ( 5, x, 1, a, 1 )\n write ( *, '(a)' ) ' '\n write ( *, '(a,f8.4,a)' ) ' SCOPY ( 5, X, 1, A, 1 )'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' A = '\n write ( *, '(a)' ) ' '\n do i = 1, 5\n write ( *, '(2x,5f8.2)' ) ( a(i,j), j = 1, 5 )\n end do\n\n do i = 1, 5\n do j = 1, 5\n a(i,j) = real ( 10 * i + j )\n end do\n end do\n\n call scopy ( 5, x, 2, a, 5 )\n write ( *, '(a)' ) ' '\n write ( *, '(a,f8.4,a)' ) ' SCOPY ( 5, X, 2, A, 5 )'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' A = '\n write ( *, '(a)' ) ' '\n do i = 1, 5\n write ( *, '(2x,5f8.2)' ) ( a(i,j), j = 1, 5 )\n end do\n\n return\n end\n subroutine test06 ( )\n\nc*********************************************************************72\nc\ncc TEST06 tests SDOT.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 22 February 2006\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n integer n\n integer lda\n integer ldb\n integer ldc\n\n parameter ( n = 5 )\n parameter ( lda = 10 )\n parameter ( ldb = 7 )\n parameter ( ldc = 6 )\n\n real a(lda,lda)\n real b(ldb,ldb)\n real c(ldc,ldc)\n integer i\n integer j\n real sdot\n real sum1\n real x(n)\n real y(n)\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST06'\n write ( *, '(a)' ) ' SDOT computes the dot product of vectors.'\n\n do i = 1, n\n x(i) = real ( i )\n end do\n\n do i = 1, n\n y(i) = - real ( i )\n end do\n\n do i = 1, n\n do j = 1, n\n a(i,j) = real ( i + j )\n end do\n end do\n\n do i = 1, n\n do j = 1, n\n b(i,j) = real ( i - j )\n end do\n end do\nc\nc To compute a simple dot product of two vectors, use a\nc call like this:\nc\n sum1 = sdot ( n, x, 1, y, 1 )\n\n write ( *, '(a)' ) ' '\n write ( *, '(a,g14.6)' ) ' Dot product of X and Y is ', sum1\nc\nc To multiply a ROW of a matrix A times a vector X, we need to\nc specify the increment between successive entries of the row of A:\nc\n sum1 = sdot ( n, a(2,1), lda, x, 1 )\n\n write ( *, '(a)' ) ' '\n write ( *, '(a,g14.6)' ) ' Product of row 2 of A and X is ', sum1\nc\nc Product of a column of A and a vector is simpler:\nc\n sum1 = sdot ( n, a(1,2), 1, x, 1 )\n\n write ( *, '(a)' ) ' '\n write ( *, '(a,g14.6)' )\n & ' Product of column 2 of A and X is ', sum1\nc\nc Here's how matrix multiplication, c = a*b, could be done\nc with SDOT:\nc\n do i = 1, n\n do j = 1, n\n c(i,j) = sdot ( n, a(i,1), lda, b(1,j), 1 )\n end do\n end do\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' Matrix product computed with SDOT:'\n write ( *, '(a)' ) ' '\n do i = 1, n\n write ( *, '(2x,5g14.6)' ) ( c(i,j), j = 1, n )\n end do\n\n return\n end\n subroutine test07 ( )\n\nc*********************************************************************72\nc\ncc TEST07 tests SMACH.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 22 February 2006\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n real smach\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST07'\n write ( *, '(a)' )\n & ' SMACH computes several machine arithmetic parameters.'\n\n write ( *, '(a)' ) ' '\n write ( *, * ) ' SMACH(1) = machine epsilon = ', smach ( 1 )\n write ( *, * ) ' SMACH(2) = a tiny value = ', smach ( 2 )\n write ( *, * ) ' SMACH(3) = a huge value = ', smach ( 3 )\n\n return\n end\n subroutine test08 ( )\n\nc*********************************************************************72\nc\ncc TEST08 tests SNRM2.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 22 February 2006\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n integer n\n integer lda\n\n parameter ( n = 5 )\n parameter ( lda = n + 5 )\nc\nc These parameters illustrate the fact that matrices are typically\nc dimensioned with more space than the user requires.\nc\n real a(lda,lda)\n integer i\n integer incx\n integer j\n real snrm2\n real sum1\n real x(n)\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST08'\n write ( *, '(a)' ) ' SNRM2 computes the Euclidean norm '\n write ( *, '(a)' ) ' of a vector.'\nc\nc Compute the euclidean norm of a vector:\nc\n do i = 1, n\n x(i) = real ( i )\n end do\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' The vector X:'\n write ( *, '(a)' ) ' '\n do i = 1, n\n write ( *, '(2x,i6,f8.4)' ) i, x(i)\n end do\n incx = 1\n\n write ( *, '(a)' ) ' '\n write ( *, '(a,g14.6)' )\n & ' The 2-norm of X is ', snrm2 ( n, x, incx )\nc\nc Compute the euclidean norm of a row or column of a matrix:\nc\n do i = 1, n\n do j = 1, n\n a(i,j) = real ( i + j )\n end do\n end do\n\n incx = lda\n sum1 = snrm2 ( n, a(2,1), incx )\n\n write ( *, '(a)' ) ' '\n write ( *, '(a,g14.6)' )\n & ' The 2-norm of row 2 of A is ', sum1\n\n incx = 1\n sum1 = snrm2 ( n, a(1,2), incx )\n\n write ( *, '(a)' ) ' '\n write ( *, '(a,g14.6)' )\n & ' The 2-norm of column 2 of A is ', sum1\n\n return\n end\n subroutine test09 ( )\n\nc*********************************************************************72\nc\ncc TEST09 tests SROT.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 22 February 2006\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n integer n\n\n parameter ( n = 6 )\n\n real c\n integer i\n real s\n real x(n)\n real y(n)\n\n do i = 1, n\n x(i) = real ( i )\n end do\n\n do i = 1, n\n y(i) = real ( i * i - 12 )\n end do\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST09'\n write ( *, '(a)' ) ' SROT carries out a Givens rotation.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' X and Y'\n write ( *, '(a)' ) ' '\n do i = 1, n\n write ( *, '(2x,i6,g14.6,g14.6)' ) i, x(i), y(i)\n end do\n\n c = 0.5E+00\n s = sqrt ( 1.0E+00 - c * c )\n call srot ( n, x, 1, y, 1, c, s )\n write ( *, '(a)' ) ' '\n write ( *, '(a,f8.4,a,f8.4,a)' )\n & ' SROT ( N, X, 1, Y, 1, ', c, ',', s, ' )'\n write ( *, '(a)' ) ' '\n do i = 1, n\n write ( *, '(2x,i6,g14.6,g14.6)' ) i, x(i), y(i)\n end do\n\n do i = 1, n\n x(i) = real ( i )\n end do\n\n do i = 1, n\n y(i) = real ( i * i - 12 )\n end do\n\n c = x(1) / sqrt ( x(1) * x(1) + y(1) * y(1) )\n s = y(1) / sqrt ( x(1) * x(1) + y(1) * y(1) )\n call srot ( n, x, 1, y, 1, c, s )\n write ( *, '(a)' ) ' '\n write ( *, '(a,f8.4,a,f8.4,a)' )\n & ' SROT ( N, X, 1, Y, 1, ', c, ',', s, ' )'\n write ( *, '(a)' ) ' '\n do i = 1, n\n write ( *, '(2x,i6,g14.6,g14.6)' ) i, x(i), y(i)\n end do\n\n return\n end\n subroutine test10 ( )\n\nc*********************************************************************72\nc\ncc TEST10 tests SROTG.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 15 May 2006\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n integer n\n parameter ( n = 6 )\n\n real a\n real b\n real c\n real r\n real r4_uniform_01\n real s\n real sa\n real sb\n integer seed\n integer test\n integer test_num\n parameter ( test_num = 5 )\n real z\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST10'\n write ( *, '(a)' ) ' SROTG generates a real Givens rotation'\n write ( *, '(a)' ) ' ( C S ) * ( A ) = ( R )'\n write ( *, '(a)' ) ' ( -S C ) ( B ) ( 0 )'\n write ( *, '(a)' ) ' '\n\n seed = 123456789\n\n do test = 1, test_num\n\n a = r4_uniform_01 ( seed )\n b = r4_uniform_01 ( seed )\n\n sa = a\n sb = b\n\n call srotg ( sa, sb, c, s )\n\n r = sa\n z = sb\n\n write ( *, '(a)' ) ' '\n write ( *, '(a,g14.6,a,g14.6)' ) ' A = ', a, ' B = ', b\n write ( *, '(a,g14.6,a,g14.6)' ) ' C = ', c, ' S = ', s\n write ( *, '(a,g14.6,a,g14.6)' ) ' R = ', r, ' Z = ', z\n write ( *, '(a,g14.6)' ) ' C*A+S*B = ', c * a + s * b\n write ( *, '(a,g14.6)' ) ' -S*A+C*B = ', -s * a + c * b\n\n end do\n\n return\n end\n subroutine test11 ( )\n\nc*********************************************************************72\nc\ncc TEST11 tests SSCAL.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 22 February 2006\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n integer n\n\n parameter ( n = 6 )\n\n real da\n integer i\n real x(n)\n\n do i = 1, n\n x(i) = real ( i )\n end do\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST11'\n write ( *, '(a)' ) ' SSCAL multiplies a vector by a scalar.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' X = '\n write ( *, '(a)' ) ' '\n do i = 1, n\n write ( *, '(2x,i6,g14.6)' ) i, x(i)\n end do\n\n da = 5.0E+00\n call sscal ( n, da, x, 1 )\n write ( *, '(a)' ) ' '\n write ( *, '(a,f8.4,a)' ) ' SSCAL ( N, ', da, ', X, 1 )'\n write ( *, '(a)' ) ' '\n do i = 1, n\n write ( *, '(2x,i6,g14.6)' ) i, x(i)\n end do\n\n do i = 1, n\n x(i) = real ( i )\n end do\n\n da = -2.0E+00\n call sscal ( 3, da, x, 2 )\n write ( *, '(a)' ) ' '\n write ( *, '(a,f8.4,a)' ) ' SSCAL ( 3, ', da, ', X, 2 )'\n write ( *, '(a)' ) ' '\n do i = 1, n\n write ( *, '(2x,i6,g14.6)' ) i, x(i)\n end do\n\n return\n end\n subroutine test12 ( )\n\nc*********************************************************************72\nc\ncc TEST12 tests SSWAP.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 22 February 2006\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n integer n\n\n parameter ( n = 6 )\n\n integer i\n real x(n)\n real y(n)\n\n do i = 1, n\n x(i) = real ( i )\n end do\n\n do i = 1, n\n y(i) = real ( 100 * i )\n end do\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST12'\n write ( *, '(a)' ) ' SSWAP swaps two vectors.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' X and Y'\n write ( *, '(a)' ) ' '\n do i = 1, n\n write ( *, '(2x,i6,g14.6,g14.6)' ) i, x(i), y(i)\n end do\n\n call sswap ( n, x, 1, y, 1 )\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' SSWAP ( N, X, 1, Y, 1 )'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' X and Y'\n write ( *, '(a)' ) ' '\n do i = 1, n\n write ( *, '(2x,i6,g14.6,g14.6)' ) i, x(i), y(i)\n end do\n\n do i = 1, n\n x(i) = real ( i )\n end do\n\n do i = 1, n\n y(i) = real ( 100 * i )\n end do\n\n call sswap ( 3, x, 2, y, 1 )\n write ( *, '(a)' ) ' '\n write ( *, '(a,f8.4,a)' ) ' SSWAP ( 3, X, 2, Y, 1 )'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' X and Y'\n write ( *, '(a)' ) ' '\n do i = 1, n\n write ( *, '(2x,i6,g14.6,g14.6)' ) i, x(i), y(i)\n end do\n\n return\n end\n", "meta": {"hexsha": "394167783510fa0b6a3d9e14af1bbd19dd458fa0", "size": 22358, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "blas1_s/blas1_s_prb.f", "max_stars_repo_name": "SourangshuGhosh/Basic-Linear-Algebra-Subprograms", "max_stars_repo_head_hexsha": "5b8b011a1acac19193203c54a97ebeed56fed6d3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-07-29T09:14:47.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-14T17:38:52.000Z", "max_issues_repo_path": "blas1_s/blas1_s_prb.f", "max_issues_repo_name": "SourangshuGhosh/Basic-Linear-Algebra-Subprograms", "max_issues_repo_head_hexsha": "5b8b011a1acac19193203c54a97ebeed56fed6d3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "blas1_s/blas1_s_prb.f", "max_forks_repo_name": "SourangshuGhosh/Basic-Linear-Algebra-Subprograms", "max_forks_repo_head_hexsha": "5b8b011a1acac19193203c54a97ebeed56fed6d3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.1323251418, "max_line_length": 72, "alphanum_fraction": 0.3917166115, "num_tokens": 8046, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8289387914176259, "lm_q2_score": 0.803173791645582, "lm_q1q2_score": 0.6657819121450008}} {"text": "!---------------------------------------------------------------------------------------------------\n! All the formulations have been taken from the original\n! article,the Span-Wagner EoS for CO2.\n! The EoS has been published in J. Phys. Chem. Ref. Data, Vol.25,\n! pp. 1509-1596, 1996.\n!---------------------------------------------------------------------------------------------------\n\n!--------------------------------------------------------------------------------------------------\n! SUBROUTINE deriv_expfonc\n! @brief Compute expotential fuction Psi p.1545 Table 32\n! @comments All exponential fuctions and their derivatives are involved\n! only in termes 40-42 of the residual parts\n! @authors Yu Fang\n! @date 26-10-2016\n!----------------------------------------------------------------------------------------------------\nSUBROUTINE deriv_expfonc( T, v, psi40, psi41, psi42,&\n dpsi_ddelt40, dpsi_ddelt41, dpsi_ddelt42,&\n dpsi_dtau40, dpsi_dtau41, dpsi_dtau42,&\n ddpsi_dddelt40, ddpsi_dddelt41, ddpsi_dddelt42,&\n ddpsi_ddtau40, ddpsi_ddtau41, ddpsi_ddtau42,&\n ddpsi_ddeltdtau40, ddpsi_ddeltdtau41, ddpsi_ddeltdtau42 )\n\n\n\n\n\n USE def_constants\n\n IMPLICIT NONE\n\n!IN/OUT\n\n REAL(pr) :: T,v\n \n REAL(pr) :: psi40, psi41, psi42\n\n REAL(pr) :: dpsi_ddelt40, dpsi_ddelt41, dpsi_ddelt42,&\n dpsi_dtau40, dpsi_dtau41, dpsi_dtau42\n \n REAL(pr) :: ddpsi_dddelt40, ddpsi_dddelt41, ddpsi_dddelt42,&\n ddpsi_ddtau40, ddpsi_ddtau41, ddpsi_ddtau42,&\n ddpsi_ddeltdtau40, ddpsi_ddeltdtau41,ddpsi_ddeltdtau42\n\n!LOCAL\n\n REAL(pr) :: tau, delt, rho\n \n REAL(pr) :: deltm1,deltm1_s, taum1,taum1_s\n\n!Preparation of variables\n\n rho = 1_pr / v\n delt = 1_pr / (rho_cr*v)\n tau = T_cr / T\n!\n!\n deltm1 = delt - 1_pr\n deltm1_s = deltm1 * deltm1\n taum1 = tau - 1_pr\n taum1_s = taum1 * taum1\n!\n!\n psi40 = exp(- CC40 * deltm1_s - DD40 * taum1_s)\n psi41 = exp(- CC41 * deltm1_s - DD40 * taum1_s)\n psi42 = exp(- CC42 * deltm1_s - DD40 * taum1_s)\n!\n!\n!-----------------------------------------------------------------------------------------------------------\n!Compute derivatives of psi 40-42\n!-----------------------------------------------------------------------------------------------------------\n\n dpsi_ddelt40 = - 2_pr * CC40 * deltm1 * psi40\n\n dpsi_ddelt41 = - 2_pr * CC41 * deltm1 * psi41\n\n dpsi_ddelt42 = - 2_pr * CC42 * deltm1 * psi42\n!\n!\n dpsi_dtau40 = - 2_pr * DD40 * taum1 * psi40\n\n dpsi_dtau41 = - 2_pr * DD40 * taum1 * psi41\n\n dpsi_dtau42 = - 2_pr * DD40 * taum1 * psi42\n!\n!\n ddpsi_dddelt40 = (2_pr * CC40 * deltm1_s - 1_pr) * 2_pr * CC40 * psi40\n\n ddpsi_dddelt41 = (2_pr * CC41 * deltm1_s - 1_pr) * 2_pr * CC41 * psi41\n\n ddpsi_dddelt42 = (2_pr * CC42 * deltm1_s - 1_pr) * 2_pr * CC42 * psi42\n!\n!\n ddpsi_ddtau40 = (2_pr * DD40 * taum1_s - 1_pr) * 2_pr * DD40 * psi40\n\n ddpsi_ddtau41 = (2_pr * DD40 * taum1_s - 1_pr) * 2_pr * DD40 * psi41\n\n ddpsi_ddtau42 = (2_pr * DD40 * taum1_s - 1_pr) * 2_pr * DD40 * psi42\n!\n!\n ddpsi_ddeltdtau40 = 4_pr * CC40 * DD40 * deltm1 * taum1 * psi40\n\n ddpsi_ddeltdtau41 = 4_pr * CC41 * DD40 * deltm1 * taum1 * psi41\n\n ddpsi_ddeltdtau42 = 4_pr * CC42 * DD40 * deltm1 * taum1 * psi42\n!\n!\nEND SUBROUTINE deriv_expfonc\n", "meta": {"hexsha": "29dc77233575c2110259b4133ea64766cb5553d7", "size": 3482, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "deriv_expfonc.f90", "max_stars_repo_name": "yufang67/CO2-look-up-table", "max_stars_repo_head_hexsha": "2acfb66790158fb2e4e1b91e18f639b26b9f297b", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-05-15T17:23:21.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-28T17:30:53.000Z", "max_issues_repo_path": "deriv_expfonc.f90", "max_issues_repo_name": "yufang67/CO2-look-up-table", "max_issues_repo_head_hexsha": "2acfb66790158fb2e4e1b91e18f639b26b9f297b", "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": "deriv_expfonc.f90", "max_forks_repo_name": "yufang67/CO2-look-up-table", "max_forks_repo_head_hexsha": "2acfb66790158fb2e4e1b91e18f639b26b9f297b", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.2407407407, "max_line_length": 108, "alphanum_fraction": 0.5005743825, "num_tokens": 1106, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802484881361, "lm_q2_score": 0.7248702761768248, "lm_q1q2_score": 0.6657790313845539}} {"text": "C Copyright(C) 1999-2020 National Technology & Engineering Solutions\nC of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with\nC NTESS, the U.S. Government retains certain rights in this software.\nC\nC See packages/seacas/LICENSE for details\n\nC=======================================================================\n SUBROUTINE GAUSSF (IS3DIM, NLNKF, LINKF1, XN, YN, ZN,\n & XGAUSS, YGAUSS, ZGAUSS)\nC=======================================================================\n\nC --*** GAUSSF *** (DETOUR) Calculate gauss point for a face\nC -- Written by Amy Gilkey - revised 10/20/87\nC --\nC --GAUSSF calculates the 4 element gauss points given the coordinates\nC --of the 4 nodes.\nC --\nC --Parameters:\nC -- IS3DIM - IN - true iff 3D versus 2D\nC -- NLNKF - IN - the number of nodes per face; must be 4\nC -- LINKF1 - IN - the connectivity for the face\nC -- XN, YN, ZN - IN - the nodal coordinates\nC -- XGAUSS, YGAUSS, ZGAUSS - OUT - the gauss point coordinates\n\n PARAMETER (S = .577350269189626)\n\n LOGICAL IS3DIM\n INTEGER LINKF1(NLNKF)\n REAL XN(*), YN(*), ZN(*)\n REAL XGAUSS(4), YGAUSS(4), ZGAUSS(4)\n\n REAL WT(4,4)\n LOGICAL FIRST\n SAVE FIRST, WT\nC --FIRST - true iff first time in routine\nC --WT - the gauss point constants\n\n DATA FIRST /.TRUE./\n\n IF (FIRST) THEN\n FIRST = .FALSE.\n\nC --Determine gauss point constants\n\n DO 100 N = 1, 4\n IF (N .EQ. 1) THEN\n SI = -S\n TI = -S\n ELSE IF (N .EQ. 2) THEN\n SI = +S\n TI = -S\n ELSE IF (N .EQ. 3) THEN\n SI = +S\n TI = +S\n ELSE IF (N .EQ. 4) THEN\n SI = -S\n TI = +S\n END IF\n WT(1,N) = .25 * (1-SI) * (1-TI)\n WT(2,N) = .25 * (1+SI) * (1-TI)\n WT(3,N) = .25 * (1+SI) * (1+TI)\n WT(4,N) = .25 * (1-SI) * (1+TI)\n 100 CONTINUE\n END IF\n\nC --Determine gauss point coordinates\n\n DO 110 N = 1, 4\n XGAUSS(N) = WT(1,N)*XN(LINKF1(1)) + WT(2,N)*XN(LINKF1(2))\n & + WT(3,N)*XN(LINKF1(3)) + WT(4,N)*XN(LINKF1(4))\n YGAUSS(N) = WT(1,N)*YN(LINKF1(1)) + WT(2,N)*YN(LINKF1(2))\n & + WT(3,N)*YN(LINKF1(3)) + WT(4,N)*YN(LINKF1(4))\n IF (IS3DIM) THEN\n ZGAUSS(N) = WT(1,N)*ZN(LINKF1(1)) + WT(2,N)*ZN(LINKF1(2))\n & + WT(3,N)*ZN(LINKF1(3)) + WT(4,N)*ZN(LINKF1(4))\n END IF\n 110 CONTINUE\n\n RETURN\n END\n", "meta": {"hexsha": "3951ea3b3544b51808e8d91494e8af7fddd69538", "size": 2551, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "packages/seacas/applications/blot/gaussf.f", "max_stars_repo_name": "jschueller/seacas", "max_stars_repo_head_hexsha": "14c34ae08b757cba43a3a03ec0f129c8a168a9d3", "max_stars_repo_licenses": ["Python-2.0", "Zlib", "BSD-2-Clause", "MIT", "NetCDF", "BSL-1.0", "X11", "BSD-3-Clause"], "max_stars_count": 82, "max_stars_repo_stars_event_min_datetime": "2016-02-04T18:38:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T03:01:49.000Z", "max_issues_repo_path": "packages/seacas/applications/blot/gaussf.f", "max_issues_repo_name": "jschueller/seacas", "max_issues_repo_head_hexsha": "14c34ae08b757cba43a3a03ec0f129c8a168a9d3", "max_issues_repo_licenses": ["Python-2.0", "Zlib", "BSD-2-Clause", "MIT", "NetCDF", "BSL-1.0", "X11", "BSD-3-Clause"], "max_issues_count": 206, "max_issues_repo_issues_event_min_datetime": "2015-11-20T01:57:47.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:12:04.000Z", "max_forks_repo_path": "packages/seacas/applications/blot/gaussf.f", "max_forks_repo_name": "jschueller/seacas", "max_forks_repo_head_hexsha": "14c34ae08b757cba43a3a03ec0f129c8a168a9d3", "max_forks_repo_licenses": ["Python-2.0", "Zlib", "BSD-2-Clause", "MIT", "NetCDF", "BSL-1.0", "X11", "BSD-3-Clause"], "max_forks_count": 68, "max_forks_repo_forks_event_min_datetime": "2016-01-13T22:46:51.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T06:25:05.000Z", "avg_line_length": 31.4938271605, "max_line_length": 72, "alphanum_fraction": 0.4845158761, "num_tokens": 896, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480237330998, "lm_q2_score": 0.7248702642896702, "lm_q1q2_score": 0.6657790123789595}} {"text": " program tipcalc\n implicit none\n double precision :: a, b, y, z\n\n write(*,'(\"Enter subtotal:\")')\n read (*,*) a\n write(*,'(\"Enter tip percentage:\")')\n read (*,*) b\n y=a*(b/100)\n z=y+a\n write(*,'(\"Tip: \", f12.2)') y\n write(*,'(\"Total:\", f12.2)') z\n stop\n end\n", "meta": {"hexsha": "ed13f87f7d62747487b5722e61cfdb5dbcd843df", "size": 324, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tipcalc.f", "max_stars_repo_name": "Silent-Hunter/tipcalc", "max_stars_repo_head_hexsha": "d6c4f58723a18208545c207e71d0d58ad6c3b5dc", "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": "tipcalc.f", "max_issues_repo_name": "Silent-Hunter/tipcalc", "max_issues_repo_head_hexsha": "d6c4f58723a18208545c207e71d0d58ad6c3b5dc", "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": "tipcalc.f", "max_forks_repo_name": "Silent-Hunter/tipcalc", "max_forks_repo_head_hexsha": "d6c4f58723a18208545c207e71d0d58ad6c3b5dc", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.6, "max_line_length": 42, "alphanum_fraction": 0.4320987654, "num_tokens": 106, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8688267830311354, "lm_q2_score": 0.766293653760418, "lm_q1q2_score": 0.6657764500538387}} {"text": "program tsunami\n\n ! Tsunami simulator\n !\n ! Solves the non-linear 1-d shallow water equation:\n !\n ! du/dt + u du/dx + g dh/dx = 0\n ! dh/dt + d(hu)/dx = 0\n !\n ! This version is parallelized.\n\n use iso_fortran_env, only: int32, real32\n use mod_diff, only: diff => diff_centered\n use mod_parallel, only: tile_indices, tile_neighbors\n\n implicit none\n\n integer(int32) :: i, n\n\n integer(int32), parameter :: grid_size = 100 ! grid size in x\n integer(int32), parameter :: num_time_steps = 5000 ! number of time steps\n\n real(real32), parameter :: dt = 0.02 ! time step [s]\n real(real32), parameter :: dx = 1 ! grid spacing [m]\n real(real32), parameter :: g = 9.8 ! gravitational acceleration [m/s]\n\n real(real32), allocatable :: h(:)[:], u(:)[:]\n real(real32), allocatable :: gather(:)[:]\n real(real32), allocatable :: hmean(:)\n\n integer(int32), parameter :: ipos = 25\n real(real32), parameter :: decay = 0.02\n\n integer(int32) :: indices(2), neighbors(2)\n integer(int32) :: left, right\n integer(int32) :: is, ie ! global start and end indices\n integer(int32) :: ils, ile ! local start and end computational indices\n integer(int32) :: ims, ime ! local start and end memory indices\n integer(int32) :: tile_size\n\n if (mod(grid_size, num_images()) > 0) then\n error stop 'Error: grid_size must be divisible by number of images'\n end if\n\n neighbors = tile_neighbors()\n left = neighbors(1)\n right = neighbors(2)\n\n indices = tile_indices(grid_size)\n is = indices(1)\n ie = indices(2)\n\n tile_size = grid_size / num_images()\n ils = 1\n ile = tile_size\n ims = ils - 1\n ime = ile + 1\n\n allocate(h(ims:ime)[*])\n allocate(u(ims:ime)[*])\n allocate(hmean(ims:ime))\n\n allocate(gather(grid_size)[*])\n\n ! initialize a gaussian blob centered at i = 25\n do i = is - 1, ie + 1\n h(i-is+1) = exp(-decay * (i - ipos)**2)\n end do\n\n ! set initial velocity and mean water depth\n u = 0\n hmean = 10\n\n ! gather to image 1 and write current state to screen\n gather(is:ie)[1] = h(ils:ile)\n sync all\n if (this_image() == 1) print *, 0, gather\n\n time_loop: do n = 1, num_time_steps\n\n ! update halo for h\n h(ime)[left] = h(ils)\n h(ims)[right] = h(ile)\n sync all\n\n ! compute u at next time step\n u = u - (u * diff(u) + g * diff(h)) / dx * dt\n\n sync all\n\n ! update halo for u\n u(ime)[left] = u(ils)\n u(ims)[right] = u(ile)\n sync all\n\n ! compute h at next time step\n h = h - diff(u * (hmean + h)) / dx * dt\n\n ! gather to image 1 and write current state to screen\n gather(is:ie)[1] = h(ils:ile)\n sync all\n if (this_image() == 1) print *, n, gather\n\n end do time_loop\n\nend program tsunami\n", "meta": {"hexsha": "4c8b18928923566b985943d77c29059c2c83fbc4", "size": 2661, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/ch07/tsunami.f90", "max_stars_repo_name": "AAGAN/tsunami", "max_stars_repo_head_hexsha": "82635516dcb7f85eb6434ffdb98a9ddc4c1403ad", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-03-13T07:53:57.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-25T01:42:37.000Z", "max_issues_repo_path": "src/ch07/tsunami.f90", "max_issues_repo_name": "AAGAN/tsunami", "max_issues_repo_head_hexsha": "82635516dcb7f85eb6434ffdb98a9ddc4c1403ad", "max_issues_repo_licenses": ["MIT"], "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/ch07/tsunami.f90", "max_forks_repo_name": "AAGAN/tsunami", "max_forks_repo_head_hexsha": "82635516dcb7f85eb6434ffdb98a9ddc4c1403ad", "max_forks_repo_licenses": ["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.8691588785, "max_line_length": 75, "alphanum_fraction": 0.6260804209, "num_tokens": 857, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267762381844, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6657764402113159}} {"text": " K = N/2\n MEDIAN = FINDELEMENT(K + 1,A,N)\n IF (MOD(N,2).EQ.0) MEDIAN = (FINDELEMENT(K,A,N) + MEDIAN)/2\n", "meta": {"hexsha": "ee070ca3ad3e510fcfdc9b1bc6a62b882457e017", "size": 118, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Averages-Median/Fortran/averages-median-2.f", "max_stars_repo_name": "mullikine/RosettaCodeData", "max_stars_repo_head_hexsha": "4f0027c6ce83daa36118ee8b67915a13cd23ab67", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Averages-Median/Fortran/averages-median-2.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Averages-Median/Fortran/averages-median-2.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 29.5, "max_line_length": 65, "alphanum_fraction": 0.5169491525, "num_tokens": 50, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.868826769445233, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6657764350059203}} {"text": "module solvers\n implicit none\n integer, parameter :: wp = selected_real_kind(15,307)\n real(wp), parameter :: pi = 3.141592653d0\n real(wp), parameter :: nu = 0.005d0\n real(wp), parameter :: CFL = 0.3d0\n integer, parameter :: nx = 400\n real(wp), allocatable :: ts(:)\n real(wp) :: dx, dt, C, dxi, dtp, dta\n \n contains\n !> @brief initialize the distribution\n subroutine initialize(x,u)\n real(wp), dimension(0:nx+1), intent(out) :: x, u\n real(wp) :: nn\n integer :: i, N\n \n dx = 1d0/real(nx - 1)\n dxi = 1d0/dx\n x(1) = 0d0; x(0) = x(1) - dx\n do i=2,nx+1\n x(i) = x(i-1) + dx\n enddo\n \n do i=0,nx+1\n u(i) = sin(pi*x(i))\n enddo\n \n dt = CFL*dx*dx\n print *,\"Parameters:\"\n print *,\" dx:\",dx\n print *,\" dt:\",dt\n print *,\" cfl:\",dt/dx/dx\n \n! compute STS substeps\n dtp = dt\n dta = CFL*dx\n \n nn = FindRoot(1d0, dtp, dta)\n N = int(nn) + 1\n allocate(ts(N))\n dtp = CorrectTimeStep(N, dta)\n CALL ComputeSubSteps(dtp, ts)\n end subroutine initialize\n \n !> @brief Compute Crank-Nicolson step\n subroutine crank(t,x,u)\n real(wp), intent(in) :: t\n real(wp), dimension(0:nx+1), intent(in) :: x\n real(wp), dimension(0:nx+1), intent(inout) :: u\n real(wp), dimension(1:nx) :: a, b, c, d, un\n real(wp) :: r\n integer :: i\n \n r = dta*dxi*dxi;\n do i=1,nx\n a(i) = -r/2d0\n b(i) = 1d0 + r\n c(i) = -r/2d0\n d(i) = u(i)*(1d0 - r) + (0.5d0*r)*(u(i+1) + u(i-1))\n enddo\n \n call tridiag(a,b,c,d,un)\n u(1:nx) = un(1:nx)\n call bc(t+dta,x,u)\n \n end subroutine crank\n \n !> @brief Tridiagonal matrix solver algorithm\n subroutine tridiag(a,b,c,d,un)\n real(wp), dimension(1:nx), intent(in) :: a,b,c,d\n real(wp), dimension(1:nx), intent(out) :: un\n real(wp), dimension(1:nx) :: dp, cp\n real(wp) :: m\n integer :: i\n! initialize c' and d'\n cp(1) = c(1)/b(1)\n dp(1) = d(1)/b(1)\n! upwards sweep\n do i=2,nx\n m = b(i) - cp(i-1)*a(i)\n cp(i) = c(i)/m\n dp(i) = (d(i) - dp(i-1)*a(i))/m\n enddo\n! downwards sweep\n un(nx) = dp(nx)\n do i=nx-1,1,-1\n un(i) = dp(i) - cp(i)*un(i+1)\n enddo\n end subroutine tridiag\n\n !> @brief Compute heat equation using super time-stepping algorithm\n subroutine super(t,x,u)\n real(wp), intent(in) :: t\n real(wp), dimension(0:nx+1), intent(in) :: x\n real(wp), dimension(0:nx+1), intent(inout) :: u\n real(wp), dimension(0:nx+1) :: un, up, phi\n real(wp) :: tau, r, tstep\n integer :: i, m\n \n tstep = t\n phi = 0d0; un = u\n do m=1,N\n tau = ts(m)\n r = tau*dxi\n tstep = tstep + tau\n! compute grad(u) using backwards difference\n do i=1,nx+1\n phi(i) = (up(i) - up(i-1))*dxi\n enddo\n! compute u(n+1) using forwards difference\n! - this is effectively a Lax-Wendroff method for parabolic methods\n do i=1,nx\n un(i) = un(i) + r*(phi(i+1) - phi(i))\n enddo\n call bc(tstep,x,un)\n enddo\n u(1:150) = un(1:150)\n end subroutine super\n \n !> @brief Determines optimal number of STS substeps\n function FindRoot(x0, dtr, dta) result(NS)\n real(wp), intent(in) :: x0, dtr, dta\n real(wp) :: NS, a, b, c, N1, rt_nu\n \n NS = x0 + 1d0\n N1 = x0\n rt_nu = sqrt(nu)\n do while(abs(NS - N1) >= 1d-5)\n NS = N1\n a = (1d0 - rt_nu)/(1d0 + rt_nu)\n b = a**(2d0*NS)\n c = (1d0 - b)/(1d0 + b)\n N1 = NS + (dta - dtr*NS/(2d0*rt_nu)*c)/(dtr/(2d0*rt_nu)*(c - 2d0*NS*b*log(a)*(1d0+c)/(1d0+b)))\n enddo\n end function FindRoot\n \n !> @brief Corrects the parabolic time step for use in STS method\n pure function CorrectTimeStep(n0, dta) result(dtr)\n integer, intent(in) :: n0\n real(wp), intent(in) :: dta\n real(wp) :: a, b, c, dtr, rt_nu\n \n rt_nu = sqrt(nu)\n a = (1d0 - rt_nu)/(1d0 + rt_nu)\n b = a**(2*n0)\n c = (1d0 - b)/(1d0 + b)\n dtr = dta*2d0*rt_nu/(n0*c)\n end function CorrectTimeStep\n \n !> @brief Determines the substeps for STS method\n subroutine ComputeSubSteps(dtex, tau)\n real(wp), intent(in) :: dtex\n real(wp), intent(out) :: tau(:)\n real(wp) :: s\n integer :: j\n \n s = real(size(tau))\n do j=1,size(tau)\n tau(j) = dtex / ((-1d0 + nu)*cos(((2d0*j - 1d0)*pi)/(2d0*s)) + 1d0 + nu);\n enddo\n end subroutine ComputeSubSteps\n \n !> @brief Adjusts the boundary conditions\n subroutine bc(t,x,u)\n real(wp), intent(in) :: t\n real(wp), dimension(0:nx+1), intent(in) :: x\n real(wp), dimension(0:nx+1), intent(inout) :: u\n \n u(0) = sin(pi*x(0))*exp(-pi*pi*t)\n u(nx+1) = sin(pi*x(nx+1))*exp(-pi*pi*t)\n end subroutine\n\nend module solvers\n", "meta": {"hexsha": "50b5a609b699c16c6d3ae5f472492dfebb7fffc7", "size": 4815, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "solvers.f90", "max_stars_repo_name": "jwood983/Diffusion1D", "max_stars_repo_head_hexsha": "621f67ba93f6d096d2f82879bf60d272dc9a2e4b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "solvers.f90", "max_issues_repo_name": "jwood983/Diffusion1D", "max_issues_repo_head_hexsha": "621f67ba93f6d096d2f82879bf60d272dc9a2e4b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "solvers.f90", "max_forks_repo_name": "jwood983/Diffusion1D", "max_forks_repo_head_hexsha": "621f67ba93f6d096d2f82879bf60d272dc9a2e4b", "max_forks_repo_licenses": ["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.5142857143, "max_line_length": 102, "alphanum_fraction": 0.5204569055, "num_tokens": 1770, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.888758793492457, "lm_q2_score": 0.7490872187162397, "lm_q1q2_score": 0.6657578527268655}} {"text": "C\nC\t$Id: rgbyiq.f,v 1.7 2008-07-27 00:16:54 haley Exp $\nC \nC Copyright (C) 2000\nC University Corporation for Atmospheric Research\nC All Rights Reserved\nC\nC The use of this Software is governed by a License Agreement.\nC\n SUBROUTINE RGBYIQ ( R, G, B, Y, I, Q )\nC\nC_BEGIN PROLOGUE RGBYIQ\nC\nC_PURPOSE\nC This subroutine converts a color specification given as\nC Red, Green, and Blue intensity values to a color specification\nC in the YIQ color space.\nC\nC_DESCRIPTION\nC This subroutine converts color values given in the\nC Red, Green, Blue (RGB) color space to color values\nC in the YIQ color space. The input Red, Green,\nC and Blue values are intensities in the range [0.,1.] .\nC\nC_ARGUMENTS\nC\nC R (INPUT,SINGLE,VARIABLE) A real variable in the range\nC [0.,1.] which represents the red intensity component\nC of the input point in RGB color space.\nC\nC G (INPUT,SINGLE,VARIABLE) A real variable in the range\nC [0.,1.] which represents the green intensity component\nC of the input point in RGB color space.\nC\nC B (INPUT,SINGLE,VARIABLE) A real variable in the range\nC [0.,1.] which represents the blue intensity component\nC of the input point in RGB color space.\nC\nC Y (OUTPUT,SINGLE,VARIABLE) A real variable in the range\nC [0.,1.] . Y is the color component of a television\nC signal which is shown on black-and-white televisions;\nC Y minimizes the effect of two colors appearing different\nC to the human eye but mapping to similar monochrome\nC intensities.\nC\nC I (OUTPUT,SINGLE,VARIABLE) A real variable in the range\nC [-.6,.6] . I attains its maximum when the input triple\nC is (1.,0.,0.); I attains its minimum when the input triple\nC is (0.,1.,1.) .\nC\nC Q (OUTPUT,SINGLE,VARIABLE) A real variable in the range\nC [-.52,.52]. Q attains its maximum when the input triple\nC is (1.,0.,1.); Q attains its minimum when the input triple\nC is (0.,1.,0.).\nC\nC_I/O\nC (NONE)\nC\nC_ROUTINES CALLED\nC (NONE)\nC\nC_COMMON BLOCKS\nC (NONE)\nC\nC_MAXIMUM GKS LEVEL\nC (NONE)\nC\nC_LANGUAGE\nC FORTRAN\nC\nC_REVISION DATE\nC 880511 (YYMMDD)\nC\nC_HISTORY\nC This subroutine was originally coded and prepared for the\nC NCAR Graphics package by Fred Clare based on algorithms\nC in Foley and van Dam (see REFERENCES below).\nC\nC_REFERENCES\nC Foley, James D. and van Dam, Andries,\"Fundamentals of Interactive\nC Computer Graphics\",Addison-Wesley Publishing Company, 1982.\nC\nC_EXAMPLES\nC Example 1 -- Full white to YIQ.\nC SUBROUTINE TYIQ1\nC REAL Y,I,Q,EPS\nC PARAMETER (EPS=0.01)\nC CALL RGBYIQ(1.,1.,1.,Y,I,Q)\nC IF ( (ABS(Y-1.) .GT. EPS) .OR. (ABS(I) .GT. EPS) .OR.\nC * (ABS(Q) .GT. EPS) ) THEN\nC IUN = I1MACH(4)\nC WRITE(IUN,10)\nC ENDIF\nC RETURN\nC 10 FORMAT(' TYIQ1 returned incorrect values')\nC END\nC\nC_END PROLOGUE RGBYIQ\nC\n REAL R,G,B,Y,I,Q\nC\nC_FIRST EXECUTABLE STATEMENT RGBYIQ\n Y = 0.2988922*R + 0.5870147*G + 0.1140931*B\n I = 0.5960695*R - 0.2743087*G - 0.3217608*B\n Q = 0.2113775*R - 0.5229881*G + 0.3116106*B\nC\n RETURN\n END\n", "meta": {"hexsha": "cc148c6615457c86737f771210eea2041c0ac908", "size": 3386, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ncarg2d/src/libncarg/colconv/rgbyiq.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "ncarg2d/src/libncarg/colconv/rgbyiq.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "ncarg2d/src/libncarg/colconv/rgbyiq.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 31.0642201835, "max_line_length": 71, "alphanum_fraction": 0.6290608387, "num_tokens": 1030, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587846530938, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.6657578411270182}} {"text": " SUBROUTINE slAV2M (AXVEC, RMAT)\n*+\n* - - - - -\n* A V 2 M\n* - - - - -\n*\n* Form the rotation matrix corresponding to a given axial vector.\n*\n* (single precision)\n*\n* A rotation matrix describes a rotation about some arbitrary axis,\n* called the Euler axis. The \"axial vector\" supplied to this routine\n* has the same direction as the Euler axis, and its magnitude is the\n* amount of rotation in radians.\n*\n* Given:\n* AXVEC r(3) axial vector (radians)\n*\n* Returned:\n* RMAT r(3,3) rotation matrix\n*\n* If AXVEC is null, the unit matrix is returned.\n*\n* The reference frame rotates clockwise as seen looking along\n* the axial vector from the origin.\n*\n* Last revision: 26 November 2005\n*\n* Copyright P.T.Wallace. All rights reserved.\n*\n* License:\n* This program is free software; you can redistribute it and/or modify\n* it under the terms of the GNU General Public License as published by\n* the Free Software Foundation; either version 2 of the License, or\n* (at your option) any later version.\n*\n* This program is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU General Public License for more details.\n*\n* You should have received a copy of the GNU General Public License\n* along with this program (see SLA_CONDITIONS); if not, write to the\n* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,\n* Boston, MA 02110-1301 USA\n*\n* Copyright (C) 1995 Association of Universities for Research in Astronomy Inc.\n*-\n\n IMPLICIT NONE\n\n REAL AXVEC(3),RMAT(3,3)\n\n REAL X,Y,Z,PHI,S,C,W\n\n\n\n* Rotation angle - magnitude of axial vector - and functions\n X = AXVEC(1)\n Y = AXVEC(2)\n Z = AXVEC(3)\n PHI = SQRT(X*X+Y*Y+Z*Z)\n S = SIN(PHI)\n C = COS(PHI)\n W = 1.0-C\n\n* Euler axis - direction of axial vector (perhaps null)\n IF (PHI.NE.0.0) THEN\n X = X/PHI\n Y = Y/PHI\n Z = Z/PHI\n END IF\n\n* Compute the rotation matrix\n RMAT(1,1) = X*X*W+C\n RMAT(1,2) = X*Y*W+Z*S\n RMAT(1,3) = X*Z*W-Y*S\n RMAT(2,1) = X*Y*W-Z*S\n RMAT(2,2) = Y*Y*W+C\n RMAT(2,3) = Y*Z*W+X*S\n RMAT(3,1) = X*Z*W+Y*S\n RMAT(3,2) = Y*Z*W-X*S\n RMAT(3,3) = Z*Z*W+C\n\n END\n", "meta": {"hexsha": "69dab51055f493639bf8072eb6fa3dac436d213d", "size": 2372, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iraf.v2161/math/slalib/av2m.f", "max_stars_repo_name": "ysBach/irafdocgen", "max_stars_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:19:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T16:48:42.000Z", "max_issues_repo_path": "math/slalib/av2m.f", "max_issues_repo_name": "kirxkirx/iraf", "max_issues_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-30T13:48:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-02T19:40:25.000Z", "max_forks_repo_path": "math/slalib/av2m.f", "max_forks_repo_name": "kirxkirx/iraf", "max_forks_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.5813953488, "max_line_length": 80, "alphanum_fraction": 0.6264755481, "num_tokens": 756, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587817066391, "lm_q2_score": 0.7490872131147276, "lm_q1q2_score": 0.6657578389198668}} {"text": "!===============================================================================\n!\n! Module:\n!\n! so32su2 By Meng Wu\n!\n! Find one of the U(2) matrix corresponding to a O(3) rotation\n!\n! ==============================================\n\n#include \"f_defs.h\"\n\nmodule so32su2_m\n use global_m\n\n implicit none\n private\n public :: so32su2\n\ncontains\n\n subroutine so32su2(Rmatrix, umatrix)\n real(DP), dimension(3,3) :: Rmatrix ! cartesian coordinates\n ! LatVec(1:3,1:3) is the lattice vectors in cartesian coordinates\n ! LatVec(1:3,i) is the i-th lattice vector\n ! umatrix(1:2,1:2) is the U(2) matrix corresponding to the Rmatrix O(3) rotation\n complex(DPC), dimension(2,2), intent(out) :: umatrix\n ! eps10 is a small number\n real(DP), parameter :: eps10 = 1.0D-10\n ! imaginary unit, (0+1j)\n complex(DPC), parameter :: ii=(0,1)\n real(DP) :: alpha, beta, gamma\n real(DP), parameter :: Pi = 3.14159265358979323846\n real(DP) :: sinbeta, Rdet\n ! for proper rotation: ifprop = .true.\n ! for improper rotation: ifprop = .false.\n logical :: ifprop = .true.\n\n ! ------------------------------------\n ! Calculate determinant of Rmatrix(i,j)\n Rdet = Rmatrix(1,1)*(Rmatrix(2,2)*Rmatrix(3,3) - Rmatrix(3,2)*Rmatrix(2,3)) &\n + Rmatrix(1,2)*(Rmatrix(3,1)*Rmatrix(2,3) - Rmatrix(2,1)*Rmatrix(3,3)) &\n + Rmatrix(1,3)*(Rmatrix(2,1)*Rmatrix(3,2) - Rmatrix(3,1)*Rmatrix(2,2))\n\n if (abs(Rdet-1.0) < eps10) then\n ! 'Proper rotation'\n ifprop = .true.\n\n elseif (abs(Rdet+1.0) < eps10) then\n ! 'Improper rotation'\n ifprop = .false.\n Rmatrix = - Rmatrix\n else\n write(*,*) 'Error in so32su2()!!!'\n call EXIT(1)\n endif\n\n if (abs(Rmatrix(3,3)-1.0) < eps10) then\n beta = 0\n gamma = 0\n alpha = atan2(Rmatrix(2,1),Rmatrix(1,1))\n elseif (abs(Rmatrix(3,3)+1.0) < eps10) THEN\n beta = Pi;\n gamma = 0;\n alpha = - atan2(Rmatrix(1,2),Rmatrix(2,2))\n else\n sinbeta=sqrt(1-Rmatrix(3,3)*Rmatrix(3,3));\n beta=atan2(sinbeta,Rmatrix(3,3));\n alpha=atan2(Rmatrix(2,3)/sinbeta,Rmatrix(1,3)/sinbeta);\n gamma=atan2(Rmatrix(3,2)/sinbeta,-Rmatrix(3,1)/sinbeta);\n endif\n\n umatrix(1,1) = exp(-ii*(alpha+gamma)/2.0)*cos(beta/2.0)\n umatrix(1,2) = -exp(-ii*(alpha-gamma)/2.0)*sin(beta/2.0)\n umatrix(2,1) = exp(ii*(alpha-gamma)/2.0)*sin(beta/2.0)\n umatrix(2,2) = exp(ii*(alpha+gamma)/2.0)*cos(beta/2.0)\n\n ! if we have improper rotation, we need to multiply the umatrix by {{i,0},{i,0}}\n if (ifprop .eqv. .false.) then\n ! we have I [spinor] = \\pm spinor\n ! take +1 as prefactor will not change the value of matrix elements\n ! umatrix = ii*umatrix\n umatrix = umatrix\n endif\n\n end subroutine so32su2\n\nend module so32su2_m\n", "meta": {"hexsha": "9e1bb54a618032067d71c832693b872d24627e24", "size": 2804, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/so32su2.f90", "max_stars_repo_name": "wu2meng3/DielectricKit", "max_stars_repo_head_hexsha": "24bad0ccfa4af8ce48632cfacb182289fc4739e7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-09-29T06:57:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-31T03:52:15.000Z", "max_issues_repo_path": "src/so32su2.f90", "max_issues_repo_name": "wu2meng3/DielectricKit", "max_issues_repo_head_hexsha": "24bad0ccfa4af8ce48632cfacb182289fc4739e7", "max_issues_repo_licenses": ["MIT"], "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/so32su2.f90", "max_forks_repo_name": "wu2meng3/DielectricKit", "max_forks_repo_head_hexsha": "24bad0ccfa4af8ce48632cfacb182289fc4739e7", "max_forks_repo_licenses": ["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.5056179775, "max_line_length": 84, "alphanum_fraction": 0.567403709, "num_tokens": 965, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995482, "lm_q2_score": 0.7490872075132152, "lm_q1q2_score": 0.6657578383557763}} {"text": " SUBROUTINE SB03MW( LTRAN, LUPPER, T, LDT, B, LDB, SCALE, X, LDX,\n $ XNORM, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To solve for the 2-by-2 symmetric matrix X in\nC\nC op(T)'*X + X*op(T) = SCALE*B,\nC\nC where T is 2-by-2, B is symmetric 2-by-2, and op(T) = T or T',\nC where T' denotes the transpose of T.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC LTRAN LOGICAL\nC Specifies the form of op(T) to be used, as follows:\nC = .FALSE.: op(T) = T,\nC = .TRUE. : op(T) = T'.\nC\nC LUPPER LOGICAL\nC Specifies which triangle of the matrix B is used, and\nC which triangle of the matrix X is computed, as follows:\nC = .TRUE. : The upper triangular part;\nC = .FALSE.: The lower triangular part.\nC\nC Input/Output Parameters\nC\nC T (input) DOUBLE PRECISION array, dimension (LDT,2)\nC The leading 2-by-2 part of this array must contain the\nC matrix T.\nC\nC LDT INTEGER\nC The leading dimension of array T. LDT >= 2.\nC\nC B (input) DOUBLE PRECISION array, dimension (LDB,2)\nC On entry with LUPPER = .TRUE., the leading 2-by-2 upper\nC triangular part of this array must contain the upper\nC triangular part of the symmetric matrix B and the strictly\nC lower triangular part of B is not referenced.\nC On entry with LUPPER = .FALSE., the leading 2-by-2 lower\nC triangular part of this array must contain the lower\nC triangular part of the symmetric matrix B and the strictly\nC upper triangular part of B is not referenced.\nC\nC LDB INTEGER\nC The leading dimension of array B. LDB >= 2.\nC\nC SCALE (output) DOUBLE PRECISION\nC The scale factor. SCALE is chosen less than or equal to 1\nC to prevent the solution overflowing.\nC\nC X (output) DOUBLE PRECISION array, dimension (LDX,2)\nC On exit with LUPPER = .TRUE., the leading 2-by-2 upper\nC triangular part of this array contains the upper\nC triangular part of the symmetric solution matrix X and the\nC strictly lower triangular part of X is not referenced.\nC On exit with LUPPER = .FALSE., the leading 2-by-2 lower\nC triangular part of this array contains the lower\nC triangular part of the symmetric solution matrix X and the\nC strictly upper triangular part of X is not referenced.\nC Note that X may be identified with B in the calling\nC statement.\nC\nC LDX INTEGER\nC The leading dimension of array X. LDX >= 2.\nC\nC XNORM (output) DOUBLE PRECISION\nC The infinity-norm of the solution.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC = 1: if T and -T have too close eigenvalues, so T\nC is perturbed to get a nonsingular equation.\nC\nC NOTE: In the interests of speed, this routine does not\nC check the inputs for errors.\nC\nC METHOD\nC\nC The equivalent linear algebraic system of equations is formed and\nC solved using Gaussian elimination with complete pivoting.\nC\nC REFERENCES\nC\nC [1] Anderson, E., Bai, Z., Bischof, C., Demmel, J., Dongarra, J.,\nC Du Croz, J., Greenbaum, A., Hammarling, S., McKenney, A.,\nC Ostrouchov, S., and Sorensen, D.\nC LAPACK Users' Guide: Second Edition.\nC SIAM, Philadelphia, 1995.\nC\nC NUMERICAL ASPECTS\nC\nC The algorithm is stable and reliable, since Gaussian elimination\nC with complete pivoting is used.\nC\nC CONTRIBUTOR\nC\nC Release 3.0: V. Sima, Katholieke Univ. Leuven, Belgium, May 1997.\nC Based on DLALY2 by P. Petkov, Tech. University of Sofia, September\nC 1993.\nC\nC REVISIONS\nC\nC -\nC\nC KEYWORDS\nC\nC Continuous-time system, Lyapunov equation, matrix algebra.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, ONE, TWO, FOUR\n PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0, TWO = 2.0D+0,\n $ FOUR = 4.0D+0 )\nC ..\nC .. Scalar Arguments ..\n LOGICAL LTRAN, LUPPER\n INTEGER INFO, LDB, LDT, LDX\n DOUBLE PRECISION SCALE, XNORM\nC ..\nC .. Array Arguments ..\n DOUBLE PRECISION B( LDB, * ), T( LDT, * ), X( LDX, * )\nC ..\nC .. Local Scalars ..\n INTEGER I, IP, IPSV, J, JP, JPSV, K\n DOUBLE PRECISION EPS, SMIN, SMLNUM, TEMP, XMAX\nC ..\nC .. Local Arrays ..\n INTEGER JPIV( 3 )\n DOUBLE PRECISION BTMP( 3 ), T9( 3, 3 ), TMP( 3 )\nC ..\nC .. External Functions ..\n DOUBLE PRECISION DLAMCH\n EXTERNAL DLAMCH\nC ..\nC .. External Subroutines ..\n EXTERNAL DSWAP\nC ..\nC .. Intrinsic Functions ..\n INTRINSIC ABS, MAX\nC ..\nC .. Executable Statements ..\nC\nC Do not check the input parameters for errors\nC\n INFO = 0\nC\nC Set constants to control overflow\nC\n EPS = DLAMCH( 'P' )\n SMLNUM = DLAMCH( 'S' ) / EPS\nC\nC Solve equivalent 3-by-3 system using complete pivoting.\nC Set pivots less than SMIN to SMIN.\nC\n SMIN = MAX( MAX( ABS( T( 1, 1 ) ), ABS( T( 1, 2 ) ),\n $ ABS( T( 2, 1 ) ), ABS( T( 2, 2 ) ) )*EPS,\n $ SMLNUM )\n T9( 1, 3 ) = ZERO\n T9( 3, 1 ) = ZERO\n T9( 1, 1 ) = T( 1, 1 )\n T9( 2, 2 ) = T( 1, 1 ) + T( 2, 2 )\n T9( 3, 3 ) = T( 2, 2 )\n IF( LTRAN ) THEN\n T9( 1, 2 ) = T( 1, 2 )\n T9( 2, 1 ) = T( 2, 1 )\n T9( 2, 3 ) = T( 1, 2 )\n T9( 3, 2 ) = T( 2, 1 )\n ELSE\n T9( 1, 2 ) = T( 2, 1 )\n T9( 2, 1 ) = T( 1, 2 )\n T9( 2, 3 ) = T( 2, 1 )\n T9( 3, 2 ) = T( 1, 2 )\n END IF\n BTMP( 1 ) = B( 1, 1 )/TWO\n IF ( LUPPER ) THEN\n BTMP( 2 ) = B( 1, 2 )\n ELSE\n BTMP( 2 ) = B( 2, 1 )\n END IF\n BTMP( 3 ) = B( 2, 2 )/TWO\nC\nC Perform elimination\nC\n DO 50 I = 1, 2\n XMAX = ZERO\nC\n DO 20 IP = I, 3\nC\n DO 10 JP = I, 3\n IF( ABS( T9( IP, JP ) ).GE.XMAX ) THEN\n XMAX = ABS( T9( IP, JP ) )\n IPSV = IP\n JPSV = JP\n END IF\n 10 CONTINUE\nC\n 20 CONTINUE\nC\n IF( IPSV.NE.I ) THEN\n CALL DSWAP( 3, T9( IPSV, 1 ), 3, T9( I, 1 ), 3 )\n TEMP = BTMP( I )\n BTMP( I ) = BTMP( IPSV )\n BTMP( IPSV ) = TEMP\n END IF\n IF( JPSV.NE.I )\n $ CALL DSWAP( 3, T9( 1, JPSV ), 1, T9( 1, I ), 1 )\n JPIV( I ) = JPSV\n IF( ABS( T9( I, I ) ).LT.SMIN ) THEN\n INFO = 1\n T9( I, I ) = SMIN\n END IF\nC\n DO 40 J = I + 1, 3\n T9( J, I ) = T9( J, I ) / T9( I, I )\n BTMP( J ) = BTMP( J ) - T9( J, I )*BTMP( I )\nC\n DO 30 K = I + 1, 3\n T9( J, K ) = T9( J, K ) - T9( J, I )*T9( I, K )\n 30 CONTINUE\nC\n 40 CONTINUE\nC\n 50 CONTINUE\nC\n IF( ABS( T9( 3, 3 ) ).LT.SMIN )\n $ T9( 3, 3 ) = SMIN\n SCALE = ONE\n IF( ( FOUR*SMLNUM )*ABS( BTMP( 1 ) ).GT.ABS( T9( 1, 1 ) ) .OR.\n $ ( FOUR*SMLNUM )*ABS( BTMP( 2 ) ).GT.ABS( T9( 2, 2 ) ) .OR.\n $ ( FOUR*SMLNUM )*ABS( BTMP( 3 ) ).GT.ABS( T9( 3, 3 ) ) ) THEN\n SCALE = ( ONE / FOUR ) / MAX( ABS( BTMP( 1 ) ),\n $ ABS( BTMP( 2 ) ), ABS( BTMP( 3 ) ) )\n BTMP( 1 ) = BTMP( 1 )*SCALE\n BTMP( 2 ) = BTMP( 2 )*SCALE\n BTMP( 3 ) = BTMP( 3 )*SCALE\n END IF\nC\n DO 70 I = 1, 3\n K = 4 - I\n TEMP = ONE / T9( K, K )\n TMP( K ) = BTMP( K )*TEMP\nC\n DO 60 J = K + 1, 3\n TMP( K ) = TMP( K ) - ( TEMP*T9( K, J ) )*TMP( J )\n 60 CONTINUE\nC\n 70 CONTINUE\nC\n DO 80 I = 1, 2\n IF( JPIV( 3-I ).NE.3-I ) THEN\n TEMP = TMP( 3-I )\n TMP( 3-I ) = TMP( JPIV( 3-I ) )\n TMP( JPIV( 3-I ) ) = TEMP\n END IF\n 80 CONTINUE\nC\n X( 1, 1 ) = TMP( 1 )\n IF ( LUPPER ) THEN\n X( 1, 2 ) = TMP( 2 )\n ELSE\n X( 2, 1 ) = TMP( 2 )\n END IF\n X( 2, 2 ) = TMP( 3 )\n XNORM = MAX( ABS( TMP( 1 ) ) + ABS( TMP( 2 ) ),\n $ ABS( TMP( 2 ) ) + ABS( TMP( 3 ) ) )\nC\n RETURN\nC *** Last line of SB03MW ***\n END\n", "meta": {"hexsha": "a52571c86d614106758c6a21e3aa2515cec3f3d0", "size": 8614, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/SB03MW.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/SB03MW.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/SB03MW.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 30.7642857143, "max_line_length": 72, "alphanum_fraction": 0.4922219642, "num_tokens": 2953, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9263037363973294, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6656366763749424}} {"text": "module linalg\n use types, only: dp\n use lapack, only: dsyevd, dsygvd, ilaenv, zgetri, zgetrf, zheevd, &\n dgeev, zgeev, zhegvd, dgesv, zgesv, dgetrf, dgetri, dgelsy, zgelsy, &\n dgesvd, zgesvd\n use utils, only: stop_error\n use constants, only: i_\n implicit none\n private\n public eig, eigvals, eigh, inv, solve, eye, det, lstsq, diag, trace, &\n svdvals, svd\n\n ! eigenvalue/-vector problem for general matrices:\n interface eig\n module procedure deig\n module procedure zeig\n end interface eig\n\n ! eigenvalue/-vector problem for real symmetric/complex hermitian matrices:\n interface eigh\n module procedure deigh_generalized\n module procedure deigh_simple\n module procedure zeigh_generalized\n module procedure zeigh_simple\n end interface eigh\n\n ! eigenvalues for general matrices:\n interface eigvals\n module procedure deigvals\n module procedure zeigvals\n end interface eigvals\n\n ! matrix inversion for real/complex matrices:\n interface inv\n module procedure dinv\n module procedure zinv\n end interface inv\n\n ! solution to linear systems of equation with real/complex coefficients:\n interface solve\n module procedure dsolve\n module procedure zsolve\n end interface solve\n\n ! determinants of real/complex square matrices:\n interface det\n module procedure ddet\n module procedure zdet\n end interface det\n\n ! least square solutions the real/complex systems of equations of possibly non-square shape:\n interface lstsq\n module procedure dlstsq\n module procedure zlstsq\n end interface lstsq\n\n ! construction of square matrices from the diagonal elements:\n interface diag\n module procedure ddiag\n module procedure zdiag\n end interface diag\n\n ! trace of real/complex matrices:\n interface trace\n module procedure dtrace\n module procedure ztrace\n end interface trace\n\n ! singular values of real/complex matrices:\n interface svdvals\n module procedure dsvdvals\n module procedure zsvdvals\n end interface svdvals\n\n ! singular value decomposition of real/complex matrices:\n interface svd\n module procedure dsvd\n module procedure zsvd\n end interface svd\n\n ! assert shape of matrices:\n interface assert_shape\n module procedure dassert_shape\n module procedure zassert_shape\n end interface assert_shape\n\ncontains\n\n ! TODO: add optional switch for left or right eigenvectors in deig() and zeig()?\n subroutine deig(A, lam, c)\n real(dp), intent(in) :: A(:, :) ! matrix for eigenvalue compuation\n complex(dp), intent(out) :: lam(:) ! eigenvalues: A c = lam c\n complex(dp), intent(out) :: c(:, :) ! eigenvectors: A c = lam c; c(i,j) = ith component of jth vec.\n ! LAPACK variables for DGEEV:\n real(dp), allocatable :: At(:,:), vl(:,: ), vr(:,:), wi(:), work(:), wr(:)\n integer :: info, lda, ldvl, ldvr, lwork, n, i\n\n lda = size(A(:,1))\n n = size(A(1,:))\n call assert_shape(A, [n, n], \"solve\", \"A\")\n call assert_shape(c, [n, n], \"solve\", \"c\")\n ldvl = n\n ldvr = n\n lwork = 8*n ! TODO: can this size be optimized? query first?\n allocate(At(lda,n), wr(n), wi(n), vl(ldvl,n), vr(ldvr,n), work(lwork))\n At = A\n\n call dgeev('N', 'V', n, At, lda, wr, wi, vl, ldvl, vr, ldvr, &\n work, lwork, info)\n if(info /= 0) then\n print *, \"dgeev returned info = \", info\n if (info < 0) then\n print *, \"the\", -info, \"-th argument had an illegal value\"\n else\n print *, \"the QR algorithm failed to compute all the\"\n print *, \"eigenvalues, and no eigenvectors have been computed;\"\n print *, \"elements \", info+1, \":\", n, \"of WR and WI contain eigenvalues which\"\n print *, \"have converged.\"\n end if\n call stop_error('eig: dgeev error')\n end if\n\n lam = wr + i_*wi\n ! as DGEEV has a rather complicated way of returning the eigenvectors,\n ! it is necessary to build the complex array of eigenvectors from\n ! two real arrays:\n do i = 1,n\n if(wi(i) > 0.0) then ! first of two conjugate eigenvalues\n c(:, i) = vr(:, i) + i_*vr(:, i+1)\n elseif(wi(i) < 0.0_dp) then ! second of two conjugate eigenvalues\n c(:, i) = vr(:, i-1) - i_*vr(:, i)\n else\n c(:, i) = vr(:, i)\n end if\n end do\n end subroutine deig\n\n subroutine zeig(A, lam, c)\n complex(dp), intent(in) :: A(:, :) ! matrix to solve eigenproblem for\n complex(dp), intent(out) :: lam(:) ! eigenvalues: A c = lam c\n complex(dp), intent(out) :: c(:,:) ! eigenvectors: A c = lam c; c(i,j) = ith component of jth vec.\n ! LAPACK variables:\n integer :: info, lda, ldvl, ldvr, lwork, n, lrwork\n real(dp), allocatable :: rwork(:)\n complex(dp), allocatable :: vl(:,:), vr(:,:), work(:)\n\n lda = size(A(:,1))\n n = size(A(1,:))\n call assert_shape(A, [n, n], \"solve\", \"A\")\n call assert_shape(c, [n, n], \"solve\", \"c\")\n ldvl = n\n ldvr = n\n lwork = 8*n ! TODO: can this size be optimized? query first?\n lrwork = 2*n\n allocate(vl(ldvl,n), vr(ldvr,n), work(lwork), rwork(lrwork))\n c = A\n call zgeev('N', 'V', n, c, lda, lam, vl, ldvl, vr, ldvr, work, &\n lwork, rwork, info)\n if(info /= 0) then\n print *, \"zgeev returned info = \", info\n if(info < 0) then\n print *, \"the \",-info, \"-th argument had an illegal value.\"\n else\n print *, \"the QR algorithm failed to compute all the\"\n print *, \"eigenvalues, and no eigenvectors have been computed;\"\n print *, \"elements and \", info+1, \":\", n, \" of W contain eigenvalues which have\"\n print *, \"converged.\"\n end if\n call stop_error('eig: zgeev error')\n end if\n c = vr\n end subroutine zeig\n\n function deigvals(A) result(lam)\n real(dp), intent(in) :: A(:, :) ! matrix for eigenvalue compuation\n complex(dp), allocatable :: lam(:) ! eigenvalues: A c = lam c\n ! LAPACK variables for DGEEV:\n real(dp), allocatable :: At(:,:), vl(:,: ), vr(:,:), wi(:), work(:), wr(:)\n integer :: info, lda, ldvl, ldvr, lwork, n\n\n lda = size(A(:,1))\n n = size(A(1,:))\n call assert_shape(A, [n, n], \"solve\", \"A\")\n ldvl = n\n ldvr = n\n lwork = 8*n ! TODO: can this size be optimized? query first?\n allocate(At(lda,n), wr(n), wi(n), vl(ldvl,n), vr(ldvr,n), work(lwork), lam(n))\n At = A\n\n call dgeev('N', 'N', n, At, lda, wr, wi, vl, ldvl, vr, ldvr, &\n work, lwork, info)\n if(info /= 0) then\n print *, \"dgeev returned info = \", info\n if (info < 0) then\n print *, \"the\", -info, \"-th argument had an illegal value\"\n else\n print *, \"the QR algorithm failed to compute all the\"\n print *, \"eigenvalues, and no eigenvectors have been computed;\"\n print *, \"elements \", info+1, \":\", n, \"of WR and WI contain eigenvalues which\"\n print *, \"have converged.\"\n end if\n call stop_error('eigvals: dgeev error')\n end if\n\n lam = wr + i_*wi\n end function deigvals\n\n function zeigvals(A) result(lam)\n complex(dp), intent(in) :: A(:, :) ! matrix to solve eigenproblem for\n complex(dp), allocatable :: lam(:) ! eigenvalues: A c = lam c\n ! LAPACK variables:\n integer :: info, lda, ldvl, ldvr, lwork, n, lrwork\n real(dp), allocatable :: rwork(:)\n complex(dp), allocatable :: At(:,:), vl(:,:), vr(:,:), work(:)\n\n lda = size(A(:,1))\n n = size(A(1,:))\n call assert_shape(A, [n, n], \"solve\", \"A\")\n ldvl = n\n ldvr = n\n lwork = 8*n ! TODO: can this size be optimized? query first?\n lrwork = 2*n\n allocate(At(lda,n), vl(ldvl,n), vr(ldvr,n), work(lwork), rwork(lrwork), lam(n))\n At = A\n call zgeev('N', 'N', n, At, lda, lam, vl, ldvl, vr, ldvr, work, &\n lwork, rwork, info)\n if(info /= 0) then\n print *, \"zgeev returned info = \", info\n if(info < 0) then\n print *, \"the \",-info, \"-th argument had an illegal value.\"\n else\n print *, \"the QR algorithm failed to compute all the\"\n print *, \"eigenvalues, and no eigenvectors have been computed;\"\n print *, \"elements and \", info+1, \":\", n, \" of W contain eigenvalues which have\"\n print *, \"converged.\"\n end if\n call stop_error('eig: zgeev error')\n end if\n end function zeigvals\n\n subroutine deigh_generalized(Am, Bm, lam, c)\n ! solves generalized eigen value problem for all eigenvalues and eigenvectors\n ! Am must by symmetric, Bm symmetric positive definite.\n ! Only the lower triangular part of Am and Bm is used.\n real(dp), intent(in) :: Am(:,:) ! LHS matrix: Am c = lam Bm c\n real(dp), intent(in) :: Bm(:,:) ! RHS matrix: Am c = lam Bm c\n real(dp), intent(out) :: lam(:) ! eigenvalues: Am c = lam Bm c\n real(dp), intent(out) :: c(:,:) ! eigenvectors: Am c = lam Bm c; c(i,j) = ith component of jth vec.\n integer :: n\n ! lapack variables\n integer :: lwork, liwork, info\n integer, allocatable :: iwork(:)\n real(dp), allocatable :: Bmt(:,:), work(:)\n\n ! solve\n n = size(Am,1)\n call assert_shape(Am, [n, n], \"eigh\", \"Am\")\n call assert_shape(Bm, [n, n], \"eigh\", \"B\")\n call assert_shape(c, [n, n], \"eigh\", \"c\")\n lwork = 1 + 6*n + 2*n**2\n liwork = 3 + 5*n\n allocate(Bmt(n,n), work(lwork), iwork(liwork))\n c = Am; Bmt = Bm ! Bmt temporaries overwritten by dsygvd\n call dsygvd(1,'V','L',n,c,n,Bmt,n,lam,work,lwork,iwork,liwork,info)\n if (info /= 0) then\n print *, \"dsygvd returned info =\", info\n if (info < 0) then\n print *, \"the\", -info, \"-th argument had an illegal value\"\n else if (info <= n) then\n print *, \"the algorithm failed to compute an eigenvalue while working\"\n print *, \"on the submatrix lying in rows and columns\", 1.0_dp*info/(n+1)\n print *, \"through\", mod(info, n+1)\n else\n print *, \"The leading minor of order \", info-n, &\n \"of B is not positive definite. The factorization of B could \", &\n \"not be completed and no eigenvalues or eigenvectors were computed.\"\n end if\n call stop_error('eigh: dsygvd error')\n end if\n end subroutine deigh_generalized\n\n subroutine deigh_simple(Am, lam, c)\n ! solves eigen value problem for all eigenvalues and eigenvectors\n ! Am must by symmetric\n ! Only the lower triangular part of Am is used.\n real(dp), intent(in) :: Am(:,:) ! LHS matrix: Am c = lam c\n real(dp), intent(out) :: lam(:) ! eigenvalues: Am c = lam c\n real(dp), intent(out) :: c(:,:) ! eigenvectors: Am c = lam c; c(i,j) = ith component of jth vec.\n integer :: n\n ! lapack variables\n integer :: lwork, liwork, info\n integer, allocatable :: iwork(:)\n real(dp), allocatable :: work(:)\n\n ! solve\n n = size(Am,1)\n call assert_shape(Am, [n, n], \"eigh\", \"Am\")\n call assert_shape(c, [n, n], \"eigh\", \"c\")\n lwork = 1 + 6*n + 2*n**2\n liwork = 3 + 5*n\n allocate(work(lwork), iwork(liwork))\n c = Am\n call dsyevd('V','L',n,c,n,lam,work,lwork,iwork,liwork,info)\n if (info /= 0) then\n print *, \"dsyevd returned info =\", info\n if (info < 0) then\n print *, \"the\", -info, \"-th argument had an illegal value\"\n else\n print *, \"the algorithm failed to compute an eigenvalue while working\"\n print *, \"on the submatrix lying in rows and columns\", 1.0_dp*info/(n+1)\n print *, \"through\", mod(info, n+1)\n end if\n call stop_error('eigh: dsyevd error')\n end if\n end subroutine deigh_simple\n\n subroutine zeigh_generalized(Am, Bm, lam, c)\n ! solves generalized eigen value problem for all eigenvalues and eigenvectors\n ! Am must by hermitian, Bm hermitian positive definite.\n ! Only the lower triangular part of Am and Bm is used.\n complex(dp), intent(in) :: Am(:,:) ! LHS matrix: Am c = lam Bm c\n complex(dp), intent(in) :: Bm(:,:) ! RHS matrix: Am c = lam Bm c\n real(dp), intent(out) :: lam(:) ! eigenvalues: Am c = lam Bm c\n complex(dp), intent(out) :: c(:,:) ! eigenvectors: Am c = lam Bm c; c(i,j) = ith component of jth vec.\n ! lapack variables\n integer :: info, liwork, lrwork, lwork, n\n integer, allocatable :: iwork(:)\n real(dp), allocatable :: rwork(:)\n complex(dp), allocatable :: Bmt(:,:), work(:)\n\n ! solve\n n = size(Am,1)\n call assert_shape(Am, [n, n], \"eigh\", \"Am\")\n call assert_shape(Bm, [n, n], \"eigh\", \"Bm\")\n call assert_shape(c, [n, n], \"eigh\", \"c\")\n lwork = 2*n + n**2\n lrwork = 1 + 5*N + 2*n**2\n liwork = 3 + 5*n\n allocate(Bmt(n,n), work(lwork), rwork(lrwork), iwork(liwork))\n c = Am; Bmt = Bm ! Bmt temporary overwritten by zhegvd\n call zhegvd(1,'V','L',n,c,n,Bmt,n,lam,work,lwork,rwork,lrwork,iwork,liwork,info)\n if (info /= 0) then\n print *, \"zhegvd returned info =\", info\n if (info < 0) then\n print *, \"the\", -info, \"-th argument had an illegal value\"\n else if (info <= n) then\n print *, \"the algorithm failed to compute an eigenvalue while working\"\n print *, \"on the submatrix lying in rows and columns\", 1.0_dp*info/(n+1)\n print *, \"through\", mod(info, n+1)\n else\n print *, \"The leading minor of order \", info-n, &\n \"of B is not positive definite. The factorization of B could \", &\n \"not be completed and no eigenvalues or eigenvectors were computed.\"\n end if\n call stop_error('eigh: zhegvd error')\n end if\n end subroutine zeigh_generalized\n\n subroutine zeigh_simple(Am, lam, c)\n ! solves eigen value problem for all eigenvalues and eigenvectors\n ! Am must by symmetric\n ! Only the lower triangular part of Am is used.\n complex(dp), intent(in) :: Am(:,:) ! LHS matrix: Am c = lam c\n real(dp), intent(out) :: lam(:) ! eigenvalues: Am c = lam c\n complex(dp), intent(out) :: c(:,:) ! eigenvectors: Am c = lam c; c(i,j) = ith component of jth vec.\n ! LAPACK variables:\n integer :: info, lda, liwork, lrwork, lwork, n\n integer, allocatable :: iwork(:)\n real(dp), allocatable :: rwork(:)\n complex(dp), allocatable :: work(:)\n\n ! use LAPACK's zheevd routine\n n = size(Am, 1)\n call assert_shape(Am, [n, n], \"eigh\", \"Am\")\n call assert_shape(c, [n, n], \"eigh\", \"c\")\n lda = max(1, n)\n lwork = 2*n + n**2\n lrwork = 1 + 5*n + 2*n**2\n liwork = 3 + 5*n\n allocate(work(lwork), rwork(lrwork), iwork(liwork))\n c = Am\n call zheevd(\"V\", \"L\", n, c, lda, lam, work, lwork, rwork, lrwork, &\n iwork, liwork, info)\n if (info /= 0) then\n print *, \"zheevd returned info =\", info\n if (info < 0) then\n print *, \"the\", -info, \"-th argument had an illegal value\"\n else\n print *, \"the algorithm failed to compute an eigenvalue while working\"\n print *, \"through the submatrix lying in rows and columns through\"\n print *, info/(n+1), \" through \", mod(info, n+1)\n end if\n call stop_error('eigh: zheevd error')\n end if\n end subroutine zeigh_simple\n\n function dinv(Am) result(Bm)\n real(dp), intent(in) :: Am(:,:) ! matrix to be inverted\n real(dp) :: Bm(size(Am, 1), size(Am, 2)) ! Bm = inv(Am)\n real(dp), allocatable :: Amt(:,:), work(:) ! temporary work arrays\n\n ! LAPACK variables:\n integer :: info, lda, n, lwork, nb\n integer, allocatable :: ipiv(:)\n\n ! use LAPACK's dgetrf and dgetri\n n = size(Am(1, :))\n call assert_shape(Am, [n, n], \"inv\", \"Am\")\n lda = n\n nb = ilaenv(1, 'DGETRI', \"UN\", n, -1, -1, -1) ! TODO: check UN param\n lwork = n*nb\n if (nb < 1) nb = max(1, n)\n allocate(Amt(n,n), work(lwork), ipiv(n))\n Amt = Am\n call dgetrf(n, n, Amt, lda, ipiv, info)\n if(info /= 0) then\n print *, \"dgetrf returned info =\", info\n if (info < 0) then\n print *, \"the\", -info, \"-th argument had an illegal value\"\n else\n print *, \"U(\", info, \",\", info, \") is exactly zero; The factorization\"\n print *, \"has been completed, but the factor U is exactly\"\n print *, \"singular, and division by zero will occur if it is used\"\n print *, \"to solve a system of equations.\"\n end if\n call stop_error('inv: dgetrf error')\n end if\n\n call dgetri(n, Amt, n, ipiv, work, lwork, info)\n if (info /= 0) then\n print *, \"dgetri returned info =\", info\n if (info < 0) then\n print *, \"the\", -info, \"-th argument had an illegal value\"\n else\n print *, \"U(\", info, \",\", info, \") is exactly zero; the matrix is\"\n print *, \"singular and its inverse could not be computed.\"\n end if\n call stop_error('inv: dgetri error')\n end if\n Bm = Amt\n\n end function dinv\n\n function zinv(Am) result(Bm)\n ! Inverts the general complex matrix Am\n complex(dp), intent(in) :: Am(:,:) ! Matrix to be inverted\n complex(dp) :: Bm(size(Am, 1), size(Am, 2)) ! Bm = inv(Am)\n integer :: n, nb\n ! lapack variables\n integer :: lwork, info\n complex(dp), allocatable:: Amt(:,:), work(:)\n integer, allocatable:: ipiv(:)\n\n n = size(Am, 1)\n call assert_shape(Am, [n, n], \"inv\", \"Am\")\n nb = ilaenv(1, 'ZGETRI', \"UN\", n, -1, -1, -1) ! TODO: check UN param\n if (nb < 1) nb = max(1, n)\n lwork = n*nb\n allocate(Amt(n,n), ipiv(n), work(lwork))\n Amt = Am\n call zgetrf(n, n, Amt, n, ipiv, info)\n if (info /= 0) then\n print *, \"zgetrf returned info =\", info\n if (info < 0) then\n print *, \"the\", -info, \"-th argument had an illegal value\"\n else\n print *, \"U(\", info, \",\", info, \") is exactly zero; The factorization\"\n print *, \"has been completed, but the factor U is exactly\"\n print *, \"singular, and division by zero will occur if it is used\"\n print *, \"to solve a system of equations.\"\n end if\n call stop_error('inv: zgetrf error')\n end if\n call zgetri(n, Amt, n, ipiv, work, lwork, info)\n if (info /= 0) then\n print *, \"zgetri returned info =\", info\n if (info < 0) then\n print *, \"the\", -info, \"-th argument had an illegal value\"\n else\n print *, \"U(\", info, \",\", info, \") is exactly zero; the matrix is\"\n print *, \"singular and its inverse could not be computed.\"\n end if\n call stop_error('inv: zgetri error')\n end if\n Bm = Amt\n end function zinv\n\n function dsolve(A, b) result(x)\n ! solves a system of equations A x = b with one right hand side\n real(dp), intent(in) :: A(:,:) ! coefficient matrix A\n real(dp), intent(in) :: b(:) ! right-hand-side A x = b\n real(dp), allocatable :: x(:)\n ! LAPACK variables:\n real(dp), allocatable :: At(:,:), bt(:,:)\n integer :: n, info, lda\n integer, allocatable :: ipiv(:)\n\n n = size(A(1,:))\n lda = size(A(:, 1)) ! TODO: remove lda (which is = n!)\n call assert_shape(A, [n, n], \"solve\", \"A\")\n allocate(At(lda,n), bt(n,1), ipiv(n), x(n))\n At = A\n bt(:,1) = b(:)\n call dgesv(n, 1, At, lda, ipiv, bt, n, info)\n if(info /= 0) then\n print *, \"dgesv returned info =\", info\n if (info < 0) then\n print *, \"the\", -info, \"-th argument had an illegal value\"\n else\n print *, \"U(\", info, \",\", info, \") is exactly zero; The factorization\"\n print *, \"has been completed, but the factor U is exactly\"\n print *, \"singular, so the solution could not be computed.\"\n end if\n call stop_error('inv: dgesv error')\n endif\n x = bt(:,1)\n end function dsolve\n\n function zsolve(A, b) result(x)\n ! solves a system of equations A x = b with one right hand side\n complex(dp), intent(in) :: A(:,:) ! coefficient matrix A\n complex(dp), intent(in) :: b(:) ! right-hand-side A x = b\n complex(dp), allocatable :: x(:)\n ! LAPACK variables:\n complex(dp), allocatable :: At(:,:), bt(:,:)\n integer :: n, info, lda\n integer, allocatable :: ipiv(:)\n\n n = size(A(1,:))\n lda = size(A(:, 1)) ! TODO: remove lda here, too\n call assert_shape(A, [n, n], \"solve\", \"A\")\n allocate(At(lda,n), bt(n,1), ipiv(n), x(n))\n At = A\n bt(:,1) = b(:)\n call zgesv(n, 1, At, lda, ipiv, bt, n, info)\n if(info /= 0) then\n print *, \"zgesv returned info =\", info\n if (info < 0) then\n print *, \"the\", -info, \"-th argument had an illegal value\"\n else\n print *, \"U(\", info, \",\", info, \") is exactly zero; The factorization\"\n print *, \"has been completed, but the factor U is exactly\"\n print *, \"singular, so the solution could not be computed.\"\n end if\n call stop_error('inv: zgesv error')\n endif\n x = bt(:,1)\n end function zsolve\n\n function eye(n) result(A)\n ! Returns the identity matrix of size n x n and type real.\n integer, intent(in) :: n\n real(dp) :: A(n, n)\n integer :: i\n\n A = 0\n do i = 1, n\n A(i, i) = 1\n end do\n end function eye\n\n function ddet(A) result(x)\n ! compute the determinant of a real matrix using an LU factorization\n real(dp), intent(in) :: A(:, :)\n real(dp) :: x\n integer :: i\n ! LAPACK variables:\n integer :: info, n\n integer, allocatable :: ipiv(:)\n real(dp), allocatable :: At(:,:)\n\n n = size(A(1,:))\n call assert_shape(A, [n, n], \"det\", \"A\")\n allocate(At(n,n), ipiv(n))\n At = A\n call dgetrf(n, n, At, n, ipiv, info)\n if(info /= 0) then\n print *, \"dgetrf returned info =\", info\n if (info < 0) then\n print *, \"the\", -info, \"-th argument had an illegal value\"\n else\n print *, \"U(\", info, \",\", info, \") is exactly zero; The factorization\"\n print *, \"has been completed, but the factor U is exactly\"\n print *, \"singular, and division by zero will occur if it is used\"\n print *, \"to solve a system of equations.\"\n end if\n call stop_error('det: dgetrf error')\n end if\n\n ! At now contains the LU of the factorization A = PLU\n ! as L has unit diagonal entries, the determinant can be computed\n ! from the product of U's diagonal entries. Additional sign changes\n ! stemming from the permutations P have to be taken into account as well.\n x = 1.0_dp\n do i = 1,n\n if(ipiv(i) /= i) then ! additional sign change\n x = -x*At(i,i)\n else\n x = x*At(i,i)\n endif\n end do\n end function ddet\n\n function zdet(A) result(x)\n ! compute the determinant of a real matrix using an LU factorization\n complex(dp), intent(in) :: A(:, :)\n complex(dp) :: x\n integer :: i\n ! LAPACK variables:\n integer :: info, n\n integer, allocatable :: ipiv(:)\n complex(dp), allocatable :: At(:,:)\n\n n = size(A(1,:))\n call assert_shape(A, [n, n], \"det\", \"A\")\n allocate(At(n,n), ipiv(n))\n At = A\n call zgetrf(n, n, At, n, ipiv, info)\n if(info /= 0) then\n print *, \"zgetrf returned info =\", info\n if (info < 0) then\n print *, \"the\", -info, \"-th argument had an illegal value\"\n else\n print *, \"U(\", info, \",\", info, \") is exactly zero; The factorization\"\n print *, \"has been completed, but the factor U is exactly\"\n print *, \"singular, and division by zero will occur if it is used\"\n print *, \"to solve a system of equations.\"\n end if\n call stop_error('inv: zgetrf error')\n end if\n\n ! for details on the computation, compare the comment in ddet().\n x = 1.0_dp + 0*i_\n do i = 1,n\n if(ipiv(i) /= i) then ! additional sign change\n x = -x*At(i,i)\n else\n x = x*At(i,i)\n endif\n end do\n end function zdet\n\n function dlstsq(A, b) result(x)\n ! compute least square solution to A x = b for real A, b\n real(dp), intent(in) :: A(:,:), b(:)\n real(dp), allocatable :: x(:)\n ! LAPACK variables:\n integer :: info, ldb, lwork, m, n, rank\n real(dp) :: rcond\n real(dp), allocatable :: work(:), At(:,:), Bt(:,:)\n integer, allocatable :: jpvt(:)\n\n m = size(A(:,1)) ! = lda\n n = size(A(1,:))\n ldb = size(b)\n allocate(x(n), At(m,n), Bt(ldb,1), jpvt(n), work(1))\n call dgelsy(m, n, 1, At, m, Bt, ldb, jpvt, rcond, rank, work, &\n -1, info) ! query optimal workspace size\n lwork = int(real(work(1)))\n deallocate(work)\n allocate(work(lwork)) ! allocate with ideal size\n rcond = 0.0_dp\n jpvt(:) = 0\n Bt(:,1) = b(:) ! only one right-hand side\n At(:,:) = A(:,:)\n call dgelsy(m, n, 1, At, m, Bt, ldb, jpvt, rcond, rank, work, &\n lwork, info)\n if(info /= 0) then\n print *, \"dgelsy returned info = \", info\n print *, \"the \", -info, \"-th argument had an illegal value\"\n call stop_error('lstsq: dgelsy error')\n endif\n x(:) = Bt(1:n,1)\n end function dlstsq\n\n function zlstsq(A, b) result(x)\n ! compute least square solution to A x = b for complex A, b\n complex(dp), intent(in) :: A(:,:), b(:)\n complex(dp), allocatable :: x(:)\n ! LAPACK variables:\n integer :: info, ldb, lwork, m, n, rank\n real(dp) :: rcond\n complex(dp), allocatable :: At(:,:), Bt(:,:), work(:)\n real(dp), allocatable :: rwork(:)\n integer, allocatable :: jpvt(:)\n\n m = size(A(:,1)) ! = lda\n n = size(A(1,:))\n ldb = size(b)\n allocate(x(n), At(m,n), Bt(ldb,1), jpvt(n), work(1), rwork(2*n))\n call zgelsy(m, n, 1, At, m, Bt, ldb, jpvt, rcond, rank, work, &\n -1, rwork, info) ! query optimal workspace size\n lwork = int(real(work(1)))\n deallocate(work)\n allocate(work(lwork)) ! allocate with ideal size\n rcond = 0.0_dp\n jpvt(:) = 0\n Bt(:,1) = b(:) ! only one right-hand side\n At(:,:) = A(:,:)\n call zgelsy(m, n, 1, At, m, Bt, ldb, jpvt, rcond, rank, work, &\n lwork, rwork, info)\n if(info /= 0) then\n print *, \"zgelsy returned info = \", info\n print *, \"the \", -info, \"-th argument had an illegal value\"\n call stop_error('lstsq: zgelsy error')\n endif\n x(:) = Bt(1:n,1)\n end function zlstsq\n\n ! TODO: can assumed types help in Xdiag() and Xtrace()?\n ! TODO: add optional axis parameter in both xdiag() functions\n function ddiag(x) result(A)\n ! construct real matrix from diagonal elements\n real(dp), intent(in) :: x(:)\n real(dp), allocatable :: A(:,:)\n integer :: i, n\n\n n = size(x)\n allocate(A(n,n))\n A(:,:) = 0.0_dp\n forall(i=1:n) A(i,i) = x(i)\n end function ddiag\n\n function zdiag(x) result(A)\n ! construct complex matrix from diagonal elements\n complex(dp), intent(in) :: x(:)\n complex(dp), allocatable :: A(:,:)\n integer :: i, n\n\n n = size(x)\n allocate(A(n,n))\n A(:,:) = 0*i_\n forall(i=1:n) A(i,i) = x(i)\n end function zdiag\n\n ! TODO: add optional axis parameter in both xtrace() functions\n function dtrace(A) result(t)\n ! return trace along the main diagonal\n real(dp), intent(in) :: A(:,:)\n real(dp) :: t\n integer :: i\n\n t = 0.0_dp\n do i = 1,minval(shape(A))\n t = t + A(i,i)\n end do\n end function dtrace\n\n function ztrace(A) result(t)\n ! return trace along the main diagonal\n complex(dp), intent(in) :: A(:,:)\n complex(dp) :: t\n integer :: i\n\n t = 0*i_\n do i = 1,minval(shape(A))\n t = t + A(i,i)\n end do\n end function ztrace\n\n function dsvdvals(A) result(s)\n ! compute singular values s_i of a real m x n matrix A\n real(dp), intent(in) :: A(:,:)\n real(dp), allocatable :: s(:)\n ! LAPACK related:\n integer :: info, lwork, m, n\n real(dp), allocatable :: work(:), At(:,:)\n real(dp) :: u(1,1), vt(1,1) ! not used if only s is to be computed\n\n m = size(A(:,1)) ! = lda\n n = size(A(1,:))\n allocate(At(m,n), s(min(m,n)))\n At(:,:) = A(:, :) ! A is overwritten in dgesvd\n\n ! query optimal lwork and allocate workspace:\n allocate(work(1))\n call dgesvd('N', 'N', m, n, At, m, s, u, 1, vt, 1, work, -1, info)\n lwork = int(real(work(1)))\n deallocate(work)\n allocate(work(lwork))\n\n call dgesvd('N', 'N', m, n, At, m, s, u, 1, vt, 1, work, lwork, info)\n if(info /= 0) then\n print *, \"dgesvd returned info = \", info\n if(info < 0) then\n print *, \"the \", -info, \"-th argument had an illegal value\"\n else\n print *, \"DBDSQR did not converge, there are \", info\n print *, \"superdiagonals of an intermediate bidiagonal form B\"\n print *, \"did not converge to zero. See the description of WORK\"\n print *, \"in DGESVD's man page for details.\"\n endif\n call stop_error('svdvals: dgesvd error')\n endif\n end function dsvdvals\n\n function zsvdvals(A) result(s)\n ! compute singular values s_i of a real m x n matrix A\n complex(dp), intent(in) :: A(:,:)\n real(dp), allocatable :: s(:)\n ! LAPACK related:\n integer :: info, lwork, m, n, lrwork\n complex(dp), allocatable :: work(:), At(:,:)\n real(dp), allocatable :: rwork(:)\n complex(dp) :: u(1,1), vt(1,1) ! not used if only s is to be computed\n\n m = size(A(:,1)) ! = lda\n n = size(A(1,:))\n lrwork = 5*min(m,n)\n allocate(At(m,n), s(min(m,n)), rwork(lrwork))\n At(:,:) = A(:,:) ! A is overwritten in zgesvd!\n\n ! query optimal lwork and allocate workspace:\n allocate(work(1))\n call zgesvd('N', 'N', m, n, At, m, s, u, 1, vt, 1, work, -1, rwork, info)\n lwork = int(real(work(1)))\n deallocate(work)\n allocate(work(lwork))\n\n call zgesvd('N', 'N', m, n, At, m, s, u, 1, vt, 1, work, lwork, rwork, info)\n if(info /= 0) then\n print *, \"zgesvd returned info = \", info\n if(info < 0) then\n print *, \"the \", -info, \"-th argument had an illegal value\"\n else\n print *, \"ZBDSQR did not converge, there are \", info\n print *, \"superdiagonals of an intermediate bidiagonal form B\"\n print *, \"did not converge to zero. See the description of RWORK\"\n print *, \"in ZGESVD's man page for details.\"\n endif\n call stop_error('svdvals: zgesvd error')\n endif\n end function zsvdvals\n\n subroutine dsvd(A, s, U, Vtransp)\n ! compute the singular value decomposition A = U sigma Vtransp of a\n ! real m x n matrix A\n ! U is m x m\n ! Vtransp is n x n\n ! s has size min(m, n) --> sigma matrix is (n x m) with sigma_ii = s_i\n real(dp), intent(in) :: A(:,:)\n real(dp), intent(out) :: s(:), U(:,:), Vtransp(:,:)\n ! LAPACK related:\n integer :: info, lwork, m, n, ldu\n real(dp), allocatable :: work(:), At(:,:)\n\n ! TODO: check shapes here and in other routines?\n\n m = size(A(:,1)) ! = lda\n n = size(A(1,:))\n ldu = m\n allocate(At(m,n))\n At(:,:) = A(:,:) ! use a temporary as dgesvd destroys its input\n\n call assert_shape(U, [m, m], \"svd\", \"U\")\n call assert_shape(Vtransp, [n, n], \"svd\", \"Vtransp\")\n\n ! query optimal lwork and allocate workspace:\n allocate(work(1))\n call dgesvd('A', 'A', m, n, At, m, s, U, ldu, Vtransp, n, work, -1, info)\n lwork = int(real(work(1)))\n deallocate(work)\n allocate(work(lwork))\n\n call dgesvd('A', 'A', m, n, At, m, s, U, ldu, Vtransp, n, work, lwork, info)\n if(info /= 0) then\n print *, \"dgesvd returned info = \", info\n if(info < 0) then\n print *, \"the \", -info, \"-th argument had an illegal value\"\n else\n print *, \"DBDSQR did not converge, there are \", info\n print *, \"superdiagonals of an intermediate bidiagonal form B\"\n print *, \"did not converge to zero. See the description of WORK\"\n print *, \"in DGESVD's man page for details.\"\n endif\n call stop_error('svd: dgesvd error')\n endif\n end subroutine dsvd\n\n subroutine zsvd(A, s, U, Vtransp)\n ! compute the singular value decomposition A = U sigma V^H of a\n ! complex m x m matrix A\n ! U is m x min(m, n)\n ! Vtransp is n x n\n ! sigma is m x n with with sigma_ii = s_i\n ! note that this routine returns V^H, not V!\n complex(dp), intent(in) :: A(:,:)\n real(dp), intent(out) :: s(:)\n complex(dp), intent(out) :: U(:,:), Vtransp(:,:)\n ! LAPACK related:\n integer :: info, lwork, m, n, ldu, lrwork\n real(dp), allocatable :: rwork(:)\n complex(dp), allocatable :: work(:), At(:,:)\n\n ! TODO: check shapes here and in other routines?\n\n m = size(A(:,1)) ! = lda\n n = size(A(1,:))\n ldu = m\n lrwork = 5*min(m,n)\n allocate(rwork(lrwork), At(m,n))\n At(:,:) = A(:,:) ! use a temporary as zgesvd destroys its input\n\n call assert_shape(U, [m, m], \"svd\", \"U\")\n call assert_shape(Vtransp, [n, n], \"svd\", \"Vtransp\")\n\n ! query optimal lwork and allocate workspace:\n allocate(work(1))\n call zgesvd('A', 'A', m, n, At, m, s, U, ldu, Vtransp, n, work, -1,&\n rwork, info)\n lwork = int(real(work(1)))\n deallocate(work)\n allocate(work(lwork))\n\n call zgesvd('A', 'A', m, n, At, m, s, U, ldu, Vtransp, n, work, &\n lwork, rwork, info)\n if(info /= 0) then\n print *, \"zgesvd returned info = \", info\n if(info < 0) then\n print *, \"the \", -info, \"-th argument had an illegal value\"\n else\n print *, \"ZBDSQR did not converge, there are \", info\n print *, \"superdiagonals of an intermediate bidiagonal form B\"\n print *, \"did not converge to zero. See the description of WORK\"\n print *, \"in DGESVD's man page for details.\"\n endif\n call stop_error('svd: zgesvd error')\n endif\n end subroutine zsvd\n\n subroutine dassert_shape(A, shap, routine, matname)\n ! make sure a given real matrix has a given shape\n real(dp), intent(in) :: A(:,:)\n integer, intent(in) :: shap(:)\n character(len=*) :: routine, matname\n\n if(any(shape(A) /= shap)) then\n print *, \"In routine \" // routine // \" matrix \" // matname // \" has illegal shape \", shape(A)\n print *, \"Shape should be \", shap\n call stop_error(\"Aborting due to illegal matrix operation\")\n end if\n end subroutine dassert_shape\n\n subroutine zassert_shape(A, shap, routine, matname)\n ! make sure a given real matrix has a given shape\n complex(dp), intent(in) :: A(:,:)\n integer, intent(in) :: shap(:)\n character(len=*) :: routine, matname\n\n if(any(shape(A) /= shap)) then\n print *, \"In routine \" // routine // \" matrix \" // matname // \" has illegal shape \", shape(A)\n print *, \"Shape should be \", shap\n call stop_error(\"Aborting due to illegal matrix operation\")\n end if\n end subroutine zassert_shape\n\nend module linalg\n", "meta": {"hexsha": "a58d91f0a098426a0c70aabdbdff32fd609b2d42", "size": 34314, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/linalg.f90", "max_stars_repo_name": "shelvon/fortran-utils", "max_stars_repo_head_hexsha": "464982bfc96359c7d37d9fd0185c6722e9a70046", "max_stars_repo_licenses": ["MIT"], "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/linalg.f90", "max_issues_repo_name": "kiranhegde/fortran-utils", "max_issues_repo_head_hexsha": "464982bfc96359c7d37d9fd0185c6722e9a70046", "max_issues_repo_licenses": ["MIT"], "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/linalg.f90", "max_forks_repo_name": "kiranhegde/fortran-utils", "max_forks_repo_head_hexsha": "464982bfc96359c7d37d9fd0185c6722e9a70046", "max_forks_repo_licenses": ["MIT"], "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": 35.8183716075, "max_line_length": 108, "alphanum_fraction": 0.5790639389, "num_tokens": 10579, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037343628703, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6656366749129914}} {"text": "module constants\r\n real, parameter :: pi=3.1415926\r\n real, parameter :: twopi=2.*pi\r\n real, parameter :: rad=pi/180.\r\n real, parameter :: ftm=12./39.37\r\n real, parameter :: mtf=1/ftm\r\n real, parameter :: rpm=60./twopi\r\n ! ft/s^2\r\n real, parameter :: g=32.179\r\n real, parameter :: circ=9.125\r\n ! radius of ball in ft\r\n real, parameter :: radius=circ/twopi/12\r\n real, parameter :: const0=5.283e-3\r\n real, parameter :: rho0=1.175\r\nend module constants\r\n\r\nmodule specs\r\n integer, parameter :: nterms=8\r\n integer, parameter :: nstep=1000\r\nend module specs\r\n\r\nsubroutine trajectory(cd0,cddot,cdspin,w0,theta0,tau0,rhodata,vdata,thetadata,vwind,spin_rpm,sfact,cdi,distance,tof)\r\n\r\n use constants, only : pi,twopi,rad,ftm,mtf,rpm,const0,rho0,g,radius\r\n use specs, only : nterms, nstep;\r\n \r\n ! Need to eventually enable 'implicit none'\r\n !implicit none\r\n\r\n ! Original version by Alan Nathan\r\n ! Modifcations by Chris Long\r\n\r\n real, intent(in) :: cd0\r\n real, intent(in) :: cddot\r\n real, intent(in) :: cdspin\r\n real, intent(in) :: w0\r\n real, intent(in) :: theta0\r\n real, intent(in) :: tau0\r\n real, intent(in) :: rhodata\r\n real, intent(in) :: vdata\r\n real, intent(in) :: thetadata\r\n real, intent(in) :: vwind\r\n real, intent(out) :: spin_rpm\r\n real, intent(out) :: sfact\r\n real, intent(out) :: cdi\r\n real, intent(out) :: distance\r\n real, intent(out) :: tof\r\n\r\n interface rkdumb\r\n subroutine rkdumb(xx,y,vstart,nvar,x1,x2,nstep,cd0,cddot,cdspin,w0,theta0,tau0,v0,theta,rho,const,vwx,vwy,ctht,stht,cphi,sphi)\r\n real, dimension(:), intent(out) :: xx\r\n real, dimension(:,:), intent(out) :: y\r\n real, dimension(:), intent(in) :: vstart\r\n integer, intent(in) :: nvar\r\n real, intent(in) :: x1\r\n real, intent(out) :: x2\r\n integer, intent(in) :: nstep\r\n real, intent(in) :: cd0\r\n real, intent(in) :: cddot\r\n real, intent(in) :: cdspin\r\n real, intent(in) :: w0\r\n real, intent(in) :: theta0\r\n real, intent(in) :: tau0\r\n ! in mph,det,kg/m^3,mph,mph\r\n real, intent(in) :: v0\r\n real, intent(in) :: theta\r\n real, intent(in) :: rho\r\n real, intent(in) :: const\r\n real, intent(in) :: vwx\r\n real, intent(in) :: vwy\r\n \r\n real, intent(in) :: ctht\r\n real, intent(in) :: stht\r\n real, intent(in) :: cphi\r\n real, intent(in) :: sphi\r\n end subroutine rkdumb\r\n end interface rkdumb\r\n\r\n interface dist\r\n subroutine dist(t,x,range,time)\r\n real, dimension(:), intent(in) :: t\r\n real, dimension(:,:), intent(in) :: x\r\n real, intent(out) :: range\r\n real, intent(out) :: time\r\n end subroutine dist\r\n end interface dist\r\n\r\n !real :: rhodata,vdata,thetadata,vwind\r\n\r\n real, dimension(nstep) :: t\r\n real, dimension(nterms,nstep) :: x\r\n\r\n real :: xstart(nterms)\r\n \r\n ! no wind\r\n vwx=0.\r\n vwy=0.\r\n\r\n ! index i:\r\n ! 1,2,3 ==> xi,yi,zi\r\n ! 4,5,6 ==> vx,vy,vz\r\n ! 7,8 ==> r*wb,r*ws\r\n\r\n ! wb=backspin rate\r\n ! ws=sidespin rate\r\n\r\n ! note on the right-handed coordinate: \r\n ! z is vertical with positive upward\r\n ! y is catcher-pitcher line\r\n ! x points to catcher's right\r\n\r\n ! NOTE: This current version is 2D, so that x=vx=ws=0\r\n ! It is easy to reinstate these to make it full 3D\r\n\r\n ! Maximum allowed hangtime in seconds\r\n tmax=10.0\r\n\r\n rho=rhodata\r\n const=const0*(rho/rho0)\r\n v0=vdata\r\n theta=thetadata\r\n vwy=vwind*1.467\r\n vwx=0.\r\n xstart(1)=0.\r\n xstart(2)=2.\r\n xstart(3)=3.\r\n xstart(4)=0.\r\n ctht=cos(theta*rad)\r\n stht=sin(theta*rad)\r\n xstart(5)=(v0*1.467)*ctht\r\n xstart(6)=(v0*1.467)*stht\r\n cphi=1.\r\n sphi=0.\r\n spin=(w0/rpm)*(v0/100.)*(theta-theta0)/(27.5-theta0)\r\n xstart(7)=radius*spin\r\n xstart(8)=0.\r\n\r\n ! spin rate=w0 at v0=100. and theta=27.5 and 0 at theta=aparm(5)\r\n\r\n ! integrate to get trajectory, then distance\r\n\r\n call rkdumb(t,x,xstart,nterms,0.,tmax,nstep,cd0,cddot,cdspin,w0,theta0,tau0,v0,theta,rho,const,vwx,vwy,ctht,stht,cphi,sphi)\r\n\r\n call dist(t,x,range,time)\r\n \r\n sfact=xstart(7)/(1.467*v0)\r\n cdi=cd0*(1.+cddot*(100.-v0))*(1.+cdspin*sfact**2)\r\n\r\n spin_rpm=spin*rpm\r\n distance=range\r\n tof=time\r\n \r\nend subroutine trajectory\r\n\r\nsubroutine derivs(t,x,dxdt,cd0,cddot,cdspin,w0,theta0,tau0,v0,theta,rho,const,vwx,vwy,ctht,stht,cphi,sphi)\r\n\r\n use constants\r\n\r\n ! Given the values of t and x, returns derivatives dxdt=dv/dt\r\n\r\n dimension x(8),dxdt(8)\r\n real drag,lift\r\n \r\n ! 1,2,4 ==> x,y,z\r\n ! 4,5,6 ==> vx,vy,vz\r\n ! 7,8 ==> r*wb,r*ws\r\n\r\n ! NOTE: this is 2D problem, so x(1),dxdt(1) are both fixed at 0\r\n\r\n ! vwx,wwy are x,y components of wind speed\r\n\r\n ! components of radius*spin\r\n\r\n rwb=x(7)\r\n rws=x(8)\r\n romega=sqrt(rwb**2+rws**2)\r\n\r\n ! speed of ball\r\n vt=sqrt((x(4)-vwx)**2+(x(5)-vwy)**2+x(6)**2)\r\n\r\n ! spin factor\r\n sfact=romega/vt\t\t\t\t\r\n\r\n ! note that spin is pure backspin (i.e, rws=0)\r\n\r\n cd=cd0*(1.+cddot*(100.-v0))*(1.+cdspin*sfact**2)\r\n ! Cross prescription\r\n cl=sfact/(2.32*sfact+0.4)\r\n !print*,cd,cl,sfact,g,x(7),vt\r\n !pause\r\n\r\n ! actually drag/(m*vt)\r\n drag=const*cd*vt\r\n ! actually lift/(m*vt)\r\n lift=const*cl*vt\r\n\r\n ! components of spin\r\n ! NOTE: For 2D, ws=0; cphi=1; sphi=0; this means wy=yz=0 and wx=wb\r\n\r\n wx1=rwb\r\n wy1=-rws*stht\r\n wz=rws*ctht\r\n wx=wx1*cphi+wy1*sphi\r\n wy=-wx1*sphi+wy1*cphi\r\n\r\n ! the preceding five statement assure the the spin vector is normal\r\n ! to the initial velocity vector\r\n\r\n !=0 for 2D\r\n liftx=lift*(wy*x(6)-wz*(x(5)-vwy))/romega\r\n lifty=lift*(wz*(x(4)-vwx)-wx*x(6))/romega\r\n liftz=lift*(wx*(x(5)-vwy)-wy*(x(4)-vwx))/romega\r\n !=0 for 2D\r\n dxdt(1)=x(4)\r\n dxdt(2)=x(5)\r\n dxdt(3)=x(6)\r\n !=0 for 2D\r\n dxdt(4)=-drag*(x(4)-vwx)+liftx\r\n dxdt(5)=-drag*(x(5)-vwy)+lifty\r\n dxdt(6)=-drag*x(6)+liftz-g\r\n !no spin-down\r\n dxdt(7)=0.\r\n !no spin-down\r\n dxdt(8)=0.\r\n\t\r\n return\r\nend subroutine derivs\r\n\r\nsubroutine rk4(y,dydx,n,x,h,yout,cd0,cddot,cdspin,w0,theta0,tau0,v0,theta,rho,const,vwx,vwy,ctht,stht,cphi,sphi)\r\n\r\n use specs, only : nterms\r\n\r\n ! Given values for N variables y and their derivatives DYDX known\r\n ! at X, use the fourth-order Runge-Kutta method to advance the\r\n ! solution over an interval H and return the incremented variables\r\n ! as YOUT, which need not be a distinct array from Y. The user\r\n ! supplies the subroutine DERIVS(X,Y,DYDX) which returns the\r\n ! derivatives DYDX at X\r\n\r\n ! Routine taken from Numerical Recipes, 15.1, p. 553\r\n\r\n ! set to the maximum number of functions\r\n\r\n real, intent(in), dimension(:) :: y\r\n real, intent(in), dimension(:) :: dydx\r\n integer, intent(in) :: n\r\n real, intent(in) :: x\r\n real, intent(in) :: h\r\n real, intent(out), dimension(:) :: yout\r\n real, intent(in) :: cd0\r\n real, intent(in) :: cddot\r\n real, intent(in) :: cdspin\r\n real, intent(in) :: w0\r\n real, intent(in) :: theta0\r\n real, intent(in) :: tau0\r\n real, intent(in) :: v0\r\n real, intent(in) :: theta\r\n real, intent(in) :: rho\r\n real, intent(in) :: const\r\n real, intent(in) :: vwx\r\n real, intent(in) :: vwy\r\n real, intent(in) :: ctht\r\n real, intent(in) :: stht\r\n real, intent(in) :: cphi\r\n real, intent(in) :: sphi\r\n \r\n !parameter (nmax=10)\r\n !dimension y(n),dydx(n),yout(n),yt(nmax),dyt(nmax),dym(nmax)\r\n dimension yt(nterms),dyt(nterms),dym(nterms)\r\n \r\n hh=h*0.5\r\n h6=h/6.\r\n xh=x+hh\r\n \r\n ! first step\r\n do i=1,n\r\n yt(i)=y(i)+hh*dydx(i)\r\n end do\r\n ! second step\r\n call derivs(xh,yt,dyt,cd0,cddot,cdspin,w0,theta0,tau0,v0,theta,rho,const,vwx,vwy,ctht,stht,cphi,sphi)\r\n do i=1,n\r\n yt(i)=y(i)+hh*dyt(i)\r\n end do\r\n ! third step\r\n call derivs(xh,yt,dym,cd0,cddot,cdspin,w0,theta0,tau0,v0,theta,rho,const,vwx,vwy,ctht,stht,cphi,sphi)\r\n do i=1,n\r\n yt(i)=y(i)+h*dym(i)\r\n dym(i)=dyt(i)+dym(i)\r\n end do\r\n ! fourth step\r\n call derivs(x+h,yt,dyt,cd0,cddot,cdspin,w0,theta0,tau0,v0,theta,rho,const,vwx,vwy,ctht,stht,cphi,sphi)\r\n do i=1,n\r\n yout(i)=y(i)+h6*(dydx(i)+dyt(i)+2.*dym(i))\r\n end do\r\n return\r\nend subroutine rk4\r\n\r\nsubroutine rkdumb(xx,y,vstart,nvar,x1,x2,nstep,cd0,cddot,cdspin,w0,theta0,tau0,v0,theta,rho,const,vwx,vwy,ctht,stht,cphi,sphi)\r\n\r\n use specs, only : nterms\r\n\r\n ! Starting from initial values VSTART for NVAR functions, known at\r\n ! X1, use fourth-order Runge-Kutta to advance nstep equal increments\r\n ! to X2. The user supplied subroutine DERIVS(X,V,DVDX) evaluates\r\n ! derivatives. Results are stored in the common block PATH. Be sure\r\n ! to dimension the common block appropriately\r\n\r\n ! Routine taken from Numerical Recipes, 15.1, p. 554\r\n\r\n interface rk4\r\n subroutine rk4(y,dydx,n,x,h,yout,cd0,cddot,cdspin,w0,theta0,tau0,v0,theta,rho,const,vwx,vwy,ctht,stht,cphi,sphi)\r\n real, intent(in), dimension(:) :: y\r\n real, intent(in), dimension(:) :: dydx\r\n integer, intent(in) :: n\r\n real, intent(in) :: x\r\n real, intent(in) :: h\r\n real, intent(out), dimension(:) :: yout\r\n real, intent(in) :: cd0\r\n real, intent(in) :: cddot\r\n real, intent(in) :: cdspin\r\n real, intent(in) :: w0\r\n real, intent(in) :: theta0\r\n real, intent(in) :: tau0\r\n ! in mph,det,kg/m^3,mph,mph\r\n real, intent(in) :: v0\r\n real, intent(in) :: theta\r\n real, intent(in) :: rho\r\n real, intent(in) :: const\r\n real, intent(in) :: vwx\r\n real, intent(in) :: vwy\r\n real, intent(in) :: ctht\r\n real, intent(in) :: stht\r\n real, intent(in) :: cphi\r\n real, intent(in) :: sphi\r\n end subroutine rk4\r\n end interface rk4\r\n\r\n real, dimension(:), intent(out) :: xx\r\n real, dimension(:,:), intent(out) :: y\r\n real, dimension(:), intent(in) :: vstart\r\n integer, intent(in) :: nvar\r\n real, intent(in) :: x1\r\n real, intent(out) :: x2\r\n integer, intent(in) :: nstep\r\n real, intent(in) :: cd0\r\n real, intent(in) :: cddot\r\n real, intent(in) :: cdspin\r\n real, intent(in) :: w0\r\n real, intent(in) :: theta0\r\n real, intent(in) :: tau0\r\n real, intent(in) :: v0\r\n real, intent(in) :: theta\r\n real, intent(in) :: rho\r\n real, intent(in) :: const\r\n real, intent(in) :: vwx\r\n real, intent(in) :: vwy\r\n real, intent(in) :: ctht\r\n real, intent(in) :: stht\r\n real, intent(in) :: cphi\r\n real, intent(in) :: sphi\r\n\r\n dimension v(nvar),dv(nvar)\r\n \r\n ! load starting values\r\n do i=1,nvar\t\t\r\n v(i)=vstart(i)\r\n y(i,1)=v(i)\r\n end do\r\n xx(1)=x1\r\n x=x1\r\n h=(x2-x1)/nstep\r\n\r\n ! take nstep steps\r\n do k=1,nstep-1\r\n call derivs(x,v,dv,cd0,cddot,cdspin,w0,theta0,tau0,v0,theta,rho,const,vwx,vwy,ctht,stht,cphi,sphi)\r\n call rk4(v,dv,nvar,x,h,v,cd0,cddot,cdspin,w0,theta0,tau0,v0,theta,rho,const,vwx,vwy,ctht,stht,cphi,sphi)\r\n \r\n ! Commented out - replace with error code\r\n !if (x+h.eq.x)pause 'Stepsize not significant in RKDUMB'\r\n x=x+h\r\n !store intermediate steps\r\n xx(k+1)=x\r\n do i=1,nvar\r\n y(i,k+1)=v(i)\r\n end do\r\n\r\n end do\r\n return\r\nend subroutine rkdumb\r\n\r\nsubroutine dist(t,x,range,time)\r\n\r\n use constants\r\n\r\n real, dimension(:), intent(in) :: t\r\n real, dimension(:,:), intent(in) :: x\r\n real, intent(out) :: range\r\n real, intent(out) :: time\r\n\r\n integer :: nstep\r\n nstep=size(t)\r\n \r\n ! Fortran does not have repeat-until\r\n do i=1,nstep\r\n if(x(3,i).le.0..and.i.gt.1) exit\r\n end do\r\n \r\n ! linear interpolation to get range\r\n frac=x(3,i-1)/(x(3,i-1)-x(3,i))\r\n d1=sqrt(x(2,i-1)**2+x(1,i-1)**2)\r\n d2=sqrt(x(2,i)**2+x(1,i)**2)\r\n range=d1+frac*(d2-d1)\r\n time=t(i)\r\n return\r\nend subroutine dist\r\n\r\nprogram main\r\n cd0=0.4103\r\n cddot=0.0044\r\n cdspin=0.2043\r\n w0=2069.4111\r\n theta0=7.2023\r\n tau0=25.0000\r\n rhodata=1.19\r\n vdata=91.0\r\n thetadata=27.5\r\n vwind=2.0\r\n call trajectory(cd0,cddot,cdspin,w0,theta0,tau0,rhodata,vdata,thetadata,vwind,spin_rpm,sfact,cdi,distance,tof)\r\n write(*,*) spin_rpm,sfact,cdi,distance,tof\r\nend program main\r\n", "meta": {"hexsha": "a3081270528c83f0bcd29609fb6b62240549b89a", "size": 11788, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "trajectories/fortran/alpha.f90", "max_stars_repo_name": "octonion/baseball-public", "max_stars_repo_head_hexsha": "66c406b5855b61d851303069487c8f7e5a885812", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 41, "max_stars_repo_stars_event_min_datetime": "2015-01-04T21:41:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-22T12:09:57.000Z", "max_issues_repo_path": "trajectories/fortran/alpha.f90", "max_issues_repo_name": "octonion/baseball-public", "max_issues_repo_head_hexsha": "66c406b5855b61d851303069487c8f7e5a885812", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2015-01-10T08:05:55.000Z", "max_issues_repo_issues_event_max_datetime": "2015-01-10T08:05:55.000Z", "max_forks_repo_path": "trajectories/fortran/alpha.f90", "max_forks_repo_name": "octonion/baseball-public", "max_forks_repo_head_hexsha": "66c406b5855b61d851303069487c8f7e5a885812", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2015-01-10T20:15:00.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-22T12:09:58.000Z", "avg_line_length": 27.3503480278, "max_line_length": 132, "alphanum_fraction": 0.6065490329, "num_tokens": 4272, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037302939515, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6656366719890892}} {"text": "SUBROUTINE eta_linear_bottom(H,k,x,int_kx,omega,time,eta,etax,etaxx,etat)\n!\nUSE Precision\nUSE Constants\nIMPLICIT NONE\nREAL(KIND=long), INTENT(IN) :: H,k,x,omega,time,int_kx\nREAL(KIND=long), INTENT(OUT) :: eta,etax\nREAL(KIND=long), INTENT(OUT) :: etaxx,etat\n! REAL(KIND=long), OPTIONAL :: y,etay,etayy !Boundary fitted ?\n! Local variables\nREAL(KIND=long) :: kx, half_H, sinkx\n!\nkx=int_kx-omega*time\nhalf_H = H*half\nsinkx = sin(kx)\n!\neta = half_H*cos(kx)\netax = -half_H*k*sinkx\netat = omega*half_H*sinkx\netaxx = -eta*(k)**2\n\nEND SUBROUTINE eta_linear_bottom\n", "meta": {"hexsha": "a71db69a9a2cb8be6341c3194d0a08e45be78fc7", "size": 563, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/functions/eta_linear_bottom.f90", "max_stars_repo_name": "apengsigkarup/OceanWave3D", "max_stars_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 46, "max_stars_repo_stars_event_min_datetime": "2016-01-08T12:36:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T06:56:45.000Z", "max_issues_repo_path": "src/functions/eta_linear_bottom.f90", "max_issues_repo_name": "apengsigkarup/OceanWave3D", "max_issues_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-10-10T19:45:08.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-07T07:37:11.000Z", "max_forks_repo_path": "src/functions/eta_linear_bottom.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": 24.4782608696, "max_line_length": 73, "alphanum_fraction": 0.7175843694, "num_tokens": 214, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9263037221561135, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6656366661412843}} {"text": " SUBROUTINE AB05PD( OVER, N1, M, P, N2, ALPHA, A1, LDA1, B1, LDB1,\n $ C1, LDC1, D1, LDD1, A2, LDA2, B2, LDB2, C2,\n $ LDC2, D2, LDD2, N, A, LDA, B, LDB, C, LDC, D,\n $ LDD, INFO)\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute the state-space model G = (A,B,C,D) corresponding to\nC the sum G = G1 + alpha*G2, where G1 = (A1,B1,C1,D1) and\nC G2 = (A2,B2,C2,D2). G, G1, and G2 are the transfer-function\nC matrices of the corresponding state-space models.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC OVER CHARACTER*1\nC Indicates whether the user wishes to overlap pairs of\nC arrays, as follows:\nC = 'N': Do not overlap;\nC = 'O': Overlap pairs of arrays: A1 and A, B1 and B,\nC C1 and C, and D1 and D, i.e. the same name is\nC effectively used for each pair (for all pairs)\nC in the routine call. In this case, setting\nC LDA1 = LDA, LDB1 = LDB, LDC1 = LDC, and LDD1 = LDD\nC will give maximum efficiency.\nC\nC Input/Output Parameters\nC\nC N1 (input) INTEGER\nC The number of state variables in the first system, i.e.\nC the order of the matrix A1, the number of rows of B1 and\nC the number of columns of C1. N1 >= 0.\nC\nC M (input) INTEGER\nC The number of input variables of the two systems, i.e. the\nC number of columns of matrices B1, D1, B2 and D2. M >= 0.\nC\nC P (input) INTEGER\nC The number of output variables of the two systems, i.e.\nC the number of rows of matrices C1, D1, C2 and D2. P >= 0.\nC\nC N2 (input) INTEGER\nC The number of state variables in the second system, i.e.\nC the order of the matrix A2, the number of rows of B2 and\nC the number of columns of C2. N2 >= 0.\nC\nC ALPHA (input) DOUBLE PRECISION\nC The coefficient multiplying G2.\nC\nC A1 (input) DOUBLE PRECISION array, dimension (LDA1,N1)\nC The leading N1-by-N1 part of this array must contain the\nC state transition matrix A1 for the first system.\nC\nC LDA1 INTEGER\nC The leading dimension of array A1. LDA1 >= MAX(1,N1).\nC\nC B1 (input) DOUBLE PRECISION array, dimension (LDB1,M)\nC The leading N1-by-M part of this array must contain the\nC input/state matrix B1 for the first system.\nC\nC LDB1 INTEGER\nC The leading dimension of array B1. LDB1 >= MAX(1,N1).\nC\nC C1 (input) DOUBLE PRECISION array, dimension (LDC1,N1)\nC The leading P-by-N1 part of this array must contain the\nC state/output matrix C1 for the first system.\nC\nC LDC1 INTEGER\nC The leading dimension of array C1.\nC LDC1 >= MAX(1,P) if N1 > 0.\nC LDC1 >= 1 if N1 = 0.\nC\nC D1 (input) DOUBLE PRECISION array, dimension (LDD1,M)\nC The leading P-by-M part of this array must contain the\nC input/output matrix D1 for the first system.\nC\nC LDD1 INTEGER\nC The leading dimension of array D1. LDD1 >= MAX(1,P).\nC\nC A2 (input) DOUBLE PRECISION array, dimension (LDA2,N2)\nC The leading N2-by-N2 part of this array must contain the\nC state transition matrix A2 for the second system.\nC\nC LDA2 INTEGER\nC The leading dimension of array A2. LDA2 >= MAX(1,N2).\nC\nC B2 (input) DOUBLE PRECISION array, dimension (LDB2,M)\nC The leading N2-by-M part of this array must contain the\nC input/state matrix B2 for the second system.\nC\nC LDB2 INTEGER\nC The leading dimension of array B2. LDB2 >= MAX(1,N2).\nC\nC C2 (input) DOUBLE PRECISION array, dimension (LDC2,N2)\nC The leading P-by-N2 part of this array must contain the\nC state/output matrix C2 for the second system.\nC\nC LDC2 INTEGER\nC The leading dimension of array C2.\nC LDC2 >= MAX(1,P) if N2 > 0.\nC LDC2 >= 1 if N2 = 0.\nC\nC D2 (input) DOUBLE PRECISION array, dimension (LDD2,M)\nC The leading P-by-M part of this array must contain the\nC input/output matrix D2 for the second system.\nC\nC LDD2 INTEGER\nC The leading dimension of array D2. LDD2 >= MAX(1,P).\nC\nC N (output) INTEGER\nC The number of state variables (N1 + N2) in the resulting\nC system, i.e. the order of the matrix A, the number of rows\nC of B and the number of columns of C.\nC\nC A (output) DOUBLE PRECISION array, dimension (LDA,N1+N2)\nC The leading N-by-N part of this array contains the state\nC transition matrix A for the resulting system.\nC The array A can overlap A1 if OVER = 'O'.\nC\nC LDA INTEGER\nC The leading dimension of array A. LDA >= MAX(1,N1+N2).\nC\nC B (output) DOUBLE PRECISION array, dimension (LDB,M)\nC The leading N-by-M part of this array contains the\nC input/state matrix B for the resulting system.\nC The array B can overlap B1 if OVER = 'O'.\nC\nC LDB INTEGER\nC The leading dimension of array B. LDB >= MAX(1,N1+N2).\nC\nC C (output) DOUBLE PRECISION array, dimension (LDC,N1+N2)\nC The leading P-by-N part of this array contains the\nC state/output matrix C for the resulting system.\nC The array C can overlap C1 if OVER = 'O'.\nC\nC LDC INTEGER\nC The leading dimension of array C.\nC LDC >= MAX(1,P) if N1+N2 > 0.\nC LDC >= 1 if N1+N2 = 0.\nC\nC D (output) DOUBLE PRECISION array, dimension (LDD,M)\nC The leading P-by-M part of this array contains the\nC input/output matrix D for the resulting system.\nC The array D can overlap D1 if OVER = 'O'.\nC\nC LDD INTEGER\nC The leading dimension of array D. LDD >= MAX(1,P).\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value.\nC\nC METHOD\nC\nC The matrices of the resulting systems are determined as:\nC\nC ( A1 0 ) ( B1 )\nC A = ( ) , B = ( ) ,\nC ( 0 A2 ) ( B2 )\nC\nC C = ( C1 alpha*C2 ) , D = D1 + alpha*D2 .\nC\nC REFERENCES\nC\nC None\nC\nC NUMERICAL ASPECTS\nC\nC None\nC\nC CONTRIBUTORS\nC\nC A. Varga, German Aerospace Research Establishment,\nC Oberpfaffenhofen, Germany, and V. Sima, Katholieke Univ. Leuven,\nC Belgium, Nov. 1996.\nC\nC REVISIONS\nC\nC V. Sima, Research Institute for Informatics, Bucharest, July 2003,\nC Feb. 2004.\nC\nC KEYWORDS\nC\nC Multivariable system, state-space model, state-space\nC representation.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, ONE\n PARAMETER ( ZERO=0.0D0, ONE = 1.0D0 )\nC .. Scalar Arguments ..\n CHARACTER OVER\n INTEGER INFO, LDA, LDA1, LDA2, LDB, LDB1, LDB2, LDC,\n $ LDC1, LDC2, LDD, LDD1, LDD2, M, N, N1, N2, P\n DOUBLE PRECISION ALPHA\nC .. Array Arguments ..\n DOUBLE PRECISION A(LDA,*), A1(LDA1,*), A2(LDA2,*), B(LDB,*),\n $ B1(LDB1,*), B2(LDB2,*), C(LDC,*), C1(LDC1,*),\n $ C2(LDC2,*), D(LDD,*), D1(LDD1,*), D2(LDD2,*)\nC .. Local Scalars ..\n LOGICAL LOVER\n INTEGER I, J, N1P1\nC .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\nC .. External Subroutines ..\n EXTERNAL DAXPY, DLACPY, DLASCL, DLASET, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC MAX, MIN\nC .. Executable Statements ..\nC\n LOVER = LSAME( OVER, 'O' )\n N = N1 + N2\n INFO = 0\nC\nC Test the input scalar arguments.\nC\n IF( .NOT.LOVER .AND. .NOT.LSAME( OVER, 'N' ) ) THEN\n INFO = -1\n ELSE IF( N1.LT.0 ) THEN\n INFO = -2\n ELSE IF( M.LT.0 ) THEN\n INFO = -3\n ELSE IF( P.LT.0 ) THEN\n INFO = -4\n ELSE IF( N2.LT.0 ) THEN\n INFO = -5\n ELSE IF( LDA1.LT.MAX( 1, N1 ) ) THEN\n INFO = -8\n ELSE IF( LDB1.LT.MAX( 1, N1 ) ) THEN\n INFO = -10\n ELSE IF( ( N1.GT.0 .AND. LDC1.LT.MAX( 1, P ) ) .OR.\n $ ( N1.EQ.0 .AND. LDC1.LT.1 ) ) THEN\n INFO = -12\n ELSE IF( LDD1.LT.MAX( 1, P ) ) THEN\n INFO = -14\n ELSE IF( LDA2.LT.MAX( 1, N2 ) ) THEN\n INFO = -16\n ELSE IF( LDB2.LT.MAX( 1, N2 ) ) THEN\n INFO = -18\n ELSE IF( ( N2.GT.0 .AND. LDC2.LT.MAX( 1, P ) ) .OR.\n $ ( N2.EQ.0 .AND. LDC2.LT.1 ) ) THEN\n INFO = -20\n ELSE IF( LDD2.LT.MAX( 1, P ) ) THEN\n INFO = -22\n ELSE IF( LDA.LT.MAX( 1, N ) ) THEN\n INFO = -25\n ELSE IF( LDB.LT.MAX( 1, N ) ) THEN\n INFO = -27\n ELSE IF( ( N.GT.0 .AND. LDC.LT.MAX( 1, P ) ) .OR.\n $ ( N.EQ.0 .AND. LDC.LT.1 ) ) THEN\n INFO = -29\n ELSE IF( LDD.LT.MAX( 1, P ) ) THEN\n INFO = -31\n END IF\nC\n IF ( INFO.NE.0 ) THEN\nC\nC Error return.\nC\n CALL XERBLA( 'AB05PD', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF ( MAX( N, MIN( M, P ) ).EQ.0 )\n $ RETURN\nC\n N1P1 = N1 + 1\nC\nC ( A1 0 )\nC Construct A = ( ) .\nC ( 0 A2 )\nC\n IF ( LOVER .AND. LDA1.LE.LDA ) THEN\n IF ( LDA1.LT.LDA ) THEN\nC\n DO 20 J = N1, 1, -1\n DO 10 I = N1, 1, -1\n A(I,J) = A1(I,J)\n 10 CONTINUE\n 20 CONTINUE\nC\n END IF\n ELSE\n CALL DLACPY( 'F', N1, N1, A1, LDA1, A, LDA )\n END IF\nC\n IF ( N2.GT.0 ) THEN\n CALL DLASET( 'F', N1, N2, ZERO, ZERO, A(1,N1P1), LDA )\n CALL DLASET( 'F', N2, N1, ZERO, ZERO, A(N1P1,1), LDA )\n CALL DLACPY( 'F', N2, N2, A2, LDA2, A(N1P1,N1P1), LDA )\n END IF\nC\nC ( B1 )\nC Construct B = ( ) .\nC ( B2 )\nC\n IF ( LOVER .AND. LDB1.LE.LDB ) THEN\n IF ( LDB1.LT.LDB ) THEN\nC\n DO 40 J = M, 1, -1\n DO 30 I = N1, 1, -1\n B(I,J) = B1(I,J)\n 30 CONTINUE\n 40 CONTINUE\nC\n END IF\n ELSE\n CALL DLACPY( 'F', N1, M, B1, LDB1, B, LDB )\n END IF\nC\n IF ( N2.GT.0 )\n $ CALL DLACPY( 'F', N2, M, B2, LDB2, B(N1P1,1), LDB )\nC\nC Construct C = ( C1 alpha*C2 ) .\nC\n IF ( LOVER .AND. LDC1.LE.LDC ) THEN\n IF ( LDC1.LT.LDC ) THEN\nC\n DO 60 J = N1, 1, -1\n DO 50 I = P, 1, -1\n C(I,J) = C1(I,J)\n 50 CONTINUE\n 60 CONTINUE\nC\n END IF\n ELSE\n CALL DLACPY( 'F', P, N1, C1, LDC1, C, LDC )\n END IF\nC\n IF ( N2.GT.0 ) THEN\n CALL DLACPY( 'F', P, N2, C2, LDC2, C(1,N1P1), LDC )\n IF ( ALPHA.NE.ONE )\n $ CALL DLASCL( 'G', 0, 0, ONE, ALPHA, P, N2, C(1,N1P1), LDC,\n $ INFO )\n END IF\nC\nC Construct D = D1 + alpha*D2 .\nC\n IF ( LOVER .AND. LDD1.LE.LDD ) THEN\n IF ( LDD1.LT.LDD ) THEN\nC\n DO 80 J = M, 1, -1\n DO 70 I = P, 1, -1\n D(I,J) = D1(I,J)\n 70 CONTINUE\n 80 CONTINUE\nC\n END IF\n ELSE\n CALL DLACPY( 'F', P, M, D1, LDD1, D, LDD )\n END IF\nC\n DO 90 J = 1, M\n CALL DAXPY( P, ALPHA, D2(1,J), 1, D(1,J), 1 )\n 90 CONTINUE\nC\n RETURN\nC *** Last line of AB05PD ***\n END\n", "meta": {"hexsha": "ada467c8990b778cfff0b5348184d43291f9b424", "size": 12012, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/AB05PD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/AB05PD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/AB05PD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 32.2903225806, "max_line_length": 72, "alphanum_fraction": 0.5094072594, "num_tokens": 3974, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9473810525948927, "lm_q2_score": 0.7025300573952054, "lm_q1q2_score": 0.6655636652546201}} {"text": " SUBROUTINE POWP(NNNN,XXXX,YYYY)\nC\nC THIS SUBROUTINE TAKES A NON-NEGATIVE POWER OF A COMPLEX NUMBER:\nC YYYY = XXXX**NNNN USING DE MOIVRE'S FORMULA:\nC\nC YYYY = R**NNNN * (COS(NNNN*THETA),SIN(NNNN*THETA)),\nC\nC WHERE R=DNRM2(2,XXXX,1) AND THETA=ATAN2(XXXX(2),XXXX(1)).\nC\nC NOTE: POWP SETS 0**0 EQUAL TO 1.\nC\nC ON INPUT:\nC\nC NNNN IS A NON-NEGATIVE INTEGER.\nC\nC XXXX IS AN ARRAY OF LENGTH TWO REPRESENTING A COMPLEX\nC NUMBER, WHERE XXXX(1) = REAL PART OF XXXX AND XXXX(2) =\nC IMAGINARY PART OF XXXX.\nC\nC ON OUTPUT:\nC\nC YYYY IS AN ARRAY OF LENGTH TWO REPRESENTING THE RESULT OF\nC THE POWER, YYYY = XXXX**NNNN, WHERE YYYY(1) =\nC REAL PART OF YYYY AND YYYY(2) = IMAGINARY PART OF YYYY.\nC\nC SUBROUTINES: COS, SIN, ATAN2, DNRM2\nC\nC DECLARATION OF INPUT\n INTEGER NNNN\n DOUBLE PRECISION XXXX\n DIMENSION XXXX(2)\nC\nC DECLARATION OF OUTPUT\n DOUBLE PRECISION YYYY\n DIMENSION YYYY(2)\nC\nC DECLARATION OF VARIABLES\n DOUBLE PRECISION R,RR,T,TT\nC\nC DECLARATION OF FUNCTIONS\n DOUBLE PRECISION DNRM2\nC\n IF (NNNN .EQ. 0) THEN\n YYYY(1)=1.\n YYYY(2)=0.\n RETURN\n ENDIF\n IF (NNNN .EQ. 1) THEN\n YYYY(1)=XXXX(1)\n YYYY(2)=XXXX(2)\n RETURN\n ENDIF\n R = DNRM2(2,XXXX,1)\n IF (R .EQ. 0.0) THEN\n YYYY(1)=0.0\n YYYY(2)=0.0\n RETURN\n END IF\n RR= R**NNNN\n T = ATAN2(XXXX(2),XXXX(1))\n TT= NNNN*T\n YYYY(1) = RR*COS(TT)\n YYYY(2) = RR*SIN(TT)\n RETURN\n END\n", "meta": {"hexsha": "c6f8d6882045dbda9fad63a2e52a21a52167fb70", "size": 1531, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/f2cl/packages/hompack/powp.f", "max_stars_repo_name": "sbwhitecap/clocc-hg", "max_stars_repo_head_hexsha": "f6cf2591ceef8a3a80e04da9b414cdf60a25a90f", "max_stars_repo_licenses": ["MIT"], "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/f2cl/packages/hompack/powp.f", "max_issues_repo_name": "sbwhitecap/clocc-hg", "max_issues_repo_head_hexsha": "f6cf2591ceef8a3a80e04da9b414cdf60a25a90f", "max_issues_repo_licenses": ["MIT"], "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/f2cl/packages/hompack/powp.f", "max_forks_repo_name": "sbwhitecap/clocc-hg", "max_forks_repo_head_hexsha": "f6cf2591ceef8a3a80e04da9b414cdf60a25a90f", "max_forks_repo_licenses": ["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.196969697, "max_line_length": 65, "alphanum_fraction": 0.5983017636, "num_tokens": 558, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636754, "lm_q2_score": 0.7401743735019595, "lm_q1q2_score": 0.6655065981214182}} {"text": "*> \\brief \\b SQRT11\n*\n* =========== DOCUMENTATION ===========\n*\n* Online html documentation available at\n* http://www.netlib.org/lapack/explore-html/\n*\n* Definition:\n* ===========\n*\n* REAL FUNCTION SQRT11( M, K, A, LDA, TAU, WORK, LWORK )\n*\n* .. Scalar Arguments ..\n* INTEGER K, LDA, LWORK, M\n* ..\n* .. Array Arguments ..\n* REAL A( LDA, * ), TAU( * ), WORK( LWORK )\n* ..\n*\n*\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*>\n*> SQRT11 computes the test ratio\n*>\n*> || Q'*Q - I || / (eps * m)\n*>\n*> where the orthogonal matrix Q is represented as a product of\n*> elementary transformations. Each transformation has the form\n*>\n*> H(k) = I - tau(k) v(k) v(k)'\n*>\n*> where tau(k) is stored in TAU(k) and v(k) is an m-vector of the form\n*> [ 0 ... 0 1 x(k) ]', where x(k) is a vector of length m-k stored\n*> in A(k+1:m,k).\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in] M\n*> \\verbatim\n*> M is INTEGER\n*> The number of rows of the matrix A.\n*> \\endverbatim\n*>\n*> \\param[in] K\n*> \\verbatim\n*> K is INTEGER\n*> The number of columns of A whose subdiagonal entries\n*> contain information about orthogonal transformations.\n*> \\endverbatim\n*>\n*> \\param[in] A\n*> \\verbatim\n*> A is REAL array, dimension (LDA,K)\n*> The (possibly partial) output of a QR reduction routine.\n*> \\endverbatim\n*>\n*> \\param[in] LDA\n*> \\verbatim\n*> LDA is INTEGER\n*> The leading dimension of the array A.\n*> \\endverbatim\n*>\n*> \\param[in] TAU\n*> \\verbatim\n*> TAU is REAL array, dimension (K)\n*> The scaling factors tau for the elementary transformations as\n*> computed by the QR factorization routine.\n*> \\endverbatim\n*>\n*> \\param[out] WORK\n*> \\verbatim\n*> WORK is REAL array, dimension (LWORK)\n*> \\endverbatim\n*>\n*> \\param[in] LWORK\n*> \\verbatim\n*> LWORK is INTEGER\n*> The length of the array WORK. LWORK >= M*M + M.\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee\n*> \\author Univ. of California Berkeley\n*> \\author Univ. of Colorado Denver\n*> \\author NAG Ltd.\n*\n*> \\ingroup single_lin\n*\n* =====================================================================\n REAL FUNCTION SQRT11( M, K, A, LDA, TAU, WORK, LWORK )\n*\n* -- LAPACK test routine --\n* -- LAPACK is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n*\n* .. Scalar Arguments ..\n INTEGER K, LDA, LWORK, M\n* ..\n* .. Array Arguments ..\n REAL A( LDA, * ), TAU( * ), WORK( LWORK )\n* ..\n*\n* =====================================================================\n*\n* .. Parameters ..\n REAL ZERO, ONE\n PARAMETER ( ZERO = 0.0E0, ONE = 1.0E0 )\n* ..\n* .. Local Scalars ..\n INTEGER INFO, J\n* ..\n* .. External Functions ..\n REAL SLAMCH, SLANGE\n EXTERNAL SLAMCH, SLANGE\n* ..\n* .. External Subroutines ..\n EXTERNAL SLASET, SORM2R, XERBLA\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC REAL\n* ..\n* .. Local Arrays ..\n REAL RDUMMY( 1 )\n* ..\n* .. Executable Statements ..\n*\n SQRT11 = ZERO\n*\n* Test for sufficient workspace\n*\n IF( LWORK.LT.M*M+M ) THEN\n CALL XERBLA( 'SQRT11', 7 )\n RETURN\n END IF\n*\n* Quick return if possible\n*\n IF( M.LE.0 )\n $ RETURN\n*\n CALL SLASET( 'Full', M, M, ZERO, ONE, WORK, M )\n*\n* Form Q\n*\n CALL SORM2R( 'Left', 'No transpose', M, M, K, A, LDA, TAU, WORK,\n $ M, WORK( M*M+1 ), INFO )\n*\n* Form Q'*Q\n*\n CALL SORM2R( 'Left', 'Transpose', M, M, K, A, LDA, TAU, WORK, M,\n $ WORK( M*M+1 ), INFO )\n*\n DO 10 J = 1, M\n WORK( ( J-1 )*M+J ) = WORK( ( J-1 )*M+J ) - ONE\n 10 CONTINUE\n*\n SQRT11 = SLANGE( 'One-norm', M, M, WORK, M, RDUMMY ) /\n $ ( REAL( M )*SLAMCH( 'Epsilon' ) )\n*\n RETURN\n*\n* End of SQRT11\n*\n END\n", "meta": {"hexsha": "d4422dacbfa24662f05190ec66ab2172ca156716", "size": 4200, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "TESTING/LIN/sqrt11.f", "max_stars_repo_name": "sergey-v-kuznetsov/lapack", "max_stars_repo_head_hexsha": "799ef93faa5878aa8702f7cf9980cfc649cc39cc", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 998, "max_stars_repo_stars_event_min_datetime": "2016-05-04T20:50:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T17:43:13.000Z", "max_issues_repo_path": "TESTING/LIN/sqrt11.f", "max_issues_repo_name": "sergey-v-kuznetsov/lapack", "max_issues_repo_head_hexsha": "799ef93faa5878aa8702f7cf9980cfc649cc39cc", "max_issues_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_issues_count": 603, "max_issues_repo_issues_event_min_datetime": "2016-06-04T07:28:21.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T21:16:50.000Z", "max_forks_repo_path": "TESTING/LIN/sqrt11.f", "max_forks_repo_name": "sergey-v-kuznetsov/lapack", "max_forks_repo_head_hexsha": "799ef93faa5878aa8702f7cf9980cfc649cc39cc", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 373, "max_forks_repo_forks_event_min_datetime": "2016-06-04T06:05:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T17:25:45.000Z", "avg_line_length": 24.4186046512, "max_line_length": 76, "alphanum_fraction": 0.4883333333, "num_tokens": 1230, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699435, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6655065918164221}} {"text": "! *******************************************************************\r\n! * *\r\n! * Function dlsfr3 *\r\n! * *\r\n! *******************************************************************\r\n! Double Precision Version 1.31\r\n! Written by Gordon A. Fenton, TUNS, Mar. 15, 1995\r\n! Latest Update: May 9, 2001\r\n!\r\n! PURPOSE returns the covariance between two points in a separable 3-D\r\n! fractional Gaussian noise field\r\n!\r\n! Returns the covariance between two points in the field separated by the\r\n! lag vector {X,Y,Z}. The covariance function is a separable fractional\r\n! Gaussian noise, given by\r\n!\r\n! B(X,Y,Z) = var*r(X)*r(Y)*r(Z)\r\n!\r\n! for two points separated by distance {X,Y,Z}, where r(X), r(Y), and r(Z)\r\n! are the correlation functions given by\r\n!\r\n! 1 2H 2H 2H\r\n! r(X) = -------- [ |X + pb| - 2|X| + |X - pb| ]\t\t(1)\r\n! 2H\r\n! 2*pb\r\n!\r\n!\r\n! 1 2G 2G 2G\r\n! r(Y) = -------- [ |Y + pb| - 2|Y| + |Y - pb| ]\t\t(2)\r\n! 2G\r\n! 2*pb\r\n!\r\n!\r\n! 1 2F 2F 2F\r\n! r(Z) = -------- [ |Z + pb| - 2|Z| + |Z - pb| ]\t\t(2)\r\n! 2F\r\n! 2*pb\r\n!\r\n! and where `pb' is the length over which the fractional Brownian motion is\r\n! averaged in order to make this, the derivative process, exist. Normally\r\n! `pb' is selected to be quite small (of the order of the size of the\r\n! discretization interval). The parameters `F', `G', and `H' are the\r\n! self-similar parameters, or Hurst exponents, (0.5 < F,G,H < 1) with\r\n! F = G = H = 1 giving a total correlated field and F = G = H = 0.5 giving\r\n! a white noise field (for sufficiently small pb). Finally var is the\r\n! point variance of the process.\r\n!\r\n! The parameters var, pb, H, G, and F are brought in via the common\r\n! block /dparam/.\r\n!\r\n! If var < 0, then this function computes the variance of a local average\r\n! of the random field, |var|*V(X,Y,Z), averaged over a domain having side\r\n! dimensions {X,Y,Z}. For a separable covariance function, the variance\r\n! function is also separable,\r\n!\r\n! V(X,Y,Z) = V(X)*V(Y)*V(Z)\r\n!\r\n! where (X,Y,Z) gives the dimensions of the averaging region. The 1-D\r\n! variance function corresponding to Eq. (1) is given by\r\n!\r\n! r r r r\r\n! |X + pb| - 2( |X| + |pb| ) + |X - pb|\r\n! V(X) = -----------------------------------------\t\t(3)\r\n! 2 2H\r\n! X * (2H+1)*(2H+2)*pb\r\n!\r\n! where r = (2*H+2). Notice that as X goes to zero the above becomes 0/0, but\r\n! its limiting value is 1.0. A similar relationship holds for the variance\r\n! function corresponding to (2).\r\n!\r\n! Parameters to this process are brought in through the common block\r\n! /dparam/ and are described as follows;\r\n!\r\n! var\tthe point variance of the fGn process.\r\n!\r\n! pb\tthe averaging length discussed above. This is assumed common\r\n!\t\tfor all three directions.\r\n!\r\n! H\tthe Hurst exponent governing the process in the X direction.\r\n!\t\tIn this implementation, 0.5 < H < 1; values of H near 1 yield\r\n!\t\ta correlation structure which remains very high (and thus a\r\n!\t\tcovariance matrix which may be nearly singular). Values of H\r\n!\t\tnear 0.5 yield a band- limited white noise process.\r\n!\r\n! G\tthe Hurst exponent governing the process in the Y direction.\r\n!\t\tIn this implementation, 0.5 < G < 1; values of G near 1 yield\r\n!\t\ta correlation structure which remains very high (and thus a\r\n!\t\tcovariance matrix which may be nearly singular). Values of G\r\n!\t\tnear 0.5 yield a band- limited white noise process.\r\n!\r\n! F\tthe Hurst exponent governing the process in the Z direction.\r\n!\t\tIn this implementation, 0.5 < F < 1; values of F near 1 yield\r\n!\t\ta correlation structure which remains very high (and thus a\r\n!\t\tcovariance matrix which may be nearly singular). Values of F\r\n!\t\tnear 0.5 yield a band- limited white noise process.\r\n!\r\n! Arguments to this function are just the X, Y, and Z elements of the\r\n! lag vector between points in the field for which the covariance is\r\n! desired (or the dimensions of the physical averaging region, if var < 0).\r\n!\r\n! REVISION HISTORY:\r\n! 1.1\tadded lvarfn flag to end of /dparam/ common block. Set it to\r\n!\ttrue if the variance function is to be returned. Otherwise this\r\n!\tfunction returns the covariance. (May 1/00)\r\n! 1.2\teliminated lvarfn -- now return covariances only if var < 0 (Apr 9/01)\r\n! 1.3\treversed default - now return covariances if var > 0. (Apr 11/01)\r\n! 1.31\trevised above documentation to reflect revision 1.3 (May 9/01)\r\n!---------------------------------------------------------------------- \r\n real*8 function dlsfr3( X, Y, Z )\r\n implicit real*8 (a-h,o-z)\r\n common/dparam/ var, pb, H, G, F\r\n data zero/0.d0/, one/1.d0/, two/2.d0/\r\n abs(q) = dabs(q)\r\n\r\n if( var .lt. zero ) then\t\t\t! return variance function\r\n!\t\t\t\t\t\t\tX-direction var func\r\n if( X .eq. zero ) then\r\n v1 = one\r\n else\r\n e0 = two*H\r\n e1 = e0 + one\r\n e2 = e0 + two\r\n t1 = abs(X+pb)**e2-two*(abs(X)**e2+pb**e2)+abs(X-pb)**e2\r\n v1 = t1/(X*X*e1*e2*pb**e0)\r\n endif\r\n!\t\t\t\t\t\t\tY-direction var func\r\n if( Y .eq. zero ) then\r\n v2 = one\r\n else\r\n e0 = two*G\r\n e1 = e0 + one\r\n e2 = e0 + two\r\n t1 = abs(Y+pb)**e2-two*(abs(Y)**e2+pb**e2)+abs(Y-pb)**e2\r\n v2 = t1/(Y*Y*e1*e2*pb**e0)\r\n endif\r\n!\t\t\t\t\t\tZ-direction var func\r\n if( Z .eq. zero ) then\r\n v3 = one\r\n else\r\n e0 = two*F\r\n e1 = e0 + one\r\n e2 = e0 + two\r\n t1 = abs(Z+pb)**e2-two*(abs(Z)**e2+pb**e2)+abs(Z-pb)**e2\r\n v3 = t1/(Z*Z*e1*e2*pb**e0)\r\n endif\r\n!\t\t\t\t\t\t\tfinal variance function\r\n dlsfr3 = -var*v1*v2*v3\r\n else\t\t\t\t\t! return covariance\r\n eH = two*H\r\n eG = two*G\r\n eF = two*F\r\n pH = two*(pb**eH)\r\n pG = two*(pb**eG)\r\n pF = two*(pb**eF)\r\n tH = abs(X+pb)**eH-two*(abs(X)**eH)+abs(X-pb)**eH\r\n tG = abs(Y+pb)**eG-two*(abs(Y)**eG)+abs(Y-pb)**eG\r\n tF = abs(Y+pb)**eF-two*(abs(Y)**eF)+abs(Y-pb)**eF\r\n dlsfr2 = var*tH*tG*tF/(pH*pG*pF)\r\n endif\r\n\r\n return\r\n end\r\n", "meta": {"hexsha": "999ea8a79d448e5404ece00016f6a39699200ad2", "size": 6653, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/libs/gaf95/dlsfr3.f95", "max_stars_repo_name": "leemargetts/PoreFEM", "max_stars_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/libs/gaf95/dlsfr3.f95", "max_issues_repo_name": "leemargetts/PoreFEM", "max_issues_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/libs/gaf95/dlsfr3.f95", "max_forks_repo_name": "leemargetts/PoreFEM", "max_forks_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.8159509202, "max_line_length": 79, "alphanum_fraction": 0.5117991883, "num_tokens": 1977, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951625409308, "lm_q2_score": 0.7122321842389469, "lm_q1q2_score": 0.6655063075588329}} {"text": "* Copyright (C) 2009 Intel Corporation. All Rights Reserved.\n* The information and material (\"Material\") provided below is owned by Intel \n* Corporation or its suppliers or licensors, and title to such Material remains\n* with Intel Corporation or its suppliers or licensors. The Material contains \n* proprietary information of Intel or its suppliers and licensors. The Material\n* is protected by worldwide copyright laws and treaty provisions. No part of \n* the Material may be copied, reproduced, published, uploaded, posted,\n* transmitted, or distributed in any way without Intel's prior express written \n* permission. No license under any patent, copyright or other intellectual \n* property rights in the Material is granted to or conferred upon you, either \n* expressly, by implication, inducement, estoppel or otherwise. Any license \n* under such intellectual property rights must be express and approved by Intel\n* in writing.\n* =============================================================================\n*\n* CGESV Example.\n* ==============\n*\n* The program computes the solution to the system of linear\n* equations with a square matrix A and multiple\n* right-hand sides B, where A is the coefficient matrix:\n*\n* ( 1.23, -5.50) ( 7.91, -5.38) ( -9.80, -4.86) ( -7.32, 7.57) \n* ( -2.14, -1.12) ( -9.92, -0.79) ( -9.18, -1.12) ( 1.37, 0.43) \n* ( -4.30, -7.10) ( -6.47, 2.52) ( -6.51, -2.67) ( -5.86, 7.38) \n* ( 1.27, 7.29) ( 8.90, 6.92) ( -8.82, 1.25) ( 5.41, 5.37) \n*\n* and B is the right-hand side matrix:\n*\n* ( 8.33, -7.32) ( -6.11, -3.81) \n* ( -6.18, -4.80) ( 0.14, -7.71) \n* ( -5.71, -2.80) ( 1.41, 3.40) \n* ( -1.60, 3.08) ( 8.54, -4.05) \n*\n* Description.\n* ============\n*\n* The routine solves for X the system of linear equations A*X = B, \n* where A is an n-by-n matrix, the columns of matrix B are individual \n* right-hand sides, and the columns of X are the corresponding \n* solutions.\n*\n* The LU decomposition with partial pivoting and row interchanges is \n* used to factor A as A = P*L*U, where P is a permutation matrix, L \n* is unit lower triangular, and U is upper triangular. The factored \n* form of A is then used to solve the system of equations A*X = B.\n*\n* Example Program Results.\n* ========================\n*\n* CGESV Example Program Results\n* \n* Solution\n* ( -1.09, -0.18) ( 1.28, 1.21)\n* ( 0.97, 0.52) ( -0.22, -0.97)\n* ( -0.20, 0.19) ( 0.53, 1.36)\n* ( -0.59, 0.92) ( 2.22, -1.00)\n* \n* Details of LU factorization\n* ( -4.30, -7.10) ( -6.47, 2.52) ( -6.51, -2.67) ( -5.86, 7.38)\n* ( 0.49, 0.47) ( 12.26, -3.57) ( -7.87, -0.49) ( -0.98, 6.71)\n* ( 0.25, -0.15) ( -0.60, -0.37) (-11.70, -4.64) ( -1.35, 1.38)\n* ( -0.83, -0.32) ( 0.05, 0.58) ( 0.93, -0.50) ( 2.66, 7.86)\n* \n* Pivot indices\n* 3 3 3 4\n* =============================================================================\n*\n* .. Parameters ..\n INTEGER N, NRHS\n PARAMETER ( N = 4, NRHS = 2 )\n INTEGER LDA, LDB\n PARAMETER ( LDA = N, LDB = N )\n*\n* .. Local Scalars ..\n INTEGER INFO\n*\n* .. Local Arrays ..\n INTEGER IPIV( N )\n COMPLEX A( LDA, N ), B( LDB, NRHS )\n DATA A/\n $ ( 1.23,-5.50),(-2.14,-1.12),(-4.30,-7.10),( 1.27, 7.29),\n $ ( 7.91,-5.38),(-9.92,-0.79),(-6.47, 2.52),( 8.90, 6.92),\n $ (-9.80,-4.86),(-9.18,-1.12),(-6.51,-2.67),(-8.82, 1.25),\n $ (-7.32, 7.57),( 1.37, 0.43),(-5.86, 7.38),( 5.41, 5.37)\n $ /\n DATA B/\n $ ( 8.33,-7.32),(-6.18,-4.80),(-5.71,-2.80),(-1.60, 3.08),\n $ (-6.11,-3.81),( 0.14,-7.71),( 1.41, 3.40),( 8.54,-4.05)\n $ /\n*\n* .. External Subroutines ..\n EXTERNAL CGESV\n EXTERNAL PRINT_MATRIX, PRINT_INT_VECTOR\n*\n* .. Executable Statements ..\n WRITE(*,*)'CGESV Example Program Results'\n*\n* Solve the equations A*X = B.\n*\n CALL CGESV( N, NRHS, A, LDA, IPIV, B, LDB, INFO )\n*\n* Check for the exact singularity.\n*\n IF( INFO.GT.0 ) THEN\n WRITE(*,*)'The diagonal element of the triangular factor of A,'\n WRITE(*,*)'U(',INFO,',',INFO,') is zero, so that'\n WRITE(*,*)'A is singular; the solution could not be computed.'\n STOP\n END IF\n*\n* Print solution.\n*\n CALL PRINT_MATRIX( 'Solution', N, NRHS, B, LDB )\n*\n* Print details of LU factorization.\n*\n CALL PRINT_MATRIX( 'Details of LU factorization', N, N, A, LDA )\n*\n* Print pivot indices.\n*\n CALL PRINT_INT_VECTOR( 'Pivot indices', N, IPIV )\n STOP\n END\n*\n* End of CGESV Example.\n*\n* =============================================================================\n*\n* Auxiliary routine: printing a matrix.\n*\n SUBROUTINE PRINT_MATRIX( DESC, M, N, A, LDA )\n CHARACTER*(*) DESC\n INTEGER M, N, LDA\n COMPLEX A( LDA, * )\n*\n INTEGER I, J\n*\n WRITE(*,*)\n WRITE(*,*) DESC\n DO I = 1, M\n WRITE(*,9998) ( A( I, J ), J = 1, N )\n END DO\n*\n 9998 FORMAT( 11(:,1X,'(',F6.2,',',F6.2,')') )\n RETURN\n END\n*\n* Auxiliary routine: printing a vector of integers.\n*\n SUBROUTINE PRINT_INT_VECTOR( DESC, N, A )\n CHARACTER*(*) DESC\n INTEGER N\n INTEGER A( N )\n*\n INTEGER I\n*\n WRITE(*,*)\n WRITE(*,*) DESC\n WRITE(*,9999) ( A( I ), I = 1, N )\n*\n 9999 FORMAT( 11(:,1X,I6) )\n RETURN\n END", "meta": {"hexsha": "6c1a7d70705f1c74688be0f36c035279f354a01c", "size": 5516, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "scalapack/rcs09/mkl.f", "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": "scalapack/rcs09/mkl.f", "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": "scalapack/rcs09/mkl.f", "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": 33.6341463415, "max_line_length": 80, "alphanum_fraction": 0.5134155185, "num_tokens": 1945, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.8311430415844384, "lm_q1q2_score": 0.665489585994365}} {"text": "* wsc@research.bell-labs.com Mon Dec 30 16:55 EST 1985\n* W. S. Cleveland\n* Bell Laboratories\n* Murray Hill NJ 07974\n* \n* outline of this file:\n* lines 1-72 introduction\n* 73-177 documentation for lowess\n* 178-238 ratfor version of lowess\n* 239-301 documentation for lowest\n* 302-350 ratfor version of lowest\n* 351-end test driver and fortran version of lowess and lowest\n* \n* a multivariate version is available by \"send dloess from a\"\n* \n* COMPUTER PROGRAMS FOR LOCALLY WEIGHTED REGRESSION\n* \n* This package consists of two FORTRAN programs for\n* smoothing scatterplots by robust locally weighted\n* regression, or lowess. The principal routine is LOWESS\n* which computes the smoothed values using the method\n* described in The Elements of Graphing Data, by William S.\n* Cleveland (Wadsworth, 555 Morego Street, Monterey,\n* California 93940).\n* \n* LOWESS calls a support routine, LOWEST, the code for\n* which is included. LOWESS also calls a routine SORT, which\n* the user must provide.\n* \n* To reduce the computations, LOWESS requires that the\n* arrays X and Y, which are the horizontal and vertical\n* coordinates, respectively, of the scatterplot, be such that\n* X is sorted from smallest to largest. The user must\n* therefore use another sort routine which will sort X and Y\n* according to X.\n* To summarize the scatterplot, YS, the fitted values,\n* should be plotted against X. No graphics routines are\n* available in the package and must be supplied by the user.\n* \n* The FORTRAN code for the routines LOWESS and LOWEST has\n* been generated from higher level RATFOR programs\n* (B. W. Kernighan, ``RATFOR: A Preprocessor for a Rational\n* Fortran,'' Software Practice and Experience, Vol. 5 (1975),\n* which are also included.\n* \n* The following are data and output from LOWESS that can\n* be used to check your implementation of the routines. The\n* notation (10)v means 10 values of v.\n* \n* \n* \n* \n* X values:\n* 1 2 3 4 5 (10)6 8 10 12 14 50\n* \n* Y values:\n* 18 2 15 6 10 4 16 11 7 3 14 17 20 12 9 13 1 8 5 19\n* \n* \n* YS values with F = .25, NSTEPS = 0, DELTA = 0.0\n* 13.659 11.145 8.701 9.722 10.000 (10)11.300 13.000 6.440 5.596\n* 5.456 18.998\n* \n* YS values with F = .25, NSTEPS = 0 , DELTA = 3.0\n* 13.659 12.347 11.034 9.722 10.511 (10)11.300 13.000 6.440 5.596\n* 5.456 18.998\n* \n* YS values with F = .25, NSTEPS = 2, DELTA = 0.0\n* 14.811 12.115 8.984 9.676 10.000 (10)11.346 13.000 6.734 5.744\n* 5.415 18.998\n* \n* \n* \n* \n* LOWESS\n* \n* \n* \n* Calling sequence\n* \n* CALL LOWESS(X,Y,N,F,NSTEPS,DELTA,YS,RW,RES)\n* \n* Purpose\n* \n* LOWESS computes the smooth of a scatterplot of Y against X\n* using robust locally weighted regression. Fitted values,\n* YS, are computed at each of the values of the horizontal\n* axis in X.\n* \n* Argument description\n* \n* X = Input; abscissas of the points on the\n* scatterplot; the values in X must be ordered\n* from smallest to largest.\n* Y = Input; ordinates of the points on the\n* scatterplot.\n* N = Input; dimension of X,Y,YS,RW, and RES.\n* F = Input; specifies the amount of smoothing; F is\n* the fraction of points used to compute each\n* fitted value; as F increases the smoothed values\n* become smoother; choosing F in the range .2 to\n* .8 usually results in a good fit; if you have no\n* idea which value to use, try F = .5.\n* NSTEPS = Input; the number of iterations in the robust\n* fit; if NSTEPS = 0, the nonrobust fit is\n* returned; setting NSTEPS equal to 2 should serve\n* most purposes.\n* DELTA = input; nonnegative parameter which may be used\n* to save computations; if N is less than 100, set\n* DELTA equal to 0.0; if N is greater than 100 you\n* should find out how DELTA works by reading the\n* additional instructions section.\n* YS = Output; fitted values; YS(I) is the fitted value\n* at X(I); to summarize the scatterplot, YS(I)\n* should be plotted against X(I).\n* RW = Output; robustness weights; RW(I) is the weight\n* given to the point (X(I),Y(I)); if NSTEPS = 0,\n* RW is not used.\n* RES = Output; residuals; RES(I) = Y(I)-YS(I).\n* \n* \n* Other programs called\n* \n* LOWEST\n* SSORT\n* \n* Additional instructions\n* \n* DELTA can be used to save computations. Very roughly the\n* algorithm is this: on the initial fit and on each of the\n* NSTEPS iterations locally weighted regression fitted values\n* are computed at points in X which are spaced, roughly, DELTA\n* apart; then the fitted values at the remaining points are\n* computed using linear interpolation. The first locally\n* weighted regression (l.w.r.) computation is carried out at\n* X(1) and the last is carried out at X(N). Suppose the\n* l.w.r. computation is carried out at X(I). If X(I+1) is\n* greater than or equal to X(I)+DELTA, the next l.w.r.\n* computation is carried out at X(I+1). If X(I+1) is less\n* than X(I)+DELTA, the next l.w.r. computation is carried out\n* at the largest X(J) which is greater than or equal to X(I)\n* but is not greater than X(I)+DELTA. Then the fitted values\n* for X(K) between X(I) and X(J), if there are any, are\n* computed by linear interpolation of the fitted values at\n* X(I) and X(J). If N is less than 100 then DELTA can be set\n* to 0.0 since the computation time will not be too great.\n* For larger N it is typically not necessary to carry out the\n* l.w.r. computation for all points, so that much computation\n* time can be saved by taking DELTA to be greater than 0.0.\n* If DELTA = Range (X)/k then, if the values in X were\n* uniformly scattered over the range, the full l.w.r.\n* computation would be carried out at approximately k points.\n* Taking k to be 50 often works well.\n* \n* Method\n* \n* The fitted values are computed by using the nearest neighbor\n* routine and robust locally weighted regression of degree 1\n* with the tricube weight function. A few additional features\n* have been added. Suppose r is FN truncated to an integer.\n* Let h be the distance to the r-th nearest neighbor\n* from X(I). All points within h of X(I) are used. Thus if\n* the r-th nearest neighbor is exactly the same distance as\n* other points, more than r points can possibly be used for\n* the smooth at X(I). There are two cases where robust\n* locally weighted regression of degree 0 is actually used at\n* X(I). One case occurs when h is 0.0. The second case\n* occurs when the weighted standard error of the X(I) with\n* respect to the weights w(j) is less than .001 times the\n* range of the X(I), where w(j) is the weight assigned to the\n* j-th point of X (the tricube weight times the robustness\n* weight) divided by the sum of all of the weights. Finally,\n* if the w(j) are all zero for the smooth at X(I), the fitted\n* value is taken to be Y(I).\n* \n* \n* \n* \n* subroutine lowess(x,y,n,f,nsteps,delta,ys,rw,res)\n* real x(n),y(n),ys(n),rw(n),res(n)\n* logical ok\n* if (n<2){ ys(1) = y(1); return }\n* ns = max0(min0(ifix(f*float(n)),n),2) # at least two, at most n points\n* for(iter=1; iter<=nsteps+1; iter=iter+1){ # robustness iterations\n* nleft = 1; nright = ns\n* last = 0 # index of prev estimated point\n* i = 1 # index of current point\n* repeat{\n* while(nright1,rw,ok)\n* # fitted value at x(i)\n* if (!ok) ys(i) = y(i)\n* # all weights zero - copy over value (all rw==0)\n* if (lastcut) break # i one beyond last pt within cut\n* if(x(i)==x(last)){ # exact match in x\n* ys(i) = ys(last)\n* last = i\n* }\n* }\n* i=max0(last+1,i-1)\n* # back 1 point so interpolation within delta, but always go forward\n* } until(last>=n)\n* do i = 1,n # residuals\n* res(i) = y(i)-ys(i)\n* if (iter>nsteps) break # compute robustness weights except last time\n* do i = 1,n\n* rw(i) = abs(res(i))\n* call sort(rw,n)\n* m1 = 1+n/2; m2 = n-m1+1\n* cmad = 3.0*(rw(m1)+rw(m2)) # 6 median abs resid\n* c9 = .999*cmad; c1 = .001*cmad\n* do i = 1,n {\n* r = abs(res(i))\n* if(r<=c1) rw(i)=1. # near 0, avoid underflow\n* else if(r>c9) rw(i)=0. # near 1, avoid underflow\n* else rw(i) = (1.0-(r/cmad)**2)**2\n* }\n* }\n* return\n* end\n* \n* \n* \n* \n* LOWEST\n* \n* \n* \n* Calling sequence\n* \n* CALL LOWEST(X,Y,N,XS,YS,NLEFT,NRIGHT,W,USERW,RW,OK)\n* \n* Purpose\n* \n* LOWEST is a support routine for LOWESS and ordinarily will\n* not be called by the user. The fitted value, YS, is\n* computed at the value, XS, of the horizontal axis.\n* Robustness weights, RW, can be employed in computing the\n* fit.\n* \n* Argument description\n* \n* \n* X = Input; abscissas of the points on the\n* scatterplot; the values in X must be ordered\n* from smallest to largest.\n* Y = Input; ordinates of the points on the\n* scatterplot.\n* N = Input; dimension of X,Y,W, and RW.\n* XS = Input; value of the horizontal axis at which the\n* smooth is computed.\n* YS = Output; fitted value at XS.\n* NLEFT = Input; index of the first point which should be\n* considered in computing the fitted value.\n* NRIGHT = Input; index of the last point which should be\n* considered in computing the fitted value.\n* W = Output; W(I) is the weight for Y(I) used in the\n* expression for YS, which is the sum from\n* I = NLEFT to NRIGHT of W(I)*Y(I); W(I) is\n* defined only at locations NLEFT to NRIGHT.\n* USERW = Input; logical variable; if USERW is .TRUE., a\n* robust fit is carried out using the weights in\n* RW; if USERW is .FALSE., the values in RW are\n* not used.\n* RW = Input; robustness weights.\n* OK = Output; logical variable; if the weights for the\n* smooth are all 0.0, the fitted value, YS, is not\n* computed and OK is set equal to .FALSE.; if the\n* fitted value is computed OK is set equal to\n* \n* \n* Method\n* \n* The smooth at XS is computed using (robust) locally weighted\n* regression of degree 1. The tricube weight function is used\n* with h equal to the maximum of XS-X(NLEFT) and X(NRIGHT)-XS.\n* Two cases where the program reverts to locally weighted\n* regression of degree 0 are described in the documentation\n* for LOWESS.\n* \n* \n* \n* \n* subroutine lowest(x,y,n,xs,ys,nleft,nright,w,userw,rw,ok)\n* real x(n),y(n),w(n),rw(n)\n* logical userw,ok\n* range = x(n)-x(1)\n* h = amax1(xs-x(nleft),x(nright)-xs)\n* h9 = .999*h\n* h1 = .001*h\n* a = 0.0 # sum of weights\n* for(j=nleft; j<=n; j=j+1){ # compute weights (pick up all ties on right)\n* w(j)=0.\n* r = abs(x(j)-xs)\n* if (r<=h9) { # small enough for non-zero weight\n* if (r>h1) w(j) = (1.0-(r/h)**3)**3\n* else w(j) = 1.\n* if (userw) w(j) = rw(j)*w(j)\n* a = a+w(j)\n* }\n* else if(x(j)>xs)break # get out at first zero wt on right\n* }\n* nrt=j-1 # rightmost pt (may be greater than nright because of ties)\n* if (a<=0.0) ok = FALSE\n* else { # weighted least squares\n* ok = TRUE\n* do j = nleft,nrt\n* w(j) = w(j)/a # make sum of w(j) == 1\n* if (h>0.) { # use linear fit\n* a = 0.0\n* do j = nleft,nrt\n* a = a+w(j)*x(j) # weighted center of x values\n* b = xs-a\n* c = 0.0\n* do j = nleft,nrt\n* c = c+w(j)*(x(j)-a)**2\n* if(sqrt(c)>.001*range) {\n* # points are spread out enough to compute slope\n* b = b/c\n* do j = nleft,nrt\n* w(j) = w(j)*(1.0+b*(x(j)-a))\n* }\n* }\n* ys = 0.0\n* do j = nleft,nrt\n* ys = ys+w(j)*y(j)\n* }\n* return\n* end\n* \n* \n* \nc test driver for lowess\nc for expected output, see introduction\n double precision x(20), y(20), ys(20), rw(20), res(20)\n data x /1,2,3,4,5,10*6,8,10,12,14,50/\n data y /18,2,15,6,10,4,16,11,7,3,14,17,20,12,9,13,1,8,5,19/\n call lowess(x,y,20,.25,0,0.,ys,rw,res)\n write(6,*) ys\n call lowess(x,y,20,.25,0,3.,ys,rw,res)\n write(6,*) ys\n call lowess(x,y,20,.25,2,0.,ys,rw,res)\n write(6,*) ys\n end\nc**************************************************************\nc Fortran output from ratfor\nc\n subroutine lowess(x, y, n, f, nsteps, delta, ys, rw, res)\n integer n, nsteps\n double precision x(n), y(n), f, delta, ys(n), rw(n), res(n)\n integer nright, i, j, iter, last, mid(2), ns, nleft\n double precision cut, cmad, r, d1, d2\n double precision c1, c9, alpha, denom, dabs\n logical ok\n if (n .ge. 2) goto 1\n ys(1) = y(1)\n return\nc at least two, at most n points\n 1 ns = max(min(int(f*dble(n)), n), 2)\n iter = 1\n goto 3\n 2 iter = iter+1\n 3 if (iter .gt. nsteps+1) goto 22\nc robustness iterations\n nleft = 1\n nright = ns\nc index of prev estimated point\n last = 0\nc index of current point\n i = 1\n 4 if (nright .ge. n) goto 5\nc move nleft, nright to right if radius decreases\n d1 = x(i)-x(nleft)\nc if d1<=d2 with x(nright+1)==x(nright), lowest fixes\n d2 = x(nright+1)-x(i)\n if (d1 .le. d2) goto 5\nc radius will not decrease by move right\n nleft = nleft+1\n nright = nright+1\n goto 4\nc fitted value at x(i)\n 5 call lowest(x, y, n, x(i), ys(i), nleft, nright, res, iter\n + .gt. 1, rw, ok)\n if (.not. ok) ys(i) = y(i)\nc all weights zero - copy over value (all rw==0)\n if (last .ge. i-1) goto 9\n denom = x(i)-x(last)\nc skipped points -- interpolate\nc non-zero - proof?\n j = last+1\n goto 7\n 6 j = j+1\n 7 if (j .ge. i) goto 8\n alpha = (x(j)-x(last))/denom\n ys(j) = alpha*ys(i)+(1.D0-alpha)*ys(last)\n goto 6\n 8 continue\nc last point actually estimated\n 9 last = i\nc x coord of close points\n cut = x(last)+delta\n i = last+1\n goto 11\n 10 i = i+1\n 11 if (i .gt. n) goto 13\nc find close points\n if (x(i) .gt. cut) goto 13\nc i one beyond last pt within cut\n if (x(i) .ne. x(last)) goto 12\n ys(i) = ys(last)\nc exact match in x\n last = i\n 12 continue\n goto 10\nc back 1 point so interpolation within delta, but always go forward\n 13 i = max(last+1, i-1)\n 14 if (last .lt. n) goto 4\nc residuals\n do 15 i = 1, n\n res(i) = y(i)-ys(i)\n 15 continue\n if (iter .gt. nsteps) goto 22\nc compute robustness weights except last time\n do 16 i = 1, n\n rw(i) = dabs(res(i))\n 16 continue\n call ssort(rw,n)\n mid(1) = n/2+1\n mid(2) = n-mid(1)+1\nc 6 median abs resid\n cmad = 3.D0*(rw(mid(1))+rw(mid(2)))\n c9 = .999999D0*cmad\n c1 = .000001D0*cmad\n do 21 i = 1, n\n r = dabs(res(i))\n if (r .gt. c1) goto 17\n rw(i) = 1.D0\nc near 0, avoid underflow\n goto 20\n 17 if (r .le. c9) goto 18\n rw(i) = 0.D0\nc near 1, avoid underflow\n goto 19\n 18 rw(i) = (1.D0-(r/cmad)**2.D0)**2.D0\n 19 continue\n 20 continue\n 21 continue\n goto 2\n 22 return\n end\n \n \n subroutine lowest(x, y, n, xs, ys, nleft, nright, w, userw\n +, rw, ok)\n integer n\n integer nleft, nright\n double precision x(n), y(n), xs, ys, w(n), rw(n)\n logical userw, ok\n integer nrt, j\n double precision dabs, a, b, c, h, r\n double precision h1, dsqrt, h9, max, range\n range = x(n)-x(1)\n h = max(xs-x(nleft), x(nright)-xs)\n h9 = .999999D0*h\n h1 = .000001D0*h\nc sum of weights\n a = 0.D0\n j = nleft\n goto 2\n 1 j = j+1\n 2 if (j .gt. n) goto 7\nc compute weights (pick up all ties on right)\n w(j) = 0.D0\n r = dabs(x(j)-xs)\n if (r .gt. h9) goto 5\n if (r .le. h1) goto 3\n w(j) = (1.D0-(r/h)**3.D0)**3.D0\nc small enough for non-zero weight\n goto 4\n 3 w(j) = 1.D0\n 4 if (userw) w(j) = rw(j)*w(j)\n a = a+w(j)\n goto 6\n 5 if (x(j) .gt. xs) goto 7\nc get out at first zero wt on right\n 6 continue\n goto 1\nc rightmost pt (may be greater than nright because of ties)\n 7 nrt = j-1\n if (a .gt. 0.D0) goto 8\n ok = .false.\n goto 16\n 8 ok = .true.\nc weighted least squares\n do 9 j = nleft, nrt\nc make sum of w(j) == 1\n w(j) = w(j)/a\n 9 continue\n if (h .le. 0.D0) goto 14\n a = 0.D0\nc use linear fit\n do 10 j = nleft, nrt\nc weighted center of x values\n a = a+w(j)*x(j)\n 10 continue\n b = xs-a\n c = 0.D0\n do 11 j = nleft, nrt\n c = c+w(j)*(x(j)-a)**2\n 11 continue\n if (dsqrt(c) .le. .0000001D0*range) goto 13\n b = b/c\nc points are spread out enough to compute slope\n do 12 j = nleft, nrt\n w(j) = w(j)*(b*(x(j)-a)+1.D0)\n 12 continue\n 13 continue\n 14 ys = 0.D0\n do 15 j = nleft, nrt\n ys = ys+w(j)*y(j)\n 15 continue\n 16 return\n end\n\n \n subroutine ssort(a,n)\n\nC Sorting by Hoare method, C.A.C.M. (1961) 321, modified by Singleton\nC C.A.C.M. (1969) 185.\n\t double precision a(n)\n\t integer iu(16), il(16)\n integer p\n\n i =1\n j = n\n m = 1\n 5 if (i.ge.j) goto 70\nc first order a(i),a(j),a((i+j)/2), and use median to split the data\n 10 k=i\n ij=(i+j)/2\n t=a(ij)\n if(a(i) .le. t) goto 20\n a(ij)=a(i)\n a(i)=t\n t=a(ij)\n 20 l=j\n if(a(j).ge.t) goto 40\n a(ij)=a(j)\n a(j)=t\n t=a(ij)\n if(a(i).le.t) goto 40\n a(ij)=a(i)\n a(i)=t\n t=a(ij)\n goto 40\n 30 a(l)=a(k)\n a(k)=tt\n 40 l=l-1\n if(a(l) .gt. t) goto 40\n tt=a(l)\nc split the data into a(i to l) .lt. t, a(k to j) .gt. t\n 50 k=k+1\n if(a(k) .lt. t) goto 50\n if(k .le. l) goto 30\n p=m\n m=m+1\nc split the larger of the segments\n if (l-i .le. j-k) goto 60\n il(p)=i\n iu(p)=l\n i=k\n goto 80\n 60 il(p)=k\n iu(p)=j\n j=l\n goto 80\n 70 m=m-1\n if(m .eq. 0) return\n i =il(m)\n j=iu(m)\nc short sections are sorted by bubble sort\n 80 if (j-i .gt. 10) goto 10\n if (i .eq. 1) goto 5\n i=i-1\n 90 i=i+1\n if(i .eq. j) goto 70\n t=a(i+1)\n if(a(i) .le. t) goto 90\n k=i\n 100 a(k+1)=a(k)\n k=k-1\n if(t .lt. a(k)) goto 100\n a(k+1)=t\n goto 90\n\n end ", "meta": {"hexsha": "fc357a57d7e895af2c229b5a2011f3fcca362481", "size": 22253, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/lowess.f", "max_stars_repo_name": "jcrotinger/pyloess", "max_stars_repo_head_hexsha": "c313d78ce8c42ef9fa75774bca0feeeaae6c7445", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-11-29T15:35:31.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-08T06:13:19.000Z", "max_issues_repo_path": "src/lowess.f", "max_issues_repo_name": "GT-Master/pyloess-py3", "max_issues_repo_head_hexsha": "ee214071b70f1cccee9d25e20d248b40b0c3fafd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-05-23T15:30:45.000Z", "max_issues_repo_issues_event_max_datetime": "2018-05-23T15:30:45.000Z", "max_forks_repo_path": "src/lowess.f", "max_forks_repo_name": "GT-Master/pyloess-py3", "max_forks_repo_head_hexsha": "ee214071b70f1cccee9d25e20d248b40b0c3fafd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-03-29T15:43:34.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-13T19:53:09.000Z", "avg_line_length": 36.1837398374, "max_line_length": 83, "alphanum_fraction": 0.5007414731, "num_tokens": 7004, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430353105599, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.665489584923823}} {"text": "c PLANCK -- Compute the Planck blackbody radiation distribution for a\nc given temperature and wavelength region.\nc\nc usage: planck temperature lambda1 lambda2\nc\nc The temperature is specified in degrees Kelvin and the wavelength\nc region in microns (1u=10000A). 100 [x,y] data points defining the\nc curve are output.\nc ----------------------------------------------------------------------\n\n program planck\n\n\tcharacter*80\terrmsg\n integer nargs, ier, i\n real w1, w2, dw, cm, t\n real xv(100), yv(100)\n\nc --- Get the temperature in degrees kelvin.\n call clargr (1, t, ier)\n if (ier .ne. 0) then\n write (*, '('' temperature (degrees kelvin): '',$)')\n read (*,*) t\n endif\n\nc --- Get the wavelength region to be computed.\n call clnarg (nargs)\n if (nargs .ge. 3) then\n call clargr (2, w1, ier)\n if (ier .ne. 0) goto 91\n call clargr (3, w2, ier)\n if (ier .ne. 0) goto 91\n else\n write (*, '('' start wavelength (microns): '',$)')\n read (*,*) w1\n write (*, '('' end wavelength (microns): '',$)')\n read (*,*) w2\n endif\n\nc --- Compute the blackbody curve.\n dw = (w2 - w1) / 99.0\n do 10 i = 1, 100\n xv(i) = ((i-1) * dw) + w1\n cm = xv(i) * 1.0E-4\n yv(i) = (3.74185E-5 * (cm ** -5)) /\n * (2.71828 ** (1.43883 / (cm * t)) - 1.0)\n 10\tcontinue\n\nc --- Print the curve as a table.\n do 20 i = 1, 100\n\t write (*, '(1x, f7.4, g12.4)') xv(i), yv(i)\n 20\tcontinue\n\n\tstop\n\nc --- Error exit. \n 91\tcall imemsg (ier, errmsg)\n\twrite (*, '('' Error: '', a80)') errmsg\n\tstop\n\tend\n", "meta": {"hexsha": "520183c09b5a8a9b6dbaf2fd5615435ddc9c20f4", "size": 1742, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iraf.v2161/sys/imfort/tasks/planck.f", "max_stars_repo_name": "ysBach/irafdocgen", "max_stars_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:19:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T16:48:42.000Z", "max_issues_repo_path": "sys/imfort/tasks/planck.f", "max_issues_repo_name": "kirxkirx/iraf", "max_issues_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-30T13:48:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-02T19:40:25.000Z", "max_forks_repo_path": "sys/imfort/tasks/planck.f", "max_forks_repo_name": "kirxkirx/iraf", "max_forks_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.0333333333, "max_line_length": 72, "alphanum_fraction": 0.4867967853, "num_tokens": 541, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256393148982, "lm_q2_score": 0.7905303285397349, "lm_q1q2_score": 0.6654886992207788}} {"text": "!****************************************************************\n!* Purpose: This program computes the spherical Bessel *\n!* functions jn(x) and jn'(x) using subroutine *\n!* SPHJ *\n!* Input : x --- Argument of jn(x) *\n!* n --- Order of jn(x) ( n = 0 to 250 ) *\n!* Output: SJ(n) --- jn(x) *\n!* DJ(n) --- jn'(x) *\n!* Example: x =10.0 *\n!* n jn(x) jn'(x) *\n!* -------------------------------------------- *\n!* 0 -.5440211109D-01 -.7846694180D-01 *\n!* 1 .7846694180D-01 -.7009549945D-01 *\n!* 2 .7794219363D-01 .5508428371D-01 *\n!* 3 -.3949584498D-01 .9374053162D-01 *\n!* 4 -.1055892851D+00 .1329879757D-01 *\n!* 5 -.5553451162D-01 -.7226857814D-01 *\n!* ------------------------------------------------------------ *\n!* REFERENCE: \"Fortran Routines for Computation of Special *\n!* Functions, *\n!* jin.ece.uiuc.edu/routines/routines.html\". *\n!* *\n!* F90 Release By J-P Moreau, Paris. *\n!* (www.jpmoreau.fr) *\n!****************************************************************\n! PROGRAM MSPHJ\n! IMPLICIT DOUBLE PRECISION (A-H,O-Z)\n! DIMENSION SJ(0:250),DJ(0:250)\n! WRITE(*,*)'Please enter n and x '\n! READ(*,*)N,X\n! WRITE(*,30)N,X\n! IF (N.LE.10) THEN\n! NS=1\n! ELSE\n! WRITE(*,*)'Please enter order step Ns'\n! READ(*,*)NS\n! ENDIF\n! CALL SPHJ(N,X,NM,SJ,DJ)\n! WRITE(*,*)\n! WRITE(*,*)' n jn(x) jn''(x)'\n! WRITE(*,*)'--------------------------------------------'\n! DO 10 K=0,NM,NS\n!10 WRITE(*,20)K,SJ(K),DJ(K)\n!20 FORMAT(1X,I3,2D20.10)\n!30 FORMAT(3X,6HNmax =,I3,', ',2Hx=,F5.1)\n! END\n\n MODULE msphj\n CONTAINS\n\n SUBROUTINE SPHJ(N,X,NM,SJ,DJ)\n\n! =======================================================\n! Purpose: Compute spherical Bessel functions jn(x) and\n! their derivatives\n! Input : x --- Argument of jn(x)\n! n --- Order of jn(x) ( n = 0,1,\u05ea\u05ea\u05ea )\n! Output: SJ(n) --- jn(x)\n! DJ(n) --- jn'(x)\n! NM --- Highest order computed\n! Routines called:\n! MSTA1 and MSTA2 for computing the starting\n! point for backward recurrence\n! =======================================================\n\n IMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION SJ(0:N),DJ(0:N)\n NM=N\n IF (DABS(X).EQ.1.0D-100) THEN\n DO 10 K=0,N\n SJ(K)=0.0D0\n10 DJ(K)=0.0D0\n SJ(0)=1.0D0\n DJ(1)=.3333333333333333D0\n RETURN\n ENDIF\n SJ(0)=DSIN(X)/X\n SJ(1)=(SJ(0)-DCOS(X))/X\n IF (N.GE.2) THEN\n SA=SJ(0)\n SB=SJ(1)\n M=MSTA1(X,200)\n IF (M.LT.N) THEN\n NM=M\n ELSE\n M=MSTA2(X,N,15)\n ENDIF\n F0=0.0D0\n F1=1.0D0-100\n DO 15 K=M,0,-1\n F=(2.0D0*K+3.0D0)*F1/X-F0\n IF (K.LE.NM) SJ(K)=F\n F0=F1\n15 F1=F\n IF (DABS(SA).GT.DABS(SB)) CS=SA/F\n IF (DABS(SA).LE.DABS(SB)) CS=SB/F0\n DO 20 K=0,NM\n20 SJ(K)=CS*SJ(K)\n ENDIF\n DJ(0)=(DCOS(X)-DSIN(X)/X)/X\n DO 25 K=1,NM\n25 DJ(K)=SJ(K-1)-(K+1.0D0)*SJ(K)/X\n RETURN\n END\n\n\n INTEGER FUNCTION MSTA1(X,MP)\n\n! ===================================================\n! Purpose: Determine the starting point for backward\n! recurrence such that the magnitude of\n! Jn(x) at that point is about 10^(-MP)\n! Input : x --- Argument of Jn(x)\n! MP --- Value of magnitude\n! Output: MSTA1 --- Starting point\n! ===================================================\n\n IMPLICIT DOUBLE PRECISION (A-H,O-Z)\n A0=DABS(X)\n N0=INT(1.1*A0)+1\n F0=ENVJ(N0,A0)-MP\n N1=N0+5\n F1=ENVJ(N1,A0)-MP\n DO 10 IT=1,20\n NN=N1-(N1-N0)/(1.0D0-F0/F1)\n F=ENVJ(NN,A0)-MP\n IF(ABS(NN-N1).LT.1) GO TO 20\n N0=N1\n F0=F1\n N1=NN\n 10 F1=F\n 20 MSTA1=NN\n RETURN\n END\n\n\n INTEGER FUNCTION MSTA2(X,N,MP)\n\n! ===================================================\n! Purpose: Determine the starting point for backward\n! recurrence such that all Jn(x) has MP\n! significant digits\n! Input : x --- Argument of Jn(x)\n! n --- Order of Jn(x)\n! MP --- Significant digit\n! Output: MSTA2 --- Starting point\n! ===================================================\n\n IMPLICIT DOUBLE PRECISION (A-H,O-Z)\n A0=DABS(X)\n HMP=0.5D0*MP\n EJN=ENVJ(N,A0)\n IF (EJN.LE.HMP) THEN\n OBJ=MP\n N0=INT(1.1*A0)\n ELSE\n OBJ=HMP+EJN\n N0=N\n ENDIF\n F0=ENVJ(N0,A0)-OBJ\n N1=N0+5\n F1=ENVJ(N1,A0)-OBJ\n DO 10 IT=1,20\n NN=N1-(N1-N0)/(1.0D0-F0/F1)\n F=ENVJ(NN,A0)-OBJ\n IF (ABS(NN-N1).LT.1) GO TO 20\n N0=N1\n F0=F1\n N1=NN\n10 F1=F\n20 MSTA2=NN+10\n RETURN\n END\n\n REAL*8 FUNCTION ENVJ(N,X)\n DOUBLE PRECISION X\n ENVJ=0.5D0*DLOG10(6.28D0*N)-N*DLOG10(1.36D0*X/N)\n RETURN\n END\n\n END MODULE\n\n!end of file msphj.f90\n", "meta": {"hexsha": "7c61564882d60ea3d0f8b779f217839166b875a6", "size": 6060, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/SpherePEC/BESSEL_LIB/msphj.f90", "max_stars_repo_name": "Riarrieta/WindowedGreenFunctionMethod", "max_stars_repo_head_hexsha": "e6f965cac1acd8d9922e2bf94c33e3577ceb0dc9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/SpherePEC/BESSEL_LIB/msphj.f90", "max_issues_repo_name": "Riarrieta/WindowedGreenFunctionMethod", "max_issues_repo_head_hexsha": "e6f965cac1acd8d9922e2bf94c33e3577ceb0dc9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/SpherePEC/BESSEL_LIB/msphj.f90", "max_forks_repo_name": "Riarrieta/WindowedGreenFunctionMethod", "max_forks_repo_head_hexsha": "e6f965cac1acd8d9922e2bf94c33e3577ceb0dc9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.9347826087, "max_line_length": 65, "alphanum_fraction": 0.3633663366, "num_tokens": 1798, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256472515683, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.6654886971860875}} {"text": "program solver\n use Utils\n use Types\n use MKL_wrapper\n use gausets\n implicit none\n integer(4) NMAX \n !PARAMETER ( NMAX = 10000 )\n complex(8), dimension(:,:), allocatable :: RA, RB\n\n\tcomplex(8), dimension (:,:), allocatable :: MA\n\tcomplex(8), dimension (:,:), allocatable :: MB\t \n\n\tcomplex(DPT), dimension (:,:), allocatable :: A\n\tcomplex(DPT), dimension (:,:), allocatable :: B\t\n \n\tinteger, dimension( 4 ) ::\tISEED\n\n CHARACTER(len=32) :: arg\n integer stat\n integer(4) N\n \n real time_init, time_mkl, time_gauset\n real T1,T2\n print *, 'Solve the complex equations A*X = B.'\n print *, 'and calc exec time'\n CALL getarg(1, arg)\n READ(arg,*,iostat=stat)N\n if (stat<0) then\n print *, \"set default size\"\n N = 4\n end if\n print *, \"N=\", N \n\n NMAX = 2*N\n\n allocate ( RA(NMAX, NMAX) )\n allocate ( RB(NMAX, 1) )\n\n call random_z(NMAX,\tRB)\n call random_z(NMAX*NMAX,\tRA)\n\n\n MA = RA(1:N, 1:N)\n MB = RB(1:N, 1:1)\n\n time_init = sys_time()\n !call cpu_time(T1) \n\n call mkl_le_solver(MA,MB)\n\n !call cpu_time(T2)\n time_mkl = sys_time() - time_init\n\n print *, 'mkl_le_solver exec time', time_mkl, T2-T1\n print *, \"---------\"\n\n\n A = RA(1:N, 1:N)\n B = RB(1:N, 1:1)\n time_init = sys_time()\n call gauset (A,B)\n time_gauset = sys_time() - time_init\n \n print *, \"---------\"\n\n print *,'Err sum: ', SUM(CDABS(B-MB))\n print *,'Time ratio: ',time_gauset/time_mkl\n\nend program solver", "meta": {"hexsha": "2094b831a2cc6dc4406e7945b381fd875becedf6", "size": 1507, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/solver.f90", "max_stars_repo_name": "temper8/FTEST", "max_stars_repo_head_hexsha": "88a6ce48a4dedec38cc05f2bd167add1e86c4767", "max_stars_repo_licenses": ["MIT"], "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/solver.f90", "max_issues_repo_name": "temper8/FTEST", "max_issues_repo_head_hexsha": "88a6ce48a4dedec38cc05f2bd167add1e86c4767", "max_issues_repo_licenses": ["MIT"], "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/solver.f90", "max_forks_repo_name": "temper8/FTEST", "max_forks_repo_head_hexsha": "88a6ce48a4dedec38cc05f2bd167add1e86c4767", "max_forks_repo_licenses": ["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.5285714286, "max_line_length": 56, "alphanum_fraction": 0.5653616457, "num_tokens": 499, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240686758841, "lm_q2_score": 0.7690802370707283, "lm_q1q2_score": 0.665426731856549}} {"text": " SUBROUTINE colsol(a,maxa,neq,task,iw,ish,nsymm,v,u)\r\n !.....................................................................\r\n !. .\r\n !. P R O G R A M .\r\n !. TO SOLVE EQUILIBRIUM EQUATIONS FROM FINITE ELEMENTS .\r\n !. IN FAST MEMORY USING COMPACT STORAGE WITH SKYLINE SCHEME .\r\n !. .\r\n !. --INPUT VARIABLE .\r\n !. A(:) = STIFFNES MATRIX IN COMPACT FORM .\r\n !. V(NEQ) = LOADING VECTOR .\r\n !. MAXA(NEQ+1)= VECTOR CONTAINING THE DIAGONAL POSITIONS IN A .\r\n !. NEQ = NUMBER OF EQUATION .\r\n !. TASK = FLAG .\r\n !. EQ. 1 MATRIX FACTORIZATION .\r\n !. EQ. 2 BACK SUBSTITUTION OF VECTOR V .\r\n !. IW = NUMBER ASSOCIATED TO OUTPUT DEVICE FOR MESSAGES .\r\n !. ISH = FLAG TO INDICATE IF NON-POSSITIVE MATRICES ALLOWED .\r\n !. EQ. 0 ONLY POSSITIVE MATRICES ALLOWED .\r\n !. EQ. 1 ANY NON-SINGULAR MATRIZ ALLOWED .\r\n !. NSYMM = INDICATES IF MATRIZ IS SYMMETRIC .\r\n !. EQ. 0 SYMMETRIC MATRIX .\r\n !. EQ. 1 NON-SYMMETRIC MATRIX .\r\n !. IN THE LAST CASE .\r\n !. U(:) = UPPER PART OF THE NON-SYMMETRIC MATRIX .\r\n !. .\r\n !.-- OUTPUT .\r\n !. TASK = 1 .\r\n !. A(:) = D & L - FACTOR OF THE STIFFNES MATRIX .\r\n !. U(:) = UPPER TRIANGULAR FACTOR FOR NON-SYMMETRIC MATRIX .\r\n !. TASK = 2 .\r\n !. V(NEQ) = EQUATION SOLUTION .\r\n !. .\r\n !.....................................................................\r\n IMPLICIT NONE\r\n !.....................................................................\r\n INTEGER (kind=4),INTENT(IN) :: neq,task,iw,ish,maxa(:),nsymm\r\n REAL (kind=8),INTENT(IN OUT) :: a(:)\r\n REAL (kind=8),INTENT(IN OUT), OPTIONAL :: u(:),v(:)\r\n !Local Variables\r\n INTEGER (kind=4) :: n,kn,kl,ku,k,ic,klt,ki,nd,l,kh,j,kk\r\n REAL (kind=8) :: b,c,d\r\n !\r\n IF(task == 1) THEN\r\n\r\n ! L*D*U Factorization of Stiffness Matrix\r\n\r\n IF(nsymm == 0 .OR. nsymm == -1) THEN ! U = L(T)\r\n DO n=1,neq !para cada fila i==N\r\n kn = maxa(n) !pos. de K(i,i)\r\n kl = kn+1 !pos. de K(i,i-1)\r\n ku = maxa(n+1)-1 !pos.del 1ro de la fila K(i,Jmin)\r\n kh = ku-kl !long de la fila sin extremos\r\n IF(kh > 0) THEN !si hay val.de g(i,j) a calcular\r\n k = n - kh !ec. asoc. al 1ro de la fila Jmin\r\n ic = 0 !contador\r\n klt = ku !pos del el (i,j) = (i,Jmin)\r\n DO j=1,kh !calculo de los g(i,j)\r\n ic = ic + 1 !num de terminos de la sumatoria\r\n klt = klt - 1 !pos de g(i,j)\r\n ki = maxa(k) !pos de d(j,j)\r\n nd = maxa(k+1) - ki - 1 !long. fila j - diagonal\r\n IF(nd > 0) THEN !num de terminos de la sumatoria\r\n kk = MIN(ic,nd) !numero definitivo de terminos\r\n c = 0.d0 !pone a 0 el acumulador\r\n DO l=1,kk ! KI+L==(j,j-l) KLT+L==(i,j-l)\r\n c = c + a(ki+l)*a(klt+l) !+l(j,k)*g(i,k)\r\n END DO\r\n a(klt) = a(klt) - c !g(i,j) --> A\r\n END IF\r\n k = k + 1 !pasa a la siguiente col. k==j\r\n END DO\r\n END IF\r\n IF(kh >= 0) THEN !si hay el. fuera de la diagonal\r\n k = n !K==j N==i --> j=i\r\n b = 0.d0 !pone a 0 el acumulador diag.\r\n DO kk=kl,ku !para c/ter. no diag.\r\n k = k - 1 !decrementa j (hasta Jmin)\r\n ki = maxa(k) !pos. de d(j,j)\r\n c = a(kk)/a(ki) !l(i,j)=g(i,j)/d(j,j)\r\n b = b + c*a(kk) !+l(i,j)*g(i,j)\r\n a(kk) = c !l(j,i) --> A\r\n END DO\r\n a(kn) = a(kn) - b !d(n,n) --> A\r\n END IF\r\n IF(a(kn) <= 0) THEN\r\n IF(ish == 0) THEN\r\n WRITE(iw,8000)\r\n WRITE(iw,8020)n,a(kn)\r\n STOP\r\n ELSE\r\n WRITE(iw,8020) n,a(kn)\r\n IF(a(kn) == 0) a(kn) = 1.d-16\r\n END IF\r\n END IF\r\n END DO\r\n ELSE ! U <> L(T)\r\n DO n=1,neq !para cada fila i==N\r\n kn = maxa(n) !pos. de K(i,i)\r\n kl = kn + 1 !pos. de K(i,i-1) y U(i-1,i)\r\n ku = maxa(n+1) - 1 !pos.de K(Jmin,i) y U(i,Jmin)\r\n kh = ku - kl !long. de la fila sin extremos\r\n IF(kh > 0) THEN !si hay val.de g(i,j) a calcular\r\n k = n - kh !ec. asoc. al 1ro de la fila Jmin\r\n ic = 0 !contador\r\n klt = ku !pos del el (i,j) = (i,Jmin)\r\n DO j=1,kh !calculo de los g(i,j) y f(j,i)\r\n ic = ic + 1 !num de terminos de la sumatoria\r\n klt = klt - 1 !pos de g(i,j) y f(j.i)\r\n ki = maxa(k) !pos de d(j,j)\r\n nd = maxa(k+1) - ki - 1 !long. fila j - diagonal\r\n IF(nd > 0) THEN !num de terminos de la sumatoria\r\n kk = MIN(ic,nd) !numero definitivo de terminos\r\n c = 0.d0 !pone a 0 el acumulador de g(i.j)\r\n d = 0.d0 !pone a 0 el acumulador de f(j.i)\r\n DO l=1,kk ! KI+L==(j,j-l) KLT+L==(i,j-l)\r\n c = c + u(ki+l)*a(klt+l) !+u(k,j)*g(i,k)\r\n d = d + a(ki+l)*u(klt+l) !+l(j,k)*f(k,i)\r\n END DO\r\n a(klt) = a(klt) - c !g(i,j) --> A\r\n u(klt) = u(klt) - d !f(j,i) --> U\r\n END IF\r\n k = k + 1 !pasa a la siguiente col. k==j\r\n END DO\r\n END IF\r\n IF(kh >= 0) THEN !si hay el. fuera de la diagonal\r\n k = n !K==j N==i --> j=i\r\n b = 0.d0 !pone a 0 el acumulador diag.\r\n DO kk=kl,ku !para c/ter. no diag.\r\n k = k - 1 !decrementa j (hasta Jmin)\r\n ki = maxa(k) !pos. de d(j,j)\r\n c = a(kk)/a(ki) !l(i,j)=g(i,j)/d(j,j)\r\n d = u(kk)/a(ki) !u(j,i)=f(j,i)/d(j,j)\r\n b = b + c*u(kk) !+l(i,j)*f(j,i)\r\n a(kk) = c !l(i,j) --> A\r\n u(kk) = d !u(j,i) --> U\r\n END DO\r\n a(kn) = a(kn) - b !d(i,i) --> A\r\n END IF\r\n IF(a(kn) <= 0) THEN\r\n IF(ish == 0) THEN\r\n WRITE(iw,8000)\r\n WRITE(iw,8020) n,a(kn)\r\n STOP\r\n ELSE\r\n WRITE(iw,8020) n,a(kn)\r\n IF(a(kn) == 0) a(kn) = 1.d-16\r\n END IF\r\n END IF\r\n END DO\r\n END IF\r\n ! d = MINVAL(a(maxa(1:neq)))\r\n ! WRITE(IW,\"(' minimum pivot =',e15.4)\")d\r\n ELSE\r\n\r\n ! Reduce Independent vector\r\n\r\n DO n=1,neq\r\n kl = maxa(n)+1\r\n ku = maxa(n+1)-1\r\n IF(ku-kl >= 0) THEN\r\n k = n\r\n c = 0.d0\r\n DO kk=kl,ku\r\n k = k-1\r\n c = c + a(kk)*v(k)\r\n END DO\r\n v(n) = v(n) - c\r\n END IF\r\n END DO\r\n\r\n ! Back-Substitution\r\n\r\n DO n=1,neq\r\n k = maxa(n)\r\n v(n) = v(n)/a(k)\r\n END DO\r\n n = neq\r\n IF(nsymm == 0 .OR. nsymm == -1) THEN ! Symmetric Matrix\r\n DO l=2,neq\r\n kl = maxa(n)+1\r\n ku = maxa(n+1)-1\r\n k = n\r\n DO kk=kl,ku\r\n k = k-1\r\n v(k) = v(k) - a(kk)*v(n)\r\n END DO\r\n n = n-1\r\n END DO\r\n ELSE !Non-symmetric matrix\r\n DO l=2,neq\r\n kl = maxa(n)+1\r\n ku = maxa(n+1)-1\r\n k = n\r\n DO kk=kl,ku\r\n k = k - 1\r\n v(k) = v(k) - u(kk)*v(n)\r\n END DO\r\n n = n-1\r\n END DO\r\n END IF\r\n\r\n END IF\r\n 8000 FORMAT(//,' STOP - Non-Positive Stiffness Matrix ',//)\r\n 8020 FORMAT(' Non-positive pivot for equation',I5,' PIVOT=',E20.12)\r\n\r\n RETURN\r\n END SUBROUTINE colsol\r\n", "meta": {"hexsha": "c2d3bffd351a344c4748c6f6aa937a1a9f3a5ec1", "size": 9379, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/solve/colsol.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/solve/colsol.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/solve/colsol.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": 45.0913461538, "max_line_length": 76, "alphanum_fraction": 0.3279667342, "num_tokens": 2652, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379297, "lm_q2_score": 0.7461389873857265, "lm_q1q2_score": 0.665414990382463}} {"text": "!------------------------------------------------------------------------\n subroutine ncperiodogram_no_norm(ht, st, rc, ic, dim)\n! Calculates a cross spectrum between the time series ht(int_len_dim) and st(int_len_dim)\n! Phase is such that +ve lag corresponds to ht lagging st\n! ***MODIFIED*** from Press et al (1992) DFT definition, this is S^*(\\nu)H(\\nu)\n ! use dyn_lc\n implicit none\n integer, intent(IN) :: dim\n double precision , intent(IN) :: ht(dim), st(dim) \n double precision , intent(OUT) :: rc(dim / 2), ic(dim / 2) \n integer :: j\n double precision , allocatable :: datah(:), datas(:)\n if (.not. allocated(datah)) allocate(datah(2 * dim))\n if (.not. allocated(datas)) allocate(datas(2 * dim))\n\n do j = 1, dim \n datah(2 * j - 1) = ht(j)\n datah(2 * j) = 0.d0\n datas(2 * j - 1) = st(j)\n datas(2 * j) = 0.d0\n end do\n call four1(datah, dim, 1)\n call four1(datas, dim, 1)\n \n do j = 1, dim / 2\n rc(j) = datah(2 * j + 1) * datas(2 * j + 1) + datah(2 * j + 2) * datas(2 * j + 2)\n ic(j) = datah(2 * j + 2) * datas(2 * j + 1) - datah(2 * j + 1) * datas(2 * j + 2)\n\n end do\n if (allocated(datah)) deallocate(datah)\n if (allocated(datas)) deallocate(datas)\n return\n end subroutine ncperiodogram_no_norm\n!------------------------------------------------------------------------\n\n!------------------------------------------------------------------------\n subroutine periodogram_no_norm(time_series, pw, dim)\n! Calculates power spectrum of the time series lc(dim)\n! ***MODIFIED*** from Press et al (1992) DFT definition\n ! use dyn_lc\n implicit none\n integer, intent(IN) :: dim\n double precision , intent(IN) :: time_series(dim)\n double precision , intent(OUT) :: pw(dim / 2)\n\n integer :: j\n double precision ,allocatable :: datah(:)\n\n if (.not. allocated(datah)) allocate(datah(2 * dim))\n ! sum = 0.d0\n \n\n do j = 1, dim\n datah(2 * j - 1) = time_series(j)\n datah(2 * j) = 0.d0\n end do\n\n call four1(datah, dim, 1)\n\n do j = 1, dim / 2\n pw(j) = (datah(2 * j + 1)**2 + datah(2 * j + 2 )**2)\n end do\n \n if (allocated(datah)) deallocate(datah)\n return\n end subroutine periodogram_no_norm\n!------------------------------------------------------------------------\n\n!------------------------------------------------------------------------\n subroutine ncperiodogram_frac_rms(ht, st, rc, ic, dt, dim)\n! Calculates a cross spectrum between the time series ht(int_len_dim) and st(int_len_dim)\n! In fractional rms normalisation\n! Phase is such that +ve lag corresponds to ht lagging st\n! ***MODIFIED*** from Press et al (1992) DFT definition, this is S^*(\\nu)H(\\nu)\n ! use dyn_lc\n implicit none\n integer, intent(IN) :: dim\n double precision , intent(IN) :: dt, ht(dim), st(dim) \n double precision , intent(OUT) :: rc(dim / 2), ic(dim / 2) \n integer :: j\n double precision :: meanh, means\n double precision , allocatable :: datah(:), datas(:)\n if (.not. allocated(datah)) allocate(datah(2 * dim))\n if (.not. allocated(datas)) allocate(datas(2 * dim))\n\n do j = 1, dim \n datah(2 * j - 1) = ht(j)\n datah(2 * j) = 0.d0\n datas(2 * j - 1) = st(j)\n datas(2 * j) = 0.d0\n end do\n call four1(datah, dim, 1)\n call four1(datas, dim, 1)\n\n meanh = datah(1) / dim\n means = datas(1) / dim\n \n do j = 1, dim / 2\n rc(j) = datah(2 * j + 1) * datas(2 * j + 1) + datah(2 * j + 2) * datas(2 * j + 2)\n rc(j) = rc(j) * 2.d0 * dt / (dble(dim) * meanh * means) \n ic(j) = datah(2 * j + 2) * datas(2 * j + 1) - datah(2 * j + 1) * datas(2 * j + 2)\n ic(j) = ic(j) * 2.d0 * dt / (dble(dim) * meanh * means) \n\n end do\n if (allocated(datah)) deallocate(datah)\n if (allocated(datas)) deallocate(datas)\n return\n end subroutine ncperiodogram_frac_rms\n!------------------------------------------------------------------------\n\n!------------------------------------------------------------------------\n subroutine periodogram_frac_rms(time_series, pw, dt, dim)\n! Calculates power spectrum of the time series lc(dim)\n! In fractional rms normalisation\n! ***MODIFIED*** from Press et al (1992) DFT definition\n ! use dyn_lc\n implicit none\n integer, intent(IN) :: dim\n double precision , intent(IN) :: dt, time_series(dim)\n double precision , intent(OUT) :: pw(dim / 2)\n\n integer :: j\n double precision :: mean !sum, var\n double precision ,allocatable :: datah(:)\n\n if (.not. allocated(datah)) allocate(datah(2 * dim))\n ! sum = 0.0\n \n\n do j = 1, dim\n datah(2 * j - 1) = time_series(j)\n datah(2 * j) = 0.d0\n end do\n\n call four1(datah, dim, 1)\n mean = datah(1) / dim\n\n do j = 1, dim / 2\n pw(j) = (datah(2 * j + 1)**2 + datah(2 * j + 2 )**2) * 2. * dt / (float(dim) * mean**2) \n end do\n \n if (allocated(datah)) deallocate(datah)\n return\n end subroutine periodogram_frac_rms\n!------------------------------------------------------------------------\n\n!------------------------------------------------------------------------\n subroutine ncperiodogram(ht, st, rc, ic, dt, dim)\n! Calculates a cross spectrum between the time series ht(int_len_dim) and st(int_len_dim)\n! In absolute rms normalisation\n! Phase is such that +ve lag corresponds to ht lagging st\n! ***MODIFIED*** from Press et al (1992) DFT definition, this is S^*(\\nu)H(\\nu)\n ! use dyn_lc\n implicit none\n integer, intent(IN) :: dim\n double precision , intent(IN) :: dt, ht(dim), st(dim) \n double precision , intent(OUT) :: rc(dim / 2), ic(dim / 2) \n integer :: j\n double precision :: meanh, means\n double precision , allocatable :: datah(:), datas(:)\n if (.not. allocated(datah)) allocate(datah(2 * dim))\n if (.not. allocated(datas)) allocate(datas(2 * dim))\n\n do j = 1, dim \n datah(2 * j - 1) = ht(j)\n datah(2 * j) = 0.d0\n datas(2 * j - 1) = st(j)\n datas(2 * j) = 0.d0\n end do\n call four1(datah, dim, 1)\n call four1(datas, dim, 1)\n\n meanh = datah(1) / dim\n means = datas(1) / dim\n \n do j = 1, dim / 2\n rc(j) = datah(2 * j + 1) * datas(2 * j + 1) + datah(2 * j + 2) * datas(2 * j + 2)\n rc(j) = rc(j) * 2.d0 * dt / (dble(dim) ) \n ic(j) = datah(2 * j + 2) * datas(2 * j + 1) - datah(2 * j + 1) * datas(2 * j + 2)\n ic(j) = ic(j) * 2.d0 * dt / (dble(dim)) \n\n end do\n if (allocated(datah)) deallocate(datah)\n if (allocated(datas)) deallocate(datas)\n return\n end subroutine ncperiodogram\n!------------------------------------------------------------------------\n\n!------------------------------------------------------------------------\n subroutine periodogram(time_series, pw, dt, dim)\n! Calculates power spectrum between the time series lc(dim)\n! In absolute rms normalisation\n! Phase is such that +ve lag corresponds to ht lagging st\n! ***MODIFIED*** from Press et al (1992) DFT definition\n ! use dyn_lc\n implicit none\n integer, intent(IN) :: dim\n double precision , intent(IN) :: dt, time_series(dim)\n double precision , intent(OUT) :: pw(dim / 2)\n\n integer :: j\n ! double precision :: mean, sum, var\n double precision ,allocatable :: datah(:)\n\n if (.not. allocated(datah)) allocate(datah(2 * dim))\n ! sum = 0.0\n do j = 1, dim\n ! sum = sum + time_series(j)**2\n datah(2 * j - 1) = time_series(j)\n datah(2 * j) = 0.d0\n end do\n\n call four1(datah, dim, 1)\n ! mean = datah(1) / dim\n ! write(*,*) 'mean ', mean\n \n do j = 1, dim / 2\n pw(j) = (datah(2 * j + 1)**2 + datah(2 * j + 2 )**2) * 2.d0 * dt / (float(dim)) \n end do\n\n!Check the Parseval theorem\n ! sum = 0.d0\n ! do j = 1, dim\n ! sum = sum + time_series(j)**2\n ! enddo \n ! var = 0.d0\n ! do j = 0, dim - 1\n ! ! write(*,*) 2 * j + 1, 2 * j + 2 \n ! var = var + datah(2 * j + 1)**2 + datah(2 * j + 2 )**2\n ! ! write(111,*) j, datah(2 * j + 1)**2 + datah(2 * j + 2 )**2\n ! enddo\n ! var = var / dim\n\n ! write(*,*) 'Parseval theorem'\n ! write(*,*) sum, var\n\n ! ! var = 0.0\n ! ! do j = 1, dim / 2 \n ! ! var = var + pw(j)\n ! ! enddo\n ! ! var = (2 * var + datah(1)**2) / dim\n ! ! write(*,*) 'Parcival theorem'\n ! ! write(*,*) sum, var\n \n if (allocated(datah)) deallocate(datah)\n return\n end subroutine periodogram\n!------------------------------------------------------------------------\n\n\n!------------------------------------------------------------------------\n subroutine periodogram_leahy(ht, pw, dt, dim)\n! Calculates power spectrum between the time series ht(int_len_dim)\n! In leahy normalisation \n! Phase is such that +ve lag corresponds to ht lagging st\n! ***MODIFIED*** from Press et al (1992) DFT definition\n ! use dyn_lc\n implicit none\n integer , intent(IN) :: dim\n double precision , intent(IN) :: ht(dim), dt\n double precision , intent(OUT) :: pw(dim / 2)\n\n integer :: j\n ! double precision :: sum!, var sum2, par\n double precision ,allocatable :: datah(:)\n\n if (.not. allocated(datah)) allocate(datah(2 * dim))\n ! sum = 0.0\n ! sum2 = 0.0\n do j = 1, dim\n ! sum = sum + ht(j)\n ! sum2 = sum2 + ht(j)**2\n datah(2 * j - 1) = ht(j)\n datah(2 * j) = 0.d0\n end do\n call four1(datah, dim, 1)\n \n ! write(*,*) ' number of photons: ', sum, datah(1)\n\n do j = 1, dim / 2\n pw(j) = (datah(2 * j + 1)**2 + datah(2 * j + 2 )**2) * 2.d0 * dt / datah(1)\n ! write(11, *) j, pw(j)\n end do\n ! write(11, *) 'no no'\n \n!Check the Parseval theorem\n ! par = 0.d0\n ! do j = 0, dim - 1\n ! ! write(*,*) 2 * j + 1, 2 * j + 2 \n ! par = par + datah(2 * j + 1)**2 + datah(2 * j + 2 )**2\n ! ! write(111,*) j, datah(2 * j + 1)**2 + datah(2 * j + 2 )**2\n ! enddo\n ! par = par / dble(dim)\n\n ! write(*,*) 'Parseval theorem'\n ! write(*,*) sum2, par\n\n! !CHECK THE VARIANCE CALCULATION \n\n! !First the variance from the light curve\n! var = (sum2 / dble(dim)) - (sum / dble(dim))**2 \n! write(*,*) 'variance from lc', var\n \n! !Then variance from the fourier transform \n! var = 0.d0\n! do j = 1, dim - 1\n! var = var + datah(2 * j + 1)**2 + datah(2 * j + 2 )**2\n! enddo\n! var = var / dble(dim)\n! write(*,*) 'variance from ft', var\n\n! ! do j = 0, dim - 1\n! ! write(10,*) j, datah(2 * j + 1)\n! ! enddo\n! ! write(10, *) 'no no'\n \n if (allocated(datah)) deallocate(datah)\n return\n end subroutine periodogram_leahy\n!------------------------------------------------------------------------\n\n\n!-----------------------------------------------------------------------\n SUBROUTINE four1(data,nn,isign)\n INTEGER isign,nn\n DOUBLE PRECISION data(2*nn)\n INTEGER i,istep,j,m,mmax,n\n DOUBLE PRECISION tempi,tempr\n DOUBLE PRECISION theta,wi,wpi,wpr,wr,wtemp\n n=2*nn\n j=1\n ! write(*,*) 'ciao ciao '\n\n ! do i = 1, nn\n ! write(*,*) i, data(2 * i - 1), data(2 * i)\n ! enddo\n ! write(*,*) 'ciao ciao '\n \n do 11 i=1,n,2\n if(j.gt.i)then\n tempr=data(j)\n tempi=data(j+1)\n data(j)=data(i)\n data(j+1)=data(i+1)\n data(i)=tempr\n data(i+1)=tempi\n endif\n m=n/2\n1 if ((m.ge.2).and.(j.gt.m)) then\n j=j-m\n m=m/2\n goto 1\n endif\n j=j+m\n11 continue\n mmax=2\n2 if (n.gt.mmax) then\n istep=2*mmax\n theta=6.28318530717959d0/(isign*mmax)\n wpr=-2.d0*sin(0.5d0*theta)**2\n wpi=sin(theta)\n wr=1.d0\n wi=0.d0\n do 13 m=1,mmax,2\n do 12 i=m,n,istep\n j=i+mmax\n tempr=sngl(wr)*data(j)-sngl(wi)*data(j+1)\n tempi=sngl(wr)*data(j+1)+sngl(wi)*data(j)\n data(j)=data(i)-tempr\n data(j+1)=data(i+1)-tempi\n data(i)=data(i)+tempr\n data(i+1)=data(i+1)+tempi\n12 continue\n wtemp=wr\n wr=wr*wpr-wi*wpi+wr\n wi=wi*wpr+wtemp*wpi+wi\n13 continue\n mmax=istep\n goto 2\n endif\n return\n end\n!---------------------------------------------------------------\n\n!----------------------------------------------------------------\n subroutine ncperiodogram_no_norm_real(ht, st, rc, ic, dim)\n! Calculates a cross spectrum between the time series ht(int_len_dim) and st(int_len_dim)\n! Phase is such that +ve lag corresponds to ht lagging st\n! ***MODIFIED*** from Press et al (1992) DFT definition, this is S^*(\\nu)H(\\nu)\n use dyn_lc\n implicit none\n integer, intent(IN) :: dim\n real , intent(IN) :: ht(dim), st(dim) \n real , intent(OUT) :: rc(dim / 2), ic(dim / 2) \n integer :: j\n real , allocatable :: datah(:), datas(:)\n if (.not. allocated(datah)) allocate(datah(2 * dim))\n if (.not. allocated(datas)) allocate(datas(2 * dim))\n\n do j = 1, dim \n datah(2 * j - 1) = ht(j)\n datah(2 * j) = 0.0\n datas(2 * j - 1) = st(j)\n datas(2 * j) = 0.0\n end do\n call four1_real(datah, dim, 1)\n call four1_real(datas, dim, 1)\n \n do j = 1, dim / 2\n rc(j) = datah(2 * j + 1) * datas(2 * j + 1) + datah(2 * j + 2) * datas(2 * j + 2)\n ic(j) = datah(2 * j + 2) * datas(2 * j + 1) - datah(2 * j + 1) * datas(2 * j + 2)\n\n end do\n if (allocated(datah)) deallocate(datah)\n if (allocated(datas)) deallocate(datas)\n return\n end subroutine ncperiodogram_no_norm_real\n!-----------------------------------------------------------------\n\n!-----------------------------------------------------------------\n subroutine periodogram_no_norm_real(time_series, pw, dim)\n! Calculates power spectrum of the time series lc(dim)\n! ***MODIFIED*** from Press et al (1992) DFT definition\n use dyn_lc\n implicit none\n integer, intent(IN) :: dim\n real , intent(IN) :: time_series(dim)\n real , intent(OUT) :: pw(dim / 2)\n\n integer :: j\n real ,allocatable :: datah(:)\n\n if (.not. allocated(datah)) allocate(datah(2 * dim))\n ! sum = 0.0\n \n\n do j = 1, dim\n datah(2 * j - 1) = time_series(j)\n datah(2 * j) = 0.0\n end do\n\n call four1_real(datah, dim, 1)\n\n do j = 1, dim / 2\n pw(j) = (datah(2 * j + 1)**2 + datah(2 * j + 2 )**2)\n end do\n \n if (allocated(datah)) deallocate(datah)\n return\n end subroutine periodogram_no_norm_real\n!-------------------------------------------------------------------\n\n!-------------------------------------------------------------------\n subroutine ncperiodogram_frac_rms_real(ht, st, rc, ic, dim)\n! Calculates a cross spectrum between the time series ht(int_len_dim) and st(int_len_dim)\n! In fractional rms normalisation\n! Phase is such that +ve lag corresponds to ht lagging st\n! ***MODIFIED*** from Press et al (1992) DFT definition, this is S^*(\\nu)H(\\nu)\n use dyn_lc\n implicit none\n integer, intent(IN) :: dim\n real , intent(IN) :: ht(dim), st(dim) \n real , intent(OUT) :: rc(dim / 2), ic(dim / 2) \n integer :: j\n real :: meanh, means\n real , allocatable :: datah(:), datas(:)\n if (.not. allocated(datah)) allocate(datah(2 * dim))\n if (.not. allocated(datas)) allocate(datas(2 * dim))\n\n do j = 1, dim \n datah(2 * j - 1) = ht(j)\n datah(2 * j) = 0.0\n datas(2 * j - 1) = st(j)\n datas(2 * j) = 0.0\n end do\n call four1_real(datah, dim, 1)\n call four1_real(datas, dim, 1)\n\n meanh = datah(1) / dim\n means = datas(1) / dim\n \n do j = 1, dim / 2\n rc(j) = datah(2 * j + 1) * datas(2 * j + 1) + datah(2 * j + 2) * datas(2 * j + 2)\n rc(j) = rc(j) * 2. * real(dt) / (real(dim) * meanh * means) \n ic(j) = datah(2 * j + 2) * datas(2 * j + 1) - datah(2 * j + 1) * datas(2 * j + 2)\n ic(j) = ic(j) * 2. * real(dt) / (real(dim) * meanh * means) \n\n end do\n if (allocated(datah)) deallocate(datah)\n if (allocated(datas)) deallocate(datas)\n return\n end subroutine ncperiodogram_frac_rms_real\n!-------------------------------------------------------------------\n\n!-------------------------------------------------------------------\n subroutine periodogram_frac_rms_real(time_series, pw, dim)\n! Calculates power spectrum of the time series lc(dim)\n! In fractional rms normalisation\n! ***MODIFIED*** from Press et al (1992) DFT definition\n use dyn_lc\n implicit none\n integer, intent(IN) :: dim\n real , intent(IN) :: time_series(dim)\n real , intent(OUT) :: pw(dim / 2)\n\n integer :: j\n real :: mean !sum, var\n real ,allocatable :: datah(:)\n\n if (.not. allocated(datah)) allocate(datah(2 * dim))\n ! sum = 0.0\n \n\n do j = 1, dim\n datah(2 * j - 1) = time_series(j)\n datah(2 * j) = 0.0\n end do\n\n call four1_real(datah, dim, 1)\n mean = datah(1) / dim\n\n do j = 1, dim / 2\n pw(j) = (datah(2 * j + 1)**2 + datah(2 * j + 2 )**2) * 2. * real(dt) / (float(dim) * mean**2) \n end do\n \n if (allocated(datah)) deallocate(datah)\n return\n end subroutine periodogram_frac_rms_real\n!------------------------------------------------------------------\n\n!------------------------------------------------------------------\n subroutine ncperiodogram_real(ht, st, rc, ic, dim)\n! Calculates a cross spectrum between the time series ht(int_len_dim) and st(int_len_dim)\n! In absolute rms normalisation\n! Phase is such that +ve lag corresponds to ht lagging st\n! ***MODIFIED*** from Press et al (1992) DFT definition, this is S^*(\\nu)H(\\nu)\n use dyn_lc\n implicit none\n integer, intent(IN) :: dim\n real , intent(IN) :: ht(dim), st(dim) \n real , intent(OUT) :: rc(dim / 2), ic(dim / 2) \n integer :: j\n real :: meanh, means\n real , allocatable :: datah(:), datas(:)\n if (.not. allocated(datah)) allocate(datah(2 * dim))\n if (.not. allocated(datas)) allocate(datas(2 * dim))\n\n do j = 1, dim \n datah(2 * j - 1) = ht(j)\n datah(2 * j) = 0.0\n datas(2 * j - 1) = st(j)\n datas(2 * j) = 0.0\n end do\n call four1_real(datah, dim, 1)\n call four1_real(datas, dim, 1)\n\n meanh = datah(1) / dim\n means = datas(1) / dim\n \n do j = 1, dim / 2\n rc(j) = datah(2 * j + 1) * datas(2 * j + 1) + datah(2 * j + 2) * datas(2 * j + 2)\n rc(j) = rc(j) * 2.0 * real(dt) / (real(dim) ) \n ic(j) = datah(2 * j + 2) * datas(2 * j + 1) - datah(2 * j + 1) * datas(2 * j + 2)\n ic(j) = ic(j) * 2.0 * real(dt) / (real(dim)) \n\n end do\n if (allocated(datah)) deallocate(datah)\n if (allocated(datas)) deallocate(datas)\n return\n end subroutine ncperiodogram_real\n!-------------------------------------------------------------------\n\n!-------------------------------------------------------------------\n subroutine periodogram_real(time_series, pw, dim)\n! Calculates power spectrum between the time series lc(dim)\n! In absolute rms normalisation\n! Phase is such that +ve lag corresponds to ht lagging st\n! ***MODIFIED*** from Press et al (1992) DFT definition\n use dyn_lc\n implicit none\n integer, intent(IN) :: dim\n real , intent(IN) :: time_series(dim)\n real , intent(OUT) :: pw(dim / 2)\n\n integer :: j\n real :: mean !sum, var\n real ,allocatable :: datah(:)\n\n if (.not. allocated(datah)) allocate(datah(2 * dim))\n ! sum = 0.0\n \n\n do j = 1, dim\n ! sum = sum + ht(j)**2\n datah(2 * j - 1) = time_series(j)\n datah(2 * j) = 0.0\n end do\n\n call four1_real(datah, dim, 1)\n mean = datah(1) / dim\n\n do j = 1, dim / 2\n pw(j) = (datah(2 * j + 1)**2 + datah(2 * j + 2 )**2) * 2. * real(dt) / (float(dim)) \n end do\n\n!Check the Parcival theorem\n! var = 0.0\n! do j = 0, dim - 1\n! ! write(*,*) 2 * j + 1, 2 * j + 2\n! var = var + datah(2 * j + 1)**2 + datah(2 * j + 2 )**2\n! write(111,*) j, datah(2 * j + 1)**2 + datah(2 * j + 2 )**2\n! enddo\n! var = var / dim\n! write(*,*) 'Parcival theorem'\n! write(*,*) sum, var\n\n! var = 0.0\n! do j = 1, dim / 2 \n! var = var + pw(j)\n! enddo\n! var = (2 * var + datah(1)**2) / dim\n! write(*,*) 'Parcival theorem'\n! write(*,*) sum, var\n \n if (allocated(datah)) deallocate(datah)\n return\n end subroutine periodogram_real\n!-------------------------------------------------------------------\n\n\n!-------------------------------------------------------------------\n subroutine periodogram_leahy_real(ht, pw)\n! Calculates power spectrum between the time series ht(int_len_dim)\n! In leahy normalisation \n! Phase is such that +ve lag corresponds to ht lagging st\n! ***MODIFIED*** from Press et al (1992) DFT definition\n use dyn_lc\n implicit none\n real , intent(IN) :: ht(int_len_dim)\n real , intent(OUT) :: pw(int_len_dim / 2)\n\n integer :: j\n real :: mean\n real ,allocatable :: datah(:)\n\n if (.not. allocated(datah)) allocate(datah(2 * int_len_dim))\n ! sum = 0.0\n do j = 1, int_len_dim\n ! sum = sum + ht(j)**2\n datah(2 * j - 1) = ht(j)\n datah(2 * j) = 0.0\n end do\n call four1_real(datah, int_len_dim, 1)\n mean = datah(1) / int_len_dim\n do j = 1, int_len_dim / 2\n pw(j) = (datah(2 * j + 1)**2 + datah(2 * j + 2 )**2) * 2.0 / datah(1) \n end do\n \n if (allocated(datah)) deallocate(datah)\n return\n end subroutine periodogram_leahy_real\n!-----------------------------------------------------------------\n\n!-----------------------------------------------------------------\n SUBROUTINE four1_real(data,nn,isign)\n INTEGER isign,nn\n REAL data(2*nn)\n INTEGER i,istep,j,m,mmax,n\n REAL tempi,tempr\n DOUBLE PRECISION theta,wi,wpi,wpr,wr,wtemp\n n=2*nn\n j=1\n ! write(*,*) 'ciao ciao '\n\n ! do i = 1, nn\n ! write(*,*) i, data(2 * i - 1), data(2 * i)\n ! enddo\n ! write(*,*) 'ciao ciao '\n \n do 11 i=1,n,2\n if(j.gt.i)then\n tempr=data(j)\n tempi=data(j+1)\n data(j)=data(i)\n data(j+1)=data(i+1)\n data(i)=tempr\n data(i+1)=tempi\n endif\n m=n/2\n1 if ((m.ge.2).and.(j.gt.m)) then\n j=j-m\n m=m/2\n goto 1\n endif\n j=j+m\n11 continue\n mmax=2\n2 if (n.gt.mmax) then\n istep=2*mmax\n theta=6.28318530717959d0/(isign*mmax)\n wpr=-2.d0*sin(0.5d0*theta)**2\n wpi=sin(theta)\n wr=1.d0\n wi=0.d0\n do 13 m=1,mmax,2\n do 12 i=m,n,istep\n j=i+mmax\n tempr=sngl(wr)*data(j)-sngl(wi)*data(j+1)\n tempi=sngl(wr)*data(j+1)+sngl(wi)*data(j)\n data(j)=data(i)-tempr\n data(j+1)=data(i+1)-tempi\n data(i)=data(i)+tempr\n data(i+1)=data(i+1)+tempi\n12 continue\n wtemp=wr\n wr=wr*wpr-wi*wpi+wr\n wi=wi*wpr+wtemp*wpi+wi\n13 continue\n mmax=istep\n goto 2\n endif\n return\n end\n!-----------------------------------------------------------------------\n\n\n\n\n!---------------------------------------------------------------------!\nsubroutine cross_FT(lc1, lc2, rc, ic, NN, dt)\n! This subroutine calculates the cross-spectrum between lc1 and lc2\n! lc2 is the complex cojugate light curve (reference light curve)\n\n! re1, im1, re2, im2 are the real and imaginary part to calculare the \n! Fourier transform \n implicit none \n integer , intent(IN) :: NN\n double precision, intent(IN) :: lc1(NN), lc2(NN), dt\n double precision, intent(OUT) :: rc(NN / 2), ic(NN / 2)\n \n integer :: i\n double precision, allocatable :: re1(:), im1(:), re2(:), im2(:)\n\n allocate (re1(NN / 2))\n allocate (im1(NN / 2))\n allocate (re2(NN / 2))\n allocate (im2(NN / 2))\n \n call FT_not_fast(lc1, re1, im1, NN)\n call FT_not_fast(lc2, re2, im2, NN)\n\n do i = 1, NN / 2 \n rc(i) = (re1(i) * re2(i) + im1(i) * im2(i)) * 2 * dt / (real(NN))\n ic(i) = (im1(i) * re2(i) - re1(i) * im2(i)) * 2 * dt / (real(NN))\n enddo\n\n end subroutine Cross_FT\n!---------------------------------------------------------------------!\n\n\n!---------------------------------------------------------------------!\nsubroutine power_FT(lc1, pw, NN, dt)\n! This subroutine calculates the power-spectrum of lc1\n! re1, im1 are the real and imaginary part to calculare the Fourier transform \n implicit none \n integer , intent(IN) :: NN\n double precision, intent(IN) :: lc1(NN), dt \n double precision, intent(OUT) :: pw(NN / 2)\n \n integer :: i\n double precision, allocatable :: re1(:), im1(:)\n\n allocate (re1(NN / 2))\n allocate (im1(NN / 2))\n \n call FT_not_fast(lc1, re1, im1, NN)\n\n do i = 1, NN / 2 \n pw(i) = (re1(i) * re1(i) + im1(i) * im1(i) ) * 2 * dt / (real(NN))\n enddo\n\nend subroutine Power_FT\n!---------------------------------------------------------------------!\n\n\n!---------------------------------------------------------------------!\nsubroutine FT_not_fast(time_series, re, im, NN)\n! This subroutine calculates the Fourier transfor of a series time_series with NN data points \n! re and im are respectively the real and the imaginary part of the FT\n! re and im don't store the average of the light curve, so they have NN/2\n! The first frequency is nu = 1/(NN*dt) the last is the Nyquist frequency nuNy = 1/(2*dt)\n implicit none \n integer , intent(IN) :: NN\n double precision, intent(IN) :: time_series(NN)\n double precision, intent(INOUT) :: re(NN / 2), im(NN / 2)\n \n integer :: n, k\n double precision :: arg\n double precision, parameter :: pi = acos(-1.0)\n \n\n do n = 1, NN / 2 \n re(n) = 0.0 \n im(n) = 0.0 \n\n do k = 1, NN \n arg = 2.0 * pi * real(k * n) / real(NN)\n re(n) = re(n) + time_series(k) * cos(arg)\n im(n) = im(n) + time_series(k) * sin(arg)\n enddo\n re(n) = re(n) / real(NN)\n im(n) = im(n) / real(NN)\n enddo\n\nend subroutine FT_not_fast\n!---------------------------------------------------------------------!\n\n\n!-----------------------------------------------------------------------\nsubroutine SFT(at,nnmax,nn,Af)\n implicit none\n integer nnmax,nn,j,k\n real at(nnmax)\n complex Af(nnmax/2)\n real pi,arg\n pi = acos(-1.0)\n do j = 1,nn/2\n Af(j) = 0.0\n do k = 1,nn\n arg = 2.0 * pi * real( j * k ) / real(nn)\n Af(j) = Af(j) + at(k) * complex( cos(arg) , sin(arg) )\n end do\n Af(j) = Af(j) / real(nn)\n end do\n return\nend subroutine SFT\n!-----------------------------------------------------------------------\n", "meta": {"hexsha": "5f6dcbfe3e4b291b68379bb0ba7c1691c4134868", "size": 28913, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "subroutines/fft.f90", "max_stars_repo_name": "mgullik/data_analysis", "max_stars_repo_head_hexsha": "b91ae014bfa280ba7e7fa3a48600b18eeb74eafe", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "subroutines/fft.f90", "max_issues_repo_name": "mgullik/data_analysis", "max_issues_repo_head_hexsha": "b91ae014bfa280ba7e7fa3a48600b18eeb74eafe", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "subroutines/fft.f90", "max_forks_repo_name": "mgullik/data_analysis", "max_forks_repo_head_hexsha": "b91ae014bfa280ba7e7fa3a48600b18eeb74eafe", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.5023866348, "max_line_length": 104, "alphanum_fraction": 0.4514232352, "num_tokens": 8583, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.7461389817407016, "lm_q1q2_score": 0.6654149896391386}} {"text": "program Faddeeva_w_test\n use faddeeva_fortran_interface, only: Faddeeva_w, find_relerr, dp\n ! -----------------------------------------------------------------------\n implicit none\n complex(dp), allocatable :: res(:)\n real(dp), allocatable :: re_err(:), im_err(:)\n real(dp) :: relerr, errmax\n integer :: i, num_args\n include '/references/reference_data.f90'\n ! -----------------------------------------------------------------------\n num_args = size(Faddeeva_w_args)\n allocate(res(1:num_args))\n allocate(re_err(1:num_args))\n allocate(im_err(1:num_args))\n relerr = 0.0_dp\n errmax = 0.0_dp\n do i = 1, num_args\n res(i) = Faddeeva_w(Faddeeva_w_args(i), relerr)\n re_err(i) = find_relerr(real(res(i)), real(Faddeeva_w_wolfram_refs(i)))\n im_err(i) = find_relerr(aimag(res(i)), aimag(Faddeeva_w_wolfram_refs(i)))\n print *, \"w(\", real(Faddeeva_w_args(i)),\"+i*\", aimag(Faddeeva_w_args(i)),\") = \", real(res(i)),\"+i*\", &\n aimag(res(i)), \" (vs.\", real(Faddeeva_w_wolfram_refs(i)),\"+i*\", aimag(Faddeeva_w_wolfram_refs(i)),\"), &\n re/im rel. err. = \", re_err(i),\"/\", im_err(i)\n if (re_err(i) > errmax) errmax = re_err(i)\n if (im_err(i) > errmax) errmax = im_err(i)\n if (errmax > 1e-13) then\n print *, \"FAILURE -- relative error\", errmax, \"is too large!\"\n stop 1\n end if\n end do\n print *, \"SUCCESS (max relative error = \", errmax\nend program Faddeeva_w_test", "meta": {"hexsha": "4426968c814286bc7e9a23e4de875b85bcaeb613", "size": 1502, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/Faddeeva_w_test.f90", "max_stars_repo_name": "ArtyomShalev/Faddeeva_Fortran", "max_stars_repo_head_hexsha": "4942a69081929355ed1bc0f14f69bea71eceae59", "max_stars_repo_licenses": ["MIT"], "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/tests/Faddeeva_w_test.f90", "max_issues_repo_name": "ArtyomShalev/Faddeeva_Fortran", "max_issues_repo_head_hexsha": "4942a69081929355ed1bc0f14f69bea71eceae59", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/tests/Faddeeva_w_test.f90", "max_forks_repo_name": "ArtyomShalev/Faddeeva_Fortran", "max_forks_repo_head_hexsha": "4942a69081929355ed1bc0f14f69bea71eceae59", "max_forks_repo_licenses": ["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.9375, "max_line_length": 119, "alphanum_fraction": 0.5459387483, "num_tokens": 444, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110339361275, "lm_q2_score": 0.7461389817407016, "lm_q1q2_score": 0.6654149767662244}} {"text": "\n SUBROUTINE DSPLINE(X,Y,A,B,C,N) ! Double Precision\n IMPLICIT REAL*8 (A-H),REAL*8 (O-Z)\n DIMENSION X(N),Y(N),A(N),B(N),C(N)\nC\nC-----COMPUTATION OF CUBIC SPLINE COEFFICIENTS A,B,C\nC-----FOR APPROXIMATION OF A DATA ARRAY (X,Y) SUCH THAT\nC-----F(X)=Y(I)+DEL*[A(I)+DEL*(B(I)+C(I)*DEL)] IN THE\nC-----INTERVAL X(I) null() !age of universe in Mpc\n\n! Model specific parameters\n character(len=8), save :: model\n real(dp), save :: alpha,amp,r0,dlr\n\n! Observer position\n real(dp), save :: r_obs,theta_obs\n\ncontains\n\n subroutine get_age\n implicit none\n real(dp) :: q\n if (.not. associated(ct2)) then\n allocate(ct2)\n if (abs(FLRW%Ok) < 1.e-8_dp) then\n q=sqrt(abs(FLRW%Ol))\n ct2=log((1._dp+q)/(1._dp-q))/(3._dp*q*H0)\n else\n STOP 'Hardcoded to work for Ok=0 only!'\n end if\n else\n return\n end if\n end subroutine get_age\n \nend module cosmo_params\n\n", "meta": {"hexsha": "1b38ef0467a54124026a9870bb8e6f341c728052", "size": 1677, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "cosmo_params.f90", "max_stars_repo_name": "lhd23/ray-sz", "max_stars_repo_head_hexsha": "a835bed8fbea6cbb76ebd46b16adc498a63f8dd8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cosmo_params.f90", "max_issues_repo_name": "lhd23/ray-sz", "max_issues_repo_head_hexsha": "a835bed8fbea6cbb76ebd46b16adc498a63f8dd8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cosmo_params.f90", "max_forks_repo_name": "lhd23/ray-sz", "max_forks_repo_head_hexsha": "a835bed8fbea6cbb76ebd46b16adc498a63f8dd8", "max_forks_repo_licenses": ["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": 60, "alphanum_fraction": 0.5384615385, "num_tokens": 565, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218327098193, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6653908250136282}} {"text": "\n! ----------------------------------------------------------------------\n subroutine regint(f,a,b,c,n)\n! ----------------------------------------------------------------------\n use stel_kinds\n implicit none\n integer :: i, n\n real(rprec), dimension(n) :: f, a, b, c\n real(rprec) :: sqp, sqm, sqa, sqc, top, tom\nc ----------------------------------------------------------------------\n do i=1,n\n sqp = sqrt(a(i)+2._dp*b(i)+c(i))\n sqm = sqrt(a(i)-2._dp*b(i)+c(i))\n sqa = sqrt(a(i))\n sqc = sqrt(c(i))\n top = log((sqc*sqp+c(i)+b(i))/(sqa*sqp-a(i)-b(i)))/sqp\n tom = log((sqc*sqm+c(i)-b(i))/(sqa*sqm-a(i)+b(i)))/sqm\n f(i) = top + tom\n enddo\n\n end subroutine regint\n", "meta": {"hexsha": "6f29b0dadb05536c3c394e97f16a4785ed3524c6", "size": 781, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "BNORM/Sources/regint.f", "max_stars_repo_name": "joseluisvelasco/STELLOPT", "max_stars_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2020-05-08T01:47:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T10:35:28.000Z", "max_issues_repo_path": "BNORM/Sources/regint.f", "max_issues_repo_name": "joseluisvelasco/STELLOPT", "max_issues_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 77, "max_issues_repo_issues_event_min_datetime": "2020-05-08T07:18:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:20:33.000Z", "max_forks_repo_path": "BNORM/Sources/regint.f", "max_forks_repo_name": "joseluisvelasco/STELLOPT", "max_forks_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-02-10T13:47:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T12:53:43.000Z", "avg_line_length": 35.5, "max_line_length": 72, "alphanum_fraction": 0.323943662, "num_tokens": 220, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9219218370002789, "lm_q2_score": 0.7217431943271999, "lm_q1q2_score": 0.6653908115565814}} {"text": "!***********************************/\n!\tName:FluxDifferenceSplitting\u6cd5\u3067\u7528\u3044\u308b\u5de6\u53f3\u306e\u56fa\u6709\u884c\u5217\u3092\u8a08\u7b97\u3059\u308b\u305f\u3081\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\n!\tAlias:GetEigenMatrix\n!\tDescription:\u7279\u6027\u901f\u5ea6\u306e\u7d76\u5bfe\u5024\u3092\u6210\u5206\u306b\u6301\u3064\u5bfe\u89d2\u884c\u5217\u306b\u5de6\u53f3\u306e\u56fa\u6709\u884c\u5217\u3092\u4f5c\u7528\u3055\u305b\u308b\u3068\u3044\u308f\u3086\u308b|A|\u304c\u5f97\u3089\u308c\uff0c\u7279\u6027\u901f\u5ea6\u304c\u3069\u3061\u3089\u306b\u5411\u3044\u3066\u3044\u3066\u3082\u98a8\u4e0a\u6cd5\u3067\u6271\u3048\u308b\u3088\u3046\u306b\u306a\u308b\n!\tType:FDSMatrix\n!\tInput:Geometory,RoeAverage,FDSMatrix\n!\tOutput:FDSMatrix\n!\tNote:\n!\tAuthor:Akitaka Toyota\n!\tDate:2017.10.26\n!\tUpdate:2017.11.09\n!\tOther:1\u6b21\u5143\u30682\u6b21\u5143\u306b\u5bfe\u5fdc\n!***********************************/\n subroutine GetEigenMatrix(Geom,RA,FM,SP4O)\n use StructVar_Mod\n !use LoopVar_Mod\n use ConstantVar_Mod, Gamma => SpecificOfHeatRatio, Epsilon => EntropyCorrection\n implicit none\n type(Geometry), intent(in) :: Geom\n type(RoeAverage), intent(in) :: RA\n type(FDSMatrix), intent(inout) :: FM\n type(PrivateVar4OMP), intent(inout) :: SP4O\n\n if(Geom%Dimension == 1) then\n FM%RightEigenMatrix(1,1) = 1.0d0\n FM%RightEigenMatrix(1,2) = 1.0d0\n FM%RightEigenMatrix(1,3) = 1.0d0\n FM%RightEigenMatrix(2,1) = RA%RoeAverage(2) - RA%RoeAverage(1)\n FM%RightEigenMatrix(2,2) = RA%RoeAverage(2)\n FM%RightEigenMatrix(2,3) = RA%RoeAverage(2) + RA%RoeAverage(1)\n FM%RightEigenMatrix(3,1) = RA%RoeAverage(3) - RA%RoeAverage(2)*RA%RoeAverage(1)\n FM%RightEigenMatrix(3,2) = 0.5d0 * RA%RoeAverage(2)**2\n FM%RightEigenMatrix(3,3) = RA%RoeAverage(3) + RA%RoeAverage(2)*RA%RoeAverage(1)\n\n SP4O%GEM%CalcAssistB2 = Gmin1/RA%RoeAverage(1)**2\n SP4O%GEM%CalcAssistB1 = 0.5d0*RA%RoeAverage(2)**2 * SP4O%GEM%CalcAssistB2\n\n FM%LeftEigenMatrix(1,1) = 0.5d0*(SP4O%GEM%CalcAssistB1 + RA%RoeAverage(2)/RA%RoeAverage(1))\n FM%LeftEigenMatrix(1,2) = -0.5d0*(1.0d0/RA%RoeAverage(1) + SP4O%GEM%CalcAssistB2*RA%RoeAverage(2))\n FM%LeftEigenMatrix(1,3) = 0.5d0*(SP4O%GEM%CalcAssistB2)\n FM%LeftEigenMatrix(2,1) = 1.0d0 - SP4O%GEM%CalcAssistB1\n FM%LeftEigenMatrix(2,2) = SP4O%GEM%CalcAssistB2 * RA%RoeAverage(2)\n FM%LeftEigenMatrix(2,3) = -SP4O%GEM%CalcAssistB2\n FM%LeftEigenMatrix(3,1) = 0.5d0*(SP4O%GEM%CalcAssistB1 - RA%RoeAverage(2)/RA%RoeAverage(1))\n FM%LeftEigenMatrix(3,2) = 0.5d0*(1.0d0/RA%RoeAverage(1) - SP4O%GEM%CalcAssistB2*RA%RoeAverage(2))\n FM%LeftEigenMatrix(3,3) = 0.5d0*(SP4O%GEM%CalcAssistB2)\n\n FM%AbsEigenValues = 0.0d0\n FM%AbsEigenValues(1,1) = dabs(RA%RoeAverage(2) - RA%RoeAverage(1))\n FM%AbsEigenValues(2,2) = dabs(RA%RoeAverage(2))\n FM%AbsEigenValues(3,3) = dabs(RA%RoeAverage(2) + RA%RoeAverage(1))\n\n else if(Geom%Dimension == 2) then\n if(RA%Direction == 1) then\n FM%RightEigenMatrix(1,1) = 1.0d0\n FM%RightEigenMatrix(1,2) = 1.0d0\n FM%RightEigenMatrix(1,3) = 1.0d0\n FM%RightEigenMatrix(1,4) = 0.0d0\n FM%RightEigenMatrix(2,1) = RA%RoeAverage(2) - RA%RoeAverage(1)\n FM%RightEigenMatrix(2,2) = RA%RoeAverage(2)\n FM%RightEigenMatrix(2,3) = RA%RoeAverage(2) + RA%RoeAverage(1)\n FM%RightEigenMatrix(2,4) = 0.0d0\n FM%RightEigenMatrix(3,1) = RA%RoeAverage(3)\n FM%RightEigenMatrix(3,2) = RA%RoeAverage(3)\n FM%RightEigenMatrix(3,3) = RA%RoeAverage(3)\n FM%RightEigenMatrix(3,4) = 1.0d0\n FM%RightEigenMatrix(4,1) = RA%RoeAverage(4) - RA%RoeAverage(2)*RA%RoeAverage(1)\n FM%RightEigenMatrix(4,2) = 0.5d0 * (RA%RoeAverage(2)**2 + RA%RoeAverage(3)**2)\n FM%RightEigenMatrix(4,3) = RA%RoeAverage(4) + RA%RoeAverage(2)*RA%RoeAverage(1)\n FM%RightEigenMatrix(4,4) = RA%RoeAverage(3)\n\n SP4O%GEM%CalcAssistB2 = Gmin1/RA%RoeAverage(1)**2\n SP4O%GEM%CalcAssistB1 = 0.5d0*(RA%RoeAverage(2)**2 + RA%RoeAverage(3)**2) * SP4O%GEM%CalcAssistB2\n\n FM%LeftEigenMatrix(1,1) = 0.5d0*(SP4O%GEM%CalcAssistB1 + RA%RoeAverage(2)/RA%RoeAverage(1))\n FM%LeftEigenMatrix(1,2) = -0.5d0*(1.0d0/RA%RoeAverage(1) + SP4O%GEM%CalcAssistB2*RA%RoeAverage(2))\n FM%LeftEigenMatrix(1,3) = -0.5d0*(SP4O%GEM%CalcAssistB2*RA%RoeAverage(3))\n FM%LeftEigenMatrix(1,4) = 0.5d0*(SP4O%GEM%CalcAssistB2)\n FM%LeftEigenMatrix(2,1) = 1.0d0 - SP4O%GEM%CalcAssistB1\n FM%LeftEigenMatrix(2,2) = SP4O%GEM%CalcAssistB2 * RA%RoeAverage(2)\n FM%LeftEigenMatrix(2,3) = SP4O%GEM%CalcAssistB2 * RA%RoeAverage(3)\n FM%LeftEigenMatrix(2,4) = - SP4O%GEM%CalcAssistB2\n FM%LeftEigenMatrix(3,1) = 0.5d0*(SP4O%GEM%CalcAssistB1 - RA%RoeAverage(2)/RA%RoeAverage(1))\n FM%LeftEigenMatrix(3,2) = 0.5d0*(1.0d0/RA%RoeAverage(1) - SP4O%GEM%CalcAssistB2*RA%RoeAverage(2))\n FM%LeftEigenMatrix(3,3) = -0.5d0*(SP4O%GEM%CalcAssistB2*RA%RoeAverage(3))\n FM%LeftEigenMatrix(3,4) = 0.5d0*(SP4O%GEM%CalcAssistB2)\n FM%LeftEigenMatrix(4,1) = -RA%RoeAverage(3)\n FM%LeftEigenMatrix(4,2) = 0.0d0\n FM%LeftEigenMatrix(4,3) = 1.0d0\n FM%LeftEigenMatrix(4,4) = 0.0d0\n\n FM%AbsEigenValues = 0.0d0\n FM%AbsEigenValues(1,1) = dabs(RA%RoeAverage(2) - RA%RoeAverage(1))\n FM%AbsEigenValues(2,2) = dabs(RA%RoeAverage(2))\n FM%AbsEigenValues(3,3) = dabs(RA%RoeAverage(2) + RA%RoeAverage(1))\n FM%AbsEigenValues(4,4) = dabs(RA%RoeAverage(2))\n\n else if(RA%Direction == 2) then\n FM%RightEigenMatrix(1,1) = 1.0d0\n FM%RightEigenMatrix(1,2) = 1.0d0\n FM%RightEigenMatrix(1,3) = 1.0d0\n FM%RightEigenMatrix(1,4) = 0.0d0\n FM%RightEigenMatrix(2,1) = RA%RoeAverage(2)\n FM%RightEigenMatrix(2,2) = RA%RoeAverage(2)\n FM%RightEigenMatrix(2,3) = RA%RoeAverage(2)\n FM%RightEigenMatrix(2,4) = 1.0d0\n FM%RightEigenMatrix(3,1) = RA%RoeAverage(3) - RA%RoeAverage(1)\n FM%RightEigenMatrix(3,2) = RA%RoeAverage(3)\n FM%RightEigenMatrix(3,3) = RA%RoeAverage(3) + RA%RoeAverage(1)\n FM%RightEigenMatrix(3,4) = 0.0d0\n FM%RightEigenMatrix(4,1) = RA%RoeAverage(4) - RA%RoeAverage(3)*RA%RoeAverage(1)\n FM%RightEigenMatrix(4,2) = 0.5d0 * (RA%RoeAverage(2)**2 + RA%RoeAverage(3)**2)\n FM%RightEigenMatrix(4,3) = RA%RoeAverage(4) + RA%RoeAverage(3)*RA%RoeAverage(1)\n FM%RightEigenMatrix(4,4) = RA%RoeAverage(2)\n\n SP4O%GEM%CalcAssistB2 = Gmin1/RA%RoeAverage(1)**2\n SP4O%GEM%CalcAssistB1 = 0.5d0*(RA%RoeAverage(2)**2 + RA%RoeAverage(3)**2) * SP4O%GEM%CalcAssistB2\n\n FM%LeftEigenMatrix(1,1) = 0.5d0*(SP4O%GEM%CalcAssistB1 + RA%RoeAverage(3)/RA%RoeAverage(1))\n FM%LeftEigenMatrix(1,2) = -0.5d0*(SP4O%GEM%CalcAssistB2*RA%RoeAverage(2))\n FM%LeftEigenMatrix(1,3) = -0.5d0*(1.0d0/RA%RoeAverage(1) + SP4O%GEM%CalcAssistB2*RA%RoeAverage(3))\n FM%LeftEigenMatrix(1,4) = 0.5d0*(SP4O%GEM%CalcAssistB2)\n FM%LeftEigenMatrix(2,1) = 1.0d0 - SP4O%GEM%CalcAssistB1\n FM%LeftEigenMatrix(2,2) = SP4O%GEM%CalcAssistB2 * RA%RoeAverage(2)\n FM%LeftEigenMatrix(2,3) = SP4O%GEM%CalcAssistB2 * RA%RoeAverage(3)\n FM%LeftEigenMatrix(2,4) = - SP4O%GEM%CalcAssistB2\n FM%LeftEigenMatrix(3,1) = 0.5d0*(SP4O%GEM%CalcAssistB1 - RA%RoeAverage(3)/RA%RoeAverage(1))\n FM%LeftEigenMatrix(3,2) = -0.5d0*(SP4O%GEM%CalcAssistB2*RA%RoeAverage(2))\n FM%LeftEigenMatrix(3,3) = 0.5d0*(1.0d0/RA%RoeAverage(1) - SP4O%GEM%CalcAssistB2*RA%RoeAverage(3))\n FM%LeftEigenMatrix(3,4) = 0.5d0*(SP4O%GEM%CalcAssistB2)\n FM%LeftEigenMatrix(4,1) = -RA%RoeAverage(2)\n FM%LeftEigenMatrix(4,2) = 1.0d0\n FM%LeftEigenMatrix(4,3) = 0.0d0\n FM%LeftEigenMatrix(4,4) = 0.0d0\n\n FM%AbsEigenValues = 0.0d0\n FM%AbsEigenValues(1,1) = dabs(RA%RoeAverage(3) - RA%RoeAverage(1))\n FM%AbsEigenValues(2,2) = dabs(RA%RoeAverage(3))\n FM%AbsEigenValues(3,3) = dabs(RA%RoeAverage(3) + RA%RoeAverage(1))\n FM%AbsEigenValues(4,4) = dabs(RA%RoeAverage(3))\n end if\n end if\n return\nend subroutine GetEigenMatrix\n", "meta": {"hexsha": "99e3acf1fa75a9585c4387a5cc3483f1560f32e2", "size": 8015, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "flow_solver/EulerSolver2_2018/source/StructuredGrid/Flux/GetEigenMatrix.f90", "max_stars_repo_name": "Mayu14/2D_comp_viscos", "max_stars_repo_head_hexsha": "a62633d8684b218b52e39d47a13717a1edfa4a46", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-05-08T18:00:28.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-08T18:00:28.000Z", "max_issues_repo_path": "flow_solver/EulerSolver2_2018/source/StructuredGrid/Flux/GetEigenMatrix.f90", "max_issues_repo_name": "Mayu14/2D_comp_viscos", "max_issues_repo_head_hexsha": "a62633d8684b218b52e39d47a13717a1edfa4a46", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "flow_solver/EulerSolver2_2018/source/StructuredGrid/Flux/GetEigenMatrix.f90", "max_forks_repo_name": "Mayu14/2D_comp_viscos", "max_forks_repo_head_hexsha": "a62633d8684b218b52e39d47a13717a1edfa4a46", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-02-20T09:26:27.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-20T09:26:27.000Z", "avg_line_length": 55.275862069, "max_line_length": 110, "alphanum_fraction": 0.6227074236, "num_tokens": 3444, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813526452772, "lm_q2_score": 0.6959583187272711, "lm_q1q2_score": 0.6653231749216295}} {"text": "module lib_constants\n\n implicit none\n save\n\n integer,parameter,private :: sp = selected_real_kind(p=6,r=37)\n integer,parameter,private :: dp = selected_real_kind(p=15,r=307)\n\n real(sp),parameter :: zero_sp = 0._sp\n real(dp),parameter :: zero_dp = 0._dp\n\n real(dp),parameter :: zero = 0._dp\n real(dp),parameter :: half = 0.5_dp\n real(dp),parameter :: one = 1._dp\n real(dp),parameter :: two = 2._dp\n\n ! Physical constants \n\n real(dp),parameter :: G_cgs = 6.67300d-08\n real(dp),parameter :: G_si = 6.67300d-11\n\n ! N = kg.m/s^2 = [G]*kg^2/m**2\n ! [G] = m^3/s^2/kg\n\n real(dp),parameter :: k_cgs = 1.380650424d-16 ! erg/K\n real(dp),parameter :: k_si = 1.380650424d-23 ! J/K\n\n real(dp),parameter :: h_cgs = 6.6260689633d-27 ! ergs.s \n real(dp),parameter :: h_si = 6.6260689633e-34_dp ! J.s\n\n real(dp),parameter :: c_si = 2.99792458e08_dp ! m / s\n real(dp),parameter :: c_cgs = 2.99792458e10_dp ! cm / s\n ! speed of light\n\n real(dp),parameter :: kpc_si = 3.08568025e19_dp ! m\n real(dp),parameter :: kpc_cgs = 3.08568025e21_dp ! cm\n ! kiloparsec\n\n real(dp),parameter :: pi = 3.14159265358979323846_dp\n real(sp),parameter :: pi_sp = 3.14159265358979323846_sp\n real(dp),parameter :: pi_dp = 3.14159265358979323846_dp\n\n real(dp),parameter :: twopi = pi + pi\n real(sp),parameter :: twopi_sp = pi_sp + pi_sp\n real(dp),parameter :: twopi_dp = pi_dp + pi_dp\n\n real(dp),parameter :: deg2rad = pi / 180._dp\n real(dp),parameter :: rad2deg = 180._dp / pi\n real(sp),parameter :: deg2rad_sp = pi_sp / 180._sp\n real(sp),parameter :: rad2deg_sp = 180._sp / pi_sp\n real(dp),parameter :: deg2rad_dp = pi_dp / 180._dp\n real(dp),parameter :: rad2deg_dp = 180._dp / pi_dp\n\n real(dp),parameter :: lsun_cgs = 3.846e33_dp ! erg/s\n\n real(dp),parameter :: rsun_cgs = 6.95508e10_dp ! cm\n\n real(dp),parameter :: au_cgs = 1.49598e13_dp ! cm\n\n real(dp),parameter :: year_cgs = 3600._dp * 24._dp * 365.25_dp\n\n real(dp),parameter :: msun_cgs = 1.989e33_dp ! g\n ! Conversions\n\n real(dp),parameter :: ergs2mJy = 1.e26_dp\n real(dp),parameter :: microns2cm = 1.e-4_dp\n real(dp),parameter :: microns2m = 1.e-6_dp\n\n real(dp),parameter :: stef_boltz = 5.670400e-5_dp\n\ncontains\n\n real(sp) function infinity_sp()\n implicit none\n real(sp) :: x\n x = huge(1._sp)\n infinity_sp = x + x\n end function infinity_sp\n\n real(dp) function infinity_dp()\n implicit none\n real(dp) :: x\n x = huge(1._dp)\n infinity_dp = x + x\n end function infinity_dp\n\nend module lib_constants\n", "meta": {"hexsha": "8ff9b2410d2fdab89d1e1f4007cd26b4974249f4", "size": 2506, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/resources/fortran_module/lib_constants.f90", "max_stars_repo_name": "Manu343726/biicode-common", "max_stars_repo_head_hexsha": "91b32c6fd1e4a72ce5451183f1766d313cd0e420", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2015-04-15T09:40:23.000Z", "max_stars_repo_stars_event_max_datetime": "2017-05-17T20:34:49.000Z", "max_issues_repo_path": "test/resources/fortran_module/lib_constants.f90", "max_issues_repo_name": "Manu343726/biicode-common", "max_issues_repo_head_hexsha": "91b32c6fd1e4a72ce5451183f1766d313cd0e420", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2015-04-22T11:29:36.000Z", "max_issues_repo_issues_event_max_datetime": "2018-09-25T09:31:09.000Z", "max_forks_repo_path": "test/resources/fortran_module/lib_constants.f90", "max_forks_repo_name": "bowlofstew/common", "max_forks_repo_head_hexsha": "45e9ca902be7bbbdd73dafe3ab8957bc4a006020", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 22, "max_forks_repo_forks_event_min_datetime": "2015-04-15T09:46:00.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-29T17:03:31.000Z", "avg_line_length": 28.4772727273, "max_line_length": 66, "alphanum_fraction": 0.6556264964, "num_tokens": 919, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.855851154320682, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.6652529834396653}} {"text": " subroutine tag4refinement(mx,my,mbc,\n & meqn, xlower,ylower,dx,dy,blockno,\n & q, tag_threshold, init_flag,tag_patch)\n implicit none\n\n integer mx,my, mbc, meqn, tag_patch, init_flag\n integer blockno\n double precision xlower, ylower, dx, dy\n double precision tag_threshold\n double precision q(1-mbc:mx+mbc,1-mbc:my+mbc,meqn)\n\n integer i,j, mq\n double precision qvec(3), dmax, heat_eval_refinement\n\n tag_patch = 0\nc # Refine based only on first variable in system.\n mq = 1\n do j = 1,my+1\n do i = 1,mx+1\n qvec(1) = q(i,j,1)\n qvec(2) = q(i-1,j,1)\n qvec(3) = q(i,j-1,1)\n\n dmax = heat_eval_refinement(qvec,dx,dy)\n\n if (abs(dmax) .gt. tag_threshold) then\n tag_patch = 1\n return\n endif\n enddo\n enddo\n\n end \n\n double precision function heat_eval_refinement(q,dx,dy)\n implicit none\n\n double precision q(3), dx,dy\n\n double precision qij, qimj, qijm\n double precision qxm, qym, dmax\n\n qij = q(1)\n qimj = q(2)\n qijm = q(3)\n qxm = (qij - qimj)/dx\n qym = (qij - qijm)/dy\n\n dmax = max(abs(qxm),abs(qym))\n\n heat_eval_refinement = dmax\n\n return\n\n end function heat_eval_refinement\n\n", "meta": {"hexsha": "96355c02d0203ff7d9d172dad747fef23ff07db3", "size": 1389, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "applications/elliptic/heat/fortran/heat_tag4refinement.f", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2017-09-26T13:39:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:56:23.000Z", "max_issues_repo_path": "applications/elliptic/heat/fortran/heat_tag4refinement.f", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 75, "max_issues_repo_issues_event_min_datetime": "2017-08-02T19:56:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T12:36:32.000Z", "max_forks_repo_path": "applications/elliptic/heat/fortran/heat_tag4refinement.f", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-02-21T00:10:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T19:08:36.000Z", "avg_line_length": 24.3684210526, "max_line_length": 61, "alphanum_fraction": 0.5370770338, "num_tokens": 428, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511543206819, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.6652529834396652}} {"text": "program test_stats_rand\n use forlab_stats, only: rng, randu, randn\n use forlab_io, only: disp\n implicit none\n integer(kind=4) :: iX(5)\n real(kind=8) :: rX(5)\n\n call rng()\n call randu(iX)\n call disp(iX, 'RANDU(iX(5)) : ')\n call randu(iX, from=-10_4, to=10_4)\n call disp(iX, 'RANDU(iX, from=-10_4, to=10_4) : ')\n\n call randu(rX)\n call disp(rX, 'RANDU(rX(5)) : ')\n call randu(rX, from=-10.d0, to=10.d0)\n call disp(rX, 'RANDU(rX, from=-10.d0, to=10.d0) : ')\n \n call randn(rX)\n call disp(rX, 'RANDN(rX(5)) : ')\n call randn(rX, mean=0.d0, std=10.d0)\n call disp(rX, 'RANDN(rX, mean=0.d0, std=10.d0) : ')\n\nend program test_stats_rand", "meta": {"hexsha": "d6b7d57b235d1cd62040c6ac3c877a64882b16ac", "size": 682, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/stats/test_stats_rand.f90", "max_stars_repo_name": "zoziha/forlab_z", "max_stars_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2021-08-31T15:23:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T02:44:46.000Z", "max_issues_repo_path": "test/stats/test_stats_rand.f90", "max_issues_repo_name": "zoziha/forlab_z", "max_issues_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-08-22T11:47:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-31T00:57:16.000Z", "max_forks_repo_path": "test/stats/test_stats_rand.f90", "max_forks_repo_name": "zoziha/forlab_z", "max_forks_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-07-16T03:16:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-31T13:09:42.000Z", "avg_line_length": 28.4166666667, "max_line_length": 56, "alphanum_fraction": 0.5865102639, "num_tokens": 273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.6652529821391225}} {"text": " module numz\n! module defines the basic real type and pi\n! integer, parameter :: b8 = selected_real_kind(14)\n integer, parameter :: b8 = selected_real_kind(4)\n real(b8), parameter :: pi = 4.0_b8*(atan(1.0_b8))\n real(b8), parameter :: pi2 = 8.0_b8*(atan(1.0_b8))\n integer, parameter :: nsig = 100\n end module\n program signal\n use numz\n real(b8) :: tmin(nsig),tmax(nsig),amp(nsig),f(nsig)\n real(b8) :: dt,maxt\n real(b8), allocatable :: sig(:)\n real(b8) sval,t,y\n integer :: nc(nsig),num,msig\n integer :: i,j\n read(*,*)num\n! subsignals are nonzero between tmin and tmax\n! tmin can be < 0.0\n! tmax can be > maxt\n! with a given max amplitude and frequency (hz)\n! nc = 0 constant amplitude between tmin and tmax\n! nc = -1 amplitude decreases between tmin and tmax\n! nc = +1 amplitude increases between tmin and tmax\n do i=1,num\n read(*,*)tmin(i),tmax(i),amp(i),f(i),nc(i)\n end do\n write(*,*)\n read(*,*)dt,maxt\n msig=maxt/dt\n msig=msig+1\n allocate(sig(msig))\n do j=1,msig\n t=dt*(j-1)\n sig(j)=0.0_b8\n do i=1,num\n y=sval(t,tmin(i),tmax(i),amp(i),f(i),nc(i))\n! write(*,*)i,t,y\n sig(j)=sig(j)+y\n enddo\n enddo\n ! do i=1,msig\n ! write(*,*)sig(i)\n ! enddo\n open(unit=18,file=\"test.dat\",access=\"stream\",status=\"replace\")\n write(18)sig\n end program\n function sval(t,tmin,tmax,amp,f,nc)\n use numz\n real(b8) :: t,tmin,tmax,amp,f,sval\n integer nc\n real(b8) cur\n sval=0.0_b8\n if(t .lt. tmin)return\n if(t .gt. tmax)return\n cur=t-tmin\n sval=amp*sin(pi2*cur*f)\n if(nc .eq. 0)then\n return\n endif\n if(nc .eq. -1)then\n sval=sval*(1.0_b8-cur/(tmax-tmin))\n return\n endif\n if(nc .eq. 1)then\n sval=sval*(cur/(tmax-tmin))\n return\n endif\n write(*,*)\"invalid nc:\",nc\n end function\n \n \n \n \n", "meta": {"hexsha": "434bbe48f7954b2b8984767ad8b096856ed90767", "size": 1898, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fft/dft/dosig.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": "fft/dft/dosig.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": "fft/dft/dosig.f90", "max_forks_repo_name": "timkphd/examples", "max_forks_repo_head_hexsha": "04c162ec890a1c9ba83498b275fbdc81a4704062", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.3066666667, "max_line_length": 66, "alphanum_fraction": 0.574288725, "num_tokens": 687, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511396138365, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.6652529808385793}} {"text": "PROGRAM FU_example2\n ! Example program for FU_Prec and FU_Statistics modules of ecasglez's FortranUtilities,\n ! showing how to apply FU_Statistics functions to an array with rank larger than 1.\n ! It shows 3 examples on how to calculate the mean value of a rank 3 array.\n ! compile using: gfortran example2.f90 -o example2 -I/path/to/include/ -lFortranUtilities -L/path/to/lib/ -O2\n ! before running: export LD_LIBRARY_PATH=/path/to/lib:${LD_LIBRARY_PATH}\n ! run using: ./example2\n ! license: MIT.\n\n USE FU_Prec , ONLY: dp\n USE FU_statistics, ONLY: mean\n\n IMPLICIT NONE\n\n INTEGER, PARAMETER :: n = 100\n REAL(KIND=8),DIMENSION(:,:,:),ALLOCATABLE :: matrix\n REAL(KIND=8) :: media\n\n ALLOCATE(matrix(n,n,n))\n CALL random_number(matrix(:,:,:))\n\n !First method. Use RESHAPE.\n media = mean(RESHAPE(matrix,([SIZE(matrix)])))\n WRITE(*,'(A,F9.5,A)') 'Mean value: ', media, '.'\n\n !Second method. Use an array constructor.\n media = mean([matrix])\n WRITE(*,'(A,F9.5,A)') 'Mean value: ', media, '.'\n\n !Third method. Use sequence association. Use auxiliary function mean3D (see below)\n media = mean3D(matrix,SIZE(matrix))\n WRITE(*,'(A,F9.5,A)') 'Mean value: ', media, '.'\n\n DEALLOCATE(matrix)\n\n CONTAINS\n\n FUNCTION mean3D(a,n) RESULT(res)\n USE FU_statistics, ONLY: mean\n IMPLICIT NONE\n REAL(KIND=dp),DIMENSION(n), INTENT(IN) :: a\n INTEGER, INTENT(IN) :: n\n REAL(KIND=dp) :: res\n res = mean(a)\n END FUNCTION mean3D\n\nEND PROGRAM FU_example2\n", "meta": {"hexsha": "1399f9edb4424bd9cbd17b5129ea28f5100e6ee7", "size": 1539, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "documentation/Examples/Example02/example2.f90", "max_stars_repo_name": "ecasglez/FortranUtilities", "max_stars_repo_head_hexsha": "a4c88fc190102524f0c669ac20489c5b85a754c1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "documentation/Examples/Example02/example2.f90", "max_issues_repo_name": "ecasglez/FortranUtilities", "max_issues_repo_head_hexsha": "a4c88fc190102524f0c669ac20489c5b85a754c1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "documentation/Examples/Example02/example2.f90", "max_forks_repo_name": "ecasglez/FortranUtilities", "max_forks_repo_head_hexsha": "a4c88fc190102524f0c669ac20489c5b85a754c1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-16T08:04:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-16T08:04:24.000Z", "avg_line_length": 32.0625, "max_line_length": 112, "alphanum_fraction": 0.6497725796, "num_tokens": 450, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.855851154320682, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6652529790243936}} {"text": "module m\r\nimplicit none\r\nprivate\r\npublic :: square_cube,powers,powers_dt,powers_2_3\r\ntype square_cube\r\n integer :: isquare,icube\r\nend type square_cube\r\ncontains\r\n! subroutine with multiple intent(out) arguments\r\nsubroutine powers(i,isquare,icube)\r\ninteger, intent(in) :: i\r\ninteger, intent(out) :: isquare,icube\r\nisquare = i**2\r\nicube = i*isquare\r\nend subroutine powers\r\n! function returning derived type with multple components\r\nfunction powers_dt(i) result(res)\r\ninteger, intent(in) :: i\r\ntype(square_cube) :: res\r\nres%isquare = i**2\r\nres%icube = i*res%isquare\r\nend function powers_dt\r\n! function returning an array. This approach is arguably worse\r\n! because it's not clear from the name what \r\n! p_2_3(1) and p_2_3(2) refer to. It's also restricted to \r\n! returning values of the same type.\r\nfunction powers_2_3(i) result(p_2_3)\r\ninteger, intent(in) :: i\r\ninteger :: p_2_3(2)\r\np_2_3(1) = i**2\r\np_2_3(2) = p_2_3(1)*i\r\nend function powers_2_3\r\n!\r\nend module m\r\n\r\nprogram main\r\nuse m, only: powers,powers_dt,square_cube,powers_2_3\r\nimplicit none\r\ninteger, parameter :: i = 4\r\ninteger :: isquare,icube,pow(2)\r\ntype(square_cube) :: dt\r\ncall powers(i,isquare,icube) ! return results in isquare and icube\r\ndt = powers_dt(i) ! return a derived type with components isquare and icube\r\npow = powers_2_3(i)\r\nprint*,isquare,icube ! 16 64\r\nprint*,dt%isquare,dt%icube ! 16 64\r\nprint*,dt ! 16 64\r\n! can print a whole derived type when it has scalar components\r\nprint*,pow ! 16 64\r\nend program main\r\n", "meta": {"hexsha": "9ec3b8d7aa5c8a633c37417f10dbf1f77b44f9ca", "size": 1521, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "subroutine_dt.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": "subroutine_dt.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": "subroutine_dt.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.8235294118, "max_line_length": 76, "alphanum_fraction": 0.7172912558, "num_tokens": 469, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711908591638, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.6652405592764136}} {"text": "\nprogram pi_main\n\n use timer\n\n ! Local variables\n integer, parameter :: num_steps = 100000000 ! number of steps over which to estimate pi\n real(kind=8) :: step ! the step size\n integer :: ii ! genereric counter\n real(kind=8) :: x, x2 ! intermediate value\n real(kind=8) :: pi = 0.0_8 ! overall estimate\n real(kind=8) :: sum = 0.0_8 ! variable to store partial sum\n real(kind=8) :: start, end ! timers\n\n real(kind=8), parameter :: PI_8 = 4.0_8 * atan(1.0_8)\n\n ! step size is dependent upon the number of steps\n step = 1.0_8/num_steps\n\n ! Start timer\n call wtime(start)\n\n ! main loop\n !$omp parallel do private(x,x2)\n do ii = 1, num_steps\n x = (ii-0.5_8)*step\n x2 = 4.0_8/(1.0_8+x*x)\n !$omp critical\n sum = sum + x2\n !$omp end critical\n end do\n !$omp end parallel do\n\n pi = step * sum\n\n ! Stop timer\n call wtime(end)\n\n ! Print result\n write(*,\"(A)\") \"------------------------------------\"\n write(*,\"(A,F19.16)\") \"pi is: \", pi\n write(*,\"(A,F19.16)\") \"error is: \", abs(pi - PI_8)\n write(*,\"(A,F10.3)\") \"runtime: \", end-start\n write(*,\"(A)\") \"------------------------------------\"\n\nend program pi_main\n", "meta": {"hexsha": "19c2b001f383729566d614778ae6fa453d1335fe", "size": 1286, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "code/pi_critical.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/pi_critical.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/pi_critical.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.3617021277, "max_line_length": 89, "alphanum_fraction": 0.5062208398, "num_tokens": 398, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711680567799, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.6652405414298431}} {"text": "module poisbinom\r\n\r\n use types, only: dp\r\n\r\n implicit none\r\n\r\ncontains\r\n\r\n function cdf(p, x)\r\n use logspace, only: logadd, log1p\r\n\r\n real(dp), dimension(:), intent(in) :: p\r\n integer, intent(in) :: x\r\n real(dp) :: cdf\r\n\r\n real(dp), dimension(size(p)) :: logp, lognotp\r\n real(dp), dimension(2, size(p)) :: memory\r\n\r\n integer :: j, k, n, prev, curr, tmp\r\n\r\n n = size(p)\r\n\r\n if (x > n) then\r\n cdf = 1\r\n else if (x < 0) then\r\n cdf = 0\r\n else\r\n logp = log(p)\r\n lognotp = log1p(-p)\r\n\r\n memory(1, 1) = lognotp(1)\r\n do j = 2, size(p)\r\n memory(1, j) = lognotp(j) + memory(1, j - 1)\r\n end do\r\n\r\n prev = 1\r\n curr = 2\r\n\r\n cdf = memory(1, n)\r\n\r\n do k = 1, x\r\n if (k > 1) then\r\n memory(curr, k) = logp(k) + memory(prev, k - 1)\r\n else\r\n memory(curr, k) = logp(k)\r\n end if\r\n\r\n do j = k + 1, n\r\n memory(curr, j) = logadd(lognotp(j) + memory(curr, j - 1), &\r\n logp(j) + memory(prev, j - 1))\r\n end do\r\n\r\n cdf = logadd(cdf, memory(curr, n))\r\n\r\n tmp = curr\r\n curr = prev\r\n prev = tmp\r\n end do\r\n\r\n cdf = exp(cdf)\r\n end if\r\n end function cdf\r\n\r\n\r\n function fullCdf(p, x) result (cdf)\r\n use logspace, only: logadd, log1p\r\n\r\n real(dp), dimension(:), intent(in) :: p\r\n integer, intent(in) :: x\r\n real(dp), dimension(0:x) :: cdf\r\n\r\n real(dp), dimension(size(p)) :: logp, lognotp\r\n real(dp), dimension(2, size(p)) :: memory\r\n\r\n integer :: j, k, n, prev, curr, tmp\r\n\r\n n = size(p)\r\n\r\n if (x > n) then\r\n cdf = 1.0\r\n else\r\n logp = log(p)\r\n lognotp = log1p(-p)\r\n\r\n memory(1, 1) = lognotp(1)\r\n do j = 2, size(p)\r\n memory(1, j) = lognotp(j) + memory(1, j - 1)\r\n end do\r\n\r\n prev = 1\r\n curr = 2\r\n\r\n cdf(0) = memory(1, n)\r\n\r\n do k = 1, x\r\n if (k > 1) then\r\n memory(curr, k) = logp(k) + memory(prev, k - 1)\r\n else\r\n memory(curr, k) = logp(k)\r\n end if\r\n\r\n do j = k + 1, n\r\n memory(curr, j) = logadd(lognotp(j) + memory(curr, j - 1), &\r\n logp(j) + memory(prev, j - 1))\r\n end do\r\n\r\n cdf(k) = logadd(cdf(k - 1), memory(curr, n))\r\n\r\n tmp = curr\r\n curr = prev\r\n prev = tmp\r\n end do\r\n\r\n cdf = exp(cdf)\r\n end if\r\n end function fullCdf\r\n\r\nend module poisbinom\r\n", "meta": {"hexsha": "dad51aa5396a846901cf7233fe0fa01e94a10c5a", "size": 2511, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "python/src/poisbinom.f90", "max_stars_repo_name": "DongqiangZeng0808/DISCOVER", "max_stars_repo_head_hexsha": "87c6462b68dbd8a346a5db4df7520b79e034e587", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-23T02:09:27.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T02:09:27.000Z", "max_issues_repo_path": "python/src/poisbinom.f90", "max_issues_repo_name": "DongqiangZeng0808/DISCOVER", "max_issues_repo_head_hexsha": "87c6462b68dbd8a346a5db4df7520b79e034e587", "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": "python/src/poisbinom.f90", "max_forks_repo_name": "DongqiangZeng0808/DISCOVER", "max_forks_repo_head_hexsha": "87c6462b68dbd8a346a5db4df7520b79e034e587", "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": 21.1008403361, "max_line_length": 73, "alphanum_fraction": 0.4404619673, "num_tokens": 817, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6651953260917316}} {"text": "!===============================================================================\nprogram thompson_parameter\n!===============================================================================\n! Program form of the CIJ_thom routine in anisotropy_ajn module\n\n use anisotropy_ajn\n \n implicit none\n \n real(8) :: ecs(6,6)\n real(8) :: vp,vs,rho,del,eps,gam\n integer :: i\n character(len=250) :: arg\n \n if (command_argument_count() /= 6) then\n write(0,'(a)') 'Usage: CIJ_thom [vp] [vs] [rho] [delta] [epsilon] [gamma]',&\n ' Rotationally symmetric about 3-axis (vertical)'\n write(0,'(a)') ' Sends 36 elastic constants to stdout (density-normalised).'\n stop\n endif\n \n call get_command_argument(1,arg) ; read(arg,*) vp\n call get_command_argument(2,arg) ; read(arg,*) vs\n call get_command_argument(3,arg) ; read(arg,*) rho\n call get_command_argument(4,arg) ; read(arg,*) del\n call get_command_argument(5,arg) ; read(arg,*) eps\n call get_command_argument(6,arg) ; read(arg,*) gam\n \n ecs = CIJ_thom(vp,vs,rho,eps,gam,del)\n \n write(*,*) ecs/rho\n \nend program thompson_parameter\n!-------------------------------------------------------------------------------\n", "meta": {"hexsha": "1d5180bbf7d85cbd3f8546550187845dd4353304", "size": 1232, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "CIJ_thom/CIJ_thom.f90", "max_stars_repo_name": "anowacki/elasticity", "max_stars_repo_head_hexsha": "ba17bcfc8a8dd8dd881f200997526bffaca3e781", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2017-03-29T21:32:13.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-21T14:47:06.000Z", "max_issues_repo_path": "CIJ_thom/CIJ_thom.f90", "max_issues_repo_name": "anowacki/elasticity", "max_issues_repo_head_hexsha": "ba17bcfc8a8dd8dd881f200997526bffaca3e781", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "CIJ_thom/CIJ_thom.f90", "max_forks_repo_name": "anowacki/elasticity", "max_forks_repo_head_hexsha": "ba17bcfc8a8dd8dd881f200997526bffaca3e781", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-30T05:31:13.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-30T05:31:13.000Z", "avg_line_length": 35.2, "max_line_length": 83, "alphanum_fraction": 0.512987013, "num_tokens": 322, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6651953260917316}} {"text": " subroutine interpolate_q2n_3r(val, f, k)\n!***********************************************************************\n! Copyright 2011 Los Alamos National Security, LLC All rights reserved\n! Unless otherwise indicated, this information has been authored by an\n! employee or employees of the Los Alamos National Security, LLC (LANS),\n! operator of the Los Alamos National Laboratory under Contract No.\n! DE-AC52-06NA25396 with the U. S. Department of Energy. The U. S.\n! Government has rights to use, reproduce, and distribute this\n! information. The public may copy and use this information without\n! charge, provided that this Notice and any statement of authorship are\n! reproduced on all copies. Neither the Government nor LANS makes any\n! warranty, express or implied, or assumes any liability or\n! responsibility for the use of this information. \n!***********************************************************************\n! \n! Extrapolates a variable defined at the gausspoints to the nodes\n! \n! Author : Sai Rapaka\n!\n\n use comfem\n\n implicit none\n real*8, dimension(8) :: f\n real*8 :: val\n integer :: k\n \n real*8 :: sq3, zeta, eta, mu\n real*8, dimension(8) :: N\n integer :: i\n\n sq3 = sqrt(3.0d0)\n \n zeta = gpcord(k,1)*sq3*sq3\n eta = gpcord(k,2)*sq3*sq3\n mu = gpcord(k,3)*sq3*sq3\n\n N(1) = 0.125d0*(1 - zeta)*(1 - eta)*(1 - mu)\n N(2) = 0.125d0*(1 + zeta)*(1 - eta)*(1 - mu)\n N(3) = 0.125d0*(1 + zeta)*(1 + eta)*(1 - mu)\n N(4) = 0.125d0*(1 - zeta)*(1 + eta)*(1 - mu)\n N(5) = 0.125d0*(1 - zeta)*(1 - eta)*(1 + mu)\n N(6) = 0.125d0*(1 + zeta)*(1 - eta)*(1 + mu)\n N(7) = 0.125d0*(1 + zeta)*(1 + eta)*(1 + mu)\n N(8) = 0.125d0*(1 - zeta)*(1 + eta)*(1 + mu)\n \n val = 0.0d0\n do i=1,8\n val = val + N(i)*f(i)\n enddo\n\n end subroutine interpolate_q2n_3r\n \n", "meta": {"hexsha": "6fac91c5616d77bf824a05fbcd73b923d3374828", "size": 2043, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/interpolate_q2n_3r.f", "max_stars_repo_name": "satkarra/FEHM", "max_stars_repo_head_hexsha": "5d8d8811bf283fcca0a8a2a1479f442d95371968", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2018-08-09T04:55:28.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-31T21:46:32.000Z", "max_issues_repo_path": "src/interpolate_q2n_3r.f", "max_issues_repo_name": "satkarra/FEHM", "max_issues_repo_head_hexsha": "5d8d8811bf283fcca0a8a2a1479f442d95371968", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 19, "max_issues_repo_issues_event_min_datetime": "2018-04-06T16:17:14.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-14T04:40:14.000Z", "max_forks_repo_path": "src/interpolate_q2n_3r.f", "max_forks_repo_name": "satkarra/FEHM", "max_forks_repo_head_hexsha": "5d8d8811bf283fcca0a8a2a1479f442d95371968", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2018-06-07T21:11:55.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-11T13:48:22.000Z", "avg_line_length": 37.8333333333, "max_line_length": 72, "alphanum_fraction": 0.516886931, "num_tokens": 640, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070084811307, "lm_q2_score": 0.7310585727705126, "lm_q1q2_score": 0.6651953189741021}} {"text": "SUBROUTINE mapc2m_cylinder(xc,yc,xp,yp,zp)\n IMPLICIT NONE\n\n DOUBLE PRECISION xc,yc,xp,yp,zp\n\n DOUBLE PRECISION pi, pi2\n COMMON /compi/ pi, pi2\n\n DOUBLE PRECISION R_cyl, h_cyl\n COMMON /cylinder_comm/ r_cyl, h_cyl\n\n DOUBLE PRECISION r1, R, theta, z, yc1\n\n\n !! finite cylinder : \n if (yc .lt. 0 .or. yc .gt. 1) then\n!! write(6,*) 'yc not in [0,1]; yc = ', yc\n endif\n\n !!yc1 = mod(yc,1.0)\n \n CALL map_comp2cylinder(xc,yc,theta,z)\n \n xp = R_cyl*cos(theta)\n yp = R_cyl*sin(theta)\n zp = z\n\nEND SUBROUTINE MAPC2M_CYLINDER\n\n", "meta": {"hexsha": "ffe198054a512061e617021403b17b408879999f", "size": 574, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "applications/paper/all/mapc2m_cylinder.f90", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2017-09-26T13:39:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:56:23.000Z", "max_issues_repo_path": "applications/paper/all/mapc2m_cylinder.f90", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 75, "max_issues_repo_issues_event_min_datetime": "2017-08-02T19:56:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T12:36:32.000Z", "max_forks_repo_path": "applications/paper/all/mapc2m_cylinder.f90", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-02-21T00:10:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T19:08:36.000Z", "avg_line_length": 19.1333333333, "max_line_length": 50, "alphanum_fraction": 0.6045296167, "num_tokens": 220, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9099070035949656, "lm_q2_score": 0.7310585727705127, "lm_q1q2_score": 0.6651953154020293}} {"text": "program main\n use plantFEM\n implicit none\n\n real(real64) :: OA(2),OB(2),OC(2)\n real(real64) :: AB(2),CA(2),AC(2),BA(2)\n\n OA(1)=3.0d0; OA(2)=8.0d0\n OB(1)=-1.0d0; OB(2)=2.0d0\n OC(1)=3.00d0; OC(2)=-20.0d0\n AB = OB - OA\n BA = OA - OB\n CA = OA - OC\n AC = OC - OA\n print *, 1, 2.0d0/3.0d0*OA + 2.0d0*BA\n print *, 2,CA + 2.0d0*OB\n print *, 3,5.0d0*CA + 2.0d0*AB\n print *, 4,5.0d0*CA + 2.0d0*AB + 2.0d0*AC\n print *, 5,AB + 2.0d0*OB\n print *, 6,OA + 2.0d0*OB + 2.0d0*OC\n print *, 7,2.0d0*OA + 2.0d0*AB\n print *, \"Student's answers\"\n\n print *, 56.00d0/19.0d0*OA+ 46.0d0/19.0d0*OB !+ 1.0d0*OC\n\n \nend program main\n", "meta": {"hexsha": "b2d36893256ea2557c84a30b2dbae06b58b0cb97", "size": 665, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/playon_std/ex0024_simplevector.f90", "max_stars_repo_name": "kazulagi/plantfem_min", "max_stars_repo_head_hexsha": "ba7398c031636644aef8acb5a0dad7f9b99fcb92", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2020-06-21T08:21:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-13T04:28:30.000Z", "max_issues_repo_path": "Tutorial/std/ex0024_simplevector.f90", "max_issues_repo_name": "kazulagi/plantFEM_binary", "max_issues_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-05-08T05:20:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T05:39:29.000Z", "max_forks_repo_path": "Tutorial/std/ex0024_simplevector.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": 23.75, "max_line_length": 60, "alphanum_fraction": 0.5157894737, "num_tokens": 369, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069987088003, "lm_q2_score": 0.7310585727705127, "lm_q1q2_score": 0.6651953118299563}} {"text": ": CR 10 EMIT ;\n: PUTS 48 + EMIT CR ;\n\n1 2 < PUTS\n1 2 <= PUTS\n1 2 = PUTS\n1 2 >= PUTS\n1 2 > PUTS\nCR\n1 2 <> PUTS\nCR\nCR\n2 2 < PUTS\n2 2 <= PUTS\n2 2 = PUTS\n2 2 >= PUTS\n2 2 > PUTS\nCR\n2 2 <> PUTS\nCR\nCR\n3 2 < PUTS\n3 2 <= PUTS\n3 2 = PUTS\n3 2 >= PUTS\n3 2 > PUTS\nCR\n3 2 <> PUTS\n\n", "meta": {"hexsha": "3d4b0a208256c49829c01c40e4976460bc58dd82", "size": 276, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/nostd-cmp.f", "max_stars_repo_name": "matematikaadit/JombloForth", "max_stars_repo_head_hexsha": "cf61a32e0679a6070b73f6db24bba1a0f9bb920c", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-03-08T08:22:38.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-12T13:14:11.000Z", "max_issues_repo_path": "tests/nostd-cmp.f", "max_issues_repo_name": "ammarfaizi2/jombloforth", "max_issues_repo_head_hexsha": "cf61a32e0679a6070b73f6db24bba1a0f9bb920c", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-03-03T20:37:51.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-04T09:15:17.000Z", "max_forks_repo_path": "tests/nostd-cmp.f", "max_forks_repo_name": "matematikaadit/JombloForth", "max_forks_repo_head_hexsha": "cf61a32e0679a6070b73f6db24bba1a0f9bb920c", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-10-25T22:06:14.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-09T13:59:04.000Z", "avg_line_length": 9.2, "max_line_length": 21, "alphanum_fraction": 0.5144927536, "num_tokens": 166, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8333245953120233, "lm_q2_score": 0.7981867825403176, "lm_q1q2_score": 0.6651486775438161}} {"text": "! These routines evaluate 1-dimensional derivatives at an interface by using\n! 4-cell centered stencils. Mostly intended to use arbitrary boundary\n! conditions when a true solution is available.\n!\n! They will work in a pinch anywhere you need a derivative, but performance\n! takes a big hit if you make pointwise function calls at every grid cell.\n\ndouble precision function derivative0(q)\n implicit none\n double precision, dimension(4), intent(in) :: q\n derivative0 = -0.0625d0 * q(1) + 0.5625d0 * q(2) &\n + 0.5625d0 * q(3) - 0.0625d0 * q(4)\nend function derivative0\n\n\ndouble precision function derivative1(q, dx)\n implicit none\n double precision, dimension(4), intent(in) :: q\n double precision, intent(in) :: dx\n derivative1 = (4.166666666666667d-2 * q(1) - 1.125d0 * q(2) &\n + 1.125d0 * q(3) - 4.166666666666667d-2 * q(4)) / dx\nend function derivative1\n\n\ndouble precision function derivative2(q, dx)\n implicit none\n double precision, dimension(4), intent(in) :: q\n double precision, intent(in) :: dx\n derivative2 = (.5d0 * q(1) - .5d0 * q(2) - .5d0 * q(3) + .5d0 * q(4)) / dx**2\nend function derivative2\n\n\ndouble precision function derivative3(q, dx)\n implicit none\n double precision, dimension(4), intent(in) :: q\n double precision, intent(in) :: dx\n derivative3 = (-q(1) + 3.d0 * q(2) - 3.d0 * q(3) + q(4)) / dx**3\nend function derivative3\n\n\ndouble precision function gen_derivative(i, q, dx)\n implicit none\n integer, intent(in) :: i\n double precision, dimension(4), intent(in) :: q\n double precision, intent(in) :: dx\n double precision, external :: derivative0, derivative1, derivative2, derivative3\n \n if (i == 0) then\n gen_derivative = derivative0(q)\n else if (i == 1) then\n gen_derivative = derivative1(q, dx)\n else if (i == 2) then\n gen_derivative = derivative2(q, dx)\n else if (i == 3) then\n gen_derivative = derivative3(q, dx)\n end if\n\nend function gen_derivative\n", "meta": {"hexsha": "df6c4efb3102f0f556526f2e7ceb735de4deb8b4", "size": 2000, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "implicit_claw/1d/interface_derivatives.f90", "max_stars_repo_name": "claridge/implicit_solvers", "max_stars_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-04-29T00:16:18.000Z", "max_stars_repo_stars_event_max_datetime": "2017-04-29T00:16:18.000Z", "max_issues_repo_path": "implicit_claw/1d/interface_derivatives.f90", "max_issues_repo_name": "claridge/implicit_solvers", "max_issues_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "implicit_claw/1d/interface_derivatives.f90", "max_forks_repo_name": "claridge/implicit_solvers", "max_forks_repo_head_hexsha": "d68bea026f6a3f8a9190a18689aea96166db65ff", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.8983050847, "max_line_length": 84, "alphanum_fraction": 0.6635, "num_tokens": 598, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765328159726, "lm_q2_score": 0.7279754371026368, "lm_q1q2_score": 0.6651340733471294}} {"text": "\tFUNCTION PR_MHKN ( smph )\nC************************************************************************\nC* PR_MHKN\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes SKNT from SMPH. 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* SKNT = SMPH * 0.868976\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PR_MHKN ( SMPH )\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*\tSMPH\t\tREAL\t\tSpeed in miles/hour\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPR_MHKN\t\tREAL\t\tSpeed in knots\t\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* T. Lee/SAIC\t\t 9/01\t\t\t\t\t\t*\nC************************************************************************\n INCLUDE 'GEMPRM.PRM'\n INCLUDE 'ERMISS.FNC'\nC------------------------------------------------------------------------\nC* Check for missing data.\nC\n\tIF ( ERMISS ( smph ) ) THEN\n\t PR_MHKN = RMISSD\n\t ELSE\n\t PR_MHKN = smph * 0.868976\n\tEND IF\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "18f482fee71da054a716c41064c9d5749a44bc4d", "size": 884, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/pr/prmhkn.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/prmhkn.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/prmhkn.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": 26.7878787879, "max_line_length": 73, "alphanum_fraction": 0.3857466063, "num_tokens": 267, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898254600903, "lm_q2_score": 0.7341195385342972, "lm_q1q2_score": 0.66510483258353}} {"text": " subroutine project(v,n1v,nrow,nv,x,work)\nc---------------------------------------------------------------\nc projects vector x onto subspace spanned by the columns of\nc the array v by forming the matrix product v*v(trans)x.\nc (note remember to be a projector the columns of v must \nc be orthonormal.) \nc \nc arguments- \nc v - array of containing the basis vectors defining the \nc subspace x is to be projected onto.\nc these vectors are assumed to be stored in the columns of v.\nc n1v-first dimension of v in calling program. \nc nrow-number of elements in the rows of v and x.\nc nv-number of vectors in v. (i.e. number of columns in v)\nc x-vector to be projected. it is overwritten on return by\nc the requested projection.\nc work - work vector of length at least nv.\nc \nc author gary l. pavlis\nc geophysics program ak-50\nc university of washington\nc seattle, wa 98195 \nc \nc written march 1983 \nc---------------------------------------------------------------------\n integer n1v,nrow,nv \n real v(n1v,nv),x(nrow),work(nv) \n integer j \n do 100 j=1,nv \n work(j) = sdot(nrow,v(1,j),1,x,1)\n 100 continue\n do 150 j=1,nrow \n x(j) = 0.0 \n 150 continue\n do 200 j=1,nv \n call saxpy(nrow,work(j),v(1,j),1,x,1)\n 200 continue\n return\n end \n\nc $Id$ \n", "meta": {"hexsha": "8c52c89709fa8bf4fc3e9c2790554db1685c39e8", "size": 1402, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "lib/location/libglp/project.f", "max_stars_repo_name": "jreyes1108/antelope_contrib", "max_stars_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_stars_repo_licenses": ["BSD-2-Clause", "MIT"], "max_stars_count": 30, "max_stars_repo_stars_event_min_datetime": "2015-02-20T21:44:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-27T02:53:14.000Z", "max_issues_repo_path": "lib/location/libglp/project.f", "max_issues_repo_name": "jreyes1108/antelope_contrib", "max_issues_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_issues_repo_licenses": ["BSD-2-Clause", "MIT"], "max_issues_count": 14, "max_issues_repo_issues_event_min_datetime": "2015-07-07T19:17:24.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-19T19:18:53.000Z", "max_forks_repo_path": "lib/location/libglp/project.f", "max_forks_repo_name": "jreyes1108/antelope_contrib", "max_forks_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_forks_repo_licenses": ["BSD-2-Clause", "MIT"], "max_forks_count": 46, "max_forks_repo_forks_event_min_datetime": "2015-02-06T16:22:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T11:46:37.000Z", "avg_line_length": 33.380952381, "max_line_length": 70, "alphanum_fraction": 0.5677603424, "num_tokens": 392, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989822921759, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.6651048201797024}} {"text": "!=============================================================================!\n\tsubroutine grad( ndof, nx, ny, v, g1v, g2v, dx, dy, optx, opty, &\n\t xper, yper, lsym, rsym, bsym, tsym, carp)\n!\n! Take the gradient of a 2-D field.\n! Updated to sixth-order accurate differencing on the interior with\n! the option for optimized fourth-order differencing.\n!\n! Revised: 6-28-95\n!\n!=============================================================================!\n\tuse stencil\n\timplicit none\n\t\n\tinteger :: ndof, nx, ny, optx, opty\n\tlogical :: xper, yper\n\tlogical :: lsym, rsym, bsym, tsym, carp\n\treal :: v(ndof,nx,ny), g1v(ndof,nx,ny), g2v(ndof,nx,ny)\n !$sgi distribute v(*,*,block), g1v(*,*,block), g2v(*,*,block)\n\n\treal :: dx, dy\n\t\n\treal, parameter :: zero = 0.0, one = 1.0, pt5 = 0.5\n\treal dxinv, dyinv\n\treal a, b, c, w\n\treal gx1, gx2, gx3, gx4, gx5, gx6\n\treal gy1, gy2, gy3, gy4, gy5, gy6\n\t\n\tinteger :: i, j, idof\n\treal, parameter :: eps = 1.0e-12\n\treal :: isign\n!=============================================================================!\n\n\tdxinv = one / dx\n\tdyinv = one / dy\n\n!.... seven point stencil in x\n\n\tif (optx.eq.0) then\n\t c = 1.0 / 60.0\n\telse if (optx.eq.-1) then\n\t c = 0.0\n\telse\n\t w = 2.0 * 3.1415926535897932385e+0 / 12.0\n\t c = (w/2.0 - 2.0*Sin(w)/3.0 + Sin(2.0*w)/12.0) / &\n\t (5.0*Sin(w) - 4.0*Sin(2.0*w) + Sin(3.0*w))\n\tend if\n\t\n\ta = (2.0 + 15.0 * c) / 3.0\n\tb = -(1.0 + 48.0 * c) / 12.0\n\n\tgx1 = -c * dxinv\n\tgx2 = -b * dxinv\n\tgx3 = -a * dxinv\n\tgx4 = a * dxinv\n\tgx5 = b * dxinv\n\tgx6 = c * dxinv\n\n!.... seven point stencil in y\n\n\tif (opty.eq.0) then\n\t c = 1.0 / 60.0\n\telse if (opty.eq.-1) then\n\t c = 0.0\n\telse\n\t w = 2.0 * 3.1415926535897932385e+0 / 12.0\n\t c = (w/2.0 - 2.0*Sin(w)/3.0 + Sin(2.0*w)/12.0) / &\n\t (5.0*Sin(w) - 4.0*Sin(2.0*w) + Sin(3.0*w))\n\tend if\n\t\n\ta = (2.0 + 15.0 * c) / 3.0\n\tb = -(1.0 + 48.0 * c) / 12.0\n\n\tgy1 = -c * dyinv\n\tgy2 = -b * dyinv\n\tgy3 = -a * dyinv\n\tgy4 = a * dyinv\n\tgy5 = b * dyinv\n\tgy6 = c * dyinv\n\n!=============================================================================!\n!.... compute the gradient in x\n!=============================================================================!\n\n\tif (xper) then\n\n!$doacross\n!$omp parallel do\n do j = 1, ny\n\n\t g1v(:,1,j) = ( gx1 * v(:,nx-3,j)\t+ &\n\t\t\t\tgx2 * v(:,nx-2,j)\t+ &\n\t\t\t\tgx3 * v(:,nx-1,j)\t+ &\n\t\t\t\tgx4 * v(:,2,j)\t\t+ &\n\t\t\t\tgx5 * v(:,3,j)\t\t+ &\n\t\t\t\tgx6 * v(:,4,j)\t) \n \n\t g1v(:,2,j) = ( gx1 * v(:,nx-2,j)\t+ &\n\t\t\t\tgx2 * v(:,nx-1,j)\t+ &\n\t\t\t\tgx3 * v(:,1,j)\t\t+ &\n\t\t\t\tgx4 * v(:,3,j)\t\t+ &\n\t\t\t\tgx5 * v(:,4,j)\t\t+ &\n\t\t\t\tgx6 * v(:,5,j)\t) \n \n\t g1v(:,3,j) = ( gx1 * v(:,nx-1,j)\t+ &\n\t\t\t\tgx2 * v(:,1,j)\t\t+ &\n\t\t\t\tgx3 * v(:,2,j)\t\t+ &\n\t\t\t\tgx4 * v(:,4,j)\t\t+ &\n\t\t\t\tgx5 * v(:,5,j)\t\t+ &\n\t\t\t\tgx6 * v(:,6,j)\t) \n \n\t g1v(:,nx-2,j) = ( gx1 * v(:,nx-5,j)\t+ &\n\t\t\t\tgx2 * v(:,nx-4,j)\t+ &\n\t\t\t\tgx3 * v(:,nx-3,j)\t+ &\n\t\t\t\tgx4 * v(:,nx-1,j)\t+ &\n\t\t\t\tgx5 * v(:,1,j)\t\t+ &\n\t\t\t\tgx6 * v(:,2,j)\t) \n \n\t g1v(:,nx-1,j) = ( gx1 * v(:,nx-4,j)\t+ &\n\t\t\t\tgx2 * v(:,nx-3,j)\t+ &\n\t\t\t\tgx3 * v(:,nx-2,j)\t+ &\n\t\t\t\tgx4 * v(:,1,j)\t\t+ &\n\t\t\t\tgx5 * v(:,2,j)\t\t+ &\n\t\t\t\tgx6 * v(:,3,j)\t) \n \n\t g1v(:,nx,j) = g1v(:,1,j)\n\n end do\n!$omp end parallel do \n\t \n\telse if (carp ) then ! Implement Carpenter's boundary stencil\n\n!$doacross\n!$omp parallel do\n do j = 1, ny\n\n\t g1v(:,1,j) = ( gg1 * v(:,1,j)\t+ &\n\t\t\t gg2 * v(:,2,j) \t+ &\n\t\t\t gg3 * v(:,3,j) \t+ &\n\t\t\t gg4 * v(:,4,j) \t+ &\n\t\t\t gg5 * v(:,5,j) \t+ &\n\t\t\t gg6 * v(:,6,j) ) * dxinv\n \n\t g1v(:,2,j) = ( gh1 * v(:,1,j) \t+ &\n\t\t\t gh2 * v(:,2,j) \t+ &\n\t\t\t gh3 * v(:,3,j) \t+ &\n\t\t\t gh4 * v(:,4,j) \t+ &\n\t\t\t gh5 * v(:,5,j) \t+ &\n\t\t\t gh6 * v(:,6,j) ) * dxinv\n\n\t g1v(:,3,j) = ( gi1 * v(:,1,j) \t+ &\n\t\t\t gi2 * v(:,2,j) \t+ &\n\t\t\t gi3 * v(:,3,j) \t+ &\n\t\t\t gi4 * v(:,4,j) \t+ &\n\t\t\t gi5 * v(:,5,j) \t+ &\n\t\t\t gi6 * v(:,6,j) ) * dxinv\n\n\t g1v(:,4,j) = ( gj1 * v(:,1,j) \t+ &\n\t\t\t gj2 * v(:,2,j) \t+ &\n\t\t\t gj3 * v(:,3,j) \t+ &\n\t\t\t gj4 * v(:,4,j) \t+ &\n\t\t\t gj5 * v(:,5,j) \t+ &\n\t\t\t gj6 * v(:,6,j) ) * dxinv\n\n\t g1v(:,nx-3,j) = -( gj1 * v(:,nx,j) \t+ &\n\t\t\t gj2 * v(:,nx-1,j) + &\n\t\t\t gj3 * v(:,nx-2,j) + &\n\t\t\t gj4 * v(:,nx-3,j) + &\n\t\t\t gj5 * v(:,nx-4,j) + &\n\t\t\t gj6 * v(:,nx-5,j) ) * dxinv\n\n\t g1v(:,nx-2,j) = -( gi1 * v(:,nx,j) \t+ &\n\t\t\t gi2 * v(:,nx-1,j) + &\n\t\t\t gi3 * v(:,nx-2,j) + &\n\t\t\t gi4 * v(:,nx-3,j) + &\n\t\t\t gi5 * v(:,nx-4,j) + &\n\t\t\t gi6 * v(:,nx-5,j) ) * dxinv\n\n\t g1v(:,nx-1,j) = -( gh1 * v(:,nx,j) \t+ &\n\t\t\t gh2 * v(:,nx-1,j) + &\n\t\t\t gh3 * v(:,nx-2,j) + &\n\t\t\t gh4 * v(:,nx-3,j) + &\n\t\t\t gh5 * v(:,nx-4,j) + &\n\t\t\t gh6 * v(:,nx-5,j) ) * dxinv\n\n\t g1v(:,nx,j) = -( gg1 * v(:,nx,j) \t+ &\n\t\t\t gg2 * v(:,nx-1,j) + &\n\t\t\t gg3 * v(:,nx-2,j) + &\n\t\t\t gg4 * v(:,nx-3,j) + &\n\t\t\t gg5 * v(:,nx-4,j) + &\n\t\t\t gg6 * v(:,nx-5,j) ) * dxinv\n\t end do\n!$omp end parallel do \n\n\telse ! boundary differences\n\t\n!$doacross\n!$omp parallel do\n\t do j = 1, ny\n\n!\t g1v(:,1,j) = ( v(:,2,j) - v(:,1,j) ) * dxinv\n\t g1v(:,1,j) = ( gc1 * v(:,1,j) + &\n\t\t\t gc2 * v(:,2,j) + &\n\t\t\t gc3 * v(:,3,j) + &\n\t\t\t gc4 * v(:,4,j) + &\n\t\t\t gc5 * v(:,5,j) ) * dxinv\n!\t g1v(:,1,j) = ( ge1 * v(:,1,j) + &\n!\t\t\t ge2 * v(:,2,j) + &\n!\t\t\t ge3 * v(:,3,j) + &\n!\t\t\t ge4 * v(:,4,j) + &\n!\t\t\t ge5 * v(:,5,j) + &\n!\t\t\t ge6 * v(:,6,j) + &\n!\t\t\t ge7 * v(:,7,j) ) * dxinv\n \n!\t g1v(:,2,j) = ( v(:,3,j) - v(:,1,j) ) * pt5 * dxinv\n\t g1v(:,2,j) = ( gb1 * v(:,1,j) + &\n\t\t\t gb2 * v(:,2,j) + &\n\t\t\t gb3 * v(:,3,j) + &\n\t\t\t gb4 * v(:,4,j) + &\n\t\t\t gb5 * v(:,5,j) ) * dxinv\n!\t g1v(:,2,j) = ( gf1 * v(:,1,j) + &\n!\t\t\t gf2 * v(:,2,j) + &\n!\t\t\t gf3 * v(:,3,j) + &\n!\t\t\t gf4 * v(:,4,j) + &\n!\t\t\t gf5 * v(:,5,j) + &\n!\t\t\t gf6 * v(:,6,j) + &\n!\t\t\t gf7 * v(:,7,j) ) * dxinv\n\n\t g1v(:,3,j) = ( ga1 * v(:,1,j) + &\n\t\t\t ga2 * v(:,2,j) + &\n\t\t\t ga3 * v(:,4,j) + &\n\t\t\t ga4 * v(:,5,j) ) * dxinv\n\t \n\t g1v(:,nx-2,j) = ( ga1 * v(:,nx-4,j) + &\n\t\t\t ga2 * v(:,nx-3,j) + &\n\t\t\t ga3 * v(:,nx-1,j) + &\n\t\t\t ga4 * v(:,nx ,j) ) * dxinv\n \n\t g1v(:,nx-1,j) = -( gb1 * v(:,nx ,j) + &\n\t\t\t gb2 * v(:,nx-1,j) + &\n\t\t\t gb3 * v(:,nx-2,j) + &\n\t\t\t gb4 * v(:,nx-3,j) + &\n\t\t\t gb5 * v(:,nx-4,j) ) * dxinv\n \n\t g1v(:,nx,j) = -( gc1 * v(:,nx ,j) + &\n\t\t\t gc2 * v(:,nx-1,j) + &\n\t\t\t gc3 * v(:,nx-2,j) + &\n\t\t\t gc4 * v(:,nx-3,j) + &\n\t\t\t gc5 * v(:,nx-4,j) ) * dxinv\n\n\t end do\n!$omp end parallel do \n\n\tend if\n\n!.... implement the symmetric conditions\n\n\tif (lsym) then\n!$doacross local( idof, isign )\n!$omp parallel do private(idof, isign)\n do j = 1, ny\n\t do idof = 1, ndof\n\t if (idof .eq. 3) then\n\t isign = -one\n\t else\n\t isign = one\n\t end if\n \n\t g1v(idof,1,j) = ( isign * gx1 * v(idof,4,j)\t+ &\n\t\t\t\t isign * gx2 * v(idof,3,j)\t+ &\n\t\t\t\t isign * gx3 * v(idof,2,j)\t+ &\n\t\t\t\t gx4 * v(idof,2,j)\t\t+ &\n\t\t\t\t gx5 * v(idof,3,j)\t\t+ &\n\t\t\t\t gx6 * v(idof,4,j)\t\t) \n \n\t g1v(idof,2,j) = ( isign * gx1 * v(idof,3,j)\t+ &\n\t\t\t\t isign * gx2 * v(idof,2,j)\t+ &\n\t\t\t\t gx3 * v(idof,1,j)\t\t+ &\n\t\t\t\t gx4 * v(idof,3,j)\t\t+ &\n\t\t\t\t gx5 * v(idof,4,j)\t\t+ &\n\t\t\t\t gx6 * v(idof,5,j)\t\t) \n \n\t g1v(idof,3,j) = ( isign * gx1 * v(idof,2,j)\t+ &\n\t\t\t\t gx2 * v(idof,1,j)\t\t+ &\n\t\t\t\t gx3 * v(idof,2,j)\t\t+ &\n\t\t\t\t gx4 * v(idof,4,j)\t\t+ &\n\t\t\t\t gx5 * v(idof,5,j)\t\t+ &\n\t\t\t\t gx6 * v(idof,6,j)\t\t) \n\t end do\n\t end do\n!$omp end parallel do \n\n\tend if\n\t\n\tif (rsym) then\n!$doacross local( idof, isign )\n!$omp parallel do private(idof, isign)\n do j = 1, ny\n\t do idof = 1, ndof\n\t if (idof .eq. 3) then\n\t isign = -one\n\t else\n\t isign = one\n\t end if\n \n\t g1v(idof,nx-2,j) = ( gx1 * v(idof,nx-5,j)\t + &\n\t\t\t\t gx2 * v(idof,nx-4,j)\t + &\n\t\t\t\t gx3 * v(idof,nx-3,j)\t + &\n\t\t\t\t gx4 * v(idof,nx-1,j)\t\t+ &\n\t\t\t\t gx5 * v(idof,nx, j)\t\t+ &\n\t\t\t\t isign * gx6 * v(idof,nx-1,j)\t) \n \n\t g1v(idof,nx-1,j) = ( gx1 * v(idof,nx-4,j)\t + &\n\t\t\t\t gx2 * v(idof,nx-3,j)\t + &\n\t\t\t\t gx3 * v(idof,nx-2,j)\t\t+ &\n\t\t\t\t gx4 * v(idof,nx, j)\t\t+ &\n\t\t\t\t isign * gx5 * v(idof,nx-1,j)\t+ &\n\t\t\t\t isign * gx6 * v(idof,nx-2,j)\t) \n \n\t g1v(idof,nx,j) = ( gx1 * v(idof,nx-3,j)\t + &\n\t\t\t\t gx2 * v(idof,nx-2,j)\t\t+ &\n\t\t\t\t gx3 * v(idof,nx-1,j)\t\t+ &\n\t\t\t\t isign * gx4 * v(idof,nx-1,j)\t+ &\n\t\t\t\t isign * gx5 * v(idof,nx-2,j)\t+ &\n\t\t\t\t isign * gx6 * v(idof,nx-3,j)\t) \n\t end do\n\t end do\n!$omp end parallel do \n\n\tend if\n\n!.... interior\n\n!$doacross local(i,idof)\n!$omp parallel do private(i,idof)\n do j = 1, ny\n do i = 4, nx-3\n do idof = 1, ndof\n\t g1v(idof,i,j) = ( gx1 * v(idof,i-3,j)\t+ &\n\t gx2 * v(idof,i-2,j)\t+ &\n\t gx3 * v(idof,i-1,j)\t+ &\n\t\t\t gx4 * v(idof,i+1,j)\t+ &\n\t\t\t gx5 * v(idof,i+2,j)\t+ &\n\t\t\t gx6 * v(idof,i+3,j)\t) \n\t end do\n\t end do\n\tend do\n!$omp end parallel do \n\n!=============================================================================!\n!.... compute the gradient in y\n!=============================================================================!\n\n\tif (yper) then\n\t\n!$doacross\n!$omp parallel do\n do i = 1, nx\n\n\t g2v(:,i,1) = ( gy1 * v(:,i,ny-3)\t+ &\n\t\t\t\tgy2 * v(:,i,ny-2)\t+ &\n\t\t\t\tgy3 * v(:,i,ny-1)\t+ &\n\t\t\t\tgy4 * v(:,i,2)\t\t+ &\n\t\t\t\tgy5 * v(:,i,3)\t\t+ &\n\t\t\t\tgy6 * v(:,i,4) \t) \n \n\t g2v(:,i,2) = ( gy1 * v(:,i,ny-2)\t+ &\n\t\t\t\tgy2 * v(:,i,ny-1)\t+ &\n\t\t\t\tgy3 * v(:,i,1)\t\t+ &\n\t\t\t\tgy4 * v(:,i,3)\t\t+ &\n\t\t\t\tgy5 * v(:,i,4)\t\t+ &\n\t\t\t\tgy6 * v(:,i,5)\t) \n \n\t g2v(:,i,3) = ( gy1 * v(:,i,ny-1)\t+ &\n\t\t\t\tgy2 * v(:,i,1)\t\t+ &\n\t\t\t\tgy3 * v(:,i,2)\t\t+ &\n\t\t\t\tgy4 * v(:,i,4)\t\t+ &\n\t\t\t\tgy5 * v(:,i,5)\t\t+ &\n\t\t\t\tgy6 * v(:,i,6)\t) \n \n\t g2v(:,i,ny-2) = ( gy1 * v(:,i,ny-5)\t+ &\n\t\t\t\tgy2 * v(:,i,ny-4)\t+ &\n\t\t\t\tgy3 * v(:,i,ny-3)\t+ &\n\t\t\t\tgy4 * v(:,i,ny-1)\t+ &\n\t\t\t\tgy5 * v(:,i,1)\t\t+ &\n\t\t\t\tgy6 * v(:,i,2)\t) \n \n\t g2v(:,i,ny-1) = ( gy1 * v(:,i,ny-4)\t+ &\n\t\t\t\tgy2 * v(:,i,ny-3)\t+ &\n\t\t\t\tgy3 * v(:,i,ny-2)\t+ &\n\t\t\t\tgy4 * v(:,i,1)\t\t+ &\n\t\t\t\tgy5 * v(:,i,2)\t\t+ &\n\t\t\t\tgy6 * v(:,i,3)\t) \n \n\t g2v(:,i,ny) = g2v(:,i,1)\n\n end do\n!$omp end parallel do \n\n\telse if (carp ) then ! Implement Carpenter's boundary stencil\n\n!$doacross\n!$omp parallel do\n do i = 1, nx\n\n\t g2v(:,i,1) = ( gg1 * v(:,i,1)\t+ &\n\t\t\t gg2 * v(:,i,2) \t+ &\n\t\t\t gg3 * v(:,i,3) \t+ &\n\t\t\t gg4 * v(:,i,4) \t+ &\n\t\t\t gg5 * v(:,i,5) \t+ &\n\t\t\t gg6 * v(:,i,6) ) * dyinv\n \n\t g2v(:,i,2) = ( gh1 * v(:,i,1) \t+ &\n\t\t\t gh2 * v(:,i,2) \t+ &\n\t\t\t gh3 * v(:,i,3) \t+ &\n\t\t\t gh4 * v(:,i,4) \t+ &\n\t\t\t gh5 * v(:,i,5) \t+ &\n\t\t\t gh6 * v(:,i,6) ) * dyinv\n\n\t g2v(:,i,3) = ( gi1 * v(:,i,1) \t+ &\n\t\t\t gi2 * v(:,i,2) \t+ &\n\t\t\t gi3 * v(:,i,3) \t+ &\n\t\t\t gi4 * v(:,i,4) \t+ &\n\t\t\t gi5 * v(:,i,5) \t+ &\n\t\t\t gi6 * v(:,i,6) ) * dyinv\n\n\t g2v(:,i,4) = ( gj1 * v(:,i,1) \t+ &\n\t\t\t gj2 * v(:,i,2) \t+ &\n\t\t\t gj3 * v(:,i,3) \t+ &\n\t\t\t gj4 * v(:,i,4) \t+ &\n\t\t\t gj5 * v(:,i,5) \t+ &\n\t\t\t gj6 * v(:,i,6) ) * dyinv\n\n\t g2v(:,i,ny-3) = -( gj1 * v(:,i,ny) \t+ &\n\t\t\t gj2 * v(:,i,ny-1) + &\n\t\t\t gj3 * v(:,i,ny-2) + &\n\t\t\t gj4 * v(:,i,ny-3) + &\n\t\t\t gj5 * v(:,i,ny-4) + &\n\t\t\t gj6 * v(:,i,ny-5) ) * dyinv\n\n\t g2v(:,i,ny-2) = -( gi1 * v(:,i,ny) \t+ &\n\t\t\t gi2 * v(:,i,ny-1) + &\n\t\t\t gi3 * v(:,i,ny-2) + &\n\t\t\t gi4 * v(:,i,ny-3) + &\n\t\t\t gi5 * v(:,i,ny-4) + &\n\t\t\t gi6 * v(:,i,ny-5) ) * dyinv\n\n\t g2v(:,i,ny-1) = -( gh1 * v(:,i,ny) \t+ &\n\t\t\t gh2 * v(:,i,ny-1) + &\n\t\t\t gh3 * v(:,i,ny-2) + &\n\t\t\t gh4 * v(:,i,ny-3) + &\n\t\t\t gh5 * v(:,i,ny-4) + &\n\t\t\t gh6 * v(:,i,ny-5) ) * dyinv\n\n\t g2v(:,i,ny) = -( gg1 * v(:,i,ny) \t+ &\n\t\t\t gg2 * v(:,i,ny-1) + &\n\t\t\t gg3 * v(:,i,ny-2) + &\n\t\t\t gg4 * v(:,i,ny-3) + &\n\t\t\t gg5 * v(:,i,ny-4) + &\n\t\t\t gg6 * v(:,i,ny-5) ) * dyinv\n\t end do\n!$omp end parallel do \n\n\telse ! normal boundary differences (must use for implicit)\n\n!$doacross\n!$omp parallel do\n do i = 1, nx\n\n\t g2v(:,i,1) = ( gc1 * v(:,i,1)\t+ &\n\t\t\t gc2 * v(:,i,2) \t+ &\n\t\t\t gc3 * v(:,i,3) \t+ &\n\t\t\t gc4 * v(:,i,4) \t+ &\n\t\t\t gc5 * v(:,i,5) ) * dyinv\n\n\t g2v(:,i,2) = ( gb1 * v(:,i,1) \t+ &\n\t\t\t gb2 * v(:,i,2) \t+ &\n\t\t\t gb3 * v(:,i,3) \t+ &\n\t\t\t gb4 * v(:,i,4) \t+ &\n\t\t\t gb5 * v(:,i,5) ) * dyinv\n \n\t g2v(:,i,3) = ( ga1 * v(:,i,1) \t+ &\n\t\t\t ga2 * v(:,i,2) \t+ &\n\t\t\t ga3 * v(:,i,4) \t+ &\n\t\t\t ga4 * v(:,i,5) ) * dyinv\n \n\t g2v(:,i,ny-2) = ( ga1 * v(:,i,ny-4) + &\n\t\t\t ga2 * v(:,i,ny-3) + &\n\t\t\t ga3 * v(:,i,ny-1) + &\n\t\t\t ga4 * v(:,i,ny ) ) * dyinv\n \n\t g2v(:,i,ny-1) = -( gb1 * v(:,i,ny ) + &\n\t\t\t gb2 * v(:,i,ny-1) + &\n\t\t\t gb3 * v(:,i,ny-2) \t+ &\n\t\t\t gb4 * v(:,i,ny-3) + &\n\t\t\t gb5 * v(:,i,ny-4) ) * dyinv\n \n\t g2v(:,i,ny) = -( gc1 * v(:,i,ny ) + &\n\t\t\t gc2 * v(:,i,ny-1) + &\n\t\t\t gc3 * v(:,i,ny-2) + &\n\t\t\t gc4 * v(:,i,ny-3) + &\n\t\t\t gc5 * v(:,i,ny-4) ) * dyinv\n\t\t\t \n\t end do\n!$omp end parallel do \n\n\tend if\n\t\n!.... interior\n\n!$doacross local(j,idof)\n!$omp parallel do private(j,idof)\n do i = 1, nx\n do j = 4, ny-3\n do idof = 1, ndof\n\t g2v(idof,i,j) = ( gy1 * v(idof,i,j-3)\t+ &\n\t\t\t gy2 * v(idof,i,j-2)\t+ &\n\t\t\t gy3 * v(idof,i,j-1)\t+ &\n\t\t\t gy4 * v(idof,i,j+1)\t+ &\n\t\t\t gy5 * v(idof,i,j+2)\t+ &\n\t\t\t gy6 * v(idof,i,j+3)\t) \n\t end do\n\t end do\n\tend do\n!$omp end parallel do \n\t\n!.... implement a filter of roundoff noise\n\n\tif (.false.) then\n\n!$omp parallel do private(i,idof)\n\t do j = 1, ny\n\t do i = 1, nx\n\t do idof = 1, ndof\n\t\tif ( abs(g1v(idof,i,j)) .lt. eps ) g1v(idof,i,j) = zero\n\t\tif ( abs(g2v(idof,i,j)) .lt. eps ) g2v(idof,i,j) = zero\n\t end do\n\t end do\n\t end do\n\n\tend if\n\n\treturn\n\tend\n", "meta": {"hexsha": "d9f6e85d32c778681ee8b34db3f3d77e9ccf49fc", "size": 13933, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "pre/src_ij/grad.f90", "max_stars_repo_name": "sscollis/lns3d", "max_stars_repo_head_hexsha": "f87b06abbb188cce9248092075f71dcce4570493", "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": "pre/src_ij/grad.f90", "max_issues_repo_name": "sscollis/lns3d", "max_issues_repo_head_hexsha": "f87b06abbb188cce9248092075f71dcce4570493", "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": "pre/src_ij/grad.f90", "max_forks_repo_name": "sscollis/lns3d", "max_forks_repo_head_hexsha": "f87b06abbb188cce9248092075f71dcce4570493", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-02-20T09:24:25.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-20T09:24:25.000Z", "avg_line_length": 25.5651376147, "max_line_length": 79, "alphanum_fraction": 0.3475920477, "num_tokens": 6288, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989822921759, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6651048149095078}} {"text": "!NCLFORTSTART\nSUBROUTINE ROTATECOORDS(ilat, ilon, olat, olon, lat_np, lon_np, lon_0, direction)\n USE wrf_constants, ONLY : PI, RAD_PER_DEG, DEG_PER_RAD\n\n IMPLICIT NONE\n\n !f2py threadsafe\n !f2py intent(in,out) :: olat, olon\n\n REAL(KIND=8), INTENT(IN) :: ilat, ilon\n REAL(KIND=8), INTENT(OUT) :: olat, olon\n REAL(KIND=8), INTENT(IN) :: lat_np, lon_np, lon_0\n INTEGER, INTENT(IN) :: direction\n\n! NCLFORTEND\n\n ! >=0, default : computational -> geographical\n ! < 0 : geographical -> computational\n\n REAL(KIND=8) :: rlat, rlon\n REAL(KIND=8) :: phi_np, lam_np, lam_0, dlam\n REAL(KIND=8) :: sinphi, cosphi, coslam, sinlam\n !REAL(KIND=8), PARAMETER :: PI=3.141592653589793D0\n !REAL(KIND=8), PARAMETER :: RAD_PER_DEG=PI/180.D0\n !REAL(KIND=8), PARAMETER :: DEG_PER_RAD=180.D0/PI\n\n !convert all angles to radians\n phi_np = lat_np*RAD_PER_DEG\n lam_np = lon_np*RAD_PER_DEG\n lam_0 = lon_0*RAD_PER_DEG\n rlat = ilat*RAD_PER_DEG\n rlon = ilon*RAD_PER_DEG\n\n IF (direction .LT. 0) THEN\n ! the equations are exactly the same except for one\n ! small difference with respect to longitude ...\n dlam = pi - lam_0\n ELSE\n dlam = lam_np\n END IF\n\n sinphi = COS(phi_np)*COS(rlat)*COS(rlon - dlam) + SIN(phi_np)*SIN(rlat)\n cosphi = SQRT(1.D0 - sinphi*sinphi)\n coslam = SIN(phi_np)*COS(rlat)*COS(rlon - dlam) - COS(phi_np)*SIN(rlat)\n sinlam = COS(rlat)*SIN(rlon - dlam)\n\n IF (cosphi.NE.0.D0) THEN\n coslam = coslam/cosphi\n sinlam = sinlam/cosphi\n END IF\n\n olat = DEG_PER_RAD*ASIN(sinphi)\n olon = DEG_PER_RAD*(ATAN2(sinlam,coslam) - dlam - lam_0 + lam_np)\n\n RETURN\n\nEND SUBROUTINE ROTATECOORDS\n\n\n!NCLFORTSTART\nSUBROUTINE DLLTOIJ(map_proj, truelat1, truelat2, stdlon, lat1, lon1,&\n pole_lat, pole_lon, knowni, knownj, dx, dy, latinc,&\n loninc, lat, lon, loc, errstat, errmsg)\n USE wrf_constants, ONLY : ALGERR, PI, RAD_PER_DEG, DEG_PER_RAD, WRF_EARTH_RADIUS\n\n ! Converts input lat/lon values to the cartesian (i,j) value\n ! for the given projection.\n\n IMPLICIT NONE\n\n !f2py threadsafe\n !f2py intent(in,out) :: loc\n\n\n INTEGER, INTENT(IN) :: map_proj\n REAL(KIND=8), INTENT(IN) :: stdlon\n REAL(KIND=8), INTENT(IN) ::lat1, lon1, pole_lat, pole_lon, knowni, knownj\n REAL(KIND=8), INTENT(IN) ::dx, dy, latinc, loninc\n REAL(KIND=8), INTENT(INOUT) :: lat, lon, truelat1, truelat2 ! these might get modified\n REAL(KIND=8), DIMENSION(2), INTENT(OUT) :: loc\n INTEGER, INTENT(INOUT) :: errstat\n CHARACTER(LEN=*), INTENT(INOUT) :: errmsg\n\n!NCLEND\n\n REAL(KIND=8) :: deltalon1\n REAL(KIND=8) :: tl1r\n REAL(KIND=8) :: clain, dlon, rsw, deltalon, deltalat\n REAL(KIND=8) :: reflon, scale_top, ala1, alo1, ala, alo, rm, polei, polej\n ! earth radius divided by dx\n REAL(KIND=8) :: rebydx\n REAL(KIND=8) :: ctl1r, arg, cone, hemi\n REAL(KIND=8) :: i, j\n REAL(KIND=8) :: lat1n, lon1n, olat, olon\n\n ! Contants\n !REAL(KIND=8),PARAMETER :: PI=3.141592653589793D0\n !REAL(KIND=8),PARAMETER :: RAD_PER_DEG=PI/180.D0\n !REAL(KIND=8),PARAMETER :: DEG_PER_RAD=180.D0/PI\n !REAL(KIND=8),PARAMETER :: RE_M=6370000.D0 ! radius of earth in meters\n\n ! lat1 ! sw latitude (1,1) in degrees (-90->90n)\n ! lon1 ! sw longitude (1,1) in degrees (-180->180e)\n ! dx ! grid spacing in meters at truelats\n ! dlat ! lat increment for lat/lon grids\n ! dlon ! lon increment for lat/lon grids\n ! stdlon ! longitude parallel to y-axis (-180->180e)\n ! truelat1 ! first true latitude (all projections)\n ! truelat2 ! second true lat (lc only)\n ! hemi ! 1 for nh, -1 for sh\n ! cone ! cone factor for lc projections\n ! polei ! computed i-location of pole point\n ! polej ! computed j-location of pole point\n ! rsw ! computed radius to sw corner\n ! knowni ! x-location of known lat/lon\n ! knownj ! y-location of known lat/lon\n ! re_m ! radius of spherical earth, meters\n ! rebydx ! earth radius divided by dx\n\n errstat = INT(dy) ! remove compiler warning since dy not used\n errstat = 0\n\n rebydx = WRF_EARTH_RADIUS/dx\n\n ! Get rid of compiler warnings\n i=0\n j=0\n\n hemi = 1.0D0\n IF (truelat1 .LT. 0.0D0) THEN\n hemi = -1.0D0\n END IF\n\n ! mercator\n IF (map_proj.EQ.3) THEN\n\n ! preliminary variables\n clain = COS(RAD_PER_DEG*truelat1)\n dlon = dx/(WRF_EARTH_RADIUS*clain)\n\n ! compute distance from equator to origin, and store in\n ! the rsw tag.\n rsw = 0.D0\n IF (lat1 .NE. 0.D0) THEN\n rsw = (LOG(TAN(0.5D0*((lat1 + 90.D0)*RAD_PER_DEG))))/dlon\n END IF\n\n deltalon = lon - lon1\n IF (deltalon .LT. -180.D0) deltalon = deltalon + 360.D0\n IF (deltalon .GT. 180.D0) deltalon = deltalon - 360.D0\n i = knowni + (deltalon/(dlon*DEG_PER_RAD))\n j = knownj + (LOG(TAN(0.5D0*((lat + 90.D0)*RAD_PER_DEG))))/dlon - rsw\n\n ! ps\n ELSE IF (map_proj .EQ. 2) THEN\n\n reflon = stdlon + 90.D0\n\n ! compute numerator term of map scale factor\n scale_top = 1.D0 + hemi*SIN(truelat1*RAD_PER_DEG)\n\n ! compute radius to lower-left (sw) corner\n ala1 = lat1*RAD_PER_DEG\n rsw = rebydx*COS(ala1)*scale_top/(1.D0 + hemi*SIN(ala1))\n\n ! find the pole point\n alo1 = (lon1 - reflon)*RAD_PER_DEG\n polei = knowni - rsw*COS(alo1)\n polej = knownj - hemi*rsw*SIN(alo1)\n\n ! find radius to desired point\n ala = lat*RAD_PER_DEG\n rm = rebydx*COS(ala)*scale_top/(1.D0 + hemi*SIN(ala))\n alo = (lon - reflon)*RAD_PER_DEG\n i = polei + rm*COS(alo)\n j = polej + hemi*rm*SIN(alo)\n\n ! lambert\n ELSE IF (map_proj .EQ. 1) THEN\n\n IF (ABS(truelat2) .GT. 90.D0) THEN\n truelat2 = truelat1\n END IF\n\n IF (ABS(truelat1 - truelat2) .GT. 0.1D0) THEN\n cone = (LOG(COS(truelat1*RAD_PER_DEG))-LOG(COS(truelat2*RAD_PER_DEG)))/&\n (LOG(TAN((90.D0 - ABS(truelat1))*RAD_PER_DEG*0.5D0))-&\n LOG(TAN((90.D0 - ABS(truelat2))*RAD_PER_DEG*0.5D0)))\n ELSE\n cone = SIN(ABS(truelat1)*RAD_PER_DEG)\n END IF\n\n ! compute longitude differences and ensure we stay\n ! out of the forbidden \"cut zone\"\n deltalon1 = lon1 - stdlon\n IF (deltalon1 .GT. +180.D0) deltalon1 = deltalon1 - 360.D0\n IF (deltalon1 .LT. -180.D0) deltalon1 = deltalon1 + 360.D0\n\n ! convert truelat1 to radian and compute cos for later use\n tl1r = truelat1*RAD_PER_DEG\n ctl1r = COS(tl1r)\n\n ! compute the radius to our known lower-left (sw) corner\n rsw = rebydx*ctl1r/cone*(TAN((90.D0*hemi - lat1)*RAD_PER_DEG/2.D0)/&\n TAN((90.D0*hemi - truelat1)*RAD_PER_DEG/2.D0))**cone\n\n ! find pole point\n arg = cone*(deltalon1*RAD_PER_DEG)\n polei = hemi*knowni - hemi*rsw*SIN(arg)\n polej = hemi*knownj + rsw*COS(arg)\n\n ! compute deltalon between known longitude and standard\n ! lon and ensure it is not in the cut zone\n deltalon = lon - stdlon\n IF (deltalon .GT. +180.D0) deltalon = deltalon - 360.D0\n IF (deltalon .LT. -180.D0) deltalon = deltalon + 360.D0\n\n ! radius to desired point\n rm = rebydx*ctl1r/cone*(TAN((90.D0*hemi - lat)*RAD_PER_DEG/2.D0)/&\n TAN((90.D0*hemi - truelat1)*RAD_PER_DEG/2.D0))**cone\n\n arg = cone*(deltalon*RAD_PER_DEG)\n i = polei + hemi*rm*SIN(arg)\n j = polej - rm*COS(arg)\n\n ! finally, if we are in the southern hemisphere, flip the\n ! i/j values to a coordinate system where (1,1) is the sw\n ! corner (what we assume) which is different than the\n ! original ncep algorithms which used the ne corner as\n ! the origin in the southern hemisphere (left-hand vs.\n ! right-hand coordinate?)\n i = hemi*i\n j = hemi*j\n\n ! lat-lon\n ELSE IF (map_proj .EQ. 6) THEN\n\n IF (pole_lat .NE. 90.D0) THEN\n CALL ROTATECOORDS(lat, lon, olat, olon, pole_lat, pole_lon, stdlon, -1)\n lat = olat\n lon = olon + stdlon\n END IF\n\n ! make sure center lat/lon is good\n IF (pole_lat .NE. 90.D0) THEN\n CALL ROTATECOORDS(lat1, lon1, olat, olon, pole_lat, pole_lon, stdlon, -1)\n lat1n = olat\n lon1n = olon + stdlon\n deltalat = lat - lat1n\n deltalon = lon - lon1n\n ELSE\n deltalat = lat - lat1\n deltalon = lon - lon1\n END IF\n\n ! compute i/j\n i = deltalon/loninc\n j = deltalat/latinc\n\n i = i + knowni\n j = j + knownj\n\n ELSE\n errstat = ALGERR\n WRITE(errmsg, *) \"Do not know map projection \", map_proj\n RETURN\n END IF\n\n loc(1) = j\n loc(2) = i\n\n RETURN\n\nEND SUBROUTINE DLLTOIJ\n\n\n!NCLFORTSTART\nSUBROUTINE DIJTOLL(map_proj, truelat1, truelat2, stdlon, lat1, lon1,&\n pole_lat, pole_lon, knowni, knownj, dx, dy, latinc,&\n loninc, ai, aj, loc, errstat, errmsg)\n USE wrf_constants, ONLY : ALGERR, PI, RAD_PER_DEG, DEG_PER_RAD, WRF_EARTH_RADIUS\n\n ! converts input lat/lon values to the cartesian (i,j) value\n ! for the given projection.\n IMPLICIT NONE\n\n !f2py threadsafe\n !f2py intent(in,out) :: loc\n\n INTEGER, INTENT(IN) :: map_proj\n REAL(KIND=8), INTENT(IN) :: stdlon\n REAL(KIND=8), INTENT(IN) :: lat1, lon1, pole_lat, pole_lon, knowni, knownj\n REAL(KIND=8), INTENT(IN) :: dx, dy, latinc, loninc, ai, aj\n REAL(KIND=8), INTENT(INOUT) :: truelat1, truelat2\n REAL(KIND=8), DIMENSION(2), INTENT(OUT) :: loc\n INTEGER, INTENT(INOUT) :: errstat\n CHARACTER(LEN=*), INTENT(INOUT) :: errmsg\n\n!NCLEND\n\n REAL(KIND=8) :: gi2\n REAL(KIND=8) :: arccos\n REAL(KIND=8) :: deltalon1\n REAL(KIND=8) :: tl1r\n REAL(KIND=8) :: clain, dlon, rsw, deltalon, deltalat\n REAL(KIND=8) :: reflon, scale_top, ala1, alo1, polei, polej\n ! earth radius divided by dx\n REAL(KIND=8) :: rebydx\n REAL(KIND=8) :: ctl1r, cone, hemi\n\n !REAL(KIND=8),PARAMETER :: PI = 3.141592653589793D0\n !REAL(KIND=8),PARAMETER :: RAD_PER_DEG = PI/180.D0\n !REAL(KIND=8),PARAMETER :: DEG_PER_RAD = 180.D0/PI\n !REAL(KIND=8),PARAMETER :: RE_M = 6370000.D0 ! radius of sperical earth\n\n REAL(KIND=8) :: inew, jnew, r, r2\n REAL(KIND=8) :: chi, chi1, chi2\n REAL(KIND=8) :: xx, yy, lat, lon\n\n REAL(KIND=8) :: olat, olon, lat1n, lon1n\n\n\n ! lat1 ! sw latitude (1,1) in degrees (-90->90n)\n ! lon1 ! sw longitude (1,1) in degrees (-180->180e)\n ! dx ! grid spacing in meters at truelats\n ! dlat ! lat increment for lat/lon grids\n ! dlon ! lon increment for lat/lon grids\n ! stdlon ! longitude parallel to y-axis (-180->180e)\n ! truelat1 ! first true latitude (all projections)\n ! truelat2 ! second true lat (lc only)\n ! hemi ! 1 for nh, -1 for sh\n ! cone ! cone factor for lc projections\n ! polei ! computed i-location of pole point\n ! polej ! computed j-location of pole point\n ! rsw ! computed radius to sw corner\n ! knowni ! x-location of known lat/lon\n ! knownj ! y-location of known lat/lon\n ! re_m ! radius of spherical earth, meters\n ! rebydx ! earth radius divided by dx\n\n errstat = INT(dy) ! Remove compiler warning since dy not used\n errstat = 0\n\n rebydx = WRF_EARTH_RADIUS/dx\n\n hemi = 1.0D0\n IF (truelat1 .LT. 0.0D0) THEN\n hemi = -1.0D0\n END IF\n\n ! mercator\n IF (map_proj .EQ. 3) THEN\n ! preliminary variables\n clain = COS(RAD_PER_DEG*truelat1)\n dlon = dx/(WRF_EARTH_RADIUS*clain)\n\n ! compute distance from equator to origin, and store in\n ! the rsw tag.\n rsw = 0.D0\n IF (lat1 .NE. 0.D0) THEN\n rsw = (LOG(TAN(0.5D0*((lat1 + 90.D0)*RAD_PER_DEG))))/dlon\n END IF\n\n lat = 2.0D0*ATAN(EXP(dlon*(rsw + aj - knownj)))*DEG_PER_RAD - 90.D0\n lon = (ai - knowni)*dlon*DEG_PER_RAD + lon1\n IF (lon .GT. 180.D0) lon = lon - 360.D0\n IF (lon .LT. -180.D0) lon = lon + 360.D0\n\n ! ps\n ELSE IF (map_proj .EQ. 2) THEN\n\n ! compute the reference longitude by rotating 90 degrees to\n ! the east to find the longitude line parallel to the\n ! positive x-axis.\n reflon = stdlon + 90.D0\n\n ! compute numerator term of map scale factor\n scale_top = 1.D0 + hemi*SIN(truelat1*RAD_PER_DEG)\n\n ! compute radius to known point\n ala1 = lat1*RAD_PER_DEG\n rsw = rebydx*COS(ala1)*scale_top/(1.D0 + hemi*SIN(ala1))\n\n ! find the pole point\n alo1 = (lon1 - reflon)*RAD_PER_DEG\n polei = knowni - rsw*COS(alo1)\n polej = knownj - hemi*rsw*SIN(alo1)\n\n ! compute radius to point of interest\n xx = ai - polei\n yy = (aj - polej)*hemi\n r2 = xx**2 + yy**2\n\n ! now the magic code\n IF (r2 .EQ. 0.D0) THEN\n lat = hemi*90.D0\n lon = reflon\n ELSE\n gi2 = (rebydx*scale_top)**2.D0\n lat = DEG_PER_RAD*hemi*ASIN((gi2 - r2)/(gi2 + r2))\n arccos = ACOS(xx/SQRT(r2))\n IF (yy .GT. 0) THEN\n lon = reflon + DEG_PER_RAD*arccos\n ELSE\n lon = reflon - DEG_PER_RAD*arccos\n END IF\n END IF\n\n ! convert to a -180 -> 180 east convention\n IF (lon .GT. 180.D0) lon = lon - 360.D0\n IF (lon .LT. -180.D0) lon = lon + 360.D0\n\n ! !lambert\n ELSE IF (map_proj .EQ. 1) THEN\n\n IF (ABS(truelat2) .GT. 90.D0) THEN\n truelat2 = truelat1\n END IF\n\n IF (ABS(truelat1 - truelat2) .GT. 0.1D0) THEN\n cone = (LOG(COS(truelat1*RAD_PER_DEG)) - LOG(COS(truelat2*RAD_PER_DEG)))/&\n (LOG(TAN((90.D0 - ABS(truelat1))*RAD_PER_DEG*0.5D0)) - &\n LOG(TAN((90.D0 - ABS(truelat2))*RAD_PER_DEG*0.5D0)))\n ELSE\n cone = SIN(ABS(truelat1)*RAD_PER_DEG)\n END IF\n\n ! compute longitude differences and ensure we stay out of the\n ! forbidden \"cut zone\"\n deltalon1 = lon1 - stdlon\n IF (deltalon1 .GT. +180.D0) deltalon1 = deltalon1 - 360.D0\n IF (deltalon1 .LT. -180.D0) deltalon1 = deltalon1 + 360.D0\n\n ! convert truelat1 to radian and compute cos for later use\n tl1r = truelat1*RAD_PER_DEG\n ctl1r = COS(tl1r)\n\n ! compute the radius to our known point\n rsw = rebydx*ctl1r/cone*(TAN((90.D0*hemi - lat1)*RAD_PER_DEG/2.D0)/&\n TAN((90.D0*hemi - truelat1)*RAD_PER_DEG/2.D0))**cone\n\n ! find pole point\n alo1 = cone*(deltalon1*RAD_PER_DEG)\n polei = hemi*knowni - hemi*rsw*SIN(alo1)\n polej = hemi*knownj + rsw*COS(alo1)\n\n chi1 = (90.D0 - hemi*truelat1)*RAD_PER_DEG\n chi2 = (90.D0 - hemi*truelat2)*RAD_PER_DEG\n\n ! see if we are in the southern hemispere and flip the\n ! indices if we are.\n inew = hemi*ai\n jnew = hemi*aj\n\n ! compute radius**2 to i/j location\n reflon = stdlon + 90.D0\n xx = inew - polei\n yy = polej - jnew\n r2 = (xx*xx + yy*yy)\n r = sqrt(r2)/rebydx\n\n ! convert to lat/lon\n IF (r2 .EQ. 0.D0) THEN\n lat = hemi*90.D0\n lon = stdlon\n ELSE\n lon = stdlon + DEG_PER_RAD*ATAN2(hemi*xx,yy)/cone\n lon = dmod(lon + 360.D0, 360.D0)\n IF (chi1 .EQ. chi2) THEN\n chi = 2.0D0*ATAN((r/TAN(chi1))**(1.D0/cone)*TAN(chi1*0.5D0))\n ELSE\n chi = 2.0D0*ATAN((r*cone/SIN(chi1))**(1.D0/cone)*TAN(chi1*0.5D0))\n END IF\n lat = (90.0D0 - chi*DEG_PER_RAD)*hemi\n END IF\n\n IF (lon .GT. +180.D0) lon = lon - 360.D0\n IF (lon .LT. -180.D0) lon = lon + 360.D0\n\n ! !lat-lon\n ELSE IF (map_proj .EQ. 6) THEN\n inew = ai - knowni\n jnew = aj - knownj\n\n IF (inew .LT. 0.D0) inew = inew + 360.D0/loninc\n IF (inew .GE. 360.D0/dx) inew = inew - 360.D0/loninc\n\n ! compute deltalat and deltalon\n deltalat = jnew*latinc\n deltalon = inew*loninc\n\n IF (pole_lat .NE. 90.D0) THEN\n CALL ROTATECOORDS(lat1, lon1, olat, olon, pole_lat, pole_lon, stdlon, -1)\n lat1n = olat\n lon1n = olon + stdlon\n lat = deltalat + lat1n\n lon = deltalon + lon1n\n ELSE\n lat = deltalat + lat1\n lon = deltalon + lon1\n END IF\n\n IF (pole_lat .NE. 90.D0) THEN\n lon = lon - stdlon\n CALL ROTATECOORDS(lat, lon, olat, olon, pole_lat, pole_lon, stdlon, 1)\n lat = olat\n lon = olon\n END IF\n\n IF (lon .LT. -180.D0) lon = lon + 360.D0\n IF (lon .GT. 180.D0) lon = lon - 360.D0\n\n ELSE\n errstat = ALGERR\n WRITE(errmsg, *) \"Do not know map projection \", map_proj\n RETURN\n END IF\n\n loc(1) = lat\n loc(2) = lon\n\n RETURN\n\nEND SUBROUTINE DIJTOLL\n", "meta": {"hexsha": "c6c5725b156f155c639d2855293f41ec8f92d96f", "size": 17266, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ni/src/lib/nfpfort/wrf_user_latlon_routines.f90", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 315, "max_stars_repo_stars_event_min_datetime": "2016-12-29T17:42:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T03:57:41.000Z", "max_issues_repo_path": "ni/src/lib/nfpfort/wrf_user_latlon_routines.f90", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "ni/src/lib/nfpfort/wrf_user_latlon_routines.f90", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 112, "max_forks_repo_forks_event_min_datetime": "2016-12-29T12:56:52.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-16T08:05:49.000Z", "avg_line_length": 32.8876190476, "max_line_length": 90, "alphanum_fraction": 0.5724545349, "num_tokens": 6001, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422186079557, "lm_q2_score": 0.6992544085240401, "lm_q1q2_score": 0.6650903894949493}} {"text": " SUBROUTINE DTWODQ(F,AA,BB,G,H,TOL,ERE,IR_0,RESULT,ERROR)\n \nC***BEGIN PROLOGUE TWODQ\nC***DATE WRITTEN 840518 (YYMMDD)\nC***REVISION DATE 840518 (YYMMDD)\nC***CATEGORY NO. D1I\nC***KEYWORDS QUADRATURE,TWO DIMENSIONAL,ADAPTIVE,CUBATURE\nC***AUTHOR KAHANER,D.K.,N.B.S.\nC RECHARD,O.W.,N.B.S.\nC BARNHILL,ROBERT,UNIV. OF UTAH\nC***PURPOSE To compute the two-dimensional integral of a function\nC F over a region consisting of N triangles.\nC***DESCRIPTION\nC\nC This subroutine computes the two-dimensional integral of a\nC function F over a region consisting of N triangles.\nC A total error estimate is obtained and compared with a\nC tolerance - TOL - that is provided as input to the subroutine.\nC The error tolerance is treated as either relative or absolute\nC depending on the input value of IFLAG. A 'Local Quadrature\nC Module' is applied to each input triangle and estimates of the\nC total integral and the total error are computed. The local\nC quadrature module is either subroutine LQM0 or subroutine\nC LQM1 and the choice between them is determined by the\nC value of the input variable ICLOSE.\nC\nC If the total error estimate exceeds the tolerance, the triangle\nC with the largest absolute error is divided into two triangles\nC by a median to its longest side. The local quadrature module\nC is then applied to each of the subtriangles to obtain new\nC estimates of the integral and the error. This process is\nC repeated until either (1) the error tolerance is satisfied,\nC (2) the number of triangles generated exceeds the input\nC parameter MAXTRI, (3) the number of integrand evaluations\nC exceeds the input parameter MEVALS, or (4) the subroutine\nC senses that roundoff error is beginning to contaminate\nC the result.\nC\nC The user must specify MAXTRI, the maximum number of triangles\nC in the final triangulation of the region, and provide two\nC storage arrays - DATA and IWORK - whose sizes are at least\nC 9*MAXTRI and 2*MAXTRI respectively. The user must also\nC specify MEVALS, the maximum number of function evaluations\nC to be allowed. This number will be effective in limiting\nC the computation only if it is less than 94*MAXTRI when LQM1\nC is specified or 56*MAXTRI when LQM0 is specified.\nC\nC After the subroutine has returned to the calling program\nC with output values, it can be called again with a smaller\nC value of TOL and/or a different value of MEVALS. The tolerance\nC can also be changed from relative to absolute\nC or vice-versa by changing IFLAG. Unless\nC the parameters NU and ND are reset to zero the subroutine\nC will restart with the final set of triangles and output\nC values from the previous call.\nC\nC ARGUMENTS:\nC\nC F function subprogram defining the integrand F(u,v);\nC the actual name for F needs to be declared EXTERNAL\nC by the calling program.\nC\nC N the number of input triangles.\nC\nC X a 3 by N array containing the abscissae of the vertices\nC of the N triangles.\nC\nC Y a 3 by N array containing the ordinates of the vertices\nC of the N triangles\nC\nC TOL the desired bound on the error. If IFLAG=0 on input,\nC TOL is interpreted as a bound on the relative error;\nC if IFLAG=1, the bound is on the absolute error.\nC\nC ICLOSE an integer parameter that determines the selection\nC of LQM0 or LQM1. If ICLOSE=1 then LQM1 is used.\nC Any other value of ICLOSE causes LQM0 to be used.\nC LQM0 uses function values only at interior points of\nC the triangle. LQM1 is usually more accurate than LQM0\nC but involves evaluating the integrand at more points\nC including some on the boundary of the triangle. It\nC will usually be better to use LQM1 unless the integrand\nC has singularities on the boundary of the triangle.\nC\nC MAXTRI The maximum number of triangles that are allowed\nC to be generated by the computation.\nC\nC MEVALS The maximum number of function evaluations allowed.\nC\nC RESULT output of the estimate of the integral.\nC\nC ERROR output of the estimate of the absolute value of the\nC total error.\nC\nC NU an integer variable used for both input and output. Must\nC be set to 0 on first call of the subroutine. Subsequent\nC calls to restart the subroutine should use the previous\nC output value.\nC\nC ND an integer variable used for both input and output. Must\nC be set to 0 on first call of the subroutine. Subsequent\nC calls to restart the subroutine should use the previous\nC output value.\nC\nC NEVALS The actual number of function evaluations performed.\nC\nC IFLAG on input:\nC IFLAG=0 means TOL is a bound on the relative error;\nC IFLAG=1 means TOL is a bound on the absolute error;\nC any other input value for IFLAG causes the subroutine\nC to return immediately with IFLAG set equal to 9.\nC\nC on output:\nC IFLAG=0 means normal termination;\nC IFLAG=1 means termination for lack of space to divide\nC another triangle;\nC IFLAG=2 means termination because of roundoff noise\nC IFLAG=3 means termination with relative error <=\nC 5.0* machine epsilon;\nC IFLAG=4 means termination because the number of function\nC evaluations has exceeded MEVALS.\nC IFLAG=9 means termination because of error in input flag\nC\nC DATA a one dimensional array of length >= 9*MAXTRI\nC passed to the subroutine by the calling program. It is\nC used by the subroutine to store information\nC about triangles used in the quadrature.\nC\nC IWORK a one dimensional integer array of length >= 2*MAXTRI\nC passed to the subroutine by the calling program.\nC It is used by the subroutine to store pointers\nC to the information in the DATA array.\nC\nC\nC The information for each triangle is contained in a nine word\nC record consisting of the error estimate, the estimate of the\nC integral, the coordinates of the three vertices, and the area.\nC These records are stored in the DATA array\nC that is passed to the subroutine. The storage is organized\nC into two heaps of length NU and ND respectively. The first heap\nC contains those triangles for which the error exceeds\nC epsabs*a/ATOT where epsabs is a bound on the absolute error\nC derived from the input tolerance (which may refer to relative\nC or absolute error), a is the area of the triangle, and ATOT\nC is the total area of all triangles. The second heap contains\nC those triangles for which the error is less than or equal to\nC epsabs*a/ATOT. At the top of each heap is the triangle with\nC the largest absolute error.\nC\nC Pointers into the heaps are contained in the array IWORK.\nC Pointers to the first heap are contained\nC between IWORK(1) and IWORK(NU). Pointers to the second\nC heap are contained between IWORK(MAXTRI+1) and\nC IWORK(MAXTRI+ND). The user thus has access to the records\nC stored in the DATA array through the pointers in IWORK.\nC For example, the following two DO loops will print out\nC the records for each triangle in the two heaps:\nC\nC DO 10 I=1,NU\nC PRINT*,(DATA(IWORK(I)+J),J=0,8)\nC 10 CONTINUE\nC DO 20 I=1,ND\nC PRINT*,(DATA(IWORK(MAXTRI+I)+J),J=0,8\nC 20 CONTINUE\nC\nC When the total number of triangles is equal to\nC MAXTRI, the program attempts to remove a triangle from the\nC bottom of the second heap and continue. If the second heap\nC is empty, the program returns with the current estimates of\nC the integral and the error and with IFLAG set equal to 1.\nC Note that in this case the actual number of triangles\nC processed may exceed MAXTRI and the triangles stored in\nC the DATA array may not constitute a complete triangulation\nC of the region.\nC\nC The following sample program will calculate the integral of\nC cos(x+y) over the square (0.,0.),(1.,0.),(1.,1.),(0.,1.) and\nC print out the values of the estimated integral, the estimated\nC error, the number of function evaluations, and IFLAG.\nC\nC real*8 X(3,2),Y(3,2),DATA(450),RES,ERR\nC INTEGER IWORK(100),NU,ND,NEVALS,IFLAG\nC EXTERNAL F\nC X(1,1)=0.\nC Y(1,1)=0.\nC X(2,1)=1.\nC Y(2,1)=0.\nC X(3,1)=1.\nC Y(3,1)=1.\nC X(1,2)=0.\nC Y(1,2)=0.\nC X(2,2)=1.\nC Y(2,2)=1.\nC X(3,2)=0.\nC Y(3,2)=1.\nC NU=0\nC ND=0\nC IFLAG=1\nC CALL TWODQ(F,2,X,Y,1.E-04,1,50,4000,RES,ERR,NU,ND,\nC * NEVALS,IFLAG,DATA,IWORK)\nC PRINT*,RES,ERR,NEVALS,IFLAG\nC END\nC FUNCTION F(X,Y)\nC F=COS(X+Y)\nC RETURN\nC END\nC\nC***REFERENCES (NONE)\nC\nC***ROUTINES CALLED HINITD,HINITU,HPACC,HPDEL,HPINS,LQM0,LQM1,\nC TRIDV,R1MACH\nC***END PROLOGUE TWODQ\n integer n,iflag,nevals,iclose,nu,nd,mevals,iwork(200),maxtri\n real*8 f,x(3,2),y(3,2),data(900),tol,result,error\n REAL*8 AA,BB,G,H,ERE\n INTEGER IR_0\n integer rndcnt\n logical full\n logical GREATR\n real*8 dat05\n real*8 a,r,e,u(3),v(3),node(9),node1(9),node2(9),\n * epsabs,EMACH,R1MACH,ATOT,fadd,newres,newerr\n save ATOT\n external f,GREATR\n EXTERNAL G,H,R1MACH\n \n EMACH = R1MACH(4)\n \n N = 2\n X(1,1) = AA\r\n Y(1,1) = G(AA)\r\n X(2,1) = BB\r\n Y(2,1) = G(BB)\r\n X(3,1) = BB\r\n Y(3,1) = H(BB)\r\n X(1,2) = AA\r\n Y(1,2) = G(AA)\r\n X(2,2) = BB\r\n Y(2,2) = H(BB)\r\n X(3,2) = AA\r\n Y(3,2) = H(AA)\n NU = 0\r\n ND = 0\r\n IFLAG = 1\n ICLOSE = 1\n MAXTRI = 100\n MEVALS = 8000\n \nc\nc If heaps are empty, apply LQM to each input triangle and\nc place all of the data on the second heap.\nc\n if((nu+nd).eq.0) then\n call HINITU(maxtri,9,nu,iwork)\n call HINITD(maxtri,9,nd,iwork(maxtri+1))\n ATOT=0.0\n result=0.0\n error=0.0\n rndcnt=0\n nevals=0\n do 20 i=1,n\n do 10 j=1,3\n u(j)=x(j,i)\n v(j)=y(j,i)\n 10 continue\n a=0.5*abs(u(1)*v(2)+u(2)*v(3)+u(3)*v(1)\n 1 -u(1)*v(3)-u(2)*v(1)-u(3)*v(2))\n ATOT=ATOT+a\n if(iclose.eq.1) then\n call LQM1(f,u,v,r,e)\n nevals=nevals+47\n else\n call LQM0(f,u,v,r,e)\n nevals=nevals+28\n end if\n result=result+r\n error=error+e\n node(1)=e\n node(2)=r\n node(3)=x(1,i)\n node(4)=y(1,i)\n node(5)=x(2,i)\n node(6)=y(2,i)\n node(7)=x(3,i)\n node(8)=y(3,i)\n node(9)=a\n call HPINS(maxtri,9,data,nd,iwork(maxtri+1),node,GREATR)\n 20 continue\n end if\nc\nc Check that input tolerance is consistent with\nc machine epsilon.\nc\n if(iflag.eq.0) then\n if(tol.le.5.0*EMACH) then\n tol=5.0*EMACH\n fadd=3\n else\n fadd=0\n end if\n epsabs=tol*abs(result)\n else if(iflag.eq.1) then\n if(tol.le.5.0*EMACH*abs(result)) then\n epsabs=5.0*EMACH*abs(result)\n else\n fadd=0\n epsabs=tol\n end if\n else\n iflag=9\n return\n end if\nc\nc Adjust the second heap on the basis of the current\nc value of epsabs.\nc\n 2 if(nd.eq.0) go to 40\n j=nd\n 3 if(j.eq.0) go to 40\n call HPACC(maxtri,9,data,nd,iwork(maxtri+1),node,j)\n if(node(1).gt.epsabs*node(9)/ATOT) then\n call HPINS(maxtri,9,data,nu,iwork,node,GREATR)\n call HPDEL(maxtri,9,data,nd,iwork(maxtri+1),GREATR,j)\n if(j.gt.nd) j=j-1\n else\n j=j-1\n endif\n go to 3\nc\nc Beginning of main loop from here to end\nc\n 40 if(nevals.ge.mevals) then\n iflag=4\n return\n end if\n if(error.le.epsabs) then\n if(iflag.eq.0) then\n if(error.le.abs(result)*tol) then\n iflag=fadd\n return\n else\n epsabs=abs(result)*tol\n go to 2\n end if\n else\n if(error.le.tol) then\n iflag=0\n return\n else if(error.le.5.0*EMACH*abs(result)) then\n iflag=3\n return\n else\n epsabs=5.0*EMACH*abs(result)\n go to 2\n end if\n end if\n end if\nc\nc If there are too many triangles and second heap\nc is not empty remove bottom triangle from second\nc heap. If second heap is empty return with iflag\nc set to 1 or 4.\nc\n if((nu+nd).ge.maxtri) then\n full=.true.\n if(nd.gt.0) then\n iwork(nu+1)=iwork(maxtri+nd)\n nd=nd-1\n else\n iflag=1\n return\n end if\n else\n full=.false.\n end if\nc\nc Find triangle with largest error, divide it in\nc two, and apply LQM to each half.\nc\n if(nd.eq.0) then\n call HPACC(maxtri,9,data,nu,iwork,node,1)\n call HPDEL(maxtri,9,data,nu,iwork,GREATR,1)\n else if(nu.eq.0) then\n call HPACC(maxtri,9,data,nd,iwork(maxtri+1),node,1)\n call HPDEL(maxtri,9,data,nd,iwork(maxtri+1),GREATR,1)\n else if(data(iwork(1)).ge.data(iwork(maxtri+1))) then\n if(full) iwork(maxtri+nd+2)=iwork(nu)\n call HPACC(maxtri,9,data,nu,iwork,node,1)\n call HPDEL(maxtri,9,data,nu,iwork,GREATR,1)\n else\n if(full) iwork(nu+2)=iwork(maxtri+nd)\n call HPACC(maxtri,9,data,nd,iwork(maxtri+1),node,1)\n call HPDEL(maxtri,9,data,nd,iwork(maxtri+1),GREATR,1)\n end if\n dat05 = 0.5\n call tridv(node,node1,node2,dat05,1)\n do 60 j=1,3\n u(j)=node1(2*j+1)\n v(j)=node1(2*j+2)\n 60 continue\n if(iclose.eq.1) then\n call LQM1(f,u,v,node1(2),node1(1))\n nevals=nevals+47\n else\n call LQM0(f,u,v,node1(2),node1(1))\n nevals=nevals+28\n end if\n do 70 j=1,3\n u(j)=node2(2*j+1)\n v(j)=node2(2*j+2)\n 70 continue\n if(iclose.eq.1) then\n call LQM1(f,u,v,node2(2),node2(1))\n nevals=nevals+47\n else\n call LQM0(f,u,v,node2(2),node2(1))\n nevals=nevals+28\n end if\n newerr=node1(1)+node2(1)\n newres=node1(2)+node2(2)\n if(newerr.gt.0.99*node(1)) then\n if(abs(node(2)-newres).le.1.E-04*abs(newres)) rndcnt=rndcnt+1\n end if\n result=result-node(2)+newres\n error=error-node(1)+newerr\n if(node1(1).gt.node1(9)*epsabs/ATOT) then\n call HPINS(maxtri,9,data,nu,iwork,node1,GREATR)\n else\n call HPINS(maxtri,9,data,nd,iwork(maxtri+1),node1,GREATR)\n end if\n if(node2(1).gt.node2(9)*epsabs/ATOT) then\n call HPINS(maxtri,9,data,nu,iwork,node2,GREATR)\n else\n call HPINS(maxtri,9,data,nd,iwork(maxtri+1),node2,GREATR)\n end if\n if(rndcnt.ge.20) then\n iflag=2\n return\n end if\n if(iflag.eq.0) then\n if(epsabs.lt.0.5*tol*abs(result)) then\n epsabs=tol*abs(result)\n j=nu\n 5 if(j.eq.0) go to 40\n call HPACC(maxtri,9,data,nu,iwork,node,j)\n if(node(1).le.epsabs*node(9)/ATOT) then\n call HPINS(maxtri,9,data,nd,iwork(maxtri+1),node,GREATR)\n call HPDEL(maxtri,9,data,nu,iwork,GREATR,j)\n if(j.gt.nu) j=j-1\n else\n j=j-1\n end if\n go to 5\n end if\n end if\n go to 40\n end\n\n\n LOGICAL FUNCTION GREATR(A,B,NWDS)\n INTEGER NWDS\n real*8 A(NWDS), B(NWDS)\n GREATR= A(1) .GT. B(1)\n RETURN\n END\n\n\n SUBROUTINE HINITD(NMAX,NWDS,N,T)\nC PURPOSE\nC THIS ROUTINE INITIALIZES THE HEAP PROGRAMS WITH T(NMAX)\nC POINTING TO THE TOP OF THE HEAP.\nC IT IS CALLED ONCE AT THE START OF EACH NEW CALCULATION.\nC INPUT\nC NMAX=MAXIMUM NUMBER OF NODES ALLOWED BY USER\nC NWDS=NUMBER OF WORDS PER NODE\nC OUTPUT\nC N=CURRENT NUMBER OF NODES IN HEAP = 0.\nC T=INTEGER ARRAY OF POINTERS TO POTENTIAL HEAP NODES.\nC\n INTEGER T(1)\n DO 1 I=1,NMAX\n 1 T(I)=(NMAX-I)*NWDS+1\n N=0\n RETURN\n END\n\n\n SUBROUTINE HINITU(NMAX,NWDS,N,T)\nC H E A P PACKAGE\nC A COLLECTION OF PROGRAMS WHICH MAINTAIN A HEAP DATA\nC STRUCTURE. BY CALLING THESE SUBROUTINES IT IS POSSIBLE TO\nC INSERT, DELETE, AND ACCESS AN EXISTING HEAP OR TO BUILD A\nC NEW HEAP FROM AN UNORDERED COLLECTION OF NODES. THE HEAP\nC FUNCTION IS AN ARGUMENT TO THE SUBROUTINES ALLOWING VERY\nC GENERAL ORGANIZATIONS.\nC THE USER MUST DECIDE ON THE MAXIMUM NUMBER OF NODES\nC ALLOWED AND DIMENSION THE real*8 ARRAY DATA AND THE INTEGER\nC ARRAY T USED INTERNALLY BY THE PACKAGE. THESE VARIABLES ARE\nC THEN PASSED THROUGH THE CALL SEQUENCE BETWEEN THE HEAP\nC PROGRAMS BUT ARE NOT IN GENERAL ACCESSED BY THE USER. HE\nC MUST ALSO PROVIDE A HEAP FUNCTION WHOSE NAME MUST BE INCLUD-\nC ED IN AN EXTERNAL STATEMENT IN THE USER PROGRAM WHICH CALLS\nC THE HEAP SUBROUTINES. TWO SIMPLE HEAP FUNCTIONS ARE\nC PROVIDED WITH THE PACKAGE.\nC\nC\nC PURPOSE\nC THIS ROUTINE INITIALIZES THE HEAP PROGRAMS WITH T(1)\nC POINTING TO THE TOP OF THE HEAP.\nC IT IS CALLED ONCE AT THE START OF EACH NEW CALCULATION\nC INPUT\nC NMAX = MAXIMUM NUMBER OF NODES ALLOWED BY USER.\nC NWDS = NUMBER OF WORDS PER NODE\nC OUTPUT\nC N = CURRENT NUMBER OF NODES IN HEAP = 0.\nC T = INTEGER ARRAY OF POINTERS TO POTENTIAL HEAP NODES.\nC\n INTEGER T(1)\n DO 1 I = 1, NMAX\n 1 T(I)=(I-1)*NWDS+1\n N = 0\n RETURN\n END\n\n\n SUBROUTINE HPACC(NMAX,NWDS,DATA,N,T,XNODE,K)\nC\nC PURPOSE\nC TO ACCESS THE K-TH NODE OF THE HEAP,\nC 1 .LE. K .LE. N .LE. NMAX\nC INPUT\nC NMAX = MAXIMUM NUMBER OF NODES ALLOWED BY USER.\nC DATA = WORK AREA FOR STORING NODES.\nC N = CURRENT NUMBER OF NODES IN THE HEAP.\nC T = INTEGER ARRAY OF POINTERS TO HEAP NODES.\nC XNODE = A real*8 ARRAY, NWDS WORDS LONG, IN WHICH NODAL IN-\nC FORMATION WILL BE INSERTED.\nC K = THE INDEX OF THE NODE TO BE FOUND AND INSERTED INTO\nC XNODE.\nC\nC OUTPUT\nC XNODE = A real*8 ARRAY. CONTAINS IN XNODE(1),...,XNODE(NWDS)\nC THE ELEMENTS OF THE K-TH NODE.\nC\n real*8 DATA(1), XNODE(1)\n INTEGER T(1)\n IF (K .LT. 1 .OR. K .GT. N .OR. N .GT. NMAX) RETURN\n J=T(K)-1\n DO 1 I=1,NWDS\n IPJ=I+J\n 1 XNODE(I)=DATA(IPJ)\n RETURN\n END\n\n\n SUBROUTINE HPBLD(NMAX,NWDS,DATA,N,T,HPFUN)\nC\nC PURPOSE\nC BUILDS A HEAP, IN T , FROM AN ARRAY OF N ELEMENTS\nC IN DATA, WHICH ARE SPACED NWDS APART.\nC AT CONCLUSION OF CALCULATION THE TOP SATISFIES\nC HPFUN(TOP,SON) = .TRUE. FOR ANY SON.\nC USES SUBROUTINE HPGRO BY FEEDING IT ONE ELEMENT OF\nC THE ARRAY AT A TIME.\nC\nC INPUT\nC NMAX = MAXIMUN NUMBER OF NODES ALLOWED BY USER.\nC NWDS = NUMBER OF WORDS PER NODE.\nC DATA = WORK AREA IN WHICH THE NODES ARE STORED.\nC N = CURRENT NUMBER OF NODES.\nC T = INTEGER ARRAY OF POINTERS TO HEAP NODES.\nC HPFUN = NAME OF USER WRITTEN FUNCTION TO DETERMINE TOP NODE.\nC OUTPUT\nC DATA = WORK AREA IN WHICH THE NODES ARE STORED.\nC T = INTEGER ARRAY OF POINTERS TO HEAP NODES.\nC IN PARTICULAR T(1) POINTS TO THE TOP.\nC\n EXTERNAL HPFUN\n LOGICAL HPFUN\n real*8 DATA(1)\n INTEGER T(1)\n IF(NMAX .LT. N) RETURN\n INDEX = N/2\n 1 CONTINUE\n IF( INDEX .EQ. 0) RETURN\n CALL HPGRO(NMAX,NWDS,DATA,N,T,HPFUN,INDEX)\n INDEX = INDEX-1\n GO TO 1\n END\n\n\n SUBROUTINE HPDEL(NMAX,NWDS,DATA,N,T,HPFUN,K)\nC\nC PURPOSE\nC DELETE K-TH ELEMENT OF HEAP. RESULTING TREE IS REHEAPED.\nC INPUT\nC NMAX = MAXIMUN NUMBER OF NODES ALLOWED BY USER.\nC NWDS = NUMBER OF WORDS PER NODE.\nC DATA = WORK AREA IN WHICH THE NODES ARE STORED.\nC N = CURRENT NUMBER OF NODES.\nC T = INTEGER ARRAY OF POINTERS TO NODES.\nC HPFUN = NAME OF USER WRITTEN FUNCTION TO DETERMINE TOP NODE.\nC K = INDEX OF NODE TO BE DELETED\nC OUTPUT\nC N = UPDATED NUMBER OF NODES.\nC T = UPDATED INTEGER POINTER ARRAY TO NODES.\nC\n EXTERNAL HPFUN\n LOGICAL HPFUN\n real*8 DATA(1)\n INTEGER T(1)\n IF(N .EQ. 0) RETURN\n IF(K.EQ.N) THEN\n N=N-1\n RETURN\n END IF\n KDEL=K\n JUNK=T(KDEL)\n T(KDEL)=T(N)\n T(N)=JUNK\n N=N-1\n 10 IF(KDEL.EQ.1) THEN\n CALL HPGRO(NMAX,NWDS,DATA,N,T,HPFUN,KDEL)\n RETURN\n ELSE\n KHALVE=KDEL/2\n IL=T(KHALVE)\n IR=T(KDEL)\n IF(HPFUN(DATA(IL),DATA(IR),NWDS)) THEN\n CALL HPGRO(NMAX,NWDS,DATA,N,T,HPFUN,KDEL)\n RETURN\n ELSE\n T(KHALVE)=IR\n T(KDEL)=IL\n KDEL=KHALVE\n END IF\n END IF\n GO TO 10\n END\n\n\n SUBROUTINE HPGRO(NMAX,NWDS,DATA,N,T,HPFUN,I)\nC\nC PURPOSE\nC FORMS A HEAP OUT OF A TREE. USED PRIVATELY BY HPBLD.\nC THE TOP OF THE TREE IS STORED IN LOCATION T(I).\nC FIRST SON IS IN LOCATION T(2I), NEXT SON\nC IS IN LOCATION T(2I+1).\nC THIS PROGRAM ASSUMES EACH BRANCH OF THE TREE IS A HEAP.\nC\n INTEGER T(1)\n real*8 DATA(1)\n LOGICAL HPFUN\n IF(N .GT. NMAX) RETURN\nC\n K=I\n 1 J=2*K\nC\nC TEST IF ELEMENT IN J TH POSITION IS A LEAF.\nC\n IF( J .GT. N ) RETURN\nC\nC IF THERE IS MORE THAN ONE SON, FIND WHICH SON IS SMALLEST.\nC\n IF( J .EQ. N ) GO TO 2\n IR=T(J)\n IL=T(J+1)\n IF(HPFUN(DATA(IL),DATA(IR),NWDS)) J=J+1\nC\nC IF A SON IS LARGER THAN FATHER, INTERCHANGE\nC THIS DESTROYS HEAP PROPERTY, SO MUST RE-HEAP REMAINING\nC ELEMENTS\nC\n 2 CONTINUE\n IL=T(K)\n IR=T(J)\n IF(HPFUN(DATA(IL),DATA(IR),NWDS)) RETURN\n ITEMP=T(J)\n T(J)=T(K)\n T(K)=ITEMP\n K=J\n GO TO 1\n END\n\n\n SUBROUTINE HPINS(NMAX,NWDS,DATA,N,T,XNODE,HPFUN)\nC\nC PURPOSE\nC THIS ROUTINE INSERTS A NODE INTO AN ALREADY EXISTING HEAP.\nC THE RESULTING TREE IS RE-HEAPED.\nC\nC INPUT\nC NMAX = MAXIMUM NUMBER OF NODES ALLOWED BY USER.\nC NWDS = NUMBER OF WORDS PER NODE.\nC DATA = WORK AREA FOR STORING NODES.\nC N = CURRENT NUMBER OF NODES IN THE TREE.\nC T = INTEGER ARRAY OF POINTERS TO HEAP NODES.\nC XNODE = A real*8 ARRAY, NWDS WORDS LONG, WHICH\nC CONTAINS THE NODAL INFORMATION TO BE INSERTED.\nC HPFUN = NAME OF USER WRITTEN FUNCTION TO DETERMINE\nC THE TOP NODE.\nC OUTPUT\nC DATA = WORK AREA WITH NEW NODE INSERTED.\nC N = UPDATED NUMBER OF NODES.\nC T = UPDATED INTEGER POINTER ARRAY.\nC\n real*8 XNODE(1),DATA(1)\n INTEGER T(1)\n LOGICAL HPFUN\n IF(N .EQ. NMAX) RETURN\n N=N+1\n J= T(N)-1\n DO 1 I= 1,NWDS\n IPJ=I+J\n 1 DATA(IPJ) = XNODE(I)\n J=N\n 2 CONTINUE\n IF(J .EQ. 1) RETURN\n JR=T(J)\n J2=J/2\n JL=T(J2)\n IF(HPFUN(DATA(JL),DATA(JR),NWDS)) RETURN\n T(J2)=T(J)\n T(J)=JL\n J=J2\n GO TO 2\n END\n\n\n LOGICAL FUNCTION LESS(A,B,NWDS)\n INTEGER NWDS\n real*8 A(NWDS), B(NWDS)\n LESS= A(1) .LT. B(1)\n RETURN\n END\n\n\n SUBROUTINE LQM0(F,U,V,RES8,EST)\nC\nC\nC\nC PURPOSE\nC TO COMPUTE - IF = INTEGRAL OF F OVER THE TRIANGLE\nC WITH VERTICES (U(1),V(1)),(U(2),V(2)),(U(3),V(3)), AND\nC ESTIMATE THE ERROR,\nC - INTEGRAL OF ABS(F) OVER THIS TRIANGLE\nC\nC CALLING SEQUENCE\nC CALL LQM0(F,U,V,RES11,EST)\nC PARAMETERS\nC F - FUNCTION SUBPROGRAM DEFINING THE INTEGRAND\nC F(X,Y); THE ACTUAL NAME FOR F NEEDS TO BE\nC DECLARED E X T E R N A L IN THE CALLING\nC PROGRAM\nC U(1),U(2),U(3)- ABSCISSAE OF VERTICES\nC V(1),V(2),V(3)- ORDINATES OF VERTICES\nC RES6 - APPROXIMATION TO THE INTEGRAL IF, OBTAINED BY THE\nC LYNESS AND JESPERSEN RULE OF DEGREE 6, USING\nC 12 POINTS\nC RES8 - APPROXIMATION TO THE INTEGRAL IF, OBTAINED BY THE\nC LYNESS AND JESPERSEN RULE OF DEGREE 8,\nC USING 16 POINTS\nC EST - ESTIMATE OF THE ABSOLUTE ERROR\nC DRESC - APPROXIMATION TO THE INTEGRAL OF ABS(F- IF/DJ),\nC OBTAINED BY THE RULE OF DEGREE 6, AND USED FOR\nC THE COMPUTATION OF EST\nC\nC REMARKS\nC DATE OF LAST UPDATE : 10 APRIL 1984 O.W. RECHARD NBS\nC\nC SUBROUTINES OR FUNCTIONS CALLED :\nC - F (USER-SUPPLIED INTEGRAND FUNCTION)\nC - R1MACH FOR MACHINE DEPENDENT INFORMATION\nC\nC .....................................................................\nC\n real*8 DJ,DF0,DRESC,EMACH,EST,F,FV,F0,\n * RES6,RES8,U1,U2,U3,UFLOW,V1,V2,V3,W,W60,W80,X,Y\n * ,ZETA1,ZETA2,Z1,Z2,Z3,RESAB6\n real*8 AMAX1,AMIN1,R1MACH,SQRT\n real*8 U(3),V(3)\n INTEGER J,KOUNT,L\nC\n DIMENSION FV(19),W(9),X(3),Y(3),ZETA1(9),ZETA2(9)\nC\nC\nC FIRST HOMOGENEOUS COORDINATES OF POINTS IN DEGREE-6\nC AND DEGREE-8 FORMULA, TAKEN WITH MULTIPLICITY 3\n DATA ZETA1(1),ZETA1(2),ZETA1(3),ZETA1(4),ZETA1(5),ZETA1(6),ZETA1(7\n * ),ZETA1(8),ZETA1(9)/0.5014265096581342E+00,\n * 0.8738219710169965E+00,0.6365024991213939E+00,\n * 0.5314504984483216E-01,0.8141482341455413E-01,\n * 0.8989055433659379E+00,0.6588613844964797E+00,\n * 0.8394777409957211E-02,0.7284923929554041E+00/\nC SECOND HOMOGENEOUS COORDINATES OF POINTS IN DEGREE-6\nC AND DEGREE-8 FORMULA, TAKEN WITH MUNLTIPLICITY 3\n DATA ZETA2(1),ZETA2(2),ZETA2(3),ZETA2(4),ZETA2(5),ZETA2(6),ZETA2(7\n * ),ZETA2(8),ZETA2(9)/0.2492867451709329E+00,\n * 0.6308901449150177E-01,0.5314504984483216E-01,\n * 0.6365024991213939E+00,0.4592925882927229E+00,\n * 0.5054722831703103E-01,0.1705693077517601E+00,\n * 0.7284923929554041E+00,0.8394777409957211E-02/\nC WEIGHTS OF MID-POINT OF TRIANGLE IN DEGREE-6\nC RESP. DEGREE-8 FORMULAE\n DATA W60/0.0E+00/\n DATA W80/0.1443156076777862E+00/\nC WEIGHTS IN DEGREE-6 AND DEGREE-8 RULE\n DATA W(1),W(2),W(3),W(4),W(5),W(6),W(7),W(8),W(9)/\n * 0.1167862757263407E+00,0.5084490637020547E-01,\n * 0.8285107561839291E-01,0.8285107561839291E-01,\n * 0.9509163426728497E-01,0.3245849762319813E-01,\n * 0.1032173705347184E+00,0.2723031417443487E-01,\n * 0.2723031417443487E-01/\nC\nC LIST OF MAJOR VARIABLES\nC ----------------------\nC DJ - AREA OF THE TRIANGLE\nC DRESC - APPROXIMATION TO INTEGRAL OF\nC ABS(F- IF/DJ) OVER THE TRIANGLE\nC RESAB6 - APPROXIMATION TO INTEGRAL OF\nC ABS(F) OVER THE TRIANGLE\nC X - CARTESIAN ABSCISSAE OF THE INTEGRATION\nC POINTS\nC Y - CARTESIAN ORDINATES OF THE INTEGRATION\nC POINTS\nC FV - FUNCTION VALUES\nC\nC COMPUTE DEGREE-6 AND DEGREE-8 RESULTS FOR IF/DJ AND\nC DEGREE-6 APPROXIMATION FOR ABS(F)\nC\n EMACH = R1MACH(4)\n UFLOW = R1MACH(1)\n U1=U(1)\n U2=U(2)\n U3=U(3)\n V1=V(1)\n V2=V(2)\n V3=V(3)\n DJ = ABS(U1*V2-U2*V1-U1*V3+V1*U3+U2*V3-V2*U3)*0.5E+00\n F0 = F((U1+U2+U3)/3.0E+00,(V1+V2+V3)/3.0E+00)\n RES6 = F0*W60\n RESAB6 = ABS(F0)*W60\n FV(1) = F0\n KOUNT = 1\n RES8 = F0*W80\n DO 50 J=1,9\n Z1 = ZETA1(J)\n Z2 = ZETA2(J)\n Z3 = 1.0E+00-Z1-Z2\n X(1) = Z1*U1+Z2*U2+Z3*U3\n Y(1) = Z1*V1+Z2*V2+Z3*V3\n X(2) = Z2*U1+Z3*U2+Z1*U3\n Y(2) = Z2*V1+Z3*V2+Z1*V3\n X(3) = Z3*U1+Z1*U2+Z2*U3\n Y(3) = Z3*V1+Z1*V2+Z2*V3\n IF(J.LE.4) THEN\n F0 = 0.0E+00\n DF0 = 0.0E+00\n DO 10 L=1,3\n KOUNT = KOUNT+1\n FV(KOUNT) = F(X(L),Y(L))\n F0 = F0+FV(KOUNT)\n DF0 = DF0+ABS(FV(KOUNT))\n 10 CONTINUE\n RES6 = RES6+F0*W(J)\n RESAB6 = RESAB6+DF0*W(J)\n ELSE\n F0 = F(X(1),Y(1))+F(X(2),Y(2))+F(X(3),Y(3))\n RES8 = RES8+F0*W(J)\n ENDIF\n 50 CONTINUE\nC\nC COMPUTE DEGREE-6 APPROXIMATION FOR THE INTEGRAL OF\nC ABS(F-IF/DJ)\nC\n DRESC = ABS(FV(1)-RES6)*W60\n KOUNT = 2\n DO 60 J=1,4\n DRESC = DRESC+(ABS(FV(KOUNT)-RES6)+ABS(FV(KOUNT+1)-RES6)+ABS(\n * FV(KOUNT+2)-RES6))*W(J)\n KOUNT = KOUNT+3\n 60 CONTINUE\nC\nC COMPUTE DEGREE-6 AND DEGREE-8 APPROXIMATIONS FOR IF,\nC AND ERROR ESTIMATE\nC\n RES6 = RES6*DJ\n RES8 = RES8*DJ\n RESAB6 = RESAB6*DJ\n DRESC = DRESC*DJ\n EST = ABS(RES6-RES8)\n IF(DRESC.NE.0.0E+00) EST = AMAX1(EST,DRESC*AMIN1(1.0E+00,(20.0E+00\n * *EST/DRESC)**1.5E+00))\n IF(RESAB6.GT.UFLOW) EST = AMAX1(EMACH*RESAB6,EST)\n RETURN\n END\n\n\n SUBROUTINE LQM1(F,U,V,RES11,EST)\nC\nC\nC\nC PURPOSE\nC TO COMPUTE - IF = INTEGRAL OF F OVER THE TRIANGLE\nC WITH VERTICES (U(1),V(1)),(U(2),V(2)),(U(3),V(3)), AND\nC ESTIMATE THE ERROR,\nC - INTEGRAL OF ABS(F) OVER THIS TRIANGLE\nC\nC CALLING SEQUENCE\nC CALL LQM1(F,U,V,RES11,EST)\nC PARAMETERS\nC F - FUNCTION SUBPROGRAM DEFINING THE INTEGRAND\nC F(X,Y); THE ACTUAL NAME FOR F NEEDS TO BE\nC DECLARED E X T E R N A L IN THE CALLING\nC PROGRAM\nC U(1),U(2),U(3)- ABSCISSAE OF VERTICES\nC V(1),V(2),V(3)- ORDINATES OF VERTICES\nC RES9 - APPROXIMATION TO THE INTEGRAL IF, OBTAINED BY THE\nC LYNESS AND JESPERSEN RULE OF DEGREE 9, USING\nC 19 POINTS\nC RES11 - APPROXIMATION TO THE INTEGRAL IF, OBTAINED BY THE\nC LYNESS AND JESPERSEN RULE OF DEGREE 11,\nC USING 28 POINTS\nC EST - ESTIMATE OF THE ABSOLUTE ERROR\nC DRESC - APPROXIMATION TO THE INTEGRAL OF ABS(F- IF/DJ),\nC OBTAINED BY THE RULE OF DEGREE 9, AND USED FOR\nC THE COMPUTATION OF EST\nC\nC REMARKS\nC DATE OF LAST UPDATE : 18 JAN 1984 D. KAHANER NBS\nC\nC SUBROUTINES OR FUNCTIONS CALLED :\nC - F (USER-SUPPLIED INTEGRAND FUNCTION)\nC - R1MACH FOR MACHINE DEPENDENT INFORMATION\nC\nC .....................................................................\nC\n real*8 DJ,DF0,DRESC,EMACH,EST,F,FV,F0,\n * RES9,RES11,U1,U2,U3,UFLOW,V1,V2,V3,W,W90,W110,X,Y\n * ,ZETA1,ZETA2,Z1,Z2,Z3\n real*8 AMAX1,AMIN1,R1MACH,SQRT\n real*8 U(3),V(3)\n INTEGER J,KOUNT,L\nC\n DIMENSION FV(19),W(15),X(3),Y(3),ZETA1(15),ZETA2(15)\nC\nC\nC FIRST HOMOGENEOUS COORDINATES OF POINTS IN DEGREE-9\nC AND DEGREE-11 FORMULA, TAKEN WITH MULTIPLICITY 3\n DATA ZETA1(1),ZETA1(2),ZETA1(3),ZETA1(4),ZETA1(5),ZETA1(6),ZETA1(7\n * ),ZETA1(8),ZETA1(9),ZETA1(10),ZETA1(11),ZETA1(12),ZETA1(13),\n * ZETA1(14),ZETA1(15)/0.2063496160252593E-01,0.1258208170141290E+\n * 00,0.6235929287619356E+00,0.9105409732110941E+00,\n * 0.3683841205473626E-01,0.7411985987844980E+00,\n * 0.9480217181434233E+00,0.8114249947041546E+00,\n * 0.1072644996557060E-01,0.5853132347709715E+00,\n * 0.1221843885990187E+00,0.4484167758913055E-01,\n * 0.6779376548825902E+00,0.0E+00,0.8588702812826364E+00/\nC SECOND HOMOGENEOUS COORDINATES OF POINTS IN DEGREE-9\nC AND DEGREE-11 FORMULA, TAKEN WITH MUNLTIPLICITY 3\n DATA ZETA2(1),ZETA2(2),ZETA2(3),ZETA2(4),ZETA2(5),ZETA2(6),ZETA2(7\n * ),ZETA2(8),ZETA2(9),ZETA2(10),ZETA2(11),ZETA2(12),ZETA2(13),\n * ZETA2(14),ZETA2(15)/0.4896825191987370E+00,0.4370895914929355E+\n * 00,0.1882035356190322E+00,0.4472951339445297E-01,\n * 0.7411985987844980E+00,0.3683841205473626E-01,\n * 0.2598914092828833E-01,0.9428750264792270E-01,\n * 0.4946367750172147E+00,0.2073433826145142E+00,\n * 0.4389078057004907E+00,0.6779376548825902E+00,\n * 0.4484167758913055E-01,0.8588702812826364E+00,0.0E+00/\nC WEIGHTS OF MID-POINT OF TRIANGLE IN DEGREE-9\nC RESP. DEGREE-11 FORMULAE\n DATA W90/0.9713579628279610E-01/\n DATA W110/0.8797730116222190E-01/\nC WEIGHTS IN DEGREE-9 AND DEGREE-11 RULE\n DATA W(1),W(2),W(3),W(4),W(5),W(6),W(7),W(8),W(9),W(10),W(11),W(12\n * ),W(13),W(14),W(15)/0.3133470022713983E-01,0.7782754100477543E-\n * 01,0.7964773892720910E-01,0.2557767565869810E-01,\n * 0.4328353937728940E-01,0.4328353937728940E-01,\n * 0.8744311553736190E-02,0.3808157199393533E-01,\n * 0.1885544805613125E-01,0.7215969754474100E-01,\n * 0.6932913870553720E-01,0.4105631542928860E-01,\n * 0.4105631542928860E-01,0.7362383783300573E-02,\n * 0.7362383783300573E-02/\nC\nC LIST OF MAJOR VARIABLES\nC ----------------------\nC DJ - AREA OF THE TRIANGLE\nC DRESC - APPROXIMATION TO INTEGRAL OF\nC ABS(F- IF/DJ) OVER THE TRIANGLE\nC RESAB9 - APPROXIMATION TO INTEGRAL OF\nC ABS(F) OVER THE TRIANGLE\nC X - CARTESIAN ABSCISSAE OF THE INTEGRATION\nC POINTS\nC Y - CARTESIAN ORDINATES OF THE INTEGRATION\nC POINTS\nC FV - FUNCTION VALUES\nC\nC COMPUTE DEGREE-9 AND DEGREE-11 RESULTS FOR IF/DJ AND\nC DEGREE-9 APPROXIMATION FOR ABS(F)\nC\n EMACH = R1MACH(4)\n UFLOW = R1MACH(1)\n U1=U(1)\n U2=U(2)\n U3=U(3)\n V1=V(1)\n V2=V(2)\n V3=V(3)\n DJ = ABS(U1*V2-U2*V1-U1*V3+V1*U3+U2*V3-V2*U3)*0.5E+00\n F0 = F((U1+U2+U3)/3.0E+00,(V1+V2+V3)/3.0E+00)\n RES9 = F0*W90\n RESAB9 = ABS(F0)*W90\n FV(1) = F0\n KOUNT = 1\n RES11 = F0*W110\n DO 50 J=1,15\n Z1 = ZETA1(J)\n Z2 = ZETA2(J)\n Z3 = 1.0E+00-Z1-Z2\n X(1) = Z1*U1+Z2*U2+Z3*U3\n Y(1) = Z1*V1+Z2*V2+Z3*V3\n X(2) = Z2*U1+Z3*U2+Z1*U3\n Y(2) = Z2*V1+Z3*V2+Z1*V3\n X(3) = Z3*U1+Z1*U2+Z2*U3\n Y(3) = Z3*V1+Z1*V2+Z2*V3\n IF(J.LE.6) THEN\n F0 = 0.0E+00\n DF0 = 0.0E+00\n DO 10 L=1,3\n KOUNT = KOUNT+1\n FV(KOUNT) = F(X(L),Y(L))\n F0 = F0+FV(KOUNT)\n DF0 = DF0+ABS(FV(KOUNT))\n 10 CONTINUE\n RES9 = RES9+F0*W(J)\n RESAB9 = RESAB9+DF0*W(J)\n ELSE\n F0 = F(X(1),Y(1))+F(X(2),Y(2))+F(X(3),Y(3))\n RES11 = RES11+F0*W(J)\n ENDIF\n 50 CONTINUE\nC\nC COMPUTE DEGREE-9 APPROXIMATION FOR THE INTEGRAL OF\nC ABS(F-IF/DJ)\nC\n DRESC = ABS(FV(1)-RES9)*W90\n KOUNT = 2\n DO 60 J=1,6\n DRESC = DRESC+(ABS(FV(KOUNT)-RES9)+ABS(FV(KOUNT+1)-RES9)+ABS(\n * FV(KOUNT+2)-RES9))*W(J)\n KOUNT = KOUNT+3\n 60 CONTINUE\nC\nC COMPUTE DEGREE-9 AND DEGREE-11 APPROXIMATIONS FOR IF,\nC AND ERROR ESTIMATE\nC\n RES9 = RES9*DJ\n RES11 = RES11*DJ\n RESAB9 = RESAB9*DJ\n DRESC = DRESC*DJ\n EST = ABS(RES9-RES11)\n IF(DRESC.NE.0.0E+00) EST = AMAX1(EST,DRESC*AMIN1(1.0E+00,(20.0E+00\n * *EST/DRESC)**1.5E+00))\n IF(RESAB9.GT.UFLOW) EST = AMAX1(EMACH*RESAB9,EST)\n RETURN\n END\n\n\n subroutine tridv(node,node1,node2,coef,rank)\n real*8 node(*),node1(*),node2(*),coef\n integer rank\n real*8 s(3),coef1,temp\n integer t(3)\n coef1=1.0-coef\n s(1)=(node(3)-node(5))**2+(node(4)-node(6))**2\n s(2)=(node(5)-node(7))**2+(node(6)-node(8))**2\n s(3)=(node(3)-node(7))**2+(node(4)-node(8))**2\n t(1)=1\n t(2)=2\n t(3)=3\n do 10 i=1,2\n do 10 j=i+1,3\n if(s(i).lt.s(j)) then\n temp=t(i)\n t(i)=t(j)\n t(j)=temp\n end if\n10 continue\n if(t(rank).eq.1)then\n node1(3)=coef*node(3)+coef1*node(5)\n node1(4)=coef*node(4)+coef1*node(6)\n node1(5)=node(5)\n node1(6)=node(6)\n node1(7)=node(7)\n node1(8)=node(8)\n node2(3)=node1(3)\n node2(4)=node1(4)\n node2(5)=node(7)\n node2(6)=node(8)\n node2(7)=node(3)\n node2(8)=node(4)\n else if(t(rank).eq.2) then\n node1(3)=coef*node(5)+coef1*node(7)\n node1(4)=coef*node(6)+coef1*node(8)\n node1(5)=node(7)\n node1(6)=node(8)\n node1(7)=node(3)\n node1(8)=node(4)\n node2(3)=node1(3)\n node2(4)=node1(4)\n node2(5)=node(3)\n node2(6)=node(4)\n node2(7)=node(5)\n node2(8)=node(6)\n else\n node1(3)=coef*node(3)+coef1*node(7)\n node1(4)=coef*node(4)+coef1*node(8)\n node1(5)=node(3)\n node1(6)=node(4)\n node1(7)=node(5)\n node1(8)=node(6)\n node2(3)=node1(3)\n node2(4)=node1(4)\n node2(5)=node(5)\n node2(6)=node(6)\n node2(7)=node(7)\n node2(8)=node(8)\n end if\n node1(9)=coef*node(9)\n node2(9)=coef1*node(9)\n end\n\n\n!DECK R1MACH\r\n REAL*8 FUNCTION R1MACH (I)\r\n IMPLICIT NONE\r\n INTEGER :: I\r\n REAL*8 :: B, X\r\n!***BEGIN PROLOGUE R1MACH\r\n!***PURPOSE Return floating point machine dependent constants.\r\n!***LIBRARY SLATEC\r\n!***CATEGORY R1\r\n!***TYPE SINGLE PRECISION (R1MACH-S, D1MACH-D)\r\n!***KEYWORDS MACHINE CONSTANTS\r\n!***AUTHOR Fox, P. A., (Bell Labs)\r\n! Hall, A. D., (Bell Labs)\r\n! Schryer, N. L., (Bell Labs)\r\n!***DESCRIPTION\r\n!\r\n! R1MACH can be used to obtain machine-dependent parameters for the\r\n! local machine environment. It is a function subprogram with one\r\n! (input) argument, and can be referenced as follows:\r\n!\r\n! A = R1MACH(I)\r\n!\r\n! where I=1,...,5. The (output) value of A above is determined by\r\n! the (input) value of I. The results for various values of I are\r\n! discussed below.\r\n!\r\n! R1MACH(1) = B**(EMIN-1), the smallest positive magnitude.\r\n! R1MACH(2) = B**EMAX*(1 - B**(-T)), the largest magnitude.\r\n! R1MACH(3) = B**(-T), the smallest relative spacing.\r\n! R1MACH(4) = B**(1-T), the largest relative spacing.\r\n! R1MACH(5) = LOG10(B)\r\n!\r\n! Assume single precision numbers are represented in the T-digit,\r\n! base-B form\r\n!\r\n! sign (B**E)*( (X(1)/B) + ... + (X(T)/B**T) )\r\n!\r\n! where 0 .LE. X(I) .LT. B for I=1,...,T, 0 .LT. X(1), and\r\n! EMIN .LE. E .LE. EMAX.\r\n!\r\n! The values of B, T, EMIN and EMAX are provided in I1MACH as\r\n! follows:\r\n! I1MACH(10) = B, the base.\r\n! I1MACH(11) = T, the number of base-B digits.\r\n! I1MACH(12) = EMIN, the smallest exponent E.\r\n! I1MACH(13) = EMAX, the largest exponent E.\r\n!\r\n!\r\n!***REFERENCES P. A. Fox, A. D. Hall and N. L. Schryer, Framework for\r\n! a portable library, ACM Transactions on Mathematical\r\n! Software 4, 2 (June 1978), pp. 177-188.\r\n!***ROUTINES CALLED XERMSG\r\n!***REVISION HISTORY (YYMMDD)\r\n! 790101 DATE WRITTEN\r\n! 960329 Modified for Fortran 90 (BE after suggestions by EG) \r\n!***END PROLOGUE R1MACH\r\n! \r\n X = 1.0\r\n B = RADIX(X)\r\n SELECT CASE (I)\r\n CASE (1)\r\n R1MACH = B**(MINEXPONENT(X)-1) ! the smallest positive magnitude.\r\n CASE (2)\r\n R1MACH = HUGE(X) ! the largest magnitude.\r\n CASE (3)\r\n R1MACH = B**(-DIGITS(X)) ! the smallest relative spacing.\r\n CASE (4)\r\n R1MACH = B**(1-DIGITS(X)) ! the largest relative spacing.\r\n CASE (5)\r\n R1MACH = LOG10(B)\r\n CASE DEFAULT\r\n WRITE (*, FMT = 9000)\r\n 9000 FORMAT ('1ERROR 1 IN R1MACH - I OUT OF BOUNDS')\r\n STOP\r\n END SELECT\r\n RETURN\r\n END\n", "meta": {"hexsha": "e6cbff59f2af8179a49ee2f1d1d7986ba3cbe9c5", "size": 40003, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "f2f-0.96/dtwodq.f", "max_stars_repo_name": "b1tank/DSM-f90", "max_stars_repo_head_hexsha": "5cab8c8e89d316828f41fc27fc9d603f6973f1bc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "f2f-0.96/dtwodq.f", "max_issues_repo_name": "b1tank/DSM-f90", "max_issues_repo_head_hexsha": "5cab8c8e89d316828f41fc27fc9d603f6973f1bc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "f2f-0.96/dtwodq.f", "max_forks_repo_name": "b1tank/DSM-f90", "max_forks_repo_head_hexsha": "5cab8c8e89d316828f41fc27fc9d603f6973f1bc", "max_forks_repo_licenses": ["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.0330305533, "max_line_length": 76, "alphanum_fraction": 0.5833562483, "num_tokens": 14005, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894745194281, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6649789169958866}} {"text": "! =============================================================================\n! Test ellipse multi merge\n!\n! This unit test checks the merging of three ellipses. The biggest\n! ellipse is located at the origin. The smaller ellipses are located\n! tangentially at 45 and 225 degrees. The final ellipse is an ellipse\n! located at the origin.\n! =============================================================================\nprogram test_ellipse_multi_merge_2\n use unit_test\n use constants, only : pi, one, two, four, five, ten\n use parcel_container\n use parcel_merge, only : merge_ellipses, merge_timer\n use options, only : parcel\n use parameters, only : update_parameters, nx, nz, lower, extent\n use parcel_ellipse\n use parcel_nearest\n use timer\n implicit none\n\n double precision :: a1b1, a2b2, error\n\n nx = 1\n nz = 1\n lower = (/-pi / two, -pi /two/)\n extent = (/pi, pi/)\n\n call register_timer('parcel merge', merge_timer)\n call register_timer('merge nearest', merge_nearest_timer)\n call register_timer('merge tree resolve', merge_tree_resolve_timer)\n\n parcel%lambda_max = five\n parcel%min_vratio = ten\n\n call update_parameters\n\n call parcel_alloc(3)\n\n a1b1 = 1.44d0\n a2b2 = 0.25d0\n\n call parcel_setup\n\n call merge_ellipses(parcels)\n\n ! check result\n call eval_max_error\n\n call print_result_dp('Test ellipse group-merge 2', error)\n\n call parcel_dealloc\n\n contains\n\n subroutine parcel_setup\n double precision :: d\n\n d = (dsqrt(a1b1) + dsqrt(a2b2)) * f12 * dsqrt(two)\n\n n_parcels = 3\n parcels%position(:, 1) = zero\n parcels%volume(1) = a1b1 * pi\n parcels%B(1, 1) = a1b1\n parcels%B(2, 1) = zero\n parcels%buoyancy(1) = 1.5d0\n#ifndef ENABLE_DRY_MODE\n parcels%humidity(1) = 1.3d0\n#endif\n ! small parcel left\n parcels%position(1, 2) = -d\n parcels%position(2, 2) = -d\n parcels%volume(2) = a2b2 * pi\n parcels%B(1, 2) = a2b2\n parcels%B(2, 2) = zero\n parcels%buoyancy(2) = 1.8d0\n#ifndef ENABLE_DRY_MODE\n parcels%humidity(2) = 1.2d0\n#endif\n ! small parcel right\n parcels%position(1, 3) = d\n parcels%position(2, 3) = d\n parcels%volume(3) = a2b2 * pi\n parcels%B(1, 3) = a2b2\n parcels%B(2, 3) = zero\n parcels%buoyancy(3) = 1.4d0\n#ifndef ENABLE_DRY_MODE\n parcels%humidity(3) = 1.1d0\n#endif\n end subroutine parcel_setup\n\n subroutine eval_max_error\n double precision :: ab, B11, B12, B22, vol, d, factor\n double precision :: hum, buoy\n\n ! reference solution\n d = (dsqrt(a1b1) + dsqrt(a2b2)) * f12 * dsqrt(two)\n ab = a1b1 + two * a2b2\n vol = ab * pi\n\n buoy = (1.5d0 * a1b1 + (1.8d0 + 1.4d0) * a2b2) / ab\n hum = (1.3d0 * a1b1 + (1.2d0 + 1.1d0) * a2b2) / ab\n\n B11 = a1b1 ** 2 / ab + two * a2b2 / ab * (four * d ** 2 + a2b2)\n B12 = two * a2b2 / ab * (four * d ** 2)\n B22 = B11\n\n factor = ab / dsqrt(B11 * B22 - B12 ** 2)\n B11 = B11 * factor\n B12 = B12 * factor\n B22 = B22 * factor\n\n error = zero\n error = max(error, abs(dble(n_parcels - 1)))\n error = max(error, abs(parcels%B(1, 1) - B11))\n error = max(error, abs(parcels%B(2, 1) - B12))\n error = max(error, abs(get_B22(parcels%B(1, 1), &\n parcels%B(2, 1), &\n parcels%volume(1)) - B22))\n error = max(error, sum(abs(parcels%position(:, 1))))\n error = max(error, abs(parcels%volume(1) - vol))\n error = max(error, abs(parcels%buoyancy(1) - buoy))\n#ifndef ENABLE_DRY_MODE\n error = max(error, abs(parcels%humidity(1) - hum))\n#endif\n end subroutine eval_max_error\nend program test_ellipse_multi_merge_2\n", "meta": {"hexsha": "28fff3abf6f0776e43c92fec0ab2ffe4f6db3f61", "size": 4122, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "unit-tests/2d/test_ellipse_merge_2.f90", "max_stars_repo_name": "matt-frey/epic", "max_stars_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2021-11-11T10:50:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T00:11:41.000Z", "max_issues_repo_path": "unit-tests/2d/test_ellipse_merge_2.f90", "max_issues_repo_name": "matt-frey/epic", "max_issues_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 47, "max_issues_repo_issues_event_min_datetime": "2021-11-12T17:09:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-24T16:50:58.000Z", "max_forks_repo_path": "unit-tests/2d/test_ellipse_merge_2.f90", "max_forks_repo_name": "matt-frey/epic", "max_forks_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.4566929134, "max_line_length": 79, "alphanum_fraction": 0.5278990781, "num_tokens": 1225, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894745194281, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.664978906816137}} {"text": " REAL FUNCTION SXPARG (L)\n INTEGER L\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nC>> 1998-10-29 SXPARG Krogh Moved external statement up for mangle.\nC>> 1994-10-20 SXPARG Krogh Changes to use M77CON\nC>> 1993-05-06 SXPARG WVS JPL Conversion from NSWC to Math 77\nc--S replaces \"?\": ?XPARG\nC -------------------------------------------------------------------\nC IF L = 0 THEN SXPARG(L) = THE LARGEST POSITIVE W FOR WHICH\nC EXP(W) CAN BE COMPUTED.\nC\nC IF L IS NONZERO THEN SXPARG(L) = THE LARGEST NEGATIVE W FOR\nC WHICH THE COMPUTED VALUE OF EXP(W) IS NONZERO.\nC\nC NOTE... ONLY AN APPROXIMATE VALUE FOR SXPARG(L) IS NEEDED.\nC -------------------------------------------------------------------\n EXTERNAL R1MACH\n REAL R1MACH\n REAL FAC, XMAX, XMIN\n SAVE XMAX, XMIN\n DATA XMAX /-1.0E0/\nC\n IF (XMAX .LT. 0.0) THEN\n FAC = 1.0E0 - R1MACH(3)\n XMAX = FAC * LOG(R1MACH(2))\n XMIN = FAC * LOG(R1MACH(1))\n END IF\nC\n IF (L .NE. 0) THEN\n SXPARG = XMIN\n ELSE\n SXPARG = XMAX\n END IF\n RETURN\n END\n", "meta": {"hexsha": "1b50353ecb5c95e7aa8f8a23b93d28ef244d8ec0", "size": 1249, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/sxparg.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/sxparg.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/sxparg.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": 32.8684210526, "max_line_length": 70, "alphanum_fraction": 0.5372297838, "num_tokens": 388, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894576856559, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6649789044855655}} {"text": "!----------------------------------------------------------------------------- best with 100 columns\n\nfunction matVecMul()\n use modSparse\n integer::matVecMul\n type(linEq)::p\n integer::iA(7),jA(7)\n double precision::A(7)\n double precision::y(4),x(4)\n \n matVecMul=0\n call p%initLinEq(4,7)\n iA=[1,2,2,3,3,4,4]\n jA=[1,2,1,3,4,4,2]\n A=[1d0,2d0,-1d0,5d0,-4d0,2d0,-1d0]\n x=[1d0,3d0/2d0,14d0/5d0,11d0/4d0]\n call p%setCOO(iA,jA,A,7)\n call p%mulVec(x,y)\n if(norm2(y-[1d0,2d0,3d0,4d0])>1d-9)then\n matVecMul=1\n end if\nend function\n", "meta": {"hexsha": "0b45ac1ca982c27ffd65b4d0800967743a5d415f", "size": 539, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/test/matVecMul.f90", "max_stars_repo_name": "mianzhi/fosolvers", "max_stars_repo_head_hexsha": "be4877a9cccd7bf6b97d4e01c58e10634684415d", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2015-08-05T14:10:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-26T10:50:06.000Z", "max_issues_repo_path": "src/test/matVecMul.f90", "max_issues_repo_name": "mianzhi/fosolvers", "max_issues_repo_head_hexsha": "be4877a9cccd7bf6b97d4e01c58e10634684415d", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2019-11-24T15:46:54.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-30T13:30:29.000Z", "max_forks_repo_path": "src/test/matVecMul.f90", "max_forks_repo_name": "mianzhi/fosolvers", "max_forks_repo_head_hexsha": "be4877a9cccd7bf6b97d4e01c58e10634684415d", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-08-23T03:10:35.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-01T05:17:19.000Z", "avg_line_length": 23.4347826087, "max_line_length": 100, "alphanum_fraction": 0.547309833, "num_tokens": 253, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969136, "lm_q2_score": 0.7431680086124812, "lm_q1q2_score": 0.6649789035657981}} {"text": "module mod_moms\n use mod_types\n implicit none\n private\n public momsad\n contains\n subroutine momsad(nx,ny,nz,dxi,dyi,dzi,dzci,dzfi,dzflzi,visc,u,v,w,s,dsdt)\n implicit none\n integer , intent(in) :: nx,ny,nz\n real(rp), intent(in) :: dxi,dyi,dzi,visc\n real(rp), intent(in), dimension(0:) :: dzci,dzfi,dzflzi\n real(rp), dimension(0:,0:,0:), intent(in) :: u,v,w,s\n real(rp), dimension(:,:,:), intent(out) :: dsdt\n integer :: im,ip,jm,jp,km,kp,i,j,k\n real(rp) :: usip,usim,vsjp,vsjm,wskp,wskm\n real(rp) :: dsdxp,dsdxm,dsdyp,dsdym,dsdzp,dsdzm\n !\n !$OMP PARALLEL DO DEFAULT(none) &\n !$OMP PRIVATE(i,j,k,im,jm,km,ip,jp,kp) &\n !$OMP PRIVATE(usip,usim,vsjp,vsjm,wskp,wskm) &\n !$OMP PRIVATE(dsdxp,dsdxm,dsdyp,dsdym,dsdzp,dsdzm) &\n !$OMP SHARED(nx,ny,nz,dxi,dyi,dzi,visc,u,v,w,s,dsdt,dzci,dzfi)\n do k=1,nz\n kp = k + 1\n km = k - 1\n do j=1,ny\n jp = j + 1\n jm = j - 1\n do i=1,nx\n ip = i + 1\n im = i - 1\n usim = 0.5*( s(im,j,k)+s(i,j,k) )*u(im,j,k)\n usip = 0.5*( s(ip,j,k)+s(i,j,k) )*u(i ,j,k)\n vsjm = 0.5*( s(i,jm,k)+s(i,j,k) )*v(i,jm,k)\n vsjp = 0.5*( s(i,jp,k)+s(i,j,k) )*v(i,j ,k)\n wskm = 0.5*( s(i,j,km)+s(i,j,k) )*w(i,j,km)\n wskp = 0.5*( s(i,j,kp)+s(i,j,k) )*w(i,j,k )\n dsdxp = (s(ip,j,k)-s(i ,j,k))*dxi\n dsdxm = (s(i ,j,k)-s(im,j,k))*dxi\n dsdyp = (s(i,jp,k)-s(i,j ,k))*dyi\n dsdym = (s(i,j ,k)-s(i,jm,k))*dyi\n dsdzp = (s(i,j,kp)-s(i,j,k ))*dzci(k)\n dsdzm = (s(i,j,k )-s(i,j,km))*dzci(km)\n !\n dsdt(i,j,k) = dxi*( -usip + usim ) + (dsdxp-dsdxm)*visc*dxi + &\n dyi*( -vsjp + vsjm ) + (dsdyp-dsdym)*visc*dyi + &\n dzfi(k)*( -wskp + wskm ) + (dsdzp-dsdzm)*visc*dzfi(k)\n enddo\n enddo\n enddo\n !$OMP END PARALLEL DO\n return\n end subroutine momsad\nend module mod_moms\n", "meta": {"hexsha": "867f84852bed6d4469e77c008ad5ec49d2baf159", "size": 1961, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/moms.f90", "max_stars_repo_name": "maxcuda/CaNS", "max_stars_repo_head_hexsha": "5895d69f4f5a99aabca751cbe6cc0c34c07a99c1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2019-11-20T15:15:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-26T08:02:23.000Z", "max_issues_repo_path": "src/moms.f90", "max_issues_repo_name": "M-Abbaszadeh/CaNS", "max_issues_repo_head_hexsha": "5a75c2b6165ba1d1d961d255901b3411ce830dd7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-05-08T10:28:13.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-16T17:41:05.000Z", "max_forks_repo_path": "src/moms.f90", "max_forks_repo_name": "M-Abbaszadeh/CaNS", "max_forks_repo_head_hexsha": "5a75c2b6165ba1d1d961d255901b3411ce830dd7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-08-30T02:49:58.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-29T09:13:13.000Z", "avg_line_length": 35.6545454545, "max_line_length": 77, "alphanum_fraction": 0.4931157573, "num_tokens": 843, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894689081711, "lm_q2_score": 0.743167997235783, "lm_q1q2_score": 0.6649788975561555}} {"text": "REAL (C_DOUBLE) FUNCTION dnrm2_noblas(n, x) BIND(C)\n USE ISO_C_BINDING\n IMPLICIT NONE\n\n INTEGER (C_LONG), VALUE :: n\n REAL (C_DOUBLE), DIMENSION(n) :: x\n\n dnrm2_noblas = SQRT(DOT_PRODUCT(x, x))\n\nEND FUNCTION\n\nREAL (C_DOUBLE) FUNCTION dnrm2_blas(n, x) BIND(C)\n USE ISO_C_BINDING\n IMPLICIT NONE\n\n INTEGER (C_LONG), VALUE :: n\n REAL (C_DOUBLE), DIMENSION(n) :: x\n DOUBLE PRECISION dnrm2\n\n dnrm2_blas = dnrm2(n, x, 1)\n\nEND FUNCTION\n", "meta": {"hexsha": "c7c0020292c0e2637da86f696fb2f899e0c357ee", "size": 461, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/level1/dnrm2.f90", "max_stars_repo_name": "PatrickSchiffmann/fortran-blas-benchmark", "max_stars_repo_head_hexsha": "a6f1224cb3d72f87ed861183822b7d23c933dd4d", "max_stars_repo_licenses": ["MIT"], "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/level1/dnrm2.f90", "max_issues_repo_name": "PatrickSchiffmann/fortran-blas-benchmark", "max_issues_repo_head_hexsha": "a6f1224cb3d72f87ed861183822b7d23c933dd4d", "max_issues_repo_licenses": ["MIT"], "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/level1/dnrm2.f90", "max_forks_repo_name": "PatrickSchiffmann/fortran-blas-benchmark", "max_forks_repo_head_hexsha": "a6f1224cb3d72f87ed861183822b7d23c933dd4d", "max_forks_repo_licenses": ["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.0434782609, "max_line_length": 51, "alphanum_fraction": 0.6616052061, "num_tokens": 153, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310355, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6649726696108076}} {"text": "C++--------------------------------------------------------------------\nC Program to smooth images with possibility of unsharp masking.\nC JLP \nC Version of 12-11-91 \nC--------------------------------------------------------------------\n\tPROGRAM SMOOTH1\n INTEGER GSIZE\n PARAMETER(GSIZE=31)\n\tREAL*4 GRID(GSIZE,GSIZE)\n\tINTEGER*4 PNTR_IN,PNTR_OUT,ISIZE\n\tINTEGER*4 MADRID(1)\n\tCHARACTER NAME*40,NAME_OUT*40,COMMENTS*80\n CHARACTER NSMOOTH*30,ANS*1,BUFFER*40\n\tLOGICAL UNSHARP\n\tCOMMON /VMR/MADRID\n \n10\tFORMAT(A)\n\tPRINT 5\n5\tFORMAT(' Program smooth1 to smooth 2-D images'\n 1\t,/,' Possibility of unsharp masking',/,' Version 12-11-91')\n \n CALL JLP_BEGIN\nC Inquires about the format of the files :\n\tCALL JLP_INQUIFMT\n \nC Read the input image :\n WRITE(6,*) 'Input file: '\n READ(5,10) NAME\n\tCALL JLP_VM_READIMAG(PNTR_IN,NX,NY,NAME,COMMENTS)\n \n\tPRINT 70\n70\tFORMAT(' MENU : ',/,\n 1\t' 1. INPUT OF THE VALUES FOR THE GRID',\n 1\t' AND STORAGE IN A FILE',/,\n 1\t' 2. GAUSSIAN GRID',/,\n 1\t' 3. \"TOP HAT\" ',/,\n 1\t' 4. GRID FROM A FILE ',/,\n 1\t' ENTER THE OPTION : ',$)\n\tREAD(5,*) IOPT\n \n\tPRINT *,' SIZE OF SMOOTHING GRID (ODD INTEGER IN RANGE 1-',GSIZE,') '\n\tREAD(5,*) NSM\n \nC-------------------------------------------------------------\nC IOPT=1 Input of the values and storage in a file :\n\tIF(IOPT.EQ.1)THEN\n WRITE(BUFFER,11) NSM\n11 FORMAT(' Width of spec. grid:',I4)\n\tIOP=4\n\tSUM=0.\n\tDO J=1,NSM\n\t PRINT 101,J\n101\t FORMAT(' LINE :',I3)\n\t DO I=1,NSM\n\t PRINT 102,I\n102\t FORMAT(' ',I3,' := ',$)\n\t READ(5,*) GRID(I,J)\n\t SUM=SUM+GRID(I,J)\n\t END DO\n\tEND DO\n \n\tIF(SUM.NE.1.)THEN\n\tPRINT 106\n106\tFORMAT(' WARNING : THE GRID IS NOT NORMALIZED',/,\n 1\t' DO YOU WANT ME TO NORMALIZE IT ? (Y)')\n\tREAD(5,10) ANS\n\t IF(ANS.NE.'N'.AND.ANS.NE.'n')THEN\n\t DO I=1,NSM\n\t DO J=1,NSM\n\t GRID(I,J)=GRID(I,J)/SUM\n\t END DO\n\t END DO\n\t PRINT *,' GRID NORMALIZED'\n\t ENDIF\n\tENDIF\n \n105\tPRINT *,' NAME OF THE OUTPUT FILE (GRID) ?'\n\tREAD(5,10) NSMOOTH\n\tOPEN(1,FILE=NSMOOTH,STATUS='NEW',ERR=105)\n\tWRITE(1,*) ((GRID(I,J),I=1,NSM),J=1,NSM)\n\tCLOSE(1)\n\tENDIF\n \nC-------------------------------------------------------------\nC IOPT=2 Gaussian grid:\n\tIF(IOPT.EQ.2)THEN\n WRITE(BUFFER,12) NSM\n12 FORMAT(' Width of Gauss grid:',I4)\n\t IOP=2\n\t PRINT 203\n203\t FORMAT(' SIGMA (IN PIXELS) : ',$)\n\t READ(5,*) SIGMA\n\tENDIF\n \nC-------------------------------------------------------------\nC IOPT=3 \"Top Hat\" :\n\tIF(IOPT.EQ.3)THEN\n IOP=3\n WRITE(BUFFER,13) NSM\n13 FORMAT(' Width of Top Hat grid:',I4)\n ENDIF\n \nC-------------------------------------------------------------\nC IOPT=4 Input of a file :\n\tIF(IOPT.EQ.4)THEN\n\t IOP=4\n WRITE(BUFFER,14) NSM\n14 FORMAT(' Width of file grid:',I4)\n405\t PRINT *,' Name of precalculated smoothing grid'\n\t READ(5,10) NSMOOTH\n \n\t OPEN(1,FILE=NSMOOTH,STATUS='OLD',ERR=405)\n\t READ(1,*) ((GRID(I,J),I=1,NSM),J=1,NSM)\n\t CLOSE(1)\n \n\tENDIF\n \nC--------------------------------------------------------------\nC Prints the grid if IOP=4\n\tIF(IOP.EQ.4)THEN\n\t PRINT 801\n801\t FORMAT(' SMOOTHING GRID :')\n\t DO J=1,NSM\n\t DO I=1,NSM\n\t PRINT *,I,J,GRID(I,J)\n\t END DO\n\t END DO\n\tENDIF\nC-------------------------------------------------------------\nC Unsharp masking :\n\tPRINT *,' DO YOU WANT UNSHARP MASKING ? (N)'\n\tREAD(5,10) ANS\n\tUNSHARP=(ANS.EQ.'Y'.OR.ANS.EQ.'y')\n\t IF(UNSHARP)THEN\n\t PRINT *,' FRACTION OF THE SMOOTHED IMAGE YOU WANT TO REMOVE ?'\n\t READ(5,*) FRACT\n\t ENDIF\n \n \nC Output file:\n\tPRINT *,' OUTPUT FILE:'\n\tREAD(5,10) NAME_OUT\n\tISIZE=NX*NY*4\n\tCALL JLP_GETVM(PNTR_OUT,ISIZE)\n \nC Calls SMOOTH2 :\nC IOP=2 Gauss\nC IOP=3 Top hat\nC IOP=4 Input grid\n \n\tCALL SMOOTH2(MADRID(PNTR_IN),MADRID(PNTR_OUT),\n 1\tNX,NY,NX,IOP,GRID,NSM,SIGMA,UNSHARP,FRACT)\n \nC Output :\n\tIN=INDEX(NAME,' ')\n\t IF(UNSHARP)THEN\n\t WRITE(COMMENTS,902)NAME(1:IN),BUFFER(1:30)\n902\t FORMAT(' Unsharp mask from :',A,A)\n\t ELSE\n\t WRITE(COMMENTS,903)NAME(1:IN),BUFFER(1:30)\n903\t FORMAT('Smoothed image of:',A,A)\n\t ENDIF\n\tCALL JLP_WRITEIMAG(MADRID(PNTR_OUT),NX,NY,NX,\n 1\tNAME_OUT,COMMENTS)\n\n\tCALL JLP_END\n\tSTOP\n\tEND\nC------------------------------------------------------------------------\n\tinclude 'jlpsub:smooth2.for'\n", "meta": {"hexsha": "ffbfca62766237c8d1182e1a0ca05546a3b26b93", "size": 4253, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "source/shell_galaxies/smooth1.for", "max_stars_repo_name": "jlprieur/shell_galaxies", "max_stars_repo_head_hexsha": "1dde87ef33b3c33b3a892e9ad0d642ae02ac6d9e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source/shell_galaxies/smooth1.for", "max_issues_repo_name": "jlprieur/shell_galaxies", "max_issues_repo_head_hexsha": "1dde87ef33b3c33b3a892e9ad0d642ae02ac6d9e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/shell_galaxies/smooth1.for", "max_forks_repo_name": "jlprieur/shell_galaxies", "max_forks_repo_head_hexsha": "1dde87ef33b3c33b3a892e9ad0d642ae02ac6d9e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.8713450292, "max_line_length": 73, "alphanum_fraction": 0.5358570421, "num_tokens": 1452, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412809, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6649726660557165}} {"text": "module constants\n\n real*8, parameter :: pi = 3.141592654\n real*8, parameter :: e = 2.7182818285 \n\nend module \n", "meta": {"hexsha": "7c6a066f33e3b3d6bad77c4d85765197387dae5c", "size": 116, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "sandbox/fortran-modules/mods/constants.f90", "max_stars_repo_name": "rboman/progs", "max_stars_repo_head_hexsha": "c60b4e0487d01ccd007bcba79d1548ebe1685655", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-12-12T13:26:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-03T16:14:53.000Z", "max_issues_repo_path": "sandbox/fortran-modules/mods/constants.f90", "max_issues_repo_name": "rboman/progs", "max_issues_repo_head_hexsha": "c60b4e0487d01ccd007bcba79d1548ebe1685655", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2019-03-01T07:08:46.000Z", "max_issues_repo_issues_event_max_datetime": "2019-04-28T07:32:42.000Z", "max_forks_repo_path": "sandbox/fortran-modules/mods/constants.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": 16.5714285714, "max_line_length": 42, "alphanum_fraction": 0.6551724138, "num_tokens": 39, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8615382094310357, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6649726605677199}} {"text": "! chk_inverse_hyperbolic.f90 --\r\n! Check: does the compiler support the inverse hyperbolic functions for real arguments?\r\n!\r\nprogram chk_inverse_hyperbolic\r\n implicit none\r\n\r\n real, dimension(5) :: xsin = (/ -2.0,-0.9, 0.0, 0.9, 2.0 /)\r\n real, dimension(5) :: xcos = (/ 1.0, 1.1, 1.9, 2.0, 3.0 /)\r\n real, dimension(5) :: xtan = (/ -0.9,-0.1, 0.0, 0.1, 0.9 /)\r\n\r\n write( *, '(a)' ) 'Inverse hyperbolic functions: '\r\n write( *, '(a,5f7.4)' ) 'asinh: ', asinh(xsin)\r\n write( *, '(a,5f7.4)' ) 'acosh: ', acosh(xcos)\r\n write( *, '(a,5f7.4)' ) 'atanh: ', atanh(xtan)\r\nend program chk_inverse_hyperbolic\r\n", "meta": {"hexsha": "7b55cad65e12556884041b495e4e83fa0ae935fe", "size": 646, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "chkfeatures/chk_inverse_hyperbolic.f90", "max_stars_repo_name": "timcera/flibs_from_svn", "max_stars_repo_head_hexsha": "7790369ac1f0ff6e35ef43546446b32446dccc6b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-11T04:06:45.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-11T04:06:45.000Z", "max_issues_repo_path": "chkfeatures/chk_inverse_hyperbolic.f90", "max_issues_repo_name": "timcera/flibs_from_svn", "max_issues_repo_head_hexsha": "7790369ac1f0ff6e35ef43546446b32446dccc6b", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chkfeatures/chk_inverse_hyperbolic.f90", "max_forks_repo_name": "timcera/flibs_from_svn", "max_forks_repo_head_hexsha": "7790369ac1f0ff6e35ef43546446b32446dccc6b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-03-15T14:46:56.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-15T14:46:56.000Z", "avg_line_length": 40.375, "max_line_length": 92, "alphanum_fraction": 0.5541795666, "num_tokens": 254, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767938900121, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6649469801337493}} {"text": "! Guessing game - guess the number \n\nprogram guess_my_number\n implicit none\n integer, parameter:: dp=kind(0.d0)\n \n integer :: guess\n real(dp) :: rand\n integer :: i, clock, count, n\n integer,dimension(:),allocatable :: seed\n \n real,parameter :: rmax = 100\n \n !initialize random number generator:\n call random_seed(size=n)\n allocate(seed(n))\n call system_clock(count)\n seed = count\n call random_seed(put=seed)\n deallocate(seed)\n \n !pick a random number between 1 and rmax:\n call random_number(rand) !r between 0.0 and 1.0\n i = int((rmax-1.0)*rand + 1.0) !i between 1 and rmax\n \n !get user guess:\n write(*,'(A)') 'I''m thinking of a number between 1 and 100.'\n do !loop until guess is correct\n write(*,'(A)',advance='NO') 'Enter Guess: '\n read(*,'(I5)') guess\n if (guess==i) then \n exit\n else if (guess > i) then \n write(*,*) 'Sorry, try again. the number is smaller than guess'\n else\n write(*,*) 'Sorry, try again. the number is larger than guess'\n end if\n end do\n \n write(*,*) 'You''ve guessed my number!'\n \nend program guess_my_number\n", "meta": {"hexsha": "ab9b6ad00b319eed1605461cb406ef527dfd2d9f", "size": 1235, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "practice/guessing_game.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/guessing_game.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/guessing_game.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": 28.7209302326, "max_line_length": 72, "alphanum_fraction": 0.5700404858, "num_tokens": 342, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476793890012, "lm_q2_score": 0.757794360334681, "lm_q1q2_score": 0.6649469657344083}} {"text": "module mod_rational\n implicit none\n type rational\n integer(8) :: n, d\n end type rational\n interface assignment(=)\n module procedure assign0, assign1\n end interface assignment(=)\n interface operator(+)\n module procedure add0, add1, add2\n end interface operator(+)\n interface operator(-)\n module procedure sub0, sub1, sub2\n end interface operator(-)\n interface operator(*)\n module procedure mul0, mul1, mul2\n end interface operator(*)\n interface operator(/)\n module procedure div0, div1, div2\n end interface operator(/)\n interface operator(**)\n module procedure pow1\n end interface operator(**)\n interface operator(.gt.)\n module procedure gt0, gt1, gt2\n end interface operator(.gt.)\n interface operator(.ge.)\n module procedure ge0, ge1, ge2\n end interface operator(.ge.)\n interface operator(.eq.)\n module procedure eq0, eq1, eq2\n end interface operator(.eq.)\n interface operator(.le.)\n module procedure le0, le1, le2\n end interface operator(.le.)\n interface operator(.lt.)\n module procedure lt0, lt1, lt2\n end interface operator(.lt.)\n interface operator(.ne.)\n module procedure ne0, ne1, ne2\n end interface operator(.ne.)\n private\n public :: rational, show, gcd, lcm, ratio_of\n public :: trunc, ceil, round, is_int, int_of\n public :: assignment(=), operator(+), operator(-)\n public :: operator(*), operator(/), operator(**)\n public :: operator(.gt.), operator(.ge.), operator(.eq.)\n public :: operator(.le.), operator(.lt.), operator(.ne.)\ncontains\n subroutine show(a)\n implicit none\n type(rational), intent(in) :: a\n write(*,'(i0,\"/\",i0)') a%n, a%d\n return\n end subroutine show\n function trunc(a) result(n)\n implicit none\n type(rational), intent(in) :: a\n integer(8) :: n\n n = a%n/a%d\n if (mod(abs(a%n),a%d).eq.0_8) return\n if (a%n.lt.0_8) n = n-1_8\n return\n end function trunc\n function ceil(a) result(n)\n implicit none\n type(rational), intent(in) :: a\n integer(8) :: n\n n = a%n/a%d\n if (mod(abs(a%n),a%d).eq.0_8) return\n if (a%n.gt.0_8) n = n+1_8\n return\n end function ceil\n function round(a) result(n)\n implicit none\n type(rational), intent(in) :: a\n type(rational) :: b\n integer :: n\n call assign0(b,\"1/2\")\n n = trunc(a+b)\n return\n end function round\n function is_int(a) result(x)\n implicit none\n type(rational), intent(in) :: a\n logical :: x\n x = a%d.eq.1_8\n return\n end function is_int\n function int_of(a) result(n)\n implicit none\n type(rational), intent(in) :: a\n integer(8) :: n\n n = a%n\n return\n end function int_of\n subroutine assign0(r,s)\n implicit none\n type(rational), intent(inout) :: r\n character(*), intent(in) :: s\n integer :: i, l\n integer(8) :: n, d, g\n l = len_trim(s)\n do i = 2, l-1\n if (s(i:i).eq.\"/\") then\n read(s(1:i-1),*) n\n read(s(i+1:l),*) d\n exit\n end if\n end do\n g = gcd(n,d)\n r%n = n/g\n r%d = d/g\n return\n end subroutine assign0\n subroutine assign1(r,a)\n implicit none\n type(rational), intent(inout) :: r\n integer(8), intent(in) :: a\n r%n = a\n r%d = 1_8\n return\n end subroutine assign1\n function ratio_of(a,b) result(r)\n implicit none\n integer(8), intent(in) :: a, b\n type(rational) :: r\n r%n = a\n r%d = b\n return\n end function ratio_of\n function add0(a,b) result(r)\n implicit none\n type(rational), intent(in) :: a, b\n type(rational) :: r\n integer(8) :: l, g\n l = lcm(a%d,b%d)\n r%n = (a%n*l)/a%d+(b%n*l)/b%d\n r%d = l\n g = gcd(abs(r%n),abs(r%d))\n r%n = r%n/g\n r%d = r%d/g\n return\n end function add0\n function add1(a,b) result(r)\n implicit none\n type(rational), intent(in) :: a\n integer(8), intent(in) :: b\n type(rational) :: r\n call assign1(r,b)\n r = add0(a,r)\n return\n end function add1\n function add2(a,b) result(r)\n implicit none\n integer(8), intent(in) :: a\n type(rational), intent(in) :: b\n type(rational) :: r\n call assign1(r,a)\n r = add0(r,b)\n return\n end function add2\n function sub0(a,b) result(r)\n implicit none\n type(rational), intent(in) :: a, b\n type(rational) :: r\n integer(8) :: l, g\n l = lcm(a%d,b%d)\n r%n = (a%n*l)/a%d-(b%n*l)/b%d\n r%d = l\n g = gcd(abs(r%n),abs(r%d))\n r%n = r%n/g\n r%d = r%d/g\n return\n end function sub0\n function sub1(a,b) result(r)\n implicit none\n type(rational), intent(in) :: a\n integer(8), intent(in) :: b\n type(rational) :: r\n call assign1(r,b)\n r = sub0(a,r)\n return\n end function sub1\n function sub2(a,b) result(r)\n implicit none\n integer(8), intent(in) :: a\n type(rational), intent(in) :: b\n type(rational) :: r\n call assign1(r,a)\n r = sub0(r,b)\n return\n end function sub2\n function mul0(a,b) result(r)\n implicit none\n type(rational), intent(in) :: a, b\n type(rational) :: r\n integer(8) :: g\n r%n = a%n*b%n\n r%d = a%d*b%d\n g = gcd(abs(r%n),abs(r%d))\n r%n = r%n/g\n r%d = r%d/g\n return\n end function mul0\n function mul1(a,b) result(r)\n implicit none\n type(rational), intent(in) :: a\n integer(8), intent(in) :: b\n type(rational) :: r\n call assign1(r,b)\n r = mul0(a,r)\n return\n end function mul1\n function mul2(a,b) result(r)\n implicit none\n integer(8), intent(in) :: a\n type(rational), intent(in) :: b\n type(rational) :: r\n call assign1(r,a)\n r = mul0(r,b)\n return\n end function mul2\n function div0(a,b) result(r)\n implicit none\n type(rational), intent(in) :: a, b\n type(rational) :: r\n r = mul0(a,inv(b))\n return\n end function div0\n function div1(a,b) result(r)\n implicit none\n type(rational), intent(in) :: a\n integer(8), intent(in) :: b\n type(rational) :: r\n call assign1(r,b)\n r = div0(a,r)\n return\n end function div1\n function div2(a,b) result(r)\n implicit none\n integer(8), intent(in) :: a\n type(rational), intent(in) :: b\n type(rational) :: r\n call assign1(r,a)\n r = div0(r,b)\n return\n end function div2\n function inv(n) result(m)\n implicit none\n type(rational), intent(in) :: n\n type(rational) :: m\n m%n = n%d\n m%d = n%n\n return\n end function inv\n recursive function pow1(a,b) result(r)\n implicit none\n type(rational), intent(in) :: a\n integer(8), intent(in) :: b\n type(rational) :: r\n if (b.eq.0_8) then\n call assign1(r,1_8)\n return\n end if\n if (mod(b,2_8).eq.0_8) then\n r = pow1(a,b/2_8)\n r = mul0(r,r)\n return\n end if\n r = mul0(a,pow1(a,b-1_8))\n return\n end function pow1\n function lcm(x,y) result(z)\n implicit none\n integer(8), intent(in) :: x, y\n integer(8) :: z\n z = (x/gcd(x,y))*y\n return\n end function lcm\n recursive function gcd(x,y) result(z)\n implicit none\n integer(8), intent(in) :: x, y\n integer(8) :: z\n if (x.lt.y) then\n z = gcd(y,x)\n return\n end if\n z = x\n if (y.eq.0_8) return\n z = gcd(y,mod(x,y))\n return\n end function gcd\n function gt0(a,b) result(x)\n implicit none\n type(rational), intent(in) :: a, b\n type(rational) :: r\n logical :: x\n r = sub0(a,b)\n x = r%n.gt.0_8\n return\n end function gt0\n function gt1(a,b) result(x)\n implicit none\n type(rational), intent(in) :: a\n integer(8), intent(in) :: b\n type(rational) :: r\n logical :: x\n call assign1(r,b)\n x = gt0(a,r)\n return\n end function gt1\n function gt2(a,b) result(x)\n implicit none\n integer(8), intent(in) :: a\n type(rational), intent(in) :: b\n type(rational) :: r\n logical :: x\n call assign1(r,a)\n x = gt0(r,b)\n return\n end function gt2\n function ge0(a,b) result(x)\n implicit none\n type(rational), intent(in) :: a, b\n type(rational) :: r\n logical :: x\n r = sub0(a,b)\n x = r%n.ge.0_8\n return\n end function ge0\n function ge1(a,b) result(x)\n implicit none\n type(rational), intent(in) :: a\n integer(8), intent(in) :: b\n type(rational) :: r\n logical :: x\n call assign1(r,b)\n x = ge0(a,r)\n return\n end function ge1\n function ge2(a,b) result(x)\n implicit none\n integer(8), intent(in) :: a\n type(rational), intent(in) :: b\n type(rational) :: r\n logical :: x\n call assign1(r,a)\n x = ge0(r,b)\n return\n end function ge2\n function eq0(a,b) result(x)\n implicit none\n type(rational), intent(in) :: a, b\n type(rational) :: r\n logical :: x\n r = sub0(a,b)\n x = r%n.eq.0_8\n return\n end function eq0\n function eq1(a,b) result(x)\n implicit none\n type(rational), intent(in) :: a\n integer(8), intent(in) :: b\n type(rational) :: r\n logical :: x\n call assign1(r,b)\n x = eq0(a,r)\n return\n end function eq1\n function eq2(a,b) result(x)\n implicit none\n integer(8), intent(in) :: a\n type(rational), intent(in) :: b\n type(rational) :: r\n logical :: x\n call assign1(r,a)\n x = eq0(r,b)\n return\n end function eq2\n function le0(a,b) result(x)\n implicit none\n type(rational), intent(in) :: a, b\n type(rational) :: r\n logical :: x\n r = sub0(a,b)\n x = r%n.le.0_8\n return\n end function le0\n function le1(a,b) result(x)\n implicit none\n type(rational), intent(in) :: a\n integer(8), intent(in) :: b\n type(rational) :: r\n logical :: x\n call assign1(r,b)\n x = le0(a,r)\n return\n end function le1\n function le2(a,b) result(x)\n implicit none\n integer(8), intent(in) :: a\n type(rational), intent(in) :: b\n type(rational) :: r\n logical :: x\n call assign1(r,a)\n x = le0(r,b)\n return\n end function le2\n function lt0(a,b) result(x)\n implicit none\n type(rational), intent(in) :: a, b\n type(rational) :: r\n logical :: x\n r = sub0(a,b)\n x = r%n.lt.0_8\n return\n end function lt0\n function lt1(a,b) result(x)\n implicit none\n type(rational), intent(in) :: a\n integer(8), intent(in) :: b\n type(rational) :: r\n logical :: x\n call assign1(r,b)\n x = lt0(a,r)\n return\n end function lt1\n function lt2(a,b) result(x)\n implicit none\n integer(8), intent(in) :: a\n type(rational), intent(in) :: b\n type(rational) :: r\n logical :: x\n call assign1(r,a)\n x = lt0(r,b)\n return\n end function lt2\n function ne0(a,b) result(x)\n implicit none\n type(rational), intent(in) :: a, b\n type(rational) :: r\n logical :: x\n r = sub0(a,b)\n x = r%n.ne.0_8\n return\n end function ne0\n function ne1(a,b) result(x)\n implicit none\n type(rational), intent(in) :: a\n integer(8), intent(in) :: b\n type(rational) :: r\n logical :: x\n call assign1(r,b)\n x = ne0(a,r)\n return\n end function ne1\n function ne2(a,b) result(x)\n implicit none\n integer(8), intent(in) :: a\n type(rational), intent(in) :: b\n type(rational) :: r\n logical :: x\n call assign1(r,a)\n x = ne0(r,b)\n return\n end function ne2\nend module mod_rational\n", "meta": {"hexsha": "647a9d578b4a0b8d55cbf3b48491d65bd1c7916b", "size": 10959, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran90/rational.f90", "max_stars_repo_name": "ue1221/fortran-utilities", "max_stars_repo_head_hexsha": "83037ee4e199e33f8d4774a9928fbfddeba2930e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fortran90/rational.f90", "max_issues_repo_name": "ue1221/fortran-utilities", "max_issues_repo_head_hexsha": "83037ee4e199e33f8d4774a9928fbfddeba2930e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran90/rational.f90", "max_forks_repo_name": "ue1221/fortran-utilities", "max_forks_repo_head_hexsha": "83037ee4e199e33f8d4774a9928fbfddeba2930e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.3667377399, "max_line_length": 58, "alphanum_fraction": 0.5828998996, "num_tokens": 3594, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818409, "lm_q2_score": 0.7577943603346811, "lm_q1q2_score": 0.6649469608783325}} {"text": " REAL FUNCTION SBESJ0 (X)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc>> 1996-03-30 SBESJ0 Krogh Added external statement.\nC>> 1995-11-10 SBESJ0 Krogh Changed data statment for C converstion.\nC>> 1995-11-03 SBESJ0 Krogh Removed blanks in numbers for C conversion.\nC>> 1994-11-11 SBESJ0 Krogh Declared all vars.\nC>> 1994-10-20 SBESJ0 Krogh Changes to use M77CON\nC>> 1990-11-29 SBESJ0 CLL\nC>> 1985-08-02 SBESJ0 Lawson Initial code.\nC JULY 1977 EDITION. W. FULLERTON, C3, LOS ALAMOS SCIENTIFIC LAB.\nC C.L.LAWSON & S.CHAN, JPL, 1984 FEB ADAPTED TO JPL MATH77 LIBRARY.\nc ------------------------------------------------------------------\nc--S replaces \"?\": ?BESJ0, ?BMP0, ?INITS, ?CSEVL\nc ------------------------------------------------------------------\n EXTERNAL R1MACH, SCSEVL\n INTEGER NTJ0\n REAL X, BJ0CS(19), AMPL, THETA, XSML, Y,\n 1 R1MACH, SCSEVL\nC\nC SERIES FOR BJ0 ON THE INTERVAL 0. TO 1.60000E+01\nC WITH WEIGHTED ERROR 4.39E-32\nC LOG WEIGHTED ERROR 31.36\nC SIGNIFICANT FIGURES REQUIRED 31.21\nC DECIMAL PLACES REQUIRED 32.00\nC\n SAVE NTJ0, XSML\nC\n DATA BJ0CS / +.10025416196893913701073127264074E+0,\n * -.66522300776440513177678757831124E+0,\n * +.24898370349828131370460468726680E+0,\n * -.33252723170035769653884341503854E-1,\n * +.23114179304694015462904924117729E-2,\n * -.99112774199508092339048519336549E-4,\n * +.28916708643998808884733903747078E-5,\n * -.61210858663032635057818407481516E-7,\n * +.98386507938567841324768748636415E-9,\n * -.12423551597301765145515897006836E-10,\n * +.12654336302559045797915827210363E-12,\n * -.10619456495287244546914817512959E-14,\n * +.74706210758024567437098915584000E-17,\n * -.44697032274412780547627007999999E-19,\n * +.23024281584337436200523093333333E-21,\n * -.10319144794166698148522666666666E-23,\n * +.40608178274873322700800000000000E-26,\n * -.14143836005240913919999999999999E-28,\n * +.43910905496698880000000000000000E-31 /\nC\n DATA NTJ0, XSML / 0, 0.E0 /\nC ------------------------------------------------------------------\n IF (NTJ0.NE.0) GO TO 10\n call SINITS (BJ0CS, 19, 0.1E0*R1MACH(3), NTJ0)\n XSML = SQRT (4.0E0*R1MACH(3))\nC\n 10 Y = ABS(X)\nC\n IF (Y .LE. XSML) THEN\n SBESJ0 = 1.E0\n ELSE IF (Y .LE. 4.E0) THEN\n SBESJ0 = SCSEVL (.125E0*Y*Y-1.E0, BJ0CS, NTJ0)\n ELSE\n CALL SBMP0 (Y, AMPL, THETA)\n SBESJ0 = AMPL * COS(THETA)\n END IF\nC\n RETURN\n END\n", "meta": {"hexsha": "ddb0077fe9be39e50a679cfda963bc7538eb2ddf", "size": 2814, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/sbesj0.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/sbesj0.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/sbesj0.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": 40.7826086957, "max_line_length": 72, "alphanum_fraction": 0.5863539446, "num_tokens": 1016, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767810736693, "lm_q2_score": 0.7577943658046608, "lm_q1q2_score": 0.6649469608220364}} {"text": " SUBROUTINE DPOSVX( FACT, UPLO, N, NRHS, A, LDA, AF, LDAF, EQUED,\n $ S, B, LDB, X, LDX, RCOND, FERR, BERR, WORK,\n $ IWORK, INFO )\n*\n* -- LAPACK driver routine (version 3.2) --\n* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..\n* November 2006\n*\n* .. Scalar Arguments ..\n CHARACTER EQUED, FACT, UPLO\n INTEGER INFO, LDA, LDAF, LDB, LDX, N, NRHS\n DOUBLE PRECISION RCOND\n* ..\n* .. Array Arguments ..\n INTEGER IWORK( * )\n DOUBLE PRECISION A( LDA, * ), AF( LDAF, * ), B( LDB, * ),\n $ BERR( * ), FERR( * ), S( * ), WORK( * ),\n $ X( LDX, * )\n* ..\n*\n* Purpose\n* =======\n*\n* DPOSVX uses the Cholesky factorization A = U**T*U or A = L*L**T to\n* compute the solution to a real system of linear equations\n* A * X = B,\n* where A is an N-by-N symmetric positive definite matrix and X and B\n* are N-by-NRHS matrices.\n*\n* Error bounds on the solution and a condition estimate are also\n* provided.\n*\n* Description\n* ===========\n*\n* The following steps are performed:\n*\n* 1. If FACT = 'E', real scaling factors are computed to equilibrate\n* the system:\n* diag(S) * A * diag(S) * inv(diag(S)) * X = diag(S) * B\n* Whether or not the system will be equilibrated depends on the\n* scaling of the matrix A, but if equilibration is used, A is\n* overwritten by diag(S)*A*diag(S) and B by diag(S)*B.\n*\n* 2. If FACT = 'N' or 'E', the Cholesky decomposition is used to\n* factor the matrix A (after equilibration if FACT = 'E') as\n* A = U**T* U, if UPLO = 'U', or\n* A = L * L**T, if UPLO = 'L',\n* where U is an upper triangular matrix and L is a lower triangular\n* matrix.\n*\n* 3. If the leading i-by-i principal minor is not positive definite,\n* then the routine returns with INFO = i. Otherwise, the factored\n* form of A is used to estimate the condition number of the matrix\n* A. If the reciprocal of the condition number is less than machine\n* precision, INFO = N+1 is returned as a warning, but the routine\n* still goes on to solve for X and compute error bounds as\n* described below.\n*\n* 4. The system of equations is solved for X using the factored form\n* of A.\n*\n* 5. Iterative refinement is applied to improve the computed solution\n* matrix and calculate error bounds and backward error estimates\n* for it.\n*\n* 6. If equilibration was used, the matrix X is premultiplied by\n* diag(S) so that it solves the original system before\n* equilibration.\n*\n* Arguments\n* =========\n*\n* FACT (input) CHARACTER*1\n* Specifies whether or not the factored form of the matrix A is\n* supplied on entry, and if not, whether the matrix A should be\n* equilibrated before it is factored.\n* = 'F': On entry, AF contains the factored form of A.\n* If EQUED = 'Y', the matrix A has been equilibrated\n* with scaling factors given by S. A and AF will not\n* be modified.\n* = 'N': The matrix A will be copied to AF and factored.\n* = 'E': The matrix A will be equilibrated if necessary, then\n* copied to AF and factored.\n*\n* UPLO (input) CHARACTER*1\n* = 'U': Upper triangle of A is stored;\n* = 'L': Lower triangle of A is stored.\n*\n* N (input) INTEGER\n* The number of linear equations, i.e., the order of the\n* matrix A. N >= 0.\n*\n* NRHS (input) INTEGER\n* The number of right hand sides, i.e., the number of columns\n* of the matrices B and X. NRHS >= 0.\n*\n* A (input/output) DOUBLE PRECISION array, dimension (LDA,N)\n* On entry, the symmetric matrix A, except if FACT = 'F' and\n* EQUED = 'Y', then A must contain the equilibrated matrix\n* diag(S)*A*diag(S). If UPLO = 'U', the leading\n* N-by-N upper triangular part of A contains the upper\n* triangular part of the matrix A, and the strictly lower\n* triangular part of A is not referenced. If UPLO = 'L', the\n* leading N-by-N lower triangular part of A contains the lower\n* triangular part of the matrix A, and the strictly upper\n* triangular part of A is not referenced. A is not modified if\n* FACT = 'F' or 'N', or if FACT = 'E' and EQUED = 'N' on exit.\n*\n* On exit, if FACT = 'E' and EQUED = 'Y', A is overwritten by\n* diag(S)*A*diag(S).\n*\n* LDA (input) INTEGER\n* The leading dimension of the array A. LDA >= max(1,N).\n*\n* AF (input or output) DOUBLE PRECISION array, dimension (LDAF,N)\n* If FACT = 'F', then AF is an input argument and on entry\n* contains the triangular factor U or L from the Cholesky\n* factorization A = U**T*U or A = L*L**T, in the same storage\n* format as A. If EQUED .ne. 'N', then AF is the factored form\n* of the equilibrated matrix diag(S)*A*diag(S).\n*\n* If FACT = 'N', then AF is an output argument and on exit\n* returns the triangular factor U or L from the Cholesky\n* factorization A = U**T*U or A = L*L**T of the original\n* matrix A.\n*\n* If FACT = 'E', then AF is an output argument and on exit\n* returns the triangular factor U or L from the Cholesky\n* factorization A = U**T*U or A = L*L**T of the equilibrated\n* matrix A (see the description of A for the form of the\n* equilibrated matrix).\n*\n* LDAF (input) INTEGER\n* The leading dimension of the array AF. LDAF >= max(1,N).\n*\n* EQUED (input or output) CHARACTER*1\n* Specifies the form of equilibration that was done.\n* = 'N': No equilibration (always true if FACT = 'N').\n* = 'Y': Equilibration was done, i.e., A has been replaced by\n* diag(S) * A * diag(S).\n* EQUED is an input argument if FACT = 'F'; otherwise, it is an\n* output argument.\n*\n* S (input or output) DOUBLE PRECISION array, dimension (N)\n* The scale factors for A; not accessed if EQUED = 'N'. S is\n* an input argument if FACT = 'F'; otherwise, S is an output\n* argument. If FACT = 'F' and EQUED = 'Y', each element of S\n* must be positive.\n*\n* B (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS)\n* On entry, the N-by-NRHS right hand side matrix B.\n* On exit, if EQUED = 'N', B is not modified; if EQUED = 'Y',\n* B is overwritten by diag(S) * B.\n*\n* LDB (input) INTEGER\n* The leading dimension of the array B. LDB >= max(1,N).\n*\n* X (output) DOUBLE PRECISION array, dimension (LDX,NRHS)\n* If INFO = 0 or INFO = N+1, the N-by-NRHS solution matrix X to\n* the original system of equations. Note that if EQUED = 'Y',\n* A and B are modified on exit, and the solution to the\n* equilibrated system is inv(diag(S))*X.\n*\n* LDX (input) INTEGER\n* The leading dimension of the array X. LDX >= max(1,N).\n*\n* RCOND (output) DOUBLE PRECISION\n* The estimate of the reciprocal condition number of the matrix\n* A after equilibration (if done). If RCOND is less than the\n* machine precision (in particular, if RCOND = 0), the matrix\n* is singular to working precision. This condition is\n* indicated by a return code of INFO > 0.\n*\n* FERR (output) DOUBLE PRECISION array, dimension (NRHS)\n* The estimated forward error bound for each solution vector\n* X(j) (the j-th column of the solution matrix X).\n* If XTRUE is the true solution corresponding to X(j), FERR(j)\n* is an estimated upper bound for the magnitude of the largest\n* element in (X(j) - XTRUE) divided by the magnitude of the\n* largest element in X(j). The estimate is as reliable as\n* the estimate for RCOND, and is almost always a slight\n* overestimate of the true error.\n*\n* BERR (output) DOUBLE PRECISION array, dimension (NRHS)\n* The componentwise relative backward error of each solution\n* vector X(j) (i.e., the smallest relative change in\n* any element of A or B that makes X(j) an exact solution).\n*\n* WORK (workspace) DOUBLE PRECISION array, dimension (3*N)\n*\n* IWORK (workspace) INTEGER array, dimension (N)\n*\n* INFO (output) INTEGER\n* = 0: successful exit\n* < 0: if INFO = -i, the i-th argument had an illegal value\n* > 0: if INFO = i, and i is\n* <= N: the leading minor of order i of A is\n* not positive definite, so the factorization\n* could not be completed, and the solution has not\n* been computed. RCOND = 0 is returned.\n* = N+1: U is nonsingular, but RCOND is less than machine\n* precision, meaning that the matrix is singular\n* to working precision. Nevertheless, the\n* solution and error bounds are computed because\n* there are a number of situations where the\n* computed solution can be more accurate than the\n* value of RCOND would suggest.\n*\n* =====================================================================\n*\n* .. Parameters ..\n DOUBLE PRECISION ZERO, ONE\n PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )\n* ..\n* .. Local Scalars ..\n LOGICAL EQUIL, NOFACT, RCEQU\n INTEGER I, INFEQU, J\n DOUBLE PRECISION AMAX, ANORM, BIGNUM, SCOND, SMAX, SMIN, SMLNUM\n* ..\n* .. External Functions ..\n LOGICAL LSAME\n DOUBLE PRECISION DLAMCH, DLANSY\n EXTERNAL LSAME, DLAMCH, DLANSY\n* ..\n* .. External Subroutines ..\n EXTERNAL DLACPY, DLAQSY, DPOCON, DPOEQU, DPORFS, DPOTRF,\n $ DPOTRS, XERBLA\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC MAX, MIN\n* ..\n* .. Executable Statements ..\n*\n INFO = 0\n NOFACT = LSAME( FACT, 'N' )\n EQUIL = LSAME( FACT, 'E' )\n IF( NOFACT .OR. EQUIL ) THEN\n EQUED = 'N'\n RCEQU = .FALSE.\n ELSE\n RCEQU = LSAME( EQUED, 'Y' )\n SMLNUM = DLAMCH( 'Safe minimum' )\n BIGNUM = ONE / SMLNUM\n END IF\n*\n* Test the input parameters.\n*\n IF( .NOT.NOFACT .AND. .NOT.EQUIL .AND. .NOT.LSAME( FACT, 'F' ) )\n $ THEN\n INFO = -1\n ELSE IF( .NOT.LSAME( UPLO, 'U' ) .AND. .NOT.LSAME( UPLO, 'L' ) )\n $ THEN\n INFO = -2\n ELSE IF( N.LT.0 ) THEN\n INFO = -3\n ELSE IF( NRHS.LT.0 ) THEN\n INFO = -4\n ELSE IF( LDA.LT.MAX( 1, N ) ) THEN\n INFO = -6\n ELSE IF( LDAF.LT.MAX( 1, N ) ) THEN\n INFO = -8\n ELSE IF( LSAME( FACT, 'F' ) .AND. .NOT.\n $ ( RCEQU .OR. LSAME( EQUED, 'N' ) ) ) THEN\n INFO = -9\n ELSE\n IF( RCEQU ) THEN\n SMIN = BIGNUM\n SMAX = ZERO\n DO 10 J = 1, N\n SMIN = MIN( SMIN, S( J ) )\n SMAX = MAX( SMAX, S( J ) )\n 10 CONTINUE\n IF( SMIN.LE.ZERO ) THEN\n INFO = -10\n ELSE IF( N.GT.0 ) THEN\n SCOND = MAX( SMIN, SMLNUM ) / MIN( SMAX, BIGNUM )\n ELSE\n SCOND = ONE\n END IF\n END IF\n IF( INFO.EQ.0 ) THEN\n IF( LDB.LT.MAX( 1, N ) ) THEN\n INFO = -12\n ELSE IF( LDX.LT.MAX( 1, N ) ) THEN\n INFO = -14\n END IF\n END IF\n END IF\n*\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'DPOSVX', -INFO )\n RETURN\n END IF\n*\n IF( EQUIL ) THEN\n*\n* Compute row and column scalings to equilibrate the matrix A.\n*\n CALL DPOEQU( N, A, LDA, S, SCOND, AMAX, INFEQU )\n IF( INFEQU.EQ.0 ) THEN\n*\n* Equilibrate the matrix.\n*\n CALL DLAQSY( UPLO, N, A, LDA, S, SCOND, AMAX, EQUED )\n RCEQU = LSAME( EQUED, 'Y' )\n END IF\n END IF\n*\n* Scale the right hand side.\n*\n IF( RCEQU ) THEN\n DO 30 J = 1, NRHS\n DO 20 I = 1, N\n B( I, J ) = S( I )*B( I, J )\n 20 CONTINUE\n 30 CONTINUE\n END IF\n*\n IF( NOFACT .OR. EQUIL ) THEN\n*\n* Compute the Cholesky factorization A = U'*U or A = L*L'.\n*\n CALL DLACPY( UPLO, N, N, A, LDA, AF, LDAF )\n CALL DPOTRF( UPLO, N, AF, LDAF, INFO )\n*\n* Return if INFO is non-zero.\n*\n IF( INFO.GT.0 )THEN\n RCOND = ZERO\n RETURN\n END IF\n END IF\n*\n* Compute the norm of the matrix A.\n*\n ANORM = DLANSY( '1', UPLO, N, A, LDA, WORK )\n*\n* Compute the reciprocal of the condition number of A.\n*\n CALL DPOCON( UPLO, N, AF, LDAF, ANORM, RCOND, WORK, IWORK, INFO )\n*\n* Compute the solution matrix X.\n*\n CALL DLACPY( 'Full', N, NRHS, B, LDB, X, LDX )\n CALL DPOTRS( UPLO, N, NRHS, AF, LDAF, X, LDX, INFO )\n*\n* Use iterative refinement to improve the computed solution and\n* compute error bounds and backward error estimates for it.\n*\n CALL DPORFS( UPLO, N, NRHS, A, LDA, AF, LDAF, B, LDB, X, LDX,\n $ FERR, BERR, WORK, IWORK, INFO )\n*\n* Transform the solution matrix X to a solution of the original\n* system.\n*\n IF( RCEQU ) THEN\n DO 50 J = 1, NRHS\n DO 40 I = 1, N\n X( I, J ) = S( I )*X( I, J )\n 40 CONTINUE\n 50 CONTINUE\n DO 60 J = 1, NRHS\n FERR( J ) = FERR( J ) / SCOND\n 60 CONTINUE\n END IF\n*\n* Set INFO = N+1 if the matrix is singular to working precision.\n*\n IF( RCOND.LT.DLAMCH( 'Epsilon' ) )\n $ INFO = N + 1\n*\n RETURN\n*\n* End of DPOSVX\n*\n END\n", "meta": {"hexsha": "58099deccdf07eb51411b0e32b9748f11d16bfa4", "size": 13986, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "code_1D/couplage_1D/fortran90_source/liblapack/SRC/dposvx.f", "max_stars_repo_name": "IRFM/ALOHA", "max_stars_repo_head_hexsha": "e8e7a47a70c7095b339b3dea25dcd4b95f382959", "max_stars_repo_licenses": ["CECILL-B"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-11-12T08:42:36.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-12T08:42:41.000Z", "max_issues_repo_path": "code_1D/couplage_1D/fortran90_source/liblapack/SRC/dposvx.f", "max_issues_repo_name": "IRFM/ALOHA", "max_issues_repo_head_hexsha": "e8e7a47a70c7095b339b3dea25dcd4b95f382959", "max_issues_repo_licenses": ["CECILL-B"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-02-21T10:46:38.000Z", "max_issues_repo_issues_event_max_datetime": "2017-10-20T17:03:14.000Z", "max_forks_repo_path": "code_1D/couplage_1D/fortran90_source/liblapack/SRC/dposvx.f", "max_forks_repo_name": "IRFM/ALOHA", "max_forks_repo_head_hexsha": "e8e7a47a70c7095b339b3dea25dcd4b95f382959", "max_forks_repo_licenses": ["CECILL-B"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-10-05T12:40:02.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-12T08:41:20.000Z", "avg_line_length": 37.0, "max_line_length": 72, "alphanum_fraction": 0.5464035464, "num_tokens": 4134, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404018582426, "lm_q2_score": 0.7154240018510026, "lm_q1q2_score": 0.664943971779428}} {"text": " SUBROUTINE SB03MD( DICO, JOB, FACT, TRANA, N, A, LDA, U, LDU, C,\n $ LDC, SCALE, SEP, FERR, WR, WI, IWORK, DWORK,\n $ LDWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To solve for X either the real continuous-time Lyapunov equation\nC\nC op(A)'*X + X*op(A) = scale*C (1)\nC\nC or the real discrete-time Lyapunov equation\nC\nC op(A)'*X*op(A) - X = scale*C (2)\nC\nC and/or estimate an associated condition number, called separation,\nC where op(A) = A or A' (A**T) and C is symmetric (C = C').\nC (A' denotes the transpose of the matrix A.) A is N-by-N, the right\nC hand side C and the solution X are N-by-N, and scale is an output\nC scale factor, set less than or equal to 1 to avoid overflow in X.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC DICO CHARACTER*1\nC Specifies the equation from which X is to be determined\nC as follows:\nC = 'C': Equation (1), continuous-time case;\nC = 'D': Equation (2), discrete-time case.\nC\nC JOB CHARACTER*1\nC Specifies the computation to be performed, as follows:\nC = 'X': Compute the solution only;\nC = 'S': Compute the separation only;\nC = 'B': Compute both the solution and the separation.\nC\nC FACT CHARACTER*1\nC Specifies whether or not the real Schur factorization\nC of the matrix A is supplied on entry, as follows:\nC = 'F': On entry, A and U contain the factors from the\nC real Schur factorization of the matrix A;\nC = 'N': The Schur factorization of A will be computed\nC and the factors will be stored in A and U.\nC\nC TRANA CHARACTER*1\nC Specifies the form of op(A) to be used, as follows:\nC = 'N': op(A) = A (No transpose);\nC = 'T': op(A) = A**T (Transpose);\nC = 'C': op(A) = A**T (Conjugate transpose = Transpose).\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The order of the matrices A, X, and C. N >= 0.\nC\nC A (input/output) DOUBLE PRECISION array, dimension (LDA,N)\nC On entry, the leading N-by-N part of this array must\nC contain the matrix A. If FACT = 'F', then A contains\nC an upper quasi-triangular matrix in Schur canonical form;\nC the elements below the upper Hessenberg part of the\nC array A are not referenced.\nC On exit, if INFO = 0 or INFO = N+1, the leading N-by-N\nC upper Hessenberg part of this array contains the upper\nC quasi-triangular matrix in Schur canonical form from the\nC Schur factorization of A. The contents of array A is not\nC modified if FACT = 'F'.\nC\nC LDA INTEGER\nC The leading dimension of array A. LDA >= MAX(1,N).\nC\nC U (input or output) DOUBLE PRECISION array, dimension\nC (LDU,N)\nC If FACT = 'F', then U is an input argument and on entry\nC the leading N-by-N part of this array must contain the\nC orthogonal matrix U of the real Schur factorization of A.\nC If FACT = 'N', then U is an output argument and on exit,\nC if INFO = 0 or INFO = N+1, it contains the orthogonal\nC N-by-N matrix from the real Schur factorization of A.\nC\nC LDU INTEGER\nC The leading dimension of array U. LDU >= MAX(1,N).\nC\nC C (input/output) DOUBLE PRECISION array, dimension (LDC,N)\nC On entry with JOB = 'X' or 'B', the leading N-by-N part of\nC this array must contain the symmetric matrix C.\nC On exit with JOB = 'X' or 'B', if INFO = 0 or INFO = N+1,\nC the leading N-by-N part of C has been overwritten by the\nC symmetric solution matrix X.\nC If JOB = 'S', C is not referenced.\nC\nC LDC INTEGER\nC The leading dimension of array C.\nC LDC >= 1, if JOB = 'S';\nC LDC >= MAX(1,N), otherwise.\nC\nC SCALE (output) DOUBLE PRECISION\nC The scale factor, scale, set less than or equal to 1 to\nC prevent the solution overflowing.\nC\nC SEP (output) DOUBLE PRECISION\nC If JOB = 'S' or JOB = 'B', and INFO = 0 or INFO = N+1, SEP\nC contains the estimated separation of the matrices op(A)\nC and -op(A)', if DICO = 'C' or of op(A) and op(A)', if\nC DICO = 'D'.\nC If JOB = 'X', SEP is not referenced.\nC\nC FERR (output) DOUBLE PRECISION\nC If JOB = 'B', and INFO = 0 or INFO = N+1, FERR contains an\nC estimated forward error bound for the solution X.\nC If XTRUE is the true solution, FERR bounds the relative\nC error in the computed solution, measured in the Frobenius\nC norm: norm(X - XTRUE)/norm(XTRUE).\nC If JOB = 'X' or JOB = 'S', FERR is not referenced.\nC\nC WR (output) DOUBLE PRECISION array, dimension (N)\nC WI (output) DOUBLE PRECISION array, dimension (N)\nC If FACT = 'N', and INFO = 0 or INFO = N+1, WR and WI\nC contain the real and imaginary parts, respectively, of\nC the eigenvalues of A.\nC If FACT = 'F', WR and WI are not referenced.\nC\nC Workspace\nC\nC IWORK INTEGER array, dimension (N*N)\nC This array is not referenced if JOB = 'X'.\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0 or INFO = N+1, DWORK(1) returns the\nC optimal value of LDWORK.\nC\nC LDWORK INTEGER\nC The length of the array DWORK. LDWORK >= 1, and\nC If JOB = 'X' then\nC If FACT = 'F', LDWORK >= N*N, for DICO = 'C';\nC LDWORK >= MAX(N*N, 2*N), for DICO = 'D';\nC If FACT = 'N', LDWORK >= MAX(N*N, 3*N).\nC If JOB = 'S' or JOB = 'B' then\nC If FACT = 'F', LDWORK >= 2*N*N, for DICO = 'C';\nC LDWORK >= 2*N*N + 2*N, for DICO = 'D'.\nC If FACT = 'N', LDWORK >= MAX(2*N*N, 3*N), DICO = 'C';\nC LDWORK >= 2*N*N + 2*N, for DICO = 'D'.\nC For optimum performance LDWORK should be larger.\nC\nC If LDWORK = -1, then a workspace query is assumed; the\nC routine only calculates the optimal size of the DWORK\nC array, returns this value as the first entry of the DWORK\nC array, and no error message related to LDWORK is issued by\nC XERBLA.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value;\nC > 0: if INFO = i, the QR algorithm failed to compute all\nC the eigenvalues (see LAPACK Library routine DGEES);\nC elements i+1:n of WR and WI contain eigenvalues\nC which have converged, and A contains the partially\nC converged Schur form;\nC = N+1: if DICO = 'C', and the matrices A and -A' have\nC common or very close eigenvalues, or\nC if DICO = 'D', and matrix A has almost reciprocal\nC eigenvalues (that is, lambda(i) = 1/lambda(j) for\nC some i and j, where lambda(i) and lambda(j) are\nC eigenvalues of A and i <> j); perturbed values were\nC used to solve the equation (but the matrix A is\nC unchanged).\nC\nC METHOD\nC\nC The Schur factorization of a square matrix A is given by\nC\nC A = U*S*U'\nC\nC where U is orthogonal and S is block upper triangular with 1-by-1\nC and 2-by-2 blocks on its diagonal, these blocks corresponding to\nC the eigenvalues of A, the 2-by-2 blocks being complex conjugate\nC pairs. This factorization is obtained by numerically stable\nC methods: first A is reduced to upper Hessenberg form (if FACT =\nC 'N') by means of Householder transformations and then the\nC QR Algorithm is applied to reduce the Hessenberg form to S, the\nC transformation matrices being accumulated at each step to give U.\nC If A has already been factorized prior to calling the routine\nC however, then the factors U and S may be supplied and the initial\nC factorization omitted.\nC _ _\nC If we now put C = U'CU and X = UXU' equations (1) and (2) (see\nC PURPOSE) become (for TRANS = 'N')\nC _ _ _\nC S'X + XS = C, (3)\nC and\nC _ _ _\nC S'XS - X = C, (4)\nC\nC respectively. Partition S, C and X as\nC _ _ _ _\nC (s s') (c c') (x x')\nC ( 11 ) _ ( 11 ) _ ( 11 )\nC S = ( ), C = ( ), X = ( )\nC ( ) ( _ ) ( _ )\nC ( 0 S ) ( c C ) ( x X )\nC 1 1 1\nC _ _\nC where s , c and x are either scalars or 2-by-2 matrices and s,\nC 11 11 11\nC _ _\nC c and x are either (N-1) element vectors or matrices with two\nC columns. Equations (3) and (4) can then be re-written as\nC _ _ _\nC s' x + x s = c (3.1)\nC 11 11 11 11 11\nC\nC _ _ _ _\nC S'x + xs = c - sx (3.2)\nC 1 11 11\nC\nC _ _\nC S'X + X S = C - (sx' + xs') (3.3)\nC 1 1 1 1 1\nC and\nC _ _ _\nC s' x s - x = c (4.1)\nC 11 11 11 11 11\nC\nC _ _ _ _\nC S'xs - x = c - sx s (4.2)\nC 1 11 11 11\nC\nC _ _ _\nC S'X S - X = C - sx s' - [s(S'x)' + (S'x)s'] (4.3)\nC 1 1 1 1 1 11 1 1\nC _\nC respectively. If DICO = 'C' ['D'], then once x has been\nC 11\nC found from equation (3.1) [(4.1)], equation (3.2) [(4.2)] can be\nC _\nC solved by forward substitution for x and then equation (3.3)\nC [(4.3)] is of the same form as (3) [(4)] but of the order (N-1) or\nC (N-2) depending upon whether s is 1-by-1 or 2-by-2.\nC 11\nC _ _\nC When s is 2-by-2 then x and c will be 1-by-2 matrices and s,\nC 11 11 11\nC _ _\nC x and c are matrices with two columns. In this case, equation\nC (3.1) [(4.1)] defines the three equations in the unknown elements\nC _\nC of x and equation (3.2) [(4.2)] can then be solved by forward\nC 11 _\nC substitution, a row of x being found at each step.\nC\nC REFERENCES\nC\nC [1] Barraud, A.Y. T\nC A numerical algorithm to solve A XA - X = Q.\nC IEEE Trans. Auto. Contr., AC-22, pp. 883-885, 1977.\nC\nC [2] Bartels, R.H. and Stewart, G.W. T\nC Solution of the matrix equation A X + XB = C.\nC Comm. A.C.M., 15, pp. 820-826, 1972.\nC\nC [3] Hammarling, S.J.\nC Numerical solution of the stable, non-negative definite\nC Lyapunov equation.\nC IMA J. Num. Anal., 2, pp. 303-325, 1982.\nC\nC NUMERICAL ASPECTS\nC 3\nC The algorithm requires 0(N ) operations and is backward stable.\nC\nC FURTHER COMMENTS\nC\nC If DICO = 'C', SEP is defined as the separation of op(A) and\nC -op(A)':\nC\nC sep( op(A), -op(A)' ) = sigma_min( T )\nC\nC and if DICO = 'D', SEP is defined as\nC\nC sep( op(A), op(A)' ) = sigma_min( T )\nC\nC where sigma_min(T) is the smallest singular value of the\nC N*N-by-N*N matrix\nC\nC T = kprod( I(N), op(A)' ) + kprod( op(A)', I(N) ) (DICO = 'C'),\nC\nC T = kprod( op(A)', op(A)' ) - I(N**2) (DICO = 'D').\nC\nC I(x) is an x-by-x identity matrix, and kprod denotes the Kronecker\nC product. The program estimates sigma_min(T) by the reciprocal of\nC an estimate of the 1-norm of inverse(T). The true reciprocal\nC 1-norm of inverse(T) cannot differ from sigma_min(T) by more\nC than a factor of N.\nC\nC When SEP is small, small changes in A, C can cause large changes\nC in the solution of the equation. An approximate bound on the\nC maximum relative error in the computed solution is\nC\nC EPS * norm(A) / SEP (DICO = 'C'),\nC\nC EPS * norm(A)**2 / SEP (DICO = 'D'),\nC\nC where EPS is the machine precision.\nC\nC CONTRIBUTOR\nC\nC Release 3.0: V. Sima, Katholieke Univ. Leuven, Belgium, July 1997.\nC Supersedes Release 2.0 routine SB03AD by Control Systems Research\nC Group, Kingston Polytechnic, United Kingdom.\nC\nC REVISIONS\nC\nC V. Sima, Katholieke Univ. Leuven, Belgium, May 1999.\nC V. Sima, Research Institute for Informatics, Bucharest, July 2011,\nC Dec. 2016, May 2020.\nC\nC KEYWORDS\nC\nC Lyapunov equation, orthogonal transformation, real Schur form,\nC Sylvester equation.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, ONE\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )\nC .. Scalar Arguments ..\n CHARACTER DICO, FACT, JOB, TRANA\n INTEGER INFO, LDA, LDC, LDU, LDWORK, N\n DOUBLE PRECISION FERR, SCALE, SEP\nC .. Array Arguments ..\n INTEGER IWORK( * )\n DOUBLE PRECISION A( LDA, * ), C( LDC, * ), DWORK( * ),\n $ U( LDU, * ), WI( * ), WR( * )\nC .. Local Scalars ..\n LOGICAL CONT, LQUERY, NOFACT, NOTA, WANTBH, WANTSP,\n $ WANTX\n CHARACTER NOTRA, NTRNST, TRANST, UPLO\n INTEGER I, IERR, KASE, LWA, MINWRK, NN, NN2, SDIM\n DOUBLE PRECISION EPS, EST, SCALEF\nC .. Local Arrays ..\n LOGICAL BWORK( 1 )\n INTEGER ISAVE( 3 )\nC .. External Functions ..\n LOGICAL LSAME, SELECT\n DOUBLE PRECISION DLAMCH, DLANHS\n EXTERNAL DLAMCH, DLANHS, LSAME, SELECT\nC .. External Subroutines ..\n EXTERNAL DCOPY, DGEES, DLACN2, MB01RD, SB03MX, SB03MY,\n $ XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC DBLE, INT, MAX\nC .. Executable Statements ..\nC\nC Decode and Test input parameters.\nC\n CONT = LSAME( DICO, 'C' )\n WANTX = LSAME( JOB, 'X' )\n WANTSP = LSAME( JOB, 'S' )\n WANTBH = LSAME( JOB, 'B' )\n NOFACT = LSAME( FACT, 'N' )\n NOTA = LSAME( TRANA, 'N' )\n LQUERY = LDWORK.EQ.-1\n NN = N*N\n NN2 = 2*NN\nC\n INFO = 0\n IF( .NOT.CONT .AND. .NOT.LSAME( DICO, 'D' ) ) THEN\n INFO = -1\n ELSE IF( .NOT.WANTBH .AND. .NOT.WANTSP .AND. .NOT.WANTX ) THEN\n INFO = -2\n ELSE IF( .NOT.NOFACT .AND. .NOT.LSAME( FACT, 'F' ) ) THEN\n INFO = -3\n ELSE IF( .NOT.NOTA .AND. .NOT.LSAME( TRANA, 'T' ) .AND.\n $ .NOT.LSAME( TRANA, 'C' ) ) THEN\n INFO = -4\n ELSE IF( N.LT.0 ) THEN\n INFO = -5\n ELSE IF( LDA.LT.MAX( 1, N ) ) THEN\n INFO = -7\n ELSE IF( LDU.LT.MAX( 1, N ) ) THEN\n INFO = -9\n ELSE IF( WANTSP .AND. LDC.LT.1 .OR.\n $ .NOT.WANTSP .AND. LDC.LT.MAX( 1, N ) ) THEN\n INFO = -11\n ELSE\n IF ( WANTX ) THEN\n IF ( NOFACT ) THEN\n MINWRK = MAX( NN, 3*N )\n ELSE IF ( CONT ) THEN\n MINWRK = NN\n ELSE\n MINWRK = MAX( NN, 2*N )\n END IF\n ELSE\n IF ( CONT ) THEN\n IF ( NOFACT ) THEN\n MINWRK = MAX( NN2, 3*N )\n ELSE\n MINWRK = NN2\n END IF\n ELSE\n MINWRK = NN2 + 2*N\n END IF\n END IF\n MINWRK = MAX( 1, MINWRK )\n IF( LQUERY ) THEN\n IF( NOFACT ) THEN\n CALL DGEES( 'Vectors', 'Not ordered', SELECT, N, A, LDA,\n $ SDIM, WR, WI, U, LDU, DWORK, -1, BWORK,\n $ INFO )\n LWA = MAX( MINWRK, INT( DWORK( 1 ) ) )\n ELSE\n LWA = MINWRK\n END IF\n ELSE IF( LDWORK.LT.MINWRK ) THEN\n INFO = -19\n END IF\n END IF\nC\n IF ( INFO.NE.0 ) THEN\nC\nC Error return.\nC\n CALL XERBLA( 'SB03MD', -INFO )\n RETURN\n ELSE IF( LQUERY ) THEN\n DWORK(1) = LWA\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF( N.EQ.0 ) THEN\n SCALE = ONE\n IF( .NOT.WANTX )\n $ SEP = ZERO\n IF( WANTBH )\n $ FERR = ZERO\n DWORK(1) = ONE\n RETURN\n END IF\nC\n LWA = 0\nC\n IF( NOFACT ) THEN\nC\nC Compute the Schur factorization of A.\nC Workspace: need 3*N;\nC prefer larger.\nC (Note: Comments in the code beginning \"Workspace:\" describe the\nC minimal amount of real workspace needed at that point in the\nC code, as well as the preferred amount for good performance.\nC NB refers to the optimal block size for the immediately\nC following subroutine, as returned by ILAENV.)\nC\n CALL DGEES( 'Vectors', 'Not ordered', SELECT, N, A, LDA, SDIM,\n $ WR, WI, U, LDU, DWORK, LDWORK, BWORK, INFO )\n IF( INFO.GT.0 )\n $ RETURN\n LWA = INT( DWORK( 1 ) )\n END IF\nC\n IF( .NOT.WANTSP ) THEN\nC\nC Transform the right-hand side.\nC Workspace: N*N.\nC\n NTRNST = 'N'\n TRANST = 'T'\n UPLO = 'U'\n CALL MB01RD( UPLO, TRANST, N, N, ZERO, ONE, C, LDC, U, LDU, C,\n $ LDC, DWORK, LDWORK, INFO )\nC\n DO 10 I = 2, N\n CALL DCOPY( I-1, C(1,I), 1, C(I,1), LDC )\n 10 CONTINUE\nC\n LWA = MAX( LWA, NN )\nC\nC Solve the transformed equation.\nC Workspace for DICO = 'D': 2*N.\nC\n IF ( CONT ) THEN\n CALL SB03MY( TRANA, N, A, LDA, C, LDC, SCALE, INFO )\n ELSE\n CALL SB03MX( TRANA, N, A, LDA, C, LDC, SCALE, DWORK, INFO )\n END IF\n IF( INFO.GT.0 )\n $ INFO = N + 1\nC\nC Transform back the solution.\nC Workspace: N*N.\nC\n CALL MB01RD( UPLO, NTRNST, N, N, ZERO, ONE, C, LDC, U, LDU, C,\n $ LDC, DWORK, LDWORK, IERR )\nC\n DO 20 I = 2, N\n CALL DCOPY( I-1, C(1,I), 1, C(I,1), LDC )\n 20 CONTINUE\nC\n END IF\nC\n IF( .NOT.WANTX ) THEN\nC\nC Estimate the separation.\nC Workspace: 2*N*N for DICO = 'C';\nC 2*N*N + 2*N for DICO = 'D'.\nC\n IF( NOTA ) THEN\n NOTRA = 'T'\n ELSE\n NOTRA = 'N'\n END IF\nC\n EST = ZERO\n KASE = 0\nC REPEAT\n 30 CONTINUE\n CALL DLACN2( NN, DWORK(NN+1), DWORK, IWORK, EST, KASE, ISAVE )\n IF( KASE.NE.0 ) THEN\n IF( KASE.EQ.1 ) THEN\n IF( CONT ) THEN\n CALL SB03MY( TRANA, N, A, LDA, DWORK, N, SCALEF,\n $ IERR )\n ELSE\n CALL SB03MX( TRANA, N, A, LDA, DWORK, N, SCALEF,\n $ DWORK(NN2+1), IERR )\n END IF\n ELSE\n IF( CONT ) THEN\n CALL SB03MY( NOTRA, N, A, LDA, DWORK, N, SCALEF,\n $ IERR )\n ELSE\n CALL SB03MX( NOTRA, N, A, LDA, DWORK, N, SCALEF,\n $ DWORK(NN2+1), IERR )\n END IF\n END IF\n GO TO 30\n END IF\nC UNTIL KASE = 0\nC\n SEP = SCALEF / EST\nC\n IF( WANTBH ) THEN\nC\nC Get the machine precision.\nC\n EPS = DLAMCH( 'P' )\nC\nC Compute the estimate of the relative error.\nC\n IF ( CONT ) THEN\n FERR = EPS*DLANHS( 'Frobenius', N, A, LDA, DWORK )/SEP\n ELSE\n FERR = EPS*DLANHS( 'Frobenius', N, A, LDA, DWORK )**2/SEP\n END IF\n END IF\n END IF\nC\n DWORK( 1 ) = DBLE( MAX( LWA, MINWRK ) )\n RETURN\nC *** Last line of SB03MD ***\n END\n", "meta": {"hexsha": "4c84e0137668c175f97f2b87e23a1518feccf9c8", "size": 21150, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/SB03MD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/SB03MD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/SB03MD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 37.1052631579, "max_line_length": 72, "alphanum_fraction": 0.4918676123, "num_tokens": 6247, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9294403979493139, "lm_q2_score": 0.7154239957834733, "lm_q1q2_score": 0.6649439633434796}} {"text": " SUBROUTINE SB03SD( JOB, FACT, TRANA, UPLO, LYAPUN, N, SCALE, A,\n $ LDA, T, LDT, U, LDU, C, LDC, X, LDX, SEPD,\n $ RCOND, FERR, IWORK, DWORK, LDWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To estimate the conditioning and compute an error bound on the\nC solution of the real discrete-time Lyapunov matrix equation\nC\nC op(A)'*X*op(A) - X = scale*C\nC\nC where op(A) = A or A' (A**T) and C is symmetric (C = C**T). The\nC matrix A is N-by-N, the right hand side C and the solution X are\nC N-by-N symmetric matrices, and scale is a given scale factor.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC JOB CHARACTER*1\nC Specifies the computation to be performed, as follows:\nC = 'C': Compute the reciprocal condition number only;\nC = 'E': Compute the error bound only;\nC = 'B': Compute both the reciprocal condition number and\nC the error bound.\nC\nC FACT CHARACTER*1\nC Specifies whether or not the real Schur factorization\nC of the matrix A is supplied on entry, as follows:\nC = 'F': On entry, T and U (if LYAPUN = 'O') contain the\nC factors from the real Schur factorization of the\nC matrix A;\nC = 'N': The Schur factorization of A will be computed\nC and the factors will be stored in T and U (if\nC LYAPUN = 'O').\nC\nC TRANA CHARACTER*1\nC Specifies the form of op(A) to be used, as follows:\nC = 'N': op(A) = A (No transpose);\nC = 'T': op(A) = A**T (Transpose);\nC = 'C': op(A) = A**T (Conjugate transpose = Transpose).\nC\nC UPLO CHARACTER*1\nC Specifies which part of the symmetric matrix C is to be\nC used, as follows:\nC = 'U': Upper triangular part;\nC = 'L': Lower triangular part.\nC\nC LYAPUN CHARACTER*1\nC Specifies whether or not the original Lyapunov equations\nC should be solved in the iterative estimation process,\nC as follows:\nC = 'O': Solve the original Lyapunov equations, updating\nC the right-hand sides and solutions with the\nC matrix U, e.g., X <-- U'*X*U;\nC = 'R': Solve reduced Lyapunov equations only, without\nC updating the right-hand sides and solutions.\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The order of the matrices A, X and C. N >= 0.\nC\nC SCALE (input) DOUBLE PRECISION\nC The scale factor, scale, set by a Lyapunov solver.\nC 0 <= SCALE <= 1.\nC\nC A (input) DOUBLE PRECISION array, dimension (LDA,N)\nC If FACT = 'N' or LYAPUN = 'O', the leading N-by-N part of\nC this array must contain the original matrix A.\nC If FACT = 'F' and LYAPUN = 'R', A is not referenced.\nC\nC LDA INTEGER\nC The leading dimension of the array A.\nC LDA >= MAX(1,N), if FACT = 'N' or LYAPUN = 'O';\nC LDA >= 1, if FACT = 'F' and LYAPUN = 'R'.\nC\nC T (input/output) DOUBLE PRECISION array, dimension\nC (LDT,N)\nC If FACT = 'F', then on entry the leading N-by-N upper\nC Hessenberg part of this array must contain the upper\nC quasi-triangular matrix T in Schur canonical form from a\nC Schur factorization of A.\nC If FACT = 'N', then this array need not be set on input.\nC On exit, (if INFO = 0 or INFO = N+1, for FACT = 'N') the\nC leading N-by-N upper Hessenberg part of this array\nC contains the upper quasi-triangular matrix T in Schur\nC canonical form from a Schur factorization of A.\nC\nC LDT INTEGER\nC The leading dimension of the array T. LDT >= MAX(1,N).\nC\nC U (input or output) DOUBLE PRECISION array, dimension\nC (LDU,N)\nC If LYAPUN = 'O' and FACT = 'F', then U is an input\nC argument and on entry, the leading N-by-N part of this\nC array must contain the orthogonal matrix U from a real\nC Schur factorization of A.\nC If LYAPUN = 'O' and FACT = 'N', then U is an output\nC argument and on exit, if INFO = 0 or INFO = N+1, it\nC contains the orthogonal N-by-N matrix from a real Schur\nC factorization of A.\nC If LYAPUN = 'R', the array U is not referenced.\nC\nC LDU INTEGER\nC The leading dimension of the array U.\nC LDU >= 1, if LYAPUN = 'R';\nC LDU >= MAX(1,N), if LYAPUN = 'O'.\nC\nC C (input) DOUBLE PRECISION array, dimension (LDC,N)\nC If UPLO = 'U', the leading N-by-N upper triangular part of\nC this array must contain the upper triangular part of the\nC matrix C of the original Lyapunov equation (with\nC matrix A), if LYAPUN = 'O', or of the reduced Lyapunov\nC equation (with matrix T), if LYAPUN = 'R'.\nC If UPLO = 'L', the leading N-by-N lower triangular part of\nC this array must contain the lower triangular part of the\nC matrix C of the original Lyapunov equation (with\nC matrix A), if LYAPUN = 'O', or of the reduced Lyapunov\nC equation (with matrix T), if LYAPUN = 'R'.\nC\nC LDC INTEGER\nC The leading dimension of the array C. LDC >= MAX(1,N).\nC\nC X (input) DOUBLE PRECISION array, dimension (LDX,N)\nC The leading N-by-N part of this array must contain the\nC symmetric solution matrix X of the original Lyapunov\nC equation (with matrix A), if LYAPUN = 'O', or of the\nC reduced Lyapunov equation (with matrix T), if\nC LYAPUN = 'R'.\nC The array X is modified internally, but restored on exit.\nC\nC LDX INTEGER\nC The leading dimension of the array X. LDX >= MAX(1,N).\nC\nC SEPD (output) DOUBLE PRECISION\nC If JOB = 'C' or JOB = 'B', the estimated quantity\nC sepd(op(A),op(A)').\nC If N = 0, or X = 0, or JOB = 'E', SEPD is not referenced.\nC\nC RCOND (output) DOUBLE PRECISION\nC If JOB = 'C' or JOB = 'B', an estimate of the reciprocal\nC condition number of the discrete-time Lyapunov equation.\nC If N = 0 or X = 0, RCOND is set to 1 or 0, respectively.\nC If JOB = 'E', RCOND is not referenced.\nC\nC FERR (output) DOUBLE PRECISION\nC If JOB = 'E' or JOB = 'B', an estimated forward error\nC bound for the solution X. If XTRUE is the true solution,\nC FERR bounds the magnitude of the largest entry in\nC (X - XTRUE) divided by the magnitude of the largest entry\nC in X.\nC If N = 0 or X = 0, FERR is set to 0.\nC If JOB = 'C', FERR is not referenced.\nC\nC Workspace\nC\nC IWORK INTEGER array, dimension (N*N)\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0 or INFO = N+1, DWORK(1) returns the\nC optimal value of LDWORK.\nC\nC LDWORK INTEGER\nC The dimension of the array DWORK.\nC LDWORK >= 1, if N = 0; else,\nC LDWORK >= MAX(3,2*N*N) + N*N, if JOB = 'C',\nC FACT = 'F';\nC LDWORK >= MAX(MAX(3,2*N*N) + N*N, 5*N), if JOB = 'C',\nC FACT = 'N';\nC LDWORK >= MAX(3,2*N*N) + N*N + 2*N, if JOB = 'E', or\nC JOB = 'B'.\nC For optimum performance LDWORK should sometimes be larger.\nC\nC If LDWORK = -1, then a workspace query is assumed;\nC the routine only calculates the optimal size of the\nC DWORK array, returns this value as the first entry of\nC the DWORK array, and no error message related to LDWORK\nC is issued by XERBLA.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value;\nC > 0: if INFO = i, i <= N, the QR algorithm failed to\nC complete the reduction to Schur canonical form (see\nC LAPACK Library routine DGEES); on exit, the matrix\nC T(i+1:N,i+1:N) contains the partially converged\nC Schur form, and DWORK(i+1:N) and DWORK(N+i+1:2*N)\nC contain the real and imaginary parts, respectively,\nC of the converged eigenvalues; this error is unlikely\nC to appear;\nC = N+1: if the matrix T has almost reciprocal eigenvalues;\nC perturbed values were used to solve Lyapunov\nC equations, but the matrix T, if given (for\nC FACT = 'F'), is unchanged.\nC\nC METHOD\nC\nC The condition number of the discrete-time Lyapunov equation is\nC estimated as\nC\nC cond = (norm(Theta)*norm(A) + norm(inv(Omega))*norm(C))/norm(X),\nC\nC where Omega and Theta are linear operators defined by\nC\nC Omega(W) = op(A)'*W*op(A) - W,\nC Theta(W) = inv(Omega(op(W)'*X*op(A) + op(A)'*X*op(W))).\nC\nC The routine estimates the quantities\nC\nC sepd(op(A),op(A)') = 1 / norm(inv(Omega))\nC\nC and norm(Theta) using 1-norm condition estimators.\nC\nC The forward error bound is estimated using a practical error bound\nC similar to the one proposed in [1].\nC\nC REFERENCES\nC\nC [1] Higham, N.J.\nC Perturbation theory and backward error for AX-XB=C.\nC BIT, vol. 33, pp. 124-136, 1993.\nC\nC NUMERICAL ASPECTS\nC 3\nC The algorithm requires 0(N ) operations.\nC The accuracy of the estimates obtained depends on the solution\nC accuracy and on the properties of the 1-norm estimator.\nC\nC FURTHER COMMENTS\nC\nC The option LYAPUN = 'R' may occasionally produce slightly worse\nC or better estimates, and it is much faster than the option 'O'.\nC When SEPD is computed and it is zero, the routine returns\nC immediately, with RCOND and FERR (if requested) set to 0 and 1,\nC respectively. In this case, the equation is singular.\nC\nC CONTRIBUTORS\nC\nC P. Petkov, Tech. University of Sofia, December 1998.\nC V. Sima, Katholieke Univ. Leuven, Belgium, February 1999.\nC\nC REVISIONS\nC\nC V. Sima, Katholieke Univ. Leuven, Belgium, March 2003, July 2012.\nC\nC KEYWORDS\nC\nC Lyapunov equation, orthogonal transformation, real Schur form.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, ONE, THREE\n PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0, THREE = 3.0D0 )\nC ..\nC .. Scalar Arguments ..\n CHARACTER FACT, JOB, LYAPUN, TRANA, UPLO\n INTEGER INFO, LDA, LDC, LDT, LDU, LDWORK, LDX, N\n DOUBLE PRECISION FERR, RCOND, SCALE, SEPD\nC ..\nC .. Array Arguments ..\n INTEGER IWORK( * )\n DOUBLE PRECISION A( LDA, * ), C( LDC, * ), DWORK( * ),\n $ T( LDT, * ), U( LDU, * ), X( LDX, * )\nC ..\nC .. Local Scalars ..\n LOGICAL JOBB, JOBC, JOBE, LOWER, LQUERY, NOFACT,\n $ NOTRNA, UPDATE\n CHARACTER SJOB, TRANAT\n INTEGER I, IABS, IRES, IWRK, IXMA, J, LDW, NN, SDIM,\n $ WRKOPT\n DOUBLE PRECISION ANORM, CNORM, DENOM, EPS, EPSN, TEMP, THNORM,\n $ TMAX, XANORM, XNORM\nC ..\nC .. Local Arrays ..\n LOGICAL BWORK( 1 )\nC ..\nC .. External Functions ..\n LOGICAL LSAME, SELECT\n DOUBLE PRECISION DLAMCH, DLANGE, DLANHS, DLANSY\n EXTERNAL DLAMCH, DLANGE, DLANHS, DLANSY, LSAME, SELECT\nC ..\nC .. External Subroutines ..\n EXTERNAL DAXPY, DCOPY, DGEES, DGEMM, DLACPY, DLASET,\n $ MA02ED, MB01RU, MB01RX, MB01RY, MB01UD, SB03SX,\n $ SB03SY, XERBLA\nC ..\nC .. Intrinsic Functions ..\n INTRINSIC ABS, DBLE, INT, MAX, MIN\nC ..\nC .. Executable Statements ..\nC\nC Decode and Test input parameters.\nC\n JOBC = LSAME( JOB, 'C' )\n JOBE = LSAME( JOB, 'E' )\n JOBB = LSAME( JOB, 'B' )\n NOFACT = LSAME( FACT, 'N' )\n NOTRNA = LSAME( TRANA, 'N' )\n LOWER = LSAME( UPLO, 'L' )\n UPDATE = LSAME( LYAPUN, 'O' )\nC\n NN = N*N\n LDW = MAX( 3, 2*NN ) + NN\nC\n INFO = 0\n IF( .NOT.( JOBB .OR. JOBC .OR. JOBE ) ) THEN\n INFO = -1\n ELSE IF( .NOT.( NOFACT .OR. LSAME( FACT, 'F' ) ) ) THEN\n INFO = -2\n ELSE IF( .NOT.( NOTRNA .OR. LSAME( TRANA, 'T' ) .OR.\n $ LSAME( TRANA, 'C' ) ) ) THEN\n INFO = -3\n ELSE IF( .NOT.( LOWER .OR. LSAME( UPLO, 'U' ) ) ) THEN\n INFO = -4\n ELSE IF( .NOT.( UPDATE .OR. LSAME( LYAPUN, 'R' ) ) ) THEN\n INFO = -5\n ELSE IF( N.LT.0 ) THEN\n INFO = -6\n ELSE IF( SCALE.LT.ZERO .OR. SCALE.GT.ONE ) THEN\n INFO = -7\n ELSE IF( LDA.LT.1 .OR.\n $ ( LDA.LT.N .AND. ( UPDATE .OR. NOFACT ) ) ) THEN\n INFO = -9\n ELSE IF( LDT.LT.MAX( 1, N ) ) THEN\n INFO = -11\n ELSE IF( LDU.LT.1 .OR. ( LDU.LT.N .AND. UPDATE ) ) THEN\n INFO = -13\n ELSE IF( LDC.LT.MAX( 1, N ) ) THEN\n INFO = -15\n ELSE IF( LDX.LT.MAX( 1, N ) ) THEN\n INFO = -17\n ELSE\n IF( JOBC ) THEN\n IF( NOFACT ) THEN\n IWRK = MAX( LDW, 5*N )\n ELSE\n IWRK = LDW\n END IF\n ELSE\n IWRK = LDW + 2*N\n END IF\n IWRK = MAX( 1, IWRK )\n LQUERY = LDWORK.EQ.-1\n IF( NOFACT ) THEN\n IF( UPDATE ) THEN\n SJOB = 'V'\n ELSE\n SJOB = 'N'\n END IF\n END IF\n IF( LQUERY ) THEN\n IF( NOFACT ) THEN\n CALL DGEES( SJOB, 'Not ordered', SELECT, N, T, LDT, SDIM,\n $ DWORK, DWORK, U, LDU, DWORK, -1, BWORK,\n $ INFO )\n WRKOPT = MAX( IWRK, INT( DWORK( 1 ) ) + 2*N )\n ELSE\n WRKOPT = IWRK\n END IF\n END IF\n IF( LDWORK.LT.IWRK .AND. .NOT. LQUERY )\n $ INFO = -23\n END IF\nC\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'SB03SD', -INFO )\n RETURN\n ELSE IF( LQUERY ) THEN\n DWORK( 1 ) = WRKOPT\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF( N.EQ.0 ) THEN\n IF( .NOT.JOBE )\n $ RCOND = ONE\n IF( .NOT.JOBC )\n $ FERR = ZERO\n DWORK( 1 ) = ONE\n RETURN\n END IF\nC\nC Compute the 1-norm of the matrix X.\nC\n XNORM = DLANSY( '1-norm', UPLO, N, X, LDX, DWORK )\n IF( XNORM.EQ.ZERO ) THEN\nC\nC The solution is zero.\nC\n IF( .NOT.JOBE )\n $ RCOND = ZERO\n IF( .NOT.JOBC )\n $ FERR = ZERO\n DWORK( 1 ) = DBLE( N )\n RETURN\n END IF\nC\nC Compute the 1-norm of A or T.\nC\n IF( NOFACT .OR. UPDATE ) THEN\n ANORM = DLANGE( '1-norm', N, N, A, LDA, DWORK )\n ELSE\n ANORM = DLANHS( '1-norm', N, T, LDT, DWORK )\n END IF\nC\nC For the special case A = I, set SEPD and RCOND to 0.\nC For the special case A = 0, set SEPD and RCOND to 1.\nC A quick test is used in general.\nC\n IF( ANORM.EQ.ONE ) THEN\n IF( NOFACT .OR. UPDATE ) THEN\n CALL DLACPY( 'Full', N, N, A, LDA, DWORK, N )\n ELSE\n CALL DLACPY( 'Full', N, N, T, LDT, DWORK, N )\n IF( N.GT.2 )\n $ CALL DLASET( 'Lower', N-2, N-2, ZERO, ZERO, DWORK( 3 ),\n $ N )\n END IF\n DWORK( NN+1 ) = ONE\n CALL DAXPY( N, -ONE, DWORK( NN+1 ), 0, DWORK, N+1 )\n IF( DLANGE( 'Max', N, N, DWORK, N, DWORK ).EQ.ZERO ) THEN\n IF( .NOT.JOBE ) THEN\n SEPD = ZERO\n RCOND = ZERO\n END IF\n IF( .NOT.JOBC )\n $ FERR = ONE\n DWORK( 1 ) = DBLE( NN + 1 )\n RETURN\n END IF\nC\n ELSE IF( ANORM.EQ.ZERO ) THEN\n IF( .NOT.JOBE ) THEN\n SEPD = ONE\n RCOND = ONE\n END IF\n IF( JOBC ) THEN\n DWORK( 1 ) = DBLE( N )\n RETURN\n ELSE\nC\nC Set FERR for the special case A = 0.\nC\n CALL DLACPY( UPLO, N, N, X, LDX, DWORK, N )\nC\n IF( LOWER ) THEN\n DO 10 J = 1, N\n CALL DAXPY( N-J+1, SCALE, C( J, J ), 1,\n $ DWORK( (J-1)*N+J ), 1 )\n 10 CONTINUE\n ELSE\n DO 20 J = 1, N\n CALL DAXPY( J, SCALE, C( 1, J ), 1,\n $ DWORK( (J-1)*N+1 ), 1 )\n 20 CONTINUE\n END IF\nC\n FERR = MIN( ONE, DLANSY( '1-norm', UPLO, N, DWORK, N,\n $ DWORK( NN+1 ) ) / XNORM )\n DWORK( 1 ) = DBLE( NN + N )\n RETURN\n END IF\n END IF\nC\nC General case.\nC\n CNORM = DLANSY( '1-norm', UPLO, N, C, LDC, DWORK )\nC\nC Workspace usage.\nC\n IABS = NN\n IXMA = MAX( 3, 2*NN )\n IRES = IXMA\n IWRK = IXMA + NN\n WRKOPT = 0\nC\n IF( NOFACT ) THEN\nC\nC Compute the Schur factorization of A, A = U*T*U'.\nC Workspace: need 5*N;\nC prefer larger.\nC (Note: Comments in the code beginning \"Workspace:\" describe the\nC minimal amount of real workspace needed at that point in the\nC code, as well as the preferred amount for good performance.)\nC\n CALL DLACPY( 'Full', N, N, A, LDA, T, LDT )\n CALL DGEES( SJOB, 'Not ordered', SELECT, N, T, LDT, SDIM,\n $ DWORK( 1 ), DWORK( N+1 ), U, LDU, DWORK( 2*N+1 ),\n $ LDWORK-2*N, BWORK, INFO )\n IF( INFO.GT.0 )\n $ RETURN\n WRKOPT = INT( DWORK( 2*N+1 ) ) + 2*N\n END IF\nC\nC Compute X*op(A) or X*op(T).\nC\n IF( UPDATE ) THEN\n CALL DGEMM( 'NoTranspose', TRANA, N, N, N, ONE, X, LDX, A, LDA,\n $ ZERO, DWORK( IXMA+1 ), N )\n ELSE\n CALL MB01UD( 'Right', TRANA, N, N, ONE, T, LDT, X, LDX,\n $ DWORK( IXMA+1 ), N, INFO )\n END IF\nC\n IF( .NOT.JOBE ) THEN\nC\nC Estimate sepd(op(A),op(A)') = sepd(op(T),op(T)') and\nC norm(Theta).\nC Workspace max(3,2*N*N) + N*N.\nC\n CALL SB03SY( 'Both', TRANA, LYAPUN, N, T, LDT, U, LDU,\n $ DWORK( IXMA+1 ), N, SEPD, THNORM, IWORK, DWORK,\n $ IXMA, INFO )\nC\n WRKOPT = MAX( WRKOPT, MAX( 3, 2*NN ) + NN )\nC\nC Return if the equation is singular.\nC\n IF( SEPD.EQ.ZERO ) THEN\n RCOND = ZERO\n IF( JOBB )\n $ FERR = ONE\n DWORK( 1 ) = DBLE( WRKOPT )\n RETURN\n END IF\nC\nC Estimate the reciprocal condition number.\nC\n TMAX = MAX( SEPD, XNORM, ANORM )\n IF( TMAX.LE.ONE ) THEN\n TEMP = SEPD*XNORM\n DENOM = ( SCALE*CNORM ) + ( SEPD*ANORM )*THNORM\n ELSE\n TEMP = ( SEPD / TMAX )*( XNORM / TMAX )\n DENOM = ( ( SCALE / TMAX )*( CNORM / TMAX ) ) +\n $ ( ( SEPD / TMAX )*( ANORM / TMAX ) )*THNORM\n END IF\n IF( TEMP.GE.DENOM ) THEN\n RCOND = ONE\n ELSE\n RCOND = TEMP / DENOM\n END IF\n END IF\nC\n IF( .NOT.JOBC ) THEN\nC\nC Form a triangle of the residual matrix\nC R = scale*C + X - op(A)'*X*op(A), or\nC R = scale*C + X - op(T)'*X*op(T),\nC exploiting the symmetry. For memory savings, R is formed in the\nC leading N-by-N upper/lower triangular part of DWORK, and it is\nC finally moved in the location where X*op(A) or X*op(T) was\nC stored, freeing workspace for the SB03SX call.\nC\n IF( NOTRNA ) THEN\n TRANAT = 'T'\n ELSE\n TRANAT = 'N'\n END IF\nC\n CALL DLACPY( UPLO, N, N, C, LDC, DWORK, N )\nC\n IF( UPDATE ) THEN\n CALL MB01RX( 'Left', UPLO, TRANAT, N, N, SCALE, -ONE, DWORK,\n $ N, A, LDA, DWORK( IXMA+1 ), N, INFO )\n ELSE\n CALL MB01RY( 'Left', UPLO, TRANAT, N, SCALE, -ONE, DWORK, N,\n $ T, LDT, DWORK( IXMA+1 ), N, DWORK( IWRK+1 ),\n $ INFO )\n END IF\nC\n IF( LOWER ) THEN\n DO 30 J = 1, N\n CALL DAXPY( N-J+1, ONE, X( J, J ), 1, DWORK( (J-1)*N+J ),\n $ 1 )\n 30 CONTINUE\n ELSE\n DO 40 J = 1, N\n CALL DAXPY( J, ONE, X( 1, J ), 1, DWORK( (J-1)*N+1 ), 1 )\n 40 CONTINUE\n END IF\nC\n CALL DLACPY( UPLO, N, N, DWORK, N, DWORK( IRES+1 ), N )\nC\nC Get the machine precision.\nC\n EPS = DLAMCH( 'Epsilon' )\n EPSN = EPS*DBLE( 2*N + 2 )\nC\nC Add to abs(R) a term that takes account of rounding errors in\nC forming R:\nC abs(R) := abs(R) + EPS*(3*scale*abs(C) + 3*abs(X) +\nC 2*(n+1)*abs(op(A))'*abs(X)*abs(op(A))), or\nC abs(R) := abs(R) + EPS*(3*scale*abs(C) + 3*abs(X) +\nC 2*(n+1)*abs(op(T))'*abs(X)*abs(op(T))),\nC where EPS is the machine precision.\nC Workspace max(3,2*N*N) + N*N + 2*N.\nC Note that the lower or upper triangular part of X specified by\nC UPLO is used as workspace, but it is finally restored.\nC\n IF( UPDATE ) THEN\n DO 60 J = 1, N\n DO 50 I = 1, N\n DWORK( IABS+(J-1)*N+I ) = ABS( A( I, J ) )\n 50 CONTINUE\n 60 CONTINUE\n ELSE\n DO 80 J = 1, N\n DO 70 I = 1, MIN( J+1, N )\n DWORK( IABS+(J-1)*N+I ) = ABS( T( I, J ) )\n 70 CONTINUE\n 80 CONTINUE\n END IF\nC\n CALL DCOPY( N, X, LDX+1, DWORK( IWRK+1 ), 1 )\nC\n IF( LOWER ) THEN\n DO 100 J = 1, N\n DO 90 I = J, N\n TEMP = ABS( X( I, J ) )\n X( I, J ) = TEMP\n DWORK( IRES+(J-1)*N+I ) =\n $ ABS( DWORK( IRES+(J-1)*N+I ) ) +\n $ EPS*THREE*( SCALE*ABS( C( I, J ) ) + TEMP )\n 90 CONTINUE\n 100 CONTINUE\n ELSE\n DO 120 J = 1, N\n DO 110 I = 1, J\n TEMP = ABS( X( I, J ) )\n X( I, J ) = TEMP\n DWORK( IRES+(J-1)*N+I ) =\n $ ABS( DWORK( IRES+(J-1)*N+I ) ) +\n $ EPS*THREE*( SCALE*ABS( C( I, J ) ) + TEMP )\n 110 CONTINUE\n 120 CONTINUE\n END IF\nC\n IF( UPDATE ) THEN\n CALL MB01RU( UPLO, TRANAT, N, N, ONE, EPSN, DWORK( IRES+1 ),\n $ N, DWORK( IABS+1 ), N, X, LDX, DWORK, NN,\n $ INFO )\n ELSE\nC\nC Compute W = abs(X)*abs(op(T)), and then premultiply by\nC abs(T)' and add in the result.\nC\n CALL MB01UD( 'Right', TRANA, N, N, ONE, DWORK( IABS+1 ), N,\n $ X, LDX, DWORK, N, INFO )\n CALL MB01RY( 'Left', UPLO, TRANAT, N, ONE, EPSN,\n $ DWORK( IRES+1 ), N, DWORK( IABS+1 ), N, DWORK,\n $ N, DWORK( IWRK+N+1 ), INFO )\n END IF\nC\n WRKOPT = MAX( WRKOPT, MAX( 3, 2*NN ) + NN + 2*N )\nC\nC Restore X.\nC\n CALL DCOPY( N, DWORK( IWRK+1 ), 1, X, LDX+1 )\n IF( LOWER ) THEN\n CALL MA02ED( 'Upper', N, X, LDX )\n ELSE\n CALL MA02ED( 'Lower', N, X, LDX )\n END IF\nC\nC Compute forward error bound, using matrix norm estimator.\nC Workspace max(3,2*N*N) + N*N.\nC\n XANORM = DLANSY( 'Max', UPLO, N, X, LDX, DWORK )\nC\n CALL SB03SX( TRANA, UPLO, LYAPUN, N, XANORM, T, LDT, U, LDU,\n $ DWORK( IRES+1 ), N, FERR, IWORK, DWORK, IRES,\n $ INFO )\n END IF\nC\n DWORK( 1 ) = DBLE( WRKOPT )\n RETURN\nC\nC *** Last line of SB03SD ***\n END\n", "meta": {"hexsha": "97cd379b2bf66f3e0605e38a546601b12a639635", "size": 24700, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/SB03SD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/SB03SD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/SB03SD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 35.7452966715, "max_line_length": 72, "alphanum_fraction": 0.4910526316, "num_tokens": 7674, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9294403979493139, "lm_q2_score": 0.7154239836484143, "lm_q1q2_score": 0.6649439520646656}} {"text": " FUNCTION rtnewt(funcd,x1,x2,xacc)\r\n INTEGER JMAX\r\n REAL rtnewt,x1,x2,xacc\r\n EXTERNAL funcd\r\n PARAMETER (JMAX=20)\r\n INTEGER j\r\n REAL df,dx,f\r\n rtnewt=.5*(x1+x2)\r\n do 11 j=1,JMAX\r\n call funcd(rtnewt,f,df)\r\n dx=f/df\r\n rtnewt=rtnewt-dx\r\n if((x1-rtnewt)*(rtnewt-x2).lt.0.)pause\r\n *'rtnewt jumped out of brackets'\r\n if(abs(dx).lt.xacc) return\r\n11 continue\r\n pause 'rtnewt exceeded maximum iterations'\r\n END\r\n", "meta": {"hexsha": "144506e03b7d95ce9a0cf5d379766df646b2afab", "size": 500, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/rtnewt.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/rtnewt.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/rtnewt.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": 26.3157894737, "max_line_length": 49, "alphanum_fraction": 0.556, "num_tokens": 168, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951182587158, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.6649312937292526}} {"text": "! Program to test the UNPACK intrinsic\nprogram intrinsic_unpack\n integer, dimension(3, 3) :: a, b\n logical, dimension(3, 3) :: mask;\n character(len=50) line1, line2\n integer i\n\n mask = reshape ((/.false.,.true.,.false.,.true.,.false.,.false.,&\n &.false.,.false.,.true./), (/3, 3/));\n a = reshape ((/1, 0, 0, 0, 1, 0, 0, 0, 1/), (/3, 3/));\n b = unpack ((/2, 3, 4/), mask, a)\n if (any (b .ne. reshape ((/1, 2, 0, 3, 1, 0, 0, 0, 4/), (/3, 3/)))) &\n call abort\n write (line1,'(10I4)') b\n write (line2,'(10I4)') unpack((/2, 3, 4/), mask, a)\n if (line1 .ne. line2) call abort\n b = -1\n b = unpack ((/2, 3, 4/), mask, 0)\n if (any (b .ne. reshape ((/0, 2, 0, 3, 0, 0, 0, 0, 4/), (/3, 3/)))) &\n call abort\nend program\n", "meta": {"hexsha": "88f09c321b4d7c065dddd43bd755eccb87ec3060", "size": 765, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_unpack.f90", "max_stars_repo_name": "best08618/asylo", "max_stars_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-05-02T17:34:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-17T10:15:18.000Z", "max_issues_repo_path": "llvm-gcc-4.2-2.9/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_unpack.f90", "max_issues_repo_name": "vidkidz/crossbridge", "max_issues_repo_head_hexsha": "ba0bf94aee0ce6cf7eb5be882382e52bc57ba396", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "llvm-gcc-4.2-2.9/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_unpack.f90", "max_forks_repo_name": "vidkidz/crossbridge", "max_forks_repo_head_hexsha": "ba0bf94aee0ce6cf7eb5be882382e52bc57ba396", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-27T00:22:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-01T09:41:02.000Z", "avg_line_length": 34.7727272727, "max_line_length": 72, "alphanum_fraction": 0.4967320261, "num_tokens": 346, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951104066293, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.6649312875423488}} {"text": "c\nc\nc\nc =================================================\n function fdisc(x,y)\nc =================================================\n\n implicit double precision (a-h,o-z)\n\nc\nc # For computing cell averages for initial data or coefficients that\nc # have a discontinuity along some curve. \n\nc # fdisc should be negative to the \"left\" of the curve and \nc # positive to the \"right\".\n\nc # The cellave routine can then be used to compute the fraction wl of\nc # a grid cell that lies to the \"left\" of the curve.\n\nc # Sample code for the case where the curve is the unit circle:\n\n fdisc = x**2 + y**2 - 1.d0\nc\n return\n end\n", "meta": {"hexsha": "f7064cdca261f44f10e89610ae911ccd87bca043", "size": 675, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/2d/fdisc.f", "max_stars_repo_name": "ClimateImpactLab/classic", "max_stars_repo_head_hexsha": "04abb3f0f3dcb767f79234b0f38ba9956ad95962", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2017-01-04T18:19:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-21T01:46:33.000Z", "max_issues_repo_path": "clawpack/2d/lib/fdisc.f", "max_issues_repo_name": "che-wenchao/D-Claw", "max_issues_repo_head_hexsha": "8ab5d971c9a7a7130e03a447a4b8642e292f4e88", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2020-01-14T18:00:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T14:25:24.000Z", "max_forks_repo_path": "src/2d/fdisc.f", "max_forks_repo_name": "cjvogl/classic", "max_forks_repo_head_hexsha": "5f5f7600f8f007dad9f7359df2033e6aa801cd1f", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2016-09-22T20:20:06.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-13T14:48:32.000Z", "avg_line_length": 25.9615384615, "max_line_length": 74, "alphanum_fraction": 0.5392592593, "num_tokens": 162, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970904940926, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6649269288600875}} {"text": "!##############################################################################\n! MODULE globals\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!##############################################################################\nmodule globals\n\n implicit none\n integer, parameter :: XX = 16 ! maximum age of individuals\n integer, parameter :: TT = XX - 1 ! maximum number of periods\n integer, parameter :: KK = 100000 ! number of mortality path simulations\n integer, parameter :: NN = 5 ! number of insurance contracts\n\n real*8, parameter :: sigma_eps = 2.0d0 ! variance of the innovation to the random walk\n real*8, parameter :: c = -1.0d0 ! drift of random walk\n\n real*8, parameter :: r = 0.16d0 ! interest rate\n real*8, parameter :: xi_1 = 0.05d0 ! loading factor for premium calculation (annuity)\n real*8, parameter :: xi_2 = 0.05d0 ! discount factor for premium calculation (life insurance)\n real*8, parameter :: gamma = 10.0d0 ! risk aversion\n\n real*8 :: q(XX, 0:TT, 0:KK), alpha(XX), beta(XX), kappa(0:TT), eps(TT)\n real*8 :: PP(XX, 0:TT, 0:KK), LE(XX, 0:KK)\n real*8 :: p_m(NN), omega(NN), n_new(NN)\n real*8 :: l(NN, KK), l_p(KK)\n real*8 :: mu(NN), sig(NN, NN), mu_p, sig_p, sum_premia\n real*8 :: VaR, CVaR, IID(NN), x_in(2*NN+1)\n real*8 :: age(0:TT+1), PP_av(0:TT+1), PP_min(0:TT+1), PP_max(0:TT+1)\n integer :: ix, ik, it, ik_max, ik_min, ii, im, id, ij, ii_VaR\n logical :: check\n\n ! define an insurance type\n type :: insurance_type\n character(len=2) :: itype\n integer :: ix, im, id\n real*8 :: BB, n_ins\n end type\n\n ! declare the insurance variable\n type(insurance_type) :: ins(NN)\n\ncontains\n\n\n ! first order condition of the insurer\n function focs(x_in)\n\n implicit none\n real*8, intent(in) :: x_in(:)\n real*8 :: focs(size(x_in, 1))\n real*8 :: omega(NN), eta(NN), lamda\n\n ! copy portfolio weights\n omega = x_in(1:NN)\n\n ! copy lagrangean multipliers\n lamda = x_in(NN+1)\n eta = x_in(NN+2:2*NN+1)\n\n ! set up first order conditions\n focs(1:NN) = - mu - gamma*matmul(sig, omega) - lamda + eta\n focs(NN+1) = sum(omega) - 1d0\n focs(NN+2:2*NN+1) = omega + eta - sqrt(omega**2 + eta**2)\n\n end function focs\n\nend module globals\n\n\n", "meta": {"hexsha": "6549bfe4922bbe4534a3f057493da28af8e135a9", "size": 2610, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "complete/prog04/prog04_09/prog04_09m.f90", "max_stars_repo_name": "aswinvk28/modflow_fortran", "max_stars_repo_head_hexsha": "0c8dd5da8fe08f0abcc6b677503e96cdcdb7ee1e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "complete/prog04/prog04_09/prog04_09m.f90", "max_issues_repo_name": "aswinvk28/modflow_fortran", "max_issues_repo_head_hexsha": "0c8dd5da8fe08f0abcc6b677503e96cdcdb7ee1e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "complete/prog04/prog04_09/prog04_09m.f90", "max_forks_repo_name": "aswinvk28/modflow_fortran", "max_forks_repo_head_hexsha": "0c8dd5da8fe08f0abcc6b677503e96cdcdb7ee1e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-04-07T12:27:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-07T12:27:47.000Z", "avg_line_length": 33.8961038961, "max_line_length": 103, "alphanum_fraction": 0.5490421456, "num_tokens": 810, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6649269241357503}} {"text": "module myinvert\n contains\n subroutine invert (matrix,size)\n implicit none\n integer, parameter:: b8 = selected_real_kind(14)\n integer, parameter :: nmax=5000\n integer switch,k, jj, kp1, i, j, l, krow, irow,size\n dimension switch(nmax,2)\n real(b8) matrix(size,size)\n real(b8) pivot, temp\n do 100 k = 1,size\n jj = k\n if (k .ne. size) then\n kp1 = k + 1\n pivot = (matrix(k, k))\n do 1 i = kp1,size\n temp = (matrix(i, k))\n if (abs(pivot) .lt. abs(temp)) then\n pivot = temp\n jj = i\n endif\n 1 continue\n endif\n switch(k, 1) = k\n switch(k, 2) = jj\n if (jj .ne. k) then\n do 2 j = 1 ,size \n temp = matrix(jj, j)\n matrix(jj, j) = matrix(k, j)\n matrix(k, j) = temp\n 2 continue\n endif\n do 3 j = 1,size\n if (j .ne. k)matrix(k, j) = matrix(k, j) / matrix(k, k)\n 3 continue\n matrix(k, k) = 1.0 / matrix(k, k)\n do 4 i = 1,size\n if (i.ne.k) then\n do 40 j = 1,size\n if(j.ne.k)matrix(i,j)=matrix(i,j)-matrix(k,j)*matrix(i,k)\n 40 continue\n endif\n 4 continue\n do 5 i = 1, size\n if (i .ne. k)matrix(i, k) = -matrix(i, k) * matrix(k, k)\n 5 continue\n 100 continue\n do 6 l = 1,size\n k = size - l + 1\n krow = switch(k, 1)\n irow = switch(k, 2)\n if (krow .ne. irow) then\n do 60 i = 1,size\n temp = matrix(i, krow)\n matrix(i, krow) = matrix(i, irow)\n matrix(i, irow) = temp\n 60 continue\n endif\n 6 continue\n return\n end\n\tsubroutine dGESV( N, NRHS, A, LDA, IPIV, B, LDB, INFO )\n\timplicit none\n\tinteger, parameter:: b8 = selected_real_kind(14)\n\treal(b8) A(:,:),B(:,:)\n\tinteger :: IPIV(:)\n\tinteger n,nrhs,lda,ldb,info\n\treal(b8), allocatable :: x(:)\n\tallocate(x(n))\n\tcall invert(a,n)\n\tx=matmul(a,b(:,1))\n\tb(:,1)=x\n\tdeallocate(x)\n\tinfo=0\n\tend subroutine\nend module\n", "meta": {"hexsha": "a3b9ba564bdca52b3fde5c7ef7bcec5c18b3bbc6", "size": 1828, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "inverts/myover.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": "inverts/myover.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": "inverts/myover.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": 23.7402597403, "max_line_length": 61, "alphanum_fraction": 0.5541575492, "num_tokens": 678, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970811069351, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6649269217735816}} {"text": "\tmodule sub1\n\tcontains \n\tsubroutine cg(A,b,x,N,e)\nc\tvariable\tmeaning\nc\tA\t\ta matrix,from main program,is coefficient matrix of Ax=b\nc\tb\t\ta vector,from main program,is righthand of Ax=b\nc\tx\t\ta vector,the answer of Ax=b,is what we need,our goal\nc\tr\t\ta vector,minus grads of 0.5xAx-bx at x point,says b-Ax\nc\tp\t\ta vector,the direction of iteration better than r\nc\tw\t\ta vector,value is A*p,is useful to simplify the process\nc\tq0\t\ta number,value is r0*r0,is standard of loop times\nc\tq1\t\ta number,value is rk-1*rk-1\nc\tq2\t\ta number, value is rk*rk\nc\tba,ar\t\ta number,named by their pronounciation\nc\te\t\ta number,standard of loop times,input by client\nc\ttest\t\ta number,value is matmul(r,w)\nc\tpw\t\ta number,value is matmul(p,w)\nc\ti\t\ta number,count variable\nc\tN\t\ta number,the degree of A\n\treal*8 A(N,N)\n\treal*8 b(N),x(N),r(N),p(N),w(N)\nc\treal*8 A(2,2),b(2),x(2),r(2),p(2),w(2)\n\treal*8 q0,q1,q2,ba,ar,e,test,pw\n\tinteger i,N\nc\twrite(*,*)\"you want the x_error less than?\"\nc\tread(*,*)e\n\tx=0.0d0\n\tr=b\n\tcall onedimenmul(r,r,N,q0)\n\tq2=q0\n\tp=r\n\nc\tw=matmul(A,p)\nc\tcall onedimenmul(r,w,2,test)\nc\tar=q2/test\nc\tx=x+ar*p\nc\tr=r-ar*w\nc\tq1=q2;call onedimenmul(r,r,2,q2)\nc\tr=r-a*w\n\ti=1\n\tdo while(q2>=q0*e)\n\tq1=q2\nc\tba=q2/q1\nc\tp=r+ba*p\n\t\n\tw=matmul(A,p)\n\tcall onedimenmul(p,w,N,pw)\nc\tpw is p*w\n\tar=q1/pw\n\tx=x+ar*p\n\tr=r-ar*w\n\tcall onedimenmul(r,r,N,q2)\nc\tr=r-a*w\n\tba=q2/q1\n\ti=i+1\n\tp=r+ba*p\n\tend do\n\tend subroutine cg\n\nc\tThis subroutine is to solve one dimention's multiplication\n\tsubroutine onedimenmul(m1,m2,n,ans)\n\tinteger n\n\treal*8 m1(n),m2(n),ans\n\tans=0\n\tdo i=1,n\n\tans=m1(i)*m2(i)+ans\n\tend do\n\t\n\tend subroutine onedimenmul\n\n\tend module sub1\n\n", "meta": {"hexsha": "67826e5d96f79edfd61a35da893185ca32c9ad46", "size": 1611, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "geomagnetic_reverse/sub1.f", "max_stars_repo_name": "DearDon/Geomagnetics", "max_stars_repo_head_hexsha": "b07fbfde7b33408a01697ac01ac54e00bafc513b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "geomagnetic_reverse/sub1.f", "max_issues_repo_name": "DearDon/Geomagnetics", "max_issues_repo_head_hexsha": "b07fbfde7b33408a01697ac01ac54e00bafc513b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "geomagnetic_reverse/sub1.f", "max_forks_repo_name": "DearDon/Geomagnetics", "max_forks_repo_head_hexsha": "b07fbfde7b33408a01697ac01ac54e00bafc513b", "max_forks_repo_licenses": ["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.0684931507, "max_line_length": 61, "alphanum_fraction": 0.687150838, "num_tokens": 634, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778824, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6649269194114128}} {"text": "module m_line\n\n use m_kind_parameters\n \n implicit none\n \n private\n public :: line\n \n type :: line \n \n real(kind=rel_kind) :: origin(n_dim) ! origin of line\n real(kind=rel_kind) :: terminus(n_dim) ! terminus of line\n real(kind=rel_kind) :: direction(n_dim) ! direction unit vector\n real(kind=rel_kind) :: inv_direction(n_dim) ! 1/direction\n real(kind=rel_kind) :: length ! length of line\n \n contains\n \n procedure,non_overridable :: initialise\n \n end type\n \n contains\n \n pure subroutine initialise(self,origin,direction,length)\n \n ! argument declarations\n class(line),intent(inout) :: self ! line object\n real(kind=rel_kind),intent(in) :: origin(n_dim) ! origin of line\n real(kind=rel_kind),intent(in) :: direction(n_dim)! direction of line\n real(kind=rel_kind),intent(in) :: length ! length of line\n \n ! set variables\n self%origin=origin\n self%direction=direction/norm2(direction)\n self%length=length\n self%inv_direction=1._rel_kind/self%direction\n self%terminus=self%origin+self%length*self%direction\n \n \n return\n \n end subroutine\n\nend module", "meta": {"hexsha": "02db30c447b4d0f323241fe5fc46af7d61c5cdb1", "size": 1285, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/line.f90", "max_stars_repo_name": "odlomax/spamcart-dev", "max_stars_repo_head_hexsha": "b9b18d0093a0de0dab3a34b40222c4a64babcea2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2016-07-28T07:12:43.000Z", "max_stars_repo_stars_event_max_datetime": "2017-02-02T15:34:59.000Z", "max_issues_repo_path": "src/line.f90", "max_issues_repo_name": "odlomax/spamcart-dev", "max_issues_repo_head_hexsha": "b9b18d0093a0de0dab3a34b40222c4a64babcea2", "max_issues_repo_licenses": ["MIT"], "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/line.f90", "max_forks_repo_name": "odlomax/spamcart-dev", "max_forks_repo_head_hexsha": "b9b18d0093a0de0dab3a34b40222c4a64babcea2", "max_forks_repo_licenses": ["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.9347826087, "max_line_length": 79, "alphanum_fraction": 0.6015564202, "num_tokens": 297, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6649269098303808}} {"text": "!--------------------------------------------------\n!PHY1038 Assignment 4 Matrix Geometry\n!URN: 6408056\n!MAY 2017\n!--------------------------------------------------\n\nPROGRAM Matrix_Geometry\n\nIMPLICIT NONE\n\nREAL, DIMENSION(1:3,1:1)::Array, Rot, Tran, Arrayone, Arraytwo, Arraythree, OArrayone, OArraytwo\nREAL, DIMENSION(1:3,1:1)::OArraythree\nCHARACTER::Mainloop, Intro, Main, Correction\nINTEGER:: I, N, Itwo\nREAL:: Inputangle, Xtranslation, Ytranslation \n\nMainloop='Y'!Allows main do loop to play intially\nIntro='Y'!Allows intro to play on first run\n\nDO WHILE (Mainloop=='Y' .OR. Mainloop=='y')\n \n IF(Intro=='Y') THEN \n WRITE(6,*) 'This program allows you to enter x and y coordinates and have them translated'\n WRITE(6,*) 'or rotated, it also allows you to rotate a triangle about its centre of mass.'\n WRITE(6,*) 'The program lets you enter your own rotation angle/translations.'\n WRITE(6,*) 'It then prints the translated/rotated coordinates to the screen as well as'\n WRITE(6,*) 'a file, named translate.dat, rotate.dat, or triangle.dat'\n WRITE(6,*) 'It writes the orginal coordinates in lines one and two, and the altered'\n WRITE(6,*) 'coordinates in lines three and four'\n WRITE(6,*) 'When using program please enter your coordiantes x first e.g.: x, y, x, y'\n Intro='N' !Prevents the intro being played too many times\n END IF\n\n WRITE(6,*)'If you would like to rotate a vector by a paticular angle type, R, for a translation'\n WRITE(6,*)'type T, to rotate a triangle about its centre of mass type, C'\n\n DO !replays if an invalid choice is entered\n READ(5,*) Main\n\n IF(Main=='r' .or. Main=='R' .or. Main=='t' .or. Main=='T' .or. Main=='c' .or. Main== 'C')THEN\n EXIT !If loop allows the exit from do loop only when a valid choice is entered\n END IF \n\n WRITE(6,*) 'Please enter a valid option'\n WRITE(6,*) 'Enter, R, for rotation, T, for translation, or C to rotate a triangle about its'\n WRITE(6,*) 'centre of mass.'\n \n END DO\n\n \n IF (Main=='r' .or. Main=='R') THEN !Main if command seperates the main components of the program\n \n DO !Do loop will replay if user says they entered the 'wrong coordinates' \n \n WRITE(6,*) 'How many points would you like to rotate?'\n READ(5,*) N\n WRITE(6,*) 'By what angle, in radians, would you like to rotate them by?'\n READ(5,*) Inputangle \n WRITE(6,*) 'You entered',N,' as the amount of points you want to rotate, and'\n WRITE(6,*) Inputangle, 'As the amount you want to rotate them by, is this correct?' \n DO !Do loop will replay if user enters an 'invalid choice'\n WRITE(6,*) 'Type Y for yes, or N for no.' \n READ(5,*) Correction\n \n IF (Correction=='n' .or. Correction=='y' .or. Correction=='N' .or. Correction=='Y') THEN\n EXIT !Exits 'invalid choice' do loop when they enter valid choice\n END IF \n WRITE(6,*) 'Please enter a valid choice.'\n END DO\n \n IF (Correction=='Y' .or. Correction=='y')THEN\n EXIT !Exits 'wrong coordinates' do loop when they say they entered the right coordinates\n END IF\n\n END DO\n \n OPEN(unit=20,file='rotate.dat')\n \n DO I=1,N !Plays once for every coordinate that they wanted to enter\n \n \n WRITE(6,*) 'Please enter Array number',i,' that you want to rotate, x then y.'\n READ(5,*) Array(1,1), Array(2,1)\n \n Array(3,1)=1 !Setting z coordinate to 1 for rotation matrix to work\n \n Rot = Rotation(Array,Inputangle) !Calls on rotation function, and stores it as a different\n !Array allowing program call on just the x and y coordinates \n WRITE(6,*)'Your number',I,' rotated array is:'\n WRITE(6,*) Rot(1,1), Rot(2,1)\n WRITE(20,*) Array(1,1), Array(2,1), Rot(1,1), Rot(2,1) !Prints orginal, and altered \n !coordinates to file\n \n IF (I==1) THEN\n Arrayone=Array; Arraytwo=Rot !This stores the first set of coordinates to later print\n ELSE IF (I==N) THEN\n WRITE(20,*) Arrayone(1,1), Arrayone(2,1), Arraytwo(1,1), Arraytwo(2,1)\n END IF !Prints coordinates to file, to allow for conjoined shape when plotting\n \n END DO \n \n CLOSE(20)\n\n ELSE IF (Main=='t' .or. Main=='T') THEN\n \n DO !Do loop will replay if user says they entered the 'wrong coordinates'\n\n WRITE(6,*) 'How many points would you like to translate?'\n READ(5,*) N\n WRITE(6,*) 'Please enter the amount you want to translate x by.'\n READ(5,*) Xtranslation\n WRITE(6,*) 'Please enter the amount you want to translate y by.'\n READ(5,*) Ytranslation\n WRITE(6,*) 'You entered',N,' as the amount of points you want to translate, and', Xtranslation\n WRITE(6,*) Ytranslation, 'as the amount to translate x, then y by.'\n \n DO !Do loop will replay if user enters an 'invalid choice'\n WRITE(6,*) 'Type Y for yes, or N for no.' \n READ(5,*) Correction\n IF (Correction=='n' .or. Correction=='y' .or. Correction=='N' .or. Correction=='Y') THEN\n EXIT!Exits 'invalid choice' do loop when they enter valid choice\n END IF \n WRITE(6,*) 'Please enter a valid choice.'\n END DO\n \n IF (Correction=='Y' .or. Correction=='y')THEN\n EXIT !Exits 'wrong coordinates' do loop when they say they entered the right coordinates\n END IF\n \n END DO\n \n OPEN(unit=20,file='translate.dat') \n\n DO Itwo=1,N !Plays once for each coordinate\n \n WRITE(6,*) 'Please enter Array number',Itwo,' that you want to translate, x then y.'\n READ(5,*) Array(1,1), Array(2,1)\n \n Array(3,1)=1 !Setting Z coordinate to one so translation equation will work\n \n Tran = Translation(Array, Xtranslation, Ytranslation)!calls on translation function and\n !stores altered coordinates in a different array, allowing program to call on it x and y only\n \n WRITE(6,*)'Your number',Itwo,' translated array is:'\n WRITE(6,*) Tran(1,1), Tran(2,1) !prints altered coordinates to screen\n WRITE(20,*) Array(1,1), Array(2,1), Tran(1,1), Tran(2,1)!writes both orginal and altered \n !altered coordinates to file\n IF (Itwo==1) THEN\n Arrayone=Array; Arraytwo=Tran !stores first set of coordinates as seperate arrays\n ELSE IF (Itwo==N) THEN\n WRITE(20,*) Arrayone(1,1), Arrayone(2,1), Arraytwo(1,1), Arraytwo(2,1)\n END IF !Prints first set of coordinates to file again, for conjoined shape\n \n END DO \n\n CLOSE(20)\n \n\n ELSE IF (Main=='c' .or. Main=='C') THEN\n \n Arrayone(3,1)=1; Arraytwo(3,1)=1; Arraythree(3,1)=1 !Setting all three z coordinates to 1\n !So equations in functions work \n DO!Do loop will replay if user says they entered the 'wrong coordinates'\n \n WRITE(6,*) 'Please enter the three x,y coordinates of the vertices of your triangle.'\n READ(5,*) Arrayone(1,1), Arrayone(2,1), Arraytwo(1,1), Arraytwo(2,1), Arraythree(1,1)\n READ(5,*) Arraythree(2,1)\n WRITE(6,*) 'Please enter the angle you want to rotate the triangle by in radians.'\n READ(5,*) Inputangle \n WRITE(6,*) 'You entered', Arrayone(1,1), Arrayone(2,1),'as one vertice', Arraytwo(1,1)\n WRITE(6,*) Arraytwo(2,1), 'as another and', Arraythree(1,1), Arraythree(2,1), 'as the third.'\n WRITE(6,*) 'You entered the angle of rotation to be', Inputangle \n WRITE(6,*) 'Is that correct? Type Y for yes, or N for no.' \n \n DO !Do loop will replay if user enters an 'invalid choice' \n WRITE(6,*) 'Type Y for yes, or N for no.' \n READ(5,*) Correction\n IF (Correction=='n' .or. Correction=='y' .or. Correction=='N' .or. Correction=='Y') THEN\n EXIT !Exits 'invalid choice' do loop when they enter valid choice\n END IF \n WRITE(6,*) 'Please enter a valid choice.'\n END DO\n \n IF (Correction=='Y' .or. Correction=='y')THEN\n EXIT !Exits 'wrong coordinates' do loop when they say they entered the right coordinates\n END IF\n\n END DO\n \n OArrayone=Arrayone; OArraytwo=Arraytwo; OArraythree=Arraythree\n !Stores orginal arrays with 'o' prefix, so they can later be written to a file\n OPEN(unit=20,file='triangle.dat')\n \n Xtranslation=(Arrayone(1,1)+Arraytwo(1,1)+Arraythree(1,1))/3\n Ytranslation=(Arrayone(2,1)+Arraytwo(2,1)+Arraythree(2,1))/3\n !^Calculates COM\n\n WRITE(6,*) 'Centre of mass of the triangle is', Xtranslation, Ytranslation\n \n Xtranslation=-Xtranslation; Ytranslation=-Ytranslation\n !^Turns COM in negative translations, so program can set it to the origin\n \n Array = Arrayone; Arrayone = Translation(Array, Xtranslation, Ytranslation)\n Array = Arraytwo; Arraytwo = Translation(Array, Xtranslation, Ytranslation)\n Array = Arraythree; Arraythree = Translation(Array, Xtranslation, Ytranslation)\n !^Translates all coorinates so that COM is at origin\n \n Array = Arrayone; Arrayone = Rotation(Array,Inputangle)\n Array = Arraytwo; Arraytwo = Rotation(Array,Inputangle)\n Array = Arraythree; Arraythree = Rotation(Array,Inputangle)\n !^Rotates coordinates, so that triangle is rotates\n \n Xtranslation=-Xtranslation; Ytranslation=-Ytranslation\n !^Again reverses coordinates so that COM can be returned to original postion\n\n Array = Arrayone; Arrayone = Translation(Array, Xtranslation, Ytranslation)\n Array = Arraytwo; Arraytwo = Translation(Array, Xtranslation, Ytranslation)\n Array = Arraythree; Arraythree = Translation(Array, Xtranslation, Ytranslation)\n !^Places COM in original postions\n\n WRITE(6,*) 'The three vertices of your rotated triangle, (x,y), are:'\n \n WRITE(6,*) Arrayone(1,1), Arrayone(2,1) \n WRITE(20,*) OArrayone(1,1), OArrayone(2,1), Arrayone(1,1), Arrayone(2,1)\n \n WRITE(6,*) Arraytwo(1,1), Arraytwo(2,1) \n WRITE(20,*) OArraytwo(1,1), OArraytwo(2,1), Arraytwo(1,1), Arraytwo(2,1)\n \n WRITE(6,*) Arraythree(1,1), Arraythree(2,1)\n WRITE(20,*) OArraythree(1,1), OArraythree(2,1), Arraythree(1,1), Arraythree(2,1)\n !^Prints all three rotated coordiantes to screen, as well as printing orginal and altered\n !to file\n\n WRITE(20,*) OArrayone(1,1), OArrayone(2,1), Arrayone(1,1), Arrayone(2,1)\n !^Prints 1st coordinates again to produce conjoined shape\n\n CLOSE(20)\n\n END IF\n\n WRITE(6,*) 'Would you like to run the program again?'!Allows user to choose between main parts of\n !program again\n WRITE(6,*) 'Type Y for Yes, or N for No.'\n DO !Plays loop again if valid choice is not entered \n READ(5,*) Mainloop\n IF (Mainloop=='n' .or. Mainloop=='y' .or. Mainloop=='N' .or. Mainloop=='Y') THEN\n EXIT!Exits loop when valid choice is chosen\n END IF \n WRITE(6,*) 'Please enter a valid choice; Y for Yes, or N for No.'\n END DO\n \nEND DO !Main do loop, will play if Y is selected\n\nWRITE(6,*) 'Thank you for using the program.'!Will play on exit\n\nCONTAINS\n\nFUNCTION Rotation(Array,Inputangle) \n REAL, DIMENSION(1:3,1:1):: Rotation, Array\n REAL, DIMENSION(1:3,1:3):: RotArray\n REAL:: Inputangle, Sinput, Cinput\n \n Cinput = cos(Inputangle)!storing cos and sine of input angle for rotation matrix\n Sinput = sin(Inputangle)\n RotArray(1,1)=Cinput; RotArray(1,2)=-Sinput; RotArray(1,3)=0\n RotArray(2,1)=Sinput; RotArray(2,2)=Cinput; RotArray(2,3)=0\n RotArray(3,1)=0; RotArray(3,2)=0; RotArray(3,3)=1 !Records rotation matrix\n\n Rotation = Matmul(Rotarray,Array) !Multiplies the rotation matrix with the users array\n\nEND FUNCTION \n\nFUNCTION Translation(Array, Xtranslation, Ytranslation)\n REAL, DIMENSION(1:3,1:1):: Translation, Array\n REAL, DIMENSION(1:3,1:3):: TranArray\n REAL:: Xtranslation, Ytranslation\n \n TranArray(1,1)=1; TranArray(1,2)=0; TranArray(1,3)=Xtranslation\n TranArray(2,1)=0; TranArray(2,2)=1; TranArray(2,3)=Ytranslation\n TranArray(3,1)=0; TranArray(3,2)=0; TranArray(3,3)=1 !Records translation array\n \n Translation = Matmul(TranArray,Array) !Multiples the translation matrix with users array\n \nEND FUNCTION\n \nEND PROGRAM \n", "meta": {"hexsha": "27ec80cc9250cb7b04853784932fe5ae495e2032", "size": 12435, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Matrix Calculator/6408056-Ass4.f90", "max_stars_repo_name": "DGrifferty/Fortran", "max_stars_repo_head_hexsha": "600b46fb553fe955c7dd574ee4f51ac1f24de62e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Matrix Calculator/6408056-Ass4.f90", "max_issues_repo_name": "DGrifferty/Fortran", "max_issues_repo_head_hexsha": "600b46fb553fe955c7dd574ee4f51ac1f24de62e", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Matrix Calculator/6408056-Ass4.f90", "max_forks_repo_name": "DGrifferty/Fortran", "max_forks_repo_head_hexsha": "600b46fb553fe955c7dd574ee4f51ac1f24de62e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.3275261324, "max_line_length": 105, "alphanum_fraction": 0.6310414154, "num_tokens": 3527, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026595857203, "lm_q2_score": 0.724870282120402, "lm_q1q2_score": 0.6649254376436963}} {"text": "c \\BeginDoc\nc\nc \\Name: dsband\nc\nc \\Description:\nc\nc This subroutine returns the converged approximations to eigenvalues\nc of A*z = lambda*B*z and (optionally):\nc\nc (1) The corresponding approximate eigenvectors;\nc\nc (2) An orthonormal (Lanczos) basis for the associated approximate\nc invariant subspace;\nc\nc (3) Both.\nc\nc Matrices A and B are stored in LAPACK-style band form.\nc\nc There is negligible additional cost to obtain eigenvectors. An orthonormal\nc (Lanczos) basis is always computed. There is an additional storage cost \nc of n*nev if both are requested (in this case a separate array Z must be \nc supplied).\nc\nc The approximate eigenvalues and eigenvectors of A*z = lambda*B*z\nc are called Ritz values and Ritz vectors respectively. They are referred \nc to as such in the comments that follow. The computed orthonormal basis \nc for the invariant subspace corresponding to these Ritz values is referred \nc to as a Lanczos basis.\nc\nc dsband can be called with one of the following modes:\nc\nc Mode 1: A*x = lambda*x, A symmetric \nc ===> OP = A and B = I.\nc\nc Mode 2: A*x = lambda*M*x, A symmetric, M symmetric positive definite\nc ===> OP = inv[M]*A and B = M.\nc ===> (If M can be factored see remark 3 in DSAUPD)\nc\nc Mode 3: K*x = lambda*M*x, K symmetric, M symmetric positive semi-definite\nc ===> OP = (inv[K - sigma*M])*M and B = M. \nc ===> Shift-and-Invert mode\nc\nc Mode 4: K*x = lambda*KG*x, K symmetric positive semi-definite, \nc KG symmetric indefinite\nc ===> OP = (inv[K - sigma*KG])*K and B = K.\nc ===> Buckling mode\nc\nc Mode 5: A*x = lambda*M*x, A symmetric, M symmetric positive semi-definite\nc ===> OP = inv[A - sigma*M]*[A + sigma*M] and B = M.\nc ===> Cayley transformed mode\nc\nc The choice of mode must be specified in IPARAM(7) defined below.\nc\nc \\Usage\nc call dsband\nc ( RVEC, HOWMNY, SELECT, D, Z, LDZ, SIGMA, N, AB, MB, LDA, \nc RFAC, KL, KU, WHICH, BMAT, NEV, TOL, RESID, NCV, V, \nc LDV, IPARAM, WORKD, WORKL, LWORKL, IWORK, INFO )\nc\nc \\Arguments\nc\nc RVEC Logical (INPUT)\nc Specifies whether Ritz vectors corresponding to the Ritz value \nc approximations to the eigenproblem A*z = lambda*B*z are computed.\nc\nc RVEC = .FALSE. Compute Ritz values only.\nc\nc RVEC = .TRUE. Compute the associated Ritz vectors. \nc\nc HOWMNY Character*1 (INPUT) \nc Specifies how many Ritz vectors are wanted and the form of Z\nc the matrix of Ritz vectors. See remark 1 below.\nc = 'A': compute all Ritz vectors;\nc = 'S': compute some of the Ritz vectors, specified\nc by the logical array SELECT.\nc\nc SELECT Logical array of dimension NCV. (INPUT)\nc If HOWMNY = 'S', SELECT specifies the Ritz vectors to be\nc computed. To select the Ritz vector corresponding to a\nc Ritz value D(j), SELECT(j) must be set to .TRUE.. \nc If HOWMNY = 'A' , SELECT is not referenced.\nc\nc D Double precision array of dimension NEV. (OUTPUT)\nc On exit, D contains the Ritz value approximations to the\nc eigenvalues of A*z = lambda*B*z. The values are returned\nc in ascending order. If IPARAM(7) = 3,4,5 then D represents\nc the Ritz values of OP computed by dsaupd transformed to\nc those of the original eigensystem A*z = lambda*B*z. If \nc IPARAM(7) = 1,2 then the Ritz values of OP are the same \nc as the those of A*z = lambda*B*z.\nc\nc Z Double precision N by NEV array if HOWMNY = 'A'. (OUTPUT)\nc On exit, Z contains the B-orthonormal Ritz vectors of the\nc eigensystem A*z = lambda*B*z corresponding to the Ritz\nc value approximations.\nc\nc If RVEC = .FALSE. then Z is not referenced.\nc NOTE: The array Z may be set equal to first NEV columns of the \nc Lanczos basis array V computed by DSAUPD.\nc\nc LDZ Integer. (INPUT) \nc The leading dimension of the array Z. If Ritz vectors are\nc desired, then LDZ .ge. max( 1, N ). In any case, LDZ .ge. 1.\nc\nc SIGMA Double precision (INPUT)\nc If IPARAM(7) = 3,4,5 represents the shift. Not referenced if\nc IPARAM(7) = 1 or 2.\nc \nc N Integer. (INPUT) \nc Dimension of the eigenproblem. \nc \nc AB Double precision array of dimension LDA by N. (INPUT)\nc The matrix A in band storage, in rows KL+1 to\nc 2*KL+KU+1; rows 1 to KL of the array need not be set.\nc The j-th column of A is stored in the j-th column of the\nc array AB as follows:\nc AB(kl+ku+1+i-j,j) = A(i,j) for max(1,j-ku)<=i<=min(m,j+kl)\nc\nc MB Double precision array of dimension LDA by N. (INPUT)\nc The matrix M in band storage, in rows KL+1 to\nc 2*KL+KU+1; rows 1 to KL of the array need not be set. \nc The j-th column of M is stored in the j-th column of the\nc array AB as follows:\nc MB(kl+ku+1+i-j,j) = M(i,j) for max(1,j-ku)<=i<=min(m,j+kl)\nc Not referenced if IPARAM(7) = 1\nc\nc LDA Integer. (INPUT)\nc Leading dimension of AB, MB, RFAC.\nc\nc RFAC Double precision array of LDA by N. (WORKSPACE/OUTPUT)\nc RFAC is used to store the LU factors of MB when IPARAM(7) = 2 \nc is invoked. It is used to store the LU factors of\nc (A-sigma*M) when IPARAM(7) = 3,4,5 is invoked.\nc It is not referenced when IPARAM(7) = 1.\nc\nc KL Integer. (INPUT)\nc Max(number of subdiagonals of A, number of subdiagonals of M)\nc\nc KU Integer. (OUTPUT)\nc Max(number of superdiagonals of A, number of superdiagonals of M)\nc\nc WHICH Character*2. (INPUT)\nc When IPARAM(7)= 1 or 2, WHICH can be set to any one of\nc the following.\nc \nc 'LM' -> want the NEV eigenvalues of largest magnitude.\nc 'SM' -> want the NEV eigenvalues of smallest magnitude.\nc 'LA' -> want the NEV eigenvalues of largest REAL part.\nc 'SA' -> want the NEV eigenvalues of smallest REAL part.\nc 'BE' -> Compute NEV eigenvalues, half from each end of the \nc spectrum. When NEV is odd, compute one more from \nc the high end than from the low end. \nc\nc When IPARAM(7) = 3, 4, or 5, WHICH should be set to 'LM' only. \nc \nc BMAT Character*1. (INPUT)\nc BMAT specifies the type of the matrix B that defines the\nc semi-inner product for the operator OP.\nc BMAT = 'I' -> standard eigenvalue problem A*x = lambda*x\nc BMAT = 'G' -> generalized eigenvalue problem A*x = lambda*M*x\n\nc NEV Integer. (INPUT)\nc Number of eigenvalues of OP to be computed.\nc \nc TOL Double precision scalar. (INPUT)\nc Stopping criterion: the relative accuracy of the Ritz value \nc is considered acceptable if BOUNDS(I) .LE. TOL*ABS(RITZ(I)).\nc If TOL .LE. 0. is passed a default is set:\nc DEFAULT = DLAMCH('EPS') (machine precision as computed\nc by the LAPACK auxiliary subroutine DLAMCH).\nc\nc RESID Double precision array of length N. (INPUT/OUTPUT)\nc On INPUT:\nc If INFO .EQ. 0, a random initial residual vector is used.\nc If INFO .NE. 0, RESID contains the initial residual vector,\nc possibly from a previous run.\nc On OUTPUT:\nc RESID contains the final residual vector.\nc\nc NCV Integer. (INPUT)\nc Number of columns of the matrix V (less than or equal to N).\nc Represents the dimension of the Lanczos basis constructed\nc by dsaupd for OP.\nc\nc V Double precision array N by NCV. (OUTPUT)\nc Upon INPUT: the NCV columns of V contain the Lanczos basis \nc vectors as constructed by dsaupd for OP.\nc Upon OUTPUT: If RVEC = .TRUE. the first NCONV=IPARAM(5) columns \nc represent the Ritz vectors that span the desired \nc invariant subspace.\nc NOTE: The array Z may be set equal to first NEV columns of the \nc Lanczos basis vector array V computed by dsaupd. In this case\nc if RVEC=.TRUE., the first NCONV=IPARAM(5) columns of V contain\nc the desired Ritz vectors. \nc\nc LDV Integer. (INPUT)\nc Leading dimension of V exactly as declared in the calling\nc program.\nc\nc IPARAM Integer array of length 11. (INPUT/OUTPUT)\nc IPARAM(1) = ISHIFT: \nc The shifts selected at each iteration are used to restart\nc the Arnoldi iteration in an implicit fashion.\nc It is set to 1 in this subroutine. The user do not need\nc to set this parameter.\nc ------------------------------------------------------------\nc ISHIFT = 1: exact shifts with respect to the reduced \nc tridiagonal matrix T. This is equivalent to \nc restarting the iteration with a starting vector \nc that is a linear combination of Ritz vectors \nc associated with the \"wanted\" Ritz values.\nc -------------------------------------------------------------\nc\nc IPARAM(2) = No longer referenced. \nc\nc IPARAM(3) = MXITER\nc On INPUT: max number of Arnoldi update iterations allowed.\nc On OUTPUT: actual number of Arnoldi update iterations taken.\nc\nc IPARAM(4) = NB: blocksize to be used in the recurrence.\nc The code currently works only for NB = 1.\nc\nc IPARAM(5) = NCONV: number of \"converged\" eigenvalues.\nc This represents the number of Ritz values that satisfy\nc the convergence criterion.\nc\nc IPARAM(6) = IUPD\nc No longer referenced. Implicit restarting is ALWAYS used. \nc\nc IPARAM(7) = MODE\nc On INPUT determines what type of eigenproblem is being solved.\nc Must be 1,2,3,4,5; See under \\Description of dsband for the \nc five modes available.\nc\nc IPARAM(8) = NP\nc Not referenced.\nc\nc IPARAM(9) = NUMOP, IPARAM(10) = NUMOPB, IPARAM(11) = NUMREO,\nc OUTPUT: NUMOP = total number of OP*x operations,\nc NUMOPB = total number of B*x operations if BMAT='G',\nc NUMREO = total number of steps of re-orthogonalization.\nc\nc WORKD Double precision work array of length at least 3*n. (WORKSPACE)\nc\nc WORKL Double precision work array of length LWORKL. (WORKSPACE)\nc\nc LWORKL Integer. (INPUT)\nc LWORKL must be at least NCV**2 + 8*NCV.\nc\nc IWORK Integer array of dimension at least N. (WORKSPACE)\nc Used when IPARAM(7)=2,3,4,5 to store the pivot information in the \nc factorization of M or (A-SIGMA*M).\nc \nc INFO Integer. (INPUT/OUTPUT)\nc Error flag on output.\nc = 0: Normal exit.\nc = 1: Maximum number of iterations taken.\nc All possible eigenvalues of OP has been found. IPARAM(5) \nc returns the number of wanted converged Ritz values.\nc = 3: No shifts could be applied during a cycle of the \nc Implicitly restarted Arnoldi iteration. One possibility \nc is to increase the size of NCV relative to NEV. \nc See remark 4 in DSAUPD.\nc\nc = -1: N must be positive.\nc = -2: NEV must be positive.\nc = -3: NCV-NEV >= 2 and less than or equal to N.\nc = -5: WHICH must be one of 'LM', 'SM', 'LR', 'SR', 'LI', 'SI'\nc = -6: BMAT must be one of 'I' or 'G'.\nc = -7: Length of private work WORKL array is not sufficient.\nc = -8: Error return from trid. eigenvalue calculation;\nc Informational error from LAPACK routine dsteqr.\nc = -9: Starting vector is zero.\nc = -10: IPARAM(7) must be 1,2,3,4,5.\nc = -11: IPARAM(7) = 1 and BMAT = 'G' are incompatible.\nc = -12: NEV and WHICH = 'BE' are incompatible.\nc = -13: HOWMNY must be one of 'A' or 'P'\nc = -14: DSAUPD did not find any eigenvalues to sufficient\nc accuracy.\nc = -9999: Could not build an Arnoldi factorization.\nc IPARAM(5) returns the size of the current\nc Arnoldi factorization.\nc\nc \\EndDoc\nc\nc------------------------------------------------------------------------\nc\nc\\BeginLib\nc\nc\\References:\nc 1. D.C. Sorensen, \"Implicit Application of Polynomial Filters in\nc a k-Step Arnoldi Method\", SIAM J. Matr. Anal. Apps., 13 (1992),\nc pp 357-385.\nc\nc 2. R.B. Lehoucq, \"Analysis and Implementation of an Implicitly \nc Restarted Arnoldi Iteration\", Ph.D thesis, TR95-13, Rice Univ,\nc May 1995.\nc\nc\\Routines called:\nc dsaupd ARPACK reverse communication interface routine.\nc dseupd ARPACK routine that returns Ritz values and (optionally)\nc Ritz vectors.\nc dgbtrf LAPACK band matrix factorization routine.\nc dgbtrs LAPACK band linear system solve routine. \nc dlacpy LAPACK matrix copy routine.\nc dlapy2 LAPACK routine to compute sqrt(x**2+y**2) carefully.\nc dcopy Level 1 BLAS that copies one vector to another.\nc ddot Level 1 BLAS that computes the dot product of two vectors.\nc dnrm2 Level 1 BLAS that computes the norm of a vector.\nc dgbmv Level 2 BLAS that computes the band matrix vector product.\nc\nc\\Remarks\nc 1. The converged Ritz values are always returned in increasing \nc (algebraic) order.\nc\nc 2. Currently only HOWMNY = 'A' is implemented. It is included at this\nc stage for the user who wants to incorporate it.\nc\nc\\Author \nc Danny Sorensen\nc Richard Lehoucq\nc Chao Yang\nc Dept. of Computational &\nc Applied Mathematics\nc Rice University\nc Houston, Texas\nc\nc\\SCCS Information: @(#)\nc FILE: sband.F SID: 2.3 DATE OF SID: 10/17/00 RELEASE: 2\nc\nc\\EndLib\nc\nc---------------------------------------------------------------------\nc\n subroutine dsband( rvec, howmny, select, d, z, ldz, sigma, \n & n, ab, mb, lda, rfac, kl, ku, which, bmat, nev, \n & tol, resid, ncv, v, ldv, iparam, workd, workl, \n & lworkl, iwork, info)\nc\nc %------------------%\nc | Scalar Arguments |\nc %------------------%\nc \n character which*2, bmat, howmny\n integer n, lda, kl, ku, nev, ncv, ldv,\n & ldz, lworkl, info \n Double precision\n & tol, sigma\n logical rvec\nc\nc %-----------------%\nc | Array Arguments |\nc %-----------------%\nc\n integer iparam(*), iwork(*)\n logical select(*)\n Double precision\n & d(*), resid(*), v(ldv,*), z(ldz,*),\n & ab(lda,*), mb(lda,*), rfac(lda,*), \n & workd(*), workl(*)\nc\nc %--------------%\nc | Local Arrays |\nc %--------------%\nc\n integer ipntr(14)\nc\nc %---------------%\nc | Local Scalars |\nc %---------------%\nc\n integer ido, i, j, type, imid, itop, ibot, ierr\nc\nc %------------%\nc | Parameters |\nc %------------%\nc\n Double precision\n & one, zero\n parameter (one = 1.0, zero = 0.0)\nc\nc\nc %-----------------------------%\nc | LAPACK & BLAS routines used |\nc %-----------------------------%\nc\n Double precision\n & ddot, dnrm2, dlapy2\n external ddot, dcopy, dgbmv, dgbtrf, \n & dgbtrs, dnrm2, dlapy2, dlacpy\nc\nc %-----------------------%\nc | Executable Statements |\nc %-----------------------%\nc \nc %----------------------------------------------------------------%\nc | Set type of the problem to be solved. Check consistency |\nc | between BMAT and IPARAM(7). |\nc | type = 1 --> Solving standard problem in regular mode. |\nc | type = 2 --> Solving standard problem in shift-invert mode. | \nc | type = 3 --> Solving generalized problem in regular mode. |\nc | type = 4 --> Solving generalized problem in shift-invert mode. |\nc | type = 5 --> Solving generalized problem in Buckling mode. |\nc | type = 6 --> Solving generalized problem in Cayley mode. | \nc %----------------------------------------------------------------%\nc\n if ( iparam(7) .eq. 1 ) then\n type = 1\n else if ( iparam(7) .eq. 3 .and. bmat .eq. 'I') then\n type = 2\n else if ( iparam(7) .eq. 2 ) then\n type = 3\n else if ( iparam(7) .eq. 3 .and. bmat .eq. 'G') then\n type = 4 \n else if ( iparam(7) .eq. 4 ) then\n type = 5\n else if ( iparam(7) .eq. 5 ) then \n type = 6\n else\n print*, ' '\n print*, 'BMAT is inconsistent with IPARAM(7).'\n print*, ' ' \n go to 9000\n end if\nc\nc %------------------------%\nc | Initialize the reverse |\nc | communication flag. |\nc %------------------------%\nc\n ido = 0\nc\nc %----------------%\nc | Exact shift is |\nc | used. | \nc %----------------%\nc \n iparam(1) = 1\nc\nc %-----------------------------------%\nc | Both matrices A and M are stored |\nc | between rows itop and ibot. Imid |\nc | is the index of the row that |\nc | stores the diagonal elements. |\nc %-----------------------------------%\nc\n itop = kl + 1\n imid = kl + ku + 1\n ibot = 2*kl + ku + 1\nc\n if ( type .eq. 2 .or. type .eq. 6 .and. bmat .eq. 'I' ) then\nc\nc %----------------------------------%\nc | Solving a standard eigenvalue |\nc | problem in shift-invert or |\nc | Cayley mode. Factor (A-sigma*I). |\nc %----------------------------------%\nc\n call dlacpy ('A', ibot, n, ab, lda, rfac, lda )\n do 10 j = 1, n\n rfac(imid,j) = ab(imid,j) - sigma\n 10 continue\n call dgbtrf(n, n, kl, ku, rfac, lda, iwork, ierr )\n if (ierr .ne. 0) then\n print*, ' ' \n print*, ' _SBAND: Error with _gbtrf. '\n print*, ' '\n go to 9000\n end if\nc\n else if ( type .eq. 3 ) then\nc\nc %----------------------------------------------%\nc | Solving generalized eigenvalue problem in |\nc | regular mode. Copy M to rfac and Call LAPACK |\nc | routine dgbtrf to factor M. |\nc %----------------------------------------------%\nc\n call dlacpy ('A', ibot, n, mb, lda, rfac, lda )\n call dgbtrf(n, n, kl, ku, rfac, lda, iwork, ierr) \n if (ierr .ne. 0) then \n print*, ' '\n print*,'_SBAND: Error with _gbtrf.' \n print*, ' ' \n go to 9000 \n end if\nc\n else if ( type .eq. 4 .or. type .eq. 5 .or. type .eq. 6 \n & .and. bmat .eq. 'G' ) then\nc\nc %-------------------------------------------%\nc | Solving generalized eigenvalue problem in |\nc | shift-invert, Buckling, or Cayley mode. |\nc %-------------------------------------------%\nc \nc %-------------------------------------%\nc | Construct and factor (A - sigma*M). |\nc %-------------------------------------%\nc\n do 60 j = 1,n\n do 50 i = itop, ibot \n rfac(i,j) = ab(i,j) - sigma*mb(i,j)\n 50 continue\n 60 continue\nc\n call dgbtrf(n, n, kl, ku, rfac, lda, iwork, ierr)\n if ( ierr .ne. 0 ) then\n print*, ' '\n print*, '_SBAND: Error with _gbtrf.'\n print*, ' '\n go to 9000\n end if\nc \n end if \nc\nc %--------------------------------------------%\nc | M A I N L O O P (reverse communication) |\nc %--------------------------------------------%\nc\n 90 continue \nc\n call dsaupd ( ido, bmat, n, which, nev, tol, resid, ncv,\n & v, ldv, iparam, ipntr, workd, workl, lworkl,\n & info )\nc\n if (ido .eq. -1) then\nc\n if ( type .eq. 1) then\nc\nc %----------------------------%\nc | Perform y <--- OP*x = A*x |\nc %----------------------------%\nc\n call dgbmv('Notranspose', n, n, kl, ku, one, ab(itop,1), \n & lda, workd(ipntr(1)), 1, zero, \n & workd(ipntr(2)), 1)\nc\n else if ( type .eq. 2 ) then\nc\nc %----------------------------------%\nc | Perform |\nc | y <--- OP*x = inv[A-sigma*I]*x |\nc | to force the starting vector |\nc | into the range of OP. |\nc %----------------------------------%\nc\n call dcopy (n, workd(ipntr(1)), 1, workd(ipntr(2)), 1)\n call dgbtrs ('Notranspose', n, kl, ku, 1, rfac, lda,\n & iwork, workd(ipntr(2)), n, ierr)\n if ( ierr .ne. 0 ) then\n print*, ' ' \n print*, ' _SBAND: Error with _bgtrs. '\n print*, ' '\n go to 9000\n end if\nc\n else if ( type .eq. 3 ) then\nc\nc %-----------------------------------%\nc | Perform y <--- OP*x = inv[M]*A*x |\nc | to force the starting vector into | \nc | the range of OP. |\nc %-----------------------------------%\nc\n call dgbmv('Notranspose', n, n, kl, ku, one, ab(itop,1), \n & lda, workd(ipntr(1)), 1, zero, \n & workd(ipntr(2)), 1)\n call dcopy(n, workd(ipntr(2)), 1, workd(ipntr(1)), 1)\n call dgbtrs ('Notranspose', n, kl, ku, 1, rfac, lda, \n & iwork, workd(ipntr(2)), n, ierr)\n if (ierr .ne. 0) then\n print*, ' '\n print*, '_SBAND: Error with sbgtrs.'\n print*, ' '\n go to 9000\n end if\nc\n else if ( type .eq. 4 ) then\nc\nc %-----------------------------------------%\nc | Perform y <-- OP*x |\nc | = inv[A-SIGMA*M]*M | \nc | to force the starting vector into the |\nc | range of OP. |\nc %-----------------------------------------%\nc\n call dgbmv('Notranspose', n, n, kl, ku, one, mb(itop,1), \n & lda, workd(ipntr(1)), 1, zero, \n & workd(ipntr(2)), 1)\n call dgbtrs ('Notranspose', n, kl, ku, 1, rfac, lda, \n & iwork, workd(ipntr(2)), n, ierr)\n if (ierr .ne. 0) then\n print*, ' ' \n print*, '_SBAND: Error with _gbtrs.'\n print*, ' ' \n go to 9000\n end if\nc\n else if ( type .eq. 5) then\nc\nc %---------------------------------------% \nc | Perform y <-- OP*x |\nc | = inv[A-SIGMA*M]*A |\nc | to force the starting vector into the |\nc | range of OP. |\nc %---------------------------------------%\nc\n call dgbmv('Notranspose', n, n, kl, ku, one, ab(itop,1), \n & lda, workd(ipntr(1)), 1, zero, \n & workd(ipntr(2)), 1)\n call dgbtrs('Notranspose', n, kl, ku, 1, rfac, lda, \n & iwork, workd(ipntr(2)), n, ierr)\nc\n if ( ierr .ne. 0 ) then\n print*, ' '\n print*, ' _SBAND: Error with _gbtrs. '\n print*, ' '\n go to 9000\n end if\nc\n else if ( type .eq. 6 ) then\nc\nc %---------------------------------------%\nc | Perform y <-- OP*x |\nc | = (inv[A-SIGMA*M])*(A+SIGMA*M)*x | \nc | to force the starting vector into the |\nc | range of OP. | \nc %---------------------------------------%\nc\n if ( bmat .eq. 'G' ) then\n call dgbmv('Notranspose', n, n, kl, ku, one, \n & ab(itop,1), lda, workd(ipntr(1)), 1, \n & zero, workd(ipntr(2)), 1)\n call dgbmv('Notranspose', n, n, kl, ku, sigma, \n & mb(itop,1), lda, workd(ipntr(1)), 1, \n & one, workd(ipntr(2)), 1)\n else \n call dcopy(n, workd(ipntr(1)), 1, workd(ipntr(2)), 1)\n call dgbmv('Notranspose', n, n, kl, ku, one, ab(itop,1), \n & lda, workd(ipntr(1)), 1, sigma, \n & workd(ipntr(2)), 1)\n end if \nc\n call dgbtrs ('Notranspose', n, kl, ku, 1, rfac, lda, \n & iwork, workd(ipntr(2)), n, ierr)\nc\n if (ierr .ne. 0) then \n print*, ' '\n print*, '_SBAND: Error with _gbtrs.' \n print*, ' '\n go to 9000\n end if\nc\n end if\nc\n else if (ido .eq. 1) then\nc\n if ( type .eq. 1) then\nc\nc %----------------------------%\nc | Perform y <--- OP*x = A*x |\nc %----------------------------%\nc\n call dgbmv('Notranspose', n, n, kl, ku, one, ab(itop,1), \n & lda, workd(ipntr(1)), 1, zero, \n & workd(ipntr(2)), 1)\nc\n else if ( type .eq. 2) then\nc\nc %----------------------------------%\nc | Perform |\nc | y <--- OP*x = inv[A-sigma*I]*x. |\nc %----------------------------------%\nc\n call dcopy (n, workd(ipntr(1)), 1, workd(ipntr(2)), 1)\n call dgbtrs ('Notranspose', n, kl, ku, 1, rfac, lda,\n & iwork, workd(ipntr(2)), n, ierr)\n if ( ierr .ne. 0 ) then\n print*, ' '\n print*, '_SBAND: Error with _gbtrs.' \n print*, ' '\n go to 9000\n end if\nc\n else if ( type .eq. 3 ) then\nc\nc %-----------------------------------%\nc | Perform y <--- OP*x = inv[M]*A*x |\nc %-----------------------------------%\nc\n call dgbmv('Notranspose', n, n, kl, ku, one, ab(itop,1), \n & lda, workd(ipntr(1)), 1, zero, \n & workd(ipntr(2)), 1)\n call dcopy(n, workd(ipntr(2)), 1, workd(ipntr(1)), 1) \n call dgbtrs ('Notranspose', n, kl, ku, 1, rfac, lda, \n & iwork, workd(ipntr(2)), n, ierr)\n if (ierr .ne. 0) then\n print*, ' '\n print*, '_SBAND: error with _bgtrs.'\n print*, ' ' \n go to 9000\n end if\nc\n else if ( type .eq. 4 ) then\nc\nc %-------------------------------------%\nc | Perform y <-- inv(A-sigma*M)*(M*x). |\nc | (M*x) has been computed and stored |\nc | in workd(ipntr(3)). | \nc %-------------------------------------%\nc\n call dcopy(n, workd(ipntr(3)), 1, workd(ipntr(2)), 1)\n call dgbtrs ('Notranspose', n, kl, ku, 1, rfac, lda, \n & iwork, workd(ipntr(2)), n, ierr)\n if (ierr .ne. 0) then \n print*, ' '\n print*, '_SBAND: Error with _gbtrs.' \n print*, ' '\n go to 9000\n end if\nc \n else if ( type .eq. 5 ) then\nc\nc %-------------------------------% \nc | Perform y <-- OP*x |\nc | = inv[A-SIGMA*M]*A*x |\nc | B*x = A*x has been computed |\nc | and saved in workd(ipntr(3)). |\nc %-------------------------------%\nc\n call dcopy (n, workd(ipntr(3)), 1, workd(ipntr(2)), 1)\n call dgbtrs('Notranspose', n, kl, ku, 1, rfac, lda, \n & iwork, workd(ipntr(2)), n, ierr)\n if ( ierr .ne. 0 ) then\n print*, ' '\n print*, ' _SBAND: Error with _gbtrs. '\n print*, ' '\n go to 9000\n end if\nc\n else if ( type .eq. 6) then\nc\nc %---------------------------------%\nc | Perform y <-- OP*x |\nc | = inv[A-SIGMA*M]*(A+SIGMA*M)*x. | \nc | (M*x) has been saved in |\nc | workd(ipntr(3)). |\nc %---------------------------------%\nc\n if ( bmat .eq. 'G' ) then\n call dgbmv('Notranspose', n, n, kl, ku, one, \n & ab(itop,1), lda, workd(ipntr(1)), 1, \n & zero, workd(ipntr(2)), 1)\n call daxpy( n, sigma, workd(ipntr(3)), 1, \n & workd(ipntr(2)), 1 )\n else \n call dcopy (n, workd(ipntr(1)), 1, workd(ipntr(2)), 1)\n call dgbmv('Notranspose', n, n, kl, ku, one, ab(itop,1), \n & lda, workd(ipntr(1)), 1, sigma, \n & workd(ipntr(2)), 1)\n end if\n call dgbtrs('Notranspose', n, kl, ku, 1, rfac, lda, \n & iwork, workd(ipntr(2)), n, ierr)\nc\n end if\nc\n else if (ido .eq. 2) then\nc\nc %----------------------------------%\nc | Perform y <-- B*x | \nc | Note when Buckling mode is used, |\nc | B = A, otherwise B=M. | \nc %----------------------------------%\nc\n if (type .eq. 5) then\nc\nc %---------------------%\nc | Buckling Mode, B=A. |\nc %---------------------%\nc\n call dgbmv('Notranspose', n, n, kl, ku, one, \n & ab(itop,1), lda, workd(ipntr(1)), 1, \n & zero, workd(ipntr(2)), 1)\n else\n\n call dgbmv('Notranspose', n, n, kl, ku, one, \n & mb(itop,1), lda, workd(ipntr(1)), 1, \n & zero, workd(ipntr(2)), 1)\n end if\nc\n else \nc\nc %-----------------------------------------%\nc | Either we have convergence, or there is | \nc | error. |\nc %-----------------------------------------%\nc\n if ( info .lt. 0) then\nc\nc %--------------------------%\nc | Error message, check the |\nc | documentation in DSAUPD |\nc %--------------------------%\nc\n print *, ' '\n print *, ' Error with _saupd info = ',info\n print *, ' Check the documentation of _saupd '\n print *, ' '\n go to 9000\nc\n else \nc\n if ( info .eq. 1) then\n print *, ' '\n print *, ' Maximum number of iterations reached.'\n print *, ' '\n else if ( info .eq. 3) then\n print *, ' '\n print *, ' No shifts could be applied during implicit',\n & ' Arnoldi update, try increasing NCV.'\n print *, ' '\n end if\nc\n if (iparam(5) .gt. 0) then\nc\n call dseupd ( rvec, 'A', select, d, z, ldz, sigma, \n & bmat, n, which, nev, tol, resid, ncv, v, ldv, \n & iparam, ipntr, workd, workl, lworkl, info ) \nc\n if ( info .ne. 0) then\nc \nc %------------------------------------%\nc | Check the documentation of dneupd. |\nc %------------------------------------%\nc\n print *, ' ' \n print *, ' Error with _neupd = ', info\n print *, ' Check the documentation of _neupd '\n print *, ' ' \n go to 9000\nc \n end if\nc\n end if\nc\n end if\nc\n go to 9000\nc\n end if\nc\nc %----------------------------------------%\nc | L O O P B A C K to call DSAUPD again. |\nc %----------------------------------------%\nc\n go to 90 \nc\n 9000 continue\nc\n end\n", "meta": {"hexsha": "785c98cdb12e2fea36eb6f812c75eef7fcedec91", "size": 32370, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "roms_Sep2018/roms/Lib/ARPACK/EXAMPLES/BAND/dsband.f", "max_stars_repo_name": "JamiePringle/ROMScode-PringleBBLpaper", "max_stars_repo_head_hexsha": "87166b65c0d926ea04e5f17ea96d16e694bac1ea", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 63, "max_stars_repo_stars_event_min_datetime": "2018-06-21T14:11:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T11:24:36.000Z", "max_issues_repo_path": "roms_Sep2018/roms/Lib/ARPACK/EXAMPLES/BAND/dsband.f", "max_issues_repo_name": "JamiePringle/ROMScode-PringleBBLpaper", "max_issues_repo_head_hexsha": "87166b65c0d926ea04e5f17ea96d16e694bac1ea", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 105, "max_issues_repo_issues_event_min_datetime": "2019-07-08T19:27:23.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-22T02:12:16.000Z", "max_forks_repo_path": "roms_Sep2018/roms/Lib/ARPACK/EXAMPLES/BAND/dsband.f", "max_forks_repo_name": "JamiePringle/ROMScode-PringleBBLpaper", "max_forks_repo_head_hexsha": "87166b65c0d926ea04e5f17ea96d16e694bac1ea", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2018-08-23T15:59:44.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-20T06:47:22.000Z", "avg_line_length": 37.5958188153, "max_line_length": 79, "alphanum_fraction": 0.4630522088, "num_tokens": 9191, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9173026618464796, "lm_q2_score": 0.7248702642896702, "lm_q1q2_score": 0.6649254229262755}} {"text": "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC BenchIT - Performance Measurement for Scientific Applications\nC Contact: developer@benchit.org\nC\nC $Id: work.f 1 2009-09-11 12:26:19Z william $\nC $URL: svn+ssh://william@rupert.zih.tu-dresden.de/svn-base/benchit-root/BenchITv6/kernel/numerical/elementary/F77/0/0/sqrt/work.f $\nC For license details see COPYING in the package base directory\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC Kernel: Core for Square Root addict to input value\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n\n SUBROUTINE mathopsqrt( x, y)\n double precision x, y\n if(x .NE. 0.0) y=sqrt(x)\n END\n\n", "meta": {"hexsha": "9b83a809e2b57a31e0ef10a2de7df6001d65a7c0", "size": 718, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "kernel/numerical/elementary/F77/0/0/sqrt/workf.f", "max_stars_repo_name": "Arka2009/x86_64-ubench-ecolab", "max_stars_repo_head_hexsha": "38461e73617c92449f85a84176cd108fb82434b2", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "kernel/numerical/elementary/F77/0/0/sqrt/workf.f", "max_issues_repo_name": "Arka2009/x86_64-ubench-ecolab", "max_issues_repo_head_hexsha": "38461e73617c92449f85a84176cd108fb82434b2", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "kernel/numerical/elementary/F77/0/0/sqrt/workf.f", "max_forks_repo_name": "Arka2009/x86_64-ubench-ecolab", "max_forks_repo_head_hexsha": "38461e73617c92449f85a84176cd108fb82434b2", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.2352941176, "max_line_length": 132, "alphanum_fraction": 0.7994428969, "num_tokens": 215, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772417253255, "lm_q2_score": 0.7606506526772883, "lm_q1q2_score": 0.6648674244087327}} {"text": " DOUBLE PRECISION FUNCTION LINTER( XTEST, X1, Y1, X2, Y2)\nC function to linearly interpolate between two points\nC arguements (xtest,x1,y1,x2,y2)\nC function returns y value for xtest between\nC two points (x1,y1) and (x2,y2)\n DOUBLE PRECISION XTEST, X1, Y1, X2, Y2\n\nC linear coeffs\n DOUBLE PRECISION A, B\n\nC end of decs\n\n A = (Y1-Y2)/(X1-X2)\n B = (Y2*X1-Y1*X2)/(X1-X2)\n LINTER = A*XTEST + B\n RETURN\n END\n", "meta": {"hexsha": "88256cc2b9374a73729304aadda0d3e32b3b8e46", "size": 442, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/linter.f", "max_stars_repo_name": "MDAnalysis/hole2", "max_stars_repo_head_hexsha": "ed28b2ac0dfc714933ddf2befe0a06ed87ede98e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2017-06-09T14:42:10.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T09:23:08.000Z", "max_issues_repo_path": "src/linter.f", "max_issues_repo_name": "MDAnalysis/hole2", "max_issues_repo_head_hexsha": "ed28b2ac0dfc714933ddf2befe0a06ed87ede98e", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-01-06T11:08:01.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-06T11:08:01.000Z", "max_forks_repo_path": "src/linter.f", "max_forks_repo_name": "MDAnalysis/hole2", "max_forks_repo_head_hexsha": "ed28b2ac0dfc714933ddf2befe0a06ed87ede98e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2017-06-09T14:42:17.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-27T03:38:01.000Z", "avg_line_length": 24.5555555556, "max_line_length": 62, "alphanum_fraction": 0.6380090498, "num_tokens": 160, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8740772351648677, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6648674194185162}} {"text": "*> \\brief \\b CHPT21\n*\n* =========== DOCUMENTATION ===========\n*\n* Online html documentation available at \n* http://www.netlib.org/lapack/explore-html/ \n*\n* Definition:\n* ===========\n*\n* SUBROUTINE CHPT21( ITYPE, UPLO, N, KBAND, AP, D, E, U, LDU, VP,\n* TAU, WORK, RWORK, RESULT )\n* \n* .. Scalar Arguments ..\n* CHARACTER UPLO\n* INTEGER ITYPE, KBAND, LDU, N\n* ..\n* .. Array Arguments ..\n* REAL D( * ), E( * ), RESULT( 2 ), RWORK( * )\n* COMPLEX AP( * ), TAU( * ), U( LDU, * ), VP( * ),\n* $ WORK( * )\n* ..\n* \n*\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*>\n*> CHPT21 generally checks a decomposition of the form\n*>\n*> A = U S UC>\n*> where * means conjugate transpose, A is hermitian, U is\n*> unitary, and S is diagonal (if KBAND=0) or (real) symmetric\n*> tridiagonal (if KBAND=1). If ITYPE=1, then U is represented as\n*> a dense matrix, otherwise the U is expressed as a product of\n*> Householder transformations, whose vectors are stored in the\n*> array \"V\" and whose scaling constants are in \"TAU\"; we shall\n*> use the letter \"V\" to refer to the product of Householder\n*> transformations (which should be equal to U).\n*>\n*> Specifically, if ITYPE=1, then:\n*>\n*> RESULT(1) = | A - U S U* | / ( |A| n ulp ) *andC> RESULT(2) = | I - UU* | / ( n ulp )\n*>\n*> If ITYPE=2, then:\n*>\n*> RESULT(1) = | A - V S V* | / ( |A| n ulp )\n*>\n*> If ITYPE=3, then:\n*>\n*> RESULT(1) = | I - UV* | / ( n ulp )\n*>\n*> Packed storage means that, for example, if UPLO='U', then the columns\n*> of the upper triangle of A are stored one after another, so that\n*> A(1,j+1) immediately follows A(j,j) in the array AP. Similarly, if\n*> UPLO='L', then the columns of the lower triangle of A are stored one\n*> after another in AP, so that A(j+1,j+1) immediately follows A(n,j)\n*> in the array AP. This means that A(i,j) is stored in:\n*>\n*> AP( i + j*(j-1)/2 ) if UPLO='U'\n*>\n*> AP( i + (2*n-j)*(j-1)/2 ) if UPLO='L'\n*>\n*> The array VP bears the same relation to the matrix V that A does to\n*> AP.\n*>\n*> For ITYPE > 1, the transformation U is expressed as a product\n*> of Householder transformations:\n*>\n*> If UPLO='U', then V = H(n-1)...H(1), where\n*>\n*> H(j) = I - tau(j) v(j) v(j)C>\n*> and the first j-1 elements of v(j) are stored in V(1:j-1,j+1),\n*> (i.e., VP( j*(j+1)/2 + 1 : j*(j+1)/2 + j-1 ) ),\n*> the j-th element is 1, and the last n-j elements are 0.\n*>\n*> If UPLO='L', then V = H(1)...H(n-1), where\n*>\n*> H(j) = I - tau(j) v(j) v(j)C>\n*> and the first j elements of v(j) are 0, the (j+1)-st is 1, and the\n*> (j+2)-nd through n-th elements are stored in V(j+2:n,j) (i.e.,\n*> in VP( (2*n-j)*(j-1)/2 + j+2 : (2*n-j)*(j-1)/2 + n ) .)\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in] ITYPE\n*> \\verbatim\n*> ITYPE is INTEGER\n*> Specifies the type of tests to be performed.\n*> 1: U expressed as a dense unitary matrix:\n*> RESULT(1) = | A - U S U* | / ( |A| n ulp ) *andC> RESULT(2) = | I - UU* | / ( n ulp )\n*>\n*> 2: U expressed as a product V of Housholder transformations:\n*> RESULT(1) = | A - V S V* | / ( |A| n ulp )\n*>\n*> 3: U expressed both as a dense unitary matrix and\n*> as a product of Housholder transformations:\n*> RESULT(1) = | I - UV* | / ( n ulp )\n*> \\endverbatim\n*>\n*> \\param[in] UPLO\n*> \\verbatim\n*> UPLO is CHARACTER\n*> If UPLO='U', the upper triangle of A and V will be used and\n*> the (strictly) lower triangle will not be referenced.\n*> If UPLO='L', the lower triangle of A and V will be used and\n*> the (strictly) upper triangle will not be referenced.\n*> \\endverbatim\n*>\n*> \\param[in] N\n*> \\verbatim\n*> N is INTEGER\n*> The size of the matrix. If it is zero, CHPT21 does nothing.\n*> It must be at least zero.\n*> \\endverbatim\n*>\n*> \\param[in] KBAND\n*> \\verbatim\n*> KBAND is INTEGER\n*> The bandwidth of the matrix. It may only be zero or one.\n*> If zero, then S is diagonal, and E is not referenced. If\n*> one, then S is symmetric tri-diagonal.\n*> \\endverbatim\n*>\n*> \\param[in] AP\n*> \\verbatim\n*> AP is COMPLEX array, dimension (N*(N+1)/2)\n*> The original (unfactored) matrix. It is assumed to be\n*> hermitian, and contains the columns of just the upper\n*> triangle (UPLO='U') or only the lower triangle (UPLO='L'),\n*> packed one after another.\n*> \\endverbatim\n*>\n*> \\param[in] D\n*> \\verbatim\n*> D is REAL array, dimension (N)\n*> The diagonal of the (symmetric tri-) diagonal matrix.\n*> \\endverbatim\n*>\n*> \\param[in] E\n*> \\verbatim\n*> E is REAL array, dimension (N)\n*> The off-diagonal of the (symmetric tri-) diagonal matrix.\n*> E(1) is the (1,2) and (2,1) element, E(2) is the (2,3) and\n*> (3,2) element, etc.\n*> Not referenced if KBAND=0.\n*> \\endverbatim\n*>\n*> \\param[in] U\n*> \\verbatim\n*> U is COMPLEX array, dimension (LDU, N)\n*> If ITYPE=1 or 3, this contains the unitary matrix in\n*> the decomposition, expressed as a dense matrix. If ITYPE=2,\n*> then it is not referenced.\n*> \\endverbatim\n*>\n*> \\param[in] LDU\n*> \\verbatim\n*> LDU is INTEGER\n*> The leading dimension of U. LDU must be at least N and\n*> at least 1.\n*> \\endverbatim\n*>\n*> \\param[in] VP\n*> \\verbatim\n*> VP is REAL array, dimension (N*(N+1)/2)\n*> If ITYPE=2 or 3, the columns of this array contain the\n*> Householder vectors used to describe the unitary matrix\n*> in the decomposition, as described in purpose.\n*> *NOTE* If ITYPE=2 or 3, V is modified and restored. The\n*> subdiagonal (if UPLO='L') or the superdiagonal (if UPLO='U')\n*> is set to one, and later reset to its original value, during\n*> the course of the calculation.\n*> If ITYPE=1, then it is neither referenced nor modified.\n*> \\endverbatim\n*>\n*> \\param[in] TAU\n*> \\verbatim\n*> TAU is COMPLEX array, dimension (N)\n*> If ITYPE >= 2, then TAU(j) is the scalar factor of\n*> v(j) v(j)* in the Householder transformation H(j) of\n*> the product U = H(1)...H(n-2)\n*> If ITYPE < 2, then TAU is not referenced.\n*> \\endverbatim\n*>\n*> \\param[out] WORK\n*> \\verbatim\n*> WORK is COMPLEX array, dimension (N**2)\n*> Workspace.\n*> \\endverbatim\n*>\n*> \\param[out] RWORK\n*> \\verbatim\n*> RWORK is REAL array, dimension (N)\n*> Workspace.\n*> \\endverbatim\n*>\n*> \\param[out] RESULT\n*> \\verbatim\n*> RESULT is REAL array, dimension (2)\n*> The values computed by the two tests described above. The\n*> values are currently limited to 1/ulp, to avoid overflow.\n*> RESULT(1) is always modified. RESULT(2) is modified only\n*> if ITYPE=1.\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee \n*> \\author Univ. of California Berkeley \n*> \\author Univ. of Colorado Denver \n*> \\author NAG Ltd. \n*\n*> \\date November 2011\n*\n*> \\ingroup complex_eig\n*\n* =====================================================================\n SUBROUTINE CHPT21( ITYPE, UPLO, N, KBAND, AP, D, E, U, LDU, VP,\n $ TAU, WORK, RWORK, RESULT )\n*\n* -- LAPACK test routine (version 3.4.0) --\n* -- LAPACK is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n* November 2011\n*\n* .. Scalar Arguments ..\n CHARACTER UPLO\n INTEGER ITYPE, KBAND, LDU, N\n* ..\n* .. Array Arguments ..\n REAL D( * ), E( * ), RESULT( 2 ), RWORK( * )\n COMPLEX AP( * ), TAU( * ), U( LDU, * ), VP( * ),\n $ WORK( * )\n* ..\n*\n* =====================================================================\n*\n* .. Parameters ..\n REAL ZERO, ONE, TEN\n PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0, TEN = 10.0E+0 )\n REAL HALF\n PARAMETER ( HALF = 1.0E+0 / 2.0E+0 )\n COMPLEX CZERO, CONE\n PARAMETER ( CZERO = ( 0.0E+0, 0.0E+0 ),\n $ CONE = ( 1.0E+0, 0.0E+0 ) )\n* ..\n* .. Local Scalars ..\n LOGICAL LOWER\n CHARACTER CUPLO\n INTEGER IINFO, J, JP, JP1, JR, LAP\n REAL ANORM, ULP, UNFL, WNORM\n COMPLEX TEMP, VSAVE\n* ..\n* .. External Functions ..\n LOGICAL LSAME\n REAL CLANGE, CLANHP, SLAMCH\n COMPLEX CDOTC\n EXTERNAL LSAME, CLANGE, CLANHP, SLAMCH, CDOTC\n* ..\n* .. External Subroutines ..\n EXTERNAL CAXPY, CCOPY, CGEMM, CHPMV, CHPR, CHPR2,\n $ CLACPY, CLASET, CUPMTR\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC CMPLX, MAX, MIN, REAL\n* ..\n* .. Executable Statements ..\n*\n* Constants\n*\n RESULT( 1 ) = ZERO\n IF( ITYPE.EQ.1 )\n $ RESULT( 2 ) = ZERO\n IF( N.LE.0 )\n $ RETURN\n*\n LAP = ( N*( N+1 ) ) / 2\n*\n IF( LSAME( UPLO, 'U' ) ) THEN\n LOWER = .FALSE.\n CUPLO = 'U'\n ELSE\n LOWER = .TRUE.\n CUPLO = 'L'\n END IF\n*\n UNFL = SLAMCH( 'Safe minimum' )\n ULP = SLAMCH( 'Epsilon' )*SLAMCH( 'Base' )\n*\n* Some Error Checks\n*\n IF( ITYPE.LT.1 .OR. ITYPE.GT.3 ) THEN\n RESULT( 1 ) = TEN / ULP\n RETURN\n END IF\n*\n* Do Test 1\n*\n* Norm of A:\n*\n IF( ITYPE.EQ.3 ) THEN\n ANORM = ONE\n ELSE\n ANORM = MAX( CLANHP( '1', CUPLO, N, AP, RWORK ), UNFL )\n END IF\n*\n* Compute error matrix:\n*\n IF( ITYPE.EQ.1 ) THEN\n*\n* ITYPE=1: error = A - U S U*\n*\n CALL CLASET( 'Full', N, N, CZERO, CZERO, WORK, N )\n CALL CCOPY( LAP, AP, 1, WORK, 1 )\n*\n DO 10 J = 1, N\n CALL CHPR( CUPLO, N, -D( J ), U( 1, J ), 1, WORK )\n 10 CONTINUE\n*\n IF( N.GT.1 .AND. KBAND.EQ.1 ) THEN\n DO 20 J = 1, N - 1\n CALL CHPR2( CUPLO, N, -CMPLX( E( J ) ), U( 1, J ), 1,\n $ U( 1, J-1 ), 1, WORK )\n 20 CONTINUE\n END IF\n WNORM = CLANHP( '1', CUPLO, N, WORK, RWORK )\n*\n ELSE IF( ITYPE.EQ.2 ) THEN\n*\n* ITYPE=2: error = V S V* - A\n*\n CALL CLASET( 'Full', N, N, CZERO, CZERO, WORK, N )\n*\n IF( LOWER ) THEN\n WORK( LAP ) = D( N )\n DO 40 J = N - 1, 1, -1\n JP = ( ( 2*N-J )*( J-1 ) ) / 2\n JP1 = JP + N - J\n IF( KBAND.EQ.1 ) THEN\n WORK( JP+J+1 ) = ( CONE-TAU( J ) )*E( J )\n DO 30 JR = J + 2, N\n WORK( JP+JR ) = -TAU( J )*E( J )*VP( JP+JR )\n 30 CONTINUE\n END IF\n*\n IF( TAU( J ).NE.CZERO ) THEN\n VSAVE = VP( JP+J+1 )\n VP( JP+J+1 ) = CONE\n CALL CHPMV( 'L', N-J, CONE, WORK( JP1+J+1 ),\n $ VP( JP+J+1 ), 1, CZERO, WORK( LAP+1 ), 1 )\n TEMP = -HALF*TAU( J )*CDOTC( N-J, WORK( LAP+1 ), 1,\n $ VP( JP+J+1 ), 1 )\n CALL CAXPY( N-J, TEMP, VP( JP+J+1 ), 1, WORK( LAP+1 ),\n $ 1 )\n CALL CHPR2( 'L', N-J, -TAU( J ), VP( JP+J+1 ), 1,\n $ WORK( LAP+1 ), 1, WORK( JP1+J+1 ) )\n*\n VP( JP+J+1 ) = VSAVE\n END IF\n WORK( JP+J ) = D( J )\n 40 CONTINUE\n ELSE\n WORK( 1 ) = D( 1 )\n DO 60 J = 1, N - 1\n JP = ( J*( J-1 ) ) / 2\n JP1 = JP + J\n IF( KBAND.EQ.1 ) THEN\n WORK( JP1+J ) = ( CONE-TAU( J ) )*E( J )\n DO 50 JR = 1, J - 1\n WORK( JP1+JR ) = -TAU( J )*E( J )*VP( JP1+JR )\n 50 CONTINUE\n END IF\n*\n IF( TAU( J ).NE.CZERO ) THEN\n VSAVE = VP( JP1+J )\n VP( JP1+J ) = CONE\n CALL CHPMV( 'U', J, CONE, WORK, VP( JP1+1 ), 1, CZERO,\n $ WORK( LAP+1 ), 1 )\n TEMP = -HALF*TAU( J )*CDOTC( J, WORK( LAP+1 ), 1,\n $ VP( JP1+1 ), 1 )\n CALL CAXPY( J, TEMP, VP( JP1+1 ), 1, WORK( LAP+1 ),\n $ 1 )\n CALL CHPR2( 'U', J, -TAU( J ), VP( JP1+1 ), 1,\n $ WORK( LAP+1 ), 1, WORK )\n VP( JP1+J ) = VSAVE\n END IF\n WORK( JP1+J+1 ) = D( J+1 )\n 60 CONTINUE\n END IF\n*\n DO 70 J = 1, LAP\n WORK( J ) = WORK( J ) - AP( J )\n 70 CONTINUE\n WNORM = CLANHP( '1', CUPLO, N, WORK, RWORK )\n*\n ELSE IF( ITYPE.EQ.3 ) THEN\n*\n* ITYPE=3: error = U V* - I\n*\n IF( N.LT.2 )\n $ RETURN\n CALL CLACPY( ' ', N, N, U, LDU, WORK, N )\n CALL CUPMTR( 'R', CUPLO, 'C', N, N, VP, TAU, WORK, N,\n $ WORK( N**2+1 ), IINFO )\n IF( IINFO.NE.0 ) THEN\n RESULT( 1 ) = TEN / ULP\n RETURN\n END IF\n*\n DO 80 J = 1, N\n WORK( ( N+1 )*( J-1 )+1 ) = WORK( ( N+1 )*( J-1 )+1 ) - CONE\n 80 CONTINUE\n*\n WNORM = CLANGE( '1', N, N, WORK, N, RWORK )\n END IF\n*\n IF( ANORM.GT.WNORM ) THEN\n RESULT( 1 ) = ( WNORM / ANORM ) / ( N*ULP )\n ELSE\n IF( ANORM.LT.ONE ) THEN\n RESULT( 1 ) = ( MIN( WNORM, N*ANORM ) / ANORM ) / ( N*ULP )\n ELSE\n RESULT( 1 ) = MIN( WNORM / ANORM, REAL( N ) ) / ( N*ULP )\n END IF\n END IF\n*\n* Do Test 2\n*\n* Compute UU* - I\n*\n IF( ITYPE.EQ.1 ) THEN\n CALL CGEMM( 'N', 'C', N, N, N, CONE, U, LDU, U, LDU, CZERO,\n $ WORK, N )\n*\n DO 90 J = 1, N\n WORK( ( N+1 )*( J-1 )+1 ) = WORK( ( N+1 )*( J-1 )+1 ) - CONE\n 90 CONTINUE\n*\n RESULT( 2 ) = MIN( CLANGE( '1', N, N, WORK, N, RWORK ),\n $ REAL( N ) ) / ( N*ULP )\n END IF\n*\n RETURN\n*\n* End of CHPT21\n*\n END\n", "meta": {"hexsha": "00456e02a4235fc46f5385f861633ade0406aca0", "size": 14471, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "old/lapack-test/3.5.0/EIG/chpt21.f", "max_stars_repo_name": "haampie/libflame", "max_stars_repo_head_hexsha": "a6b27af9b7ef91ec2724b52c7c09b681379a3470", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 199, "max_stars_repo_stars_event_min_datetime": "2015-02-06T06:05:32.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T05:20:33.000Z", "max_issues_repo_path": "old/lapack-test/3.5.0/EIG/chpt21.f", "max_issues_repo_name": "haampie/libflame", "max_issues_repo_head_hexsha": "a6b27af9b7ef91ec2724b52c7c09b681379a3470", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 44, "max_issues_repo_issues_event_min_datetime": "2015-05-10T18:14:52.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-22T08:22:10.000Z", "max_forks_repo_path": "old/lapack-test/3.5.0/EIG/chpt21.f", "max_forks_repo_name": "haampie/libflame", "max_forks_repo_head_hexsha": "a6b27af9b7ef91ec2724b52c7c09b681379a3470", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 70, "max_forks_repo_forks_event_min_datetime": "2015-02-07T04:53:03.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T05:20:36.000Z", "avg_line_length": 31.944812362, "max_line_length": 114, "alphanum_fraction": 0.4622348145, "num_tokens": 4742, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044095, "lm_q2_score": 0.760650658103136, "lm_q1q2_score": 0.6648674191709094}} {"text": "module colatitudinal_derivative_routines\n\n use spherepack_precision, only: &\n wp, & ! working precision\n ip, & ! integer precision\n PI\n\n use type_SpherepackUtility, only: &\n SpherepackUtility\n\n use gaussian_latitudes_and_weights_routines, only: &\n compute_gaussian_latitudes_and_weights\n\n ! Explicit typing only\n implicit none\n\n ! Everything is private unless stated otherwise\n private\n public :: vtsec, vtseci, initialize_vtsec\n public :: vtses, vtsesi, initialize_vtses\n public :: vtsgc, vtsgci, initialize_vtsgc\n public :: vtsgs, vtsgsi, initialize_vtsgs\n public :: check_calling_arguments, check_init_calling_arguments\n public :: get_lwvts, get_lwvts_saved\n\n ! Parameters confined to the module\n real(wp), parameter :: ZERO = 0.0_wp\n real(wp), parameter :: HALF = 0.5_wp\n\n ! Declare interfaces for submodule implementation\n interface\n module subroutine vtsec(nlat, nlon, ityp, nt, vt, wt, idvw, jdvw, br, bi, cr, ci, &\n mdab, ndab, wvts, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n integer(ip), intent(in) :: ityp\n integer(ip), intent(in) :: nt\n real(wp), intent(out) :: vt(idvw, jdvw, nt)\n real(wp), intent(out) :: wt(idvw, jdvw, nt)\n integer(ip), intent(in) :: idvw\n integer(ip), intent(in) :: jdvw\n real(wp), intent(in) :: br(mdab, ndab, nt)\n real(wp), intent(in) :: bi(mdab, ndab, nt)\n real(wp), intent(in) :: cr(mdab, ndab, nt)\n real(wp), intent(in) :: ci(mdab, ndab, nt)\n integer(ip), intent(in) :: mdab\n integer(ip), intent(in) :: ndab\n real(wp), intent(in) :: wvts(:)\n integer(ip), intent(out) :: ierror\n end subroutine vtsec\n\n module subroutine vtses(nlat, nlon, ityp, nt, vt, wt, idvw, jdvw, br, bi, cr, ci, &\n mdab, ndab, wvts, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n integer(ip), intent(in) :: ityp\n integer(ip), intent(in) :: nt\n real(wp), intent(out) :: vt(idvw, jdvw, nt)\n real(wp), intent(out) :: wt(idvw, jdvw, nt)\n integer(ip), intent(in) :: idvw\n integer(ip), intent(in) :: jdvw\n real(wp), intent(in) :: br(mdab, ndab, nt)\n real(wp), intent(in) :: bi(mdab, ndab, nt)\n real(wp), intent(in) :: cr(mdab, ndab, nt)\n real(wp), intent(in) :: ci(mdab, ndab, nt)\n integer(ip), intent(in) :: mdab\n integer(ip), intent(in) :: ndab\n real(wp), intent(in) :: wvts(:)\n integer(ip), intent(out) :: ierror\n end subroutine vtses\n\n module subroutine vtsgc(nlat, nlon, ityp, nt, vt, wt, idvw, jdvw, br, bi, cr, ci, &\n mdab, ndab, wvts, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n integer(ip), intent(in) :: ityp\n integer(ip), intent(in) :: nt\n real(wp), intent(out) :: vt(idvw, jdvw, nt)\n real(wp), intent(out) :: wt(idvw, jdvw, nt)\n integer(ip), intent(in) :: idvw\n integer(ip), intent(in) :: jdvw\n real(wp), intent(in) :: br(mdab, ndab, nt)\n real(wp), intent(in) :: bi(mdab, ndab, nt)\n real(wp), intent(in) :: cr(mdab, ndab, nt)\n real(wp), intent(in) :: ci(mdab, ndab, nt)\n integer(ip), intent(in) :: mdab\n integer(ip), intent(in) :: ndab\n real(wp), intent(in) :: wvts(:)\n integer(ip), intent(out) :: ierror\n end subroutine vtsgc\n\n module subroutine vtsgs(nlat, nlon, ityp, nt, vt, wt, idvw, jdvw, br, bi, cr, ci, &\n mdab, ndab, wvts, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n integer(ip), intent(in) :: ityp\n integer(ip), intent(in) :: nt\n real(wp), intent(out) :: vt(idvw, jdvw, nt)\n real(wp), intent(out) :: wt(idvw, jdvw, nt)\n integer(ip), intent(in) :: idvw\n integer(ip), intent(in) :: jdvw\n real(wp), intent(in) :: br(mdab, ndab, nt)\n real(wp), intent(in) :: bi(mdab, ndab, nt)\n real(wp), intent(in) :: cr(mdab, ndab, nt)\n real(wp), intent(in) :: ci(mdab, ndab, nt)\n integer(ip), intent(in) :: mdab\n integer(ip), intent(in) :: ndab\n real(wp), intent(in) :: wvts(:)\n integer(ip), intent(out) :: ierror\n end subroutine vtsgs\n\n module subroutine vtseci(nlat, nlon, wvts, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n real(wp), intent(out) :: wvts(:)\n integer(ip), intent(out) :: ierror\n end subroutine vtseci\n\n module subroutine vtsesi(nlat, nlon, wvts, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n real(wp), intent(out) :: wvts(:)\n integer(ip), intent(out) :: ierror\n end subroutine vtsesi\n\n module subroutine vtsgci(nlat, nlon, wvts, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n real(wp), intent(out) :: wvts(:)\n integer(ip), intent(out) :: ierror\n end subroutine vtsgci\n\n module subroutine vtsgsi(nlat, nlon, wvts, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n real(wp), intent(out) :: wvts(:)\n integer(ip), intent(out) :: ierror\n end subroutine vtsgsi\n end interface\n\ncontains\n\n subroutine initialize_vtsec(nlat, nlon, wavetable, error_flag)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n real(wp), allocatable, intent(out) :: wavetable(:)\n integer(ip), intent(out) :: error_flag\n\n ! Local variables\n type(SpherepackUtility) :: util\n\n ! Initialize wavetable\n call util%initialize_wavetable(nlat, nlon, wavetable, &\n get_lwvts, vtseci, error_flag)\n\n ! Check error flag\n if (error_flag /= 0) then\n error stop \"Failed to initialize wavetable for vtsec\"\n end if\n\n end subroutine initialize_vtsec\n\n subroutine initialize_vtsgc(nlat, nlon, wavetable, error_flag)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n real(wp), allocatable, intent(out) :: wavetable(:)\n integer(ip), intent(out) :: error_flag\n\n ! Local variables\n type(SpherepackUtility) :: util\n\n ! Initialize wavetable\n call util%initialize_wavetable(nlat, nlon, wavetable, &\n get_lwvts, vtsgci, error_flag)\n\n ! Check error flag\n if (error_flag /= 0) then\n error stop \"Failed to initialize wavetable for vtsgc\"\n end if\n\n end subroutine initialize_vtsgc\n\n subroutine initialize_vtses(nlat, nlon, wavetable, error_flag)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n real(wp), allocatable, intent(out) :: wavetable(:)\n integer(ip), intent(out) :: error_flag\n\n ! Local variables\n type(SpherepackUtility) :: util\n\n ! Initialize wavetable\n call util%initialize_wavetable(nlat, nlon, wavetable, &\n get_lwvts_saved, vtsesi, error_flag)\n\n ! Check error flag\n if (error_flag /= 0) then\n error stop \"Failed to initialize wavetable for vtses\"\n end if\n\n end subroutine initialize_vtses\n\n subroutine initialize_vtsgs(nlat, nlon, wavetable, error_flag)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n real(wp), allocatable, intent(out) :: wavetable(:)\n integer(ip), intent(out) :: error_flag\n\n ! Local variables\n type(SpherepackUtility) :: util\n\n ! Initialize wavetable\n call util%initialize_wavetable(nlat, nlon, wavetable, &\n get_lwvts_saved, vtsgsi, error_flag)\n\n ! Check error flag\n if (error_flag /= 0) then\n error stop \"Failed to initialize wavetable for vtsgs\"\n end if\n\n end subroutine initialize_vtsgs\n\n subroutine check_init_calling_arguments(&\n nlat, nlon, wvts, error_flag, required_size)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n real(wp), intent(in) :: wvts(:)\n integer(ip), intent(out) :: error_flag\n integer(ip), intent(in) :: required_size\n\n ! Check calling arguments\n if (nlat < 3) then\n error_flag = 1\n else if (nlon < 1) then\n error_flag = 2\n else if (size(wvts) < required_size) then\n error_flag = 3\n else\n error_flag = 0\n end if\n\n end subroutine check_init_calling_arguments\n\n subroutine check_calling_arguments( &\n nlat, nlon, ityp, nt, idvw, jdvw, mdab, ndab, wvts, error_flag, required_size)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n integer(ip), intent(in) :: ityp\n integer(ip), intent(in) :: nt\n integer(ip), intent(in) :: idvw\n integer(ip), intent(in) :: jdvw\n integer(ip), intent(in) :: mdab\n integer(ip), intent(in) :: ndab\n real(wp), intent(in) :: wvts(:)\n integer(ip), intent(out) :: error_flag\n integer(ip), intent(in) :: required_size\n\n ! Local variable\n integer(ip) :: imid, mmax\n\n imid = (nlat + 1)/2\n mmax = min(nlat, (nlon + 1)/2)\n\n ! Check calling arguments\n if (nlat < 3) then\n error_flag = 1\n else if (nlon < 1) then\n error_flag = 2\n else if (ityp < 0 .or. ityp > 8) then\n error_flag = 3\n else if (nt < 0) then\n error_flag = 4\n else if ((ityp <= 2 .and. idvw < nlat) &\n .or. &\n (ityp > 2 .and. idvw < imid)) then\n error_flag = 5\n else if (jdvw < nlon) then\n error_flag = 6\n else if (mdab < mmax) then\n error_flag = 7\n else if (ndab < nlat) then\n error_flag = 8\n else if (size(wvts) < required_size) then\n error_flag = 9\n else\n error_flag = 0\n end if\n\n end subroutine check_calling_arguments\n\n pure function get_lwvts(nlat, nlon) &\n result (return_value)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n integer(ip) :: return_value\n\n ! Local variables\n integer(ip) :: imid, lzz1, mmax, labc\n\n imid = (nlat + 1)/2\n lzz1 = 2*nlat*imid\n mmax = min(nlat, (nlon + 1)/2)\n labc = 3*(max(mmax-2, 0)*(2 * nlat - mmax - 1))/2\n return_value = 2*(lzz1 + labc) + nlon + 15\n\n end function get_lwvts\n\n pure function get_lwvts_saved(nlat, nlon) &\n result (return_value)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n integer(ip) :: return_value\n\n ! Local variables\n integer(ip) :: imid, lzimn, mmax\n\n mmax = min(nlat, nlon/2+1)\n imid = (nlat + 1)/2\n lzimn = (imid * mmax * (2*nlat - mmax + 1))/2\n return_value = (2 * lzimn) + nlon + 15\n\n end function get_lwvts_saved\n\nend module colatitudinal_derivative_routines\n", "meta": {"hexsha": "cd8cef4609ff9f3e8db50b38ebeb93b5adaeaa99", "size": 12277, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/colatitudinal_derivative_routines.f90", "max_stars_repo_name": "jlokimlin/spherepack4.1", "max_stars_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-06-28T14:01:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T21:59:28.000Z", "max_issues_repo_path": "src/colatitudinal_derivative_routines.f90", "max_issues_repo_name": "jlokimlin/spherepack4.1", "max_issues_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2016-05-07T23:00:35.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-22T23:52:30.000Z", "max_forks_repo_path": "src/colatitudinal_derivative_routines.f90", "max_forks_repo_name": "jlokimlin/spherepack4.1", "max_forks_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-06-28T14:03:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T12:53:54.000Z", "avg_line_length": 34.3893557423, "max_line_length": 91, "alphanum_fraction": 0.5353913823, "num_tokens": 3434, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772384450967, "lm_q2_score": 0.7606506418255927, "lm_q1q2_score": 0.6648674124284044}} {"text": "************************************************************************\r\n*\r\n* Function DLNGAM Called by: EXPON, EXPVAR\r\n*\r\n* compute logarithm of the GAMMA function; valid only for XX>0\r\n*\r\n************************************************************************\r\n DOUBLE PRECISION FUNCTION DLNGAM(XX)\r\n*\r\n* subroutine args\r\n*\r\n DOUBLE PRECISION XX\r\n*\r\n* local vars\r\n*\r\n INTEGER*4 J\r\n DOUBLE PRECISION SER,COF(6)\r\n \r\n DATA COF /76.18009173D0,-86.50532033D0,24.01409822D0,\r\n & -1.231739516D0,1.20858003D-3,-5.36382D-6/\r\n*\r\n* \r\n*\r\n SER = 1.D0\r\n DO 10 J=1,6\r\n SER = SER+COF(J)/(XX+DBLE(J-1))\r\n 10 CONTINUE\r\n\r\n DLNGAM = ((XX-0.5D0)*LOG(XX+4.5D0)-(XX+4.5D0))\r\n & + LOG(2.50662827465D0*SER)\r\n\r\n RETURN\r\n END\r\n", "meta": {"hexsha": "1ce2d76e2c31cda488f89e62e0a113f5845d76ed", "size": 839, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "codeNexampls/[loadest]/loadsrc/loadest/source_USGS/dlngam.f", "max_stars_repo_name": "lthiamodelers/baseflow-coefficients", "max_stars_repo_head_hexsha": "183fef49548fa2e1bf0bb8cff57e96e75d629760", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "codeNexampls/[loadest]/loadsrc/loadest/source_USGS/dlngam.f", "max_issues_repo_name": "lthiamodelers/baseflow-coefficients", "max_issues_repo_head_hexsha": "183fef49548fa2e1bf0bb8cff57e96e75d629760", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "codeNexampls/[loadest]/loadsrc/loadest/source_USGS/dlngam.f", "max_forks_repo_name": "lthiamodelers/baseflow-coefficients", "max_forks_repo_head_hexsha": "183fef49548fa2e1bf0bb8cff57e96e75d629760", "max_forks_repo_licenses": ["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.6764705882, "max_line_length": 73, "alphanum_fraction": 0.4231227652, "num_tokens": 248, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299570920386, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6648650645808305}} {"text": "!----------------------------------------------------j.ostertag---------\n subroutine SPL_P(x,y,n,y2)\n! \n! jasmin ostertag IAG\n! Universitaet Stuttgart\n! 03.02.1998\n!-----------------------------------------------------------------------\n!\n! scope prepare spline interpolation\n! (natural splines)\n!-----------------------------------------------------------------------\n! declarations\n!-----------------------------------------------------------------------\nUSE TIPrecision \n \nIMPLICIT NONE \n \n \n ! Local variables. \n \nINTEGER(4) :: n, i, k \nINTEGER(4),PARAMETER :: NMAX=5000 \n \nREAL(DbKi) :: yp1, ypn,p, qn, sig, un\nREAL(DbKi) :: x(n), y(n), y2(n),u(NMAX)\n\n \n\n\n yp1 = -25.0d0 / 12.0d0 * y(1 ) &\n +48.0d0 / 12.0d0 * y(2 ) &\n -36.0d0 / 12.0d0 * y(3 ) &\n +16.0d0 / 12.0d0 * y(4 ) &\n -3.0d0 / 12.0d0 * y(5 )\n ypn = 3.0d0 / 12.0d0 * y(n-4) &\n -16.0d0 / 12.0d0 * y(n-3) &\n +36.0d0 / 12.0d0 * y(n-2) &\n -48.0d0 / 12.0d0 * y(n-1) &\n +25.0d0 / 12.0d0 * y(n )\n\n \n!-----------------------------------------------------------------------\n! prepare spline interpolation\n!-----------------------------------------------------------------------\n! lower boundary condition is set either to be \"natural\"\n!jo erste Ableitung in Punkt 1 \n if (yp1.gt..99e30) then\n y2(1) = 0.\n u(1) = 0.\n \n! or else to have a first derivative \n else\n y2(1) = -0.5\n u(1) = (3./(x(2) - x(1)))*((y(2) - y(1))/(x(2) - x(1)) - yp1)\n endif\n \n! this is the decomposition loop of the tridiagonal algorithm.\n! (y2 und u are used for temporary storage of the decomposed factors)\n do i=2,n-1\n sig = (x(i) - x(i-1))/(x(i+1) - x(i-1))\n p = sig*y2(i-1) + 2.0d0\n y2(i) = (sig - 1.0d0)/p\n u(i) = (6.0d0*((y(i+1) - y(i))/(x(i+1) - x(i)) - (y(i) - y(i-1))/ &\n (x(i) - x(i-1)))/(x(i+1) - x(i-1)) - sig*u(i-1))/p\n enddo\n \n! upper boundary condition is set either to be \"natural\"\n! erste Ableitung in Punkt n \n if (ypn.gt..99e30) then\n qn = 0.\n un = 0.\n \n! or else to have a first derivative \n else\n qn = 0.5\n un = (3.0d0/(x(n) - x(n-1)))*(ypn - (y(n) - y(n-1))/(x(n) - x(n-1))) \n endif\n \n y2(n) = (un - qn*u(n-1))/(qn*y2(n-1) + 1.0d0)\n \n! backsubstitution loop of the tridiagonal algorithm\n do k=n-1,1,-1\n y2(k) = y2(k)*y2(k+1) + u(k)\n enddo\n \n!-----------------------------------------------------------------------\n! end of subroutine\n!-----------------------------------------------------------------------\n return\n!-----------------------------------------------------------------------\n end\n", "meta": {"hexsha": "25cba91d84b0e9a24495368e33352d8a9ef279c1", "size": 3429, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "modules/aerodyn/src/AeroAcoustics/TINoise/SPL_P.f90", "max_stars_repo_name": "CarloSucameli/Openfast-noise", "max_stars_repo_head_hexsha": "b695c53ff790ac390f9fcf7ec1bf67e24688deb0", "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": "modules/aerodyn/src/AeroAcoustics/TINoise/SPL_P.f90", "max_issues_repo_name": "CarloSucameli/Openfast-noise", "max_issues_repo_head_hexsha": "b695c53ff790ac390f9fcf7ec1bf67e24688deb0", "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/aerodyn/src/AeroAcoustics/TINoise/SPL_P.f90", "max_forks_repo_name": "CarloSucameli/Openfast-noise", "max_forks_repo_head_hexsha": "b695c53ff790ac390f9fcf7ec1bf67e24688deb0", "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.2717391304, "max_line_length": 78, "alphanum_fraction": 0.2954214057, "num_tokens": 929, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92522995296862, "lm_q2_score": 0.718594386544335, "lm_q1q2_score": 0.6648650504659295}} {"text": " subroutine svd(nm,m,n,a,w,matu,u,matv,v,ierr,rv1)\nc\n integer i,j,k,l,m,n,ii,i1,kk,k1,ll,l1,mn,nm,its,ierr\n real a(nm,n),w(n),u(nm,n),v(nm,n),rv1(n)\n real c,f,g,h,s,x,y,z,scale,anorm\n logical matu,matv\nc\nc this subroutine is a translation of the algol procedure svd,\nc num. math. 14, 403-420(1970) by golub and reinsch.\nc handbook for auto. comp., vol ii-linear algebra, 134-151(1971).\nc\nc this subroutine determines the singular value decomposition\nc t\nc a=usv of a real m by n rectangular matrix. householder\nc bidiagonalization and a variant of the qr algorithm are used.\nc\nc on input.\nc\nc nm must be set to the row dimension of two-dimensional\nc array parameters as declared in the calling program\nc dimension statement. note that nm must be at least\nc as large as the maximum of m and n.\nc\nc m is the number of rows of a (and u).\nc\nc n is the number of columns of a (and u) and the order of v.\nc\nc a contains the rectangular input matrix to be decomposed.\nc\nc matu should be set to .true. if the u matrix in the\nc decomposition is desired, and to .false. otherwise.\nc\nc matv should be set to .true. if the v matrix in the\nc decomposition is desired, and to .false. otherwise.\nc\nc on output.\nc\nc a is unaltered (unless overwritten by u or v).\nc\nc w contains the n (non-negative) singular values of a (the\nc diagonal elements of s). they are unordered. if an\nc error exit is made, the singular values should be correct\nc for indices ierr+1,ierr+2,...,n.\nc\nc u contains the matrix u (orthogonal column vectors) of the\nc decomposition if matu has been set to .true. otherwise\nc u is used as a temporary array. u may coincide with a.\nc if an error exit is made, the columns of u corresponding\nc to indices of correct singular values should be correct.\nc\nc v contains the matrix v (orthogonal) of the decomposition if\nc matv has been set to .true. otherwise v is not referenced.\nc v may also coincide with a if u is not needed. if an error\nc exit is made, the columns of v corresponding to indices of\nc correct singular values should be correct.\nc\nc ierr is set to\nc zero for normal return,\nc k if the k-th singular value has not been\nc determined after 30 iterations.\nc\nc rv1 is a temporary storage array.\nc\nc questions and comments should be directed to b. s. garbow,\nc applied mathematics division, argonne national laboratory\nc\nc modified to eliminate machep\nc\n ierr = 0\nc\n do 100 i = 1, m\nc\n do 100 j = 1, n\n u(i,j) = a(i,j)\n 100 continue\nc .......... householder reduction to bidiagonal form ..........\n g = 0.0\n scale = 0.0\n anorm = 0.0\nc\n do 300 i = 1, n\n l = i + 1\n rv1(i) = scale * g\n g = 0.0\n s = 0.0\n scale = 0.0\n if (i .gt. m) go to 210\nc\n do 120 k = i, m\n 120 scale = scale + abs(u(k,i))\nc\n if (scale .eq. 0.0) go to 210\nc\n do 130 k = i, m\n u(k,i) = u(k,i) / scale\n s = s + u(k,i)**2\n 130 continue\nc\n f = u(i,i)\n g = -sign(sqrt(s),f)\n h = f * g - s\n u(i,i) = f - g\n if (i .eq. n) go to 190\nc\n do 150 j = l, n\n s = 0.0\nc\n do 140 k = i, m\n 140 s = s + u(k,i) * u(k,j)\nc\n f = s / h\nc\n do 150 k = i, m\n u(k,j) = u(k,j) + f * u(k,i)\n 150 continue\nc\n 190 do 200 k = i, m\n 200 u(k,i) = scale * u(k,i)\nc\n 210 w(i) = scale * g\n g = 0.0\n s = 0.0\n scale = 0.0\n if (i .gt. m .or. i .eq. n) go to 290\nc\n do 220 k = l, n\n 220 scale = scale + abs(u(i,k))\nc\n if (scale .eq. 0.0) go to 290\nc\n do 230 k = l, n\n u(i,k) = u(i,k) / scale\n s = s + u(i,k)**2\n 230 continue\nc\n f = u(i,l)\n g = -sign(sqrt(s),f)\n h = f * g - s\n u(i,l) = f - g\nc\n do 240 k = l, n\n 240 rv1(k) = u(i,k) / h\nc\n if (i .eq. m) go to 270\nc\n do 260 j = l, m\n s = 0.0\nc\n do 250 k = l, n\n 250 s = s + u(j,k) * u(i,k)\nc\n do 260 k = l, n\n u(j,k) = u(j,k) + s * rv1(k)\n 260 continue\nc\n 270 do 280 k = l, n\n 280 u(i,k) = scale * u(i,k)\nc\n 290 anorm = amax1(anorm,abs(w(i))+abs(rv1(i)))\n 300 continue\nc .......... accumulation of right-hand transformations ..........\n if (.not. matv) go to 410\nc .......... for i=n step -1 until 1 do -- ..........\n do 400 ii = 1, n\n i = n + 1 - ii\n if (i .eq. n) go to 390\n if (g .eq. 0.0) go to 360\nc\n do 320 j = l, n\nc .......... double division avoids possible underflow ..........\n 320 v(j,i) = (u(i,j) / u(i,l)) / g\nc\n do 350 j = l, n\n s = 0.0\nc\n do 340 k = l, n\n 340 s = s + u(i,k) * v(k,j)\nc\n do 350 k = l, n\n v(k,j) = v(k,j) + s * v(k,i)\n 350 continue\nc\n 360 do 380 j = l, n\n v(i,j) = 0.0\n v(j,i) = 0.0\n 380 continue\nc\n 390 v(i,i) = 1.0\n g = rv1(i)\n l = i\n 400 continue\nc .......... accumulation of left-hand transformations ..........\n 410 if (.not. matu) go to 510\nc ..........for i=min(m,n) step -1 until 1 do -- ..........\n mn = n\n if (m .lt. n) mn = m\nc\n do 500 ii = 1, mn\n i = mn + 1 - ii\n l = i + 1\n g = w(i)\n if (i .eq. n) go to 430\nc\n do 420 j = l, n\n 420 u(i,j) = 0.0\nc\n 430 if (g .eq. 0.0) go to 475\n if (i .eq. mn) go to 460\nc\n do 450 j = l, n\n s = 0.0\nc\n do 440 k = l, m\n 440 s = s + u(k,i) * u(k,j)\nc .......... double division avoids possible underflow ..........\n f = (s / u(i,i)) / g\nc\n do 450 k = i, m\n u(k,j) = u(k,j) + f * u(k,i)\n 450 continue\nc\n 460 do 470 j = i, m\n 470 u(j,i) = u(j,i) / g\nc\n go to 490\nc\n 475 do 480 j = i, m\n 480 u(j,i) = 0.0\nc\n 490 u(i,i) = u(i,i) + 1.0\n 500 continue\nc .......... diagonalization of the bidiagonal form ..........\nc .......... for k=n step -1 until 1 do -- ..........\n 510 do 700 kk = 1, n\n k1 = n - kk\n k = k1 + 1\n its = 0\nc .......... test for splitting.\nc for l=k step -1 until 1 do -- ..........\n 520 do 530 ll = 1, k\n l1 = k - ll\n l = l1 + 1\n if (abs(rv1(l)) + anorm .eq. anorm) go to 565\nc .......... rv1(1) is always zero, so there is no exit\nc through the bottom of the loop ..........\n if (abs(w(l1)) + anorm .eq. anorm) go to 540\n 530 continue\nc .......... cancellation of rv1(l) if l greater than 1 ..........\n 540 c = 0.0\n s = 1.0\nc\n do 560 i = l, k\n f = s * rv1(i)\n rv1(i) = c * rv1(i)\n if (abs(f) + anorm .eq. anorm) go to 565\n g = w(i)\n h = sqrt(f*f+g*g)\n w(i) = h\n c = g / h\n s = -f / h\n if (.not. matu) go to 560\nc\n do 550 j = 1, m\n y = u(j,l1)\n z = u(j,i)\n u(j,l1) = y * c + z * s\n u(j,i) = -y * s + z * c\n 550 continue\nc\n 560 continue\nc .......... test for convergence ..........\n 565 z = w(k)\n if (l .eq. k) go to 650\nc .......... shift from bottom 2 by 2 minor ..........\n if (its .eq. 30) go to 1000\n its = its + 1\n x = w(l)\n y = w(k1)\n g = rv1(k1)\n h = rv1(k)\n f = ((y - z) * (y + z) + (g - h) * (g + h)) / (2.0 * h * y)\n g = sqrt(f*f+1.0)\n f = ((x - z) * (x + z) + h * (y / (f + sign(g,f)) - h)) / x\nc .......... next qr transformation ..........\n c = 1.0\n s = 1.0\nc\n do 600 i1 = l, k1\n i = i1 + 1\n g = rv1(i)\n y = w(i)\n h = s * g\n g = c * g\n z = sqrt(f*f+h*h)\n rv1(i1) = z\n c = f / z\n s = h / z\n f = x * c + g * s\n g = -x * s + g * c\n h = y * s\n y = y * c\n if (.not. matv) go to 575\nc\n do 570 j = 1, n\n x = v(j,i1)\n z = v(j,i)\n v(j,i1) = x * c + z * s\n v(j,i) = -x * s + z * c\n 570 continue\nc\n 575 z = sqrt(f*f+h*h)\n w(i1) = z\nc .......... rotation can be arbitrary if z is zero ..........\n if (z .eq. 0.0) go to 580\n c = f / z\n s = h / z\n 580 f = c * g + s * y\n x = -s * g + c * y\n if (.not. matu) go to 600\nc\n do 590 j = 1, m\n y = u(j,i1)\n z = u(j,i)\n u(j,i1) = y * c + z * s\n u(j,i) = -y * s + z * c\n 590 continue\nc\n 600 continue\nc\n rv1(l) = 0.0\n rv1(k) = f\n w(k) = x\n go to 520\nc .......... convergence ..........\n 650 if (z .ge. 0.0) go to 700\nc .......... w(k) is made non-negative ..........\n w(k) = -z\n if (.not. matv) go to 700\nc\n do 690 j = 1, n\n 690 v(j,k) = -v(j,k)\nc\n 700 continue\nc\n go to 1001\nc .......... set error -- no convergence to a\nc singular value after 30 iterations ..........\n 1000 ierr = k\n 1001 return\n end\n", "meta": {"hexsha": "f3c772300a981a6043c23c112988384905f32741", "size": 9687, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Resources/netlib.org/sfmm/svd.f", "max_stars_repo_name": "RobinSchmidt/LAPackCPP", "max_stars_repo_head_hexsha": "e0a47c2f93f1af54afc6c60f3330ce81260e2a2b", "max_stars_repo_licenses": ["Intel"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Resources/netlib.org/sfmm/svd.f", "max_issues_repo_name": "RobinSchmidt/LAPackCPP", "max_issues_repo_head_hexsha": "e0a47c2f93f1af54afc6c60f3330ce81260e2a2b", "max_issues_repo_licenses": ["Intel"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Resources/netlib.org/sfmm/svd.f", "max_forks_repo_name": "RobinSchmidt/LAPackCPP", "max_forks_repo_head_hexsha": "e0a47c2f93f1af54afc6c60f3330ce81260e2a2b", "max_forks_repo_licenses": ["Intel"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.5982905983, "max_line_length": 70, "alphanum_fraction": 0.4352224631, "num_tokens": 3342, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92522995296862, "lm_q2_score": 0.7185943805178139, "lm_q1q2_score": 0.6648650448900115}} {"text": "!version: serial with no mpi\n! solves the 2d Stommel Model of Ocean Circulation \n! using a Five-point stencil and Jacobi iteration\n!\n! gamma*((d(d(psi)/dx)/dx) + (d(d(psi)/dy)/dy))\n! +beta(d(psi)/dx)=-alpha*sin(pi*y/(2*ly))\n!\nmodule numz\n! module defines the basic real type and pi\n integer, parameter:: b8 = selected_real_kind(14)\n real(b8), parameter :: pi = 3.141592653589793239_b8\nend module\n!*********************\nmodule input\n! module contains the inputs \n use numz\n integer nx,ny ! number of interior points for our grid (50 50)\n real(b8) lx,ly ! physical size of our grid (2000 2000)\n real(b8) alpha,beta,gamma ! parameters of the calculation (1.0e-9 2.25e-11 3.0e-6)\n integer steps ! number of Jacobi iteration steps (60)\nend module\n!*********************\nmodule constants\n! this module contains the invariants (constants) of the\n! calculation. these values are determined in the main\n! routine and used in the do_jacobi Jacobi iteration subroutine\n! a6 is used in the force function\n use numz\n real(b8) dx,dy,a1,a2,a3,a4,a5,a6\n real(b8), allocatable:: for(:,:) ! our force grid\nend module\n!*********************\nmodule face\n! this module contains the interface for the two subroutines\n! that modify the grid. an interface is a good idea in this\n! case because we are passing allocatable arrays\n interface bc\n subroutine bc (psi,i1,i2,j1,j2)\n! sets the boundary conditions\n! input is the grid and the indices for the interior cells\n use numz\n integer,intent(in):: i1,i2,j1,j2\n real(b8),dimension(i1:i2,j1:j2):: psi\n end subroutine\n end interface\n interface do_jacobi\n subroutine do_jacobi (psi,new_psi,diff,i1,i2,j1,j2)\n! does a single Jacobi iteration step\n! input is the grid and the indices for the interior cells\n! new_psi is temp storage for the the updated grid\n! output is the updated grid in psi and diff which is\n! the sum of the differences between the old and new grids\n use numz\n integer,intent(in):: i1,i2,j1,j2\n real(b8),dimension(i1-1:i2+1,j1-1:j2+1):: psi\n real(b8),dimension(i1-1:i2+1,j1-1:j2+1):: new_psi\n real(b8) diff\n end subroutine\n end interface\n! interface for the forcing function\n interface force\n function force(y)\n use numz\n real(b8) force,y\n end function force\n end interface \n interface do_force\n subroutine do_force (i1,i2,j1,j2)\n! sets the boundary conditions\n! input is the grid and the indices for the interior cells\n use numz\n integer,intent(in):: i1,i2,j1,j2\n end subroutine\n end interface\n! interface for routine to write the grid\n interface write_grid\n subroutine write_grid (psi,i1,i2,j1,j2)\n! input is the grid and the indices for the interior cells\n use numz\n integer,intent(in):: i1,i2,j1,j2\n real(b8),dimension(i1:i2,j1:j2):: psi\n end subroutine\n end interface\nend module", "meta": {"hexsha": "229ad4a80437c84fb60270bdb8b4ca7fe80bdabe", "size": 3062, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "make/simple/mods.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": "make/simple/mods.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": "make/simple/mods.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": 36.4523809524, "max_line_length": 86, "alphanum_fraction": 0.6485956891, "num_tokens": 841, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206818021529, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6648581978421162}} {"text": " PROGRAM xfitexy\r\nC driver for routine fitexy\r\n INTEGER NPT\r\n PARAMETER (NPT=30)\r\n REAL a,b,chi2,gasdev,q,ran1,sa,sb,siga,sigb\r\n REAL x(NPT),y(NPT),dx(NPT),dy(NPT),dz(NPT)\r\n INTEGER idum,j\r\n DATA dz /NPT*0./\r\n idum=-1\r\n do 11 j=1,NPT\r\n dx(j)=0.1+ran1(idum)\r\n dy(j)=0.1+ran1(idum)\r\n x(j)=10.+10.*gasdev(idum)\r\n y(j)=2.*x(j)-5.+dy(j)*gasdev(idum)\r\n x(j)=x(j)+dx(j)*gasdev(idum)\r\n11 continue\r\n write(*,*) 'Values of a,b,siga,sigb,chi2,q:'\r\n write(*,*) 'Fit with x and y errors gives:'\r\n call fitexy(x,y,NPT,dx,dy,a,b,siga,sigb,chi2,q)\r\n write(*,'(6f11.6)') a,b,siga,sigb,chi2,q\r\n write(*,*)\r\n write(*,*) 'Setting x errors to zero gives:'\r\n call fitexy(x,y,NPT,dz,dy,a,b,siga,sigb,chi2,q)\r\n write(*,'(6f11.6)') a,b,siga,sigb,chi2,q\r\n write(*,*) '...to be compared with fit result:'\r\n call fit(x,y,NPT,dy,1,a,b,siga,sigb,chi2,q)\r\n write(*,'(6f11.6)') a,b,siga,sigb,chi2,q\r\n write(*,*)\r\n write(*,*) 'Setting y errors to zero gives:'\r\n call fitexy(x,y,NPT,dx,dz,a,b,siga,sigb,chi2,q)\r\n write(*,'(6f11.6)') a,b,siga,sigb,chi2,q\r\n write(*,*) '...to be compared with fit result:'\r\n call fit(y,x,NPT,dx,1,a,b,siga,sigb,chi2,q)\r\n sa=sqrt(siga**2+sigb**2*(a/b)**2)/b\r\n sb=sigb/b**2\r\n write(*,'(6f11.6)') -a/b,1./b,sa,sb,chi2,q\r\n END\r\n", "meta": {"hexsha": "fe3c2ef367f15f926a5a3d0dfa46566ea4d30734", "size": 1413, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xfitexy.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xfitexy.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xfitexy.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": 37.1842105263, "max_line_length": 54, "alphanum_fraction": 0.5286624204, "num_tokens": 567, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206765295399, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6648581939553664}} {"text": " subroutine idzr_svd(m,n,a,krank,u,v,s,ier,r)\nc\nc constructs a rank-krank SVD u diag(s) v^* approximating a,\nc where u is an m x krank matrix whose columns are orthonormal,\nc v is an n x krank matrix whose columns are orthonormal,\nc and diag(s) is a diagonal krank x krank matrix whose entries\nc are all nonnegative. This routine combines a QR code\nc (which is based on plane/Householder reflections)\nc with the LAPACK routine zgesdd.\nc\nc input:\nc m -- first dimension of a and u\nc n -- second dimension of a, and first dimension of v\nc a -- matrix to be SVD'd\nc krank -- desired rank of the approximation to a\nc\nc output:\nc u -- left singular vectors of a corresponding\nc to the k greatest singular values of a\nc v -- right singular vectors of a corresponding\nc to the k greatest singular values of a\nc s -- k greatest singular values of a\nc ier -- 0 when the routine terminates successfully;\nc nonzero when the routine encounters an error\nc\nc work:\nc r -- must be at least\nc (krank+2)*n+8*min(m,n)+6*krank**2+8*krank\nc complex*16 elements long\nc\nc _N.B._: This routine destroys a. Also, please beware that\nc the source code for this routine could be clearer.\nc\n implicit none\n character*1 jobz\n integer m,n,k,krank,ifadjoint,ldr,ldu,ldvadj,lwork,\n 1 info,j,ier,io\n real*8 s(krank)\n complex*16 a(m,n),u(m,krank),v(n*krank),r(*)\nc\nc\n io = 8*min(m,n)\nc\nc\n ier = 0\nc\nc\nc Compute a pivoted QR decomposition of a.\nc\n call idzr_qrpiv(m,n,a,krank,r,r(io+1))\nc\nc\nc Extract R from the QR decomposition.\nc\n call idz_retriever(m,n,a,krank,r(io+1))\nc\nc\nc Rearrange R according to ind.\nc\n call idz_permuter(krank,r,krank,n,r(io+1))\nc\nc\nc Use LAPACK to SVD r,\nc storing the krank (krank x 1) left singular vectors\nc in r(io+krank*n+1 : io+krank*n+krank*krank).\nc\n jobz = 'S'\n ldr = krank\n lwork = 2*(krank**2+2*krank+n)\n ldu = krank\n ldvadj = krank\nc\n call zgesdd(jobz,krank,n,r(io+1),ldr,s,r(io+krank*n+1),ldu,\n 1 v,ldvadj,r(io+krank*n+krank*krank+1),lwork,\n 2 r(io+krank*n+krank*krank+lwork+1),r,info)\nc\n if(info .ne. 0) then\n ier = info\n return\n endif\nc\nc\nc Multiply the U from R from the left by Q to obtain the U\nc for A.\nc\n do k = 1,krank\nc\n do j = 1,krank\n u(j,k) = r(io+krank*n+j+krank*(k-1))\n enddo ! j\nc\n do j = krank+1,m\n u(j,k) = 0\n enddo ! j\nc\n enddo ! k\nc\n ifadjoint = 0\n call idz_qmatmat(ifadjoint,m,n,a,krank,krank,u,r)\nc\nc\nc Take the adjoint of v to obtain r.\nc\n call idz_adjer(krank,n,v,r)\nc\nc\nc Copy r into v.\nc\n do k = 1,n*krank\n v(k) = r(k)\n enddo ! k\nc\nc\n return\n end\nc\nc\nc\nc\n", "meta": {"hexsha": "76adc7c5f250ad6bc7d0019fd3c660354106a610", "size": 3066, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "contrib/python/scipy/scipy/linalg/src/id_dist/src/idz_svd_subr_0.f", "max_stars_repo_name": "ibr11/catboost", "max_stars_repo_head_hexsha": "842a25b4fb856a61564b163b16a3f49ba35fdc14", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 6989, "max_stars_repo_stars_event_min_datetime": "2017-07-18T06:23:18.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T15:58:36.000Z", "max_issues_repo_path": "contrib/python/scipy/scipy/linalg/src/id_dist/src/idz_svd_subr_0.f", "max_issues_repo_name": "birichie/catboost", "max_issues_repo_head_hexsha": "de75c6af12cf490700e76c22072fbdc15b35d679", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1978, "max_issues_repo_issues_event_min_datetime": "2017-07-18T09:17:58.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T14:28:43.000Z", "max_forks_repo_path": "contrib/python/scipy/scipy/linalg/src/id_dist/src/idz_svd_subr_0.f", "max_forks_repo_name": "birichie/catboost", "max_forks_repo_head_hexsha": "de75c6af12cf490700e76c22072fbdc15b35d679", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1228, "max_forks_repo_forks_event_min_datetime": "2017-07-18T09:03:13.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T05:57:40.000Z", "avg_line_length": 25.55, "max_line_length": 69, "alphanum_fraction": 0.5704500978, "num_tokens": 1009, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206844384594, "lm_q2_score": 0.7371581510799252, "lm_q1q2_score": 0.6648581841613954}} {"text": "*\n************************************************************************\n*\n* File of the EXTENDED-COMPLEX Level-2 BLAS.\n* ===================================================\n*\n* SUBROUTINE ECGEMV( TRANS, M, N, ALPHA, A, LDA, X, INCX,\n* $ BETA, Y, INCY )\n*\n* SUBROUTINE ECGBMV( TRANS, M, N, KL, KU, ALPHA, A, LDA, X, INCX,\n* $ BETA, Y, INCY )\n*\n* SUBROUTINE ECHEMV( UPLO, N, ALPHA, A, LDA, X, INCX,\n* $ BETA, Y, INCY )\n*\n* SUBROUTINE ECHBMV( UPLO, N, K, ALPHA, A, LDA, X, INCX,\n* $ BETA, Y, INCY )\n*\n* SUBROUTINE ECHPMV( UPLO, N, ALPHA, AP, X, INCX, BETA, Y, INCY )\n*\n* SUBROUTINE ECTRMV( UPLO, TRANS, DIAG, N, A, LDA, X, INCX )\n*\n* SUBROUTINE ECTBMV( UPLO, TRANS, DIAG, N, K, A, LDA, X, INCX )\n*\n* SUBROUTINE ECTPMV( UPLO, TRANS, DIAG, N, AP, X, INCX )\n*\n* SUBROUTINE ECTRSV( UPLO, TRANS, DIAG, N, A, LDA, X, INCX )\n*\n* SUBROUTINE ECTBSV( UPLO, TRANS, DIAG, N, K, A, LDA, X, INCX )\n*\n* SUBROUTINE ECTPSV( UPLO, TRANS, DIAG, N, AP, X, INCX )\n*\n* SUBROUTINE ECGERU( M, N, ALPHA, X, INCX, Y, INCY, A, LDA )\n*\n* SUBROUTINE ECGERC( M, N, ALPHA, X, INCX, Y, INCY, A, LDA )\n*\n* SUBROUTINE ECHER ( UPLO, N, ALPHA, X, INCX, A, LDA )\n*\n* SUBROUTINE ECHPR ( UPLO, N, ALPHA, X, INCX, AP )\n*\n* SUBROUTINE ECHER2( UPLO, N, ALPHA, X, INCX, Y, INCY, A, LDA )\n*\n* SUBROUTINE ECHPR2( UPLO, N, ALPHA, X, INCX, Y, INCY, AP )\n*\n* See:\n*\n* Dongarra J. J., Du Croz J. J., Hammarling S. and Hanson R. J..\n* A proposal for an extended set of Fortran Basic Linear Algebra\n* Subprograms.\n*\n* Technical Memorandum No.41 (revision 1), Mathematics and\n* Computer Science Division, Argonne National Laboratory, 9700\n* South Cass Avenue, Argonne, Illinois 60439, US.\n*\n* Or\n*\n* NAG Technical Report TR3/86, Numerical Algorithms Group Ltd.,\n* NAG Central Office, 256 Banbury Road, Oxford OX2 7DE, UK, and\n* Numerical Algorithms Group Inc., 1101 31st Street, Suite 100,\n* Downers Grove, Illinois 60515-1263, USA.\n*\n************************************************************************\n*\n SUBROUTINE ECGEMV( TRANS, M, N, ALPHA, A, LDA, X, INCX,\n $ BETA, Y, INCY )\n* .. Scalar Arguments ..\n COMPLEX ALPHA, BETA\n INTEGER INCX, INCY, LDA, M, N\n CHARACTER*1 TRANS\n* .. Array Arguments ..\n COMPLEX*16 Y( * )\n COMPLEX A( LDA, * ), X( * )\n* ..\n*\n* Purpose\n* =======\n*\n* ECGEMV performs one of the matrix-vector operations\n*\n* y := alpha*A*x + beta*y, or y := alpha*A'*x + beta*y, or\n*\n* y := alpha*conjg( A' )*x + beta*y,\n*\n* where alpha and beta are scalars, x and y are vectors and A is an\n* m by n matrix. Additional precision arithmetic is used in the\n* computation.\n*\n* Parameters\n* ==========\n*\n* TRANS - CHARACTER*1.\n* On entry, TRANS specifies the operation to be performed as\n* follows:\n*\n* TRANS = 'N' or 'n' y := alpha*A*x + beta*y.\n*\n* TRANS = 'T' or 't' y := alpha*A'*x + beta*y.\n*\n* TRANS = 'C' or 'c' y := alpha*conjg( A' )*x + beta*y.\n*\n* Unchanged on exit.\n*\n* M - INTEGER.\n* On entry, M specifies the number of rows of the matrix A.\n* M must be at least zero.\n* Unchanged on exit.\n*\n* N - INTEGER.\n* On entry, N specifies the number of columns of the matrix A.\n* N must be at least zero.\n* Unchanged on exit.\n*\n* ALPHA - COMPLEX .\n* On entry, ALPHA specifies the scalar alpha.\n* Unchanged on exit.\n*\n* A - COMPLEX array of DIMENSION ( LDA, n ).\n* Before entry, the leading m by n part of the array A must\n* contain the matrix of coefficients.\n* Unchanged on exit.\n*\n* LDA - INTEGER.\n* On entry, LDA specifies the first dimension of A as declared\n* in the calling (sub) program. LDA must be at least\n* max( 1, m ).\n* Unchanged on exit.\n*\n* X - COMPLEX array of DIMENSION at least\n* ( 1 + ( n - 1 )*abs( INCX ) ) when TRANS = 'N' or 'n'\n* and at least\n* ( 1 + ( m - 1 )*abs( INCX ) ) otherwise.\n* Before entry, the incremented array X must contain the\n* vector x.\n* Unchanged on exit.\n*\n* INCX - INTEGER.\n* On entry, INCX specifies the increment for the elements of\n* X. INCX must not be zero.\n* Unchanged on exit.\n*\n* BETA - COMPLEX .\n* On entry, BETA specifies the scalar beta. When BETA is\n* supplied as zero then Y need not be set on input.\n* Unchanged on exit.\n*\n* Y - COMPLEX*16 array of DIMENSION at least\n* ( 1 + ( m - 1 )*abs( INCY ) ) when TRANS = 'N' or 'n'\n* and at least\n* ( 1 + ( n - 1 )*abs( INCY ) ) otherwise.\n* Before entry with BETA non-zero, the incremented array Y\n* must contain the vector y. On exit, Y is overwritten by the\n* updated vector y. At least double precision arithmetic is\n* used in the computation of y.\n*\n* INCY - INTEGER.\n* On entry, INCY specifies the increment for the elements of\n* Y. INCY must not be zero.\n* Unchanged on exit.\n*\n*\n* Level 2 Blas routine.\n*\n* -- Written on 20-July-1986.\n* Sven Hammarling, Nag Central Office.\n* Richard Hanson, Sandia National Labs.\n*\n*\n* .. Parameters ..\n COMPLEX ONE\n PARAMETER ( ONE = ( 1.0E+0, 0.0E+0 ) )\n COMPLEX ZERO\n PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) )\n* .. Local Scalars ..\n COMPLEX*16 TEMP\n INTEGER I, INFO, IX, IY, J, JX, JY, KX, KY, LENX, LENY\n LOGICAL NOCONJ\n* .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\n* .. External Subroutines ..\n EXTERNAL XERBLA\n* .. Intrinsic Functions ..\n INTRINSIC DCMPLX, CONJG, MAX\n* ..\n* .. Executable Statements ..\n*\n* Test the input parameters.\n*\n INFO = 0\n IF ( .NOT.LSAME( TRANS, 'N' ).AND.\n $ .NOT.LSAME( TRANS, 'T' ).AND.\n $ .NOT.LSAME( TRANS, 'C' ) ) THEN\n INFO = 1\n ELSE IF ( M.LT.0 ) THEN\n INFO = 2\n ELSE IF ( N.LT.0 ) THEN\n INFO = 3\n ELSE IF ( LDA.LT.MAX(1,M) ) THEN\n INFO = 6\n ELSE IF ( INCX.EQ.0 ) THEN\n INFO = 8\n ELSE IF ( INCY.EQ.0 ) THEN\n INFO = 11\n END IF\n IF( INFO.NE.0 )THEN\n CALL XERBLA( 'ECGEMV', INFO )\n RETURN\n END IF\n*\n* Quick return if possible.\n*\n IF( ( M.EQ.0 ).OR.( N.EQ.0 ).OR.\n $ ( ( ALPHA.EQ.ZERO ).AND.( BETA.EQ.ONE ) ) )\n $ RETURN\n*\n NOCONJ = LSAME( TRANS, 'T' )\n*\n* Set LENX and LENY, the lengths of the vectors x and y.\n*\n IF( LSAME( TRANS, 'N' ) )THEN\n LENX = N\n LENY = M\n ELSE\n LENX = M\n LENY = N\n END IF\n*\n* Start the operations. In this version the elements of A are\n* accessed sequentially with one pass through A.\n*\n* First form y := beta*y and set up the start points in X and Y if\n* the increments are not both unity.\n*\n IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN\n IF( BETA.NE.ONE )THEN\n IF( BETA.EQ.ZERO )THEN\n DO 10, I = 1, LENY\n Y( I ) = ZERO\n 10 CONTINUE\n ELSE\n DO 20, I = 1, LENY\n Y( I ) = BETA*Y( I )\n 20 CONTINUE\n END IF\n END IF\n ELSE\n IF( INCX.GT.0 )THEN\n KX = 1\n ELSE\n KX = 1 - ( LENX - 1 )*INCX\n END IF\n IF( INCY.GT.0 )THEN\n KY = 1\n ELSE\n KY = 1 - ( LENY - 1 )*INCY\n END IF\n IF( BETA.NE.ONE )THEN\n IY = KY\n IF( BETA.EQ.ZERO )THEN\n DO 30, I = 1, LENY\n Y( IY ) = ZERO\n IY = IY + INCY\n 30 CONTINUE\n ELSE\n DO 40, I = 1, LENY\n Y( IY ) = BETA*Y( IY )\n IY = IY + INCY\n 40 CONTINUE\n END IF\n END IF\n END IF\n IF( ALPHA.EQ.ZERO )\n $ RETURN\n IF( LSAME( TRANS, 'N' ) )THEN\n*\n* Form y := alpha*A*x + y.\n*\n IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN\n DO 60, J = 1, N\n IF( X( J ).NE.ZERO )THEN\n TEMP = DCMPLX( ALPHA )*X( J )\n DO 50, I = 1, M\n Y( I ) = Y( I ) + TEMP*A( I, J )\n 50 CONTINUE\n END IF\n 60 CONTINUE\n ELSE\n JX = KX\n DO 80, J = 1, N\n IF( X( JX ).NE.ZERO )THEN\n TEMP = DCMPLX( ALPHA )*X( JX )\n IY = KY\n DO 70, I = 1, M\n Y( IY ) = Y( IY ) + TEMP*A( I, J )\n IY = IY + INCY\n 70 CONTINUE\n END IF\n JX = JX + INCX\n 80 CONTINUE\n END IF\n ELSE\n*\n* Form y := alpha*A'*x + y or y := alpha*conjg( A' )*x + y.\n*\n IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN\n DO 110, J = 1, N\n TEMP = ZERO\n IF( NOCONJ )THEN\n DO 90, I = 1, M\n TEMP = TEMP + A( I, J )*DCMPLX( X( I ) )\n 90 CONTINUE\n ELSE\n DO 100, I = 1, M\n TEMP = TEMP + CONJG( A( I, J ) )*DCMPLX( X( I ) )\n 100 CONTINUE\n END IF\n Y( J ) = Y( J ) + ALPHA*TEMP\n 110 CONTINUE\n ELSE\n JY = KY\n DO 140, J = 1, N\n TEMP = ZERO\n IX = KX\n IF( NOCONJ )THEN\n DO 120, I = 1, M\n TEMP = TEMP + A( I, J )*DCMPLX( X( IX ) )\n IX = IX + INCX\n 120 CONTINUE\n ELSE\n DO 130, I = 1, M\n TEMP = TEMP + CONJG( A( I, J ) )*DCMPLX( X( IX ) )\n IX = IX + INCX\n 130 CONTINUE\n END IF\n Y( JY ) = Y( JY ) + ALPHA*TEMP\n JY = JY + INCY\n 140 CONTINUE\n END IF\n END IF\n*\n RETURN\n*\n* End of ECGEMV.\n*\n END\n*\n************************************************************************\n*\n SUBROUTINE ECGERC( M, N, ALPHA, X, INCX, Y, INCY, A, LDA )\n* .. Scalar Arguments ..\n COMPLEX ALPHA\n INTEGER INCX, INCY, LDA, M, N\n* .. Array Arguments ..\n COMPLEX*16 X( * ), Y( * )\n COMPLEX A( LDA, * )\n* ..\n*\n* Purpose\n* =======\n*\n* ECGERC performs the rank 1 operation\n*\n* A := alpha*x*conjg( y' ) + A,\n*\n* where alpha is a scalar, x is an m element vector, y is an n element\n* vector and A is an m by n matrix. Additional precision is used in the\n* computation.\n*\n* Parameters\n* ==========\n*\n* M - INTEGER.\n* On entry, M specifies the number of rows of the matrix A.\n* M must be at least zero.\n* Unchanged on exit.\n*\n* N - INTEGER.\n* On entry, N specifies the number of columns of the matrix A.\n* N must be at least zero.\n* Unchanged on exit.\n*\n* ALPHA - COMPLEX .\n* On entry, ALPHA specifies the scalar alpha.\n* Unchanged on exit.\n*\n* X - COMPLEX*16 array of dimension at least\n* ( 1 + ( m - 1 )*abs( INCX ) ).\n* Before entry, the incremented array X must contain the m\n* element vector x.\n* Unchanged on exit.\n*\n* INCX - INTEGER.\n* On entry, INCX specifies the increment for the elements of\n* X. INCX must not be zero.\n* Unchanged on exit.\n*\n* Y - COMPLEX*16 array of dimension at least\n* ( 1 + ( n - 1 )*abs( INCY ) ).\n* Before entry, the incremented array Y must contain the n\n* element vector y.\n* Unchanged on exit.\n*\n* INCY - INTEGER.\n* On entry, INCY specifies the increment for the elements of\n* Y. INCY must not be zero.\n* Unchanged on exit.\n*\n* A - COMPLEX array of DIMENSION ( LDA, n ).\n* Before entry, the leading m by n part of the array A must\n* contain the matrix of coefficients. On exit, A is\n* overwritten by the updated matrix. At least double precision\n* arithmetic is used in the computation of A.\n*\n* LDA - INTEGER.\n* On entry, LDA specifies the first dimension of A as declared\n* in the calling (sub) program. LDA must be at least\n* max( 1, m ).\n* Unchanged on exit.\n*\n*\n* Level 2 Blas routine.\n*\n* -- Written on 20-July-1986.\n* Sven Hammarling, Nag Central Office.\n* Richard Hanson, Sandia National Labs.\n*\n*\n* .. Parameters ..\n COMPLEX*16 ZERO\n PARAMETER ( ZERO = ( 0.0D+0, 0.0D+0 ) )\n* .. Local Scalars ..\n COMPLEX*16 TEMP\n INTEGER I, INFO, IX, J, JY, KX\n* .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\n* .. External Subroutines ..\n EXTERNAL XERBLA\n* .. Intrinsic Functions ..\n INTRINSIC DCONJG, CMPLX, MAX\n* ..\n* .. Executable Statements ..\n*\n* Test the input parameters.\n*\n INFO = 0\n IF ( M.LT.0 ) THEN\n INFO = 1\n ELSE IF ( N.LT.0 ) THEN\n INFO = 2\n ELSE IF ( INCX.EQ.0 ) THEN\n INFO = 5\n ELSE IF ( INCY.EQ.0 ) THEN\n INFO = 7\n ELSE IF ( LDA.LT.MAX(1,M) ) THEN\n INFO = 9\n END IF\n IF( INFO.NE.0 )THEN\n CALL XERBLA( 'ECGERC', INFO )\n RETURN\n END IF\n*\n* Quick return if possible.\n*\n IF( ( M.EQ.0 ).OR.( N.EQ.0 ).OR.( ALPHA.EQ.CMPLX( ZERO ) ) )\n $ RETURN\n*\n* Start the operations. In this version the elements of A are\n* accessed sequentially with one pass through A.\n*\n IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN\n DO 20, J = 1, N\n IF( Y( J ).NE.ZERO )THEN\n TEMP = ALPHA*DCONJG( Y( J ) )\n DO 10, I = 1, M\n A( I, J ) = A( I, J ) + X( I )*TEMP\n 10 CONTINUE\n END IF\n 20 CONTINUE\n ELSE\n IF( INCX.GT.0 )THEN\n KX = 1\n ELSE\n KX = 1 - ( M - 1 )*INCX\n END IF\n IF( INCY.GT.0 )THEN\n JY = 1\n ELSE\n JY = 1 - ( N - 1 )*INCY\n END IF\n DO 40, J = 1, N\n IF( Y( JY ).NE.ZERO )THEN\n TEMP = ALPHA*DCONJG( Y( JY ) )\n IX = KX\n DO 30, I = 1, M\n A( I, J ) = A( I, J ) + X( IX )*TEMP\n IX = IX + INCX\n 30 CONTINUE\n END IF\n JY = JY + INCY\n 40 CONTINUE\n END IF\n*\n RETURN\n*\n* End of ECGERC.\n*\n END\n*\n************************************************************************\n*\n SUBROUTINE ECGERU( M, N, ALPHA, X, INCX, Y, INCY, A, LDA )\n* .. Scalar Arguments ..\n COMPLEX ALPHA\n INTEGER INCX, INCY, LDA, M, N\n* .. Array Arguments ..\n COMPLEX*16 X( * ), Y( * )\n COMPLEX A( LDA, * )\n* ..\n*\n* Purpose\n* =======\n*\n* ECGERU performs the rank 1 operation\n*\n* A := alpha*x*y' + A,\n*\n* where alpha is a scalar, x is an m element vector, y is an n element\n* vector and A is an m by n matrix. Additional precision is used in the\n* computation.\n*\n* Parameters\n* ==========\n*\n* M - INTEGER.\n* On entry, M specifies the number of rows of the matrix A.\n* M must be at least zero.\n* Unchanged on exit.\n*\n* N - INTEGER.\n* On entry, N specifies the number of columns of the matrix A.\n* N must be at least zero.\n* Unchanged on exit.\n*\n* ALPHA - COMPLEX .\n* On entry, ALPHA specifies the scalar alpha.\n* Unchanged on exit.\n*\n* X - COMPLEX*16 array of dimension at least\n* ( 1 + ( m - 1 )*abs( INCX ) ).\n* Before entry, the incremented array X must contain the m\n* element vector x.\n* Unchanged on exit.\n*\n* INCX - INTEGER.\n* On entry, INCX specifies the increment for the elements of\n* X. INCX must not be zero.\n* Unchanged on exit.\n*\n* Y - COMPLEX*16 array of dimension at least\n* ( 1 + ( n - 1 )*abs( INCY ) ).\n* Before entry, the incremented array Y must contain the n\n* element vector y.\n* Unchanged on exit.\n*\n* INCY - INTEGER.\n* On entry, INCY specifies the increment for the elements of\n* Y. INCY must not be zero.\n* Unchanged on exit.\n*\n* A - COMPLEX array of DIMENSION ( LDA, n ).\n* Before entry, the leading m by n part of the array A must\n* contain the matrix of coefficients. On exit, A is\n* overwritten by the updated matrix. At least double precision\n* arithmetic is used in the computation of A.\n*\n* LDA - INTEGER.\n* On entry, LDA specifies the first dimension of A as declared\n* in the calling (sub) program. LDA must be at least\n* max( 1, m ).\n* Unchanged on exit.\n*\n*\n* Level 2 Blas routine.\n*\n* -- Written on 20-July-1986.\n* Sven Hammarling, Nag Central Office.\n* Richard Hanson, Sandia National Labs.\n*\n*\n* .. Parameters ..\n COMPLEX*16 ZERO\n PARAMETER ( ZERO = ( 0.0D+0, 0.0D+0 ) )\n* .. Local Scalars ..\n COMPLEX*16 TEMP\n INTEGER I, INFO, IX, J, JY, KX\n* .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\n* .. External Subroutines ..\n EXTERNAL XERBLA\n* .. Intrinsic Functions ..\n INTRINSIC CMPLX, MAX\n* ..\n* .. Executable Statements ..\n*\n* Test the input parameters.\n*\n INFO = 0\n IF ( M.LT.0 ) THEN\n INFO = 1\n ELSE IF ( N.LT.0 ) THEN\n INFO = 2\n ELSE IF ( INCX.EQ.0 ) THEN\n INFO = 5\n ELSE IF ( INCY.EQ.0 ) THEN\n INFO = 7\n ELSE IF ( LDA.LT.MAX(1,M) ) THEN\n INFO = 9\n END IF\n IF( INFO.NE.0 )THEN\n CALL XERBLA( 'ECGERU', INFO )\n RETURN\n END IF\n*\n* Quick return if possible.\n*\n IF( ( M.EQ.0 ).OR.( N.EQ.0 ).OR.( ALPHA.EQ.CMPLX( ZERO ) ) )\n $ RETURN\n*\n* Start the operations. In this version the elements of A are\n* accessed sequentially with one pass through A.\n*\n IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN\n DO 20, J = 1, N\n IF( Y( J ).NE.ZERO )THEN\n TEMP = ALPHA*Y( J )\n DO 10, I = 1, M\n A( I, J ) = A( I, J ) + X( I )*TEMP\n 10 CONTINUE\n END IF\n 20 CONTINUE\n ELSE\n IF( INCX.GT.0 )THEN\n KX = 1\n ELSE\n KX = 1 - ( M - 1 )*INCX\n END IF\n IF( INCY.GT.0 )THEN\n JY = 1\n ELSE\n JY = 1 - ( N - 1 )*INCY\n END IF\n DO 40, J = 1, N\n IF( Y( JY ).NE.ZERO )THEN\n TEMP = ALPHA*Y( JY )\n IX = KX\n DO 30, I = 1, M\n A( I, J ) = A( I, J ) + X( IX )*TEMP\n IX = IX + INCX\n 30 CONTINUE\n END IF\n JY = JY + INCY\n 40 CONTINUE\n END IF\n*\n RETURN\n*\n* End of ECGERU.\n*\n END\n*\n************************************************************************\n*\n SUBROUTINE ECGBMV( TRANS, M, N, KL, KU, ALPHA, A, LDA, X, INCX,\n $ BETA, Y, INCY )\n* .. Scalar Arguments ..\n COMPLEX ALPHA, BETA\n INTEGER INCX, INCY, KL, KU, LDA, M, N\n CHARACTER*1 TRANS\n* .. Array Arguments ..\n COMPLEX*16 Y( * )\n COMPLEX A( LDA, * ), X( * )\n* ..\n*\n* Purpose\n* =======\n*\n* ECGBMV performs one of the matrix-vector operations\n*\n* y := alpha*A*x + beta*y, or y := alpha*A'*x + beta*y, or\n*\n* y := alpha*conjg( A' )*x + beta*y,\n*\n* where alpha and beta are scalars, x and y are vectors and A is an\n* m by n band matrix, with kl sub-diagonals and ku super-diagonals.\n* Additional precision arithmetic is used in the computation.\n*\n* Parameters\n* ==========\n*\n* TRANS - CHARACTER*1.\n* On entry, TRANS specifies the operation to be performed as\n* follows:\n*\n* TRANS = 'N' or 'n' y := alpha*A*x + beta*y.\n*\n* TRANS = 'T' or 't' y := alpha*A'*x + beta*y.\n*\n* TRANS = 'C' or 'c' y := alpha*conjg( A' )*x + beta*y.\n*\n* Unchanged on exit.\n*\n* M - INTEGER.\n* On entry, M specifies the number of rows of the matrix A.\n* M must be at least zero.\n* Unchanged on exit.\n*\n* N - INTEGER.\n* On entry, N specifies the number of columns of the matrix A.\n* N must be at least zero.\n* Unchanged on exit.\n*\n* KL - INTEGER.\n* On entry, KL specifies the number of sub-diagonals of the\n* matrix A. KL must satisfy 0 .le. KL.\n* Unchanged on exit.\n*\n* KU - INTEGER.\n* On entry, KU specifies the number of super-diagonals of the\n* matrix A. KU must satisfy 0 .le. KU.\n* Unchanged on exit.\n*\n* ALPHA - COMPLEX .\n* On entry, ALPHA specifies the scalar alpha.\n* Unchanged on exit.\n*\n* A - COMPLEX array of DIMENSION ( LDA, n ).\n* Before entry, the leading ( kl + ku + 1 ) by n part of the\n* array A must contain the matrix of coefficients, supplied\n* column by column, with the leading diagonal of the matrix in\n* row ( ku + 1 ) of the array, the first super-diagonal\n* starting at position 2 in row ku, the first sub-diagonal\n* starting at position 1 in row ( ku + 2 ), and so on.\n* Elements in the array A that do not correspond to elements\n* in the band matrix (such as the top left ku by ku triangle)\n* are not referenced.\n* The following program segment will transfer a band matrix\n* from conventional full matrix storage to band storage:\n*\n* DO 20, J = 1, N\n* K = KU + 1 - J\n* DO 10, I = MAX( 1, J - KU ), MIN( M, J + KL )\n* A( K + I, J ) = matrix( I, J )\n* 10 CONTINUE\n* 20 CONTINUE\n*\n* Unchanged on exit.\n*\n* LDA - INTEGER.\n* On entry, LDA specifies the first dimension of A as declared\n* in the calling (sub) program. LDA must be at least\n* ( kl + ku + 1 ).\n* Unchanged on exit.\n*\n* X - COMPLEX array of DIMENSION at least\n* ( 1 + ( n - 1 )*abs( INCX ) ) when TRANS = 'N' or 'n'\n* and at least\n* ( 1 + ( m - 1 )*abs( INCX ) ) otherwise.\n* Before entry, the incremented array X must contain the\n* vector x.\n* Unchanged on exit.\n*\n* INCX - INTEGER.\n* On entry, INCX specifies the increment for the elements of\n* X. INCX must not be zero.\n* Unchanged on exit.\n*\n* BETA - COMPLEX .\n* On entry, BETA specifies the scalar beta. When BETA is\n* supplied as zero then Y need not be set on input.\n* Unchanged on exit.\n*\n* Y - COMPLEX*16 array of DIMENSION at least\n* ( 1 + ( m - 1 )*abs( INCY ) ) when TRANS = 'N' or 'n'\n* and at least\n* ( 1 + ( n - 1 )*abs( INCY ) ) otherwise.\n* Before entry, the incremented array Y must contain the\n* vector y. On exit, Y is overwritten by the updated vector y.\n* At least double precision arithmetic is used in the\n* computation of y.\n*\n* INCY - INTEGER.\n* On entry, INCY specifies the increment for the elements of\n* Y. INCY must not be zero.\n* Unchanged on exit.\n*\n*\n* Level 2 Blas routine.\n*\n* -- Written on 20-July-1986.\n* Sven Hammarling, Nag Central Office.\n* Richard Hanson, Sandia National Labs.\n*\n*\n* .. Parameters ..\n COMPLEX ONE\n PARAMETER ( ONE = ( 1.0E+0, 0.0E+0 ) )\n COMPLEX ZERO\n PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) )\n* .. Local Scalars ..\n COMPLEX*16 TEMP\n INTEGER I, INFO, IX, IY, J, JX, JY, K, KUP1, KX, KY,\n $ LENX, LENY\n LOGICAL NOCONJ\n* .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\n* .. External Subroutines ..\n EXTERNAL XERBLA\n* .. Intrinsic Functions ..\n INTRINSIC DCMPLX, MAX, MIN, CONJG\n* ..\n* .. Executable Statements ..\n*\n* Test the input parameters.\n*\n INFO = 0\n IF ( .NOT.LSAME( TRANS, 'N' ).AND.\n $ .NOT.LSAME( TRANS, 'T' ).AND.\n $ .NOT.LSAME( TRANS, 'C' ) ) THEN\n INFO = 1\n ELSE IF ( M.LT.0 ) THEN\n INFO = 2\n ELSE IF ( N.LT.0 ) THEN\n INFO = 3\n ELSE IF ( KL.LT.0 ) THEN\n INFO = 4\n ELSE IF ( KU.LT.0 ) THEN\n INFO = 5\n ELSE IF ( LDA.LT.( KL + KU + 1 ) ) THEN\n INFO = 8\n ELSE IF ( INCX.EQ.0 ) THEN\n INFO = 10\n ELSE IF ( INCY.EQ.0 ) THEN\n INFO = 13\n END IF\n IF( INFO.NE.0 )THEN\n CALL XERBLA( 'ECGBMV', INFO )\n RETURN\n END IF\n*\n* Quick return if possible.\n*\n IF( ( M.EQ.0 ).OR.( N.EQ.0 ).OR.\n $ ( ( ALPHA.EQ.ZERO ).AND.( BETA.EQ.ONE ) ) )\n $ RETURN\n*\n NOCONJ = LSAME( TRANS, 'T' )\n*\n* Set LENX and LENY, the lengths of the vectors x and y.\n*\n IF( LSAME( TRANS, 'N' ) )THEN\n LENX = N\n LENY = M\n ELSE\n LENX = M\n LENY = N\n END IF\n*\n* Start the operations. In this version the elements of A are\n* accessed sequentially with one pass through the band part of A.\n*\n* First form y := beta*y and set up the start points in X and Y\n* if the increments are not both unity.\n*\n IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN\n IF( BETA.NE.ONE )THEN\n IF( BETA.EQ.ZERO )THEN\n DO 10, I = 1, LENY\n Y( I ) = ZERO\n 10 CONTINUE\n ELSE\n DO 20, I = 1, LENY\n Y( I ) = BETA*Y( I )\n 20 CONTINUE\n END IF\n END IF\n ELSE\n IF( INCX.GT.0 )THEN\n KX = 1\n ELSE\n KX = 1 - ( LENX - 1 )*INCX\n END IF\n IF( INCY.GT.0 )THEN\n KY = 1\n ELSE\n KY = 1 - ( LENY - 1 )*INCY\n END IF\n IF( BETA.NE.ONE )THEN\n IY = KY\n IF( BETA.EQ.ZERO )THEN\n DO 30, I = 1, LENY\n Y( IY ) = ZERO\n IY = IY + INCY\n 30 CONTINUE\n ELSE\n DO 40, I = 1, LENY\n Y( IY ) = BETA*Y( IY )\n IY = IY + INCY\n 40 CONTINUE\n END IF\n END IF\n END IF\n IF( ALPHA.EQ.ZERO )\n $ RETURN\n KUP1 = KU + 1\n IF( LSAME( TRANS, 'N' ) )THEN\n*\n* Form y := alpha*A*x + y.\n*\n IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN\n DO 60, J = 1, N\n IF( X( J ).NE.ZERO )THEN\n TEMP = DCMPLX( ALPHA )*X( J )\n K = KUP1 - J\n DO 50, I = MAX( 1, J - KU ), MIN( M, J + KL )\n Y( I ) = Y( I ) + TEMP*A( K + I, J )\n 50 CONTINUE\n END IF\n 60 CONTINUE\n ELSE\n JX = KX\n DO 80, J = 1, N\n IF( X( JX ).NE.ZERO )THEN\n TEMP = DCMPLX( ALPHA )*X( JX )\n IY = KY\n K = KUP1 - J\n DO 70, I = MAX( 1, J - KU ), MIN( M, J + KL )\n Y( IY ) = Y( IY ) + TEMP*A( K + I, J )\n IY = IY + INCY\n 70 CONTINUE\n END IF\n JX = JX + INCX\n IF( J.GT.KU )\n $ KY = KY + INCY\n 80 CONTINUE\n END IF\n ELSE\n*\n* Form y := alpha*A'*x + y or y := alpha*conjg( A' )*x + y.\n*\n IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN\n DO 110, J = 1, N\n TEMP = ZERO\n K = KUP1 - J\n IF( NOCONJ )THEN\n DO 90, I = MAX( 1, J - KU ), MIN( M, J + KL )\n TEMP = TEMP + A( K + I, J )*DCMPLX( X( I ) )\n 90 CONTINUE\n ELSE\n DO 100, I = MAX( 1, J - KU ), MIN( M, J + KL )\n TEMP = TEMP +\n $ CONJG( A( K + I, J ) )*DCMPLX( X( I ) )\n 100 CONTINUE\n END IF\n Y( J ) = Y( J ) + ALPHA*TEMP\n 110 CONTINUE\n ELSE\n JY = KY\n DO 140, J = 1, N\n TEMP = ZERO\n IX = KX\n K = KUP1 - J\n IF( NOCONJ )THEN\n DO 120, I = MAX( 1, J - KU ), MIN( M, J + KL )\n TEMP = TEMP + A( K + I, J )*DCMPLX( X( IX ) )\n IX = IX + INCX\n 120 CONTINUE\n ELSE\n DO 130, I = MAX( 1, J - KU ), MIN( M, J + KL )\n TEMP = TEMP +\n $ CONJG( A( K + I, J ) )*DCMPLX( X( IX ) )\n IX = IX + INCX\n 130 CONTINUE\n END IF\n Y( JY ) = Y( JY ) + ALPHA*TEMP\n JY = JY + INCY\n IF( J.GT.KU )\n $ KX = KX + INCX\n 140 CONTINUE\n END IF\n END IF\n*\n RETURN\n*\n* End of ECGBMV.\n*\n END\n*\n************************************************************************\n*\n SUBROUTINE ECHEMV( UPLO, N, ALPHA, A, LDA, X, INCX,\n $ BETA, Y, INCY )\n* .. Scalar Arguments ..\n COMPLEX ALPHA, BETA\n INTEGER INCX, INCY, LDA, N\n CHARACTER*1 UPLO\n* .. Array Arguments ..\n COMPLEX*16 Y( * )\n COMPLEX A( LDA, * ), X( * )\n* ..\n*\n* Purpose\n* =======\n*\n* ECHEMV performs the matrix-vector operation\n*\n* y := alpha*A*x + beta*y,\n*\n* where alpha and beta are scalars, x and y are n element vectors and\n* A is an n by n hermitian matrix. Additional precision arithmetic is\n* used in the computation.\n*\n* Parameters\n* ==========\n*\n* UPLO - CHARACTER*1.\n* On entry, UPLO specifies whether the upper or lower\n* triangular part of the array A is to be referenced as\n* follows:\n*\n* UPLO = 'U' or 'u' Only the upper triangular part of A\n* is to be referenced.\n*\n* UPLO = 'L' or 'l' Only the lower triangular part of A\n* is to be referenced.\n*\n* Unchanged on exit.\n*\n* N - INTEGER.\n* On entry, N specifies the order of the matrix A.\n* N must be at least zero.\n* Unchanged on exit.\n*\n* ALPHA - COMPLEX .\n* On entry, ALPHA specifies the scalar alpha.\n* Unchanged on exit.\n*\n* A - COMPLEX array of DIMENSION ( LDA, n ).\n* Before entry with UPLO = 'U' or 'u', the leading n by n\n* upper triangular part of the array A must contain the upper\n* triangular part of the hermitian matrix and the strictly\n* lower triangular part of A is not referenced.\n* Before entry with UPLO = 'L' or 'l', the leading n by n\n* lower triangular part of the array A must contain the lower\n* triangular part of the hermitian matrix and the strictly\n* upper triangular part of A is not referenced.\n* Note that the imaginary parts of the diagonal elements need\n* not be set and are assumed to be zero.\n* Unchanged on exit.\n*\n* LDA - INTEGER.\n* On entry, LDA specifies the first dimension of A as declared\n* in the calling (sub) program. LDA must be at least\n* max( 1, n ).\n* Unchanged on exit.\n*\n* X - COMPLEX array of dimension at least\n* ( 1 + ( n - 1 )*abs( INCX ) ).\n* Before entry, the incremented array X must contain the n\n* element vector x.\n* Unchanged on exit.\n*\n* INCX - INTEGER.\n* On entry, INCX specifies the increment for the elements of\n* X. INCX must not be zero.\n* Unchanged on exit.\n*\n* BETA - COMPLEX .\n* On entry, BETA specifies the scalar beta. When BETA is\n* supplied as zero then Y need not be set on input.\n* Unchanged on exit.\n*\n* Y - COMPLEX*16 array of dimension at least\n* ( 1 + ( n - 1 )*abs( INCY ) ).\n* Before entry, the incremented array Y must contain the n\n* element vector y. On exit, Y is overwritten by the updated\n* vector y. At least double precision arithmetic is used in\n* the computation of y.\n*\n* INCY - INTEGER.\n* On entry, INCY specifies the increment for the elements of\n* Y. INCY must not be zero.\n* Unchanged on exit.\n*\n*\n* Level 2 Blas routine.\n*\n* -- Written on 20-July-1986.\n* Sven Hammarling, Nag Central Office.\n* Richard Hanson, Sandia National Labs.\n*\n*\n* .. Parameters ..\n COMPLEX ONE\n PARAMETER ( ONE = ( 1.0E+0, 0.0E+0 ) )\n COMPLEX ZERO\n PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) )\n* .. Local Scalars ..\n COMPLEX*16 TEMP1, TEMP2\n INTEGER I, INFO, IX, IY, J, JX, JY, KX, KY\n* .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\n* .. External Subroutines ..\n EXTERNAL XERBLA\n* .. Intrinsic Functions ..\n INTRINSIC DCMPLX, CONJG, MAX, REAL\n* ..\n* .. Executable Statements ..\n*\n* Test the input parameters.\n*\n INFO = 0\n IF ( .NOT.LSAME( UPLO, 'U' ).AND.\n $ .NOT.LSAME( UPLO, 'L' ) ) THEN\n INFO = 1\n ELSE IF ( N.LT.0 ) THEN\n INFO = 2\n ELSE IF ( LDA.LT.MAX(1,N) ) THEN\n INFO = 5\n ELSE IF ( INCX.EQ.0 ) THEN\n INFO = 7\n ELSE IF ( INCY.EQ.0 ) THEN\n INFO = 10\n END IF\n IF( INFO.NE.0 )THEN\n CALL XERBLA( 'ECHEMV', INFO )\n RETURN\n END IF\n*\n* Quick return if possible.\n*\n IF( ( N.EQ.0 ).OR.( ( ALPHA.EQ.ZERO ).AND.( BETA.EQ.ONE ) ) )\n $ RETURN\n*\n* Start the operations. In this version the elements of A are\n* accessed sequentially with one pass through the triangular part\n* of A.\n*\n* First form y := beta*y and set up the start points in X and Y if\n* the increments are not both unity.\n*\n IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN\n IF( BETA.NE.ONE )THEN\n IF( BETA.EQ.ZERO )THEN\n DO 10, I = 1, N\n Y( I ) = ZERO\n 10 CONTINUE\n ELSE\n DO 20, I = 1, N\n Y( I ) = BETA*Y( I )\n 20 CONTINUE\n END IF\n END IF\n ELSE\n IF( INCX.GT.0 )THEN\n KX = 1\n ELSE\n KX = 1 - ( N - 1 )*INCX\n END IF\n IF( INCY.GT.0 )THEN\n KY = 1\n ELSE\n KY = 1 - ( N - 1 )*INCY\n END IF\n IF( BETA.NE.ONE )THEN\n IY = KY\n IF( BETA.EQ.ZERO )THEN\n DO 30, I = 1, N\n Y( IY ) = ZERO\n IY = IY + INCY\n 30 CONTINUE\n ELSE\n DO 40, I = 1, N\n Y( IY ) = BETA*Y( IY )\n IY = IY + INCY\n 40 CONTINUE\n END IF\n END IF\n END IF\n IF( ALPHA.EQ.ZERO )\n $ RETURN\n IF( LSAME( UPLO, 'U' ) )THEN\n*\n* Form y when A is stored in upper triangle.\n*\n IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN\n DO 60, J = 1, N\n TEMP1 = DCMPLX( ALPHA )*X( J )\n TEMP2 = ZERO\n DO 50, I = 1, J - 1\n Y( I ) = Y( I ) + TEMP1*A( I, J )\n TEMP2 = TEMP2 + CONJG( A( I, J ) )*DCMPLX( X( I ) )\n 50 CONTINUE\n Y( J ) = Y( J ) + TEMP1*REAL( A( J, J ) ) + ALPHA*TEMP2\n 60 CONTINUE\n ELSE\n IX = KX - INCX\n DO 80, J = 1, N\n TEMP1 = DCMPLX( ALPHA )*X( IX + INCX )\n TEMP2 = ZERO\n IX = KX\n IY = KY\n DO 70, I = 1, J - 1\n Y( IY ) = Y( IY ) + TEMP1*A( I, J )\n TEMP2 = TEMP2 +\n $ CONJG( A( I, J ) )*DCMPLX( X( IX ) )\n IX = IX + INCX\n IY = IY + INCY\n 70 CONTINUE\n Y( IY ) = Y( IY ) + TEMP1*REAL( A( J, J ) ) + ALPHA*TEMP2\n 80 CONTINUE\n END IF\n ELSE\n*\n* Form y when A is stored in lower triangle.\n*\n IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN\n DO 100, J = 1, N\n TEMP1 = DCMPLX( ALPHA )*X( J )\n TEMP2 = ZERO\n Y( J ) = Y( J ) + TEMP1*REAL( A( J, J ) )\n DO 90, I = J + 1, N\n Y( I ) = Y( I ) + TEMP1*A( I, J )\n TEMP2 = TEMP2 + CONJG( A( I, J ) )*DCMPLX( X( I ) )\n 90 CONTINUE\n Y( J ) = Y( J ) + ALPHA*TEMP2\n 100 CONTINUE\n ELSE\n JX = KX\n JY = KY\n DO 120, J = 1, N\n TEMP1 = DCMPLX( ALPHA )*X( JX )\n TEMP2 = ZERO\n Y( JY ) = Y( JY ) + TEMP1*REAL( A( J, J ) )\n IX = JX\n IY = JY\n DO 110, I = J + 1, N\n IX = IX + INCX\n IY = IY + INCY\n Y( IY ) = Y( IY ) + TEMP1*A( I, J )\n TEMP2 = TEMP2 +\n $ CONJG( A( I, J ) )*DCMPLX( X( IX ) )\n 110 CONTINUE\n Y( JY ) = Y( JY ) + ALPHA*TEMP2\n JX = JX + INCX\n JY = JY + INCY\n 120 CONTINUE\n END IF\n END IF\n*\n RETURN\n*\n* End of ECHEMV.\n*\n END\n*\n************************************************************************\n*\n SUBROUTINE ECHER ( UPLO, N, ALPHA, X, INCX, A, LDA )\n* .. Scalar Arguments ..\n REAL ALPHA\n INTEGER INCX, LDA, N\n CHARACTER*1 UPLO\n* .. Array Arguments ..\n COMPLEX*16 X( * )\n COMPLEX A( LDA, * )\n* ..\n*\n* Purpose\n* =======\n*\n* ECHER performs the hermitian rank 1 operation\n*\n* A := alpha*x*conjg( x' ) + A,\n*\n* where alpha is a real scalar, x is an n element vector and A is an\n* n by n hermitian matrix. Additional precision arithmetic is used in\n* the computation.\n*\n* Parameters\n* ==========\n*\n* UPLO - CHARACTER*1.\n* On entry, UPLO specifies whether the upper or lower\n* triangular part of the array A is to be referenced as\n* follows:\n*\n* UPLO = 'U' or 'u' Only the upper triangular part of A\n* is to be referenced.\n*\n* UPLO = 'L' or 'l' Only the lower triangular part of A\n* is to be referenced.\n*\n* Unchanged on exit.\n*\n* N - INTEGER.\n* On entry, N specifies the order of the matrix A.\n* N must be at least zero.\n* Unchanged on exit.\n*\n* ALPHA - REAL .\n* On entry, ALPHA specifies the scalar alpha.\n* Unchanged on exit.\n*\n* X - COMPLEX*16 array of dimension at least\n* ( 1 + ( n - 1 )*abs( INCX ) ).\n* Before entry, the incremented array X must contain the n\n* element vector x.\n* Unchanged on exit.\n*\n* INCX - INTEGER.\n* On entry, INCX specifies the increment for the elements of\n* X. INCX must not be zero.\n* Unchanged on exit.\n*\n* A - COMPLEX array of DIMENSION ( LDA, n ).\n* Before entry with UPLO = 'U' or 'u', the leading n by n\n* upper triangular part of the array A must contain the upper\n* triangular part of the hermitian matrix and the strictly\n* lower triangular part of A is not referenced. On exit, the\n* upper triangular part of the array A is overwritten by the\n* upper triangular part of the updated matrix.\n* Before entry with UPLO = 'L' or 'l', the leading n by n\n* lower triangular part of the array A must contain the lower\n* triangular part of the hermitian matrix and the strictly\n* upper triangular part of A is not referenced. On exit, the\n* lower triangular part of the array A is overwritten by the\n* lower triangular part of the updated matrix.\n* Note that the imaginary parts of the diagonal elements need\n* not be set, they are assumed to be zero, and on exit they\n* are set to zero. At least double precision arithmetic is\n* used in the computation of A.\n*\n* LDA - INTEGER.\n* On entry, LDA specifies the first dimension of A as declared\n* in the calling (sub) program. LDA must be at least\n* max( 1, n ).\n* Unchanged on exit.\n*\n*\n* Level 2 Blas routine.\n*\n* -- Written on 20-July-1986.\n* Sven Hammarling, Nag Central Office.\n* Richard Hanson, Sandia National Labs.\n*\n*\n* .. Parameters ..\n COMPLEX*16 ZERO\n PARAMETER ( ZERO = ( 0.0D+0, 0.0D+0 ) )\n* .. Local Scalars ..\n COMPLEX*16 TEMP\n INTEGER I, INFO, IX, J, JX, KX\n* .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\n* .. External Subroutines ..\n EXTERNAL XERBLA\n* .. Intrinsic Functions ..\n INTRINSIC DCONJG, DBLE, MAX, REAL\n* ..\n* .. Executable Statements ..\n*\n* Test the input parameters.\n*\n INFO = 0\n IF ( .NOT.LSAME( UPLO, 'U' ).AND.\n $ .NOT.LSAME( UPLO, 'L' ) ) THEN\n INFO = 1\n ELSE IF ( N.LT.0 ) THEN\n INFO = 2\n ELSE IF ( INCX.EQ.0 ) THEN\n INFO = 5\n ELSE IF ( LDA.LT.MAX(1,N) ) THEN\n INFO = 7\n END IF\n IF( INFO.NE.0 )THEN\n CALL XERBLA( 'ECHER ', INFO )\n RETURN\n END IF\n*\n* Quick return if possible.\n*\n IF( ( N.EQ.0 ).OR.( ALPHA.EQ.REAL( ZERO ) ) )\n $ RETURN\n*\n* Set the start point in X if the increment is not unity.\n*\n IF( INCX.LE.0 )THEN\n KX = 1 - ( N - 1 )*INCX\n ELSE IF( INCX.NE.1 )THEN\n KX = 1\n END IF\n*\n* Start the operations. In this version the elements of A are\n* accessed sequentially with one pass through the triangular part\n* of A.\n*\n IF( LSAME( UPLO, 'U' ) )THEN\n*\n* Form A when A is stored in upper triangle.\n*\n IF( INCX.EQ.1 )THEN\n DO 20, J = 1, N\n IF( X( J ).NE.ZERO )THEN\n TEMP = ALPHA*DCONJG( X( J ) )\n DO 10, I = 1, J - 1\n A( I, J ) = A( I, J ) + X( I )*TEMP\n 10 CONTINUE\n A( J, J ) = REAL( A( J, J ) ) + DBLE( X( J )*TEMP )\n ELSE\n A( J, J ) = REAL( A( J, J ) )\n END IF\n 20 CONTINUE\n ELSE\n JX = KX\n DO 40, J = 1, N\n IF( X( JX ).NE.ZERO )THEN\n TEMP = ALPHA*DCONJG( X( JX ) )\n IX = KX\n DO 30, I = 1, J - 1\n A( I, J ) = A( I, J ) + X( IX )*TEMP\n IX = IX + INCX\n 30 CONTINUE\n A( J, J ) = REAL( A( J, J ) ) + DBLE( X( JX )*TEMP )\n ELSE\n A( J, J ) = REAL( A( J, J ) )\n END IF\n JX = JX + INCX\n 40 CONTINUE\n END IF\n ELSE\n*\n* Form A when A is stored in lower triangle.\n*\n IF( INCX.EQ.1 )THEN\n DO 60, J = 1, N\n IF( X( J ).NE.ZERO )THEN\n TEMP = ALPHA*DCONJG( X( J ) )\n A( J, J ) = REAL( A( J, J ) ) + DBLE( TEMP*X( J ) )\n DO 50, I = J + 1, N\n A( I, J ) = A( I, J ) + X( I )*TEMP\n 50 CONTINUE\n ELSE\n A( J, J ) = REAL( A( J, J ) )\n END IF\n 60 CONTINUE\n ELSE\n JX = KX\n DO 80, J = 1, N\n IF( X( JX ).NE.ZERO )THEN\n TEMP = ALPHA*DCONJG( X( JX ) )\n A( J, J ) = REAL( A( J, J ) ) + DBLE( TEMP*X( JX ) )\n IX = JX\n DO 70, I = J + 1, N\n IX = IX + INCX\n A( I, J ) = A( I, J ) + X( IX )*TEMP\n 70 CONTINUE\n ELSE\n A( J, J ) = REAL( A( J, J ) )\n END IF\n JX = JX + INCX\n 80 CONTINUE\n END IF\n END IF\n*\n RETURN\n*\n* End of ECHER .\n*\n END\n*\n************************************************************************\n*\n SUBROUTINE ECHER2( UPLO, N, ALPHA, X, INCX, Y, INCY, A, LDA )\n* .. Scalar Arguments ..\n COMPLEX ALPHA\n INTEGER INCX, INCY, LDA, N\n CHARACTER*1 UPLO\n* .. Array Arguments ..\n COMPLEX*16 X( * ), Y( * )\n COMPLEX A( LDA, * )\n* ..\n*\n* Purpose\n* =======\n*\n* ECHER2 performs the hermitian rank 2 operation\n*\n* A := alpha*x*conjg( y' ) + conjg( alpha )*y*conjg( x' ) + A,\n*\n* where alpha is a scalar, x and y are n element vectors and A is an n\n* by n hermitian matrix. Additional precision arithmetic is used in the\n* computation.\n*\n* Parameters\n* ==========\n*\n* UPLO - CHARACTER*1.\n* On entry, UPLO specifies whether the upper or lower\n* triangular part of the array A is to be referenced as\n* follows:\n*\n* UPLO = 'U' or 'u' Only the upper triangular part of A\n* is to be referenced.\n*\n* UPLO = 'L' or 'l' Only the lower triangular part of A\n* is to be referenced.\n*\n* Unchanged on exit.\n*\n* N - INTEGER.\n* On entry, N specifies the order of the matrix A.\n* N must be at least zero.\n* Unchanged on exit.\n*\n* ALPHA - COMPLEX .\n* On entry, ALPHA specifies the scalar alpha.\n* Unchanged on exit.\n*\n* X - COMPLEX*16 array of dimension at least\n* ( 1 + ( n - 1 )*abs( INCX ) ).\n* Before entry, the incremented array X must contain the n\n* element vector x.\n* Unchanged on exit.\n*\n* INCX - INTEGER.\n* On entry, INCX specifies the increment for the elements of\n* X. INCX must not be zero.\n* Unchanged on exit.\n*\n* Y - COMPLEX*16 array of dimension at least\n* ( 1 + ( n - 1 )*abs( INCY ) ).\n* Before entry, the incremented array Y must contain the n\n* element vector y.\n* Unchanged on exit.\n*\n* INCY - INTEGER.\n* On entry, INCY specifies the increment for the elements of\n* Y. INCY must not be zero.\n* Unchanged on exit.\n*\n* A - COMPLEX array of DIMENSION ( LDA, n ).\n* Before entry with UPLO = 'U' or 'u', the leading n by n\n* upper triangular part of the array A must contain the upper\n* triangular part of the hermitian matrix and the strictly\n* lower triangular part of A is not referenced. On exit, the\n* upper triangular part of the array A is overwritten by the\n* upper triangular part of the updated matrix.\n* Before entry with UPLO = 'L' or 'l', the leading n by n\n* lower triangular part of the array A must contain the lower\n* triangular part of the hermitian matrix and the strictly\n* upper triangular part of A is not referenced. On exit, the\n* lower triangular part of the array A is overwritten by the\n* lower triangular part of the updated matrix.\n* Note that the imaginary parts of the diagonal elements need\n* not be set, they are assumed to be zero, and on exit they\n* are set to zero. At least double precision arithmetic is\n* used in the computation of A.\n*\n* LDA - INTEGER.\n* On entry, LDA specifies the first dimension of A as declared\n* in the calling (sub) program. LDA must be at least\n* max( 1, n ).\n* Unchanged on exit.\n*\n*\n* Level 2 Blas routine.\n*\n* -- Written on 20-July-1986.\n* Sven Hammarling, Nag Central Office.\n* Richard Hanson, Sandia National Labs.\n*\n*\n* .. Parameters ..\n COMPLEX*16 ZERO\n PARAMETER ( ZERO = ( 0.0D+0, 0.0D+0 ) )\n* .. Local Scalars ..\n COMPLEX*16 TEMP1, TEMP2\n INTEGER I, INFO, IX, IY, J, JX, JY, KX, KY\n* .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\n* .. External Subroutines ..\n EXTERNAL XERBLA\n* .. Intrinsic Functions ..\n INTRINSIC DCONJG, DBLE, CMPLX, MAX, REAL\n* ..\n* .. Executable Statements ..\n*\n* Test the input parameters.\n*\n INFO = 0\n IF ( .NOT.LSAME( UPLO, 'U' ).AND.\n $ .NOT.LSAME( UPLO, 'L' ) ) THEN\n INFO = 1\n ELSE IF ( N.LT.0 ) THEN\n INFO = 2\n ELSE IF ( INCX.EQ.0 ) THEN\n INFO = 5\n ELSE IF ( INCY.EQ.0 ) THEN\n INFO = 7\n ELSE IF ( LDA.LT.MAX(1,N) ) THEN\n INFO = 9\n END IF\n IF( INFO.NE.0 )THEN\n CALL XERBLA( 'ECHER2', INFO )\n RETURN\n END IF\n*\n* Quick return if possible.\n*\n IF( ( N.EQ.0 ).OR.( ALPHA.EQ.CMPLX( ZERO ) ) )\n $ RETURN\n*\n* Set up the start points in X and Y if the increments are not both\n* unity.\n*\n IF( ( INCX.NE.1 ).OR.( INCY.NE.1 ) )THEN\n IF( INCX.GT.0 )THEN\n KX = 1\n ELSE\n KX = 1 - ( N - 1 )*INCX\n END IF\n IF( INCY.GT.0 )THEN\n KY = 1\n ELSE\n KY = 1 - ( N - 1 )*INCY\n END IF\n END IF\n*\n* Start the operations. In this version the elements of A are\n* accessed sequentially with one pass through the triangular part\n* of A.\n*\n IF( LSAME( UPLO, 'U' ) )THEN\n*\n* Form A when A is stored in the upper triangle.\n*\n IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN\n DO 20, J = 1, N\n IF( ( X( J ).NE.ZERO ).OR.( Y( J ).NE.ZERO ) )THEN\n TEMP1 = ALPHA*DCONJG( Y( J ) )\n TEMP2 = DCONJG( ALPHA*X( J ) )\n DO 10, I = 1, J - 1\n A( I, J ) = A( I, J ) + X( I )*TEMP1 + Y( I )*TEMP2\n 10 CONTINUE\n A( J, J ) = REAL( A( J, J ) ) +\n $ DBLE( X( J )*TEMP1 + Y( J )*TEMP2 )\n ELSE\n A( J, J ) = REAL( A( J, J ) )\n END IF\n 20 CONTINUE\n ELSE\n JX = KX\n JY = KY\n DO 40, J = 1, N\n IF( ( X( JX ).NE.ZERO ).OR.( Y( JY ).NE.ZERO ) )THEN\n TEMP1 = ALPHA*DCONJG( Y( JY ) )\n TEMP2 = DCONJG( ALPHA*X( JX ) )\n IX = KX\n IY = KY\n DO 30, I = 1, J - 1\n A( I, J ) = A( I, J ) + X( IX )*TEMP1\n $ + Y( IY )*TEMP2\n IX = IX + INCX\n IY = IY + INCY\n 30 CONTINUE\n A( J, J ) = REAL( A( J, J ) ) +\n $ DBLE( X( JX )*TEMP1 + Y( JY )*TEMP2 )\n ELSE\n A( J, J ) = REAL( A( J, J ) )\n END IF\n JX = JX + INCX\n JY = JY + INCY\n 40 CONTINUE\n END IF\n ELSE\n*\n* Form A when A is stored in the lower triangle.\n*\n IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN\n DO 60, J = 1, N\n IF( ( X( J ).NE.ZERO ).OR.( Y( J ).NE.ZERO ) )THEN\n TEMP1 = ALPHA*DCONJG( Y( J ) )\n TEMP2 = DCONJG( ALPHA*X( J ) )\n A( J, J ) = REAL( A( J, J ) ) +\n $ DBLE( X( J )*TEMP1 + Y( J )*TEMP2 )\n DO 50, I = J + 1, N\n A( I, J ) = A( I, J ) + X( I )*TEMP1 + Y( I )*TEMP2\n 50 CONTINUE\n ELSE\n A( J, J ) = REAL( A( J, J ) )\n END IF\n 60 CONTINUE\n ELSE\n JX = KX\n JY = KY\n DO 80, J = 1, N\n IF( ( X( JX ).NE.ZERO ).OR.( Y( JY ).NE.ZERO ) )THEN\n TEMP1 = ALPHA*DCONJG( Y( JY ) )\n TEMP2 = DCONJG( ALPHA*X( JX ) )\n A( J, J ) = REAL( A( J, J ) ) +\n $ DBLE( X( JX )*TEMP1 + Y( JY )*TEMP2 )\n IX = JX\n IY = JY\n DO 70, I = J + 1, N\n IX = IX + INCX\n IY = IY + INCY\n A( I, J ) = A( I, J ) + X( IX )*TEMP1\n $ + Y( IY )*TEMP2\n 70 CONTINUE\n ELSE\n A( J, J ) = REAL( A( J, J ) )\n END IF\n JX = JX + INCX\n JY = JY + INCY\n 80 CONTINUE\n END IF\n END IF\n*\n RETURN\n*\n* End of ECHER2.\n*\n END\n*\n************************************************************************\n*\n SUBROUTINE ECHPMV( UPLO, N, ALPHA, AP, X, INCX, BETA, Y, INCY )\n* .. Scalar Arguments ..\n COMPLEX ALPHA, BETA\n INTEGER INCX, INCY, N\n CHARACTER*1 UPLO\n* .. Array Arguments ..\n COMPLEX*16 Y( * )\n COMPLEX AP( * ), X( * )\n* ..\n*\n* Purpose\n* =======\n*\n* ECHPMV performs the matrix-vector operation\n*\n* y := alpha*A*x + beta*y,\n*\n* where alpha and beta are scalars, x and y are n element vectors and\n* A is an n by n hermitian matrix. Additional precision arithmetic is\n* used in the computation.\n*\n* Parameters\n* ==========\n*\n* UPLO - CHARACTER*1.\n* On entry, UPLO specifies whether the upper or lower\n* triangular part of the matrix A is supplied in the packed\n* array AP as follows:\n*\n* UPLO = 'U' or 'u' The upper triangular part of A is\n* supplied in AP.\n*\n* UPLO = 'L' or 'l' The lower triangular part of A is\n* supplied in AP.\n*\n* Unchanged on exit.\n*\n* N - INTEGER.\n* On entry, N specifies the order of the matrix A.\n* N must be at least zero.\n* Unchanged on exit.\n*\n* ALPHA - COMPLEX .\n* On entry, ALPHA specifies the scalar alpha.\n* Unchanged on exit.\n*\n* AP - COMPLEX array of DIMENSION at least\n* ( ( n*( n + 1 ) )/2 ).\n* Before entry with UPLO = 'U' or 'u', the array AP must\n* contain the upper triangular part of the hermitian matrix\n* packed sequentially, column by column, so that AP( 1 )\n* contains a( 1, 1 ), AP( 2 ) and AP( 3 ) contain a( 1, 2 )\n* and a( 2, 2 ) respectively, and so on.\n* Before entry with UPLO = 'L' or 'l', the array AP must\n* contain the lower triangular part of the hermitian matrix\n* packed sequentially, column by column, so that AP( 1 )\n* contains a( 1, 1 ), AP( 2 ) and AP( 3 ) contain a( 2, 1 )\n* and a( 3, 1 ) respectively, and so on.\n* Note that the imaginary parts of the diagonal elements need\n* not be set and are assumed to be zero.\n* Unchanged on exit.\n*\n* X - COMPLEX array of dimension at least\n* ( 1 + ( n - 1 )*abs( INCX ) ).\n* Before entry, the incremented array X must contain the n\n* element vector x.\n* Unchanged on exit.\n*\n* INCX - INTEGER.\n* On entry, INCX specifies the increment for the elements of\n* X. INCX must not be zero.\n* Unchanged on exit.\n*\n* BETA - COMPLEX .\n* On entry, BETA specifies the scalar beta. When BETA is\n* supplied as zero then Y need not be set on input.\n* Unchanged on exit.\n*\n* Y - COMPLEX*16 array of dimension at least\n* ( 1 + ( n - 1 )*abs( INCY ) ).\n* Before entry, the incremented array Y must contain the n\n* element vector y. On exit, Y is overwritten by the updated\n* vector y. At least double precision arithmetic is used in\n* the computation of y.\n*\n* INCY - INTEGER.\n* On entry, INCY specifies the increment for the elements of\n* Y. INCY must not be zero.\n* Unchanged on exit.\n*\n*\n* Level 2 Blas routine.\n*\n* -- Written on 20-July-1986.\n* Sven Hammarling, Nag Central Office.\n* Richard Hanson, Sandia National Labs.\n*\n*\n* .. Parameters ..\n COMPLEX ONE\n PARAMETER ( ONE = ( 1.0E+0, 0.0E+0 ) )\n COMPLEX ZERO\n PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) )\n* .. Local Scalars ..\n COMPLEX*16 TEMP1, TEMP2\n INTEGER I, INFO, IX, IY, J, JX, JY, K, KK, KX, KY\n* .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\n* .. External Subroutines ..\n EXTERNAL XERBLA\n* .. Intrinsic Functions ..\n INTRINSIC DCMPLX, CONJG, REAL\n* ..\n* .. Executable Statements ..\n*\n* Test the input parameters.\n*\n INFO = 0\n IF ( .NOT.LSAME( UPLO, 'U' ).AND.\n $ .NOT.LSAME( UPLO, 'L' ) ) THEN\n INFO = 1\n ELSE IF ( N.LT.0 ) THEN\n INFO = 2\n ELSE IF ( INCX.EQ.0 ) THEN\n INFO = 6\n ELSE IF ( INCY.EQ.0 ) THEN\n INFO = 9\n END IF\n IF( INFO.NE.0 )THEN\n CALL XERBLA( 'ECHPMV', INFO )\n RETURN\n END IF\n*\n* Quick return if possible.\n*\n IF( ( N.EQ.0 ).OR.( ( ALPHA.EQ.ZERO ).AND.( BETA.EQ.ONE ) ) )\n $ RETURN\n*\n* Start the operations. In this version the elements of the array AP\n* are accessed sequentially with one pass through AP.\n*\n* First form y := beta*y and set up the start points in X and Y if\n* the increments are not both unity.\n*\n IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN\n IF( BETA.NE.ONE )THEN\n IF( BETA.EQ.ZERO )THEN\n DO 10, I = 1, N\n Y( I ) = ZERO\n 10 CONTINUE\n ELSE\n DO 20, I = 1, N\n Y( I ) = BETA*Y( I )\n 20 CONTINUE\n END IF\n END IF\n ELSE\n IF( INCX.GT.0 )THEN\n KX = 1\n ELSE\n KX = 1 - ( N - 1 )*INCX\n END IF\n IF( INCY.GT.0 )THEN\n KY = 1\n ELSE\n KY = 1 - ( N - 1 )*INCY\n END IF\n IF( BETA.NE.ONE )THEN\n IY = KY\n IF( BETA.EQ.ZERO )THEN\n DO 30, I = 1, N\n Y( IY ) = ZERO\n IY = IY + INCY\n 30 CONTINUE\n ELSE\n DO 40, I = 1, N\n Y( IY ) = BETA*Y( IY )\n IY = IY + INCY\n 40 CONTINUE\n END IF\n END IF\n END IF\n IF( ALPHA.EQ.ZERO )\n $ RETURN\n K = 1\n IF( LSAME( UPLO, 'U' ) )THEN\n*\n* Form y when AP contains the upper triangle.\n*\n IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN\n DO 60, J = 1, N\n TEMP1 = DCMPLX( ALPHA )*X( J )\n TEMP2 = ZERO\n DO 50, I = 1, J - 1\n Y( I ) = Y( I ) + TEMP1*AP( K )\n TEMP2 = TEMP2 + CONJG( AP( K ) )*DCMPLX( X( I ) )\n K = K + 1\n 50 CONTINUE\n Y( J ) = Y( J ) + TEMP1*REAL( AP( K ) ) + ALPHA*TEMP2\n K = K + 1\n 60 CONTINUE\n ELSE\n IX = KX - INCX\n DO 80, J = 1, N\n TEMP1 = DCMPLX( ALPHA )*X( IX + INCX )\n TEMP2 = ZERO\n IX = KX\n IY = KY\n KK = K\n DO 70, K = KK, KK + J - 2\n Y( IY ) = Y( IY ) + TEMP1*AP( K )\n TEMP2 = TEMP2 + CONJG( AP( K ) )*DCMPLX( X( IX ) )\n IX = IX + INCX\n IY = IY + INCY\n 70 CONTINUE\n Y( IY ) = Y( IY ) + TEMP1*REAL( AP( K ) ) + ALPHA*TEMP2\n K = K + 1\n 80 CONTINUE\n END IF\n ELSE\n*\n* Form y when AP contains the lower triangle.\n*\n IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN\n DO 100, J = 1, N\n TEMP1 = DCMPLX( ALPHA )*X( J )\n TEMP2 = ZERO\n Y( J ) = Y( J ) + TEMP1*REAL( AP( K ) )\n K = K + 1\n DO 90, I = J + 1, N\n Y( I ) = Y( I ) + TEMP1*AP( K )\n TEMP2 = TEMP2 + CONJG( AP( K ) )*DCMPLX( X( I ) )\n K = K + 1\n 90 CONTINUE\n Y( J ) = Y( J ) + ALPHA*TEMP2\n 100 CONTINUE\n ELSE\n JX = KX\n JY = KY\n DO 120, J = 1, N\n TEMP1 = DCMPLX( ALPHA )*X( JX )\n TEMP2 = ZERO\n Y( JY ) = Y( JY ) + TEMP1*REAL( AP( K ) )\n IX = JX\n IY = JY\n KK = K + 1\n DO 110, K = KK, KK + N - ( J + 1 )\n IX = IX + INCX\n IY = IY + INCY\n Y( IY ) = Y( IY ) + TEMP1*AP( K )\n TEMP2 = TEMP2 + CONJG( AP( K ) )*DCMPLX( X( IX ) )\n 110 CONTINUE\n Y( JY ) = Y( JY ) + ALPHA*TEMP2\n JX = JX + INCX\n JY = JY + INCY\n 120 CONTINUE\n END IF\n END IF\n*\n RETURN\n*\n* End of ECHPMV.\n*\n END\n*\n************************************************************************\n*\n SUBROUTINE ECHPR ( UPLO, N, ALPHA, X, INCX, AP )\n* .. Scalar Arguments ..\n REAL ALPHA\n INTEGER INCX, N\n CHARACTER*1 UPLO\n* .. Array Arguments ..\n COMPLEX*16 X( * )\n COMPLEX AP( * )\n* ..\n*\n* Purpose\n* =======\n*\n* ECHPR performs the hermitian rank 1 operation\n*\n* A := alpha*x*conjg( x' ) + A,\n*\n* where alpha is a real scalar, x is an n element vector and A is an\n* n by n hermitian matrix. Additional precision arithmetic is used in\n* the computation.\n*\n* Parameters\n* ==========\n*\n* UPLO - CHARACTER*1.\n* On entry, UPLO specifies whether the upper or lower\n* triangular part of the matrix A is supplied in the packed\n* array AP as follows:\n*\n* UPLO = 'U' or 'u' The upper triangular part of A is\n* supplied in AP.\n*\n* UPLO = 'L' or 'l' The lower triangular part of A is\n* supplied in AP.\n*\n* Unchanged on exit.\n*\n* N - INTEGER.\n* On entry, N specifies the order of the matrix A.\n* N must be at least zero.\n* Unchanged on exit.\n*\n* ALPHA - REAL .\n* On entry, ALPHA specifies the scalar alpha.\n* Unchanged on exit.\n*\n* X - COMPLEX*16 array of dimension at least\n* ( 1 + ( n - 1 )*abs( INCX ) ).\n* Before entry, the incremented array X must contain the n\n* element vector x.\n* Unchanged on exit.\n*\n* INCX - INTEGER.\n* On entry, INCX specifies the increment for the elements of\n* X. INCX must not be zero.\n* Unchanged on exit.\n*\n* AP - COMPLEX array of DIMENSION at least\n* ( ( n*( n + 1 ) )/2 ).\n* Before entry with UPLO = 'U' or 'u', the array AP must\n* contain the upper triangular part of the hermitian matrix\n* packed sequentially, column by column, so that AP( 1 )\n* contains a( 1, 1 ), AP( 2 ) and AP( 3 ) contain a( 1, 2 )\n* and a( 2, 2 ) respectively, and so on. On exit, the array\n* AP is overwritten by the upper triangular part of the\n* updated matrix.\n* Before entry with UPLO = 'L' or 'l', the array AP must\n* contain the lower triangular part of the hermitian matrix\n* packed sequentially, column by column, so that AP( 1 )\n* contains a( 1, 1 ), AP( 2 ) and AP( 3 ) contain a( 2, 1 )\n* and a( 3, 1 ) respectively, and so on. On exit, the array\n* AP is overwritten by the lower triangular part of the\n* updated matrix.\n* Note that the imaginary parts of the diagonal elements need\n* not be set, they are assumed to be zero, and on exit they\n* are set to zero. At least double precision arithmetic is\n* used in the computation of A.\n*\n*\n* Level 2 Blas routine.\n*\n* -- Written on 20-July-1986.\n* Sven Hammarling, Nag Central Office.\n* Richard Hanson, Sandia National Labs.\n*\n*\n* .. Parameters ..\n COMPLEX*16 ZERO\n PARAMETER ( ZERO = ( 0.0D+0, 0.0D+0 ) )\n* .. Local Scalars ..\n COMPLEX*16 TEMP\n INTEGER I, INFO, IX, J, JX, K, KK, KX\n* .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\n* .. External Subroutines ..\n EXTERNAL XERBLA\n* .. Intrinsic Functions ..\n INTRINSIC DCONJG, DBLE, REAL\n* ..\n* .. Executable Statements ..\n*\n* Test the input parameters.\n*\n INFO = 0\n IF ( .NOT.LSAME( UPLO, 'U' ).AND.\n $ .NOT.LSAME( UPLO, 'L' ) ) THEN\n INFO = 1\n ELSE IF ( N.LT.0 ) THEN\n INFO = 2\n ELSE IF ( INCX.EQ.0 ) THEN\n INFO = 5\n END IF\n IF( INFO.NE.0 )THEN\n CALL XERBLA( 'ECHPR ', INFO )\n RETURN\n END IF\n*\n* Quick return if possible.\n*\n IF( ( N.EQ.0 ).OR.( ALPHA.EQ.REAL( ZERO ) ) )\n $ RETURN\n*\n* Set the start point in X if the increment is not unity.\n*\n IF( INCX.LE.0 )THEN\n KX = 1 - ( N - 1 )*INCX\n ELSE IF( INCX.NE.1 )THEN\n KX = 1\n END IF\n*\n* Start the operations. In this version the elements of the array AP\n* are accessed sequentially with one pass through AP.\n*\n K = 1\n IF( LSAME( UPLO, 'U' ) )THEN\n*\n* Form A when upper triangle is stored in AP.\n*\n IF( INCX.EQ.1 )THEN\n DO 20, J = 1, N\n IF( X( J ).NE.ZERO )THEN\n TEMP = ALPHA*DCONJG( X( J ) )\n DO 10, I = 1, J - 1\n AP( K ) = AP( K ) + X( I )*TEMP\n K = K + 1\n 10 CONTINUE\n AP( K ) = REAL( AP( K ) ) + DBLE( X( J )*TEMP )\n ELSE\n K = K + J - 1\n AP( K ) = REAL( AP( K ) )\n END IF\n K = K + 1\n 20 CONTINUE\n ELSE\n JX = KX\n DO 40, J = 1, N\n IF( X( JX ).NE.ZERO )THEN\n TEMP = ALPHA*DCONJG( X( JX ) )\n IX = KX\n KK = K\n DO 30, K = KK, KK + J - 2\n AP( K ) = AP( K ) + X( IX )*TEMP\n IX = IX + INCX\n 30 CONTINUE\n AP( K ) = REAL( AP( K ) ) + DBLE( X( JX )*TEMP )\n ELSE\n K = K + J - 1\n AP( K ) = REAL( AP( K ) )\n END IF\n K = K + 1\n JX = JX + INCX\n 40 CONTINUE\n END IF\n ELSE\n*\n* Form A when lower triangle is stored in AP.\n*\n IF( INCX.EQ.1 )THEN\n DO 60, J = 1, N\n IF( X( J ).NE.ZERO )THEN\n TEMP = ALPHA*DCONJG( X( J ) )\n AP( K ) = REAL( AP( K ) ) + DBLE( TEMP*X( J ) )\n K = K + 1\n DO 50, I = J + 1, N\n AP( K ) = AP( K ) + X( I )*TEMP\n K = K + 1\n 50 CONTINUE\n ELSE\n AP( K ) = REAL( AP( K ) )\n K = K + N - J + 1\n END IF\n 60 CONTINUE\n ELSE\n JX = KX\n DO 80, J = 1, N\n IF( X( JX ).NE.ZERO )THEN\n TEMP = ALPHA*DCONJG( X( JX ) )\n AP( K ) = REAL( AP( K ) ) + DBLE( TEMP*X( JX ) )\n IX = JX\n KK = K + 1\n DO 70, K = KK, KK + N - J - 1\n IX = IX + INCX\n AP( K ) = AP( K ) + X( IX )*TEMP\n 70 CONTINUE\n ELSE\n AP( K ) = REAL( AP( K ) )\n K = K + N - J + 1\n END IF\n JX = JX + INCX\n 80 CONTINUE\n END IF\n END IF\n*\n RETURN\n*\n* End of ECHPR .\n*\n END\n*\n************************************************************************\n*\n SUBROUTINE ECHPR2( UPLO, N, ALPHA, X, INCX, Y, INCY, AP )\n* .. Scalar Arguments ..\n COMPLEX ALPHA\n INTEGER INCX, INCY, N\n CHARACTER*1 UPLO\n* .. Array Arguments ..\n COMPLEX*16 X( * ), Y( * )\n COMPLEX AP( * )\n* ..\n*\n* Purpose\n* =======\n*\n* ECHPR2 performs the hermitian rank 2 operation\n*\n* A := alpha*x*conjg( y' ) + conjg( alpha )*y*conjg( x' ) + A,\n*\n* where alpha is a scalar, x and y are n element vectors and A is an\n* n by n hermitian matrix. Additional precision arithmetic is used in\n* the computation.\n*\n* Parameters\n* ==========\n*\n* UPLO - CHARACTER*1.\n* On entry, UPLO specifies whether the upper or lower\n* triangular part of the matrix A is supplied in the packed\n* array AP as follows:\n*\n* UPLO = 'U' or 'u' The upper triangular part of A is\n* supplied in AP.\n*\n* UPLO = 'L' or 'l' The lower triangular part of A is\n* supplied in AP.\n*\n* Unchanged on exit.\n*\n* N - INTEGER.\n* On entry, N specifies the order of the matrix A.\n* N must be at least zero.\n* Unchanged on exit.\n*\n* ALPHA - COMPLEX .\n* On entry, ALPHA specifies the scalar alpha.\n* Unchanged on exit.\n*\n* X - COMPLEX*16 array of dimension at least\n* ( 1 + ( n - 1 )*abs( INCX ) ).\n* Before entry, the incremented array X must contain the n\n* element vector x.\n* Unchanged on exit.\n*\n* INCX - INTEGER.\n* On entry, INCX specifies the increment for the elements of\n* X. INCX must not be zero.\n* Unchanged on exit.\n*\n* Y - COMPLEX*16 array of dimension at least\n* ( 1 + ( n - 1 )*abs( INCY ) ).\n* Before entry, the incremented array Y must contain the n\n* element vector y.\n* Unchanged on exit.\n*\n* INCY - INTEGER.\n* On entry, INCY specifies the increment for the elements of\n* Y. INCY must not be zero.\n* Unchanged on exit.\n*\n* AP - COMPLEX array of DIMENSION at least\n* ( ( n*( n + 1 ) )/2 ).\n* Before entry with UPLO = 'U' or 'u', the array AP must\n* contain the upper triangular part of the hermitian matrix\n* packed sequentially, column by column, so that AP( 1 )\n* contains a( 1, 1 ), AP( 2 ) and AP( 3 ) contain a( 1, 2 )\n* and a( 2, 2 ) respectively, and so on. On exit, the array\n* AP is overwritten by the upper triangular part of the\n* updated matrix.\n* Before entry with UPLO = 'L' or 'l', the array AP must\n* contain the lower triangular part of the hermitian matrix\n* packed sequentially, column by column, so that AP( 1 )\n* contains a( 1, 1 ), AP( 2 ) and AP( 3 ) contain a( 2, 1 )\n* and a( 3, 1 ) respectively, and so on. On exit, the array\n* AP is overwritten by the lower triangular part of the\n* updated matrix.\n* Note that the imaginary parts of the diagonal elements need\n* not be set, they are assumed to be zero, and on exit they\n* are set to zero. At least double precision arithmetic is\n* used in the computation of A.\n*\n*\n* Level 2 Blas routine.\n*\n* -- Written on 20-July-1986.\n* Sven Hammarling, Nag Central Office.\n* Richard Hanson, Sandia National Labs.\n*\n*\n* .. Parameters ..\n COMPLEX*16 ZERO\n PARAMETER ( ZERO = ( 0.0D+0, 0.0D+0 ) )\n* .. Local Scalars ..\n COMPLEX*16 TEMP1, TEMP2\n INTEGER I, INFO, IX, IY, J, JX, JY, K, KK, KX, KY\n* .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\n* .. External Subroutines ..\n EXTERNAL XERBLA\n* .. Intrinsic Functions ..\n INTRINSIC DCONJG, DBLE, CMPLX, REAL\n* ..\n* .. Executable Statements ..\n*\n* Test the input parameters.\n*\n INFO = 0\n IF ( .NOT.LSAME( UPLO, 'U' ).AND.\n $ .NOT.LSAME( UPLO, 'L' ) ) THEN\n INFO = 1\n ELSE IF ( N.LT.0 ) THEN\n INFO = 2\n ELSE IF ( INCX.EQ.0 ) THEN\n INFO = 5\n ELSE IF ( INCY.EQ.0 ) THEN\n INFO = 7\n END IF\n IF( INFO.NE.0 )THEN\n CALL XERBLA( 'ECHPR2', INFO )\n RETURN\n END IF\n*\n* Quick return if possible.\n*\n IF( ( N.EQ.0 ).OR.( ALPHA.EQ.CMPLX( ZERO ) ) )\n $ RETURN\n*\n* Set up the start points in X and Y if the increments are not both\n* unity.\n*\n IF( ( INCX.NE.1 ).OR.( INCY.NE.1 ) )THEN\n IF( INCX.GT.0 )THEN\n KX = 1\n ELSE\n KX = 1 - ( N - 1 )*INCX\n END IF\n IF( INCY.GT.0 )THEN\n KY = 1\n ELSE\n KY = 1 - ( N - 1 )*INCY\n END IF\n END IF\n*\n* Start the operations. In this version the elements of the array AP\n* are accessed sequentially with one pass through AP.\n*\n K = 1\n IF( LSAME( UPLO, 'U' ) )THEN\n*\n* Form A when upper triangle is stored in AP.\n*\n IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN\n DO 20, J = 1, N\n IF( ( X( J ).NE.ZERO ).OR.( Y( J ).NE.ZERO ) )THEN\n TEMP1 = ALPHA*DCONJG( Y( J ) )\n TEMP2 = DCONJG( ALPHA*X( J ) )\n DO 10, I = 1, J - 1\n AP( K ) = AP( K ) + X( I )*TEMP1 + Y( I )*TEMP2\n K = K + 1\n 10 CONTINUE\n AP( K ) = REAL( AP( K ) ) +\n $ DBLE( X( J )*TEMP1 + Y( J )*TEMP2 )\n ELSE\n K = K + J - 1\n AP( K ) = REAL( AP( K ) )\n END IF\n K = K + 1\n 20 CONTINUE\n ELSE\n JX = KX\n JY = KY\n DO 40, J = 1, N\n IF( ( X( JX ).NE.ZERO ).OR.( Y( JY ).NE.ZERO ) )THEN\n TEMP1 = ALPHA*DCONJG( Y( JY ) )\n TEMP2 = DCONJG( ALPHA*X( JX ) )\n IX = KX\n IY = KY\n KK = K\n DO 30, K = KK, KK + J - 2\n AP( K ) = AP( K ) + X( IX )*TEMP1 + Y( IY )*TEMP2\n IX = IX + INCX\n IY = IY + INCY\n 30 CONTINUE\n AP( K ) = REAL( AP( K ) ) +\n $ DBLE( X( JX )*TEMP1 + Y( JY )*TEMP2 )\n ELSE\n K = K + J - 1\n AP( K ) = REAL( AP( K ) )\n END IF\n K = K + 1\n JX = JX + INCX\n JY = JY + INCY\n 40 CONTINUE\n END IF\n ELSE\n*\n* Form A when lower triangle is stored in AP.\n*\n IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN\n DO 60, J = 1, N\n IF( ( X( J ).NE.ZERO ).OR.( Y( J ).NE.ZERO ) )THEN\n TEMP1 = ALPHA*DCONJG( Y( J ) )\n TEMP2 = DCONJG( ALPHA*X( J ) )\n AP( K ) = REAL( AP( K ) ) +\n $ DBLE( X( J )*TEMP1 + Y( J )*TEMP2 )\n K = K + 1\n DO 50, I = J + 1, N\n AP( K ) = AP( K ) + X( I )*TEMP1 + Y( I )*TEMP2\n K = K + 1\n 50 CONTINUE\n ELSE\n AP( K ) = REAL( AP( K ) )\n K = K + N - J + 1\n END IF\n 60 CONTINUE\n ELSE\n JX = KX\n JY = KY\n DO 80, J = 1, N\n IF( ( X( JX ).NE.ZERO ).OR.( Y( JY ).NE.ZERO ) )THEN\n TEMP1 = ALPHA*DCONJG( Y( JY ) )\n TEMP2 = DCONJG( ALPHA*X( JX ) )\n AP( K ) = REAL( AP( K ) ) +\n $ DBLE( X( JX )*TEMP1 + Y( JY )*TEMP2 )\n IX = JX\n IY = JY\n KK = K + 1\n DO 70, K = KK, KK + N - J - 1\n IX = IX + INCX\n IY = IY + INCY\n AP( K ) = AP( K ) + X( IX )*TEMP1 + Y( IY )*TEMP2\n 70 CONTINUE\n ELSE\n AP( K ) = REAL( AP( K ) )\n K = K + N - J + 1\n END IF\n JX = JX + INCX\n JY = JY + INCY\n 80 CONTINUE\n END IF\n END IF\n*\n RETURN\n*\n* End of ECHPR2.\n*\n END\n*\n************************************************************************\n*\n SUBROUTINE ECHBMV( UPLO, N, K, ALPHA, A, LDA, X, INCX,\n $ BETA, Y, INCY )\n* .. Scalar Arguments ..\n COMPLEX ALPHA, BETA\n INTEGER INCX, INCY, K, LDA, N\n CHARACTER*1 UPLO\n* .. Array Arguments ..\n COMPLEX*16 Y( * )\n COMPLEX A( LDA, * ), X( * )\n* ..\n*\n* Purpose\n* =======\n*\n* ECHBMV performs the matrix-vector operation\n*\n* y := alpha*A*x + beta*y,\n*\n* where alpha and beta are scalars, x and y are n element vectors and\n* A is an n by n hermitian band matrix, with k super-diagonals.\n* Additional precision arithmetic is used in the computation.\n*\n* Parameters\n* ==========\n*\n* UPLO - CHARACTER*1.\n* On entry, UPLO specifies whether the upper or lower\n* triangular part of the band matrix A is being supplied as\n* follows:\n*\n* UPLO = 'U' or 'u' The upper triangular part of A is\n* being supplied.\n*\n* UPLO = 'L' or 'l' The lower triangular part of A is\n* being supplied.\n*\n* Unchanged on exit.\n*\n* N - INTEGER.\n* On entry, N specifies the order of the matrix A.\n* N must be at least zero.\n* Unchanged on exit.\n*\n* K - INTEGER.\n* On entry, K specifies the number of super-diagonals of the\n* matrix A. K must satisfy 0 .le. K.\n* Unchanged on exit.\n*\n* ALPHA - COMPLEX .\n* On entry, ALPHA specifies the scalar alpha.\n* Unchanged on exit.\n*\n* A - COMPLEX array of DIMENSION ( LDA, n ).\n* Before entry with UPLO = 'U' or 'u', the leading ( k + 1 )\n* by n part of the array A must contain the upper triangular\n* band part of the hermitian matrix, supplied column by\n* column, with the leading diagonal of the matrix in row\n* ( k + 1 ) of the array, the first super-diagonal starting at\n* position 2 in row k, and so on. The top left k by k triangle\n* of the array A is not referenced.\n* The following program segment will transfer the upper\n* triangular part of a hemitian band matrix from conventional\n* full matrix storage to band storage:\n*\n* DO 20, J = 1, N\n* M = K + 1 - J\n* DO 10, I = MAX( 1, J - K ), J\n* A( M + I, J ) = matrix( I, J )\n* 10 CONTINUE\n* 20 CONTINUE\n*\n* Before entry with UPLO = 'L' or 'l', the leading ( k + 1 )\n* by n part of the array A must contain the lower triangular\n* band part of the hermitian matrix, supplied column by\n* column, with the leading diagonal of the matrix in row 1 of\n* the array, the first sub-diagonal starting at position 1 in\n* row 2, and so on. The bottom right k by k triangle of the\n* array A is not referenced.\n* The following program segment will transfer the lower\n* triangular part of a hermitian band matrix from conventional\n* full matrix storage to band storage:\n*\n* DO 20, J = 1, N\n* M = 1 - J\n* DO 10, I = J, MIN( N, J + K )\n* A( M + I, J ) = matrix( I, J )\n* 10 CONTINUE\n* 20 CONTINUE\n*\n* Note that the imaginary parts of the diagonal elements need\n* not be set and are assumed to be zero.\n* Unchanged on exit.\n*\n* LDA - INTEGER.\n* On entry, LDA specifies the first dimension of A as declared\n* in the calling (sub) program. LDA must be at least\n* ( k + 1 ).\n* Unchanged on exit.\n*\n* X - COMPLEX array of DIMENSION at least\n* ( 1 + ( n - 1 )*abs( INCX ) ).\n* Before entry, the incremented array X must contain the\n* vector x.\n* Unchanged on exit.\n*\n* INCX - INTEGER.\n* On entry, INCX specifies the increment for the elements of\n* X. INCX must not be zero.\n* Unchanged on exit.\n*\n* BETA - COMPLEX .\n* On entry, BETA specifies the scalar beta.\n* Unchanged on exit.\n*\n* Y - COMPLEX*16 array of DIMENSION at least\n* ( 1 + ( n - 1 )*abs( INCY ) ).\n* Before entry, the incremented array Y must contain the\n* vector y. On exit, Y is overwritten by the updated vector y.\n* At least double precision arithmetic is used in the\n* computation of y.\n*\n* INCY - INTEGER.\n* On entry, INCY specifies the increment for the elements of\n* Y. INCY must not be zero.\n* Unchanged on exit.\n*\n*\n* Level 2 Blas routine.\n*\n* -- Written on 20-July-1986.\n* Sven Hammarling, Nag Central Office.\n* Richard Hanson, Sandia National Labs.\n*\n*\n* .. Parameters ..\n COMPLEX ONE\n PARAMETER ( ONE = ( 1.0E+0, 0.0E+0 ) )\n COMPLEX ZERO\n PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) )\n* .. Local Scalars ..\n COMPLEX*16 TEMP1, TEMP2\n INTEGER I, INFO, IX, IY, J, JX, JY, KPLUS1, KX, KY, L\n* .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\n* .. External Subroutines ..\n EXTERNAL XERBLA\n* .. Intrinsic Functions ..\n INTRINSIC DCMPLX, MAX, MIN, CONJG, REAL\n* ..\n* .. Executable Statements ..\n*\n* Test the input parameters.\n*\n INFO = 0\n IF ( .NOT.LSAME( UPLO, 'U' ).AND.\n $ .NOT.LSAME( UPLO, 'L' ) ) THEN\n INFO = 1\n ELSE IF ( N.LT.0 ) THEN\n INFO = 2\n ELSE IF ( K.LT.0 ) THEN\n INFO = 3\n ELSE IF ( LDA.LT.( K + 1 ) ) THEN\n INFO = 6\n ELSE IF ( INCX.EQ.0 ) THEN\n INFO = 8\n ELSE IF ( INCY.EQ.0 ) THEN\n INFO = 11\n END IF\n IF( INFO.NE.0 )THEN\n CALL XERBLA( 'ECHBMV', INFO )\n RETURN\n END IF\n*\n* Quick return if possible.\n*\n IF( ( N.EQ.0 ).OR.( ( ALPHA.EQ.ZERO ).AND.( BETA.EQ.ONE ) ) )\n $ RETURN\n*\n* Start the operations. In this version the elements of the array A\n* are accessed sequentially with one pass through A.\n*\n* First form y := beta*y and set up the start points in X and Y if\n* the increments are not both unity.\n*\n IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN\n IF( BETA.NE.ONE )THEN\n IF( BETA.EQ.ZERO )THEN\n DO 10, I = 1, N\n Y( I ) = ZERO\n 10 CONTINUE\n ELSE\n DO 20, I = 1, N\n Y( I ) = BETA*Y( I )\n 20 CONTINUE\n END IF\n END IF\n ELSE\n IF( INCX.GT.0 )THEN\n KX = 1\n ELSE\n KX = 1 - ( N - 1 )*INCX\n END IF\n IF( INCY.GT.0 )THEN\n KY = 1\n ELSE\n KY = 1 - ( N - 1 )*INCY\n END IF\n IF( BETA.NE.ONE )THEN\n IY = KY\n IF( BETA.EQ.ZERO )THEN\n DO 30, I = 1, N\n Y( IY ) = ZERO\n IY = IY + INCY\n 30 CONTINUE\n ELSE\n DO 40, I = 1, N\n Y( IY ) = BETA*Y( IY )\n IY = IY + INCY\n 40 CONTINUE\n END IF\n END IF\n END IF\n IF( ALPHA.EQ.ZERO )\n $ RETURN\n IF( LSAME( UPLO, 'U' ) )THEN\n*\n* Form y when upper triangle of A is stored.\n*\n KPLUS1 = K + 1\n IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN\n DO 60, J = 1, N\n TEMP1 = DCMPLX( ALPHA )*X( J )\n TEMP2 = ZERO\n L = KPLUS1 - J\n DO 50, I = MAX( 1, J - K ), J - 1\n Y( I ) = Y( I ) + TEMP1*A( L + I, J )\n TEMP2 = TEMP2 +\n $ CONJG( A( L + I, J ) )*DCMPLX( X( I ) )\n 50 CONTINUE\n Y( J ) = Y( J ) + TEMP1*REAL( A( KPLUS1, J ) )\n $ + ALPHA*TEMP2\n 60 CONTINUE\n ELSE\n IX = KX - INCX\n DO 80, J = 1, N\n TEMP1 = DCMPLX( ALPHA )*X( IX + INCX )\n TEMP2 = ZERO\n IX = KX\n IY = KY\n L = KPLUS1 - J\n DO 70, I = MAX( 1, J - K ), J - 1\n Y( IY ) = Y( IY ) + TEMP1*A( L + I, J )\n TEMP2 = TEMP2 +\n $ CONJG( A( L + I, J ) )*DCMPLX( X( IX ) )\n IX = IX + INCX\n IY = IY + INCY\n 70 CONTINUE\n Y( IY ) = Y( IY ) + TEMP1*REAL( A( KPLUS1, J ) )\n $ + ALPHA*TEMP2\n IF( J.GT.K )THEN\n KX = KX + INCX\n KY = KY + INCY\n END IF\n 80 CONTINUE\n END IF\n ELSE\n*\n* Form y when lower triangle of A is stored.\n*\n IF( ( INCX.EQ.1 ).AND.( INCY.EQ.1 ) )THEN\n DO 100, J = 1, N\n TEMP1 = DCMPLX( ALPHA )*X( J )\n TEMP2 = ZERO\n Y( J ) = Y( J ) + TEMP1*REAL( A( 1, J ) )\n L = 1 - J\n DO 90, I = J + 1, MIN( N, J + K )\n Y( I ) = Y( I ) + TEMP1*A( L + I, J )\n TEMP2 = TEMP2 +\n $ CONJG( A( L + I, J ) )*DCMPLX( X( I ) )\n 90 CONTINUE\n Y( J ) = Y( J ) + ALPHA*TEMP2\n 100 CONTINUE\n ELSE\n JX = KX\n JY = KY\n DO 120, J = 1, N\n TEMP1 = DCMPLX( ALPHA )*X( JX )\n TEMP2 = ZERO\n Y( JY ) = Y( JY ) + TEMP1*REAL( A( 1, J ) )\n L = 1 - J\n IX = JX\n IY = JY\n DO 110, I = J + 1, MIN( N, J + K )\n IX = IX + INCX\n IY = IY + INCY\n Y( IY ) = Y( IY ) + TEMP1*A( L + I, J )\n TEMP2 = TEMP2 +\n $ CONJG( A( L + I, J ) )*DCMPLX( X( IX ) )\n 110 CONTINUE\n Y( JY ) = Y( JY ) + ALPHA*TEMP2\n JX = JX + INCX\n JY = JY + INCY\n 120 CONTINUE\n END IF\n END IF\n*\n RETURN\n*\n* End of ECHBMV.\n*\n END\n*\n************************************************************************\n*\n SUBROUTINE ECTRMV( UPLO, TRANS, DIAG, N, A, LDA, X, INCX )\n* .. Scalar Arguments ..\n INTEGER INCX, LDA, N\n CHARACTER*1 DIAG, TRANS, UPLO\n* .. Array Arguments ..\n COMPLEX*16 X( * )\n COMPLEX A( LDA, * )\n* ..\n*\n* Purpose\n* =======\n*\n* ECTRMV performs one of the matrix-vector operations\n*\n* x := A*x, or x := A'*x, or x := conjg( A' )*x,\n*\n* where x is n element vector and A is an n by n unit, or non-unit,\n* upper or lower triangular matrix. Additional precision arithmetic is\n* used in the computation.\n*\n* Parameters\n* ==========\n*\n* UPLO - CHARACTER*1.\n* On entry, UPLO specifies whether the matrix is an upper or\n* lower triangular matrix as follows:\n*\n* UPLO = 'U' or 'u' A is an upper triangular matrix.\n*\n* UPLO = 'L' or 'l' A is a lower triangular matrix.\n*\n* Unchanged on exit.\n*\n* TRANS - CHARACTER*1.\n* On entry, TRANS specifies the operation to be performed as\n* follows:\n*\n* TRANS = 'N' or 'n' x := A*x.\n*\n* TRANS = 'T' or 't' x := A'*x.\n*\n* TRANS = 'C' or 'c' x := conjg( A' )*x.\n*\n* Unchanged on exit.\n*\n* DIAG - CHARACTER*1.\n* On entry, DIAG specifies whether or not A is unit\n* triangular as follows:\n*\n* DIAG = 'U' or 'u' A is assumed to be unit triangular.\n*\n* DIAG = 'N' or 'n' A is not assumed to be unit\n* triangular.\n*\n* Unchanged on exit.\n*\n* N - INTEGER.\n* On entry, N specifies the order of the matrix A.\n* N must be at least zero.\n* Unchanged on exit.\n*\n* A - COMPLEX array of DIMENSION ( LDA, n ).\n* Before entry with UPLO = 'U' or 'u', the leading n by n\n* upper triangular part of the array A must contain the upper\n* triangular matrix and the strictly lower triangular part of\n* A is not referenced.\n* Before entry with UPLO = 'L' or 'l', the leading n by n\n* lower triangular part of the array A must contain the lower\n* triangular matrix and the strictly upper triangular part of\n* A is not referenced.\n* Note that when DIAG = 'U' or 'u', the diagonal elements of\n* A are not referenced either, but are assumed to be unity.\n* Unchanged on exit.\n*\n* LDA - INTEGER.\n* On entry, LDA specifies the first dimension of A as declared\n* in the calling (sub) program. LDA must be at least\n* max( 1, n ).\n* Unchanged on exit.\n*\n* X - COMPLEX*16 array of dimension at least\n* ( 1 + ( n - 1 )*abs( INCX ) ).\n* Before entry, the incremented array X must contain the n\n* element vector x. On exit, X is overwritten with the\n* tranformed vector x. At least double precision arithmetic is\n* used in the computation of x.\n*\n* INCX - INTEGER.\n* On entry, INCX specifies the increment for the elements of\n* X. INCX must not be zero.\n* Unchanged on exit.\n*\n*\n* Level 2 Blas routine.\n*\n* -- Written on 20-July-1986.\n* Sven Hammarling, Nag Central Office.\n* Richard Hanson, Sandia National Labs.\n*\n*\n* .. Parameters ..\n COMPLEX*16 ZERO\n PARAMETER ( ZERO = ( 0.0D+0, 0.0D+0 ) )\n* .. Local Scalars ..\n INTEGER I, INFO, IX, J, JX, KX\n LOGICAL NOCONJ, NOUNIT\n* .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\n* .. External Subroutines ..\n EXTERNAL XERBLA\n* .. Intrinsic Functions ..\n INTRINSIC CONJG, MAX\n* ..\n* .. Executable Statements ..\n*\n* Test the input parameters.\n*\n INFO = 0\n IF ( .NOT.LSAME( UPLO, 'U' ).AND.\n $ .NOT.LSAME( UPLO, 'L' ) ) THEN\n INFO = 1\n ELSE IF ( .NOT.LSAME( TRANS, 'N' ).AND.\n $ .NOT.LSAME( TRANS, 'T' ).AND.\n $ .NOT.LSAME( TRANS, 'C' ) ) THEN\n INFO = 2\n ELSE IF ( .NOT.LSAME( DIAG, 'U' ).AND.\n $ .NOT.LSAME( DIAG, 'N' ) ) THEN\n INFO = 3\n ELSE IF ( N.LT.0 ) THEN\n INFO = 4\n ELSE IF ( LDA.LT.MAX(1,N) ) THEN\n INFO = 6\n ELSE IF ( INCX.EQ.0 ) THEN\n INFO = 8\n END IF\n IF( INFO.NE.0 )THEN\n CALL XERBLA( 'ECTRMV', INFO )\n RETURN\n END IF\n*\n* Quick return if possible.\n*\n IF( N.EQ.0 )\n $ RETURN\n*\n NOCONJ = LSAME( TRANS, 'T' )\n NOUNIT = ( DIAG .EQ.'N' ).OR.( DIAG .EQ.'n' )\n*\n* Set up the start point in X if the increment is not unity. This\n* will be ( N - 1 )*INCX too small for descending loops.\n*\n IF( INCX.LE.0 )THEN\n KX = 1 - ( N - 1 )*INCX\n ELSE IF( INCX.NE.1 )THEN\n KX = 1\n END IF\n*\n* Start the operations. In this version the elements of A are\n* accessed sequentially with one pass through A.\n*\n IF( LSAME( TRANS, 'N' ) )THEN\n*\n* Form x := A*x.\n*\n IF( LSAME( UPLO, 'U' ) )THEN\n IF( INCX.EQ.1 )THEN\n DO 20, J = 1, N\n IF( X( J ).NE.ZERO )THEN\n DO 10, I = 1, J - 1\n X( I ) = X( I ) + X( J )*A( I, J )\n 10 CONTINUE\n IF( NOUNIT )\n $ X( J ) = X( J )*A( J, J )\n END IF\n 20 CONTINUE\n ELSE\n JX = KX\n DO 40, J = 1, N\n IF( X( JX ).NE.ZERO )THEN\n IX = KX\n DO 30, I = 1, J - 1\n X( IX ) = X( IX ) + X( JX )*A( I, J )\n IX = IX + INCX\n 30 CONTINUE\n IF( NOUNIT )\n $ X( JX ) = X( JX )*A( J, J )\n END IF\n JX = JX + INCX\n 40 CONTINUE\n END IF\n ELSE\n IF( INCX.EQ.1 )THEN\n DO 60, J = N, 1, -1\n IF( X( J ).NE.ZERO )THEN\n DO 50, I = N, J + 1, -1\n X( I ) = X( I ) + X( J )*A( I, J )\n 50 CONTINUE\n IF( NOUNIT )\n $ X( J ) = X( J )*A( J, J )\n END IF\n 60 CONTINUE\n ELSE\n KX = KX + ( N - 1 )*INCX\n JX = KX\n DO 80, J = N, 1, -1\n IF( X( JX ).NE.ZERO )THEN\n IX = KX\n DO 70, I = N, J + 1, -1\n X( IX ) = X( IX ) + X( JX )*A( I, J )\n IX = IX - INCX\n 70 CONTINUE\n IF( NOUNIT )\n $ X( JX ) = X( JX )*A( J, J )\n END IF\n JX = JX - INCX\n 80 CONTINUE\n END IF\n END IF\n ELSE\n*\n* Form x := A'*x or x := conjg( A' )*x.\n*\n IF( LSAME( UPLO, 'U' ) )THEN\n IF( INCX.EQ.1 )THEN\n DO 110, J = N, 1, -1\n IF( NOCONJ )THEN\n IF( NOUNIT )\n $ X( J ) = X( J )*A( J, J )\n DO 90, I = J - 1, 1, -1\n X( J ) = X( J ) + A( I, J )*X( I )\n 90 CONTINUE\n ELSE\n IF( NOUNIT )\n $ X( J ) = X( J )*CONJG( A( J, J ) )\n DO 100, I = J - 1, 1, -1\n X( J ) = X( J ) + CONJG( A( I, J ) )*X( I )\n 100 CONTINUE\n END IF\n 110 CONTINUE\n ELSE\n JX = KX + ( N - 1 )*INCX\n DO 140, J = N, 1, -1\n IX = JX\n IF( NOCONJ )THEN\n IF( NOUNIT )\n $ X( JX ) = X( JX )*A( J, J )\n DO 120, I = J - 1, 1, -1\n IX = IX - INCX\n X( JX ) = X( JX ) + A( I, J )*X( IX )\n 120 CONTINUE\n ELSE\n IF( NOUNIT )\n $ X( JX ) = X( JX )*CONJG( A( J, J ) )\n DO 130, I = J - 1, 1, -1\n IX = IX - INCX\n X( JX ) = X( JX ) + CONJG( A( I, J ) )*X( IX )\n 130 CONTINUE\n END IF\n JX = JX - INCX\n 140 CONTINUE\n END IF\n ELSE\n IF( INCX.EQ.1 )THEN\n DO 170, J = 1, N\n IF( NOCONJ )THEN\n IF( NOUNIT )\n $ X( J ) = X( J )*A( J, J )\n DO 150, I = J + 1, N\n X( J ) = X( J ) + A( I, J )*X( I )\n 150 CONTINUE\n ELSE\n IF( NOUNIT )\n $ X( J ) = X( J )*CONJG( A( J, J ) )\n DO 160, I = J + 1, N\n X( J ) = X( J ) + CONJG( A( I, J ) )*X( I )\n 160 CONTINUE\n END IF\n 170 CONTINUE\n ELSE\n JX = KX\n DO 200, J = 1, N\n IX = JX\n IF( NOCONJ )THEN\n IF( NOUNIT )\n $ X( JX ) = X( JX )*A( J, J )\n DO 180, I = J + 1, N\n IX = IX + INCX\n X( JX ) = X( JX ) + A( I, J )*X( IX )\n 180 CONTINUE\n ELSE\n IF( NOUNIT )\n $ X( JX ) = X( JX )*CONJG( A( J, J ) )\n DO 190, I = J + 1, N\n IX = IX + INCX\n X( JX ) = X( JX ) + CONJG( A( I, J ) )*X( IX )\n 190 CONTINUE\n END IF\n JX = JX + INCX\n 200 CONTINUE\n END IF\n END IF\n END IF\n*\n RETURN\n*\n* End of ECTRMV.\n*\n END\n*\n************************************************************************\n*\n SUBROUTINE ECTRSV( UPLO, TRANS, DIAG, N, A, LDA, X, INCX )\n* .. Scalar Arguments ..\n INTEGER INCX, LDA, N\n CHARACTER*1 DIAG, TRANS, UPLO\n* .. Array Arguments ..\n COMPLEX*16 X( * )\n COMPLEX A( LDA, * )\n* ..\n*\n* Purpose\n* =======\n*\n* ECTRSV solves one of the systems of equations\n*\n* A*x = b, or A'*x = b, or conjg( A' )*x = b,\n*\n* where b and x are n element vectors and A is an n by n unit, or\n* non-unit, upper or lower triangular matrix. Additional precision\n* arithmetic is used in the computation.\n*\n* No test for singularity or near-singularity is included in this\n* routine. Such tests must be performed before calling this routine.\n*\n* Parameters\n* ==========\n*\n* UPLO - CHARACTER*1.\n* On entry, UPLO specifies whether the matrix is an upper or\n* lower triangular matrix as follows:\n*\n* UPLO = 'U' or 'u' A is an upper triangular matrix.\n*\n* UPLO = 'L' or 'l' A is a lower triangular matrix.\n*\n* Unchanged on exit.\n*\n* TRANS - CHARACTER*1.\n* On entry, TRANS specifies the equations to be solved as\n* follows:\n*\n* TRANS = 'N' or 'n' A*x = b.\n*\n* TRANS = 'T' or 't' A'*x = b.\n*\n* TRANS = 'C' or 'c' conjg( A' )*x = b.\n*\n* Unchanged on exit.\n*\n* DIAG - CHARACTER*1.\n* On entry, DIAG specifies whether or not A is unit\n* triangular as follows:\n*\n* DIAG = 'U' or 'u' A is assumed to be unit triangular.\n*\n* DIAG = 'N' or 'n' A is not assumed to be unit\n* triangular.\n*\n* Unchanged on exit.\n*\n* N - INTEGER.\n* On entry, N specifies the order of the matrix A.\n* N must be at least zero.\n* Unchanged on exit.\n*\n* A - COMPLEX array of DIMENSION ( LDA, n ).\n* Before entry with UPLO = 'U' or 'u', the leading n by n\n* upper triangular part of the array A must contain the upper\n* triangular matrix and the strictly lower triangular part of\n* A is not referenced.\n* Before entry with UPLO = 'L' or 'l', the leading n by n\n* lower triangular part of the array A must contain the lower\n* triangular matrix and the strictly upper triangular part of\n* A is not referenced.\n* Note that when DIAG = 'U' or 'u', the diagonal elements of\n* A are not referenced either, but are assumed to be unity.\n* Unchanged on exit.\n*\n* LDA - INTEGER.\n* On entry, LDA specifies the first dimension of A as declared\n* in the calling (sub) program. LDA must be at least\n* max( 1, n ).\n* Unchanged on exit.\n*\n* X - COMPLEX*16 array of dimension at least\n* ( 1 + ( n - 1 )*abs( INCX ) ).\n* Before entry, the incremented array X must contain the n\n* element right-hand side vector b. On exit, X is overwritten\n* with the solution vector x. At least double precision\n* arithmetic is used in the computation of x.\n*\n* INCX - INTEGER.\n* On entry, INCX specifies the increment for the elements of\n* X. INCX must not be zero.\n* Unchanged on exit.\n*\n*\n* Level 2 Blas routine.\n*\n* -- Written on 20-July-1986.\n* Sven Hammarling, Nag Central Office.\n* Richard Hanson, Sandia National Labs.\n*\n*\n* .. Parameters ..\n COMPLEX*16 ZERO\n PARAMETER ( ZERO = ( 0.0D+0, 0.0D+0 ) )\n* .. Local Scalars ..\n INTEGER I, INFO, IX, J, JX, KX\n LOGICAL NOCONJ, NOUNIT\n* .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\n* .. External Subroutines ..\n EXTERNAL XERBLA\n* .. Intrinsic Functions ..\n INTRINSIC CONJG, MAX\n* ..\n* .. Executable Statements ..\n*\n* Test the input parameters.\n*\n INFO = 0\n IF ( .NOT.LSAME( UPLO, 'U' ).AND.\n $ .NOT.LSAME( UPLO, 'L' ) ) THEN\n INFO = 1\n ELSE IF ( .NOT.LSAME( TRANS, 'N' ).AND.\n $ .NOT.LSAME( TRANS, 'T' ).AND.\n $ .NOT.LSAME( TRANS, 'C' ) ) THEN\n INFO = 2\n ELSE IF ( .NOT.LSAME( DIAG, 'U' ).AND.\n $ .NOT.LSAME( DIAG, 'N' ) ) THEN\n INFO = 3\n ELSE IF ( N.LT.0 ) THEN\n INFO = 4\n ELSE IF ( LDA.LT.MAX(1,N) ) THEN\n INFO = 6\n ELSE IF ( INCX.EQ.0 ) THEN\n INFO = 8\n END IF\n IF( INFO.NE.0 )THEN\n CALL XERBLA( 'ECTRSV', INFO )\n RETURN\n END IF\n*\n* Quick return if possible.\n*\n IF( N.EQ.0 )\n $ RETURN\n*\n NOCONJ = LSAME( TRANS, 'T' )\n NOUNIT = ( DIAG .EQ.'N' ).OR.( DIAG .EQ.'n' )\n*\n* Set up the start point in X if the increment is not unity. This\n* will be ( N - 1 )*INCX too small for descending loops.\n*\n IF( INCX.LE.0 )THEN\n KX = 1 - ( N - 1 )*INCX\n ELSE IF( INCX.NE.1 )THEN\n KX = 1\n END IF\n*\n* Start the operations. In this version the elements of A are\n* accessed sequentially with one pass through A.\n*\n IF( LSAME( TRANS, 'N' ) )THEN\n*\n* Form x := inv( A )*x.\n*\n IF( LSAME( UPLO, 'U' ) )THEN\n IF( INCX.EQ.1 )THEN\n DO 20, J = N, 1, -1\n IF( X( J ).NE.ZERO )THEN\n IF( NOUNIT )\n $ X( J ) = X( J )/A( J, J )\n DO 10, I = J - 1, 1, -1\n X( I ) = X( I ) - X( J )*A( I, J )\n 10 CONTINUE\n END IF\n 20 CONTINUE\n ELSE\n JX = KX + ( N - 1 )*INCX\n DO 40, J = N, 1, -1\n IF( X( JX ).NE.ZERO )THEN\n IF( NOUNIT )\n $ X( JX ) = X( JX )/A( J, J )\n IX = JX\n DO 30, I = J - 1, 1, -1\n IX = IX - INCX\n X( IX ) = X( IX ) - X( JX )*A( I, J )\n 30 CONTINUE\n END IF\n JX = JX - INCX\n 40 CONTINUE\n END IF\n ELSE\n IF( INCX.EQ.1 )THEN\n DO 60, J = 1, N\n IF( X( J ).NE.ZERO )THEN\n IF( NOUNIT )\n $ X( J ) = X( J )/A( J, J )\n DO 50, I = J + 1, N\n X( I ) = X( I ) - X( J )*A( I, J )\n 50 CONTINUE\n END IF\n 60 CONTINUE\n ELSE\n JX = KX\n DO 80, J = 1, N\n IF( X( JX ).NE.ZERO )THEN\n IF( NOUNIT )\n $ X( JX ) = X( JX )/A( J, J )\n IX = JX\n DO 70, I = J + 1, N\n IX = IX + INCX\n X( IX ) = X( IX ) - X( JX )*A( I, J )\n 70 CONTINUE\n END IF\n JX = JX + INCX\n 80 CONTINUE\n END IF\n END IF\n ELSE\n*\n* Form x := inv( A' )*x or x := inv( conjg( A' ) )*x.\n*\n IF( LSAME( UPLO, 'U' ) )THEN\n IF( INCX.EQ.1 )THEN\n DO 110, J = 1, N\n IF( NOCONJ )THEN\n DO 90, I = 1, J - 1\n X( J ) = X( J ) - A( I, J )*X( I )\n 90 CONTINUE\n IF( NOUNIT )\n $ X( J ) = X( J )/A( J, J )\n ELSE\n DO 100, I = 1, J - 1\n X( J ) = X( J ) - CONJG( A( I, J ) )*X( I )\n 100 CONTINUE\n IF( NOUNIT )\n $ X( J ) = X( J )/CONJG( A( J, J ) )\n END IF\n 110 CONTINUE\n ELSE\n JX = KX\n DO 140, J = 1, N\n IX = KX\n IF( NOCONJ )THEN\n DO 120, I = 1, J - 1\n X( JX ) = X( JX ) - A( I, J )*X( IX )\n IX = IX + INCX\n 120 CONTINUE\n IF( NOUNIT )\n $ X( JX ) = X( JX )/A( J, J )\n ELSE\n DO 130, I = 1, J - 1\n X( JX ) = X( JX ) - CONJG( A( I, J ) )*X( IX )\n IX = IX + INCX\n 130 CONTINUE\n IF( NOUNIT )\n $ X( JX ) = X( JX )/CONJG( A( J, J ) )\n END IF\n JX = JX + INCX\n 140 CONTINUE\n END IF\n ELSE\n IF( INCX.EQ.1 )THEN\n DO 170, J = N, 1, -1\n IF( NOCONJ )THEN\n DO 150, I = N, J + 1, -1\n X( J ) = X( J ) - A( I, J )*X( I )\n 150 CONTINUE\n IF( NOUNIT )\n $ X( J ) = X( J )/A( J, J )\n ELSE\n DO 160, I = N, J + 1, -1\n X( J ) = X( J ) - CONJG( A( I, J ) )*X( I )\n 160 CONTINUE\n IF( NOUNIT )\n $ X( J ) = X( J )/CONJG( A( J, J ) )\n END IF\n 170 CONTINUE\n ELSE\n KX = KX + ( N - 1 )*INCX\n JX = KX\n DO 200, J = N, 1, -1\n IX = KX\n IF( NOCONJ )THEN\n DO 180, I = N, J + 1, -1\n X( JX ) = X( JX ) - A( I, J )*X( IX )\n IX = IX - INCX\n 180 CONTINUE\n IF( NOUNIT )\n $ X( JX ) = X( JX )/A( J, J )\n ELSE\n DO 190, I = N, J + 1, -1\n X( JX ) = X( JX ) - CONJG( A( I, J ) )*X( IX )\n IX = IX - INCX\n 190 CONTINUE\n IF( NOUNIT )\n $ X( JX ) = X( JX )/CONJG( A( J, J ) )\n END IF\n JX = JX - INCX\n 200 CONTINUE\n END IF\n END IF\n END IF\n*\n RETURN\n*\n* End of ECTRSV.\n*\n END\n*\n************************************************************************\n*\n SUBROUTINE ECTPMV( UPLO, TRANS, DIAG, N, AP, X, INCX )\n* .. Scalar Arguments ..\n INTEGER INCX, N\n CHARACTER*1 DIAG, TRANS, UPLO\n* .. Array Arguments ..\n COMPLEX*16 X( * )\n COMPLEX AP( * )\n* ..\n*\n* Purpose\n* =======\n*\n* ECTPMV performs one of the matrix-vector operations\n*\n* x := A*x, or x := A'*x, or x := conjg( A' )*x,\n*\n* where x is n element vector and A is an n by n unit, or non-unit,\n* upper or lower triangular matrix. Additional precision arithmetic is\n* used in the computation.\n*\n* Parameters\n* ==========\n*\n* UPLO - CHARACTER*1.\n* On entry, UPLO specifies whether the matrix is an upper or\n* lower triangular matrix as follows:\n*\n* UPLO = 'U' or 'u' A is an upper triangular matrix.\n*\n* UPLO = 'L' or 'l' A is a lower triangular matrix.\n*\n* Unchanged on exit.\n*\n* TRANS - CHARACTER*1.\n* On entry, TRANS specifies the operation to be performed as\n* follows:\n*\n* TRANS = 'N' or 'n' x := A*x.\n*\n* TRANS = 'T' or 't' x := A'*x.\n*\n* TRANS = 'C' or 'c' x := conjg( A' )*x.\n*\n* Unchanged on exit.\n*\n* DIAG - CHARACTER*1.\n* On entry, DIAG specifies whether or not A is unit\n* triangular as follows:\n*\n* DIAG = 'U' or 'u' A is assumed to be unit triangular.\n*\n* DIAG = 'N' or 'n' A is not assumed to be unit\n* triangular.\n*\n* Unchanged on exit.\n*\n* N - INTEGER.\n* On entry, N specifies the order of the matrix A.\n* N must be at least zero.\n* Unchanged on exit.\n*\n* AP - COMPLEX array of DIMENSION at least\n* ( ( n*( n + 1 ) )/2 ).\n* Before entry with UPLO = 'U' or 'u', the array AP must\n* contain the upper triangular matrix packed sequentially,\n* column by column, so that AP( 1 ) contains a( 1, 1 ),\n* AP( 2 ) and AP( 3 ) contain a( 1, 2 ) and a( 2, 2 )\n* respectively, and so on.\n* Before entry with UPLO = 'L' or 'l', the array AP must\n* contain the lower triangular matrix packed sequentially,\n* column by column, so that AP( 1 ) contains a( 1, 1 ),\n* AP( 2 ) and AP( 3 ) contain a( 2, 1 ) and a( 3, 1 )\n* respectively, and so on.\n* Note that when DIAG = 'U' or 'u', the diagonal elements of\n* A are not referenced, but are assumed to be unity.\n* Unchanged on exit.\n*\n* X - COMPLEX*16 array of dimension at least\n* ( 1 + ( n - 1 )*abs( INCX ) ).\n* Before entry, the incremented array X must contain the n\n* element vector x. On exit, X is overwritten with the\n* tranformed vector x. At least double precision arithmetic is\n* used in the computation of x.\n*\n* INCX - INTEGER.\n* On entry, INCX specifies the increment for the elements of\n* X. INCX must not be zero.\n* Unchanged on exit.\n*\n*\n* Level 2 Blas routine.\n*\n* -- Written on 20-July-1986.\n* Sven Hammarling, Nag Central Office.\n* Richard Hanson, Sandia National Labs.\n*\n*\n* .. Parameters ..\n COMPLEX*16 ZERO\n PARAMETER ( ZERO = ( 0.0D+0, 0.0D+0 ) )\n* .. Local Scalars ..\n INTEGER I, INFO, IX, J, JX, K, KK, KX\n LOGICAL NOCONJ, NOUNIT\n* .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\n* .. External Subroutines ..\n EXTERNAL XERBLA\n* .. Intrinsic Functions ..\n INTRINSIC CONJG\n* ..\n* .. Executable Statements ..\n*\n* Test the input parameters.\n*\n INFO = 0\n IF ( .NOT.LSAME( UPLO, 'U' ).AND.\n $ .NOT.LSAME( UPLO, 'L' ) ) THEN\n INFO = 1\n ELSE IF ( .NOT.LSAME( TRANS, 'N' ).AND.\n $ .NOT.LSAME( TRANS, 'T' ).AND.\n $ .NOT.LSAME( TRANS, 'C' ) ) THEN\n INFO = 2\n ELSE IF ( .NOT.LSAME( DIAG, 'U' ).AND.\n $ .NOT.LSAME( DIAG, 'N' ) ) THEN\n INFO = 3\n ELSE IF ( N.LT.0 ) THEN\n INFO = 4\n ELSE IF ( INCX.EQ.0 ) THEN\n INFO = 7\n END IF\n IF( INFO.NE.0 )THEN\n CALL XERBLA( 'ECTPMV', INFO )\n RETURN\n END IF\n*\n* Quick return if possible.\n*\n IF( N.EQ.0 )\n $ RETURN\n*\n NOCONJ = LSAME( TRANS, 'T' )\n NOUNIT = ( DIAG .EQ.'N' ).OR.( DIAG .EQ.'n' )\n*\n* Set up the start point in X if the increment is not unity. This\n* will be ( N - 1 )*INCX too small for descending loops.\n*\n IF( INCX.LE.0 )THEN\n KX = 1 - ( N - 1 )*INCX\n ELSE IF( INCX.NE.1 )THEN\n KX = 1\n END IF\n*\n* Start the operations. In this version the elements of AP are\n* accessed sequentially with one pass through AP.\n*\n IF( LSAME( TRANS, 'N' ) )THEN\n*\n* Form x:= A*x.\n*\n IF( LSAME( UPLO, 'U' ) )THEN\n K = 1\n IF( INCX.EQ.1 )THEN\n DO 20, J = 1, N\n IF( X( J ).NE.ZERO )THEN\n DO 10, I = 1, J - 1\n X( I ) = X( I ) + X( J )*AP( K )\n K = K + 1\n 10 CONTINUE\n IF( NOUNIT )\n $ X( J ) = X( J )*AP( K )\n K = K + 1\n ELSE\n K = K + J\n END IF\n 20 CONTINUE\n ELSE\n JX = KX\n DO 40, J = 1, N\n IF( X( JX ).NE.ZERO )THEN\n IX = KX\n KK = K\n DO 30, K = KK, KK + J - 2\n X( IX ) = X( IX ) + X( JX )*AP( K )\n IX = IX + INCX\n 30 CONTINUE\n IF( NOUNIT )\n $ X( JX ) = X( JX )*AP( K )\n K = K + 1\n ELSE\n K = K + J\n END IF\n JX = JX + INCX\n 40 CONTINUE\n END IF\n ELSE\n K = ( N*( N + 1 ) )/2\n IF( INCX.EQ.1 )THEN\n DO 60, J = N, 1, -1\n IF( X( J ).NE.ZERO )THEN\n DO 50, I = N, J + 1, -1\n X( I ) = X( I ) + X( J )*AP( K )\n K = K - 1\n 50 CONTINUE\n IF( NOUNIT )\n $ X( J ) = X( J )*AP( K )\n K = K - 1\n ELSE\n K = K - ( N - J + 1 )\n END IF\n 60 CONTINUE\n ELSE\n KX = KX + ( N - 1 )*INCX\n JX = KX\n DO 80, J = N, 1, -1\n IF( X( JX ).NE.ZERO )THEN\n IX = KX\n KK = K\n DO 70, K = KK, KK - ( N - ( J + 1 ) ), -1\n X( IX ) = X( IX ) + X( JX )*AP( K )\n IX = IX - INCX\n 70 CONTINUE\n IF( NOUNIT )\n $ X( JX ) = X( JX )*AP( K )\n K = K - 1\n ELSE\n K = K - ( N - J + 1 )\n END IF\n JX = JX - INCX\n 80 CONTINUE\n END IF\n END IF\n ELSE\n*\n* Form x := A'*x or x := conjg( A' )*x.\n*\n IF( LSAME( UPLO, 'U' ) )THEN\n K = ( N*( N + 1 ) )/2\n IF( INCX.EQ.1 )THEN\n DO 110, J = N, 1, -1\n IF( NOCONJ )THEN\n IF( NOUNIT )\n $ X( J ) = X( J )*AP( K )\n K = K - 1\n DO 90, I = J - 1, 1, -1\n X( J ) = X( J ) + AP( K )*X( I )\n K = K - 1\n 90 CONTINUE\n ELSE\n IF( NOUNIT )\n $ X( J ) = X( J )*CONJG( AP( K ) )\n K = K - 1\n DO 100, I = J - 1, 1, -1\n X( J ) = X( J ) + CONJG( AP( K ) )*X( I )\n K = K - 1\n 100 CONTINUE\n END IF\n 110 CONTINUE\n ELSE\n JX = KX + ( N - 1 )*INCX\n DO 140, J = N, 1, -1\n IX = JX\n IF( NOCONJ )THEN\n IF( NOUNIT )\n $ X( JX ) = X( JX )*AP( K )\n KK = K - 1\n DO 120, K = KK, KK - J + 2, -1\n IX = IX - INCX\n X( JX ) = X( JX ) + AP( K )*X( IX )\n 120 CONTINUE\n ELSE\n IF( NOUNIT )\n $ X( JX ) = X( JX )*CONJG( AP( K ) )\n KK = K - 1\n DO 130, K = KK, KK - J + 2, -1\n IX = IX - INCX\n X( JX ) = X( JX ) + CONJG( AP( K ) )*X( IX )\n 130 CONTINUE\n END IF\n JX = JX - INCX\n 140 CONTINUE\n END IF\n ELSE\n K = 1\n IF( INCX.EQ.1 )THEN\n DO 170, J = 1, N\n IF( NOCONJ )THEN\n IF( NOUNIT )\n $ X( J ) = X( J )*AP( K )\n K = K + 1\n DO 150, I = J + 1, N\n X( J ) = X( J ) + AP( K )*X( I )\n K = K + 1\n 150 CONTINUE\n ELSE\n IF( NOUNIT )\n $ X( J ) = X( J )*CONJG( AP( K ) )\n K = K + 1\n DO 160, I = J + 1, N\n X( J ) = X( J ) + CONJG( AP( K ) )*X( I )\n K = K + 1\n 160 CONTINUE\n END IF\n 170 CONTINUE\n ELSE\n JX = KX\n DO 200, J = 1, N\n IX = JX\n IF( NOCONJ )THEN\n IF( NOUNIT )\n $ X( JX ) = X( JX )*AP( K )\n KK = K + 1\n DO 180, K = KK, KK + N - ( J + 1 )\n IX = IX + INCX\n X( JX ) = X( JX ) + AP( K )*X( IX )\n 180 CONTINUE\n ELSE\n IF( NOUNIT )\n $ X( JX ) = X( JX )*CONJG( AP( K ) )\n KK = K + 1\n DO 190, K = KK, KK + N - ( J + 1 )\n IX = IX + INCX\n X( JX ) = X( JX ) + CONJG( AP( K ) )*X( IX )\n 190 CONTINUE\n END IF\n JX = JX + INCX\n 200 CONTINUE\n END IF\n END IF\n END IF\n*\n RETURN\n*\n* End of ECTPMV.\n*\n END\n*\n************************************************************************\n*\n SUBROUTINE ECTPSV( UPLO, TRANS, DIAG, N, AP, X, INCX )\n* .. Scalar Arguments ..\n INTEGER INCX, N\n CHARACTER*1 DIAG, TRANS, UPLO\n* .. Array Arguments ..\n COMPLEX*16 X( * )\n COMPLEX AP( * )\n* ..\n*\n* Purpose\n* =======\n*\n* ECTPSV solves one of the systems of equations\n*\n* A*x = b, or A'*x = b, or conjg( A' )*x = b,\n*\n* where b and x are n element vectors and A is an n by n unit, or\n* non-unit, upper or lower triangular matrix. Additional precision\n* arithmetic is used in the computation.\n*\n* No test for singularity or near-singularity is included in this\n* routine. Such tests must be performed before calling this routine.\n*\n* Parameters\n* ==========\n*\n* UPLO - CHARACTER*1.\n* On entry, UPLO specifies whether the matrix is an upper or\n* lower triangular matrix as follows:\n*\n* UPLO = 'U' or 'u' A is an upper triangular matrix.\n*\n* UPLO = 'L' or 'l' A is a lower triangular matrix.\n*\n* Unchanged on exit.\n*\n* TRANS - CHARACTER*1.\n* On entry, TRANS specifies the equations to be solved as\n* follows:\n*\n* TRANS = 'N' or 'n' A*x = b.\n*\n* TRANS = 'T' or 't' A'*x = b.\n*\n* TRANS = 'C' or 'c' conjg( A' )*x = b.\n*\n* Unchanged on exit.\n*\n* DIAG - CHARACTER*1.\n* On entry, DIAG specifies whether or not A is unit\n* triangular as follows:\n*\n* DIAG = 'U' or 'u' A is assumed to be unit triangular.\n*\n* DIAG = 'N' or 'n' A is not assumed to be unit\n* triangular.\n*\n* Unchanged on exit.\n*\n* N - INTEGER.\n* On entry, N specifies the order of the matrix A.\n* N must be at least zero.\n* Unchanged on exit.\n*\n* AP - COMPLEX array of DIMENSION at least\n* ( ( n*( n + 1 ) )/2 ).\n* Before entry with UPLO = 'U' or 'u', the array AP must\n* contain the upper triangular matrix packed sequentially,\n* column by column, so that AP( 1 ) contains a( 1, 1 ),\n* AP( 2 ) and AP( 3 ) contain a( 1, 2 ) and a( 2, 2 )\n* respectively, and so on.\n* Before entry with UPLO = 'L' or 'l', the array AP must\n* contain the lower triangular matrix packed sequentially,\n* column by column, so that AP( 1 ) contains a( 1, 1 ),\n* AP( 2 ) and AP( 3 ) contain a( 2, 1 ) and a( 3, 1 )\n* respectively, and so on.\n* Note that when DIAG = 'U' or 'u', the diagonal elements of\n* A are not referenced, but are assumed to be unity.\n* Unchanged on exit.\n*\n* X - COMPLEX*16 array of dimension at least\n* ( 1 + ( n - 1 )*abs( INCX ) ).\n* Before entry, the incremented array X must contain the n\n* element right-hand side vector b. On exit, X is overwritten\n* with the solution vector x. At least double precision\n* arithemtic is used in the computation of x.\n*\n* INCX - INTEGER.\n* On entry, INCX specifies the increment for the elements of\n* X. INCX must not be zero.\n* Unchanged on exit.\n*\n*\n* Level 2 Blas routine.\n*\n* -- Written on 20-July-1986.\n* Sven Hammarling, Nag Central Office.\n* Richard Hanson, Sandia National Labs.\n*\n*\n* .. Parameters ..\n COMPLEX*16 ZERO\n PARAMETER ( ZERO = ( 0.0D+0, 0.0D+0 ) )\n* .. Local Scalars ..\n INTEGER I, INFO, IX, J, JX, K, KK, KX\n LOGICAL NOCONJ, NOUNIT\n* .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\n* .. External Subroutines ..\n EXTERNAL XERBLA\n* .. Intrinsic Functions ..\n INTRINSIC CONJG\n* ..\n* .. Executable Statements ..\n*\n* Test the input parameters.\n*\n INFO = 0\n IF ( .NOT.LSAME( UPLO, 'U' ).AND.\n $ .NOT.LSAME( UPLO, 'L' ) ) THEN\n INFO = 1\n ELSE IF ( .NOT.LSAME( TRANS, 'N' ).AND.\n $ .NOT.LSAME( TRANS, 'T' ).AND.\n $ .NOT.LSAME( TRANS, 'C' ) ) THEN\n INFO = 2\n ELSE IF ( .NOT.LSAME( DIAG, 'U' ).AND.\n $ .NOT.LSAME( DIAG, 'N' ) ) THEN\n INFO = 3\n ELSE IF ( N.LT.0 ) THEN\n INFO = 4\n ELSE IF ( INCX.EQ.0 ) THEN\n INFO = 7\n END IF\n IF( INFO.NE.0 )THEN\n CALL XERBLA( 'ECTPSV', INFO )\n RETURN\n END IF\n*\n* Quick return if possible.\n*\n IF( N.EQ.0 )\n $ RETURN\n*\n NOCONJ = LSAME( TRANS, 'T' )\n NOUNIT = ( DIAG .EQ.'N' ).OR.( DIAG .EQ.'n' )\n*\n* Set up the start point in X if the increment is not unity. This\n* will be ( N - 1 )*INCX too small for descending loops.\n*\n IF( INCX.LE.0 )THEN\n KX = 1 - ( N - 1 )*INCX\n ELSE IF( INCX.NE.1 )THEN\n KX = 1\n END IF\n*\n* Start the operations. In this version the elements of AP are\n* accessed sequentially with one pass through AP.\n*\n IF( LSAME( TRANS, 'N' ) )THEN\n*\n* Form x := inv( A )*x.\n*\n IF( LSAME( UPLO, 'U' ) )THEN\n K = ( N*( N + 1 ) )/2\n IF( INCX.EQ.1 )THEN\n DO 20, J = N, 1, -1\n IF( X( J ).NE.ZERO )THEN\n IF( NOUNIT )\n $ X( J ) = X( J )/AP( K )\n K = K - 1\n DO 10, I = J - 1, 1, -1\n X( I ) = X( I ) - X( J )*AP( K )\n K = K - 1\n 10 CONTINUE\n ELSE\n K = K - J\n END IF\n 20 CONTINUE\n ELSE\n JX = KX + ( N - 1 )*INCX\n DO 40, J = N, 1, -1\n IF( X( JX ).NE.ZERO )THEN\n IF( NOUNIT )\n $ X( JX ) = X( JX )/AP( K )\n IX = JX\n KK = K - 1\n DO 30, K = KK, KK - J + 2, -1\n IX = IX - INCX\n X( IX ) = X( IX ) - X( JX )*AP( K )\n 30 CONTINUE\n ELSE\n K = K - J\n END IF\n JX = JX - INCX\n 40 CONTINUE\n END IF\n ELSE\n K = 1\n IF( INCX.EQ.1 )THEN\n DO 60, J = 1, N\n IF( X( J ).NE.ZERO )THEN\n IF( NOUNIT )\n $ X( J ) = X( J )/AP( K )\n K = K + 1\n DO 50, I = J + 1, N\n X( I ) = X( I ) - X( J )*AP( K )\n K = K + 1\n 50 CONTINUE\n ELSE\n K = K + N - J + 1\n END IF\n 60 CONTINUE\n ELSE\n JX = KX\n DO 80, J = 1, N\n IF( X( JX ).NE.ZERO )THEN\n IF( NOUNIT )\n $ X( JX ) = X( JX )/AP( K )\n IX = JX\n KK = K + 1\n DO 70, K = KK, KK + N - ( J + 1 )\n IX = IX + INCX\n X( IX ) = X( IX ) - X( JX )*AP( K )\n 70 CONTINUE\n ELSE\n K = K + N - J + 1\n END IF\n JX = JX + INCX\n 80 CONTINUE\n END IF\n END IF\n ELSE\n*\n* Form x := inv( A' )*x or x := inv( conjg( A' ) )*x.\n*\n IF( LSAME( UPLO, 'U' ) )THEN\n K = 1\n IF( INCX.EQ.1 )THEN\n DO 110, J = 1, N\n IF( NOCONJ )THEN\n DO 90, I = 1, J - 1\n X( J ) = X( J ) - AP( K )*X( I )\n K = K + 1\n 90 CONTINUE\n IF( NOUNIT )\n $ X( J ) = X( J )/AP( K )\n ELSE\n DO 100, I = 1, J - 1\n X( J ) = X( J ) - CONJG( AP( K ) )*X( I )\n K = K + 1\n 100 CONTINUE\n IF( NOUNIT )\n $ X( J ) = X( J )/CONJG( AP( K ) )\n END IF\n K = K + 1\n 110 CONTINUE\n ELSE\n JX = KX\n DO 140, J = 1, N\n IX = KX\n KK = K\n IF( NOCONJ )THEN\n DO 120, K = KK, KK + J - 2\n X( JX ) = X( JX ) - AP( K )*X( IX )\n IX = IX + INCX\n 120 CONTINUE\n IF( NOUNIT )\n $ X( JX ) = X( JX )/AP( K )\n ELSE\n DO 130, K = KK, KK + J - 2\n X( JX ) = X( JX ) - CONJG( AP( K ) )*X( IX )\n IX = IX + INCX\n 130 CONTINUE\n IF( NOUNIT )\n $ X( JX ) = X( JX )/CONJG( AP( K ) )\n END IF\n K = K + 1\n JX = JX + INCX\n 140 CONTINUE\n END IF\n ELSE\n K = ( N*( N + 1 ) )/2\n IF( INCX.EQ.1 )THEN\n DO 170, J = N, 1, -1\n IF( NOCONJ )THEN\n DO 150, I = N, J + 1, -1\n X( J ) = X( J ) - AP( K )*X( I )\n K = K - 1\n 150 CONTINUE\n IF( NOUNIT )\n $ X( J ) = X( J )/AP( K )\n ELSE\n DO 160, I = N, J + 1, -1\n X( J ) = X( J ) - CONJG( AP( K ) )*X( I )\n K = K - 1\n 160 CONTINUE\n IF( NOUNIT )\n $ X( J ) = X( J )/CONJG( AP( K ) )\n END IF\n K = K - 1\n 170 CONTINUE\n ELSE\n KX = KX + ( N - 1 )*INCX\n JX = KX\n DO 200, J = N, 1, -1\n IX = KX\n KK = K\n IF( NOCONJ )THEN\n DO 180, K = KK, KK - ( N - ( J + 1 ) ), -1\n X( JX ) = X( JX ) - AP( K )*X( IX )\n IX = IX - INCX\n 180 CONTINUE\n IF( NOUNIT )\n $ X( JX ) = X( JX )/AP( K )\n ELSE\n DO 190, K = KK, KK - ( N - ( J + 1 ) ), -1\n X( JX ) = X( JX ) - CONJG( AP( K ) )*X( IX )\n IX = IX - INCX\n 190 CONTINUE\n IF( NOUNIT )\n $ X( JX ) = X( JX )/CONJG( AP( K ) )\n END IF\n K = K - 1\n JX = JX - INCX\n 200 CONTINUE\n END IF\n END IF\n END IF\n*\n RETURN\n*\n* End of ECTPSV.\n*\n END\n*\n************************************************************************\n*\n SUBROUTINE ECTBMV( UPLO, TRANS, DIAG, N, K, A, LDA, X, INCX )\n* .. Scalar Arguments ..\n INTEGER INCX, K, LDA, N\n CHARACTER*1 DIAG, TRANS, UPLO\n* .. Array Arguments ..\n COMPLEX*16 X( * )\n COMPLEX A( LDA, * )\n* ..\n*\n* Purpose\n* =======\n*\n* ECTBMV performs one of the matrix-vector operations\n*\n* x := A*x, or x := A'*x, or x := conjg( A' )*x,\n*\n* where x is n element vector and A is an n by n unit, or non-unit,\n* upper or lower triangular band matrix, with ( k + 1 ) diagonals.\n* Additional precision arithmetic is used in the computation.\n*\n* Parameters\n* ==========\n*\n* UPLO - CHARACTER*1.\n* On entry, UPLO specifies whether the matrix is an upper or\n* lower triangular matrix as follows:\n*\n* UPLO = 'U' or 'u' A is an upper triangular matrix.\n*\n* UPLO = 'L' or 'l' A is a lower triangular matrix.\n*\n* Unchanged on exit.\n*\n* TRANS - CHARACTER*1.\n* On entry, TRANS specifies the operation to be performed as\n* follows:\n*\n* TRANS = 'N' or 'n' x := A*x.\n*\n* TRANS = 'T' or 't' x := A'*x.\n*\n* TRANS = 'C' or 'c' x := conjg( A' )*x.\n*\n* Unchanged on exit.\n*\n* DIAG - CHARACTER*1.\n* On entry, DIAG specifies whether or not A is unit\n* triangular as follows:\n*\n* DIAG = 'U' or 'u' A is assumed to be unit triangular.\n*\n* DIAG = 'N' or 'n' A is not assumed to be unit\n* triangular.\n*\n* Unchanged on exit.\n*\n* N - INTEGER.\n* On entry, N specifies the order of the matrix A.\n* N must be at least zero.\n* Unchanged on exit.\n*\n* K - INTEGER.\n* On entry with UPLO = 'U' or 'u', K specifies the number of\n* super-diagonals of the matrix A.\n* On entry with UPLO = 'L' or 'l', K specifies the number of\n* sub-diagonals of the matrix A.\n* K must satisfy 0 .le. K.\n* Unchanged on exit.\n*\n* A - COMPLEX array of DIMENSION ( LDA, n ).\n* Before entry with UPLO = 'U' or 'u', the leading ( k + 1 )\n* by n part of the array A must contain the upper triangular\n* band part of the matrix of coefficients, supplied column by\n* column, with the leading diagonal of the matrix in row\n* ( k + 1 ) of the array, the first super-diagonal starting at\n* position 2 in row k, and so on. The top left k by k triangle\n* of the array A is not referenced.\n* The following program segment will transfer an upper\n* triangular band matrix from conventional full matrix storage\n* to band storage:\n*\n* DO 20, J = 1, N\n* M = K + 1 - J\n* DO 10, I = MAX( 1, J - K ), J\n* A( M + I, J ) = matrix( I, J )\n* 10 CONTINUE\n* 20 CONTINUE\n*\n* Before entry with UPLO = 'L' or 'l', the leading ( k + 1 )\n* by n part of the array A must contain the lower triangular\n* band part of the matrix of coefficients, supplied column by\n* column, with the leading diagonal of the matrix in row 1 of\n* the array, the first sub-diagonal starting at position 1 in\n* row 2, and so on. The bottom right k by k triangle of the\n* array A is not referenced.\n* The following program segment will transfer a lower\n* triangular band matrix from conventional full matrix storage\n* to band storage:\n*\n* DO 20, J = 1, N\n* M = 1 - J\n* DO 10, I = J, MIN( N, J + K )\n* A( M + I, J ) = matrix( I, J )\n* 10 CONTINUE\n* 20 CONTINUE\n*\n* Note that when DIAG = 'U' or 'u' the elements of the array A\n* corresponding to the diagonal elements of the matrix are not\n* referenced, but are assumed to be unity.\n* Unchanged on exit.\n*\n* LDA - INTEGER.\n* On entry, LDA specifies the first dimension of A as declared\n* in the calling (sub) program. LDA must be at least\n* ( k + 1 ).\n* Unchanged on exit.\n*\n* X - COMPLEX*16 array of dimension at least\n* ( 1 + ( n - 1 )*abs( INCX ) ).\n* Before entry, the incremented array X must contain the n\n* element vector x. On exit, X is overwritten with the\n* tranformed vector x. At least double precision arithmetic is\n* used in the computation of x.\n*\n* INCX - INTEGER.\n* On entry, INCX specifies the increment for the elements of\n* X. INCX must not be zero.\n* Unchanged on exit.\n*\n*\n*\n* Level 2 Blas routine.\n*\n* -- Written on 20-July-1986.\n* Sven Hammarling, Nag Central Office.\n* Richard Hanson, Sandia National Labs.\n*\n*\n* .. Parameters ..\n COMPLEX*16 ZERO\n PARAMETER ( ZERO = ( 0.0D+0, 0.0D+0 ) )\n* .. Local Scalars ..\n INTEGER I, INFO, IX, J, JX, KPLUS1, KX, L\n LOGICAL NOCONJ, NOUNIT\n* .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\n* .. External Subroutines ..\n EXTERNAL XERBLA\n* .. Intrinsic Functions ..\n INTRINSIC MAX, MIN, CONJG\n* ..\n* .. Executable Statements ..\n*\n* Test the input parameters.\n*\n INFO = 0\n IF ( .NOT.LSAME( UPLO, 'U' ).AND.\n $ .NOT.LSAME( UPLO, 'L' ) ) THEN\n INFO = 1\n ELSE IF ( .NOT.LSAME( TRANS, 'N' ).AND.\n $ .NOT.LSAME( TRANS, 'T' ).AND.\n $ .NOT.LSAME( TRANS, 'C' ) ) THEN\n INFO = 2\n ELSE IF ( .NOT.LSAME( DIAG, 'U' ).AND.\n $ .NOT.LSAME( DIAG, 'N' ) ) THEN\n INFO = 3\n ELSE IF ( N.LT.0 ) THEN\n INFO = 4\n ELSE IF ( K.LT.0 ) THEN\n INFO = 5\n ELSE IF ( LDA.LT.( K + 1 ) ) THEN\n INFO = 7\n ELSE IF ( INCX.EQ.0 ) THEN\n INFO = 9\n END IF\n IF( INFO.NE.0 )THEN\n CALL XERBLA( 'ECTBMV', INFO )\n RETURN\n END IF\n*\n* Quick return if possible.\n*\n IF( N.EQ.0 )\n $ RETURN\n*\n NOCONJ = LSAME( TRANS, 'T' )\n NOUNIT = ( DIAG .EQ.'N' ).OR.( DIAG .EQ.'n' )\n*\n* Set up the start point in X if the increment is not unity. This\n* will be ( N - 1 )*INCX too small for descending loops.\n*\n IF( INCX.LE.0 )THEN\n KX = 1 - ( N - 1 )*INCX\n ELSE IF( INCX.NE.1 )THEN\n KX = 1\n END IF\n*\n* Start the operations. In this version the elements of A are\n* accessed sequentially with one pass through A.\n*\n IF( LSAME( TRANS, 'N' ) )THEN\n*\n* Form x := A*x.\n*\n IF( LSAME( UPLO, 'U' ) )THEN\n KPLUS1 = K + 1\n IF( INCX.EQ.1 )THEN\n DO 20, J = 1, N\n IF( X( J ).NE.ZERO )THEN\n L = KPLUS1 - J\n DO 10, I = MAX( 1, J - K ), J - 1\n X( I ) = X( I ) + X( J )*A( L + I, J )\n 10 CONTINUE\n IF( NOUNIT )\n $ X( J ) = X( J )*A( KPLUS1, J )\n END IF\n 20 CONTINUE\n ELSE\n JX = KX\n DO 40, J = 1, N\n IF( X( JX ).NE.ZERO )THEN\n IX = KX\n L = KPLUS1 - J\n DO 30, I = MAX( 1, J - K ), J - 1\n X( IX ) = X( IX ) + X( JX )*A( L + I, J )\n IX = IX + INCX\n 30 CONTINUE\n IF( NOUNIT )\n $ X( JX ) = X( JX )*A( KPLUS1, J )\n END IF\n JX = JX + INCX\n IF( J.GT.K )\n $ KX = KX + INCX\n 40 CONTINUE\n END IF\n ELSE\n IF( INCX.EQ.1 )THEN\n DO 60, J = N, 1, -1\n IF( X( J ).NE.ZERO )THEN\n L = 1 - J\n DO 50, I = MIN( N, J + K ), J + 1, -1\n X( I ) = X( I ) + X( J )*A( L + I, J )\n 50 CONTINUE\n IF( NOUNIT )\n $ X( J ) = X( J )*A( 1, J )\n END IF\n 60 CONTINUE\n ELSE\n KX = KX + ( N - 1 )*INCX\n JX = KX\n DO 80, J = N, 1, -1\n IF( X( JX ).NE.ZERO )THEN\n IX = KX\n L = 1 - J\n DO 70, I = MIN( N, J + K ), J + 1, -1\n X( IX ) = X( IX ) + X( JX )*A( L + I, J )\n IX = IX - INCX\n 70 CONTINUE\n IF( NOUNIT )\n $ X( JX ) = X( JX )*A( 1, J )\n END IF\n JX = JX - INCX\n IF( ( N - J ).GE.K )\n $ KX = KX - INCX\n 80 CONTINUE\n END IF\n END IF\n ELSE\n*\n* Form x := A'*x or x := conjg( A' )*x.\n*\n IF( LSAME( UPLO, 'U' ) )THEN\n KPLUS1 = K + 1\n IF( INCX.EQ.1 )THEN\n DO 110, J = N, 1, -1\n L = KPLUS1 - J\n IF( NOCONJ )THEN\n IF( NOUNIT )\n $ X( J ) = X( J )*A( KPLUS1, J )\n DO 90, I = J - 1, MAX( 1, J - K ), -1\n X( J ) = X( J ) + A( L + I, J )*X( I )\n 90 CONTINUE\n ELSE\n IF( NOUNIT )\n $ X( J ) = X( J )*CONJG( A( KPLUS1, J ) )\n DO 100, I = J - 1, MAX( 1, J - K ), -1\n X( J ) = X( J ) + CONJG( A( L + I, J ) )*X( I )\n 100 CONTINUE\n END IF\n 110 CONTINUE\n ELSE\n KX = KX + ( N - 1 )*INCX\n JX = KX\n DO 140, J = N, 1, -1\n KX = KX - INCX\n IX = KX\n L = KPLUS1 - J\n IF( NOCONJ )THEN\n IF( NOUNIT )\n $ X( JX ) = X( JX )*A( KPLUS1, J )\n DO 120, I = J - 1, MAX( 1, J - K ), -1\n X( JX ) = X( JX ) + A( L + I, J )*X( IX )\n IX = IX - INCX\n 120 CONTINUE\n ELSE\n IF( NOUNIT )\n $ X( JX ) = X( JX )*CONJG( A( KPLUS1, J ) )\n DO 130, I = J - 1, MAX( 1, J - K ), -1\n X( JX ) = X( JX ) +\n $ CONJG( A( L + I, J ) )*X( IX )\n IX = IX - INCX\n 130 CONTINUE\n END IF\n JX = JX - INCX\n 140 CONTINUE\n END IF\n ELSE\n IF( INCX.EQ.1 )THEN\n DO 170, J = 1, N\n L = 1 - J\n IF( NOCONJ )THEN\n IF( NOUNIT )\n $ X( J ) = X( J )*A( 1, J )\n DO 150, I = J + 1, MIN( N, J + K )\n X( J ) = X( J ) + A( L + I, J )*X( I )\n 150 CONTINUE\n ELSE\n IF( NOUNIT )\n $ X( J ) = X( J )*CONJG( A( 1, J ) )\n DO 160, I = J + 1, MIN( N, J + K )\n X( J ) = X( J ) + CONJG( A( L + I, J ) )*X( I )\n 160 CONTINUE\n END IF\n 170 CONTINUE\n ELSE\n JX = KX\n DO 200, J = 1, N\n KX = KX + INCX\n IX = KX\n L = 1 - J\n IF( NOCONJ )THEN\n IF( NOUNIT )\n $ X( JX ) = X( JX )*A( 1, J )\n DO 180, I = J + 1, MIN( N, J + K )\n X( JX ) = X( JX ) + A( L + I, J )*X( IX )\n IX = IX + INCX\n 180 CONTINUE\n ELSE\n IF( NOUNIT )\n $ X( JX ) = X( JX )*CONJG( A( 1, J ) )\n DO 190, I = J + 1, MIN( N, J + K )\n X( JX ) = X( JX ) +\n $ CONJG( A( L + I, J ) )*X( IX )\n IX = IX + INCX\n 190 CONTINUE\n END IF\n JX = JX + INCX\n 200 CONTINUE\n END IF\n END IF\n END IF\n*\n RETURN\n*\n* End of ECTBMV.\n*\n END\n*\n************************************************************************\n*\n SUBROUTINE ECTBSV( UPLO, TRANS, DIAG, N, K, A, LDA, X, INCX )\n* .. Scalar Arguments ..\n INTEGER INCX, K, LDA, N\n CHARACTER*1 DIAG, TRANS, UPLO\n* .. Array Arguments ..\n COMPLEX*16 X( * )\n COMPLEX A( LDA, * )\n* ..\n*\n* Purpose\n* =======\n*\n* ECTBSV solves one of the systems of equations\n*\n* A*x = b, or A'*x = b, or conjg( A' )*x = b,\n*\n* where b and x are n element vectors and A is an n by n unit, or\n* non-unit, upper or lower triangular band matrix, with ( k + 1 )\n* diagonals. Additional precision arithmetic is used in the\n* computation.\n*\n* No test for singularity or near-singularity is included in this\n* routine. Such tests must be performed before calling this routine.\n*\n* Parameters\n* ==========\n*\n* UPLO - CHARACTER*1.\n* On entry, UPLO specifies whether the matrix is an upper or\n* lower triangular matrix as follows:\n*\n* UPLO = 'U' or 'u' A is an upper triangular matrix.\n*\n* UPLO = 'L' or 'l' A is a lower triangular matrix.\n*\n* Unchanged on exit.\n*\n* TRANS - CHARACTER*1.\n* On entry, TRANS specifies the equations to be solved as\n* follows:\n*\n* TRANS = 'N' or 'n' A*x = b.\n*\n* TRANS = 'T' or 't' A'*x = b.\n*\n* TRANS = 'C' or 'c' conjg( A' )*x = b.\n*\n* Unchanged on exit.\n*\n* DIAG - CHARACTER*1.\n* On entry, DIAG specifies whether or not A is unit\n* triangular as follows:\n*\n* DIAG = 'U' or 'u' A is assumed to be unit triangular.\n*\n* DIAG = 'N' or 'n' A is not assumed to be unit\n* triangular.\n*\n* Unchanged on exit.\n*\n* N - INTEGER.\n* On entry, N specifies the order of the matrix A.\n* N must be at least zero.\n* Unchanged on exit.\n*\n* K - INTEGER.\n* On entry with UPLO = 'U' or 'u', K specifies the number of\n* super-diagonals of the matrix A.\n* On entry with UPLO = 'L' or 'l', K specifies the number of\n* sub-diagonals of the matrix A.\n* K must satisfy 0 .le. K.\n* Unchanged on exit.\n*\n* A - COMPLEX array of DIMENSION ( LDA, n ).\n* Before entry with UPLO = 'U' or 'u', the leading ( k + 1 )\n* by n part of the array A must contain the upper triangular\n* band part of the matrix of coefficients, supplied column by\n* column, with the leading diagonal of the matrix in row\n* ( k + 1 ) of the array, the first super-diagonal starting at\n* position 2 in row k, and so on. The top left k by k triangle\n* of the array A is not referenced.\n* The following program segment will transfer an upper\n* triangular band matrix from conventional full matrix storage\n* to band storage:\n*\n* DO 20, J = 1, N\n* M = K + 1 - J\n* DO 10, I = MAX( 1, J - K ), J\n* A( M + I, J ) = matrix( I, J )\n* 10 CONTINUE\n* 20 CONTINUE\n*\n* Before entry with UPLO = 'L' or 'l', the leading ( k + 1 )\n* by n part of the array A must contain the lower triangular\n* band part of the matrix of coefficients, supplied column by\n* column, with the leading diagonal of the matrix in row 1 of\n* the array, the first sub-diagonal starting at position 1 in\n* row 2, and so on. The bottom right k by k triangle of the\n* array A is not referenced.\n* The following program segment will transfer a lower\n* triangular band matrix from conventional full matrix storage\n* to band storage:\n*\n* DO 20, J = 1, N\n* M = 1 - J\n* DO 10, I = J, MIN( N, J + K )\n* A( M + I, J ) = matrix( I, J )\n* 10 CONTINUE\n* 20 CONTINUE\n*\n* Note that when DIAG = 'U' or 'u' the elements of the array A\n* corresponding to the diagonal elements of the matrix are not\n* referenced, but are assumed to be unity.\n* Unchanged on exit.\n*\n* LDA - INTEGER.\n* On entry, LDA specifies the first dimension of A as declared\n* in the calling (sub) program. LDA must be at least\n* ( k + 1 ).\n* Unchanged on exit.\n*\n* X - COMPLEX*16 array of dimension at least\n* ( 1 + ( n - 1 )*abs( INCX ) ).\n* Before entry, the incremented array X must contain the n\n* element right-hand side vector b. On exit, X is overwritten\n* with the solution vector x. At least double precision\n* arithmetic is used in the computation of x.\n*\n* INCX - INTEGER.\n* On entry, INCX specifies the increment for the elements of\n* X. INCX must not be zero.\n* Unchanged on exit.\n*\n*\n* Level 2 Blas routine.\n*\n* -- Written on 20-July-1986.\n* Sven Hammarling, Nag Central Office.\n* Richard Hanson, Sandia National Labs.\n*\n*\n* .. Parameters ..\n COMPLEX*16 ZERO\n PARAMETER ( ZERO = ( 0.0D+0, 0.0D+0 ) )\n* .. Local Scalars ..\n INTEGER I, INFO, IX, J, JX, KPLUS1, KX, L\n LOGICAL NOCONJ, NOUNIT\n* .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\n* .. External Subroutines ..\n EXTERNAL XERBLA\n* .. Intrinsic Functions ..\n INTRINSIC MAX, MIN, CONJG\n* ..\n* .. Executable Statements ..\n*\n* Test the input parameters.\n*\n INFO = 0\n IF ( .NOT.LSAME( UPLO, 'U' ).AND.\n $ .NOT.LSAME( UPLO, 'L' ) ) THEN\n INFO = 1\n ELSE IF ( .NOT.LSAME( TRANS, 'N' ).AND.\n $ .NOT.LSAME( TRANS, 'T' ).AND.\n $ .NOT.LSAME( TRANS, 'C' ) ) THEN\n INFO = 2\n ELSE IF ( .NOT.LSAME( DIAG, 'U' ).AND.\n $ .NOT.LSAME( DIAG, 'N' ) ) THEN\n INFO = 3\n ELSE IF ( N.LT.0 ) THEN\n INFO = 4\n ELSE IF ( K.LT.0 ) THEN\n INFO = 5\n ELSE IF ( LDA.LT.( K + 1 ) ) THEN\n INFO = 7\n ELSE IF ( INCX.EQ.0 ) THEN\n INFO = 9\n END IF\n IF( INFO.NE.0 )THEN\n CALL XERBLA( 'ECTBSV', INFO )\n RETURN\n END IF\n*\n* Quick return if possible.\n*\n IF( N.EQ.0 )\n $ RETURN\n*\n NOCONJ = LSAME( TRANS, 'T' )\n NOUNIT = ( DIAG .EQ.'N' ).OR.( DIAG .EQ.'n' )\n*\n* Set up the start point in X if the increment is not unity. This\n* will be ( N - 1 )*INCX too small for descending loops.\n*\n IF( INCX.LE.0 )THEN\n KX = 1 - ( N - 1 )*INCX\n ELSE IF( INCX.NE.1 )THEN\n KX = 1\n END IF\n*\n* Start the operations. In this version the elements of A are\n* accessed by sequentially with one pass through A.\n*\n IF( LSAME( TRANS, 'N' ) )THEN\n*\n* Form x := inv( A )*x.\n*\n IF( LSAME( UPLO, 'U' ) )THEN\n KPLUS1 = K + 1\n IF( INCX.EQ.1 )THEN\n DO 20, J = N, 1, -1\n IF( X( J ).NE.ZERO )THEN\n L = KPLUS1 - J\n IF( NOUNIT )\n $ X( J ) = X( J )/A( KPLUS1, J )\n DO 10, I = J - 1, MAX( 1, J - K ), -1\n X( I ) = X( I ) - X( J )*A( L + I, J )\n 10 CONTINUE\n END IF\n 20 CONTINUE\n ELSE\n KX = KX + ( N - 1 )*INCX\n JX = KX\n DO 40, J = N, 1, -1\n KX = KX - INCX\n IF( X( JX ).NE.ZERO )THEN\n IX = KX\n L = KPLUS1 - J\n IF( NOUNIT )\n $ X( JX ) = X( JX )/A( KPLUS1, J )\n DO 30, I = J - 1, MAX( 1, J - K ), -1\n X( IX ) = X( IX ) - X( JX )*A( L + I, J )\n IX = IX - INCX\n 30 CONTINUE\n END IF\n JX = JX - INCX\n 40 CONTINUE\n END IF\n ELSE\n IF( INCX.EQ.1 )THEN\n DO 60, J = 1, N\n IF( X( J ).NE.ZERO )THEN\n L = 1 - J\n IF( NOUNIT )\n $ X( J ) = X( J )/A( 1, J )\n DO 50, I = J + 1, MIN( N, J + K )\n X( I ) = X( I ) - X( J )*A( L + I, J )\n 50 CONTINUE\n END IF\n 60 CONTINUE\n ELSE\n JX = KX\n DO 80, J = 1, N\n KX = KX + INCX\n IF( X( JX ).NE.ZERO )THEN\n IX = KX\n L = 1 - J\n IF( NOUNIT )\n $ X( JX ) = X( JX )/A( 1, J )\n DO 70, I = J + 1, MIN( N, J + K )\n X( IX ) = X( IX ) - X( JX )*A( L + I, J )\n IX = IX + INCX\n 70 CONTINUE\n END IF\n JX = JX + INCX\n 80 CONTINUE\n END IF\n END IF\n ELSE\n*\n* Form x := inv( A' )*x or x := inv( conjg( A') )*x.\n*\n IF( LSAME( UPLO, 'U' ) )THEN\n KPLUS1 = K + 1\n IF( INCX.EQ.1 )THEN\n DO 110, J = 1, N\n L = KPLUS1 - J\n IF( NOCONJ )THEN\n DO 90, I = MAX( 1, J - K ), J - 1\n X( J ) = X( J ) - A( L + I, J )*X( I )\n 90 CONTINUE\n IF( NOUNIT )\n $ X( J ) = X( J )/A( KPLUS1, J )\n ELSE\n DO 100, I = MAX( 1, J - K ), J - 1\n X( J ) = X( J ) - CONJG( A( L + I, J ) )*X( I )\n 100 CONTINUE\n IF( NOUNIT )\n $ X( J ) = X( J )/CONJG( A( KPLUS1, J ) )\n END IF\n 110 CONTINUE\n ELSE\n JX = KX\n DO 140, J = 1, N\n IX = KX\n L = KPLUS1 - J\n IF( NOCONJ )THEN\n DO 120, I = MAX( 1, J - K ), J - 1\n X( JX ) = X( JX ) - A( L + I, J )*X( IX )\n IX = IX + INCX\n 120 CONTINUE\n IF( NOUNIT )\n $ X( JX ) = X( JX )/A( KPLUS1, J )\n ELSE\n DO 130, I = MAX( 1, J - K ), J - 1\n X( JX ) = X( JX ) -\n $ CONJG( A( L + I, J ) )*X( IX )\n IX = IX + INCX\n 130 CONTINUE\n IF( NOUNIT )\n $ X( JX ) = X( JX )/CONJG( A( KPLUS1, J ) )\n END IF\n JX = JX + INCX\n IF( J.GT.K )\n $ KX = KX + INCX\n 140 CONTINUE\n END IF\n ELSE\n IF( INCX.EQ.1 )THEN\n DO 170, J = N, 1, -1\n L = 1 - J\n IF( NOCONJ )THEN\n DO 150, I = MIN( N, J + K ), J + 1, -1\n X( J ) = X( J ) - A( L + I, J )*X( I )\n 150 CONTINUE\n IF( NOUNIT )\n $ X( J ) = X( J )/A( 1, J )\n ELSE\n DO 160, I = MIN( N, J + K ), J + 1, -1\n X( J ) = X( J ) - CONJG( A( L + I, J ) )*X( I )\n 160 CONTINUE\n IF( NOUNIT )\n $ X( J ) = X( J )/CONJG( A( 1, J ) )\n END IF\n 170 CONTINUE\n ELSE\n KX = KX + ( N - 1 )*INCX\n JX = KX\n DO 200, J = N, 1, -1\n IX = KX\n L = 1 - J\n IF( NOCONJ )THEN\n DO 180, I = MIN( N, J + K ), J + 1, -1\n X( JX ) = X( JX ) - A( L + I, J )*X( IX )\n IX = IX - INCX\n 180 CONTINUE\n IF( NOUNIT )\n $ X( JX ) = X( JX )/A( 1, J )\n ELSE\n DO 190, I = MIN( N, J + K ), J + 1, -1\n X( JX ) = X( JX ) -\n $ CONJG( A( L + I, J ) )*X( IX )\n IX = IX - INCX\n 190 CONTINUE\n IF( NOUNIT )\n $ X( JX ) = X( JX )/CONJG( A( 1, J ) )\n END IF\n JX = JX - INCX\n IF( ( N - J ).GE.K )\n $ KX = KX - INCX\n 200 CONTINUE\n END IF\n END IF\n END IF\n*\n RETURN\n*\n* End of ECTBSV.\n*\n END\n", "meta": {"hexsha": "ac7ed155c7dfe0cadf14857a35133e443f87d558", "size": 158599, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "blas-www/ecblas2.f", "max_stars_repo_name": "NetlibRepository/lapack-www", "max_stars_repo_head_hexsha": "e3253f69893da6930057896e48ebfb9e7ae30473", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2016-05-26T03:44:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-19T19:11:09.000Z", "max_issues_repo_path": "blas-www/ecblas2.f", "max_issues_repo_name": "NetlibRepository/lapack-www", "max_issues_repo_head_hexsha": "e3253f69893da6930057896e48ebfb9e7ae30473", "max_issues_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-12-13T10:51:03.000Z", "max_issues_repo_issues_event_max_datetime": "2017-12-13T10:51:03.000Z", "max_forks_repo_path": "blas-www/ecblas2.f", "max_forks_repo_name": "NetlibRepository/lapack-www", "max_forks_repo_head_hexsha": "e3253f69893da6930057896e48ebfb9e7ae30473", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2016-12-13T09:04:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-23T17:34:31.000Z", "avg_line_length": 32.680609932, "max_line_length": 72, "alphanum_fraction": 0.4102358779, "num_tokens": 47085, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206659843132, "lm_q2_score": 0.7371581568543044, "lm_q1q2_score": 0.6648581757658031}} {"text": "C\nC $Id: rbgdfe.f,v 1.12 2008-09-18 00:42:18 kennison Exp $\nC\nC Copyright (C) 2000\nC University Corporation for Atmospheric Research\nC All Rights Reserved\nC\nC The use of this Software is governed by a License Agreement.\nC\n DOUBLE PRECISION FUNCTION RBGDFE (RLAT)\nC\n DOUBLE PRECISION RLAT\nC\nC The value of RBGDFE(RLAT) is the signed distance, from the equator,\nC of the parallel at latitude RLAT; its magnitude is a fraction of the\nC length of the equator.\nC\nC Declare local variables.\nC\n DOUBLE PRECISION FLAT,PDFE(19)\nC\n INTEGER ILAT\nC\nC Define the contents of PDFE per the definition of the Robinson\nC projection. The values are associated with values of latitude from\nC 0 North to 90 North at five-degree intervals.\nC\n DATA PDFE( 1) / 0.0000D0 /\n DATA PDFE( 2) / 0.0620D0 /\n DATA PDFE( 3) / 0.1240D0 /\n DATA PDFE( 4) / 0.1860D0 /\n DATA PDFE( 5) / 0.2480D0 /\n DATA PDFE( 6) / 0.3100D0 /\n DATA PDFE( 7) / 0.3720D0 /\n DATA PDFE( 8) / 0.4340D0 /\n DATA PDFE( 9) / 0.4958D0 /\n DATA PDFE(10) / 0.5571D0 /\n DATA PDFE(11) / 0.6176D0 /\n DATA PDFE(12) / 0.6769D0 /\n DATA PDFE(13) / 0.7346D0 /\n DATA PDFE(14) / 0.7903D0 /\n DATA PDFE(15) / 0.8435D0 /\n DATA PDFE(16) / 0.8936D0 /\n DATA PDFE(17) / 0.9394D0 /\n DATA PDFE(18) / 0.9761D0 /\n DATA PDFE(19) / 1.0000D0 /\nC\nC Determine where the parallel of interest lies relative to the ones\nC represented in the tables (between the ones associated with elements\nC ILAT and ILAT+1 and a fractional distance FLAT from the former to the\nC latter).\nC\n ILAT=MAX(1,MIN(18,INT(1.D0+ABS(RLAT)/5.D0)))\nC\n FLAT=1.D0+ABS(RLAT)/5.D0-DBLE(ILAT)\nC\nC Return the desired value.\nC\n RBGDFE=.5072D0*SIGN((1.D0-FLAT)*PDFE(ILAT)+\n + FLAT*PDFE(ILAT+1),RLAT)\nC\nC Done.\nC\n RETURN\nC\n END\n", "meta": {"hexsha": "688359a59fbcf45a3699a71861e73f70817fcf1c", "size": 1968, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ncarg2d/src/libncarg/ezmap/rbgdfe.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "ncarg2d/src/libncarg/ezmap/rbgdfe.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "ncarg2d/src/libncarg/ezmap/rbgdfe.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 29.3731343284, "max_line_length": 71, "alphanum_fraction": 0.6112804878, "num_tokens": 701, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569268, "lm_q2_score": 0.7371581510799252, "lm_q1q2_score": 0.6648581744445212}} {"text": "Module schapery_mod\n ! Module for all Schapery theory-related work\n\nContains\n\n Function Schapery_damage(m, eps, Sr_old) result(Sr)\n ! Determine the current Schapery damage state variable based on the current strain state.\n\n Use matProp_Mod\n\n ! Arguments\n Type(matProps), intent(IN) :: m\n Double Precision, intent(IN) :: eps(3,3) ! strain tensor\n Double Precision, intent(IN) :: Sr_old ! previous converged value for Schapery damage\n Double Precision :: Sr\n\n ! Locals\n Double Precision :: Sr_A, Sr_B, Sr_C\n Parameter (zero=0.d0, one=1.d0, two=2.d0, three=3.d0, four=4.d0, six=6.d0)\n ! -------------------------------------------------------------------- !\n\n ! Determine the reduce Schapery damage state variable, Sr\n Sr_A = ( eps(2,2)**2*m%E2*m%es(4) + (two*eps(1,2))**2*m%G12*m%gs(4) ) / two + one\n Sr_B = ( eps(2,2)**2*m%E2*m%es(3) + (two*eps(1,2))**2*m%G12*m%gs(3) ) / three\n Sr_C = ( eps(2,2)**2*m%E2*m%es(2) + (two*eps(1,2))**2*m%G12*m%gs(2) ) / six\n\n Sr = ( -Sr_B + SQRT( Sr_B*Sr_B - four*Sr_A*Sr_C ) ) / ( two*Sr_A )\n\n Sr = max(Sr, Sr_old)\n\n Return\n End Function Schapery_damage\n\n Function Schapery_reduction(Sr, c) result(reduction)\n ! Calculates the stiffness reduction according to Schapery theory.\n\n ! Arguments\n Double Precision, intent(IN) :: Sr ! Reduced Schapery damage state variable\n Double Precision, intent(IN) :: c(4) ! Schapery coefficients\n Double Precision :: reduction\n ! -------------------------------------------------------------------- !\n\n reduction = c(1) + c(2)*Sr + c(3)*Sr**2 + c(4)*Sr**3\n\n Return\n End Function Schapery_reduction\n\nEnd Module schapery_mod\n", "meta": {"hexsha": "d248098d15cedc1033751e0c37e2917e68836bbc", "size": 1714, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "for/schapery.for", "max_stars_repo_name": "LucaDiStasio/CompDam_DGD", "max_stars_repo_head_hexsha": "c01344972db6b9b97d5d19225bff8e63d8e54a20", "max_stars_repo_licenses": ["NASA-1.3"], "max_stars_count": 81, "max_stars_repo_stars_event_min_datetime": "2016-07-12T18:14:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T04:46:46.000Z", "max_issues_repo_path": "for/schapery.for", "max_issues_repo_name": "LucaDiStasio/CompDam_DGD", "max_issues_repo_head_hexsha": "c01344972db6b9b97d5d19225bff8e63d8e54a20", "max_issues_repo_licenses": ["NASA-1.3"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2017-04-04T13:37:26.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-18T14:52:06.000Z", "max_forks_repo_path": "for/schapery.for", "max_forks_repo_name": "LucaDiStasio/CompDam_DGD", "max_forks_repo_head_hexsha": "c01344972db6b9b97d5d19225bff8e63d8e54a20", "max_forks_repo_licenses": ["NASA-1.3"], "max_forks_count": 55, "max_forks_repo_forks_event_min_datetime": "2016-07-12T18:47:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T22:46:28.000Z", "avg_line_length": 34.9795918367, "max_line_length": 102, "alphanum_fraction": 0.5787631272, "num_tokens": 525, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.933430812881347, "lm_q2_score": 0.7122321842389469, "lm_q1q2_score": 0.6648194666944175}} {"text": "!===============================================================================\nprogram chi2_95\n!===============================================================================\n! Compute percentage points of the chi-2 probability distribution\n use statistical\n implicit none\n \n integer,parameter :: rs=8\n real(rs) :: p,v,g\n character(20) :: arg\n \n if (command_argument_count() /= 1) then\n write(*,'(a)') 'Usage: chi2_95 [degrees of freedom]'\n stop\n endif\n \n call get_command_argument(1,arg) ; read(arg,*) v\n p = 0.05\n g = log_gamma(v/2._rs)\n \n write(*,*) ppchi2(p,v,g)\n\nend program chi2_95\n", "meta": {"hexsha": "ce6ec36f4af3c561b86b0b5886cf91cd6cb68ae3", "size": 632, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test_statistical/chi2_95.f90", "max_stars_repo_name": "JackWalpole/seismo-fortran-fork", "max_stars_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2015-06-23T05:28:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T03:46:07.000Z", "max_issues_repo_path": "test_statistical/chi2_95.f90", "max_issues_repo_name": "JackWalpole/seismo-fortran-fork", "max_issues_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2017-05-17T11:02:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-28T09:36:24.000Z", "max_forks_repo_path": "test_statistical/chi2_95.f90", "max_forks_repo_name": "JackWalpole/seismo-fortran-fork", "max_forks_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-04-15T02:55:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-20T12:20:51.000Z", "avg_line_length": 26.3333333333, "max_line_length": 80, "alphanum_fraction": 0.4667721519, "num_tokens": 153, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563336, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6648086650789553}} {"text": "!======================================================================\n! SUBRUTINA GENERADORA DE VALORES ALEATORIOS CON UNA DISTRIBUCION\n! GAUSSIANA.\n!\n! AUTOR: MARTIN ALEJANDRO PAREDES SOSA\n! MODIFICACION DEL DE GABY\n!======================================================================\n\nSubroutine RanGauss(Gauss)\n Use cte\n Implicit None\n \n Real :: Rand1, Rand2 !VALORES ALEATORIOS CON DISTRIBUCION UNIFORME\n Real :: Gauss !VALORES ALEATORIOS CON DISTRIBUCION GAUSSIANA\n \n !GENERANDO NUMEROS ALEATORIOS UNIFORMES\n12 Call random_number(Rand1)\n Call random_number(Rand2)\n \n !PREVENIR QUE DIVERJA EL LOGARITMO AL EVALUARLO EN Rand1 \n Diver:If (rand1.le.1E-8) Then\n go to 12\n End If Diver\n \n !GENERANDO UN NUMERO ALEATORIOS CON DISTRIBUCION GAUSSIANA\n Gauss = Sqrt ( -2.0 * log(Rand1) ) * cos(2.0 * pi * Rand2)\n \n \nEnd Subroutine RanGauss\n", "meta": {"hexsha": "7552943e966c966a99331b08c40dce88a6bab4b0", "size": 870, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "Portafolio_III/Comentarios/RanGauss.f03", "max_stars_repo_name": "maps16/DesExpII", "max_stars_repo_head_hexsha": "d9d12b445e0fe86e32fce028be4f5b8bcfd2391f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Portafolio_III/Comentarios/RanGauss.f03", "max_issues_repo_name": "maps16/DesExpII", "max_issues_repo_head_hexsha": "d9d12b445e0fe86e32fce028be4f5b8bcfd2391f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Portafolio_III/Comentarios/RanGauss.f03", "max_forks_repo_name": "maps16/DesExpII", "max_forks_repo_head_hexsha": "d9d12b445e0fe86e32fce028be4f5b8bcfd2391f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.0, "max_line_length": 71, "alphanum_fraction": 0.6091954023, "num_tokens": 281, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392939666335, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.664808664760642}} {"text": "!\n!*******************************************************************************\n!\nsubroutine log_fact(lfactc, faclog)\n!\n!*******************************************************************************\n!\n! Discussion:\n!\n! This subroutine sets up a stored array of the log of n factorial\n!\n! Dependencies:\n!\n! Modules:\n!\n! None\n!\n! Subroutines:\n!\n! None\n!\n! External functions:\n!\n! None\n!\n! MPI routines:\n!\n! None\n!\n! Licensing:\n!\n! SPDX-License-Identifier: MIT \n!\n! Date:\n!\n! 11 May 2021\n!\n! Author:\n!\n! Erich Ormand, LLNL\n!\n!*******************************************************************************\n!\n implicit none\n integer(kind=4), intent(in) :: lfactc\n real(kind=8), intent(out) :: faclog(lfactc)\n integer(kind=4) :: i\n real(kind=8) :: fn\n!-------------------------------------------------------------------------------\n faclog(1) = 0.0d0\n faclog(2) = 0.0d0\n fn = 1.0d0\n do i = 3, lfactc\n fn = fn + 1.0d0\n faclog(i) = faclog(i-1) + log(fn)\n end do\n return\nend subroutine log_fact\n!\n!*******************************************************************************\n!\nreal(kind=8) function wigner3j(j1,j2,j3,m1,m2,m3)\n!\n!*******************************************************************************\n!\n! Discussion:\n!\n! This function computes the Wigner 3J symbol\n! Modified from a FORTRAN77 code of unknown origin\n! Converted and updtated to FORTRAN 90 to remove outdated\n! FORTRAN \n!\n! Dependencies:\n!\n! Modules:\n!\n! None\n!\n! Subroutines:\n!\n! None\n!\n! External functions:\n!\n! None\n!\n! Functions:\n!\n! real(kind=8) :: phase \n! logical :: frac\n! logical :: triangle\n!\n! MPI routines:\n!\n! None\n!\n! Dependencies:\n!\n!\n! Licensing:\n!\n! SPDX-License-Identifier: MIT \n!\n! Date:\n!\n! 11 May 2021\n!\n! Author:\n!\n! Erich Ormand, LLNL updated to FORTRAN 90 removing computed IF and GOTO\n! statements\n!\n!*******************************************************************************\n!\n!---- uses array fact inside module log_factorial\n use log_factorial\n implicit none\n real(kind=8), intent(in) :: j1, m1, j2, m2, j3, m3\n!-------------------------------------------------------------------\n real(kind=8) :: x, y, z\n\n integer(kind=4) :: ia, ib, ic, id, ie\n integer(kind=4) :: i\n integer(kind=4) :: ih, ii, ij, ik, il, im, in\n integer(kind=4) :: ix, iy, iz\n integer(kind=4) :: minn, nin\n real(kind=8) :: s, t, ta, tb, xddd\n!---- Function definitions ------------------------------\n real(kind=8) :: phase \n logical :: frac, triangle\n!---- Phase (-1)**i\n phase(i) = (-1.0d0)**i\n!---- Check x is an integer\n frac(x) = abs(x-int(x)) > 1.0d-10\n!---- Triangle relation to check if angular momenta can couple\n triangle(x,y,z) = frac(x+y+z) .or. x > y+z .or. x < abs(y-z)\n!--------------------------------------------------------------------------\n wigner3j = 0.0d0\n\n if(abs(m1 + m2 + m3) > 1.0d-6)return ! check on z-component \n if(triangle(j3,j1,j2))return ! angular momenta can't couple\n if(j1 - abs(m1) < 0)return ! m1 > j1 - not allowed\n if(j2 - abs(m2) < 0)return ! m2 > j1 - not allowed\n if(j3 - abs(m3) < 0)return ! m3 > j - not allowed\n\n ia = int(j3 - j2 + m1)\n\n ib = int(j3 - j1 - m2)\n\n if(ia < 0)then\n minn = -ia\n if(minn + ib < 0)minn = -ib\n else\n if(ib < 0)then\n minn = -ia\n if(minn + ib < 0)minn = -ib\n else\n minn = 0\n end if\n end if\n\n ic = int(j1 - m1)\n id = int(j2 + m2)\n ie = int(j1 + j2 - j3)\n nin = minn\n t = real(phase(minn),kind=8)\n s = t\n\n ix = 1\n do while(ix > 0)\n minn = minn + 1\n i = int(j2 - j1 + m3)\n iz = ic - minn + 1\n if(iz > 0)then\n iy = id - minn + 1\n if(iy > 0)then\n ix = ie - minn + 1\n if(ix > 0)then\n ta = real(ix*iy*iz,kind=8)\n tb = real(minn*(ia+minn)*(ib+minn),kind=8)\n t = -t*ta/tb\n s = s + t\n end if\n else\n ix = -1\n end if\n else\n ix = -1\n end if\n end do \n\n\n if(abs(s) <= 1.0d-10)then\n wigner3j = 0.0d0\n return\n end if\n ih = int(j1 + m1)\n ii = int(j2 - m2)\n ij = int(j3 + m3)\n ik = int(j3 - m3)\n il = int(j1 + j3 - j2)\n im = int(j2 + j3 - j1)\n in = int(j1 + j2 + j3) + 1\n xddd = 0.5d0*(fact(ih+1) + fact(ic+1) + fact(id+1) + &\n fact(ii+1) + fact(ij+1) + fact(ik+1) + &\n fact(ie+1) + fact(im+1) + fact(il+1) - fact(in+1)) - &\n (fact(ic-nin+1) + fact(ia+nin+1) + fact(id-nin+1) + &\n fact(ib+nin+1) + fact(nin+1) + fact(ie-nin+1))\n wigner3j = phase(i)*exp(xddd)*s\n\n return\nend function wigner3j\n!\n!*******************************************************************************\n!\nreal(kind=8) function clebr(j1,m1,j2,m2,j3,m3)\n!\n!*******************************************************************************\n!\n! Discussion:\n!\n! This function computes Clebsch-Gordan coefficient\n! Modified from a FORTRAN77 code of unknown origin\n! Converted and updtated to FORTRAN 90 to remove outdated\n! FORTRAN \n!\n! Dependencies:\n!\n! Modules:\n!\n! None\n!\n! Subroutines:\n!\n! None\n!\n! External functions:\n!\n! real(kind=8) :: wigner3j\n!\n! Functions:\n!\n! real(kind=8) :: phase \n!\n! MPI routines:\n!\n! None\n!\n! Licensing:\n!\n! SPDX-License-Identifier: MIT \n!\n! Date:\n!\n! 11 May 2021\n!\n! Author:\n!\n! Erich Ormand, LLNL updated to FORTRAN 90 removing computed IF and GOTO\n! statements\n!\n!*******************************************************************************\n!\n implicit none\n real(kind=8), intent(in) :: j1, j2, j3\n real(kind=8), intent(in) :: m1, m2, m3\n!---------------------------------------------------------------------------\n integer(kind=4) :: i\n integer(kind=4) :: iphase\n!---- External functions\n real(kind=8) :: wigner3j\n!---- Function definitions \n real(kind=8) :: phase\n phase(i) = (-1.0d0)**i\n!--------------------------------------------------------------\n\n iphase = nint(-j1 + j2 - m3)\n\n clebr = phase(iphase)*wigner3j(j1,j2,j3,m1,m2,-m3)*sqrt(2.0d0*j3+1.0d0)\n\n return\nend function clebr\n!\n!*******************************************************************************\n!\nreal(kind=8) function wigner6j(j1,j2,j3,j4,j5,j6)\n!\n!*******************************************************************************\n!\n! Discussion:\n!\n! This function computes Wigner 6J symbols defined in Brink and Satcher\n! Modified from a FORTRAN77 code of unknown origin\n! Converted and updtated to FORTRAN 90 to remove outdated\n! FORTRAN \n!\n! Dependencies:\n!\n! Modules:\n!\n! None\n!\n! Subroutines:\n!\n! None\n!\n! External functions:\n!\n! None\n!\n! Functions:\n!\n! real(kind=8) :: phase \n! logical :: frac\n! logical :: triangle\n!\n! MPI routines:\n!\n! None\n!\n! Dependencies:\n!\n!\n! Licensing:\n!\n! SPDX-License-Identifier: MIT \n!\n! Date:\n!\n! 11 May 2021\n!\n! Author:\n!\n! Erich Ormand, LLNL \n!\n!*******************************************************************************\n!\n!---- uses array fact inside module log_factorial\n use log_factorial\n implicit none\n real(kind=8), intent(in) :: j1, j2, j3, j4, j5, j6\n!---------------------------------------------------------------------------\n integer(kind=4) :: i\n integer(kind=4) :: ia, ib, ic, id, ie, ig, ih, m, n, mup\n integer(kind=4) :: it, iu, iv, iw\n real(kind=8) :: xd\n real(kind=8) :: ta, tb, t, s\n\n real(kind=8) :: x, y, z\n!---- Function definitions ------------------------------\n real(kind=8) :: phase \n logical :: frac, triangle\n!---- Phase (-1)**i\n phase(i) = (-1.0d0)**i\n!---- Check x is an integer\n frac(x) = abs(x-int(x)) > 1.0d-10\n!---- Triangle relation to check if angular momenta can couple\n triangle(x,y,z) = frac(x+y+z) .or. x > y+z .or. x < abs(y-z)\n!--------------------------------------------------------------\n!\n! call log_fact(num_fac,fact)\n\n wigner6j = 0.0d0\n\n if(triangle(j1,j2,j3))return\n if(triangle(j1,j5,j6))return\n if(triangle(j2,j4,j6))return\n if(triangle(j3,j4,j5))return\n\n ic = int(j1+j2-j3)\n id = int(j5+j4-j3)\n ie = int(j1+j5-j6)\n ig = int(j2+j4-j6)\n ia = int(j3+j6-j1-j4)\n ib = int(j3+j6-j2-j5)\n ih = int(j1+j2+j5+j4) + 1\n\n m = min(ih,ic,id,ie,ig)\n\n if(m < 0)return\n\n mup = min(ia,ib,0)\n t = phase(m)\n n = m\n s = t\n\n m = m - 1\n do while((m+mup) >= 0)\n ta = (ia+m+1)*(ib+m+1)*(ih-m)*(m+1)\n tb = (ic-m)*(id-m)*(ie-m)*(ig-m)\n t = -t*ta/tb\n s = s + t\n m = m - 1\n end do\n\n it = int(j1+j2+j3) + 1\n iu = int(j1+j5+j6) + 1\n iv = int(j2+j4+j6) + 1\n iw = int(j3+j4+j5) + 1\n\n xd = 0.5d0*(fact(1+ic) + fact(1+ie+ib) + fact(1+ia+ig) + &\n fact(1+ie) + fact(1+ib+ic) + fact(1+ia+id) + &\n fact(1+ig) + fact(1+ic+ia) + fact(1+id+ib) + &\n fact(1+id) + fact(1+ia+ie) + fact(1+ib+ig) - &\n fact(1+it) - fact(1+iu) - fact(1+iv) - fact(1+iw)) + &\n fact(1+ih-n) - fact(1+n) - fact(1+ia+n) - fact(1+ib+n) - &\n fact(1+ic-n) - fact(1+id-n) - fact(1+ie-n) - fact(1+ig-n)\n wigner6j = phase(ih-1)*s*exp(xd)\n\n return\nend function wigner6j\n!\n!*******************************************************************************\n!\nreal(kind=8) function wigner9j(j1,j2,j3,j4,j5,j6,j7,j8,j9)\n!\n!*******************************************************************************\n!\n! Discussion:\n!\n! This function computes Wigner 9J symbols defined in Brink and Satcher\n! Modified from a FORTRAN77 code of unknown origin\n! Converted and updtated to FORTRAN 90 to remove outdated\n! FORTRAN \n!\n! Dependencies:\n!\n! Modules:\n!\n! None\n!\n! Subroutines:\n!\n! None\n!\n! External functions:\n!\n! real(kind=8) :: wigner6j\n!\n! Functions:\n!\n! real(kind=8) :: phase \n! logical :: frac\n! logical :: triangle\n!\n! MPI routines:\n!\n! None\n!\n! Licensing:\n!\n! SPDX-License-Identifier: MIT \n!\n! Date:\n!\n! 11 May 2021\n!\n! Author:\n!\n! Erich Ormand, LLNL \n!\n!*******************************************************************************\n!\n implicit none\n real(kind=8), intent(in) :: j1, j2, j3, j4, j5, j6, j7, j8, j9\n!---------------------------------------------------------------------------\n real(kind=8) :: s\n real(kind=8) :: xa, xb, xc, x\n integer(kind=4) :: k\n integer(kind=4) :: i\n real(kind=8) :: xx, yy, zz\n!---- External functions ---------------------------------------------\n real(kind=8) :: wigner6j\n!---- Function definitions ------------------------------\n real(kind=8) :: phase \n logical :: frac, triangle\n!---- Phase (-1)**i\n phase(i) = (-1.0d0)**i\n!---- Check x is an integer\n frac(x) = abs(xx-int(xx)) > 1.0d-10\n!---- Triangle relation to check if angular momenta can couple\n triangle(xx,yy,zz) = frac(xx+yy+zz) .or. xx > yy+zz .or. xx < abs(yy-zz)\n!--------------------------------------------------------------\n!\n wigner9j = 0.0d0\n\n if(triangle(j1,j2,j3))return\n if(triangle(j4,j5,j6))return\n if(triangle(j3,j6,j9))return\n if(triangle(j1,j4,j7))return\n if(triangle(j2,j5,j8))return\n if(triangle(j7,j8,j9))return\n s = 0.0d0\n\n xa = abs(j1-j9)\n xb = abs(j4-j8)\n xc = abs(j2-j6)\n x = xa\n\n if((x - xb) < 0)x = xb\n if((x - xc) < 0)x = xc\n\n do while((x-j1-j9) <= 0.0d0 .and. (x-j4-j8) <= 0.0d0 .and. &\n (x-j2-j6) <= 0.0d0 )\n s = s + (2.0d0*x+1.0d0)*wigner6j(j1,j9,X,j8,j4,j7)* &\n wigner6j(j2,j6,X,j4,j8,j5)*wigner6j(j1,j9,X,j6,j2,j3)\n x = x + 1.0d0\n end do\n\n k = int(2.0d0*(j1+j2+j4+j6+j8+j9))\n wigner9j = phase(k)*s\n return\nend function wigner9j\n!\n!*******************************************************************************\n!\nreal(kind=8) function racahr(j1,j2,j3,j4,j5,j6)\n!\n!*******************************************************************************\n!\n! Discussion:\n!\n! This function computes Racah 9J symbols defined in Brink and Satcher\n! Modified from a FORTRAN77 code of unknown origin\n! Converted and updtated to FORTRAN 90 to remove outdated\n! FORTRAN \n!\n! Dependencies:\n!\n! Modules:\n!\n! None\n!\n! Subroutines:\n!\n! None\n!\n! External functions:\n!\n! real(kind=8) :: wigner6j\n!\n! Functions:\n!\n! real(kind=8) :: phase \n!\n! MPI routines:\n!\n! None\n!\n! Licensing:\n!\n! SPDX-License-Identifier: MIT \n!\n! Date:\n!\n! 11 May 2021\n!\n! Author:\n!\n! Erich Ormand, LLNL \n!\n!*******************************************************************************\n!\n implicit none\n real(kind=8), intent(in) :: j1, j2, j3, j4, j5, j6\n!---------------------------------------------------------------------------\n integer(kind=4) :: i\n real(kind=8) :: z\n!---- Internal inline function\n real(kind=8) :: phase\n!---- External functions -------------------------------\n real(kind=8) :: wigner6j\n!---- Function definitions ------------------------------\n!---- Compute phase (-1)**i\n phase(i) = (-1.0d0)**i\n!--------------------------------------------------------------\n!\n z = abs(j1+j2+j3+j4)\n i = int(z + 0.5d0)\n racahr = phase(i)*wigner6j(j1,j2,j5,j4,j3,j6)\n return\nend function racahr\n\n\n", "meta": {"hexsha": "12320a7132f76c770441f977c19a8be6fabb7323", "size": 13597, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Src/cleb-lib.f90", "max_stars_repo_name": "LLNL/Yet-Another-Hauser-Feshbach-Code", "max_stars_repo_head_hexsha": "18af2fea77d0263986648b057c06bd96f87ae8e0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-11-05T23:37:51.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-05T23:37:53.000Z", "max_issues_repo_path": "Src/cleb-lib.f90", "max_issues_repo_name": "LLNL/Yet-Another-Hauser-Feshbach-Code", "max_issues_repo_head_hexsha": "18af2fea77d0263986648b057c06bd96f87ae8e0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Src/cleb-lib.f90", "max_forks_repo_name": "LLNL/Yet-Another-Hauser-Feshbach-Code", "max_forks_repo_head_hexsha": "18af2fea77d0263986648b057c06bd96f87ae8e0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-11-05T23:38:28.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-10T21:34:37.000Z", "avg_line_length": 23.2427350427, "max_line_length": 80, "alphanum_fraction": 0.4334779731, "num_tokens": 4288, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563336, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6648086601656197}} {"text": " program tst\n implicit none \n integer :: num, i, r1, c1, m1, pl,in\n CHARACTER(len=32) :: rt, ct, mt\n \n num = IARGC()\n pl = (num/3) -1 \n in = 0 \n \n do i = 1,num,3\n CALL GETARG(i, rt)\n CALL GETARG(i+1, ct)\n CALL GETARG(i+2, mt)\n read(rt, *) r1\n read(ct, *) c1\n read(mt, *) m1\n\n CALL rnd(r1,c1,m1)\n if(pl>in)then\n write(*,*) \" \"\n pl =pl-1\n endif\n \n end do \n end program tst\n\n\n subroutine rnd(r2, c2, m2)\n implicit none\n integer :: r2, c2, m2, r_rand, c_rand\n integer, allocatable :: seed(:)\n integer :: size\n real :: u \n\n !generating random numbers \n call random_seed(size=size)\n allocate(seed(size))\n call random_seed(put=seed)\n CALL random_number(u)\n\n r_rand = 1 + FLOOR((r2-1)*u) \n c_rand = 1 + FLOOR((c2-1)*u)\n call matrx(r_rand, c_rand,m2)\n \n return\n end subroutine rnd\n\n subroutine matrx(r,c,m)\n implicit none\n integer :: r,c,m,i,j\n real :: A(r,c), B(c,r), rslt(r,r) \n\n call random_number(A)\n call random_number(B)\n\n A = (anint(m*A*1000))/1000.0\n B = (anint(m*B*1000))/1000.0\n rslt = matmul(A,B)\n\n do i=1,r\n write(*,*) ( rslt(i,j), j=1,r )\n end do\n \n return\n end subroutine matrx\n", "meta": {"hexsha": "b2688a95fc28ad524f972606311c227e16b2511d", "size": 1410, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "program.f", "max_stars_repo_name": "navneetcmu/Xenon", "max_stars_repo_head_hexsha": "de7fcadf54d62e780bdcd3ad267233cdebc0a819", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "program.f", "max_issues_repo_name": "navneetcmu/Xenon", "max_issues_repo_head_hexsha": "de7fcadf54d62e780bdcd3ad267233cdebc0a819", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "program.f", "max_forks_repo_name": "navneetcmu/Xenon", "max_forks_repo_head_hexsha": "de7fcadf54d62e780bdcd3ad267233cdebc0a819", "max_forks_repo_licenses": ["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.3636363636, "max_line_length": 43, "alphanum_fraction": 0.4758865248, "num_tokens": 445, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460332, "lm_q2_score": 0.752012562644147, "lm_q1q2_score": 0.6648086457439255}} {"text": "program test_products\n use mod_orrb\n implicit none\n\n character(len=*), parameter :: fmt=\"(A40, 'Time: ',ES8.2,', error: ',ES8.2, ', ', A10)\"\n character(len=40) :: test_name\n \n real(kind=dp) :: t0, t1\n integer(kind=int32) :: ma, na, lbwb, ubwb\n type(error_info) :: error\n real(kind=dp), parameter :: tol=1e-15, c=7.0\n !\n real(kind=dp), dimension(:,:), allocatable :: b_d, a_d, c0_d, c1_d\n complex(kind=dp), dimension(:,:), allocatable :: b_z, a_z, c0_z, c1_z\n\n type(d_ub), allocatable :: ub_d\n type(d_bv), allocatable :: bv_d\n type(d_wb), allocatable :: wb_d\n type(d_bt), allocatable :: bt_d\n type(d_ubt), allocatable :: ubt_d\n type(d_wbv), allocatable :: wbv_d\n \n type(z_ub), allocatable :: ub_z\n type(z_bv), allocatable :: bv_z\n type(z_wb), allocatable :: wb_z\n type(z_bt), allocatable :: bt_z\n type(z_ubt), allocatable :: ubt_z\n type(z_wbv), allocatable :: wbv_z\n \n call initialize_errors\n print *\n print *, \"--------------------------------\"\n print *\n print *, \"Tests of Real Products\"\n print *\n\n ma=40; na=10; lbwb=5; ubwb=7\n a_d=d_random_matrix(ma,na)\n ub_d=d_random_ub(ma,lbwb,ubwb,error=error)\n b_d = general(ub_d,error)\n call cpu_time(t0)\n c0_d=d_product_of_ub_and_general(ub_d,a_d,error)\n call cpu_time(t1)\n c1_d=matmul(b_d,a_d)\n test_name = \"Real UB Times Gen. (40x10)\"\n call d_output_result(test_name,c0_d,c1_d,t0,t1,c*tol,error)\n\n ma=40; na=10; lbwb=5; ubwb=7\n a_d=d_random_matrix(ma,na)\n bv_d=d_random_bv(ma,lbwb,ubwb,error=error)\n b_d = general(bv_d,error)\n call cpu_time(t0)\n c0_d=d_product_of_bv_and_general(bv_d,a_d,error)\n call cpu_time(t1)\n c1_d=matmul(b_d,a_d)\n test_name = \"Real BV Times Gen. (40x10)\"\n call d_output_result(test_name,c0_d,c1_d,t0,t1,c*tol,error)\n\n ma=40; na=10; lbwb=5; ubwb=7\n a_d=d_random_matrix(ma,na)\n wb_d=d_random_wb(ma,lbwb,ubwb,error=error)\n b_d = general(wb_d,error)\n call cpu_time(t0)\n c0_d=d_product_of_wb_and_general(wb_d,a_d,error)\n call cpu_time(t1)\n c1_d=matmul(b_d,a_d)\n test_name = \"Real WB Times Gen. (40x10)\"\n call d_output_result(test_name,c0_d,c1_d,t0,t1,c*tol,error)\n\n ma=40; na=10; lbwb=5; ubwb=7\n a_d=d_random_matrix(ma,na)\n bt_d=d_random_bt(ma,lbwb,ubwb,error=error)\n b_d = general(bt_d,error)\n call cpu_time(t0)\n c0_d=d_product_of_bt_and_general(bt_d,a_d,error)\n call cpu_time(t1)\n c1_d=matmul(b_d,a_d)\n test_name = \"Real BT Times Gen. (40x10)\"\n call d_output_result(test_name,c0_d,c1_d,t0,t1,c*tol,error)\n\n ma=40; na=10; lbwb=5; ubwb=7\n a_d=d_random_matrix(ma,na)\n ubt_d=d_random_ubt(ma,lbwb,ubwb,error=error)\n b_d = general(ubt_d,error)\n call cpu_time(t0)\n c0_d=d_product_of_ubt_and_general(ubt_d,a_d,error)\n call cpu_time(t1)\n c1_d=matmul(b_d,a_d)\n test_name = \"Real UBT Times Gen. (40x10)\"\n call d_output_result(test_name,c0_d,c1_d,t0,t1,c*tol,error)\n\n ma=40; na=10; lbwb=5; ubwb=7\n a_d=d_random_matrix(ma,na)\n wbv_d=d_random_wbv(ma,lbwb,ubwb,error=error)\n b_d = general(wbv_d,error)\n call cpu_time(t0)\n c0_d=d_product_of_wbv_and_general(wbv_d,a_d,error)\n call cpu_time(t1)\n c1_d=matmul(b_d,a_d)\n test_name = \"Real WBV Times Gen. (40x10)\"\n call d_output_result(test_name,c0_d,c1_d,t0,t1,c*tol,error)\n\n ma=10; na=40; lbwb=5; ubwb=7\n a_d=d_random_matrix(ma,na)\n ub_d=d_random_ub(na,lbwb,ubwb,error=error)\n b_d = general(ub_d,error)\n call cpu_time(t0)\n c0_d=d_product_of_general_and_ub(a_d, ub_d,error)\n call cpu_time(t1)\n c1_d=matmul(a_d,b_d)\n test_name = \"Real Gen. Times UB. (10x40)\"\n call d_output_result(test_name,c0_d,c1_d,t0,t1,c*tol,error)\n \n \n print *\n print *, \"--------------------------------\"\n print *\n print *, \"Tests of Complex Products\"\n print *\n\n ma=40; na=10; lbwb=5; ubwb=7\n a_z=z_random_matrix(ma,na)\n ub_z=z_random_ub(ma,lbwb,ubwb,error=error)\n b_z = general(ub_z,error)\n call cpu_time(t0)\n c0_z=z_product_of_ub_and_general(ub_z,a_z,error)\n call cpu_time(t1)\n c1_z=matmul(b_z,a_z)\n test_name = \"Complex UB Times Gen. (40x10)\"\n call z_output_result(test_name,c0_z,c1_z,t0,t1,c*tol,error)\n \n ma=40; na=10; lbwb=5; ubwb=7\n a_z=z_random_matrix(ma,na)\n bv_z=z_random_bv(ma,lbwb,ubwb,error=error)\n b_z = general(bv_z,error)\n call cpu_time(t0)\n c0_z=z_product_of_bv_and_general(bv_z,a_z,error)\n call cpu_time(t1)\n c1_z=matmul(b_z,a_z)\n test_name = \"Complex BV Times Gen. (40x10)\"\n call z_output_result(test_name,c0_z,c1_z,t0,t1,c*tol,error)\n\n ma=40; na=10; lbwb=5; ubwb=7\n a_z=z_random_matrix(ma,na)\n wb_z=z_random_wb(ma,lbwb,ubwb,error=error)\n b_z = general(wb_z,error)\n call cpu_time(t0)\n c0_z=z_product_of_wb_and_general(wb_z,a_z,error)\n call cpu_time(t1)\n c1_z=matmul(b_z,a_z)\n test_name = \"Complex WB Times Gen. (40x10)\"\n call z_output_result(test_name,c0_z,c1_z,t0,t1,c*tol,error)\n \n ma=40; na=10; lbwb=5; ubwb=7\n a_z=z_random_matrix(ma,na)\n bt_z=z_random_bt(ma,lbwb,ubwb,error=error)\n b_z = general(bt_z,error)\n call cpu_time(t0)\n c0_z=z_product_of_bt_and_general(bt_z,a_z,error)\n call cpu_time(t1)\n c1_z=matmul(b_z,a_z)\n test_name = \"Complex BT Times Gen. (40x10)\"\n call z_output_result(test_name,c0_z,c1_z,t0,t1,c*tol,error)\n\n ma=40; na=10; lbwb=5; ubwb=7\n a_z=z_random_matrix(ma,na)\n ubt_z=z_random_ubt(ma,lbwb,ubwb,error=error)\n b_z = general(ubt_z,error)\n call cpu_time(t0)\n c0_z=z_product_of_ubt_and_general(ubt_z,a_z,error)\n call cpu_time(t1)\n c1_z=matmul(b_z,a_z)\n test_name = \"Complex UBT Times Gen. (40x10)\"\n call z_output_result(test_name,c0_z,c1_z,t0,t1,c*tol,error)\n\n ma=40; na=10; lbwb=5; ubwb=7\n a_z=z_random_matrix(ma,na)\n wbv_z=z_random_wbv(ma,lbwb,ubwb,error=error)\n b_z = general(wbv_z,error)\n call cpu_time(t0)\n c0_z=z_product_of_wbv_and_general(wbv_z,a_z,error)\n call cpu_time(t1)\n c1_z=matmul(b_z,a_z)\n test_name = \"Complex WBV Times Gen. (40x10)\"\n call z_output_result(test_name,c0_z,c1_z,t0,t1,c*tol,error)\n \n ma=10; na=40; lbwb=5; ubwb=7\n a_z=z_random_matrix(ma,na)\n ub_z=z_random_ub(na,lbwb,ubwb,error=error)\n b_z = general(ub_z,error)\n call cpu_time(t0)\n c0_z=z_product_of_general_and_ub(a_z, ub_z,error)\n call cpu_time(t1)\n c1_z=matmul(a_z,b_z)\n test_name = \"Complex Gen. Times UB. (10x40)\"\n call z_output_result(test_name,c0_z,c1_z,t0,t1,c*tol,error)\n\ncontains\n\n subroutine d_output_result(name,a0,a1,t0,t1,bnd,error)\n character(len=*) :: name\n real(kind=dp), dimension(:,:) :: a0, a1 \n real(kind=dp) :: bnd, t0, t1\n type(error_info) :: error\n\n real(kind=dp) :: err\n character(len=10) :: test_result\n\n if (error%code > 0) then\n print *, \"Calling error in test: \", name\n else\n err = maxabs(a1-a0)\n if (err < bnd) then\n test_result=\"PASSED\"\n else\n test_result=\" FAILED\"\n end if\n write (*,fmt) name, t1-t0, err, test_result\n end if\n end subroutine d_output_result\n\n subroutine z_output_result(name,a0,a1,t0,t1,bnd,error)\n character(len=*) :: name\n complex(kind=dp), dimension(:,:) :: a0, a1 \n real(kind=dp) :: bnd, t0, t1\n type(error_info) :: error\n\n real(kind=dp) :: err\n character(len=10) :: test_result\n\n if (error%code > 0) then\n print *, \"Calling error in test: \", name\n else\n err = maxabs(a1-a0)\n if (err < bnd) then\n test_result=\"PASSED\"\n else\n test_result=\" FAILED\"\n end if\n write (*,fmt) name, t1-t0, err, test_result\n end if\n end subroutine z_output_result\n \nend program test_products\n", "meta": {"hexsha": "f05d5529bccd23e36dee76197d3372c370a2a7b7", "size": 7370, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/test_products.f90", "max_stars_repo_name": "m-a-stewart/BandGivensWeight", "max_stars_repo_head_hexsha": "f7858d3d0dd95e87a891dc583233e64650209288", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/test_products.f90", "max_issues_repo_name": "m-a-stewart/BandGivensWeight", "max_issues_repo_head_hexsha": "f7858d3d0dd95e87a891dc583233e64650209288", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/test_products.f90", "max_forks_repo_name": "m-a-stewart/BandGivensWeight", "max_forks_repo_head_hexsha": "f7858d3d0dd95e87a891dc583233e64650209288", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.0816326531, "max_line_length": 89, "alphanum_fraction": 0.6856173677, "num_tokens": 2703, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392725805823, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.664808643764727}} {"text": "module ekat_ut\n\n use iso_c_binding, only: c_int, c_double, c_float\n\n implicit none\n\n#ifdef EKAT_TEST_DOUBLE_PRECISION\n integer, parameter :: c_real = c_double\n#else\n integer, parameter :: c_real = c_float\n#endif\n\ncontains\n\n subroutine linear_interp_c(x1,x2,y1,y2,km1,km2,ncol,minthresh) bind(c)\n\n integer(kind=c_int), value, intent(in) :: km1, km2, ncol\n real(kind=c_real), value, intent(in) :: minthresh\n real(kind=c_real), intent(in) :: x1(ncol,km1), y1(ncol,km1)\n real(kind=c_real), intent(in) :: x2(ncol,km2)\n real(kind=c_real), intent(out) :: y2(ncol,km2)\n\n call linear_interp(x1,x2,y1,y2,km1,km2,ncol,minthresh)\n\n end subroutine linear_interp_c\n\n !==============================================================\n ! Linear interpolation to get values on various grids\n\n subroutine linear_interp(x1,x2,y1,y2,km1,km2,ncol,minthresh)\n use iso_c_binding\n implicit none\n\n integer(kind=c_int), intent(in) :: km1, km2\n integer(kind=c_int), intent(in) :: ncol\n real(kind=c_real), intent(in) :: x1(ncol,km1), y1(ncol,km1)\n real(kind=c_real), intent(in) :: x2(ncol,km2)\n real(kind=c_real), intent(in) :: minthresh\n real(kind=c_real), intent(out) :: y2(ncol,km2)\n\n integer :: k1, k2, i\n\n do i=1,ncol\n do k2=1,km2\n if( x2(i,k2) <= x1(i,1) ) then\n y2(i,k2) = y1(i,1) + (y1(i,2)-y1(i,1))*(x2(i,k2)-x1(i,1))/(x1(i,2)-x1(i,1))\n elseif( x2(i,k2) >= x1(i,km1) ) then\n y2(i,k2) = y1(i,km1) + (y1(i,km1)-y1(i,km1-1))*(x2(i,k2)-x1(i,km1))/(x1(i,km1)-x1(i,km1-1))\n else\n do k1 = 2,km1\n if( (x2(i,k2)>=x1(i,k1-1)).and.(x2(i,k2)p.\n\n! We use a binary search.\n\nfunction choice(dist, n, p) result(i)\n\n implicit none\n\n integer, intent(in) :: n\n double precision, intent(in) :: dist(n)\n double precision, intent(in) :: p\n integer :: i\n\n i = 1\n do while (i<=n .and. dist(i)= max_tries) then\n print *, '[Warning] Bipartite edge swap: Maximum tries exceeded.'\n end if\n\n if (verbose) then\n print *, 'Number of swaps: ', swapcount\n print *, 'Maximum number of swaps:', nswap\n print *, 'Number of tries: ', iter\n print *, 'Maximum number of tries:', max_tries\n end if\n\nend subroutine bipartite_edge_swap\n", "meta": {"hexsha": "ff328e9f4b891c67396fbf6378cc05437168dd74", "size": 4054, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "comet/src/fortran/permute_matrix.f95", "max_stars_repo_name": "3lectrologos/comet", "max_stars_repo_head_hexsha": "97c945a5f3a355028de302667cc2cb785b13bc8e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "comet/src/fortran/permute_matrix.f95", "max_issues_repo_name": "3lectrologos/comet", "max_issues_repo_head_hexsha": "97c945a5f3a355028de302667cc2cb785b13bc8e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "comet/src/fortran/permute_matrix.f95", "max_forks_repo_name": "3lectrologos/comet", "max_forks_repo_head_hexsha": "97c945a5f3a355028de302667cc2cb785b13bc8e", "max_forks_repo_licenses": ["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.1530054645, "max_line_length": 75, "alphanum_fraction": 0.61124815, "num_tokens": 1313, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835452961425, "lm_q2_score": 0.7956581049086031, "lm_q1q2_score": 0.6647592543326498}} {"text": "!*****************************************************************************************\n!>\n! This program tests codes for the least-squares solution of\n! M nonlinear equations in n variables. it consists of a driver\n! And an interface subroutine fcn. the driver reads in data,\n! Calls the nonlinear least-squares solver, and finally prints\n! Out information on the performance of the solver. this is\n! Only a sample driver, many other drivers are possible. the\n! Interface subroutine fcn is necessary to take into account the\n! Forms of calling sequences used by the function and jacobian\n! Subroutines in the various nonlinear least-squares solvers.\n!\n!### Reference\n! * ARGONNE NATIONAL LABORATORY. MINPACK PROJECT. MARCH 1980.\n! BURTON S. GARBOW, KENNETH E. HILLSTROM, JORGE J. MORE\n\nprogram test\n\n use minpack_module\n use iso_fortran_env, only: output_unit\n\n implicit none\n\n integer :: i, ic, info, k, ldfjac, lwa, m, n, NFEv, NJEv, NPRob, ntries\n integer :: iwa(40), ma(60), na(60), nf(60), nj(60), np(60), nx(60)\n real(wp) :: factor, fnorm1, fnorm2, tol\n real(wp) :: fjac(65, 40), fnm(60), fvec(65), wa(265), x(40)\n\n integer, parameter :: nwrite = output_unit ! logical output unit\n real(wp), parameter :: one = 1.0_wp\n real(wp), parameter :: ten = 10.0_wp\n\n tol = sqrt(dpmpar(1))\n ldfjac = 65\n lwa = 265\n ic = 0\n n = 40\n m = 65\n ntries = 1\n do NPRob = 1, 20\n if (NPRob == 20) then\n write (nwrite, 99002) ic\n99002 format('1SUMMARY OF ', i3, ' CALLS TO LMDER1'/)\n write (nwrite, 99003)\n99003 format(' NPROB N M NFEV NJEV INFO FINAL L2 NORM'/)\n do i = 1, ic\n write (nwrite, 99004) np(i), na(i), ma(i), nf(i), nj(i),&\n & nx(i), fnm(i)\n99004 format(3i5, 3i6, 1x, d15.7)\n end do\n stop\n else\n factor = one\n do k = 1, ntries\n ic = ic + 1\n call initpt(n, x, NPRob, factor)\n call ssqfcn(m, n, x, fvec, NPRob)\n fnorm1 = enorm(m, fvec)\n write (nwrite, 99005) NPRob, n, m\n99005 format(////5x, ' PROBLEM', i5, 5x, ' DIMENSIONS', 2i5, 5x//)\n NFEv = 0\n NJEv = 0\n call lmder1(fcn, m, n, x, fvec, fjac, ldfjac, tol, info, iwa, wa, lwa)\n call ssqfcn(m, n, x, fvec, NPRob)\n fnorm2 = enorm(m, fvec)\n np(ic) = NPRob\n na(ic) = n\n ma(ic) = m\n nf(ic) = NFEv\n nj(ic) = NJEv\n nx(ic) = info\n fnm(ic) = fnorm2\n write (nwrite, 99006) fnorm1, fnorm2, NFEv, NJEv, info, &\n & (x(i), i=1, n)\n99006 format(5x, ' INITIAL L2 NORM OF THE RESIDUALS', d15.7//5x, &\n ' FINAL L2 NORM OF THE RESIDUALS ', d15.7//5x, &\n ' NUMBER OF FUNCTION EVALUATIONS ', i10//5x, &\n ' NUMBER OF JACOBIAN EVALUATIONS ', i10//5x, &\n ' EXIT PARAMETER', 18x, i10//5x, &\n ' FINAL APPROXIMATE SOLUTION'//(5x, 5d15.7))\n factor = ten*factor\n end do\n end if\n end do\n\ncontains\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! THE CALLING SEQUENCE OF FCN SHOULD BE IDENTICAL TO THE\n! CALLING SEQUENCE OF THE FUNCTION SUBROUTINE IN THE NONLINEAR\n! LEAST-SQUARES SOLVER. FCN SHOULD ONLY CALL THE TESTING\n! FUNCTION AND JACOBIAN SUBROUTINES SSQFCN AND SSQJAC WITH\n! THE APPROPRIATE VALUE OF PROBLEM NUMBER (NPROB).\n\n subroutine fcn(m, n, x, Fvec, Fjac, Ldfjac, Iflag)\n\n implicit none\n\n integer, intent(in) :: m !! the number of functions.\n integer, intent(in) :: n !! the number of variables.\n integer, intent(in) :: ldfjac !! leading dimension of the array fjac.\n integer, intent(inout) :: iflag !! if iflag = 1 calculate the functions at x and\n !! return this vector in fvec. do not alter fjac.\n !! if iflag = 2 calculate the jacobian at x and\n !! return this matrix in fjac. do not alter fvec.\n !!\n !! the value of iflag should not be changed by fcn unless\n !! the user wants to terminate execution of lmder.\n !! in this case set iflag to a negative integer.\n real(wp), intent(in) :: x(n) !! independant variable vector\n real(wp), intent(inout) :: fvec(m) !! value of function at `x`\n real(wp), intent(inout) :: fjac(ldfjac, n) !! jacobian matrix at `x`\n\n select case (iflag)\n case (1)\n call ssqfcn(m, n, x, Fvec, NPRob)\n NFEv = NFEv + 1\n case (2)\n call ssqjac(m, n, x, Fjac, Ldfjac, NPRob)\n NJEv = NJEv + 1\n case default\n error stop 'invalid iflag value'\n end select\n\n end subroutine fcn\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Replaced statement function in original code.\n\n pure elemental function dfloat(i) result(f)\n implicit none\n integer, intent(in) :: i\n real(wp) :: f\n f = real(i, wp)\n end function dfloat\n!*****************************************************************************************\n\n!*****************************************************************************************\n!\n! This subroutine defines the jacobian matrices of eighteen\n! nonlinear least squares problems. The problem dimensions are\n! as described in the prologue comments of [[ssqfcn]].\n\n subroutine ssqjac(m, n, x, Fjac, Ldfjac, Nprob)\n implicit none\n\n integer, intent(in) :: m !! positive integer input variables. n must not exceed m.\n integer, intent(in) :: n !! positive integer input variables. n must not exceed m.\n integer, intent(in) :: ldfjac !! a positive integer input variable not less than m\n !! which specifies the leading dimension of the array fjac.\n integer, intent(in) :: nprob !! a positive integer variable which defines the\n !! number of the problem. nprob must not exceed 18.\n real(wp), intent(in) :: x(n) !! an input array of length n.\n real(wp), intent(out) :: fjac(ldfjac, n) !! an m by n output array which contains the jacobian\n !! matrix of the nprob function evaluated at x.\n\n real(wp), parameter :: v(11) = [4.0_wp, 2.0_wp, 1.0_wp, 5.0e-1_wp, &\n 2.5e-1_wp, 1.67e-1_wp, 1.25e-1_wp, 1.0e-1_wp, &\n 8.33e-2_wp, 7.14e-2_wp, 6.25e-2_wp]\n\n real(wp), parameter :: zero = 0.0_wp\n real(wp), parameter :: one = 1.0_wp\n real(wp), parameter :: two = 2.0_wp\n real(wp), parameter :: three = 3.0_wp\n real(wp), parameter :: four = 4.0_wp\n real(wp), parameter :: five = 5.0_wp\n real(wp), parameter :: eight = 8.0_wp\n real(wp), parameter :: ten = 10.0_wp\n real(wp), parameter :: c14 = 14.0_wp\n real(wp), parameter :: c20 = 20.0_wp\n real(wp), parameter :: c29 = 29.0_wp\n real(wp), parameter :: c45 = 45.0_wp\n real(wp), parameter :: c100 = 100.0_wp\n\n integer :: i, ivar, j, k, mm1, nm1\n real(wp) :: div, dx, prod, s2, temp, ti, tmp1, tmp2, tmp3, tmp4, tpi\n\n Fjac(1:m, 1:n) = zero\n\n ! JACOBIAN ROUTINE SELECTOR.\n\n select case (Nprob)\n case (2)\n\n ! LINEAR FUNCTION - RANK 1.\n\n do j = 1, n\n do i = 1, m\n Fjac(i, j) = dfloat(i)*dfloat(j)\n end do\n end do\n\n case (3)\n\n ! LINEAR FUNCTION - RANK 1 WITH ZERO COLUMNS AND ROWS.\n\n do j = 1, n\n do i = 1, m\n Fjac(i, j) = zero\n end do\n end do\n nm1 = n - 1\n mm1 = m - 1\n if (nm1 >= 2) then\n do j = 2, nm1\n do i = 2, mm1\n Fjac(i, j) = dfloat(i - 1)*dfloat(j)\n end do\n end do\n end if\n\n case (4)\n\n ! ROSENBROCK FUNCTION.\n\n Fjac(1, 1) = -c20*x(1)\n Fjac(1, 2) = ten\n Fjac(2, 1) = -one\n Fjac(2, 2) = zero\n\n case (5)\n\n ! HELICAL VALLEY FUNCTION.\n\n tpi = eight*atan(one)\n temp = x(1)**2 + x(2)**2\n tmp1 = tpi*temp\n tmp2 = sqrt(temp)\n Fjac(1, 1) = c100*x(2)/tmp1\n Fjac(1, 2) = -c100*x(1)/tmp1\n Fjac(1, 3) = ten\n Fjac(2, 1) = ten*x(1)/tmp2\n Fjac(2, 2) = ten*x(2)/tmp2\n Fjac(2, 3) = zero\n Fjac(3, 1) = zero\n Fjac(3, 2) = zero\n Fjac(3, 3) = one\n\n case (6)\n\n ! POWELL SINGULAR FUNCTION.\n\n do j = 1, 4\n do i = 1, 4\n Fjac(i, j) = zero\n end do\n end do\n Fjac(1, 1) = one\n Fjac(1, 2) = ten\n Fjac(2, 3) = sqrt(five)\n Fjac(2, 4) = -Fjac(2, 3)\n Fjac(3, 2) = two*(x(2) - two*x(3))\n Fjac(3, 3) = -two*Fjac(3, 2)\n Fjac(4, 1) = two*sqrt(ten)*(x(1) - x(4))\n Fjac(4, 4) = -Fjac(4, 1)\n\n case (7)\n\n ! FREUDENSTEIN AND ROTH FUNCTION.\n\n Fjac(1, 1) = one\n Fjac(1, 2) = x(2)*(ten - three*x(2)) - two\n Fjac(2, 1) = one\n Fjac(2, 2) = x(2)*(two + three*x(2)) - c14\n\n case (8)\n\n ! BARD FUNCTION.\n\n do i = 1, 15\n tmp1 = dfloat(i)\n tmp2 = dfloat(16 - i)\n tmp3 = tmp1\n if (i > 8) tmp3 = tmp2\n tmp4 = (x(2)*tmp2 + x(3)*tmp3)**2\n Fjac(i, 1) = -one\n Fjac(i, 2) = tmp1*tmp2/tmp4\n Fjac(i, 3) = tmp1*tmp3/tmp4\n end do\n\n case (9)\n\n ! KOWALIK AND OSBORNE FUNCTION.\n\n do i = 1, 11\n tmp1 = v(i)*(v(i) + x(2))\n tmp2 = v(i)*(v(i) + x(3)) + x(4)\n Fjac(i, 1) = -tmp1/tmp2\n Fjac(i, 2) = -v(i)*x(1)/tmp2\n Fjac(i, 3) = Fjac(i, 1)*Fjac(i, 2)\n Fjac(i, 4) = Fjac(i, 3)/v(i)\n end do\n\n case (10)\n\n ! MEYER FUNCTION.\n\n do i = 1, 16\n temp = five*dfloat(i) + c45 + x(3)\n tmp1 = x(2)/temp\n tmp2 = exp(tmp1)\n Fjac(i, 1) = tmp2\n Fjac(i, 2) = x(1)*tmp2/temp\n Fjac(i, 3) = -tmp1*Fjac(i, 2)\n end do\n\n case (11)\n\n ! WATSON FUNCTION.\n\n do i = 1, 29\n div = dfloat(i)/c29\n s2 = zero\n dx = one\n do j = 1, n\n s2 = s2 + dx*x(j)\n dx = div*dx\n end do\n temp = two*div*s2\n dx = one/div\n do j = 1, n\n Fjac(i, j) = dx*(dfloat(j - 1) - temp)\n dx = div*dx\n end do\n end do\n do j = 1, n\n do i = 30, 31\n Fjac(i, j) = zero\n end do\n end do\n Fjac(30, 1) = one\n Fjac(31, 1) = -two*x(1)\n Fjac(31, 2) = one\n\n case (12)\n\n ! BOX 3-DIMENSIONAL FUNCTION.\n\n do i = 1, m\n temp = dfloat(i)\n tmp1 = temp/ten\n Fjac(i, 1) = -tmp1*exp(-tmp1*x(1))\n Fjac(i, 2) = tmp1*exp(-tmp1*x(2))\n Fjac(i, 3) = exp(-temp) - exp(-tmp1)\n end do\n\n case (13)\n\n ! JENNRICH AND SAMPSON FUNCTION.\n\n do i = 1, m\n temp = dfloat(i)\n Fjac(i, 1) = -temp*exp(temp*x(1))\n Fjac(i, 2) = -temp*exp(temp*x(2))\n end do\n\n case (14)\n\n ! BROWN AND DENNIS FUNCTION.\n\n do i = 1, m\n temp = dfloat(i)/five\n ti = sin(temp)\n tmp1 = x(1) + temp*x(2) - exp(temp)\n tmp2 = x(3) + ti*x(4) - cos(temp)\n Fjac(i, 1) = two*tmp1\n Fjac(i, 2) = temp*Fjac(i, 1)\n Fjac(i, 3) = two*tmp2\n Fjac(i, 4) = ti*Fjac(i, 3)\n end do\n\n case (15)\n\n ! CHEBYQUAD FUNCTION.\n\n dx = one/dfloat(n)\n do j = 1, n\n tmp1 = one\n tmp2 = two*x(j) - one\n temp = two*tmp2\n tmp3 = zero\n tmp4 = two\n do i = 1, m\n Fjac(i, j) = dx*tmp4\n ti = four*tmp2 + temp*tmp4 - tmp3\n tmp3 = tmp4\n tmp4 = ti\n ti = temp*tmp2 - tmp1\n tmp1 = tmp2\n tmp2 = ti\n end do\n end do\n\n case (16)\n\n ! BROWN ALMOST-LINEAR FUNCTION.\n\n prod = one\n do j = 1, n\n prod = x(j)*prod\n do i = 1, n\n Fjac(i, j) = one\n end do\n Fjac(j, j) = two\n end do\n do j = 1, n\n temp = x(j)\n if (temp == zero) then\n temp = one\n prod = one\n do k = 1, n\n if (k /= j) prod = x(k)*prod\n end do\n end if\n Fjac(n, j) = prod/temp\n end do\n\n case (17)\n\n ! OSBORNE 1 FUNCTION.\n\n do i = 1, 33\n temp = ten*dfloat(i - 1)\n tmp1 = exp(-x(4)*temp)\n tmp2 = exp(-x(5)*temp)\n Fjac(i, 1) = -one\n Fjac(i, 2) = -tmp1\n Fjac(i, 3) = -tmp2\n Fjac(i, 4) = temp*x(2)*tmp1\n Fjac(i, 5) = temp*x(3)*tmp2\n end do\n\n case (18)\n\n ! OSBORNE 2 FUNCTION.\n\n do i = 1, 65\n temp = dfloat(i - 1)/ten\n tmp1 = exp(-x(5)*temp)\n tmp2 = exp(-x(6)*(temp - x(9))**2)\n tmp3 = exp(-x(7)*(temp - x(10))**2)\n tmp4 = exp(-x(8)*(temp - x(11))**2)\n Fjac(i, 1) = -tmp1\n Fjac(i, 2) = -tmp2\n Fjac(i, 3) = -tmp3\n Fjac(i, 4) = -tmp4\n Fjac(i, 5) = temp*x(1)*tmp1\n Fjac(i, 6) = x(2)*(temp - x(9))**2*tmp2\n Fjac(i, 7) = x(3)*(temp - x(10))**2*tmp3\n Fjac(i, 8) = x(4)*(temp - x(11))**2*tmp4\n Fjac(i, 9) = -two*x(2)*x(6)*(temp - x(9))*tmp2\n Fjac(i, 10) = -two*x(3)*x(7)*(temp - x(10))*tmp3\n Fjac(i, 11) = -two*x(4)*x(8)*(temp - x(11))*tmp4\n end do\n\n case default\n\n ! LINEAR FUNCTION - FULL RANK.\n\n temp = two/dfloat(m)\n do j = 1, n\n do i = 1, m\n Fjac(i, j) = -temp\n end do\n Fjac(j, j) = Fjac(j, j) + one\n end do\n\n end select\n\n end subroutine ssqjac\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! This subroutine specifies the standard starting points for the\n! functions defined by subroutine [[ssqfcn]]. the subroutine returns\n! in x a multiple (factor) of the standard starting point. for\n! the 11th function the standard starting point is zero, so in\n! this case, if factor is not unity, then the subroutine returns\n! the vector x(j) = factor, j=1,...,n.\n\n subroutine initpt(n, x, Nprob, Factor)\n implicit none\n\n integer, intent(in) :: n !! a positive integer input variable.\n integer, intent(in) :: nprob !! a positive integer input variable which defines the\n !! number of the problem. nprob must not exceed 18.\n real(wp), intent(in) :: factor !! an input variable which specifies the multiple of\n !! the standard starting point. if factor is unity, no\n !! multiplication is performed.\n real(wp), intent(out) :: x(n) !! an output array of length n which contains the standard\n !! starting point for problem nprob multiplied by factor.\n\n real(wp), parameter :: zero = 0.0_wp\n real(wp), parameter :: half = 0.5_wp\n real(wp), parameter :: one = 1.0_wp\n real(wp), parameter :: two = 2.0_wp\n real(wp), parameter :: three = 3.0_wp\n real(wp), parameter :: five = 5.0_wp\n real(wp), parameter :: seven = 7.0_wp\n real(wp), parameter :: ten = 10.0_wp\n real(wp), parameter :: twenty = 20.0_wp\n real(wp), parameter :: twntf = 25.0_wp\n\n real(wp), parameter :: c1 = 1.2_wp\n real(wp), parameter :: c2 = 2.5e-1_wp\n real(wp), parameter :: c3 = 3.9e-1_wp\n real(wp), parameter :: c4 = 4.15e-1_wp\n real(wp), parameter :: c5 = 2.0e-2_wp\n real(wp), parameter :: c6 = 4.0e3_wp\n real(wp), parameter :: c7 = 2.5e2_wp\n real(wp), parameter :: c8 = 3.0e-1_wp\n real(wp), parameter :: c9 = 4.0e-1_wp\n real(wp), parameter :: c10 = 1.5_wp\n real(wp), parameter :: c11 = 1.0e-2_wp\n real(wp), parameter :: c12 = 1.3_wp\n real(wp), parameter :: c13 = 6.5e-1_wp\n real(wp), parameter :: c14 = 7.0e-1_wp\n real(wp), parameter :: c15 = 6.0e-1_wp\n real(wp), parameter :: c16 = 4.5_wp\n real(wp), parameter :: c17 = 5.5_wp\n\n integer :: ivar, j\n real(wp) :: h\n\n x(1:n) = zero\n\n ! SELECTION OF INITIAL POINT.\n\n select case (Nprob)\n case (4)\n\n ! ROSENBROCK FUNCTION.\n\n x(1) = -c1\n x(2) = one\n\n case (5)\n\n ! HELICAL VALLEY FUNCTION.\n\n x(1) = -one\n x(2) = zero\n x(3) = zero\n\n case (6)\n\n ! POWELL SINGULAR FUNCTION.\n\n x(1) = three\n x(2) = -one\n x(3) = zero\n x(4) = one\n\n case (7)\n\n ! FREUDENSTEIN AND ROTH FUNCTION.\n\n x(1) = half\n x(2) = -two\n\n case (8)\n\n ! BARD FUNCTION.\n\n x(1) = one\n x(2) = one\n x(3) = one\n\n case (9)\n\n ! KOWALIK AND OSBORNE FUNCTION.\n\n x(1) = c2\n x(2) = c3\n x(3) = c4\n x(4) = c3\n\n case (10)\n\n ! MEYER FUNCTION.\n\n x(1) = c5\n x(2) = c6\n x(3) = c7\n\n case (11)\n\n ! WATSON FUNCTION.\n\n do j = 1, n\n x(j) = zero\n end do\n\n case (12)\n\n ! BOX 3-DIMENSIONAL FUNCTION.\n\n x(1) = zero\n x(2) = ten\n x(3) = twenty\n\n case (13)\n\n ! JENNRICH AND SAMPSON FUNCTION.\n\n x(1) = c8\n x(2) = c9\n\n case (14)\n\n ! BROWN AND DENNIS FUNCTION.\n\n x(1) = twntf\n x(2) = five\n x(3) = -five\n x(4) = -one\n\n case (15)\n\n ! CHEBYQUAD FUNCTION.\n\n h = one/dfloat(n + 1)\n do j = 1, n\n x(j) = dfloat(j)*h\n end do\n\n case (16)\n\n ! BROWN ALMOST-LINEAR FUNCTION.\n\n do j = 1, n\n x(j) = half\n end do\n\n case (17)\n\n ! OSBORNE 1 FUNCTION.\n\n x(1) = half\n x(2) = c10\n x(3) = -one\n x(4) = c11\n x(5) = c5\n\n case (18)\n\n ! OSBORNE 2 FUNCTION.\n\n x(1) = c12\n x(2) = c13\n x(3) = c13\n x(4) = c14\n x(5) = c15\n x(6) = three\n x(7) = five\n x(8) = seven\n x(9) = two\n x(10) = c16\n x(11) = c17\n\n case default\n\n ! LINEAR FUNCTION - FULL RANK OR RANK 1.\n\n do j = 1, n\n x(j) = one\n end do\n\n end select\n\n ! COMPUTE MULTIPLE OF INITIAL POINT.\n\n if (Factor /= one) then\n if (Nprob == 11) then\n do j = 1, n\n x(j) = Factor\n end do\n else\n do j = 1, n\n x(j) = Factor*x(j)\n end do\n end if\n end if\n\n end subroutine initpt\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! THIS SUBROUTINE DEFINES THE FUNCTIONS OF EIGHTEEN NONLINEAR\n! LEAST SQUARES PROBLEMS. THE ALLOWABLE VALUES OF (M,N) FOR\n! FUNCTIONS 1,2 AND 3 ARE VARIABLE BUT WITH M .GE. N.\n! FOR FUNCTIONS 4,5,6,7,8,9 AND 10 THE VALUES OF (M,N) ARE\n! (2,2),(3,3),(4,4),(2,2),(15,3),(11,4) AND (16,3), RESPECTIVELY.\n! FUNCTION 11 (WATSON) HAS M = 31 WITH N USUALLY 6 OR 9.\n! HOWEVER, ANY N, N = 2,...,31, IS PERMITTED.\n! FUNCTIONS 12,13 AND 14 HAVE N = 3,2 AND 4, RESPECTIVELY, BUT\n! ALLOW ANY M .GE. N, WITH THE USUAL CHOICES BEING 10,10 AND 20.\n! FUNCTION 15 (CHEBYQUAD) ALLOWS M AND N VARIABLE WITH M .GE. N.\n! FUNCTION 16 (BROWN) ALLOWS N VARIABLE WITH M = N.\n! FOR FUNCTIONS 17 AND 18, THE VALUES OF (M,N) ARE\n! (33,5) AND (65,11), RESPECTIVELY.\n\n subroutine ssqfcn(m, n, x, Fvec, Nprob)\n\n implicit none\n\n integer,intent(in) :: m !! positive integer input variable. n must not exceed m.\n integer,intent(in) :: n !! positive integer input variable. n must not exceed m.\n integer,intent(in) :: nprob !! a positive integer input variable which defines the\n !! number of the problem. nprob must not exceed 18.\n real(wp),intent(in) :: x(n) !! an input array of length n.\n real(wp),intent(out) :: fvec(m) !! an output array of length m which contains the nprob\n !! function evaluated at x.\n\n real(wp),parameter :: zero = 0.0_wp\n real(wp),parameter :: zp25 = 0.25_wp\n real(wp),parameter :: zp5 = 0.5_wp\n real(wp),parameter :: one = 1.0_wp\n real(wp),parameter :: two = 2.0_wp\n real(wp),parameter :: five = 5.0_wp\n real(wp),parameter :: eight = 8.0_wp\n real(wp),parameter :: ten = 10.0_wp\n real(wp),parameter :: c13 = 13.0_wp\n real(wp),parameter :: c14 = 14.0_wp\n real(wp),parameter :: c29 = 29.0_wp\n real(wp),parameter :: c45 = 45.0_wp\n\n integer :: i, iev, ivar, j, nm1\n real(wp) :: div, dx, prod, sum, s1, s2, temp, ti, &\n tmp1, tmp2, tmp3, tmp4, tpi\n\n real(wp),parameter :: v(11) = [ &\n 4.0_wp, 2.0_wp, 1.0_wp, 5.0e-1_wp, 2.5e-1_wp, 1.67e-1_wp, &\n 1.25e-1_wp, 1.0e-1_wp, 8.33e-2_wp, 7.14e-2_wp, 6.25e-2_wp]\n real(wp),parameter :: y1(15) = [ &\n 1.4e-1_wp, 1.8e-1_wp, 2.2e-1_wp, 2.5e-1_wp, 2.9e-1_wp, 3.2e-1_wp, &\n 3.5e-1_wp, 3.9e-1_wp, 3.7e-1_wp, 5.8e-1_wp, 7.3e-1_wp, 9.6e-1_wp, &\n 1.34_wp, 2.1_wp, 4.39_wp]\n real(wp),parameter :: y2(11) = [1.957e-1_wp, 1.947e-1_wp, &\n 1.735e-1_wp, 1.6e-1_wp, 8.44e-2_wp, 6.27e-2_wp, 4.56e-2_wp, 3.42e-2_wp, &\n 3.23e-2_wp, 2.35e-2_wp, 2.46e-2_wp ]\n real(wp),parameter :: y3(16) = [ &\n 3.478e4_wp, 2.861e4_wp, 2.365e4_wp, 1.963e4_wp, &\n 1.637e4_wp, 1.372e4_wp, 1.154e4_wp, 9.744e3_wp, 8.261e3_wp, 7.03e3_wp, &\n 6.005e3_wp, 5.147e3_wp, 4.427e3_wp, 3.82e3_wp, 3.307e3_wp, 2.872e3_wp ]\n real(wp),parameter :: y4(33) = [ 8.44e-1_wp,&\n 9.08e-1_wp, 9.32e-1_wp, 9.36e-1_wp, 9.25e-1_wp, 9.08e-1_wp, 8.81e-1_wp, &\n 8.5e-1_wp, 8.18e-1_wp, 7.84e-1_wp, 7.51e-1_wp, 7.18e-1_wp, 6.85e-1_wp, &\n 6.58e-1_wp, 6.28e-1_wp, 6.03e-1_wp, 5.8e-1_wp, 5.58e-1_wp, 5.38e-1_wp, &\n 5.22e-1_wp, 5.06e-1_wp, 4.9e-1_wp, 4.78e-1_wp, 4.67e-1_wp, 4.57e-1_wp, &\n 4.48e-1_wp, 4.38e-1_wp, 4.31e-1_wp, 4.24e-1_wp, 4.2e-1_wp, 4.14e-1_wp, &\n 4.11e-1_wp, 4.06e-1_wp ]\n real(wp),parameter :: y5(65) = [ 1.366_wp, &\n 1.191_wp, 1.112_wp, 1.013_wp, 9.91e-1_wp, 8.85e-1_wp, 8.31e-1_wp, &\n 8.47e-1_wp, 7.86e-1_wp, 7.25e-1_wp, 7.46e-1_wp, 6.79e-1_wp, 6.08e-1_wp, &\n 6.55e-1_wp, 6.16e-1_wp, 6.06e-1_wp, 6.02e-1_wp, 6.26e-1_wp, 6.51e-1_wp, &\n 7.24e-1_wp, 6.49e-1_wp, 6.49e-1_wp, 6.94e-1_wp, 6.44e-1_wp, 6.24e-1_wp, &\n 6.61e-1_wp, 6.12e-1_wp, 5.58e-1_wp, 5.33e-1_wp, 4.95e-1_wp, 5.0e-1_wp, &\n 4.23e-1_wp, 3.95e-1_wp, 3.75e-1_wp, 3.72e-1_wp, 3.91e-1_wp, 3.96e-1_wp, &\n 4.05e-1_wp, 4.28e-1_wp, 4.29e-1_wp, 5.23e-1_wp, 5.62e-1_wp, 6.07e-1_wp, &\n 6.53e-1_wp, 6.72e-1_wp, 7.08e-1_wp, 6.33e-1_wp, 6.68e-1_wp, 6.45e-1_wp, &\n 6.32e-1_wp, 5.91e-1_wp, 5.59e-1_wp, 5.97e-1_wp, 6.25e-1_wp, 7.39e-1_wp, &\n 7.1e-1_wp, 7.29e-1_wp, 7.2e-1_wp, 6.36e-1_wp, 5.81e-1_wp, 4.28e-1_wp, &\n 2.92e-1_wp, 1.62e-1_wp, 9.8e-2_wp, 5.4e-2_wp ]\n\n ! initialize:\n fvec = zero\n\n ! FUNCTION ROUTINE SELECTOR.\n\n select case (Nprob)\n case (2)\n\n ! LINEAR FUNCTION - RANK 1.\n\n sum = zero\n do j = 1, n\n sum = sum + dfloat(j)*x(j)\n end do\n do i = 1, m\n Fvec(i) = dfloat(i)*sum - one\n end do\n case (3)\n\n ! LINEAR FUNCTION - RANK 1 WITH ZERO COLUMNS AND ROWS.\n\n sum = zero\n nm1 = n - 1\n if (nm1 >= 2) then\n do j = 2, nm1\n sum = sum + dfloat(j)*x(j)\n end do\n end if\n do i = 1, m\n Fvec(i) = dfloat(i - 1)*sum - one\n end do\n Fvec(m) = -one\n case (4)\n\n ! ROSENBROCK FUNCTION.\n\n Fvec(1) = ten*(x(2) - x(1)**2)\n Fvec(2) = one - x(1)\n case (5)\n\n ! HELICAL VALLEY FUNCTION.\n\n tpi = eight*atan(one)\n tmp1 = sign(zp25, x(2))\n if (x(1) > zero) tmp1 = atan(x(2)/x(1))/tpi\n if (x(1) < zero) tmp1 = atan(x(2)/x(1))/tpi + zp5\n tmp2 = sqrt(x(1)**2 + x(2)**2)\n Fvec(1) = ten*(x(3) - ten*tmp1)\n Fvec(2) = ten*(tmp2 - one)\n Fvec(3) = x(3)\n case (6)\n\n ! POWELL SINGULAR FUNCTION.\n\n Fvec(1) = x(1) + ten*x(2)\n Fvec(2) = sqrt(five)*(x(3) - x(4))\n Fvec(3) = (x(2) - two*x(3))**2\n Fvec(4) = sqrt(ten)*(x(1) - x(4))**2\n case (7)\n\n ! FREUDENSTEIN AND ROTH FUNCTION.\n\n Fvec(1) = -c13 + x(1) + ((five - x(2))*x(2) - two)*x(2)\n Fvec(2) = -c29 + x(1) + ((one + x(2))*x(2) - c14)*x(2)\n case (8)\n\n ! BARD FUNCTION.\n\n do i = 1, 15\n tmp1 = dfloat(i)\n tmp2 = dfloat(16 - i)\n tmp3 = tmp1\n if (i > 8) tmp3 = tmp2\n Fvec(i) = y1(i) - (x(1) + tmp1/(x(2)*tmp2 + x(3)*tmp3))\n end do\n case (9)\n\n ! KOWALIK AND OSBORNE FUNCTION.\n\n do i = 1, 11\n tmp1 = v(i)*(v(i) + x(2))\n tmp2 = v(i)*(v(i) + x(3)) + x(4)\n Fvec(i) = y2(i) - x(1)*tmp1/tmp2\n end do\n case (10)\n\n ! MEYER FUNCTION.\n\n do i = 1, 16\n temp = five*dfloat(i) + c45 + x(3)\n tmp1 = x(2)/temp\n tmp2 = exp(tmp1)\n Fvec(i) = x(1)*tmp2 - y3(i)\n end do\n case (11)\n\n ! WATSON FUNCTION.\n\n do i = 1, 29\n div = dfloat(i)/c29\n s1 = zero\n dx = one\n do j = 2, n\n s1 = s1 + dfloat(j - 1)*dx*x(j)\n dx = div*dx\n end do\n s2 = zero\n dx = one\n do j = 1, n\n s2 = s2 + dx*x(j)\n dx = div*dx\n end do\n Fvec(i) = s1 - s2**2 - one\n end do\n Fvec(30) = x(1)\n Fvec(31) = x(2) - x(1)**2 - one\n case (12)\n\n ! BOX 3-DIMENSIONAL FUNCTION.\n\n do i = 1, m\n temp = dfloat(i)\n tmp1 = temp/ten\n Fvec(i) = exp(-tmp1*x(1)) - exp(-tmp1*x(2)) &\n & + (exp(-temp) - exp(-tmp1))*x(3)\n end do\n case (13)\n\n ! JENNRICH AND SAMPSON FUNCTION.\n\n do i = 1, m\n temp = dfloat(i)\n Fvec(i) = two + two*temp - exp(temp*x(1)) - exp(temp*x(2))\n end do\n case (14)\n\n ! BROWN AND DENNIS FUNCTION.\n\n do i = 1, m\n temp = dfloat(i)/five\n tmp1 = x(1) + temp*x(2) - exp(temp)\n tmp2 = x(3) + sin(temp)*x(4) - cos(temp)\n Fvec(i) = tmp1**2 + tmp2**2\n end do\n case (15)\n\n ! CHEBYQUAD FUNCTION.\n\n do i = 1, m\n Fvec(i) = zero\n end do\n do j = 1, n\n tmp1 = one\n tmp2 = two*x(j) - one\n temp = two*tmp2\n do i = 1, m\n Fvec(i) = Fvec(i) + tmp2\n ti = temp*tmp2 - tmp1\n tmp1 = tmp2\n tmp2 = ti\n end do\n end do\n dx = one/dfloat(n)\n iev = -1\n do i = 1, m\n Fvec(i) = dx*Fvec(i)\n if (iev > 0) Fvec(i) = Fvec(i) + one/(dfloat(i)**2 - one)\n iev = -iev\n end do\n case (16)\n\n ! BROWN ALMOST-LINEAR FUNCTION.\n\n sum = -dfloat(n + 1)\n prod = one\n do j = 1, n\n sum = sum + x(j)\n prod = x(j)*prod\n end do\n do i = 1, n\n Fvec(i) = x(i) + sum\n end do\n Fvec(n) = prod - one\n case (17)\n\n ! OSBORNE 1 FUNCTION.\n\n do i = 1, 33\n temp = ten*dfloat(i - 1)\n tmp1 = exp(-x(4)*temp)\n tmp2 = exp(-x(5)*temp)\n Fvec(i) = y4(i) - (x(1) + x(2)*tmp1 + x(3)*tmp2)\n end do\n case (18)\n\n ! OSBORNE 2 FUNCTION.\n\n do i = 1, 65\n temp = dfloat(i - 1)/ten\n tmp1 = exp(-x(5)*temp)\n tmp2 = exp(-x(6)*(temp - x(9))**2)\n tmp3 = exp(-x(7)*(temp - x(10))**2)\n tmp4 = exp(-x(8)*(temp - x(11))**2)\n Fvec(i) = y5(i) - (x(1)*tmp1 + x(2)*tmp2 + x(3)*tmp3 + x(4)*tmp4)\n end do\n case default\n\n ! LINEAR FUNCTION - FULL RANK.\n\n sum = zero\n do j = 1, n\n sum = sum + x(j)\n end do\n temp = two*sum/dfloat(m) + one\n do i = 1, m\n Fvec(i) = -temp\n if (i <= n) Fvec(i) = Fvec(i) + x(i)\n end do\n end select\n\n end subroutine ssqfcn\n!*****************************************************************************************\n\n!*****************************************************************************************\n end program test\n!*****************************************************************************************", "meta": {"hexsha": "8a113400a103c5275183539c0e59cdcb4b9f1c0f", "size": 32158, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/test_lmder.f90", "max_stars_repo_name": "ivan-pi/minpack-1", "max_stars_repo_head_hexsha": "d5dbbaf2fe6a1e3704ca865a8583d51f13c94a20", "max_stars_repo_licenses": ["MIT"], "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/test_lmder.f90", "max_issues_repo_name": "ivan-pi/minpack-1", "max_issues_repo_head_hexsha": "d5dbbaf2fe6a1e3704ca865a8583d51f13c94a20", "max_issues_repo_licenses": ["MIT"], "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/test_lmder.f90", "max_forks_repo_name": "ivan-pi/minpack-1", "max_forks_repo_head_hexsha": "d5dbbaf2fe6a1e3704ca865a8583d51f13c94a20", "max_forks_repo_licenses": ["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.2547642929, "max_line_length": 102, "alphanum_fraction": 0.4164438087, "num_tokens": 10322, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835330070839, "lm_q2_score": 0.7956580976404297, "lm_q1q2_score": 0.6647592384823215}} {"text": "\tinclude 'VICMAIN_FOR'\n\tsubroutine main44\n\n\timplicit none\n\treal*4\tbuffer(32000)\n\treal*4\tmean,sigma\n\treal*4\tx,y,u,t\n\treal*4\tranx,rany\n\tinteger*4\tnl,ns\n\tinteger*4\tcnt,status\n\tinteger*4\tline,samp\n\tinteger*4\tunit,seed\n\tinteger*8 dseed\n\tcharacter*8 format\n\n\tcall xvmessage('gausnois version 2016-06-08',' ')\n\tcall xvp('NL',nl,cnt)\n\tcall xvp('NS',ns,cnt)\n\tcall xvp('FORMAT',format,cnt)\n\n\tcall xvunit(unit,'OUT',1,status,' ')\n\tcall xvopen(unit,status, 'IO_ACT','SA','OPEN_ACT','SA',\n +\t\t'OP','WRITE', 'U_FORMAT','REAL', 'O_FORMAT',format,\n +\t\t'U_NL',NL, 'U_NS',NS,' ')\n\tcall xvp('SEED',seed,cnt)\n\tdseed = seed\nc\tget_seconds parm is (long)\n\tif (cnt .eq. 0) then\t\t\t\t!no seed entered\n\t\tcall get_seconds(dseed)\t\t\t!p2 subroutine\n\tendif\n call xvp('MEAN',mean,cnt)\n call xvp('SIGMA',sigma,cnt)\nc\trangen parms are (long,float)\n\tdo line = 1,nl\n\t do samp = 1,ns\n\t\tcall rangen(dseed,ranx)\n\t\tcall rangen(dseed,rany)\n\t\tx = max( ranx, 1.0e-10)\n\t\ty = rany\n\t\tu = sqrt((-2.)*log(x)) * cos(2*3.1415927*y)\n\t\tt = sigma*u\n\t\tbuffer(samp) = sigma*u + mean\n\t enddo\n\t call xvwrit(unit,buffer,status,' ')\n\tenddo\n\n\tcall xvclose(unit,status,' ')\n\n\treturn\n\tend\n", "meta": {"hexsha": "114305f4cea1d7437805fd67080516b210675019", "size": 1158, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "vos/p2/prog/gausnois/gausnois.f", "max_stars_repo_name": "NASA-AMMOS/VICAR", "max_stars_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2020-10-21T05:56:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T10:02:01.000Z", "max_issues_repo_path": "vos/p2/prog/gausnois/gausnois.f", "max_issues_repo_name": "NASA-AMMOS/VICAR", "max_issues_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "vos/p2/prog/gausnois/gausnois.f", "max_forks_repo_name": "NASA-AMMOS/VICAR", "max_forks_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-03-09T01:51:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-23T00:23:24.000Z", "avg_line_length": 22.7058823529, "max_line_length": 60, "alphanum_fraction": 0.6424870466, "num_tokens": 427, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835207180243, "lm_q2_score": 0.7956581049086031, "lm_q1q2_score": 0.6647592347768709}} {"text": "!> \\brief Compute the potential vorticity, z\n!! \\detail Given the current pressure and velocity fields,\n!! computes the potential voriticity.\nmodule compute_z_mod\n use kind_params_mod\n use kernel_mod\n use argument_mod\n use grid_mod\n use field_mod\n implicit none\n\n private\n\n public invoke_compute_z\n public compute_z, compute_z_code\n\n type, extends(kernel_type) :: compute_z\n type(go_arg), dimension(6) :: meta_args = &\n (/ go_arg(GO_WRITE, GO_CF, GO_POINTWISE), & ! z\n go_arg(GO_READ, GO_CT, GO_POINTWISE), & ! p\n go_arg(GO_READ, GO_CU, GO_POINTWISE), & ! u\n go_arg(GO_READ, GO_CV, GO_POINTWISE), & ! v\n go_arg(GO_READ, GO_GRID_DX_CONST), & ! dx\n go_arg(GO_READ, GO_GRID_DY_CONST) & ! dy\n /)\n !> This kernel operates on fields that live on an\n !! orthogonal, regular grid.\n integer :: GRID_TYPE = GO_ORTHOGONAL_REGULAR\n\n !> This kernel writes only to internal points of the\n !! simulation domain.\n integer :: ITERATES_OVER = GO_INTERNAL_PTS\n \n !> Although the staggering of variables used in an Arakawa\n !! C grid is well defined, the way in which they are indexed is\n !! an implementation choice. This can be thought of as choosing\n !! which grid-point types have the same (i,j) index as a T\n !! point. This kernel assumes that the U,V and F points that\n !! share the same index as a given T point are those immediately\n !! to the South and West of it.\n integer :: index_offset = GO_OFFSET_SW\n\n contains\n procedure, nopass :: code => compute_z_code\n end type compute_z\n\ncontains\n\n !===================================================\n\n !> Manual implementation of the code needed to invoke\n !! compute_z_code().\n subroutine invoke_compute_z(zfld, pfld, ufld, vfld)\n implicit none\n type(r2d_field), intent(inout) :: zfld\n type(r2d_field), intent(in) :: pfld, ufld, vfld\n ! Locals\n integer :: I, J\n real(go_wp) :: dx, dy\n\n dx = zfld%grid%dx\n dy = zfld%grid%dy\n\n do J=zfld%internal%ystart, zfld%internal%ystop, 1\n do I=zfld%internal%xstart, zfld%internal%xstop, 1\n\n call compute_z_code(i, j, &\n zfld%data, &\n pfld%data, &\n ufld%data, &\n vfld%data, &\n dx, dy)\n\n end do\n end do\n\n end subroutine invoke_compute_z\n\n !===================================================\n\n !> Compute the potential vorticity on the grid point (i,j)\n subroutine compute_z_code(i, j, z, p, u, v, dx, dy)\n implicit none\n integer, intent(in) :: I, J\n real(go_wp), intent(in) :: dx, dy\n real(go_wp), intent(inout), dimension(:,:) :: z\n real(go_wp), intent(in), dimension(:,:) :: p, u, v\n\n ! Original code looked like:\n ! DO J=1,N\n ! DO I=1,M\n ! Z(I+1,J+1) =(FSDX*(V(I+1,J+1)-V(I,J+1))-FSDY*(U(I+1,J+1) & \n ! -U(I+1,J)))/(P(I,J)+P(I+1,J)+P(I+1,J+1)+P(I,J+1))\n\n Z(I,J) =( (4.0d0/dx)*( V(I,J)-V(I-1,J))- &\n (4.0d0/dy)*( U(I,J)-U(I,J-1)) ) / &\n (P(I-1,J-1)+P(I,J-1)+ P(I,J)+P(I-1,J))\n\n end subroutine compute_z_code\n\nend module compute_z_mod\n", "meta": {"hexsha": "2ae0814de81bf2c5dcb27134d3c36cf8fcb02cda", "size": 3285, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "benchmarks/shallow/SEQ/compute_z_mod.f90", "max_stars_repo_name": "stfc/PSycloneBench", "max_stars_repo_head_hexsha": "f3c65c904eb286b4e3f63c43273a80d25e92cbe4", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-03-30T23:33:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T13:32:01.000Z", "max_issues_repo_path": "benchmarks/shallow/SEQ/compute_z_mod.f90", "max_issues_repo_name": "stfc/PSycloneBench", "max_issues_repo_head_hexsha": "f3c65c904eb286b4e3f63c43273a80d25e92cbe4", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 76, "max_issues_repo_issues_event_min_datetime": "2018-01-31T14:16:03.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T13:56:17.000Z", "max_forks_repo_path": "benchmarks/shallow/SEQ/compute_z_mod.f90", "max_forks_repo_name": "stfc/PSycloneBench", "max_forks_repo_head_hexsha": "f3c65c904eb286b4e3f63c43273a80d25e92cbe4", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-08-01T10:23:02.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-28T13:23:01.000Z", "avg_line_length": 32.2058823529, "max_line_length": 74, "alphanum_fraction": 0.5652968037, "num_tokens": 953, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972583359805, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6646868760196033}} {"text": "module ccm_numz\n! basic real types\n integer, parameter:: b8 = selected_real_kind(10)\ncontains\n function ccm_time()\n implicit none\n integer i\n integer :: ccm_start_time(8) = (/(-100,i=1,8)/)\n real(b8) :: ccm_time,tmp\n integer,parameter :: norm(13)=(/ & \n 0, 2678400, 5097600, 7776000,10368000,13046400,&\n 15638400,18316800,20995200,23587200,26265600,28857600,31536000/)\n integer,parameter :: leap(13)=(/ & \n 0, 2678400, 5184000, 7862400,10454400,13132800,&\n 15724800,18403200,21081600,23673600,26352000,28944000,31622400/)\n integer :: values(8),m,sec\n save\n call date_and_time(values=values)\n if(mod(values(1),4) .eq. 0)then\n m=leap(values(2))\n else\n m=norm(values(2))\n endif\n sec=((values(3)*24+values(5))*60+values(6))*60+values(7)\n tmp=real(m,b8)+real(sec,b8)+real(values(8),b8)/1000.0_b8\n !write(*,*)\"vals \",values\n if(values(1) .ne. ccm_start_time(1))then\n if(mod(ccm_start_time(1),4) .eq. 0)then\n tmp=tmp+real(leap(13),b8)\n else\n tmp=tmp+real(norm(13),b8)\n endif\n endif\n ccm_time=tmp\n end function\n\nsubroutine invert (matrix,size)\n implicit none\n real(b8) matrix(:,:)\n integer size\n integer switch,k, jj, kp1, i, j, l, krow, irow,nmax\n parameter (nmax=1000)\n dimension switch(nmax,2)\n real(b8) pivot,temp\n do k = 1,size\n jj = k\n if (k .ne. size) then\n kp1 = k + 1\n pivot = (matrix(k, k))\n do i = kp1,size\n temp = (matrix(i, k))\n if ( abs(pivot) .lt. abs(temp)) then\n pivot = temp\n jj = i\n endif\n enddo\n endif\n switch(k, 1) = k\n switch(k, 2) = jj\n if (jj .ne. k) then\n do j = 1 ,size \n temp = matrix(jj, j)\n matrix(jj, j) = matrix(k, j)\n matrix(k, j) = temp\n enddo\n endif\n do j = 1,size\n if (j .ne. k)matrix(k, j) = matrix(k, j) / matrix(k, k)\n enddo\n matrix(k, k) = 1.0_b8 / matrix(k, k)\n do i = 1,size\n if (i.ne.k) then\n do j = 1,size\n if(j.ne.k)matrix(i,j)=matrix(i,j)-matrix(k,j)*matrix(i,k)\n enddo\n endif\n enddo\n do i = 1, size\n if (i .ne. k)matrix(i, k) = -matrix(i, k) * matrix(k, k)\n enddo\n enddo \n do l = 1,size\n k = size - l + 1\n krow = switch(k, 1)\n irow = switch(k, 2)\n if (krow .ne. irow) then\n do i = 1,size\n temp = matrix(i, krow)\n matrix(i, krow) = matrix(i, irow)\n matrix(i, irow) = temp\n enddo\n endif\n enddo\nend subroutine\n\nsubroutine mset(m, n, in)\n real(b8) :: m(:,:)\n integer n,in\n integer i,j\n do i=1,n\n do j=1,n\n if( i .eq. j)then\n m(i,j)=in\n else\n m(i,j)=1\n endif\n enddo\n enddo\nend subroutine\n\nfunction mcheck(m, n, in)\n real(b8) :: m(:,:)\n real(b8) mcheck,x\n integer n,in\n integer i,j\n x=0\n do i=1,n\n do j=1,n\n if( i .eq. j)then\n x=x+abs(m(i,j)-in)\n else\n x=x+abs(m(i,j)-1)\n endif\n enddo\n enddo\n mcheck=x\nend function\nend module ccm_numz\n\n", "meta": {"hexsha": "e95fe639e6a888e6d7322c7db737f878f65d3453", "size": 3559, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "make/example/ccm_numz.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": "make/example/ccm_numz.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": "make/example/ccm_numz.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": 27.3769230769, "max_line_length": 77, "alphanum_fraction": 0.4650182636, "num_tokens": 1147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972684083608, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6646868743393014}} {"text": "C FILE: TRANS_SUBLIB.FOR\n\nC Overview of transformation subroutine library:\n\nC SUBROUTINE etr3 (dx,dy,dz, xfrmt) : 3D translate\nC SUBROUTINE etr (dx,dy, xfrmt) : 2D translate\nC SUBROUTINE esc3 (fx,fy,fz, xfrmt) : 3D scale\nC SUBROUTINE esc (fx,fy, xfrmt) : 2D scale\nC SUBROUTINE erox (rotang, xfrmt) : 3D rotate X axis\nC SUBROUTINE eroy (rotang, xfrmt) : 3D rotate Y axis\nC SUBROUTINE eroz (rotang, xfrmt) : 3D rotate Z axis\nC SUBROUTINE ero (rotang, xfrmt) : 2D rotate Z axis\nC SUBROUTINE ecom3 (xfrmta, xfrmtb, xfrmto) : 3D composition\nC SUBROUTINE ecom (xfrmta, xfrmtb, xfrmto) : 2D composition\nC SUBROUTINE etp3 (xi,yi,zi, xfrmt, xo,yo,zo) : 3D transform point\nC SUBROUTINE etp (xi,yi, xfrmt, xo,yo) : 2D transform point\nC SUBROUTINE ebltm3 (x0,y0,z0, dx,dy,dz, phix,phiy,phiz, fx,fy,fz, xfrmt)\nC : 3D build transform\nC SUBROUTINE ebltm (x0,y0, dx,dy, phi, fx,fy, xfrmt)\nC : 2D build transform\nC SUBROUTINE ecotm3 (xfrmti, x0,y0,z0, dx,dy,dz, phix,phiy,phiz, fx,fy,fz, xfrmto)\nC : 3D compose transform\nC SUBROUTINE ecotm (xfrmti, x0,y0, dx,dy, phi, fx,fy, xfrmto)\nC : 2D compose transform\nC SUBROUTINE eevom3 (vwrx,vwry,vwrz, vpnx,vpny,vpnz, vupx,vupy,vupz, vwormt)\nC : 3D view orientation\nC SUBROUTINE eevom (vwrx,vwry, vupx,vupy, vwormt)\nC : 2D view orientation\nC SUBROUTINE eevmm (umin, umax, vmin, vmax, xmin, xmax, ymin, ymax)\nC : 2D view mapping\nC *** *** *** *** *** End of PHIGS-mimicking routines; *** *** *** *** ***\n\nC *** *** *** *** *** General-purpose PVT math routines *** *** *** *** ***\nC SUBROUTINE matmul (m,n,p, a,b, c) : matrix multiply\nC SUBROUTINE idmat (sz, mat) : generate identity matrix\nC SUBROUTINE arrtp3 (nsz, xi,yi,zi, xfrmt, xo,yo,zo)\nC : transforms a list of 3D points\nC SUBROUTINE red43 (m4, m3) : reduce 4x4 matrix to 3x3\nC SUBROUTINE exp34 (m3, m4) : expand 3x3 matrix to 4x4\nC LOGICAL FUNCTION trnseq (sz, actmat,expmat) : test transformations equal\nC REAL FUNCTION satan2 (y,x) : safe arctan\nC REAL FUNCTION vecl2 (vx,vy,vz) : squared length of vector\nC REAL FUNCTION vecl (vx,vy,vz) : length of vector\nC SUBROUTINE vec1 (vx,vy,vz, vx1,vy1,vz1) : scale vector to unit length\nC REAL FUNCTION dotprd (vx1,vy1,vz1, vx2,vy2,vz2)\nC : dot product of vectors\nC REAL FUNCTION vecang (vx1,vy1,vz1, vx2,vy2,vz2)\nC : angle between vectors\nC SUBROUTINE crossp (vx1,vy1,vz1, vx2,vy2,vz2, vx3,vy3,vz3)\nC : cross product of vectors\nC SUBROUTINE prpv1 (vx1,vy1,vz1, vx2,vy2,vz2) : get perpendicular 3D vector\nC SUBROUTINE pervec (vx1,vy1,vz1, vx2,vy2,vz2, vx3,vy3,vz3)\nC : perpendicular projection\nC SUBROUTINE ptplds (px,py,pz, a,b,c,d, xn,yn,zn, dist)\nC : point-plane projection,distance\nC SUBROUTINE lnplpt (lx,ly,lz, al,bl,cl, ap,bp,cp,dp, xi,yi,zi)\nC : point of intersection of\nC : line and plane\nC SUBROUTINE pt3pl (xarr,yarr,zarr, a,b,c,d) : plane containing 3 points\nC SUBROUTINE ptspl (ilim, x,y,z, a,b,c,d) : plane containing n points\nC SUBROUTINE pl2pl (ar,br,cr,dr, ax,bx,cx,dx, ap,bp,cp,dp)\nC : plane perpendicular\nC : to reference plane\nC SUBROUTINE pl2ln (a1,b1,c1,d1, a2,b2,c2,d2, a,b,c, px,py,pz)\nC : line as intersection of\nC : two planes\nC INTEGER function abest3 (aa,ba,ca) : greatest magnitude\nC SUBROUTINE ptlnds (px,py,pz, a,b,c,lx,ly,lz, xn,yn,zn, dist)\nC : distance from point to line\nC SUBROUTINE lintpt (a,b,c, d,e,f, x,y) : intersection of 2 lines\nC SUBROUTINE pt2cof (x1,y1, x2,y2, a,b,c) : calculate 2D line coefficients\nC SUBROUTINE parcof (x0,y0, xcoeff,ycoeff, a,b,c)\nC : line coefficients\nC REAL FUNCTION ptregd (px,py,pz, nsz, xa,ya,za)\nC : minimum distance from 3D\nC : point to planar 3D region.\nC INTEGER FUNCTION ceilng (x) : integer ceiling for x\nC INTEGER FUNCTION mod1 (x,m) : x between 1 and m\nC SUBROUTINE invol (px,py,pz, ilim, arx,ary,arz, side, pldist)\nC : is point inside volume\nC INTEGER FUNCTION inarea (px,py, ilim, x, y) : is point inside area\nC SUBROUTINE issdis (sisrpx,sisrpy,sisrpz, sdist, xfrmt, mclipi, expath)\nC : ISS for structure 101, varying search distance\nC SUBROUTINE issab (srpx,srpy,srpz, sdist, stpath, mclipi, sceil, expath)\nC : ISS with varying search distance\nC SUBROUTINE ispths (srpx,srpy,srpz, sdist, sceil, mclipi, stpth, expths)\nC : ISS for multiple expected found paths\n\nC This set of subroutines is a simple implementation of some of\nC the matrix utility functions of PHIGS. They are not meant\nC to be terribly robust or numerically stable in all cases, just\nC adequate to generate expected values which may then be compared\nC with the actual values returned by the implementation under test.\nC They have the same names as the corresponding PHIGS function\nC except that the leading \"P\" is replaced by \"E\" (for Expected).\nC Also, there is no parameter for error indicator.\n\nC Note that the Fortran binding to PHIGS specifies that the\nC first index addresses the row and the second index the column\nC of a transformation matrix.\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/etr3 *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE ETR3 (DX,DY,DZ, XFRMT)\n\n REAL DX,DY,DZ, XFRMT (4,4)\n\n CALL IDMAT (4, XFRMT)\n XFRMT (1,4) = DX\n XFRMT (2,4) = DY\n XFRMT (3,4) = DZ\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/etr *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE ETR (DX,DY, XFRMT)\n\n REAL DX,DY, XFRMT (3,3)\n\n CALL IDMAT (3, XFRMT)\n XFRMT (1,3) = DX\n XFRMT (2,3) = DY\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/esc3 *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE ESC3 (FX,FY,FZ, XFRMT)\n\n REAL FX,FY,FZ, XFRMT (4,4)\n\n CALL IDMAT (4, XFRMT)\n XFRMT (1,1) = FX\n XFRMT (2,2) = FY\n XFRMT (3,3) = FZ\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/esc *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE ESC (FX,FY, XFRMT)\n\n REAL FX,FY, XFRMT (3,3)\n\n CALL IDMAT (3, XFRMT)\n XFRMT (1,1) = FX\n XFRMT (2,2) = FY\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/erox *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE EROX (ROTANG, XFRMT)\n\n REAL XFRMT (4,4), SN, CS, ROTANG\n\n CALL IDMAT (4, XFRMT)\n SN = SIN(ROTANG)\n CS = COS(ROTANG)\n XFRMT (2,2) = CS\n XFRMT (3,3) = CS\n XFRMT (2,3) = -SN\n XFRMT (3,2) = SN\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/eroy *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE EROY (ROTANG, XFRMT)\n\n REAL XFRMT (4,4), SN, CS, ROTANG\n\n CALL IDMAT (4, XFRMT)\n SN = SIN(ROTANG)\n CS = COS(ROTANG)\n XFRMT (1,1) = CS\n XFRMT (3,3) = CS\n XFRMT (1,3) = SN\n XFRMT (3,1) = -SN\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/eroz *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE EROZ (ROTANG, XFRMT)\n\n REAL XFRMT (4,4), SN, CS, ROTANG\n\n CALL IDMAT (4, XFRMT)\n SN = SIN(ROTANG)\n CS = COS(ROTANG)\n XFRMT (1,1) = CS\n XFRMT (2,2) = CS\n XFRMT (1,2) = -SN\n XFRMT (2,1) = SN\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/ero *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE ERO (ROTANG, XFRMT)\n\n REAL XFRMT (3,3), SN, CS, ROTANG\n\n CALL IDMAT (3, XFRMT)\n SN = SIN(ROTANG)\n CS = COS(ROTANG)\n XFRMT (1,1) = CS\n XFRMT (2,2) = CS\n XFRMT (1,2) = -SN\n XFRMT (2,1) = SN\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/ecom3 *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE ECOM3 (XFRMTA, XFRMTB, XFRMTO)\n\n REAL XFRMTA(4,4), XFRMTB(4,4), XFRMTO(4,4)\n\n CALL MATMUL (4,4,4, XFRMTA, XFRMTB, XFRMTO)\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/ecom *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE ECOM (XFRMTA, XFRMTB, XFRMTO)\n\n REAL XFRMTA(3,3), XFRMTB(3,3), XFRMTO(3,3)\n\n CALL MATMUL (3,3,3, XFRMTA, XFRMTB, XFRMTO)\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/etp3 *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE ETP3 (XI,YI,ZI, XFRMT, XO,YO,ZO)\n\n REAL XFRMT (4,4), PTI(4,1), PTO(4,1)\n REAL XI,YI,ZI, XO,YO,ZO, W\n\n PTI(1,1) = XI\n PTI(2,1) = YI\n PTI(3,1) = ZI\n PTI(4,1) = 1.0\n\n CALL MATMUL (4,4,1, XFRMT, PTI, PTO)\n W = PTO(4,1)\n XO = PTO(1,1) / W\n YO = PTO(2,1) / W\n ZO = PTO(3,1) / W\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/etp *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE ETP (XI,YI, XFRMT, XO,YO)\n\n REAL XFRMT (3,3), PTI(3,1), PTO(3,1)\n REAL XI,YI, XO,YO, W\n\n PTI(1,1) = XI\n PTI(2,1) = YI\n PTI(3,1) = 1.0\n\n CALL MATMUL (3,3,1, XFRMT, PTI, PTO)\n W = PTO(3,1)\n XO = PTO(1,1) / W\n YO = PTO(2,1) / W\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/ebltm3 *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE EBLTM3 (X0,Y0,Z0, DX,DY,DZ, PHIX,PHIY,PHIZ, FX,FY,FZ,\n 1 XFRMT)\n\n REAL X0,Y0,Z0, DX,DY,DZ, PHIX,PHIY,PHIZ, FX,FY,FZ,\n 1 XFRMT (4,4), WKA(4,4), WKB(4,4), WKC(4,4)\n\nC shift so that fixed point is at origin\n CALL ETR3 (-X0,-Y0,-Z0, WKA)\nC scale\n CALL ESC3 ( FX, FY, FZ, WKB)\n CALL ECOM3 (WKB, WKA, WKC)\nC rotations\n CALL EROX (PHIX, WKA)\n CALL ECOM3 (WKA, WKC, WKB)\n CALL EROY (PHIY, WKA)\n CALL ECOM3 (WKA, WKB, WKC)\n CALL EROZ (PHIZ, WKA)\n CALL ECOM3 (WKA, WKC, WKB)\nC do specified shift and undo fixed-point shift\n CALL ETR3 (X0+DX, Y0+DY, Z0+DZ, WKA)\n CALL ECOM3 (WKA, WKB, XFRMT)\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/ebltm *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE EBLTM (X0,Y0, DX,DY, PHI, FX,FY, XFRMT)\n\n REAL X0,Y0, DX,DY, PHI, FX,FY,\n 1 XFRMT (3,3), WKA(3,3), WKB(3,3), WKC(3,3)\n\nC shift so that fixed point is at origin\n CALL ETR (-X0,-Y0, WKA)\nC scale\n CALL ESC ( FX, FY, WKB)\n CALL ECOM (WKB, WKA, WKC)\nC rotation\n CALL ERO (PHI, WKA)\n CALL ECOM (WKA, WKC, WKB)\nC do specified shift and undo fixed-point shift\n CALL ETR (X0+DX, Y0+DY, WKA)\n CALL ECOM (WKA, WKB, XFRMT)\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/ecotm3 *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE ECOTM3 (XFRMTI, X0,Y0,Z0, DX,DY,DZ, PHIX,PHIY,PHIZ,\n 1 FX,FY,FZ, XFRMTO)\n\n REAL X0,Y0,Z0, DX,DY,DZ, PHIX,PHIY,PHIZ, FX,FY,FZ,\n 1 XFRMTI (4,4), XFRMTO (4,4), WKA(4,4)\n\n CALL EBLTM3 (X0,Y0,Z0, DX,DY,DZ, PHIX,PHIY,PHIZ, FX,FY,FZ,\n 1 WKA)\n CALL ECOM3 (XFRMTI, WKA, XFRMTO)\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/ecotm *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE ECOTM (XFRMTI, X0,Y0, DX,DY, PHI,\n 1 FX,FY, XFRMTO)\n\n REAL X0,Y0, DX,DY, PHI, FX,FY,\n 1 XFRMTI (3,3), XFRMTO (3,3), WKA(3,3)\n\n CALL EBLTM (X0,Y0, DX,DY, PHI, FX,FY, WKA)\n CALL ECOM (XFRMTI, WKA, XFRMTO)\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/eevom3 *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE EEVOM3 (VWRX,VWRY,VWRZ, VPNX,VPNY,VPNZ,\n 1 VUPX,VUPY,VUPZ, VWORMT)\n\n REAL VWRX,VWRY,VWRZ, VPNX,VPNY,VPNZ, VUPX,VUPY,VUPZ\n REAL TVX,TVY,TVZ, SATAN2\n REAL VWORMT(4,4), TRMT(4,4), WK(4,4)\n REAL XROT(4,4), YROT(4,4), ZROT(4,4), XYROT(4,4)\n\nC calculate Y-rotation (longitude shift), ie swing VPN around\nC into the VN plane of the UVN system.\n CALL EROY (-SATAN2(VPNX, VPNZ), YROT)\n\nC transformed VPN:\n CALL ETP3 (VPNX,VPNY,VPNZ, YROT, TVX,TVY,TVZ)\n\nC calculate X-rotation (latitude shift), ie swing VPN down\nC to coincide with N axis\n CALL EROX (-SATAN2(-TVY,TVZ), XROT)\n\nC calculate composite 1st Y, then X rotation:\n CALL ECOM3 (XROT, YROT, XYROT)\n\nC calculate transformed view-up vector\n CALL ETP3 (VUPX,VUPY,VUPZ, XYROT, TVX,TVY,TVZ)\n\nC calculate Z-rotation so as to swing view-up vector into\nC vn plane, pointing up.\n CALL EROZ (-SATAN2(-TVX, TVY), ZROT)\n\nC calculate shift for view ref pt\n CALL ETR3 ( -VWRX,-VWRY,-VWRZ, TRMT)\n\nC compose into one matrix\n CALL ECOM3 (XYROT, TRMT, WK)\n CALL ECOM3 (ZROT, WK, VWORMT)\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/eevom *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE EEVOM (VWRX,VWRY, VUPX,VUPY, VWORMT)\n\n REAL VWRX,VWRY, VUPX,VUPY, VWORMT(3,3)\n REAL WK(4,4), ZZ,U\n\n ZZ = 0.0\n U = 1.0\n CALL EEVOM3 (VWRX,VWRY,ZZ, ZZ,ZZ,U, VUPX,VUPY,ZZ, WK)\n CALL RED43 (WK, VWORMT)\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/eevmm *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE EEVMM (VWWNLM, PJVPLM, VWMPMT)\n\nC note: no 3D version (eevmm3) because standard does not specify\nC a unique transformation.\n\n REAL VWMPMT(3,3), VWWNLM(4), PJVPLM(4)\n\n CALL EBLTM (VWWNLM(1),VWWNLM(3),\n 1 PJVPLM(1)-VWWNLM(1), PJVPLM(3)-VWWNLM(3), 0.0,\n 2 (PJVPLM(2)-PJVPLM(1))/(VWWNLM(2)-VWWNLM(1)),\n 3 (PJVPLM(4)-PJVPLM(3))/(VWWNLM(4)-VWWNLM(3)), VWMPMT)\n\n END\n\nC *** *** *** *** *** End of PHIGS-mimicking routines; *** *** *** *** ***\n\n\nC *** *** *** *** *** General-purpose PVT math routines *** *** *** *** ***\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/matmul *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE MATMUL (M,N,P, A,B, C)\n\nC general purpose matrix multiply - multiplies an MxN array (A)\nC by a NxP array (B) to yield an MxP array (C).\n\n INTEGER I,J,K, M,N,P\n REAL A(M,N), B(N,P), C(M,P), TOT\n\n DO 100 I = 1,M\n DO 200 J = 1,P\n TOT = 0.0\n DO 300 K = 1,N\n TOT = TOT + A(I,K) * B(K,J)\n300 CONTINUE\n C(I,J) = TOT\n200 CONTINUE\n100 CONTINUE\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/idmat *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE IDMAT (SZ, MAT)\n\nC General purpose routine to initialize a square matrix to\nC the identity matrix.\n\n INTEGER SZ, I,J\n REAL MAT(SZ, SZ)\n\n DO 100 I = 1,SZ\n DO 200 J = 1,SZ\n IF (I .EQ. J) THEN\n MAT (I,J) = 1.0\n ELSE\n MAT (I,J) = 0.0\n ENDIF\n200 CONTINUE\n100 CONTINUE\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/arrtp3 *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE ARRTP3 (NSZ, XI,YI,ZI, XFRMT, XO,YO,ZO)\n\nC This subroutine transforms a list of 3D points according to the\nC given matrix.\n\nC Input parameters:\nC NSZ : number of points\nC XI,YI,ZI : points to be transformed\nC XFRMT : matrix containing transformation\nC Output parameters:\nC XO,YO,ZO : points after being transformed\n\n INTEGER NSZ,IX\n\n REAL XI(NSZ),YI(NSZ),ZI(NSZ), XFRMT(4,4),\n 1 XO(NSZ),YO(NSZ),ZO(NSZ)\n\n DO 100 IX = 1,NSZ\n CALL ETP3 (XI(IX),YI(IX),ZI(IX), XFRMT, XO(IX),YO(IX),ZO(IX))\n100 CONTINUE\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/red43 *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE RED43 (M4, M3)\n\nC General purpose routine to reduce a 4x4 matrix to 3x3, by\nC suppressing 3rd row and column\n\n REAL M4(4,4), M3(3,3)\n INTEGER I,J, IR,JR\n\n DO 100 I = 1,4\n IR = MIN(I,3)\n DO 200 J = 1,4\n JR = MIN(J,3)\n M3(IR,JR) = M4(I,J)\n200 CONTINUE\n100 CONTINUE\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/exp34 *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE EXP34 (MAT3, MAT4)\n\nC Expand a 3x3 matrix into a 4x4 matrix.\n\n INTEGER I,J, IRECV,JRECV\n\n REAL MAT3(3,3), MAT4(4,4)\n\n CALL IDMAT (4,MAT4)\n DO 100 I = 1,3\n IF (I.EQ.3) THEN\n IRECV = 4\n ELSE\n IRECV = I\n ENDIF\n DO 200 J = 1,3\n IF (J.EQ.3) THEN\n JRECV = 4\n ELSE\n JRECV = J\n ENDIF\n MAT4 (IRECV, JRECV) = MAT3 (I, J)\n200 CONTINUE\n100 CONTINUE\n\n END\n\nC *********************************************************\nC * *\nC * LOGICAL FUNCTION TR/trnseq *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n LOGICAL FUNCTION TRNSEQ (SZ, ACTMAT,EXPMAT)\n\nC Test two square matrices to see if they represent the same homogeneous\nC transformation. Each transformation has an infinite number of\nC representations, because the matrix is scaled by element (sz,sz).\n\n INTEGER SZ, I,J\n REAL ACTMAT(SZ,SZ), EXPMAT(SZ,SZ), ASCALE, BSCALE\n LOGICAL APPEQ\n\n ASCALE = ACTMAT(SZ,SZ)\n BSCALE = EXPMAT(SZ,SZ)\n\n IF (ASCALE*BSCALE .EQ. 0.0) THEN\nC at least one is zero\n IF (ASCALE .EQ. BSCALE) THEN\nC both are zero - set to 1.0 - both matrices represent transformation to\nC points at infinity\n ASCALE = 1.0\n BSCALE = 1.0\n ELSE\nC one zero and one not -\n TRNSEQ = .FALSE.\n RETURN\n ENDIF\n ENDIF\n\n DO 100 I = 1,SZ\n DO 200 J = 1,SZ\n IF (.NOT. APPEQ(ACTMAT(I,J)/ASCALE,\n 1 EXPMAT(I,J)/BSCALE, 1E-7, 1E-4)) THEN\n TRNSEQ = .FALSE.\n RETURN\n ENDIF\n200 CONTINUE\n100 CONTINUE\n\n TRNSEQ = .TRUE.\n\n END\n\nC *********************************************************\nC * *\nC * REAL FUNCTION TR/satan2 *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n REAL FUNCTION SATAN2 (Y, X)\n\nC Safe version of arctan-2 function; returns zero when both x and y\nC are zero.\n\n REAL X,Y\n\n IF (X .EQ. 0.0 .AND. Y .EQ. 0.0) THEN\n SATAN2 = 0.0\n ELSE\n SATAN2 = ATAN2(Y,X)\n ENDIF\n\n END\n\n\nC *********************************************************\nC * *\nC * REAL FUNCTION TR/vecl2 *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n REAL FUNCTION VECL2 (VX,VY,VZ)\n\nC This function returns the squared length of a 3D vector.\n\n REAL VX,VY,VZ\n\n VECL2 = VX*VX + VY*VY + VZ*VZ\n\n END\n\n\nC *********************************************************\nC * *\nC * REAL FUNCTION TR/vecl *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n REAL FUNCTION VECL (VX,VY,VZ)\n\nC This function returns the length of a 3D vector.\n\n REAL VX,VY,VZ, VECL2\n\n VECL = SQRT (VECL2 (VX,VY,VZ) )\n\n END\n\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/vec1 *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE VEC1 (VX,VY,VZ, VX1,VY1,VZ1)\n\nC This subroutine accepts an arbitrary 3D vector and returns a\nC parallel vector normalized to unit size.\n\n REAL VX,VY,VZ, VX1,VY1,VZ1, D, VECL\n\n D = VECL(VX,VY,VZ)\n VX1 = VX/D\n VY1 = VY/D\n VZ1 = VZ/D\n\n END\n\n\nC *********************************************************\nC * *\nC * REAL FUNCTION TR/dotprd *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n REAL FUNCTION DOTPRD (VX1,VY1,VZ1, VX2,VY2,VZ2)\n\nC This function accepts two 3D vectors and returns their dot product.\n\n REAL VX1,VY1,VZ1, VX2,VY2,VZ2\n\n DOTPRD = VX1*VX2 + VY1*VY2 + VZ1*VZ2\n\n END\n\n\nC *********************************************************\nC * *\nC * REAL FUNCTION TR/vecang *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n REAL FUNCTION VECANG (VX1,VY1,VZ1, VX2,VY2,VZ2)\n\nC This function accepts two 3D vectors and returns the\nC angle between them.\n\n REAL VX1,VY1,VZ1, VX2,VY2,VZ2, VECL, DOTPRD, VL, COSVAL\n\n VL = VECL(VX1,VY1,VZ1) * VECL(VX2,VY2,VZ2)\n\n IF (VL .EQ. 0) THEN\n VECANG = 0.0\n ELSE\n COSVAL = DOTPRD (VX1,VY1,VZ1, VX2,VY2,VZ2) / VL\n IF (ABS(COSVAL) .GT. 1.0) THEN\n CALL UNMSG ('Unstable parameters passed to VECANG.')\n ENDIF\n VECANG = ACOS (COSVAL)\n ENDIF\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/crossp *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE CROSSP (VX1,VY1,VZ1, VX2,VY2,VZ2, VX3,VY3,VZ3)\n\nC This subroutine accepts two 3D vectors and returns their\nC cross product.\n\n REAL VX1,VY1,VZ1, VX2,VY2,VZ2, VX3,VY3,VZ3\n\n VX3 = VY1*VZ2 - VZ1*VY2\n VY3 = VZ1*VX2 - VX1*VZ2\n VZ3 = VX1*VY2 - VY1*VX2\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/prpv1 *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE PRPV1 (VX1,VY1,VZ1, VX2,VY2,VZ2)\n\nC PRPV1 accepts a 3D vector and returns another 3D vector\nC perpendicular to it.\n\n REAL VX1,VY1,VZ1, VX2,VY2,VZ2, Z\n\n Z = 0.0\n VX2 = Z\n VY2 = Z\n VZ2 = Z\n IF (VX1 .EQ. Z) THEN\n VX2 = 1.0\n ELSEIF (VY1 .EQ. Z) THEN\n VY2 = 1.0\n ELSEIF (VZ1 .EQ. Z) THEN\n VZ2 = 1.0\n ELSE\n VX2 = VY1\n VY2 = -VX1\n ENDIF\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/pervec *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE PERVEC (VX1,VY1,VZ1, VX2,VY2,VZ2, VX3,VY3,VZ3)\n\nC This subroutine accepts two 3D vectors and returns a vector\nC orthogonal to the first, in the plane of the first two vectors,\nC whose dot product with the second vector is positive, hence\nC the angle between them is < 90 degrees. I.e. the 2nd vector\nC minus the 3rd results in a vector with the same direction (but\nC not length) as the 1st. K is the factor by which V1 is \nC multiplied and then subtracted from V2 - i.e.\nC \nC V3 = V2 - K*V1\n\n\nC _ \nC /|A \nC / | \nC / | \nC V2 / | V3\nC / | \nC / | \nC / | \nC / | \nC ----------->.....| \nC V1\nC \\________________/\nC V2 - V3\n\nC Or, V1 can be thought of as the attitude numbers for a plane, and\nC then V3 is the result of the normal projection of V2 into the plane.\nC \nC Closely related to PTPLDS, which is a slightly more general case.\n\n REAL VX1,VY1,VZ1, VX2,VY2,VZ2, VX3,VY3,VZ3, K, DOTPRD, VECL2\n\n K = DOTPRD (VX1,VY1,VZ1, VX2,VY2,VZ2) / VECL2 (VX1, VY1, VZ1)\n VX3 = VX2 - K*VX1\n VY3 = VY2 - K*VY1\n VZ3 = VZ2 - K*VZ1\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/ptplds *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE PTPLDS (PX,PY,PZ, A,B,C,D, XN,YN,ZN, DIST)\n\nC Given a point and plane-coefficients, find nearest\nC point on plane and distance from plane to point.\n\n REAL PX,PY,PZ, A,B,C,D, XN,YN,ZN, DIST, SQ,SOL,U, VECL2\n\n SQ = VECL2 (A,B,C)\n SOL = A*PX + B*PY + C*PZ + D\n DIST = ABS(SOL) / SQRT(SQ)\n U = - SOL / SQ\n XN = PX + A*U\n YN = PY + B*U\n ZN = PZ + C*U\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/lnplpt *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE LNPLPT (LX,LY,LZ, AL,BL,CL, AP,BP,CP,DP, XI,YI,ZI)\n\nC Given a line and a plane, find point of intersection.\n\nC Input parameters\nC LX,LY,LZ : point on the line\nC AL,BL,CL : direction of line\nC AP,BP,CP,DP : co-efficients of plane\nC Output parameters\nC XI,YI,ZI : point of intersection\n\n REAL U, LX,LY,LZ, AL,BL,CL, AP,BP,CP,DP, XI,YI,ZI, DOTPRD\n\n U = - (DOTPRD (AP,BP,CP, LX,LY,LZ) + DP) /\n 1 DOTPRD (AP,BP,CP, AL,BL,CL)\n\n XI = LX + AL*U\n YI = LY + BL*U\n ZI = LZ + CL*U\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/pt3pl *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE PT3PL (X,Y,Z, A,B,C,D)\n\n REAL X(3),Y(3),Z(3), A,B,C,D\n\nC Given 3 points, find containing plane\n A = Y(2)*Z(3) + Y(3)*Z(1) + Y(1)*Z(2)\n 1 - Y(1)*Z(3) - Y(2)*Z(1) - Y(3)*Z(2)\n B = Z(2)*X(3) + Z(3)*X(1) + Z(1)*X(2)\n 1 - Z(1)*X(3) - Z(2)*X(1) - Z(3)*X(2)\n C = X(2)*Y(3) + X(3)*Y(1) + X(1)*Y(2)\n 1 - X(1)*Y(3) - X(2)*Y(1) - X(3)*Y(2)\n\n D = - (A*X(1) + B*Y(1) + C*Z(1) +\n 1 A*X(2) + B*Y(2) + C*Z(2) +\n 2 A*X(3) + B*Y(3) + C*Z(3)) / 3\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/ptspl *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE PTSPL (ILIM, X,Y,Z, A,B,C,D)\n\nC Given a set of supposedly co-planar points, find containing\nC plane. Idea here is to find 2 points at greatest separation\nC along a principal axis (x, y, or z) and then select 3rd point\nC as the one with greatest distance from the line connecting\nC these 2 points. This is an attempt to find 3 \"good\" (widely\nC separated, highly non-colinear) points for computing the plane.\nC If there are 3 non-colinear points, this will find them.\n\n INTEGER IA, ILIM, IXMAX,IXMIN,IYMAX,IYMIN,IZMAX,IZMIN\n INTEGER ILO,IHI, IBEST\n\n REAL X(ILIM),Y(ILIM),Z(ILIM), XT(3),YT(3),ZT(3)\n REAL A,B,C,D, XSEP,YSEP,ZSEP, SEP, AL,BL,CL,XL,YL,ZL\n REAL DISTMX,DIST, XN,YN,ZN\n\n IXMAX = 1\n IXMIN = 1\n IYMAX = 1\n IYMIN = 1\n IZMAX = 1\n IZMIN = 1\n\nC find min,max points for x,y,z\n DO 100 IA = 2,ILIM\n IF (X(IA) .GT. X(IXMAX)) IXMAX = IA\n IF (X(IA) .LT. X(IXMIN)) IXMIN = IA\n\n IF (Y(IA) .GT. Y(IYMAX)) IYMAX = IA\n IF (Y(IA) .LT. Y(IYMIN)) IYMIN = IA\n\n IF (Z(IA) .GT. Z(IZMAX)) IZMAX = IA\n IF (Z(IA) .LT. Z(IZMIN)) IZMIN = IA\n100 CONTINUE\n\n XSEP = X(IXMAX) - X(IXMIN)\n YSEP = Y(IYMAX) - Y(IYMIN)\n ZSEP = Z(IZMAX) - Z(IZMIN)\n\nC take largest of the three separations:\n IF (XSEP .GT. YSEP) THEN\n IHI = IXMAX\n ILO = IXMIN\n SEP = XSEP\n ELSE\n IHI = IYMAX\n ILO = IYMIN\n SEP = YSEP\n ENDIF\n\n IF (ZSEP .GT. SEP) THEN\n IHI = IZMAX\n ILO = IZMIN\n ENDIF\n\nC use two widely separated points as axis for plane\n XT(1) = X(ILO)\n YT(1) = Y(ILO)\n ZT(1) = Z(ILO)\n\n XT(2) = X(IHI)\n YT(2) = Y(IHI)\n ZT(2) = Z(IHI)\n\nC Parameters for axis\n AL = XT(2) - XT(1)\n BL = YT(2) - YT(1)\n CL = ZT(2) - ZT(1)\n\n XL = XT(1)\n YL = YT(1)\n ZL = ZT(1)\n\nC as 3rd point, use one with greatest distance from line\n DISTMX = -1.1\n DO 200 IA = 1,ILIM\n CALL PTLNDS (X(IA),Y(IA),Z(IA), AL,BL,CL, XL,YL,ZL,\n 1 XN,YN,ZN, DIST)\n IF (DIST .GT. DISTMX) THEN\n DISTMX = DIST\n IBEST = IA\n ENDIF\n200 CONTINUE\n\n XT(3) = X(IBEST)\n YT(3) = Y(IBEST)\n ZT(3) = Z(IBEST)\n\n CALL PT3PL (XT,YT,ZT, A,B,C,D)\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/pl2pl *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE PL2PL (AR,BR,CR,DR, AX,BX,CX,DX, AP,BP,CP,DP)\n\nC Given a reference plane (R) and an intersecting crossing plane\nC (X), find the perpendicular plane (P), which contains the line of\nC intersection of R and X, and is perpendicular to R.\n\n REAL AR,BR,CR,DR, AX,BX,CX,DX, AP,BP,CP,DP\n REAL AL,BL,CL, PX,PY,PZ\n\nC get line of intersection of R and X\n CALL PL2LN (AR,BR,CR,DR, AX,BX,CX,DX, AL,BL,CL, PX,PY,PZ)\nC cross-prod of line and ref plane is attitude of P-plane\n CALL CROSSP ( AR,BR,CR, AL,BL,CL, AP,BP,CP)\nC solve for dp, given point on line:\n DP = -(AP*PX + BP*PY + CP*PZ)\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/pl2ln *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE PL2LN (A1,B1,C1,D1, A2,B2,C2,D2, A,B,C, PX,PY,PZ)\n\nC Given two planes, return line-intersection\n\n INTEGER IXYZ, ABEST3\n REAL A1,B1,C1,D1, A2,B2,C2,D2, A,B,C, PX,PY,PZ\n\nC Direction of line is cross-product of normal vectors\n CALL CROSSP (A1,B1,C1, A2,B2,C2, A,B,C)\n\nC use most stable variable as basis - effectively, use x=0, y=0,\nC or z=0 as 3rd plane.\n IXYZ = ABEST3 (A,B,C)\n IF (IXYZ .EQ. 1) THEN\n PX = 0\n CALL LINTPT (B1,C1,D1, B2,C2,D2, PY,PZ)\n ELSEIF (IXYZ .EQ. 2) THEN\n PY = 0\n CALL LINTPT (A1,C1,D1, A2,C2,D2, PX,PZ)\n ELSE\n PZ = 0\n CALL LINTPT (A1,B1,D1, A2,B2,D2, PX,PY)\n ENDIF\n\n END\n\nC *********************************************************\nC * *\nC * INTEGER FUNCTION TR/abest3 *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n INTEGER FUNCTION ABEST3 (AA,BA,CA)\n\n REAL A,B,C,BEST, AA,BA,CA\n\nC function to pick greatest magnitude of 3 numbers\n\n A = ABS(AA)\n B = ABS(BA)\n C = ABS(CA)\n\n IF (A .GT. B) THEN\n ABEST3 = 1\n BEST=A\n ELSE\n ABEST3 = 2\n BEST=B\n ENDIF\n\n IF (C .GT. BEST) THEN\n ABEST3 = 3\n ENDIF\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/ptlnds *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE PTLNDS (PX,PY,PZ, A,B,C,LX,LY,LZ, XN,YN,ZN, DIST)\n\nC Given a point and a line, find nearest point on line and\nC distance from line to point.\n\n REAL PX,PY,PZ, A,B,C,LX,LY,LZ, XN,YN,ZN, DIST, VECL2, VECL\n REAL DX,DY,DZ, D2ABC, DP, U, DOTPRD\n\n DX = PX-LX\n DY = PY-LY\n DZ = PZ-LZ\n D2ABC = VECL2 (A,B,C)\n\n DP = DOTPRD (A,B,C, DX,DY,DZ)\n U = DP / D2ABC\n XN = LX + A*U\n YN = LY + B*U\n ZN = LZ + C*U\n\n DIST = VECL (PX-XN, PY-YN, PZ-ZN)\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/lintpt *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE LINTPT (A,B,C, D,E,F, X,Y)\n\nC Given two sets of line-coefficients, find intersection point\n\n REAL A,B,C,D,E,F,X,Y, DEN\n\n DEN = D*B - A*E\n X = (C*E - F*B) / DEN\n Y = (F*A - C*D) / DEN\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/pt2cof *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE PT2COF (X1,Y1, X2,Y2, A,B,C)\nC Given two points, calculate line coefficients.\n\n REAL X1,Y1, X2,Y2, A,B,C\n\n A = Y1-Y2\n B = X2-X1\n C = X1*Y2 - Y1*X2\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/parcof *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE PARCOF (X0,Y0, XCOEFF,YCOEFF, A,B,C)\nC given parametric form, find line coefficients\n\n REAL X0,Y0, XCOEFF,YCOEFF, A,B,C\n\n A = YCOEFF\n B = -XCOEFF\n C = XCOEFF*Y0 - YCOEFF*X0\n\n END\n\nC *********************************************************\nC * *\nC * REAL FUNCTION TR/ptregd *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n REAL FUNCTION PTREGD (PX,PY,PZ, NSZ, XA,YA,ZA)\n\nC PTREGD computes the minimum distance from a 3D point to a planar\nC 3D region.\n\nC Input parameters:\nC PX,PY,PZ : point for which distance is found.\nC NSZ : number of points in region.\nC XA,YA,ZA : coordinates of planar region.\n\n INTEGER NSZ, IA, IB, SIDE\n\n REAL PX,PY,PZ, XA(NSZ),YA(NSZ),ZA(NSZ)\n REAL XN,YN,ZN, PTMIN, EDGMIN\n REAL SEGA,SEGB,SEGC, D1,D2, ABCP, DTMP,VECL, PLDIST\n\n IF (NSZ .LT. 3) THEN\n CALL UNMSG ('Degenerate region passed to PTREGD.')\n ENDIF\n\n CALL INVOL (PX,PY,PZ, NSZ, XA,YA,ZA, SIDE, PLDIST)\n IF (SIDE .LE. 2) THEN\nC Distance is simply distance of point from containing plane\n PTREGD = PLDIST\n RETURN\n ENDIF\n\nC Distance is minimum of distances from points and from individual edges\n\nC Get point minimum:\n PTMIN = 1E38\n DO 100 IA = 1,NSZ\n DTMP = VECL (PX-XA(IA), PY-YA(IA), PZ-ZA(IA) )\n IF (DTMP .LT. PTMIN) PTMIN = DTMP\n100 CONTINUE\n\nC Get edge minimum:\n EDGMIN = 1E38\n DO 200 IA = 1,NSZ\n IB = MOD(IA, NSZ) + 1\nC Determine if point is between the two planes that contain the\nC endpoints of the segment, and are normal to it. If not, ignore -\nC handled by point minimum. If so, distance is that from point to\nC containing line.\n\nC attitude of planes:\n SEGA = XA(IA) - XA(IB)\n SEGB = YA(IA) - YA(IB)\n SEGC = ZA(IA) - ZA(IB)\nC d-coefficient of each plane:\n D1 = -(SEGA*XA(IA) + SEGB*YA(IA) + SEGC*ZA(IA))\n D2 = -(SEGA*XA(IB) + SEGB*YA(IB) + SEGC*ZA(IB))\nC ABC terms for px,py,pz:\n ABCP = SEGA*PX + SEGB*PY + SEGC*PZ\n IF ( (ABCP + D1) * (ABCP + D2) .LT. 0.0 ) THEN\nC Opposite signs imply point is between planes - get distance from\nC point to line.\n CALL PTLNDS (PX,PY,PZ, SEGA,SEGB,SEGC,\n 1 XA(IA),YA(IA),ZA(IA), XN,YN,ZN, DTMP)\n IF (DTMP .LT. EDGMIN) EDGMIN = DTMP\n ENDIF\n200 CONTINUE\n\n PTREGD = MIN (PTMIN, EDGMIN)\n\n END\n\nC *********************************************************\nC * *\nC * INTEGER FUNCTION TR/ceilng *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n INTEGER FUNCTION CEILNG (X)\n\nC CEILNG returns the integer ceiling for x, i.e. the lowest\nC integer .ge. x\n\n INTEGER IX\n REAL X\n\n IX = INT(X)\n IF (REAL(IX).EQ.X .OR. X.LE.0) THEN\n CEILNG = IX\n ELSE\n CEILNG = IX + 1\n ENDIF\n\n END\n\nC *********************************************************\nC * *\nC * INTEGER FUNCTION TR/mod1 *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n INTEGER FUNCTION MOD1 (X,M)\n\nC MOD1 returns X mod M, but coerced between 1 and M, not between\nC 0 and M-1.\n\n INTEGER X,M, XW\n\n IF (X.LT.0) THEN\n XW = X - (X/M - 2) * M\n ELSE\n XW = X\n ENDIF\n MOD1 = MOD(XW,M)\n IF (MOD1.LE.0) MOD1 = M\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/invol *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE INVOL (PX,PY,PZ, ILIM, ARX,ARY,ARZ, SIDE, PLDIST)\n\nC Given a 3D point and planar fill area, determine whether point\nC is within normal projection of the area, and distance of point\nC from the plane.\n\nC Input parameters:\nC PX,PY,PZ : 3D point\nC ILIM : Number of vertices of fill area\nC ARX,ARY,ARZ : vertices of fill area\n\nC Output parameters:\nC SIDE : location of point within volume -\nC : 1 if inside, 2 if on an edge, 3 if outside\nC PLDIST : distance of point from the plane.\n\n INTEGER ILIM, INAREA, IDIM, SIDE\n\n REAL PX,PY,PZ, ARX(*),ARY(*),ARZ(*)\n REAL A,B,C,D, XN,YN,ZN, PLDIST, BEST\n\n IF (ILIM .LT. 3) THEN\n CALL UNMSG ('Degenerate fill area passed to INVOL.')\n ENDIF\n\nC get plane from set of points\n CALL PTSPL (ILIM, ARX,ARY,ARZ, A,B,C,D)\n\nC Given a point and plane-coefficients, find nearest\nC point on plane and distance from plane to point.\n CALL PTPLDS (PX,PY,PZ, A,B,C,D, XN,YN,ZN, PLDIST)\n\nC Now project the planar points (fill area, plus the normal\nC projected point xn,yn,zn) to the \"best\" plane: x=0, y=0, or z=0,\nC depending on largest attitude number.\n IF (ABS(A) .GT. ABS(B)) THEN\n IDIM = 1\n BEST=ABS(A)\n ELSE\n IDIM = 2\n BEST=ABS(B)\n ENDIF\n\n IF (ABS(C) .GT. BEST) THEN\n IDIM = 3\n ENDIF\n\n IF (IDIM .EQ. 1) THEN\nC project to x=0\n SIDE = INAREA (YN,ZN, ILIM, ARY,ARZ)\n ELSEIF (IDIM .EQ. 2) THEN\nC project to y=0\n SIDE = INAREA (XN,ZN, ILIM, ARX,ARZ)\n ELSE\nC project to z=0\n SIDE = INAREA (XN,YN, ILIM, ARX,ARY)\n ENDIF\n\n END\n\nC *********************************************************\nC * *\nC * INTEGER FUNCTION TR/inarea *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n INTEGER FUNCTION INAREA (PX,PY, ILIM, X, Y)\n\nC Given a 2D point and fill area, determine whether point\nC is within the area, on edge, or outside.\n\nC Input parameters:\nC PX,PY : 2D point\nC ILIM : Number of vertices of fill area\nC X,Y : vertices of fill area\n\nC Function returns:\nC 1 : inside\nC 2 : on an edge\nC 3 : outside\n\nC Idea here is to generate a ray straight up from px,py (positive\nC y-direction), and see how many times it crosses the border.\n\n INTEGER ILIM, CURSGN, IA,IB, IX, IPREV, ICROSS, ICT,ICUR\n\n REAL PX,PY, X(*), Y(*), XA,YA,XB,YB, A,B,C\n REAL XCUR,YCUR, XPREV,YPREV, YINT\n\nC First see if px,py is on any edge:\n DO 100 IA = 1,ILIM\n IB = MOD(IA,ILIM) + 1\n XA = X(IA)\n YA = Y(IA)\n XB = X(IB)\n YB = Y(IB)\nC Given two points, calculate line coefficients\n CALL PT2COF (XA,YA, XB,YB, A,B,C)\nC if not co-linear, skip\n IF (A*PX + B*PY + C .NE. 0.0) GOTO 100\nC if px,py between points, it's on edge:\n IF ((XA-PX)*(XB-PX) .LE. 0 .AND.\n 1 (YA-PY)*(YB-PY) .LE. 0) THEN\n INAREA = 2\n RETURN\n ENDIF\n100 CONTINUE\n\nC OK, assume from here on that point is not on an edge;\nC get point off y-axis\n DO 200 IX = 1,ILIM\n IF (X(IX) .EQ. PX) GOTO 200\n IF (X(IX) .LT. PX) THEN\n CURSGN = -1\n ELSE\n CURSGN = +1\n ENDIF\n IPREV = IX\n GOTO 210\n200 CONTINUE\n INAREA = 3\n RETURN\n\n210 CONTINUE\n ICROSS = 0\n XPREV = X(IPREV)\n YPREV = Y(IPREV)\n\nC start of loop for checking edge segments\n DO 300 ICT = 0,ILIM-1\n ICUR = MOD(IPREV+ICT, ILIM) + 1\n XCUR = X(ICUR)\n YCUR = Y(ICUR)\nC if not a definite crossing of y-axis (equal doesn't count),\nC save last point and keep going ...\n IF ( (XCUR-PX)*CURSGN .GE. 0) GOTO 290\n\nC crossed y-axis\n CURSGN = -CURSGN\n\nC last two points (cur and prev) determine whether crossing above\nC or below px,py:\n CALL PT2COF (XCUR,YCUR, XPREV,YPREV, A,B,C)\n\nC formula for y-intercept of line:a,b,c and line:x=px\n YINT = -(A*PX + C) / B\n\n IF (YINT .GT. PY) THEN\n ICROSS = ICROSS+1\n ELSEIF (YINT .EQ. PY) THEN\nC aha - on edge after all ..\n INAREA = 2\n RETURN\n ENDIF\n\n290 CONTINUE\n XPREV = XCUR\n YPREV = YCUR\n300 CONTINUE\n INAREA = 3 - 2*MOD(ICROSS,2)\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/issdis *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE ISSDIS (SISRPX,SISRPY,SISRPZ, SDIST, XFRMT,\n 1 MCLIPI, EXPATH)\n\nC This subroutine invokes the 3D spatial search routine with the\nC search distance set just below and above the theoretically\nC correct distance. The search always begins at the start of\nC structure #101. Thus, the search should first be unsuccessful,\nC and then successful. ISSDIS issues pass or fail as a result\nC of these two searches.\n\nC Input parameters:\nC SISRPX,Y,Z : untransformed search reference point\nC SDIST : correct search distance\nC XFRMT : matrix used to transform search reference point\nC MCLIPI : clipping indicator to be used\nC EXPATH : expected found path\n\n INTEGER MCLIPI\n\n REAL SISRPX,SISRPY,SISRPZ, COSRPX,COSRPY,COSRPZ, SDIST\n REAL XFRMT(4,4)\n\n CHARACTER EXPATH*(*)\n\nC transform search reference point\n CALL ETP3 (SISRPX,SISRPY,SISRPZ, XFRMT, COSRPX,COSRPY,COSRPZ)\n\n CALL ISSAB (COSRPX,COSRPY,COSRPZ, SDIST, '101,0', MCLIPI, 1,\n 1 EXPATH)\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/issab *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE ISSAB (SRPX,SRPY,SRPZ, SDIST, STPATH, MCLIPI, SCEIL,\n 1 EXPATH)\n\nC This subroutine invokes the 3D spatial search routine with the\nC search distance set just below and above the theoretically\nC correct distance. Thus, the search should first be unsuccessful,\nC and then successful. ISSAB issues pass or fail as a result\nC of these two searches.\n\nC Input parameters:\nC SRPX,Y,Z : search reference point\nC SDIST : correct search distance\nC STPATH : starting path\nC MCLIPI : modelling clipping indicator\nC SCEIL : search ceiling\nC EXPATH : expected found path\n\n REAL SRPX,SRPY,SRPZ, SDIST\n\n INTEGER IPTHSZ\n PARAMETER (IPTHSZ = 100)\n\n INTEGER ISTPTH(2,IPTHSZ),ISTLEN, IDUM(2),ERRIND, MCLIPI, SCEIL\n INTEGER IEXPTH(2,IPTHSZ), IEXLEN, FPATH(2,IPTHSZ), FPTHSZ\n\n LOGICAL IAREQL\n\n CHARACTER MSG*200, EXPATH*(*), STPATH*(*)\n\n CALL SETVS (STPATH, ISTPTH, ISTLEN)\n CALL SETVS (EXPATH, IEXPTH, IEXLEN)\n\n CALL PISS3 (SRPX,SRPY,SRPZ, 0.98*SDIST, ISTLEN/2, ISTPTH, MCLIPI,\n 1 SCEIL, 0,IDUM,IDUM,IDUM,IDUM, 0,IDUM,IDUM,IDUM,IDUM,\n 2 IPTHSZ, ERRIND, FPTHSZ, FPATH)\n\n IF (ERRIND .EQ. 0 .AND. FPTHSZ .EQ. 0) THEN\nC OK so far\n ELSE\n CALL FAIL\n WRITE (MSG, '(A,I5,A)') 'ISS did not return null ' //\n 1 'path as expected; error indicator = ', ERRIND, '.'\n CALL INMSG (MSG)\n RETURN\n ENDIF\n\n CALL PISS3 (SRPX,SRPY,SRPZ, 1.02*SDIST, ISTLEN/2, ISTPTH, MCLIPI,\n 1 SCEIL, 0,IDUM,IDUM,IDUM,IDUM, 0,IDUM,IDUM,IDUM,IDUM,\n 2 IPTHSZ, ERRIND, FPTHSZ, FPATH)\n\n IF (ERRIND .EQ. 0 .AND.\n 1 IAREQL (2*FPTHSZ, FPATH, IEXLEN, IEXPTH)) THEN\n CALL PASS\n ELSE\n CALL FAIL\n WRITE (MSG, '(A,I5,A)') 'ISS did not return correct ' //\n 1 'found path; error indicator = ', ERRIND, '.'\n CALL INMSG (MSG)\n ENDIF\n\n END\n\nC *********************************************************\nC * *\nC * SUBROUTINE TR/ispths *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n\n SUBROUTINE ISPTHS (SRPX,SRPY,SRPZ, SDIST, SCEIL, MCLIPI,\n 1 STPTH, EXPTHS)\n\nC This subroutine repeatedly invokes spatial search, using the\nC found path of one search as the starting path for the next, and\nC issues pass or fail, depending on whether the actual paths match\nC those expected.\n\nC Input parameters:\nC SRPX,Y,Z : search reference point to be used in ISS's\nC SDIST : search distance to be used in ISS's\nC SCEIL : search ceiling to be used in ISS's\nC MCLIPI : modelling clipping indicator\nC STPTH : starting path for first ISS\nC EXPTHS : sequence of expected found paths for ISS's\n\n INTEGER EXDIM,IPTHSZ\n PARAMETER (EXDIM = 30, IPTHSZ = 30)\n\n INTEGER EXNUM, EXLEN(EXDIM), EXPATH(EXDIM, EXDIM)\n INTEGER SPSIZ, SPATH(2,IPTHSZ), SCEIL, IDUM(2), IPATH, IX\n INTEGER FPTHSZ, FPATH(2,IPTHSZ), ERRIND, MCLIPI\n\n REAL SRPX,SRPY,SRPZ, SDIST\n\n LOGICAL IAREQL\n\n CHARACTER EXPTHS*(*), STPTH*(*)\n\n CALL SETVS (STPTH, SPATH, SPSIZ)\n SPSIZ = SPSIZ/2\n CALL SET2D (EXPTHS, EXDIM, EXNUM,EXLEN,EXPATH)\n\n DO 100 IPATH = 1,EXNUM\n CALL PISS3 (SRPX,SRPY,SRPZ, SDIST, SPSIZ, SPATH, MCLIPI, SCEIL,\n 1 0,IDUM,IDUM,IDUM,IDUM, 0,IDUM,IDUM,IDUM,IDUM,\n 2 IPTHSZ, ERRIND, FPTHSZ, FPATH)\n IF (ERRIND .EQ. 0 .AND.\n 1 IAREQL (FPTHSZ*2,FPATH, EXLEN(IPATH),EXPATH(1,IPATH))) THEN\nC OK so far - copy found path to next starting path\n SPSIZ = FPTHSZ\n DO 110 IX = 1,SPSIZ\n SPATH(1,IX) = FPATH(1,IX)\n SPATH(2,IX) = FPATH(2,IX)\n110 CONTINUE\n ELSE\n CALL FAIL\n RETURN\n ENDIF\n100 CONTINUE\n CALL PASS\n\n END\n", "meta": {"hexsha": "615e598c75fb7a045144428a32cc5e75fb3764ac", "size": 60853, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "third_party/Phigs/PVT/PVT_fort/trans-sublib.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/trans-sublib.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/trans-sublib.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": 33.7884508606, "max_line_length": 83, "alphanum_fraction": 0.4012949238, "num_tokens": 16924, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972684083608, "lm_q2_score": 0.7634837527911056, "lm_q1q2_score": 0.6646868696541007}} {"text": "Module rand_num_gen\n ! This module will contain a routine to generate random numbers\n !\n ! This is taken from numerical recipes for F90\n !\n ! It has been modified slightly to make it easily used. The basic workings\n ! of it have not been changed in any way.\n !\n ! The variable names don't seem to have a lot of meaning (I simply copied\n ! them from Numerical Recipes)\n use precision\n \n implicit none\n integer(idp), save, private :: idum=-1, ix=-1, iy=-1, c\n real(fdp), save, private :: am\n \ncontains\n function random_num(init) result(number)\n ! This function returns a rantom number. The optional input init, tells\n ! the random number generator to re-initialise, if the user desires.\n integer(idp), optional, intent(in) :: init\n real(fdp) :: number\n integer(idp), parameter :: ia=16807, im=2147483647, iq=127773, ir=2836\n if (present(init)) then\n \n idum=init\n end if\n if (idum<=0 .or. iy < 0) then\n \n am=nearest(1.0,-1.0)/im\n iy=ior(ieor(888889999,abs(idum)),1)\n ix=ieor(777755555,abs(idum))\n idum=abs(idum)+1\n end if\n ix=ieor(ix,ishft(ix,13))\n ix=ieor(ix,ishft(ix,-17))\n ix=ieor(ix,ishft(ix,5))\n c=iy/iq\n iy=ia*(iy-c*iq)-ir*c\n if (iy < 0) iy=iy+im\n number=am*ior(iand(im,ieor(ix,iy)),1)\n end function random_num\nend module rand_num_gen\n", "meta": {"hexsha": "b76590933dc0835d69e37b982abc81ea083a5b0c", "size": 1355, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "rand_num_gen_module.f90", "max_stars_repo_name": "sdm900/quantum_chaos", "max_stars_repo_head_hexsha": "d82b8b3e8108a8de72cc4f86e73eb9d6583b26ec", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "rand_num_gen_module.f90", "max_issues_repo_name": "sdm900/quantum_chaos", "max_issues_repo_head_hexsha": "d82b8b3e8108a8de72cc4f86e73eb9d6583b26ec", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "rand_num_gen_module.f90", "max_forks_repo_name": "sdm900/quantum_chaos", "max_forks_repo_head_hexsha": "d82b8b3e8108a8de72cc4f86e73eb9d6583b26ec", "max_forks_repo_licenses": ["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.7954545455, "max_line_length": 78, "alphanum_fraction": 0.6442804428, "num_tokens": 440, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972549785201, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6646868640858361}} {"text": " SUBROUTINE trigfunc (uang, vang, cosm, sinm, cosn, sinn, \n 1 mpol, ntor, nznt)\n USE stel_kinds\n USE booz_params, ONLY: nfp\nC-----------------------------------------------\nC D u m m y A r g u m e n t s\nC-----------------------------------------------\n INTEGER, INTENT(in) :: mpol, ntor, nznt\n REAL(rprec), DIMENSION(nznt), INTENT(in) :: uang, vang\n REAL(rprec), DIMENSION(nznt,0:mpol), INTENT(out) :: cosm, sinm\n REAL(rprec), DIMENSION(nznt,0:ntor), INTENT(out) :: cosn, sinn\nC-----------------------------------------------\nC L o c a l V a r i a b l e s\nC-----------------------------------------------\n INTEGER :: m, n\nC-----------------------------------------------\n\n cosm(:,0) = 1\n sinm(:,0) = 0\n cosm(:,1) = COS(uang)\n sinm(:,1) = SIN(uang)\n\n DO m = 2,mpol\n cosm(:,m) = cosm(:,m-1)*cosm(:,1)\n 1 - sinm(:,m-1)*sinm(:,1)\n sinm(:,m) = sinm(:,m-1)*cosm(:,1)\n 1 + cosm(:,m-1)*sinm(:,1)\n END DO\n\n cosn(:,0) = 1\n sinn(:,0) = 0\n IF (ntor .ge. 1) THEN\n cosn(:,1) = COS(vang*nfp)\n sinn(:,1) = SIN(vang*nfp)\n END IF\n\n DO n = 2,ntor\n cosn(:,n) = cosn(:,n-1)*cosn(:,1)\n 1 - sinn(:,n-1)*sinn(:,1)\n sinn(:,n) = sinn(:,n-1)*cosn(:,1)\n 1 + cosn(:,n-1)*sinn(:,1)\n END DO\n\n END SUBROUTINE trigfunc\n", "meta": {"hexsha": "2f9bdeaebc85ba208633a63a7d62a706a4ccb01c", "size": 1435, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Sources/trigfunc.f", "max_stars_repo_name": "ORNL-Fusion/BOOZ_XFORM", "max_stars_repo_head_hexsha": "e8386b2d8d701ab40ae3f32803c02783efbb3b36", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Sources/trigfunc.f", "max_issues_repo_name": "ORNL-Fusion/BOOZ_XFORM", "max_issues_repo_head_hexsha": "e8386b2d8d701ab40ae3f32803c02783efbb3b36", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Sources/trigfunc.f", "max_forks_repo_name": "ORNL-Fusion/BOOZ_XFORM", "max_forks_repo_head_hexsha": "e8386b2d8d701ab40ae3f32803c02783efbb3b36", "max_forks_repo_licenses": ["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.8888888889, "max_line_length": 68, "alphanum_fraction": 0.3770034843, "num_tokens": 486, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.7490872243177518, "lm_q1q2_score": 0.6645936220413566}} {"text": " SUBROUTINE CHFDV(X1,X2,F1,F2,D1,D2,NE,XE,FE,DE,NEXT,IERR)\n USE stel_kinds\n IMPLICIT NONE\n!- ----------------------------------------------\n! D u m m y A r g u m e n t s\n!- ----------------------------------------------\n INTEGER :: NE, IERR\n REAL(rprec):: X1, X2, F1, F2, D1, D2\n INTEGER, DIMENSION(2) :: NEXT\n REAL(rprec), DIMENSION(NE) :: XE, FE, DE\n!- ----------------------------------------------\n! L o c a l V a r i a b l e s\n!- ----------------------------------------------\n INTEGER :: I\n REAL(rprec) :: C2,C2T2,C3,C3T3,DEL1,DEL2,DELTA,H,\n 1 X,XMI,XMA,ZERO\n!- ----------------------------------------------\n!* **BEGIN PROLOGUE CHFDV\n!* **DATE WRITTEN 811019 (YYMMDD)\n!* **REVISION DATE 870707 (YYMMDD)\n!* **CATEGORY NO. E3,H1\n!* **KEYWORDS LIBRARY=SLATEC(PCHIP),\n! TYPE=SINGLE PRECISION(CHFDV-S DCHFDV-D),\n! CUBIC HERMITE DIFFERENTIATION,CUBIC HERMITE EVALUATION,\n! CUBIC POLYNOMIAL EVALUATION\n!* **AUTHOR FRITSCH, F. N., (LLNL)\n! MATHEMATICS AND STATISTICS DIVISION\n! LAWRENCE LIVERMORE NATIONAL LABORATORY\n! P.O. BOX 808 (L-316)\n! LIVERMORE, CA 94550\n! FTS 532-4275, (415) 422-4275\n!* **PURPOSE Evaluate a cubic polynomial given in Hermite form and its\n! first derivative at an array of points. While designed for\n! USE by PCHFD, it may be USEful directly as an evaluator for\n! a piecewise cubic Hermite FUNCTION in applications, such as\n! graphing, WHERE the interval is known in advance.\n! If ONLY FUNCTION values are required, USE CHFEV instead.\n!* **DESCRIPTION\n!\n! CHFDV: Cubic Hermite Function and Derivative Evaluator\n!\n! Evaluates the cubic polynomial determined by FUNCTION values\n! F1,F2 and derivatives D1,D2 on interval (X1,X2), together with\n! its first derivative, at the points XE(J), J=1(1)NE.\n!\n! If ONLY FUNCTION values are required, USE CHFEV, instead.\n!\n! ----------------------------------------------------------------------\n!\n! Calling sequence:\n!\n! INTEGER NE, NEXT(2), IERR\n! REAL X1, X2, F1, F2, D1, D2, XE(NE), FE(NE), DE(NE)\n!\n! CALL CHFDV (X1,X2, F1,F2, D1,D2, NE, XE, FE, DE, NEXT, IERR)\n!\n! Parameters:\n!\n! X1,X2 -- (input) ENDpoints of interval of definition of cubic.\n! (Error RETURN IF X1.EQ.X2 .)\n!\n! F1,F2 -- (input) values of FUNCTION at X1 and X2, respectively.\n!\n! D1,D2 -- (input) values of derivative at X1 and X2, respectively.\n!\n! NE -- (input) number of evaluation points. (Error RETURN IF\n! NE.LT.1 .)\n!\n! XE -- (input) REAL array of points at which the functions are to\n! be evaluated. If ANY of the XE are outside the interval\n! [X1,X2], a warning error is returned in NEXT.\n!\n! FE -- (output) REAL array of values of the cubic FUNCTION defined\n! by X1,X2, F1,F2, D1,D2 at the points XE.\n!\n! DE -- (output) REAL array of values of the first derivative of\n! the same FUNCTION at the points XE.\n!\n! NEXT -- (output) INTEGER array indicating number of extrapolation\n! points:\n! NEXT(1) = number of evaluation points to left of interval.\n! NEXT(2) = number of evaluation points to right of interval.\n!\n! IERR -- (output) error flag.\n! Normal RETURN:\n! IERR = 0 (no errors).\n! \"Recoverable\" errors:\n! IERR = -1 IF NE.LT.1 .\n! IERR = -2 IF X1.EQ.X2 .\n! (Output arrays have not been changed in either CASE.)\n!\n!* **REFERENCES (NONE)\n!* **END PROLOGUE CHFDV\n!\n! ----------------------------------------------------------------------\n!\n! Change record:\n! 82-08-03 Minor cosmetic changes for release 1.\n!\n! ----------------------------------------------------------------------\n!\n! Programming notes:\n!\n! To produce a Double precision version, simply:\n! a. Change CHFDV to DCHFDV wherever it occurs,\n! b. Change the Real declaration to Double precision,\n! c. Change the constant ZERO to Double precision, and\n! d. Change the names of the Fortran functions: MAX, MIN.\n!\n! DECLARE ARGUMENTS.\n!\n!\n! DECLARE LOCAL VARIABLES.\n!\n DATA ZERO/0/\n!\n! VALIDITY-CHECK ARGUMENTS.\n!\n!* **FIRST EXECUTABLE STATEMENT CHFDV\n IF (NE >= 1) THEN\n H = X2 - X1\n IF (H == ZERO) GO TO 5002\n!\n! INITIALIZE.\n!\n IERR = 0\n NEXT(1) = 0\n NEXT(2) = 0\n XMI = MIN(ZERO,H)\n XMA = MAX(ZERO,H)\n!\n! COMPUTE CUBIC COEFFICIENTS (EXPANDED ABOUT X1).\n!\n DELTA = (F2 - F1)/H\n DEL1 = (D1 - DELTA)/H\n DEL2 = (D2 - DELTA)/H\n! (DELTA IS NO LONGER NEEDED.)\n C2 = -(DEL1 + DEL1 + DEL2)\n C2T2 = C2 + C2\n C3 = (DEL1 + DEL2)/H\n! (H, DEL1 AND DEL2 ARE NO LONGER NEEDED.)\n C3T3 = C3 + C3 + C3\n!\n! EVALUATION LOOP.\n!\n DO I = 1, NE\n X = XE(I) - X1\n FE(I) = F1 + X*(D1 + X*(C2 + X*C3))\n DE(I) = D1 + X*(C2T2 + X*C3T3)\n! COUNT EXTRAPOLATION POINTS.\n IF (X < XMI) NEXT(1) = NEXT(1) + 1\n IF (X > XMA) NEXT(2) = NEXT(2) + 1\n! (NOTE REDUNDANCY--IF EITHER CONDITION IS TRUE, OTHER IS FALSE.)\n END DO\n!\n! NORMAL RETURN.\n!\n RETURN\n!\n! ERROR RETURNS.\n!\n ENDIF\n! NE.LT.1 RETURN.\n IERR = -1\n STOP 'CHFDV -- NUMBER OF EVALUATION POINTS LESS THAN ONE'\n RETURN\n!\n 5002 CONTINUE\n! X1.EQ.X2 RETURN.\n IERR = -2\n STOP 'CHFDV -- INTERVAL ENDPOINTS EQUAL'\n\n END SUBROUTINE CHFDV\n", "meta": {"hexsha": "4b7f9557da8e1cea354e9ceb0b9d2cfcf580841f", "size": 5731, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "LIBSTELL/Sources/Miscel/CHFDV.f", "max_stars_repo_name": "jonathanschilling/VMEC_8_00", "max_stars_repo_head_hexsha": "25519df38bf81bcb673dd9374bda11988de2d940", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "LIBSTELL/Sources/Miscel/CHFDV.f", "max_issues_repo_name": "jonathanschilling/VMEC_8_00", "max_issues_repo_head_hexsha": "25519df38bf81bcb673dd9374bda11988de2d940", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "LIBSTELL/Sources/Miscel/CHFDV.f", "max_forks_repo_name": "jonathanschilling/VMEC_8_00", "max_forks_repo_head_hexsha": "25519df38bf81bcb673dd9374bda11988de2d940", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.9367816092, "max_line_length": 72, "alphanum_fraction": 0.5163147793, "num_tokens": 1736, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8872045877523148, "lm_q2_score": 0.7490872187162397, "lm_q1q2_score": 0.6645936170716695}} {"text": "!\tAsymptotic covariance matrix of matrix inverse of symmetric matrix.\r\n!\tInput is matrix mat, its inverse matinv and its covariance matrix covmat.\r\n!\tOutput is the asymptotic covariance matrix of matinv.\r\nfunction covmatinv(mat,matinv,covmat)\r\nimplicit none\r\nreal(kind=8),intent(in)::mat(:,:),matinv(:,:),covmat(:,:,:,:)\r\nreal(kind=8)::covmatinv(size(mat,1),size(mat,1),size(mat,1),size(mat,1))\r\n! Indices i,j,k,l,m,n,o,p and array size s.\r\ninteger::i,j,k,l,m,n,o,p,s\r\ns=size(mat,1)\r\ncovmatinv=0.0_8\r\ndo i=1,s\r\n do j=1,s\r\n do k=1,s\r\n do l=1,s\r\n do m=1,s\r\n do n=1,s\r\n\t\t\t\t\t\tdo o=1,s\r\n\t\t\t\t\t\t\tdo p=1,s\r\n\t\t\t\t\t\t\t\tcovmatinv(i,j,k,l)=covmatinv(i,j,k,l)+matinv(i,m)*matinv(k,n)*matinv(j,o)*matinv(l,p)*covmat(m,o,n,p)\r\n\t\t\t\t\t\t\tend do\r\n\t\t\t\t\t\tend do\r\n end do\r\n end do\r\n \r\n end do\r\n \r\n end do\r\n\t\t\r\n end do\r\n\r\nend do\r\nreturn\r\nend function covmatinv\r\n", "meta": {"hexsha": "38796ba490b0a3d7383380cef1dafcfd60486472", "size": 970, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Source/covmatinv.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/covmatinv.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/covmatinv.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": 27.7142857143, "max_line_length": 110, "alphanum_fraction": 0.5453608247, "num_tokens": 292, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896802383028, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.664573701652042}} {"text": "! *********************************************************************\r\n! * *\r\n! * subroutine dcvmt3 *\r\n! * *\r\n! *********************************************************************\r\n! Double Precision Version 1.0\r\n! Written by Gordon A. Fenton, TUNS, July 17, 1992\r\n!\r\n! PURPOSE computes the covariance matrices between local averages needed\r\n! by LAS3G for all stages of the subdivision.\r\n!\r\n! This routine computes the three covariance matrices, R (27x27), B (8x8),\r\n! and S (27x8), required by LAS3G. The matrices R and B represent the\r\n! covariances between a 3 x 3 x 3 array of equal sized local average elements\r\n! and a 2 x 2 x 2 subarray respectively, numbered as follows for the first\r\n! plane only (in the depth or Z direction, the numbering is similar; ie the\r\n! element behind element 1 of the R array is element number 10, etc.);\r\n!\r\n! |-- Dx--| R Array B Array\r\n! --- ------------------------- -------------------------\r\n! | | | | | | | | |\r\n! Dy | 7 | 8 | 9 | | | | |\r\n! | | | | | | | | |\r\n! --- ------------------------- -------------------------\r\n! | | | | | | | |\r\n! | 4 | 5 | 6 | | 3 | 4 | |\r\n! | | | | | | | |\r\n! ------------------------- -------------------------\r\n! | | | | | | | |\r\n! | 1 | 2 | 3 | | 1 | 2 | |\r\n! | | | | | | | |\r\n! ------------------------- -------------------------\r\n!\r\n! Figure 1\r\n!\r\n! Notice that the array B is just equal to selected elements of the array R\r\n! (ie. B(1,1) = R(1,1), B(1,4) = R(1,5), etc.). S represents the 27x8\r\n! covariance matrix between a doubly large array and an interior subdivided\r\n! 2 x 2 x 2 array as shown, where the numbering of the larger array is the\r\n! same as on the left in Figure 1.\r\n!\r\n! |--2Dx--|\r\n! --- -------------------------\r\n! | | | | |\r\n! 2Dy | | | |\r\n! | | | | |\r\n! --- -------------------------\r\n! | | 3 | 4 | |\r\n! | |-------| | Figure 2\r\n! | | 1 | 2 | |\r\n! -------------------------\r\n! | | | |\r\n! | | | |\r\n! | | | |\r\n! -------------------------\r\n!\r\n! Finally note that the random process is assumed to be quadrant symmetric\r\n! (that is the covariance function is even in each individual lag component)\r\n! to reduce the total number of covariance calculations.\r\n!\r\n! Arguments to this routine are as follows;\r\n!\r\n! dvfn external double precision function which returns the\r\n! variance of a local average of size X x Y x Z. This function\r\n! is referenced using the call \"V = dvfn(X,Y,Z)\" (other\r\n! parameters to the function must be passed via common blocks).\r\n!\r\n! R double precision array of size at least 27 x 27 which on output\r\n! will contain the covariance matrix between the local average\r\n! elements shown above in Figure 1, left. Note that since R is\r\n! symmetric, only the upper triangular values are actually\r\n! stored (this is to be compatible with DFACLD). (output)\r\n!\r\n! ir leading dimension of the array R as specified in the calling\r\n! routine. (input)\r\n!\r\n! B double precision vector of length at least 8 which on output\r\n! will contain the essential elements of the covariance matrix\r\n! between the local average elements shown above in Figure 1,\r\n! right (upper triangle only). (output)\r\n!\r\n! S double precision array of size at least 27 x 8 which on output\r\n! will contain the covariances between the set of subdivided\r\n! central elements and the parent 3 x 3 x 3 set of doubly\r\n! large elements (see Figure 2). (output)\r\n!\r\n! is leading dimension of the array S as specified in the calling\r\n! routine. (input)\r\n!\r\n! Dx x-dimension of the subdivided elements. The dimension of the\r\n! parent elements is assumed to be 2*Dx. (input)\r\n!\r\n! Dy y-dimension of the subdivided elements. The dimension of the\r\n! parent elements is assumed to be 2*Dy. (input)\r\n!\r\n! Dz z-dimension of the subdivided elements. The dimension of the\r\n! parent elements is assumed to be 2*Dz. (input)\r\n!\r\n! lformR logical flag which is true if the matrix R is to be formed\r\n! (in some cases, only the smaller matrix B is required). (input)\r\n!----------------------------------------------------------------------------\r\n subroutine dcvmt3( dvfn, R, ir, B, ib, S, is, Dx, Dy, Dz, lformR )\r\n implicit real*8 (a-h,o-z)\r\n dimension R(ir,*), B(ib,*), S(is,*)\r\n dimension T(3)\r\n integer map(5)\r\n logical lformR\r\n external dvfn\r\n data zero/0.d0/, half/0.5d0/, one/1.d0/, onept5/1.5d0/\r\n data two/2.d0/, twopt5/2.5d0/\r\n data T/ 1.5d0, 0.5d0, 2.5d0 /\r\n data map/1, -1, 0, -1, 2/\r\n!\t\t\t\t\tfirst find B's essential elements\r\n B(1,1) = dcvaa3(dvfn,Dx,Dy,Dz,zero,zero,zero)\r\n B(1,2) = dcvaa3(dvfn,Dx,Dy,Dz, one,zero,zero)\r\n B(1,3) = dcvaa3(dvfn,Dx,Dy,Dz,zero, one,zero)\r\n B(1,4) = dcvaa3(dvfn,Dx,Dy,Dz, one, one,zero)\r\n B(1,5) = dcvaa3(dvfn,Dx,Dy,Dz,zero,zero, one)\r\n B(1,6) = dcvaa3(dvfn,Dx,Dy,Dz, one,zero, one)\r\n B(1,7) = dcvaa3(dvfn,Dx,Dy,Dz,zero, one, one)\r\n B(1,8) = dcvaa3(dvfn,Dx,Dy,Dz, one, one, one)\r\n!\t\t\t\t\t\tfill in the upper triangle\r\n do 20 n = 2, 8\r\n n3 = (n-1)/4\r\n n2 = (n - 4*n3 - 1)/2\r\n do 10 m = 2, n\r\n m3 = (m-1)/4\r\n m2 = (m - 4*m3 - 1)/2\r\n i3 = m3 - n3\r\n i2 = m2 - n2\r\n i1 = (m-n) - 2*i2 - 4*i3\r\n k = 1 + iabs(i1) + 2*iabs(i2) + 4*iabs(i3)\r\n B(m,n) = B(1,k)\r\n 10 continue\r\n 20 continue\r\n\r\n!\t\t\t\t\tnow find R optionally (upper triangle)\r\n if( lformR ) then\r\n!\t\t\t\t\t\tessential elements first ...\r\n R(1, 1) = B(1,1)\r\n R(1, 2) = B(1,2)\r\n R(1, 3) = dcvaa3(dvfn,Dx,Dy,Dz, two, zero, zero )\r\n R(1, 4) = B(1,3)\r\n R(1, 5) = B(1,4)\r\n R(1, 6) = dcvaa3(dvfn,Dx,Dy,Dz, two, one, zero )\r\n R(1, 7) = dcvaa3(dvfn,Dx,Dy,Dz, zero, two, zero )\r\n R(1, 8) = dcvaa3(dvfn,Dx,Dy,Dz, one, two, zero )\r\n R(1, 9) = dcvaa3(dvfn,Dx,Dy,Dz, two, two, zero )\r\n R(1,10) = B(1,5)\r\n R(1,11) = B(1,6)\r\n R(1,12) = dcvaa3(dvfn,Dx,Dy,Dz, two, zero, one )\r\n R(1,13) = B(1,7)\r\n R(1,14) = B(1,8)\r\n R(1,15) = dcvaa3(dvfn,Dx,Dy,Dz, two, one, one )\r\n R(1,16) = dcvaa3(dvfn,Dx,Dy,Dz, zero, two, one )\r\n R(1,17) = dcvaa3(dvfn,Dx,Dy,Dz, one, two, one )\r\n R(1,18) = dcvaa3(dvfn,Dx,Dy,Dz, two, two, one )\r\n R(1,19) = dcvaa3(dvfn,Dx,Dy,Dz, zero, zero, two )\r\n R(1,20) = dcvaa3(dvfn,Dx,Dy,Dz, one, zero, two )\r\n R(1,21) = dcvaa3(dvfn,Dx,Dy,Dz, two, zero, two )\r\n R(1,22) = dcvaa3(dvfn,Dx,Dy,Dz, zero, one, two )\r\n R(1,23) = dcvaa3(dvfn,Dx,Dy,Dz, one, one, two )\r\n R(1,24) = dcvaa3(dvfn,Dx,Dy,Dz, two, one, two )\r\n R(1,25) = dcvaa3(dvfn,Dx,Dy,Dz, zero, two, two )\r\n R(1,26) = dcvaa3(dvfn,Dx,Dy,Dz, one, two, two )\r\n R(1,27) = dcvaa3(dvfn,Dx,Dy,Dz, two, two, two )\r\n!\t\t\t\t\t\tdistribute into upper triangle\r\n do 40 n = 2, 27\r\n n3 = (n-1)/9\r\n n2 = (n - 9*n3 - 1)/3\r\n do 30 m = 2, n\r\n m3 = (m-1)/9\r\n m2 = (m - 9*m3 - 1)/3\r\n i3 = m3 - n3\r\n i2 = m2 - n2\r\n i1 = (m-n) - 3*i2 - 9*i3\r\n k = 1 + iabs(i1) + 3*iabs(i2) + 9*iabs(i3)\r\n R(m,n) = R(1,k)\r\n 30 continue\r\n 40 continue\r\n endif\r\n!\t\t\t\t\tnow find S (essential elements first)\r\n ii = 1\r\n do 50 k = 1, 3\r\n do 50 j = 1, 3\r\n S(ii, 1) = dcvab3(dvfn,Dx,Dy,Dz,onept5,T(j),T(k))\r\n S(ii+1,1) = dcvab3(dvfn,Dx,Dy,Dz,half, T(j),T(k))\r\n S(ii+2,1) = dcvab3(dvfn,Dx,Dy,Dz,twopt5,T(j),T(k))\r\n ii = ii + 3\r\n 50 continue\r\n!\t\t\t\t\tand distribute to remainder of S\r\n do 70 n = 2, 8\r\n n3 = (n-1)/4\r\n n2 = (n - 4*n3 - 1)/2\r\n do 60 m = 1, 27\r\n m3 = (m-1)/9\r\n m2 = (m - 9*m3 - 1)/3\r\n i3 = iabs(4*m3 - 2*n3 - 3)\r\n i2 = iabs(4*m2 - 2*n2 - 3)\r\n i1 = iabs(4*m - 12*m2 - 36*m3 - 2*n + 4*n2 + 8*n3 - 5)\r\n k = 1 + map(i1) + 3*map(i2) + 9*map(i3)\r\n S(m,n) = S(k,1)\r\n 60 continue\r\n 70 continue\r\n\r\n return\r\n end\r\n", "meta": {"hexsha": "8a3f97d0cb4d1c669e24f6b7568012989423ec73", "size": 9633, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/libs/gaf95/dcvmt3.f95", "max_stars_repo_name": "leemargetts/PoreFEM", "max_stars_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/libs/gaf95/dcvmt3.f95", "max_issues_repo_name": "leemargetts/PoreFEM", "max_issues_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/libs/gaf95/dcvmt3.f95", "max_forks_repo_name": "leemargetts/PoreFEM", "max_forks_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.3125, "max_line_length": 80, "alphanum_fraction": 0.4163811897, "num_tokens": 3094, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896824119663, "lm_q2_score": 0.7217431943271999, "lm_q1q2_score": 0.6645736866875405}} {"text": "\tFUNCTION CCuij(UU,VV)\nC ===============================================================\nC\tCorrelation coefficient between two (3x3) anisotropic \nC\tdisplacement matrices Uij and Vij.\nC\tSee Merritt (1999) Acta Crystallographica D55, 1997-2004.\nC\tReturn 0 if any of the tensors involved are NPD\nC ===============================================================\n\tREAL CCuij V3VINV\n\tREAL UU(3,3), VV(3,3), WW(3,3), UI(3,3), VI(3,3), WI(3,3)\n\tREAL DUI, DVI, DWI\n\tDUI = 1. / V3INV(UI,UU)\n\tDVI = 1. / V3INV(VI,VV)\nC\tSylvester's criterion for NPD tensor\n\tIF (DUI.LE.0 .OR. UU(1,1).LE.0 \n & .OR. (UU(1,1)*UU(2,2)-UU(1,2)*UU(2,1)).LE.0) THEN\n\t\tCCuij = 0\n\t\tRETURN\n\tENDIF\n\tIF (DVI.LE.0 .OR. VV(1,1).LE.0 \n & .OR. (VV(1,1)*VV(2,2)-VV(1,2)*VV(2,1)).LE.0) THEN\n\t\tCCuij = 0\n\t\tRETURN\n\tENDIF\n\tCALL M3ADD(WI,UI,VI)\n\tDWI = V3INV(WW,WI)\n\tIF (DWI.LE.0 .OR. WW(1,1).LE.0\n & .OR. (WW(1,1)*WW(2,2)-WW(1,2)*WW(2,1)).LE.0) THEN\n\t\tCCuij = 0\n\t\tRETURN\n\tENDIF\n\tCCuij \t= sqrt(sqrt(DUI*DVI))\n &\t\t/ sqrt(0.125*DWI)\n\tRETURN\n\tEND\n\n\n\tFUNCTION CCuv(U,V)\nC ===============================================================\nC\tWrapper for CCuij()\nC ===============================================================\n\tREAL CCuv, CCuij\n\tREAL U(6), V(6)\n\tREAL UU(3,3), VV(3,3)\n\tUU(1,1) = U(1)\n\tUU(2,2) = U(2)\n\tUU(3,3) = U(3)\n\tUU(1,2) = U(4)\n\tUU(2,1) = U(4)\n\tUU(1,3) = U(5)\n\tUU(3,1) = U(5)\n\tUU(2,3) = U(6)\n\tUU(3,2) = U(6)\n\tVV(1,1) = V(1)\n\tVV(2,2) = V(2)\n\tVV(3,3) = V(3)\n\tVV(1,2) = V(4)\n\tVV(2,1) = V(4)\n\tVV(1,3) = V(5)\n\tVV(3,1) = V(5)\n\tVV(2,3) = V(6)\n\tVV(3,2) = V(6)\n\tCCuv = CCuij(UU,VV)\n\tRETURN\n\tEND\n\n\tFUNCTION Suv(U,V)\nC ===============================================================\nC\tNormalized correlation coefficient (\"similarity\") between two\nC\tanisotropic displacement vectors Uij and Vij.\nC\tSee Merritt (1999) Acta Crystallographica D55, 1997-2004.\nC ===============================================================\n\tREAL Suv, CCuij\n\tREAL U(6), V(6)\n\tREAL UU(3,3), VV(3,3), Uiso(3,3), Viso(3,3), WW(3,3)\n\tREAL Ueq, Veq\n\tUU(1,1) = U(1)\n\tUU(2,2) = U(2)\n\tUU(3,3) = U(3)\n\tUU(1,2) = U(4)\n\tUU(2,1) = U(4)\n\tUU(1,3) = U(5)\n\tUU(3,1) = U(5)\n\tUU(2,3) = U(6)\n\tUU(3,2) = U(6)\n\tVV(1,1) = V(1)\n\tVV(2,2) = V(2)\n\tVV(3,3) = V(3)\n\tVV(1,2) = V(4)\n\tVV(2,1) = V(4)\n\tVV(1,3) = V(5)\n\tVV(3,1) = V(5)\n\tVV(2,3) = V(6)\n\tVV(3,2) = V(6)\n\tUeq = (UU(1,1) + UU(2,2) + UU(3,3)) / 3.\n\tVeq = (VV(1,1) + VV(2,2) + VV(3,3)) / 3.\n\tDO I = 1,3\n\tDO J = 1,3\n\t\tWW(I,J) = VV(I,J) * Ueq / Veq\n\t\tUiso(I,J) = 0\n\t\tViso(I,J) = 0\n\tENDDO\n\tENDDO\n\tDO I = 1,3\n\t\tUiso(I,I) = Ueq\n\t\tViso(I,I) = Veq\n\tENDDO\n\tSuv_top = CCuij(UU,WW)\n\tSuv_bot = (CCuij(UU,Uiso) * CCuij(VV,Viso))\n\tif (Suv_top.eq.0 .or. Suv_bot.eq.0) then\n\t\tSuv = 0\n\telse\n\t\tSuv = Suv_top / Suv_bot\n\tendif\n\tRETURN\n\tEND\n\nC\t=======================================================\nC\tThe rest of the file is just generic 3x3 matrix algebra\nC\t=======================================================\n\n\tSUBROUTINE V3CROSS(B,C,A)\nC\tCROSS PRODUCT OF TWO VECTORS\nC\t=======================\n\tREAL A(3),B(3),C(3)\n\tA(1)=B(2)*C(3)-C(2)*B(3)\n\tA(2)=B(3)*C(1)-C(3)*B(1)\n\tA(3)=B(1)*C(2)-C(1)*B(2)\n\tRETURN\n\tEND\nC\n\tFUNCTION V3DOT(A,B)\nC\tDOT PRODUCT OF TWO VECTORS\nC\t================\n\tREAL A(3),B(3)\n\tV3DOT=A(1)*B(1)+A(2)*B(2)+A(3)*B(3)\n\tRETURN\n\tEND\nC\n\tSUBROUTINE M3ADD(A,B,C)\nC\tA=B+C\nC\t========================\n\tREAL A(3,3),B(3,3),C(3,3)\n\tDO I=1,3\n\tDO J=1,3\n\t A(I,J) = B(I,J) + C(I,J)\n\tENDDO\n\tENDDO\n\tRETURN\n\tEND\nC\n\tSUBROUTINE M3MUL(A,B,C)\nC\tA=B*C\nC\t========================\n\tREAL A(3,3),B(3,3),C(3,3),S\n\tDO I=1,3\n\tDO J=1,3\n\t S=0\n\t DO K=1,3\n\t S=S+B(I,K)*C(K,J)\n\t ENDDO\n\t A(I,J)=S\n\tENDDO\n\tENDDO\n\tRETURN\n\tEND\nC\n\tFUNCTION V3INV(A,B)\nC\tINVERT A GENERAL 3X3 MATRIX AND RETURN DETERMINANT\nC\tA=(B)-1\nC\t======================\n\tREAL A(3,3),B(3,3),C(3,3),D\n\tCALL V3CROSS(B(1,2),B(1,3),C(1,1))\n\tCALL V3CROSS(B(1,3),B(1,1),C(1,2))\n\tCALL V3CROSS(B(1,1),B(1,2),C(1,3))\n\tD=V3DOT(B(1,1),C(1,1))\n\tIF (ABS(D).LE.1.E-30) THEN\n\t V3INV=0.0\n\t RETURN\n\tENDIF\n\tDO I=1,3\n\tDO J=1,3\n\t A(I,J)=C(J,I)/D\n\tENDDO\n\tENDDO\n\tV3INV=D\n\tRETURN\n\tEND\nC\n", "meta": {"hexsha": "65c1bc501f84151d6b67cd369422cde662751a85", "size": 4024, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "suv.f", "max_stars_repo_name": "wkpark/raster3d", "max_stars_repo_head_hexsha": "1fc0f8e363c6c5a63a9fe64e7adeb4f2538bacb3", "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": "suv.f", "max_issues_repo_name": "wkpark/raster3d", "max_issues_repo_head_hexsha": "1fc0f8e363c6c5a63a9fe64e7adeb4f2538bacb3", "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": "suv.f", "max_forks_repo_name": "wkpark/raster3d", "max_forks_repo_head_hexsha": "1fc0f8e363c6c5a63a9fe64e7adeb4f2538bacb3", "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": 21.291005291, "max_line_length": 71, "alphanum_fraction": 0.4686878728, "num_tokens": 1957, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896780646393, "lm_q2_score": 0.7217431943271999, "lm_q1q2_score": 0.6645736835498868}} {"text": " subroutine ero_pkq\n \n!! ~ ~ ~ PURPOSE ~ ~ ~\n!! this subroutine computes the peak runoff rate for each HRU\n!! and the entire subbasin using a modification of the rational formula\n\n!! ~ ~ ~ INCOMING VARIABLES ~ ~ ~\n!! name |units |definition\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\n!! hru_km(:) |km^2 |area of HRU in square kilometers\n!! ihru |none |HRU number\n!! tconc(:) |hr |time of concentration for HRU\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\n\n!! ~ ~ ~ OUTGOING VARIABLES ~ ~ ~\n!! name |units |definition\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\n!! peakr |m^3/s |peak runoff rate\n!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\n!! ~ ~ ~ SUBROUTINES/FUNCTIONS CALLED ~ ~ ~\n!! Intrinsic: Log, Expo\n\n!! ~ ~ ~ ~ ~ ~ END SPECIFICATIONS ~ ~ ~ ~ ~ ~\n\n use hru_module, only: hru, tconc, ihru, peakr, qday\n use hydrograph_module\n use climate_module\n \n implicit none\n\n integer :: j !none |HRU number\n real :: altc ! |\n real :: expo ! | \n integer :: iob ! | \n \n j = ihru\n iob = hru(j)%obj_no\n iwst = ob(iob)%wst\n \n altc = 1. - expo(2. * tconc(j) * Log(1. - wst(iwst)%weat%precip_half_hr))\n peakr = altc * qday / tconc(j) !! mm/h\n peakr = peakr * hru(j)%km / 3.6 !! m^3/s\n\n return\n end subroutine ero_pkq", "meta": {"hexsha": "594cf51a460f51c0555199372cd3becbfb820c4e", "size": 1662, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/data/program_analysis/multifile_multimod/mfmm_02/ero_pkq.f90", "max_stars_repo_name": "mikiec84/delphi", "max_stars_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2018-03-03T11:57:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-16T21:19:54.000Z", "max_issues_repo_path": "tests/data/program_analysis/multifile_multimod/mfmm_02/ero_pkq.f90", "max_issues_repo_name": "mikiec84/delphi", "max_issues_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 385, "max_issues_repo_issues_event_min_datetime": "2018-02-21T16:52:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-17T07:44:56.000Z", "max_forks_repo_path": "tests/data/program_analysis/multifile_multimod/mfmm_02/ero_pkq.f90", "max_forks_repo_name": "mikiec84/delphi", "max_forks_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2018-03-20T01:08:11.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-29T01:04:49.000Z", "avg_line_length": 36.9333333333, "max_line_length": 79, "alphanum_fraction": 0.389290012, "num_tokens": 558, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896693699844, "lm_q2_score": 0.7217431943271999, "lm_q1q2_score": 0.6645736772745788}} {"text": "program pointer_remap_array\r\nimplicit none\r\ninteger, parameter :: n = 6\r\ninteger, target :: a1d(n)\r\ninteger, pointer :: a2d(:,:)\r\ninteger :: i,i1,iter\r\na1d = [(10*i,i=1,n)]\r\nprint \"('a1d =',/,*(i4))\",a1d\r\ndo iter=1,2\r\n print*\r\n if (iter == 1) then \r\n! map a1d to array with lower bounds 1, 1\r\n a2d(1:3,1:2) => a1d\r\n print*,\"a2d(1:3,1:2) => a1d\"\r\n else\r\n! map a1d to array with lower bounds -1, 1\r\n a2d(-1:1,1:2) => a1d \r\n print*,\"a2d(-1:1,1:2) => a1d\"\r\n end if\r\n print \"(' shape(a2d) =',*(1x,i4))\",shape(a2d)\r\n print \"('lbound(a2d) =',*(1x,i4))\",lbound(a2d)\r\n print \"('ubound(a2d) =',*(1x,i4))\",ubound(a2d)\r\n print \"(/,'a2d =')\"\r\n do i1=lbound(a2d,1),ubound(a2d,1)\r\n print \"(*(i4))\",a2d(i1,:)\r\n end do\r\n ! changes to pointer affect the pointee\r\n if (iter == 2) a2d(-1,1) = a2d(-1,1)*10\r\nend do\r\nprint \"(/,'a1d =',/,*(i4))\",a1d\r\nend program pointer_remap_array\r\n! output:\r\n! a1d =\r\n! 10 20 30 40 50 60\r\n! \r\n! a2d(1:3,1:2) => a1d\r\n! shape(a2d) = 3 2\r\n! lbound(a2d) = 1 1\r\n! ubound(a2d) = 3 2\r\n! \r\n! a2d =\r\n! 10 40\r\n! 20 50\r\n! 30 60\r\n! \r\n! a2d(-1:1,1:2) => a1d\r\n! shape(a2d) = 3 2\r\n! lbound(a2d) = -1 1\r\n! ubound(a2d) = 1 2\r\n! \r\n! a2d =\r\n! 10 40\r\n! 20 50\r\n! 30 60\r\n! \r\n! a1d =\r\n! 100 20 30 40 50 60", "meta": {"hexsha": "3a62eeed400f455b59773d5be62ed77d29038508", "size": 1332, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "pointer_reshape.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": "pointer_reshape.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": "pointer_reshape.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": 23.3684210526, "max_line_length": 50, "alphanum_fraction": 0.484984985, "num_tokens": 648, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929104825006, "lm_q2_score": 0.8519528094861981, "lm_q1q2_score": 0.664517151464883}} {"text": "!*****************************************************************************************\n!> author: Jacob Williams\n! license: BSD\n!\n!### Description\n!\n! Multidimensional (1D-6D) B-Spline interpolation of data on a regular grid.\n! This module uses both the subroutine and object-oriented modules.\n\n module bspline_module\n\n use bspline_kinds_module, only: bspline_wp => wp\n use bspline_oo_module\n use bspline_sub_module\n\n implicit none\n\n public\n\n!*****************************************************************************************\n end module bspline_module\n!*****************************************************************************************\n", "meta": {"hexsha": "4d59d64697181a24a4501a769f32ed5b4477a52d", "size": 679, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/Bspline_hatest/bspline_module.f90", "max_stars_repo_name": "hhc2tech/bspline-fortran", "max_stars_repo_head_hexsha": "2dea3f1a9ce04095ce45bb48c97c0fd9d0e8c9be", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 139, "max_stars_repo_stars_event_min_datetime": "2015-02-25T08:11:20.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T17:33:50.000Z", "max_issues_repo_path": "src/tests/Bspline_hatest/bspline_module.f90", "max_issues_repo_name": "hhc2tech/bspline-fortran", "max_issues_repo_head_hexsha": "2dea3f1a9ce04095ce45bb48c97c0fd9d0e8c9be", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 46, "max_issues_repo_issues_event_min_datetime": "2015-06-19T18:25:15.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T21:14:15.000Z", "max_forks_repo_path": "src/tests/Bspline_hatest/bspline_module.f90", "max_forks_repo_name": "hhc2tech/bspline-fortran", "max_forks_repo_head_hexsha": "2dea3f1a9ce04095ce45bb48c97c0fd9d0e8c9be", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 51, "max_forks_repo_forks_event_min_datetime": "2015-09-17T16:52:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-26T03:18:28.000Z", "avg_line_length": 29.5217391304, "max_line_length": 90, "alphanum_fraction": 0.4359351988, "num_tokens": 118, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527944504227, "lm_q2_score": 0.7799929104825006, "lm_q1q2_score": 0.6645171397370848}} {"text": "program newkinds\n\n use iso_fortran_env\n\n implicit none\n\n real(kind=real32) :: x32\n real(kind=real64) :: x64\n real(kind=real128) :: x128\n\n print *, 'real32 : ', real32, achar(10), &\n ' real64 : ', real64, achar(10), &\n ' real128 : ', real128\n\n x32 = 2.0\n x64 = 2.0\n x128 = 2.0\n\n print *, 'SQRT(2.0) using kind=real32 :', sqrt(x32)\n print *, 'SQRT(2.0) using kind=real64 :', sqrt(x64)\n print *, 'SQRT(2.0) using kind=real128 :', sqrt(x128)\n\nend program\n\n", "meta": {"hexsha": "7329fedbc8229cea1d58c0f691775494d657ecf4", "size": 500, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "files/advanced/example_09.f90", "max_stars_repo_name": "WVUHPC/Modern-Fortran", "max_stars_repo_head_hexsha": "97c4db834d4e6ca43802318e4dc63ce4faa641aa", "max_stars_repo_licenses": ["CC-BY-4.0"], "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": "files/advanced/example_09.f90", "max_issues_repo_name": "WVUHPC/Modern-Fortran", "max_issues_repo_head_hexsha": "97c4db834d4e6ca43802318e4dc63ce4faa641aa", "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": "files/advanced/example_09.f90", "max_forks_repo_name": "WVUHPC/Modern-Fortran", "max_forks_repo_head_hexsha": "97c4db834d4e6ca43802318e4dc63ce4faa641aa", "max_forks_repo_licenses": ["CC-BY-4.0"], "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": 20.0, "max_line_length": 56, "alphanum_fraction": 0.564, "num_tokens": 191, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.851952809486198, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6645171383937196}} {"text": "program AoS\n USE IFPORT\n use iso_fortran_env, only : real32, real64\n implicit none\n\n type charge\n real(real32),allocatable :: x(:),y(:),z(:),q(:) ! Coordinates and value of the charge\n end type charge\n\n type(charge) :: charges\n real(real32), allocatable :: potential(:)\n integer, parameter :: m = 2048, n_trials = 10\n integer :: i,j\n real(real32) :: Rx, Ry, Rz\n real(real64) :: end_time, start_time\n\n allocate(potential(m*m), charges%x(m), charges%y(m), charges%z(m), charges%q(m))\n\n call srand(12345)\n\n do i = 1, m\n charges%x(i) = rand()\n charges%y(i) = rand()\n charges%z(i) = rand()\n charges%q(i) = rand()\n end do\n\n do i = 1, n_trials\n potential = 0.0\n call cpu_time(start_time)\n do j = 1, m*m\n Rx = real(mod(j,m))\n Ry = real(j/m)\n Rz = 0.0\n potential(j) = calculate_electric_potential(charges, Rx, Ry, Rz)\n end do\n call cpu_time(end_time)\n write(*,*) 'Trial ',i,' test ',potential(100), 'time ', end_time - start_time\n end do\n\ncontains\n\n function calculate_electric_potential(charges, Rx, Ry, Rz) result(phi)\n implicit none\n\n real(real32), intent(in) :: Rx, Ry, Rz\n type(charge),intent(in) :: charges\n real(real32) :: dx,dy,dz\n real(real32) :: phi\n integer :: i\n\n phi = 0.0\n\n do i = 1, size(charges%x)\n dx = charges%x(i) - Rx\n dy = charges%y(i) - Ry\n dz = charges%z(i) - Rz\n phi = phi - charges%q(i) / sqrt(dx**2 + dy**2 + dz**2)\n end do\n\n end function calculate_electric_potential\n\nend program AoS\n", "meta": {"hexsha": "6dcd5b8f5829b96e1f7a65b85eafd57b3fb32d93", "size": 1544, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "AoS_vs_SoA/SoA/SoA.f90", "max_stars_repo_name": "afanfa/OptimizedModernFortran", "max_stars_repo_head_hexsha": "9b55295fc7041cd91e7a8cea902f2007a8dd5fc7", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 26, "max_stars_repo_stars_event_min_datetime": "2019-01-29T22:42:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T16:53:02.000Z", "max_issues_repo_path": "AoS_vs_SoA/SoA/SoA.f90", "max_issues_repo_name": "afanfa/OptimizedModernFortran", "max_issues_repo_head_hexsha": "9b55295fc7041cd91e7a8cea902f2007a8dd5fc7", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-07-23T16:39:14.000Z", "max_issues_repo_issues_event_max_datetime": "2020-03-24T20:55:21.000Z", "max_forks_repo_path": "AoS_vs_SoA/SoA/SoA.f90", "max_forks_repo_name": "afanfa/OptimizedModernFortran", "max_forks_repo_head_hexsha": "9b55295fc7041cd91e7a8cea902f2007a8dd5fc7", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-03-12T05:18:59.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-12T16:09:44.000Z", "avg_line_length": 24.125, "max_line_length": 90, "alphanum_fraction": 0.5945595855, "num_tokens": 507, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528094861981, "lm_q2_score": 0.7799928900257126, "lm_q1q2_score": 0.664517134036665}} {"text": "module assert\n\nuse, intrinsic:: iso_fortran_env, only: stderr=>error_unit, real64, real32\nuse, intrinsic:: ieee_arithmetic, only: ieee_is_finite, ieee_is_nan\n\nimplicit none (type, external)\n\nprivate\n\npublic :: isclose, assert_allclose\n\ncontains\n\nelemental logical function isclose(actual, desired, rtol, atol, equal_nan)\n!! ## inputs\n!!\n!! * actual: value \"measured\"\n!! * desired: value \"wanted\"\n!! * rtol: relative tolerance\n!! * atol: absolute tolerance\n!! * equal_nan: consider NaN to be equal\n!!\n!! https://www.python.org/dev/peps/pep-0485/#proposed-implementation\n!! https://github.com/PythonCHB/close_pep/blob/master/is_close.py\n\nclass(*), intent(in) :: actual, desired\nclass(*), intent(in), optional :: rtol, atol\nlogical, intent(in), optional :: equal_nan\n\nreal(real64) :: r,a, act, des\nlogical :: n\n\nisclose = .false. !< ensure it's defined\n\n!> INSTEAD OF merge(), since non present values aren't defined.\nr = 1e-6\na = 1e-12\nn = .false.\n\nselect type (actual)\ntype is (real(real32))\n act = real(actual, real32)\ntype is (real(real64))\n act = actual\nclass default\n error stop \"assert: actual must be real32 or real64\"\nend select\n\nselect type (desired)\ntype is (real(real32))\n des = real(desired, real32)\ntype is (real(real64))\n des = desired\nclass default\n error stop \"assert: desired must be real32 or real64\"\nend select\n\nif (present(rtol)) then\n select type (rtol)\n type is (real(real64))\n r = rtol\n type is (real(real32))\n r = real(rtol, real64)\n class default\n error stop \"assert: rtol needs real32 or real64\"\n end select\nendif\n\nif (present(atol)) then\n select type (atol)\n type is (real(real64))\n a = atol\n type is (real(real32))\n a = real(atol, real64)\n class default\n error stop \"assert: atol needs real32 or real64\"\n end select\nendif\n\nif (present(equal_nan)) n = equal_nan\n\n!print*,r,a,n,act,des\n\n!> sanity check\nif ((r < 0).or.(a < 0)) error stop 'improper tolerances specified'\n!> simplest case -- too unlikely, especially for arrays?\n!isclose = (act == des)\n!if (isclose) return\n\n!> equal nan\nif (n) then ! fortran is NOT short circuit logic in general\n isclose = (ieee_is_nan(act) .and. ieee_is_nan(des))\n if (isclose) return\nendif\n\n!> Inf /= -Inf, unequal NaN\nif (.not.ieee_is_finite(act) .or. .not.ieee_is_finite(des)) return\n\n!> floating point closeness check\nisclose = abs(act-des) <= max(r * max(abs(act), abs(des)), a)\n\nend function isclose\n\n\nimpure elemental subroutine assert_allclose(actual, desired, rtol, atol, equal_nan, err_msg)\n\n!! ## inputs\n!!\n!! * actual: value \"measured\"\n!! * desired: value \"wanted\"\n!! * rtol: relative tolerance\n!! * atol: absolute tolerance\n!! * equal_nan: consider NaN to be equal\n!! * err_msg: message to print on mismatch\n\nclass(*), intent(in) :: actual, desired\nclass(*), intent(in), optional :: rtol, atol\nlogical, intent(in), optional :: equal_nan\ncharacter(*), intent(in), optional :: err_msg\ncharacter(:), allocatable :: emsg\n\nreal(real64) :: act, des\n\nselect type (actual)\ntype is (real(real32))\n act = real(actual, real32)\ntype is (real(real64))\n act = actual\nclass default\n error stop \"assert: actual must be real32 or real64\"\nend select\n\nselect type (desired)\ntype is (real(real32))\n des = real(desired, real32)\ntype is (real(real64))\n des = desired\nclass default\n error stop \"assert: desired must be real32 or real64\"\nend select\n\nif (present(err_msg)) then\n emsg = err_msg\nelse\n emsg = 'assert: MISMATCH'\nendif\n\nif (.not.isclose(act, des, rtol,atol,equal_nan)) then\n write(stderr,*) emsg // ': actual',act,'desired',des\n error stop\nendif\n\nend subroutine assert_allclose\n\nend module assert\n", "meta": {"hexsha": "07c26c582c4641240730f3a6209cdc8e1e5a4204", "size": 3609, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/utils/assert.f90", "max_stars_repo_name": "paulinchin/gemini3d", "max_stars_repo_head_hexsha": "787168fcafb51624b5ad1aedbd40ad47466cb43f", "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/utils/assert.f90", "max_issues_repo_name": "paulinchin/gemini3d", "max_issues_repo_head_hexsha": "787168fcafb51624b5ad1aedbd40ad47466cb43f", "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/utils/assert.f90", "max_forks_repo_name": "paulinchin/gemini3d", "max_forks_repo_head_hexsha": "787168fcafb51624b5ad1aedbd40ad47466cb43f", "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.1346153846, "max_line_length": 92, "alphanum_fraction": 0.6996397894, "num_tokens": 1059, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933447152498, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.6645062594976326}} {"text": " SUBROUTINE MB04IZ( N, M, P, L, A, LDA, B, LDB, TAU, ZWORK, LZWORK,\n $ INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute a QR factorization of an n-by-m matrix A (A = Q * R),\nC having a p-by-min(p,m) zero triangle in the lower left-hand side\nC corner, as shown below, for n = 8, m = 7, and p = 2:\nC\nC [ x x x x x x x ]\nC [ x x x x x x x ]\nC [ x x x x x x x ]\nC [ x x x x x x x ]\nC A = [ x x x x x x x ],\nC [ x x x x x x x ]\nC [ 0 x x x x x x ]\nC [ 0 0 x x x x x ]\nC\nC and optionally apply the transformations to an n-by-l matrix B\nC (from the left). The problem structure is exploited. This\nC computation is useful, for instance, in combined measurement and\nC time update of one iteration of the time-invariant Kalman filter\nC (square root information filter).\nC\nC ARGUMENTS\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The number of rows of the matrix A. N >= 0.\nC\nC M (input) INTEGER\nC The number of columns of the matrix A. M >= 0.\nC\nC P (input) INTEGER\nC The order of the zero triagle. P >= 0.\nC\nC L (input) INTEGER\nC The number of columns of the matrix B. L >= 0.\nC\nC A (input/output) COMPLEX*16 array, dimension (LDA,M)\nC On entry, the leading N-by-M part of this array must\nC contain the matrix A. The elements corresponding to the\nC zero P-by-MIN(P,M) lower trapezoidal/triangular part\nC (if P > 0) are not referenced.\nC On exit, the elements on and above the diagonal of this\nC array contain the MIN(N,M)-by-M upper trapezoidal matrix\nC R (R is upper triangular, if N >= M) of the QR\nC factorization, and the relevant elements below the\nC diagonal contain the trailing components (the vectors v,\nC see Method) of the elementary reflectors used in the\nC factorization.\nC\nC LDA INTEGER\nC The leading dimension of array A. LDA >= MAX(1,N).\nC\nC B (input/output) COMPLEX*16 array, dimension (LDB,L)\nC On entry, the leading N-by-L part of this array must\nC contain the matrix B.\nC On exit, the leading N-by-L part of this array contains\nC the updated matrix B.\nC If L = 0, this array is not referenced.\nC\nC LDB INTEGER\nC The leading dimension of array B.\nC LDB >= MAX(1,N) if L > 0;\nC LDB >= 1 if L = 0.\nC\nC TAU (output) COMPLEX*16 array, dimension MIN(N,M)\nC The scalar factors of the elementary reflectors used.\nC\nC Workspace\nC\nC ZWORK COMPLEX*16 array, dimension (LZWORK)\nC On exit, if INFO = 0, ZWORK(1) returns the optimal value\nC of LZWORK.\nC\nC LZWORK The length of the array ZWORK.\nC LZWORK >= MAX(1,M-1,M-P,L).\nC For optimum performance LZWORK should be larger.\nC\nC If LZWORK = -1, then a workspace query is assumed;\nC the routine only calculates the optimal size of the\nC ZWORK array, returns this value as the first entry of\nC the ZWORK array, and no error message related to LZWORK\nC is issued by XERBLA.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value.\nC\nC METHOD\nC\nC The routine uses min(N,M) Householder transformations exploiting\nC the zero pattern of the matrix. A Householder matrix has the form\nC\nC ( 1 ),\nC H = I - tau *u *u', u = ( v )\nC i i i i i ( i)\nC\nC where v is an (N-P+I-2)-vector. The components of v are stored\nC i i\nC in the i-th column of A, beginning from the location i+1, and\nC tau is stored in TAU(i).\nC i\nC\nC NUMERICAL ASPECTS\nC\nC The algorithm is backward stable.\nC\nC CONTRIBUTORS\nC\nC V. Sima, Katholieke Univ. Leuven, Belgium, Feb. 1997.\nC Complex version: V. Sima, Research Institute for Informatics,\nC Bucharest, Nov. 2008.\nC\nC REVISIONS\nC\nC V. Sima, Research Institute for Informatics, Bucharest, Apr. 2009,\nC Apr. 2011.\nC\nC KEYWORDS\nC\nC Elementary reflector, QR factorization, unitary transformation.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n COMPLEX*16 ZERO, ONE\n PARAMETER ( ZERO = ( 0.0D+0, 0.0D+0 ),\n $ ONE = ( 1.0D+0, 0.0D+0 ) )\nC .. Scalar Arguments ..\n INTEGER INFO, L, LDA, LDB, LZWORK, M, N, P\nC .. Array Arguments ..\n COMPLEX*16 A(LDA,*), B(LDB,*), TAU(*), ZWORK(*)\nC .. Local Scalars ..\n LOGICAL LQUERY\n INTEGER I, WRKOPT\n COMPLEX*16 FIRST\nC .. External Subroutines ..\n EXTERNAL XERBLA, ZGEQRF, ZLARF, ZLARFG, ZUNMQR\nC .. Intrinsic Functions ..\n INTRINSIC DCONJG, INT, MAX, MIN\nC .. Executable Statements ..\nC\nC Test the input scalar arguments.\nC\n INFO = 0\n LQUERY = LZWORK.EQ.-1\n IF( N.LT.0 ) THEN\n INFO = -1\n ELSE IF( M.LT.0 ) THEN\n INFO = -2\n ELSE IF( P.LT.0 ) THEN\n INFO = -3\n ELSE IF( L.LT.0 ) THEN\n INFO = -4\n ELSE IF( LDA.LT.MAX( 1, N ) ) THEN\n INFO = -6\n ELSE IF( LDB.LT.1 .OR. ( L.GT.0 .AND. LDB.LT.N ) ) THEN\n INFO = -8\n ELSE\n I = MAX( 1, M - 1, M - P, L )\n IF( LQUERY ) THEN\n IF( M.GT.P ) THEN\n CALL ZGEQRF( N-P, M-P, A, LDA, TAU, ZWORK, -1, INFO )\n WRKOPT = MAX( I, INT( ZWORK( 1 ) ) )\n IF ( L.GT.0 ) THEN\n CALL ZUNMQR( 'Left', 'Conjugate', N-P, L, MIN(N,M)-P,\n $ A, LDA, TAU, B, LDB, ZWORK, -1, INFO )\n WRKOPT = MAX( WRKOPT, INT( ZWORK( 1 ) ) )\n END IF\n END IF\n ELSE IF( LZWORK.LT.I ) THEN\n INFO = -11\n END IF\n END IF\nC\n IF( INFO.NE.0 ) THEN\nC\nC Error return.\nC\n CALL XERBLA( 'MB04IZ', -INFO )\n RETURN\n ELSE IF( LQUERY ) THEN\n ZWORK(1) = WRKOPT\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF( MIN( M, N ).EQ.0 ) THEN\n ZWORK(1) = ONE\n RETURN\n ELSE IF( N.LE.P+1 ) THEN\n DO 5 I = 1, MIN( N, M )\n TAU(I) = ZERO\n 5 CONTINUE\n ZWORK(1) = ONE\n RETURN\n END IF\nC\nC Annihilate the subdiagonal elements of A and apply the\nC transformations to B, if L > 0.\nC Workspace: need MAX(M-1,L).\nC\nC (Note: Comments in the code beginning \"Workspace:\" describe the\nC minimal amount of complex workspace needed at that point in the\nC code, as well as the preferred amount for good performance.\nC NB refers to the optimal block size for the immediately\nC following subroutine, as returned by ILAENV.)\nC\n DO 10 I = 1, MIN( P, M )\nC\nC Exploit the structure of the I-th column of A.\nC\n CALL ZLARFG( N-P, A(I,I), A(I+1,I), 1, TAU(I) )\n IF( TAU(I).NE.ZERO ) THEN\nC\n FIRST = A(I,I)\n A(I,I) = ONE\nC\n IF ( I.LT.M ) CALL ZLARF( 'Left', N-P, M-I, A(I,I), 1,\n $ DCONJG( TAU(I) ), A(I,I+1), LDA,\n $ ZWORK )\n IF ( L.GT.0 ) CALL ZLARF( 'Left', N-P, L, A(I,I), 1,\n $ DCONJG( TAU(I) ), B(I,1), LDB,\n $ ZWORK )\nC\n A(I,I) = FIRST\n END IF\n 10 CONTINUE\nC\n WRKOPT = MAX( 1, M - 1, L )\nC\nC Fast QR factorization of the remaining right submatrix, if any.\nC Workspace: need M-P; prefer (M-P)*NB.\nC\n IF( M.GT.P ) THEN\n CALL ZGEQRF( N-P, M-P, A(P+1,P+1), LDA, TAU(P+1), ZWORK,\n $ LZWORK, INFO )\n WRKOPT = MAX( WRKOPT, INT( ZWORK(1) ) )\nC\n IF ( L.GT.0 ) THEN\nC\nC Apply the transformations to B.\nC Workspace: need L; prefer L*NB.\nC\n CALL ZUNMQR( 'Left', 'Conjugate', N-P, L, MIN(N,M)-P,\n $ A(P+1,P+1), LDA, TAU(P+1), B(P+1,1), LDB,\n $ ZWORK, LZWORK, INFO )\n WRKOPT = MAX( WRKOPT, INT( ZWORK(1) ) )\n END IF\n END IF\nC\n ZWORK(1) = WRKOPT\n RETURN\nC *** Last line of MB04IZ ***\n END\n", "meta": {"hexsha": "dda97f444bbf882c4ac629cdc9d30dcfab178730", "size": 8762, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB04IZ.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB04IZ.f", "max_issues_repo_name": "bnavigator/SLICOT-Reference", "max_issues_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB04IZ.f", "max_forks_repo_name": "bnavigator/SLICOT-Reference", "max_forks_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 32.8164794007, "max_line_length": 72, "alphanum_fraction": 0.5125542114, "num_tokens": 2701, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9372107896491797, "lm_q2_score": 0.709019146082187, "lm_q1q2_score": 0.6645003937760735}} {"text": " SUBROUTINE MB04WP( N, ILO, U1, LDU1, U2, LDU2, CS, TAU, DWORK,\n $ LDWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To generate an orthogonal symplectic matrix U, which is defined as\nC a product of symplectic reflectors and Givens rotations\nC\nC U = diag( H(1),H(1) ) G(1) diag( F(1),F(1) )\nC diag( H(2),H(2) ) G(2) diag( F(2),F(2) )\nC ....\nC diag( H(n-1),H(n-1) ) G(n-1) diag( F(n-1),F(n-1) ).\nC\nC as returned by MB04PU. The matrix U is returned in terms of its\nC first N rows\nC\nC [ U1 U2 ]\nC U = [ ].\nC [ -U2 U1 ]\nC\nC ARGUMENTS\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The order of the matrices U1 and U2. N >= 0.\nC\nC ILO (input) INTEGER\nC ILO must have the same value as in the previous call of\nC MB04PU. U is equal to the unit matrix except in the\nC submatrix\nC U([ilo+1:n n+ilo+1:2*n], [ilo+1:n n+ilo+1:2*n]).\nC 1 <= ILO <= N, if N > 0; ILO = 1, if N = 0.\nC\nC U1 (input/output) DOUBLE PRECISION array, dimension (LDU1,N)\nC On entry, the leading N-by-N part of this array must\nC contain in its i-th column the vector which defines the\nC elementary reflector F(i).\nC On exit, the leading N-by-N part of this array contains\nC the matrix U1.\nC\nC LDU1 INTEGER\nC The leading dimension of the array U1. LDU1 >= MAX(1,N).\nC\nC U2 (input/output) DOUBLE PRECISION array, dimension (LDU2,N)\nC On entry, the leading N-by-N part of this array must\nC contain in its i-th column the vector which defines the\nC elementary reflector H(i) and, on the subdiagonal, the\nC scalar factor of H(i).\nC On exit, the leading N-by-N part of this array contains\nC the matrix U2.\nC\nC LDU2 INTEGER\nC The leading dimension of the array U2. LDU2 >= MAX(1,N).\nC\nC CS (input) DOUBLE PRECISION array, dimension (2N-2)\nC On entry, the first 2N-2 elements of this array must\nC contain the cosines and sines of the symplectic Givens\nC rotations G(i).\nC\nC TAU (input) DOUBLE PRECISION array, dimension (N-1)\nC On entry, the first N-1 elements of this array must\nC contain the scalar factors of the elementary reflectors\nC F(i).\nC\nC Workspace\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0, DWORK(1) returns the optimal\nC value of LDWORK.\nC On exit, if INFO = -10, DWORK(1) returns the minimum\nC value of LDWORK.\nC\nC LDWORK INTEGER\nC The length of the array DWORK. LDWORK >= MAX(1,2*(N-ILO)).\nC For optimum performance LDWORK should be larger. (See\nC SLICOT Library routine MB04WD).\nC\nC If LDWORK = -1, then a workspace query is assumed;\nC the routine only calculates the optimal size of the\nC DWORK array, returns this value as the first entry of\nC the DWORK array, and no error message related to LDWORK\nC is issued by XERBLA.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value.\nC\nC NUMERICAL ASPECTS\nC\nC The algorithm requires O(N**3) floating point operations and is\nC strongly backward stable.\nC\nC REFERENCES\nC\nC [1] C. F. VAN LOAN:\nC A symplectic method for approximating all the eigenvalues of\nC a Hamiltonian matrix.\nC Linear Algebra and its Applications, 61, pp. 233-251, 1984.\nC\nC [2] D. KRESSNER:\nC Block algorithms for orthogonal symplectic factorizations.\nC BIT, 43 (4), pp. 775-790, 2003.\nC\nC CONTRIBUTORS\nC\nC D. Kressner (Technical Univ. Berlin, Germany) and\nC P. Benner (Technical Univ. Chemnitz, Germany), December 2003.\nC\nC REVISIONS\nC\nC V. Sima, Nov. 2008 (SLICOT version of the HAPACK routine DOSGPV).\nC V. Sima, Aug. 2011.\nC\nC KEYWORDS\nC\nC Elementary matrix operations, orthogonal symplectic matrix.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, ONE\n PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )\nC .. Scalar Arguments ..\n INTEGER ILO, INFO, LDU1, LDU2, LDWORK, N\nC .. Array Arguments ..\n DOUBLE PRECISION CS(*), DWORK(*), U1(LDU1,*), U2(LDU2,*), TAU(*)\nC .. Local Scalars ..\n LOGICAL LQUERY\n INTEGER I, IERR, J, MINWRK, NH, WRKOPT\nC .. External Subroutines ..\n EXTERNAL DLASET, MB04WD, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC DBLE, INT, MAX\nC\nC .. Executable Statements ..\nC\nC Check the scalar input parameters.\nC\n INFO = 0\n NH = N - ILO\n IF ( N.LT.0 ) THEN\n INFO = -1\n ELSE IF ( ILO.LT.1 .OR. ILO.GT.MAX( 1, N ) ) THEN\n INFO = -2\n ELSE IF ( LDU1.LT.MAX( 1, N ) ) THEN\n INFO = -4\n ELSE IF ( LDU2.LT.MAX( 1, N ) ) THEN\n INFO = -6\n ELSE\n LQUERY = LDWORK.EQ.-1\n MINWRK = MAX( 1, 2*NH )\n IF ( LQUERY ) THEN\n IF ( N.EQ.0 ) THEN\n WRKOPT = ONE\n ELSE\n CALL MB04WD( 'No Transpose', 'No Transpose', NH, NH, NH,\n $ U1, LDU1, U2, LDU2, CS, TAU, DWORK, -1,\n $ IERR )\n WRKOPT = MAX( MINWRK, INT( DWORK(1) ) ) \n END IF\n DWORK(1) = DBLE( WRKOPT )\n RETURN\n ELSE IF ( LDWORK.LT.MINWRK ) THEN\n DWORK(1) = DBLE( MINWRK )\n INFO = -10\n END IF\n END IF\nC\nC Return if there were illegal values.\nC\n IF ( INFO.NE.0 ) THEN\n CALL XERBLA( 'MB04WP', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF( N.EQ.0 ) THEN\n DWORK(1) = ONE\n RETURN\n END IF\nC\nC Shift the vectors which define the elementary reflectors one\nC column to the right, and set the first ilo rows and columns to\nC those of the unit matrix.\nC\n DO 30 J = N, ILO + 1, -1\n DO 10 I = 1, J-1\n U1(I,J) = ZERO\n 10 CONTINUE\n DO 20 I = J+1, N\n U1(I,J) = U1(I,J-1)\n 20 CONTINUE\n 30 CONTINUE\n CALL DLASET( 'All', N, ILO, ZERO, ONE, U1, LDU1 )\n DO 60 J = N, ILO + 1, -1\n DO 40 I = 1, J-1\n U2(I,J) = ZERO\n 40 CONTINUE\n DO 50 I = J, N\n U2(I,J) = U2(I,J-1)\n 50 CONTINUE\n 60 CONTINUE\n CALL DLASET( 'All', N, ILO, ZERO, ZERO, U2, LDU2 )\n IF ( NH.GT.0 ) THEN\n CALL MB04WD( 'No Transpose', 'No Transpose', NH, NH, NH,\n $ U1(ILO+1,ILO+1), LDU1, U2(ILO+1,ILO+1), LDU2,\n $ CS(ILO), TAU(ILO), DWORK, LDWORK, IERR )\n ELSE\n DWORK(1) = ONE\n END IF\n RETURN\nC *** Last line of MB04WP ***\n END\n", "meta": {"hexsha": "ca40e5494acce0cc2b19d3aa0127872f21081c03", "size": 7294, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB04WP.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB04WP.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB04WP.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 32.7085201794, "max_line_length": 72, "alphanum_fraction": 0.5308472717, "num_tokens": 2301, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9458012640659996, "lm_q2_score": 0.7025300636233416, "lm_q1q2_score": 0.6644538222193236}} {"text": " SUBROUTINE SSVDRS (A,LDA,M1,N1,B,LDB,NB,S,WORK)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nC>> 2001-05-25 SSVDRS Krogh Minor change for making .f90 version.\nC>> 1999-08-12 SSVDRS Krogh Loop at 180 => 2 loops for Sun optimizer.\nC>> 1994-10-20 SSVDRS Krogh Changes to use M77CON\nC>> 1992-06-16 SSVDRS CLL\nC>> 1992-03-13 SSVDRS FTK Removed implicit statements.\nC>> 1989-10-20 CLL\nC>> 1989-06-05 SSVDRS Snyder Add END statement, polish a little.\nC>> 1987-11-24 SSVDRS Lawson Adaptation to Fortran 77 and MATH77.\nc>> 1974-01-01 Lawson and Hanson initial code.\nc\nC This subr computes the singular value decomposition of the\nc given M1 x N1 matrix, A, and optionally applys the transformations\nc from the left to the NB column vectors of the M1 x NB matrix B.\nc Either M1 .ge. N1 or M1 .lt. N1 is permitted.\nc\nc The singular value decomposition of A is of the form\nc\nC A = U * S * V**t\nc\nc where U is M1 x M1 orthogonal, S is M1 x N1 diagonal with the\nc diagonal terms nonnegative and ordered from large to small, and\nc V is N1 x N1 orthogonal. Note that these matrices also satisfy\nc\nc S = (U**t) * A * V\nc\nc The matrix V is returned in the leading N1 rows and\nc columns of the array A(,).\nc\nc The singular values, i.e. the diagonal terms of the matrix S,\nc are returned in the array S(). If M1 .lt. N1, positions M1+1\nc through N1 of S() will be set to zero.\nc\nc The product matrix G = U**t * B replaces the given matrix B\nc in the array B(,).\nc\nc If the user wishes to obtain a minimum length least squares\nc solution of the linear system\nc\nc A * X ~=~ B\nc\nc the solution X can be constructed, following use of this subr,\nc by computing the sum for i = 1, ..., R of the outer products\nc\nc (Col i of V) * (1/S(i)) * (Row i of G)\nc\nc Here R denotes the pseudorank of A which the user may choose\nc in the range 0 through Min(M1, N1) based on the sizes of the\nc singular values.\nC ------------------------------------------------------------------\nC Subroutine Arguments\nc\nc A(,) (In/Out) On input contains the M1 x N1 matrix A.\nc On output contains the N1 x N1 matrix V.\nc\nc LDA (In) First dimensioning parameter for A(,).\nc Require LDA .ge. Max(M1, N1).\nc\nc M1 (In) No. of rows of matrices A, B, and G.\nc Require M1 > 0.\nc\nc N1 (In) No. of cols of matrix A, No. of rows and cols of\nc matrix V. Permit M1 .ge. N1 or M1 .lt. N1.\nc Require N1 > 0.\nc\nc B(,) (In/Out) If NB .gt. 0 this array must contain an\nC M1 x NB matrix on input and will contain the\nc M1 x NB product matrix, G = (U**t) * B on output.\nc\nc LDB (In) First dimensioning parameter for B(,).\nc Require LDB .ge. M1.\nc\nc NB (In) No. of cols in the matrices B and G.\nc Require NB .ge. 0.\nc\nc S() (Out) Must be dimensioned at least N1. On return will\nc contain the singular values of A, with the ordering\nc S(1) .ge. S(2) .ge. ... .ge. S(N1) .ge. 0.\nc If M1 .lt. N1 the singular values indexed from M1+1\nc through N1 will be zero.\nc If the given integer arguments are not consistent, this\nc subr will return immediately, setting S(1) = -1.0.\nc\nc WORK() (Scratch) Work space of total size at least 2*N1.\nc Locations 1 thru N1 will hold the off-diagonal terms of\nc the bidiagonal matrix for subr _QRBD. Locations N1+1\nc thru 2*N1 will save info from one call to the next of\nc _HTGEN.\nc ------------------------------------------------------------------\nc Subprograms referenced directly: SCOPY, SHTCC, SHTGEN,SQRBD,SSWAP,\nc ERMSG, ERMOR, IERV1\nc Other subprograms needed: ERFIN, *1MACH (Fortran 77 only), *ROT,\nc *ROTG (* = S or D)\nC ------------------------------------------------------------------\nc This subr gives special treatment to the cases of entire rows\nc and/or columns of A being zero. This provides the feature that\nc singular values that are zero because of the zero structure of A\nc will be produced as exact zeros rather than as relatively small\nc nonzero values. This is convenient for cases in which a user\nc wishes to remove a variable from a problem by simply zeroing the\nc corresponding column of A.\nc\nc Method for this special feature:\nc\nC 1. EXCHANGE COLS OF A TO PACK NONZERO COLS TO THE LEFT.\nC SET NWORK = NO. OF NONZERO COLS.\nC USE LOCATIONS A(1,NWORK+1),...,A(1,N1) TO RECORD THE\nC COL PERMUTATIONS.\nC 2. EXCHANGE ROWS OF A TO PACK NONZERO ROWS TO THE TOP.\nC QUIT PACKING IF FIND NWORK NONZERO ROWS. MAKE SAME ROW\nC EXCHANGES IN B. SET MWORK SO THAT ALL NONZERO ROWS OF THE\nC PERMUTED A ARE IN FIRST MWORK ROWS. IF MWORK .LE. NWORK THEN\nC ALL MWORK ROWS ARE NONZERO. IF MWORK .GT. NWORK THEN THE\nC FIRST NWORK ROWS ARE KNOWN TO BE NONZERO, AND ROWS NWORK+1\nC THRU MWORK MAY BE ZERO OR NONZERO.\nC 3. APPLY THE BASIC SVD ALGORITHM TO THE MWORK BY NWORK PROBLEM.\nC 4. MOVE PERMUTATION RECORD FROM A(,) TO S(I),I = NWORK+1,...,N1.\nC 5. BUILD V UP FROM NWORK BY NWORK TO N1 BY N1 BY PLACING ONES ON\nC THE DIAGONAL AND ZEROS ELSEWHERE. THIS IS ONLY PARTLY DONE\nC EXPLICITLY. IT IS COMPLETED DURING STEP 6.\nC 6. EXCHANGE ROWS OF V TO COMPENSATE FOR COL EXCHANGES OF STEP 2.\nC 7. PLACE ZEROS IN S(I),I = NWORK+1,...,N1 TO REPRESENT ZERO\nC SING VALS.\nC\nc ------------------------------------------------------------------\nc This code was originally developed by Charles L. Lawson and\nc Richard J. Hanson at Jet Propulsion Laboratory in 1973. The\nc original code was described and listed in the book,\nc\nc Solving Least Squares Problems\nc C. L. Lawson and R. J. Hanson\nc Prentice-Hall, 1974\nc\nc Feb 1985, Mar 1987, C. L. Lawson & S. Y. Chiu, JPL. Adapted code\nc from the Lawson & Hanson book to Fortran 77 for use in the\nc JPL MATH77 library.\nc Prefixing subprogram names with S or D for s.p. or d.p. versions.\nc Using generic names for intrinsic functions.\nc Adding calls to BLAS and MATH77 error processing subrs in some\nc program units.\nc 1989-10-20 CLL Moved integer declaration to earlier position to\nc avoid warning msg from Cray compiler.\nC 1992-06-16 CLL. Using \"min\" fcn in arg list of calls to _HTCC\nc and _HTGEN to avoid \"index out of range\" when using a bounds\nc checker, even though no reference would be made to the \"out of\nc range\" location.\nc ------------------------------------------------------------------\nC--S replaces \"?\": ?SVDRS, ?COPY, ?HTCC, ?HTGEN, ?QRBD, ?SWAP\nc ------------------------------------------------------------------\n integer I,IPASS,J,K,L,LBASE,LDA,LDB,M1,MWORK,N1,NB,NP1,NS,NWORK\n real A(LDA,N1),B(LDB,*),ONE,S(N1),UPARAM,WORK(2*N1)\n real ZERO\n logical COL, ROW\n parameter( ZERO = 0.0E0, ONE = 1.0E0, COL = .true., ROW = .false.)\nc ------------------------------------------------------------------\n NWORK = N1\n LBASE = NWORK\n if(LDA .lt. max(M1,NWORK) .or. M1 .le. 0 .or. NWORK .le. 0 .or.\n * (NB .gt. 0 .and. LDB .lt. M1)) then\n call ERMSG('SSVDRS',1,0,\n * 'Bad argument values. Require LDA .ge. max(M,N), M > 0,',\n * ',')\n call ERMOR('N > 0, LDB .ge. M if NB > 0', ',')\n call IERV1('LDA',LDA, ',')\n call IERV1('M', M1, ',')\n call IERV1('N', NWORK, ',')\n call IERV1('LDB',LDB, ',')\n call IERV1('NB', NB, '.')\n S(1) = -ONE\n return\n endif\nC BEGIN.. SPECIAL FOR ZERO ROWS AND COLS.\nC\nC PACK THE NONZERO COLS TO THE LEFT\nC\n DO 50 J = NWORK, 1, -1\n DO 20 I = 1,M1\n IF (A(I,J) .NE. ZERO) GO TO 50\n 20 CONTINUE\nC\nC COL J IS ZERO. EXCHANGE IT WITH COL NWORK.\nC\n IF (J .ne. NWORK) then\n DO 30 I = 1, M1\n 30 A(I,J) = A(I,NWORK)\n end if\n A(1,NWORK) = J\n NWORK = NWORK - 1\n 50 CONTINUE\nC IF NWORK = 0 THEN A IS ENTIRELY ZERO AND SVD\nC COMPUTATION CAN BE SKIPPED\n NS = 0\n IF (NWORK .ne. 0) then\nC ---------------------------------------------------------------\nC PACK NONZERO ROWS TO THE TOP\nC QUIT PACKING IF FIND NWORK NONZERO ROWS\n I = 1\n MWORK = M1\n 60 IF (I.le.NWORK .and. I.lt.MWORK) then\n DO 80 J = I, NWORK\n IF (A(I,J) .NE. ZERO) GO TO 145\n 80 CONTINUE\n DO 85 J = 1, I-1\n IF(A(I,J) .NE. ZERO) GO TO 145\n 85 CONTINUE\nC ROW I IS ZERO\nC EXCHANGE ROWS I AND MWORK\n IF (NB .GT. 0)\n * CALL SSWAP( NB, B(MWORK,1), LDB, B(I,1), LDB)\n CALL SCOPY(NWORK, A(MWORK,1), LDA, A(I,1), LDA)\n IF (MWORK .LE. NWORK) THEN\n DO 130 J = 1,NWORK\n 130 A(MWORK,J) = ZERO\n ENDIF\nC EXCHANGE IS FINISHED\n MWORK = MWORK - 1\n GO TO 60\nc Here when row I is not all zero. No exchange needed.\n 145 I = I + 1\n GO TO 60\n end if\nC END.. SPECIAL FOR ZERO ROWS AND COLUMNS\nc ---------------------------------------------------------------\nC BEGIN.. SVD ALGORITHM\nC METHOD..\nC (1) REDUCE THE MATRIX TO UPPER BIDIAGONAL FORM WITH\nC HOUSEHOLDER TRANSFORMATIONS.\nC H(NWORK)...H(1)AQ(1)...Q(NWORK-2) = (D**T,0)**T\nC WHERE D IS UPPER BIDIAGONAL.\nC\nC (2) APPLY H(NWORK)...H(1) TO B. HERE H(NWORK)...H(1)*B REPLAC\nC IN STORAGE.\nC\nC (3) THE MATRIX PRODUCT W = Q(1)...Q(NWORK-2) OVERWRITES THE F\nC NWORK ROWS OF A IN STORAGE.\nC\nC (4) AN SVD FOR D IS COMPUTED. HERE K ROTATIONS RI AND PI ARE\nC COMPUTED SO THAT\nC RK...R1*D*P1**(T)...PK**(T) = DIAG(S1,...,S.NS)\nC TO WORKING ACCURACY. THE SI ARE NONNEGATIVE AND NONINCREASING.\nC HERE RK...R1*B OVERWRITES B IN STORAGE WHILE\nC A*P1**(T)...PK**(T) OVERWRITES A IN STORAGE.\nC\nC (5) IT FOLLOWS THAT,WITH THE PROPER DEFINITIONS,\nC U**(T)*B OVERWRITES B, WHILE V OVERWRITES THE FIRST NWORK ROW AND\nC COLUMNS OF A.\nC ------------------------------------------------------------------\n L = MIN(MWORK,NWORK)\nC THE FOLLOWING LOOP REDUCES A TO UPPER BIDIAGONAL AND\nC ALSO APPLIES THE PREMULTIPLYING TRANSFORMATIONS TO B.\nC\n DO 170 J = 1,L\n IF(J .LT. MWORK) THEN\n CALL SHTCC(1,J,J+1,MWORK,A(1,J),UPARAM,\n * A(1,min(J+1,NWORK)),LDA,NWORK-J)\n CALL SHTCC(2,J,J+1,MWORK,A(1,J),UPARAM,B,LDB,NB)\n ENDIF\n IF (J .LT. NWORK-1) THEN\n CALL SHTGEN (1,J+1,J+2,NWORK,A(J,1),LDA,ROW,\n * WORK(LBASE + J),A(min(J+1,MWORK),1),LDA,MWORK-J,ROW)\n ENDIF\n 170 CONTINUE\nC Copy the bidiagonal matrix into the arrays\nc S() and WORK(1:N1) for _QRBD.\n DO 180 J = 1, L\n 180 S(J) = A(J,J)\n DO 190 J = 2, L\n 190 WORK(J) = A(J-1,J)\nC\n NS = NWORK\n IF (MWORK .LT. NWORK) THEN\n NS = MWORK + 1\n S(NS) = ZERO\n WORK(NS) = A(MWORK,MWORK+1)\n ENDIF\nC\nC CONSTRUCT THE EXPLICIT NWORK BY NWORK PRODUCT MATRIX,\nC W = Q1*Q2*...*QL*I IN THE ARRAY A().\nC\n DO 230 I = NWORK, 1, -1\n IF (I .LE. MIN(MWORK,NWORK-2))\n * CALL SHTGEN(2,I+1,I+2,NWORK,A(I,1),LDA,ROW,\n * WORK(LBASE+I),A(1,min(I+1,NWORK)),LDA,NWORK-I,COL)\nC\n DO 220 J = 1, NWORK\n 220 A(I,J) = ZERO\n 230 A(I,I) = ONE\nC\nC COMPUTE THE SVD OF THE BIDIAGONAL MATRIX\nC\n CALL SQRBD (IPASS,S,WORK(1),NS,A,LDA,NWORK,B,LDB,NB)\nC\nC If the above subr has a convergence failure it will report\nc the error via the MATH77 error message subrs and return\nc with IPASS = 2. Since the error has been reported, we don't\nc report it again here but just return.\nc\n IF (IPASS .EQ. 2) RETURN\nC ---------------------------------------------------------------\n end if\n DO 250 J = NS+1, NWORK\n 250 S(J) = ZERO\n IF (NWORK .EQ. N1) RETURN\n NP1 = NWORK + 1\nC MOVE RECORD OF PERMUTATIONS\nC AND STORE ZEROS\n DO 280 J = NP1, N1\n S(J) = A(1,J)\n DO 270 I = 1,NWORK\n 270 A(I,J) = ZERO\n 280 CONTINUE\nC PERMUTE ROWS AND SET ZERO SINGULAR VALUES.\n DO 300 K = NP1, N1\n I = S(K)\n S(K) = ZERO\n DO 290 J = 1,N1\n A(K,J) = A(I,J)\n 290 A(I,J) = ZERO\n A(I,K) = ONE\n 300 CONTINUE\nc End.. Special for zero rows and columns.\n RETURN\n END\n", "meta": {"hexsha": "edfca0b1f7d7dac265cb03fd41b3ab6c4d6d7202", "size": 13619, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/ssvdrs.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/ssvdrs.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/ssvdrs.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 41.6483180428, "max_line_length": 72, "alphanum_fraction": 0.5291137382, "num_tokens": 4203, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813453, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.6644510493378123}} {"text": "program test_schroed\nuse types, only: dp\nuse bsplines, only: bspline, bspline_der, bspline_der2\nuse mesh, only: meshexp\nuse quadrature, only: gauss_pts, gauss_wts\nuse linalg, only: eigh\nuse utils, only: stop_error\nuse schroed_util, only: lho, radial\nimplicit none\n\ninteger, parameter :: n = 30, k = 6, Nq=7\ninteger, parameter :: N_intervals = n-k+1\ninteger, parameter :: Nq_total = Nq*N_intervals, Nb=n-2\nreal(dp) :: t(n+k), rmin, rmax, a\nreal(dp) :: xiq(Nq), wtq(Nq), xa, xb, jac, x(Nq)\nreal(dp), allocatable :: xq(:), wq(:), hq(:)\nreal(dp), allocatable :: B(:,:), Bp(:,:), Bpp(:,:)\nreal(dp), allocatable :: Am(:,:), Bm(:,:), c(:,:), lam(:)\nreal(dp) :: En, condA, condB\ninteger :: i, j, u, l, Z\n\nallocate(Am(Nb,Nb), Bm(Nb,Nb), c(Nb,Nb), lam(Nb))\nallocate(xq(Nq_total), wq(Nq_total), hq(Nq_total))\nallocate(B(Nq_total, n), Bp(Nq_total, n), Bpp(Nq_total, n))\n\nrmin = -10\nrmax = 10\na = 1\ncall construct_basis()\ncall lho(xq, wq, B(:,:Nb), Bp(:,:Nb), lam, condA, condB)\n\n\nrmin = 0\nrmax = 30\na = 30\nZ = 2\nl = 2\ncall construct_basis()\ncall radial(Nb, xq, wq, B, Bp, Z, l)\n\nopen(newunit=u, file=\"bspline_basis.txt\", status=\"replace\")\nwrite(u,*) t\nwrite(u,*) xq\ndo i = 1, n\n write(u,*) B(:,i)\nend do\nclose(u)\n\ncontains\n\n subroutine construct_basis()\n t(:k-1) = rmin\n t(k:n+1) = meshexp(rmin, rmax, a, N_intervals)\n t(n+2:) = rmax\n\n print *, \"Constructing quadrature rule\"\n ! Loop over knot spans (intervals), and constract a global quadrature rule\n ! Integrals of a function hq evaluated at the points xq are calculated using:\n ! sum(wq*hq)\n xiq = gauss_pts(Nq)\n wtq = gauss_wts(Nq)\n do i = 1, n-k+1\n xa = t(i+k-1)\n xb = t(i+k)\n jac = (xb-xa)/2\n x = (xiq(:)+1) * jac + xa\n xq((i-1)*Nq+1:i*Nq) = x\n wq((i-1)*Nq+1:i*Nq) = wtq*jac\n end do\n\n print *, \"Evaluating basis functions\"\n ! Evaluate basis functions and their derivatives on quadrature grid\n ! Skip the first and last B-spline (that's why Nb=n-2).\n do i = 1, Nb\n B(:,i) = bspline (t, i+1, k, xq)\n Bp(:,i) = bspline_der (t, i+1, k, xq)\n Bpp(:,i) = bspline_der2(t, i+1, k, xq)\n end do\n end subroutine\n\nend program\n", "meta": {"hexsha": "a43568001ff03fa1b46f7b20ac5f1abdd436d792", "size": 2185, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/bsplines/test_schroed.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/tests/bsplines/test_schroed.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/tests/bsplines/test_schroed.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.6463414634, "max_line_length": 81, "alphanum_fraction": 0.6009153318, "num_tokens": 826, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813453, "lm_q2_score": 0.7401743505760728, "lm_q1q2_score": 0.6644510339024666}} {"text": "module barotropic_dynamics_mod\n\nuse fms_mod, only: open_namelist_file, &\n open_restart_file, &\n file_exist, &\n check_nml_error, &\n error_mesg, &\n FATAL, WARNING, &\n write_version_number, &\n mpp_pe, &\n mpp_root_pe, &\n read_data, &\n write_data, &\n set_domain, &\n close_file, &\n stdlog\n\nuse time_manager_mod, only : time_type, &\n get_time, &\n operator(==), &\n operator(-)\n\nuse constants_mod, only: radius, omega\n\nuse transforms_mod, only: transforms_init, transforms_end, &\n get_grid_boundaries, &\n trans_spherical_to_grid, trans_grid_to_spherical, & \n compute_laplacian, &\n get_sin_lat, get_cos_lat, &\n get_deg_lon, get_deg_lat, &\n get_grid_domain, get_spec_domain, &\n spectral_domain, grid_domain, &\n vor_div_from_uv_grid, uv_grid_from_vor_div, &\n horizontal_advection\n\nuse spectral_damping_mod, only: spectral_damping_init, &\n compute_spectral_damping\n\nuse leapfrog_mod, only: leapfrog\n\nuse fv_advection_mod, only: fv_advection_init, &\n a_grid_horiz_advection\n\n!===============================================================================================\nimplicit none\nprivate\n!===============================================================================================\n\npublic :: barotropic_dynamics_init, &\n barotropic_dynamics, &\n barotropic_dynamics_end, &\n dynamics_type, &\n grid_type, &\n spectral_type, &\n tendency_type\n\n\n! version information \n!===================================================================\ncharacter(len=128) :: version = '$Id: barotropic_dynamics.f90,v 10.0 2003/10/24 22:00:57 fms Exp $'\ncharacter(len=128) :: tagname = '$Name: latest $'\n!===================================================================\n\ntype grid_type\n real, pointer, dimension(:,:,:) :: u=>NULL(), v=>NULL(), vor=>NULL(), trs=>NULL(), tr=>NULL()\n real, pointer, dimension(:,:) :: pv=>NULL(), stream=>NULL()\nend type\ntype spectral_type\n complex, pointer, dimension(:,:,:) :: vor=>NULL(), trs=>NULL()\nend type\ntype tendency_type\n real, pointer, dimension(:,:) :: u=>NULL(), v=>NULL(), trs=>NULL(), tr=>NULL()\nend type\ntype dynamics_type\n type(grid_type) :: grid\n type(spectral_type) :: spec\n type(tendency_type) :: tend\n integer :: num_lon, num_lat\n logical :: grid_tracer, spec_tracer\nend type\n\ninteger, parameter :: num_time_levels = 2\n\ninteger :: is, ie, js, je, ms, me, ns, ne\n\nlogical :: module_is_initialized = .false.\n\nreal, allocatable, dimension(:) :: sin_lat, cos_lat, rad_lat, rad_lon, &\n deg_lat, deg_lon, &\n coriolis, glon_bnd, glat_bnd\n\ninteger :: pe, npes\n\n! namelist parameters with default values\n\nlogical :: check_fourier_imag = .false.\nlogical :: south_to_north = .true.\nlogical :: triang_trunc = .true.\n\nreal :: robert_coeff = 0.04\nreal :: longitude_origin = 0.0\n\ncharacter(len=64) :: damping_option = 'resolution_dependent'\ninteger :: damping_order = 4\nreal :: damping_coeff = 1.e-04\n\nreal :: zeta_0 = 8.e-05\ninteger :: m_0 = 4\nreal :: eddy_width = 15.0\nreal :: eddy_lat = 45.0\n\nlogical :: spec_tracer = .true.\nlogical :: grid_tracer = .true.\n\ninteger :: num_lat = 128\ninteger :: num_lon = 256\ninteger :: num_fourier = 85\ninteger :: num_spherical = 86\ninteger :: fourier_inc = 1\n\nreal, dimension(2) :: valid_range_v = (/-1.e3,1.e3/)\n\nnamelist /barotropic_dynamics_nml/ check_fourier_imag, south_to_north, &\n triang_trunc, &\n num_lon, num_lat, num_fourier, &\n num_spherical, fourier_inc, &\n longitude_origin, damping_option, &\n damping_order, damping_coeff, &\n robert_coeff, &\n spec_tracer, grid_tracer, &\n eddy_lat, eddy_width, zeta_0, m_0, &\n valid_range_v\n\ncontains\n\n!===============================================================================================\n\nsubroutine barotropic_dynamics_init (Dyn, Time, Time_init)\n\ntype(dynamics_type), intent(inout) :: Dyn\ntype(time_type) , intent(in) :: Time, Time_init\n\ninteger :: i, j\n\nreal, allocatable, dimension(:) :: glon_bnd, glat_bnd\ncomplex, allocatable, dimension(:,:) :: div\nreal :: xx, yy, dd\n\ninteger :: ierr, io, unit, pe\nlogical :: root\n\n! < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < >\n\ncall write_version_number (version, tagname)\n\npe = mpp_pe()\nroot = (pe == mpp_root_pe())\n\nif (file_exist('input.nml')) then\n unit = open_namelist_file ()\n ierr=1\n do while (ierr /= 0)\n read (unit, nml=barotropic_dynamics_nml, iostat=io, end=10)\n ierr = check_nml_error (io, 'barotropic_dynamics_nml')\n enddo\n 10 call close_file (unit)\nendif\n\n\nif (root) write (stdlog(), nml=barotropic_dynamics_nml)\n\ncall transforms_init(radius, num_lat, num_lon, num_fourier, fourier_inc, num_spherical, &\n south_to_north=south_to_north, &\n triang_trunc=triang_trunc, &\n longitude_origin=longitude_origin )\n\ncall get_grid_domain(is,ie,js,je)\ncall get_spec_domain(ms,me,ns,ne)\n\nDyn%num_lon = num_lon\nDyn%num_lat = num_lat\nDyn%spec_tracer = spec_tracer\nDyn%grid_tracer = grid_tracer\n\nallocate (sin_lat (js:je))\nallocate (cos_lat (js:je))\nallocate (deg_lat (js:je))\nallocate (deg_lon (is:ie))\nallocate (rad_lat (js:je))\nallocate (rad_lon (is:ie))\nallocate (coriolis (js:je))\n\nallocate (glon_bnd (num_lon + 1))\nallocate (glat_bnd (num_lat + 1))\n\ncall get_deg_lon (deg_lon)\ncall get_deg_lat (deg_lat)\ncall get_sin_lat (sin_lat)\ncall get_cos_lat (cos_lat)\ncall get_grid_boundaries (glon_bnd, glat_bnd, global=.true.)\n\ncoriolis = 2*omega*sin_lat\n\nrad_lat = deg_lat*atan(1.0)/45.0\nrad_lon = deg_lon*atan(1.0)/45.0\n\ncall spectral_damping_init(damping_coeff, damping_order, damping_option, num_fourier, num_spherical, 1, 0., 0., 0.)\n\nallocate (Dyn%spec%vor (ms:me, ns:ne, num_time_levels))\nallocate (Dyn%grid%u (is:ie, js:je, num_time_levels))\nallocate (Dyn%grid%v (is:ie, js:je, num_time_levels))\nallocate (Dyn%grid%vor (is:ie, js:je, num_time_levels))\n\nallocate (Dyn%tend%u (is:ie, js:je))\nallocate (Dyn%tend%v (is:ie, js:je))\nallocate (Dyn%grid%stream (is:ie, js:je))\nallocate (Dyn%grid%pv (is:ie, js:je))\n\nallocate (div (ms:me, ns:ne))\n\ncall fv_advection_init(num_lon, num_lat, glat_bnd, 360./float(fourier_inc))\nif(Dyn%grid_tracer) then\n allocate(Dyn%Grid%tr (is:ie, js:je, num_time_levels))\n allocate(Dyn%Tend%tr (is:ie, js:je))\nendif\n\nif(Dyn%spec_tracer) then\n allocate(Dyn%Grid%trs (is:ie, js:je, num_time_levels))\n allocate(Dyn%Tend%trs (is:ie, js:je))\n allocate(Dyn%Spec%trs (ms:me, ns:ne, num_time_levels))\nendif\n\nif(Time == Time_init) then\n\n do j = js, je\n Dyn%Grid%u(:,j,1) = 25.0*cos_lat(j) &\n - 30.0*(cos_lat(j)**3) &\n + 300.0*(sin_lat(j)**2)*(cos_lat(j)**6)\n Dyn%Grid%v(:,j,1) = 0.0\n end do\n\n call vor_div_from_uv_grid(Dyn%Grid%u (:,:,1), Dyn%Grid%v (:,:,1), &\n Dyn%Spec%vor(:,:,1), div) \n\n call trans_spherical_to_grid(Dyn%Spec%vor(:,:,1), Dyn%Grid%vor(:,:,1))\n\n do j = js, je\n do i = is, ie\n yy = (deg_lat(j)- eddy_lat)/eddy_width\n Dyn%Grid%vor(i,j,1) = Dyn%Grid%vor(i,j,1) + &\n 0.5*zeta_0*cos_lat(j)*exp(-yy*yy)*cos(m_0*rad_lon(i))\n end do\n end do\n \n call trans_grid_to_spherical(Dyn%Grid%vor(:,:,1), Dyn%Spec%vor(:,:,1))\n \n div = (0.,0.)\n call uv_grid_from_vor_div (Dyn%Spec%vor(:,:,1), div, &\n Dyn%Grid%u (:,:,1), Dyn%Grid%v (:,:,1))\n\n if(Dyn%grid_tracer) then\n Dyn%Grid%tr = 0.0\n do j = js, je\n if(deg_lat(j) > 10.0 .and. deg_lat(j) < 20.0) Dyn%Grid%tr(:,j,1) = 1.0\n if(deg_lat(j) > 70.0 ) Dyn%Grid%tr(:,j,1) = -1.0\n end do\n endif\n \n if(Dyn%spec_tracer) then\n Dyn%Grid%trs = 0.0\n do j = js, je\n if(deg_lat(j) > 10.0 .and. deg_lat(j) < 20.0) Dyn%Grid%trs(:,j,1) = 1.0\n if(deg_lat(j) > 70.0 ) Dyn%Grid%trs(:,j,1) = -1.0\n end do\n call trans_grid_to_spherical(Dyn%Grid%trs(:,:,1), Dyn%Spec%trs(:,:,1))\n endif\n \nelse\n\n call read_restart(Dyn)\n \nendif\n\nmodule_is_initialized = .true.\n\nreturn\nend subroutine barotropic_dynamics_init\n\n!===============================================================================================\n\nsubroutine barotropic_dynamics(Time, Time_init, Dyn, previous, current, future, delta_t)\n\ntype(time_type) , intent(in) :: Time, Time_init\ntype(dynamics_type), intent(inout) :: Dyn\ninteger, intent(in ) :: previous, current, future\nreal, intent(in ) :: delta_t\n\n! < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < >\n\ncomplex, dimension(ms:me, ns:ne) :: dt_vors, dt_divs, stream, zeros, spec_diss\nreal, dimension(is:ie, js:je) :: dt_vorg\ninteger :: j\n\n! < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < >\n\nif(.not.module_is_initialized) then\n call error_mesg('barotropic_dynamics','dynamics has not been initialized ', FATAL)\nendif\n\nzeros = (0.,0.)\n\ndo j = js, je\n Dyn%grid%pv(:,j) = Dyn%grid%vor(:,j,current) + coriolis(j) \nend do\n\nDyn%Tend%u = Dyn%Tend%u + Dyn%grid%pv*Dyn%Grid%v(:,:,current)\nDyn%Tend%v = Dyn%Tend%v - Dyn%grid%pv*Dyn%Grid%u(:,:,current)\n\ncall vor_div_from_uv_grid (Dyn%Tend%u, Dyn%Tend%v, dt_vors, dt_divs)\n\ncall compute_spectral_damping(Dyn%Spec%vor(:,:,previous), dt_vors, delta_t)\n\ncall leapfrog(Dyn%Spec%vor , dt_vors , previous, current, future, delta_t, robert_coeff)\n\ncall trans_spherical_to_grid(Dyn%Spec%vor(:,:,future), Dyn%Grid%vor(:,:,future))\n \ncall uv_grid_from_vor_div (Dyn%Spec%vor (:,:,future), zeros, &\n Dyn%Grid%u (:,:,future), Dyn%Grid%v (:,:,future))\n\nif(minval(Dyn%Grid%v) < valid_range_v(1) .or. maxval(Dyn%Grid%v) > valid_range_v(2)) then\n call error_mesg('barotropic_dynamics','meridional wind out of valid range', FATAL)\nendif\n\nif(Dyn%spec_tracer) call update_spec_tracer(Dyn%Spec%trs, Dyn%Grid%trs, Dyn%Tend%trs, &\n Dyn%Grid%u, Dyn%Grid%v, previous, current, future, delta_t)\n\nif(Dyn%grid_tracer) call update_grid_tracer(Dyn%Grid%tr, Dyn%Tend%tr, &\n Dyn%Grid%u, Dyn%Grid%v, previous, current, future, delta_t)\n\nstream = compute_laplacian(Dyn%Spec%vor(:,:,current), -1) \ncall trans_spherical_to_grid(stream, Dyn%grid%stream)\n\nreturn\nend subroutine barotropic_dynamics\n\n!===================================================================================\n\nsubroutine update_spec_tracer(tr_spec, tr_grid, dt_tr, ug, vg, &\n previous, current, future, delta_t)\n\ncomplex, intent(inout), dimension(ms:me, ns:ne, num_time_levels) :: tr_spec\nreal , intent(inout), dimension(is:ie, js:je, num_time_levels) :: tr_grid\nreal , intent(inout), dimension(is:ie, js:je ) :: dt_tr\nreal , intent(in ), dimension(is:ie, js:je, num_time_levels) :: ug, vg \nreal , intent(in ) :: delta_t\ninteger, intent(in ) :: previous, current, future\n\ncomplex, dimension(ms:me, ns:ne) :: dt_trs\n\ncall horizontal_advection (tr_spec(:,:,current), ug(:,:,current), vg(:,:,current), dt_tr)\ncall trans_grid_to_spherical (dt_tr, dt_trs)\ncall compute_spectral_damping (tr_spec(:,:,previous), dt_trs, delta_t)\ncall leapfrog (tr_spec, dt_trs, previous, current, future, delta_t, robert_coeff)\ncall trans_spherical_to_grid (tr_spec(:,:,future), tr_grid(:,:,future))\n\nreturn\nend subroutine update_spec_tracer\n!==========================================================================\n\nsubroutine update_grid_tracer(tr_grid, dt_tr_grid, ug, vg, &\n previous, current, future, delta_t)\n\nreal , intent(inout), dimension(is:ie, js:je, num_time_levels) :: tr_grid\nreal , intent(inout), dimension(is:ie, js:je ) :: dt_tr_grid\nreal , intent(in ), dimension(is:ie, js:je, num_time_levels) :: ug, vg\n\nreal , intent(in ) :: delta_t\ninteger, intent(in ) :: previous, current, future\n\nreal, dimension(size(tr_grid,1),size(tr_grid,2)) :: tr_current, tr_future\n\ntr_future = tr_grid(:,:,previous) + delta_t*dt_tr_grid\ndt_tr_grid = 0.0\ncall a_grid_horiz_advection (ug(:,:,current), vg(:,:,current), tr_future, delta_t, dt_tr_grid)\ntr_future = tr_future + delta_t*dt_tr_grid\ntr_current = tr_grid(:,:,current) + &\n robert_coeff*(tr_grid(:,:,previous) + tr_future - 2.0*tr_grid(:,:,current))\ntr_grid(:,:,current) = tr_current\ntr_grid(:,:,future) = tr_future\n\nreturn\nend subroutine update_grid_tracer\n\n!==========================================================================\n\nsubroutine read_restart(Dyn)\n\ntype(dynamics_type), intent(inout) :: Dyn\n\ninteger :: unit, m, n, nt\nreal, dimension(ms:me, ns:ne) :: real_part, imag_part\n\nif(file_exist('INPUT/barotropic_dynamics.res.nc')) then\n do nt = 1, 2\n call read_data('INPUT/barotropic_dynamics.res.nc', 'vors_real', real_part, spectral_domain, timelevel=nt)\n call read_data('INPUT/barotropic_dynamics.res.nc', 'vors_imag', imag_part, spectral_domain, timelevel=nt)\n do n=ns,ne\n do m=ms,me\n Dyn%Spec%vor(m,n,nt) = cmplx(real_part(m,n),imag_part(m,n))\n end do\n end do\n if(Dyn%spec_tracer) then\n call read_data('INPUT/barotropic_dynamics.res.nc', 'trs_real', real_part, spectral_domain, timelevel=nt)\n call read_data('INPUT/barotropic_dynamics.res.nc', 'trs_imag', imag_part, spectral_domain, timelevel=nt)\n do n=ns,ne\n do m=ms,me\n Dyn%Spec%trs(m,n,nt) = cmplx(real_part(m,n),imag_part(m,n))\n end do\n end do\n endif\n call read_data('INPUT/barotropic_dynamics.res.nc', 'u', Dyn%Grid%u (:,:,nt), grid_domain, timelevel=nt)\n call read_data('INPUT/barotropic_dynamics.res.nc', 'v', Dyn%Grid%v (:,:,nt), grid_domain, timelevel=nt)\n call read_data('INPUT/barotropic_dynamics.res.nc', 'vor', Dyn%Grid%vor(:,:,nt), grid_domain, timelevel=nt)\n if(Dyn%spec_tracer) then\n call read_data('INPUT/barotropic_dynamics.res.nc', 'trs', Dyn%Grid%trs(:,:,nt), grid_domain, timelevel=nt)\n endif\n if(Dyn%grid_tracer) then\n call read_data('INPUT/barotropic_dynamics.res.nc', 'tr', Dyn%Grid%tr(:,:,nt), grid_domain, timelevel=nt)\n endif\n end do\nelse if(file_exist('INPUT/barotropic_dynamics.res')) then\n unit = open_restart_file(file='INPUT/barotropic_dynamics.res',action='read')\n\n do nt = 1, 2\n call set_domain(spectral_domain)\n call read_data(unit,Dyn%Spec%vor(:,:, nt))\n if(Dyn%spec_tracer) call read_data(unit,Dyn%Spec%trs(:,:, nt))\n\n call set_domain(grid_domain)\n call read_data(unit,Dyn%Grid%u (:,:, nt))\n call read_data(unit,Dyn%Grid%v (:,:, nt))\n call read_data(unit,Dyn%Grid%vor (:,:, nt))\n if(Dyn%spec_tracer) call read_data(unit,Dyn%Grid%trs(:,:, nt))\n if(Dyn%grid_tracer) call read_data(unit,Dyn%Grid%tr (:,:, nt))\n \n end do\n call close_file(unit)\n \nelse\n call error_mesg('read_restart', 'restart does not exist', FATAL)\nendif\n \nreturn\nend subroutine read_restart\n\n!====================================================================\n\nsubroutine write_restart(Dyn, previous, current)\n\ntype(dynamics_type), intent(in) :: Dyn\ninteger, intent(in) :: previous, current\n\ninteger :: unit, nt, nn\n\ndo nt = 1, 2\n if(nt == 1) nn = previous\n if(nt == 2) nn = current\n call write_data('RESTART/barotropic_dynamics.res.nc', 'vors_real', real(Dyn%Spec%vor(:,:,nn)), spectral_domain)\n call write_data('RESTART/barotropic_dynamics.res.nc', 'vors_imag', aimag(Dyn%Spec%vor(:,:,nn)), spectral_domain)\n if(Dyn%spec_tracer) then\n call write_data('RESTART/barotropic_dynamics.res.nc', 'trs_real', real(Dyn%Spec%trs(:,:,nn)), spectral_domain)\n call write_data('RESTART/barotropic_dynamics.res.nc', 'trs_imag', aimag(Dyn%Spec%trs(:,:,nn)), spectral_domain)\n endif\n call write_data('RESTART/barotropic_dynamics.res.nc', 'u', Dyn%Grid%u (:,:,nn), grid_domain)\n call write_data('RESTART/barotropic_dynamics.res.nc', 'v', Dyn%Grid%v (:,:,nn), grid_domain)\n call write_data('RESTART/barotropic_dynamics.res.nc', 'vor', Dyn%Grid%vor(:,:,nn), grid_domain)\n if(Dyn%spec_tracer) then\n call write_data('RESTART/barotropic_dynamics.res.nc', 'trs', Dyn%Grid%trs(:,:,nn), grid_domain)\n endif\n if(Dyn%grid_tracer) then\n call write_data('RESTART/barotropic_dynamics.res.nc', 'tr', Dyn%Grid%tr(:,:,nn), grid_domain)\n endif\nenddo\n\n!unit = open_restart_file(file='RESTART/barotropic_dynamics.res', action='write')\n\n!do nt = 1, 2\n! if(nt == 1) nn = previous\n! if(nt == 2) nn = current\n \n! call set_domain(spectral_domain)\n! call write_data(unit,Dyn%Spec%vor(:,:, nn))\n! if(Dyn%spec_tracer) call write_data(unit,Dyn%Spec%trs(:,:, nn))\n\n! call set_domain(grid_domain)\n! call write_data(unit,Dyn%Grid%u (:,:, nn))\n! call write_data(unit,Dyn%Grid%v (:,:, nn))\n! call write_data(unit,Dyn%Grid%vor (:,:, nn))\n! if(Dyn%spec_tracer) call write_data(unit,Dyn%Grid%trs(:,:, nn))\n! if(Dyn%grid_tracer) call write_data(unit,Dyn%Grid%tr (:,:, nn))\n!end do\n\n!call close_file(unit)\n\nend subroutine write_restart\n\n!====================================================================\n\nsubroutine barotropic_dynamics_end (Dyn, previous, current)\n\ntype(dynamics_type), intent(inout) :: Dyn\ninteger, intent(in) :: previous, current\n\nif(.not.module_is_initialized) then\n call error_mesg('barotropic_dynamics','dynamics has not been initialized ', FATAL)\nendif\n\ncall transforms_end()\n\ncall write_restart (Dyn, previous, current)\n\nmodule_is_initialized = .false.\n\nreturn\nend subroutine barotropic_dynamics_end\n!===================================================================================\n\nend module barotropic_dynamics_mod\n", "meta": {"hexsha": "1564a35da5f45d02e5869f9e97b8942a1bff61b5", "size": 19348, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fms_dynamical_cores/_fortran/src/atmos_spectral_barotropic/barotropic_dynamics.f90", "max_stars_repo_name": "JoyMonteiro/FMSDynamicalCore", "max_stars_repo_head_hexsha": "b46a8943de28f8b16a1d36f5607f10e928ed6667", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-05-23T13:35:20.000Z", "max_stars_repo_stars_event_max_datetime": "2018-05-23T13:35:20.000Z", "max_issues_repo_path": "fms_dynamical_cores/_fortran/src/atmos_spectral_barotropic/barotropic_dynamics.f90", "max_issues_repo_name": "JoyMonteiro/fms_dynamical_cores", "max_issues_repo_head_hexsha": "b46a8943de28f8b16a1d36f5607f10e928ed6667", "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": "fms_dynamical_cores/_fortran/src/atmos_spectral_barotropic/barotropic_dynamics.f90", "max_forks_repo_name": "JoyMonteiro/fms_dynamical_cores", "max_forks_repo_head_hexsha": "b46a8943de28f8b16a1d36f5607f10e928ed6667", "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": 36.5746691871, "max_line_length": 115, "alphanum_fraction": 0.5666218731, "num_tokens": 5358, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333484, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6644510309441554}} {"text": " FUNCTION bessj1(x)\n REAL bessj1,x\n REAL ax,xx,z\n DOUBLE PRECISION p1,p2,p3,p4,p5,q1,q2,q3,q4,q5,r1,r2,r3,r4,r5,r6,\n *s1,s2,s3,s4,s5,s6,y\n SAVE p1,p2,p3,p4,p5,q1,q2,q3,q4,q5,r1,r2,r3,r4,r5,r6,s1,s2,s3,s4,\n *s5,s6\n DATA r1,r2,r3,r4,r5,r6/72362614232.d0,-7895059235.d0,\n *242396853.1d0,-2972611.439d0,15704.48260d0,-30.16036606d0/,s1,s2,\n *s3,s4,s5,s6/144725228442.d0,2300535178.d0,18583304.74d0,\n *99447.43394d0,376.9991397d0,1.d0/\n DATA p1,p2,p3,p4,p5/1.d0,.183105d-2,-.3516396496d-4,\n *.2457520174d-5,-.240337019d-6/, q1,q2,q3,q4,q5/.04687499995d0,\n *-.2002690873d-3,.8449199096d-5,-.88228987d-6,.105787412d-6/\n if(abs(x).lt.8.)then\n y=x**2\n bessj1=x*(r1+y*(r2+y*(r3+y*(r4+y*(r5+y*r6)))))/(s1+y*(s2+y*(s3+\n *y*(s4+y*(s5+y*s6)))))\n else\n ax=abs(x)\n z=8./ax\n y=z**2\n xx=ax-2.356194491\n bessj1=sqrt(.636619772/ax)*(cos(xx)*(p1+y*(p2+y*(p3+y*(p4+y*\n *p5))))-z*sin(xx)*(q1+y*(q2+y*(q3+y*(q4+y*q5)))))*sign(1.,x)\n endif\n return\n END\n\n FUNCTION bessj0(x)\n REAL bessj0,x\n REAL ax,xx,z\n DOUBLE PRECISION p1,p2,p3,p4,p5,q1,q2,q3,q4,q5,r1,r2,r3,r4,r5,r6,\n *s1,s2,s3,s4,s5,s6,y\n SAVE p1,p2,p3,p4,p5,q1,q2,q3,q4,q5,r1,r2,r3,r4,r5,r6,s1,s2,s3,s4,\n *s5,s6\n DATA p1,p2,p3,p4,p5/1.d0,-.1098628627d-2,.2734510407d-4,\n *-.2073370639d-5,.2093887211d-6/, q1,q2,q3,q4,q5/-.1562499995d-1,\n *.1430488765d-3,-.6911147651d-5,.7621095161d-6,-.934945152d-7/\n DATA r1,r2,r3,r4,r5,r6/57568490574.d0,-13362590354.d0,\n *651619640.7d0,-11214424.18d0,77392.33017d0,-184.9052456d0/,s1,s2,\n *s3,s4,s5,s6/57568490411.d0,1029532985.d0,9494680.718d0,\n *59272.64853d0,267.8532712d0,1.d0/\n if(abs(x).lt.8.)then\n y=x**2\n bessj0=(r1+y*(r2+y*(r3+y*(r4+y*(r5+y*r6)))))/(s1+y*(s2+y*(s3+y*\n *(s4+y*(s5+y*s6)))))\n else\n ax=abs(x)\n z=8./ax\n y=z**2\n xx=ax-.785398164\n bessj0=sqrt(.636619772/ax)*(cos(xx)*(p1+y*(p2+y*(p3+y*(p4+y*\n *p5))))-z*sin(xx)*(q1+y*(q2+y*(q3+y*(q4+y*q5)))))\n endif\n return\n END\nC (C) Copr. 1986-92 Numerical Recipes Software =v1.9\"217..\n", "meta": {"hexsha": "ae3b17d9353507c6c39afb5f8f02c151b5a42bb6", "size": 2201, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/amuse/community/galactics/gas_src/src/bessj01.f", "max_stars_repo_name": "rknop/amuse", "max_stars_repo_head_hexsha": "85d5bdcc29cfc87dc69d91c264101fafd6658aec", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 131, "max_stars_repo_stars_event_min_datetime": "2015-06-04T09:06:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-01T12:11:29.000Z", "max_issues_repo_path": "src/amuse/community/galactics/gas_src/src/bessj01.f", "max_issues_repo_name": "rknop/amuse", "max_issues_repo_head_hexsha": "85d5bdcc29cfc87dc69d91c264101fafd6658aec", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 690, "max_issues_repo_issues_event_min_datetime": "2015-10-17T12:18:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:15:58.000Z", "max_forks_repo_path": "src/amuse/community/galactics/gas_src/src/bessj01.f", "max_forks_repo_name": "rieder/amuse", "max_forks_repo_head_hexsha": "3ac3b6b8f922643657279ddee5c8ab3fc0440d5e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 102, "max_forks_repo_forks_event_min_datetime": "2015-01-22T10:00:29.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-09T13:29:43.000Z", "avg_line_length": 37.3050847458, "max_line_length": 71, "alphanum_fraction": 0.5679236711, "num_tokens": 1084, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901036, "lm_q2_score": 0.7745833841649232, "lm_q1q2_score": 0.6644129215919676}} {"text": "C SUBROUTINE INTERP.F \nC\nC SOURCE\nC BEVINGTON, PAGES 266-267.\nC\nC PURPOSE\nC INTERPOLATE BETWEEN DATA POINTS TO EVALUATE A FUNCTION\nC\nC USAGE \nC CALL INTERP (X, Y, NPTS, NTERMS, XIN, YOUT) \nC\nC DESCRIPTION OF PARAMETERS\nC X\t - ARRAY OF DATA POINTS FOR INDEPENDENT VARIABLE\nC Y\t - ARRAY OF DATA POINTS FOR DEPENDENT VARIABLE\nC NPTS - NUMBER OF PAIRS OF DATA POINTS\nC NTERMS - NUMBER OF TERMS IN FITTING POLYNOMIAL\nC XIN - INPUT VALUE OF X\nC YOUT - INTERPOLATED VALUE OF Y\nC\nC SUBROUTINES AND FUNCTION SUBPROGRAMS REQUIRED \nC NONE\nC\nC COMMENTS\nC DIMENSION STATEMENT VALID FOR NTERMS UP TO 10\nC VALUE OF NTERMS MAY BE MODIFIED BY THE PROGRAM\nC\n\tSUBROUTINE INTERP (X,Y,NPTS,NTERMS,XIN,YOUT)\n\tDOUBLE PRECISION DELTAX,DELTA,A,PROD,SUM\n\tDIMENSION X(1),Y(1)\n\tDIMENSION DELTA(10),A(10)\nC\nC SEARCH FOR APPROPRIATE VALUE OF X(1)\nC\n11\tDO 19 I=1,NPTS\n\tIF (XIN-X(I)) 13,17,19\n13\tI1=I-NTERMS/2\n\tIF (I1) 15,15,21\n15\tI1=1\n\tGOTO 21 \n17\tYOUT=Y(I)\n18\tGOTO 61 \n19\tCONTINUE\n\tI1=NPTS-NTERMS+1\n21\tI2=I1+NTERMS-1\n\tIF (NPTS-I2) 23,31,31\n23\tI2=NPTS \n\tI1=I2-NTERMS+1\n25\tIF (I1) 26,26,31\n26\tI1=1\n27\tNTERMS=I2-I1+1\nC\nC EVALUATE DEVIATIONS DELTA\nC\n31\tDENOM=X(I1+1)-X(I1)\n\tDELTAX=(XIN-X(I1))/DENOM\n\tDO 35 I=1,NTERMS\n\tIX=I1+I-1\n35\tDELTA(I)=(X(IX)-X(I1))/DENOM\nC\nC ACCUMULATE COEFFICIENTS A\nC\n40\tA(1)=Y(I1)\n41\tDO 50 K=2,NTERMS\n\tPROD=1. \n\tSUM=0.\n\tIMAX=K-1\n\tIXMAX=I1+IMAX\n\tDO 49 I=1,IMAX\n\tJ=K-I\n\tPROD=PROD*(DELTA(K)-DELTA(J))\n49\tSUM=SUM-A(J)/PROD\n50\tA(K)=SUM+Y(IXMAX)/PROD\nC\nC ACCUMULATE SUM OF EXPANSION\nC\n51\tSUM=A(1)\n\tDO 57 J=2,NTERMS\n\tPROD=1. \n\tIMAX=J-1\n\tDO 56 I=1,IMAX\n56\tPROD=PROD*(DELTAX-DELTA(I))\n57\tSUM=SUM+A(J)*PROD\n60\tYOUT=SUM\n61\tRETURN\n\tEND\n", "meta": {"hexsha": "75ca1b23e41698ebcb8905ef1b08d6f6617dcac2", "size": 1650, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iraf.v2161/math/bevington/interp.f", "max_stars_repo_name": "ysBach/irafdocgen", "max_stars_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:19:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T16:48:42.000Z", "max_issues_repo_path": "math/bevington/interp.f", "max_issues_repo_name": "kirxkirx/iraf", "max_issues_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-30T13:48:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-02T19:40:25.000Z", "max_forks_repo_path": "math/bevington/interp.f", "max_forks_repo_name": "kirxkirx/iraf", "max_forks_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.1860465116, "max_line_length": 58, "alphanum_fraction": 0.6993939394, "num_tokens": 764, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680904463334, "lm_q2_score": 0.7745833841649232, "lm_q1q2_score": 0.6644129103266049}} {"text": " PROGRAM LA_SPTSVX_EXAMPLE\n\n! -- LAPACK95 EXAMPLE DRIVER ROUTINE (VERSION 1.0) --\n! UNI-C, DENMARK\n! DECEMBER, 1999\n!\n! .. \"Use Statements\" ..\n USE LA_PRECISION, ONLY: WP => SP\n USE F95_LAPACK, ONLY: LA_PTSVX\n! .. \"IMPLICIT STATEMENT\" ..\n IMPLICIT NONE\n! .. \"Parameters\" ..\n REAL(WP), PARAMETER :: ONE = 1.0_WP, THREE = 3.0_WP\n! .. \"Local Scalars\" ..\n INTEGER :: I, J, INFO, N, NRHS\n REAL(WP) :: RCOND\n! .. \"Local Arrays\" ..\n REAL(WP), ALLOCATABLE :: A(:), D(:), E(:), B(:,:), X(:,:), FERR(:), BERR(:)\n! .. \"Executable Statements\" ..\n WRITE (*,*) 'SPTSVX Program Results.'\n N = 5; NRHS = 3\n WRITE(*,'(5H N = , I4, 9H; NRHS = , I4)') N, NRHS \n ALLOCATE ( A(N), D(N), E(N-1), B(N,NRHS), X(N,NRHS), FERR(NRHS), BERR(NRHS) )\n \n OPEN(UNIT=21,FILE='ptsv.ma',STATUS='UNKNOWN')\n DO I=1,N\n READ(21,'(F3.0)') A(I);\n ENDDO;\n CLOSE(21)\n\n E = THREE; D(1) = 2*E(1)+ONE; D(2:N) = 2*E+ONE\n B(1,1) = D(1)+E(1); B(N,1) = E(N-1)+D(N)\n B(2:N-1,1) = 2*E + D(2:N-1)\n DO I = 2, NRHS; B(:,I) = B(:,1)*I; ENDDO\n WRITE(*,*) ' on entry:'\n WRITE (*,'(2HD:,8(1X,F9.2))') D\n WRITE (*,'(2HE:,8(1X,F9.2))') E\n WRITE(*,*) 'The RHS matrix B:'\n DO J = 1, N; WRITE (*,'(3(F9.5))') B(J,:); \n ENDDO \n \n CALL LA_PTSVX( D, E, B, X, FERR=FERR, BERR=BERR, RCOND=RCOND, INFO=INFO)\n\n WRITE(*,*) 'FERR on exit :'\n DO I = 1, N-1; WRITE (*,'(E13.5)') FERR(I); \n ENDDO\n WRITE(*,*)'BERR on exit :'\n DO I = 1, N-1; WRITE (*,'(E13.5)') BERR(I); \n ENDDO\n WRITE(*,*) 'RCOND =', RCOND\n WRITE(*,*) 'The matrix X on exit:'\n DO J = 1, N; WRITE (*,'(7(F9.5))') X(J,:); \n ENDDO\n WRITE(*,*)'INFO = ' ,INFO\n\n WRITE(*,*) '\\noindent'\n WRITE(*,*) 'The solution of the system $ A\\,X = B $ is:'\n WRITE(*,*) '$$ X = \\left( \\begin{array}{rrr}'\n DO I=1,N; WRITE(*,\"(2(F9.5,' & '),F9.5,' \\\\')\") X(I,:); ENDDO\n WRITE(*,*) '\\end{array} \\right). $$'\n\n END PROGRAM LA_SPTSVX_EXAMPLE\n", "meta": {"hexsha": "c8a114e4e609f32116f06d6f0f26a66620056fa6", "size": 2079, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "EXAMPLES1/la_ptsvx_example.f90", "max_stars_repo_name": "MattBurn/LAPACK95", "max_stars_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-12-29T15:07:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T10:09:22.000Z", "max_issues_repo_path": "EXAMPLES1/la_ptsvx_example.f90", "max_issues_repo_name": "MattBurn/LAPACK95", "max_issues_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-12-30T15:38:47.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-31T06:45:11.000Z", "max_forks_repo_path": "EXAMPLES1/la_ptsvx_example.f90", "max_forks_repo_name": "MattBurn/LAPACK95", "max_forks_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-12-29T15:34:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-15T07:12:40.000Z", "avg_line_length": 33.0, "max_line_length": 83, "alphanum_fraction": 0.4627224627, "num_tokens": 858, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357529306639, "lm_q2_score": 0.766293653760418, "lm_q1q2_score": 0.6644039950541535}} {"text": " SUBROUTINE CROSS(LX,X,LY,Y,LG,G)\n!\n! CROSS COMPUTES THE CROSS PRODUCT BETWEEN TWO VECTORS.\n! REFERENCE: EAR MULTICHANNEL VOLUME, P. 27.\n!\n! INPUTS ARE\n! LX= LENGTH OF X SERIES\n! X= X SERIES\n! LY= LENGTH OF Y SERIES\n! Y= Y SERIES\n! LG= NUMBER OF LAGS,FROM 0 TO LG-1,DESIRED IN CROSS PRODUCT\n! OUTPUT IS\n! G= CROSS PRODUCT GIVEN BY (WHERE THE SUM IS OVER ALL I)\n!\n!\n! G(K) = SUM X(I+K)*Y(I)\n!\n! WHERE VALUES OF X AND Y OUTSIDE OF THEIR RANGES ARE\n! TAKEN TO BE ZERO.\n!\n DIMENSION X(*),Y(*),G(*)\n\n if(lg .gt. 0) then\n\n DO I=1,LG\nc 1 call dotpr(x(i),1,y,1,g(i),min0(ly+i-1,lx)-i+1)\n CALL DOT(MIN0(LY+I-1,LX)-I+1,X(I),Y,G(I))\n enddo\n\n else if(lg .lt. 0) then\n\n lg2=-lg\n lg1=lg2+1\n do 2 i=1,lg1\nc call dotpr(x(i),1,y,1,g(i+lg2-1),min0(ly+i-1,lx)-i+1)\n call dot(min0(ly+i-1,lx)-i+1,x(i),y,g(i+lg2-1))\n 2 continue\n do 3 i=1,lg2\n ii=lg2-i+1\nc call dotpr(y(i),1,x,1,g(ii),min0(lx+i-1,ly)-i+1)\n call dot(min0(lx+i-1,ly)-i+1,y(i),x,g(ii))\n 3 continue\n\n endif\n\n RETURN\n END\n\n", "meta": {"hexsha": "78f89650aec85d494dfa1e24ec87bf4632fdbcca", "size": 1274, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "cross.f", "max_stars_repo_name": "henkart/sioseis-2020.5.0", "max_stars_repo_head_hexsha": "1c7e606b5a3a615abf3cdd6687115f8a4117e855", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cross.f", "max_issues_repo_name": "henkart/sioseis-2020.5.0", "max_issues_repo_head_hexsha": "1c7e606b5a3a615abf3cdd6687115f8a4117e855", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cross.f", "max_forks_repo_name": "henkart/sioseis-2020.5.0", "max_forks_repo_head_hexsha": "1c7e606b5a3a615abf3cdd6687115f8a4117e855", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.0, "max_line_length": 69, "alphanum_fraction": 0.4748822606, "num_tokens": 469, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357563664174, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6644039930593811}} {"text": " program test\n\n implicit none\n integer,parameter :: t = 10*9*8*7*6*5*4*3*2 !computed at compile time\n\n write(*,*) t !write the value the console.\n\n end program test\n", "meta": {"hexsha": "86bf133fba451f2ec3e6f4c618107c24e80277fe", "size": 173, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Compile-time-calculation/Fortran/compile-time-calculation.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/Compile-time-calculation/Fortran/compile-time-calculation.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/Compile-time-calculation/Fortran/compile-time-calculation.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 19.2222222222, "max_line_length": 73, "alphanum_fraction": 0.6589595376, "num_tokens": 57, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8670357666736773, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.6644039917026316}} {"text": "PROGRAM mclqn\n \n! Code converted using TO_F90 by Alan Miller\n! Date: 2004-06-28 Time: 12:58:10\n\n! ==========================================================\n! Purpose: This program computes the Legendre polynomials\n! Qn(z) and Qn'(z) for a complex argument using\n! subroutine CLQN\n! Input : x --- Real part of z\n! y --- Imaginary part of z\n! n --- Degree of Qn(z), n = 0,1,...\n! Output: CQN(n) --- Qn(z)\n! CQD(n) --- Qn'(z)\n! Examples:\n\n! z = 0.5 + 0.5 i\n! n Re[Qn(z)] Im[Qn(z)] Re[Qn'(z)] Im[Qn'(z)]\n! -----------------------------------------------------------\n! 0 .402359D+00 .553574D+00 .800000D+00 .400000D+00\n! 1 -.107561D+01 .477967D+00 .602359D+00 .115357D+01\n! 2 -.136636D+01 -.725018D+00 -.242682D+01 .183390D+01\n! 3 .182619D+00 -.206146D+01 -.622944D+01 -.247151D+01\n! 4 .298834D+01 -.110022D+01 -.114849D+01 -.125963D+02\n! 5 .353361D+01 .334847D+01 .206656D+02 -.123735D+02\n\n! z = 3.0 + 2.0 i\n! n Re[Qn(z)] Im[Qn(z)] Re[Qn'(z)] Im[Qn'(z)]\n! -----------------------------------------------------------\n! 0 .229073D+00 -.160875D+00 -.250000D-01 .750000D-01\n! 1 .896860D-02 -.244805D-01 .407268D-02 .141247D-01\n! 2 -.736230D-03 -.281865D-02 .190581D-02 .155860D-02\n! 3 -.264727D-03 -.227023D-03 .391535D-03 .314880D-04\n! 4 -.430648D-04 -.443187D-05 .527190D-04 -.305592D-04\n! 5 -.481362D-05 .265297D-05 .395108D-05 -.839883D-05\n! ==========================================================\n\nIMPLICIT DOUBLE PRECISION (x,y)\nIMPLICIT COMPLEX*16 (c,z)\nDIMENSION cqn(0:100),cqd(0:100)\nWRITE(*,*)' Please enter Nmax, x and y (z=x+iy)'\n! READ(*,*)N,X,Y\nn=5\nx=.5\ny=.5\nWRITE(*,30)x,y\nWRITE(*,*)\nCALL clqn(n,x,y,cqn,cqd)\nWRITE(*,*)' n Re[Qn(z)] Im[Qn(z)] Re[Qn''(Z)]', ' Im[Qn''(Z)]'\nWRITE(*,*)' ---------------------------------------------', '--------------'\nDO k=0,n\n WRITE(*,20)k,cqn(k),cqd(k)\nEND DO\n20 FORMAT(1X,i3,4D14.6)\n30 FORMAT(3X,'x =',f5.1,', ','y =',f5.1)\nEND PROGRAM mclqn\n\n\nSUBROUTINE clqn(n,x,y,cqn,cqd)\n\n! ==================================================\n! Purpose: Compute the Legendre functions Qn(z) and\n! their derivatives Qn'(z) for a complex\n! argument\n! Input : x --- Real part of z\n! y --- Imaginary part of z\n! n --- Degree of Qn(z), n = 0,1,2,...\n! Output: CQN(n) --- Qn(z)\n! CQD(n) --- Qn'(z)\n! ==================================================\n\n\nINTEGER, INTENT(IN) :: n\nDOUBLE PRECISION, INTENT(IN OUT) :: x\nDOUBLE PRECISION, INTENT(IN OUT) :: y\nCOMPLEX, INTENT(OUT) :: cqn(0:n)\nCOMPLEX, INTENT(OUT) :: cqd(0:n)\nIMPLICIT DOUBLE PRECISION (x,y)\nIMPLICIT COMPLEX*16 (c,z)\n\n\nz=CMPLX(x,y)\nIF (z == 1.0D0) THEN\n DO k=0,n\n cqn(k)=(1.0D+300,0.0D0)\n cqd(k)=(1.0D+300,0.0D0)\n END DO\n RETURN\nEND IF\nls=1\nIF (CDABS(z) > 1.0D0) ls=-1\ncq0=0.5D0*CDLOG(ls*(1.0D0+z)/(1.0D0-z))\ncq1=z*cq0-1.0D0\ncqn(0)=cq0\ncqn(1)=cq1\nIF (CDABS(z) < 1.0001D0) THEN\n cqf0=cq0\n cqf1=cq1\n DO k=2,n\n cqf2=((2.0D0*k-1.0D0)*z*cqf1-(k-1.0D0)*cqf0)/k\n cqn(k)=cqf2\n cqf0=cqf1\n cqf1=cqf2\n END DO\nELSE\n IF (CDABS(z) > 1.1D0) THEN\n km=40+n\n ELSE\n km=(40+n)*INT(-1.0-1.8*LOG(CDABS(z-1.0)))\n END IF\n cqf2=0.0D0\n cqf1=1.0D0\n DO k=km,0,-1\n cqf0=((2*k+3.0D0)*z*cqf1-(k+2.0D0)*cqf2)/(k+1.0D0)\n IF (k <= n) cqn(k)=cqf0\n cqf2=cqf1\n cqf1=cqf0\n END DO\n DO k=0,n\n cqn(k)=cqn(k)*cq0/cqf0\n END DO\nEND IF\ncqd(0)=(cqn(1)-z*cqn(0))/(z*z-1.0D0)\nDO k=1,n\n cqd(k)=(k*z*cqn(k)-k*cqn(k-1))/(z*z-1.0D0)\nEND DO\nRETURN\nEND SUBROUTINE clqn\n", "meta": {"hexsha": "be845c76527bf08c6138885a3c879d1f8bed6a2b", "size": 3903, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "MATLAB/f2matlab/comp_spec_func/mclqn.f90", "max_stars_repo_name": "vasaantk/bin", "max_stars_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MATLAB/f2matlab/comp_spec_func/mclqn.f90", "max_issues_repo_name": "vasaantk/bin", "max_issues_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MATLAB/f2matlab/comp_spec_func/mclqn.f90", "max_forks_repo_name": "vasaantk/bin", "max_forks_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.2558139535, "max_line_length": 77, "alphanum_fraction": 0.4586215731, "num_tokens": 1617, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6644039910646086}} {"text": "*DECK DPCHBS\n SUBROUTINE DPCHBS (N, X, F, D, INCFD, KNOTYP, NKNOTS, T, BCOEF,\n + NDIM, KORD, IERR)\nC***BEGIN PROLOGUE DPCHBS\nC***PURPOSE Piecewise Cubic Hermite to B-Spline converter.\nC***LIBRARY SLATEC (PCHIP)\nC***CATEGORY E3\nC***TYPE DOUBLE PRECISION (PCHBS-S, DPCHBS-D)\nC***KEYWORDS B-SPLINES, CONVERSION, CUBIC HERMITE INTERPOLATION,\nC PIECEWISE CUBIC INTERPOLATION\nC***AUTHOR Fritsch, F. N., (LLNL)\nC Computing and Mathematics Research Division\nC Lawrence Livermore National Laboratory\nC P.O. Box 808 (L-316)\nC Livermore, CA 94550\nC FTS 532-4275, (510) 422-4275\nC***DESCRIPTION\nC\nC *Usage:\nC\nC INTEGER N, INCFD, KNOTYP, NKNOTS, NDIM, KORD, IERR\nC PARAMETER (INCFD = ...)\nC DOUBLE PRECISION X(nmax), F(INCFD,nmax), D(INCFD,nmax),\nC * T(2*nmax+4), BCOEF(2*nmax)\nC\nC CALL DPCHBS (N, X, F, D, INCFD, KNOTYP, NKNOTS, T, BCOEF,\nC * NDIM, KORD, IERR)\nC\nC *Arguments:\nC\nC N:IN is the number of data points, N.ge.2 . (not checked)\nC\nC X:IN is the real array of independent variable values. The\nC elements of X must be strictly increasing:\nC X(I-1) .LT. X(I), I = 2(1)N. (not checked)\nC nmax, the dimension of X, must be .ge.N.\nC\nC F:IN is the real array of dependent variable values.\nC F(1+(I-1)*INCFD) is the value corresponding to X(I).\nC nmax, the second dimension of F, must be .ge.N.\nC\nC D:IN is the real array of derivative values at the data points.\nC D(1+(I-1)*INCFD) is the value corresponding to X(I).\nC nmax, the second dimension of D, must be .ge.N.\nC\nC INCFD:IN is the increment between successive values in F and D.\nC This argument is provided primarily for 2-D applications.\nC It may have the value 1 for one-dimensional applications,\nC in which case F and D may be singly-subscripted arrays.\nC\nC KNOTYP:IN is a flag to control the knot sequence.\nC The knot sequence T is normally computed from X by putting\nC a double knot at each X and setting the end knot pairs\nC according to the value of KNOTYP:\nC KNOTYP = 0: Quadruple knots at X(1) and X(N). (default)\nC KNOTYP = 1: Replicate lengths of extreme subintervals:\nC T( 1 ) = T( 2 ) = X(1) - (X(2)-X(1)) ;\nC T(M+4) = T(M+3) = X(N) + (X(N)-X(N-1)).\nC KNOTYP = 2: Periodic placement of boundary knots:\nC T( 1 ) = T( 2 ) = X(1) - (X(N)-X(N-1));\nC T(M+4) = T(M+3) = X(N) + (X(2)-X(1)) .\nC Here M=NDIM=2*N.\nC If the input value of KNOTYP is negative, however, it is\nC assumed that NKNOTS and T were set in a previous call.\nC This option is provided for improved efficiency when used\nC in a parametric setting.\nC\nC NKNOTS:INOUT is the number of knots.\nC If KNOTYP.GE.0, then NKNOTS will be set to NDIM+4.\nC If KNOTYP.LT.0, then NKNOTS is an input variable, and an\nC error return will be taken if it is not equal to NDIM+4.\nC\nC T:INOUT is the array of 2*N+4 knots for the B-representation.\nC If KNOTYP.GE.0, T will be returned by DPCHBS with the\nC interior double knots equal to the X-values and the\nC boundary knots set as indicated above.\nC If KNOTYP.LT.0, it is assumed that T was set by a\nC previous call to DPCHBS. (This routine does **not**\nC verify that T forms a legitimate knot sequence.)\nC\nC BCOEF:OUT is the array of 2*N B-spline coefficients.\nC\nC NDIM:OUT is the dimension of the B-spline space. (Set to 2*N.)\nC\nC KORD:OUT is the order of the B-spline. (Set to 4.)\nC\nC IERR:OUT is an error flag.\nC Normal return:\nC IERR = 0 (no errors).\nC \"Recoverable\" errors:\nC IERR = -4 if KNOTYP.GT.2 .\nC IERR = -5 if KNOTYP.LT.0 and NKNOTS.NE.(2*N+4).\nC\nC *Description:\nC DPCHBS computes the B-spline representation of the PCH function\nC determined by N,X,F,D. To be compatible with the rest of PCHIP,\nC DPCHBS includes INCFD, the increment between successive values of\nC the F- and D-arrays.\nC\nC The output is the B-representation for the function: NKNOTS, T,\nC BCOEF, NDIM, KORD.\nC\nC *Caution:\nC Since it is assumed that the input PCH function has been\nC computed by one of the other routines in the package PCHIP,\nC input arguments N, X, INCFD are **not** checked for validity.\nC\nC *Restrictions/assumptions:\nC 1. N.GE.2 . (not checked)\nC 2. X(i).LT.X(i+1), i=1,...,N . (not checked)\nC 3. INCFD.GT.0 . (not checked)\nC 4. KNOTYP.LE.2 . (error return if not)\nC *5. NKNOTS = NDIM+4 = 2*N+4 . (error return if not)\nC *6. T(2*k+1) = T(2*k) = X(k), k=1,...,N . (not checked)\nC\nC * Indicates this applies only if KNOTYP.LT.0 .\nC\nC *Portability:\nC Argument INCFD is used only to cause the compiler to generate\nC efficient code for the subscript expressions (1+(I-1)*INCFD) .\nC The normal usage, in which DPCHBS is called with one-dimensional\nC arrays F and D, is probably non-Fortran 77, in the strict sense,\nC but it works on all systems on which DPCHBS has been tested.\nC\nC *See Also:\nC PCHIC, PCHIM, or PCHSP can be used to determine an interpolating\nC PCH function from a set of data.\nC The B-spline routine DBVALU can be used to evaluate the\nC B-representation that is output by DPCHBS.\nC (See BSPDOC for more information.)\nC\nC***REFERENCES F. N. Fritsch, \"Representations for parametric cubic\nC splines,\" Computer Aided Geometric Design 6 (1989),\nC pp.79-82.\nC***ROUTINES CALLED DPCHKT, XERMSG\nC***REVISION HISTORY (YYMMDD)\nC 870701 DATE WRITTEN\nC 900405 Converted Fortran to upper case.\nC 900405 Removed requirement that X be dimensioned N+1.\nC 900406 Modified to make PCHKT a subsidiary routine to simplify\nC usage. In the process, added argument INCFD to be com-\nC patible with the rest of PCHIP.\nC 900410 Converted prologue to SLATEC 4.0 format.\nC 900410 Added calls to XERMSG and changed constant 3. to 3 to\nC reduce single/double differences.\nC 900411 Added reference.\nC 900430 Produced double precision version.\nC 900501 Corrected declarations.\nC 930317 Minor cosmetic changes. (FNF)\nC 930514 Corrected problems with dimensioning of arguments and\nC clarified DESCRIPTION. (FNF)\nC 930604 Removed NKNOTS from DPCHKT call list. (FNF)\nC***END PROLOGUE DPCHBS\nC\nC*Internal Notes:\nC\nC**End\nC\nC Declare arguments.\nC\n INTEGER N, INCFD, KNOTYP, NKNOTS, NDIM, KORD, IERR\n DOUBLE PRECISION X(*), F(INCFD,*), D(INCFD,*), T(*), BCOEF(*)\nC\nC Declare local variables.\nC\n INTEGER K, KK\n DOUBLE PRECISION DOV3, HNEW, HOLD\n CHARACTER*8 LIBNAM, SUBNAM\nC***FIRST EXECUTABLE STATEMENT DPCHBS\nC\nC Initialize.\nC\n NDIM = 2*N\n KORD = 4\n IERR = 0\n LIBNAM = 'SLATEC'\n SUBNAM = 'DPCHBS'\nC\nC Check argument validity. Set up knot sequence if OK.\nC\n IF ( KNOTYP.GT.2 ) THEN\n IERR = -1\n CALL XERMSG (LIBNAM, SUBNAM, 'KNOTYP GREATER THAN 2', IERR, 1)\n RETURN\n ENDIF\n IF ( KNOTYP.LT.0 ) THEN\n IF ( NKNOTS.NE.NDIM+4 ) THEN\n IERR = -2\n CALL XERMSG (LIBNAM, SUBNAM,\n * 'KNOTYP.LT.0 AND NKNOTS.NE.(2*N+4)', IERR, 1)\n RETURN\n ENDIF\n ELSE\nC Set up knot sequence.\n NKNOTS = NDIM + 4\n CALL DPCHKT (N, X, KNOTYP, T)\n ENDIF\nC\nC Compute B-spline coefficients.\nC\n HNEW = T(3) - T(1)\n DO 40 K = 1, N\n KK = 2*K\n HOLD = HNEW\nC The following requires mixed mode arithmetic.\n DOV3 = D(1,K)/3\n BCOEF(KK-1) = F(1,K) - HOLD*DOV3\nC The following assumes T(2*K+1) = X(K).\n HNEW = T(KK+3) - T(KK+1)\n BCOEF(KK) = F(1,K) + HNEW*DOV3\n 40 CONTINUE\nC\nC Terminate.\nC\n RETURN\nC------------- LAST LINE OF DPCHBS FOLLOWS -----------------------------\n END\n", "meta": {"hexsha": "43133920ade2def5a676041c51bc02fe800309cc", "size": 8321, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/dpchbs.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/dpchbs.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/dpchbs.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.1697247706, "max_line_length": 72, "alphanum_fraction": 0.6037735849, "num_tokens": 2708, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.867035752930664, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6644039857990166}} {"text": "program PSOclassicG\r\n\r\n! Author: Mohammad Asif Zaman\r\n! Fortran code (gfortran, G95)\r\n! The fitness.f95 and timestamp.f95 files are expected to be in the same directory.\r\n\r\n! gfortran -c PSOclassicG.f95\r\n! gfortran PSOclassicG.f95 -o PSOclassicG.exe\r\n! ./PSOclassicG.exe to run (in Cygwin or powershell terminal)\r\n\r\n\r\n! Date: 13th Aug., 2012\r\n\r\n! VTR = Value to reach. Required fitness function value for termination.\r\n! NIR = Number of iterations required to obtain VTR.\r\n! pbest = population best solution at each generation/iteration\r\n! pbest_val = fitness value at pbset\r\n! gbest = global best solution\r\n! gbest_val = fitness value at gbest\r\n\r\n\r\n\r\n! -> Mathematical parameters\r\n!real(kind(1.0d0)) , parameter :: pi = 3.141592653589793\r\n!complex, parameter :: j = (0,1)\r\n!real(kind(1.0d0)), parameter :: eps = epsilon(eps)\r\n! <- Mathematical parameters\n\n\n\n! May 2, 2020\n! version 1.2\n! - timestamp subroutine: date bug fixed\n! - added Makefile\n! - The make file works in both linux terminal and windows powershell as well\n! - The code works fine in both linux and windows\n\n\r\n\r\n! -> File operation parameters\r\nCHARACTER(len=18) :: str\r\ncharacter(len=29) :: command_Make\r\ncharacter(len=35) :: command_File\r\n! <- File operation parameters\r\n\r\n\r\n! -> PSO and fitness parameters\r\ninteger, parameter :: psize = 30, dimen = 30, max_iter = 5000, c1 = 2, c2 = 2\r\nreal(kind(1.0d0)), parameter :: VTR = 1e-6\r\ninteger :: iter = 1, overfly_counter = 0, NIR = 0, NFE = 0\r\nlogical :: overfly_flag = .false.\r\nreal(kind(1.0d0)) :: xmin(dimen), xmax(dimen), vmin(dimen), vmax(dimen)\r\nreal(kind(1.0d0)) :: x(psize, dimen) = 0, v(psize, dimen) = 0\r\nreal(kind(1.0d0)) :: pbest(psize, dimen), gbest(dimen)\r\nreal(kind(1.0d0)) :: pbest_val(psize) = 0\r\nreal(kind(1.0d0)) :: gbest_val\r\nreal(kind(1.0d0)) :: w\r\nreal(kind(1.0d0)) :: gbest_val_store(max_iter) = 0, x11_store(max_iter)\r\n! <- PSO and fitness parameters\r\n\r\n\r\ninteger :: loop1, loop2, loopG\r\n\r\n\r\nreal(kind(1.0d0)) :: time_start, time_end\r\nreal(kind(1.0d0)) :: temp1, temp2\r\n\r\n\r\n\r\n! The following loop runs the PSO. Every time this loop starts, a new PSO run is initiated with new seeds.\r\nloopG = 0\r\n! Do while (NIR == 0) ! Turn this loop on if you want to run PSO multiple times till it satisfies VTR\r\n\r\n\t\t\t\t\t\t! until NIR reaches a finite value. If VTR is not achieved, this loop will continue.\r\n\r\n\r\n\tloopG = loopG + 1\r\n\tprint *, loopG\r\n\tprint *, NIR\r\n\r\n\r\n\tNIR = 0\r\n\tNFE = 0\r\n\toverfly_counter = 0\r\n\r\n\tcall cpu_time(time_start)\r\n\r\n\r\n\t! -> Defining solution space\r\n\t! All dimensions are assigned same limit. But this can easily be changed by employing a loop\r\n\txmin = -30\r\n\txmax = 30\r\n\r\n\tvmin = 0.5 * xmin ! lower limit for velocity\r\n\tvmax = 0.5 * xmax ! higher limit for velocity\r\n\t! <- Defining solution space\r\n\r\n\r\n\r\n\tcall random_seed\r\n\tcall random_number(x)\r\n\tcall random_number(v)\r\n\r\n\r\n\t! -> Intializaing particle position and velocities\r\n\r\n\t! The cost of the first particle is evaluated because it is needed as a stepping stool for evaluating gbest.\r\n\tx(1,:) = x(1,:) * (xmax - xmin) + xmin\t\t\t! fixing the location of the first particle\r\n\tv(1,:) = v(1,:) * (vmax - vmin) + vmin\r\n\tpbest(1,:) = x(1,:)\r\n\tgbest = pbest(1,:)\r\n\tcall fitness(dimen, pbest(1,:), pbest_val(1))\t\t! evaluating the fitenss of the first particle\r\n\tNFE = NFE + 1\r\n\tgbest_val = pbest_val(1)\r\n\r\n\r\n\t! Composite threaded loop (15th Aug., 2012)\r\n\t! As the population is adjusted, the corresponding fitness parameters of the population is assigned simultaneously.\r\n\r\n\tdo loop1 = 2, psize\r\n\t\tx(loop1,:) = x(loop1,:) * (xmax - xmin) + xmin\r\n\t\tv(loop1,:) = v(loop1,:) * (vmax - vmin) + vmin\r\n\r\n\t\tpbest(loop1,:) = x(loop1,:)\r\n\r\n\t\tcall fitness(dimen, x(loop1,:), pbest_val(loop1))\r\n\t\tNFE = NFE + 1\r\n\t\tif ( pbest_val(loop1) < gbest_val ) then\t\t! Geared for minimization problem\r\n\t\t\tgbest_val = pbest_val(loop1)\r\n\t\t\tgbest = x(loop1,:)\r\n\t\tend if\r\n\r\n\tend do\r\n\r\n\r\n\t! <- Intializaing particle position and velocities\r\n\r\n\r\n\r\n\r\n\r\n\t! Main iteration loop. Creating the generations.\r\n\tdo iter = 1, max_iter\r\n\r\n\t\tw = 0.9 - (0.9 - 0.2) * iter /max_iter\r\n\r\n\t\tgbest_val_store(iter) = gbest_val\r\n\t\tx11_store(iter) = x(1,1)\r\n\r\n\r\n\t\tdo loop1 = 1, psize\r\n\t\t\toverfly_flag = .false.\r\n\t\t\tdo loop2 = 1, dimen\r\n\t\t\t\tcall random_number(temp1)\r\n\t\t\t\tcall random_number(temp2)\r\n\t\t\t\tv(loop1, loop2) = w*v(loop1, loop2) + c1 * temp1 * (pbest(loop1,loop2) - x(loop1,loop2))\r\n\t\t\t\tv(loop1, loop2) = v(loop1, loop2) + c2* temp2 *(gbest(loop2) - x(loop1,loop2))\r\n\r\n\t\t\t\tif ( v(loop1, loop2) > vmax(loop2) ) then\r\n\t\t\t\t\tv(loop1, loop2) = vmax(loop2)\r\n\t\t\t\tend if\r\n\r\n\t\t\t\tif ( v(loop1, loop2) < vmin(loop2) ) then\r\n\t\t\t\t\tv(loop1, loop2) = vmin(loop2)\r\n\t\t\t\tend if\r\n\r\n\r\n\t\t\t\tx(loop1, loop2) = x(loop1, loop2) + v(loop1, loop2)\r\n\r\n\t\t\t\tif ( x(loop1, loop2) < xmin(loop2) .or. x(loop1, loop2) > xmax(loop2) ) then\r\n\t\t\t\t\toverfly_flag = .true.\r\n\t\t\t\t\t!print *, \"fly\"\r\n\t\t\t\t\toverfly_counter = overfly_counter + 1\r\n\t\t\t\tend if\r\n\r\n\t\t\tend do\r\n\r\n\t\t\t! Invisible boundary condition. Can be changed to reflecting or absorbing boundary conditions.\r\n\r\n\t\t\tif ( .not. overfly_flag ) then\r\n\r\n\t\t\t\t!print *, \"No overfly\"\r\n\t\t\t\tcall fitness(dimen, x(loop1,:), temp1)\r\n\t\t\t\tif (NIR == 0) then\r\n\t\t\t\t\tNFE = NFE + 1\r\n\t\t\t\tend if\r\n\r\n\r\n\t\t\t\t! Composite IF statement that adjusts the pbset and gbest parameters (15th Aug., 2012)\r\n\t\t\t\tif ( temp1 < pbest_val(loop1) ) then\r\n\t\t\t\t\tpbest_val(loop1) = temp1\r\n\t\t\t\t\tpbest(loop1,:) = x(loop1,:)\r\n\r\n\t\t\t\t\tif ( pbest_val(loop1) < gbest_val ) then\r\n\t\t\t\t\t\tgbest_val = pbest_val(loop1)\r\n\t\t\t\t\t\tgbest = pbest(loop1,:)\r\n\t\t\t\t\t\tif ( NIR == 0 .and. gbest_val < VTR ) then\r\n\t\t\t\t\t\t\tNIR = iter\r\n\t\t\t\t\t\tend if\r\n\t\t\t\t\tend if\r\n\r\n\t\t\t\tend if\r\n\r\n\r\n\t\t\tend if\r\n\r\n\t\tend do ! Ending loop over population\r\n\r\n\tend do ! Ending main iteration loop\r\n\r\n\r\n\tcall cpu_time(time_end)\r\n\r\n\r\n\r\n\r\n\r\n\tcall timestamp(str)\r\n\r\n\r\n\t!do loop1 = 1, psize\r\n\t!print \"(4f10.3)\", x(loop1,:), pbest_val(loop1)\r\n\t!print *, x(loop1,:), pbest_val(loop1)\r\n\r\n\t!print \"(1f10.3)\", pbest_val(loop1)\r\n\t!end do\r\n\r\n\t!print \"(2f10.5)\", x\r\n\t!print * , \"Best\"\r\n\t!print *, x(1,:)\r\n\t!print \"(4f10.6)\", gbest, gbest_val\r\n\r\n\tprint *, \"======================================================\"\r\n\tprint *, \"Time stamp = \", str\r\n\tprint *, \"======================================================\"\r\n\r\n\tprint *, \"======================================================\"\r\n\tprint *, \"Algorithm parameters\"\r\n\tprint *, \"--------------------------------------------------------------------------------------------\"\r\n\tprint *, \"Problem dimension = \", dimen\r\n\tprint *, \"Dynamic range = \", xmin(1) , \"to\", xmax(1)\r\n\tprint *, \"Population size = \", psize\r\n\tprint *, \"Maximum allowed iterations = \", max_iter\r\n\tprint *, \"Defined value to reach (VTR) = \", VTR\r\n\tprint *, \"======================================================\"\r\n\r\n\tprint *,\r\n\r\n\r\n\tprint *, \"======================================================\"\r\n\tprint *, \"Performance parameters\"\r\n\tprint *, \"--------------------------------------------------------------------------------------------\"\r\n\tprint *, \"Total CPU time = \", time_end - time_start, \"seconds\"\r\n\tprint *, \"Overfly counter = \", overfly_counter\r\n\tprint *, \"No. of iterations required to reach VTR (NIR) = \", NIR\r\n\tprint *, \"No. of function evaluations (NFE) = \", NFE\r\n\tprint *, \"Global best value achieved after NIR = \", gbest_val_store(NIR)\r\n\tprint *, \"Global best value achieved after max_iter = \", gbest_val\r\n\tprint *,\r\n\tprint *, \"Global best solution =\"\r\n\tprint *,\r\n\tdo loop1 = 1, dimen\r\n\t\tprint *, gbest(loop1)\r\n\tend do\r\n\tprint *,\r\n\t!call fitness(dimen, gbest, temp1)\r\n\t!print *, temp1\r\n\tprint *, \"======================================================\"\r\n\r\n!end do ! Ending NIR loop if active.\r\n\r\n\r\n\r\n\r\n! -> CSV File operation 17th Aug., 2012. (M -> 18th Aug., 2012)\r\n\n\r\ncommand_Make = ('mkdir ' // 'Data_') // str\n\nprint *, \"commandMake = \", command_Make\r\n\ncall system(command_Make)\r\ncommand_File = 'Data_' // str // '/' // 'converg.csv' \t! the file name must be 11 characters, including . and extension\r\nopen (20, file = command_File)\r\n\tdo loop1 = 1, max_iter\r\n\t\twrite (20,*) gbest_val_store(loop1), \",\", x11_store(loop1)\r\n\tend do\r\nclose (20)\r\n\r\ncommand_File = 'Data_' // str // '/' // 'final_x.txt' \t! the file name must be 11 characters, including . and extension\r\nopen (30, file = command_File)\r\n\tdo loop1 = 1, psize\r\n\r\n\t\twrite (30,*) x(loop1,:), \",\"\r\n\r\n\tend do\r\nclose (30)\r\n\r\n! <- File operation 17th Aug., 2012.\r\n\r\n\r\n\r\n! -> Log file operation\r\ncommand_File = 'Data_' // str // '/' // 'logfile.txt'\r\nopen (11, file = command_File)\r\n\r\nwrite (11,*) \"======================================================\"\r\nwrite (11,*) \"Time stamp = \", str\r\nwrite (11,*) \"======================================================\"\r\n\r\nwrite (11,*) \"======================================================\"\r\nwrite (11,*) \"Algorithm parameters\"\r\nwrite (11,*) \"--------------------------------------------------------------------------------------------\"\r\nwrite (11,*) \"Problem dimension = \", dimen\r\nwrite (11,*) \"Dynamic range = \", xmin(1) , \"to\", xmax(1)\r\nwrite (11,*) \"Population size = \", psize\r\nwrite (11,*) \"Maximum allowed iterations = \", max_iter\r\nwrite (11,*) \"Defined value to reach (VTR) = \", VTR\r\nwrite (11,*) \"======================================================\"\r\n\r\nwrite (11,*)\r\n\r\n\r\nwrite (11,*) \"======================================================\"\r\nwrite (11,*) \"Performance parameters\"\r\nwrite (11,*) \"---------------------------------------------------------------------------------------------\"\r\nwrite (11,*) \"Total CPU time = \", time_end - time_start, \"seconds\"\r\nwrite (11,*) \"Overfly counter = \", overfly_counter\r\nwrite (11,*) \"No. of iterations required to reach VTR (NIR) = \", NIR\r\nwrite (11,*) \"No. of function evaluations (NFE) = \", NFE\r\nwrite (11,*) \"Global best value achieved after NIR = \", gbest_val_store(NIR)\r\nwrite (11,*) \"Global best value achieved after max_iter = \", gbest_val\r\nwrite (11,*)\r\nwrite (11,*) \"Global best solution =\"\r\nwrite (11,*)\r\ndo loop1 = 1, dimen\r\n\twrite (11,*) gbest(loop1)\r\nend do\r\nwrite (11,*)\r\nwrite (11,*) \"======================================================\"\r\n\r\nclose(11)\r\n\r\n! <- Log file operation\r\n\r\n\r\n\r\n\r\ncontains\r\n\r\n\tinclude 'fitness.f95'\r\n\tinclude 'timestamp.f95'\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nend program PSOclassicG\r\n", "meta": {"hexsha": "a72b07e59a5f77fa051b8bdc25516b9e99d488fb", "size": 10234, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Fortran codes/PSOclassicG.f95", "max_stars_repo_name": "zaman13/Particle-Swarm-Optimization-Fortran-95", "max_stars_repo_head_hexsha": "abaef418d133ca9e55d81417836d7cbe2057fb29", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2018-07-02T20:48:05.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-19T02:58:21.000Z", "max_issues_repo_path": "Fortran codes/PSOclassicG.f95", "max_issues_repo_name": "zaman13/Particle-Swarm-Optimization-Fortran-95", "max_issues_repo_head_hexsha": "abaef418d133ca9e55d81417836d7cbe2057fb29", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran codes/PSOclassicG.f95", "max_forks_repo_name": "zaman13/Particle-Swarm-Optimization-Fortran-95", "max_forks_repo_head_hexsha": "abaef418d133ca9e55d81417836d7cbe2057fb29", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-05-19T06:54:06.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-19T06:54:06.000Z", "avg_line_length": 28.0383561644, "max_line_length": 122, "alphanum_fraction": 0.5596052374, "num_tokens": 2893, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6644039818094711}} {"text": "!We will create an array with ten integer numbers, and write a routine to sort the numbers. \n\nPROGRAM Sort_numbers_within_an_array\n IMPLICIT NONE\n\n INTEGER, DIMENSION(1:10) :: a\n INTEGER, DIMENSION(1:1) :: i,k\n INTEGER :: j,n\n\na = (/ 12, 5, 2, 4, 0, 9, 13, 5, 6, 10 /)\n\nn=0\n\nDo\ni=MAXLOC(a(1:10-n)) !find location of maximum value\nj=MAXVAL(a(1:10-n)) !Maximum value\nk=MINLOC(a(1:10-n)) !find location of minimum value\n\na(i)=a(10-n)\na(10-n)=j\n\nn=n+1\n\nIf (n==9) Exit\nend do\n\n\nWrite (6,*) a\n\nEND PROGRAM Sort_numbers_within_an_array\n", "meta": {"hexsha": "b111877a2943ef26bc51047a867d5326b4daf27c", "size": 534, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Intrinsics.f90", "max_stars_repo_name": "WilliamHoltam/fortran-basics", "max_stars_repo_head_hexsha": "069212620623c256b578c148fedea710cab7afbc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Intrinsics.f90", "max_issues_repo_name": "WilliamHoltam/fortran-basics", "max_issues_repo_head_hexsha": "069212620623c256b578c148fedea710cab7afbc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Intrinsics.f90", "max_forks_repo_name": "WilliamHoltam/fortran-basics", "max_forks_repo_head_hexsha": "069212620623c256b578c148fedea710cab7afbc", "max_forks_repo_licenses": ["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.2258064516, "max_line_length": 92, "alphanum_fraction": 0.670411985, "num_tokens": 204, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.867035752930664, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6644039765438793}} {"text": "\tREAL FUNCTION CHISQSIZE(P1)\r\n\tIMPLICIT NONE\r\nC\r\nC This function returns the sample size associated with P1 and the\r\nC other input parameters. This formula should be used for studies that\r\nC are analyzed with an uncorrected chi-squared test.\r\nC\r\nC Arguments\r\nC\r\n\tREAL P1\r\nC\r\nC Functions\r\nC\r\n\tREAL ZCRVALUE\r\nC\r\nC Locals\r\nC\r\n\tREAL ZALPHA,ZBETA,P,Q\r\nC\r\nC Common from main\r\nC\r\n\tREAL ALPHA,BETA,P0,N,M,Q0,Q1\r\n\tCOMMON/IPCOM/ALPHA,BETA,P0,N,M,Q0,Q1\r\nC\r\nC Code:\r\n\tZALPHA=ZCRVALUE(ALPHA/2.)\r\n\tZBETA=ZCRVALUE(BETA)\r\n\tP=(N*P1+M*N*P0)/(M*N+N)\r\n Q=1.-P\r\n\tQ1=1.-P1\r\n\tQ0=1.-P0\r\n\tCHISQSIZE=\r\n .\t(\r\n .\t(ZALPHA*SQRT((1.+1./M)*P*Q) + ZBETA*SQRT((P0*Q0)/M+(P1*Q1)))**2\r\n . /\r\n . (P0-P1)**2\r\n .\t) - N\r\nC\r\nC Done.\r\nC\r\n\tRETURN\r\n\tEND\r\n", "meta": {"hexsha": "ad4f34e8b005eaf6159b7e5072492e460098c1fe", "size": 768, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "misc/fortran-tests/chisqsiz.for", "max_stars_repo_name": "vubiostat/ps", "max_stars_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2017-12-29T14:19:14.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-06T15:08:46.000Z", "max_issues_repo_path": "misc/fortran-tests/chisqsiz.for", "max_issues_repo_name": "vubiostat/ps", "max_issues_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2020-04-30T16:57:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-07T00:26:02.000Z", "max_forks_repo_path": "misc/fortran-tests/chisqsiz.for", "max_forks_repo_name": "vubiostat/ps", "max_forks_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-07T20:11:54.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-11T19:18:59.000Z", "avg_line_length": 17.8604651163, "max_line_length": 75, "alphanum_fraction": 0.5963541667, "num_tokens": 312, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474168650674, "lm_q2_score": 0.6959583250334526, "lm_q1q2_score": 0.6643948172389245}} {"text": "MODULE matrices\n\tIMPLICIT NONE \n\tCONTAINS\n\t\n\tINTEGER FUNCTION plus_un(i,n)\n\t\tINTEGER, INTENT(IN) :: i, n\n\t\tIF(n>i)THEN\n\t\t\tplus_un=i+1\n\t\tELSE\n\t\t\tplus_un=1\n\t\tEND IF\n\tEND FUNCTION plus_un\n\t\n\tINTEGER FUNCTION moins_un(i,n)\n\t\tINTEGER, INTENT(IN) :: i, n\n\t\tIF(i>1)THEN\n\t\t\tmoins_un=i-1\n\t\tELSE\n\t\t\tmoins_un=n\n\t\tEND IF\n\tEND FUNCTION moins_un\n\t\n\tSUBROUTINE saisit_impair(n)\n\t\tINTEGER, INTENT(OUT)::n\n\t\tDO\n\t\t\tPRINT*, \"Entrez l'ordre impair et positif n du carre magique\"\n\t\t\tREAD*, n\n\t\t\tIF(MODULO(n,2)==1 .AND. n>0)EXIT\n\t\t\tPRINT*, \"Recommencez!\"\n\t\tEND DO\n\tEND SUBROUTINE saisit_impair\n\t\n\tSUBROUTINE affiche(A)\n\t\tINTEGER, DIMENSION(:,:), INTENT(IN):: A\n\t\tINTEGER:: i, nl\n\t\tnl = SIZE(A,1)\n\t\tDO i=1, nl\n\t\t\tPRINT*, A(i,:)\n\t\tEND DO\n\tEND SUBROUTINE affiche\nEND MODULE matrices\n", "meta": {"hexsha": "54901ab59187e6935f7b74bf09226824594b5970", "size": 758, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "carremagique/carremagique.f90", "max_stars_repo_name": "psekercioglu/fortran90", "max_stars_repo_head_hexsha": "10a3c7fff3dd52ba6e2247bde18f25f8e81bf50d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "carremagique/carremagique.f90", "max_issues_repo_name": "psekercioglu/fortran90", "max_issues_repo_head_hexsha": "10a3c7fff3dd52ba6e2247bde18f25f8e81bf50d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "carremagique/carremagique.f90", "max_forks_repo_name": "psekercioglu/fortran90", "max_forks_repo_head_hexsha": "10a3c7fff3dd52ba6e2247bde18f25f8e81bf50d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.0476190476, "max_line_length": 64, "alphanum_fraction": 0.6622691293, "num_tokens": 301, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424295406088, "lm_q2_score": 0.7853085859124003, "lm_q1q2_score": 0.6643258531058358}} {"text": "! { dg-do compile }\n! { dg-additional-options \"-ffrontend-optimize\" }\n! PR 84270 - this used to be rejected.\n! Test case by Michael Weinert\n\nmodule fp_precision\n\n integer, parameter :: fp = selected_real_kind(13)\n\nend module fp_precision\n\n subroutine lhcal(nrot,orth,ngpts,vgauss,vr_0)\n\n use fp_precision ! floating point precision\n\n implicit none\n\n!---> rotation matrices and rotations (input)\n integer, intent(in) :: nrot\n! real(kind=fp), intent(in) :: orth(3,3,nrot) ! fine at all -O\n real(kind=fp), intent(in) :: orth(3,3,*)\n\n!---> gaussian integration points\n integer, intent(in) :: ngpts\n real(kind=fp), intent(in) :: vgauss(3,*)\n\n!---> output results\n real(kind=fp), intent(out) :: vr_0(3)\n\n real(kind=fp) :: v(3),vr(3)\n integer :: n,nn\n\n vr_0 = 0\n do nn=1,ngpts\n v(:) = vgauss(:,nn)\n!---> apply rotations\n do n=2,nrot\n vr = matmul( orth(:,:,n), v )\n vr_0 = vr_0 + vr\n enddo\n enddo\n\n return\n end subroutine lhcal\n", "meta": {"hexsha": "702e32e74671cb03d493fe70772cbb41627756ec", "size": 1112, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/inline_matmul_22.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/inline_matmul_22.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/inline_matmul_22.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.7111111111, "max_line_length": 71, "alphanum_fraction": 0.5503597122, "num_tokens": 333, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424373085146, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.6643258507049228}} {"text": "! vim: set ft=fortran sw=4 ts=4:\n\nprogram weather_stats\n\n ! parallel version, using coarrays\n\n use mod_array, only: denan, mean\n use mod_io, only: read_buoy\n use mod_parallel, only: tile_indices\n\n implicit none\n\n character(len=5), allocatable :: ids(:)\n character(len=20), allocatable :: time(:)\n real, allocatable :: gather_max(:)[:], gather_mean(:)[:]\n real, allocatable :: wind_speed(:)\n real, allocatable :: max_wind(:), mean_wind(:)\n integer :: is, ie, indices(2)\n integer :: i\n\n ids = ['42001', '42002', '42003', '42020', '42035',&\n '42036', '42039', '42040', '42055']\n\n indices = tile_indices(size(ids))\n is = indices(1)\n ie = indices(2)\n\n allocate(gather_max(size(ids))[*], gather_mean(size(ids))[*])\n allocate(max_wind(is:ie), mean_wind(is:ie))\n\n do i = is, ie\n call read_buoy('data/buoy_' // ids(i) // '.csv', time, wind_speed)\n wind_speed = denan(wind_speed)\n max_wind(i) = maxval(wind_speed)\n mean_wind(i) = mean(wind_speed)\n end do\n\n gather_max(is:ie)[1] = max_wind\n gather_mean(is:ie)[1] = mean_wind\n\n sync all\n\n if (this_image() == 1) then\n print *, 'Maximum wind speed measured is ', maxval(gather_max),&\n 'at station ', ids(maxloc(gather_max))\n print *, 'Highest mean wind speed is ', maxval(gather_mean),&\n 'at station ', ids(maxloc(gather_mean))\n print *, 'Lowest mean wind speed is ', minval(gather_mean),&\n 'at station ', ids(minloc(gather_mean))\n end if\n\nend program weather_stats\n\n", "meta": {"hexsha": "dbb8ce57c96fb9c065c6f08af151379580a3d243", "size": 1569, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran/ModernFortran/weather-buoys/src/weather_stats_parallel.f90", "max_stars_repo_name": "kkirstein/proglang-playground", "max_stars_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Fortran/ModernFortran/weather-buoys/src/weather_stats_parallel.f90", "max_issues_repo_name": "kkirstein/proglang-playground", "max_issues_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran/ModernFortran/weather-buoys/src/weather_stats_parallel.f90", "max_forks_repo_name": "kkirstein/proglang-playground", "max_forks_repo_head_hexsha": "d00be09ba2bb2351c6f5287cc4d93fcaf21f75fd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.0555555556, "max_line_length": 74, "alphanum_fraction": 0.6080305927, "num_tokens": 450, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424217727027, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.6643258385045164}} {"text": "program co_reduce_factorial\n !! author: Daniel Topa & Izaak Beekman\n !! category: regression\n !!\n !! [issue #172](https://github.com/sourceryinstitute/opencoarrays/issues/172)\n !! wherein co-reduce gets junk in the first image when binary\n !! operator's (pure function) arguments have `value` attribute\n !! instead of `intent(in)`\n\n implicit none\n integer :: value[ * ] !! Each image stores their image number here\n integer :: k\n value = this_image ( )\n call co_reduce ( value, result_image = 1, operator = myProd )\n !! value[k /= 1] undefined, value[ k == 1 ] should equal $n!$ where $n$ is `num_images()`\n if ( this_image ( ) == 1 ) then\n write ( * , '( \"Number of images = \", g0 )' ) num_images ( )\n do k = 1, num_images ( )\n write ( * , '( 2( a, i0 ) )' ) 'value [ ', k, ' ] is ', value [ k ]\n write ( * , '(a)' ) 'since RESULT_IMAGE is present, value on other images is undefined by the standard'\n end do\n write ( * , '( \"Product value = \", g0 )' ) value !! should print num_images() factorial\n write ( * , 100 )\n if ( value == factorial( num_images() ) ) then\n write ( * , '(a)' ) 'Test passed.'\n else\n write ( * , '(a, I0)') 'Answer should have been num_images()! = ', factorial( num_images() )\n error stop 'Wrong answer for n! using co_reduce'\n end if\n end if\n100 format ( \"Expected value = num_images()!\", /, \" 2! = 2, 3! = 6, 4! = 24, ...\" )\n\ncontains\n\n pure function myProd ( a, b ) result ( rslt )\n !! Product function to be used in `co_reduce` reduction for\n !! computing factorials. When `value` attribute is changed to\n !! `intent(in)` tests pass, and expected behavior is observed.\n integer, value :: a, b\n !! multiply two inputs together. If we change `value` to\n !! `intent(in)` the test passes and the issue goes away and\n !! according to C1276 of F2008:\n !!\n !! > C1276 The specification-part of a pure function subprogram\n !! > shall specify that all its nonpointer dummy data objects have\n !! > the INTENT (IN) or the VALUE attribute.\n !!\n !! Thanks to @LadaF for pointing this out.\n integer :: rslt !! product of a*b\n rslt = a * b\n end function\n\n pure function factorial ( n ) result ( rslt )\n !! Compute $n!$\n integer, intent(in) :: n\n integer :: rslt\n integer :: i\n rslt = 1\n do i = 1, n\n rslt = rslt*i\n end do\n end function\nend program\n", "meta": {"hexsha": "15d55fcb412a76e41aae196982a0f001a1bb22d7", "size": 2427, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/regression/reported/issue-172-wrong-co_reduce.f90", "max_stars_repo_name": "neok-m4700/OpenCoarrays", "max_stars_repo_head_hexsha": "2a8134df5ec11a2e56c5a87cc935a9452cf25a2b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 144, "max_stars_repo_stars_event_min_datetime": "2017-02-18T19:30:00.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-16T19:53:23.000Z", "max_issues_repo_path": "src/tests/regression/reported/issue-172-wrong-co_reduce.f90", "max_issues_repo_name": "neok-m4700/OpenCoarrays", "max_issues_repo_head_hexsha": "2a8134df5ec11a2e56c5a87cc935a9452cf25a2b", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 441, "max_issues_repo_issues_event_min_datetime": "2017-02-12T19:28:14.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-23T17:27:41.000Z", "max_forks_repo_path": "src/tests/regression/reported/issue-172-wrong-co_reduce.f90", "max_forks_repo_name": "neok-m4700/OpenCoarrays", "max_forks_repo_head_hexsha": "2a8134df5ec11a2e56c5a87cc935a9452cf25a2b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 46, "max_forks_repo_forks_event_min_datetime": "2017-04-01T03:11:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T19:20:30.000Z", "avg_line_length": 37.921875, "max_line_length": 111, "alphanum_fraction": 0.6044499382, "num_tokens": 709, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332893, "lm_q2_score": 0.7931059609645724, "lm_q1q2_score": 0.6643213859425583}} {"text": "\n SUBROUTINE CALJY0(ARG,RESULT,JINT)\nC---------------------------------------------------------------------\nC\nC This packet computes zero-order Bessel functions of the first and\nC second kind (J0 and Y0), for real arguments X, where 0 < X <= XMAX\nC for Y0, and |X| <= XMAX for J0. It contains two function-type\nC subprograms, BESJ0 and BESY0, and one subroutine-type\nC subprogram, CALJY0. The calling statements for the primary\nC entries are:\nC\nC Y = BESJ0(X)\nC and\nC Y = BESY0(X),\nC\nC where the entry points correspond to the functions J0(X) and Y0(X),\nC respectively. The routine CALJY0 is intended for internal packet\nC use only, all computations within the packet being concentrated in\nC this one routine. The function subprograms invoke CALJY0 with\nC the statement\nC CALL CALJY0(ARG,RESULT,JINT),\nC where the parameter usage is as follows:\nC\nC Function Parameters for CALJY0\nC call ARG RESULT JINT\nC\nC BESJ0(ARG) |ARG| .LE. XMAX J0(ARG) 0\nC BESY0(ARG) 0 .LT. ARG .LE. XMAX Y0(ARG) 1\nC\nC The main computation uses unpublished minimax rational\nC approximations for X .LE. 8.0, and an approximation from the\nC book Computer Approximations by Hart, et. al., Wiley and Sons,\nC New York, 1968, for arguments larger than 8.0 Part of this\nC transportable packet is patterned after the machine-dependent\nC FUNPACK program BESJ0(X), but cannot match that version for\nC efficiency or accuracy. This version uses rational functions\nC that are theoretically accurate to at least 18 significant decimal\nC digits for X <= 8, and at least 18 decimal places for X > 8. The\nC accuracy achieved depends on the arithmetic system, the compiler,\nC the intrinsic functions, and proper selection of the machine-\nC dependent constants.\nC\nC*******************************************************************\nC\nC The following machine-dependent constants must be declared in\nC DATA statements. IEEE values are provided as a default.\nC\nC XINF = largest positive machine number\nC XMAX = largest acceptable argument. The functions AINT, SIN\nC and COS must perform properly for ABS(X) .LE. XMAX.\nC We recommend that XMAX be a small integer multiple of\nC sqrt(1/eps), where eps is the smallest positive number\nC such that 1+eps > 1.\nC XSMALL = positive argument such that 1.0-(X/2)**2 = 1.0\nC to machine precision for all ABS(X) .LE. XSMALL.\nC We recommend that XSMALL < sqrt(eps)/beta, where beta\nC is the floating-point radix (usually 2 or 16).\nC\nC Approximate values for some important machines are\nC\nC eps XMAX XSMALL XINF\nC\nC CDC 7600 (S.P.) 7.11E-15 1.34E+08 2.98E-08 1.26E+322\nC CRAY-1 (S.P.) 7.11E-15 1.34E+08 2.98E-08 5.45E+2465\nC IBM PC (8087) (S.P.) 5.96E-08 8.19E+03 1.22E-04 3.40E+38\nC IBM PC (8087) (D.P.) 1.11D-16 2.68D+08 3.72D-09 1.79D+308\nC IBM 195 (D.P.) 2.22D-16 6.87D+09 9.09D-13 7.23D+75\nC UNIVAC 1108 (D.P.) 1.73D-18 4.30D+09 2.33D-10 8.98D+307\nC VAX 11/780 (D.P.) 1.39D-17 1.07D+09 9.31D-10 1.70D+38\nC\nC*******************************************************************\nC*******************************************************************\nC\nC Error Returns\nC\nC The program returns the value zero for X .GT. XMAX, and returns\nC -XINF when BESLY0 is called with a negative or zero argument.\nC\nC\nC Intrinsic functions required are:\nC\nC ABS, AINT, COS, LOG, SIN, SQRT\nC\nC\nC Latest modification: March 13, 1992\nC\nC Author: W. J. Cody\nC Mathematics and Computer Science Division\nC Argonne National Laboratory\nC Argonne, IL 60439\nC\nC--------------------------------------------------------------------\n INTEGER I,JINT\nCS REAL\n DOUBLE PRECISION\n 1 ARG,AX,CONS,DOWN,EIGHT,FIVE5,FOUR,ONE,ONEOV8,PI2,PJ0,\n 2 PJ1,PLG,PROD,PY0,PY1,PY2,P0,P1,P17,QJ0,QJ1,QLG,QY0,QY1,\n 3 QY2,Q0,Q1,RESJ,RESULT,R0,R1,SIXTY4,THREE,TWOPI,TWOPI1,\n 4 TWOPI2,TWO56,UP,W,WSQ,XDEN,XINF,XMAX,XNUM,XSMALL,XJ0,\n 5 XJ1,XJ01,XJ02,XJ11,XJ12,XY,XY0,XY01,XY02,XY1,XY11,XY12,\n 6 XY2,XY21,XY22,Z,ZERO,ZSQ\n DIMENSION PJ0(7),PJ1(8),PLG(4),PY0(6),PY1(7),PY2(8),P0(6),P1(6),\n 1 QJ0(5),QJ1(7),QLG(4),QY0(5),QY1(6),QY2(7),Q0(5),Q1(5)\nC-------------------------------------------------------------------\nC Mathematical constants\nC CONS = ln(.5) + Euler's gamma\nC-------------------------------------------------------------------\nCS DATA ZERO,ONE,THREE,FOUR,EIGHT/0.0E0,1.0E0,3.0E0,4.0E0,8.0E0/,\nCS 1 FIVE5,SIXTY4,ONEOV8,P17/5.5E0,64.0E0,0.125E0,1.716E-1/,\nCS 2 TWO56,CONS/256.0E0,-1.1593151565841244881E-1/,\nCS 3 PI2,TWOPI/6.3661977236758134308E-1,6.2831853071795864769E0/,\nCS 4 TWOPI1,TWOPI2/6.28125E0,1.9353071795864769253E-3/\n DATA ZERO,ONE,THREE,FOUR,EIGHT/0.0D0,1.0D0,3.0D0,4.0D0,8.0D0/,\n 1 FIVE5,SIXTY4,ONEOV8,P17/5.5D0,64.0D0,0.125D0,1.716D-1/,\n 2 TWO56,CONS/256.0D0,-1.1593151565841244881D-1/,\n 3 PI2,TWOPI/6.3661977236758134308D-1,6.2831853071795864769D0/,\n 4 TWOPI1,TWOPI2/6.28125D0,1.9353071795864769253D-3/\nC-------------------------------------------------------------------\nC Machine-dependent constants\nC-------------------------------------------------------------------\nCS DATA XMAX/8.19E+03/,XSMALL/1.22E-04/,XINF/3.40E+38/\n DATA XMAX/2.68D+08/,XSMALL/3.72D-09/,XINF/1.79D+308/\nC-------------------------------------------------------------------\nC Zeroes of Bessel functions\nC-------------------------------------------------------------------\nCS DATA XJ0/2.4048255576957727686E+0/,XJ1/5.5200781102863106496E+0/,\nCS 1 XY0/8.9357696627916752158E-1/,XY1/3.9576784193148578684E+0/,\nCS 2 XY2/7.0860510603017726976E+0/,\nCS 3 XJ01/ 616.0E+0/, XJ02/-1.4244423042272313784E-03/,\nCS 4 XJ11/1413.0E+0/, XJ12/ 5.4686028631064959660E-04/,\nCS 5 XY01/ 228.0E+0/, XY02/ 2.9519662791675215849E-03/,\nCS 6 XY11/1013.0E+0/, XY12/ 6.4716931485786837568E-04/,\nCS 7 XY21/1814.0E+0/, XY22/ 1.1356030177269762362E-04/\n DATA XJ0/2.4048255576957727686D+0/,XJ1/5.5200781102863106496D+0/,\n 1 XY0/8.9357696627916752158D-1/,XY1/3.9576784193148578684D+0/,\n 2 XY2/7.0860510603017726976D+0/,\n 3 XJ01/ 616.0D+0/, XJ02/-1.4244423042272313784D-03/,\n 4 XJ11/1413.0D+0/, XJ12/ 5.4686028631064959660D-04/,\n 5 XY01/ 228.0D+0/, XY02/ 2.9519662791675215849D-03/,\n 6 XY11/1013.0D+0/, XY12/ 6.4716931485786837568D-04/,\n 7 XY21/1814.0D+0/, XY22/ 1.1356030177269762362D-04/\nC-------------------------------------------------------------------\nC Coefficients for rational approximation to ln(x/a)\nC--------------------------------------------------------------------\nCS DATA PLG/-2.4562334077563243311E+01,2.3642701335621505212E+02,\nCS 1 -5.4989956895857911039E+02,3.5687548468071500413E+02/\nCS DATA QLG/-3.5553900764052419184E+01,1.9400230218539473193E+02,\nCS 1 -3.3442903192607538956E+02,1.7843774234035750207E+02/\n DATA PLG/-2.4562334077563243311D+01,2.3642701335621505212D+02,\n 1 -5.4989956895857911039D+02,3.5687548468071500413D+02/\n DATA QLG/-3.5553900764052419184D+01,1.9400230218539473193D+02,\n 1 -3.3442903192607538956D+02,1.7843774234035750207D+02/\nC-------------------------------------------------------------------\nC Coefficients for rational approximation of\nC J0(X) / (X**2 - XJ0**2), XSMALL < |X| <= 4.0\nC--------------------------------------------------------------------\nCS DATA PJ0/6.6302997904833794242E+06,-6.2140700423540120665E+08,\nCS 1 2.7282507878605942706E+10,-4.1298668500990866786E+11,\nCS 2 -1.2117036164593528341E-01, 1.0344222815443188943E+02,\nCS 3 -3.6629814655107086448E+04/\nCS DATA QJ0/4.5612696224219938200E+05, 1.3985097372263433271E+08,\nCS 1 2.6328198300859648632E+10, 2.3883787996332290397E+12,\nCS 2 9.3614022392337710626E+02/\n DATA PJ0/6.6302997904833794242D+06,-6.2140700423540120665D+08,\n 1 2.7282507878605942706D+10,-4.1298668500990866786D+11,\n 2 -1.2117036164593528341D-01, 1.0344222815443188943D+02,\n 3 -3.6629814655107086448D+04/\n DATA QJ0/4.5612696224219938200D+05, 1.3985097372263433271D+08,\n 1 2.6328198300859648632D+10, 2.3883787996332290397D+12,\n 2 9.3614022392337710626D+02/\nC-------------------------------------------------------------------\nC Coefficients for rational approximation of\nC J0(X) / (X**2 - XJ1**2), 4.0 < |X| <= 8.0\nC-------------------------------------------------------------------\nCS DATA PJ1/4.4176707025325087628E+03, 1.1725046279757103576E+04,\nCS 1 1.0341910641583726701E+04,-7.2879702464464618998E+03,\nCS 2 -1.2254078161378989535E+04,-1.8319397969392084011E+03,\nCS 3 4.8591703355916499363E+01, 7.4321196680624245801E+02/\nCS DATA QJ1/3.3307310774649071172E+02,-2.9458766545509337327E+03,\nCS 1 1.8680990008359188352E+04,-8.4055062591169562211E+04,\nCS 2 2.4599102262586308984E+05,-3.5783478026152301072E+05,\nCS 3 -2.5258076240801555057E+01/\n DATA PJ1/4.4176707025325087628D+03, 1.1725046279757103576D+04,\n 1 1.0341910641583726701D+04,-7.2879702464464618998D+03,\n 2 -1.2254078161378989535D+04,-1.8319397969392084011D+03,\n 3 4.8591703355916499363D+01, 7.4321196680624245801D+02/\n DATA QJ1/3.3307310774649071172D+02,-2.9458766545509337327D+03,\n 1 1.8680990008359188352D+04,-8.4055062591169562211D+04,\n 2 2.4599102262586308984D+05,-3.5783478026152301072D+05,\n 3 -2.5258076240801555057D+01/\nC-------------------------------------------------------------------\nC Coefficients for rational approximation of\nC (Y0(X) - 2 LN(X/XY0) J0(X)) / (X**2 - XY0**2),\nC XSMALL < |X| <= 3.0\nC--------------------------------------------------------------------\nCS DATA PY0/1.0102532948020907590E+04,-2.1287548474401797963E+06,\nCS 1 2.0422274357376619816E+08,-8.3716255451260504098E+09,\nCS 2 1.0723538782003176831E+11,-1.8402381979244993524E+01/\nCS DATA QY0/6.6475986689240190091E+02, 2.3889393209447253406E+05,\nCS 1 5.5662956624278251596E+07, 8.1617187777290363573E+09,\nCS 2 5.8873865738997033405E+11/\n DATA PY0/1.0102532948020907590D+04,-2.1287548474401797963D+06,\n 1 2.0422274357376619816D+08,-8.3716255451260504098D+09,\n 2 1.0723538782003176831D+11,-1.8402381979244993524D+01/\n DATA QY0/6.6475986689240190091D+02, 2.3889393209447253406D+05,\n 1 5.5662956624278251596D+07, 8.1617187777290363573D+09,\n 2 5.8873865738997033405D+11/\nC-------------------------------------------------------------------\nC Coefficients for rational approximation of\nC (Y0(X) - 2 LN(X/XY1) J0(X)) / (X**2 - XY1**2),\nC 3.0 < |X| <= 5.5\nC--------------------------------------------------------------------\nCS DATA PY1/-1.4566865832663635920E+04, 4.6905288611678631510E+06,\nCS 1 -6.9590439394619619534E+08, 4.3600098638603061642E+10,\nCS 2 -5.5107435206722644429E+11,-2.2213976967566192242E+13,\nCS 3 1.7427031242901594547E+01/\nCS DATA QY1/ 8.3030857612070288823E+02, 4.0669982352539552018E+05,\nCS 1 1.3960202770986831075E+08, 3.4015103849971240096E+10,\nCS 2 5.4266824419412347550E+12, 4.3386146580707264428E+14/\n DATA PY1/-1.4566865832663635920D+04, 4.6905288611678631510D+06,\n 1 -6.9590439394619619534D+08, 4.3600098638603061642D+10,\n 2 -5.5107435206722644429D+11,-2.2213976967566192242D+13,\n 3 1.7427031242901594547D+01/\n DATA QY1/ 8.3030857612070288823D+02, 4.0669982352539552018D+05,\n 1 1.3960202770986831075D+08, 3.4015103849971240096D+10,\n 2 5.4266824419412347550D+12, 4.3386146580707264428D+14/\nC-------------------------------------------------------------------\nC Coefficients for rational approximation of\nC (Y0(X) - 2 LN(X/XY2) J0(X)) / (X**2 - XY2**2),\nC 5.5 < |X| <= 8.0\nC--------------------------------------------------------------------\nCS DATA PY2/ 2.1363534169313901632E+04,-1.0085539923498211426E+07,\nCS 1 2.1958827170518100757E+09,-1.9363051266772083678E+11,\nCS 2 -1.2829912364088687306E+11, 6.7016641869173237784E+14,\nCS 3 -8.0728726905150210443E+15,-1.7439661319197499338E+01/\nCS DATA QY2/ 8.7903362168128450017E+02, 5.3924739209768057030E+05,\nCS 1 2.4727219475672302327E+08, 8.6926121104209825246E+10,\nCS 2 2.2598377924042897629E+13, 3.9272425569640309819E+15,\nCS 3 3.4563724628846457519E+17/\n DATA PY2/ 2.1363534169313901632D+04,-1.0085539923498211426D+07,\n 1 2.1958827170518100757D+09,-1.9363051266772083678D+11,\n 2 -1.2829912364088687306D+11, 6.7016641869173237784D+14,\n 3 -8.0728726905150210443D+15,-1.7439661319197499338D+01/\n DATA QY2/ 8.7903362168128450017D+02, 5.3924739209768057030D+05,\n 1 2.4727219475672302327D+08, 8.6926121104209825246D+10,\n 2 2.2598377924042897629D+13, 3.9272425569640309819D+15,\n 3 3.4563724628846457519D+17/\nC-------------------------------------------------------------------\nC Coefficients for Hart,s approximation, |X| > 8.0\nC-------------------------------------------------------------------\nCS DATA P0/3.4806486443249270347E+03, 2.1170523380864944322E+04,\nCS 1 4.1345386639580765797E+04, 2.2779090197304684302E+04,\nCS 2 8.8961548424210455236E-01, 1.5376201909008354296E+02/\nCS DATA Q0/3.5028735138235608207E+03, 2.1215350561880115730E+04,\nCS 1 4.1370412495510416640E+04, 2.2779090197304684318E+04,\nCS 2 1.5711159858080893649E+02/\nCS DATA P1/-2.2300261666214198472E+01,-1.1183429920482737611E+02,\nCS 1 -1.8591953644342993800E+02,-8.9226600200800094098E+01,\nCS 2 -8.8033303048680751817E-03,-1.2441026745835638459E+00/\nCS DATA Q1/1.4887231232283756582E+03, 7.2642780169211018836E+03,\nCS 1 1.1951131543434613647E+04, 5.7105024128512061905E+03,\nCS 2 9.0593769594993125859E+01/\n DATA P0/3.4806486443249270347D+03, 2.1170523380864944322D+04,\n 1 4.1345386639580765797D+04, 2.2779090197304684302D+04,\n 2 8.8961548424210455236D-01, 1.5376201909008354296D+02/\n DATA Q0/3.5028735138235608207D+03, 2.1215350561880115730D+04,\n 1 4.1370412495510416640D+04, 2.2779090197304684318D+04,\n 2 1.5711159858080893649D+02/\n DATA P1/-2.2300261666214198472D+01,-1.1183429920482737611D+02,\n 1 -1.8591953644342993800D+02,-8.9226600200800094098D+01,\n 2 -8.8033303048680751817D-03,-1.2441026745835638459D+00/\n DATA Q1/1.4887231232283756582D+03, 7.2642780169211018836D+03,\n 1 1.1951131543434613647D+04, 5.7105024128512061905D+03,\n 2 9.0593769594993125859D+01/\nC-------------------------------------------------------------------\nC Check for error conditions\nC-------------------------------------------------------------------\n AX = ABS(ARG)\n IF ((JINT .EQ. 1) .AND. (ARG .LE. ZERO)) THEN\n RESULT = -XINF\n GO TO 2000\n ELSE IF (AX .GT. XMAX) THEN\n RESULT = ZERO\n GO TO 2000\n END IF\n IF (AX .GT. EIGHT) GO TO 800\n IF (AX .LE. XSMALL) THEN\n IF (JINT .EQ. 0) THEN\n RESULT = ONE\n ELSE\n RESULT = PI2 * (LOG(AX) + CONS)\n END IF\n GO TO 2000\n END IF\nC-------------------------------------------------------------------\nC Calculate J0 for appropriate interval, preserving\nC accuracy near the zero of J0\nC-------------------------------------------------------------------\n ZSQ = AX * AX\n IF (AX .LE. FOUR) THEN\n XNUM = (PJ0(5) * ZSQ + PJ0(6)) * ZSQ + PJ0(7)\n XDEN = ZSQ + QJ0(5)\n DO 50 I = 1, 4\n XNUM = XNUM * ZSQ + PJ0(I)\n XDEN = XDEN * ZSQ + QJ0(I)\n 50 CONTINUE\n PROD = ((AX - XJ01/TWO56) - XJ02) * (AX + XJ0)\n ELSE\n WSQ = ONE - ZSQ / SIXTY4\n XNUM = PJ1(7) * WSQ + PJ1(8)\n XDEN = WSQ + QJ1(7)\n DO 220 I = 1, 6\n XNUM = XNUM * WSQ + PJ1(I)\n XDEN = XDEN * WSQ + QJ1(I)\n 220 CONTINUE\n PROD = (AX + XJ1) * ((AX - XJ11/TWO56) - XJ12)\n END IF\n RESULT = PROD * XNUM / XDEN\n IF (JINT .EQ. 0) GO TO 2000\nC-------------------------------------------------------------------\nC Calculate Y0. First find RESJ = pi/2 ln(x/xn) J0(x),\nC where xn is a zero of Y0\nC-------------------------------------------------------------------\n IF (AX .LE. THREE) THEN\n UP = (AX-XY01/TWO56)-XY02\n XY = XY0\n ELSE IF (AX .LE. FIVE5) THEN\n UP = (AX-XY11/TWO56)-XY12\n XY = XY1\n ELSE\n UP = (AX-XY21/TWO56)-XY22\n XY = XY2\n END IF\n DOWN = AX + XY\n IF (ABS(UP) .LT. P17*DOWN) THEN\n W = UP/DOWN\n WSQ = W*W\n XNUM = PLG(1)\n XDEN = WSQ + QLG(1)\n DO 320 I = 2, 4\n XNUM = XNUM*WSQ + PLG(I)\n XDEN = XDEN*WSQ + QLG(I)\n 320 CONTINUE\n RESJ = PI2 * RESULT * W * XNUM/XDEN\n ELSE\n RESJ = PI2 * RESULT * LOG(AX/XY)\n END IF\nC-------------------------------------------------------------------\nC Now calculate Y0 for appropriate interval, preserving\nC accuracy near the zero of Y0\nC-------------------------------------------------------------------\n IF (AX .LE. THREE) THEN\n XNUM = PY0(6) * ZSQ + PY0(1)\n XDEN = ZSQ + QY0(1)\n DO 340 I = 2, 5\n XNUM = XNUM * ZSQ + PY0(I)\n XDEN = XDEN * ZSQ + QY0(I)\n 340 CONTINUE\n ELSE IF (AX .LE. FIVE5) THEN\n XNUM = PY1(7) * ZSQ + PY1(1)\n XDEN = ZSQ + QY1(1)\n DO 360 I = 2, 6\n XNUM = XNUM * ZSQ + PY1(I)\n XDEN = XDEN * ZSQ + QY1(I)\n 360 CONTINUE\n ELSE\n XNUM = PY2(8) * ZSQ + PY2(1)\n XDEN = ZSQ + QY2(1)\n DO 380 I = 2, 7\n XNUM = XNUM * ZSQ + PY2(I)\n XDEN = XDEN * ZSQ + QY2(I)\n 380 CONTINUE\n END IF\n RESULT = RESJ + UP * DOWN * XNUM / XDEN\n GO TO 2000\nC-------------------------------------------------------------------\nC Calculate J0 or Y0 for |ARG| > 8.0\nC-------------------------------------------------------------------\n 800 Z = EIGHT / AX\n W = AX / TWOPI\n W = AINT(W) + ONEOV8\n W = (AX - W * TWOPI1) - W * TWOPI2\n ZSQ = Z * Z\n XNUM = P0(5) * ZSQ + P0(6)\n XDEN = ZSQ + Q0(5)\n UP = P1(5) * ZSQ + P1(6)\n DOWN = ZSQ + Q1(5)\n DO 850 I = 1, 4\n XNUM = XNUM * ZSQ + P0(I)\n XDEN = XDEN * ZSQ + Q0(I)\n UP = UP * ZSQ + P1(I)\n DOWN = DOWN * ZSQ + Q1(I)\n 850 CONTINUE\n R0 = XNUM / XDEN\n R1 = UP / DOWN\n IF (JINT .EQ. 0) THEN\n RESULT = SQRT(PI2/AX) * (R0*COS(W) - Z*R1*SIN(W))\n ELSE\n RESULT = SQRT(PI2/AX) * (R0*SIN(W) + Z*R1*COS(W))\n END IF\n 2000 RETURN\nC---------- Last line of CALJY0 ----------\n END\n", "meta": {"hexsha": "adc68d7f9bca6a1a81fd60b87ad9b7fc8ab1b0c7", "size": 19598, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/f2cl/packages/toms/715/caljy0.f", "max_stars_repo_name": "sbwhitecap/clocc-hg", "max_stars_repo_head_hexsha": "f6cf2591ceef8a3a80e04da9b414cdf60a25a90f", "max_stars_repo_licenses": ["MIT"], "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/f2cl/packages/toms/715/caljy0.f", "max_issues_repo_name": "sbwhitecap/clocc-hg", "max_issues_repo_head_hexsha": "f6cf2591ceef8a3a80e04da9b414cdf60a25a90f", "max_issues_repo_licenses": ["MIT"], "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/f2cl/packages/toms/715/caljy0.f", "max_forks_repo_name": "sbwhitecap/clocc-hg", "max_forks_repo_head_hexsha": "f6cf2591ceef8a3a80e04da9b414cdf60a25a90f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.5099009901, "max_line_length": 71, "alphanum_fraction": 0.5507194612, "num_tokens": 7413, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942348544447, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6642832489211112}} {"text": "program multtable\nimplicit none\n\n integer :: i, j, k\n\n write(*, \"(a)\") \" x| 1 2 3 4 5 6 7 8 9 10 11 12\"\n write(*, \"(a)\") \"--+------------------------------------------------\"\n do i = 1, 12\n write(*, \"(i2, a)\", advance=\"no\") i, \"|\"\n\tdo k = 2, i\n \t write(*, \"(a4)\", advance=\"no\") \"\"\n end do\n \tdo j = i, 12\n write(*, \"(i4)\", advance=\"no\") i*j\n end do\n write(*, *)\n end do\n\nend program multtable\n", "meta": {"hexsha": "5d357f235f4d1f3dcd6302696dca70a8771aa07a", "size": 468, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Multiplication-tables/Fortran/multiplication-tables-1.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Multiplication-tables/Fortran/multiplication-tables-1.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Multiplication-tables/Fortran/multiplication-tables-1.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 23.4, "max_line_length": 73, "alphanum_fraction": 0.3717948718, "num_tokens": 169, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9086178919837705, "lm_q2_score": 0.7310585903489892, "lm_q1q2_score": 0.6642529152795255}} {"text": "program ex4p1\r\n use mt_mod\r\n implicit none\r\n integer, parameter:: ik=selected_int_kind(11), rk=selected_real_kind(11,100)\r\n integer(kind=ik) :: i, j, h, l, Np, runs=500\r\n real(kind=rk), parameter :: pi = 4.0*atan(1.0), k=8.6173324E-5, T=600\r\n real(kind=rk) :: x, x0, x1, trial, state, u, u1, a=1/real(2,rk)*k*T, mean, E_theor=3/2*k*T, sumrun=0, x_max, b\r\n real(kind=rk), allocatable :: E_MC(:), means(:), rms(:)\r\n\r\n b=sqrt(2/pi)*1/(a**3)\r\n \r\n call init_genrand64(int(123465, ik))\r\n\r\n open(1, action=\"write\", file=\"data_max.txt\", status=\"replace\", position=\"append\")\r\n open(2, action=\"write\", file=\"data_points.txt\", status=\"replace\", position=\"append\")\r\n\r\n allocate(means(runs))\r\n allocate(rms(1000))\r\n\r\n !Data for (E_max, RMS) plot with N=10^3 \r\n Np = 10**3\r\n allocate(E_MC(Np))\r\n !Vary E_max from 0.001 to 0.1\r\n do l=1, 100\r\n !Markov Chain\r\n x_max=0.001*l !0b\r\n do h=1, runs\r\n !Inital config.\r\n x = 3/real(2,rk)*k*T !0a\r\n do i=1, Np\r\n state = rho(x) !0c\r\n x0 = x !1\r\n u = genrand64_real1()*2-1 !2\r\n x1 = x + u*x_max !3\r\n trial = rho(x1) !4\r\n\r\n if (trial/state >= 1) then\r\n x = x1\r\n state = trial !5\r\n else if (trial/state >= genrand64_real1()) then\r\n x = x1\r\n state = trial !5\r\n else\r\n x = x0\r\n end if\r\n E_MC(i) = abs(x) !6\r\n end do\r\n\r\n means(h)=sum(E_MC)/real(Np, rk) !Mean energy of distribution\r\n end do\r\n\r\n !Sum inside RMS \r\n do i=1, runs\r\n sumrun=sumrun+(means(i)-E_theor)**2\r\n end do\r\n\r\n !RMS for x_max=0.001*l\r\n rms(l)=sqrt(1/real(runs,rk)*sumrun)\r\n sumrun=0\r\n\r\n print *, l*0.001,\"done.\"\r\n end do\r\n\r\n !Save data\r\n do l=1, 1000\r\n write(1, *) rms(h), 0.001*l\r\n end do\r\n deallocate(E_MC)\r\n deallocate(rms)\r\n\r\n print*, \"E_max done\"\r\n\r\n allocate(rms(6))\r\n \r\n !Set x_max according to previous results\r\n x_max=0.05\r\n\r\n !Markov Chain as before, but now with looping over N_points\r\n do j=2, 7\r\n Np = 10**j\r\n allocate(E_MC(Np))\r\n do h=1, runs\r\n x = 3/real(2,rk)*k*T\r\n do i=1, Np\r\n x0 = x\r\n E_MC(i) = abs(x)\r\n state = rho(x)\r\n u = genrand64_real1()*2-1\r\n x1 = x + u*x_max\r\n trial = rho(x1)\r\n if (trial/state >= 1) then\r\n x = x1\r\n state = trial\r\n else if (trial/state >= genrand64_real1()) then\r\n x = x1\r\n state = trial\r\n else\r\n x = x0\r\n end if\r\n end do\r\n means(h)=sum(E_MC)/real(Np, rk)\r\n end do\r\n do i=1, runs\r\n sumrun=sumrun+(means(i)-E_theor)**2\r\n end do\r\n rms(j-1)=sqrt(1/real(runs,rk)*sumrun)\r\n sumrun=0\r\n write(2, *) rms(j-1), 10**j\r\n deallocate(E_MC)\r\n print*, j, \"-power done\"\r\n end do\r\n \r\n close(1)\r\n close(2)\r\n\r\n\r\ncontains\r\n\r\nreal(kind=rk) function rho(E)\r\n implicit none\r\n real(kind=rk), intent(in) :: E\r\n rho=b*E**2*exp(-1/real(2,rk)*(E/a)**2)\r\nend function rho\r\nend program ex4p1", "meta": {"hexsha": "17ee1a2fd9a4911b7d56ca60ab3bbb261e4e47d8", "size": 3525, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Nico_Toikka_ex4/p1/ex4p1.f95", "max_stars_repo_name": "toicca/basics-of-mc", "max_stars_repo_head_hexsha": "71f2fc2ac4252c359a6c6bbf46d9bac743aaec25", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Nico_Toikka_ex4/p1/ex4p1.f95", "max_issues_repo_name": "toicca/basics-of-mc", "max_issues_repo_head_hexsha": "71f2fc2ac4252c359a6c6bbf46d9bac743aaec25", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Nico_Toikka_ex4/p1/ex4p1.f95", "max_forks_repo_name": "toicca/basics-of-mc", "max_forks_repo_head_hexsha": "71f2fc2ac4252c359a6c6bbf46d9bac743aaec25", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.4274193548, "max_line_length": 115, "alphanum_fraction": 0.4456737589, "num_tokens": 1081, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818865, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6642529118675492}} {"text": "!\n! ===================================\n! NIST Guide to Available Math Software.\n! Fullsource for module TVAL from package NAPACK.\n! Retrieved from NETLIB on Fri Aug 7 17:41:59 1998.\n! ===================================\n!\n SUBROUTINE TVAL(E, K, L, D, U, N, W) \n\n! ________________________________________________________\n! | |\n! | FIND THE K-TH SMALLEST EIGENVALUE OF A TRIDIAGONAL |\n! | MATRIX WHOSE CROSS-DIAGONAL PRODUCTS ARE NONNEGATIVE |\n! |USING BOTH THE BISECTION METHOD AND A NEWTON-LIKE METHOD|\n! | |\n! | INPUT: |\n! | |\n! | K --INDEX OF DESIRED EIGENVALUE (REPLACE K |\n! | BY -K TO GET K-TH LARGEST EIGENVALUE) |\n! | |\n! | L --SUBDIAGONAL (CAN BE IDENTIFIED WITH U) |\n! | |\n! | D --DIAGONAL |\n! | |\n! | U --SUPERDIAGONAL |\n! | |\n! | N --MATRIX DIMENSION |\n! | |\n! | W --WORK ARRAY (LENGTH AT LEAST N) |\n! | |\n! | OUTPUT: |\n! | |\n! | E --EIGENVALUE |\n! | |\n! | BUILTIN FUNCTIONS: ABS,MAX |\n! | PACKAGE SUBROUTINES: CP,EQL,INP,STM |\n! |________________________________________________________|\n!\n use kind_spec\n IMPLICIT NONE\n!-----------------------------------------------\n! D u m m y A r g u m e n t s\n!-----------------------------------------------\n integer, intent(in) :: K, N \n REAL(rprec):: E \n REAL(rprec), DIMENSION(N) :: L, D, U, W \n!-----------------------------------------------\n! L o c a l P a r a m e t e r s\n!-----------------------------------------------\n real(rprec), parameter :: zero = 0, one = 1\n!-----------------------------------------------\n! L o c a l V a r i a b l e s\n!-----------------------------------------------\n integer :: I, M \n REAL(rprec) :: S, T, Y, Z \n!-----------------------------------------------\n IF (N > 1) THEN \n! -------------------------------------------------------\n! |*** BOUND EIGENVALUES USING GERSCHGORIN'S THEOREM ***|\n! -------------------------------------------------------\n M = N - 1 \n Y = D(1) \n Z = D(1) \n S = 0 \n DO I = 1, M \n W(I) = L(I)*U(I) \n IF (W(I) < ZERO) GO TO 50 \n S = S + ABS(U(I)) \n T = D(I) + S \n Z = MAX(T,Z) \n T = D(I) - S \n Y = MIN(T,Y) \n S = ABS(L(I)) \n END DO \n T = D(N) + S \n Z = MAX(T,Z) \n T = D(N) - S \n Y = MIN(T,Y) \n M = K \n IF (K .LE. 0) M = N + K + 1 \n T = ONE \n T = T/2 \n S = ONE + T \n 1003 CONTINUE \n IF (S .LE. ONE) GO TO 1002 \n T = T/2 \n S = ONE + T \n IF (S .LE. ONE) GO TO 1002 \n T = T/2 \n S = ONE + T \n IF (S .LE. ONE) GO TO 1002 \n T = T/2 \n S = ONE + T \n IF (S .LE. ONE) GO TO 1002 \n T = T/2 \n S = ONE + T \n GO TO 1003 \n 1002 CONTINUE \n T = 8*N*T*MAX(ABS(Y),ABS(Z)) \n IF (T .NE. ZERO) THEN \n CALL STM (E, Y, Z, M, T, D, W, N) \n RETURN \n ENDIF \n ENDIF \n E = D(1) \n RETURN \n\n 50 CONTINUE \n WRITE (6, *) 'ERROR: SUBROUTINE TVAL CAN ONLY BE APPLIED' \n WRITE (6, *) 'WHEN THE CROSS-DIAGONAL PRODUCTS ARE NONNEGATIVE' \n STOP \n\n END SUBROUTINE TVAL \n\n\n SUBROUTINE STM(E, Y, Z, K, T, D, P, N) \n! ________________________________________________________\n! | |\n! | FIND THE K-TH SMALLEST EIGENVALUE OF A TRIDIAGONAL |\n! | MATRIX WHOSE CROSS-DIAGONAL PRODUCTS ARE NONNEGATIVE |\n! |USING BOTH THE BISECTION METHOD AND A NEWTON-LIKE METHOD|\n! | |\n! | INPUT: |\n! | |\n! | Y,Z --ENDS OF AN INTERVAL THAT CONTAINS THE |\n! | DESIRED EIGENVALUE |\n! | |\n! | K --INDEX OF DESIRED EIGENVALUE |\n! | |\n! | T --TOLERANCE (ITERATIONS CONTINUE UNTIL |\n! | THE ERROR IN THE EIGENVALUE .LE. T) |\n! | |\n! | D --DIAGONAL OF THE COEFFICIENT MATRIX A |\n! | |\n! | P --CROSS-DIAGONAL PRODUCTS A SUB I+1,I |\n! | TIMES A SUB I,I+1 |\n! | |\n! | N --MATRIX DIMENSION |\n! | |\n! | OUTPUT: |\n! | |\n! | E --EIGENVALUE |\n! | |\n! | BUILTIN FUNCTIONS: ABS,MAX,SIGN,SQRT |\n! | PACKAGE SUBROUTINES: CP,EQL,INP |\n! |________________________________________________________|\n!\n use kind_spec\n IMPLICIT NONE\n!-----------------------------------------------\n! D u m m y A r g u m e n t s\n!-----------------------------------------------\n integer:: K, N \n REAL(rprec):: E, Y, Z, T \n REAL(rprec), DIMENSION(N) :: D, P \n!-----------------------------------------------\n! L o c a l P a r a m e t e r s\n!-----------------------------------------------\n real(rprec), parameter :: one = 1, zero = 0\n!-----------------------------------------------\n! L o c a l V a r i a b l e s\n!-----------------------------------------------\n integer :: I, J, M \n REAL(rprec) :: A,B,FL,FR,L,Q,R,S,U,V,\n 1 W,D2,D3,D4,P2,P3,P4,D34,D42,D23 \n REAL(rprec), DIMENSION(4) :: F, H, X \n REAL(rprec), DIMENSION(4) :: G \n REAL(rprec) :: C, GL, GR \n!-----------------------------------------------\n L = Y\n R = Z\n IF ( L .LT. R ) GOTO 10\n L = Z\n R = Y\n10 IF ( N .EQ. 1 ) GOTO 210\n S = T + T\n U = ONE\n20 U = U/2\n A = ONE + U\n IF (A .GT. ONE) GOTO 20\n U = 5*U\n V = U/2\n CALL CP(L,FL,GL,I,D,P,N)\n CALL CP(R,FR,GR,J,D,P,N)\n IF ( I .GE. K ) GOTO 190\n IF ( J .LT. K ) GOTO 200\nC --------------------------------\nC |*** ISOLATE THE EIGENVALUE ***|\nC --------------------------------\n30 E = R - L\n IF ( E .LE. S ) GOTO 180\n IF ( E .LE. U*(ABS(L)+ABS(R)) ) GOTO 180\n IF ( J .EQ. I+1 ) GOTO 70\n40 A = .5*(L+R)\n CALL CP(A,B,C,M,D,P,N)\n IF ( K .LE. M ) GOTO 50\n L = A\n I = M\n FL = B\n GL = C\n GOTO 30\n50 R = A\n J = M\n FR = B\n GR = C\n GOTO 30\n60 E = R - L\n IF ( E .LE. S ) GOTO 180\n IF ( E .LE. U*(ABS(L)+ABS(R)) ) GOTO 180\n70 X(1) = L\n F(1) = FL\n G(1) = GL\n X(2) = R\n F(2) = FR\n G(2) = GR\n CALL EQL(X,F,G,H,2)\n IF ( H(1) .EQ. H(2) ) GOTO 160\nC ---------------------\nC |*** SECANT STEP ***|\nC ---------------------\n A = X(1) - H(1)*(X(1)-X(2))/(H(1)-H(2))\n Q = A\n W = max(T,V*(ABS(L)+ABS(R)))\n IF ( ABS(A-L) .LT. W ) A = L + W\n IF ( ABS(A-R) .LT. W ) A = R - W\n CALL CP(A,B,C,J,D,P,N)\n IF ( I .GE. J ) GOTO 80\n R = A\n FR = B\n GR = C\n GOTO 90\n80 L = A\n FL = B\n GL = C\n90 X(3) = A\n F(3) = B\n G(3) = C\n W = R - L\n IF ( W .LE. S ) GOTO 220\n IF ( W .LE. U*(ABS(L)+ABS(R)) ) GOTO 220\n CALL EQL(X,F,G,H,3)\nC --------------------------------------\nC |*** QUADRATIC INTERPOLATION STEP ***|\nC --------------------------------------\n CALL INP(A,X(1),X(2),X(3),H(1),H(2),H(3),L,R)\n B = L\n IF ( ABS(A-L) .GT. ABS(A-R) ) B = R\nC ------------------------------------\nC |*** APPLY PSEUDO-NEWTON METHOD ***|\nC ------------------------------------\n100 Q = A\n W = max(T,V*(ABS(L)+ABS(R)))\n IF ( ABS(A-L) .LT. W ) GOTO 110\n IF ( ABS(A-R) .GT. W ) GOTO 130\n110 IF ( A+A .GT. L+R ) GOTO 120\n A = L + W\n GOTO 130\n120 A = R - W\n130 IF ( A .LE. L ) GOTO 160\n IF ( A .GE. R ) GOTO 160\n E = .5*E\n IF ( E .LT. ABS(B-A) ) GOTO 160\n CALL CP(A,B,C,J,D,P,N)\n IF ( I .GE. J ) GOTO 140\n R = A\n FR = B\n GR = C\n GOTO 150\n140 L = A\n FL = B\n GL = C\n150 W = R - L\n IF ( W .LE. S ) GOTO 220\n IF ( W .LE. U*(ABS(L)+ABS(R)) ) GOTO 220\n X(4) = A\n F(4) = B\n G(4) = C\n CALL EQL(X,F,G,H,4)\n IF ( X(1) .LT. L ) GOTO 160\n IF ( X(1) .GT. R ) GOTO 160\n B = X(1)\n D4 = X(4) - B\n D3 = X(3) - B\n D2 = X(2) - B\n D34 = X(3) - X(4)\n D42 = X(4) - X(2)\n D23 = X(2) - X(3)\n P2 = D2*(ONE+((D2/D3)*D42+(D2/D4)*D23)/D34)\n P3 = D3*(ONE+((D3/D2)*D34+(D3/D4)*D23)/D42)\n P4 = D4*(ONE+((D4/D2)*D34+(D4/D3)*D42)/D23)\n IF (P2 .NE. ZERO) P2 = (H(2)-H(1))/P2\n IF (P3 .NE. ZERO) P3 = (H(3)-H(1))/P3\n IF (P4 .NE. ZERO) P4 = (H(4)-H(1))/P4\n P2 = P2 + P3 + P4\n IF (P2 .EQ. ZERO) GOTO 160\n A = B - H(1)/P2\n GOTO 100\nC --------------------------\nC |*** BISECTION METHOD ***|\nC --------------------------\n160 A = (L+R)/2\n CALL CP(A,B,C,J,D,P,N)\n IF ( I .GE. J ) GOTO 170\n R = A\n FR = B\n GR = C\n GOTO 60\n170 L = A\n FL = B\n GL = C\n GOTO 60\n180 E = (L+R)/2\n RETURN\n190 E = L\n RETURN\n200 E = R\n RETURN\n210 E = D(1)\n IF ( L .GT. E ) E = L\n IF ( R .LT. E ) E = R\n RETURN\n220 E = Q\n RETURN\n END SUBROUTINE STM\n\n\n SUBROUTINE INP(A, X, Y, Z, U, V, W, L, R) \n use kind_spec\n IMPLICIT NONE\n!-----------------------------------------------\n! D u m m y A r g u m e n t s\n!-----------------------------------------------\n REAL(rprec) :: A, X, Y, Z, U, V, W, L, R \n!-----------------------------------------------\n! L o c a l P a r a m e t e r s\n!-----------------------------------------------\n real(rprec), parameter :: zero = 0, one = 1\n!-----------------------------------------------\n! L o c a l V a r i a b l e s\n!-----------------------------------------------\n REAL(rprec) :: B, C, P, Q, S, T \n!-----------------------------------------------\n S = Z - X \n T = (Y - X)/S \n A = (U - V)/T + (W - V)/(1. - T) \n IF (A .NE. ZERO) THEN \n B = .5_dp*(W - U)/A - .5_dp \n C = U/A \n T = SQRT(ABS(C)) \n IF (ABS(B) < SIGN(T,C)) GO TO 60 \n T = MAX(T,ABS(B)) \n IF (T .EQ. ZERO) GO TO 50 \n Q = ONE/T \n P = SQRT((Q*B)**2 - Q*C*Q) \n P = T*P \n IF (ABS(P + B) .LE. ABS(P - B)) THEN \n Q = P - B \n ELSE \n Q = -(B + P) \n ENDIF \n P = C/Q \n Q = X + S*Q \n P = X + S*P \n IF (Q .GE. L) THEN \n IF (Q .LE. R) THEN \n A = Q \n RETURN \n ENDIF \n ENDIF \n A = P \n RETURN \n ENDIF \n IF (U .NE. W) THEN \n A = X + S*U/(U - W) \n RETURN \n ENDIF \n 50 CONTINUE \n A = L \n RETURN \n 60 CONTINUE \n A = X - S*B \n RETURN \n\n END SUBROUTINE INP \n\n\n SUBROUTINE CP(T, B, V, L, D, P, N) \n!------------------------------------------------\n!*** EVALUATE CHARACTERISTIC POLYNOMIAL AND ***\n! SIGN ALTERNATIONS \n!------------------------------------------------\n use kind_spec\n IMPLICIT NONE\n!-----------------------------------------------\n! D u m m y A r g u m e n t s\n!-----------------------------------------------\n integer :: L, N \n REAL(rprec) :: T, B \n REAL(rprec) :: V \n REAL(rprec), DIMENSION(N) :: D, P \n!-----------------------------------------------\n! L o c a l P a r a m e t e r s\n!-----------------------------------------------\n real(rprec), parameter :: zero = 0, one = 1\n!-----------------------------------------------\n! L o c a l V a r i a b l e s\n!-----------------------------------------------\n integer :: I, J, M \n REAL(rprec) :: A, C, E, F, U, Z \n!-----------------------------------------------\n L = 0 \n Z = 0 \n V = Z \n IF (N .LE. 1) THEN \n B = D(1) - T \n IF (B .LE. Z) L = 1 \n RETURN \n ENDIF \n F = 65536\n F = F**4\n E = ONE/F \n U = 16 \n M = 0 \n I = 1 \n 20 CONTINUE \n C = ONE \n B = D(I) - T \n 30 CONTINUE \n IF (B .LE. Z) GO TO 70 \n IF (I .GE. N) GO TO 130 \n 40 CONTINUE \n J = I \n I = I + 1 \n A = (D(I)-T)*B - P(J)*C \n C = B \n B = A \n 50 CONTINUE \n A = ABS(B) \n IF (A > F) GO TO 60 \n IF (A > E) GO TO 30 \n IF (A .EQ. Z) GO TO 70 \n C = C*F \n B = B*F \n V = V - U \n GO TO 50 \n 60 CONTINUE \n C = C*E \n B = B*E \n V = V + U \n GO TO 50 \n 70 CONTINUE \n L = L + 1 \n IF (I .GE. N) GO TO 130 \n IF (B < Z) GO TO 90 \n IF (P(I) > ZERO) GO TO 90 \n I = I + 1 \n M = 1 \n V = Z \n GO TO 20 \n 80 CONTINUE \n IF (B .GE. Z) GO TO 120 \n IF (I .GE. N) GO TO 130 \n 90 CONTINUE \n J = I \n I = I + 1 \n A = (D(I)-T)*B - P(J)*C \n C = B \n B = A \n 100 CONTINUE \n A = ABS(B) \n IF (A > F) GO TO 110 \n IF (A > E) GO TO 80 \n IF (A .EQ. Z) GO TO 120 \n C = C*F \n B = B*F \n V = V - U \n GO TO 100 \n 110 CONTINUE \n C = C*E \n B = B*E \n V = V + U \n GO TO 100 \n 120 CONTINUE \n L = L + 1 \n IF (I .GE. N) GO TO 130 \n IF (B > Z) GO TO 40 \n IF (P(I) > ZERO) GO TO 40 \n I = I + 1 \n M = 1 \n V = Z \n GO TO 20 \n 130 CONTINUE \n IF (M .NE. 1) THEN \n IF (B .NE. ZERO) THEN \n A = ONE/U \n IF (ABS(B) .GE. A) THEN \n 140 CONTINUE \n IF (ABS(B) < ONE) RETURN \n B = B*A \n V = V + ONE \n GO TO 140 \n ENDIF \n B = B*U \n V = V - ONE\n 1003 CONTINUE \n IF (ABS(B) .GE. A) GO TO 1002 \n B = B*U \n V = V - ONE\n IF (ABS(B) .GE. A) GO TO 1002 \n B = B*U \n V = V - ONE\n IF (ABS(B) .GE. A) GO TO 1002 \n B = B*U \n V = V - ONE\n IF (ABS(B) .GE. A) GO TO 1002 \n B = B*U \n V = V - ONE\n GO TO 1003 \n 1002 CONTINUE \n RETURN \n ENDIF \n ENDIF \n V = Z \n B = Z \n RETURN \n\n END SUBROUTINE CP \n\n\n SUBROUTINE EQL(X, F, G, H, N) \n use kind_spec\n IMPLICIT NONE\n!-----------------------------------------------\n! D u m m y A r g u m e n t s\n!-----------------------------------------------\n integer N \n REAL(rprec), DIMENSION(N) :: X, F, H \n REAL(rprec), DIMENSION(N) :: G \n!-----------------------------------------------\n! L o c a l V a r i a b l e s\n!-----------------------------------------------\n integer :: I1, J2, I, J, K, L, M, NM1 \n REAL(rprec) :: R, S, Z, U \n!-----------------------------------------------\n Z = 0 \n I = 1 \n R = X(N) \n S = F(N) \n U = G(N) \n IF (S .EQ. Z) GO TO 30 \n I1 = I \n J2 = MAX(N - 1,I1) \n DO I = I1, J2 \n IF (F(I) .EQ. Z) CYCLE \n IF (U < G(I)) GO TO 30 \n IF (U > G(I)) CYCLE \n IF (ABS(F(I)) .GE. ABS(S)) GO TO 30 \n END DO \n GO TO 50 \n 30 CONTINUE \n M = N + I \n NM1 = N - 1 \n DO J = I, NM1 \n K = M - J \n L = K - 1 \n X(K) = X(L) \n F(K) = F(L) \n G(K) = G(L) \n END DO \n X(I) = R \n F(I) = S \n G(I) = U \n 50 CONTINUE \n U = G(N) \n WHERE ((G(:N)-U).LE.(-99._dp) .OR. F(:N).EQ.Z) H(:N) = Z \n WHERE (F(:N).NE.Z .AND. (G(:N)-U)>(-99._dp))\n 1 H(:N) = F(:N)*16._dp**(G(:N)-U) \n\n RETURN \n END SUBROUTINE EQL \n\n\n SUBROUTINE TVECT(E, X, L, D, U, N, W) \n! ________________________________________________________\n! | |\n! | COMPUTE EIGENVECTOR CORRESPONDING TO GIVEN REAL |\n! | EIGENVALUE FOR A REAL TRIDIAGONAL MATRIX |\n! | |\n! | INPUT: |\n! | |\n! | E --EIGENVALUE |\n! | |\n! | L --SUBDIAGONAL |\n! | |\n! | D --DIAGONAL |\n! | |\n! | U --SUPERDIAGONAL |\n! | |\n! | N --MATRIX DIMENSION |\n! | |\n! | W --WORK ARRAY (LENGTH AT LEAST 4N) |\n! | |\n! | OUTPUT: |\n! | |\n! | E --IMPROVED ESTIMATE FOR EIGENVALUE |\n! | |\n! | X --EIGENVECTOR |\n! | |\n! | BUILTIN FUNCTIONS: ABS,SQRT |\n! |________________________________________________________|\n!\n use kind_spec\n IMPLICIT NONE\n!-----------------------------------------------\n! D u m m y A r g u m e n t s\n!-----------------------------------------------\n integer:: N \n REAL(rprec):: E \n REAL(rprec), DIMENSION(N) :: X, L, D, U\n REAL(rprec), DIMENSION(4*N) :: W\n!-----------------------------------------------\n! L o c a l P a r a m e t e r s\n!-----------------------------------------------\n real(rprec), parameter :: zero = 0, one = 1\n!-----------------------------------------------\n! L o c a l V a r i a b l e s\n!-----------------------------------------------\n integer :: G1, J1, J2, J4, J3, F, G, H, I, J, K, M \n REAL(rprec) :: O, P, Q, R, S, T, V, Y, Z \n!-----------------------------------------------\n IF (N .LE. 1) THEN \n E = D(1) \n X(1) = ONE \n RETURN \n ENDIF \n M = N - 1 \n J = 2 \n! ---------------------------------------------------------\n! |*** STORE MATRIX IN W ARRAY AND SUBTRACT EIGENVALUE ***|\n! ---------------------------------------------------------\n X(1:M) = 0\n DO I = 1,M\n W(J) = U(I)\n W(J+1) = D(I) - E\n W(J+2) = L(I)\n J = J + 4\n END DO \n W(J) = 0 \n W(J+1) = D(N) - E \n O = 65536\n O = O**(-4) \n T = O/2\n S = T \n T = T/2\n P = S \n S = S + T \n IF (S .GE. O) GO TO 40 \n DO WHILE(S + T > S) \n T = T/2\n P = S \n S = S + T \n IF (S .GE. O) GO TO 40 \n END DO \n 40 CONTINUE \n R = W(3) \n V = ABS(R) + ABS(W(4)) \n F = 4 \n M = 4*N - 3 \n G = -2 \n! ---------------------------\n! |*** FACTOR THE MATRIX ***|\n! ---------------------------\n G = G + 4 \n G1 = G \n DO G = G1, M, 4 \n H = G - 1 \n I = G + 2 \n J = G + 5 \n! --------------------\n! |*** FIND PIVOT ***|\n! --------------------\n Q = W(I) \n Y = ABS(Q) \n Z = ABS(R) \n IF (Z < Y) THEN \n! -------------------\n! |*** SWAP ROWS ***|\n! -------------------\n IF (V < Y) THEN \n V = Y \n F = I \n ENDIF \n T = W(G) \n W(G) = W(J) \n W(J) = T \n T = R/Q \n K = G + 1 \n W(K) = Q \n K = J - 1 \n S = W(K) \n IF (S .NE. ZERO) THEN \n IF (S .EQ. O) S = P \n W(K) = -S*T \n W(H) = S \n GO TO 100 \n ENDIF \n W(K) = S \n W(H) = O \n GO TO 100 \n ENDIF \n W(H) = 0 \n IF (V < Z) THEN \n V = Z \n F = I \n ENDIF \n IF (R .EQ. ZERO) GO TO 120 \n T = Q/R \n! -------------------\n! |*** ELIMINATE ***|\n! -------------------\n 100 CONTINUE \n R = W(J) - T*W(G) \n W(J) = R \n W(I) = T \n END DO \n IF (ABS(R) < V) THEN \n V = R \n F = J + 1 \n! ---------------------------------------------------\n! |*** COMPUTE INITIAL EIGENVECTOR APPROXIMATION ***|\n! ---------------------------------------------------\n ENDIF \n 120 CONTINUE \n J = F/4 \n X(J) = ONE \n IF (J .NE. 1) THEN \n K = F - 5 \n J = J - 1 \n X(J) = (X(J)-W(K-1)*X(J+1))/W(K) \n J1 = J \n IF (J1 - 1 > 0) THEN \n DO J = J1, 2, -1 \n K = K - 4 \n T = W(K-2) \n IF (T .EQ. O) T = 0 \n X(J-1) = (X(J-1)-W(K-1)*X(J)-T*X(J+1))/W(K) \n END DO \n ENDIF \n GO TO 140 \n ENDIF \n 140 CONTINUE \n IF (V .NE. ZERO) THEN \n S = MAXVAL(ABS(X(:N)))\n S = ONE/S \n X(:N) = S*X(:N)\n R = SUM(X(:N)*X(:N))\n K = 0 \n J = 1 \n Y = X(1) \n! -----------------------------------------------------\n! |*** APPLY ONE ITERATION OF INVERSE POWER METHOD ***|\n! -----------------------------------------------------\n J2 = J \n J4 = MAX(N - 1,J2) \n DO J = J2, J4 \n K = K + 4 \n I = J \n S = W(K) \n W(K) = Y \n Y = X(J+1) \n IF (W(K-3) .NE. ZERO) THEN \n T = X(J+1) \n X(J+1) = X(I) \n X(I) = T \n ENDIF \n X(J+1) = X(J+1) - S*X(I) \n END DO \n! ---------------------------\n! |*** BACK SUBSTITUTION ***|\n! ---------------------------\n S = X(J)/W(K+3) \n X(J) = S \n T = ABS(S) \n V = S*Y \n J = J - 1 \n K = K - 1 \n S = (X(J)-W(K-1)*S)/W(K) \n X(J) = S \n T = MAX(ABS(S),T) \n V = V + S*W(K+1) \n J3 = J \n IF (J3 - 1 > 0) THEN \n DO J = J3, 2, -1 \n K = K - 4 \n Z = W(K-2) \n IF (Z .EQ. O) Z = 0 \n S = (X(J-1)-W(K-1)*S-Z*X(J+1))/W(K) \n X(J-1) = S \n T = MAX(ABS(S),T) \n V = V + S*W(K+1) \n END DO \n ENDIF \n IF (V .NE. ZERO) V = R/V \n T = ONE/T \n S = SUM((X(:N)*V)**2) \n Z = SUM((T*X(:N))**2) \n T = T/SQRT(Z) \n X(:N) = T*X(:N) \n! --------------------------------------------------------------\n! |*** USE RAYLEIGH QUOTIENT TO IMPROVE EIGENVALUE ESTIMATE ***|\n! --------------------------------------------------------------\n IF (R + R .GE. S) E = E + V \n RETURN \n ENDIF \n T = MAXVAL(ABS(X(:N)))\n T = ONE/T \n Z = SUM((T*X(:N))**2) \n T = T/SQRT(Z) \n X(:N) = T*X(:N) \n\n END SUBROUTINE TVECT \n", "meta": {"hexsha": "11b64937fc43ea2ed22890d3a783b07d554179b4", "size": 24765, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/cobravmec/cobra_lib.f", "max_stars_repo_name": "jonathanschilling/VMEC_6_90", "max_stars_repo_head_hexsha": "5a63cc2b475038560d8e81de1ddae477d6f8ddec", "max_stars_repo_licenses": ["MIT"], "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/cobravmec/cobra_lib.f", "max_issues_repo_name": "jonathanschilling/VMEC_6_90", "max_issues_repo_head_hexsha": "5a63cc2b475038560d8e81de1ddae477d6f8ddec", "max_issues_repo_licenses": ["MIT"], "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/cobravmec/cobra_lib.f", "max_forks_repo_name": "jonathanschilling/VMEC_6_90", "max_forks_repo_head_hexsha": "5a63cc2b475038560d8e81de1ddae477d6f8ddec", "max_forks_repo_licenses": ["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.1277372263, "max_line_length": 70, "alphanum_fraction": 0.2801130628, "num_tokens": 7475, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178870347122, "lm_q2_score": 0.731058584489497, "lm_q1q2_score": 0.6642529063374344}} {"text": "C LAST UPDATE 16/03/89\nC+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\nC\n SUBROUTINE FFT1D (X,Y,TABLE,M,LL,ISN)\n IMPLICIT NONE\nC\nC Purpose: FFT is in place DFT computation using Sande algorithm\nC and Markel pruning modification.\nC\n REAL X(1),Y(1),TABLE(1)\n INTEGER M,LL,ISN\nC\nC X : Array of length 2**M used to hold real part of complex input\nC Y : Array of length 2**M used to hold imaginary part of input\nC X&Y are real and complex part of output\nC TABLE : Array of length N/4+1 (N=2**M) contains quarter length\nC cosine table.\nC M : Integer power of two which determines size of fft to be\nC performed. (bit reverse table is set for a max of N=2**12)\nC LL : Integer power of 2 which determines 2**ll actual data pts\nC and thus no. of stages in which no pruning is allowable\nC ISN :-1 for forward fft\nC +1 for reverse fft\nC\nC Calls 0:\nC Called by: FRWFFT , INVFFT\nC\nC-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-\nC Local variables:\nC\n REAL C,S,R,FI,T1,T2\n INTEGER L(12),L1,L2,L3,L4,L5,L6,L7,L8,L9,L10,L11,L12,IARG\n INTEGER J,J1,J2,J3,J4,J5,J6,J7,J8,J9,J10,J11,JR,JN,K1,K2,K3\n INTEGER N,ND4,ND4P1,ND4P2,ND2P2,LLL,LM,LMM,LO,LI,LMX,LIX,ISCL\nC\nC L :\nC\n EQUIVALENCE (L12,L(1)) , (L11,L(2)) , (L10,L(3)) , (L9,L(4)) ,\n 1 (L8,L(5)) , (L7,L(6)) , (L6,L(7)) , (L5,L(8)) ,\n 1 (L4,L(9)) , (L3,L(10)) , (L2,L(11)) , (L1,L(12))\nC\nC-----------------------------------------------------------------------\n N=2**M\n ND4=N/4\n ND4P1=ND4+1\n ND4P2=ND4P1+1\n ND2P2=ND4+ND4P2\n LLL=2**LL\n DO 50 LO=1,M\n LMX=2**(M-LO)\n LMM=LMX\n LIX=2*LMX\n ISCL=N/LIX\nC\nC=======TEST FOR PRUNING\nC\n IF (LO-M+LL) 10,20,20\n 10 LMM=LLL\n 20 DO 50 LM=1,LMM\n IARG=(LM-1)*ISCL+1\n IF (IARG.LE.ND4P1) GO TO 30\n K1=ND2P2-IARG\n C=-TABLE(K1)\n K3=IARG-ND4\n S=ISN*TABLE(K3)\n GO TO 40\n 30 C=TABLE(IARG)\n K2=ND4P2-IARG\n S=ISN*TABLE(K2)\n 40 DO 50 LI=LIX,N,LIX\n J1=LI-LIX+LM\n J2=J1+LMX\n T1=X(J1)-X(J2)\n T2=Y(J1)-Y(J2)\n X(J1)=X(J1)+X(J2)\n Y(J1)=Y(J1)+Y(J2)\n X(J2)=C*T1-S*T2\n Y(J2)=C*T2+S*T1\n 50 CONTINUE\nC\nC========PERFORM BIT REVERSAL\nC\n DO 70 J=1,12\n L(J)=1\n IF (J-M) 60,60,70\n 60 L(J)=2**(M+1-J)\n 70 CONTINUE\n JN=1\n DO 120 J1=1,L1\n DO 120 J2=J1,L2,L1\n DO 120 J3=J2,L3,L2\n DO 120 J4=J3,L4,L3\n DO 120 J5=J4,L5,L4\n DO 120 J6=J5,L6,L5\n DO 120 J7=J6,L7,L6\n DO 120 J8=J7,L8,L7\n DO 120 J9=J8,L9,L8\n DO 120 J10=J9,L10,L9\n DO 120 J11=J10,L11,L10\n DO 120 JR=J11,L12,L11\n IF (JN-JR) 80,80,90\n 80 R=X(JN)\n X(JN)=X(JR)\n X(JR)=R\n FI=Y(JN)\n Y(JN)=Y(JR)\n Y(JR)=FI\n 90 IF (ISN) 110,110,100\n 100 X(JR)=X(JR)/REAL(N)\n Y(JR)=Y(JR)/REAL(N)\n 110 JN=JN+1\n 120 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "6a0494993484e131bf64693225580b93f82ceb23", "size": 3369, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "otoko/src/fft1d.f", "max_stars_repo_name": "scattering-central/CCP13", "max_stars_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "otoko/src/fft1d.f", "max_issues_repo_name": "scattering-central/CCP13", "max_issues_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "otoko/src/fft1d.f", "max_forks_repo_name": "scattering-central/CCP13", "max_forks_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-09-05T15:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-15T11:13:45.000Z", "avg_line_length": 29.2956521739, "max_line_length": 72, "alphanum_fraction": 0.4487978629, "num_tokens": 1279, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178994073577, "lm_q2_score": 0.7310585727705126, "lm_q1q2_score": 0.6642529047344841}} {"text": " program GaussSeidel\n implicit none\n\n ! Diclarations\n character :: FileImport, LINE, NetDataDate,NetOrigName,NetSeason,&\n &NetCaseId,FData, CharNbBus, CharNbBranch\n character(len=106) :: FMT1\n character(len=124) :: FMT2\n character,dimension(500) :: BusName\n character(len=32)::NetDataFileIn, NetDataFileOut, arg, NetFileFormat\n character(len=100) :: OutMessage\n integer,dimension(500) :: NbNode,LFAreaN,LZoneN,Ntype,Ib,Jb,LFAreaB,&\n &LZoneB,Circ,BType,LineRate1,LineRate2,LineRate3,BCntl,BSide\n integer :: N,I,J,Kmax,S,K,M,W,NB,NetYear,ii,jj\n real,dimension(500) :: FV,FDelta,Pd,Qd,Pg,Qg,Vb,Vspec,Qmax,Qmin,&\n &ChargLine,TrRatio,TrPhase,Tapmin,Tapmax,SteSize,Vmin,Vmax\n real::a,b,d,e,NetMVABase\n real,Dimension(500):: P,Q\n complex,dimension(500) :: Ybs\n complex,dimension(500,500) :: Z,Ya,Ys\n complex,Dimension(500)::V\n complex::SS,ST,Va,eps,DVamax\n\n ! arg represente les arguments transmits \u00e0 l'application\n NetDataFileOut=\"\"\n if (iargc()/=0 .and. iargc()>0) then\n CALL getarg(1, arg)\n NetDataFileIn=arg\n if (iargc()>1) then\n CALL getarg(2, arg)\n NetDataFileOut=arg\n endif\n if (iargc()>2) then\n CALL getarg(3, arg)\n NetFileFormat=arg\n NetFileFormat=trim(NetFileFormat)\n endif\n DO i = 4, iargc()\n CALL getarg(i, arg)\n selectcase (arg)\n Case (\"GS\")\n Case (\"NR\")\n Case (\"RL\")\n Case (\"FD\")\n endselect\n enddo\n ! NetDataFile : Nom du fichier de donnees du reseau\n open(unit=100,file=NetDataFileIn,status='old',action='read')\n ! Data.res : Nom du fichier de resultats du reseau\n if (NetDataFileOut==\"\") Then\n open(unit=200,file='data.html')\n else\n NetDataFileOut=trim(NetDataFileOut) // \".html\"\n open(unit=200,file=NetDataFileOut)\n endif\n ! Preparation du fichier \u00e0 soumettre : RESULTATS et insertion des BALISES HTML necessaire\n write(200,*) \"\"\n write(200,*) \"\"\n write(200,*) \"\"\n write(200,*) \"\"\n write(200,*) \"Net Platform Version 1.0 | UTMB, SimulIA Team ENERGARID Lab., 2015\"\n write(200,*) \"\"\n write(200,*) \"\"\n write(200,*) \"\"\n write(200,*) \"\"\n write(200,*) \"\"\n write(200,*) \"\"\n write(200,*) \" \"\n write(200,*) \"
\"\n write(200,*) \"

DONNEES DU RESEAU [\",trim(NetDataFileIn),\"]



\"\n\n if(NetFileFormat=='CDF')then\n call CDFImport(100)\n else\n Call SimulIANetRead(100,200)\n endif\n\n ! Debut du traitement selon la methode GAUSS-SEIDEL\n K=0\n write(200,*) '

RESULTATS INTERMEDIAIRES


'\n 100 write(200,'(A,I4,A)') 'Iteration : ',K,'
'\n ! Boucle principale du calcul des element du vecteur tensions nodales\n do I=1,N\n ! On saute le noeud BILAN numero s\n if (I/=S)then\n ! Calcul de la somme des courant de contributions SS\n SS=(0.,0.)\n do J=1,N\n if(I/=J)then\n SS=SS+Ya(I,J)*V(J)\n endif\n enddo\n ! Si TYPE du noeud courant I est Producteur (1), on calcul la puissance reactive Q(i)\n if (Ntype(I)==2) then\n ST=cmplx(0.,0.)\n do J=1,N\n ST=ST+Ya(I,J)*V(J)\n enddo\n Q(I)=aimag(V(I)*ST)\n endif\n ! On sauvegarde l'ancienne valeur de V(i) dans Va\n Va=V(I)\n ! On calcul la nouvelle valeur de V(i)\n V(I)=(1/Ya(I,I))*(cmplx(P(I),-Q(I))/V(I)-SS)\n ! On compare la difference des deux valeur Va et V(i) \u00e0 Delta Vmax, si superieur on ecrase Delta Vmax\n if (real(Va-V(I))>real(DVamax) .and. aimag(Va-V(I))>aimag(DVamax)) then\n DVamax=(Va-V(I))\n endif\n endif\n enddo\n ! Fin de la boucle principale\n ! On imprime les valeurs intermediaires de V\n write(200,*) '

TENSIONS NODALES (TMP)


'\n do M=1,N\n write(200,'(2F12.6,A)') V(M),'
'\n enddo\n if (cabs(DVamax)>cabs(eps)) then\n K=K+1\n if (K<=Kmax) then\n Go to 100\n else\n write(200,*) '

Le calcul a diverge, le maximum des iterations ',&\n &Kmax,' a ete atteint


'\n GoTo 2\n endif\n else\n ! Calcul de P(s) et Q(s), du noeud BILAN\n ST=cmplx(0.,0.)\n do I=1,N\n ST=ST+Ya(S,I)*V(S)\n enddo\n P(S)=Real(V(S)*ST)\n Q(S)=aimag(V(S)*ST)\n write(200,*) '

PUISSANCE APPARENTE NODALES DU NOEUD BILAN


'\n write(200,'(2F14.6,A)') P(S),Q(S),'
'\n write(200,*) '

RESULTATS FINAUX (en p.u.)


'\n write(200,'(A,I4,A)') \"

Pour un nombre d'iterations gal \u00e0 \",K,\"


\"\n write(200,*) '
'\n do I=1,N\n write(200,'(2F12.6,A)') V(I),'
'\n enddo\n ! calcul des puissance des pertes par transmission PL et QL\n SS=cmplx(0.,0.)\n ST=cmplx(0.,0.)\n do I=1,N\n SS=SS+P(S)\n ST=ST+Q(S)\n enddo\n write(200,*) '
'\n write(200,*) '

PERTES PAR TRANSMISSION PL et QL (en p.u.)


'\n write(200,'(2F12.6,A)') SS, ST,'
'\n endif\n 2 write(200,*) \"
\"\n write(200,*) \"\"\n else\n OutMessage=\"Donner au moins un argument, NOM DU FICHIER\\n\"\n open(unit=300,file='Error')\n write(300,*) OutMessage\n endif\n\n CONTAINS\n\n Subroutine SimulIANetRead(InFile, OutFile)\n implicit none\n integer,intent(In) :: InFile, OutFile\n ! Lecture des nombres de noeuds et de lignes\n ! saisie de la dimension reseau\n Read(InFile,'(2I2)') N,NB\n ! Eciture de N et de Nb dans le fichier \u00e0 soumettre\n write(OutFile,*)'

le nombre =',N,' le nombre de branches=',NB,'


'\n ! Initialisation des elements de la matrice admittance\n do I=1,N\n do J=1,N\n Ya(I,J)=cmplx(0.,0.)\n enddo\n enddo\n ! Lecture et ecriture des donnees des lignes\n write(OutFile,*) '

La matrice admittance, elements extra-diagonaux


'\n write(OutFile,*) ' Ni Nj Ya[i,j]
'\n do w=1,NB\n Read(InFile,*) I,J,a,b,d,e\n Z(I,J) = cmplx(a,b)\n Ys(I,J)= cmplx(d,e)\n if(real(Z(I,J))>1.0e-6 .and. aimag(Z(I,J))>1.0e-6)then\n Ya(I,J)=-1/Z(I,J)\n else\n Ya(I,J)=cmplx(1.0e-6, 1.0e-6)\n endif\n Ya(J,I)=Ya(I,J)\n Z(J,I)=Z(I,J)\n write(OutFile, '(2I4,2F12.6,A)') I,J,Ya(I,J),'
'\n enddo\n ! Calcul les element de diagonale\n write(OutFile,*)'

La matrice admittance, les elements diagonaux


'\n do I=1,N\n Ya(I,I)=(0.,0.)\n do J=1,N\n if(Z(I,J)/=0)then\n Ya(I,I)=Ya(I,I)+(-Ya(I,J)+Ys(I,J)/2)\n endif\n enddo\n write(OutFile, '(2I4,2F12.6,A)') I,I,Ya(I,I),'
'\n enddo\n ! Initialisation de Delta_Vmax\n DVamax=cmplx(-100000, -100000)\n ! Initialisation du vecteur tensions nodales\n do I=1,N\n V(I)=cmplx(1.,0.)\n enddo\n ! Ici commence la saisie des tableaux de planification\n ! Saisie numero n\u009cud balancier\n\n Read(InFile,*),S\n write(OutFile,*) '

Numero du noeud BILAN ',S,'


'\n Ntype(S)=0\n write(OutFile,*) '

TABLEAU DE PLANIFICATION


'\n write(OutFile,*) ' TYPE P Q/|V|'\n ! Saisie du vecteur type des n\u009cud\n do I = 1,N\n if (I/=S) then\n Read(InFile,*) Ntype(I)\n ! Si le n\u009cud est de type consommateur : 2 sinon Producteur : 1, 0 pour le noeud Bilan\n if (Ntype(I) <= 1) then\n Read(InFile,*) P(I),Q(I)\n write(OutFile,'(I4,2F12.6,A)') Ntype(I),P(I),Q(I),'
'\n endif\n if (Ntype(I) == 2) then\n Read(InFile,*) a,b,P(I)\n V(I)=cmplx(a,b)\n write(OutFile,'(I4,2F12.6,A)') Ntype(I),P(I),cabs(V(I)),'
'\n endif\n endif\n enddo\n ! Saisie de Epsilon,Kmax\n Read(InFile,*)a,b,Kmax\n eps=cmplx(a,b)\n write(OutFile,*) '

Epsillon Kmax


'\n write(OutFile,'(A,2F10.6,A,I10)') '(',eps,')', Kmax\n end subroutine SimulIANetRead\n\n\n ! Processus d'importation \u00e0 partir de fichier IEEE CDF\n subroutine CDFImport(f)\n implicit none\n integer,Intent(In):: f\n\n !FileImport=trim(f)\n !open(unit=10,file=FileImport,status='old',action='read')\n ! Lecture des informations de la premi\u00e8re section (Identification du r\u00e9seau)\n read(f,'(1X,A8,1X,A19,2X,F6.1,1X,I4,1X,A1,1X,A)') NetDataDate,NetOrigName,&\n &NetMVABase,NetYear, NetSeason, NetCaseId\n ! Lecture de la deuxi\u00e8me section (Pas importante) mention du nombre de neuds dans le r\u00e9seau.\n read(f, '(A16,1X,A)') FData, CharNbBus\n CharNbBus=trim(CharNbBus)\n ! Lecture de la troisi\u00e8me section, Donn\u00e9es des noeuds\n FMT1='(2X,A10,1X,I2,I3,1X,I2,1X,F6.4,F5.2,F8.2,F9.2,F7.2,F8.2,1X,&\n &F7.2,1X,F6.4,F7.2,F7.2,2F8.4,1X,I4,1X,I4)'\n i=0\n loop1: Do\n read(f, '(I4)'), w\n If (w/=-999) then\n i=i+1\n NbNode(i)=w\n read(f, FMT1) BusName(i),LFAreaN(i),LZoneN(i),Ntype(i),&\n &FV(i),FDelta(i),Pd(i),Qd(i),Pg(i),Qg(i),Vb(i),&\n &Vspec(i),Qmax(i),Qmin(i),Ybs(i),w\n else\n exit loop1\n endif\n enddo loop1\n ! Apr\u00e8s detection de la fin de la section 3, lecture de la section quatri\u00e8me : Donn\u00e9es es lignes\n read(f, '(A19,1X,A)') FData, CharNbBranch\n CharNbBranch=trim(CharNbBranch)\n FMT2='(1X,I2,I2,2X,I1,1X,F10.6,F11.6,F9.5,F6.0,1X,F6.0,1X,F6.0,&\n &1X,I4,1X,I1,2X,F6.4,1X,F7.2,F7.4,F6.4,1X,F6.5,1X,2F7.4,2X,I4)'\n i=0\n loop2: Do\n read(f, '(I4)'), w\n If (w/=-999) then\n i=i+1\n Ib(i)=w\n read(f, '(1X,I4)'),Jb(i)\n ii=Ib(i)\n jj=Jb(i)\n read(f, FMT2) LFAreaB(i),LZoneB(i),Circ(i),BType(i),Z(ii,jj),&\n &Ys(ii,jj),LineRate1(i),LineRate2(i),LineRate3(i),BCntl(i),&\n &BSide(i),TrRatio(i),TrPhase(i),Tapmin(i),Tapmax(i),SteSize(i),Vmin(i),Vmax(i)\n else\n exit loop2\n endif\n enddo loop2\n end subroutine CDFImport\n end program\n\n", "meta": {"hexsha": "52263b23d4506f41fc8c20c8de9838519ee58fa8", "size": 12194, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "gs.f95", "max_stars_repo_name": "mtamali/Load-Flow-Tools", "max_stars_repo_head_hexsha": "5d2db7ac44f529f2b17386d0c080226aea3bb0df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-04-01T20:21:47.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-01T20:21:47.000Z", "max_issues_repo_path": "gs.f95", "max_issues_repo_name": "mtamali/Load-Flow-Tools", "max_issues_repo_head_hexsha": "5d2db7ac44f529f2b17386d0c080226aea3bb0df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gs.f95", "max_forks_repo_name": "mtamali/Load-Flow-Tools", "max_forks_repo_head_hexsha": "5d2db7ac44f529f2b17386d0c080226aea3bb0df", "max_forks_repo_licenses": ["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.3355932203, "max_line_length": 116, "alphanum_fraction": 0.4937674266, "num_tokens": 3797, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178895092414, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6642529028224209}} {"text": "SUBROUTINE SSPGV_F95( A, B, W, ITYPE, UPLO, Z, INFO )\n!\n! -- LAPACK95 interface driver routine (version 3.0) --\n! UNI-C, Denmark; Univ. of Tennessee, USA; NAG Ltd., UK\n! September, 2000\n!\n! .. USE STATEMENTS ..\n USE LA_PRECISION, ONLY: WP => SP\n USE LA_AUXMOD, ONLY: ERINFO, LSAME\n USE F77_LAPACK, ONLY: SPGV_F77 => LA_SPGV\n! .. IMPLICIT STATEMENT ..\n IMPLICIT NONE\n! .. SCALAR ARGUMENTS ..\n CHARACTER(LEN=1), INTENT(IN), OPTIONAL :: UPLO\n INTEGER, INTENT(IN), OPTIONAL :: ITYPE\n INTEGER, INTENT(OUT), OPTIONAL :: INFO\n! .. ARRAY ARGUMENTS ..\n REAL(WP), INTENT(INOUT) :: A(:), B(:)\n REAL(WP), INTENT(OUT) :: W(:)\n REAL(WP), INTENT(OUT), OPTIONAL, TARGET :: Z(:,:)\n!----------------------------------------------------------------------\n! \n! Purpose\n! =======\n! \n! LA_SPGV, LA_SPGVD, LA_HPGV and LA_HPGVD compute all eigenvalues \n! and, optionally, all eigenvectors of generalized eigenvalue problems \n! of the form A*z = lambda*B*z, A*B*z = lambda*z; and B*A*z = lambda*z,\n! where A and B are real symmetric in the cases of LA_SPGV and LA_SPGVD\n! and complex Hermitian in the cases of LA_HPGV and LA_HPGVD. In all \n! four cases B is positive definite. Matrices A and B are stored in a \n! packed format.\n! LA_SPGVD and LA_HPGVD use a divide and conquer algorithm. If \n! eigenvectors are desired, they can be much faster than LA_SPGV and\n! LA_HPGV for large matrices but use more workspace.\n! \n! =========\n! \n! SUBROUTINE LA_SPGV / LA_SPGVD / LA_HPGV / LA_HPGVD( AP, BP, &\n! W, ITYPE=itype, UPLO=uplo, Z=z, INFO=info )\n! (), INTENT(INOUT) :: AP(:), BP(:)\n! REAL(), INTENT(OUT) :: W(:)\n! INTEGER, INTENT(IN), OPTIONAL :: ITYPE\n! CHARACTER(LEN=1), INTENT(IN), OPTIONAL :: UPLO\n! (), INTENT(OUT), OPTIONAL :: Z(:,:)\n! INTEGER, INTENT(OUT), OPTIONAL :: INFO\n! where\n! ::= REAL | COMPLEX\n! ::= KIND(1.0) | KIND(1.0D0)\n! \n! Arguments\n! =========\n! \n! AP (input/output) REAL or COMPLEX array, shape (:) with\n! size(AP) = n*(n + 1)/2, where n is the order of A and B.\n! On entry, the upper or lower triangle of matrix A in packed \n! \t storage. The elements are stored columnwise as follows:\n! \t if UPLO = 'U', AP(i +(j-1)*j/2) = A(i,j) for 1<=i<=j<=n;\n! \t if UPLO = 'L', AP(i +(j-1)*(2*n-j)/2) = A(i,j) for 1<=j<=i<=n.\n! On exit, the contents of AP are destroyed.\n! BP (input/output) REAL or COMPLEX array, shape (:) and \n! size(BP) = size(AP).\n! On entry, the upper or lower triangle of matrix B in packed \n! \t storage. The elements are stored columnwise as follows:\n! \t if UPLO = 'U', BP(i +(j-1)*j/2) = B(i,j) for 1<=i<=j<=n;\n! \t if UPLO = 'L', BP(i +(j-1)*(2*n-j)/2) = B(i,j) for 1<=j<=i<=n.\n! On exit, the triangular factor U or L of the Cholesky \n! \t factorization B = U^H*U or B = L*L^H, in the same storage\n! \t format as B.\n! W (output) REAL array, shape (:) with size(W) = n.\n! The eigenvalues in ascending order.\n! ITYPE Optional (input) INTEGER.\n! Specifies the problem type to be solved:\n! = 1: A*z = lambda*B*z\n! = 2: A*B*z = lambda*z\n! = 3: B*A*z = lambda*z\n! Default value: 1.\n! UPLO Optional (input) CHARACTER(LEN=1).\n! = 'U': Upper triangles of A and B are stored;\n! = 'L': Lower triangles of A and B are stored.\n! Default value: 'U'.\n! Z Optional (output) REAL or COMPLEX square array, shape (:,:)\n! with size(Z,1) = n.\n! The matrix Z of eigenvectors, normalized as follows:\n! if ITYPE = 1 or 2: Z^H * B * Z = I ,\n! if ITYPE = 3: Z^H * B^-1 * Z = I .\n! INFO Optional (output) INTEGER.\n! = 0: successful exit.\n! < 0: if INFO = -i, the i-th argument had an illegal value.\n! > 0: the algorithm failed to converge or matrix B is not \n! \t positive definite:\n! <= n: if INFO = i, i off-diagonal elements of an \n! \t intermediate tridiagonal form did not converge to \n! \t\t zero.\n! > n: if INFO = n+i, for 1<=i<=n, then the leading minor \n! \t of order i of B is not positive definite. The \n! \t\t factorization of B could not be completed and no\n! eigenvalues or eigenvectors were computed.\n! If INFO is not present and an error occurs, then the program\n! \t is terminated with an error message.\n!----------------------------------------------------------------------\n! .. LOCAL PARAMETERS ..\n CHARACTER(LEN=7), PARAMETER :: SRNAME = 'LA_SPGV'\n! .. LOCAL SCALARS ..\n CHARACTER(LEN=1) :: LJOBZ, LUPLO\n INTEGER :: LINFO, N, NN, LD, LITYPE, ISTAT, ISTAT1, S1Z, S2Z\n! .. LOCAL ARRAYS ..\n REAL(WP), TARGET :: LLZ(1,1)\n REAL(WP), POINTER :: WORK(:)\n COMPLEX(WP) :: WW\n! .. INTRINSIC FUNCTIONS ..\n INTRINSIC SIZE, MAX, PRESENT\n! .. EXECUTABLE STATEMENTS ..\n LINFO = 0; ISTAT = 0; NN = SIZE(A)\n WW = (-1+SQRT(1+8*REAL(NN,WP)))*0.5; N = INT(WW); LD = MAX(1,N)\n IF( PRESENT(ITYPE) )THEN; LITYPE = ITYPE; ELSE; LITYPE = 1; END IF\n IF( PRESENT(Z) )THEN; S1Z = SIZE(Z,1); S2Z = SIZE(Z,2); LJOBZ = 'V'\n ELSE; S1Z = 1; S2Z = 1; LJOBZ = 'N'; END IF\n IF( PRESENT(UPLO) ) THEN; LUPLO = UPLO; ELSE; LUPLO = 'U'; END IF\n! .. TEST THE ARGUMENTS\n IF( NN < 0 .OR. AIMAG(WW) /= 0 .OR. REAL(N,WP) /= REAL(WW) ) THEN; LINFO = -1\n ELSE IF( SIZE(B) /= SIZE(A) )THEN; LINFO = -2\n ELSE IF( SIZE(W) /= N )THEN; LINFO = -3\n ELSE IF( LITYPE < 1 .OR. LITYPE > 3 )THEN; LINFO = -4\n ELSE IF( .NOT.LSAME(LUPLO,'U') .AND. .NOT.LSAME(LUPLO,'L') )THEN; LINFO = -5\n ELSE IF( PRESENT(Z) .AND. ( S1Z /= LD .OR. S2Z /= N ) )THEN; LINFO = -6\n ELSE IF( N > 0 )THEN\n ALLOCATE(WORK(MAX(1,3*N)), STAT=ISTAT)\n IF( ISTAT == 0 )THEN\n IF( PRESENT(Z) )THEN\n CALL SPGV_F77( LITYPE, LJOBZ, LUPLO, N, A, B, W, Z, S1Z, &\n WORK, LINFO )\n\t ELSE\n\t CALL SPGV_F77( LITYPE, LJOBZ, LUPLO, N, A, B, W, LLZ, S1Z, &\n WORK, LINFO )\n\tENDIF\t\t\n ELSE; LINFO = -100; ENDIF\n DEALLOCATE(WORK, STAT=ISTAT1)\n ENDIF\n CALL ERINFO(LINFO,SRNAME,INFO,ISTAT)\nEND SUBROUTINE SSPGV_F95\n", "meta": {"hexsha": "eba89fabe61757cd89179a35b794eaea04c57376", "size": 6289, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "code_1D/couplage_1D/fortran90_source/liblapack95/SRC/la_sspgv.f90", "max_stars_repo_name": "IRFM/ALOHA", "max_stars_repo_head_hexsha": "e8e7a47a70c7095b339b3dea25dcd4b95f382959", "max_stars_repo_licenses": ["CECILL-B"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-12-29T15:07:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T10:09:22.000Z", "max_issues_repo_path": "code_1D/couplage_1D/fortran90_source/liblapack95/SRC/la_sspgv.f90", "max_issues_repo_name": "IRFM/ALOHA", "max_issues_repo_head_hexsha": "e8e7a47a70c7095b339b3dea25dcd4b95f382959", "max_issues_repo_licenses": ["CECILL-B"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-02-21T10:46:38.000Z", "max_issues_repo_issues_event_max_datetime": "2017-10-20T17:03:14.000Z", "max_forks_repo_path": "code_1D/couplage_1D/fortran90_source/liblapack95/SRC/la_sspgv.f90", "max_forks_repo_name": "IRFM/ALOHA", "max_forks_repo_head_hexsha": "e8e7a47a70c7095b339b3dea25dcd4b95f382959", "max_forks_repo_licenses": ["CECILL-B"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-12-29T15:34:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-15T07:12:40.000Z", "avg_line_length": 44.2887323944, "max_line_length": 80, "alphanum_fraction": 0.5535061218, "num_tokens": 2118, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361604769413, "lm_q2_score": 0.7279754489059774, "lm_q1q2_score": 0.6642311235212478}} {"text": "* SUBROUTINE 'DGPFA'\r\n* SELF-SORTING IN-PLACE GENERALIZED PRIME FACTOR (COMPLEX) FFT\r\n*\r\n* *** THIS IS THE ALL-FORTRAN VERSION ***\r\n* -------------------------------\r\n*\r\n* CALL DGPFA(A,B,TRIGS,INC,JUMP,N,LOT,ISIGN,NPQR)\r\n*\r\n* A IS FIRST REAL INPUT/OUTPUT VECTOR\r\n* B IS FIRST IMAGINARY INPUT/OUTPUT VECTOR\r\n* TRIGS IS A TABLE OF TWIDDLE FACTORS, PRECALCULATED\r\n* BY CALLING SUBROUTINE 'SETDGPFA'\r\n* INC IS THE INCREMENT WITHIN EACH DATA VECTOR\r\n* JUMP IS THE INCREMENT BETWEEN DATA VECTORS\r\n* N IS THE LENGTH OF THE TRANSFORMS:\r\n* -----------------------------------\r\n* N = (2**IP) * (3**IQ) * (5**IR)\r\n* -----------------------------------\r\n* LOT IS THE NUMBER OF TRANSFORMS\r\n* ISIGN = +1 FOR FORWARD TRANSFORM\r\n* = -1 FOR INVERSE TRANSFORM\r\n* NPQR = NPQR OBTAINED FROM SETDGPFA\r\n*\r\n* WRITTEN BY CLIVE TEMPERTON\r\n* RECHERCHE EN PREVISION NUMERIQUE\r\n* ATMOSPHERIC ENVIRONMENT SERVICE, CANADA\r\n*\r\n* MODIFIED FOR VXL PROJECT TO ADD NPQR ARGUMENT\r\n*\r\n*----------------------------------------------------------------------\r\n*\r\n* DEFINITION OF TRANSFORM\r\n* -----------------------\r\n*\r\n* X(J) = SUM(K=0,...,N-1)(C(K)*EXP(ISIGN*2*I*J*K*PI/N))\r\n*\r\n*---------------------------------------------------------------------\r\n*\r\n* FOR A MATHEMATICAL DEVELOPMENT OF THE ALGORITHM USED,\r\n* SEE:\r\n*\r\n* C TEMPERTON : \"A GENERALIZED PRIME FACTOR FFT ALGORITHM\r\n* FOR ANY N = (2**P)(3**Q)(5**R)\",\r\n* SIAM J. SCI. STAT. COMP., MAY 1992.\r\n*\r\n*----------------------------------------------------------------------\r\n*\r\n SUBROUTINE DGPFA(A,B,TRIGS,INC,JUMP,N,LOT,ISIGN,NPQR)\r\n*\r\n DOUBLE PRECISION A(*), B(*), TRIGS(*)\r\n INTEGER INC, JUMP, N, LOT, ISIGN, NPQR(3)\r\n*\r\n IP = NPQR(1)\r\n IQ = NPQR(2)\r\n IR = NPQR(3)\r\n*\r\n* COMPUTE THE TRANSFORM\r\n* ---------------------\r\n I = 1\r\n IF (IP.GT.0) THEN\r\n CALL DGPFA2F(A,B,TRIGS,INC,JUMP,N,IP,LOT,ISIGN)\r\n I = I + 2 * ( 2**IP)\r\n ENDIF\r\n IF (IQ.GT.0) THEN\r\n CALL DGPFA3F(A,B,TRIGS(I),INC,JUMP,N,IQ,LOT,ISIGN)\r\n I = I + 2 * (3**IQ)\r\n ENDIF\r\n IF (IR.GT.0) THEN\r\n CALL DGPFA5F(A,B,TRIGS(I),INC,JUMP,N,IR,LOT,ISIGN)\r\n ENDIF\r\n*\r\n RETURN\r\n END\r\n", "meta": {"hexsha": "1c6ef30a3e760e3ba0fc4c53b2a4ae557cec243a", "size": 2420, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Modules/ThirdParty/VNL/src/vxl/v3p/netlib/temperton/dgpfa.f", "max_stars_repo_name": "nalinimsingh/ITK_4D", "max_stars_repo_head_hexsha": "95a2eacaeaffe572889832ef0894239f89e3f303", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-10-01T20:46:17.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-17T19:39:50.000Z", "max_issues_repo_path": "Modules/ThirdParty/VNL/src/vxl/v3p/netlib/temperton/dgpfa.f", "max_issues_repo_name": "nalinimsingh/ITK_4D", "max_issues_repo_head_hexsha": "95a2eacaeaffe572889832ef0894239f89e3f303", "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/temperton/dgpfa.f", "max_forks_repo_name": "nalinimsingh/ITK_4D", "max_forks_repo_head_hexsha": "95a2eacaeaffe572889832ef0894239f89e3f303", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-05-17T16:34:54.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-24T02:12:40.000Z", "avg_line_length": 32.7027027027, "max_line_length": 72, "alphanum_fraction": 0.447107438, "num_tokens": 713, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.912436153333645, "lm_q2_score": 0.7279754430043072, "lm_q1q2_score": 0.6642311129362062}} {"text": "program expr_02\nimplicit none\ninteger :: x\nx = (2+3)*5\nif (x /= 25) error stop\n\nx = (2+3)*4\nif (x /= 20) error stop\n\nx = (2+3)*(2+3)\nif (x /= 25) error stop\n\nx = (2+3)*(2+3)*4*2*(1+2)\nif (x /= 600) error stop\n\nx = x / 60\nif (x /= 10) error stop\n\nx = x + 1\nif (x /= 11) error stop\n\nx = x - 1\nif (x /= 10) error stop\nend program\n", "meta": {"hexsha": "f514628c3780c95e3ff998a628caca29e401490a", "size": 327, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "integration_tests/expr_02.f90", "max_stars_repo_name": "Thirumalai-Shaktivel/lfortran", "max_stars_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 316, "max_stars_repo_stars_event_min_datetime": "2019-03-24T16:23:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:28:33.000Z", "max_issues_repo_path": "integration_tests/expr_02.f90", "max_issues_repo_name": "Thirumalai-Shaktivel/lfortran", "max_issues_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-07-29T04:58:03.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-04T16:40:06.000Z", "max_forks_repo_path": "integration_tests/expr_02.f90", "max_forks_repo_name": "Thirumalai-Shaktivel/lfortran", "max_forks_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2019-03-28T19:40:07.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T07:28:55.000Z", "avg_line_length": 13.08, "max_line_length": 25, "alphanum_fraction": 0.5351681957, "num_tokens": 154, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619350028204, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.6642130734280436}} {"text": "! solve the 2d linear advection equation, in conservative form:\n!\n! a_t + [f(a)]_x + [g(a)]_y=0 \n! f(a) = u*a\n! g(a) = v*a \n! a=a(x,y,t) (user defined) \n! u=constant (user defined)\n! v=constant (user defined)\n!\n! using either\n! - dimensionally split 2nd order finite volume predictor-corrector \n! - unsplit with \"Corner Transport Upwind\" (CTU) method (coming soon)\n! with a choice of gradient limiters\n!\n! https://github.com/JOThurgood/SimpleCFD/wiki/advect_2d.f90\n!\n\nmodule shared_data\n\n implicit none\n\n integer, parameter :: num=selected_real_kind(p=15)\n integer :: nx, ny !number of cells\n integer :: ix,iy\n integer(num) :: step, nsteps\n real(num) :: u, v\n real(num) :: time=0.0_num, t_end, dt\n real(num) :: x_min, x_max \n real(num) :: y_min, y_max \n real(num) :: dx, dy\n real(num), dimension(:), allocatable :: xb, xc\n real(num), dimension(:), allocatable :: yb, yc\n real(num), dimension(:,:), allocatable :: a,a1x,a1y, a1Lx, a1Rx, a1Ly,a1Ry\n !solution and states at half time step indicated by 1\n real(num) :: CFL !cfl modifier\n\n !keyword codes\n integer :: limiter\n integer, parameter :: lim_unlimited = 1, lim_minmod = 2\n integer :: method\n integer, parameter :: method_split = 1, method_unsplit = 2\n\n contains\n\nend module shared_data\n\nmodule setup\n\n use shared_data\n\n implicit none\n\n contains\n\n subroutine initial_setup\n call control\n call setup_2dfvgrid\n call initial_conditions\n end subroutine initial_setup\n\n subroutine control\n !user control variables\n u = 1.0_num\n v = 1.0_num\n nx = 64 \n ny = 64 \n x_min = 0.0_num\n x_max = 1.0_num\n y_min = x_min\n y_max = x_max\n t_end = 1.0_num\n CFL = 0.7_num !cfl multiplier <= 1\n nsteps = -1 !set to -1 to run till t_end\n limiter = lim_minmod\n! limiter = lim_unlimited\n method = method_split \n end subroutine control\n\n subroutine initial_conditions\n !user set initial profile on a\n a = 0.0_num\n! call x_top_hat\n! call y_top_hat\n call square \n! call gaussian\n end subroutine initial_conditions\n\n subroutine x_top_hat\n a = 0.0_num\n do ix = 0,nx+1\n if ((xc(ix) .ge. 1.0_num/3.0_num) .and. (xc(ix) .le. 2.0_num/3.0_num)) &\n & a(ix,:) = 1.0_num\n enddo\n end subroutine x_top_hat\n\n subroutine square \n real(num) :: lo,hi\n lo = 1.0_num/3.0_num\n hi = 2.0_num*lo\n a = 0.0_num\n do iy = 0,ny+1\n do ix = 0,nx+1\n if ((xc(ix) .ge. lo) & \n & .and. (xc(ix) .le. hi) &\n & .and. (yc(iy) .ge. lo) &\n & .and. (yc(iy) .le. hi) ) a(ix,iy) = 1.0_num\n enddo\n enddo\n end subroutine square\n\n subroutine y_top_hat\n a = 0.0_num\n do iy = 0,ny+1\n if ((yc(iy) .ge. 1.0_num/3.0_num) .and. (yc(iy) .le. 2.0_num/3.0_num)) &\n & a(:,iy) = 1.0_num\n enddo\n end subroutine y_top_hat\n\n subroutine gaussian\n print *, 'gaussian currently a stub'\n end subroutine gaussian\n\n subroutine setup_2dfvgrid !setup the grid and allocate other arrays \n\n allocate(xc(-1:nx+2)) !cell center (cc) - counts from 1 to nx\n allocate(xb(-2:nx+2)) !cell boundary (cb) - counts from 0 to nx\n allocate(yc(-1:ny+2)) !cell center (cc) - counts from 1 to ny\n allocate(yb(-2:ny+2)) !cell boundary (cb) - counts from 0 to ny\n !all above have two guards either side\n\n allocate(a(-1:nx+2,-1:ny+2)) !cc + 2 guards\n allocate(a1x(0:nx,1:ny)) !cb,cc - no guards needed \n allocate(a1Lx(0:nx,1:ny)) !cb,cc \n allocate(a1Rx(0:nx,1:ny)) !cb,cc\n allocate(a1y(1:nx,0:ny)) !cc,cb - no guards needed \n allocate(a1Ly(1:nx,0:ny)) !cc,cb \n allocate(a1Ry(1:nx,0:ny)) !cc,cb\n\n dx = (x_max - x_min) / REAL(nx,num)\n do ix = -2, nx+2\n xb(ix) = x_min + REAL(ix,num) * dx \n if (ix /= -2) xc(ix) = xb(ix) - dx/2.0_num\n enddo\n\n dy = (y_max - y_min) / REAL(ny,num)\n do iy = -2, ny+2\n yb(iy) = y_min + REAL(iy,num) * dy \n if (iy /= -2) yc(iy) = yb(iy) - dy/2.0_num\n enddo\n\n end subroutine setup_2dfvgrid \n\nend module setup\n\nmodule split_solver \n\n use shared_data\n\n implicit none\n\n private\n\n public :: solve_split\n\n contains \n\n subroutine solve_split\n\n call set_dt \n\n if (MOD(step,2) == 1) then !strang splitting \n call x_bcs\n call x_interface_state\n call x_reimann\n call x_update\n call y_bcs\n call y_interface_state\n call y_reimann\n call y_update\n else\n call y_bcs\n call y_interface_state\n call y_reimann\n call y_update\n call x_bcs\n call x_interface_state\n call x_reimann\n call x_update\n endif\n\n time = time + dt\n\n !if plotting ghost cells may want to call bcs before plot\n !to update (order here will have them one time before?)\n !no effect on sln / correct for what you intend\n end subroutine solve_split\n\n subroutine set_dt\n real(num) ::dtx,dty\n dtx = CFL * dx / abs(u)\n dty = CFL * dy / abs(v)\n dt = MIN(dtx,dty)\n if ((step==1) .and. (abs(u-v) .gt. 1e-2_num)) then\n print *,'u not ~= v detected ; even if CFL=1 perfect translation not poss' \n print *,'effective CFL in x drn',dt/dtx * CFL\n print *,'effective CFL in y drn',dt/dty * CFL\n endif\n! if (step==1) print *,'effective CFL in x drn',dt/dtx\n! if (step==1) print *,'effective CFL in y drn',dt/dty\n end subroutine set_dt\n\n subroutine x_bcs !periodic\n a(-1,:) = a(nx-1,:)\n a(0,:) = a(nx,:)\n a(nx+1,:) = a(1,:)\n a(nx+2,:) = a(2,:)\n end subroutine x_bcs\n\n subroutine y_bcs !periodic\n a(:,-1) = a(:,ny-1)\n a(:,0) = a(:,ny)\n a(:,ny+1) = a(:,1)\n a(:,ny+2) = a(:,2)\n end subroutine y_bcs\n\n subroutine x_interface_state\n !be careful with cc vs cb here\n real(num) dadx\n do iy = 1, ny !inefficient, refactor to vector operation\n do ix = 0, nx \n !left state\n if (limiter == lim_minmod) then\n dadx = minmod( ( a(ix,iy)-a(ix-1,iy) ) / dx, ( a(ix+1,iy)-a(ix,iy) ) / dx )\n else \n dadx = ( a(ix+1,iy) - a(ix-1,iy) ) / 2.0_num / dx\n endif\n a1Lx(ix,iy) = a(ix,iy) + 0.5_num * dx * (1.0_num - dt * u / dx) * dadx\n !right state\n if (limiter == lim_minmod) then\n dadx = minmod( ( a(ix+1,iy)-a(ix,iy) )/dx , ( a(ix+2,iy)-a(ix+1,iy) ) / dx )\n else\n dadx = ( a(ix+2,iy) - a(ix,iy) ) / 2.0_num / dx\n endif\n\n a1Rx(ix,iy) = a(ix+1,iy) - 0.5_num * dx * (1.0_num + dt * u / dx) * dadx\n enddo\n enddo\n end subroutine x_interface_state\n\n subroutine x_reimann\n !worlds simplest reimann problem\n if (u < 0.0_num) then\n a1x = a1Rx\n else if (u > 0.0_num) then\n a1x = a1Lx\n endif\n end subroutine x_reimann\n\n\n subroutine x_update\n do ix = 1,nx\n a(ix,1:ny) = a(ix,1:ny) - dt / dx * (u*a1x(ix,1:ny)-u*a1x(ix-1,1:ny))\n enddo\n endsubroutine x_update\n\n subroutine y_interface_state\n !consider a1L as \"bottom\" and a1R as \"top\" conceptually\n ! (or most negative -> most positive y)\n !be careful with cc vs cb here\n real(num) dady\n do ix = 1, nx !refactor to vector operation\n do iy = 0, ny \n !left state\n if (limiter == lim_minmod) then\n dady = minmod( ( a(ix,iy)-a(ix,iy-1) ) / dy, ( a(ix,iy+1)-a(ix,iy) ) / dy )\n else \n dady = ( a(ix,iy+1) - a(ix,iy-1) ) / 2.0_num / dy\n endif\n a1Ly(ix,iy) = a(ix,iy) + 0.5_num * dy * (1.0_num - dt * v / dy) * dady\n !right state\n if (limiter == lim_minmod) then\n dady = minmod( ( a(ix,iy+1)-a(ix,iy) )/dy , ( a(ix,iy+2)-a(ix,iy+1) ) / dy )\n else\n dady = ( a(ix,iy+2) - a(ix,iy) ) / 2.0_num / dy\n endif\n a1Ry(ix,iy) = a(ix,iy+1) - 0.5_num * dy * (1.0_num + dt * v / dy) * dady\n enddo\n enddo\n end subroutine y_interface_state\n\n subroutine y_reimann\n if (v < 0.0_num) then\n a1y = a1Ry\n else if (v > 0.0_num) then\n a1y = a1Ly\n endif\n end subroutine y_reimann\n\n subroutine y_update\n do iy = 1,ny\n a(1:nx,iy) = a(1:nx,iy) - dt / dy * (v*a1y(1:nx,iy)-v*a1y(1:nx,iy-1))\n enddo\n endsubroutine y_update\n\n real(num) function minmod(a,b) ! refactor - \"a\" is an unfortunate choice\n real(num), intent(in) :: a, b \n if ( (abs(a) < abs(b)) .and. (a*b > 0) ) then\n minmod = a\n else if ( (abs(a) > abs(b)) .and. (a*b > 0) ) then\n minmod = b\n else \n minmod = 0.0_num\n endif \n end function minmod\n\nend module split_solver\n\nmodule diagnostics\n\n use shared_data\n\n implicit none \n\n contains\n\n subroutine do_io\n\n integer :: out_unit =10\n\n call execute_command_line(\"rm -rf xc.dat yc.dat a.dat\") \n !dont want to stream to existing files\n\n open(out_unit, file=\"xc.dat\", access=\"stream\")\n write(out_unit) xc\n close(out_unit)\n\n open(out_unit, file=\"yc.dat\", access=\"stream\")\n write(out_unit) yc\n close(out_unit)\n\n open(out_unit, file=\"a.dat\", access=\"stream\")\n write(out_unit) a\n close(out_unit)\n \n call execute_command_line(\"python plot_advect_2d.py\")\n\n\n end subroutine do_io\n\nend module diagnostics\n\nprogram advection2d !main driver\n\n use shared_data\n use setup\n use split_solver\n use diagnostics\n\n implicit none\n\n call initial_setup\n\n do \n if ((step >= nsteps .and. nsteps >= 0) .or. (time >= t_end)) exit\n step = step + 1\n if (method == method_split) call solve_split\n enddo\n\n call do_io\n\n print *, 'Done in',step,'steps', 'with CFL',CFL\n\nend program advection2d\n", "meta": {"hexsha": "0a1c41f4705afb58130385cd600ff2be3cb4e3ca", "size": 9332, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "linear_advection/2D/advect_2d.f90", "max_stars_repo_name": "JOThurgood/SimpleCFD", "max_stars_repo_head_hexsha": "d0dc2fae9dab21c33d50b443caa727fa763c95d9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-04-23T05:31:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-04T23:21:11.000Z", "max_issues_repo_path": "linear_advection/2D/advect_2d.f90", "max_issues_repo_name": "JOThurgood/SimpleCFD", "max_issues_repo_head_hexsha": "d0dc2fae9dab21c33d50b443caa727fa763c95d9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 39, "max_issues_repo_issues_event_min_datetime": "2018-08-31T23:48:02.000Z", "max_issues_repo_issues_event_max_datetime": "2019-08-07T10:03:11.000Z", "max_forks_repo_path": "linear_advection/2D/advect_2d.f90", "max_forks_repo_name": "JOThurgood/SimpleCFD", "max_forks_repo_head_hexsha": "d0dc2fae9dab21c33d50b443caa727fa763c95d9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-11-14T20:42:54.000Z", "max_forks_repo_forks_event_max_datetime": "2019-05-18T09:16:27.000Z", "avg_line_length": 24.9518716578, "max_line_length": 84, "alphanum_fraction": 0.5956922417, "num_tokens": 3364, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619263765707, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.6642130607071661}} {"text": " SUBROUTINE CONTINUTYn(X, Y, Z, W, C, M, NTS, CTS)\n USE global\n IMPLICIT NONE\n REAL*8 :: X(2,NXP4), Y(2,NXP4), Z(2,NXP4), W(2,NXP4)\n INTEGER :: IC, NTS, CTS\n REAL*8 :: C, M\n!----------------------------------------------------------------------\n! X = Density of fluid\n! Y = Velocity of fluid\n! Z = Pressure of fluid\n! W = Electric field in system\n! C = Charge \n! M = Mass (mu)\n! NTS = (N)ext (T)ime (S)tep \n! CTS = (C)urrent (T)ime (S)tep\n! FD0 = Density derivative (dN/dx)\n! FD1 = Velocity derivative (dV/dx)\n! FD2 = Pressure derivative (dP/dx)\n!----------------------------------------------------------------------\n!\n CALL FD4n(X(CTS,:), FD0(1,:)) ! density\n CALL FD4n(Y(CTS,:), FD1(1,:)) ! velocity \n CALL FD4n(Z(CTS,:), FD2(1,:)) ! presure\n! \n DO 1 IC=3, NXP2\n X(NTS,IC) = X(NTS,IC) - DT*(X(CTS,IC)*FD1(1,IC) &\n & + Y(CTS,IC)*FD0(1,IC))\n Y(NTS,IC) = Y(NTS,IC) - DT*(Y(CTS,IC)*FD1(1,IC) &\n & + FD2(1,IC)/(X(CTS,IC)*M) - W(CTS,IC)*(C/M))\n Z(NTS,IC) = Z(NTS,IC) - DT*(Y(CTS,IC)*FD2(1,IC) &\n & + GYM*Z(CTS,IC)*FD1(1,IC) )\n 1 CONTINUE \n!\n CALL boundary_condition(X(NTS,:)) \n CALL boundary_condition(Y(NTS,:)) \n CALL boundary_condition(Z(NTS,:)) \n!\n CALL FILTERn(X(NTS,:))\n CALL FILTERn(Y(NTS,:))\n CALL FILTERn(Z(NTS,:))\n!\n RETURN \n END", "meta": {"hexsha": "6f8dadd39247d0fd4f0649f928c1c2ff6aa1a555", "size": 1450, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "electron_acoustic_double_layer/src/CONTINUTYn.f90", "max_stars_repo_name": "ablotekar/oneD-fluid-simulation-code-fortran", "max_stars_repo_head_hexsha": "a9bbd96b2e540906b0630284607ac73742d971d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-07-19T15:02:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-19T15:02:18.000Z", "max_issues_repo_path": "two_component_full_fluid/src/CONTINUTYn.f90", "max_issues_repo_name": "ablotekar/oneD-fluid-simulation-code-fortran", "max_issues_repo_head_hexsha": "a9bbd96b2e540906b0630284607ac73742d971d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "two_component_full_fluid/src/CONTINUTYn.f90", "max_forks_repo_name": "ablotekar/oneD-fluid-simulation-code-fortran", "max_forks_repo_head_hexsha": "a9bbd96b2e540906b0630284607ac73742d971d4", "max_forks_repo_licenses": ["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.7209302326, "max_line_length": 71, "alphanum_fraction": 0.4420689655, "num_tokens": 541, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088084787998, "lm_q2_score": 0.7154240018510026, "lm_q1q2_score": 0.664205945115624}} {"text": "! *********************************************************************\r\n! * *\r\n! * subroutine dcvit2 *\r\n! * *\r\n! *********************************************************************\r\n! Double Precision Version 2.11\r\n! Written by Gordon A. Fenton, TUNS, July 18, 1992\r\n! Latest Update: Jun 9, 1999\r\n!\r\n! PURPOSE computes the initial k1*k2 x k1*k2 covariance matrix (and a 9x9\r\n! submatrix) between local averages. Used by LAS2G.\r\n! \r\n!\r\n! This routine forms the covariance matrix Q between local averages arranged\r\n! on a k1 x k2 grid using a user provided variance function \"dvarfn\" that\r\n! returns the variance of a local average (note that this is the point\r\n! variance sigma^2 times the traditionally \"variance\" function, as defined\r\n! by Vanmarcke in \"Random Fields\", MIT Press, 1984). The grid and element\r\n! numbering schemes appear as follows (for k1 = k2 = 5)\r\n!\r\n! | Dx |\r\n! --- --------------------------\r\n! Dy | 21 | 22 | 23 | 24 | 25 |\r\n! --- --------------------------\r\n! | 16 | 17 | 18 | 19 | 20 |\r\n! -------------------------- ----------------\r\n! | 11 | 12 | 13 | 14 | 15 | | 7 | 8 | 9 |\r\n! -------------------------- ----------------\r\n! | 6 | 7 | 8 | 9 | 10 | | 4 | 5 | 6 |\r\n! -------------------------- ----------------\r\n! | 1 | 2 | 3 | 4 | 5 | | 1 | 2 | 3 |\r\n! -------------------------- ----------------\r\n!\r\n! Q Array R Array\r\n!\r\n! with the k1 x k2 array numbering on the left and a basic 3 x 3 subarray\r\n! shown on the right. If we call Z_i the local average of a random process\r\n! over the i'th cell, then for E[Z] = 0, the elements of Q are defined by\r\n!\r\n! Q(i,j) = E[Z_i*Z_j]\r\n!\r\n! Note that the elements of R are simply extracted directly from the\r\n! appropriate elements of Q (for example, R(1,5) = Q(1,7)) if k1 and k2 are\r\n! greater than 2. Note also that since both Q and R are symmetric, ONLY THE\r\n! UPPER TRIANGULAR VALUES are stored herein. Finally note that the random\r\n! process is assumed to be quadrant symmetric (that is the covariance\r\n! function is even in each individual lag component) to reduce the total\r\n! number of covariance calculations.\r\n!\r\n! Arguments to this routine are as follows;\r\n!\r\n! dvarfn external double precision function which returns the\r\n! variance of a local average of size X x Y. This function\r\n! is referenced using the call \"V = dvarfn(X,Y)\" (other\r\n! parameters to the function must be passed via common blocks).\r\n! On each invocation, this routine calls DVARFN approximately\r\n! 225 times (via DCVAA2).\r\n!\r\n! Q double precision array of size at least k1*k2 x k1*k2 which\r\n! on output will contain the covariance matrix between the local\r\n! average elements shown above on the left. Note that since Q is\r\n! symmetric, only the upper triangular values are actually\r\n! stored (compatible with DCHOL2). (output)\r\n!\r\n! iq leading dimension of the array Q as specified in the calling\r\n! routine. (input)\r\n!\r\n! R double precision array of size at least 9 x 9 which on output\r\n! will contain the covariance matrix between the local average\r\n! elements shown above on the right. Note that since R is\r\n! symmetric, only the upper triangular values are actually\r\n! stored (compatible with DSIFA). (output)\r\n!\r\n! ir leading dimension of the array R as specified in the calling\r\n! routine. (input)\r\n!\r\n! k1 number of local average cells in the x direction\r\n! (horizontally). (input)\r\n!\r\n! k2 number of local average cells in the y direction\r\n! (vertically). (input)\r\n!\r\n! Dx x-dimension of the local average cells. (input)\r\n!\r\n! Dy y-dimension of the local average cells. (input)\r\n!\r\n! Required:\r\n! 1) from libGAFsim: DCVAA2\r\n!\r\n! REVISION HISTORY:\r\n! 2.1\teliminated unused local variables (Dec 5/96)\r\n! 2.11\treplaced dummy dimensions with a (*) for GNU's compiler (Jun 9/99)\r\n!----------------------------------------------------------------------------\r\n subroutine dcvit2( dvarfn, Q, iq, R, ir, k1, k2, Dx, Dy )\r\n implicit real*8 (a-h,o-z)\r\n dimension Q(iq,*), R(ir,*)\r\n integer kx(9), ky(9)\r\n external dvarfn\r\n data kx/0,1,2,0,1,2,0,1,2/, ky/0,0,0,1,1,1,2,2,2/\r\n\r\n!\t\t\t\t\tfirst form the essential elements of Q\r\n ii = 0\r\n do 20 j = 1, k2\r\n ty = dble(j-1)\r\n do 10 i = 1, k1\r\n ii = ii + 1\r\n tx = dble(i-1)\r\n Q(1,ii) = dcvaa2( dvarfn, Dx, Dy, tx, ty )\r\n 10 continue\r\n 20 continue\r\n!\t\t\t\t\tnow distribute into the upper triangle\r\n kk = k1*k2\r\n do 40 j = 2, kk\r\n mxj = mod(j-1,k1)\r\n myj = (j-1)/k1\r\n do 30 i = 2, j\r\n mxi = mod(i-1,k1)\r\n myi = (i-1)/k1\r\n m = 1 + iabs(mxj - mxi) + k1*iabs(myj - myi)\r\n Q(i,j) = Q(1,m)\r\n 30 continue\r\n 40 continue\r\n!\t\t\t\t\tform R (9 x 9)\r\n if( k1 .lt. 3 .or. k2 .lt. 3 ) then\r\n!\t\t\t\t\t\tfind essential elements of R\r\n ii = 0\r\n do 60 j = 1, 3\r\n ty = dble(j-1)\r\n do 50 i = 1, 3\r\n ii = ii + 1\r\n tx = dble(i-1)\r\n R(1,ii) = dcvaa2( dvarfn, Dx, Dy, tx, ty )\r\n 50 continue\r\n 60 continue\r\n!\t\t\t\t\t\tand distribute into upper tri.\r\n do 70 j = 2, 9\r\n do 70 i = 2, j\r\n m = 1 + iabs(kx(j)-kx(i)) + 3*iabs(ky(j)-ky(i))\r\n R(i,j) = R(1,m)\r\n 70 continue\r\n else\r\n!\t\t\t\t\t\tor extract elements of R from Q\r\n do 80 j = 1, 9\r\n do 80 i = 1, j\r\n m = 1 + iabs(kx(j)-kx(i)) + k1*iabs(ky(j)-ky(i))\r\n R(i,j) = Q(1,m)\r\n 80 continue\r\n endif\r\n\r\n return\r\n end\r\n", "meta": {"hexsha": "9bbd865d74c2453dd50dc4eb4c1a5b56d174fdeb", "size": 6306, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/libs/gaf95/dcvit2.f95", "max_stars_repo_name": "leemargetts/PoreFEM", "max_stars_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/libs/gaf95/dcvit2.f95", "max_issues_repo_name": "leemargetts/PoreFEM", "max_issues_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/libs/gaf95/dcvit2.f95", "max_forks_repo_name": "leemargetts/PoreFEM", "max_forks_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.4868421053, "max_line_length": 79, "alphanum_fraction": 0.4765302886, "num_tokens": 1744, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088045171237, "lm_q2_score": 0.7154239957834733, "lm_q1q2_score": 0.6642059366481982}} {"text": "module mjl\n\n ! Note: j values are integer number of half-quanta, i.e. j = 2 x j.\n ! bigJ values are not multiplied by 2, nor are l or n values.\n\n use norm\n use wigner\n use bessel\n use constants, only: pi\n contains\n\n function MJ(y,np,lp,jp,n,l,j,bigJ)\n implicit none\n integer, intent(in) :: np,lp,jp,n,l,j,bigJ\n real(kind=8), intent(in) :: y\n real(kind=8) :: Pi = 3.1415926535897932\n real(kind=8) :: MJ\n \n MJ = (-1d0)**(0.5d0+j/2d0+dble(bigJ))&\n * SQRT(J2norm(j)*J2norm(jp) &\n * Jnorm(l)*Jnorm(lp)*Jnorm(bigJ)/(4*Pi)) &\n * threej_lookup(2*lp,2*bigJ,2*l,0,0,0) &\n * sixj_lookup(2*lp,jp,1,j,2*l,2*bigJ) &\n * BesselElement(y,np,lp,n,l,bigJ)\n \n end function MJ\n \n \n function MJLDivQoverall(lp,jp,l,j,bigJ,bigL)\n implicit none\n integer, intent(in) :: lp,jp,l,j,bigJ,bigL\n real(kind=8) :: MJLDivQoverall\n \n MJLDivQoverall = (-1.0)**(bigL+(j+1)/2)* Qnorm(lp) * q2norm(jp) &\n * q2norm(j)*Qnorm(bigJ)*Qnorm(bigL) &\n * sixj_lookup(2*lp,jp,1,j,2*l,2*bigJ)/SQRT(4d0*Pi)\n \n end function MJLDivQoverall\n \n \n function MJLDivQsummand1(y,np,lp,n,l,bigJ,bigL)\n implicit none\n integer, intent(in) :: np,lp,n,l,bigJ,bigL\n real(kind=8), intent(in) :: y\n real(kind=8) :: MJLDivQsummand1\n \n MJLDivQsummand1 = -SQRT(l+1d0)*Qnorm(l+1) &\n * sixj_lookup(2*bigL,2,2*bigJ,2*l,2*lp,2*(l+1)) &\n * threej_lookup(2*lp,2*bigL,2*(l+1),0,0,0) &\n * BesselElementminus(y,np,lp,n,l,bigL)\n \n end function MJLDivQsummand1\n \n \n function MJLDivQsummand2(y,np,lp,n,l,bigJ,bigL)\n implicit none\n integer, intent(in) :: np,lp,n,l,bigJ,bigL\n real(kind=8), intent(in) :: y\n real(kind=8) :: MJLDivQsummand2\n \n if (l.eq.0) then ! O.C.G: avoid Qnorm(-1)\n MJLDivQsummand2 = 0d0\n else\n MJLDivQsummand2 = SQRT(dble(l))*Qnorm(l-1) &\n * sixj_lookup(2*bigL,2,2*bigJ,2*l,2*lp,2*(l-1)) &\n * threej_lookup(2*lp,2*bigL,2*(l-1),0,0,0) &\n * BesselElementplus(y,np,lp,n,l,bigL)\n endif\n \n end function MJLDivQsummand2\n \n \n function MJLDivQ(y,np,lp,jp,n,l,j,bigJ,bigL)\n implicit none\n integer, intent(in) :: np,lp,jp,n,l,j,bigJ,bigL\n real(kind=8), intent(in) :: y\n real(kind=8) :: MJLDivQ\n \n MJLDivQ = MJLDivQoverall(lp,jp,l,j,bigJ,bigL) & \n * (MJLDivQsummand1(y,np,lp,n,l,bigJ,bigL) &\n + MJLDivQsummand2(y,np,lp,n,l,bigJ,bigL))\n \n end function MJLDivQ\n\nend module mjl\n", "meta": {"hexsha": "3547df377cc251631a90e917682ba1487a3b7221", "size": 2713, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/mjl.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/mjl.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/mjl.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": 31.5465116279, "max_line_length": 73, "alphanum_fraction": 0.5377810542, "num_tokens": 996, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088025362857, "lm_q2_score": 0.7154239897159438, "lm_q1q2_score": 0.6642059295979114}} {"text": "\tFUNCTION PS_RICH ( datain, nparm, clev, ivcord )\nC************************************************************************\nC* PS_RICH\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes the Richardson number for a layer.\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC*\t\tRICH = BFVQ ** 2 / SHRM ** 2\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PS_RICH ( DATAIN, NPARM, CLEV, IVCORD )\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tDATAIN(NPARM,*)\tREAL\t\tStation data\t\t\t*\nC*\tNPARM\t\tINTEGER\t\tNumber of data set parameters\t*\nC*\tCLEV\t\tREAL\t\tVertical level\t\t\t*\nC*\tIVCORD\t\tINTEGER \tVertical coordinate number\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPS_RICH\t\tREAL\t\tRichardson number\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* K. Brill/NMC\t\t 7/90\t\t\t\t\t\t*\nC* T. Lee/GSC\t\t 8/97\tChanged default depth to RMISSD\t\t*\nC************************************************************************\n\tINCLUDE\t\t'GEMPRM.PRM'\nC*\n\tREAL datain (*)\nC*\n\tREAL \tstndb (10), stndt (10), stndl (10)\n\tCHARACTER cvalue*20\nC*\n\tINCLUDE\t\t'ERMISS.FNC'\nC-----------------------------------------------------------------------------\n\tPS_RICH = RMISSD\nC\nC*\tGet information over a depth.\nC\n\tdfdpth = RMISSD\n\tidfcrd = 3\n\tCALL PC_DPTH ( datain, nparm, clev, ivcord, dfdpth, idfcrd, 1,\n +\t\t\tdepth, idcord, stndl, stndb, stndt, ier )\nC\nC*\tCheck for missing data.\nC\n\tIF ( ier .ne. 0 ) RETURN\n\tDO i = 1, 6\n\t IF ( i .ne. 3 ) THEN\n\t\tIF ( ERMISS ( stndt (i) ) .or. ERMISS ( stndb (i) ) )\n +\t\t\t\t\tRETURN\n\t END IF\n\tEND DO\n\tdepth = stndt (6) - stndb (6)\n\tIF ( depth .eq. 0.0 ) RETURN\nC*\n\tthtop = PR_THTA ( stndt (2), stndt (1) )\n\tthbot = PR_THTA ( stndb (2), stndb (1) )\n theta = .5 * ( thtop + thbot )\n bvfsqd = ( GRAVTY / theta ) * ( thtop - thbot ) / depth\nC*\n\tCALL PC_GCND ( '$', 1, dir, cvalue, ier )\n\tutop = stndt (4)\n\tvtop = stndt (5)\n\tubot = stndb (4)\n\tvbot = stndb (5)\n\tIF ( ier .ne. 0 ) THEN\n\t dudz = ( utop - ubot ) / depth\n\t dvdz = ( vtop - vbot ) / depth\n\t shrsqd = ( dudz * dudz + dvdz * dvdz )\n\t ELSE\n\t alpha = ( 270. - dir ) * DTR\n\t uutop = utop * COS ( alpha ) + vtop * SIN ( alpha )\n\t uubot = ubot * COS ( alpha ) + vbot * SIN ( alpha )\n\t dudz = ( uutop - uubot ) / depth\n\t shrsqd = dudz * dudz\n\tEND IF\n\tIF ( shrsqd .eq. 0.0 ) RETURN\nC*\n\tPS_RICH = bvfsqd / shrsqd \nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "da62a31085eb263d09aac9da540fec42aec300b0", "size": 2278, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/ps/psrich.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/ps/psrich.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/ps/psrich.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": 28.1234567901, "max_line_length": 78, "alphanum_fraction": 0.4969271291, "num_tokens": 881, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533126145178, "lm_q2_score": 0.7122321842389469, "lm_q1q2_score": 0.6641232595442795}} {"text": "!\n! file thwsssp.f90\n!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 2005 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Fishpack *\n! * *\n! * A Package of Fortran *\n! * *\n! * Subroutines and Example Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams, Paul Swarztrauber and Roland Sweet *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\n! program to illustrate the use of hwsssp\n!\nprogram test_hwsssp\n\n use fishpack\n\n ! Explicit typing only\n implicit none\n\n ! Dictionary\n integer(ip), parameter :: M = 18, N = 72\n integer(ip), parameter :: MP1 = M + 1, NP1 = N + 1\n integer(ip), parameter :: IDIMF = MP1\n integer(ip) :: mbdcnd, nbdcnd, i, j, ierror\n real(wp) :: f(IDIMF, NP1), sint(IDIMF)\n real(wp), dimension(NP1) :: bdtf, bdts, bdps, bdpf, sinp\n real(wp) :: ts, tf, ps, pf, elmbda\n real(wp) :: dtheta, dphi, pertrb\n real(wp) :: ZERO = 0.0_wp\n\n ! Set domain\n ts = ZERO\n tf = HALF_PI\n ps = ZERO\n pf = TWO_PI\n\n ! Set boundary conditions\n nbdcnd = 0\n mbdcnd = 6\n\n ! Set helmholtz constant\n elmbda = ZERO\n\n ! Set mesh sizes\n dtheta = tf/M\n dphi = TWO_PI/N\n\n ! Generate sines for use in subsequent computations\n do i = 1, MP1\n sint(i) = sin(real(i - 1, kind=wp) * dtheta)\n end do\n\n do j = 1, NP1\n sinp(j) = sin(real(j - 1, kind=wp) * dphi)\n end do\n\n ! Compute right hand side of equation and store in f\n block\n real(wp), parameter :: TWO = 2.0_wp\n real(wp), parameter :: SIX = 6.0_wp\n\n do j = 1, NP1\n f(:MP1, j) = TWO - SIX * (sint(:MP1)*sinp(j))**2\n end do\n end block\n\n ! Store derivative data at the equator\n bdtf(:NP1) = ZERO\n\n ! Solve 2D Helmholtz in spherical coordinates on a centered grid\n call hwsssp(ts, tf, M, mbdcnd, bdts, bdtf, ps, pf, N, nbdcnd, &\n bdps, bdpf, elmbda, f, IDIMF, pertrb, ierror)\n\n ! Compute discretization error.\n ! Since problem is singular, the solution must be normalized.\n block\n real(wp), parameter :: KNOWN_ERROR = 0.338107338525839e-2_wp\n real(wp) :: discretization_error, exact_solution(MP1, NP1)\n\n do j = 1, NP1\n do i = 1, MP1\n exact_solution(i,j) = (sint(i)*sinp(j))**2 - f(1, 1)\n end do\n end do\n\n ! Set discretization error\n discretization_error = maxval(abs(exact_solution - f(:MP1,:NP1)))\n\n call check_output('hwsssp', ierror, KNOWN_ERROR, discretization_error)\n end block\n\nend program test_hwsssp\n", "meta": {"hexsha": "2a860ebf9575c599bf7dd68dec3a8f2041763131", "size": 4537, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/thwsssp.f90", "max_stars_repo_name": "jlokimlin/fishpack", "max_stars_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2018-03-12T11:31:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-27T07:58:23.000Z", "max_issues_repo_path": "examples/thwsssp.f90", "max_issues_repo_name": "jlokimlin/fishpack", "max_issues_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2016-05-07T22:42:47.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-15T17:44:58.000Z", "max_forks_repo_path": "examples/thwsssp.f90", "max_forks_repo_name": "jlokimlin/fishpack", "max_forks_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-09-07T15:43:32.000Z", "max_forks_repo_forks_event_max_datetime": "2018-06-16T21:30:13.000Z", "avg_line_length": 38.4491525424, "max_line_length": 78, "alphanum_fraction": 0.35265594, "num_tokens": 1055, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505428129514, "lm_q2_score": 0.7341195385342971, "lm_q1q2_score": 0.6641216390246453}} {"text": "program Test_Stddev\n implicit none\n\n real, dimension(8) :: v = (/ 2,4,4,4,5,5,7,9 /)\n integer :: i\n real :: sd\n\n do i = 1, size(v)\n sd = stat_object(v(i))\n end do\n\n print *, \"std dev = \", sd\n\ncontains\n\n recursive function stat_object(a, cmd) result(stddev)\n real :: stddev\n real, intent(in) :: a\n character(len=*), intent(in), optional :: cmd\n\n real, save :: summa = 0.0, summa2 = 0.0\n integer, save :: num = 0\n\n real :: m\n\n if ( .not. present(cmd) ) then\n num = num + 1\n summa = summa + a\n summa2 = summa2 + a*a\n stddev = stat_object(0.0, \"stddev\")\n else\n select case(cmd)\n case(\"stddev\")\n stddev = sqrt(stat_object(0.0, \"variance\"))\n case(\"variance\")\n m = stat_object(0.0, \"mean\")\n if ( num > 0 ) then\n stddev = summa2/real(num) - m*m\n else\n stddev = 0.0\n end if\n case(\"count\")\n stddev = real(num)\n case(\"mean\")\n if ( num > 0 ) then\n stddev = summa/real(num)\n else\n stddev = 0.0\n end if\n case(\"reset\")\n summa = 0.0\n summa2 = 0.0\n num = 0\n case default\n stddev = 0.0\n end select\n end if\n\n end function stat_object\n\nend program Test_Stddev\n", "meta": {"hexsha": "bd4fe633693757cd42ed38cdc8bd5cf991ad4bce", "size": 1317, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Standard-deviation/Fortran/standard-deviation-1.f", "max_stars_repo_name": "djgoku/RosettaCodeData", "max_stars_repo_head_hexsha": "91df62d46142e921b3eacdb52b0316c39ee236bc", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Task/Standard-deviation/Fortran/standard-deviation-1.f", "max_issues_repo_name": "djgoku/RosettaCodeData", "max_issues_repo_head_hexsha": "91df62d46142e921b3eacdb52b0316c39ee236bc", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Standard-deviation/Fortran/standard-deviation-1.f", "max_forks_repo_name": "djgoku/RosettaCodeData", "max_forks_repo_head_hexsha": "91df62d46142e921b3eacdb52b0316c39ee236bc", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.2419354839, "max_line_length": 55, "alphanum_fraction": 0.4927866363, "num_tokens": 414, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595161, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6641216243262836}} {"text": "!====================================================================\n!-----------------------------------------------------------------------\n! NASA/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !\n!-----------------------------------------------------------------------\n!BOI\n! !MODULE: m_temperature -- Temperature conversion routines\n!\n! !DESCRIPTION:\n! This module contains routines that convert temperature values. \n!\n! !REFERENCES:\n! Rogers, R. R., 1979: A Short Course in Cloud Physics, 2nd. Ed., \n! Pergamon Press, Oxford. 235pp.\n!\n! !INTERFACE:\n!\n module m_temperature\n implicit NONE\n private\t! except\n\n public :: ! Routines to convert from air temp (AT) to ...\n . ATtoPT, AT2PT, ! ... potential temperature (PT)\n . ATtoVT, AT2VT ! ... virtual temperature (VT)\n\n public :: ! Routines to convert from ...\n . PTtoAT, PT2AT, ! ... potential temperature (PT)\n . VTtoAT, VT2AT ! ... virtual temperature (VT)\n public :: ! Equation code for determining the VT\n . VT_Exact, ! ... using the exact equations\n . VT_NCEP ! ... NCEPS's approximation\n!\n interface ATtoVT\n module procedure ! Convert from air temperature and ..\n . ATtoVT_vp, ! ... vapor pressure or\n . ATtoVT_mr ! ... mixing ratio to virtual temperature\n end interface\n\n interface AT2VT\n module procedure ! Convert from air temperature and ..\n . AT2VT_vp, ! ... vapor pressure or\n . AT2VT_mr ! ... mixing ratio to virtual temperature\n end interface\n!\n interface VTtoAT\n module procedure ! Convert from virtual temperature and ..\n . VTtoAT_vp, ! ... vapor pressure or\n . VTtoAT_mr ! ... mixing ratio to air temperature\n end interface\n!\n interface VT2AT\n module procedure ! Convert from virtual temperature and ..\n . VT2AT_vp, ! ... vapor pressure or\n . VT2AT_mr ! ... mixing ratio to air temperature\n end interface\n!\n! Note: Routine names of the form xxtoxx and xx2xx implies a\n! subroutine and function, respectively.\n!\n! !REVISION HISTORY:\n! 23Jul2002 C. Redder Original code\n!EOI\n!-----------------------------------------------------------------\n real, parameter ::\n . Ra = 287.0, ! The individual gas constant for dry air and ...\n . Rv = 461.0, ! ... water vapor (j/(kg-deg K, from Rogers,\n . RaRv = Ra / Rv ! 1979)\n real, parameter ::\n . Cp = 1004.0, ! Specific heat at constant pressure\n . Cv = 717.0, ! ... at constant volume for dry air\n . ! (j/(kg-deg K, from Rogers, 1979)\n . k = ( Cp - Cv ) / Cp,\n . PS_Def = 1000.0 ! Default value for the final pressure for\n ! the potential temperature (mb).\n\n integer, parameter ::\n . VT_Exact = 0, ! Exact equation\n . VT_NCEP = 1 ! ... NCEP's approximation\n\n contains\n!......................................................................\n\n!-------------------------------------------------------------------------\n! Nasa/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !\n!-------------------------------------------------------------------------\n! BOP\n!\n! !ROUTINE: ATtoPT () --- Air temperature to potential temperature\n!\n! !DESCRIPTION:\n! This routine converts a set of temperature values from air temperature\n! to potential temperature\n!\n! !INTERFACE:\n pure subroutine ATtoPT ( AT, P, PT, PS )\n implicit NONE\n!\n! !INPUT PARAMETERS:\n real, intent (in) ::\n . AT (:), ! air temperature (deg K)\n . P (:) ! air pressure (mb or hPa)\n real, intent (in), optional ::\n . PS ! reference pressure (mb or hPa). Default: PS = 1000.0 mb\n! !OUTPUT PARAMETERS:\n real, intent (out) ::\n . PT (:) ! potential temperature (deg K)\n!\n! Note: The minimum size of the arrays AT and PT determines the number\n! of values to convert.\n!\n! !SEE ALSO:\n!\n! !REVISION HISTORY:\n! 23Jul2002 C. Redder Original code.\n!\n! EOP\n!-------------------------------------------------------------------------\n\n real :: T, PP, PSS\n integer :: iT, NT, NP\n\n PSS = PS_Def\n if ( present ( PS )) PSS = PS\n\n NP = size ( P )\n NT = min ( size ( AT ), size ( PT ))\n if ( NP .eq. 0 ) NT = 0\n do iT = 1, NT\n T = AT ( iT )\n PP = PSS / P ( min ( iT, NP ))\n PT ( iT ) = T * PP ** k\n end do\n\n return\n end subroutine ATtoPT\n\n!......................................................................\n\n!-------------------------------------------------------------------------\n! Nasa/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !\n!-------------------------------------------------------------------------\n! BOP\n!\n! !ROUTINE: PTtoAT () --- Potential temperature to air temperature\n!\n! !DESCRIPTION:\n! This routine converts a set of temperature values from potential\n! temperature to air temperature\n!\n! !INTERFACE:\n pure subroutine PTtoAT ( PT, P, AT, PS )\n implicit NONE\n!\n! !INPUT PARAMETERS:\n real, intent (in) ::\n . PT (:), ! potential temperature (deg K)\n . P (:) ! air pressure (mb or hPa)\n real, intent (in), optional ::\n . PS ! reference pressure (mb or hPa). Default: PS = 1000.0 mb\n! !OUTPUT PARAMETERS:\n real, intent (out) ::\n . AT (:) ! air temperature (deg K)\n!\n! Note: The minimum size of the arrays PT and AT determines the number\n! of values to convert.\n!\n! !SEE ALSO:\n!\n! !REVISION HISTORY:\n! 23Jul2002 C. Redder Original code.\n!\n! EOP\n!-------------------------------------------------------------------------\n\n real :: T, PP, PSS\n integer :: iT, NT, NP\n\n PSS = PS_Def\n if ( present ( PS )) PSS = PS\n\n NP = size ( P )\n NT = min ( size ( AT ), size ( PT ))\n if ( NP .eq. 0 ) NT = 0\n do iT = 1, NT\n T = PT ( iT )\n PP = PSS / P ( min ( iT, NP ))\n AT ( iT ) = T * PP ** (-k)\n end do\n\n return\n end subroutine PTtoAT\n\n!......................................................................\n\n!-------------------------------------------------------------------------\n! Nasa/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !\n!-------------------------------------------------------------------------\n! BOP\n!\n! !ROUTINE: AT2PT () --- Air temperature to potential temperature\n!\n! !DESCRIPTION:\n! This routine converts a set of temperature values from air\n! temperature to potential temperature\n!\n! !INTERFACE:\n pure function AT2PT ( AT, P, PS )\n implicit NONE\n!\n! !INPUT PARAMETERS:\n real, intent (in) :: AT ! air temperature (deg K)\n real, intent (in) :: P ! air pressure (mb or hPa)\n real, intent (in), optional :: PS ! reference pressure (mb or hPa).\n ! Default: PS = 1000.0 mb\n! !OUTPUT PARAMETERS:\n real :: AT2PT ! potential temperature (deg K)\n!\n! !SEE ALSO:\n!\n! !REVISION HISTORY: \n! 23Jul2002 C. Redder Original code.\n!\n! EOP\n!-------------------------------------------------------------------------\n\n real :: PT (1)\n\n call ATtoPT ( (/AT/), (/P/), PT, PS )\n AT2PT = PT (1)\n\n return\n end function AT2PT\n\n!......................................................................\n\n!-------------------------------------------------------------------------\n! Nasa/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !\n!-------------------------------------------------------------------------\n! BOP\n!\n! !ROUTINE: PT2AT () --- Potential temperature to air temperature\n!\n! !DESCRIPTION:\n! This routine converts a set of temperature values from potential\n! temperature to air temperature\n!\n! !INTERFACE:\n pure function PT2AT ( PT, P, PS )\n implicit NONE\n!\n! !INPUT PARAMETERS:\n real, intent (in) :: PT ! potential temperature (deg K)\n real, intent (in) :: P ! air pressure (mb or hPa)\n real, intent (in), optional :: PS ! reference pressure (mb or hPa).\n ! Default: PS = 1000.0 mb\n! !OUTPUT PARAMETERS:\n real :: PT2AT ! air temperature (deg K)\n!\n! !SEE ALSO:\n!\n! !REVISION HISTORY: \n! 23Jul2002 C. Redder Original code.\n!\n! EOP\n!-------------------------------------------------------------------------\n\n real :: AT (1)\n\n call PTtoAT ( (/PT/), (/P/), AT, PS )\n PT2AT = AT (1)\n\n return\n end function PT2AT\n!......................................................................\n\n!-------------------------------------------------------------------------\n! Nasa/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !\n!-------------------------------------------------------------------------\n! BOP\n!\n! !ROUTINE: ATtoVT_vp () --- Air temperature and vapor pressure to virtual temperature\n!\n! !DESCRIPTION:\n! This routine converts a set of temperature values from air temperature\n! and vapor pressure to virtual temperature.\n!\n! !INTERFACE:\n pure subroutine ATtoVT_vp ( AT, P, VP, VT, Eqtn )\n implicit NONE\n!\n! !INPUT PARAMETERS:\n real, intent (in) ::\n . AT (:), ! air temperature (deg K)\n . P (:), ! air pressure (mb or hPa)\n . VP (:) ! vapor pressure (mb or hPa)\n integer, intent (in), optional ::\n . Eqtn ! equation code (default: 0)\n!\n! !OUTPUT PARAMETERS:\n real, intent (out) ::\n . VT (:) ! virtual temperature (deg K)\n!\n! Note: The minimum size of the arrays AT, VP and VT determines the\n! number of values to convert.\n!\n! !SEE ALSO:\n!\n! !REVISION HISTORY:\n! 23Jul2002 C. Redder Original code.\n! 20Apr2004 C. Redder Added the optional argument, Eqtn.\n!\n! EOP\n!-------------------------------------------------------------------------\n\n real :: T, W, PP\n integer :: iT, NT, NP, Code_\n\n Code_ = VT_Exact\n if ( present ( Eqtn )) Code_ = Eqtn\n\n NP = size ( P )\n NT = min ( size ( AT ), size ( VP ), size ( VT ))\n if ( NP .eq. 0 ) NT = 0\n\n if ( Code_ .eq. VT_NCEP ) then\n do iT = 1, NT\n T = AT ( iT )\n PP = P ( min ( iT, NP ))\n W = RaRv * VP ( iT ) / ( PP - VP ( iT ))\n VT ( iT ) = T * ( 1.0 + 0.61 * W )\n end do\n\n else\n do iT = 1, NT\n T = AT ( iT )\n PP = P ( min ( iT, NP ))\n W = RaRv * VP ( iT ) / ( PP - VP ( iT ))\n VT ( iT ) = T * ( 1.0 + W / RaRv )\n . / ( 1.0 + W )\n end do\n\n end if\n\n return\n end subroutine ATtoVT_vp\n!......................................................................\n\n!-------------------------------------------------------------------------\n! Nasa/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !\n!-------------------------------------------------------------------------\n! BOP\n!\n! !ROUTINE: ATtoVT_mr () --- Air temperature and mixing ratio to virtual temperature\n!\n! !DESCRIPTION:\n! This routine converts a set of temperature values from air temperature\n! and mixing ratio to virtual temperature\n!\n! !INTERFACE:\n pure subroutine ATtoVT_mr ( AT, MR, VT, Eqtn )\n implicit NONE\n!\n! !INPUT PARAMETERS:\n real, intent (in) ::\n . AT (:), ! air temperature (deg K)\n . MR (:) ! mixing ratio (g/kg)\n integer, intent (in), optional ::\n . Eqtn ! equation code (default: 0)\n! !OUTPUT PARAMETERS:\n real, intent (out) ::\n . VT (:) ! virtual temperature (deg K)\n!\n! Note: The minimum size of the arrays AT, MR and VT determines the\n! number of values to convert.\n!\n! !SEE ALSO:\n!\n! !REVISION HISTORY:\n! 23Jul2002 C. Redder Original code.\n! 20Apr2004 C. Redder Added the optional argument, Eqtn.\n!\n! EOP\n!-------------------------------------------------------------------------\n\n real :: T, MRR\n integer :: iT, NT, Code_\n\n Code_ = VT_Exact\n if ( present ( Eqtn )) Code_ = Eqtn\n\n NT = min ( size ( AT ), size ( MR ), size ( VT ))\n\n if ( Code_ .eq. VT_NCEP ) then\n do iT = 1, NT\n T = AT ( iT )\n MRR = 0.001 * MR ( iT )\n VT ( iT ) = T * ( 1.0 + 0.61 * MRR )\n end do\n\n else\n do iT = 1, NT\n T = AT ( iT )\n MRR = 0.001 * MR ( iT )\n VT ( iT ) = T * ( 1.0 + MRR / RaRv )\n . / ( 1.0 + MRR )\n end do\n\n end if\n\n return\n end subroutine ATtoVT_mr\n!......................................................................\n\n!-------------------------------------------------------------------------\n! Nasa/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !\n!-------------------------------------------------------------------------\n! BOP\n!\n! !ROUTINE: VTtoAT_vp () --- Virtual temperature and vapor pressure to airtemperature\n!\n! !DESCRIPTION:\n! This routine converts a set of temperature values from virtual\n! temperature and vapor pressure to air temperature.\n!\n! !INTERFACE:\n pure subroutine VTtoAT_vp ( VT, P, VP, AT, Eqtn )\n implicit NONE\n!\n! !INPUT PARAMETERS:\n real, intent (in) ::\n . VT (:), ! virtual temperature (deg K)\n . P (:), ! air pressure (mb or hPa)\n . VP (:) ! vapor pressure (mb or hPa)\n integer, intent (in), optional ::\n . Eqtn ! equation code (default: 0)\n! !OUTPUT PARAMETERS:\n real, intent (out) ::\n . AT (:) ! air temperature (deg K)\n!\n! Note: The minimum size of the arrays VT, VP and AT determines the\n! number of values to convert.\n!\n! !SEE ALSO:\n!\n! !REVISION HISTORY:\n! 23Jul2002 C. Redder Original code.\n! 20Apr2004 C. Redder Added the optional argument, Eqtn.\n!\n! EOP\n!-------------------------------------------------------------------------\n\n real :: T, W, PP\n integer :: iT, NT, NP, Code_\n\n Code_ = VT_Exact\n if ( present ( Eqtn )) Code_ = Eqtn\n\n NP = size ( P )\n NT = min ( size ( VT ), size ( VP ), size ( AT ))\n if ( NP .eq. 0 ) NT = 0\n\n if ( Code_ .eq. VT_NCEP ) then\n do iT = 1, NT\n T = VT ( iT )\n PP = P ( min ( iT, NP ))\n W = RaRv * VP ( iT ) / ( PP - VP ( iT ))\n AT ( iT ) = T / ( 1.0 + 0.61 * W )\n\n end do\n\n else\n do iT = 1, NT\n T = VT ( iT )\n PP = P ( min ( iT, NP ))\n W = RaRv * VP ( iT ) / ( PP - VP ( iT ))\n AT ( iT ) = T * ( 1.0 + W )\n . / ( 1.0 + W / RaRv )\n end do\n\n end if\n\n return\n end subroutine VTtoAT_vp\n!......................................................................\n\n!-------------------------------------------------------------------------\n! Nasa/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !\n!-------------------------------------------------------------------------\n! BOP\n!\n! !ROUTINE: VTtoAT_mr () --- Virtual temperature and mixing ratio to air temperature\n!\n! !DESCRIPTION:\n! This routine converts a set of temperature values from virtural\n! temperature and mixing ratio to air temperature\n!\n! !INTERFACE:\n pure subroutine VTtoAT_mr ( VT, MR, AT, Eqtn )\n implicit NONE\n!\n! !INPUT PARAMETERS:\n real, intent (in) ::\n . VT (:), ! virtual temperature (deg K)\n . MR (:) ! mixing ratio (g/kg)\n integer, intent (in), optional ::\n . Eqtn ! equation code (default: 0)\n! !OUTPUT PARAMETERS:\n real, intent (out) ::\n . AT (:) ! air temperature (deg K)\n!\n! Note: The minimum size of the arrays AT, MR and VT determines the\n! number of values to convert.\n!\n! !SEE ALSO:\n!\n! !REVISION HISTORY:\n! 23Jul2002 C. Redder Original code.\n! 20Apr2004 C. Redder Added the optional argument, Eqtn.\n!\n! EOP\n!-------------------------------------------------------------------------\n\n real :: T, MRR\n integer :: iT, NT, Code_\n\n Code_ = VT_Exact\n if ( present ( Eqtn )) Code_ = Eqtn\n\n NT = min ( size ( VT ), size ( MR ), size ( AT ))\n\n if ( Code_ .eq. VT_NCEP ) then\n do iT = 1, NT\n T = VT ( iT )\n MRR = 0.001 * MR ( iT )\n AT ( iT ) = T / ( 1.0 + 0.61 * MRR )\n end do\n else\n do iT = 1, NT\n T = VT ( iT )\n MRR = 0.001 * MR ( iT )\n AT ( iT ) = T * ( 1.0 + MRR )\n . / ( 1.0 + MRR / RaRv )\n end do\n\n end if\n\n return\n end subroutine VTtoAT_mr\n!......................................................................\n\n!-------------------------------------------------------------------------\n! Nasa/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !\n!-------------------------------------------------------------------------\n! BOP\n!\n! !ROUTINE: AT2VT_vp () --- Air temperature and vapor pressure to virtual temperature\n!\n! !DESCRIPTION:\n! This routine converts a set of temperature values from air\n! temperature and vapor pressure to virtual temperature\n!\n! !INTERFACE:\n pure function AT2VT_vp ( AT, P, VP, Eqtn )\n implicit NONE\n!\n! !INPUT PARAMETERS:\n real, intent (in) :: AT ! air temperature (deg K)\n real, intent (in) :: P ! air pressure (mb or hPa)\n real, intent (in) :: VP ! vapor pressure (mb or hPa)\n integer, intent (in), optional ::\n . Eqtn ! equation code (default: 0)\n!\n! !OUTPUT PARAMETERS:\n real :: AT2VT_vp ! virtual temperature (deg K)\n!\n! !SEE ALSO:\n!\n! !REVISION HISTORY: \n! 23Jul2002 C. Redder Original code.\n! 20Apr2004 C. Redder Added the optional argument, Eqtn.\n!\n! EOP\n!-------------------------------------------------------------------------\n\n real :: VT (1)\n\n call ATtoVT_vp ( (/AT/), (/P/), (/VP/), VT, Eqtn )\n AT2VT_vp = VT (1)\n\n return\n end function AT2VT_vp\n\n!......................................................................\n\n!-------------------------------------------------------------------------\n! Nasa/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !\n!-------------------------------------------------------------------------\n! BOP\n!\n! !ROUTINE: AT2VT_mr () --- Air temperature and mixing ratio to virtual temperature\n!\n! !DESCRIPTION:\n! This routine converts a set of temperature values from air\n! temperature and mixing ratio to virtual temperature\n!\n! !INTERFACE:\n pure function AT2VT_mr ( AT, MR, Eqtn )\n implicit NONE\n!\n! !INPUT PARAMETERS:\n real, intent (in) :: AT ! air temperature (deg K)\n real, intent (in) :: MR ! vapor pressure (mb or hPa)\n integer, intent (in), optional ::\n . Eqtn ! equation code (default: 0)\n!\n! !OUTPUT PARAMETERS:\n real :: AT2VT_mr ! virtual temperature (deg K)\n!\n! !SEE ALSO:\n!\n! !REVISION HISTORY: \n! 23Jul2002 C. Redder Original code.\n! 20Apr2004 C. Redder Added the optional argument, Eqtn.\n!\n! EOP\n!-------------------------------------------------------------------------\n\n real :: VT (1)\n\n call ATtoVT_mr ( (/AT/), (/MR/), VT, Eqtn )\n AT2VT_mr = VT (1)\n\n return\n end function AT2VT_mr\n\n!......................................................................\n\n!-------------------------------------------------------------------------\n! Nasa/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !\n!-------------------------------------------------------------------------\n! BOP\n!\n! !ROUTINE: VT2AT_vp () --- Virtual temperature and vapor pressure to air temperature\n!\n! !DESCRIPTION:\n! This routine converts a set of temperature values from virtual\n! temperature and vapor pressure to air temperature\n!\n! !INTERFACE:\n pure function VT2AT_vp ( VT, P, VP, Eqtn )\n implicit NONE\n!\n! !INPUT PARAMETERS:\n real, intent (in) :: VT ! virtual temperature (deg K)\n real, intent (in) :: P ! air pressure (mb or hPa)\n real, intent (in) :: VP ! vapor pressure (mb or hPa)\n integer, intent (in), optional ::\n . Eqtn ! equation code (default: 0)\n!\n! !OUTPUT PARAMETERS:\n real :: VT2AT_vp ! air temperature (deg K)\n!\n! !SEE ALSO:\n!\n! !REVISION HISTORY: \n! 23Jul2002 C. Redder Original code.\n! 20Apr2004 C. Redder Added the optional argument, Eqtn.\n!\n! EOP\n!-------------------------------------------------------------------------\n\n real :: AT (1)\n\n call VTtoAT_vp ( (/VT/), (/P/), (/VP/), AT, Eqtn )\n VT2AT_vp = AT (1)\n\n return\n end function VT2AT_vp\n\n!......................................................................\n\n!-------------------------------------------------------------------------\n! Nasa/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !\n!-------------------------------------------------------------------------\n! BOP\n!\n! !ROUTINE: VT2AT_mr () --- Virtual temperature and mixing ratio to air temperature\n!\n! !DESCRIPTION:\n! This routine converts a set of temperature values from virtual\n! temperature and mixing ratio to air temperature\n!\n! !INTERFACE:\n pure function VT2AT_mr ( VT, MR, Eqtn )\n implicit NONE\n!\n! !INPUT PARAMETERS:\n real, intent (in) :: VT ! virtual temperature (deg K)\n real, intent (in) :: MR ! vapor pressure (mb or hPa)\n integer, intent (in), optional ::\n . Eqtn ! equation code (default: 0)\n!\n! !OUTPUT PARAMETERS:\n real :: VT2AT_mr ! air temperature (deg K)\n!\n! !SEE ALSO:\n!\n! !REVISION HISTORY: \n! 23Jul2002 C. Redder Original code.\n! 20Apr2004 C. Redder Added the optional argument, Eqtn.\n!\n! EOP\n!-------------------------------------------------------------------------\n\n real :: AT (1)\n\n call VTtoAT_mr ( (/VT/), (/MR/), AT, Eqtn )\n VT2AT_mr = AT (1)\n\n return\n end function VT2AT_mr\n!......................................................................\n end module m_temperature\n!====================================================================\n", "meta": {"hexsha": "24fd88474535b03fb006e5645aa103cb95c8cb5b", "size": 22779, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/Applications/NCEP_Paqc/radcor/m_temperature.f", "max_stars_repo_name": "GEOS-ESM/GEOSadas", "max_stars_repo_head_hexsha": "8e3665af71eb37c48573c65ed0e9daa5ca429535", "max_stars_repo_licenses": ["NASA-1.3", "Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-09-07T09:00:32.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-12T02:25:56.000Z", "max_issues_repo_path": "src/Applications/NCEP_Paqc/radcor/m_temperature.f", "max_issues_repo_name": "GEOS-ESM/GEOSadas", "max_issues_repo_head_hexsha": "8e3665af71eb37c48573c65ed0e9daa5ca429535", "max_issues_repo_licenses": ["NASA-1.3", "Apache-2.0"], "max_issues_count": 81, "max_issues_repo_issues_event_min_datetime": "2019-07-05T19:28:50.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-04T19:37:47.000Z", "max_forks_repo_path": "src/Applications/NCEP_Paqc/radcor/m_temperature.f", "max_forks_repo_name": "GEOS-ESM/GEOSadas", "max_forks_repo_head_hexsha": "8e3665af71eb37c48573c65ed0e9daa5ca429535", "max_forks_repo_licenses": ["NASA-1.3", "Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.4627071823, "max_line_length": 86, "alphanum_fraction": 0.4395715352, "num_tokens": 5689, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6641216138014762}} {"text": " SUBROUTINE SHSTTS (TAB,UAB,VAB)\r\nC\r\nC TO CREATE STRESS TENSOR TRANSFORMATION MATRICES FROM AN ORTHOGONAL\r\nC TRANSFORMATION FOR SHELL ELEMENTS.\r\nC\r\nC INPUT :\r\nC TAB - ORTHOGONAL INPLANE ROTATION TRANSFORMATION\r\nC OUTPUT:\r\nC UAB - TENSOR TRANSFORMATION FOR NORMAL AND INPLANE SHEAR\r\nC COMPONENTS\r\nC VAB - TENSOR TRANSFORMATION FOR OUT-OF-PLANE SHEAR\r\nC\r\nC USAGE:\r\nC THE INPUT IS ASSUMED TO BE ROW-LOADED.\r\nC OUTPUTS ARE CREATED ROW-LOADED.\r\nC DEFINING:\r\nC [S] AS A 2-D STRESS VECTOR;\r\nC [E] AS A 2-D STRAIN VECTOR;\r\nC [Q] AS A 2-D SHEAR FORCE VECTOR;\r\nC [G] AS A 2-D STRESS/FORCE-STRAIN RELATION; AND\r\nC [ALPHA] AS A VECTOR OF THERMAL EXPANSION COEFFICIENTS,\r\nC\r\nC THEN THE FOLLOWING RELATIONSHIPS ARE TRUE:\r\nC\r\nC T T\r\nC [S] = [UAB] [S] [G] = [UAB] [G] [UAB]\r\nC A B A B\r\nC\r\nC T\r\nC [Q] = [VAB] [Q]\r\nC A B\r\nC\r\nC IF [TBA] IS INPUT, THE OUTPUT WILL BE:\r\nC\r\nC -1 -1 T\r\nC [UAB] = [UBA], AND [VAB] = [VAB] = [VBA]\r\nC\r\nC WHICH MAY BE USED IN THE FOLLOWING:\r\nC\r\nC [E] = [UBA] [E] [ALPHA] = [UBA] [ALPHA]\r\nC A B A B\r\nC\r\nC [Q] = [VBA][Q]\r\nC A B\r\nC\r\nC\r\n REAL TAB(9),UAB(9),VAB(4)\r\nC\r\n UAB(1) = TAB(1)*TAB(1)\r\n UAB(2) = TAB(4)*TAB(4)\r\n UAB(3) = TAB(1)*TAB(4)\r\n UAB(4) = TAB(2)*TAB(2)\r\n UAB(5) = TAB(5)*TAB(5)\r\n UAB(6) = TAB(2)*TAB(5)\r\n UAB(7) = TAB(1)*TAB(2)*2.0\r\n UAB(8) = TAB(4)*TAB(5)*2.0\r\n UAB(9) = TAB(1)*TAB(5) + TAB(2)*TAB(4)\r\nC\r\n VAB(1) = TAB(5)*TAB(9)\r\n VAB(2) = TAB(2)*TAB(9)\r\n VAB(3) = TAB(4)*TAB(9)\r\n VAB(4) = TAB(1)*TAB(9)\r\nC\r\n RETURN\r\n END\r\n", "meta": {"hexsha": "d277d50d15a950a829e981d937809a3f350c312e", "size": 2071, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "mis/shstts.f", "max_stars_repo_name": "ldallolio/NASTRAN-95", "max_stars_repo_head_hexsha": "6d2c175f5b53ebaec4ba2b5186f7926ef9d0ed47", "max_stars_repo_licenses": ["NASA-1.3"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2016-01-09T14:33:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-18T11:51:42.000Z", "max_issues_repo_path": "mis/shstts.f", "max_issues_repo_name": "gassive/NASTRAN95", "max_issues_repo_head_hexsha": "98cb3acaa7990d639360601648498834c7782056", "max_issues_repo_licenses": ["NASA-1.3"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2016-01-17T07:30:19.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-06T19:37:44.000Z", "max_forks_repo_path": "mis/shstts.f", "max_forks_repo_name": "gassive/NASTRAN95", "max_forks_repo_head_hexsha": "98cb3acaa7990d639360601648498834c7782056", "max_forks_repo_licenses": ["NASA-1.3"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-04-07T20:51:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T14:16:01.000Z", "avg_line_length": 31.3787878788, "max_line_length": 73, "alphanum_fraction": 0.4239497827, "num_tokens": 716, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418283357702, "lm_q2_score": 0.7185944046238982, "lm_q1q2_score": 0.6640831469209836}} {"text": "C-----------------------------------------------------------------------------\nC\n double precision function massfrun(mf,scale,asmz,nloop)\nC\nC-----------------------------------------------------------------------------\nC\nC This function returns the 'nloop' value of a MSbar fermion mass\nC at a given scale.\nC\nC INPUT: mf = MSbar mass of fermion at MSbar fermion mass scale\nC scale = scale at which the running mass is evaluated\nC asmz = AS(MZ) : this is passed to alphas(scale,asmz,2)\nC nloop = # of loops in the evolutionC\nC\nC COMMON BLOCKS: COMMON/QMASS/CMASS,BMASS,TMASS\nC contains the MS-bar masses of the heavy quarks.\nC\nC EXTERNAL: double precision alphas(scale,asmz,2)\nC\nC-----------------------------------------------------------------------------\nC\n implicit none\n include 'masses.f'\nC\nC ARGUMENTS\nC\n double precision mf,scale,asmz\n integer nloop\nC\nC LOCAL\nC\n double precision beta0, beta1,gamma0,gamma1\n double precision A1,as,asmf,l2\n integer nf\nC\nC EXTERNAL\nC\n double precision alphas\n external alphas\nC\nC COMMON\nC\nc real *8 cmass,bmass,tmass\nc COMMON/QMASS/CMASS,BMASS,TMASS\nc\nc CONSTANTS\nc\n double precision One, Two, Three, Pi\n parameter( One = 1d0, Two = 2d0, Three = 3d0 )\n parameter( Pi = 3.14159265358979323846d0)\ncc\nC\nC\n\n if ( mf.gt.mt ) then\n nf = 6\n else\n nf = 5\n end if\n\n beta0 = ( 11d0 - Two/Three *nf )/4d0\n beta1 = ( 102d0 - 38d0/Three*nf )/16d0\n gamma0= one\n gamma1= ( 202d0/3d0 - 20d0/9d0*nf )/16d0\n A1 = -beta1*gamma0/beta0**2+gamma1/beta0\n as = alphas(scale,asmz,nloop)\n asmf = alphas(mf ,asmz,nloop)\n l2 = (one+A1*as/Pi)/(one+A1*asmf/Pi)\n\n massfrun = mf * (as/asmf)**(gamma0/beta0)\n\n if(nloop.eq.2) massfrun=massfrun*l2\nccc\n return\n end\n\n\n", "meta": {"hexsha": "0d89570ff0bcc548fdb6252bf9efee94d3951d2d", "size": 2000, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "MCFM-JHUGen/src/Need/mfrun.f", "max_stars_repo_name": "tmartini/JHUGen", "max_stars_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-06-08T13:09:28.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-04T19:59:36.000Z", "max_issues_repo_path": "MCFM-JHUGen/src/Need/mfrun.f", "max_issues_repo_name": "tmartini/JHUGen", "max_issues_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 64, "max_issues_repo_issues_event_min_datetime": "2015-06-24T15:08:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-25T04:59:32.000Z", "max_forks_repo_path": "MCFM-JHUGen/src/Need/mfrun.f", "max_forks_repo_name": "tmartini/JHUGen", "max_forks_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2015-05-04T22:15:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-06T10:04:40.000Z", "avg_line_length": 25.641025641, "max_line_length": 78, "alphanum_fraction": 0.519, "num_tokens": 631, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418241572634, "lm_q2_score": 0.7185943805178139, "lm_q1q2_score": 0.6640831216408912}} {"text": " MODULE m_gtest\n use m_juDFT\n!*********************************************************************\n! test the gaussian integration mesh for this l\n! 1) integrate each ylm, 2) get normalization of each ylm,\n! 3) (ylm(lmax,m=lmax | ylm) for all lm\n!*********************************************************************\n CONTAINS\n SUBROUTINE gtest(lmax,ngpts,vgauss,wt)\n\n USE m_constants\n USE m_ylm\n IMPLICIT NONE\n!\n INTEGER, INTENT (IN) :: lmax,ngpts\n REAL, INTENT (IN) :: vgauss(3,*),wt(*) ! gaussian integration points\n\n INTEGER :: lm,lmmax,nn\n LOGICAL :: lerr\n COMPLEX :: temp\n REAL :: v(3)\n COMPLEX, DIMENSION((lmax+1)**2) :: ylm,s1,s2,s3\n\n REAL, PARAMETER :: del = 1.e-10\n\n lmmax = (lmax+1)**2\n DO lm = 1, lmmax\n s1(lm)=cmplx(0.0,0.0)\n s2(lm)=cmplx(0.0,0.0)\n s3(lm)=cmplx(0.0,0.0)\n ENDDO\n\n!---> loop over points\n DO nn = 1, ngpts\n v(:) = vgauss(:,nn)\n CALL ylm4(\n > lmax,v,\n < ylm)\n DO lm = 1, lmmax\n s1(lm) = s1(lm) + wt(nn)*ylm(lm)\n s2(lm) = s2(lm) + wt(nn)*conjg(ylm(lm))*ylm(lm)\n s3(lm) = s3(lm) + wt(nn)*conjg(ylm(lmmax))*ylm(lm)\n ENDDO\n ENDDO\n\n!---> check for non-zero elements\n lerr = .false.\n DO lm=1,lmmax\n IF ((abs(s1(lm)).GT.del).AND.(lm.GT.1)) THEN\n WRITE (oUnit,1000) lm,s1(lm)\n lerr = .true.\n ENDIF\n 1000 FORMAT (20x,' integration of s.h. lm=',i3,1p,2e14.6)\n\n temp = s2(lm) - cmplx(1.0,0.0)\n IF (abs(temp).GT.del) THEN\n WRITE (oUnit,1001) lm,temp\n lerr = .true.\n ENDIF\n 1001 FORMAT (20x,' normalization error lm=',i3,1p,2e14.6)\n\n IF (abs(s3(lm)).GT.del) THEN\n IF(lm.ne.lmmax) THEN\n WRITE (oUnit,1002) lm,s3(lm)\n lerr = .true.\n ELSEIF( abs(abs(s3(lm))-1.0).GT.del ) THEN\n WRITE (oUnit,1002) lm,s3(lm)\n lerr = .true.\n ENDIF\n ENDIF\n 1002 FORMAT (20x,' (ylm(lmax,lmax) | ylm) lm=',i3,1p,2e14.6)\n ENDDO\n\n IF (lerr) THEN\n WRITE (oUnit,'(/,'' error in gaussian points'')')\n CALL juDFT_error(\"Error in gaussian points\",calledby=\"gtest\")\n ENDIF\n\n RETURN\n END SUBROUTINE gtest\n END MODULE m_gtest\n", "meta": {"hexsha": "cd0e0d6a1cef9e32ee4de5f20295de40a663d704", "size": 2398, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "init/gtest.f", "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": "init/gtest.f", "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": "init/gtest.f", "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": 29.243902439, "max_line_length": 79, "alphanum_fraction": 0.4708090075, "num_tokens": 822, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096204605946, "lm_q2_score": 0.7248702642896702, "lm_q1q2_score": 0.6640606227015806}} {"text": "!\n! wavy - A spectral ocean wave modeling and development framework\n! Copyright (c) 2017, Wavebit Scientific LLC\n! All rights reserved.\n!\n! Licensed under the BSD-3 clause license. See LICENSE for details.\n\nmodule mod_spectral_shapes\n\nuse mod_precision,only:ik => intkind,rk => realkind\nuse mod_const,only:twopi\nuse mod_nondimensional,only:nondimensionalFetch,nondimensionalFrequency\n\nimplicit none\n\nprivate\n\npublic :: donelanHamiltonHui\npublic :: donelanHamiltonHuiDirectionalSpreading\npublic :: donelanHamiltonHuiDirectionalSpectrum\npublic :: jonswap\npublic :: jonswapPeakFrequency\npublic :: piersonMoskowitz\npublic :: piersonMoskowitzPeakFrequency\npublic :: phillips\n\n!===============================================================================\ncontains\n\n\n\n!-------------------------------------------------------------------------------\npure elemental real(kind=rk) function donelanHamiltonHui(f,fpeak,wspd,grav)&\n result(spec)\n\n !! The omnidirectional spectrum function based on the laboratory and field\n !! measurements by Donelan, Hamilton, and Hui (1985).\n !!\n !! References:\n !!\n !! Donelan, M. A., J. Hamilton, and W. H. Hui, 1985. Directional\n !! spectra of wind-generated waves. Phil. Trans. Royal Soc. London A.,\n !! 315, 509-562.\n\n real(kind=rk),intent(in) :: f !! Frequency [Hz]\n real(kind=rk),intent(in) :: fpeak !! Peak frequency [Hz]\n real(kind=rk),intent(in) :: wspd !! Wind speed at 10 m height [m/s]\n real(kind=rk),intent(in) :: grav !! Gravitational acceleration [m/s^2]\n\n real(kind=rk) :: beta\n real(kind=rk) :: gamma ! Peak enhancement factor\n real(kind=rk) :: nu ! Nondimensional frequency\n real(kind=rk) :: r ! Exponent in peak enhancement factor\n real(kind=rk) :: omega ! Radian frequency [rad/s]\n real(kind=rk) :: sigma ! Spread of the spectrum peak\n\n omega = twopi*f\n nu = nondimensionalFrequency(wspd,fpeak,grav)\n if(nu >= 0.159_rk)then\n gamma = 6.489_rk + 6*log10(nu)\n if(gamma < 0)gamma = 0\n else\n gamma = 1.7_rk\n endif\n sigma = 0.08_rk + 1.29e-3_rk*nu**(-3)\n r = exp(-0.5_rk*((f-fpeak)/(sigma*fpeak))**2)\n beta = 0.0165_rk*nu**0.55_rk\n spec = twopi*beta*grav**2/omega**4/fpeak*exp(-(fpeak/f)**4)*gamma**r\n\nendfunction donelanHamiltonHui\n!-------------------------------------------------------------------------------\n\n\n\n!-------------------------------------------------------------------------------\npure elemental real(kind=rk) function donelanHamiltonHuiDirectionalSpreading(f,&\n wspd,fpeak,theta,theta_mean) result(spreading)\n\n !! Directional spreading function based on the laboratory and field\n !! measurements by Donelan, Hamilton, and Hui (1985). Includes the\n !! high-frequency form for beta_s found by Banner (1990).\n !!\n !! References:\n !!\n !! Donelan, M. A., J. Hamilton, and W. H. Hui, 1985. Directional\n !! spectra of wind-generated waves. *Phil. Trans. Royal Soc. London A.*,\n !! **315**, 509-562.\n !!\n !! Banner, M. L., 1990. Equilibrium spectra of wind waves. *J. Phys. \n !! Oceanogr.*, **20**, 966-984.\n\n real(kind=rk),intent(in) :: f !! Frequency [Hz]\n real(kind=rk),intent(in) :: wspd !! Wind speed at 10 m height [m/s]\n real(kind=rk),intent(in) :: fpeak !! Peak frequency [Hz]\n real(kind=rk),intent(in) :: theta !! Wave direction [rad]\n real(kind=rk),intent(in) :: theta_mean !! Mean wave direction [rad]\n\n real(kind=rk) :: frel ! Frequency relative to peak frequency, f/fpeak\n real(kind=rk) :: nu ! Nondimensional frequency\n real(kind=rk) :: beta\n\n frel = f/fpeak\n\n if(frel < 0.56_rk)then\n beta = 1.24_rk\n elseif(frel >= 0.56_rk .and. frel < 0.95_rk)then\n beta = 2.61_rk*frel**1.3_rk\n elseif(frel >= 0.95_rk .and. frel < 1.6_rk)then\n beta = 2.28_rk*frel**(-1.3_rk)\n else\n beta = 10**(-0.4_rk+0.8393_rk*exp(-0.567_rk*log(frel**2)))\n endif\n\n spreading = 0.5_rk*beta/cosh(beta*(theta-theta_mean))**2\n\nendfunction donelanHamiltonHuiDirectionalSpreading\n!-------------------------------------------------------------------------------\n\n\n\n!-------------------------------------------------------------------------------\npure function donelanHamiltonHuiDirectionalSpectrum(f,theta,wspd,fpeak,&\n theta_mean,grav) result(spec)\n\n !! Returns directional frequency spectrum based on the laboratory and field\n !! measurements by Donelan, Hamilton, and Hui (1985). Includes the high\n !! frequency form for beta_s found by Banner (1990). This function invokes the\n !! DHH omnidirectional spectrum and the directional spreading functions to\n !! compute directional frequency spectrum:\n !!\n !! $$\n !! F(f,\\theta) = F'(f) * D(f,\\theta)\n !! $$\n !!\n !! References:\n !!\n !! Donelan, M. A., J. Hamilton, and W. H. Hui, 1985. Directional\n !! spectra of wind-generated waves. Phil. Trans. Royal Soc. London A.,\n !! 315, 509-562.\n !!\n !! Banner, M. L., 1990. Equilibrium spectra of wind waves. J. Phys. Oceanogr.,\n !! 20, 966-984.\n\n real(kind=rk),dimension(:),intent(in) :: f !! Frequency [Hz]\n real(kind=rk),dimension(:),intent(in) :: theta !! Wave direction [rad]\n real(kind=rk),intent(in) :: wspd !! Wind speed at 10 m height [m/s]\n real(kind=rk),intent(in) :: fpeak !! Peak frequency [Hz]\n real(kind=rk),intent(in) :: theta_mean !! Mean wave direction [rad]\n real(kind=rk),intent(in) :: grav !! Gravitational acceleration [m/s^2]\n\n real(kind=rk),dimension(:,:),allocatable :: spec\n\n integer(kind=ik) :: ndir\n\n allocate(spec(size(f),size(theta)))\n\n do concurrent(ndir = 1:size(theta))\n spec(:,ndir) = donelanHamiltonHui(f,fpeak,wspd,grav)&\n * donelanHamiltonHuiDirectionalSpreading(f,wspd,fpeak,theta(ndir),&\n theta_mean)\n enddo\n\nendfunction donelanHamiltonHuiDirectionalSpectrum\n!-------------------------------------------------------------------------------\n\n\n\n!-------------------------------------------------------------------------------\npure elemental real(kind=rk) function jonswap(f,wspd,fetch,grav) result(spec)\n\n !! Computes the JONSWAP equilibrium spectrum (Hasselmann et al. 1973) based on\n !! input wind speed at the height of 10 m and fetch.\n !!\n !! References:\n !!\n !! Hasselmann, K. et al., 1973. Measurements of wind-wave growth and swell\n !! decay during the Joint North Sea Wave Project (JONSWAP). Dtsch. Hydrogh.\n !! Z., Suppl. A, 8, 12, 95pp.\n\n real(kind=rk),intent(in) :: f !! Frequency [Hz]\n real(kind=rk),intent(in) :: wspd !! Wind speed at 10 m height [m/s]\n real(kind=rk),intent(in) :: fetch !! Fetch [m]\n real(kind=rk),intent(in) :: grav !! Gravitational acceleration [m/s^2]\n\n real(kind=rk) :: alpha ! Phillips' constant\n real(kind=rk) :: sigma ! Spread of the spectrum peak\n real(kind=rk) :: r ! Exponent in peak enhancement factor\n\n real(kind=rk) :: fpeak ! Peak frequency [Hz]\n real(kind=rk) :: omega ! Radian frequency [rad/s]\n\n real(kind=rk),parameter :: beta = -1.25_rk\n real(kind=rk),parameter :: gamma = 3.3_rk ! peak enhancement\n\n omega = twopi*f\n alpha = 0.076_rk*nondimensionalFetch(wspd,fetch,grav)**(-0.22_rk)\n fpeak = jonswapPeakFrequency(wspd,fetch,grav)\n if(f > fpeak)then\n sigma = 0.09_rk\n else\n sigma = 0.07_rk\n endif\n r = exp(-0.5_rk*((f-fpeak)/(sigma*fpeak))**2)\n spec = twopi*alpha*grav**2/omega**5*exp(beta*(fpeak/f)**4)*gamma**r\n\nendfunction jonswap\n!-------------------------------------------------------------------------------\n\n\n\n!-------------------------------------------------------------------------------\npure elemental real(kind=rk) function jonswapPeakFrequency(wspd,fetch,grav)&\n result(fpeak)\n\n !! Computes the JONSWAP equilibrium peak frequency [Hz] on the input\n !! based on the 10-m wind speed and fetch [km] (Hasselmann et al., 1973).\n !!\n !! References:\n !!\n !! Hasselmann, K. et al., 1973. Measurements of wind-wave growth and swell\n !! decay during the Joint North Sea Wave Project (JONSWAP). Dtsch. Hydrogh.\n !! Z., Suppl. A, 8, 12, 95pp.\n\n real(kind=rk),intent(in) :: wspd !! Wind speed at 10 m height [m/s]\n real(kind=rk),intent(in) :: fetch !! Fetch [m]\n real(kind=rk),intent(in) :: grav !! Gravitational acceleration [m/s^2]\n\n real(kind=rk),parameter :: a = 3.5_rk\n real(kind=rk),parameter :: b = 1._rk/3._rk\n\n fpeak = a*(grav**2/(wspd*fetch))**b\n\nendfunction jonswapPeakFrequency\n!-------------------------------------------------------------------------------\n\n\n\n!-------------------------------------------------------------------------------\npure elemental real(kind=rk) function phillips(f,fpeak,grav) result(spec)\n\n !! Computes the Phillips (1958) equilibrium spectrum based on the input\n !! peak frequency [Hz].\n !!\n !! References:\n !!\n !! Phillips, O.M., 1958. The equilibrium range in the spectrum of\n !! wind-generated waves. J. Fluid Mech., 4, 426\u2013434.\n !! doi:10.1017/S0022112058000550.\n\n real(kind=rk),intent(in) :: f !! Frequency [Hz]\n real(kind=rk),intent(in) :: fpeak !! Peak frequency [Hz]\n real(kind=rk),intent(in) :: grav !! Gravitational acceleration [m/s^2]\n\n real(kind=rk),parameter :: alpha = 8.13e-3 !! Phillips' parameter\n\n if(f < fpeak)then\n spec = 0\n else\n spec = alpha*grav**2*(twopi*f)**(-5)\n endif\n\nendfunction phillips\n!-------------------------------------------------------------------------------\n\n\n\n!-------------------------------------------------------------------------------\npure elemental real(kind=rk) function piersonMoskowitz(f,wspd,grav) result(spec)\n\n !! Computes the Pierson-Moskowitz (1964) equilibrium spectrum based on input\n !! wind speed at the height of 10 m.\n !!\n !! References:\n !!\n !! Pierson Jr., W. J., and L. Moskowitz (1964), A proposed spectral form for\n !! fully developed wind seas based on the similarity theory of S. A.\n !! Kitaigorodskii, J. Geophys. Res., 69(24), 5181\u20135190,\n !! doi:10.1029/JZ069i024p05181.\n\n real(kind=rk),intent(in) :: f !! Frequency [Hz]\n real(kind=rk),intent(in) :: wspd !! Wind speed at 10 m height [m/s]\n real(kind=rk),intent(in) :: grav !! Gravitational acceleration [m/s^2]\n\n real(kind=rk) :: omega\n real(kind=rk) :: fpeak\n\n real(kind=rk),parameter :: alpha = 8.1e-3_rk ! Phillips' constant\n real(kind=rk),parameter :: beta = -1.25_rk\n\n omega = twopi*f\n fpeak = piersonMoskowitzPeakFrequency(wspd,grav)\n spec = twopi*alpha*grav**2/omega**5*exp(beta*(fpeak/f)**4)\n\nendfunction piersonMoskowitz\n!-------------------------------------------------------------------------------\n\n\n\n!-------------------------------------------------------------------------------\npure elemental real(kind=rk) function piersonMoskowitzPeakFrequency(wspd,grav)&\n result(fpeak)\n\n !! Computes the Pierson-Moskowitz (1964) peak frequency based on input wind\n !! speed at the height of 10 m.\n !!\n !! References:\n !!\n !! Pierson Jr., W. J., and L. Moskowitz (1964), A proposed spectral form for\n !! fully developed wind seas based on the similarity theory of S. A.\n !! Kitaigorodskii, J. Geophys. Res., 69(24), 5181\u20135190,\n !! doi:10.1029/JZ069i024p05181.\n\n real(kind=rk),intent(in) :: wspd !! Wind speed at 10 m height [m/s]\n real(kind=rk),intent(in) :: grav !! Gravitational acceleration [m/s^2]\n real(kind=rk),parameter :: const = 0.1325_rk\n\n fpeak = const*grav/max(wspd,1e-2_rk)\n\nendfunction piersonMoskowitzPeakFrequency\n!-------------------------------------------------------------------------------\nendmodule mod_spectral_shapes\n", "meta": {"hexsha": "277b7674c418fad0cf0efaeace56531591b93109", "size": 11285, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/lib/mod_spectral_shapes.f90", "max_stars_repo_name": "dksasaki/wavy", "max_stars_repo_head_hexsha": "95242818fca6d09f1e15e641dc9b978b5793eee5", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2017-06-20T19:00:02.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-04T13:19:30.000Z", "max_issues_repo_path": "src/lib/mod_spectral_shapes.f90", "max_issues_repo_name": "dksasaki/wavy", "max_issues_repo_head_hexsha": "95242818fca6d09f1e15e641dc9b978b5793eee5", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2017-06-22T15:23:31.000Z", "max_issues_repo_issues_event_max_datetime": "2019-11-21T21:10:35.000Z", "max_forks_repo_path": "src/lib/mod_spectral_shapes.f90", "max_forks_repo_name": "dksasaki/wavy", "max_forks_repo_head_hexsha": "95242818fca6d09f1e15e641dc9b978b5793eee5", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2017-10-27T13:28:27.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-06T15:01:08.000Z", "avg_line_length": 35.0465838509, "max_line_length": 80, "alphanum_fraction": 0.5970757643, "num_tokens": 3235, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096067182449, "lm_q2_score": 0.7248702702332475, "lm_q1q2_score": 0.6640606181851283}} {"text": "PROGRAM CONVERT_TEMP\n IMPLICIT NONE\n REAL centigrade, fahrenheit\n PRINT *, \"Enter the temprature in centigrade\"\n READ *, centigrade\n ! Perform the calculation\n fahrenheit = (centigrade*9.0 / 5.0) + 32.0\n PRINT *, \" Fahrenheit temprature is : \", fahrenheit\n PRINT *, 10**4 ! \n STOP\nEND", "meta": {"hexsha": "898d27d8c83b200e792b37b6d4a02c423271668a", "size": 311, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Learning FORTRAN Concepts/4.f90", "max_stars_repo_name": "arpitkekri/Code_With_FORTRAN", "max_stars_repo_head_hexsha": "fb731e6f8d8a47cfe38896fffd74a55d17efb2e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-02-21T05:24:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-27T10:25:24.000Z", "max_issues_repo_path": "Learning FORTRAN Concepts/4.f90", "max_issues_repo_name": "akhil18soni/Code_With_FORTRAN", "max_issues_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Learning FORTRAN Concepts/4.f90", "max_forks_repo_name": "akhil18soni/Code_With_FORTRAN", "max_forks_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-02-27T12:14:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T23:30:55.000Z", "avg_line_length": 28.2727272727, "max_line_length": 55, "alphanum_fraction": 0.6559485531, "num_tokens": 96, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916029436189, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.6640174232464859}} {"text": "c # --------------------------------------------------------------- \n double precision function q0_physical(xp,yp,zp)\n implicit none\n\n double precision xp, yp, zp\n\n double precision x0, y0, z0, q0, r0, r\n double precision xpp, ypp\n double precision Hsmooth\n\nc # Sphere centered at (0.5,0.5,0) on swirl\n x0 = 0.5\n y0 = 0.5\n z0 = 0\n r0 = 0.2 !! radius of sphere\n\nc # modulo(A,P) = A - floor(A/P)*P\nc write(6,*) 'mod(6.1,1.d0) ', modulo(6.1d0,1.d0)\nc write(6,*) 'mod(0.5,1.d0) ', modulo(0.5d0,1.d0)\nc write(6,*) 'mod(-0.5,1.d0) ', modulo(-0.5d0,1.d0)\nc write(6,*) 'mod(-1.3,1.d0) ', modulo(-1.3d0,1.d0)\nc write(6,*) ' '\nc write(6,*) 'mod(6.1,1.d0) ', 6.1d0 - floor(6.1d0)\nc write(6,*) 'mod(0.5,1.d0) ', 0.5d0 - floor(0.5d0)\nc write(6,*) 'mod(-0.5,1.d0) ', -0.5d0 - floor(-0.5d0)\nc write(6,*) 'mod(-1.3,1.d0) ', -1.3d0 - floor(-1.3d0)\nc stop\n\n xpp = modulo(xp,1.d0)\n ypp = modulo(yp,1.d0)\n\n\n r = sqrt((xpp - x0)**2 + (ypp-y0)**2)\n q0 = Hsmooth(r + r0) - Hsmooth(r - r0)\n\n q0_physical = q0\n\n end\n\nc # --------------------------------------------------------------- \n double precision function Hsmooth(r)\n implicit none\n\n double precision r\n\n Hsmooth = (tanh(r/0.02d0) + 1)/2.d0\n\n end\n\n\n\n", "meta": {"hexsha": "b4eeb2f82898df6f4fa2c05ed14edf418ae1f9eb", "size": 1369, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "applications/clawpack/transport/2d/square/q0.f", "max_stars_repo_name": "scivision/forestclaw", "max_stars_repo_head_hexsha": "4dae847a8abd1055e70acda9c2973cd3dd77d3f1", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "applications/clawpack/transport/2d/square/q0.f", "max_issues_repo_name": "scivision/forestclaw", "max_issues_repo_head_hexsha": "4dae847a8abd1055e70acda9c2973cd3dd77d3f1", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "applications/clawpack/transport/2d/square/q0.f", "max_forks_repo_name": "scivision/forestclaw", "max_forks_repo_head_hexsha": "4dae847a8abd1055e70acda9c2973cd3dd77d3f1", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.3269230769, "max_line_length": 77, "alphanum_fraction": 0.4543462381, "num_tokens": 545, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.7690802264851919, "lm_q1q2_score": 0.6640174203508078}} {"text": " program bucle_simultaneo\n implicit none \n real, parameter :: pi =3.14159265\n integer, parameter :: n=10\n real :: resultado_sin(n)\n integer :: i\n do concurrent (i=1:n) !Cuidado la sintaxis es ligeramente diferente\n resultado_sin(i)=sin(i*pi/4.)\n end do\n print *, resultado_sin\n end program bucle_simultaneo\n", "meta": {"hexsha": "8caeb2d07707e51ec5a29c0e5cb70681249c1207", "size": 383, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Programas/bucle_simultaneo.f90", "max_stars_repo_name": "Marc-xyz/InicioRapidoEnFortran", "max_stars_repo_head_hexsha": "8cfe017877061bbfbb2bef66e16c2afc9375243d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-25T22:00:53.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-25T22:00:53.000Z", "max_issues_repo_path": "Programas/bucle_simultaneo.f90", "max_issues_repo_name": "Marc-xyz/InicioRapidoEnFortran", "max_issues_repo_head_hexsha": "8cfe017877061bbfbb2bef66e16c2afc9375243d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Programas/bucle_simultaneo.f90", "max_forks_repo_name": "Marc-xyz/InicioRapidoEnFortran", "max_forks_repo_head_hexsha": "8cfe017877061bbfbb2bef66e16c2afc9375243d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.9166666667, "max_line_length": 76, "alphanum_fraction": 0.5953002611, "num_tokens": 101, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737806, "lm_q2_score": 0.7690802264851919, "lm_q1q2_score": 0.6640174149440496}} {"text": "! =============================================================================\n! Test trilinear interpolation\n!\n! This unit test checks the trilinear interpolation par2grid\n! =============================================================================\nprogram test_trilinear\n use unit_test\n use constants, only : pi, zero, one, f12, f23, f32\n use parcel_container\n use parcel_interpl, only : par2grid, par2grid_timer\n use parcel_ellipsoid, only : get_abc\n use parameters, only : lower, update_parameters, vcell, dx, nx, ny, nz, ngrid\n use fields, only : volg, field_alloc\n use timer\n implicit none\n\n double precision :: error\n integer :: ix, iy, iz, i, j, k, l, n_per_dim\n double precision :: im, corner(3)\n\n nx = 32\n ny = 32\n nz = 32\n lower = (/-f32, -f32, -f32/)\n extent = (/0.4d0, 0.4d0, 0.4d0/)\n\n call register_timer('par2grid', par2grid_timer)\n\n call update_parameters\n\n call field_alloc\n\n n_per_dim = 3\n\n n_parcels = n_per_dim ** 3 * nx *ny *nz\n call parcel_alloc(n_parcels)\n\n\n im = one / dble(n_per_dim)\n\n l = 1\n do iz = 0, nz-1\n do iy = 0, ny-1\n do ix = 0, nx-1\n corner = lower + dble((/ix, iy, iz/)) * dx\n do k = 1, n_per_dim\n do j = 1, n_per_dim\n do i = 1, n_per_dim\n parcels%position(1, l) = corner(1) + dx(1) * (dble(i) - f12) * im\n parcels%position(2, l) = corner(2) + dx(2) * (dble(j) - f12) * im\n parcels%position(3, l) = corner(3) + dx(3) * (dble(k) - f12) * im\n l = l + 1\n enddo\n enddo\n enddo\n enddo\n enddo\n enddo\n\n parcels%volume = vcell / dble(n_per_dim ** 3)\n\n parcels%B(:, :) = zero\n\n ! b11\n parcels%B(1, :) = get_abc(parcels%volume(1:n_parcels)) ** f23\n\n ! b22\n parcels%B(4, :) = parcels%B(1, :)\n\n call par2grid\n\n error = abs(sum(volg(0:nz, :, :)) - dble(ngrid) * vcell)\n\n call print_result_dp('Test trilinear (par2grid)', error, atol=dble(3.0e-14))\n\nend program test_trilinear\n", "meta": {"hexsha": "9ad1bf128b39c57f413e2fad9eca14f83ab382d8", "size": 2224, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "unit-tests/3d/test_trilinear.f90", "max_stars_repo_name": "matt-frey/epic", "max_stars_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2021-11-11T10:50:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T00:11:41.000Z", "max_issues_repo_path": "unit-tests/3d/test_trilinear.f90", "max_issues_repo_name": "matt-frey/epic", "max_issues_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 47, "max_issues_repo_issues_event_min_datetime": "2021-11-12T17:09:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-24T16:50:58.000Z", "max_forks_repo_path": "unit-tests/3d/test_trilinear.f90", "max_forks_repo_name": "matt-frey/epic", "max_forks_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.8831168831, "max_line_length": 93, "alphanum_fraction": 0.4842625899, "num_tokens": 666, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391602943619, "lm_q2_score": 0.7690802317779601, "lm_q1q2_score": 0.6640174141070231}} {"text": "! Recursive Fortran 95 quicksort routine\n! sorts real numbers into ascending numerical order\n! Author: Juli Rew, SCD Consulting (juliana@ucar.edu), 9/03\n! Based on algorithm from Thomas H. Cormen, Charles E. Leiserson, Ronald L.\n! Rivest, and Clifford Stein, Introduction to Algorithms, The MIT Press, 1997 edition.\n\n! Made F conformant by Walt Brainerd\n\n! Modified by Giulio Fella (02/2013) to sort the array index accordingly \n\n! Contains the component subroutines: Partition, QsortC\n\nMODULE mod_gf_qsort\n IMPLICIT NONE\n PUBLIC :: QsortC\n PRIVATE :: Partition\n\n ! Set kind of real arrays\n INTEGER, PARAMETER :: ki=SELECTED_REAL_KIND(p = 15, r = 30)\n\nCONTAINS\n\n RECURSIVE SUBROUTINE QsortC(A, index_A)\n ! Input/output variables\n ! A \t: real(precision) array to sort\n ! index_A : integer array indexing elements of A\n REAL(ki), INTENT(in out), DIMENSION(:) :: A\n INTEGER, INTENT(in out), DIMENSION(SIZE(A)) :: index_A\n INTEGER :: iq\n\n IF(SIZE(A) > 1) THEN\n CALL Partition(A,index_A, iq)\n CALL QsortC(A(:iq-1),index_A(:iq-1))\n CALL QsortC(A(iq:),index_A(iq:))\n ENDIF\n END SUBROUTINE QsortC\n\n SUBROUTINE Partition(A, index_A, marker)\n REAL(ki), INTENT(in out), DIMENSION(:) :: A\n INTEGER, INTENT(in out), DIMENSION(SIZE(A)) :: index_A\n INTEGER, INTENT(out) :: marker\n INTEGER :: i, j\n INTEGER :: index_temp\n REAL(ki) :: temp\n REAL(ki) :: x ! pivot point\n x = A(1)\n i= 0\n j= SIZE(A) + 1\n\n DO\n j = j-1\n DO\n IF (A(j) <= x) EXIT\n j = j-1\n END DO\n i = i+1\n DO\n IF (A(i) >= x) EXIT\n i = i+1\n END DO\n IF (i < j) THEN\n ! exchange A(i) and A(j)\n temp = A(i)\n A(i) = A(j)\n A(j) = temp\n\n index_temp = index_A(i)\n index_A(i) = index_A(j)\n index_A(j) = index_temp\n\n ELSEIF (i == j) THEN\n marker = i+1\n RETURN\n ELSE\n marker = i\n RETURN\n ENDIF\n END DO\n\n END SUBROUTINE Partition\n\nEND MODULE mod_gf_qsort\n\n\n", "meta": {"hexsha": "5f199667d8480f8a73d015dcbbbd6021b1ea2a1b", "size": 2038, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mod_gf_qsort.f90", "max_stars_repo_name": "gfell/gf_qsort", "max_stars_repo_head_hexsha": "ab2a4e34be880b0ff2643cd2ae61624bfda05b2e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "mod_gf_qsort.f90", "max_issues_repo_name": "gfell/gf_qsort", "max_issues_repo_head_hexsha": "ab2a4e34be880b0ff2643cd2ae61624bfda05b2e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-03-27T19:47:58.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-27T19:47:58.000Z", "max_forks_repo_path": "mod_gf_qsort.f90", "max_forks_repo_name": "gfell/gf_qsort", "max_forks_repo_head_hexsha": "ab2a4e34be880b0ff2643cd2ae61624bfda05b2e", "max_forks_repo_licenses": ["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.9764705882, "max_line_length": 86, "alphanum_fraction": 0.5981354269, "num_tokens": 644, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118111485244, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.663993265800702}} {"text": " program demo_maxval\n implicit none\n integer,save :: ints(3,5)= reshape([&\n 1, 2, 3, 4, 5, &\n 10, 20, 30, 40, 50, &\n 11, 22, 33, 44, 55 &\n ],shape(ints),order=[2,1])\n\n write(*,*) maxval(ints)\n write(*,*) maxval(ints,dim=1)\n write(*,*) maxval(ints,dim=2)\n ! find biggest number less than 30 with mask\n write(*,*) maxval(ints,mask=ints.lt.30)\n end program demo_maxval\n", "meta": {"hexsha": "97ce43f8526626544e4cf4f3b7153e0f9e3d70a1", "size": 432, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/maxval.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/maxval.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/maxval.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": 28.8, "max_line_length": 51, "alphanum_fraction": 0.5347222222, "num_tokens": 163, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8267118026095991, "lm_q2_score": 0.803173801068221, "lm_q1q2_score": 0.6639932608899125}} {"text": "PROGRAM square_roots\r\n \r\nIMPLICIT NONE\r\n \r\nINTEGER :: i\r\nREAL, DIMENSION(10) :: value = (/ (i, i=1,10) /) \r\nREAL, DIMENSION(10) :: square_root\r\n\r\n! Calculate the square roots of the numbers.\r\nDO i = 1, 10\r\n square_root(i) = SQRT(value(i))\r\nEND DO\r\n\r\n! Write out each number and its square root.\r\nDO i = 1, 10\r\n WRITE (*,100) value(i), square_root(i)\r\n 100 FORMAT (1X,'Value = ',F5.1,' Square Root = ',F10.4)\r\nEND DO\r\n\r\nEND PROGRAM square_roots\r\n", "meta": {"hexsha": "a03a86534bb587fea40bc6a1d2f26dad63199b53", "size": 452, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap6/square_roots.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/chap6/square_roots.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/chap6/square_roots.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": 21.5238095238, "max_line_length": 60, "alphanum_fraction": 0.6283185841, "num_tokens": 148, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569016, "lm_q2_score": 0.8267118026095991, "lm_q1q2_score": 0.6639932569950091}} {"text": "\nmodule functions\n\n implicit none\n integer :: gevals\n save\n\ncontains\n\n function g(x,ndim)\n\n implicit none\n integer, intent(in) :: ndim\n real(kind=8), intent(in) :: x(ndim)\n real(kind=8) :: g\n integer :: i\n\n g = 0.d0\n do i=1,ndim\n g = g + x(i)**2\n enddo\n\n gevals = gevals + 1\n\n end function g\n\nend module functions\n", "meta": {"hexsha": "8eb7351e821db839779b5f3020f276909d077f08", "size": 367, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/2013/solutions/project/part2/functions.f90", "max_stars_repo_name": "philipwangdk/HPC", "max_stars_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "uwhpsc/2013/solutions/project/part2/functions.f90", "max_issues_repo_name": "philipwangdk/HPC", "max_issues_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "uwhpsc/2013/solutions/project/part2/functions.f90", "max_forks_repo_name": "philipwangdk/HPC", "max_forks_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 13.1071428571, "max_line_length": 39, "alphanum_fraction": 0.5504087193, "num_tokens": 119, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.826711776992821, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.6639932383677358}} {"text": "!*****************************************************************************************\n!> author: Jacob Williams\n! date: 12/6/2015\n!\n! Tests for different knot vectors.\n!\n! This requires [pyplot_module](https://github.com/jacobwilliams/pyplot-fortran)\n!\n!### Results\n! ![Plot of results](https://raw.githubusercontent.com/jacobwilliams/bspline-fortran/master/src/tests/results/knot_tests.png)\n\n program knot_tests\n\n use bspline_module\n use bspline_kinds_module, only: wp, ip\n use pyplot_module\n use, intrinsic :: iso_fortran_env\n\n implicit none\n\n integer :: i !! counter\n\n integer(ip),parameter :: kx = 4 !! x bspline order\n integer(ip),parameter :: nx = 6 !! number of points in x dimension\n real(wp),dimension(nx),parameter :: x = [(real(i*10,wp), i=0,11,(10+2)/nx)] !! [0,20,40,60,80,100]\n\n real(wp),dimension(nx) :: fcn\n real(wp),dimension(nx+kx) :: tx\n type(bspline_1d) :: s_default, s1, s2\n real(wp),dimension(0:100) :: x_new,f_new_default,f1,f2 !,f_actual\n real(wp) :: xval\n type(pyplot) :: plt\n integer(ip) :: iflag\n integer :: istat !! pyplot-fortran status flag\n\n !function evaluations for original grid:\n do i=1,nx\n fcn(i) = test_func(x(i))\n end do\n\n !initialize the plot:\n call plt%initialize(grid=.true.,xlabel='x',ylabel='f(x)',&\n title='Knot Test',legend=.true.)\n call plt%add_plot(real(x,real64),real(fcn,real64),&\n label='Function $f(x) = \\sin(x \\cdot \\pi/18)$ : $x=[0,20,40,60,80,100]$',&\n linestyle='ko--',markersize=5,linewidth=2,istat=istat)\n\n !initialize three with different knot sequences:\n\n ! x = [ 0, 20,40,60,80,100 ] (x points)\n ! t = [ 0,0,0,0, 40,60, 101,101,101,101 ] (tx for not a knot conditions)\n\n call s_default%initialize(x,fcn,kx,iflag) !default (not-a-knot)\n if (iflag/=0) error stop 'error initializing s_default'\n\n !user-specified knots:\n\n tx = real([0,0,0,0,20,40,101,101,101,101], wp)\n call s1%initialize(x,fcn,kx,tx,iflag)\n if (iflag/=0) error stop 'error initializing s1'\n\n tx = real([0,0,0,0,60,80,101,101,101,101], wp)\n call s2%initialize(x,fcn,kx,tx,iflag)\n if (iflag/=0) error stop 'error initializing s2'\n\n do i = 0,100\n\n xval = real(i,wp)\n x_new(i) = xval\n\n !f_actual(i) = test_func(xval)\n\n call s_default%evaluate(xval,0_ip,f_new_default(i),iflag)\n if (iflag/=0) error stop 'error evaluating s_default'\n\n call s1%evaluate(xval,0_ip,f1(i),iflag)\n if (iflag/=0) error stop 'error evaluating s1'\n\n call s2%evaluate(xval,0_ip,f2(i),iflag)\n if (iflag/=0) error stop 'error evaluating s2'\n\n end do\n\n !call plt%add_plot(x_new,f_actual,label='Actual function',linestyle='k--',linewidth=2)\n\n call plt%add_plot(real(x_new,real64),real(f_new_default,real64),&\n label='Interpolated : $t_x=[0,0,0,0,40,60,102,102,102,102]$ (Default)',&\n linestyle='b-',linewidth=1,istat=istat)\n call plt%add_plot(real(x_new,real64),real(f1,real64),&\n label='Interpolated : $t_x=[0,0,0,0,20,40,101,101,101,101]$',&\n linestyle='r-',linewidth=1,istat=istat)\n call plt%add_plot(real(x_new,real64),real(f2,real64),&\n label='Interpolated : $t_x=[0,0,0,0,60,80,101,101,101,101]$',&\n linestyle='g-',linewidth=1,istat=istat)\n\n !plot the results:\n call plt%savefig('knot_tests.png',istat=istat)\n\n contains\n\n pure function test_func(x) result(f)\n !! 1d test function\n\n implicit none\n\n real(wp) :: f\n real(wp),intent(in) :: x\n\n real(wp),parameter :: a = acos(-1.0_wp)/18.0_wp\n\n f = sin(a*x)\n\n end function test_func\n\n end program knot_tests\n", "meta": {"hexsha": "bf1a7a5fdc0d7f89cc0a309bd984cc00b889c8f7", "size": 3878, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/knot_tests.f90", "max_stars_repo_name": "jacobwilliams/bspline-fortran", "max_stars_repo_head_hexsha": "5c0f836e0043e51d86420f321f607ff8ae21ca98", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 139, "max_stars_repo_stars_event_min_datetime": "2015-02-25T08:11:20.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T17:33:50.000Z", "max_issues_repo_path": "src/tests/knot_tests.f90", "max_issues_repo_name": "jacobwilliams/bspline-fortran", "max_issues_repo_head_hexsha": "5c0f836e0043e51d86420f321f607ff8ae21ca98", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 46, "max_issues_repo_issues_event_min_datetime": "2015-06-19T18:25:15.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T21:14:15.000Z", "max_forks_repo_path": "src/tests/knot_tests.f90", "max_forks_repo_name": "jacobwilliams/bspline-fortran", "max_forks_repo_head_hexsha": "5c0f836e0043e51d86420f321f607ff8ae21ca98", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 51, "max_forks_repo_forks_event_min_datetime": "2015-09-17T16:52:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-26T03:18:28.000Z", "avg_line_length": 33.4310344828, "max_line_length": 126, "alphanum_fraction": 0.5832903559, "num_tokens": 1212, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117769928211, "lm_q2_score": 0.8031737963569016, "lm_q1q2_score": 0.6639932364202843}} {"text": "\n !-------------------------------------------------------------------------------------------------------------\n !\n !> \\file CompExcessGibbsEnergySUBI.f90\n !> \\brief Compute the partial molar excess Gibbs energy of mixing of solution phase constituents in a\n !! SUBI solution phase.\n !> \\author M.H.A. Piro\n !> \\date January 19, 2021\n !> \\sa CompExcessGibbsEnergy.f90\n !> \\sa CompExcessGibbsEnergyRKMP.f90\n !> \\sa CompExcessGibbsEnergyQKTO.f90\n !\n !\n ! Revisions:\n ! ==========\n !\n ! Date Programmer Description of change\n ! ---- ---------- ---------------------\n ! 01/19/2021 M. Poschmann Original code\n !\n !\n ! Purpose:\n ! ========\n !\n !> \\details The purpose of this subroutine is to compute the partial molar excess Gibbs energy of mixing\n !! (dPartialExcessGibbs) of all constituents in a non-ideal solution phase designated as 'SUBI'\n !! (Ionic Liquid Model).\n !!\n !\n ! Pertinent variables:\n ! ====================\n !\n !> \\param[in] iSolnIndex Absolute index of a solution phase\n !\n ! nSpeciesPhase An integec vector representing the last index of a species in a particular\n ! solution phase\n ! nParamPhase An integer vector representing the number of parameters for a particular phase.\n ! nSublattice An integer scalar representing the number of sublattices associated with this\n ! particular phase (used for convenience).\n ! nSublatticePhase An integer vector representing the number of sublattices for each charged phase.\n ! iSPI An integer scalar representing the relative index of the charged phase.\n ! iParam An integer scalar representing the index number of a parameter.\n ! iPhaseSublattice An integer vector representing the relative index of a charged phase corresponding\n ! to each solution phase in the system. Thus, it is equal to zero for a phase\n ! that does not contain any sublattices.\n ! iRegularParam An integer matrix representing the relative indices of species mixing for a\n ! particular parmater.\n ! iFirst An integer scalar representing the absolute index of the first species in a phase.\n ! iLast An integer scalar representing the absolute index of the last species in a phase.\n ! dChemicalPotential A double real vector representing the chemical potential for every species in the\n ! system.\n ! dMolFraction A double real vector representing hte mole fraction of all species in the system.\n ! dSiteFraction A double real array representing the site fraction of each constituent on each\n ! sublattice. The first dimension corresponds to the charged phase index, the\n ! second dimension corresponds to the sublattice index and the third dimension\n ! corresponds to the constituent index.\n ! dExcessGibbsParam A double real vector representing the molar excess Gibbs energy of mixing for\n ! each subsystem.\n ! dPartialExcessGibbs Partial molar excess Gibbs energy of mixing of species.\n ! dMolFraction Current estimated mole fraction.\n ! cSolnPhaseType A character vector representing the solution phase type.\n ! iConstituentSublattice An integer array representing the constituent index for a particular sublattice\n ! phase. The first dimension refers to the relative phase index for charged phases,\n ! the second dimension represents the sublattice index and the third dimension\n ! corresponds to the relative component index (not absolute).\n ! iFirstParam An integer scalar representing the constituent index of the first constituent\n ! that is being mixed for a mixing parameter.\n ! iSeconParam An integer scalar representing the constituent index of the second constituent\n ! that is being mixed for a mixing parameter.\n ! iSubParam An integer scalar representing the sublattice index corresponding to the mixing\n ! parameter.\n !\n !-------------------------------------------------------------------------------------------------------------\n\n\nsubroutine CompExcessGibbsEnergySUBI(iSolnIndex)\n\n USE ModuleThermo\n USE ModuleThermoIO\n USE ModuleGEMSolver\n\n implicit none\n\n integer :: i, j, l, k1, l1, k2, l2, m, n, c, d, k, s\n integer :: iCi, iCj, iCk, iBi, iBj, iBk, iAi, iAj, iDi, iDj\n integer :: iSolnIndex, nSublattice, iSPI, iExponent\n integer :: iFirst, iLast, iExponentAdjust\n real(8) :: dSub1Total, dSub2Total, dydn\n real(8) :: dSum, p, q, kc1, kc2, lc1, lc2, cc1, gref, gideal, gexcess, natom, yva, dMol, dMolAtoms\n real(8), dimension(:), allocatable :: dgdc1, dgdc2, dMolDerivatives\n real(8) :: dPreFactor, v, f, chargeCi, chargeCj, chargeCk\n real(8) :: yCi, yCj, yCk, yAi, yAj, yBi, yBj, yBk, yDi, yDj, gex\n logical :: lEven\n\n ! Only proceed if the correct phase type is selected:\n IF_SUBL: if (cSolnPhaseType(iSolnIndex) == 'SUBI') then\n\n ! Define temporary variables for sake of convenience:\n iSPI = iPhaseSublattice(iSolnIndex)\n nSublattice = nSublatticePhase(iSPI)\n iFirst = nSpeciesPhase(iSolnIndex-1) + 1\n iLast = nSpeciesPhase(iSolnIndex)\n\n if (allocated(dgdc1)) deallocate(dgdc1)\n if (allocated(dgdc2)) deallocate(dgdc2)\n if (allocated(dMolDerivatives)) deallocate(dMolDerivatives)\n allocate(dgdc1(nConstituentSublattice(iSPI,1)),dgdc2(nConstituentSublattice(iSPI,2)))\n allocate(dMolDerivatives(iLast - iFirst + 1))\n\n ! Initialize variables:\n dSiteFraction(iSPI,1:nSublattice,1:nMaxConstituentSys) = 0D0\n dChemicalPotential(iFirst:iLast) = 0D0\n dPartialExcessGibbs(iFirst:iLast) = 0D0\n dgdc1 = 0D0\n dgdc2 = 0D0\n dMolDerivatives = 0D0\n\n ! Compute site fractions on first sublattice:\n do i = iFirst, iLast\n ! Relative component index:\n m = i - iFirst + 1\n c = iConstituentSublattice(iSPI,1,m)\n d = iConstituentSublattice(iSPI,2,m)\n\n if (cConstituentNameSUB(iSPI,2,d) == 'Va') then\n lc2 = 1D0\n else\n lc2 = -dSublatticeCharge(iSPI,2,d)\n end if\n if (c > 0) then\n dSiteFraction(iSPI,1,c) = dSiteFraction(iSPI,1,c) + dMolFraction(i) * lc2\n end if\n end do\n\n ! Correct first site fraction\n dSub1Total = 0D0\n do i = 1, nConstituentSublattice(iSPI,1)\n dSub1Total = dSub1Total + dSiteFraction(iSPI,1,i)\n end do\n do i = 1, nConstituentSublattice(iSPI,1)\n dSiteFraction(iSPI,1,i) = dSiteFraction(iSPI,1,i) / dSub1Total\n end do\n\n ! Compute Q\n q = 0D0\n do i = 1, nConstituentSublattice(iSPI,1)\n q = q + dSublatticeCharge(iSPI,1,i) * dSiteFraction(iSPI,1,i)\n end do\n\n ! Compute site fractions on second sublattice:\n do i = iFirst, iLast\n ! Relative component index:\n m = i - iFirst + 1\n c = iConstituentSublattice(iSPI,2,m)\n if (cConstituentNameSUB(iSPI,2,c) == 'Va') then\n ! Vacancy gets scaled by Q\n d = iConstituentSublattice(iSPI,1,m)\n dSiteFraction(iSPI,2,c) = dSiteFraction(iSPI,2,c) + dMolFraction(i) * dSublatticeCharge(iSPI,1,d) / q\n else if (dSublatticeCharge(iSPI,2,c) == 0D0) then\n ! Neutral counts as 1\n dSiteFraction(iSPI,2,c) = dSiteFraction(iSPI,2,c) + dMolFraction(i)\n else\n d = iConstituentSublattice(iSPI,1,m)\n dSiteFraction(iSPI,2,c) = dSiteFraction(iSPI,2,c) + dMolFraction(i) * dSublatticeCharge(iSPI,1,d)\n end if\n end do\n\n ! Correct second site fraction\n dSub2Total = 0D0\n yva = 0D0\n do i = 1, nConstituentSublattice(iSPI,2)\n dSub2Total = dSub2Total + dSiteFraction(iSPI,2,i)\n end do\n do i = 1, nConstituentSublattice(iSPI,2)\n dSiteFraction(iSPI,2,i) = dSiteFraction(iSPI,2,i) / dSub2Total\n ! find site fraction of vacancies\n if (cConstituentNameSUB(iSPI,2,i) == 'Va') yva = dSiteFraction(iSPI,2,i)\n end do\n\n ! Compute P\n p = 0D0\n do i = 1, nConstituentSublattice(iSPI,2)\n if (cConstituentNameSUB(iSPI,2,i) == 'Va') then\n ! Use Q as charge if this constituent is vacancy\n p = p + q * dSiteFraction(iSPI,2,i)\n else\n p = p - dSublatticeCharge(iSPI,2,i) * dSiteFraction(iSPI,2,i)\n end if\n end do\n\n ! Compute number of moles and its derivatives\n dMol = (p + (q * (1D0 - yva)))\n do j = iFirst, iLast\n ! Relative species index:\n n = j - iFirst + 1\n\n ! Store constituent indices:\n l1 = iConstituentSublattice(iSPI,1,n)\n l2 = iConstituentSublattice(iSPI,2,n)\n\n ! Allocating the correct constituent charges\n if (l1 > 0) lc1 = dSublatticeCharge(iSPI,1,l1)\n lc2 = -dSublatticeCharge(iSPI,2,l2)\n\n if (cConstituentNameSUB(iSPI,2,l2) == 'Va') then\n ! cation / vacancy\n dMolDerivatives(n) = (q-lc1)*(1D0+(p-q*yva)*yva/q)/(dSub1Total*dMol**2)\n dMolDerivatives(n) = dMolDerivatives(n) + (p-q*yva)*lc1/(dSub2Total*q*dMol**2)\n else if (dSublatticeCharge(iSPI,2,l2) == 0D0) then\n ! neutral\n dMolDerivatives(n) = (p-q*yva)/(dSub2Total*dMol**2)\n else\n ! cation / anion\n dMolDerivatives(n) = (q-lc1)*(1D0+(p-q*yva)*yva/q)*lc2/(dSub1Total*dMol**2)\n dMolDerivatives(n) = dMolDerivatives(n) + (p-q*yva-lc2)*lc1/(dSub2Total*dMol**2)\n end if\n end do\n\n ! Correct the mole fractions of phase components by the site fractions of the constituents\n dSum = 0D0\n LOOP_CorrectX: do i = iFirst, iLast\n dMolFraction(i) = 1D0\n m = i - iFirst + 1\n\n c = iConstituentSublattice(iSPI,2,m)\n d = iConstituentSublattice(iSPI,1,m)\n\n if (cConstituentNameSUB(iSPI,2,c) == 'Va') then\n dMolFraction(i) = dMolFraction(i) * dSiteFraction(iSPI,1,d)\n dMolFraction(i) = dMolFraction(i) * dSiteFraction(iSPI,2,c) * q\n else if (dSublatticeCharge(iSPI,2,c) == 0D0) then\n dMolFraction(i) = dMolFraction(i) * dSiteFraction(iSPI,2,c) * q\n else\n dMolFraction(i) = dMolFraction(i) * dSiteFraction(iSPI,1,d)\n dMolFraction(i) = dMolFraction(i) * dSiteFraction(iSPI,2,c)\n end if\n dSum = dSum + dMolFraction(i)\n end do LOOP_CorrectX\n\n ! Normalize mole fractions and compute number of mole atoms per mole (yes that makes sense, don't think about it)\n dMolAtoms = 0D0\n do i = iFirst, iLast\n\n dMolFraction(i) = dMolFraction(i) / dSum\n\n m = i - iFirst + 1\n d = iConstituentSublattice(iSPI,1,m)\n c = iConstituentSublattice(iSPI,2,m)\n if ((cConstituentNameSUB(iSPI,2,c) == 'Va') .OR. &\n (dSublatticeCharge(iSPI,2,c) == 0D0)) then\n dMolAtoms = dMolAtoms + dMolFraction(i)\n else\n dMolAtoms = dMolAtoms + dMolFraction(i) * (dSublatticeCharge(iSPI,1,d) - dSublatticeCharge(iSPI,2,c))\n end if\n end do\n\n dStoichSublattice(iSPI,1) = p\n dStoichSublattice(iSPI,2) = q\n\n !---------------------------------------------------------------\n ! EXCESS TERMS - With Derived Excess Terms\n ! --------------------------------------------------------------\n gexcess = 0D0\n ! Loop through parameters:\n LOOP_Param: do l = nParamPhase(iSolnIndex-1) + 1, nParamPhase(iSolnIndex)\n ! Return control to the parent subroutine if there aren't any interaction parameters for this phase:\n if (nParamPhase(iSolnIndex) - nParamPhase(iSolnIndex-1) == 0) exit LOOP_Param\n\n ! Reinitialize temporary variable:\n dPreFactor = 1D0\n\n f = 0D0\n v = 0D0\n\n chargeCi = 0D0\n chargeCj = 0D0\n chargeCk = 0D0\n\n iAi = 0\n iAj = 0\n iBi = 0\n iBj = 0\n iBk = 0\n iCi = 0\n iCj = 0\n iCk = 0\n iDi = 0\n iDj = 0\n\n iExponentAdjust = 0\n\n yCi = 0D0\n yCj = 0D0\n yCk = 0D0\n yAi = 0D0\n yAj = 0D0\n yBi = 0D0\n yBj = 0D0\n yBk = 0D0\n yDi = 0D0\n yDj = 0D0\n\n gex = 0D0\n\n ! Store the number of constituents involved in this parameter:\n n = iRegularParam(l,1)\n\n ! Case 1: Determine the mixing parameter type: L_Ci,Cj:Ak\n if (iSUBIMixType(l) == 1) then\n\n ! Loop through constituents associated with this parameter:\n do k = 2, n + 1\n ! Determine constituent and sublattice indices:\n c = MOD(iRegularParam(l,k), 10000)\n s = iRegularParam(l,k) - c\n s = s / 10000\n\n ! Compute prefactor term:\n dPreFactor = dPreFactor * dSiteFraction(iSPI,s,c)\n\n ! Store the first and second site fractions:\n if (k == 2) then\n ! cation - Ci\n yCi = dSiteFraction(iSPI,s,c)\n iCi = c\n chargeCi = dSublatticeCharge(iSPI,s,c)\n\n else if (k == 3) then\n ! cation - Cj\n yCj = dSiteFraction(iSPI,s,c)\n iCj = c\n chargeCj = dSublatticeCharge(iSPI,s,c)\n\n else if (k == 4) then\n ! anion - Ak\n yAi = dSiteFraction(iSPI,s,c)\n iAi = c\n\n end if\n end do\n\n ! Multiply prefactor term by excess Gibbs energy parameter:\n iExponent = iRegularParam(l,n+2)\n ! Excess Gibbs energy equation for L_Ci,Cj:Ak case\n gex = dPreFactor * dExcessGibbsParam(l) * (yCi - yCj)**(iExponent)\n ! Total Excess Gibbs Energy\n gexcess = gexcess + gex\n\n ! Avoiding a situation with 0^(-1)\n if ((yCi - yCj) /= 0) then\n\n ! First sublattice - Cation:vacancy contributions\n do i = 1, nConstituentSublattice(iSPI,1)\n\n ! Derivative with respect to Ci\n if (i == iCi) then\n dgdc1(i) = dgdc1(i) + gex / yCi\n\n dgdc1(i) = dgdc1(i) + gex * iExponent / (yCi - yCj)\n\n ! Derivative with respect to Cj\n else if (i == iCj) then\n dgdc1(i) = dgdc1(i) + gex / yCj\n\n dgdc1(i) = dgdc1(i) + gex * iExponent * (-1) / (yCi - yCj)\n\n end if\n end do\n end if\n\n ! Second sublattice - Cation:vacancy contributions\n do i = 1, nConstituentSublattice(iSPI,2)\n if (i == iAi) then\n dgdc2(i) = dgdc2(i) + gex / yAi\n\n end if\n end do\n\n ! Case 2: Determine the mixing parameter type: L_Ci:Aj,Dk\n else if (iSUBIMixType(l) == 2) then\n ! Loop through constituents associated with this parameter:\n do k = 2, n + 1\n ! Determine constituent and sublattice indices:\n c = MOD(iRegularParam(l,k), 10000)\n s = iRegularParam(l,k) - c\n s = s / 10000\n\n ! Compute prefactor term:\n dPreFactor = dPreFactor * dSiteFraction(iSPI,s,c)\n\n ! Establishing the site fractions for the L_Ci:Aj,Dk cases\n if (k == 2) then\n ! cation - Ci\n yCi = dSiteFraction(iSPI,s,c)\n iCi = c\n else if (k == 3) then\n ! anion - Aj\n yAi = dSiteFraction(iSPI,s,c)\n iAi = c\n else if (k == 4) then\n ! Dl - anion, vacancy or neutral\n yDi = dSiteFraction(iSPI,s,c)\n iDi = c\n end if\n end do\n\n ! Multiply prefactor term by excess Gibbs energy parameter:\n iExponent = iRegularParam(l,n+2)\n ! Excess Gibbs energy equation for L_Ci:Aj,Dk case\n gex = dPreFactor * dExcessGibbsParam(l) * (yAi - yDi)**(iExponent)\n ! Total Excess Gibbs\n gexcess = gexcess + gex\n\n ! Derived Excess Equations for Mixing Case 1: L_Ci:Aj,Dk\n ! Chemical potential with respect to the first sublattice\n do i = 1, nConstituentSublattice(iSPI,1)\n if (i == iCi) then\n dgdc1(i) = dgdc1(i) + gex / yCi\n end if\n end do\n\n ! Avoiding a situation with 0^(-1)\n if ((yAi - yDi) /= 0D0) then\n ! Chemical potential with respect to the second sublattice\n do i = 1, nConstituentSublattice(iSPI,2)\n if (i == iAi) then\n ! cation / anion\n dgdc2(i) = dgdc2(i) + gex / yAi\n dgdc2(i) = dgdc2(i) + gex * iExponent / (yAi - yDi)\n else if (i == iDi) then\n ! Dl - anion, vacancy or neutral\n dgdc2(i) = dgdc2(i) + gex / yDi\n dgdc2(i) = dgdc2(i) + gex * iExponent * (-1) / (yAi - yDi)\n end if\n end do\n end if\n\n ! Case 3: Determine the mixing parameter type: L_Ci,Cj:Va\n else if (iSUBIMixType(l) == 3) then\n ! Loop through constituents associated with this parameter:\n do k = 2, n + 1\n ! Determine constituent and sublattice indices:\n c = MOD(iRegularParam(l,k), 10000)\n s = iRegularParam(l,k) - c\n s = s / 10000\n\n ! Store the first and second site fractions:\n if (k == 2) then\n ! cation - Ci\n yCi = dSiteFraction(iSPI,s,c)\n iCi = c\n chargeCi = dSublatticeCharge(iSPI,s,c)\n ! Compute prefactor term:\n dPreFactor = dPreFactor * dSiteFraction(iSPI,s,c)\n else if (k == 3) then\n ! cation - Cj\n yCj = dSiteFraction(iSPI,s,c)\n iCj = c\n chargeCj = dSublatticeCharge(iSPI,s,c)\n ! Compute prefactor term:\n dPreFactor = dPreFactor * dSiteFraction(iSPI,s,c)\n else if (k == 4) then\n ! Vacancy\n yva = dSiteFraction(iSPI,s,c)\n ! Compute prefactor term:\n dPreFactor = dPreFactor * dSiteFraction(iSPI,s,c)**2\n end if\n end do\n\n ! Multiply prefactor term by excess Gibbs energy parameter:\n iExponent = iRegularParam(l,n+2)\n ! Excess Gibbs energy equation for L_Ci,Cj:Va case\n gex = q * dPreFactor * dExcessGibbsParam(l) * (yCi - yCj)**(iExponent)\n ! Total Excess Gibbs Energy\n gexcess = gexcess + gex\n\n ! Derived Excess Equations for Mixing Case 2: L_Ci,Cj:Va\n ! Avoiding a situation with 0^(-1)\n if ((yCi - yCj) /= 0) then\n ! Chemical potential with respect to the first sublattice\n do i = 1, nConstituentSublattice(iSPI,1)\n\n ! Derivative with respect to Ci\n if (i == iCi) then\n dgdc1(i) = dgdc1(i) + gex / yCi\n dgdc1(i) = dgdc1(i) + gex * chargeCi / q\n dgdc1(i) = dgdc1(i) + gex * iExponent / (yCi - yCj)\n ! Derivative with respect to Cj\n else if (i == iCj) then\n dgdc1(i) = dgdc1(i) + gex / yCj\n dgdc1(i) = dgdc1(i) + gex * chargeCj / q\n dgdc1(i) = dgdc1(i) + gex * iExponent * (-1) / (yCi - yCj)\n else\n !&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n ! Not yet tested\n ! If there are additional cations that are not i or j\n dgdc1(i) = dgdc1(i) + gex * dSublatticeCharge(iSPI,1,i) / q\n end if\n end do\n end if\n\n ! Second sublattice - Cation:vacancy contributions\n do i = 1, nConstituentSublattice(iSPI,2)\n if (cConstituentNameSUB(iSPI,2,i) == 'Va') then\n dgdc2(i) = dgdc2(i) + 2 * gex / yva\n end if\n end do\n\n ! Case 4: Determine the mixing parameter type: L_Ci:Va,Bj\n else if (iSUBIMixType(l) == 4) then\n ! Loop through constituents associated with this parameter:\n do k = 2, n + 1\n ! Determine constituent and sublattice indices:\n c = MOD(iRegularParam(l,k), 10000)\n s = iRegularParam(l,k) - c\n s = s / 10000\n\n ! Compute prefactor term:\n dPreFactor = dPreFactor * dSiteFraction(iSPI,s,c)\n\n ! Store the first and second site fractions:\n if (k == 2) then\n ! cation - Ci\n yCi = dSiteFraction(iSPI,s,c)\n iCi = c\n chargeCi = dSublatticeCharge(iSPI,s,c)\n else if (k == 3) then\n ! vacancy - Va\n yva = dSiteFraction(iSPI,s,c)\n else if (k == 4) then\n ! nuetral - Bj\n yBi = dSiteFraction(iSPI,s,c)\n iBi = c\n end if\n end do\n\n ! Multiply prefactor term by excess Gibbs energy parameter:\n iExponent = iRegularParam(l,n+2)\n ! Excess Gibbs energy equation for L_Ci:Va,Bj case\n gex = q * dPreFactor * dExcessGibbsParam(l) * (yCi * yva - yBi)**(iExponent)\n ! Total Excess Gibbs Energy\n gexcess = gexcess + gex\n\n ! Avoiding a situation with 0^(-1)\n if ((yCi * yva - yBi) /= 0) then\n\n ! First sublattice\n do i = 1, nConstituentSublattice(iSPI,1)\n if (i == iCi) then\n ! cation - Ci\n dgdc1(i) = dgdc1(i) + gex / yCi\n dgdc1(i) = dgdc1(i) + gex * chargeCi / q\n dgdc1(i) = dgdc1(i) + gex * iExponent * yva / (yCi * yva - yBi)\n else\n !&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n ! Not yet tested\n ! If there are additional cations that are not i\n dgdc1(i) = dgdc1(i) + gex * dSublatticeCharge(iSPI,1,i) / q\n end if\n end do\n\n ! Second sublattice\n do i = 1, nConstituentSublattice(iSPI,2)\n if (cConstituentNameSUB(iSPI,2,i) == 'Va') then\n ! vacancy contributions\n dgdc2(i) = dgdc2(i) + gex / yva\n dgdc2(i) = dgdc2(i) + gex * iExponent * yCi / (yCi * yva - yBi)\n else if (i == iBi) then\n ! neutral contributions\n dgdc2(i) = dgdc2(i) + gex / yBi\n dgdc2(i) = dgdc2(i) + gex * iExponent * (-1) / (yCi * yva - yBi)\n end if\n end do\n end if\n\n ! Begining of ternary mixing cases\n ! Case 5: Determine the mixing parameter type: L_Ci:Bj,Bk\n else if (iSUBIMixType(l) == 5) then\n ! Loop through constituents associated with this parameter:\n do k = 2, n + 1\n ! Determine constituent and sublattice indices:\n c = MOD(iRegularParam(l,k), 10000)\n s = iRegularParam(l,k) - c\n s = s / 10000\n\n ! Store the first and second site fractions:\n if (k == 2) then\n ! cation - Ci\n yCi = dSiteFraction(iSPI,s,c)\n iCi = c\n chargeCi = dSublatticeCharge(iSPI,s,c)\n else if (k == 3) then\n ! nuetral - Bj\n yBi = dSiteFraction(iSPI,s,c)\n iBi = c\n ! Compute prefactor term:\n dPreFactor = dPreFactor * dSiteFraction(iSPI,s,c)\n else if (k == 4) then\n ! nuetral - Bk\n yBj = dSiteFraction(iSPI,s,c)\n iBj = c\n ! Compute prefactor term:\n dPreFactor = dPreFactor * dSiteFraction(iSPI,s,c)\n end if\n end do\n\n ! Multiply prefactor term by excess Gibbs energy parameter:\n iExponent = iRegularParam(l,n+2)\n ! Excess Gibbs energy equation for L_Ci:Bj,Bk case\n gex = q * dPreFactor * dExcessGibbsParam(l) * (yCi*yBi - yBj)**(iExponent)\n ! Total Excess Gibbs Energy\n gexcess = gexcess + gex\n\n ! Derived Excess Equations for Mixing Case 1: L_Ci:Aj,Dk\n ! Chemical potential with respect to the first sublattice\n do i = 1, nConstituentSublattice(iSPI,1)\n dgdc1(i) = dgdc1(i) + gex * dSublatticeCharge(iSPI,1,i) / q\n end do\n\n ! Avoiding a situation with 0^(-1)\n if ((yBi - yBj) /= 0D0) then\n do i = 1, nConstituentSublattice(iSPI,2)\n if (i == iBi) then\n ! cation / anion\n dgdc2(i) = dgdc2(i) + gex / yBi\n dgdc2(i) = dgdc2(i) + gex * iExponent / (yBi - yBj)\n else if (i == iBj) then\n ! Dl - anion, vacancy or neutral\n dgdc2(i) = dgdc2(i) + gex / yBj\n dgdc2(i) = dgdc2(i) + gex * iExponent * (-1) / (yBi - yBj)\n end if\n end do\n end if\n\n ! Case 6: Determine the mixing parameter type: L_Ci,Cj,Ck:Al\n else if (iSUBIMixType(l) == 6) then\n print *, 'Unrecognized excess mixing term in SUBI phase. Case #6. ', cSolnPhaseName(iSolnIndex)\n INFOThermo = 44\n return\n ! ! Loop through constituents associated with this parameter:\n ! do k = 2, n + 1\n ! ! Determine constituent and sublattice indices:\n ! c = MOD(iRegularParam(l,k), 10000)\n ! s = iRegularParam(l,k) - c\n ! s = s / 10000\n !\n ! ! Compute prefactor term:\n ! dPreFactor = dPreFactor * dSiteFraction(iSPI,s,c)\n !\n ! if (k == 2) then\n ! ! Cation - Ci\n ! yCi = dSiteFraction(iSPI,s,c)\n ! iCi = c\n ! else if (k == 3) then\n ! ! Cation - Cj\n ! yCj = dSiteFraction(iSPI,s,c)\n ! iCj = c\n ! else if (k == 4) then\n ! ! Cation - Ck\n ! yCk = dSiteFraction(iSPI,s,c)\n ! iCk = c\n ! else if (k == 5) then\n ! ! Anion - Al\n ! yAi = dSiteFraction(iSPI,s,c)\n ! iAi = c\n ! end if\n ! end do\n !\n ! ! Multiply prefactor term by excess Gibbs energy parameter:\n ! iExponent = iRegularParam(l,n+2)\n ! ! Calculate f and v\n ! f = (1D0 - yCi - yCj - yCk)/3D0\n ! if (iRegularParam(l,n+2) == 0) then\n ! v = yCi + f\n ! else if (iRegularParam(l,n+2) == 1) then\n ! v = yCj + f\n ! else if (iRegularParam(l,n+2) == 2) then\n ! v = yCk + f\n ! end if\n !\n ! ! Excess Gibbs energy equation for L_Ci,Cj,Ck:Al case\n ! gex = dPreFactor * v * dExcessGibbsParam(l)\n ! ! Total Excess Gibbs Energy\n ! gexcess = gexcess + gex\n !\n ! do i = 1, nConstituentSublattice(iSPI, 1)\n ! ! Derivative with respect to C\n ! if (i == iCi) then\n ! ! prefactor part\n ! dgdc1(i) = dgdc1(i) + gex / yCi\n ! ! f part\n ! dgdc1(i) = dgdc1(i) - gex / (3D0 * v)\n ! ! other v part\n ! if (iRegularParam(l,n+2) == 0) dgdc1(i) = dgdc1(i) + gex / v\n ! ! Derivative with respect to Cj\n ! else if (i == iCj) then\n ! ! prefactor part\n ! dgdc1(i) = dgdc1(i) + gex / yCj\n ! ! f part\n ! dgdc1(i) = dgdc1(i) - gex / (3D0 * v)\n ! ! other v part\n ! if (iRegularParam(l,n+2) == 1) dgdc1(i) = dgdc1(i) + gex / v\n ! else if (i == iCk) then\n ! ! prefactor part\n ! dgdc1(i) = dgdc1(i) + gex / yCk\n ! ! f part\n ! dgdc1(i) = dgdc1(i) - gex / (3D0 * v)\n ! ! other v part\n ! if (iRegularParam(l,n+2) == 2) dgdc1(i) = dgdc1(i) + gex / v\n ! end if\n ! end do\n !\n ! do i = 1, nConstituentSublattice(iSPI,2)\n ! ! Derivative with respect to Bk\n ! if (i == iAi) then\n ! ! prefactor part\n ! dgdc2(i) = dgdc2(i) + gex / yAi\n ! end if\n ! end do\n\n ! Case 7: Determine the mixing parameter type: L_Ci:Aj,Dk,Dl\n else if (iSUBIMixType(l) == 7) then\n\n ! Loop through constituents associated with this parameter:\n do k = 2, n + 1\n ! Determine constituent and sublattice indices:\n c = MOD(iRegularParam(l,k), 10000)\n s = iRegularParam(l,k) - c\n s = s / 10000\n\n ! Compute prefactor term:\n dPreFactor = dPreFactor * dSiteFraction(iSPI,s,c)\n\n if (k == 2) then\n ! Cation - Ci\n yCi = dSiteFraction(iSPI,s,c)\n iCi = c\n else if (k == 3) then\n ! Anion - Aj\n yAi = dSiteFraction(iSPI,s,c)\n iAi = c\n else if (k == 4) then\n ! Dk\n yDi = dSiteFraction(iSPI,s,c)\n iDi = c\n else if (k == 5) then\n ! Dl\n yDj = dSiteFraction(iSPI,s,c)\n iDj = c\n end if\n end do\n\n ! Multiply prefactor term by excess Gibbs energy parameter:\n iExponent = iRegularParam(l,n+2)\n ! Calculate f and v\n f = (1D0 - yAi - yDi - yDj)/3D0\n if (iRegularParam(l,n+2) == 0) then\n v = yAi + f\n else if (iRegularParam(l,n+2) == 1) then\n v = yDi + f\n else if (iRegularParam(l,n+2) == 2) then\n v = yDj + f\n end if\n\n ! Excess Gibbs energy equation for L_Ci:Aj,Dk,Dl case\n gex = dPreFactor * v * dExcessGibbsParam(l)\n ! Total Excess Gibbs Energy\n gexcess = gexcess + gex\n ! First Sublattice\n do i = 1, nConstituentSublattice(iSPI, 1)\n ! Derivative with respect to C\n if (i == iCi) then\n ! prefactor part\n dgdc1(i) = dgdc1(i) + gex / yCi\n end if\n end do\n\n ! Second Sublattice\n do i = 1, nConstituentSublattice(iSPI,2)\n ! Derivative with respect to Bk\n if (i == iAi) then\n ! prefactor part\n dgdc2(i) = dgdc2(i) + gex / yAi\n ! f part\n dgdc2(i) = dgdc2(i) - gex / (3D0 * v)\n ! other v part\n if (iRegularParam(l,n+2) == 0) dgdc2(i) = dgdc2(i) + gex / v\n else if (i == iDi) then\n ! prefactor part\n dgdc2(i) = dgdc2(i) + gex / yDi\n ! f part\n dgdc2(i) = dgdc2(i) - gex / (3D0 * v)\n ! other v part\n if (iRegularParam(l,n+2) == 1) dgdc2(i) = dgdc2(i) + gex / v\n else if (i == iDj) then\n ! prefactor part\n dgdc2(i) = dgdc2(i) + gex / yDj\n ! f part\n dgdc2(i) = dgdc2(i) - gex / (3D0 * v)\n ! other v part\n if (iRegularParam(l,n+2) == 2) dgdc2(i) = dgdc2(i) + gex / v\n end if\n end do\n\n ! Case 8: Determine the mixing parameter type: L_Ci,Cj,Ck:Va\n else if (iSUBIMixType(l) == 8) then\n\n ! Loop through constituents associated with this parameter:\n do k = 2, n + 1\n ! Determine constituent and sublattice indices:\n c = MOD(iRegularParam(l,k), 10000)\n s = iRegularParam(l,k) - c\n s = s / 10000\n\n if (k == 2) then\n ! Cation - Ci\n yCi = dSiteFraction(iSPI,s,c)\n iCi = c\n else if (k == 3) then\n ! Cation - Cj\n yCj = dSiteFraction(iSPI,s,c)\n iCj = c\n else if (k == 4) then\n ! Cation - Ck\n yCk = dSiteFraction(iSPI,s,c)\n iCk = c\n end if\n end do\n ! Compute prefactor term:\n dPreFactor = yCi * yCj * yCk * yva**3\n ! Multiply prefactor term by excess Gibbs energy parameter:\n iExponent = iRegularParam(l,n+2)\n ! Calculate f and v\n f = (1D0 - yva * yCi - yva * yCj - yva * yCk)/3D0\n if (iRegularParam(l,n+2) == 0) then\n v = yva * yCi + f\n else if (iRegularParam(l,n+2) == 1) then\n v = yva * yCj + f\n else if (iRegularParam(l,n+2) == 2) then\n v = yva * yCk + f\n end if\n\n ! Excess Gibbs energy equation for L_Ci,Cj,Ck:Al case\n gex = q * dPreFactor * v * dExcessGibbsParam(l)\n ! Total Excess Gibbs Energy\n gexcess = gexcess + gex\n\n do i = 1, nConstituentSublattice(iSPI, 1)\n ! Q part:\n dgdc1(i) = dgdc1(i) + gex * dSublatticeCharge(iSPI,1,i) / q\n ! Derivative with respect to C\n if (i == iCi) then\n ! prefactor part\n dgdc1(i) = dgdc1(i) + gex / yCi\n ! f part\n dgdc1(i) = dgdc1(i) - yva * gex / (3D0 * v)\n ! other v part\n if (iRegularParam(l,n+2) == 0) dgdc1(i) = dgdc1(i) + yva * gex / v\n ! Derivative with respect to Cj\n else if (i == iCj) then\n ! prefactor part\n dgdc1(i) = dgdc1(i) + gex / yCj\n ! f part\n dgdc1(i) = dgdc1(i) - yva * gex / (3D0 * v)\n ! other v part\n if (iRegularParam(l,n+2) == 1) dgdc1(i) = dgdc1(i) + yva * gex / v\n else if (i == iCk) then\n ! prefactor part\n dgdc1(i) = dgdc1(i) + gex / yCk\n ! f part\n dgdc1(i) = dgdc1(i) - yva * gex / (3D0 * v)\n ! other v part\n if (iRegularParam(l,n+2) == 2) dgdc1(i) = dgdc1(i) + yva * gex / v\n end if\n end do\n\n do i = 1, nConstituentSublattice(iSPI,2)\n ! Derivative with respect to Va\n if (cConstituentNameSUB(iSPI,2,i) == 'Va') then\n ! prefactor part\n dgdc2(i) = dgdc2(i) + gex * 3D0 / yva\n ! f part\n dgdc2(i) = dgdc2(i) - (yCi + yCj + yCk) * gex / (3D0 * v)\n ! other v parts\n if (iRegularParam(l,n+2) == 0) dgdc2(i) = dgdc2(i) + yCi * gex / v\n if (iRegularParam(l,n+2) == 1) dgdc2(i) = dgdc2(i) + yCj * gex / v\n if (iRegularParam(l,n+2) == 2) dgdc2(i) = dgdc2(i) + yCk * gex / v\n end if\n end do\n\n ! Case 9: Determine the mixing parameter type: L_Ci:Va,Bj,Bk\n else if (iSUBIMixType(l) == 9) then\n\n ! Loop through constituents associated with this parameter:\n do k = 2, n + 1\n ! Determine constituent and sublattice indices:\n c = MOD(iRegularParam(l,k), 10000)\n s = iRegularParam(l,k) - c\n s = s / 10000\n\n if (k == 2) then\n ! Cation - Ci\n yCi = dSiteFraction(iSPI,s,c)\n iCi = c\n else if (k == 3) then\n ! vacancy\n yva = dSiteFraction(iSPI,s,c)\n else if (k == 4) then\n ! neutral - Bi\n yBi = dSiteFraction(iSPI,s,c)\n iBi = c\n else if (k == 5) then\n ! Neutral - Bj\n yBj = dSiteFraction(iSPI,s,c)\n iBj = c\n end if\n end do\n\n ! Compute prefactor term:\n dPreFactor = yCi * yva * yBi * yBj\n ! Calculate f and v\n f = (1D0 - yCi * yva - yBi - yBj)/3D0\n if (iRegularParam(l,n+2) == 0) then\n v = yCi * yva + f\n else if (iRegularParam(l,n+2) == 1) then\n v = yBi + f\n else if (iRegularParam(l,n+2) == 2) then\n v = yBj + f\n end if\n ! Excess Gibbs energy equation for L_Ci:Va,Bj,Bk case\n gex = q * dPreFactor * v * dExcessGibbsParam(l)\n ! Total Excess Gibbs Energy\n gexcess = gexcess + gex\n\n do i = 1, nConstituentSublattice(iSPI, 1)\n ! Q part:\n dgdc1(i) = dgdc1(i) + gex * dSublatticeCharge(iSPI,1,i) / q\n ! Derivative with respect to Ci\n if (i == iCi) then\n ! prefactor part\n dgdc1(i) = dgdc1(i) + gex / yCi\n ! f part\n dgdc1(i) = dgdc1(i) - yva * gex / (3D0 * v)\n ! other v part\n if (iRegularParam(l,n+2) == 0) dgdc1(i) = dgdc1(i) + yva * gex / v\n end if\n end do\n\n do i = 1, nConstituentSublattice(iSPI,2)\n ! Derivative with respect to Bk\n if (i == iBi) then\n ! prefactor part\n dgdc2(i) = dgdc2(i) + gex / yBi\n ! f part\n dgdc2(i) = dgdc2(i) - gex / (3D0 * v)\n ! other v part\n if (iRegularParam(l,n+2) == 1) dgdc2(i) = dgdc2(i) + gex / v\n ! Derivative with respect to Bl\n else if (i == iBj) then\n ! prefactor part\n dgdc2(i) = dgdc2(i) + gex / yBj\n ! f part\n dgdc2(i) = dgdc2(i) - gex / (3D0 * v)\n ! other v part\n if (iRegularParam(l,n+2) == 2) dgdc2(i) = dgdc2(i) + gex / v\n ! Derivative with respect to Va\n else if (cConstituentNameSUB(iSPI,2,i) == 'Va') then\n ! prefactor part\n dgdc2(i) = dgdc2(i) + gex / yva\n ! f part\n dgdc2(i) = dgdc2(i) - yCi * gex / (3D0 * v)\n ! other v part\n if (iRegularParam(l,n+2) == 0) dgdc2(i) = dgdc2(i) + yCi * gex / v\n end if\n end do\n\n ! Case 10: Determine the mixing parameter type: L_Ci:Bj,Bk,Bl\n else if (iSUBIMixType(l) == 10) then\n print *, 'Unrecognized excess mixing term in SUBI phase. Case #6. ', cSolnPhaseName(iSolnIndex)\n INFOThermo = 44\n return\n\n ! ! Loop through constituents associated with this parameter:\n ! do k = 2, n + 1\n ! ! Determine constituent and sublattice indices:\n ! c = MOD(iRegularParam(l,k), 10000)\n ! s = iRegularParam(l,k) - c\n ! s = s / 10000\n !\n ! if (k == 3) then\n ! ! neutral - Bj\n ! yBi = dSiteFraction(iSPI,s,c)\n ! iBi = c\n ! else if (k == 4) then\n ! ! neutral - Bk\n ! yBj = dSiteFraction(iSPI,s,c)\n ! iBj = c\n ! else if (k == 5) then\n ! ! neutral - Bl\n ! yBk = dSiteFraction(iSPI,s,c)\n ! iBk = c\n ! end if\n ! end do\n !\n ! ! Compute prefactor term:\n ! dPreFactor = yBi * yBj * yBk\n ! ! Calculate f and v\n ! f = (1D0 - yBi - yBj - yBk)/3D0\n ! if (iRegularParam(l,n+2) == 0) then\n ! v = yBi + f\n ! else if (iRegularParam(l,n+2) == 1) then\n ! v = yBj + f\n ! else if (iRegularParam(l,n+2) == 2) then\n ! v = yBk + f\n ! end if\n ! ! Excess Gibbs energy equation for L_Ci:Bj,Bk,Bl case\n ! gex = q * dPreFactor * v * dExcessGibbsParam(l)\n ! ! Total Excess Gibbs Energy\n ! gexcess = gexcess + gex\n !\n ! do i = 1, nConstituentSublattice(iSPI, 1)\n ! ! Q part:\n ! dgdc1(i) = dgdc1(i) + gex * dSublatticeCharge(iSPI,1,i) / q\n ! end do\n !\n ! do i = 1, nConstituentSublattice(iSPI,2)\n ! ! Derivative with respect to Bk\n ! if (i == iBi) then\n ! ! prefactor part\n ! dgdc2(i) = dgdc2(i) + gex / yBi\n ! ! f part\n ! dgdc2(i) = dgdc2(i) - gex / (3D0 * v)\n ! ! other v part\n ! if (iRegularParam(l,n+2) == 0) dgdc2(i) = dgdc2(i) + gex / v\n ! ! Derivative with respect to Bl\n ! else if (i == iBj) then\n ! ! prefactor part\n ! dgdc2(i) = dgdc2(i) + gex / yBj\n ! ! f part\n ! dgdc2(i) = dgdc2(i) - gex / (3D0 * v)\n ! ! other v part\n ! if (iRegularParam(l,n+2) == 1) dgdc2(i) = dgdc2(i) + gex / v\n ! ! Derivative with respect to Va\n ! else if (i == iBk) then\n ! ! prefactor part\n ! dgdc2(i) = dgdc2(i) + gex / yBk\n ! ! f part\n ! dgdc2(i) = dgdc2(i) - gex / (3D0 * v)\n ! ! other v part\n ! if (iRegularParam(l,n+2) == 2) dgdc2(i) = dgdc2(i) + gex / v\n ! end if\n ! end do\n\n ! Case 11: Determine the mixing parameter type: L_Ci,Cj:Ak,Dl\n else if (iSUBIMixType(l) == 11) then\n\n ! Loop through constituents associated with this parameter:\n do k = 2, n + 1\n ! Determine constituent and sublattice indices:\n c = MOD(iRegularParam(l,k), 10000)\n s = iRegularParam(l,k) - c\n s = s / 10000\n\n ! Compute prefactor term:\n dPreFactor = dPreFactor * dSiteFraction(iSPI,s,c)\n\n ! Store the first and second site fractions:\n if (k == 2) then\n ! cation - Ci\n yCi = dSiteFraction(iSPI,s,c)\n iCi = c\n else if (k == 3) then\n ! cation - Cj\n yCj = dSiteFraction(iSPI,s,c)\n iCj = c\n else if (k == 4) then\n ! anion - Ak\n yAi = dSiteFraction(iSPI,s,c)\n iAi = c\n else if (k == 5) then\n ! Dl\n yDi = dSiteFraction(iSPI,s,c)\n iDi = c\n end if\n end do\n\n ! Multiply prefactor term by excess Gibbs energy parameter:\n iExponent = iRegularParam(l,n+2)\n\n ! Accounting for odd/even exponentials\n iExponentAdjust = iExponent\n\n if (MOD(iExponent,2) == 0) then\n lEven = .TRUE.\n else\n lEven = .FALSE.\n iExponentAdjust = iExponentAdjust + 1\n end if\n\n iExponentAdjust = iExponentAdjust / 2\n \n ! Excess Gibbs energy equation for L_Ci,Cj:Ak,Dl case\n ! Dealing with the reciprocals\n ! Part 1 of equation:\n if (lEven) then\n gex = dPreFactor * dExcessGibbsParam(l) * (yCi - yCj)**(iExponentAdjust)\n end if\n ! Part 2 of equation:\n if (.NOT. lEven) then\n gex = dPreFactor * dExcessGibbsParam(l) * (yAi - yDi)**(iExponentAdjust)\n end if\n\n ! Total Excess Gibbs Energy\n gexcess = gexcess + gex\n\n ! Avoiding a situation with 0^(-1)\n if ((yCi - yCj) /= 0) then\n do i = 1, nConstituentSublattice(iSPI,1)\n ! Derivative with respect to Ci\n if (i == iCi) then\n dgdc1(i) = dgdc1(i) + gex / yCi\n ! Dealing with the reciprocals\n if ((iExponent > 0) .AND. (lEven)) then\n dgdc1(i) = dgdc1(i) + gex * iExponentAdjust / (yCi - yCj)\n end if\n\n ! Derivative with respect to Cj\n else if (i == iCj) then\n dgdc1(i) = dgdc1(i) + gex / yCj\n ! Dealing with the reciprocals\n if ((iExponent > 0) .AND. (lEven)) then\n dgdc1(i) = dgdc1(i) + gex * iExponentAdjust * (-1) / (yCi - yCj)\n end if\n end if\n end do\n end if\n\n ! Avoiding a situation with 0^(-1)\n if ((yAi - yDi) /= 0) then\n\n ! Chemical potential with respect to the second sublattice\n do i = 1, nConstituentSublattice(iSPI,2)\n !! When Dl = Al or Bl - Cases untested... %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n if (i == iAi) then\n ! anion - Ak\n dgdc2(i) = dgdc2(i) + gex / yAi\n ! Dealing with the reciprocals\n if (.NOT. lEven) then\n dgdc2(i) = dgdc2(i) + gex * iExponentAdjust / (yAi - yDi)\n end if\n\n else if (i == iDi) then\n ! Dl\n dgdc2(i) = dgdc2(i) + gex / yDi\n ! Dealing with the reciprocals\n if (.NOT. lEven) then\n dgdc2(i) = dgdc2(i) + gex * iExponentAdjust * (-1) / (yAi - yDi)\n end if\n end if\n end do\n end if\n\n ! Case 12: Determine the mixing parameter type: L_Ci,Cj:Va,Bk\n else if (iSUBIMixType(l) == 12) then\n\n ! Loop through constituents associated with this parameter:\n do k = 2, n + 1\n ! Determine constituent and sublattice indices:\n c = MOD(iRegularParam(l,k), 10000)\n s = iRegularParam(l,k) - c\n s = s / 10000\n\n if (k == 2) then\n ! Cation - Ci\n yCi = dSiteFraction(iSPI,s,c)\n iCi = c\n else if (k == 3) then\n ! Cation - Cj\n yCj = dSiteFraction(iSPI,s,c)\n iCj = c\n else if (k == 4) then\n ! Vacancy\n yva = dSiteFraction(iSPI,s,c)\n else if (k == 5) then\n ! Neutral - Bk\n yBi = dSiteFraction(iSPI,s,c)\n iBi = c\n end if\n end do\n\n ! Compute prefactor term:\n dPreFactor = yCi * yCj * yBi * yva**2\n ! Calculate f and v\n f = (1D0 - yCi * yva - yCj * yva - yBi)/3D0\n if (iRegularParam(l,n+2) == 0) then\n v = yCi * yva + f\n else if (iRegularParam(l,n+2) == 1) then\n v = yCj * yva + f\n else if (iRegularParam(l,n+2) == 2) then\n v = yBi + f\n end if\n ! Excess Gibbs energy equation for L_Ci,Cj:Va,Bk case\n gex = q * dPreFactor * v * dExcessGibbsParam(l)\n ! Total Excess Gibbs Energy\n gexcess = gexcess + gex\n\n do i = 1, nConstituentSublattice(iSPI, 1)\n ! Q part:\n dgdc1(i) = dgdc1(i) + gex * dSublatticeCharge(iSPI,1,i) / q\n ! Derivative with respect to C\n if (i == iCi) then\n ! prefactor part\n dgdc1(i) = dgdc1(i) + gex / yCi\n ! f part\n dgdc1(i) = dgdc1(i) - yva * gex / (3D0 * v)\n ! other v part\n if (iRegularParam(l,n+2) == 0) dgdc1(i) = dgdc1(i) + yva * gex / v\n ! Derivative with respect to Cj\n else if (i == iCj) then\n ! prefactor part\n dgdc1(i) = dgdc1(i) + gex / yCj\n ! f part\n dgdc1(i) = dgdc1(i) - yva * gex / (3D0 * v)\n ! other v part\n if (iRegularParam(l,n+2) == 1) dgdc1(i) = dgdc1(i) + yva * gex / v\n end if\n end do\n\n do i = 1, nConstituentSublattice(iSPI,2)\n ! Derivative with respect to Bk\n if (i == iBi) then\n ! prefactor part\n dgdc2(i) = dgdc2(i) + gex / yBi\n ! f part\n dgdc2(i) = dgdc2(i) - gex / (3D0 * v)\n ! other v part\n if (iRegularParam(l,n+2) == 2) dgdc2(i) = dgdc2(i) + gex / v\n ! Derivative with respect to Va\n else if (cConstituentNameSUB(iSPI,2,i) == 'Va') then\n ! prefactor part\n dgdc2(i) = dgdc2(i) + gex * 2 / yva\n ! f part\n dgdc2(i) = dgdc2(i) - (yCi + yCj) * gex / (3D0 * v)\n ! other v part\n if (iRegularParam(l,n+2) == 0) dgdc2(i) = dgdc2(i) + yCi * gex / v\n if (iRegularParam(l,n+2) == 1) dgdc2(i) = dgdc2(i) + yCj * gex / v\n end if\n end do\n else\n print *, 'Unrecognized excess mixing term in SUBI phase ', cSolnPhaseName(iSolnIndex)\n INFOThermo = 36\n return\n end if\n end do LOOP_Param\n\n ! REFERENCE GIBBS ENERGY AND IDEAL MIXING\n ! ---------------------------------------\n gref = 0D0\n do j = iFirst, iLast\n ! Relative species index:\n n = j - iFirst + 1\n\n ! Store constituent indices:\n l1 = iConstituentSublattice(iSPI,1,n)\n l2 = iConstituentSublattice(iSPI,2,n)\n\n if (cConstituentNameSUB(iSPI,2,l2) == 'Va') then\n ! cation / vacancy\n gref = gref + q * dSiteFraction(iSPI,1,l1) * dSiteFraction(iSPI,2,l2) * dStdGibbsEnergy(j)\n else if (dSublatticeCharge(iSPI,2,l2) == 0D0) then\n ! neutral\n gref = gref + q * dSiteFraction(iSPI,2,l2) * dStdGibbsEnergy(j)\n else\n ! cation / anion\n gref = gref + dSiteFraction(iSPI,1,l1) * dSiteFraction(iSPI,2,l2) * dStdGibbsEnergy(j)\n end if\n end do\n\n gideal = 0D0\n do i = 1, nConstituentSublattice(iSPI,1)\n gideal = gideal + p * dSiteFraction(iSPI,1,i) * DLOG(dSiteFraction(iSPI,1,i))\n end do\n\n do i = 1, nConstituentSublattice(iSPI,2)\n gideal = gideal + q * dSiteFraction(iSPI,2,i) * DLOG(dSiteFraction(iSPI,2,i))\n end do\n\n ! For Sublattice Number 1\n do i = 1, nConstituentSublattice(iSPI,1)\n lc1 = dSublatticeCharge(iSPI,1,i)\n ! Reference\n do j = iFirst, iLast\n ! Relative species index:\n n = j - iFirst + 1\n ! Store constituent indices:\n l1 = iConstituentSublattice(iSPI,1,n)\n l2 = iConstituentSublattice(iSPI,2,n)\n\n if (cConstituentNameSUB(iSPI,2,l2) == 'Va') then\n ! cation / vacancy\n if (i == l1) dgdc1(i) = dgdc1(i) + q * dSiteFraction(iSPI,2,l2) * dStdGibbsEnergy(j)\n dgdc1(i) = dgdc1(i) + lc1 * dSiteFraction(iSPI,1,l1) * dSiteFraction(iSPI,2,l2) * dStdGibbsEnergy(j)\n else if (dSublatticeCharge(iSPI,2,l2) == 0D0) then\n ! neutral\n dgdc1(i) = dgdc1(i) + lc1 * dSiteFraction(iSPI,2,l2) * dStdGibbsEnergy(j)\n else\n ! cation / anion\n if (i == l1) dgdc1(i) = dgdc1(i) + dSiteFraction(iSPI,2,l2) * dStdGibbsEnergy(j)\n end if\n end do\n\n ! Entropy\n dgdc1(i) = dgdc1(i) + (1 + DLOG(dSiteFraction(iSPI,1,i))) * p\n do j = 1, nConstituentSublattice(iSPI,1)\n dgdc1(i) = dgdc1(i) + dSublatticeCharge(iSPI,1,i) * yva &\n * dSiteFraction(iSPI,1,j)*DLOG(dSiteFraction(iSPI,1,j))\n end do\n do j = 1, nConstituentSublattice(iSPI,2)\n dgdc1(i) = dgdc1(i) + dSublatticeCharge(iSPI,1,i) * dSiteFraction(iSPI,2,j) * DLOG(dSiteFraction(iSPI,2,j))\n end do\n end do\n\n ! For Sublattice Number 2\n do i = 1, nConstituentSublattice(iSPI,2)\n do j = iFirst, iLast\n ! Relative species index:\n n = j - iFirst + 1\n\n ! Store constituent indices:\n l1 = iConstituentSublattice(iSPI,1,n)\n l2 = iConstituentSublattice(iSPI,2,n)\n\n if (cConstituentNameSUB(iSPI,2,l2) == 'Va') then\n ! cation / vacancy\n if (i == l2) dgdc2(i) = dgdc2(i) + q * dSiteFraction(iSPI,1,l1) * dStdGibbsEnergy(j)\n else if (dSublatticeCharge(iSPI,2,l2) == 0D0) then\n ! neutral\n if (i == l2) dgdc2(i) = dgdc2(i) + q * dStdGibbsEnergy(j)\n else\n ! cation / anion\n if (i == l2) dgdc2(i) = dgdc2(i) + dSiteFraction(iSPI,1,l1) * dStdGibbsEnergy(j)\n end if\n end do\n ! Entropy\n dgdc2(i) = dgdc2(i) + (1 + DLOG(dSiteFraction(iSPI,2,i))) * q\n do j = 1, nConstituentSublattice(iSPI,1)\n if (cConstituentNameSUB(iSPI,2,i) == 'Va') then\n ! cation / vacancy\n dgdc2(i) = dgdc2(i) + q * dSiteFraction(iSPI,1,j) * DLOG(dSiteFraction(iSPI,1,j))\n else if (dSublatticeCharge(iSPI,2,i) == 0D0) then\n ! neutral\n else\n ! cation / anion\n dgdc2(i) = dgdc2(i) + (-dSublatticeCharge(iSPI,2,i)) * dSiteFraction(iSPI,1,j) * DLOG(dSiteFraction(iSPI,1,j))\n end if\n end do\n end do\n\n cc1 = 0D0\n\n ! Compute the chemical potential for each phase component assuming ideal mixing:\n LOOP_Ideal: do i = iFirst, iLast\n ! Relative species index:\n m = i - iFirst + 1\n k1 = iConstituentSublattice(iSPI,1,m)\n k2 = iConstituentSublattice(iSPI,2,m)\n\n kc1 = 1D0\n ! cation / vacancy\n if (cConstituentNameSUB(iSPI,2,k2) == 'Va') then\n kc2 = 1D0\n cc1 = dSublatticeCharge(iSPI,1,k1)\n natom = 1D0 / dMol + dMolDerivatives(m) * dMolAtoms\n ! neutral\n else if (dSublatticeCharge(iSPI,2,k2) == 0D0) then\n kc2 = 1D0\n cc1 = 1D0\n natom = 1D0 / dMol + dMolDerivatives(m) * dMolAtoms\n ! cation / anion\n else\n if (k1 > 0) kc1 = dSublatticeCharge(iSPI,1,k1)\n kc2 = -dSublatticeCharge(iSPI,2,k2)\n cc1 = dSublatticeCharge(iSPI,1,k1)\n natom = (kc1 + kc2) / dMol + dMolDerivatives(m) * dMolAtoms\n end if\n\n dChemicalPotential(i) = (gref + gideal + gexcess) * natom\n\n do j = 1, nConstituentSublattice(iSPI,1)\n ! cation / (anion or vacancy)\n if (k1 > 0) then\n dydn = -kc2 * dSiteFraction(iSPI,1,j) / dSub1Total\n if (j == k1) dydn = dydn + kc2 / dSub1Total\n dChemicalPotential(i) = dChemicalPotential(i) + dydn * dgdc1(j) * dMolAtoms / dMol\n end if\n end do\n\n do j = 1, nConstituentSublattice(iSPI,2)\n ! cation / vacancy\n if (cConstituentNameSUB(iSPI,2,k2) == 'Va') then\n dydn = -dSiteFraction(iSPI,2,j)*(dSub1Total*cc1+(q-cc1)*dSub2Total*yva)/(dSub1Total*dSub2Total*q)\n if (cConstituentNameSUB(iSPI,2,j) == 'Va') then\n ! vacancy\n dydn = dydn + (dSub1Total*cc1+(q-cc1)*dSub2Total*yva)/(dSub1Total*dSub2Total*q)\n else\n ! neutral or anion\n end if\n ! neutral\n else if (dSublatticeCharge(iSPI,2,k2) == 0D0) then\n dydn = -dSiteFraction(iSPI,2,j) / dSub2Total\n if (cConstituentNameSUB(iSPI,2,j) == 'Va') then\n ! vacancy\n else\n ! neutral or anion\n if (j == k2) dydn = dydn + 1 / dSub2Total\n end if\n ! cation / anion\n else\n dydn = -dSiteFraction(iSPI,2,j) * (cc1 / dSub2Total + kc2*yva*(q-cc1)/(dSub1Total*q))\n if (cConstituentNameSUB(iSPI,2,j) == 'Va') then\n dydn = dydn + dSiteFraction(iSPI,2,j) * kc2*(q-cc1)/(dSub1Total*q)\n else if (dSublatticeCharge(iSPI,2,j) == 0D0) then\n ! neutral\n else\n ! cation / anion\n if (j == k2) dydn = dydn + cc1 / dSub2Total\n end if\n end if\n dChemicalPotential(i) = dChemicalPotential(i) + dydn * dgdc2(j) * dMolAtoms / dMol\n end do\n end do LOOP_Ideal\n\n\n deallocate(dgdc1,dgdc2)\n deallocate(dMolDerivatives)\n end if IF_SUBL\n\n return\n\nend subroutine CompExcessGibbsEnergySUBI\n", "meta": {"hexsha": "3445b7e4a93cddcf70b4c8f17ef138bac917211a", "size": 64321, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/gem/CompExcessGibbsEnergySUBI.f90", "max_stars_repo_name": "elementx54/thermochimica", "max_stars_repo_head_hexsha": "ea7bb8f64b03d8583d326f737e9699083c304847", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/gem/CompExcessGibbsEnergySUBI.f90", "max_issues_repo_name": "elementx54/thermochimica", "max_issues_repo_head_hexsha": "ea7bb8f64b03d8583d326f737e9699083c304847", "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/gem/CompExcessGibbsEnergySUBI.f90", "max_forks_repo_name": "elementx54/thermochimica", "max_forks_repo_head_hexsha": "ea7bb8f64b03d8583d326f737e9699083c304847", "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": 44.6363636364, "max_line_length": 130, "alphanum_fraction": 0.430978996, "num_tokens": 17257, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9539660976007596, "lm_q2_score": 0.6959583313396339, "lm_q1q2_score": 0.663920653440807}} {"text": "!! Choose one.\n# define PP_GAUSS_NODES\n!# define PP_GAUSS_LOBATTO_NODES\n\nmodule kernel_utils_mod\n\nuse globals_mod\nuse equations_mod, only: N_VARS\n\nprivate\n\npublic :: kernel_utils_init\npublic :: interpolate2visual \n\n!! -------------------------------------------------------------------------- !!\n!! nodes within reference element [-1,1]\n\nreal(dp), save, public :: refnodes(N_NODES)\nreal(dp), save, public :: refweights(N_NODES)\nreal(dp), save, public :: refweights2D(N_NODES,N_NODES)\n\n!! -------------------------------------------------------------------------- !!\n!! prolongate to boundaries\n\nreal(dp), save, public :: toBoundaryVecM(N_NODES)\nreal(dp), save, public :: toBoundaryVecP(N_NODES)\n\n!! ------------------------------------------------------------------------- !!\n!! Weak-Form Standard DG operators (on Legendre-Gauss nodes)\n\nreal(dp), save, public :: diffMat(N_NODES,N_NODES)\nreal(dp), save, public :: diffTam(N_NODES,N_NODES)\n\nreal(dp), save, public :: surfMat(N_NODES,N_NODES)\nreal(dp), save, public :: surfTam(N_NODES,N_NODES)\n\n!! ------------------------------------------------------------------------- !!\n!! Visualization operator\n\nreal(dp), save :: visuMat(N_NODES,N_NODES)\nreal(dp), save :: visuTam(N_NODES,N_NODES)\n\ncontains\n\n!! ========================================================================== !!\n!! Routines regarding Lagrange polynomials as well as quadrature points generation\n\npure function lagrange_polynomial(N, nodes, j, x) result(lp)\n \n integer, intent(in) :: N\n real(dp), intent(in) :: nodes(N)\n integer, intent(in) :: j\n real(dp), intent(in) :: x\n\n real(dp) :: lp\n\n integer :: i\n\n lp = 1.0\n\n if (abs(x-nodes(j)) < 10*TOL) return !! Kronecker property\n\n do i = 1,N\n if (i == j) cycle\n lp = lp * (x - nodes(i))/(nodes(j) - nodes(i))\n end do\n \nend function\n\npure function lagrange_basis(N, nodes, x) result(lp)\n \n integer, intent(in) :: N\n real(dp), intent(in) :: nodes(N)\n real(dp), intent(in) :: x\n\n real(dp) :: lp(N)\n integer :: i\n\n !! Kronecker property\n if (any(abs(x-nodes) < 10*TOL)) then\n lp = merge(1.0,0.0,abs(x-nodes) < 10*TOL)\n return\n end if\n\n forall (i = 1:N) lp(i) = Lagrange_Polynomial(N, nodes, i, x)\n \nend function\n\npure subroutine lagrange_VanderMonde_Matrix(N, M, xs, ys, mat)\n\n integer, intent(in) :: N,M\n real(dp), intent(in) :: xs(N), ys(M)\n real(dp), intent(out) :: mat(M,N)\n\n integer :: i\n\n do i = 1,M\n mat(i,:) = Lagrange_Basis(N, xs, ys(i))\n end do\n\nend subroutine\n\nsubroutine barycentric_weights(N,nodes,weights)\n\n integer,intent(in) :: N\n real(dp),intent(in) :: nodes(N)\n real(dp),intent(out) :: weights(N)\n\n integer :: i,j\n\n weights = 1.0_dp\n\n do i = 2,N\n do j = 1,i-1\n weights(j) = weights(j)*(nodes(j) - nodes(i))\n weights(i) = weights(i)*(nodes(i) - nodes(j))\n end do\n end do\n\n weights = 1.0_dp/weights\n\nend subroutine\n\nsubroutine lagrange_diff_matrix(N,nodes,diffMat)\n\n integer,intent(in) :: N !! number of nodes\n real(dp),intent(in) :: nodes(N)\n real(dp),intent(out) :: diffMat(N,N)\n\n integer :: i,j\n real(dp) :: bweights(N)\n\n call barycentric_weights(N,nodes,bweights)\n\n diffMat = 0.0_dp\n\n do j = 1,N\n do i = 1,N\n if (i.ne.j) then\n diffMat(i,j) = bweights(j)/(bweights(i)*(nodes(i) - nodes(j)))\n diffMat(i,i) = diffMat(i,i) - diffMat(i,j)\n end if\n end do\n end do\n\nend subroutine\n\n# if defined(PP_GAUSS_NODES)\npure subroutine Legendre_polynomial_and_derivative(p,x,L,Lder)\n\n integer,intent(in) :: p !! polynomial order\n real(dp),intent(in) :: x\n real(dp),intent(out) :: L\n real(dp),intent(out) :: Lder\n\n real(dp) :: L_Nm1,L_Nm2\n real(dp) :: Lder_Nm1,Lder_Nm2\n\n integer :: i\n\n if (p == 0) then\n L = 1.0_dp\n Lder = 0.0_dp\n\n else if (p == 1) then\n L = x\n Lder = 1.0_dp\n\n else\n L_Nm2 = 1.0_dp\n L_Nm1 = x\n Lder_Nm2 = 0.0_dp\n Lder_Nm1 = 1.0_dp\n\n do i = 2,p\n L = (real(2*i-1,dp)*x*L_Nm1 - real(i-1,dp)*L_Nm2)/real(i,dp)\n Lder = Lder_Nm2 + real(2*i-1,dp)*L_Nm1\n L_Nm2 = L_Nm1\n L_Nm1 = L\n Lder_Nm2 = Lder_Nm1\n Lder_Nm1 = Lder\n end do\n end if\n\n !! normalize\n L = L*SQRT(real(p,dp)+0.5)\n Lder = Lder*SQRT(real(p,dp)+0.5)\n\nend subroutine\n# endif\n\n# if defined(PP_GAUSS_LOBATTO_NODES)\npure subroutine q_and_L_evaluation(p,x,q,dq,L_N)\n\n integer, intent(in) :: p !! polynomial order\n real(dp), intent(in) :: x\n real(dp), intent(out) :: L_n,q,dq\n\n integer :: k\n real(dp) :: L_n_1,L_n_2,L_k,dL_n,dL_n_1,dL_n_2,dL_k\n\n L_N_2 = 1.0_dp\n L_N_1 = x\n dL_N_2 = 0.0_dp\n dL_N_1 = 1.0_dp\n\n do k = 2,p\n L_N = (2.0_dp*real(k,dp) - 1.0_dp)/real(k,dp)*x*L_N_1 - (real(k,dp)-1.0_dp)/real(k,dp)*L_N_2\n dL_N = dL_N_2 + (2.0_dp*real(k,dp) - 1.0_dp) * L_N_1\n L_N_2 = L_N_1\n L_N_1 = L_N\n dL_N_2 = dL_N_1\n dL_N_1 = dL_N\n end do\n\n !! take another step\n k = p+1\n L_k = (2.0_dp*real(k,dp) - 1.0_dp)/real(k,dp)*x*L_N - (real(k,dp) - 1.0_dp)/real(k,dp)*L_N_2\n dL_k = dL_N_2 + (2.0_dp*real(k,dp) - 1.0_dp) * L_N_1\n q = L_k - L_N_2\n dq = dL_k - dL_N_2\n\nend subroutine\n# endif\n\npure subroutine equidistant_nodes_and_weights(N,nodes,weights)\n\n integer,intent(in) :: N\n real(dp),intent(out) :: nodes(N)\n real(dp),intent(out),optional :: weights(N)\n\n integer :: i\n\n do i = 1,N\n nodes(i) = -1.0 + 2.0*(real(i,dp)-0.5)/real(N,dp)\n end do\n\n weights = 2.0/real(N,dp)\n\nend subroutine\n\n# if defined(PP_GAUSS_NODES)\npure subroutine Legendre_Gauss_nodes_and_weights(N,nodes,weights)\n\n integer,intent(in) :: N !! number of nodes\n real(dp),intent(out) :: nodes(n)\n real(dp),intent(out) :: weights(n)\n\n integer, parameter :: niter = 10\n\n integer :: i,j\n real(dp) :: dx,cheb\n real(dp) :: L_Np1,Lder_Np1\n\n if (N == 1) then\n nodes = 0.0_dp\n weights = 2.0_dp\n return\n end if\n\n if (N == 2) then\n nodes(1) = -sqrt(1.0_dp/3.0_dp)\n nodes(N) = -nodes(1)\n weights = 1.0_dp\n return\n end if\n\n cheb = 2.0_dp*atan(1.0_dp)/real(N,dp)\n\n do i = 1,N/2\n !! initial guess\n nodes(i) = -cos(cheb*real(2*i-1,dp))\n\n !! Newton iteration\n do j = 1,nIter\n call Legendre_polynomial_and_derivative(N,nodes(i),L_Np1,Lder_Np1)\n\n dx = L_Np1/Lder_Np1\n nodes(i) = nodes(i) - dx\n\n if (abs(dx) < 10*tol*abs(nodes(i))) exit\n end do\n\n weights(i) = (2.0_dp*N + 1.0_dp)/((1.0_dp - nodes(i)*nodes(i))*Lder_Np1*Lder_Np1)\n\n !! symmetries\n nodes(N+1-i) = -nodes(i)\n weights(N+1-i) = weights(i)\n\n end do\n\n if (mod(N+1,2) .eq. 0) then\n call Legendre_polynomial_and_derivative(N,0.0_dp,L_Np1,Lder_Np1)\n nodes(N/2+1) = 0.0_dp\n weights(N/2+1) = (2.0_dp*N + 1.0_dp)/(Lder_Np1*Lder_Np1)\n end if\n\nend subroutine\n# endif\n\n# if defined(PP_GAUSS_LOBATTO_NODES)\npure subroutine Legendre_Gauss_Lobatto_Nodes_And_Weights(N,nodes,weights)\n\n integer, intent(in) :: N !! number of nodes\n real(dp), intent(out) :: nodes(N)\n real(dp), intent(out) :: weights(N)\n\n integer, parameter :: niter = 10\n real(dp) :: q,dq,L_n,delta\n\n integer :: i,j\n\n nodes(1) = -1.0_dp\n weights(1) = 2.0_dp / (real(N-1,dp)*real(N,dp))\n\n nodes(N) = -nodes(1)\n weights(N) = weights(1)\n\n if (N < 3) return\n \n do i = 2,N/2\n !! initial guess\n nodes(i) = -cos(((real(i-1,dp)+0.25_dp)*pi)/real(N-1,dp) - (3.0_dp/(8.0_dp*real(N-1,dp)*pi)) * (1.0_dp/(real(i-1,dp)+0.25_dp)))\n\n !! Newton iteration\n do j = 1,niter\n call q_And_L_Evaluation(N-1,nodes(i),q,dq,L_N)\n\n delta = q/dq\n nodes(i) = nodes(i) - delta\n\n if (abs(delta) < 10*tol*abs(nodes(i))) exit\n end do\n\n call q_And_L_Evaluation(N-1,nodes(i),q,dq,L_N)\n\n weights(i) = 2.0_dp / (real(N-1,dp)*real(N,dp) * L_N*L_N)\n\n nodes(N+1-i) = -nodes(i)\n weights(N+1-i) = weights(i)\n end do\n\n if (mod(N+1,2) == 0) then\n call q_And_L_Evaluation(N-1,0.0_dp,q,dq,L_N)\n\n nodes(N/2+1) = 0.0_dp\n weights(N/2+1) = 2.0_dp / (real(N-1,dp) * real(N,dp) * L_N*L_N)\n end if\n\nend subroutine\n# endif\n\n!! ========================================================================== !!\n!! public routines\n\nsubroutine kernel_utils_init()\n\n integer, parameter :: N = N_NODES\n\n real(dp) :: fvnodes(N_NODES), fvweights(N_NODES)\n real(dp) :: dgnodes(N_NODES), dgweights(N_NODES)\n\n real(dp) :: tempMat(N_NODES,N_NODES)\n \n integer :: i,j\n\n call Equidistant_Nodes_And_Weights(N_NODES,fvnodes,fvweights)\n\n# if defined(PP_GAUSS_NODES)\n call Legendre_Gauss_Nodes_And_Weights(N_NODES,dgnodes,dgweights)\n# elif defined(PP_GAUSS_LOBATTO_NODES)\n call Legendre_Gauss_Lobatto_Nodes_And_Weights(N_NODES,dgnodes,dgweights)\n# else\n# error No node type choosen!\n# endif\n\n !! --------------------------------------------------------------------- !!\n !! Boundary Interpolation Operators\n\n do i = 1,N_NODES\n toBoundaryVecM(i) = lagrange_polynomial(N_NODES,dgnodes,i,-1.0_dp)\n toBoundaryVecP(i) = lagrange_polynomial(N_NODES,dgnodes,i, 1.0_dp)\n end do\n\n !! --------------------------------------------------------------------- !!\n !! Volume Term Matrix (weak form)\n\n call lagrange_Diff_Matrix(N_NODES,dgnodes,tempMat)\n forall (j = 1:N_NODES, i = 1:N_NODES)\n diffMat(i,j) = -2.0_dp * dgweights(j)/dgweights(i) * tempMat(j,i)\n end forall\n diffTam = transpose(diffMat)\n\n !! --------------------------------------------------------------------- !!\n !! Surface Term Matrix\n\n surfMat = 0.0_dp\n do i = 1,N_NODES\n surfMat(i,1) = 2.0_dp/dgweights(i) * lagrange_polynomial(N_NODES,dgnodes,i,-1.0_dp)\n surfMat(i,N) = -2.0_dp/dgweights(i) * lagrange_polynomial(N_NODES,dgnodes,i, 1.0_dp)\n end do\n surfTam = transpose(surfMat)\n\n !! --------------------------------------------------------------------- !!\n !! Visualization Matrix\n\n call lagrange_VanderMonde_Matrix(N_NODES,N_NODES,dgnodes,fvnodes,visuMat)\n visuTam = transpose(visuMat)\n\n !! --------------------------------------------------------------------- !!\n\n refnodes = dgnodes\n refweights = dgweights\n\n !! Scaled it to unity.\n do j = 1,N_NODES; do i = 1,N_NODES\n refweights2D(i,j) = 0.25*refweights(i)*refweights(j)\n end do; end do\n\n !! --------------------------------------------------------------------- !!\n\n# if 0\n write (*,*) 'fvnodes', fvnodes\n write (*,*) 'dgnodes', dgnodes\n write (*,*) 'dgweights', dgweights\n write (*,*)\n\n write (*,*) 'toBoundaryVec{M,P}'\n write (*,'(32(ES12.4))') toBoundaryVecM\n write (*,'(32(ES12.4))') toBoundaryVecP\n write (*,*)\n\n write (*,*) 'diffMat'\n do i = 1,N_NODES\n write (*,'(32(ES12.4))') diffMat(i,:)\n end do\n write (*,*)\n\n write (*,*) 'surfMat'\n do i = 1,N_NODES\n write (*,'(32(ES12.4))') surfmat(i,:)\n end do\n write (*,*)\n# endif\n\nend subroutine\n\npure subroutine interpolate2visual(input,output)\n\n real(dp), intent(in) :: input(N_NODES,N_NODES)\n real(dp), intent(out) :: output(N_NODES,N_NODES)\n \n output = matmul(visuMat,matmul(input,visuTam))\n\nend subroutine\n\nend module\n", "meta": {"hexsha": "7fb4e37404d0813687ff6a40f18a722ed21c5594", "size": 11891, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/kernel/dg/weakform/kernel_utils_mod.f90", "max_stars_repo_name": "jmark/nemo2d", "max_stars_repo_head_hexsha": "a508f192d0f6da49e485ee9c8d1c049dbb81d033", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source/kernel/dg/weakform/kernel_utils_mod.f90", "max_issues_repo_name": "jmark/nemo2d", "max_issues_repo_head_hexsha": "a508f192d0f6da49e485ee9c8d1c049dbb81d033", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/kernel/dg/weakform/kernel_utils_mod.f90", "max_forks_repo_name": "jmark/nemo2d", "max_forks_repo_head_hexsha": "a508f192d0f6da49e485ee9c8d1c049dbb81d033", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.9628820961, "max_line_length": 135, "alphanum_fraction": 0.5240938525, "num_tokens": 3779, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543488, "lm_q2_score": 0.7431680086124812, "lm_q1q2_score": 0.6638789723722088}} {"text": "!******************************************************************************\n!\tWritten for 'complexify.py 1.3'\n!\tJ.R.R.A.Martins 1999\n! 21-Apr-00 Fixed tan, sinh, cosh\n! sign now returns complex\n! added log10 and nint\n! changed ==, /= and >= -- see comments below\n! 20-May-00 added cosd, sind, and epsilon\n! 11-Jul-00 took away cosd, sind (they are reserved, but not\n! intrinsic functions in F90)\n! 21-Jul-00 converted all trig functions to the value/derivative\n! formulas -- not general complex number formulas\n! 15-Aug-00 Fixed bug in atan2 formula and added the rest of the\n! _ci and _ic cominations to the relational operators.\n! P. Sturdza\n! \n!******************************************************************************\n!\n! Assume all code is compiled with double precision (-r8 compiler flag)\n!\n\n!TODO:\n! more typ combinations: cc, cr, rc, ic ?\n! check all fcns\n!\n\nmodule complexify\n\n\n implicit none\n \n! ABS\n interface abs\n module procedure abs_c\n end interface\n\n! COSD\n! interface cosd\n! module procedure cosd_c\n! end interface\n\n! ACOS\n interface acos\n module procedure acos_c\n end interface\n\n! SIND\n! interface sind\n! module procedure sind_c\n! end interface\n\n! ASIN\n interface asin\n module procedure asin_c\n end interface\n\n! ATAN\n interface atan\n module procedure atan_c\n end interface\n\n! ATAN2\n interface atan2\n module procedure atan2_cc\n end interface\n\n! COSH\n interface cosh\n module procedure cosh_c\n end interface\n\n! MAX (limited to 2-4 complex args, 2 mixed args)\n interface max\n module procedure max_cc\n module procedure max_cr\n module procedure max_rc\n module procedure max_ccc ! added because of DFLUX.f\n module procedure max_cccc ! added because of DFLUX.f\n end interface\n\n! MIN (limited to 2-4 complex args, 2 mixed args)\n interface min\n module procedure min_cc\n module procedure min_cr\n module procedure min_rc\n module procedure min_ccc\n module procedure min_cccc\n end interface\n\n! MINVAL\n interface minval\n module procedure minval_c\n end interface minval\n\n! MAXVAL\n interface maxval\n module procedure maxval_c\n end interface maxval\n\n! SIGN\n interface sign\n module procedure sign_cc\n module procedure sign_cca\n module procedure sign_cr\n module procedure sign_rc\n end interface\n\n! DIM\n interface dim\n module procedure dim_cc\n module procedure dim_cr\n module procedure dim_rc\n end interface\n\n! SINH\n interface sinh\n module procedure sinh_c\n end interface\n \n! TAN\n interface tan\n module procedure tan_c\n end interface\n \n! TANH\n interface tanh\n module procedure tanh_c\n end interface\n\n! LOG10\n interface log10\n module procedure log10_c\n end interface\n\n! NINT\n interface nint\n module procedure nint_c\n end interface\n\n! EPSILON\n interface epsilon\n module procedure epsilon_c\n end interface\n\n! <\n interface operator (<)\n module procedure lt_cc\n module procedure lt_cr\n module procedure lt_rc\n module procedure lt_ci\n module procedure lt_ic\n end interface\n\n! <=\n interface operator (<=)\n module procedure le_cc\n module procedure le_cr\n module procedure le_rc\n module procedure le_ci\n module procedure le_ic\n end interface\n\n! >\n interface operator (>)\n module procedure gt_cc\n module procedure gt_cr\n module procedure gt_rc\n module procedure gt_ci\n module procedure gt_ic\n module procedure gt_cac\n module procedure gt_car\n end interface\n\n!! MIPSpro Compilers: Version 7.30 won't take .ge. and .eq..\n!! But pgf90 on Linux doesn't complain, go figure.\n!! It looks like a strict interpretation of FORTRAN should\n!! not allow overloading of .eq. and .ne. since they already\n!! have a definition for type complex, so define new operators\n!! called .ceq., .cne. and, for MIPS, .cge.\n!!\n!! comment out (and uncomment) the appropriate versions for\n!! your compiler\n!!\n! >= \n interface operator (>=)\n module procedure ge_cc\n module procedure ge_cr\n module procedure ge_rc\n module procedure ge_ci\n module procedure ge_ic\n end interface\n! interface operator (.cge.)\n! module procedure ge_cc\n! module procedure ge_rr\n! module procedure ge_ii\n! module procedure ge_aa\n! module procedure ge_cr\n! module procedure ge_rc\n! module procedure ge_ci\n! module procedure ge_ic\n! module procedure ge_ir\n! module procedure ge_ri\n! end interface\n\n! ==\n! interface operator (==)\n! module procedure eq_cc\n! module procedure eq_cr\n! module procedure eq_rc\n! module procedure eq_ci\n! module procedure eq_ic\n! end interface\n interface operator (.ceq.)\n module procedure eq_cc\n module procedure eq_rr\n module procedure eq_ii\n module procedure eq_iai\n module procedure eq_iaia\n module procedure eq_i8i8\n module procedure eq_i1i1\n module procedure eq_aa\n module procedure eq_cr\n module procedure eq_rc\n module procedure eq_ci\n module procedure eq_ic\n module procedure eq_ir\n module procedure eq_ri\n end interface\n\n! /=\n! interface operator (/=)\n! module procedure ne_cc\n! module procedure ne_cr\n! module procedure ne_rc\n! module procedure ne_ci\n! module procedure ne_ic\n! end interface\n interface operator (.cne.)\n module procedure ne_cc\n module procedure ne_rr\n module procedure ne_ii\n module procedure ne_aa\n module procedure ne_cr\n module procedure ne_rc\n module procedure ne_ci\n module procedure ne_ic\n module procedure ne_ir\n module procedure ne_ri\n end interface\n\n! floor\n interface floor\n module procedure floor_c\n end interface\n\ncontains\n\n!******************************************************************************\n!\n! Function definitions\n!\n!******************************************************************************\n\n! ABS, intrinsic\n complex*16 function abs_c(val)\n complex*16, intent(in) :: val\n abs_c = val\n if (real(val) < 0) abs_c = cmplx(-real(val),-aimag(val))\n return\n end function abs_c\n\n! COSD\n! complex*16 function cosd_c(z)\n! complex*16, intent(in) :: z\n! cosd_c = cos(z*3.14159265358979323846/180.)\n! end function cosd_c\n\n! SIND\n! complex*16 function sind_c(z)\n! complex*16, intent(in) :: z\n! sind_c = sin(z*3.14159265358979323846/180.)\n! end function sind_c\n\n! ACOS\n complex*16 function acos_c(z)\n complex*16, intent(in) :: z\n! acos_c = - cmplx(0., 1.)*log(z+sqrt(z**2-1.))\n! not general complex valued formula:\n acos_c = cmplx(acos(real(z)),-aimag(z)/sqrt(1.-real(z)**2))\n return\n end function acos_c\n\n! ASIN\n complex*16 function asin_c(z)\n complex*16, intent(in) :: z\n! asin_c = - cmplx(0., 1.)*log(cmplx(0.,1.)*z+sqrt(1.-z**2))\n! not general complex valued formula:\n asin_c = cmplx(asin(real(z)),aimag(z)/sqrt(1.-real(z)**2))\n return\n end function asin_c\n\n! ATAN\n complex*16 function atan_c(z)\n complex*16, intent(in) :: z\n! complex*16 z2\n! real*8 pi2, xans, yans, r, r2, x, y\n! pi2 = 2.0*atan(1.0)\n! r = sqrt(real(z)**2+aimag(z)**2)\n! x = real(z)\n! y = aimag(z)\n! r2 = r*r\n! xans = 0.5*atan2 (2.0*x, 1.0-r2)\n! yans = 0.25*log((r2+2.0*y+1.0)/(r2-2.0*y+1.0))\n! atan_c = cmplx (xans, yans)\n! not general complex valued formula:\n atan_c = cmplx(atan(real(z)),aimag(z)/(1.+real(z)**2))\n return\n end function atan_c\n \n! ATAN2\n complex*16 function atan2_cc(csn, ccs)\n complex*16, intent(in) :: csn, ccs\n! real*8 pi\n! pi = 4.0*atan(1.0)\n! if (sqrt(real(ccs)**2 + aimag(ccs)**2).eq.0.) then ! abs orig\n! if (sqrt(real(csn)**2+aimag(csn)**2).eq.0.) then\n! atan2_cc = cmplx(0.0)\n! else\n! atan2_cc = cmplx(sign(0.5*pi,real(csn)), 0.0)\n! end if\n! else\n! atan2_cc = atan(csn/ccs)\n! if (real(ccs).lt.0.) atan2_cc = atan2_cc + pi\n! if (real(atan2_cc).gt.pi) atan2_cc = atan2_cc - 2.0*pi\n! end if\n! not general complex valued formula:\n real*8 a,b,c,d\n a=real(csn)\n b=aimag(csn)\n c=real(ccs)\n d=aimag(ccs)\n atan2_cc=cmplx(atan2(a,c),(c*b-a*d)/(a**2+c**2))\n return\n end function atan2_cc\n\n! COSH\n complex*16 function cosh_c(z)\n complex*16, intent(in) :: z\n! complex*16 eplus, eminus\n! eplus = exp(z)\n! eminus = exp(z)\n! cosh_c = (eplus + eminus)/2.\n! not general complex valued formula:\n cosh_c=cmplx(cosh(real(z)),aimag(z)*sinh(real(z)))\n return\n end function cosh_c\n\n! SINH\n complex*16 function sinh_c(z)\n complex*16, intent(in) :: z\n! complex*16 eplus, eminus\n! eplus = exp(z)\n! eminus = exp(z)\n! sinh_c = (eplus - eminus)/2.\n! not general complex valued formula:\n sinh_c=cmplx(sinh(real(z)),aimag(z)*cosh(real(z)))\n return\n end function sinh_c\n\n! TAN\n complex*16 function tan_c(z)\n complex*16, intent(in) :: z\n! complex*16 eiplus, eiminus\n! eiplus = exp(cmplx(0.,1.)*z)\n! eiminus = exp(-cmplx(0.,1.)*z)\n! tan_c = cmplx(0.,1.)*(eiminus - eiplus)/(eiplus + eiminus)\n! not general complex valued formula:\n tan_c=cmplx(tan(real(z)),aimag(z)/cos(real(z))**2)\n return\n end function tan_c\n \n! TANH\n complex*16 function tanh_c(a)\n complex*16, intent(in) :: a\n! complex*16 eplus, eminus\n! if(real(a) > 50)then\n! tanh_c = 1.\n! else\n! eplus = exp(a)\n! eminus = exp(-a)\n! tanh_c = (eplus - eminus)/(eplus + eminus)\n! end if\n! not general complex valued formula:\n tanh_c=cmplx(tanh(real(a)),aimag(a)/cosh(real(a))**2)\n return\n end function tanh_c\n\n! MAX, intrinsic\n complex*16 function max_cc(val1, val2)\n complex*16, intent(in) :: val1, val2\n if (real(val1) > real(val2)) then\n max_cc = val1\n else\n max_cc = val2\n endif\n return\n end function max_cc\n complex*16 function max_cr(val1, val2)\n complex*16, intent(in) :: val1 \n real*8, intent(in) :: val2 \n if (real(val1) > val2) then\n max_cr = val1\n else\n max_cr = cmplx(val2, 0.)\n endif\n return\n end function max_cr\n complex*16 function max_rc(val1, val2)\n real*8, intent(in) :: val1\n complex*16, intent(in) :: val2\n if (val1 > real(val2)) then\n max_rc = cmplx(val1, 0.)\n else\n max_rc = val2\n endif\n return\n end function max_rc\n complex*16 function max_ccc(val1, val2, val3)\n complex*16, intent(in) :: val1, val2, val3\n if (real(val1) > real(val2)) then\n max_ccc = val1\n else\n max_ccc = val2\n endif\n if (real(val3) > real(max_ccc)) then\n max_ccc = val3\n endif\n return\n end function max_ccc\n function max_cccc(val1, val2, val3, val4)\n complex*16, intent(in) :: val1, val2, val3, val4\n complex*16 max_cccc\n complex*16 max_cccc2\n if (real(val1) > real(val2)) then\n max_cccc = val1\n else\n max_cccc = val2\n endif\n if (real(val3) > real(val4)) then\n max_cccc2 = val3\n else\n max_cccc2 = val4\n endif\n if (real(max_cccc2) > real(max_cccc)) then\n max_cccc = max_cccc2\n endif\n return\n end function max_cccc\n\n! MIN, intrinsic\n complex*16 function min_cc(val1, val2)\n complex*16, intent(in) :: val1, val2\n if (real(val1) < real(val2)) then\n min_cc = val1\n else\n min_cc = val2\n endif\n return\n end function min_cc\n complex*16 function min_cr(val1, val2)\n complex*16, intent(in) :: val1 \n real*8, intent(in) :: val2 \n if (real(val1) < val2) then\n min_cr = val1\n else\n min_cr = cmplx(val2, 0.)\n endif\n return\n end function min_cr\n complex*16 function min_rc(val1, val2)\n real*8, intent(in) :: val1\n complex*16, intent(in) :: val2\n if (val1 < real(val2)) then\n min_rc = cmplx(val1, 0.)\n else\n min_rc = val2\n endif\n return\n end function min_rc\n complex*16 function min_ccc(val1, val2, val3)\n complex*16, intent(in) :: val1, val2, val3\n if (real(val1) < real(val2)) then\n min_ccc = val1\n else\n min_ccc = val2\n endif\n if (real(val3) < real(min_ccc)) then\n min_ccc = val3\n endif\n return\n end function min_ccc\n function min_cccc(val1, val2, val3, val4)\n complex*16, intent(in) :: val1, val2, val3, val4\n complex*16 min_cccc\n complex*16 min_cccc2\n if (real(val1) < real(val2)) then\n min_cccc = val1\n else\n min_cccc = val2\n endif\n if (real(val3) < real(val4)) then\n min_cccc2 = val3\n else\n min_cccc2 = val4\n endif\n if (real(min_cccc2) < real(min_cccc)) then\n min_cccc = min_cccc2\n endif\n return\n end function min_cccc\n\n! MINVAL: minimum of an array\n! Assumes a 1D array!\n complex*16 function minval_c(z)\n complex*16, intent(in) :: z(:)\n minval_c = cmplx(minval(real(z)), aimag(z(minloc(real(z),dim=1))))\n end function minval_c\n\n! MAXVAL: maximum of an array\n! Assumes a 1D array!\n complex*16 function maxval_c(z)\n complex*16, intent(in) :: z(:)\n maxval_c = cmplx(maxval(real(z)), aimag(z(maxloc(real(z),dim=1))))\n end function maxval_c\n\n!! MINLOC: location of minimum in an array\n! complex*16 function minloc_c(z)\n! complex*16, intent(in) :: z(:)\n! !integer n\n! !n = size(z)\n! minloc_c = minloc(real(z))\n! end function minval_c\n\n \n! SIGN, intrinsic, assume that val1 is always a complex*16\n! in reality could be int\n complex*16 function sign_cc(val1, val2)\n complex*16, intent(in) :: val1, val2\n real*8 sign\n if (real(val2) < 0.) then\n sign = -1.\n else\n sign = 1.\n endif\n sign_cc = sign * val1\n return\n end function sign_cc\n function sign_cca(val1, val2) ! NEW, not verified\n complex*16, intent(in) :: val1\n complex*16, intent(in) :: val2(:)\n complex*16 sign_cca(size(val2))\n real*8 sign\n integer i, n\n n = size(val2)\n do i = 1, n\n if (real(val2(i)) < 0.) then\n sign = -1.\n else\n sign = 1.\n endif\n sign_cca(i) = sign * val1\n enddo\n return\n end function sign_cca\n complex*16 function sign_cr(val1, val2)\n complex*16, intent(in) :: val1\n real*8, intent(in) :: val2\n real*8 sign\n if (real(val2) < 0.) then\n sign = -1.\n else\n sign = 1.\n endif\n sign_cr = sign * val1\n return\n end function sign_cr\n complex*16 function sign_rc(val1, val2)\n real*8, intent(in) :: val1\n complex*16, intent(in) :: val2\n real*8 sign\n if (real(val2) < 0.) then\n sign = -1.\n else\n sign = 1.\n endif\n sign_rc = sign * val1\n return\n end function sign_rc\n\n! DIM, intrinsic\n complex*16 function dim_cc(val1, val2)\n complex*16, intent(in) :: val1, val2\n if (val1 > val2) then\n dim_cc = val1 - val2\n else\n dim_cc = cmplx(0., 0.)\n endif\n return\n end function dim_cc\n complex*16 function dim_cr(val1, val2)\n complex*16, intent(in) :: val1\n real*8, intent(in) :: val2\n if (val1 > val2) then\n dim_cr = val1 - cmplx(val2, 0.)\n else\n dim_cr = cmplx(0., 0.)\n endif\n return\n end function dim_cr\n complex*16 function dim_rc(val1, val2)\n real*8, intent(in) :: val1\n complex*16, intent(in) :: val2\n if (val1 > val2) then\n dim_rc = cmplx(val1, 0.) - val2\n else\n dim_rc = cmplx(0., 0.)\n endif\n return\n end function dim_rc\n \n! LOG10\n complex*16 function log10_c(z)\n complex*16, intent(in) :: z\n log10_c=log(z)/log((10.0,0.0))\n end function log10_c\n\n! NINT\n integer function nint_c(z)\n complex*16, intent(in) :: z\n nint_c = nint(real(z))\n end function nint_c\n\n! EPSILON !! bad news ulness compiled with -r8\n complex*16 function epsilon_c(z)\n complex*16, intent(in) :: z\n epsilon_c=epsilon(real(z))\n end function epsilon_c\n\n! <, .lt.\n logical function lt_cc(lhs, rhs)\n complex*16, intent(in) :: lhs, rhs\n lt_cc = real(lhs) < real(rhs)\n end function lt_cc\n logical function lt_cr(lhs, rhs)\n complex*16, intent(in) :: lhs\n real*8, intent(in) :: rhs\n lt_cr = real(lhs) < rhs\n end function lt_cr\n logical function lt_rc(lhs, rhs)\n real*8, intent(in) :: lhs\n complex*16, intent(in) :: rhs\n lt_rc = lhs < real(rhs)\n end function lt_rc\n logical function lt_ci(lhs, rhs)\n complex*16, intent(in) :: lhs\n integer, intent(in) :: rhs\n lt_ci = real(lhs) < rhs\n end function lt_ci\n logical function lt_ic(lhs, rhs)\n integer, intent(in) :: lhs\n complex*16, intent(in) :: rhs\n lt_ic = lhs < real(rhs)\n end function lt_ic\n\n! <=, .le.\n logical function le_cc(lhs, rhs)\n complex*16, intent(in) :: lhs, rhs\n le_cc = real(lhs) <= real(rhs)\n end function le_cc\n logical function le_cr(lhs, rhs)\n complex*16, intent(in) :: lhs\n real*8, intent(in) :: rhs\n le_cr = real(lhs) <= rhs\n end function le_cr\n logical function le_rc(lhs, rhs)\n real*8, intent(in) :: lhs\n complex*16, intent(in) :: rhs\n le_rc = lhs <= real(rhs)\n end function le_rc\n logical function le_ci(lhs, rhs)\n complex*16, intent(in) :: lhs\n integer, intent(in) :: rhs\n le_ci = real(lhs) <= rhs\n end function le_ci\n logical function le_ic(lhs, rhs)\n integer, intent(in) :: lhs\n complex*16, intent(in) :: rhs\n le_ic = lhs <= real(rhs)\n end function le_ic\n\n! >, .gt.\n logical function gt_cc(lhs, rhs)\n complex*16, intent(in) :: lhs, rhs\n gt_cc = real(lhs) > real(rhs)\n end function gt_cc\n logical function gt_cr(lhs, rhs)\n complex*16, intent(in) :: lhs\n real*8, intent(in) :: rhs\n gt_cr = real(lhs) > rhs\n end function gt_cr\n logical function gt_rc(lhs, rhs)\n real*8, intent(in) :: lhs\n complex*16, intent(in) :: rhs\n gt_rc = lhs > real(rhs)\n end function gt_rc\n logical function gt_ci(lhs, rhs)\n complex*16, intent(in) :: lhs\n integer, intent(in) :: rhs\n gt_ci = real(lhs) > rhs\n end function gt_ci\n logical function gt_ic(lhs, rhs)\n integer, intent(in) :: lhs\n complex*16, intent(in) :: rhs\n gt_ic = lhs > real(rhs)\n end function gt_ic\n! function gt_caca(lhs, rhs) ! Arrays\n! complex*16, intent(in) :: lhs(:), rhs(:)\n! logical gt_caca(size(lhs))\n! integer n\n! n = size(lhs)\n! gt_caca = real(lhs) > real(rhs)\n! end function gt_caca\n function gt_cac(lhs, rhs) ! Arrays\n complex*16, intent(in) :: lhs(:)\n complex*16, intent(in) :: rhs\n logical gt_cac(size(lhs))\n integer n\n n = size(lhs)\n gt_cac = real(lhs) > real(rhs)\n end function gt_cac\n function gt_car(lhs, rhs) ! Arrays\n complex*16, intent(in) :: lhs(:)\n real*8, intent(in) :: rhs\n logical gt_car(size(lhs))\n integer n\n n = size(lhs)\n gt_car = real(lhs) > rhs\n end function gt_car\n\n!! here are the redefined ones:\n! >=, .ge.\n logical function ge_cc(lhs, rhs)\n complex*16, intent(in) :: lhs, rhs\n ge_cc = real(lhs) >= real(rhs)\n end function ge_cc\n logical function ge_rr(lhs, rhs)\n real*8, intent(in) :: lhs, rhs\n ge_rr = lhs >= rhs\n end function ge_rr\n logical function ge_ii(lhs, rhs)\n integer, intent(in) :: lhs, rhs\n ge_ii = lhs >= rhs\n end function ge_ii\n logical function ge_aa(lhs, rhs)\n character(len=*), intent(in) :: lhs, rhs\n ge_aa = lhs >= rhs\n end function ge_aa\n logical function ge_cr(lhs, rhs)\n complex*16, intent(in) :: lhs\n real*8, intent(in) :: rhs\n ge_cr = real(lhs) >= rhs\n end function ge_cr\n logical function ge_rc(lhs, rhs)\n real*8, intent(in) :: lhs\n complex*16, intent(in) :: rhs\n ge_rc = lhs >= real(rhs)\n end function ge_rc\n logical function ge_ci(lhs, rhs)\n complex*16, intent(in) :: lhs\n integer, intent(in) :: rhs\n ge_ci = real(lhs) >= rhs\n end function ge_ci\n logical function ge_ic(lhs, rhs)\n integer, intent(in) :: lhs\n complex*16, intent(in) :: rhs\n ge_ic = lhs >= real(rhs)\n end function ge_ic\n logical function ge_ir(lhs, rhs)\n integer, intent(in) :: lhs\n real*8, intent(in) :: rhs\n ge_ir = lhs >= rhs\n end function ge_ir\n logical function ge_ri(lhs, rhs)\n real*8, intent(in) :: lhs\n integer, intent(in) :: rhs\n ge_ri = lhs >= rhs\n end function ge_ri\n\n! ==, .eq.\n logical function eq_cc(lhs, rhs)\n complex*16, intent(in) :: lhs, rhs\n eq_cc = real(lhs) == real(rhs)\n end function eq_cc\n logical function eq_rr(lhs, rhs)\n real*8, intent(in) :: lhs, rhs\n eq_rr = lhs == rhs\n end function eq_rr\n logical function eq_ii(lhs, rhs)\n integer, intent(in) :: lhs, rhs\n eq_ii = lhs == rhs\n end function eq_ii\n ! lhs and rhs are rank 1 integer arrays\n function eq_iaia(lhs, rhs) \n integer, intent(in) :: lhs(:), rhs(:)\n logical eq_iaia(size(lhs))\n eq_iaia = lhs == rhs\n end function eq_iaia\n ! lhs is a rank 3 integer array\n function eq_iai(lhs, rhs) \n integer, intent(in) :: lhs(:,:,:)\n integer, intent(in) :: rhs\n logical eq_iai(size(lhs,1), size(lhs,2), size(lhs,3))\n eq_iai = lhs == rhs\n end function eq_iai\n logical function eq_i8i8(lhs, rhs)\n integer(kind = 8), intent(in) :: lhs, rhs\n eq_i8i8 = lhs == rhs\n end function eq_i8i8\n logical function eq_i1i1(lhs, rhs)\n integer(kind = 1), intent(in) :: lhs, rhs\n eq_i1i1 = lhs == rhs\n end function eq_i1i1\n logical function eq_aa(lhs, rhs)\n character(len=*), intent(in) :: lhs, rhs\n eq_aa = lhs == rhs\n end function eq_aa\n logical function eq_cr(lhs, rhs)\n complex*16, intent(in) :: lhs\n real*8, intent(in) :: rhs\n eq_cr = real(lhs) == rhs\n end function eq_cr\n logical function eq_rc(lhs, rhs)\n real*8, intent(in) :: lhs\n complex*16, intent(in) :: rhs\n eq_rc = lhs == real(rhs)\n end function eq_rc\n logical function eq_ci(lhs, rhs)\n complex*16, intent(in) :: lhs\n integer, intent(in) :: rhs\n eq_ci = real(lhs) == rhs\n end function eq_ci\n logical function eq_ic(lhs, rhs)\n integer, intent(in) :: lhs\n complex*16, intent(in) :: rhs\n eq_ic = lhs == real(rhs)\n end function eq_ic\n logical function eq_ir(lhs, rhs)\n integer, intent(in) :: lhs\n real*8, intent(in) :: rhs\n eq_ir = lhs == rhs\n end function eq_ir\n logical function eq_ri(lhs, rhs)\n real*8, intent(in) :: lhs\n integer, intent(in) :: rhs\n eq_ri = lhs == rhs\n end function eq_ri\n\n! /=, .ne.\n logical function ne_cc(lhs, rhs)\n complex*16, intent(in) :: lhs, rhs\n ne_cc = real(lhs) /= real(rhs)\n end function ne_cc\n logical function ne_rr(lhs, rhs)\n real*8, intent(in) :: lhs, rhs\n ne_rr = lhs /= rhs\n end function ne_rr\n logical function ne_ii(lhs, rhs)\n integer, intent(in) :: lhs, rhs\n ne_ii = lhs /= rhs\n end function ne_ii\n logical function ne_aa(lhs, rhs)\n character(len=*), intent(in) :: lhs, rhs\n ne_aa = lhs /= rhs\n end function ne_aa\n logical function ne_cr(lhs, rhs)\n complex*16, intent(in) :: lhs\n real*8, intent(in) :: rhs\n ne_cr = real(lhs) /= rhs\n end function ne_cr\n logical function ne_rc(lhs, rhs)\n real*8, intent(in) :: lhs\n complex*16, intent(in) :: rhs\n ne_rc = lhs /= real(rhs)\n end function ne_rc\n logical function ne_ci(lhs, rhs)\n complex*16, intent(in) :: lhs\n integer, intent(in) :: rhs\n ne_ci = real(lhs) /= rhs\n end function ne_ci\n logical function ne_ic(lhs, rhs)\n integer, intent(in) :: lhs\n complex*16, intent(in) :: rhs\n ne_ic = lhs /= real(rhs)\n end function ne_ic\n logical function ne_ir(lhs, rhs)\n integer, intent(in) :: lhs\n real*8, intent(in) :: rhs\n ne_ir = lhs /= rhs\n end function ne_ir\n logical function ne_ri(lhs, rhs)\n real*8, intent(in) :: lhs\n integer, intent(in) :: rhs\n ne_ri = lhs /= rhs\n end function ne_ri\n\n! floor: the largest integer less than or equal to the argument\n function floor_c(z)\n complex*16, intent(in) :: z(:)\n complex*16 floor_c(size(z))\n integer n\n n = size(z)\n floor_c = floor(real(z(1:n)))\n end function floor_c\n\nend module complexify\n\n", "meta": {"hexsha": "4f12368f051d10765ddb2e4dbe5fa81ffbc72d7c", "size": 23717, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/modules/complexify.f90", "max_stars_repo_name": "marcomangano/idwarp", "max_stars_repo_head_hexsha": "3e0d4837a9b926b1cd227654365ca4adfbc08cbe", "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/modules/complexify.f90", "max_issues_repo_name": "marcomangano/idwarp", "max_issues_repo_head_hexsha": "3e0d4837a9b926b1cd227654365ca4adfbc08cbe", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/modules/complexify.f90", "max_forks_repo_name": "marcomangano/idwarp", "max_forks_repo_head_hexsha": "3e0d4837a9b926b1cd227654365ca4adfbc08cbe", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-10-30T01:56:44.000Z", "max_forks_repo_forks_event_max_datetime": "2019-10-30T01:56:44.000Z", "avg_line_length": 25.5846817691, "max_line_length": 79, "alphanum_fraction": 0.6232660117, "num_tokens": 7404, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093946927838, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6638789690101127}} {"text": " SUBROUTINE PRESHYBRID(P0,PS,HYA,HYB,KLVL,PHY)\n IMPLICIT NONE\n\nc NCL: phy = pres_hybrid (ps,p0,hya,hyb)\nc klvl = dimsizes(hya)\nc input\n INTEGER KLVL\n DOUBLE PRECISION P0,PS,HYA(KLVL),HYB(KLVL)\nc output\n DOUBLE PRECISION PHY(KLVL)\nc local\n INTEGER K\n\n DO K = 1,KLVL\n PHY(K) = P0*HYA(K) + HYB(K)*PS\n END DO\n\n RETURN\n END\n\n SUBROUTINE DPRESHYBRID(P0,PS,HYAI,HYBI,KLVL,DPHY)\n IMPLICIT NONE\n\nc NCL: dphy = dpres_hybrid (ps,p0,hyai,hybi)\nc klvl = dimsizes(hyai)\n\nc this routine interploates ccm2/3 hybrid coordinate data\nc to pressure coordinates. These are ordered from top-to-bottom.\n\nc formula for the pressure of a hybrid surface is;\nc phy(k) = hya(k)*p0 + hyb(k)*psfc\n\nc input\nc hyai - is the \"a\" or pressure hybrid coef\nc hybi - is the \"b\" or sigma coeficient\nc p0 - is the base pressure in pascals [Pa]\nc psfc - is the surface pressure in pascals [Pa]\nc output\nc dphy - delta pressure [Pa]\nc INPUT\n INTEGER KLVL\n DOUBLE PRECISION P0,PS,HYAI(KLVL),HYBI(KLVL)\nc OUTPUT\n DOUBLE PRECISION DPHY(KLVL-1)\nc LOCAL\n INTEGER K\n\n DO K = 1,KLVL - 1\n DPHY(K) = ABS(P0* (HYAI(K+1)-HYAI(K))+ (HYAI(K+1)-HYBI(K))*PS)\n END DO\n\n RETURN\n END\n", "meta": {"hexsha": "8b8c90c27299841ff8e4939356ff715813584192", "size": 1512, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ni/src/lib/nfpfort/preshybrid.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "ni/src/lib/nfpfort/preshybrid.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "ni/src/lib/nfpfort/preshybrid.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 28.0, "max_line_length": 72, "alphanum_fraction": 0.5284391534, "num_tokens": 471, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093946927837, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6638789588472014}} {"text": "program spell\n\n implicit none\n integer :: e\n integer :: i\n integer :: m\n integer :: n\n character (9), dimension (19), parameter :: small = &\n & (/'one ', 'two ', 'three ', 'four ', &\n & 'five ', 'six ', 'seven ', 'eight ', &\n & 'nine ', 'ten ', 'eleven ', 'twelve ', &\n & 'thirteen ', 'fourteen ', 'fifteen ', 'sixteen ', &\n & 'seventeen', 'eighteen ', 'nineteen '/)\n character (7), dimension (2 : 9), parameter :: tens = &\n & (/'twenty ', 'thirty ', 'forty ', 'fifty ', 'sixty ', &\n & 'seventy', 'eighty ', 'ninety '/)\n character (8), dimension (3), parameter :: big = &\n & (/'thousand', 'million ', 'billion '/)\n character (256) :: r\n\n do\n read (*, *, iostat = i) n\n if (i /= 0) then\n exit\n end if\n if (n == 0) then\n r = 'zero'\n else\n r = ''\n m = abs (n)\n e = 0\n do\n if (m == 0) then\n exit\n end if\n if (modulo (m, 1000) > 0) then\n if (e > 0) then\n r = trim (big (e)) // ' ' // r\n end if\n if (modulo (m, 100) > 0) then\n if (modulo (m, 100) < 20) then\n r = trim (small (modulo (m, 100))) // ' ' // r\n else\n if (modulo (m, 10) > 0) then\n r = trim (small (modulo (m, 10))) // ' ' // r\n r = trim (tens (modulo (m, 100) / 10)) // '-' // r\n else\n r = trim (tens (modulo (m, 100) / 10)) // ' ' // r\n end if\n end if\n end if\n if (modulo (m, 1000) / 100 > 0) then\n r = 'hundred' // ' ' // r\n r = trim (small (modulo (m, 1000) / 100)) // ' ' // r\n end if\n end if\n m = m / 1000\n e = e + 1\n end do\n if (n < 0) then\n r = 'negative' // ' ' // r\n end if\n end if\n write (*, '(a)') trim (r)\n end do\n\nend program spell\n", "meta": {"hexsha": "a932dc3af78587235c4c3e6ec4dbc6b5670ab0b2", "size": 1950, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Number-names/Fortran/number-names.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/Number-names/Fortran/number-names.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/Number-names/Fortran/number-names.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.6764705882, "max_line_length": 66, "alphanum_fraction": 0.3882051282, "num_tokens": 670, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339756938818, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.663835165330981}} {"text": "program problem83\n implicit none\n integer, parameter :: n=80\n integer, dimension(n,n) :: data\n integer, dimension(n,n) :: state\n integer :: i,j\n\n open(33,file='./data/problem83.dat')\n read(33,*) data\n\n do i=1,n\n do j=1,n\n state(i,j)=huge(state)\n end do\n end do\n\n call search(1,1,0)\n \n print *, state(n,n)\n\ncontains\n\n recursive subroutine search(x,y,previous)\n implicit none\n integer, intent(in) :: x,y,previous\n integer :: current\n\n current=data(x,y)+previous\n if (current1) call search(x-1,y,current)\n if (x1) call search(x,y-1,current)\n if (y c_double\n\n implicit none\n\ncontains\n\n\tsubroutine calc_rot_matrix_zyz(T_rot, alpha, beta, gam) bind(c)\n\t\t! computes rotation matrix (with direction cosines) for coordinate transformation of vector\n\t\t! following the zyz convention:\n\t\t! 1. rotation around z axis,\n\t\t! 2. rotation around rotated y axis,\n\t\t! 3. rotation around rotated z axis,\n\t\t! for further informations see euler angles on wikipedia\n\t\t! for definition of anisotropy (eg transverse isotropy) assume:\n\t\t! y axis to show into northern direction,\n\t\t! x axis to show into eastern direction,\n\t\t! z axis to show into skywards direction,\n\t\t! alpha to be positive in eastern direction,\n\t\t! beta to be positive in downwards direction,\n\t\t! gamma to be zero\n\t\t! for further information see Wittke: 'Rock Mechanics Based on an Anisotropic Jointed Rock Model', p. 44\n\n\t\t! --------------------------------------------------------------------------\n\t\t! passed variables\n\t\treal(kind=dbl), intent(in) :: alpha\t\t! rotation around z axis\n\t\treal(kind=dbl), intent(in) :: beta\t\t! rotation around rotated y axis\n\t\treal(kind=dbl), intent(in) :: gam\t\t! rotation around rotated z axis, in case if transverse isotropy zero\n\n\t\t! return variable\n\t\treal(kind=dbl), dimension(3,3), intent(out) :: T_rot\t\t! rotation matrix with direction cosines between old an rotated coordinate basis\n\n\t\t! internal variables\n\t\treal(kind=dbl), dimension(3,3) :: Tz1\t! rotation matrix for first rotation around z axis\n\t\treal(kind=dbl), dimension(3,3) :: Ty2\t! rotation matrix for second rotation around rotated y axis\n\t\treal(kind=dbl), dimension(3,3) :: Tz3\t! rotation matrix for third rotation around rotated z axis\n\t\treal(kind=dbl), dimension(3,3) :: Tzyz\t! rotation matrix all three above combined into one: Tz1*Ty2*Tz3\n\t\t! --------------------------------------------------------------------------\n\n\t\tTz1 = reshape( (/ cos(-gam), -sin(-gam), 0._dbl, sin(-gam), cos(-gam), 0._dbl, 0._dbl, 0._dbl, 1._dbl /), (/3,3/) )\n\t\tTy2 = reshape( (/ cos(beta), 0._dbl, sin(beta), 0._dbl, 1._dbl, 0._dbl, -sin(beta), 0._dbl, cos(beta) /), (/3,3/) )\n\t\tTz3 = reshape( (/ cos(-alpha), -sin(-alpha), 0._dbl, sin(-alpha), cos(-alpha), 0._dbl, 0._dbl, 0._dbl, 1._dbl /), (/3,3/) )\n\t\tT_rot = transpose(matmul(Tz1, matmul(Ty2, Tz3) ))\n\n\n\tend subroutine calc_rot_matrix_zyz\n\n\n\n\tfunction mcauly(x) bind(c)\n\t\t! computes (mcauly brackets\n\t\t! if x < 0 => = 0\n\t\t! if x >= 0 => = x\n\t\timplicit none\n\n\t\t! --------------------------------------------------------------------------\n\t\t! return variable\n\t\treal(kind=dbl) :: mcauly\n\n\t\t! passed variable\n\t\treal(kind=dbl), intent(in) :: x\n\t\t! --------------------------------------------------------------------------\n\n\t\tif (x < 0._dbl) then\n\n\t\t\tmcauly = 0._dbl\n\n\t\telse\n\n\t\t\tmcauly = x\n\n\t\tend if\n\n\tend function mcauly\n\n\n\telemental function mcauly_elemental(x)\n\t\t! computes (mcauly brackets\n\t\t! if x < 0 => = 0\n\t\t! if x >= 0 => = x\n\t\timplicit none\n\n\t\t! --------------------------------------------------------------------------\n\t\t! return variable\n\t\treal(kind=dbl) :: mcauly_elemental\n\n\t\t! passed variable\n\t\treal(kind=dbl), intent(in) :: x\n\t\t! --------------------------------------------------------------------------\n\n\t\tif (x < 0._dbl) then\n\n\t\t\tmcauly_elemental = 0._dbl\n\n\t\telse\n\n\t\t\tmcauly_elemental = x\n\n\t\tend if\n\n\tend function mcauly_elemental\n\n\n\tfunction heaviside(x) bind(c)\n\t\t! computes heaviside function H(x)\n\t\t! if x < 0 => H(x) = 0\n\t\t! if x >= 0 => H(x) = 1\n\t\timplicit none\n\n\t\t! --------------------------------------------------------------------------\n\t\t! return variable\n\t\treal(kind=dbl) :: heaviside\n\n\t\t! passed variable\n\t\treal(kind=dbl), intent(in) :: x\n\t\t! --------------------------------------------------------------------------\n\n\t\tif (x < 0._dbl) then\n\n\t\t\theaviside = 0._dbl\n\n\t\telse\n\n\t\t\theaviside = 1._dbl\n\n\t\tend if\n\n\tend function heaviside\n\n\n\telemental function heaviside_elemental(x)\n\t\t! computes heaviside function H(x)\n\t\t! if x < 0 => H(x) = 0\n\t\t! if x >= 0 => H(x) = 1\n\t\timplicit none\n\n\t\t! --------------------------------------------------------------------------\n\t\t! return variable\n\t\treal(kind=dbl) :: heaviside_elemental\n\n\t\t! passed variable\n\t\treal(kind=dbl), intent(in) :: x\n\t\t! --------------------------------------------------------------------------\n\n\t\tif (x < 0._dbl) then\n\n\t\t\theaviside_elemental = 0._dbl\n\n\t\telse\n\n\t\t\theaviside_elemental = 1._dbl\n\n\t\tend if\n\n\tend function heaviside_elemental\n\nend module math_routines_lib\n", "meta": {"hexsha": "46690a67abcef63debfae0be052859c425abe76a", "size": 4595, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "libraries/math_routines_lib.f90", "max_stars_repo_name": "yuyong1990/TsaiWu-Fortran", "max_stars_repo_head_hexsha": "a111ca1717adfbbaf3e9e34f4189a441e16441b8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2017-11-19T15:12:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T15:34:59.000Z", "max_issues_repo_path": "libraries/math_routines_lib.f90", "max_issues_repo_name": "OVGULIU/TsaiWu-Fortran", "max_issues_repo_head_hexsha": "a111ca1717adfbbaf3e9e34f4189a441e16441b8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "libraries/math_routines_lib.f90", "max_forks_repo_name": "OVGULIU/TsaiWu-Fortran", "max_forks_repo_head_hexsha": "a111ca1717adfbbaf3e9e34f4189a441e16441b8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 16, "max_forks_repo_forks_event_min_datetime": "2017-02-11T12:56:43.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-01T11:29:18.000Z", "avg_line_length": 28.3641975309, "max_line_length": 136, "alphanum_fraction": 0.5562568009, "num_tokens": 1323, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127603871312, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.6637462701042144}} {"text": "module test_rawmoment\n use testdrive, only : new_unittest, unittest_type, error_type, check\n use stdlib_kinds, only: sp, dp, int32\n use stdlib_stats, only: mean, moment\n use,intrinsic :: ieee_arithmetic, only : ieee_is_nan\n implicit none\n\n\n real(sp), parameter :: sptol = 1000 * epsilon(1._sp)\n real(dp), parameter :: dptol = 1000 * epsilon(1._dp)\n\n real(dp), parameter :: d1(5) = [1.0_dp, 2.0_dp, 3.0_dp, 4.0_dp, 5.0_dp]\n real(dp), parameter :: d(4, 3) = reshape([1._dp, 3._dp, 5._dp, 7._dp,&\n 2._dp, 4._dp, 6._dp, 8._dp,&\n 9._dp, 10._dp, 11._dp, 12._dp], [4, 3])\n\n\n complex(sp), parameter :: cs1(5) = [ cmplx(0.57706_sp, 0.00000_sp),&\n cmplx(0.00000_sp, 1.44065_sp),&\n cmplx(1.26401_sp, 0.00000_sp),&\n cmplx(0.00000_sp, 0.88833_sp),&\n cmplx(1.14352_sp, 0.00000_sp)]\n complex(sp), parameter :: cs(5,3) = reshape([cs1, cs1*3.0_sp, cs1*1.5_sp], shape(cs))\n\n\n\n\ncontains\n\n\n !> Collect all exported unit tests\n subroutine collect_rawmoment(testsuite)\n !> Collection of tests\n type(unittest_type), allocatable, intent(out) :: testsuite(:)\n\n testsuite = [ &\n new_unittest(\"sp\", test_sp), &\n new_unittest(\"int32\", test_int32), &\n new_unittest(\"csp\", test_csp) &\n ]\n end subroutine collect_rawmoment\n\n subroutine test_sp(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n real(sp), parameter :: x1(5) = d1\n real(sp), parameter :: x2(4, 3) = d\n\n integer :: order\n real(sp), allocatable :: x3(:, :, :)\n real(sp), allocatable :: zero2_1(:), zero2_2(:)\n real(sp), allocatable :: zero3_1(:,:), zero3_2(:,:), zero3_3(:,:)\n\n allocate(zero2_1(size(x2, 2)), zero2_2(size(x2, 1)))\n zero2_1 = 0\n zero2_2 = 0\n\n order = 1\n\n !1dim\n print*,' test_sp_1dim', order\n call check(error, abs(moment(x1, order, center = 0.) - mean(x1)) < sptol)\n call check(error, abs(moment(x1, order, 1, center = 0.) - mean(x1)) < sptol)\n\n print*,' test_sp_1dim_mask', order\n call check(error, ieee_is_nan(moment(x1, order, center = 0., mask = .false.)))\n call check(error, ieee_is_nan(moment(x1, order, dim = 1, center = 0., mask = .false.)))\n\n print*,' test_sp_1dim_mask_array', order\n call check(error, abs(moment(x1, order, center = 0., mask = (x1 < 5)) -&\n mean(x1, mask = (x1 < 5)) ) < sptol)\n call check(error, abs(moment(x1, order, dim = 1, center = 0., mask = (x1 < 5)) -&\n mean(x1, dim = 1, mask = (x1 < 5))) < sptol)\n\n !2dim\n print*,' test_sp_2dim', order\n call check(error, abs(moment(x2, order, center = 0.) - mean(x2)) < sptol)\n call check(error, all( abs( moment(x2, order, dim = 1, center = 0.) -&\n mean(x2, dim = 1)) < sptol))\n call check(error, all( abs( moment(x2, order, dim = 2, center = 0.) -&\n mean(x2, dim = 2)) < sptol))\n call check(error, all( abs( moment(x2, order, dim = 1, center = zero2_1) -&\n mean(x2, dim = 1)) < sptol))\n call check(error, all( abs( moment(x2, order, dim = 2, center = zero2_2) -&\n mean(x2, dim = 2)) < sptol))\n\n print*,' test_sp_2dim_mask', order\n call check(error, ieee_is_nan(moment(x2, order, center = 0., mask = .false.)))\n call check(error, any(ieee_is_nan(moment(x2, order, dim = 1, center = zero2_1,&\n mask = .false.))))\n call check(error, any(ieee_is_nan(moment(x2, order, dim = 2, center = zero2_2,&\n mask = .false.))))\n\n print*,' test_sp_2dim_mask_array', order\n call check(error, abs(moment(x2, order, center = 0., mask = (x2 < 11)) -&\n mean(x2, x2 < 11)) < sptol)\n call check(error, all( abs( moment(x2, order, dim = 1, center = 0.,&\n mask = (x2 < 11)) -&\n mean(x2, 1, x2 < 11)) < sptol))\n call check(error, all( abs( moment(x2, order, dim = 2, center = 0.,&\n mask = (x2 < 11)) -&\n mean(x2, 2, x2 < 11)) < sptol))\n call check(error, all( abs( moment(x2, order, dim = 1, center = zero2_1,&\n mask = (x2 < 11)) -&\n mean(x2, 1, x2 < 11)) < sptol))\n call check(error, all( abs( moment(x2, order, dim = 2, center = zero2_2,&\n mask = (x2 < 11)) -&\n mean(x2, 2, x2 < 11)) < sptol))\n\n !3dim\n allocate(x3(size(x2,1),size(x2,2),3))\n x3(:,:,1)=x2;\n x3(:,:,2)=x2*2;\n x3(:,:,3)=x2*4;\n\n allocate(zero3_1(size(x3, 2), size(x3, 3))&\n ,zero3_2(size(x3, 1), size(x3, 3))&\n ,zero3_3(size(x3, 1), size(x3, 2)))\n zero3_1 = 0\n zero3_2 = 0\n zero3_3 = 0\n\n print*,' test_sp_3dim', order\n call check(error, abs(moment(x3, order, center = 0.) - mean(x3)) < sptol)\n call check(error, all( abs( moment(x3, order, dim = 1, center = 0._sp) -&\n mean(x3, 1)) < sptol))\n call check(error, all( abs( moment(x3, order, dim = 2, center = 0._sp) -&\n mean(x3, 2)) < sptol))\n call check(error, all( abs( moment(x3, order, dim = 3, center = 0._sp) -&\n mean(x3, 3)) < sptol))\n call check(error, all( abs( moment(x3, order, dim = 1, center = zero3_1) -&\n mean(x3, 1)) < sptol))\n call check(error, all( abs( moment(x3, order, dim = 2, center = zero3_2) -&\n mean(x3, 2)) < sptol))\n call check(error, all( abs( moment(x3, order, dim = 3, center = zero3_3) -&\n mean(x3, 3)) < sptol))\n\n print*,' test_sp_3dim_mask', order\n call check(error, ieee_is_nan(moment(x3, order, center = 0., mask = .false.)))\n call check(error, any(ieee_is_nan(moment(x3, order, dim = 1, center = zero3_1,&\n mask = .false.))))\n call check(error, any(ieee_is_nan(moment(x3, order, dim = 2, center = zero3_2,&\n mask = .false.))))\n call check(error, any(ieee_is_nan(moment(x3, order, dim = 3, center = zero3_3,&\n mask = .false.))))\n\n print*,' test_sp_3dim_mask_array', order\n call check(error, abs(moment(x3, order, center = 0., mask = (x3 < 11)) -&\n mean(x3, x3 < 11)) < sptol)\n call check(error, all( abs( moment(x3, order, dim = 1, center = 0.,&\n mask = (x3 < 45)) -&\n mean(x3, 1, x3 < 45)) < sptol ))\n call check(error, all( abs( moment(x3, order, dim = 2, center = 0.,&\n mask = (x3 < 45)) -&\n mean(x3, 2, x3 < 45)) < sptol ))\n call check(error, all( abs( moment(x3, order, dim = 3, center = 0.,&\n mask = (x3 < 45)) -&\n mean(x3, 3, x3 < 45)) < sptol ))\n call check(error, all( abs( moment(x3, order, dim = 1, center = zero3_1,&\n mask = (x3 < 45)) -&\n mean(x3, 1, x3 < 45)) < sptol ))\n call check(error, all( abs( moment(x3, order, dim = 2, center = zero3_2,&\n mask = (x3 < 45)) -&\n mean(x3, 2, x3 < 45)) < sptol ))\n call check(error, all( abs( moment(x3, order, dim = 3, center = zero3_3,&\n mask = (x3 < 45)) -&\n mean(x3, 3, x3 < 45)) < sptol ))\n\n\n order = 2\n\n !1dim\n print*,' test_sp_1dim', order\n call check(error, abs(moment(x1, order, center = 0.) - mean(x1**2)) < sptol)\n call check(error, abs(moment(x1, order, 1, center = 0.) - mean(x1**2, 1)) < sptol)\n\n print*,' test_sp_1dim_mask', order\n call check(error, ieee_is_nan(moment(x1, order, center = 0., mask = .false.)))\n call check(error, ieee_is_nan(moment(x1, order, dim = 1, center = 0., mask = .false.)))\n\n print*,' test_sp_1dim_mask_array', order\n call check(error, abs(moment(x1, order, center = 0., mask = (x1 < 5)) -&\n mean(x1**2, x1 < 5)) < sptol)\n call check(error, abs(moment(x1, order, dim = 1, center = 0., mask = (x1 < 5)) -&\n mean(x1**2, 1, x1 < 5)) < sptol)\n\n !2dim\n print*,' test_sp_2dim', order\n call check(error, abs(moment(x2, order, center = 0.) - mean(x2**2)) < sptol)\n call check(error, all( abs( moment(x2, order, dim = 1, center = 0.) -&\n mean(x2**2, 1)) < sptol))\n call check(error, all( abs( moment(x2, order, dim = 2, center = 0.) - &\n mean(x2**2, 2)) < sptol))\n call check(error, all( abs( moment(x2, order, dim = 1, center = zero2_1) -&\n mean(x2**2, 1)) < sptol))\n call check(error, all( abs( moment(x2, order, dim = 2, center = zero2_2) - &\n mean(x2**2, 2)) < sptol))\n\n print*,' test_sp_2dim_mask', order\n call check(error, ieee_is_nan(moment(x2, order, center = 0., mask = .false.)))\n call check(error, any(ieee_is_nan(moment(x2, order, dim = 1, center = zero2_1, &\n mask = .false.))))\n call check(error, any(ieee_is_nan(moment(x2, order, dim = 2, center = zero2_2, &\n mask = .false.))))\n\n print*,' test_sp_2dim_mask_array', order\n call check(error, abs(moment(x2, order, center = 0., mask = (x2 < 11)) -&\n mean(x2**2, x2 < 11)) < sptol)\n call check(error, all( abs( moment(x2, order, dim = 1, center = 0.,&\n mask = (x2 < 11)) -&\n mean(x2**2, 1, x2 < 11)) < sptol))\n call check(error, all( abs( moment(x2, order, dim = 2, center = 0.,&\n mask = (x2 < 11)) -&\n mean(x2**2, 2, x2 < 11)) < sptol))\n call check(error, all( abs( moment(x2, order, dim = 1, center = zero2_1,&\n mask = (x2 < 11)) -&\n mean(x2**2, 1, x2 < 11)) < sptol))\n call check(error, all( abs( moment(x2, order, dim = 2, center = zero2_2,&\n mask = (x2 < 11)) -&\n mean(x2**2, 2, x2 < 11)) < sptol))\n\n !3dim\n print*,' test_sp_3dim', order\n call check(error, abs(moment(x3, order, center = 0.) - mean(x3**2)) < sptol)\n call check(error, all( abs( moment(x3, order, dim = 1, center = 0.) -&\n mean(x3**2, 1)) < sptol))\n call check(error, all( abs( moment(x3, order, dim = 2, center = 0.) -&\n mean(x3**2, 2)) < sptol))\n call check(error, all( abs( moment(x3, order, dim = 3, center = 0.) -&\n mean(x3**2, 3)) < sptol))\n call check(error, all( abs( moment(x3, order, dim = 1, center = zero3_1) -&\n mean(x3**2, 1)) < sptol))\n call check(error, all( abs( moment(x3, order, dim = 2, center = zero3_2) -&\n mean(x3**2, 2)) < sptol))\n call check(error, all( abs( moment(x3, order, dim = 3, center = zero3_3) -&\n mean(x3**2, 3)) < sptol))\n\n print*,' test_sp_3dim_mask', order\n call check(error, ieee_is_nan(moment(x3, order, center = 0., mask = .false.)))\n call check(error, any(ieee_is_nan(moment(x3, order, dim = 1, center = zero3_1,&\n mask = .false.))))\n call check(error, any(ieee_is_nan(moment(x3, order, dim = 2, center = zero3_2,&\n mask = .false.))))\n call check(error, any(ieee_is_nan(moment(x3, order, dim = 3, center = zero3_3,&\n mask = .false.))))\n\n print*,' test_sp_3dim_mask_array', order\n call check(error, abs(moment(x3, order, center = 0., mask = (x3 < 11)) -&\n mean(x3**2, x3 < 11)) < sptol)\n call check(error, all( abs( moment(x3, order, dim = 1, center = 0.,&\n mask = (x3 < 45)) -&\n mean(x3**2, 1, x3 < 45)) < sptol ))\n call check(error, all( abs( moment(x3, order, dim = 2, center = 0.,&\n mask = (x3 < 45)) -&\n mean(x3**2, 2, x3 < 45)) < sptol ))\n call check(error, all( abs( moment(x3, order, dim = 3, center = 0.,&\n mask = (x3 < 45)) -&\n mean(x3**2, 3, x3 < 45)) < sptol ))\n call check(error, all( abs( moment(x3, order, dim = 1, center = zero3_1,&\n mask = (x3 < 45)) -&\n mean(x3**2, 1, x3 < 45)) < sptol ))\n call check(error, all( abs( moment(x3, order, dim = 2, center = zero3_2,&\n mask = (x3 < 45)) -&\n mean(x3**2, 2, x3 < 45)) < sptol ))\n call check(error, all( abs( moment(x3, order, dim = 3, center = zero3_3,&\n mask = (x3 < 45)) -&\n mean(x3**2, 3, x3 < 45)) < sptol ))\n\n end subroutine\n\n subroutine test_int32(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n integer(int32), parameter :: x1(5) = d1\n integer(int32), parameter :: x2(4, 3) = d\n\n integer :: order\n integer(int32), allocatable :: x3(:, :, :)\n real(dp), allocatable :: zero2_1(:), zero2_2(:)\n real(dp), allocatable :: zero3_1(:,:), zero3_2(:,:), zero3_3(:,:)\n\n allocate(zero2_1(size(x2, 2)), zero2_2(size(x2, 1)))\n zero2_1 = 0\n zero2_2 = 0\n\n order = 1\n\n !1dim\n print*,' test_sp_1dim', order\n call check(error, abs(moment(x1, order, center = 0._dp) - mean(x1)) < sptol)\n call check(error, abs(moment(x1, order, 1, center = 0._dp) - mean(x1)) < sptol)\n\n print*,' test_sp_1dim_mask', order\n call check(error, ieee_is_nan(moment(x1, order, center = 0._dp, mask = .false.)))\n call check(error, ieee_is_nan(moment(x1, order, dim = 1, center = 0._dp,&\n mask = .false.)))\n\n print*,' test_sp_1dim_mask_array', order\n call check(error, abs(moment(x1, order, center = 0._dp, mask = (x1 < 5)) -&\n mean(x1, mask = (x1 < 5)) ) < sptol)\n call check(error, abs(moment(x1, order, dim = 1, center = 0._dp, mask = (x1 < 5)) -&\n mean(x1, dim = 1, mask = (x1 < 5))) < sptol)\n\n !2dim\n print*,' test_sp_2dim', order\n call check(error, abs(moment(x2, order, center = 0._dp) - mean(x2)) < sptol)\n call check(error, all( abs( moment(x2, order, dim = 1, center = 0._dp) -&\n mean(x2, dim = 1)) < sptol))\n call check(error, all( abs( moment(x2, order, dim = 2, center = 0._dp) -&\n mean(x2, dim = 2)) < sptol))\n call check(error, all( abs( moment(x2, order, dim = 1, center = zero2_1) -&\n mean(x2, dim = 1)) < sptol))\n call check(error, all( abs( moment(x2, order, dim = 2, center = zero2_2) -&\n mean(x2, dim = 2)) < sptol))\n\n print*,' test_sp_2dim_mask', order\n call check(error, ieee_is_nan(moment(x2, order, center = 0._dp, mask = .false.)))\n call check(error, any(ieee_is_nan(moment(x2, order, dim = 1, center = zero2_1,&\n mask = .false.))))\n call check(error, any(ieee_is_nan(moment(x2, order, dim = 2, center = zero2_2,&\n mask = .false.))))\n\n print*,' test_sp_2dim_mask_array', order\n call check(error, abs(moment(x2, order, center = 0._dp, mask = (x2 < 11)) -&\n mean(x2, x2 < 11)) < sptol)\n call check(error, all( abs( moment(x2, order, dim = 1, center = 0._dp,&\n mask = (x2 < 11)) -&\n mean(x2, 1, x2 < 11)) < sptol))\n call check(error, all( abs( moment(x2, order, dim = 2, center = 0._dp,&\n mask = (x2 < 11)) -&\n mean(x2, 2, x2 < 11)) < sptol))\n call check(error, all( abs( moment(x2, order, dim = 1, center = zero2_1,&\n mask = (x2 < 11)) -&\n mean(x2, 1, x2 < 11)) < sptol))\n call check(error, all( abs( moment(x2, order, dim = 2, center = zero2_2,&\n mask = (x2 < 11)) -&\n mean(x2, 2, x2 < 11)) < sptol))\n\n !3dim\n allocate(x3(size(x2,1),size(x2,2),3))\n x3(:,:,1)=x2;\n x3(:,:,2)=x2*2;\n x3(:,:,3)=x2*4;\n\n allocate(zero3_1(size(x3, 2), size(x3, 3))&\n ,zero3_2(size(x3, 1), size(x3, 3))&\n ,zero3_3(size(x3, 1), size(x3, 2)))\n zero3_1 = 0\n zero3_2 = 0\n zero3_3 = 0\n\n print*,' test_sp_3dim', order\n call check(error, abs(moment(x3, order, center = 0._dp) - mean(x3)) < sptol)\n call check(error, all( abs( moment(x3, order, dim = 1, center = 0._dp) -&\n mean(x3, 1)) < sptol))\n call check(error, all( abs( moment(x3, order, dim = 2, center = 0._dp) -&\n mean(x3, 2)) < sptol))\n call check(error, all( abs( moment(x3, order, dim = 3, center = 0._dp) -&\n mean(x3, 3)) < sptol))\n call check(error, all( abs( moment(x3, order, dim = 1, center = zero3_1) -&\n mean(x3, 1)) < sptol))\n call check(error, all( abs( moment(x3, order, dim = 2, center = zero3_2) -&\n mean(x3, 2)) < sptol))\n call check(error, all( abs( moment(x3, order, dim = 3, center = zero3_3) -&\n mean(x3, 3)) < sptol))\n\n print*,' test_sp_3dim_mask', order\n call check(error, ieee_is_nan(moment(x3, order, center = 0._dp, mask = .false.)))\n call check(error, any(ieee_is_nan(moment(x3, order, dim = 1, center = zero3_1,&\n mask = .false.))))\n call check(error, any(ieee_is_nan(moment(x3, order, dim = 2, center = zero3_2,&\n mask = .false.))))\n call check(error, any(ieee_is_nan(moment(x3, order, dim = 3, center = zero3_3,&\n mask = .false.))))\n\n print*,' test_sp_3dim_mask_array', order\n call check(error, abs(moment(x3, order, center = 0._dp, mask = (x3 < 11)) -&\n mean(x3, x3 < 11)) < sptol)\n call check(error, all( abs( moment(x3, order, dim = 1, center = 0._dp,&\n mask = (x3 < 45)) -&\n mean(x3, 1, x3 < 45)) < sptol ))\n call check(error, all( abs( moment(x3, order, dim = 2, center = 0._dp,&\n mask = (x3 < 45)) -&\n mean(x3, 2, x3 < 45)) < sptol ))\n call check(error, all( abs( moment(x3, order, dim = 3, center = 0._dp,&\n mask = (x3 < 45)) -&\n mean(x3, 3, x3 < 45)) < sptol ))\n call check(error, all( abs( moment(x3, order, dim = 1, center = zero3_1,&\n mask = (x3 < 45)) -&\n mean(x3, 1, x3 < 45)) < sptol ))\n call check(error, all( abs( moment(x3, order, dim = 2, center = zero3_2,&\n mask = (x3 < 45)) -&\n mean(x3, 2, x3 < 45)) < sptol ))\n call check(error, all( abs( moment(x3, order, dim = 3, center = zero3_3,&\n mask = (x3 < 45)) -&\n mean(x3, 3, x3 < 45)) < sptol ))\n\n\n order = 2\n\n !1dim\n print*,' test_sp_1dim', order\n call check(error, abs(moment(x1, order, center = 0._dp) - mean(x1**2)) < sptol)\n call check(error, abs(moment(x1, order, 1, center = 0._dp) - mean(x1**2, 1)) < sptol)\n\n print*,' test_sp_1dim_mask', order\n call check(error, ieee_is_nan(moment(x1, order, center = 0._dp, mask = .false.)))\n call check(error, ieee_is_nan(moment(x1, order, dim = 1, center = 0._dp,&\n mask = .false.)))\n\n print*,' test_sp_1dim_mask_array', order\n call check(error, abs(moment(x1, order, center = 0._dp, mask = (x1 < 5)) -&\n mean(x1**2, x1 < 5)) < sptol)\n call check(error, abs(moment(x1, order, dim = 1, center = 0._dp, mask = (x1 < 5)) -&\n mean(x1**2, 1, x1 < 5)) < sptol)\n\n !2dim\n print*,' test_sp_2dim', order\n call check(error, abs(moment(x2, order, center = 0._dp) - mean(x2**2)) < sptol)\n call check(error, all( abs( moment(x2, order, dim = 1, center = 0._dp) -&\n mean(x2**2, 1)) < sptol))\n call check(error, all( abs( moment(x2, order, dim = 2, center = 0._dp) -&\n mean(x2**2, 2)) < sptol))\n call check(error, all( abs( moment(x2, order, dim = 1, center = zero2_1) -&\n mean(x2**2, 1)) < sptol))\n call check(error, all( abs( moment(x2, order, dim = 2, center = zero2_2) -&\n mean(x2**2, 2)) < sptol))\n\n print*,' test_sp_2dim_mask', order\n call check(error, ieee_is_nan(moment(x2, order, center = 0._dp, mask = .false.)))\n call check(error, any(ieee_is_nan(moment(x2, order, dim = 1, center = 0._dp,&\n mask = .false.))))\n call check(error, any(ieee_is_nan(moment(x2, order, dim = 2, center = 0._dp,&\n mask = .false.))))\n call check(error, any(ieee_is_nan(moment(x2, order, dim = 1, center = zero2_1,&\n mask = .false.))))\n call check(error, any(ieee_is_nan(moment(x2, order, dim = 2, center = zero2_2,&\n mask = .false.))))\n\n print*,' test_sp_2dim_mask_array', order\n call check(error, abs(moment(x2, order, center = 0._dp, mask = (x2 < 11)) -&\n mean(x2**2, x2 < 11)) < sptol)\n call check(error, all( abs( moment(x2, order, dim = 1, center = 0._dp,&\n mask = (x2 < 11)) -&\n mean(x2**2, 1, x2 < 11)) < sptol))\n call check(error, all( abs( moment(x2, order, dim = 2, center = 0._dp,&\n mask = (x2 < 11)) -&\n mean(x2**2, 2, x2 < 11)) < sptol))\n call check(error, all( abs( moment(x2, order, dim = 1, center = zero2_1,&\n mask = (x2 < 11)) -&\n mean(x2**2, 1, x2 < 11)) < sptol))\n call check(error, all( abs( moment(x2, order, dim = 2, center = zero2_2,&\n mask = (x2 < 11)) -&\n mean(x2**2, 2, x2 < 11)) < sptol))\n\n !3dim\n print*,' test_sp_3dim', order\n call check(error, abs(moment(x3, order, center = 0._dp) - mean(x3**2)) < sptol)\n call check(error, all( abs( moment(x3, order, dim = 1, center = 0._dp) -&\n mean(x3**2, 1)) < sptol))\n call check(error, all( abs( moment(x3, order, dim = 2, center = 0._dp) -&\n mean(x3**2, 2)) < sptol))\n call check(error, all( abs( moment(x3, order, dim = 3, center = 0._dp) -&\n mean(x3**2, 3)) < sptol))\n call check(error, all( abs( moment(x3, order, dim = 1, center = zero3_1) -&\n mean(x3**2, 1)) < sptol))\n call check(error, all( abs( moment(x3, order, dim = 2, center = zero3_2) -&\n mean(x3**2, 2)) < sptol))\n call check(error, all( abs( moment(x3, order, dim = 3, center = zero3_3) -&\n mean(x3**2, 3)) < sptol))\n\n print*,' test_sp_3dim_mask', order\n call check(error, ieee_is_nan(moment(x3, order, center = 0._dp, mask = .false.)))\n call check(error, any(ieee_is_nan(moment(x3, order, dim = 1, center = 0._dp,&\n mask = .false.))))\n call check(error, any(ieee_is_nan(moment(x3, order, dim = 2, center = 0._dp,&\n mask = .false.))))\n call check(error, any(ieee_is_nan(moment(x3, order, dim = 3, center = 0._dp,&\n mask = .false.))))\n call check(error, any(ieee_is_nan(moment(x3, order, dim = 1, center = zero3_1,&\n mask = .false.))))\n call check(error, any(ieee_is_nan(moment(x3, order, dim = 2, center = zero3_2,&\n mask = .false.))))\n call check(error, any(ieee_is_nan(moment(x3, order, dim = 3, center = zero3_3,&\n mask = .false.))))\n\n print*,' test_sp_3dim_mask_array', order\n call check(error, abs(moment(x3, order, center = 0._dp, mask = (x3 < 11)) -&\n mean(x3**2, x3 < 11)) < sptol)\n call check(error, all( abs( moment(x3, order, dim = 1, center = 0._dp,&\n mask = (x3 < 45)) -&\n mean(x3**2, 1, x3 < 45)) < sptol ))\n call check(error, all( abs( moment(x3, order, dim = 2, center = 0._dp,&\n mask = (x3 < 45)) -&\n mean(x3**2, 2, x3 < 45)) < sptol ))\n call check(error, all( abs( moment(x3, order, dim = 3, center = 0._dp,&\n mask = (x3 < 45)) -&\n mean(x3**2, 3, x3 < 45)) < sptol ))\n call check(error, all( abs( moment(x3, order, dim = 1, center = zero3_1,&\n mask = (x3 < 45)) -&\n mean(x3**2, 1, x3 < 45)) < sptol ))\n call check(error, all( abs( moment(x3, order, dim = 2, center = zero3_2,&\n mask = (x3 < 45)) -&\n mean(x3**2, 2, x3 < 45)) < sptol ))\n call check(error, all( abs( moment(x3, order, dim = 3, center = zero3_3,&\n mask = (x3 < 45)) -&\n mean(x3**2, 3, x3 < 45)) < sptol ))\n\n end subroutine\n\n subroutine test_csp(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n complex(sp), parameter :: x1(5) = cs1\n complex(sp), parameter :: x2(5, 3) = cs\n\n integer :: order\n complex(sp), allocatable :: zero2_1(:), zero2_2(:)\n\n allocate(zero2_1(size(x2, 2)), zero2_2(size(x2, 1)))\n zero2_1 = (0., 0.)\n zero2_2 = (0., 0.)\n\n order = 1\n\n !1dim\n print*,' test_sp_1dim', order\n call check(error, abs(moment(x1, order, center = (0., 0.)) - mean(x1)) < sptol)\n call check(error, abs(moment(x1, order, 1, center = (0., 0.)) - mean(x1, 1)) < sptol)\n\n print*,' test_sp_1dim_mask', order\n call check(error, ieee_is_nan(abs(moment(x1, order, center = (0., 0.),&\n mask = .false.))))\n call check(error, ieee_is_nan(abs(moment(x1, order, dim = 1, center = (0., 0.),&\n mask = .false.))))\n\n print*,' test_sp_1dim_mask_array', order\n call check(error, abs(moment(x1, order, center = (0., 0.), mask = (aimag(x1) == 0)) -&\n mean(x1, aimag(x1) == 0)) < sptol)\n call check(error, abs(moment(x1, order, dim = 1, center = (0., 0.),&\n mask = (aimag(x1) == 0)) -&\n mean(x1, 1, aimag(x1) == 0)) < sptol)\n\n !2dim\n print*,' test_sp_2dim', order\n call check(error, abs(moment(x2, order, center = (0., 0.)) - mean(x2)) < sptol)\n call check(error, all( abs( moment(x2, order, dim = 1, center = (0., 0.)) -&\n mean(x2, 1)) < sptol))\n call check(error, all( abs( moment(x2, order, dim = 2, center = (0., 0.)) -&\n mean(x2, 2)) < sptol))\n call check(error, all( abs( moment(x2, order, dim = 1, center = zero2_1) -&\n mean(x2, 1)) < sptol))\n call check(error, all( abs( moment(x2, order, dim = 2, center = zero2_2) -&\n mean(x2, 2)) < sptol))\n\n print*,' test_sp_2dim_mask', order\n call check(error, ieee_is_nan(abs(moment(x2, order, center = (0., 0.),&\n mask = .false.))))\n call check(error, any(ieee_is_nan(abs(moment(x2, order, dim = 1, center = (0., 0.),&\n mask = .false.)))))\n call check(error, any(ieee_is_nan(abs(moment(x2, order, dim = 2, center = (0., 0.),&\n mask = .false.)))))\n call check(error, any(ieee_is_nan(abs(moment(x2, order, dim = 1, center = zero2_1,&\n mask = .false.)))))\n call check(error, any(ieee_is_nan(abs(moment(x2, order, dim = 2, center = zero2_2,&\n mask = .false.)))))\n\n print*,' test_sp_2dim_mask_array', order\n call check(error, abs(moment(x2, order, center = (0., 0.), mask = (aimag(x2) == 0)) -&\n mean(x2, aimag(x2) == 0)) < sptol)\n call check(error, all( abs( moment(x2, order, dim = 1, center = (0., 0.),&\n mask = (aimag(x2) == 0)) -&\n mean(x2, 1, aimag(x2) == 0)) < sptol))\n call check(error, any(ieee_is_nan( abs( moment(x2, order,&\n dim = 2, center = (0., 0.), mask = (aimag(x2) == 0)) -&\n mean(x2, 2, aimag(x2) == 0)))))\n call check(error, all( abs( moment(x2, order, dim = 1, center = zero2_1,&\n mask = (aimag(x2) == 0)) -&\n mean(x2, 1, aimag(x2) == 0)) < sptol))\n call check(error, any(ieee_is_nan( abs( moment(x2, order,&\n dim = 2, center = zero2_2, mask = (aimag(x2) == 0)) -&\n mean(x2, 2, aimag(x2) == 0)))))\n\n order = 2\n\n !1dim\n print*,' test_sp_1dim', order\n call check(error, abs(moment(x1, order, center = (0., 0.)) - mean(x1**2)) < sptol)\n call check(error, abs(moment(x1, order, 1, center = (0., 0.)) -&\n mean(x1**2, 1)) < sptol)\n\n print*,' test_sp_1dim_mask', order\n call check(error, ieee_is_nan(abs(moment(x1, order, center = (0., 0.),&\n mask = .false.))))\n call check(error, ieee_is_nan(abs(moment(x1, order, dim = 1, center = (0., 0.),&\n mask = .false.))))\n\n print*,' test_sp_1dim_mask_array', order\n call check(error, abs(moment(x1, order, center = (0., 0.), mask = (aimag(x1) == 0)) -&\n mean(x1**2, aimag(x1) == 0)) < sptol)\n call check(error, abs(moment(x1, order, dim = 1, center = (0., 0.),&\n mask = (aimag(x1) == 0)) -&\n mean(x1**2, 1, aimag(x1) == 0)) < sptol)\n\n !2dim\n print*,' test_sp_2dim', order\n call check(error, abs(moment(x2, order, center = (0., 0.)) - mean(x2**2)) < sptol)\n call check(error, all( abs( moment(x2, order, dim = 1, center = (0., 0.)) -&\n mean(x2**2, 1)) < sptol))\n call check(error, all( abs( moment(x2, order, dim = 2, center = (0., 0.)) -&\n mean(x2**2, 2)) < sptol))\n call check(error, all( abs( moment(x2, order, dim = 1, center = zero2_1) -&\n mean(x2**2, 1)) < sptol))\n call check(error, all( abs( moment(x2, order, dim = 2, center = zero2_2) -&\n mean(x2**2, 2)) < sptol))\n\n print*,' test_sp_2dim_mask', order\n call check(error, ieee_is_nan(abs(moment(x2, order, center = (0., 0.),&\n mask = .false.))))\n call check(error, any(ieee_is_nan(abs(moment(x2, order, dim = 1, center = (0., 0.),&\n mask = .false.)))))\n call check(error, any(ieee_is_nan(abs(moment(x2, order, dim = 2, center = (0., 0.),&\n mask = .false.)))))\n call check(error, any(ieee_is_nan(abs(moment(x2, order, dim = 1, center = zero2_1,&\n mask = .false.)))))\n call check(error, any(ieee_is_nan(abs(moment(x2, order, dim = 2, center = zero2_2,&\n mask = .false.)))))\n\n print*,' test_sp_2dim_mask_array', order\n call check(error, abs(moment(x2, order, center = (0., 0.), mask = (aimag(x2) == 0)) -&\n mean(x2**2, aimag(x2) == 0)) < sptol)\n call check(error, all( abs( moment(x2, order, dim = 1, center = zero2_1,&\n mask = (aimag(x2)==0)) -&\n mean(x2**2, 1, aimag(x2)==0)) < sptol))\n call check(error, all( abs( moment(x2, order, dim = 1, center = zero2_1,&\n mask = (aimag(x2)==0)) -&\n mean(x2**2, 1, aimag(x2)==0)) < sptol))\n\n end subroutine\nend module\n\n\nprogram tester\n use, intrinsic :: iso_fortran_env, only : error_unit\n use testdrive, only : run_testsuite, new_testsuite, testsuite_type\n use test_rawmoment, only : collect_rawmoment\n implicit none\n integer :: stat, is\n type(testsuite_type), allocatable :: testsuites(:)\n character(len=*), parameter :: fmt = '(\"#\", *(1x, a))'\n\n stat = 0\n\n testsuites = [ &\n new_testsuite(\"rawmoment\", collect_rawmoment) &\n ]\n\n do is = 1, size(testsuites)\n write(error_unit, fmt) \"Testing:\", testsuites(is)%name\n call run_testsuite(testsuites(is)%collect, error_unit, stat)\n end do\n\n if (stat > 0) then\n write(error_unit, '(i0, 1x, a)') stat, \"test(s) failed!\"\n error stop\n end if\nend program\n", "meta": {"hexsha": "088ddbeac83e7f268fb3307487c45f2ba5d3e73f", "size": 34883, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/stats/test_rawmoment.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/tests/stats/test_rawmoment.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/tests/stats/test_rawmoment.f90", "max_forks_repo_name": "seanwallawalla-forks/stdlib", "max_forks_repo_head_hexsha": "f58da3b1141a0bb0ce741aa6b74f636a1376706d", "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": 51.9865871833, "max_line_length": 95, "alphanum_fraction": 0.4622022188, "num_tokens": 10682, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127641048444, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6637462685887207}} {"text": "C File: arrays-basic-04.f\nC This program has a 2-D array with the implicit lower bounds of 1.\n\n program main\n implicit none\n\nC arr is a 2-D array (5x5) of integers with implicit lower-bounds \nC of 1 and upper bounds of 5. \n integer, dimension(5,5) :: arr \n integer :: i, j\n\n open (10, FILE=\"OUTPUT\", STATUS=\"REPLACE\")\n\n do i = 1, 5\n do j = 1, 5\n arr(i,j) = i+j ! initialize the array\n end do\n end do\n\n ! write out the array\n do i = 1, 5\n write (10,10) arr(i,1), arr(i,2), arr(i,3), arr(i,4), arr(i,5)\n end do\n\n 10 format(5(I5,X))\n\n stop\n end program main\n", "meta": {"hexsha": "55870e4458a00ee453670619e1c10649c227c025", "size": 662, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/data/program_analysis/arrays/arrays-basic-04.f", "max_stars_repo_name": "mikiec84/delphi", "max_stars_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2018-03-03T11:57:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-16T21:19:54.000Z", "max_issues_repo_path": "tests/data/program_analysis/arrays/arrays-basic-04.f", "max_issues_repo_name": "mikiec84/delphi", "max_issues_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 385, "max_issues_repo_issues_event_min_datetime": "2018-02-21T16:52:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-17T07:44:56.000Z", "max_forks_repo_path": "tests/data/program_analysis/arrays/arrays-basic-04.f", "max_forks_repo_name": "mikiec84/delphi", "max_forks_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2018-03-20T01:08:11.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-29T01:04:49.000Z", "avg_line_length": 22.8275862069, "max_line_length": 72, "alphanum_fraction": 0.5422960725, "num_tokens": 216, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127380808499, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.6637462615760878}} {"text": "! { dg-do run }\n! { dg-options \"-std=f2003 -fall-intrinsics -cpp\" }\n\n! PR fortran/38936\n! Check the basic semantics of the ASSOCIATE construct.\n\nPROGRAM main\n IMPLICIT NONE\n REAL :: a, b, c\n INTEGER, ALLOCATABLE :: arr(:)\n INTEGER :: mat(3, 3)\n\n TYPE :: myt\n INTEGER :: comp\n END TYPE myt\n\n TYPE(myt) :: tp\n\n a = -2.0\n b = 3.0\n c = 4.0\n\n ! Simple association to expressions.\n ASSOCIATE (r => SQRT (a**2 + b**2 + c**2), t => a + b)\n PRINT *, t, a, b\n IF (ABS (r - SQRT (4.0 + 9.0 + 16.0)) > 1.0e-3) CALL abort ()\n IF (ABS (t - a - b) > 1.0e-3) CALL abort ()\n END ASSOCIATE\n\n ! Target is vector-indexed.\n ASSOCIATE (foo => arr((/ 3, 1 /)))\n IF (LBOUND (foo, 1) /= 1 .OR. UBOUND (foo, 1) /= 2) CALL abort ()\n IF (foo(1) /= 3 .OR. foo(2) /= 1) CALL abort ()\n END ASSOCIATE\n\n ! Named and nested associate.\n myname: ASSOCIATE (x => a - b * c)\n ASSOCIATE (y => 2.0 * x)\n IF (ABS (y - 2.0 * (a - b * c)) > 1.0e-3) CALL abort ()\n END ASSOCIATE\n END ASSOCIATE myname ! Matching end-label.\n\n ! Correct behaviour when shadowing already existing names.\n ASSOCIATE (a => 1 * b, b => 1 * a, x => 1, y => 2)\n IF (ABS (a - 3.0) > 1.0e-3 .OR. ABS (b + 2.0) > 1.0e-3) CALL abort ()\n ASSOCIATE (x => 1 * y, y => 1 * x)\n IF (x /= 2 .OR. y /= 1) CALL abort ()\n END ASSOCIATE\n END ASSOCIATE\n\n ! Association to variables.\n mat = 0\n mat(2, 2) = 5;\n ASSOCIATE (x => arr(2), y => mat(2:3, 1:2))\n IF (x /= 2) CALL abort ()\n IF (ANY (LBOUND (y) /= (/ 1, 1 /) .OR. UBOUND (y) /= (/ 2, 2 /))) &\n CALL abort ()\n IF (y(1, 2) /= 5) CALL abort ()\n\n x = 7\n y = 8\n END ASSOCIATE\n IF (arr(2) /= 7 .OR. ANY (mat(2:3, 1:2) /= 8)) CALL abort ()\n\n\nEND PROGRAM main\n", "meta": {"hexsha": "ebb47c678ac5082ba60b9f9a5c49733c11bf6e2c", "size": 1714, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/nonsmoke/functional/CompileTests/Fortran_tests/test2019_multi_associate.f90", "max_stars_repo_name": "ouankou/rose", "max_stars_repo_head_hexsha": "76f2a004bd6d8036bc24be2c566a14e33ba4f825", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/nonsmoke/functional/CompileTests/Fortran_tests/test2019_multi_associate.f90", "max_issues_repo_name": "WildeGeist/rose", "max_issues_repo_head_hexsha": "17db6454e8baba0014e30a8ec23df1a11ac55a0c", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/nonsmoke/functional/CompileTests/Fortran_tests/test2019_multi_associate.f90", "max_forks_repo_name": "WildeGeist/rose", "max_forks_repo_head_hexsha": "17db6454e8baba0014e30a8ec23df1a11ac55a0c", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 25.5820895522, "max_line_length": 73, "alphanum_fraction": 0.5239206534, "num_tokens": 719, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746912, "lm_q2_score": 0.8539127455162773, "lm_q1q2_score": 0.6637462585451017}} {"text": "! Created by EverLookNeverSee@GitHub on 4/23/20.\n! This program integrate a function numerically\n! using trapezoidal rule.\n\n! Trapezoidal Rule:\n! integral f(x) dx = h[(f(a) + f(b)) / 2 + f(a + h) + f(a + 2h) +...+ f(a + nh)]\n\nprogram trapezoidal_rule\n implicit none\n ! declaring counter variables\n integer :: i, n = 100\n ! declaring limits of integration\n real :: a = 1.0, b = 4.0\n ! declaring length of intervals and sum, h, x variables\n real :: sum = 0.0, h, x\n h = (b - a) / n\n sum = sum + 0.5 * (a ** 3 * exp(-a ** 3) + b ** 3 * exp(-b ** 3))\n x = a + h\n do i = 2, 100\n sum = sum + (x ** 3 * exp(-x ** 3))\n end do\n sum = sum * h\n print *, \"the result of integration is:\", sum\nend program trapezoidal_rule", "meta": {"hexsha": "8118843192151e091cb7b49ca7677eabcbc24af0", "size": 759, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/other/trapezoidal_rule.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/trapezoidal_rule.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/trapezoidal_rule.f90", "max_forks_repo_name": "EverLookNeverSee/FCS", "max_forks_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-06-08T12:57:46.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-08T12:57:46.000Z", "avg_line_length": 31.625, "max_line_length": 82, "alphanum_fraction": 0.5599472991, "num_tokens": 273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425399873763, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6637457609623995}} {"text": "module test_linspace\n use testdrive, only : new_unittest, unittest_type, error_type, check\n use stdlib_kinds, only: sp, dp, int8, int16\n use stdlib_math, only: linspace, DEFAULT_LINSPACE_LENGTH\n\n implicit none\n private\n\n public :: collect_linspace\n\n real(sp), parameter :: TOLERANCE_SP = 1000 * epsilon(1.0_sp)\n real(dp), parameter :: TOLERANCE_DP = 1000 * epsilon(1.0_dp) ! Percentage of the range for which the actual gap must not exceed\n\n ! Testing linspace.\n !\n ! For single and double precision, check if the beginning and end values are properly recorded\n ! and make sure that the size of the result array is as expected.\n !\n ! This testing suite makes use of the a repeated section of code that will check to make\n ! sure that every element is linearly spaced (i.e., call check(|array(i+1) - array(i)| < |expected_value| * TOLERANCE)).\n ! I would convert this repeated code into a subroutine but that would require the implementation of a\n ! generic procedure given that each linear space will have a different expected_value type and kind.\n\ncontains\n\n !> Collect all exported unit tests\n subroutine collect_linspace(testsuite)\n !> Collection of tests\n type(unittest_type), allocatable, intent(out) :: testsuite(:)\n\n testsuite = [ &\n new_unittest(\"linspace_sp\", test_linspace_sp), &\n new_unittest(\"linspace_dp\", test_linspace_dp), &\n new_unittest(\"linspace_neg_index\", test_linspace_neg_index), &\n new_unittest(\"linspace_cmplx\", test_linspace_cmplx), &\n new_unittest(\"linspace_cmplx_2\", test_linspace_cmplx_2), &\n new_unittest(\"linspace_cmplx_3\", test_linspace_cmplx_3), &\n new_unittest(\"linspace_cmplx_sp\", test_linspace_cmplx_sp), &\n new_unittest(\"linspace_cmplx_sp_2\", test_linspace_cmplx_sp_2), &\n new_unittest(\"linspace_int16\", test_linspace_int16), &\n new_unittest(\"linspace_int8\", test_linspace_int8) &\n ]\n\n end subroutine collect_linspace\n\n\n subroutine test_linspace_sp(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n integer, parameter :: n = 20\n real(sp), parameter :: start = 1.0_sp\n real(sp), parameter :: end = 10.0_sp\n real(sp) :: expected_interval\n real(sp) :: true_difference\n\n integer :: i\n real(sp), allocatable :: x(:)\n\n x = linspace(start, end, n)\n\n expected_interval =( end - start ) / real(( n - 1 ), sp)\n\n call check(error, x(1), start, \"Initial value of array is not equal to the passed start parameter\")\n if (allocated(error)) return\n call check(error, x(n), end, \"Final array value is not equal to end parameter\")\n if (allocated(error)) return\n call check(error, size(x), n, \"Array not allocated to appropriate size\")\n if (allocated(error)) return\n\n print *, \"Made it through first round of tests\"\n\n ! Due to roundoff error, it is possible that the jump from x(n-1) to x(n) is slightly different than the expected interval\n do i = 1, n-1\n\n true_difference = x(i + 1) - x(i)\n call check(error, abs(true_difference - expected_interval) < abs(expected_interval) * TOLERANCE_SP)\n if (allocated(error)) return\n\n end do\n\n end subroutine\n\n subroutine test_linspace_dp(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n real(dp), parameter :: start = 1.0_dp\n real(dp), parameter :: end = 10.0_dp\n integer, parameter :: n = DEFAULT_LINSPACE_LENGTH\n real(dp) :: expected_interval\n real(dp) :: true_difference\n\n real(dp), allocatable :: x(:)\n integer :: i\n\n x = linspace(start, end)\n\n expected_interval =( end - start ) / ( n - 1 )\n\n call check(error, size(x), n, \"Array not allocated to default size\")\n if (allocated(error)) return\n call check(error, x(1), start, \"Initial value of array is not equal to the passed start parameter\")\n if (allocated(error)) return\n call check(error, x(n), end, \"Final array value is not equal to end parameter\")\n if (allocated(error)) return\n\n ! Due to roundoff error, it is possible that the jump from x(n-1) to x(n) is slightly different than the expected interval\n do i = 1, n-1\n\n true_difference = x(i + 1) - x(i)\n call check(error, true_difference, expected_interval, &\n & thr=abs(expected_interval) * TOLERANCE_DP)\n if (allocated(error)) return\n\n end do\n\n end subroutine\n\n subroutine test_linspace_neg_index(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n real(dp), parameter :: start = 1.0_dp\n real(dp), parameter :: end = 10.0_dp\n\n real(dp), allocatable :: x(:)\n\n x = linspace(start, end, -15)\n\n call check(error, size(x), 0, \"Allocated array is not empty\")\n\n end subroutine\n\n subroutine test_linspace_cmplx(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n complex(dp), parameter :: start = (0.0_dp, 10.0_dp)\n complex(dp), parameter :: end = (1.0_dp, 0.0_dp)\n complex(dp) :: expected_interval\n integer, parameter :: n = 10\n\n complex(dp), allocatable :: z(:)\n\n integer :: i\n\n z = linspace(start, end, n)\n\n expected_interval =( end - start ) / ( n - 1 )\n\n call check(error, size(z), n, \"Array not allocated to correct size\")\n if (allocated(error)) return\n call check(error, z(1), start, \"Initial value of array is not equal to the passed start parameter\")\n if (allocated(error)) return\n call check(error, z(n), end, \"Final array value is not equal to end parameter\")\n if (allocated(error)) return\n\n ! Due to roundoff error, it is possible that the jump from x(n-1) to x(n) is slightly different than the expected interval\n do i = 1, n-1\n\n call check(error, z(i + 1) - z(i), expected_interval, &\n & thr=abs(expected_interval) * TOLERANCE_DP)\n if (allocated(error)) return\n\n end do\n\n end subroutine\n\n subroutine test_linspace_cmplx_2(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n complex(dp), parameter :: start = (10.0_dp, 10.0_dp)\n complex(dp), parameter :: end = (1.0_dp, 1.0_dp)\n complex(dp) :: expected_interval\n\n integer, parameter :: n = 5\n\n complex(dp), allocatable :: z(:)\n\n integer :: i\n\n z = linspace(start, end, n)\n\n expected_interval =( end - start ) / ( n - 1 )\n\n call check(error, size(z), n, \"Array not allocated to correct size\")\n if (allocated(error)) return\n call check(error, z(1), start, \"Initial value of array is not equal to the passed start parameter\")\n if (allocated(error)) return\n call check(error, z(n), end, \"Final array value is not equal to end parameter\")\n if (allocated(error)) return\n\n ! Due to roundoff error, it is possible that the jump from x(n-1) to x(n) is slightly different than the expected interval\n do i = 1, n-1\n\n call check(error, z(i + 1) - z(i), expected_interval, &\n & thr=abs(expected_interval) * TOLERANCE_DP)\n if (allocated(error)) return\n\n end do\n\n end subroutine\n\n subroutine test_linspace_cmplx_3(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n complex(dp), parameter :: start = (-5.0_dp, 100.0_dp)\n complex(dp), parameter :: end = (20.0_dp, 13.0_dp)\n complex(dp) :: expected_interval\n\n integer, parameter :: n = 20\n\n complex(dp), allocatable :: z(:)\n\n integer :: i\n\n z = linspace(start, end, n)\n\n expected_interval = ( end - start ) / ( n - 1 )\n\n call check(error, size(z), n, \"Array not allocated to correct size\")\n if (allocated(error)) return\n call check(error, z(1), start, \"Initial value of array is not equal to the passed start parameter\")\n if (allocated(error)) return\n call check(error, z(n), end, \"Final array value is not equal to end parameter\")\n if (allocated(error)) return\n\n ! Due to roundoff error, it is possible that the jump from x(n-1) to x(n) is slightly different than the expected interval\n do i = 1, n-1\n\n call check(error, z(i + 1) - z(i), expected_interval, &\n & thr=abs(expected_interval) * TOLERANCE_DP)\n if (allocated(error)) return\n\n end do\n\n end subroutine\n\n subroutine test_linspace_cmplx_sp(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n complex(sp), parameter :: start = (0.5_sp, 5.0_sp)\n complex(sp), parameter :: end = (1.0_sp, -30.0_sp)\n complex(sp) :: expected_interval\n\n integer, parameter :: n = 10\n\n complex(sp), allocatable :: z(:)\n\n integer :: i\n\n z = linspace(start, end, n)\n\n expected_interval =( end - start ) / ( n - 1 )\n\n call check(error, size(z), n, \"Array not allocated to correct size\")\n if (allocated(error)) return\n call check(error, z(1), start, \"Initial value of array is not equal to the passed start parameter\")\n if (allocated(error)) return\n call check(error, z(n), end, \"Final array value is not equal to end parameter\")\n if (allocated(error)) return\n\n ! Due to roundoff error, it is possible that the jump from x(n-1) to x(n) is slightly different than the expected interval\n do i = 1, n-1\n\n call check(error, z(i + 1) - z(i), expected_interval, &\n & thr=abs(expected_interval) * TOLERANCE_SP)\n if (allocated(error)) return\n\n end do\n\n end subroutine\n\n subroutine test_linspace_cmplx_sp_2(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n complex(sp), parameter :: start = (50.0_sp, 500.0_sp)\n complex(sp), parameter :: end = (-100.0_sp, 2000.0_sp)\n complex(sp) :: expected_interval\n complex(sp) :: true_interval\n real(sp) :: offset\n\n integer, parameter :: n = DEFAULT_LINSPACE_LENGTH\n\n complex(sp), allocatable :: z(:)\n\n integer :: i\n\n z = linspace(start, end)\n\n expected_interval =( end - start ) / ( n - 1 )\n\n call check(error, size(z), n, \"Array not allocated to default size\")\n if (allocated(error)) return\n call check(error, z(1), start, \"Initial value of array is not equal to the passed start parameter\")\n if (allocated(error)) return\n call check(error, z(n), end, \"Final array value is not equal to end parameter\")\n if (allocated(error)) return\n\n ! Due to roundoff error, it is possible that the jump from x(n-1) to x(n) is slightly different than the expected interval\n do i = 1, n-1\n\n true_interval = (z(i + 1) - z(i))\n offset = abs(true_interval - expected_interval)\n call check(error, z(i + 1) - z(i), expected_interval, &\n & thr=abs(expected_interval) * TOLERANCE_SP)\n if (allocated(error)) return\n ! print *, i\n\n end do\n\n end subroutine\n\n subroutine test_linspace_int16(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n integer(int16), parameter :: start = 5\n integer(int16), parameter :: end = 10\n real(dp) :: expected_interval\n\n integer, parameter :: n = 6\n\n integer(int16), allocatable :: z(:)\n\n integer :: i\n\n z = linspace(start, end, n)\n\n expected_interval =( end - start ) / ( n - 1 )\n\n call check(error, size(z), n, \"Array not allocated to correct size\")\n if (allocated(error)) return\n call check(error, z(1), start, \"Initial value of array is not equal to the passed start parameter\")\n if (allocated(error)) return\n call check(error, z(n), end, \"Final array value is not equal to end parameter\")\n if (allocated(error)) return\n\n ! Due to roundoff error, it is possible that the jump from x(n-1) to x(n) is slightly different than the expected interval\n do i = 1, n-1\n\n call check(error, real(z(i + 1) - z(i), dp), expected_interval, &\n & thr=abs(expected_interval) * TOLERANCE_DP)\n if (allocated(error)) return\n\n end do\n\n end subroutine\n\n subroutine test_linspace_int8(error)\n !> Error handling\n type(error_type), allocatable, intent(out) :: error\n\n integer(int8), parameter :: start = 20\n integer(int8), parameter :: end = 50\n\n real(dp) :: expected_interval\n\n integer, parameter :: n = 10\n\n real(dp), allocatable :: z(:)\n integer(int8) :: z_int(n)\n\n integer :: i\n\n z = linspace(start, end, n)\n z_int = linspace(start, end, n)\n\n expected_interval =real( end - start, dp ) / ( n - 1 )\n\n call check(error, size(z), n, \"Array not allocated to correct size\")\n if (allocated(error)) return\n call check(error, z(1), real(start, dp), \"Initial value of array is not equal to the passed start parameter\")\n if (allocated(error)) return\n call check(error, z(n), real(end, dp), \"Final array value is not equal to end parameter\")\n if (allocated(error)) return\n\n ! Due to roundoff error, it is possible that the jump from x(n-1) to x(n) is slightly different than the expected interval\n do i = 1, n-1\n\n call check(error, z(i + 1) - z(i), expected_interval, &\n & thr=abs(expected_interval) * TOLERANCE_DP)\n if (allocated(error)) return\n\n end do\n\n end subroutine\n\n\n\nend module\n\nprogram tester\n use, intrinsic :: iso_fortran_env, only : error_unit\n use testdrive, only : run_testsuite, new_testsuite, testsuite_type\n use test_linspace, only : collect_linspace\n implicit none\n integer :: stat, is\n type(testsuite_type), allocatable :: testsuites(:)\n character(len=*), parameter :: fmt = '(\"#\", *(1x, a))'\n\n stat = 0\n\n testsuites = [ &\n new_testsuite(\"linspace\", collect_linspace) &\n ]\n\n do is = 1, size(testsuites)\n write(error_unit, fmt) \"Testing:\", testsuites(is)%name\n call run_testsuite(testsuites(is)%collect, error_unit, stat)\n end do\n\n if (stat > 0) then\n write(error_unit, '(i0, 1x, a)') stat, \"test(s) failed!\"\n error stop\n end if\nend program tester\n", "meta": {"hexsha": "ed449740c75ebffef60f230fbd5a47eafea17944", "size": 14743, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/math/test_linspace.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/tests/math/test_linspace.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/tests/math/test_linspace.f90", "max_forks_repo_name": "seanwallawalla-forks/stdlib", "max_forks_repo_head_hexsha": "f58da3b1141a0bb0ce741aa6b74f636a1376706d", "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": 34.853427896, "max_line_length": 131, "alphanum_fraction": 0.6114088042, "num_tokens": 3671, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388083214156, "lm_q2_score": 0.8006920092299293, "lm_q1q2_score": 0.6637246799635376}} {"text": "program mnist\nuse activations\nimplicit none\n\ninteger, allocatable :: train(:,:)\ninteger :: n, m, io, i, j, number_to_display\ninteger :: seed = 1234567\ncharacter(len=128) :: arg\ncharacter(len=128) :: filename\n\n! Declaration of network weights and biases\ndouble precision, dimension(30, 784) :: w_h1\ndouble precision, dimension(30) :: b_h1\ndouble precision, dimension(10,30) :: w_out\ndouble precision, dimension(10) :: b_out, out\n\n! Initializes all weights with gaussian normal distribution\n! with 1 variance\ncall r8mat_normal_01(30, 784, seed, w_h1)\ncall r8vec_normal_01(30, seed, b_h1)\ncall r8mat_normal_01(10, 30, seed, w_out)\ncall r8vec_normal_01(10, seed, b_out)\n\ncall getarg(1, arg)\nfilename = arg\ncall getarg(2, arg)\nread(arg, '(I10)') number_to_display\n\nm = 784\nn = 0\nopen(1, file = filename)\ndo\n\tread(1,*,iostat=io)\n\tif (io/=0) exit\n\tn = n + 1\nend do\nclose(1)\n\nn = n - 1 ! remove header line from count\nallocate(train(n, m))\n\nopen(1, file = filename)\nread(1,*) ! read header\ndo i = 1, n\n\tread(1, *) train(i,:)\nend do\n\ncall display(train(number_to_display,:))\ncall feedforward(train(202,:), w_h1, b_h1, w_out, b_out, out)\nwrite(*,*) out\n\ncontains\n\nsubroutine feedforward(input, w_h1, b_h1, w_out, b_out, out)\n\tinteger, intent(in), dimension(784) :: input\n\tdouble precision, intent(in), dimension(30, 784) :: w_h1\n\tdouble precision, intent(in), dimension(30) :: b_h1\n\tdouble precision, intent(in), dimension(10,30) :: w_out\n\tdouble precision, intent(in), dimension(10) :: b_out\n\tdouble precision, dimension(30) :: h1\n\tdouble precision, intent(out), dimension(10) :: out\n\n\th1 = sigmoid(matmul(w_h1, input) + b_h1)\n\tout = sigmoid(matmul(w_out, h1) + b_out)\n\nend subroutine\n\nsubroutine display(x)\n\tinteger, dimension(784) :: x\n\tcharacter, dimension(28,28) :: d\n\tinteger :: i, j, k\n\tk = 1\n\tdo i = 1, 28\n\t\tdo j = 1, 28\n\t\t\tif(x(k) > 128) then\n\t\t\t\td(i,j) = 'X'\n\t\t\telse\n\t\t\t\td(i,j) = ' '\n\t\t\tend if\n\t\t\tk = k +1\n\t\tend do\n\tend do\n\n\tdo i = 1, 28\n\t\twrite(*,*) d(i,:)\n\tend do\n\n\nend subroutine\n\nend program\n", "meta": {"hexsha": "eee94847e9374d4a298384a70ee74fd5d6b99203", "size": 1996, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/mnist.f90", "max_stars_repo_name": "alexmconn/dl4TRAN", "max_stars_repo_head_hexsha": "4fc0ccfa3e738615a9037061ac775ef7bf87ad5e", "max_stars_repo_licenses": ["MIT"], "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/mnist.f90", "max_issues_repo_name": "alexmconn/dl4TRAN", "max_issues_repo_head_hexsha": "4fc0ccfa3e738615a9037061ac775ef7bf87ad5e", "max_issues_repo_licenses": ["MIT"], "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/mnist.f90", "max_forks_repo_name": "alexmconn/dl4TRAN", "max_forks_repo_head_hexsha": "4fc0ccfa3e738615a9037061ac775ef7bf87ad5e", "max_forks_repo_licenses": ["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.6956521739, "max_line_length": 61, "alphanum_fraction": 0.6803607214, "num_tokens": 676, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467801752451, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6636810848583075}} {"text": " function fact_i(n)\n \n integer, intent(in) :: n\n real(kind=8) :: fact_i\n integer :: i\n\n fact_i = 1.d0\n do i = 2, n\n fact_i = fact_i * i\n enddo\n \n end function fact_i", "meta": {"hexsha": "ee7977861804ccaf7231ab969ad4cd204cede0f4", "size": 243, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ttb/libtools.f", "max_stars_repo_name": "kengwit/ttb", "max_stars_repo_head_hexsha": "e3e41fdc0a3b47a45f762d8d89dafce3ace838f4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 41, "max_stars_repo_stars_event_min_datetime": "2018-02-27T06:31:19.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-30T07:58:45.000Z", "max_issues_repo_path": "ttb/libtools.f", "max_issues_repo_name": "kengwit/ttb", "max_issues_repo_head_hexsha": "e3e41fdc0a3b47a45f762d8d89dafce3ace838f4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 22, "max_issues_repo_issues_event_min_datetime": "2017-12-01T07:47:36.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-16T05:42:06.000Z", "max_forks_repo_path": "ttb/libtools.f", "max_forks_repo_name": "kengwit/ttb", "max_forks_repo_head_hexsha": "e3e41fdc0a3b47a45f762d8d89dafce3ace838f4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-07-12T01:45:20.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-25T08:03:13.000Z", "avg_line_length": 20.25, "max_line_length": 32, "alphanum_fraction": 0.4238683128, "num_tokens": 67, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095294, "lm_q2_score": 0.7549149978955811, "lm_q1q2_score": 0.6636810801443633}} {"text": " FUNCTION PSI(XX)\nC----------------------------------------------------------------------\nC\nC This function program evaluates the logarithmic derivative of the\nC gamma function, \nC\nC psi(x) = d/dx (gamma(x)) / gamma(x) = d/dx (ln gamma(x))\nC\nC for real x, where either\nC\nC -xmax1 < x < -xmin (x not a negative integer), or\nC xmin < x.\nC\nC The calling sequence for this function is \nC\nC Y = PSI(X)\nC\nC The main computation uses rational Chebyshev approximations\nC published in Math. Comp. 27, 123-127 (1973) by Cody, Strecok and\nC Thacher. This transportable program is patterned after the\nC machine-dependent FUNPACK program PSI(X), but cannot match that\nC version for efficiency or accuracy. This version uses rational\nC approximations that are theoretically accurate to 20 significant\nC decimal digits. The accuracy achieved depends on the arithmetic\nC system, the compiler, the intrinsic functions, and proper selection\nC of the machine-dependent constants.\nC\nC*******************************************************************\nC*******************************************************************\nC\nC Explanation of machine-dependent constants\nC\nC XINF = largest positive machine number\nC XMAX1 = beta ** (p-1), where beta is the radix for the\nC floating-point system, and p is the number of base-beta\nC digits in the floating-point significand. This is an\nC upper bound on non-integral floating-point numbers, and\nC the negative of the lower bound on acceptable negative\nC arguments for PSI. If rounding is necessary, round this\nC value down.\nC XMIN1 = the smallest in magnitude acceptable argument. We\nC recommend XMIN1 = MAX(1/XINF,xmin) rounded up, where\nC xmin is the smallest positive floating-point number.\nC XSMALL = absolute argument below which PI*COTAN(PI*X) may be\nC represented by 1/X. We recommend XSMALL < sqrt(3 eps)/pi,\nC where eps is the smallest positive number such that\nC 1+eps > 1. \nC XLARGE = argument beyond which PSI(X) may be represented by\nC LOG(X). The solution to the equation\nC x*ln(x) = beta ** p\nC is a safe value.\nC\nC Approximate values for some important machines are\nC\nC beta p eps xmin XINF \nC\nC CDC 7600 (S.P.) 2 48 7.11E-15 3.13E-294 1.26E+322\nC CRAY-1 (S.P.) 2 48 7.11E-15 4.58E-2467 5.45E+2465\nC IEEE (IBM/XT,\nC SUN, etc.) (S.P.) 2 24 1.19E-07 1.18E-38 3.40E+38\nC IEEE (IBM/XT,\nC SUN, etc.) (D.P.) 2 53 1.11D-16 2.23E-308 1.79D+308\nC IBM 3033 (D.P.) 16 14 1.11D-16 5.40D-79 7.23D+75\nC SUN 3/160 (D.P.) 2 53 1.11D-16 2.23D-308 1.79D+308\nC VAX 11/780 (S.P.) 2 24 5.96E-08 2.94E-39 1.70E+38\nC (D.P.) 2 56 1.39D-17 2.94D-39 1.70D+38\nC (G Format) (D.P.) 2 53 1.11D-16 5.57D-309 8.98D+307\nC\nC XMIN1 XMAX1 XSMALL XLARGE\nC\nC CDC 7600 (S.P.) 3.13E-294 1.40E+14 4.64E-08 9.42E+12\nC CRAY-1 (S.P.) 1.84E-2466 1.40E+14 4.64E-08 9.42E+12\nC IEEE (IBM/XT,\nC SUN, etc.) (S.P.) 1.18E-38 8.38E+06 1.90E-04 1.20E+06\nC IEEE (IBM/XT,\nC SUN, etc.) (D.P.) 2.23D-308 4.50D+15 5.80D-09 2.71D+14\nC IBM 3033 (D.P.) 1.39D-76 4.50D+15 5.80D-09 2.05D+15\nC SUN 3/160 (D.P.) 2.23D-308 4.50D+15 5.80D-09 2.71D+14\nC VAX 11/780 (S.P.) 5.89E-39 8.38E+06 1.35E-04 1.20E+06\nC (D.P.) 5.89D-39 3.60D+16 2.05D-09 2.05D+15\nC (G Format) (D.P.) 1.12D-308 4.50D+15 5.80D-09 2.71D+14\nC\nC*******************************************************************\nC*******************************************************************\nC\nC Error Returns\nC\nC The program returns XINF for X < -XMAX1, for X zero or a negative\nC integer, or when X lies in (-XMIN1, 0), and returns -XINF\nC when X lies in (0, XMIN1).\nC\nC Intrinsic functions required are:\nC\nC ABS, AINT, DBLE, INT, LOG, REAL, TAN\nC\nC----------------------------------------------------------------------\n INTEGER I,N,NQ\nCS REAL\n DOUBLE PRECISION\n 1 AUG,CONV,DEN,PSI,FOUR,FOURTH,HALF,ONE,P1,P2,PIOV4,Q1,Q2,\n 2 SGN,THREE,XLARGE,UPPER,W,X,XINF,XMAX1,XMIN1,XSMALL,X01,\n 3 X01D,X02,XX,Z,ZERO\n DIMENSION P1(9),P2(7),Q1(8),Q2(6)\nC----------------------------------------------------------------------\nC Mathematical constants. PIOV4 = pi / 4\nC----------------------------------------------------------------------\nCS DATA ZERO,FOURTH,HALF,ONE/0.0E0,0.25E0,0.5E0,1.0E0/\nCS DATA THREE,FOUR/3.0E0,4.0E0/,PIOV4/7.8539816339744830962E-01/\n DATA ZERO,FOURTH,HALF,ONE/0.0D0,0.25D0,0.5D0,1.0D0/\n DATA THREE,FOUR/3.0D0,4.0D0/,PIOV4/7.8539816339744830962D-01/\nC----------------------------------------------------------------------\nC Machine-dependent constants\nC----------------------------------------------------------------------\nCS DATA XINF/1.70E+38/, XMIN1/5.89E-39/, XMAX1/8.38E+06/,\nCS 1 XSMALL/1.35E-04/, XLARGE/1.20E+06/\n DATA XINF/1.79D+308/, XMIN1/2.23D-308/, XMAX1/4.50D+15/,\n 1 XSMALL/5.80D-09/, XLARGE/2.71D+14/\nC----------------------------------------------------------------------\nC Zero of psi(x)\nC----------------------------------------------------------------------\nCS DATA X01/187.0E0/,X01D/128.0E0/,X02/6.9464496836234126266E-04/\n DATA X01/187.0D0/,X01D/128.0D0/,X02/6.9464496836234126266D-04/\nC----------------------------------------------------------------------\nC Coefficients for approximation to psi(x)/(x-x0) over [0.5, 3.0]\nC----------------------------------------------------------------------\nCS DATA P1/4.5104681245762934160E-03,5.4932855833000385356E+00,\nCS 1 3.7646693175929276856E+02,7.9525490849151998065E+03,\nCS 2 7.1451595818951933210E+04,3.0655976301987365674E+05,\nCS 3 6.3606997788964458797E+05,5.8041312783537569993E+05,\nCS 4 1.6585695029761022321E+05/\nCS DATA Q1/9.6141654774222358525E+01,2.6287715790581193330E+03,\nCS 1 2.9862497022250277920E+04,1.6206566091533671639E+05,\nCS 2 4.3487880712768329037E+05,5.4256384537269993733E+05,\nCS 3 2.4242185002017985252E+05,6.4155223783576225996E-08/\n DATA P1/4.5104681245762934160D-03,5.4932855833000385356D+00,\n 1 3.7646693175929276856D+02,7.9525490849151998065D+03,\n 2 7.1451595818951933210D+04,3.0655976301987365674D+05,\n 3 6.3606997788964458797D+05,5.8041312783537569993D+05,\n 4 1.6585695029761022321D+05/\n DATA Q1/9.6141654774222358525D+01,2.6287715790581193330D+03,\n 1 2.9862497022250277920D+04,1.6206566091533671639D+05,\n 2 4.3487880712768329037D+05,5.4256384537269993733D+05,\n 3 2.4242185002017985252D+05,6.4155223783576225996D-08/\nC----------------------------------------------------------------------\nC Coefficients for approximation to psi(x) - ln(x) + 1/(2x) \nC for x > 3.0\nC----------------------------------------------------------------------\nCS DATA P2/-2.7103228277757834192E+00,-1.5166271776896121383E+01,\nCS 1 -1.9784554148719218667E+01,-8.8100958828312219821E+00,\nCS 2 -1.4479614616899842986E+00,-7.3689600332394549911E-02,\nCS 3 -6.5135387732718171306E-21/\nCS DATA Q2/ 4.4992760373789365846E+01, 2.0240955312679931159E+02,\nCS 1 2.4736979003315290057E+02, 1.0742543875702278326E+02,\nCS 2 1.7463965060678569906E+01, 8.8427520398873480342E-01/\n DATA P2/-2.7103228277757834192D+00,-1.5166271776896121383D+01,\n 1 -1.9784554148719218667D+01,-8.8100958828312219821D+00,\n 2 -1.4479614616899842986D+00,-7.3689600332394549911D-02,\n 3 -6.5135387732718171306D-21/\n DATA Q2/ 4.4992760373789365846D+01, 2.0240955312679931159D+02,\n 1 2.4736979003315290057D+02, 1.0742543875702278326D+02,\n 2 1.7463965060678569906D+01, 8.8427520398873480342D-01/\nC----------------------------------------------------------------------\nCS CONV(I) = REAL(I)\n CONV(I) = DBLE(I)\n X = XX\n W = ABS(X)\n AUG = ZERO\nC----------------------------------------------------------------------\nC Check for valid arguments, then branch to appropriate algorithm\nC----------------------------------------------------------------------\n IF ((-X .GE. XMAX1) .OR. (W .LT. XMIN1)) THEN\n GOTO 410\n ELSE IF (X .GE. HALF) THEN\n GOTO 200\nC----------------------------------------------------------------------\nC X < 0.5, use reflection formula: psi(1-x) = psi(x) + pi * cot(pi*x)\nC Use 1/X for PI*COTAN(PI*X) when XMIN1 < |X| <= XSMALL. \nC----------------------------------------------------------------------\n ELSE IF (W .LE. XSMALL) THEN\n AUG = -ONE / X\n GOTO 150\n END IF\nC----------------------------------------------------------------------\nC Argument reduction for cot\nC----------------------------------------------------------------------\n 100 IF (X .LT. ZERO) THEN\n SGN = PIOV4\n ELSE\n SGN = -PIOV4\n END IF\n W = W - AINT(W)\n NQ = INT(W * FOUR)\n W = FOUR * (W - CONV(NQ) * FOURTH)\nC----------------------------------------------------------------------\nC W is now related to the fractional part of 4.0 * X.\nC Adjust argument to correspond to values in the first\nC quadrant and determine the sign.\nC----------------------------------------------------------------------\n N = NQ / 2\n IF ((N+N) .NE. NQ) W = ONE - W\n Z = PIOV4 * W\n IF (MOD(N,2) .NE. 0) SGN = - SGN\nC----------------------------------------------------------------------\nC determine the final value for -pi * cotan(pi*x)\nC----------------------------------------------------------------------\n N = (NQ + 1) / 2\n IF (MOD(N,2) .EQ. 0) THEN\nC----------------------------------------------------------------------\nC Check for singularity\nC----------------------------------------------------------------------\n IF (Z .EQ. ZERO) GOTO 410\n AUG = SGN * (FOUR / TAN(Z))\n ELSE\n AUG = SGN * (FOUR * TAN(Z))\n END IF\n 150 X = ONE - X\n 200 IF (X .GT. THREE) GOTO 300\nC----------------------------------------------------------------------\nC 0.5 <= X <= 3.0\nC----------------------------------------------------------------------\n DEN = X\n UPPER = P1(1) * X\n DO 210 I = 1, 7\n DEN = (DEN + Q1(I)) * X\n UPPER = (UPPER + P1(I+1)) * X\n 210 CONTINUE\n DEN = (UPPER + P1(9)) / (DEN + Q1(8))\n X = (X-X01/X01D) - X02\n PSI = DEN * X + AUG\n GO TO 500\nC----------------------------------------------------------------------\nC 3.0 < X \nC----------------------------------------------------------------------\n 300 IF (X .LT. XLARGE) THEN\n W = ONE / (X * X)\n DEN = W\n UPPER = P2(1) * W\n DO 310 I = 1, 5\n DEN = (DEN + Q2(I)) * W\n UPPER = (UPPER + P2(I+1)) * W\n 310 CONTINUE\n AUG = (UPPER + P2(7)) / (DEN + Q2(6)) - HALF / X + AUG\n END IF\n PSI = AUG + LOG(X)\n GOTO 500\nC----------------------------------------------------------------------\nC Error return\nC----------------------------------------------------------------------\n 410 PSI = XINF\n IF (X .GT. ZERO) PSI = -XINF\n 500 RETURN\nC---------- Last card of PSI ----------\n END\n", "meta": {"hexsha": "466c0f6f45981e43a353d5578654d47cb21bb0ce", "size": 11578, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/calelm/psi.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/psi.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/psi.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": 45.5826771654, "max_line_length": 71, "alphanum_fraction": 0.4771117637, "num_tokens": 3893, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095294, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6636810752967688}} {"text": "MODULE MODULE_GEOMETRY\n\nUSE MODULE_PBC\nUSE MODULE_MATH\nUSE MODULE_COM\n\nCONTAINS\n\n FUNCTION DIST2POINTS(point1,point2,box,inv,ortho,pbc_opt) RESULT (valdist)\n \n IMPLICIT NONE \n INTEGER, INTENT(IN)::ortho,pbc_opt\n DOUBLE PRECISION,DIMENSION(3),INTENT(IN)::point1,point2\n DOUBLE PRECISION,DIMENSION(3,3),INTENT(IN)::box,inv\n DOUBLE PRECISION::valdist\n DOUBLE PRECISION,DIMENSION(3)::vect_aux\n \n vect_aux(:)=point1(:)-point2(:)\n IF (pbc_opt==1) THEN\n CALL PBC (vect_aux,box,inv,ortho)\n END IF\n valdist=sqrt(dot_product(vect_aux(:),vect_aux(:)))\n\n END FUNCTION DIST2POINTS\n \n SUBROUTINE DISTANCE(diff_set,coors1,coors2,box,inv,ortho,&\n pbc_opt,n1,n2,n_frames,matrix)\n \n IMPLICIT NONE\n INTEGER,INTENT(IN)::diff_set,pbc_opt,ortho\n INTEGER,INTENT(IN)::n1,n2,n_frames\n DOUBLE PRECISION,DIMENSION(n_frames,n1,3),INTENT(IN)::coors1\n DOUBLE PRECISION,DIMENSION(n_frames,n2,3),INTENT(IN)::coors2\n DOUBLE PRECISION,DIMENSION(n_frames,3,3),INTENT(IN)::box,inv\n DOUBLE PRECISION,DIMENSION(n_frames,n1,n2),INTENT(OUT)::matrix\n \n INTEGER::ii,jj,kk\n DOUBLE PRECISION::val_aux\n DOUBLE PRECISION,DIMENSION(:),ALLOCATABLE::vect,vect_aux,vect_aux2\n DOUBLE PRECISION,DIMENSION(:,:),ALLOCATABLE::tmp_box,tmp_inv\n\n ALLOCATE(vect(3),vect_aux(3),vect_aux2(3))\n ALLOCATE(tmp_box(3,3),tmp_inv(3,3))\n\n IF (diff_set==1) THEN\n DO kk=1,n_frames\n tmp_box=box(kk,:,:)\n tmp_inv=inv(kk,:,:)\n DO ii=1,n1\n vect_aux=coors1(kk,ii,:)\n DO jj=1,n2\n vect_aux2=coors2(kk,jj,:)\n matrix(kk,ii,jj)=DIST2POINTS(vect_aux,vect_aux2,tmp_box,tmp_inv,ortho,pbc_opt)\n END DO\n END DO\n END DO\n ELSE\n DO kk=1,n_frames\n tmp_box=box(kk,:,:)\n tmp_inv=inv(kk,:,:)\n DO ii=1,n1\n matrix(kk,ii,ii)=0.0d0\n vect_aux=coors1(kk,ii,:)\n DO jj=ii+1,n1\n vect_aux2=coors1(kk,jj,:)\n val_aux=DIST2POINTS(vect_aux,vect_aux2,tmp_box,tmp_inv,ortho,pbc_opt)\n matrix(kk,ii,jj)=val_aux\n matrix(kk,jj,ii)=val_aux\n END DO\n END DO\n END DO\n END IF\n \n DEALLOCATE(vect,vect_aux,vect_aux2)\n DEALLOCATE(tmp_box,tmp_inv)\n \n END SUBROUTINE DISTANCE\n\n !FUNCTION RADIUS_OF_GYRATION (coors,weights,n_frames,n_atoms) RESULT(Rg)\n\n ! IMPLICIT NONE \n ! INTEGER, INTENT(IN)::n_frames,n_atoms\n ! DOUBLE PRECISION,DIMENSION(n_frames,n_atoms,3),INTENT(IN)::coors\n ! DOUBLE PRECISION,DIMENSION(n_atoms),INTENT(IN)::weights\n ! DOUBLE PRECISION,DIMENSION(n_frames)::Rg\n\n ! INTEGER::ii,jj\n ! DOUBLE PRECISION,DIMENSION(n_frames,3)::com\n ! DOUBLE PRECISION,DIMENSION(3)::vect_aux\n ! DOUBLE PRECISION::total_weight\n ! DOUBLE PRECISION::val_aux\n\n ! Rg(:) = 0.0d0\n ! com = CENTER_OF_MASS(coors,weights,n_frames,n_atoms)\n ! total_weight=SUM(weights)\n\n ! DO ii=1,n_frames\n ! val_aux=0.0d0\n ! DO jj=1,n_atoms\n ! vect_aux = coors(ii,jj,:)-com(ii,:)\n ! Rg(ii)=Rg(ii)+weights(jj)*dot_product(vect_aux,vect_aux)\n ! END DO\n ! END DO\n\n ! Rg(:)=Rg(:)/total_weight\n ! Rg(:)=sqrt(Rg(:))\n\n !END FUNCTION\n\n SUBROUTINE TRANSLATE(coors, shifts, n_frames, n_atoms)\n \n IMPLICIT NONE\n INTEGER,INTENT(IN)::n_frames, n_atoms\n DOUBLE PRECISION,DIMENSION(n_frames, n_atoms, 3),INTENT(INOUT)::coors\n DOUBLE PRECISION,DIMENSION(n_frames,3),INTENT(IN)::shifts\n INTEGER::ii,jj\n\n DO ii=1,n_frames\n DO jj=1,n_atoms\n coors(ii,jj,:)=coors(ii,jj,:)+shifts(ii,:)\n END DO\n END DO\n\n END SUBROUTINE\n\nEND MODULE MODULE_GEOMETRY\n \n", "meta": {"hexsha": "4f0e0e5e69e7de0b99319e820c32478a9d4dc4f0", "size": 3555, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "molmodmt/lib/libgeometry.f90", "max_stars_repo_name": "LMMV/MolModMT", "max_stars_repo_head_hexsha": "5725d6d5627b07edcbbd5e55318345a136b28c35", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "molmodmt/lib/libgeometry.f90", "max_issues_repo_name": "LMMV/MolModMT", "max_issues_repo_head_hexsha": "5725d6d5627b07edcbbd5e55318345a136b28c35", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "molmodmt/lib/libgeometry.f90", "max_forks_repo_name": "LMMV/MolModMT", "max_forks_repo_head_hexsha": "5725d6d5627b07edcbbd5e55318345a136b28c35", "max_forks_repo_licenses": ["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.7734375, "max_line_length": 90, "alphanum_fraction": 0.6610407876, "num_tokens": 1209, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467738423873, "lm_q2_score": 0.7549149868676284, "lm_q1q2_score": 0.6636810752299436}} {"text": "program tsunami\n\n ! Tsunami simulator.\n !\n ! Solves the non-linear 2-d shallow water equation system:\n !\n ! du/dt + u du/dx + v du/dy + g dh/dx = 0\n ! dv/dt + u dv/dx + v dv/dy + g dh/dy = 0\n ! dh/dt + d(hu)/dx + d(hv)/dy = 0\n !\n ! This version is parallelized and uses derived types.\n\n use iso_fortran_env, only: int32, real32\n use mod_field, only: Field, diffx, diffy\n\n implicit none\n\n integer(int32) :: n\n\n integer(int32), parameter :: im = 201, jm = 201\n integer(int32), parameter :: num_time_steps = 1000\n\n real(real32), parameter :: dt = 0.02\n real(real32), parameter :: dx = 1, dy = 1\n real(real32), parameter :: g = 9.8\n\n integer(int32), parameter :: ic = im / 2 + 1\n integer(int32), parameter :: jc = jm / 2 + 1\n real(real32), parameter :: decay = 0.02\n\n type(Field) :: h, hm, u, v\n\n real(real32) :: hmin, hmax, hmean\n\n u = Field('u', [im, jm])\n v = Field('v', [im, jm])\n h = Field('h', [im, jm])\n hm = Field('h_mean', [im, jm])\n\n ! initialize a gaussian blob in the center\n call h % init_gaussian(decay, ic, jc)\n\n hm = 10.\n\n call h % write(0)\n\n time_loop: do n = 1, num_time_steps\n\n ! compute u at next time step\n u = u - (u * diffx(u) / dx + v * diffy(u) / dy &\n + g * diffx(h) / dx) * dt\n\n ! compute v at next time step\n v = v - (u * diffx(v) / dx + v * diffy(v) / dy &\n + g * diffy(h) / dy) * dt\n\n ! compute h at next time step\n h = h - (diffx(u * (hm + h)) / dx &\n + diffy(v * (hm + h)) / dy) * dt\n\n hmin = minval(h % data)\n call co_min(hmin, 1)\n\n hmax = maxval(h % data)\n call co_max(hmax, 1)\n\n hmean = sum(h % data(h % lb(1):h % ub(1),h % lb(2):h % ub(2))) &\n / size(h % data(h % lb(1):h % ub(1),h % lb(2):h % ub(2)))\n call co_sum(hmean, 1)\n hmean = hmean / num_images()\n\n if (this_image() == 1) &\n print '(a, i5, 3(f10.6))', &\n 'step, min(h), max(h), mean(h):', &\n n, hmin, hmax, hmean\n\n call h % write(n)\n\n end do time_loop\n\nend program tsunami\n", "meta": {"hexsha": "0969e0ee36b6ea896b58f4b2fab481192b019f0e", "size": 2002, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/final/tsunami.f90", "max_stars_repo_name": "AAGAN/tsunami", "max_stars_repo_head_hexsha": "82635516dcb7f85eb6434ffdb98a9ddc4c1403ad", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 103, "max_stars_repo_stars_event_min_datetime": "2018-03-29T23:39:31.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T12:24:25.000Z", "max_issues_repo_path": "src/final/tsunami.f90", "max_issues_repo_name": "AAGAN/tsunami", "max_issues_repo_head_hexsha": "82635516dcb7f85eb6434ffdb98a9ddc4c1403ad", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2018-04-06T14:33:04.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T19:50:12.000Z", "max_forks_repo_path": "src/final/tsunami.f90", "max_forks_repo_name": "AAGAN/tsunami", "max_forks_repo_head_hexsha": "82635516dcb7f85eb6434ffdb98a9ddc4c1403ad", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 32, "max_forks_repo_forks_event_min_datetime": "2018-04-01T19:54:12.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-27T14:06:03.000Z", "avg_line_length": 24.4146341463, "max_line_length": 68, "alphanum_fraction": 0.538961039, "num_tokens": 744, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467738423873, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6636810703823489}} {"text": "program main\n ! Default\n implicit none\n\n ! Parameters\n integer(4), parameter :: max_val = 999\n\n ! Variables\n integer(4) :: i,j,max_pal,prod\n\n ! Do work\n max_pal = 1\n do i=1,max_val\n do j=i,max_val\n prod = i*j\n if (is_pal(prod)) then\n max_pal = max(prod,max_pal)\n endif\n enddo\n enddo\n\n ! Write out result\n write(*,*) \"Max palindrome: \",max_pal\n\n\ncontains\n\n\n pure function is_pal(targ)\n ! Default\n implicit none\n\n ! Local parameters\n integer(4), parameter :: max_places = 1 + int(log10(1D0*max_val**2))\n\n ! Function arguments\n integer(4), intent(in) :: targ\n logical :: is_pal\n\n ! Local variables\n integer(4) :: i,len_targ\n character(max_places) :: targ_char\n character(100) :: tag\n character :: ic,jc\n\n ! Write the product as a character\n if (max_places < 1e10) then\n write(tag,'(a,i10,a)') '(i',max_places,')'\n else\n write(tag,'(a,i100,a)') '(i',max_places,')'\n endif\n write(targ_char,tag) targ\n\n ! Find the length of the string\n len_targ = len_trim(targ_char)\n\n ! Test whether it's a palindrome\n do i=1,len_targ/2\n !write(ic,'(a1)') targ_char(i:i)\n !write(jc,'(a1)') targ_char(len_targ-i+1:len_targ-i+1)\n ic = targ_char(i:i)\n jc = targ_char(len_targ-i+1:len_targ-i+1)\n if (ic/=jc) then\n is_pal = .false.\n return\n endif\n enddo\n\n is_pal = .true.\n return\n end function is_pal\n\n\nend program main\n", "meta": {"hexsha": "85a39029f087d7f74ae5aad15244500f99e14d36", "size": 1529, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/problem4/problem4.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/problem4/problem4.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/problem4/problem4.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": 20.3866666667, "max_line_length": 72, "alphanum_fraction": 0.5735775016, "num_tokens": 470, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467548438124, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6636810657352292}} {"text": "*DECK CPPSL\n SUBROUTINE CPPSL (AP, N, B)\nC***BEGIN PROLOGUE CPPSL\nC***PURPOSE Solve the complex Hermitian positive definite system using\nC the factors computed by CPPCO or CPPFA.\nC***LIBRARY SLATEC (LINPACK)\nC***CATEGORY D2D1B\nC***TYPE COMPLEX (SPPSL-S, DPPSL-D, CPPSL-C)\nC***KEYWORDS LINEAR ALGEBRA, LINPACK, MATRIX, PACKED,\nC POSITIVE DEFINITE, SOLVE\nC***AUTHOR Moler, C. B., (U. of New Mexico)\nC***DESCRIPTION\nC\nC CPPSL solves the complex Hermitian positive definite system\nC A * X = B\nC using the factors computed by CPPCO or CPPFA.\nC\nC On Entry\nC\nC AP COMPLEX (N*(N+1)/2)\nC the output from CPPCO or CPPFA.\nC\nC N INTEGER\nC the order of the matrix A .\nC\nC B COMPLEX(N)\nC the right hand side vector.\nC\nC On Return\nC\nC B the solution vector X .\nC\nC Error Condition\nC\nC A division by zero will occur if the input factor contains\nC a zero on the diagonal. Technically this indicates\nC singularity but it is usually caused by improper subroutine\nC arguments. It will not occur if the subroutines are called\nC correctly and INFO .EQ. 0 .\nC\nC To compute INVERSE(A) * C where C is a matrix\nC with P columns\nC CALL CPPCO(AP,N,RCOND,Z,INFO)\nC IF (RCOND is too small .OR. INFO .NE. 0) GO TO ...\nC DO 10 J = 1, P\nC CALL CPPSL(AP,N,C(1,J))\nC 10 CONTINUE\nC\nC***REFERENCES J. J. Dongarra, J. R. Bunch, C. B. Moler, and G. W.\nC Stewart, LINPACK Users' Guide, SIAM, 1979.\nC***ROUTINES CALLED CAXPY, CDOTC\nC***REVISION HISTORY (YYMMDD)\nC 780814 DATE WRITTEN\nC 890831 Modified array declarations. (WRB)\nC 890831 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900326 Removed duplicate information from DESCRIPTION section.\nC (WRB)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE CPPSL\n INTEGER N\n COMPLEX AP(*),B(*)\nC\n COMPLEX CDOTC,T\n INTEGER K,KB,KK\nC***FIRST EXECUTABLE STATEMENT CPPSL\n KK = 0\n DO 10 K = 1, N\n T = CDOTC(K-1,AP(KK+1),1,B(1),1)\n KK = KK + K\n B(K) = (B(K) - T)/AP(KK)\n 10 CONTINUE\n DO 20 KB = 1, N\n K = N + 1 - KB\n B(K) = B(K)/AP(KK)\n KK = KK - K\n T = -B(K)\n CALL CAXPY(K-1,T,AP(KK+1),1,B(1),1)\n 20 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "b5f823ef29925dcf85186a928ab043fa1ed56b73", "size": 2514, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/cppsl.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/cppsl.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/cppsl.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.6585365854, "max_line_length": 71, "alphanum_fraction": 0.5871121718, "num_tokens": 833, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095294, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6636810656015796}} {"text": "module blas_d2\n use blas_kinds, only : ik, dp\n implicit none\n private :: ik, dp\n\n interface\n subroutine dgbmv(trans, m, n, kl, ku, alpha, a, lda, x, incx, beta, y, incy)\n import :: ik, dp\n integer(ik) :: lda\n character(len=1) :: trans\n integer(ik) :: m\n integer(ik) :: n\n integer(ik) :: kl\n integer(ik) :: ku\n real(dp) :: alpha\n real(dp) :: a(lda, *)\n real(dp) :: x(*)\n integer(ik) :: incx\n real(dp) :: beta\n real(dp) :: y(*)\n integer(ik) :: incy\n end subroutine dgbmv\n end interface\n interface\n subroutine dgemv(trans, m, n, alpha, a, lda, x, incx, beta, y, incy)\n import :: ik, dp\n integer(ik) :: lda\n character(len=1) :: trans\n integer(ik) :: m\n integer(ik) :: n\n real(dp) :: alpha\n real(dp) :: a(lda, *)\n real(dp) :: x(*)\n integer(ik) :: incx\n real(dp) :: beta\n real(dp) :: y(*)\n integer(ik) :: incy\n end subroutine dgemv\n end interface\n interface\n subroutine dger(m, n, alpha, x, incx, y, incy, a, lda)\n import :: ik, dp\n integer(ik) :: lda\n integer(ik) :: m\n integer(ik) :: n\n real(dp) :: alpha\n real(dp) :: x(*)\n integer(ik) :: incx\n real(dp) :: y(*)\n integer(ik) :: incy\n real(dp) :: a(lda, *)\n end subroutine dger\n end interface\n interface\n subroutine dsbmv(uplo, n, k, alpha, a, lda, x, incx, beta, y, incy)\n import :: ik, dp\n integer(ik) :: lda\n character(len=1) :: uplo\n integer(ik) :: n\n integer(ik) :: k\n real(dp) :: alpha\n real(dp) :: a(lda, *)\n real(dp) :: x(*)\n integer(ik) :: incx\n real(dp) :: beta\n real(dp) :: y(*)\n integer(ik) :: incy\n end subroutine dsbmv\n end interface\n interface\n subroutine dspmv(uplo, n, alpha, ap, x, incx, beta, y, incy)\n import :: ik, dp\n character(len=1) :: uplo\n integer(ik) :: n\n real(dp) :: alpha\n real(dp) :: ap(*)\n real(dp) :: x(*)\n integer(ik) :: incx\n real(dp) :: beta\n real(dp) :: y(*)\n integer(ik) :: incy\n end subroutine dspmv\n end interface\n interface\n subroutine dspr2(uplo, n, alpha, x, incx, y, incy, ap)\n import :: ik, dp\n character(len=1) :: uplo\n integer(ik) :: n\n real(dp) :: alpha\n real(dp) :: x(*)\n integer(ik) :: incx\n real(dp) :: y(*)\n integer(ik) :: incy\n real(dp) :: ap(*)\n end subroutine dspr2\n end interface\n interface\n subroutine dspr(uplo, n, alpha, x, incx, ap)\n import :: ik, dp\n character(len=1) :: uplo\n integer(ik) :: n\n real(dp) :: alpha\n real(dp) :: x(*)\n integer(ik) :: incx\n real(dp) :: ap(*)\n end subroutine dspr\n end interface\n interface\n subroutine dsymv(uplo, n, alpha, a, lda, x, incx, beta, y, incy)\n import :: ik, dp\n integer(ik) :: lda\n character(len=1) :: uplo\n integer(ik) :: n\n real(dp) :: alpha\n real(dp) :: a(lda, *)\n real(dp) :: x(*)\n integer(ik) :: incx\n real(dp) :: beta\n real(dp) :: y(*)\n integer(ik) :: incy\n end subroutine dsymv\n end interface\n interface\n subroutine dsyr2(uplo, n, alpha, x, incx, y, incy, a, lda)\n import :: ik, dp\n integer(ik) :: lda\n character(len=1) :: uplo\n integer(ik) :: n\n real(dp) :: alpha\n real(dp) :: x(*)\n integer(ik) :: incx\n real(dp) :: y(*)\n integer(ik) :: incy\n real(dp) :: a(lda, *)\n end subroutine dsyr2\n end interface\n interface\n subroutine dsyr(uplo, n, alpha, x, incx, a, lda)\n import :: ik, dp\n integer(ik) :: lda\n character(len=1) :: uplo\n integer(ik) :: n\n real(dp) :: alpha\n real(dp) :: x(*)\n integer(ik) :: incx\n real(dp) :: a(lda, *)\n end subroutine dsyr\n end interface\n interface\n subroutine dtbmv(uplo, trans, diag, n, k, a, lda, x, incx)\n import :: ik, dp\n integer(ik) :: lda\n character(len=1) :: uplo\n character(len=1) :: trans\n character(len=1) :: diag\n integer(ik) :: n\n integer(ik) :: k\n real(dp) :: a(lda, *)\n real(dp) :: x(*)\n integer(ik) :: incx\n end subroutine dtbmv\n end interface\n interface\n subroutine dtbsv(uplo, trans, diag, n, k, a, lda, x, incx)\n import :: ik, dp\n integer(ik) :: lda\n character(len=1) :: uplo\n character(len=1) :: trans\n character(len=1) :: diag\n integer(ik) :: n\n integer(ik) :: k\n real(dp) :: a(lda, *)\n real(dp) :: x(*)\n integer(ik) :: incx\n end subroutine dtbsv\n end interface\n interface\n subroutine dtpmv(uplo, trans, diag, n, ap, x, incx)\n import :: ik, dp\n character(len=1) :: uplo\n character(len=1) :: trans\n character(len=1) :: diag\n integer(ik) :: n\n real(dp) :: ap(*)\n real(dp) :: x(*)\n integer(ik) :: incx\n end subroutine dtpmv\n end interface\n interface\n subroutine dtpsv(uplo, trans, diag, n, ap, x, incx)\n import :: ik, dp\n character(len=1) :: uplo\n character(len=1) :: trans\n character(len=1) :: diag\n integer(ik) :: n\n real(dp) :: ap(*)\n real(dp) :: x(*)\n integer(ik) :: incx\n end subroutine dtpsv\n end interface\n interface\n subroutine dtrmv(uplo, trans, diag, n, a, lda, x, incx)\n import :: ik, dp\n integer(ik) :: lda\n character(len=1) :: uplo\n character(len=1) :: trans\n character(len=1) :: diag\n integer(ik) :: n\n real(dp) :: a(lda, *)\n real(dp) :: x(*)\n integer(ik) :: incx\n end subroutine dtrmv\n end interface\n interface\n subroutine dtrsm(side, uplo, transa, diag, m, n, alpha, a, lda, b, ldb)\n import :: ik, dp\n integer(ik) :: ldb\n integer(ik) :: lda\n character(len=1) :: side\n character(len=1) :: uplo\n character(len=1) :: transa\n character(len=1) :: diag\n integer(ik) :: m\n integer(ik) :: n\n real(dp) :: alpha\n real(dp) :: a(lda, *)\n real(dp) :: b(ldb, *)\n end subroutine dtrsm\n end interface\n interface\n subroutine dtrsv(uplo, trans, diag, n, a, lda, x, incx)\n import :: ik, dp\n integer(ik) :: lda\n character(len=1) :: uplo\n character(len=1) :: trans\n character(len=1) :: diag\n integer(ik) :: n\n real(dp) :: a(lda, *)\n real(dp) :: x(*)\n integer(ik) :: incx\n end subroutine dtrsv\n end interface\nend module blas_d2\n", "meta": {"hexsha": "43722feb6fddb5e581bbe3b7ec5e349b7b44217f", "size": 6404, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/blas/d2.f90", "max_stars_repo_name": "awvwgk/blas-interface", "max_stars_repo_head_hexsha": "4a5898eaf446a019d1cadbb619b1148bc7bc0289", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-07-05T23:21:38.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T08:12:37.000Z", "max_issues_repo_path": "src/blas/d2.f90", "max_issues_repo_name": "awvwgk/blas-interface", "max_issues_repo_head_hexsha": "4a5898eaf446a019d1cadbb619b1148bc7bc0289", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-03-04T13:30:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-04T14:37:34.000Z", "max_forks_repo_path": "src/blas/d2.f90", "max_forks_repo_name": "awvwgk/blas-interface", "max_forks_repo_head_hexsha": "4a5898eaf446a019d1cadbb619b1148bc7bc0289", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-16T08:12:11.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-16T08:12:11.000Z", "avg_line_length": 26.2459016393, "max_line_length": 80, "alphanum_fraction": 0.5231105559, "num_tokens": 2107, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146761176671, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6636810608208099}} {"text": "! examples/Fortran/ssmfe/shift_invert.f90\n! Laplacian on a rectangular grid by shift-invert via LDLT factorization\nprogram ssmfe_shift_invert_example\n use spral_ssmfe\n use laplace2d ! implement Lapalacian and preconditioners\n use ldltf ! implements LDLT support routines\n implicit none\n\n integer, parameter :: wp = kind(0d0) ! Working precision\n\n integer, parameter :: nx = 8 ! grid points along x\n integer, parameter :: ny = 8 ! grid points along y\n integer, parameter :: n = nx*ny ! problem size\n real(wp), parameter :: sigma = 1.0 ! shift\n\n integer :: ipiv(n) ! LDLT pivot index\n real(wp) :: lambda(n) ! eigenvalues\n real(wp) :: X(n, n) ! eigenvectors\n real(wp) :: A(n, n) ! matrix\n real(wp) :: LDLT(n, n) ! factors\n real(wp) :: work(n*n) ! work array for dsytrf\n integer :: lwork = n*n ! size of work\n integer :: left, right ! wanted eigenvalues left and right of sigma\n integer :: i ! index\n type(ssmfe_options) :: options ! eigensolver options\n type(ssmfe_inform ) :: inform ! information\n type(ssmfe_rcid ) :: rci ! reverse communication data\n type(ssmfe_keepd ) :: keep ! private data\n\n call set_laplacian_matrix( nx, ny, A, n )\n\n ! perform LDLT factorization of the shifted matrix\n LDLT = A\n forall ( i = 1 : n ) LDLT(i, i) = A(i, i) - sigma\n lwork = n*n\n call dsytrf( 'L', n, LDLT, n, ipiv, work, lwork, i )\n\n left = num_neg_D(n, LDLT, n, ipiv) ! all eigenvalues to the left from sigma\n right = 5 ! 5 eigenvalues to the right from sigma\n rci%job = 0\n do\n call ssmfe_standard_shift &\n ( rci, sigma, left, right, n, lambda, n, X, n, keep, options, inform )\n select case ( rci%job )\n case ( 1 )\n call dgemm &\n ( 'N', 'N', n, rci%nx, n, 1.0_wp, A, n, rci%x, n, 0.0_wp, rci%y, n )\n case ( 9 )\n call dcopy( n * rci%nx, rci%x, 1, rci%y, 1 )\n call dsytrs( 'L', n, rci%nx, LDLT, n, ipiv, rci%y, n, i )\n case ( :-1 )\n exit\n end select\n end do\n print '(1x, a, es10.2, 1x, a, i3, 1x, a)', 'Eigenvalues near', sigma, &\n '(took', inform%iteration, 'iterations)'\n print '(1x, a, i2, a, es13.7)', &\n ('lambda(', i, ') = ', lambda(i), i = 1, inform%left + inform%right)\n call ssmfe_free( keep, inform )\nend program ssmfe_shift_invert_example\n", "meta": {"hexsha": "a0b6b6641429ce6f34b4d07f665b7f93ad2ad275", "size": 2396, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/Fortran/ssmfe/shift_invert.f90", "max_stars_repo_name": "mjacobse/spral", "max_stars_repo_head_hexsha": "9bf003b2cc199928ec18c967ce0e009d98790898", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 76, "max_stars_repo_stars_event_min_datetime": "2016-10-03T13:58:37.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-14T00:11:34.000Z", "max_issues_repo_path": "examples/Fortran/ssmfe/shift_invert.f90", "max_issues_repo_name": "mjacobse/spral", "max_issues_repo_head_hexsha": "9bf003b2cc199928ec18c967ce0e009d98790898", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 51, "max_issues_repo_issues_event_min_datetime": "2016-09-20T19:01:18.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-11T12:52:21.000Z", "max_forks_repo_path": "examples/Fortran/ssmfe/shift_invert.f90", "max_forks_repo_name": "mjacobse/spral", "max_forks_repo_head_hexsha": "9bf003b2cc199928ec18c967ce0e009d98790898", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2016-09-30T20:52:47.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-28T14:58:37.000Z", "avg_line_length": 39.2786885246, "max_line_length": 79, "alphanum_fraction": 0.590984975, "num_tokens": 802, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146761176671, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6636810608208099}} {"text": "program ex20\n\n use utils\n\n implicit none\n\n real(rk), allocatable :: A(:,:)\n real(rk), allocatable :: B(:,:)\n integer :: i, j\n\n allocate(A(20,20), B(20,20))\n\n call initRand()\n call randMat(A, 0.0_rk, 1.0_rk)\n call randMat(B, 0.0_rk, 1.0_rk)\n\n do i=1,20\n A(i,i) = 2.0_rk * B(i,i)\n end do\n\n forall(i=1:20) A(i,i) = 2.0_rk * B(i,i)\n\n forall(i=1:20, j=1:20) A(i,j) = i + j\n\n forall(i=1:20, j=1:20, A(i,j)/=0.0_rk)\n B(i,j) = 1.0/A(i,j)\n end forall\n\n deallocate(A, B)\n\nend program ex20\n", "meta": {"hexsha": "f488e5df5f0750da3c7bee51e268ab6acbd6493b", "size": 541, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/ex20/ex20.f90", "max_stars_repo_name": "jonaslindemann/compute-course-public", "max_stars_repo_head_hexsha": "b8f55595ebbd790d79b525efdff17b8517154796", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-09-12T12:07:01.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-29T17:38:34.000Z", "max_issues_repo_path": "fortran/ex20/ex20.f90", "max_issues_repo_name": "jonaslindemann/compute-course-public", "max_issues_repo_head_hexsha": "b8f55595ebbd790d79b525efdff17b8517154796", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/ex20/ex20.f90", "max_forks_repo_name": "jonaslindemann/compute-course-public", "max_forks_repo_head_hexsha": "b8f55595ebbd790d79b525efdff17b8517154796", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2020-10-24T16:02:31.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-28T20:57:46.000Z", "avg_line_length": 16.90625, "max_line_length": 43, "alphanum_fraction": 0.5120147874, "num_tokens": 233, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677660619633, "lm_q2_score": 0.782662489091802, "lm_q1q2_score": 0.6636725624556711}} {"text": "! Extend operators for a user-defined vector type. Create new operator .DOT. to\n! calculate dot product. Set module to PRIVATE, and set specific elements of\n! module to PUBLIC.\nMODULE vector_operators\nIMPLICIT NONE\nPRIVATE\nPUBLIC :: vector, ASSIGNMENT(=), OPERATOR(+), OPERATOR(-), OPERATOR(*), &\n OPERATOR(/), OPERATOR(.DOT.), signal_me\nTYPE :: vector\n !PRIVATE\n REAL :: x\n REAL :: y\n REAL :: z\nEND TYPE vector\nCHARACTER(LEN=20), PUBLIC :: hello = \"HELLO WORLD\"\nINTEGER, PUBLIC, PROTECTED :: signal = 29\n\nINTERFACE OPERATOR(+)\n MODULE PROCEDURE add_vectors\n MODULE PROCEDURE add_vector_and_scalar\nEND INTERFACE\n\nINTERFACE OPERATOR(-)\n MODULE PROCEDURE sub_vectors\nEND INTERFACE\n\nINTERFACE OPERATOR(*)\n MODULE PROCEDURE mult_by_scalar\nEND INTERFACE\n\nINTERFACE OPERATOR(/)\n MODULE PROCEDURE div_by_scalar\nEND INTERFACE\n\nINTERFACE OPERATOR(.DOT.)\n MODULE PROCEDURE dot_product\nEND INTERFACE\n\nINTERFACE ASSIGNMENT(=)\n MODULE PROCEDURE array_to_vector\n MODULE PROCEDURE vector_to_array\nEND INTERFACE\n\nCONTAINS\n INTEGER FUNCTION signal_me()\n IMPLICIT NONE\n signal = 33\n signal_me = signal\n END FUNCTION signal_me\n\n TYPE(vector) FUNCTION add_vectors(v1, v2)\n IMPLICIT NONE\n TYPE(vector), INTENT(IN) :: v1, v2\n add_vectors = vector(v1%x + v2%x, v1%y + v2%y, v1%z + v2%z)\n END FUNCTION add_vectors\n\n TYPE(vector) FUNCTION sub_vectors(v1, v2)\n IMPLICIT NONE\n TYPE(vector), INTENT(IN) :: v1, v2\n sub_vectors = vector(v1%x - v2%x, v1%y - v2%y, v1%z - v2%z)\n END FUNCTION sub_vectors\n\n TYPE(vector) FUNCTION mult_by_scalar(v, s)\n IMPLICIT NONE\n TYPE(vector), INTENT(IN) :: v\n REAL, INTENT(IN) :: s\n mult_by_scalar = vector(v%x * s, v%y * s, v%z * s)\n END FUNCTION mult_by_scalar\n\n TYPE(vector) FUNCTION div_by_scalar(v, s)\n IMPLICIT NONE\n TYPE(vector), INTENT(IN) :: v\n REAL, INTENT(IN) :: s\n div_by_scalar = vector(v%x / s, v%y / s, v%z / s)\n END FUNCTION div_by_scalar\n\n REAL FUNCTION dot_product(v1, v2)\n IMPLICIT NONE\n TYPE(vector), INTENT(IN) :: v1, v2\n dot_product = v1%x * v2%x + v1%y * v2%y + v1%z * v2%z\n END FUNCTION dot_product\n\n SUBROUTINE vector_to_array(vec, arr)\n IMPLICIT NONE\n REAL, DIMENSION(3), INTENT(IN) :: arr\n TYPE(vector), INTENT(OUT) :: vec\n vec = vector(arr(1), arr(2), arr(3))\n END SUBROUTINE vector_to_array\n\n SUBROUTINE array_to_vector(arr, vec)\n IMPLICIT NONE\n TYPE(vector), INTENT(IN) :: vec\n REAL, DIMENSION(3), INTENT(OUT) :: arr\n arr(1) = vec%x\n arr(2) = vec%y\n arr(3) = vec%z\n END SUBROUTINE array_to_vector\n\n TYPE(vector) FUNCTION add_vector_and_scalar(v, s)\n IMPLICIT NONE\n TYPE(vector), INTENT(IN) :: v\n REAL, INTENT(IN) :: s\n add_vector_and_scalar = vector(v%x + s, v%y + s, v%z + s)\n END FUNCTION add_vector_and_scalar\n\nEND MODULE vector_operators\n\nPROGRAM test_vector_operators\nUSE vector_operators\nIMPLICIT NONE\nTYPE(vector) :: u, v\nREAL :: s\nREAL, DIMENSION(3) :: a\n\na = [7., 8., 9.]\ns = 2\n!greet = hello\n!u = vector(1., 2., 3.)\n!v = vector(4., 5., 4.)\nu = [1., 2., 3.]\nv = [4., 5., 4.]\nWRITE(*, *) u + v\nWRITE(*, *) u * s\nWRITE(*, *) v / 3.\nWRITE(*, *) u .DOT. v\nv = a\nWRITE(*, *) v\na = u\nWRITE(*, *) a\n!signal = 55\nWRITE(*, *) signal_me()\nEND PROGRAM test_vector_operators\n", "meta": {"hexsha": "f4691c41b3baec43cb9b3d379a25de39cb51b505", "size": 3179, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap13/data_hiding.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/data_hiding.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/data_hiding.f90", "max_forks_repo_name": "evanmacbride/fortran-practice", "max_forks_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.9022556391, "max_line_length": 79, "alphanum_fraction": 0.68386285, "num_tokens": 1044, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677737461007, "lm_q2_score": 0.7826624789529376, "lm_q1q2_score": 0.6636725598723269}} {"text": " subroutine setprob()\n implicit none\n\n double precision pi, pi2\n common /compi/ pi, pi2\n\n pi = 4.d0*atan(1.d0)\n pi2 = 2.0*pi\n\n\n end\n", "meta": {"hexsha": "885529efc0222a91dcfff07dc8e20a6cb863b28a", "size": 167, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "applications/clawpack/advection/2d/disk/setprob.f", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "applications/clawpack/advection/2d/disk/setprob.f", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-08-02T09:52:43.000Z", "max_issues_repo_issues_event_max_datetime": "2017-08-02T14:16:23.000Z", "max_forks_repo_path": "applications/clawpack/advection/2d/disk/setprob.f", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "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": 13.9166666667, "max_line_length": 30, "alphanum_fraction": 0.5209580838, "num_tokens": 55, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8479677737461007, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.6636725598723268}} {"text": "MODULE interfaces\n \nINTERFACE \n FUNCTION arth(first,increment,n)\n use def_kind\n integer(kind=i_single),intent(in) :: first,increment,n\n integer(kind=i_single),dimension(n):: arth\n END FUNCTION arth\nEND INTERFACE \n\nINTERFACE\n FUNCTION convlv(data,respns)\n use def_kind\n implicit none\n real(kind=r_single),dimension(:),intent(inout):: data\n real(kind=r_single),dimension(:),intent(in) :: respns\n real(kind=r_single),dimension(size(data)) :: convlv\n END FUNCTION convlv \nEND INTERFACE\n\nINTERFACE\n FUNCTION correl(data1,data2)\n use def_kind\n implicit none\n real(kind=r_single),dimension(:),intent(in) :: data1,data2\n real(kind=r_single),dimension(size(data1)) :: correl\n END FUNCTION correl\nEND INTERFACE\n\nINTERFACE\n FUNCTION derive(fun,dt)\n use def_kind\n implicit none\n real(kind=r_single),dimension(:),intent(in):: fun\n real(kind=r_single),intent(in) :: dt\n real(kind=r_single),dimension(size(fun)-1) :: derive\n END FUNCTION derive\nEND INTERFACE \n\nINTERFACE four1d\n SUBROUTINE four1d(data,isign)\n use def_kind\n implicit none\n complex(kind=r_single),dimension(:),intent(inout):: data\n integer(kind=i_single),intent(in) :: isign\n END SUBROUTINE four1d\nEND INTERFACE four1d\n\nINTERFACE fourrow\n SUBROUTINE fourrow(data,isign)\n use def_kind\n implicit none\n complex(kind=r_single),dimension(:,:),intent(inout):: data\n integer(kind=i_single),intent(in) :: isign\n END SUBROUTINE fourrow\nEND INTERFACE fourrow \n\nINTERFACE\n FUNCTION lag_correl(seq1,seq2)\n use def_kind\n implicit none\n real(kind=r_single),dimension(:),intent(in):: seq1,seq2\n real(kind=r_single) :: lag_correl\n END FUNCTION lag_correl\nEND INTERFACE\n\nINTERFACE \n FUNCTION normal_pdf(a,b,seed)\n use def_kind; use constants\n implicit none\n real(kind=r_scat),intent(in) :: a,b\n integer(kind=i_single),intent(in):: seed\n real(kind=r_scat) :: normal_pdf\n END FUNCTION normal_pdf\nEND INTERFACE\n\nINTERFACE\n FUNCTION peaker(fun,dt)\n use def_kind\n real(kind=r_single),dimension(:),intent(in):: fun\n real(kind=r_single),intent(in) :: dt\n real(kind=r_single) :: peaker\n END FUNCTION peaker\nEND INTERFACE\n\nINTERFACE polint\n SUBROUTINE polint(xa,ya,x,y)\n use def_kind\n implicit none\n real(kind=r_single),dimension(:),intent(in):: xa,ya\n real(kind=r_single),intent(in) :: x\n real(kind=r_single),intent(out) :: y\n END SUBROUTINE polint\nEND INTERFACE polint\n\nINTERFACE poly_interp\n SUBROUTINE poly_interp(x1a,x2a,ya,x1,x2,y)\n use def_kind\n implicit none\n real(kind=r_single),dimension(:),intent(in) :: x1a,x2a \n real(kind=r_single),dimension(:,:),intent(in):: ya\n real(kind=r_single),intent(in) :: x1,x2\n real(kind=r_single),intent(out) :: y\n END SUBROUTINE poly_interp\nEND INTERFACE poly_interp\n\nINTERFACE \n FUNCTION rand_pdf(seed,val_min,val_max,pdf)\n use def_kind\n implicit none\n real(kind=r_scat) :: rand_pdf\n integer(kind=i_single),intent(in):: seed\n character(len=*),intent(in) :: pdf \n real(kind=r_scat),intent(in) :: val_min,val_max\n END FUNCTION rand_pdf\nEND INTERFACE \n\nINTERFACE realft\n SUBROUTINE realft(data,isign,zdata)\n use def_kind\n implicit none\n real(kind=r_single),dimension(:),intent(inout) :: data\n integer(kind=i_single),intent(in) :: isign\n complex(kind=r_single),dimension(:),optional,target:: zdata\n END SUBROUTINE realft\nEND INTERFACE realft\n\nINTERFACE spline_interp\n SUBROUTINE spline_interp(in_seis,time_len,interp_npts,orig_npts,out_seis)\n use def_kind\n implicit none \n integer(kind=i_single),intent(in) :: interp_npts,orig_npts\n real(kind=r_single),intent(in) :: time_len\n real(kind=r_single),dimension(:),intent(in) :: in_seis\n real(kind=r_single),dimension(:),intent(out):: out_seis\n END SUBROUTINE spline_interp\nEND INTERFACE spline_interp\n\nINTERFACE swap\n SUBROUTINE swap(a,b)\n use def_kind\n complex(kind=r_single),dimension(:),intent(inout):: a,b\n END SUBROUTINE swap\nEND INTERFACE swap\n\nINTERFACE\n FUNCTION trapz(fun,dt)\n use def_kind\n implicit none\n real(kind=r_single),dimension(:),intent(in):: fun\n real(kind=r_single),intent(in) :: dt\n real(kind=r_single) :: trapz\n END FUNCTION trapz\nEND INTERFACE\n\nINTERFACE \n FUNCTION uniform_pdf(a,b,seed)\n use def_kind\n implicit none\n real(kind=r_scat),intent(in) :: a,b\n integer(kind=i_single),intent(in):: seed\n real(kind=r_scat) :: uniform_pdf\n END FUNCTION uniform_pdf \nEND INTERFACE \n\nINTERFACE write_disk\n SUBROUTINE write_disk(station,type_flag,in_arr)\n use def_kind; use flags; use scattering, only: npts\n use source_receiver, only: stat_name\n use stf_data, only: npts_stf,total\n use waveform, only: lf_len,lf_npts\n implicit none\n integer(kind=i_single),intent(in) :: station\n real(kind=r_single),dimension(:,:),intent(in):: in_arr\n character(len=*),intent(in) :: type_flag\n END SUBROUTINE write_disk\nEND INTERFACE write_disk\n\nINTERFACE write_disk_mpi\n SUBROUTINE write_disk_mpi(station,type_flag,in_arr)\n use def_kind; use flags; use scattering, only: npts\n use source_receiver, only: stat_name\n use stf_data, only: npts_stf,total\n use waveform, only: lf_len,lf_npts\n implicit none\n integer(kind=i_single),intent(in) :: station\n real(kind=r_single),dimension(:,:),intent(in):: in_arr\n character(len=*),intent(in) :: type_flag\n END SUBROUTINE write_disk_mpi\nEND INTERFACE write_disk_mpi\n\nINTERFACE \n FUNCTION zroots_unity(n,nn)\n use def_kind\n integer(kind=i_single),intent(in) :: n,nn\n complex(kind=r_single),dimension(nn):: zroots_unity\n END FUNCTION zroots_unity \nEND INTERFACE \n\nEND MODULE interfaces\n", "meta": {"hexsha": "56b704b7af50b1c874d2a9e74bd00c07d83e2e78", "size": 6263, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "bbp/src/sdsu/bbtoolbox/module_interface.f90", "max_stars_repo_name": "ZhangHCFJEA/bbp", "max_stars_repo_head_hexsha": "33bd999cf8d719c49f9a904872c62f02eb5850d1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2017-10-31T09:16:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T23:44:29.000Z", "max_issues_repo_path": "bbp/src/sdsu/bbtoolbox/module_interface.f90", "max_issues_repo_name": "ZhangHCFJEA/bbp", "max_issues_repo_head_hexsha": "33bd999cf8d719c49f9a904872c62f02eb5850d1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 37, "max_issues_repo_issues_event_min_datetime": "2017-05-23T15:15:35.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-05T09:13:18.000Z", "max_forks_repo_path": "bbp/src/sdsu/bbtoolbox/module_interface.f90", "max_forks_repo_name": "ZhangHCFJEA/bbp", "max_forks_repo_head_hexsha": "33bd999cf8d719c49f9a904872c62f02eb5850d1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2017-09-21T17:43:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-29T06:34:30.000Z", "avg_line_length": 31.1592039801, "max_line_length": 76, "alphanum_fraction": 0.6517643302, "num_tokens": 1557, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936879, "lm_q2_score": 0.782662489091802, "lm_q1q2_score": 0.6636725504274984}} {"text": " PROGRAM MATMUL\n implicit none\n INTEGER N, I, J, K\n PARAMETER (N=10)\n REAL*8 A(N,N), B(N,N), C(N,N)\n\n!$OMP PARALLEL\n\nC Initialize A, B and C matrices\n!$OMP DO\n DO 10 J=1, N\n DO 10 I=1, N\n A(I,J) = 2.0\n B(I,J) = 3.0\n C(I,J) = 0\n 10 CONTINUE\n!$OMP END DO\n\n!$OMP MASTER\n PRINT *, '******************************************************'\n PRINT *, 'Matrices initialized'\n PRINT *, '******************************************************'\n!$OMP END MASTER\n\nC Compute matrix-matrix product\n!$OMP DO\n DO 20 J=1, N\n DO 20 I=1, N\n DO 20 K=1, N\n C(I,J) = C(I,J) + A(I,K) * B(K,J)\n 20 CONTINUE\n!$OMP END DO\n\nC Print result matrix\n!$OMP MASTER\n PRINT *, '******************************************************'\n PRINT *, 'Result Matrix:'\n DO 50 I=1, N\n DO 40 J=1, N\n WRITE(*,30) C(I,J)\n 30\t FORMAT(2x,f8.2,$)\n 40 CONTINUE\n PRINT *, ' '\n 50 CONTINUE\n PRINT *, '******************************************************'\n PRINT *, 'Done.'\n!$OMP END MASTER\n!$OMP END PARALLEL\n\n END\n\n", "meta": {"hexsha": "13701e3d4e37fc9c98bb4078d1ea7a08c31a8019", "size": 1162, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "packages/PIPS/validation/Step/matmul.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/Step/matmul.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/Step/matmul.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": 22.3461538462, "max_line_length": 71, "alphanum_fraction": 0.3795180723, "num_tokens": 356, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936879, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6636725461287833}} {"text": "subroutine dfrad(df,f,r,nrad)\n ! Computes the radial derivative of function f(r)\n IMPLICIT NONE\n REAL*8, intent(out):: df(nrad)\n INTEGER, intent(in):: nrad\n REAL*8, intent(in) :: r(nrad), f(nrad)\n ! locals\n REAL*8 :: C(nrad), D(nrad)\n call spline(nrad, r, f, df, C, D)\n return\nend subroutine dfrad\n\nREAL*8 FUNCTION int_radial(funct,RX,DELTA,nr)\n ! Integrates radial function by Simpson: int funct(rx)*drx\n ! Notice that rx is logarithmic mesh, hence int[func(r)] requires summation of func(r)*r\n IMPLICIT NONE\n INTEGER, intent(in):: nr\n REAL*8, intent(in) :: RX(nr), funct(nr), DELTA\n ! locals\n REAL*8 :: dsum\n INTEGER :: jstart, jfin, j\n dsum=0.0D0\n jstart = 2-MOD(nr,2)\n jfin = nr-2\n ! Integration by Simpson Integrate[f(r) r dr]\n ! dsum = (1/3.*f_0*r0 + 4/3.*f1*r1 + 2/3.*f2*r2 + 4/3.*f3*r3+....+fn*rn)*dx\n DO j=jstart,jfin,2\n dsum = dsum + funct(j)*RX(j)+4.*funct(j+1)*RX(j+1)+funct(j+2)*RX(j+2)\n ENDDO\n dsum = dsum * DELTA/3.0D0\n dsum = dsum + (1-MOD(nr,2))*(funct(1)+funct(jstart))/2.0D0*(RX(jstart)-RX(1)) ! correction for even number of mesh points\n int_radial = dsum\n RETURN \nend FUNCTION int_radial\n\n\nSUBROUTINE SPLINE(N,X,Y,B,C,D)\n IMPLICIT NONE\n INTEGER, intent(in) :: N\n REAL*8, intent(in) :: X(N), Y(N)\n REAL*8, intent(out) :: B(N), C(N), D(N)\n !---------------------------------------------------------\n ! CALCULATE COEFFICIENTS B(I),C(I),D(I),I=1,2,...,N\n ! FOR CUBIC INTERPOLATIONAL SPLINE:\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).LE.X.LE.X(I+1),\n ! WHERE: N - NUMBER OF POINTS (N.GE.2),\n ! X - ABSCISES (IN STRICTLY INCREASING ORDER),\n ! Y - ORDINATES.\n !---------------------------------------------------------\n ! \n INTEGER :: NM1, IB, I\n REAL*8 :: T\n ! \n NM1=N-1\n IF(N .LT. 2) RETURN\n IF(N .LT. 3) GO TO 50\n !---------------------------------------------------------\n ! CONSTRUCT 3-DIAGONAL SYSTEM WITH B - DIAGONAL,\n ! D - OVERDIAGONAL, C - RIGHT SIDES\n !---------------------------------------------------------\n ! \n D(1)=X(2)-X(1)\n C(2)=(Y(2)-Y(1))/D(1)\n DO I=2,NM1\n D(I)=X(I+1)-X(I)\n B(I)=2.d0*(D(I-1)+D(I))\n C(I+1)=(Y(I+1)-Y(I))/D(I)\n C(I)=C(I+1)-C(I)\n ENDDO\n !----------------------------------------------------------\n ! BOUNDARY CONDITIONS\n !----------------------------------------------------------\n ! \n B(1)= -D(1)\n B(N)= -D(N-1)\n C(1)=0.D00\n C(N)=0.D00\n IF(N .EQ. 3) GO TO 15\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)*D(1)/(X(4)-X(1))\n C(N)= -C(N)*D(N-1)*D(N-1)/(X(N)-X(N-3))\n !----------------------------------------------------------\n ! UPWARD STEP\n !----------------------------------------------------------\n ! \n15 CONTINUE\n DO I=2,N\n T=D(I-1)/B(I-1)\n B(I)=B(I)-T*D(I-1)\n C(I)=C(I)-T*C(I-1)\n ENDDO\n !----------------------------------------------------------\n ! BACKWARD SUBSTITUTION\n !----------------------------------------------------------\n ! \n C(N)=C(N)/B(N)\n DO IB =1,NM1\n I=N-IB\n C(I)=(C(I)-D(I)*C(I+1))/B(I)\n ENDDO\n !----------------------------------------------------------\n ! CALCULATE COEFFICIENTS OF THE POLINOMIALS\n !----------------------------------------------------------\n ! \n B(N)=(Y(N)-Y(NM1))/D(NM1)+D(NM1)*(C(NM1)+2.D00*C(N))\n DO I=1,NM1\n B(I)=(Y(I+1)-Y(I))/D(I)-D(I)*(C(I+1)+2.D00*C(I))\n D(I)=(C(I+1)-C(I))/D(I)\n C(I)=3.D00*C(I)\n ENDDO\n \n C(N)=3.D00*C(N)\n D(N)=D(N-1)\n RETURN\n! \n50 CONTINUE\n B(1)=(Y(2)-Y(1))/(X(2)-X(1))\n C(1)=0.D00\n D(1)=0.D00\n B(2)=B(1)\n C(2)=0.D00\n D(2)=0.D00\n ! \n RETURN\nEND SUBROUTINE SPLINE\n", "meta": {"hexsha": "4a30638a85b13a97ceb82a1d6306a17deefe6ae8", "size": 3791, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/dmft2/dfrad.f90", "max_stars_repo_name": "dmft-wien2k/dmft-wien2k-v2", "max_stars_repo_head_hexsha": "83481be27e8a9ff14b9635d6cc1cd9d96f053487", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2018-04-03T06:37:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-08T11:44:06.000Z", "max_issues_repo_path": "src/dmft2/dfrad.f90", "max_issues_repo_name": "dmft-wien2k/dmft-wien2k-v2", "max_issues_repo_head_hexsha": "83481be27e8a9ff14b9635d6cc1cd9d96f053487", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2016-07-12T21:37:53.000Z", "max_issues_repo_issues_event_max_datetime": "2016-07-12T21:42:01.000Z", "max_forks_repo_path": "src/dmft2/dfrad.f90", "max_forks_repo_name": "dmft-wien2k/dmft-wien2k", "max_forks_repo_head_hexsha": "83481be27e8a9ff14b9635d6cc1cd9d96f053487", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-10-27T20:23:34.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-13T13:54:11.000Z", "avg_line_length": 29.6171875, "max_line_length": 123, "alphanum_fraction": 0.4162490108, "num_tokens": 1423, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677545357568, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.6636725448371115}} {"text": "c program DRDRANG\nc>> 2001-05-22 DRDRANG Krogh Minor change for making .f90 version.\nc>> 1996-05-28 DRDRANG Krogh Added external statement.\nc>> 1994-10-19 DRDRANG Krogh Changes to use M77CON\nc>> 1987-12-09 DRDRANG Lawson Initial Code.\nc--D replaces \"?\": DR?RANG, ?RANG, ?STAT1, ?STAT2\nc Demonstration driver for DRANG. Generates random numbers\nc from the Gaussian distribution.\nc ------------------------------------------------------------------\n integer NCELLS\n parameter(NCELLS = 12+2)\n external DRANG\n double precision DRANG, STATS(5), Y1, Y2, YTAB(1), ZERO\n integer I, IHIST(NCELLS), N\nc\n parameter(ZERO = 0.0D0)\n data N / 10000/\n data Y1, Y2 / -3.0D0, +3.0D0/\nc ------------------------------------------------------------------\n STATS(1) = ZERO\n do 20 I=1,N\nc GET RANDOM NUMBER\n YTAB(1) = DRANG()\nc\nc Accumulate statistics and histogram.\nc\n call DSTAT1(YTAB(1), 1, STATS, IHIST, NCELLS, Y1, Y2)\n 20 continue\nc Print the statistics and histogram.\nc\n write(*,'(13x,a//)') 'Gaussian random numbers from DRANG'\n call DSTAT2(STATS, IHIST, NCELLS, Y1, Y2)\n stop\n end\n", "meta": {"hexsha": "f034219ecbd37f277d28d8ff5fc3ebf73618504e", "size": 1269, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drdrang.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drdrang.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drdrang.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 36.2571428571, "max_line_length": 72, "alphanum_fraction": 0.5279747833, "num_tokens": 384, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757870013740061, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6636664600767177}} {"text": "program ns\n use, intrinsic :: iso_fortran_env, only : wp => real64\n use pyplot_module, only : pyplot\n \n implicit none\n \n type(pyplot) :: plt\n \n real(kind=8), parameter :: nx = 41 ! Number of grid points\n real(kind=8) :: dx, nt, dt, c, i, n, j, nu, sigma\n real(kind=8), dimension(nx) :: u, un, grid ! \n integer :: istat\n character :: input \n \n !nx is declared and assigned above \n dx = 2 / (nx-1) ! Distance between points\n nt = 20 ! Number of timesteps\n nu = 0.3 ! Viscosity\n sigma = 0.2\n dt = sigma * dx**2 / nu\n \n ! Initialize u to match our initial condition of \n ! u = 2 in the following range: 0.5 > x > 1 \n ! and 1 everywhere else\n do i=1, nx\n u(i) = 1\n if (i .ge. (.5 / dx) .and. i .le. (1 / dx + 1)) then \n u(i) = 2\n end if \n end do\n \n ! Use this array to represent the gridpoints for plotting\n do i=1, nx\n grid(i) = i\n end do\n \n ! Copy values from u to un\n do i=1, nx\n un(i) = u(i)\n end do\n \n ! Solve convection\n do n=1, nt\n do j =1, nx\n un(j)=u(j)\n end do\n \n do i=2, nx-1\n u(i) = un(i) + nu * dt / dx**2 * (un(i+1) - 2 * un(i) + un(i-1))\n end do\n end do\n \n \n \n ! Print the values contained in u\n do i=1, nx\n print*, u(i)\n end do\n \n print*, \"plotting\"\n call plt%initialize(grid=.true.,xlabel='timestep',&\n title='Plot of u over time',legend=.true.)\n call plt%add_plot(grid,u,label='value of u',linestyle='b-o',markersize=3,linewidth=1,istat=istat)\n call plt%savefig('plot.png', pyfile='plot.py', dpi='320', istat=istat)\n \n read*, input \nend program ns\n ", "meta": {"hexsha": "8e8114044dc539785444faf24d373cdb49bef9bb", "size": 1772, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "12 Steps to Navier-Stokes/main.f90", "max_stars_repo_name": "dominique120/12-steps-navier-stokes", "max_stars_repo_head_hexsha": "3e195bf7f7895f83f5f2248ef48dc13b76e8b5de", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "12 Steps to Navier-Stokes/main.f90", "max_issues_repo_name": "dominique120/12-steps-navier-stokes", "max_issues_repo_head_hexsha": "3e195bf7f7895f83f5f2248ef48dc13b76e8b5de", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "12 Steps to Navier-Stokes/main.f90", "max_forks_repo_name": "dominique120/12-steps-navier-stokes", "max_forks_repo_head_hexsha": "3e195bf7f7895f83f5f2248ef48dc13b76e8b5de", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.0588235294, "max_line_length": 101, "alphanum_fraction": 0.5079006772, "num_tokens": 566, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.875787001374006, "lm_q2_score": 0.7577943658046608, "lm_q1q2_score": 0.6636664552861804}} {"text": "subroutine downhill (n, func, xstart, fstart, stepi, epsf, itmin, iter)\n!\n! n dimension of the problem\n! func function\n! xstart starting values\n! fstart conrespoding function value\n! stepi relative stepsize for initial simplex\n! epsf esilon for termination\n! itmin termination istested if itmin < it\n! iter maximum number of iterations\n!\n\n use numtype\n implicit none\n integer :: n, iter , itmin\n real (dp), external :: func\n real (dp) :: xstart (1:n), fstart , stepi , epsf\n real (dp), parameter :: alph =1._dp , gamm =2._dp , &\n rho =0.5_dp , sig =0.5_dp\n real (dp) :: xi (1:n ,1:n+1) , x(1:n ,1:n+1) , &\n fi (1: n+1) , f(1: n+1) , &\n x0 (1: n), xr (1: n), xe (1: n), xc (1: n), &\n fxr , fxe , fxc , deltaf\n integer :: i, j, ii , it\n\n xi (1:n ,1) = xstart (1:n); fi (1) = fstart\n do i = 2, n+1\n xi (1:n,i)= xi (1:n ,1) !can be done with append\n xi(i -1,i)= xi(i -1,i )*(1+ stepi ) !complete the actions seperatly\n fi(i)= func (xi (1:n,i))\n end do\n\n do it = 1, iter\n\n do i = 1, n+1 ! ordering\n ii = minloc(fi (1:n+1) ,dim=1)\n x(1:n,i) = xi (1:n,ii ); f(i) = fi(ii)\n fi(ii) = huge(0._dp)\n end do !order the parameters from best to worst, and ss\n xi (1:n ,1: n+1) = x(1:n ,1: n+1)\n fi (1: n+1) = f(1: n+1)\n\n x0 (1: n) = sum(x(1:n ,1:n),dim=2)/ n ! central\n\n if ( itmin < it ) then ! exit\n deltaf = (f(n)-f (1))\n write (7 ,*) it , deltaf\n if ( deltaf < epsf ) exit\n end if\n\n xr (1: n) = x0 (1: n)+ alph *( x0 (1: n)-x(1:n,n +1))\n fxr = func (xr)\n if ( fxr < f(n) .and. f(1) <= fxr ) then! reflection\n xi (1:n,n+1) = xr (1: n); fi(n+1) = fxr\n cycle\n\n else if ( fxr < f(1) ) then ! expansion\n xe (1: n) = x0 (1: n)+ gamm *( x0 (1: n)-x(1:n,n +1))\n fxe = func (xe)\n if ( fxe < fxr ) then\n xi (1:n,n+1) = xe (1: n); fi(n+1) = fxe\n cycle\n else\n xi (1:n,n+1) = xr (1: n); fi(n+1) = fxr\n cycle\n end if\n\n else if ( fxr >= f(n) ) then ! contraction\n xc (1: n) = x(1:n,n +1)+ rho *( x0 (1: n)-x(1:n,n +1))\n fxc = func (xc)\n if ( fxc <= f(n+1) ) then\n xi (1:n,n+1) = xc (1: n); fi(n+1) = fxc\n cycle\n end if\n\n else ! reduction\n do i = 2, n+1\n xi(1:n,i) = x(1:n ,1)+ sig *(x(1:n,i)-x(1:n ,1))\n fi(i) = func(xi)\n end do\n cycle\n\n end if\n\n end do\n\n xstart (1:n)= xi (1:n ,1); fstart = fi (1)\n\nend subroutine downhill", "meta": {"hexsha": "2553a3feb4232b44e0fce6969e5a215decca5c71", "size": 2793, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "gaussian_fit_fortran/mylib.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/mylib.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/mylib.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": 31.3820224719, "max_line_length": 75, "alphanum_fraction": 0.432867884, "num_tokens": 1002, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869786798663, "lm_q2_score": 0.7577943822145998, "lm_q1q2_score": 0.6636664524603002}} {"text": "Program Main\n\n use mfpGlobal\n use mfpSpecialFunction\n\nImplicit None\n integer,parameter :: nX = 5000\n Real(RP) :: xMin, xMax\n Real(RP),dimension(nX) :: X, Y\n integer :: ii\n\n ! write(*,*) \"Test Gamma Related Function\"\n\n ! Call testGx()\n\n\n xMin = 0.1;\n xMax = 300.0;\n Call testBetaFunction(xMin, xMax, nX, X, Y)\n\n do ii = 1,nX\n write(*,*) ii, X(ii), Y(ii)\n Enddo\n\nEnd Program\n\n#include \"gammaRelated/testXbeta2xm1.inc\"\n", "meta": {"hexsha": "1c8ab97ca8d7ac70cd353f352593d157b047451d", "size": 464, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/example/testSpecialFn/main.f90", "max_stars_repo_name": "YoungmChoi/FyMcPack", "max_stars_repo_head_hexsha": "ce00c96d040a89ba59119738d80dd9713c4fb3e1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/example/testSpecialFn/main.f90", "max_issues_repo_name": "YoungmChoi/FyMcPack", "max_issues_repo_head_hexsha": "ce00c96d040a89ba59119738d80dd9713c4fb3e1", "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/example/testSpecialFn/main.f90", "max_forks_repo_name": "YoungmChoi/FyMcPack", "max_forks_repo_head_hexsha": "ce00c96d040a89ba59119738d80dd9713c4fb3e1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-16T01:24:15.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-16T01:24:15.000Z", "avg_line_length": 16.5714285714, "max_line_length": 47, "alphanum_fraction": 0.5926724138, "num_tokens": 160, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869786798663, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6636664476697633}} {"text": "\tsubroutine alphasub(tau,n,alpha,depar)\n\n\n\tinclude 'PARAMETER'\n parameter (num=19)\n\treal*4 tau(*),alpha(*),depar(*),x(num),y(num),z(num)\n real xr(num)\n\treal xa(11),ya(11)\n\n\tdata x/ \n & 0.5235 , -0.0020 , -0.3570 , -0.6574 , -0.9519 ,\n & -1.2627 , -1.5735 , -1.9115 , -2.2498 , -2.6212 ,\n & -2.9927 , -3.4148 , -3.8368 , -4.1535 , -4.3514 ,\n & -4.4831 , -4.5957 , -4.7022 , -8.0 /\n\n\tdata y/ \n & 1.00000e+00 , 1.00000e+00 , 9.89000e-01 , 9.79185e-01 ,\n & 9.63803e-01 , 9.34267e-01 , 8.81333e-01 , 8.11867e-01 ,\n & 7.05453e-01 , 5.86343e-01 , 4.67177e-01 , 3.55368e-01 ,\n & 2.61316e-01 , 1.87804e-01 , 1.29386e-01 , 8.72174e-02 ,\n & 5.19049e-02 , 2.72269e-02 , 0./\n\n\tdata z/ \n & 1.00000e+00 , 1.01600e+00 , 1.04200e+00 , 1.04200e+00 ,\n & 1.02100e+00 , 9.95000e-01 , 9.60000e-01 , 9.21000e-01 ,\n & 8.98000e-01 , 8.98000e-01 , 9.35000e-01 , 1.10800e+00 ,\n & 1.60500e+00 , 3.03500e+00 , 6.90700e+00 , 1.63790e+01 ,\n & 3.80500e+01 , 9.21060e+01 , 9.2106e1 /\n \n\tngrado=1 !grado del polinomio interpolador\n\n\tn2=int(ngrado/2)\n\nc print*,'entro en alphasub'\n do i=1,num\n\t xr(i)=x(i)\n end do\n \t\n\tdo i=1,n\n stau=tau(i) \n\t call locate(xr,num,stau,j)\n\t n3=j-n2-1\n if(n3.lt.0)n3=0\n if(n3+ngrado+1.gt.num)n3=num-ngrado-1\n\t do k=1,ngrado+1\n\t xa(k)=x(n3+k)\n\t end do\n\t do k=1,ngrado+1\n\t ya(k)=y(n3+k)\n\t end do\n\t call polint(xa,ya,ngrado+1,stau,sa,error)\n alpha(i)=dble(sa)\n\n\t do k=1,ngrado+1\n\t ya(k)=z(n3+k)\n\t end do\n\t call polint(xa,ya,ngrado+1,stau,da,error)\n depar(i)=dble(da) \nc print*,tau(i),alpha(i),depar(i)\n\tend do\n\nc print*,'salgo de alphasub'\n\n\n\treturn\n\tend\n\n\t \n", "meta": {"hexsha": "bd0cbdea8e122dff6806b451961416a1edf30ae4", "size": 1904, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "SIR2015/alphasub.f", "max_stars_repo_name": "cdiazbas/SIRcode", "max_stars_repo_head_hexsha": "026d4bce6e82ae6503493bf382b687fdd63514e9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-04-14T20:13:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-18T15:46:03.000Z", "max_issues_repo_path": "SIR2015/alphasub.f", "max_issues_repo_name": "cdiazbas/SIRcode", "max_issues_repo_head_hexsha": "026d4bce6e82ae6503493bf382b687fdd63514e9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SIR2015/alphasub.f", "max_forks_repo_name": "cdiazbas/SIRcode", "max_forks_repo_head_hexsha": "026d4bce6e82ae6503493bf382b687fdd63514e9", "max_forks_repo_licenses": ["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.5942028986, "max_line_length": 74, "alphanum_fraction": 0.4879201681, "num_tokens": 894, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869819218865, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.663666445336011}} {"text": " subroutine polcoe(x,y,n,cof)\nc\nc ************************************************\nc * njtj *\nc * Returns the coefficients of a polynominal. *\nc * Taken from numerical recipes, page 93. *\nc * njtj *\nc ************************************************\nc\nc njtj\nc ### Cray conversions \nc ### 1)Comment out implicit double precision.\nc ### 2)Switch double precision parameter\nc ### to single precision parameter statement.\nc ### Cray conversions\nc njtj\nc \n implicit double precision (a-h,o-z)\nc\n parameter (nmax=10,zero=0.D0,one=1.D0)\nCray parameter (nmax=10,zero=0.0,one=1.0)\nc\n dimension x(n),y(n),cof(n),s(nmax)\n do 11 i=1,n\n s(i)=zero\n cof(i)=zero\n11 continue\n s(n)=-x(1)\n do 13 i=2,n\n do 12 j=n+1-i,n-1\n s(j)=s(j)-x(i)*s(j+1)\n12 continue\n s(n)=s(n)-x(i)\n13 continue\n do 16 j=1,n\n phi=n\n do 14 k=n-1,1,-1\n phi=k*s(k+1)+x(j)*phi\n14 continue\n ff=y(j)/phi\n b=one\n do 15 k=n,1,-1\n cof(k)=cof(k)+b*ff\n b=s(k)+x(j)*b\n15 continue\n16 continue\n return\n end\n", "meta": {"hexsha": "d9be83022d0b3d7d353d0ae7e6f1726dea279771", "size": 1236, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "PSEUDO/source/polcoe.f", "max_stars_repo_name": "qsnake/petot", "max_stars_repo_head_hexsha": "bed334c6639fb02104821ce77d89ed83114febfe", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-07-13T07:57:59.000Z", "max_stars_repo_stars_event_max_datetime": "2016-07-13T07:57:59.000Z", "max_issues_repo_path": "PSEUDO/source/polcoe.f", "max_issues_repo_name": "qsnake/petot", "max_issues_repo_head_hexsha": "bed334c6639fb02104821ce77d89ed83114febfe", "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": "PSEUDO/source/polcoe.f", "max_forks_repo_name": "qsnake/petot", "max_forks_repo_head_hexsha": "bed334c6639fb02104821ce77d89ed83114febfe", "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": 25.2244897959, "max_line_length": 52, "alphanum_fraction": 0.4482200647, "num_tokens": 393, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278540866547, "lm_q2_score": 0.7520125848754472, "lm_q1q2_score": 0.6635968515177991}} {"text": "C -----------------------------------------------------------------------\nC Program to run a least squares minimization to standard star \nC photometry to find transformation coefficients: \nC instrumental --> standard\nC\nC ISYA 2004 (c) Ignasi Ribas (IEEC, Spain)\nC -----------------------------------------------------------------------\n PROGRAM FINDCOEFS\n IMPLICIT DOUBLE PRECISION (A-H,O-Z)\n PARAMETER (MAX=1000,N=2)\n DIMENSION YINST(MAX),BINST(MAX)\n DIMENSION XMA(MAX,N),XDEP(MAX)\n DIMENSION XV(MAX),XCV(N,N),XCR(N,N),XR(N),XERR(MAX)\n DIMENSION YMA(MAX,N),YDEP(MAX)\n DIMENSION YV(MAX),YCV(N,N),YCR(N,N),YR(N),YERR(MAX)\n\n Open(1,file='standards.lst',status='old')\n Do 1 k=1,MAX\n Read(1,*,end=2) yinst(k),xerr(k),binst(k),sigb,ystd,ydep(k)\n xma(k,1)=1.d0 \n yma(k,1)=1.d0\n xma(k,2)=binst(k)-yinst(k)\n yma(k,2)=binst(k)-yinst(k)\n yerr(k)=dsqrt(xerr(k)*xerr(k)+sigb*sigb)\n xdep(k)=ystd-yinst(k)\n 1 Continue\n 2 Close(1)\n ns=k-1\n\n CALL MINQ(XMA,XDEP,XERR,NS,XR,XCV,XCR,XV,XSIG,XR1)\n CALL MINQ(YMA,YDEP,YERR,NS,YR,YCV,YCR,YV,YSIG,YR1)\n\n Open(2,file='coefficients.dat')\n Write(2,50) \n 50 Format(20x,'FIT RESULTS',/,20x,'-----------')\n Write(2,*) \n Write(2,100) XR(1),XR(2)\n Write(2,200) SQRT(XCV(1,1)),SQRT(XCV(2,2))\n Write(2,*) \n Write(2,400) XSIG,XR1\n Write(2,*) \n Write(2,*) \n Write(2,300) YR(1),YR(2)\n Write(2,200) SQRT(YCV(1,1)),SQRT(YCV(2,2))\n Write(2,*) \n Write(2,400) YSIG,YR1\n 100 Format('y_std-y_inst = ',f7.3,' + ',f7.3,' * (b-y)_inst')\n 200 Format(' +/-',f7.3,' +/-',f7.3)\n 300 Format(' (b-y)_std = ',f7.3,' + ',f7.3,' * (b-y)_inst')\n 400 Format(5x,'sigma = ',f7.3,5x,'correlation coeff = ',f7.3)\n Write(2,*)\n Write(2,500)\n 500 Format(' y_inst',' O-C ',' sigma',' (b-y)_i',' O-C ',\n $ ' sigma')\n Do 40 i=1,ns\n calc1=xr(1)+xma(i,2)*xr(2)\n res1=xdep(i)-calc1\n calc2=yr(1)+yma(i,2)*yr(2)\n res2=ydep(i)-calc2\n Write(2,'(2(f8.3,2f7.3))') yinst(i),-res1,xerr(i),yma(i,2),res2,\n $ yerr(i)\n 40 Continue\n Close(2)\n\nC WRITE(*,900)\nC Do 10 i=1,n\nC WRITE(*,800) (XCV(i,j),j=1,n)\nC 10 Continue\nC WRITE(*,901)\nC Do 20 i=1,n\nC WRITE(*,800) (YCV(i,j),j=1,n)\nC 20 Continue\n\n 800 Format(8x,4f9.5)\n 900 Format(/,/,9x,'Covariance matrix 1')\n 901 Format(/,/,9x,'Covariance matrix 2')\n\n Stop\n End\n*\n* -------------\n* LEAST SQUARES\n* -------------\n*\n SUBROUTINE MINQ (A,ALTINCR,ERRY,NS,R,CV,CR,V,SIGMA,R2)\n PARAMETER (MAX=1000,N=2)\n IMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION A(MAX,N),ALTINCR(MAX),ERRY(MAX)\n DIMENSION P(MAX,MAX),ATP(N,MAX),AT(N,MAX),C(N,N)\n DIMENSION V(MAX),CV(N,N),CR(N,N)\n DIMENSION D(N,MAX),E(MAX),F(MAX),G(MAX),R(N)\n DIMENSION LL(N),MM(N)\n*\n* -------------------------------\n* INITIALIZATION OF WEIGHT MATRIX \n* -------------------------------\n*\n PT=0.\n DO 5 I=1,NS\n DO 6 J=1,NS\n IF (I.EQ.J) THEN\n P(I,J)=1.D0/ERRY(I)\n ELSE\n P(I,J)=0.D0\n ENDIF\n6 CONTINUE\n PT=PT+P(I,I)\n5 CONTINUE\n DO 7 I=1,NS\n7 P(I,I)=NS*(P(I,I)/PT)\n*\n* ------------------------------------\n* CALCULATION OF THE TRANSPOSED MATRIX\n* -------------------------------------\n*\n DO 10 I=1,NS\n DO 15 J=1,N\n AT(J,I)=A(I,J)\n15 CONTINUE\n10 CONTINUE\n*\n* ----------------------------------\n* PRODUCT OF TRANSPOSED TIMES WEIGHT\n* ----------------------------------\n*\n DO 20 I=1,N\n DO 25 J=1,NS\n ATP(I,J)=0.D0\n DO 30 K=1,NS\n ATP(I,J)=ATP(I,J)+AT(I,K)*P(K,J)\n30 CONTINUE\n25 CONTINUE\n20 CONTINUE\n*\n* --------------------------\n* PRODUCT WITH SYSTEM MATRIX\n* --------------------------\n*\n DO 35 I=1,N\n DO 40 J=1,N\n C(I,J)=0.D0\n DO 45 K=1,NS\n C(I,J)=C(I,J)+ATP(I,K)*A(K,J)\n45 CONTINUE\n40 CONTINUE\n35 CONTINUE\n*\n* -------\n* INVERSE\n* -------\n*\n CALL INVERT (C,N,DET,LL,MM)\n*\n* -----------------------------------\n* PRODUCT OF INVERSE TIMES TRANSPOSED\n* -----------------------------------\n*\n DO 50 I=1,N\n DO 55 J=1,NS\n D(I,J)=0.D0\n DO 60 K=1,N\n D(I,J)=D(I,J)+C(I,K)*AT(K,J)\n60 CONTINUE\n55 CONTINUE\n50 CONTINUE\n*\n* -----------------------------------\n* PRODUCT OF WEIGHT TIMES DATA MATRIX\n* -----------------------------------\n*\n em1=0.\n em2=0.\n DO 65 I=1,NS\n E(I)=0.D0\n em1=em1+ALTINCR(I)\n em2=em2+A(I,2)\n DO 70 J=1,NS\n E(I)=E(I)+P(I,J)*ALTINCR(J)\n70 CONTINUE\n65 CONTINUE\n em1=em1/NS\n em2=em2/NS\n dyt=0.\n dxt=0.\n dxy=0.\n Do 77 I=1,NS\n DXY=DXY+(P(I,I)/NS)*(A(I,2)-em2)*(ALTINCR(I)-em1)\n DXT=DXT+(P(I,I)/NS)*(A(I,2)-em2)*(A(I,2)-em2)\n77 DYT=DYT+(P(I,I)/NS)*(ALTINCR(I)-em1)*(ALTINCR(I)-em1)\n R2=DXY/(SQRT(DXT*DYT))\n*\n* -------------------------\n* SOLUTION BY LEAST SQUARES\n* -------------------------\n*\n DO 75 I=1,N\n R(I)=0.D0\n DO 80 J=1,NS\n R(I)=R(I)+D(I,J)*E(J)\n80 CONTINUE\n75 CONTINUE\n*\n* ------------------------------------\n* CALCULATION OF THE COVARIANCE MATRIX \n* ------------------------------------\n*\n DO 85 I=1,NS\n F(I)=0.D0\n DO 90 J=1,N\n F(I)=F(I)+A(I,J)*R(J)\n90 CONTINUE\n V(I)=F(I)-ALTINCR(I)\n85 CONTINUE\n*\n XNUMSIG=0.D0\n DO 95 I=1,NS\n G(I)=0.D0\n DO 100 J=1,NS\n G(I)=G(I)+V(J)*P(J,I)\n100 CONTINUE\n XNUMSIG=XNUMSIG+G(I)*V(I)\n95 CONTINUE\n SIGMAQ=XNUMSIG/(NS-N)\n SIGMA=DSQRT(SIGMAQ)\n*\n DO 105 I=1,N\n DO 110 J=1,N\n CV(I,J)=SIGMAQ*C(I,J)\n110 CONTINUE\n105 CONTINUE\n*\n* ------------------\n* CORRELATION MATRIX\n* ------------------\n*\n DO 115 I=1,N\n DO 120 J=1,N\n CR(I,J)=C(I,J)/DSQRT(C(I,I)*C(J,J))\n120 CONTINUE\n115 CONTINUE\n*\n RETURN\n END\n*\n* ----------------\n* MATRIX INVERSION\n* ----------------\n*\n SUBROUTINE INVERT (A,N,D,LL,MM)\n DIMENSION A(2*N),LL(N),MM(N)\n DOUBLE PRECISION A,D,BIGA,HOLD,DABS\n* --------------------------\n* SEARCH FOR LARGEST ELEMENT\n* --------------------------\n D=1.0D0\n NK=-N\n DO 80 K=1,N\n NK=NK+N\n LL(K)=K\n MM(K)=K\n KK=NK+K\n BIGA=A(KK)\n DO 20 J=K,N\n IZ=N*(J-1)\n DO 20 I=K,N\n IJ=IZ+I\n10 IF (DABS(BIGA)-DABS(A(IJ))) 15,20,20\n15 BIGA=A(IJ)\n LL(K)=I\n MM(K)=J\n20 CONTINUE\n* ----------------\n* INTERCHANGE ROWS\n* ----------------\n J=LL(K)\n IF(J-K) 35,35,25\n25 KI=K-N\n DO 30 I=1,N\n KI=KI+N\n HOLD=-A(KI)\n JI=KI-K+J\n A(KI)=A(JI)\n30 A(JI) =HOLD\n* -------------------\n* INTERCHANGE COLUMNS\n* -------------------\n35 I=MM(K)\n IF(I-K) 45,45,38\n38 JP=N*(I-1)\n DO 40 J=1,N\n JK=NK+J\n JI=JP+J\n HOLD=-A(JK)\n A(JK)=A(JI)\n40 A(JI) =HOLD\n* -------------------------------------------------------\n* DIVIDE COLUMN BY MINUS PIVOT (VALUE OF PIVOT ELEMENT IS\n* CONTAINED IN BIGA)\n* -------------------------------------------------------\n45 IF(BIGA) 48,46,48\n46 D=0.0D0\n RETURN\n48 DO 55 I=1,N\n IF(I-K) 50,55,50\n50 IK=NK+I\n A(IK)=A(IK)/(-BIGA)\n55 CONTINUE\n* -------------\n* REDUCE MATRIX\n* -------------\n DO 65 I=1,N\n IK=NK+I\n HOLD=A(IK)\n IJ=I-N\n DO 65 J=1,N\n IJ=IJ+N\n IF(I-K) 60,65,60\n60 IF(J-K) 62,65,62\n62 KJ=IJ-I+K\n A(IJ)=HOLD*A(KJ)+A(IJ)\n65 CONTINUE\n* -------------------\n* DIVIDE ROW BY PIVOT\n* -------------------\n KJ=K-N\n DO 75 J=1,N\n KJ=KJ+N\n IF(J-K) 70,75,70\n70 A(KJ)=A(KJ)/BIGA\n75 CONTINUE\n* -----------------\n* PRODUCT OF PIVOTS\n* -----------------\n D=D*BIGA\n* ---------------------------\n* REPLACE PIVOT BY RECIPROCAL\n* ---------------------------\n A(KK)=1.0D0/BIGA\n80 CONTINUE\n* --------------------------------\n* FINAL ROW AND COLUMN INTERCHANGE\n* --------------------------------\n K=N\n100 K=(K-1)\n IF(K) 150,150,105\n105 I=LL(K)\n IF(I-K) 120,120,108\n108 JQ=N*(K-1)\n JR=N*(I-1)\n DO 110 J=1,N\n JK=JQ+J\n HOLD=A(JK)\n JI=JR+J\n A(JK)=-A(JI)\n110 A(JI) =HOLD\n120 J=MM(K)\n IF(J-K) 100,100,125\n125 KI=K-N\n DO 130 I=1,N\n KI=KI+N\n HOLD=A(KI)\n JI=KI-K+J\n A(KI)=-A(JI)\n130 A(JI) =HOLD\n GO TO 100\n150 RETURN\n END\n", "meta": {"hexsha": "12fd1c2748a7b57ed147106b5521804424eaca1d", "size": 8898, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Lab1/src/findcoefs.f", "max_stars_repo_name": "mbadenas/Optical-Astronomy", "max_stars_repo_head_hexsha": "b27fd95f1b9dbfbf77e1abf68d61e3f402243b8d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-12-27T11:08:59.000Z", "max_stars_repo_stars_event_max_datetime": "2017-12-27T11:08:59.000Z", "max_issues_repo_path": "Lab1/src/findcoefs.f", "max_issues_repo_name": "mbadenas/Optical-Astronomy", "max_issues_repo_head_hexsha": "b27fd95f1b9dbfbf77e1abf68d61e3f402243b8d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Lab1/src/findcoefs.f", "max_forks_repo_name": "mbadenas/Optical-Astronomy", "max_forks_repo_head_hexsha": "b27fd95f1b9dbfbf77e1abf68d61e3f402243b8d", "max_forks_repo_licenses": ["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.1793478261, "max_line_length": 73, "alphanum_fraction": 0.4096426163, "num_tokens": 3211, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278757303678, "lm_q2_score": 0.752012562644147, "lm_q1q2_score": 0.6635968481766248}} {"text": " SUBROUTINE slCRAF (NDP, ANGLE, SIGN, IDMSF)\n*+\n* - - - - - -\n* C R A F\n* - - - - - -\n*\n* Convert an angle in radians into degrees, arcminutes, arcseconds\n* (single precision)\n*\n* Given:\n* NDP int number of decimal places of arcseconds\n* ANGLE real angle in radians\n*\n* Returned:\n* SIGN char '+' or '-'\n* IDMSF int(4) degrees, arcminutes, arcseconds, fraction\n*\n* Notes:\n*\n* 1) NDP less than zero is interpreted as zero.\n*\n* 2) The largest useful value for NDP is determined by the size of\n* ANGLE, the format of REAL floating-point numbers on the target\n* machine, and the risk of overflowing IDMSF(4). On some\n* architectures, for ANGLE up to 2pi, the available floating-\n* point precision corresponds roughly to NDP=3. This is well\n* below the ultimate limit of NDP=9 set by the capacity of a\n* typical 32-bit IDMSF(4).\n*\n* 3) The absolute value of ANGLE may exceed 2pi. In cases where it\n* does not, it is up to the caller to test for and handle the\n* case where ANGLE is very nearly 2pi and rounds up to 360 deg,\n* by testing for IDMSF(1)=360 and setting IDMSF(1-4) to zero.\n*\n* Called: slCDTF\n*\n* Last revision: 26 December 2004\n*\n* Copyright P.T.Wallace. All rights reserved.\n*\n* License:\n* This program is free software; you can redistribute it and/or modify\n* it under the terms of the GNU General Public License as published by\n* the Free Software Foundation; either version 2 of the License, or\n* (at your option) any later version.\n*\n* This program is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU General Public License for more details.\n*\n* You should have received a copy of the GNU General Public License\n* along with this program (see SLA_CONDITIONS); if not, write to the\n* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,\n* Boston, MA 02110-1301 USA\n*\n* Copyright (C) 1995 Association of Universities for Research in Astronomy Inc.\n*-\n\n IMPLICIT NONE\n\n INTEGER NDP\n REAL ANGLE\n CHARACTER SIGN*(*)\n INTEGER IDMSF(4)\n\n* Hours to degrees * radians to turns\n REAL F\n PARAMETER (F=15.0/6.283185307179586476925287)\n\n\n\n* Scale then use days to h,m,s routine\n CALL slCDTF(NDP,ANGLE*F,SIGN,IDMSF)\n\n END\n", "meta": {"hexsha": "f12058a17b692a0224837f882a1343d5df8decf0", "size": 2523, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iraf.v2161/math/slalib/cr2af.f", "max_stars_repo_name": "ysBach/irafdocgen", "max_stars_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:19:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T16:48:42.000Z", "max_issues_repo_path": "math/slalib/cr2af.f", "max_issues_repo_name": "kirxkirx/iraf", "max_issues_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-30T13:48:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-02T19:40:25.000Z", "max_forks_repo_path": "math/slalib/cr2af.f", "max_forks_repo_name": "kirxkirx/iraf", "max_forks_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.7662337662, "max_line_length": 80, "alphanum_fraction": 0.656757828, "num_tokens": 703, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278726384089, "lm_q2_score": 0.752012562644147, "lm_q1q2_score": 0.6635968458514329}} {"text": "!---------------------------------------------------!\n! Copyright (c) 2016 Shunsuke A. Sato !\n! Released under the MIT license !\n! https://opensource.org/licenses/mit-license.php !\n!---------------------------------------------------!\n!-------10--------20--------30--------40--------50--------60--------70--------80--------90\nsubroutine multipole(dipole_m,quadrupole_m,norm_m)\n use global_variables\n implicit none\n real(dp) :: dipole_m, quadrupole_m, norm_m\n real(dp) :: ss\n integer :: ix,iy\n\n dipole_m = 0d0; norm_m = 0d0\n do ix = 0,Nx\n dipole_m = dipole_m + xn(ix)*abs(zwfn_e(ix))**2\n norm_m = norm_m + abs(zwfn_e(ix))**2\n end do\n dipole_m = dipole_m*dx\n norm_m = norm_m*dx\n\n ss = 0d0\n quadrupole_m = 0d0\n do iy = 0,NR\n ss = ss + abs(zwfn_n(iy))**2\n quadrupole_m = quadrupole_m + Rn(iy)**2*abs(zwfn_n(iy))**2\n end do\n ss = ss*dr\n quadrupole_m = quadrupole_m*dr\n\n dipole_m = dipole_m * ss\n quadrupole_m = quadrupole_m*norm_m\n norm_m = norm_m * ss\n\n return\nend subroutine multipole\n", "meta": {"hexsha": "3fa2ecc42e2c493a06fcf197316b2d38497f6d9a", "size": 1053, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/multipole.f90", "max_stars_repo_name": "shunsuke-sato/tdmf-1d-h2plus", "max_stars_repo_head_hexsha": "d53c59af708b0c49f1f8d633f4064d43b07e8504", "max_stars_repo_licenses": ["MIT"], "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/multipole.f90", "max_issues_repo_name": "shunsuke-sato/tdmf-1d-h2plus", "max_issues_repo_head_hexsha": "d53c59af708b0c49f1f8d633f4064d43b07e8504", "max_issues_repo_licenses": ["MIT"], "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/multipole.f90", "max_forks_repo_name": "shunsuke-sato/tdmf-1d-h2plus", "max_forks_repo_head_hexsha": "d53c59af708b0c49f1f8d633f4064d43b07e8504", "max_forks_repo_licenses": ["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.4594594595, "max_line_length": 90, "alphanum_fraction": 0.5394112061, "num_tokens": 349, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473879530492, "lm_q2_score": 0.7606506526772883, "lm_q1q2_score": 0.6635516100078145}} {"text": " subroutine SGESLD(A,LDA,N,IPVT,B)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nC>> 1994-10-20 SGESLD Krogh Changes to use M77CON\nC>> 1987-08-18 SGESLD Lawson Initial code.\nc--S replaces \"?\": ?GESLD, ?AXPY\n\nC This subroutine solves the system of equations A * X = B\nC using the LU factorization of A given in the array A().\nc ------------------------------------------------------------------\nc Subroutine arguments\nC\nC A(,) [in] An array of size at least N x N. On entry must\nc contain the LU factors of an N x N matrix, A. It is\nc expected that this factorization will have been computed by\nc use of _GEFA, either directly or indirectly via use of\nc _GEFS or _GEFSC. This subr will not alter the contents of\nc A(,)\nC\nC LDA [in] Leading dimensioning parameter for the array A(,).\nC\nC N [in] The order of the original matrix, A.\nC\nC IPVT() [in] An integer array of length at least N, containg a\nc record of the row interchanges made during factorization of\nc A.\nC\nc B() [inout] On entry contains the right-side N-vector for the\nc problem, A * X = B. On return contains the solution\nc N-vector, X.\nc ------------------------------------------------------------------\nC ERROR CONDITION\nC A DIVISION BY ZERO WILL OCCUR IF THE INPUT FACTOR CONTAINS A\nC ZERO ON THE DIAGONAL. TECHNICALLY THIS INDICATES SINGULARITY\nC BUT IT IS OFTEN CAUSED BY IMPROPER ARGUMENTS OR IMPROPER\nC setting of LDA. The user can avoid sending a singular matrix\nc to this subr by testing INFO (set by _GEFS or _GEFA) or\nc RCOND (set by _GEFSC or _GERC) before calling this subr.\nc Nonsingularity is indicated by INFO .eq. 0 or RCOND .ne. ZERO.\nC ------------------------------------------------------------------\nC LINPACK. THIS VERSION DATED 08/14/78 .\nC CLEVE MOLER, UNIVERSITY OF NEW MEXICO, ARGONNE NATIONAL LAB.\nc Ref: LINPACK Users' Guide, by J. J. Dongarra, C. B. Moler,\nc J. R. Bunch, and G. W. Stewart, publ by Soc. for Indust. and Appl.\nc Math, Philadelphia, 1979.\nc Adapted from LINPACK for the JPL Math77 library by\nc C. L. Lawson, JPL, Aug 1987.\nC ------------------------------------------------------------------\nc Subprograms referenced: SAXPY\nC ------------------------------------------------------------------\n integer LDA,N,IPVT(N), K, KB, L, NM1\n real A(LDA,N), B(N), T, ZERO\n parameter ( ZERO = 0.E0 )\nC ------------------------------------------------------------------\n NM1 = N - 1\n\nC SOLVE A * X = B\nC FIRST SOLVE L*Y = B\n\n DO 20 K = 1, NM1\n L = IPVT(K)\n T = B(L)\n IF (L .ne. K) THEN\n B(L) = B(K)\n B(K) = T\n END IF\n CALL SAXPY(N-K,T,A(K+1,K),1,B(K+1),1)\n 20 CONTINUE\nC\nC NOW SOLVE U*X = Y\nC\n DO 40 KB = 1, N\n K = N + 1 - KB\n IF (A(K,K) .NE. ZERO) THEN\n B(K) = B(K)/A(K,K)\n ELSE\n CALL ERMSG('SGESLD',1,0,'A diagonal element is zero','.')\n RETURN\n END IF\n T = -B(K)\n CALL SAXPY(K-1,T,A(1,K),1,B(1),1)\n 40 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "72b34386249a1308cecd637e6e18fc5672602280", "size": 3452, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/sgesld.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/sgesld.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/sgesld.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": 40.1395348837, "max_line_length": 72, "alphanum_fraction": 0.5127462341, "num_tokens": 978, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.760650658103136, "lm_q1q2_score": 0.6635516046435229}} {"text": "Module m_valmed\nInteger, Parameter :: kdp = selected_real_kind(15)\npublic :: valmed\nprivate :: kdp\nprivate :: R_valmed, I_valmed, D_valmed\ninterface valmed\n module procedure d_valmed, r_valmed, i_valmed\nend interface valmed\ncontains\n\nRecursive Function D_valmed (XDONT) Result (res_med)\n! Finds the median of XDONT using the recursive procedure\n! described in Knuth, The Art of Computer Programming,\n! vol. 3, 5.3.3 - This procedure is linear in time, and\n! does not require to be able to interpolate in the\n! set as the one used in INDNTH. It also has better worst\n! case behavior than INDNTH, but is about 30% slower in\n! average for random uniformly distributed values.\n! __________________________________________________________\n! __________________________________________________________\n Real (kind=kdp), Dimension (:), Intent (In) :: XDONT\n Real (kind=kdp) :: res_med\n! __________________________________________________________\n Real (kind=kdp), Parameter :: XHUGE = HUGE (XDONT)\n Real (kind=kdp), Dimension (SIZE(XDONT)+6) :: XWRKT\n Real (kind=kdp) :: XWRK, XWRK1, XMED7\n!\n Integer, Dimension ((SIZE(XDONT)+6)/7) :: ISTRT, IENDT, IMEDT\n Integer :: NDON, NTRI, NMED, NORD, NEQU, NLEQ, IMED, IDON, IDON1\n Integer :: IDEB, IWRK, IDCR, ICRS, ICRS1, ICRS2, IMED1\n!\n NDON = SIZE (XDONT)\n NMED = (NDON+1) / 2\n! write(unit=*,fmt=*) NMED, NDON\n!\n! If the number of values is small, then use insertion sort\n!\n If (NDON < 35) Then\n!\n! Bring minimum to first location to save test in decreasing loop\n!\n IDCR = NDON\n If (XDONT (1) < XDONT (NDON)) Then\n XWRK = XDONT (1)\n XWRKT (IDCR) = XDONT (IDCR)\n Else\n XWRK = XDONT (IDCR)\n XWRKT (IDCR) = XDONT (1)\n Endif\n Do IWRK = 1, NDON - 2\n IDCR = IDCR - 1\n XWRK1 = XDONT (IDCR)\n If (XWRK1 < XWRK) Then\n XWRKT (IDCR) = XWRK\n XWRK = XWRK1\n Else\n XWRKT (IDCR) = XWRK1\n Endif\n End Do\n XWRKT (1) = XWRK\n!\n! Sort the first half, until we have NMED sorted values\n!\n Do ICRS = 3, NMED\n XWRK = XWRKT (ICRS)\n IDCR = ICRS - 1\n Do\n If (XWRK >= XWRKT(IDCR)) Exit\n XWRKT (IDCR+1) = XWRKT (IDCR)\n IDCR = IDCR - 1\n End Do\n XWRKT (IDCR+1) = XWRK\n End Do\n!\n! Insert any value less than the current median in the first half\n!\n Do ICRS = NMED+1, NDON\n XWRK = XWRKT (ICRS)\n If (XWRK < XWRKT (NMED)) Then\n IDCR = NMED - 1\n Do\n If (XWRK >= XWRKT(IDCR)) Exit\n XWRKT (IDCR+1) = XWRKT (IDCR)\n IDCR = IDCR - 1\n End Do\n XWRKT (IDCR+1) = XWRK\n End If\n End Do\n res_med = XWRKT (NMED)\n Return\n End If\n!\n! Make sorted subsets of 7 elements\n! This is done by a variant of insertion sort where a first\n! pass is used to bring the smallest element to the first position\n! decreasing disorder at the same time, so that we may remove\n! remove the loop test in the insertion loop.\n!\n DO IDEB = 1, NDON-6, 7\n IDCR = IDEB + 6\n If (XDONT (IDEB) < XDONT (IDCR)) Then\n XWRK = XDONT (IDEB)\n XWRKT (IDCR) = XDONT (IDCR)\n Else\n XWRK = XDONT (IDCR)\n XWRKT (IDCR) = XDONT (IDEB)\n Endif\n Do IWRK = 1, 5\n IDCR = IDCR - 1\n XWRK1 = XDONT (IDCR)\n If (XWRK1 < XWRK) Then\n XWRKT (IDCR) = XWRK\n XWRK = XWRK1\n Else\n XWRKT (IDCR) = XWRK1\n Endif\n End Do\n XWRKT (IDEB) = XWRK\n Do ICRS = IDEB+2, IDEB+6\n XWRK = XWRKT (ICRS)\n If (XWRK < XWRKT(ICRS-1)) Then\n XWRKT (ICRS) = XWRKT (ICRS-1)\n IDCR = ICRS - 1\n XWRK1 = XWRKT (IDCR-1)\n Do\n If (XWRK >= XWRK1) Exit\n XWRKT (IDCR) = XWRK1\n IDCR = IDCR - 1\n XWRK1 = XWRKT (IDCR-1)\n End Do\n XWRKT (IDCR) = XWRK\n EndIf\n End Do\n End Do\n!\n! Add-up alternatively + and - HUGE values to make the number of data\n! an exact multiple of 7.\n!\n IDEB = 7 * (NDON/7)\n NTRI = NDON\n If (IDEB < NDON) Then\n!\n XWRK1 = XHUGE\n Do ICRS = IDEB+1, IDEB+7\n If (ICRS <= NDON) Then\n XWRKT (ICRS) = XDONT (ICRS)\n Else\n If (XWRK1 /= XHUGE) NMED = NMED + 1\n XWRKT (ICRS) = XWRK1\n XWRK1 = - XWRK1\n Endif\n End Do\n!\n Do ICRS = IDEB+2, IDEB+7\n XWRK = XWRKT (ICRS)\n Do IDCR = ICRS - 1, IDEB+1, - 1\n If (XWRK >= XWRKT(IDCR)) Exit\n XWRKT (IDCR+1) = XWRKT (IDCR)\n End Do\n XWRKT (IDCR+1) = XWRK\n End Do\n!\n NTRI = IDEB+7\n End If\n!\n! Make the set of the indices of median values of each sorted subset\n!\n IDON1 = 0\n Do IDON = 1, NTRI, 7\n IDON1 = IDON1 + 1\n IMEDT (IDON1) = IDON + 3\n End Do\n!\n! Find XMED7, the median of the medians\n!\n XMED7 = D_valmed (XWRKT (IMEDT))\n!\n! Count how many values are not higher than (and how many equal to) XMED7\n! This number is at least 4 * 1/2 * (N/7) : 4 values in each of the\n! subsets where the median is lower than the median of medians. For similar\n! reasons, we also have at least 2N/7 values not lower than XMED7. At the\n! same time, we find in each subset the index of the last value < XMED7,\n! and that of the first > XMED7. These indices will be used to restrict the\n! search for the median as the Kth element in the subset (> or <) where\n! we know it to be.\n!\n IDON1 = 1\n NLEQ = 0\n NEQU = 0\n Do IDON = 1, NTRI, 7\n IMED = IDON+3\n If (XWRKT (IMED) > XMED7) Then\n IMED = IMED - 2\n If (XWRKT (IMED) > XMED7) Then\n IMED = IMED - 1\n Else If (XWRKT (IMED) < XMED7) Then\n IMED = IMED + 1\n Endif\n Else If (XWRKT (IMED) < XMED7) Then\n IMED = IMED + 2\n If (XWRKT (IMED) > XMED7) Then\n IMED = IMED - 1\n Else If (XWRKT (IMED) < XMED7) Then\n IMED = IMED + 1\n Endif\n Endif\n If (XWRKT (IMED) > XMED7) Then\n NLEQ = NLEQ + IMED - IDON\n IENDT (IDON1) = IMED - 1\n ISTRT (IDON1) = IMED\n Else If (XWRKT (IMED) < XMED7) Then\n NLEQ = NLEQ + IMED - IDON + 1\n IENDT (IDON1) = IMED\n ISTRT (IDON1) = IMED + 1\n Else ! If (XWRKT (IMED) == XMED7)\n NLEQ = NLEQ + IMED - IDON + 1\n NEQU = NEQU + 1\n IENDT (IDON1) = IMED - 1\n Do IMED1 = IMED - 1, IDON, -1\n If (XWRKT (IMED1) == XMED7) Then\n NEQU = NEQU + 1\n IENDT (IDON1) = IMED1 - 1\n Else\n Exit\n End If\n End Do\n ISTRT (IDON1) = IMED + 1\n Do IMED1 = IMED + 1, IDON + 6\n If (XWRKT (IMED1) == XMED7) Then\n NEQU = NEQU + 1\n NLEQ = NLEQ + 1\n ISTRT (IDON1) = IMED1 + 1\n Else\n Exit\n End If\n End Do\n Endif\n IDON1 = IDON1 + 1\n End Do\n!\n! Carry out a partial insertion sort to find the Kth smallest of the\n! large values, or the Kth largest of the small values, according to\n! what is needed.\n!\n If (NLEQ - NEQU + 1 <= NMED) Then\n If (NLEQ < NMED) Then ! Not enough low values\n XWRK1 = XHUGE\n NORD = NMED - NLEQ\n IDON1 = 0\n ICRS1 = 1\n ICRS2 = 0\n IDCR = 0\n Do IDON = 1, NTRI, 7\n IDON1 = IDON1 + 1\n If (ICRS2 < NORD) Then\n Do ICRS = ISTRT (IDON1), IDON + 6\n If (XWRKT(ICRS) < XWRK1) Then\n XWRK = XWRKT (ICRS)\n Do IDCR = ICRS1 - 1, 1, - 1\n If (XWRK >= XWRKT(IDCR)) Exit\n XWRKT (IDCR+1) = XWRKT (IDCR)\n End Do\n XWRKT (IDCR+1) = XWRK\n XWRK1 = XWRKT(ICRS1)\n Else\n If (ICRS2 < NORD) Then\n XWRKT (ICRS1) = XWRKT (ICRS)\n XWRK1 = XWRKT(ICRS1)\n Endif\n End If\n ICRS1 = MIN (NORD, ICRS1 + 1)\n ICRS2 = MIN (NORD, ICRS2 + 1)\n End Do\n Else\n Do ICRS = ISTRT (IDON1), IDON + 6\n If (XWRKT(ICRS) >= XWRK1) Exit\n XWRK = XWRKT (ICRS)\n Do IDCR = ICRS1 - 1, 1, - 1\n If (XWRK >= XWRKT(IDCR)) Exit\n XWRKT (IDCR+1) = XWRKT (IDCR)\n End Do\n XWRKT (IDCR+1) = XWRK\n XWRK1 = XWRKT(ICRS1)\n End Do\n End If\n End Do\n res_med = XWRK1\n Return\n Else\n res_med = XMED7\n Return\n End If\n Else ! If (NLEQ > NMED)\n! Not enough high values\n XWRK1 = -XHUGE\n NORD = NLEQ - NEQU - NMED + 1\n IDON1 = 0\n ICRS1 = 1\n ICRS2 = 0\n Do IDON = 1, NTRI, 7\n IDON1 = IDON1 + 1\n If (ICRS2 < NORD) Then\n!\n Do ICRS = IDON, IENDT (IDON1)\n If (XWRKT(ICRS) > XWRK1) Then\n XWRK = XWRKT (ICRS)\n IDCR = ICRS1 - 1\n Do IDCR = ICRS1 - 1, 1, - 1\n If (XWRK <= XWRKT(IDCR)) Exit\n XWRKT (IDCR+1) = XWRKT (IDCR)\n End Do\n XWRKT (IDCR+1) = XWRK\n XWRK1 = XWRKT(ICRS1)\n Else\n If (ICRS2 < NORD) Then\n XWRKT (ICRS1) = XWRKT (ICRS)\n XWRK1 = XWRKT (ICRS1)\n End If\n End If\n ICRS1 = MIN (NORD, ICRS1 + 1)\n ICRS2 = MIN (NORD, ICRS2 + 1)\n End Do\n Else\n Do ICRS = IENDT (IDON1), IDON, -1\n If (XWRKT(ICRS) > XWRK1) Then\n XWRK = XWRKT (ICRS)\n IDCR = ICRS1 - 1\n Do IDCR = ICRS1 - 1, 1, - 1\n If (XWRK <= XWRKT(IDCR)) Exit\n XWRKT (IDCR+1) = XWRKT (IDCR)\n End Do\n XWRKT (IDCR+1) = XWRK\n XWRK1 = XWRKT(ICRS1)\n Else\n Exit\n End If\n End Do\n Endif\n End Do\n!\n res_med = XWRK1\n Return\n End If\n!\nEnd Function D_valmed\n\nRecursive Function R_valmed (XDONT) Result (res_med)\n! Finds the median of XDONT using the recursive procedure\n! described in Knuth, The Art of Computer Programming,\n! vol. 3, 5.3.3 - This procedure is linear in time, and\n! does not require to be able to interpolate in the\n! set as the one used in INDNTH. It also has better worst\n! case behavior than INDNTH, but is about 30% slower in\n! average for random uniformly distributed values.\n! __________________________________________________________\n! _________________________________________________________\n Real, Dimension (:), Intent (In) :: XDONT\n Real :: res_med\n! __________________________________________________________\n Real, Parameter :: XHUGE = HUGE (XDONT)\n Real, Dimension (SIZE(XDONT)+6) :: XWRKT\n Real :: XWRK, XWRK1, XMED7\n!\n Integer, Dimension ((SIZE(XDONT)+6)/7) :: ISTRT, IENDT, IMEDT\n Integer :: NDON, NTRI, NMED, NORD, NEQU, NLEQ, IMED, IDON, IDON1\n Integer :: IDEB, IWRK, IDCR, ICRS, ICRS1, ICRS2, IMED1\n!\n NDON = SIZE (XDONT)\n NMED = (NDON+1) / 2\n! write(unit=*,fmt=*) NMED, NDON\n!\n! If the number of values is small, then use insertion sort\n!\n If (NDON < 35) Then\n!\n! Bring minimum to first location to save test in decreasing loop\n!\n IDCR = NDON\n If (XDONT (1) < XDONT (NDON)) Then\n XWRK = XDONT (1)\n XWRKT (IDCR) = XDONT (IDCR)\n Else\n XWRK = XDONT (IDCR)\n XWRKT (IDCR) = XDONT (1)\n Endif\n Do IWRK = 1, NDON - 2\n IDCR = IDCR - 1\n XWRK1 = XDONT (IDCR)\n If (XWRK1 < XWRK) Then\n XWRKT (IDCR) = XWRK\n XWRK = XWRK1\n Else\n XWRKT (IDCR) = XWRK1\n Endif\n End Do\n XWRKT (1) = XWRK\n!\n! Sort the first half, until we have NMED sorted values\n!\n Do ICRS = 3, NMED\n XWRK = XWRKT (ICRS)\n IDCR = ICRS - 1\n Do\n If (XWRK >= XWRKT(IDCR)) Exit\n XWRKT (IDCR+1) = XWRKT (IDCR)\n IDCR = IDCR - 1\n End Do\n XWRKT (IDCR+1) = XWRK\n End Do\n!\n! Insert any value less than the current median in the first half\n!\n Do ICRS = NMED+1, NDON\n XWRK = XWRKT (ICRS)\n If (XWRK < XWRKT (NMED)) Then\n IDCR = NMED - 1\n Do\n If (XWRK >= XWRKT(IDCR)) Exit\n XWRKT (IDCR+1) = XWRKT (IDCR)\n IDCR = IDCR - 1\n End Do\n XWRKT (IDCR+1) = XWRK\n End If\n End Do\n res_med = XWRKT (NMED)\n Return\n End If\n!\n! Make sorted subsets of 7 elements\n! This is done by a variant of insertion sort where a first\n! pass is used to bring the smallest element to the first position\n! decreasing disorder at the same time, so that we may remove\n! remove the loop test in the insertion loop.\n!\n DO IDEB = 1, NDON-6, 7\n IDCR = IDEB + 6\n If (XDONT (IDEB) < XDONT (IDCR)) Then\n XWRK = XDONT (IDEB)\n XWRKT (IDCR) = XDONT (IDCR)\n Else\n XWRK = XDONT (IDCR)\n XWRKT (IDCR) = XDONT (IDEB)\n Endif\n Do IWRK = 1, 5\n IDCR = IDCR - 1\n XWRK1 = XDONT (IDCR)\n If (XWRK1 < XWRK) Then\n XWRKT (IDCR) = XWRK\n XWRK = XWRK1\n Else\n XWRKT (IDCR) = XWRK1\n Endif\n End Do\n XWRKT (IDEB) = XWRK\n Do ICRS = IDEB+2, IDEB+6\n XWRK = XWRKT (ICRS)\n If (XWRK < XWRKT(ICRS-1)) Then\n XWRKT (ICRS) = XWRKT (ICRS-1)\n IDCR = ICRS - 1\n XWRK1 = XWRKT (IDCR-1)\n Do\n If (XWRK >= XWRK1) Exit\n XWRKT (IDCR) = XWRK1\n IDCR = IDCR - 1\n XWRK1 = XWRKT (IDCR-1)\n End Do\n XWRKT (IDCR) = XWRK\n EndIf\n End Do\n End Do\n!\n! Add-up alternatively + and - HUGE values to make the number of data\n! an exact multiple of 7.\n!\n IDEB = 7 * (NDON/7)\n NTRI = NDON\n If (IDEB < NDON) Then\n!\n XWRK1 = XHUGE\n Do ICRS = IDEB+1, IDEB+7\n If (ICRS <= NDON) Then\n XWRKT (ICRS) = XDONT (ICRS)\n Else\n If (XWRK1 /= XHUGE) NMED = NMED + 1\n XWRKT (ICRS) = XWRK1\n XWRK1 = - XWRK1\n Endif\n End Do\n!\n Do ICRS = IDEB+2, IDEB+7\n XWRK = XWRKT (ICRS)\n Do IDCR = ICRS - 1, IDEB+1, - 1\n If (XWRK >= XWRKT(IDCR)) Exit\n XWRKT (IDCR+1) = XWRKT (IDCR)\n End Do\n XWRKT (IDCR+1) = XWRK\n End Do\n!\n NTRI = IDEB+7\n End If\n!\n! Make the set of the indices of median values of each sorted subset\n!\n IDON1 = 0\n Do IDON = 1, NTRI, 7\n IDON1 = IDON1 + 1\n IMEDT (IDON1) = IDON + 3\n End Do\n!\n! Find XMED7, the median of the medians\n!\n XMED7 = R_valmed (XWRKT (IMEDT))\n!\n! Count how many values are not higher than (and how many equal to) XMED7\n! This number is at least 4 * 1/2 * (N/7) : 4 values in each of the\n! subsets where the median is lower than the median of medians. For similar\n! reasons, we also have at least 2N/7 values not lower than XMED7. At the\n! same time, we find in each subset the index of the last value < XMED7,\n! and that of the first > XMED7. These indices will be used to restrict the\n! search for the median as the Kth element in the subset (> or <) where\n! we know it to be.\n!\n IDON1 = 1\n NLEQ = 0\n NEQU = 0\n Do IDON = 1, NTRI, 7\n IMED = IDON+3\n If (XWRKT (IMED) > XMED7) Then\n IMED = IMED - 2\n If (XWRKT (IMED) > XMED7) Then\n IMED = IMED - 1\n Else If (XWRKT (IMED) < XMED7) Then\n IMED = IMED + 1\n Endif\n Else If (XWRKT (IMED) < XMED7) Then\n IMED = IMED + 2\n If (XWRKT (IMED) > XMED7) Then\n IMED = IMED - 1\n Else If (XWRKT (IMED) < XMED7) Then\n IMED = IMED + 1\n Endif\n Endif\n If (XWRKT (IMED) > XMED7) Then\n NLEQ = NLEQ + IMED - IDON\n IENDT (IDON1) = IMED - 1\n ISTRT (IDON1) = IMED\n Else If (XWRKT (IMED) < XMED7) Then\n NLEQ = NLEQ + IMED - IDON + 1\n IENDT (IDON1) = IMED\n ISTRT (IDON1) = IMED + 1\n Else ! If (XWRKT (IMED) == XMED7)\n NLEQ = NLEQ + IMED - IDON + 1\n NEQU = NEQU + 1\n IENDT (IDON1) = IMED - 1\n Do IMED1 = IMED - 1, IDON, -1\n If (XWRKT (IMED1) == XMED7) Then\n NEQU = NEQU + 1\n IENDT (IDON1) = IMED1 - 1\n Else\n Exit\n End If\n End Do\n ISTRT (IDON1) = IMED + 1\n Do IMED1 = IMED + 1, IDON + 6\n If (XWRKT (IMED1) == XMED7) Then\n NEQU = NEQU + 1\n NLEQ = NLEQ + 1\n ISTRT (IDON1) = IMED1 + 1\n Else\n Exit\n End If\n End Do\n Endif\n IDON1 = IDON1 + 1\n End Do\n!\n! Carry out a partial insertion sort to find the Kth smallest of the\n! large values, or the Kth largest of the small values, according to\n! what is needed.\n!\n If (NLEQ - NEQU + 1 <= NMED) Then\n If (NLEQ < NMED) Then ! Not enough low values\n XWRK1 = XHUGE\n NORD = NMED - NLEQ\n IDON1 = 0\n ICRS1 = 1\n ICRS2 = 0\n IDCR = 0\n Do IDON = 1, NTRI, 7\n IDON1 = IDON1 + 1\n If (ICRS2 < NORD) Then\n Do ICRS = ISTRT (IDON1), IDON + 6\n If (XWRKT(ICRS) < XWRK1) Then\n XWRK = XWRKT (ICRS)\n Do IDCR = ICRS1 - 1, 1, - 1\n If (XWRK >= XWRKT(IDCR)) Exit\n XWRKT (IDCR+1) = XWRKT (IDCR)\n End Do\n XWRKT (IDCR+1) = XWRK\n XWRK1 = XWRKT(ICRS1)\n Else\n If (ICRS2 < NORD) Then\n XWRKT (ICRS1) = XWRKT (ICRS)\n XWRK1 = XWRKT(ICRS1)\n Endif\n End If\n ICRS1 = MIN (NORD, ICRS1 + 1)\n ICRS2 = MIN (NORD, ICRS2 + 1)\n End Do\n Else\n Do ICRS = ISTRT (IDON1), IDON + 6\n If (XWRKT(ICRS) >= XWRK1) Exit\n XWRK = XWRKT (ICRS)\n Do IDCR = ICRS1 - 1, 1, - 1\n If (XWRK >= XWRKT(IDCR)) Exit\n XWRKT (IDCR+1) = XWRKT (IDCR)\n End Do\n XWRKT (IDCR+1) = XWRK\n XWRK1 = XWRKT(ICRS1)\n End Do\n End If\n End Do\n res_med = XWRK1\n Return\n Else\n res_med = XMED7\n Return\n End If\n Else ! If (NLEQ > NMED)\n! Not enough high values\n XWRK1 = -XHUGE\n NORD = NLEQ - NEQU - NMED + 1\n IDON1 = 0\n ICRS1 = 1\n ICRS2 = 0\n Do IDON = 1, NTRI, 7\n IDON1 = IDON1 + 1\n If (ICRS2 < NORD) Then\n!\n Do ICRS = IDON, IENDT (IDON1)\n If (XWRKT(ICRS) > XWRK1) Then\n XWRK = XWRKT (ICRS)\n IDCR = ICRS1 - 1\n Do IDCR = ICRS1 - 1, 1, - 1\n If (XWRK <= XWRKT(IDCR)) Exit\n XWRKT (IDCR+1) = XWRKT (IDCR)\n End Do\n XWRKT (IDCR+1) = XWRK\n XWRK1 = XWRKT(ICRS1)\n Else\n If (ICRS2 < NORD) Then\n XWRKT (ICRS1) = XWRKT (ICRS)\n XWRK1 = XWRKT (ICRS1)\n End If\n End If\n ICRS1 = MIN (NORD, ICRS1 + 1)\n ICRS2 = MIN (NORD, ICRS2 + 1)\n End Do\n Else\n Do ICRS = IENDT (IDON1), IDON, -1\n If (XWRKT(ICRS) > XWRK1) Then\n XWRK = XWRKT (ICRS)\n IDCR = ICRS1 - 1\n Do IDCR = ICRS1 - 1, 1, - 1\n If (XWRK <= XWRKT(IDCR)) Exit\n XWRKT (IDCR+1) = XWRKT (IDCR)\n End Do\n XWRKT (IDCR+1) = XWRK\n XWRK1 = XWRKT(ICRS1)\n Else\n Exit\n End If\n End Do\n Endif\n End Do\n!\n res_med = XWRK1\n Return\n End If\n!\nEnd Function R_valmed\nRecursive Function I_valmed (XDONT) Result (res_med)\n! Finds the median of XDONT using the recursive procedure\n! described in Knuth, The Art of Computer Programming,\n! vol. 3, 5.3.3 - This procedure is linear in time, and\n! does not require to be able to interpolate in the\n! set as the one used in INDNTH. It also has better worst\n! case behavior than INDNTH, but is about 30% slower in\n! average for random uniformly distributed values.\n! __________________________________________________________\n! __________________________________________________________\n Integer, Dimension (:), Intent (In) :: XDONT\n Integer :: res_med\n! __________________________________________________________\n Integer, Parameter :: XHUGE = HUGE (XDONT)\n Integer, Dimension (SIZE(XDONT)+6) :: XWRKT\n Integer :: XWRK, XWRK1, XMED7\n!\n Integer, Dimension ((SIZE(XDONT)+6)/7) :: ISTRT, IENDT, IMEDT\n Integer :: NDON, NTRI, NMED, NORD, NEQU, NLEQ, IMED, IDON, IDON1\n Integer :: IDEB, IWRK, IDCR, ICRS, ICRS1, ICRS2, IMED1\n!\n NDON = SIZE (XDONT)\n NMED = (NDON+1) / 2\n! write(unit=*,fmt=*) NMED, NDON\n!\n! If the number of values is small, then use insertion sort\n!\n If (NDON < 35) Then\n!\n! Bring minimum to first location to save test in decreasing loop\n!\n IDCR = NDON\n If (XDONT (1) < XDONT (NDON)) Then\n XWRK = XDONT (1)\n XWRKT (IDCR) = XDONT (IDCR)\n Else\n XWRK = XDONT (IDCR)\n XWRKT (IDCR) = XDONT (1)\n Endif\n Do IWRK = 1, NDON - 2\n IDCR = IDCR - 1\n XWRK1 = XDONT (IDCR)\n If (XWRK1 < XWRK) Then\n XWRKT (IDCR) = XWRK\n XWRK = XWRK1\n Else\n XWRKT (IDCR) = XWRK1\n Endif\n End Do\n XWRKT (1) = XWRK\n!\n! Sort the first half, until we have NMED sorted values\n!\n Do ICRS = 3, NMED\n XWRK = XWRKT (ICRS)\n IDCR = ICRS - 1\n Do\n If (XWRK >= XWRKT(IDCR)) Exit\n XWRKT (IDCR+1) = XWRKT (IDCR)\n IDCR = IDCR - 1\n End Do\n XWRKT (IDCR+1) = XWRK\n End Do\n!\n! Insert any value less than the current median in the first half\n!\n Do ICRS = NMED+1, NDON\n XWRK = XWRKT (ICRS)\n If (XWRK < XWRKT (NMED)) Then\n IDCR = NMED - 1\n Do\n If (XWRK >= XWRKT(IDCR)) Exit\n XWRKT (IDCR+1) = XWRKT (IDCR)\n IDCR = IDCR - 1\n End Do\n XWRKT (IDCR+1) = XWRK\n End If\n End Do\n res_med = XWRKT (NMED)\n Return\n End If\n!\n! Make sorted subsets of 7 elements\n! This is done by a variant of insertion sort where a first\n! pass is used to bring the smallest element to the first position\n! decreasing disorder at the same time, so that we may remove\n! remove the loop test in the insertion loop.\n!\n DO IDEB = 1, NDON-6, 7\n IDCR = IDEB + 6\n If (XDONT (IDEB) < XDONT (IDCR)) Then\n XWRK = XDONT (IDEB)\n XWRKT (IDCR) = XDONT (IDCR)\n Else\n XWRK = XDONT (IDCR)\n XWRKT (IDCR) = XDONT (IDEB)\n Endif\n Do IWRK = 1, 5\n IDCR = IDCR - 1\n XWRK1 = XDONT (IDCR)\n If (XWRK1 < XWRK) Then\n XWRKT (IDCR) = XWRK\n XWRK = XWRK1\n Else\n XWRKT (IDCR) = XWRK1\n Endif\n End Do\n XWRKT (IDEB) = XWRK\n Do ICRS = IDEB+2, IDEB+6\n XWRK = XWRKT (ICRS)\n If (XWRK < XWRKT(ICRS-1)) Then\n XWRKT (ICRS) = XWRKT (ICRS-1)\n IDCR = ICRS - 1\n XWRK1 = XWRKT (IDCR-1)\n Do\n If (XWRK >= XWRK1) Exit\n XWRKT (IDCR) = XWRK1\n IDCR = IDCR - 1\n XWRK1 = XWRKT (IDCR-1)\n End Do\n XWRKT (IDCR) = XWRK\n EndIf\n End Do\n End Do\n!\n! Add-up alternatively + and - HUGE values to make the number of data\n! an exact multiple of 7.\n!\n IDEB = 7 * (NDON/7)\n NTRI = NDON\n If (IDEB < NDON) Then\n!\n XWRK1 = XHUGE\n Do ICRS = IDEB+1, IDEB+7\n If (ICRS <= NDON) Then\n XWRKT (ICRS) = XDONT (ICRS)\n Else\n If (XWRK1 /= XHUGE) NMED = NMED + 1\n XWRKT (ICRS) = XWRK1\n XWRK1 = - XWRK1\n Endif\n End Do\n!\n Do ICRS = IDEB+2, IDEB+7\n XWRK = XWRKT (ICRS)\n Do IDCR = ICRS - 1, IDEB+1, - 1\n If (XWRK >= XWRKT(IDCR)) Exit\n XWRKT (IDCR+1) = XWRKT (IDCR)\n End Do\n XWRKT (IDCR+1) = XWRK\n End Do\n!\n NTRI = IDEB+7\n End If\n!\n! Make the set of the indices of median values of each sorted subset\n!\n IDON1 = 0\n Do IDON = 1, NTRI, 7\n IDON1 = IDON1 + 1\n IMEDT (IDON1) = IDON + 3\n End Do\n!\n! Find XMED7, the median of the medians\n!\n XMED7 = I_valmed (XWRKT (IMEDT))\n!\n! Count how many values are not higher than (and how many equal to) XMED7\n! This number is at least 4 * 1/2 * (N/7) : 4 values in each of the\n! subsets where the median is lower than the median of medians. For similar\n! reasons, we also have at least 2N/7 values not lower than XMED7. At the\n! same time, we find in each subset the index of the last value < XMED7,\n! and that of the first > XMED7. These indices will be used to restrict the\n! search for the median as the Kth element in the subset (> or <) where\n! we know it to be.\n!\n IDON1 = 1\n NLEQ = 0\n NEQU = 0\n Do IDON = 1, NTRI, 7\n IMED = IDON+3\n If (XWRKT (IMED) > XMED7) Then\n IMED = IMED - 2\n If (XWRKT (IMED) > XMED7) Then\n IMED = IMED - 1\n Else If (XWRKT (IMED) < XMED7) Then\n IMED = IMED + 1\n Endif\n Else If (XWRKT (IMED) < XMED7) Then\n IMED = IMED + 2\n If (XWRKT (IMED) > XMED7) Then\n IMED = IMED - 1\n Else If (XWRKT (IMED) < XMED7) Then\n IMED = IMED + 1\n Endif\n Endif\n If (XWRKT (IMED) > XMED7) Then\n NLEQ = NLEQ + IMED - IDON\n IENDT (IDON1) = IMED - 1\n ISTRT (IDON1) = IMED\n Else If (XWRKT (IMED) < XMED7) Then\n NLEQ = NLEQ + IMED - IDON + 1\n IENDT (IDON1) = IMED\n ISTRT (IDON1) = IMED + 1\n Else ! If (XWRKT (IMED) == XMED7)\n NLEQ = NLEQ + IMED - IDON + 1\n NEQU = NEQU + 1\n IENDT (IDON1) = IMED - 1\n Do IMED1 = IMED - 1, IDON, -1\n If (XWRKT (IMED1) == XMED7) Then\n NEQU = NEQU + 1\n IENDT (IDON1) = IMED1 - 1\n Else\n Exit\n End If\n End Do\n ISTRT (IDON1) = IMED + 1\n Do IMED1 = IMED + 1, IDON + 6\n If (XWRKT (IMED1) == XMED7) Then\n NEQU = NEQU + 1\n NLEQ = NLEQ + 1\n ISTRT (IDON1) = IMED1 + 1\n Else\n Exit\n End If\n End Do\n Endif\n IDON1 = IDON1 + 1\n End Do\n!\n! Carry out a partial insertion sort to find the Kth smallest of the\n! large values, or the Kth largest of the small values, according to\n! what is needed.\n!\n If (NLEQ - NEQU + 1 <= NMED) Then\n If (NLEQ < NMED) Then ! Not enough low values\n XWRK1 = XHUGE\n NORD = NMED - NLEQ\n IDON1 = 0\n ICRS1 = 1\n ICRS2 = 0\n IDCR = 0\n Do IDON = 1, NTRI, 7\n IDON1 = IDON1 + 1\n If (ICRS2 < NORD) Then\n Do ICRS = ISTRT (IDON1), IDON + 6\n If (XWRKT(ICRS) < XWRK1) Then\n XWRK = XWRKT (ICRS)\n Do IDCR = ICRS1 - 1, 1, - 1\n If (XWRK >= XWRKT(IDCR)) Exit\n XWRKT (IDCR+1) = XWRKT (IDCR)\n End Do\n XWRKT (IDCR+1) = XWRK\n XWRK1 = XWRKT(ICRS1)\n Else\n If (ICRS2 < NORD) Then\n XWRKT (ICRS1) = XWRKT (ICRS)\n XWRK1 = XWRKT(ICRS1)\n Endif\n End If\n ICRS1 = MIN (NORD, ICRS1 + 1)\n ICRS2 = MIN (NORD, ICRS2 + 1)\n End Do\n Else\n Do ICRS = ISTRT (IDON1), IDON + 6\n If (XWRKT(ICRS) >= XWRK1) Exit\n XWRK = XWRKT (ICRS)\n Do IDCR = ICRS1 - 1, 1, - 1\n If (XWRK >= XWRKT(IDCR)) Exit\n XWRKT (IDCR+1) = XWRKT (IDCR)\n End Do\n XWRKT (IDCR+1) = XWRK\n XWRK1 = XWRKT(ICRS1)\n End Do\n End If\n End Do\n res_med = XWRK1\n Return\n Else\n res_med = XMED7\n Return\n End If\n Else ! If (NLEQ > NMED)\n! Not enough high values\n XWRK1 = -XHUGE\n NORD = NLEQ - NEQU - NMED + 1\n IDON1 = 0\n ICRS1 = 1\n ICRS2 = 0\n Do IDON = 1, NTRI, 7\n IDON1 = IDON1 + 1\n If (ICRS2 < NORD) Then\n!\n Do ICRS = IDON, IENDT (IDON1)\n If (XWRKT(ICRS) > XWRK1) Then\n XWRK = XWRKT (ICRS)\n IDCR = ICRS1 - 1\n Do IDCR = ICRS1 - 1, 1, - 1\n If (XWRK <= XWRKT(IDCR)) Exit\n XWRKT (IDCR+1) = XWRKT (IDCR)\n End Do\n XWRKT (IDCR+1) = XWRK\n XWRK1 = XWRKT(ICRS1)\n Else\n If (ICRS2 < NORD) Then\n XWRKT (ICRS1) = XWRKT (ICRS)\n XWRK1 = XWRKT (ICRS1)\n End If\n End If\n ICRS1 = MIN (NORD, ICRS1 + 1)\n ICRS2 = MIN (NORD, ICRS2 + 1)\n End Do\n Else\n Do ICRS = IENDT (IDON1), IDON, -1\n If (XWRKT(ICRS) > XWRK1) Then\n XWRK = XWRKT (ICRS)\n IDCR = ICRS1 - 1\n Do IDCR = ICRS1 - 1, 1, - 1\n If (XWRK <= XWRKT(IDCR)) Exit\n XWRKT (IDCR+1) = XWRKT (IDCR)\n End Do\n XWRKT (IDCR+1) = XWRK\n XWRK1 = XWRKT(ICRS1)\n Else\n Exit\n End If\n End Do\n Endif\n End Do\n!\n res_med = XWRK1\n Return\n End If\n!\nEnd Function I_valmed\nend module m_valmed\n", "meta": {"hexsha": "e40407b3fb94af6236463a814d6beeeb236ef679", "size": 35804, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/f2000/valmed.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/f2000/valmed.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/f2000/valmed.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": 35.1709233792, "max_line_length": 76, "alphanum_fraction": 0.4175231818, "num_tokens": 10913, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.6635515995947646}} {"text": "!*==dlapy3.f90 processed by SPAG 7.51RB at 20:08 on 3 Mar 2022\n!> \\brief \\b DLAPY3 returns sqrt(x2+y2+z2).\n!\n! =========== DOCUMENTATION ===========\n!\n! Online html documentation available at\n! http://www.netlib.org/lapack/explore-html/\n!\n!> \\htmlonly\n!> Download DLAPY3 + dependencies\n!> \n!> [TGZ]\n!> \n!> [ZIP]\n!> \n!> [TXT]\n!> \\endhtmlonly\n!\n! Definition:\n! ===========\n!\n! DOUBLE PRECISION FUNCTION DLAPY3( X, Y, Z )\n!\n! .. Scalar Arguments ..\n! DOUBLE PRECISION X, Y, Z\n! ..\n!\n!\n!> \\par Purpose:\n! =============\n!>\n!> \\verbatim\n!>\n!> DLAPY3 returns sqrt(x**2+y**2+z**2), taking care not to cause\n!> unnecessary overflow.\n!> \\endverbatim\n!\n! Arguments:\n! ==========\n!\n!> \\param[in] X\n!> \\verbatim\n!> X is DOUBLE PRECISION\n!> \\endverbatim\n!>\n!> \\param[in] Y\n!> \\verbatim\n!> Y is DOUBLE PRECISION\n!> \\endverbatim\n!>\n!> \\param[in] Z\n!> \\verbatim\n!> Z is DOUBLE PRECISION\n!> X, Y and Z specify the values x, y and z.\n!> \\endverbatim\n!\n! Authors:\n! ========\n!\n!> \\author Univ. of Tennessee\n!> \\author Univ. of California Berkeley\n!> \\author Univ. of Colorado Denver\n!> \\author NAG Ltd.\n!\n!> \\date December 2016\n!\n!> \\ingroup OTHERauxiliary\n!\n! =====================================================================\n DOUBLE PRECISION FUNCTION DLAPY3(X,Y,Z)\n IMPLICIT NONE\n!*--DLAPY372\n!\n! -- LAPACK auxiliary routine (version 3.7.0) --\n! -- LAPACK is a software package provided by Univ. of Tennessee, --\n! -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n! December 2016\n!\n! .. Scalar Arguments ..\n DOUBLE PRECISION X , Y , Z\n! ..\n!\n! =====================================================================\n!\n! .. Parameters ..\n DOUBLE PRECISION ZERO\n PARAMETER (ZERO=0.0D0)\n! ..\n! .. Local Scalars ..\n DOUBLE PRECISION w , xabs , yabs , zabs\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC ABS , MAX , SQRT\n! ..\n! .. Executable Statements ..\n!\n xabs = ABS(X)\n yabs = ABS(Y)\n zabs = ABS(Z)\n w = MAX(xabs,yabs,zabs)\n IF ( w==ZERO ) THEN\n! W can be zero for max(0,nan,0)\n! adding all three entries together will make sure\n! NaN will not disappear.\n DLAPY3 = xabs + yabs + zabs\n ELSE\n DLAPY3 = w*SQRT((xabs/w)**2+(yabs/w)**2+(zabs/w)**2)\n ENDIF\n!\n! End of DLAPY3\n!\n END FUNCTION DLAPY3\n", "meta": {"hexsha": "00ebdfa18cb22d451af889d01881d5260ed4941f", "size": 2772, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/double/dlapy3.f90", "max_stars_repo_name": "urbanjost/spag_lapack", "max_stars_repo_head_hexsha": "1b082638c0ff5feb1a295a3aa4624c538d14847c", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2022-03-04T13:15:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-04T17:40:26.000Z", "max_issues_repo_path": "src/double/dlapy3.f90", "max_issues_repo_name": "urbanjost/spag_lapack", "max_issues_repo_head_hexsha": "1b082638c0ff5feb1a295a3aa4624c538d14847c", "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": "src/double/dlapy3.f90", "max_forks_repo_name": "urbanjost/spag_lapack", "max_forks_repo_head_hexsha": "1b082638c0ff5feb1a295a3aa4624c538d14847c", "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": 24.5309734513, "max_line_length": 111, "alphanum_fraction": 0.5508658009, "num_tokens": 872, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8723473647220786, "lm_q2_score": 0.760650658103136, "lm_q1q2_score": 0.6635515970703856}} {"text": "subroutine dTuberiaSimple\n use messages\n implicit none\n !!Variables Externas\n real:: Qd, ks, d_delta, H, z2, l, nu,sigma_km,E\n\n !!Variables Internas\n real:: di, hfi, vi, Qi, Hfi_1,sigma_hm\n real, parameter, dimension(1:6)::d_comercial=(/3,4,6,8,10,12/) !Tomados del ejemplo 2.5\n integer::i,j=1,k=0\n character :: option !es la opci\u00f3n par cambiar los ejemplos (y/n)\n\n real, parameter :: pi = 4 * atan (1.0), g = 9.81, p_agua = 999.1\n\n\n\n print *, char(10),\" <<<<1: disenio de tuberia simple>>>>\",char(10) \n\n\n\n !Leer las variables\n l=150; ks=0.00015;Qd=0.12; H=2.2;Sigma_km=0.5+0.8+10*0.1+1; nu = 1.17E-6; E = 1.0E-5; d_delta=0.0254; z2=0\n print\"('Por defecto, se cargaran datos del ejemplo 2.3'/)\"\n do i = 1,10\n \n print datosEjercicio4, l,ks,Qd,H,Sigma_km,nu,E,d_delta\n print \"('Diametros comerciales(inch): ',6f10.0)\",d_comercial(:)\n print \"('Diametros comerciales( mts): ',6f10.4)\",d_comercial(:)*0.0254\n \n write(*,'(a)',ADVANCE=\"NO\") \"Desea continuar con estos datos (y/n)? \"\n read(*,*) option\n if (option == 'y')then \n exit\n else\n write(*,*) char(10),\"introduzca los valores(9) como un vector con el sgte formato: \"\n print*,\"l, ks, Qd, H, Sigma_km, nu, E, d_delta\"\n read(*,*)l, ks, Qd, H, Sigma_km, nu, E, d_delta !DEBUG\n print*, char(10)\n end if\n end do\n \n \n \n \n \n\n !Suponer hs = H-z2\n hfi= H-z2\n\n !Suponer d peque\u00f1o\n di=5*0.0254\n\n print\"(/,2x,'i',2x,'k',4x,'di',4x,'hfi',4x,'j',5x,'vi',5x,'Qi',4x,'Qi>Qd',2x,'Sigma_hm')\"\n !Loop\n do i = 0, 10, 1\n vi = cal_vi(l,ks,nu,g,di,hfi)\n sigma_hm = sigma_km* vi**2 /(2*g)\n\n !Calcular Q\n Qi=vi*pi/4 * di ** 2\n\n !Visualizacion 1ra convergencia\n print \"(i3,1x,i2,2x,f6.4,2x,f4.2,2x,f3.0,2x,f5.3,2x,f6.4,4x,L1,5x,f5.3)\",&\n i,k, di,hfi,d_comercial(j), vi,Qi,Qi>Qd,sigma_hm\n\n\n if (Qi < Qd) then\n if (di>=d_comercial(1)*0.0254)then\n di = d_comercial(j+1)*0.0254 \n if (jQd,sigma_hm\n end if\n\n end do\n\n\n\n if (Qi > Qd) then\n exit\n else\n if (di>=d_comercial(1)*0.0254)then\n di = d_comercial(j+1)*0.0254 \n if (j> 1996-06-18 DRDBLAS1 Krogh Minor format change for C conversion.\nc>> 1996-05-28 DRDBLAS1 Krogh Added external statement.\nc>> 1994-10-19 DRDBLAS1 Krogh Changes to use M77CON\nc>> 1992-03-24 DRDBLAS1 CLL Removed reference to DBLE() function.\nc>> 1991-12-02 DRDBLAS1 CLL\nc>> 1991-07-25 DRDBLAS1 CLL\nc>> 1987-12-09 DRBLAS1 Lawson Initial Code.\nc\nc Demonstrate usage of DAXPY, DCOPY, and DDOT from the BLAS\nc by computing\nc (1) p = A * b using DDOT\nc (2) q = A * b using DCOPY & DAXPY\nc (3) r = (A Transposed) * p using DDOT\nc (4) S = A * E using DDOT\nc ------------------------------------------------------------------\nc--D replaces \"?\": DR?BLAS1, ?AXPY, ?COPY, ?DOT\nc ------------------------------------------------------------------\n external DDOT\n double precision DDOT\n integer M2, M3, M4, N2, N3, N4\n parameter ( M2=5, M3=10, M4=12 )\n parameter ( N2=2, N3=3, N4=4 )\n integer I, J\n double precision A(M2,M3), E(M3,M4), S(M2,M4)\n double precision B(M3), P(M2), Q(M2), R(M3)\n double precision ZERO(1)\nc\n data ZERO(1) / 0.0d0 /\n data (A(1,J),J=1,N3) / 2.0d0, -4.0d0, 3.0d0 /\n data (A(2,J),J=1,N3) / -5.0d0, -2.0d0, 6.0d0 /\n data (B(J),J=1,N3) / 7.0d0, -3.0d0, 5.0d0 /\n data (E(1,J),J=1,N4) / -4.0d0, 2.0d0, 3.0d0, -6.0d0 /\n data (E(2,J),J=1,N4) / 7.0d0, 5.0d0, -6.0d0, -3.0d0 /\n data (E(3,J),J=1,N4) / 3.0d0, 4.0d0, -2.0d0, 5.0d0 /\nc ---------------------------------------------------------------\nc\nc 1. p = A * b using DDOT\nc\n do 10 I = 1, N2\n P(I) = DDOT(N3,A(I,1),M2,B,1)\n 10 continue\nc\nc 2. q = A * b using DCOPY and DAXPY\nc\n call DCOPY(N2,ZERO,0,Q,1)\n do 20 J = 1, N3\n call DAXPY(N2,B(J),A(1,J),1,Q,1)\n 20 continue\nc\nc 3. r = (A Transposed) * p using DDOT\nc\n do 30 J = 1, N3\n R(J) = DDOT(N2,A(1,J),1,P,1)\n 30 continue\nc\nc 4. S = A * E using DDOT\nc\n do 50 I = 1, N2\n do 40 J = 1, N4\n S(I,J) = DDOT(N3,A(I,1),M2,E(1,J),1)\n 40 continue\n 50 continue\nc\n print*,'DRDBLAS1.. Demo driver for DAXPY, DCOPY, and DDOT'\n print'(/'' P() = '', 7x,4f8.1)', (P(J),J=1,N2)\n print'(/'' Q() = '',7x,4f8.1)', (Q(J),J=1,N2)\n print'(/'' R() = '',7x,4f8.1)', (R(J),J=1,N3)\n print'(/'' S(,) = '')'\n do 60 I = 1,N2\n print'('' Row '',i2,5x,4f8.1)', I,(S(I,J),J=1,N4)\n 60 continue\n stop\n end\n", "meta": {"hexsha": "8a38fa84949f64fe0c39a579fe99a7221a9bfaba", "size": 2621, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drdblas1.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drdblas1.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drdblas1.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": 34.9466666667, "max_line_length": 72, "alphanum_fraction": 0.4524990462, "num_tokens": 1090, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.7606506526772883, "lm_q1q2_score": 0.6635515948615407}} {"text": "\n subroutine caprsh2(irho)\nc--\nc Evaluate CAPR, CAPS, and H2. Here, m is the poloidal mode number\nc and n is the toroidal mode number/periods.\nc--LAB--changed calculation of H2 to use proper 1/b**2 Jacobian for\nc flux surface average\nC-----------------------------------------------\nC M o d u l e s\nC-----------------------------------------------\n use parambs\n use vmec0\n implicit none\nC-----------------------------------------------\nC D u m m y A r g u m e n t s\nC-----------------------------------------------\n integer irho\nC-----------------------------------------------\nC L o c a l P a r a m e t e r s\nC-----------------------------------------------\n real(rprec), parameter :: zero = 0, one = 1\nC-----------------------------------------------\nC L o c a l V a r i a b l e s\nC-----------------------------------------------\n integer :: nh, m, i, j\n real(rprec) :: h2top_th, h2top_phi, den, qn, e2\n real(rprec) :: b2, h2top\n real(rprec) :: h2top_tmp, den_tmp, sin_eps\nC-----------------------------------------------------------------------\n\nc the following code was added to evaluate H2 LAB\n h2top = zero\n den = zero\n do i=1, nthetah\n do j=1, nzetah\n h2top_th = zero\n h2top_phi = zero\n den_tmp = zero\n do nh = 0, nbuse ! evaluate i,j terms in num and denom of H2\n qn = qsafety(irho)*periods*nh*zetasign\n do m = -mbuse, mbuse\n sin_eps = amnfit(irho,m,nh)*\n 1 (sinmi(m,i)*cosnj(nh,j)+cosmi(m,i)*sinnj(nh,j))\n h2top_th = h2top_th - m*sin_eps\n h2top_phi = h2top_phi - qn*sin_eps\n den_tmp = den_tmp - (m + qn)*sin_eps\n enddo\n enddo\n b2 = bfield(i,j)**2\n h2top = h2top + (h2top_th**2 - h2top_phi**2)/b2\n den = den + den_tmp**2/b2\n enddo\n enddo\n\n ! Modified by SAL so code won't stop\n !if (den .eq. zero) stop 'den = 0 in caprsh2'\n IF (den .eq. zero) THEN\n IF (lscreen) THEN\n WRITE(6,'(A)') 'WARNING(BOOTSJ): den = 0 in caprsh2'\n WRITE(6,'(A,I3.3)') ' irho: ',irho\n END IF\n h2(irho) = 0.0\n ELSE\n h2(irho) = h2top/den\n END IF\n capr(irho) = (one - h2(irho))/(2*qsafety(irho))\n caps(irho) = (one + h2(irho))/2\n\n end subroutine caprsh2\n", "meta": {"hexsha": "5ed3464335630bb772fda0eb88c363b8f69bb001", "size": 2482, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "BOOTSJ/Sources/caprsh2.f", "max_stars_repo_name": "joseluisvelasco/STELLOPT", "max_stars_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2020-05-08T01:47:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T10:35:28.000Z", "max_issues_repo_path": "BOOTSJ/Sources/caprsh2.f", "max_issues_repo_name": "joseluisvelasco/STELLOPT", "max_issues_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 77, "max_issues_repo_issues_event_min_datetime": "2020-05-08T07:18:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:20:33.000Z", "max_forks_repo_path": "BOOTSJ/Sources/caprsh2.f", "max_forks_repo_name": "joseluisvelasco/STELLOPT", "max_forks_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-02-10T13:47:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T12:53:43.000Z", "avg_line_length": 35.4571428571, "max_line_length": 84, "alphanum_fraction": 0.4190169218, "num_tokens": 731, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632876167045, "lm_q2_score": 0.7154240079185319, "lm_q1q2_score": 0.663457960023249}} {"text": " SUBROUTINE DE01PD( CONV, WGHT, N, A, B, W, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute the convolution or deconvolution of two real signals\nC A and B using the Hartley transform.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC CONV CHARACTER*1\nC Indicates whether convolution or deconvolution is to be\nC performed as follows:\nC = 'C': Convolution;\nC = 'D': Deconvolution.\nC\nC WGHT CHARACTER*1\nC Indicates whether the precomputed weights are available\nC or not, as follows:\nC = 'A': available;\nC = 'N': not available.\nC Note that if N > 1 and WGHT = 'N' on entry, then WGHT is\nC set to 'A' on exit.\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The number of samples. N must be a power of 2. N >= 0.\nC\nC A (input/output) DOUBLE PRECISION array, dimension (N)\nC On entry, this array must contain the first signal.\nC On exit, this array contains the convolution (if\nC CONV = 'C') or deconvolution (if CONV = 'D') of the two\nC signals.\nC\nC B (input) DOUBLE PRECISION array, dimension (N)\nC On entry, this array must contain the second signal.\nC NOTE that this array is overwritten.\nC\nC W (input/output) DOUBLE PRECISION array,\nC dimension (N - LOG2(N))\nC On entry with WGHT = 'A', this array must contain the long\nC weight vector computed by a previous call of this routine\nC or of the SLICOT Library routine DG01OD.f, with the same\nC value of N. If WGHT = 'N', the contents of this array on\nC entry is ignored.\nC On exit, this array contains the long weight vector.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value.\nC\nC METHOD\nC\nC This routine computes the convolution or deconvolution of two\nC real signals A and B using three scrambled Hartley transforms\nC (SLICOT Library routine DG01OD).\nC\nC REFERENCES\nC\nC [1] Van Loan, Charles.\nC Computational frameworks for the fast Fourier transform.\nC SIAM, 1992.\nC\nC NUMERICAL ASPECTS\nC\nC The algorithm requires O(N log(N)) floating point operations.\nC\nC CONTRIBUTOR\nC\nC D. Kressner, Technical Univ. Berlin, Germany, April 2001.\nC\nC REVISIONS\nC\nC V. Sima, Research Institute for Informatics, Bucharest, Apr. 2000.\nC\nC KEYWORDS\nC\nC Convolution, deconvolution, digital signal processing,\nC fast Hartley transform, real signals.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION HALF, TWO\n PARAMETER ( HALF = 0.5D0, TWO = 2.0D0 )\nC .. Scalar Arguments ..\n CHARACTER CONV, WGHT\n INTEGER INFO, N\nC .. Array Arguments ..\n DOUBLE PRECISION A(*), B(*), W(*)\nC .. Local Scalars ..\n LOGICAL LCONV, LWGHT\n INTEGER J, L, LEN, M, P1, R1\n DOUBLE PRECISION T1, T2, T3\nC .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\nC .. External Subroutines ..\n EXTERNAL DG01OD, DLADIV, DSCAL, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC DBLE, MOD\nC .. Executable Statements ..\nC\n INFO = 0\n LCONV = LSAME( CONV, 'C' )\n LWGHT = LSAME( WGHT, 'A' )\nC\nC Test the input scalar arguments.\nC\n IF( .NOT.LCONV .AND. .NOT.LSAME( CONV, 'D' ) ) THEN\n INFO = -1\n ELSE IF( .NOT.LWGHT .AND. .NOT.LSAME( WGHT, 'N' ) ) THEN\n INFO = -2\n ELSE\n M = 0\n J = 0\n IF( N.GE.1 ) THEN\n J = N\nC WHILE ( MOD( J, 2 ).EQ.0 ) DO\n 10 CONTINUE\n IF ( MOD( J, 2 ).EQ.0 ) THEN\n J = J/2\n M = M + 1\n GO TO 10\n END IF\nC END WHILE 10\n IF ( J.NE.1 ) INFO = -3\n ELSE IF ( N.LT.0 ) THEN\n INFO = -3\n END IF\n END IF\nC\n IF ( INFO.NE.0 ) THEN\nC\nC Error return.\nC\n CALL XERBLA( 'DE01PD', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF ( N.LE.0 ) THEN\n RETURN\n ELSE IF ( N.EQ.1 ) THEN\n IF ( LCONV ) THEN\n A(1) = A(1)*B(1)\n ELSE\n A(1) = A(1)/B(1)\n END IF\n RETURN\n END IF\nC\nC Scrambled Hartley transforms of A and B.\nC\n CALL DG01OD( 'OutputScrambled', WGHT, N, A, W, INFO )\n CALL DG01OD( 'OutputScrambled', WGHT, N, B, W, INFO )\nC\nC Something similar to a Hadamard product/quotient.\nC\n LEN = 1\n IF( LCONV ) THEN\n A(1) = TWO*A(1)*B(1)\n A(2) = TWO*A(2)*B(2)\nC\n DO 30 L = 1, M - 1\n LEN = 2*LEN\n R1 = 2*LEN\nC\n DO 20 P1 = LEN + 1, LEN + LEN/2\n T1 = B(P1) + B(R1)\n T2 = B(P1) - B(R1)\n T3 = T2*A(P1)\n A(P1) = T1*A(P1) + T2*A(R1)\n A(R1) = T1*A(R1) - T3\n R1 = R1 - 1\n 20 CONTINUE\nC\n 30 CONTINUE\nC\n ELSE\nC\n A(1) = HALF*A(1)/B(1)\n A(2) = HALF*A(2)/B(2)\nC\n DO 50 L = 1, M - 1\n LEN = 2*LEN\n R1 = 2*LEN\nC\n DO 40 P1 = LEN + 1, LEN + LEN/2\n CALL DLADIV( A(P1), A(R1), B(P1)+B(R1), B(R1)-B(P1), T1,\n $ T2 )\n A(P1) = T1\n A(R1) = T2\n R1 = R1 - 1\n 40 CONTINUE\nC\n 50 CONTINUE\nC\n END IF\nC\nC Transposed Hartley transform of A.\nC\n CALL DG01OD( 'InputScrambled', WGHT, N, A, W, INFO )\n IF ( LCONV ) THEN\n CALL DSCAL( N, HALF/DBLE( N ), A, 1 )\n ELSE\n CALL DSCAL( N, TWO/DBLE( N ), A, 1 )\n END IF\nC\n RETURN\nC *** Last line of DE01PD ***\n END\n", "meta": {"hexsha": "0875e7379513048f4eb5cc35b3fb8fb311283d98", "size": 6126, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/DE01PD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/DE01PD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/DE01PD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 27.4708520179, "max_line_length": 72, "alphanum_fraction": 0.5039177277, "num_tokens": 1933, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9273633016692236, "lm_q2_score": 0.7154239897159438, "lm_q1q2_score": 0.6634579531963464}} {"text": "c.......subroutine bfilter\nc\nc\tWritten by: David R. Russell, AFTAC/TT 10 December 2004\nc\nc Subroutine bfilter executes a fast, stable zero phase butterworth\nc bandpass filter of order (m), which is optimized for narrow band\nc applications. The method produces a complex time series output,\nc of which the real portion is used to calculate the filtered time\nc series, and the modulus is used to calculate the envelope function.\nc Stability of the method is achieved by reducing the bandpass \nc filter calculations to simple cascaded first order filters,\nc which are forward and reverse filtered for zero phase. The method\nc also does a linear shift of a butterworth lowpass filter \nc to an equivalent bandpass, without going through a standard\nc non-linear translation (Kanasewich, E.R., 1975) to bandpass. An option\nc is included to remove the signal mean initially to compensate for\nc large DC offsets\nc \nc\tINPUT:\nc\nc\tm: Order of Butterworth filter\nc\tn: Number of input, output time series points\nc mzer: Integer flag to remove mean (0 no, 1 yes)\nc\txr(n): Input (real) time series\nc f0: Center value of bandpass filter\nc fc: Corners of filter [ flow= f0-fc; fhigh= f0+fc ]\nc dt: Time series sampling interval\nc\nc\tOUTPUT:\nc\nc yr(n): Output filtered (real) time series\nc\ter(n): Output envelope function for filtered time series\nc ermx: Maximum value of envelope function er.\nc\nc**************************** \n subroutine bfilter(xr,yr,er,ermx,f0,fc,dt,m,n,mzer)\nc****************************\nc\nc.......nmax = total possible number of time series points\nc mmax = highest possible order of butterworth filter\nc\n parameter (nmax=65000,mmax=10)\nc\n double complex z1(nmax),z2(nmax),a1(mmax),a2(mmax),\n & a1c(mmax),a2c(mmax),p,s,ctemp\n double precision pi,w0,wc,w1,w2,dtemp,dtt\n dimension xr(n),yr(n),er(n)\nc\nc.......error check on frequencies\nc\n fnyq=1.0/(2.0*dt)\n if ((f0-fc).le.0.0) then\n write(6,*)'low corner frequency (f0-fc) <= 0.0'\n stop\n endif\n if ((f0+fc).ge.fnyq) then\n write(6,*)'high corner frequency (f0+fc) >= nyquist'\n stop\n endif\nc\nc.......initialize double precision pi, dtt, angular frequencies w0,wc\nc\n pi=3.14159265358979d0\n w0=2.0d0*pi*dble(f0)\n wc=2.0d0*pi*dble(fc)\n dtt=dble(dt)\nc\nc.......prewarp frequencies for bilinear z-transform\nc\n w1=w0-wc\n w2=w0+wc\n w1=2.0d0/dtt*dtan(w1*dtt/2.0d0)\n w2=2.0d0/dtt*dtan(w2*dtt/2.0d0)\n w0=(w1+w2)/2.0d0\n wc=(w2-w1)/2.0d0\nc\nc.......calculate (m) prototype lowpass poles (p), translate into bandpass\nc poles (s), calculate bilinear recursive coefficients (a1,a2),\nc conjugates of coefficients (a1c,a2c)\nc\n do j=1,m\n dtemp=pi*(2.0d0*dble(j)-1.0d0+dble(m))/(2.0d0*dble(m))\n ctemp=dcmplx(0.0d0,dtemp)\n p=cdexp(ctemp)\n s=p*wc+dcmplx(0.0d0,w0)\n a1(j)=wc*dtt/(2.0d0-s*dtt)\n a2(j)=(2.0d0+s*dtt)/(2.0d0-s*dtt)\n a1c(j)=dconjg(a1(j))\n a2c(j)=dconjg(a2(j))\n enddo\nc\nc.......put real time series xr into complex series z1 and remove mean\nc if mzer set to 1\nc\n xmean=0.0\n if(mzer.eq.1) then\n do k=1,n\n xmean=xmean+xr(k)\n enddo\n xmean=xmean/float(n)\n endif\n do k=1,n\n z1(k)=xr(k)-xmean\n enddo\nc\nc.......calculate (m) cascaded first order complex filters\nc \n do j=1,m\n do k=1,n\n z2(k)=z1(k)\n enddo\n z1(1)=a1(j)*z2(1)\n do k=2,n\n z1(k)=a1(j)*(z2(k)+z2(k-1))+a2(j)*z1(k-1)\n enddo\n enddo\nc\nc.......reverse filtered time series\nc\n do k=1,n\n z2(k)=z1(n-k+1)\n enddo\nc\nc.......calculate (m) cascaded first order complex filters on\nc reversed series - note conjugate bilinear coefficients\nc for complex conjugate of filter\nc\n do j=1,m\n do k=1,n\n z1(k)=z2(k)\n enddo\n z2(1)=a1c(j)*z1(1)\n do k=2,n\n z2(k)=a1c(j)*(z1(k)+z1(k-1))+a2c(j)*z2(k-1)\n enddo\n enddo\nc\nc.......reverse filtered time series\nc\n do k=1,n\n z1(k)=z2(n-k+1)\n enddo\nc\nc.......calculate real output time series (yr), envelope (er),\nc envelope maximum (ermx)\nc\n ermx=0.0\n do k=1,n\n yr(k)=2.0*dreal(z1(k))\n er(k)=2.0*cdabs(z1(k))\n ermx=amax1(er(k),ermx)\n enddo\n return\n end\n", "meta": {"hexsha": "ebb29972c24598ceecba0f5d7e9aec9fceb1041b", "size": 4541, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ni/src/lib/nfpfort/bfilter1.f", "max_stars_repo_name": "jlost/ncl_ncarg", "max_stars_repo_head_hexsha": "2206367f1887732bc7745bfb5ca56f6543f77948", "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": "ni/src/lib/nfpfort/bfilter1.f", "max_issues_repo_name": "jlost/ncl_ncarg", "max_issues_repo_head_hexsha": "2206367f1887732bc7745bfb5ca56f6543f77948", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2016-09-27T18:49:30.000Z", "max_issues_repo_issues_event_max_datetime": "2016-09-27T18:49:30.000Z", "max_forks_repo_path": "ni/src/lib/nfpfort/bfilter1.f", "max_forks_repo_name": "jlost/ncl_ncarg", "max_forks_repo_head_hexsha": "2206367f1887732bc7745bfb5ca56f6543f77948", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.2967741935, "max_line_length": 78, "alphanum_fraction": 0.5892975116, "num_tokens": 1519, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632956467157, "lm_q2_score": 0.7154239897159439, "lm_q1q2_score": 0.6634579488876998}} {"text": "PROGRAM mo_bootstrapping_test\n\n USE mo_bootstrapping_sensitivity_analysis, only: bootstrap_si\n USE mo_kind, only: i4, i8, dp\n USE mo_model, only: model, par_range\n USE mo_sobol, only: sobol_array\n USE mo_sobol_index, only: sobol_index\n use mo_ansi_colors, only: color, c_red, c_green\n\n IMPLICIT NONE\n\n!-----------------------------------------------------------\n\n integer(i4), parameter :: npar = 4_i4 ! number of parameters\n integer(i4), parameter :: nsets = 1500_i4 ! number of parameter sets\n integer(i4), parameter :: nt = 10_i4 ! number of time points\n integer(i4), parameter :: nboot = 19_i4 ! number of new datasets generated with bootstrapping\n\n integer(i4) :: skip = 30000_i4 \n integer(i8) :: seed = 123_i8\n\n real(dp), dimension(nt) :: t ! i.e. time series\n\n real(dp), dimension(npar,2) :: range ! parameter range\n\n real(dp), dimension(nsets,2*npar) :: p ! sobol sequence\n real(dp), dimension(nsets,npar) :: pa ! parameter sample A\n real(dp), dimension(nsets,npar) :: pb ! parameter sample B\n real(dp), dimension(nsets,npar) :: pci ! parameter sample Ci\n\n real(dp), dimension(nsets,nt) :: ya ! model output A\n real(dp), dimension(nsets,nt) :: yb ! model output B\n real(dp), dimension(nsets,npar,nt) :: yci ! model output C(i), i=1,npar\n\n real(dp), dimension(nboot+1,npar,nt) :: si ! sobol index (main effect) \n ! per parameter and time point\n ! for each bootstrapping sample\n real(dp), dimension(nboot+1,npar,nt) :: sti ! sobol index (total effect)\n ! per parameter and time point\n ! for each bootstrapping sample\n integer(i4) :: i\n logical :: isgood = .true.\n\n!----------------------------------------------------------\n\n do i = 1, nt\n t(i) = real(i-1,dp)\n end do\n\n ! Generating parameter sets \n call sobol_array(2*npar,nsets,skip,p)\n range = par_range()\n pa = p(:,:npar)\n pb = p(:,npar+1:)\n do i = 1, npar\n pa(:,i) = pa(:,i)*(range(i,2)-range(i,1)) + range(i,1)\n pb(:,i) = pb(:,i)*(range(i,2)-range(i,1)) + range(i,1)\n end do\n\n ! Calculating the model output\n ya = model(pa,t)\n yb = model(pb,t)\n\n do i = 1, npar\n pci = pa\n pci(:,i) = pb(:,i) \n yci(:,i,:) = model(pci,t)\n end do\n\n ! Calculating the sobol index\n call sobol_index(ya, yb, yci, si(1,:,:), sti(1,:,:))\n\n ! Bootstrapping\n call bootstrap_si(ya, yb, yci, nboot, si(2:,:,:), sti(2:,:,:), seed = seed)\n\n\n if (abs(si(1,1,3) - 0.97236268) > 0.000001) isgood = .false.\n if (abs(si(1,2,3) - 0.01255484) > 0.000001) isgood = .false.\n if (abs(si(1,3,3) - 0.00000000) > 0.000001) isgood = .false.\n if (abs(si(1,4,3) - 0.00275693) > 0.000001) isgood = .false.\n if (abs(si(2,1,3) - 0.82035742) > 0.000001) isgood = .false.\n if (abs(si(2,2,3) - 0.00413255) > 0.000001) isgood = .false.\n if (abs(si(2,3,3) - 0.00000000) > 0.000001) isgood = .false.\n if (abs(si(2,4,3) - 0.01841593) > 0.000001) isgood = .false.\n if (abs(sti(1,1,3) - 0.97907962) > 0.000001) isgood = .false.\n if (abs(sti(1,2,3) - 0.01529379) > 0.000001) isgood = .false.\n if (abs(sti(1,3,3) - 0.00000000) > 0.000001) isgood = .false.\n if (abs(sti(1,4,3) - 0.00382390) > 0.000001) isgood = .false.\n if (abs(sti(2,1,3) - 1.01645796) > 0.000001) isgood = .false.\n if (abs(sti(2,2,3) - 0.01582186) > 0.000001) isgood = .false.\n if (abs(sti(2,3,3) - 0.00000000) > 0.000001) isgood = .false.\n if (abs(sti(2,4,3) - 0.00392133) > 0.000001) isgood = .false.\n\n if (isgood) then\n write(*,*) 'mo_bootstrapping_sensitivity_analysis ', color('o.k.', c_green)\n else\n write(*,*) 'mo_bootstrapping_sensitivity_analysis ', color('failed', c_red)\n end if\n\n!-----------------------------------------------------------\nEND PROGRAM mo_bootstrapping_test\n", "meta": {"hexsha": "85caaea9d7e76cdd15d673e80dfaa35d1072ebe7", "size": 4646, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/test_mo_bootstrapping_sensitivity_analysis/main.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_bootstrapping_sensitivity_analysis/main.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_bootstrapping_sensitivity_analysis/main.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": 45.5490196078, "max_line_length": 125, "alphanum_fraction": 0.4741713302, "num_tokens": 1403, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632976542184, "lm_q2_score": 0.7154239836484144, "lm_q1q2_score": 0.6634579446971113}} {"text": " include 'ttb/ttb_library.f'\n\n subroutine hypela2(d,g,e,de,s,t,dt,ngens,m,nn,kcus,matus,ndi,\n 2 nshear,disp,dispt,coord,ffn,frotn,strechn,eigvn,ffn1,\n 3 frotn1,strechn1,eigvn1,ncrd,itel,ndeg,ndm,\n 4 nnode,jtype,lclass,ifr,ifu)\n \n ! HYPELA2 St. Venant - Kirchhoff Material\n ! Formulation: Total Lagrange, Large Strain\n ! (Updated Lagrange with Push Forward\n ! and Jaumann Correction)\n !\n ! Andreas Dutzler, Graz University of Technology\n ! 2018-02-11\n\n use Tensor\n implicit none\n \n real*8 coord, d, de, disp, dispt, dt, e, eigvn, eigvn1, ffn, ffn1\n real*8 frotn, frotn1, g\n integer ifr, ifu, itel, jtype, kcus, lclass, matus, m, ncrd, ndeg\n integer ndi, ndm, ngens, nn, nnode, nshear\n real*8 s, strechn, strechn1, t\n\n dimension e(*),de(*),t(*),dt(*),g(*),d(ngens,*),s(*)\n dimension m(2),coord(ncrd,*),disp(ndeg,*),matus(2),\n * dispt(ndeg,*),ffn(itel,3),frotn(itel,3),\n * strechn(itel),eigvn(itel,*),ffn1(itel,3),\n * frotn1(itel,3),strechn1(itel),eigvn1(itel,*),\n * kcus(2),lclass(2)\n \n include 'concom'\n\n type(Tensor2) :: F1\n\n type(Tensor2s) :: E1,S1,Eye\n type(Tensor4s) :: C4\n \n real(kind=8) :: J,young,nu,lambda,mu\n \n ! material parameters\n young = 210000.0\n nu = 0.3\n \n ! lame parameter\n mu = young / ( 2.*(1.+nu) )\n lambda = nu*young / ((1.+nu)*(1.-2.*nu))\n \n ! large strain formulation\n Eye = Eye**0\n F1 = Eye\n F1%ab(1:itel,1:3) = ffn1(1:itel,1:3)\n E1 = 0.5*(transpose(F1)*F1-Eye)\n\n ! material elasticity tensor\n C4 = lambda*(Eye.dya.Eye) + 2.*mu*(Eye.cdya.Eye)\n \n ! pk2 stress\n S1 = lambda*tr(E1)*Eye + 2.*mu*E1\n \n if (iupdat.eq.1) then ! updated lagrange\n J = det(F1)\n ! cauchy stress\n S1 = piola(F1,S1)/J\n ! tangent matrix (jaumann)\n C4 = piola(F1,C4)/J\n * + (S1.cdya.Eye) + (Eye.cdya.S1)\n endif\n \n ! output as array\n s(1:ngens) = asarray( asvoigt(S1), ngens )\n d(1:ngens,1:ngens) = asarray( asvoigt(C4), ngens,ngens )\n \n return\n end", "meta": {"hexsha": "a2ec4725b234af7c04a88d5466d8a7ea4355aede", "size": 2305, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "docs/examples/hypela2_stvenantkirchhoff.f", "max_stars_repo_name": "pinkieli/Tensor-for-Fortran", "max_stars_repo_head_hexsha": "15372e07ad2031a83b8e3a4fe1c99bf538c4d20b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "docs/examples/hypela2_stvenantkirchhoff.f", "max_issues_repo_name": "pinkieli/Tensor-for-Fortran", "max_issues_repo_head_hexsha": "15372e07ad2031a83b8e3a4fe1c99bf538c4d20b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/examples/hypela2_stvenantkirchhoff.f", "max_forks_repo_name": "pinkieli/Tensor-for-Fortran", "max_forks_repo_head_hexsha": "15372e07ad2031a83b8e3a4fe1c99bf538c4d20b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-18T02:02:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-18T02:02:31.000Z", "avg_line_length": 30.7333333333, "max_line_length": 72, "alphanum_fraction": 0.5206073753, "num_tokens": 828, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.953275045356249, "lm_q2_score": 0.6959583124210896, "lm_q1q2_score": 0.6634396918392726}} {"text": "*> \\brief \\b SSXT1\n*\n* =========== DOCUMENTATION ===========\n*\n* Online html documentation available at\n* http://www.netlib.org/lapack/explore-html/\n*\n* Definition:\n* ===========\n*\n* REAL FUNCTION SSXT1( IJOB, D1, N1, D2, N2, ABSTOL,\n* ULP, UNFL )\n*\n* .. Scalar Arguments ..\n* INTEGER IJOB, N1, N2\n* REAL ABSTOL, ULP, UNFL\n* ..\n* .. Array Arguments ..\n* REAL D1( * ), D2( * )\n* ..\n*\n*\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*>\n*> SSXT1 computes the difference between a set of eigenvalues.\n*> The result is returned as the function value.\n*>\n*> IJOB = 1: Computes max { min | D1(i)-D2(j) | }\n*> i j\n*>\n*> IJOB = 2: Computes max { min | D1(i)-D2(j) | /\n*> i j\n*> ( ABSTOL + |D1(i)|*ULP ) }\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in] IJOB\n*> \\verbatim\n*> IJOB is INTEGER\n*> Specifies the type of tests to be performed. (See above.)\n*> \\endverbatim\n*>\n*> \\param[in] D1\n*> \\verbatim\n*> D1 is REAL array, dimension (N1)\n*> The first array. D1 should be in increasing order, i.e.,\n*> D1(j) <= D1(j+1).\n*> \\endverbatim\n*>\n*> \\param[in] N1\n*> \\verbatim\n*> N1 is INTEGER\n*> The length of D1.\n*> \\endverbatim\n*>\n*> \\param[in] D2\n*> \\verbatim\n*> D2 is REAL array, dimension (N2)\n*> The second array. D2 should be in increasing order, i.e.,\n*> D2(j) <= D2(j+1).\n*> \\endverbatim\n*>\n*> \\param[in] N2\n*> \\verbatim\n*> N2 is INTEGER\n*> The length of D2.\n*> \\endverbatim\n*>\n*> \\param[in] ABSTOL\n*> \\verbatim\n*> ABSTOL is REAL\n*> The absolute tolerance, used as a measure of the error.\n*> \\endverbatim\n*>\n*> \\param[in] ULP\n*> \\verbatim\n*> ULP is REAL\n*> Machine precision.\n*> \\endverbatim\n*>\n*> \\param[in] UNFL\n*> \\verbatim\n*> UNFL is REAL\n*> The smallest positive number whose reciprocal does not\n*> overflow.\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee\n*> \\author Univ. of California Berkeley\n*> \\author Univ. of Colorado Denver\n*> \\author NAG Ltd.\n*\n*> \\date December 2016\n*\n*> \\ingroup single_eig\n*\n* =====================================================================\n REAL FUNCTION SSXT1( IJOB, D1, N1, D2, N2, ABSTOL,\n $ ULP, UNFL )\n*\n* -- LAPACK test routine (version 3.7.0) --\n* -- LAPACK is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n* December 2016\n*\n* .. Scalar Arguments ..\n INTEGER IJOB, N1, N2\n REAL ABSTOL, ULP, UNFL\n* ..\n* .. Array Arguments ..\n REAL D1( * ), D2( * )\n* ..\n*\n* =====================================================================\n*\n* .. Parameters ..\n REAL ZERO\n PARAMETER ( ZERO = 0.0E0 )\n* ..\n* .. Local Scalars ..\n INTEGER I, J\n REAL TEMP1, TEMP2\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC ABS, MAX, MIN\n* ..\n* .. Executable Statements ..\n*\n TEMP1 = ZERO\n*\n J = 1\n DO 20 I = 1, N1\n 10 CONTINUE\n IF( D2( J ).LT.D1( I ) .AND. J.LT.N2 ) THEN\n J = J + 1\n GO TO 10\n END IF\n IF( J.EQ.1 ) THEN\n TEMP2 = ABS( D2( J )-D1( I ) )\n IF( IJOB.EQ.2 )\n $ TEMP2 = TEMP2 / MAX( UNFL, ABSTOL+ULP*ABS( D1( I ) ) )\n ELSE\n TEMP2 = MIN( ABS( D2( J )-D1( I ) ),\n $ ABS( D1( I )-D2( J-1 ) ) )\n IF( IJOB.EQ.2 )\n $ TEMP2 = TEMP2 / MAX( UNFL, ABSTOL+ULP*ABS( D1( I ) ) )\n END IF\n TEMP1 = MAX( TEMP1, TEMP2 )\n 20 CONTINUE\n*\n SSXT1 = TEMP1\n RETURN\n*\n* End of SSXT1\n*\n END\n", "meta": {"hexsha": "858ef8c6f28b42fb3a5be195a49a40087cdeb517", "size": 4039, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "lapack-netlib/TESTING/EIG/ssxt1.f", "max_stars_repo_name": "dnoan/OpenBLAS", "max_stars_repo_head_hexsha": "b54b50fe3a5ec921d18ddf5fbdb80092d1b23893", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 4392, "max_stars_repo_stars_event_min_datetime": "2015-01-02T18:15:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T12:14:38.000Z", "max_issues_repo_path": "lapack-netlib/TESTING/EIG/ssxt1.f", "max_issues_repo_name": "dnoan/OpenBLAS", "max_issues_repo_head_hexsha": "b54b50fe3a5ec921d18ddf5fbdb80092d1b23893", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2067, "max_issues_repo_issues_event_min_datetime": "2015-01-01T03:50:01.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T18:59:43.000Z", "max_forks_repo_path": "lapack-netlib/TESTING/EIG/ssxt1.f", "max_forks_repo_name": "dnoan/OpenBLAS", "max_forks_repo_head_hexsha": "b54b50fe3a5ec921d18ddf5fbdb80092d1b23893", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1564, "max_forks_repo_forks_event_min_datetime": "2015-01-01T01:32:27.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T07:12:54.000Z", "avg_line_length": 24.4787878788, "max_line_length": 76, "alphanum_fraction": 0.4468927952, "num_tokens": 1218, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314858927011, "lm_q2_score": 0.7490872243177518, "lm_q1q2_score": 0.6634152315357696}} {"text": "#include \"eiscor.h\"\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! d_orthfact_qr\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! This routine computes the real Schur factorization of a real \n! orthogonal upper-Hessenberg matrix that is stored as a product of \n! N-1 Givens rotations and a diagonal matrix.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! INPUT VARIABLES:\n!\n! VEC LOGICAL\n! .TRUE.: compute schurvectors\n! .FALSE.: no schurvectors\n!\n! ID LOGICAL\n! .TRUE.: initialize to Z to identity\n! .FALSE.: assume Z is already initialized\n!\n! N INTEGER\n! dimension of matrix\n!\n! Q REAL(8) array of dimension (2*(N-1))\n! array of generators for givens rotations\n!\n! D REAL(8) array of dimension (N)\n! array of generators for complex diagonal matrix\n!\n! M INTEGER\n! leading dimension of Z\n!\n! OUTPUT VARIABLES:\n!\n! Z REAL(8) array of dimension (M,N)\n! components of schurvectors\n! if VEC = .FALSE. unused\n! if VEC = .TRUE. and ID = .TRUE. initializes Z to I \n! if VEC = .TRUE. and ID = .FALSE. assumes Z initialized\n!\n! ITS INTEGER array of dimension (N-1)\n! Contains the number of iterations per deflation\n!\n! INFO INTEGER\n! INFO = 1 implies no convergence\n! INFO = 0 implies successful computation\n! INFO = -3 implies N is invalid\n! INFO = -4 implies Q is invalid\n! INFO = -5 implies D is invalid\n! INFO = -6 implies M is invalid\n! INFO = -7 implies Z is invalid\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine d_orthfact_qr(VEC,ID,N,Q,D,M,Z,ITS,INFO)\n \n implicit none\n \n ! input variables\n logical, intent(in) :: VEC, ID\n integer, intent(in) :: N, M\n integer, intent(inout) :: INFO, ITS(N-1)\n real(8), intent(inout) :: Q(2*(N-1)), D(N), Z(M,N)\n \n ! compute variables\n logical :: flg\n integer :: ii, kk\n integer :: STR, STP, ZERO, ITMAX, ITCNT\n real(8) :: block(2,2) \n\n ! initialize INFO\n INFO = 0\n \n ! check factorization\n call d_orthfact_factorcheck(N,Q,D,INFO)\n if (INFO.NE.0) then\n INFO = INFO - 2\n ! print error message in debug mode\n if (DEBUG) then\n call u_infocode_check(__FILE__,__LINE__,\"N, Q, or D is invalid\",INFO,INFO)\n end if\n return\n end if\n \n ! check M\n if (VEC.AND.(M < 1)) then\n INFO = -6\n ! print error message in debug mode\n if (DEBUG) then\n call u_infocode_check(__FILE__,__LINE__,\"M must be at least 1\",INFO,INFO)\n end if\n return\n end if\n \n ! check Z\n if (VEC.AND..NOT.ID) then\n call d_2Darray_check(M,N,Z,flg)\n if (.NOT.flg) then\n INFO = -7\n ! print error message in debug mode\n if (DEBUG) then\n call u_infocode_check(__FILE__,__LINE__,\"Z is invalid\",INFO,INFO)\n end if\n return\n end if\n end if \n \n ! initialize storage\n ITS = 0\n \n if (VEC.AND.ID) then\n Z = 0d0\n do ii=1,min(M,N)\n Z(ii,ii) = 1d0\n end do\n end if\n \n ! initialize indices\n STR = 1\n STP = N-1\n ZERO = 0\n ITMAX = 20*N\n ITCNT = 0\n\n ! loop for bulgechasing\n do kk=1,ITMAX\n\n ! check for completion\n if(STP <= 0)then\n exit\n end if\n\n ! check for deflation\n call d_orthfact_deflationcheck(STP-STR+2,Q((2*STR-1):(2*STP)),D(STR:(STP+1)),ZERO)\n\n ! if 1x1 block remove and check again \n if(STP == (STR+ZERO-1))then\n \n ! update indices\n ITS(STR+STP-1) = ITCNT\n ITCNT = 0\n STP = STP - 1\n ZERO = 0\n STR = 1\n \n ! if 2x2 block remove and check again\n else if(STP == (STR+ZERO))then\n \n ! call 2x2 deflation\n call d_orthfact_2x2deflation(VEC,Q((2*STP-1):(2*STP)),D(STP:(STP+1)),M,Z(:,STP:(STP+1)))\n \n ! update indices\n ITS(STR+STP-1) = ITCNT\n ITCNT = 0\n STP = STP - 2\n ZERO = 0\n STR = 1\n \n ! if greater than 2x2 chase a bulge\n else\n\n ! check STR\n if (ZERO.GT.0) then\n STR = STR+ZERO\n end if\n\n ! perform singleshift iteration\n call d_orthfact_doublestep(VEC,STP-STR+2,Q((2*STR-1):(2*STP)),D(STR:(STP+1)) &\n ,M,Z(:,STR:(STP+1)),ITCNT)\n \n ! update indices\n ITCNT = ITCNT + 1\n \n end if\n \n ! if ITMAX hit\n if (kk == ITMAX) then\n INFO = 1\n ITS(STR+STP-1) = ITCNT\n end if\n \n end do \n \nend subroutine d_orthfact_qr\n", "meta": {"hexsha": "76bff694039942f01510e729d2c1cfd80c1d8804", "size": 4762, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/AMVW/src/double/d_orthfact_qr.f90", "max_stars_repo_name": "trcameron/FPML", "max_stars_repo_head_hexsha": "f6aacfcd702f7ce74a45ffaf281e9586dceb1b7e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tests/AMVW/src/double/d_orthfact_qr.f90", "max_issues_repo_name": "trcameron/FPML", "max_issues_repo_head_hexsha": "f6aacfcd702f7ce74a45ffaf281e9586dceb1b7e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/AMVW/src/double/d_orthfact_qr.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": 25.4652406417, "max_line_length": 94, "alphanum_fraction": 0.5081898362, "num_tokens": 1436, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554444, "lm_q2_score": 0.7490872131147276, "lm_q1q2_score": 0.6634152170915869}} {"text": "module utils\n implicit none\n\n integer, parameter, public :: dp = kind(0.d0)\n real(dp), parameter, public :: pi = 4.0_dp * datan(1.0_dp)\n\ncontains\n\npure function r_to_inds(r, l, m) result(inds)\n real(kind(0.d0)), intent(in) :: r(:, :), l\n integer, intent(in) :: m\n integer :: inds(size(r, 1), size(r, 2))\n\n inds = 1 + int((r + l / 2.0_dp) / (l / m))\nend function\n\npure function r_wrap(r, l, l_half)\n real(kind(0.d0)), intent(in) :: r, l, l_half\n real(kind(0.d0)) :: r_wrap\n\n if (r > l_half) then \n r_wrap = r - l\n else if (r < -l_half) then\n r_wrap = r + l\n else\n r_wrap = r\n end if\nend function\n\npure function i_wrap(i, m)\n integer, intent(in) :: i, m\n integer :: i_wrap\n\n if (i > m) then\n i_wrap = i - m\n else if (i < 1) then\n i_wrap = i + m\n else\n i_wrap = i\n end if\nend function\n\npure function r_sep_sq(r_1, r_2, l, l_half)\n real(kind(0.d0)), intent(in) :: r_1(:), r_2(size(r_1)), l, l_half\n real(kind(0.d0)) :: r_sep_sq, r_diff\n integer :: i\n\n r_sep_sq = 0.0d0\n do i = 1, size(r_1, 1)\n r_diff = dabs(r_1(i) - r_2(i))\n if (r_diff > l_half) r_diff = l - r_diff\n r_sep_sq = r_sep_sq + r_diff ** 2\n end do\nend function\n\npure function rot_2d(a, theta) result(a_rot)\n real(kind(0.d0)), intent(in) :: a(2), theta\n real(kind(0.d0)) :: a_rot(2), s, c\n\n s = sin(theta)\n c = cos(theta)\n a_rot(1) = c * a(1) - s * a(2)\n a_rot(2) = s * a(1) + c * a(2)\nend function\n\nsubroutine add_noise_2d(v, eta)\n real(kind(0.d0)), intent(inout) :: v(:, :)\n real(kind(0.d0)), intent(in) :: eta\n real(kind(0.d0)) :: theta(size(v, 2))\n integer :: i\n\n call random_number(theta)\n theta = (theta - 0.5_dp) * eta\n do i = 1, size(v, 2)\n v(:, i) = rot_2d(v(:, i), theta(i))\n end do\nend subroutine\n\nsubroutine clusters(r_raw, r_cut_raw, l, list)\n real(kind(0.d0)), intent(in) :: r_raw(:, :), r_cut_raw, l\n integer, intent(out) :: list(size(r_raw, 2))\n real(kind(0.d0)) :: r(size(r_raw, 1), size(r_raw, 2)), r_cut_sq, r_j(size(r_raw, 1)), r_j_k(size(r_raw, 1))\n integer :: n, d, i, j, k, list_k\n\n d = size(r, 1)\n n = size(r, 2)\n\n ! scale distances to internal units\n r = r_raw / l\n r_cut_sq = (r_cut_raw / l) ** 2\n\n do i = 1, n\n list(i) = i\n end do\n\n do i = 1, n - 1\n if (i == list(i)) then\n j = i\n r_j = r(:, j)\n do k = i + 1, n\n list_k = list(k)\n if (list_k == k) then\n r_j_k = r_j - r(:, k)\n r_j_k = r_j_k - anint(r_j_k)\n if (sum(r_j_k ** 2) < r_cut_sq) then\n list(k) = list(j)\n list(j) = list_k\n end if\n end if\n end do\n\n j = list(j)\n r_j = r(:, j)\n\n do while (j /= i)\n do k = i + 1, n\n list_k = list(k)\n if (list_k == k) then\n r_j_k = r_j - r(:, k)\n r_j_k = r_j_k - anint(r_j_k)\n if (sum(r_j_k ** 2) < r_cut_sq) then\n list(k) = list(j)\n list(j) = list_k\n end if\n end if\n end do\n j = list(j)\n r_j = r(:, j)\n end do\n end if\n end do\nend subroutine clusters\n\nend module\n", "meta": {"hexsha": "cc16ae26c5b9234dd3356caaa704e2f6e1568d0b", "size": 3501, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "cellulist/numerics/utils.f90", "max_stars_repo_name": "eddiejessup/cellulist", "max_stars_repo_head_hexsha": "44a790829274be3b8ce78abc6b4969e593d29f71", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-11-28T01:20:24.000Z", "max_stars_repo_stars_event_max_datetime": "2016-11-28T01:20:24.000Z", "max_issues_repo_path": "cellulist/numerics/utils.f90", "max_issues_repo_name": "eddiejessup/cellulist", "max_issues_repo_head_hexsha": "44a790829274be3b8ce78abc6b4969e593d29f71", "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": "cellulist/numerics/utils.f90", "max_forks_repo_name": "eddiejessup/cellulist", "max_forks_repo_head_hexsha": "44a790829274be3b8ce78abc6b4969e593d29f71", "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.9333333333, "max_line_length": 111, "alphanum_fraction": 0.4627249357, "num_tokens": 1160, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314617436727, "lm_q2_score": 0.7490872243177518, "lm_q1q2_score": 0.6634152134460409}} {"text": " Program dggev3_example\n\n! DGGEV3 Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_example_aux, Only: nagf_sort_cmplxvec_rank_rearrange, &\n nagf_sort_realmat_rank_rows, nagf_file_print_matrix_complex_gen, &\n nagf_file_print_matrix_real_gen\n Use lapack_interfaces, Only: dggev3\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Real (Kind=dp), Parameter :: zero = 0.0_dp\n Integer, Parameter :: nin = 5, nout = 6\n! .. Local Scalars ..\n Complex (Kind=dp) :: scal\n Integer :: i, ifail, info, j, k, lda, ldb, ldvr, lwork, n\n! .. Local Arrays ..\n Complex (Kind=dp), Allocatable :: eigval(:), eigvec(:, :)\n Real (Kind=dp), Allocatable :: a(:, :), alphai(:), alphar(:), b(:, :), &\n beta(:), vr(:, :), work(:)\n Real (Kind=dp) :: dummy(1, 1)\n Integer, Allocatable :: irank(:)\n! .. Intrinsic Procedures ..\n Intrinsic :: abs, all, cmplx, conjg, epsilon, maxloc, nint\n! .. Executable Statements ..\n Write (nout, *) 'DGGEV3 Example Program Results'\n Flush (nout)\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n\n lda = n\n ldb = n\n ldvr = n\n Allocate (a(lda,n), alphai(n), alphar(n), b(ldb,n), beta(n), vr(ldvr,n), &\n eigvec(n,n), eigval(n), irank(n))\n\n! Use routine workspace query to get optimal workspace.\n lwork = -1\n Call dggev3('No left vectors', 'Vectors (right)', n, a, lda, b, ldb, &\n alphar, alphai, beta, dummy, 1, vr, ldvr, dummy, lwork, info)\n\n lwork = nint(dummy(1,1))\n Allocate (work(lwork))\n\n! Read in the matrices A and B\n\n Read (nin, *)(a(i,1:n), i=1, n)\n Read (nin, *)(b(i,1:n), i=1, n)\n\n! Solve the generalized eigenvalue problem\n\n Call dggev3('No left vectors', 'Vectors (right)', n, a, lda, b, ldb, &\n alphar, alphai, beta, dummy, 1, vr, ldvr, work, lwork, info)\n If (info>0) Then\n Write (nout, *)\n Write (nout, 110) 'Failure in DGGEV3. INFO =', info\n Go To 100\n End If\n\n! Re-normalize the eigenvectors, largest absolute element real\n j = 0\n Do i = 1, n\n If (alphai(i)==zero) Then\n eigvec(1:n, i) = cmplx(vr(1:n,i), zero, kind=dp)\n Else If (j==0) Then\n eigvec(1:n, i) = cmplx(vr(1:n,i), vr(1:n,i+1), kind=dp)\n j = 1\n Else\n eigvec(1:n, i) = cmplx(vr(1:n,i-1), -vr(1:n,i), kind=dp)\n j = 0\n End If\n work(1:n) = abs(eigvec(1:n,i))\n k = maxloc(work(1:n), 1)\n scal = conjg(eigvec(k,i))/abs(eigvec(k,i))\n eigvec(1:n, i) = eigvec(1:n, i)*scal\n End Do\n\n! If eigenvalues are finite, order by descending absolute values\n If (all(abs(beta(1:n))>epsilon(1.0E0_dp))) Then\n! add small amount to alphai to distinguish conjugates\n alphai(1:n) = alphai(1:n) + epsilon(1.0E0_dp)*10.0_dp\n eigval(1:n) = cmplx(alphar(1:n), alphai(1:n), kind=dp)\n eigval(1:n) = eigval(1:n)/beta(1:n)\n work(1:n) = abs(eigval(1:n))\n ifail = 0\n Call nagf_sort_realmat_rank_rows(work, n, 1, n, 1, 1, 'Descending', &\n irank, ifail)\n Call nagf_sort_cmplxvec_rank_rearrange(eigval, 1, n, irank, ifail)\n\n! Print ordered eigenvalues\n ifail = 0\n Call nagf_file_print_matrix_complex_gen('Gen', ' ', 1, n, eigval, 1, &\n 'Eigenvalues:', ifail)\n\n! Order the eigenvectors in the same way and print\n Do j = 1, n\n eigval(1:n) = eigvec(j, 1:n)\n Call nagf_sort_cmplxvec_rank_rearrange(eigval, 1, n, irank, ifail)\n eigvec(j, 1:n) = eigval(1:n)\n End Do\n\n Write (nout, *)\n Flush (nout)\n ifail = 0\n Call nagf_file_print_matrix_complex_gen('Gen', ' ', n, n, eigvec, n, &\n 'Right Eigenvectors (columns):', ifail)\n Else\n Write (nout, *) 'Some of the eigenvalues are infinite'\n Write (nout, *)\n Flush (nout)\n ifail = 0\n Call nagf_file_print_matrix_real_gen('Gen', ' ', 1, n, alphar, 1, &\n 'Alpha (real):', ifail)\n Call nagf_file_print_matrix_real_gen('Gen', ' ', 1, n, alphai, 1, &\n 'Alpha (imag):', ifail)\n Call nagf_file_print_matrix_real_gen('Gen', ' ', 1, n, beta, 1, &\n 'Beta:', ifail)\n End If\n100 Continue\n\n110 Format (1X, A, I4)\n End Program\n", "meta": {"hexsha": "ffeae56944efdccaece2c390263729e7cfcc61b9", "size": 4599, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/dggev3_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/dggev3_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/dggev3_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 35.6511627907, "max_line_length": 90, "alphanum_fraction": 0.5638182214, "num_tokens": 1506, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513703624557, "lm_q2_score": 0.7401743505760728, "lm_q1q2_score": 0.663382276010946}} {"text": " REAL FUNCTION LINT2 (TABNAM,TABLE,ILTAB,X)\r\n IMPLICIT NONE\r\n \r\n* FORMAL_PARAMETERS:\r\n CHARACTER*(*) TABNAM\r\n INTEGER ILTAB\r\n REAL TABLE(ILTAB), X\r\n \r\n** local variables\r\n INTEGER I1, IUP, IL, UNLOG\r\n REAL SLOPE, TINY\r\n PARAMETER (TINY=1.E-7)\r\n LOGICAL ERR, TOSCR, TOLOG\r\n SAVE\r\n \r\n* initialize\r\n ERR = .FALSE.\r\n \r\n* desired output type for messages\r\n CALL MESSINQ (TOSCR, TOLOG, UNLOG)\r\n\r\n* check on value of ILTAB\r\n IF (MOD(ILTAB,2).NE.0 .OR. ILTAB.LE.2) THEN\r\n IL = MAX (1, LEN_TRIM (TABNAM))\r\n IF (TOSCR) WRITE (*,'(2A,/,A)')\r\n & ' Number of elements in interpolation table: ',TABNAM(1:IL),\r\n & ' not correct !'\r\n IF (TOLOG) WRITE (UNLOG,'(2A,/,A)')\r\n & ' Number of elements in interpolation table: ',TABNAM(1:IL),\r\n & ' not correct !'\r\n ERR = .TRUE.\r\n \r\n ELSE\r\n IUP = 0\r\n DO 10 I1=3,ILTAB,2\r\n* check on ascending order of X-values in function\r\n IF (TABLE(I1).LE.TABLE(I1-2)) THEN\r\n IL = MAX (1, LEN_TRIM (TABNAM))\r\n IF (TOSCR) WRITE (*,'(2A,/,A,I4)')\r\n & ' X-coordinates in interpolation table: ',TABNAM(1:IL),\r\n & ' not in ascending order at point',I1\r\n IF (TOLOG) WRITE (UNLOG,'(2A,/,A,I4)')\r\n & ' X-coordinates in interpolation table: ',TABNAM(1:IL),\r\n & ' not in ascending order at point',I1\r\n ERR = .TRUE.\r\n END IF\r\n IF (IUP.EQ.0 .AND. TABLE(I1).GE.X) IUP = I1\r\n10 CONTINUE\r\n END IF\r\n \r\n IF (.NOT.ERR .AND. X.LT.TABLE(1)) THEN\r\n IUP = 3\r\n IF ((TABLE(1)-X) .GT. ABS(X)*TINY) THEN\r\n IL = MAX (1, LEN_TRIM (TABNAM))\r\n IF (TOSCR) WRITE (*,'(A,G13.5,/,2A)')\r\n & ' WARNING in LINT2: X-value below defined region at X=',X,\r\n & ' in interpolation table: ',TABNAM(1:IL)\r\n IF (TOLOG) WRITE (UNLOG,'(A,G13.5,/,2A)')\r\n & ' WARNING in LINT2: X-value below defined region at X=',X,\r\n & ' in interpolation table: ',TABNAM(1:IL)\r\n END IF\r\n ELSE IF (.NOT.ERR .AND. X.GT.TABLE(ILTAB-1)) THEN\r\n IUP = ILTAB-1\r\n IF ((X-TABLE(ILTAB-1)) .GT. ABS(X)*TINY) THEN\r\n IL = MAX (1, LEN_TRIM (TABNAM))\r\n IF (TOSCR) WRITE (*,'(A,G13.5,/,2A)')\r\n & ' WARNING in LINT2: X-value above defined region at X=',X,\r\n & ' in interpolation table: ',TABNAM(1:IL)\r\n IF (TOLOG) WRITE (UNLOG,'(A,G13.5,/,2A)')\r\n & ' WARNING in LINT2: X-value above defined region at X=',X,\r\n & ' in interpolation table: ',TABNAM(1:IL)\r\n END IF\r\n END IF\r\n \r\n IF (ERR) CALL FATALERR ('LINT2',' ')\r\n \r\n* interpolation and extrapolation\r\n SLOPE = (TABLE(IUP+1)-TABLE(IUP-1))/(TABLE(IUP)-TABLE(IUP-2))\r\n LINT2 = TABLE(IUP-1)+(X-TABLE(IUP-2))*SLOPE\r\n \r\n RETURN\r\n END\r\n", "meta": {"hexsha": "8599e1184d460d11a3791248c4a2f6dc5df23872", "size": 2975, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "tests/data/program_analysis/DSSAT/CSM/LINT2.for", "max_stars_repo_name": "mikiec84/delphi", "max_stars_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2018-03-03T11:57:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-16T21:19:54.000Z", "max_issues_repo_path": "tests/data/program_analysis/DSSAT/CSM/LINT2.for", "max_issues_repo_name": "mikiec84/delphi", "max_issues_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 385, "max_issues_repo_issues_event_min_datetime": "2018-02-21T16:52:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-17T07:44:56.000Z", "max_forks_repo_path": "tests/data/program_analysis/DSSAT/CSM/LINT2.for", "max_forks_repo_name": "mikiec84/delphi", "max_forks_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2018-03-20T01:08:11.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-29T01:04:49.000Z", "avg_line_length": 35.843373494, "max_line_length": 72, "alphanum_fraction": 0.5011764706, "num_tokens": 968, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513675912913, "lm_q2_score": 0.7401743505760728, "lm_q1q2_score": 0.6633822739598012}} {"text": "!*******************************************************************\n! *\n SUBROUTINE SIXJ3(J, K, L, M, N, ITIK, SI)\n! *\n! THIS PACKAGE DETERMINES THE VALUES OF 6j COEFFICIENT *\n! *\n! | J/2 K/2 L/2 | *\n! | M/2 N/2 2 | [B.M.X. 75] *\n! *\n! Written by G. Gaigalas, *\n! Vanderbilt University, Nashville October 1996 *\n! Transform to fortran 90/95 by G. Gaigalas December 2012 *\n! The last modification made by G. Gaigalas October 2017 *\n! *\n!*******************************************************************\n!\n!-----------------------------------------------\n! M o d u l e s\n!-----------------------------------------------\n USE vast_kind_param, ONLY: DOUBLE\n USE CONS_C, ONLY: ZERO, ONE, TWO, THREE, FOUR, SEVEN\n!-----------------------------------------------\n! I n t e r f a c e B l o c k s\n!-----------------------------------------------\n USE ixjtik_I\n IMPLICIT NONE\n!-----------------------------------------------\n! D u m m y A r g u m e n t s\n!-----------------------------------------------\n INTEGER :: J, K, L, M, N\n INTEGER, INTENT(IN) :: ITIK\n REAL(DOUBLE), INTENT(OUT) :: SI\n!-----------------------------------------------\n! L o c a l V a r i a b l e s\n!-----------------------------------------------\n INTEGER :: I1\n REAL(DOUBLE) :: AS, A, B, C, AKA\n!-----------------------------------------------\n SI = ZERO\n IF (ITIK /= 0) THEN\n!\n! CHESKED TRIANGULAR CONDITIONS\n!\n IF (IXJTIK(J,K,L,M,N,6) == 0) RETURN\n ENDIF\n I1 = (J + K + L)/2\n AS = DBLE(I1)\n A = DBLE(L)\n B = DBLE(J)\n C = DBLE(K)\n AKA = ONE\n IF (MOD(I1,2) /= 0) AKA = -AKA\n IF (J - N == 6) THEN\n! -3\n IF (K - M == 6) THEN\n! -3 -3\n SI = AKA*DSQRT((AS + ONE)*AS*(AS - ONE)*(AS - TWO)*(AS - THREE)*(AS&\n - FOUR)/((B + ONE)*B*(B - ONE)*(B - TWO)*(B - THREE)*(B - FOUR)&\n *(B - THREE - TWO)))\n SI = SI*DSQRT((AS - A - THREE - TWO)*(AS - A - FOUR)*(AS - A - &\n THREE)*(AS - A - TWO)*(AS - A - ONE)*(AS - A)/((C + ONE)*C*(C - &\n ONE)*(C - TWO)*(C - THREE)*(C - FOUR)*(C - THREE - TWO)))\n ELSE IF (M - K == 6) THEN\n! 3 -3\n SI = AKA*DSQRT((AS - C)*(AS - C - ONE)*(AS - C - TWO)*(AS - C - &\n THREE)*(AS - C - FOUR)*(AS - C - THREE - TWO)/((B + ONE)*B*(B - &\n ONE)*(B - TWO)*(B - THREE)*(B - FOUR)*(B - THREE - TWO)))\n SI = SI*DSQRT((AS - B + THREE + THREE)*(AS - B + THREE + TWO)*(AS&\n - B + FOUR)*(AS - B + THREE)*(AS - B + TWO)*(AS - B + ONE)/((C&\n + FOUR + THREE)*(C + THREE + THREE)*(C + THREE + TWO)*(C + FOUR&\n )*(C + THREE)*(C + TWO)*(C + ONE)))\n ELSE IF (K - M == 4) THEN\n! -2 -3\n SI = AKA*DSQRT(TWO*THREE*(AS - C)*(AS - B + ONE)*(AS - THREE)*(AS&\n - TWO)*(AS - ONE)*AS*(AS + ONE)/((B - THREE - TWO)*(B - FOUR)*(&\n B - THREE)*(B - TWO)*(B - ONE)*B*(B + ONE)))\n SI = SI*DSQRT((AS - A - FOUR)*(AS - A - THREE)*(AS - A - TWO)*(AS&\n - A - ONE)*(AS - A)/((C - FOUR)*(C - THREE)*(C - TWO)*(C - ONE)&\n *C*(C + ONE)*(C + TWO)))\n ELSE IF (M - K == 4) THEN\n! 2 -3\n SI = AKA*DSQRT(TWO*THREE*(AS + ONE)*(AS - A)*(AS - C - FOUR)*(AS - &\n C - THREE)*(AS - C - TWO)*(AS - C - ONE)*(AS - C)/((C + THREE + &\n THREE)*(C + THREE + TWO)*(C + FOUR)*(C + THREE)*(C + TWO)*(C + &\n ONE)*C))\n SI = SI*DSQRT((AS - B + THREE + TWO)*(AS - B + FOUR)*(AS - B + &\n THREE)*(AS - B + TWO)*(AS - B + ONE)/((B - THREE - TWO)*(B - &\n FOUR)*(B - THREE)*(B - TWO)*(B - ONE)*B*(B + ONE)))\n ELSE IF (K - M == 2) THEN\n! -1 -3\n SI = AKA*DSQRT(THREE*(THREE + TWO)*(AS - C)*(AS - C - ONE)*(AS - B&\n + TWO)*(AS - B + ONE)*(AS - TWO)*(AS - ONE)*AS*(AS + ONE)/((B&\n - THREE - TWO)*(B - FOUR)*(B - THREE)*(B - TWO)*(B - ONE)*B*(B&\n + ONE)))\n SI = SI*DSQRT((AS - A - THREE)*(AS - A - TWO)*(AS - A - ONE)*(AS - &\n A)/((C - THREE)*(C - TWO)*(C - ONE)*C*(C + ONE)*(C + TWO)*(C + &\n THREE)))\n ELSE IF (M - K == 2) THEN\n! 1 -3\n SI = AKA*DSQRT(THREE*(THREE + TWO)*(AS + ONE)*AS*(AS - A - ONE)*(AS&\n - A)*(AS - C - THREE)*(AS - C - TWO)*(AS - C - ONE)*(AS - C)/((&\n B - THREE - TWO)*(B - FOUR)*(B - THREE)*(B - TWO)*(B - ONE)*B*(B&\n + ONE)))\n SI = SI*DSQRT((AS - B + FOUR)*(AS - B + THREE)*(AS - B + TWO)*(AS&\n - B + ONE)/((C + THREE + TWO)*(C + FOUR)*(C + THREE)*(C + TWO)*&\n (C + ONE)*C*(C - ONE)))\n ELSE IF (M - K == 0) THEN\n! 0 -3\n SI = AKA*TWO*DSQRT((THREE + TWO)*(AS + ONE)*AS*(AS - ONE)*(AS - A&\n - TWO)*(AS - A - ONE)*(AS - A)/((B - THREE - TWO)*(B - FOUR)*(B&\n - THREE)*(B - TWO)*(B - ONE)*B*(B + ONE)))\n SI = SI*DSQRT((AS - C - TWO)*(AS - C - ONE)*(AS - C)*(AS - B + &\n THREE)*(AS - B + TWO)*(AS - B + ONE)/((C + FOUR)*(C + THREE)*(C&\n + TWO)*(C + ONE)*C*(C - ONE)*(C - TWO)))\n ENDIF\n ELSE IF (N - J == 6) THEN\n! 3\n IF (K - M == 6) THEN\n! -3 3\n SI = AKA*DSQRT((AS - B)*(AS - B - ONE)*(AS - B - TWO)*(AS - B - &\n THREE)*(AS - B - FOUR)*(AS - B - THREE - TWO)/((C + ONE)*C*(C - &\n ONE)*(C - TWO)*(C - THREE)*(C - FOUR)*(C - THREE - TWO)))\n SI = SI*DSQRT((AS - C + THREE + THREE)*(AS - C + THREE + TWO)*(AS&\n - C + FOUR)*(AS - C + THREE)*(AS - C + TWO)*(AS - C + ONE)/((B&\n + FOUR + THREE)*(B + THREE + THREE)*(B + THREE + TWO)*(B + FOUR&\n )*(B + THREE)*(B + TWO)*(B + ONE)))\n ELSE IF (M - K == 6) THEN\n! 3 3\n SI = AKA*DSQRT((AS - A + THREE + THREE)*(AS - A + THREE + TWO)*(AS&\n - A + FOUR)*(AS - A + THREE)*(AS - A + TWO)*(AS - A + ONE)/((B&\n + SEVEN)*(B + THREE + THREE)*(B + THREE + TWO)*(B + FOUR)*(B + &\n THREE)*(B + TWO)*(B + ONE)))\n SI = SI*DSQRT((AS + SEVEN)*(AS + THREE + THREE)*(AS + THREE + TWO)*&\n (AS + FOUR)*(AS + THREE)*(AS + TWO)/((C + SEVEN)*(C + THREE + &\n THREE)*(C + THREE + TWO)*(C + FOUR)*(C + THREE)*(C + TWO)*(C + &\n ONE)))\n ELSE IF (K - M == 4) THEN\n! -2 3\n SI = -AKA*DSQRT(TWO*THREE*(AS - A + ONE)*(AS + TWO)*(AS - B - FOUR)&\n *(AS - B - THREE)*(AS - B - TWO)*(AS - B - ONE)*(AS - B)/((B + &\n SEVEN)*(B + THREE + THREE)*(B + THREE + TWO)*(B + FOUR)*(B + &\n THREE)*(B + TWO)*(B + ONE)))\n SI = SI*DSQRT((AS - C + THREE + TWO)*(AS - C + FOUR)*(AS - C + &\n THREE)*(AS - C + TWO)*(AS - C + ONE)/((C - FOUR)*(C - THREE)*(C&\n - TWO)*(C - ONE)*C*(C + ONE)*(C + TWO)))\n ELSE IF (M - K == 4) THEN\n! 2 3\n SI = -AKA*DSQRT(TWO*THREE*(AS - B)*(AS - C + ONE)*(AS - A + THREE&\n + TWO)*(AS - A + FOUR)*(AS - A + THREE)*(AS - A + TWO)*(AS - A&\n + ONE)/((B + SEVEN)*(B + THREE + THREE)*(B + THREE + TWO)*(B + &\n FOUR)*(B + THREE)*(B + TWO)*(B + ONE)))\n SI = SI*DSQRT((AS + THREE + THREE)*(AS + THREE + TWO)*(AS + FOUR)*(&\n AS + THREE)*(AS + TWO)/((C + THREE + THREE)*(C + THREE + TWO)*(C&\n + FOUR)*(C + THREE)*(C + TWO)*(C + ONE)*C))\n ELSE IF (K - M == 2) THEN\n! -1 3\n SI = AKA*DSQRT(THREE*(THREE + TWO)*(AS - A + ONE)*(AS - A + TWO)*(&\n AS + THREE)*(AS + TWO)*(AS - B - THREE)*(AS - B - TWO)*(AS - B&\n - ONE)*(AS - B)/((B + SEVEN)*(B + THREE + THREE)*(B + THREE + &\n TWO)*(B + FOUR)*(B + THREE)*(B + TWO)*(B + ONE)))\n SI = SI*DSQRT((AS - C + FOUR)*(AS - C + THREE)*(AS - C + TWO)*(AS&\n - C + ONE)/((C - THREE)*(C - TWO)*(C - ONE)*C*(C + ONE)*(C + &\n TWO)*(C + THREE)))\n ELSE IF (M - K == 2) THEN\n! 1 3\n SI = AKA*DSQRT(THREE*(THREE + TWO)*(AS - B)*(AS - B - ONE)*(AS - C&\n + TWO)*(AS - C + ONE)*(AS - A + FOUR)*(AS - A + THREE)*(AS - A&\n + TWO)*(AS - A + ONE)/((B + SEVEN)*(B + THREE + THREE)*(B + &\n THREE + TWO)*(B + FOUR)*(B + THREE)*(B + TWO)*(B + ONE)))\n SI = SI*DSQRT((AS + THREE + TWO)*(AS + FOUR)*(AS + THREE)*(AS + TWO&\n )/((C + THREE + TWO)*(C + FOUR)*(C + THREE)*(C + TWO)*(C + ONE)*&\n C*(C - ONE)))\n ELSE IF (M - K == 0) THEN\n! 0 3\n SI = -AKA*TWO*DSQRT((THREE + TWO)*(AS - B)*(AS - B - ONE)*(AS - B&\n - TWO)*(AS - C + THREE)*(AS - C + TWO)*(AS - C + ONE)/((B + &\n SEVEN)*(B + THREE + THREE)*(B + THREE + TWO)*(B + FOUR)*(B + &\n THREE)*(B + TWO)*(B + ONE)))\n SI = SI*DSQRT((AS - A + THREE)*(AS - A + TWO)*(AS - A + ONE)*(AS + &\n FOUR)*(AS + THREE)*(AS + TWO)/((C + FOUR)*(C + THREE)*(C + TWO)*&\n (C + ONE)*C*(C - ONE)*(C - TWO)))\n ENDIF\n ELSE IF (J - N == 4) THEN\n! -2\n IF (K - M == 6) THEN\n! -3 -2\n SI = AKA*DSQRT(TWO*THREE*(AS - B)*(AS - C + ONE)*(AS - THREE)*(AS&\n - TWO)*(AS - ONE)*AS*(AS + ONE)/((C - THREE - TWO)*(C - FOUR)*(&\n C - THREE)*(C - TWO)*(C - ONE)*C*(C + ONE)))\n SI = SI*DSQRT((AS - A - FOUR)*(AS - A - THREE)*(AS - A - TWO)*(AS&\n - A - ONE)*(AS - A)/((B - FOUR)*(B - THREE)*(B - TWO)*(B - ONE)&\n *B*(B + ONE)*(B + TWO)))\n ELSE IF (M - K == 6) THEN\n! 3 -2\n SI = -AKA*DSQRT(TWO*THREE*(AS - A + ONE)*(AS + TWO)*(AS - C - FOUR)&\n *(AS - C - THREE)*(AS - C - TWO)*(AS - C - ONE)*(AS - C)/((C + &\n SEVEN)*(C + THREE + THREE)*(C + THREE + TWO)*(C + FOUR)*(C + &\n THREE)*(C + TWO)*(C + ONE)))\n SI = SI*DSQRT((AS - B + THREE + TWO)*(AS - B + FOUR)*(AS - B + &\n THREE)*(AS - B + TWO)*(AS - B + ONE)/((B - FOUR)*(B - THREE)*(B&\n - TWO)*(B - ONE)*B*(B + ONE)*(B + TWO)))\n ELSE IF (K - M == 4) THEN\n! -2 -2\n SI = AKA*((TWO + THREE)*(AS - C)*(AS - B) - (AS + TWO)*(AS - A - &\n FOUR))*DSQRT((AS - TWO)*(AS - ONE)*AS*(AS + ONE)/((B - FOUR)*(B&\n - THREE)*(B - TWO)*(B - ONE)*B*(B + ONE)*(B + TWO)))\n SI = SI*DSQRT((AS - A - THREE)*(AS - A - TWO)*(AS - A - ONE)*(AS - &\n A)/((C - FOUR)*(C - THREE)*(C - TWO)*(C - ONE)*C*(C + ONE)*(C + &\n TWO)))\n ELSE IF (M - K == 4) THEN\n! 2 -2\n SI = -AKA*((TWO + THREE)*(AS + ONE)*(AS - A + ONE) - (AS - C + ONE)&\n *(AS - B + THREE + TWO))*DSQRT((AS - C - THREE)*(AS - C - TWO)*(&\n AS - C - ONE)*(AS - C)/((B - FOUR)*(B - THREE)*(B - TWO)*(B - &\n ONE)*B*(B + ONE)*(B + TWO)))\n SI = SI*DSQRT((AS - B + FOUR)*(AS - B + THREE)*(AS - B + TWO)*(AS&\n - B + ONE)/((C + THREE + THREE)*(C + THREE + TWO)*(C + FOUR)*(C&\n + THREE)*(C + TWO)*(C + ONE)*C))\n ELSE IF (K - M == 2) THEN\n! -1 -2\n SI = AKA*(TWO*(AS - C - ONE)*(AS - B) - (AS + TWO)*(AS - A - THREE)&\n )*DSQRT(TWO*(THREE + TWO)*(AS - C)*(AS - B + ONE)*(AS - ONE)*AS*&\n (AS + ONE)/((B - FOUR)*(B - THREE)*(B - TWO)*(B - ONE)*B*(B + &\n ONE)*(B + TWO)))\n SI = SI*DSQRT((AS - A - TWO)*(AS - A - ONE)*(AS - A)/((C - THREE)*(&\n C - TWO)*(C - ONE)*C*(C + ONE)*(C + TWO)*(C + THREE)))\n ELSE IF (M - K == 2) THEN\n! 1 -2\n SI = -AKA*(TWO*AS*(AS - A + ONE) - (AS - C + ONE)*(AS - B + FOUR))*&\n DSQRT(TWO*(THREE + TWO)*(AS + ONE)*(AS - A)*(AS - C - TWO)*(AS&\n - C - ONE)*(AS - C)/((B - FOUR)*(B - THREE)*(B - TWO)*(B - ONE)&\n *B*(B + ONE)*(B + TWO)))\n SI = SI*DSQRT((AS - B + THREE)*(AS - B + TWO)*(AS - B + ONE)/((C + &\n THREE + TWO)*(C + FOUR)*(C + THREE)*(C + TWO)*(C + ONE)*C*(C - &\n ONE)))\n ELSE IF (M - K == 0) THEN\n! 0 -2\n SI = -AKA*((AS - ONE)*(AS - A + ONE) - (AS - C + ONE)*(AS - B + &\n THREE))*DSQRT(TWO*THREE*(THREE + TWO)*(AS + ONE)*AS*(AS - A - &\n ONE)*(AS - A)/((B - FOUR)*(B - THREE)*(B - TWO)*(B - ONE)*B*(B&\n + ONE)*(B + TWO)))\n SI = SI*DSQRT((AS - C - ONE)*(AS - C)*(AS - B + TWO)*(AS - B + ONE)&\n /((C + FOUR)*(C + THREE)*(C + TWO)*(C + ONE)*C*(C - ONE)*(C - &\n TWO)))\n ENDIF\n ELSE IF (N - J == 4) THEN\n! 2\n IF (K - M == 6) THEN\n! -3 2\n SI = AKA*DSQRT(TWO*THREE*(AS + ONE)*(AS - A)*(AS - B - FOUR)*(AS - &\n B - THREE)*(AS - B - TWO)*(AS - B - ONE)*(AS - B)/((B + THREE + &\n THREE)*(B + THREE + TWO)*(B + FOUR)*(B + THREE)*(B + TWO)*(B + &\n ONE)*B))\n SI = SI*DSQRT((AS - C + THREE + TWO)*(AS - C + FOUR)*(AS - C + &\n THREE)*(AS - C + TWO)*(AS - C + ONE)/((C - THREE - TWO)*(C - &\n FOUR)*(C - THREE)*(C - TWO)*(C - ONE)*C*(C + ONE)))\n ELSE IF (M - K == 6) THEN\n! 3 2\n SI = -AKA*DSQRT(TWO*THREE*(AS - C)*(AS - B + ONE)*(AS - A + THREE&\n + TWO)*(AS - A + FOUR)*(AS - A + THREE)*(AS - A + TWO)*(AS - A&\n + ONE)/((C + SEVEN)*(C + THREE + THREE)*(C + THREE + TWO)*(C + &\n FOUR)*(C + THREE)*(C + TWO)*(C + ONE)))\n SI = SI*DSQRT((AS + THREE + THREE)*(AS + THREE + TWO)*(AS + FOUR)*(&\n AS + THREE)*(AS + TWO)/((B + THREE + THREE)*(B + THREE + TWO)*(B&\n + FOUR)*(B + THREE)*(B + TWO)*(B + ONE)*B))\n ELSE IF (K - M == 4) THEN\n! -2 2\n SI = -AKA*((TWO + THREE)*(AS + ONE)*(AS - A + ONE) - (AS - B + ONE)&\n *(AS - C + THREE + TWO))*DSQRT((AS - B - THREE)*(AS - B - TWO)*(&\n AS - B - ONE)*(AS - B)/((C - FOUR)*(C - THREE)*(C - TWO)*(C - &\n ONE)*C*(C + ONE)*(C + TWO)))\n SI = SI*DSQRT((AS - C + FOUR)*(AS - C + THREE)*(AS - C + TWO)*(AS&\n - C + ONE)/((B + THREE + THREE)*(B + THREE + TWO)*(B + FOUR)*(B&\n + THREE)*(B + TWO)*(B + ONE)*B))\n ELSE IF (M - K == 4) THEN\n! 2 2\n SI = AKA*((TWO + THREE)*(AS - B)*(AS - C) - (AS - A)*(AS + THREE + &\n THREE))*DSQRT((AS - A + FOUR)*(AS - A + THREE)*(AS - A + TWO)*(&\n AS - A + ONE)/((B + THREE + THREE)*(B + THREE + TWO)*(B + FOUR)*&\n (B + THREE)*(B + TWO)*(B + ONE)*B))\n SI = SI*DSQRT((AS + THREE + TWO)*(AS + FOUR)*(AS + THREE)*(AS + TWO&\n )/((C + THREE + THREE)*(C + THREE + TWO)*(C + FOUR)*(C + THREE)*&\n (C + TWO)*(C + ONE)*C))\n ELSE IF (K - M == 2) THEN\n! -1 2\n SI = AKA*(TWO*(AS - A + TWO)*(AS + ONE) - (AS - B + ONE)*(AS - C + &\n FOUR))*DSQRT(TWO*(THREE + TWO)*(AS - A + ONE)*(AS + TWO)*(AS - B&\n - TWO)*(AS - B - ONE)*(AS - B)/((B + THREE + THREE)*(B + THREE&\n + TWO)*(B + FOUR)*(B + THREE)*(B + TWO)*(B + ONE)*B))\n SI = SI*DSQRT((AS - C + THREE)*(AS - C + TWO)*(AS - C + ONE)/((C - &\n THREE)*(C - TWO)*(C - ONE)*C*(C + ONE)*(C + TWO)*(C + THREE)))\n ELSE IF (M - K == 2) THEN\n! 1 2\n SI = -AKA*(TWO*(AS - B - ONE)*(AS - C) - (AS - A)*(AS + THREE + TWO&\n ))*DSQRT(TWO*(THREE + TWO)*(AS - B)*(AS - C + ONE)*(AS - A + &\n THREE)*(AS - A + TWO)*(AS - A + ONE)/((B + THREE + THREE)*(B + &\n THREE + TWO)*(B + FOUR)*(B + THREE)*(B + TWO)*(B + ONE)*B))\n SI = SI*DSQRT((AS + FOUR)*(AS + THREE)*(AS + TWO)/((C + THREE + TWO&\n )*(C + FOUR)*(C + THREE)*(C + TWO)*(C + ONE)*C*(C - ONE)))\n ELSE IF (M - K == 0) THEN\n! 0 2\n SI = AKA*((AS - B - TWO)*(AS - C) - (AS - A)*(AS + FOUR))*DSQRT(TWO&\n *THREE*(THREE + TWO)*(AS - B)*(AS - B - ONE)*(AS - C + TWO)*(AS&\n - C + ONE)/((B + THREE + THREE)*(B + THREE + TWO)*(B + FOUR)*(B&\n + THREE)*(B + TWO)*(B + ONE)*B))\n SI = SI*DSQRT((AS - A + TWO)*(AS - A + ONE)*(AS + THREE)*(AS + TWO)&\n /((C + FOUR)*(C + THREE)*(C + TWO)*(C + ONE)*C*(C - ONE)*(C - &\n TWO)))\n ENDIF\n ELSE IF (J - N == 2) THEN\n! - 1\n IF (K - M == 6) THEN\n! -3 -1\n SI = AKA*DSQRT(THREE*(THREE + TWO)*(AS - B)*(AS - B - ONE)*(AS - C&\n + TWO)*(AS - C + ONE)*(AS - TWO)*(AS - ONE)*AS*(AS + ONE)/((C&\n - THREE - TWO)*(C - FOUR)*(C - THREE)*(C - TWO)*(C - ONE)*C*(C&\n + ONE)))\n SI = SI*DSQRT((AS - A - THREE)*(AS - A - TWO)*(AS - A - ONE)*(AS - &\n A)/((B - THREE)*(B - TWO)*(B - ONE)*B*(B + ONE)*(B + TWO)*(B + &\n THREE)))\n ELSE IF (M - K == 6) THEN\n! 3 -1\n SI = AKA*DSQRT(THREE*(THREE + TWO)*(AS - A + ONE)*(AS - A + TWO)*(&\n AS + THREE)*(AS + TWO)*(AS - C - THREE)*(AS - C - TWO)*(AS - C&\n - ONE)*(AS - C)/((C + SEVEN)*(C + THREE + THREE)*(C + THREE + &\n TWO)*(C + FOUR)*(C + THREE)*(C + TWO)*(C + ONE)))\n SI = SI*DSQRT((AS - B + FOUR)*(AS - B + THREE)*(AS - B + TWO)*(AS&\n - B + ONE)/((B - THREE)*(B - TWO)*(B - ONE)*B*(B + ONE)*(B + &\n TWO)*(B + THREE)))\n ELSE IF (K - M == 4) THEN\n! -2 -1\n SI = AKA*(TWO*(AS - B - ONE)*(AS - C) - (AS + TWO)*(AS - A - THREE)&\n )*DSQRT(TWO*(THREE + TWO)*(AS - B)*(AS - C + ONE)*(AS - ONE)*AS*&\n (AS + ONE)/((C - FOUR)*(C - THREE)*(C - TWO)*(C - ONE)*C*(C + &\n ONE)*(C + TWO)))\n SI = SI*DSQRT((AS - A - TWO)*(AS - A - ONE)*(AS - A)/((B - THREE)*(&\n B - TWO)*(B - ONE)*B*(B + ONE)*(B + TWO)*(B + THREE)))\n ELSE IF (M - K == 4) THEN\n! 2 -1\n SI = AKA*(TWO*(AS - A + TWO)*(AS + ONE) - (AS - C + ONE)*(AS - B + &\n FOUR))*DSQRT(TWO*(THREE + TWO)*(AS - A + ONE)*(AS + TWO)*(AS - C&\n - TWO)*(AS - C - ONE)*(AS - C)/((C + THREE + THREE)*(C + THREE&\n + TWO)*(C + FOUR)*(C + THREE)*(C + TWO)*(C + ONE)*C))\n SI = SI*DSQRT((AS - B + THREE)*(AS - B + TWO)*(AS - B + ONE)/((B - &\n THREE)*(B - TWO)*(B - ONE)*B*(B + ONE)*(B + TWO)*(B + THREE)))\n ELSE IF (K - M == 2) THEN\n! -1 -1\n SI = AKA*(TWO*THREE*(AS - C)*(AS - C - ONE)*(AS - B - ONE)*(AS - B)&\n - TWO*FOUR*(AS - C)*(AS - B)*(AS + TWO)*(AS - A - TWO) + (AS + &\n THREE)*(AS + TWO)*(AS - A - THREE)*(AS - A - TWO))\n SI = SI*DSQRT(AS*(AS + ONE)*(AS - A - ONE)*(AS - A)/((B - THREE)*(B&\n - TWO)*(B - ONE)*B*(B + ONE)*(B + TWO)*(B + THREE)*(C - THREE)*&\n (C - TWO)*(C - ONE)*C*(C + ONE)*(C + TWO)*(C + THREE)))\n ELSE IF (M - K == 2) THEN\n! 1 -1\n SI = AKA*(TWO*THREE*(AS + ONE)*AS*(AS - A + ONE)*(AS - A + TWO) - &\n TWO*FOUR*(AS + ONE)*(AS - A + ONE)*(AS - C + ONE)*(AS - B + &\n THREE) + (AS - C + ONE)*(AS - C + TWO)*(AS - B + FOUR)*(AS - B&\n + THREE))\n SI = SI*DSQRT((AS - C - ONE)*(AS - C)*(AS - B + TWO)*(AS - B + ONE)&\n /((B - THREE)*(B - TWO)*(B - ONE)*B*(B + ONE)*(B + TWO)*(B + &\n THREE)*(C + THREE + TWO)*(C + FOUR)*(C + THREE)*(C + TWO)*(C + &\n ONE)*C*(C - ONE)))\n ELSE IF (M - K == 0) THEN\n! 0 -1\n SI = AKA*TWO*(AS*(AS - ONE)*(AS - A + ONE)*(AS - A + TWO) - THREE*&\n AS*(AS - A + ONE)*(AS - C + ONE)*(AS - B + TWO) + (AS - C + ONE)&\n *(AS - C + TWO)*(AS - B + THREE)*(AS - B + TWO))\n SI = SI*DSQRT(THREE*(AS + ONE)*(AS - A)*(AS - C)*(AS - B + ONE)/((B&\n - THREE)*(B - TWO)*(B - ONE)*B*(B + ONE)*(B + TWO)*(B + THREE)*&\n (C + FOUR)*(C + THREE)*(C + TWO)*(C + ONE)*C*(C - ONE)*(C - TWO)&\n ))\n ENDIF\n ELSE IF (N - J == 2) THEN\n! - 1\n IF (K - M == 6) THEN\n! -3 1\n SI = AKA*DSQRT(THREE*(THREE + TWO)*(AS + ONE)*AS*(AS - A - ONE)*(AS&\n - A)*(AS - B - THREE)*(AS - B - TWO)*(AS - B - ONE)*(AS - B)/((&\n C - THREE - TWO)*(C - FOUR)*(C - THREE)*(C - TWO)*(C - ONE)*C*(C&\n + ONE)))\n SI = SI*DSQRT((AS - C + FOUR)*(AS - C + THREE)*(AS - C + TWO)*(AS&\n - C + ONE)/((B + THREE + TWO)*(B + FOUR)*(B + THREE)*(B + TWO)*&\n (B + ONE)*B*(B - ONE)))\n ELSE IF (M - K == 6) THEN\n! 3 1\n SI = AKA*DSQRT(THREE*(THREE + TWO)*(AS - C)*(AS - C - ONE)*(AS - B&\n + TWO)*(AS - B + ONE)*(AS - A + FOUR)*(AS - A + THREE)*(AS - A&\n + TWO)*(AS - A + ONE)/((C + SEVEN)*(C + THREE + THREE)*(C + &\n THREE + TWO)*(C + FOUR)*(C + THREE)*(C + TWO)*(C + ONE)))\n SI = SI*DSQRT((AS + THREE + TWO)*(AS + FOUR)*(AS + THREE)*(AS + TWO&\n )/((B + THREE + TWO)*(B + FOUR)*(B + THREE)*(B + TWO)*(B + ONE)*&\n B*(B - ONE)))\n ELSE IF (K - M == 4) THEN\n! -2 1\n SI = -AKA*(TWO*AS*(AS - A + ONE) - (AS - B + ONE)*(AS - C + FOUR))*&\n DSQRT(TWO*(THREE + TWO)*(AS + ONE)*(AS - A)*(AS - B - TWO)*(AS&\n - B - ONE)*(AS - B)/((C - FOUR)*(C - THREE)*(C - TWO)*(C - ONE)&\n *C*(C + ONE)*(C + TWO)))\n SI = SI*DSQRT((AS - C + THREE)*(AS - C + TWO)*(AS - C + ONE)/((B + &\n THREE + TWO)*(B + FOUR)*(B + THREE)*(B + TWO)*(B + ONE)*B*(B - &\n ONE)))\n ELSE IF (M - K == 4) THEN\n! 2 1\n SI = -AKA*(TWO*(AS - C - ONE)*(AS - B) - (AS - A)*(AS + THREE + TWO&\n ))*DSQRT(TWO*(THREE + TWO)*(AS - C)*(AS - B + ONE)*(AS - A + &\n THREE)*(AS - A + TWO)*(AS - A + ONE)/((C + THREE + THREE)*(C + &\n THREE + TWO)*(C + FOUR)*(C + THREE)*(C + TWO)*(C + ONE)*C))\n SI = SI*DSQRT((AS + FOUR)*(AS + THREE)*(AS + TWO)/((B + THREE + TWO&\n )*(B + FOUR)*(B + THREE)*(B + TWO)*(B + ONE)*B*(B - ONE)))\n ELSE IF (M - K == 2) THEN\n! 1 1\n SI = AKA*(TWO*THREE*(AS - B)*(AS - B - ONE)*(AS - C)*(AS - C - ONE)&\n - TWO*FOUR*(AS - B)*(AS - C)*(AS - A)*(AS + FOUR) + (AS - A)*(&\n AS - A - ONE)*(AS + THREE + TWO)*(AS + FOUR))\n SI = SI*DSQRT((AS - A + TWO)*(AS - A + ONE)*(AS + THREE)*(AS + TWO)&\n /((B + THREE + TWO)*(B + FOUR)*(B + THREE)*(B + TWO)*(B + ONE)*B&\n *(B - ONE)*(C + THREE + TWO)*(C + FOUR)*(C + THREE)*(C + TWO)*(C&\n + ONE)*C*(C - ONE)))\n ELSE IF (K - M == 2) THEN\n! -1 1\n SI = AKA*(TWO*THREE*(AS + ONE)*AS*(AS - A + ONE)*(AS - A + TWO) - &\n TWO*FOUR*(AS + ONE)*(AS - A + ONE)*(AS - B + ONE)*(AS - C + &\n THREE) + (AS - B + ONE)*(AS - B + TWO)*(AS - C + FOUR)*(AS - C&\n + THREE))\n SI = SI*DSQRT((AS - B - ONE)*(AS - B)*(AS - C + TWO)*(AS - C + ONE)&\n /((C - THREE)*(C - TWO)*(C - ONE)*C*(C + ONE)*(C + TWO)*(C + &\n THREE)*(B + THREE + TWO)*(B + FOUR)*(B + THREE)*(B + TWO)*(B + &\n ONE)*B*(B - ONE)))\n ELSE IF (M - K == 0) THEN\n! 0 1\n SI = -AKA*TWO*((AS - B - ONE)*(AS - B - TWO)*(AS - C)*(AS - C - ONE&\n ) - THREE*(AS - B - ONE)*(AS - C)*(AS - A)*(AS + THREE) + (AS - &\n A)*(AS - A - ONE)*(AS + FOUR)*(AS + THREE))\n SI = SI*DSQRT(THREE*(AS - B)*(AS - C + ONE)*(AS - A + ONE)*(AS + &\n TWO)/((B + THREE + TWO)*(B + FOUR)*(B + THREE)*(B + TWO)*(B + &\n ONE)*B*(B - ONE)*(C + FOUR)*(C + THREE)*(C + TWO)*(C + ONE)*C*(C&\n - ONE)*(C - TWO)))\n ENDIF\n ELSE IF (J - N == 0) THEN\n! 0\n IF (K - M == 6) THEN\n! -3 0\n SI = AKA*TWO*DSQRT((THREE + TWO)*(AS + ONE)*AS*(AS - ONE)*(AS - A&\n - TWO)*(AS - A - ONE)*(AS - A)/((C - THREE - TWO)*(C - FOUR)*(C&\n - THREE)*(C - TWO)*(C - ONE)*C*(C + ONE)))\n SI = SI*DSQRT((AS - B - TWO)*(AS - B - ONE)*(AS - B)*(AS - C + &\n THREE)*(AS - C + TWO)*(AS - C + ONE)/((B + FOUR)*(B + THREE)*(B&\n + TWO)*(B + ONE)*B*(B - ONE)*(B - TWO)))\n ELSE IF (M - K == 6) THEN\n! 3 0\n SI = -AKA*TWO*DSQRT((THREE + TWO)*(AS - C)*(AS - C - ONE)*(AS - C&\n - TWO)*(AS - B + THREE)*(AS - B + TWO)*(AS - B + ONE)/((C + &\n SEVEN)*(C + THREE + THREE)*(C + THREE + TWO)*(C + FOUR)*(C + &\n THREE)*(C + TWO)*(C + ONE)))\n SI = SI*DSQRT((AS - A + THREE)*(AS - A + TWO)*(AS - A + ONE)*(AS + &\n FOUR)*(AS + THREE)*(AS + TWO)/((B + FOUR)*(B + THREE)*(B + TWO)*&\n (B + ONE)*B*(B - ONE)*(B - TWO)))\n ELSE IF (K - M == 4) THEN\n! -2 0\n SI = -AKA*((AS - ONE)*(AS - A + ONE) - (AS - B + ONE)*(AS - C + &\n THREE))*DSQRT(TWO*THREE*(THREE + TWO)*(AS + ONE)*AS*(AS - A - &\n ONE)*(AS - A)/((C - FOUR)*(C - THREE)*(C - TWO)*(C - ONE)*C*(C&\n + ONE)*(C + TWO)))\n SI = SI*DSQRT((AS - B - ONE)*(AS - B)*(AS - C + TWO)*(AS - C + ONE)&\n /((B + FOUR)*(B + THREE)*(B + TWO)*(B + ONE)*B*(B - ONE)*(B - &\n TWO)))\n ELSE IF (M - K == 4) THEN\n! 2 0\n SI = AKA*((AS - C - TWO)*(AS - B) - (AS - A)*(AS + FOUR))*DSQRT(TWO&\n *THREE*(THREE + TWO)*(AS - C)*(AS - C - ONE)*(AS - B + TWO)*(AS&\n - B + ONE)/((C + THREE + THREE)*(C + THREE + TWO)*(C + FOUR)*(C&\n + THREE)*(C + TWO)*(C + ONE)*C))\n SI = SI*DSQRT((AS - A + TWO)*(AS - A + ONE)*(AS + THREE)*(AS + TWO)&\n /((B + FOUR)*(B + THREE)*(B + TWO)*(B + ONE)*B*(B - ONE)*(B - &\n TWO)))\n ELSE IF (K - M == 2) THEN\n! -1 0\n SI = AKA*TWO*(AS*(AS - ONE)*(AS - A + ONE)*(AS - A + TWO) - THREE*&\n AS*(AS - A + ONE)*(AS - B + ONE)*(AS - C + TWO) + (AS - B + ONE)&\n *(AS - B + TWO)*(AS - C + THREE)*(AS - C + TWO))\n SI = SI*DSQRT(THREE*(AS + ONE)*(AS - A)*(AS - B)*(AS - C + ONE)/((C&\n - THREE)*(C - TWO)*(C - ONE)*C*(C + ONE)*(C + TWO)*(C + THREE)*&\n (B + FOUR)*(B + THREE)*(B + TWO)*(B + ONE)*B*(B - ONE)*(B - TWO)&\n ))\n ELSE IF (M - K == 2) THEN\n! 1 0\n SI = -AKA*TWO*((AS - C - ONE)*(AS - C - TWO)*(AS - B)*(AS - B - ONE&\n ) - THREE*(AS - C - ONE)*(AS - B)*(AS - A)*(AS + THREE) + (AS - &\n A)*(AS - A - ONE)*(AS + FOUR)*(AS + THREE))\n SI = SI*DSQRT(THREE*(AS - C)*(AS - B + ONE)*(AS - A + ONE)*(AS + &\n TWO)/((C + THREE + TWO)*(C + FOUR)*(C + THREE)*(C + TWO)*(C + &\n ONE)*C*(C - ONE)*(B + FOUR)*(B + THREE)*(B + TWO)*(B + ONE)*B*(B&\n - ONE)*(B - TWO)))\n ELSE IF (K - M == 0) THEN\n! 0 0\n SI = AKA*((AS - B)*(AS - B - ONE)*(AS - B - TWO)*(AS - C)*(AS - C&\n - ONE)*(AS - C - TWO) - THREE*THREE*(AS - B)*(AS - B - ONE)*(AS&\n - C)*(AS - C - ONE)*(AS - A)*(AS + TWO) + THREE*THREE*(AS - B)*&\n (AS - C)*(AS - A)*(AS - A - ONE)*(AS + THREE)*(AS + TWO) - (AS&\n - A)*(AS - A - ONE)*(AS - A - TWO)*(AS + FOUR)*(AS + THREE)*(AS&\n + TWO))\n SI = SI/DSQRT((B + FOUR)*(B + THREE)*(B + TWO)*(B + ONE)*B*(B - ONE&\n )*(B - TWO)*(C + FOUR)*(C + THREE)*(C + TWO)*(C + ONE)*C*(C - &\n ONE)*(C - TWO))\n ENDIF\n ENDIF\n RETURN\n END SUBROUTINE SIXJ3\n", "meta": {"hexsha": "ece0a6948a8f90f16e1438858266592840b486ed", "size": 29371, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/lib/librang90/sixj3.f90", "max_stars_repo_name": "sylas/grasp-continuum", "max_stars_repo_head_hexsha": "f5e2fb18bb2bca4f715072190bf455fba889320f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 33, "max_stars_repo_stars_event_min_datetime": "2019-03-10T04:00:32.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T22:01:15.000Z", "max_issues_repo_path": "src/lib/librang90/sixj3.f90", "max_issues_repo_name": "sylas/grasp-continuum", "max_issues_repo_head_hexsha": "f5e2fb18bb2bca4f715072190bf455fba889320f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 65, "max_issues_repo_issues_event_min_datetime": "2019-03-07T17:56:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-16T16:45:24.000Z", "max_forks_repo_path": "src/lib/librang90/sixj3.f90", "max_forks_repo_name": "sylas/grasp-continuum", "max_forks_repo_head_hexsha": "f5e2fb18bb2bca4f715072190bf455fba889320f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2019-03-10T04:00:43.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-23T02:06:40.000Z", "avg_line_length": 57.5901960784, "max_line_length": 80, "alphanum_fraction": 0.3345476831, "num_tokens": 9674, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133540338004, "lm_q2_score": 0.7057850278370112, "lm_q1q2_score": 0.6633767727411244}} {"text": "\n SUBROUTINE PHO_PECMS(Id,Pmass1,Pmass2,Ecm,Pp,Ee)\nC*******************************************************************\nC\nC calculation of cms momentum and energy of massive particle\nC (ID= 1 using PMASS1, 2 using PMASS2)\nC\nC output: PP cms momentum\nC EE energy in CMS of particle ID\nC\nC********************************************************************\n IMPLICIT NONE\n DOUBLE PRECISION Ecm , Ee , pm1 , pm2 , Pmass1 , Pmass2 , Pp , s\n INTEGER Id\n SAVE \n \nC input/output channels\n INCLUDE 'inc/poinou'\nC event debugging information\n INCLUDE 'inc/podebg'\nC some constants\n INCLUDE 'inc/pocons'\n \n s = Ecm**2\n pm1 = SIGN(Pmass1**2,Pmass1)\n pm2 = SIGN(Pmass2**2,Pmass2)\n Pp = SQRT(s**2-2.D0*pm1*s-2.D0*pm2*s-2.D0*pm1*pm2+pm1**2+pm2**2)\n & /(2.D0*Ecm)\n \n IF ( Id.EQ.1 ) THEN\n Ee = SQRT(pm1+Pp**2)\n ELSE IF ( Id.EQ.2 ) THEN\n Ee = SQRT(pm2+Pp**2)\n ELSE\n IF ( LPRi.GT.4 ) WRITE (LO,'(/1X,A,I3,/)')\n & 'PHO_PECMS:ERROR: invalid ID number:' , Id\n Ee = Pp\n END IF\n \n END SUBROUTINE\n", "meta": {"hexsha": "4ccbebac5bb9a907b5979bcfac4dd4b3e61afb46", "size": 1148, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/phojet/PHO_PECMS.f", "max_stars_repo_name": "pzhristov/DPMJET", "max_stars_repo_head_hexsha": "946e001290ca5ece608d7e5d1bfc7311cda7ebaa", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-06-15T01:59:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-01T08:39:13.000Z", "max_issues_repo_path": "src/phojet/PHO_PECMS.f", "max_issues_repo_name": "pzhristov/DPMJET", "max_issues_repo_head_hexsha": "946e001290ca5ece608d7e5d1bfc7311cda7ebaa", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-03-15T09:53:05.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-20T20:52:28.000Z", "max_forks_repo_path": "src/phojet/PHO_PECMS.f", "max_forks_repo_name": "pzhristov/DPMJET", "max_forks_repo_head_hexsha": "946e001290ca5ece608d7e5d1bfc7311cda7ebaa", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2020-07-05T02:44:05.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-20T20:49:05.000Z", "avg_line_length": 28.0, "max_line_length": 70, "alphanum_fraction": 0.4886759582, "num_tokens": 382, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133464597458, "lm_q2_score": 0.7057850278370112, "lm_q1q2_score": 0.66337676739547}} {"text": " double precision function vol_mass(decaymass,s)\n implicit none\n double precision decaymass,b0,bp,bm,s,vol,ro,ddilog\n \n ro=4d0*decaymass**2/s\n b0=dsqrt(1d0-ro)\n bp=0.5d0*(1d0+b0) \n bm=0.5d0*(1d0-b0) \n\nc temp=(4d0*b0*(27d0 - 26d0*b0**2 + 3d0*b0**4)\nc . + 3d0*(-1d0 + b0**2)**2*dlog((-1d0 + b0)**2)**2 + \nc . 6d0*(-1d0 + b0**2)**2*dlog(1d0-b0)*(1d0-4d0*dlog(1d0 + b0))+ \nc . 6d0*(-1d0 + b0**2)*dlog(1d0 + b0)*\nc . (9d0 - b0**4 + (-1d0 + b0**2)*dlog(16d0)\nc . - 2d0*(-1d0 + b0**2)*dlog(1d0 + b0)) \nc . + 3d0*(-1d0 + b0**2)*dlog((-1d0 + b0)**2)*\nc . (-8d0 + b0**4 + dlog(16d0) - b0**2*(1d0 + dlog(16d0)) + \nc . 4d0*(-1d0 + b0**2)*dlog(1d0 + b0)) + \nc . 24d0*(-1d0 + b0**2)**2*Ddilog((1d0 - b0)/2d0) - \nc . 24d0*(-1d0 + b0**2)**2*Ddilog((1d0 + b0)/2d0))/192d0\nc \nc--- normalize to massless case (1/12)\nc temp=temp/(1d0/12d0)\n \n vol_mass=b0*(1d0+5d0*ro+0.75d0*ro**2)\n . +1.5d0*ro**2*(Ddilog(bm)-Ddilog(bp))\n . -ro*dlog(bp/bm)*(24d0+6d0*ro-3d0*ro**2+6d0*ro*dlog(bp*bm))/8d0\n vol_mass=vol_mass*vol(s,4)\n \n return\n end\n \n", "meta": {"hexsha": "3041499535a813a0d60109a73fb61cd1f5c11f57", "size": 1154, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "MCFM-JHUGen/src/Vol/vol_mass.f", "max_stars_repo_name": "tmartini/JHUGen", "max_stars_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-06-08T13:09:28.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-04T19:59:36.000Z", "max_issues_repo_path": "MCFM-JHUGen/src/Vol/vol_mass.f", "max_issues_repo_name": "tmartini/JHUGen", "max_issues_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 64, "max_issues_repo_issues_event_min_datetime": "2015-06-24T15:08:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-25T04:59:32.000Z", "max_forks_repo_path": "MCFM-JHUGen/src/Vol/vol_mass.f", "max_forks_repo_name": "tmartini/JHUGen", "max_forks_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2015-05-04T22:15:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-06T10:04:40.000Z", "avg_line_length": 34.9696969697, "max_line_length": 69, "alphanum_fraction": 0.5, "num_tokens": 601, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133447766224, "lm_q2_score": 0.7057850154599563, "lm_q1q2_score": 0.6633767545741877}} {"text": "! To compile, type following command.\n! gfortran vicsek.f95 gettime.c -o vicsek && ./vicsek\nprogram main\nimplicit none\ncharacter filename*128\ninteger:: i,j, iter\ninteger:: iflag=0, gettime\nreal:: rand\ninteger:: num_particle, steps\nparameter(num_particle=300)\nreal*8:: pi=atan(1.0)*4.0\nreal*8:: x(num_particle), y(num_particle), vx(num_particle), vy(num_particle), theta(num_particle)\nreal*8:: mean_ang(num_particle)=0, D(num_particle, num_particle), randarray(num_particle)\nreal*8:: L, vc, dt, eta, r\n\ncall system('mkdir -p data')\n\n!L: system size\n!num_particle: the number of particles\n!vc: constant speed\n!dt: time step\n!steps: the number of run steps\n!eta: Order\n!r: interaction radius\nsteps=500\nL=5.0; vc=1.0; dt=0.1; eta=0.1; r=0.5\n! initial condition\ni=rand(gettime())\ndo i=1,num_particle\n theta(i) = unirand(-pi,pi)\n x(i) = unirand(0.0d0,L)\n y(i) = unirand(0.0d0,L)\n vx(i) = vc * cos(theta(i))\n vy(i) = vc * sin(theta(i))\nend do\n\n! start vicsek model\ndo iter=1,steps\n call filewrite(x,y,vx,vy,iter,num_particle) \n call ppdist(x,y,D,num_particle,L) \n call cal_mean_ang(D, mean_ang, theta, num_particle, r) \n\n \n !i=rand(gettime())\n do i=1,num_particle\n randarray(i) = unirand(-pi,pi)\n end do\n theta = mean_ang + eta * randarray\n vx = vc * cos(theta); vy = vc * sin(theta)\n x = x + vx * dt; y = y + vy * dt\n\n ! periodic boundary condition\n x = dmod((x + L), L); y = dmod((y + L), L)\nend do\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! function, subroutine\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\ncontains\n ! uniform random number\n function unirand(a,b)\n real*8:: unirand, a, b\n! real:: rand\n! integer:: i\n unirand = a + (b-a)*rand(iflag)\n end function unirand\n\n ! pairwise distance\n function dist(x1, x2, y1, y2, L)\n real*8 dist, x1, x2, y1, y2, L, dx, dy\n dx = dabs(x1 - x2)\n if (dx > L-dx) then\n dx = L-dx\n end if\n\n dy = dabs(y1 - y2)\n if (dy > L-dy) then\n dy = L-dy\n end if \n dist = sqrt(dx**2 + dy**2)\n end function dist\n\n subroutine ppdist(x,y,D,num_particle,L)\n integer:: num_particle, i, j\n real*8:: x(num_particle), y(num_particle), D(num_particle,num_particle), L\n\n do i=1,num_particle\n do j=1,num_particle\n D(i,j) = dist(x(i),x(j), y(i), y(j), L)\n end do\n end do\n return\n end subroutine ppdist\n\n ! mean angle\n subroutine cal_mean_ang(D, mean_ang, theta, N, r)\n integer:: N, near_count, i, j\n real*8:: D(N,N), mean_ang(N), theta(N), list_ang(N), mean_sin, mean_cos, r\n\n do i=1,N\n near_count = 0\n do j=1,N\n if (D(i,j) .le. r) then\n list_ang(near_count+1) = theta(j)\n near_count = near_count + 1\n end if\n end do\n\n mean_sin=0.0d0; mean_cos=0.0d0\n do j=1,near_count\n mean_sin = mean_sin + sin(list_ang(j))\n mean_cos = mean_cos + cos(list_ang(j))\n end do\n mean_sin = mean_sin / dble(near_count)\n mean_cos = mean_cos / dble(near_count)\n\n mean_ang(i) = atan2(mean_sin, mean_cos)\n end do\n end subroutine cal_mean_ang\n\n ! file write\n subroutine filewrite(x,y,vx,vy,iter,N)\n integer:: iter, N\n real*8:: x(N), y(N), vx(N), vy(N)\n write (filename, '(\"./data/\",i5.5, \".csv\")') iter-1\n open(17,file=filename, status='replace')\n do i=1,N\n write (17,*) x(i), \",\", y(i), \",\", vx(i), \",\", vy(i)\n end do\n close(17)\n end subroutine filewrite\nend program main\n", "meta": {"hexsha": "76294c806206a0d26761669286c0fc148d6d6845", "size": 3876, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Fortran/vicsek.f95", "max_stars_repo_name": "goropikari/vicsek-model", "max_stars_repo_head_hexsha": "1bbcd13be0cdedd959a799ef679c95f6bf549a34", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-02-02T17:23:22.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-02T17:23:22.000Z", "max_issues_repo_path": "Fortran/vicsek.f95", "max_issues_repo_name": "goropikari/vicsek-model", "max_issues_repo_head_hexsha": "1bbcd13be0cdedd959a799ef679c95f6bf549a34", "max_issues_repo_licenses": ["MIT"], "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/vicsek.f95", "max_forks_repo_name": "goropikari/vicsek-model", "max_forks_repo_head_hexsha": "1bbcd13be0cdedd959a799ef679c95f6bf549a34", "max_forks_repo_licenses": ["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.5, "max_line_length": 98, "alphanum_fraction": 0.528121775, "num_tokens": 1173, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267796346598, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.6633351489435705}} {"text": " subroutine compute_th(ctfm,ctfmp,n_a1,n_alpha,n_b1,n_beta,np1_a1,n\n &p1_alpha,np1_b1,np1_beta,x,Nx,ht,hx,myzero,phys_bdy,res)\n implicit none\n integer i\n integer Nx\n real*8 ht\n real*8 hx\n real*8 myzero\n real*8 ctfm(Nx)\n real*8 ctfmp(Nx)\n real*8 n_a1(Nx)\n real*8 n_alpha(Nx)\n real*8 n_b1(Nx)\n real*8 n_beta(Nx)\n real*8 np1_a1(Nx)\n real*8 np1_alpha(Nx)\n real*8 np1_b1(Nx)\n real*8 np1_beta(Nx)\n real*8 x(Nx)\n integer phys_bdy(2)\n real*8 res(Nx)\n real*8 qb\n if (phys_bdy(1) .eq. 1) then\n do i=1, 1, 1\n qb = 0.1D1 + myzero * x(i)\n res(i)=qb\n end do\n endif\n do i=2, Nx-1, 1\n qb = ((0.5000000000000000D0 / np1_alpha(i) + 0.5000000000000000D0 \n #/ n_alpha(i)) * (-0.1D1 * n_b1(i) + np1_b1(i)) / ht + 0.5000000000\n #000000D0 * (0.1D1 / np1_a1(i) - 0.1D1 * np1_beta(i) / np1_alpha(i)\n #) * (-0.5000000000000000D0 * (np1_b1(i - 1) - 0.1D1 * np1_b1(i + 1\n #)) / hx / ctfmp(i) + np1_b1(i) / ctfm(i)) + 0.5000000000000000D0 *\n # (0.1D1 / n_a1(i) - 0.1D1 * n_beta(i) / n_alpha(i)) * (-0.50000000\n #00000000D0 * (n_b1(i - 1) - 0.1D1 * n_b1(i + 1)) / hx / ctfmp(i) +\n # n_b1(i) / ctfm(i))) / (0.5000000000000000D0 * np1_b1(i) + 0.50000\n #00000000000D0 * n_b1(i))\n res(i)=qb\n end do\n if (phys_bdy(2) .eq. 1) then\n do i=Nx, Nx, 1\n qb = myzero * x(i)\n res(i)=qb\n end do\n endif\n END\n", "meta": {"hexsha": "3b0d650c5ba900a29fc5202fa92212aad78084cb", "size": 1488, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/FD/compute_th.f", "max_stars_repo_name": "rmanak/bssn_spher", "max_stars_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/FD/compute_th.f", "max_issues_repo_name": "rmanak/bssn_spher", "max_issues_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/FD/compute_th.f", "max_forks_repo_name": "rmanak/bssn_spher", "max_forks_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.0, "max_line_length": 72, "alphanum_fraction": 0.5329301075, "num_tokens": 673, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267694452331, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.6633351411641085}} {"text": " subroutine setprob_annulus()\n implicit none\n\n integer iunit\n character(len=25) fname \n\n double precision pi, pi2\n common /compi/ pi, pi2\n\n integer example\n common /example_comm/ example\n\n double precision revs_per_s, cart_speed, amplitude,freq\n common /stream_comm/ revs_per_s, cart_speed, amplitude, freq\n\n double precision beta, theta(2)\n common /annulus_comm/ beta, theta\n\n integer refine_pattern\n common /refine_comm/ refine_pattern\n\n double precision init_radius\n common /initradius_comm/ init_radius\n\n pi = 4.d0*atan(1.d0)\n pi2 = 2*pi\n\n iunit = 10\n fname = 'setprob.data' \n open(iunit,file=fname)\n\n read(iunit,*) example\n read(iunit,*) revs_per_s\n read(iunit,*) cart_speed\n read(iunit,*) amplitude\n read(iunit,*) freq\n read(iunit,*) beta\n read(iunit,*) theta(1), theta(2)\n read(iunit,*) refine_pattern\n read(iunit,*) init_radius !! radius\n close(iunit)\n\n cart_speed = 1.092505803290319d0\n\n\n open(10,file='mapping.dat')\n write(10,*) example\n write(10,*) amplitude\n write(10,*) init_radius\n write(10,*) beta\n write(10,*) theta(1)\n write(10,*) theta(2)\n write(10,*) freq\n write(10,*) cart_speed\n close(10)\n\n end\n", "meta": {"hexsha": "d22ec63e9ebee2f23676c13137bd2aa6ad9c721d", "size": 1344, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "applications/paper/annulus/setprob.f", "max_stars_repo_name": "scivision/forestclaw", "max_stars_repo_head_hexsha": "4dae847a8abd1055e70acda9c2973cd3dd77d3f1", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "applications/paper/annulus/setprob.f", "max_issues_repo_name": "scivision/forestclaw", "max_issues_repo_head_hexsha": "4dae847a8abd1055e70acda9c2973cd3dd77d3f1", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "applications/paper/annulus/setprob.f", "max_forks_repo_name": "scivision/forestclaw", "max_forks_repo_head_hexsha": "4dae847a8abd1055e70acda9c2973cd3dd77d3f1", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.1724137931, "max_line_length": 66, "alphanum_fraction": 0.603422619, "num_tokens": 379, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267864276108, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6633351401028613}} {"text": "C*************************************************************\nC Subroutine CHEBYFIT\nC Fits a Chebyscheff polynomial to arrays XX and YY\nC\nC XX real*8 array, in any order (!)\nC KK : Order of the polynomial (less than 19)\nC ICLASS=1 if array in ascending order and need to be sorted\nC\t =0 otherwise\nC************************************************************\n\tSUBROUTINE CHEBYFIT(XX,YY,NPTS,KK,ICLASS)\n\tIMPLICIT REAL*8 (A-H,O-Z)\n\tPARAMETER (IDIM=2000)\n\tREAL*8 XX(NPTS),YY(NPTS)\n\tREAL*8 WORK1(3,IDIM),WORK2(2,20)\n\tREAL*8 W(IDIM),CHEBY(20),SIGMA(20),ACHEBY(20,20)\nC This common block is internal to these two subroutines\n\tCOMMON /CHEBYFIT1/CHEBY,XMIN,XMAX,DELTA\nC\nC\tGenerating the array of the weights\nC\n\tDO I=1,NPTS\n\tW(I)=1.D0\n\tEND DO\nC Sort the array XX in ascending order (if ICLASS=0)\n\tIF(ICLASS.EQ.0)THEN\n\t CALL SORT_REAL8(XX,YY,NPTS,'A')\n\tENDIF\nC\nC Generates the coefficients of the Chebyscheff polynomial\nC\nC\tM=NPTS : number of points to fit\nC\tXX=RAD : array X\nC\tYY=PROF1 : array Y\nC\tW(M) : array of the weights\nC\tWORK1 and WORK2 : arrays for E02ADF to work\nC\tACHEBY(nrows,kplus1) : coeff. of the Chebyscheff polynomial\nC\tSIGMA(kplus1) : rms of the different fits of poly. of degree K\nC\tIFAIL : error flag\nC\n\tM=NPTS\n\tKPLUS1=KK+1\n\tNROWS=20\n\tIFAIL=1\n\tCALL E02ADF(M,KPLUS1,NROWS,XX,YY,W,WORK1,WORK2,\n\t1\tACHEBY,SIGMA,IFAIL)\n\tIF(IFAIL.NE.0)PRINT 56,IFAIL\n56\tFORMAT(' WARNING : ERROR IN E02ADF IFAIL=',I4)\n\tXMIN=XX(1)\n\tXMAX=XX(M)\n\tDELTA=XMAX-XMIN\nC\tWRITE (6,99) SIGMA(KK+1)\n99\tFORMAT(' RMS FOR THE FIT WITH POLYNOMIALS = ',F9.4)\nC\nC\tGenerating the array of the Chebyscheff polynomial\nC\n\tDO IPLUS1=1,KPLUS1\n\tCHEBY(IPLUS1)=ACHEBY(KPLUS1,IPLUS1)\nC\tPRINT 100,IPLUS1,CHEBY(IPLUS1)\n\tEND DO\n100\tFORMAT(' CHEBY ',I2,' : ',F10.3)\n\tRETURN\n\tEND\nC***************************************************************\nC\tSubroutine CALCHEBY\nC\tCalculates the image Y of X by a CHEBYSCHEFF polynomial\nC***************************************************************\n\tSUBROUTINE CALCHEBY(X,Y,KK)\n\tIMPLICIT REAL*8 (A-H,O-Z)\n\tREAL*8 CHEBY(20)\n\tREAL*8 X,Y,XMIN,XMAX\nC This common block is internal to these two subroutines\n\tCOMMON /CHEBYFIT1/CHEBY,XMIN,XMAX,DELTA\nC\nC\tCalculates the value of XCAP corresponding to X\nC\t(for Chebyscheff polynomials, XCAP comprised between -1 and +1\nC\n\tXCAP=((X-XMIN)-(XMAX-X))/DELTA\n\tIPLUS1=KK+1\n\tIFAIL=1\nC\tIPLUS1 : degree + 1 of the polynomial\nC\tCHEBY(20) : array of the coeff. of the Chebyscheff function\nC\tIFAIL : error flag\nC\n\tCALL E02AEF(IPLUS1,CHEBY,XCAP,Y,IFAIL)\n\tIF(IFAIL.NE.0)PRINT 56,IFAIL\n56\tFORMAT(' WARNING : ERROR IN E02AEF IFAIL=',I4)\n\tRETURN\n\tEND\nC******************************************************************\n\tinclude 'jlpsub:sort_set.for'\n", "meta": {"hexsha": "3e9468cd8520b0d2bb1a426b0051e4061fda3d14", "size": 2680, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "jlpsub/chebyfit.for", "max_stars_repo_name": "jlprieur/shell_galaxies", "max_stars_repo_head_hexsha": "1dde87ef33b3c33b3a892e9ad0d642ae02ac6d9e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "jlpsub/chebyfit.for", "max_issues_repo_name": "jlprieur/shell_galaxies", "max_issues_repo_head_hexsha": "1dde87ef33b3c33b3a892e9ad0d642ae02ac6d9e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "jlpsub/chebyfit.for", "max_forks_repo_name": "jlprieur/shell_galaxies", "max_forks_repo_head_hexsha": "1dde87ef33b3c33b3a892e9ad0d642ae02ac6d9e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.4505494505, "max_line_length": 67, "alphanum_fraction": 0.6470149254, "num_tokens": 939, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267898240861, "lm_q2_score": 0.7634837527911057, "lm_q1q2_score": 0.6633351380203425}} {"text": " PROGRAM MAIN_POWER\n! Purpose: Build sparse matrix and \n! perform power iteration via calls to Sparse BLAS\n\n! Header file of prototypes and named constants\n USE BLAS_SPARSE\n INTEGER, PARAMETER :: NMAX = 4, NNZ = 6\n INTEGER A,I,N,NITERS,ISTAT\n INTEGER, DIMENSION(:), ALLOCATABLE :: INDX,JNDX\n REAL(KIND=DP), DIMENSION(:), ALLOCATABLE :: VAL,Q,WORK\n REAL(KIND=DP) LAMBDA\n\n ALLOCATE (VAL(NNZ),INDX(NNZ),JNDX(NNZ))\n ALLOCATE (Q(NMAX),WORK(NMAX))\n\n! -----------------------------------\n! Define matrix, in coordinate format\n! -----------------------------------\n VAL = (/ 1.1_dp, 2.2_dp, 2.4_dp, 3.3_dp, 4.1_dp, 4.4_dp/)\n INDX = (/ 1, 2, 2, 3, 4, 4/)\n JNDX = (/ 1, 2, 4, 3, 1, 4/)\n\n N = NMAX\n\n! ----------------------------------\n! Step 1: Create Sparse BLAS handle\n! ----------------------------------\n CALL DUSCR_BEGIN( N, N, A, ISTAT)\n\n! -----------------------------------\n! Step 2: Insert entries all at once\n! -----------------------------------\n CALL USCR_INSERT_ENTRIES(A, VAL, INDX, JNDX, ISTAT)\n\n! -----------------------------------------------\n! Step 3: Complete construction of sparse matrix\n! -----------------------------------------------\n CALL USCR_END(A, ISTAT)\n\n\n! -----------------------------------------------\n! Step 4: Call Power Method Routine\n! -----------------------------------------------\n! q - eigenvector approximation. \n! lambda - eigenvalue approximation.\n NITERS = 100\n CALL POWER_METHOD(A, Q, LAMBDA, N, NITERS, WORK, ISTAT)\n IF (ISTAT.NE.0) THEN\n WRITE(*,*) 'ERROR IN POWER_METHOD = ',ISTAT\n ELSE\n WRITE(*,*) 'NUMBER OF ITERATIONS = ',NITERS\n WRITE(*,*) 'APPROXIMATE DOMINANT EIGENVALUE = ',LAMBDA\n ENDIF\n\n! -----------------------------------------------\n! Step 5: Release Matrix Handle\n! -----------------------------------------------\n CALL USDS(A,ISTAT)\n\n\n CONTAINS\n\n \n SUBROUTINE POWER_METHOD(A, Q, LAMBDA, N, NITERS, Z, ISTAT)\n USE BLAS_SPARSE\n IMPLICIT NONE\n REAL(KIND=DP), DIMENSION(:),INTENT(INOUT) :: Q(N),Z(N)\n REAL(KIND=DP), INTENT(OUT) :: LAMBDA\n INTEGER, INTENT(IN) :: A,N,NITERS\n INTEGER, INTENT(OUT):: ISTAT\n INTEGER I,ITER,ISEED\n REAL(KIND=DP):: NORMZ\n REAL Y\n INTRINSIC RANDOM_NUMBER,DOT_PRODUCT\n \n ! Fill Z by random numbers\n DO I = 1, N\n CALL RANDOM_NUMBER(HARVEST=Y)\n Z(I)=DBLE(Y)\n END DO\n \n DO ITER = 1, NITERS\n !Compute 2-norm of Z\n NORMZ = SQRT(DOT_PRODUCT(Z(1:N),Z(1:N)))\n !Normalize Z\n if (NORMZ.NE.0) Z(1:N) = Z(1:N)/NORMZ\n !Copy Z to Q\n Q=Z\n !Set Z to 0\n Z=0.D0\n !Compute new Z\n CALL USMV(A, Q, Z, ISTAT)\n !Test error flag\n IF (ISTAT.NE.0) RETURN\n !New LAMBDA\n LAMBDA = DOT_PRODUCT(Q,Z)\n END DO\n\n RETURN\n END SUBROUTINE POWER_METHOD\n\n END PROGRAM MAIN_POWER\n", "meta": {"hexsha": "9c3653b32e862a9dae21f8176cc9160f0a9ab310", "size": 3192, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ext/TESTER/power.f90", "max_stars_repo_name": "ittnas/qsc", "max_stars_repo_head_hexsha": "5e23c7f0c2985d79b966f8301a17c2679a5f2c8d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-23T09:41:11.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-23T09:41:11.000Z", "max_issues_repo_path": "ext/TESTER/power.f90", "max_issues_repo_name": "ittnas/qsc", "max_issues_repo_head_hexsha": "5e23c7f0c2985d79b966f8301a17c2679a5f2c8d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ext/TESTER/power.f90", "max_forks_repo_name": "ittnas/qsc", "max_forks_repo_head_hexsha": "5e23c7f0c2985d79b966f8301a17c2679a5f2c8d", "max_forks_repo_licenses": ["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.9902912621, "max_line_length": 66, "alphanum_fraction": 0.4483082707, "num_tokens": 915, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267762381843, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.663335136999072}} {"text": " function unimod_2(T)\n implicit none\n \n type(Tensor2), intent(in) :: T\n type(Tensor2) :: unimod_2, Eye\n real(kind=8) :: detT\n \n detT = det(T)\n Eye = identity2(Eye)\n \n unimod_2 = detT**(-1./3.) * T\n \n end function unimod_2\n \n function unimod_2s(T)\n implicit none\n \n type(Tensor2s), intent(in) :: T\n type(Tensor2s) :: unimod_2s, Eye\n real(kind=8) :: detT\n \n detT = det(T)\n Eye = identity2(Eye)\n \n unimod_2s = detT**(-1./3.) * T\n \n end function unimod_2s\n \n function unimod_2d(T,detT)\n implicit none\n \n type(Tensor2), intent(in) :: T\n type(Tensor2) :: unimod_2d, Eye\n real(kind=8), intent(in) :: detT\n\n Eye = identity2(Eye)\n \n unimod_2d = detT**(-1./3.) * T\n \n end function unimod_2d\n \n function unimod_2sd(T,detT)\n implicit none\n \n type(Tensor2s), intent(in) :: T\n type(Tensor2s) :: unimod_2sd, Eye\n real(kind=8), intent(in) :: detT\n\n Eye = identity2(Eye)\n \n unimod_2sd = detT**(-1./3.) * T\n \n end function unimod_2sd", "meta": {"hexsha": "d985e641031cb29e4689203c2cb03dc32ff44ccc", "size": 1261, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ttb/libunimodular.f", "max_stars_repo_name": "kengwit/ttb", "max_stars_repo_head_hexsha": "e3e41fdc0a3b47a45f762d8d89dafce3ace838f4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 41, "max_stars_repo_stars_event_min_datetime": "2018-02-27T06:31:19.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-30T07:58:45.000Z", "max_issues_repo_path": "ttb/libunimodular.f", "max_issues_repo_name": "kengwit/ttb", "max_issues_repo_head_hexsha": "e3e41fdc0a3b47a45f762d8d89dafce3ace838f4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 22, "max_issues_repo_issues_event_min_datetime": "2017-12-01T07:47:36.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-16T05:42:06.000Z", "max_forks_repo_path": "ttb/libunimodular.f", "max_forks_repo_name": "kengwit/ttb", "max_forks_repo_head_hexsha": "e3e41fdc0a3b47a45f762d8d89dafce3ace838f4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-07-12T01:45:20.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-25T08:03:13.000Z", "avg_line_length": 23.7924528302, "max_line_length": 41, "alphanum_fraction": 0.4694686757, "num_tokens": 388, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797124237604, "lm_q2_score": 0.7279754548076477, "lm_q1q2_score": 0.6633164655631886}} {"text": "SUBROUTINE bisect(d,e,acheps,ifail)\r\n!\r\n! This subroutine finds the eigenvalues of a tridiagonal matrix,\r\n! given with its diagonal elements in the array d(n) and\r\n! its subdiagonal elements in the last n - 1 stores of the\r\n! array e(n), using ql transformations. The eigenvalues are\r\n! overwritten on the diagonal elements in the array d in\r\n! ascending order. The subroutine will fail if any one\r\n! eigenvalue takes more than 30 iterations.\r\n!\r\n IMPLICIT NONE\r\n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\r\n REAL(iwp),INTENT(IN)::acheps\r\n REAL(iwp),INTENT(IN OUT)::d(0:),e(0:)\r\n INTEGER,INTENT(IN OUT)::ifail\r\n INTEGER::m,n,i,l,j,i1,m1,ii,aux\r\n REAL(iwp)::b,f,h,g,p,r,c,s,zero=0.0_iwp,pt5=0.5_iwp,one=1.0_iwp, &\r\n two=2.0_iwp\r\n n=UBOUND(d,1)\r\n IF(n/=1)THEN\r\n DO i=2,n\r\n e(i-1)=e(i)\r\n END DO\r\n END IF\r\n e(n)=zero\r\n b=zero\r\n f=zero\r\n loop_1: DO l=1,n\r\n j=0\r\n h=acheps*(ABS(d(l))+ABS(e(l)))\r\n IF(b=ABS(e(i)))THEN\r\n c= e(i)/p\r\n r=SQRT(c*c+one)\r\n e(i+1)=s*p*r\r\n s=c/r\r\n c=one/r\r\n ELSE\r\n c=p/e(i)\r\n r=SQRT(c*c+one)\r\n e(i+1)=s*e(i)*r\r\n s=one/r\r\n c=c/r\r\n END IF\r\n p=c*d(i)-s*g\r\n d(i+1)=h+s*(c*g+s*d(i))\r\n END DO loop_4\r\n e(l)=s*p\r\n d(l)=c*p\r\n IF(ABS(e(l))<=b)EXIT loop_2\r\n END DO loop_2\r\n END IF\r\n p=d(l)+f\r\n ! order eigenvalue\r\n aux=0\r\n IF(l/=1)THEN\r\n loop_3: DO ii=2,l\r\n i=l-ii+2\r\n IF(p>=d(i-1))THEN\r\n aux=1\r\n EXIT loop_3\r\n END IF\r\n d(i)=d(i-1)\r\n END DO loop_3\r\n END IF\r\n IF(aux==0)THEN\r\n i=1\r\n END IF\r\n d(i) = p\r\n ifail=0\r\n END DO loop_1\r\nRETURN\r\nEND SUBROUTINE bisect\r\n", "meta": {"hexsha": "3b2712a37a70e3a589d2747dd467426ad13acd6f", "size": 2602, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "src/libs/main/bisect.f03", "max_stars_repo_name": "leemargetts/PoreFEM", "max_stars_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/libs/main/bisect.f03", "max_issues_repo_name": "leemargetts/PoreFEM", "max_issues_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/libs/main/bisect.f03", "max_forks_repo_name": "leemargetts/PoreFEM", "max_forks_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.4310344828, "max_line_length": 76, "alphanum_fraction": 0.4723289777, "num_tokens": 927, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797172476384, "lm_q2_score": 0.7279754489059774, "lm_q1q2_score": 0.6633164636973711}} {"text": "MODULE lorenz96\n use common\n PRIVATE\n\n PUBLIC :: tinteg_rk4\n\n INTEGER,PARAMETER,PUBLIC :: nx=40 ! number of grid points\n REAL(r_size),SAVE,PUBLIC :: dt=0.005d0 ! time of one time step\n REAL(r_size),SAVE,PUBLIC :: force=8.0d0 ! F term\n REAL(r_size),SAVE,PUBLIC :: oneday=0.2d0 ! time for one day\nCONTAINS\n\nSUBROUTINE tinteg_rk4(kt,xin,xout)\n IMPLICIT NONE\n\n INTEGER,INTENT(IN) :: kt\n REAL(r_size),INTENT(IN) :: xin(1:nx)\n REAL(r_size),INTENT(OUT) :: xout(1:nx)\n REAL(r_size),ALLOCATABLE :: x(:),xtmp(:),q1(:),q2(:),q3(:),q4(:)\n INTEGER :: k\n!--[1.1.1] allocation --------------------------------------------------\n ALLOCATE( x(1:nx) ) ! nx : number of grid points\n ALLOCATE( xtmp(1:nx) )\n ALLOCATE( q1(1:nx) )\n ALLOCATE( q2(1:nx) )\n ALLOCATE( q3(1:nx) )\n ALLOCATE( q4(1:nx) )\n!--[1.1.2] time integration --------------------------------------------\n x(:) = xin(:)\n!>>>>> TIME INTEGRATION START\n DO k=1,kt\n xtmp(:) = x(:)\n CALL lorenz96_core(xtmp,q1)\n xtmp(:) = x(:) + 0.5d0 * q1(:)\n CALL lorenz96_core(xtmp,q2)\n xtmp(:) = x(:) + 0.5d0 * q2(:)\n CALL lorenz96_core(xtmp,q3)\n xtmp(:) = x(:) + q3(:)\n CALL lorenz96_core(xtmp,q4)\n x(:) = x(:) + ( q1(:) + 2.0d0 * q2(:) + 2.0d0 * q3(:) + q4(:) ) / 6.0d0\n END DO\n!<<<<< TIME INTEGRATION END\n xout(:) = x(:)\n!--[1.1.3] tidy up -----------------------------------------------------\n DEALLOCATE( xtmp,q1,q2,q3,q4 )\n\n RETURN\nEND SUBROUTINE tinteg_rk4\n\nSUBROUTINE lorenz96_core(xin,xout)\n IMPLICIT NONE\n\n REAL(r_size),INTENT(IN) :: xin(1:nx)\n REAL(r_size),INTENT(OUT) :: xout(1:nx)\n INTEGER :: i\n\n xout(1) = xin(nx) * ( xin(2) - xin(nx-1) ) - xin(1) + force\n xout(2) = xin(1) * ( xin(3) - xin(nx) ) - xin(2) + force\n DO i=3,nx-1\n xout(i) = xin(i-1) * ( xin(i+1) - xin(i-2) ) - xin(i) + force\n END DO\n xout(nx) = xin(nx-1) * ( xin(1) - xin(nx-2) ) - xin(nx) + force\n\n xout(:) = dt * xout(:)\n\n RETURN\nEND SUBROUTINE lorenz96_core\n\nEND MODULE lorenz96\n", "meta": {"hexsha": "26e815458bf95ade51fdd067ed94b92900a86156", "size": 1967, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "data/prep/lorenz96.f90", "max_stars_repo_name": "f-tomizawa/RC_Analysis_Loren96", "max_stars_repo_head_hexsha": "f8ba9368acbaaeef6b7cdf337b4a7c21048a17e8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-06-27T09:57:17.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-04T02:56:34.000Z", "max_issues_repo_path": "data/prep/lorenz96.f90", "max_issues_repo_name": "f-tomizawa/RC_Analysis_Loren96", "max_issues_repo_head_hexsha": "f8ba9368acbaaeef6b7cdf337b4a7c21048a17e8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "data/prep/lorenz96.f90", "max_forks_repo_name": "f-tomizawa/RC_Analysis_Loren96", "max_forks_repo_head_hexsha": "f8ba9368acbaaeef6b7cdf337b4a7c21048a17e8", "max_forks_repo_licenses": ["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.1, "max_line_length": 75, "alphanum_fraction": 0.5358413828, "num_tokens": 821, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998823, "lm_q2_score": 0.7279754548076477, "lm_q1q2_score": 0.6633164620515237}} {"text": "SUBROUTINE DGEEV_F95( A, WR, WI, VL, VR, INFO )\n!\n! -- LAPACK95 interface driver routine (version 3.0) --\n! UNI-C, Denmark; Univ. of Tennessee, USA; NAG Ltd., UK\n! September, 2000\n!\n! .. USE STATEMENTS ..\n USE LA_PRECISION, ONLY: WP => DP\n USE LA_AUXMOD, ONLY: ERINFO, LSAME\n USE F77_LAPACK, ONLY: GEEV_F77 => LA_GEEV\n! .. IMPLICIT STATEMENT ..\n IMPLICIT NONE\n! .. SCALAR ARGUMENTS ..\n INTEGER, INTENT(OUT), OPTIONAL :: INFO\n! .. ARRAY ARGUMENTS ..\n REAL(WP), INTENT(INOUT) :: A(:,:)\n REAL(WP), INTENT(OUT) :: WR(:), WI(:)\n REAL(WP), INTENT(OUT), OPTIONAL, TARGET :: VL(:,:), VR(:,:)\n!----------------------------------------------------------------------\n! \n! Purpose\n! =======\n! \n! LA_GEEV computes for a real or complex square matrix A, the \n! eigenvalues and, optionally, the left and/or right eigenvectors. A \n! right eigenvector v(j) of A satisfies\n! A * v(j) = lambda(j) * v(j)\n! where lambda(j) is its eigenvalue. A left eigenvector u(j) of A \n! satisffies\n! u(j)^H * A = lambda(j) * u(j)^H\n! where u(j)^H denotes the conjugate-transpose of u(j).\n! \n! =========\n! \n! SUBROUTINE LA_GEEV( A, , VL=vl, VR=vr, INFO=info )\n! (), INTENT(INOUT) :: A(:,:)\n! (), INTENT(OUT) :: \n! (), INTENT(OUT), OPTIONAL :: VL(:,:), VR(:,:)\n! INTEGER, INTENT(OUT), OPTIONAL :: INFO\n! where\n! ::= REAL | COMPLEX\n! ::= KIND(1.0) | KIND(1.0D0)\n! ::= WR, WI | W\n! ::= WR(:), WI(:) | W(:)\n! \n! Arguments\n! =========\n! \n! A (input/output) REAL or COMPLEX square array, shape (:,:).\n! On entry, the matrix A.\n! On exit, the contents of A are destroyed.\n! (output) REAL or COMPLEX array, shape (:) with size(w) = \n! size(A,1).\n! The computed eigenvalues.\n! ::= WR(:), WI(:) | W(:),\n! where\n! WR(:), WI(:) are of REAL type (for the real and imaginary\n! parts) and W(:) is of COMPLEX type.\n! Note: If A is real, then a complex-conjugate pair appear \n! consecutively, with the eigenvalue having the positive \n! imaginary part appearing first.\n! VL Optional (output) REAL or COMPLEX square array, shape (:,:)\n! with size(VL,1) = size(A,1).\n! The left eigenvectors u(j) are stored in the columns of VL in\n! the order of their eigenvalues. Each eigenvector is scaled so\n! that the Euclidean norm is 1 and the largest component is real.\n! Note: If A is real then complex eigenvectors, like their \n! eigenvalues, occur in complex conjugate pairs. The real and \n! imaginary parts of the first eigenvector of the pair are\n! stored in VL(:,j) and VL(:,j+1). Thus a complex conjugate pair\n! is given by \n! u(j) = VL(:,j) + i*VL(:,j+1), u(j+1) = VL(:,j) - i*VL(:,j+1)\n! VR Optional (output) REAL or COMPLEX square array, shape (:,:) \n! with size(VR,1) = size(A,1).\n! The right eigenvectors v(j) are stored in the columns of VR in\n! the order of their eigenvalues.\n! Each eigenvector is scaled so that the Euclidean norm is 1 and \n! the largest component is real.\n! Note: If A is real then complex eigenvectors, like their \n! eigenvalues, occur in complex conjugate pairs. The real and \n! imaginary parts of the first eigenvector of the pair are stored\n! in VR(:,j) and VR(:,j+1). Thus a complex conjugate pair is \n! given by \n! \t v(j) = VR(:,j) + i*VR(:,j+1), v(j+1) = VR(:,j) - i*VR(:,j+1)\n! INFO Optional (output) INTEGER.\n! = 0: successful exit.\n! < 0: if INFO = -i, the i-th argument had an illegal value.\n! > 0: if INFO = i, the QR algorithm failed to compute all the \n! eigenvalues and no eigenvectors were computed. Elements \n! \t i+1 : n of contain eigenvalues which have converged.\n! n is the order of A\n! If INFO is not present and an error occurs, then the program\n! is terminated with an error message.\n!----------------------------------------------------------------------\n! .. LOCAL PARAMETERS ..\n CHARACTER(LEN=7), PARAMETER :: SRNAME = 'LA_GEEV'\n! .. LOCAL SCALARS ..\n CHARACTER(LEN=1) :: LJOBVL, LJOBVR\n INTEGER, SAVE :: LWORK = 0\n INTEGER :: N, NN, LINFO, LD, ISTAT, ISTAT1, S1VL, S2VL, S1VR, S2VR\n! .. LOCAL ARRAYS ..\n REAL(WP), TARGET :: LLVL(1,1), LLVR(1,1)\n REAL(WP), POINTER :: WORK(:)\n! .. INTRINSIC FUNCTIONS ..\n INTRINSIC MAX, PRESENT, SIZE\n! .. EXECUTABLE STATEMENTS ..\n LINFO = 0; ISTAT = 0; N = SIZE(A,1); LD = MAX(1,N)\n IF( PRESENT(VL) )THEN; S1VL = SIZE(VL,1); S2VL = SIZE(VL,2); LJOBVL = 'V'\n ELSE; S1VL = 1; S2VL = 1; LJOBVL = 'N'; END IF\n IF( PRESENT(VR) )THEN; S1VR = SIZE(VR,1); S2VR = SIZE(VR,2); LJOBVR = 'V'\n ELSE; S1VR = 1; S2VR = 1; LJOBVR = 'N'; END IF\n! .. TEST THE ARGUMENTS\n IF( N < 0 .OR. SIZE(A,2) /= N )THEN; LINFO = -1\n ELSE IF( SIZE( WR ) /= N )THEN; LINFO = -2\n ELSE IF( SIZE( WI ) /= N )THEN; LINFO = -3\n ELSE IF( PRESENT(VL) .AND. ( S1VL /= N .OR. S2VL /= N ) )THEN; LINFO = -4\n ELSE IF( PRESENT(VR) .AND. ( S1VR /= N .OR. S2VR /= N ) )THEN; LINFO = -5\n ELSE IF( N > 0 )THEN\n NN = 3; IF( LSAME(LJOBVL,'V').OR.LSAME(LJOBVR,'V') ) NN = NN + 1\n LWORK = MAX( 1, NN*N, LWORK); ALLOCATE(WORK(LWORK), STAT=ISTAT)\n IF( ISTAT /= 0 )THEN; DEALLOCATE(WORK,STAT=ISTAT1)\n LWORK = MAX( 1, NN*N ); ALLOCATE(WORK(LWORK), STAT=ISTAT)\n IF( ISTAT == 0) CALL ERINFO( -200, SRNAME, LINFO )\n END IF\n IF( ISTAT == 0 ) THEN\n IF( PRESENT(VL) )THEN\n IF( PRESENT(VR) )THEN\n CALL GEEV_F77( LJOBVL, LJOBVR, N, A, LD, WR, WI, &\n VL, S1VL, VR, S1VR, WORK, LWORK, LINFO )\n\t ELSE\n\t CALL GEEV_F77( LJOBVL, LJOBVR, N, A, LD, WR, WI, &\n VL, S1VL, LLVR, S1VR, WORK, LWORK, LINFO )\n\t ENDIF\n\t ELSE\n\t IF( PRESENT(VR) )THEN\n\t CALL GEEV_F77( LJOBVL, LJOBVR, N, A, LD, WR, WI, &\n LLVL, S1VL, VR, S1VR, WORK, LWORK, LINFO )\n\t ELSE\n\t CALL GEEV_F77( LJOBVL, LJOBVR, N, A, LD, WR, WI, &\n LLVL, S1VL, LLVR, S1VR, WORK, LWORK, LINFO )\n\t ENDIF\n\t ENDIF \n IF( LINFO == 0 ) LWORK = INT(WORK(1)+1)\n ELSE; LINFO = -100; ENDIF\n DEALLOCATE(WORK, STAT=ISTAT1)\n ENDIF\n CALL ERINFO(LINFO,SRNAME,INFO,ISTAT)\nEND SUBROUTINE DGEEV_F95\n", "meta": {"hexsha": "fe48237570ce414823352f907fe0ebb9e74d90bd", "size": 6589, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "code_1D/couplage_1D/fortran90_source/liblapack95/SRC/la_dgeev.f90", "max_stars_repo_name": "IRFM/ALOHA", "max_stars_repo_head_hexsha": "e8e7a47a70c7095b339b3dea25dcd4b95f382959", "max_stars_repo_licenses": ["CECILL-B"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-12-29T15:07:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T10:09:22.000Z", "max_issues_repo_path": "code_1D/couplage_1D/fortran90_source/liblapack95/SRC/la_dgeev.f90", "max_issues_repo_name": "IRFM/ALOHA", "max_issues_repo_head_hexsha": "e8e7a47a70c7095b339b3dea25dcd4b95f382959", "max_issues_repo_licenses": ["CECILL-B"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-02-21T10:46:38.000Z", "max_issues_repo_issues_event_max_datetime": "2017-10-20T17:03:14.000Z", "max_forks_repo_path": "code_1D/couplage_1D/fortran90_source/liblapack95/SRC/la_dgeev.f90", "max_forks_repo_name": "IRFM/ALOHA", "max_forks_repo_head_hexsha": "e8e7a47a70c7095b339b3dea25dcd4b95f382959", "max_forks_repo_licenses": ["CECILL-B"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-12-29T15:34:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-15T07:12:40.000Z", "avg_line_length": 44.2214765101, "max_line_length": 76, "alphanum_fraction": 0.5402944301, "num_tokens": 2185, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9111797124237604, "lm_q2_score": 0.7279754489059774, "lm_q1q2_score": 0.6633164601857063}} {"text": "\nsubroutine shape2(s,t,nnode,shape,deriv,heslo)\n\n!-----------------------------------------------------------------------\n!\n! This routine evaluates shape functions and their first and\n! second derivatives for 2-d continuos standar interpolation \n! elements.\n!\n! TRIANGLES 3 6 10 & 15 nodes\n! QUADRILATERALS 4 9 16 & 25 nodes\n!\n!-----------------------------------------------------------------------\n\n use typre\n implicit none\n integer(ip), intent(in) :: nnode\n real(rp), intent(in) :: s,t\n real(rp), intent(out) :: deriv(2,nnode),shape(nnode),heslo(3,nnode)\n real(rp) :: st,ss,tt,s1,s2,s3,s4,t1,t2,t3,t4,s9,t9,c,a\n real(rp) :: a1,a2,a3\n real(rp) :: Nt(5), DNt(5), D2Nt(5), Ns(5), DNs(5), D2Ns(5)\n if(nnode==3) then \n shape(1)=1.0_rp-s-t \n shape(2)=s \n shape(3)=t ! 3\n deriv(1,1)=-1.0_rp ! \n deriv(1,2)= 1.0_rp !\n deriv(1,3)= 0.0_rp !\n deriv(2,1)=-1.0_rp ! 1 2\n deriv(2,2)= 0.0_rp\n deriv(2,3)= 1.0_rp\n else if(nnode==4) then\n st=s*t \n shape(1)=(1.0_rp-t-s+st)*0.25_rp ! 4 3\n shape(2)=(1.0_rp-t+s-st)*0.25_rp !\n shape(3)=(1.0_rp+t+s+st)*0.25_rp ! \n shape(4)=(1.0_rp+t-s-st)*0.25_rp !\n deriv(1,1)=(-1.0_rp+t)*0.25_rp ! 1 2\n deriv(1,2)=(+1.0_rp-t)*0.25_rp\n deriv(1,3)=(+1.0_rp+t)*0.25_rp\n deriv(1,4)=(-1.0_rp-t)*0.25_rp\n deriv(2,1)=(-1.0_rp+s)*0.25_rp\n deriv(2,2)=(-1.0_rp-s)*0.25_rp\n deriv(2,3)=(+1.0_rp+s)*0.25_rp\n deriv(2,4)=(+1.0_rp-s)*0.25_rp\n heslo(3,1)= 0.25_rp\n heslo(3,2)=-0.25_rp\n heslo(3,3)= 0.25_rp\n heslo(3,4)=-0.25_rp\n else if(nnode==6) then\n a1=1.0_rp-s-t\n a2=s \n a3=t\n shape( 1)=(2.0_rp*a1-1.0_rp)*a1 ! 3\n shape( 2)=(2.0_rp*a2-1.0_rp)*a2 ! \n shape( 3)=(2.0_rp*a3-1.0_rp)*a3 ! \n shape( 4)=4.0_rp*a1*a2 ! 6 5\n shape( 5)=4.0_rp*a2*a3 ! \n shape( 6)=4.0_rp*a1*a3 ! \n deriv(1,1)= 1.0_rp-4.0_rp*a1 ! 1 4 2\n deriv(1,2)= 4.0_rp*a2-1.0_rp \n deriv(1,3)= 0.0_rp \n deriv(1,4)= 4.0_rp*(a1-a2) \n deriv(1,5)= 4.0_rp*a3 \n deriv(1,6)=-4.0_rp*a3 \n deriv(2,1)= 1.0_rp-4.0_rp*a1 \n deriv(2,2)= 0.0_rp \n deriv(2,3)= 4.0_rp*a3-1.0_rp \n deriv(2,4)=-4.0_rp*a2 \n deriv(2,5)= 4.0_rp*a2 \n deriv(2,6)= 4.0_rp*(a1-a3)\n heslo(1,1)= 4.0_rp\n heslo(1,2)= 4.0_rp\n heslo(1,4)=-8.0_rp\n heslo(2,1)= 4.0_rp\n heslo(2,3)= 4.0_rp\n heslo(2,6)=-8.0_rp\n heslo(3,1)= 4.0_rp\n heslo(3,4)=-4.0_rp\n heslo(3,5)= 4.0_rp\n heslo(3,6)=-4.0_rp\n else if(nnode==9) then\n ss=s*s\n st=s*t\n tt=t*t\n s1=s+1.0_rp\n t1=t+1.0_rp\n s2=s*2.0_rp\n t2=t*2.0_rp\n s9=s-1.0_rp \n t9=t-1.0_rp ! 4 7 3\n shape( 1)=0.25_rp*s9*st*t9 !\n shape( 2)=0.25_rp*s1*st*t9 ! \n shape( 3)=0.25_rp*s1*st*t1 ! \n shape( 4)=0.25_rp*s9*st*t1 ! 8 9 6\n shape( 5)=0.5_rp*(1.0_rp-ss)*t*t9 ! \n shape( 6)=0.5_rp*s*s1*(1.0_rp-tt) ! \n shape( 7)=0.5_rp*(1.0_rp-ss)*t*t1 ! \n shape( 8)=0.5_rp*s*s9*(1.0_rp-tt) ! 1 5 2\n shape( 9)=(1.0_rp-ss)*(1.0_rp-tt)\n deriv(1,1)= 0.25_rp*t*t9*(-1.0_rp+s2)\n deriv(1,2)= 0.25_rp*(1.0_rp+s2)*t*t9\n deriv(1,3)= 0.25_rp*(1.0_rp+s2)*t*t1\n deriv(1,4)= 0.25_rp*(-1.0_rp+s2)*t*t1\n deriv(1,5)=-st*t9\n deriv(1,6)= 0.5_rp*(1.0_rp+s2)*(1.0_rp-tt)\n deriv(1,7)=-st*t1\n deriv(1,8)= 0.5_rp*(-1.0_rp+s2)*(1.0_rp-tt)\n deriv(1,9)=-s2*(1.0_rp-tt)\n deriv(2,1)= 0.25_rp*(-1.0_rp+t2)*s*s9\n deriv(2,2)= 0.25_rp*s*s1*(-1.0_rp+t2)\n deriv(2,3)= 0.25_rp*s*s1*(1.0_rp+t2)\n deriv(2,4)= 0.25_rp*s*s9*(1.0_rp+t2)\n deriv(2,5)= 0.5_rp*(1.0_rp-ss)*(-1.0_rp+t2)\n deriv(2,6)=-st*s1\n deriv(2,7)= 0.5_rp*(1.0_rp-ss)*(1.0_rp+t2)\n deriv(2,8)=-st*s9\n deriv(2,9)=-t2*(1.0_rp-ss)\n heslo(1,1)= 0.5_rp*t*t9\n heslo(1,2)= 0.5_rp*t*t9\n heslo(1,3)= 0.5_rp*t*t1\n heslo(1,4)= 0.5_rp*t*t1\n heslo(1,5)=-t*t9\n heslo(1,6)= 1.0_rp-tt\n heslo(1,7)=-t*t1\n heslo(1,8)= 1.0_rp-tt\n heslo(1,9)=-2.0_rp*(1.0_rp-tt)\n heslo(2,1)= 0.5_rp*s*s9\n heslo(2,2)= 0.5_rp*s*s1\n heslo(2,3)= 0.5_rp*s*s1\n heslo(2,4)= 0.5_rp*s*s9\n heslo(2,5)= 1.0_rp-ss\n heslo(2,6)=-s*s1\n heslo(2,7)= 1.0_rp-ss\n heslo(2,8)=-s*s9\n heslo(2,9)=-2.0_rp*(1.0_rp-ss)\n heslo(3,1)= 0.25_rp*(-1.0_rp+t2)*(s9+s)\n heslo(3,2)= 0.25_rp*(-1.0_rp+t2)*(s1+s)\n heslo(3,3)= 0.25_rp*(1.0_rp+t2)*(s1+s)\n heslo(3,4)= 0.25_rp*(1.0_rp+t2)*(s9+s)\n heslo(3,5)=-s*(-1.0_rp+t2)\n heslo(3,6)=-t*s1-st\n heslo(3,7)=-s*(1.0_rp+t2)\n heslo(3,8)=-t*s9-st\n heslo(3,9)= s2*t2\n else if(nnode==10) then\n c=9.0_rp/2.0_rp\n a1=(3.0_rp-3.0_rp*s-3.0_rp*t)/3.0_rp\n a2=(2.0_rp-3.0_rp*(s+t))/3.0_rp\n a3=(1.0_rp-3.0_rp*(s+t))/3.0_rp\n shape( 1)=c*a1*a2*a3 ! 3 \n shape( 2)=c*(3.0_rp*s-1.0_rp)*(3.0_rp*s-2.0_rp)*s/9.0_rp ! \n shape( 3)=c*(1.0_rp-3.0_rp*t)*(2.0_rp-3.0_rp*t)*t/9.0_rp ! \n shape( 4)= 3.0_rp*c*a1*a2*s ! 8 7 \n shape( 5)=-c*a1*(1.0_rp-3.0_rp*s)*s ! \n shape( 6)=-c*(1.0_rp-3.0_rp*s)*s*t ! \n shape( 7)=-c*s*(1.0_rp-3.0_rp*t)*t ! 9 10 6\n shape( 8)=-c*a1*(1.0_rp-3.0_rp*t)*t !\n shape( 9)= 3.0_rp*c*a1*a2*t !\n shape(10)= 6.0_rp*c*a1*s*t ! 1 4 5 2\n deriv(1, 1)=-c*(a1*a2+a1*a3+a2*a3) \n deriv(1, 2)=-c*((2.0_rp-3.0_rp*s)/3.0_rp*s&\n + (1.0_rp-3.0_rp*s)/3.0_rp*s-(1.0_rp-3.0_rp*s)*(2.0_rp-3.0_rp*s)/9.0_rp)\n deriv(1, 3)=0.0_rp\n deriv(1, 4)= 3.0_rp*c*(a1*a2-a1*s-a2*s)\n deriv(1, 5)=-3.0_rp*c*(a1*(1.0_rp-3.0_rp*s)/3.0_rp&\n - a1*s-(1.0_rp-3.0_rp*s)*s/3.0_rp)\n deriv(1, 6)=-3.0_rp*c*((1.0_rp-3.0_rp*s)*t/3.0_rp-s*t)\n deriv(1, 7)=-c*(1.0_rp-3.0_rp*t)*t\n deriv(1, 8)= c*(1.0_rp-3.0_rp*t)*t\n deriv(1, 9)= 3.0_rp*c*(-a1*t-a2*t)\n deriv(1,10)= 6.0_rp*c*(a1*t-s*t)\n deriv(2, 1)=-c*(a1*a2+a1*a3+a2*a3)\n deriv(2, 2)= 0.0_rp\n deriv(2, 3)=-c*((2.0_rp-3.0_rp*t)*t/3.0_rp&\n + (1.0_rp-3.0_rp*t)*t/3.0_rp-(1.0_rp-3.0_rp*t)*(2.0_rp-3.0_rp*t)/9.0_rp)\n deriv(2, 4)= 3.0_rp*c*(-a1*s-a2*s)\n deriv(2, 5)=c*(1.0_rp-3.0_rp*s)*s\n deriv(2, 6)=-c*(1.0_rp-3.0_rp*s)*s\n deriv(2, 7)=-3.0_rp*c*((1.0_rp-3.0_rp*t)*s/3.0_rp-s*t)\n deriv(2, 8)=-3.0_rp*c*(-(1.0_rp-3.0_rp*t)*t/3.0_rp&\n - a1*t+a1*(1.0_rp-3.0_rp*t)/3.0_rp)\n deriv(2, 9)= 3.0_rp*c*(-a1*t-a2*t+a1*a2)\n deriv(2,10)= 6.0_rp*c*(a1*s-s*t)\n heslo(1, 1)= c*(6.0_rp*a1+6.0_rp*a2+6.0_rp*a3)/3.0_rp\n heslo(1, 2)=-c*(2.0_rp-6.0_rp*s) \n heslo(1, 3)= 0.0_rp \n heslo(1, 4)= c*(-6.0_rp*a1-6.0_rp*a2+6.0_rp*s)\n heslo(1, 5)=-c*(-6.0_rp*a1-2.0_rp*(1.0_rp-3.0_rp*s)+6.0_rp*s) \n heslo(1, 6)= 6.0_rp*c*t \n heslo(1, 7)= 0.0_rp \n heslo(1, 8)= 0.0_rp \n heslo(1, 9)= 6.0_rp*c*t \n heslo(1,10)=-12.0_rp*c*t \n heslo(2, 1)= c*(6.0_rp*a1+6.0_rp*a2+6.0_rp*a3)/3.0_rp \n heslo(2, 2)= 0.0_rp \n heslo(2, 3)=-c*(2.0_rp-6.0_rp*t)\n heslo(2, 4)= 6.0_rp*c*s\n heslo(2, 5)= 0.0_rp\n heslo(2, 6)= 0.0_rp\n heslo(2, 7)= 6.0_rp*c*s\n heslo(2, 8)=-c*(-6.0_rp*a1-2.0_rp*(1.0_rp-3.0_rp*t)+6.0_rp*t)\n heslo(2, 9)= c*(-6.0_rp*a1-6.0_rp*a2+6.0_rp*t)\n heslo(2,10)=-12.0_rp*c*s\n heslo(3, 1)= c*(6.0_rp*a1+6.0_rp*a2+6.0_rp*a3)/3.0_rp \n heslo(3, 2)= 0.0_rp \n heslo(3, 3)= 0.0_rp \n heslo(3, 4)= c*(-3.0_rp*a1-3.0_rp*a2+6.0_rp*s) \n heslo(3, 5)=-c*(-(1.0_rp-3.0_rp*s)+3.0_rp*s) \n heslo(3, 6)=-c*(1.0_rp-6.0_rp*s)\n heslo(3, 7)=-c*(1.0_rp-6.0_rp*t)\n heslo(3, 8)= c*(1.0_rp-6.0_rp*t) \n heslo(3, 9)= c*(-3.0_rp*a1-3.0_rp*a2+6.0_rp*t) \n heslo(3,10)= c*(6.0_rp*a1-6.0_rp*s-6.0_rp*t)\n else if(nnode==16) then\n a =81.0_rp/256.0_rp\n s1=(3.0_rp+3.0_rp*s)/3.0_rp\n s2=(1.0_rp+3.0_rp*s)/3.0_rp\n s3=(1.0_rp-3.0_rp*s)/3.0_rp\n s4=(3.0_rp-3.0_rp*s)/3.0_rp\n t1=(3.0_rp+3.0_rp*t)/3.0_rp\n t2=(1.0_rp+3.0_rp*t)/3.0_rp\n t3=(1.0_rp-3.0_rp*t)/3.0_rp\n t4=(3.0_rp-3.0_rp*t)/3.0_rp\n shape( 1) = a*s2*s3*s4*t2*t3*t4 ! 4 10 9 3\n shape( 2) = a*s1*s2*s3*t2*t3*t4 ! \n shape( 3) = a*s1*s2*s3*t1*t2*t3 ! \n shape( 4) = a*s2*s3*s4*t1*t2*t3 ! 11 16 15 8\n shape( 5) =-3.0_rp*a*s1*s3*s4*t2*t3*t4 !\n shape( 6) =-3.0_rp*a*s1*s2*s4*t2*t3*t4 !\n shape( 7) =-3.0_rp*a*s1*s2*s3*t1*t3*t4 ! 12 13 14 7\n shape( 8) =-3.0_rp*a*s1*s2*s3*t1*t2*t4 !\n shape( 9) =-3.0_rp*a*s1*s2*s4*t1*t2*t3 !\n shape(10) =-3.0_rp*a*s1*s3*s4*t1*t2*t3 ! 1 5 6 2\n shape(11) =-3.0_rp*a*s2*s3*s4*t1*t2*t4 \n shape(12) =-3.0_rp*a*s2*s3*s4*t1*t3*t4\n shape(13) = 9.0_rp*a*s1*s3*s4*t1*t3*t4\n shape(14) = 9.0_rp*a*s1*s2*s4*t1*t3*t4\n shape(15) = 9.0_rp*a*s1*s2*s4*t1*t2*t4\n shape(16) = 9.0_rp*a*s1*s3*s4*t1*t2*t4\n deriv(1, 1)= a *t2*t3*t4*(-s2*s3-s2*s4+s3*s4)\n deriv(1, 2)= a *t2*t3*t4*(-s1*s2+s1*s3+s2*s3)\n deriv(1, 3)= a *t1*t2*t3*(-s1*s2+s1*s3+s2*s3)\n deriv(1, 4)= a *t1*t2*t3*(-s2*s3-s2*s4+s3*s4)\n deriv(1, 5)= -3.0_rp*a*t2*t3*t4*(-s1*s3-s1*s4+s3*s4) \n deriv(1, 6)=-3.0_rp*a*t2*t3*t4*(-s1*s2+s1*s4+s2*s4)\n deriv(1, 7)=-3.0_rp*a*t1*t3*t4*(-s1*s2+s1*s3+s2*s3)\n deriv(1, 8)=-3.0_rp*a*t1*t2*t4*(-s1*s2+s1*s3+s2*s3)\n deriv(1, 9)=-3.0_rp*a*t1*t2*t3*(-s1*s2+s1*s4+s2*s4)\n deriv(1,10)=-3.0_rp*a*t1*t2*t3*(-s1*s3-s1*s4+s3*s4)\n deriv(1,11)=-3.0_rp*a*t1*t2*t4*(-s2*s3-s2*s4+s3*s4)\n deriv(1,12)=-3.0_rp*a*t1*t3*t4*(-s2*s3-s2*s4+s3*s4)\n deriv(1,13)= 9.0_rp*a*t1*t3*t4*(-s1*s3-s1*s4+s3*s4)\n deriv(1,14)= 9.0_rp*a*t1*t3*t4*(-s1*s2+s1*s4+s2*s4)\n deriv(1,15)= 9.0_rp*a*t1*t2*t4*(-s1*s2+s1*s4+s2*s4)\n deriv(1,16)= 9.0_rp*a*t1*t2*t4*(-s1*s3-s1*s4+s3*s4)\n deriv(2, 1)= a *s2*s3*s4*(-t2*t3-t2*t4+t3*t4)\n deriv(2, 2)= a *s1*s2*s3*(-t2*t3-t2*t4+t3*t4)\n deriv(2, 3)= a *s1*s2*s3*(-t1*t2+t1*t3+t2*t3)\n deriv(2, 4)= a *s2*s3*s4*(-t1*t2+t1*t3+t2*t3)\n deriv(2, 5)= -3.0_rp*a *s1*s3*s4*(-t2*t3-t2*t4+t3*t4)\n deriv(2, 6)= -3.0_rp*a *s1*s2*s4*(-t2*t3-t2*t4+t3*t4)\n deriv(2, 7)= -3.0_rp*a *s1*s2*s3*(-t1*t3-t1*t4+t3*t4)\n deriv(2, 8)= -3.0_rp*a *s1*s2*s3*(-t1*t2+t1*t4+t2*t4)\n deriv(2, 9)= -3.0_rp*a *s1*s2*s4*(-t1*t2+t1*t3+t2*t3)\n deriv(2,10)= -3.0_rp*a *s1*s3*s4*(-t1*t2+t1*t3+t2*t3)\n deriv(2,11)= -3.0_rp*a *s2*s3*s4*(-t1*t2+t1*t4+t2*t4)\n deriv(2,12)= -3.0_rp*a *s2*s3*s4*(-t1*t3-t1*t4+t3*t4)\n deriv(2,13)= 9.0_rp*a *s1*s3*s4*(-t1*t3-t1*t4+t3*t4)\n deriv(2,14)= 9.0_rp*a *s1*s2*s4*(-t1*t3-t1*t4+t3*t4)\n deriv(2,15)= 9.0_rp*a *s1*s2*s4*(-t1*t2+t1*t4+t2*t4)\n deriv(2,16)= 9.0_rp*a *s1*s3*s4*(-t1*t2+t1*t4+t2*t4)\n heslo(1, 1) =&\n 2.0_rp*a *t2*t3*t4*(s2-s3-s4)\n heslo(1, 2) =&\n 2.0_rp*a *t2*t3*t4*(-3.0_rp*s1-3.0_rp*s2+3.0_rp*s3)/3.0_rp\n heslo(1, 3) =&\n 2.0_rp*a *t1*t2*t3*(-3.0_rp*s1-3.0_rp*s2+3.0_rp*s3)/3.0_rp\n heslo(1, 4) =&\n 2.0_rp*a *t1*t2*t3*(s2-s3-s4)\n heslo(1, 5) =&\n -2.0_rp*a *t2*t3*t4*(3.0_rp*s1-3.0_rp*s3-3.0_rp*s4)\n heslo(1, 6) =&\n -2.0_rp*a *t2*t3*t4*(-3.0_rp*s1-3.0_rp*s2+3.0_rp*s4)\n heslo(1, 7) =&\n -2.0_rp*a *t1*t3*t4*(-3.0_rp*s1-3.0_rp*s2+3.0_rp*s3)\n heslo(1, 8) =&\n -2.0_rp*a *t1*t2*t4*(-3.0_rp*s1-3.0_rp*s2+3.0_rp*s3)\n heslo(1, 9) =&\n -2.0_rp*a *t1*t2*t3*(-3.0_rp*s1-3.0_rp*s2+3.0_rp*s4)\n heslo(1,10) =&\n -2.0_rp*a *t1*t2*t3*(3.0_rp*s1-3.0_rp*s3-3.0_rp*s4)\n heslo(1,11) =&\n -6.0_rp*a *t1*t2*t4*(s2-s3-s4)\n heslo(1,12) =&\n -6.0_rp*a *t1*t3*t4*(s2-s3-s4)\n heslo(1,13) =&\n 6.0_rp*a *t1*t3*t4*(3.0_rp*s1-3.0_rp*s3-3.0_rp*s4)\n heslo(1,14) =&\n 6.0_rp*a *t1*t3*t4*(-3.0_rp*s1-3.0_rp*s2+3.0_rp*s4)\n heslo(1,15) =&\n 6.0_rp*a *t1*t2*t4*(-3.0_rp*s1-3.0_rp*s2+3.0_rp*s4)\n heslo(1,16) =&\n 6.0_rp*a *t1*t2*t4*(3.0_rp*s1-3.0_rp*s3-3.0_rp*s4)\n heslo(2, 1) =&\n 2.0_rp*a *s2*s3*s4*(t2-t3-t4)\n heslo(2, 2) =&\n 2.0_rp*a *s1*s2*s3*(t2-t3-t4)\n heslo(2, 3) =&\n 2.0_rp*a *s1*s2*s3*(-3.0_rp*t1-3.0_rp*t2+3.0_rp*t3)/3.0_rp\n heslo(2, 4) =&\n 2.0_rp*a *s2*s3*s4*(-3.0_rp*t1-3.0_rp*t2+3.0_rp*t3)/3.0_rp\n heslo(2, 5) =&\n -6.0_rp*a *s1*s3*s4*(t2-t3-t4)\n heslo(2, 6) =&\n -6.0_rp*a *s1*s2*s4*(t2-t3-t4)\n heslo(2, 7) =&\n -2.0_rp*a *s1*s2*s3*(3.0_rp*t1-3.0_rp*t3-3.0_rp*t4)\n heslo(2, 8) =&\n -2.0_rp*a *s1*s2*s3*(-3.0_rp*t1-3.0_rp*t2+3.0_rp*t4)\n heslo(2, 9) =&\n -2.0_rp*a *s1*s2*s4*(-3.0_rp*t1-3.0_rp*t2+3.0_rp*t3)\n heslo(2,10) =&\n -2.0_rp*a *s1*s3*s4*(-3.0_rp*t1-3.0_rp*t2+3.0_rp*t3)\n heslo(2,11) =&\n -2.0_rp*a *s2*s3*s4*(-3.0_rp*t1-3.0_rp*t2+3.0_rp*t4)\n heslo(2,12) =&\n -2.0_rp*a *s2*s3*s4*(3.0_rp*t1-3.0_rp*t3-3.0_rp*t4)\n heslo(2,13) =&\n 6.0_rp*a *s1*s3*s4*(3.0_rp*t1-3.0_rp*t3-3.0_rp*t4)\n heslo(2,14) =&\n 6.0_rp*a *s1*s2*s4*(3.0_rp*t1-3.0_rp*t3-3.0_rp*t4)\n heslo(2,15) =&\n 6.0_rp*a *s1*s2*s4*(-3.0_rp*t1-3.0_rp*t2+3.0_rp*t4)\n heslo(2,16) =&\n 6.0_rp*a *s1*s3*s4*(-3.0_rp*t1-3.0_rp*t2+3.0_rp*t4)\n heslo(3, 1) =&\n a*(-3.0_rp*s2*s3-3.0_rp*s2*s4+3.0_rp*s3*s4)*(-3.0_rp*t2*t3-3.0_rp*t2*t4+3.0_rp*t3*t4)/9.0_rp\n heslo(3, 2) =&\n a*(-3.0_rp*s1*s2+3.0_rp*s1*s3+3.0_rp*s2*s3)*(-3.0_rp*t2*t3-3.0_rp*t2*t4+3.0_rp*t3*t4)/9.0_rp \n heslo(3, 3) =&\n a*(-3.0_rp*s1*s2+3.0_rp*s1*s3+3.0_rp*s2*s3)*(-3.0_rp*t1*t2+3.0_rp*t1*t3+3.0_rp*t2*t3)/9.0_rp\n heslo(3, 4) =&\n a*(-3.0_rp*s2*s3-3.0_rp*s2*s4+3.0_rp*s3*s4)*(-3.0_rp*t1*t2+3.0_rp*t1*t3+3.0_rp*t2*t3)/9.0_rp\n heslo(3, 5) =&\n -a*(-9.0_rp*s1*s3-9.0_rp*s1*s4+9.0_rp*s3*s4)*(-3.0_rp*t2*t3-3.0_rp*t2*t4+3.0_rp*t3*t4)/9.0_rp\n heslo(3, 6) =&\n -a*(-3.0_rp*s1*s2+3.0_rp*s1*s4+3.0_rp*s2*s4)*(-3.0_rp*t2*t3-3.0_rp*t2*t4+3.0_rp*t3*t4)/3.0_rp\n heslo(3, 7) =&\n -3.0_rp*a*(-s1*s2+s1*s3+s2*s3)*(-t1*t3-t1*t4+t3*t4)\n heslo(3, 8) =&\n -3.0_rp*a*(-s1*s2+s1*s3+s2*s3)*(-t1*t2+t1*t4+t2*t4)\n heslo(3, 9) =&\n -a*(-3.0_rp*s1*s2+3.0_rp*s1*s4+3.0_rp*s2*s4)*(-3.0_rp*t1*t2+3.0_rp*t1*t3+3.0_rp*t2*t3)/3.0_rp\n heslo(3,10) =&\n -a*(-9.0_rp*s1*s3-9.0_rp*s1*s4+9.0_rp*s3*s4)*(-3.0_rp*t1*t2+3.0_rp*t1*t3+3.0_rp*t2*t3)/9.0_rp\n heslo(3,11) =&\n -3.0_rp*a*(-3.0_rp*s2*s3-3.0_rp*s2*s4+3.0_rp*s3*s4)*(-t1*t2+t1*t4+t2*t4)/3.0_rp\n heslo(3,12) =&\n -3.0_rp*a*(-s2*s3-s2*s4+s3*s4)*(-t1*t3-t1*t4+t3*t4)\n heslo(3,13) =&\n 9.0_rp*a*(-s1*s3-s1*s4+s3*s4)*(-t1*t3-t1*t4+t3*t4)\n heslo(3,14) =&\n 9.0_rp*a*(-s1*s2+s1*s4+s2*s4)*(-t1*t3-t1*t4+t3*t4)\n heslo(3,15) =&\n 9.0_rp*a*(-s1*s2+s1*s4+s2*s4)*(-t1*t2+t1*t4+t2*t4)\n heslo(3,16) =&\n 9.0_rp*a*(-s1*s3-s1*s4+s3*s4)*(-t1*t2+t1*t4+t2*t4)\n\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * Valores calculados para tri\u00e1ngulos nnode=15. Elemento p4_modificado con posici\u00f3n de nodos para obtener * \n! * una cuadratura cerrada exacta hasta un polinomio de quinto grado. *\n! * Ver la posici\u00f3n de nodos interiores en Regla cerrada para ngaus==15, p5 exacto del archivo rutope.f90 * \n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \n\n else if(nnode==15) then\n\n shape( 1)= 1.0_rp+(-25.0_rp/3.0_rp)*s+(-25.0_rp/3.0_rp)*t&\n +(70.0_rp/3)*s*s+(70.0_rp/3)*t*t+(55.0_rp*sqrt(7.0_rp)+1890.0_rp)/42.0_rp*s*t&\n +(-80.0_rp/3)*s*s*s+(-80.0_rp/3)*t*t*t-(22.0_rp*sqrt(7.0_rp)+525.0_rp)/7.0_rp*s*s*t&\n -(22.0_rp*sqrt(7.0_rp)+525.0_rp)/7.0_rp*s*t*t+(32.0_rp/3)*s*s*s*s+(32.0_rp/3)*t*t*t*t&\n +(11.0_rp*sqrt(7.0_rp)+236.0_rp)/6.0_rp*s*s*s*t+(11.0_rp*sqrt(7.0_rp)+236.0_rp)/6.0_rp*s*t*t*t&\n +(11.0_rp*sqrt(7.0_rp)+172.0_rp)/3.0_rp*s*s*t*t\n shape( 2)= -s+22.0_rp/3.0_rp*s*s-(11.0_rp*sqrt(7.0_rp)-35.0_rp)/21.0_rp*s*t-16.0_rp*s*s*s&\n +(33.0_rp*sqrt(7.0_rp)-70.0_rp)/14.0_rp*s*s*t+(11.0_rp*sqrt(7.0_rp)-35.0_rp)/21.0_rp*s*t*t&\n +32.0_rp/3.0_rp*s*s*s*s-(11.0_rp*sqrt(7.0_rp)-20.0_rp)/6.0_rp*s*s*s*t&\n -(11.0_rp*sqrt(7.0_rp)-20.0_rp)/6.0_rp*s*s*t*t\n shape( 3)= -t+22.0_rp/3.0_rp*t*t-(11.0_rp*sqrt(7.0_rp)-35.0_rp)/21.0_rp*s*t-16.0_rp*t*t*t&\n +(11.0_rp*sqrt(7.0_rp)-35.0_rp)/21.0_rp*s*s*t+(33.0_rp*sqrt(7.0_rp)-70.0_rp)/14.0_rp*s*t*t&\n +32.0_rp/3.0_rp*t*t*t*t-(11.0_rp*sqrt(7.0_rp)-20.0_rp)/6.0_rp*s*t*t*t&\n -(11.0_rp*sqrt(7.0_rp)-20.0_rp)/6.0_rp*s*s*t*t\n shape( 4)= 16.0_rp*s-208.0_rp/3.0_rp*s*s-(104.0_rp*sqrt(7.0_rp)+1400.0_rp)/21.0_rp*s*t&\n +96.0_rp*s*s*s+(72.0_rp*sqrt(7.0_rp)+1288.0_rp)/7.0_rp*s*s*t+(272.0_rp*sqrt(7.0_rp)+1792.0_rp)/21.0_rp*s*t*t&\n -128.0_rp/3.0_rp*s*s*s*s-(16.0_rp*sqrt(7.0_rp)+368.0_rp)/3.0_rp*s*s*s*t&\n -(24.0_rp*sqrt(7.0_rp)+104.0_rp)/3.0_rp*s*t*t*t-(40.0_rp*sqrt(7.0_rp)+344.0_rp)/3.0_rp*s*s*t*t\n shape( 5)= -12.0_rp*s+76.0_rp*s*s+(66.0_rp*sqrt(7.0_rp)+70.0_rp)/7.0_rp*s*t-128.0_rp*s*s*s&\n -(66.0_rp*sqrt(7.0_rp)+882.0_rp)/7.0_rp*s*s*t-(220.0_rp*sqrt(7.0_rp)-336.0_rp)/7.0_rp*s*t*t&\n +64.0_rp*s*s*s*s+128.0_rp*s*s*s*t+(22.0_rp*sqrt(7.0_rp)-46.0_rp)*s*t*t*t+(22.0_rp*sqrt(7.0_rp)+18.0_rp)*s*s*t*t\n shape( 6)= 16.0_rp/3.0_rp*s-112.0_rp/3.0_rp*s*s+(8.0_rp*sqrt(7.0_rp)-168.0_rp)/21.0_rp*s*t&\n +224.0_rp/3.0_rp*s*s*s-(40.0_rp*sqrt(7.0_rp)-280.0_rp)/7.0_rp*s*s*t&\n +16.0_rp*sqrt(7.0_rp)/7.0_rp*s*t*t-128.0_rp/3.0_rp*s*s*s*s+(16.0_rp*sqrt(7.0_rp)-144.0_rp)/3.0_rp*s*s*s*t&\n -(8.0_rp*sqrt(7.0_rp)-8.0_rp)/3.0_rp*s*t*t*t+(8.0_rp*sqrt(7.0_rp)-8.0_rp)/3.0_rp*s*s*t*t\n shape( 7)= (64.0_rp*sqrt(7.0_rp))/21.0_rp*s*t -(232.0_rp*sqrt(7.0_rp)+392.0_rp)/21.0_rp*s*s*t&\n - (40.0_rp*sqrt(7.0_rp)-56.0_rp)/7.0_rp*s*t*t + (24.0_rp*sqrt(7.0_rp)+104.0_rp)/3.0_rp*s*s*s*t&\n + (8.0_rp*sqrt(7.0_rp)-8.0_rp)/3.0_rp*s*t*t*t+(32.0_rp*sqrt(7.0_rp)-32.0_rp)/3.0_rp*s*s*t*t\n shape( 8)=-(88.0_rp*sqrt(7.0_rp)-224.0_rp)/7.0_rp*s*t + (242.0_rp*sqrt(7.0_rp)-630.0_rp)/7.0_rp*s*s*t&\n + (242.0_rp*sqrt(7.0_rp)-630.0_rp)/7.0_rp*s*t*t + (46.0_rp-22.0_rp*sqrt(7.0_rp))*s*s*s*t&\n + (46.0_rp-22.0_rp*sqrt(7.0_rp))*s*t*t*t + (156.0_rp-44.0_rp*sqrt(7.0_rp))*s*s*t*t \n shape( 9)= +(64.0_rp*sqrt(7.0_rp))/21.0_rp*s*t - (40.0_rp*sqrt(7.0_rp)-56.0_rp)/7.0_rp*s*s*t&\n -(232.0_rp*sqrt(7.0_rp)+392.0_rp)/21.0_rp*s*t*t + (8.0_rp*sqrt(7.0_rp)-8.0_rp)/3.0_rp*s*s*s*t&\n +(24.0_rp*sqrt(7.0_rp)+104.0_rp)/3.0_rp*s*t*t*t+(32.0_rp*sqrt(7.0_rp)-32.0_rp)/3.0_rp*s*s*t*t\n shape(10)= 16.0_rp/3.0_rp*t-112.0_rp/3.0_rp*t*t+(8.0_rp*sqrt(7.0_rp)-168.0_rp)/21.0_rp*s*t&\n +224.0_rp/3.0_rp*t*t*t+16.0_rp*sqrt(7.0_rp)/7.0_rp*s*s*t-(40.0_rp*sqrt(7.0_rp)-280.0_rp)/7.0_rp*s*t*t&\n -128.0_rp/3.0_rp*t*t*t*t-(8.0_rp*sqrt(7.0_rp)-8.0_rp)/3.0_rp*s*s*s*t&\n +(16.0_rp*sqrt(7.0_rp)-144.0_rp)/3.0_rp*s*t*t*t+(8.0_rp*sqrt(7.0_rp)-8.0_rp)/3.0_rp*s*s*t*t\n shape(11)= -12.0_rp*t+76.0_rp*t*t+(66.0_rp*sqrt(7.0_rp)+70.0_rp)/7.0_rp*s*t-128.0_rp*t*t*t&\n -(220.0_rp*sqrt(7.0_rp)-336.0_rp)/7.0_rp*s*s*t-(66.0_rp*sqrt(7.0_rp)+882.0_rp)/7.0_rp*s*t*t&\n +64.0_rp*t*t*t*t+(22.0_rp*sqrt(7.0_rp)-46)*s*s*s*t+128.0_rp*s*t*t*t+(22.0_rp*sqrt(7.0_rp)+18.0_rp)*s*s*t*t\n shape(12)= 16.0_rp*t-208.0_rp/3.0_rp*t*t-(104.0_rp*sqrt(7.0_rp)+1400.0_rp)/21.0_rp*s*t+96.0_rp*t*t*t&\n +(272.0_rp*sqrt(7.0_rp)+1792.0_rp)/21.0_rp*s*s*t+(72.0_rp*sqrt(7.0_rp)+1288.0_rp)/7.0_rp*s*t*t&\n -128.0_rp/3.0_rp*t*t*t*t-(24.0_rp*sqrt(7.0_rp)+104.0_rp)/3.0_rp*s*s*s*t&\n -(16.0_rp*sqrt(7.0_rp)+368.0_rp)/3.0_rp*s*t*t*t-(40.0_rp*sqrt(7.0_rp)+344.0_rp)/3.0_rp*s*s*t*t\n shape(13)= (9.0_rp*sqrt(7.0_rp**3))/2.0_rp*s*t - (23.0_rp*sqrt(7.0_rp**3)-49.0_rp)/2.0_rp*s*s*t&\n -(23.0_rp*sqrt(7.0_rp**3)-49.0_rp)/2.0_rp*s*t*t+(2.0_rp*sqrt(7.0_rp**5)-49.0_rp)/2.0_rp*s*s*s*t&\n +(2.0_rp*sqrt(7.0_rp**5)-49.0_rp)/2.0_rp*s*t*t*t+(2.0_rp*sqrt(7.0_rp**5)-49.0_rp)*s*s*t*t\n shape(14)=-(5.0_rp*sqrt(7.0_rp**3)-49.0_rp)/2.0_rp*s*t + (19.0_rp*sqrt(7.0_rp**3)-98.0_rp)/2.0_rp*s*s*t&\n +(5.0_rp*sqrt(7.0_rp**3)-49.0_rp)/2.0_rp*s*t*t - (2.0_rp*sqrt(7.0_rp**5)-49.0_rp)/2.0_rp*s*s*s*t&\n -(2.0_rp*sqrt(7.0_rp**5)-49.0_rp)/2.0_rp*s*s*t*t\n shape(15)=-(5.0_rp*sqrt(7.0_rp**3)-49.0_rp)/2.0_rp*s*t + (5.0_rp*sqrt(7.0_rp**3)-49.0_rp)/2.0_rp*s*s*t&\n +(19.0_rp*sqrt(7.0_rp**3)-98.0_rp)/2.0_rp*s*t*t - (2.0_rp*sqrt(7.0_rp**5)-49.0_rp)/2.0_rp*s*s*t*t&\n -(2.0_rp*sqrt(7.0_rp**5)-49.0_rp)/2.0_rp*s*t*t*t\n\n deriv(1, 1)= -8.3333333334921917_rp+2*( 23.3333333342179685_rp)*s+( 48.4646743398957369_rp)*t&\n +3*( -26.6666666681470019_rp)*s*s+2*( -83.3152184149769255_rp)*s*t+( -83.3152184151310848_rp)*t*t&\n +4*( 10.6666666674143897_rp)*s*s*s+3*( 44.1838774082058023_rp)*s*s*t+2*( 67.0344214842568249_rp)*s*t*t&\n +( 44.1838774082991677_rp)*t*t*t\n deriv(1, 2)= -0.9999999999974740_rp+2*( 7.3333333333189632_rp)*s+( 0.2807969323081281_rp)*t&\n +3*( -15.9999999999762199_rp)*s*s+2*( 1.2364138045634334_rp)*s*t+( -0.2807969322706239_rp)*t*t&\n +4*( 10.6666666666547059_rp)*s*s*s+3*( -1.5172107368690897_rp)*s*s*t+2*( -1.5172107369162715_rp)*s*t*t&\n +( -0.0000000000342917_rp)*t*t*t\n deriv(1, 3)= 0.0000000000009095_rp+2*( -0.0000000000048423_rp)*s+( 0.2807969323084976_rp)*t&\n +3*( 0.0000000000081046_rp)*s*s+2*( -0.2807969322737502_rp)*s*t+( 1.2364138045616002_rp)*t*t&\n +4*( -0.0000000000040843_rp)*s*s*s+3*( -0.0000000000324771_rp)*s*s*t+2*( -1.5172107369120971_rp)*s*t*t&\n +( -1.5172107368673551_rp)*t*t*t\n deriv(1, 4)= 16.0000000003747118_rp+2*( -69.3333333354410115_rp)*s+( -79.7694350723932075_rp)*t&\n +3*( 96.0000000035275320_rp)*s*s+2*( 211.2134420756940472_rp)*s*t+( 119.6021122364136318_rp)*t*t&\n +4*( -42.6666666684495084_rp)*s*s*s+3*(-136.7773403361930775_rp)*s*s*t+2*(-149.9433508352551598_rp)*s*t*t&\n +( -55.8326771634506258_rp)*t*t*t\n deriv(1, 5)= -12.0000000002560228_rp+2*( 76.0000000014252919_rp)*s+( 34.9456552233868933_rp)*t&\n +3*(-128.0000000023889015_rp)*s*s+2*(-150.9456552308158734_rp)*s*t+( -35.1521840712055109_rp)*t*t&\n +4*( 64.0000000012041710_rp)*s*s*s+3*( 128.0000000071673867_rp)*s*s*t+2*( 76.2065288559824694_rp)*s*t*t&\n +( 12.2065288474843783_rp)*t*t*t\n deriv(1, 6)= 5.3333333333723658_rp+2*( -37.3333333335594801_rp)*s+( -6.9920947394621180_rp)*t&\n +3*( 74.6666666670428043_rp)*s*s+2*( 24.8814210820214541_rp)*s*t+( 6.0474315694772400_rp)*t*t&\n +4*( -42.6666666668577079_rp)*s*s*s+3*( -33.8893263425222955_rp)*s*s*t+2*( 4.3886701606570888_rp)*s*t*t&\n +( -4.3886701633013701_rp)*t*t*t\n deriv(1, 7)= -0.0000000000853788_rp+2*( 0.0000000004719141_rp)*s+( 8.0632420921942867_rp)*t&\n +3*( -0.0000000007879990_rp)*s*s+2*( -47.8959192493797872_rp)*s*t+( -7.1185789229376155_rp)*t*t&\n +4*( 0.0000000003987015_rp)*s*s*s+3*( 55.8326771571037881_rp)*s*s*t+2*( 17.5546806548235281_rp)*s*t*t&\n +( 4.3886701639723640_rp)*t*t*t\n deriv(1, 8)= -0.0000000000146656_rp+2*( 0.0000000000808882_rp)*s+( -1.2608736244689567_rp)*t&\n +3*( -0.0000000001355609_rp)*s*s+2*( 1.4674024674377790_rp)*s*t+( 1.4674024674318957_rp)*t*t&\n +4*( 0.0000000000681117_rp)*s*s*s+3*( -12.2065288429870833_rp)*s*s*t+2*( 39.5869423141255865_rp)*s*t*t&\n +( -12.2065288429873533_rp)*t*t*t\n deriv(1, 9)= -0.0000000000309228_rp+2*( 0.0000000001664375_rp)*s+( 8.0632420922024721_rp)*t&\n +3*( -0.0000000002787885_rp)*s*s+2*( -7.1185789229073748_rp)*s*t+( -47.8959192494714898_rp)*t*t&\n +4*( 0.0000000001408225_rp)*s*s*s+3*( 4.3886701639702750_rp)*s*s*t+2*( 17.5546806548536551_rp)*s*t*t&\n +( 55.8326771571770450_rp)*t*t*t\n deriv(1,10)= 0.0000000000113687_rp+2*( -0.0000000000623004_rp)*s+( -6.9920947394698487_rp)*t&\n +3*( 0.0000000001044782_rp)*s*s+2*( 6.0474315694737584_rp)*s*t+( 24.8814210820885933_rp)*t*t&\n +4*( -0.0000000000528626_rp)*s*s*s+3*( -4.3886701633092073_rp)*s*s*t+2*( 4.3886701606180765_rp)*s*t*t&\n +( -33.8893263425786131_rp)*t*t*t\n deriv(1,11)= -0.0000000001164153_rp+2*( 0.0000000006548362_rp)*s+( 34.9456552234114497_rp)*t&\n +3*( -0.0000000010986128_rp)*s*s+2*( -35.1521840711213827_rp)*s*t+(-150.9456552311207815_rp)*t*t&\n +4*( 0.0000000005536549_rp)*s*s*s+3*( 12.2065288474785518_rp)*s*s*t+2*( 76.2065288561027501_rp)*s*t*t&\n +( 128.0000000074010131_rp)*t*t*t\n deriv(1,12)= 0.0000000002710294_rp+2*( -0.0000000015311343_rp)*s+( -79.7694350724123069_rp)*t&\n +3*( 0.0000000025710278_rp)*s*s+2*( 119.6021122361757989_rp)*s*t+( 211.2134420760958164_rp)*t*t&\n +4*( -0.0000000012939552_rp)*s*s*s+3*( -55.8326771633475119_rp)*s*s*t+2*(-149.9433508353474735_rp)*s*t*t&\n +(-136.7773403364694786_rp)*t*t*t\n deriv(1,13)= -0.0000000003819878_rp+2*( 0.0000000021809683_rp)*s+( 83.3411663078350102_rp)*t&\n +3*( -0.0000000036493475_rp)*s*s+2*(-188.4829805611818756_rp)*s*t+(-188.4829805615527221_rp)*t*t&\n +4*( 0.0000000018402773_rp)*s*s*s+3*( 105.1418142528370367_rp)*s*s*t+2*( 210.2836285085713826_rp)*s*t*t&\n +( 105.1418142530505975_rp)*t*t*t\n deriv(1,14)= 0.0000000002305569_rp+2*( -0.0000000013075123_rp)*s+( -21.8006479476589448_rp)*t&\n +3*( 0.0000000021808262_rp)*s*s+2*( 126.9424621956307533_rp)*s*t+( 21.8006479517496246_rp)*t*t&\n +4*( -0.0000000011054730_rp)*s*s*s+3*(-105.1418142477331941_rp)*s*s*t+2*(-105.1418142527448367_rp)*s*t*t&\n +( -0.0000000037839527_rp)*t*t*t\n deriv(1,15)= 0.0000000001082299_rp+2*( -0.0000000006107257_rp)*s+( -21.8006479476762252_rp)*t&\n +3*( 0.0000000010202257_rp)*s*s+2*( 21.8006479516582203_rp)*s*t+( 126.9424621958696662_rp)*t*t&\n +4*( -0.0000000005163372_rp)*s*s*s+3*( -0.0000000037693724_rp)*s*s*t+2*(-105.1418142528167436_rp)*s*t*t&\n +(-105.1418142479110429_rp)*t*t*t\n\n deriv(2, 1)= -8.3333333334921917_rp+2*( 23.3333333342488913_rp)*t+( 48.4646743398957369_rp)*s&\n +3*( -26.6666666681967399_rp)*t*t+( -83.3152184149769255_rp)*s*s+2*( -83.3152184151310848_rp)*s*t&\n +4*( 10.6666666674386761_rp)*t*t*t+( 44.1838774082058023_rp)*s*s*s+2*( 67.0344214842568249_rp)*s*s*t&\n +3*( 44.1838774082991677_rp)*s*t*t\n deriv(2, 2)= 0.0000000000008811_rp+2*( -0.0000000000051514_rp)*t+( 0.2807969323081281_rp)*s&\n +3*( 0.0000000000085656_rp)*t*t+( 1.2364138045634334_rp)*s*s+2*( -0.2807969322706239_rp)*s*t&\n +4*( -0.0000000000043308_rp)*t*t*t+( -1.5172107368690897_rp)*s*s*s+2*( -1.5172107369162715_rp)*s*s*t&\n +3*( -0.0000000000342917_rp)*s*t*t\n deriv(2, 3)= -0.9999999999976126_rp+2*( 7.3333333333196151_rp)*t+( 0.2807969323084976_rp)*s&\n +3*( -15.9999999999765521_rp)*t*t+( -0.2807969322737502_rp)*s*s+2*( 1.2364138045616002_rp)*s*t&\n +4*( 10.6666666666549830_rp)*t*t*t+( -0.0000000000324771_rp)*s*s*s+2*( -1.5172107369120971_rp)*s*s*t&\n +3*( -1.5172107368673551_rp)*s*t*t\n deriv(2, 4)= 0.0000000002874003_rp+2*( -0.0000000015916157_rp)*t+( -79.7694350723932075_rp)*s&\n +3*( 0.0000000026575435_rp)*t*t+( 211.2134420756940472_rp)*s*s+2*( 119.6021122364136318_rp)*s*t&\n +4*( -0.0000000013415047_rp)*t*t*t+(-136.7773403361930775_rp)*s*s*s+2*(-149.9433508352551598_rp)*s*s*t&\n +3*( -55.8326771634506258_rp)*s*t*t\n deriv(2, 5)= -0.0000000001236913_rp+2*( 0.0000000006839400_rp)*t+( 34.9456552233868933_rp)*s&\n +3*( -0.0000000011459633_rp)*t*t+(-150.9456552308158734_rp)*s*s+2*( -35.1521840712055109_rp)*s*t&\n +4*( 0.0000000005770744_rp)*t*t*t+( 128.0000000071673867_rp)*s*s*s+2*( 76.2065288559824694_rp)*s*s*t&\n +3*( 12.2065288474843783_rp)*s*t*t\n deriv(2, 6)= 0.0000000000118234_rp+2*( -0.0000000000662794_rp)*t+( -6.9920947394621180_rp)*s&\n +3*( 0.0000000001102194_rp)*t*t+( 24.8814210820214541_rp)*s*s+2*( 6.0474315694772400_rp)*s*t&\n +4*( -0.0000000000557918_rp)*t*t*t+( -33.8893263425222955_rp)*s*s*s+2*( 4.3886701606570888_rp)*s*s*t&\n +3*( -4.3886701633013701_rp)*s*t*t\n deriv(2, 7)= -0.0000000000313776_rp+2*( 0.0000000001753051_rp)*t+( 8.0632420921942867_rp)*s&\n +3*( -0.0000000002929710_rp)*t*t+( -47.8959192493797872_rp)*s*s+2*( -7.1185789229376155_rp)*s*t&\n +4*( 0.0000000001480203_rp)*t*t*t+( 55.8326771571037881_rp)*s*s*s+2*( 17.5546806548235281_rp)*s*s*t&\n +3*( 4.3886701639723640_rp)*s*t*t\n deriv(2, 8)= -0.0000000000147793_rp+2*( 0.0000000000837872_rp)*t+( -1.2608736244689567_rp)*s&\n +3*( -0.0000000001402896_rp)*t*t+( 1.4674024674377790_rp)*s*s+2*( 1.4674024674318957_rp)*s*t&\n +4*( 0.0000000000704858_rp)*t*t*t+( -12.2065288429870833_rp)*s*s*s+2*( 39.5869423141255865_rp)*s*s*t&\n +3*( -12.2065288429873533_rp)*s*t*t\n deriv(2, 9)= -0.0000000000836735_rp+2*( 0.0000000004856702_rp)*t+( 8.0632420922024721_rp)*s&\n +3*( -0.0000000008099050_rp)*t*t+( -7.1185789229073748_rp)*s*s+2*( -47.8959192494714898_rp)*s*t&\n +4*( 0.0000000004104095_rp)*t*t*t+( 4.3886701639702750_rp)*s*s*s+2*( 17.5546806548536551_rp)*s*s*t&\n +3*( 55.8326771571770450_rp)*s*t*t\n deriv(2,10)= 5.3333333333748669_rp+2*( -37.3333333335672251_rp)*t+( -6.9920947394698487_rp)*s&\n +3*( 74.6666666670587347_rp)*t*t+( 6.0474315694737584_rp)*s*s+2*( 24.8814210820885933_rp)*s*t&\n +4*( -42.6666666668641028_rp)*t*t*t+( -4.3886701633092073_rp)*s*s*s+2*( 4.3886701606180765_rp)*s*s*t&\n +3*( -33.8893263425786131_rp)*s*t*t\n deriv(2,11)= -12.0000000002619345_rp+2*( 76.0000000014715624_rp)*t+( 34.9456552234114497_rp)*s&\n +3*(-128.0000000024665496_rp)*t*t+( -35.1521840711213827_rp)*s*s+2*(-150.9456552311207815_rp)*s*t&\n +4*( 64.0000000012423698_rp)*t*t*t+( 12.2065288474785518_rp)*s*s*s+2*( 76.2065288561027501_rp)*s*s*t&\n +3*( 128.0000000074010131_rp)*s*t*t\n deriv(2,12)= 16.0000000003929017_rp+2*( -69.3333333355112700_rp)*t+( -79.7694350724123069_rp)*s&\n +3*( 96.0000000036416168_rp)*t*t+( 119.6021122361757989_rp)*s*s+2*( 211.2134420760958164_rp)*s*t&\n +4*( -42.6666666685041491_rp)*t*t*t+( -55.8326771633475119_rp)*s*s*s+2*(-149.9433508353474735_rp)*s*s*t&\n +3*(-136.7773403364694786_rp)*s*t*t\n deriv(2,13)= -0.0000000004001777_rp+2*( 0.0000000022519089_rp)*t+( 83.3411663078350102_rp)*s&\n +3*( -0.0000000037653081_rp)*t*t+(-188.4829805611818756_rp)*s*s+2*(-188.4829805615527221_rp)*s*t&\n +4*( 0.0000000019017534_rp)*t*t*t+( 105.1418142528370367_rp)*s*s*s+2*( 210.2836285085713826_rp)*s*s*t&\n +3*( 105.1418142530505975_rp)*s*t*t\n deriv(2,14)= 0.0000000001127773_rp+2*( -0.0000000006393748_rp)*t+( -21.8006479476589448_rp)*s&\n +3*( 0.0000000010663825_rp)*t*t+( 126.9424621956307533_rp)*s*s+2*( 21.8006479517496246_rp)*s*t&\n +4*( -0.0000000005381935_rp)*t*t*t+(-105.1418142477331941_rp)*s*s*s+2*(-105.1418142527448367_rp)*s*s*t&\n +3*( -0.0000000037839527_rp)*s*t*t\n deriv(2,15)= 0.0000000002401066_rp+2*( -0.0000000013442332_rp)*t+( -21.8006479476762252_rp)*s&\n +3*( 0.0000000022464519_rp)*t*t+( 21.8006479516582203_rp)*s*s+2*( 126.9424621958696662_rp)*s*t&\n +4*( -0.0000000011341399_rp)*t*t*t+( -0.0000000037693724_rp)*s*s*s+2*(-105.1418142528167436_rp)*s*s*t&\n +3*(-105.1418142479110429_rp)*s*t*t\n\n heslo(1, 1)= 2*( 23.3333333342179685_rp)+6*( -26.6666666681470019_rp)*s+2*( -83.3152184149769255_rp)*t&\n +12*( 10.6666666674143897_rp)*s*s+6*( 44.1838774082058023_rp)*s*t+2*( 67.0344214842568249_rp)*t*t\n heslo(1, 2)= 2*( 7.3333333333189632_rp)+6*( -15.9999999999762199_rp)*s+2*( 1.2364138045634334_rp)*t&\n +12*( 10.6666666666547059_rp)*s*s+6*( -1.5172107368690897_rp)*s*t+2*( -1.5172107369162715_rp)*t*t\n heslo(1, 3)= 2*( -0.0000000000048423_rp)+6*( 0.0000000000081046_rp)*s+2*( -0.2807969322737502_rp)*t&\n +12*( -0.0000000000040843_rp)*s*s+6*( -0.0000000000324771_rp)*s*t+2*( -1.5172107369120971_rp)*t*t\n heslo(1, 4)= 2*( -69.3333333354410115_rp)+6*( 96.0000000035275320_rp)*s+2*( 211.2134420756940472_rp)*t&\n +12*( -42.6666666684495084_rp)*s*s+6*(-136.7773403361930775_rp)*s*t+2*(-149.9433508352551598_rp)*t*t\n heslo(1, 5)= 2*( 76.0000000014252919_rp)+6*(-128.0000000023889015_rp)*s+2*(-150.9456552308158734_rp)*t&\n +12*( 64.0000000012041710_rp)*s*s+6*( 128.0000000071673867_rp)*s*t+2*( 76.2065288559824694_rp)*t*t\n heslo(1, 6)= 2*( -37.3333333335594801_rp)+6*( 74.6666666670428043_rp)*s+2*( 24.8814210820214541_rp)*t&\n +12*( -42.6666666668577079_rp)*s*s+6*( -33.8893263425222955_rp)*s*t+2*( 4.3886701606570888_rp)*t*t\n heslo(1, 7)= 2*( 0.0000000004719141_rp)+6*( -0.0000000007879990_rp)*s+2*( -47.8959192493797872_rp)*t&\n +12*( 0.0000000003987015_rp)*s*s+6*( 55.8326771571037881_rp)*s*t+2*( 17.5546806548235281_rp)*t*t\n heslo(1, 8)= 2*( 0.0000000000808882_rp)+6*( -0.0000000001355609_rp)*s+2*( 1.4674024674377790_rp)*t&\n +12*( 0.0000000000681117_rp)*s*s+6*( -12.2065288429870833_rp)*s*t+2*( 39.5869423141255865_rp)*t*t\n heslo(1, 9)= 2*( 0.0000000001664375_rp)+6*( -0.0000000002787885_rp)*s+2*( -7.1185789229073748_rp)*t&\n +12*( 0.0000000001408225_rp)*s*s+6*( 4.3886701639702750_rp)*s*t+2*( 17.5546806548536551_rp)*t*t\n heslo(1,10)= 2*( -0.0000000000623004_rp)+6*( 0.0000000001044782_rp)*s+2*( 6.0474315694737584_rp)*t&\n +12*( -0.0000000000528626_rp)*s*s+6*( -4.3886701633092073_rp)*s*t+2*( 4.3886701606180765_rp)*t*t\n heslo(1,11)= 2*( 0.0000000006548362_rp)+6*( -0.0000000010986128_rp)*s+2*( -35.1521840711213827_rp)*t&\n +12*( 0.0000000005536549_rp)*s*s+6*( 12.2065288474785518_rp)*s*t+2*( 76.2065288561027501_rp)*t*t\n heslo(1,12)= 2*( -0.0000000015311343_rp)+6*( 0.0000000025710278_rp)*s+2*( 119.6021122361757989_rp)*t&\n +12*( -0.0000000012939552_rp)*s*s+6*( -55.8326771633475119_rp)*s*t+2*(-149.9433508353474735_rp)*t*t\n heslo(1,13)= 2*( 0.0000000021809683_rp)+6*( -0.0000000036493475_rp)*s+2*(-188.4829805611818756_rp)*t&\n +12*( 0.0000000018402773_rp)*s*s+6*( 105.1418142528370367_rp)*s*t+2*( 210.2836285085713826_rp)*t*t\n heslo(1,14)= 2*( -0.0000000013075123_rp)+6*( 0.0000000021808262_rp)*s+2*( 126.9424621956307533_rp)*t&\n +12*( -0.0000000011054730_rp)*s*s+6*(-105.1418142477331941_rp)*s*t+2*(-105.1418142527448367_rp)*t*t\n heslo(1,15)= 2*( -0.0000000006107257_rp)+6*( 0.0000000010202257_rp)*s+2*( 21.8006479516582203_rp)*t&\n +12*( -0.0000000005163372_rp)*s*s+6*( -0.0000000037693724_rp)*s*t+2*(-105.1418142528167436_rp)*t*t\n\n heslo(2, 1)= 2*( 23.3333333342488913_rp)+6*( -26.6666666681967399_rp)*t+2*( -83.3152184151310848_rp)*s&\n +12*( 10.6666666674386761_rp)*t*t+2*( 67.0344214842568249_rp)*s*s+6*( 44.1838774082991677_rp)*s*t\n heslo(2, 2)= 2*( -0.0000000000051514_rp)+6*( 0.0000000000085656_rp)*t+2*( -0.2807969322706239_rp)*s&\n +12*( -0.0000000000043308_rp)*t*t+2*( -1.5172107369162715_rp)*s*s+6*( -0.0000000000342917_rp)*s*t\n heslo(2, 3)= 2*( 7.3333333333196151_rp)+6*( -15.9999999999765521_rp)*t+2*( 1.2364138045616002_rp)*s&\n +12*( 10.6666666666549830_rp)*t*t+2*( -1.5172107369120971_rp)*s*s+6*( -1.5172107368673551_rp)*s*t\n heslo(2, 4)= 2*( -0.0000000015916157_rp)+6*( 0.0000000026575435_rp)*t+2*( 119.6021122364136318_rp)*s&\n +12*( -0.0000000013415047_rp)*t*t+2*(-149.9433508352551598_rp)*s*s+6*( -55.8326771634506258_rp)*s*t\n heslo(2, 5)= 2*( 0.0000000006839400_rp)+6*( -0.0000000011459633_rp)*t+2*( -35.1521840712055109_rp)*s&\n +12*( 0.0000000005770744_rp)*t*t+2*( 76.2065288559824694_rp)*s*s+6*( 12.2065288474843783_rp)*s*t\n heslo(2, 6)= 2*( -0.0000000000662794_rp)+6*( 0.0000000001102194_rp)*t+2*( 6.0474315694772400_rp)*s&\n +12*( -0.0000000000557918_rp)*t*t+2*( 4.3886701606570888_rp)*s*s+6*( -4.3886701633013701_rp)*s*t\n heslo(2, 7)= 2*( 0.0000000001753051_rp)+6*( -0.0000000002929710_rp)*t+2*( -7.1185789229376155_rp)*s&\n +12*( 0.0000000001480203_rp)*t*t+2*( 17.5546806548235281_rp)*s*s+6*( 4.3886701639723640_rp)*s*t\n heslo(2, 8)= 2*( 0.0000000000837872_rp)+6*( -0.0000000001402896_rp)*t+2*( 1.4674024674318957_rp)*s&\n +12*( 0.0000000000704858_rp)*t*t+2*( 39.5869423141255865_rp)*s*s+6*( -12.2065288429873533_rp)*s*t\n heslo(2, 9)= 2*( 0.0000000004856702_rp)+6*( -0.0000000008099050_rp)*t+2*( -47.8959192494714898_rp)*s&\n +12*( 0.0000000004104095_rp)*t*t+2*( 17.5546806548536551_rp)*s*s+6*( 55.8326771571770450_rp)*s*t\n heslo(2,10)= 2*( -37.3333333335672251_rp)+6*( 74.6666666670587347_rp)*t+2*( 24.8814210820885933_rp)*s&\n +12*( -42.6666666668641028_rp)*t*t+2*( 4.3886701606180765_rp)*s*s+6*( -33.8893263425786131_rp)*s*t\n heslo(2,11)= 2*( 76.0000000014715624_rp)+6*(-128.0000000024665496_rp)*t+2*(-150.9456552311207815_rp)*s&\n +12*( 64.0000000012423698_rp)*t*t+2*( 76.2065288561027501_rp)*s*s+6*( 128.0000000074010131_rp)*s*t\n heslo(2,12)= 2*( -69.3333333355112700_rp)+6*( 96.0000000036416168_rp)*t+2*( 211.2134420760958164_rp)*s&\n +12*( -42.6666666685041491_rp)*t*t+2*(-149.9433508353474735_rp)*s*s+6*(-136.7773403364694786_rp)*s*t\n heslo(2,13)= 2*( 0.0000000022519089_rp)+6*( -0.0000000037653081_rp)*t+2*(-188.4829805615527221_rp)*s&\n +12*( 0.0000000019017534_rp)*t*t+2*( 210.2836285085713826_rp)*s*s+6*( 105.1418142530505975_rp)*s*t\n heslo(2,14)= 2*( -0.0000000006393748_rp)+6*( 0.0000000010663825_rp)*t+2*( 21.8006479517496246_rp)*s&\n +12*( -0.0000000005381935_rp)*t*t+2*(-105.1418142527448367_rp)*s*s+6*( -0.0000000037839527_rp)*s*t\n heslo(2,15)= 2*( -0.0000000013442332_rp)+6*( 0.0000000022464519_rp)*t+2*( 126.9424621958696662_rp)*s&\n +12*( -0.0000000011341399_rp)*t*t+2*(-105.1418142528167436_rp)*s*s+6*(-105.1418142479110429_rp)*s*t\n\n heslo(3, 1)= 48.4646743398957369_rp+2*( -83.3152184149769255_rp)*s+2*( -83.3152184151310848_rp)*t&\n +3*( 44.1838774082058023_rp)*s*s+4*( 67.0344214842568249_rp)*s*t+3*( 44.1838774082991677_rp)*t*t\n heslo(3, 2)= 0.2807969323081281_rp+2*( 1.2364138045634334_rp)*s+2*( -0.2807969322706239_rp)*t&\n +3*( -1.5172107368690897_rp)*s*s+4*( -1.5172107369162715_rp)*s*t+3*( -0.0000000000342917_rp)*t*t\n heslo(3, 3)= 0.2807969323084976_rp+2*( -0.2807969322737502_rp)*s+2*( 1.2364138045616002_rp)*t&\n +3*( -0.0000000000324771_rp)*s*s+4*( -1.5172107369120971_rp)*s*t+3*( -1.5172107368673551_rp)*t*t\n heslo(3, 4)= -79.7694350723932075_rp+2*( 211.2134420756940472_rp)*s+2*( 119.6021122364136318_rp)*t&\n +3*(-136.7773403361930775_rp)*s*s+4*(-149.9433508352551598_rp)*s*t+3*( -55.8326771634506258_rp)*t*t\n heslo(3, 5)= 34.9456552233868933_rp+2*(-150.9456552308158734_rp)*s+2*( -35.1521840712055109_rp)*t&\n +3*( 128.0000000071673867_rp)*s*s+4*( 76.2065288559824694_rp)*s*t+3*( 12.2065288474843783_rp)*t*t\n heslo(3, 6)= -6.9920947394621180_rp+2*( 24.8814210820214541_rp)*s+2*( 6.0474315694772400_rp)*t&\n +3*( -33.8893263425222955_rp)*s*s+4*( 4.3886701606570888_rp)*s*t+3*( -4.3886701633013701_rp)*t*t\n heslo(3, 7)= 8.0632420921942867_rp+2*( -47.8959192493797872_rp)*s+2*( -7.1185789229376155_rp)*t&\n +3*( 55.8326771571037881_rp)*s*s+4*( 17.5546806548235281_rp)*s*t+3*( 4.3886701639723640_rp)*t*t\n heslo(3, 8)= -1.2608736244689567_rp+2*( 1.4674024674377790_rp)*s+2*( 1.4674024674318957_rp)*t&\n +3*( -12.2065288429870833_rp)*s*s+4*( 39.5869423141255865_rp)*s*t+3*( -12.2065288429873533_rp)*t*t\n heslo(3, 9)= 8.0632420922024721_rp+2*( -7.1185789229073748_rp)*s+2*( -47.8959192494714898_rp)*t&\n +3*( 4.3886701639702750_rp)*s*s+4*( 17.5546806548536551_rp)*s*t+3*( 55.8326771571770450_rp)*t*t\n heslo(3,10)= -6.9920947394698487_rp+2*( 6.0474315694737584_rp)*s+2*( 24.8814210820885933_rp)*t&\n +3*( -4.3886701633092073_rp)*s*s+4*( 4.3886701606180765_rp)*s*t+3*( -33.8893263425786131_rp)*t*t\n heslo(3,11)= 34.9456552234114497_rp+2*( -35.1521840711213827_rp)*s+2*(-150.9456552311207815_rp)*t&\n +3*( 12.2065288474785518_rp)*s*s+4*( 76.2065288561027501_rp)*s*t+3*( 128.0000000074010131_rp)*t*t\n heslo(3,12)= -79.7694350724123069_rp+2*( 119.6021122361757989_rp)*s+2*( 211.2134420760958164_rp)*t&\n +3*( -55.8326771633475119_rp)*s*s+4*(-149.9433508353474735_rp)*s*t+3*(-136.7773403364694786_rp)*t*t\n heslo(3,13)= 83.3411663078350102_rp+2*(-188.4829805611818756_rp)*s+2*(-188.4829805615527221_rp)*t&\n +3*( 105.1418142528370367_rp)*s*s+4*( 210.2836285085713826_rp)*s*t+3*( 105.1418142530505975_rp)*t*t\n heslo(3,14)= -21.8006479476589448_rp+2*( 126.9424621956307533_rp)*s+2*( 21.8006479517496246_rp)*t&\n +3*(-105.1418142477331941_rp)*s*s+4*(-105.1418142527448367_rp)*s*t+3*( -0.0000000037839527_rp)*t*t\n heslo(3,15)= -21.8006479476762252_rp+2*( 21.8006479516582203_rp)*s+2*( 126.9424621958696662_rp)*t&\n +3*( -0.0000000037693724_rp)*s*s+4*(-105.1418142528167436_rp)*s*t+3*(-105.1418142479110429_rp)*t*t\n\n! * * * * * * * * * * * * * * * * * * * * * * * * * \n! *Valores calculados para cuadril\u00e1teros nnode=25 *\n! * * * * * * * * * * * * * * * * * * * * * * * * * \n else if (nnode==25) then\n s1 = s+1.0_rp\n s2 = s-1.0_rp\n s3 = s + 1.0_rp/2.0_rp\n s4 = s - 1.0_rp/2.0_rp\n Ns(1) = 2.0_rp*s*s3*s4*s2/3.0_rp \n Ns(2) =-8.0_rp*s*s1*s4*s2/3.0_rp \n Ns(3) = 4.0_rp*s1*s3*s4*s2 \n Ns(4) =-8.0_rp*s*s1*s3*s2/3.0_rp\n Ns(5) = 2.0_rp*s*s1*s3*s4/3.0_rp\n DNs(1) =2.0_rp*(s*s3*s4+s*s3*s2+s*s4*s2+s3*s4*s2)/3.0_rp\n DNs(2) =-8.0_rp*(s*s1*s4+s*s1*s2+s*s4*s2+s1*s4*s2)/3.0_rp\n DNs(3) = 4.0_rp*(s1*s3*s4+s1*s3*s2+s1*s4*s2+s3*s4*s2)\n DNs(4) =-8.0_rp*(s*s1*s3+s*s1*s2+s*s3*s2+s1*s3*s2)/3.0_rp\n DNs(5) = 2.0_rp*(s*s1*s3+s*s1*s4+s*s3*s4+s1*s3*s4)/3.0_rp\n D2Ns(1) = 4.0_rp*(s*s3+s*s4+s3*s4+s*s2+s3*s2+s4*s2)/3.0_rp\n D2Ns(2) =-16.0_rp*(s*s1+s*s4+s1*s4+s*s2+s1*s2+s4*s2)/3.0_rp\n D2Ns(3) = 8.0_rp*(s1*s3+s1*s4+s3*s4+s1*s2+s3*s2+s4*s2)\n D2Ns(4) =-16.0_rp*(s*s1+s*s3+s1*s3+s*s2+s1*s2+s3*s2)/3.0_rp\n D2Ns(5) = 4.0_rp*(s*s1+s*s3+s1*s3+s*s4+s1*s4+s3*s4)/3.0_rp\n t1 = t+1.0_rp \n t2 = t-1-0_rp \n t3 = t+1.0_rp/2.0_rp\n t4 = t-1.0_rp/2.0_rp\n Nt(1) = 2.0_rp*t*t3*t4*t2/3.0_rp \n Nt(2) =-8.0_rp/3.0_rp*t*t1*t4*t2 \n Nt(3) = 4.0_rp*t1*t3*t4*t2 \n Nt(4) =-8.0_rp*t*t1*t3*t2/3.0_rp\n Nt(5) = 2.0_rp*t*t1*t3*t4/3.0_rp\n DNt(1) = 2.0_rp*(t*t3*t4+t*t3*t2+t*t4*t2+t3*t4*t2)/3.0_rp\n DNt(2) =-8.0_rp*(t*t1*t4+t*t1*t2+t*t4*t2+t1*t4*t2)/3.0_rp\n DNt(3) = 4.0_rp*(t1*t3*t4+t1*t3*t2+t1*t4*t2+t3*t4*t2)\n DNt(4) =-8.0_rp*(t*t1*t3+t*t1*t2+t*t3*t2+t1*t3*t2)/3.0_rp\n DNt(5) = 2.0_rp*(t*t1*t3+t*t1*t4+t*t3*t4+t1*t3*t4)/3.0_rp\n D2Nt(1) = 4.0_rp*(t*t3+t*t4+t3*t4+t*t2+t3*t2+t4*t2)/3.0_rp\n D2Nt(2) =-16.0_rp*(t*t1+t*t4+t1*t4+t*t2+t1*t2+t4*t2)/3.0_rp\n D2Nt(3) = 8.0_rp*(t1*t3+t1*t4+t3*t4+t1*t2+t3*t2+t4*t2)\n D2Nt(4) =-16.0_rp*(t*t1+t*t3+t1*t3+t*t2+t1*t2+t3*t2)/3.0_rp\n D2Nt(5) = 4.0_rp*(t*t1+t*t3+t1*t3+t*t4+t1*t4+t3*t4)/3.0_rp\n shape( 1) = Ns(1)*Nt(1) !4 13 12 11 3\n shape( 2) = Ns(5)*Nt(1) !\n shape( 3) = Ns(5)*Nt(5) !\n shape( 4) = Ns(1)*Nt(5) !14 23 22 21 10\n shape( 5) = Ns(2)*Nt(1) !\n shape( 6) = Ns(3)*Nt(1) !\n shape( 7) = Ns(4)*Nt(1) !15 24 25 20 9 \n shape( 8) = Ns(5)*Nt(2) ! \n shape( 9) = Ns(5)*Nt(3) !\n shape(10) = Ns(5)*Nt(4) !16 17 18 19 8\n shape(11) = Ns(4)*Nt(5) !\n shape(12) = Ns(3)*Nt(5) !\n shape(13) = Ns(2)*Nt(5) !1 5 6 7 2\n shape(14) = Ns(1)*Nt(4)\n shape(15) = Ns(1)*Nt(3)\n shape(16) = Ns(1)*Nt(2)\n shape(17) = Ns(2)*Nt(2)\n shape(18) = Ns(3)*Nt(2)\n shape(19) = Ns(4)*Nt(2)\n shape(20) = Ns(4)*Nt(3)\n shape(21) = Ns(4)*Nt(4)\n shape(22) = Ns(3)*Nt(4)\n shape(23) = Ns(2)*Nt(4)\n shape(24) = Ns(2)*Nt(3)\n shape(25) = Ns(3)*Nt(3)\n deriv(1, 1) = DNs(1)*Nt(1)\n deriv(1, 2) = DNs(5)*Nt(1)\n deriv(1, 3) = DNs(5)*Nt(5)\n deriv(1, 4) = DNs(1)*Nt(5)\n deriv(1, 5) = DNs(2)*Nt(1)\n deriv(1, 6) = DNs(3)*Nt(1)\n deriv(1, 7) = DNs(4)*Nt(1)\n deriv(1, 8) = DNs(5)*Nt(2)\n deriv(1, 9) = DNs(5)*Nt(3)\n deriv(1,10) = DNs(5)*Nt(4)\n deriv(1,11) = DNs(4)*Nt(5)\n deriv(1,12) = DNs(3)*Nt(5)\n deriv(1,13) = DNs(2)*Nt(5)\n deriv(1,14) = DNs(1)*Nt(4)\n deriv(1,15) = DNs(1)*Nt(3)\n deriv(1,16) = DNs(1)*Nt(2)\n deriv(1,17) = DNs(2)*Nt(2)\n deriv(1,18) = DNs(3)*Nt(2)\n deriv(1,19) = DNs(4)*Nt(2)\n deriv(1,20) = DNs(4)*Nt(3)\n deriv(1,21) = DNs(4)*Nt(4)\n deriv(1,22) = DNs(3)*Nt(4)\n deriv(1,23) = DNs(2)*Nt(4)\n deriv(1,24) = DNs(2)*Nt(3)\n deriv(1,25) = DNs(3)*Nt(3)\n deriv(2, 1) = Ns(1)*DNt(1)\n deriv(2, 2) = Ns(5)*DNt(1)\n deriv(2, 3) = Ns(5)*DNt(5)\n deriv(2, 4) = Ns(1)*DNt(5)\n deriv(2, 5) = Ns(2)*DNt(1)\n deriv(2, 6) = Ns(3)*DNt(1)\n deriv(2, 7) = Ns(4)*DNt(1)\n deriv(2, 8) = Ns(5)*DNt(2)\n deriv(2, 9) = Ns(5)*DNt(3)\n deriv(2,10) = Ns(5)*DNt(4)\n deriv(2,11) = Ns(4)*DNt(5)\n deriv(2,12) = Ns(3)*DNt(5)\n deriv(2,13) = Ns(2)*DNt(5)\n deriv(2,14) = Ns(1)*DNt(4)\n deriv(2,15) = Ns(1)*DNt(3)\n deriv(2,16) = Ns(1)*DNt(2)\n deriv(2,17) = Ns(2)*DNt(2)\n deriv(2,18) = Ns(3)*DNt(2)\n deriv(2,19) = Ns(4)*DNt(2)\n deriv(2,20) = Ns(4)*DNt(3)\n deriv(2,21) = Ns(4)*DNt(4)\n deriv(2,22) = Ns(3)*DNt(4)\n deriv(2,23) = Ns(2)*DNt(4)\n deriv(2,24) = Ns(2)*DNt(3)\n deriv(2,25) = Ns(3)*DNt(3)\n heslo(1, 1) = D2Ns(1)*Nt(1)\n heslo(1, 2) = D2Ns(5)*Nt(1)\n heslo(1, 3) = D2Ns(5)*Nt(5)\n heslo(1, 4) = D2Ns(1)*Nt(5)\n heslo(1, 5) = D2Ns(2)*Nt(1)\n heslo(1, 6) = D2Ns(3)*Nt(1)\n heslo(1, 7) = D2Ns(4)*Nt(1)\n heslo(1, 8) = D2Ns(5)*Nt(2)\n heslo(1, 9) = D2Ns(5)*Nt(3)\n heslo(1,10) = D2Ns(5)*Nt(4)\n heslo(1,11) = D2Ns(4)*Nt(5)\n heslo(1,12) = D2Ns(3)*Nt(5)\n heslo(1,13) = D2Ns(2)*Nt(5)\n heslo(1,14) = D2Ns(1)*Nt(4)\n heslo(1,15) = D2Ns(1)*Nt(3)\n heslo(1,16) = D2Ns(1)*Nt(2)\n heslo(1,17) = D2Ns(2)*Nt(2)\n heslo(1,18) = D2Ns(3)*Nt(2)\n heslo(1,19) = D2Ns(4)*Nt(2)\n heslo(1,20) = D2Ns(4)*Nt(3)\n heslo(1,21) = D2Ns(4)*Nt(4)\n heslo(1,22) = D2Ns(3)*Nt(4)\n heslo(1,23) = D2Ns(2)*Nt(4)\n heslo(1,24) = D2Ns(2)*Nt(3)\n heslo(1,25) = D2Ns(3)*Nt(3)\n heslo(2, 1) = Ns(1)*D2Nt(1)\n heslo(2, 2) = Ns(5)*D2Nt(1)\n heslo(2, 3) = Ns(5)*D2Nt(5)\n heslo(2, 4) = Ns(1)*D2Nt(5)\n heslo(2, 5) = Ns(2)*D2Nt(1)\n heslo(2, 6) = Ns(3)*D2Nt(1)\n heslo(2, 7) = Ns(4)*D2Nt(1)\n heslo(2, 8) = Ns(5)*D2Nt(2)\n heslo(2, 9) = Ns(5)*D2Nt(3)\n heslo(2,10) = Ns(5)*D2Nt(4)\n heslo(2,11) = Ns(4)*D2Nt(5)\n heslo(2,12) = Ns(3)*D2Nt(5)\n heslo(2,13) = Ns(2)*D2Nt(5)\n heslo(2,14) = Ns(1)*D2Nt(4)\n heslo(2,15) = Ns(1)*D2Nt(3)\n heslo(2,16) = Ns(1)*D2Nt(2)\n heslo(2,17) = Ns(2)*D2Nt(2)\n heslo(2,18) = Ns(3)*D2Nt(2)\n heslo(2,19) = Ns(4)*D2Nt(2)\n heslo(2,20) = Ns(4)*D2Nt(3)\n heslo(2,21) = Ns(4)*D2Nt(4)\n heslo(2,22) = Ns(3)*D2Nt(4)\n heslo(2,23) = Ns(2)*D2Nt(4)\n heslo(2,24) = Ns(2)*D2Nt(3)\n heslo(2,25) = Ns(3)*D2Nt(3)\n heslo(3, 1) = DNs(1)*DNt(1)\n heslo(3, 2) = DNs(5)*DNt(1)\n heslo(3, 3) = DNs(5)*DNt(5)\n heslo(3, 4) = DNs(1)*DNt(5)\n heslo(3, 5) = DNs(2)*DNt(1)\n heslo(3, 6) = DNs(3)*DNt(1)\n heslo(3, 7) = DNs(4)*DNt(1)\n heslo(3, 8) = DNs(5)*DNt(2)\n heslo(3, 9) = DNs(5)*DNt(3)\n heslo(3,10) = DNs(5)*DNt(4)\n heslo(3,11) = DNs(4)*DNt(5)\n heslo(3,12) = DNs(3)*DNt(5)\n heslo(3,13) = DNs(2)*DNt(5)\n heslo(3,14) = DNs(1)*DNt(4)\n heslo(3,15) = DNs(1)*DNt(3)\n heslo(3,16) = DNs(1)*DNt(2)\n heslo(3,17) = DNs(2)*DNt(2)\n heslo(3,18) = DNs(3)*DNt(2)\n heslo(3,19) = DNs(4)*DNt(2)\n heslo(3,20) = DNs(4)*DNt(3)\n heslo(3,21) = DNs(4)*DNt(4)\n heslo(3,22) = DNs(3)*DNt(4)\n heslo(3,23) = DNs(2)*DNt(4)\n heslo(3,24) = DNs(2)*DNt(3)\n heslo(3,25) = DNs(3)*DNt(3)\n\n end if\n \nend subroutine shape2\n", "meta": {"hexsha": "27073683bb777910d959ec66f23503baf68a2c84", "size": 51268, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Sources/domain/shape2.f90", "max_stars_repo_name": "ciaid-colombia/InsFEM", "max_stars_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-24T08:19:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-24T08:19:54.000Z", "max_issues_repo_path": "Sources/domain/shape2.f90", "max_issues_repo_name": "ciaid-colombia/InsFEM", "max_issues_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Sources/domain/shape2.f90", "max_forks_repo_name": "ciaid-colombia/InsFEM", "max_forks_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 60.6721893491, "max_line_length": 127, "alphanum_fraction": 0.540941718, "num_tokens": 25172, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797148356994, "lm_q2_score": 0.7279754371026368, "lm_q1q2_score": 0.6633164511865742}} {"text": "! *******************************************************************\r\n! * *\r\n! * Function dlspx1 *\r\n! * *\r\n! *******************************************************************\r\n! Double Precision Version 1.41\r\n! Written by Gordon A. Fenton, Mar. 25, 1994\r\n! Latest Update: May 9, 2001\r\n!\r\n! PURPOSE returns the covariance between two points along a 1-D random\r\n! process having an exponential (Gaussian) type covariance function\r\n!\r\n! This function returns the covariance between two points, separated by\r\n! distance T, along a random process having Gaussian type covariance function\r\n!\r\n! B(T) = var * exp{ -pi*[(|T|/dthx)^2] }\r\n!\r\n!\r\n! If var < 0, then this function returns the variance of a local average\r\n! of the process, |var|*V(T), averaged over the distance T, where the\r\n! variance function is given by\r\n!\r\n! V(T) = (1/a*a) * [pi*(|T|/dthx)*erf(a) + exp(-a*a) - 1]\r\n!\r\n! where a = (|T|*sqrt(pi))/dthx, erf(.) is the error function,\r\n! dthx is the directional scale of fluctuation, and var is the point\r\n! variance. The variance of a local average is given by var*V(X).\r\n!\r\n! See page 186 of \"Random Fields\" by E. Vanmarcke and G.A. Fenton's thesis\r\n! for more details.\r\n!\r\n! The parameters var and dthx are brought in via the common block\r\n! /dparam/.\r\n!\r\n! The argument to this routine, T, is the distance between the two points\r\n! for which the covariance is desired (or the distance over which the local\r\n! averaging is performed, if var < 0).\r\n!\r\n! REVISION HISTORY:\r\n! 1.1\tfixed argument list and dthx = 0 case, improved limit handling\r\n!\t(Jun 19/96)\r\n! 1.2\tadded lvarfn flag to end of /dparam/ common block. Set it to\r\n!\ttrue if the variance function is to be returned. Otherwise this\r\n!\tfunction returns the covariance. (May 1/00)\r\n! 1.3\teliminated lvarfn -- now return covariances only if var < 0 (Mar 2/01)\r\n! 1.4\treversed default - now return covariances if var > 0. (Apr 11/01)\r\n! 1.41\trevised above documentation to reflect revision 1.4 (May 9/01)\r\n!---------------------------------------------------------------------------\r\n real*8 function dlspx1( T )\r\n implicit real*8 (a-h,o-z)\r\n common/dparam/ var, dpb, dthx, dthy, dthz\r\n data zero/0.d0/, one/1.d0/, six/6.d0/\r\n data rtpi/1.77245385090551588d0/, pt1/0.1d0/\r\n data pi/3.1415926535897932384d0/, big/1.d6/\r\n exp(s) = dexp(s)\r\n abs(s) = dabs(s)\r\n r_erf(s) = derf(s)\r\n\r\n if( var .lt. zero ) then\t\t\t! return variance function\r\n aT = abs(T)\r\n if( dthx .ge. big*aT ) then\r\n if( dthx .eq. zero ) then\r\n dlspx1 = -var\r\n else\r\n rx = aT/dthx\r\n dlspx1 = -var*(one - pi*rx*rx/six)\r\n endif\r\n elseif( dthx .le. pt1*aT ) then\r\n rx = dthx/aT\r\n dlspx1 = -var*rx*(one - rx/pi)\r\n else\r\n rx = aT/dthx\r\n a = rtpi*rx\r\n aa = a*a\r\n dlspx1 = -var*(pi*rx*r_erf(a) + exp(-aa) - one)/aa\r\n endif\r\n else\t\t\t\t\t! return covariance\r\n if( dthx .eq. zero ) then\r\n if( T .eq. zero ) then\r\n dlspx1 = var\r\n else\r\n dlspx1 = zero\r\n endif\r\n else\r\n at = T/dthx\r\n dlspx1 = var * exp(-pi*at*at)\r\n endif\r\n endif\r\n\r\n return\r\n end\r\n\r\n", "meta": {"hexsha": "345ddddf2a9a8a3f3e11d9f6be7e2e4b5a0f9d0b", "size": 3561, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/libs/gaf95/dlspx1.f95", "max_stars_repo_name": "leemargetts/PoreFEM", "max_stars_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/libs/gaf95/dlspx1.f95", "max_issues_repo_name": "leemargetts/PoreFEM", "max_issues_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/libs/gaf95/dlspx1.f95", "max_forks_repo_name": "leemargetts/PoreFEM", "max_forks_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.2903225806, "max_line_length": 79, "alphanum_fraction": 0.5074417299, "num_tokens": 1027, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797003640646, "lm_q2_score": 0.7279754430043072, "lm_q1q2_score": 0.6633164460290618}} {"text": "c fishpk35 from portlib 12/30/83\nc\nc * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nc * *\nc * f i s h p a k *\nc * *\nc * *\nc * a package of fortran subprograms for the solution of *\nc * *\nc * separable elliptic partial differential equations *\nc * *\nc * (version 3.1 , october 1980) *\nc * *\nc * by *\nc * *\nc * john adams, paul swarztrauber and roland sweet *\nc * *\nc * of *\nc * *\nc * the national center for atmospheric research *\nc * *\nc * boulder, colorado (80307) u.s.a. *\nc * *\nc * which is sponsored by *\nc * *\nc * the national science foundation *\nc * *\nc * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nc\nc program to illustrate the use of subroutine hw3crt to\nc solve the helmholtz equation\nc\nc (d/dx)(du/dx) + (d/dy)(du/dy) + (d/dz)(du/dz) - 3u\nc\nc = 4x**2*(3-x**2):sin(y)*cos(z)\nc\nc on the parallelepiped 0 .lt. x .lt. 1, 0 .lt. y .lt. 2*pi,\nc 0 .lt. z .lt. pi/2 with the boundary conditions\nc\nc u(0,y,z) = 0\nc 0 .le. y .le. 2*pi , 0 .le. z .le. pi/2\nc u(1,y,z) = sin(y)*cos(z)\nc\nc u periodic in y,\nc\nc u(x,y,0) = x**4*sin(y)\nc 0 .le. x .le. 1 , 0 .le. y .le. 2*pi\nc (du/dx)(x,y,pi/2) = -x**4*sin(y)\nc\nc using a finite difference grid with panel widths\nc\nc deltax (=dx) = 1/10 , deltay (=dy) = 1/40 , deltaz (=dz) = 1/15.\nc\nc the exact solution of this problem is\nc\nc u(x,y,z) = x**4*sin(y)*cos(z) .\nc\n dimension f(11,41,16),bdzf(11,41),w(370) ,x(11) ,\n 1 y(41) ,z(16)\n real dum(1)\nc\nc from the description of the problem given above, we define\nc the following quantities\nc\n elmbda = -3.\n xs = 0.\n xf = 1.\n lbdcnd = 1\n ys = 0.\n pi = pimach(dum0)\n yf = 2.*pi\n mbdcnd = 0\n zs = 0.\n zf = pi/2.\n nbdcnd = 2\n l = 10\n m = 40\n n = 15\nc\nc from the dimension statement above we define\nc\n ldimf = 11\n mdimf = 41\nc\nc also note that w has been dimensioned\nc 30+l+m+5*n+max(l,m,n)+7*(int((l+1)/2)+int((m+1)/2))\nc = 30+10+40+75+40+7*(5+20) = 370\nc we define the grid points for later use.\nc\n lp1 = l+1\n dx = (xf-xs)/float(l)\n do 101 i=1,lp1\n x(i) = xs+float(i-1)*dx\n 101 continue\n mp1 = m+1\n dy = (yf-ys)/float(m)\n do 102 j=1,mp1\n y(j) = ys+float(j-1)*dy\n 102 continue\n np1 = n+1\n dz = (zf-zs)/float(n)\n do 103 k=1,np1\n z(k) = zs+float(k-1)*dz\n 103 continue\nc\nc we define the array of derivative boundary values.\nc\n do 105 i=1,lp1\n do 104 j=1,mp1\n bdzf(i,j) = -x(i)**4*sin(y(j))\n 104 continue\n 105 continue\nc\nc note that for this example all other boundary arrays are\nc dummy variables.\nc we define the function boundary values in the f array.\nc\n do 107 j=1,mp1\n do 106 k=1,np1\n f(1,j,k) = 0.\n f(lp1,j,k) = sin(y(j))*cos(z(k))\n 106 continue\n 107 continue\n do 109 i=1,lp1\n do 108 j=1,mp1\n f(i,j,1) = x(i)**4*sin(y(j))\n 108 continue\n 109 continue\nc\nc we now define the values of the right side of the helmholtz\nc equation.\nc\n do 112 i=2,l\n do 111 j=1,mp1\n do 110 k=2,np1\n f(i,j,k) = 4.*x(i)**2*(3.-x(i)**2)*sin(y(j))*cos(z(k))\n 110 continue\n 111 continue\n 112 continue\nc\nc call hw3crt to generate and solve the finite difference equation.\nc\nc call hw3crt (xs,xf,l,lbdcnd,bdxs,bdxf,ys,yf,m,mbdcnd,bdys,bdyf,\nc 1 zs,zf,n,nbdcnd,bdzs,bdzf,elmbda,ldimf,mdimf,f,\nc 2 pertrb,ierror,w)\n call hw3crt (xs,xf,l,lbdcnd,dum,dum,ys,yf,m,mbdcnd,dum,dum,\n 1 zs,zf,n,nbdcnd,dum,bdzf,elmbda,ldimf,mdimf,f,\n 2 pertrb,ierror,w)\nc\nc compute discretization error. the exact solution to the\nc problem is\nc\nc u(x,y,z) = x**4*sin(y)*cos(z)\nc\n err = 0.\n do 115 i=1,lp1\n do 114 j=1,mp1\n do 113 k=1,np1\n t = abs(f(i,j,k)-x(i)**4*sin(y(j))*cos(z(k)))\n if (t .gt. err) err = t\n 113 continue\n 114 continue\n 115 continue\n print 1001 , ierror,err\n stop\nc\n 1001 format (1h1,20x,25hsubroutine hw3crt example///\n 1 10x,46hthe output from the ncar control data 7600 was//\n 2 32x,10hierror = 0/\n 3 18x,34hdiscretization error = 9.64802e-03//\n 4 10x,32hthe output from your computer is//\n 5 32x,8hierror =,i2/18x,22hdiscretization error =,e12.5)\nc\n end\nc problem is\n", "meta": {"hexsha": "7fa6f944434066d976293dfc024e784f7994658a", "size": 5919, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/f2cl/packages/fishpack/ex/tsthw3crt.f", "max_stars_repo_name": "sbwhitecap/clocc-hg", "max_stars_repo_head_hexsha": "f6cf2591ceef8a3a80e04da9b414cdf60a25a90f", "max_stars_repo_licenses": ["MIT"], "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/f2cl/packages/fishpack/ex/tsthw3crt.f", "max_issues_repo_name": "sbwhitecap/clocc-hg", "max_issues_repo_head_hexsha": "f6cf2591ceef8a3a80e04da9b414cdf60a25a90f", "max_issues_repo_licenses": ["MIT"], "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/f2cl/packages/fishpack/ex/tsthw3crt.f", "max_forks_repo_name": "sbwhitecap/clocc-hg", "max_forks_repo_head_hexsha": "f6cf2591ceef8a3a80e04da9b414cdf60a25a90f", "max_forks_repo_licenses": ["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.6306818182, "max_line_length": 72, "alphanum_fraction": 0.4042912654, "num_tokens": 1868, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256551882382, "lm_q2_score": 0.787931190663057, "lm_q1q2_score": 0.6633006908231766}} {"text": "subroutine initial()\n use commondata\n implicit none\n integer :: i, j, k\n integer :: alpha\n real(8) :: un(0:18)\n real(8) :: us2\n\n itc = 0\n errorU = 100.0d0\n\n if (rank == 0) then\n write(*,*) \"nx=\",nx,\", ny=\",ny, \", nz = \",nz\n write(*,*) \"Reynolds=\",real(Reynolds)\n write(*,*) \"U0=\",real(U0),\", tauf=\",real(tauf)\n endif\n\n xp(0) = 0.0d0\n xp(total_nx+1) = dble(total_nx)\n do i=1,total_nx\n xp(i) = dble(i)-0.5d0\n enddo\n yp(0) = 0.0d0\n yp(total_ny+1) = dble(total_ny)\n do j=1,total_ny\n yp(j) = dble(j)-0.5d0\n enddo\n zp(0) = 0.0d0\n zp(total_nz+1) = dble(total_nz)\n do k=1,total_nz\n zp(k) = dble(k)-0.5d0\n enddo\n\n \n allocate (u(nx, ny, nz))\n allocate (v(nx, ny, nz))\n allocate (w(nx, ny, nz))\n allocate (rho(nx, ny, nz))\n allocate (up(nx, ny, nz))\n allocate (vp(nx, ny, nz))\n allocate (wp(nx, ny, nz))\n \n allocate (f(0:18, nx, ny, nz))\n allocate (f_post(0:18, 0:nx+1, 0:ny+1, 0:nz+1))\n\n rho = rho0\n u = 0.0d0\n v = 0.0d0\n w = 0.0d0\n up = 0.0d0\n vp = 0.0d0\n wp = 0.0d0\n\n ! top bpundary\n if (coords(2) == dims(2) - 1) then\n do j = 1, ny\n do i = 1, nx\n u(i, j, nz) = U0\n enddo\n enddo\n endif\n\n do k = 1, nz\n do j = 1, ny\n do i = 1, nx\n us2 = u(i,j,k)*u(i,j,k) + v(i,j,k)*v(i,j,k) + w(i,j,k)*w(i,j,k)\n do alpha = 0, 18\n un(alpha) = u(i,j,k)*ex(alpha) + v(i,j,k)*ey(alpha) + w(i,j,k)*ez(alpha)\n f(alpha,i,j,k) = rho(i,j,k)*omega(alpha)*(1.0d0+3.0d0*un(alpha)+4.5d0*un(alpha)*un(alpha)-1.5d0*us2)\n enddo\n enddo\n enddo\n enddo\n \n return\nend subroutine initial", "meta": {"hexsha": "70eb564a004e5d46834efd70d6a345ae93043db7", "size": 1797, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "MPI/Lid_driven_cavity/fortran/3d/mpi_3d_blocked/initial.f90", "max_stars_repo_name": "cheryli/parallel", "max_stars_repo_head_hexsha": "a6b3f3ea479e64476a56f08e8c9e28c632a1b68b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-12-10T06:44:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-26T16:06:48.000Z", "max_issues_repo_path": "MPI/Lid_driven_cavity/fortran/3d/mpi_3d_blocked/initial.f90", "max_issues_repo_name": "cheryli/parallel", "max_issues_repo_head_hexsha": "a6b3f3ea479e64476a56f08e8c9e28c632a1b68b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-12-11T12:50:24.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-11T14:11:56.000Z", "max_forks_repo_path": "MPI/Lid_driven_cavity/fortran/3d/mpi_3d_blocked/initial.f90", "max_forks_repo_name": "cheryli/MGLC", "max_forks_repo_head_hexsha": "a6b3f3ea479e64476a56f08e8c9e28c632a1b68b", "max_forks_repo_licenses": ["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.6447368421, "max_line_length": 120, "alphanum_fraction": 0.4590984975, "num_tokens": 736, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256472515684, "lm_q2_score": 0.787931190663057, "lm_q1q2_score": 0.6633006845696269}} {"text": "program sort\n implicit none\n integer :: i, j\n integer, parameter :: M = 5\n real, dimension(M) :: x\n real :: s\n\n ! initialize the array\n do i=1, M\n x(i) = sin(real(i))\n end do\n\n ! sort the array\n do i=1, M-1\n do j=i+1, M\n if (x(i) > x(j)) then\n s = x(j)\n x(j) = x(i)\n x(i) = s\n end if\n end do\n end do\n write(*,*) x\nend program\n\n", "meta": {"hexsha": "5ae376c57f24c546459dbf3826d23461ba069df5", "size": 451, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lec08/sort.f90", "max_stars_repo_name": "rekka/intro-fortran-2016", "max_stars_repo_head_hexsha": "72310e04254bde150e78609eef74158620f2fa72", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-05T01:54:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T01:54:57.000Z", "max_issues_repo_path": "lec08/sort.f90", "max_issues_repo_name": "rekka/intro-fortran-2016", "max_issues_repo_head_hexsha": "72310e04254bde150e78609eef74158620f2fa72", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lec08/sort.f90", "max_forks_repo_name": "rekka/intro-fortran-2016", "max_forks_repo_head_hexsha": "72310e04254bde150e78609eef74158620f2fa72", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-06-22T12:39:34.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-25T04:45:37.000Z", "avg_line_length": 17.3461538462, "max_line_length": 33, "alphanum_fraction": 0.4057649667, "num_tokens": 145, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311856832191, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.6633006772506966}} {"text": "subroutine init(km, jm, Rd, Cpd, g, nuv, lat, lev, T, cosphi, tanphi, dphi, theta, p, dp, eta)\n\nimplicit none\n\n! In\ninteger :: km, jm\nreal, intent(in) :: Rd, Cpd, g, nuv\nreal, intent(in), dimension(jm) :: lat\nreal, intent(in), dimension(km) :: lev\nreal, intent(in), dimension(jm,km) :: T\n\n! Out\nreal, intent(out) :: dp, dphi\nreal, intent(out),dimension(jm) :: cosphi, tanphi\nreal, intent(out),dimension(jm,km-1) :: eta\nreal, intent(out),dimension(jm,km) :: p,theta\n\n! Local\ninteger :: j\nreal :: deg2rad\nreal, dimension(jm,km) :: eta_mid\n\n! Pressure field \np=1.\ndo j=1,jm\n p(j,:) = lev*100. ! mb -> Pa\nenddo\ndp = p(1,km)-p(1,km-1) \n\n! geometry\ndeg2rad = abs(acos(-1.))/180.\ndphi = (lat(2)-lat(1))*deg2rad\ncosphi = cos( lat*deg2rad )\ntanphi = sin( lat*deg2rad )/cosphi\n\n! Dynamical viscosity\neta_mid = nuv*g*(p/Rd/T)**2 ! viscosity on level midpoints\neta = ( eta_mid(:,2:km)+eta_mid(:,1:km-1) )/2. ! viscosity on level interfaces\n\n! Temp -> pot. temp.\ntheta = (lev(km)*100./p)**(Rd/Cpd) * T\n\nend subroutine init\n", "meta": {"hexsha": "dfaedc6018632940bebb8e79eb3fb670214ae29a", "size": 1114, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/turbulence/simple/src/init.f90", "max_stars_repo_name": "CliMT/climt-legacy", "max_stars_repo_head_hexsha": "adbd4fe77426c90deb8d2c046a2f3dc3b72df89e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/turbulence/simple/src/init.f90", "max_issues_repo_name": "CliMT/climt-legacy", "max_issues_repo_head_hexsha": "adbd4fe77426c90deb8d2c046a2f3dc3b72df89e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/turbulence/simple/src/init.f90", "max_forks_repo_name": "CliMT/climt-legacy", "max_forks_repo_head_hexsha": "adbd4fe77426c90deb8d2c046a2f3dc3b72df89e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.3181818182, "max_line_length": 94, "alphanum_fraction": 0.5825852783, "num_tokens": 398, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122113355092, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.663298375592584}} {"text": "function topo_xy(xxx,yyy)\r\n\r\ncommon/topo/nxx,xmin,xmax,nyy,ymin,ymax,htopo(1500,1500),topomin,topomax\r\n\r\ntopo_xy=0\r\n\r\n\r\nif (nxx.eq.0) return\r\nif ((xxx-xmin)*(xxx-xmax).gt.0) return\r\nif ((yyy-ymin)*(yyy-ymax).gt.0) return\r\n\r\ndxx=(xmax-xmin)/nxx\r\ndyy=(ymax-ymin)/nyy\r\n\r\ndo ixx=1,nxx\r\n\tx1=xmin+dxx*(ixx-1)\r\n\tx2=fmin+dxx*ixx\r\n\tif ((xxx-x1)*(xxx-x2).gt.0.) cycle\r\n\texit\r\nend do\r\n\r\ndo iyy=1,nyy\r\n\ty1=ymin+dyy*(iyy-1)\r\n\ty2=ymin+dt*iyy\r\n\tif ((yyy-y1)*(yyy-y2).gt.0.) cycle\r\n\texit\r\nend do\r\n\r\nh11=htopo(ixx,iyy)\r\nh12=htopo(ixx,iyy+1)\r\nh21=htopo(ixx+1,iyy)\r\nh22=htopo(ixx+1,iyy+1)\r\n\r\nh1=h11+(h11-h12)*(yyy-y1)/(y1-y2)\r\nh2=h21+(h21-h22)*(yyy-y1)/(y1-y2)\r\n\r\nhhh=h1+(h1-h2)*(xxx-x1)/(x1-x2)\r\n\r\ntopo_xy=-hhh\r\n\r\nreturn\r\nend\t", "meta": {"hexsha": "c01b5f058f38539480d26c730c520f73bc221012", "size": 708, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "PROGRAMS/subr/3D_model/topo.f90", "max_stars_repo_name": "ilyasnsk/colima_lotos_2019", "max_stars_repo_head_hexsha": "d3ff4f32034e49a32560f170e980b6847b6ea9c7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-10-28T06:16:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-16T02:52:23.000Z", "max_issues_repo_path": "PROGRAMS/subr/3D_model/topo.f90", "max_issues_repo_name": "ilyasnsk/colima_lotos_2019", "max_issues_repo_head_hexsha": "d3ff4f32034e49a32560f170e980b6847b6ea9c7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "PROGRAMS/subr/3D_model/topo.f90", "max_forks_repo_name": "ilyasnsk/colima_lotos_2019", "max_forks_repo_head_hexsha": "d3ff4f32034e49a32560f170e980b6847b6ea9c7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.8571428571, "max_line_length": 73, "alphanum_fraction": 0.6242937853, "num_tokens": 324, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122113355091, "lm_q2_score": 0.7310585727705126, "lm_q1q2_score": 0.663298370276195}} {"text": "!\tcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\n!\tquad3d4n.fcm c\n!\t---------------------------------------------------------------------c\n! quadrature definitions in three dimensional tetrahedral ref domain c\n!\t---------------------------------------------------------------------c\n!\t930329 - converted from quad2d3n.fcm c\n!\t rules taken from Hughes Table 3.I.2 c\n!\tcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\n\tsubroutine quad3d4n(iquad, nquad, xquad, wquad, maxnsd, maxnquad)\n implicit none\n\n\tinteger :: iquad,nquad\n\tinteger :: maxnsd,maxnquad\n\treal* 8 xquad(maxnsd,maxnquad)\n\treal* 8 wquad(maxnquad)\n\n\tif ((iquad.eq.1).or.(iquad.eq.313131)) then\n\n!\t\t1 point quadrature - code 3.1,3.1,3.1 - old code 1 - precision 2\n\t\tnquad = 1\n\n\t\txquad(1,1) = + 0.250000000000000\n\t\txquad(2,1) = + 0.250000000000000\n\t\txquad(3,1) = + 0.250000000000000\n\n\t\twquad(1) = 0.166666666666667\n\t\treturn\n\n\telse if ((iquad.eq.2).or.(iquad.eq.323232)) then\n!\t\t4 point quadrature - code 3.2,3.2,3.2 - old code 2 - precision 3\n\t\tnquad = 4\n\n\t\txquad(1,1) = + 0.585410200000000\n\t\txquad(2,1) = + 0.138196600000000\n\t\txquad(3,1) = + 0.138196600000000\n\t\txquad(1,2) = + 0.138196600000000\n\t\txquad(2,2) = + 0.585410200000000\n\t\txquad(3,2) = + 0.138196600000000\n\t\txquad(1,3) = + 0.138196600000000\n\t\txquad(2,3) = + 0.138196600000000\n\t\txquad(3,3) = + 0.585410200000000\n\t\txquad(1,4) = + 0.138196600000000\n\t\txquad(2,4) = + 0.138196600000000\n\t\txquad(3,4) = + 0.138196600000000\n\n\t\twquad(1) = 0.041666666666667\n\t\twquad(2) = 0.041666666666667\n\t\twquad(3) = 0.041666666666667\n\t\twquad(4) = 0.041666666666667\n\t\treturn\n\n\telse if ((iquad.eq.3).or.(iquad.eq.333333)) then\n!\t\t5 point quadrature - code 3.3,3.3,3.3 - old code 3 - precision 4\n\t\tnquad = 5\n\n\t\txquad(1,1) = + 0.250000000000000\n\t\txquad(2,1) = + 0.250000000000000\n\t\txquad(3,1) = + 0.250000000000000\n\t\txquad(1,2) = + 0.333333333333333\n\t\txquad(2,2) = + 0.166666666666667\n\t\txquad(3,2) = + 0.166666666666667\n\t\txquad(1,3) = + 0.166666666666667\n\t\txquad(2,3) = + 0.333333333333333\n\t\txquad(3,3) = + 0.166666666666667\n\t\txquad(1,4) = + 0.166666666666667\n\t\txquad(2,4) = + 0.166666666666667\n\t\txquad(3,4) = + 0.333333333333333\n\t\txquad(1,5) = + 0.166666666666667\n\t\txquad(2,5) = + 0.166666666666667\n\t\txquad(3,5) = + 0.166666666666667\n\n\t\twquad(1) = - 0.133333333333333\n\t\twquad(2) = + 0.075000000000000\n\t\twquad(3) = + 0.075000000000000\n\t\twquad(4) = + 0.075000000000000\n\t\twquad(5) = + 0.075000000000000\n\t\treturn\n\n\telse if ((iquad.eq.4).or.(iquad.eq.222222)) then\n!\t4 point Lobatto quadrature - element corners - code 2.2,2.2,2.2 - old 4\n\t\tnquad = 4\n\n\t\txquad(1,1) = + 0.0\n\t\txquad(2,1) = + 0.0\n\t\txquad(3,1) = + 0.0\n\t\txquad(1,2) = + 1.0\n\t\txquad(2,2) = + 0.0\n\t\txquad(3,2) = + 0.0\n\t\txquad(1,3) = + 0.0\n\t\txquad(2,3) = + 1.0\n\t\txquad(3,3) = + 0.0\n\t\txquad(1,4) = + 0.0\n\t\txquad(2,4) = + 0.0\n\t\txquad(3,4) = + 1.0\n\t\n\t\twquad(1) = 0.041666666666667\n\t\twquad(2) = 0.041666666666667\n\t\twquad(3) = 0.041666666666667\n\t\twquad(4) = 0.041666666666667\n\t\treturn\n\n\telse\n\t\tcall error(\"quad3d4n: unknown quadrature code \", iquad, .true.)\n\tend if\n\n\tend\n", "meta": {"hexsha": "aeef2c5ae3c855178e2862b0c8e9e3b3cdac60d0", "size": 3188, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "quad3d4n.f90", "max_stars_repo_name": "biofluids/IFEM-archive", "max_stars_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-15T11:40:16.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-15T11:40:16.000Z", "max_issues_repo_path": "quad3d4n.f90", "max_issues_repo_name": "biofluids/IFEM-archive", "max_issues_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "quad3d4n.f90", "max_forks_repo_name": "biofluids/IFEM-archive", "max_forks_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-02-11T16:50:21.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-08T07:24:59.000Z", "avg_line_length": 29.7943925234, "max_line_length": 75, "alphanum_fraction": 0.6091593476, "num_tokens": 1435, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391579526935, "lm_q2_score": 0.7185944046238982, "lm_q1q2_score": 0.6632907741535602}} {"text": "\tPROGRAM CUBICHK\nC\n\tCOMPLEX ROOT(3)\nC\n\tA = 0.\n\tB = -1.\n\tC = 0.\n\tCALL CUBIC(A,B,C,ROOT)\n\tPRINT*,ROOT\n\tA = -1.\n\tB = 1.\n\tC = -1.\n\tCALL CUBIC(A,B,C,ROOT)\n\tPRINT*,ROOT\n\tSTOP\n\tEND\n", "meta": {"hexsha": "c2fa5cb4a40f7da686b72b438df33a4713d6d5e1", "size": 174, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/waves_dir/cubichk_3.for", "max_stars_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_stars_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/waves_dir/cubichk_3.for", "max_issues_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_issues_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/waves_dir/cubichk_3.for", "max_forks_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_forks_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 10.2352941176, "max_line_length": 23, "alphanum_fraction": 0.5574712644, "num_tokens": 86, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.923039160069787, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6632907701121767}} {"text": "program mandelbrot\n\n implicit none\n integer , parameter :: rk = selected_real_kind (9, 99)\n integer , parameter :: i_max = 800\n integer , parameter :: j_max = 600\n integer , parameter :: n_max = 100\n real (rk), parameter :: x_centre = -0.5_rk\n real (rk), parameter :: y_centre = 0.0_rk\n real (rk), parameter :: width = 4.0_rk\n real (rk), parameter :: height = 3.0_rk\n real (rk), parameter :: dx_di = width / i_max\n real (rk), parameter :: dy_dj = -height / j_max\n real (rk), parameter :: x_offset = x_centre - 0.5_rk * (i_max + 1) * dx_di\n real (rk), parameter :: y_offset = y_centre - 0.5_rk * (j_max + 1) * dy_dj\n integer, dimension (i_max, j_max) :: image\n integer :: i\n integer :: j\n integer :: n\n real (rk) :: x\n real (rk) :: y\n real (rk) :: x_0\n real (rk) :: y_0\n real (rk) :: x_sqr\n real (rk) :: y_sqr\n\n do j = 1, j_max\n y_0 = y_offset + dy_dj * j\n do i = 1, i_max\n x_0 = x_offset + dx_di * i\n x = 0.0_rk\n y = 0.0_rk\n n = 0\n do\n x_sqr = x ** 2\n y_sqr = y ** 2\n if (x_sqr + y_sqr > 4.0_rk) then\n image (i, j) = 255\n exit\n end if\n if (n == n_max) then\n image (i, j) = 0\n exit\n end if\n y = y_0 + 2.0_rk * x * y\n x = x_0 + x_sqr - y_sqr\n n = n + 1\n end do\n end do\n end do\n open (10, file = 'out.pgm')\n write (10, '(a/ i0, 1x, i0/ i0)') 'P2', i_max, j_max, 255\n write (10, '(i0)') image\n close (10)\n\nend program mandelbrot\n", "meta": {"hexsha": "9a69ecdc39abef24cf01077a114d5d088060454b", "size": 1537, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Mandelbrot-set/Fortran/mandelbrot-set.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/Mandelbrot-set/Fortran/mandelbrot-set.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/Mandelbrot-set/Fortran/mandelbrot-set.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 26.9649122807, "max_line_length": 76, "alphanum_fraction": 0.5159401431, "num_tokens": 618, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391558355999, "lm_q2_score": 0.7185943985973773, "lm_q1q2_score": 0.6632907670695137}} {"text": "PROGRAM t_logistic\r\n! Illustration of the problem of a boundary between two regions.\r\n! In one region, every case falls into one category, in the other\r\n! region, every case is in the other category.\r\n\r\nUSE Logistic_Regression\r\nIMPLICIT NONE\r\n\r\nREAL (dp) :: x(16,2), chisq, devnce, beta(0:2), se_beta(0:2), scale\r\nINTEGER :: n(16), s(16), i, iostatus, ndf, ier\r\n\r\n! Read in the artificial data\r\n\r\nOPEN(UNIT=8, FILE='clearcut.dat', STATUS='OLD')\r\n\r\ni = 1\r\nDO\r\n READ(8, *, IOSTAT=iostatus) x(i,1), x(i,2), s(i), n(i)\r\n IF (iostatus < 0) EXIT\r\n IF (iostatus > 0) CYCLE\r\n i = i + 1\r\n IF (i > 16) EXIT\r\nEND DO\r\n\r\nCALL logistic(16, x, 2, s, n, chisq, devnce, ndf, beta, se_beta, ier)\r\nWRITE(*, *) 'IER =', ier\r\nWRITE(*, *)\r\nWRITE(*, *) 'If IER = 7, it means that there is a linear boundary'\r\nWRITE(*, *) 'between cases in which s = 0 and s = 1'\r\n\r\nIF (ier == 0) WRITE(*, '(a, f8.3, a, f8.3, a, i3, a)') &\r\n ' Deviance = ', devnce, ' Chi-square = ', chisq, &\r\n ' with ', ndf, ' deg. of freedom'\r\nWRITE(*, *)\r\nWRITE(*, *) ' Coefficient'\r\nDO i = 0, 2\r\n WRITE(*, '(i3, g12.4)') i, beta(i)\r\nEND DO\r\nWRITE(*, *)\r\n\r\nscale = SQRT(ABS(beta(1))*ABS(beta(2)))\r\nbeta = beta / scale\r\nWRITE(*, *) 'Boundary is approx:'\r\nWRITE(*, '(f9.4, a, f9.4, a, f9.4, a)') &\r\n beta(0), ' + ', beta(1), ' * X1 + ', beta(2), ' * X2 = 0.0'\r\n\r\nSTOP\r\nEND PROGRAM t_logistic\r\n\r\n", "meta": {"hexsha": "7ca0818a3eb771cc1d31018fc1d9d97cd6d55003", "size": 1408, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/t_lgstc3.f90", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/amil/t_lgstc3.f90", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/amil/t_lgstc3.f90", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 28.16, "max_line_length": 76, "alphanum_fraction": 0.5504261364, "num_tokens": 526, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.923039160069787, "lm_q2_score": 0.7185943925708562, "lm_q1q2_score": 0.6632907645494619}} {"text": " subroutine somm (dr,dp,dq,dpas,da,m,np)\nc\nc integration by the method of simpson of (dp+dq)*dr**m from\nc 0 to r=dr(np)\nc dpas=exponential step;\nc for r in the neighborhood of zero (dp+dq)=cte*r**da\nc **********************************************************************\n implicit double precision (a-h,o-z)\n save\n dimension dr(251), dp(251), dq(251)\n mm=m+1\n d1=da+mm\n da=0.0\n db=0.0\n do i=1,np\n dl=dr(i)**mm\n if (i.ne.1.and.i.ne.np) then\n dl=dl+dl\n if ((i-2*(i/2)).eq.0) dl=dl+dl\n endif\n dc=dp(i)*dl\n if (dc.lt.0) then\n db=db+dc\n elseif(dc.gt.0) then\n da=da+dc\n endif\n dc=dq(i)*dl\n if (dc.lt.0) then\n db=db+dc\n elseif (dc.gt.0) then\n da=da+dc\n endif\n enddo\n da=dpas*(da+db)/3.0\n dc=exp(dpas)-1.0\n db=d1*(d1+1.0)*dc*exp((d1-1.0)*dpas)\n db=dr(1)*(dr(2)**m)/db\n dc=(dr(1)**mm)*(1.0+1.0/(dc*(d1+1.0)))/d1\n da=da+dc*(dp(1)+dq(1))-db*(dp(2)+dq(2))\n return\n end\n", "meta": {"hexsha": "8288d5a598ea8c7a827c3f41827b2bf6c14240b3", "size": 1102, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/feff6l/somm.f", "max_stars_repo_name": "xraypy/feff85exafs", "max_stars_repo_head_hexsha": "ec8dcb07ca8ee034d0fa7431782074f0f65357a5", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2016-01-05T21:29:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:59:17.000Z", "max_issues_repo_path": "src/feff6l/somm.f", "max_issues_repo_name": "xraypy/feff85exafs", "max_issues_repo_head_hexsha": "ec8dcb07ca8ee034d0fa7431782074f0f65357a5", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 17, "max_issues_repo_issues_event_min_datetime": "2015-01-04T18:37:30.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-07T12:06:12.000Z", "max_forks_repo_path": "src/feff6l/somm.f", "max_forks_repo_name": "xraypy/feff85exafs", "max_forks_repo_head_hexsha": "ec8dcb07ca8ee034d0fa7431782074f0f65357a5", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2016-01-05T21:29:26.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T13:11:01.000Z", "avg_line_length": 26.2380952381, "max_line_length": 72, "alphanum_fraction": 0.4364791289, "num_tokens": 412, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009503523291, "lm_q2_score": 0.7248702880639791, "lm_q1q2_score": 0.663184515431901}} {"text": " SUBROUTINE MB04BZ( JOB, COMPQ, N, A, LDA, DE, LDDE, B, LDB, FG,\n $ LDFG, Q, LDQ, ALPHAR, ALPHAI, BETA, IWORK,\n $ DWORK, LDWORK, ZWORK, LZWORK, BWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute the eigenvalues of a complex N-by-N skew-Hamiltonian/\nC Hamiltonian pencil aS - bH, with\nC\nC ( A D ) ( B F )\nC S = ( H ) and H = ( H ). (1)\nC ( E A ) ( G -B )\nC\nC This routine computes the eigenvalues using an embedding to a real\nC skew-Hamiltonian/skew-Hamiltonian pencil aB_S - bB_T, defined as\nC\nC ( Re(A) -Im(A) | Re(D) -Im(D) )\nC ( | )\nC ( Im(A) Re(A) | Im(D) Re(D) )\nC ( | )\nC B_S = (-----------------+-----------------) , and\nC ( | T T )\nC ( Re(E) -Im(E) | Re(A ) Im(A ) )\nC ( | T T )\nC ( Im(E) Re(E) | -Im(A ) Re(A ) )\nC (2)\nC ( -Im(B) -Re(B) | -Im(F) -Re(F) )\nC ( | )\nC ( Re(B) -Im(B) | Re(F) -Im(F) )\nC ( | )\nC B_T = (-----------------+-----------------) , T = i*H.\nC ( | T T )\nC ( -Im(G) -Re(G) | -Im(B ) Re(B ) )\nC ( | T T )\nC ( Re(G) -Im(G) | -Re(B ) -Im(B ) )\nC\nC Optionally, if JOB = 'T', the pencil aB_S - bB_H (B_H = -i*B_T) is\nC transformed by a unitary matrix Q to the structured Schur form\nC\nC ( BA BD ) ( BB BF )\nC B_Sout = ( H ) and B_Hout = ( H ), (3)\nC ( 0 BA ) ( 0 -BB )\nC\nC where BA and BB are upper triangular, BD is skew-Hermitian, and\nC BF is Hermitian. The embedding doubles the multiplicities of the\nC eigenvalues of the pencil aS - bH. Optionally, if COMPQ = 'C', the\nC unitary matrix Q is computed.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC JOB CHARACTER*1\nC Specifies the computation to be performed, as follows:\nC = 'E': compute the eigenvalues only; S and H will not\nC necessarily be transformed as in (3).\nC = 'T': put S and H into the forms in (3) and return the\nC eigenvalues in ALPHAR, ALPHAI and BETA.\nC\nC COMPQ CHARACTER*1\nC Specifies whether to compute the unitary transformation\nC matrix Q, as follows:\nC = 'N': Q is not computed;\nC = 'C': compute the unitary transformation matrix Q.\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The order of the pencil aS - bH. N >= 0, even.\nC\nC A (input/output) COMPLEX*16 array, dimension (LDA, K)\nC where K = N/2, if JOB = 'E', and K = N, if JOB = 'T'.\nC On entry, the leading N/2-by-N/2 part of this array must\nC contain the matrix A.\nC On exit, if JOB = 'T', the leading N-by-N part of this\nC array contains the upper triangular matrix BA in (3) (see\nC also METHOD). The strictly lower triangular part is not\nC zeroed, but it is preserved.\nC If JOB = 'E', this array is unchanged on exit.\nC\nC LDA INTEGER\nC The leading dimension of the array A. LDA >= MAX(1, K).\nC\nC DE (input/output) COMPLEX*16 array, dimension\nC (LDDE, MIN(K+1,N))\nC On entry, the leading N/2-by-N/2 lower triangular part of\nC this array must contain the lower triangular part of the\nC skew-Hermitian matrix E, and the N/2-by-N/2 upper\nC triangular part of the submatrix in the columns 2 to N/2+1\nC of this array must contain the upper triangular part of\nC the skew-Hermitian matrix D.\nC On exit, if JOB = 'T', the leading N-by-N part of this\nC array contains the skew-Hermitian matrix BD in (3) (see\nC also METHOD). The strictly lower triangular part of the\nC input matrix is preserved.\nC If JOB = 'E', this array is unchanged on exit.\nC\nC LDDE INTEGER\nC The leading dimension of the array DE. LDDE >= MAX(1, K).\nC\nC B (input/output) COMPLEX*16 array, dimension (LDB, K)\nC On entry, the leading N/2-by-N/2 part of this array must\nC contain the matrix B.\nC On exit, if JOB = 'T', the leading N-by-N part of this\nC array contains the upper triangular matrix BB in (3) (see\nC also METHOD). The strictly lower triangular part is not\nC zeroed; the elements below the first subdiagonal of the\nC input matrix are preserved.\nC If JOB = 'E', this array is unchanged on exit.\nC\nC LDB INTEGER\nC The leading dimension of the array B. LDB >= MAX(1, K).\nC\nC FG (input/output) COMPLEX*16 array, dimension\nC (LDFG, MIN(K+1,N))\nC On entry, the leading N/2-by-N/2 lower triangular part of\nC this array must contain the lower triangular part of the\nC Hermitian matrix G, and the N/2-by-N/2 upper triangular\nC part of the submatrix in the columns 2 to N/2+1 of this\nC array must contain the upper triangular part of the\nC Hermitian matrix F.\nC On exit, if JOB = 'T', the leading N-by-N part of this\nC array contains the Hermitian matrix BF in (3) (see also\nC METHOD). The strictly lower triangular part of the input\nC matrix is preserved. The diagonal elements might have tiny\nC imaginary parts.\nC If JOB = 'E', this array is unchanged on exit.\nC\nC LDFG INTEGER\nC The leading dimension of the array FG. LDFG >= MAX(1, K).\nC\nC Q (output) COMPLEX*16 array, dimension (LDQ, 2*N)\nC On exit, if COMPQ = 'C', the leading 2*N-by-2*N part of\nC this array contains the unitary transformation matrix Q\nC that reduced the matrices B_S and B_H to the form in (3).\nC However, if JOB = 'E', the reduction was possibly not\nC completed: the matrix B_H may have 2-by-2 diagonal blocks,\nC and the array Q returns the orthogonal matrix that\nC performed the partial reduction.\nC If COMPQ = 'N', this array is not referenced.\nC\nC LDQ INTEGER\nC The leading dimension of the array Q.\nC LDQ >= 1, if COMPQ = 'N';\nC LDQ >= MAX(1, 2*N), if COMPQ = 'C'.\nC\nC ALPHAR (output) DOUBLE PRECISION array, dimension (N)\nC The real parts of each scalar alpha defining an eigenvalue\nC of the pencil aS - bH.\nC\nC ALPHAI (output) DOUBLE PRECISION array, dimension (N)\nC The imaginary parts of each scalar alpha defining an\nC eigenvalue of the pencil aS - bH.\nC If ALPHAI(j) is zero, then the j-th eigenvalue is real.\nC\nC BETA (output) DOUBLE PRECISION array, dimension (N)\nC The scalars beta that define the eigenvalues of the pencil\nC aS - bH.\nC Together, the quantities alpha = (ALPHAR(j),ALPHAI(j)) and\nC beta = BETA(j) represent the j-th eigenvalue of the pencil\nC aS - bH, in the form lambda = alpha/beta. Since lambda may\nC overflow, the ratios should not, in general, be computed.\nC\nC Workspace\nC\nC IWORK INTEGER array, dimension (2*N+4)\nC On exit, IWORK(1) contains the number, q, of unreliable,\nC possibly inaccurate (pairs of) eigenvalues, and the\nC absolute values in IWORK(2), ..., IWORK(q+1) are their\nC indices, as well as of the corresponding 1-by-1 and 2-by-2\nC diagonal blocks of the arrays B and A on exit, if\nC JOB = 'T'. Specifically, a positive value is an index of\nC a real or purely imaginary eigenvalue, corresponding to a\nC 1-by-1 block, while the absolute value of a negative entry\nC in IWORK is an index to the first eigenvalue in a pair of\nC consecutively stored eigenvalues, corresponding to a\nC 2-by-2 block. Moreover, IWORK(q+2),..., IWORK(2*q+1)\nC contain pointers to the starting elements in DWORK where\nC each block pair is stored. Specifically, if IWORK(i+1) > 0\nC then DWORK(r) and DWORK(r+1) store corresponding diagonal\nC elements of T11 and S11, respectively, and if\nC IWORK(i+1) < 0, then DWORK(r:r+3) and DWORK(r+4:r+7) store\nC the elements of the block in T11 and S11, respectively\nC (see Section METHOD), where r = IWORK(q+1+i). Moreover,\nC IWORK(2*q+2) contains the number of the 1-by-1 blocks, and\nC IWORK(2*q+3) contains the number of the 2-by-2 blocks,\nC corresponding to unreliable eigenvalues. IWORK(2*q+4)\nC contains the total number t of the 2-by-2 blocks.\nC If INFO = 0, then q = 0, therefore IWORK(1) = 0.\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0 or INFO = 3, DWORK(1) returns the\nC optimal LDWORK, and DWORK(2) and DWORK(3) contain the\nC Frobenius norms of the matrices B_S and B_T. These norms\nC are used in the tests to decide that some eigenvalues are\nC considered as numerically unreliable. Moreover, DWORK(4),\nC ..., DWORK(3+2*s) contain the s pairs of values of the\nC 1-by-1 diagonal elements of T11 and S11. The eigenvalue of\nC such a block pair is obtained from -i*T11(i,i)/S11(i,i).\nC Similarly, DWORK(4+2*s), ..., DWORK(3+2*s+8*t) contain the\nC t groups of pairs of 2-by-2 diagonal submatrices of T11\nC and S11, stored column-wise. The spectrum of such a block\nC pair is obtained from -i*ev, where ev are the eigenvalues\nC of (T11(i:i+1,i:i+1),S11(i:i+1,i:i+1)).\nC On exit, if INFO = -19, DWORK(1) returns the minimum value\nC of LDWORK.\nC\nC LDWORK INTEGER\nC The dimension of the array DWORK. If COMPQ = 'N',\nC LDWORK >= MAX( 3, 4*N*N + 3*N ), if JOB = 'E';\nC LDWORK >= MAX( 3, 5*N*N + 3*N ), if JOB = 'T';\nC LDWORK >= MAX( 3, 11*N*N + 2*N ), if COMPQ = 'C'.\nC For good performance LDWORK should be generally larger.\nC\nC If LDWORK = -1, then a workspace query is assumed;\nC the routine only calculates the optimal size of the\nC DWORK array, returns this value as the first entry of\nC the DWORK array, and no error message related to LDWORK\nC is issued by XERBLA.\nC\nC ZWORK COMPLEX*16 array, dimension (LZWORK)\nC On exit, if INFO = 0, ZWORK(1) returns the optimal LZWORK.\nC On exit, if INFO = -21, ZWORK(1) returns the minimum value\nC of LZWORK.\nC\nC LZWORK INTEGER\nC The dimension of the array ZWORK.\nC LZWORK >= 1, if JOB = 'E'; otherwise,\nC LZWORK >= 6*N + 4, if COMPQ = 'N';\nC LZWORK >= 8*N + 4, if COMPQ = 'C'.\nC\nC If LZWORK = -1, then a workspace query is assumed;\nC the routine only calculates the optimal size of the\nC ZWORK array, returns this value as the first entry of\nC the ZWORK array, and no error message related to LZWORK\nC is issued by XERBLA.\nC\nC BWORK LOGICAL array, dimension (LBWORK)\nC LBWORK >= 0, if JOB = 'E';\nC LBWORK >= N, if JOB = 'T'.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: succesful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal value;\nC = 1: QZ iteration failed in the SLICOT Library routine\nC MB04FD (QZ iteration did not converge or computation\nC of the shifts failed);\nC = 2: QZ iteration failed in the LAPACK routine ZHGEQZ when\nC trying to triangularize the 2-by-2 blocks;\nC = 3: warning: the pencil is numerically singular.\nC\nC METHOD\nC\nC First, T = i*H is set. Then, the embeddings, B_S and B_T, of the\nC matrices S and T, are determined and, subsequently, the SLICOT\nC Library routine MB04FD is applied to compute the structured Schur\nC form, i.e., the factorizations\nC\nC ~ T T ( S11 S12 )\nC B_S = J Q J B_S Q = ( T ) and\nC ( 0 S11 )\nC\nC ~ T T ( T11 T12 )\nC B_T = J Q J B_T Q = ( T ),\nC ( 0 T11 )\nC\nC where Q is real orthogonal, S11 is upper triangular, and T11 is\nC upper quasi-triangular. If JOB = 'T', then the matrices above are\nC ~\nC further transformed so that the 2-by-2 blocks in i*B_T are split\nC into 1-by-1 blocks. If COMPQ = 'C', the transformations are\nC accumulated in the unitary matrix Q.\nC See also page 22 in [1] for more details.\nC\nC REFERENCES\nC\nC [1] Benner, P., Byers, R., Mehrmann, V. and Xu, H.\nC Numerical Computation of Deflating Subspaces of Embedded\nC Hamiltonian Pencils.\nC Tech. Rep. SFB393/99-15, Technical University Chemnitz,\nC Germany, June 1999.\nC\nC NUMERICAL ASPECTS\nC 3\nC The algorithm is numerically backward stable and needs O(N )\nC complex floating point operations.\nC\nC FURTHER COMMENTS\nC\nC The returned eigenvalues are those of the pencil (-i*T11,S11),\nC where i is the purely imaginary unit.\nC\nC If JOB = 'E', the returned matrix T11 is quasi-triangular. Note\nC that the off-diagonal elements of the 2-by-2 blocks of S11 are\nC zero by construction.\nC\nC If JOB = 'T', the returned eigenvalues correspond to the diagonal\nC elements of BB and BA.\nC\nC This routine does not perform any scaling of the matrices. Scaling\nC might sometimes be useful, and it should be done externally.\nC\nC CONTRIBUTOR\nC\nC V. Sima, Research Institute for Informatics, Bucharest, Romania,\nC Nov. 2011.\nC\nC REVISIONS\nC\nC V. Sima, July 2012, Sep. 2016, Nov. 2016, Apr. 2020.\nC\nC KEYWORDS\nC\nC Deflating subspace, embedded pencil, skew-Hamiltonian/Hamiltonian\nC pencil, structured Schur form.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ONE, THREE, ZERO\n PARAMETER ( ONE = 1.0D+0, THREE = 3.0D+0, ZERO = 0.0D+0 )\n COMPLEX*16 CZERO, CONE, CIMAG\n PARAMETER ( CZERO = ( 0.0D+0, 0.0D+0 ),\n $ CONE = ( 1.0D+0, 0.0D+0 ),\n $ CIMAG = ( 0.0D+0, 1.0D+0 ) )\nC\nC .. Scalar Arguments ..\n CHARACTER COMPQ, JOB\n INTEGER INFO, LDA, LDB, LDDE, LDFG, LDQ, LDWORK,\n $ LZWORK, N\nC\nC .. Array Arguments ..\n LOGICAL BWORK( * )\n INTEGER IWORK( * )\n DOUBLE PRECISION ALPHAI( * ), ALPHAR( * ), BETA( * ), DWORK( * )\n COMPLEX*16 A( LDA, * ), B( LDB, * ), DE( LDDE, * ),\n $ FG( LDFG, * ), Q( LDQ, * ), ZWORK( * )\nC\nC .. Local Scalars ..\n LOGICAL LCMPQ, LQUERY, LTRI, UNREL\n CHARACTER*14 CMPQ, JOBF\n INTEGER I, I1, IA, IB, IDE, IEV, IFG, IQ, IQ2, IQB, IS,\n $ IW, IW1, IWRK, J, J1, J2, JM1, JP2, K, L, M,\n $ MINDB, MINDW, MINZW, N2, NB, NC, NN, OPTDW,\n $ OPTZW\n DOUBLE PRECISION NRMBS, NRMBT\n COMPLEX*16 TMP\nC\nC .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\nC\nC .. External Subroutines ..\n EXTERNAL DCOPY, DLACPY, DSCAL, MB04FD, XERBLA, ZGEMM,\n $ ZGEQRF, ZHGEQZ, ZLACPY, ZSCAL\nC\nC .. Intrinsic Functions ..\n INTRINSIC DBLE, DCMPLX, DIMAG, INT, MAX, MIN, MOD\nC\nC .. Executable Statements ..\nC\nC Decode the input arguments.\nC\n M = N/2\n NN = N*N\n N2 = 2*N\n LTRI = LSAME( JOB, 'T' )\n LCMPQ = LSAME( COMPQ, 'C' )\nC\n IF( LTRI ) THEN\n K = N\n ELSE\n K = M\n END IF\nC\n IF( N.EQ.0 ) THEN\n MINDW = 3\n MINZW = 1\n ELSE IF( LCMPQ ) THEN\n MINDB = 8*NN + N2\n MINDW = 11*NN + N2\n MINZW = 8*N + 4\n ELSE\n MINDB = 4*NN + N2\n IF( LTRI ) THEN\n MINDW = 5*NN + 3*N\n ELSE\n MINDW = 4*NN + 3*N\n END IF\n MINZW = 6*N + 4\n END IF\nC\n LQUERY = LDWORK.EQ.-1 .OR. LZWORK.EQ.-1\nC\nC Test the input arguments.\nC\n INFO = 0\n IF( .NOT.( LSAME( JOB, 'E' ) .OR. LTRI ) ) THEN\n INFO = -1\n ELSE IF( .NOT.( LSAME( COMPQ, 'N' ) .OR. LCMPQ ) ) THEN\n INFO = -2\n ELSE IF( N.LT.0 .OR. MOD( N, 2 ).NE.0 ) THEN\n INFO = -3\n ELSE IF( LDA.LT.MAX( 1, K ) ) THEN\n INFO = -5\n ELSE IF( LDDE.LT.MAX( 1, K ) ) THEN\n INFO = -7\n ELSE IF( LDB.LT.MAX( 1, K ) ) THEN\n INFO = -9\n ELSE IF( LDFG.LT.MAX( 1, K ) ) THEN\n INFO = -11\n ELSE IF( LDQ.LT.1 .OR. ( LCMPQ .AND. LDQ.LT.N2 ) ) THEN\n INFO = -13\n ELSE IF( .NOT. LQUERY ) THEN\n IF( LDWORK.LT.MINDW ) THEN\n DWORK( 1 ) = MINDW\n INFO = -19\n ELSE IF( LZWORK.LT.MINZW ) THEN\n ZWORK( 1 ) = MINZW\n INFO = -21\n END IF\n END IF\nC\n IF( INFO.NE.0) THEN\n CALL XERBLA( 'MB04BZ', -INFO )\n RETURN\n ELSE IF( N.GT.0 ) THEN\nC\nC Compute optimal workspace.\nC\n OPTZW = MINZW\n IF( LCMPQ ) THEN\n CMPQ = 'Initialize'\n ELSE\n CMPQ = 'No Computation'\n END IF\nC\n IF( LTRI ) THEN\n JOBF = 'Triangularize'\n CALL ZGEQRF( N, N, ZWORK, N, ZWORK, ZWORK, -1, INFO )\n I = INT( ZWORK( 1 ) )\n NB = MAX( I/N, 2 )\n ELSE\n JOBF = 'Eigenvalues'\n END IF\nC\n IF( LQUERY ) THEN\n CALL MB04FD( JOBF, CMPQ, N2, DWORK, N, DWORK, N, DWORK, N,\n $ DWORK, N, DWORK, N2, ALPHAI, ALPHAR, BETA,\n $ IWORK, DWORK, -1, INFO )\n OPTDW = MAX( MINDW, MINDB + INT( DWORK( 1 ) ) )\n DWORK( 1 ) = OPTDW\n ZWORK( 1 ) = OPTZW\n RETURN\n END IF\n ELSE IF( LQUERY ) THEN\n DWORK( 1 ) = MINDW\n ZWORK( 1 ) = MINZW\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF( N.EQ.0 ) THEN\n IWORK( 1 ) = 0\n DWORK( 1 ) = THREE\n DWORK( 2 ) = ZERO\n DWORK( 3 ) = ZERO\n ZWORK( 1 ) = CONE\n RETURN\n END IF\nC\nC Set up the embeddings of the matrices S and H.\nC\nC Set the pointers for the inputs and outputs of MB04FD.\nC Real workspace: need 4*N**2 + 2*N, if COMPQ = 'N';\nC 8*N**2 + 2*N, if COMPQ = 'C'.\nC\n IQ = 1\n IF( LCMPQ ) THEN\n IA = IQ + N2*N2\n ELSE\n IA = 1\n END IF\nC\n IDE = IA + NN\n IB = IDE + NN + N\n IFG = IB + NN\n IWRK = IFG + NN + N\nC\nC Build the embedding of A.\nC\n IW = IA\n IS = IW + N*M\n DO 30 J = 1, M\n IW1 = IW\n DO 10 I = 1, M\n DWORK( IW ) = DBLE( A( I, J ) )\n IW = IW + 1\n 10 CONTINUE\nC\n DO 20 I = 1, M\n DWORK( IW ) = DIMAG( A( I, J ) )\n DWORK( IS ) = -DWORK( IW )\n IW = IW + 1\n IS = IS + 1\n 20 CONTINUE\n CALL DCOPY( M, DWORK( IW1 ), 1, DWORK( IS ), 1 )\n IS = IS + M\n 30 CONTINUE\nC\nC Build the embedding of D and E.\nC\n IW = IDE\n DO 60 J = 1, M + 1\n DO 40 I = 1, M\n DWORK( IW ) = DBLE( DE( I, J ) )\n IW = IW + 1\n 40 CONTINUE\nC\n IW = IW + J - 1\n IS = IW\n DO 50 I = J, M\n DWORK( IW ) = DIMAG( DE( I, J ) )\n DWORK( IS ) = DWORK( IW )\n IW = IW + 1\n IS = IS + N\n 50 CONTINUE\n 60 CONTINUE\nC\n IW1 = IW\n I1 = IW\n DO 80 J = 2, M + 1\n IS = I1\n I1 = I1 + 1\n DO 70 I = 1, J - 1\n DWORK( IW ) = -DIMAG( DE( I, J ) )\n DWORK( IS ) = DWORK( IW )\n IW = IW + 1\n IS = IS + N\n 70 CONTINUE\n IW = IW + N - J + 1\n 80 CONTINUE\n CALL DLACPY( 'Full', M, M+1, DWORK( IDE ), N, DWORK( IW1-M ), N )\nC\nC Build the embedding of B.\nC\n IW = IB\n IS = IW + N*M\n DO 110 J = 1, M\n IW1 = IW\n DO 90 I = 1, M\n DWORK( IW ) = -DIMAG( B( I, J ) )\n IW = IW + 1\n 90 CONTINUE\nC\n DO 100 I = 1, M\n DWORK( IW ) = DBLE( B( I, J ) )\n DWORK( IS ) = -DWORK( IW )\n IW = IW + 1\n IS = IS + 1\n 100 CONTINUE\n CALL DCOPY( M, DWORK( IW1 ), 1, DWORK( IS ), 1 )\n IS = IS + M\n 110 CONTINUE\nC\nC Build the embedding of F and G.\nC\n IW = IFG\n DO 140 J = 1, M + 1\n DO 120 I = 1, M\n DWORK( IW ) = -DIMAG( FG( I, J ) )\n IW = IW + 1\n 120 CONTINUE\nC\n IW = IW + J - 1\n IS = IW\n DO 130 I = J, M\n DWORK( IW ) = DBLE( FG( I, J ) )\n DWORK( IS ) = DWORK( IW )\n IW = IW + 1\n IS = IS + N\n 130 CONTINUE\n 140 CONTINUE\nC\n IW1 = IW\n I1 = IW\n DO 160 J = 2, M + 1\n IS = I1\n I1 = I1 + 1\n DO 150 I = 1, J - 1\n DWORK( IW ) = -DBLE( FG( I, J ) )\n DWORK( IS ) = DWORK( IW )\n IW = IW + 1\n IS = IS + N\n 150 CONTINUE\n IW = IW + N - J + 1\n 160 CONTINUE\n CALL DLACPY( 'Full', M, M+1, DWORK( IFG ), N, DWORK( IW1-M ), N )\nC\nC STEP 1: Apply MB04FD to transform the extended pencil to real\nC skew-Hamiltonian/skew-Hamiltonian Schur form.\nC\nC Real workspace:\nC need 4*N*N + 2*N + max(3,N), if JOB = 'E' and COMPQ = 'N';\nC 4*N*N + 2*N + max(3,N*N+N), if JOB = 'T' and COMPQ = 'N';\nC 11*N*N + 2*N, if COMPQ = 'C'.\nC prefer larger.\nC\n CALL MB04FD( JOBF, CMPQ, N2, DWORK( IA ), N, DWORK( IDE ), N,\n $ DWORK( IB ), N, DWORK( IFG ), N, DWORK( IQ ), N2,\n $ ALPHAI, ALPHAR, BETA, IWORK, DWORK( IWRK ),\n $ LDWORK-IWRK+1, INFO )\n IF( INFO.EQ.1 ) THEN\n RETURN\n ELSE IF( INFO.EQ.2 ) THEN\n INFO = 3\n END IF\n OPTDW = MAX( MINDW, MINDB + INT( DWORK( IWRK ) ) )\n NRMBS = DWORK( IWRK+1 )\n NRMBT = DWORK( IWRK+2 )\nC\nC Scale the eigenvalues.\nC\n CALL DSCAL( N, -ONE, ALPHAI, 1 )\nC\n IF( LCMPQ ) THEN\nC\nC Set the transformation matrix.\nC\n IW = IQ\n DO 180 J = 1, N2\n DO 170 I = 1, N2\n Q( I, J ) = DCMPLX( DWORK( IW ) )\n IW = IW + 1\n 170 CONTINUE\n 180 CONTINUE\n END IF\nC\nC Count the numbers of pairs of diagonal 1-by-1 and 2-by-2 blocks of\nC B and A with possibly unreliable eigenvalues.\nC\n I = IWORK( 1 )\n IS = 0\n IW = 0\n DO 190 J = 1, I\n IF( IWORK( J+1 ).GT.0 ) THEN\n IS = IS + 1\n ELSE IF( IWORK( J+1 ).LT.0 ) THEN\n IW = IW + 1\n END IF\n 190 CONTINUE\nC\n I = 2*I + 2\n IWORK( I ) = IS\n IWORK( I+1 ) = IW\nC\n IF( LTRI ) THEN\nC\nC Convert the results to complex datatype. D and F start in the\nC first column of DE and FG, respectively.\nC\n IW = IA\n DO 210 J = 1, N\n DO 200 I = 1, J\n A( I, J ) = DCMPLX( DWORK( IW ) )\n IW = IW + 1\n 200 CONTINUE\n IW = IW + N - J\n 210 CONTINUE\nC\n IW = IDE + N\n DO 230 J = 1, N\n DO 220 I = 1, J - 1\n DE( I, J ) = DCMPLX( DWORK( IW ) )\n IW = IW + 1\n 220 CONTINUE\n DE( J, J ) = CZERO\n IW = IW + N - J + 1\n 230 CONTINUE\nC\n IW = IB\n DO 250 J = 1, N\n DO 240 I = 1, MIN( J + 1, N )\n B( I, J ) = DCMPLX( DWORK( IW ) )\n IW = IW + 1\n 240 CONTINUE\n IW = IW + N - J - 1\n 250 CONTINUE\nC\n IW = IFG + N\n DO 270 J = 1, N\n DO 260 I = 1, J - 1\n FG( I, J ) = DCMPLX( DWORK( IW ) )\n IW = IW + 1\n 260 CONTINUE\n FG( J, J ) = CZERO\n IW = IW + N - J + 1\n 270 CONTINUE\nC\n END IF\nC\nC Count the number of diagonal 2-by-2 blocks of B and A.\nC\n I1 = 0\n I = 1\nC WHILE( I.LT.N ) DO\n 280 CONTINUE\n IF ( I.LT.N ) THEN\n IF( ALPHAR( I ).NE.ZERO .AND. BETA( I ).NE.ZERO .AND.\n $ ALPHAR( I ).NE.ZERO ) THEN\n I1 = I1 + 1\n I = I + 2\n ELSE\n I = I + 1\n END IF\n GO TO 280\n END IF\nC END WHILE 280\nC\n I = 2*IWORK( 1 ) + 4\n IWORK( I ) = I1\nC\nC Save in DWORK the pairs of diagonal 1-by-1 and 2-by-2 blocks of\nC B and A. Also, save in IWORK the pointers to the starting element\nC of each pair corresponding to unreliable eigenvalues.\nC\n CALL DCOPY( N, DWORK( IA ), N+1, DWORK( IFG ), 1 )\n DWORK( 1 ) = OPTDW\n DWORK( 2 ) = NRMBS\n DWORK( 3 ) = NRMBT\nC\n K = 4\n I = 1\n IW = IWORK( 1 )\n J = 1\n L = ( N - 2*I1 )*2 + K\nC WHILE( I.LE.N ) DO\n 290 CONTINUE\n IF ( I.LE.N ) THEN\n IF ( J.LE.IW )\n $ UNREL = I.EQ.ABS( IWORK( J+1 ) )\n IF( ALPHAR( I ).NE.ZERO .AND. BETA( I ).NE.ZERO .AND.\n $ ALPHAI( I ).NE.ZERO ) THEN\n IF ( UNREL ) THEN\n J = J + 1\n IWORK( J+IW ) = L\n UNREL = .FALSE.\n END IF\n CALL DLACPY( 'Full', 2, 2, DWORK( IB+(I-1)*(N+1) ), N,\n $ DWORK( L ), 2 )\n L = L + 4\n CALL DCOPY( 2, DWORK( IFG+I-1 ), 1, DWORK( L ), 3 )\n DWORK( L+1 ) = ZERO\n DWORK( L+2 ) = ZERO\n L = L + 4\n I = I + 2\n ELSE\n IF ( UNREL ) THEN\n J = J + 1\n IWORK( J+IW ) = K\n UNREL = .FALSE.\n END IF\n DWORK( K ) = DWORK( IB+(I-1)*(N+1) )\n DWORK( K+1 ) = DWORK( IFG+I-1 )\n K = K + 2\n I = I + 1\n END IF\n GO TO 290\n END IF\nC END WHILE 290\nC\n IF( .NOT.LTRI ) THEN\nC\nC Return.\nC\n ZWORK( 1 ) = OPTZW\n RETURN\n END IF\nC\nC Triangularize the 2-by-2 diagonal blocks in B using the complex\nC version of the QZ algorithm.\nC\nC Set up pointers on the outputs of ZHGEQZ.\nC A block algorithm is used for large N.\nC\n IQ2 = 1\n IEV = 5\n IQ = 9\n IWRK = IQ + 4*( N - 1 )\nC\n J = 1\n J1 = 1\n J2 = MIN( N, NB )\nC WHILE( J.LT.N ) DO\n 300 CONTINUE\n IF( J.LT.N ) THEN\n IF( B( J+1, J ).NE.CZERO ) THEN\nC\nC Triangularization step.\nC Complex workspace: need 4*N + 6.\nC Real workspace: need 4*N + 5.\nC\n NC = MAX( J2-J-1, 0 )\n JM1 = MAX( J-1, 1 )\n JP2 = MIN( J+2, N )\n TMP = A( J+1, J )\n A( J+1, J ) = CZERO\n CALL ZHGEQZ( 'Schur Form', 'Initialize', 'Initialize', 2, 1,\n $ 2, B( J, J ), LDB, A( J, J ), LDA,\n $ ZWORK( IEV ), ZWORK( IEV+2 ), ZWORK( IQ ), 2,\n $ ZWORK( IQ2 ), 2, ZWORK( IWRK ), LZWORK-IWRK+1,\n $ DWORK( 4*N+4 ), IW )\n A( J+1, J ) = TMP\n IF( IW.GT.0 ) THEN\n INFO = 2\n RETURN\n END IF\nC\nC Update A, DE, B, and FG.\nC Complex workspace: need 6*N + 4.\nC\nC Update A.\nC\n CALL ZGEMM( 'No Transpose', 'No Transpose', J-1, 2, 2,\n $ CONE, A( 1, J ), LDA, ZWORK( IQ2 ), 2, CZERO,\n $ ZWORK( IWRK ), JM1 )\n CALL ZLACPY( 'Full', J-1, 2, ZWORK( IWRK ), JM1, A( 1, J ),\n $ LDA )\n CALL ZGEMM( 'Conjugate Transpose', 'No Transpose', 2, NC,\n $ 2, CONE, ZWORK( IQ ), 2, A( J, JP2 ), LDA,\n $ CZERO, ZWORK( IWRK ), 2 )\n CALL ZLACPY( 'Full', 2, NC, ZWORK( IWRK ), 2, A( J, JP2 ),\n $ LDA )\nC\nC Update DE.\nC\n TMP = DE( J+1, J )\n DE( J+1, J ) = -DE( J, J+1 )\n CALL ZGEMM( 'No Transpose', 'No Transpose', J+1, 2, 2,\n $ CONE, DE( 1, J ), LDDE, ZWORK( IQ ), 2, CZERO,\n $ ZWORK( IWRK ), J+1 )\n CALL ZLACPY( 'Full', J+1, 2, ZWORK( IWRK ), J+1, DE( 1, J ),\n $ LDDE )\n CALL ZGEMM( 'Conjugate Transpose', 'No Transpose', 2,\n $ J2-J+1, 2, CONE, ZWORK( IQ ), 2, DE( J, J ),\n $ LDDE, CZERO, ZWORK( IWRK ), 2 )\n CALL ZLACPY( 'Full', 2, J2-J+1, ZWORK( IWRK ), 2,\n $ DE( J, J ), LDDE )\n DE( J+1, J ) = TMP\nC\nC Update B.\nC\n CALL ZGEMM( 'No Transpose', 'No Transpose', J-1, 2, 2,\n $ CONE, B( 1, J ), LDB, ZWORK( IQ2 ), 2, CZERO,\n $ ZWORK( IWRK ), JM1 )\n CALL ZLACPY( 'Full', J-1, 2, ZWORK( IWRK ), JM1, B( 1, J ),\n $ LDB )\n CALL ZGEMM( 'Conjugate Transpose', 'No Transpose', 2, NC,\n $ 2, CONE, ZWORK( IQ ), 2, B( J, JP2 ), LDB,\n $ CZERO, ZWORK( IWRK ), 2 )\n CALL ZLACPY( 'Full', 2, NC, ZWORK( IWRK ), 2, B( J, JP2 ),\n $ LDB )\nC\nC Update FG.\nC\n TMP = FG( J+1, J )\n FG( J+1, J ) = -FG( J, J+1 )\n CALL ZGEMM( 'No Transpose', 'No Transpose', J+1, 2, 2,\n $ CONE, FG( 1, J ), LDFG, ZWORK( IQ ), 2, CZERO,\n $ ZWORK( IWRK ), J+1 )\n CALL ZLACPY( 'Full', J+1, 2, ZWORK( IWRK ), J+1, FG( 1, J ),\n $ LDFG )\n CALL ZGEMM( 'Conjugate Transpose', 'No Transpose', 2,\n $ J2-J+1, 2, CONE, ZWORK( IQ ), 2, FG( J, J ),\n $ LDFG, CZERO, ZWORK( IWRK ), 2 )\n CALL ZLACPY( 'Full', 2, J2-J+1, ZWORK( IWRK ), 2,\n $ FG( J, J ), LDFG )\n FG( J+1, J ) = TMP\nC\n IF( LCMPQ ) THEN\nC\nC Update Q.\nC Complex workspace: need 8*N + 4.\nC\n CALL ZGEMM( 'No Transpose', 'No Transpose', N2, 2, 2,\n $ CONE, Q( 1, J ), LDQ, ZWORK( IQ2 ), 2,\n $ CZERO, ZWORK( IWRK ), N2 )\n CALL ZLACPY( 'Full', N2, 2, ZWORK( IWRK ), N2, Q( 1, J ),\n $ LDQ )\n CALL ZGEMM( 'No Transpose', 'No Transpose', N2, 2, 2,\n $ CONE, Q( 1, N+J ), LDQ, ZWORK( IQ ), 2,\n $ CZERO, ZWORK( IWRK ), N2 )\n CALL ZLACPY( 'Full', N2, 2, ZWORK( IWRK ), N2,\n $ Q( 1, N+J ), LDQ )\n END IF\nC\n BWORK( J ) = .TRUE.\n J = J + 2\n IQ = IQ + 4\n ELSE\n BWORK( J ) = .FALSE.\n B( J+1, J ) = CZERO\n J = J + 1\n END IF\nC\n IF( J.GE.J2 ) THEN\n J1 = J2 + 1\n J2 = MIN( N, J1 + NB - 1 )\n NC = J2 - J1 + 1\nC\nC Update the columns J1 to J2 of A, DE, B, and FG for previous\nC transformations.\nC\n I = 1\n IQB = 9\nC WHILE( I.LT.J ) DO\n 310 CONTINUE\n IF( I.LT.J ) THEN\n IF( BWORK( I ) ) THEN\n CALL ZGEMM( 'Conjugate Transpose', 'No Transpose', 2,\n $ NC, 2, CONE, ZWORK( IQB ), 2, A( I, J1 ),\n $ LDA, CZERO, ZWORK( IWRK ), 2 )\n CALL ZLACPY( 'Full', 2, NC, ZWORK( IWRK ), 2,\n $ A( I, J1 ), LDA )\nC\n CALL ZGEMM( 'Conjugate Transpose', 'No Transpose', 2,\n $ NC, 2, CONE, ZWORK( IQB ), 2,\n $ DE( I, J1 ), LDDE, CZERO, ZWORK( IWRK ),\n $ 2 )\n CALL ZLACPY( 'Full', 2, NC, ZWORK( IWRK ), 2,\n $ DE( I, J1 ), LDDE )\nC\n CALL ZGEMM( 'Conjugate Transpose', 'No Transpose', 2,\n $ NC, 2, CONE, ZWORK( IQB ), 2, B( I, J1 ),\n $ LDB, CZERO, ZWORK( IWRK ), 2 )\n CALL ZLACPY( 'Full', 2, NC, ZWORK( IWRK ), 2,\n $ B( I, J1 ), LDB )\nC\n CALL ZGEMM( 'Conjugate Transpose', 'No Transpose', 2,\n $ NC, 2, CONE, ZWORK( IQB ), 2,\n $ FG( I, J1 ), LDFG, CZERO, ZWORK( IWRK ),\n $ 2 )\n CALL ZLACPY( 'Full', 2, NC, ZWORK( IWRK ), 2,\n $ FG( I, J1 ), LDFG )\n IQB = IQB + 4\nC\n I = I + 2\n ELSE\n I = I + 1\n END IF\n GO TO 310\n END IF\nC END WHILE 310\n END IF\n GO TO 300\n END IF\nC END WHILE 300\nC\nC Scale B and FG by -i.\nC\n DO 320 I = 1, N\n CALL ZSCAL( I, -CIMAG, B( 1, I ), 1 )\n 320 CONTINUE\nC\n DO 330 I = 1, N\n CALL ZSCAL( I, -CIMAG, FG( 1, I ), 1 )\n 330 CONTINUE\nC\n ZWORK( 1 ) = OPTZW\n RETURN\nC *** Last line of MB04BZ ***\n END\n", "meta": {"hexsha": "cef0b31825ac723fd8c22dac8b6fbb2df47a6e28", "size": 34548, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB04BZ.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB04BZ.f", "max_issues_repo_name": "bnavigator/SLICOT-Reference", "max_issues_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB04BZ.f", "max_forks_repo_name": "bnavigator/SLICOT-Reference", "max_forks_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 35.2530612245, "max_line_length": 72, "alphanum_fraction": 0.4617054533, "num_tokens": 11294, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9353465134460243, "lm_q2_score": 0.7090191460821871, "lm_q1q2_score": 0.663178586254451}} {"text": "!=======================================================================\n!\n subroutine calll(x1,x2,y1,y2,dum,dum1,n1,n2,dipok,v1,v2,dv1d1,dv1d2,dv2d1,dv2d2)\n USE TIPrecision \n \nIMPLICIT NONE \n \n \n ! Local variables. \n \nINTEGER(4) :: nvar, istr,nok,nbad \n \nREAL(DbKi) :: n1,n2,small,pi,pi2,r1,r2,rsq,z,x,thet1\nREAL(DbKi) :: dipok, v1_t,v2_t, dv1d1_t,dv1d2_t,dv2d1_t,dv2d2_t\nREAL(DbKi) :: v1,v2,dv1d1,dv1d2,dv2d1,dv2d2,x1,x2,y1,y2,dum,dum1 \n \n\n! \n small = 1.0D-12 \n pi = dacos(-1.0d0) \n pi2 = 2.0d0*dacos(-1.0d0) \n! R1s = (x1-s1a)**2+(x2-s2a)**2 \n! R2s = (x1-s1b)**2+(x2-s2b)**2 \n r1 = (x1 - y1) \n r2 = (x2 - y2) \n rsq = r1**2+r2**2\n z = r1*n1+r2*n2\n x = r1*n2-r2*n1\n if(z.gt.small) then\n if(x.lt.small) then\n thet1 = datan(DBLE(z/x))+pi\n elseif(abs(x).le.small) then\n thet1 = 0.5d0*pi\n elseif(x.gt.small) then \n thet1 = datan(DBLE(z/x))\n endif\n elseif(abs(z).le.small) then\n if(x.lt.small) then\n thet1 = 0.0d0\n elseif(abs(x).le.small) then\n write(*,*) 'SHITA!'\n stop\n elseif(x.gt.small) then \n! write(*,*) 'SHITB!'\n! write(*,*) x1,x2,y1,y2\n thet1 = 0.0d0\n! stop\n endif\n else\n if(x.lt.small) then\n thet1 = datan(DBLE(z/x))-pi\n elseif(abs(x).le.small) then\n thet1 = -0.5d0*pi\n elseif(x.gt.small) then \n thet1 = datan(DBLE(z/x))\n endif\n endif\n!\n dipok = -thet1/pi2\n v1_t = z/pi2*(1.0d0/rsq)\n v2_t = -1.0d0/pi2*(x/rsq)\n dv1d1_t = -z*x/(pi*rsq**2)\n dv1d2_t = (rsq-2.0d0*z**2)/(2.0d0*pi*rsq**2)\n dv2d1_t = dv1d2_t\n dv2d2_t = -dv1d1_t\n v1 = +n1*v2_t+n2*v1_t\n v2 = n2*v2_t-n1*v1_t\n dv1d1 = n2**2*dv1d1_t+n1*n2*(dv1d2_t+dv2d1_t)+n1**2*dv2d2_t\n dv1d2 = n2**2*dv1d2_t-n1*n2*(dv1d1_t-dv2d2_t)-n1**2*dv2d1_t\n dv2d1 = n2**2*dv2d1_t-n1*n2*(dv1d1_t-dv2d2_t)-n1**2*dv1d2_t\n dv2d2 = n2**2*dv2d2_t-n1*n2*(dv1d2_t+dv2d1_t)+n1**2*dv1d1_t\n\n\n\n return\n end\n", "meta": {"hexsha": "d20ede18e5eb20107705beb1b551111e900281ed", "size": 2807, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "modules/aerodyn/src/AeroAcoustics/TINoise/WAKE.f90", "max_stars_repo_name": "CarloSucameli/Openfast-noise", "max_stars_repo_head_hexsha": "b695c53ff790ac390f9fcf7ec1bf67e24688deb0", "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": "modules/aerodyn/src/AeroAcoustics/TINoise/WAKE.f90", "max_issues_repo_name": "CarloSucameli/Openfast-noise", "max_issues_repo_head_hexsha": "b695c53ff790ac390f9fcf7ec1bf67e24688deb0", "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/aerodyn/src/AeroAcoustics/TINoise/WAKE.f90", "max_forks_repo_name": "CarloSucameli/Openfast-noise", "max_forks_repo_head_hexsha": "b695c53ff790ac390f9fcf7ec1bf67e24688deb0", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.4545454545, "max_line_length": 86, "alphanum_fraction": 0.3747773424, "num_tokens": 961, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465170505205, "lm_q2_score": 0.7090191399336402, "lm_q1q2_score": 0.663178583059086}} {"text": "C N.B.S APPLIED MATHEMATICS SERIES,\nC PUBLICATION 55\nC SEE P 299, SERIES NUMBER 7.1.26\nC ACCURACY: ERROR LT 1.5 X 10**(-7)\nC\nC FOLLOWS IBM ERROR FUNCTION HANDLING--\nC I.E. ERF(-X) = -ERF(X)\nC RANGE OF VALUES+ -1 TO +1\nC\nC\nc 18-May-94 note! in call to DERF, \"x\" is NOT in\nc units of standard deviations! To get the\nc integral of a Gaussian distribution out\nc of this, divide \"x\" by sqrt(2.) !\nc\nc\nc***********************************************\nc\n real function derf(x)\nc\nc***********************************************\nc\nc modified 3/22/96 by J. Dwyer for sdf_lister\nc\n IMPLICIT REAL*8 (A-H,O-Z)\n XLC=X\n IF(XLC.LT.0.D0) XLC=-X\n T= 1.D0/(1.D0 + (0.3275911D0)*XLC)\n T2= T*T\n T3= T*T2\n T4= T*T3\n T5= T*T4\n EZX=DEXP(-XLC*XLC)\n DERF = 1.D0 -\n * ((0.254829592D0)*T\n * - (0.284496736D0)*T2\n * + (1.421413741D0)*T3\n * - (1.453152027D0)*T4\n * + (1.061405429D0)*T5)*EZX\n IF(X.LT.0.D0) DERF=-DERF\n RETURN\n END ! end derf\n", "meta": {"hexsha": "519a75815fd3df6e38a83b2c31ba7f88794d5ae4", "size": 1252, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "EPACE_STEP_code/sdf_lister/DERF.f95", "max_stars_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_stars_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "EPACE_STEP_code/sdf_lister/DERF.f95", "max_issues_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_issues_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "EPACE_STEP_code/sdf_lister/DERF.f95", "max_forks_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_forks_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.1162790698, "max_line_length": 65, "alphanum_fraction": 0.4249201278, "num_tokens": 426, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.935346504434783, "lm_q2_score": 0.7090191337850932, "lm_q1q2_score": 0.6631785683632646}} {"text": " SUBROUTINE svd_solve(m, n, mp, np, a, b, v, w, nw, small)\n USE stel_kinds\n IMPLICIT NONE\nC-----------------------------------------------\nC D u m m y A r g u m e n t s\nC-----------------------------------------------\n INTEGER m, n, mp, np, nw\n REAL(rprec), DIMENSION(mp,np) :: a\n REAL(rprec), DIMENSION(n,n) :: v\n REAL(rprec), DIMENSION(n) :: w\n REAL(rprec), DIMENSION(m) :: b\n REAL(rprec) :: small\nC-----------------------------------------------\nC L o c a l P a r a m e t e r s\nC-----------------------------------------------\n! REAL(rprec) :: small = 1.0e-10_dp\nC-----------------------------------------------\nC L o c a l V a r i a b l e s\nC-----------------------------------------------\n INTEGER :: istat, i, j\n REAL(rprec), ALLOCATABLE :: u(:,:)\nC-----------------------------------------------\n\nc Solves Matrix equation A * V = B for V using SVD method\nc Uses svd routines from numerical recipes\nc Prashant Valanju (Dec 1998) pvalanju@mail.utexas.edu\n\nc Almost same as SvdSolveB except this one finds\nc nw solutions V(:,i) by keeping i = 1 to nw vectors, where\nc nw is the number of vectors with nonzero weights > small\n\nc It also uses V internally for SVD decomposition to save space, so\n\nc Inputs:\nc A(M,N) - Matrix with physical dimensions (Mp,Np)\nc B(M) - R.H.S. of A X = B\nc M - Number of rows of A to use\nc N - Number of columns of A to use\nc Mp,Np - Storage dimensions of A(Mp,Np)\nc\nc Output:\nc nw - number of vectors with normalized weights above small\nc Eventually, this will be the number of optimum weights\nc after we decide on a criterion for optimization\nc V(N,nw) - nw Solutions of A V = B, each a vector of length N\nc V(:N,iw) = solution with top iw weights kept\nc Physical dimensions of V are (N,N)\nc w(n) - Weights in decreasing order\nc\n\nc Allocate local arrays.\nc Note u(m,n) is enough because needed part of a(mp,np) is copied to\nc u(m,n), and a(mp,np) is never used directly. This saves space.\nc It is essential to USE a local u since svdcmp changes it\n\n ALLOCATE (u(m,n), stat=istat)\n IF(istat.ne.0) STOP 'Stop: No memory in svd_nesc'\n\nc.......................................\nc Initialize ALL to zero to wipe out effects of old CALL\n w(:n) = 0 !Zero ALL weights\n DO j = 1, n\n u(:m,j) = a(:m,j) !Because U will be changed by svdcmp\n v(:n,j) = 0\n END DO\n\nc Do the SVD decomposition of a, i.e, of u into u, v and w\n CALL svdcmp (u, m, n, m, n, w, v)\n\nc Sort weights and matrices with DECREASING weights so w(1) is biggest\nc Permute weight w(i) AND column vectors U(*,i), V(*,i) at the same time\n CALL sortsvd (m, n, m, n, w, u, v)\n\nc Find nw = number of large weights (dcreasing ordered by sortsvd)\n DO nw = n, 1, -1 !Find first large weight and get out\n IF ( ABS(w(nw)/w(1)) .gt. small) EXIT\n END DO\n\nc Find nw solutions by successively adding up eigenvectors V\nc with correct weight given by (U(i) dot b)/w(i) in eq 14.3.17 (NR).\nc The coeff of ith vector V(i) is the dot product of the i-th column\nc of U with the rhs vector B, divided by w(i)\nc This does the svdbksb directly, faster than the NR svdbksub routine\nc and uses less memory due to the dual role of V\nc Note: any optimization scheme to find the 'best' nw will\n\nc First set the 1st vector with largest weight w(1)\n v(:n,1) = SUM(u(:m,1)*b(:m)) *v(:n,1) /w(1)\nc Next add the vectors with successive weights (in decreasing order)\n DO i = 2, nw\n j = i - 1\n v(:n,i) = v(:n,j) + SUM(u(:m,i)*b(:m)) *v(:n,i) / w(i)\n END DO\nc................................................\n\n DEALLOCATE (u, stat=istat)\n\n END SUBROUTINE svd_solve\n", "meta": {"hexsha": "b30d537d75dfeb3dc63cd109caaf4146387350a3", "size": 3983, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Sources/SVDpack/svd_solve.f", "max_stars_repo_name": "ORNL-Fusion/libstell", "max_stars_repo_head_hexsha": "92ac5c339b31e29d9d734c20eae3e7571de8f490", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-10-19T06:24:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-08T21:10:12.000Z", "max_issues_repo_path": "Sources/SVDpack/svd_solve.f", "max_issues_repo_name": "ORNL-Fusion/libstell", "max_issues_repo_head_hexsha": "92ac5c339b31e29d9d734c20eae3e7571de8f490", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-09-21T14:00:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-03T00:48:39.000Z", "max_forks_repo_path": "Sources/SVDpack/svd_solve.f", "max_forks_repo_name": "ORNL-Fusion/LIBSTELL", "max_forks_repo_head_hexsha": "ba938c678d776b84d7bb260ea541a9b45deb37e2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.2323232323, "max_line_length": 80, "alphanum_fraction": 0.5320110469, "num_tokens": 1153, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587964389112, "lm_q2_score": 0.7461389986757758, "lm_q1q2_score": 0.6631375984392168}} {"text": "!===============================================================================\nprogram CIJ_BandS_axes\n!===============================================================================\n! CIJ_BandS_axes reads constants from stdin, or from a file, and returns information\n! about the tensor symmetry and the orientation of the symmetry axes, via the\n! process described by Browaeys & Chvrot, GJI, 2004.\n\n use anisotropy_ajn\n\n implicit none\n\n logical :: all = .true., Xout = .false., iso = .false., hex = .false., &\n tet = .false., ort = .false., mon = .false., tri = .false., &\n read_file = .true., rotate = .false., symmetry = .false., sum = .false.\n real(8), dimension(6,6) :: C, Ciso, Chex, Ctet, Cort, Cmon, Ctri, CR\n real(8) :: rho, R(3,3), x1(3), x2(3), x3(3)\n character(len=500) :: file, arg, symm\n integer :: iostat, i, j\n\n call get_args\n\n if (read_file) then\n call CIJ_load(file, C, rho)\n C = C/rho\n else\n read(*,'(a)',iostat=iostat) arg\n if (iostat /= 0) call bad_read('')\n ! 36 ecs\n read(arg,*,iostat=iostat) C\n if (iostat > 0) call bad_read('36')\n if (iostat < 0) then ! EOF\n ! 21 ecs\n read(arg,*,iostat=iostat) ((C(i,j), j=i,6), i=1,6)\n if (iostat /= 0) call bad_read('21')\n do i=1,6; do j=i+1,6; C(j,i) = C(i,j); enddo; enddo\n endif\n endif\n\n ! Find symmetry and axes\n call CIJ_brow_chev_symm(C, CR=CR, R=R, symm=symm)\n x1 = R(:,1)\n x2 = R(:,2)\n x3 = R(:,3)\n\n ! If desired, rotate into optimum orientation before decomposing, otherwise leave\n if (rotate) C = CR\n\n call CIJ_brow_chev(C, Ciso, Chex, Ctet, Cort, Cmon, Ctri)\n\n if (all .or. symmetry) call write_symm(symm)\n\n if (.not.sum .and. any([all, iso, hex, tet, ort, mon, tri])) then\n if (all .or. iso) call write_C('Ciso:', Ciso)\n if (all .or. hex) call write_C('Chex:', Chex)\n if (all .or. tet) call write_C('Ctet:', Ctet)\n if (all .or. ort) call write_C('Cort:', Cort)\n if (all .or. mon) call write_C('Cmon:', Cmon)\n if (all .or. tri) call write_C('Ctri:', Ctri)\n endif\n \n if (sum) then\n C = 0._8\n if (all .or. iso) C = C + Ciso\n if (all .or. hex) C = C + Chex\n if (all .or. tet) C = C + Ctet\n if (all .or. ort) C = C + Cort\n if (all .or. mon) C = C + Cmon\n if (all .or. tri) C = C + Ctri\n call write_C('Csum:', C)\n endif\n\n if (all .or. Xout) call write_X(x1, x2, x3)\n\n\ncontains\n subroutine usage(help)\n logical, intent(in), optional :: help\n logical :: stdout\n integer :: lu\n stdout = .false.\n if (present(help)) stdout = help\n lu = 0\n if (stdout) lu = 6\n write(lu,'(a)') &\n 'Usage: CIJ_BandS_axes (options) [file]', &\n 'Return information about the symmetry and the symmetry axes of a tensor', &\n ' read from file or from a list of Cij from stdin if is \"-\".', &\n 'The outputs are chosen as flags read on the command line and are printed', &\n ' prefaced by:', &\n ' Ciso, Chex, Ctet, Cort, Cmon, Ctri : Elastic constants from unrotated', &\n ' input tensor', &\n ' x1, x2, x3 : Symmetry axes', &\n 'Options:', &\n ' -a: Return all information [default]', &\n ' -R: Rotate elastic constants before decomposition', &\n ' -S: Write only the sum of the desired terms (e.g., Ciso+Chex)', &\n ' -X: Provide symmetry axes, in order x{1,2,3}, as cartesian unit vectors', &\n ' -i: Return isotropic part', &\n ' -h: Return hexagonal part', &\n ' -t: Return tetragonal part', &\n ' -o: Return orthorhombic part', &\n ' -m: Return monoclinic part', &\n ' -r: Return triclinic part', &\n ' -s: Return symmetry name', &\n ' --help: Print this message'\n if (stdout) then\n stop\n else\n error stop\n endif\n end subroutine usage\n\n subroutine get_args\n integer :: iarg, narg, ichar\n narg = command_argument_count()\n if (narg < 1) call usage\n iarg = 1\n do while (iarg <= narg - 1)\n call get_command_argument(iarg, arg)\n if (arg == '--help') call usage(help=.true.)\n select case (arg(1:1))\n case ('-')\n ichar = 2\n do while (ichar <= len_trim(arg))\n select case (arg(ichar:ichar))\n case ('a'); all = .true.\n case ('R'); rotate = .true.\n case ('S'); sum = .true.\n case ('X'); all = .false.; Xout = .true.\n case ('i'); all = .false.; iso = .true.\n case ('h'); all = .false.; hex = .true.\n case ('t'); all = .false.; tet = .true.\n case ('o'); all = .false.; ort = .true.\n case ('m'); all = .false.; mon = .true.\n case ('r'); all = .false.; tri = .true.\n case ('s'); all = .false.; symmetry = .true.\n case default; call usage\n end select\n ichar = ichar + 1\n enddo\n case default; call usage\n end select\n iarg = iarg + 1\n enddo\n call get_command_argument(narg, file)\n if (file == '-') read_file = .false.\n if (file == '--help') call usage(help=.true.)\n end subroutine get_args\n\n subroutine write_C(str, CC)\n character(len=*), intent(in) :: str\n real(8), intent(in) :: CC(6,6)\n write(*,'(a,36(1x,es14.7))') trim(str), CC\n end subroutine write_C\n\n subroutine write_X(xx1, xx2, xx3)\n real(8), intent(in), dimension(3) :: xx1, xx2, xx3\n write(*,'(a,3f10.6))') 'x1:', xx1, 'x2:', xx2, 'x3:', xx3\n end subroutine write_X\n\n subroutine write_symm(str)\n character(len=*), intent(in) :: str\n write(*,'(a)') 'Symmetry: ' // trim(str)\n end subroutine write_symm\n\n subroutine bad_read(str)\n character(len=*), intent(in) :: str\n write(0,'(a)') 'CIJ_BandS_axes: Error: Error reading ' // trim(str) // &\n ' ecs from stdin'\n error stop\n end subroutine bad_read\nend program CIJ_BandS_axes\n!-------------------------------------------------------------------------------", "meta": {"hexsha": "3ad1e0a895b07b07b29b4fe8aa1475a6b0274fb4", "size": 6364, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "CIJ_BandS_axes/CIJ_BandS_axes.f90", "max_stars_repo_name": "anowacki/elasticity", "max_stars_repo_head_hexsha": "ba17bcfc8a8dd8dd881f200997526bffaca3e781", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2017-03-29T21:32:13.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-21T14:47:06.000Z", "max_issues_repo_path": "CIJ_BandS_axes/CIJ_BandS_axes.f90", "max_issues_repo_name": "anowacki/elasticity", "max_issues_repo_head_hexsha": "ba17bcfc8a8dd8dd881f200997526bffaca3e781", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "CIJ_BandS_axes/CIJ_BandS_axes.f90", "max_forks_repo_name": "anowacki/elasticity", "max_forks_repo_head_hexsha": "ba17bcfc8a8dd8dd881f200997526bffaca3e781", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-30T05:31:13.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-30T05:31:13.000Z", "avg_line_length": 36.7861271676, "max_line_length": 89, "alphanum_fraction": 0.4996857322, "num_tokens": 1900, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853654, "lm_q2_score": 0.746138993030751, "lm_q1q2_score": 0.6631375956206158}} {"text": " SUBROUTINE rubber2d(pr,lb,model,stre,r1,r2,vec)\r\n\r\n ! calculates stiffness and stresses for rubber and elastomeric\r\n ! foam materials\r\n\r\n IMPLICIT NONE\r\n ! DUMMY arguments\r\n REAL(kind=8), INTENT(IN):: pr(12) !(12) material constants\r\n REAL(kind=8), INTENT(IN OUT):: lb(3) !(3) Principal stretches Eigenvalues of U\r\n INTEGER(kind=4), INTENT(IN OUT) :: model !Model\r\n !1: Arruda-Boyce\r\n !2: Mooney-Rivlin\r\n !3: Neo-Hooke\r\n !4: Ogden (N=1)\r\n !5: Ogden (N=2)\r\n !6: Ogden (N=3)\r\n !7: Polynomial (N=1)\r\n !8: Polynomial (N=2)\r\n !9: Polynomial (N=3)\r\n !10: Reduced Polynomial (N=1)\r\n !11: Reduced Polynomial (N=2)\r\n !12: Reduced Polynomial (N=3)\r\n !13: Van der Waals (not implemented yet)\r\n !14: Yeoh\r\n !15: Hyperfoam (N=1)\r\n !16: Hyperfoam (N=2)\r\n !17: Hyperfoam (N=3)\r\n REAL(kind=8), INTENT(OUT) :: stre(:) ! 2nd Piola-Kirchhoff stresses S11 S22 S12 S33\r\n REAL(kind=8), INTENT(IN):: r1,r2 ! first eigenvector in-plane components\r\n ! optional arguments\r\n REAL(kind=8), OPTIONAL, INTENT(OUT) :: vec(:) !elasticity (stiffness) matrix in vector form\r\n\r\n\r\n ! Local variables\r\n REAL(kind=8) :: &\r\n lbg(3),lbb(3), & !principal strains of G U & U_bar\r\n bet(3),p, & !Biot principal stresses and Kirchhoff press\r\n d(3,4), & ! first derivatives of invariants and auxiliar values\r\n dd(3,4), & ! second derivatives of invariants\r\n c(7),cc, & ! local elasticity matrix\r\n i1,i2,det,j3,j23,j32,aux,a1,a2,a3,a4,a5,i13,i23,det2, & ! auxiliar terms\r\n r11,r22,r12,r1111,r2222,r1122,r1112,r1222 !,r(3,3),v(10) !auxiliar rotation terms\r\n\r\n LOGICAL :: ci1, ci2 ! use first and second invariants\r\n\r\n INTEGER(kind=4) nterm, & ! number of terms (sum) in the model\r\n kode, & ! model\r\n i,j,k,l ! index and pointers\r\n\r\n INTEGER(kind=4), PARAMETER :: ij(3,3) = (/ 1,0,0,4,2,0,5,6,3 /) !, &\r\n !kk(4,10) = (/1,1,1,1, 1,1,2,2, 1,1,1,2, 1,1,3,3, &\r\n ! 2,2,2,2, 2,2,1,2, 2,2,3,3, &\r\n ! 1,2,1,2, 1,2,3,3, &\r\n ! 3,3,3,3 /)\r\n\r\n !initializes Flags\r\n ci1 = .TRUE. !compute I1 invariant derivatives for model 1-3, 7-14\r\n ci2 = .FALSE. !do NOT compute I2 derivatives but for model 2, 7-9\r\n kode = model !strain energy model\r\n SELECT CASE (kode)\r\n CASE (2) !Mooney Rivlin\r\n ci2 = .TRUE. !compute second invariant derivatives\r\n CASE (4:6) !Ogden\r\n nterm = kode - 3 !number of terms to be considered\r\n ci1 = .FALSE. !do not compute 1st invariant derivatives\r\n CASE (7:9) !Polynomial\r\n nterm = kode - 6 !number of terms to be considered\r\n ci2 = .TRUE. !compute second invariant derivatives\r\n CASE (10:12)!reduced polynomial\r\n nterm = kode - 9 !number of terms to be considered\r\n CASE (14) !yeoh\r\n kode = 12 !reduced polynomial\r\n nterm = 3 !number of terms to be considered\r\n CASE (15:17) !hyperfoam (highly compressible)\r\n CALL runen2(' Hyperfoam not implemented yet')\r\n !nterm = kode - 14 !number of terms to be considered\r\n END SELECT\r\n\r\n\r\n lbg = lb**2 !eigenvalues of C\r\n det = lb(1)*lb(2)*lb(3) !J\r\n det2 = det*det !J^2\r\n j23 = det2**(-1d0/3d0) ![J^(-1/3)]^2\r\n j3 = SQRT(j23) ![J^(-1/3)]\r\n lbb= lb*j3 !deviatoric eigenvalues of U\r\n\r\n ! COMPUTE FIRST DERIVATIVES OF THE INVARIANTS IF NECESSARY\r\n IF( ci1 )THEN\r\n ! first derivatives of I1\r\n i1 =(lbg(1)+lbg(2)+lbg(3))*j23 !1st deviatoric invariant of G\r\n j32 = 2d0*j3 !2/j^(1/3)\r\n DO i=1,3\r\n d(i,3) = lbb(i)**2 !lbb**2\r\n d(i,1) = j32*lbb(i)*(1d0-i1/3d0/d(i,3)) !I1,l1\r\n END DO\r\n IF( ci2 )THEN\r\n i2 =(lbg(1)*lbg(2)+lbg(1)*lbg(3)+lbg(2)*lbg(3))*j23**2 !2nd deviatoric invariant of G\r\n ! first derivatives of I2\r\n DO i=1,3\r\n d(i,2) = j32*lbb(i)*(i1 - d(i,3) - 2d0*i2/3d0/d(i,3)) !I2,l1\r\n END DO\r\n END IF\r\n END IF\r\n\r\n ! COMPUTE FIRST DERIVATIVE OF THE STRAIN FUNCTION ==> BET_I\r\n SELECT CASE (kode)\r\n CASE (1) !Arruda-Boyce\r\n ! pr(5) = Mu/5/lm^2, pr(6) = Mu 11/350/lm^4, pr(7) =Mu 19/1750/lm^6, ! pr(8) =Mu 519/134750/lm^8\r\n a1 = pr(4)+i1*(pr(5)+i1*(pr(6)+i1*(pr(7)+i1*pr(8)))) !Phi,I1\r\n bet = a1*d(:,1) !principal Biot stresses\r\n ! pressure\r\n cc = 1d0/pr(3) !inverse compresibility\r\n p = cc*(det2-1d0) !kirchhoff pressure\r\n\r\n CASE (2) !Mooney-Rivlin\r\n a1 = pr(1)\r\n a2 = pr(2)\r\n bet = a1*d(:,1) + a2*d(:,2) !principal Biot stresses\r\n ! pressure\r\n cc = 1d0/pr(3) !inverse compresibility & Phi,J,J\r\n p = cc*det*(det-1d0) !kirchhoff pressure\r\n\r\n CASE (3) !Neo-Hookean\r\n a1 = pr(1)\r\n bet = a1*d(:,1) !principal Biot stresses\r\n ! pressure\r\n cc = 1d0/pr(3) !inverse compresibility & Phi,J,J\r\n p = cc*det*(det-1d0) !kirchhoff pressure\r\n\r\n CASE (4:6) !ogden\r\n bet = 0d0 !initializes diagonal stresses\r\n k = 1 !pointer to properties array\r\n DO j=1,nterm !for each term\r\n a1 = pr(k+1) !exponent alpha\r\n d(:,j) = lbb**a1 !l1^alpha_i\r\n d(j,4) = SUM(d(:,j))/3d0 !ap\r\n bet = bet + pr(k)*(d(:,j) - d(j,4)) !principal Kirchhoff stresses\r\n k = k+2 !update pointer\r\n END DO\r\n bet = bet/lb !principal Biot Stress\r\n ! pressure\r\n cc = 1d0/pr(10) !inverse compresibility & Phi,J,J\r\n p = cc*det*(det-1d0) !kirchhoff pressure\r\n\r\n CASE ( 7: 9) !polynomial model\r\n i13 = i1 - 3d0 !I1 -3\r\n i23 = i2 - 3d0 !I2 - 3\r\n a1 = pr(1) !initializes Phi,I1\r\n a2 = pr(2) !initializes Phi,I2\r\n ! for pressure\r\n aux = det - 1d0 !j-1\r\n a3 = aux*det*2d0 !2J*(J-1)\r\n p = 1d0/pr(10) !initializes pressure\r\n cc = p !initializes compresibility\r\n IF( nterm > 1 )THEN\r\n a1 = a1+2d0*pr(3)*i13 + pr(4)*i23 !Phi,I1\r\n a2 = a2+ pr(4)*i13 + 2d0*pr(5)*i23 !Phi,I2\r\n aux = aux*aux !(J-1)^2\r\n p = p + 2d0/pr(11)*aux !pressure term\r\n cc = cc + 6d0/pr(11)*aux !tangent compressibility\r\n END IF\r\n IF( nterm > 2 )THEN\r\n a1 = a1+3d0*pr(6)*i13*i13 +2d0*pr(7)*i13*i23+ pr(8)*i23*i23 !Phi,I1\r\n a2 = a2+ pr(7)*i13*i13 + pr(8)*i13*i23+3d0*pr(9)*i23*i23 !Phi,I2\r\n aux = aux*aux !(J-1)^4\r\n p = p + 3d0/pr(12)*aux !pressure term\r\n cc = cc + 15d0/pr(12)*aux !tangent compressibility\r\n END IF\r\n\r\n bet = a1*d(:,1) + a2*d(:,2) !principal Biot Stress\r\n\r\n p = a3*p !kirchhoff pressure\r\n cc = cc*2d0 !tangent compressibility\r\n\r\n CASE (10:12) !Reduced polynomial\r\n i13 = i1 - 3d0 !I1 -3\r\n a1 = pr(1) !initializes Phi,I1\r\n ! for pressure\r\n aux = det - 1d0 !j-1\r\n a3 = aux*det*2d0 !2J*(J-1)\r\n p = 1d0/pr(10) !initializes pressure\r\n cc = p !initializes compresibility\r\n IF( nterm > 1 ) THEN\r\n a1 = a1 + 2d0*pr(3)*i13 !Phi,I1\r\n aux = aux*aux !(J-1)^2\r\n p = p + 2d0/pr(11)*aux !pressure term\r\n cc = cc + 6d0/pr(11)*aux !tangent compressibility\r\n END IF\r\n IF( nterm > 2 ) THEN\r\n a1 = a1 + 3d0*pr(6)*i13**2 !Phi,I1\r\n aux = aux*aux !(J-1)^4\r\n p = p + 3d0/pr(12)*aux !pressure term\r\n cc = cc + 15d0/pr(12)*aux !tangent compressibility\r\n END IF\r\n bet = a1*d(:,1) !principal Biot Stress\r\n\r\n p = a3*p !kirchhoff pressure\r\n cc = cc*2d0 !tangent compressibility\r\n\r\n END SELECT\r\n\r\n !SECOND PIOLA KIRCHHOFF STRESS TENSOR\r\n DO i=1,3\r\n bet(i) = (bet(i)+p/lb(i))/lb(i) ! S = [ Phid_i + (Li Phiv_i)/Li ]/Li\r\n END DO\r\n !bet = (bet+p/lb)/lb ! S = [ Phid_i + (Li Phiv_i)/Li ]/Li\r\n\r\n r11 = r1*r1 !factors for stress and matrix computation\r\n r22 = r2*r2\r\n r12 = r1*r2\r\n\r\n !COMPUTE ELASTICITY MATRIX IN VECTOR FORM\r\n IF( PRESENT(vec) ) THEN !to compute stiffness\r\n\r\n IF( ci1 )THEN\r\n ! Second Derivatives of First Invariant\r\n j32 = j32*j3/3d0 !2/3j^(2/3)\r\n DO i=1,3\r\n dd(i,i) = j32*(5d0/3d0*i1/d(i,3)-1d0) !I1,li,li\r\n DO j=i+1,3\r\n dd(i,j) = 2d0*j32/lbb(i)/lbb(j)*(i1/3d0-d(i,3)-d(j,3)) !I1,li,lj\r\n END DO\r\n END DO\r\n IF( ci2 )THEN\r\n ! Second Derivatives of Second Invariant\r\n DO i=1,3\r\n !d(i,4) = d(i,3)**2 !lbb(i)**4\r\n dd(i,4) = j32*(5d0*(d(i,3)-i1)+14d0/3d0*i2/d(i,3)) !I2,li,li\r\n DO j=i+1,3\r\n dd(j,i) = 4d0*j32*lbb(i)*lbb(j)* (1.5d0+d(i,3)/d(j,3)+d(j,3)/d(i,3)& !I2,li,lj\r\n -(1d0/d(i,3)+1d0/d(j,3))*i1 + 2d0/3d0*i2/d(i,3)/d(j,3))\r\n END DO\r\n END DO\r\n END IF\r\n END IF\r\n\r\n ! compute second derivative of the distortion strain function ==> c(i)\r\n SELECT CASE (kode)\r\n\r\n CASE (1) !Arruda-Boyce\r\n a2 = pr(5)+i1*(2d0*pr(6)+i1*(3d0*pr(7)+i1*4d0*pr(8))) !Phi,I1,i2\r\n DO i=1,3\r\n c(i) = a1*dd(i,i) + a2*d(i,1)**2\r\n DO j=i+1,3\r\n c(ij(i,j)) = a1*dd(i,j) + a2*d(i,1)*d(j,1)\r\n END DO\r\n END DO\r\n cc = cc*(1d0+1d0/det2) !Phi,J,J\r\n\r\n CASE (2) !Mooney-Rivlin\r\n\r\n DO i=1,3\r\n c(i) = a1*dd(i,i) + a2*dd(i,4)\r\n DO j=i+1,3\r\n c(ij(i,j)) = a1*dd(i,j) + a2*dd(j,i)\r\n END DO\r\n END DO\r\n\r\n CASE (3) !Neo-Hookean\r\n\r\n DO i=1,3\r\n c(i) = a1*dd(i,i)\r\n DO j=i+1,3\r\n c(ij(i,j)) = a1*dd(i,j)\r\n END DO\r\n END DO\r\n\r\n CASE (4:6) !ogden\r\n c = 0d0 !initializes\r\n k = 1 !initializes pointer\r\n DO j=1,nterm !for each term\r\n a1 = pr(k+1)/3d0 !exponent alpha/3\r\n a2 = a1-1d0 !alpha/3 -1\r\n a3 = a1+1d0 !alpha/3 +1\r\n DO i=1,3\r\n c(i) = c(i)+pr(k)*(a2*d(i,j)+a3*d(j,4))\r\n DO l=i+1,3\r\n c(ij(i,l)) = c(ij(i,l)) - pr(k)*a1*(d(i,j)+d(l,j)-d(j,4))\r\n END DO\r\n END DO\r\n k = k+2\r\n END DO !DS1/L1\r\n ! divide by lb(i)lb(j)\r\n DO i=1,3\r\n c(i) = c(i)/lbg(i)\r\n DO j=i+1,3\r\n c(ij(i,j)) = c(ij(i,j)) /lb(i)/lb(j)\r\n END DO\r\n END DO\r\n\r\n CASE ( 7: 9) !polynomial model\r\n a3 = 0 !Initializes Phi,I1,I1\r\n a4 = 0 !Initializes Phi,I1,I2 = Phi,I2,I1\r\n a5 = 0 !Initializes Phi,I22,I2\r\n IF( nterm > 1 )THEN\r\n a3 = 2d0*pr(3) !Phi,I1,I1\r\n a4 = pr(4) !Phi,I1,I2 = Phi,I2,I1\r\n a5 = 2d0*pr(5) !Phi,I22,I2\r\n END IF\r\n IF( nterm > 2 )THEN\r\n a3 = a3+6d0*pr(6)*i13 +2d0*pr(7)*i23 !Phi,I1,I1\r\n a4 = a4+2d0*pr(7)*i13 +2d0*pr(8)*i23 !Phi,I1,I2 = Phi,I2,I1\r\n a5 = a5+2d0*pr(8)*i13 +6d0*pr(9)*i23 !Phi,I22,I2\r\n END IF\r\n DO i=1,3\r\n c(i) = a1*dd(i,i) + a2*dd(i,4) &\r\n + a3*d(i,1)**2 + 2d0*a4*d(i,1)*d(i,2) + a5*d(i,2)**2\r\n DO j=i+1,3\r\n c(ij(i,j)) = a1*dd(i,j) + a2*dd(j,i) &\r\n + a3*d(i,1)*d(j,1) + a4*(d(i,1)*d(j,2)+d(i,2)*d(j,1)) + a5*d(i,2)*d(j,2)\r\n END DO\r\n END DO\r\n\r\n CASE (10:12) !Reduced polynomial\r\n a3 = 0d0 !initializes Phi,I1,I1\r\n IF( nterm > 1 )THEN\r\n a3 = pr(3)*2d0 !Phi,I1,I1\r\n END IF\r\n IF( nterm > 2 )THEN\r\n a3 = a3 + pr(6)*6d0*i13 !Phi,I1,I1\r\n END IF\r\n DO i=1,3\r\n c(i) = a1*dd(i,i) + a3*d(i,1)**2\r\n DO j=i+1,3\r\n c(ij(i,j)) = a1*dd(i,j) + a3*d(i,1)*d(j,1)\r\n END DO\r\n END DO\r\n\r\n END SELECT\r\n\r\n ! from second derivative of strain function, compute elasticity matrix\r\n\r\n ! for pressure terms\r\n cc = det2*cc !J^2 Phiv_JJ\r\n aux = cc+p !J^2 Phiv_JJ + Jp\r\n\r\n DO i=1,3\r\n c(i) = (c(i) - bet(i) + cc/lbg(i))/lbg(i) !Diagonal terms DSi/Li\r\n DO j=i+1,3 !off-Diagonal terms\r\n c(ij(i,j)) = (c(ij(i,j)) + aux/lb(i)/lb(j) )/lb(i)/lb(j) !DSi/Lj\r\n END DO\r\n END DO\r\n ! shear term 1-2\r\n IF( ABS((lb(1)-lb(2))/lb(1)) < 1e-8 )THEN !equal eigenvalues\r\n c(7) = (c(1) - c(4))/2d0 !DSij/DEij\r\n ELSE !different eigenvalues\r\n c(7) = ( bet(1) - bet(2))/(lbg(1) - lbg(2))!DSij/DEij\r\n END IF\r\n\r\n ! Transform to global coordinates (21 terms)\r\n ! with the spectral decomposition C(IJKL) = c(ijkl)*R(i,I)*R(j,J)*R(k,K)*R(l,L)\r\n !factors for matrix computation\r\n r1111 = r11*r11\r\n r2222 = r22*r22\r\n r1122 = r11*r22\r\n r1112 = r11*r12\r\n r1222 = r12*r22\r\n\r\n vec(1) = c(1)*r1111 + c(2)*r2222 + (c(4)+2d0*c(7))*r1122*2d0 !1,1,1,1 \r\n vec(2) = (c(1)+c(2)-4d0*c(7))*r1122 + c(4)*(r1111+r2222) !1,1,2,2 \r\n vec(3) = c(1)*r1112 - c(2)*r1222 - (c(4)+2d0*c(7))*(r1112-r1222) !1,1,1,2 \r\n vec(4) = c(5)*r11 + c(6)*r22 !1,1,3,3 \r\n vec(5) = c(1)*r2222 + c(2)*r1111 + (c(4)+2d0*c(7))*r1122*2d0 !2,2,2,2 \r\n vec(6) = c(1)*r1222 - c(2)*r1112 + (c(4)+2d0*c(7))*(r1112-r1222) !2,2,1,2 \r\n vec(7) = c(5)*r22 + c(6)*r11 !2,2,3,3 \r\n vec(8) = (c(1)+c(2)-2d0*c(4))*r1122 + c(7)*(r1111+r2222-r1122*2d0) !1,2,1,2 \r\n vec(9) = (c(5)-c(6))*r12 !1,2,3,3 \r\n vec(10)= c(3) !3,3,3,3 \r\n\r\n ! this is for test\r\n !r = RESHAPE( (/ r1,r2,0d0,-r2,r1,0d0,0d0,0d0,1d0 /),(/3,3/))\r\n !DO m=1,10\r\n ! i=kk(1,m) ; j=kk(2,m) ; k=kk(3,m) ; l=kk(4,m) !index\r\n ! v(m) = c(1)* r(i,1)*r(j,1)*r(k,1)*r(l,1) &\r\n ! + c(2)* r(i,2)*r(j,2)*r(k,2)*r(l,2) &\r\n ! + c(3)* r(i,3)*r(j,3)*r(k,3)*r(l,3) &\r\n ! + c(4)* (r(i,1)*r(j,1)*r(k,2)*r(l,2) + r(i,2)*r(j,2)*r(k,1)*r(l,1) ) &\r\n ! + c(5)* (r(i,1)*r(j,1)*r(k,3)*r(l,3) + r(i,3)*r(j,3)*r(k,1)*r(l,1) ) &\r\n ! + c(6)* (r(i,2)*r(j,2)*r(k,3)*r(l,3) + r(i,3)*r(j,3)*r(k,2)*r(l,2) ) &\r\n ! + c(7)* (r(i,1)*r(j,2)* (r(k,1)*r(l,2) + r(k,2)*r(l,1)) + &\r\n ! r(i,2)*r(j,1)* (r(k,2)*r(l,1) + r(k,1)*r(l,2)))\r\n !\r\n !END DO\r\n !WRITE(55,\"(5e15.5)\")v-vec\r\n ELSE\r\n ! store the stress vector (2nd Piola-Kirchhoff stress tensor)\r\n !Compute 3-D stresses with the spectral decomposition R^T * Beta * R\r\n stre(1) = r11*bet(1) + r22*bet(2) !(1,1)\r\n stre(2) = r22*bet(1) + r11*bet(2) !(2,2)\r\n stre(3) = r12*(bet(1)-bet(2)) !(1,2)\r\n stre(4) = bet(3) !(3,3)\r\n\r\n END IF\r\n\r\n RETURN\r\n END SUBROUTINE rubber2d\r\n", "meta": {"hexsha": "9ae6ad4747694b698cc3d81ae0368ae5ea758dc7", "size": 15732, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/matdb/rubber2d.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/matdb/rubber2d.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/matdb/rubber2d.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": 39.6272040302, "max_line_length": 102, "alphanum_fraction": 0.4453979151, "num_tokens": 6031, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971872, "lm_q2_score": 0.734119526900183, "lm_q1q2_score": 0.6631259118547936}} {"text": "PROGRAM mlpmn\n \n! Code converted using TO_F90 by Alan Miller\n! Date: 2004-06-28 Time: 12:58:12\n\n! ==========================================================\n! Purpose: This program computes the associated Legendre\n! functions Pmn(x) and their derivatives Pmn'(x)\n! using subroutine LPMN\n! Input : x --- Argument of Pmn(x)\n! m --- Order of Pmn(x), m = 0,1,2,...,n\n! n --- Degree of Pmn(x), n = 0,1,2,...,N\n! Output: PM(m,n) --- Pmn(x)\n! PD(m,n) --- Pmn'(x)\n! Example: x = 0.50\n! Pmn(x):\n! m\\n 1 2 3 4\n! --------------------------------------------------------\n! 0 .500000 -.125000 -.437500 -.289063\n! 1 -.866025 -1.299038 -.324760 1.353165\n! 2 .000000 2.250000 5.625000 4.218750\n! 3 .000000 .000000 -9.742786 -34.099750\n! 4 .000000 .000000 .000000 59.062500\n\n! Pmn'(x):\n! m\\n 1 2 3 4\n! --------------------------------------------------------\n! 0 1.000000 1.500000 .375000 -1.562500\n! 1 .577350 -1.732051 -6.278684 -5.773503\n! 2 .000000 -3.000000 3.750000 33.750000\n! 3 .000000 .000000 19.485572 .000000\n! 4 .000000 .000000 .000000 -157.500000\n! ==========================================================\n\nIMPLICIT DOUBLE PRECISION (p,x)\nDIMENSION pm(0:100,0:100),pd(0:100,0:100)\nWRITE(*,*)' Please enter m, n and x'\n! READ(*,*) M,N,X\nm=2\nn=4\nx=.5\nWRITE(*,*)\nWRITE(*,*)' m n x Pmn(x) Pmn''(X)'\nWRITE(*,*)' ---------------------------------------------------'\nCALL lpmn(100,m,n,x,pm,pd)\nDO j=0,n\n WRITE(*,10)m,j,x,pm(m,j),pd(m,j)\nEND DO\n10 FORMAT(1X,i3,3X,i3,3X,f5.1,2E17.8)\nEND PROGRAM mlpmn\n\n\nSUBROUTINE lpmn(mm,m,n,x,pm,pd)\n\n! =====================================================\n! Purpose: Compute the associated Legendre functions\n! Pmn(x) and their derivatives Pmn'(x)\n! Input : x --- Argument of Pmn(x)\n! m --- Order of Pmn(x), m = 0,1,2,...,n\n! n --- Degree of Pmn(x), n = 0,1,2,...,N\n! mm --- Physical dimension of PM and PD\n! Output: PM(m,n) --- Pmn(x)\n! PD(m,n) --- Pmn'(x)\n! =====================================================\n\n\nINTEGER, INTENT(IN OUT) :: mm\nINTEGER, INTENT(IN) :: m\nINTEGER, INTENT(IN) :: n\nDOUBLE PRECISION, INTENT(IN) :: x\nDOUBLE PRECISION, INTENT(OUT) :: pm(0:mm,0:n)\nDOUBLE PRECISION, INTENT(OUT) :: pd(0:mm,0:n)\nIMPLICIT DOUBLE PRECISION (p,x)\n\n\nDO i=0,n\n DO j=0,m\n pm(j,i)=0.0D0\n pd(j,i)=0.0D0\n END DO\nEND DO\npm(0,0)=1.0D0\nIF (DABS(x) == 1.0D0) THEN\n DO i=1,n\n pm(0,i)=x**i\n pd(0,i)=0.5D0*i*(i+1.0D0)*x**(i+1)\n END DO\n DO j=1,n\n DO i=1,m\n IF (i == 1) THEN\n pd(i,j)=1.0D+300\n ELSE IF (i == 2) THEN\n pd(i,j)=-0.25D0*(j+2)*(j+1)*j*(j-1)*x**(j+1)\n END IF\n END DO\n END DO\n RETURN\nEND IF\nls=1\nIF (DABS(x) > 1.0D0) ls=-1\nxq=DSQRT(ls*(1.0D0-x*x))\nxs=ls*(1.0D0-x*x)\nDO i=1,m\n pm(i,i)=-ls*(2.0D0*i-1.0D0)*xq*pm(i-1,i-1)\nEND DO\nDO i=0,m\n pm(i,i+1)=(2.0D0*i+1.0D0)*x*pm(i,i)\nEND DO\nDO i=0,m\n DO j=i+2,n\n pm(i,j)=((2.0D0*j-1.0D0)*x*pm(i,j-1)- (i+j-1.0D0)*pm(i,j-2))/(j-i)\n END DO\nEND DO\npd(0,0)=0.0D0\nDO j=1,n\n pd(0,j)=ls*j*(pm(0,j-1)-x*pm(0,j))/xs\nEND DO\nDO i=1,m\n DO j=i,n\n pd(i,j)=ls*i*x*pm(i,j)/xs+(j+i) *(j-i+1.0D0)/xq*pm(i-1,j)\n END DO\nEND DO\nRETURN\nEND SUBROUTINE lpmn\n", "meta": {"hexsha": "7629d92334465bc517b2adfa798656569497589a", "size": 3833, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "MATLAB/f2matlab/comp_spec_func/mlpmn.f90", "max_stars_repo_name": "vasaantk/bin", "max_stars_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MATLAB/f2matlab/comp_spec_func/mlpmn.f90", "max_issues_repo_name": "vasaantk/bin", "max_issues_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MATLAB/f2matlab/comp_spec_func/mlpmn.f90", "max_forks_repo_name": "vasaantk/bin", "max_forks_repo_head_hexsha": "a8c264482ad3e5f78308f53d8af0667b02d6968d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.664, "max_line_length": 70, "alphanum_fraction": 0.4075136968, "num_tokens": 1423, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245870332531, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.6630414637115382}} {"text": " PROGRAM LA_CGEEV_EXAMPLE\n\n! -- LAPACK95 EXAMPLE DRIVER ROUTINE (VERSION 1.0) --\n! UNI-C, DENMARK\n! DECEMBER, 1999\n!\n! .. \"Use Statements\" ..\n USE LA_PRECISION, ONLY: WP => SP\n USE F95_LAPACK, ONLY: LA_GEEV\n! .. \"Implicit Statement\" ..\n IMPLICIT NONE\n! .. \"Local Scalars\" ..\n INTEGER :: I, J, INFO, N\n REAL(WP), ALLOCATABLE :: WR(:), WI(:)\n! .. \"Local Arrays\" ..\n REAL(WP), ALLOCATABLE :: A(:,:)\n COMPLEX(WP), ALLOCATABLE :: AA(:,:), W(:), VL(:,:), VR(:,:)\n! .. \"Intrinsic Functions\" ..\n INTRINSIC REAL, AIMAG, INT\n! .. \"Executable Statements\" ..\n WRITE (*,*) 'LA_GEEV Example Program Results'\n N = 5\n ALLOCATE( A(N,N), AA(N,N), W(N), WR(N), WI(N), VL(N,N), VR(N,N) )\n\n OPEN(UNIT=21,FILE='geev1.ma',STATUS='UNKNOWN')\n DO I=1,N\n DO J=1,N\n READ(21,*) A(I,J)\n ENDDO\n ENDDO\n CLOSE(21)\n\n WRITE(*,*)'Matrix A:'\n DO I=1,N\n WRITE(*,\"(5(I3,1X))\") INT(A(I,:))\n ENDDO\n\n WRITE(*,*) \"CALL LA_GEEV( A, WR, WI ) \"\n CALL LA_GEEV( A, WR, WI )\n \n WRITE(*,*) 'WR on exit : '\n DO I=1,N\n WRITE(*,\"((F9.6,1X))\") REAL(WR(I))\n ENDDO\n \n WRITE(*,*) 'WI on exit : '\n DO I=1,N\n WRITE(*,\"((F9.5,1X))\") REAL(WI(I))\n ENDDO\n \n WRITE(*,*)\n WRITE(*,*) ' * EXAMPLE 2 * '\n\n OPEN(UNIT=21,FILE='geev.ma',STATUS='UNKNOWN')\n DO I=1,N\n DO J=1,N\n READ(21,*) AA(I,J)\n ENDDO\n ENDDO\n CLOSE(21)\n \n WRITE(*,*)'Matrix A : '\n DO J=1,N \n WRITE(*,\"(5(I3,1X,'+',I3,'i',1X,1X,1X))\") INT(AA(J,1)),INT(AIMAG(AA(J,1))), &\n INT(AA(J,2)),INT(AIMAG(AA(J,2))), & \n INT(AA(J,3)),INT(AIMAG(AA(J,3))), & \n INT(AA(J,4)),INT(AIMAG(AA(J,4))), & \n INT(AA(J,5)),INT(AIMAG(AA(J,5))) \n ENDDO\n\n WRITE(*,*) \"CALL LA_GEEV( A, W, VL, VR, INFO )\"\n CALL LA_GEEV( AA, W, VL, VR, INFO )\n \n WRITE(*,*) ' W on exit : '\n DO I=1,N;\n WRITE(*,\"('('E14.7,1X,',',1X,E14.7,')',1X)\") W(I) \n ENDDO\n \n WRITE(*,*)' VL on exit : '\n DO I=1,N;\n WRITE(*,\"(5('('E14.7,1X,',',1X,E14.7,')',1X))\") VL(I,:)\n ENDDO;\n \n WRITE(*,*) ' VR on exit : '\n DO I=1,N;\n WRITE(*,\"(5('('E14.7,1X,',',1X,E14.7,')',1X))\") VR(I,:)\n ENDDO;\n\n WRITE(*,*) ' INFO = ', INFO\n DEALLOCATE( A, AA, VL, VR )\n\n END PROGRAM LA_CGEEV_EXAMPLE\n\n\n\n\n\n\n", "meta": {"hexsha": "9018f7549b05e23599da75bcdf08a88d50fabcbb", "size": 2475, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "EXAMPLES1/la_geev_example.f90", "max_stars_repo_name": "MattBurn/LAPACK95", "max_stars_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-12-29T15:07:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T10:09:22.000Z", "max_issues_repo_path": "EXAMPLES1/la_geev_example.f90", "max_issues_repo_name": "MattBurn/LAPACK95", "max_issues_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-12-30T15:38:47.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-31T06:45:11.000Z", "max_forks_repo_path": "EXAMPLES1/la_geev_example.f90", "max_forks_repo_name": "MattBurn/LAPACK95", "max_forks_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-12-29T15:34:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-15T07:12:40.000Z", "avg_line_length": 25.0, "max_line_length": 86, "alphanum_fraction": 0.4391919192, "num_tokens": 938, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245787544825, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.6630414450109722}} {"text": "module linalg\n use iso_fortran_env, only: wp => real64\n implicit none\n\n public :: linsolve_quick, linsolve\n\ncontains\n subroutine linsolve_quick(n, a, nrhs, b, x)\n\n ! Quick wrapper around linsolve\n\n integer, intent(in) :: n, nrhs\n real(wp), intent(in), dimension(n, n) :: a\n real(wp), intent(in), dimension(n, nrhs) :: b\n real(wp), intent(out), dimension(n, nrhs) :: x\n\n integer, dimension(n) :: P\n real(wp), dimension(n, n) :: LU\n\n call linsolve (n, a, nrhs, b, x, LU, P, .False.)\n return\n end subroutine linsolve_quick\n\n subroutine linsolve (n, a, nrhs, b, x, LU, P, toggle)\n ! This routine is a wrapper dgesv, splitting it into its two primary\n ! components:\n ! dgetrf - Decomposes A into P*L*U\n ! dgetrs - Uses P*L*U to solve for x (Ax=b => (P*L*U)x=b)\n !\n ! Splitting these two up like this allows you to save the decomposed\n ! version of 'a' so that you don't have to do it again. If 'toggle' is\n ! equal to true, then the decomposition has already occured and LU can be\n ! trusted - OK to skip dgetrf\n\n ! Dummy variables\n integer, intent(in) :: n, nrhs\n integer, intent(inout), dimension(n) :: P\n real(wp), intent(in), dimension(n, nrhs) :: b\n real(wp), intent(in), dimension(n, n) :: a\n real(wp), intent(out), dimension(n, nrhs) :: x\n real(wp), intent(inout), dimension(n, n) :: LU\n logical, intent(in) :: toggle\n\n ! Local variables\n integer :: info\n integer, dimension(n) :: my_P\n real(wp), dimension(n, n) :: my_a\n real(wp), dimension(n, nrhs) :: my_b\n\n my_a = a\n my_b = b\n\n if ( .not. toggle ) then\n call dgetrf (n, n, my_a, n, my_P, info)\n\n if ( info /= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'DGETRF'\n write ( *, '(a,i8)' ) ' Factorization failed, INFO = ', info\n stop\n end if\n\n LU = my_a\n P = my_P\n\n end if\n\n call dgetrs ('No transpose', n, nrhs, LU, n, P, my_b, n, info)\n\n if ( info /= 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'DGETRS'\n write ( *, '(a,i8)' ) ' Back substitution failed, INFO = ', info\n stop\n end if\n\n x = my_b\n\n return\n end subroutine linsolve\nend module linalg\n", "meta": {"hexsha": "ed21012b8647c964acb875eb638581460f0283be", "size": 2518, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/linalg.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/linalg.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/linalg.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": 30.7073170732, "max_line_length": 77, "alphanum_fraction": 0.5079428118, "num_tokens": 752, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.7662936537604181, "lm_q1q2_score": 0.6630157288856529}} {"text": "module integrator\n implicit none\n\ncontains\n function verlet_step(f, x0, x1, dt) result(xn)\n interface\n function f(x) result(ddx)\n real(8), dimension(:), intent(in) :: x\n real(8), dimension(size(x)) :: ddx\n end function\n end interface\n real(8), dimension(:), intent(in) :: x0, x1\n real(8), intent(in) :: dt\n real(8), dimension(size(x0)) :: xn\n xn = 2d0 * x1 - x0 + dt**2 * f(x1)\n return\n end function\nend module integrator\n\n\nprogram main\n use ogpf\n use integrator, only: verlet_step\n implicit none\n\n type(gpf) :: gp\n integer, parameter :: steps = 9733\n real(8), parameter :: mu = 2d0\n real(8), dimension(2) :: x0, x1\n real(8), dimension(2, steps) :: xn\n integer :: i\n real(8) :: dt, t\n x0 = [1d0, 1d0]\n x1 = [1.05d0, 1d0]\n dt = .05d0\n t = 0d0\n\n ! call gp%animation_start(1)\n call gp%axis([-2d0, 2d0, -2d0, 2d0])\n\n do i=1, steps\n xn(:,i) = verlet_step(f, x0, x1, dt)\n x0 = x1\n x1 = xn(:,i)\n t = t + dt\n ! if (mod(100, i) == 0) then\n ! call gp%plot(xn(1,:i), xn(2,:i), 'w lines lc \"blue\" lw 1')\n ! ! call gp%plot(xn(1,i:i), xn(2,i:i), 'w points ps 2 lc \"red\"')\n ! end if\n end do\n\n call gp%plot(xn(1,:), xn(2,:), 'w lines lc \"blue\" lw 1')\n ! call gp%animation_show()\n\ncontains\n function f(x) result(ddx)\n real(8), dimension(:), intent(in) :: x\n real(8), dimension(size(x)) :: ddx\n ddx = -mu * x / sum(x**2)**(3d0/2d0)\n return\n end function\nend program\n", "meta": {"hexsha": "dfaaebea9230df2cdc1bf48673ecb1677ca6dc99", "size": 1616, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "2nd_exercise/task2.f90", "max_stars_repo_name": "jerluebke/comp_phys", "max_stars_repo_head_hexsha": "94bca4ab79546f94e50a22476e4d02681efc4177", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-05-28T02:17:09.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-04T03:35:51.000Z", "max_issues_repo_path": "2nd_exercise/task2.f90", "max_issues_repo_name": "jerluebke/comp_phys", "max_issues_repo_head_hexsha": "94bca4ab79546f94e50a22476e4d02681efc4177", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2nd_exercise/task2.f90", "max_forks_repo_name": "jerluebke/comp_phys", "max_forks_repo_head_hexsha": "94bca4ab79546f94e50a22476e4d02681efc4177", "max_forks_repo_licenses": ["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.6507936508, "max_line_length": 76, "alphanum_fraction": 0.5086633663, "num_tokens": 575, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240930029118, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6630157223129465}} {"text": "! Example to debug\nprogram main\n \n implicit none\n real(kind=8), dimension(6) :: v\n \n v = (/1, 2, 3, 5, 6, 7/)\n \n write(*,'(a, f10.7)') 'Self-written routine: ', norm(v)\n write(*,'(a, 3x, f10.7)') 'Intrinsic routine: ', norm2(v)\n write(*,'(a, 10x, f10.7)') 'Difference: ', norm2(v) - norm(v)\n \ncontains\n \n pure function norm(vector) result(res)\n real(kind=8), dimension(:), intent(in) :: vector\n real(kind=8) :: res\n integer :: i\n \n res = 0\n do i = 1, size(vector), 2\n res = res + vector(i) ** 2\n end do\n \n res = sqrt(res)\n \n end function norm\n \nend program main\n", "meta": {"hexsha": "ae70e064c1b2d690da9556ad20f80575a19ad63f", "size": 685, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "main.f90", "max_stars_repo_name": "Huite/VSCode_GFortran_Debugging_Windows", "max_stars_repo_head_hexsha": "2586ec8ef09aadb876cc5c236f985045eaf32135", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-09-17T14:28:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-17T15:04:31.000Z", "max_issues_repo_path": "main.f90", "max_issues_repo_name": "Huite/VSCode_GFortran_Debugging_Windows", "max_issues_repo_head_hexsha": "2586ec8ef09aadb876cc5c236f985045eaf32135", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "main.f90", "max_forks_repo_name": "Huite/VSCode_GFortran_Debugging_Windows", "max_forks_repo_head_hexsha": "2586ec8ef09aadb876cc5c236f985045eaf32135", "max_forks_repo_licenses": ["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.8333333333, "max_line_length": 65, "alphanum_fraction": 0.4861313869, "num_tokens": 217, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6630157143236697}} {"text": "submodule(euler_interface_m) euler_prob_0044_m\n implicit none\n integer(int64), parameter :: dim_of_arr = 3000_int64\n integer(int64) :: pen_arr(dim_of_arr)\n\ncontains\n\n module character(len=20) function euler0044()\n write (euler0044, \"(i20)\") ans()\n end function euler0044\n\n integer(int64) function ans()\n integer(int64) :: i, j, minimised_d\n integer(int64) :: pm, pn\n\n j = 1_int64\n i = 1_int64\n\n do while (i <= dim_of_arr)\n if (is_pen(j)) then\n pen_arr(i) = j\n i = i + 1_int64\n end if\n j = j + 1_int64\n end do\n\n ! set minimised_d to a big number\n minimised_d = huge(0_int64)\n\n do i = 1_int64, dim_of_arr\n do j = i + 1_int64, dim_of_arr\n pm = pen_arr(i)\n pn = pen_arr(j)\n if (is_pen_sum_diff(pm, pn)) then\n minimised_d = min(minimised_d, pn - pm)\n end if\n end do\n end do\n\n ans = minimised_d\n end function ans\n\n logical function is_pen_sum_diff(pj, pk)\n integer(int64), intent(in) :: pj, pk\n integer(int64) :: s, d\n\n if (pj > pk) then\n error stop \"is_pen_SUM_DIFF: pj < pk\"\n end if\n\n s = pj + pk\n d = pk - pj\n\n if (is_pen(s) .and. is_pen(d)) then\n is_pen_sum_diff = .true.\n else\n is_pen_sum_diff = .false.\n end if\n end function is_pen_sum_diff\n\n logical function is_pen(p)\n integer(int64), intent(in) :: p\n\n if (p <= 0) then\n error stop \"is_pen: p > 0.\"\n end if\n\n associate (x => sqrt(24.0_sp*real(p) + 1.0_sp))\n if (is_int(x) .and. mod(int(x, int64), 6_int64) == 5_int64) then\n is_pen = .true.\n else\n is_pen = .false.\n end if\n end associate\n end function is_pen\n\n logical function is_int(n)\n real, intent(in) :: n\n\n is_int = .false.\n if (n - floor(n) <= tiny_sp) then\n is_int = .true.\n end if\n end function is_int\n\nend submodule euler_prob_0044_m\n", "meta": {"hexsha": "b9abd226c9d7f1008a64f0020c5b4dc8e0682841", "size": 2176, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/euler/prob_0044_m.f90", "max_stars_repo_name": "han190/PE-Fortran", "max_stars_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-02-09T07:07:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-31T07:45:48.000Z", "max_issues_repo_path": "src/euler/prob_0044_m.f90", "max_issues_repo_name": "han190/PE-Fortran", "max_issues_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-14T00:48:58.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-14T00:48:58.000Z", "max_forks_repo_path": "docs/src/prob_0044_m.f90", "max_forks_repo_name": "han190/PE-Fortran", "max_forks_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-04T21:29:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T21:29:45.000Z", "avg_line_length": 25.0114942529, "max_line_length": 76, "alphanum_fraction": 0.5133272059, "num_tokens": 615, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240721511739, "lm_q2_score": 0.7662936430859598, "lm_q1q2_score": 0.6630157063343924}} {"text": "module boundary\n\n implicit none\n\ncontains\n\nsubroutine boundarypsi(psi, m, n, b, h, w)\n\n integer :: m, n, b, h, w\n \n double precision, dimension(0:m+1, 0:n+1) :: psi\n\n integer :: i, j\n\n! Set the boundary conditions on the bottom edge\n\n do i = b+1, b+w-1\n psi(i, 0) = float(i-b)\n end do\n\n do i = b+w, m\n psi(i, 0) = float(w)\n end do\n\n ! Set the boundary conditions on the right hand side\n\n do j = 1, h\n\n psi(m+1,j) = float(w)\n \n end do\n\n do j = h+1, h+w-1\n\n psi(m+1,j) = float(w-j+h)\n\n end do\n\nend subroutine boundarypsi\n\nsubroutine boundaryzet(zet, psi, m, n)\n\n integer :: m, n\n \n double precision, dimension(0:m+1, 0:n+1) :: zet, psi\n\n integer :: i, j\n\n! Set the zeta boundary conditions which depend on psi\n\n do j = 1, n\n\n zet(0, j) = 2.0*(psi(1,j) - psi(0, j))\n zet(m+1,j) = 2.0*(psi(m,j) - psi(m+1,j))\n\n end do\n\n do i = 1, m\n zet(i,0) = 2.0*(psi(i, 1)-psi(i,0))\n end do\n\n do i = 1, m\n zet(i,n+1) = 2.0*(psi(i,n)-psi(i,n+1))\n end do\n\nend subroutine boundaryzet\n\nend module boundary\n", "meta": {"hexsha": "f017b28014ddbd2140e611fea84304d62add6162", "size": 1049, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "F-SER/boundary.f90", "max_stars_repo_name": "davidhenty/CFD", "max_stars_repo_head_hexsha": "2f22d1afb564fa6e11fdf9316c669ea977d71888", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2019-04-26T04:51:29.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-10T16:52:05.000Z", "max_issues_repo_path": "F-SER/boundary.f90", "max_issues_repo_name": "davidhenty/CFD", "max_issues_repo_head_hexsha": "2f22d1afb564fa6e11fdf9316c669ea977d71888", "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": "F-SER/boundary.f90", "max_forks_repo_name": "davidhenty/CFD", "max_forks_repo_head_hexsha": "2f22d1afb564fa6e11fdf9316c669ea977d71888", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2019-04-26T04:51:30.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-26T04:43:11.000Z", "avg_line_length": 15.2028985507, "max_line_length": 55, "alphanum_fraction": 0.5605338418, "num_tokens": 415, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240756264638, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6630157043795856}} {"text": "C \tCopyright restrictions apply - see stsdas$copyright.stsdas \nC \n SUBROUTINE YCLCPL (RS, RP, PSIRAD, NLPMAT, ISTAT)\n*\n* Module number:\n*\n* Module name: YCLCPL\n*\n* Keyphrase:\n* ----------\n* Polarimetry processing\n*\n* Description:\n* ------------\n* Creates Mueller Matrix for Polarizer\n*\n* FORTRAN name: YCLCPL\n*\n* Keywords of accessed files and tables:\n* --------------------------------------\n* none\n*\n* Subroutines Called:\n* -------------------\n* CDBS:\n*\n* SDAS:\n*\n*\n* History:\n* --------\n* Version Date Author\t\t Description\n* 1 Mar97 M.D. De La Pena Original Implementation for CALFOS\n* based upon code from R. Allen.\n*-------------------------------------------------------------------------------\n*\n* INPUTS:\n* RS - Reflectivity perpendicular to the plane of incidence\n* RP - Reflectivity parallel to the plane of incidence\n* PSIRAD - Polarizing axis\n*\n* INPUT/OUTPUT:\n* NLPMAT - Mueller matrix for the polarizer\n* ISTAT - Modified return status\n*----------------------------------------------------------------------------\nC\nC Passed Parameters\nC RS=1.0 and RP=0.0 for a perfect polarizer\nC\n DOUBLE PRECISION RS, RP, PSIRAD, NLPMAT(4,4)\n INTEGER ISTAT\nC\nC Local Variables\nC\n DOUBLE PRECISION C2, S2, RSADRP, RSSURP, RSMURP\n DOUBLE PRECISION DHALF, DZERO, DTWO\nC\n PARAMETER (DZERO = 0.0D0)\n PARAMETER (DHALF = 0.5D0)\n PARAMETER (DTWO = 2.0D0)\nC\nC----------------------------------------------------------------------------\nC\n C2 = DCOS(DTWO * PSIRAD)\n S2 = DSIN(DTWO * PSIRAD)\nC\nC Define arithmetic relationships used multiple times\nC\n RSADRP = RS + RP\n RSMURP = RS * RP\n RSSURP = RS - RP\nC\nC Fill the matrix\nC\n NLPMAT(1,1) = DHALF * RSADRP\n NLPMAT(1,2) = DHALF * C2 * RSSURP\n NLPMAT(1,3) = DHALF * S2 * RSSURP\n NLPMAT(1,4) = DZERO\n NLPMAT(2,1) = NLPMAT(1,2)\n NLPMAT(2,2) = DHALF * C2 * C2 * RSADRP + S2 * S2 * DSQRT(RSMURP)\n NLPMAT(2,3) = DHALF * C2 * S2 * RSADRP - S2 * C2 * DSQRT(RSMURP)\n NLPMAT(2,4) = DZERO\n NLPMAT(3,1) = NLPMAT(1,3)\n NLPMAT(3,2) = NLPMAT(2,3)\n NLPMAT(3,3) = DHALF * S2 * S2 * RSADRP + C2 * C2 * DSQRT(RSMURP)\n NLPMAT(3,4) = DZERO\n NLPMAT(4,1) = DZERO\n NLPMAT(4,2) = DZERO\n NLPMAT(4,3) = DZERO\n NLPMAT(4,4) = DSQRT(RSMURP)\nC\n ISTAT = 0\n RETURN\n END\n", "meta": {"hexsha": "8698b988f348592d38b0c4d64ebf3b1566f47441", "size": 2468, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "stsdas/pkg/hst_calib/stpoa/poa_fos/poa_calfos/yclcpl.f", "max_stars_repo_name": "iraf-community/stsdas", "max_stars_repo_head_hexsha": "043c173fd5497c18c2b1bfe8bcff65180bca3996", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-12-20T10:06:48.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-20T10:06:48.000Z", "max_issues_repo_path": "stsdas/pkg/hst_calib/stpoa/poa_fos/poa_calfos/yclcpl.f", "max_issues_repo_name": "spacetelescope/stsdas_stripped", "max_issues_repo_head_hexsha": "043c173fd5497c18c2b1bfe8bcff65180bca3996", "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": "stsdas/pkg/hst_calib/stpoa/poa_fos/poa_calfos/yclcpl.f", "max_forks_repo_name": "spacetelescope/stsdas_stripped", "max_forks_repo_head_hexsha": "043c173fd5497c18c2b1bfe8bcff65180bca3996", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-10-12T20:01:16.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-19T08:04:30.000Z", "avg_line_length": 25.9789473684, "max_line_length": 80, "alphanum_fraction": 0.5101296596, "num_tokens": 840, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545392102522, "lm_q2_score": 0.6992544085240401, "lm_q1q2_score": 0.6630012415048486}} {"text": "!*****************************************************************************************\n!> author: Jacob Williams\n!\n! Propagate a state using the various kepler methods and compare.\n\n program kepler_tests\n\n use kind_module, only: wp\n use gooding_module\n use kepler_module\n use conversion_module\n use random_module\n use numbers_module\n\n implicit none\n\n real(wp),parameter :: dt1 = 0.74060940549140621E+06_wp !! time step (sec)\n real(wp),dimension(6),parameter :: rv1 = [ 0.14624621707935020E+06_wp,&\n -0.20413097635909508E+04_wp,&\n -0.13806223844513239E+06_wp,&\n 0.82912050920300651E+00_wp,&\n 0.10284105194164532E+01_wp,&\n -0.19717889495193228E+01_wp ] !! initial state [km,km/s]\n\n logical,parameter :: run_all = .true. !! run the full set of tests\n real(wp),parameter :: mu = 398600.0_wp !! Earth grav param.\n integer,parameter :: n_cases = 10000 !! number of cases to run\n integer,parameter :: n_methods = 4 !! number of kepler methods to test\n character(len=*),dimension(n_methods),parameter :: methods = ['gooding ',&\n 'shepperd ',&\n 'goodyear ',&\n 'classical'] !! method names\n\n integer :: i !! counter\n real(wp) :: alpha,rp,inc,raan,w,tau,sma,per,dt\n real(wp),dimension(6) :: rv !! cartesian state\n real(wp),dimension(6) :: e !! universal elements\n real(wp),dimension(6) :: err !! state error estimate\n real(wp),dimension(n_methods,n_cases) :: pos_err,vel_err\n integer,dimension(n_methods,n_cases) :: istats\n integer :: imethod,istat\n\n pos_err = zero\n vel_err = zero\n istats = 0\n\n write(*,*) ''\n write(*,*) '---------------'\n write(*,*) ' kepler_tests'\n write(*,*) '---------------'\n write(*,*) ''\n\n write(*,*) ''\n write(*,*) ' Unusual case ...'\n write(*,*) ''\n do imethod = 1,n_methods\n call prop_error(rv1,dt1,imethod,err,istat)\n write(*,'(A,1X,6(E30.17,1X),I5)') trim(methods(imethod))//' err: ', err, istat\n end do\n write(*,*) ''\n\n if (run_all) then\n\n write(*,*) ''\n write(*,*) ' All cases ...'\n write(*,*) ''\n\n do i = 1, n_cases\n\n ! get random elements:\n rp = get_random_number(7000.0_wp,100000.0_wp)\n if (get_random_number(0.0_wp,1.0_wp)>0.5_wp) then\n ! ellipse\n sma = get_random_number(rp, 1000000.0_wp)\n per = twopi*sqrt(sma**3/mu)\n tau = get_random_number(0.0_wp,per)\n dt = get_random_number(0.0_wp,per)\n else\n ! hyperbola\n sma = get_random_number(-1000000.0_wp,-rp)\n tau = get_random_number(0.0_wp,10.0_wp) * day2sec\n dt = get_random_number(0.0_wp,10.0_wp) * day2sec\n end if\n alpha = mu / sma\n ! add a specific test for a parabola (a=0)\n if (i==n_cases) then ! the last one\n alpha = zero\n end if\n inc = get_random_number(0.0_wp, pi)\n raan = get_random_number(0.0_wp, twopi)\n w = get_random_number(0.0_wp, twopi)\n\n e = [alpha,rp,inc,raan,w,tau]\n\n call els3pv (mu, e, rv)\n\n do imethod = 1,n_methods\n call prop_error(rv,dt,imethod,err,istats(imethod,i))\n pos_err(imethod,i) = norm2(err(1:3))\n vel_err(imethod,i) = norm2(err(4:6))\n\n if (istats(imethod,i) /= 0 .or. pos_err(imethod,i)>one .or. vel_err(imethod,i)>one) then\n write(*,*) ''\n write(*,*) 'error for method: '//trim(methods(imethod))\n write(*,*) 'i: ', i\n write(*,'(A,1X,I6)') 'istat =', istats(imethod,i)\n write(*,'(A,1X,*(E30.16,1X))') 'e =',e\n write(*,'(A,1X,*(E30.16,1X))') 'pos err =',err(1:3)\n write(*,'(A,1X,*(E30.16,1X))') 'vel err =',err(4:6)\n write(*,*) ''\n write(*,'(A,1X,*(E30.17,1X))') 'rv (km,km/s) = ',rv\n write(*,'(A,1X,*(E30.17))') 'dt (sec) = ', dt\n if (e(1)/=zero) write(*,'(A,1X,*(E30.17))') 'sma (km) = ', mu / e(1)\n write(*,'(A,1X,*(E30.17))') 'rp (km) = ', e(2)\n write(*,'(A,1X,*(E30.17))') 'inc (deg) = ', e(3) * rad2deg\n write(*,'(A,1X,*(E30.17))') 'raan (deg) = ', e(4) * rad2deg\n write(*,'(A,1X,*(E30.17))') 'w (deg) = ', e(5) * rad2deg\n write(*,'(A,1X,*(E30.17))') 'tau (days) = ', e(6) * sec2day\n write(*,*) ''\n !stop\n end if\n\n end do\n\n end do\n\n ! results:\n write(*,*) ''\n write(*,*) '-------------------'\n do imethod = 1,n_methods\n do i = 1, n_cases\n if (istats(imethod,i)/=0) &\n write(*,'(A,E30.16,1X,I5)') trim(methods(imethod))//' pos error: ', pos_err(imethod,i), istats(imethod,i)\n end do\n write(*,*) ''\n end do\n do imethod = 1,n_methods\n do i = 1, n_cases\n if (istats(imethod,i)/=0) &\n write(*,'(A,E30.16,1X,I5)') trim(methods(imethod))//' vel error: ', vel_err(imethod,i), istats(imethod,i)\n end do\n write(*,*) ''\n end do\n write(*,*) '-------------------'\n write(*,*) ''\n\n write(*,*) ''\n write(*,*) 'summary'\n do imethod = 1,n_methods\n write(*,*) '-------------------'\n write(*,'(A,E30.16)') trim(methods(imethod))//' max pos error: ', maxval(abs(pos_err(imethod,:)))\n write(*,'(A,E30.16)') trim(methods(imethod))//' max vel error: ', maxval(abs(vel_err(imethod,:)))\n write(*,*) '-------------------'\n end do\n write(*,*) ''\n\n end if\n\n contains\n\n subroutine prop_error(x0,dt,imethod,xerr,istat)\n\n !! propagate the state forward the backwards, and return\n !! the error vector.\n\n implicit none\n\n real(wp),dimension(6),intent(in) :: x0\n real(wp),intent(in) :: dt\n integer,intent(in) :: imethod\n real(wp),dimension(6),intent(out) :: xerr\n integer,intent(out) :: istat\n\n real(wp),dimension(6) :: rv2,rv3,rv4\n\n real(wp),parameter :: tol = 1.0e-15_wp !! tolerance for goodyear\n\n istat = 0\n\n select case (imethod)\n case(1)\n call propagate(mu,x0,dt,rv2)\n call propagate(mu,rv2,-dt,rv3)\n case(2)\n call kepler_shepperd(mu,x0,dt,rv2,istat)\n call kepler_shepperd(mu,rv2,-dt,rv3,istat)\n case(3)\n call kepler_goodyear_stienon_klumpp(x0,dt,mu,tol,rv2)\n call kepler_goodyear_stienon_klumpp(rv2,-dt,mu,tol,rv3)\n case(4)\n call kepler_classical(x0,dt,mu,rv2)\n call kepler_classical(rv2,-dt,mu,rv3)\n case default\n error stop 'invalid method'\n end select\n\n xerr = rv3 - x0\n\n end subroutine prop_error\n\n end program kepler_tests\n!*****************************************************************************************\n", "meta": {"hexsha": "bc86129fd7164cfaa5219d81ea85344732fa6aa7", "size": 7721, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/kepler/kepler_tests.f90", "max_stars_repo_name": "jacobwilliams/Fortran-Astrodynamics-Toolk", "max_stars_repo_head_hexsha": "f8e18642dc8d78473d233b8fa6078fdbf7a1d6fc", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 122, "max_stars_repo_stars_event_min_datetime": "2015-01-29T05:40:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:20:21.000Z", "max_issues_repo_path": "tests/kepler/kepler_tests.f90", "max_issues_repo_name": "gandymagic/Fortran-Astrodynamics-Toolkit", "max_issues_repo_head_hexsha": "7f176fabc8c36cc1981349b02eeb6d8112f2bfbc", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 25, "max_issues_repo_issues_event_min_datetime": "2015-06-10T02:16:59.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T04:28:55.000Z", "max_forks_repo_path": "tests/kepler/kepler_tests.f90", "max_forks_repo_name": "gandymagic/Fortran-Astrodynamics-Toolkit", "max_forks_repo_head_hexsha": "7f176fabc8c36cc1981349b02eeb6d8112f2bfbc", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 43, "max_forks_repo_forks_event_min_datetime": "2015-02-12T13:24:23.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-30T04:30:49.000Z", "avg_line_length": 38.0344827586, "max_line_length": 125, "alphanum_fraction": 0.4527910892, "num_tokens": 2214, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711756575749, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.6629714867804647}} {"text": "MODULE MODULE_COM\n\nCONTAINS\n\n FUNCTION GEOMETRICAL_CENTER(coors, atoms_indices_serialized, atoms_series_starts, frame_indices,& \n n_frames, n_atoms, n_atoms_indices, n_atoms_series, n_frame_indices) RESULT(center)\n\n IMPLICIT NONE\n\n INTEGER,INTENT(IN)::n_frames, n_atoms, n_atoms_indices, n_atoms_series, n_frame_indices\n DOUBLE PRECISION,DIMENSION(n_frames,n_atoms,3),INTENT(IN)::coors\n INTEGER,DIMENSION(n_atoms_indices),INTENT(IN)::atoms_indices_serialized\n INTEGER,DIMENSION(n_atoms_series+1),INTENT(IN)::atoms_series_starts\n INTEGER,DIMENSION(n_frame_indices),INTENT(IN)::frame_indices\n DOUBLE PRECISION,DIMENSION(n_atoms_indices)::weights\n DOUBLE PRECISION,DIMENSION(n_frames,n_atoms_series,3)::center\n \n\n weights(:)=1.0d0\n\n center=CENTER_OF_MASS(coors, atoms_indices_serialized, atoms_series_starts, weights, frame_indices,& \n n_frames, n_atoms, n_atoms_indices, n_atoms_series, n_frame_indices)\n\n END FUNCTION\n\n FUNCTION CENTER_OF_MASS(coors, atoms_indices_serialized, atoms_series_starts, weights, frame_indices,& \n n_frames, n_atoms, n_atoms_indices, n_atoms_series, n_frame_indices) RESULT(center)\n \n IMPLICIT NONE\n \n INTEGER,INTENT(IN)::n_frames, n_atoms, n_atoms_indices, n_atoms_series, n_frame_indices\n DOUBLE PRECISION,DIMENSION(n_frames,n_atoms,3),INTENT(IN)::coors\n INTEGER,DIMENSION(n_atoms_indices),INTENT(IN)::atoms_indices_serialized\n INTEGER,DIMENSION(n_atoms_series+1),INTENT(IN)::atoms_series_starts\n DOUBLE PRECISION,DIMENSION(n_atoms_indices),INTENT(IN)::weights\n INTEGER,DIMENSION(n_frame_indices),INTENT(IN)::frame_indices\n DOUBLE PRECISION,DIMENSION(n_frames,n_atoms_series,3)::center\n \n INTEGER::ii,jj,ll,frame_index,atom_index\n DOUBLE PRECISION::total_weight\n \n center(:,:,:)=0.0d0\n\n DO ii=1,n_atoms_series\n total_weight=0.0d0\n DO jj=atoms_series_starts(ii)+1,atoms_series_starts(ii+1)\n total_weight = total_weight+weights(jj)\n END DO\n DO jj=atoms_series_starts(ii)+1,atoms_series_starts(ii+1)\n atom_index = atoms_indices_serialized(jj)+1\n DO ll=1,n_frame_indices\n frame_index=frame_indices(ll)+1\n center(ll,ii,:)=center(ll,ii,:)+weights(jj)*coors(frame_index,atom_index,:)/total_weight\n END DO\n END DO\n END DO\n \n END FUNCTION CENTER_OF_MASS\n\nEND MODULE MODULE_COM\n \n", "meta": {"hexsha": "bfba2f1f5726fff858ffe35dc0b208b2b150dcee", "size": 2459, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "molmodmt/lib/libcom.f90", "max_stars_repo_name": "LMMV/MolModMT", "max_stars_repo_head_hexsha": "5725d6d5627b07edcbbd5e55318345a136b28c35", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "molmodmt/lib/libcom.f90", "max_issues_repo_name": "LMMV/MolModMT", "max_issues_repo_head_hexsha": "5725d6d5627b07edcbbd5e55318345a136b28c35", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "molmodmt/lib/libcom.f90", "max_forks_repo_name": "LMMV/MolModMT", "max_forks_repo_head_hexsha": "5725d6d5627b07edcbbd5e55318345a136b28c35", "max_forks_repo_licenses": ["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.6612903226, "max_line_length": 113, "alphanum_fraction": 0.728751525, "num_tokens": 616, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711604559846, "lm_q2_score": 0.7799929104825006, "lm_q1q2_score": 0.662971479270252}} {"text": "! =============================================================================\n!\n! Angry Polynomial Interpolator (Procedure)\n!\n! AUTHOR: Maciek_Bak\n! CONTACT: wsciekly.maciek@gmail.com\n! CREATED: 15-07-2020\n! LICENSE: MIT\n!\n! =============================================================================\n\nmodule AngryPolynomialInterpolator\n\ncontains\n\nsubroutine interpolate(n, x, y, a)\n implicit none\n integer :: n, i, j, info\n real(8), dimension (:), intent(in) :: x, y\n real(8), dimension (:), intent(inout) :: a\n integer, dimension (:), allocatable :: ipiv\n real(8), dimension(:,:), allocatable :: Mat_X, Mat_B\n\n ! create the Vandermonde matrix:\n allocate(Mat_X(n,n))\n do i = 1,n\n do j = 1,n\n Mat_X(i,j) = x(i) ** (j - 1)\n end do\n end do\n\n ! reshape ipnut data into a matrix form:\n allocate (Mat_B(n,1))\n do i = 1,n\n Mat_B(i,1) = y(i)\n end do\n\n ! prepare an array for the pivot indices from DGETRF:\n allocate(ipiv(n))\n\n ! LAPACK:\n ! compute an LU factorization of a general M-by-N matrix A using\n ! partial pivoting with row interchanges\n ! http://sites.science.oregonstate.edu/~landaur/nacphy/lapack/routines/dgetrf.html\n call DGETRF(n, n, Mat_X, n, ipiv, info)\n\n ! LAPACK:\n ! DGETRS - solve a system of linear equations A * X = B or A' * X = B with a\n ! general N-by-N matrix A using the LU factorization computed by DGETRF\n ! http://sites.science.oregonstate.edu/~landaur/nacphy/lapack/routines/dgetrs.html\n call DGETRS(\"N\", n, 1, Mat_X, n, ipiv, Mat_B, n, info)\n\n ! save the results into the argument array\n do i = 1,n\n a(i) = Mat_B(i,1)\n end do\n\n deallocate(ipiv)\n deallocate(Mat_X)\n deallocate(Mat_B)\n\nend subroutine interpolate\n\nend module AngryPolynomialInterpolator\n", "meta": {"hexsha": "e4dc9dbcfa99b9b43b295c0006021a9bf68eb711", "size": 1738, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/angrypolynomialinterpolator.f90", "max_stars_repo_name": "AngryMaciek/angry-polynomial-interpolator", "max_stars_repo_head_hexsha": "e733736b737d10f5daa348b2ccc0fefe93f7ed2f", "max_stars_repo_licenses": ["MIT"], "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/angrypolynomialinterpolator.f90", "max_issues_repo_name": "AngryMaciek/angry-polynomial-interpolator", "max_issues_repo_head_hexsha": "e733736b737d10f5daa348b2ccc0fefe93f7ed2f", "max_issues_repo_licenses": ["MIT"], "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/angrypolynomialinterpolator.f90", "max_forks_repo_name": "AngryMaciek/angry-polynomial-interpolator", "max_forks_repo_head_hexsha": "e733736b737d10f5daa348b2ccc0fefe93f7ed2f", "max_forks_repo_licenses": ["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.7384615385, "max_line_length": 84, "alphanum_fraction": 0.6081703107, "num_tokens": 520, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711756575749, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6629714780866246}} {"text": "* _______________________________________________________________________\n*\n* DAKOTA: Design Analysis Kit for Optimization and Terascale Applications\n* Copyright 2014 Sandia Corporation.\n* This software is distributed under the GNU Lesser General Public License.\n* For more information, see the README file in the top Dakota directory.\n* _______________________________________________________________________\n*\nC From http://www.netlib.org/lawson-hanson/all\nC \nC This package of Fortran 77 and Fortran 90 code accompanies\nC the SIAM Publications printing of \"Solving Least Squares\nC Problems,\" by C. Lawson and R. Hanson. The routines in the\nC package are filed as shown in the list below. The units \nC listed 1.-14. may be compiled and placed in a library. Routine\nC G2 is no longer used but is included for completeness. The\nC main program units 15.-18., 20.-21. require this library for\nC all external references. The item 19. is a data file read\nC by program unit PROG4.FOR. The main program 23., PROG7.F90,\nC requires the subprogram 22. or BVLS.F90.\nC \nC 1. BNDACC.FOR \nC 2. BNDSOL.FOR \nC 3. DIFF.FOR\nC 4. G1.FOR\nC 5. G2.FOR \nC 6. GEN.FOR \nC 7. H12.FOR \nC 8. HFTI.FOR \nC 9. LDP.FOR \nC 10. MFEOUT.FOR \nC 11. NNLS.FOR \nC 12. QRBD.FOR \nC 13. SVA.FOR \nC 14. SVDRS.FOR\nC 15. PROG1.FOR \nC 16. PROG2.FOR \nC 17. PROG3.FOR \nC 18. PROG4.FOR \nC 19. DATA4.DAT \nC 20. PROG5.FOR \nC 21. PROG6.FOR\nC \nC 22. BVLS.F90\nC 23. PROG7.F90 \nC -------------------------------------------------------------\nC -------------------------------------------------------------\n SUBROUTINE BNDACC (G,MDG,NB,IP,IR,MT,JT) \nc\nC SEQUENTIAL ALGORITHM FOR BANDED LEAST SQUARES PROBLEM.. \nC ACCUMULATION PHASE. FOR SOLUTION PHASE USE BNDSOL. \nc\nc The original version of this code was developed by\nc Charles L. Lawson and Richard J. Hanson at Jet Propulsion Laboratory\nc 1973 JUN 12, and published in the book\nc \"SOLVING LEAST SQUARES PROBLEMS\", Prentice-HalL, 1974.\nc Revised FEB 1995 to accompany reprinting of the book by SIAM.\nC \nC THE CALLING PROGRAM MUST SET IR=1 AND IP=1 BEFORE THE FIRST CALL \nC TO BNDACC FOR A NEW CASE. \nC \nC THE SECOND SUBSCRIPT OF G( ) MUST BE DIMENSIONED AT LEAST \nC NB+1 IN THE CALLING PROGRAM. \nc ------------------------------------------------------------------\n integer I, J, IE, IG, IG1, IG2, IP, IR, JG, JT, K, KH, L, LP1\n integer MDG, MH, MT, MU, NB, NBP1\nc double precision G(MDG,NB+1)\n double precision G(MDG,*)\n double precision RHO, ZERO\n parameter(ZERO = 0.0d0)\nc ------------------------------------------------------------------\nC \nC ALG. STEPS 1-4 ARE PERFORMED EXTERNAL TO THIS SUBROUTINE.\nC \n NBP1=NB+1 \n IF (MT.LE.0) RETURN \nC ALG. STEP 5 \n IF (JT.EQ.IP) GO TO 70\nC ALG. STEPS 6-7\n IF (JT.LE.IR) GO TO 30\nC ALG. STEPS 8-9\n DO 10 I=1,MT \n IG1=JT+MT-I \n IG2=IR+MT-I \n DO 10 J=1,NBP1 \n 10 G(IG1,J)=G(IG2,J) \nC ALG. STEP 10 \n IE=JT-IR \n DO 20 I=1,IE \n IG=IR+I-1 \n DO 20 J=1,NBP1 \n 20 G(IG,J)=ZERO \nC ALG. STEP 11 \n IR=JT \nC ALG. STEP 12 \n 30 MU=min(NB-1,IR-IP-1) \n IF (MU.EQ.0) GO TO 60 \nC ALG. STEP 13 \n DO 50 L=1,MU \nC ALG. STEP 14 \n K=min(L,JT-IP) \nC ALG. STEP 15 \n LP1=L+1 \n IG=IP+L \n DO 40 I=LP1,NB \n JG=I-K\n 40 G(IG,JG)=G(IG,I) \nC ALG. STEP 16 \n DO 50 I=1,K \n JG=NBP1-I \n 50 G(IG,JG)=ZERO \nC ALG. STEP 17 \n 60 IP=JT \nC ALG. STEPS 18-19 \n 70 MH=IR+MT-IP \n KH=min(NBP1,MH) \nC ALG. STEP 20 \n DO 80 I=1,KH \n CALL H12 (1,I,max(I+1,IR-IP+1),MH,G(IP,I),1,RHO, \n * G(IP,I+1),1,MDG,NBP1-I) \n 80 continue\nC ALG. STEP 21 \n IR=IP+KH \nC ALG. STEP 22 \n IF (KH.LT.NBP1) GO TO 100 \nC ALG. STEP 23 \n DO 90 I=1,NB \n 90 G(IR-1,I)=ZERO \nC ALG. STEP 24 \n 100 CONTINUE \nC ALG. STEP 25 \n RETURN\n END \n\n\n SUBROUTINE BNDSOL (MODE,G,MDG,NB,IP,IR,X,N,RNORM) \nc\nC SEQUENTIAL SOLUTION OF A BANDED LEAST SQUARES PROBLEM.. \nC SOLUTION PHASE. FOR THE ACCUMULATION PHASE USE BNDACC. \nc\nc The original version of this code was developed by\nc Charles L. Lawson and Richard J. Hanson at Jet Propulsion Laboratory\nc 1973 JUN 12, and published in the book\nc \"SOLVING LEAST SQUARES PROBLEMS\", Prentice-HalL, 1974.\nc Revised FEB 1995 to accompany reprinting of the book by SIAM.\nC \nC MODE = 1 SOLVE R*X=Y WHERE R AND Y ARE IN THE G( ) ARRAY \nC AND X WILL BE STORED IN THE X( ) ARRAY. \nC 2 SOLVE (R**T)*X=Y WHERE R IS IN G( ), \nC Y IS INITIALLY IN X( ), AND X REPLACES Y IN X( ), \nC 3 SOLVE R*X=Y WHERE R IS IN G( ).\nC Y IS INITIALLY IN X( ), AND X REPLACES Y IN X( ). \nC \nC THE SECOND SUBSCRIPT OF G( ) MUST BE DIMENSIONED AT LEAST \nC NB+1 IN THE CALLING PROGRAM. \n integer I, I1, I2, IE, II, IP, IR, IX, J, JG, L\n integer MDG, MODE, N, NB, NP1, IRM1\n double precision G(MDG,*), RNORM, RSQ, S, X(N), ZERO\n parameter(ZERO = 0.0d0)\nC \n RNORM=ZERO\n GO TO (10,90,50), MODE\nC ********************* MODE = 1 \nC ALG. STEP 26\n 10 DO 20 J=1,N \n 20 X(J)=G(J,NB+1) \n RSQ=ZERO \n NP1=N+1 \n IRM1=IR-1 \n IF (NP1.GT.IRM1) GO TO 40 \n DO 30 J=NP1,IRM1 \n 30 RSQ=RSQ+G(J,NB+1)**2 \n RNORM=SQRT(RSQ) \n 40 CONTINUE \nC ********************* MODE = 3 \nC ALG. STEP 27\n 50 DO 80 II=1,N \n I=N+1-II \nC ALG. STEP 28\n S=ZERO \n L=max(0,I-IP) \nC ALG. STEP 29\n IF (I.EQ.N) GO TO 70 \nC ALG. STEP 30\n IE=min(N+1-I,NB)\n DO 60 J=2,IE\n JG=J+L \n IX=I-1+J\n 60 S=S+G(I,JG)*X(IX) \nC ALG. STEP 31\n 70 continue\n IF (G(I,L+1) .eq. ZERO) go to 130\n 80 X(I)=(X(I)-S)/G(I,L+1) \nC ALG. STEP 32\n RETURN\nC ********************* MODE = 2 \n 90 DO 120 J=1,N \n S=ZERO \n IF (J.EQ.1) GO TO 110 \n I1=max(1,J-NB+1)\n I2=J-1 \n DO 100 I=I1,I2 \n L=J-I+1+max(0,I-IP)\n 100 S=S+X(I)*G(I,L) \n 110 L=max(0,J-IP) \n IF (G(J,L+1) .eq. ZERO) go to 130\n 120 X(J)=(X(J)-S)/G(J,L+1) \n RETURN\nC \n 130 write (*,'(/a/a,4i6)')' ZERO DIAGONAL TERM IN BNDSOL.',\n * ' MODE,I,J,L = ',MODE,I,J,L \n STOP \n END\n\n double precision FUNCTION DIFF(X,Y)\nc\nc Function used in tests that depend on machine precision.\nc\nc The original version of this code was developed by\nc Charles L. Lawson and Richard J. Hanson at Jet Propulsion Laboratory\nc 1973 JUN 7, and published in the book\nc \"SOLVING LEAST SQUARES PROBLEMS\", Prentice-HalL, 1974.\nc Revised FEB 1995 to accompany reprinting of the book by SIAM.\nC\n double precision X, Y\n DIFF=X-Y \n RETURN\n END \n SUBROUTINE G1 (A,B,CTERM,STERM,SIG) \nc\nC COMPUTE ORTHOGONAL ROTATION MATRIX.. \nc\nc The original version of this code was developed by\nc Charles L. Lawson and Richard J. Hanson at Jet Propulsion Laboratory\nc 1973 JUN 12, and published in the book\nc \"SOLVING LEAST SQUARES PROBLEMS\", Prentice-HalL, 1974.\nc Revised FEB 1995 to accompany reprinting of the book by SIAM.\nC \nC COMPUTE.. MATRIX (C, S) SO THAT (C, S)(A) = (SQRT(A**2+B**2)) \nC (-S,C) (-S,C)(B) ( 0 ) \nC COMPUTE SIG = SQRT(A**2+B**2) \nC SIG IS COMPUTED LAST TO ALLOW FOR THE POSSIBILITY THAT \nC SIG MAY BE IN THE SAME LOCATION AS A OR B .\nC ------------------------------------------------------------------\n double precision A, B, CTERM, ONE, SIG, STERM, XR, YR, ZERO\n parameter(ONE = 1.0d0, ZERO = 0.0d0)\nC ------------------------------------------------------------------\n if (abs(A) .gt. abs(B)) then\n XR=B/A\n YR=sqrt(ONE+XR**2)\n CTERM=sign(ONE/YR,A)\n STERM=CTERM*XR\n SIG=abs(A)*YR \n RETURN\n endif\n\n if (B .ne. ZERO) then\n XR=A/B\n YR=sqrt(ONE+XR**2)\n STERM=sign(ONE/YR,B)\n CTERM=STERM*XR\n SIG=abs(B)*YR \n RETURN\n endif\n\n SIG=ZERO \n CTERM=ZERO \n STERM=ONE \n RETURN\n END \n\n\n SUBROUTINE G2 (CTERM,STERM,X,Y)\nc\nC APPLY THE ROTATION COMPUTED BY G1 TO (X,Y). \nc\nc The original version of this code was developed by\nc Charles L. Lawson and Richard J. Hanson at Jet Propulsion Laboratory\nc 1972 DEC 15, and published in the book\nc \"SOLVING LEAST SQUARES PROBLEMS\", Prentice-HalL, 1974.\nc Revised FEB 1995 to accompany reprinting of the book by SIAM.\nc ------------------------------------------------------------------\n double precision CTERM, STERM, X, XR, Y\nc ------------------------------------------------------------------\n XR=CTERM*X+STERM*Y \n Y=-STERM*X+CTERM*Y \n X=XR \n RETURN\n END \n \n double precision FUNCTION GEN(ANOISE)\nc\nC GENERATE NUMBERS FOR CONSTRUCTION OF TEST CASES. \nc\nc The original version of this code was developed by\nc Charles L. Lawson and Richard J. Hanson at Jet Propulsion Laboratory\nc 1972 DEC 15, and published in the book\nc \"SOLVING LEAST SQUARES PROBLEMS\", Prentice-HalL, 1974.\nc Revised FEB 1995 to accompany reprinting of the book by SIAM.\nc ------------------------------------------------------------------\n integer I, J, MI, MJ\n double precision AI, AJ, ANOISE, ZERO\n parameter(ZERO = 0.0d0)\n SAVE\nc ------------------------------------------------------------------\n IF (ANOISE) 10,30,20 \n 10 MI=891\n MJ=457\n I=5 \n J=7 \n AJ= ZERO\n GEN= ZERO\n RETURN\nC \nC THE SEQUENCE OF VALUES OF J IS BOUNDED BETWEEN 1 AND 996 \nC IF INITIAL J = 1,2,3,4,5,6,7,8, OR 9, THE PERIOD IS 332 \n 20 J=J*MJ\n J=J-997*(J/997) \n AJ=J-498 \nC THE SEQUENCE OF VALUES OF I IS BOUNDED BETWEEN 1 AND 999 \nC IF INITIAL I = 1,2,3,6,7, OR 9, THE PERIOD WILL BE 50\nC IF INITIAL I = 4 OR 8 THE PERIOD WILL BE 25 \nC IF INITIAL I = 5 THE PERIOD WILL BE 10 \n 30 I=I*MI\n I=I-1000*(I/1000) \n AI=I-500 \n GEN=AI+AJ*ANOISE \n RETURN\n END \n\n\nC SUBROUTINE H12 (MODE,LPIVOT,L1,M,U,IUE,UP,C,ICE,ICV,NCV) \nC \nC CONSTRUCTION AND/OR APPLICATION OF A SINGLE \nC HOUSEHOLDER TRANSFORMATION.. Q = I + U*(U**T)/B \nC \nc The original version of this code was developed by\nc Charles L. Lawson and Richard J. Hanson at Jet Propulsion Laboratory\nc 1973 JUN 12, and published in the book\nc \"SOLVING LEAST SQUARES PROBLEMS\", Prentice-HalL, 1974.\nc Revised FEB 1995 to accompany reprinting of the book by SIAM.\nC ------------------------------------------------------------------\nc Subroutine Arguments\nc\nC MODE = 1 OR 2 Selects Algorithm H1 to construct and apply a\nc Householder transformation, or Algorithm H2 to apply a\nc previously constructed transformation.\nC LPIVOT IS THE INDEX OF THE PIVOT ELEMENT. \nC L1,M IF L1 .LE. M THE TRANSFORMATION WILL BE CONSTRUCTED TO \nC ZERO ELEMENTS INDEXED FROM L1 THROUGH M. IF L1 GT. M \nC THE SUBROUTINE DOES AN IDENTITY TRANSFORMATION.\nC U(),IUE,UP On entry with MODE = 1, U() contains the pivot\nc vector. IUE is the storage increment between elements. \nc On exit when MODE = 1, U() and UP contain quantities\nc defining the vector U of the Householder transformation.\nc on entry with MODE = 2, U() and UP should contain\nc quantities previously computed with MODE = 1. These will\nc not be modified during the entry with MODE = 2. \nC C() ON ENTRY with MODE = 1 or 2, C() CONTAINS A MATRIX WHICH\nc WILL BE REGARDED AS A SET OF VECTORS TO WHICH THE\nc HOUSEHOLDER TRANSFORMATION IS TO BE APPLIED.\nc ON EXIT C() CONTAINS THE SET OF TRANSFORMED VECTORS.\nC ICE STORAGE INCREMENT BETWEEN ELEMENTS OF VECTORS IN C(). \nC ICV STORAGE INCREMENT BETWEEN VECTORS IN C(). \nC NCV NUMBER OF VECTORS IN C() TO BE TRANSFORMED. IF NCV .LE. 0 \nC NO OPERATIONS WILL BE DONE ON C(). \nC ------------------------------------------------------------------\n SUBROUTINE H12 (MODE,LPIVOT,L1,M,U,IUE,UP,C,ICE,ICV,NCV) \nC ------------------------------------------------------------------\n integer I, I2, I3, I4, ICE, ICV, INCR, IUE, J\n integer L1, LPIVOT, M, MODE, NCV\n double precision B, C(*), CL, CLINV, ONE, SM\nc double precision U(IUE,M)\n double precision U(IUE,*)\n double precision UP\n parameter(ONE = 1.0d0)\nC ------------------------------------------------------------------\n IF (0.GE.LPIVOT.OR.LPIVOT.GE.L1.OR.L1.GT.M) RETURN \n CL=abs(U(1,LPIVOT)) \n IF (MODE.EQ.2) GO TO 60 \nC ****** CONSTRUCT THE TRANSFORMATION. ******\n DO 10 J=L1,M \n 10 CL=MAX(abs(U(1,J)),CL) \n IF (CL) 130,130,20\n 20 CLINV=ONE/CL \n SM=(U(1,LPIVOT)*CLINV)**2 \n DO 30 J=L1,M \n 30 SM=SM+(U(1,J)*CLINV)**2 \n CL=CL*SQRT(SM) \n IF (U(1,LPIVOT)) 50,50,40 \n 40 CL=-CL\n 50 UP=U(1,LPIVOT)-CL \n U(1,LPIVOT)=CL \n GO TO 70 \nC ****** APPLY THE TRANSFORMATION I+U*(U**T)/B TO C. ******\nC \n 60 IF (CL) 130,130,70\n 70 IF (NCV.LE.0) RETURN \n B= UP*U(1,LPIVOT)\nC B MUST BE NONPOSITIVE HERE. IF B = 0., RETURN.\nC \n IF (B) 80,130,130 \n 80 B=ONE/B \n I2=1-ICV+ICE*(LPIVOT-1) \n INCR=ICE*(L1-LPIVOT) \n DO 120 J=1,NCV\n I2=I2+ICV \n I3=I2+INCR \n I4=I3 \n SM=C(I2)*UP\n DO 90 I=L1,M \n SM=SM+C(I3)*U(1,I)\n 90 I3=I3+ICE \n IF (SM) 100,120,100 \n 100 SM=SM*B \n C(I2)=C(I2)+SM*UP\n DO 110 I=L1,M \n C(I4)=C(I4)+SM*U(1,I)\n 110 I4=I4+ICE \n 120 CONTINUE \n 130 RETURN\n END \n\n SUBROUTINE HFTI (A,MDA,M,N,B,MDB,NB,TAU,KRANK,RNORM,H,G,IP) \nc\nC SOLVE LEAST SQUARES PROBLEM USING ALGORITHM, HFTI. \nc Householder Forward Triangulation with column Interchanges.\nc\nc The original version of this code was developed by\nc Charles L. Lawson and Richard J. Hanson at Jet Propulsion Laboratory\nc 1973 JUN 12, and published in the book\nc \"SOLVING LEAST SQUARES PROBLEMS\", Prentice-HalL, 1974.\nc Revised FEB 1995 to accompany reprinting of the book by SIAM.\nC ------------------------------------------------------------------\n integer I, II, IP1, J, JB, JJ, K, KP1, KRANK\n integer L, LDIAG, LMAX, M, MDA, MDB, N, NB\nc integer IP(N) \nc double precision A(MDA,N),B(MDB,NB),H(N),G(N),RNORM(NB) \n integer IP(*) \n double precision A(MDA,*),B(MDB, *),H(*),G(*),RNORM( *) \n double precision DIFF, FACTOR, HMAX, SM, TAU, TMP, ZERO \n parameter(FACTOR = 0.001d0, ZERO = 0.0d0)\nC ------------------------------------------------------------------\nC \n K=0 \n LDIAG=min(M,N) \n IF (LDIAG.LE.0) GO TO 270 \n DO 80 J=1,LDIAG \n IF (J.EQ.1) GO TO 20 \nC \nC UPDATE SQUARED COLUMN LENGTHS AND FIND LMAX \nC .. \n LMAX=J\n DO 10 L=J,N \n H(L)=H(L)-A(J-1,L)**2 \n IF (H(L).GT.H(LMAX)) LMAX=L \n 10 CONTINUE \n IF(DIFF(HMAX+FACTOR*H(LMAX),HMAX)) 20,20,50 \nC \nC COMPUTE SQUARED COLUMN LENGTHS AND FIND LMAX \nC .. \n 20 LMAX=J\n DO 40 L=J,N \n H(L)=0. \n DO 30 I=J,M \n 30 H(L)=H(L)+A(I,L)**2 \n IF (H(L).GT.H(LMAX)) LMAX=L \n 40 CONTINUE \n HMAX=H(LMAX) \nC .. \nC LMAX HAS BEEN DETERMINED \nC \nC DO COLUMN INTERCHANGES IF NEEDED. \nC .. \n 50 CONTINUE \n IP(J)=LMAX \n IF (IP(J).EQ.J) GO TO 70 \n DO 60 I=1,M \n TMP=A(I,J)\n A(I,J)=A(I,LMAX) \n 60 A(I,LMAX)=TMP \n H(LMAX)=H(J) \nC \nC COMPUTE THE J-TH TRANSFORMATION AND APPLY IT TO A AND B. \nC .. \n 70 CALL H12 (1,J,J+1,M,A(1,J),1,H(J),A(1,J+1),1,MDA,N-J) \n 80 CALL H12 (2,J,J+1,M,A(1,J),1,H(J),B,1,MDB,NB) \nC \nC DETERMINE THE PSEUDORANK, K, USING THE TOLERANCE, TAU.\nC .. \n DO 90 J=1,LDIAG \n IF (ABS(A(J,J)).LE.TAU) GO TO 100 \n 90 CONTINUE \n K=LDIAG \n GO TO 110 \n 100 K=J-1 \n 110 KP1=K+1 \nC \nC COMPUTE THE NORMS OF THE RESIDUAL VECTORS.\nC \n IF (NB.LE.0) GO TO 140\n DO 130 JB=1,NB\n TMP=ZERO \n IF (KP1.GT.M) GO TO 130 \n DO 120 I=KP1,M\n 120 TMP=TMP+B(I,JB)**2 \n 130 RNORM(JB)=SQRT(TMP) \n 140 CONTINUE \nC SPECIAL FOR PSEUDORANK = 0 \n IF (K.GT.0) GO TO 160 \n IF (NB.LE.0) GO TO 270\n DO 150 JB=1,NB\n DO 150 I=1,N \n 150 B(I,JB)=ZERO \n GO TO 270 \nC \nC IF THE PSEUDORANK IS LESS THAN N COMPUTE HOUSEHOLDER \nC DECOMPOSITION OF FIRST K ROWS.\nC .. \n 160 IF (K.EQ.N) GO TO 180 \n DO 170 II=1,K \n I=KP1-II \n 170 CALL H12 (1,I,KP1,N,A(I,1),MDA,G(I),A,MDA,1,I-1) \n 180 CONTINUE \nC \nC \n IF (NB.LE.0) GO TO 270\n DO 260 JB=1,NB\nC \nC SOLVE THE K BY K TRIANGULAR SYSTEM. \nC .. \n DO 210 L=1,K \n SM=ZERO \n I=KP1-L \n IF (I.EQ.K) GO TO 200 \n IP1=I+1 \n DO 190 J=IP1,K \n 190 SM=SM+A(I,J)*B(J,JB)\n 200 continue\n 210 B(I,JB)=(B(I,JB)-SM)/A(I,I) \nC \nC COMPLETE COMPUTATION OF SOLUTION VECTOR. \nC .. \n IF (K.EQ.N) GO TO 240 \n DO 220 J=KP1,N\n 220 B(J,JB)=ZERO \n DO 230 I=1,K \n 230 CALL H12 (2,I,KP1,N,A(I,1),MDA,G(I),B(1,JB),1,MDB,1) \nC \nC RE-ORDER THE SOLUTION VECTOR TO COMPENSATE FOR THE \nC COLUMN INTERCHANGES. \nC .. \n 240 DO 250 JJ=1,LDIAG \n J=LDIAG+1-JJ \n IF (IP(J).EQ.J) GO TO 250 \n L=IP(J) \n TMP=B(L,JB) \n B(L,JB)=B(J,JB) \n B(J,JB)=TMP \n 250 CONTINUE \n 260 CONTINUE \nC .. \nC THE SOLUTION VECTORS, X, ARE NOW \nC IN THE FIRST N ROWS OF THE ARRAY B(,). \nC \n 270 KRANK=K \n RETURN\n END \n\n SUBROUTINE LDP (G,MDG,M,N,H,X,XNORM,W,INDEX,MODE) \nc\nC Algorithm LDP: LEAST DISTANCE PROGRAMMING\nc\nc The original version of this code was developed by\nc Charles L. Lawson and Richard J. Hanson at Jet Propulsion Laboratory\nc 1974 MAR 1, and published in the book\nc \"SOLVING LEAST SQUARES PROBLEMS\", Prentice-HalL, 1974.\nc Revised FEB 1995 to accompany reprinting of the book by SIAM.\nC ------------------------------------------------------------------\n integer I, IW, IWDUAL, IY, IZ, J, JF, M, MDG, MODE, N, NP1\nc integer INDEX(M) \nc double precision G(MDG,N), H(M), X(N), W(*) \n integer INDEX(*) \n double precision G(MDG,*), H(*), X(*), W(*)\n double precision DIFF, FAC, ONE, RNORM, XNORM, ZERO\n parameter(ONE = 1.0d0, ZERO = 0.0d0)\nC ------------------------------------------------------------------\n IF (N.LE.0) GO TO 120 \n DO 10 J=1,N \n 10 X(J)=ZERO \n XNORM=ZERO\n IF (M.LE.0) GO TO 110 \nC \nC THE DECLARED DIMENSION OF W() MUST BE AT LEAST (N+1)*(M+2)+2*M. \nC \nC FIRST (N+1)*M LOCS OF W() = MATRIX E FOR PROBLEM NNLS.\nC NEXT N+1 LOCS OF W() = VECTOR F FOR PROBLEM NNLS.\nC NEXT N+1 LOCS OF W() = VECTOR Z FOR PROBLEM NNLS.\nC NEXT M LOCS OF W() = VECTOR Y FOR PROBLEM NNLS.\nC NEXT M LOCS OF W() = VECTOR WDUAL FOR PROBLEM NNLS. \nC COPY G**T INTO FIRST N ROWS AND M COLUMNS OF E. \nC COPY H**T INTO ROW N+1 OF E. \nC \n IW=0 \n DO 30 J=1,M \n DO 20 I=1,N \n IW=IW+1 \n 20 W(IW)=G(J,I) \n IW=IW+1 \n 30 W(IW)=H(J) \n JF=IW+1 \nC STORE N ZEROS FOLLOWED BY A ONE INTO F.\n DO 40 I=1,N \n IW=IW+1 \n 40 W(IW)=ZERO \n W(IW+1)=ONE \nC \n NP1=N+1 \n IZ=IW+2 \n IY=IZ+NP1 \n IWDUAL=IY+M \nC \n CALL NNLS (W,NP1,NP1,M,W(JF),W(IY),RNORM,W(IWDUAL),W(IZ),INDEX, \n * MODE) \nC USE THE FOLLOWING RETURN IF UNSUCCESSFUL IN NNLS.\n IF (MODE.NE.1) RETURN \n IF (RNORM) 130,130,50 \n 50 FAC=ONE \n IW=IY-1 \n DO 60 I=1,M \n IW=IW+1 \nC HERE WE ARE USING THE SOLUTION VECTOR Y.\n 60 FAC=FAC-H(I)*W(IW)\nC \n IF (DIFF(ONE+FAC,ONE)) 130,130,70 \n 70 FAC=ONE/FAC \n DO 90 J=1,N \n IW=IY-1 \n DO 80 I=1,M \n IW=IW+1 \nC HERE WE ARE USING THE SOLUTION VECTOR Y.\n 80 X(J)=X(J)+G(I,J)*W(IW)\n 90 X(J)=X(J)*FAC \n DO 100 J=1,N \n 100 XNORM=XNORM+X(J)**2 \n XNORM=sqrt(XNORM) \nC SUCCESSFUL RETURN.\n 110 MODE=1\n RETURN\nC ERROR RETURN. N .LE. 0. \n 120 MODE=2\n RETURN\nC RETURNING WITH CONSTRAINTS NOT COMPATIBLE.\n 130 MODE=4\n RETURN\n END \n \n subroutine MFEOUT (A, MDA, M, N, NAMES, MODE, UNIT, WIDTH)\nc\nC LABELED MATRIX OUTPUT FOR USE WITH SINGULAR VALUE ANALYSIS.\nC \nc The original version of this code was developed by\nc Charles L. Lawson and Richard J. Hanson at Jet Propulsion Laboratory\nc 1973 JUN 12, and published in the book\nc \"SOLVING LEAST SQUARES PROBLEMS\", Prentice-HalL, 1974.\nc Revised FEB 1995 to accompany reprinting of the book by SIAM.\nC ------------------------------------------------------------------ \nc This 1995 version has additional arguments, UNIT and WIDTH,\nc to support user options regarding the output unit and the width of\nc print lines. Also allows user to choose length of names in NAMES().\nc ------------------------------------------------------------------\nc Subroutine Arguments\nC All are input arguments. None are modified by this subroutine.\nc\nC A(,) Array containing matrix to be output.\nC MDA First dimension of the array, A(,).\nC M, N No. of rows and columns, respectively in the matrix\nc contained in A(,).\nC NAMES() [character array] Array of names.\nc If NAMES(1) contains only blanks, the rest of the NAMES()\nc array will be ignored.\nC MODE =1 Write header for V matrix and use an F format.\nC =2 Write header for for candidate solutions and use\nc P format.\nc UNIT [integer] Selects output unit. If UNIT .ge. 0 then UNIT\nc is the output unit number. If UNIT = -1, output to\nc the '*' unit.\nc WIDTH [integer] Selects width of output lines.\nc Each output line from this subroutine will have at most\nc max(26,min(124,WIDTH)) characters plus one additional\nc leading character for Fortran \"carriage control\". The\nc carriage control character will always be a blank.\nc ------------------------------------------------------------------\n integer I, J, J1, J2, KBLOCK, L, LENNAM\n integer M, MAXCOL, MDA, MODE, N, NAMSIZ, NBLOCK, UNIT, WIDTH\n double precision A(MDA,N)\n character NAMES(M)*(*)\n character*4 HEAD (2)\n character*26 FMT1(2)\n character*26 FMT2(2)\n logical BLKNAM, STAR\nC\n data HEAD(1)/' COL'/\n data HEAD(2)/'SOLN'/\n data FMT1 / '(/7x,00x,8(5x,a4,i4,1x)/)',\n * '(/7x,00x,8(2x,a4,i4,4x)/)'/\n data FMT2 / '(1x,i4,1x,a00,1x,4p8f14.0)',\n * '(1x,i4,1x,a00,1x,8g14.6 )'/\nc ------------------------------------------------------------------\n if (M .le. 0 .or. N .le. 0) return\n STAR = UNIT .lt. 0\nC\nc The LEN function returns the char length of a single element of\nc the NAMES() array.\nc\n LENNAM = len(NAMES(1))\n BLKNAM = NAMES(1) .eq. ' '\n NAMSIZ = 1\n if(.not. BLKNAM) then\n do 30 I = 1,M\n do 10 L = LENNAM, NAMSIZ+1, -1\n if(NAMES(I)(L:L) .ne. ' ') then\n NAMSIZ = L\n go to 20\n endif\n 10 continue\n 20 continue\n 30 continue\n endif\nc\n write(FMT1(MODE)(6:7),'(i2.2)') NAMSIZ\n write(FMT2(MODE)(12:13),'(i2.2)') NAMSIZ\n\n 70 format(/' V-Matrix of the Singular Value Decomposition of A*D.'/\n * ' (Elements of V scaled up by a factor of 10**4)')\n 80 format(/' Sequence of candidate solutions, X')\n\n if(STAR) then\n if (MODE .eq. 1) then\n write (*,70)\n else\n write (*,80)\n endif\n else\n if (MODE .eq. 1) then\n write (UNIT,70)\n else\n write (UNIT,80)\n endif\n endif\nc\nc With NAMSIZ characters allowed for the \"name\" and MAXCOL\nc columns of numbers, the total line width, exclusive of a\nc carriage control character, will be 6 + LENNAM + 14 * MAXCOL.\nc\n MAXCOL = max(1,min(8,(WIDTH - 6 - NAMSIZ)/14))\nC\n NBLOCK = (N + MAXCOL -1) / MAXCOL\n J2 = 0\nC\n do 50 KBLOCK = 1, NBLOCK\n J1 = J2 + 1\n J2 = min(N, J2 + MAXCOL)\n if(STAR) then\n write (*,FMT1(MODE)) (HEAD(MODE),J,J=J1,J2)\n else\n write (UNIT,FMT1(MODE)) (HEAD(MODE),J,J=J1,J2)\n endif\nC\n do 40 I=1,M\n if(STAR) then\n if(BLKNAM) then\n write (*,FMT2(MODE)) I,' ',(A(I,J),J=J1,J2)\n else\n write (*,FMT2(MODE)) I,NAMES(I),(A(I,J),J=J1,J2)\n endif\n else\n if(BLKNAM) then\n write (UNIT,FMT2(MODE)) I,' ',(A(I,J),J=J1,J2)\n else\n write (UNIT,FMT2(MODE)) I,NAMES(I),(A(I,J),J=J1,J2)\n endif\n endif\n 40 continue\n 50 continue\n end\n\nC SUBROUTINE NNLS (A,MDA,M,N,B,X,RNORM,W,ZZ,INDEX,MODE)\nC \nC Algorithm NNLS: NONNEGATIVE LEAST SQUARES\nC \nc The original version of this code was developed by\nc Charles L. Lawson and Richard J. Hanson at Jet Propulsion Laboratory\nc 1973 JUN 15, and published in the book\nc \"SOLVING LEAST SQUARES PROBLEMS\", Prentice-HalL, 1974.\nc Revised FEB 1995 to accompany reprinting of the book by SIAM.\nc\nC GIVEN AN M BY N MATRIX, A, AND AN M-VECTOR, B, COMPUTE AN\nC N-VECTOR, X, THAT SOLVES THE LEAST SQUARES PROBLEM \nC \nC A * X = B SUBJECT TO X .GE. 0 \nC ------------------------------------------------------------------\nc Subroutine Arguments\nc\nC A(),MDA,M,N MDA IS THE FIRST DIMENSIONING PARAMETER FOR THE \nC ARRAY, A(). ON ENTRY A() CONTAINS THE M BY N \nC MATRIX, A. ON EXIT A() CONTAINS \nC THE PRODUCT MATRIX, Q*A , WHERE Q IS AN \nC M BY M ORTHOGONAL MATRIX GENERATED IMPLICITLY BY \nC THIS SUBROUTINE. \nC B() ON ENTRY B() CONTAINS THE M-VECTOR, B. ON EXIT B() CON- \nC TAINS Q*B.\nC X() ON ENTRY X() NEED NOT BE INITIALIZED. ON EXIT X() WILL \nC CONTAIN THE SOLUTION VECTOR. \nC RNORM ON EXIT RNORM CONTAINS THE EUCLIDEAN NORM OF THE \nC RESIDUAL VECTOR. \nC W() AN N-ARRAY OF WORKING SPACE. ON EXIT W() WILL CONTAIN \nC THE DUAL SOLUTION VECTOR. W WILL SATISFY W(I) = 0. \nC FOR ALL I IN SET P AND W(I) .LE. 0. FOR ALL I IN SET Z \nC ZZ() AN M-ARRAY OF WORKING SPACE. \nC INDEX() AN INTEGER WORKING ARRAY OF LENGTH AT LEAST N.\nC ON EXIT THE CONTENTS OF THIS ARRAY DEFINE THE SETS \nC P AND Z AS FOLLOWS.. \nC \nC INDEX(1) THRU INDEX(NSETP) = SET P. \nC INDEX(IZ1) THRU INDEX(IZ2) = SET Z. \nC IZ1 = NSETP + 1 = NPP1\nC IZ2 = N \nC MODE THIS IS A SUCCESS-FAILURE FLAG WITH THE FOLLOWING \nC MEANINGS. \nC 1 THE SOLUTION HAS BEEN COMPUTED SUCCESSFULLY.\nC 2 THE DIMENSIONS OF THE PROBLEM ARE BAD. \nC EITHER M .LE. 0 OR N .LE. 0.\nC 3 ITERATION COUNT EXCEEDED. MORE THAN 3*N ITERATIONS. \nC \nC ------------------------------------------------------------------\n SUBROUTINE NNLS (A,MDA,M,N,B,X,RNORM,W,ZZ,INDEX,MODE) \nC ------------------------------------------------------------------\n integer I, II, IP, ITER, ITMAX, IZ, IZ1, IZ2, IZMAX, J, JJ, JZ, L\n integer M, MDA, MODE,N, NPP1, NSETP, RTNKEY\nc integer INDEX(N) \nc double precision A(MDA,N), B(M), W(N), X(N), ZZ(M) \n integer INDEX(*) \n double precision A(MDA,*), B(*), W(*), X(*), ZZ(*) \n double precision ALPHA, ASAVE, CC, DIFF, DUMMY, FACTOR, RNORM\n double precision SM, SS, T, TEMP, TWO, UNORM, UP, WMAX\n double precision ZERO, ZTEST\n parameter(FACTOR = 0.01d0)\n parameter(TWO = 2.0d0, ZERO = 0.0d0)\nC ------------------------------------------------------------------\n MODE=1\n IF (M .le. 0 .or. N .le. 0) then\n MODE=2\n RETURN\n endif\n ITER=0\n ITMAX=3*N \nC \nC INITIALIZE THE ARRAYS INDEX() AND X(). \nC \n DO 20 I=1,N \n X(I)=ZERO \n 20 INDEX(I)=I \nC \n IZ2=N \n IZ1=1 \n NSETP=0 \n NPP1=1\nC ****** MAIN LOOP BEGINS HERE ****** \n 30 CONTINUE \nC QUIT IF ALL COEFFICIENTS ARE ALREADY IN THE SOLUTION.\nC OR IF M COLS OF A HAVE BEEN TRIANGULARIZED. \nC \n IF (IZ1 .GT.IZ2.OR.NSETP.GE.M) GO TO 350 \nC \nC COMPUTE COMPONENTS OF THE DUAL (NEGATIVE GRADIENT) VECTOR W().\nC \n DO 50 IZ=IZ1,IZ2 \n J=INDEX(IZ) \n SM=ZERO \n DO 40 L=NPP1,M\n 40 SM=SM+A(L,J)*B(L) \n W(J)=SM \n 50 continue\nC FIND LARGEST POSITIVE W(J). \n 60 continue\n WMAX=ZERO \n DO 70 IZ=IZ1,IZ2 \n J=INDEX(IZ) \n IF (W(J) .gt. WMAX) then\n WMAX=W(J) \n IZMAX=IZ \n endif\n 70 CONTINUE \nC \nC IF WMAX .LE. 0. GO TO TERMINATION.\nC THIS INDICATES SATISFACTION OF THE KUHN-TUCKER CONDITIONS.\nC \n IF (WMAX .le. ZERO) go to 350\n IZ=IZMAX \n J=INDEX(IZ) \nC \nC THE SIGN OF W(J) IS OK FOR J TO BE MOVED TO SET P. \nC BEGIN THE TRANSFORMATION AND CHECK NEW DIAGONAL ELEMENT TO AVOID \nC NEAR LINEAR DEPENDENCE. \nC \n ASAVE=A(NPP1,J) \n CALL H12 (1,NPP1,NPP1+1,M,A(1,J),1,UP,DUMMY,1,1,0) \n UNORM=ZERO\n IF (NSETP .ne. 0) then\n DO 90 L=1,NSETP \n 90 UNORM=UNORM+A(L,J)**2 \n endif\n UNORM=sqrt(UNORM) \n IF (DIFF(UNORM+ABS(A(NPP1,J))*FACTOR,UNORM) .gt. ZERO) then\nC \nC COL J IS SUFFICIENTLY INDEPENDENT. COPY B INTO ZZ, UPDATE ZZ\nC AND SOLVE FOR ZTEST ( = PROPOSED NEW VALUE FOR X(J) ). \nC \n DO 120 L=1,M \n 120 ZZ(L)=B(L) \n CALL H12 (2,NPP1,NPP1+1,M,A(1,J),1,UP,ZZ,1,1,1) \n ZTEST=ZZ(NPP1)/A(NPP1,J) \nC \nC SEE IF ZTEST IS POSITIVE \nC \n IF (ZTEST .gt. ZERO) go to 140\n endif\nC \nC REJECT J AS A CANDIDATE TO BE MOVED FROM SET Z TO SET P. \nC RESTORE A(NPP1,J), SET W(J)=0., AND LOOP BACK TO TEST DUAL\nC COEFFS AGAIN. \nC \n A(NPP1,J)=ASAVE \n W(J)=ZERO \n GO TO 60 \nC \nC THE INDEX J=INDEX(IZ) HAS BEEN SELECTED TO BE MOVED FROM\nC SET Z TO SET P. UPDATE B, UPDATE INDICES, APPLY HOUSEHOLDER \nC TRANSFORMATIONS TO COLS IN NEW SET Z, ZERO SUBDIAGONAL ELTS IN \nC COL J, SET W(J)=0. \nC \n 140 continue\n DO 150 L=1,M \n 150 B(L)=ZZ(L) \nC \n INDEX(IZ)=INDEX(IZ1) \n INDEX(IZ1)=J \n IZ1=IZ1+1 \n NSETP=NPP1\n NPP1=NPP1+1 \nC \n IF (IZ1 .le. IZ2) then\n DO 160 JZ=IZ1,IZ2 \n JJ=INDEX(JZ) \n CALL H12 (2,NSETP,NPP1,M,A(1,J),1,UP,A(1,JJ),1,MDA,1)\n 160 continue\n endif\nC \n IF (NSETP .ne. M) then\n DO 180 L=NPP1,M \n 180 A(L,J)=ZERO \n endif\nC \n W(J)=ZERO \nC SOLVE THE TRIANGULAR SYSTEM. \nC STORE THE SOLUTION TEMPORARILY IN ZZ().\n RTNKEY = 1\n GO TO 400 \n 200 CONTINUE \nC \nC ****** SECONDARY LOOP BEGINS HERE ****** \nC \nC ITERATION COUNTER. \nC \n 210 continue \n ITER=ITER+1 \n IF (ITER .gt. ITMAX) then\n MODE=3\n write (*,'(/a)') ' NNLS quitting on iteration count.'\n GO TO 350 \n endif\nC \nC SEE IF ALL NEW CONSTRAINED COEFFS ARE FEASIBLE. \nC IF NOT COMPUTE ALPHA. \nC \n ALPHA=TWO \n DO 240 IP=1,NSETP \n L=INDEX(IP) \n IF (ZZ(IP) .le. ZERO) then\n T=-X(L)/(ZZ(IP)-X(L)) \n IF (ALPHA .gt. T) then\n ALPHA=T \n JJ=IP \n endif\n endif\n 240 CONTINUE \nC \nC IF ALL NEW CONSTRAINED COEFFS ARE FEASIBLE THEN ALPHA WILL \nC STILL = 2. IF SO EXIT FROM SECONDARY LOOP TO MAIN LOOP. \nC \n IF (ALPHA.EQ.TWO) GO TO 330 \nC \nC OTHERWISE USE ALPHA WHICH WILL BE BETWEEN 0. AND 1. TO \nC INTERPOLATE BETWEEN THE OLD X AND THE NEW ZZ. \nC \n DO 250 IP=1,NSETP \n L=INDEX(IP) \n X(L)=X(L)+ALPHA*(ZZ(IP)-X(L)) \n 250 continue\nC \nC MODIFY A AND B AND THE INDEX ARRAYS TO MOVE COEFFICIENT I \nC FROM SET P TO SET Z. \nC \n I=INDEX(JJ) \n 260 continue\n X(I)=ZERO \nC \n IF (JJ .ne. NSETP) then\n JJ=JJ+1 \n DO 280 J=JJ,NSETP \n II=INDEX(J) \n INDEX(J-1)=II \n CALL G1 (A(J-1,II),A(J,II),CC,SS,A(J-1,II)) \n A(J,II)=ZERO \n DO 270 L=1,N \n IF (L.NE.II) then\nc\nc Apply procedure G2 (CC,SS,A(J-1,L),A(J,L)) \nc\n TEMP = A(J-1,L)\n A(J-1,L) = CC*TEMP + SS*A(J,L)\n A(J,L) =-SS*TEMP + CC*A(J,L)\n endif\n 270 CONTINUE \nc\nc Apply procedure G2 (CC,SS,B(J-1),B(J)) \nc\n TEMP = B(J-1)\n B(J-1) = CC*TEMP + SS*B(J) \n B(J) =-SS*TEMP + CC*B(J) \n 280 continue\n endif\nc\n NPP1=NSETP\n NSETP=NSETP-1 \n IZ1=IZ1-1 \n INDEX(IZ1)=I \nC \nC SEE IF THE REMAINING COEFFS IN SET P ARE FEASIBLE. THEY SHOULD\nC BE BECAUSE OF THE WAY ALPHA WAS DETERMINED.\nC IF ANY ARE INFEASIBLE IT IS DUE TO ROUND-OFF ERROR. ANY \nC THAT ARE NONPOSITIVE WILL BE SET TO ZERO \nC AND MOVED FROM SET P TO SET Z. \nC \n DO 300 JJ=1,NSETP \n I=INDEX(JJ) \n IF (X(I) .le. ZERO) go to 260\n 300 CONTINUE \nC \nC COPY B( ) INTO ZZ( ). THEN SOLVE AGAIN AND LOOP BACK.\nC \n DO 310 I=1,M \n 310 ZZ(I)=B(I) \n RTNKEY = 2\n GO TO 400 \n 320 CONTINUE \n GO TO 210 \nC ****** END OF SECONDARY LOOP ******\nC \n 330 continue\n DO 340 IP=1,NSETP \n I=INDEX(IP) \n 340 X(I)=ZZ(IP) \nC ALL NEW COEFFS ARE POSITIVE. LOOP BACK TO BEGINNING. \n GO TO 30 \nC \nC ****** END OF MAIN LOOP ****** \nC \nC COME TO HERE FOR TERMINATION. \nC COMPUTE THE NORM OF THE FINAL RESIDUAL VECTOR. \nC \n 350 continue \n SM=ZERO \n IF (NPP1 .le. M) then\n DO 360 I=NPP1,M \n 360 SM=SM+B(I)**2 \n else\n DO 380 J=1,N \n 380 W(J)=ZERO \n endif\n RNORM=sqrt(SM) \n RETURN\nC \nC THE FOLLOWING BLOCK OF CODE IS USED AS AN INTERNAL SUBROUTINE \nC TO SOLVE THE TRIANGULAR SYSTEM, PUTTING THE SOLUTION IN ZZ(). \nC \n 400 continue\n DO 430 L=1,NSETP \n IP=NSETP+1-L \n IF (L .ne. 1) then\n DO 410 II=1,IP\n ZZ(II)=ZZ(II)-A(II,JJ)*ZZ(IP+1) \n 410 continue\n endif\n JJ=INDEX(IP) \n ZZ(IP)=ZZ(IP)/A(IP,JJ) \n 430 continue\n go to (200, 320), RTNKEY\n END \n\nC SUBROUTINE QRBD (IPASS,Q,E,NN,V,MDV,NRV,C,MDC,NCC) \nc\nC QR ALGORITHM FOR SINGULAR VALUES OF A BIDIAGONAL MATRIX.\nc\nc The original version of this code was developed by\nc Charles L. Lawson and Richard J. Hanson at Jet Propulsion Laboratory\nc 1973 JUN 12, and published in the book\nc \"SOLVING LEAST SQUARES PROBLEMS\", Prentice-HalL, 1974.\nc Revised FEB 1995 to accompany reprinting of the book by SIAM.\nC ------------------------------------------------------------------ \nC THE BIDIAGONAL MATRIX \nC \nC (Q1,E2,0... )\nC ( Q2,E3,0... )\nC D= ( . )\nC ( . 0)\nC ( .EN)\nC ( 0,QN)\nC \nC IS PRE AND POST MULTIPLIED BY \nC ELEMENTARY ROTATION MATRICES \nC RI AND PI SO THAT \nC \nC RK...R1*D*P1**(T)...PK**(T) = DIAG(S1,...,SN) \nC \nC TO WITHIN WORKING ACCURACY. \nC \nC 1. EI AND QI OCCUPY E(I) AND Q(I) AS INPUT. \nC \nC 2. RM...R1*C REPLACES 'C' IN STORAGE AS OUTPUT. \nC \nC 3. V*P1**(T)...PM**(T) REPLACES 'V' IN STORAGE AS OUTPUT.\nC \nC 4. SI OCCUPIES Q(I) AS OUTPUT. \nC \nC 5. THE SI'S ARE NONINCREASING AND NONNEGATIVE. \nC \nC THIS CODE IS BASED ON THE PAPER AND 'ALGOL' CODE.. \nC REF.. \nC 1. REINSCH,C.H. AND GOLUB,G.H. 'SINGULAR VALUE DECOMPOSITION \nC AND LEAST SQUARES SOLUTIONS' (NUMER. MATH.), VOL. 14,(1970). \nC \nC ------------------------------------------------------------------ \n SUBROUTINE QRBD (IPASS,Q,E,NN,V,MDV,NRV,C,MDC,NCC) \nC ------------------------------------------------------------------ \n integer MDC, MDV, NCC, NN, NRV\nc double precision C(MDC,NCC), E(NN), Q(NN),V(MDV,NN)\n double precision C(MDC,* ), E(* ), Q(* ),V(MDV,* )\n integer I, II, IPASS, J, K, KK, L, LL, LP1, N, N10, NQRS\n double precision CS, DIFF, DNORM, F, G, H, SMALL\n double precision ONE, SN, T, TEMP, TWO, X, Y, Z, ZERO\n \n logical WNTV ,HAVERS,FAIL \n parameter(ONE = 1.0d0, TWO = 2.0d0, ZERO = 0.0d0)\nC ------------------------------------------------------------------ \n N=NN \n IPASS=1 \n IF (N.LE.0) RETURN\n N10=10*N \n WNTV=NRV.GT.0 \n HAVERS=NCC.GT.0 \n FAIL=.FALSE. \n NQRS=0\n E(1)=ZERO \n DNORM=ZERO\n DO 10 J=1,N \n 10 DNORM=max(abs(Q(J))+abs(E(J)),DNORM) \n DO 200 KK=1,N\n K=N+1-KK \nC \nC TEST FOR SPLITTING OR RANK DEFICIENCIES.. \nC FIRST MAKE TEST FOR LAST DIAGONAL TERM, Q(K), BEING SMALL. \n 20 IF(K.EQ.1) GO TO 50 \n IF(DIFF(DNORM+Q(K),DNORM) .ne. ZERO) go to 50\nC \nC SINCE Q(K) IS SMALL WE WILL MAKE A SPECIAL PASS TO \nC TRANSFORM E(K) TO ZERO. \nC \n CS=ZERO \n SN=-ONE \n DO 40 II=2,K\n I=K+1-II\n F=-SN*E(I+1)\n E(I+1)=CS*E(I+1) \n CALL G1 (Q(I),F,CS,SN,Q(I)) \nC TRANSFORMATION CONSTRUCTED TO ZERO POSITION (I,K).\nC \n IF (.NOT.WNTV) GO TO 40 \n DO 30 J=1,NRV \nc\nc Apply procedure G2 (CS,SN,V(J,I),V(J,K)) \nc\n TEMP = V(J,I)\n V(J,I) = CS*TEMP + SN*V(J,K)\n V(J,K) =-SN*TEMP + CS*V(J,K)\n 30 continue\nC ACCUMULATE RT. TRANSFORMATIONS IN V. \nC \n 40 CONTINUE\nC \nC THE MATRIX IS NOW BIDIAGONAL, AND OF LOWER ORDER \nC SINCE E(K) .EQ. ZERO.. \nC \n 50 DO 60 LL=1,K\n L=K+1-LL\n IF(DIFF(DNORM+E(L),DNORM) .eq. ZERO) go to 100\n IF(DIFF(DNORM+Q(L-1),DNORM) .eq. ZERO) go to 70\n 60 CONTINUE\nC THIS LOOP CAN'T COMPLETE SINCE E(1) = ZERO. \nC \n GO TO 100 \nC \nC CANCELLATION OF E(L), L.GT.1. \n 70 CS=ZERO \n SN=-ONE \n DO 90 I=L,K \n F=-SN*E(I) \n E(I)=CS*E(I)\n IF(DIFF(DNORM+F,DNORM) .eq. ZERO) go to 100\n CALL G1 (Q(I),F,CS,SN,Q(I)) \n IF (HAVERS) then\n DO 80 J=1,NCC \nc\nc Apply procedure G2 ( CS, SN, C(I,J), C(L-1,J)\nc\n TEMP = C(I,J)\n C(I,J) = CS*TEMP + SN*C(L-1,J)\n C(L-1,J) =-SN*TEMP + CS*C(L-1,J)\n 80 continue\n endif\n 90 CONTINUE\nC \nC TEST FOR CONVERGENCE.. \n 100 Z=Q(K) \n IF (L.EQ.K) GO TO 170 \nC \nC SHIFT FROM BOTTOM 2 BY 2 MINOR OF B**(T)*B. \n X=Q(L) \n Y=Q(K-1) \n G=E(K-1) \n H=E(K) \n F=((Y-Z)*(Y+Z)+(G-H)*(G+H))/(TWO*H*Y)\n G=sqrt(ONE+F**2) \n IF (F .ge. ZERO) then\n T=F+G\n else\n T=F-G\n endif\n F=((X-Z)*(X+Z)+H*(Y/T-H))/X \nC \nC NEXT QR SWEEP.. \n CS=ONE \n SN=ONE \n LP1=L+1 \n DO 160 I=LP1,K \n G=E(I) \n Y=Q(I) \n H=SN*G \n G=CS*G \n CALL G1 (F,H,CS,SN,E(I-1)) \n F=X*CS+G*SN \n G=-X*SN+G*CS\n H=Y*SN \n Y=Y*CS \n IF (WNTV) then\nC \nC ACCUMULATE ROTATIONS (FROM THE RIGHT) IN 'V' \nc\n DO 130 J=1,NRV \nc \nc Apply procedure G2 (CS,SN,V(J,I-1),V(J,I))\nc\n TEMP = V(J,I-1)\n V(J,I-1) = CS*TEMP + SN*V(J,I)\n V(J,I) =-SN*TEMP + CS*V(J,I)\n 130 continue\n endif\n CALL G1 (F,H,CS,SN,Q(I-1)) \n F=CS*G+SN*Y \n X=-SN*G+CS*Y\n IF (HAVERS) then\n DO 150 J=1,NCC \nc\nc Apply procedure G2 (CS,SN,C(I-1,J),C(I,J))\nc\n TEMP = C(I-1,J)\n C(I-1,J) = CS*TEMP + SN*C(I,J)\n C(I,J) =-SN*TEMP + CS*C(I,J)\n 150 continue\n endif\nc\nC APPLY ROTATIONS FROM THE LEFT TO \nC RIGHT HAND SIDES IN 'C'..\nC \n 160 CONTINUE\n E(L)=ZERO \n E(K)=F \n Q(K)=X \n NQRS=NQRS+1 \n IF (NQRS.LE.N10) GO TO 20\nC RETURN TO 'TEST FOR SPLITTING'. \nC \n SMALL=ABS(E(K))\n I=K \nC IF FAILURE TO CONVERGE SET SMALLEST MAGNITUDE\nC TERM IN OFF-DIAGONAL TO ZERO. CONTINUE ON.\nC .. \n DO 165 J=L,K \n TEMP=ABS(E(J))\n IF(TEMP .EQ. ZERO) GO TO 165\n IF(TEMP .LT. SMALL) THEN\n SMALL=TEMP\n I=J\n end if \n 165 CONTINUE\n E(I)=ZERO\n NQRS=0\n FAIL=.TRUE. \n GO TO 20\nC .. \nC CUTOFF FOR CONVERGENCE FAILURE. 'NQRS' WILL BE 2*N USUALLY. \n 170 IF (Z.GE.ZERO) GO TO 190 \n Q(K)=-Z \n IF (WNTV) then\n DO 180 J=1,NRV \n 180 V(J,K)=-V(J,K) \n endif\n 190 CONTINUE \nC CONVERGENCE. Q(K) IS MADE NONNEGATIVE.. \nC \n 200 CONTINUE \n IF (N.EQ.1) RETURN\n DO 210 I=2,N \n IF (Q(I).GT.Q(I-1)) GO TO 220\n 210 CONTINUE \n IF (FAIL) IPASS=2 \n RETURN\nC .. \nC EVERY SINGULAR VALUE IS IN ORDER..\n 220 DO 270 I=2,N \n T=Q(I-1) \n K=I-1\n DO 230 J=I,N\n IF (T.GE.Q(J)) GO TO 230\n T=Q(J) \n K=J \n 230 CONTINUE\n IF (K.EQ.I-1) GO TO 270 \n Q(K)=Q(I-1) \n Q(I-1)=T \n IF (HAVERS) then\n DO 240 J=1,NCC \n T=C(I-1,J) \n C(I-1,J)=C(K,J) \n 240 C(K,J)=T\n endif\n\n 250 IF (WNTV) then\n DO 260 J=1,NRV \n T=V(J,I-1) \n V(J,I-1)=V(J,K) \n 260 V(J,K)=T\n endif\n 270 CONTINUE \nC END OF ORDERING ALGORITHM.\nC \n IF (FAIL) IPASS=2 \n RETURN\n END \n subroutine SVA(A,MDA,M,N,MDATA,B,SING,KPVEC,NAMES,ISCALE,D,WORK)\nc\nC SINGULAR VALUE ANALYSIS. COMPUTES THE SINGULAR VALUE\nC DECOMPOSITION OF THE MATRIX OF A LEAST SQUARES PROBLEM, AND\nC PRODUCES A PRINTED REPORT.\nc\nc The original version of this code was developed by\nc Charles L. Lawson and Richard J. Hanson at Jet Propulsion Laboratory\nc 1973 JUN 12, and published in the book\nc \"SOLVING LEAST SQUARES PROBLEMS\", Prentice-HalL, 1974.\nc Revised FEB 1995 to accompany reprinting of the book by SIAM.\nC ------------------------------------------------------------------ \nc This 1995 version differs from the original 1973 version by the \nc addition of the arguments KPVEC() and WORK(), and by allowing user to\nc choose the length of names in NAMES().\nc KPVEC() allows the user to exercise options regarding printing.\nc WORK() provides 2*N locations of work space. Originally SING() was\nc required to have 3*N elements, of which the last 2*N were used for\nc work space. Now SING() only needs N elements.\nc ------------------------------------------------------------------\nc Subroutine Arguments\nc A(,) [inout] On entry, contains the M x N matrix of the least\nc squares problem to be analyzed. This could be a matrix\nc obtained by preliminary orthogonal transformations\nc applied to the actual problem matrix which may have had\nc more rows (See MDATA below.)\nc\nc MDA [in] First dimensioning parameter for A(,). Require\nc MDA .ge. max(M, N).\nc\nc M,N [in] No. of rows and columns, respectively, in the\nc matrix, A. Either M > N or M .le. N is permitted.\nc Require M > 0 and N > 0.\nc\nc MDATA [in] No. of rows in actual least squares problem.\nc Generally MDATA .ge. M. MDATA is used only in computing\nc statistics for the report and is not used as a loop\nc count or array dimension.\nc\nc B() [inout] On entry, contains the right-side vector, b, of the\nc least squares problem. This vector is of length, M.\nc On return, contains the vector, g = (U**t)*b, where U\nc comes from the singular value decomposition of A. The\nc vector , g, is also of length M.\nc\nc SING() [out] On return, contains the singular values of A, in\nc descending order, in locations indexed 1 thru min(M,N).\nc If M < N, locations indexed from M+1 through N will be\nc set to zero.\nc\nc KPVEC() [integer array, in] Array of integers to select print\nc options. KPVEC(1) determines whether the rest of\nc the array is to be used or ignored.\nc If KPVEC(1) = 1, the contents of (KPVEC(I), I=2,4)\nc will be used to set internal variables as follows:\nc PRBLK = KPVEC(2)\nc UNIT = KPVEC(3)\nc WIDTH = KPVEC(4)\nc If KPVEC(1) = 0 default settings will be used. The user\nc need not dimension KPVEC() greater than 1. The subr will\nc set PRBLK = 111111, UNIT = -1, and WIDTH = 69.\nc\nc The internal variables PRBLK, UNIT, and WIDTH are\nc interpreted as follows:\nc\nc PRBLK The decimal representation of PRBLK must be\nc representable as at most 6 digits, each being 0 or 1.\nc The decimal digits will be interpreted as independant\nc on/off flags for the 6 possible blocks of printed output.\nc Examples: 111111 selects all blocks, 0 suppresses all\nc printing, 101010 selects the 1st, 3rd, and 5th blocks,\nc etc.\nc The six blocks are:\nc 1. Header, with size and scaling option parameters.\nc 2. V-matrix. Amount of output depends on M and N.\nc 3. Singular values and related quantities. Amount of\nc output depends on N.\nc 4. Listing of YNORM and RNORM and their logarithms.\nc Amount of output depends on N.\nc 5. Levenberg-Marquart analysis.\nc 6. Candidate solutions. Amount of output depends on\nc M and N.\nc\nc UNIT Selects the output unit. If UNIT .ge. 0,\nc UNIT will be used as the output unit number.\nc If UNIT = -1, output will be written to the \"*\" output\nc unit, i.e., the standard system output unit.\nc The calling program unit is responsible for opening\nc and/or closing the selected output unit if the host\nc system requires these actions.\nc\nc WIDTH Default value is 79. Determines the width of\nc blocks 2, 3, and 6 of the output report.\nc Block 3 will use 95(+1) cols if WIDTH .ge. 95, and otherwise\nc 69(+1) cols.\nc Blocks 2 and 6 are printed by subroutine MFEOUT. These blocks\nc generally use at most WIDTH(+1) cols, but will use more if\nc the names are so long that more space is needed to print one\nc name and one numeric column. The (+1)'s above are reminders\nc that in all cases there is one extra initial column for Fortran\nc \"carriage control\". The carriage control character will always\nc be a blank.\nc Blocks 1, 4, and 5 have fixed widths of 63(+1), 66(+1) and\nc 66(+1), respectively.\nc\nc NAMES() [in] NAMES(j), for j = 1, ..., N, may contain a\nc name for the jth component of the solution\nc vector. The declared length of the elements of the\nc NAMES() array is not specifically limited, but a\nc greater length reduces the space available for columns\nc of the matris to be printed.\nc If NAMES(1) contains only blank characters,\nc it will be assumed that no names have been provided,\nc and this subr will not access the NAMES() array beyond\nc the first element.\nC\nC ISCALE [in] Set by the user to 1, 2, or 3 to select the column\nc scaling option.\nC 1 SUBR WILL USE IDENTITY SCALING AND IGNORE THE D()\nC ARRAY.\nC 2 SUBR WILL SCALE NONZERO COLS TO HAVE UNIT EUCLID-\nC EAN LENGTH AND WILL STORE RECIPROCAL LENGTHS OF\nC ORIGINAL NONZERO COLS IN D().\nC 3 USER SUPPLIES COL SCALE FACTORS IN D(). SUBR\nC WILL MULT COL J BY D(J) AND REMOVE THE SCALING\nC FROM THE SOLN AT THE END.\nc\nc D() [ignored or out or in] Usage of D() depends on ISCALE as\nc described above. When used, its length must be\nc at least N.\nc\nc WORK() [scratch] Work space of length at least 2*N. Used\nc directly in this subr and also in _SVDRS.\nc ------------------------------------------------------------------\n integer I, IE, IPASS, ISCALE, J, K, KPVEC(4), M, MDA, MDATA\n integer MINMN, MINMN1, MPASS, N, NSOL\n integer PRBLK, UNIT, WIDTH\n double precision A(MDA,N), A1, A2, A3, A4, ALAMB, ALN10, B(M)\n double precision D(N), DEL, EL, EL2\n double precision ONE, PCOEF, RL, RNORM, RS\n double precision SB, SING(N), SL, TEN, THOU, TWENTY\n double precision WORK(2*N), YL, YNORM, YS, YSQ, ZERO\n character*(*) NAMES(N)\n logical BLK(6), NARROW, STAR\n parameter( ZERO = 0.0d0, ONE = 1.0d0)\n parameter( TEN = 10.0d0, TWENTY = 20.0d0, THOU = 1000.0d0)\nc -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n 220 format (1X/' INDEX SING. VAL. P COEF ',\n * ' RECIPROCAL G COEF G**2 ',\n * ' CUMULATIVE SCALED SQRT'/\n * 31x,' SING. VAL.',26x,\n * ' SUM of SQRS of CUM.S.S.')\n 221 format (1X/' INDEX SING. VAL. P COEF ',\n * ' RECIPROCAL G COEF SCALED SQRT'/\n * 31x,' SING. VAL.',13x,' of CUM.S.S.')\n 222 format (1X/' INDEX SING. VAL. G COEF G**2 ',\n * ' CUMULATIVE SCALED SQRT'/\n * 44x,' SUM of SQRS of CUM.S.S.')\n\n 230 format (' ',4X,'0',64X,2g13.4)\n 231 format (' ',4X,'0',51X, g13.4)\n 232 format (' ',4X,'0',38X,2g13.4)\n\n 240 format (' ',i5,g12.4,6g13.4)\n\n 260 format (1X,' M = ',I6,', N =',I4,', MDATA =',I8)\n 270 format (1X/' Singular Value Analysis of the least squares',\n * ' problem, A*X = B,'/\n * ' scaled as (A*D)*Y = B.')\n 280 format (1X/' Scaling option No.',I2,'. D is a diagonal',\n * ' matrix with the following diagonal elements..'/(5X,10E12.4))\n 290 format (1X/' Scaling option No. 1. D is the identity matrix.'/\n * 1X)\n 300 format (1X/' INDEX',12X,'YNORM RNORM',11X,\n * ' LOG10 LOG10'/\n * 45X,' YNORM RNORM'/1X)\n 310 format (' ',I5,6X,2E11.3,11X,2F11.3)\n 320 format (1X/\n *' Norms of solution and residual vectors for a range of values'/\n *' of the Levenberg-Marquardt parameter, LAMBDA.'//\n * ' LAMBDA YNORM RNORM',\n * ' LOG10 LOG10 LOG10'/\n * 34X,' LAMBDA YNORM RNORM')\n 330 format (1X, 3E11.3, 3F11.3)\nc ------------------------------------------------------------------\n IF (M.LE.0 .OR. N.LE.0) RETURN\n MINMN = min(M,N)\n MINMN1 = MINMN + 1\n if(KPVEC(1) .eq. 0) then\n PRBLK = 111111\n UNIT = -1\n WIDTH = 79\n else\n PRBLK = KPVEC(2)\n UNIT = KPVEC(3)\n WIDTH = KPVEC(4)\n endif\n STAR = UNIT .lt. 0\nc Build logical array BLK() by testing\nc decimal digits of PRBLK.\n do 20 I=6, 1, -1\n J = PRBLK/10\n BLK(I) = (PRBLK - 10*J) .gt. 0\n PRBLK = J\n 20 continue\nc -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\nc Optionally print header and M, N, MDATA\n if(BLK(1)) then\n if(STAR) then\n write (*,270)\n write (*,260) M,N,MDATA\n else\n write (UNIT,270)\n write (UNIT,260) M,N,MDATA\n endif\n endif\nc -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\nc Handle scaling as selected by ISCALE.\n if( ISCALE .eq. 1) then\n if(BLK(1)) then\n if(STAR) then\n write (*,290)\n else\n write (UNIT,290)\n endif\n endif\n else\nC\nC Apply column scaling to A.\nC\n DO 52 J = 1,N\n A1 = D(J)\n if( ISCALE .le. 2) then\n SB = ZERO\n DO 30 I = 1,M\n 30 SB = SB + A(I,J)**2\n A1 = sqrt(SB)\n IF (A1.EQ.ZERO) A1 = ONE\n A1 = ONE/A1\n D(J) = A1\n endif\n DO 50 I = 1,M\n A(I,J) = A(I,J)*A1\n 50 continue\n 52 continue\n if(BLK(1)) then\n if(STAR) then\n write (*,280) ISCALE,(D(J),J = 1,N)\n else\n write (UNIT,280) ISCALE,(D(J),J = 1,N)\n endif\n endif\n endif\nc -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\nC Compute the Singular Value Decomposition of the scaled matrix.\nC\n call SVDRS (A,MDA,M,N,B,M,1,SING,WORK)\nc\nc Determine NSOL.\n NSOL = MINMN\n do 60 J = 1,MINMN\n if(SING(J) .eq. ZERO) then\n NSOL = J-1\n go to 65\n endif\n 60 continue\n 65 continue\nC\nc The array B() contains the vector G.\nC Compute cumulative sums of squares of components of\nC G and store them in WORK(I), I = 1,...,MINMN+1\nC\n SB = ZERO\n DO 70 I = MINMN1,M\n SB = SB + B(I)**2\n 70 CONTINUE\n WORK(MINMN+1) = SB\n DO 75 J = MINMN, 1, -1\n SB = SB + B(J)**2\n WORK(J) = SB\n 75 CONTINUE\nc -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\nC PRINT THE V MATRIX.\nC\n if(BLK(2)) CALL MFEOUT (A,MDA,N,N,NAMES,1, UNIT, WIDTH)\nc -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\nC REPLACE V BY D*V IN THE ARRAY A()\n if (ISCALE .gt.1) then\n do 82 I = 1,N\n do 80 J = 1,N\n A(I,J) = D(I)*A(I,J)\n 80 continue\n 82 continue\n endif\nc -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n if(BLK(3)) then\nc Print singular values and other summary results.\nc\nc Output will be done using one of two layouts. The narrow\nc layout uses 69 cols + 1 for carriage control, and makes two passes\nc through the computation.\nc The wide layout uses 95 cols + 1 for carriage control, and makes\nc only one pass through the computation.\nc\nC G NOW IN B() ARRAY. V NOW IN A(,) ARRAY.\nC\n NARROW = WIDTH .lt. 95\n MPASS = 1\n if(NARROW) MPASS = 2\n do 170 IPASS = 1, MPASS\n if(STAR) then\n if(NARROW) then\n if(IPASS .eq. 1) then\n write(*,221)\n else\n write(*,222)\n endif\n else\n write (*,220)\n endif\n else\n if(NARROW) then\n if(IPASS .eq. 1) then\n write(UNIT,221)\n else\n write(UNIT,222)\n endif\n else\n write (UNIT,220)\n endif\n endif\nc The following stmt converts from\nc integer to floating-point.\n A3 = WORK(1)\n A4 = sqrt(A3/ max(1,MDATA))\n if(STAR) then\n if(NARROW) then\n if(IPASS .eq. 1) then\n write(*,231) A4\n else\n write(*,232) A3, A4\n endif\n else\n write (*,230) A3,A4\n endif\n else\n if(NARROW) then\n if(IPASS .eq. 1) then\n write(UNIT,231) A4\n else\n write(UNIT,232) A3, A4\n endif\n else\n write (UNIT,230) A3,A4\n endif\n endif\nC\n DO 160 K = 1,MINMN\n if (SING(K).EQ.ZERO) then\n PCOEF = ZERO\n if(STAR) then\n write (*,240) K,SING(K)\n else\n write (UNIT,240) K,SING(K)\n endif\n else\n PCOEF = B(K) / SING(K)\n A1 = ONE / SING(K)\n A2 = B(K)**2\n A3 = WORK(K+1)\n A4 = sqrt(A3/max(1,MDATA-K))\n if(STAR) then\n if(NARROW) then\n if(IPASS .eq. 1) then\n write(*,240) K,SING(K),PCOEF,A1,B(K), A4\n else\n write(*,240) K,SING(K), B(K),A2,A3,A4\n endif\n else\n write (*,240) K,SING(K),PCOEF,A1,B(K),A2,A3,A4\n endif\n else\n if(NARROW) then\n if(IPASS .eq. 1) then\n write(UNIT,240) K,SING(K),PCOEF,A1,B(K), A4\n else\n write(UNIT,240) K,SING(K), B(K),A2,A3,A4\n endif\n else\n write (UNIT,240) K,SING(K),PCOEF,A1,B(K),A2,A3,A4\n endif\n\n endif\n endif\n 160 continue\n 170 continue\n endif\nc -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n if( BLK(4) ) then\nC\nC Compute and print values of YNORM, RNORM and their logarithms.\nC\n if(STAR) then\n write (*,300)\n else\n write (UNIT,300)\n endif\n YSQ = ZERO\n do 180 J = 0, NSOL\n if(J .ne. 0) YSQ = YSQ + (B(J) / SING(J))**2\n YNORM = sqrt(YSQ)\n RNORM = sqrt(WORK(J+1))\n YL = -THOU\n IF (YNORM .GT. ZERO) YL = log10(YNORM)\n RL = -THOU\n IF (RNORM .GT. ZERO) RL = log10(RNORM)\n if(STAR) then\n write (*,310) J,YNORM,RNORM,YL,RL\n else\n write (UNIT,310) J,YNORM,RNORM,YL,RL\n endif\n 180 continue\n endif\nc -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n if( BLK(5) .and. SING(1) .ne. ZERO ) then\nC\nC COMPUTE VALUES OF XNORM AND RNORM FOR A SEQUENCE OF VALUES OF\nC THE LEVENBERG-MARQUARDT PARAMETER.\nC\n EL = log10(SING(1)) + ONE\n EL2 = log10(SING(NSOL)) - ONE\n DEL = (EL2-EL) / TWENTY\n ALN10 = log(TEN)\n if(STAR) then\n write (*,320)\n else\n write (UNIT,320)\n endif\n DO 200 IE = 1,21\nC COMPUTE ALAMB = 10.0**EL\n ALAMB = EXP(ALN10*EL)\n YS = ZERO\n RS = WORK(NSOL+1)\n DO 190 I = 1,MINMN\n SL = SING(I)**2 + ALAMB**2\n YS = YS + (B(I)*SING(I)/SL)**2\n RS = RS + (B(I)*(ALAMB**2)/SL)**2\n 190 CONTINUE\n YNORM = sqrt(YS)\n RNORM = sqrt(RS)\n RL = -THOU\n IF (RNORM.GT.ZERO) RL = log10(RNORM)\n YL = -THOU\n IF (YNORM.GT.ZERO) YL = log10(YNORM)\n if(STAR) then\n write (*,330) ALAMB,YNORM,RNORM,EL,YL,RL\n else\n write (UNIT,330) ALAMB,YNORM,RNORM,EL,YL,RL\n endif\n EL = EL + DEL\n 200 CONTINUE\n endif\nc -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\nC Compute and optionally print candidate solutions.\nC\n do 215 K = 1,NSOL\n PCOEF = B(K) / SING(K)\n DO 210 I = 1,N\n A(I,K) = A(I,K) * PCOEF\n 210 IF (K.GT.1) A(I,K) = A(I,K) + A(I,K-1)\n 215 continue\n if (BLK(6) .and. NSOL.GE.1)\n * CALL MFEOUT (A,MDA,N,NSOL,NAMES,2,UNIT,WIDTH)\n return\n END\nC SUBROUTINE SVDRS (A, MDA, M1, N1, B, MDB, NB, S, WORK) \nc\nC SINGULAR VALUE DECOMPOSITION ALSO TREATING RIGHT SIDE VECTOR.\nc\nc The original version of this code was developed by\nc Charles L. Lawson and Richard J. Hanson at Jet Propulsion Laboratory\nc 1974 SEP 25, and published in the book\nc \"SOLVING LEAST SQUARES PROBLEMS\", Prentice-HalL, 1974.\nc Revised FEB 1995 to accompany reprinting of the book by SIAM.\nC ------------------------------------------------------------------ \nc This 1995 version differs from the original 1974 version by adding\nc the argument WORK().\nc WORK() provides 2*N1 locations of work space. Originally S() was\nc required to have 3*N1 elements, of which the last 2*N1 were used for\nc work space. Now S() only needs N1 elements.\nC ------------------------------------------------------------------\nc This subroutine computes the singular value decomposition of the\nc given M1 x N1 matrix, A, and optionally applys the transformations\nc from the left to the NB column vectors of the M1 x NB matrix B.\nc Either M1 .ge. N1 or M1 .lt. N1 is permitted.\nc\nc The singular value decomposition of A is of the form\nc\nc A = U * S * V**t\nc\nc where U is M1 x M1 orthogonal, S is M1 x N1 diagonal with the\nc diagonal terms nonnegative and ordered from large to small, and\nc V is N1 x N1 orthogonal. Note that these matrices also satisfy\nc\nc S = (U**t) * A * V\nc\nc The matrix V is returned in the leading N1 rows and\nc columns of the array A(,).\nc\nc The singular values, i.e. the diagonal terms of the matrix S,\nc are returned in the array S(). If M1 .lt. N1, positions M1+1\nc through N1 of S() will be set to zero.\nc\nc The product matrix G = U**t * B replaces the given matrix B\nc in the array B(,).\nc\nc If the user wishes to obtain a minimum length least squares\nc solution of the linear system\nc\nc A * X ~=~ B\nc\nc the solution X can be constructed, following use of this subroutine,\nc by computing the sum for i = 1, ..., R of the outer products\nc\nc (Col i of V) * (1/S(i)) * (Row i of G)\nc\nc Here R denotes the pseudorank of A which the user may choose\nc in the range 0 through Min(M1, N1) based on the sizes of the\nc singular values.\nC ------------------------------------------------------------------\nC Subroutine Arguments\nc\nc A(,) (In/Out) On input contains the M1 x N1 matrix A.\nc On output contains the N1 x N1 matrix V.\nc\nc LDA (In) First dimensioning parameter for A(,).\nc Require LDA .ge. Max(M1, N1).\nc\nc M1 (In) No. of rows of matrices A, B, and G.\nc Require M1 > 0.\nc\nc N1 (In) No. of cols of matrix A, No. of rows and cols of\nc matrix V. Permit M1 .ge. N1 or M1 .lt. N1.\nc Require N1 > 0.\nc\nc B(,) (In/Out) If NB .gt. 0 this array must contain an\nc M1 x NB matrix on input and will contain the\nc M1 x NB product matrix, G = (U**t) * B on output.\nc\nc LDB (In) First dimensioning parameter for B(,).\nc Require LDB .ge. M1.\nc\nc NB (In) No. of cols in the matrices B and G.\nc Require NB .ge. 0.\nc\nc S() (Out) Must be dimensioned at least N1. On return will\nc contain the singular values of A, with the ordering\nc S(1) .ge. S(2) .ge. ... .ge. S(N1) .ge. 0.\nc If M1 .lt. N1 the singular values indexed from M1+1\nc through N1 will be zero.\nc If the given integer arguments are not consistent, this\nc subroutine will return immediately, setting S(1) = -1.0.\nc\nc WORK() (Scratch) Work space of total size at least 2*N1.\nc Locations 1 thru N1 will hold the off-diagonal terms of\nc the bidiagonal matrix for subroutine QRBD. Locations N1+1\nc thru 2*N1 will save info from one call to the next of\nc H12.\nc ------------------------------------------------------------------\nC This code gives special treatment to rows and columns that are\nc entirely zero. This causes certain zero sing. vals. to appear as\nc exact zeros rather than as about MACHEPS times the largest sing. val.\nc It similarly cleans up the associated columns of U and V. \nc\nc METHOD.. \nc 1. EXCHANGE COLS OF A TO PACK NONZERO COLS TO THE LEFT. \nc SET N = NO. OF NONZERO COLS. \nc USE LOCATIONS A(1,N1),A(1,N1-1),...,A(1,N+1) TO RECORD THE \nc COL PERMUTATIONS. \nc 2. EXCHANGE ROWS OF A TO PACK NONZERO ROWS TO THE TOP. \nc QUIT PACKING IF FIND N NONZERO ROWS. MAKE SAME ROW EXCHANGES \nc IN B. SET M SO THAT ALL NONZERO ROWS OF THE PERMUTED A \nc ARE IN FIRST M ROWS. IF M .LE. N THEN ALL M ROWS ARE \nc NONZERO. IF M .GT. N THEN THE FIRST N ROWS ARE KNOWN \nc TO BE NONZERO,AND ROWS N+1 THRU M MAY BE ZERO OR NONZERO. \nc 3. APPLY ORIGINAL ALGORITHM TO THE M BY N PROBLEM. \nc 4. MOVE PERMUTATION RECORD FROM A(,) TO S(I),I=N+1,...,N1. \nc 5. BUILD V UP FROM N BY N TO N1 BY N1 BY PLACING ONES ON \nc THE DIAGONAL AND ZEROS ELSEWHERE. THIS IS ONLY PARTLY DONE \nc EXPLICITLY. IT IS COMPLETED DURING STEP 6. \nc 6. EXCHANGE ROWS OF V TO COMPENSATE FOR COL EXCHANGES OF STEP 2. \nc 7. PLACE ZEROS IN S(I),I=N+1,N1 TO REPRESENT ZERO SING VALS. \nc ------------------------------------------------------------------\n subroutine SVDRS (A, MDA, M1, N1, B, MDB, NB, S, WORK) \n integer I, IPASS, J, K, L, M, MDA, MDB, M1\n integer N, NB, N1, NP1, NS, NSP1\nc double precision A(MDA,N1),B(MDB,NB), S(N1)\n double precision A(MDA, *),B(MDB, *), S( *)\n double precision ONE, T, WORK(N1,2), ZERO\n parameter(ONE = 1.0d0, ZERO = 0.0d0)\nc -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\nC BEGIN.. SPECIAL FOR ZERO ROWS AND COLS. \nC \nC PACK THE NONZERO COLS TO THE LEFT \nC \n N=N1 \n IF (N.LE.0.OR.M1.LE.0) RETURN \n J=N \n 10 CONTINUE \n DO 20 I=1,M1 \n IF (A(I,J) .ne. ZERO) go to 50\n 20 CONTINUE \nC \nC COL J IS ZERO. EXCHANGE IT WITH COL N. \nC \n IF (J .ne. N) then\n DO 30 I=1,M1 \n 30 A(I,J)=A(I,N) \n endif\n A(1,N)=J \n N=N-1 \n 50 CONTINUE \n J=J-1 \n IF (J.GE.1) GO TO 10 \nC IF N=0 THEN A IS ENTIRELY ZERO AND SVD \nC COMPUTATION CAN BE SKIPPED \n NS=0 \n IF (N.EQ.0) GO TO 240 \nC PACK NONZERO ROWS TO THE TOP \nC QUIT PACKING IF FIND N NONZERO ROWS \n I=1 \n M=M1 \n 60 IF (I.GT.N.OR.I.GE.M) GO TO 150 \n IF (A(I,I)) 90,70,90 \n 70 DO 80 J=1,N \n IF (A(I,J)) 90,80,90 \n 80 CONTINUE \n GO TO 100 \n 90 I=I+1 \n GO TO 60 \nC ROW I IS ZERO \nC EXCHANGE ROWS I AND M \n 100 IF(NB.LE.0) GO TO 115 \n DO 110 J=1,NB \n T=B(I,J) \n B(I,J)=B(M,J) \n 110 B(M,J)=T \n 115 DO 120 J=1,N \n 120 A(I,J)=A(M,J) \n IF (M.GT.N) GO TO 140 \n DO 130 J=1,N \n 130 A(M,J)=ZERO \n 140 CONTINUE \nC EXCHANGE IS FINISHED \n M=M-1 \n GO TO 60 \nC \n 150 CONTINUE \nC END.. SPECIAL FOR ZERO ROWS AND COLUMNS \nC BEGIN.. SVD ALGORITHM \nC METHOD.. \nC (1) REDUCE THE MATRIX TO UPPER BIDIAGONAL FORM WITH \nC HOUSEHOLDER TRANSFORMATIONS. \nC H(N)...H(1)AQ(1)...Q(N-2) = (D**T,0)**T \nC WHERE D IS UPPER BIDIAGONAL. \nC \nC (2) APPLY H(N)...H(1) TO B. HERE H(N)...H(1)*B REPLACES B \nC IN STORAGE. \nC \nC (3) THE MATRIX PRODUCT W= Q(1)...Q(N-2) OVERWRITES THE FIRST \nC N ROWS OF A IN STORAGE. \nC \nC (4) AN SVD FOR D IS COMPUTED. HERE K ROTATIONS RI AND PI ARE \nC COMPUTED SO THAT \nC RK...R1*D*P1**(T)...PK**(T) = DIAG(S1,...,SM) \nC TO WORKING ACCURACY. THE SI ARE NONNEGATIVE AND NONINCREASING. \nC HERE RK...R1*B OVERWRITES B IN STORAGE WHILE \nC A*P1**(T)...PK**(T) OVERWRITES A IN STORAGE. \nC \nC (5) IT FOLLOWS THAT,WITH THE PROPER DEFINITIONS, \nC U**(T)*B OVERWRITES B, WHILE V OVERWRITES THE FIRST N ROW AND \nC COLUMNS OF A. \nC \n L=min(M,N) \nC THE FOLLOWING LOOP REDUCES A TO UPPER BIDIAGONAL AND \nC ALSO APPLIES THE PREMULTIPLYING TRANSFORMATIONS TO B. \nC \n DO 170 J=1,L \n IF (J.GE.M) GO TO 160 \n CALL H12 (1,J,J+1,M,A(1,J),1,T,A(1,J+1),1,MDA,N-J)\n CALL H12 (2,J,J+1,M,A(1,J),1,T,B,1,MDB,NB)\n 160 IF (J.GE.N-1) GO TO 170 \n CALL H12 (1,J+1,J+2,N,A(J,1),MDA,work(J,2),A(J+1,1),MDA,1,M-J) \n 170 CONTINUE \nC \nC COPY THE BIDIAGONAL MATRIX INTO S() and WORK() FOR QRBD. \nC 1986 Jan 8. C. L. Lawson. Changed N to L in following 2 statements.\n IF (L.EQ.1) GO TO 190 \n DO 180 J=2,L \n S(J)=A(J,J) \n 180 WORK(J,1)=A(J-1,J) \n 190 S(1)=A(1,1) \nC \n NS=N \n IF (M.GE.N) GO TO 200 \n NS=M+1\n S(NS)=ZERO \n WORK(NS,1)=A(M,M+1) \n 200 CONTINUE \nC \nC CONSTRUCT THE EXPLICIT N BY N PRODUCT MATRIX, W=Q1*Q2*...*QL*I \nC IN THE ARRAY A(). \nC \n DO 230 K=1,N \n I=N+1-K \n IF (I .GT. min(M,N-2)) GO TO 210 \n CALL H12 (2,I+1,I+2,N,A(I,1),MDA,WORK(I,2),A(1,I+1),1,MDA,N-I) \n 210 DO 220 J=1,N \n 220 A(I,J)=ZERO \n 230 A(I,I)=ONE \nC \nC COMPUTE THE SVD OF THE BIDIAGONAL MATRIX \nC \n CALL QRBD (IPASS,S(1),WORK(1,1),NS,A,MDA,N,B,MDB,NB) \nC \n if(IPASS .eq. 2) then\n write (*,'(/a)')\n * ' FULL ACCURACY NOT ATTAINED IN BIDIAGONAL SVD'\n endif\n\n 240 CONTINUE \n IF (NS.GE.N) GO TO 260\n NSP1=NS+1 \n DO 250 J=NSP1,N \n 250 S(J)=ZERO \n 260 CONTINUE \n IF (N.EQ.N1) RETURN \n NP1=N+1 \nC MOVE RECORD OF PERMUTATIONS \nC AND STORE ZEROS \n DO 280 J=NP1,N1 \n S(J)=A(1,J) \n DO 270 I=1,N \n 270 A(I,J)=ZERO \n 280 CONTINUE \nC PERMUTE ROWS AND SET ZERO SINGULAR VALUES.\n DO 300 K=NP1,N1 \n I=S(K) \n S(K)=ZERO \n DO 290 J=1,N1 \n A(K,J)=A(I,J) \n 290 A(I,J)=ZERO \n A(I,K)=ONE \n 300 CONTINUE \nC END.. SPECIAL FOR ZERO ROWS AND COLUMNS \n RETURN\n END \n", "meta": {"hexsha": "e77dc93a6e90f039a9d8839f819f796d3eb72c36", "size": 75913, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/lawson_hanson1.f", "max_stars_repo_name": "jnnccc/Dakota-orb", "max_stars_repo_head_hexsha": "96488e723be9c67f0f85be8162b7af52c312b770", "max_stars_repo_licenses": ["MIT"], "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/lawson_hanson1.f", "max_issues_repo_name": "jnnccc/Dakota-orb", "max_issues_repo_head_hexsha": "96488e723be9c67f0f85be8162b7af52c312b770", "max_issues_repo_licenses": ["MIT"], "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/lawson_hanson1.f", "max_forks_repo_name": "jnnccc/Dakota-orb", "max_forks_repo_head_hexsha": "96488e723be9c67f0f85be8162b7af52c312b770", "max_forks_repo_licenses": ["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.5065481759, "max_line_length": 77, "alphanum_fraction": 0.4773754166, "num_tokens": 23838, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511543206819, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.66292808790868}} {"text": "!##############################################################################\n! PROGRAM market2\n!\n! ## The static GE model with variable labor supply\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!##############################################################################\ninclude \"prog03_03m.f90\"\n\nprogram market2\n\n use globals\n use toolbox\n\n implicit none\n real*8 :: x(3), L(2), K(2), Y(2), Ybar, w, r, p(2), U, ell\n logical :: check\n\n ! initial guess\n x(:) = 0.5d0\n\n ! find market equilibrium\n call fzero(x, markets, check)\n\n ! check whether fzero converged\n if(check)then\n write(*,'(a/)')'Error in fzero !!!'\n stop\n endif\n\n ! copy prices\n p(1) = 1d0\n p(2) = x(1)\n w = x(2)\n r = x(3)\n\n ! calculate other economic variables\n Ybar = w*Tbar+r*Kbar\n Y = alpha*Ybar/p\n ell = (1d0-alpha(1)-alpha(2))*Ybar/w\n L = beta*p*Y/w\n K = (1d0-beta)*p*Y/r\n U = Y(1)**alpha(1)*Y(2)**alpha(2)*ell**(1d0-alpha(1)-alpha(2))\n\n ! output\n write(*,'(/a)')'GOODS MARKET 1 :'\n write(*,'(4(a,f6.2,2x))')' X1 =',Y(1),' Y1 =',Y(1)\n write(*,'(2(a,f6.2,2x))')' q1 =',p(1),' p1 =',p(1)\n\n write(*,'(/a)')'GOODS MARKET 2 :'\n write(*,'(2(a,f6.2,2x))')' X2 =',Y(2),' Y2 =',Y(2)\n write(*,'(2(a,f6.2,2x))')' q2 =',p(2),' p2 =',p(2)\n\n write(*,'(/a)')'LABOR MARKET :'\n write(*,'(3(a,f6.2,2x))')' L1 =',L(1),' L2 =',L(2),' T-F=',Tbar-ell\n write(*,'(a,f6.2,2x)')' w =',w\n\n write(*,'(/a)')'CAPITAL MARKET :'\n write(*,'(4(a,f6.2,2x))')' K1 =',K(1),' K2 =',K(2),' K =',Kbar\n write(*,'(a,f6.2,2x)')' r =',r\n\n write(*,'(/a)')'UTILITY :'\n write(*,'(a,f6.2,2x)')' U =',U\n\nend program\n\n", "meta": {"hexsha": "0feab48c8f153d926e587d72d809c9884615017f", "size": 1913, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "complete/prog03/prog03_03/prog03_03.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/prog03/prog03_03/prog03_03.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/prog03/prog03_03/prog03_03.f90", "max_forks_repo_name": "aswinvk28/modflow_fortran", "max_forks_repo_head_hexsha": "0c8dd5da8fe08f0abcc6b677503e96cdcdb7ee1e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-04-07T12:27:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-07T12:27:47.000Z", "avg_line_length": 25.8513513514, "max_line_length": 79, "alphanum_fraction": 0.4568740199, "num_tokens": 743, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672595, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.662928077759331}} {"text": "!-----------------------------------------------------------------------\n program test\n implicit none\n include 'ceedf.h'\n\n integer ceed,err\n integer x,i,n\n real*8 a(10)\n real*8 norm,diff\n integer*8 aoffset\n character arg*32\n\n call getarg(1,arg)\n\n call ceedinit(trim(arg)//char(0),ceed,err)\n\n n=10\n\n call ceedvectorcreate(ceed,n,x,err)\n\n do i=1,10\n if (mod(i,2) == 0) then\n a(i)=i-1\n else\n a(i)=-(i-1)\n endif\n enddo\n aoffset=0\n call ceedvectorsetarray(x,ceed_mem_host,ceed_use_pointer,a,aoffset,err)\n\n call ceedvectornorm(x,ceed_norm_1,norm,err)\n diff = norm - 45.\n if (abs(diff)>1.0D-14) then\n! LCOV_EXCL_START\n write(*,*) 'Error L1 norm ',norm,' != 45.'\n! LCOV_EXCL_STOP\n endif\n\n call ceedvectornorm(x,ceed_norm_2,norm,err)\n diff = norm - sqrt(285.)\n if (abs(diff)>1.0D-6) then\n! LCOV_EXCL_START\n write(*,*) 'Error L2 norm ',norm,' != sqrt(285.)'\n! LCOV_EXCL_STOP\n endif\n\n call ceedvectornorm(x,ceed_norm_max,norm,err)\n diff = norm - 9.\n if (abs(diff)>1.0D-14) then\n! LCOV_EXCL_START\n write(*,*) 'Error Max norm ',norm,' != 9.'\n! LCOV_EXCL_STOP\n endif\n\n call ceedvectordestroy(x,err)\n call ceeddestroy(ceed,err)\n\n end\n!-----------------------------------------------------------------------\n", "meta": {"hexsha": "4b838cb45d4581a443f1d3f07247f0b0bf61615d", "size": 1412, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/t108-vector-f.f90", "max_stars_repo_name": "rscohn2/libCEED", "max_stars_repo_head_hexsha": "0983a37fb2a235bf55920dd2b1098e5586f89fb8", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tests/t108-vector-f.f90", "max_issues_repo_name": "rscohn2/libCEED", "max_issues_repo_head_hexsha": "0983a37fb2a235bf55920dd2b1098e5586f89fb8", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/t108-vector-f.f90", "max_forks_repo_name": "rscohn2/libCEED", "max_forks_repo_head_hexsha": "0983a37fb2a235bf55920dd2b1098e5586f89fb8", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-03-30T23:13:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-30T23:13:18.000Z", "avg_line_length": 23.5333333333, "max_line_length": 77, "alphanum_fraction": 0.5106232295, "num_tokens": 425, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511322604134, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6629280708211625}} {"text": " subroutine compute_mass(A,B,psi,ctfm,ctfmp,rho,b1,a1,mass,\n & mass2,tmr\n & ,maxtmr,bhmass,dx,Nx)\n implicit none\n real*8 pi\n parameter ( pi = 3.141592653589793D0 )\n integer i\n integer Nx\n real*8 ctfm(Nx)\n real*8 rho(Nx)\n real*8 ctfmp(Nx)\n real*8 b1(Nx)\n real*8 avg\n real*8 dx\n real*8 mass(Nx)\n real*8 mass2(Nx)\n real*8 dR\n real*8 a1(Nx)\n real*8 grr\n real*8 r,b1p,rp\n real*8 tmr(Nx)\n real*8 maxtmr\n real*8 A(Nx)\n real*8 B(Nx)\n real*8 psi(Nx)\n real*8 bhmass\n\n\n mass2(1) = 0.0D0\n do i=2, Nx-1, 1\n dR = ctfmp(i)*dx\n avg = 0.5*( ctfm(i)**2*rho(i) +\n & ctfm(i-1)**2*rho(i-1)\n & )\n mass2(i) = mass2(i-1) + 4*pi*avg*dR\n end do\n mass2(Nx) = mass2(Nx-1)\n\n mass(1) = 0.0D0\n tmr(1) = 0.0D0\n maxtmr = 0.0D0\n bhmass = 0.0D0\n do i=2, Nx-1, 1\n rp = b1(i)*ctfm(i)\n mass(i) = ctfm(i)*psi(i)**2*sqrt(B(i))/2.0D0 * (\n & 1.0D0 - B(i)/A(i)* ( \n & 1.0D0 + ctfm(i)*(B(i)-B(i-1))/dx/ctfmp(i)/(2.0D0*B(i))\n & + 2*ctfm(i) * (psi(i)-psi(i-1))/dx/ctfmp(i)/psi(i)\n & )**2\n & )\n\n tmr(i) = 2.0D0*mass(i)/rp\n if ( maxtmr .lt. tmr(i) ) then\n maxtmr = tmr(i)\n bhmass = mass(i)\n end if\n end do\n mass(Nx) = mass(Nx-1)\n tmr(Nx) = tmr(Nx-1)\n END\n", "meta": {"hexsha": "95466b72c1e90829e8c4427f7c953f5eab4dbc41", "size": 1527, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/human/compute_mass.f", "max_stars_repo_name": "rmanak/bssn_spher", "max_stars_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/human/compute_mass.f", "max_issues_repo_name": "rmanak/bssn_spher", "max_issues_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/human/compute_mass.f", "max_forks_repo_name": "rmanak/bssn_spher", "max_forks_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.0327868852, "max_line_length": 65, "alphanum_fraction": 0.4191224623, "num_tokens": 631, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802462567087, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6629068833516112}} {"text": "module mathieu\n use param\n\n public :: matfcn\n\n contains\n\n subroutine matfcn(lnum, ioprad, izxi, icq, isq, qc, r, iopang, narg, arg, &\n mc1c, mc1e, mc1dc, mc1de, mc23c, mc23e, mc23dc, mc23de, naccrc, &\n ms1c, ms1e, ms1dc, ms1de, ms23c, ms23e, ms23dc, ms23de, naccrs, &\n ce, ced, se, sed, nacca)\n!\n! version 1.09 April 2021\n!\n! Subroutine version of the fortran program matfcn originally developed\n! about 2005 by arnie lee van buren and jeffrey boisvert. Updated\n! several times since then. For more information see the GitHub\n! repository: GitHub.com/MathieuandSpheroidalWaveFunctions/Mathieu\n! Especially see the readme file, example input and output files and a\n! journal article describing the methods used in matfcn.\n!\n! purpose : To calculate the Mathieu radial functions and their\n! first derivatives for a range of lnum orders from l\n! = 0 to l = lnum - 1 and for a given value of q\n! [or c=sqrt(2*q)] and the radial coordinate r. The\n! radial coordinate can either be the traditional\n! coordinate z or the spheroidal-like radial\n! coordinate xi = cosh(z).\n! To calculate the Mathieu angular functions and\n! their first derivatives for orders l = 0 to l = lnum - 1\n! for a given value of q (or c) and for one or more\n! angular coordinate values.\n!\n! Matfcn can be run in either double precision or quadruple precision\n! arithmetic. The choice is set in the module param provided in the github\n! repository. If this is not available, then create param as follows:\n! module param\n! integer, parameter :: knd = selected_real_kind(8)\n! logical, parameter :: debug = .true.\n! logical, parameter :: warn = .true.\n! logical, parameter :: output = .true.\n! end module param\n! Set the value of knd in the parenthesis to either 8 for double\n! precision or 16 for quadruple precision arithmetic. Some compilers\n! require that param be compiled prior to mathieu. The logicals in param\n! are described in the readme file and below in the discussion of the\n! output files.\n!\n! Matfcn provides accurate results over extremely wide parameter ranges\n! when using double precision. It provides higher accuracy using quadruple\n! precision but run times are considerable greater.\n!\n! Input and output parameters appearing in the subroutine call\n! statement are defined below:\n!\n! lnum : number of integer values of l, given by\n! 0, 1, 2, ..., lnum-1, that radial and/or\n! angular functions are desired\n!\n! ioprad : (integer)\n! : =0 if radial functions are not desired\n! : =1 if radial functions of both kinds and\n! their first derivatives are computed.\n! When q is positive, this results in\n! radial functions of the first kind Mc1 and\n! Ms1 and of the second kind Mc2 and Ms2 and\n! their first derivatives. When q is negative,\n! the radial functions of the second kind are\n! replaced by those of the third kind Mc3\n! and Ms3 and their first derivatives.\n!\n! izxi : (integer)\n! : = 1 if the input radial coordinate is the\n! traditional radial coordinate z\n! : = 2 if the input radial coordinate is the\n! spheroidal-like radial coordinate = cosh(z)\n! (actually x1 = xi - 1 is imput to avoid\n! subtraction errors in the calculation of\n! xi*xi - 1 in matfcn when xi is near unity.\n! We avoid the subtraction error by using\n! instead x1*(x1 + 2). Note that When z is\n! input, the subtraction error is avoided in\n! computing x1 = xi - 1 by using the identity\n! x1=2*sinh(z/2)*sinh(z/2)\n!\n! icq : integer equal to 1 when q is input and equal to 2\n! when cm, the magnitude of c, is input\n! Note that c is pure imaginary when q is negative;\n! we choose the positive square root of q in the\n! definition of c.\n!\n! isq : integer equal to +1 when q is positive and\n! equal to -1 when q is negative\n!\n! qc : size parameter [real(knd)]\n! : = q when icq = 1\n! : = cm, magnitude of c, when icq = 2\n! This is equal to c when isq = +1 so that q\n! is positive. When isq = -1 so that q\n! is negative, then c is equal to i times the\n! input value\n!\n! r : radial coordinate [real(knd)]\n! : = z [real(knd)] when izxi = 1; this is the\n! traditional radial coordinate ranging from\n! zero to infinity.\n! : = xi - 1 [real(knd)] when izxi = 2; where xi is\n! the spheroidal-like radial coordinate equal to\n! cosh(z). A dummy value, e.g. 1.0d0, should be\n! entered for r if ioprad = 0\n!\n! iopang : (integer)\n! : = 0 if angular functions are not desired\n! : = 1 if angular functions of the first kind\n! are computed\n! : = 2 if angular functions of the first kind and\n! their first derivatives are computed\n!\n! narg : number of values of the angular coordinate phi for\n! which angular functions of the first kind are\n! calculated (integer). If no angular functions\n! are desired (iopang = 0), set narg equal to unity.\n!\n! arg: vector arg(narg) containing the values of phi in\n! degrees for which angular functions are desired\n! [real(knd)]\n!\n! mc1c : real(knd) vectors of length lnum containing the\n! mc1dc characteristics for the cosine radial functions\n! of the first kind Mc1 and their first derivatives\n! with respect to z.\n! When q is positive, the functions are real.\n! When q is negative and the order is odd, the\n! functions are imaginary. The real values given\n! in the vectors mc1 and mc1d must be multiplied\n! by i to obtain the characteristics for odd orders.\n!\n! mc1e : integer vectors of length lnum containing the\n! mc1de exponents corresponding to mc1c and mc1dc.\n!\n! mc23c : When q is positive, these are real(knd) vectors of\n! mc23dc length lnum containing the characteristics for the\n! cosine radial functions of the second kind Mc2 and\n! their first derivatives with respect to z.\n! When q is negative, these vectors instead contain\n! the characteristics for the cosine radial functions\n! of the third kind Mc3 and their first derivatives\n! with respect to z. Mc3 and its first derivative is\n! real when l is odd and imaginary when l is even.\n! In this case, the real values given in the vectors\n! mc23 and mc23d must be multiplied by i to obtain\n! the characteristics for even orders.\n!\n! mc23e : integer vectors of length lnum containing the\n! mc23de exponents corresponding to mc23 and mc23d\n!\n! naccrc : vector of lnum values for the estimated accuracy of the\n! cosine radial functions; obtained using the Wronskian\n!\n! ms1c : real(knd) vectors of length lnum containing the\n! ms1dc characteristics for the sine radial functions\n! of the first kind Ms1 and their first derivatives\n! with respect to z.\n! When q is positive, the functions are real.\n! When q is negative and the order is odd, the\n! functions are imaginary. The real values given in\n! the vectors ms1 and ms1d must be multiplied by i\n! to obtain the characteristics for odd orders.\n!\n! ms1e : integer vectors of length lnum containing the\n! ms1de exponents corresponding to ms1c and ms1de\n!\n! ms23c : When q is positive, these are real*8 vectors of\n! ms23dc length lnum containing the characteristics for the\n! sine radial functions of the second kind Ms2 and\n! their first derivatives with respect to z.\n! When q is negative, these vectors instead contain\n! the characteristics for the sine radial functions\n! of the third kind Ms3 and their first derivatives\n! with respect to z. Ms3 and its first derivative is\n! real when l is odd and imaginary when l is even.\n! In this case, the real values given in the vectors\n! ms23 and ms23d must be multiplied by i to obtain\n! the characteristics for even orders.\n!\n! ms23e : integer vectors of length lnum containing the\n! ms23de exponents corresponding to ms23 and ms23d\n!\n! naccrs : vector of lnum values for the estimated accuracy of the\n! sine radial functions; obtained using the Wronskian\n!\n! ce,ced : arrays ce(lnum,narg) and ced(lnum,narg) that\n! contain narg calculated angular cosine functions\n! and their first derivatives for each of the lnum\n! values of l [real(knd)]\n! For example, ce(10,1) is the angular function for\n! l = 9 and the first value of the angle phi given\n! by arg(1)\n!\n! se,sed : arrays se(lnum,narg) and sed(lnum,narg) that\n! contain narg calculated angular sine functions\n! and their first derivatives for each of the lnum\n! values of l [real(knd))\n! For example, se(10,1) is the angular function for\n! l = 9 and the first value of the angle phi given\n! by arg(1)\n!\n! nacca : array of lnum values of the estimated accuracy of the angular\n! functions for each of the narg angles; equal to the minimum\n! of the estimates for the sine and cosine angular functions\n! and their first derivatives; based on subtraction errors\n! in their calculation\n!\n! We use the term radial function for what is normally referred to as\n! a modified Mathieu function. First derivative values for the radial\n! functions are with respect to the traditional radial coordinate z.\n!\n! Matfcn offers several several output files: Fort.20 and fort.30\n! list the calculated radial and angular functions. Fort.40 and\n! fort.50 are diagnostic files. Fort.60 provides warning whenever the\n! estimated accuracy falls below a specified minimum, currently set\n! equal to 6. Writing to these files is controlled by logicals specified\n! in the module param. False suppresses the file; true enables it. Debug\n! controls fort.30 and fort.40, warn controls fort.60 and output\n! controls fort.20 and fort.30. Information about these files as well\n! as a discussion about accuracy, expansion A and B coefficients and\n! eigenvalues is given in the readme file.\n!\n integer, intent (in) :: lnum, ioprad, izxi, icq, isq, iopang, narg\n real(knd), intent (in) :: qc, r, arg(narg)\n integer, intent (out) :: mc1e(lnum), mc1de(lnum), mc23e(lnum), mc23de(lnum), &\n ms1e(lnum), ms1de(lnum), ms23e(lnum), ms23de(lnum), &\n naccrc(lnum), naccrs(lnum), nacca(lnum, narg)\n real(knd), intent (out) :: mc1c(lnum), mc1dc(lnum), mc23c(lnum), mc23dc(lnum), &\n ms1c(lnum), ms1dc(lnum), ms23c(lnum), ms23dc(lnum), &\n ce(lnum, narg), ced(lnum, narg), &\n se(lnum, narg), sed(lnum, narg)\n real(knd) q, cm, z, x1\n!\n! ndec: the maximum number of decimal digits available in real(knd)\n! arithmetic.\n! nex: the maximum exponent available in real(knd) arithmetic.\n!\n ndec = precision(cm)\n nex = range(cm) - 1\n!\n! Here is where the user sets kindd, the number of bytes available\n! in double precision data for the computer that coblfcn is run on.\n! Similarly kindq, the number of bytes available in quadruple\n! precision data, is set here. This allows coblfcn to be run on\n! computers with values for kindd and kindq different than 8 and 16,\n! respectively.\n!\n5 kindd = 8\n kindq = 16\n\n! set the minimum desired accuray minacc to 10 for real*8\n! arithmetic and to 15 for real*16 arithmetic. Minacc for\n! real*16 can be changed if desired. See comments above about\n! changing minacc\n!\n if(knd == kindd) minacc = 10\n if(knd == kindq) minacc = 15\n!\n! open output files\n if (output) then\n open(20, file='fort.20')\n open(30, file='fort.30')\n end if\n if (debug) then\n open(40, file='fort.40')\n open(50, file='fort.50')\n end if\n if (warn) then\n open(60, file='fort.60',access='append')\n end if\n!\n if(icq == 1) then\n q = qc\n cm = sqrt(2.0e0_knd * abs(q))\n end if\n if(icq == 2) then\n cm = qc\n q = cm * cm / 2.0e0_knd\n if(isq == -1) q = -q\n end if\n if(izxi == 1) then\n z = r\n x1 = 2.0e0_knd * (sinh(0.5e0_knd * z)) ** 2\n end if\n if(izxi == 2) then\n x1 = r\n z = 0.0e0_knd\n end if\n!\n! set array dimensions\n maxj = 1\n if(ioprad /= 0) maxj = 1.5 * lnum + 4 * ndec + int(cm) + 105\n!\n! for isq = -1, the maximum s value used for m1 occurs at the\n! last l that the Bessel product series is used, namely at the\n! break point l = lb = 2*cm/pi.\n!\n if(isq == 1) go to 10\n ismax = int(0.85e0_knd * cm)\n if(x1 < 1.0e0_knd) ismax = ismax * 1.5\n if(x1 < 0.1e0_knd .and. x1 >= 0.00001e0_knd) ismax = ismax* &\n int(3.0e0_knd ** (-1.0e0_knd - log10(x1)))\n if(x1 < 0.00001e0_knd) ismax = ismax * 81\n maxj = max(maxj, ismax + int(cm / 3.14159) + 4 * ndec + int(cm) + 105)\n10 maxp = 2 * lnum + 2 * cm + 4 * ndec + 105\n maxn = maxj\n maxk = 1\n maxkbp = 1\n if(ioprad == 0 .or. isq == 1 .or. x1 == 0.0e0_knd) go to 30\n maxkbp = lnum + 4 * ndec + int(cm) + 103\n if(minacc <= (ndec - 2) .and. cm <= 5.0e0_knd) go to 30\n if(minacc <= (ndec - 4) .and. cm <= 10.0e0_knd) go to 30\n if(minacc <= (ndec - 6) .and. cm <= 15.0e0_knd) go to 30\n if(minacc <= (ndec - 8) .and. cm <= 20.0e0_knd) go to 30\n maxk = 1.5 * cm + 100\n if(x1 < 1.0e0_knd .and. x1 >= 0.01e0_knd) maxk = 40 / x1 + cm / sqrt(x1)+ &\n 1.5 * cm + 200\n if(x1 < 0.01e0_knd .and. x1 > 0.0e0_knd) maxk = 34 / x1 + 1.5 * cm+ &\n 1.4 * cm / sqrt(x1) + 200\n20 maxterm = 10000000\n maxk = min(maxk, maxterm)\n maxk = max(maxk, maxj)\n30 maxd = max(maxj, maxn, maxk, maxkbp, maxp) / 2 + 1\n maxlp = lnum + 3\n if(isq == -1) maxlp = max(maxlp, ismax + int(cm / 3.14159) + 3)\n ngau = 200\n!\n call mathieuf(lnum, cm, q, icq, isq, ioprad, iopang, minacc, izxi, x1, z, &\n narg, arg, maxd, maxj, maxlp, maxn, maxp, maxkbp, maxk, &\n ndec, nex, ngau, kindd, kindq, &\n mc1c, mc1e, mc1dc, mc1de, mc23c, mc23e, mc23dc, mc23de, naccrc, &\n ms1c, ms1e, ms1dc, ms1de, ms23c, ms23e, ms23dc, ms23de, naccrs, &\n ce, ced, se, sed, nacca)\n end subroutine\n!\n\n subroutine mathieuf(lnum, cm, q, icq, isq, ioprad, iopang, minacc, izxi, x1, &\n z, narg, arg, maxd, maxj, maxlp, maxn, maxp, maxkbp, &\n maxk, ndec, nex, ngau, kindd, kindq, &\n amc1c, mc1e, amc1dc, mc1de, amc23c, mc23e, amc23dc, mc23de, narc, &\n ams1c, ms1e, ams1dc, ms1de, ams23c, ms23e, ams23dc, ms23de, &\n nars, ace, aced, ase, ased, naa)\n!\n! purpose: to coordinate the calculation of Mathieu functions,\n! including the radial and angular functions and their\n! first derivatives using various algorithms.\n!\n! input: lnum : desired number of values of l = m, m + 1, ...,\n! m + lnum - 1\n! cm : magnitude of c, the spheroidal-like size\n! parameter = sqrt(2*q)\n! q : traditional size parameter\n! icq : equal to 1 when q is input and equal to 2 when\n! cm, the magnitude of c, is input\n! isq : sign of q\n! ioprad : = 0 if radial functions are not desired\n! : = 1 if radial functions of both kinds and\n! their first derivatives are computed.\n! When q is positive, this results in\n! radial functions of the first and second\n! kind m1 and m2. When q is negative, it\n! results in radial functions of the first\n! and third kind m1 and m3.\n! iopang : equal to 0 if no angular functions are desired;\n! equal to 1 if only angular functions of the\n! first kind are desired;\n! equal to 2 if angular functions of the first\n! kind and their first derivatives are desired\n! minacc : desired minimum accuracy for the radial\n! functions\n! izxi : = 1 if the input radial coordinate is the\n! traditional radial coordinate z\n! : = 2 if the input radial coordinate is the\n! spheroidal-like radial coordinate xi = cosh(z)\n! x1 : radial coordinate xi - 1 = cosh(z) - 1\n! z : traditional radial coordinate\n! arg : vector of narg angle coordinates in degrees\n! for which angular functions are desired\n! narg : number of desired angle arguments.\n! maxd : dimension of the vectors enra and enrb that\n! contain ratios of the a and b expansion\n! coefficients\n! maxj : equal to the dimension of the array of ratios\n! of Bessel functions of the first kind and of\n! the array of ratios of the first derivatives of\n! these functions. The ratios are of consecutive\n! functions of the same parity. Maxj applies to\n! both the regular and the modified Bessel\n! functions.\n! maxlp : lnum+3\n! maxn : dimension of the array of ratios of Bessel\n! functions of the second kind and of the array\n! of ratios of the first derivatives of these\n! functions. The ratios are of consecutive\n! functions of the same parity.\n! maxp : number of sine and cosine function values\n! computed for each desired angle coordinate\n! maxk : dimension of the array of ratios of modified\n! Bessel functions of the third kind and of the\n! array of ratios of the first derivatives of\n! these functions. The ratios are of consecutive\n! functions of the same parity.\n! maxkbp : dimension of the array of ratios of modified\n! Bessel functions of the third kind and of the\n! array of ratios of the first derivatives of\n! these functions. The ratios are of consecutive\n! functions of the same parity.\n! ndec : number of decimal digits for real(knd)\n! nex : maximum exponent for real(knd)\n! ngau : order of the Gaussian quadrature to be used in\n! computing integrals in subroutine pint for use\n! in subroutine r2int where the integal method\n! is used to calculate r2 and r2d\n! kindd : kind value for double precision real data\n! kindq : kind value for quadruple precision real datac\n!\n! Output: amc1c : vector containing the lnum characteristics for\n! the cosine radial functions of the first kind\n! Mc1. The factor i is suppressed for all of the\n! radial and angular functions that are maginary.\n! mc1e : integer vector of exponents corresponding to\n! amc1c\n! amc1dc : vector containing the lnum characteristics for\n! the first derivatives with respect to z of the\n! cosine radial functions of the first kind\n! mc1de : integer vector of exponents corresponding to\n! amc1dc\n! amc23c : When q is positive, these are vectors of lnum\n! characteristics for the cosine radial functions\n! of the second kind Mc2.\n! When q is negative, these are vectors of lnum\n! characteristics for the cosine radial functions\n! of the third kind Mc3\n! mc23e : integer vector of exponents corresponding to\n! amc23c\n! amc23dc: When q is positive, this is a vector of lnum\n! characteristics for the first derivative with\n! respect to z of the cosine radial functions\n! of the second kind\n! When q is negative, this is a vector of lnum\n! characteristics for the first derivatives with\n! respect to z of the cosine radial functions\n! of the third kind\n! mc23de : integer vector of exponents corresponding to\n! amc23dc\n! narc : vector of lnum values for the estimated accuracy\n! of the cosine radial functions\n! ams1c : vector containing the lnum characteristics for\n! the sine radial functions of the first kind\n! Ms1\n! ms1e : integer vector of exponents corresponding to\n! ams1c\n! ams1dc : vector containing the lnum characteristics for\n! the first derivatives with respect to z of the\n! sine radial functions of the first kind\n! ms1de : integer vector of exponents corresponding to\n! ams1dc\n! ams23c : When q is positive, these are vectors of lnum\n! characteristics for the sine radial functions\n! of the second kind Ms2.\n! When q is negative, these are vectors of lnum\n! characteristics for the sine radial functions\n! of the third kind Ms3\n! ms23e : integer vector of exponents corresponding to\n! ams23c\n! ams23dc: When q is positive, this is a vector of lnum\n! characteristics for the first derivative with\n! respect to z of the sine radial functions\n! of the second kind\n! When q is negative, this is a vector of lnum\n! characteristics for the first derivatives with\n! respect to z of the sine radial functions\n! of the third kind\n! ms23de : integer vector of exponents corresponding to\n! ams23dc\n! nars : vector of lnum values for the estimated accuracy\n! of the sine radial functions\n! ace : array of lnum values of the cosine angular\n! functions for each of the narg angles\n! aced : array of lnum values of the first derivatives\n! of the cosine angular functions for each of\n! the narg angles\n! ase : array of lnum values of the sine angular\n! functions for each of the narg angles\n! ased : array of lnum values of the first derivatives\n! of the sine angular functions for each of\n! the narg angles\n! naa : array of lnum values of the estimated accuracy of the\n! angular functions for each of the narg angles\n!\n use param\n!\n! real(knd) scalars\n real(knd) api, a01, asubl, b12, bsubl, cm, cepio2, cedpio2, ce0, dec, &\n eigaval, eigbval, eigavalp, eigbvalp, eiga1, eiga2, eiga3, &\n eiga4, eiga5, eigb1, eigb2, eigb3, eigb4, eigb5, esa, esb, &\n gamma, m1botc, m1bots, mc1c, mc1dc, mc2c, mc2dc, mc3c, mc3dc, &\n ms1c, ms1dc, ms2c, ms2dc, ms3c, ms3dc, m3bot, pi, q, rl, sed0, &\n sepio2, sedpio2, sgna, sgnb, wroncc, wroncs, wront, xi, xb, &\n x1, z\n!\n! real(knd) vectors with dimension lnum\n real(knd) eiga(lnum), eigb(lnum)\n real(knd) amc1c(lnum), amc1dc(lnum), amc23c(lnum), amc23dc(lnum), &\n ams1c(lnum), ams1dc(lnum), ams23c(lnum), ams23dc(lnum)\n!\n! integer vectors with dimension lnum\n integer mc1e(lnum), mc1de(lnum), mc23e(lnum), mc23de(lnum), &\n ms1e(lnum), ms1de(lnum), ms23e(lnum), ms23de(lnum), &\n narc(lnum), nars(lnum)\n!\n! real(knd) arrays with dimensions lnum and narg\n real(knd) ace(lnum, narg), aced(lnum, narg), ase(lnum, narg), ased(lnum, narg)\n!\n! integer arrays with dimensions lnum and narg\n integer naa(lnum, narg)\n!\n! real(knd) vectors with dimension maxd\n real(knd) enra(maxd), blista(maxd), glista(maxd), enrb(maxd), &\n blistb(maxd), glistb(maxd)\n!\n! real(knd) vectors with dimension maxj\n real(knd) cbesf(maxj), cbesf1(maxj), cbesf2(maxj), cbesdf(maxj), &\n cbesdf1(maxj), cbesdf2(maxj), cbesdr(maxj), &\n cbesdr1(maxj), cbesdr2(maxj)\n!\n! integer and real(knd) vectors with dimension maxlp\n dimension ibese(maxlp), ibese1(maxlp), ibese2(maxlp), &\n ineue(maxlp), ineue2(maxlp), ineue3(maxlp)\n real(knd) cbesn(maxlp), cbesn1(maxlp), cbesn2(maxlp), cneun(maxlp), &\n cneun2(maxlp), cneun3(maxlp)\n!\n! real(knd) vectors with dimension maxn\n real(knd) cneudf2(maxn), cneuf2(maxn), cneudr2(maxn)\n!\n! real(knd) vectors with dimension maxk\n real(knd) cneudf(maxk), cneuf(maxk), cneudr(maxk)\n\n! real(knd) vectors with dimension maxkbp\n real(knd) cneudf3(maxkbp), cneuf3(maxkbp), cneudr3(maxkbp)\n!\n! real(knd) vectors with dimension given by maxp\n real(knd) cosi(narg, maxp), sine(narg, maxp)\n!\n! integer and real(knd) vectors with dimension narg\n dimension nacca(narg), naccc(narg), naccs(narg)\n real(knd) arg(narg), barg(narg), ce(narg), ced(narg), &\n se(narg), sed(narg)\n!\n! real(knd) vectors with dimension ngau\n real(knd) xr(ngau), wr(ngau)\n!\n dec = 10.0e0_knd ** (-ndec - 1)\n xi = x1 + 1.0e0_knd\n pi = acos(-1.0e0_knd)\n api = pi / 180.0e0_knd\n wront = 2.0e0_knd / pi\n gamma = 0.577215664901532860606512090082402431042e0_knd\n igauss = 0\n!\n! begin loops\n!\n if(iopang /= 0) then\n do jarg = 1, narg\n barg(jarg) = arg(jarg) * api\n end do\n limsc = 2 * (lnum + cm + 2 * ndec + 50)\n call sincos (limsc, maxp, narg, isq, barg, sine, cosi)\n end if\n if(izxi == 1) then\nif (output) then\n if(ioprad /= 0 .and. knd == kindd) write(20, 10) z\n if(ioprad /= 0 .and. knd == kindq) write(20, 15) z\nend if\nif (debug) then\n if(ioprad /= 0 .and. knd == kindd) write(40, 10) z\n if(ioprad /= 0 .and. knd == kindq) write(40, 15) z\nend if\n10 format(1x,' z = ',e23.14)\n15 format(1x,' z = ',e39.30)\n end if\n if(izxi == 2) then\nif (output) then\n if(ioprad /= 0 .and. knd == kindd) write(20, 20) xi\n if(ioprad /= 0 .and. knd == kindq) write(20, 25) xi\nend if\nif (debug) then\n if(ioprad /= 0 .and. knd == kindd) write(40, 20) xi\n if(ioprad /= 0 .and. knd == kindq) write(40, 25) xi\nend if\n end if\n20 format(1x,'xi = ',e23.14)\n25 format(1x,'xi = ',e39.30)\n if(icq == 1) then\nif (output) then\n if(ioprad /= 0 .and. knd == kindd) write(20, 30) q\n if(ioprad /= 0 .and. knd == kindq) write(20, 35) q\n if(iopang /= 0 .and. knd == kindd) write(30, 30) q\n if(iopang /= 0 .and. knd == kindq) write(30, 35) q\nend if\nif (debug) then\n if(ioprad /= 0 .and. knd == kindd) write(40, 30) q\n if(iopang /= 0 .and. knd == kindd) write(50, 30) q\n if(ioprad /= 0 .and. knd == kindq) write(40, 35) q\n if(iopang /= 0 .and. knd == kindq) write(50, 35) q\nend if\n30 format(1x,' q = ',e23.14)\n35 format(1x,' q = ',e39.30)\n end if\n if(icq == 2) then\nif (output) then\n if(ioprad /= 0 .and. isq == 1 .and. knd == kindd) write(20, 40) cm\n if(ioprad /= 0 .and. isq == -1 .and. knd == kindd) write(20, 50) cm\n if(ioprad /= 0 .and. isq == 1 .and. knd == kindq) write(20, 45) cm\n if(ioprad /= 0 .and. isq == -1 .and. knd == kindq) write(20, 55) cm\nend if\nif (debug) then\n if(ioprad /= 0 .and. isq == 1 .and. knd == kindd) write(40, 40) cm\n if(ioprad /= 0 .and. isq == -1 .and. knd == kindd) write(40, 50) cm\n if(ioprad /= 0 .and. isq == 1 .and. knd == kindq) write(40, 45) cm\n if(ioprad /= 0 .and. isq == -1 .and. knd == kindq) write(40, 55) cm\nend if\n40 format(1x,' c = ',e23.14)\n45 format(1x,' c = ',e39.30)\n50 format(1x,' c = i times',e23.14)\n55 format(1x,' c = i times',e39.30)\nif (output) then\n if(iopang /= 0 .and. isq == 1 .and. knd == kindd) write(30, 40) cm\n if(iopang /= 0 .and. isq == -1 .and. knd == kindd) write(30, 50) cm\n if(iopang /= 0 .and. isq == 1 .and. knd == kindq) write(30, 45) cm\n if(iopang /= 0 .and. isq == -1 .and. knd == kindq) write(30, 55) cm\nend if\nif (debug) then\n if(iopang /= 0 .and. isq == 1 .and. knd == kindd) write(50, 40) cm\n if(iopang /= 0 .and. isq == -1 .and. knd == kindd) write(50, 50) cm\n if(iopang /= 0 .and. isq == 1 .and. knd == kindq) write(50, 45) cm\n if(iopang /= 0 .and. isq == -1 .and. knd == kindq) write(50, 55) cm\nend if\n end if\n\n ibflag = 1\n iopbpe = 1\n iopneu = 0\n iopbp1 = 0\n iopbes = 1\n if(isq == 1) go to 60\n iopneu = 1\n if(minacc <= (ndec - 4) .and. cm <= 5.0e0_knd) iopneu = 0\n if(minacc <= (ndec - 6) .and. cm <= 10.0e0_knd) iopneu = 0\n if(minacc <= (ndec - 8) .and. cm <= 15.0e0_knd) iopneu = 0\n if(minacc <= (ndec - 10) .and. cm <= 20.0e0_knd) iopneu = 0\n if(iopneu == 0) go to 60\n iopbpe = 0\n iopbes = 0\n iopbp1 = 1\n60 if(x1 == 0.0e0_knd) iopneu = 0\n if(x1 == 0.0e0_knd) iopbpe = 1\n if(ioprad == 0) go to 70\n limj = lnum + 4 * ndec + int(cm) + 100\n xb = sqrt(x1 * (x1 + 2.0e0_knd))\n limbes = 2 * int(cm * xb) + 2 * ndec\n limjt = max(limbes, limj)\n numlp = lnum\n iopr = 2\n if(isq == 1 .and. x1 /= 0.0e0_knd) call cbesj(cm, xb, limj, maxj, &\n numlp, maxlp, limjt, ndec, limbes, &\n cbesf, cbesn, ibese, cbesdf, &\n cbesdr, iopr)\n if(isq == -1 .and. x1 /= 0.0e0_knd) call cbesi(cm, xb, limj, maxj, &\n numlp, maxlp, limjt, ndec, limbes, &\n cbesf, cbesn, ibese, cbesdf, &\n cbesdr, iopr, nex)\n xb = 0.5e0_knd / (xi + sqrt(x1 * (x1 + 2.0e0_knd)))\n limbes = 2 * int(cm * xb) + 2 * ndec\n limbpe = 1.5 * lnum + 4 * ndec + int(cm) + 100\n numlp = lnum + 1\n if(isq == 1) go to 65\n ismax = int(0.85e0_knd * cm)\n if(x1 < 1.0e0_knd) ismax = ismax * 1.5\n if(x1 < 0.1e0_knd .and. x1 >= 0.00001e0_knd) ismax = ismax* &\n int(3.0e0_knd ** (-1.0e0_knd - log10(x1)))\n if(x1 < 0.00001e0_knd) ismax = ismax * 81\n limbpe = max(limbpe, ismax + int(cm / pi) + 4 * ndec+ &\n int(cm) + 102)\n numlp = max(numlp, ismax + int(cm / pi) + 2)\n65 limjt = max(limbes, limbpe)\n iopr = 1\n if(isq == 1) call cbesj(cm, xb, limbpe, maxj, numlp, maxlp, limjt, &\n ndec, limbes, cbesf1, cbesn1, &\n ibese1, cbesdf1, cbesdr1, iopr)\n if(isq == -1) call cbesi(cm, xb, limbpe, maxj, numlp, maxlp, limjt, &\n ndec, limbes, cbesf1, cbesn1, &\n ibese1, cbesdf1, cbesdr1, iopr, nex)\n70 eiga1 = 0.0e0_knd\n eiga2 = 0.0e0_knd\n eiga3 = 0.0e0_knd\n eiga4 = 0.0e0_knd\n eiga5 = 0.0e0_knd\n eigb1 = 0.0e0_knd\n eigb2 = 0.0e0_knd\n eigb3 = 0.0e0_knd\n eigb4 = 0.0e0_knd\n eigb5 = 0.0e0_knd\n kflag = 0\n kflaga1 = 0\n kflagb1 = 0\n m1flag = 0\n jbesa = 0\n jbesb = 0\n jbesmax = 0\n jbp1a = 0\n jbp1b = 0\n jbp1 = 0\n jneua = 0\n jneub = 0\n jbpe = 0\n jbpemax = 0\n jneumax = 0\n iss1 = 0\n iss2 = 0\n iflag = 0\n eigval = 0.0q0\n jmfb = 0\n jsubb = 0\n jbpeb = 0\nif (debug) then\n if(ioprad /= 0 .and. isq == 1 .and. x1 == 0.0q0) write(40, 75)\n75 format(1x,/,5x,'Note that when x = 1.0, some of the radial', &\n ' functions of the second kind can be very small for', &\n /,5x,'l less than 2c / pi. These are correspondingly', &\n ' inaccurate. This should not reduce the accuracy', &\n /,5x,'of solutions to problems where the radial', &\n ' functions of the second kind appear in a pair with', &\n /,5x,'the radial functions of the first kind. The', &\n ' radial functions of the first kind are very', &\n /,5x,'accurate and dominate the radial functions', &\n ' of the second kind to the degree the radial', &\n /,5x,'functions of the second kind are inaccurate.', &\n ' Note that the Wronskian accuracy overestimates', &\n /,5x,'the accuracy of the smaller function values',/)\n if(ioprad /= 0 .and. isq == -1 .and. x1 == 0.0q0) write(40, 80)\n80 format(1x,/,5x,'When x = 1.0 and c is not small and l is', &\n ' less than about 2c / pi, accuracy of the radial', &\n /,5x,'functions of the third kind calculated using', &\n ' the Bessel product expansion is reduced due to', &\n /,5x,'subtraction errors. These errors are similar', &\n ' in size to those obtained in computing the angular', &\n /,5x,'functions ce(0) and sed(0). The associated', &\n ' radial functions of the first kind are computed', &\n /,5x,'accurately. When the Wronskian accuracy is less', &\n ' than the desired minimum accuracy, we use the', &\n /,5x,'Wronskian to compute an accurate value for the', &\n ' radial function of the third kind (for sine', &\n /,5x,'functions). We also do this for the first', &\n ' derivative of the radial function of the third kind', &\n /,5x,'(for cosine functions). When the Wronskian', &\n ' accuracy equals zero digits, the radial functions', &\n /,5x,'of the third kind (for cosine functions) and', &\n ' their first derivatives (for sine functions) are', &\n /,5x,'set equal to zero.',/)\nend if\n do 700 li = 1, lnum\n l = li - 1\nif (output) then\n if(iopang /= 0) write(30, 90) l\n90 format(1x,'l = ',i6)\nend if\n ix = l - 2 * (l / 2)\n rl = real(l, knd)\n istop = 0\n naccrs = 0\n naccrc = 0\n issd = max(iss1, iss2)\n limdrad = 4 * ndec + int(cm) + 100\n if(iopbes /= 0 .and. l > 1) limdrad = jbesmax + jbesmax + 20 + cm / 25\n if(iopbpe /= 0 .and. l > 1) limdrad = max(limdrad, jbpemax+ &\n jbpemax + 40 + int(cm / 25))\n if(iopbp1 /= 0 .and. l > 1) limdrad = max(limdrad, jbp1 + jbp1+ &\n 20 + int(cm / 25) + 2 * issd, 2 * l + 20 + int(cm / 25) + 2 * issd)\n limdang = 4 * ndec + 2 * int(cm) + 100\n if(iopang /= 0 .and. l > 1) limdang = jang + jang + 20 + cm / 25\n if(iopang == 0) limd = limdrad\n if(ioprad == 0) limd = limdang\n if(iopang /= 0 .and. ioprad /= 0) limd = max(limdang, limdrad)\n if(l == 0) limmf = limdang\n if(l > 0) limmf = jmf + jmf + 40 + cm / 25\n limd = max(limd, limmf)\n if(isq == 1 .or. ioprad == 0 .or. iopneu == 0) go to 100\n if(iopneu == 3 .and. l > 1) go to 95\n limdneu = 1.5 * cm + 100\n if(x1 < 1.0e0_knd .and. x1 >= 0.01e0_knd) limdneu = 40 / x1+ &\n cm / sqrt(x1) + 1.5 * cm + 200\n if(x1 < 0.01e0_knd .and. x1 > 0.0e0_knd) limdneu = 34 / x1+ &\n 1.5 * cm + 1.4 * cm / sqrt(x1) + 200\n95 continue\n if(iopneu == 3 .and. l > 1) limdneu = jneumax + jneumax + limndel+ &\n 100\n limdneu = min(limdneu, maxk)\n if(iopneu /= 0) limd = max(limd, limdneu)\n100 if(limd > 2 * maxd) limd = 2 * maxd - 5\n if(l == 0) ienra = (3 * ndec + int(cm)) / 2\n call geteiga(l, cm, eiga1, eiga2, eiga3, eiga4, eiga5, eigaval)\n call convera(l, cm, limd, eiga1, eiga3, eiga4, eiga5, ndec, maxd, &\n enra, ienra, sgna, a01, ia01, blista, glista, &\n eigaval)\n if(l == 1) ienrb = (3 * ndec + int(cm)) / 2\n if(l /= 0) call geteigb(l, cm, eigb1, eigb2, eigb3, eigb4, eigb5, &\n eigbval)\n if(l /= 0) call converb(l, cm, limd, eigb1, eigb3, eigb4, eigb5, &\n ndec, maxd, enrb, ienrb, sgnb, b12, ib12, &\n blistb, glistb, eigbval)\n esa = eigaval\n if(l /= 0) esb = eigbval\n if(isq == -1 .and. ix == 1) esa = eigbval\n if(isq == -1 .and. ix == 1) esb = eigaval\n eiga(l + 1) = esa\n if(l /= 0) eigb(l + 1) = esb\n if(l == 0) eigb(l + 1) = 0.0e0_knd\nif (debug) then\n if(knd == kindd) then\n if(ioprad /= 0 .and. l == 0) write(40, 110) l, esa\n110 format(1x,'l =',i5, 5x,'eigenvalue a =',e23.14)\n if(ioprad /= 0 .and. l /= 0) write(40, 120) l, esa, esb\n120 format(1x,'l =',i5, 5x,'eigenvalue a =',e23.14,/,14x, &\n 'eigenvalue b =',e23.14)\n if(iopang /= 0 .and. l /= 0) write(50, 120) l, esa, esb\n if(iopang /= 0 .and. l == 0) write(50, 110) l, esa\n end if\n if(knd == kindq) then\n if(ioprad /= 0 .and. l == 0) write(40, 115) l, esa\n115 format(1x,'l =',i5, 5x,'eigenvalue a =',e39.30)\n if(ioprad /= 0 .and. l /= 0) write(40, 125) l, esa, esb\n125 format(1x,'l =',i5, 5x,'eigenvalue a =',e39.30,/,14x, &\n 'eigenvalue b =',e39.30)\n if(iopang /= 0 .and. l /= 0) write(50, 125) l, esa, esb\n if(iopang /= 0 .and. l == 0) write(50, 115) l, esa\n end if\nend if\n if(ioprad == 0) go to 610\n call dnorma(l, limd, maxd, ndec, enra, ce0, &\n cepio2, cedpio2, jmfa, jsuba)\n if(l /= 0) call dnormb(l, limd, maxd, ndec, enrb, sed0, &\n sepio2, sedpio2, jmfb, jsubb)\n jmf = max(jmfa, jmfb)\n jsubmax = max(jsuba, jsubb)\n jtest = ndec - jsubmax\n if(jtest < 0) jtest = 0\n if(isq == 1 .or. kflag == 1) go to 140\n if(jtest < minacc .and. jsubmax > 1) go to 140\n kflag = 1\n iopbpe = 1\n iopbp1 = 0\n iopneu = 0\n iopbes = 1\n if(m1flag == 0) m1flag = 1\n140 if(l > 0 .and. eigaval <= eigavalp) go to 710\n if(l > 1 .and. eigbval <= eigbvalp) go to 710\n eigavalp = eigaval\n if(l /= 0) eigbvalp = eigbval\n if(ioprad == 0) go to 610\n!\n! determine Mathieu radial functions of the first kind\n!\n! calculation of m1 using a series of cylindrical Bessel functions\n! of the first kind with argument c*sqrt(xi*xi-1)\n if(iopbes == 0) go to 170\nif (debug) then\n if(x1 /= 0.0e0_knd) write(40, 150)\n150 format(1x,'m1 calculation using series of Bessel functions', &\n ' with argument cm*sqrt(xi*xi-1)')\n if(x1 == 0.0e0_knd) write(40, 155)\n155 format(1x,'m1 equal to nonzero term (if any) in series of', &\n ' Bessel functions with argument cm*sqrt(xi*xi-1)')\nend if\n if(iopbes == 1) limr1 = l + 4 * ndec + int(cm) + 100\n if(iopbes == 2) limr1 = jbesa + jbesa + 20 + cm / 25\n jbesa1 = jbesa\n iopcs = 1\n if(isq == 1 .and. ix == 0) m1botc = cepio2\n if(isq == 1 .and. ix == 1) m1botc = cedpio2\n if(isq == -1 .and. ix == 0) m1botc = ce0\n if(isq == -1 .and. ix == 1) m1botc = sed0\n call m1bes(iopcs, l, cm, x1, isq, limr1, ndec, maxd, enra, enrb, &\n maxj, maxlp, nex, cbesf, cbesn, ibese, cbesdf, cbesdr, &\n m1botc, a01, ia01, b12, ib12, jbesa, kflaga1, nsubc1, &\n mc1c, imc1e, mc1dc, imc1de)\n jbesa = max(jbesa1, jbesa)\n if(x1 == 0.0e0_knd) jbesa = jmfa\n if(l == 0) go to 160\n if(iopbes == 1 .or. l == 1) limr1 = l + 4 * ndec + int(cm) + 100\n if(iopbes == 2 .and. l /= 1) limr1 = jbesb + jbesb + 20 + cm / 25\n iopcs = 2\n jbesb1 = jbesb\n if(isq == 1 .and. ix == 0) m1bots = sedpio2\n if(isq == 1 .and. ix == 1) m1bots = sepio2\n if(isq == -1 .and. ix == 0) m1bots = sed0\n if(isq == -1 .and. ix == 1) m1bots = ce0\n call m1bes(iopcs, l, cm, x1, isq, limr1, ndec, maxd, enra, enrb, &\n maxj, maxlp, nex, cbesf, cbesn, ibese, cbesdf, cbesdr, &\n m1bots, a01, ia01, b12, ib12, jbesb, kflagb1, nsubs1, &\n ms1c, ims1e, ms1dc, ims1de)\n jbesb = max(jbesb1, jbesb)\n if(x1 == 0.0e0_knd) jbesb = jmfb\n160 iopbes = 2\n jbesmax = max(jbesa, jbesb)\n if(isq == 1) go to 200\n!\n! calculation of m1 using a series of products of cylindrical\n! Bessel functions of the first kind (q < 0, c imaginary)\n170 if(iopbp1 == 0) go to 200\nif (debug) then\n write(40, 180)\n180 format(1x,'m1 calculation using Bessel product expansion')\nend if\n if(l /= 0 .or. x1 == 0.0e0_knd) go to 190\n limbpe = lnum + 4 * ndec + int(cm) + 100\n numi = max(limbpe, ismax + int(cm / pi) + 4 * ndec + int(cm) + 102)\n numlp = ismax + int(cm / pi) + 2\n xb = 0.5e0_knd * (xi + sqrt(x1 * (x1 + 2.0e0_knd)))\n limbes = 2 * int(cm * xb) + 2 * ndec\n limjt = max(limbes, numi)\n iopr = 1\n call cbesi(cm, xb, numi, maxj, numlp, maxlp, limjt, ndec, limbes, &\n cbesf2, cbesn2, ibese2, cbesdf2, cbesdr2, iopr, nex)\n190 continue\n jbp1a1 = jbp1a\n iopcs = 1\n if(l == 0) limbp1a = 4 * ndec + int(cm) + 100\n if(l > 0) limbp1a = jbp1 + jbp1 + 20 + cm / 25\n if(x1 == 0.0e0_knd) call m1bpe0(iopcs, iss1, ismax, l, cm, &\n limbp1a, ndec, limd, maxd, enra, enrb, &\n maxj, maxlp, nex, cbesf1, cbesn1, &\n ibese1, cbesdf1, cbesdr1, a01, ia01, &\n b12, ib12, jbp1a, nsubc1, mc1c, imc1e, &\n mc1dc, imc1de)\n if(x1 /= 0.0e0_knd) call m1bpe(iopcs, iss1, ismax, l, cm, x1, &\n limbp1a, ndec, limd, maxd, enra, enrb, &\n maxj, maxlp, nex, cbesf1, cbesn1, &\n ibese1, cbesdf1, cbesdr1, cbesf2, &\n cbesn2, ibese2, cbesdf2, cbesdr2, a01, &\n ia01, b12, ib12, jbp1a, nsubc1, mc1c, &\n imc1e, mc1dc, imc1de)\n jbp1a = max(jbp1a1, jbp1a)\n if(l == 0) go to 200\n iopcs = 2\n jbp1b1 = jbp1b\n if(l == 1) limbp1a = 4 * ndec + int(cm) + 100\n if(l > 1) limbp1a = jbp1 + jbp1 + 20 + cm / 25\n if(x1 == 0.0e0_knd) call m1bpe0(iopcs, iss2, ismax, l, cm, &\n limbp1a, ndec, limd, maxd, enra, enrb, &\n maxj, maxlp, nex, cbesf1, cbesn1, &\n ibese1, cbesdf1, cbesdr1, a01, ia01, &\n b12, ib12, jbp1b, nsubs1, ms1c, ims1e, &\n ms1dc, ims1de)\n if(x1 /= 0.0e0_knd) call m1bpe(iopcs, iss2, ismax, l, cm, x1, &\n limbp1a, ndec, limd, maxd, enra, enrb, &\n maxj, maxlp, nex, cbesf1, cbesn1, &\n ibese1, cbesdf1, cbesdr1, cbesf2, &\n cbesn2, ibese2, cbesdf2, cbesdr2, a01, &\n ia01, b12, ib12, jbp1b, nsubs1, ms1c, &\n ims1e, ms1dc, ims1de)\n jbp1b = max(jbp1b1, jbp1b)\n200 jbp1 = max(jbp1a, jbp1b)\nif (debug) then\n if(knd == kindd) then\n if(isq == 1 .or. (isq == -1 .and. ix == 0)) &\n write(40, 210) mc1c, imc1e, mc1dc, imc1de\n210 format(10x,'mc1 = ', f17.14, i8, 5x,'mc1d = ',f17.14, i8)\n if((isq == 1 .or. (isq == -1 .and. ix == 0)) .and. l /= 0) &\n write(40, 220) ms1c, ims1e, ms1dc, ims1de\n220 format(10x,'ms1 = ', f17.14, i8, 5x,'ms1d = ',f17.14, i8)\n if(isq == -1 .and. ix == 1) &\n write(40, 230) mc1c, imc1e, mc1dc, imc1de\n230 format(10x,'mc1 = i times ',f17.14, i8, 5x, &\n 'mc1d = i times ',f17.14, i8)\n if(isq == -1 .and. ix == 1 .and. l /= 0) &\n write(40, 240) ms1c, ims1e, ms1dc, ims1de\n240 format(10x,'ms1 = i times ',f17.14, i8, 5x, &\n 'ms1d = i times ',f17.14, i8)\n end if\n if(knd == kindq) then\n if(isq == 1 .or. (isq == -1 .and. ix == 0)) &\n write(40, 215) mc1c, imc1e, mc1dc, imc1de\n215 format(10x,'mc1 = ', f33.30, i8, 5x,'mc1d = ',f33.30, i8)\n if((isq == 1 .or. (isq == -1 .and. ix == 0)) .and. l /= 0) &\n write(40, 225) ms1c, ims1e, ms1dc, ims1de\n225 format(10x,'ms1 = ', f33.30, i8, 5x,'ms1d = ',f33.30, i8)\n if(isq == -1 .and. ix == 1) &\n write(40, 235) mc1c, imc1e, mc1dc, imc1de\n235 format(10x,'mc1 = i times ',f33.30, i8, 5x, &\n 'mc1d = i times ',f33.30, i8)\n if(isq == -1 .and. ix == 1 .and. l /= 0) &\n write(40, 245) ms1c, ims1e, ms1dc, ims1de\n245 format(10x,'ms1 = i times ',f33.30, i8, 5x, &\n 'ms1d = i times ',f33.30, i8)\n end if\nend if\n continue\n!\n! determine Mathieu radial functions of the second kind (when q\n! is positive or Mathieu radial functions of the third kind when\n! q is negative)\n!\n! calculation of m2 (q positive) or m3 (q negative) using a series\n! of products of cylindrical Bessel functions of the first and second\n! kinds\n!\n if(iopbpe == 0) go to 400\nif (debug) then\n if(isq == 1) write(40, 250)\n250 format(1x,'m2 calculation using Bessel product series')\n if(isq == -1) write(40, 260)\n260 format(1x,'m3 calculation using Bessel product series')\nend if\n limbpe = lnum + 4 * ndec + int(cm) + 100\n if(iopbpe > 1) go to 280\n xb = 0.5e0_knd * (xi + sqrt(x1 * (x1 + 2.0e0_knd)))\n iopr = 1\n limbes = 2 * int(cm * xb) + 2 * ndec\n numlp = lnum\n if(igauss == 1 .or. isq /= -1) go to 270\n if((cm * xb <= 1.0e0_knd) .or. (cm * xb >= 40.0e0_knd)) go to 270\n call gauss (ngau, ndec, xr, wr)\n igauss = 1\n270 if(isq == 1) call cneuy (cm, xb, limbpe, maxn, numlp, maxlp, ndec, &\n limbes, pi, gamma, cneuf2, cneun2, &\n ineue2, cneudf2, cneudr2, iopr)\n if(isq == -1) call cneuk (cm, xb, limbpe, maxkbp, numlp, maxlp, &\n ndec, nex, limbes, pi, gamma, ngau, wr, &\n xr, iopr, cneuf3, cneun3, ineue3, &\n cneudf3, cneudr3)\n iopbpe = iopbpe + 1\n280 continue\n if(iopbpe == 2) limbpea = l + 4 * ndec + int(cm) + 100\n if(iopbpe == 3) limbpea = jbpea + jbpea + 40 + cm / 25\n if(limbpea > limbpe) limbpea = limbpe\n iopcs = 1\n if(isq == -1) go to 290\n call m2bpe (iopcs, iss1, l, cm, x1, limbpea, ndec, maxd, enra, enrb, &\n maxj, maxlp, maxn, nex, cbesf1, cbesn1, ibese1, &\n cbesdf1, cbesdr1, cneuf2, cneun2, ineue2, cneudf2, &\n cneudr2, a01, ia01, jbpea, nsubbpec, mc2c, imc2e, &\n mc2dc, imc2de)\n wroncc = (mc1c * mc2dc) * 10.0e0_knd ** (imc1e+imc2de)\n if(x1 /= 0.0e0_knd) wroncc = wroncc - (mc2c * mc1dc) * 10.0e0_knd ** (imc2e+imc1de)\n naccrc = -int(log10(abs((wroncc - 2.0e0_knd / pi) / (2.0e0_knd / pi)) + dec))\n if(naccrc < 0) naccrc = 0\n naccrc = min(naccrc, ndec - 1)\n go to 300\n290 call m3bpe (iopcs, l, cm, x1, limbpea, ndec, maxd, enra, enrb, &\n maxj, maxlp, maxkbp, nex, cbesf1, cbesn1, ibese1, &\n cbesdf1, cbesdr1, cneuf3, cneun3, ineue3, cneudf3, &\n cneudr3, a01, ia01, b12, ib12, pi, jbpea, nsubc3, &\n mc3c, imc3e, mc3dc, imc3de)\n wroncc = mc1c * mc3dc * 10.0e0_knd ** (imc1e+imc3de)\n if(x1 /= 0.0e0_knd) wroncc = wroncc- &\n mc3c * mc1dc * 10.0e0_knd ** (imc3e+imc1de)\n naccrc = -int(log10(abs((wroncc - (2.0e0_knd / pi))/ &\n (2.0e0_knd / pi)) + dec))\n if(naccrc < 0) naccrc = 0\n naccrc = min(naccrc, ndec - 1)\n if(x1 /= 0.0e0_knd) go to 300\n if(naccrc == 0) mc3c = 0\n if(naccrc == 0) imc3e = 0\n if(naccrc < minacc) mc3dc = (2.0e0_knd / pi) / mc1c\n iterm = int(log10(abs(mc3dc)))\n imc3de = -imc1e + iterm\n mc3dc = mc3dc * 10.0e0_knd ** (-iterm)\n if(abs(mc3dc) >= 1.0e0_knd) go to 300\n mc3dc = mc3dc * 10.0e0_knd\n imc3de = imc3de - 1\n300 if(l == 0) go to 320\n limbpeb = limbpea\n if(l > 1 .and. iopbpe == 3) limbpeb = jbpeb + jbpeb + 40 + cm / 25\n if(limbpeb > limbpe) limbpeb = limbpe\n iopcs = 2\n if(isq == -1) go to 310\n call m2bpe (iopcs, iss2, l, cm, x1, limbpeb, ndec, maxd, enra, enrb, &\n maxj, maxlp, maxn, nex, cbesf1, cbesn1, ibese1, &\n cbesdf1, cbesdr1, cneuf2, cneun2, ineue2, cneudf2, &\n cneudr2, b12, ib12, jbpeb, nsubbpes, ms2c, ims2e, &\n ms2dc, ims2de)\n wroncs = -ms2c * ms1dc * 10.0e0_knd ** (ims2e+ims1de)\n if(x1 /= 0.0e0_knd) wroncs = wroncs+ &\n ms1c * ms2dc * 10.0e0_knd ** (ims1e+ims2de)\n naccrs = -int(log10(abs((wroncs - (2.0e0_knd / pi))/ &\n (2.0e0_knd / pi)) + dec))\n if(naccrs < 0) naccrs = 0\n naccrs = min(naccrs, ndec - 1)\n go to 320\n310 call m3bpe (iopcs, l, cm, x1, limbpeb, ndec, maxd, enra, enrb, &\n maxj, maxlp, maxkbp, nex, cbesf1, cbesn1, ibese1, &\n cbesdf1, cbesdr1, cneuf3, cneun3, ineue3, cneudf3, &\n cneudr3, a01, ia01, b12, ib12, pi, jbpeb, nsubs4, &\n ms3c, ims3e, ms3dc, ims3de)\n wroncs = -ms3c * ms1dc * 10.0e0_knd ** (ims3e+ims1de)\n if(x1 /= 0.0e0_knd) wroncs = wroncs+ &\n ms1c * ms3dc * 10.0e0_knd ** (ims1e+ims3de)\n naccrs = -int(log10(abs((wroncs - (2.0e0_knd / pi))/ &\n (2.0e0_knd / pi)) + dec))\n if(naccrs < 0) naccrs = 0\n naccrs = min(naccrs, ndec - 1)\n if(x1 /= 0.0e0_knd) go to 320\n if(naccrs == 0) ms3dc = 0.0e0_knd\n if(naccrs == 0) ims3de = 0\n if(naccrs < minacc) ms3c = -(2.0e0_knd / pi) / ms1dc\n iterm = int(log10(abs(ms3c)))\n ims3e = -ims1de + iterm\n ms3c = ms3c * 10.0e0_knd ** (-iterm)\n if(abs(ms3c) >= 1.0e0_knd) go to 320\n ms3c = ms3c * 10.0e0_knd\n ims3e = ims3e - 1\n320 if(l == 0) jbpeb = 0\n jbpemax = max(jbpea, jbpeb)\n iopbpe = 3\n if(isq == -1) go to 350\n if(knd == kindd) then\nif (debug) then\n write(40, 330) naccrc, mc2c, imc2e, mc2dc, imc2de\n330 format(15x,'Wronskian accuracy =',i3, &\n ' decimal digits.'/,10x,'mc2 = ', f17.14, i6, &\n 5x,'mc2d = ',f17.14, i6)\n if(l > 0) write(40, 340) naccrs, ms2c, ims2e, ms2dc, ims2de\n340 format(15x,'Wronskian accuracy =',i3, &\n ' decimal digits.'/,10x,'ms2 = ', f17.14, i6, &\n 5x,'ms2d = ',f17.14, i6)\nend if\n go to 400\n end if\n if(knd == kindq) then\nif (debug) then\n write(40, 335) naccrc, mc2c, imc2e, mc2dc, imc2de\n335 format(15x,'Wronskian accuracy =',i3, &\n ' decimal digits.'/,10x,'mc2 = ', f33.30, i6, &\n 5x,'mc2d = ',f33.30, i6)\n if(l > 0) write(40, 345) naccrs, ms2c, ims2e, ms2dc, ims2de\n345 format(15x,'Wronskian accuracy =',i3, &\n ' decimal digits.'/,10x,'ms2 = ', f33.30, i6, &\n 5x,'ms2d = ',f33.30, i6)\nend if\n go to 400\n end if\n350 continue\nif (debug) then\n if(knd == kindd) then\n if(ix == 1) write(40, 360) naccrc, mc3c, imc3e, mc3dc, imc3de\n360 format(15x,'Wronskian accuracy =',i3, &\n ' decimal digits.'/,10x,'mc3 = ', f17.14, i8, &\n 5x,'mc3d = ',f17.14, i8)\n if(ix == 1 .and. l > 0) write(40, 370) naccrs, ms3c, ims3e, &\n ms3dc, ims3de\n370 format(15x,'Wronskian accuracy =',i3, &\n ' decimal digits.'/,10x,'ms3 = ', f17.14, i8, &\n 5x,'ms3d = ',f17.14, i8)\n if(ix == 0) write(40, 380) naccrc, mc3c, imc3e, mc3dc, imc3de\n380 format(15x,'Wronskian accuracy =',i3, &\n ' decimal digits.'/,10x,'mc3 = i times ',f17.14, i8, &\n 5x,'mc3d = i times ',f17.14, i8)\n if(l > 0 .and. ix == 0) write(40, 390) naccrs, ms3c, ims3e, &\n ms3dc, ims3de\n390 format(15x,'Wronskian accuracy =',i3, &\n ' decimal digits.'/,10x,'ms3 = i times ',f17.14, i8, &\n 5x,'ms3d = i times ',f17.14, i8)\n end if\n if(knd == kindq) then\n if(ix == 1) write(40, 365) naccrc, mc3c, imc3e, mc3dc, imc3de\n365 format(15x,'Wronskian accuracy =',i3, &\n ' decimal digits.'/,10x,'mc3 = ', f33.30, i8, &\n 5x,'mc3d = ',f33.30, i8)\n if(ix == 1 .and. l > 0) write(40, 375) naccrs, ms3c, ims3e, &\n ms3dc, ims3de\n375 format(15x,'Wronskian accuracy =',i3, &\n ' decimal digits.'/,10x,'ms3 = ', f33.30, i8, &\n 5x,'ms3d = ',f33.30, i8)\n if(ix == 0) write(40, 385) naccrc, mc3c, imc3e, mc3dc, imc3de\n385 format(15x,'Wronskian accuracy =',i3, &\n ' decimal digits.'/,10x,'mc3 = i times ',f33.30, i8, &\n 5x,'mc3d = i times',f33.30, i8)\n if(l > 0 .and. ix == 0) write(40, 395) naccrs, ms3c, ims3e, &\n ms3dc, ims3de\n395 format(15x,'Wronskian accuracy =',i3, &\n ' decimal digits.'/,10x,'ms3 = i times ',f33.30, i8, &\n 5x,'ms3d = i times',f33.30, i8)\n end if\nend if\n400 continue\n if(isq == 1) go to 510\n!\n! calculation of m3 (q negative) using the conventional Neumann\n! expansion in a series of modified cylindrical Bessel functions\n! of the second kind with argument cm*xi\n!\n if(iopneu == 0) go to 510\n if(ibflag == 0) go to 420\n limn = 1.5 * cm + 100\n if(x1 < 1.0e0_knd .and. x1 >= 0.01e0_knd) limn = 40 / x1 + cm/ &\n sqrt(x1) + 1.5 * cm + 200\n if(x1 < 0.01e0_knd .and. x1 > 0.0e0_knd) limn = 34 / x1 + 1.5 * cm+ &\n 1.4 * cm / sqrt(x1) + 200\n limn = min(limn, maxk - 3)\n limndel = 2 * limn / cm\n xb = xi\n limbes = 2 * int(cm * xb) + 2 * ndec\n iopr = 2\n numlp = min(lnum, int(2.0e0_knd * cm / pi) + 10)\n if(igauss == 1) go to 410\n if((cm * xb <= 1.0e0_knd) .or. (cm * xb >= 40.0e0_knd)) go to 410\n call gauss (ngau, ndec, xr, wr)\n igauss = 1\n410 call cneuk(cm, xb, limn, maxk, numlp, maxlp, ndec, nex, limbes, pi, &\n gamma, ngau, wr, xr, iopr, cneuf, cneun, ineue, cneudf, &\n cneudr)\n ibflag = 0\n420 if(iopneu == 1) iopneu = 2\n if(iopneu == 4) go to 510\n if(iopneu == 3 .and. l > 1) go to 430\n limneua = 1.5 * cm + 100\n if(x1 < 1.0e0_knd .and. x1 >= 0.01e0_knd) limneua = 40 / x1 + cm/ &\n sqrt(x1) + 1.5 * cm + 200\n if(x1 < 0.01e0_knd .and. x1 > 0.0e0_knd) limneua = 34 / x1+ &\n 1.5 * cm + 1.4 * cm / sqrt(x1) + 200\n430 continue\n if(iopneu == 3 .and. l > 1) limneua = jneumax + jneumax + limndel+ &\n 100\n limneua = min(limneua, limn - 2)\n iopcs = 1\n if(ix == 0) m3bot = cepio2\n if(ix == 1) m3bot = sepio2\nif (debug) then\n write(40, 440)\n440 format(1x,'m3 calculation using Bessel function series')\nend if\n call m3neu (iopcs, l, cm, x1, limneua, ndec, minacc, maxd, &\n enra, enrb, maxk, maxlp, nex, cneuf, cneun, ineue, &\n cneudf, cneudr, m3bot, pi, jneua, ndig, mc3c, imc3e, &\n mc3dc, imc3de, jtermflag)\n wroncc = mc1c * mc3dc * 10.0e0_knd ** (imc1e+imc3de)- &\n mc3c * mc1dc * 10.0e0_knd ** (imc3e+imc1de)\n naccrc = -int(log10(abs((wroncc - (2.0e0_knd / pi))/ &\n (2.0e0_knd / pi)) + dec))\n if(naccrc < 0) naccrc = 0\n naccrc = min(naccrc, ndec - 1)\n if(l == 0) go to 450\n if(jtermflag == 1) jneua = jneua + 2 * limndel\n limneub = limneua\n if(jtermflag == 1) limneub = limneub + 2 * limndel\n if(l > 1 .and. iopneu == 3) limneub = jneumax + jneumax + limndel+ &\n 100\n limneub = min(limneub, limn - 2)\n iopcs = 2\n if(ix == 0) m3bot = sedpio2\n if(ix == 1) m3bot = cedpio2\n if(l > 0) call m3neu (iopcs, l, cm, x1, limneub, ndec, &\n minacc, maxd, enra, enrb, maxk, maxlp, &\n nex, cneuf, cneun, ineue, cneudf, &\n cneudr, m3bot, pi, jneub, ndig, ms3c, &\n ims3e, ms3dc, ims3de, jtermflag)\n wroncs = ms1c * ms3dc * 10.0e0_knd ** (ims1e+ims3de) - ms3c * ms1dc* &\n 10.0e0_knd ** (ims3e+ims1de)\n naccrs = -int(log10(abs((wroncs - (2.0e0_knd / pi))/ &\n (2.0e0_knd / pi)) + dec))\n if(naccrs < 0) naccrs = 0\n naccrs = min(naccrs, ndec - 1)\n if(jtermflag == 1) jneub = jneub + 2 * limndel\n450 jneumax = max(jneua, jneub, jneumax, limn - 2)\n iopneu = 3\nif (debug) then\n write(40, 460) naccrc\n460 format(15x,'Wronskian accuracy =',i3,' decimal digits.')\n if(knd == kindd) then\n if(ix == 0) write(40, 470) mc3c, imc3e, mc3dc, imc3de\n470 format(10x,'mc3 = i times ',f17.14, i8, &\n 5x,'mc3d = i times ',f17.14, i8)\n if(ix == 1) write(40, 480) mc3c, imc3e, mc3dc, imc3de\n480 format(10x,'mc3 = ', f17.14, i8, 5x,'mc3d = ',f17.14, i8)\n if(l > 0) write(40, 460) naccrs\n if(ix == 0 .and. l > 0) write(40, 490) ms3c, ims3e, ms3dc, &\n ims3de\n490 format(10x,'ms3 = i times ',f17.14, i8, &\n 5x,'ms3d = i times ',f17.14, i8)\n if(ix == 1 .and. l > 0) write(40, 500) ms3c, ims3e, ms3dc, &\n ims3de\n500 format(10x,'ms3 = ', f17.14, i8, 5x,'ms3d = ',f17.14, i8)\n end if\n if(knd == kindq) then\n if(ix == 0) write(40, 475) mc3c, imc3e, mc3dc, imc3de\n475 format(10x,'mc3 = i times ',f33.30, i8, &\n 5x,'mc3d = i times ',f33.30, i8)\n if(ix == 1) write(40, 485) mc3c, imc3e, mc3dc, imc3de\n485 format(10x,'mc3 = ', f33.30, i8, 5x,'mc3d = ',f33.30, i8)\n if(l > 0) write(40, 460) naccrs\n if(ix == 0 .and. l > 0) write(40, 495) ms3c, ims3e, ms3dc, &\n ims3de\n495 format(10x,'ms3 = i times ',f33.30, i8, &\n 5x,'ms3d = i times ',f33.30, i8)\n if(ix == 1 .and. l > 0) write(40, 505) ms3c, ims3e, ms3dc, &\n ims3de\n505 format(10x,'ms3 = ', f33.30, i8, 5x,'ms3d = ',f33.30, i8)\n end if\nend if\n510 if(iopneu == 4) iopneu = 1\n if(isq == -1) go to 540\nif (output) then\n write(20, 520) l, mc1c, imc1e, mc1dc, imc1de, mc2c, imc2e, mc2dc, &\n imc2de, naccrc\n520 format(1x, i5, 2x, 4(f17.14, i6, 2x), i2)\n if(l > 0) write(20, 530) ms1c, ims1e, ms1dc, ims1de, ms2c, &\n ims2e, ms2dc, ims2de, naccrs\n530 format(8x, 4(f17.14, i6, 2x), i2)\nend if\n go to 600\n540 continue\nif (output) then\n write(20, 550) l, mc1c, imc1e, mc1dc, imc1de, mc3c, imc3e, mc3dc, &\n imc3de, naccrc\n550 format(1x, i5, 2x, 4(f17.14, i7, 2x), i2)\n if(l > 0) write(20, 560) ms1c, ims1e, ms1dc, ims1de, ms3c, &\n ims3e, ms3dc, ims3de, naccrs\n560 format(8x, 4(f17.14, i7, 2x), i2)\nend if\n600 continue\nif (warn) then\n if(ioprad == 1 .and. naccrc < 6) then\n write(60,*) ' est. acc. = ',naccrc, ' digits for xi = ', &\n xi,' cm, q = ',cm, q,' l = ',l\n end if\n if(ioprad == 1 .and. l /= 0 .and. naccrs < 6) then\n write(60,*) ' est. acc. = ',naccrs, ' digits for xi = ', &\n xi,' cm, q = ',cm, q,' l = ',l\n end if\nend if\n amc1c(li) = mc1c\n amc1dc(li) = mc1dc\n mc1e(li) = imc1e\n mc1de(li) = imc1de\n narc(li) = naccrc\n if(isq == 1) then\n amc23c(li) = mc2c\n amc23dc(li) = mc2dc\n mc23e(li) = imc2e\n mc23de(li) = imc2de\n else\n amc23c(li) = mc3c\n amc23dc(li) = mc3dc\n mc23e(li) = imc3e\n mc23de(li) = imc3de\n end if\n if(l == 0) nars(1) = ndec\n if(l /= 0) then\n ams1c(li) = ms1c\n ams1dc(li) = ms1dc\n ms1e(li) = ims1e\n ms1de(li) = ims1de\n nars(li) = naccrs\n if(isq == 1) then\n ams23c(li) = ms2c\n ams23dc(li) = ms2dc\n ms23e(li) = ims2e\n ms23de(li) = ims2de\n else\n ams23c(li) = ms3c\n ams23dc(li) = ms3dc\n ms23e(li) = ims3e\n ms23de(li) = ims3de\n end if\n end if\n610 if(iopang == 0) go to 700\n!\n! determine Mathieu angular functions of the first kind\n!\n lims1 = 4 + ndec + 2 * int(cm) + 100\n if(l /= 0) lims1 = jang + jang + 20 + cm / 25\n if(lims1 > maxp) lims1 = maxp\n call cese(cm, isq, l, lims1, ndec, iopang, maxd, maxp, enra, enrb, &\n sgna, sgnb, narg, cosi, sine, ce, ced, se, sed, naccc, &\n naccs, jangc, jangs, asubl, bsubl)\n jang = max(jangc, jangs)\n do 680 jarg = 1, narg\n nacca(jarg) = min(naccc(jarg), naccs(jarg))\nif (output) then\n if(iopang == 1) write(30, 620) arg(jarg), &\n ce(jarg), se(jarg), nacca(jarg)\n if(iopang == 2) write(30, 630) arg(jarg), &\n ce(jarg), ced(jarg), se(jarg), &\n sed(jarg), nacca(jarg)\nend if\n if(iopang == 1) then\n ace(li, jarg) = ce(jarg)\n ase(li, jarg) = se(jarg)\n end if\n if(iopang == 2) then\n ace(li, jarg) = ce(jarg)\n aced(li, jarg) = ced(jarg)\n ase(li, jarg) = se(jarg)\n ased(li, jarg) = sed(jarg)\n end if\n naa(li, jarg) = nacca(jarg)\n620 format(1x, f20.14, 5x, e23.14, 2x, e23.14, 2x, i2)\n630 format(1x, f20.14, 5x, e23.14, 2x, e23.14, 2x,/,26x, &\n e23.14, 2x, e23.14, 2x, i2)\n\nif (debug) then\n if(knd == kindd) then\n if(iopang == 1) write(50, 640) arg(jarg), ce(jarg), se(jarg)\n if(iopang == 2) write(50, 650) arg(jarg), ce(jarg), ced(jarg), se(jarg), sed(jarg)\n640 format(5x, f20.14,' degrees',/,10x,'ce = ', &\n e23.14, 2x,' se = ',e23.14)\n650 format(5x, f20.14,' degrees',/,10x,'ce = ',e23.14, 2x, &\n ' ced = ',e23.14,/,10x,'se = ',e23.14, 2x, &\n ' sed = ',e23.14)\n end if\n if(knd == kindq) then\n if(iopang == 1) write(50, 660) arg(jarg), ce(jarg), se(jarg)\n if(iopang == 2) write(50, 670) arg(jarg), ce(jarg), ced(jarg), se(jarg), sed(jarg)\n660 format(5x, f20.14,' degrees',/,10x,'ce = ', &\n e39.30, 2x,' se = ',e39.30)\n670 format(5x, f20.14,' degrees',/,10x,'ce = ',e39.30, 2x, &\n ' ced = ',e39.30,/,10x,'se = ',e39.30, 2x, &\n ' sed = ',e39.30)\n end if\nend if\n680 continue\n700 continue\n710 continue\n return\n end subroutine\n!\n!\n subroutine cese (cm, isq, l, lims1, ndec, iopang, maxd, maxp, enra, &\n enrb, sgna, sgnb, narg, cosi, sine, ce, ced, se, sed, &\n naccc, naccs, jangc, jangs, asubl, bsubl)\n!\n! purpose: to calculate the Mathieu angular functions\n! ce and se and their first derivatives with respect to phi\n!\n! parameters :\n!\n! input : cm : magnitude of c\n! isq : integer = +1 if q is positive (c is real);\n! = -1 if q is negative (c is imaginary)\n! l : l\n! lims1 : twice the number of terms available\n! ndec : number of decimal digits available in\n! real(knd) arithmetic\n! iopang : integer = 1 if no derivatives of the angular\n! functions are desired, = 2 otherwise\n! maxd : size of enr vector\n! maxp : number of sine and cosine values available\n! for each desired angle\n! enra : a coefficient ratios\n! enrb : b coefficient ratios\n! sgna : sign of the a coefficient with index = l\n! sgnb : sign of the b coefficient with index = l\n! narg : number of angles desired\n! cosi : array containing maxp cosine values\n! for each of the narg angles\n! sine : array containing maxp sine values\n! for each of the narg angles\n!\n! output : ce : vector of dimension narg containing values\n! of the cosine angular functions for each of\n! the desired angles\n! ced : corresponding vector for first derivatives\n! of the cosine angular functions\n! se : vector of dimension narg containing values\n! of the sine angular functions for each of\n! the desired angles\n! sed : corresponding vector for first derivatives\n! of the sine angular functions\n! naccc : vector of dimension narg containing estimates\n! of the minimum accuracy in decimal digits of\n! the ce and ced function values for each angle\n! naccs : vector of dimension narg containing estimates\n! of the minimum accuracy in decimal digits of\n! the se and sed function values for each angle\n! jangc : largest number of terms taken for ce\n! jangs : largest number of terms taken for se\n! asubl : a coefficient with subscript l\n! bsubl : b coefficient with subscript l\n!\n use param\n!\n! real(knd) scalars and vectors\n real(knd) adec, asubl, asubls, bsubl, cm, coef, csum, cdsum, dcon, dec, &\n dnew, dnewd, dnuma, dnumb, dold, doldd, dterm, fterm, sgna, &\n sgnb, ssum, sdsum, suma, temp, tempd\n real(knd) ce(narg), ced(narg), cosi(narg, maxp), enra(maxd), &\n enrb(maxd), se(narg), sed(narg), sine(narg, maxp)\n! integer vectors\n dimension naccc(narg), naccs(narg)\n!\n dec = 10.0e0_knd ** (-ndec - 1)\n dcon = dec\n adec = 1000.0e0_knd * dec\n csq = cm * cm\n l2 = l / 2\n lx2 = l2 - 2 * (l2 / 2)\n ix = l - 2 * l2\n ixx = ix - 1\n ixx2 = ixx + 2\n lim = lims1 / 2 - ix\n!\n! compute dnuma, the magnitude of the a coeficient with index = l\n suma = 1.0e0_knd\n if(l == 0) suma = 2.0e0_knd\n coef = 1.0e0_knd\n jlow = l + 2\n jterm = l2\n do 110 j = jlow, lims1, 2\n jterm = jterm + 1\n coef = coef * enra(jterm) * enra(jterm)\n suma = suma + coef\n if(abs(coef / suma) < dcon) go to 120\n110 continue\n120 jlow = l\n jn = jterm\n if(jlow < 2) go to 140\n coef = 1.0e0_knd\n jterm = l2\n j = jlow\n do 130 jj = 2, jlow, 2\n coef = coef / (enra(jterm) * enra(jterm))\n jterm = jterm - 1\n j = j - 2\n suma = suma + coef\n if(abs(coef / suma) < dcon) go to 140\n130 continue\n if(ix == 0) suma = suma + coef\n140 dnuma = 1.0e0_knd / sqrt(suma)\n asubl = dnuma * sgna\nif (debug) then\n if(isq == 1 .or. ix == 0) write(50, 145) jn, lim\n if(isq == -1 .and. ix == 1) write(50, 345) jn, lim\n145 format(5x,'ce normalization series converged in ', &\n i6,' terms; ',i6,' terms available')\nend if\n jlow = l2 + 1\n jangc = 0\n do 290 k = 1, narg\n!\n! compute the angular function ce\n if(abs(cosi(k, 3 - ix)) > adec) go to 150\n ce(k) = 0.0e0_knd\n naccc(k) = ndec\n jfun = 1\nif (debug) then\n if(iopang == 1 .and. (isq == 1 .or. ix == 0)) write(50, 175) k, jfun\n if(iopang == 1 .and. isq == -1 .and. ix == 1) write(50, 375) k, jfun\nend if\n go to 210\n150 dold = 1.0e0_knd\n fterm = 0.0e0_knd\n csum = cosi(k, l + 1)\n if(csum > 0.0e0_knd) fterm = csum\n do 160 j = jlow, lim\n dnew = dold * enra(j)\n dterm = dnew * cosi(k, j + j + ixx2)\n csum = csum + dterm\n if(dterm > 0.0e0_knd) fterm = fterm + dterm\n if((abs(dterm / csum) < dcon) .and. (abs(cosi(k, j + j + ixx2)) &\n > 1.0e-01_knd)) go to 170\n dold = dnew\n160 continue\n170 if(j > jangc) jangc = j\n jfun = j\nif (debug) then\n if(iopang == 1 .and. (isq == 1 .or. ix == 0)) write(50, 175) k, jfun\n if(iopang == 1 .and. isq == -1 .and. ix == 1) write(50, 375) k, jfun\n175 format(8x,'angle ',i3,'. ce converged in ',i6,' terms')\nend if\n if(l2 < 1) go to 190\n dold = 1.0e0_knd\n j = l2\n do 180 jj = 1, l2\n dnew = dold / enra(j)\n dterm = dnew * cosi(k, j + j + ixx)\n csum = csum + dterm\n if(dterm > 0.0e0_knd) fterm = fterm + dterm\n if(csum == 0.0e0_knd) go to 180\n if((abs(dterm / csum) < dcon) .and. (abs(cosi(k, j + j + ixx)) &\n > 1.0e-01_knd)) go to 190\n dold = dnew\n j = j - 1\n180 continue\n190 ce(k) = csum * dnuma * sgna\n200 if((csum == 0.0e0_knd) .and. fterm /= 0.0e0_knd) naccc(k) = 0\n if((csum * fterm) /= 0.0e0_knd) naccc(k) = ndec - 2 &\n -log10(abs((fterm) / (csum)))\n if((csum /= 0.0e0_knd) .and. fterm == 0.0e0_knd) naccc(k) = ndec - 2\n if((csum == 0.0e0_knd) .and. fterm == 0.0e0_knd) naccc(k) = ndec\n if(naccc(k) > ndec - 2) naccc(k) = ndec - 2\n if(naccc(k) < 0) naccc(k) = 0\n if(naccc(k) > 0) go to 210\n naccc(k) = 0\n ce(k) = 0.0e0_knd\n ced(k) = 0.0e0_knd\n go to 280\n!\n! compute the first derivative of the angular functions ce (when\n! iopang equals 2)\n210 if(iopang == 1) go to 280\n if(abs(sine(k, 3 - ix)) > adec) go to 230\n ced(k) = 0.0e0_knd\n jn = 1\nif (debug) then\n if(isq == 1 .or. ix == 0) write(50, 275) k, jfun, jn\n if(isq == -1 .and. ix == 1) write(50, 455) k, jfun, jn\nend if\n go to 280\n230 doldd = 1.0e0_knd\n fterm = 0.0e0_knd\n cdsum = -real(l, knd) * sine(k, l + 1)\n if(cdsum > 0.0e0_knd) fterm = cdsum\n do 240 j = jlow, lim\n coef = real(j + j + ix, knd)\n dnewd = doldd * enra(j)\n dterm = -dnewd * sine(k, j + j + ixx2) * coef\n if(dterm > 0.0e0_knd) fterm = fterm + dterm\n cdsum = cdsum + dterm\n if(cdsum == 0.0e0_knd) go to 235\n if((abs(dterm / cdsum) < dcon) .and. (abs(sine(k, j + j + ixx2)) &\n > 1.0e-01_knd)) go to 250\n235 doldd = dnewd\n240 continue\n250 if(j > jangc) jangc = j\n jn = j\n doldd = 1.0e0_knd\n j = l2\n ja = l2\n if(ja == 0) go to 270\n do 260 jj = 1, ja\n coef = real(j + j + ix - 2, knd)\n dnewd = doldd / enra(j)\n dterm = -dnewd * sine(k, j + j + ixx) * coef\n if(dterm > 0.0e0_knd) fterm = fterm + dterm\n cdsum = cdsum + dterm\n if((abs(dterm / cdsum) < dcon) .and. (abs(sine(k, j + j + ixx)) &\n > 1.0e-01_knd)) go to 270\n doldd = dnewd\n j = j - 1\n260 continue\n270 ced(k) = cdsum * dnuma * sgna\nif (debug) then\n if(isq == 1 .or. ix == 0) write(50, 275) k, jfun, jn\n if(isq == -1 .and. ix == 1) write(50, 455) k, jfun, jn\n275 format(8x,'angle ',i3,'. ce converged in ',i6,' terms; ced ', &\n 'converged in ',i6,' terms')\nend if\n if((cdsum == 0.0e0_knd) .and. fterm /= 0.0e0_knd) nacd = 0\n if((cdsum * fterm) /= 0.0e0_knd) nacd = ndec - 2 &\n -log10(abs((fterm) / (cdsum)))\n if((cdsum /= 0.0e0_knd) .and. fterm == 0.0e0_knd) nacd = ndec - 2\n if((cdsum == 0.0e0_knd) .and. fterm == 0.0e0_knd) nacd = ndec\n naccc(k) = min(naccc(k), nacd)\n if(naccc(k) < 0) naccc(k) = 0\n if(naccc(k) > 0) go to 280\n ced(k) = 0.0e0_knd\n280 if(l /= 0) go to 290\n se(k) = 0.0e0_knd\n sed(k) = 0.0e0_knd\n naccs(k) = ndec\n290 continue\n jangs = 0\n if(l == 0) go to 500\n!\n! compute dnumb, the magnitude of the b coefficient with index = l\n dnumb = 1.0e0_knd\n coef = 1.0e0_knd\n jlow = l + 2\n jterm = l2\n do 310 j = jlow, lims1, 2\n jterm = jterm + 1\n coef = coef * enrb(jterm) * enrb(jterm)\n dnumb = dnumb + coef\n if(abs(coef / dnumb) < dcon) go to 320\n310 continue\n320 jlow = l\n if(ix == 0) jlow = jlow - 2\n jn = jterm\n if(l < 3) go to 340\n coef = 1.0e0_knd\n jterm = l2\n j = jlow\n do 330 jj = 2, jlow, 2\n coef = coef / (enrb(jterm) * enrb(jterm))\n jterm = jterm - 1\n j = j - 2\n dnumb = dnumb + coef\n if(abs(coef / dnumb) < dcon) go to 340\n330 continue\n340 dnumb = 1.0e0_knd / sqrt(dnumb)\n bsubl = dnumb * sgnb\nif (debug) then\n if(isq == 1 .or. ix == 0) write(50, 345) jn, lim\n if(isq == -1 .and. ix == 1) write(50, 145) jn, lim\n345 format(5x,'se normalization series converged in ', &\n i6,' terms; ',i6,' terms available')\nend if\n jlow = l2 + 1\n jangs = 0\n do 490 k = 1, narg\n!\n! compute the angular function se\n if(abs(sine(k, 3 - ix)) > adec) go to 350\n naccs(k) = ndec\n se(k) = 0.0e0_knd\n jfun = 1\nif (debug) then\n if(iopang == 1 .and. (isq == 1 .or. ix == 0)) write(50, 375) k, jfun\n if(iopang == 1 .and. isq == -1 .and. ix == 1) write(50, 175) k, jfun\nend if\n go to 410\n350 dold = 1.0e0_knd\n ssum = sine(k, l + 1)\n fterm = 0.0e0_knd\n if(ssum > 0.0e0_knd) fterm = ssum\n do 360 j = jlow, lim\n dnew = dold * enrb(j)\n dterm = dnew * sine(k, j + j + ixx2)\n ssum = ssum + dterm\n if(dterm > 0.0e0_knd) fterm = fterm + dterm\n if((abs(dterm / ssum) < dcon) .and. (abs(sine(k, j + j + ixx2)) &\n > 1.0e-01_knd)) go to 370\n dold = dnew\n360 continue\n370 if(j > jangs) jangs = j\n jfun = j\nif (debug) then\n if(iopang == 1 .and. (isq == 1 .or. ix == 0)) write(50, 375) k, jfun\n if(iopang == 1 .and. isq == -1 .and. ix == 1) write(50, 175) k, jfun\n375 format(8x,'angle ',i3,'. se converged in ',i6,' terms')\nend if\n jjupp = l2\n if(ix == 0) jjupp = l2 - 1\n if(jjupp < 1) go to 390\n dold = 1.0e0_knd\n j = l2\n do 380 jj = 1, jjupp\n dnew = dold / enrb(j)\n dterm = dnew * sine(k, j + j + ixx)\n ssum = ssum + dterm\n if(dterm > 0.0e0_knd) fterm = fterm + dterm\n if((abs(dterm / ssum) < dcon) .and. (abs(sine(k, j + j + ixx)) &\n > 0.1e0_knd)) go to 390\n dold = dnew\n j = j - 1\n380 continue\n390 se(k) = ssum * dnumb * sgnb\n if((ssum == 0.0e0_knd) .and. fterm /= 0.0e0_knd) naccs(k) = 0\n if((ssum /= 0.0e0_knd) .and. fterm /= 0.0e0_knd) naccs(k) = ndec - 2 &\n -log10(abs((fterm) / (ssum)))\n if((ssum == 0.0e0_knd) .and. fterm == 0.0e0_knd) naccs(k) = ndec\n if((ssum /= 0.0e0_knd) .and. fterm == 0.0e0_knd) naccs(k) = ndec - 2\n if(naccs(k) > ndec - 2) naccs(k) = ndec - 2\n if(naccs(k) < 0) naccs(k) = 0\n if(naccs(k) > 0) go to 410\n naccs(k) = 0\n se(k) = 0.0e0_knd\n sed(k) = 0.0e0_knd\n go to 490\n!\n! compute the first derivative of the angular functions se (when\n! iopang equals 2)\n410 if(iopang == 1) go to 490\n if(abs(cosi(k, 3 - ix)) > adec) go to 415\n sed(k) = 0.0e0_knd\n jn = 1\nif (debug) then\n if(isq == 1 .or. ix == 0) write(50, 455) k, jfun, jn\n if(isq == -1 .and. ix == 1) write(50, 275) k, jfun, jn\nend if\n go to 490\n415 doldd = 1.0e0_knd\n fterm = 0.0e0_knd\n sdsum = real(l, knd) * (cosi(k, l + 1))\n if(sdsum > 0.0e0_knd) fterm = sdsum\n do 440 j = jlow, lim\n coef = real(j + j + ix, knd)\n dnewd = doldd * enrb(j)\n dterm = dnewd * cosi(k, j + j + ixx2) * coef\n if(dterm > 0.0e0_knd) fterm = fterm + dterm\n sdsum = sdsum + dterm\n if(sdsum == 0.0e0_knd) go to 420\n if((abs(dterm / sdsum) < dcon) .and. (abs(cosi(k, j + j + ixx2)) &\n > 1.0e-01_knd)) go to 450\n420 doldd = dnewd\n440 continue\n450 if(j > jangs) jangs = j\nif (debug) then\n if(isq == 1 .or. ix == 0) write(50, 455) k, jfun, j\n if(isq == -1 .and. ix == 1) write(50, 275) k, jfun, j\n455 format(8x,'angle ',i3,'. se converged in ',i6,' terms; sed ', &\n 'converged in ',i6,' terms')\nend if\n jjupp = l2\n if(ix == 0) jjupp = l2 - 1\n if(jjupp < 1) go to 470\n doldd = 1.0e0_knd\n j = l2\n do 460 jj = 1, jjupp\n coef = real(j + j + ix - 2, knd)\n dnewd = doldd / enrb(j)\n dterm = dnewd * cosi(k, j + j + ixx) * coef\n if(dterm > 0.0e0_knd) fterm = fterm + dterm\n sdsum = sdsum + dterm\n if((abs(dterm / sdsum) < dcon) .and. (abs(cosi(k, j + j + ixx)) &\n > 1.0e-01_knd)) go to 470\n doldd = dnewd\n j = j - 1\n460 continue\n470 sed(k) = sdsum * dnumb * sgnb\n if((sdsum == 0.0e0_knd) .and. fterm /= 0.0e0_knd) nacd = 0\n if((sdsum /= 0.0e0_knd) .and. fterm /= 0.0e0_knd) nacd = ndec - 2 &\n -log10(abs((fterm) / (sdsum)))\n if((sdsum /= 0.0e0_knd) .and. fterm == 0.0e0_knd) nacd = ndec - 2\n if((sdsum == 0.0e0_knd) .and. fterm == 0.0e0_knd) nacd = ndec\n naccs(k) = min(naccs(k), nacd)\n if(naccs(k) < 0) naccs(k) = 0\n if(naccs(k) > 0) go to 490\n sed(k) = 0.0e0_knd\n490 continue\n500 if(isq == 1) go to 600\n do 520 k = 1, narg\n if(ix /= 0) go to 510\n se(k) = -se(k)\n sed(k) = -sed(k)\n if(lx2 == 0) go to 520\n ce(k) = -ce(k)\n ced(k) = -ced(k)\n se(k) = -se(k)\n sed(k) = -sed(k)\n go to 520\n510 temp = ce(k)\n tempd = ced(k)\n ce(k) = se(k)\n ced(k) = sed(k)\n se(k) = temp\n sed(k) = tempd\n if(lx2 == 0) go to 520\n ce(k) = -ce(k)\n ced(k) = -ced(k)\n se(k) = -se(k)\n sed(k) = -sed(k)\n520 continue\n asubls = asubl\n asubl = bsubl\n bsubl = asubls\n600 return\n end subroutine\n!\n!\n subroutine m1bes (iopcs, l, cm, x1, isq, limr1, ndec, maxd, enra, &\n enrb, maxj, maxlp, nex, cbesf, cbesn, ibese, cbesdf, &\n cbesdr, m1bot, a01, ia01, b12, ib12, jbes, iflag, &\n nsubcs, m1c, im1e, m1dc, im1de)\n!\n! purpose : to calculate the Mathieu radial function of the\n! first kind and its first derivative with respect\n! to the traditional radial coordinate z, using an\n! expansion of cylindrical Bessel functions of the\n! first kind with argument c*sqrt(xi*xi-1)\n!\n! parameters :\n!\n! input : iopcs : =1 if cosine radial functions calculated\n! : =2 if sine radial functions calculated\n! l : l\n! cm : magnitude of c\n! x1 : xi-1\n! isq : integer = +1 if q is positive, = -1 if q is\n! negative\n! limr1 : twice the maximum number of terms available\n! ndec : number of decimal digits available in\n! real(knd) arithmetic\n! maxd : size of enr vector\n! enra : a coefficient ratios\n! enrb : b coefficient ratios\n! maxj : size of cbesf vector\n! maxlp : maximum l value desired; size\n! of the cbesn and ibese vectors\n! nex : largest integer exponent available in\n! real(knd) arithmetic\n! cbesf : vector of ratios of cylindrical Bessel\n! functions of the first kind\n! cbesn : vector of characteristics of the Bessel\n! functions\n! ibese : vector of exponents of the Bessel functions\n! cbesdf : vector of ratios of first derivatives of the\n! cylindrical Bessel functions\n! cbesdr : vector of ratios of first derivatives of the\n! cylindrical Bessel functions to the\n! corresponding Bessel functions\n! m1bot : denominator sum for m1 and m1d that is\n! calculated in dnorma or dnormb\n! a01 : characteristic of the first a coefficient\n! ia01 : exponent of the first a coefficient\n! a01 : characteristic of the first b coefficient\n! ia01 : exponent of the first b coefficient\n!\n! output : jbes : maximum number of terms taken\n! iflag : integer = 1 when backward series not used\n! to calculate functions and first derivatives\n! nsubcs : larger of the subtraction errors encountered\n! in the numerator series for m1 and m1d\n! m1c : characteristic of Mathieu radial function\n! of the first kind\n! im1e : exponent of Mathieu radial function of the\n! first kind [note that when q is\n! negative (isq=-1) and l is odd, the Mathieu\n! radial function m1 = i times m1c times\n! 10**(im1e), where i is the square root of -1.]\n! m1dc : characteristic of derivative with respect\n! to x of Mathieu radial function of the first\n! kind\n! im1de : exponent of derivative with respect to x of\n! Mathieu radial function of the first kind\n! [note that when qu is negative (isq=-1)\n! and l is odd, the Mathieu radial function\n! m1d = i times m1dc times 10**(im1de), where i\n! is the square root of -1.]\n!\n use param\n!\n! real(knd) scalars and vectors\n real(knd) a1ol, a01, b12, cm, con1, dcon, dsqu, dnew, dnewd, dold, doldd, &\n m1bot, m1c, m1dc, m1dpos, m1dstore, m1dtemp, m1dtempd, &\n m1pos, m1temp, m1tempd, m1top, sqx2m1, term, termd, &\n teste, testeo, xi, x1, x2m1\n real(knd) enr(maxd), enra(maxd), enrb(maxd), cbesdf(maxj), &\n cbesdr(maxj), cbesf(maxj), cbesn(maxlp)\n!\n! integer vector\n dimension ibese(maxlp)\n!\n! convergence ratio dcon is set according to the number of decimal\n! digits available\n dcon = 10.0e0_knd ** (-ndec - 2)\n xi = x1 + 1.0e0_knd\n x2m1 = x1 * (x1 + 2.0e0_knd)\n sqx2m1 = sqrt(x2m1)\n l2 = l / 2\n! ix=0 for l even, ix=1 for l odd\n ix = l - 2 * l2\n! lx2=0 for l2 even, lx2=1 for l2 odd\n lx2 = l2 - 2 * (l2 / 2)\n! ix2=0 for (l+1)/2 even, ix2=1 for (l+1)/2 odd\n ix2 = (l + 1) / 2 - 2 * ((l + 1) / 4)\n ics = ix\n if(iopcs == 2) ics = iabs(ix - 1)\n dsqu = real(isq, knd)\n iflagd = 0\n if(xi < 1.1e0_knd .and. iopcs == 1 .and. ix == 1) iflagd = 1\n if(x1 == 0.0e0_knd) go to 220\n jlim = 1\n if(ix == 0 .and. iopcs == 2) jlim = 2\n lim = limr1 / 2 - ix\n con1 = xi / sqx2m1\n nfac = nex - ndec\n teste = 10.0e0_knd ** nfac\n testeo = 1.0e0_knd / teste\n im1dtemp = 0\n im1temp = 0\n if(isq == -1) go to 25\n if(iopcs == 2) go to 15\n do 10 i = 1, lim\n enr(i) = enra(i)\n10 continue\n go to 50\n15 do 20 i = 1, lim\n enr(i) = enrb(i)\n20 continue\n go to 50\n25 if(ics == 1) go to 35\n do 30 i = 1, lim\n enr(i) = enra(i)\n30 continue\n go to 50\n35 do 40 i = 1, lim\n enr(i) = enrb(i)\n40 continue\n50 continue\n!\n! compute ratio of 1st coeffficient to lth coefficient when l\n! is odd, xi is less than 1.1 but not equal to 1, and cosine functions\n! are being computed\n!\n if(iflagd == 0) go to 70\n a1ol = 1.0e0_knd\n ia1ol = 0\n if(l == 1) go to 70\n do 60 i = 1, l2\n a1ol = a1ol / enr(i)\n iterm = int(log10(abs(a1ol)))\n a1ol = a1ol * (10.0e0_knd ** (-iterm))\n ia1ol = ia1ol + iterm\n60 continue\n70 continue\n!\n! compute radial function of the first kind m1\n!\n! forward summation of numerator series for m1 and m1d\n m1tempd = 0.0e0_knd\n m1dtempd = 0.0e0_knd\n dold = 1.0e0_knd\n doldd = 1.0e0_knd\n m1temp = dold\n m1dtemp = doldd\n jlow = l2 + 1\n if(ics == 0) go to 80\n m1temp = real(l, knd) * dold\n m1dtemp = real(l, knd) * doldd\n80 m1pos = m1temp\n m1dpos = m1dtemp\n jbes = l2\n if(iflag == 1) go to 120\n do 100 j = jlow, lim\n jj = j + j + ix\n dnew = dold * enr(j) * cbesf(jj)\n dnewd = doldd * enr(j) * cbesdf(jj)\n term = dnew\n termd = dnewd\n if(ics == 0) go to 90\n term = dnew * real(jj, knd)\n termd = dnewd * real(jj, knd)\n90 if(term > 0.0e0_knd) m1pos = m1pos + term\n if(termd > 0.0e0_knd) m1dpos = m1dpos + termd\n m1temp = m1temp + term\n m1dtemp = m1dtemp + termd\n if((abs(term / m1temp) + abs(termd / m1dtemp)) < dcon) go to 110\n dold = dnew\n doldd = dnewd\n100 continue\n110 jbes = j\n if(iflagd == 0 .or. l /= 1) go to 120\n m1tempd = m1temp - 1.0e0_knd\n m1dtempd = m1dtemp - 1.0e0_knd\n120 continue\n!\n! backward summation of numerator series for m1\n if (l2 < jlim) go to 175\n dold = 1.0e0_knd\n doldd = 1.0e0_knd\n do 160 j = l2, jlim,-1\n jj = j + j + ix\n dnew = dold / (enr(j) * cbesf(jj))\n dnewd = doldd / (enr(j) * cbesdf(jj))\n term = dnew\n termd = dnewd\n if(ics == 0) go to 140\n term = dnew * real(jj - 2, knd)\n termd = dnewd * real(jj - 2, knd)\n140 if(term > 0.0e0_knd) m1pos = m1pos + term\n if(termd > 0.0e0_knd) m1dpos = m1dpos + termd\n m1temp = m1temp + term\n m1dtemp = m1dtemp + termd\n if((abs(term / m1temp) + abs(termd / m1dtemp)) < dcon) go to 170\n if(abs(m1temp) > teste .or. abs(m1dtemp) > teste) then\n m1temp = m1temp * testeo\n m1dtemp = m1dtemp * testeo\n dnew = dnew * testeo\n dnewd = dnewd * testeo\n m1pos = max(m1pos * testeo, dcon * abs(m1temp))\n m1dpos = max(m1dpos * testeo, dcon * abs(m1dtemp))\n im1temp = im1temp + nfac\n end if\n150 dold = dnew\n doldd = dnewd\n160 continue\n170 if(jj /= 3) iflagd = 0\n im1dtemp = im1temp\n if(iflagd == 0) go to 175\n m1tempd = m1temp - dnew\n m1dtempd = m1dtemp - dnewd\n175 m1top = m1temp * cbesn(l + 1)\n im1tope = im1temp + ibese(l + 1)\n iterm = 0\n if(m1top /= 0.0e0_knd) iterm = log10(abs(m1top))\n im1tope = im1tope + iterm\n m1top = m1top * 10.0e0_knd ** (-iterm)\n nsub = 0\n if((m1temp * m1pos) /= 0.0e0_knd) nsub= &\n int(log10(abs(m1pos / m1temp)))\n if(nsub < 0) nsub = 0\n if(nsub > ndec) nsub = ndec\n if(m1temp == 0.0e0_knd .and. m1pos /= 0.0e0_knd) nsub = ndec\n nsubd = 0\n if((m1dtemp * m1dpos) /= 0.0e0_knd) nsubd= &\n int(log10(abs(m1dpos / m1dtemp)))\n if(nsubd < 0) nsubd = 0\n if(nsubd > ndec) nsubd = ndec\n if(m1dtemp == 0.0e0_knd .and. m1dpos /= 0.0e0_knd) nsubd = ndec\n nsubcs = max(nsub, nsubd)\nif (debug) then\n if(iopcs == 1 .and. iflag == 0) write(40, 180) jbes, lim, nsubcs\n180 format(3x,'mc1/mc1d numerator converged in ',i5,' terms; ',i5, &\n ' available; sub. error = ',i3,' digits.')\n if(iopcs == 2 .and. iflag == 0) write(40, 190) jbes, lim, nsubcs\n190 format(3x,'ms1/ms1d numerator converged in ',i5,' terms; ',i5, &\n ' available; sub. error = ',i3,' digits.')\n if(iopcs == 1 .and. iflag == 1) write(40, 200) jbes, lim, nsubcs\n200 format(3x,'mc1/mc1d numerator converged in ',i5,' terms; ',i5, &\n ' available; fwd series not used; sub. error = ',i3, &\n ' digits.')\n if(iopcs == 2 .and. iflag == 1) write(40, 210) jbes, lim, nsubcs\n210 format(3x,'ms1/ms1d numerator converged in ',i5,' terms; ',i5, &\n ' available; fwd series not used; sub. error = ',i3, &\n ' digits.')\nend if\n!\n! combining numerator with denominator series computed in dnorma for\n! mc1 or in dnormb for ms1\n m1c = m1top / m1bot\n if(ics == 1) m1c = m1c * con1\n go to 240\n220 if(isq == -1) go to 230\n m1c = 0.0e0_knd\n im1e = 0\n if(iopcs == 1) m1c = a01 / m1bot\n if(iopcs == 1) im1e = ia01\n if(ix == 1) m1c = 0.5e0_knd * m1c * cm\n go to 240\n230 m1c = 0.0e0_knd\n im1e = 0\n if(iopcs == 1 .and. ix == 0) m1c = a01 / m1bot\n if(iopcs == 1 .and. ix == 0) im1e = ia01\n if(iopcs == 1 .and. ix == 1) m1c = 0.5e0_knd * cm * b12 / m1bot\n if(iopcs == 1 .and. ix == 1) im1e = ib12\n240 if(isq == 1 .and. iopcs == 1 .and. ix2 == 1) m1c = -m1c\n if(isq == 1 .and. iopcs == 2 .and. lx2 == 1) m1c = -m1c\n if(isq == -1 .and. iopcs == 1 .and. lx2 == 1) m1c = -m1c\n if(isq == -1 .and. iopcs == 2 .and. lx2 == 1) m1c = -m1c\n iterm = 0\n if(m1c /= 0.0e0_knd) iterm = int(log10(abs(m1c)))\n if(x1 == 0.0e0_knd) im1e = im1e + iterm\n if(x1 /= 0.0e0_knd) im1e = im1tope + iterm\n m1c = m1c * 10.0e0_knd ** (-iterm)\n if(abs(m1c) >= 1.0e0_knd .or. m1c == 0.0e0_knd) go to 250\n m1c = m1c * 10.0e0_knd\n im1e = im1e - 1\n250 continue\n if(x1 == 0.0e0_knd) go to 270\n if(iflagd == 1) m1temp = m1tempd\n if(iflagd == 1) m1dtemp = m1dtempd\n m1dtemp = cm * xi * m1dtemp * cbesdr(l + 1)\n m1dstore = m1dtemp\n if(ics == 1) m1dtemp = m1dtemp - m1temp / (xi * sqx2m1)\n idsub = -log10(abs(m1dtemp / m1dstore))\n if(idsub < 0) idsub = 0\n m1dc = m1dtemp * cbesn(l + 1) / m1bot\n if(iflagd == 0) go to 255\n term = x2m1 * cbesdr(2) * cbesn(2)\n termd = term - dsqu * cbesn(3) * (10.0e0_knd ** (ibese(3) - ibese(2)))\n idsub1 = -log10(abs(termd / term))\n if(idsub1 < 0) idsub1 = 0\n termd = termd * a1ol * (cm / xi) * (10.0e0_knd ** (ia1ol + ibese(2)- &\n ibese(l + 1) - im1dtemp)) / m1bot\n m1dc = m1dc + termd\n idsub2 = -log10(abs(m1dc / termd))\n if(idsub2 < 0) idsub2 = 0\n idsub = idsub + idsub1 + idsub2\n255 continue\nif (debug) then\n if(idsub /= 0) write(40, 260) idsub\n260 format(24x,'subtraction error in forming m1d =',i3,' digits.')\nend if\n if(ics == 1) m1dc = m1dc * con1\n go to 290\n270 if(isq == -1) go to 280\n m1dc = 0.0e0_knd\n im1de = 0\n if(iopcs == 2) m1dc = 0.5e0_knd * cm * b12 / m1bot\n if(iopcs == 2) im1de = ib12\n if(ix == 0) m1dc = 0.5e0_knd * cm * m1dc\n go to 290\n280 m1dc = 0.0e0_knd\n im1de = 0\n if(iopcs == 2 .and. ix == 0) m1dc = 0.25e0_knd * cm * cm * b12 / m1bot\n if(iopcs == 2 .and. ix == 0) im1de = ib12\n if(iopcs == 2 .and. ix == 1) m1dc = 0.5e0_knd * cm * a01 / m1bot\n if(iopcs == 2 .and. ix == 1) im1de = ia01\n290 if(isq == 1 .and. iopcs == 1 .and. ix2 == 1) m1dc = -m1dc\n if(isq == 1 .and. iopcs == 2 .and. lx2 == 1) m1dc = -m1dc\n if(isq == -1 .and. iopcs == 1 .and. lx2 == 1) m1dc = -m1dc\n if(isq == -1 .and. iopcs == 2 .and. lx2 == 1) m1dc = -m1dc\n iterm = 0\n if(m1dc /= 0.0e0_knd) iterm = int(log10(abs(m1dc)))\n if(x1 /= 0.0e0_knd) im1de = iterm + ibese(l + 1) + im1dtemp\n if(x1 == 0.0e0_knd) im1de = im1de + iterm\n m1dc = m1dc * 10.0e0_knd ** (-iterm)\n if(abs(m1dc) >= 1.0e0_knd .or. m1dc == 0.0e0_knd) go to 300\n m1dc = 10.0e0_knd * m1dc\n im1de = im1de - 1\n300 mfac = im1tope - ibese(l + 1)\n if(mfac > (ndec + 5)) iflag = 1\n if(mfac <= (ndec + 5)) iflag = 0\n return\n end subroutine\n!\n!\n subroutine m1bpe (iopcs, iss, ismax, l, cm, x1, limbpe, ndec, limd, maxd, &\n enra, enrb, maxj, maxlp, nex, cbesf1, cbesn1, ibese1, &\n cbesdf1, cbesdr1, cbesf, cbesn, ibese, cbesdf, &\n cbesdr, a01, ia01, b12, ib12, jbpe, nsub, m1c, im1e, &\n m1dc, im1de)\n!\n! purpose : to calculate the Mathieu radial function of the\n! first kind and its first derivative with respect\n! to the traditional radial function z when q is\n! negative, using a series of products of modified\n! cylindrical Bessel functions of the first kind,\n! with the integer order offset s (is) of the Bessel\n! function for input as a free parameter\n!\n! parameters :\n!\n! input : iopcs : =1 if cosine radial functions calculated\n! : =2 if sine radial functions calculated\n! iss : integer offset minus l from calculation\n! for radial function of the same kind\n! (sine or cosine) for previous l\n! ismax : maximum allowable value for the integer offset\n! l : l\n! cm : magnitude of c (c being positive imaginary)\n! x1 : xi-1\n! limbpe : twice the maximum number of terms available\n! ndec : number of decimal digits available in\n! real(knd) arithmetic\n! limd : number of a and b coefficient ratios that have\n! been calculated for this case\n! maxd : dimension of enra and enrb vectors\n! enra : vector of a coefficient ratios\n! enrb : vector of b coefficient ratios\n! maxj : dimension of cbesf, cbesdf, cbesdr, cbesf1,\n! cbesdf1 and cbesdr1 vectors\n! maxlp : dimension of cbesn, ibese, cbesn1, and\n! ibese1 vectors\n! nex : largest integer exponent abvailable in\n! real(knd) arithmetic\n! cbesf1 : vector of ratios of cylindrical Bessel\n! functions of the first kind with argument\n! c*[xi - sqrt(xi*xi - 1)]/2\n! cbesn1 : vector of characteristics of these Bessel\n! functions\n! ibese1 : vector of exponents of these Bessel functions\n! cbesdf1: vector of ratios of first derivatives of\n! these Bessel functions\n! cbesdr1: vector of ratios of first derivatives of\n! these Bessel functions to the corresponding\n! Bessel functions\n! cbesf : vector of ratios of cylindrical Bessel\n! functions of the first kind with argument\n! c*[xi + sqrt(xi*xi - 1)]/2\n! cbesn : vector of characteristics of these Bessel\n! functions\n! ibese : vector of exponents of these Bessel functions\n! cbesdf : vector of ratios of first derivatives of these\n! Bessel functions\n! cbesdr : vector of ratios of first derivatives of\n! these Bessel functions to the corresponding\n! Bessel functions\n! a01 : characteristic of the first a coefficient\n! ia01 : exponent of the first a coefficient\n! b12 : characteristic of the first b coefficient\n! ib12 : exponent of the first b coefficient\n!\n! output : jbpe : twice the maximum number of terms taken\n! nsub : maximum number of digits of subtraction\n! error encountered in the calculation of\n! the function and its first derivative\n! m1c : characteristic of Mathieu radial function\n! of the first kind.\n! im1e : exponent of Mathieu radial function of the\n! first kind\n! m1dc : characteristic of derivative with respect\n! to x of Mathieu radial function of the first\n! kind\n! im1de : exponent of derivative with respect to x of\n! Mathieu radial function of the first kind\n!\n use param\n!\n! real(knd) scalars and vectors\n real(knd) a01, b12, cm, coef, coefa, coefb, dcon, den, dnewa, dnewb, &\n dolda, doldas, doldb, doldbs, m1bot, m1c, m1dc, m1dpos, &\n m1dtemp, m1pos, m1temp, sqx2m1, term, terma, termb, termd, &\n termd1, termd1a, termd1b, termd2, termd2a, termd2b, &\n teste, testeo, u1, u2, xi, x1, x2m1\n real(knd) enr(maxd), enra(maxd), enrb(maxd), cbesdf1(maxj), &\n cbesdr1(maxj), cbesf1(maxj), cbesn1(maxlp), cbesdf(maxj), &\n cbesdr(maxj), cbesf(maxj), cbesn(maxlp)\n!\n! integer vectors\n dimension ibese1(maxlp), ibese(maxlp)\n!\n! convergence ratio dcon is set according to the number of decimal\n! digits available\n dcon = 10.0e0_knd ** (-ndec - 2)\n xi = x1 + 1.0e0_knd\n x2m1 = x1 * (x1 + 2.0e0_knd)\n sqx2m1 = sqrt(x2m1)\n u1 = 0.5e0_knd * cm / (xi + sqx2m1)\n u2 = 0.5e0_knd * cm * (xi + sqx2m1)\n l2 = l / 2\n!\n! ix=0 for l even, ix=1 for l odd\n ix = l - 2 * l2\n ics = ix\n if(iopcs == 2) ics = iabs(ix - 1)\n if(iopcs == 1 .and. ix == 0) iopt = 10\n if(iopcs == 1 .and. ix == 1) iopt = 11\n if(iopcs == 2 .and. ix == 0) iopt = 20\n if(iopcs == 2 .and. ix == 1) iopt = 21\n lim = limbpe / 2 - ix\n nfac = nex - ndec\n teste = 10.0e0_knd ** nfac\n testeo = 1.0e0_knd / teste\n im1dtemp = 0\n im1temp = 0\n joff = 0\n if(iopt == 20) joff = 1\n jlim = 1 + joff\n is = l + iss\n if(is > ismax) is = ismax\n lims = is + joff + 100 + int(cm / 10.0)\n limmax = max(lims, lim)\n if(limmax > limd - 1) limmax = limd - 1\n if(ics == 1) go to 20\n do 10 i = 1, limmax\n enr(i) = enra(i)\n10 continue\n m1bot = a01\n ibot = ia01\n go to 40\n20 do 30 i = 1, limmax\n enr(i) = enrb(i)\n30 continue\n m1bot = b12\n ibot = ib12\n40 continue\n den = m1bot\n iden = ibot\n if(is == 0) go to 60\n do 50 k = 1, is\n den = den * enr(k + joff)\n iterm = int(log10(abs(den)))\n den = den * (10.0e0_knd ** (-iterm))\n iden = iden + iterm\n50 continue\n60 continue\n!\n! compute radial function of the first kind m1\n!\n! forward summation of product series for m1 and m1d\n coefa = cbesn1(-l2 + is + 1 + joff) * cbesn(l2 + is + 1 + joff)\n inda = ibese1(-l2 + is + 1 + joff) + ibese(l2 + is + 1 + joff)\n coefb = cbesn1(l2 + is + 1 + joff) * cbesn(-l2 + is + 1 + joff)\n indb = ibese1(l2 + is + 1 + joff) + ibese(-l2 + is + 1 + joff)\n if(inda < indb) go to 70\n dolda = 1.0e0_knd\n doldb = (coefb / coefa) * (10.0e0_knd ** (indb - inda))\n coef = coefa\n icoef = inda\n go to 80\n70 doldb = 1.0e0_knd\n dolda = (coefa / coefb) * (10.0e0_knd ** (inda - indb))\n coef = coefb\n icoef = indb\n80 doldas = dolda\n doldbs = doldb\n if(iopt == 10) terma = 1.0e0_knd\n if(iopt == 10) termb = 1.0e0_knd\n if(iopt == 11) terma = cbesf(l2 + is + 1)\n if(iopt == 11) termb = cbesf1(l2 + is + 1)\n if(iopt == 21) terma = cbesf(l2 + is + 1)\n if(iopt == 21) termb = -cbesf1(l2 + is + 1)\n if(iopt == 20) terma = 1.0e0_knd\n if(iopt == 20) termb = -1.0e0_knd\n m1temp = dolda * terma + doldb * termb\n if(iopt == 10) termd1a = cbesdr1(is - l2 + 1)\n if(iopt == 10) termd2a = cbesdr(l2 + is + 1)\n if(iopt == 10) termd1b = cbesdr1(l2 + is + 1)\n if(iopt == 10) termd2b = cbesdr(is - l2 + 1)\n if(iopt == 20) termd1a = cbesdr1(is - l2 + 2)\n if(iopt == 20) termd2a = cbesdr(l2 + is + 2)\n if(iopt == 20) termd1b = -cbesdr1(l2 + is + 2)\n if(iopt == 20) termd2b = -cbesdr(is - l2 + 2)\n if(iopt == 11) termd1a = cbesdr1(is - l2 + 1) * cbesf(l2 + is + 1)\n if(iopt == 11) termd2a = cbesdr(l2 + is + 2) * cbesf(l2 + is + 1)\n if(iopt == 11) termd1b = cbesdr1(l2 + is + 2) * cbesf1(l2 + is + 1)\n if(iopt == 11) termd2b = cbesdr(is - l2 + 1) * cbesf1(l2 + is + 1)\n if(iopt == 21) termd1a = cbesdr1(is - l2 + 1) * cbesf(l2 + is + 1)\n if(iopt == 21) termd2a = cbesdr(l2 + is + 2) * cbesf(l2 + is + 1)\n if(iopt == 21) termd1b = -cbesdr1(l2 + is + 2) * cbesf1(l2 + is + 1)\n if(iopt == 21) termd2b = -cbesdr(is - l2 + 1) * cbesf1(l2 + is + 1)\n termd1 = dolda * termd1a + doldb * termd1b\n termd2 = dolda * termd2a + doldb * termd2b\n m1dtemp = -u1 * termd1 + u2 * termd2\n m1pos = 0.0e0_knd\n if(m1temp > 0.0e0_knd) m1pos = m1temp\n m1dpos = 0.0e0_knd\n if(m1dtemp > 0.0e0_knd) m1dpos = m1dtemp\n jbpe = l2\n lflag = 0\n!\n! forward summation for is => j\n do 100 j = l2 + 1, is + joff\n dnewa = -dolda * enr(j) * cbesf(j + is + joff) / cbesf1(is + joff - j + 1)\n dnewb = -doldb * enr(j) * cbesf1(j + is + joff) / cbesf(is + joff - j + 1)\n if(iopt == 10) terma = dnewa\n if(iopt == 10) termb = dnewb\n if(iopt == 11) terma = dnewa * cbesf(j + is + 1)\n if(iopt == 11) termb = dnewb * cbesf1(j + is + 1)\n if(iopt == 21) terma = dnewa * cbesf(j + is + 1)\n if(iopt == 21) termb = -dnewb * cbesf1(j + is + 1)\n if(iopt == 20) terma = dnewa\n if(iopt == 20) termb = -dnewb\n term = terma + termb\n if(iopt == 10) termd1a = dnewa * cbesdr1(is - j + 1)\n if(iopt == 10) termd2a = dnewa * cbesdr(j + is + 1)\n if(iopt == 10) termd1b = dnewb * cbesdr1(j + is + 1)\n if(iopt == 10) termd2b = dnewb * cbesdr(is - j + 1)\n if(iopt == 20) termd1a = dnewa * cbesdr1(is - j + 2)\n if(iopt == 20) termd2a = dnewa * cbesdr(j + is + 2)\n if(iopt == 20) termd1b = -dnewb * cbesdr1(j + is + 2)\n if(iopt == 20) termd2b = -dnewb * cbesdr(is - j + 2)\n if(iopt == 11) termd1a = dnewa * cbesdr1(is - j + 1) * cbesf(j + is + 1)\n if(iopt == 11) termd2a = dnewa * cbesdr(j + is + 2) * cbesf(j + is + 1)\n if(iopt == 11) termd1b = dnewb * cbesdr1(j + is + 2) * cbesf1(j + is + 1)\n if(iopt == 11) termd2b = dnewb * cbesdr(is - j + 1) * cbesf1(j + is + 1)\n if(iopt == 21) termd1a = dnewa * cbesdr1(is - j + 1) * cbesf(j + is + 1)\n if(iopt == 21) termd2a = dnewa * cbesdr(j + is + 2) * cbesf(j + is + 1)\n if(iopt == 21) termd1b = -dnewb * cbesdr1(j + is + 2) * cbesf1(j + is + 1)\n if(iopt == 21) termd2b = -dnewb * cbesdr(is - j + 1) * cbesf1(j + is + 1)\n termd1 = termd1a + termd1b\n termd2 = termd2a + termd2b\n termd = -u1 * termd1 + u2 * termd2\n if(term > 0.0e0_knd) m1pos = m1pos + term\n if(termd > 0.0e0_knd) m1dpos = m1dpos + termd\n m1temp = m1temp + term\n m1dtemp = m1dtemp + termd\n if(m1temp * m1dtemp == 0.0e0_knd) go to 120\n if((abs(term / m1temp) + abs(termd / m1dtemp)) < dcon) go to 120\n if(abs(m1temp) > teste .or. abs(m1dtemp) > teste) then\n m1temp = m1temp * testeo\n m1dtemp = m1dtemp * testeo\n dnewa = dnewa * testeo\n dnewb = dnewb * testeo\n m1pos = max(m1pos * testeo, dcon * abs(m1temp))\n m1dpos = max(m1dpos * testeo, dcon * abs(m1dtemp))\n m1dpos = m1dpos * testeo\n im1temp = im1temp + nfac\n im1dtemp = im1dtemp + nfac\n lflag = 1\n end if\n90 dolda = dnewa\n doldb = dnewb\n100 continue\n!\n! forward summation for j > is\n do 110 j = is + joff + 1, lim\n dnewa = -dolda * enr(j) * cbesf1(j - is - joff) * cbesf(j + is + joff)\n dnewb = -doldb * enr(j) * cbesf1(j + is + joff) * cbesf(j - is - joff)\n if(iopt == 10) terma = dnewa\n if(iopt == 10) termb = dnewb\n if(iopt == 11) terma = dnewa * cbesf(j + is + 1)\n if(iopt == 11) termb = dnewb * cbesf1(j + is + 1)\n if(iopt == 21) terma = dnewa * cbesf(j + is + 1)\n if(iopt == 21) termb = -dnewb * cbesf1(j + is + 1)\n if(iopt == 20) terma = dnewa\n if(iopt == 20) termb = -dnewb\n term = terma + termb\n if(iopt == 10) termd1a = dnewa * cbesdr1(j - is + 1)\n if(iopt == 10) termd2a = dnewa * cbesdr(j + is + 1)\n if(iopt == 10) termd1b = dnewb * cbesdr1(j + is + 1)\n if(iopt == 10) termd2b = dnewb * cbesdr(j - is + 1)\n if(iopt == 20) termd1a = dnewa * cbesdr1(j - is)\n if(iopt == 20) termd2a = dnewa * cbesdr(j + is + 2)\n if(iopt == 20) termd1b = -dnewb * cbesdr1(j + is + 2)\n if(iopt == 20) termd2b = -dnewb * cbesdr(j - is)\n if(iopt == 11) termd1a = dnewa * cbesdr1(j - is + 1) * cbesf(j + is + 1)\n if(iopt == 11) termd2a = dnewa * cbesdr(j + is + 2) * cbesf(j + is + 1)\n if(iopt == 11) termd1b = dnewb * cbesdr1(j + is + 2) * cbesf1(j + is + 1)\n if(iopt == 11) termd2b = dnewb * cbesdr(j - is + 1) * cbesf1(j + is + 1)\n if(iopt == 21) termd1a = dnewa * cbesdr1(j - is + 1) * cbesf(j + is + 1)\n if(iopt == 21) termd2a = dnewa * cbesdr(j + is + 2) * cbesf(j + is + 1)\n if(iopt == 21) termd1b = -dnewb * cbesdr1(j + is + 2) * cbesf1(j + is + 1)\n if(iopt == 21) termd2b = -dnewb * cbesdr(j - is + 1) * cbesf1(j + is + 1)\n termd1 = termd1a + termd1b\n termd2 = termd2a + termd2b\n termd = -u1 * termd1 + u2 * termd2\n if(term > 0.0e0_knd) m1pos = m1pos + term\n if(termd > 0.0e0_knd) m1dpos = m1dpos + termd\n m1temp = m1temp + term\n m1dtemp = m1dtemp + termd\n if(m1temp * m1dtemp == 0.0e0_knd) go to 120\n if((abs(term / m1temp) + abs(termd / m1dtemp)) < dcon) go to 120\n dolda = dnewa\n doldb = dnewb\n110 continue\n120 jbpe = j\n!\n! backward summation of product series for m1 and m1d\n if(l2 < jlim .or. lflag == 1) go to 140\n dolda = doldas\n doldb = doldbs\n do 130 j = l2, jlim,-1\n dnewa = -dolda * cbesf1(is - j + 1 + joff) / (enr(j) * cbesf(j + is + joff))\n dnewb = -doldb * cbesf(is - j + 1 + joff) / (enr(j) * cbesf1(j + is + joff))\n if(iopt == 10) terma = dnewa\n if(iopt == 10) termb = dnewb\n if(iopt == 11) terma = dnewa * cbesf(j + is)\n if(iopt == 11) termb = dnewb * cbesf1(j + is)\n if(iopt == 21) terma = dnewa * cbesf(j + is)\n if(iopt == 21) termb = -dnewb * cbesf1(j + is)\n if(iopt == 20) terma = dnewa\n if(iopt == 20) termb = -dnewb\n term = terma + termb\n if(iopt == 10) termd1a = dnewa * cbesdr1(is - j + 2)\n if(iopt == 10) termd2a = dnewa * cbesdr(j + is)\n if(iopt == 10) termd1b = dnewb * cbesdr1(j + is)\n if(iopt == 10) termd2b = dnewb * cbesdr(is - j + 2)\n if(iopt == 20) termd1a = dnewa * cbesdr1(is - j + 3)\n if(iopt == 20) termd2a = dnewa * cbesdr(j + is + 1)\n if(iopt == 20) termd1b = -dnewb * cbesdr1(j + is + 1)\n if(iopt == 20) termd2b = -dnewb * cbesdr(is - j + 3)\n if(iopt == 11) termd1a = dnewa * cbesdr1(is - j + 2) * cbesf(j + is)\n if(iopt == 11) termd2a = dnewa * cbesdr(j + is + 1) * cbesf(j + is)\n if(iopt == 11) termd1b = dnewb * cbesdr1(j + is + 1) * cbesf1(j + is)\n if(iopt == 11) termd2b = dnewb * cbesdr(is - j + 2) * cbesf1(j + is)\n if(iopt == 21) termd1a = dnewa * cbesdr1(is - j + 2) * cbesf(j + is)\n if(iopt == 21) termd2a = dnewa * cbesdr(j + is + 1) * cbesf(j + is)\n if(iopt == 21) termd1b = -dnewb * cbesdr1(j + is + 1) * cbesf1(j + is)\n if(iopt == 21) termd2b = -dnewb * cbesdr(is - j + 2) * cbesf1(j + is)\n termd1 = termd1a + termd1b\n termd2 = termd2a + termd2b\n termd = -u1 * termd1 + u2 * termd2\n if(term > 0.0e0_knd) m1pos = m1pos + term\n if(termd > 0.0e0_knd) m1dpos = m1dpos + termd\n m1temp = m1temp + term\n m1dtemp = m1dtemp + termd\n if(m1temp * m1dtemp == 0.0e0_knd) go to 140\n if((abs(term / m1temp) + abs(termd / m1dtemp)) < dcon) go to 140\n dolda = dnewa\n doldb = dnewb\n130 continue\n140 nsub = 0\n if((m1temp * m1pos) /= 0.0e0_knd) nsub= &\n int(log10(abs(m1pos / m1temp)))\n if(nsub < 0) nsub = 0\n if(nsub > ndec) nsub = ndec\n if(m1temp == 0.0e0_knd .and. m1pos /= 0.0e0_knd) nsub = ndec\n nsubd = 0\n if((m1dtemp * m1dpos) /= 0.0e0_knd) nsubd= &\n int(log10(abs(m1dpos / m1dtemp)))\n if(nsubd < 0) nsubd = 0\n if(nsubd > ndec) nsubd = ndec\n if(m1dtemp == 0.0e0_knd .and. m1dpos /= 0.0e0_knd) nsubd = ndec\nif (debug) then\n if(iopcs == 1) write(40, 150) jbpe, lim, nsub, nsubd, is\n150 format(3x,'mc1/mc1d converged in ',i5,' of ',i5,' terms;', &\n ' sub. errors =',i3,' and',i3,' digits. s = ',i6)\n if(iopcs == 2) write(40, 160) jbpe, lim, nsub, nsubd, is\n160 format(3x,'ms1/ms1d converged in ',i5,' of ',i5,' terms;', &\n ' sub. errors =',i3,' and',i3,' digits. s = ',i6)\nend if\n if(nsub /= 0 .or. nsubd /= 0) then\n issinc = (nsub + nsubd) * (1.5 - min(0, int(3.0e0_knd * (log10(x1)))))+ &\n max(0, 2 * int(log10(cm)))\n if(l < 200 .and. cm > 1000.0e0_knd .and. x1 < 0.1e0_knd) &\n issinc = issinc * cm / 1000.0e0_knd\n iss = iss + issinc\n end if\n iterm = log10(abs(m1temp))\n m1temp = m1temp * 10.0e0_knd ** (-iterm)\n m1c = m1temp * coef / den\n if(is == 0) m1c = m1c / 2.0e0_knd\n im1e = im1temp + iterm + icoef - iden\n iterm = log10(abs(m1c))\n im1e = im1e + iterm\n m1c = m1c * 10.0e0_knd ** (-iterm)\n if(abs(m1c) >= 1.0e0_knd) go to 170\n m1c = m1c * 10.0e0_knd\n im1e = im1e - 1\n170 continue\n m1c = -m1c\n if(iopt == 10) m1c = -m1c\n if(ix == 1) m1c = -m1c\n if(2 * (is / 2) /= is) m1c = -m1c\n iterm = log10(abs(m1dtemp))\n m1dtemp = m1dtemp * 10.0e0_knd ** (-iterm)\n m1dc = m1dtemp * coef / den\n if(is == 0) m1dc = m1dc / 2.0e0_knd\n im1de = im1dtemp + iterm + icoef - iden\n iterm = log10(abs(m1dc))\n im1de = im1de + iterm\n m1dc = m1dc * 10.0e0_knd ** (-iterm)\n if(abs(m1dc) >= 1.0e0_knd) go to 180\n m1dc = m1dc * 10.0e0_knd\n im1de = im1de - 1\n180 continue\n m1dc = -m1dc\n if(iopt == 10) m1dc = -m1dc\n if(ix == 1) m1dc = -m1dc\n if(2 * (is / 2) /= is) m1dc = -m1dc\n return\n end subroutine\n!\n!\n subroutine m1bpe0 (iopcs, iss, ismax, l, cm, limbpe, ndec, limd, &\n maxd, enra, enrb, maxj, maxlp, nex, cbesf, cbesn, &\n ibese, cbesdf, cbesdr, a01, ia01, b12, ib12, jbpe, &\n nsub, m1c, im1e, m1dc, im1de)\n!\n! purpose : to calculate the Mathieu radial function of the\n! first kind and its first derivative with respect\n! to the traditional radial function z when q is negative\n! and xi = 0, using a series of products of modified\n! cylindrical Bessel functions of the first kind, with\n! the integer order offset s (is) of the Bessel function\n! for input as a free parameter\n!\n! parameters :\n!\n! input : iopcs : =1 if cosine radial functions calculated\n! : =2 if sine radial functions calculated\n! iss : integer offset minus l from calculation\n! for radial function of the same kind\n! (sine or cosine) for previous l\n! ismax : maxable allowable value for the integer offset\n! l : l\n! cm : magnitude of c (c being positive imaginary)\n! limbpe : twice the maximum number of terms available\n! ndec : number of decimal digits available in\n! real(knd) arithmetic\n! limd : number of a and b coefficient ratios that have\n! been calculated for this case\n! maxd : dimension of enra and enrb vectors\n! enra : vector of a coefficient ratios\n! enrb : vector of b coefficient ratios\n! maxj : dimension of cbesf, cbesdf, and cbesdr vectors\n! maxlp : dimension of cbesn and ibese vectors\n! nex : largest integer exponent abvailable in\n! real(knd) arithmetic\n! cbesf : vector of ratios of cylindrical Bessel\n! functions of the first kind with argument\n! c/2\n! cbesn : vector of characteristics of these Bessel\n! functions\n! ibese : vector of exponents of these Bessel functions\n! cbesdf : vector of ratios of first derivatives of\n! these Bessel functions\n! cbesdr : vector of ratios of first derivatives of\n! these Bessel functions to the corresponding\n! Bessel functions\n! a01 : characteristic of the first a coefficient\n! ia01 : exponent of the first a coefficient\n! b12 : characteristic of the first b coefficient\n! ib12 : exponent of the first b coefficient\n!\n! output : jbpe : twice the maximum number of terms taken\n! nsub : maximum number of digits of subtraction\n! error encountered in the calculation of\n! the function and its first derivative\n! m1c : characteristic of Mathieu radial function\n! of the first kind.\n! im1e : exponent of Mathieu radial function of the\n! first kind\n! m1dc : characteristic of derivative with respect\n! to x of Mathieu radial function of the first\n! kind\n! im1de : exponent of derivative with respect to x of\n! Mathieu radial function of the first kind\n!\n use param\n!\n! real(knd) scalars and vectors\n real(knd) a01, b12, cm, coef, dcon, den, dnew, dold, dolds, m1bot, m1c, &\n m1dc, m1dpos, m1dtemp, m1pos, m1temp, term, termd, termda, &\n termdb, teste, testeo, u\n real(knd) enr(maxd), enra(maxd), enrb(maxd), cbesdf(maxj), &\n cbesdr(maxj), cbesf(maxj), cbesn(maxlp)\n!\n! integer vectors\n dimension ibese(maxlp)\n!\n! convergence ratio dcon is set according to the number of decimal\n! digits available\n dcon = 10.0e0_knd ** (-ndec - 2)\n u = 0.5e0_knd * cm\n l2 = l / 2\n!\n! ix=0 for l even, ix=1 for l odd\n ix = l - 2 * l2\n ics = ix\n if(iopcs == 2) ics = iabs(ix - 1)\n if(iopcs == 1 .and. ix == 0) iopt = 10\n if(iopcs == 1 .and. ix == 1) iopt = 11\n if(iopcs == 2 .and. ix == 0) iopt = 20\n if(iopcs == 2 .and. ix == 1) iopt = 21\n lim = limbpe / 2 - ix\n nfac = nex - ndec\n teste = 10.0e0_knd ** nfac\n testeo = 1.0e0_knd / teste\n im1dtemp = 0\n im1temp = 0\n joff = 0\n if(iopt == 20) joff = 1\n jlim = 1 + joff\n is = l + iss\n if(is > ismax) is = ismax\n lims = is + joff + 100 + int(cm / 10.0)\n limmax = max(lims, lim)\n if(limmax > limd - 1) limmax = limd - 1\n if(ics == 1) go to 20\n do 10 i = 1, limmax\n enr(i) = enra(i)\n10 continue\n m1bot = a01\n ibot = ia01\n go to 40\n20 do 30 i = 1, limmax\n enr(i) = enrb(i)\n30 continue\n m1bot = b12\n ibot = ib12\n40 continue\n den = m1bot\n iden = ibot\n if(is == 0) go to 60\n do 50 k = 1, is\n den = den * enr(k + joff)\n iterm = int(log10(abs(den)))\n den = den * (10.0e0_knd ** (-iterm))\n iden = iden + iterm\n50 continue\n60 continue\n!\n! compute radial function of the first kind m1\n!\n! forward summation of product series for m1 and m1d\n coef = cbesn(-l2 + is + 1 + joff) * cbesn(l2 + is + 1 + joff)\n icoef = ibese(-l2 + is + 1 + joff) + ibese(l2 + is + 1 + joff)\n dold = 1.0e0_knd\n dolds = dold\n if(iopcs == 2) go to 70\n if(iopt == 10) term = 1.0e0_knd\n if(iopt == 11) term = cbesf(l2 + is + 1)\n m1temp = dold * (term + term)\n m1pos = 0.0e0_knd\n if(m1temp > 0.0e0_knd) m1pos = m1temp\n go to 80\n70 if(iopt == 20) termda = cbesdr(is - l2 + 2)\n if(iopt == 20) termdb = -cbesdr(l2 + is + 2)\n if(iopt == 21) termda = cbesdr(is - l2 + 1) * cbesf(l2 + is + 1)\n if(iopt == 21) termdb = -cbesdr(l2 + is + 2) * cbesf(l2 + is + 1)\n termd = dold * (termda + termdb)\n m1dtemp = -u * (termd + termd)\n m1dpos = 0.e0_knd\n if(m1dtemp > 0.0e0_knd) m1dpos = m1dtemp\n80 jbpe = l2\n lflag = 0\n!\n! forward summation for is => j\n do 100 j = l2 + 1, is + joff\n dnew = -dold * enr(j) * cbesf(j + is + joff) / cbesf(is + joff - j + 1)\n if(iopcs == 2) go to 85\n if(iopt == 10) term = dnew\n if(iopt == 11) term = dnew * cbesf(j + is + 1)\n term = term + term\n if(term > 0.0e0_knd) m1pos = m1pos + term\n m1temp = m1temp + term\n if(m1temp == 0.0e0_knd) go to 120\n if(abs(term / m1temp) < dcon) go to 120\n if(abs(m1temp) < teste) go to 90\n m1temp = m1temp * testeo\n dnew = dnew * testeo\n dnew = dnew * testeo\n m1pos = m1pos * testeo\n im1temp = im1temp + nfac\n iflag = 1\n go to 90\n85 if(iopt == 20) termda = dnew * cbesdr(is - j + 2)\n if(iopt == 20) termdb = -dnew * cbesdr(j + is + 2)\n if(iopt == 21) termda = dnew * cbesdr(is - j + 1) * cbesf(j + is + 1)\n if(iopt == 21) termdb = -dnew * cbesdr(j + is + 2) * cbesf(j + is + 1)\n termd = termda + termdb\n termd = -u * (termd + termd)\n if(termd > 0.0e0_knd) m1dpos = m1dpos + termd\n m1dtemp = m1dtemp + termd\n if(m1dtemp == 0.0e0_knd) go to 120\n if(abs(termd / m1dtemp) < dcon) go to 120\n if(abs(m1dtemp) < teste) go to 90\n m1dtemp = m1dtemp * testeo\n m1dpos = m1dpos * testeo\n im1dtemp = im1dtemp + nfac\n lflag = 1\n90 dold = dnew\n100 continue\n!\n! forward summation for j > is\n do 110 j = is + joff + 1, lim\n dnew = -dold * enr(j) * cbesf(j - is - joff) * cbesf(j + is + joff)\n if(iopcs == 2) go to 105\n if(iopt == 10) term = dnew\n if(iopt == 11) term = dnew * cbesf(j + is + 1)\n term = term + term\n if(term > 0.0e0_knd) m1pos = m1pos + term\n m1temp = m1temp + term\n if(m1temp == 0.0e0_knd) go to 120\n if(abs(term / m1temp) < dcon) go to 120\n go to 110\n105 if(iopt == 20) termda = dnew * cbesdr(j - is)\n if(iopt == 20) termdb = -dnew * cbesdr(j + is + 2)\n if(iopt == 21) termda = dnew * cbesdr(j - is + 1) * cbesf(j + is + 1)\n if(iopt == 21) termdb = -dnew * cbesdr(j + is + 2) * cbesf(j + is + 1)\n termd = termda + termdb\n termd = -u * (termd + termd)\n if(termd > 0.0e0_knd) m1dpos = m1dpos + termd\n m1dtemp = m1dtemp + termd\n if(m1temp * m1dtemp == 0.0e0_knd) go to 120\n if(abs(termd / m1dtemp) < dcon) go to 120\n110 dold = dnew\n120 jbpe = j\n!\n! backward summation of product series for m1 and m1d\n if(l2 < jlim .or. lflag == 1) go to 140\n dold = dolds\n do 130 j = l2, jlim,-1\n dnew = -dold * cbesf(is - j + 1 + joff) / (enr(j) * cbesf(j + is + joff))\n if(iopcs == 2) go to 125\n if(iopt == 10) term = dnew\n if(iopt == 11) term = dnew * cbesf(j + is)\n term = term + term\n if(term > 0.0e0_knd) m1pos = m1pos + term\n m1temp = m1temp + term\n if(m1temp == 0.0e0_knd) go to 140\n if(abs(term / m1temp) < dcon) go to 140\n go to 130\n125 if(iopt == 20) termda = dnew * cbesdr(is - j + 3)\n if(iopt == 20) termdb = -dnew * cbesdr(j + is + 1)\n if(iopt == 21) termda = dnew * cbesdr(is - j + 2) * cbesf(j + is)\n if(iopt == 21) termdb = -dnew * cbesdr(j + is + 1) * cbesf(j + is)\n termd = termda + termdb\n termd = -u * (termd + termd)\n if(termd > 0.0e0_knd) m1dpos = m1dpos + termd\n m1dtemp = m1dtemp + termd\n if(m1dtemp == 0.0e0_knd) go to 140\n if(abs(termd / m1dtemp) < dcon) go to 140\n130 dold = dnew\n140 nsub = 0\n nsubd = 0\n if(iopcs == 2) go to 170\n if((m1temp * m1pos) /= 0.0e0_knd) nsub= &\n int(log10(abs(m1pos / m1temp)))\n if(nsub < 0) nsub = 0\n if(nsub > ndec) nsub = ndec\n if(m1temp == 0.0e0_knd .and. m1pos /= 0.0e0_knd) nsub = ndec\n iterm = log10(abs(m1temp))\n m1temp = m1temp * 10.0e0_knd ** (-iterm)\n m1c = m1temp * coef / den\n if(is == 0) m1c = m1c / 2.0e0_knd\n im1e = im1temp + iterm + icoef - iden\n iterm = log10(abs(m1c))\n im1e = im1e + iterm\n m1c = m1c * 10.0e0_knd ** (-iterm)\n if(abs(m1c) >= 1.0e0_knd) go to 150\n m1c = m1c * 10.0e0_knd\n im1e = im1e - 1\n150 continue\n m1c = -m1c\n if(iopt == 10) m1c = -m1c\n if(ix == 1) m1c = -m1c\n if(2 * (is / 2) /= is) m1c = -m1c\nif (debug) then\n write(40, 160) jbpe, lim, nsub, is\n160 format(3x,'mc1 converged in ',i5,' of ',i5,' terms;', &\n ' sub. errors =',i3,'. s = ',i6)\nend if\n m1dc = 0.0e0_knd\n im1de = 0\n go to 200\n170 nsubd = 0\n if((m1dtemp * m1dpos) /= 0.0e0_knd) nsubd= &\n int(log10(abs(m1dpos / m1dtemp)))\n if(nsubd < 0) nsubd = 0\n if(nsubd > ndec) nsubd = ndec\n if(m1dtemp == 0.0e0_knd .and. m1dpos /= 0.0e0_knd) nsubd = ndec\n iterm = log10(abs(m1dtemp))\n m1dtemp = m1dtemp * 10.0e0_knd ** (-iterm)\n m1dc = m1dtemp * coef / den\n if(is == 0) m1dc = m1dc / 2.0e0_knd\n im1de = im1dtemp + iterm + icoef - iden\n iterm = log10(abs(m1dc))\n im1de = im1de + iterm\n m1dc = m1dc * 10.0e0_knd ** (-iterm)\n if(abs(m1dc) >= 1.0e0_knd) go to 180\n m1dc = m1dc * 10.0e0_knd\n im1de = im1de - 1\n180 continue\n m1dc = -m1dc\n if(iopt == 10) m1dc = -m1dc\n if(ix == 1) m1dc = -m1dc\n if(2 * (is / 2) /= is) m1dc = -m1dc\n m1c = 0.0e0_knd\n im1e = 0\nif (debug) then\n write(40, 190) jbpe, lim, nsubd, is\n190 format(3x,'ms1d converged in ',i5,' of ',i5,' terms;', &\n ' sub. errors =',i3,'. s = ',i6)\nend if\n200 if(nsub == 0 .and. nsubd == 0) go to 210\n issinc = (nsub + nsubd) * (1.5 + 15) + max(0, 2 * int(log10(cm)))\n if(l < 20 .and. cm > 2000.0e0_knd) issinc= &\n issinc * cm / 2000.0e0_knd\n iss = iss + issinc\n210 continue\n return\n end subroutine\n!\n!\n subroutine m2bpe (iopcs, iss, l, c, x1, limbpe, ndec, maxd, enra, &\n enrb, maxj, maxlp, maxn, nex, cbesf, cbesn, ibese, &\n cbesdf, cbesdr, cneuf, cneun, ineue, cneudf, &\n cneudr, m2bot, ibot, jbpe, nsub, m2c, im2e, m2dc, &\n im2de)\n!\n! purpose : to calculate the Mathieu radial function of the\n! second kind and its first derivative with respect\n! to the traditional radial coordinate z, using a series\n! of products of cylindrical Bessel functions of the\n! first and second kinds, with the integer Bessel\n! function order offset s (is) for input as a free\n! parameter. c is real here.\n!\n! parameters :\n!\n! input : iopcs : =1 if cosine radial functions calculated\n! : =2 if sine radial functions calculated\n! iss : integer offset minus l from calculation\n! for radial function of the same kind\n! (sine or cosine) for previous l\n! l : l\n! c : c, c being a real positive number\n! x1 : xi-1\n! limbpe : twice maximum number of terms available\n! ndec : number of decimal digits available in\n! real(knd) arithmetic\n! maxd : dimension of enra and enrb vectors\n! enra : vector of a coefficient ratios\n! enrb : vector of b coefficient ratios\n! maxj : dimension of cbesf, cbesdf, cbesdr, cbesf1,\n! cbesdf1 and cbesdr1 vectors\n! maxlp : dimension of cbesn, ibese, cbesn1 and ibese1\n! vectors\n! maxn : dimension of cneuf, cneudf and cneudr vectors\n! nex : largest integer exponent abvailable in\n! real(knd) arithmetic\n! cbesf : vector of ratios of cylindrical Bessel\n! functions of the first kind with argument\n! c*[xi - sqrt(xi*xi - 1)]/2\n! cbesn : vector of characteristics of these Bessel\n! functions\n! ibese : vector of exponents of these Bessel functions\n! cbesdf : vector of ratios of first derivatives of\n! these Bessel functions\n! cbesdr : vector of ratios of first derivatives of\n! these Bessel functions to the corresponding\n! Bessel functions\n! cneuf : vector of ratios of cylindrical Bessel\n! functions of the second kind with argument\n! c*[xi + sqrt(xi*xi - 1)]/2\n! cneun : vector of characteristics of these Bessel\n! functions\n! ineue : vector of exponents of these Bessel functions\n! cneudf : vector of ratios of first derivatives of these\n! Bessel functions\n! cneudr : vector of ratios of first derivatives of\n! these Bessel functions to the corresponding\n! Bessel functions\n! m2bot : equal to a01, the characteristic of the first\n! a coefficient when iopcs =1 and equal to b12,\n! the characteristic of the first b coefficient\n! when iopcs =2\n! ibot : equal to ia01, the exponent of the first\n! a coefficient when iopcs =1 and equal to ib12,\n! the exponent of the first b coefficient\n! when iopcs =2\n!\n! output : jbpe : maximum number of terms taken\n! nsub : maximum number of digits of subtraction\n! error encountered in the calculation of\n! the function and its first derivative\n! m2c : characteristic of Mathieu radial function\n! of the second kind.\n! im2e : exponent of Mathieu radial function of the\n! second kind\n! m2dc : characteristic of derivative with respect\n! to x of Mathieu radial function of the second\n! kind\n! im2de : exponent of derivative with respect to x of\n! Mathieu radial function of the second kind\n!\n use param\n!\n! real(knd) scalars and vectors\n real(knd) c, coef, coefa, coefb, dcon, den, dnewa, dnewb, dolda, &\n doldas, doldb, doldbs, m2bot, m2c, m2dc, m2dpos, m2dtemp, &\n m2pos, m2temp, sqx2m1, term, terma, termb, termd, &\n termd1, termd1a, termd1b, termd2, termd2a, termd2b, teste, &\n testeo, u1, u2, xi, x1, x2m1\n real(knd) enr(maxd), enra(maxd), enrb(maxd), cbesdf(maxj), &\n cbesdr(maxj), cbesf(maxj), cbesn(maxlp), cneudf(maxn), &\n cneudr(maxn), cneuf(maxn), cneun(maxlp)\n!\n! integer vectors\n dimension ibese(maxlp), ineue(maxlp)\n!\n! convergence ratio dcon is set according to the number of decimal\n! digits available\n dcon = 10.0e0_knd ** (-ndec - 2)\n xi = x1 + 1.0e0_knd\n x2m1 = x1 * (x1 + 2.0e0_knd)\n sqx2m1 = sqrt(x2m1)\n u1 = 0.5e0_knd * c / (xi + sqx2m1)\n u2 = 0.5e0_knd * c * (xi + sqx2m1)\n l2 = l / 2\n!\n! ix=0 for l even, ix=1 for l odd\n ix = l - 2 * l2\n ics = ix\n if(iopcs == 2) ics = iabs(ix - 1)\n if(iopcs == 1 .and. ix == 0) iopt = 10\n if(iopcs == 1 .and. ix == 1) iopt = 11\n if(iopcs == 2 .and. ix == 0) iopt = 20\n if(iopcs == 2 .and. ix == 1) iopt = 21\n lim = limbpe / 2 - ix\n nexpt = nex - ndec\n nfac = 50\n teste = 10.0e0_knd ** (nex - 10)\n testeo = 10.0e0_knd ** (-nfac)\n im2dtemp = 0\n im2temp = 0\n if(iopcs == 2) go to 30\n do 20 i = 1, lim\n enr(i) = enra(i)\n20 continue\n go to 50\n30 do 40 i = 1, lim\n enr(i) = enrb(i)\n40 continue\n50 continue\n joff = 0\n if(iopt == 20) joff = 1\n jlim = 1 + joff\n den = m2bot\n iden = ibot\n if(iss > (l2 - joff)) iss = l2 - joff\n is = iss\n if(is == 0) go to 70\n do 60 k = 1, is\n den = den * enr(k + joff)\n iterm = int(log10(abs(den)))\n den = den * (10.0e0_knd ** (-iterm))\n60 iden = iden + iterm\n70 continue\n!\n! compute radial function of the second kind m2\n!\n! forward summation of product series for m2 and m2d\n coefa = cbesn(l2 - is + 1 - joff) * cneun(l2 + is + 1 + joff)\n inda = ibese(l2 - is + 1 - joff) + ineue(l2 + is + 1 + joff)\n coefb = cbesn(l2 + is + 1 + joff) * cneun(l2 - is + 1 - joff)\n indb = ibese(l2 + is + 1 + joff) + ineue(l2 - is + 1 - joff)\n if(inda < indb) go to 80\n coef = coefa\n icoef = inda\n dolda = 1.0e0_knd\n indexp = indb - inda\n if(indexp < -nexpt) then\n dolda = dolda * (10.0e0_knd ** (nexpt))\n indexp = indexp + nexpt\n icoef = icoef - nexpt\n end if\n if(indexp < -nexpt) then\n doldb = 0.0e0_knd\n else\n doldb = (coefb / coefa) * (10.0e0_knd ** (indexp))\n end if\n go to 90\n80 doldb = 1.0e0_knd\n dolda = (coefa / coefb) * (10.0e0_knd ** (inda - indb))\n coef = coefb\n icoef = indb\n90 if(is == 0 .and. iopt == 10) dolda = 0.5e0_knd * dolda\n if(is == 0 .and. iopt == 10) doldb = 0.5e0_knd * doldb\n doldas = dolda\n doldbs = doldb\n if(iopt == 10) terma = 1.0e0_knd\n if(iopt == 10) termb = 1.0e0_knd\n if(iopt == 11) terma = cneuf(l2 + is + 1)\n if(iopt == 11) termb = cbesf(l2 + is + 1)\n if(iopt == 21) terma = cneuf(l2 + is + 1)\n if(iopt == 21) termb = -cbesf(l2 + is + 1)\n if(iopt == 20) terma = 1.0e0_knd\n if(iopt == 20) termb = -1.0e0_knd\n m2temp = dolda * terma + doldb * termb\n if(iopt == 10) termd1a = cbesdr(l2 - is + 1)\n if(iopt == 10) termd2a = cneudr(l2 + is + 1)\n if(iopt == 10) termd1b = cbesdr(l2 + is + 1)\n if(iopt == 10) termd2b = cneudr(l2 - is + 1)\n if(iopt == 20) termd1a = cbesdr(l2 - is)\n if(iopt == 20) termd2a = cneudr(l2 + is + 2)\n if(iopt == 20) termd1b = -cbesdr(l2 + is + 2)\n if(iopt == 20) termd2b = -cneudr(l2 - is)\n if(iopt == 11) termd1a = cbesdr(l2 - is + 1) * cneuf(l2 + is + 1)\n if(iopt == 11) termd2a = cneudr(l2 + is + 2) * cneuf(l2 + is + 1)\n if(iopt == 11) termd1b = cbesdr(l2 + is + 2) * cbesf(l2 + is + 1)\n if(iopt == 11) termd2b = cneudr(l2 - is + 1) * cbesf(l2 + is + 1)\n if(iopt == 21) termd1a = cbesdr(l2 - is + 1) * cneuf(l2 + is + 1)\n if(iopt == 21) termd2a = cneudr(l2 + is + 2) * cneuf(l2 + is + 1)\n if(iopt == 21) termd1b = -cbesdr(l2 + is + 2) * cbesf(l2 + is + 1)\n if(iopt == 21) termd2b = -cneudr(l2 - is + 1) * cbesf(l2 + is + 1)\n termd1 = dolda * termd1a + doldb * termd1b\n termd2 = dolda * termd2a + doldb * termd2b\n m2dtemp = -u1 * termd1 + u2 * termd2\n m2pos = 0.0e0_knd\n if(m2temp > 0.0e0_knd) m2pos = m2temp\n m2dpos = 0.e0_knd\n if(m2dtemp > 0.0e0_knd) m2dpos = m2dtemp\n jbpe = l2\n do 100 j = l2 + 1, lim\n dnewa = -dolda * enr(j) * cbesf(j - is - joff) * cneuf(j + is + joff)\n dnewb = -doldb * enr(j) * cbesf(j + is + joff) * cneuf(j - is - joff)\n if(iopt == 10) terma = dnewa\n if(iopt == 10) termb = dnewb\n if(iopt == 11) terma = dnewa * cneuf(j + is + 1)\n if(iopt == 11) termb = dnewb * cbesf(j + is + 1)\n if(iopt == 21) terma = dnewa * cneuf(j + is + 1)\n if(iopt == 21) termb = -dnewb * cbesf(j + is + 1)\n if(iopt == 20) terma = dnewa\n if(iopt == 20) termb = -dnewb\n term = terma + termb\n if(iopt == 10) termd1a = dnewa * cbesdr(j - is + 1)\n if(iopt == 10) termd2a = dnewa * cneudr(j + is + 1)\n if(iopt == 10) termd1b = dnewb * cbesdr(j + is + 1)\n if(iopt == 10) termd2b = dnewb * cneudr(j - is + 1)\n if(iopt == 20) termd1a = dnewa * cbesdr(j - is)\n if(iopt == 20) termd2a = dnewa * cneudr(j + is + 2)\n if(iopt == 20) termd1b = -dnewb * cbesdr(j + is + 2)\n if(iopt == 20) termd2b = -dnewb * cneudr(j - is)\n if(iopt == 11) termd1a = dnewa * cbesdr(j - is + 1) * cneuf(j + is + 1)\n if(iopt == 11) termd2a = dnewa * cneudr(j + is + 2) * cneuf(j + is + 1)\n if(iopt == 11) termd1b = dnewb * cbesdr(j + is + 2) * cbesf(j + is + 1)\n if(iopt == 11) termd2b = dnewb * cneudr(j - is + 1) * cbesf(j + is + 1)\n if(iopt == 21) termd1a = dnewa * cbesdr(j - is + 1) * cneuf(j + is + 1)\n if(iopt == 21) termd2a = dnewa * cneudr(j + is + 2) * cneuf(j + is + 1)\n if(iopt == 21) termd1b = -dnewb * cbesdr(j + is + 2) * cbesf(j + is + 1)\n if(iopt == 21) termd2b = -dnewb * cneudr(j - is + 1) * cbesf(j + is + 1)\n termd1 = termd1a + termd1b\n termd2 = termd2a + termd2b\n termd = -u1 * termd1 + u2 * termd2\n if(term > 0.0e0_knd) m2pos = m2pos + term\n if(termd > 0.0e0_knd) m2dpos = m2dpos + termd\n m2temp = m2temp + term\n m2dtemp = m2dtemp + termd\n if(m2temp * m2dtemp == 0.0e0_knd) go to 110\n if((abs(term / m2temp) + abs(termd / m2dtemp)) < dcon) go to 110\n if(abs(m2temp) > teste .or. abs(m2dtemp) > teste) then\n m2temp = m2temp * testeo\n m2dtemp = m2dtemp * testeo\n dnewa = dnewa * testeo\n dnewb = dnewb * testeo\n m2pos = m2pos * testeo\n m2dpos = m2dpos * testeo\n doldas = doldas * testeo\n doldbs = doldbs * testeo\n im2temp = im2temp + nfac\n im2dtemp = im2dtemp + nfac\n end if\n dolda = dnewa\n doldb = dnewb\n100 continue\n110 jbpe = j\n!\n! backward summation of m2 product series (terms with j > is)\n if (l2 == 0) go to 170\n dolda = doldas\n doldb = doldbs\n jlim1 = jlim + is\n if(jlim1 > l2) go to 140\n do 130 j = l2, jlim1,-1\n dnewa = -dolda / (enr(j) * cbesf(j - is - joff) * cneuf(j + is + joff))\n dnewb = -doldb / (enr(j) * cbesf(j + is + joff) * cneuf(j - is - joff))\n if(iopt == 10) terma = dnewa\n if(iopt == 10) termb = dnewb\n if(iopt == 11) terma = dnewa * cneuf(j + is)\n if(iopt == 11) termb = dnewb * cbesf(j + is)\n if(iopt == 21) terma = dnewa * cneuf(j + is)\n if(iopt == 21) termb = -dnewb * cbesf(j + is)\n if(iopt == 20) terma = dnewa\n if(iopt == 20) termb = -dnewb\n term = terma + termb\n if(iopt == 10) termd1a = dnewa * cbesdr(j - is)\n if(iopt == 10) termd2a = dnewa * cneudr(j + is)\n if(iopt == 10) termd1b = dnewb * cbesdr(j + is)\n if(iopt == 10) termd2b = dnewb * cneudr(j - is)\n if(iopt == 20) termd1a = dnewa * cbesdr(j - is - 1)\n if(iopt == 20) termd2a = dnewa * cneudr(j + is + 1)\n if(iopt == 20) termd1b = -dnewb * cbesdr(j + is + 1)\n if(iopt == 20) termd2b = -dnewb * cneudr(j - is - 1)\n if(iopt == 11) termd1a = dnewa * cbesdr(j - is) * cneuf(j + is)\n if(iopt == 11) termd2a = dnewa * cneudr(j + is + 1) * cneuf(j + is)\n if(iopt == 11) termd1b = dnewb * cbesdr(j + is + 1) * cbesf(j + is)\n if(iopt == 11) termd2b = dnewb * cneudr(j - is) * cbesf(j + is)\n if(iopt == 21) termd1a = dnewa * cbesdr(j - is) * cneuf(j + is)\n if(iopt == 21) termd2a = dnewa * cneudr(j + is + 1) * cneuf(j + is)\n if(iopt == 21) termd1b = -dnewb * cbesdr(j + is + 1) * cbesf(j + is)\n if(iopt == 21) termd2b = -dnewb * cneudr(j - is) * cbesf(j + is)\n termd1 = termd1a + termd1b\n termd2 = termd2a + termd2b\n termd = -u1 * termd1 + u2 * termd2\n if(term > 0.0e0_knd) m2pos = m2pos + term\n if(termd > 0.0e0_knd) m2dpos = m2dpos + termd\n m2temp = m2temp + term\n m2dtemp = m2dtemp + termd\n if(m2temp * m2dtemp == 0.0e0_knd) go to 140\n if((abs(term / m2temp) + abs(termd / m2dtemp)) < dcon) go to 140\n if(abs(m2temp) > teste .or. abs(m2dtemp) > teste) then\n m2temp = m2temp * testeo\n m2dtemp = m2dtemp * testeo\n dnewa = dnewa * testeo\n dnewb = dnewb * testeo\n m2pos = m2pos * testeo\n m2dpos = m2dpos * testeo\n im2temp = im2temp + nfac\n im2dtemp = im2dtemp + nfac\n end if\n120 dolda = dnewa\n doldb = dnewb\n130 continue\n140 continue\n! backward summation of m2 product series (terms with j <= is)\n if(is == 0) go to 170\n jlow = jlim1 - 1\n if(jlim1 > l2) jlow = l2\n do 160 j = jlow, jlim,-1\n dnewa = dolda * cbesf(is - j + 1 + joff) / (enr(j) * cneuf(j + is + joff))\n dnewb = doldb * cneuf(is - j + 1 + joff) / (enr(j) * cbesf(j + is + joff))\n if(iopt == 10) terma = dnewa\n if(iopt == 10) termb = dnewb\n if(iopt == 11) terma = dnewa * cneuf(j + is)\n if(iopt == 11) termb = dnewb * cbesf(j + is)\n if(iopt == 21) terma = dnewa * cneuf(j + is)\n if(iopt == 21) termb = -dnewb * cbesf(j + is)\n if(iopt == 20) terma = dnewa\n if(iopt == 20) termb = -dnewb\n term = terma + termb\n if(iopt == 10) termd1a = dnewa * cbesdr(is - j + 2)\n if(iopt == 10) termd2a = dnewa * cneudr(j + is)\n if(iopt == 10) termd1b = dnewb * cbesdr(j + is)\n if(iopt == 10) termd2b = dnewb * cneudr(is - j + 2)\n if(iopt == 20) termd1a = dnewa * cbesdr(is - j + 3)\n if(iopt == 20) termd2a = dnewa * cneudr(j + is + 1)\n if(iopt == 20) termd1b = -dnewb * cbesdr(j + is + 1)\n if(iopt == 20) termd2b = -dnewb * cneudr(is - j + 3)\n if(iopt == 11) termd1a = dnewa * cbesdr(is - j + 2) * cneuf(j + is)\n if(iopt == 11) termd2a = dnewa * cneudr(j + is + 1) * cneuf(j + is)\n if(iopt == 11) termd1b = dnewb * cbesdr(j + is + 1) * cbesf(j + is)\n if(iopt == 11) termd2b = dnewb * cneudr(is - j + 2) * cbesf(j + is)\n if(iopt == 21) termd1a = dnewa * cbesdr(is - j + 2) * cneuf(j + is)\n if(iopt == 21) termd2a = dnewa * cneudr(j + is + 1) * cneuf(j + is)\n if(iopt == 21) termd1b = -dnewb * cbesdr(j + is + 1) * cbesf(j + is)\n if(iopt == 21) termd2b = -dnewb * cneudr(is - j + 2) * cbesf(j + is)\n termd1 = termd1a + termd1b\n termd2 = termd2a + termd2b\n termd = -u1 * termd1 + u2 * termd2\n if(term > 0.0e0_knd) m2pos = m2pos + term\n if(termd > 0.0e0_knd) m2dpos = m2dpos + termd\n m2temp = m2temp + term\n m2dtemp = m2dtemp + termd\n if(m2temp * m2dtemp == 0.0e0_knd) go to 170\n if((abs(term / m2temp) + abs(termd / m2dtemp)) < dcon) go to 170\n if(abs(m2temp) > teste .or. abs(m2dtemp) > teste) then\n m2temp = m2temp * testeo\n m2dtemp = m2dtemp * testeo\n dnewa = dnewa * testeo\n dnewb = dnewb * testeo\n m2pos = m2pos * testeo\n m2dpos = m2dpos * testeo\n im2temp = im2temp + nfac\n im2dtemp = im2dtemp + nfac\n end if\n150 dolda = dnewa\n doldb = dnewb\n160 continue\n170 nsub = 0\n if((m2temp * m2pos) /= 0.0e0_knd) nsub= &\n int(log10(abs(m2pos / m2temp)))\n if(nsub < 0) nsub = 0\n if(nsub > ndec) nsub = ndec\n if(m2temp == 0.0e0_knd .and. m2pos /= 0.0e0_knd) nsub = ndec\n nsubd = 0\n if((m2dtemp * m2dpos) /= 0.0e0_knd) nsubd= &\n int(log10(abs(m2dpos / m2dtemp)))\n if(nsubd < 0) nsubd = 0\n if(nsubd > ndec) nsubd = ndec\n if(m2dtemp == 0.0e0_knd .and. m2dpos /= 0.0e0_knd) nsubd = ndec\nif (debug) then\n if(iopcs == 1) write(40, 180) jbpe, lim, nsub, nsubd, is\n180 format(3x,'mc2/mc2d converged in ',i5,' of ',i5,' terms;', &\n ' sub. errors =',i3,' and',i3,' digits. s = ',i6)\n if(iopcs == 2) write(40, 190) jbpe, lim, nsub, nsubd, is\n190 format(3x,'ms2/ms2d converged in ',i5,' of ',i5,' terms;', &\n ' sub. errors =',i3,' and',i3,' digits. s = ',i6)\nend if\n iss = is\n llim1 = int(0.6e0_knd * c)\n llim2 = int(2.0e0_knd * c / 3.1416)\n if((nsub > 2 .and. nsubd > 2) .and. l >= llim1) &\n iss = is + max(2, int(abs(log10(c))))\n if((nsub > 0 .and. nsubd > 0) .and. l >= llim2) &\n iss = is + max(2, int(abs(log10(c))))\n iterm = log10(abs(m2temp))\n m2temp = m2temp * 10.0e0_knd ** (-iterm)\n m2c = m2temp * coef / den\n im2e = im2temp + iterm + icoef - iden\n iterm = log10(abs(m2c))\n im2e = im2e + iterm\n m2c = m2c * 10.0e0_knd ** (-iterm)\n if(abs(m2c) >= 1.0e0_knd) go to 200\n m2c = m2c * 10.0e0_knd\n im2e = im2e - 1\n200 continue\n iterm = log10(abs(m2dtemp))\n m2dtemp = m2dtemp * 10.0e0_knd ** (-iterm)\n m2dc = m2dtemp * coef / den\n im2de = im2dtemp + iterm + icoef - iden\n iterm = log10(abs(m2dc))\n im2de = im2de + iterm\n m2dc = m2dc * 10.0e0_knd ** (-iterm)\n if(abs(m2dc) >= 1.0e0_knd) go to 210\n m2dc = m2dc * 10.0e0_knd\n im2de = im2de - 1\n210 continue\n return\n end subroutine\n!\n!\n subroutine m3bpe (iopcs, l, cm, x1, limbpe, ndec, maxd, enra, enrb, &\n maxj, maxlp, maxn, nex, cbesf, cbesn, ibese, &\n cbesdf, cbesdr, cneuf, cneun, ineue, cneudf, &\n cneudr, a01, ia01, b12, ib12, pi, jbpe, nsub, &\n m3c, im3e, m3dc, im3de)\n!\n! purpose : to calculate the Mathieu radial function of the\n! third kind and its first derivative with respect\n! to the traditional radial coordinate z, for the\n! case where q is negative, using a series of products\n! of modified cylindrical Bessel functions of the first\n! and second kinds\n!\n! parameters :\n!\n! input : iopcs : =1 if cosine radial functions calculated\n! : =2 if sine radial functions calculated\n! l : l\n! cm : magnitude of c (c being positive imaginary)\n! x1 : xi-1\n! limbpe : twice maximum number of terms available\n! ndec : number of decimal digits available in\n! real(knd) arithmetic\n! maxd : dimension of enra and enrb vectors\n! enra : vector of a coefficient ratios\n! enrb : vector of b coefficient ratios\n! maxj : dimension of cbesf, cbesdf and cbesdr vectors\n! maxlp : dimension of cbesn, ibese, cneun and ineue\n! vectors\n! maxn : dimension of cneuf, cneudf and cneudr vectors\n! nex : largest integer exponent abvailable in\n! real(knd) arithmetic\n! cbesf : vector of ratios of modified cylindrical Bessel\n! functions of the first kind with argument\n! c*[xi - sqrt(xi*xi - 1)]/2\n! cbesn : vector of characteristics of these Bessel\n! functions\n! ibese : vector of exponents of these Bessel functions\n! cbesdf : vector of ratios of first derivatives of\n! these Bessel functions\n! cbesdr : vector of ratios of first derivatives of\n! these Bessel functions to the corresponding\n! Bessel functions\n! cneuf : vector of ratios of modified cylindrical Bessel\n! functions of the second kind with argument\n! c*[xi + sqrt(xi*xi - 1)]/2\n! cneun : vector of characteristics of these Bessel\n! functions\n! ineue : vector of exponents of these Bessel functions\n! cneudf : vector of ratios of first derivatives of these\n! Bessel functions\n! cneudr : vector of ratios of first derivatives of\n! these Bessel functions to the corresponding\n! Bessel functions\n! a01 : characteristic of the first a coefficient\n! ia01 : exponent of the first a coefficient\n! b12 : characteristic of the first b coefficient\n! ib12 : exponent of the first b coefficient\n! pi : 3.14...\n!\n! output : jbpe : maximum number of terms taken\n! nsub : maximum number of digits of subtraction\n! error encountered in the calculation of\n! the function and its first derivative\n! m3c : characteristic of Mathieu radial function\n! of the third kind [note that when l is even,\n! the Mathieu radial function of the third kind\n! is equal to i times m3c times 10**(im3e)]\n! im3e : exponent of Mathieu radial function of the\n! third kind\n! m3dc : characteristic of derivative with respect\n! to x of Mathieu radial function of the third\n! kind (see note above for m3c)\n! im3de : exponent of derivative with respect to x of\n! Mathieu radial function of the third kind\n!\n use param\n!\n! real(knd) scalars and vectors\n real(knd) a01, b12, cm, dcon, dnew, dold, m3bot, m3c, m3dc, &\n m3dtemp, m3dpos, m3pos, m3temp, pi, sqx2m1, term, termd, &\n termd1, termd2, teste, testeo, u1, u2, xi, x1, x2m1\n real(knd) enr(maxd), enra(maxd), enrb(maxd), cbesdf(maxj), &\n cbesdr(maxj), cbesf(maxj), cbesn(maxlp), cneudf(maxn), &\n cneudr(maxn), cneuf(maxn), cneun(maxlp)\n!\n! integer vectors\n dimension ibese(maxlp), ineue(maxlp)\n!\n! convergence ratio dcon is set according to the number of decimal\n! digits available\n dcon = 10.0e0_knd ** (-ndec - 2)\n xi = x1 + 1.0e0_knd\n x2m1 = x1 * (x1 + 2.0e0_knd)\n sqx2m1 = sqrt(x2m1)\n u1 = 0.5e0_knd * cm / (xi + sqx2m1)\n u2 = 0.5e0_knd * cm * (xi + sqx2m1)\n l2 = l / 2\n!\n! ix=0 for l even, ix=1 for l odd\n ix = l - 2 * l2\n! lx2=0 for l2 even, lx2=1 for l2 odd\n lx2 = l2 - 2 * (l2 / 2)\n ics = ix\n if(iopcs == 2) ics = iabs(ix - 1)\n if(iopcs == 1 .and. ix == 0) iopt = 10\n if(iopcs == 1 .and. ix == 1) iopt = 11\n if(iopcs == 2 .and. ix == 0) iopt = 20\n if(iopcs == 2 .and. ix == 1) iopt = 21\n lim = limbpe / 2 - ix\n nfac = nex - ndec\n teste = 10.0e0_knd ** nfac\n testeo = 1.0e0_knd / teste\n im3dtemp = 0\n im3temp = 0\n if(ics == 1) go to 20\n do 10 i = 1, lim\n enr(i) = enra(i)\n10 continue\n m3bot = a01\n ibot = ia01\n go to 40\n20 do 30 i = 1, lim\n enr(i) = enrb(i)\n30 continue\n m3bot = b12\n ibot = ib12\n40 continue\n!\n!\n! compute radial function of the third kind m3\n!\n! forward summation of product series for m3 and m3d\n m3pos = 0.0e0_knd\n m3dpos = 0.0e0_knd\n dold = 1.0e0_knd\n m3temp = 1.0e0_knd\n if(iopt == 11) m3temp = cneuf(l2 + 1) - cbesf(l2 + 1)\n if(iopt == 21) m3temp = cneuf(l2 + 1) + cbesf(l2 + 1)\n if(iopt == 20) m3temp = cbesf(l2 + 1) / cneuf(l2)- &\n cneuf(l2 + 1) / cbesf(l2)\n if(iopt == 10) termd1 = cbesdr(l2 + 1)\n if(iopt == 11) termd1 = cbesdr(l2 + 1) * cneuf(l2 + 1)- &\n cbesdr(l2 + 2) * cbesf(l2 + 1)\n if(iopt == 21) termd1 = cbesdr(l2 + 1) * cneuf(l2 + 1)+ &\n cbesdr(l2 + 2) * cbesf(l2 + 1)\n if(iopt == 20) termd1 = -cbesdr(l2) * cneuf(l2 + 1)/ &\n cbesf(l2) + cbesdr(l2 + 2)* &\n cbesf(l2 + 1) / cneuf(l2)\n if(iopt == 10) termd2 = cneudr(l2 + 1)\n if(iopt == 11) termd2 = cneudr(l2 + 2) * cneuf(l2 + 1)- &\n cneudr(l2 + 1) * cbesf(l2 + 1)\n if(iopt == 21) termd2 = cneudr(l2 + 2) * cneuf(l2 + 1)+ &\n cneudr(l2 + 1) * cbesf(l2 + 1)\n if(iopt == 20) termd2 = -cneudr(l2 + 2) * cneuf(l2 + 1)/ &\n cbesf(l2) + cneudr(l2)* &\n cbesf(l2 + 1) / cneuf(l2)\n m3dtemp = -u1 * termd1 + u2 * termd2\n if(m3temp > 0.0e0_knd) m3pos = m3temp\n if(m3dtemp > 0.0e0_knd) m3dpos = m3dtemp\n jbpe = l2\n do 50 j = l2 + 1, lim\n dnew = dold * enr(j) * cbesf(j) * cneuf(j)\n if(iopt == 10) term = dnew\n if(iopt == 11) term = dnew * (-cbesf(j + 1) + cneuf(j + 1))\n if(iopt == 21) term = dnew * (cbesf(j + 1) + cneuf(j + 1))\n if(iopt == 20) term = dnew * (-cneuf(j + 1) / cbesf(j)+ &\n cbesf(j + 1) / cneuf(j))\n if(iopt == 10) termd1 = dnew * cbesdr(j + 1)\n if(iopt == 11) termd1 = dnew * (cbesdr(j + 1) * cneuf(j + 1) &\n -cbesdr(j + 2) * cbesf(j + 1))\n if(iopt == 21) termd1 = dnew * (cbesdr(j + 1) * cneuf(j + 1) &\n +cbesdr(j + 2) * cbesf(j + 1))\n if(iopt == 20) termd1 = dnew * (-cbesdr(j) * cneuf(j + 1)/ &\n cbesf(j) + cbesdr(j + 2)* &\n cbesf(j + 1) / cneuf(j))\n if(iopt == 10) termd2 = dnew * cneudr(j + 1)\n if(iopt == 11) termd2 = dnew * (cneudr(j + 2) * cneuf(j + 1) &\n -cneudr(j + 1) * cbesf(j + 1))\n if(iopt == 21) termd2 = dnew * (cneudr(j + 2) * cneuf(j + 1) &\n +cneudr(j + 1) * cbesf(j + 1))\n if(iopt == 20) termd2 = dnew * (-cneudr(j + 2)* &\n cneuf(j + 1) / cbesf(j)+ &\n cneudr(j) * cbesf(j + 1)/ &\n cneuf(j))\n termd = -u1 * termd1 + u2 * termd2\n if(term > 0.0e0_knd) m3pos = m3pos + term\n if(termd > 0.0e0_knd) m3dpos = m3dpos + termd\n m3temp = m3temp + term\n m3dtemp = m3dtemp + termd\n if(m3temp * m3dtemp == 0.0e0_knd) go to 60\n if((abs(term / m3temp) + abs(termd / m3dtemp)) < dcon) go to 60\n dold = dnew\n50 continue\n60 jbpe = j\n!\n! backward summation of product series for m3\n if (l2 == 0) go to 90\n dold = 1.0e0_knd\n jlim = 1\n if(iopcs == 2 .and. ix == 0) jlim = 2\n if(l2 < jlim) go to 90\n do 80 j = l2, jlim,-1\n dnew = dold / (enr(j) * cbesf(j) * cneuf(j))\n if(iopt == 10) term = dnew\n if(iopt == 11) term = dnew * (-cbesf(j) + cneuf(j))\n if(iopt == 21) term = dnew * (cbesf(j) + cneuf(j))\n if(iopt == 20) term = dnew * (-cneuf(j) / cbesf(j - 1)+ &\n cbesf(j) / cneuf(j - 1))\n if(iopt == 10) termd1 = dnew * cbesdr(j)\n if(iopt == 11) termd1 = dnew * (cbesdr(j) * cneuf(j) &\n -cbesdr(j + 1) * cbesf(j))\n if(iopt == 21) termd1 = dnew * (cbesdr(j) * cneuf(j) &\n +cbesdr(j + 1) * cbesf(j))\n if(iopt == 20) termd1 = dnew * (-cbesdr(j - 1) * cneuf(j)/ &\n cbesf(j - 1) + cbesdr(j + 1)* &\n cbesf(j) / cneuf(j - 1))\n if(iopt == 10) termd2 = dnew * cneudr(j)\n if(iopt == 11) termd2 = dnew * (cneudr(j + 1) * cneuf(j) &\n -cneudr(j) * cbesf(j))\n if(iopt == 21) termd2 = dnew * (cneudr(j + 1) * cneuf(j) &\n +cneudr(j) * cbesf(j))\n if(iopt == 20) termd2 = dnew * (-cneudr(j + 1) * cneuf(j)/ &\n cbesf(j - 1) + cneudr(j - 1)* &\n cbesf(j) / cneuf(j - 1))\n termd = -u1 * termd1 + u2 * termd2\n if(term > 0.0e0_knd) m3pos = m3pos + term\n if(termd > 0.0e0_knd) m3dpos = m3dpos + termd\n m3temp = m3temp + term\n m3dtemp = m3dtemp + termd\n if(m3temp * m3dtemp == 0.0e0_knd) go to 90\n if((abs(term / m3temp) + abs(termd / m3dtemp)) < dcon) go to 90\n if(abs(m3temp) > teste .or. abs(m3dtemp) > teste) then\n m3temp = m3temp * testeo\n m3dtemp = m3dtemp * testeo\n dnew = dnew * testeo\n m3pos = m3pos * testeo\n m3dpos = m3dpos * testeo\n im3temp = im3temp + nfac\n im3dtemp = im3dtemp + nfac\n end if\n70 dold = dnew\n80 continue\n90 nsub = 0\n if((m3temp * m3pos) /= 0.0e0_knd) nsub= &\n int(log10(abs(m3pos / m3temp)))\n if(nsub < 0) nsub = 0\n if(nsub > ndec) nsub = ndec\n if(m3temp == 0.0e0_knd .and. m3pos /= 0.0e0_knd) nsub = ndec\n nsubd = 0\n if((m3dtemp * m3dpos) /= 0.0e0_knd) nsubd= &\n int(log10(abs(m3dpos / m3dtemp)))\n if(nsubd < 0) nsubd = 0\n if(nsubd > ndec) nsubd = ndec\n if(m3dtemp == 0.0e0_knd .and. m3dpos /= 0.0e0_knd) nsubd = ndec\n nsub = max(nsub, nsubd)\nif (debug) then\n if(iopcs == 1) write(40, 100) jbpe, lim, nsub\n100 format(3x,'mc3 numerator converged in ',i5,' terms; ',i5, &\n ' available; sub. error = ',i3,' digits.')\n if(iopcs == 2) write(40, 110) jbpe, lim, nsub\n110 format(3x,'ms3 numerator converged in ',i5,' terms; ',i5, &\n ' available; sub. error = ',i3,' digits.')\nend if\n iterm = log10(abs(m3temp))\n m3temp = m3temp * 10.0e0_knd ** (-iterm)\n m3c = 2.0e0_knd * m3temp * cbesn(l2 + 1) * cneun(l2 + 1) / (m3bot * pi)\n im3e = im3temp + iterm + ibese(l2 + 1) + ineue(l2 + 1) - ibot\n iterm = 0\n if(m3c /= 0.0e0_knd) iterm = int(log10(abs(m3c)))\n im3e = im3e + iterm\n m3c = m3c * 10.0e0_knd ** (-iterm)\n if(abs(m3c) >= 1.0e0_knd) go to 120\n m3c = m3c * 10.0e0_knd\n im3e = im3e - 1\n120 continue\n iterm = log10(abs(m3dtemp))\n m3dtemp = m3dtemp * 10.0e0_knd ** (-iterm)\n m3dc = 2.0e0_knd * m3dtemp * cbesn(l2 + 1) * cneun(l2 + 1) / (m3bot * pi)\n im3de = im3dtemp + iterm + ibese(l2 + 1) + ineue(l2 + 1) - ibot\n iterm = 0\n if(m3dc /= 0.0e0_knd) iterm = int(log10(abs(m3dc)))\n im3de = im3de + iterm\n m3dc = m3dc * 10.0e0_knd ** (-iterm)\n if(abs(m3dc) >= 1.0e0_knd) go to 130\n m3dc = m3dc * 10.0e0_knd\n im3de = im3de - 1\n130 continue\n if(lx2 == 0) m3c = -m3c\n if(lx2 == 0) m3dc = -m3dc\n if(iopt == 20) m3c = -m3c\n if(iopt == 20) m3dc = -m3dc\n return\n end subroutine\n!\n!\n subroutine m3neu (iopcs, l, cm, x1, limneu, ndec, minacc, maxd, &\n enra, enrb, maxn, maxlp, nex, cneuf, cneun, ineue, &\n cneudf, cneudr, m3bot, pi, jneu, ndig, m3c, &\n im3e, m3dc, im3de, jtermflag)\n!\n! purpose : to calculate the Mathieu radial function of the\n! third kind (q negative) and its first derivative\n! with respect to the traditional radial coordinate\n! z, using an expansion of modified cylindrical Bessel\n! functions of the second kind with argument c*xi.\n!\n! parameters :\n!\n! input : iopcs : =1 if cosine radial functions calculated\n! : =2 if sine radial functions calculated\n! l : l\n! cm : magnitude of c (c being positive imaginary)\n! x1 : xi-1\n! limneu : twice maximum number of terms available\n! ndec : number of decimal digits available in\n! real(knd) arithmetic\n! minacc : desired minimum accuracy of the calculated\n! functions, in decimal digits\n! maxd : size of enr vector\n! enra : a coefficient ratios\n! enrb : b coefficient ratios\n! maxn : size of cneuf, cneudf and cneudr vectors\n! maxlp : maximum l value desired; size of the cneun and\n! ineue vectors\n! nex : largest integer exponent abvailable in\n! real(knd) arithmetic\n! cneuf : ratios of cylindrical Bessel functions of the\n! second kind\n! cneun : vector of characteristics of the Bessel\n! functions\n! ineue : vector of exponents of the Bessel functions\n! cneudf : ratios of first derivatives of the cylindrical\n! Bessel functions\n! cneudr : ratios of first derivatives of the cylindrical\n! Bessel functions to the corresponding Bessel\n! functions\n! m3bot : denominator series sum. when q is positive, it\n! is calculated in dnorma as ce0 when\n! iopcs = 1 or in dnormb as sed0 when\n! iopcs = 2. when q is negative it is calculated\n! as the denominator series in the calculation\n! of m1 in subroutine mcs1bes\n! pi : pi\n!\n! output : jneu : maximum number of terms taken\n! ndig : minimum number of digits of convergence of\n! series\n! m3c : characteristic of Mathieu radial function\n! of the second kind.\n! im3e : exponent of Mathieu radial function of the\n! second kind [note that when q is negative\n! (isq=-1) the modified Mathieu function m2 =\n! i times m1c times 10**(im1e), where i is the\n! square root of -1.]\n! m3dc : characteristic of derivative with respect\n! to x of Mathieu radial function of the second\n! kind\n! im3de : exponent of derivative with respect to x of\n! Mathieu radial function of the second kind\n! [note that when q is negative (isq=-1) the\n! modified Mathieu function derivative m2d =\n! i times m1dc times 10**(im1de), where i is the\n! square root of -1.]\n!\n use param\n!\n! real(knd) scalars and vectors\n real(knd) cm, con, dcon, dk, dnew, dnewd, dold, doldd, m3bot, m3c, m3dc, &\n m3dtemp, m3temp, m3top, pi, sqx2m1, sscale, stest, term, &\n termd, xi, x1, x2m1\n real(knd) enr(maxd), enra(maxd), enrb(maxd), cneudf(maxn), &\n cneudr(maxn), cneuf(maxn), cneun(maxlp)\n!\n! integer vector\n dimension ineue(maxlp)\n!\n! convergence ratio dcon is set according to the desired accuracy\n! and the approximate number of terms expected to be taken in the\n! series\n ncon = max(1,-int(log10(x1)))\n dcon = 10.0e0_knd ** (-minacc - 1 - ncon)\n xi = x1 + 1.0e0_knd\n x2m1 = x1 * (x1 + 2.0e0_knd)\n sqx2m1 = sqrt(x2m1)\n nex2 = nex / 2\n stest = 10.0e0_knd ** nex2\n sscale = 10.0e0_knd ** (-nex2)\n iscale = 0\n l2 = l / 2\n!\n! ix=0 for l even, ix=1 for l odd\n ix = l - 2 * l2\n ics = ix\n if(iopcs == 2) ics = iabs(ix - 1)\n jlim = 1\n if(ix == 0 .and. iopcs == 2) jlim = 2\n lim = limneu / 2 - ix - 1\n con = sqx2m1 / xi\n if(ics == 1) go to 20\n do 10 i = 1, lim\n enr(i) = enra(i)\n10 continue\n go to 40\n20 do 30 i = 1, lim\n30 enr(i) = enrb(i)\n40 continue\n!\n! compute radial functions of the third kind m3 and their\n! first derivatives m3d\n!\n! forward summation of numerator series for m3 and m3d\n dold = 1.0e0_knd\n doldd = cm\n m3temp = dold\n m3dtemp = doldd\n if(iopcs == 1) go to 50\n m3temp = real(l, knd) * dold\n m3dtemp = real(l, knd) * doldd\n50 jtermflag = 0\n kount = 1\n kountm = 1\n do 90 j = l2 + 1, lim\n jj = j + j + ix\n dnew = -dold * enr(j) * cneuf(jj)\n if(dnew * dold > 0.0e0_knd) then\n kount = kount + 1\n else\n kountm = max(kount, kountm)\n kount = 1\n end if\n dnewd = -doldd * enr(j) * cneudf(jj)\n term = dnew\n termd = dnewd\n if(iopcs == 1) go to 60\n term = dnew * real(jj, knd)\n termd = dnewd * real(jj, knd)\n60 m3temp = m3temp + term\n m3dtemp = m3dtemp + termd\n if((abs(term / m3temp) + abs(termd / m3dtemp)) < dcon) &\n go to 100\n if(j == lim) go to 100\n dold = dnew\n doldd = dnewd\n if(abs(m3dtemp) < stest) go to 90\n iscale = iscale + nex2\n dold = dold * sscale\n doldd = doldd * sscale\n m3temp = m3temp * sscale\n m3dtemp = m3dtemp * sscale\n90 continue\n jtermflag = 1\n100 jneu = min(j, lim)\n dk = real(kountm, knd)\n ndig = -int(log10(dk * abs(term / m3temp)))\n ndigd = -int(log10(dk * abs(termd / m3dtemp)))\n ndig = min(ndig, ndigd, ndec)\n if(ndig < 0) ndig = 0\n!\n! backward summation of numerator series for m3\n if(iscale /= 0) go to 130\n if (l2 < jlim) go to 130\n dold = 1.0e0_knd\n doldd = cm\n do 120 j = l2, jlim,-1\n jj = j + j + ix\n dnew = -dold / (enr(j) * cneuf(jj))\n dnewd = -doldd / (enr(j) * cneudf(jj))\n term = dnew\n termd = dnewd\n if(iopcs == 1) go to 110\n term = dnew * real(jj - 2, knd)\n termd = dnewd * real(jj - 2, knd)\n110 m3temp = m3temp + term\n m3dtemp = m3dtemp + termd\n if((abs(term / m3temp) + abs(termd / m3dtemp)) < dcon) go to 130\n dold = dnew\n doldd = dnewd\n120 continue\n130 m3top = m3temp * cneun(l + 1)\n im3e = ineue(l + 1)\n iterm = log10(abs(m3top))\n im3e = im3e + iterm\n m3top = m3top * 10.0e0_knd ** (-iterm)\nif (debug) then\n if(iopcs == 1) write(40, 140) ndig, jneu, lim\n140 format(3x,'mc3/mc3d num. converged to ',i3,' digits in ',i10, &\n ' terms; ',i10,' available.')\n if(iopcs == 2) write(40, 150) ndig, jneu, lim\n150 format(3x,'ms3/ms3d num. converged to ',i3,' digits in ',i10, &\n ' terms; ',i10,' available.')\nend if\n!\n m3c = m3top / m3bot\n if(iopcs == 2) m3c = m3c * con\n m3c = m3c * 2.0e0_knd / pi\n if(ix == 0) m3c = -m3c\n if(iopcs == 1 .and. ix == 1) m3c = -m3c\n iterm = log10(abs(m3c))\n im3e = im3e + iterm + iscale\n m3c = m3c * 10.0e0_knd ** (-iterm)\n if(abs(m3c) >= 1.0e0_knd) go to 160\n m3c = m3c * 10.0e0_knd\n im3e = im3e - 1\n160 continue\n m3dtemp = m3dtemp * cneudr(l + 1)\n if(iopcs == 2) m3dtemp = m3dtemp + m3temp / (xi * x2m1)\n m3dc = m3dtemp * cneun(l + 1) / m3bot\n if(iopcs == 2) m3dc = m3dc * con\n m3dc = m3dc * 2.0e0_knd / pi\n if(ix == 0) m3dc = -m3dc\n if(iopcs == 1 .and. ix == 1) m3dc = -m3dc\n m3dc = m3dc * sqx2m1\n iterm = log10(abs(m3dc))\n im3de = iterm + ineue(l + 1) + iscale\n m3dc = m3dc * 10.0e0_knd ** (-iterm)\n if(abs(m3dc) >= 1.0e0_knd) go to 170\n m3dc = 10.0e0_knd * m3dc\n im3de = im3de - 1\n170 continue\n if(jneu == lim) jneu = lim + 20\n return\n end subroutine\n!\n!\n subroutine geteiga (l, cm, eiga1, eiga2, eiga3, eiga4, eiga5, eigaval)\n!\n! purpose : to calculate an estimate of the eigenvalue for\n! c real. eigenvalues for c imaginary will be\n! obtained from eigenvalues for c real using\n! traditional relationships\n!\n! parameters :\n!\n! input : l : l\n! cm : magnitude of c\n! eiga2-eiga5: previous eigenvalues\n!\n! output : eigaval : estimate of the eigenvalue\n!\n use param\n!\n! real(knd) scalars\n real(knd) cm, d1, d2, d3, d4, eigaval, eiga1, eiga2, eiga3, eiga4, eiga5, &\n phi, phi12, phi32, phi2, phi52, qu, qu2, qu3, qu4, qu6, w, w2, w3, &\n w4, w5, w6, w7, w8, w9\n!\n qu = cm * cm / 4.0e0_knd\n qu2 = qu * qu\n qu3 = qu2 * qu\n qu4 = qu2 * qu2\n qu6 = qu4 * qu2\n!\n! after first four eigenvalues (l=0,1,2,3) have been computed, use\n! these via extrapolation to determine estimate for next eigenvalue\n if(l > 3) go to 30\n!\n! use expansions in powers of qu for qu < 10, and\n! asymptotic expansions for qu >= 10.\n if(qu >= 10.0e0_knd) go to 20\n if(qu >= 1.0e0_knd) go to 10\n!\n! estimates for qu < 1\n if(l == 0) eigaval = -0.5e0_knd * qu2 + 0.0546875e0_knd * qu4- &\n 0.0125868e0_knd * qu6\n if(l == 1) eigaval = 1.0e0_knd + qu - 0.125e0_knd * qu2 - 0.0156e0_knd * qu3\n if(l == 2) eigaval = 4.0e0_knd + 0.417e0_knd * qu2 - 0.0552e0_knd * qu4\n if(l == 3) eigaval = 9.0e0_knd + 0.0625e0_knd * qu2 + 0.015625e0_knd * qu3\n go to 40\n! estimates for 1 < qu < 10\n10 if(l == 0) eigaval = 0.5543e0_knd - (0.883e0_knd * qu) - 0.09639e0_knd* &\n qu2 + 0.004e0_knd * qu3\n if(l == 1) eigaval = 0.81175e0_knd + 1.3337e0_knd * qu - 0.30892e0_knd* &\n qu2 + 0.01929e0_knd * qu3 - 0.0004946e0_knd * qu4\n if(l == 2) eigaval = 3.3290504e0_knd + 0.992e0_knd * qu- &\n 0.0001829e0_knd * qu2 - 0.00866745e0_knd * qu3+ &\n 0.0003200972e0_knd * qu4\n if(l == 3) eigaval = 8.9449274e0_knd - (0.1039356e0_knd * qu)+ &\n 0.190696e0_knd * qu2 - 0.01453021e0_knd * qu3+ &\n 0.000303573e0_knd * qu4\n go to 40\n! estimates for qu >= 10\n20 w = l + l + 1\n w2 = w * w\n w3 = w2 * w\n w4 = w2 * w2\n w5 = w3 * w2\n w6 = w3 * w3\n w7 = w3 * w4\n w8 = w4 * w4\n w9 = w5 * w4\n phi = qu / w4\n phi12 = sqrt(phi)\n phi2 = phi * phi\n phi32 = phi * phi12\n phi52 = phi32 * phi\n d1 = 5 + 34 / w2 + 9 / w4\n d2 = 33 / w + 410 / w3 + 405 / w5\n d3 = 63 / w2 + 1260 / w4 + 2943 / w6 + 486 / w8\n d4 = 527 / w3 + 15617 / w5 + 69001 / w7 + 41607 / w9\n eigaval = -2.0e0_knd * qu + 2.0e0_knd * w * sqrt(qu) - ((w2 + 1.0e0_knd)/ &\n 8.0e0_knd) - ((w + (3.0e0_knd / w)) / (128.0e0_knd * phi12))- &\n (d1 / (4096.0e0_knd * phi)) - (d2 / (131072.0e0_knd * phi32))- &\n (d3 / (1048576.0e0_knd * phi2))- &\n (d4 / (33554432.0e0_knd * phi52))\n go to 40\n!\n! third order extrapolation\n30 eigaval = 4.0e0_knd * eiga5 - 6.0e0_knd * eiga4 + 4.0e0_knd * eiga3 - eiga2\n if(eigaval < eiga5) eigaval = eiga5\n40 eiga1 = eiga2\n eiga2 = eiga3\n eiga3 = eiga4\n eiga4 = eiga5\n return\n end subroutine\n!\n!\n subroutine convera (l, cm, limd, eiga1, eiga3, eiga4, eiga5, ndec, maxd, &\n enra, ienra, sgna, a01, ia01, blista, glista, &\n eigaval)\n!\n! purpose : to determine a converged eigenvalue using the\n! boukwamp procedure. eigenvalues are obtained for\n! c real; when c is imaginary, traditional relationships\n! are used to obtain the necessary eigenvalues from\n! those for c real.\n! parameters :\n!\n! input: l : l\n! cm : magnitude of c\n! limd : number of enra values computed\n! eiga1 : eigenvalue for l-4\n! eiga3 : eigenvalue for l-2\n! eiga4 : eigenvalue for l-1\n! ndec : number of decimal digits available in\n! real(knd) arithmetic\n! maxd : size of enr,blist,glist vectors\n! eigaval: estimated value of the eigenvalue\n!\n! output: enra : vector of coefficient ratios; enra(i) =\n! a(sub 2i)/a(sub 2i-2) for l even or\n! a(sub 2i+1)/a(sub 2i-1) for l odd\n! ienra : index i of last a coefficient ratio used\n! in computing first term in the denominator\n! of the eigenvalue correction\n! sgna : sign of the a coefficient a(sub l)\n! a01 : characteristic of the ratio of the first a\n! coefficent, either a(sub 0) if l is even or\n! a(sub 1) if l is odd, to the a coefficient\n! a(sub l)\n! ia01 : exponent corresponding to a01\n! eiga5 : converged eigenvalue for l\n!\n! other: blista : storage vector required by conver\n! glista : storage vector required by conver\n!\n use param\n!\n! real(knd) scalars and vectors\n real(knd) a01, cm, cll, clu, cora, corb, de, dec, decinv, dl, &\n dla, eiga1, eiga3, eiga4, eiga5, eigdec, eigaval, &\n enririo, fl, qu, qu2, r, sgna\n real(knd) blista(maxd), glista(maxd), enra(maxd)\n!\n qu = cm * cm / 4.0e0_knd\n qu2 = qu * qu\n dec = 10.0e0_knd ** (-ndec - 1)\n decinv = 10.0e0_knd ** (ndec)\n eigdec = dec * 100.0e0_knd\n!\n! set the upper and lower bounds for the eigenvalue\n if(l > 0) cll = eiga4\n if(l == 1) clu = eigaval + (eigaval - eiga4)\n if(l == 2 .or. l == 3) clu = eigaval + 0.5e0_knd * (eigaval - eiga3)\n if(l > 3) clu = eigaval + 0.5e0_knd * (eiga3 - eiga1)\n l2 = l / 2\n!\n! begin bouwkamp procedure\n fl = eigaval\n jnde = 0\n ix = l - 2 * l2\n isc = 2 + ix\n j = 1\n!\n! compute the beta coeficients\n do 10 i = isc, limd, 2\n blista(j) = qu2\n j = j + 1\n10 continue\n if(ix == 0) blista(1) = 2.0e0_knd * qu2\n j = 1\n id21 = isc - 1\n lim11 = limd + 1\n if(lim11 < id21) go to 30\n!\n! compute the gamma coeficients\n do 20 i = id21, lim11, 2\n r = real(i - 1, knd)\n glista(j) = r * r\n j = j + 1\n20 continue\n! begin Bouwkamp procedure\n30 ifc = 1\n limc = limd / 2 - ix\n limdb = 2 * ienra + 20\n if(l == 0) limdb = 2 * ienra\n if(limdb > limd) limdb = limd\n lim2 = limdb / 2 - ix\n iglim = lim2 + 1\n irio = l2 + 1\n iw1 = l2 + 2\n40 enra(1) = eigaval - glista(1)\n if(ix == 1) enra(1) = enra(1) - qu\n if(l2 < 1) go to 60\n!\n! evaluate the continued fraction\n do 50 i = 1, l2\n enra(i + 1) = -blista(i) / enra(i) - glista(i + 1) + eigaval\n50 continue\n60 enra(lim2) = -blista(lim2) / (glista(iglim) - eigaval)\n iw15 = lim2 - 1\n ip = iw1 + iw15\n if(iw15 < iw1) go to 80\n do 70 i = iw1, iw15\n ipi = ip - i\n enra(ipi) = -blista(ipi) / (glista(ipi + 1) - eigaval + enra(ipi + 1))\n70 continue\n80 enririo = -blista(irio) / (glista(irio + 1) - eigaval + enra(irio + 1))\n de = enririo * enririo / blista(irio)\n corb = de\n if(lim2 < iw1) go to 100\n!\n! compute denominator\n do 90 i = iw1, lim2\n de = enra(i) * enra(i) / blista(i) * de\n corb = corb + de\n if(abs(de / corb) < dec) go to 100\n90 continue\n100 ienra = i\n if(ienra < lim2 - 10) ienra = lim2 - 12\n cora = 1.0e0_knd\n de = 1.0e0_knd\n if(l2 < 1) go to 120\n do 110 i = 1, l2\n de = blista(irio - i) / (enra(irio - i) * enra(irio - i)) * de\n cora = cora + de\n if(abs(de / cora) < dec) go to 120\n110 continue\n!\n! compute the correction to the eigenvalue\n120 dl = (enririo - enra(irio)) / (cora + corb)\n if(ifc == 1) dla = dl\n eigaval = dl + eigaval\n!\n! eigenvalue accurate enough?\n if(abs(dl / eigaval) < eigdec) go to 130\n ifc = ifc + 1\n if(ifc < 20) go to 40\n130 continue\n!\n! is the eigenvalue the correct one\n! if not then modify the original guess\n if(l == 0) go to 180\n if(eigaval > cll) go to 140\n!\n! converged to next lower eigenvalue of the same parity\n cll = fl\n go to 170\n140 if(eigaval < clu) go to 180\n!\n! converged to the next higher eigenvalue of the same parity\n clu = fl\n go to 170\n!\n! check to see if too many modifications are being made\n! if so then suspect error in the routine\n170 jnde = jnde + 1\n if(jnde == 50) go to 230\n!\n! eigenvalue lies somewhere within the range established above\n! repeat procedure using the midpoint of this range\n! as the starting value\n eigaval = 0.5e0_knd * (cll + clu)\n fl = eigaval\n ifc = 1\n go to 40\n!\n180 continue\n eiga5 = eigaval\n!\n! compute enra using converged eigenvalue\n do i = 2 - ix, l2\n enra(i + 1) = -blista(i) / enra(i) - glista(i + 1) + eigaval\n end do\n enra(limc) = -blista(limc) / (glista(limc + 1) - eigaval)\n iw15 = limc - 1\n ip = iw1 + iw15\n if(iw15 >= iw1) then\n do i = iw1, iw15\n ipi = ip - i\n enra(ipi) = -blista(ipi) / (glista(ipi + 1) - eigaval + enra(ipi + 1))\n end do\n end if\n if((l2 > 2 .and. abs(enra(l2 + 2) / enra(l2 + 3)) < 0.01e0_knd) .or. &\n cm < 10.0e0_knd) then\n enra(l2 + 1) = -blista(l2 + 1) / (glista(l2 + 2) - eigaval + enra(l2 + 2))\n end if\n sgna = 1.0e0_knd\n limit = limd / 2 - ix\n do 200 i = 1, limit\n if(i > l2) go to 190\n if(enra(i) < (0.0e0_knd)) sgna = -sgna\n190 enra(i) = enra(i) / qu\n200 continue\n!\n! compute the ratio a(n=0)/a(n=l) for l even or a(n=1)/a(n=l) for l odd\n! this ratio has the characteristic a01 and the exponent ia01\n ia01 = 0\n a01 = 1.0e0_knd\n if(l2 == 0) go to 220\n do 210 kjl = 1, l2\n kkjl = l2 - kjl + 1\n a01 = a01 / enra(kkjl)\n if(abs(a01) > dec) go to 210\n a01 = a01 * decinv\n ia01 = ia01 - ndec\n210 continue\n iterm = int(log10(abs(a01)))\n a01 = a01 * (10.0e0_knd ** (-iterm))\n ia01 = ia01 + iterm\n220 continue\n return\n!\n! error printout\n230 continue\nif (output) then\n write(20, 240) l\n write(30, 240) l\nend if\nif (warn) then\n write(60, 240) l\nend if\n240 format(1x,'error in eigenvalue routine conver at l=',i5,/, &\n 1x,'this value may be inaccurate')\n eiga5 = eigaval\n return\n end subroutine\n!\n!\n subroutine dnorma (l, limd, maxd, ndec, enra, ce0, &\n cepio2, cedpio2, jmfa, jsuba)\n!\n! purpose : to calculate several special values of the angular\n! functions ce and its first derivatives.\n!\n! parameters :\n!\n! input : l : l\n! limd : equal to ~ twice the number of a coefficient\n! ratios\n! maxd : size of enra vector\n! ndec : number of decimal digits available in\n! real(knd) arithmetic\n! enra : vector of a coefficient ratios\n!\n! output : ce0 : ce(0), divided by the a coefficient with\n! subscript l\n! cepio2 : ce(pi/2), divided by the a coefficient with\n! subscript l\n! cedpio2 : ce'(pi/2), divided by the a coefficient with\n! subscript l\n! jmfa : maximum number of a coefficient ratios\n! required for convergence of all sums in\n! this subroutine\n! jsuba : subtraction error in calculating ce0\n!\n use param\n!\n! real(knd) scalars and vector\n real(knd) ce0, cedpio2, cepio2, dec, dnew, dold, sump, term\n real(knd) enra(maxd)\n!\n dec = 10.0e0_knd ** (-ndec - 2)\n l2 = l / 2\n ix = l - 2 * l2\n ix2 = (l + 1) / 2 - 2 * ((l + 1) / 4)\n lim2 = limd / 2 - ix\n!\n! compute ce(0), divided by the a coefficient with subscript l\n ce0 = 1.0e0_knd\n sump = 1.0e0_knd\n term = 1.0e0_knd\n jlow = l + 2\n jterm = l2\n do 30 j = jlow, limd, 2\n jterm = jterm + 1\n term = term * enra(jterm)\n if(term > 0.0e0_knd) sump = sump + term\n ce0 = ce0 + term\n if(abs(term) < dec) go to 40\n30 continue\n40 jlow = l\n jmfa = jterm\n if(jlow < 2) go to 60\n term = 1.0e0_knd\n jterm = l2\n do 50 j = jlow, 2,-2\n term = term / enra(jterm)\n if(term > 0.0e0_knd) sump = sump + term\n jterm = jterm - 1\n ce0 = ce0 + term\n if(abs(term) < dec) go to 60\n50 continue\n60 continue\n jsuba = 0\n if((sump * ce0) /= 0.0e0_knd) jsuba= &\n int(log10(abs(sump / ce0)))\n if(jsuba < 0) jsuba = 0\n if(jsuba > ndec) jsuba = ndec\n if(ce0 == 0.0e0_knd .and. sump /= 0.0e0_knd) jsuba = ndec\nif (debug) then\n write(40, 70) lim2, jmfa, jsuba\n70 format(3x, i10,' \"a\" coefficients; ce(0) converged in ', &\n i6,' terms; sub. error =',i3,' digits.')\n if(ix == 1) go to 125\nend if\n!\n! compute ce(pi/2), divided by the a coefficient with subscript l\n term = 1.0e0_knd\n cepio2 = 1.0e0_knd\n do 80 j = l2 + 1, lim2\n term = -term * enra(j)\n cepio2 = cepio2 + term\n if(abs(term / cepio2) < dec) go to 90\n80 continue\n90 continue\n jterm = j\n jmfa = max(jmfa, jterm)\n if(l2 < 1) go to 110\n term = 1.0e0_knd\n do 100 j = l2, 1,-1\n term = -term / enra(j)\n cepio2 = cepio2 + term\n if(abs(term / cepio2) < dec) go to 110\n100 continue\n110 nsub = 0\n if(ix2 == 1) cepio2 = -cepio2\n125 continue\n if(ix == 0) go to 180\n!\n! compute ce'(pi/2), divided by the a coefficient with subscript l\n dold = 1.0e0_knd\n cedpio2 = real(l, knd)\n do 130 j = l2 + 1, lim2\n dnew = -dold * enra(j)\n term = dnew * real(j + j + ix, knd)\n cedpio2 = cedpio2 + term\n if(abs(term / cedpio2) < dec) go to 140\n dold = dnew\n130 continue\n140 continue\n jterm = j\n jmfa = max(jmfa, jterm)\n if(l2 < 1) go to 160\n dold = 1.0e0_knd\n do 150 j = l2, 1,-1\n dnew = -dold / enra(j)\n term = dnew * real(j + j + ix - 2, knd)\n cedpio2 = cedpio2 + term\n if(abs(term / cedpio2) < dec) go to 160\n dold = dnew\n150 continue\n160 if(ix2 == 1) cedpio2 = -cedpio2\n180 continue\n return\n end subroutine\n!\n!\n subroutine geteigb (l, cm, eigb1, eigb2, eigb3, eigb4, eigb5, eigbval)\n!\n! purpose : to calculate an estimate of the eigenvalue for\n! c real. eigenvalues for c imaginary will be\n! obtained from eigenvalues for c real using\n! traditional relationships\n!\n! parameters :\n!\n! input : l : l\n! cm : cm\n! eigb2-eigb5: previous eigenvalues\n!\n! output : eigbval : estimate of the eigenvalue\n!\n use param\n!\n! real(knd) scalars\n real(knd) cm, d1, d2, d3, d4, eigbval, eigb1, eigb2, eigb3, eigb4, eigb5, &\n phi, phi12, phi32, phi2, phi52, qu, qu2, qu3, qu4, qu6, w, w2, w3, &\n w4, w5, w6, w7, w8, w9\n!\n qu = cm * cm / 4.0e0_knd\n qu2 = qu * qu\n qu3 = qu2 * qu\n qu4 = qu2 * qu2\n qu6 = qu4 * qu2\n!\n! after first four eigenvalues (l=0,1,2,3) have been computed, use\n! these via extrapolation to determine estimate for next eigenvalue\n if(l > 4) go to 30\n!\n! use expansions in powers of qu for qu < 10, and\n! asymptotic expansions for qu >= 10.\n if(qu >= 10.0e0_knd) go to 20\n if(qu >= 1.0e0_knd) go to 10\n!\n! estimates for qu < 1\n if(l == 1) eigbval = 1.0e0_knd - qu - 0.125e0_knd * qu2 + 0.0156e0_knd * qu3\n if(l == 2) eigbval = 4.0e0_knd + 0.08333333e0_knd * qu2+ &\n (3.6169e-4_knd) * qu4\n if(l == 3) eigbval = 9.0e0_knd + 0.0625e0_knd * qu2 - 0.015625e0_knd * qu3\n if(l == 4) eigbval = 16.0e0_knd + 0.033333333e0_knd * qu2- &\n (3.66898e-04_knd) * qu4\n go to 40\n! estimates for 1 < qu < 10\n10 if(l == 1) eigbval = 1.10427e0_knd - (1.152218e0_knd * qu)- &\n 0.0548246e0_knd * qu2+ &\n 0.0019711e0_knd * qu3\n if(l == 2) eigbval = 4.00909e0_knd - (0.004732542e0_knd * qu)- &\n 0.08725329e0_knd * qu2 &\n +0.00238446e0_knd * qu3\n if(l == 3) eigbval = 8.771735e0_knd + 0.268987e0_knd * qu- &\n 0.03569325e0_knd * qu2+ &\n 0.00009369364e0_knd * qu3\n if(l == 4) eigbval = 15.744e0_knd + 0.1907483e0_knd * qu+ &\n 0.0038216144e0_knd * qu2- &\n 0.000708719e0_knd * qu3\n go to 40\n! estimates for qu >= 10\n20 w = l + l - 1\n w2 = w * w\n w3 = w2 * w\n w4 = w2 * w2\n w5 = w3 * w2\n w6 = w3 * w3\n w7 = w3 * w4\n w8 = w4 * w4\n w9 = w5 * w4\n phi = qu / w4\n phi12 = sqrt(phi)\n phi2 = phi * phi\n phi32 = phi * phi12\n phi52 = phi32 * phi\n d1 = 5 + 34 / w2 + 9 / w4\n d2 = 33 / w + 410 / w3 + 405 / w5\n d3 = 63 / w2 + 1260 / w4 + 2943 / w6 + 486 / w8\n d4 = 527 / w3 + 15617 / w5 + 69001 / w7 + 41607 / w9\n eigbval = -2.0e0_knd * qu + 2.0e0_knd * w * sqrt(qu) - ((w2 + 1.0e0_knd)/ &\n 8.0e0_knd) - ((w + (3.0e0_knd / w)) / (128.0e0_knd * phi12))- &\n (d1 / (4096.0e0_knd * phi)) - (d2 / (131072.0e0_knd * phi32))- &\n (d3 / (1048576.0e0_knd * phi2)) - (d4 / (33554432.0e0_knd* &\n phi52))\n go to 40\n!\n! third order extrapolation\n30 eigbval = 4.0e0_knd * eigb5 - 6.0e0_knd * eigb4 + 4.0e0_knd * eigb3 - eigb2\n if(eigbval < eigb5) eigbval = eigb5\n40 eigb1 = eigb2\n eigb2 = eigb3\n eigb3 = eigb4\n eigb4 = eigb5\n return\n end subroutine\n!\n!\n subroutine converb (l, cm, limd, eigb1, eigb3, eigb4, eigb5, ndec, maxd, &\n enrb, ienrb, sgnb, b12, ib12, blistb, glistb, &\n eigbval)\n!\n! purpose : to determine a converged eigenvalue using the\n! boukwamp procedure for c real. eigenvalues for\n! c imaginary will be obtained from eigenvalues\n! for c real using traditional relationships\n! parameters :\n!\n! input: l : l\n! cm : magnitude of c\n! eigb1 : eigenvalue for l-4\n! eigb3 : eigenvalue for l-2\n! eigb4 : eigenvalue for l-1\n! ndec : number of decimal digits available in\n! real(knd) arithmetic\n! maxd : size of enr,blist,glist vectors\n! eigbval: estimated value of the eigenvalue\n!\n! output: enrb : vector of coefficient ratios; enrb(i) =\n! b(sub 2i)/b(sub 2i-2) for l even or\n! b(sub 2i+1)/b(sub 2i-1) for l odd; Since\n! b(sub 0) is not used, enrb(1) is not defined\n! when l is even\n! ienrb : index i of last b coefficient ratio used\n! in computing first term in the denominator\n! of the eigenvalue correction\n! sgnb : sign of the b coefficient b(sub l)\n! b01 : characteristic of the ratio of the first b\n! coefficent, either b(sub 2) if l is even or\n! b(sub 1) if l is odd, to the b coefficient\n! b(sub l)\n!\n! other: blistb : storage vector required by conver\n! glistb : storage vector required by conver\n!\n use param\n!\n! real(knd) scalars and vectors\n real(knd) b12, cm, cll, clu, cora, corb, de, dec, decinv, dl, &\n dla, eigb1, eigb3, eigb4, eigb5, eigdec, eigbval, &\n enrc, fl, qu, qu2, r, sgnb\n real(knd) blistb(maxd), glistb(maxd), enrb(maxd)\n!\n qu = cm * cm / 4.0e0_knd\n qu2 = qu * qu\n l2 = l / 2\n ix = l - 2 * l2\n dec = 10.0e0_knd ** (-ndec - 1)\n decinv = 10.0e0_knd ** (ndec)\n eigdec = dec * 100.0e0_knd\n!\n! set the upper and lower bounds for the eigenvalue\n if(l > 1) cll = eigb4\n if(l == 2) clu = eigbval + (eigbval - eigb4)\n if(l == 3 .or. l == 4) clu = eigbval + 0.5e0_knd * (eigbval - eigb3)\n if(l > 4) clu = eigbval + 0.5e0_knd * (eigb3 - eigb1)\n!\n! begin bouwkamp procedure\n fl = eigbval\n jnde = 0\n isc = 2 + ix\n j = 1\n!\n! compute the beta coeficients\n do 10 i = isc, limd, 2\n blistb(j) = qu2\n j = j + 1\n10 continue\n j = 1\n id21 = isc - 1\n lim11 = limd + 1\n if(lim11 < id21) go to 30\n!\n! compute the gamma coeficients\n do 20 i = id21, lim11, 2\n r = real(i - 1, knd)\n glistb(j) = r * r\n j = j + 1\n20 continue\n30 ifc = 1\n limc = limd / 2 - ix\n limdb = 2 * ienrb + 20\n if(l == 1) limdb = 2 * ienrb\n if(limdb > limd) limdb = limd\n lim2 = limdb / 2 - ix\n iglim = lim2 + 1\n irio = l2 + 1\n iw1 = l2 + 2\n40 if(ix == 1) enrb(1) = eigbval - glistb(1) + qu\n if(ix == 0) enrb(2) = eigbval - glistb(2)\n if(l2 < (2 - ix)) go to 60\n!\n! evaluate the continued fraction\n do 50 i = 2 - ix, l2\n enrb(i + 1) = -blistb(i) / enrb(i) - glistb(i + 1) + eigbval\n50 continue\n60 enrb(lim2) = -blistb(lim2) / (glistb(iglim) - eigbval)\n iw15 = lim2 - 1\n ip = iw1 + iw15\n if(iw15 < iw1) go to 80\n do 70 i = iw1, iw15\n ipi = ip - i\n enrb(ipi) = -blistb(ipi) / (glistb(ipi + 1) - eigbval + enrb(ipi + 1))\n70 continue\n80 enrc = -blistb(irio) / (glistb(irio + 1) - eigbval + enrb(irio + 1))\n de = enrc * enrc / blistb(irio)\n corb = de\n if(lim2 < iw1) go to 100\n!\n! compute denominator\n do 90 i = iw1, lim2\n de = enrb(i) * enrb(i) / blistb(i) * de\n corb = corb + de\n if(abs(de / corb) < dec) go to 100\n90 continue\n100 ienrb = i\n if(ienrb < lim2 - 10) ienrb = lim2 - 12\n cora = 1.0e0_knd\n de = 1.0e0_knd\n if(l2 + ix < 2) go to 120\n do 110 i = 1, l2 - 1 + ix\n de = blistb(irio - i) / (enrb(irio - i) * enrb(irio - i)) * de\n cora = cora + de\n if(abs(de / cora) < dec) go to 120\n110 continue\n!\n! compute the correction to the eigenvalue\n120 dl = (enrc - enrb(irio)) / (cora + corb)\n if(ifc == 1) dla = dl\n eigbval = dl + eigbval\n!\n! eigenvalue accurate enough?\n if(abs(dl / eigbval) < eigdec) go to 130\n ifc = ifc + 1\n if(ifc < 20) go to 40\n130 continue\n!\n! is the eigenvalue the correct one\n! if not then modify the original guess\n if(l < 2) go to 180\n if(eigbval > cll) go to 140\n!\n! converged to next lower eigenvalue of the same parity\n cll = fl\n go to 170\n140 if(eigbval < clu) go to 180\n!\n! converged to the next higher eigenvalue of the same parity\n clu = fl\n go to 170\n!\n! check to see if too many modifications are being made\n! if so then suspect error in the routine\n170 jnde = jnde + 1\n if(jnde == 50) go to 230\n!\n! eigenvalue lies somewhere within the range established above\n! repeat bouwkamp procedure using the midpoint value as the\n! starting value\n eigbval=.5e0_knd * (cll + clu)\n fl = eigbval\n ifc = 1\n go to 40\n!\n180 continue\n eigb5 = eigbval\n do i = 2 - ix, l2\n enrb(i + 1) = -blistb(i) / enrb(i) - glistb(i + 1) + eigbval\n end do\n enrb(limc) = -blistb(limc) / (glistb(limc + 1) - eigbval)\n iw15 = limc - 1\n ip = iw1 + iw15\n if(iw15 >= iw1) then\n do i = iw1, iw15\n ipi = ip - i\n enrb(ipi) = -blistb(ipi) / (glistb(ipi + 1) - eigbval + enrb(ipi + 1))\n end do\n end if\n if((l2 > 2 .and. abs(enrb(l2 + 2) / enrb(l2 + 3)) < 0.01e0_knd) .or. &\n cm < 10.0e0_knd) then\n enrb(l2 + 1) = -blistb(l2 + 1) / (glistb(l2 + 2) - eigbval + enrb(l2 + 2))\n end if\n sgnb = 1.0e0_knd\n jlim = 1\n if(ix == 0) jlim = 2\n do 200 j = jlim, limc\n if(j > l2) go to 190\n if(enrb(j) < (0.0e0_knd)) sgnb = -sgnb\n190 enrb(j) = enrb(j) / qu\n200 continue\n if(ix == 0) enrb(1) = 0.0e0_knd\n!\n! compute b1(cm,l) or b2(cm,l)\n ib12 = 0\n b12 = 1.0e0_knd\n if(l2 == 0) go to 220\n kjlupp = l2\n if(ix == 0) kjlupp = l2 - 1\n if(kjlupp == 0) go to 220\n do 210 kjl = 1, kjlupp\n kkjl = l2 - kjl + 1\n b12 = b12 / enrb(kkjl)\n if(abs(b12) > dec) go to 210\n b12 = b12 * decinv\n ib12 = ib12 - ndec\n210 continue\n iterm = int(log10(abs(b12)))\n b12 = b12 * (10.0e0_knd ** (-iterm))\n ib12 = ib12 + iterm\n220 continue\n return\n!\n! error printout\n230 continue\nif (output) then\n write(20, 240) l\n write(30, 240) l\nend if\nif (warn) then\n write(60, 240) l\nend if\n240 format(1x,'error in eigenvalue routine conver at l=',i5,/, &\n 1x,'this value may be inaccurate')\n eigb5 = eigbval\n return\n end subroutine\n!\n!\n subroutine dnormb (l, limd, maxd, ndec, enrb, sed0, sepio2, &\n sedpio2, jmfb, jsubb)\n!\n! purpose : to calculate several special values of the angular\n! functions se and its first derivative.\n!\n! parameters :\n!\n! input : l : l\n! limd : equal to ~twice the number of b coefficient\n! ratios\n! maxd : size of enra vector\n! ndec : number of decimal digits available in\n! real(knd) arithmetic\n! enrb : vector of b coefficient ratios\n!\n! output: sed0 : se'(0), divided by the b coefficient with\n! subscript l\n! sepio2 : se(pi/2), divided by the b coefficient with\n! subscript l\n! sedpio2 : se'(pi/2), divided by the b coefficient with\n! subscript l\n! jmfb : maximum number of b coefficient ratios\n! required for convergence of all sums in\n! this subroutine\n! jsubb : subtraction error in calculating sed0\n!\n use param\n!\n! real(knd) scalars and vector\n real(knd) dec, dnew, dold, sed0, sedpio2, sepio2, sump, term\n real(knd) enrb(maxd)\n!\n dec = 10.0e0_knd ** (-ndec - 2)\n l2 = l / 2\n ix = l - 2 * l2\n ix2 = (l + 1) / 2 - 2 * ((l + 1) / 4)\n lim2 = limd / 2 - ix\n jlim = 1\n if(ix == 0) jlim = 2\n!\n! compute se'(0), divided by the b coefficient with subscript l\n sed0 = real(l, knd)\n sump = sed0\n dold = 1.0e0_knd\n do 30 j = l2 + 1, lim2\n dnew = dold * enrb(j)\n term = dnew * real(j + j + ix, knd)\n if(term > 0.0e0_knd) sump = sump + term\n sed0 = sed0 + term\n if(abs(term / sed0) < dec) go to 40\n dold = dnew\n30 continue\n40 jmfb = j\n if(l2 < jlim) go to 60\n dold = 1.0e0_knd\n do 50 j = l2, jlim,-1\n dnew = dold / enrb(j)\n term = dnew * real(j + j + ix - 2, knd)\n if(term > 0.0e0_knd) sump = sump + term\n sed0 = sed0 + term\n if(abs(term / sed0) < dec) go to 60\n dold = dnew\n50 continue\n60 continue\n jsubb = 0\n if((sump * sed0) /= 0.0e0_knd) jsubb= &\n int(log10(abs(sump / sed0)))\n if(jsubb < 0) jsubb = 0\n if(jsubb > ndec) jsubb = ndec\n if(sed0 == 0.0e0_knd .and. sump /= 0.0e0_knd) jsubb = ndec\nif (debug) then\n write(40, 70) lim2, jmfb, jsubb\n70 format(3x, i10,' \"b\" coefficients; sed(0) converged in', &\n i6,' terms; sub. error =',i3,' digits.')\nend if\n if(ix == 0) go to 125\n!\n! compute se(pi/2), divided by the b coefficient with subscript l\n term = 1.0e0_knd\n sepio2 = 1.0e0_knd\n do 80 j = l2 + 1, lim2\n term = -term * enrb(j)\n sepio2 = sepio2 + term\n if(abs(term / sepio2) < dec) go to 90\n80 continue\n90 continue\n jterm = j\n jmfb = max(jmfb, jterm)\n if(l2 < 1) go to 110\n term = 1.0e0_knd\n do 100 j = l2, 1,-1\n term = -term / enrb(j)\n sepio2 = sepio2 + term\n if(abs(term / sepio2) < dec) go to 110\n100 continue\n110 continue\n if(ix2 == 0) sepio2 = -sepio2\n125 continue\n if(ix == 1) go to 180\n!\n! compute se'(pi/2), divided by the b coefficient with subscript l\n dold = 1.0e0_knd\n sedpio2 = real(l, knd)\n do 130 j = l2 + 1, lim2\n dnew = -dold * enrb(j)\n term = dnew * real(j + j + ix, knd)\n sedpio2 = sedpio2 + term\n if(abs(term / sedpio2) < dec) go to 140\n dold = dnew\n130 continue\n140 continue\n jterm = j\n jmfb = max(jmfb, jterm)\n if(l2 < 2) go to 160\n dold = 1.0e0_knd\n do 150 j = l2, 2,-1\n dnew = -dold / enrb(j)\n term = dnew * real(j + j + ix - 2, knd)\n sedpio2 = sedpio2 + term\n if(abs(term / sedpio2) < dec) go to 160\n dold = dnew\n150 continue\n160 if(ix2 == 1) sedpio2 = -sedpio2\n180 continue\n return\n end subroutine\n!\n!\n subroutine sincos(limsc, maxp, narg, isq, barg, sine, cosi)\n!\n use param\n!\n! real(knd) scalars and vectors\n real(knd) cosi1, sine1\n real(knd) barg(narg), sine(narg, maxp), cosi(narg, maxp)\n!\n do 40 i = 1, narg\n sine(i, 1) = 0.0e0_knd\n cosi(i, 1) = 1.0e0_knd\n if(isq == -1) go to 10\n sine1 = sin(barg(i))\n cosi1 = cos(barg(i))\n go to 20\n10 cosi1 = sin(barg(i))\n sine1 = cos(barg(i))\n20 do 30 j = 2, limsc\n sine(i, j) = cosi1 * sine(i, j - 1) + sine1 * cosi(i, j - 1)\n cosi(i, j) = cosi1 * cosi(i, j - 1) - sine1 * sine(i, j - 1)\n30 continue\n40 continue\n return\n end subroutine\n!\n subroutine cbesj (cm, x, limj, maxj, numlp, maxlp, limjt, ndec, limbes, &\n cbesf, cbesn, ibese, cbesdf, cbesdr, iopr)\n!\n! purpose : to calculate ratios of cylindrical Bessel functions of\n! the first kind and ratios of their first derivatives\n! for given c and xi. to calculate the Bessel function\n! characteristics and exponents and the ratios of the\n! first derivatives to the functions.\n!\n! parameters :\n!\n! input cm : c, since c is real here\n! x : value of radial argument equal to xi or\n! sqrt(xi*xi-1) or 0.5/[xi + sqrt(xi*xi-1)]\n! depending on the expansion used to\n! calculate the radial functions. the\n! argument of the Bessel functions is cm*x.\n! limj : the number of cylindrical Bessel function\n! ratios calculated for given lnum, c, and ndec.\n! maxj : size of cbesf and sbesdf vectors\n! numlp : the number of values of scale factors\n! and ratios of first derivatives to functions\n! that are calculated\n! maxlp : dimension of vectors of scale factors and\n! ratios of first derivatives to functions\n! limjt : Bessel function order to begin backward\n! recursion\n! ndec : number of decimal digits for real(knd)\n! arithmetic\n! limbes : 2*c*xi+2*ndec\n!\n! output : cbesf : ratios of cylindrical Bessel functions of the\n! first kind\n! cbesn : characteristics for the cylindrical\n! Bessel functions\n! ibese : exponents for the cylindrical\n! Bessel functions\n! cbesdf : ratios of first derivatives of the cylindrical\n! Bessel functions\n! cbesdr : ratios of first derivatives of the cylindrical\n! Bessel functions to the corresponding Bessel\n! functions\n!\n use param\n!\n! real(knd) scalars and vectors\n real(knd) besj0, cm, cx, dec, rn, sumj, temp0, temp1, term, x\n real(knd) cbesdf(maxj), cbesdr(maxj), cbesf(maxj), cbesn(maxlp), &\n ratio(limjt)\n!\n! integer vector\n dimension ibese(maxlp)\n!\n cx = cm * x\n dec = 10.0e0_knd ** (-ndec - 2)\n lim1 = max(limj + ndec, limbes)\n!\n! compute first kind Bessel function ratios\n! cbesf(k)= J(n=k,c*x)/J(n=k-1,c*x)\n! cbesn(k)= (J(n=k-1),c*x))*10.0e0_knd**(-ibese(k))\n!\n! use backward recursion to compute ratios:\n! J(n,c*x)/J(n-1,c*x) = 1/[(2*n)/(c*x) - J(n+1,c*x)/J(n,c*x)]\n!\n temp0 = cx / (2.0e0_knd * real(lim1 + 1, knd))\n if(limjt >= lim1) go to 15\n do 10 n = lim1, limjt,-1\n rn = real(n + n, knd)\n temp1 = 1.0e0_knd / (rn / cx - temp0)\n temp0 = temp1\n10 continue\n15 if(limjt >= lim1) temp1 = cx / (2.0e0_knd * real(limjt, knd))\n ratio(limjt) = temp1\n do 20 n = limjt - 1, 1,-1\n rn = real(n + n, knd)\n ratio(n) = 1.0e0_knd / (rn / cx - ratio(n + 1))\n20 continue\n do 30 n = 1, limj\n cbesf(n) = ratio(n)\n30 continue\n!\n! calculate the zeroth order function J(0,c*x) by use of the ratios\n! calculated above and the formula\n!\n! 1 = J(0,c*x) + 2J(2,c*x) + 2J(4,c*x) + ..., or\n!\n! J(0,c*x) = 1/[1 + 2(J(2,c*x)/J(0,c*x)) + 2(J(4,c*x)/J(0,c*x)) +\n! ...]\n!\n term = 2.0e0_knd\n sumj = 1.0e0_knd\n do 40 j = 2, limbes, 2\n term = term * ratio(j - 1) * ratio(j)\n sumj = sumj + term\n if(abs(term / sumj) < dec) go to 50\n40 continue\n50 continue\n besj0 = 1.0e0_knd / sumj\n!\n! calculate the characteristics and exponents for the\n! Bessel functions by forward operation on the function\n! ratios starting with the calculated value for J(0,c*x).\n ibese(1) = int(log10(abs(besj0)))\n cbesn(1) = besj0 * 10.0e0_knd ** (-ibese(1))\n cbesn(2) = cbesn(1) * cbesf(1)\n ibese(2) = int(log10(abs(cbesn(2))))\n cbesn(2) = cbesn(2) * 10.0e0_knd ** (-ibese(2))\n ibese(2) = ibese(2) + ibese(1)\n do 60 n = 3, numlp\n cbesn(n) = cbesn(n - 1) * cbesf(n - 1)\n ibese(n) = int(log10(abs(cbesn(n))))\n cbesn(n) = cbesn(n) * 10.0e0_knd ** (-ibese(n))\n ibese(n) = ibese(n) + ibese(n - 1)\n60 continue\n!\n! calculate the ratios of the first derivatives of successive\n! Bessel functions using corresponding function ratios\n! calculate the ratios of the first derivative to the corresponding\n! cylindrical Bessel function\n do 70 n = 1, limj\n rn = real(n - 1, knd)\n cbesdf(n) = (cx - (rn + 1.0e0_knd) * cbesf(n)) / (rn - cx * cbesf(n))\n cbesdr(n) = (rn / cx) - cbesf(n)\n70 continue\n if(iopr == 1) go to 90\n!\n! convert ratios of successive functions or derivatives to ratios of\n! functions or derivatives of the same parity\n do 80 n = limj, 2,-1\n cbesf(n) = cbesf(n - 1) * cbesf(n)\n80 cbesdf(n) = cbesdf(n - 1) * cbesdf(n)\n90 continue\n return\n end subroutine\n!\n!\n subroutine cbesi (cm, x, limj, maxj, numlp, maxlp, limjt, ndec, limbes, &\n cbesf, cbesn, ibese, cbesdf, cbesdr, iopr, nex)\n!\n! purpose : to calculate ratios of modified cylindrical Bessel\n! functions of the first kind and ratios of their first\n! derivatives for given c and x. to calculate the\n! modified Bessel function characteristics and exponents\n! and ratios of the first derivatives to the functions.\n!\n! parameters :\n!\n! input cm : mgnitude of c, c being positive imaginary\n! x : value of radial argument for modified Bessel\n! functions equal to cm*xi or cm*sqrt(xi*xi-1) or\n! cm*0.5*[xi - sqrt(xi*xi-1)] or cm*0.5*[xi +\n! sqrt(xi*xi-1)] depending on the expansion\n! used to calculate the radial functions\n! limj : the number of cylindrical Bessel function\n! ratios calculated for given lnum, c, and ndec.\n! maxj : size of cbesf and cbesdf vectors\n! numlp : the number of values of scale factors\n! and ratios of first derivatives to functions\n! that are calculated\n! maxlp : dimension of vectors of scale factors and\n! ratios of first derivatives to functions\n! limjt : Bessel function order to begin backward\n! recursion\n! ndec : number of decimal digits for real(knd)\n! arithmetic\n! limbes : 2*x+2*ndec\n!\n! output : cbesf : ratios of modified cylindrical Bessel functions\n! of the first kind\n! cbesn : characteristics for the modified cylindrical\n! Bessel functions\n! ibese : exponents for the modified cylindrical\n! Bessel functions\n! cbesdf : ratios of derivatives of the modified\n! cylindrical Bessel functions\n! cbesdr : ratios of the derivatives of the modified\n! cylindrical Bessel functions to their\n! corresponding Bessel functions\n!\n use param\n!\n! real(knd) scalars and vectors\n real(knd) besi0, cm, cx, dec, fac, rn, sumj, temp0, temp1, term, x\n real(knd) cbesdf(maxj), cbesdr(maxj), cbesf(maxj), cbesn(maxlp), &\n ratio(limjt)\n!\n! integer vector\n dimension ibese(maxlp)\n!\n cx = cm * x\n dec = 10.0e0_knd ** (-ndec - 2)\n lim1 = max(limj + ndec, limbes)\n!\n! compute first kind modified Bessel function ratios\n! cbesf(k)= I(n=k,cm*x)/I(n=k-1,cm*x)\n! cbesn(k)= (I(n=k-1),cm*x))*10.0e0_knd**(-ibese(k))\n!\n! use backward recursion to compute ratios:\n! I(n,cm*x)/I(n-1,cm*x) = 1/((2*n)/(cm*x) + I(n+1,cm*x)/I(n,cm*x))\n!\n temp0 = cx / (2.0e0_knd * real(lim1 + 1, knd))\n if(limjt >= lim1) go to 20\n do 10 n = lim1, limjt,-1\n rn = real(n + n, knd)\n temp1 = 1.0e0_knd / (rn / cx + temp0)\n temp0 = temp1\n10 continue\n20 if(limjt >= lim1) temp1 = cx / (2.0e0_knd * real(limjt, knd))\n ratio(limjt) = temp1\n do 30 n = limjt - 1, 1,-1\n rn = real(n + n, knd)\n ratio(n) = 1.0e0_knd / (rn / cx + ratio(n + 1))\n30 continue\n do 40 n = 1, limj\n cbesf(n) = ratio(n)\n40 continue\n!\n! calculate the zeroth order function I(0,cm*x) divided by\n! exp(cm*x) by use of the ratios calculated above and the formula\n!\n! exp(cm*x) = I(0,cm*x) + 2I(1,cm*x) + 2I(2,cm*x) + ..., or\n!\n! I(0,cm*x) = exp(cm*x)/[1 + 2(I(1,cm*x)/I(0,cm*x)) +\n! 2(I(2,cm*x)/I(0,cm*x)) + ...]\n!\n term = 2.0e0_knd\n sumj = 1.0e0_knd\n do 50 j = 1, limbes\n term = term * ratio(j)\n sumj = sumj + term\n if(abs(term / sumj) < dec) go to 60\n50 continue\n60 continue\n besi0 = 1.0e0_knd / sumj\n!\n! for all cm*x, calculate the amplitude and sign scale\n! factors by forward operation on the Bessel function\n! ratios starting with the calculated value for i(0,cm*x)\n! divided by exp(cm*x).\n ncx = 2 * int(cx * log10(exp(1.0e0_knd))) / nex\n if(ncx < 1) then\n cbesn(1) = besi0 * exp(cx)\n iterm = int(log10(abs(cbesn(1))))\n cbesn(1) = cbesn(1) * (10.0e0_knd ** (-iterm))\n ibese(1) = iterm\n else\n fac = exp(cx / real(ncx, knd))\n cbesn(1) = besi0 * fac\n ibese(1) = int(log10(abs(cbesn(1))))\n cbesn(1) = cbesn(1) * (10.0e0_knd ** (-ibese(1)))\n do j = 2, ncx\n cbesn(1) = cbesn(1) * fac\n iterm = int(log10(abs(cbesn(1))))\n cbesn(1) = cbesn(1) * (10.0e0_knd ** (-iterm))\n ibese(1) = ibese(1) + iterm\n end do\n end if\n cbesn(2) = cbesn(1) * cbesf(1)\n ibese(2) = int(log10(abs(cbesn(2))))\n cbesn(2) = cbesn(2) * 10.0e0_knd ** (-ibese(2))\n ibese(2) = ibese(2) + ibese(1)\n do 70 n = 3, numlp\n cbesn(n) = cbesn(n - 1) * cbesf(n - 1)\n ibese(n) = int(log10(abs(cbesn(n))))\n cbesn(n) = cbesn(n) * 10.0e0_knd ** (-ibese(n))\n ibese(n) = ibese(n) + ibese(n - 1)\n70 continue\n!\n! calculate the ratios of the first derivatives of successive\n! modified Bessel functions using corresponding function ratios\n! calculate the ratios of the first derivative to the corresponding\n! modified cylindrical Neumann function\n\n do 80 n = 1, limj\n rn = real(n - 1, knd)\n cbesdf(n) = (cx - (rn + 1.0e0_knd) * cbesf(n)) / (rn + cx * cbesf(n))\n cbesdr(n) = (rn / cx) + cbesf(n)\n80 continue\n!\n if(iopr == 1) go to 100\n!\n! convert ratios of successive functions and derivatives to ratios of\n! functions and derivatives of the same parity\n do 90 n = limj, 2,-1\n cbesf(n) = cbesf(n - 1) * cbesf(n)\n cbesdf(n) = cbesdf(n - 1) * cbesdf(n)\n90 continue\n100 continue\n return\n end subroutine\n!\n!\n subroutine cneuy (cm, x, limn, maxn, numlp, maxlp, ndec, limbes, pi, &\n gamma, cneuf, cneun, ineue, cneudf, cneudr, iopr)\n!\n! purpose : to calculate same parity ratios of cylindrical Bessel\n! functions of the second kind (Neumann functions) and\n! same parity ratios of their first derivatives for\n! given c and x.\n! to calculate the Neumann function and Neumann function\n! characteristics and exponents.\n! to calculate the ratios of the first derivatives to\n! corresponding cylindrical Neumann functions\n!\n! parameters :\n!\n! input cm : c, since c is real here\n! x : x\n! limn : the number of cylindrical Neumann function\n! ratios calculated for given lnum, c, and ndec\n! maxn : size of cneuf, cneudf and cneudr vectors\n! numlp : the number of values of scale factors\n! that are calculated\n! maxlp : dimension of vectors of scale factors\n! ndec : number of decimal digits for real(knd)\n! arithmetic\n! limbes : 2*c*x+2*ndec\n!\n! output : cneuf : same parity ratios of cylindrical Neumann\n! functions\n! cneun : characteristic for the cylindrical\n! Neumann functions\n! ineue : exponent for the cylindrical\n! Neumann functions\n! cneudf : same parity ratios of first derivatives\n! of cylindrical Neumann functions\n! cneudr : ratios of first derivatives to the\n! corresponding cylindrical Neumann functions\n!\n use param\n!\n! real(knd) scalars and vectors\n real(knd) besj0, cm, cx, cy0, cy1, dec, gamma, pi, rn, sumj, term, x\n real(knd) cbesf(limbes), cneuf(maxn), cneun(maxlp), cneudf(maxn), &\n cneudr(maxn)\n!\n! integer vectors\n dimension ineue(maxlp)\n cx = cm * x\n dec = 10.0e0_knd ** (-ndec - 2)\n! calculate ratios of successive cylindrical Bessel functions of the\n! first kind\n cbesf(limbes) = cx / (2.e0_knd * real(limbes, knd))\n do 10 n = limbes - 1, 1,-1\n rn = real(n + n, knd)\n cbesf(n) = 1.0e0_knd / (rn / cx - cbesf(n + 1))\n10 continue\n!\n! calculate the zeroth order function J(n=0,c*x) by use of the ratios\n! calculated above and the formula\n!\n! 1 = J(0,c*x) + 2J(2,c*x) + 2J(4,c*x) + ..., or\n!\n! J(0,c*x) = 1/[1 + 2(J(2,c*x)/J(0,c*x)) + 2(J(4,c*x)/J(0,c*x)) +\n! ...]\n!\n term = 2.0e0_knd\n sumj = 1.0e0_knd\n do 20 j = 2, limbes, 2\n term = term * cbesf(j - 1) * cbesf(j)\n sumj = sumj + term\n if(abs(term / sumj) < dec) go to 30\n20 continue\n30 continue\n besj0 = 1.0e0_knd / sumj\n!\n! calculate cy0 = Y(n=0,c*x) using J(n=0,c*x) and J ratios\n!\n term = besj0 * cbesf(1) * cbesf(2)\n sumj = term\n do 40 j = 2, limbes / 2\n term = -term * cbesf(j + j - 1) * cbesf(j + j)\n sumj = sumj + term / real(j, knd)\n if(abs(term / sumj) < dec) go to 50\n40 continue\n50 cy0 = 2.0e0_knd * ((log(cx / 2.0e0_knd) + gamma) * besj0 + 2.0e0_knd * sumj) &\n /pi\n cy1 = (cy0 * besj0 * cbesf(1) - 2.0e0_knd / (pi * cx)) / besj0\n!\n! compute ratios of successive cylindrical Neumann functions\n! using forward recursion from cy1/cy0\n!\n! y(n+1,c*x)/y(n,c*x)=(2*n)/(c*x)-1/(y(n,c*x)/y(n-1,c*x))\n!\n cneuf(1) = cy1 / cy0\n do 60 n = 1, limn - 1\n rn = real(n + n, knd)\n cneuf(n + 1) = (rn / cx) - (1.0e0_knd / cneuf(n))\n60 continue\n cneuf(limn + 1) = 0.0e0_knd\n!\n! now calculate the characteristic and exponent for each function\n! by forward multiplication using the Neumann function ratios:\n ineue(1) = int(log10(abs(cy0)))\n cneun(1) = cy0 * 10.0e0_knd ** (-ineue(1))\n ineue(2) = int(log10(abs(cy1)))\n cneun(2) = cy1 * 10.0e0_knd ** (-ineue(2))\n do 70 n = 3, numlp\n cneun(n) = cneun(n - 1) * cneuf(n - 1)\n ineue(n) = int(log10(abs(cneun(n))))\n cneun(n) = cneun(n) * 10.0e0_knd ** (-ineue(n))\n ineue(n) = ineue(n) + ineue(n - 1)\n70 continue\n!\n! calculate the ratios of the first derivatives of successive\n! Neumann functions using corresponding function ratios\n! calculate the ratios of the first derivatives to the\n! corresponding cylindrical Neumann functions\n do 80 n = 1, limn\n rn = real(n - 1, knd)\n cneudf(n) = (cx - (rn + 1.0e0_knd) * cneuf(n)) / (rn - cx * cneuf(n))\n cneudr(n) = (rn / cx) - cneuf(n)\n80 continue\n!\n if(iopr == 1) go to 100\n!\n! convert ratios of successive functions and derivatives to ratios of\n! functions and derivatives of the same parity\n do 90 n = limn, 2,-1\n cneuf(n) = cneuf(n - 1) * cneuf(n)\n cneudf(n) = cneudf(n - 1) * cneudf(n)\n90 continue\n100 continue\n return\n end subroutine\n!\n!\n subroutine cneuk (cm, x, limn, maxn, numlp, maxlp, ndec, nex, limbes, pi, &\n gamma, ngau, wr, xr, iopr, cneuf, cneun, ineue, &\n cneudf, cneudr)\n!\n! purpose : to calculate same parity ratios of modified cylindrical\n! Bessel functions of the third kind and the same\n! parity ratios of their first derivatives for\n! given cm and x.\n! to calculate the characteristics and exponents of the\n! modified Bessel functions of the third kind.\n! to calculate the ratios of the first derivatives to\n! corresponding modified cylindrical Bessel functions\n! of the third kind.\n!\n! parameters :\n!\n! input cm : magnitude of c, c being pure imaginary here\n! x : x\n! limn : the number of modified cylindrical Bessel\n! function ratios calculated for given lnum,\n! c, and ndec\n! maxn : size of cneuf, cneudf and cneudr vectors\n! numlp : the number of values of scale factors\n! that are calculated\n! maxlp : dimension of vectors of scale factors\n! ndec : number of decimal digits for real(knd)\n! nex : maximum exponent for real(knd)\n! limbes : 2*c*x+2*ndec\n! pi : pi\n! gamma : gamma\n! ngau : order of the Gaussian quadrature\n! wr : vector of ngau weighting factors for the\n! Gaussian quadrature\n! xr : vector of ngau coordinates for the Gaussian\n! quadrature\n! iopr : if iopr = 2 convert ratios of successive\n! functions to ratios of successive functions of\n! the same parity; also for the derivatives.\n!\n! output : cneuf : same parity ratios of cylindrical Bessel\n! functions\n! cneun : characteristic for the cylindrical\n! Bessel functions\n! ineue : exponent for the cylindrical\n! Bessel functions\n! cneudf : same parity ratios of first derivatives\n! of cylindrical Bessel functions\n! cneudr : ratios of first derivatives to the\n! corresponding cylindrical Bessel functions\n!\n use param\n!\n! real(knd) scalars and vectors\n real(knd) aj, besi0, bj, cm, cbexp, ck0, ck1, cx, dec, gamma, pi, rn, sumi, &\n term, term1, term2, x, z\n real(knd) cbesf(limbes), cneuf(maxn), cneun(maxlp), cneudf(maxn), &\n cneudr(maxn), wr(ngau), xr(ngau)\n!\n! integer vectors\n dimension ineue(maxlp)\n!\n cx = cm * x\n dec = 10.0e0_knd ** (-ndec - 2)\n! calculate ratios of successive modified cylindrical Bessel functions\n! of the first kind\n cbesf(limbes) = cx / (2.0e0_knd * real(limbes, knd))\n do 10 n = limbes - 1, 1,-1\n rn = real(n + n, knd)\n cbesf(n) = 1.0e0_knd / (rn / cx + cbesf(n + 1))\n10 continue\n!\n! calculate the zeroth order function I(n=0,cm*x) divided\n! by exp(cx) by use of the ratios calculated above and the\n! formula\n!\n! exp(cm*x) = I(0,cm*x) + 2I(2,cm*x) + 2I(4,cm*x) + ..., or\n!\n! I(0,cm*x) = exp(cm*x)/[1 + 2(I(2,cm*x)/I(0,cm*x)) +\n! 2(I(4,cm*x)/I(0,cm*x)) + ...]\n term = 2.0e0_knd\n sumi = 1.0e0_knd\n do 20 j = 1, limbes\n term = term * cbesf(j)\n sumi = sumi + term\n if(abs(term / sumi) < dec) go to 30\n20 continue\n30 continue\n besi0 = 1.0e0_knd / sumi\n!\n! when cx <= 1 calculate ck0 = K(n=0,cm*x) times exp(cmx) by\n! using I(n=0,cm*x) and I ratios\n if(cx > 1.0e0_knd) go to 60\n term = besi0 * cbesf(1) * cbesf(2)\n sumi = term\n do 40 j = 2, limbes / 2\n term = term * cbesf(j + j - 1) * cbesf(j + j)\n sumi = sumi + term / real(j, knd)\n if(abs(term / sumi) < dec) go to 50\n40 continue\n50 ck0 = (-(log(cx / 2.0e0_knd) + gamma) * besi0 + 2.0e0_knd * sumi)\n nsub = -int(log10(abs(ck0 / (ck0 - 2.0e0_knd * sumi))))\n if(nsub < 0) nsub = 0\n if(nsub > ndec) nsub = ndec\n nacck0 = ndec - nsub - 2\n ck0 = ck0 * exp(2.0e0_knd * cx)\n go to 100\n60 if(cx >= 40.0e0_knd) go to 70\n!\n! when 40 > cm*x > 1 calculate ck0 = K(n=0,cm*x) times exp(cm*x)\n! by numerical integration (via gaussian quadrature) of its\n! integral representation\n call k0int (cx, ndec, ngau, wr, xr, ck0)\n go to 100\n!\n! when cm*x >= 40 calculate ck0 = K(n=0,cm*x) times exp(cm*x) by\n! use of an asymptotic series\n70 sumi = 1.0e0_knd\n term1 = 1.0e0_knd\n z = 8.0e0_knd * cx\n do 80 j = 1, 100\n aj = real(j, knd)\n bj = aj + aj - 1.0e0_knd\n term2 = -term1 * bj * bj / (aj * z)\n if(abs(term2) >= abs(term1)) go to 90\n sumi = sumi + term2\n if(abs(term2 / sumi) < dec) go to 90\n term1 = term2\n80 continue\n90 continue\n ck0 = sqrt(pi / (2.0e0_knd * cx)) * sumi\n!\n! calculate ck1 = K(n=1,cm*x) times exp(cm*x) by use of the Wronskian\n100 ck1 = -ck0 * cbesf(1) + 1.0e0_knd / (cx * besi0)\n!\n! now compute ratios of successive modified cylindrical Neumann\n! functions using forward recursion\n!\n! K(n+1,cm*x)/K(n,cm*x)=-(2*n)/(cm*x)+1/(K(n,cm*x)/K(n-1,cm*x))\n cneuf(1) = ck1 / ck0\n limit = max(numlp, limn)\n do 110 n = 1, limit - 1\n rn = real(n + n, knd)\n cneuf(n + 1) = (rn / cx) + (1.0e0_knd / cneuf(n))\n110 continue\n cneuf(limit + 1) = 0.0e0_knd\n!\n! now calculate the characteristic and exponent for each function\n! by forward multiplication using the Neumann function ratios:\n cbexp = cx * log10(exp(1.0e0_knd))\n if(cbexp < real((nex - 10) * (nex - 10), knd)) go to 120\n ncbexp = int(cbexp)\n cneun(1) = ck0 * 10.0e0_knd ** (-cbexp + ncbexp)\n iterm = int(log10(abs(cneun(1))))\n cneun(1) = cneun(1) * 10.0e0_knd ** (-iterm)\n ineue(1) = iterm - ncbexp\n go to 150\n120 numsca = cbexp / (nex - 10) + 1\n isca = int(cbexp / real(numsca, knd))\n cneun(1) = exp(-cx / (real(numsca, knd)))\n cneun(1) = cneun(1) * 10.0e0_knd ** (isca)\n130 cneun(1) = ck0 * (cneun(1) ** (numsca))\n iterm = int(log10(abs(cneun(1))))\n cneun(1) = cneun(1) * 10.0e0_knd ** (-iterm)\n140 ineue(1) = iterm - isca * numsca\n150 cneun(2) = cneun(1) * cneuf(1)\n ineue(2) = int(log10(abs(cneun(2))))\n cneun(2) = cneun(2) * 10.0e0_knd ** (-ineue(2))\n ineue(2) = ineue(2) + ineue(1)\n do 160 n = 3, numlp\n cneun(n) = cneun(n - 1) * cneuf(n - 1)\n ineue(n) = int(log10(abs(cneun(n))))\n cneun(n) = cneun(n) * 10.0e0_knd ** (-ineue(n))\n ineue(n) = ineue(n) + ineue(n - 1)\n160 continue\n!\n! calculate the ratios of the first derivatives of successive\n! modified Bessel functions using corresponding function ratios\n! calculate the ratios of the first derivative to the corresponding\n! cylindrical Neumann function\n do 170 n = 1, limn\n rn = real(n - 1, knd)\n cneudf(n) = -(cx + (rn + 1.0e0_knd) * cneuf(n)) / (rn - cx * cneuf(n))\n cneudr(n) = (rn / cx) - cneuf(n)\n170 continue\n!\n if(iopr == 1) go to 190\n!\n! convert ratios of successive functions and derivatives to ratios of\n! functions and derivatives of the same parity\n do 180 n = limn, 2,-1\n cneuf(n) = cneuf(n - 1) * cneuf(n)\n cneudf(n) = cneudf(n - 1) * cneudf(n)\n180 continue\n190 continue\n return\n end subroutine\n!\n!\n subroutine gauss (n, ndec, x, w)\n!\n! purpose: To evaluate the coordinates and weighting factors\n! for an nth order Gaussian quadrature\n!\n! parameters:\n!\n! input: n : order of quadrature\n! ndec: precision for real(knd)\n!\n! output: x : coordinate values for quadrature\n! w : weighting factors\n!\n use param\n!\n! real(knd) scalars and arrays\n real(knd) delta, der, pi, s, t, test, u, v, z\n real(knd) x(n), w(n)\n!\n test = 10.0e0_knd ** (-ndec)\n imax = (n + 1) / 2\n pi = acos(-1.0e0_knd)\n do 40 i = 1, imax\n z = cos(pi * (i - 0.25e0_knd) / (n + 0.5e0_knd))\n do 20 j = 1, 30\n u = 0.0e0_knd\n v = 1.0e0_knd\n do 10 k = 1, n\n t = u\n u = v\n v = ((k + k - 1) * z * u - (k - 1) * t) / k\n10 continue\n s = z * z - 1.0e0_knd\n der = n * (z * v - u) / s\n delta = -v / der - 0.5e0_knd * v * v * ((n * n * s - n * z * z - n) * v+ &\n 2.0e0_knd * n * z * u) / (der * der * der * s * s)\n z = z + delta\n if(abs(delta / z) < test) go to 30\n20 continue\n30 continue\n x(i) = -z\n x(n + 1 - i) = z\n w(i) = 2.0e0_knd / ((1.0e0_knd - z * z) * der * der)\n w(n + 1 - i) = w(i)\n40 continue\n return\n end subroutine\n!\n!\n subroutine k0int (cx, ndec, ngau, wr, xr, ck0)\n!\n! purpose: To evaluate the product of the modified Bessel function\n! K of order zero with argument cx times the factor\n! exp(cx)\n! Gaussian quadrature is used to evaluate the integral\n! expression for K given in 9.6.24 in the Handbook of\n! Mathematical Functions\n!\n! parameters:\n!\n! input: cx : argument of K of zero order\n! ndec : precision for real(knd)\n! ngau : order of gaussain quadrature\n! wr : weighting factors for Gaussian quadrature\n! xr : coordinates for Gaussian quadrature\n!\n! output: ck0 : exp(cx)*K(cx)_sub 0\n!\n use param\n!\n! real(knd) scalars and vectors\n real(knd) arg, ck0, coef, cx, t, tupp\n real(knd) wr(ngau), xr(ngau)\n!\n tupp = log(2.0e0_knd + 4.61e0_knd * (ndec + 2) / cx)\n coef = tupp / 2.0e0_knd\n ck0 = 0.0e0_knd\n do 10 i = 1, ngau\n t = coef * (1.0e0_knd + xr(i))\n arg = exp(cx * (1.0e0_knd - cosh(t)))\n ck0 = ck0 + wr(i) * arg\n10 continue\n ck0 = coef * ck0\n return\n end subroutine\nend module mathieu\n", "meta": {"hexsha": "435c457cc99dc13bf7eeb69f27f21e6d2d035d50", "size": 236050, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mathieu.f90", "max_stars_repo_name": "MathieuandSpheroidalWaveFunctions/Mathieu", "max_stars_repo_head_hexsha": "bbdadcfe96c946177f4a7e7981a88254d07bc131", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-14T21:34:12.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-14T21:34:12.000Z", "max_issues_repo_path": "mathieu.f90", "max_issues_repo_name": "MathieuandSpheroidalWaveFunctions/Mathieu", "max_issues_repo_head_hexsha": "bbdadcfe96c946177f4a7e7981a88254d07bc131", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "mathieu.f90", "max_forks_repo_name": "MathieuandSpheroidalWaveFunctions/Mathieu", "max_forks_repo_head_hexsha": "bbdadcfe96c946177f4a7e7981a88254d07bc131", "max_forks_repo_licenses": ["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.7239819005, "max_line_length": 172, "alphanum_fraction": 0.4915907647, "num_tokens": 81155, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213799730774, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6627946696329875}} {"text": " function ilog2(l)\n ilog2 = dlog(real(l, 8))/dlog(2.0d0)\n end\n\n subroutine rotate(theta, x1, x2, x1p, x2p)\n double precision theta, x1, x2, x1p, x2p, c, s\n c = cos(theta)\n s = sin(theta)\n x1p = c*x1-s*x2\n x2p = s*x1+c*x2\n end\n\n subroutine rot1(theta, n, x)\n double precision theta, x, x1p, x2p\n dimension x(n)\n do k = 1, n-1, 2\n call rotate(theta, x(k), x(k+1), x1p, x2p)\n x(k) = x1p\n x(k+1) = x2p\n end do\n end\n\n subroutine rot2(theta, n, x)\n double precision theta, x, x1p, x2p\n dimension x(n)\n do k = 2, n-2, 2\n call rotate(theta, x(k), x(k+1), x1p, x2p)\n x(k) = x1p\n x(k+1) = x2p\n end do\n end\n\n subroutine magsqr(n, x, y)\n double precision x, y\n dimension x(n)\n y = 0.0d0\n do k = 1, n\n y = y+x(k)*x(k)\n end do\n end\n\n subroutine f(n, x, l, phi, y)\n double precision phi, x, y, x1\n dimension x(n), x1(1000)\n do k = 1, n\n x1(k) = x(k)\n end do\n do i = 1, l\n m = 2**(ilog2(l)-\n + ilog2(1+int(mod(1013.0d0*3.0d0**phi*real(i, 8),\n + real(l, 8)))))\n do j = 1, m\n call magsqr(n, x1, y)\n y = sqrt(y)\n call rot1(1.2d0*y, n, x1)\n call rot2(1.4d0*y, n, x1)\n end do\n end do\n call magsqr(n, x1, y)\n y = y/2.0d0\n end\n\n program main\n double precision phi, x, xb, y, yb\n dimension x(1000), xb(1000)\n read *, n\n read *, l\n read *, phi\n do k = 1, n\n x(k) = n+1-k\n xb(k) = 0.0d0\n end do\n yb = 1.0d0\n call f(n, x, l, phi, y)\n print *, y\n call f_b(n, x, xb, l, phi, y, yb)\n do k = 1, n\n print *, xb(k)\n end do\n end\n", "meta": {"hexsha": "d12f7a790a75b99d47ca0476f7099e2a1d36ef92", "size": 1865, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "example-without-binomial.f", "max_stars_repo_name": "qobi/checkpoint-VLAD", "max_stars_repo_head_hexsha": "a22151db51d6d7d1d2e495a77597370d2b8e8857", "max_stars_repo_licenses": ["FSFAP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-10T23:10:29.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-10T23:10:29.000Z", "max_issues_repo_path": "example-without-binomial.f", "max_issues_repo_name": "qobi/checkpoint-VLAD", "max_issues_repo_head_hexsha": "a22151db51d6d7d1d2e495a77597370d2b8e8857", "max_issues_repo_licenses": ["FSFAP"], "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-without-binomial.f", "max_forks_repo_name": "qobi/checkpoint-VLAD", "max_forks_repo_head_hexsha": "a22151db51d6d7d1d2e495a77597370d2b8e8857", "max_forks_repo_licenses": ["FSFAP"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.024691358, "max_line_length": 64, "alphanum_fraction": 0.4316353887, "num_tokens": 721, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636752, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6627946636550754}} {"text": " SUBROUTINE CLSTP(KLOG, COND, ISTAT) CLS 10\nC\nC THE EDITING REQUIRED TO CONVERT THIS SUBROUTINE FROM SINGLE TO\nC DOUBLE PRECISION INVOLVES THE FOLLOWING CHARACTER STRING CHANGES.\nC USE AN EDITING COMMAND (CHANGE) /STRING-1/(TO)STRING-2/.\nC (BEGIN THE CHANGES AT THE LINE WITH C++ IN COLS. 1-3.)\nC /REAL (12 BLANKS)/DOUBLE PRECISION/,/DCOPY/DCOPY/,/DDOT/DDOT/,\nC /DNRM2/DNRM2/,/DSQRT/DSQRT/,/D0/D0/,/DSCAL/DSCAL/,/DAXPY/DAXPY/,\nC /DRELPR/DRELPR/,/DSWAP/DSWAP/\nC\nC REVISED 820305-2000\nC REVISED YYMMDD-HHMM\nC\nC THIS SUBROUTINE EXERCISES MOST OF THE MATHEMATICAL FEATURES OF THE\nC CONSTRAINED LEAST SQUARES SUBPROGRAMS WNNLS( ) AND LSEI( ).\nC THE PROBLEM THAT IS SOLVED HERE IS OF THE FORM\nC\nC A*X=B (LEAST SQUARES, A MA BY N),\nC\nC\nC SUBJECT TO CONSTRAINTS\nC\nC E*X=F (CONSTRAINT EQUATIONS, ME BY N),\nC AND G*X .GE. H (INEQUALITY CONSTRAINTS, MG BY N).\nC\nC THE CLASS OF PROBLEMS THAT IS SOLVED HERE IS GENERATED WITH\nC HADAMARD MATRICES OF ORDER=POWER OF 2. EACH OF THE MATRICES\nC A,E, AND G HAVE A SPECIFIED CONDITION NUMBER. FOR EXAMPLE\nC A=HADAMARD MATRIX * DIAGONAL MATRIX * HADAMARD MATRIX.\nC DIAGONAL TERMS OF THE DIAGONAL MATRIX ARE CHOSEN SO THAT A\nC HAS A GIVEN CONDITION NUMBER. THE MATRICES E AND G ARE\nC CONSTRUCTED IN SIMILIAR WAYS. FURTHER, THE PROBLEM IS CONSTRUCTED\nC SO THAT THE TRUE SOLUTION IS X=(1,...,1) (TRANSPOSED).\nC THIS REQUIRES COMPUTING THE RIGHT HAND SIDE VECTORS B,F AND\nC H. THE VECTOR B=A*X+COMPONENT ORTHOGONAL TO COL. SPACE OF\nC A, F=E*X, AND H=G*H-SLACK COMPONENTS. THESE SLACK COMPONENTS\nC ARE CHOSEN SO THAT THE FIRST MI OF THE INEQUALITIES ARE\nC STRICT INEQUALITIES.\nC\nC THE PROBLEMS DIMENSIONS ARE SPECIFIED BY\nC\nC MA = 2**KA\nC ME = 2**KE\nC MG = 2**KG\nC MI = 2**KI\nC N = 2**KN\nC\nC WHERE KA, KE, KG, KI, AND KN ARE INPUT TO THE SUBROUTINE AS\nC DISCUSSED BELOW.\nC\nC THE SUBROUTINE ARGUMENTS ARE AS FOLLOWS\nC\nC I N P U T\nC\nC KLOG(*) - AN INTEGER ARRAY WHOSE DIMENSION IS AT LEAST 5. THE\nC ENTRIES CORRESPOND TO THE POWERS OF 2 NECESSARY\nC TO SPECIFY THE PROBLEM DIMENSIONS. REFERRING TO\nC THE ABOVE DISCUSSION, THE ENTRIES OF KLOG(*)\nC SHOULD BE SET AS FOLLOWS\nC\nC KLOG(1) = KA\nC KLOG(2) = KE\nC KLOG(3) = KG\nC KLOG(4) = KI\nC KLOG(5) = KN\nC\nC IF KA, KE, KG, OR KI IS LESS THAN ZERO, THE\nC CORRESPONDING DIMENSION WILL BE SET TO ZERO.\nC\nC KN.LT.0 WILL CAUSE THE SUBROUTINE TO SIMPLY RETURN.\nC\nC COND(*) - AN ARRAY WHOSE DIMENSION IS AT LEAST 3. THE\nC ENTRIES COND(1), COND(2), AND COND(3) RESPECTIVELY\nC SPECIFY THE CONDITION NUMBER FOR THE LEAST SQUARES\nC MATRIX, THE EQUALITY CONSTRAINT MATRIX, AND THE\nC INEQUALITY CONSTRAINT MATRIX.\nC\nC O U T P U T\nC\nC ISTAT - AN INTEGER FLAG WHICH INDICATES WHETHER THE SOLUTION\nC WAS CORRECTLY COMPUTED.\nC =1 NEITHER WNNLS( ) NOR LSEI( ) PASSED THE TEST.\nC =2 WNNLS( ) PASSED BUT LSEI( ) FAILED THE TEST.\nC =3 LSEI( ) PASSED BUT WNNLS( ) FAILED THE TEST.\nC =4 BOTH WNNLS( ) AND LSEI( ) PASSED THE TEST.\nC\nC THE DIMENSION STATEMENTS BELOW ARE SET UP TO SOLVE PROBLEMS FOR\nC WHICH NONE OF THE ABOVE LOGARITHMS IS GREATER THAN 5. TO CHANGE\nC THESE DIMENSIONS TO SOLVE LARGER PROBLEMS, USE THE FOLLOWING\nC FORMULAS\nC\nC DIMENSION W(MA+ME+MG,N+MG+1),X(N+MG),HH(MMAX,MMAX),GG(MMAX,MMAX)\nC DIMENSION WORK(2*(ME+N)+K+(MG+2)*(N+7)),IWORK(ME+MA+2*MG+N)\nC DIMENSION SA(MIN(MA,N)),SE(MIN(ME,N)),SG(MIN(MG,N))\nC\nC WHERE MMAX = MAX(MA,ME,MG,N)\nC K = MAX(MA+MG,N)\nC\nC NOTE THAT IF THE DIMENSIONS ARE CHANGED, THE VALUES ASSIGNED TO\nC MDW, MDH, AND MDG BELOW MUST BE ALTERED APPROPRIATELY. THESE\nC ARE THE RESPECTIVE ROW DIMENSIONS OF THE ARRAYS W(*,*), HH(*,*),\nC AND GG(*,*).\nC++\n DOUBLE PRECISION ANSR, BETA, BNORM, CONDA, CONDE, CONDG,\n * DXBYX, GAM, GNORM, ONE, PHI, RHO, RNORME,\n * RNORML, SOLERR, DRELPR, T, TWO, ZERO\n DOUBLE PRECISION DNRM2, DDOT, DSQRT\n DOUBLE PRECISION W(96,65), X(64), HH(32,32), GG(32,32)\n DOUBLE PRECISION WORK(1518)\n INTEGER IWORK(0640)\n DOUBLE PRECISION SA(32), SE(32), SG(32)\nC\nC THE FOLLOWING DIMENSION STATEMENTS NEED NOT BE ALTERED TO\nC SOLVE LARGER PROBLEMS.\n DOUBLE PRECISION COND(3), PRGOPT(4)\n INTEGER KLOG(5)\n LOGICAL DONE\nC\n MDW = 96\n MDH = 32\n MDG = 32\n ZERO = 0.D0\n ONE = 1.D0\n TWO = 2.D0\n ISTAT = 1\nC COMPUTE THE RELATIVE MACHINE PRECISION.\n DRELPR = ONE\n 10 IF (ONE+DRELPR.EQ.ONE) GO TO 20\n DRELPR = DRELPR/TWO\n GO TO 10\n 20 DRELPR = DRELPR*TWO\nC\nC SET THE OUTPUT UNIT TO WHICH ERROR MESSAGES WILL BE PRINTED.\n LOUT = I1MACH(4)\nC\nC SET UP THE PROBLEM DIMENSIONS\n KA = KLOG(1)\n KE = KLOG(2)\n KG = KLOG(3)\n KI = KLOG(4)\n KN = KLOG(5)\n CONDA = ONE\n CONDE = ONE\n CONDG = ONE\n DONE = KN.LT.0\n IF (.NOT.(DONE)) GO TO 30\n RETURN\n 30 MA = 0\n ME = 0\n MG = 0\n N = 0\nC\nC SET NOISE-TO-SIGNAL RATIO PARAMETER FOR LEAST SQUARES EQUAS.\nC THIS ESSENTIALLY SPECIFIES THE RATIO\nC\nC NORM(RESIDUAL VECTOR)\nC ---------------------\nC NORM(A*X)\n ANSR = 0.01\nC\nC SET UP THE CONDITION NUMBERS FOR THE MATRICES A, E, AND G.\n IF (KA.GE.0) CONDA = COND(1)\n IF (KE.GE.0) CONDE = COND(2)\n IF (KG.GE.0) CONDG = COND(3)\nC\nC CHECK THE VALIDITY OF THE INPUT\n IF (.NOT.(.NOT.(KA.LE.5 .AND. KE.LE.5 .AND. KG.LE.5 .AND. KI.LE.5\n * .AND. KN.LE.5))) GO TO 40\n WRITE (LOUT,99999)\n RETURN\n 40 IF (.NOT.(CONDA.LT.ONE .OR. CONDE.LT.ONE .OR. CONDG.LT.ONE)) GO\n * TO 50\n WRITE (LOUT,99998)\n99999 FORMAT (/42H KA, KE, KG, KI, AND KN MUST ALL BE .LE. 5, 7H AS REQ,\n * 53HUIRED BY THE CURRENT SUBPROGRAM DIMENSION STATEMENTS.)\n99998 FORMAT (/46H CONDA, CONDE, AND CONDG MUST ALL BE .GE. ONE.)\n RETURN\n 50 CONTINUE\n ICASE = 1\n 60 CONTINUE\n ISEED = 100001\n T = RAN(ISEED)\n ISEED = 0\nC\nC COMPUTE THE PRE-MULTIPLYING HADAMARD MATRIX FOR E.\n K = KE\n ASSIGN 70 TO NGO\n GO TO 900\n 70 ME = NN\nC\nC SAVE THE HADAMARD MATRIX.\n J = 1\n N20011 = ME\n GO TO 90\n 80 J = J + 1\n 90 IF ((N20011-J).LT.0) GO TO 100\n CALL DCOPY(ME, HH(1,J), 1, GG(1,J), 1)\n GO TO 80\nC\nC NOW FORM THE POST-MULTIPLYING HADAMARD MATRIX.\n 100 K = KN\n ASSIGN 110 TO NGO\n GO TO 900\n 110 N = NN\nC\nC COMPUTE THE SINGULAR VALUES OF THE MATRIX E.\nC DISTRIBUTE THEM UNIFORMLY BETWEEN 1. AND CONDE.\n SE(1) = CONDE\n MNE = MAX0(1,MIN0(ME,N))\n SE(MNE) = ONE\n I = 2\n N20016 = MNE - 1\n GO TO 130\n 120 I = I + 1\n 130 IF ((N20016-I).LT.0) GO TO 140\n SE(I) = ONE + RAN(ISEED)*(CONDE-ONE)\n GO TO 120\n 140 J = 1\n N20020 = MNE\n GO TO 160\n 150 J = J + 1\n 160 IF ((N20020-J).LT.0) GO TO 170\n CALL DSCAL(ME, SE(J), GG(1,J), 1)\n GO TO 150\n 170 J = 1\n N20024 = N\n GO TO 190\n 180 J = J + 1\n 190 IF ((N20024-J).LT.0) GO TO 230\n IF (ME.GT.0) W(1,J) = ZERO\n CALL DCOPY(ME, W(1,J), 0, W(1,J), 1)\n I = 1\n N20028 = MNE\n GO TO 210\n 200 I = I + 1\n 210 IF ((N20028-I).LT.0) GO TO 220\n CALL DAXPY(ME, HH(I,J), GG(1,I), 1, W(1,J), 1)\n GO TO 200\n 220 GO TO 180\nC\nC COMPUTE E*X AND STORE IN W(*,N+1).\n 230 I = 1\n N20032 = ME\n GO TO 250\n 240 I = I + 1\n 250 IF ((N20032-I).LT.0) GO TO 260\n X(1) = ONE\n W(I,N+1) = DDOT(N,X,0,W(I,1),MDW)\n GO TO 240\nC\nC COMPUTE THE PRE-MULTIPLYING HADAMARD MATRIX FOR A.\n 260 K = KA\n ASSIGN 270 TO NGO\n GO TO 900\n 270 MA = NN\nC\nC SAVE THE HADAMARD MATRIX.\n J = 1\n N20037 = MA\n GO TO 290\n 280 J = J + 1\n 290 IF ((N20037-J).LT.0) GO TO 300\n CALL DCOPY(MA, HH(1,J), 1, GG(1,J), 1)\n GO TO 280\nC\nC NOW FORM THE POST-MULTIPLYING HADAMARD MATRIX.\n 300 K = KN\n ASSIGN 310 TO NGO\n GO TO 900\n 310 N = NN\nC\nC COMPUTE THE SINGULAR VALUES OF THE MATRIX A.\nC DISTRUBUTE THEM UNIFORMLY BETWEEN 1. AND CONDA.\n SA(1) = CONDA\n MNA = MAX0(1,MIN0(MA,N))\n SA(MNA) = ONE\n I = 2\n N20042 = MNA - 1\n GO TO 330\n 320 I = I + 1\n 330 IF ((N20042-I).LT.0) GO TO 340\n SA(I) = ONE + RAN(ISEED)*(CONDA-ONE)\n GO TO 320\n 340 J = 1\n N20046 = MNA\n GO TO 360\n 350 J = J + 1\n 360 IF ((N20046-J).LT.0) GO TO 370\n CALL DSCAL(MA, SA(J), GG(1,J), 1)\n GO TO 350\n 370 J = 1\n N20050 = N\n GO TO 390\n 380 J = J + 1\n 390 IF ((N20050-J).LT.0) GO TO 430\nC\nC COMPUTE THE PRODUCT IN PLACE INTO W(*,*).\n IF (MA.GT.0) W(ME+1,J) = ZERO\n CALL DCOPY(MA, W(ME+1,J), 0, W(ME+1,J), 1)\n I = 1\n N20054 = MNA\n GO TO 410\n 400 I = I + 1\n 410 IF ((N20054-I).LT.0) GO TO 420\n CALL DAXPY(MA, HH(I,J), GG(1,I), 1, W(ME+1,J), 1)\n GO TO 400\n 420 GO TO 380\nC\nC COMPUTE A*X AND STORE IN W(*,N+1).\n 430 I = 1\n N20058 = MA\n GO TO 450\n 440 I = I + 1\n 450 IF ((N20058-I).LT.0) GO TO 460\n MEPI = ME + I\n X(1) = ONE\n W(MEPI,N+1) = DDOT(N,X,0,W(MEPI,1),MDW)\n GO TO 440\n 460 BNORM = DNRM2(MA,W(ME+1,N+1),1)\nC\nC ADD COMPONENTS TO RIGHT SIDE THAT ARE ORTHOGONAL TO COL.\nC SPACE OF A.\n K = KA\n ASSIGN 470 TO NGO\n GO TO 900\n 470 MA = NN\n I = N + 1\n N20063 = MA\n GO TO 490\n 480 I = I + 1\n 490 IF ((N20063-I).LT.0) GO TO 500\n T = RAN(ISEED)*BNORM*ANSR\n CALL DAXPY(MA, T, HH(1,I), 1, W(ME+1,N+1), 1)\n GO TO 480\nC\nC COMPUTE THE PRE-MULTIPLYING HADAMARD MATRIX FOR G.\n 500 K = KG\n ASSIGN 510 TO NGO\n GO TO 900\n 510 MG = NN\nC\nC SAVE THE HADAMARD MATRIX.\n J = 1\n N20068 = MG\n GO TO 530\n 520 J = J + 1\n 530 IF ((N20068-J).LT.0) GO TO 540\n CALL DCOPY(MG, HH(1,J), 1, GG(1,J), 1)\n GO TO 520\nC\nC NOW FORM THE POST-MULTIPLYING HADAMARD MATRIX.\n 540 K = KN\n ASSIGN 550 TO NGO\n GO TO 900\n 550 N = NN\nC\nC COMPUTE THE SINGULAR VALUES OF G.\nC DISTRIBUTE THEM UNIFORMLY BETWEEN 1. AND CONDG.\n SG(1) = CONDG\n MNG = MAX0(1,MIN0(MG,N))\n SG(MNG) = ONE\n I = 2\n N20073 = MNG - 1\n GO TO 570\n 560 I = I + 1\n 570 IF ((N20073-I).LT.0) GO TO 580\n SG(I) = ONE + RAN(ISEED)*(CONDG-ONE)\n GO TO 560\n 580 J = 1\n N20077 = MNG\n GO TO 600\n 590 J = J + 1\n 600 IF ((N20077-J).LT.0) GO TO 610\n CALL DSCAL(MG, SG(J), GG(1,J), 1)\n GO TO 590\n 610 J = 1\n N20081 = N\n GO TO 630\n 620 J = J + 1\n 630 IF ((N20081-J).LT.0) GO TO 670\n MEPMA = ME + MA\n IF (MG.GT.0) W(MEPMA+1,J) = ZERO\n CALL DCOPY(MG, W(MEPMA+1,J), 0, W(MEPMA+1,J), 1)\n I = 1\n N20085 = MNG\n GO TO 650\n 640 I = I + 1\n 650 IF ((N20085-I).LT.0) GO TO 660\n CALL DAXPY(MG, HH(I,J), GG(1,I), 1, W(MEPMA+1,J), 1)\n GO TO 640\n 660 GO TO 620\nC\nC COMPUTE G*X AND STORE IN W(*,N+1).\n 670 I = 1\n N20089 = MG\n GO TO 690\n 680 I = I + 1\n 690 IF ((N20089-I).LT.0) GO TO 700\n IROW = I + MEPMA\n X(1) = ONE\n W(IROW,N+1) = DDOT(N,X,0,W(IROW,1),MDW)\n GO TO 680\nC\nC MAKE FIRST MI=2**KI OF THE INEQUALITIES STRICT.\n 700 IF (.NOT.(KI.GE.0)) GO TO 710\n MI = 1\n GO TO 720\n 710 MI = 0\n 720 K = 1\n N20096 = KI\n GO TO 740\n 730 K = K + 1\n 740 IF ((N20096-K).LT.0) GO TO 750\n MI = MI + MI\n GO TO 730\n 750 GNORM = DNRM2(MG,W(MEPMA+1,N+1),1)\n I = 1\n N20100 = MIN0(MI,MG)\n GO TO 770\n 760 I = I + 1\n 770 IF ((N20100-I).LT.0) GO TO 780\n IROW = I + MEPMA\n W(IROW,N+1) = W(IROW,N+1) - RAN(ISEED)*GNORM\n GO TO 760\nC\nC OBTAIN THE CONSTRAINED LEAST SQUARES SOLUTION.\nC\nC NOTE THE LENGTHS OF THE WORK ARRAYS IN IWORK(*).\n 780 IWORK(1) = 1518\n IWORK(2) = 0640\n IF (.NOT.(ICASE.EQ.1)) GO TO 810\nC\nC EXCHANGE POSITIONS OF THE ROWS (A B) AND (G H).\n NP1 = N + 1\n DO 790 J=1,NP1\n IROW = ME + (MA+MG+2)/2\n CALL DSWAP((MA+MG+1)/2, W(ME+1,J), 1, W(IROW,J), -1)\n 790 CONTINUE\nC\nC MOVE RT-SIDE TO W(*,N+MG+1).\n JCOL = N + MG + 1\n CALL DCOPY(ME+MA+MG, W(1,N+1), 1, W(1,JCOL), 1)\nC\nC PUT IN SLACK VARIABLE COLS. AS REQUIRED.\n IF (.NOT.(MG.GT.0)) GO TO 800\n W(1,N+1) = ZERO\n CALL DCOPY(MDW*MG, W(1,N+1), 0, W(1,N+1), 1)\n W(ME+1,N+1) = -ONE\n CALL DCOPY(MG, W(ME+1,N+1), 0, W(ME+1,N+1), MDW+1)\n 800 CONTINUE\nC\nC SET THE OPTION (NUMBER 6) FOR WNNLS( ) TO SCALE THE\nC COLUMNS OF THE MATRIX TO HAVE UNIT LENGTH.\n PRGOPT(1) = 4\n PRGOPT(2) = 6\n PRGOPT(3) = 1\n PRGOPT(4) = 1\n CALL WNNLS(W, MDW, ME+MG, MA, N+MG, N, PRGOPT, X, RNORML, MODE,\n * IWORK, WORK)\n GO TO 820\n 810 CONTINUE\nC\nC SET THE OPTION (NUMBER 2) FOR LSEI( ) TO SCALE THE\nC COLUMNS OF THE MATRIX TO HAVE UNIT LENGTH.\n PRGOPT(1) = 4\n PRGOPT(2) = 2\n PRGOPT(3) = 1\n PRGOPT(4) = 1\n CALL LSEI(W, MDW, ME, MA, MG, N, PRGOPT, X, RNORME, RNORML, MODE,\n * WORK, IWORK)\n 820 CONTINUE\nC\nC COMPUTE THE RESIDUAL SUM OF SQUARES OF ERRORS.\n SOLERR = ZERO\n I = 1\n N20104 = N\n GO TO 840\n 830 I = I + 1\n 840 IF ((N20104-I).LT.0) GO TO 850\n X(I) = ONE - X(I)\n SOLERR = SOLERR + X(I)**2\n GO TO 830\n 850 SOLERR = DSQRT(SOLERR)\nC\nC TEST SIZE OF ERROR (REF. LAWSON-HANSON, PAGE 51 AND CH. 16)\n PHI = 100.\n T = N\n DXBYX = SOLERR/DSQRT(T)\n RHO = ONE\n IF (BNORM.NE.ZERO) RHO = RNORML/BNORM\n GAM = (6*MAX0(MA,N)-3*MIN0(MA,N))*MIN0(MA,N)\n BETA = CONDA*(ONE+CONDA*RHO)*GAM*PHI\n IF (.NOT.(DXBYX+BETA.EQ.BETA)) GO TO 860\n ISTAT = ISTAT + ICASE\n GO TO 870\n 860 CONTINUE\n IF (MA.EQ.0 .AND. MODE.EQ.0) ISTAT = ISTAT + ICASE\n 870 CONTINUE\n IF (.NOT.(ICASE.EQ.1)) GO TO 880\n WRITE (LOUT,99997) RNORML\n99997 FORMAT (18H0LEAST SQS. RESID., E012.5, 2X, 12HFOR WNNLS( )/\n * 30H ERRORS, 1-X(I), FOR WNNLS( ).)\n WRITE (LOUT,99996) (I,X(I),I=1,N)\n99996 FORMAT (4(I4, E012.5))\n GO TO 890\n 880 CONTINUE\n WRITE (LOUT,99995) RNORML, IWORK(1), IWORK(2)\n99995 FORMAT (18H0LEAST SQS. RESID., E012.5, 2X, 11HFOR LSEI( )/\n * 41H COMP. RANK OF E, COMP. RANK OF REDUCED A, 2I4/11H ERRORS, 1-,\n * 18HX(I), FOR LSEI( ).)\n WRITE (LOUT,99996) (I,X(I),I=1,N)\n 890 CONTINUE\n IF (ICASE.EQ.2) RETURN\n ICASE = 2\n GO TO 60\nC\nC PROCEDURE (GET HADAMARD MATRIX)\n 900 NN = 0\n IF (.NOT.(K.GE.0)) GO TO 940\n NN = 1\n I = 1\n N20114 = K\n GO TO 920\n 910 I = I + 1\n 920 IF ((N20114-I).LT.0) GO TO 930\n NN = NN + NN\n GO TO 910\n 930 GO TO 950\n 940 NN = 0\n GO TO 1080\nC\nC PLACE THE SYMMETRIC HADAMARD MATRIX IN THE ARRAY HH(*,*).\n 950 HH(1,1) = ONE\n NN = 1\n L = 1\n N20118 = K\n GO TO 970\n 960 L = L + 1\n 970 IF ((N20118-L).LT.0) GO TO 1040\n J = 1\n N20122 = NN\n GO TO 990\n 980 J = J + 1\n 990 IF ((N20122-J).LT.0) GO TO 1000\n CALL DCOPY(NN, HH(1,J), 1, HH(NN+1,J), 1)\n GO TO 980\n 1000 J = 1\n N20126 = NN\n GO TO 1020\n 1010 J = J + 1\n 1020 IF ((N20126-J).LT.0) GO TO 1030\n JPNN = J + NN\n CALL DCOPY(2*NN, HH(1,J), 1, HH(1,JPNN), 1)\n CALL DSCAL(NN, -ONE, HH(NN+1,JPNN), 1)\n GO TO 1010\n 1030 NN = NN + NN\n GO TO 960\nC\nC MAKE THE MATRIX ORTHOGONAL BY SCALING THE ENTRIES.\n 1040 T = NN\n T = ONE/DSQRT(T)\n J = 1\n N20130 = NN\n GO TO 1060\n 1050 J = J + 1\n 1060 IF ((N20130-J).LT.0) GO TO 1070\n CALL DSCAL(NN, T, HH(1,J), 1)\n GO TO 1050\n 1070 CONTINUE\n 1080 GO TO NGO, (70, 110, 270, 310, 470, 510, 550)\n END\n\nC PROGRAM CLSTST (INPUT,OUTPUT,TAPE5=INPUT,TAPE6=OUTPUT) MAN 10\nC MAN 20\nC TO CONVERT THE CONSTRAINED LEAST SQUARES PACKAGE OF SUBPROGRAMS MAN 30\nC TO DOUBLE PRECISION, FOLLOW THE EDITING INSTRUCTIONS NEAR THE MAN 40\nC BEGINNING OF THE FOLLOWING SUBPROGRAMS MAN 50\nC LSEI(), LSI(), LPDP(), WNNLS(), WNLSM(), WNLIT(), MAN 60\nC HFTI(), H12(), DIFF(), AND THE TESTING SUBPROGRAM CLSTP(). MAN 70\nC REVISED 820305-2000 MAN 80\nC REVISED YYMMDD-HHMM MAN 90\nC MAN 100\nC MAN 110\nC CHANGE STRING /DOUBLE PRECISION /DOUBLE PRECISION/, AND MAN 120\nC CHANGE STRING /E12/D12/ MAN 130\n DOUBLE PRECISION COND(3) MAN 140\n INTEGER KLOG(5) MAN 150\n LOGICAL DONE MAN 160\nC MAN 170\n LIN = 5 MAN 180\n LOUT = I1MACH(4) MAN 190\nC MAN 200\nC MAN 210\nC READ IN THE LOGS OF THE VARIOUS DIMENSIONS. MAN 220\n 10 READ (LIN,99999) (KLOG(I),I=1,5) MAN 230\n99999 FORMAT (5I5) MAN 240\n DONE = KLOG(5).LT.0 MAN 250\n IF (.NOT.(DONE)) GO TO 20 MAN 260\n GO TO 30 MAN 270\nC MAN 280\nC READ THE CONDITION NUMBERS FOR THE THREE MATRICES. MAN 290\n 20 READ (LIN,99998) (COND(I),I=1,3) MAN 300\n99998 FORMAT (3F10.0) MAN 310\nC MAN 320\n WRITE (LOUT,99997) KLOG, COND MAN 330\n99997 FORMAT (/////17H KLOG(*) ARRAY = , 5I5/17H COND(*) ARRAY = , MAN 340\n * 3E12.4) MAN 350\nC MAN 360\nC CALL TESTING SUBPROGRAM TO FORM CONSTRAINED LEAST SQUARES MAN 370\nC SYSTEM AND SOLVE IT. MAN 380\n CALL CLSTP(KLOG, COND, ISTAT) MAN 390\nC MAN 400\n WRITE (LOUT,99996) ISTAT MAN 410\n99996 FORMAT (/23H FROM CLSTP( ), ISTAT =, I2, 2X, 16H(ISTAT=4 IS GOOD/ MAN 420\n * 27X, 24H ISTAT=1,2,3 MAY BE BAD)) MAN 430\nC MAN 440\n GO TO 10 MAN 450\n 30 STOP MAN 460\n END MAN 470\n\n REAL FUNCTION RAN(K) RAN 10\nC\nC RANDOM NUMBER GENERATOR - BASED ON ALGORITHM 266\nC BY PIKE AND HILL (MODIFIED BY HANSSON)\nC COLLECTED ALG. FROM CACM.\nC\nC THIS SUBPROGRAM IS INTENDED FOR USE ON COMPUTERS WITH\nC FIXED POINT WORDLENGTH OF AT LEAST 29 BITS. IT IS\nC BEST IF THE FLOATING POINT SIGNIFICAND HAS AT MOST\nC 29 BITS.\nC\n INTEGER IY,K\n DATA IY/100001/\nC\n IF(K.GT.0) IY = K\n IY = IY * 125\n IY = IY - (IY/2796203) * 2796203\n RAN = FLOAT(IY) / 2796203.0E0\n RETURN\nC ---------- LAST CARD OF RAN ----------\n END\n", "meta": {"hexsha": "0f17ce9d082f5a603f847af51f4026c9c435ade3", "size": 20614, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "hanson-haskell/fortran-tests/clstp.f", "max_stars_repo_name": "jhu-cisst/cisstNetlib", "max_stars_repo_head_hexsha": "19932915dc3e24bddeff7078b270f862e86e3f9e", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-10-19T03:12:28.000Z", "max_stars_repo_stars_event_max_datetime": "2017-10-19T03:12:28.000Z", "max_issues_repo_path": "hanson-haskell/fortran-tests/clstp.f", "max_issues_repo_name": "jhu-cisst/cisstNetlib", "max_issues_repo_head_hexsha": "19932915dc3e24bddeff7078b270f862e86e3f9e", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2015-08-07T23:07:38.000Z", "max_issues_repo_issues_event_max_datetime": "2015-09-28T14:48:54.000Z", "max_forks_repo_path": "hanson-haskell/fortran-tests/clstp.f", "max_forks_repo_name": "jhu-cisst/cisstNetlib", "max_forks_repo_head_hexsha": "19932915dc3e24bddeff7078b270f862e86e3f9e", "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": 32.1090342679, "max_line_length": 80, "alphanum_fraction": 0.5023285146, "num_tokens": 7535, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213691605412, "lm_q2_score": 0.7371581684030624, "lm_q1q2_score": 0.6627946616624383}} {"text": " SUBROUTINE HSHLDR(A,N,NA)\nC \nC PURPOSE:\nC Reduce a real n x n matrix A to upper Hessenberg form by House-\nC holder's method of elementary Hermitian transformations.\nC REFERENCES:\nC Wilkinson, J.H.: The Algebraic Eigenvalue Problem. Clarendon\nC Press (Oxford), 1965.\nC Bartels, R.H.; and Stewart, G.W.: Algorithm 432 - Solution of\nC the Matrix Equation AX + XB = C. Commun. ACM, vol. 15, no. 9,\nC Sept. 1972, pp. 820-826.\nC \nC Subroutines employed by HSHLDR: None\nC Subroutines employing HSHLDR: ATXPXA, AXPXB\nC \n IMPLICIT REAL*8 (A-H,O-Z)\n REAL*8\n 1A(NA,1),MAX,SUM,S,P\n INTEGER\n 1N,NA,NM2,N1,L,L1,I,J\n NM2 = N-2\n N1 = N+1\n IF(N .EQ. 1) RETURN\n IF(N .GT. 2) GO TO 5\n A(1,N1) = A(2,1)\n RETURN\n 5 DO 80 L=1,NM2\n L1 = L+1\n MAX = 0.\n DO 10 I=L1,N\n MAX = DMAX1(MAX,DABS(A(I,L)))\n 10 CONTINUE\n IF(MAX .NE. 0.) GO TO 20\n A(L,N1) = 0.\n A(N1,L) = 0.\n GO TO 80\n 20 SUM = 0.\n DO 30 I=L1,N\n A(I,L) = A(I,L)/MAX\n SUM = SUM + A(I,L)**2\n 30 CONTINUE\n S = DSIGN(DSQRT(SUM),A(L1,L))\n A(L,N1) = -MAX*S\n A(L1,L) = S + A(L1,L)\n A(N1,L) = S*A(L1,L)\n DO 50 J=L1,N\n SUM = 0.\n DO 40 I=L1,N\n SUM = SUM + A(I,L)*A(I,J)\n 40 CONTINUE\n P = SUM/A(N1,L)\n DO 50 I=L1,N\n A(I,J) = A(I,J) - A(I,L)*P\n 50 CONTINUE\n DO 70 I=1,N\n SUM = 0.\n DO 60 J=L1,N\n SUM = SUM + A(I,J)*A(J,L)\n 60 CONTINUE\n P = SUM/A(N1,L)\n DO 70 J=L1,N\n A(I,J) = A(I,J) - P*A(J,L)\n 70 CONTINUE\n 80 CONTINUE\n A(N-1,N1) = A(N,N-1)\n RETURN\n END\n", "meta": {"hexsha": "7422e769b70a702db1ebf05cfd9d06f5beb648c0", "size": 1777, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "gsc-13067/iac/diriac2/oracls/hshldr.for", "max_stars_repo_name": "SteveDoyle2/nasa-cosmic", "max_stars_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_stars_repo_licenses": ["BSD-Source-Code"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2015-03-14T07:26:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-16T12:23:17.000Z", "max_issues_repo_path": "gsc-13067/iac/diriac2/oracls/hshldr.for", "max_issues_repo_name": "SteveDoyle2/nasa-cosmic", "max_issues_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_issues_repo_licenses": ["BSD-Source-Code"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gsc-13067/iac/diriac2/oracls/hshldr.for", "max_forks_repo_name": "SteveDoyle2/nasa-cosmic", "max_forks_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_forks_repo_licenses": ["BSD-Source-Code"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2016-02-12T22:18:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-08T17:46:54.000Z", "avg_line_length": 26.1323529412, "max_line_length": 71, "alphanum_fraction": 0.469330332, "num_tokens": 689, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762114, "lm_q2_score": 0.7371581568543043, "lm_q1q2_score": 0.6627946612418897}} {"text": "Program final\n\tImplicit none\n\treal*8 :: infty, x, dx, e, de, tol\n\treal*8, dimension(2) :: y\n\treal*8, external :: f_x, g_x\n\tcharacter (len=10) :: filename\n\tinteger :: n=1\n\n! parameters\n\ttol = epsilon(0.0d0) ! tolerance of 0\n\te = -8.0d0 ! lower bound energy level\n\tde = 1.d-2/7 ! energy resolution\n\tinfty = 2.4d0 ! where psi(infty) is considered to be tol\n\tdx = de*10d0\n\n\tdo while ( n.le.4 )\n\n\t\tx = -infty\n\t\ty(1) = tol ! initial psi at x=infty\n\t\ty(2) = tol ! initial psi' at x=infty\n\n\t\twrite(filename , '(\"res\",i1,\".dat\")') n\n\t\topen(10, file=filename)\n\n\t\tdo while( .true. )\n\t\t\tcall rk4(x, dx, f_x, g_x, y, e)\n\t\t\tif (x.lt.infty) then\n\t\t\t\twrite (10,*) x, y(1), y(2)\n\t\t\telse\n\t\t\t\texit\n\t\t\tendif\n\t\t\tx = x + dx\n\t\tenddo\n\n\t\tif (abs(y(1)).lt.tol) then\n\t\t\tprint *, \"eigenvalue\", e, \" psi(\",x,\")=\",y(1)\n\t\t\tn = n + 1\n\t\t\te = e + 0.21d-1\n\t\tendif\n\n\t\te = e + de\n\t\tclose(10)\n\tenddo\n\nend program final\n\n\n! 4th-order Runge-Kutta subroutine \nsubroutine rk4(x, dx, df, dg, y, e)\n\timplicit none\n\treal*8, external :: df, dg\n\treal*8, intent(in) :: x, dx, e\n\treal*8, intent(inout), dimension(2) :: y\n\treal*8 :: h, k0, k1, k2, k3, l0, l1, l2, l3\n\n\th=dx/2.0D0\n\n\tk0 = dx * df(y(1),y(2))\n\tl0 = dx * dg(y(1),y(2),x,e)\n\tk1 = dx * df(y(1)+h, y(2)+0.5d0*l0)\n\tl1 = dx * dg(y(1)+0.5d0*k0,y(2)+0.5d0*l0,x,e)\n\tk2 = dx * df(y(1)+0.5d0*k1,y(2)+0.5d0*l1)\n\tl2 = dx * dg(y(1)+0.5d0*k1,y(2)+0.5d0*l1,x,e)\n\tk3 = dx * df(y(1)+k2,y(2)+l2)\n\tl3 = dx * dg(y(1)+k2,y(2)+l2,x,e)\n\ty(1) = y(1) + (k0+2*k1+2*k2+k3)/6.0d0\n\ty(2) = y(2) + (l0+2*l1+2*l2+l3)/6.0d0\n\tReturn\nEnd subroutine rk4\n\n! function which returns the derivatives (RHS)\nreal*8 function f_x(y, yp)\n! dpsi/dx = psi'\n\tImplicit none\n\treal*8 ,intent(in) :: y, yp\n\tf_x = yp\n\tReturn\nEnd function f_x\n\nreal*8 function g_x(y, yp, x, e)\n! d^2y/dx^2 = 2(V(x)-e)*y = (4x^4-16x^2-2e)y\n\timplicit none\n\treal*8, intent(in) :: y, yp, x, e\n!\tg_x = ( -4.0d0 - e) * y\n!\tg_x = ( 4.0d0 * x**4.0d0 - 16.0d0 * x**2.0d0 - 2.0d0*e) * y\n\tg_x = 2.d0 * ( (x+sqrt(2.d0))**2.d0-8 - e) * y\n\tReturn\nEnd function g_x", "meta": {"hexsha": "4947aec5459ac05bc8afe378cc0583a70dddee11", "size": 1991, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Final/final.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": "Final/final.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": "Final/final.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": 22.625, "max_line_length": 61, "alphanum_fraction": 0.5635359116, "num_tokens": 951, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379296, "lm_q2_score": 0.743168019989179, "lm_q1q2_score": 0.6627654488425859}} {"text": "MODULE m_gaunt\n!*********************************************************************\n! Modified module to include old gaunt_init subroutine\n! the private arrays are allocated and computed in the first call to gaunt1\n! Daniel Wortmann\n!*********************************************************************\n PRIVATE\n INTEGER,SAVE :: lmaxdp\n REAL,SAVE,ALLOCATABLE::w(:),yr(:,:)\n PUBLIC gaunt1, gaunt_init\nCONTAINS\n FUNCTION gaunt1(lp,l,ls,mp,m,ms,lmaxd)\n!*********************************************************************\n! gaunt computes the integral of conjg(y(lp,mp))*y(l,m)*y(ls,ms)\n! for lp+l+ls .lt. 2*ngntd\n! using gaussian quadrature as given by\n! m. abramowitz and i.a. stegun, handbook of mathematical functions,\n! nbs applied mathematics series 55 (1968), pages 887 and 916\n! m. weinert and e. wimmer\n! northwestern university march 1980\n! modified to use calculated points and weights\n! to make it dynamic. (m.w. jan. 1982)\n!*********************************************************************\n USE m_judft\n IMPLICIT NONE\n INTEGER,INTENT(IN) :: l,lp,ls,m,mp,ms,lmaxd\n REAL :: gaunt1\n INTEGER :: i,il,ilp,ils,n\n\n\n n= (3*lmaxd)/4+1\n! heck if this is first call to subroutine\n IF(.NOT. ALLOCATED(YR)) CALL gaunt_init(lmaxd)\n! heck if the previous call of the subroutine was with the same lmaxd\n IF(lmaxd > lmaxdp) call juDFT_error(\"Can't calc gaunt. lmaxd too high\")\n\n gaunt1 = 0.0\n IF (mp /= (m+ms)) RETURN\n IF (MOD((l+lp+ls),2) == 1) RETURN\n IF ((l+lp-ls) < 0) RETURN\n IF ((l-lp+ls) < 0) RETURN\n IF ((lp-l+ls) < 0) RETURN\n\n il = l * (l + 1) + m + 1\n ilp = lp * (lp + 1) + mp + 1\n ils = ls * (ls + 1) + ms + 1\n\n gaunt1 = dot_product(w, yr(:,ilp)*yr(:,il)*yr(:,ils))\n END FUNCTION\n\n! private subroutine for initializing the private arrays!\n SUBROUTINE gaunt_init(lmaxd)\n!**********************************************************************\n! sets up values needed for gaunt1\n! m. weinert january 1982\n!**********************************************************************\n USE m_constants, ONLY : pimach\n USE m_grule\n USE m_juDFT_stop\n IMPLICIT NONE\n\n INTEGER, INTENT (IN) :: lmaxd\n REAL :: a,cd,cth,fac,fpi,rf,sgm,sth,t\n INTEGER :: k,l,lm,lomax,m\n INTEGER :: n,lmax1d\n REAL :: p(0:lmaxd+1,0:lmaxd+1),x((3*lmaxd)/4+1)\n\n if (allocated(w)) return\n n = (3*lmaxd)/4+1\n ALLOCATE(w(n), source=0.0)\n ALLOCATE(yr(n,(lmaxd+1)**2), source=0.0)\n lmaxdp = lmaxd\n lmax1d = lmaxd+1\n\n fpi = 4.0 * pimach()\n rf = fpi** (1./3.)\n lomax = lmax1d - 1\n!---> obtain gauss-legendre points and weights\n CALL grule(2*n,x,w)\n!---> generate associated legendre functions for m.ge.0\n DO k = 1,n\n cth = x(k)\n sth = sqrt(1.0-cth*cth)\n fac = 1.0\n !---> loop over m values\n DO m = 0,lomax\n fac = - (2*m-1)*fac\n p(m,m) = fac\n p(m+1,m) = (2*m+1)*cth*fac\n !---> recurse upward in l\n DO l = m + 2,lomax\n p(l,m) = ((2*l-1)*cth*p(l-1,m)- (l+m-1)*p(l-2,m))/ (l-m)\n ENDDO\n fac = fac*sth\n ENDDO\n !---> multiply in the normalization factors\n DO l = 0,lomax\n a = rf*sqrt((2*l+1)/fpi)\n cd = 1\n lm = l* (l+1) + 1\n yr(k,lm) = a*p(l,0)\n sgm = -1.\n DO m = 1,l\n t = (l+1-m)* (l+m)\n cd = cd/t\n yr(k,lm+m) = a*sqrt(cd)*p(l,m)\n yr(k,lm-m) = sgm*a*sqrt(cd)*p(l,m)\n sgm = -sgm\n ENDDO\n ENDDO\n ENDDO\n END SUBROUTINE\nEND MODULE\n", "meta": {"hexsha": "bd058c82e06126e993421cea446849acf380d173", "size": 3860, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "xc-pot/gaunt.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": "xc-pot/gaunt.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": "xc-pot/gaunt.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.8596491228, "max_line_length": 79, "alphanum_fraction": 0.4606217617, "num_tokens": 1230, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110396870287, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6627654394957679}} {"text": "C PROGRAM No. 4: CONSTANT STRENGTH DOUBLET\nC ----------------------------------------\nC THIS PROGRAM FINDS THE PRESSURE DISTRIBUTION ON AN ARBITRARY AIRFOIL\nC BY REPRESENTING THE SURFACE AS A FINITE NUMBER OF DOUBLET PANELS WITH\nC CONST. STRENGTH (NEUMANN B.C., PROGRAM BY STEVEN YON, 1989).\n\n REAL EP(400,2),EPT(400,2),PT1(400,2),PT2(400,2)\n REAL CO(400,2),A(400,400),B(400,400),G(400)\n REAL TH(400)\n\n OPEN(8,FILE='CPD.DAT',STATUS='NEW')\n OPEN(9,FILE='AFOIL2.DAT',STATUS='OLD')\n\n WRITE(6,*) 'ENTER NUMBER OF PANELS'\n READ(5,*) M\n N=M+1\n WRITE(6,*) 'ENTER ANGLE OF ATTACK IN DEGREES'\n READ(5,*) ALPHA\n AL=ALPHA/57.2958\n\nC READ IN THE PANEL END POINTS\n DO I=1,M+1\n READ(9,*) EPT(I,1), EPT(I,2)\n END DO\n\nC CONVERT PANELING TO CLOCKWISE\n DO I=1,M+1\n EP(I,1)=EPT(N-I+1,1)\n EP(I,2)=EPT(N-I+1,2)\n END DO\n\nC ESTABLISH COORDINATES OF PANEL END POINTS\n DO I=1,M\n PT1(I,1)=EP(I,1)\n PT2(I,1)=EP(I+1,1)\n PT1(I,2)=EP(I,2)\n PT2(I,2)=EP(I+1,2)\n END DO\n\nC FIND PANEL ANGLES TH(J)\n DO I=1,M\n DZ=PT2(I,2)-PT1(I,2)\n DX=PT2(I,1)-PT1(I,1)\n TH(I)=ATAN2(DZ,DX)\n END DO\n\nC ESTABLISH COLLOCATION POINTS\n DO I=1,M\n CO(I,1)=(PT2(I,1)-PT1(I,1))/2+PT1(I,1)\n CO(I,2)=(PT2(I,2)-PT1(I,2))/2+PT1(I,2)\n END DO\n\nC ESTABLISH INFLUENCE COEFFICIENTS\n DO I=1,M\n DO J=1,M\n\nC CONVERT THE COLLOCATION POINT\nC TO LOCAL PANEL COORDS.\n XT=CO(I,1)-PT1(J,1)\n ZT=CO(I,2)-PT1(J,2)\n X2T=PT2(J,1)-PT1(J,1)\n Z2T=PT2(J,2)-PT1(J,2)\n X=XT*COS(TH(J))+ZT*SIN(TH(J))\n Z=-XT*SIN(TH(J))+ZT*COS(TH(J))\n X2=X2T*COS(TH(J))+Z2T*SIN(TH(J))\n Z2=0\n\n R1=SQRT(X**2+Z**2)\n R2=SQRT((X-X2)**2+Z**2)\n\nC COMPUTE THE VELOCITY INDUCED AT THE ITH\nC COLLOCATION POINT BY THE JTH PANEL\n IF(I.EQ.J) THEN\n UL=0\n WL=-1/(3.14159265*X)\n ELSE\n UL=0.15916*(Z/(R1**2)-Z/(R2**2))\n WL=-0.15916*(X/(R1**2)-(X-X2)/(R2**2))\n END IF\n\n U=UL*COS(-TH(J))+WL*SIN(-TH(J))\n W=-UL*SIN(-TH(J))+WL*COS(-TH(J))\n\nC A(I,J) IS THE COMPONENT OF VELOCITY INDUCED IN THE\nC DIRECTION NORMAL TO PANEL I BY PANEL J AT THE ITH\nC COLLOCATION POINT\n\n A(I,J)=-U*SIN(TH(I))+W*COS(TH(I))\n B(I,J)=U*COS(TH(I))+W*SIN(TH(I))\n END DO\n\nC INCLUDE THE INFLUENCE OF THE WAKE PANEL\n R=SQRT((CO(I,1)-PT2(M,1))**2\n * +(CO(I,2)-PT2(M,2))**2)\n\n U=0.15916*(CO(I,2)/(R**2))\n W=-0.15916*(CO(I,1)-PT2(M,1))/(R**2)\n\n A(I,N)=-U*SIN(TH(I))+W*COS(TH(I))\n B(I,N)=U*COS(TH(I))+W*SIN(TH(I))\n A(I,N+1)=COS(AL)*SIN(TH(I))-SIN(AL)*COS(TH(I))\n END DO\n\nC PREPARE THE MATRIX FOR SOLUTION BY PROVIDING\nC A KUTTA CONDITION\n DO I=1,N+1\n A(N,I)=0\n END DO\n A(N,1)=-1\n A(N,M)=1\n A(N,N)=-1\n\nC SOLVE FOR THE SOLUTION VECTOR OF DOUBLET STRENGTHS\n\n N=N+1\n\n CALL MATRX(A,N,G)\n\nC CONVERT DOUBLET STRENGTHS INTO TANGENTIAL\nC VELOCITIES ALONG THE AIRFOIL SURFACE AND CP'S\nC ON EACH OF THE PANELS\n\n 200 CONTINUE\n\n DO I=1,M\n TEMP=0\n DO J=1,M+1\n TEMP=TEMP+B(I,J)*G(J)\n END DO\n IF(I.NE.1.AND.I.NE.M) THEN\n R=SQRT((CO(I+1,1)-CO(I-1,1))**2\n * +(CO(I+1,2)-CO(I-1,2))**2)\n VLOC=(G(I+1)-G(I-1))/R\n ELSE IF(I.EQ.1) THEN\n R=SQRT((CO(2,1)-CO(1,1))**2\n * +(CO(2,2)-CO(1,2))**2)\n VLOC=(G(2)-G(1))/R\n ELSE IF(I.EQ.M) THEN\n R=SQRT((CO(M,1)-CO(M-1,1))**2\n * +(CO(M,2)-CO(M-1,2))**2)\n VLOC=(G(M)-G(M-1))/R\n END IF\n\n VEL=COS(AL)*COS(TH(I))+SIN(AL)*SIN(TH(I))\n * +TEMP+VLOC/2\n CP=1-VEL**2\n WRITE(8,*) CO(I,1),' ,',CP\n\n END DO\n\n WRITE(6,*) ' '\n WRITE(6,*) 'LIFT COEFFICIENT=', G(M+1)\n\n STOP\n END\n\n SUBROUTINE MATRX(A,N,G)\nC MATRX IS A MATRIX REDUCER OF THE GAUSSIAN TYPE\nC A(I,J) IS THE MATRIX, A(I,N) IS THE RHS VECTOR\nC AND G(I) IS THE SOLUTION VECTOR.\n REAL A(400,400),TEMP(400,400),G(400)\nC INITIALIZE THE G VECTOR TO ALL ZEROES\n DO I=1,N-1\n G(I)=0\n END DO\n\nC CONVERT COEFFICIENT MATRIX TO\nC UPPER TRIANGULAR FORM\n DO I=1,N-1\n 5 IF(ABS(A(I,I)).LT.0.0000001) GOTO 9\n\n P=A(I,I)\n DO J=I,N\n A(I,J)=A(I,J)/P\n END DO\n DO K=I+1,N-1\n P2=A(K,I)\n DO L=I,N\n A(K,L)=A(K,L)-P2*A(I,L)\n END DO\n END DO\n END DO\n\nC BACK SUBSTITUTE TRIANGULARIZED MATRIX TO GET\nC VALUES OF SOLUTION VECTOR\n DO I=N-1,1,-1\n G(I)=A(I,N)\n DO J=1,N-1\n A(I,I)=0\n G(I)=G(I)-A(I,J)*G(J)\n END DO\n END DO\n RETURN\n\nC ORDER MATRIX SO THAT DIAGONAL COEFFICIENTS ARE\nC NOT =0 AND STOP IS MATRIX IS SINGULAR\n 9 IF(I.NE.N-1) THEN\n DO J=1,N\n TEMP(I,J)=A(I,J)\n A(I,J)=A(I+1,J)\n A(I+1,J)=TEMP(I,J)\n END DO\n GOTO 5\n ELSE\n GOTO 10\n END IF\n\n 10 WRITE(6,*) 'NO SOLUTION'\n STOP\n END\n", "meta": {"hexsha": "5801f7f0c445f8a9efe234615728a22255461012", "size": 5145, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "p04/p04.f", "max_stars_repo_name": "cibinjoseph/KatzPlotkin", "max_stars_repo_head_hexsha": "9029652ba1c5c2a5608e0f7e87dee9d401d56699", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-09-15T18:06:51.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-10T07:42:42.000Z", "max_issues_repo_path": "p04/p04.f", "max_issues_repo_name": "cibinjoseph/KatzPlotkin", "max_issues_repo_head_hexsha": "9029652ba1c5c2a5608e0f7e87dee9d401d56699", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "p04/p04.f", "max_forks_repo_name": "cibinjoseph/KatzPlotkin", "max_forks_repo_head_hexsha": "9029652ba1c5c2a5608e0f7e87dee9d401d56699", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-09-25T11:33:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-25T11:33:04.000Z", "avg_line_length": 24.3838862559, "max_line_length": 75, "alphanum_fraction": 0.4952380952, "num_tokens": 2054, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110569397307, "lm_q2_score": 0.743167997235783, "lm_q1q2_score": 0.6627654370986265}} {"text": " subroutine emcee_lnprob (ndim, p, lp)\n\n ! This subroutine demonstrates the syntax for implementing a\n ! log-probability function. This particular example implements\n ! an isotropic `ndim`-dimensional Gaussian with unit variance.\n !\n ! Inputs\n ! ------\n !\n ! ndim [integer]:\n ! The dimension of the parameter space.\n !\n ! pos [double precision (ndim)]:\n ! The position in parameter space where the probability should\n ! be computed.\n !\n ! Outputs\n ! -------\n !\n ! lp [double precision]:\n ! The log-probability computed at `pos`.\n\n implicit none\n\n integer, intent(in) :: ndim\n double precision, intent(in), dimension(ndim) :: p\n double precision, intent(out) :: lp\n\n integer :: i\n\n lp = 1.d0\n do i=1,ndim\n lp = lp + p(i)*p(i)\n enddo\n lp = -0.5d0 * lp\n\n end subroutine\n\n program main\n\n implicit none\n\n integer, parameter :: nwalkers=20, ndim=2\n double precision, dimension(ndim,nwalkers) :: pos\n double precision, dimension(nwalkers) :: lp\n integer, dimension(nwalkers) :: accept\n\n integer :: i, j\n\n ! First seed the random number generator... don't forget this!\n call init_random_seed ()\n\n ! Loop over the walkers and initialize their positions. In\n ! practice, you should initialize them more intelligently than\n ! this! Also, don't forget to compute the initial\n ! log-probabilities.\n do j=1,nwalkers\n\n ! Loop over the number of dimensions and initialize each one\n ! in the range `(0.5, 0.5)`.\n do i=1,ndim\n call random_number(pos(i,j))\n pos(i,j) = pos(i,j) - 0.5d0\n enddo\n\n ! Compute the initial log-probability.\n call emcee_lnprob(ndim, pos(:, j), lp(j))\n enddo\n\n ! Start by running a burn-in of 200 steps.\n do i=1,200\n ! You'll notice that I'm overwriting the position and\n ! log-probability of the ensemble at each step. This works but\n ! you also have the option of saving the samples by giving\n ! different input and output arguments.\n call emcee_advance (ndim,nwalkers,2.d0,pos,lp,pos,lp,accept)\n enddo\n\n ! Run a production chain of 500 steps and print to `stdout`.\n do i=1,500\n call emcee_advance (ndim,nwalkers,2.d0,pos,lp,pos,lp,accept)\n do j=1,nwalkers\n write(*,*) pos(:, j), lp(j)\n enddo\n enddo\n\n end program\n", "meta": {"hexsha": "3e2a246f49877b16fba7579d97ce8ce3bba6f9ba", "size": 2654, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/test.f95", "max_stars_repo_name": "bd-j/fmc", "max_stars_repo_head_hexsha": "1e92dcac07a773f259c31bdd64b33251174f1a6c", "max_stars_repo_licenses": ["MIT"], "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/test.f95", "max_issues_repo_name": "bd-j/fmc", "max_issues_repo_head_hexsha": "1e92dcac07a773f259c31bdd64b33251174f1a6c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/test.f95", "max_forks_repo_name": "bd-j/fmc", "max_forks_repo_head_hexsha": "1e92dcac07a773f259c31bdd64b33251174f1a6c", "max_forks_repo_licenses": ["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.1590909091, "max_line_length": 72, "alphanum_fraction": 0.5629238885, "num_tokens": 663, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110425624791, "lm_q2_score": 0.7431680086124812, "lm_q1q2_score": 0.6627654365597784}} {"text": "*> \\brief DGESVD computes the singular value decomposition (SVD) for GE matrices\n*\n* =========== DOCUMENTATION ===========\n*\n* Online html documentation available at \n* http://www.netlib.org/lapack/explore-html/ \n*\n*> \\htmlonly\n*> Download DGESVD + dependencies \n*> \n*> [TGZ] \n*> \n*> [ZIP] \n*> \n*> [TXT]\n*> \\endhtmlonly \n*\n* Definition:\n* ===========\n*\n* SUBROUTINE DGESVD( JOBU, JOBVT, M, N, A, LDA, S, U, LDU, VT, LDVT,\n* WORK, LWORK, INFO )\n* \n* .. Scalar Arguments ..\n* CHARACTER JOBU, JOBVT\n* INTEGER INFO, LDA, LDU, LDVT, LWORK, M, N\n* ..\n* .. Array Arguments ..\n* DOUBLE PRECISION A( LDA, * ), S( * ), U( LDU, * ),\n* $ VT( LDVT, * ), WORK( * )\n* ..\n* \n*\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*>\n*> DGESVD computes the singular value decomposition (SVD) of a real\n*> M-by-N matrix A, optionally computing the left and/or right singular\n*> vectors. The SVD is written\n*>\n*> A = U * SIGMA * transpose(V)\n*>\n*> where SIGMA is an M-by-N matrix which is zero except for its\n*> min(m,n) diagonal elements, U is an M-by-M orthogonal matrix, and\n*> V is an N-by-N orthogonal matrix. The diagonal elements of SIGMA\n*> are the singular values of A; they are real and non-negative, and\n*> are returned in descending order. The first min(m,n) columns of\n*> U and V are the left and right singular vectors of A.\n*>\n*> Note that the routine returns V**T, not V.\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in] JOBU\n*> \\verbatim\n*> JOBU is CHARACTER*1\n*> Specifies options for computing all or part of the matrix U:\n*> = 'A': all M columns of U are returned in array U:\n*> = 'S': the first min(m,n) columns of U (the left singular\n*> vectors) are returned in the array U;\n*> = 'O': the first min(m,n) columns of U (the left singular\n*> vectors) are overwritten on the array A;\n*> = 'N': no columns of U (no left singular vectors) are\n*> computed.\n*> \\endverbatim\n*>\n*> \\param[in] JOBVT\n*> \\verbatim\n*> JOBVT is CHARACTER*1\n*> Specifies options for computing all or part of the matrix\n*> V**T:\n*> = 'A': all N rows of V**T are returned in the array VT;\n*> = 'S': the first min(m,n) rows of V**T (the right singular\n*> vectors) are returned in the array VT;\n*> = 'O': the first min(m,n) rows of V**T (the right singular\n*> vectors) are overwritten on the array A;\n*> = 'N': no rows of V**T (no right singular vectors) are\n*> computed.\n*>\n*> JOBVT and JOBU cannot both be 'O'.\n*> \\endverbatim\n*>\n*> \\param[in] M\n*> \\verbatim\n*> M is INTEGER\n*> The number of rows of the input matrix A. M >= 0.\n*> \\endverbatim\n*>\n*> \\param[in] N\n*> \\verbatim\n*> N is INTEGER\n*> The number of columns of the input matrix A. N >= 0.\n*> \\endverbatim\n*>\n*> \\param[in,out] A\n*> \\verbatim\n*> A is DOUBLE PRECISION array, dimension (LDA,N)\n*> On entry, the M-by-N matrix A.\n*> On exit,\n*> if JOBU = 'O', A is overwritten with the first min(m,n)\n*> columns of U (the left singular vectors,\n*> stored columnwise);\n*> if JOBVT = 'O', A is overwritten with the first min(m,n)\n*> rows of V**T (the right singular vectors,\n*> stored rowwise);\n*> if JOBU .ne. 'O' and JOBVT .ne. 'O', the contents of A\n*> are destroyed.\n*> \\endverbatim\n*>\n*> \\param[in] LDA\n*> \\verbatim\n*> LDA is INTEGER\n*> The leading dimension of the array A. LDA >= max(1,M).\n*> \\endverbatim\n*>\n*> \\param[out] S\n*> \\verbatim\n*> S is DOUBLE PRECISION array, dimension (min(M,N))\n*> The singular values of A, sorted so that S(i) >= S(i+1).\n*> \\endverbatim\n*>\n*> \\param[out] U\n*> \\verbatim\n*> U is DOUBLE PRECISION array, dimension (LDU,UCOL)\n*> (LDU,M) if JOBU = 'A' or (LDU,min(M,N)) if JOBU = 'S'.\n*> If JOBU = 'A', U contains the M-by-M orthogonal matrix U;\n*> if JOBU = 'S', U contains the first min(m,n) columns of U\n*> (the left singular vectors, stored columnwise);\n*> if JOBU = 'N' or 'O', U is not referenced.\n*> \\endverbatim\n*>\n*> \\param[in] LDU\n*> \\verbatim\n*> LDU is INTEGER\n*> The leading dimension of the array U. LDU >= 1; if\n*> JOBU = 'S' or 'A', LDU >= M.\n*> \\endverbatim\n*>\n*> \\param[out] VT\n*> \\verbatim\n*> VT is DOUBLE PRECISION array, dimension (LDVT,N)\n*> If JOBVT = 'A', VT contains the N-by-N orthogonal matrix\n*> V**T;\n*> if JOBVT = 'S', VT contains the first min(m,n) rows of\n*> V**T (the right singular vectors, stored rowwise);\n*> if JOBVT = 'N' or 'O', VT is not referenced.\n*> \\endverbatim\n*>\n*> \\param[in] LDVT\n*> \\verbatim\n*> LDVT is INTEGER\n*> The leading dimension of the array VT. LDVT >= 1; if\n*> JOBVT = 'A', LDVT >= N; if JOBVT = 'S', LDVT >= min(M,N).\n*> \\endverbatim\n*>\n*> \\param[out] WORK\n*> \\verbatim\n*> WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK))\n*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK;\n*> if INFO > 0, WORK(2:MIN(M,N)) contains the unconverged\n*> superdiagonal elements of an upper bidiagonal matrix B\n*> whose diagonal is in S (not necessarily sorted). B\n*> satisfies A = U * B * VT, so it has the same singular values\n*> as A, and singular vectors related by U and VT.\n*> \\endverbatim\n*>\n*> \\param[in] LWORK\n*> \\verbatim\n*> LWORK is INTEGER\n*> The dimension of the array WORK.\n*> LWORK >= MAX(1,5*MIN(M,N)) for the paths (see comments inside code):\n*> - PATH 1 (M much larger than N, JOBU='N') \n*> - PATH 1t (N much larger than M, JOBVT='N')\n*> LWORK >= MAX(1,3*MIN(M,N)+MAX(M,N),5*MIN(M,N)) for the other paths\n*> For good performance, LWORK should generally be larger.\n*>\n*> If LWORK = -1, then a workspace query is assumed; the routine\n*> only calculates the optimal size of the WORK array, returns\n*> this value as the first entry of the WORK array, and no error\n*> message related to LWORK is issued by XERBLA.\n*> \\endverbatim\n*>\n*> \\param[out] INFO\n*> \\verbatim\n*> INFO is INTEGER\n*> = 0: successful exit.\n*> < 0: if INFO = -i, the i-th argument had an illegal value.\n*> > 0: if DBDSQR did not converge, INFO specifies how many\n*> superdiagonals of an intermediate bidiagonal form B\n*> did not converge to zero. See the description of WORK\n*> above for details.\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee \n*> \\author Univ. of California Berkeley \n*> \\author Univ. of Colorado Denver \n*> \\author NAG Ltd. \n*\n*> \\date April 2012\n*\n*> \\ingroup doubleGEsing\n*\n* =====================================================================\n SUBROUTINE DGESVD( JOBU, JOBVT, M, N, A, LDA, S, U, LDU,\n $ VT, LDVT, WORK, LWORK, INFO )\n*\n* -- LAPACK driver routine (version 3.4.1) --\n* -- LAPACK is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n* April 2012\n*\n* .. Scalar Arguments ..\n CHARACTER JOBU, JOBVT\n INTEGER INFO, LDA, LDU, LDVT, LWORK, M, N\n* ..\n* .. Array Arguments ..\n DOUBLE PRECISION A( LDA, * ), S( * ), U( LDU, * ),\n $ VT( LDVT, * ), WORK( * )\n* ..\n*\n* =====================================================================\n*\n* .. Parameters ..\n DOUBLE PRECISION ZERO, ONE\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )\n* ..\n* .. Local Scalars ..\n LOGICAL LQUERY, WNTUA, WNTUAS, WNTUN, WNTUO, WNTUS,\n $ WNTVA, WNTVAS, WNTVN, WNTVO, WNTVS\n INTEGER BDSPAC, BLK, CHUNK, I, IE, IERR, IR, ISCL,\n $ ITAU, ITAUP, ITAUQ, IU, IWORK, LDWRKR, LDWRKU,\n $ MAXWRK, MINMN, MINWRK, MNTHR, NCU, NCVT, NRU,\n $ NRVT, WRKBL\n INTEGER LWORK_DGEQRF, LWORK_DORGQR_N, LWORK_DORGQR_M,\n $ LWORK_DGEBRD, LWORK_DORGBR_P, LWORK_DORGBR_Q,\n $ LWORK_DGELQF, LWORK_DORGLQ_N, LWORK_DORGLQ_M\n DOUBLE PRECISION ANRM, BIGNUM, EPS, SMLNUM\n* ..\n* .. Local Arrays ..\n DOUBLE PRECISION DUM( 1 )\n* ..\n* .. External Subroutines ..\n EXTERNAL DBDSQR, DGEBRD, DGELQF, DGEMM, DGEQRF, DLACPY,\n $ DLASCL, DLASET, DORGBR, DORGLQ, DORGQR, DORMBR,\n $ XERBLA\n* ..\n* .. External Functions ..\n LOGICAL LSAME\n INTEGER ILAENV\n DOUBLE PRECISION DLAMCH, DLANGE\n EXTERNAL LSAME, ILAENV, DLAMCH, DLANGE\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC MAX, MIN, SQRT\n* ..\n* .. Executable Statements ..\n*\n* Test the input arguments\n*\n INFO = 0\n MINMN = MIN( M, N )\n WNTUA = LSAME( JOBU, 'A' )\n WNTUS = LSAME( JOBU, 'S' )\n WNTUAS = WNTUA .OR. WNTUS\n WNTUO = LSAME( JOBU, 'O' )\n WNTUN = LSAME( JOBU, 'N' )\n WNTVA = LSAME( JOBVT, 'A' )\n WNTVS = LSAME( JOBVT, 'S' )\n WNTVAS = WNTVA .OR. WNTVS\n WNTVO = LSAME( JOBVT, 'O' )\n WNTVN = LSAME( JOBVT, 'N' )\n LQUERY = ( LWORK.EQ.-1 )\n*\n IF( .NOT.( WNTUA .OR. WNTUS .OR. WNTUO .OR. WNTUN ) ) THEN\n INFO = -1\n ELSE IF( .NOT.( WNTVA .OR. WNTVS .OR. WNTVO .OR. WNTVN ) .OR.\n $ ( WNTVO .AND. WNTUO ) ) THEN\n INFO = -2\n ELSE IF( M.LT.0 ) THEN\n INFO = -3\n ELSE IF( N.LT.0 ) THEN\n INFO = -4\n ELSE IF( LDA.LT.MAX( 1, M ) ) THEN\n INFO = -6\n ELSE IF( LDU.LT.1 .OR. ( WNTUAS .AND. LDU.LT.M ) ) THEN\n INFO = -9\n ELSE IF( LDVT.LT.1 .OR. ( WNTVA .AND. LDVT.LT.N ) .OR.\n $ ( WNTVS .AND. LDVT.LT.MINMN ) ) THEN\n INFO = -11\n END IF\n*\n* Compute workspace\n* (Note: Comments in the code beginning \"Workspace:\" describe the\n* minimal amount of workspace needed at that point in the code,\n* as well as the preferred amount for good performance.\n* NB refers to the optimal block size for the immediately\n* following subroutine, as returned by ILAENV.)\n*\n IF( INFO.EQ.0 ) THEN\n MINWRK = 1\n MAXWRK = 1\n IF( M.GE.N .AND. MINMN.GT.0 ) THEN\n*\n* Compute space needed for DBDSQR\n*\n MNTHR = ILAENV( 6, 'DGESVD', JOBU // JOBVT, M, N, 0, 0 )\n BDSPAC = 5*N\n* Compute space needed for DGEQRF\n CALL DGEQRF( M, N, A, LDA, DUM(1), DUM(1), -1, IERR )\n LWORK_DGEQRF=DUM(1)\n* Compute space needed for DORGQR\n CALL DORGQR( M, N, N, A, LDA, DUM(1), DUM(1), -1, IERR )\n LWORK_DORGQR_N=DUM(1)\n CALL DORGQR( M, M, N, A, LDA, DUM(1), DUM(1), -1, IERR )\n LWORK_DORGQR_M=DUM(1)\n* Compute space needed for DGEBRD\n CALL DGEBRD( N, N, A, LDA, S, DUM(1), DUM(1),\n $ DUM(1), DUM(1), -1, IERR )\n LWORK_DGEBRD=DUM(1)\n* Compute space needed for DORGBR P\n CALL DORGBR( 'P', N, N, N, A, LDA, DUM(1),\n $ DUM(1), -1, IERR )\n LWORK_DORGBR_P=DUM(1)\n* Compute space needed for DORGBR Q\n CALL DORGBR( 'Q', N, N, N, A, LDA, DUM(1),\n $ DUM(1), -1, IERR )\n LWORK_DORGBR_Q=DUM(1)\n*\n IF( M.GE.MNTHR ) THEN\n IF( WNTUN ) THEN\n*\n* Path 1 (M much larger than N, JOBU='N')\n*\n MAXWRK = N + LWORK_DGEQRF\n MAXWRK = MAX( MAXWRK, 3*N+LWORK_DGEBRD )\n IF( WNTVO .OR. WNTVAS )\n $ MAXWRK = MAX( MAXWRK, 3*N+LWORK_DORGBR_P )\n MAXWRK = MAX( MAXWRK, BDSPAC )\n MINWRK = MAX( 4*N, BDSPAC )\n ELSE IF( WNTUO .AND. WNTVN ) THEN\n*\n* Path 2 (M much larger than N, JOBU='O', JOBVT='N')\n*\n WRKBL = N + LWORK_DGEQRF\n WRKBL = MAX( WRKBL, N+LWORK_DORGQR_N )\n WRKBL = MAX( WRKBL, 3*N+LWORK_DGEBRD )\n WRKBL = MAX( WRKBL, 3*N+LWORK_DORGBR_Q )\n WRKBL = MAX( WRKBL, BDSPAC )\n MAXWRK = MAX( N*N+WRKBL, N*N+M*N+N )\n MINWRK = MAX( 3*N+M, BDSPAC )\n ELSE IF( WNTUO .AND. WNTVAS ) THEN\n*\n* Path 3 (M much larger than N, JOBU='O', JOBVT='S' or\n* 'A')\n*\n WRKBL = N + LWORK_DGEQRF\n WRKBL = MAX( WRKBL, N+LWORK_DORGQR_N )\n WRKBL = MAX( WRKBL, 3*N+LWORK_DGEBRD )\n WRKBL = MAX( WRKBL, 3*N+LWORK_DORGBR_Q )\n WRKBL = MAX( WRKBL, 3*N+LWORK_DORGBR_P )\n WRKBL = MAX( WRKBL, BDSPAC )\n MAXWRK = MAX( N*N+WRKBL, N*N+M*N+N )\n MINWRK = MAX( 3*N+M, BDSPAC )\n ELSE IF( WNTUS .AND. WNTVN ) THEN\n*\n* Path 4 (M much larger than N, JOBU='S', JOBVT='N')\n*\n WRKBL = N + LWORK_DGEQRF\n WRKBL = MAX( WRKBL, N+LWORK_DORGQR_N )\n WRKBL = MAX( WRKBL, 3*N+LWORK_DGEBRD )\n WRKBL = MAX( WRKBL, 3*N+LWORK_DORGBR_Q )\n WRKBL = MAX( WRKBL, BDSPAC )\n MAXWRK = N*N + WRKBL\n MINWRK = MAX( 3*N+M, BDSPAC )\n ELSE IF( WNTUS .AND. WNTVO ) THEN\n*\n* Path 5 (M much larger than N, JOBU='S', JOBVT='O')\n*\n WRKBL = N + LWORK_DGEQRF\n WRKBL = MAX( WRKBL, N+LWORK_DORGQR_N )\n WRKBL = MAX( WRKBL, 3*N+LWORK_DGEBRD )\n WRKBL = MAX( WRKBL, 3*N+LWORK_DORGBR_Q )\n WRKBL = MAX( WRKBL, 3*N+LWORK_DORGBR_P )\n WRKBL = MAX( WRKBL, BDSPAC )\n MAXWRK = 2*N*N + WRKBL\n MINWRK = MAX( 3*N+M, BDSPAC )\n ELSE IF( WNTUS .AND. WNTVAS ) THEN\n*\n* Path 6 (M much larger than N, JOBU='S', JOBVT='S' or\n* 'A')\n*\n WRKBL = N + LWORK_DGEQRF\n WRKBL = MAX( WRKBL, N+LWORK_DORGQR_N )\n WRKBL = MAX( WRKBL, 3*N+LWORK_DGEBRD )\n WRKBL = MAX( WRKBL, 3*N+LWORK_DORGBR_Q )\n WRKBL = MAX( WRKBL, 3*N+LWORK_DORGBR_P )\n WRKBL = MAX( WRKBL, BDSPAC )\n MAXWRK = N*N + WRKBL\n MINWRK = MAX( 3*N+M, BDSPAC )\n ELSE IF( WNTUA .AND. WNTVN ) THEN\n*\n* Path 7 (M much larger than N, JOBU='A', JOBVT='N')\n*\n WRKBL = N + LWORK_DGEQRF\n WRKBL = MAX( WRKBL, N+LWORK_DORGQR_M )\n WRKBL = MAX( WRKBL, 3*N+LWORK_DGEBRD )\n WRKBL = MAX( WRKBL, 3*N+LWORK_DORGBR_Q )\n WRKBL = MAX( WRKBL, BDSPAC )\n MAXWRK = N*N + WRKBL\n MINWRK = MAX( 3*N+M, BDSPAC )\n ELSE IF( WNTUA .AND. WNTVO ) THEN\n*\n* Path 8 (M much larger than N, JOBU='A', JOBVT='O')\n*\n WRKBL = N + LWORK_DGEQRF\n WRKBL = MAX( WRKBL, N+LWORK_DORGQR_M )\n WRKBL = MAX( WRKBL, 3*N+LWORK_DGEBRD )\n WRKBL = MAX( WRKBL, 3*N+LWORK_DORGBR_Q )\n WRKBL = MAX( WRKBL, 3*N+LWORK_DORGBR_P )\n WRKBL = MAX( WRKBL, BDSPAC )\n MAXWRK = 2*N*N + WRKBL\n MINWRK = MAX( 3*N+M, BDSPAC )\n ELSE IF( WNTUA .AND. WNTVAS ) THEN\n*\n* Path 9 (M much larger than N, JOBU='A', JOBVT='S' or\n* 'A')\n*\n WRKBL = N + LWORK_DGEQRF\n WRKBL = MAX( WRKBL, N+LWORK_DORGQR_M )\n WRKBL = MAX( WRKBL, 3*N+LWORK_DGEBRD )\n WRKBL = MAX( WRKBL, 3*N+LWORK_DORGBR_Q )\n WRKBL = MAX( WRKBL, 3*N+LWORK_DORGBR_P )\n WRKBL = MAX( WRKBL, BDSPAC )\n MAXWRK = N*N + WRKBL\n MINWRK = MAX( 3*N+M, BDSPAC )\n END IF\n ELSE\n*\n* Path 10 (M at least N, but not much larger)\n*\n CALL DGEBRD( M, N, A, LDA, S, DUM(1), DUM(1),\n $ DUM(1), DUM(1), -1, IERR )\n LWORK_DGEBRD=DUM(1)\n MAXWRK = 3*N + LWORK_DGEBRD\n IF( WNTUS .OR. WNTUO ) THEN\n CALL DORGBR( 'Q', M, N, N, A, LDA, DUM(1),\n $ DUM(1), -1, IERR )\n LWORK_DORGBR_Q=DUM(1)\n MAXWRK = MAX( MAXWRK, 3*N+LWORK_DORGBR_Q )\n END IF\n IF( WNTUA ) THEN\n CALL DORGBR( 'Q', M, M, N, A, LDA, DUM(1),\n $ DUM(1), -1, IERR )\n LWORK_DORGBR_Q=DUM(1)\n MAXWRK = MAX( MAXWRK, 3*N+LWORK_DORGBR_Q )\n END IF\n IF( .NOT.WNTVN ) THEN\n MAXWRK = MAX( MAXWRK, 3*N+LWORK_DORGBR_P )\n END IF\n MAXWRK = MAX( MAXWRK, BDSPAC )\n MINWRK = MAX( 3*N+M, BDSPAC )\n END IF\n ELSE IF( MINMN.GT.0 ) THEN\n*\n* Compute space needed for DBDSQR\n*\n MNTHR = ILAENV( 6, 'DGESVD', JOBU // JOBVT, M, N, 0, 0 )\n BDSPAC = 5*M\n* Compute space needed for DGELQF\n CALL DGELQF( M, N, A, LDA, DUM(1), DUM(1), -1, IERR )\n LWORK_DGELQF=DUM(1)\n* Compute space needed for DORGLQ\n CALL DORGLQ( N, N, M, DUM(1), N, DUM(1), DUM(1), -1, IERR )\n LWORK_DORGLQ_N=DUM(1)\n CALL DORGLQ( M, N, M, A, LDA, DUM(1), DUM(1), -1, IERR )\n LWORK_DORGLQ_M=DUM(1)\n* Compute space needed for DGEBRD\n CALL DGEBRD( M, M, A, LDA, S, DUM(1), DUM(1),\n $ DUM(1), DUM(1), -1, IERR )\n LWORK_DGEBRD=DUM(1)\n* Compute space needed for DORGBR P\n CALL DORGBR( 'P', M, M, M, A, N, DUM(1),\n $ DUM(1), -1, IERR )\n LWORK_DORGBR_P=DUM(1)\n* Compute space needed for DORGBR Q\n CALL DORGBR( 'Q', M, M, M, A, N, DUM(1),\n $ DUM(1), -1, IERR )\n LWORK_DORGBR_Q=DUM(1)\n IF( N.GE.MNTHR ) THEN\n IF( WNTVN ) THEN\n*\n* Path 1t(N much larger than M, JOBVT='N')\n*\n MAXWRK = M + LWORK_DGELQF\n MAXWRK = MAX( MAXWRK, 3*M+LWORK_DGEBRD )\n IF( WNTUO .OR. WNTUAS )\n $ MAXWRK = MAX( MAXWRK, 3*M+LWORK_DORGBR_Q )\n MAXWRK = MAX( MAXWRK, BDSPAC )\n MINWRK = MAX( 4*M, BDSPAC )\n ELSE IF( WNTVO .AND. WNTUN ) THEN\n*\n* Path 2t(N much larger than M, JOBU='N', JOBVT='O')\n*\n WRKBL = M + LWORK_DGELQF\n WRKBL = MAX( WRKBL, M+LWORK_DORGLQ_M )\n WRKBL = MAX( WRKBL, 3*M+LWORK_DGEBRD )\n WRKBL = MAX( WRKBL, 3*M+LWORK_DORGBR_P )\n WRKBL = MAX( WRKBL, BDSPAC )\n MAXWRK = MAX( M*M+WRKBL, M*M+M*N+M )\n MINWRK = MAX( 3*M+N, BDSPAC )\n ELSE IF( WNTVO .AND. WNTUAS ) THEN\n*\n* Path 3t(N much larger than M, JOBU='S' or 'A',\n* JOBVT='O')\n*\n WRKBL = M + LWORK_DGELQF\n WRKBL = MAX( WRKBL, M+LWORK_DORGLQ_M )\n WRKBL = MAX( WRKBL, 3*M+LWORK_DGEBRD )\n WRKBL = MAX( WRKBL, 3*M+LWORK_DORGBR_P )\n WRKBL = MAX( WRKBL, 3*M+LWORK_DORGBR_Q )\n WRKBL = MAX( WRKBL, BDSPAC )\n MAXWRK = MAX( M*M+WRKBL, M*M+M*N+M )\n MINWRK = MAX( 3*M+N, BDSPAC )\n ELSE IF( WNTVS .AND. WNTUN ) THEN\n*\n* Path 4t(N much larger than M, JOBU='N', JOBVT='S')\n*\n WRKBL = M + LWORK_DGELQF\n WRKBL = MAX( WRKBL, M+LWORK_DORGLQ_M )\n WRKBL = MAX( WRKBL, 3*M+LWORK_DGEBRD )\n WRKBL = MAX( WRKBL, 3*M+LWORK_DORGBR_P )\n WRKBL = MAX( WRKBL, BDSPAC )\n MAXWRK = M*M + WRKBL\n MINWRK = MAX( 3*M+N, BDSPAC )\n ELSE IF( WNTVS .AND. WNTUO ) THEN\n*\n* Path 5t(N much larger than M, JOBU='O', JOBVT='S')\n*\n WRKBL = M + LWORK_DGELQF\n WRKBL = MAX( WRKBL, M+LWORK_DORGLQ_M )\n WRKBL = MAX( WRKBL, 3*M+LWORK_DGEBRD )\n WRKBL = MAX( WRKBL, 3*M+LWORK_DORGBR_P )\n WRKBL = MAX( WRKBL, 3*M+LWORK_DORGBR_Q )\n WRKBL = MAX( WRKBL, BDSPAC )\n MAXWRK = 2*M*M + WRKBL\n MINWRK = MAX( 3*M+N, BDSPAC )\n ELSE IF( WNTVS .AND. WNTUAS ) THEN\n*\n* Path 6t(N much larger than M, JOBU='S' or 'A',\n* JOBVT='S')\n*\n WRKBL = M + LWORK_DGELQF\n WRKBL = MAX( WRKBL, M+LWORK_DORGLQ_M )\n WRKBL = MAX( WRKBL, 3*M+LWORK_DGEBRD )\n WRKBL = MAX( WRKBL, 3*M+LWORK_DORGBR_P )\n WRKBL = MAX( WRKBL, 3*M+LWORK_DORGBR_Q )\n WRKBL = MAX( WRKBL, BDSPAC )\n MAXWRK = M*M + WRKBL\n MINWRK = MAX( 3*M+N, BDSPAC )\n ELSE IF( WNTVA .AND. WNTUN ) THEN\n*\n* Path 7t(N much larger than M, JOBU='N', JOBVT='A')\n*\n WRKBL = M + LWORK_DGELQF\n WRKBL = MAX( WRKBL, M+LWORK_DORGLQ_N )\n WRKBL = MAX( WRKBL, 3*M+LWORK_DGEBRD )\n WRKBL = MAX( WRKBL, 3*M+LWORK_DORGBR_P )\n WRKBL = MAX( WRKBL, BDSPAC )\n MAXWRK = M*M + WRKBL\n MINWRK = MAX( 3*M+N, BDSPAC )\n ELSE IF( WNTVA .AND. WNTUO ) THEN\n*\n* Path 8t(N much larger than M, JOBU='O', JOBVT='A')\n*\n WRKBL = M + LWORK_DGELQF\n WRKBL = MAX( WRKBL, M+LWORK_DORGLQ_N )\n WRKBL = MAX( WRKBL, 3*M+LWORK_DGEBRD )\n WRKBL = MAX( WRKBL, 3*M+LWORK_DORGBR_P )\n WRKBL = MAX( WRKBL, 3*M+LWORK_DORGBR_Q )\n WRKBL = MAX( WRKBL, BDSPAC )\n MAXWRK = 2*M*M + WRKBL\n MINWRK = MAX( 3*M+N, BDSPAC )\n ELSE IF( WNTVA .AND. WNTUAS ) THEN\n*\n* Path 9t(N much larger than M, JOBU='S' or 'A',\n* JOBVT='A')\n*\n WRKBL = M + LWORK_DGELQF\n WRKBL = MAX( WRKBL, M+LWORK_DORGLQ_N )\n WRKBL = MAX( WRKBL, 3*M+LWORK_DGEBRD )\n WRKBL = MAX( WRKBL, 3*M+LWORK_DORGBR_P )\n WRKBL = MAX( WRKBL, 3*M+LWORK_DORGBR_Q )\n WRKBL = MAX( WRKBL, BDSPAC )\n MAXWRK = M*M + WRKBL\n MINWRK = MAX( 3*M+N, BDSPAC )\n END IF\n ELSE\n*\n* Path 10t(N greater than M, but not much larger)\n*\n CALL DGEBRD( M, N, A, LDA, S, DUM(1), DUM(1),\n $ DUM(1), DUM(1), -1, IERR )\n LWORK_DGEBRD=DUM(1)\n MAXWRK = 3*M + LWORK_DGEBRD\n IF( WNTVS .OR. WNTVO ) THEN\n* Compute space needed for DORGBR P\n CALL DORGBR( 'P', M, N, M, A, N, DUM(1),\n $ DUM(1), -1, IERR )\n LWORK_DORGBR_P=DUM(1)\n MAXWRK = MAX( MAXWRK, 3*M+LWORK_DORGBR_P )\n END IF\n IF( WNTVA ) THEN\n CALL DORGBR( 'P', N, N, M, A, N, DUM(1),\n $ DUM(1), -1, IERR )\n LWORK_DORGBR_P=DUM(1)\n MAXWRK = MAX( MAXWRK, 3*M+LWORK_DORGBR_P )\n END IF\n IF( .NOT.WNTUN ) THEN\n MAXWRK = MAX( MAXWRK, 3*M+LWORK_DORGBR_Q )\n END IF\n MAXWRK = MAX( MAXWRK, BDSPAC )\n MINWRK = MAX( 3*M+N, BDSPAC )\n END IF\n END IF\n MAXWRK = MAX( MAXWRK, MINWRK )\n WORK( 1 ) = MAXWRK\n*\n IF( LWORK.LT.MINWRK .AND. .NOT.LQUERY ) THEN\n INFO = -13\n END IF\n END IF\n*\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'DGESVD', -INFO )\n RETURN\n ELSE IF( LQUERY ) THEN\n RETURN\n END IF\n*\n* Quick return if possible\n*\n IF( M.EQ.0 .OR. N.EQ.0 ) THEN\n RETURN\n END IF\n*\n* Get machine constants\n*\n EPS = DLAMCH( 'P' )\n SMLNUM = SQRT( DLAMCH( 'S' ) ) / EPS\n BIGNUM = ONE / SMLNUM\n*\n* Scale A if max element outside range [SMLNUM,BIGNUM]\n*\n ANRM = DLANGE( 'M', M, N, A, LDA, DUM )\n ISCL = 0\n IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN\n ISCL = 1\n CALL DLASCL( 'G', 0, 0, ANRM, SMLNUM, M, N, A, LDA, IERR )\n ELSE IF( ANRM.GT.BIGNUM ) THEN\n ISCL = 1\n CALL DLASCL( 'G', 0, 0, ANRM, BIGNUM, M, N, A, LDA, IERR )\n END IF\n*\n IF( M.GE.N ) THEN\n*\n* A has at least as many rows as columns. If A has sufficiently\n* more rows than columns, first reduce using the QR\n* decomposition (if sufficient workspace available)\n*\n IF( M.GE.MNTHR ) THEN\n*\n IF( WNTUN ) THEN\n*\n* Path 1 (M much larger than N, JOBU='N')\n* No left singular vectors to be computed\n*\n ITAU = 1\n IWORK = ITAU + N\n*\n* Compute A=Q*R\n* (Workspace: need 2*N, prefer N+N*NB)\n*\n CALL DGEQRF( M, N, A, LDA, WORK( ITAU ), WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n*\n* Zero out below R\n*\n CALL DLASET( 'L', N-1, N-1, ZERO, ZERO, A( 2, 1 ), LDA )\n IE = 1\n ITAUQ = IE + N\n ITAUP = ITAUQ + N\n IWORK = ITAUP + N\n*\n* Bidiagonalize R in A\n* (Workspace: need 4*N, prefer 3*N+2*N*NB)\n*\n CALL DGEBRD( N, N, A, LDA, S, WORK( IE ), WORK( ITAUQ ),\n $ WORK( ITAUP ), WORK( IWORK ), LWORK-IWORK+1,\n $ IERR )\n NCVT = 0\n IF( WNTVO .OR. WNTVAS ) THEN\n*\n* If right singular vectors desired, generate P'.\n* (Workspace: need 4*N-1, prefer 3*N+(N-1)*NB)\n*\n CALL DORGBR( 'P', N, N, N, A, LDA, WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n NCVT = N\n END IF\n IWORK = IE + N\n*\n* Perform bidiagonal QR iteration, computing right\n* singular vectors of A in A if desired\n* (Workspace: need BDSPAC)\n*\n CALL DBDSQR( 'U', N, NCVT, 0, 0, S, WORK( IE ), A, LDA,\n $ DUM, 1, DUM, 1, WORK( IWORK ), INFO )\n*\n* If right singular vectors desired in VT, copy them there\n*\n IF( WNTVAS )\n $ CALL DLACPY( 'F', N, N, A, LDA, VT, LDVT )\n*\n ELSE IF( WNTUO .AND. WNTVN ) THEN\n*\n* Path 2 (M much larger than N, JOBU='O', JOBVT='N')\n* N left singular vectors to be overwritten on A and\n* no right singular vectors to be computed\n*\n IF( LWORK.GE.N*N+MAX( 4*N, BDSPAC ) ) THEN\n*\n* Sufficient workspace for a fast algorithm\n*\n IR = 1\n IF( LWORK.GE.MAX( WRKBL, LDA*N+N )+LDA*N ) THEN\n*\n* WORK(IU) is LDA by N, WORK(IR) is LDA by N\n*\n LDWRKU = LDA\n LDWRKR = LDA\n ELSE IF( LWORK.GE.MAX( WRKBL, LDA*N+N )+N*N ) THEN\n*\n* WORK(IU) is LDA by N, WORK(IR) is N by N\n*\n LDWRKU = LDA\n LDWRKR = N\n ELSE\n*\n* WORK(IU) is LDWRKU by N, WORK(IR) is N by N\n*\n LDWRKU = ( LWORK-N*N-N ) / N\n LDWRKR = N\n END IF\n ITAU = IR + LDWRKR*N\n IWORK = ITAU + N\n*\n* Compute A=Q*R\n* (Workspace: need N*N+2*N, prefer N*N+N+N*NB)\n*\n CALL DGEQRF( M, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Copy R to WORK(IR) and zero out below it\n*\n CALL DLACPY( 'U', N, N, A, LDA, WORK( IR ), LDWRKR )\n CALL DLASET( 'L', N-1, N-1, ZERO, ZERO, WORK( IR+1 ),\n $ LDWRKR )\n*\n* Generate Q in A\n* (Workspace: need N*N+2*N, prefer N*N+N+N*NB)\n*\n CALL DORGQR( M, N, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IE = ITAU\n ITAUQ = IE + N\n ITAUP = ITAUQ + N\n IWORK = ITAUP + N\n*\n* Bidiagonalize R in WORK(IR)\n* (Workspace: need N*N+4*N, prefer N*N+3*N+2*N*NB)\n*\n CALL DGEBRD( N, N, WORK( IR ), LDWRKR, S, WORK( IE ),\n $ WORK( ITAUQ ), WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Generate left vectors bidiagonalizing R\n* (Workspace: need N*N+4*N, prefer N*N+3*N+N*NB)\n*\n CALL DORGBR( 'Q', N, N, N, WORK( IR ), LDWRKR,\n $ WORK( ITAUQ ), WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n IWORK = IE + N\n*\n* Perform bidiagonal QR iteration, computing left\n* singular vectors of R in WORK(IR)\n* (Workspace: need N*N+BDSPAC)\n*\n CALL DBDSQR( 'U', N, 0, N, 0, S, WORK( IE ), DUM, 1,\n $ WORK( IR ), LDWRKR, DUM, 1,\n $ WORK( IWORK ), INFO )\n IU = IE + N\n*\n* Multiply Q in A by left singular vectors of R in\n* WORK(IR), storing result in WORK(IU) and copying to A\n* (Workspace: need N*N+2*N, prefer N*N+M*N+N)\n*\n DO 10 I = 1, M, LDWRKU\n CHUNK = MIN( M-I+1, LDWRKU )\n CALL DGEMM( 'N', 'N', CHUNK, N, N, ONE, A( I, 1 ),\n $ LDA, WORK( IR ), LDWRKR, ZERO,\n $ WORK( IU ), LDWRKU )\n CALL DLACPY( 'F', CHUNK, N, WORK( IU ), LDWRKU,\n $ A( I, 1 ), LDA )\n 10 CONTINUE\n*\n ELSE\n*\n* Insufficient workspace for a fast algorithm\n*\n IE = 1\n ITAUQ = IE + N\n ITAUP = ITAUQ + N\n IWORK = ITAUP + N\n*\n* Bidiagonalize A\n* (Workspace: need 3*N+M, prefer 3*N+(M+N)*NB)\n*\n CALL DGEBRD( M, N, A, LDA, S, WORK( IE ),\n $ WORK( ITAUQ ), WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Generate left vectors bidiagonalizing A\n* (Workspace: need 4*N, prefer 3*N+N*NB)\n*\n CALL DORGBR( 'Q', M, N, N, A, LDA, WORK( ITAUQ ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IWORK = IE + N\n*\n* Perform bidiagonal QR iteration, computing left\n* singular vectors of A in A\n* (Workspace: need BDSPAC)\n*\n CALL DBDSQR( 'U', N, 0, M, 0, S, WORK( IE ), DUM, 1,\n $ A, LDA, DUM, 1, WORK( IWORK ), INFO )\n*\n END IF\n*\n ELSE IF( WNTUO .AND. WNTVAS ) THEN\n*\n* Path 3 (M much larger than N, JOBU='O', JOBVT='S' or 'A')\n* N left singular vectors to be overwritten on A and\n* N right singular vectors to be computed in VT\n*\n IF( LWORK.GE.N*N+MAX( 4*N, BDSPAC ) ) THEN\n*\n* Sufficient workspace for a fast algorithm\n*\n IR = 1\n IF( LWORK.GE.MAX( WRKBL, LDA*N+N )+LDA*N ) THEN\n*\n* WORK(IU) is LDA by N and WORK(IR) is LDA by N\n*\n LDWRKU = LDA\n LDWRKR = LDA\n ELSE IF( LWORK.GE.MAX( WRKBL, LDA*N+N )+N*N ) THEN\n*\n* WORK(IU) is LDA by N and WORK(IR) is N by N\n*\n LDWRKU = LDA\n LDWRKR = N\n ELSE\n*\n* WORK(IU) is LDWRKU by N and WORK(IR) is N by N\n*\n LDWRKU = ( LWORK-N*N-N ) / N\n LDWRKR = N\n END IF\n ITAU = IR + LDWRKR*N\n IWORK = ITAU + N\n*\n* Compute A=Q*R\n* (Workspace: need N*N+2*N, prefer N*N+N+N*NB)\n*\n CALL DGEQRF( M, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Copy R to VT, zeroing out below it\n*\n CALL DLACPY( 'U', N, N, A, LDA, VT, LDVT )\n IF( N.GT.1 )\n $ CALL DLASET( 'L', N-1, N-1, ZERO, ZERO,\n $ VT( 2, 1 ), LDVT )\n*\n* Generate Q in A\n* (Workspace: need N*N+2*N, prefer N*N+N+N*NB)\n*\n CALL DORGQR( M, N, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IE = ITAU\n ITAUQ = IE + N\n ITAUP = ITAUQ + N\n IWORK = ITAUP + N\n*\n* Bidiagonalize R in VT, copying result to WORK(IR)\n* (Workspace: need N*N+4*N, prefer N*N+3*N+2*N*NB)\n*\n CALL DGEBRD( N, N, VT, LDVT, S, WORK( IE ),\n $ WORK( ITAUQ ), WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n CALL DLACPY( 'L', N, N, VT, LDVT, WORK( IR ), LDWRKR )\n*\n* Generate left vectors bidiagonalizing R in WORK(IR)\n* (Workspace: need N*N+4*N, prefer N*N+3*N+N*NB)\n*\n CALL DORGBR( 'Q', N, N, N, WORK( IR ), LDWRKR,\n $ WORK( ITAUQ ), WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n*\n* Generate right vectors bidiagonalizing R in VT\n* (Workspace: need N*N+4*N-1, prefer N*N+3*N+(N-1)*NB)\n*\n CALL DORGBR( 'P', N, N, N, VT, LDVT, WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IWORK = IE + N\n*\n* Perform bidiagonal QR iteration, computing left\n* singular vectors of R in WORK(IR) and computing right\n* singular vectors of R in VT\n* (Workspace: need N*N+BDSPAC)\n*\n CALL DBDSQR( 'U', N, N, N, 0, S, WORK( IE ), VT, LDVT,\n $ WORK( IR ), LDWRKR, DUM, 1,\n $ WORK( IWORK ), INFO )\n IU = IE + N\n*\n* Multiply Q in A by left singular vectors of R in\n* WORK(IR), storing result in WORK(IU) and copying to A\n* (Workspace: need N*N+2*N, prefer N*N+M*N+N)\n*\n DO 20 I = 1, M, LDWRKU\n CHUNK = MIN( M-I+1, LDWRKU )\n CALL DGEMM( 'N', 'N', CHUNK, N, N, ONE, A( I, 1 ),\n $ LDA, WORK( IR ), LDWRKR, ZERO,\n $ WORK( IU ), LDWRKU )\n CALL DLACPY( 'F', CHUNK, N, WORK( IU ), LDWRKU,\n $ A( I, 1 ), LDA )\n 20 CONTINUE\n*\n ELSE\n*\n* Insufficient workspace for a fast algorithm\n*\n ITAU = 1\n IWORK = ITAU + N\n*\n* Compute A=Q*R\n* (Workspace: need 2*N, prefer N+N*NB)\n*\n CALL DGEQRF( M, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Copy R to VT, zeroing out below it\n*\n CALL DLACPY( 'U', N, N, A, LDA, VT, LDVT )\n IF( N.GT.1 )\n $ CALL DLASET( 'L', N-1, N-1, ZERO, ZERO,\n $ VT( 2, 1 ), LDVT )\n*\n* Generate Q in A\n* (Workspace: need 2*N, prefer N+N*NB)\n*\n CALL DORGQR( M, N, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IE = ITAU\n ITAUQ = IE + N\n ITAUP = ITAUQ + N\n IWORK = ITAUP + N\n*\n* Bidiagonalize R in VT\n* (Workspace: need 4*N, prefer 3*N+2*N*NB)\n*\n CALL DGEBRD( N, N, VT, LDVT, S, WORK( IE ),\n $ WORK( ITAUQ ), WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Multiply Q in A by left vectors bidiagonalizing R\n* (Workspace: need 3*N+M, prefer 3*N+M*NB)\n*\n CALL DORMBR( 'Q', 'R', 'N', M, N, N, VT, LDVT,\n $ WORK( ITAUQ ), A, LDA, WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n*\n* Generate right vectors bidiagonalizing R in VT\n* (Workspace: need 4*N-1, prefer 3*N+(N-1)*NB)\n*\n CALL DORGBR( 'P', N, N, N, VT, LDVT, WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IWORK = IE + N\n*\n* Perform bidiagonal QR iteration, computing left\n* singular vectors of A in A and computing right\n* singular vectors of A in VT\n* (Workspace: need BDSPAC)\n*\n CALL DBDSQR( 'U', N, N, M, 0, S, WORK( IE ), VT, LDVT,\n $ A, LDA, DUM, 1, WORK( IWORK ), INFO )\n*\n END IF\n*\n ELSE IF( WNTUS ) THEN\n*\n IF( WNTVN ) THEN\n*\n* Path 4 (M much larger than N, JOBU='S', JOBVT='N')\n* N left singular vectors to be computed in U and\n* no right singular vectors to be computed\n*\n IF( LWORK.GE.N*N+MAX( 4*N, BDSPAC ) ) THEN\n*\n* Sufficient workspace for a fast algorithm\n*\n IR = 1\n IF( LWORK.GE.WRKBL+LDA*N ) THEN\n*\n* WORK(IR) is LDA by N\n*\n LDWRKR = LDA\n ELSE\n*\n* WORK(IR) is N by N\n*\n LDWRKR = N\n END IF\n ITAU = IR + LDWRKR*N\n IWORK = ITAU + N\n*\n* Compute A=Q*R\n* (Workspace: need N*N+2*N, prefer N*N+N+N*NB)\n*\n CALL DGEQRF( M, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Copy R to WORK(IR), zeroing out below it\n*\n CALL DLACPY( 'U', N, N, A, LDA, WORK( IR ),\n $ LDWRKR )\n CALL DLASET( 'L', N-1, N-1, ZERO, ZERO,\n $ WORK( IR+1 ), LDWRKR )\n*\n* Generate Q in A\n* (Workspace: need N*N+2*N, prefer N*N+N+N*NB)\n*\n CALL DORGQR( M, N, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IE = ITAU\n ITAUQ = IE + N\n ITAUP = ITAUQ + N\n IWORK = ITAUP + N\n*\n* Bidiagonalize R in WORK(IR)\n* (Workspace: need N*N+4*N, prefer N*N+3*N+2*N*NB)\n*\n CALL DGEBRD( N, N, WORK( IR ), LDWRKR, S,\n $ WORK( IE ), WORK( ITAUQ ),\n $ WORK( ITAUP ), WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n*\n* Generate left vectors bidiagonalizing R in WORK(IR)\n* (Workspace: need N*N+4*N, prefer N*N+3*N+N*NB)\n*\n CALL DORGBR( 'Q', N, N, N, WORK( IR ), LDWRKR,\n $ WORK( ITAUQ ), WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n IWORK = IE + N\n*\n* Perform bidiagonal QR iteration, computing left\n* singular vectors of R in WORK(IR)\n* (Workspace: need N*N+BDSPAC)\n*\n CALL DBDSQR( 'U', N, 0, N, 0, S, WORK( IE ), DUM,\n $ 1, WORK( IR ), LDWRKR, DUM, 1,\n $ WORK( IWORK ), INFO )\n*\n* Multiply Q in A by left singular vectors of R in\n* WORK(IR), storing result in U\n* (Workspace: need N*N)\n*\n CALL DGEMM( 'N', 'N', M, N, N, ONE, A, LDA,\n $ WORK( IR ), LDWRKR, ZERO, U, LDU )\n*\n ELSE\n*\n* Insufficient workspace for a fast algorithm\n*\n ITAU = 1\n IWORK = ITAU + N\n*\n* Compute A=Q*R, copying result to U\n* (Workspace: need 2*N, prefer N+N*NB)\n*\n CALL DGEQRF( M, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n CALL DLACPY( 'L', M, N, A, LDA, U, LDU )\n*\n* Generate Q in U\n* (Workspace: need 2*N, prefer N+N*NB)\n*\n CALL DORGQR( M, N, N, U, LDU, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IE = ITAU\n ITAUQ = IE + N\n ITAUP = ITAUQ + N\n IWORK = ITAUP + N\n*\n* Zero out below R in A\n*\n CALL DLASET( 'L', N-1, N-1, ZERO, ZERO, A( 2, 1 ),\n $ LDA )\n*\n* Bidiagonalize R in A\n* (Workspace: need 4*N, prefer 3*N+2*N*NB)\n*\n CALL DGEBRD( N, N, A, LDA, S, WORK( IE ),\n $ WORK( ITAUQ ), WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Multiply Q in U by left vectors bidiagonalizing R\n* (Workspace: need 3*N+M, prefer 3*N+M*NB)\n*\n CALL DORMBR( 'Q', 'R', 'N', M, N, N, A, LDA,\n $ WORK( ITAUQ ), U, LDU, WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n IWORK = IE + N\n*\n* Perform bidiagonal QR iteration, computing left\n* singular vectors of A in U\n* (Workspace: need BDSPAC)\n*\n CALL DBDSQR( 'U', N, 0, M, 0, S, WORK( IE ), DUM,\n $ 1, U, LDU, DUM, 1, WORK( IWORK ),\n $ INFO )\n*\n END IF\n*\n ELSE IF( WNTVO ) THEN\n*\n* Path 5 (M much larger than N, JOBU='S', JOBVT='O')\n* N left singular vectors to be computed in U and\n* N right singular vectors to be overwritten on A\n*\n IF( LWORK.GE.2*N*N+MAX( 4*N, BDSPAC ) ) THEN\n*\n* Sufficient workspace for a fast algorithm\n*\n IU = 1\n IF( LWORK.GE.WRKBL+2*LDA*N ) THEN\n*\n* WORK(IU) is LDA by N and WORK(IR) is LDA by N\n*\n LDWRKU = LDA\n IR = IU + LDWRKU*N\n LDWRKR = LDA\n ELSE IF( LWORK.GE.WRKBL+( LDA+N )*N ) THEN\n*\n* WORK(IU) is LDA by N and WORK(IR) is N by N\n*\n LDWRKU = LDA\n IR = IU + LDWRKU*N\n LDWRKR = N\n ELSE\n*\n* WORK(IU) is N by N and WORK(IR) is N by N\n*\n LDWRKU = N\n IR = IU + LDWRKU*N\n LDWRKR = N\n END IF\n ITAU = IR + LDWRKR*N\n IWORK = ITAU + N\n*\n* Compute A=Q*R\n* (Workspace: need 2*N*N+2*N, prefer 2*N*N+N+N*NB)\n*\n CALL DGEQRF( M, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Copy R to WORK(IU), zeroing out below it\n*\n CALL DLACPY( 'U', N, N, A, LDA, WORK( IU ),\n $ LDWRKU )\n CALL DLASET( 'L', N-1, N-1, ZERO, ZERO,\n $ WORK( IU+1 ), LDWRKU )\n*\n* Generate Q in A\n* (Workspace: need 2*N*N+2*N, prefer 2*N*N+N+N*NB)\n*\n CALL DORGQR( M, N, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IE = ITAU\n ITAUQ = IE + N\n ITAUP = ITAUQ + N\n IWORK = ITAUP + N\n*\n* Bidiagonalize R in WORK(IU), copying result to\n* WORK(IR)\n* (Workspace: need 2*N*N+4*N,\n* prefer 2*N*N+3*N+2*N*NB)\n*\n CALL DGEBRD( N, N, WORK( IU ), LDWRKU, S,\n $ WORK( IE ), WORK( ITAUQ ),\n $ WORK( ITAUP ), WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n CALL DLACPY( 'U', N, N, WORK( IU ), LDWRKU,\n $ WORK( IR ), LDWRKR )\n*\n* Generate left bidiagonalizing vectors in WORK(IU)\n* (Workspace: need 2*N*N+4*N, prefer 2*N*N+3*N+N*NB)\n*\n CALL DORGBR( 'Q', N, N, N, WORK( IU ), LDWRKU,\n $ WORK( ITAUQ ), WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n*\n* Generate right bidiagonalizing vectors in WORK(IR)\n* (Workspace: need 2*N*N+4*N-1,\n* prefer 2*N*N+3*N+(N-1)*NB)\n*\n CALL DORGBR( 'P', N, N, N, WORK( IR ), LDWRKR,\n $ WORK( ITAUP ), WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n IWORK = IE + N\n*\n* Perform bidiagonal QR iteration, computing left\n* singular vectors of R in WORK(IU) and computing\n* right singular vectors of R in WORK(IR)\n* (Workspace: need 2*N*N+BDSPAC)\n*\n CALL DBDSQR( 'U', N, N, N, 0, S, WORK( IE ),\n $ WORK( IR ), LDWRKR, WORK( IU ),\n $ LDWRKU, DUM, 1, WORK( IWORK ), INFO )\n*\n* Multiply Q in A by left singular vectors of R in\n* WORK(IU), storing result in U\n* (Workspace: need N*N)\n*\n CALL DGEMM( 'N', 'N', M, N, N, ONE, A, LDA,\n $ WORK( IU ), LDWRKU, ZERO, U, LDU )\n*\n* Copy right singular vectors of R to A\n* (Workspace: need N*N)\n*\n CALL DLACPY( 'F', N, N, WORK( IR ), LDWRKR, A,\n $ LDA )\n*\n ELSE\n*\n* Insufficient workspace for a fast algorithm\n*\n ITAU = 1\n IWORK = ITAU + N\n*\n* Compute A=Q*R, copying result to U\n* (Workspace: need 2*N, prefer N+N*NB)\n*\n CALL DGEQRF( M, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n CALL DLACPY( 'L', M, N, A, LDA, U, LDU )\n*\n* Generate Q in U\n* (Workspace: need 2*N, prefer N+N*NB)\n*\n CALL DORGQR( M, N, N, U, LDU, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IE = ITAU\n ITAUQ = IE + N\n ITAUP = ITAUQ + N\n IWORK = ITAUP + N\n*\n* Zero out below R in A\n*\n CALL DLASET( 'L', N-1, N-1, ZERO, ZERO, A( 2, 1 ),\n $ LDA )\n*\n* Bidiagonalize R in A\n* (Workspace: need 4*N, prefer 3*N+2*N*NB)\n*\n CALL DGEBRD( N, N, A, LDA, S, WORK( IE ),\n $ WORK( ITAUQ ), WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Multiply Q in U by left vectors bidiagonalizing R\n* (Workspace: need 3*N+M, prefer 3*N+M*NB)\n*\n CALL DORMBR( 'Q', 'R', 'N', M, N, N, A, LDA,\n $ WORK( ITAUQ ), U, LDU, WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n*\n* Generate right vectors bidiagonalizing R in A\n* (Workspace: need 4*N-1, prefer 3*N+(N-1)*NB)\n*\n CALL DORGBR( 'P', N, N, N, A, LDA, WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IWORK = IE + N\n*\n* Perform bidiagonal QR iteration, computing left\n* singular vectors of A in U and computing right\n* singular vectors of A in A\n* (Workspace: need BDSPAC)\n*\n CALL DBDSQR( 'U', N, N, M, 0, S, WORK( IE ), A,\n $ LDA, U, LDU, DUM, 1, WORK( IWORK ),\n $ INFO )\n*\n END IF\n*\n ELSE IF( WNTVAS ) THEN\n*\n* Path 6 (M much larger than N, JOBU='S', JOBVT='S'\n* or 'A')\n* N left singular vectors to be computed in U and\n* N right singular vectors to be computed in VT\n*\n IF( LWORK.GE.N*N+MAX( 4*N, BDSPAC ) ) THEN\n*\n* Sufficient workspace for a fast algorithm\n*\n IU = 1\n IF( LWORK.GE.WRKBL+LDA*N ) THEN\n*\n* WORK(IU) is LDA by N\n*\n LDWRKU = LDA\n ELSE\n*\n* WORK(IU) is N by N\n*\n LDWRKU = N\n END IF\n ITAU = IU + LDWRKU*N\n IWORK = ITAU + N\n*\n* Compute A=Q*R\n* (Workspace: need N*N+2*N, prefer N*N+N+N*NB)\n*\n CALL DGEQRF( M, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Copy R to WORK(IU), zeroing out below it\n*\n CALL DLACPY( 'U', N, N, A, LDA, WORK( IU ),\n $ LDWRKU )\n CALL DLASET( 'L', N-1, N-1, ZERO, ZERO,\n $ WORK( IU+1 ), LDWRKU )\n*\n* Generate Q in A\n* (Workspace: need N*N+2*N, prefer N*N+N+N*NB)\n*\n CALL DORGQR( M, N, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IE = ITAU\n ITAUQ = IE + N\n ITAUP = ITAUQ + N\n IWORK = ITAUP + N\n*\n* Bidiagonalize R in WORK(IU), copying result to VT\n* (Workspace: need N*N+4*N, prefer N*N+3*N+2*N*NB)\n*\n CALL DGEBRD( N, N, WORK( IU ), LDWRKU, S,\n $ WORK( IE ), WORK( ITAUQ ),\n $ WORK( ITAUP ), WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n CALL DLACPY( 'U', N, N, WORK( IU ), LDWRKU, VT,\n $ LDVT )\n*\n* Generate left bidiagonalizing vectors in WORK(IU)\n* (Workspace: need N*N+4*N, prefer N*N+3*N+N*NB)\n*\n CALL DORGBR( 'Q', N, N, N, WORK( IU ), LDWRKU,\n $ WORK( ITAUQ ), WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n*\n* Generate right bidiagonalizing vectors in VT\n* (Workspace: need N*N+4*N-1,\n* prefer N*N+3*N+(N-1)*NB)\n*\n CALL DORGBR( 'P', N, N, N, VT, LDVT, WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IWORK = IE + N\n*\n* Perform bidiagonal QR iteration, computing left\n* singular vectors of R in WORK(IU) and computing\n* right singular vectors of R in VT\n* (Workspace: need N*N+BDSPAC)\n*\n CALL DBDSQR( 'U', N, N, N, 0, S, WORK( IE ), VT,\n $ LDVT, WORK( IU ), LDWRKU, DUM, 1,\n $ WORK( IWORK ), INFO )\n*\n* Multiply Q in A by left singular vectors of R in\n* WORK(IU), storing result in U\n* (Workspace: need N*N)\n*\n CALL DGEMM( 'N', 'N', M, N, N, ONE, A, LDA,\n $ WORK( IU ), LDWRKU, ZERO, U, LDU )\n*\n ELSE\n*\n* Insufficient workspace for a fast algorithm\n*\n ITAU = 1\n IWORK = ITAU + N\n*\n* Compute A=Q*R, copying result to U\n* (Workspace: need 2*N, prefer N+N*NB)\n*\n CALL DGEQRF( M, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n CALL DLACPY( 'L', M, N, A, LDA, U, LDU )\n*\n* Generate Q in U\n* (Workspace: need 2*N, prefer N+N*NB)\n*\n CALL DORGQR( M, N, N, U, LDU, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Copy R to VT, zeroing out below it\n*\n CALL DLACPY( 'U', N, N, A, LDA, VT, LDVT )\n IF( N.GT.1 )\n $ CALL DLASET( 'L', N-1, N-1, ZERO, ZERO,\n $ VT( 2, 1 ), LDVT )\n IE = ITAU\n ITAUQ = IE + N\n ITAUP = ITAUQ + N\n IWORK = ITAUP + N\n*\n* Bidiagonalize R in VT\n* (Workspace: need 4*N, prefer 3*N+2*N*NB)\n*\n CALL DGEBRD( N, N, VT, LDVT, S, WORK( IE ),\n $ WORK( ITAUQ ), WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Multiply Q in U by left bidiagonalizing vectors\n* in VT\n* (Workspace: need 3*N+M, prefer 3*N+M*NB)\n*\n CALL DORMBR( 'Q', 'R', 'N', M, N, N, VT, LDVT,\n $ WORK( ITAUQ ), U, LDU, WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n*\n* Generate right bidiagonalizing vectors in VT\n* (Workspace: need 4*N-1, prefer 3*N+(N-1)*NB)\n*\n CALL DORGBR( 'P', N, N, N, VT, LDVT, WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IWORK = IE + N\n*\n* Perform bidiagonal QR iteration, computing left\n* singular vectors of A in U and computing right\n* singular vectors of A in VT\n* (Workspace: need BDSPAC)\n*\n CALL DBDSQR( 'U', N, N, M, 0, S, WORK( IE ), VT,\n $ LDVT, U, LDU, DUM, 1, WORK( IWORK ),\n $ INFO )\n*\n END IF\n*\n END IF\n*\n ELSE IF( WNTUA ) THEN\n*\n IF( WNTVN ) THEN\n*\n* Path 7 (M much larger than N, JOBU='A', JOBVT='N')\n* M left singular vectors to be computed in U and\n* no right singular vectors to be computed\n*\n IF( LWORK.GE.N*N+MAX( N+M, 4*N, BDSPAC ) ) THEN\n*\n* Sufficient workspace for a fast algorithm\n*\n IR = 1\n IF( LWORK.GE.WRKBL+LDA*N ) THEN\n*\n* WORK(IR) is LDA by N\n*\n LDWRKR = LDA\n ELSE\n*\n* WORK(IR) is N by N\n*\n LDWRKR = N\n END IF\n ITAU = IR + LDWRKR*N\n IWORK = ITAU + N\n*\n* Compute A=Q*R, copying result to U\n* (Workspace: need N*N+2*N, prefer N*N+N+N*NB)\n*\n CALL DGEQRF( M, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n CALL DLACPY( 'L', M, N, A, LDA, U, LDU )\n*\n* Copy R to WORK(IR), zeroing out below it\n*\n CALL DLACPY( 'U', N, N, A, LDA, WORK( IR ),\n $ LDWRKR )\n CALL DLASET( 'L', N-1, N-1, ZERO, ZERO,\n $ WORK( IR+1 ), LDWRKR )\n*\n* Generate Q in U\n* (Workspace: need N*N+N+M, prefer N*N+N+M*NB)\n*\n CALL DORGQR( M, M, N, U, LDU, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IE = ITAU\n ITAUQ = IE + N\n ITAUP = ITAUQ + N\n IWORK = ITAUP + N\n*\n* Bidiagonalize R in WORK(IR)\n* (Workspace: need N*N+4*N, prefer N*N+3*N+2*N*NB)\n*\n CALL DGEBRD( N, N, WORK( IR ), LDWRKR, S,\n $ WORK( IE ), WORK( ITAUQ ),\n $ WORK( ITAUP ), WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n*\n* Generate left bidiagonalizing vectors in WORK(IR)\n* (Workspace: need N*N+4*N, prefer N*N+3*N+N*NB)\n*\n CALL DORGBR( 'Q', N, N, N, WORK( IR ), LDWRKR,\n $ WORK( ITAUQ ), WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n IWORK = IE + N\n*\n* Perform bidiagonal QR iteration, computing left\n* singular vectors of R in WORK(IR)\n* (Workspace: need N*N+BDSPAC)\n*\n CALL DBDSQR( 'U', N, 0, N, 0, S, WORK( IE ), DUM,\n $ 1, WORK( IR ), LDWRKR, DUM, 1,\n $ WORK( IWORK ), INFO )\n*\n* Multiply Q in U by left singular vectors of R in\n* WORK(IR), storing result in A\n* (Workspace: need N*N)\n*\n CALL DGEMM( 'N', 'N', M, N, N, ONE, U, LDU,\n $ WORK( IR ), LDWRKR, ZERO, A, LDA )\n*\n* Copy left singular vectors of A from A to U\n*\n CALL DLACPY( 'F', M, N, A, LDA, U, LDU )\n*\n ELSE\n*\n* Insufficient workspace for a fast algorithm\n*\n ITAU = 1\n IWORK = ITAU + N\n*\n* Compute A=Q*R, copying result to U\n* (Workspace: need 2*N, prefer N+N*NB)\n*\n CALL DGEQRF( M, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n CALL DLACPY( 'L', M, N, A, LDA, U, LDU )\n*\n* Generate Q in U\n* (Workspace: need N+M, prefer N+M*NB)\n*\n CALL DORGQR( M, M, N, U, LDU, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IE = ITAU\n ITAUQ = IE + N\n ITAUP = ITAUQ + N\n IWORK = ITAUP + N\n*\n* Zero out below R in A\n*\n CALL DLASET( 'L', N-1, N-1, ZERO, ZERO, A( 2, 1 ),\n $ LDA )\n*\n* Bidiagonalize R in A\n* (Workspace: need 4*N, prefer 3*N+2*N*NB)\n*\n CALL DGEBRD( N, N, A, LDA, S, WORK( IE ),\n $ WORK( ITAUQ ), WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Multiply Q in U by left bidiagonalizing vectors\n* in A\n* (Workspace: need 3*N+M, prefer 3*N+M*NB)\n*\n CALL DORMBR( 'Q', 'R', 'N', M, N, N, A, LDA,\n $ WORK( ITAUQ ), U, LDU, WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n IWORK = IE + N\n*\n* Perform bidiagonal QR iteration, computing left\n* singular vectors of A in U\n* (Workspace: need BDSPAC)\n*\n CALL DBDSQR( 'U', N, 0, M, 0, S, WORK( IE ), DUM,\n $ 1, U, LDU, DUM, 1, WORK( IWORK ),\n $ INFO )\n*\n END IF\n*\n ELSE IF( WNTVO ) THEN\n*\n* Path 8 (M much larger than N, JOBU='A', JOBVT='O')\n* M left singular vectors to be computed in U and\n* N right singular vectors to be overwritten on A\n*\n IF( LWORK.GE.2*N*N+MAX( N+M, 4*N, BDSPAC ) ) THEN\n*\n* Sufficient workspace for a fast algorithm\n*\n IU = 1\n IF( LWORK.GE.WRKBL+2*LDA*N ) THEN\n*\n* WORK(IU) is LDA by N and WORK(IR) is LDA by N\n*\n LDWRKU = LDA\n IR = IU + LDWRKU*N\n LDWRKR = LDA\n ELSE IF( LWORK.GE.WRKBL+( LDA+N )*N ) THEN\n*\n* WORK(IU) is LDA by N and WORK(IR) is N by N\n*\n LDWRKU = LDA\n IR = IU + LDWRKU*N\n LDWRKR = N\n ELSE\n*\n* WORK(IU) is N by N and WORK(IR) is N by N\n*\n LDWRKU = N\n IR = IU + LDWRKU*N\n LDWRKR = N\n END IF\n ITAU = IR + LDWRKR*N\n IWORK = ITAU + N\n*\n* Compute A=Q*R, copying result to U\n* (Workspace: need 2*N*N+2*N, prefer 2*N*N+N+N*NB)\n*\n CALL DGEQRF( M, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n CALL DLACPY( 'L', M, N, A, LDA, U, LDU )\n*\n* Generate Q in U\n* (Workspace: need 2*N*N+N+M, prefer 2*N*N+N+M*NB)\n*\n CALL DORGQR( M, M, N, U, LDU, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Copy R to WORK(IU), zeroing out below it\n*\n CALL DLACPY( 'U', N, N, A, LDA, WORK( IU ),\n $ LDWRKU )\n CALL DLASET( 'L', N-1, N-1, ZERO, ZERO,\n $ WORK( IU+1 ), LDWRKU )\n IE = ITAU\n ITAUQ = IE + N\n ITAUP = ITAUQ + N\n IWORK = ITAUP + N\n*\n* Bidiagonalize R in WORK(IU), copying result to\n* WORK(IR)\n* (Workspace: need 2*N*N+4*N,\n* prefer 2*N*N+3*N+2*N*NB)\n*\n CALL DGEBRD( N, N, WORK( IU ), LDWRKU, S,\n $ WORK( IE ), WORK( ITAUQ ),\n $ WORK( ITAUP ), WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n CALL DLACPY( 'U', N, N, WORK( IU ), LDWRKU,\n $ WORK( IR ), LDWRKR )\n*\n* Generate left bidiagonalizing vectors in WORK(IU)\n* (Workspace: need 2*N*N+4*N, prefer 2*N*N+3*N+N*NB)\n*\n CALL DORGBR( 'Q', N, N, N, WORK( IU ), LDWRKU,\n $ WORK( ITAUQ ), WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n*\n* Generate right bidiagonalizing vectors in WORK(IR)\n* (Workspace: need 2*N*N+4*N-1,\n* prefer 2*N*N+3*N+(N-1)*NB)\n*\n CALL DORGBR( 'P', N, N, N, WORK( IR ), LDWRKR,\n $ WORK( ITAUP ), WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n IWORK = IE + N\n*\n* Perform bidiagonal QR iteration, computing left\n* singular vectors of R in WORK(IU) and computing\n* right singular vectors of R in WORK(IR)\n* (Workspace: need 2*N*N+BDSPAC)\n*\n CALL DBDSQR( 'U', N, N, N, 0, S, WORK( IE ),\n $ WORK( IR ), LDWRKR, WORK( IU ),\n $ LDWRKU, DUM, 1, WORK( IWORK ), INFO )\n*\n* Multiply Q in U by left singular vectors of R in\n* WORK(IU), storing result in A\n* (Workspace: need N*N)\n*\n CALL DGEMM( 'N', 'N', M, N, N, ONE, U, LDU,\n $ WORK( IU ), LDWRKU, ZERO, A, LDA )\n*\n* Copy left singular vectors of A from A to U\n*\n CALL DLACPY( 'F', M, N, A, LDA, U, LDU )\n*\n* Copy right singular vectors of R from WORK(IR) to A\n*\n CALL DLACPY( 'F', N, N, WORK( IR ), LDWRKR, A,\n $ LDA )\n*\n ELSE\n*\n* Insufficient workspace for a fast algorithm\n*\n ITAU = 1\n IWORK = ITAU + N\n*\n* Compute A=Q*R, copying result to U\n* (Workspace: need 2*N, prefer N+N*NB)\n*\n CALL DGEQRF( M, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n CALL DLACPY( 'L', M, N, A, LDA, U, LDU )\n*\n* Generate Q in U\n* (Workspace: need N+M, prefer N+M*NB)\n*\n CALL DORGQR( M, M, N, U, LDU, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IE = ITAU\n ITAUQ = IE + N\n ITAUP = ITAUQ + N\n IWORK = ITAUP + N\n*\n* Zero out below R in A\n*\n CALL DLASET( 'L', N-1, N-1, ZERO, ZERO, A( 2, 1 ),\n $ LDA )\n*\n* Bidiagonalize R in A\n* (Workspace: need 4*N, prefer 3*N+2*N*NB)\n*\n CALL DGEBRD( N, N, A, LDA, S, WORK( IE ),\n $ WORK( ITAUQ ), WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Multiply Q in U by left bidiagonalizing vectors\n* in A\n* (Workspace: need 3*N+M, prefer 3*N+M*NB)\n*\n CALL DORMBR( 'Q', 'R', 'N', M, N, N, A, LDA,\n $ WORK( ITAUQ ), U, LDU, WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n*\n* Generate right bidiagonalizing vectors in A\n* (Workspace: need 4*N-1, prefer 3*N+(N-1)*NB)\n*\n CALL DORGBR( 'P', N, N, N, A, LDA, WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IWORK = IE + N\n*\n* Perform bidiagonal QR iteration, computing left\n* singular vectors of A in U and computing right\n* singular vectors of A in A\n* (Workspace: need BDSPAC)\n*\n CALL DBDSQR( 'U', N, N, M, 0, S, WORK( IE ), A,\n $ LDA, U, LDU, DUM, 1, WORK( IWORK ),\n $ INFO )\n*\n END IF\n*\n ELSE IF( WNTVAS ) THEN\n*\n* Path 9 (M much larger than N, JOBU='A', JOBVT='S'\n* or 'A')\n* M left singular vectors to be computed in U and\n* N right singular vectors to be computed in VT\n*\n IF( LWORK.GE.N*N+MAX( N+M, 4*N, BDSPAC ) ) THEN\n*\n* Sufficient workspace for a fast algorithm\n*\n IU = 1\n IF( LWORK.GE.WRKBL+LDA*N ) THEN\n*\n* WORK(IU) is LDA by N\n*\n LDWRKU = LDA\n ELSE\n*\n* WORK(IU) is N by N\n*\n LDWRKU = N\n END IF\n ITAU = IU + LDWRKU*N\n IWORK = ITAU + N\n*\n* Compute A=Q*R, copying result to U\n* (Workspace: need N*N+2*N, prefer N*N+N+N*NB)\n*\n CALL DGEQRF( M, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n CALL DLACPY( 'L', M, N, A, LDA, U, LDU )\n*\n* Generate Q in U\n* (Workspace: need N*N+N+M, prefer N*N+N+M*NB)\n*\n CALL DORGQR( M, M, N, U, LDU, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Copy R to WORK(IU), zeroing out below it\n*\n CALL DLACPY( 'U', N, N, A, LDA, WORK( IU ),\n $ LDWRKU )\n CALL DLASET( 'L', N-1, N-1, ZERO, ZERO,\n $ WORK( IU+1 ), LDWRKU )\n IE = ITAU\n ITAUQ = IE + N\n ITAUP = ITAUQ + N\n IWORK = ITAUP + N\n*\n* Bidiagonalize R in WORK(IU), copying result to VT\n* (Workspace: need N*N+4*N, prefer N*N+3*N+2*N*NB)\n*\n CALL DGEBRD( N, N, WORK( IU ), LDWRKU, S,\n $ WORK( IE ), WORK( ITAUQ ),\n $ WORK( ITAUP ), WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n CALL DLACPY( 'U', N, N, WORK( IU ), LDWRKU, VT,\n $ LDVT )\n*\n* Generate left bidiagonalizing vectors in WORK(IU)\n* (Workspace: need N*N+4*N, prefer N*N+3*N+N*NB)\n*\n CALL DORGBR( 'Q', N, N, N, WORK( IU ), LDWRKU,\n $ WORK( ITAUQ ), WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n*\n* Generate right bidiagonalizing vectors in VT\n* (Workspace: need N*N+4*N-1,\n* prefer N*N+3*N+(N-1)*NB)\n*\n CALL DORGBR( 'P', N, N, N, VT, LDVT, WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IWORK = IE + N\n*\n* Perform bidiagonal QR iteration, computing left\n* singular vectors of R in WORK(IU) and computing\n* right singular vectors of R in VT\n* (Workspace: need N*N+BDSPAC)\n*\n CALL DBDSQR( 'U', N, N, N, 0, S, WORK( IE ), VT,\n $ LDVT, WORK( IU ), LDWRKU, DUM, 1,\n $ WORK( IWORK ), INFO )\n*\n* Multiply Q in U by left singular vectors of R in\n* WORK(IU), storing result in A\n* (Workspace: need N*N)\n*\n CALL DGEMM( 'N', 'N', M, N, N, ONE, U, LDU,\n $ WORK( IU ), LDWRKU, ZERO, A, LDA )\n*\n* Copy left singular vectors of A from A to U\n*\n CALL DLACPY( 'F', M, N, A, LDA, U, LDU )\n*\n ELSE\n*\n* Insufficient workspace for a fast algorithm\n*\n ITAU = 1\n IWORK = ITAU + N\n*\n* Compute A=Q*R, copying result to U\n* (Workspace: need 2*N, prefer N+N*NB)\n*\n CALL DGEQRF( M, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n CALL DLACPY( 'L', M, N, A, LDA, U, LDU )\n*\n* Generate Q in U\n* (Workspace: need N+M, prefer N+M*NB)\n*\n CALL DORGQR( M, M, N, U, LDU, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Copy R from A to VT, zeroing out below it\n*\n CALL DLACPY( 'U', N, N, A, LDA, VT, LDVT )\n IF( N.GT.1 )\n $ CALL DLASET( 'L', N-1, N-1, ZERO, ZERO,\n $ VT( 2, 1 ), LDVT )\n IE = ITAU\n ITAUQ = IE + N\n ITAUP = ITAUQ + N\n IWORK = ITAUP + N\n*\n* Bidiagonalize R in VT\n* (Workspace: need 4*N, prefer 3*N+2*N*NB)\n*\n CALL DGEBRD( N, N, VT, LDVT, S, WORK( IE ),\n $ WORK( ITAUQ ), WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Multiply Q in U by left bidiagonalizing vectors\n* in VT\n* (Workspace: need 3*N+M, prefer 3*N+M*NB)\n*\n CALL DORMBR( 'Q', 'R', 'N', M, N, N, VT, LDVT,\n $ WORK( ITAUQ ), U, LDU, WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n*\n* Generate right bidiagonalizing vectors in VT\n* (Workspace: need 4*N-1, prefer 3*N+(N-1)*NB)\n*\n CALL DORGBR( 'P', N, N, N, VT, LDVT, WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IWORK = IE + N\n*\n* Perform bidiagonal QR iteration, computing left\n* singular vectors of A in U and computing right\n* singular vectors of A in VT\n* (Workspace: need BDSPAC)\n*\n CALL DBDSQR( 'U', N, N, M, 0, S, WORK( IE ), VT,\n $ LDVT, U, LDU, DUM, 1, WORK( IWORK ),\n $ INFO )\n*\n END IF\n*\n END IF\n*\n END IF\n*\n ELSE\n*\n* M .LT. MNTHR\n*\n* Path 10 (M at least N, but not much larger)\n* Reduce to bidiagonal form without QR decomposition\n*\n IE = 1\n ITAUQ = IE + N\n ITAUP = ITAUQ + N\n IWORK = ITAUP + N\n*\n* Bidiagonalize A\n* (Workspace: need 3*N+M, prefer 3*N+(M+N)*NB)\n*\n CALL DGEBRD( M, N, A, LDA, S, WORK( IE ), WORK( ITAUQ ),\n $ WORK( ITAUP ), WORK( IWORK ), LWORK-IWORK+1,\n $ IERR )\n IF( WNTUAS ) THEN\n*\n* If left singular vectors desired in U, copy result to U\n* and generate left bidiagonalizing vectors in U\n* (Workspace: need 3*N+NCU, prefer 3*N+NCU*NB)\n*\n CALL DLACPY( 'L', M, N, A, LDA, U, LDU )\n IF( WNTUS )\n $ NCU = N\n IF( WNTUA )\n $ NCU = M\n CALL DORGBR( 'Q', M, NCU, N, U, LDU, WORK( ITAUQ ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n END IF\n IF( WNTVAS ) THEN\n*\n* If right singular vectors desired in VT, copy result to\n* VT and generate right bidiagonalizing vectors in VT\n* (Workspace: need 4*N-1, prefer 3*N+(N-1)*NB)\n*\n CALL DLACPY( 'U', N, N, A, LDA, VT, LDVT )\n CALL DORGBR( 'P', N, N, N, VT, LDVT, WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n END IF\n IF( WNTUO ) THEN\n*\n* If left singular vectors desired in A, generate left\n* bidiagonalizing vectors in A\n* (Workspace: need 4*N, prefer 3*N+N*NB)\n*\n CALL DORGBR( 'Q', M, N, N, A, LDA, WORK( ITAUQ ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n END IF\n IF( WNTVO ) THEN\n*\n* If right singular vectors desired in A, generate right\n* bidiagonalizing vectors in A\n* (Workspace: need 4*N-1, prefer 3*N+(N-1)*NB)\n*\n CALL DORGBR( 'P', N, N, N, A, LDA, WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n END IF\n IWORK = IE + N\n IF( WNTUAS .OR. WNTUO )\n $ NRU = M\n IF( WNTUN )\n $ NRU = 0\n IF( WNTVAS .OR. WNTVO )\n $ NCVT = N\n IF( WNTVN )\n $ NCVT = 0\n IF( ( .NOT.WNTUO ) .AND. ( .NOT.WNTVO ) ) THEN\n*\n* Perform bidiagonal QR iteration, if desired, computing\n* left singular vectors in U and computing right singular\n* vectors in VT\n* (Workspace: need BDSPAC)\n*\n CALL DBDSQR( 'U', N, NCVT, NRU, 0, S, WORK( IE ), VT,\n $ LDVT, U, LDU, DUM, 1, WORK( IWORK ), INFO )\n ELSE IF( ( .NOT.WNTUO ) .AND. WNTVO ) THEN\n*\n* Perform bidiagonal QR iteration, if desired, computing\n* left singular vectors in U and computing right singular\n* vectors in A\n* (Workspace: need BDSPAC)\n*\n CALL DBDSQR( 'U', N, NCVT, NRU, 0, S, WORK( IE ), A, LDA,\n $ U, LDU, DUM, 1, WORK( IWORK ), INFO )\n ELSE\n*\n* Perform bidiagonal QR iteration, if desired, computing\n* left singular vectors in A and computing right singular\n* vectors in VT\n* (Workspace: need BDSPAC)\n*\n CALL DBDSQR( 'U', N, NCVT, NRU, 0, S, WORK( IE ), VT,\n $ LDVT, A, LDA, DUM, 1, WORK( IWORK ), INFO )\n END IF\n*\n END IF\n*\n ELSE\n*\n* A has more columns than rows. If A has sufficiently more\n* columns than rows, first reduce using the LQ decomposition (if\n* sufficient workspace available)\n*\n IF( N.GE.MNTHR ) THEN\n*\n IF( WNTVN ) THEN\n*\n* Path 1t(N much larger than M, JOBVT='N')\n* No right singular vectors to be computed\n*\n ITAU = 1\n IWORK = ITAU + M\n*\n* Compute A=L*Q\n* (Workspace: need 2*M, prefer M+M*NB)\n*\n CALL DGELQF( M, N, A, LDA, WORK( ITAU ), WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n*\n* Zero out above L\n*\n CALL DLASET( 'U', M-1, M-1, ZERO, ZERO, A( 1, 2 ), LDA )\n IE = 1\n ITAUQ = IE + M\n ITAUP = ITAUQ + M\n IWORK = ITAUP + M\n*\n* Bidiagonalize L in A\n* (Workspace: need 4*M, prefer 3*M+2*M*NB)\n*\n CALL DGEBRD( M, M, A, LDA, S, WORK( IE ), WORK( ITAUQ ),\n $ WORK( ITAUP ), WORK( IWORK ), LWORK-IWORK+1,\n $ IERR )\n IF( WNTUO .OR. WNTUAS ) THEN\n*\n* If left singular vectors desired, generate Q\n* (Workspace: need 4*M, prefer 3*M+M*NB)\n*\n CALL DORGBR( 'Q', M, M, M, A, LDA, WORK( ITAUQ ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n END IF\n IWORK = IE + M\n NRU = 0\n IF( WNTUO .OR. WNTUAS )\n $ NRU = M\n*\n* Perform bidiagonal QR iteration, computing left singular\n* vectors of A in A if desired\n* (Workspace: need BDSPAC)\n*\n CALL DBDSQR( 'U', M, 0, NRU, 0, S, WORK( IE ), DUM, 1, A,\n $ LDA, DUM, 1, WORK( IWORK ), INFO )\n*\n* If left singular vectors desired in U, copy them there\n*\n IF( WNTUAS )\n $ CALL DLACPY( 'F', M, M, A, LDA, U, LDU )\n*\n ELSE IF( WNTVO .AND. WNTUN ) THEN\n*\n* Path 2t(N much larger than M, JOBU='N', JOBVT='O')\n* M right singular vectors to be overwritten on A and\n* no left singular vectors to be computed\n*\n IF( LWORK.GE.M*M+MAX( 4*M, BDSPAC ) ) THEN\n*\n* Sufficient workspace for a fast algorithm\n*\n IR = 1\n IF( LWORK.GE.MAX( WRKBL, LDA*N+M )+LDA*M ) THEN\n*\n* WORK(IU) is LDA by N and WORK(IR) is LDA by M\n*\n LDWRKU = LDA\n CHUNK = N\n LDWRKR = LDA\n ELSE IF( LWORK.GE.MAX( WRKBL, LDA*N+M )+M*M ) THEN\n*\n* WORK(IU) is LDA by N and WORK(IR) is M by M\n*\n LDWRKU = LDA\n CHUNK = N\n LDWRKR = M\n ELSE\n*\n* WORK(IU) is M by CHUNK and WORK(IR) is M by M\n*\n LDWRKU = M\n CHUNK = ( LWORK-M*M-M ) / M\n LDWRKR = M\n END IF\n ITAU = IR + LDWRKR*M\n IWORK = ITAU + M\n*\n* Compute A=L*Q\n* (Workspace: need M*M+2*M, prefer M*M+M+M*NB)\n*\n CALL DGELQF( M, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Copy L to WORK(IR) and zero out above it\n*\n CALL DLACPY( 'L', M, M, A, LDA, WORK( IR ), LDWRKR )\n CALL DLASET( 'U', M-1, M-1, ZERO, ZERO,\n $ WORK( IR+LDWRKR ), LDWRKR )\n*\n* Generate Q in A\n* (Workspace: need M*M+2*M, prefer M*M+M+M*NB)\n*\n CALL DORGLQ( M, N, M, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IE = ITAU\n ITAUQ = IE + M\n ITAUP = ITAUQ + M\n IWORK = ITAUP + M\n*\n* Bidiagonalize L in WORK(IR)\n* (Workspace: need M*M+4*M, prefer M*M+3*M+2*M*NB)\n*\n CALL DGEBRD( M, M, WORK( IR ), LDWRKR, S, WORK( IE ),\n $ WORK( ITAUQ ), WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Generate right vectors bidiagonalizing L\n* (Workspace: need M*M+4*M-1, prefer M*M+3*M+(M-1)*NB)\n*\n CALL DORGBR( 'P', M, M, M, WORK( IR ), LDWRKR,\n $ WORK( ITAUP ), WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n IWORK = IE + M\n*\n* Perform bidiagonal QR iteration, computing right\n* singular vectors of L in WORK(IR)\n* (Workspace: need M*M+BDSPAC)\n*\n CALL DBDSQR( 'U', M, M, 0, 0, S, WORK( IE ),\n $ WORK( IR ), LDWRKR, DUM, 1, DUM, 1,\n $ WORK( IWORK ), INFO )\n IU = IE + M\n*\n* Multiply right singular vectors of L in WORK(IR) by Q\n* in A, storing result in WORK(IU) and copying to A\n* (Workspace: need M*M+2*M, prefer M*M+M*N+M)\n*\n DO 30 I = 1, N, CHUNK\n BLK = MIN( N-I+1, CHUNK )\n CALL DGEMM( 'N', 'N', M, BLK, M, ONE, WORK( IR ),\n $ LDWRKR, A( 1, I ), LDA, ZERO,\n $ WORK( IU ), LDWRKU )\n CALL DLACPY( 'F', M, BLK, WORK( IU ), LDWRKU,\n $ A( 1, I ), LDA )\n 30 CONTINUE\n*\n ELSE\n*\n* Insufficient workspace for a fast algorithm\n*\n IE = 1\n ITAUQ = IE + M\n ITAUP = ITAUQ + M\n IWORK = ITAUP + M\n*\n* Bidiagonalize A\n* (Workspace: need 3*M+N, prefer 3*M+(M+N)*NB)\n*\n CALL DGEBRD( M, N, A, LDA, S, WORK( IE ),\n $ WORK( ITAUQ ), WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Generate right vectors bidiagonalizing A\n* (Workspace: need 4*M, prefer 3*M+M*NB)\n*\n CALL DORGBR( 'P', M, N, M, A, LDA, WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IWORK = IE + M\n*\n* Perform bidiagonal QR iteration, computing right\n* singular vectors of A in A\n* (Workspace: need BDSPAC)\n*\n CALL DBDSQR( 'L', M, N, 0, 0, S, WORK( IE ), A, LDA,\n $ DUM, 1, DUM, 1, WORK( IWORK ), INFO )\n*\n END IF\n*\n ELSE IF( WNTVO .AND. WNTUAS ) THEN\n*\n* Path 3t(N much larger than M, JOBU='S' or 'A', JOBVT='O')\n* M right singular vectors to be overwritten on A and\n* M left singular vectors to be computed in U\n*\n IF( LWORK.GE.M*M+MAX( 4*M, BDSPAC ) ) THEN\n*\n* Sufficient workspace for a fast algorithm\n*\n IR = 1\n IF( LWORK.GE.MAX( WRKBL, LDA*N+M )+LDA*M ) THEN\n*\n* WORK(IU) is LDA by N and WORK(IR) is LDA by M\n*\n LDWRKU = LDA\n CHUNK = N\n LDWRKR = LDA\n ELSE IF( LWORK.GE.MAX( WRKBL, LDA*N+M )+M*M ) THEN\n*\n* WORK(IU) is LDA by N and WORK(IR) is M by M\n*\n LDWRKU = LDA\n CHUNK = N\n LDWRKR = M\n ELSE\n*\n* WORK(IU) is M by CHUNK and WORK(IR) is M by M\n*\n LDWRKU = M\n CHUNK = ( LWORK-M*M-M ) / M\n LDWRKR = M\n END IF\n ITAU = IR + LDWRKR*M\n IWORK = ITAU + M\n*\n* Compute A=L*Q\n* (Workspace: need M*M+2*M, prefer M*M+M+M*NB)\n*\n CALL DGELQF( M, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Copy L to U, zeroing about above it\n*\n CALL DLACPY( 'L', M, M, A, LDA, U, LDU )\n CALL DLASET( 'U', M-1, M-1, ZERO, ZERO, U( 1, 2 ),\n $ LDU )\n*\n* Generate Q in A\n* (Workspace: need M*M+2*M, prefer M*M+M+M*NB)\n*\n CALL DORGLQ( M, N, M, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IE = ITAU\n ITAUQ = IE + M\n ITAUP = ITAUQ + M\n IWORK = ITAUP + M\n*\n* Bidiagonalize L in U, copying result to WORK(IR)\n* (Workspace: need M*M+4*M, prefer M*M+3*M+2*M*NB)\n*\n CALL DGEBRD( M, M, U, LDU, S, WORK( IE ),\n $ WORK( ITAUQ ), WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n CALL DLACPY( 'U', M, M, U, LDU, WORK( IR ), LDWRKR )\n*\n* Generate right vectors bidiagonalizing L in WORK(IR)\n* (Workspace: need M*M+4*M-1, prefer M*M+3*M+(M-1)*NB)\n*\n CALL DORGBR( 'P', M, M, M, WORK( IR ), LDWRKR,\n $ WORK( ITAUP ), WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n*\n* Generate left vectors bidiagonalizing L in U\n* (Workspace: need M*M+4*M, prefer M*M+3*M+M*NB)\n*\n CALL DORGBR( 'Q', M, M, M, U, LDU, WORK( ITAUQ ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IWORK = IE + M\n*\n* Perform bidiagonal QR iteration, computing left\n* singular vectors of L in U, and computing right\n* singular vectors of L in WORK(IR)\n* (Workspace: need M*M+BDSPAC)\n*\n CALL DBDSQR( 'U', M, M, M, 0, S, WORK( IE ),\n $ WORK( IR ), LDWRKR, U, LDU, DUM, 1,\n $ WORK( IWORK ), INFO )\n IU = IE + M\n*\n* Multiply right singular vectors of L in WORK(IR) by Q\n* in A, storing result in WORK(IU) and copying to A\n* (Workspace: need M*M+2*M, prefer M*M+M*N+M))\n*\n DO 40 I = 1, N, CHUNK\n BLK = MIN( N-I+1, CHUNK )\n CALL DGEMM( 'N', 'N', M, BLK, M, ONE, WORK( IR ),\n $ LDWRKR, A( 1, I ), LDA, ZERO,\n $ WORK( IU ), LDWRKU )\n CALL DLACPY( 'F', M, BLK, WORK( IU ), LDWRKU,\n $ A( 1, I ), LDA )\n 40 CONTINUE\n*\n ELSE\n*\n* Insufficient workspace for a fast algorithm\n*\n ITAU = 1\n IWORK = ITAU + M\n*\n* Compute A=L*Q\n* (Workspace: need 2*M, prefer M+M*NB)\n*\n CALL DGELQF( M, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Copy L to U, zeroing out above it\n*\n CALL DLACPY( 'L', M, M, A, LDA, U, LDU )\n CALL DLASET( 'U', M-1, M-1, ZERO, ZERO, U( 1, 2 ),\n $ LDU )\n*\n* Generate Q in A\n* (Workspace: need 2*M, prefer M+M*NB)\n*\n CALL DORGLQ( M, N, M, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IE = ITAU\n ITAUQ = IE + M\n ITAUP = ITAUQ + M\n IWORK = ITAUP + M\n*\n* Bidiagonalize L in U\n* (Workspace: need 4*M, prefer 3*M+2*M*NB)\n*\n CALL DGEBRD( M, M, U, LDU, S, WORK( IE ),\n $ WORK( ITAUQ ), WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Multiply right vectors bidiagonalizing L by Q in A\n* (Workspace: need 3*M+N, prefer 3*M+N*NB)\n*\n CALL DORMBR( 'P', 'L', 'T', M, N, M, U, LDU,\n $ WORK( ITAUP ), A, LDA, WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n*\n* Generate left vectors bidiagonalizing L in U\n* (Workspace: need 4*M, prefer 3*M+M*NB)\n*\n CALL DORGBR( 'Q', M, M, M, U, LDU, WORK( ITAUQ ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IWORK = IE + M\n*\n* Perform bidiagonal QR iteration, computing left\n* singular vectors of A in U and computing right\n* singular vectors of A in A\n* (Workspace: need BDSPAC)\n*\n CALL DBDSQR( 'U', M, N, M, 0, S, WORK( IE ), A, LDA,\n $ U, LDU, DUM, 1, WORK( IWORK ), INFO )\n*\n END IF\n*\n ELSE IF( WNTVS ) THEN\n*\n IF( WNTUN ) THEN\n*\n* Path 4t(N much larger than M, JOBU='N', JOBVT='S')\n* M right singular vectors to be computed in VT and\n* no left singular vectors to be computed\n*\n IF( LWORK.GE.M*M+MAX( 4*M, BDSPAC ) ) THEN\n*\n* Sufficient workspace for a fast algorithm\n*\n IR = 1\n IF( LWORK.GE.WRKBL+LDA*M ) THEN\n*\n* WORK(IR) is LDA by M\n*\n LDWRKR = LDA\n ELSE\n*\n* WORK(IR) is M by M\n*\n LDWRKR = M\n END IF\n ITAU = IR + LDWRKR*M\n IWORK = ITAU + M\n*\n* Compute A=L*Q\n* (Workspace: need M*M+2*M, prefer M*M+M+M*NB)\n*\n CALL DGELQF( M, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Copy L to WORK(IR), zeroing out above it\n*\n CALL DLACPY( 'L', M, M, A, LDA, WORK( IR ),\n $ LDWRKR )\n CALL DLASET( 'U', M-1, M-1, ZERO, ZERO,\n $ WORK( IR+LDWRKR ), LDWRKR )\n*\n* Generate Q in A\n* (Workspace: need M*M+2*M, prefer M*M+M+M*NB)\n*\n CALL DORGLQ( M, N, M, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IE = ITAU\n ITAUQ = IE + M\n ITAUP = ITAUQ + M\n IWORK = ITAUP + M\n*\n* Bidiagonalize L in WORK(IR)\n* (Workspace: need M*M+4*M, prefer M*M+3*M+2*M*NB)\n*\n CALL DGEBRD( M, M, WORK( IR ), LDWRKR, S,\n $ WORK( IE ), WORK( ITAUQ ),\n $ WORK( ITAUP ), WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n*\n* Generate right vectors bidiagonalizing L in\n* WORK(IR)\n* (Workspace: need M*M+4*M, prefer M*M+3*M+(M-1)*NB)\n*\n CALL DORGBR( 'P', M, M, M, WORK( IR ), LDWRKR,\n $ WORK( ITAUP ), WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n IWORK = IE + M\n*\n* Perform bidiagonal QR iteration, computing right\n* singular vectors of L in WORK(IR)\n* (Workspace: need M*M+BDSPAC)\n*\n CALL DBDSQR( 'U', M, M, 0, 0, S, WORK( IE ),\n $ WORK( IR ), LDWRKR, DUM, 1, DUM, 1,\n $ WORK( IWORK ), INFO )\n*\n* Multiply right singular vectors of L in WORK(IR) by\n* Q in A, storing result in VT\n* (Workspace: need M*M)\n*\n CALL DGEMM( 'N', 'N', M, N, M, ONE, WORK( IR ),\n $ LDWRKR, A, LDA, ZERO, VT, LDVT )\n*\n ELSE\n*\n* Insufficient workspace for a fast algorithm\n*\n ITAU = 1\n IWORK = ITAU + M\n*\n* Compute A=L*Q\n* (Workspace: need 2*M, prefer M+M*NB)\n*\n CALL DGELQF( M, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Copy result to VT\n*\n CALL DLACPY( 'U', M, N, A, LDA, VT, LDVT )\n*\n* Generate Q in VT\n* (Workspace: need 2*M, prefer M+M*NB)\n*\n CALL DORGLQ( M, N, M, VT, LDVT, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IE = ITAU\n ITAUQ = IE + M\n ITAUP = ITAUQ + M\n IWORK = ITAUP + M\n*\n* Zero out above L in A\n*\n CALL DLASET( 'U', M-1, M-1, ZERO, ZERO, A( 1, 2 ),\n $ LDA )\n*\n* Bidiagonalize L in A\n* (Workspace: need 4*M, prefer 3*M+2*M*NB)\n*\n CALL DGEBRD( M, M, A, LDA, S, WORK( IE ),\n $ WORK( ITAUQ ), WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Multiply right vectors bidiagonalizing L by Q in VT\n* (Workspace: need 3*M+N, prefer 3*M+N*NB)\n*\n CALL DORMBR( 'P', 'L', 'T', M, N, M, A, LDA,\n $ WORK( ITAUP ), VT, LDVT,\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IWORK = IE + M\n*\n* Perform bidiagonal QR iteration, computing right\n* singular vectors of A in VT\n* (Workspace: need BDSPAC)\n*\n CALL DBDSQR( 'U', M, N, 0, 0, S, WORK( IE ), VT,\n $ LDVT, DUM, 1, DUM, 1, WORK( IWORK ),\n $ INFO )\n*\n END IF\n*\n ELSE IF( WNTUO ) THEN\n*\n* Path 5t(N much larger than M, JOBU='O', JOBVT='S')\n* M right singular vectors to be computed in VT and\n* M left singular vectors to be overwritten on A\n*\n IF( LWORK.GE.2*M*M+MAX( 4*M, BDSPAC ) ) THEN\n*\n* Sufficient workspace for a fast algorithm\n*\n IU = 1\n IF( LWORK.GE.WRKBL+2*LDA*M ) THEN\n*\n* WORK(IU) is LDA by M and WORK(IR) is LDA by M\n*\n LDWRKU = LDA\n IR = IU + LDWRKU*M\n LDWRKR = LDA\n ELSE IF( LWORK.GE.WRKBL+( LDA+M )*M ) THEN\n*\n* WORK(IU) is LDA by M and WORK(IR) is M by M\n*\n LDWRKU = LDA\n IR = IU + LDWRKU*M\n LDWRKR = M\n ELSE\n*\n* WORK(IU) is M by M and WORK(IR) is M by M\n*\n LDWRKU = M\n IR = IU + LDWRKU*M\n LDWRKR = M\n END IF\n ITAU = IR + LDWRKR*M\n IWORK = ITAU + M\n*\n* Compute A=L*Q\n* (Workspace: need 2*M*M+2*M, prefer 2*M*M+M+M*NB)\n*\n CALL DGELQF( M, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Copy L to WORK(IU), zeroing out below it\n*\n CALL DLACPY( 'L', M, M, A, LDA, WORK( IU ),\n $ LDWRKU )\n CALL DLASET( 'U', M-1, M-1, ZERO, ZERO,\n $ WORK( IU+LDWRKU ), LDWRKU )\n*\n* Generate Q in A\n* (Workspace: need 2*M*M+2*M, prefer 2*M*M+M+M*NB)\n*\n CALL DORGLQ( M, N, M, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IE = ITAU\n ITAUQ = IE + M\n ITAUP = ITAUQ + M\n IWORK = ITAUP + M\n*\n* Bidiagonalize L in WORK(IU), copying result to\n* WORK(IR)\n* (Workspace: need 2*M*M+4*M,\n* prefer 2*M*M+3*M+2*M*NB)\n*\n CALL DGEBRD( M, M, WORK( IU ), LDWRKU, S,\n $ WORK( IE ), WORK( ITAUQ ),\n $ WORK( ITAUP ), WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n CALL DLACPY( 'L', M, M, WORK( IU ), LDWRKU,\n $ WORK( IR ), LDWRKR )\n*\n* Generate right bidiagonalizing vectors in WORK(IU)\n* (Workspace: need 2*M*M+4*M-1,\n* prefer 2*M*M+3*M+(M-1)*NB)\n*\n CALL DORGBR( 'P', M, M, M, WORK( IU ), LDWRKU,\n $ WORK( ITAUP ), WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n*\n* Generate left bidiagonalizing vectors in WORK(IR)\n* (Workspace: need 2*M*M+4*M, prefer 2*M*M+3*M+M*NB)\n*\n CALL DORGBR( 'Q', M, M, M, WORK( IR ), LDWRKR,\n $ WORK( ITAUQ ), WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n IWORK = IE + M\n*\n* Perform bidiagonal QR iteration, computing left\n* singular vectors of L in WORK(IR) and computing\n* right singular vectors of L in WORK(IU)\n* (Workspace: need 2*M*M+BDSPAC)\n*\n CALL DBDSQR( 'U', M, M, M, 0, S, WORK( IE ),\n $ WORK( IU ), LDWRKU, WORK( IR ),\n $ LDWRKR, DUM, 1, WORK( IWORK ), INFO )\n*\n* Multiply right singular vectors of L in WORK(IU) by\n* Q in A, storing result in VT\n* (Workspace: need M*M)\n*\n CALL DGEMM( 'N', 'N', M, N, M, ONE, WORK( IU ),\n $ LDWRKU, A, LDA, ZERO, VT, LDVT )\n*\n* Copy left singular vectors of L to A\n* (Workspace: need M*M)\n*\n CALL DLACPY( 'F', M, M, WORK( IR ), LDWRKR, A,\n $ LDA )\n*\n ELSE\n*\n* Insufficient workspace for a fast algorithm\n*\n ITAU = 1\n IWORK = ITAU + M\n*\n* Compute A=L*Q, copying result to VT\n* (Workspace: need 2*M, prefer M+M*NB)\n*\n CALL DGELQF( M, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n CALL DLACPY( 'U', M, N, A, LDA, VT, LDVT )\n*\n* Generate Q in VT\n* (Workspace: need 2*M, prefer M+M*NB)\n*\n CALL DORGLQ( M, N, M, VT, LDVT, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IE = ITAU\n ITAUQ = IE + M\n ITAUP = ITAUQ + M\n IWORK = ITAUP + M\n*\n* Zero out above L in A\n*\n CALL DLASET( 'U', M-1, M-1, ZERO, ZERO, A( 1, 2 ),\n $ LDA )\n*\n* Bidiagonalize L in A\n* (Workspace: need 4*M, prefer 3*M+2*M*NB)\n*\n CALL DGEBRD( M, M, A, LDA, S, WORK( IE ),\n $ WORK( ITAUQ ), WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Multiply right vectors bidiagonalizing L by Q in VT\n* (Workspace: need 3*M+N, prefer 3*M+N*NB)\n*\n CALL DORMBR( 'P', 'L', 'T', M, N, M, A, LDA,\n $ WORK( ITAUP ), VT, LDVT,\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Generate left bidiagonalizing vectors of L in A\n* (Workspace: need 4*M, prefer 3*M+M*NB)\n*\n CALL DORGBR( 'Q', M, M, M, A, LDA, WORK( ITAUQ ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IWORK = IE + M\n*\n* Perform bidiagonal QR iteration, compute left\n* singular vectors of A in A and compute right\n* singular vectors of A in VT\n* (Workspace: need BDSPAC)\n*\n CALL DBDSQR( 'U', M, N, M, 0, S, WORK( IE ), VT,\n $ LDVT, A, LDA, DUM, 1, WORK( IWORK ),\n $ INFO )\n*\n END IF\n*\n ELSE IF( WNTUAS ) THEN\n*\n* Path 6t(N much larger than M, JOBU='S' or 'A',\n* JOBVT='S')\n* M right singular vectors to be computed in VT and\n* M left singular vectors to be computed in U\n*\n IF( LWORK.GE.M*M+MAX( 4*M, BDSPAC ) ) THEN\n*\n* Sufficient workspace for a fast algorithm\n*\n IU = 1\n IF( LWORK.GE.WRKBL+LDA*M ) THEN\n*\n* WORK(IU) is LDA by N\n*\n LDWRKU = LDA\n ELSE\n*\n* WORK(IU) is LDA by M\n*\n LDWRKU = M\n END IF\n ITAU = IU + LDWRKU*M\n IWORK = ITAU + M\n*\n* Compute A=L*Q\n* (Workspace: need M*M+2*M, prefer M*M+M+M*NB)\n*\n CALL DGELQF( M, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Copy L to WORK(IU), zeroing out above it\n*\n CALL DLACPY( 'L', M, M, A, LDA, WORK( IU ),\n $ LDWRKU )\n CALL DLASET( 'U', M-1, M-1, ZERO, ZERO,\n $ WORK( IU+LDWRKU ), LDWRKU )\n*\n* Generate Q in A\n* (Workspace: need M*M+2*M, prefer M*M+M+M*NB)\n*\n CALL DORGLQ( M, N, M, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IE = ITAU\n ITAUQ = IE + M\n ITAUP = ITAUQ + M\n IWORK = ITAUP + M\n*\n* Bidiagonalize L in WORK(IU), copying result to U\n* (Workspace: need M*M+4*M, prefer M*M+3*M+2*M*NB)\n*\n CALL DGEBRD( M, M, WORK( IU ), LDWRKU, S,\n $ WORK( IE ), WORK( ITAUQ ),\n $ WORK( ITAUP ), WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n CALL DLACPY( 'L', M, M, WORK( IU ), LDWRKU, U,\n $ LDU )\n*\n* Generate right bidiagonalizing vectors in WORK(IU)\n* (Workspace: need M*M+4*M-1,\n* prefer M*M+3*M+(M-1)*NB)\n*\n CALL DORGBR( 'P', M, M, M, WORK( IU ), LDWRKU,\n $ WORK( ITAUP ), WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n*\n* Generate left bidiagonalizing vectors in U\n* (Workspace: need M*M+4*M, prefer M*M+3*M+M*NB)\n*\n CALL DORGBR( 'Q', M, M, M, U, LDU, WORK( ITAUQ ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IWORK = IE + M\n*\n* Perform bidiagonal QR iteration, computing left\n* singular vectors of L in U and computing right\n* singular vectors of L in WORK(IU)\n* (Workspace: need M*M+BDSPAC)\n*\n CALL DBDSQR( 'U', M, M, M, 0, S, WORK( IE ),\n $ WORK( IU ), LDWRKU, U, LDU, DUM, 1,\n $ WORK( IWORK ), INFO )\n*\n* Multiply right singular vectors of L in WORK(IU) by\n* Q in A, storing result in VT\n* (Workspace: need M*M)\n*\n CALL DGEMM( 'N', 'N', M, N, M, ONE, WORK( IU ),\n $ LDWRKU, A, LDA, ZERO, VT, LDVT )\n*\n ELSE\n*\n* Insufficient workspace for a fast algorithm\n*\n ITAU = 1\n IWORK = ITAU + M\n*\n* Compute A=L*Q, copying result to VT\n* (Workspace: need 2*M, prefer M+M*NB)\n*\n CALL DGELQF( M, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n CALL DLACPY( 'U', M, N, A, LDA, VT, LDVT )\n*\n* Generate Q in VT\n* (Workspace: need 2*M, prefer M+M*NB)\n*\n CALL DORGLQ( M, N, M, VT, LDVT, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Copy L to U, zeroing out above it\n*\n CALL DLACPY( 'L', M, M, A, LDA, U, LDU )\n CALL DLASET( 'U', M-1, M-1, ZERO, ZERO, U( 1, 2 ),\n $ LDU )\n IE = ITAU\n ITAUQ = IE + M\n ITAUP = ITAUQ + M\n IWORK = ITAUP + M\n*\n* Bidiagonalize L in U\n* (Workspace: need 4*M, prefer 3*M+2*M*NB)\n*\n CALL DGEBRD( M, M, U, LDU, S, WORK( IE ),\n $ WORK( ITAUQ ), WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Multiply right bidiagonalizing vectors in U by Q\n* in VT\n* (Workspace: need 3*M+N, prefer 3*M+N*NB)\n*\n CALL DORMBR( 'P', 'L', 'T', M, N, M, U, LDU,\n $ WORK( ITAUP ), VT, LDVT,\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Generate left bidiagonalizing vectors in U\n* (Workspace: need 4*M, prefer 3*M+M*NB)\n*\n CALL DORGBR( 'Q', M, M, M, U, LDU, WORK( ITAUQ ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IWORK = IE + M\n*\n* Perform bidiagonal QR iteration, computing left\n* singular vectors of A in U and computing right\n* singular vectors of A in VT\n* (Workspace: need BDSPAC)\n*\n CALL DBDSQR( 'U', M, N, M, 0, S, WORK( IE ), VT,\n $ LDVT, U, LDU, DUM, 1, WORK( IWORK ),\n $ INFO )\n*\n END IF\n*\n END IF\n*\n ELSE IF( WNTVA ) THEN\n*\n IF( WNTUN ) THEN\n*\n* Path 7t(N much larger than M, JOBU='N', JOBVT='A')\n* N right singular vectors to be computed in VT and\n* no left singular vectors to be computed\n*\n IF( LWORK.GE.M*M+MAX( N+M, 4*M, BDSPAC ) ) THEN\n*\n* Sufficient workspace for a fast algorithm\n*\n IR = 1\n IF( LWORK.GE.WRKBL+LDA*M ) THEN\n*\n* WORK(IR) is LDA by M\n*\n LDWRKR = LDA\n ELSE\n*\n* WORK(IR) is M by M\n*\n LDWRKR = M\n END IF\n ITAU = IR + LDWRKR*M\n IWORK = ITAU + M\n*\n* Compute A=L*Q, copying result to VT\n* (Workspace: need M*M+2*M, prefer M*M+M+M*NB)\n*\n CALL DGELQF( M, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n CALL DLACPY( 'U', M, N, A, LDA, VT, LDVT )\n*\n* Copy L to WORK(IR), zeroing out above it\n*\n CALL DLACPY( 'L', M, M, A, LDA, WORK( IR ),\n $ LDWRKR )\n CALL DLASET( 'U', M-1, M-1, ZERO, ZERO,\n $ WORK( IR+LDWRKR ), LDWRKR )\n*\n* Generate Q in VT\n* (Workspace: need M*M+M+N, prefer M*M+M+N*NB)\n*\n CALL DORGLQ( N, N, M, VT, LDVT, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IE = ITAU\n ITAUQ = IE + M\n ITAUP = ITAUQ + M\n IWORK = ITAUP + M\n*\n* Bidiagonalize L in WORK(IR)\n* (Workspace: need M*M+4*M, prefer M*M+3*M+2*M*NB)\n*\n CALL DGEBRD( M, M, WORK( IR ), LDWRKR, S,\n $ WORK( IE ), WORK( ITAUQ ),\n $ WORK( ITAUP ), WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n*\n* Generate right bidiagonalizing vectors in WORK(IR)\n* (Workspace: need M*M+4*M-1,\n* prefer M*M+3*M+(M-1)*NB)\n*\n CALL DORGBR( 'P', M, M, M, WORK( IR ), LDWRKR,\n $ WORK( ITAUP ), WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n IWORK = IE + M\n*\n* Perform bidiagonal QR iteration, computing right\n* singular vectors of L in WORK(IR)\n* (Workspace: need M*M+BDSPAC)\n*\n CALL DBDSQR( 'U', M, M, 0, 0, S, WORK( IE ),\n $ WORK( IR ), LDWRKR, DUM, 1, DUM, 1,\n $ WORK( IWORK ), INFO )\n*\n* Multiply right singular vectors of L in WORK(IR) by\n* Q in VT, storing result in A\n* (Workspace: need M*M)\n*\n CALL DGEMM( 'N', 'N', M, N, M, ONE, WORK( IR ),\n $ LDWRKR, VT, LDVT, ZERO, A, LDA )\n*\n* Copy right singular vectors of A from A to VT\n*\n CALL DLACPY( 'F', M, N, A, LDA, VT, LDVT )\n*\n ELSE\n*\n* Insufficient workspace for a fast algorithm\n*\n ITAU = 1\n IWORK = ITAU + M\n*\n* Compute A=L*Q, copying result to VT\n* (Workspace: need 2*M, prefer M+M*NB)\n*\n CALL DGELQF( M, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n CALL DLACPY( 'U', M, N, A, LDA, VT, LDVT )\n*\n* Generate Q in VT\n* (Workspace: need M+N, prefer M+N*NB)\n*\n CALL DORGLQ( N, N, M, VT, LDVT, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IE = ITAU\n ITAUQ = IE + M\n ITAUP = ITAUQ + M\n IWORK = ITAUP + M\n*\n* Zero out above L in A\n*\n CALL DLASET( 'U', M-1, M-1, ZERO, ZERO, A( 1, 2 ),\n $ LDA )\n*\n* Bidiagonalize L in A\n* (Workspace: need 4*M, prefer 3*M+2*M*NB)\n*\n CALL DGEBRD( M, M, A, LDA, S, WORK( IE ),\n $ WORK( ITAUQ ), WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Multiply right bidiagonalizing vectors in A by Q\n* in VT\n* (Workspace: need 3*M+N, prefer 3*M+N*NB)\n*\n CALL DORMBR( 'P', 'L', 'T', M, N, M, A, LDA,\n $ WORK( ITAUP ), VT, LDVT,\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IWORK = IE + M\n*\n* Perform bidiagonal QR iteration, computing right\n* singular vectors of A in VT\n* (Workspace: need BDSPAC)\n*\n CALL DBDSQR( 'U', M, N, 0, 0, S, WORK( IE ), VT,\n $ LDVT, DUM, 1, DUM, 1, WORK( IWORK ),\n $ INFO )\n*\n END IF\n*\n ELSE IF( WNTUO ) THEN\n*\n* Path 8t(N much larger than M, JOBU='O', JOBVT='A')\n* N right singular vectors to be computed in VT and\n* M left singular vectors to be overwritten on A\n*\n IF( LWORK.GE.2*M*M+MAX( N+M, 4*M, BDSPAC ) ) THEN\n*\n* Sufficient workspace for a fast algorithm\n*\n IU = 1\n IF( LWORK.GE.WRKBL+2*LDA*M ) THEN\n*\n* WORK(IU) is LDA by M and WORK(IR) is LDA by M\n*\n LDWRKU = LDA\n IR = IU + LDWRKU*M\n LDWRKR = LDA\n ELSE IF( LWORK.GE.WRKBL+( LDA+M )*M ) THEN\n*\n* WORK(IU) is LDA by M and WORK(IR) is M by M\n*\n LDWRKU = LDA\n IR = IU + LDWRKU*M\n LDWRKR = M\n ELSE\n*\n* WORK(IU) is M by M and WORK(IR) is M by M\n*\n LDWRKU = M\n IR = IU + LDWRKU*M\n LDWRKR = M\n END IF\n ITAU = IR + LDWRKR*M\n IWORK = ITAU + M\n*\n* Compute A=L*Q, copying result to VT\n* (Workspace: need 2*M*M+2*M, prefer 2*M*M+M+M*NB)\n*\n CALL DGELQF( M, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n CALL DLACPY( 'U', M, N, A, LDA, VT, LDVT )\n*\n* Generate Q in VT\n* (Workspace: need 2*M*M+M+N, prefer 2*M*M+M+N*NB)\n*\n CALL DORGLQ( N, N, M, VT, LDVT, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Copy L to WORK(IU), zeroing out above it\n*\n CALL DLACPY( 'L', M, M, A, LDA, WORK( IU ),\n $ LDWRKU )\n CALL DLASET( 'U', M-1, M-1, ZERO, ZERO,\n $ WORK( IU+LDWRKU ), LDWRKU )\n IE = ITAU\n ITAUQ = IE + M\n ITAUP = ITAUQ + M\n IWORK = ITAUP + M\n*\n* Bidiagonalize L in WORK(IU), copying result to\n* WORK(IR)\n* (Workspace: need 2*M*M+4*M,\n* prefer 2*M*M+3*M+2*M*NB)\n*\n CALL DGEBRD( M, M, WORK( IU ), LDWRKU, S,\n $ WORK( IE ), WORK( ITAUQ ),\n $ WORK( ITAUP ), WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n CALL DLACPY( 'L', M, M, WORK( IU ), LDWRKU,\n $ WORK( IR ), LDWRKR )\n*\n* Generate right bidiagonalizing vectors in WORK(IU)\n* (Workspace: need 2*M*M+4*M-1,\n* prefer 2*M*M+3*M+(M-1)*NB)\n*\n CALL DORGBR( 'P', M, M, M, WORK( IU ), LDWRKU,\n $ WORK( ITAUP ), WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n*\n* Generate left bidiagonalizing vectors in WORK(IR)\n* (Workspace: need 2*M*M+4*M, prefer 2*M*M+3*M+M*NB)\n*\n CALL DORGBR( 'Q', M, M, M, WORK( IR ), LDWRKR,\n $ WORK( ITAUQ ), WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n IWORK = IE + M\n*\n* Perform bidiagonal QR iteration, computing left\n* singular vectors of L in WORK(IR) and computing\n* right singular vectors of L in WORK(IU)\n* (Workspace: need 2*M*M+BDSPAC)\n*\n CALL DBDSQR( 'U', M, M, M, 0, S, WORK( IE ),\n $ WORK( IU ), LDWRKU, WORK( IR ),\n $ LDWRKR, DUM, 1, WORK( IWORK ), INFO )\n*\n* Multiply right singular vectors of L in WORK(IU) by\n* Q in VT, storing result in A\n* (Workspace: need M*M)\n*\n CALL DGEMM( 'N', 'N', M, N, M, ONE, WORK( IU ),\n $ LDWRKU, VT, LDVT, ZERO, A, LDA )\n*\n* Copy right singular vectors of A from A to VT\n*\n CALL DLACPY( 'F', M, N, A, LDA, VT, LDVT )\n*\n* Copy left singular vectors of A from WORK(IR) to A\n*\n CALL DLACPY( 'F', M, M, WORK( IR ), LDWRKR, A,\n $ LDA )\n*\n ELSE\n*\n* Insufficient workspace for a fast algorithm\n*\n ITAU = 1\n IWORK = ITAU + M\n*\n* Compute A=L*Q, copying result to VT\n* (Workspace: need 2*M, prefer M+M*NB)\n*\n CALL DGELQF( M, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n CALL DLACPY( 'U', M, N, A, LDA, VT, LDVT )\n*\n* Generate Q in VT\n* (Workspace: need M+N, prefer M+N*NB)\n*\n CALL DORGLQ( N, N, M, VT, LDVT, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IE = ITAU\n ITAUQ = IE + M\n ITAUP = ITAUQ + M\n IWORK = ITAUP + M\n*\n* Zero out above L in A\n*\n CALL DLASET( 'U', M-1, M-1, ZERO, ZERO, A( 1, 2 ),\n $ LDA )\n*\n* Bidiagonalize L in A\n* (Workspace: need 4*M, prefer 3*M+2*M*NB)\n*\n CALL DGEBRD( M, M, A, LDA, S, WORK( IE ),\n $ WORK( ITAUQ ), WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Multiply right bidiagonalizing vectors in A by Q\n* in VT\n* (Workspace: need 3*M+N, prefer 3*M+N*NB)\n*\n CALL DORMBR( 'P', 'L', 'T', M, N, M, A, LDA,\n $ WORK( ITAUP ), VT, LDVT,\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Generate left bidiagonalizing vectors in A\n* (Workspace: need 4*M, prefer 3*M+M*NB)\n*\n CALL DORGBR( 'Q', M, M, M, A, LDA, WORK( ITAUQ ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IWORK = IE + M\n*\n* Perform bidiagonal QR iteration, computing left\n* singular vectors of A in A and computing right\n* singular vectors of A in VT\n* (Workspace: need BDSPAC)\n*\n CALL DBDSQR( 'U', M, N, M, 0, S, WORK( IE ), VT,\n $ LDVT, A, LDA, DUM, 1, WORK( IWORK ),\n $ INFO )\n*\n END IF\n*\n ELSE IF( WNTUAS ) THEN\n*\n* Path 9t(N much larger than M, JOBU='S' or 'A',\n* JOBVT='A')\n* N right singular vectors to be computed in VT and\n* M left singular vectors to be computed in U\n*\n IF( LWORK.GE.M*M+MAX( N+M, 4*M, BDSPAC ) ) THEN\n*\n* Sufficient workspace for a fast algorithm\n*\n IU = 1\n IF( LWORK.GE.WRKBL+LDA*M ) THEN\n*\n* WORK(IU) is LDA by M\n*\n LDWRKU = LDA\n ELSE\n*\n* WORK(IU) is M by M\n*\n LDWRKU = M\n END IF\n ITAU = IU + LDWRKU*M\n IWORK = ITAU + M\n*\n* Compute A=L*Q, copying result to VT\n* (Workspace: need M*M+2*M, prefer M*M+M+M*NB)\n*\n CALL DGELQF( M, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n CALL DLACPY( 'U', M, N, A, LDA, VT, LDVT )\n*\n* Generate Q in VT\n* (Workspace: need M*M+M+N, prefer M*M+M+N*NB)\n*\n CALL DORGLQ( N, N, M, VT, LDVT, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Copy L to WORK(IU), zeroing out above it\n*\n CALL DLACPY( 'L', M, M, A, LDA, WORK( IU ),\n $ LDWRKU )\n CALL DLASET( 'U', M-1, M-1, ZERO, ZERO,\n $ WORK( IU+LDWRKU ), LDWRKU )\n IE = ITAU\n ITAUQ = IE + M\n ITAUP = ITAUQ + M\n IWORK = ITAUP + M\n*\n* Bidiagonalize L in WORK(IU), copying result to U\n* (Workspace: need M*M+4*M, prefer M*M+3*M+2*M*NB)\n*\n CALL DGEBRD( M, M, WORK( IU ), LDWRKU, S,\n $ WORK( IE ), WORK( ITAUQ ),\n $ WORK( ITAUP ), WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n CALL DLACPY( 'L', M, M, WORK( IU ), LDWRKU, U,\n $ LDU )\n*\n* Generate right bidiagonalizing vectors in WORK(IU)\n* (Workspace: need M*M+4*M, prefer M*M+3*M+(M-1)*NB)\n*\n CALL DORGBR( 'P', M, M, M, WORK( IU ), LDWRKU,\n $ WORK( ITAUP ), WORK( IWORK ),\n $ LWORK-IWORK+1, IERR )\n*\n* Generate left bidiagonalizing vectors in U\n* (Workspace: need M*M+4*M, prefer M*M+3*M+M*NB)\n*\n CALL DORGBR( 'Q', M, M, M, U, LDU, WORK( ITAUQ ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IWORK = IE + M\n*\n* Perform bidiagonal QR iteration, computing left\n* singular vectors of L in U and computing right\n* singular vectors of L in WORK(IU)\n* (Workspace: need M*M+BDSPAC)\n*\n CALL DBDSQR( 'U', M, M, M, 0, S, WORK( IE ),\n $ WORK( IU ), LDWRKU, U, LDU, DUM, 1,\n $ WORK( IWORK ), INFO )\n*\n* Multiply right singular vectors of L in WORK(IU) by\n* Q in VT, storing result in A\n* (Workspace: need M*M)\n*\n CALL DGEMM( 'N', 'N', M, N, M, ONE, WORK( IU ),\n $ LDWRKU, VT, LDVT, ZERO, A, LDA )\n*\n* Copy right singular vectors of A from A to VT\n*\n CALL DLACPY( 'F', M, N, A, LDA, VT, LDVT )\n*\n ELSE\n*\n* Insufficient workspace for a fast algorithm\n*\n ITAU = 1\n IWORK = ITAU + M\n*\n* Compute A=L*Q, copying result to VT\n* (Workspace: need 2*M, prefer M+M*NB)\n*\n CALL DGELQF( M, N, A, LDA, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n CALL DLACPY( 'U', M, N, A, LDA, VT, LDVT )\n*\n* Generate Q in VT\n* (Workspace: need M+N, prefer M+N*NB)\n*\n CALL DORGLQ( N, N, M, VT, LDVT, WORK( ITAU ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Copy L to U, zeroing out above it\n*\n CALL DLACPY( 'L', M, M, A, LDA, U, LDU )\n CALL DLASET( 'U', M-1, M-1, ZERO, ZERO, U( 1, 2 ),\n $ LDU )\n IE = ITAU\n ITAUQ = IE + M\n ITAUP = ITAUQ + M\n IWORK = ITAUP + M\n*\n* Bidiagonalize L in U\n* (Workspace: need 4*M, prefer 3*M+2*M*NB)\n*\n CALL DGEBRD( M, M, U, LDU, S, WORK( IE ),\n $ WORK( ITAUQ ), WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Multiply right bidiagonalizing vectors in U by Q\n* in VT\n* (Workspace: need 3*M+N, prefer 3*M+N*NB)\n*\n CALL DORMBR( 'P', 'L', 'T', M, N, M, U, LDU,\n $ WORK( ITAUP ), VT, LDVT,\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n*\n* Generate left bidiagonalizing vectors in U\n* (Workspace: need 4*M, prefer 3*M+M*NB)\n*\n CALL DORGBR( 'Q', M, M, M, U, LDU, WORK( ITAUQ ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n IWORK = IE + M\n*\n* Perform bidiagonal QR iteration, computing left\n* singular vectors of A in U and computing right\n* singular vectors of A in VT\n* (Workspace: need BDSPAC)\n*\n CALL DBDSQR( 'U', M, N, M, 0, S, WORK( IE ), VT,\n $ LDVT, U, LDU, DUM, 1, WORK( IWORK ),\n $ INFO )\n*\n END IF\n*\n END IF\n*\n END IF\n*\n ELSE\n*\n* N .LT. MNTHR\n*\n* Path 10t(N greater than M, but not much larger)\n* Reduce to bidiagonal form without LQ decomposition\n*\n IE = 1\n ITAUQ = IE + M\n ITAUP = ITAUQ + M\n IWORK = ITAUP + M\n*\n* Bidiagonalize A\n* (Workspace: need 3*M+N, prefer 3*M+(M+N)*NB)\n*\n CALL DGEBRD( M, N, A, LDA, S, WORK( IE ), WORK( ITAUQ ),\n $ WORK( ITAUP ), WORK( IWORK ), LWORK-IWORK+1,\n $ IERR )\n IF( WNTUAS ) THEN\n*\n* If left singular vectors desired in U, copy result to U\n* and generate left bidiagonalizing vectors in U\n* (Workspace: need 4*M-1, prefer 3*M+(M-1)*NB)\n*\n CALL DLACPY( 'L', M, M, A, LDA, U, LDU )\n CALL DORGBR( 'Q', M, M, N, U, LDU, WORK( ITAUQ ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n END IF\n IF( WNTVAS ) THEN\n*\n* If right singular vectors desired in VT, copy result to\n* VT and generate right bidiagonalizing vectors in VT\n* (Workspace: need 3*M+NRVT, prefer 3*M+NRVT*NB)\n*\n CALL DLACPY( 'U', M, N, A, LDA, VT, LDVT )\n IF( WNTVA )\n $ NRVT = N\n IF( WNTVS )\n $ NRVT = M\n CALL DORGBR( 'P', NRVT, N, M, VT, LDVT, WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n END IF\n IF( WNTUO ) THEN\n*\n* If left singular vectors desired in A, generate left\n* bidiagonalizing vectors in A\n* (Workspace: need 4*M-1, prefer 3*M+(M-1)*NB)\n*\n CALL DORGBR( 'Q', M, M, N, A, LDA, WORK( ITAUQ ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n END IF\n IF( WNTVO ) THEN\n*\n* If right singular vectors desired in A, generate right\n* bidiagonalizing vectors in A\n* (Workspace: need 4*M, prefer 3*M+M*NB)\n*\n CALL DORGBR( 'P', M, N, M, A, LDA, WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, IERR )\n END IF\n IWORK = IE + M\n IF( WNTUAS .OR. WNTUO )\n $ NRU = M\n IF( WNTUN )\n $ NRU = 0\n IF( WNTVAS .OR. WNTVO )\n $ NCVT = N\n IF( WNTVN )\n $ NCVT = 0\n IF( ( .NOT.WNTUO ) .AND. ( .NOT.WNTVO ) ) THEN\n*\n* Perform bidiagonal QR iteration, if desired, computing\n* left singular vectors in U and computing right singular\n* vectors in VT\n* (Workspace: need BDSPAC)\n*\n CALL DBDSQR( 'L', M, NCVT, NRU, 0, S, WORK( IE ), VT,\n $ LDVT, U, LDU, DUM, 1, WORK( IWORK ), INFO )\n ELSE IF( ( .NOT.WNTUO ) .AND. WNTVO ) THEN\n*\n* Perform bidiagonal QR iteration, if desired, computing\n* left singular vectors in U and computing right singular\n* vectors in A\n* (Workspace: need BDSPAC)\n*\n CALL DBDSQR( 'L', M, NCVT, NRU, 0, S, WORK( IE ), A, LDA,\n $ U, LDU, DUM, 1, WORK( IWORK ), INFO )\n ELSE\n*\n* Perform bidiagonal QR iteration, if desired, computing\n* left singular vectors in A and computing right singular\n* vectors in VT\n* (Workspace: need BDSPAC)\n*\n CALL DBDSQR( 'L', M, NCVT, NRU, 0, S, WORK( IE ), VT,\n $ LDVT, A, LDA, DUM, 1, WORK( IWORK ), INFO )\n END IF\n*\n END IF\n*\n END IF\n*\n* If DBDSQR failed to converge, copy unconverged superdiagonals\n* to WORK( 2:MINMN )\n*\n IF( INFO.NE.0 ) THEN\n IF( IE.GT.2 ) THEN\n DO 50 I = 1, MINMN - 1\n WORK( I+1 ) = WORK( I+IE-1 )\n 50 CONTINUE\n END IF\n IF( IE.LT.2 ) THEN\n DO 60 I = MINMN - 1, 1, -1\n WORK( I+1 ) = WORK( I+IE-1 )\n 60 CONTINUE\n END IF\n END IF\n*\n* Undo scaling if necessary\n*\n IF( ISCL.EQ.1 ) THEN\n IF( ANRM.GT.BIGNUM )\n $ CALL DLASCL( 'G', 0, 0, BIGNUM, ANRM, MINMN, 1, S, MINMN,\n $ IERR )\n IF( INFO.NE.0 .AND. ANRM.GT.BIGNUM )\n $ CALL DLASCL( 'G', 0, 0, BIGNUM, ANRM, MINMN-1, 1, WORK( 2 ),\n $ MINMN, IERR )\n IF( ANRM.LT.SMLNUM )\n $ CALL DLASCL( 'G', 0, 0, SMLNUM, ANRM, MINMN, 1, S, MINMN,\n $ IERR )\n IF( INFO.NE.0 .AND. ANRM.LT.SMLNUM )\n $ CALL DLASCL( 'G', 0, 0, SMLNUM, ANRM, MINMN-1, 1, WORK( 2 ),\n $ MINMN, IERR )\n END IF\n*\n* Return optimal workspace in WORK(1)\n*\n WORK( 1 ) = MAXWRK\n*\n RETURN\n*\n* End of DGESVD\n*\n END\nc $Id$\n", "meta": {"hexsha": "f21b7ce7528a091ab8ad816f8b1d9aa47890baa0", "size": 134926, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/lapack/double/dgesvd.f", "max_stars_repo_name": "dinisAbranches/nwchem", "max_stars_repo_head_hexsha": "21cb07ff634475600ab687882652b823cad8c0cd", "max_stars_repo_licenses": ["ECL-2.0"], "max_stars_count": 317, "max_stars_repo_stars_event_min_datetime": "2017-11-20T21:29:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T11:48:24.000Z", "max_issues_repo_path": "src/lapack/double/dgesvd.f", "max_issues_repo_name": "dinisAbranches/nwchem", "max_issues_repo_head_hexsha": "21cb07ff634475600ab687882652b823cad8c0cd", "max_issues_repo_licenses": ["ECL-2.0"], "max_issues_count": 356, "max_issues_repo_issues_event_min_datetime": "2017-12-05T01:38:12.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T02:28:21.000Z", "max_forks_repo_path": "src/lapack/double/dgesvd.f", "max_forks_repo_name": "dinisAbranches/nwchem", "max_forks_repo_head_hexsha": "21cb07ff634475600ab687882652b823cad8c0cd", "max_forks_repo_licenses": ["ECL-2.0"], "max_forks_count": 135, "max_forks_repo_forks_event_min_datetime": "2017-11-19T18:36:44.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T02:28:49.000Z", "avg_line_length": 38.6054363376, "max_line_length": 112, "alphanum_fraction": 0.396884218, "num_tokens": 38462, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110339361276, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6627654352218821}} {"text": "FUNCTION erf(x)\n!\nIMPLICIT NONE\n!\n! Function arguments\n!\nREAL :: x\nREAL :: erf\n!\n! Local variables\n!\nREAL :: a,b,c,d,e,f,g,h,i,j,k,x2,x3,x4,x5,z\n!\n!**********************************************************************\n \n! + + + purpose + + +\n! for the equation y = erf(x), the function returns y, given x\n! written by l. hagen and coded by i. elmanyawi.\n \n! + + + argument declarations + + +\n \n! + + + local variables + + +\n!\n! + + + end specifications + + +\n!\na = -0.000018936\nb = 0.030284321\nc = 1.12891921\nd = 0.37693092\ne = 0.029375235\nf = 0.088848989\ng = 0.068200064\nh = 0.022155958\ni = 0.050754183\nj = 0.038090749\nk = 0.034275052\n \nz = x\nx = abs(x)\nx2 = x*x\nx3 = x2*x\nx4 = x3*x\nx5 = x4*x\n \nerf = (a+c*x+e*x2+g*x3+i*x4+k*x5)/(1.000000+b*x+d*x2+f*x3+h*x4+j*x5)\nerf = erf*z/x\n!\nEND FUNCTION erf\n", "meta": {"hexsha": "e04dcbb8dffe74779c6191386b1b6352ee3d3e39", "size": 823, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Project Documents/Source Code Original/Erf.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/Erf.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/Erf.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": 16.7959183673, "max_line_length": 71, "alphanum_fraction": 0.5273390036, "num_tokens": 323, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248140158417, "lm_q2_score": 0.7057850278370111, "lm_q1q2_score": 0.662749654499815}} {"text": "! ---------------------------------------------------------------------\n! Program to calculate the first kind modified Bessel function\n! of integer order N, for any REAL X, using the function BESSI(N,X).\n! ---------------------------------------------------------------------\n! SAMPLE RUN:\n!\n! (Calculate Bessel function for N=2, X=0.75).\n! \n! Bessel function of order 2 for X = 0.7500:\n!\n! Y = 0.73666878E-01\n!\n! ---------------------------------------------------------------------\n! Reference: From Numath Library By Tuan Dang Trong in Fortran 77\n! [BIBLI 18]. \n!\n! F90 Release 1.0 By J-P Moreau, Paris\n! ---------------------------------------------------------------------\nPROGRAM TBESSI\n\n REAL*8 BESSI, y\n real*8 :: x\n INTEGER N\n\n N=0\n X=450.1D0\n\n Y = BESSI(N,X)\n\n write(*,10) N, X\n write(*,20) Y\n\n stop\n\n10 format (/' Bessel Function of order ',I2,' for X=',F8.4,':')\n20 format(/' Y = ',E15.8/)\n\nEND\n\n! ----------------------------------------------------------------------\n FUNCTION BESSI(N,X)\n!\n! This subroutine calculates the first kind modified Bessel function\n! of integer order N, for any REAL X. We use here the classical\n! recursion formula, when X > N. For X < N, the Miller's algorithm\n! is used to avoid overflows. \n! REFERENCE:\n! C.W.CLENSHAW, CHEBYSHEV SERIES FOR MATHEMATICAL FUNCTIONS,\n! MATHEMATICAL TABLES, VOL.5, 1962.\n!\n PARAMETER (IACC = 40,BIGNO = 1.D10, BIGNI = 1.D-10)\n REAL *8 X,BESSI,BESSI0,BESSI1,TOX,BIM,BI,BIP\n IF (N.EQ.0) THEN\n BESSI = BESSI0(X)\n RETURN\n ENDIF\n IF (N.EQ.1) THEN\n BESSI = BESSI1(X)\n RETURN\n ENDIF\n IF(X.EQ.0.D0) THEN\n BESSI=0.D0\n RETURN\n ENDIF\n TOX = 2.D0/X\n BIP = 0.D0\n BI = 1.D0\n BESSI = 0.D0\n M = 2*((N+INT(SQRT(FLOAT(IACC*N)))))\n DO 12 J = M,1,-1\n BIM = BIP+DFLOAT(J)*TOX*BI\n BIP = BI\n BI = BIM\n IF (ABS(BI).GT.BIGNO) THEN\n BI = BI*BIGNI\n BIP = BIP*BIGNI\n BESSI = BESSI*BIGNI\n ENDIF\n IF (J.EQ.N) BESSI = BIP\n 12 CONTINUE\n BESSI = BESSI*BESSI0(X)/BI\n RETURN\n END\n! ----------------------------------------------------------------------\n! Auxiliary Bessel functions for N=0, N=1\n FUNCTION BESSI0(X)\n REAL *8 X,BESSI0,Y,P1,P2,P3,P4,P5,P6,P7, &\n Q1,Q2,Q3,Q4,Q5,Q6,Q7,Q8,Q9,AX,BX\n DATA P1,P2,P3,P4,P5,P6,P7/1.D0,3.5156229D0,3.0899424D0,1.2067429D0, &\n 0.2659732D0,0.360768D-1,0.45813D-2/\n DATA Q1,Q2,Q3,Q4,Q5,Q6,Q7,Q8,Q9/0.39894228D0,0.1328592D-1, &\n 0.225319D-2,-0.157565D-2,0.916281D-2,-0.2057706D-1, &\n 0.2635537D-1,-0.1647633D-1,0.392377D-2/\n IF(ABS(X).LT.3.75D0) THEN\n Y=(X/3.75D0)**2\n BESSI0=P1+Y*(P2+Y*(P3+Y*(P4+Y*(P5+Y*(P6+Y*P7)))))\n ELSE\n AX=ABS(X)\n Y=3.75D0/AX\n BX=EXP(AX)/SQRT(AX)\n AX=Q1+Y*(Q2+Y*(Q3+Y*(Q4+Y*(Q5+Y*(Q6+Y*(Q7+Y*(Q8+Y*Q9)))))))\n BESSI0=AX*BX\n ENDIF\n RETURN\n END\n! ----------------------------------------------------------------------\n FUNCTION BESSI1(X)\n REAL *8 X,BESSI1,Y,P1,P2,P3,P4,P5,P6,P7, &\n Q1,Q2,Q3,Q4,Q5,Q6,Q7,Q8,Q9,AX,BX\n DATA P1,P2,P3,P4,P5,P6,P7/0.5D0,0.87890594D0,0.51498869D0, &\n 0.15084934D0,0.2658733D-1,0.301532D-2,0.32411D-3/\n DATA Q1,Q2,Q3,Q4,Q5,Q6,Q7,Q8,Q9/0.39894228D0,-0.3988024D-1, &\n -0.362018D-2,0.163801D-2,-0.1031555D-1,0.2282967D-1, &\n -0.2895312D-1,0.1787654D-1,-0.420059D-2/\n IF(ABS(X).LT.3.75D0) THEN\n Y=(X/3.75D0)**2\n BESSI1=X*(P1+Y*(P2+Y*(P3+Y*(P4+Y*(P5+Y*(P6+Y*P7))))))\n ELSE\n AX=ABS(X)\n Y=3.75D0/AX\n BX=EXP(AX)/SQRT(AX)\n AX=Q1+Y*(Q2+Y*(Q3+Y*(Q4+Y*(Q5+Y*(Q6+Y*(Q7+Y*(Q8+Y*Q9)))))))\n BESSI1=AX*BX\n ENDIF\n RETURN\n END\n! ----------------------------------------------------------------------\n\n! end of file tbessi.f90\n\n", "meta": {"hexsha": "98f106a81355a184595f12096be7d536aa1991ea", "size": 3896, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/test/test_beselI.f90", "max_stars_repo_name": "dlg0/p2f", "max_stars_repo_head_hexsha": "bed2ca3b2271899b32f7f44769bf2018ec350e20", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-04-18T22:34:36.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-21T05:12:33.000Z", "max_issues_repo_path": "src/test/test_beselI.f90", "max_issues_repo_name": "ORNL-Fusion/p2f", "max_issues_repo_head_hexsha": "bed2ca3b2271899b32f7f44769bf2018ec350e20", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-05-06T08:02:18.000Z", "max_issues_repo_issues_event_max_datetime": "2019-05-30T06:42:31.000Z", "max_forks_repo_path": "src/test/test_beselI.f90", "max_forks_repo_name": "dlg0/p2f", "max_forks_repo_head_hexsha": "bed2ca3b2271899b32f7f44769bf2018ec350e20", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.7404580153, "max_line_length": 76, "alphanum_fraction": 0.4761293634, "num_tokens": 1529, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950947024555, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.6627180549986547}} {"text": "\tSUBROUTINE PSIZE\r\n .(ALPHA,POWER,P0,P1,R,PHI,ALT,resultN,resultERR)\r\n!MS$ATTRIBUTES REFERENCE :: resultN\r\n!MS$ATTRIBUTES REFERENCE :: resultERR\r\n\tIMPLICIT NONE\r\n\tREAL ALPHA,POWER,P0,P1,R,PHI\r\n\tINTEGER ALT,resultERR\r\n\tREAL resultN\r\nC\r\nC-Description-----------------------------------------------------------\r\nC\r\nC Function:\r\nC\tSample size calculations for paired prospective studies with\r\nC\tdichotomous outcomes.\r\nC\r\nC Input (provided by user):\r\nC\tALPHA\tType I error probability for a two sided test\r\nC\tPOWER\tThe desired statistical power\r\nC\tP0\t\tEvent rate among controls\r\nC\tP1\t\tEvent rate among experimental subjects\r\nC\tR=P1/P0\tRelative risk of failure for experimental subjects\r\nC\t\t\trelative to controls\r\nC\tPHI\t\tcorrelation coefficient for failure between paired subjects\r\nC\tALT\t=1 \tif input requires P0 and P1\r\nC\t\t=2 \tif input requires P0 and R\r\nC\r\nC Output:\r\nC\tN\t\tNumber of pairs of subjects needed to detect a true\r\nC\t\t\trelative risk R with power POWER and type I error\r\nC\t\t\tprobability ALPHA\r\nC\tERR\t\t=1 if disclaimer is necessary\r\nC\t\t\t=0 otherwise\r\nC\r\nC Notes:\r\nC .\tThis routine was written by Dale Plummer.\r\nC\t\tDesigned by William Dupont.\r\nC .\tReference:\r\nC\t Schlesselman, JJ: \"Case-Control Studies: Design, Conduct,\r\nC\t Analysis\", New York: Oxford U. Press 1982\r\nC\tSee also:\r\nC\t Dupont, WD: \"Power Calculations for Matched Case-Control\r\nC\t Studies\", Biometrics, 1988; 44:1157-1168\r\nC\r\nC-Declarations----------------------------------------------------------\r\nC\r\nC\r\nC Functions\r\nC\r\n\tREAL ZCRVALUE\r\nC\r\nC Locals\r\nC\r\n\tREAL BETA,ZALPHA,Q1,Q0,P10,P01,PA,QA,ZBETA,XP1\r\nC\r\nC-Code------------------------------------------------------------------\r\nC\r\n\tBETA=1.-POWER\r\nC\r\nC If alternative hypothesis is expressed as relative risk then\r\nC calculate second event rate.\r\nC Copy P1 to local storage.\r\nC\r\n\tIF (ALT.EQ.2) THEN\r\n\t\tXP1=R*P0\r\n\tELSE\r\n\t\tXP1=P1\r\n\tEND IF\r\nC\r\nC Solve for samplesize.\r\nC\r\n\tZALPHA=ZCRVALUE(ALPHA/2.)\r\n\tZBETA=ZCRVALUE(BETA)\r\n\tQ1=1.-XP1\r\n\tQ0=1.-P0\r\nC\r\nC If XP1*Q1*P0*Q0 is less than zero then the calculations below will\r\nC fail when argument to SQRT is negative. In this case output\r\nC failure value of -901.\r\nC\r\n\tIF (XP1*Q1*P0*Q0.LT.0) THEN\r\n\t resultN=-901\r\n\t\tRETURN\r\n\tENDIF\r\n\r\n\tP10=XP1*Q0 - PHI*SQRT(XP1*Q1*P0*Q0)\r\n\tP01=Q1*P0 - PHI*SQRT(XP1*Q1*P0*Q0)\r\n\tPA=P10/(P01+P10)\r\n\tQA=1.-PA\r\nC\r\nC If PA*QA is less than zero then the resultN calculation will\r\nC fail when argument to SQRT is negative. In this case output\r\nC failure value of -902.\r\nC\r\n\tIF (PA*QA.LT.0) THEN\r\n\t resultN=-902\r\n\t\tRETURN\r\n\tENDIF\r\nC\r\nC Calculate the sample size\r\nC\r\nC\tresultN=NINT((ZALPHA*0.5+ZBETA*SQRT(PA*QA))**2 /\r\nC . ((PA-0.5)**2 * (P01+P10)))\r\n\tresultN=(ZALPHA*0.5+ZBETA*SQRT(PA*QA))**2 /\r\n . ((PA-0.5)**2 * (P01+P10))\r\nC\r\nC If conditions warrent then output the disclaimer.\r\nC\r\nc\tIF (2.*(0.5/SQRT(PA*QA))*ZALPHA+ZBETA .LE. 3.1) THEN\r\nc\t\tresultERR=1\r\nc\tELSE\r\n\t\tresultERR=0\r\nc\tEND IF\r\nC\r\nC Done.\r\nC\r\n\tRETURN\r\n\tEND\r\n", "meta": {"hexsha": "935bc7cc706f373df887d29fa4ac812323c664d0", "size": 2980, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "misc/old_ps/ps-development-version/psDll/psize.for", "max_stars_repo_name": "vubiostat/ps", "max_stars_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2017-12-29T14:19:14.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-06T15:08:46.000Z", "max_issues_repo_path": "misc/old_ps/ps-development-version/psDll/psize.for", "max_issues_repo_name": "vubiostat/ps", "max_issues_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2020-04-30T16:57:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-07T00:26:02.000Z", "max_forks_repo_path": "misc/old_ps/ps-development-version/psDll/psize.for", "max_forks_repo_name": "vubiostat/ps", "max_forks_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-07T20:11:54.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-11T19:18:59.000Z", "avg_line_length": 25.2542372881, "max_line_length": 73, "alphanum_fraction": 0.6419463087, "num_tokens": 1005, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582554941719, "lm_q2_score": 0.7122321720225278, "lm_q1q2_score": 0.6627023042869061}} {"text": "SUBROUTINE p89(input_file,output_file) \n!-------------------------------------------------------------------------\n! Program 8.9 Plane analysis of the diffusion-convection equation\n! using 4-node rectangular quadrilaterals. Implicit time\n! integration using the \"theta\" method.\n! Self-adjoint transformation.\n!-------------------------------------------------------------------------\n USE main\n USE geom\n IMPLICIT NONE\n CHARACTER(len=60),INTENT(IN) :: input_file\n CHARACTER(len=60),INTENT(OUT) :: output_file \n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\n INTEGER::i,iel,j,nci,ndim=2,nels,neq,nip=4,nlen,nn,nod=4,npri,np_types, &\n nres,nstep,ntime,nxe,nye\n REAL(iwp)::det,dtim,d6=6.0_iwp,d12=12.0_iwp,f1,f2,pt25=0.25_iwp,theta, &\n time,two=2.0_iwp,ux,uy,zero=0.0_iwp \n CHARACTER(LEN=15)::argv,element='quadrilateral'\n!-----------------------dynamic arrays------------------------------------\n INTEGER,ALLOCATABLE::etype(:),g_num(:,:),num(:),kdiag(:)\n REAL(iwp),ALLOCATABLE::ans(:),bp(:),coord(:,:),der(:,:),deriv(:,:), &\n fun(:),g_coord(:,:),jac(:,:),kay(:,:),kc(:,:),kv(:),loads(:),ntn(:,:), &\n mm(:,:),points(:,:),prop(:,:),weights(:),x_coords(:),y_coords(:)\n!-------------------------input and initialisation------------------------\n \n OPEN(10,FILE=input_file) \n OPEN(11,FILE=output_file)\n READ(10,*)nxe,nye,np_types \n CALL mesh_size(element,nod,nels,nn,nxe,nye)\n neq=nn\n ALLOCATE(points(nip,ndim),weights(nip),kay(ndim,ndim),coord(nod,ndim), &\n fun(nod),jac(ndim,ndim),g_coord(ndim,nn),der(ndim,nod),deriv(ndim,nod),&\n mm(nod,nod),g_num(nod,nels),kc(nod,nod),ntn(nod,nod),num(nod), &\n prop(ndim,np_types),x_coords(nxe+1),y_coords(nye+1),etype(nels), &\n kdiag(neq),loads(0:neq),ans(0:neq))\n READ(10,*)prop\n etype=1\n if(np_types>1)read(10,*)etype\n READ(10,*)x_coords,y_coords \n READ(10,*)dtim,nstep,theta,npri,nres,ntime,ux,uy,nci\n kdiag=0\n!-----------------------loop the elements to find global arrays sizes-----\n elements_1: DO iel=1,nels\n CALL geom_rect(element,iel,x_coords,y_coords,coord,num,'x')\n g_num(:,iel)=num\n g_coord(:,num)=TRANSPOSE(coord)\n CALL fkdiag(kdiag,num)\n END DO elements_1\n CALL mesh(g_coord,g_num,argv,nlen,12) \n DO i=2,neq\n kdiag(i)=kdiag(i)+kdiag(i-1)\n END DO \n ALLOCATE(kv(kdiag(neq)),bp(kdiag(neq)))\n WRITE(11,'(2(a,i5),/)') &\n \" There are\",neq,\" equations and the skyline storage is\",kdiag(neq)\n CALL sample(element,points,weights)\n kv=zero\n bp=zero\n!-----------------------global conductivity and \"mass\" matrix assembly----\n elements_2: DO iel=1,nels\n kay=zero\n DO i=1,ndim\n kay(i,i)=prop(i,etype(iel))\n END DO\n num=g_num(:,iel)\n coord=TRANSPOSE(g_coord(:,num))\n kc=zero\n mm=zero\n gauss_pts: DO i=1,nip\n CALL shape_der(der,points,i)\n CALL shape_fun(fun,points,i)\n jac=MATMUL(der,coord)\n det=determinant(jac)\n CALL invert(jac)\n deriv=MATMUL(jac,der)\n kc=kc+MATMUL(MATMUL(TRANSPOSE(deriv),kay),deriv)*det*weights(i)\n CALL cross_product(fun,fun,ntn)\n mm=mm+ntn*det*weights(i)\n END DO gauss_pts\n kc=kc+mm*(ux*ux/kay(1,1)+uy*uy/kay(2,2))*pt25\n mm=mm/(theta*dtim)\n!-----------------------derivative boundary conditions--------------------\n IF(iel==1)THEN\n det=x_coords(2)-x_coords(1)\n kc(2,2)=kc(2,2)+uy*det/d6\n kc(2,3)=kc(2,3)+uy*det/d12\n kc(3,2)=kc(3,2)+uy*det/d12\n kc(3,3)=kc(3,3)+uy*det/d6\n ELSE IF(iel==nels)THEN\n det=x_coords(2)-x_coords(1)\n kc(1,1)=kc(1,1)+uy*det/d6\n kc(1,4)=kc(1,4)+uy*det/d12\n kc(4,1)=kc(4,1)+uy*det/d12\n kc(4,4)=kc(4,4)+uy*det/d6\n END IF\n CALL fsparv(kv,kc,num,kdiag)\n CALL fsparv(bp,mm,num,kdiag)\n END DO elements_2\n f1=uy*det/(two*theta)\n f2=f1\n bp=bp+kv\n kv=bp-kv/theta \n!-----------------------factorise equations-------------------------------\n CALL sparin(bp,kdiag)\n loads=zero \n!-----------------------time stepping loop--------------------------------\n WRITE(11,'(a,i3,a)')\" Time Concentration (node\",nres,\")\"\n WRITE(11,'(2e12.4)')0.0,loads(nres)\n timesteps: DO j=1,nstep\n time=j*dtim\n CALL linmul_sky(kv,loads,ans,kdiag)\n ans(neq)=ans(neq)+f1\n ans(neq-1)=ans(neq-1)+f2\n CALL spabac(bp,ans,kdiag)\n loads=ans\n IF(nod==4.AND.j==ntime)CALL contour(loads,g_coord,g_num,nci,argv,nlen,13)\n IF(j/npri*npri==j)WRITE(11,'(2e12.4)') &\n time,loads(nres)*exp(-ux*g_coord(1,nres)/two/kay(1,1))* &\n exp(-uy*g_coord(2,nres)/two/kay(2,2))\n END DO timesteps\n\nEND SUBROUTINE p89\n", "meta": {"hexsha": "9e7e9368bea777043b8a18a8000b9de16f579f7c", "size": 4586, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "subordinates/Transient-Problems/p89.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": "subordinates/Transient-Problems/p89.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": "subordinates/Transient-Problems/p89.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": 37.2845528455, "max_line_length": 76, "alphanum_fraction": 0.5715220235, "num_tokens": 1567, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037343628703, "lm_q2_score": 0.7154240079185319, "lm_q1q2_score": 0.6626999301877877}} {"text": " subroutine ktable\n!------------------------------------------------------------\n! -\n! This subroutine builds a table for the various values -\n! of the kernel, the gradient of the kernel, the mass -\n! fraction and the potential energy. -\n! The entry is v**2. -\n! (updated to F90 DHF 17/10/2009 -\n!------------------------------------------------------------\n\n\t use sphkerneldata\n\n\t real :: sum, v, v3, v4, v5, v6\n\t real, parameter :: pi = 3.141596253d0\n\t integer :: i1\n\t \n\t \n!\tAllocate arrays\n\n\tallocate(wij(itable))\n\tallocate(grwij(itable))\n\tallocate(fmass(itable))\n\tallocate(fpoten(itable))\n\tallocate(dphidh(itable))\n\t \n!\n!--Maximum interaction length and step size\n!\n\t radkernel = 2.0\n part1kernel = 1.0\n part2kernel = 2.0\n v2max = radkernel*radkernel\n dvtable = v2max/itable\n i1 = part1kernel/dvtable +1\n!\n!--Build tables\n!\n! a) v less than 1\n!\n do i = 1, i1\n\t \n v2 = i*dvtable\n\t\t v = SQRT(v2)\n v3 = v*v2\n v4 = v*v3\n v5 = v*v4\n v6 = v*v5\n\t\t \n sum = 1. - 1.5*v2 + 0.75*v3\n wij(i) = sum\n sum = -3.*v + 2.25*v2\n grwij(i) = sum\n sum = 1.3333333333*v3 - 1.2*v5 + 0.5*v6\n fmass(i) = sum\n sum = 0.66666666666*v2 - 0.3*v4 + 0.1*v5 - 1.4\n fpoten(i) = sum\n sum = -1.4 + 2.*v2 - 1.5*v4 + 0.6*v5\n dphidh(i) = sum\n enddo\n\t \n\t\n!\n! b) v greater than 1\n!\n do i = i1 + 1, itable\n v2 = i*dvtable\n v = SQRT(v2)\n v3 = v*v2\n v4 = v*v3\n v5 = v*v4\n v6 = v*v5\n dif2 = 2. - v\n sum = 0.25*dif2*dif2*dif2\n wij(i) = sum\n sum = -0.75*v2 + 3*v - 3.\n grwij(i) = sum\n sum = -0.16666666666*v6 + 1.2*v5 - 3.*v4 + 2.66666666666*v3 - &\n 0.0666666666666\n fmass(i) = sum\n sum = -0.033333333333*v5 + 0.3*v4 - v3 + 1.3333333333*v2 - 1.6\n fpoten(i) = sum\n sum = -1.6 + 4.*v2 - 4.*v3 + 1.5*v4 - 0.2*v5\n dphidh(i) = sum\n enddo\n\t \n!\n!--Normalisation constant\n!\n cnormk = 1.0/pi\n selfnormkernel = 1.0\n part1potenkernel = 1.0/15.0\n part2potenkernel = 0.0\n\t\n return\n\t \n end subroutine ktable\n", "meta": {"hexsha": "40cdf8cb3bc13429912df75bfc19b68aa5fb29b0", "size": 2362, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/sph/ktable.f90", "max_stars_repo_name": "dh4gan/tache", "max_stars_repo_head_hexsha": "51ed037769ecc4fdadc591e3b3619416c79e65b7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-02-27T04:07:15.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-29T20:49:36.000Z", "max_issues_repo_path": "src/sph/ktable.f90", "max_issues_repo_name": "dh4gan/tache", "max_issues_repo_head_hexsha": "51ed037769ecc4fdadc591e3b3619416c79e65b7", "max_issues_repo_licenses": ["MIT"], "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/sph/ktable.f90", "max_forks_repo_name": "dh4gan/tache", "max_forks_repo_head_hexsha": "51ed037769ecc4fdadc591e3b3619416c79e65b7", "max_forks_repo_licenses": ["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.3505154639, "max_line_length": 72, "alphanum_fraction": 0.4445385267, "num_tokens": 845, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037302939515, "lm_q2_score": 0.7154240079185319, "lm_q1q2_score": 0.6626999272767856}} {"text": "program Factorial\n implicit none\n integer :: ans\n integer :: n\n integer :: i\n read(*,*) n\n ans=1\n do 1 i=1,n,1\n ans=ans*i\n 1 continue ! 1 is a label\n write(*,*) n,\"! = \",ans\n\nend program Factorial", "meta": {"hexsha": "08c6e5983e7027b9946951b73c0e6f00a27f7b46", "size": 231, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "factorial.f90", "max_stars_repo_name": "vs666/Fortan", "max_stars_repo_head_hexsha": "a8e434e857fefce56b9b47b3b36b9b20ca2d9716", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "factorial.f90", "max_issues_repo_name": "vs666/Fortan", "max_issues_repo_head_hexsha": "a8e434e857fefce56b9b47b3b36b9b20ca2d9716", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "factorial.f90", "max_forks_repo_name": "vs666/Fortan", "max_forks_repo_head_hexsha": "a8e434e857fefce56b9b47b3b36b9b20ca2d9716", "max_forks_repo_licenses": ["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.7692307692, "max_line_length": 30, "alphanum_fraction": 0.5324675325, "num_tokens": 80, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673359709795, "lm_q2_score": 0.815232480373843, "lm_q1q2_score": 0.6626758545184995}} {"text": "module m_array1D\n !! 1D array routines\n !!\n !! See\n !! [[arange]], [[diff]], [[isSorted]], [[repeat]]\n !! for more information.\nuse variableKind, only: r32, r64, i32, i64\nuse m_allocate, only: allocate\nuse m_errors, only: eMsg\nuse m_random, only: rngInteger\nuse m_strings, only: str\nuse m_swap, only: swap\n\nimplicit none\n\nprivate\n\npublic :: arange\ninterface arange\n !! Create a 1D array from start to stop in given increments of 1 or optionally step\n !!\n !! Example Usage\n !!```fortran\n !!program arangeTest\n !!use variableKind, only: i32,i64,r32,r64\n !!use m_allocatable, only: allocatable\n !!use m_array1D, only: arange\n !!real(r32), allocatable :: a(:)\n !!integer(i32), allocatable :: b(:)\n !!real(r64), allocatable :: c(:)\n !!integer(i64), allocatable :: d(:)\n !!integer :: N\n !!N = 10000\n !!call allocate(a, N)\n !!call allocate(b, N)\n !!call allocate(c, N)\n !!call allocate(d, N)\n !!\n !!call arange(a, 1, N)\n !!call arange(b, 1, N)\n !!call arange(c, 1, N)\n !!call arange(d, 1, N)\n !!\n !!call deallocate(a)\n !!call deallocate(b)\n !!call deallocate(c)\n !!call deallocate(d)\n !!\n !!end program\n !!```\n module subroutine arange_r1D(res,start,stp,step)\n !! Interfaced with [[arange]]\n real(r32), intent(in) :: start !! Start from here\n real(r32), intent(in) :: stp !! Stop here\n real(r32), optional, intent(in) :: step !! Step size\n real(r32), allocatable, intent(inout) :: res(:)\n end subroutine\n module subroutine arange_d1D(res,start,stp,step)\n !! Interfaced with [[arange]]\n real(r64), intent(in) :: start !! Start from here\n real(r64), intent(in) :: stp !! Stop here\n real(r64), optional, intent(in) :: step !! Step size\n real(r64), allocatable, intent(inout) :: res(:)\n end subroutine\n module subroutine arange_i1D(res,start,stp,step)\n !! Interfaced with [[arange]]\n integer(i32), intent(in) :: start !! Start from here\n integer(i32), intent(in) :: stp !! Stop here\n integer(i32), optional, intent(in) :: step !! Step size\n integer(i32), allocatable, intent(inout) :: res(:)\n end subroutine\n module subroutine arange_id1D(res,start,stp,step)\n !! Interfaced with [[arange]]\n integer(i64), intent(in) :: start !! Start from here\n integer(i64), intent(in) :: stp !! Stop here\n integer(i64), optional, intent(in) :: step !! Step size\n integer(i64), allocatable, intent(inout) :: res(:)\n end subroutine\nend interface\n\npublic :: diff\ninterface diff\n !! Compute the difference along an array\n !!\n !! Example Usage\n !!```fortran\n !!program arangeTest\n !!use variableKind, only: i32,i64,r32,r64\n !!use m_allocatable, only: allocatable\n !!use m_array1D, only: arange, diff\n !!real(r32), allocatable :: a(:)\n !!integer(i32), allocatable :: b(:)\n !!real(r64), allocatable :: c(:)\n !!integer(i64), allocatable :: d(:)\n !!integer :: N\n !!N = 10000\n !!call allocate(a, N)\n !!call allocate(b, N)\n !!call allocate(c, N)\n !!call allocate(d, N)\n !!\n !!call arange(a, 1, N)\n !!call arange(b, 1, N)\n !!call arange(c, 1, N)\n !!call arange(d, 1, N)\n !!\n !!call diff(a, 1, N)\n !!call diff(b, 1, N)\n !!call diff(c, 1, N)\n !!call diff(d, 1, N)\n !!\n !!call deallocate(a)\n !!call deallocate(b)\n !!call deallocate(c)\n !!call deallocate(d)\n !!\n !!end program\n !!```\n module subroutine diff_r1D(this, res)\n !! Interfaced with [[diff]]\n real(r32),intent(in) :: this(:) !! 1D array\n real(r32) :: res(:) !! Difference along array\n end subroutine\n module subroutine diff_d1D(this, res)\n !! Interfaced with [[diff]]\n real(r64),intent(in) :: this(:) !! 1D array\n real(r64) :: res(:) !! Difference along array\n end subroutine\n module subroutine diff_i1D(this, res)\n !! Interfaced with [[diff]]\n integer(i32),intent(in) :: this(:) !! 1D array\n integer(i32) :: res(:) !! Difference along array\n end subroutine\n module subroutine diff_id1D(this, res)\n !! Interfaced with [[diff]]\n integer(i64),intent(in) :: this(:) !! 1D array\n integer(i64) :: res(:) !! Difference along array\n end subroutine\nend interface\n\npublic isSorted\ninterface isSorted\n !! Check that a 1D array is sorted\n !!\n !! Example Usage\n !!```fortran\n !!program arangeTest\n !!use variableKind, only: i32,i64,r32,r64\n !!use m_allocatable, only: allocatable\n !!use m_array1D, only: arange, isSorted\n !!real(r32), allocatable :: a(:)\n !!integer(i32), allocatable :: b(:)\n !!real(r64), allocatable :: c(:)\n !!integer(i64), allocatable :: d(:)\n !!integer :: N\n !!N = 10000\n !!call allocate(a, N)\n !!call allocate(b, N)\n !!call allocate(c, N)\n !!call allocate(d, N)\n !!\n !!call arange(a, 1, N)\n !!call arange(b, 1, N)\n !!call arange(c, 1, N)\n !!call arange(d, 1, N)\n !!\n !!call diff(a, 1, N)\n !!call diff(b, 1, N)\n !!call diff(c, 1, N)\n !!call diff(d, 1, N)\n !!\n !!call deallocate(a)\n !!call deallocate(b)\n !!call deallocate(c)\n !!call deallocate(d)\n !!\n !!end program\n !!```\n\n module function isSorted_r1D(this) result(yes)\n !! Interfaced with [[isSorted]]\n real(r32), intent(in) :: this(:) !! 1D array\n logical :: yes !! isSorted\n end function\n module function isSorted_d1D(this) result(yes)\n !! Interfaced with [[isSorted]]\n real(r64), intent(in) :: this(:) !! 1D array\n logical :: yes !! isSorted\n end function\n module function isSorted_i1D(this) result(yes)\n !! Interfaced with [[isSorted]]\n integer(i32), intent(in) :: this(:) !! 1D array\n logical :: yes !! isSorted\n end function\n module function isSorted_id1D(this) result(yes)\n !! Interfaced with [[isSorted]]\n integer(i64), intent(in) :: this(:) !! 1D array\n logical :: yes !! isSorted\n end function\n module function isSorted_r1Di1D(this, indx) result(yes)\n !! Interfaced with [[isSorted]]\n real(r32), intent(in) :: this(:) !! 1D array\n integer(i32), intent(in) :: indx(:) !! Index into 1D array\n logical :: yes !! isSorted\n end function\n module function isSorted_d1Di1D(this, indx) result(yes)\n !! Interfaced with [[isSorted]]\n real(r64), intent(in) :: this(:) !! 1D array\n integer(i32), intent(in) :: indx(:) !! Index into 1D array\n logical :: yes !! isSorted\n end function\n module function isSorted_i1Di1D(this, indx) result(yes)\n !! Interfaced with [[isSorted]]\n integer(i32), intent(in) :: this(:) !! 1D array\n integer(i32), intent(in) :: indx(:) !! Index into 1D array\n logical :: yes !! isSorted\n end function\n module function isSorted_id1Di1D(this, indx) result(yes)\n !! Interfaced with [[isSorted]]\n integer(i64), intent(in) :: this(:) !! 1D array\n integer(i32), intent(in) :: indx(:) !! Index into 1D array\n logical :: yes !! isSorted\n end function\nend interface\n\n\npublic repeat\ninterface repeat\n !! Repeat each element nRepeat times\n module subroutine repeat_r1D(this, nRepeats, res)\n !! Interfaced with [[repeat]]\n real(r32) :: this(:) !! 1D array\n integer(i32) :: nRepeats !! Number of times each element should be repeated\n real(r32), allocatable :: res(:)\n end subroutine\n module subroutine repeat_d1D(this, nRepeats, res)\n !! Interfaced with [[repeat]]\n real(r64) :: this(:) !! 1D array\n integer(i32) :: nRepeats !! Number of times each element should be repeated\n real(r64), allocatable :: res(:)\n end subroutine\n module subroutine repeat_i1D(this, nRepeats, res)\n !! Interfaced with [[repeat]]\n integer(i32) :: this(:) !! 1D array\n integer(i32) :: nRepeats !! Number of times each element should be repeated\n integer(i32), allocatable :: res(:)\n end subroutine\n module subroutine repeat_id1D(this, nRepeats, res)\n !! Interfaced with [[repeat]]\n integer(i64) :: this(:) !! 1D array\n integer(i32) :: nRepeats !! Number of times each element should be repeated\n integer(i64), allocatable :: res(:)\n end subroutine\nend interface\n\npublic shuffle\n\ninterface shuffle\n !! Perform Knuth shuffling on an array\n !====================================================================!\n module subroutine shuffle_r1D(this)\n !! Interfaced with [[shuffle]]\n !====================================================================!\n !! Interfaced with shuffle()\n real(r32), intent(inout) :: this(:) !! 1D array\n end subroutine\n !====================================================================!\n !====================================================================!\n module subroutine shuffle_d1D(this)\n !! Interfaced with [[shuffle]]\n !====================================================================!\n !! Interfaced with shuffle()\n real(r64), intent(inout) :: this(:) !! 1D array\n end subroutine\n !====================================================================!\n !====================================================================!\n module subroutine shuffle_i1D(this)\n !! Interfaced with [[shuffle]]\n !====================================================================!\n !! Interfaced with shuffle()\n integer(i32), intent(inout) :: this(:) !! 1D array\n end subroutine\n !====================================================================!\n !====================================================================!\n module subroutine shuffle_id1D(this)\n !! Interfaced with [[shuffle]]\n !====================================================================!\n !! Interfaced with shuffle()\n integer(i64), intent(inout) :: this(:) !! 1D array\n end subroutine\n !====================================================================!\nend interface\n\n! interface isConstant\n! module procedure :: isConstant_DV\n! end interface\n! private :: isConstant_DV\n!\n! interface isConstantIncrement\n! module procedure :: isConstantIncrement_DV\n! end interface\n! private :: isConstantIncrement_DV\n!\n! interface isInside\n! module procedure :: isInside1D_I1,isInside1D_D1\n! end interface\n!\n! interface getBin\n! module procedure :: getBin1D_I1,getBin1D_D1\n! end interface\n!\n! interface scale\n! module procedure :: scaleVector\n! end interface\n!\n! interface deintegerize\n! module procedure :: deintegerizeVector\n! end interface\n! private :: deintegerizeVector\n!\n! private :: isInside1D_I1,isInside1D_D1\n! private :: getBin1D_I1,getBin1D_D1\n!\n! interface mapExponential\n! module procedure :: mapExponential_1D\n! end interface\n! private :: mapExponential_1D\n!\n! interface unitize\n! module procedure :: unitize_1D\n! end interface\n! private :: unitize_1D\nend module\n", "meta": {"hexsha": "06152abfdb2790c83ccac358fb2de2e6cf1cbc99", "size": 10478, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "docs/src/m_array1D.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/arrays/m_array1D.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": "docs/src/m_array1D.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": 31.371257485, "max_line_length": 85, "alphanum_fraction": 0.5898072151, "num_tokens": 3020, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.8354835330070838, "lm_q1q2_score": 0.6626269621442455}} {"text": "module quadglobal\nuse mpmodule\nimplicit none\ninteger ndebug, nerror, nquadl, ndigits1, ndigits2, nepsilon1, nepsilon2, &\n nwords1, nwords2\nend module\n\nsubroutine f_main\n\n! David H. Bailey 2009-05-13\n! This is the ARPREC Fortran-90 version.\n\n! This work was supported by the Director, Office of Science, Division\n! of Mathematical, Information, and Computational Sciences of the\n! U.S. Department of Energy under contract number DE-AC03-76SF00098.\n\n! This program demonstrates the quadrature routine 'quadgs', which employs\n! Gaussian quadrature. The function quadgs is suitable to integrate\n! a function that is continuous, infinitely differentiable and integrable on a\n! finite open interval. It can also be used for certain integrals on infinite\n! intervals, by making a suitable change of variable -- see below. While\n! this routine is usually more efficient than quaderf or quadts for functions\n! that are regular on a closed interval, it is not very effective for \n! functions with a singularity at one or both of the endpoints.\n\n! The function(s) to be integrated is(are) defined in external function\n! subprogram(s) -- see the sample function subprograms below. The name(s) of\n! the function subprogram(s) must be included in appropriate type and external\n! statements in the main program.\n\n! Note that an integral of a function on an infinite interval can be\n! converted to an integral on a finite interval by means of a suitable\n! change of variable. Example (here the notation \"inf\" means infinity):\n\n! Int_0^inf f(t) dt = Int_0^1 f(t) dt + Int_1^inf f(t) dt\n! = Int_0^1 f(t) dt + Int_0^1 f(1/t)/t^2 dt\n\n! See examples below.\n\n! Inputs set in parameter statement below:\n! kdebug Debug level setting. Default = 2.\n! ndp1 Primary working precision, in digits; may not exceed mpipl in \n! mp_mod.f.\n! ndp2 Secondary working precision, in digits; here ndp2 = ndp1.\n! neps1 Log10 of the primary tolerance. By default, neps1 = - ndp1.\n! neps2 Log10 of the secondary tolerance. By default, neps2 = - ndp2.\n! nq1 Max number of phases in quadrature routine; adding 1 increases\n! (possibly doubles) the number of accurate digits in the result,\n! but also roughly doubles the run time. nq1 must be at least 2.\n! nq2 Space parameter for wk and xk arrays in the calling program. By\n! default it is set to 12 * 2^nq1. Increase nq2 if directed by a \n! message produced in initqgs. Note that the dimension of the\n! wk and xk arrays starts with -1, so the length of these arrays is\n! (nq2+2) * (mpwds+5) eight-byte words.\n\nuse mpmodule\nuse quadglobal\nimplicit none\nsave\ninteger kdebug, ndp1, ndp2, neps1, neps2, nq1, nq2, n1\nparameter (kdebug = 2, ndp1 = 400, ndp2 = ndp1, neps1 = -ndp1, neps2 = -ndp2, &\n nq1 = 9, nq2 = 12 * 2 ** nq1)\ndouble precision d1, second, tm0, tm1\ntype (mp_real) quadgs, fun01, fun02, fun03, fun04, fun05, fun06, fun07, &\n fun08, fun09, fun10, fun11, fun12, fun13, fun14, fun15a, fun15b, &\n t1, t2, t3, t4, wk(-1:nq2), xk(-1:nq2), x1, x2\nexternal quadgs, fun01, fun02, fun03, fun04, fun05, fun06, fun07, fun08, &\n fun09, fun10, fun11, fun12, fun13, fun14, fun15a, fun15b, second\n\ncall mpinit (ndp1)\ncall mpsetprec (ndp1)\ncall mpgetprecwords (nwords1)\ncall mpsetprec (ndp2)\ncall mpgetprecwords (nwords2)\ncall mpsetprecwords (nwords1)\nndigits1 = ndp1\nndigits2 = ndp2\nnepsilon1 = neps1\nnepsilon2 = neps2\nmpoud = ndp1\nndebug = kdebug\nnerror = 0\nnquadl = nq1\nwrite (6, 1) nquadl, ndigits1, ndigits2, nepsilon1, nepsilon2\n1 format ('Quadgs test: Quadlevel =',i6/'Digits1 =',i6,' Digits2 =',i6, &\n ' Epsilon1 =',i6,' Epsilon2 =',i6)\n\n! Initialize quadrature tables wk and xk (weights and abscissas).\n\ntm0 = second ()\ncall initqgs (nq1, nq2, wk, xk)\ntm1 = second ()\nif (nerror > 0) stop\nwrite (6, 2) tm1 - tm0\n2 format ('Quadrature initialization completed: cpu time =',f12.4)\n\n! Begin quadrature tests.\n\nwrite (6, 11)\n11 format (/'Continuous functions on finite itervals:'//&\n 'Problem 1: Int_0^1 t*log(1+t) dt = 1/4')\nx1 = 0.d0\nx2 = 1.d0\ntm0 = second ()\nt1 = quadgs (fun01, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\n3 format ('Quadrature completed: CPU time =',f12.6/'Result =')\ncall mpwrite (6, t1)\nt2 = 0.25d0\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n4 format ('Actual error =',f10.6,'x10^',i5)\n\nwrite (6, 12)\n12 format (/'Problem 2: Int_0^1 t^2*arctan(t) dt = (pi - 2 + 2*log(2))/12')\nx1 = 0.d0\nx2 = 1.d0\ntm0 = second ()\nt1 = quadgs (fun02, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, t1)\nt2 = (mppic - 2.d0 + 2.d0 * mpl02) / 12.d0\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 13)\n13 format (/'Problem 3: Int_0^(pi/2) e^t*cos(t) dt = 1/2*(e^(pi/2) - 1)')\nx1 = 0.d0\nx2 = 0.5d0 * mppic\ntm0 = second ()\nt1 = quadgs (fun03, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, t1)\nt2 = 0.5d0 * (exp (0.5d0 * mppic) - 1.d0)\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 14)\n14 format (/ &\n 'Problem 4: Int_0^1 arctan(sqrt(2+t^2))/((1+t^2)sqrt(2+t^2)) dt = 5*Pi^2/96')\nx1 = 0.d0\nx2 = 1.d0\ntm0 = second ()\nt1 = quadgs (fun04, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, t1)\nt2 = 5.d0 * mppic**2 / 96.d0\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 15)\n15 format (/&\n 'Continuous functions on finite itervals, but non-diff at an endpoint'// &\n 'Problem 5: Int_0^1 sqrt(t)*log(t) dt = -4/9')\nx1 = 0.d0\nx2 = 1.d0\ntm0 = second ()\nt1 = quadgs (fun05, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, t1)\nt2 = mpreal (-4.d0) / 9.d0\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 16)\n16 format (/'Problem 6: Int_0^1 sqrt(1-t^2) dt = pi/4')\nx1 = 0.d0\nx2 = 1.d0\ntm0 = second ()\nt1 = quadgs (fun06, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, t1)\nt2 = 0.25d0 * mppic\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 17)\n17 format (/&\n 'Functions on finite intervals with integrable singularity at an endpoint.'//&\n 'Problem 7: Int_0^1 sqrt(t)/sqrt(1-t^2) dt = 2*sqrt(pi)*gamma(3/4)/gamma(1/4)')\nx1 = 0.d0\nx2 = 1.d0\ntm0 = second ()\nt1 = quadgs (fun07, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, t1)\nt2 = 2.d0 * sqrt (mppic) * gamma (mpreal (0.75d0)) / gamma (mpreal (0.25d0))\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 18)\n18 format (/'Problem 8: Int_0^1 log(t)^2 dt = 2')\nx1 = 0.d0\nx2 = 1.d0\ntm0 = second ()\nt1 = quadgs (fun08, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, t1)\nt2 = 2.d0\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 19)\n19 format (/'Problem 9: Int_0^(pi/2) log(cos(t)) dt = -pi*log(2)/2')\nx1 = 0.d0\nx2 = 0.5d0 * mppic\ntm0 = second ()\nt1 = quadgs (fun09, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, t1)\nt2 = -0.5d0 * mppic * mpl02\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 20)\n20 format (/'Problem 10: Int_0^(pi/2) sqrt(tan(t)) dt = pi*sqrt(2)/2')\nx1 = 0.d0\nx2 = 0.5d0 * mppic\ntm0 = second ()\nt1 = quadgs (fun10, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, t1)\nt2 = 0.5d0 * mppic * sqrt (mpreal (2.d0))\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 21)\n21 format (/&\n 'Functions on an infinite interval (requiring a two-step solution'//&\n 'Problem 11: Int_0^inf 1/(1+t^2) dt = pi/2')\nx1 = 0.d0\nx2 = 1.d0\ntm0 = second ()\nt1 = quadgs (fun11, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, t1)\nt2 = 0.5d0 * mppic\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 22)\n22 format (/'Problem 12: Int_0^inf e^(-t)/sqrt(t) dt = sqrt(pi)')\nx1 = 0.d0\nx2 = 1.d0\ntm0 = second ()\nt1 = quadgs (fun12, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, t1)\nt2 = sqrt (mppic)\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 23)\n23 format (/'Problem 13: Int_0^inf e^(-t^2/2) dt = sqrt(pi/2)')\nx1 = 0.d0\nx2 = 1.d0\ntm0 = second ()\nt1 = quadgs (fun13, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, t1)\nt2 = sqrt (0.5d0 * mppic)\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 24)\n24 format (/&\n 'Oscillatory functions on an infinite interval.'//&\n 'Problem 14: Int_0^inf e^(-t)*cos(t) dt = 1/2')\nx1 = 0.d0\nx2 = 1.d0\ntm0 = second ()\nt1 = quadgs (fun14, x1, x2, nq1, nq2, wk, xk)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\ncall mpwrite (6, t1)\nt2 = 0.5d0\ncall decmdq (t2 - t1, d1, n1)\nwrite (6, 4) d1, n1\n\nwrite (6, 25)\n25 format (/'Problem 15: Int_0^inf sin(t)/t = pi/2')\nx1 = 0.d0\nx2 = mppic\ntm0 = second ()\nt1 = quadgs (fun15a, x1, x2, nq1, nq2, wk, xk)\nx2 = 1.d0 / mppic\nt2 = quadgs (fun15b, x1, x2, nq1, nq2, wk, xk)\nt3 = t1 + 40320.d0 * t2 - 1.d0 / mppic + 2.d0 / mppic ** 3 &\n - 24.d0 / mppic ** 5 + 720.d0 / mppic ** 7\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\nt4 = 0.5d0 * mppic\ncall decmdq (t4 - t3, d1, n1)\nwrite (6, 4) d1, n1\nwrite (6, 26)\n26 format ('Prob 15 error may be 40,000 X higher than estimated error.')\n\nstop\nend\n\nfunction fun01 (t)\n\n! fun01(t) = t * log(1+t)\n\nuse mpmodule\nimplicit none\ntype (mp_real) fun01, t, t1\n\nt1 = t\nfun01 = t1 * log (1.d0 + t1)\nreturn\nend\n\nfunction fun02 (t)\n\n! fun02(t) = t^2 * arctan(t)\n\nuse mpmodule\nimplicit none\ntype (mp_real) fun02, t, t1\n\nt1 = t\nfun02 = t1 ** 2 * atan (t1)\nreturn\nend\n\nfunction fun03 (t)\n\n! fun03(t) = e^t * cos(t)\n\nuse mpmodule\nimplicit none\ntype (mp_real) fun03, t, t1\n\nt1 = t\nfun03 = exp(t1) * cos(t1)\nreturn\nend\n\nfunction fun04 (t)\n\n! fun04(t) = arctan(sqrt(2+t^2))/((1+t^2)sqrt(2+t^2))\n\nuse mpmodule\nimplicit none\ntype (mp_real) fun04, t, t1, t2\n\nt1 = t\nt2 = sqrt (2.d0 + t1**2)\nfun04 = atan(t2) / ((1.d0 + t1**2) * t2)\nreturn\nend\n\nfunction fun05 (t)\n\n! fun05(t) = sqrt(t)*log(t)\n\nuse mpmodule\nimplicit none\ntype (mp_real) fun05, t, t1\n\nt1 = t\nif (t1 >= 0.d0) then\n fun05 = sqrt (t1) * log (t1)\nelse\n fun05 = 0.d0\nendif\nreturn\nend\n\nfunction fun06 (t)\n\n! fun06(t) = sqrt(1-t^2)\n\nuse mpmodule\nimplicit none\ntype (mp_real) fun06, t, t1\n\nt1 = t\nif (t1 <= 1.d0) then\n fun06 = sqrt (1.d0 - t1**2)\nelse\n fun06 = 0.d0\nendif\nreturn\nend\n\nfunction fun07 (t)\n\n! fun07(t) = sqrt (t) / sqrt(1-t^2)\n\nuse mpmodule\nimplicit none\ntype (mp_real) fun07, t, t1, t2\n\nt1 = t\nt2 = 1.d0 - t\nif (t1 >= 0.d0 .and. t2 > 0.d0) then\n fun07 = sqrt (t1) / sqrt (t2 * (1.d0 + t1))\nelse\n fun07 = 0.d0\nendif\nreturn\nend\n\nfunction fun08 (t)\n\n! fun08(t) = log(t)^2\n\nuse mpmodule\nimplicit none\ntype (mp_real) fun08, t, t1\n\nt1 = t\nif (t1 > 0.d0) then\n fun08 = log (t1) ** 2\nelse\n fun08 = 0.d0\nendif\nreturn\nend\n\nfunction fun09 (t)\n\n! fun09(t) = log (cos (t))\n\nuse mpmodule\nimplicit none\ntype (mp_real) fun09, t, t1, t2\n\nt1 = t\nif (t1 < 0.25d0 * mppic) then\n fun09 = log (cos (t1))\nelse\n t2 = 0.5d0 * mppic - t\n if (t2 > 0.d0) then\n fun09 = log (sin (t2))\n else\n fun09 = 0.d0\n endif\nendif\nreturn\nend\n\nfunction fun10 (t)\n\n! fun10(t) = sqrt(tan(t))\n\nuse mpmodule\nimplicit none\ntype (mp_real) fun10, t, t1, t2\n\nt1 = t\nif (t1 < 0.25d0 * mppic) then\n fun10 = sqrt (tan (t1))\nelse\n t2 = 0.5d0 * mppic - t\n if (t2 > 0.d0) then\n fun10 = 1.d0 / sqrt (tan (t2))\n else\n fun10 = 0.d0\n endif\nendif\nreturn\nend\n\nfunction fun11 (t)\n\n! fun11(t) = 1/(u^2(1+(1/u-1)^2)) = 1/(1 - 2*u + u^2)\n\nuse mpmodule\nimplicit none\ntype (mp_real) fun11, t, t1\n\nt1 = t\nfun11 = 1.d0 / (1.d0 - 2.d0 * t1 + 2.d0 * t1 ** 2)\nreturn\nend\n\nfunction fun12 (t)\n\n! fun12(t) = e^(-(1/t-1)) / sqrt(t^3 - t^4)\n\nuse mpmodule\nimplicit none\ntype (mp_real) fun12, t, t1, t2\n\nt1 = t\nt2 = 1.d0 - t\nif (t1 > 0.d0 .and. t2 > 0.d0) then\n fun12 = exp (1.d0 - 1.d0/t1) / sqrt (t1 ** 3 * t2)\nelse\n fun12 = 0.d0\nendif\nreturn\nend\n\nfunction fun13 (t)\n\n! fun13(t) = e^(-(1/t-1)^2/2) / t^2\n\nuse mpmodule\nuse quadglobal\nimplicit none\ntype (mp_real) fun13, t, t1, t2\n\nt1 = t\nif (t1 > 0.25d0 / sqrt (dble (ndigits1))) then\n t2 = 1.d0 / t1 - 1.d0\n fun13 = exp (-0.5d0 * t2 ** 2) / t1 ** 2\nelse\n fun13 = 0.d0\nendif\nreturn\nend\n\nfunction fun14 (t)\n\n! fun14(t) = e^(-(1/t-1)) * cos (1/t-1) / t^2\n\nuse mpmodule\nuse quadglobal\nimplicit none\ntype (mp_real) fun14, t, t1, t2\n\nt1 = t\nif (t1 > 0.25d0 / ndigits1) then\n t2 = 1.d0 / t1 - 1.d0\n fun14 = exp (-t2) * cos (t2) / t1 ** 2\nelse\n fun14 = 0.d0\nendif\nreturn\nend\n\nfunction fun15a (t)\n\n! fun15a(t) = sin(t)/t\n\nuse mpmodule\nimplicit none\ntype (mp_real) fun15a, t1\ntype (mp_real) t\n\nt1 = t\nfun15a = sin (t1) / t1\nreturn\nend\n\nfunction fun15b (t)\n\n! fun15b(t) = t^7 * sin(1/t)\n\nuse mpmodule\nuse quadglobal\nimplicit none\ntype (mp_real) fun15b, t1\ntype (mp_real) t\nreal*8 dplog10q\nexternal dplog10q\n\nt1 = t\nif (-dplog10q (t1) < ndigits1) then\n fun15b = t1**7 * sin (1.d0 / t1)\nelse\n fun15b = 0.d0\nendif\nreturn\nend\n\nsubroutine initqgs (nq1, nq2, wk, xk)\n\n! This subroutine initializes the quadrature arays xk and wk for Gaussian\n! quadrature. It employs a Newton iteration scheme with a dynamic precision\n! level. The argument nq2, which is the space allocated for wk and xk in\n! the calling program, should be at least 8 * 2^nq1 + 100, although a higher\n! value may be required, depending on precision level. Monitor the space\n! figure given in the message below during initialization to be certain.\n\n! David H Bailey 2004-08-14\n\nuse mpmodule\nuse quadglobal\nimplicit none\ninteger i, ierror, ik0, is, j, j1, k, n, nq1, nq2, nwp\ndouble precision pi\nparameter (pi = 3.141592653589793238d0)\ntype (mp_real) eps, r, t1, t2, t3, t4, t5, wk(-1:nq2), xk(-1:nq2)\nparameter (ik0 = 100)\n\nif (ndebug >= 1) then\n write (6, 1)\n1 format ('initqgs: Gaussian quadrature initialization')\nendif\n\neps = 2.d0 ** (-96)\nwk(-1) = dble (nq1)\nwk(0) = 0.d0\nxk(0) = 0.d0\nwk(1) = dble (nq1)\nxk(1) = dble (ik0)\ni = ik0\n\ndo j = 2, ik0\n wk(j) = 0.d0\n xk(j) = 0.d0\nenddo\n\ndo k = 1, nq1\n if (ndebug >= 2) write (6, *) k, i, nq2\n n = 3 * 2 ** (k + 1)\n\n do j = 1, n / 2\n\n! Compute a double precision estimate of the root.\n\n is = 0\n nwp = 3\n call mpsetprecwords (nwp)\n r = cos ((pi * (j - 0.25d0)) / (n + 0.5d0))\n\n! Compute the j-th root of the n-degree Legendre polynomial using Newton's\n! iteration.\n\n100 continue\n\n t1 = 1.d0\n t2 = 0.d0\n\n do j1 = 1, n\n t3 = t2\n t2 = t1\n t1 = ((2 * j1 - 1) * r * t2 - (j1 - 1) * t3) / j1\n enddo\n\n t4 = n * (r * t1 - t2) / (r ** 2 - 1.d0)\n t5 = r\n r = r - t1 / t4\n\n! Once convergence is achieved at nwp = 3, then start doubling (almost) the\n! working precision level at each iteration until full precision is reached.\n\n if (nwp == 3) then\n if (abs (r - t5) > eps) goto 100\n nwp = min (2 * nwp - 1, nwords1)\n call mpsetprecwords (nwp)\n goto 100\n elseif (nwp < nwords1) then\n nwp = min (2 * nwp - 1, nwords1)\n call mpsetprecwords (nwp)\n goto 100\n endif\n\n i = i + 1\n if (i > nq2) goto 110\n xk(i) = r\n t4 = n * (r * t1 - t2) / (r ** 2 - 1.d0)\n wk(i) = 2.d0 / ((1.d0 - r ** 2) * t4 ** 2)\n call mpgetpar ('mpier', ierror)\n if (ierror > 0) goto 120\n enddo\n\n xk(k+1) = i\nenddo\n\nxk(-1) = dble (i)\nif (ndebug >= 2) then\n write (6, 2) i\n2 format ('initqerf: Table spaced used =',i8)\nendif\ngoto 130\n\n110 continue\n\nwrite (6, 3) nq2\n3 format ('initqgs: Table space parameter is too small; value =',i8)\nnerror = 92\ngoto 130\n\n120 continue\n\nnerror = ierror + 100\nwrite (6, 4) nerror\n4 format ('initqgs: Error in quadrature initialization; code =',i5)\n\n130 continue\n\ncall mpsetprecwords (nwords1)\nreturn\nend\n\nfunction quadgs (fun, x1, x2, nq1, nq2, wk, xk)\n\n! This routine computes the integral of the function fun on the interval\n! [0, 1], with up to nq1 iterations, with a target tolerance of 10^nepsilon1.\n! wk and xk are precomputed tables of weights and abscissas, each of size\n! nq2 and of type mp_real. The function fun is not evaluated at x1 or x2.\n\n! David H. Bailey 2004-08-14\n\nuse mpmodule\nuse quadglobal\nimplicit none\ninteger i, ierror, ik0, k, j, n, nds, nq1, nq2, nerr, nwp\nlogical log1, log2\ndouble precision d1, d2, d3, dplog10q, dpw\ntype (mp_real) ax, bx, c10, eps1, epsilon1, epsilon2, err, fun, &\n quadgs, tsum, s1, s2, s3, t1, t2, tw1, tw2, twmx, &\n wk(-1:nq2), xk(-1:nq2), x1, x2, xx1, xx2\nexternal fun, dplog10q\nparameter (ik0 = 100, dpw = 14.44943979d0)\n\nnds = mpoud\nmpoud = 56\nax = 0.5d0 * (x2 - x1)\nbx = 0.5d0 * (x2 + x1)\nepsilon1 = mpreal (10.d0) ** nepsilon1\nepsilon2 = mpreal (10.d0) ** nepsilon2\ns1 = 0.d0\ns2 = 0.d0\nc10 = 10.d0\n\nif (wk(-1) < dble (nq1)) then\n write (6, 1) nq1\n1 format ('quadgs: quadrature arrays have not been initialized; nq1 =',i6)\n nerror = 70\n goto 130\nendif\n\ndo k = 1, nq1\n n = 3 * 2 ** (k + 1)\n s3 = s2\n s2 = s1\n\n twmx = 0.d0\n tsum = 0.d0\n i = dble (xk(k))\n\n do j = 1, n / 2\n i = i + 1\n xx1 = - ax * xk(i) + bx\n xx2 = ax * xk(i) + bx\n log1 = xx1 > x1\n log2 = xx2 < x2\n\n if (log1) then\n t1 = fun (xx1)\n call mpgetpar ('mpier', ierror)\n if (ierror > 0 .or. nerror > 0) goto 120\n tw1 = t1 * wk(i)\n else\n t1 = 0.d0\n tw1 = 0.d0\n endif\n\n if (log2 .and. j + k > 2) then\n t2 = fun (xx2)\n call mpgetpar ('mpier', ierror)\n if (ierror > 0 .or. nerror > 0) goto 120\n tw2 = t2 * wk(i)\n else\n t2 = 0.d0\n tw2 = 0.d0\n endif\n\n tsum = tsum + tw1 + tw2\n twmx = max (twmx, abs (tw1), abs (tw2))\n enddo\n\n! Compute s1 = current integral approximation and err = error estimate.\n! Tsum is the sum of all tw1 and tw2 from the loop above.\n! Twmx is the largest absolute value of tw1 and tw2 from the loop above.\n\n s1 = ax * tsum\n eps1 = twmx * epsilon1\n d1 = dplog10q (abs (s1 - s2))\n d2 = dplog10q (abs (s1 - s3))\n d3 = dplog10q (eps1) - 1.d0\n\n if (k <= 2) then\n nerr = 0\n err = 1.d0\n elseif (d1 .eq. -9999.d0) then\n nerr = -9999\n err = 0.d0\n else\n nerr = nint (min (0.d0, max (d1 ** 2 / d2, 2.d0 * d1, d3)))\n err = c10 ** nerr\n endif\n\n! Output current integral approximation and error estimate, to 56 dp.\n\n if (ndebug >= 2) then\n write (6, 2) k, nq1, nint (dplog10q (abs (err)))\n2 format ('quadgs: Iteration',i3,' of',i3,'; est error = 10^',i5, &\n '; approx value =')\n call mpwrite (6, s1)\n endif\n if (k >= 3 .and. err < eps1) goto 130\nenddo\n\nwrite (6, 3) nint (dplog10q (abs (err))), nquadl\n3 format ('quadgs: Estimated error = 10^',i5/&\n 'Increase Quadlevel for greater accuracy. Current Quadlevel =',i4)\nif (err > 1.d-20) then\n write (6, 4)\n4 format ('quadgs: Poor results may be due to singularities at endpoints.'/&\n 'If so, try the erf or tanh-sinh quadrature routines (Quadtype = 2 or 3).')\nendif\ngoto 130\n\n120 continue\n\nnerror = ierror + 100\nwrite (6, 6) nerror\n6 format ('quadgs: Error in quadrature calculation; code =',i5)\ns1 = 0.d0\n\n130 continue\n\nquadgs = s1\nmpoud = nds\nreturn\nend\n\nfunction dplog10q (a)\n\n! For input MP value a, this routine returns a DP approximation to log10 (a).\n\nuse mpmodule\nimplicit none\ninteger ia\ndouble precision da, dplog10q\ntype (mp_real) a\n\ncall mpmdc (a%mpr, da, ia)\nif (da .eq. 0.d0) then\n dplog10q = -9999.d0\nelse\n dplog10q = log10 (abs (da)) + ia * log10 (2.d0)\nendif\n\nreturn\nend\n\nsubroutine decmdq (a, b, ib)\n\n! For input MP value a, this routine returns DP b and integer ib such that \n! a = b * 10^ib, with 1 <= abs (b) < 10 for nonzero a.\n\nuse mpmodule\nimplicit none\ninteger ia, ib\ndouble precision da, b, t1, xlt\nparameter (xlt = 0.3010299956639812d0)\ntype (mp_real) a\n\ncall mpmdc (a%mpr, da, ia)\nif (da .ne. 0.d0) then\n t1 = xlt * ia + log10 (abs (da))\n ib = t1\n if (t1 .lt. 0.d0) ib = ib - 1\n b = sign (10.d0 ** (t1 - ib), da)\nelse\n b = 0.d0\n ib = 0\nendif\n\nreturn\nend\n", "meta": {"hexsha": "79dd4c8cdf8d9ec324420eefda026491babf3c0c", "size": 19775, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ARPREC/arprec/fortran/tquadgs.f", "max_stars_repo_name": "paveloom-p/P3", "max_stars_repo_head_hexsha": "57df3b6263db81685f137a7ed9428dbd3c1b4a5b", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ARPREC/arprec/fortran/tquadgs.f", "max_issues_repo_name": "paveloom-p/P3", "max_issues_repo_head_hexsha": "57df3b6263db81685f137a7ed9428dbd3c1b4a5b", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ARPREC/arprec/fortran/tquadgs.f", "max_forks_repo_name": "paveloom-p/P3", "max_forks_repo_head_hexsha": "57df3b6263db81685f137a7ed9428dbd3c1b4a5b", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.3699095023, "max_line_length": 81, "alphanum_fraction": 0.6212389381, "num_tokens": 8468, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.8175744806385543, "lm_q1q2_score": 0.6626268728246412}} {"text": " !****************************************************************************\n !\n ! PROGRAM: tst_approach\n !\n ! PURPOSE: Take part in a performance measurement study on a computer problem\n !\n !****************************************************************************\n ! Traveling Salesman Problem Exact algorithm\n ! Nodes : 13\n ! Iterations : 479001600\n ! Nodules\n ! NODE: 1\n ! NODE: 2\n ! NODE: 3\n ! NODE: 4\n ! NODE: 5\n ! NODE: 6\n ! NODE: 7\n ! NODE: 8\n ! NODE: 9\n ! NODE: 10\n ! NODE: 11\n ! NODE: 12\n ! ... 30 s\n\n ! RESULT\n ! NODE: 0\n ! NODE: 7\n ! NODE: 2\n ! NODE: 3\n ! NODE: 4\n ! NODE: 12\n ! NODE: 6\n ! NODE: 8\n ! NODE: 1\n ! NODE: 11\n ! NODE: 10\n ! NODE: 5\n ! NODE: 9\n ! NODE: 0\n ! Distance : 7293\n ! Elapsed time : 7.39 s x86 | x64 7.42 s\n\n program tsp_approach\n\n implicit none\n\n integer, parameter :: NODES_COUNT = 13\n integer, parameter :: NODULES_COUNT = NODES_COUNT - 1\n\n ! FUNCTIONS\n integer :: factorial\n\n ! VARS\n integer :: depot\n integer :: nodes\n integer :: nodulesCount\n integer :: iterations\n integer :: percentSize\n integer :: percent\n integer :: permutation\n integer :: minDistance\n integer :: finalIndex\n integer :: fragment\n\n ! temporaries\n integer :: i\n integer :: j\n integer :: t\n real :: startTime, stopTime\n\n ! define matrix\n integer, dimension(0:NODES_COUNT-1, 0:NODES_COUNT-1) :: data\n integer, dimension(0:NODULES_COUNT-1) :: nodules\n integer, dimension(0:NODULES_COUNT-1) :: route\n\n write(*, '(A)') 'Traveling Salesman Problem Exact algorithm'\n\n data = reshape((/ &\n 0, 2451, 713, 1018, 1631, 1374, 2408, 213, 2571, 875, 1420, 2145, 1972, &\n 2451, 0, 1745, 1524, 831, 1240, 959, 2596, 403, 1589, 1374, 357, 579, &\n 713, 1745, 0, 355, 920, 803, 1737, 851, 1858, 262, 940, 1453, 1260, &\n 1018, 1524, 355, 0, 700, 862, 1395, 1123, 1584, 466, 1056, 1280, 987, &\n 1631, 831, 920, 700, 0, 663, 1021, 1769, 949, 796, 879, 586, 371, &\n 1374, 1240, 803, 862, 663, 0, 1681, 1551, 1765, 547, 225, 887, 999, &\n 2408, 959, 1737, 1395, 1021, 1681, 0, 2493, 678, 1724, 1891, 1114, 701, &\n 213, 2596, 851, 1123, 1769, 1551, 2493, 0, 2699, 1038, 1605, 2300, 2099, &\n 2571, 403, 1858, 1584, 949, 1765, 678, 2699, 0, 1744, 1645, 653, 600, &\n 875, 1589, 262, 466, 796, 547, 1724, 1038, 1744, 0, 679, 1272, 1162, &\n 1420, 1374, 940, 1056, 879, 225, 1891, 1605, 1645, 679, 0, 1017, 1200, &\n 2145, 357, 1453, 1280, 586, 887, 1114, 2300, 653, 1272, 1017, 0, 504, &\n 1972, 579, 1260, 987, 371, 999, 701, 2099, 600, 1162, 1200, 504, 0 &\n ! sample or 4 nodes\n ! NODES_COUNT = 4\n ! 00, 10, 35, 30, &\n ! 10, 00, 30, 15, &\n ! 35, 30, 00, 30, &\n ! 30, 15, 30, 00 &\n /), shape(data))\n\n depot = 0\n nodes = NODES_COUNT\n nodulesCount = NODULES_COUNT\n iterations = factorial(nodulesCount)\n percentSize = iterations / 100\n fragment = percentSize;\n percent = 0\n permutation = 1\n minDistance = 999999\n finalIndex = nodulesCount - 1\n !\n call cpu_time(startTime)\n\n ! initialize permutation array\n j = 0\n do i = 0, nodulesCount\n if (i /= depot) then\n nodules(j) = i\n route(j) = i\n j = j + 1\n end if\n end do\n\n write(*, '(A, I0)') 'Nodes : ', nodes\n write(*, '(A, I0)') 'Iterations : ', iterations\n write(*, '(A)') 'Nodules'\n do i = 0, finalIndex\n write(*, '(A, I0)') \" NODE: \", nodules(i)\n end do\n\n ! recursive calculation\n call GetRoute(0, nodulesCount)\n\n call cpu_time(stopTime)\n\n write(*, '(A)') 'RESULT'\n write(*, '(A, I0)') ' NODE: ', depot\n do i = 0, finalIndex\n write(*, '(A, I0)') ' NODE: ', route(i)\n end do\n write(*, '(A, I0)') ' NODE: ', depot\n write(*, '(A, I0)') 'Distance : ', minDistance\n write(*, '(A, F12.6, A)') 'Elapsed time : ', (stopTime - startTime), ' s'\n\n contains\n recursive subroutine GetRoute(start, finish)\n implicit none\n\n integer :: start\n integer :: finish\n integer :: s\n integer :: i\n\n if (start == finish - 1) then\n s = data(depot, nodules(0)) + data(nodules(finalIndex), depot)\n ! 2. route\n do i = 0, finalIndex - 1\n s = s + data(nodules(i), nodules(i + 1))\n end do\n permutation = permutation + 1\n if (minDistance > s) then\n minDistance = s\n ! preserve the minimum route\n do i = 0, finalIndex\n route(i) = nodules(i)\n end do\n end if\n ! show advance\n if (percentSize > 0) then\n ! if (mod(permutation, percentSize) == 0) then\n if (permutation > fragment) then\n percent = percent + 1\n fragment = fragment + percentSize\n write(*, '(A, I0, A)') \" permutations: \", percent, \" %\"\n end if\n end if\n else\n do i = start, finish - 1\n ! swap\n call swap(nodules(start), nodules(i))\n ! permute\n call GetRoute(start + 1, finish)\n ! swap\n call swap(nodules(start), nodules(i))\n end do\n end if\n end subroutine\n\n subroutine swap(a, b)\n implicit none\n integer :: a, b\n t = a\n a = b\n b = t\n end subroutine\n end program\n\n function factorial(number)\n integer :: factorial\n integer :: number, f\n f = 1\n do i = 1,number\n f = f * i\n end do\n factorial = f\n end function\n\n", "meta": {"hexsha": "2430d4a13ea93b6977bada5fe7fefc7268d84aaa", "size": 5744, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran/tsp_approach_ifort/tsp_approach/tsp_approach.f90", "max_stars_repo_name": "harveytriana/TspApproach", "max_stars_repo_head_hexsha": "e5967438f51f776e003b6e30c6e97d86a8716821", "max_stars_repo_licenses": ["Intel"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-09-03T03:57:40.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-30T14:03:25.000Z", "max_issues_repo_path": "Fortran/tsp_approach_ifort/tsp_approach/tsp_approach.f90", "max_issues_repo_name": "harveytriana/TspApproach", "max_issues_repo_head_hexsha": "e5967438f51f776e003b6e30c6e97d86a8716821", "max_issues_repo_licenses": ["Intel"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran/tsp_approach_ifort/tsp_approach/tsp_approach.f90", "max_forks_repo_name": "harveytriana/TspApproach", "max_forks_repo_head_hexsha": "e5967438f51f776e003b6e30c6e97d86a8716821", "max_forks_repo_licenses": ["Intel"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-10-01T07:29:15.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-16T07:56:03.000Z", "avg_line_length": 27.6153846154, "max_line_length": 82, "alphanum_fraction": 0.5033077994, "num_tokens": 2070, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382236515259, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.6625920167314875}} {"text": "! A recursive version of Fibonacci\n! Note that while this works OK as a recursive program\n! it actually does far, far more work that it needs to, much\n! more than double (actually 2^n -1) fold\n! Fpr instance, to calculate Fib(3), it will calculate\n! Fib(1) twice, and Fib(2) once. For Fib(4) it calculates\n! Fib(3) once, Fib(2) twice, and Fib(1) three times. This is\n! actually the Fibonacci sequence all over again, so it grows FAST!\n\nPROGRAM MAIN\n\n IMPLICIT NONE\n\n ! Loop counter and maximum value\n INTEGER :: i, max_val\n ! Variables for previous sequence vals, and current one\n INTEGER :: fib_first, fib_second, fib_current\n\n ! Do the first 20 terms\n max_val = 20\n\n ! Optional last but to add- sanity check on max_val\n IF(max_val < 3 .OR. max_val > 46) THEN\n PRINT*, \"Sequence is too short or long. max_val should be between 3 and 46\"\n END IF\n\n ! f(1) = 1 and f(2) = 1\n fib_first = 1\n fib_second = 1\n\n ! Print the initial 2 values so we see the whole sequence up to max_val\n PRINT*, fib_first\n PRINT*, fib_second\n\n ! Loop from the third value to max_value, calculating and printing the term\n DO i = 3, max_val\n\n ! This is the current term\n fib_current = fib(i)\n\n ! Print the calculated value\n PRINT*, fib_current\n\n END DO\n\n! A slightly old-fashioned way to define a function, putting it inside the main program like this.\n! It is available inside MAIN, but not outside. But one function here can call another. \nCONTAINS\n\n ! We have to use a 'RESULT' here because otherwise there is an\n ! ambiguity about where we are setting the result variable and\n ! where we are calling the function. So we have e.g.:\n RECURSIVE FUNCTION fib(n) RESULT(fib_n)\n INTEGER:: fib_n, n\n\n IF (n < 3) THEN\n fib_n = 1\n ELSE\n fib_n = fib(n-1) + fib(n-2)\n END IF\n\n END FUNCTION\n\nEND PROGRAM\n", "meta": {"hexsha": "ff8a7baac31038533c4a0d292783ebaa0ab17743", "size": 1829, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ModelSolutions/Fibonacci_recursive.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/Fibonacci_recursive.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/Fibonacci_recursive.f90", "max_forks_repo_name": "WarwickRSE/Fortran4Researchers", "max_forks_repo_head_hexsha": "14467a32a516fdc0cf33341aea8d5b26f4501b51", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.1384615385, "max_line_length": 98, "alphanum_fraction": 0.6981957354, "num_tokens": 525, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310357, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.6625920149146335}} {"text": " Program dstev_example\n\n! DSTEV Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_example_aux, Only: nagf_file_print_matrix_real_gen\n Use lapack_interfaces, Only: ddisna, dstev\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nin = 5, nout = 6\n! .. Local Scalars ..\n Real (Kind=dp) :: eerrbd, eps\n Integer :: i, ifail, info, ldz, n\n! .. Local Arrays ..\n Real (Kind=dp), Allocatable :: d(:), e(:), rcondz(:), work(:), z(:, :), &\n zerrbd(:)\n! .. Intrinsic Procedures ..\n Intrinsic :: abs, epsilon, max\n! .. Executable Statements ..\n Write (nout, *) 'DSTEV Example Program Results'\n Write (nout, *)\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n\n ldz = n\n Allocate (d(n), e(n-1), rcondz(n), work(2*n-2), z(ldz,n), zerrbd(n))\n\n! Read the diagonal and off-diagonal elements of the matrix A\n! from data file\n\n Read (nin, *) d(1:n)\n Read (nin, *) e(1:n-1)\n\n! Solve the symmetric tridiagonal eigenvalue problem\n Call dstev('Vectors', n, d, e, z, ldz, work, info)\n\n If (info==0) Then\n\n! Print solution\n\n Write (nout, *) 'Eigenvalues'\n Write (nout, 100) d(1:n)\n Flush (nout)\n\n! Standardize the eigenvectors so that first elements are non-negative.\n Do i = 1, n\n If (z(1,i)<0.0_dp) Then\n z(1:n, i) = -z(1:n, i)\n End If\n End Do\n\n! ifail: behaviour on error exit\n! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft\n ifail = 0\n Call nagf_file_print_matrix_real_gen('General', ' ', n, n, z, ldz, &\n 'Eigenvectors', ifail)\n\n! Get the machine precision, EPS and compute the approximate\n! error bound for the computed eigenvalues. Note that for\n! the 2-norm, max( abs(D(i)) ) = norm(A), and since the\n! eigenvalues are returned in ascending order\n! max( abs(D(i)) ) = max( abs(D(1)), abs(D(n)))\n\n eps = epsilon(1.0E0_dp)\n eerrbd = eps*max(abs(d(1)), abs(d(n)))\n\n! Call DDISNA to estimate reciprocal condition\n! numbers for the eigenvectors\n Call ddisna('Eigenvectors', n, n, d, rcondz, info)\n\n! Compute the error estimates for the eigenvectors\n\n Do i = 1, n\n zerrbd(i) = eerrbd/rcondz(i)\n End Do\n\n! Print the approximate error bounds for the eigenvalues\n! and vectors\n\n Write (nout, *)\n Write (nout, *) 'Error estimate for the eigenvalues'\n Write (nout, 110) eerrbd\n Write (nout, *)\n Write (nout, *) 'Error estimates for the eigenvectors'\n Write (nout, 110) zerrbd(1:n)\n Else\n Write (nout, 120) 'Failure in DSTEV. INFO =', info\n End If\n\n100 Format (3X, (8F8.4))\n110 Format (4X, 1P, 6E11.1)\n120 Format (1X, A, I4)\n End Program\n", "meta": {"hexsha": "d995d326cb849e79d30aa85e76a705b2e56f60ea", "size": 3128, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/dstev_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/dstev_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/dstev_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 31.28, "max_line_length": 90, "alphanum_fraction": 0.5757672634, "num_tokens": 950, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412809, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.6625920112631387}} {"text": "! { dg-do run }\n! PR 48955 - missing array temporary when there was both a forward\n! and a backward dependency.\n! Test case slightly modified from the original one by Kacper Kowalik.\nprogram ala\n implicit none\n\n integer, parameter :: n = 6\n real, dimension(n), parameter :: result = [1.,10.,30.,90.,270., 243.];\n real, dimension(n) :: v0, v1\n character(len=80) :: line1, line2\n\n v0 = [1.0, 3.0, 9.0, 27.0, 81.0, 243.0]\n v1 = v0\n\n v1(2:n-1) = v1(1:n-2) + v1(3:n)\n if (any(v1 /= result)) STOP 1\n v1 = v0\n v1(2:n-1) = v0(1:n-2) + v0(3:n)\n if (any(v1 /= result)) STOP 2\n\n v1 = v0\n v1(2:n-1) = v1(3:n) + v1(1:n-2)\n if (any(v1 /= result)) STOP 3\n v1 = v0\n v1(2:n-1) = v0(3:n) + v0(1:n-2)\n if (any(v1 /= result)) STOP 4\n\nend program ala\n", "meta": {"hexsha": "8baad9a8345a5f8e0ecb82125012282d4b8c0ade", "size": 767, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/dependency_40.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/dependency_40.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/dependency_40.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": 25.5666666667, "max_line_length": 73, "alphanum_fraction": 0.5697522816, "num_tokens": 335, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527632, "lm_q2_score": 0.8198933425148213, "lm_q1q2_score": 0.6625289286964129}} {"text": "integer function PlmIndex(l, m)\n!-------------------------------------------------------------------------------\n!\n! This function will return the index corresponding \n! to a given l and m in the arrays of Legendre Polynomials\n! generated by routines such as PlmBar and PlmSchmidt.\n!\n! Calling Parameters\n!\n! l Spherical harmonic angular degree.\n! m Spherical harmonic angular order.\n!\n! Copyright (c) 2005-2019, SHTOOLS\n! All rights reserved.\n!\n!-------------------------------------------------------------------------------\n implicit none\n\n integer, intent(in) :: l, m\n\n if (l < 0) then\n print*, \"Error --- PlmIndex\"\n print*, \"L must be greater of equal to 0.\"\n print*, \"L = \", l\n print*, \"M = \", m\n stop\n\n else if (m < 0 .or. m > l) then\n print*, \"Error --- PlmIndex\"\n print*, \"M must be greater than or equal to zero and less than or \" // &\n \"equal to L.\"\n print*, \"L = \", l\n print*, \"M = \", m\n stop\n\n end if\n\n PlmIndex = (l*(l+1))/2+m+1\n\nend function PlmIndex\n", "meta": {"hexsha": "f2b413e5b3d227996840c35f479992cd5af104bc", "size": 1098, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/PlmIndex.f95", "max_stars_repo_name": "dilkins/SHTOOLS", "max_stars_repo_head_hexsha": "7bb13a0f7e05bdc66ab534dcd6a8d01e74bda886", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-01-28T13:35:22.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-28T13:35:22.000Z", "max_issues_repo_path": "src/PlmIndex.f95", "max_issues_repo_name": "dilkins/SHTOOLS", "max_issues_repo_head_hexsha": "7bb13a0f7e05bdc66ab534dcd6a8d01e74bda886", "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/PlmIndex.f95", "max_forks_repo_name": "dilkins/SHTOOLS", "max_forks_repo_head_hexsha": "7bb13a0f7e05bdc66ab534dcd6a8d01e74bda886", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.7804878049, "max_line_length": 80, "alphanum_fraction": 0.4790528233, "num_tokens": 284, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933447152497, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.6625289285796601}} {"text": "program bspline_tests\nuse utils\nuse bspline\nuse ogpf\n\nimplicit none\n!---------------\n! Variables\n!---------------\ninteger :: i,j,total_tests, passed_tests\nreal(wp), allocatable :: y(:),x(:)\nreal(wp) :: result,true\n\n!---------------\n! Logic\n!---------------\ntotal_tests = 1\npassed_tests = 0\n\nwrite(*,*)\nwrite(*,*) \"!-----------------------\"\nwrite(*,*) \"! Testing linear splines\"\nwrite(*,*) \"!-----------------------\"\nwrite(*,*)\n\nallocate(y(3))\nallocate(x(4))\n\ny = linspace(1.0_wp,3.0_wp,3)\nx = [y(1)-0.1,y(1),y(2),y(3),y(3)+0.1]\n!call test_linear_spline(y,x,linear_spline,total_tests,passed_tests)\n\ny = linspace(200.42_wp,799.99_wp,3)\nx = [y(1)-0.1,y(1),y(2),y(3),y(3)+0.1]\n!call test_linear_spline(y,x,linear_spline,total_tests,passed_tests)\n\nwrite(*,*)\nwrite(*,*) \"!----------------------------------\"\nwrite(*,*) \"! Testing linear spline derivatives\"\nwrite(*,*) \"!----------------------------------\"\nwrite(*,*)\n\ny = linspace(1.0_wp,3.0_wp,3)\nx = [y(1)-0.1,y(1),y(2),y(3),y(3)+0.1]\n!call test_linear_spline(y,x,linear_spline_deriv,total_tests,passed_tests)\n!call plot_spline(y,linear_spline_deriv)\n\ny = linspace(200.42_wp,799.99_wp,3)\nx = [y(1)-0.1,y(1),y(2),y(3),y(3)+0.1]\n!call test_linear_spline(y,x,linear_spline_deriv,total_tests,passed_tests)\n!call plot_spline(y,linear_spline_deriv)\n\ndeallocate(y)\ndeallocate(x)\n\nwrite(*,*)\nwrite(*,*) \"!----------------------\"\nwrite(*,*) \"! Testing cubic splines\"\nwrite(*,*) \"!----------------------\"\nwrite(*,*)\n\nallocate(y(5))\nallocate(x(7))\n\ny = linspace(1.0_wp,5.0_wp,5)\nx = [y(1)-0.1,y(1),y(2),y(3),y(4),y(5),y(5)+0.1]\n!call test_cubic_spline(y,x,cubic_spline,total_tests,passed_tests)\n\n\ny = linspace(234.432_wp,987.789_wp,5)\nx = [y(1)-0.1,y(1),y(2),y(3),y(4),y(5),y(5)+0.1]\n!call test_cubic_spline(y,x,cubic_spline,total_tests,passed_tests)\n\nwrite(*,*)\nwrite(*,*) \"!--------------------------------\"\nwrite(*,*) \"! Testing cubic spline derivative\"\nwrite(*,*) \"!--------------------------------\"\nwrite(*,*)\n\ny = linspace(1.0_wp,5.0_wp,5)\nx = [y(1)-0.1,y(1),y(2),y(3),y(4),y(5),y(5)+0.1]\n!call test_cubic_spline(y,x,cubic_spline_deriv,total_tests,passed_tests)\n!call plot_spline(y,cubic_spline_deriv)\n\ny = linspace(234.432_wp,987.789_wp,5)\nx = [y(1)-0.1,y(1),y(2),y(3),y(4),y(5),y(5)+0.1]\n!call test_cubic_spline(y,x,cubic_spline_deriv,total_tests,passed_tests)\n!call plot_spline(y,cubic_spline_deriv)\n\ny = linspace(0.0_wp,1.0_wp,5)\ny(2) = 0.0_wp\ny(3) = 0.0_wp\nx = [y(1)-0.1,y(1),y(2),y(3),y(4),y(5),y(5)+0.1]\ncall test_cubic_spline(y,x,cubic_spline,total_tests,passed_tests)\n!call plot_spline(y,cubic_spline_deriv)\n\n!call plot_new_cubic_spline(cubic_spline_basis)\n\nwrite(*,*) \"!---------------------------\"\nwrite(*,'(a,g14.6)') \" !Total tests \", total_tests-1\nwrite(*,'(a,g14.6)') \" !Tests passed\", passed_tests\nwrite(*,*) \"!---------------------------\"\n\ncontains\nsubroutine test_linear_spline(y,x,f,total_tests,passed_tests)\n real(wp), allocatable, intent(in) :: y(:),x(:)\n integer, intent(inout) :: passed_tests,total_tests\n real(wp) :: true,result\n real(wp), external :: f\n integer :: i\n\n write(*,*)\n write(*,*) \"Test number \", total_tests\n write(*,*) \"Grid is \"\n write(*,*) y\n\n do i = 1, size(x)\n result = f(y,x(i))\n if ( x(i) <= y(1) .or. x(i) >= y(3) ) then\n true = 0.0\n else\n true = 1.0\n end if\n\n write(*,\"(A,TR8,F15.5)\") \"Evaluating at\", x(i)\n write(*,\"(A,TR4,F15.5)\") \"Expected value is\", true\n write(*,\"(A,TR2,F15.5)\") \"Calculated value is\", result\n if ( close(result,true,1.0_wp*1e-5) ) then\n passed_tests = passed_tests + 1\n write(*,*) \"Test passed\"\n else\n write(*,*) \"!-----------!\"\n write(*,*) \"!Test failed!\"\n write(*,*) \"!-----------!\"\n end if\n total_tests = total_tests + 1\n write(*,*)\n end do\n\n call plot_spline(y, f)\nend subroutine test_linear_spline\n\nsubroutine test_cubic_spline(y,x,f,total_tests,passed_tests)\n real(wp), intent(in) :: y(5),x(7)\n integer, intent(inout) :: passed_tests,total_tests\n real(wp) :: true,result\n real(wp), external :: f\n integer :: i\n\n write(*,*)\n write(*,\"(A,I10)\") \"Test number \", total_tests\n write(*,*) \"Grid is \"\n write(*,*) y\n write(*,*)\n\n do i = 1, size(x)\n result = f(y,x(i))\n true = 0.0\n if ( close(x(i),y(2),1.0_wp*1e-1) .or. close(x(i),y(4),1.0_wp*1e-1) ) then\n true = 0.16666666_wp\n elseif ( close(x(i),y(3),1.0_wp*1e-1) ) then\n true = 0.66666666_wp\n end if\n\n write(*,\"(A,TR8,F15.5)\") \"Evaluating at\", x(i)\n write(*,\"(A,TR4,F15.5)\") \"Expected value is\", true\n write(*,\"(A,TR2,F15.5)\") \"Calculated value is\", result\n if ( close(result,true,1.0_wp*1e-5) ) then\n passed_tests = passed_tests + 1\n write(*,*) \"Test passed\"\n else\n write(*,*) \"!-----------!\"\n write(*,*) \"!Test failed!\"\n write(*,*) \"!-----------!\"\n end if\n total_tests = total_tests + 1\n write(*,*)\n end do\n call plot_spline(y, f)\nend subroutine test_cubic_spline\n\nsubroutine plot_new_cubic_spline(spline)\n real(wp), external :: spline\n integer, parameter :: i = 101\n integer, parameter :: n = 5\n integer, parameter :: m = n+2\n integer :: j\n real(wp) :: y(m)\n real(wp) :: x(i),fx(i),h\n type(gpf):: gp\n\n y = linspace(0.0_wp,1.0_wp,m)\n h = y(2) - y(1)\n\n x = linspace(y(1),y(3),i)\n do j = 1,i\n fx(j) = spline(x(j)/h) - 4*spline((x(j)+h)/h)\n end do\n call gp%title('B-Spline Phi_0')\n call gp%options('set key top right; set grid')\n call gp%plot(x,fx,'title \"B(x)\" with lines lt 1 lw 1')\n\n x = linspace(y(1),y(4),i)\n do j = 1,i\n fx(j) = spline((x(j)-y(2))/h) - spline((x(j)+h)/h)\n end do\n call gp%title('B-Spline Phi_1')\n call gp%options('set key top right; set grid')\n call gp%plot(x,fx,'title \"B(x)\" with lines lt 1 lw 1')\n\n x = linspace(y(1),y(5),i)\n do j = 1,i\n fx(j) = spline((x(j)-y(3))/h)\n end do\n call gp%title('B-Spline Phi_2')\n call gp%options('set key top right; set grid')\n call gp%plot(x,fx,'title \"B(x)\" with lines lt 1 lw 1')\n\n x = linspace(y(m-3),y(m),i)\n do j = 1,i\n fx(j) = spline((x(j)-y(n+1))/h) - spline((x(j)-(n+2)*h)/h)\n end do\n call gp%title('B-Spline Phi_6')\n call gp%options('set key top right; set grid')\n call gp%plot(x,fx,'title \"B(x)\" with lines lt 1 lw 1')\n\n x = linspace(y(m-2),y(m),i)\n do j = 1,i\n fx(j) = spline((x(j)-y(n+2))/h) - 4*spline((x(j)-(n+2)*h)/h)\n end do\n call gp%title('B-Spline Phi_7')\n call gp%options('set key top right; set grid')\n call gp%plot(x,fx,'title \"B(x)\" with lines lt 1 lw 1')\n\nend subroutine plot_new_cubic_spline\n\nsubroutine plot_spline(y,spline)\n real(wp), external :: spline\n integer, parameter :: i = 101\n integer :: j\n real(wp), intent(in) :: y(:)\n real(wp) :: x(i),fx(i)\n type(gpf):: gp\n x = linspace(y(1),y(size(y)),i)\n\n do j = 1,i\n fx(j) = spline(y,x(j))\n end do\n\n call gp%title('B-Spline')\n call gp%options('set key top right; set grid')\n call gp%plot(x,fx,'title \"B(x)\" with lines lt 1 lw 1')\nend subroutine plot_spline\n\nend program bspline_tests\n", "meta": {"hexsha": "47dff6c20e103cee0581df947abd2a1b65f2f1e4", "size": 6917, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "tests/bspline_tests_old.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": "tests/bspline_tests_old.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": "tests/bspline_tests_old.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": 27.01953125, "max_line_length": 78, "alphanum_fraction": 0.5790082406, "num_tokens": 2540, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.819893335913536, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.6625289214672838}} {"text": "! gfortran phys395_hw0_fib.f90 && ./a.out\n\nprogram fibonacci\n implicit none\n integer(kind=8) :: i, a = 0, b = 1, c\n\n do i = 1, 50\n c = a + b\n a = b\n b = c\n print *, a\n enddo\nend program fibonacci\n", "meta": {"hexsha": "4d3e415b0c8e1d05fec9c72dfdf3f02c1af487ab", "size": 212, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/phys395_hw0/phys395_hw0_fib.f90", "max_stars_repo_name": "YodaEmbedding/experiments", "max_stars_repo_head_hexsha": "567c6a1c18fac2d951fe2af54aaa4917b7d529d2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fortran/phys395_hw0/phys395_hw0_fib.f90", "max_issues_repo_name": "YodaEmbedding/experiments", "max_issues_repo_head_hexsha": "567c6a1c18fac2d951fe2af54aaa4917b7d529d2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/phys395_hw0/phys395_hw0_fib.f90", "max_forks_repo_name": "YodaEmbedding/experiments", "max_forks_repo_head_hexsha": "567c6a1c18fac2d951fe2af54aaa4917b7d529d2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.1428571429, "max_line_length": 41, "alphanum_fraction": 0.5613207547, "num_tokens": 85, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933183101077, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.6625289053476837}} {"text": "\tDOUBLE PRECISION FUNCTION R1(X)\r\n\tIMPLICIT NONE\r\n\tDOUBLE PRECISION X,P(0:3),Q(0:3),NUMER,DENOM\r\n INTEGER J\r\n\tDATA P/2.4266 7955 2305 3175D2,\r\n . 2.1979 2616 1829 4152D1,\r\n . 6.9963 8348 8619 1355D0,\r\n . -3.5609 8437 0181 5385D-2/\r\n\tDATA Q/2.1505 8875 8698 6120D2,\r\n . 9.1164 9054 0451 4901D1,\r\n . 1.5082 7976 3040 7787D1,\r\n . 1.0000 0000 0000 0000D0/\r\n NUMER = 0\r\n DENOM = 0\r\n\tDO 10 J=0,3\r\n\t NUMER= NUMER +P(J)*X**(2*J)\r\n DENOM = DENOM +Q(J)*X**(2*J)\r\n10\tCONTINUE\r\n R1= NUMER/DENOM\r\n\tRETURN\r\n\tEND", "meta": {"hexsha": "901bb955dd8149020c919bce1a4590ebd6b75a86", "size": 603, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "misc/old_ps/ps-development-version/psDll/r1.for", "max_stars_repo_name": "vubiostat/ps", "max_stars_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2017-12-29T14:19:14.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-06T15:08:46.000Z", "max_issues_repo_path": "misc/old_ps/ps-development-version/psDll/r1.for", "max_issues_repo_name": "vubiostat/ps", "max_issues_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2020-04-30T16:57:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-07T00:26:02.000Z", "max_forks_repo_path": "misc/old_ps/ps-development-version/psDll/r1.for", "max_forks_repo_name": "vubiostat/ps", "max_forks_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-07T20:11:54.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-11T19:18:59.000Z", "avg_line_length": 28.7142857143, "max_line_length": 46, "alphanum_fraction": 0.5306799337, "num_tokens": 278, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951625409308, "lm_q2_score": 0.7090191337850932, "lm_q1q2_score": 0.6625040487577522}} {"text": "c-------------------------------------------------------------------------\n subroutine delaz(a1lat,a1lon,a2lat,a2lon,del,dist,az)\nc\nc by Bill Ellsworth\nc\nc computes distance and azimuth from a1 to a2\nc a1 and a2 are in decimal degrees and n-e coordinates\nc del -- delta in degrees\nc dist -- distance in km\nc az -- azimuth from a to b clockwise from north in degrees\n\nc changes by Felix Waldhauser (fw)\nc\n real*8 pi2,rad,flat\n real*8 alatr,alonr,blatr,blonr\n real*8 tana,geoa,acol,tanb,geob,bcol\n real*8 diflon,cosdel,delr,top,den,azr,colat,radius\ncfw real*8 dtan,datan,dsin,dcos,darcos,dcotan,datan2\n real*8 dtan,datan,dsin,dcos,datan2\n data pi2/1.570796d0/\n data rad/1.745329d-02/\n data flat/.993231d0/\n\nc-----convert to radians\n alatr=a1lat*rad\n alonr=a1lon*rad\n blatr=a2lat*rad\n blonr=a2lon*rad\nc-----convert latitudes to geocentric colatitudes\n tana=flat*dtan(alatr)\n geoa=datan(tana)\n acol=pi2-geoa\n tanb=flat*dtan(blatr)\n geob=datan(tanb)\n bcol=pi2-geob\nc-----calcuate delta\n diflon=blonr-alonr\n cosdel=dsin(acol)*dsin(bcol)*dcos(diflon)+dcos(acol)*dcos(bcol)\ncfw delr=darcos(cosdel)\n delr=dacos(cosdel)\nc-----calcuate azimuth from a to b\n top=dsin(diflon)\ncfw den=dsin(acol)*dcotan(bcol)-dcos(acol)*dcos(diflon)\n den=dsin(acol)*(1/dtan(bcol))-dcos(acol)*dcos(diflon)\n azr=datan2(top,den)\nc-----convert to degrees\n del=delr/rad\n az=azr/rad\n if (az.lt.0.0) az=360+az\nc-----compute distance in kilometers\n colat=pi2-(alatr+blatr)/2\n radius=6371.227*(1.0+3.37853d-3*(1/3-((dcos(colat))**2)))\ncfw radius=6378.140*(1.0+3.37853d-3*(1/3-((dcos(colat))**2)))\n dist=delr*radius\n return\n end\n", "meta": {"hexsha": "8b41d8ca00dd830030a13f8947d54e6c69758e1f", "size": 1816, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "HypoDD_scripts/src/hypoDD/delaz.f", "max_stars_repo_name": "Damin1909/ESPRH", "max_stars_repo_head_hexsha": "2b26a7e698fe7c411d44ce5f51d52fffdb742d48", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-12-02T02:01:11.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-02T02:01:11.000Z", "max_issues_repo_path": "HypoDD_scripts/src/hypoDD/delaz.f", "max_issues_repo_name": "Damin1909/ESPRH", "max_issues_repo_head_hexsha": "2b26a7e698fe7c411d44ce5f51d52fffdb742d48", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HypoDD_scripts/src/hypoDD/delaz.f", "max_forks_repo_name": "Damin1909/ESPRH", "max_forks_repo_head_hexsha": "2b26a7e698fe7c411d44ce5f51d52fffdb742d48", "max_forks_repo_licenses": ["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.8596491228, "max_line_length": 74, "alphanum_fraction": 0.6106828194, "num_tokens": 671, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951625409307, "lm_q2_score": 0.7090191337850932, "lm_q1q2_score": 0.662504048757752}} {"text": "!\n! CalculiX - A 3-dimensional finite element program\n! Copyright (C) 1998-2020 Guido Dhondt\n!\n! This program is free software; you can redistribute it and/or\n! modify it under the terms of the GNU General Public License as\n! published by the Free Software Foundation(version 2);\n! \n!\n! This program is distributed in the hope that it will be useful,\n! but WITHOUT ANY WARRANTY; without even the implied warranty of \n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \n! GNU General Public License for more details.\n!\n! You should have received a copy of the GNU General Public License\n! along with this program; if not, write to the Free Software\n! Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n!\n subroutine anisomaxwavspd(elas,rho,iorth,wavspd)\n!\n! Calculates the propagation wave speed in a material, up to its 21 \n! constants. Subroutine for calcmatwavsps.f\n\n! Based on the procedure in:\n! C. Lane. The Development of a 2D Ultrasonic Array Inspection \n! for Single Crystal Turbine Blades.\n! Switzerland: Springer International Publishing, 2014.\n!\n! CARLO MONJARAZ TEC (CMT)\n!\n! INPUT:\n! \n! elas: double(21) - The elasticity vector, containing 21 entries. \n! Non used are zero. If material is orthotropic, values are\n! rearranged to match indexes from anisotropic\n! material card.\n! \n! rho: double - Density of the material\n! \n! iorth: INTEGER - if the value is 1 : material is iorthtropic\n! for other vaules: material is anisotropic\n! \n! OUTPUT:\n! \n! wavspd\n!\n implicit none\n! \n integer i,j,k,im,imin,jm,jmin,iorth\n!\n real*8 elas(21),c(3,3,3,3),rho,xi(-1:1,-1:1),et(-1:1,-1:1),\n & wavspd,d1,distmin,a\n!\n!\n! \nc write(*,*)'++cMT: calculating max. speed in ANISOTROPIC...'\n! \n!--------IF IORTHTROPIC----------------------------- \n if(iorth.eq.1)then\n! \n elas(10)=elas(9)\n elas(15)=elas(8)\n elas(21)=elas(7)\n elas(9)=0.d0\n elas(8)=0.d0\n elas(7)=0.d0\n! \n endif\n! \n!--------FIlling c voigt Matrix----------------------------- \n! \n call anisotropic(elas,c)\n!\n d1=1.d0\n!\n xi(0,0)=0.d0\n et(0,0)=0.d0\n call inversewavspd(xi(0,0),et(0,0),c,rho,a)\n distmin=a\n imin=0\n jmin=0\n!\n do k=1,8\n!\n! initialisation\n!\n d1=d1/10.d0\n! \n do i=-1,1\n do j=-1,1\n if((i.eq.0).and.(j.eq.0)) cycle\n!\n xi(i,j)=xi(0,0)+i*d1\n et(i,j)=et(0,0)+j*d1\n!\n! check whether inside the (-1,1)x(-1,1) domain\n!\n if((xi(i,j).le.1.d0).and.\n & (xi(i,j).ge.-1.d0).and.\n & (et(i,j).le.1.d0).and.\n & (et(i,j).ge.-1.d0)) then\n call inversewavspd(xi(i,j),et(i,j),c,rho,a)\n! \n! checking for smallest initial distance\n! \n if(a.lt.distmin) then\n distmin=a\n imin=i\n jmin=j\n endif\n endif\n!\n enddo\n enddo\n! \n! minimizing the distance from the face to the node\n! \n do\n! \n! exit if minimum found\n! \n if((imin.eq.0).and.(jmin.eq.0)) exit\n!\n! new center of 3x3 matrix\n!\n xi(0,0)=xi(imin,jmin)\n et(0,0)=et(imin,jmin)\n!\n im=imin\n jm=jmin\n!\n imin=0\n jmin=0\n! \n do i=-1,1\n do j=-1,1\n if((i+im.lt.-1).or.(i+im.gt.1).or.\n & (j+jm.lt.-1).or.(j+jm.gt.1)) then\n!\n xi(i,j)=xi(0,0)+i*d1\n et(i,j)=et(0,0)+j*d1\n!\n! check whether inside the (-1,1)x(-1,1) domain\n!\n if((xi(i,j).le.1.d0).and.\n & (xi(i,j).ge.-1.d0).and.\n & (et(i,j).le.1.d0).and.\n & (et(i,j).ge.-1.d0)) then\n call inversewavspd(xi(i,j),et(i,j),c,rho,a)\n!\n! check for new minimum\n!\n if(a.lt.distmin) then\n distmin=a\n imin=i\n jmin=j\n endif\n endif\n!\n endif\n enddo\n enddo\n enddo\n enddo\n!\n call inversewavspd(xi(0,0),et(0,0),c,rho,a)\n!\n wavspd=1.d0/a\n! \n return\n end\n \n", "meta": {"hexsha": "2e2ba568d7569a35579fbf36fac5faa989cccfd1", "size": 4711, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ccx_prool/CalculiX/ccx_2.17/src/anisomaxwavspd.f", "max_stars_repo_name": "alleindrach/calculix-desktop", "max_stars_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ccx_prool/CalculiX/ccx_2.17/src/anisomaxwavspd.f", "max_issues_repo_name": "alleindrach/calculix-desktop", "max_issues_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ccx_prool/CalculiX/ccx_2.17/src/anisomaxwavspd.f", "max_forks_repo_name": "alleindrach/calculix-desktop", "max_forks_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.2312138728, "max_line_length": 73, "alphanum_fraction": 0.4646571853, "num_tokens": 1358, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218327098193, "lm_q2_score": 0.7185944046238982, "lm_q1q2_score": 0.6624878704858858}} {"text": " REAL*8 AA(513,513), DD(513,513)\n REAL*8 X (513,513), Y (513,513)\n REAL*8 RX(513,513), RY(513,513)\n DO J = 2,N-1\n DO I = 2,N-1\n XX = X(I+1,J)-X(I-1,J)\n YX = Y(I+1,J)-Y(I-1,J)\n XY = X(I,J+1)-X(I,J-1)\n YY = Y(I,J+1)-Y(I,J-1)\n A = 0.25 * (XY*XY+YY*YY)\n B = 0.25* (XX*XX+YX*YX)\n C = 0.125 * (XX*XY+YX*YY)\n AA(I,J) = -B\n DD(I,J) = B+B+A*REL\n PXX = X(I+1,J)-2.*X(I,J)+X(I-1,J)\n QXX = Y(I+1,J)-2.*Y(I,J)+Y(I-1,J)\n PYY = X(I,J+1)-2.*X(I,J)+X(I,J-1)\n QYY = Y(I,J+1)-2.*Y(I,J)+Y(I,J-1)\n PXY = X(I+1,J+1)-X(I+1,J-1)-X(I-1,J+1)+X(I-1,J-1)\n QXY = Y(I+1,J+1)-Y(I+1,J-1)-Y(I-1,J+1)+Y(I-1,J-1)\n RX(I,J) = A*PXX+B*PYY-C*PXY\n RY(I,J) = A*QXX+B*QYY-C*QXY\n END DO\n END DO\n", "meta": {"hexsha": "989f05f32bb2051751f25b89ff52b2301b967f3b", "size": 880, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "depspawn-blitz-0.10/examples/stencil4.f", "max_stars_repo_name": "fraguela/depspawn", "max_stars_repo_head_hexsha": "b5760f4c0d38a1b245ee5274e2ccc5c5fe2d3d45", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2017-04-12T11:05:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T11:10:27.000Z", "max_issues_repo_path": "ibtk/third_party/blitz-0.10/examples/stencil4.f", "max_issues_repo_name": "MSV-Project/IBAMR", "max_issues_repo_head_hexsha": "3cf614c31bb3c94e2620f165ba967cba719c45ea", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ibtk/third_party/blitz-0.10/examples/stencil4.f", "max_forks_repo_name": "MSV-Project/IBAMR", "max_forks_repo_head_hexsha": "3cf614c31bb3c94e2620f165ba967cba719c45ea", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.2, "max_line_length": 61, "alphanum_fraction": 0.3556818182, "num_tokens": 412, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218391455084, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6624878695545545}} {"text": "module loglikelihood_module\n\n integer :: nx,ny\n double precision :: xmin,xmax,ymin,ymax\n double precision :: sigma\n\n double precision, dimension(:,:), allocatable :: dat,xarr,yarr\n\n\n\n contains\n\n function loglikelihood(theta,phi)\n use utils_module, only: logzero, logincexp,logTwoPi\n implicit none\n double precision, intent(in), dimension(:) :: theta !> Input parameters\n double precision, intent(out), dimension(:) :: phi !> Output derived parameters\n double precision :: loglikelihood ! loglikelihood value to output\n\n loglikelihood = -sum(&\n (dat-signal(theta))**2/2/sigma**2&\n )\n \n loglikelihood = loglikelihood &\n - log(sigma**2*atan(1d0)*8)*nx*ny/2d0\n\n end function loglikelihood\n\n function signal(theta)\n implicit none\n double precision, intent(in), dimension(:) :: theta !> Input parameters\n double precision,dimension(nx,ny) :: signal\n integer :: i,Nobj\n double precision :: A,x,y,R\n\n signal = 0\n Nobj = size(theta)/4\n\n do i=1,Nobj\n A = theta(4*(i-1)+1)\n x = theta(4*(i-1)+2)\n y = theta(4*(i-1)+3)\n R = theta(4*(i-1)+4)\n signal = signal + A*exp( -((x-xarr)**2 + (y-yarr)**2)/2/R/R)\n end do\n\n end function signal\n\n\n\n\n subroutine setup_loglikelihood(settings)\n use settings_module, only: program_settings\n use abort_module, only: halt_program\n implicit none\n type(program_settings), intent(in) :: settings\n\n integer, parameter :: stats_unit = 1000\n\n integer :: i\n\n\n ! Allocate any arrays that need to be allocated\n\n ! Find out the number of points\n open(stats_unit,file='data/obj_info.dat')\n\n read(stats_unit,*) nx\n read(stats_unit,*) xmin\n read(stats_unit,*) xmax\n read(stats_unit,*) ny\n read(stats_unit,*) ymin\n read(stats_unit,*) ymax\n read(stats_unit,*) sigma\n\n close(stats_unit)\n\n allocate(dat(nx,ny))\n\n open(stats_unit,file='data/obj.dat')\n do i=1,ny\n read(stats_unit,*) dat(:,i)\n end do\n close(stats_unit)\n\n allocate(xarr(nx,ny),yarr(nx,ny))\n\n xarr = spread( &\n [(xmin + (xmax-xmin)/(nx-1)*(i-1),i=1,nx)],&\n 1,ny )\n yarr = spread( &\n [(ymax + (ymin-ymax)/(ny-1)*(i-1),i=1,ny)],&\n 2,nx )\n\n end subroutine setup_loglikelihood\n\n\n\n\n\n\nend module loglikelihood_module\n", "meta": {"hexsha": "3efce8389dc6859307a7052c7bf9aaa7e87ab2c4", "size": 2615, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Externals/PolyChord/likelihoods/examples/object_detection.f90", "max_stars_repo_name": "yuanfangtardis/vscode_project", "max_stars_repo_head_hexsha": "2d78a85413cc85789cc4fee8ec991eb2a0563ef8", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Externals/PolyChord/likelihoods/examples/object_detection.f90", "max_issues_repo_name": "yuanfangtardis/vscode_project", "max_issues_repo_head_hexsha": "2d78a85413cc85789cc4fee8ec991eb2a0563ef8", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Externals/PolyChord/likelihoods/examples/object_detection.f90", "max_forks_repo_name": "yuanfangtardis/vscode_project", "max_forks_repo_head_hexsha": "2d78a85413cc85789cc4fee8ec991eb2a0563ef8", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-15T12:22:30.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-15T12:22:30.000Z", "avg_line_length": 25.3883495146, "max_line_length": 100, "alphanum_fraction": 0.5499043977, "num_tokens": 663, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218370002787, "lm_q2_score": 0.718594386544335, "lm_q1q2_score": 0.6624878569010417}} {"text": " SUBROUTINE SB02PD( JOB, TRANA, UPLO, N, A, LDA, G, LDG, Q, LDQ, X,\n $ LDX, RCOND, FERR, WR, WI, IWORK, DWORK, LDWORK,\n $ INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To solve the real continuous-time matrix algebraic Riccati\nC equation\nC\nC op(A)'*X + X*op(A) + Q - X*G*X = 0,\nC\nC where op(A) = A or A' = A**T and G, Q are symmetric (G = G**T,\nC Q = Q**T). The matrices A, G and Q are N-by-N and the solution X\nC is an N-by-N symmetric matrix.\nC\nC An error bound on the solution and a condition estimate are also\nC optionally provided.\nC\nC It is assumed that the matrices A, G and Q are such that the\nC corresponding Hamiltonian matrix has N eigenvalues with negative\nC real parts.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC JOB CHARACTER*1\nC Specifies the computation to be performed, as follows:\nC = 'X': Compute the solution only;\nC = 'A': Compute all: the solution, reciprocal condition\nC number, and the error bound.\nC\nC TRANA CHARACTER*1\nC Specifies the option op(A):\nC = 'N': op(A) = A (No transpose);\nC = 'T': op(A) = A**T (Transpose);\nC = 'C': op(A) = A**T (Conjugate transpose = Transpose).\nC\nC UPLO CHARACTER*1\nC Specifies which triangle of the matrices G and Q is\nC stored, as follows:\nC = 'U': Upper triangles of G and Q are stored;\nC = 'L': Lower triangles of G and Q are stored.\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The order of the matrices A, G, Q, and X. N >= 0.\nC\nC A (input) DOUBLE PRECISION array, dimension (LDA,N)\nC The leading N-by-N part of this array must contain the\nC coefficient matrix A of the equation.\nC\nC LDA INTEGER\nC The leading dimension of the array A. LDA >= max(1,N).\nC\nC G (input) DOUBLE PRECISION array, dimension (LDG,N)\nC If UPLO = 'U', the leading N-by-N upper triangular part of\nC this array must contain the upper triangular part of the\nC matrix G.\nC If UPLO = 'L', the leading N-by-N lower triangular part of\nC this array must contain the lower triangular part of the\nC matrix G.\nC\nC LDG INTEGER\nC The leading dimension of the array G. LDG >= max(1,N).\nC\nC Q (input) DOUBLE PRECISION array, dimension (LDQ,N)\nC If UPLO = 'U', the leading N-by-N upper triangular part of\nC this array must contain the upper triangular part of the\nC matrix Q.\nC If UPLO = 'L', the leading N-by-N lower triangular part of\nC this array must contain the lower triangular part of the\nC matrix Q.\nC\nC LDQ INTEGER\nC The leading dimension of the array Q. LDQ >= max(1,N).\nC\nC X (output) DOUBLE PRECISION array, dimension (LDX,N)\nC If INFO = 0, INFO = 2, or INFO = 4, the leading N-by-N\nC part of this array contains the symmetric solution matrix\nC X of the algebraic Riccati equation.\nC\nC LDX INTEGER\nC The leading dimension of the array X. LDX >= max(1,N).\nC\nC RCOND (output) DOUBLE PRECISION\nC If JOB = 'A', the estimate of the reciprocal condition\nC number of the Riccati equation.\nC\nC FERR (output) DOUBLE PRECISION\nC If JOB = 'A', the estimated forward error bound for the\nC solution X. If XTRUE is the true solution, FERR bounds the\nC magnitude of the largest entry in (X - XTRUE) divided by\nC the magnitude of the largest entry in X.\nC\nC WR (output) DOUBLE PRECISION array, dimension (N)\nC WI (output) DOUBLE PRECISION array, dimension (N)\nC If JOB = 'A' and TRANA = 'N', WR and WI contain the real\nC and imaginary parts, respectively, of the eigenvalues of\nC the matrix A - G*X, i.e., the closed-loop system poles.\nC If JOB = 'A' and TRANA = 'T' or 'C', WR and WI contain the\nC real and imaginary parts, respectively, of the eigenvalues\nC of the matrix A - X*G, i.e., the closed-loop system poles.\nC If JOB = 'X', these arrays are not referenced.\nC\nC Workspace\nC\nC IWORK INTEGER array, dimension (LIWORK), where\nC LIWORK >= 2*N, if JOB = 'X';\nC LIWORK >= max(2*N,N*N), if JOB = 'A'.\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0 or INFO = 2, DWORK(1) contains the\nC optimal value of LDWORK. If JOB = 'A', then DWORK(2:N*N+1)\nC and DWORK(N*N+2:2*N*N+1) contain a real Schur form of the\nC closed-loop system matrix, Ac = A - G*X (if TRANA = 'N')\nC or Ac = A - X*G (if TRANA = 'T' or 'C'), and the\nC orthogonal matrix which reduced Ac to real Schur form,\nC respectively.\nC\nC LDWORK INTEGER\nC The dimension of the array DWORK.\nC LDWORK >= 4*N*N + 8*N + 1, if JOB = 'X';\nC LDWORK >= max( 4*N*N + 8*N + 1, 6*N*N ), if JOB = 'A'.\nC For good performance, LDWORK should be larger, e.g.,\nC LDWORK >= 4*N*N + 6*N +( 2*N+1 )*NB, if JOB = 'X',\nC where NB is the optimal blocksize.\nC\nC If LDWORK = -1, then a workspace query is assumed;\nC the routine only calculates the optimal size of the\nC DWORK array, returns this value as the first entry of\nC the DWORK array, and no error message related to LDWORK\nC is issued by XERBLA.\nC\nC Error indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value;\nC = 1: the Hamiltonian matrix has eigenvalues on the\nC imaginary axis, so the solution and error bounds\nC could not be computed;\nC = 2: the iteration for the matrix sign function failed to\nC converge after 50 iterations, but an approximate\nC solution and error bounds (if JOB = 'A') have been\nC computed;\nC = 3: the system of linear equations for the solution is\nC singular to working precision, so the solution and\nC error bounds could not be computed;\nC = 4: the matrix A-G*X (or A-X*G) cannot be reduced to\nC Schur canonical form and condition number estimate\nC and forward error estimate have not been computed.\nC\nC METHOD\nC\nC The Riccati equation is solved by the matrix sign function\nC approach [1], [2], implementing a scaling which enhances the\nC numerical stability [4].\nC\nC REFERENCES\nC\nC [1] Bai, Z., Demmel, J., Dongarra, J., Petitet, A., Robinson, H.,\nC and Stanley, K.\nC The spectral decomposition of nonsymmetric matrices on\nC distributed memory parallel computers.\nC SIAM J. Sci. Comput., vol. 18, pp. 1446-1461, 1997.\nC\nC [2] Byers, R., He, C., and Mehrmann, V.\nC The matrix sign function method and the computation of\nC invariant subspaces.\nC SIAM J. Matrix Anal. Appl., vol. 18, pp. 615-632, 1997.\nC\nC [3] Higham, N.J.\nC Perturbation theory and backward error for AX-XB=C.\nC BIT, vol. 33, pp. 124-136, 1993.\nC\nC [4] Petkov, P.Hr., Konstantinov, M.M., and Mehrmann, V.,\nC DGRSVX and DMSRIC: Fortran 77 subroutines for solving\nC continuous-time matrix algebraic Riccati equations with\nC condition and accuracy estimates.\nC Preprint SFB393/98-16, Fak. f. Mathematik, Technical\nC University Chemnitz, May 1998.\nC\nC NUMERICAL ASPECTS\nC\nC The solution accuracy can be controlled by the output parameter\nC FERR.\nC\nC FURTHER COMMENTS\nC\nC The condition number of the Riccati equation is estimated as\nC\nC cond = ( norm(Theta)*norm(A) + norm(inv(Omega))*norm(Q) +\nC norm(Pi)*norm(G) ) / norm(X),\nC\nC where Omega, Theta and Pi are linear operators defined by\nC\nC Omega(W) = op(Ac)'*W + W*op(Ac),\nC Theta(W) = inv(Omega(op(W)'*X + X*op(W))),\nC Pi(W) = inv(Omega(X*W*X)),\nC\nC and the matrix Ac (the closed-loop system matrix) is given by\nC Ac = A - G*X, if TRANA = 'N', or\nC Ac = A - X*G, if TRANA = 'T' or 'C'.\nC\nC The program estimates the quantities\nC\nC sep(op(Ac),-op(Ac)') = 1 / norm(inv(Omega)),\nC\nC norm(Theta) and norm(Pi) using 1-norm condition estimator.\nC\nC The forward error bound is estimated using a practical error bound\nC similar to the one proposed in [3].\nC\nC CONTRIBUTOR\nC\nC P. Petkov, Tech. University of Sofia, March 2000.\nC\nC REVISIONS\nC\nC V. Sima, Katholieke Univ. Leuven, Belgium, June 2000; Aug. 2011.\nC\nC KEYWORDS\nC\nC Algebraic Riccati equation, continuous-time system,\nC optimal control, optimal regulator.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n INTEGER MAXIT\n PARAMETER ( MAXIT = 50 )\n DOUBLE PRECISION ZERO, HALF, ONE, TWO, TEN\n PARAMETER ( ZERO = 0.0D+0, HALF = 0.5D+0, ONE = 1.0D+0,\n $ TWO = 2.0D+0, TEN = 10.0D+0 )\nC ..\nC .. Scalar Arguments ..\n CHARACTER JOB, TRANA, UPLO\n INTEGER INFO, LDA, LDG, LDQ, LDWORK, LDX, N\n DOUBLE PRECISION FERR, RCOND\nC ..\nC .. Array Arguments ..\n INTEGER IWORK( * )\n DOUBLE PRECISION A( LDA, * ), DWORK( * ), G( LDG, * ),\n $ Q( LDQ, * ), WI( * ), WR( * ), X( LDX, * )\nC ..\nC .. Local Scalars ..\n LOGICAL ALL, LOWER, LQUERY, NOTRNA\n CHARACTER EQUED, LOUP\n INTEGER I, IAF, IB, IBR, IC, IFR, IJ, IJ1, IJ2, INFO2,\n $ INI, IR, ISCL, ISV, IT, ITAU, ITER, IU, IWRK,\n $ J, JI, LWAMAX, MINWRK, N2, SDIM\n DOUBLE PRECISION CONV, GNORM2, EPS, HNORM, HINNRM, QNORM2,\n $ SCALE, SEP, TEMP, TOL\nC ..\nC .. Local Arrays ..\n LOGICAL BWORK( 1 )\nC ..\nC .. External Functions ..\n LOGICAL LSAME, SELECT\n DOUBLE PRECISION DLAMCH, DLANSY\n EXTERNAL DLAMCH, DLANSY, LSAME, SELECT\nC ..\nC .. External Subroutines ..\n EXTERNAL DCOPY, DGEES, DGEQP3, DGESVX, DLACPY, DLASCL,\n $ DLASET, DORMQR, DSCAL, DSWAP, DSYMM, DSYTRF,\n $ DSYTRI, MA02AD, MA02ED, SB02QD, XERBLA\nC ..\nC .. Intrinsic Functions ..\n INTRINSIC DBLE, INT, MAX, SQRT\nC ..\nC .. Executable Statements ..\nC\nC Decode and Test input parameters.\nC\n ALL = LSAME( JOB, 'A' )\n NOTRNA = LSAME( TRANA, 'N' )\n LOWER = LSAME( UPLO, 'L' )\n LQUERY = LDWORK.EQ.-1\nC\n INFO = 0\n IF( .NOT.ALL .AND. .NOT.LSAME( JOB, 'X' ) ) THEN\n INFO = -1\n ELSE IF( .NOT.LSAME( TRANA, 'T' ) .AND.\n $ .NOT.LSAME( TRANA, 'C' ) .AND. .NOT.NOTRNA ) THEN\n INFO = -2\n ELSE IF( .NOT.LOWER .AND. .NOT.LSAME( UPLO, 'U' ) ) THEN\n INFO = -3\n ELSE IF( N.LT.0 ) THEN\n INFO = -4\n ELSE IF( LDA.LT.MAX( 1, N ) ) THEN\n INFO = -6\n ELSE IF( LDG.LT.MAX( 1, N ) ) THEN\n INFO = -8\n ELSE IF( LDQ.LT.MAX( 1, N ) ) THEN\n INFO = -10\n ELSE IF( LDX.LT.MAX( 1, N ) ) THEN\n INFO = -12\n ELSE\nC\nC Compute workspace.\nC\n N2 = 2*N\n IF( ALL ) THEN\n MINWRK = MAX( N2*N2 + 8*N + 1, 6*N*N )\n ELSE\n MINWRK = N2*N2 + 8*N + 1\n END IF\n ITAU = N2*N2\n IWRK = ITAU + N2\n IF ( LQUERY ) THEN\n CALL DSYTRF( UPLO, N2, DWORK, N2, IWORK, DWORK, -1, INFO2 )\n LWAMAX = INT( DWORK( 1 ) )\n CALL DGEQP3( N2, N2, DWORK, N2, IWORK, DWORK, DWORK, -1,\n $ INFO2 )\n LWAMAX = MAX( INT( DWORK( 1 ) ), LWAMAX )\n CALL DORMQR( 'L', 'N', N2, N, N, DWORK, N2, DWORK, DWORK,\n $ N2, DWORK, -1, INFO2 )\n LWAMAX = MAX( IWRK + MAX( INT( DWORK( 1 ) ), LWAMAX ),\n $ MINWRK )\n IF( ALL ) THEN\n CALL DGEES( 'V', 'N', SELECT, N, DWORK, N, SDIM, WR, WI,\n $ DWORK, N, DWORK, -1, BWORK, INFO2 )\n LWAMAX = MAX( N2*N + INT( DWORK( 1 ) ), LWAMAX )\n CALL SB02QD( 'B', 'F', TRANA, UPLO, 'O', N, A, LDA,\n $ DWORK, N, DWORK, N, G, LDG, Q, LDQ, X, LDX,\n $ SEP, RCOND, FERR, IWORK, DWORK, -1, INFO2 )\n LWAMAX = MAX( N2*N + INT( DWORK( 1 ) ), LWAMAX )\n END IF\n END IF\n IF( LDWORK.LT.MINWRK .AND. .NOT.LQUERY )\n $ INFO = -19\n END IF\nC\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'SB02PD', -INFO )\n RETURN\n ELSE IF( LQUERY ) THEN\n DWORK(1) = LWAMAX\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF( N.EQ.0 ) THEN\n IF( ALL ) THEN\n RCOND = ONE\n FERR = ZERO\n END IF\n DWORK(1) = ONE\n RETURN\n END IF\nC\nC Set tol.\nC\n EPS = DLAMCH( 'P' )\n TOL = TEN*DBLE( N )*EPS\nC\nC Compute the square-roots of the norms of the matrices Q and G .\nC\n QNORM2 = SQRT( DLANSY( '1', UPLO, N, Q, LDQ, DWORK ) )\n GNORM2 = SQRT( DLANSY( '1', UPLO, N, G, LDG, DWORK ) )\nC\nC Construct the lower (if UPLO = 'L') or upper (if UPLO = 'U')\nC triangle of the symmetric block-permuted Hamiltonian matrix.\nC During iteration, both the current iterate corresponding to the\nC Hamiltonian matrix, and its inverse are needed. To reduce the\nC workspace length, the transpose of the triangle specified by UPLO\nC of the current iterate H is saved in the opposite triangle,\nC suitably shifted with one column, and then the inverse of H\nC overwrites H. The triangles of the saved iterate and its inverse\nC are stored together in an 2*N-by-(2*N+1) matrix. For instance, if\nC UPLO = 'U', then the upper triangle is built starting from the\nC location 2*N+1 of the array DWORK, so that its transpose can be\nC stored in the lower triangle of DWORK.\nC Workspace: need 4*N*N, if UPLO = 'L';\nC 4*N*N + 2*N, if UPLO = 'U'.\nC\n IF ( LOWER ) THEN\n INI = 0\n ISV = N2\n LOUP = 'U'\nC\n DO 40 J = 1, N\n IJ = ( J - 1 )*N2 + J\nC\n DO 10 I = J, N\n DWORK(IJ) = -Q(I,J)\n IJ = IJ + 1\n 10 CONTINUE\nC\n IF( NOTRNA ) THEN\nC\n DO 20 I = 1, N\n DWORK( IJ ) = -A( I, J )\n IJ = IJ + 1\n 20 CONTINUE\nC\n ELSE\nC\n DO 30 I = 1, N\n DWORK( IJ ) = -A( J, I )\n IJ = IJ + 1\n 30 CONTINUE\nC\n END IF\n 40 CONTINUE\nC\n DO 60 J = 1, N\n IJ = ( N + J - 1 )*N2 + N + J\nC\n DO 50 I = J, N\n DWORK( IJ ) = G( I, J )\n IJ = IJ + 1\n 50 CONTINUE\nC\n 60 CONTINUE\nC\n ELSE\n INI = N2\n ISV = 0\n LOUP = 'L'\nC\n DO 80 J = 1, N\n IJ = J*N2 + 1\nC\n DO 70 I = 1, J\n DWORK(IJ) = -Q(I,J)\n IJ = IJ + 1\n 70 CONTINUE\nC\n 80 CONTINUE\nC\n DO 120 J = 1, N\n IJ = ( N + J )*N2 + 1\nC\n IF( NOTRNA ) THEN\nC\n DO 90 I = 1, N\n DWORK( IJ ) = -A( J, I )\n IJ = IJ + 1\n 90 CONTINUE\nC\n ELSE\nC\n DO 100 I = 1, N\n DWORK( IJ ) = -A( I, J )\n IJ = IJ + 1\n 100 CONTINUE\nC\n END IF\nC\n DO 110 I = 1, J\n DWORK( IJ ) = G( I, J )\n IJ = IJ + 1\n 110 CONTINUE\nC\n 120 CONTINUE\nC\n END IF\nC\nC Block-scaling.\nC\n ISCL = 0\n IF( QNORM2.GT.GNORM2 .AND. GNORM2.GT.ZERO ) THEN\n CALL DLASCL( UPLO, 0, 0, QNORM2, GNORM2, N, N, DWORK( INI+1 ),\n $ N2, INFO2 )\n CALL DLASCL( UPLO, 0, 0, GNORM2, QNORM2, N, N,\n $ DWORK( N2*N+N+INI+1 ), N2, INFO2 )\n ISCL = 1\n END IF\nC\nC Compute the matrix sign function.\nC\n DO 230 ITER = 1, MAXIT\nC\nC Save the transpose of the corresponding triangle of the\nC current iterate in the free locations of the shifted opposite\nC triangle.\nC Workspace: need 4*N*N + 2*N.\nC\n IF( LOWER ) THEN\nC\n DO 130 I = 1, N2\n CALL DCOPY( I, DWORK( I ), N2, DWORK( I*N2+1 ), 1 )\n 130 CONTINUE\nC\n ELSE\nC\n DO 140 I = 1, N2\n CALL DCOPY( I, DWORK( I*N2+1 ), 1, DWORK( I ), N2 )\n 140 CONTINUE\nC\n END IF\nC\nC Store the norm of the Hamiltonian matrix.\nC\n HNORM = DLANSY( 'F', UPLO, N2, DWORK( INI+1 ), N2, DWORK )\nC\nC Compute the inverse of the block-permuted Hamiltonian matrix.\nC Workspace: need 4*N*N + 2*N + 1;\nC prefer 4*N*N + 2*N + 2*N*NB.\nC\n CALL DSYTRF( UPLO, N2, DWORK( INI+1 ), N2, IWORK,\n $ DWORK( IWRK+1 ), LDWORK-IWRK, INFO2 )\n IF( INFO2.GT.0 ) THEN\n INFO = 1\n RETURN\n END IF\n LWAMAX = MAX( LWAMAX, IWRK + INT( DWORK( IWRK+1 ) ) )\nC\nC Workspace: need 4*N*N + 4*N.\nC\n CALL DSYTRI( UPLO, N2, DWORK( INI+1 ), N2, IWORK,\n $ DWORK( IWRK+1 ), INFO2 )\nC\nC Block-permutation of the inverse matrix.\nC\n IF( LOWER ) THEN\nC\n DO 160 J = 1, N\n IJ2 = ( N + J - 1 )*N2 + N + J\nC\n DO 150 IJ1 = ( J - 1 )*N2 + J, ( J - 1 )*N2 + N\n TEMP = DWORK( IJ1 )\n DWORK( IJ1 ) = -DWORK( IJ2 )\n DWORK( IJ2 ) = -TEMP\n IJ2 = IJ2 + 1\n 150 CONTINUE\nC\n CALL DSWAP( J-1, DWORK( N+J ), N2, DWORK( (J-1)*N2+N+1 ),\n $ 1 )\n 160 CONTINUE\nC\n ELSE\nC\n DO 180 J = 1, N\n IJ2 = ( N + J )*N2 + N + 1\nC\n DO 170 IJ1 = J*N2 + 1, J*N2 + J\n TEMP = DWORK( IJ1 )\n DWORK( IJ1 ) = -DWORK( IJ2 )\n DWORK( IJ2 ) = -TEMP\n IJ2 = IJ2 + 1\n 170 CONTINUE\nC\n CALL DSWAP( J-1, DWORK( (N+1)*N2+J ), N2,\n $ DWORK( (N+J)*N2+1 ), 1 )\n 180 CONTINUE\nC\n END IF\nC\nC Scale the Hamiltonian matrix and its inverse and compute\nC the next iterate.\nC\n HINNRM = DLANSY( 'F', UPLO, N2, DWORK( INI+1 ), N2, DWORK )\n SCALE = SQRT( HINNRM / HNORM )\nC\n IF( LOWER ) THEN\nC\n DO 200 J = 1, N2\n JI = ( J - 1 )*N2 + J\nC\n DO 190 IJ = JI, J*N2\n JI = JI + N2\n DWORK( IJ ) = ( DWORK( IJ ) / SCALE +\n $ DWORK( JI )*SCALE ) / TWO\n DWORK( JI ) = DWORK( JI ) - DWORK( IJ )\n 190 CONTINUE\nC\n 200 CONTINUE\nC\n ELSE\nC\n DO 220 J = 1, N2\n JI = J\nC\n DO 210 IJ = J*N2 + 1, J*N2 + J\n DWORK( IJ ) = ( DWORK( IJ ) / SCALE +\n $ DWORK( JI )*SCALE ) / TWO\n DWORK( JI ) = DWORK( JI ) - DWORK( IJ )\n JI = JI + N2\n 210 CONTINUE\nC\n 220 CONTINUE\nC\n END IF\nC\nC Test for convergence.\nC\n CONV = DLANSY( 'F', LOUP, N2, DWORK( ISV+1 ), N2, DWORK )\n IF( CONV.LE.TOL*HNORM ) GO TO 240\n 230 CONTINUE\nC\nC No convergence after MAXIT iterations, but an approximate solution\nC has been found.\nC\n INFO = 2\nC\n 240 CONTINUE\nC\nC If UPLO = 'U', shift the upper triangle one column to the left.\nC\n IF( .NOT.LOWER )\n $ CALL DLACPY( 'U', N2, N2, DWORK( INI+1 ), N2, DWORK, N2 )\nC\nC Divide the triangle elements by -2 and then fill-in the other\nC triangle by symmetry.\nC\n IF( LOWER ) THEN\nC\n DO 250 I = 1, N2\n CALL DSCAL( N2-I+1, -HALF, DWORK( (I-1)*N2+I ), 1 )\n 250 CONTINUE\nC\n ELSE\nC\n DO 260 I = 1, N2\n CALL DSCAL( I, -HALF, DWORK( (I-1)*N2+1 ), 1 )\n 260 CONTINUE\nC\n END IF\n CALL MA02ED( UPLO, N2, DWORK, N2 )\nC\nC Back block-permutation.\nC\n DO 280 J = 1, N2\nC\n DO 270 I = ( J - 1 )*N2 + 1, ( J - 1 )*N2 + N\n TEMP = DWORK( I )\n DWORK( I ) = -DWORK( I+N )\n DWORK( I+N ) = TEMP\n 270 CONTINUE\nC\n 280 CONTINUE\nC\nC Compute the QR decomposition of the projector onto the stable\nC invariant subspace.\nC Workspace: need 4*N*N + 8*N + 1.\nC prefer 4*N*N + 6*N + ( 2*N+1 )*NB.\nC\n DO 290 I = 1, N2\n IWORK( I ) = 0\n DWORK( ( I-1 )*N2 + I ) = DWORK( ( I-1 )*N2 + I ) + HALF\n 290 CONTINUE\nC\n CALL DGEQP3( N2, N2, DWORK, N2, IWORK, DWORK( ITAU+1 ),\n $ DWORK( IWRK+1 ), LDWORK-IWRK, INFO2 )\n LWAMAX = MAX( LWAMAX, IWRK + INT( DWORK( IWRK+1 ) ) )\nC\nC Accumulate the orthogonal transformations. Note that only the\nC first N columns of the array DWORK, returned by DGEQP3, are\nC needed, so that the last N columns of DWORK are used to get the\nC orthogonal basis for the stable invariant subspace.\nC Workspace: need 4*N*N + 3*N.\nC prefer 4*N*N + 2*N + N*NB.\nC\n IB = N*N\n IAF = N2*N\n CALL DLASET( 'F', N2, N, ZERO, ONE, DWORK( IAF+1 ), N2 )\n CALL DORMQR( 'L', 'N', N2, N, N, DWORK, N2, DWORK( ITAU+1 ),\n $ DWORK( IAF+1 ), N2, DWORK( IWRK+1 ), LDWORK-IWRK,\n $ INFO2 )\n LWAMAX = MAX( LWAMAX, IWRK + INT( DWORK( IWRK+1 ) ) )\nC\nC Store the matrices V11 and V21' .\nC\n CALL DLACPY( 'F', N, N, DWORK( IAF+1 ), N2, DWORK, N )\n CALL MA02AD( 'F', N, N, DWORK( IAF+N+1 ), N2, DWORK( IB+1 ), N )\nC\n IR = IAF + IB\n IC = IR + N\n IFR = IC + N\n IBR = IFR + N\n IWRK = IBR + N\nC\nC Compute the solution matrix X .\nC Workspace: need 3*N*N + 8*N.\nC\n CALL DGESVX( 'E', 'T', N, N, DWORK, N, DWORK( IAF+1 ), N,\n $ IWORK, EQUED, DWORK( IR+1 ), DWORK( IC+1 ),\n $ DWORK( IB+1 ), N, X, LDX, RCOND, DWORK( IFR+1 ),\n $ DWORK( IBR+1 ), DWORK( IWRK+1 ), IWORK( N+1 ),\n $ INFO2 )\n IF( INFO2.GT.0 ) THEN\n INFO = 3\n RETURN\n END IF\nC\nC Symmetrize the solution.\nC\n DO 310 I = 1, N - 1\nC\n DO 300 J = I + 1, N\n TEMP = ( X( I, J ) + X( J, I ) ) / TWO\n X( I, J ) = TEMP\n X( J, I ) = TEMP\n 300 CONTINUE\nC\n 310 CONTINUE\nC\nC Undo scaling for the solution matrix.\nC\n IF( ISCL.EQ.1 ) THEN\n CALL DLASCL( 'G', 0, 0, GNORM2, QNORM2, N, N, X, LDX, INFO2 )\n END IF\nC\n IF( ALL ) THEN\nC\nC Compute the estimates of the reciprocal condition number and\nC error bound.\nC Workspace usage.\nC\n IT = 0\n IU = IT + N*N\n IWRK = IU + N*N\nC\n CALL DLACPY( 'Full', N, N, A, LDA, DWORK( IT+1 ), N )\n IF( NOTRNA ) THEN\nC\nC Compute Ac = A-G*X .\nC\n CALL DSYMM( 'L', UPLO, N, N, -ONE, G, LDG, X, LDX, ONE,\n $ DWORK( IT+1 ), N )\n ELSE\nC\nC Compute Ac = A-X*G .\nC\n CALL DSYMM( 'R', UPLO, N, N, -ONE, G, LDG, X, LDX, ONE,\n $ DWORK( IT+1 ), N )\n END IF\nC\nC Compute the Schur factorization of Ac .\nC Workspace: need 2*N*N + 5*N;\nC prefer larger.\nC\n CALL DGEES( 'V', 'N', SELECT, N, DWORK( IT+1 ), N, SDIM, WR,\n $ WI, DWORK( IU+1 ), N, DWORK( IWRK+1 ), LDWORK-IWRK,\n $ BWORK, INFO2 )\n IF( INFO2.GT.0 ) THEN\n INFO = 4\n RETURN\n END IF\n LWAMAX = MAX( LWAMAX, IWRK + INT( DWORK( IWRK+1 ) ) )\nC\nC Estimate the reciprocal condition number and the forward error.\nC Workspace: need 6*N*N;\nC prefer larger.\nC\n CALL SB02QD( 'B', 'F', TRANA, UPLO, 'O', N, A, LDA,\n $ DWORK( IT+1 ), N, DWORK( IU+1 ), N, G, LDG, Q,\n $ LDQ, X, LDX, SEP, RCOND, FERR, IWORK,\n $ DWORK( IWRK+1 ), LDWORK-IWRK, INFO2 )\n LWAMAX = MAX( LWAMAX, IWRK + INT( DWORK( IWRK+1 ) ) )\n END IF\nC\n DWORK( 1 ) = DBLE( LWAMAX )\n RETURN\nC *** Last line of SB02PD\n END\n", "meta": {"hexsha": "1166b6251610e7c816f5bd3b940960de3dcb34ae", "size": 25020, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/SB02PD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/SB02PD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/SB02PD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 32.6205997392, "max_line_length": 72, "alphanum_fraction": 0.4994404476, "num_tokens": 8266, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9473810436809827, "lm_q2_score": 0.6992544085240401, "lm_q1q2_score": 0.6624603713460334}} {"text": "C A very simple implementation of a 2D wave equation solver,\nC aimed at testing high-performance computing techniques.\nC To make the code as simple as possible, the initial condition\nC is implemented in a rough way.\n\n\n PROGRAM wave2D\n INTEGER n, nsteps\n PARAMETER (n=501)\nC PARAMETER (n=101)\n\n REAL*8 up(n,n), u(n,n), um(n,n), lambda(n,n)\n REAL*8 dt, tstop, delta\nC domain has size 10x10 in x and y direction\nC delta is the cell size:\n delta = 10.0/(n-1)\n\n dt = SQRT(1.0/(1.0/(delta*delta) + 1.0/(delta*delta)))\nC dt = delta\n write(*,*) 'Give number of time steps:'\n read(*,*) nsteps\n tstop = nsteps*dt\n write(*,*) 'time step =',dt\n call timeloop(up, u, um, lambda, n, tstop, dt)\n\n END\n\n\nC function for coefficient in the wave equation (\"lambda\"):\n REAL*8 FUNCTION h(x, y)\n REAL*8 x,y\n h = 1.0\n RETURN\n END\n\nC initial surface shape:\n REAL*8 FUNCTION bell(x, y)\n REAL*8 x,y\n bell = exp(-x*x - y*y)\n RETURN\n END\n\n SUBROUTINE setIC(u, um, lambda, n)\nC set initial conditions (rough approximations)\nC set lambda values as well\n INTEGER n\n REAL*8 u(n,n), um(n,n), lambda(n,n)\n INTEGER i, j\n REAL*8 x, y, delta, bell, h\nC domain has size 10x10 in x and y direction\nC delta is the cell size:\n delta = 10.0/(n-1)\n \n DO 20 j=1,n\n DO 10 i=1,n\n x = (i-1)*delta\n y = (j-1)*delta\n u(i,j) = bell(x,y)\nC this is a rough approximation to du/dt=0:\n um(i,j) = u(i,j)\n\nC initialize the variable coefficient as an array:\n lambda(i,j) = h(x,y)\n 10 CONTINUE\n 20 CONTINUE\n RETURN\n END\n\n\n SUBROUTINE timeloop(up, u, um, lambda, n, tstop, dt)\n INTEGER n\n REAL*8 up(n,n), u(n,n), um(n,n), lambda(n,n)\n REAL*8 tstop, dt, t\n INTEGER nsteps, timelevel\n REAL*8 x, y, delta, bell, h, a, b, c\nC domain has size 10x10 in x and y direction\nC delta is the cell size:\n delta = 10.0/(n-1)\n nsteps = int(tstop/dt)\n\n t = 0\n call setIC(u, um, lambda, n)\n call dump(u, n, 0)\n a = 1.0\n b = 1.0\n c = 1.0\n\n DO 30 timelevel=1,nsteps\n t = t + dt\n write(*,*) 'time level', timelevel\n call F77WAVE(up, u, um, lambda, a, b, c, n, n, dt,\n & delta, delta)\nC update for next step:\n DO 20 j=1,n\n DO 10 i=1,n\n um(i,j) = u(i,j)\n u(i,j) = up(i,j)\n 10 CONTINUE\n 20 CONTINUE\n call dump(u, n, timelevel)\n 30 CONTINUE\n RETURN\n END\n\nC dump solution in plotmtv format:\n SUBROUTINE dump(u, n, timelevel)\n INTEGER n, i, j, timelevel, iunit\n REAL*8 u(n,n)\n CHARACTER*40 filename\n WRITE(filename,1000) 'tmp_',timelevel,'.mtv'\n 1000 FORMAT(A,I5.5,A)\n iunit = 20\n OPEN(iunit, FILE=filename, STATUS='UNKNOWN', FORM='FORMATTED')\n WRITE(iunit,*) '$ DATA=CONTOUR'\n WRITE(iunit,*) '% contstyle=2 nsteps=30 nx=',n,' ny=',n,\n & ' xmin=0 xmax=10 ymin=0 ymax=10' \n WRITE(iunit,*) '% cmin=-0.2 cmax=0.4 zmin=-0.2 zmax=0.6'\n WRITE(iunit,*) '% leftworld=False'\n WRITE(iunit,*) '% eyepos.x=0.5 eyepos.y=-1.5 eyepos.z=0.5'\n DO 20 j=1,n\n DO 10 i=1,n\n WRITE(iunit,*) u(i,j)\n 10 CONTINUE\n 20 CONTINUE\n CLOSE(iunit)\n RETURN\n END\n\n \n \n", "meta": {"hexsha": "f863e02e731d7c6e534e46a3dcdf043ef4d383be", "size": 3481, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "sandbox/src1/TCSE3-3rd-examples/src/app/wavesim2D/F77/versions/main_wIO.f", "max_stars_repo_name": "sniemi/SamPy", "max_stars_repo_head_hexsha": "e048756feca67197cf5f995afd7d75d8286e017b", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2016-05-28T14:12:28.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-22T10:23:12.000Z", "max_issues_repo_path": "sandbox/src1/TCSE3-3rd-examples/src/app/wavesim2D/F77/versions/main_wIO.f", "max_issues_repo_name": "sniemi/SamPy", "max_issues_repo_head_hexsha": "e048756feca67197cf5f995afd7d75d8286e017b", "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": "sandbox/src1/TCSE3-3rd-examples/src/app/wavesim2D/F77/versions/main_wIO.f", "max_forks_repo_name": "sniemi/SamPy", "max_forks_repo_head_hexsha": "e048756feca67197cf5f995afd7d75d8286e017b", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2015-07-13T10:04:10.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-22T10:23:23.000Z", "avg_line_length": 26.572519084, "max_line_length": 68, "alphanum_fraction": 0.5351910371, "num_tokens": 1147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818409, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6624203823368889}} {"text": " Program fpgrid\n\nc Creates a grid for a laminar boundary layer on a flat plate.\n\n parameter ( nimax = 200 )\n parameter ( njmax = 100 )\n\n dimension x (nimax,njmax)\n dimension y (nimax,njmax)\n\n dimension eta (njmax)\n\nc.....Get grid parameters.\n\n fplen = 1.0\n xin = - 0.25\n\n write(*,*) ' '\n write(*,*) 'Enter axial grid spacing (ft)' !0.025\n read(*,*) spax\n\n write(*,*) ' '\n write(*,*) 'Enter wall spacing (in terms of eta)' !0.4\n read (*,*) spwall\n\nc.....Create an evenly-spaced axial grid.\n\n nia = 0.25 / spax + 1 \n nib = 4 * nia - 3\n ni = nia + nib - 1 \n\n write(*,*) ' '\n write(*,*) 'Number of axial grid points: ', ni\n write(*,*) 'Leading edge is at i = ', nia\n\n x(1,1) = xin\n do i = 2, nia\n x(i,1) = x(i-1,1) + spax\n enddo\n x(nia,1) = 0.0\n\n do i = 2, nib\n ix = nia + i - 1\n x(ix,1) = x(ix-1,1) + spax\n enddo\n x(ni,1) = fplen\n\n do i = 1, ni\n write(*,*) i, x(i,1)\n enddo\n\nc.....Create the eta distribution.\n\n eta(1) = 0.0\n ibl = 0\n\n do j = 2, njmax\n if ( ibl .eq. 0 ) then\n eta(j) = eta(j-1) + spwall\n if ( eta(j) .ge. 4.0 ) ibl = 1 \n else\n eta(j) = eta(j-1) + 1.1 * ( eta(j-1) - eta(j-2) )\n endif\n if ( eta(j) .gt. 50 ) go to 10\n enddo\n\n write(*,*) ' '\n write(*,*) 'Warning: njmax reached'\n\n 10 continue\n\n nj = j\n\n write(*,*) ' '\n write(*,*) 'Number of wall normal grid points: ', nj\n\n do j = 1, nj\n write(*,*) j, eta(j)\n enddo\n\nc.....Create the x-coordinates for entire grid.\n\n do i = 1, ni\n do j = 2, nj\n x(i,j) = x(i,1)\n enddo\n enddo\n\nc.....Create the y grid coordinates starting at about x = 0.25.\n\n istart = ni * 2 / 5 + 1 \n\n ufs = 129.6974\n dynvis = 6.4849819E-04\n\n do i = istart, ni\n do j = 1, nj\n y(i,j) = eta(j) / sqrt( 0.5 * ufs / ( dynvis * x(i,j) ) )\n enddo\n enddo\n\nc.....For i = 1, istart-1, use the y-coordinates at istart.\n\n do i = 1, istart\n do j = 1, nj\n y(i,j) = y(istart,j)\n enddo\n enddo\n\nc.....Write out the grid to a Plot3d file.\n\nc.....open ( unit=7, file='fplam.d', form='formatted', status='unknown' )\n open ( unit=7, file='fplam.txt', form='formatted' )\n write(7, *) ni, nj\n write(7, *) (( x(i,j), i=1,ni), j=1,nj),\n & (( y(i,j), i=1,ni), j=1,nj)\n\n stop\n end\n", "meta": {"hexsha": "8d3a95759267dc69c4924c06f9415d2325fd969e", "size": 2554, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "examples/mesh_generator/nasa_plate/fpgrid.f", "max_stars_repo_name": "SangVn/VnCFD_2.21.5", "max_stars_repo_head_hexsha": "dc1c604e2e2121e57b2af4af235965ce27af1d57", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-01-23T21:45:46.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-03T23:44:18.000Z", "max_issues_repo_path": "examples/mesh_generator/nasa_plate/fpgrid.f", "max_issues_repo_name": "SangVn/VnCFD_2.21.5", "max_issues_repo_head_hexsha": "dc1c604e2e2121e57b2af4af235965ce27af1d57", "max_issues_repo_licenses": ["MIT"], "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/mesh_generator/nasa_plate/fpgrid.f", "max_forks_repo_name": "SangVn/VnCFD_2.21.5", "max_forks_repo_head_hexsha": "dc1c604e2e2121e57b2af4af235965ce27af1d57", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-01-23T21:46:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-23T21:46:04.000Z", "avg_line_length": 21.2833333333, "max_line_length": 73, "alphanum_fraction": 0.4541895067, "num_tokens": 945, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767938900121, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6624203774977406}} {"text": "*DECK DGBCO\n SUBROUTINE DGBCO (ABD, LDA, N, ML, MU, IPVT, RCOND, Z)\nC***BEGIN PROLOGUE DGBCO\nC***PURPOSE Factor a band matrix by Gaussian elimination and\nC estimate the condition number of the matrix.\nC***LIBRARY SLATEC (LINPACK)\nC***CATEGORY D2A2\nC***TYPE DOUBLE PRECISION (SGBCO-S, DGBCO-D, CGBCO-C)\nC***KEYWORDS BANDED, CONDITION NUMBER, LINEAR ALGEBRA, LINPACK,\nC MATRIX FACTORIZATION\nC***AUTHOR Moler, C. B., (U. of New Mexico)\nC***DESCRIPTION\nC\nC DGBCO factors a double precision band matrix by Gaussian\nC elimination and estimates the condition of the matrix.\nC\nC If RCOND is not needed, DGBFA is slightly faster.\nC To solve A*X = B , follow DGBCO by DGBSL.\nC To compute INVERSE(A)*C , follow DGBCO by DGBSL.\nC To compute DETERMINANT(A) , follow DGBCO by DGBDI.\nC\nC On Entry\nC\nC ABD DOUBLE PRECISION(LDA, N)\nC contains the matrix in band storage. The columns\nC of the matrix are stored in the columns of ABD and\nC the diagonals of the matrix are stored in rows\nC ML+1 through 2*ML+MU+1 of ABD .\nC See the comments below for details.\nC\nC LDA INTEGER\nC the leading dimension of the array ABD .\nC LDA must be .GE. 2*ML + MU + 1 .\nC\nC N INTEGER\nC the order of the original matrix.\nC\nC ML INTEGER\nC number of diagonals below the main diagonal.\nC 0 .LE. ML .LT. N .\nC\nC MU INTEGER\nC number of diagonals above the main diagonal.\nC 0 .LE. MU .LT. N .\nC More efficient if ML .LE. MU .\nC\nC On Return\nC\nC ABD an upper triangular matrix in band storage and\nC the multipliers which were used to obtain it.\nC The factorization can be written A = L*U where\nC L is a product of permutation and unit lower\nC triangular matrices and U is upper triangular.\nC\nC IPVT INTEGER(N)\nC an integer vector of pivot indices.\nC\nC RCOND DOUBLE PRECISION\nC an estimate of the reciprocal condition of A .\nC For the system A*X = B , relative perturbations\nC in A and B of size EPSILON may cause\nC relative perturbations in X of size EPSILON/RCOND .\nC If RCOND is so small that the logical expression\nC 1.0 + RCOND .EQ. 1.0\nC is true, then A may be singular to working\nC precision. In particular, RCOND is zero if\nC exact singularity is detected or the estimate\nC underflows.\nC\nC Z DOUBLE PRECISION(N)\nC a work vector whose contents are usually unimportant.\nC If A is close to a singular matrix, then Z is\nC an approximate null vector in the sense that\nC NORM(A*Z) = RCOND*NORM(A)*NORM(Z) .\nC\nC Band Storage\nC\nC If A is a band matrix, the following program segment\nC will set up the input.\nC\nC ML = (band width below the diagonal)\nC MU = (band width above the diagonal)\nC M = ML + MU + 1\nC DO 20 J = 1, N\nC I1 = MAX(1, J-MU)\nC I2 = MIN(N, J+ML)\nC DO 10 I = I1, I2\nC K = I - J + M\nC ABD(K,J) = A(I,J)\nC 10 CONTINUE\nC 20 CONTINUE\nC\nC This uses rows ML+1 through 2*ML+MU+1 of ABD .\nC In addition, the first ML rows in ABD are used for\nC elements generated during the triangularization.\nC The total number of rows needed in ABD is 2*ML+MU+1 .\nC The ML+MU by ML+MU upper left triangle and the\nC ML by ML lower right triangle are not referenced.\nC\nC Example: If the original matrix is\nC\nC 11 12 13 0 0 0\nC 21 22 23 24 0 0\nC 0 32 33 34 35 0\nC 0 0 43 44 45 46\nC 0 0 0 54 55 56\nC 0 0 0 0 65 66\nC\nC then N = 6, ML = 1, MU = 2, LDA .GE. 5 and ABD should contain\nC\nC * * * + + + , * = not used\nC * * 13 24 35 46 , + = used for pivoting\nC * 12 23 34 45 56\nC 11 22 33 44 55 66\nC 21 32 43 54 65 *\nC\nC***REFERENCES J. J. Dongarra, J. R. Bunch, C. B. Moler, and G. W.\nC Stewart, LINPACK Users' Guide, SIAM, 1979.\nC***ROUTINES CALLED DASUM, DAXPY, DDOT, DGBFA, DSCAL\nC***REVISION HISTORY (YYMMDD)\nC 780814 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890831 Modified array declarations. (WRB)\nC 890831 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900326 Removed duplicate information from DESCRIPTION section.\nC (WRB)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE DGBCO\n INTEGER LDA,N,ML,MU,IPVT(*)\n DOUBLE PRECISION ABD(LDA,*),Z(*)\n DOUBLE PRECISION RCOND\nC\n DOUBLE PRECISION DDOT,EK,T,WK,WKM\n DOUBLE PRECISION ANORM,S,DASUM,SM,YNORM\n INTEGER IS,INFO,J,JU,K,KB,KP1,L,LA,LM,LZ,M,MM\nC\nC COMPUTE 1-NORM OF A\nC\nC***FIRST EXECUTABLE STATEMENT DGBCO\n ANORM = 0.0D0\n L = ML + 1\n IS = L + MU\n DO 10 J = 1, N\n ANORM = MAX(ANORM,DASUM(L,ABD(IS,J),1))\n IF (IS .GT. ML + 1) IS = IS - 1\n IF (J .LE. MU) L = L + 1\n IF (J .GE. N - ML) L = L - 1\n 10 CONTINUE\nC\nC FACTOR\nC\n CALL DGBFA(ABD,LDA,N,ML,MU,IPVT,INFO)\nC\nC RCOND = 1/(NORM(A)*(ESTIMATE OF NORM(INVERSE(A)))) .\nC ESTIMATE = NORM(Z)/NORM(Y) WHERE A*Z = Y AND TRANS(A)*Y = E .\nC TRANS(A) IS THE TRANSPOSE OF A . THE COMPONENTS OF E ARE\nC CHOSEN TO CAUSE MAXIMUM LOCAL GROWTH IN THE ELEMENTS OF W WHERE\nC TRANS(U)*W = E . THE VECTORS ARE FREQUENTLY RESCALED TO AVOID\nC OVERFLOW.\nC\nC SOLVE TRANS(U)*W = E\nC\n EK = 1.0D0\n DO 20 J = 1, N\n Z(J) = 0.0D0\n 20 CONTINUE\n M = ML + MU + 1\n JU = 0\n DO 100 K = 1, N\n IF (Z(K) .NE. 0.0D0) EK = SIGN(EK,-Z(K))\n IF (ABS(EK-Z(K)) .LE. ABS(ABD(M,K))) GO TO 30\n S = ABS(ABD(M,K))/ABS(EK-Z(K))\n CALL DSCAL(N,S,Z,1)\n EK = S*EK\n 30 CONTINUE\n WK = EK - Z(K)\n WKM = -EK - Z(K)\n S = ABS(WK)\n SM = ABS(WKM)\n IF (ABD(M,K) .EQ. 0.0D0) GO TO 40\n WK = WK/ABD(M,K)\n WKM = WKM/ABD(M,K)\n GO TO 50\n 40 CONTINUE\n WK = 1.0D0\n WKM = 1.0D0\n 50 CONTINUE\n KP1 = K + 1\n JU = MIN(MAX(JU,MU+IPVT(K)),N)\n MM = M\n IF (KP1 .GT. JU) GO TO 90\n DO 60 J = KP1, JU\n MM = MM - 1\n SM = SM + ABS(Z(J)+WKM*ABD(MM,J))\n Z(J) = Z(J) + WK*ABD(MM,J)\n S = S + ABS(Z(J))\n 60 CONTINUE\n IF (S .GE. SM) GO TO 80\n T = WKM - WK\n WK = WKM\n MM = M\n DO 70 J = KP1, JU\n MM = MM - 1\n Z(J) = Z(J) + T*ABD(MM,J)\n 70 CONTINUE\n 80 CONTINUE\n 90 CONTINUE\n Z(K) = WK\n 100 CONTINUE\n S = 1.0D0/DASUM(N,Z,1)\n CALL DSCAL(N,S,Z,1)\nC\nC SOLVE TRANS(L)*Y = W\nC\n DO 120 KB = 1, N\n K = N + 1 - KB\n LM = MIN(ML,N-K)\n IF (K .LT. N) Z(K) = Z(K) + DDOT(LM,ABD(M+1,K),1,Z(K+1),1)\n IF (ABS(Z(K)) .LE. 1.0D0) GO TO 110\n S = 1.0D0/ABS(Z(K))\n CALL DSCAL(N,S,Z,1)\n 110 CONTINUE\n L = IPVT(K)\n T = Z(L)\n Z(L) = Z(K)\n Z(K) = T\n 120 CONTINUE\n S = 1.0D0/DASUM(N,Z,1)\n CALL DSCAL(N,S,Z,1)\nC\n YNORM = 1.0D0\nC\nC SOLVE L*V = Y\nC\n DO 140 K = 1, N\n L = IPVT(K)\n T = Z(L)\n Z(L) = Z(K)\n Z(K) = T\n LM = MIN(ML,N-K)\n IF (K .LT. N) CALL DAXPY(LM,T,ABD(M+1,K),1,Z(K+1),1)\n IF (ABS(Z(K)) .LE. 1.0D0) GO TO 130\n S = 1.0D0/ABS(Z(K))\n CALL DSCAL(N,S,Z,1)\n YNORM = S*YNORM\n 130 CONTINUE\n 140 CONTINUE\n S = 1.0D0/DASUM(N,Z,1)\n CALL DSCAL(N,S,Z,1)\n YNORM = S*YNORM\nC\nC SOLVE U*Z = W\nC\n DO 160 KB = 1, N\n K = N + 1 - KB\n IF (ABS(Z(K)) .LE. ABS(ABD(M,K))) GO TO 150\n S = ABS(ABD(M,K))/ABS(Z(K))\n CALL DSCAL(N,S,Z,1)\n YNORM = S*YNORM\n 150 CONTINUE\n IF (ABD(M,K) .NE. 0.0D0) Z(K) = Z(K)/ABD(M,K)\n IF (ABD(M,K) .EQ. 0.0D0) Z(K) = 1.0D0\n LM = MIN(K,M) - 1\n LA = M - LM\n LZ = K - LM\n T = -Z(K)\n CALL DAXPY(LM,T,ABD(LA,K),1,Z(LZ),1)\n 160 CONTINUE\nC MAKE ZNORM = 1.0\n S = 1.0D0/DASUM(N,Z,1)\n CALL DSCAL(N,S,Z,1)\n YNORM = S*YNORM\nC\n IF (ANORM .NE. 0.0D0) RCOND = YNORM/ANORM\n IF (ANORM .EQ. 0.0D0) RCOND = 0.0D0\n RETURN\n END\n", "meta": {"hexsha": "2a5efd4d9d2e3da7298f68024bbe7631e49b59d5", "size": 9128, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/dgbco.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/dgbco.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/dgbco.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.7168458781, "max_line_length": 71, "alphanum_fraction": 0.500219106, "num_tokens": 3226, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767906859264, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6624203750789284}} {"text": "! =====================================================\nsubroutine rpn2(ixy,maxm,meqn,mwaves,maux,mbc,mx,ql,qr,auxl,auxr,wave,s,amdq,apdq)\n! =====================================================\n\n! Aproximate Riemann solver for the nonlinear KPP system:\n\n! q_t + sin(q)_x + cos(q)_y = 0\n\n! waves: 1\n! equations: 1\n\n! Conserved quantities:\n! 1 q\n\n! Solve Riemann problems along one slice of data:\n! in the x-direction if ixy=1\n! in the y-direction if ixy=2.\n\n! On input, ql contains the state vector at the left edge of each cell\n! qr contains the state vector at the right edge of each cell\n\n! On output, wave contains the waves,\n! s the speeds,\n! amdq the left-going fluctuation\n! apdq the right-going fluctuation\n\n! Note that the i'th Riemann problem has left state qr(i-1,:)\n! and right state ql(i,:)\n! From the basic clawpack routines, this routine is called with ql = qr\n\n! implicit none\n\n double precision :: ul, ur, fl, fr, fedge, pi, reml, remr\n integer :: i, ixy, maxm, meqn, mwaves, mbc, mx\n\n double precision :: wave(meqn,mwaves,1-mbc:maxm+mbc)\n double precision :: s(mwaves, 1-mbc:maxm+mbc)\n double precision :: ql(meqn, 1-mbc:maxm+mbc)\n double precision :: qr(meqn, 1-mbc:maxm+mbc)\n double precision :: apdq(meqn, 1-mbc:maxm+mbc)\n double precision :: amdq(meqn, 1-mbc:maxm+mbc)\n\n\n pi=4.d0*datan(1.d0)\n\n do i=2-mbc,mx+mbc\n\n ul = qr(1,i-1)\n ur = ql(1,i )\n\n if (ixy == 1) then\n fl = dsin(ul)\n fr = dsin(ur)\n\n ! The flux fedge at the cell interface is obtained by\n ! minimizing or maximizing the function sin(q) over the\n ! interval between the left and right states.\n\n if (ul < ur) then\n ! inimum\n fedge = dmin1(fl,fr)\n if (ur-ul > 2.d0*pi) then\n fedge=-1.d0\n else\n reml = dmod(ul,2.d0*pi)\n remr = dmod(ur,2.d0*pi)\n if (remr > 1.5d0*pi .AND. reml < 1.5d0*pi) then\n fedge=-1.d0\n elseif (ur-ul > remr+0.5d0*pi) then\n fedge=-1.d0\n endif\n endif\n else\n ! aximum\n fedge = dmax1(fl,fr)\n if (ul-ur > 2.d0*pi) then\n fedge=1.d0\n else\n reml = dmod(ul,2.d0*pi)\n remr = dmod(ur,2.d0*pi)\n if (reml > 0.5d0*pi .AND. remr < 0.5d0*pi) then\n fedge=1.d0\n elseif (ul-ur > reml+1.5d0*pi) then\n fedge=1.d0\n endif\n endif\n endif\n else ! ixy == 2\n fl = dcos(ul)\n fr = dcos(ur)\n\n ! The flux fedge at the cell interface is obtained by\n ! minimizing or maximizing the function cos(q) over the\n ! interval between the left and right states.\n\n if (ul < ur) then\n ! inimum\n fedge = dmin1(fl,fr)\n if (ur-ul > 2.d0*pi) then\n fedge=-1.d0\n else\n reml = dmod(ul,2.d0*pi)\n remr = dmod(ur,2.d0*pi)\n if (remr > 1.d0*pi .AND. reml < 1.d0*pi) then\n fedge=-1.d0\n elseif (ur-ul > remr+1.d0*pi) then\n fedge=-1.d0\n endif\n endif\n else\n ! aximum\n fedge = dmax1(fl,fr)\n if (ul-ur > 2.d0*pi) then\n fedge=1.d0\n else\n reml = dmod(ul,2.d0*pi)\n remr = dmod(ur,2.d0*pi)\n if (reml < remr) then\n fedge=1.d0\n endif\n endif\n endif\n endif\n\n\n if (ul /= ur) then\n ! ecant approximation\n s(1,i) = (fr-fl)/(ur-ul)\n else\n s(1,i) = 0.d0\n endif\n\n wave(1,1,i) = ur-ul\n\n amdq(1,i)= fedge - fl\n apdq(1,i)= fr - fedge\n\n enddo\n \n return\n end subroutine rpn2\n", "meta": {"hexsha": "8cb8bcbae733b831b18e6fdd87b2698cbbabe220", "size": 4311, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/rpn2_kpp.f90", "max_stars_repo_name": "ranocha/riemann", "max_stars_repo_head_hexsha": "d7b4d72d1147eee12e60a64f46a7e076b28a212d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 27, "max_stars_repo_stars_event_min_datetime": "2015-03-08T03:42:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-21T01:46:12.000Z", "max_issues_repo_path": "src/rpn2_kpp.f90", "max_issues_repo_name": "ranocha/riemann", "max_issues_repo_head_hexsha": "d7b4d72d1147eee12e60a64f46a7e076b28a212d", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 47, "max_issues_repo_issues_event_min_datetime": "2015-02-11T15:39:22.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-25T01:56:46.000Z", "max_forks_repo_path": "src/rpn2_kpp.f90", "max_forks_repo_name": "ranocha/riemann", "max_forks_repo_head_hexsha": "d7b4d72d1147eee12e60a64f46a7e076b28a212d", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 37, "max_forks_repo_forks_event_min_datetime": "2015-01-09T21:44:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-21T12:53:04.000Z", "avg_line_length": 30.3591549296, "max_line_length": 82, "alphanum_fraction": 0.4428206913, "num_tokens": 1230, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.7279754548076477, "lm_q1q2_score": 0.6623899701102213}} {"text": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\ncc cc\ncc mncurf : curfit test program cc\ncc cc\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\n real x(25),y(25),w(25),t(35),c(35),wrk(1000),sp(25)\n integer iwrk(35)\n real ai,fp,s,xb,xe\n integer i,ier,iopt,is,j,k,l,lwrk,l1,l2,m,n,nest,nk1\nc the ordinate values of the data points\n data y(1),y(2),y(3),y(4),y(5),y(6),y(7),y(8),y(9),y(10),y(11),\n * y(12),y(13),y(14),y(15),y(16),y(17),y(18),y(19),y(20),y(21),\n * y(22),y(23),y(24),y(25)/1.0,1.0,1.4,1.1,1.0,1.0,4.0,9.0,13.0,\n * 13.4,12.8,13.1,13.0,14.0,13.0,13.5,10.0,2.0,3.0,2.5,2.5,2.5,\n * 3.0,4.0,3.5/\nc m denotes the number of data points\n m = 25\nc we set up the abscissae and weights of the data points\n do 10 i=1,m\n ai = i-1\n x(i) = ai\n w(i) = 1.0\n 10 continue\nc we set up the boundaries of the approximation interval\n xb = x(1)\n xe = x(m)\nc we set up the dimension information.\n nest = 35\n lwrk = 1000\nc loop for the different spline degrees.\n do 400 k=3,5,2\nc loop for the different spline approximations of degree k\n do 300 is=1,7\n go to (110,120,130,140,150,160,170),is\nc we start computing the least-squares polynomial (large value for s).\n 110 iopt = 0\n s = 1000.\n go to 200\nc iopt=1 from the second call on\n 120 iopt = 1\n s = 60.\n go to 200\nc a smaller value for s to get a closer approximation\n 130 s = 10.\n go to 200\nc a larger value for s to get a smoother approximation\n 140 s = 30.\n go to 200\nc if a satisfactory fit is obtained we can calculate a spline of equal\nc quality of fit ( same value for s ) but possibly with fewer knots by\nc specifying iopt=0\n 150 s = 30.\n iopt = 0\n go to 200\nc we calculate an interpolating spline\n 160 s = 0.\n go to 200\nc finally, we also calculate a least-squares spline function with\nc specified knots\n 170 iopt = -1\n j = k+2\n do 180 l=1,7\n ai =3*l\n t(j) = ai\n j = j+1\n 180 continue\n n = 9+2*k\n 200 call curfit(iopt,m,x,y,w,xb,xe,k,s,nest,n,t,c,fp,wrk,lwrk,\n * iwrk,ier)\nc printing of the results.\n if(iopt.ge.0) go to 210\n write(6,910) k\n go to 220\n 210 write(6,915) k\n write(6,920) s\n 220 write(6,925) fp,ier\n write(6,930) n\n write(6,935)\n write(6,940) (t(i),i=1,n)\n nk1 = n-k-1\n write(6,945)\n write(6,950) (c(i),i=1,nk1)\n write(6,955)\nc evaluation of the spline approximation\n call splev(t,n,c,k,x,sp,m,ier)\n do 230 i=1,5\n l1 = (i-1)*5+1\n l2 = l1+4\n write(6,960) (x(l),y(l),sp(l),l=l1,l2)\n 230 continue\n 300 continue\n 400 continue\n stop\n 910 format(32h0least-squares spline of degree ,i1)\n 915 format(28h0smoothing spline of degree ,i1)\n 920 format(20h smoothing factor s=,f5.0)\n 925 format(1x,23hsum squared residuals =,e15.6,5x,11herror flag=,i2)\n 930 format(1x,24htotal number of knots n=,i3)\n 935 format(1x,22hposition of the knots )\n 940 format(5x,12f6.1)\n 945 format(23h0b-spline coefficients )\n 950 format(5x,8f9.4)\n 955 format(1h0,5(1x,2hxi,3x,2hyi,2x,5hs(xi),1x))\n 960 format(1h ,5(f4.1,1x,f4.1,1x,f4.1,2x))\n end\n", "meta": {"hexsha": "038be525b132047b40aa94fd031001dc1b2f2cda", "size": 3714, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ApproxSpline/Resources/F77-Sources/ex/mncurf.f", "max_stars_repo_name": "modelica-3rdparty/ApproxSpline", "max_stars_repo_head_hexsha": "28420f5c1a88c9cd069defbd8c05e4a78a090675", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-07-13T17:24:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-18T16:16:02.000Z", "max_issues_repo_path": "ApproxSpline/Resources/F77-Sources/ex/mncurf.f", "max_issues_repo_name": "tbeu/ApproxSpline", "max_issues_repo_head_hexsha": "28420f5c1a88c9cd069defbd8c05e4a78a090675", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-03-28T09:08:23.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T07:35:48.000Z", "max_forks_repo_path": "ApproxSpline/Resources/F77-Sources/ex/mncurf.f", "max_forks_repo_name": "modelica-3rdparty/ApproxSpline", "max_forks_repo_head_hexsha": "28420f5c1a88c9cd069defbd8c05e4a78a090675", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-10-21T07:46:49.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T20:02:06.000Z", "avg_line_length": 35.0377358491, "max_line_length": 72, "alphanum_fraction": 0.5409262251, "num_tokens": 1344, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070035949657, "lm_q2_score": 0.7279754548076477, "lm_q1q2_score": 0.662389964774709}} {"text": "\tsubroutine sub_expav2l(time_const1,time_const2,srate,isize,\n $ rarray,outmax)\n\nc sub_expav2 without the output array\n\nc Based on graf::dkb0:[sullivan.boom3]expav2c.pro - July 20 1994\nc\nc; 2-time-constant exponential average - Averaging pressure of A-weighted boom?!\nc; one (time_const1) for rising signals, another (time_const2) for decaying.\nc; Version 3 = Feb 1 1994\nc; Method courtesy of B&K - 2131 Instruction Manual - but they only have one!\nc;\nc input variables\nc time_const1 = time constant for averaging increasing (abs.) signals\nc time_const2 = time constant for averaging decaying (abs.) signals\nc srate = sample rate of signal array\nc make sure these three are in the same units!\nc isize = number of points in input array\nc rarray = signal array\nc output variables\nc outmax = maximum value\nc\n\treal rarray(1),output(2),konstant1,konstant2,normf,normf2,\n $ outmax\nc\nc;time interval between samples is 1/srate (eg 0.000026 secs = .026 msecs)\n\ttinterval = 1./srate\nc\nc;time constant = Konstant * tinterval (according to B&K) (eg 2 msec)\nc; = Konstant / srate\nc; Konstant = time constant * srate = time constant / tinterval\nc; ~= number of samples per Averaging Time\nc\n\tkonstant1 = time_const1/tinterval\n\tkonstant2 = time_const2/tinterval\nc;\nc; apparently I need some kind of normalization factor - squared or not?\nc\tnormf = max(abs(rarray))\n\tnormf = abs(rarray(1))\n\tdo i=2,isize\n\t normf = max(normf,rarray(i))\n\tenddo\n\tnormf2 = normf*normf\nc\tarray = rarray**2/normf2\n\nc;present average=previous average+(\"volts squared\"-previous average)/Konstant \nc\toutput(1) = array(1)**2/konstant1\n\toutput(1) = (rarray(1)**2/normf2)/konstant1\n\toutmax = output(1)\n\tdo i=2,isize\n valnow=rarray(i)**2/normf2\n\t if (valnow .gt. output(1)) then\n\t output(2) = output(1) + (valnow - output(1))/konstant1\n\t else\n\t output(2) = output(1) + (valnow - output(1))/konstant2\n\t endif\n\t outmax = max(outmax,output(2))\n\t output(1) = output(2)\n\tenddo\n\n\toutmax = outmax*normf2\n\n\treturn\n\tend\n", "meta": {"hexsha": "b5c0e9ccd9bd9651f1d79013067ad3091498a126", "size": 2131, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "sub_expav2l.f", "max_stars_repo_name": "mandalin/DissertationPostProcessing", "max_stars_repo_head_hexsha": "e80f82c7966b00ca9cab898f708a6b82077e61af", "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": "sub_expav2l.f", "max_issues_repo_name": "mandalin/DissertationPostProcessing", "max_issues_repo_head_hexsha": "e80f82c7966b00ca9cab898f708a6b82077e61af", "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": "sub_expav2l.f", "max_forks_repo_name": "mandalin/DissertationPostProcessing", "max_forks_repo_head_hexsha": "e80f82c7966b00ca9cab898f708a6b82077e61af", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.7846153846, "max_line_length": 80, "alphanum_fraction": 0.6766776161, "num_tokens": 664, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070035949657, "lm_q2_score": 0.7279754548076477, "lm_q1q2_score": 0.662389964774709}} {"text": " subroutine axafs(em, emu, xsec,ne1,ik0)\nc extract axafs from xsec\nc written by a.l.ankudinov Dec. 1998\n\nc the file axafs.dat (format as in xmu.dat) will be written if\nc you use PRINT 0 1 0 0 0 0 (ipr2 > 0), and ran the second module.\n\nc the code draws a parabola using least mean square method\nc through xsec(i) * ee (i)**xn \nc the weight for each point i, is defined as (ee(i)-E_F)**mm*\nc (ee(i+1)- ee(i-1)), where the last multiplier is used since the \nc grid is not regular in energy.\nc E_F - energy that corresponds to Fermi level.\n\n implicit double precision (a-h, o-z)\n include '../HEADERS/dim.h'\n include '../HEADERS/const.h'\n\n complex*16 em(nex), xsec(nex)\n dimension ee(nex), xmu(nex), wt(nex)\n dimension xx(0:4), yy(0:2), xm(3,3)\n\nc empirically I found that the best curve is drawn if xn=0 and mm=1\nc alex ankudinov, january 1999.\n xn = 0\n mm = 1\n np = ne1 - ik0\n ef = emu\n\n do 10 ie = 1, np\n ee(ie) = dble(em(ik0+ie)-em(ik0)) +emu\n xmu(ie) = dimag(xsec(ik0+ie)) * ee(ie)**xn\n 10 continue\n do 20 ie = 1, np\n if (ie.eq.1) then\n wt(ie) = (ee(ie+1)-ef) * (abs(ee(ie)-ef))**mm\n elseif (ie.eq.np) then\n wt(ie) = (ee(ie)-ee(ie-1)) * (ee(ie)-ef)**mm\n else\n wt(ie) = (ee(ie+1)-ee(ie-1)) * (ee(ie)-ef)**mm\n endif\n 20 continue\n do 30 i = 0, 4\n 30 xx(i) = 0\n do 40 i = 0, 2\n 40 yy(i) = 0\n\n do 100 ie = 1, np\n do 80 i = 0,4\n 80 xx(i) = xx(i) + wt(ie)*ee(ie)**i\n do 90 i = 0,2\n 90 yy(i) = yy(i) + wt(ie)*xmu(ie)*ee(ie)**i\n 100 continue\n\n do 105 i=1,3\n do 105 j=1,3\n 105 xm(i,j) = xx(i+j-2)\n denom = determ (xm, 3, 3)\n\n do 110 i=1,3\n do 110 j=1,3\n 110 xm(i,j) = xx(i+j-2)\n do 120 i=1,3\n 120 xm(i,1) = yy (i-1)\n aa = determ (xm,3,3)\n aa = aa / denom\n\n do 210 i=1,3\n do 210 j=1,3\n 210 xm(i,j) = xx(i+j-2)\n do 220 i=1,3\n 220 xm(i,2) = yy (i-1)\n bb = determ (xm,3,3)\n bb = bb / denom\n\n do 310 i=1,3\n do 310 j=1,3\n 310 xm(i,j) = xx(i+j-2)\n do 320 i=1,3\n 320 xm(i,3) = yy (i-1)\n cc = determ (xm,3,3)\n cc = cc / denom\n\nc find normalization at edge+100 eV\n eee = ee(1) + 100/hart\n xnorm = (aa+bb*eee+cc*eee**2) / eee**xn\n\n open (unit=1,file='axafs.dat', status='unknown')\n write (1,*) '# File contains AXAFS. See manual for details.'\n write (1,*)\n 1 '#--------------------------------------------------------------'\n write(1,*) '# e, e(wrt edge), k,',\n 1 ' mu_at=(1+chi_at)*mu0_at, mu0_at, chi_at @#'\n do 400 ie = 1, np\n xmu(ie) = dimag(xsec(ie+ik0))\n xmu0 = (aa+bb*ee(ie)+cc*ee(ie)**2) / ee(ie)**xn\n chiat = (xmu(ie) - xmu0) / xmu0\n eee = ee(ie) -ef\n if (eee.ge.0.d0) then\n xk = sqrt(2*eee) /bohr\n else\n xk = -sqrt(-2*eee) /bohr\n endif\n write (1, 410) ee(ie)*hart, (ee(ie)-emu)*hart, xk,\n 1 xmu(ie)/xnorm, xmu0/xnorm, chiat\n 410 format (1x, 2f11.3, f8.3, 1p, 3e13.5)\n 400 continue\n close (unit=1)\n\n return\n end\n \n\n", "meta": {"hexsha": "ed6dc1c673c34e21c6958babedde99560a1ba056", "size": 3211, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/XSPH/axafs.f", "max_stars_repo_name": "bruceravel/feff85exafs", "max_stars_repo_head_hexsha": "9698ce3703a73def4c1a965f276708d689ea5acb", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-01-28T15:52:14.000Z", "max_stars_repo_stars_event_max_datetime": "2019-01-28T15:52:14.000Z", "max_issues_repo_path": "src/XSPH/axafs.f", "max_issues_repo_name": "bruceravel/feff85exafs", "max_issues_repo_head_hexsha": "9698ce3703a73def4c1a965f276708d689ea5acb", "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/XSPH/axafs.f", "max_forks_repo_name": "bruceravel/feff85exafs", "max_forks_repo_head_hexsha": "9698ce3703a73def4c1a965f276708d689ea5acb", "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": 28.1666666667, "max_line_length": 72, "alphanum_fraction": 0.493615696, "num_tokens": 1306, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070084811307, "lm_q2_score": 0.727975443004307, "lm_q1q2_score": 0.6623899575917749}} {"text": "program modEuler\nimplicit none\ninteger n,i\ndouble precision a,b,alpha,h,t,y,e,f,g\ne=dexp(1.d0)\nwrite(*,*)'enter n'\nread(*,*) n\nwrite(*,*)'enter a'\nread(*,*) a\nwrite(*,*)'enter b'\nread(*,*) b\nwrite(*,*)'enter alpha'\nread(*,*) alpha\nh=(b-a)/n\nt=a\ny=alpha\nwrite(8,*) t,y\nwrite(*,*) h\ndo i=1,n\n\ty=y+ h/2.d0*(f(t,y)+f(t+h,y+h*f(t,y)))\n\twrite(*,*)'Y=', y\n\tt=a + i*h\n\twrite(8,*) t,y,g(t),'error:', dabs(y - g(t))\nenddo\nwrite(9,*) h, dabs(y-g(t))\nstop\nend program modEuler\n\nfunction f(t,y)\nimplicit none\ndouble precision t,x,y,f,z\nx=2*t\nz=2*t*y\nf=(1/(t**2))*(dsin(x) - z)\nreturn\nend function f\n\nfunction g(t)\nimplicit none\ndouble precision t,g,x\nx=2.d0*t\ng=(.5d0)*(1/(t**2.d0))*(4+dcos(2.d0)-dcos(x))\nreturn\nend function g\n", "meta": {"hexsha": "8acfb5daff56bcc5daf870505b4c5650a5d648f1", "size": 715, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "MidPtODE.f90", "max_stars_repo_name": "whisker-rebellion/Fortran", "max_stars_repo_head_hexsha": "65c0e064bcc92f33bc78cc89220a0298b3ee96be", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MidPtODE.f90", "max_issues_repo_name": "whisker-rebellion/Fortran", "max_issues_repo_head_hexsha": "65c0e064bcc92f33bc78cc89220a0298b3ee96be", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MidPtODE.f90", "max_forks_repo_name": "whisker-rebellion/Fortran", "max_forks_repo_head_hexsha": "65c0e064bcc92f33bc78cc89220a0298b3ee96be", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.8888888889, "max_line_length": 45, "alphanum_fraction": 0.6, "num_tokens": 304, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069987088003, "lm_q2_score": 0.7279754489059774, "lm_q1q2_score": 0.6623899558477295}} {"text": " SUBROUTINE POTMP(PRESS,TEMP,S,RP,POTEMP)\n!SOURCE: http://www.ncl.ucar.edu/Support/talk_archives/2011/att-1609/potmp.f\nC\nC TITLE:\nC *****\nC\nC POTMP -- CALCULATE POTENTIAL TEMPERATURE FOR AN ARBITRARY\nC REFERENCE PRESSURE\nC\nC PURPOSE:\nC *******\nC\nC TO CALCULATE POTENTIAL TEMPERATURE\nC\nC REF: N.P. FOFONOFF\nC DEEP SEA RESEARCH\nC IN PRESS NOV 1976\nC\nC PARAMETERS:\nC **********\nC\nC PRESS -> PRESSURE IN DECIBARS\nC TEMP -> TEMPERATURE IN CELSIUS DEGREES\nC S -> SALINITY PSS 78\nC RP -> REFERENCE PRESSURE IN DECIBARS\nC (0.0 FOR THE QUANTITY THETA)\nC POTEMP <- POTENTIAL TEMPERATURE (DEG C)\nC\n REAL PRESS,TEMP,S,RP,POTEMP\nC\nC VARIABLES:\nC *********\nC\n INTEGER I,J,N\n REAL*4 DP,P,Q,R1,R2,R3,R4,R5,S1,T,X\nC\nC CODE:\nC ****\nC\n S1 = S-35.0\n P = PRESS\n T = TEMP\nC\n DP = RP - P\n N = IFIX(ABS(DP)/1000.) + 1\n DP = DP/FLOAT(N)\nC\n DO 10 I=1,N\n DO 20 J=1,4\nC\n R1 = ((-2.1687E-16*T+1.8676E-14)*T-4.6206E-13)*P\n R2 = (2.7759E-12*T-1.1351E-10)*S1\n R3 = ((-5.4481E-14*T+8.733E-12)*T-6.7795E-10)*T\n R4 = (R1+(R2+R3+1.8741E-8))*P+(-4.2393E-8*T+1.8932E-6)*S1\n R5 = R4+((6.6228E-10*T-6.836E-8)*T+8.5258E-6)*T+3.5803E-5\nC\n X = DP*R5\nC\n GO TO (100,200,300,400),J\nC\n 100 CONTINUE\n T = T+.5*X\n Q = X\n P = P + .5*DP\n GO TO 20\nC\n 200 CONTINUE\n T = T + .29298322*(X-Q)\n Q = .58578644*X + .121320344*Q\n GO TO 20\nC\n 300 CONTINUE\n T = T + 1.707106781*(X-Q)\n Q = 3.414213562*X - 4.121320344*Q\n P = P + .5*DP\n GO TO 20\nC\n 400 CONTINUE\n T = T + (X-2.0*Q)/6.0\n 20 CONTINUE\n 10 CONTINUE\nC\n POTEMP = T\n RETURN\nC\nC END POTMP\nC\n END\n\n", "meta": {"hexsha": "31d144a6bf4025f281f9874ad4d02f30628ed2e3", "size": 1995, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/obs/HOLD/potmp.f", "max_stars_repo_name": "GEOS-ESM/Ocean-LETKF", "max_stars_repo_head_hexsha": "a7c4bbf86cdbff078212914dcc059d0b1450accf", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-12-31T15:40:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-03T13:44:20.000Z", "max_issues_repo_path": "src/obs/HOLD/potmp.f", "max_issues_repo_name": "GEOS-ESM/Ocean-LETKF", "max_issues_repo_head_hexsha": "a7c4bbf86cdbff078212914dcc059d0b1450accf", "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/obs/HOLD/potmp.f", "max_forks_repo_name": "GEOS-ESM/Ocean-LETKF", "max_forks_repo_head_hexsha": "a7c4bbf86cdbff078212914dcc059d0b1450accf", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-14T18:46:56.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-14T18:46:56.000Z", "avg_line_length": 22.1666666667, "max_line_length": 76, "alphanum_fraction": 0.4731829574, "num_tokens": 793, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070084811306, "lm_q2_score": 0.7279754371026367, "lm_q1q2_score": 0.6623899522218036}} {"text": "cdis Forecast Systems Laboratory\ncdis NOAA/OAR/ERL/FSL\ncdis 325 Broadway\ncdis Boulder, CO 80303\ncdis\ncdis Forecast Research Division\ncdis Local Analysis and Prediction Branch\ncdis LAPS\ncdis\ncdis This software and its documentation are in the public domain and\ncdis are furnished \"as is.\" The United States government, its\ncdis instrumentalities, officers, employees, and agents make no\ncdis warranty, express or implied, as to the usefulness of the software\ncdis and documentation for any purpose. They assume no responsibility\ncdis (1) for the use of the software and documentation; or (2) to provide\ncdis technical support to users.\ncdis\ncdis Permission to use, copy, modify, and distribute this software is\ncdis hereby granted, provided that the entire disclaimer notice appears\ncdis in all copies. All modifications to this software must be clearly\ncdis documented, and are solely the responsibility of the agent making\ncdis the modifications. If significant modifications or enhancements\ncdis are made to this software, the FSL Software Policy Manager\ncdis (softwaremgr@fsl.noaa.gov) should be notified.\ncdis\ncdis\ncdis\ncdis\ncdis\ncdis\ncdis\n\n\n function sind(x)\n\n real x,sind,pi,rpd\n\n parameter (pi = 3.1415926535897932)\n parameter (rpd = pi / 180.)\n\n sind = sin(x*rpd)\n\n return\n end\n\n function cosd(x)\n\n real x,cosd,pi,rpd\n\n parameter (pi = 3.1415926535897932)\n parameter (rpd = pi / 180.)\n\n cosd = cos(x*rpd)\n\n return\n end\n\n function tand(x)\n\n real x,tand,pi,rpd\n\n parameter (pi = 3.1415926535897932)\n parameter (rpd = pi / 180.)\n\n tand = tan(x*rpd)\n\n return\n end\n\n function asind(x)\n\n real x,asind,pi,rpd\n\n parameter (pi = 3.1415926535897932)\n parameter (rpd = pi / 180.)\n\n asind = asin(x) / rpd\n\n return\n end\n\n function acosd(x)\n\n real x,acosd,pi,rpd\n\n parameter (pi = 3.1415926535897932)\n parameter (rpd = pi / 180.)\n\n acosd = acos(x) / rpd\n\n return\n end\n\n\n function atan2d(x,y)\n\n real x,y,atan2d,pi,rpd\n\n parameter (pi = 3.1415926535897932)\n parameter (rpd = pi / 180.)\n\n atan2_deg = atan2(x,y) / rpd\n\n return\n end\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "3d151ac16db2e2d869e80f091a93fba75b02b73c", "size": 2397, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/lib/trig.f", "max_stars_repo_name": "maxinye/laps-mirror", "max_stars_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_stars_repo_licenses": ["Intel", "Unlicense", "OLDAP-2.2.1", "NetCDF"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-04-05T12:28:22.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-29T06:37:29.000Z", "max_issues_repo_path": "src/lib/trig.f", "max_issues_repo_name": "longwosion/laps-mirror", "max_issues_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_issues_repo_licenses": ["Intel", "NetCDF", "OLDAP-2.2.1", "Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/lib/trig.f", "max_forks_repo_name": "longwosion/laps-mirror", "max_forks_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_forks_repo_licenses": ["Intel", "NetCDF", "OLDAP-2.2.1", "Unlicense"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-04-27T12:51:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-19T13:57:44.000Z", "avg_line_length": 21.0263157895, "max_line_length": 76, "alphanum_fraction": 0.6299541093, "num_tokens": 663, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891392358015, "lm_q2_score": 0.8056321983146848, "lm_q1q2_score": 0.6623820436729972}} {"text": "program main\n use iso_fortran_env\n implicit none\n\n real(real64),allocatable :: NodCoord(:,:)\n integer(int32),allocatable :: ElemNod(:,:)\n integer(int32),allocatable :: ElemMat(:)\n\n integer(int32) :: num_dim =2 ! 2-dimensional\n integer(int32) :: num_node=9 ! 9 nodes\n integer(int32) :: num_elem=4 ! 4 elements\n integer(int32) :: num_node_per_elem=4 ! 4 nodes per 1 element\n \n allocate(NodCoord(num_node,num_dim) )\n allocate(ElemNod(num_elem,num_node_per_elem) )\n allocate(ElemMat(num_elem))\n \n NodCoord(1,1) = 0.0d0; NodCoord(1,2) = 0.0d0;\n NodCoord(2,1) = 1.0d0; NodCoord(2,2) = 0.0d0;\n NodCoord(3,1) = 2.0d0; NodCoord(3,2) = 0.0d0;\n NodCoord(4,1) = 0.0d0; NodCoord(4,2) = 1.0d0;\n NodCoord(5,1) = 1.0d0; NodCoord(5,2) = 1.0d0;\n NodCoord(6,1) = 2.0d0; NodCoord(6,2) = 1.0d0;\n NodCoord(7,1) = 0.0d0; NodCoord(7,2) = 2.0d0;\n NodCoord(8,1) = 1.0d0; NodCoord(8,2) = 2.0d0;\n NodCoord(9,1) = 2.0d0; NodCoord(9,2) = 2.0d0;\n\n ElemNod(1,1) = 1; ElemNod(1,2) = 2; ElemNod(1,3) = 5; ElemNod(1,4) = 4; \n ElemNod(2,1) = 2; ElemNod(2,2) = 3; ElemNod(2,3) = 6; ElemNod(2,4) = 5; \n ElemNod(3,1) = 4; ElemNod(3,2) = 5; ElemNod(3,3) = 8; ElemNod(3,4) = 7; \n ElemNod(4,1) = 5; ElemNod(4,2) = 6; ElemNod(4,3) = 9; ElemNod(4,4) = 8; \n\n ElemMat(1) = 1;\n ElemMat(2) = 1;\n ElemMat(3) = 1;\n ElemMat(4) = 2;\n\n ! export\n ! ...\u7565\n \n \nend program main\n", "meta": {"hexsha": "08a03aaff7ee66b13ed5cb575945d6d4faf08f98", "size": 1426, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/playon_fem/ex0008_CreateMeshEx0.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/fem/ex0008_CreateMeshEx0.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/fem/ex0008_CreateMeshEx0.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": 33.1627906977, "max_line_length": 76, "alphanum_fraction": 0.5813464236, "num_tokens": 706, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219504, "lm_q2_score": 0.8056321983146848, "lm_q1q2_score": 0.6623820366528382}} {"text": "************************************************************************\n* ARITH.FOR *\n* *\n* *\n* PROGRAMMER: *\n* RALPH F. MILES, JR. *\n* SYSTEMS DIVISION *\n* JET PROPULSION LABORATORY *\n* PASADENA, CA 91109 *\n* *\n* VERSION: 1.00X1 *\n* DATE: 06/13/85 *\n* *\n*----------------------------------------------------------------------*\n* THE PROGRAM \"ARITH.FOR\" TESTS THE FOUR FORTRAN DOUBLE-PRECISION *\n* ARITHMETICAL OPERATIONS (+,-,*,/) AND THE FORTRAN DOUBLE-PRECISION *\n* FUNCTIONS MODULO (DMOD) AND TRUNCATION (DINT). *\n* *\n*----------------------------------------------------------------------*\n* CONFIGURATION CHANGES *\n* *\n* VER. DATE CHANGES *\n* *\n* 1.0X01 06/13/85 * ORIGINAL. *\n* *\n************************************************************************\n\n \n$TITLE:'RANDOM.LST'\n$DEBUG\n$NOFLOATCALLS\n$STORAGE:4\n \n************************************************************************\n\n PROGRAM ARITH\n\n************************************************************************\n\n\n***** INITIALIZE PROGRAM. {MODULE 1}\n\n CHARACTER*1 MENU\n DOUBLE PRECISION ARITH1,ARITH2,ARITH3\n\n*** {END MODULE 1}\n\n\n***** MENU DISPLAY. {MODULE 2}\n\n100 CONTINUE\n\n WRITE (*,110)\n110 FORMAT (1X,/////////////////////////\n * 24X,'****** THE ARITH MENU ****** '/\n * /\n * 24X,'+ : Addition '/\n * 24X,'- : Subtraction '/\n * 24X,'* : Multiplication '/\n * 24X,'/ : Division '/\n * 24X,'M : Modulo (DMOD) '/\n * 24X,'T : Truncation (DINT) '/\n * 24X,'Q : Quit '/\n * /\n * 24X,'----------------------------- '/\n * //)\n\n WRITE (*,'(20X,A\\)') 'Enter a Menu Character & : '\n READ (*,'(BN,A1)') MENU\n\n*** {END MODULE 2}\n\n\n***** QUIT THE PROGRAM. {MODULE 3}\n\n IF (MENU .EQ. 'Q') THEN\n\n WRITE (*,120)\n120 FORMAT (1X,/////////////////////////)\n\n GOTO 999\n\n ENDIF\n\n*** {END MODULE 3}\n\n\n***** PERFORM ADDITION. {MODULE 4}\n\n IF (MENU .EQ. '+') THEN\n\n WRITE (*,130)\n130 FORMAT (1X,/////////////////////////\n * 30X,'****** ADDITION ****** ')\n\n WRITE (*,140)\n140 FORMAT (/////1X,5X,'Enter the first number for addition: '\\)\n READ (*,150) ARITH1\n150 FORMAT (BN,F20.0)\n\n WRITE (*,160)\n160 FORMAT ( //1X,5X,'Enter the second number for addition: '\\)\n READ (*,170) ARITH2\n170 FORMAT (BN,F20.0)\n\n ARITH3 = ARITH1 + ARITH2\n\n WRITE (*,180) ARITH3\n180 FORMAT ( //1X,5X,'The addition of the two numbers is: ',\n * F20.0)\n\n WRITE (*,'(//1X,A\\)') 'Enter to continue: '\n READ (*,'(BN,A1)') MENU\n\n ENDIF \n\n*** {END MODULE 4}\n\n\n***** PERFORM SUBTRACTION. {MODULE 5}\n\n IF (MENU .EQ. '-') THEN\n\n WRITE (*,190)\n190 FORMAT (1X,/////////////////////////\n * 30X,'****** SUBTRACTION ****** ')\n\n WRITE (*,200)\n200 FORMAT (/////1X,5X,\n * 'Enter the first number for subtraction: '\\)\n READ (*,210) ARITH1\n210 FORMAT (BN,F20.0)\n\n WRITE (*,220)\n220 FORMAT (//1X,5X,'Enter the second number for subtraction: '\\)\n READ (*,230) ARITH2\n230 FORMAT (BN,F20.0)\n\n ARITH3 = ARITH1 - ARITH2\n\n WRITE (*,240) ARITH3\n240 FORMAT (//1X,5X,'The subtraction of the two numbers is: ',\n * F20.0)\n\n WRITE (*,'(//1X,A\\)') 'Enter to continue: '\n READ (*,'(BN,A1)') MENU\n\n ENDIF \n\n*** {END MODULE 5}\n\n\n***** PERFORM MULTIPLICATION. {MODULE 6}\n\n IF (MENU .EQ. '*') THEN\n\n WRITE (*,250)\n250 FORMAT (1X,/////////////////////////\n * 30X,'****** MULTIPLICATION ****** ')\n\n WRITE (*,260)\n260 FORMAT (/////1X,5X,\n * 'Enter the first number for multiplication: '\\)\n READ (*,270) ARITH1\n270 FORMAT (BN,F20.0)\n\n WRITE (*,280)\n280 FORMAT ( //1X,5X,\n * 'Enter the second number for multiplication: '\\)\n READ (*,290) ARITH2\n290 FORMAT (BN,F20.0)\n\n ARITH3 = ARITH1 * ARITH2\n\n WRITE (*,300) ARITH3\n300 FORMAT ( //1X,5X,\n * 'The multiplication of the two numbers is: ',F20.0)\n\n WRITE (*,'(//1X,A\\)') 'Enter to continue: '\n READ (*,'(BN,A1)') MENU\n\n ENDIF \n\n*** {END MODULE 6}\n\n\n***** PERFORM DIVISION. {MODULE 7}\n\n IF (MENU .EQ. '/') THEN\n\n WRITE (*,310)\n310 FORMAT (1X,/////////////////////////\n * 30X,'****** DIVISION ****** ')\n\n WRITE (*,320)\n320 FORMAT (/////1X,5X,'Enter the first number for division: '\\)\n READ (*,330) ARITH1\n330 FORMAT (BN,F20.0)\n\n WRITE (*,340)\n340 FORMAT ( //1X,5X,'Enter the second number for division: '\\)\n READ (*,350) ARITH2\n350 FORMAT (BN,F20.0)\n\n ARITH3 = ARITH1 / ARITH2\n\n WRITE (*,360) ARITH3\n360 FORMAT ( //1X,5X,'The division of the two numbers is: ',\n * F30.10)\n\n WRITE (*,'(//1X,A\\)') 'Enter to continue: '\n READ (*,'(BN,A1)') MENU\n\n ENDIF \n\n*** {END MODULE 7}\n\n\n***** PERFORM MODULO FUNCTION. {MODULE 8}\n\n IF (MENU .EQ. 'M') THEN\n\n WRITE (*,370)\n370 FORMAT (1X,/////////////////////////\n * 30X,'****** MODULO ****** ')\n\n WRITE (*,380)\n380 FORMAT (/////1X,5X,\n * 'Enter the argument of the modulo function: '\\)\n READ (*,390) ARITH1\n390 FORMAT (BN,F20.0)\n\n WRITE (*,400)\n400 FORMAT ( //1X,5X,\n * 'Enter the modulus of the modulo function: '\\)\n READ (*,410) ARITH2\n410 FORMAT (BN,F20.0)\n\n ARITH3 = DMOD(ARITH1,ARITH2)\n\n WRITE (*,420) ARITH3\n420 FORMAT ( //1X,5X,'The remainder is: ',F20.0)\n\n WRITE (*,'(//1X,A\\)') 'Enter to continue: '\n READ (*,'(BN,A1)') MENU\n\n ENDIF \n\n*** {END MODULE 8}\n\n\n***** PERFORM TRUNCATION. {MODULE 9}\n\n IF (MENU .EQ. 'T') THEN\n\n WRITE (*,430)\n430 FORMAT (1X,/////////////////////////\n * 30X,'****** TRUNCATION ****** ')\n\n WRITE (*,440)\n440 FORMAT (/////1X,5X,\n * 'Enter the decimal number for truncation: '\\)\n READ (*,450) ARITH1\n450 FORMAT (BN,F30.10)\n\n ARITH3 = DINT(ARITH1)\n\n WRITE (*,460) ARITH3\n460 FORMAT ( //1X,5X,\n * 'The truncation of the decimal number is: ',F30.10)\n\n WRITE (*,'(//1X,A\\)') 'Enter to continue: '\n READ (*,'(BN,A1)') MENU\n\n ENDIF \n\n*** {END MODULE 9}\n\n\n***** GO TO MENU. {MODULE 10}\n\n GOTO 100\n\n*** {END MODULE 10}\n\n\n***** STOP PROGRAM. {MODULE 11}\n\n999 CONTINUE\n\n STOP\n\n END\n\n*** {END MODULE 11}\n\n****************************** ARITH.FOR *******************************\n\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a\u001a", "meta": {"hexsha": "2b687bdcf415e0664375f9a2b8c32804033de61e", "size": 8279, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "npo-16937/arith.for", "max_stars_repo_name": "SteveDoyle2/nasa-cosmic", "max_stars_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_stars_repo_licenses": ["BSD-Source-Code"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2015-03-14T07:26:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-16T12:23:17.000Z", "max_issues_repo_path": "npo-16937/arith.for", "max_issues_repo_name": "SteveDoyle2/nasa-cosmic", "max_issues_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_issues_repo_licenses": ["BSD-Source-Code"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "npo-16937/arith.for", "max_forks_repo_name": "SteveDoyle2/nasa-cosmic", "max_forks_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_forks_repo_licenses": ["BSD-Source-Code"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2016-02-12T22:18:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-08T17:46:54.000Z", "avg_line_length": 27.7818791946, "max_line_length": 80, "alphanum_fraction": 0.3536659017, "num_tokens": 2208, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.822189134878876, "lm_q2_score": 0.8056321843145405, "lm_q1q2_score": 0.6623820286521512}} {"text": "module m_searching\n !! Contains routines to perform a simple binary search on a vector\n !!\n !! Example usage\n !!```fortran\n !!program binarySearch_test\n !!use variableKind, only: i32, r64\n !!use m_BinarySearch, only: binarySearch\n !!\n !!implicit none\n !!\n !!real(r64) :: arr(20)\n !!integer(i32) :: i\n !!integer(i32) :: j\n !!arr=[(dble(i), i = 1, 20)]\n !!j = binarySearch(arr, 10.d0, 1, 20)\n !!write(*,*) 'Location of 10.0 in arr is 10? ',j == 10\n !!end program\n !!```\n !! Perform a binary search but also return the neighbouring interval if the actual value is not found.\n !! This is useful if you need to find a number that is not contained in the array and you want the interval\n !!\n !! Example usage\n !!```fortran\n !!use variableKind\n !!use m_BinarySearch, only: intervalSearch\n !!real(r64) :: arr(20)\n !!integer(i32) :: i\n !!integer(i32) :: j(3)\n !!arr=[(dble(i), i = 1, 20)]\n !!j = intervalSearch(arr, 10.5d0, 1, 20)\n !!write(*,*) 'Location of 10.5 in arr is -1? ',j(1) == -1\n !!write(*,*) 'The interval containing 10.5 is [10,11]? ',j(2:3) == [10,11]\n !!```\n\nuse variableKind\nimplicit none\n\nprivate\n\npublic :: binarySearch\npublic :: intervalSearch\npublic :: simpleSearch\n\ninterface binarySearch\n !! Perform a binary search. See [[m_searching]] for more information on how to use this interface\n !====================================================================!\n module recursive function binarySearch_i1D(this,v,imin,imax) result(iout)\n !! Search for the value i in an integer vector\n !! Assumes this is sorted!\n !====================================================================!\n integer(i32) :: this(:)\n !! Vector to search within\n integer(i32) :: v\n !! Number to find in the vector\n integer(i32) :: imin\n !! Left integer\n integer(i32) :: imax\n !! Right integer\n integer(i32) :: iout\n !! Location of i in this. Returns -1 if not present\n end function\n !====================================================================!\n !====================================================================!\n module recursive function binarySearch_id1D(this,v,imin,imax) result(iout)\n !! Search for the value i in an integer vector\n !! Assumes this is sorted!\n !====================================================================!\n integer(i64) :: this(:)\n !! Vector to search within\n integer(i64) :: v\n !! Number to find in the vector\n integer(i32) :: imin\n !! Left integer\n integer(i32) :: imax\n !! Right integer\n integer(i32) :: iout\n !! Location of i in this. Returns -1 if not present\n end function\n !====================================================================!\n !====================================================================!\n module recursive function binarySearch_r1D(this,v,imin,imax) result(iout)\n !! Search for the value i in an integer vector\n !! Assumes this is sorted!\n !====================================================================!\n real(r32) :: this(:)\n !! Vector to search within\n real(r32) :: v\n !! Number to find in the vector\n integer(i32) :: imin\n !! Left integer\n integer(i32) :: imax\n !! Right integer\n integer(i32) :: iout\n !! Location of i in this. Returns -1 if not present\n end function\n !====================================================================!\n !====================================================================!\n module recursive function binarySearch_d1D(this,v,imin,imax) result(iout)\n !! Search for the value i in an integer vector\n !! Assumes this is sorted!\n !====================================================================!\n real(r64) :: this(:)\n !! Vector to search within\n real(r64) :: v\n !! Number to find in the vector\n integer(i32) :: imin\n !! Left integer\n integer(i32) :: imax\n !! Right integer\n integer(i32) :: iout\n !! Location of i in this. Returns -1 if not present\n end function\n !====================================================================!\nend interface\n\ninterface intervalSearch\n !! Perform an interval search on an array\n !! Returns a length 3 integer(i32) array where the last two entries are the left and right neighbours\n !! The first entry of iout is -1 if the value is not present in the vector\n !! Assumes this is sorted!See [[m_searching]] for more information on how to use this interface\n !====================================================================!\n module recursive function intervalSearch_i1D(this,v,imin,imax) result(iout)\n !! interfaced with [[intervalSearch]]\n !====================================================================!\n integer(i32) :: this(:)\n !! Vector to search within\n integer(i32) :: v\n !! Number to find in the vector\n integer(i32) :: imin\n !! Left integer\n integer(i32) :: imax\n !! Right integer\n integer(i32) :: iout(3)\n !! Location of i in this. iout(1) = -1 if not present with iout(2-3) as the interval\n end function\n !====================================================================!\n !====================================================================!\n module recursive function intervalSearch_id1D(this,v,imin,imax) result(iout)\n !! interfaced with [[intervalSearch]]\n !====================================================================!\n integer(i64) :: this(:)\n !! Vector to search within\n integer(i64) :: v\n !! Number to find in the vector\n integer(i32) :: imin\n !! Left integer\n integer(i32) :: imax\n !! Right integer\n integer(i32) :: iout(3)\n !! Location of i in this. iout(1) = -1 if not present with iout(2-3) as the interval\n end function\n !====================================================================!\n !====================================================================!\n module recursive function intervalSearch_r1D(this,v,imin,imax) result(iout)\n !! interfaced with [[intervalSearch]]\n !====================================================================!\n real(r32) :: this(:)\n !! Vector to search within\n real(r32) :: v\n !! Number to find in the vector\n integer(i32) :: imin\n !! Left integer\n integer(i32) :: imax\n !! Right integer\n integer(i32) :: iout(3)\n !! Location of i in this. iout(1) = -1 if not present with iout(2-3) as the interval\n end function\n !====================================================================!\n !====================================================================!\n module recursive function intervalSearch_d1D(this,v,imin,imax) result(iout)\n !! interfaced with [[intervalSearch]]\n !====================================================================!\n real(r64) :: this(:)\n !! Vector to search within\n real(r64) :: v\n !! Number to find in the vector\n integer(i32) :: imin\n !! Left integer\n integer(i32) :: imax\n !! Right integer\n integer(i32) :: iout(3)\n !! Location of i in this. iout(1) = -1 if not present with iout(2-3) as the interval\n end function\n !====================================================================!\nend interface\n\ninterface simpleSearch\n !! Carry out a brute force search on an array for a given number. Returns -1 if the value is not found.\n !====================================================================!\n module function simpleSearch_i1D(this, val) result(iout)\n !! Interfaced with [[simpleSearch]]\n !====================================================================!\n integer(i32) :: this(:)\n !! Search this vector\n integer(i32) :: val\n !! Number to find in the vector\n integer(i32) :: iout\n !! Location of i in this\n end function\n !====================================================================!\n !====================================================================!\n module function simpleSearch_id1D(this, val) result(iout)\n !! Interfaced with [[simpleSearch]]\n !====================================================================!\n integer(i64) :: this(:)\n !! Search this vector\n integer(i64) :: val\n !! Number to find in the vector\n integer(i32) :: iout\n !! Location of i in this\n end function\n !====================================================================!\n !====================================================================!\n module function simpleSearch_r1D(this, val) result(iout)\n !! Interfaced with [[simpleSearch]]\n !====================================================================!\n real(r32) :: this(:)\n !! Search this vector\n real(r32) :: val\n !! Number to find in the vector\n integer(i32) :: iout\n !! Location of i in this\n end function\n !====================================================================!\n !====================================================================!\n module function simpleSearch_d1D(this, val) result(iout)\n !! Interfaced with [[simpleSearch]]\n !====================================================================!\n real(r64) :: this(:)\n !! Search this vector\n real(r64) :: val\n !! Number to find in the vector\n integer(i32) :: iout\n !! Location of i in this\n end function\n !====================================================================!\nend interface\n\nend module\n\n\n\n", "meta": {"hexsha": "d5404885d89067f8ec06b93a32327e6ec1fa9fd9", "size": 9178, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "docs/src/m_searching.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": "docs/src/m_searching.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": "docs/src/m_searching.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": 37.6147540984, "max_line_length": 109, "alphanum_fraction": 0.4709086947, "num_tokens": 2117, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321796478255, "lm_q2_score": 0.8221891261650247, "lm_q1q2_score": 0.6623820177950699}} {"text": "! Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.\n! See https://llvm.org/LICENSE.txt for license information.\n! SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception\n!\n! Tests \"generic procedure interfaces named the same as a type in the same \n! module\", a.k.a. \"Type Overloading\"\n\n\n! This is a slightly modified version of Figure 17.1 in\n! Fortran 95/2003 Explained by Metcalf, Reid & Cohen.\n! All modifications are marked.\n!\n\nmodule mycomplex_module ! Not in Figure 17.1\n private ! Not in Figure 17.1\n public :: mycomplex ! Not in Figure 17.1\n type mycomplex\n private ! Not in Figure 17.1\n real :: argument, modulus\n real :: x, y\n contains\n procedure :: getx\n procedure :: gety\n end type\n interface mycomplex\n module procedure complex_to_mycomplex, two_reals_to_mycomplex\n end interface\n contains\n type(mycomplex) function complex_to_mycomplex(c)\n complex, intent(in) :: c\n\t complex_to_mycomplex%x = 0.0\n\t complex_to_mycomplex%y = 0.0\n end function complex_to_mycomplex\n type(mycomplex) function two_reals_to_mycomplex(x,y)\n real, intent(in) :: x\n real, intent(in), optional :: y\n\t two_reals_to_mycomplex%x = x\n\t if (present(y)) then\n\t two_reals_to_mycomplex%y = y\n\t else\n\t two_reals_to_mycomplex%y = 0.0\n\t endif\n end function two_reals_to_mycomplex\n real function getx(this)\n class(mycomplex) :: this\n\tgetx = this%x\n end function getx\n real function gety(this)\n\tclass(mycomplex) :: this\n\tgety = this%y\n end function gety\nend module mycomplex_module ! Not in Figure 17.1\n\nprogram myuse ! Not in Figure 17.1\n use mycomplex_module ! Not in Figure 17.1\n logical rslt(4), expect(4)\n type(mycomplex) :: c ! Not in Figure 17.1\n rslt = .false.\n expect = .true.\n c = mycomplex(x=1.0, y=2.0)! This should invoke two_reals_tomycomplex()\n rslt(1) = c%getx() .eq. 1.0\n rslt(2) = c%gety() .eq. 2.0\n c = mycomplex(3.0, 4.0) ! This should invoke two_reals_tomycomplex()\n rslt(3) = c%getx() .eq. 3.0\n rslt(4) = c%gety() .eq. 4.0\n\n call check(rslt,expect,4)\n\nend program myuse\n\n", "meta": {"hexsha": "3de77864246c1ba120dbdfcb879b3a589217c704", "size": 2300, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/f90_correct/src/oop354.f90", "max_stars_repo_name": "abrahamtovarmob/flang", "max_stars_repo_head_hexsha": "bcd84b29df046b6d6574f0bfa34ea5059092615a", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 716, "max_stars_repo_stars_event_min_datetime": "2017-05-17T17:58:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T11:20:58.000Z", "max_issues_repo_path": "test/f90_correct/src/oop354.f90", "max_issues_repo_name": "abrahamtovarmob/flang", "max_issues_repo_head_hexsha": "bcd84b29df046b6d6574f0bfa34ea5059092615a", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 794, "max_issues_repo_issues_event_min_datetime": "2017-05-18T19:27:40.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T23:22:11.000Z", "max_forks_repo_path": "test/f90_correct/src/oop354.f90", "max_forks_repo_name": "abrahamtovarmob/flang", "max_forks_repo_head_hexsha": "bcd84b29df046b6d6574f0bfa34ea5059092615a", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 157, "max_forks_repo_forks_event_min_datetime": "2017-05-17T18:50:33.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T07:06:45.000Z", "avg_line_length": 32.3943661972, "max_line_length": 79, "alphanum_fraction": 0.6313043478, "num_tokens": 672, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321796478255, "lm_q2_score": 0.8221891239865619, "lm_q1q2_score": 0.6623820160400301}} {"text": "\nmodule armstrong_numbers\n implicit none\ncontains\n\n logical function isArmstrongNumber(i)\n integer, intent(in) :: i\n integer :: slen, idx, j, sum\n character(len=100) :: s \n\n isArmstrongNumber = .false.\n sum = 0\n write(s,'(i100)') i\n s=adjustl(s)\n slen = len_trim(s)\n do idx =1,slen\n read(s(idx:idx),*) j\n sum = sum + j**slen\n enddo\n if (sum == i) then\n isArmstrongNumber = .true.\n endif \n end function\n\nend module\n", "meta": {"hexsha": "75a6b45c82c1be4f3b04a4c33f0dd56f5c1427fc", "size": 468, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "exercises/practice/armstrong-numbers/.meta/example.f90", "max_stars_repo_name": "hiljusti/fortran", "max_stars_repo_head_hexsha": "998dae09b8ef463752c3e15598d115c5aec7e64c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2017-06-28T12:57:17.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-22T03:30:48.000Z", "max_issues_repo_path": "exercises/practice/armstrong-numbers/.meta/example.f90", "max_issues_repo_name": "hiljusti/fortran", "max_issues_repo_head_hexsha": "998dae09b8ef463752c3e15598d115c5aec7e64c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 92, "max_issues_repo_issues_event_min_datetime": "2017-06-28T13:27:55.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T08:46:33.000Z", "max_forks_repo_path": "exercises/practice/armstrong-numbers/.meta/example.f90", "max_forks_repo_name": "hiljusti/fortran", "max_forks_repo_head_hexsha": "998dae09b8ef463752c3e15598d115c5aec7e64c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 20, "max_forks_repo_forks_event_min_datetime": "2017-07-29T03:43:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-08T05:59:28.000Z", "avg_line_length": 18.0, "max_line_length": 39, "alphanum_fraction": 0.5961538462, "num_tokens": 152, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772417253256, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6623708138387151}} {"text": "MODULE func_psi\r\nUSE use_func\r\nUSE ParamModule\r\nIMPLICIT NONE\r\n!INTEGER,PARAMETER::SGL=SELECTED_REAL_KIND(p=6)\r\n!INTEGER,PARAMETER::DBL=SELECTED_REAL_KIND(p=13)\r\n!REAL(KIND=DBL),PARAMETER::pi=3.1415926535897932385d0\r\n!REAL(KIND=DBL),PARAMETER::EulerGamma=0.57721566490153286061d0\r\nINTERFACE unit_step\r\n MODULE PROCEDURE unit_step_d\r\n MODULE PROCEDURE unit_step_s\r\n MODULE PROCEDURE unit_step_i\r\nEND INTERFACE unit_step\r\nINTERFACE Arg\r\n MODULE PROCEDURE ArgI\r\n MODULE PROCEDURE ArgR\r\n MODULE PROCEDURE ArgC\r\nEND INTERFACE Arg\r\nINTERFACE Log2\r\n MODULE PROCEDURE LogR\r\n MODULE PROCEDURE LogI\r\n MODULE PROCEDURE LogC\r\nEND INTERFACE Log2\r\nINTERFACE CSQRT2\r\n MODULE PROCEDURE CSQRTC\r\n MODULE PROCEDURE CSQRTR\r\n MODULE PROCEDURE CSQRTI\r\nEND INTERFACE CSQRT2\r\nINTERFACE li2\r\n MODULE PROCEDURE li2I\r\n MODULE procedure li2R\r\n MODULE procedure li2C\r\nEND INTERFACE li2\r\nCONTAINS\r\nFUNCTION lamda_func(a,b,c)\r\nREAL(KIND=DBL)::lamda_func\r\nREAL(KIND=DBL),INTENT(IN)::a,b,c\r\nlamda_func=a**2+b**2+c**2-2*a*b-2*a*c-2*b*c\r\nEND FUNCTION lamda_func\r\n\r\nFUNCTION unit_step_d(x)\r\nREAL(KIND=DBL)::unit_step_d\r\nREAL(KIND=DBL)::x\r\nIF(x.LT.0d0) THEN\r\n unit_step_d=0d0\r\nELSE\r\n unit_step_d=1d0\r\nEND IF\r\nEND FUNCTION unit_step_d\r\n\r\nFUNCTION unit_step_s(x)\r\nREAL(KIND=DBL)::unit_step_s\r\nREAL(KIND=SGL)::x\r\nIF(x.LT.0.0) THEN\r\n unit_step_s=0d0\r\nELSE\r\n unit_step_s=1d0\r\nEND IF\r\nEND FUNCTION unit_step_s\r\n\r\nFUNCTION unit_step_i(x)\r\nREAL(KIND=DBL)::unit_step_i\r\nINTEGER::x\r\nIF(x.LT.0) THEN\r\n unit_step_i=0d0\r\nELSE\r\n unit_step_i=1d0\r\nEND IF\r\nEND FUNCTION unit_step_i\r\n\r\nFUNCTION ACosh_p(x)\r\nREAL(KIND=DBL),INTENT(IN)::x\r\nREAL(KIND=DBL)::ACosh_p\r\nIF(DABS(x).LT.1d0) THEN\r\n WRITE(*,*)\"Error in ACosh_p!\"\r\n ACosh_p=0\r\nELSE\r\n ACosh_p=DLOG(x+DSQRT(x**2-1d0))\r\nEND IF\r\nEND FUNCTION ACosh_p\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! Li2 function\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\nFUNCTION li2R(x)\r\n COMPLEX(KIND=DBL)::li2R\r\n REAL(KIND=DBL),INTENT(IN)::x\r\n REAL(KIND=DBL)::y\r\n y=1d0-x\r\n IF(y.GT.0d0) THEN\r\n ! IF(y.GT.1d0)WRITE(*,*)\"ATTENTION!\"\r\n li2R=func_li2a(y,0)\r\n ELSEIF(y.LT.0d0)THEN\r\n li2R=func_li2a(-y,1)\r\n ELSE\r\n li2R=DCMPLX(0d0)\r\n END IF\r\n RETURN\r\nEND FUNCTION li2R\r\n\r\nFUNCTION li2I(x)\r\n COMPLEX(KIND=DBL)::li2I\r\n INTEGER,INTENT(IN)::x\r\n REAL(KIND(1d0))::xx\r\n REAL(KIND=DBL)::y\r\n xx=x\r\n y=1d0-xx\r\n IF(y.GT.0d0) THEN\r\n li2I=func_li2a(y,0)\r\n ELSEIF(y.LT.0d0)THEN\r\n li2I=func_li2a(-y,1)\r\n ELSE\r\n li2I=DCMPLX(0d0)\r\n END IF\r\n RETURN\r\nEND FUNCTION li2I\r\n\r\nFUNCTION li2C(x)\r\n COMPLEX(KIND=DBL)::li2C\r\n COMPLEX(KIND=DBL),INTENT(IN)::x\r\n COMPLEX(KIND=DBL)::y,newy\r\n REAL(KIND=DBL)::yr,yi\r\n INTEGER::iphi\r\n y=DCMPLX(1d0)-x\r\n yr=DBLE(y)\r\n yi=DIMAG(y)\r\n IF(yr.EQ.0d0.AND.yi.EQ.0d0)THEN\r\n li2C=DCMPLX(0d0)\r\n RETURN\r\n ENDIF\r\n IF(yr.GE.0d0.AND.yi.GE.0d0)THEN\r\n iphi=0\r\n newy=y\r\n ELSEIF(yr.GE.0d0.AND.yi.LT.0d0)THEN\r\n iphi=0\r\n newy=y\r\n ELSEIF(yr.LT.0d0.AND.yi.GE.0d0)THEN\r\n iphi=1\r\n newy=DCMPLX(-yr,-yi)\r\n ELSEIF(yr.LT.0d0.AND.yi.LT.0d0)THEN\r\n iphi=-1\r\n newy=DCMPLX(-yr,-yi)\r\n END IF\r\n li2C=func_li2c(newy,iphi)\r\n RETURN\r\nEND FUNCTION li2C\r\n\r\nFUNCTION PolyLog(n,x)\r\n COMPLEX(KIND=DBL)::PolyLog\r\n REAL(KIND=DBL),INTENT(IN)::x\r\n INTEGER,INTENT(IN)::n\r\n IF(n.NE.2)THEN\r\n WRITE(*,*)\"ERROR:Don't know n = \",n\r\n STOP\r\n ENDIF\r\n PolyLog=li2R(x)\r\n RETURN\r\nEND FUNCTION PolyLog\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! DLOG2\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\nFUNCTION DLOG2(x)\r\nREAL(KIND=DBL)::DLOG2\r\nREAL(KIND=DBL),INTENT(IN)::x\r\nIF(x.LT.0d0)THEN\r\n DLOG2=DLOG(-x)\r\nELSE\r\n DLOG2=DLOG(x)\r\nENDIF\r\nEND FUNCTION DLOG2\r\n\r\nFUNCTION LogI(x)\r\n COMPLEX(KIND(1d0))::LogI\r\n INTEGER,INTENT(IN)::x\r\n REAL(KIND(1d0))::xx\r\n xx=x\r\n LogI=DLOG(xx)\r\n RETURN\r\nEND FUNCTION LogI\r\n\r\nFUNCTION LogR(x)\r\n COMPLEX(KIND(1d0))::LogR\r\n REAL(KIND(1d0)),INTENT(IN)::x\r\n LogR=DLOG(x)\r\n RETURN\r\nEND FUNCTION LogR\r\n\r\nFUNCTION LogC(x)\r\n COMPLEX(KIND(1d0))::LogC\r\n COMPLEX(KIND(1d0)),INTENT(IN)::x\r\n LogC=CDLOG(x)\r\n RETURN\r\nEND FUNCTION LogC\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! Arg\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\nFUNCTION ArgR(x)\r\n IMPLICIT NONE\r\n REAL(KIND=DBL),INTENT(IN)::x\r\n REAL(KIND=DBL)::ArgR\r\n IF(x.GE.0d0)THEN\r\n ArgR=0d0\r\n ELSE\r\n ArgR=pi\r\n ENDIF\r\n RETURN\r\nEND FUNCTION ArgR\r\n\r\nFUNCTION ArgI(x)\r\n IMPLICIT NONE\r\n INTEGER,INTENT(IN)::x\r\n REAL(KIND=DBL)::ArgI\r\n IF(x.GE.0)THEN\r\n ArgI=0d0\r\n ELSE\r\n ArgI=pi\r\n ENDIF\r\n RETURN\r\nEND FUNCTION ArgI\r\n\r\nFUNCTION ArgC(x)\r\n IMPLICIT NONE\r\n COMPLEX(KIND=DBL),INTENT(IN)::x\r\n REAL(KIND=DBL)::ArgC\r\n REAL(KIND=DBL)::xr,xi\r\n REAL(KIND=DBL)::add,time\r\n xr=DBLE(x)\r\n xi=DIMAG(x)\r\n IF(xr.EQ.0d0)THEN\r\n IF(xi.GT.0d0)THEN\r\n ArgC=pi/2d0\r\n RETURN\r\n ENDIF\r\n IF(xi.LT.0d0)THEN\r\n ArgC=-pi/2d0\r\n RETURN\r\n ENDIF\r\n IF(xi.EQ.0d0)THEN\r\n ArgC=0d0\r\n RETURN\r\n ENDIF\r\n ENDIF\r\n IF(xr.GE.0d0.AND.xi.GE.0d0)THEN\r\n add=0d0\r\n time=1d0\r\n ELSEIF(xr.GE.0d0.AND.xi.LT.0d0)THEN\r\n add=0d0\r\n time=-1d0\r\n ELSEIF(xr.LT.0d0.AND.xi.GE.0d0)THEN\r\n add=pi\r\n time=-1d0\r\n ELSEIF(xr.LT.0d0.AND.xi.LE.0d0)THEN\r\n add=-pi\r\n time=1d0\r\n ENDIF\r\n ArgC=time*atan(abs(xi/xr))+add\r\n RETURN\r\nEND FUNCTION ArgC\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! CSQRT2\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\nFUNCTION CSQRTI(x)\r\n IMPLICIT NONE\r\n COMPLEX(KIND(1d0))::CSQRTI\r\n INTEGER,INTENT(IN)::x\r\n REAL(KIND(1d0))::xx\r\n COMPLEX(KIND(1d0))::xxx\r\n IF(x.GE.0)THEN\r\n xx=x\r\n CSQRTI=DCMPLX(DSQRT(xx))\r\n ELSE\r\n xxx=x\r\n CSQRTI=CDSQRT(xxx)\r\n ENDIF\r\n RETURN\r\nEND FUNCTION CSQRTI\r\n\r\nFUNCTION CSQRTR(x)\r\n IMPLICIT NONE\r\n COMPLEX(KIND(1d0))::CSQRTR\r\n REAL(KIND(1d0)),INTENT(IN)::x\r\n COMPLEX(KIND(1d0))::xx\r\n IF(x.GE.0d0)THEN\r\n CSQRTR=DCMPLX(DSQRT(x))\r\n ELSE\r\n xx=x\r\n CSQRTR=CDSQRT(xx)\r\n ENDIF\r\n RETURN\r\nEND FUNCTION CSQRTR\r\n\r\nFUNCTION CSQRTC(x)\r\n IMPLICIT NONE\r\n COMPLEX(KIND(1d0))::CSQRTC\r\n COMPLEX(KIND(1d0)),INTENT(IN)::x\r\n CSQRTC=CDSQRT(x)\r\n RETURN\r\nEND FUNCTION CSQRTC\r\nEND MODULE func_psi\r\n", "meta": {"hexsha": "3eff3a15a4324426baf288f62121127d8189cd9e", "size": 6316, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "vendor/SMWidth/Func_PSI.f90", "max_stars_repo_name": "khurtado/MG5_aMC", "max_stars_repo_head_hexsha": "9cde676b0a1097058c416983017af257385fa375", "max_stars_repo_licenses": ["NCSA"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-10-23T14:37:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-22T20:59:02.000Z", "max_issues_repo_path": "vendor/SMWidth/Func_PSI.f90", "max_issues_repo_name": "khurtado/MG5_aMC", "max_issues_repo_head_hexsha": "9cde676b0a1097058c416983017af257385fa375", "max_issues_repo_licenses": ["NCSA"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2018-10-08T15:49:32.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-15T13:33:36.000Z", "max_forks_repo_path": "vendor/SMWidth/Func_PSI.f90", "max_forks_repo_name": "khurtado/MG5_aMC", "max_forks_repo_head_hexsha": "9cde676b0a1097058c416983017af257385fa375", "max_forks_repo_licenses": ["NCSA"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2019-02-18T11:42:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-11T20:46:08.000Z", "avg_line_length": 21.1237458194, "max_line_length": 82, "alphanum_fraction": 0.5911969601, "num_tokens": 2409, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772482857833, "lm_q2_score": 0.757794360334681, "lm_q1q2_score": 0.6623708092478232}} {"text": "! Fundamental constants taken from NIST's 2010 CODATA recommended values\n\nmodule fundamental_constants_module\n\n use amrex_fort_module, only : rt => amrex_real\n\n implicit none\n\n ! Pi\n real(rt), parameter :: pi = 3.141592653589793238d0\n\n ! newton's gravitational constant\n real(rt), parameter :: Gconst = 6.67428e-8_rt ! cm^3/g/s^2\n ! new value; if uncommented initial models will need to be re-HSE'ed\n !real(rt), parameter :: Gconst = 6.67384e-8_rt ! cm^3/g/s^2\n\n ! boltzmann's constant\n real(rt), parameter :: k_B = 1.3806488e-16_rt ! erg/K\n\n ! planck's constant over 2pi\n real(rt), parameter :: hbar = 1.054571726e-27_rt ! erg s\n\n ! planck's constant\n real(rt), parameter :: hplanck = 6.62606957e-27_rt ! erg s\n\n ! avogradro's Number\n real(rt), parameter :: n_A = 6.02214129e23_rt ! mol^-1\n\n ! Thomson cross section [cm^2]\n real(rt), parameter :: sigma_T = 6.6524587158e-25_rt\n\n ! convert eV to erg\n real(rt), parameter :: ev2erg = 1.602176487e-12_rt\n\n ! convert MeV to eV\n real(rt), parameter :: MeV2eV = 1.0e6_rt\n\n ! mass of proton\n real(rt), parameter :: m_proton = 1.672621777e-24_rt ! g\n\n ! mass of neutron\n real(rt), parameter :: m_n = 1.674927351e-24_rt ! g\n\n ! mass of electron\n real(rt), parameter :: m_e = 9.10938291e-28_rt ! g\n\n ! speed of light in vacuum\n real(rt), parameter :: c_light = 2.99792458e10_rt ! cm/s\n\n real(rt), parameter :: mp_over_kb = m_proton/k_B\n\n ! electron charge\n ! NIST: q_e = 1.602176565e-19 C\n !\n ! C is the SI unit Coulomb; in cgs we have the definition:\n ! 1 C = 0.1 * |c_light| * 1 statC\n ! where statC is the cgs unit statCoulomb; 1 statC = 1 erg^1/2 cm^1/2\n ! and |c_light| is the speed of light in cgs (but without units)\n real(rt), parameter :: q_e = 4.80320451e-10_rt ! erg^1/2 cm^1/2\n\n ! stefan-boltzmann constant\n real(rt), parameter :: sigma_SB = 5.670373e-5_rt ! erg/s/cm^2/K^4\n\n ! radiation constant\n real(rt), parameter :: a_rad = 4.0_rt*sigma_SB/c_light\n\n ! Hubble constant (in s^{-1}, converted from 100 (km/s)/Mpc by dividing by 3.08568025e19km/Mpc)\n real(rt), parameter :: Hubble_const = 32.407764868e-19\n\n !!! conversion factors\n\n ! conversion factor for density from cosmo to cgs units.\n real(rt), parameter :: density_to_cgs = 1\n\n ! converstion factor for \"heat\" from cgs to cosmo units.\n real(rt), parameter :: heat_from_cgs = 1\n\n ! conversion factor for energy from cosmo to cgs units.\n real(rt), parameter :: e_to_cgs = 1\n\n ! For AGN accretion rate\n real(rt), parameter :: eddington_const = 4.0d0*pi * Gconst * m_proton / (sigma_T * c_light)\n\nend module fundamental_constants_module\n", "meta": {"hexsha": "0b7a570840962c1c69d19fc6e970ee500ef5b592", "size": 2628, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Source/Constants/constants_cgs.f90", "max_stars_repo_name": "Gosenca/axionyx_1.0", "max_stars_repo_head_hexsha": "7e2a723e00e6287717d6d81b23db32bcf6c3521a", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-02-18T09:13:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T21:27:46.000Z", "max_issues_repo_path": "Source/Constants/constants_cgs.f90", "max_issues_repo_name": "Gosenca/axionyx_1.0", "max_issues_repo_head_hexsha": "7e2a723e00e6287717d6d81b23db32bcf6c3521a", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-10-12T08:54:31.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-12T08:54:31.000Z", "max_forks_repo_path": "Source/Constants/constants_cgs.f90", "max_forks_repo_name": "Gosenca/axionyx_1.0", "max_forks_repo_head_hexsha": "7e2a723e00e6287717d6d81b23db32bcf6c3521a", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-09-04T10:26:25.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T23:51:51.000Z", "avg_line_length": 30.9176470588, "max_line_length": 97, "alphanum_fraction": 0.6777016743, "num_tokens": 917, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778825, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6623704775702562}} {"text": "PROGRAM F003\n\n ! Copyright 2021 Melwyn Francis Carlo\n ! FILE REFERENCE: http://www.naturalnumbers.org/primes.html\n\n IMPLICIT NONE\n\n INTEGER :: PRIME_NUM\n REAL (KIND=8), PARAMETER :: N = 600851475143.D0\n REAL (KIND=8), PARAMETER :: PRIME_NUM_MAX = SQRT(N)\n REAL (KIND=8) :: PRIME_NUM_LARGEST\n CHARACTER (LEN=50), PARAMETER :: FILENAME = \"problems/003/PrimeNumbers_Upto_1000000\"\n\n OPEN (2, FILE = FILENAME, STATUS = 'OLD')\n\n PRIME_NUM_LARGEST = N\n DO\n READ(2, *, END=10) PRIME_NUM\n IF (PRIME_NUM <= PRIME_NUM_MAX) THEN\n IF (MOD(INT(N, 8), INT(PRIME_NUM, 8)) == 0) THEN\n PRIME_NUM_LARGEST = PRIME_NUM\n END IF\n ELSE\n EXIT\n END IF\n END DO\n\n 10 CLOSE(2)\n\n PRINT ('(I0)'), INT(PRIME_NUM_LARGEST)\n\nEND PROGRAM F003\n", "meta": {"hexsha": "d13968dd07f96cf5ed11ced8115f19c6ea893d9e", "size": 825, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "problems/003/003.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/003/003.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/003/003.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": 25.0, "max_line_length": 88, "alphanum_fraction": 0.6036363636, "num_tokens": 265, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970654616712, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6623704730532239}} {"text": "MODULE PolynomialBasisModuleX_Legendre\n\n USE KindModule, ONLY: &\n DP\n USE QuadratureModule, ONLY: &\n InitializeQuadratures, &\n xG5, wG5\n USE ProgramHeaderModule, ONLY: &\n nDOFX, nNodesX, nDimsX, nNodes\n\n IMPLICIT NONE\n PRIVATE\n\n INTERFACE\n PURE REAL(DP) FUNCTION Basis( X )\n USE KindModule, ONLY: DP\n REAL(DP), INTENT(IN) :: X\n END FUNCTION Basis\n END INTERFACE\n\n TYPE :: PolynomialBasisType\n PROCEDURE (Basis), POINTER, NOPASS :: P\n END TYPE PolynomialBasisType\n\n INTEGER, DIMENSION(:,:), ALLOCATABLE, PUBLIC :: IndPX_Q\n REAL(DP), DIMENSION(:), ALLOCATABLE, PUBLIC :: MassPX\n TYPE(PolynomialBasisType), DIMENSION(:), ALLOCATABLE, PUBLIC :: P_X1\n TYPE(PolynomialBasisType), DIMENSION(:), ALLOCATABLE, PUBLIC :: P_X2\n TYPE(PolynomialBasisType), DIMENSION(:), ALLOCATABLE, PUBLIC :: P_X3\n\n PUBLIC :: InitializePolynomialBasisX_Legendre\n PUBLIC :: evalPX\n\nCONTAINS\n\n\n SUBROUTINE InitializePolynomialBasisX_Legendre\n\n CALL InitializeQuadratures\n\n ALLOCATE( P_X1(nNodesX(1)) )\n CALL InitializeBasis( P_X1 )\n\n ALLOCATE( P_X2(nNodesX(2)) )\n CALL InitializeBasis( P_X2 )\n\n ALLOCATE( P_X3(nNodesX(3)) )\n CALL InitializeBasis( P_X3 )\n\n ALLOCATE( IndPX_Q(1:3,nDOFX) )\n CALL InitializeIndices_TensorProductBasis\n\n ALLOCATE( MassPX(nDOFX) )\n CALL ComputeMassMatrix\n\n END SUBROUTINE InitializePolynomialBasisX_Legendre\n\n\n SUBROUTINE InitializeBasis( P )\n\n TYPE(PolynomialBasisType), DIMENSION(:) :: P\n\n SELECT CASE ( SIZE( P ) )\n\n CASE ( 1 )\n\n P(1) % P => Legendre_0\n\n CASE ( 2 )\n\n P(1) % P => Legendre_0\n P(2) % P => Legendre_1\n\n CASE ( 3 )\n\n P(1) % P => Legendre_0\n P(2) % P => Legendre_1\n P(3) % P => Legendre_2\n\n CASE ( 4 )\n\n P(1) % P => Legendre_0\n P(2) % P => Legendre_1\n P(3) % P => Legendre_2\n P(4) % P => Legendre_3\n\n CASE DEFAULT\n\n WRITE(*,*)\n WRITE(*,*) \" Invalid Basis Size \"\n STOP\n\n END SELECT\n\n END SUBROUTINE InitializeBasis\n\n\n SUBROUTINE InitializeIndices_TensorProductBasis\n\n INTEGER :: i, ik, kMax, ik_X1, ik_X2, ik_X3\n\n kMax = nDimsX * nNodes\n\n i = 0\n DO ik = 0, kMax\n DO ik_X3 = 0, nNodesX(3) - 1\n DO ik_X2 = 0, nNodesX(2) - 1\n DO ik_X1 = 0, nNodesX(1) - 1\n\n IF( SUM( [ ik_X1, ik_X2, ik_X3 ] ) == ik )THEN\n\n i = i + 1\n\n IndPX_Q(1:3,i) = [ ik_X1+1, ik_X2+1, ik_X3+1 ]\n\n END IF\n\n END DO\n END DO\n END DO\n END DO\n\n END SUBROUTINE InitializeIndices_TensorProductBasis\n\n\n SUBROUTINE ComputeMassMatrix\n\n INTEGER :: i, j\n INTEGER :: qX1, qX2, qX3\n\n MassPX = 0.0_DP\n DO j = 1, nDOFX\n DO i = 1, nDOFX\n\n IF( i /= j ) cycle ! --- Diagonal Mass Matrix\n\n DO qX3 = 1, SIZE( xG5 )\n DO qX2 = 1, SIZE( xG5 )\n DO qX1 = 1, SIZE( xG5 )\n\n MassPX(i) &\n = MassPX(i) &\n + wG5(qX1) * wG5(qX2) * wG5(qX3) &\n * P_X1(IndPX_Q(1,i)) % P( xG5(qX1) ) &\n * P_X2(IndPX_Q(2,i)) % P( xG5(qX2) ) &\n * P_X3(IndPX_Q(3,i)) % P( xG5(qX3) ) &\n * P_X1(IndPX_Q(1,j)) % P( xG5(qX1) ) &\n * P_X2(IndPX_Q(2,j)) % P( xG5(qX2) ) &\n * P_X3(IndPX_Q(3,j)) % P( xG5(qX3) )\n\n END DO\n END DO\n END DO\n\n END DO\n END DO\n\n MassPX = 1.0_DP / MassPX ! --- Store as Inverse\n\n END SUBROUTINE ComputeMassMatrix\n\n\n PURE REAL(DP) FUNCTION evalPX( u, X1, X2, X3 )\n\n REAL(DP), INTENT(in) :: u(1:nDOFX), X1, X2, X3\n\n INTEGER :: i\n\n evalPX = 0.0_DP\n DO i = 1, nDOFX\n\n evalPX &\n = evalPX &\n + P_X1(IndPX_Q(1,i)) % P( X1 ) &\n * P_X2(IndPX_Q(2,i)) % P( X2 ) &\n * P_X3(IndPX_Q(3,i)) % P( X3 ) &\n * u(i)\n\n END DO\n\n RETURN\n END FUNCTION evalPX\n\n\n !***************************************************************************\n ! Elements of Legendre Polynomial Basis\n !***************************************************************************\n\n\n PURE REAL(DP) FUNCTION Legendre_0( x )\n REAL(DP), INTENT(IN) :: x\n Legendre_0 = 1.0_DP\n RETURN\n END FUNCTION Legendre_0\n\n\n PURE REAL(DP) FUNCTION Legendre_1( x )\n REAL(DP), INTENT(IN) :: x\n Legendre_1 = x\n RETURN\n END FUNCTION Legendre_1\n\n\n PURE REAL(DP) FUNCTION Legendre_2( x )\n REAL(DP), INTENT(IN) :: x\n Legendre_2 = x**2 - 1.0_DP / 12.0_DP\n RETURN\n END FUNCTION Legendre_2\n\n\n PURE REAL(DP) FUNCTION Legendre_3( x )\n REAL(DP), INTENT(IN) :: x\n Legendre_3 = x * ( x**2 - 3.0_DP / 20.0_DP )\n RETURN\n END FUNCTION Legendre_3\n\n\nEND MODULE PolynomialBasisModuleX_Legendre\n", "meta": {"hexsha": "ebe48fecc4d6578188248c845725750dd66ff8e7", "size": 4677, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Modules/Library/PolynomialBasisModuleX_Legendre.f90", "max_stars_repo_name": "srichers/thornado", "max_stars_repo_head_hexsha": "bc6666cbf9ae8b39b1ba5feffac80303c2b1f9a8", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-12-08T16:16:55.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-24T19:31:21.000Z", "max_issues_repo_path": "Modules/Library/PolynomialBasisModuleX_Legendre.f90", "max_issues_repo_name": "srichers/thornado", "max_issues_repo_head_hexsha": "bc6666cbf9ae8b39b1ba5feffac80303c2b1f9a8", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2019-07-10T20:13:15.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-11T13:21:00.000Z", "max_forks_repo_path": "Modules/Library/PolynomialBasisModuleX_Legendre.f90", "max_forks_repo_name": "srichers/thornado", "max_forks_repo_head_hexsha": "bc6666cbf9ae8b39b1ba5feffac80303c2b1f9a8", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2018-11-14T01:13:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-24T02:08:20.000Z", "avg_line_length": 21.3561643836, "max_line_length": 78, "alphanum_fraction": 0.5497113534, "num_tokens": 1645, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797068590724, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.662370465615679}} {"text": " FUNCTION CANG (Z)\nC\nC CANG RETURNS THE PHASE ANGLE OF A COMPLEX NUMBER IN DEGREES.\nC\n COMPLEX Z\n CANG=ATGN2(AIMAG(Z),REAL(Z))*57.29577951\n RETURN\n END\n", "meta": {"hexsha": "9be779d81169ae9e4d3c1946b62c70950ab47f7f", "size": 181, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "NEC2/src/nec/cang.f", "max_stars_repo_name": "ViperScience/ViperNEC", "max_stars_repo_head_hexsha": "13394358ebfd64c75163e8fab49bdec66accfcb8", "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": "NEC2/src/nec/cang.f", "max_issues_repo_name": "ViperScience/ViperNEC", "max_issues_repo_head_hexsha": "13394358ebfd64c75163e8fab49bdec66accfcb8", "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": "NEC2/src/nec/cang.f", "max_forks_repo_name": "ViperScience/ViperNEC", "max_forks_repo_head_hexsha": "13394358ebfd64c75163e8fab49bdec66accfcb8", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.1111111111, "max_line_length": 66, "alphanum_fraction": 0.6187845304, "num_tokens": 63, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9059898203834277, "lm_q2_score": 0.731058584489497, "lm_q1q2_score": 0.6623316356514023}} {"text": "program rhop\n \n use omp_lib\n\n real(kind=8), allocatable, dimension (:,:,:) :: t, p, qv, qc, qi, rho\n integer:: isize, jsize, ksize\n integer :: i,j,k, cnt\n\n real :: pc_r_d, pc_rvd_o\n real(kind=8) :: startt, endt\n real(kind=8) :: mean\n\n pc_r_d = 287.05\n pc_rvd_o = 461.51 / pc_r_d - 1.0\n\n\n isize = 1024\n jsize = 1024\n ksize = 80\n allocate(t(isize, jsize, ksize))\n allocate(p(isize, jsize, ksize))\n allocate(qv(isize, jsize, ksize))\n allocate(qc(isize, jsize, ksize))\n allocate(qi(isize, jsize, ksize))\n allocate(rho(isize, jsize, ksize))\n\n do k=1, ksize\n do i=1, isize\n do j=1, jsize\n p(i,j,k) = 1+i\n t(i,j,k) = 0.1*i\n qv(i,j,k) = 0.02*j\n qc(i,j,k) = p(i,j,k)*1.1\n qi(i,j,k) = 0.3*i\n rho(i,j,k) = 1.1*k\n enddo\n enddo\n enddo\n mean = 0\n do cnt=1, 100\n startt = omp_get_wtime()\n!$omp parallel do\n do k=1, ksize\n do i=2, isize-1\n do j=2, jsize-1\n rho(i,j,k) = p(i,j,k) * (t(i+1,j,k) + t(i-1,j,k) + t(i,j-1,k) + t(i,j+1,k))*0.25 \n enddo\n enddo\n enddo\n!$omp end parallel do\n endt = omp_get_wtime()\n write(*,*) \"KK\" , endt-startt, rho(cnt,cnt,4)\n mean = mean + (endt-startt)\n enddo \n\n write(*,*) \"Mean \", mean/100.0\nend program\n\n!def rho(t, p, qv, qc, qi):\n! return p / ( pc_r_d * t * (1.0 + pc_rvd_o * qv - qc - qi) )\n\n\n", "meta": {"hexsha": "751f4233520d19036845285ac04118d871c35feb", "size": 1347, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "avg.f90", "max_stars_repo_name": "cosunae/numbabench", "max_stars_repo_head_hexsha": "c41e34c8e1f736103b3a315bd6b26ba4785c2647", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "avg.f90", "max_issues_repo_name": "cosunae/numbabench", "max_issues_repo_head_hexsha": "c41e34c8e1f736103b3a315bd6b26ba4785c2647", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "avg.f90", "max_forks_repo_name": "cosunae/numbabench", "max_forks_repo_head_hexsha": "c41e34c8e1f736103b3a315bd6b26ba4785c2647", "max_forks_repo_licenses": ["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.380952381, "max_line_length": 91, "alphanum_fraction": 0.5352635486, "num_tokens": 570, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989822921759, "lm_q2_score": 0.7310585786300048, "lm_q1q2_score": 0.6623316321984308}} {"text": "program SphereMLSQTester\n\nuse NumberKindsModule\nuse OutputWriterModule\nuse LoggerModule\nuse PolyMesh2dModule\nuse ParticlesModule\nuse EdgesModule\nuse FacesModule\nuse STDIntVectorModule\nuse FieldModule\nuse SphereGeomModule\nuse MPISetupModule\nuse MLSQModule\n\nimplicit none\n\ninclude 'mpif.h'\n\n!\n!\tlogger / console output\n!\ntype(Logger) :: exeLog\ncharacter(len=MAX_STRING_LENGTH) :: logstring\ncharacter(len=18) :: logKey = \"sphereMLSQ\"\ninteger(kint), parameter :: logLevel = DEBUG_LOGGING_LEVEL\n!\n!\tmesh\n!\ntype(PolyMesh2d) :: sphere\ninteger(kint) :: initNest\ninteger(kint) :: maxNest\ninteger(kint) :: amrLimit\nreal(kreal) :: radius\ninteger(kint) :: faceType\ninteger(kint) :: meshSeed\n!\n!\tinterpolation\n!\ntype(MLSQ) :: scalarMlsq, vectorMlsq\nreal(kreal), allocatable :: lons(:)\nreal(kreal), allocatable :: lats(:)\nreal(kreal), allocatable :: scalarInterp(:,:), scalarGradX(:,:), scalarGradY(:,:), scalarGradZ(:,:), scalarLap(:,:)\nreal(kreal), allocatable :: exactScalar(:,:), exactScalarGradX(:,:), exactScalarGradY(:,:), exactScalarGradZ(:,:)\nreal(kreal), allocatable :: exactScalarLap(:,:)\ninteger(kint) :: nLon, nLat\n\ntype(Field) :: testScalar, testVector\ntype(Field) :: estGrad\ntype(Field) :: estLap\ntype(Field) :: exactGrad\ntype(Field) :: exactLap\ntype(Field) :: estDoubleDot\ntype(Field) :: exactDoubleDot\n\n!\n!\tMPI\n!\ntype(MPISetup) :: interpMPI\ninteger(kint) :: mpiErrCode\n\n!\n!\tgeneral\n!\nreal(kreal) :: programStart, programEnd\ninteger(kint) :: i, j\ncharacter(len=MAX_STRING_LENGTH) :: namelistFile, outputDir, outputRoot, matlabFile, vtkFile\ncharacter(len=12) :: meshString\nreal(kreal) :: xij(3), vecA(3)\n\nnamelist /mlsqTest/ initNest, faceType, radius, nLon, outputDir, outputRoot\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!! PROGRAM START \n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tInitialize computing environment\n!\ncall MPI_INIT(mpiErrCode)\ncall MPI_COMM_SIZE(MPI_COMM_WORLD, numProcs, mpiErrCode)\ncall MPI_COMM_RANK(MPI_COMM_WORLD, procRank, mpiErrCode)\n\ncall InitLogger(exeLog, procRank)\n\ncall ReadNamelistFile(procRank)\n\nprogramStart = MPI_WTIME()\n\n!\n!\tInitialize sphere mesh\n!\namrLimit = 0\nmaxNest = initNest\ncall New(sphere, meshSeed, initNest, maxNest, amrLimit, radius )\n\ncall LogStats(sphere, exeLog)\n\n!\n!\tInitialize interpolation tests\n!\nallocate(lons(nLon))\nallocate(lats(nLat))\nallocate(scalarInterp(nLat, nLon))\nallocate(scalarGradX(nLat, nLon))\nallocate(scalarGradY(nLat, nLon))\nallocate(scalarGradZ(nLat, nLon))\nallocate(scalarLap(nLat, nLon))\nallocate(exactScalar(nLat, nLon))\nallocate(exactScalarGradX(nLat, nLon))\nallocate(exactScalarGradY(nLat, nLon))\nallocate(exactScalarGradZ(nLat, nLon))\nallocate(exactScalarLap(nLat,nLon))\n\ndo j = 1, nLon\n\tlons(j) = real(j-1, kreal) * DEG_2_RAD\nenddo\ndo i = 1, nLat\n\tlats(i) = -0.5_kreal * PI + real(i-1,kreal) * DEG_2_RAD\nenddo\n\ncall New(testScalar, 1, sphere%particles%N, 'sphHarm', 'n/a')\ncall New(testVector, 3, sphere%particles%N, 'tangentVector','n/a')\ncall New(estGrad, 3, sphere%particles%N, 'estGrad', 'n/a')\ncall New(exactGrad, 3, sphere%particles%N, 'exactGrad', 'n/a')\ncall New(estLap, 1, sphere%particles%N, 'estLap', 'n/a')\ncall New(exactLap, 1, sphere%particles%N, 'exactLap', 'n/a')\ncall New(estDoubleDot, 1, sphere%particles%N, 'estDoubleDot', 'n/a')\ncall New(exactDoubleDot, 1, sphere%particles%N,'exactDoubleDot','n/a')\n\ndo j = 1, nLon\n\tdo i = 1, nLat\n\t\txij = [ radius * cos(lons(j)) * cos(lats(i)), radius * sin(lons(j)) * cos(lats(i)), radius * sin(lats(i)) ]\n\t\texactScalar(i,j) = SphereHarmonic54( xij )\n\t\tvecA = HarmGradient( xij )\n\t\texactScalarGradX(i,j) = vecA(1)\n\t\texactScalarGradY(i,j) = vecA(2)\n\t\texactScalarGradZ(i,j) = vecA(3)\n\t\texactScalarLap(i,j) = - 30.0_kreal * SphereHarmonic54( xij )\n\tenddo\nenddo\n\ndo i = 1, sphere%particles%n\n\txij = PhysCoord(sphere%particles, i)\n\tcall InsertScalarToField( testScalar, SphereHarmonic54(xij) )\n\tcall InsertVectorToField( testVector, VectorFromLinearPotential(xij))\nenddo\n\ncall MPI_BARRIER(MPI_COMM_WORLD, mpiErrCode)\ncall LogMessage(exeLog, TRACE_LOGGING_LEVEL, trim(logKey), \" initialization complete... Running problem...\")\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!! PROGRAM RUN\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tperform interpolation and derivative approximation\n!\ncall New( scalarMlsq, sphere, testScalar )\n\ncall New( vectorMlsq, sphere, testVector )\n\ncall New(interpMPI, nLon, numProcs )\n\ndo j = interpMPI%indexStart(procRank), interpMPI%indexEnd(procRank)\n\tdo i = 1, nLat\n\t\txij = [ radius * cos(lons(j)) * cos(lats(i)), radius * sin(lons(j)) * cos(lats(i)), radius * sin(lats(i)) ]\n\t\tscalarInterp(i,j) = InterpolateScalar( scalarMlsq, sphere, xij )\n\t\tvecA = InterpolateScalarGradient( scalarMlsq, sphere, xij )\n\t\tscalarGradX(i,j) = vecA(1)\n\t\tscalarGradY(i,j) = vecA(2)\n\t\tscalarGradZ(i,j) = vecA(3)\n\t\tscalarLap(i,j) = InterpolateScalarLaplacian( scalarMlsq, sphere, xij )\n\tenddo\nenddo\n\ncall MLSQGradientAtParticles( scalarMlsq, sphere, estGrad )\n\ncall MLSQLaplacianAtParticles( scalarMlsq, sphere, estLap )\n\ncall MLSQDoubleDotProductAtParticles( vectorMlsq, sphere, estDoubleDot )\n\ndo i = 0, numProcs - 1\n\tcall MPI_BCAST( scalarInterp(:, interpMPI%indexStart(i):interpMPI%indexEnd(i)), nLat * interpMPI%messageLength(i), &\n\t\tMPI_DOUBLE_PRECISION, i, MPI_COMM_WORLD, mpiErrCode)\n\tcall MPI_BCAST( scalarGradX(:, interpMPI%indexStart(i):interpMPI%indexEnd(i)), nLat * interpMPI%messageLength(i), &\n\t\tMPI_DOUBLE_PRECISION, i, MPI_COMM_WORLD, mpiErrCode)\n\tcall MPI_BCAST( scalarGradY(:, interpMPI%indexStart(i):interpMPI%indexEnd(i)), nLat * interpMPI%messageLength(i), &\n\t\tMPI_DOUBLE_PRECISION, i, MPI_COMM_WORLD, mpiErrCode)\t\t\n\tcall MPI_BCAST( scalarGradZ(:, interpMPI%indexStart(i):interpMPI%indexEnd(i)), nLat * interpMPI%messageLength(i), &\n\t\tMPI_DOUBLE_PRECISION, i, MPI_COMM_WORLD, mpiErrCode)\t\t\n\tcall MPI_BCAST( scalarLap(:, interpMPI%indexStart(i):interpMPI%indexEnd(i)), nLat * interpMPI%messageLength(i), &\n\t\tMPI_DOUBLE_PRECISION, i, MPI_COMM_WORLD, mpiErrCode)\t\t\nenddo\n\n!\n!\twrite output\n!\nif ( procRank == 0 ) then\n\topen(unit=WRITE_UNIT_1, file=vtkFile, status='REPLACE', action='WRITE')\n\t\t! vtk header and point locations\n\t\tcall WriteVTKPoints( sphere%particles, WRITE_UNIT_1, 'SphereMLSQTester')\n\t\t! vtk polydata\n\t\tcall WriteFacesToVTKPolygons( sphere%faces, WRITE_UNIT_1 )\n\t\t! point data section header\n\t\tcall WriteVTKPointDataSectionHeader( WRITE_UNIT_1, sphere%particles%N)\n\t\t! fields @ points\n\t\tcall WriteVTKLagCoords( sphere%particles, WRITE_UNIT_1)\n\t\tcall WriteFieldToVTKPointData( testScalar, WRITE_UNIT_1 )\n\t\tcall WriteFieldToVTKPointData( estGrad, WRITE_UNIT_1 )\n\t\tcall WriteFieldToVTKPointData( estLap, WRITE_UNIT_1)\n\t\tcall WriteFieldToVTKPointData( testVector, WRITE_UNIT_1 )\n\t\tcall WriteFieldToVTKPointData( estDoubleDot, WRITE_UNIT_1)\n\t\tcall WriteFieldToVTKPointData( exactGrad, WRITE_UNIT_1)\n\t\tcall WriteFieldToVTKPointData( exactLap, WRITE_UNIT_1 )\n\t\t!\tfields @ cells\n\t\tcall WriteFaceAreaToVTKCellData( sphere%faces, sphere%particles, WRITE_UNIT_1)\n\tclose(WRITE_UNIT_1)\n\topen(unit=WRITE_UNIT_1, file=matlabFile, status='REPLACE', action='WRITE')\n\t\tcall WriteToMatlab( lons, WRITE_UNIT_1, \"lons\" )\n\t\tcall WriteToMatlab( lats, WRITE_UNIT_1, \"lats\" )\n\t\tcall WriteToMatlab( scalarInterp, WRITE_UNIT_1, \"scalarInterp\")\n\t\tcall WriteToMatlab( exactScalar, WRITE_UNIT_1, \"exactScalar\")\n\t\tcall WriteToMatlab( scalarGradX, WRITE_UNIT_1, \"scalarGradX\")\n\t\tcall WriteToMatlab( scalarGradY, WRITE_UNIT_1, \"scalarGradY\")\n\t\tcall WriteToMatlab( scalarGradZ, WRITE_UNIT_1, \"scalarGradZ\")\n\t\tcall WriteToMatlab( exactScalarGradX, WRITE_UNIT_1, \"exactScalarGradX\")\n\t\tcall WriteToMatlab( exactScalarGradY, WRITE_UNIT_1, \"exactScalarGradY\")\n\t\tcall WriteToMatlab( exactScalarGradZ, WRITE_UNIT_1, \"exactScalarGradZ\")\n\t\tcall WriteToMatlab( scalarLap, WRITE_UNIT_1, \"scalarLap\")\n\t\tcall WriteToMatlab( exactScalarLap, WRITE_UNIT_1, \"exactScalarLap\")\n\tclose(WRITE_UNIT_1)\nendif\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!! PROGRAM END\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nprogramEnd = MPI_WTIME()\n\nif ( procRank == 0 ) then\n\twrite(6,'(A,F12.2,A)') \"PROGRAM COMPLETE : elapsed time = \", programEnd - programStart, \" seconds.\"\nendif\n\ncall Delete(interpMPI)\ncall Delete(scalarMlsq)\ncall Delete(vectorMlsq)\ncall Delete(estGrad)\ncall Delete(estLap)\ncall Delete(estDoubleDot)\ncall Delete(exactDoubleDot)\ncall Delete(testVector)\ncall Delete(testScalar)\ndeallocate(exactScalarLap)\ndeallocate(exactScalar)\ndeallocate(exactScalarGradZ)\ndeallocate(exactScalarGradY)\ndeallocate(exactScalarGradX)\ndeallocate(scalarLap)\ndeallocate(scalarGradZ)\ndeallocate(scalarGradY)\ndeallocate(scalarGradX)\ndeallocate(scalarInterp)\ndeallocate(lats)\ndeallocate(lons)\ncall Delete(exeLog)\ncall MPI_FINALIZE(mpiErrCode)\n\ncontains\n\npure function SolidBodyRotationVelocity( xyz )\n\treal(kreal), dimension(3) :: SolidBodyRotationVelocity\n\treal(kreal), dimension(3), intent(in) :: xyz\n\t!\n\treal(kreal), parameter :: OMG = 2.0_kreal * PI\n\t\n\tSolidBodyRotationVelocity(1) = - OMG * xyz(2)\n\tSolidBodyRotationVelocity(2) = OMG * xyz(1)\n\tSolidBodyRotationVelocity(3) = \t 0.0_kreal\nend function \n\npure function VectorFromLinearPotential( xyz )\n\treal(kreal), dimension(3) :: VectorFromLinearPotential\n\treal(kreal), dimension(3), intent(in) :: xyz\n\tVectorFromLinearPotential(1) = 1.0_kreal - xyz(1) * xyz(1)\n\tVectorFromLinearPotential(2) = - xyz(1) * xyz(2)\n\tVectorFromLinearPotential(3) = - xyz(1) * xyz(3)\nend function\n\npure function SphereHarmonic54(xyz)\n\treal(kreal) :: SphereHarmonic54\n\treal(kreal), intent(in) :: xyz(3)\n\tSphereHarmonic54 = 3.0_kreal * sqrt(35.0_kreal) * cos( 4.0_kreal * Longitude(xyz)) * sin(Latitude(xyz)) * &\n\t\t\t\t\t (-1.0_kreal + sin(Latitude(xyz)) * sin(Latitude(xyz)))**2\nend function\n\npure function HarmGradient( xyz ) \n\treal(kreal) :: HarmGradient(3)\n\treal(kreal), intent(in) :: xyz(3)\n\t!\n\treal(kreal) :: lon, lat, u, v\n\t\n\tlat = Latitude(xyz)\n\tlon = Longitude(xyz)\n\t\n\tu = -12.0_kreal * sqrt(35.0_kreal) * sin(4.0_kreal * lon) * (-1.0_kreal + sin(lat)*sin(lat))**2 * tan(lat)\n\tv = 12.0_kreal * sqrt(35.0_kreal) * cos(4.0_kreal * lon) * sin(lat) * sin(lat)*(-1.0_kreal + sin(lat)*sin(lat)) + &\n\t3.0_kreal * sqrt(35.0_kreal) * cos(4.0_kreal * lon)*cos(lat)*(-1.0_kreal + sin(lat)*sin(lat))**2\n\t\n\tHarmGradient(1) = -u * sin(lon) - v*sin(lat)*cos(lon)\n\tHarmGradient(2) = u * cos(lon) - v * sin(lat)*sin(lon)\n\tHarmGradient(3) = v * cos(lat)\nend function\n\nsubroutine ReadNamelistFile(rank)\n\tinteger(kint), intent(in) :: rank\n\t!\n\tinteger(kint), parameter :: initBCAST_intSize = 4\n\tinteger(kint), parameter :: initBCAST_realSize = 1\n\tinteger(kint) :: readStat\n\tinteger(kint) :: bcastIntegers(initBCAST_intSize)\n\treal(kreal) :: bcastReals(initBCAST_realSize)\n\t\n\tif ( COMMAND_ARGUMENT_COUNT() /= 1 ) then\n\t\tcall LogMessage(exeLog,ERROR_LOGGING_LEVEL, trim(logKey), \" expected namelist file name as 1st argument.\")\n\t\tstop\n\tendif\n\t\n\tif ( rank == 0 ) then\n\t\tcall GET_COMMAND_ARGUMENT(1, namelistFile)\n\t\t\n\t\topen(unit = READ_UNIT, file=namelistFile, status='OLD', action='READ', iostat = readstat)\n\t\t\tif (readStat /= 0 ) then\t\n\t\t\t\tcall LogMessage(exeLog, ERROR_LOGGING_LEVEL, trim(logKey), \" cannot read namelist file.\")\n\t\t\t\tstop\n\t\t\tendif\n\t\t\t\n\t\t\tread(READ_UNIT,nml=mlsqTest)\n\t\tclose(READ_UNIT)\t\t\t\n\t\t\n\t\tif ( faceType == 3 ) then\n\t\t\tmeshSeed = ICOS_TRI_SPHERE_SEED\n\t\t\twrite(meshString,'(A,I1)') 'icosTri', initNest\n\t\telseif ( faceType == 4) then\n\t\t\tmeshSeed = CUBED_SPHERE_SEED\n\t\t\twrite(meshString,'(A,I1)') 'cubedSphere', initNest\n\t\telse\n\t\t\tcall LogMessage(exeLog, WARNING_LOGGING_LEVEL, trim(logKey)//\" ReadNamelistFile WARNING :\", &\n\t\t\t\t\" invalid faceKind -- using triangles.\")\n\t\t\tmeshSeed = ICOS_TRI_SPHERE_SEED\n\t\t\twrite(meshString,'(A,I1)') 'icosTri', initNest\n\t\tendif\n\t\n\t\twrite(matlabFile,'(A,A,A,A,A,A)') trim(outputDir), '/', trim(outputRoot), '_', trim(meshString), '.m'\n\t\twrite(vtkFile,'(A,A,A,A,A,A)') trim(outputDir), '/', trim(outputRoot), '_', trim(meshString), '.vtk'\n\t\n\t\tbcastIntegers(1) = meshSeed\n\t\tbcastIntegers(2) = initNest\n\t\tbcastIntegers(3) = nLon\n\t\tbcastIntegers(4) = nLon / 2 + 1\n\t\t\n\t\tbcastReals(1) = radius\n\tendif\n\t\n\tcall MPI_BCAST( bcastIntegers, initBCAST_intSize, MPI_INTEGER, 0, MPI_COMM_WORLD, mpiErrCode)\n\tcall MPI_BCAST( bcastReals, initBCAST_realSize, MPI_DOUBLE_PRECISION, 0, MPI_COMM_WORLD, mpiErrCode)\n\t\n\tmeshSeed = bcastIntegers(1)\n\tinitNest = bcastIntegers(2)\n\tnLon = bcastIntegers(3)\n\tnLat = bcastIntegers(4)\n\t\n\tradius = bcastReals(1)\nend subroutine\n\nsubroutine InitLogger(aLog,rank)\n! Initialize a logger for this processor\n\ttype(Logger), intent(out) :: aLog\n\tinteger(kint), intent(in) :: rank\n\twrite(logKey,'(A,A,I0.2,A)') trim(logKey),'_',rank,' : '\n\tif ( rank == 0 ) then\n\t\tcall New(aLog,logLevel)\n\telse\n\t\tcall New(aLog,ERROR_LOGGING_LEVEL)\n\tendif\nend subroutine\n\nend program", "meta": {"hexsha": "6077e2052c408681bfe65cc9163833b612a7889d", "size": 12657, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "development/SphereMLSQTest.f90", "max_stars_repo_name": "pbosler/LPPM", "max_stars_repo_head_hexsha": "33b9572120ceca28ee56630a1af54f3befbda672", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "development/SphereMLSQTest.f90", "max_issues_repo_name": "pbosler/LPPM", "max_issues_repo_head_hexsha": "33b9572120ceca28ee56630a1af54f3befbda672", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2015-01-21T21:50:20.000Z", "max_issues_repo_issues_event_max_datetime": "2015-01-21T21:54:31.000Z", "max_forks_repo_path": "development/SphereMLSQTest.f90", "max_forks_repo_name": "pbosler/LPPM", "max_forks_repo_head_hexsha": "33b9572120ceca28ee56630a1af54f3befbda672", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.7901554404, "max_line_length": 117, "alphanum_fraction": 0.7228411156, "num_tokens": 4023, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989810230102, "lm_q2_score": 0.7310585844894971, "lm_q1q2_score": 0.6623316282287265}} {"text": "!!\n!! @author R.C. Singleton\n!! @author M. Olesen\n!! @author J. Beale\n!! @author D. Wortmann\n!! @author Paul Baumeister\n!! @version 0.0\n!!\n!!>This code is a replacement of the old FFT code\n!! It has been modified to\n!! 1. Not to use any kind-parameter\n!! 2. to be fixed-format compatible\n!! 3. Some further changes are marked by !DW\n!! D. Wortmann\n!!<4. Fixed-format was removed again ! PB P.Baumeister\n!!\n!!-----------------------------------------------------------------------------\n!! Multivariate Fast Fourier Transform\n!!\n!! Fortran 90 (ELF90) Implementation of Singleton's mixed-radix algorithm,\n!! RC Singleton, Stanford Research Institute, Sept. 1968.\n!!\n!! Adapted from fftn.c, translated from Fortran 66 to C by Mark Olesen and\n!! John Beale.\n!!\n!! Fourier transforms can be computed either in place, using assumed size\n!! arguments, or by generic function, using assumed shape arguments.\n!!\n!!\n!! Public:\n!!\n!! fftkind kind parameter of complex :: arguments\n!! and function results.\n!!\n!! fft(array, dims, inv) generic transform function\n!! COMPLEX(fftkind), DIMENSION(:,...,:), INTENT(IN) :: array\n!! INTEGER, DIMENSION(:), INTENT(IN), OPTIONAL :: dims\n!! LOGICAL, INTENT(IN), OPTIONAL :: inv\n!!\n!! fftn(array, shape, dim, inv, stat) in place transform subroutine\n!! COMPLEX(fftkind), DIMENSION(*), INTENT(INOUT) :: array\n!! INTEGER, DIMENSION(:), INTENT(IN) :: shape\n!! INTEGER, DIMENSION(:), INTENT(IN), OPTIONAL :: dims\n!! LOGICAL, INTENT(IN), OPTIONAL :: inv\n!! INTEGER, INTENT(OUT), OPTIONAL :: stat\n!!\n!!\n!! Formal Parameters:\n!!\n!! array The complex :: array to be transformed. array can be of arbitrary\n!! rank (i.e. up to seven).\n!!\n!! shape With subroutine fftn, the shape of the array to be transformed\n!! has to be passed separately, since fftradix - the internal trans-\n!! formation routine - will treat array always as one dimensional.\n!! The product of elements in shape must be the number of\n!! elements in array.\n!! Although passing array with assumed shape would have been nicer,\n!! I prefered assumed size in order to prevent the compiler from\n!! using a copy-in-copy-out mechanism. That would generally be\n!! necessary with fftn passing array to fftradix and with fftn\n!! being prepared for accepting non consecutive array sections.\n!! Using assumed size, it's up to the user to pass an array argu-\n!! ment, that can be addressed as continous one dimensional array\n!! without copying. Otherwise, transformation will not really be\n!! performed in place.\n!! On the other hand, since the rank of array and the size of\n!! shape needn't match, fftn is appropriate for handling more than\n!! seven dimensions.\n!! As far as function fft is concerned all this doesn't matter,\n!! because the argument will be copied anyway. Thus no extra\n!! shape argument is needed for fft.\n!!\n!! Optional Parameters:\n!!\n!! dims One dimensional integer :: array, containing the dimensions to be\n!! transformed. Default is (/1,...,N/) with N being the rank of\n!! array, i.e. complete transform. dims can restrict transformation\n!! to a subset of available dimensions. Its size must not exceed the\n!! rank of array or the size of shape respectivly.\n!!\n!! inv If .true., inverse transformation will be performed. Default is\n!! .false., i.e. forward transformation.\n!!\n!! stat If present, a system dependent nonzero status value will be\n!! returned in stat, if allocation of temporary storage failed.\n!! For functions, the integer :: variable status is used.\n!!\n!! Scaling:\n!!\n!! Transformation results will always be scaled by the square root of the\n!! product of sizes of each dimension in dims. (See examples below)\n!!\n!!\n!! Examples:\n!!\n!! Let A be a L*M*N three dimensional complex :: array. Then\n!!\n!! result = fft(A)\n!!\n!! will produce a three dimensional transform, scaled by sqrt(L*M*N), while\n!!\n!! call fftn(A, SHAPE(A))\n!!\n!! will do the same in place.\n!!\n!! result = fft(A, dims = (/1,3/))\n!!\n!! will transform with respect to the first and the third dimension, scaled\n!! by sqrt(L*N).\n!!\n!! result = fft(fft(A), inv = .true.)\n!!\n!! should (approximately) reproduce A.\n!! With B having the same shape as A\n!!\n!! result = fft(fft(A) * CONJG(fft(B)), inv = .true.)\n!!\n!! will correlate A and B.\n!!\n!!\n!! Remarks:\n!!\n!! Following changes have been introduced with respect to fftn.c:\n!! - complex arguments and results are of type complex, rather than\n!! real an imaginary part separately.\n!! - increment parameter (magnitude of isign) has been dropped,\n!! inc is always one, direction of transform is given by inv.\n!! - maxf and maxp have been dropped. The amount of temporary storage\n!! needed is determined by the fftradix routine. Both fftn and fft\n!! can handle any size of array. (Maybe they take a lot of time and\n!! memory, but they will do it)\n!!\n!! Redesigning fftradix in a way, that it handles assumed shape arrays\n!! would have been desirable. However, I found it rather hard to do this\n!! in an efficient way. Problems were:\n!! - to prevent stride multiplications when indexing arrays. At least our\n!! compiler was not clever enough to discover that in fact additions\n!! would do the job as well. On the other hand, I haven't been clever\n!! enough to find an implementation using array operations.\n!! - fftradix is rather large and different versions would be necessaray\n!! for each possible rank of array.\n!! Consequently, in place transformation still needs the argument stored\n!! in a consecutive bunch of memory and can't be performed on array\n!! sections like A(100:199:-3, 50:1020). Calling fftn with such sections\n!! will most probably imply copy-in-copy-out. However, the function fft\n!! works with everything it gets and should be convenient to use.\n!!\n!! To enable this module to be used with ELF90 it appears to be necessary\n!! to allocate a 1-D work array into which the multi-dimensional array is\n!! copied, and then to copy the results back from the 1-D array to the\n!! multi-dimensional array ft.\n!!\n!! Unfortunately, ELF90 will not allow a function to return more than one\n!! output variable. The variable `stat' has been dropped from the function\n!! arguments. Users should examine the value of the variable `status'\n!! instead. This is a PUBLIC variable declared in this module.\n!!\n!! Michael Steffens, 09.12.96, \n!! ELF90-compatible version by Alan Miller, 29 April 1997 & 6 June 1997\n!! amiller @ bigpond.net.au\n!! Restructured fftradix for better optimization by M. Steffens, 4 June 1997\n!!-----------------------------------------------------------------------------\nmodule FFT_tools\n implicit none\n private !! default visibility for this module namespace\n\n public :: fftn\n public :: fft\n public :: test\n\n interface fft\n module procedure fft1d, fft2d, fft3d, fft4d, fft5d, fft6d, fft7d\n endinterface\n\n character(len=*), parameter, private :: sym = 'fft' !! module symbol\n\n real, parameter :: sin60 = 0.86602540378443865\n real, parameter :: cos72 = 0.30901699437494742\n real, parameter :: sin72 = 0.95105651629515357\n real, parameter :: Pi = 3.14159265358979323\n\n integer, save :: status = 0 !--- shifted to here as elf90 does not allow arguments to be intent(out)\n\n contains\n\n function fft1d( a, dims, inv ) result( ft )\n !--- formal parameters\n complex, intent(in) :: a(:)\n integer, intent(in), optional :: dims(:)\n logical, intent(in), optional :: inv\n !--- function result\n complex :: ft(size(a))\n\n ft = a\n call fftn( ft, shape(a), dims, inv=inv, stat=status )\n endfunction ! fft1d\n\n\n function fft2d( a, dims, inv ) result( ft )\n !--- formal parameters\n complex, intent(in) :: a(:,:)\n integer, intent(in), optional :: dims(:)\n logical, intent(in), optional :: inv\n !--- function result\n complex :: ft(size(a,1),size(a,2))\n complex :: work(size(a))\n\n work = reshape( a, (/ size(a) /) )\n call fftn( work, shape(a), dims, inv, stat=status )\n ft = reshape( work, shape(ft) )\n endfunction ! fft2d\n\n\n function fft3d( a, dims, inv ) result( ft )\n !--- formal parameters\n complex, intent(in) :: a(:,:,:)\n integer, intent(in), optional :: dims(:)\n logical, intent(in), optional :: inv\n !--- function result\n complex :: ft(size(a,1),size(a,2),size(a,3))\n complex :: work(size(a))\n\n work = reshape( a, (/ size(a) /) )\n call fftn( work, shape(a), dims, inv, stat=status )\n ft = reshape( work, shape(ft) )\n endfunction ! fft3d\n\n\n function fft4d( a, dims, inv ) result(ft)\n !--- formal parameters\n complex, intent(in) :: a(:,:,:,:)\n integer, intent(in), optional :: dims(:)\n logical, intent(in), optional :: inv\n !--- function result\n complex :: ft(size(a,1),size(a,2),size(a,3),size(a,4))\n complex :: work(size(a))\n\n work = reshape( a, (/ size(a) /) )\n call fftn( work, shape(a), dims, inv, stat=status )\n ft = reshape( work, shape(ft) )\n endfunction ! fft4d\n\n\n function fft5d( a, dims, inv ) result(ft)\n !--- formal parameters\n complex, intent(in) :: a(:,:,:,:,:)\n integer, intent(in), optional :: dims(:)\n logical, intent(in), optional :: inv\n !--- function result\n complex :: ft(size(a,1),size(a,2),size(a,3),size(a,4),size(a,5))\n complex :: work(size(a))\n\n work = reshape( a, (/ size(a) /) )\n call fftn( work, shape(a), dims, inv, stat=status )\n ft = reshape( work, shape(ft) )\n endfunction ! fft5d\n\n\n function fft6d( a, dims, inv ) result(ft)\n !--- formal parameters\n complex, intent(in) :: a(:,:,:,:,:,:)\n integer, intent(in), optional :: dims(:)\n logical, intent(in), optional :: inv\n !--- function result\n complex :: ft(size(a,1),size(a,2),size(a,3),size(a,4),size(a,5),size(a,6))\n complex :: work(size(a))\n\n work = reshape( a, (/ size(a) /) )\n call fftn( work, shape(a), dims, inv, stat=status )\n ft = reshape( work, shape(ft) )\n endfunction ! fft6d\n\n\n function fft7d( a, dims, inv ) result(ft)\n !--- formal parameters\n complex, intent(in) :: a(:,:,:,:,:,:,:)\n integer, intent(in), optional :: dims(:)\n logical, intent(in), optional :: inv\n !--- function result\n complex :: ft(size(a,1),size(a,2),size(a,3),size(a,4),size(a,5),size(a,6),size(a,7))\n complex :: work(size(a))\n\n work = reshape( a, (/ size(a) /) )\n call fftn( work, shape(a), dims, inv, stat=status )\n ft = reshape( work, shape(ft) )\n endfunction ! fft7d\n\n\n subroutine fftn( array, shape, dims, inv, stat )\n !--- formal parameters\n complex, intent(inout) :: array(:)\n integer, intent(in) :: shape(:)\n integer, intent(in), optional :: dims(:)\n logical, intent(in), optional :: inv\n integer, intent(out), optional :: stat\n !--- local vars\n integer :: d(size(shape))\n logical :: inverse\n integer :: id, ndims, ntotal\n! real :: scal\n\n !--- optional parameter settings\n inverse = .false. ; if( present(inv) ) inverse = inv\n\n if( present(dims) ) then\n ndims = min( size(dims), size(d) )\n d(1:ndims) = dims(1:ndims)\n else\n ndims = size(d)\n d = (/ ( id, id=1,size(d) ) /) ! default is all dimensions 1,...,N\n endif\n\n ntotal = product(shape)\n\n !dw!\n !dw: no scaling!\n ! scal = sqrt( 1. / product(shape(d(1:ndims))) )\n ! array = scal * array\n\n do id = 1, ndims\n call fftradix( array, ntotal, shape(d(id)), product(shape(1:d(id))), inverse )\n enddo ! id\n\n if( present(stat) ) stat = status\n endsubroutine ! fftn\n\n subroutine fftradix( array, ntotal, npass, nspan, inv )\n !--- formal parameters\n complex, intent(inout) :: array(:)\n integer, intent(in) :: ntotal, npass, nspan\n logical, intent(in) :: inv\n !--- local arrays\n integer :: factor(bit_size(0))\n !--- local scalars\n integer :: maxfactor, nfactor, nsquare\n !--- intrinsics used\n\n if ( npass <= 1 ) return\n\n maxfactor = factorize( npass, factor, nfactor, nsquare )\n\n call transform( array, ntotal, npass, nspan, factor, nfactor, maxfactor, inv )\n call permute( array, ntotal, npass, nspan, factor, nfactor, nsquare, maxfactor )\n endsubroutine ! fftradix\n\n integer function factorize( npass, factor, nfactor, nsquare ) result( maxfactor )\n !--- formal parameters\n integer, intent(in) :: npass\n integer, intent(out) :: factor(:)\n integer, intent(out) :: nfactor, nsquare\n !--- local scalars\n integer :: j, jj, k\n\n nfactor = 0 ! init the number of factors\n k = npass\n\n ! try with 4\n do while ( mod( k, 16 ) == 0 ) ! npass can be divided by 16\n nfactor = nfactor + 1 ! increase the number of factors\n factor(nfactor) = 4 ! store the factor 4\n k = k / 16 ! proceed with the reduced number\n enddo\n ! now k does not contain any powers of 16 any more\n\n j = 3 ! try odd numbers starting from 3\n jj = j * j\n do\n do while ( mod( k, jj ) == 0 ) ! npass can be divided by j^2\n nfactor = nfactor + 1 ! increase the number of factors\n factor(nfactor) = j ! store the factor j\n k = k / jj ! proceed with the reduced number\n enddo\n j = j + 2 ! try higher odd numbers\n jj = j * j\n if ( jj > k ) exit\n enddo\n\n if ( k <= 4 ) then\n nsquare = nfactor\n factor(nfactor+1) = k\n if ( k /= 1 ) nfactor = nfactor + 1\n else ! k <= 4\n if ( k - ishft( k / 4, 2 ) == 0 ) then\n nfactor = nfactor + 1\n factor(nfactor) = 2\n k = k / 4\n endif\n nsquare = nfactor\n j = 2\n do\n if ( mod( k, j ) == 0 ) then\n nfactor = nfactor + 1\n factor(nfactor) = j\n k = k / j\n endif\n j = ishft( (j + 1) / 2, 1 ) + 1\n if ( j > k ) exit\n enddo\n endif ! k <= 4\n if ( nsquare > 0 ) then\n j = nsquare\n do\n nfactor = nfactor + 1\n factor(nfactor) = factor(j)\n j = j - 1\n if ( j == 0 ) exit\n enddo\n endif\n maxfactor = maxval( factor(:nfactor) )\n endfunction ! factorize\n\n subroutine transform( array, ntotal, npass, nspan, factor, nfactor, maxfactor, inv )\n !--- formal parameters\n complex, intent(inout) :: array(:)\n integer, intent(in) :: ntotal, npass, nspan\n integer, intent(in) :: factor(:)\n integer, intent(in) :: nfactor\n integer, intent(in) :: maxfactor\n logical, intent(in) :: inv\n !--- local scalars\n integer :: ii, ispan\n integer :: j, jc, jf, jj\n integer :: k, kk, kspan, k1, k2, k3, k4\n integer :: nn, nt\n real :: s60, c72, s72, pi2, radf\n real :: c1, s1, c2, s2, c3, s3, cd, sd, ak\n complex :: cc, cj, ck, cjp, cjm, ckp, ckm\n !--- local arrays\n ! complex, allocatable :: ctmp(:)\n ! real, allocatable :: sine(:), cosine(:)\n ! \n ! maxfactor = maxval(factor(:nfactor))\n ! allocate( ctmp(maxfactor), sine(maxfactor), cosine(maxfactor), stat=status )\n ! if (status /= 0) return\n complex :: ctmp(maxfactor)\n real :: sine(maxfactor), cosine(maxfactor)\n\n c72 = cos72\n if (inv) then\n s72 = sin72\n s60 = sin60\n pi2 = pi\n else\n s72 = -sin72\n s60 = -sin60\n pi2 = -pi\n endif\n\n nt = ntotal\n nn = nt - 1\n kspan = nspan\n jc = nspan / npass\n radf = pi2 * jc\n pi2 = pi2 * 2.0 !-- use 2 pi from here on\n\n ii = 0\n jf = 0\n do\n sd = radf / kspan\n cd = sin(sd)\n cd = 2.0 * cd * cd\n sd = sin(sd + sd)\n kk = 1\n ii = ii + 1\n\n select case (factor(ii))\n case (2)\n !-- transform for factor of 2 (including rotation factor)\n kspan = kspan / 2\n k1 = kspan + 2\n do\n do\n k2 = kk + kspan\n ck = array(k2)\n array(k2) = array(kk)-ck\n array(kk) = array(kk) + ck\n kk = k2 + kspan\n if (kk > nn) exit\n enddo\n kk = kk - nn\n if (kk > jc) exit\n enddo\n if (kk > kspan) then\n! deallocate( ctmp, sine, cosine, stat=status )\n return\n endif\n do\n c1 = 1.0 - cd\n s1 = sd\n do\n do\n do\n k2 = kk + kspan\n ck = array(kk) - array(k2)\n array(kk) = array(kk) + array(k2)\n array(k2) = ck * cmplx(c1, s1)\n kk = k2 + kspan\n if (kk >= nt) exit\n enddo\n k2 = kk - nt\n c1 = -c1\n kk = k1 - k2\n if (kk <= k2) exit\n enddo\n ak = c1 - (cd * c1 + sd * s1)\n s1 = sd * c1 - cd * s1 + s1\n c1 = 2.0 - (ak * ak + s1 * s1)\n s1 = s1 * c1\n c1 = c1 * ak\n kk = kk + jc\n if (kk >= k2) exit\n enddo\n k1 = k1 + 1 + 1\n kk = (k1 - kspan) / 2 + jc\n if (kk > jc + jc) exit\n enddo\n\n case (4) !-- transform for factor of 4\n ispan = kspan\n kspan = kspan / 4\n\n do\n c1 = 1.0\n s1 = 0.0\n do\n do\n k1 = kk + kspan\n k2 = k1 + kspan\n k3 = k2 + kspan\n ckp = array(kk) + array(k2)\n ckm = array(kk) - array(k2)\n cjp = array(k1) + array(k3)\n cjm = array(k1) - array(k3)\n array(kk) = ckp + cjp\n cjp = ckp - cjp\n if (inv) then\n ckp = ckm + cmplx(-aimag(cjm), real(cjm))\n ckm = ckm + cmplx(aimag(cjm), -real(cjm))\n else\n ckp = ckm + cmplx(aimag(cjm), -real(cjm))\n ckm = ckm + cmplx(-aimag(cjm), real(cjm))\n endif\n !-- avoid useless multiplies\n if (s1 == 0.0) then\n array(k1) = ckp\n array(k2) = cjp\n array(k3) = ckm\n else\n array(k1) = ckp * cmplx(c1, s1)\n array(k2) = cjp * cmplx(c2, s2)\n array(k3) = ckm * cmplx(c3, s3)\n endif\n kk = k3 + kspan\n if (kk > nt) exit\n enddo\n\n c2 = c1 - (cd * c1 + sd * s1)\n s1 = sd * c1 - cd * s1 + s1\n c1 = 2.0 - (c2 * c2 + s1 * s1)\n s1 = s1 * c1\n c1 = c1 * c2\n !-- values of c2, c3, s2, s3 that will get used next time\n c2 = c1 * c1 - s1 * s1\n s2 = 2.0 * c1 * s1\n c3 = c2 * c1 - s2 * s1\n s3 = c2 * s1 + s2 * c1\n kk = kk - nt + jc\n if (kk > kspan) exit\n enddo\n kk = kk - kspan + 1\n if (kk > jc) exit\n enddo\n if (kspan == jc) then\n! deallocate( ctmp, sine, cosine, stat=status )\n return\n endif\n\n case default\n !-- transform for odd factors\n k = factor(ii)\n ispan = kspan\n kspan = kspan / k\n\n select case (k)\n case (3) !-- transform for factor of 3 (optional code)\n do\n do\n k1 = kk + kspan\n k2 = k1 + kspan\n ck = array(kk)\n cj = array(k1) + array(k2)\n array(kk) = ck + cj\n ck = ck - cmplx( 0.5 * real (cj), 0.5 * aimag(cj))\n cj = cmplx( (real(array(k1)) - real (array(k2))) * s60,(aimag(array(k1)) - aimag(array(k2))) * s60)\n array(k1) = ck + cmplx(-aimag(cj), real(cj))\n array(k2) = ck + cmplx(aimag(cj), -real(cj))\n kk = k2 + kspan\n if (kk >= nn) exit\n enddo\n kk = kk - nn\n if (kk > kspan) exit\n enddo\n\n case (5) !-- transform for factor of 5 (optional code)\n c2 = c72 * c72 - s72 * s72\n s2 = 2.0 * c72 * s72\n do\n do\n k1 = kk + kspan\n k2 = k1 + kspan\n k3 = k2 + kspan\n k4 = k3 + kspan\n ckp = array(k1) + array(k4)\n ckm = array(k1) - array(k4)\n cjp = array(k2) + array(k3)\n cjm = array(k2) - array(k3)\n cc = array(kk)\n array(kk) = cc + ckp + cjp\n ck = cmplx(real(ckp) * c72, aimag(ckp) * c72 ) + &\n cmplx(real(cjp) * c2, aimag(cjp) * c2) + cc\n cj = cmplx(real(ckm) * s72, aimag(ckm) * s72) + &\n cmplx(real(cjm) * s2, aimag(cjm) * s2)\n array(k1) = ck + cmplx(-aimag(cj), real(cj))\n array(k4) = ck + cmplx(aimag(cj), -real(cj))\n ck = cmplx(real(ckp) * c2, aimag(ckp) * c2) &\n + cmplx(real(cjp) * c72, aimag(cjp) * c72) + cc\n cj = cmplx(real(ckm) * s2, aimag(ckm) * s2) - &\n cmplx(real(cjm) * s72, aimag(cjm) * s72)\n array(k2) = ck + cmplx(-aimag(cj), real(cj))\n array(k3) = ck + cmplx(aimag(cj), -real(cj))\n kk = k4 + kspan\n if (kk >= nn) exit\n enddo\n kk = kk - nn\n if (kk > kspan) exit\n enddo\n\n case default\n if (k /= jf) then\n jf = k\n s1 = pi2 / k\n c1 = cos(s1)\n s1 = sin(s1)\n cosine (jf) = 1.0\n sine (jf) = 0.0\n j = 1\n do\n cosine (j) = cosine (k) * c1 + sine (k) * s1\n sine (j) = cosine (k) * s1 - sine (k) * c1\n k = k-1\n cosine (k) = cosine (j)\n sine (k) = -sine (j)\n j = j + 1\n if (j >= k) exit\n enddo\n endif\n do\n do\n k1 = kk\n k2 = kk + ispan\n cc = array(kk)\n ck = cc\n j = 1\n k1 = k1 + kspan\n do\n k2 = k2 - kspan\n j = j + 1\n ctmp(j) = array(k1) + array(k2)\n ck = ck + ctmp(j)\n j = j + 1\n ctmp(j) = array(k1) - array(k2)\n k1 = k1 + kspan\n if (k1 >= k2) exit\n enddo\n array(kk) = ck\n k1 = kk\n k2 = kk + ispan\n j = 1\n do\n k1 = k1 + kspan\n k2 = k2 - kspan\n jj = j\n ck = cc\n cj = (0.0, 0.0)\n k = 1\n do\n k = k + 1\n ck = ck + cmplx(real (ctmp(k)) * cosine(jj),aimag(ctmp(k)) * cosine(jj))\n k = k + 1\n cj = cj + cmplx( real (ctmp(k)) * sine(jj),aimag(ctmp(k)) * sine(jj))\n jj = jj + j\n if (jj > jf) jj = jj - jf\n if (k >= jf) exit\n enddo\n k = jf - j\n array(k1) = ck + cmplx(-aimag(cj), real(cj))\n array(k2) = ck + cmplx(aimag(cj), -real(cj))\n j = j + 1\n if (j >= k) exit\n enddo\n kk = kk + ispan\n if (kk > nn) exit\n enddo\n kk = kk - nn\n if (kk > kspan) exit\n enddo\n\n endselect\n !-- multiply by rotation factor (except for factors of 2 and 4)\n if (ii == nfactor) then\n! deallocate( ctmp, sine, cosine, stat=status )\n return\n endif\n\n kk = jc + 1\n do\n c2 = 1.0 - cd\n s1 = sd\n do\n c1 = c2\n s2 = s1\n kk = kk + kspan\n do\n do\n array(kk) = cmplx(c2, s2)* array(kk)\n kk = kk + ispan\n if (kk > nt) exit\n enddo\n ak = s1 * s2\n s2 = s1 * c2 + c1 * s2\n c2 = c1 * c2 - ak\n kk = kk - nt + kspan\n if (kk > ispan) exit\n enddo\n c2 = c1 - (cd * c1 + sd * s1)\n s1 = s1 + sd * c1 - cd * s1\n c1 = 2.0 - (c2 * c2 + s1 * s1)\n s1 = s1 * c1\n c2 = c2 * c1\n kk = kk - ispan + jc\n if (kk > kspan) exit\n enddo\n kk = kk - kspan + jc + 1\n if (kk > jc + jc) exit\n enddo\n\n endselect\n enddo\n\n ! deallocate( ctmp, sine, cosine, stat=status )\n endsubroutine ! transform\n\n subroutine permute( array, ntotal, npass, nspan, factor, nfactor, nsquare, maxfactor )\n !--- formal parameters\n complex, intent(inout) :: array(:)\n integer, intent(in) :: ntotal, npass, nspan\n integer, intent(inout) :: factor(:)\n integer, intent(in) :: nfactor, nsquare\n integer, intent(in) :: maxfactor\n !--- local scalars\n integer :: ii, ispan\n integer :: j, jc, jj\n integer :: k, kk, kspan, kt, k1, k2, k3\n integer :: nn, nperm, nt\n complex :: ck\n !--- local arrays\n complex, allocatable :: ctmp(:)\n integer, allocatable :: perm(:)\n\n allocate( ctmp(maxfactor), stat=status )\n if (status /= 0) return\n\n if (nfactor - ishft(nsquare, 1) > 0) then\n nperm = max(nfactor + 1,product(factor(nsquare+1: nfactor-nsquare)) - 1)\n else\n nperm = nfactor + 1\n endif\n allocate( perm(nperm), stat=status )\n if ( status /= 0 ) return\n\n !-- permute the results to normal order---done in two stages\n !-- permutation for square factors of n\n\n nt = ntotal\n nn = nt - 1\n kt = nsquare\n kspan = nspan\n jc = nspan / npass\n\n perm (1) = nspan\n if (kt > 0) then\n k = kt + kt + 1\n if (nfactor < k) k = k - 1\n j = 1\n perm (k + 1) = jc\n do\n perm (j + 1) = perm (j) / factor(j)\n perm (k) = perm (k + 1) * factor(j)\n j = j + 1\n k = k - 1\n if (j >= k) exit\n enddo\n k3 = perm (k + 1)\n kspan = perm (2)\n kk = jc + 1\n k2 = kspan + 1\n j = 1\n\n if (npass /= ntotal) then\n permute_multi: do\n do\n do\n k = kk + jc\n do\n !-- swap array(kk) <> array(k2)\n ck = array(kk)\n array(kk) = array(k2)\n array(k2) = ck\n kk = kk + 1\n k2 = k2 + 1\n if (kk >= k) exit\n enddo\n kk = kk + nspan - jc\n k2 = k2 + nspan - jc\n if (kk >= nt) exit\n enddo\n kk = kk - nt + jc\n k2 = k2 - nt + kspan\n if (k2 >= nspan) exit\n enddo\n do\n do\n k2 = k2 - perm (j)\n j = j + 1\n k2 = perm (j + 1) + k2\n if (k2 <= perm (j)) exit\n enddo\n j = 1\n do\n if (kk < k2) cycle permute_multi\n kk = kk + jc\n k2 = k2 + kspan\n if (k2 >= nspan) exit\n enddo\n if (kk >= nspan) exit\n enddo\n exit\n enddo permute_multi\n else\n permute_single: do\n do\n !-- swap array(kk) <> array(k2)\n ck = array(kk)\n array(kk) = array(k2)\n array(k2) = ck\n kk = kk + 1\n k2 = k2 + kspan\n if (k2 >= nspan) exit\n enddo\n do\n do\n k2 = k2 - perm (j)\n j = j + 1\n k2 = perm (j + 1) + k2\n if (k2 <= perm (j)) exit\n enddo\n j = 1\n do\n if (kk < k2) cycle permute_single\n kk = kk + 1\n k2 = k2 + kspan\n if (k2 >= nspan) exit\n enddo\n if (kk >= nspan) exit\n enddo\n exit\n enddo permute_single\n endif\n jc = k3\n endif\n\n if (ishft(kt, 1) + 1 >= nfactor) then\n deallocate( perm, ctmp )\n return\n endif\n\n ispan = perm (kt + 1)\n !-- permutation for square-free factors of n\n j = nfactor - kt\n factor(j + 1) = 1\n do\n factor(j) = factor(j) * factor(j+1)\n j = j - 1\n if (j == kt) exit\n enddo\n kt = kt + 1\n nn = factor(kt) - 1\n j = 0\n jj = 0\n do\n k = kt + 1\n k2 = factor(kt)\n kk = factor(k)\n j = j + 1\n if (j > nn) exit !-- exit infinite loop\n jj = jj + kk\n do while (jj >= k2)\n jj = jj - k2\n k2 = kk\n k = k + 1\n kk = factor(k)\n jj = jj + kk\n enddo\n perm (j) = jj\n enddo\n !-- determine the permutation cycles of length greater than 1\n j = 0\n do\n do\n j = j + 1\n kk = perm(j)\n if (kk >= 0) exit\n enddo\n if (kk /= j) then\n do\n k = kk\n kk = perm (k)\n perm (k) = -kk\n if (kk == j) exit\n enddo\n k3 = kk\n else\n perm (j) = -j\n if (j == nn) exit !-- exit infinite loop\n endif\n enddo\n !-- reorder a and b, following the permutation cycles\n do\n j = k3 + 1\n nt = nt - ispan\n ii = nt - 1 + 1\n if (nt < 0) exit !-- exit infinite loop\n do\n do\n j = j-1\n if (perm(j) >= 0) exit\n enddo\n jj = jc\n do\n kspan = jj\n if (jj > maxfactor) kspan = maxfactor\n jj = jj - kspan\n k = perm(j)\n kk = jc * k + ii + jj\n k1 = kk + kspan\n k2 = 0\n do\n k2 = k2 + 1\n ctmp(k2) = array(k1)\n k1 = k1 - 1\n if (k1 == kk) exit\n enddo\n do\n k1 = kk + kspan\n k2 = k1 - jc * (k + perm(k))\n k = -perm(k)\n do\n array(k1) = array(k2)\n k1 = k1 - 1\n k2 = k2 - 1\n if (k1 == kk) exit\n enddo\n kk = k2\n if (k == j) exit\n enddo\n k1 = kk + kspan\n k2 = 0\n do\n k2 = k2 + 1\n array(k1) = ctmp(k2)\n k1 = k1 - 1\n if (k1 == kk) exit\n enddo\n if (jj == 0) exit\n enddo\n if (j == 1) exit\n enddo\n enddo\n\n deallocate( perm, ctmp )\n endsubroutine ! permute\n\n integer function test( )\n write(*,*,iostat=test) 'FFT: no module test implemented!'\n endfunction ! test\n\nendmodule ! FFT_tools\n", "meta": {"hexsha": "c68d20a55a4d5e88314cefa87fe451d4bbe54890", "size": 32115, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/mod_FFT_tools.f90", "max_stars_repo_name": "real-space/juRS", "max_stars_repo_head_hexsha": "0975dd6c30ef3344a89ff3f203043338e5588f0a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-03-05T10:30:29.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T13:10:32.000Z", "max_issues_repo_path": "src/mod_FFT_tools.f90", "max_issues_repo_name": "real-space/juRS", "max_issues_repo_head_hexsha": "0975dd6c30ef3344a89ff3f203043338e5588f0a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/mod_FFT_tools.f90", "max_forks_repo_name": "real-space/juRS", "max_forks_repo_head_hexsha": "0975dd6c30ef3344a89ff3f203043338e5588f0a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-02-28T13:10:32.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-28T13:10:32.000Z", "avg_line_length": 32.1471471471, "max_line_length": 117, "alphanum_fraction": 0.4704343765, "num_tokens": 9233, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789468908171, "lm_q2_score": 0.7401743735019595, "lm_q1q2_score": 0.6623002345652566}} {"text": " PROGRAM sphfpt\r\n INTEGER i,m,n,nvar,nn2,N1,N2,NTOT\r\n REAL DXX\r\n PARAMETER (N1=2,N2=1,NTOT=N1+N2,DXX=1.e-4)\r\n REAL c2,dx,gamma,q1,x1,x2,xf,v1(N2),v2(N1),v(NTOT)\r\n LOGICAL check\r\n COMMON /sphcom/ c2,gamma,dx,m,n\r\n COMMON /caller/ x1,x2,xf,nvar,nn2\r\n EQUIVALENCE (v1(1),v(1)),(v2(1),v(N2+1))\r\nCU USES newt\r\n nvar=NTOT\r\n nn2=N2\r\n dx=DXX\r\n1 write(*,*) 'input m,n,c-squared (999 to end)'\r\n read(*,*) m,n,c2\r\n if (c2.eq.999.) stop\r\n if ((n.lt.m).or.(m.lt.0)) goto 1\r\n gamma=1.0\r\n q1=n\r\n do 11 i=1,m\r\n gamma=-0.5*gamma*(n+i)*(q1/i)\r\n q1=q1-1.0\r\n11 continue\r\n v1(1)=n*(n+1)-m*(m+1)+c2/2.0\r\n v2(2)=v1(1)\r\n v2(1)=gamma*(1.-(v2(2)-c2)*dx/(2*(m+1)))\r\n x1=-1.0+dx\r\n x2=1.0-dx\r\n xf=0.\r\n call newt(v,NTOT,check)\r\n if(check)then\r\n write(*,*)'shootf failed; bad initial guess'\r\n else\r\n write(*,'(1x,t6,a)') 'mu(m,n)'\r\n write(*,'(1x,f12.6)') v1(1)\r\n goto 1\r\n endif\r\n END\r\n SUBROUTINE load1(x1,v1,y)\r\n INTEGER m,n\r\n REAL c2,dx,gamma,x1,y1,v1(1),y(3)\r\n COMMON /sphcom/ c2,gamma,dx,m,n\r\n y(3)=v1(1)\r\n if(mod(n-m,2).eq.0)then\r\n y1=gamma\r\n else\r\n y1=-gamma\r\n endif\r\n y(2)=-(y(3)-c2)*y1/(2*(m+1))\r\n y(1)=y1+y(2)*dx\r\n return\r\n END\r\n SUBROUTINE load2(x2,v2,y)\r\n INTEGER m,n\r\n REAL c2,dx,gamma,x2,v2(2),y(3)\r\n COMMON /sphcom/ c2,gamma,dx,m,n\r\n y(3)=v2(2)\r\n y(1)=v2(1)\r\n y(2)=(y(3)-c2)*y(1)/(2*(m+1))\r\n return\r\n END\r\n SUBROUTINE score(xf,y,f)\r\n INTEGER i,m,n\r\n REAL c2,gamma,dx,xf,f(3),y(3)\r\n COMMON /sphcom/ c2,gamma,dx,m,n\r\n do 12 i=1,3\r\n f(i)=y(i)\r\n12 continue\r\n return\r\n END\r\n", "meta": {"hexsha": "4bcea1be5b53df1faa34d07b8d9a3c386cd6521f", "size": 1813, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/sphfpt.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/sphfpt.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/sphfpt.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.5352112676, "max_line_length": 57, "alphanum_fraction": 0.4649751793, "num_tokens": 769, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894717137996, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6623002263849901}} {"text": "program problem_12\n\n!! What is the Manhattan distance between that location \n!! and the ship's starting position?\n\nuse aoc_utilities\nuse iso_fortran_env\n\nimplicit none\n\ninteger,parameter :: chunk_size = 256\n\ninteger :: n, iunit, istat, i\ncharacter(len=:),allocatable :: line\nlogical :: status_ok\ncharacter(len=1) :: action\ninteger :: value\ninteger,dimension(2) :: r ! (x,y) position\ninteger :: direction ! current direction (N=90,S=270,E=0,W=180)\n\nopen(newunit=iunit, file='input.txt', iostat=istat)\nn = number_of_lines_in_file(iunit)\n\ndirection = 0 ! start facing east\nr = 0 ! initial position\n\ndo i = 1, n\n call read_line_from_file(iunit,chunk_size,line,status_ok)\n\n action = line(1:1)\n read(line(2:),'(I5)') value\n\n select case (action)\n case('N'); r(2) = r(2) + value ! move north by the given value. \n case('S'); r(2) = r(2) - value ! move south by the given value.\n case('E'); r(1) = r(1) + value ! move east by the given value.\n case('W'); r(1) = r(1) - value ! move west by the given value.\n case('L'); direction = wrap(direction + value) ! turn left the given number of degrees.\n case('R'); direction = wrap(direction - value) ! turn right the given number of degrees.\n case('F') ! move forward by the given value in the direction the ship is currently facing.\n select case (direction)\n case(0,360); r(1) = r(1) + value ! E\n case(90); r(2) = r(2) + value ! N\n case(180); r(1) = r(1) - value ! W\n case(270); r(2) = r(2) - value ! S\n case default \n error stop 'invalid direction'\n end select\n case default\n error stop 'invalid action: '//action\n end select \n\nend do\n\nwrite(*,*) 'Manhattan distance: ', abs(r(1)) + abs(r(2))\n\ncontains\n\npure function wrap(angle) result(wrapped_angle)\nimplicit none \ninteger,intent(in) :: angle\ninteger :: wrapped_angle\nwrapped_angle = mod(angle, 360)\nif (wrapped_angle<0) wrapped_angle = wrapped_angle + 360\nend function wrap\n\nend program problem_12", "meta": {"hexsha": "71ea8184cb7f98244f8687b75936a25e9bd4de08", "size": 2024, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/day12/problem_12.f90", "max_stars_repo_name": "jacobwilliams/AoC-2020", "max_stars_repo_head_hexsha": "2adf673a0ac62710fc5461576feb95bf5fae4cf2", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/day12/problem_12.f90", "max_issues_repo_name": "jacobwilliams/AoC-2020", "max_issues_repo_head_hexsha": "2adf673a0ac62710fc5461576feb95bf5fae4cf2", "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/day12/problem_12.f90", "max_forks_repo_name": "jacobwilliams/AoC-2020", "max_forks_repo_head_hexsha": "2adf673a0ac62710fc5461576feb95bf5fae4cf2", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.2089552239, "max_line_length": 95, "alphanum_fraction": 0.6457509881, "num_tokens": 596, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894576856559, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6623002160017177}} {"text": "!##############################################################################\n! MODULE globals\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!##############################################################################\nmodule globals\n\n implicit none\n real*8, parameter :: Kbar = 10d0\n real*8, parameter :: Tbar = 30d0\n real*8, parameter :: alpha(2) = (/0.3d0, 0.4d0/)\n real*8, parameter :: beta(2) = (/ 0.3d0, 0.6d0/)\n real*8, parameter :: gamma(2) = (/ -2.5d0, 0.5d0/)\n real*8, parameter :: G = 3d0\n real*8, parameter :: B = 0.1d0\n real*8 :: tauw = 0d0\n real*8 :: tauu = 0d0\n real*8 :: taur = 0d0\n real*8 :: tauc(2) = 0d0\n\ncontains\n\n\n ! function to determine market equilibrium\n function markets(x)\n\n implicit none\n real*8, intent(in) :: x(:)\n real*8 :: markets(size(x, 1))\n real*8 :: Ybarn, q(2), p(2), PX, w, wn, r, rn, ur\n\n ! copy producer prices and taxes\n q(1) = 1d0\n q(2) = x(1)\n w = x(2)\n r = x(3)\n\n ! set tax rates (uncomment respective line for different tables)\n taur = x(4)\n !tauw = x(4)\n !tauc(1) = x(4)\n !tauc(2) = x(4)\n\n ! copy the unempoyment rate\n ur = x(5)\n\n ! calculate consumer prices and total income\n p = q*(1d0+tauc)\n PX = p(1)*alpha(1)/sum(alpha)+p(2)*alpha(2)/sum(alpha)\n tauu = PX*B*ur/(w*(1-ur))\n wn = w*(1d0-tauw-tauu)*(1-ur)+PX*B*ur\n rn = r*(1d0-taur)\n Ybarn = wn*Tbar+rn*Kbar\n\n ! get market equations\n markets(1) = alpha(1)*Ybarn/p(1)+G-(beta(1)/w)**beta(1)* &\n ((1d0-beta(1))/r)**(1d0-beta(1))*q(1)*(alpha(1)*Ybarn/p(1)+G)\n markets(2) = 1d0-(beta(2)/w)**beta(2)*((1d0-beta(2))/r)**(1d0-beta(2))*q(2)\n markets(3) = beta(1)/w*q(1)*(alpha(1)*Ybarn/p(1)+G)+ &\n beta(2)/w*q(2)*alpha(2)*Ybarn/p(2)+(1-ur)*((1d0-alpha(1)-alpha(2))*Ybarn/wn-Tbar)\n markets(4) = q(1)*G-tauc(1)/(1d0+tauc(1))*alpha(1)*Ybarn- &\n tauc(2)/(1d0+tauc(2))*alpha(2)*Ybarn-&\n tauw*w*(1-ur)*(Tbar-(1d0-alpha(1)-alpha(2))/wn*Ybarn)-taur*r*Kbar\n markets(5) = log(w*(1-tauw-tauu)/PX)-gamma(1)+gamma(2)*log(ur)\n\n end function markets\n\nend module\n\n", "meta": {"hexsha": "b866eb3dc13cfe8a34f7f6861a9e095dc77d34ff", "size": 2537, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "complete/prog03/prog03_05/prog03_05m.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/prog03/prog03_05/prog03_05m.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/prog03/prog03_05/prog03_05m.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": 32.9480519481, "max_line_length": 93, "alphanum_fraction": 0.4737879385, "num_tokens": 919, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789452074398, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6623002118484085}} {"text": "!Please Note: In order to run a fortran OpenMP program, the environment variable\r\n!OMP_NUM_THREADS must be set to the number of threads to be used. I have been\r\n!running the command 'export OMP_NUM_THREADS=10' to set my thread numbers\r\n!through a system call. Should this not work, please set the environment\r\n!variable before running.\r\n!\r\n!Thank you\r\n\r\nprogram gaussianElimination\r\n\r\nimplicit none\r\n\r\ninteger :: x, y, count, n, rowselect\r\n\r\nreal :: scalar\r\n\r\nreal(kind=4), dimension(10, 10) :: matrix\r\n\r\nreal(kind=4), dimension(10) :: rightside, solutions\r\n\r\n!this is the number of rows & columns\r\nn = 10\r\n\r\nx = 1\r\n\r\ny = 1\r\n\r\ndo while(x <= n)\r\n\r\n y = 1\r\n\r\n do while(y <= n)\r\n\r\n!this code generates values from -10 (inclusive) to 10 (inclusive)\r\n!the basis for this code came from the new mexico tech computer program\r\n!website, at http://infohost.nmt.edu/tcc/help/lang/fortran/scaling.html\r\n matrix(x, y) = int(rand(0)*(10+1+10))-10\r\n\r\n rightside(x) = int(rand(0)*(10+1+10))-10\r\n\r\n count = count + 1\r\n\r\n y = y + 1\r\n\r\n end do\r\n\r\n x = x + 1\r\n\r\nend do\r\n\r\nx = 1\r\n\r\ncount = 0\r\n\r\ny = 1\r\n\r\nprint *, \"Original Matrix:\"\r\n\r\ncall printmatrix(matrix, n)\r\n\r\nprint *, \"Beginning Elimination\"\r\n\r\ncall elimination(matrix, n)\r\n\r\nprint *, \"End Elimination\"\r\n\r\ncall backsubstitution(matrix, rightside, solutions, n)\r\n\r\ncall printmatrix(matrix, n)\r\n\r\nPrint *, \"Below is the solutions to each row: \"\r\n\r\ndo count = 1, 10\r\n\r\nprint *, rightside(count)\r\n\r\nend do\r\n\r\nprint *, \"The solution set for this matrix is: \"\r\n\r\ndo count = 1, 10\r\n\r\nprint *, solutions(count)\r\n\r\nend do\r\n\r\nend program gaussianElimination\r\n\r\n\r\n\r\n\r\n\r\n\r\nsubroutine printmatrix(matrix, n)\r\n\r\nimplicit none\r\n\r\ninteger, intent(in) :: n\r\n\r\ninteger :: x, y\r\n\r\nreal, intent(in) :: matrix(10, 10)\r\n\r\nx = 1\r\n\r\ndo while(x <= n)\r\n\r\n write(*, 20) matrix(x, :)\r\n\r\n x = x + 1\r\n\r\nend do\r\n\r\n20 format(10f10.5)\r\n\r\nend subroutine\r\n\r\n\r\n\r\nsubroutine elimination(matrix, n)\r\n\r\nuse omp_lib\r\n\r\nimplicit none\r\n\r\ninteger :: row, rowadd, column, test, myid\r\n\r\nreal, intent(inout) :: matrix(10, 10)\r\n\r\nreal(kind=4), dimension(10) :: swapvector \r\n \r\nreal :: scalar\r\n\r\ninteger, intent(in) :: n\r\n\r\nlogical :: bool\r\n\r\nrow = 1\r\n\r\ncolumn = 1\r\n\r\ndo while(row <= n)\r\n\r\n rowadd = row + 1\r\n\r\n !if a zero exists, swap rows\r\n if(matrix(row, column) == 0) then\r\n\r\n swapvector = matrix(row, :)\r\n\r\n matrix(row, :) = matrix(row + 1, :)\r\n\r\n matrix(row + 1, :) = swapvector\r\n\r\n end if\r\n\r\n if(matrix(row, column) /= 1) then\r\n\r\n scalar = (1/matrix(row, column))\r\n\r\n matrix(row, :) = matrix(row, :) * scalar\r\n\r\n end if\r\n\r\n! print *, \"Post reduction\"\r\n\r\n! call printmatrix(matrix, n)\r\n\r\n !make all numbers below it in the column a zero\r\n\r\n!turn this loop into parallel do while(rowadd <= n)\r\n\r\n\r\n call system(\"export OMP_NUM_THREADS=10\")\r\n !$OMP PARALLEL DEFAULT(NONE) NUM_THREADS(10) SHARED(matrix, n, row, column) PRIVATE(myid)\r\n\r\n myid = OMP_GET_THREAD_NUM() + 1\r\n\r\n if(myid <= n .and. myid > row) then\r\n \r\n matrix(myid, :) = matrix(myid, :) - matrix(row, :) * matrix(myid, column)\r\n \r\n end if\r\n\r\n !$OMP END PARALLEL\r\n\r\n !move to the next diagonal\r\n\r\n row = row + 1\r\n\r\n column = column + 1\r\n\r\nend do\r\n\r\nend subroutine\r\n\r\n\r\n\r\nsubroutine backsubstitution(matrix, rightside, solutions, n)\r\n\r\nuse omp_lib\r\n\r\nimplicit none\r\n\r\nreal, intent(in) ::matrix(10, 10)\r\n\r\ninteger, intent(in) :: n\r\n\r\nreal, intent(inout) :: rightside(10), solutions(10)\r\n\r\ninteger :: row, col, myid\r\n\r\nrow = n\r\n\r\ndo while(row >= 1)\r\n\r\nsolutions(row) = rightside(row)\r\n\r\ndo col = row + 1, n\r\n\r\nsolutions(row) = solutions(row) - (matrix(row, col) * solutions(col))\r\n\r\nend do\r\n\r\nsolutions(row) = solutions(row) / matrix(row, row)\r\n\r\nrow = row - 1\r\n\r\nend do\r\n\r\nend subroutine\r\n\r\n", "meta": {"hexsha": "6b494399f2bcc5487ae91c4e1b7f2b591946168d", "size": 4004, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "gaussianElimination.f95", "max_stars_repo_name": "HWorrell/Fortan-Gaussian-Elimination", "max_stars_repo_head_hexsha": "7d7e69b8f8c3bf9b63559c7fed0f56c68cc46d8f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "gaussianElimination.f95", "max_issues_repo_name": "HWorrell/Fortan-Gaussian-Elimination", "max_issues_repo_head_hexsha": "7d7e69b8f8c3bf9b63559c7fed0f56c68cc46d8f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gaussianElimination.f95", "max_forks_repo_name": "HWorrell/Fortan-Gaussian-Elimination", "max_forks_repo_head_hexsha": "7d7e69b8f8c3bf9b63559c7fed0f56c68cc46d8f", "max_forks_repo_licenses": ["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.1845493562, "max_line_length": 98, "alphanum_fraction": 0.5731768232, "num_tokens": 1057, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.913676514011486, "lm_q2_score": 0.7248702761768248, "lm_q1q2_score": 0.6622969470477843}} {"text": "SUBROUTINE p52(input_file,output_file)\n!-------------------------------------------------------------------------\n! Program 5.2 Non-axisymmetric analysis of an axisymmetric elastic solid\n! using 8-node rectangular quadrilaterals. Mesh numbered in\n! r- or z- direction.\n!-------------------------------------------------------------------------\n USE main \n USE geom \n IMPLICIT NONE\n CHARACTER(len=70),INTENT(IN) :: input_file\n CHARACTER(len=70),INTENT(OUT) :: output_file\n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\n INTEGER::i,iel,iflag,k,loaded_nodes,lth,ndim=2,ndof=24,nels,neq,nip=4, &\n nlen,nod=8,nodof=3,nn,nprops=2,np_types,nr,nre,nst=6,nze \n REAL(iwp)::ca,chi,det,one=1.0_iwp,pi,radius,sa,zero=0.0_iwp\n CHARACTER(LEN=15)::argv,element='quadrilateral'\n!-----------------------dynamic arrays------------------------------------\n INTEGER,ALLOCATABLE::etype(:),g(:),g_g(:,:),g_num(:,:),kdiag(:),nf(:,:), &\n num(:) \n REAL(iwp),ALLOCATABLE::bee(:,:),coord(:,:),dee(:,:),der(:,:),deriv(:,:), &\n eld(:),fun(:),gc(:),g_coord(:,:),jac(:,:),km(:,:),kv(:),loads(:), &\n points(:,:),prop(:,:),r_coords(:),sigma(:),weights(:),z_coords(:) \n!-----------------------input and initialisation--------------------------\n\n OPEN(10,FILE=input_file) \n OPEN(11,FILE=output_file)\n READ(10,*)nre,nze,lth,iflag,chi,np_types \n CALL mesh_size(element,nod,nels,nn,nre,nze)\n ALLOCATE(nf(nodof,nn),points(nip,ndim),g(ndof),g_coord(ndim,nn), &\n dee(nst,nst),coord(nod,ndim),fun(nod),jac(ndim,ndim),eld(ndof), &\n weights(nip),der(ndim,nod),deriv(ndim,nod),bee(nst,ndof),km(ndof,ndof),&\n sigma(nst),num(nod),g_num(nod,nels),g_g(ndof,nels),gc(ndim), &\n r_coords(nre+1),z_coords(nze+1),prop(nprops,np_types),etype(nels))\n READ(10,*)prop \n etype=1 \n IF(np_types>1)read(10,*)etype\n READ(10,*)r_coords,z_coords\n nf=1 \n READ(10,*)nr,(k,nf(:,k),i=1,nr) \n CALL formnf(nf) \n neq=MAXVAL(nf) \n ALLOCATE(kdiag(neq),loads(0:neq))\n pi=ACOS(-one) \n chi=chi*pi/180.0_iwp \n ca=COS(chi) \n sa=SIN(chi) \n kdiag=0\n!-----------------------loop the elements to find global arrays sizes-----\n elements_1: DO iel=1,nels\n CALL geom_rect(element,iel,r_coords,z_coords,coord,num,'r')\n CALL num_to_g(num,nf,g) \n g_num(:,iel)=num \n g_coord(:,num)=TRANSPOSE(coord) \n g_g(:,iel)=g \n CALL fkdiag(kdiag,g)\n END DO elements_1\n CALL mesh(g_coord,g_num,argv,nlen,12)\n DO i=2,neq \n kdiag(i)=kdiag(i)+kdiag(i-1) \n END DO \n ALLOCATE(kv(kdiag(neq)))\n WRITE(11,'(2(A,I5))') &\n \" There are\",neq,\" equations and the skyline storage is\",kdiag(neq)\n!-----------------------element stiffness integration and assembly--------\n CALL sample(element,points,weights) \n kv=zero\n elements_2: DO iel=1,nels\n CALL deemat(dee,prop(1,etype(iel)),prop(2,etype(iel))) \n num=g_num(:,iel)\n coord=TRANSPOSE(g_coord(:,num)) \n g=g_g(:,iel) \n km=zero\n gauss_pts_1: DO i=1,nip\n CALL shape_fun(fun,points,i) \n CALL shape_der(der,points,i)\n jac=MATMUL(der,coord) \n det=determinant(jac) \n CALL invert(jac)\n deriv=MATMUL(jac,der)\n CALL bmat_nonaxi(bee,radius,coord,deriv,fun,iflag,lth)\n km=km+MATMUL(MATMUL(TRANSPOSE(bee),dee),bee)*det*weights(i)*radius\n END DO gauss_pts_1\n CALL fsparv(kv,km,g,kdiag)\n END DO elements_2 \n loads=zero \n READ(10,*)loaded_nodes,(k,loads(nf(:,k)),i=1,loaded_nodes)\n!-----------------------equation solution---------------------------------\n CALL sparin(kv,kdiag) \n CALL spabac(kv,loads,kdiag) \n loads(0)=zero\n WRITE(11,'(/A)')\" Node r-disp z-disp t-disp\"\n DO k=1,nn \n WRITE(11,'(I5,3E12.4)')k,loads(nf(:,k)) \n END DO\n!-----------------------recover stresses at nip integrating points--------\n nip=1 \n DEALLOCATE(points,weights) \n ALLOCATE(points(nip,ndim),weights(nip))\n CALL sample(element,points,weights)\n WRITE(11,'(/A,I2,A)')\" The integration point (nip=\",nip,\") stresses are:\"\n WRITE(11,'(A,A)')\" Element r-coord z-coord\", &\n \" sig_r sig_z sig_t\" \n WRITE(11,'(A,A)')\" \", &\n \" tau_rz tau_zt tau_tr\" \n elements_3: DO iel=1,nels\n CALL deemat(dee,prop(1,etype(iel)),prop(2,etype(iel))) \n num=g_num(:,iel)\n coord=TRANSPOSE(g_coord(:,num)) \n g=g_g(:,iel) \n eld=loads(g)\n int_pts_2: DO i=1,nip\n CALL shape_fun(fun,points,i) \n CALL shape_der(der,points,i)\n gc=MATMUL(fun,coord) \n jac=MATMUL(der,coord) \n CALL invert(jac)\n deriv=MATMUL(jac,der)\n CALL bmat_nonaxi(bee,radius,coord,deriv,fun,iflag,lth)\n bee(1:4,:)=bee(1:4,:)*ca \n bee(5:6,:)=bee(5:6,:)*sa\n sigma=MATMUL(dee,MATMUL(bee,eld)) \n WRITE(11,'(I5,5X,5E12.4/34X,3E12.4)')iel,gc,sigma(:3),sigma(4:6)\n END DO int_pts_2\n END DO elements_3\n CALL dismsh(loads,nf,0.05_iwp,g_coord,g_num,argv,nlen,13)\n CALL vecmsh(loads,nf,0.05_iwp,0.1_iwp,g_coord,g_num,argv,nlen,14)\n\nEND SUBROUTINE p52\n", "meta": {"hexsha": "e1ed7b24a7b3c82b9d6bf2e5866c1a7525443efe", "size": 5002, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "subordinates/Static-Equilibrium-Linear-Elastic-Solids/p52.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": "subordinates/Static-Equilibrium-Linear-Elastic-Solids/p52.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": "subordinates/Static-Equilibrium-Linear-Elastic-Solids/p52.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": 38.7751937984, "max_line_length": 78, "alphanum_fraction": 0.5779688125, "num_tokens": 1668, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765210631688, "lm_q2_score": 0.7248702702332475, "lm_q1q2_score": 0.6622969467288325}} {"text": "!\n! (c) 2020-2021 Sourcery, Inc.\n! This software was developed for the U.S. Nuclear Regulatory Commission (US NRC) under contract # 31310020D0006:\n! \"Technical Assistance in Support of NRC Nuclear Regulatory Research for Materials, Waste, and Reactor Programs\"\n!\nmodule calc_cpi\n\n implicit none\n\ncontains\n\n ! calculate cpi(t)\n pure function cpi_t(K, RTndt, T)\n\n real :: cpi_t\n real, intent(in) :: K, RTndt, T\n real, parameter :: cKic = 4.0\n\n associate( &\n aKic => 19.35+8.335*exp(0.02254*(T-RTndt)), &\n bKic => 15.61+50.132*exp(0.008*(T-RTndt)) &\n )\n cpi_t = merge(0.0,1-exp(-((K-aKic)/bKic)**cKic), K < aKic)\n end associate\n\n end function cpi_t\n\nend module calc_cpi\n", "meta": {"hexsha": "ca22fe005575273d48b0fa0908c6040911d9ffe6", "size": 716, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/Calc_cpi.f90", "max_stars_repo_name": "sourceryinstitute/miniFAVOR", "max_stars_repo_head_hexsha": "0aea13023cabf8a08080ff367e83b91870661f60", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/Calc_cpi.f90", "max_issues_repo_name": "sourceryinstitute/miniFAVOR", "max_issues_repo_head_hexsha": "0aea13023cabf8a08080ff367e83b91870661f60", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 31, "max_issues_repo_issues_event_min_datetime": "2020-11-20T19:51:17.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-19T16:47:24.000Z", "max_forks_repo_path": "src/Calc_cpi.f90", "max_forks_repo_name": "sourceryinstitute/miniFAVOR", "max_forks_repo_head_hexsha": "0aea13023cabf8a08080ff367e83b91870661f60", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-12-11T23:36:46.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-22T18:39:46.000Z", "avg_line_length": 24.6896551724, "max_line_length": 117, "alphanum_fraction": 0.6452513966, "num_tokens": 251, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.913676518712608, "lm_q2_score": 0.7248702702332476, "lm_q1q2_score": 0.662296945024981}} {"text": "cc Copyright (C) 2004-2009: Leslie Greengard and June-Yub Lee \ncc Contact: greengard@cims.nyu.edu\ncc \ncc This program is free software; you can redistribute it and/or modify \ncc it under the terms of the GNU General Public License as published by \ncc the Free Software Foundation; either version 2 of the License, or \ncc (at your option) any later version. This program is distributed in \ncc the hope that it will be useful, but WITHOUT ANY WARRANTY; without \ncc even the implied warranty of MERCHANTABILITY or FITNESS FOR A \ncc PARTICULAR PURPOSE. See the GNU General Public License for more \ncc details. You should have received a copy of the GNU General Public \ncc License along with this program; \ncc if not, see .\ncc\n program testfft\n implicit none\nc\n integer i,ier,iflag,j,k1,k2,mx,ms,mt,n1,n2,nj,nk\n parameter (mx=256*256)\n real(8) xj(mx),yj(mx)\n real(8) sk(mx),tk(mx)\n real(8) err,pi,eps!,salg,ealg\n parameter (pi=3.141592653589793d0)\n complex(8) cj(mx),cj0(mx),cj1(mx)\n complex(8) fk0(mx),fk1(mx)\nc\nc --------------------------------------------------\nc create some test data\nc --------------------------------------------------\nc\n n1 = 36\n n2 = 40\n ms = 32\n mt = 30\n nj = n1*n2\n do k1 = -n1/2, (n1-1)/2\n do k2 = -n2/2, (n2-1)/2\n j = (k2+n2/2+1) + (k1+n1/2)*n2\n xj(j) = pi*dcos(-pi*k1/n1)\n yj(j) = pi*dcos(-pi*k2/n2)\n cj(j) = cmplx(dsin(pi*j/n1),dcos(pi*j/n2),kind=8)\n enddo\n enddo\nc\nc -----------------------\nc start tests\nc -----------------------\nc\n iflag = 1\n print*,'Starting 2D testing: ', ' nj =',nj, ' ms,mt =',ms,mt\n do i = 1,3\n if (i.eq.1) eps=1d-4\n if (i.eq.2) eps=1d-8\n if (i.eq.3) eps=1d-12\n print*,' '\n print*,' Requested precision eps =',eps\n print*,' '\nc\nc -----------------------\nc call 2D Type 1 method\nc -----------------------\nc\n call dirft2d1(nj,xj,yj,cj,iflag,ms,mt,fk0)\n call nufft2d1f90(nj,xj,yj,cj,iflag,eps,ms,mt,fk1,ier)\n call errcomp(fk0,fk1,ms*mt,err)\n print *, ' ier = ',ier\n call errcomp(fk0,fk1,ms*mt,err)\n print *, ' type 1 err = ',err\nc\nc -----------------------\nc call 2D Type 2 method\nc -----------------------\n call dirft2d2(nj,xj,yj,cj0,iflag,ms,mt,fk0)\n call nufft2d2f90(nj,xj,yj,cj1,iflag,eps,ms,mt,fk1,ier)\n print *, ' ier = ',ier\n call errcomp(cj0,cj1,nj,err)\n print *, ' type 1 err = ',err\nc\nc -----------------------\nc call 2D Type3 method\nc -----------------------\n nk = ms*mt\n do k1 = 1, nk\n sk(k1) = 48D0*(dcos(k1*pi/nk))\n tk(k1) = 32D0*(dsin(-pi/2+k1*pi/nk))\n enddo\n\n call dirft2d3(nj,xj,yj,cj,iflag,nk,sk,tk,fk0)\n call nufft2d3f90(nj,xj,yj,cj,iflag,eps,nk,sk,tk,fk1,ier)\nc\n print *, ' ier = ',ier\n call errcomp(fk0,fk1,nk,err)\n print *, ' type 1 err = ',err\n enddo \n stop\n end\nc\nc\nc\nc\nc\n subroutine errcomp(fk0,fk1,n,err)\n implicit none\n integer k,n\n complex(8) fk0(n), fk1(n)\n real(8) salg,ealg,err\nc\n ealg = 0d0\n salg = 0d0\n do k = 1, n\n ealg = ealg + abs(fk1(k)-fk0(k))**2\n salg = salg + abs(fk0(k))**2\n enddo\n err =sqrt(ealg/salg)\n return\n end\n", "meta": {"hexsha": "d70a4eb2af5a2546fddd3d2b95adb914371e0187", "size": 3473, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "external/nufft/nufft2d_demof90.f", "max_stars_repo_name": "utastudents/selalib", "max_stars_repo_head_hexsha": "84af43d0e82d4686a837c64384bbd173412df50e", "max_stars_repo_licenses": ["CECILL-B"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-03-11T15:22:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-22T16:26:18.000Z", "max_issues_repo_path": "external/nufft/nufft2d_demof90.f", "max_issues_repo_name": "utastudents/selalib", "max_issues_repo_head_hexsha": "84af43d0e82d4686a837c64384bbd173412df50e", "max_issues_repo_licenses": ["CECILL-B"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2021-06-30T20:39:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-15T12:42:50.000Z", "max_forks_repo_path": "external/nufft/nufft2d_demof90.f", "max_forks_repo_name": "utastudents/selalib", "max_forks_repo_head_hexsha": "84af43d0e82d4686a837c64384bbd173412df50e", "max_forks_repo_licenses": ["CECILL-B"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-03-13T17:09:10.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-22T00:30:19.000Z", "avg_line_length": 29.6837606838, "max_line_length": 72, "alphanum_fraction": 0.5099337748, "num_tokens": 1209, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528170040852, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.6622228107798229}} {"text": "subroutine evolve_step(mass, pos, vel, &\n acc, jerk, n, t, &\n dt, epot, coll_time)\n\tuse numz\n\tuse dim\n\tuse face, only:predict_step,get_acc_jerk_pot_coll,correct_step\n\timplicit none\n real(b8) mass(0:), pos(0:,0:)\n real(b8) vel(0:,0:), acc(0:,0:)\n real(b8) jerk(0:,0:)\n integer n\n real(b8) t,dt\n real(b8) epot\n real(b8) coll_time\n\t\n\treal(b8),allocatable:: old_pos(:,:),old_vel(:,:),old_acc(:,:),old_jerk(:,:)\n\tallocate( old_pos(0:n-1,0:ndim-1) )\n\tallocate( old_vel(0:n-1,0:ndim-1) )\n\tallocate( old_acc(0:n-1,0:ndim-1) )\n\tallocate( old_jerk(0:n-1,0:ndim-1) )\n\told_pos=pos\n\told_vel=vel\n\told_acc=acc\n\told_jerk=jerk\n\t\n\tcall predict_step(pos, vel, acc, jerk, n, dt)\n\tcall get_acc_jerk_pot_coll(mass, pos, vel, acc, jerk, n, epot, coll_time)\n\tcall correct_step(pos, vel, acc, jerk, old_pos, old_vel, old_acc, old_jerk, n, dt)\n\tt = t +dt\n\t\n\tdeallocate( old_pos )\n\tdeallocate( old_vel )\n\tdeallocate( old_acc )\n\tdeallocate( old_jerk )\nend subroutine evolve_step\n\n!/*-----------------------------------------------------------------------------\n! * predict_step -- takes the first approximation of one Hermite integration\n! * step, advancing the positions and velocities through a\n! * Taylor series development up to the order of the jerks.\n! *-----------------------------------------------------------------------------\n! */\n\nsubroutine predict_step(pos,vel, acc, jerk,n,dt)\n\tuse numz\n\tuse dim\n\timplicit none\n real(b8) pos(0:,0:)\n real(b8) vel(0:,0:)\n real(b8) acc(0:,0:)\n real(b8) jerk(0:,0:)\n integer n\n real(b8) dt\n \n real(b8) dt2,dt3\n integer i,k\n dt2=dt*dt\n dt3=dt2*dt\n dt2=dt2/2.0_b8\n dt3=dt3/6.0_b8\n do i=0,n-1\n do k=0,ndim-1\n\n pos(i,k) = pos(i,k) + vel(i,k)*dt + acc(i,k)*dt2 &\n + jerk(i,k)*dt3\n vel(i,k) = vel(i,k) + acc(i,k)*dt + jerk(i,k)*dt2\n enddo\n enddo\nend subroutine predict_step\n!/*-----------------------------------------------------------------------------\n! * correct_step -- takes one iteration to improve the new values of position\n! * and velocities, effectively by using a higher-order\n! * Taylor series constructed from the terms up to jerk at\n! * the beginning and the end of the time step.\n! *-----------------------------------------------------------------------------\n! */\n\nsubroutine correct_step(pos,vel, acc, jerk, &\n old_pos, old_vel, old_acc, old_jerk, &\n n,dt)\n\tuse numz\n\tuse dim\n\timplicit none\n real(b8) pos(0:,0:),vel(0:,0:),acc(0:,0:),jerk(0:,0:)\n real(b8) old_pos(0:,0:),old_vel(0:,0:),old_acc(0:,0:),old_jerk(0:,0:)\n integer n\n real(b8) dt\n \n integer i,k\n \n do i=0,n-1\n do k=0,ndim-1\n vel(i,k) = old_vel(i,k) + (old_acc(i,k) + acc(i,k))*dt/2 &\n + (old_jerk(i,k) - jerk(i,k))*dt*dt/12\n pos(i,k) = old_pos(i,k) + (old_vel(i,k) + vel(i,k))*dt/2 &\n + (old_acc(i,k) - acc(i,k))*dt*dt/12\n enddo\n enddo\nend subroutine correct_step\n", "meta": {"hexsha": "89e9261ec07cedd0af90d291a14dbaa6216c1be3", "size": 3229, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "make/fort/steps.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": "make/fort/steps.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": "make/fort/steps.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": 32.29, "max_line_length": 83, "alphanum_fraction": 0.5017033137, "num_tokens": 978, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528057272543, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.662222793224023}} {"text": "MODULE ISING\n IMPLICIT NONE \n REAL, PARAMETER :: TEMP = 3.5, dTEMP = 0.05\n INTEGER, PARAMETER :: LSIZE = 20\n INTEGER, PARAMETER :: NTEMP = 40, NSTEP = 10000, ESTEP = 5000\n INTEGER, PARAMETER :: NSPIN = LSIZE*LSIZE \nCONTAINS\n\nSUBROUTINE INIT_TRANSITION_PROBABILITY(tprob, temperature) \n IMPLICIT NONE \n REAL, INTENT(OUT) :: tprob(1:8) \n REAL, INTENT(IN) :: temperature \n INTEGER :: dE\n\n ! two possible value: exp(-4J) and exp(-8J)\n DO dE = 4, 8, 4\n tprob(dE) = EXP(-dE/temperature) \n END DO \nEND SUBROUTINE INIT_TRANSITION_PROBABILITY \n\nSUBROUTINE INIT_CONFIGURATION(spin, init_mag)\n IMPLICIT NONE \n INTEGER, INTENT(OUT) :: spin(LSIZE+2,LSIZE+2)\n INTEGER, INTENT(IN) :: init_mag \n INTEGER :: spin_up, spin_count\n INTEGER :: i, j \n\n spin_count = 0 \n spin_up = (NSPIN + init_mag )/2\n DO i = 2, LSIZE + 1 \n DO j = 2, LSIZE + 1 \n IF ( spin_count < spin_up ) THEN \n spin_count = spin_count + 1 \n spin(i,j) = 1 \n ELSE \n spin(i,j) = -1\n END IF \n END DO \n END DO \n\n ! Periodic boundary conditon \n spin(1,:) = spin(LSIZE+1,:) \n spin(LSIZE+2,:) = spin(2,:)\n spin(:,1) = spin(:,LSIZE+1)\n spin(:,LSIZE+2) = spin(:,2)\nEND SUBROUTINE INIT_CONFIGURATION\n\nSUBROUTINE METROPOLIS(tprob, spin, i, j, idata, ene, mag)\n IMPLICIT NONE \n REAL, INTENT(IN) :: tprob(1:8) \n INTEGER, INTENT(INOUT) :: spin(LSIZE+2,LSIZE+2) \n INTEGER, INTENT(IN) :: i, j\n INTEGER, INTENT(IN), OPTIONAL :: idata\n INTEGER, INTENT(OUT), OPTIONAL :: ene, mag\n INTEGER, SAVE :: local_ene, local_mag\n INTEGER :: dE \n REAL :: random \n LOGICAL :: move \n\n move = .FALSE. \n dE = 2*spin(i,j)*(spin(i-1,j) + spin(i+1,j) + spin(i,j-1) + spin(i,j+1))\n\n ! Metropolis condition\n IF ( dE <= 0 ) THEN \n move = .TRUE. \n ELSE \n CAll RANDOM_NUMBER(random) \n IF ( tprob(dE) > random ) THEN \n move = .TRUE.\n END IF \n END IF \n\n IF ( move ) THEN \n ! flip the spin\n spin(i,j) = -spin(i,j) \n ! Periodic boundary condition\n IF ( i == 2 ) spin(LSIZE+2,j) = spin(i,j)\n IF ( i == LSIZE+1 ) spin(1,j) = spin(i,j) \n IF ( j == 2 ) spin(i,LSIZE+2) = spin(i,j)\n IF ( j == LSIZE+1 ) spin(i,1) = spin(i,j)\n END IF \n\n ! data collection if idata, ene, and mag are passed to subroutine\n IF ( PRESENT(idata) .AND. PRESENT(ene) .AND. PRESENT(mag) ) THEN \n IF ( idata == 1 ) THEN \n local_ene = TOTAL_ENE(spin)\n local_mag = TOTAL_MAG(spin)\n END IF \n IF ( move ) THEN \n ene = local_ene + dE \n mag = local_mag + 2*spin(i,j)\n ELSE \n ene = local_ene \n mag = local_mag \n END IF \n ! save value of local_ene, and local_mag for next pass\n local_ene = ene \n local_mag = mag \n END IF \nEND SUBROUTINE METROPOLIS\n\nSUBROUTINE RESPONSE_FUNCTION(ene_per_spin, mag_per_spin, temperature, output) \n IMPLICIT NONE \n REAL, INTENT(IN) :: ene_per_spin(NSTEP*NSPIN), mag_per_spin(NSTEP*NSPIN)\n REAL, INTENT(IN) :: temperature\n INTEGER, INTENT(IN) :: output\n REAL :: ave_ene, ave_ene2, ave_mag, ave_mag2, Cv, chi\n \n ! Heat capacity\n ave_ene = SUM(ene_per_spin)/(NSTEP*NSPIN)\n ave_ene2 = SUM(ene_per_spin**2)/(NSTEP*NSPIN)\n Cv = NSPIN*(ave_ene2 - ave_ene**2)/(temperature**2)\n\n ! Magnetic susceptability \n ave_mag = SUM(mag_per_spin)/(NSTEP*NSPIN)\n ave_mag2 = SUM(mag_per_spin**2)/(NSTEP*NSPIN)\n chi = NSPIN*(ave_mag2 - ave_mag**2)/(temperature)\n\n WRITE (output, '(F7.3, 4(3X, F15.8))') temperature, ave_ene, ave_mag, Cv, chi\nEND SUBROUTINE RESPONSE_FUNCTION\n\nSUBROUTINE SPIN_CORRELATION(s, ss1, ss2, ss3, ss4, ss5, temperature, output) \n IMPLICIT NONE \n REAL, INTENT(IN) :: ss1(NSTEP*NSPIN), ss2(NSTEP*NSPIN), ss3(NSTEP*NSPIN),&\n ss4(NSTEP*NSPIN), ss5(NSTEP*NSPIN), s(NSTEP*NSPIN) \n REAL, INTENT(IN) :: temperature \n INTEGER, INTENT(IN) :: output \n \n REAL :: G2_1, G2_2, G2_3, G2_4, G2_5\n REAL :: s2 \n\n s2 = (SUM(s)/(NSTEP*NSPIN))**2 \n \n G2_1 = SUM(ss1)/(NSTEP*NSPIN) - s2\n G2_2 = SUM(ss2)/(NSTEP*NSPIN) - s2\n G2_3 = SUM(ss3)/(NSTEP*NSPIN) - s2\n G2_4 = SUM(ss4)/(NSTEP*NSPIN) - s2\n G2_5 = SUM(ss5)/(NSTEP*NSPIN) - s2\n\n WRITE (output, '(F7.3, 5(3X, F15.8))') temperature, G2_1, G2_2, G2_3, G2_4, G2_5\nEND SUBROUTINE SPIN_CORRELATION \n\nSUBROUTINE SPIN_CONFIGURATION(spin, output) \n IMPLICIT NONE \n INTEGER, INTENT(INOUT) :: spin(LSIZE+2,LSIZE+2)\n INTEGER, INTENT(IN) :: output\n INTEGER :: i, j \n\n DO i = 2, LSIZE + 1 \n DO j = 2, LSIZE + 1 \n IF ( spin(i,j) == 1 ) WRITE (output, '(I3,2(3X,I3))') i, j, 0 \n IF ( spin(i,j) == -1 ) WRITE (output, '(I3,2(3X,I3))') i, 0, j \n END DO \n END DO \n ! two blank space to separate between data block\n WRITE (output,*)\n WRITE (output,*)\nEND SUBROUTINE SPIN_CONFIGURATION\n\nINTEGER FUNCTION TOTAL_ENE(spin) \n IMPLICIT NONE\n INTEGER, INTENT(INOUT) :: spin(LSIZE+2,LSIZE+2) \n INTEGER :: i, j \n\n TOTAL_ENE = 0.0\n DO i = 2, LSIZE + 1 \n DO j = 2, LSIZE + 1 \n TOTAL_ENE = TOTAL_ENE - spin(i,j)*(spin(i-1,j) + spin(i+1,j) + spin(i,j-1) + spin(i,j+1))\n END DO \n END DO \n \n ! Double counting\n TOTAL_ENE = TOTAL_ENE/2\nEND FUNCTION TOTAL_ENE\n\nINTEGER FUNCTION TOTAL_MAG(spin)\n IMPLICIT NONE \n INTEGER, INTENT(INOUT) :: spin(LSIZE+2,LSIZE+2) \n\n TOTAL_MAG = SUM(spin(2:LSIZE+1,2:LSIZE+1))\nEND FUNCTION TOTAL_MAG\nEND MODULE ISING\n", "meta": {"hexsha": "ee4bcf133f76f3a6b5ff4c928891b97d9a16f566", "size": 6203, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ising.f90", "max_stars_repo_name": "vitduck/Ising2D", "max_stars_repo_head_hexsha": "d78685896551460af699d607446696fb12ff9832", "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": "ising.f90", "max_issues_repo_name": "vitduck/Ising2D", "max_issues_repo_head_hexsha": "d78685896551460af699d607446696fb12ff9832", "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": "ising.f90", "max_forks_repo_name": "vitduck/Ising2D", "max_forks_repo_head_hexsha": "d78685896551460af699d607446696fb12ff9832", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.8961748634, "max_line_length": 101, "alphanum_fraction": 0.5255521522, "num_tokens": 1996, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.851952809486198, "lm_q2_score": 0.7772998508568417, "lm_q1q2_score": 0.662222791750689}} {"text": "module SmoothingModule\n use KindModule, only: DP, I4B\n use ConstantsModule, only: DZERO, DHALF, DONE, DTWO, DTHREE, DFOUR, &\n & DSIX, DPREC, DEM2, DEM4, DEM5, DEM6, DEM8, DEM14 \n implicit none\n \n contains\n \n subroutine sSCurve(x,range,dydx,y)\n! ******************************************************************************\n! COMPUTES THE S CURVE FOR SMOOTH DERIVATIVES BETWEEN X=0 AND X=1\n! FROM mfusg smooth SUBROUTINE in gwf2wel7u1.f\n! ******************************************************************************\n! \n! SPECIFICATIONS:\n! ------------------------------------------------------------------------------\n real(DP), intent(in) :: x\n real(DP), intent(in) :: range\n real(DP), intent(inout) :: dydx\n real(DP), intent(inout) :: y\n !--local variables\n real(DP) :: s\n real(DP) :: xs\n! ------------------------------------------------------------------------------\n! code\n!\n s = range\n if ( s < DPREC ) s = DPREC\n xs = x / s\n if (xs < DZERO) xs = DZERO\n if (xs <= DZERO) then\n y = DZERO\n dydx = DZERO\n elseif(xs < DONE)then\n y = -DTWO * xs**DTHREE + DTHREE * xs**DTWO\n dydx = -DSIX * xs**DTWO + DSIX * xs\n else\n y = DONE\n dydx = DZERO\n endif\n return\n end subroutine sSCurve\n \n subroutine sCubicLinear(x,range,dydx,y)\n! ******************************************************************************\n! COMPUTES THE S CURVE WHERE DY/DX = 0 at X=0; AND DY/DX = 1 AT X=1.\n! Smooths from zero to a slope of 1.\n! ******************************************************************************\n! \n! SPECIFICATIONS:\n! ------------------------------------------------------------------------------\n real(DP), intent(in) :: x\n real(DP), intent(in) :: range\n real(DP), intent(inout) :: dydx\n real(DP), intent(inout) :: y\n !--local variables\n real(DP) :: s\n real(DP) :: xs\n! ------------------------------------------------------------------------------\n! code\n!\n s = range\n if ( s < DPREC ) s = DPREC\n xs = x / s\n if (xs < DZERO) xs = DZERO\n if (xs <= DZERO) then\n y = DZERO\n dydx = DZERO\n elseif(xs < DONE)then\n y = -DONE * xs**DTHREE + DTWO * xs**DTWO\n dydx = -DTHREE * xs**DTWO + DFOUR * xs\n else\n y = DONE\n dydx = DZERO\n endif\n return\n end subroutine sCubicLinear\n\n subroutine sCubic(x,range,dydx,y)\n! ******************************************************************************\n! Nonlinear smoothing function returns value between 0-1; cubic function\n! ******************************************************************************\n! \n! SPECIFICATIONS:\n! ------------------------------------------------------------------------------\n real(DP), intent(inout) :: x\n real(DP), intent(inout) :: range\n real(DP), intent(inout) :: dydx\n real(DP), intent(inout) :: y\n !--local variables\n real(DP) :: s, aa, bb\n real(DP) :: cof1, cof2, cof3\n! ------------------------------------------------------------------------------\n! code\n!\n dydx = DZERO\n y = DZERO\n if ( range < DPREC ) range = DPREC\n if ( x < DPREC ) x = DPREC\n s = range\n aa = -DSIX/(s**DTHREE)\n bb = -DSIX/(s**DTWO)\n cof1 = x**DTWO\n cof2 = -(DTWO*x)/(s**DTHREE)\n cof3 = DTHREE/(s**DTWO)\n y = cof1 * (cof2 + cof3)\n dydx = (aa*x**DTWO - bb*x)\n if ( x <= DZERO ) then\n y = DZERO\n dydx = DZERO\n else if ( (x - s) > -DPREC ) then\n y = DONE\n dydx = DZERO\n end if\n return\n end subroutine sCubic\n \n subroutine sLinear(x,range,dydx,y)\n! ******************************************************************************\n! Linear smoothing function returns value between 0-1\n! ******************************************************************************\n! \n! SPECIFICATIONS:\n! ------------------------------------------------------------------------------\n real(DP), intent(inout) :: x\n real(DP), intent(inout) :: range\n real(DP), intent(inout) :: dydx\n real(DP), intent(inout) :: y\n !--local variables\n real(DP) :: s\n! ------------------------------------------------------------------------------\n! code\n!\n dydx = DZERO\n y = DZERO\n if ( range < DPREC ) range = DPREC\n if ( x < DPREC ) x = DPREC\n s = range\n y = DONE - (s - x)/s\n dydx = DONE/s\n if ( y > DONE ) then\n y = DONE\n dydx = DZERO\n end if\n return\n end subroutine sLinear\n \n subroutine sQuadratic(x,range,dydx,y)\n! ******************************************************************************\n! Nonlinear smoothing function returns value between 0-1; quadratic function\n! ******************************************************************************\n! \n! SPECIFICATIONS:\n! ------------------------------------------------------------------------------\n real(DP), intent(inout) :: x\n real(DP), intent(inout) :: range\n real(DP), intent(inout) :: dydx\n real(DP), intent(inout) :: y\n !--local variables\n real(DP) :: s\n! ------------------------------------------------------------------------------\n! code\n!\n dydx = DZERO\n y = DZERO\n if ( range < DPREC ) range = DPREC\n if ( x < DPREC ) x = DPREC\n s = range\n y = (x**DTWO) / (s**DTWO)\n dydx = DTWO*x/(s**DTWO)\n if ( y > DONE ) then\n y = DONE\n dydx = DZERO\n end if\n return\n end subroutine sQuadratic\n\n subroutine sChSmooth(d, smooth, dwdh)\n! ******************************************************************************\n! Function to smooth channel variables during channel drying\n! ******************************************************************************\n! \n! SPECIFICATIONS:\n! ------------------------------------------------------------------------------\n real(DP), intent(in) :: d\n real(DP), intent(inout) :: smooth\n real(DP), intent(inout) :: dwdh\n !\n ! -- local variables\n real(DP) :: s\n real(DP) :: diff\n real(DP) :: aa\n real(DP) :: ad\n real(DP) :: b\n real(DP) :: x\n real(DP) :: y\n! ------------------------------------------------------------------------------\n! code\n! \n smooth = DZERO\n s = DEM5\n x = d\n diff = x - s\n if ( diff > DZERO ) then\n smooth = DONE\n dwdh = DZERO\n else\n aa = -DONE / (s**DTWO)\n ad = -DTWO / (s**DTWO)\n b = DTWO / s\n y = aa * x**DTWO + b*x\n dwdh = (ad*x + b)\n if ( x <= DZERO ) then\n y = DZERO\n dwdh = DZERO\n else if ( diff > -DEM14 ) then\n y = DONE\n dwdh = DZERO\n end if\n smooth = y\n end if\n return\nend subroutine sChSmooth\n \n function sLinearSaturation(top, bot, x) result(y)\n! ******************************************************************************\n! Linear smoothing function returns value between 0-1;\n! Linear saturation function\n! ******************************************************************************\n! \n! SPECIFICATIONS:\n! ------------------------------------------------------------------------------\n ! -- return\n real(DP) :: y\n ! -- dummy variables\n real(DP), intent(in) :: top\n real(DP), intent(in) :: bot\n real(DP), intent(in) :: x\n ! -- local\n real(DP) :: b\n! ------------------------------------------------------------------------------\n! code\n!\n b = top - bot\n if (x < bot) then\n y = DZERO\n else if (x > top) then\n y = DONE\n else\n y = (x - bot) / b\n end if\n return\n end function sLinearSaturation\n\n\n function sCubicSaturation(top, bot, x, eps) result(y)\n! ******************************************************************************\n! Nonlinear smoothing function returns value between 0-1;\n! Quadratic saturation function\n! ******************************************************************************\n! \n! SPECIFICATIONS:\n! ------------------------------------------------------------------------------\n ! -- return\n real(DP) :: y\n ! -- dummy variables\n real(DP), intent(in) :: top\n real(DP), intent(in) :: bot\n real(DP), intent(in) :: x\n real(DP), intent(in), optional :: eps\n ! -- local\n real(DP) :: teps\n real(DP) :: w\n real(DP) :: b\n real(DP) :: s\n real(DP) :: cof1\n real(DP) :: cof2\n! ------------------------------------------------------------------------------\n! code\n!\n if (present(eps)) then\n teps = eps\n else\n teps = DEM2\n end if\n w = x - bot\n b = top - bot\n s = teps * b\n cof1 = DONE / (s**DTWO)\n cof2 = DTWO / s\n if (w < DZERO) then\n y = DZERO\n else if (w < s) then\n y = -cof1 * (w**DTHREE) + cof2 * (w**DTWO)\n else if (w < (b-s)) then\n y = w / b\n else if (w < b) then\n y = DONE + cof1 * ((b - w)**DTHREE) - cof2 * ((b - w)**DTWO)\n else\n y = DONE\n end if\n \n return\n end function sCubicSaturation\n\n \n function sQuadraticSaturation(top, bot, x, eps, bmin) result(y)\n! ******************************************************************************\n! Nonlinear smoothing function returns value between 0-1;\n! Quadratic saturation function\n! ******************************************************************************\n! \n! SPECIFICATIONS:\n! ------------------------------------------------------------------------------\n ! -- return\n real(DP) :: y\n ! -- dummy variables\n real(DP), intent(in) :: top\n real(DP), intent(in) :: bot\n real(DP), intent(in) :: x\n real(DP), optional, intent(in) :: eps\n real(DP), optional, intent(in) :: bmin\n ! -- local\n real(DP) :: teps\n real(DP) :: tbmin\n real(DP) :: b\n real(DP) :: br\n real(DP) :: bri\n real(DP) :: av\n! ------------------------------------------------------------------------------\n! code\n!\n if (present(eps)) then\n teps = eps\n else\n teps = DEM6\n end if\n if (present(bmin)) then\n tbmin = bmin\n else\n tbmin = DZERO\n end if\n b = top - bot\n if (b > DZERO) then\n if (x < bot) then\n br = DZERO\n else if (x > top) then\n br = DONE\n else\n br = (x - bot) / b\n end if\n av = DONE / (DONE - teps) \n bri = DONE - br\n if (br < tbmin) then\n br = tbmin\n end if\n if (br < teps) then\n y = av * DHALF * (br*br) / teps\n elseif (br < (DONE-teps)) then\n y = av * br + DHALF * (DONE - av)\n elseif (br < DONE) then\n y = DONE - ((av * DHALF * (bri * bri)) / teps)\n else\n y = DONE\n end if\n else\n if (x < bot) then\n y = DZERO\n else\n y = DONE\n end if\n end if\n \n return\n end function sQuadraticSaturation\n \n function svanGenuchtenSaturation(top, bot, x, alpha, beta, sr) result(y)\n! ******************************************************************************\n! Nonlinear smoothing function returns value between 0-1;\n! van Genuchten saturation function\n! ******************************************************************************\n! \n! SPECIFICATIONS:\n! ------------------------------------------------------------------------------\n ! -- return\n real(DP) :: y\n ! -- dummy variables\n real(DP), intent(in) :: top\n real(DP), intent(in) :: bot\n real(DP), intent(in) :: x\n real(DP), intent(in) :: alpha\n real(DP), intent(in) :: beta\n real(DP), intent(in) :: sr\n ! -- local\n real(DP) :: b\n real(DP) :: pc\n real(DP) :: gamma\n real(DP) :: seff\n! ------------------------------------------------------------------------------\n! code\n!\n b = top - bot\n pc = (DHALF * b) - x\n if (pc <= DZERO) then\n y = DZERO\n else\n gamma = DONE - (DONE / beta)\n seff = (DONE + (alpha * pc)**beta)**gamma\n seff = DONE / seff\n y = seff * (DONE - sr) + sr\n end if\n\n return\n end function svanGenuchtenSaturation\n \n \n function sQuadraticSaturationDerivative(top, bot, x, eps, bmin) result(y)\n! ******************************************************************************\n! Derivative of nonlinear smoothing function returns value between 0-1;\n! Derivative of the quadratic saturation function\n! ******************************************************************************\n! \n! SPECIFICATIONS:\n! ------------------------------------------------------------------------------\n ! -- return\n real(DP) :: y\n ! -- dummy variables\n real(DP), intent(in) :: top\n real(DP), intent(in) :: bot\n real(DP), intent(in) :: x\n real(DP), optional, intent(in) :: eps\n real(DP), optional, intent(in) :: bmin\n ! -- local\n real(DP) :: teps\n real(DP) :: tbmin\n real(DP) :: b\n real(DP) :: br\n real(DP) :: bri\n real(DP) :: av\n! ------------------------------------------------------------------------------\n! code\n!\n if (present(eps)) then\n teps = eps\n else\n teps = DEM6\n end if\n if (present(bmin)) then\n tbmin = bmin\n else\n tbmin = DZERO\n end if\n b = top - bot\n if (x < bot) then\n br = DZERO\n else if (x > top) then\n br = DONE\n else\n br = (x - bot) / b\n end if\n av = DONE / (DONE - teps) \n bri = DONE - br\n if (br < tbmin) then\n br = tbmin\n end if\n if (br < teps) then\n y = av * br / teps\n elseif (br < (DONE-teps)) then\n y = av\n elseif (br < DONE) then\n y = av * bri / teps\n else\n y = DZERO\n end if\n y = y / b\n \n return\n end function sQuadraticSaturationDerivative\n\n\n\n function sQSaturation(top, bot, x, c1, c2) result(y)\n! ******************************************************************************\n! Nonlinear smoothing function returns value between 0-1;\n! Cubic saturation function\n! ******************************************************************************\n! \n! SPECIFICATIONS:\n! ------------------------------------------------------------------------------\n ! -- return\n real(DP) :: y\n ! -- dummy variables\n real(DP), intent(in) :: top\n real(DP), intent(in) :: bot\n real(DP), intent(in) :: x\n real(DP), intent(in), optional :: c1\n real(DP), intent(in), optional :: c2\n ! -- local\n real(DP) :: w\n real(DP) :: b\n real(DP) :: s\n real(DP) :: cof1\n real(DP) :: cof2\n! ------------------------------------------------------------------------------\n! code\n!\n !\n ! -- process optional variables\n if (present(c1)) then\n cof1 = c1\n else\n cof1 = -DTWO\n end if\n if (present(c2)) then\n cof2 = c2\n else\n cof2 = DTHREE\n end if\n !\n ! -- calculate head diference from bottom (w),\n ! calculate range (b), and\n ! calculate normalized head difference from bottom (s)\n w = x - bot\n b = top - bot\n s = w / b\n !\n ! -- divide cof1 and cof2 by range to the power 3 and 2, respectively\n cof1 = cof1 / b**DTHREE\n cof2 = cof2 / b**DTWO\n !\n ! -- calculate fraction\n if (s < DZERO) then\n y = DZERO\n else if(s < DONE) then\n y = cof1 * w**DTHREE + cof2 * w**DTWO\n else\n y = DONE\n end if\n !\n ! -- return\n return\n end function sQSaturation\n \n function sQSaturationDerivative(top, bot, x, c1, c2) result(y)\n! ******************************************************************************\n! Nonlinear smoothing function returns value between 0-1;\n! Cubic saturation function\n! ******************************************************************************\n! \n! SPECIFICATIONS:\n! ------------------------------------------------------------------------------\n ! -- return\n real(DP) :: y\n ! -- dummy variables\n real(DP), intent(in) :: top\n real(DP), intent(in) :: bot\n real(DP), intent(in) :: x\n real(DP), intent(in), optional :: c1\n real(DP), intent(in), optional :: c2\n ! -- local\n real(DP) :: w\n real(DP) :: b\n real(DP) :: s\n real(DP) :: cof1\n real(DP) :: cof2\n! ------------------------------------------------------------------------------\n! code\n!\n !\n ! -- process optional variables\n if (present(c1)) then\n cof1 = c1 \n else\n cof1 = -DTWO\n end if\n if (present(c2)) then\n cof2 = c2\n else\n cof2 = DTHREE\n end if\n !\n ! -- calculate head diference from bottom (w),\n ! calculate range (b), and\n ! calculate normalized head difference from bottom (s)\n w = x - bot\n b = top - bot\n s = w / b\n !\n ! -- multiply cof1 and cof2 by 3 and 2, respectively, and then \n ! divide by range to the power 3 and 2, respectively\n cof1 = cof1 * DTHREE / b**DTHREE\n cof2 = cof2 * DTWO / b**DTWO\n !\n ! -- calculate derivative of fraction with respect to x\n if (s < DZERO) then\n y = DZERO\n else if(s < DONE) then\n y = cof1 * w**DTWO + cof2 * w\n else\n y = DZERO\n end if\n !\n ! -- return\n return\n end function sQSaturationDerivative\n \n function sSlope(x, xi, yi, sm, sp, ta) result(y)\n! ******************************************************************************\n! Nonlinear smoothing function returns a smoothed value of y that has the value\n! yi at xi and yi + (sm * dx) for x-values less than xi and yi + (sp * dx) for\n! x-values greater than xi, where dx = x - xi.\n! ******************************************************************************\n! \n! SPECIFICATIONS:\n! ------------------------------------------------------------------------------\n ! -- return\n real(DP) :: y\n ! -- dummy variables\n real(DP), intent(in) :: x\n real(DP), intent(in) :: xi\n real(DP), intent(in) :: yi\n real(DP), intent(in) :: sm\n real(DP), intent(in) :: sp\n real(DP), optional, intent(in) :: ta\n ! -- local\n real(DP) :: a\n real(DP) :: b\n real(DP) :: dx\n real(DP) :: xm\n real(DP) :: xp\n real(DP) :: ym\n real(DP) :: yp\n! ------------------------------------------------------------------------------\n !\n ! -- set smoothing variable a\n if (present(ta)) then\n a = ta\n else\n a = DEM8\n end if\n !\n ! -- calculate b from smoothing variable a\n b = a / (sqrt(DTWO) - DONE)\n !\n ! -- calculate contributions to y\n dx = x - xi\n xm = DHALF * (x + xi - sqrt(dx + b**DTWO - a**DTWO))\n xp = DHALF * (x + xi + sqrt(dx + b**DTWO - a**DTWO))\n ym = sm * (xm - xi)\n yp = sp * (xi - xp)\n !\n ! -- calculate y from ym and yp contributions\n y = yi + ym + yp\n !\n ! -- return\n return\n end function sSlope \n \n function sSlopeDerivative(x, xi, sm, sp, ta) result(y)\n! ******************************************************************************\n! Derivative of nonlinear smoothing function that has the value yi at xi and \n! yi + (sm * dx) for x-values less than xi and yi + (sp * dx) for x-values \n! greater than xi, where dx = x - xi.\n! ******************************************************************************\n! \n! SPECIFICATIONS:\n! ------------------------------------------------------------------------------\n ! -- return\n real(DP) :: y\n ! -- dummy variables\n real(DP), intent(in) :: x\n real(DP), intent(in) :: xi\n real(DP), intent(in) :: sm\n real(DP), intent(in) :: sp\n real(DP), optional, intent(in) :: ta\n ! -- local\n real(DP) :: a\n real(DP) :: b\n real(DP) :: dx\n real(DP) :: mu\n real(DP) :: rho\n! ------------------------------------------------------------------------------\n !\n ! -- set smoothing variable a\n if (present(ta)) then\n a = ta\n else\n a = DEM8\n end if\n !\n ! -- calculate b from smoothing variable a\n b = a / (sqrt(DTWO) - DONE)\n !\n ! -- calculate contributions to derivative\n dx = x - xi\n mu = sqrt(dx**DTWO + b**DTWO - a**DTWO)\n rho = dx / mu\n !\n ! -- calculate derivative from individual contributions\n y = DHALF * (sm + sp) - DHALF * rho * (sm - sp) \n !\n ! -- return\n return\n end function sSlopeDerivative \n \n function sQuadratic0sp(x, xi, tomega) result(y)\n! ******************************************************************************\n! Nonlinear smoothing function returns a smoothed value of y that uses a \n! quadratic to smooth x over range of xi - epsilon to xi + epsilon.\n! Simplification of sQuadraticSlope with sm = 0, sp = 1, and yi = 0.\n! From Panday et al. (2013) - eq. 35 - https://dx.doi.org/10.5066/F7R20ZFJ\n! ******************************************************************************\n! \n! SPECIFICATIONS:\n! ------------------------------------------------------------------------------\n ! -- return\n real(DP) :: y\n ! -- dummy variables\n real(DP), intent(in) :: x\n real(DP), intent(in) :: xi\n real(DP), optional, intent(in) :: tomega\n ! -- local\n real(DP) :: omega\n real(DP) :: epsilon\n real(DP) :: dx\n! ------------------------------------------------------------------------------\n !\n ! -- set smoothing interval\n if (present(tomega)) then\n omega = tomega\n else\n omega = DEM6\n end if\n !\n ! -- set smoothing interval\n epsilon = DHALF * omega\n !\n ! -- calculate distance from xi\n dx = x - xi\n !\n ! -- evaluate smoothing function\n if (dx < -epsilon) then\n y = xi\n else if (dx < epsilon) then\n y = (dx**DTWO / (DFOUR * epsilon)) + DHALF * dx + (epsilon / DFOUR) + xi\n else\n y = x\n end if\n !\n ! -- return\n return\n end function sQuadratic0sp \n \n function sQuadratic0spDerivative(x, xi, tomega) result(y)\n! ******************************************************************************\n! Derivative of nonlinear smoothing function returns a smoothed value of y \n! that uses a quadratic to smooth x over range of xi - epsilon to xi + epsilon.\n! Simplification of sQuadraticSlope with sm = 0, sp = 1, and yi = 0.\n! From Panday et al. (2013) - eq. 35 - https://dx.doi.org/10.5066/F7R20ZFJ\n! ******************************************************************************\n! \n! SPECIFICATIONS:\n! ------------------------------------------------------------------------------\n ! -- return\n real(DP) :: y\n ! -- dummy variables\n real(DP), intent(in) :: x\n real(DP), intent(in) :: xi\n real(DP), optional, intent(in) :: tomega\n ! -- local\n real(DP) :: omega\n real(DP) :: epsilon\n real(DP) :: dx\n! ------------------------------------------------------------------------------\n !\n ! -- set smoothing interval\n if (present(tomega)) then\n omega = tomega\n else\n omega = DEM6\n end if\n !\n ! -- set smoothing interval\n epsilon = DHALF * omega\n !\n ! -- calculate distance from xi\n dx = x - xi\n !\n ! -- evaluate smoothing function\n if (dx < -epsilon) then\n y = 0\n else if (dx < epsilon) then\n y = (dx / omega) + DHALF\n else\n y = 1\n end if\n !\n ! -- return\n return\n end function sQuadratic0spDerivative \n \n function sQuadraticSlope(x, xi, yi, sm, sp, tomega) result(y)\n! ******************************************************************************\n! Quadratic smoothing function returns a smoothed value of y that has the value\n! yi at xi and yi + (sm * dx) for x-values less than xi and yi + (sp * dx) for\n! x-values greater than xi, where dx = x - xi.\n! ******************************************************************************\n! \n! SPECIFICATIONS:\n! ------------------------------------------------------------------------------\n ! -- return\n real(DP) :: y\n ! -- dummy variables\n real(DP), intent(in) :: x\n real(DP), intent(in) :: xi\n real(DP), intent(in) :: yi\n real(DP), intent(in) :: sm\n real(DP), intent(in) :: sp\n real(DP), optional, intent(in) :: tomega\n ! -- local\n real(DP) :: omega\n real(DP) :: epsilon\n real(DP) :: dx\n real(DP) :: c\n! ------------------------------------------------------------------------------\n !\n ! -- set smoothing interval\n if (present(tomega)) then\n omega = tomega\n else\n omega = DEM6\n end if\n !\n ! -- set smoothing interval\n epsilon = DHALF * omega\n !\n ! -- calculate distance from xi\n dx = x - xi\n !\n ! -- evaluate smoothing function\n if (dx < -epsilon) then\n y = sm * dx\n else if (dx < epsilon) then\n c = dx / epsilon\n y = DHALF * epsilon * (DHALF * (sp - sm) * (DONE + c**DTWO) + (sm + sp) * c)\n else\n y = sp * dx\n end if\n !\n ! -- add value at xi\n y = y + yi\n !\n ! -- return\n return\n end function sQuadraticSlope \n \n \n function sQuadraticSlopeDerivative(x, xi, sm, sp, tomega) result(y)\n! ******************************************************************************\n! Derivative of quadratic smoothing function returns a smoothed value of y \n! that has the value yi at xi and yi + (sm * dx) for x-values less than xi and \n! yi + (sp * dx) for x-values greater than xi, where dx = x - xi.\n! ******************************************************************************\n! \n! SPECIFICATIONS:\n! ------------------------------------------------------------------------------\n ! -- return\n real(DP) :: y\n ! -- dummy variables\n real(DP), intent(in) :: x\n real(DP), intent(in) :: xi\n real(DP), intent(in) :: sm\n real(DP), intent(in) :: sp\n real(DP), optional, intent(in) :: tomega\n ! -- local\n real(DP) :: omega\n real(DP) :: epsilon\n real(DP) :: dx\n real(DP) :: c\n! ------------------------------------------------------------------------------\n !\n ! -- set smoothing interval\n if (present(tomega)) then\n omega = tomega\n else\n omega = DEM6\n end if\n !\n ! -- set smoothing interval\n epsilon = DHALF * omega\n !\n ! -- calculate distance from xi\n dx = x - xi\n !\n ! -- evaluate smoothing function\n if (dx < -epsilon) then\n y = sm\n else if (dx < epsilon) then\n c = dx / epsilon\n y = DHALF * ((sp - sm) * c + (sm + sp))\n else\n y = sp\n end if\n !\n ! -- return\n return\n end function sQuadraticSlopeDerivative \n \nend module SmoothingModule\n", "meta": {"hexsha": "12ae5ad60f4fbe213c50ab93a50fab3e59856768", "size": 25901, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/Utilities/SmoothingFunctions.f90", "max_stars_repo_name": "scharlton2/modflow6", "max_stars_repo_head_hexsha": "83ac72ee3b6f580aaffef6352cf15c1697d3ce66", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 102, "max_stars_repo_stars_event_min_datetime": "2017-12-19T09:56:38.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T01:47:28.000Z", "max_issues_repo_path": "src/Utilities/SmoothingFunctions.f90", "max_issues_repo_name": "scharlton2/modflow6", "max_issues_repo_head_hexsha": "83ac72ee3b6f580aaffef6352cf15c1697d3ce66", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 331, "max_issues_repo_issues_event_min_datetime": "2018-01-10T21:22:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T05:57:00.000Z", "max_forks_repo_path": "src/Utilities/SmoothingFunctions.f90", "max_forks_repo_name": "scharlton2/modflow6", "max_forks_repo_head_hexsha": "83ac72ee3b6f580aaffef6352cf15c1697d3ce66", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 87, "max_forks_repo_forks_event_min_datetime": "2017-12-13T21:40:39.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T05:31:40.000Z", "avg_line_length": 28.4626373626, "max_line_length": 82, "alphanum_fraction": 0.4137678082, "num_tokens": 6844, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528019683105, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.6622227859070361}} {"text": "program complex_06\nimplicit none\n\nreal, parameter :: a = 3.0, b = 4.0\ncomplex, parameter :: i_ = (0, 1)\ncomplex, parameter :: z = a + i_*b\nreal, parameter :: x = z\nreal, parameter :: y = real(z)\nreal, parameter :: w = aimag(z)\n\nprint *, x, y, w\n\nend program\n", "meta": {"hexsha": "1184957571d40918d4b2bc22dbf454d8c04bc123", "size": 258, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "integration_tests/complex_06.f90", "max_stars_repo_name": "Thirumalai-Shaktivel/lfortran", "max_stars_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 316, "max_stars_repo_stars_event_min_datetime": "2019-03-24T16:23:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:28:33.000Z", "max_issues_repo_path": "integration_tests/complex_06.f90", "max_issues_repo_name": "Thirumalai-Shaktivel/lfortran", "max_issues_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-07-29T04:58:03.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-04T16:40:06.000Z", "max_forks_repo_path": "integration_tests/complex_06.f90", "max_forks_repo_name": "Thirumalai-Shaktivel/lfortran", "max_forks_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2019-03-28T19:40:07.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T07:28:55.000Z", "avg_line_length": 18.4285714286, "max_line_length": 35, "alphanum_fraction": 0.6240310078, "num_tokens": 89, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8519527944504227, "lm_q2_score": 0.7772998508568417, "lm_q1q2_score": 0.6622227800633831}} {"text": "! gfortran -03 -I$SHTOOLSMODPATH_GCC -L$SHTOOLSLIBPATH_GCC -L$FFTW3_LIB_DIR_GCC -lSHTOOLS2.8 -llapack -lblas -lfftw3 -lm TEST_RESULTS.f90 -o TEST_RESULTS\n\n\nPROGRAM TEST_RESULTS\n\tUSE SHTOOLS\n\t\n\tREAL*8 :: DAT(181,361)\n\tREAL*8 :: CILM(2,10,10)\n\tinteger :: SH_LMAX, I, J\n\t\n\tOPEN(34, FILE=\"/Users/dchandan/Volumes/Elysium/Data1/CommonData/Dynamic_topography/C2E5/dyntopoC2E5_l1-22.txt\", STATUS=\"OLD\")\n\tDO I= 1,181\n\t\tREAD(34, *) DAT(I,:)\n\tENDDO\n\tCLOSE(34)\n\t\n\tOPEN(34, FILE=\"FieldRead.txt\", STATUS=\"REPLACE\")\n\tDO I=1,181\n\t\tWRITE(34, *) DAT(I,:)\n\tENDDO\n\tCLOSE(34)\n\t\n\tOPEN(34, FILE=\"Coeffs.txt\", STATUS=\"REPLACE\")\n\tCALL SHExpandDH(DAT(1:180,1:360), 180, CILM, LMAX=SH_LMAX, NORM=4, SAMPLING=2, LMAX_CALC=9)\n\tDO I =1,10\n\t\tWRITE(34, '(10F6.3)') CILM(1,I,:)\n\tENDDO\n\tCLOSE(34)\n\t\nEND PROGRAM TEST_RESULTS", "meta": {"hexsha": "66544f0880e5ed4f8328cd03234db67b4539b99b", "size": 798, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/TEST_RESULTS.f90", "max_stars_repo_name": "dchandan/PySHTOOLS", "max_stars_repo_head_hexsha": "8b1c32229db87b43d3f40d8f759a3e939f9d9a54", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-11-19T14:48:22.000Z", "max_stars_repo_stars_event_max_datetime": "2017-11-19T14:48:22.000Z", "max_issues_repo_path": "tests/TEST_RESULTS.f90", "max_issues_repo_name": "dchandan/PySHTOOLS", "max_issues_repo_head_hexsha": "8b1c32229db87b43d3f40d8f759a3e939f9d9a54", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-01-30T07:08:55.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-30T07:08:55.000Z", "max_forks_repo_path": "tests/TEST_RESULTS.f90", "max_forks_repo_name": "dchandan/PySHTOOLS", "max_forks_repo_head_hexsha": "8b1c32229db87b43d3f40d8f759a3e939f9d9a54", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.6, "max_line_length": 153, "alphanum_fraction": 0.6892230576, "num_tokens": 357, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563335, "lm_q2_score": 0.7490872243177518, "lm_q1q2_score": 0.6622225363281428}} {"text": "c\nc\nc ... file rgrd3.f\nc\nc this file contains documentation for subroutine rgrd3 followed by\nc fortran code for rgrd3 and additional subroutines.\nc\nc ... author\nc\nc John C. Adams (NCAR 1999)\nc\nc ... subroutine rgrd3(nx,ny,nz,x,y,z,p,mx,my,mz,xx,yy,zz,q,intpol,\nc + w,lw,iw,liw,ier)\nc\nc ... purpose\nc\nc subroutine rgrd3 interpolates the values p(i,j,k) on the orthogonal\nc grid (x(i),y(j),z(k)) for i=1,...,nx; j=1,...,ny; k=1,...,nz\nc onto q(ii,jj,kk) on the orthogonal grid (xx(ii),yy(jj),zz(kk)) for\nc ii=1,...,mx; jj=1,...,my; kk=1,...,mz.\nc\nc ... language\nc\nc coded in portable FORTRAN77 and FORTRAN90\nc\nc ... test program\nc\nc file trgrd3.f on regridpack includes a test program for subroutine rgrd3\nc\nc ... method\nc\nc linear or cubic interpolation is used (independently) in\nc each direction (see argument intpol).\nc\nc ... required files\nc\nc files rgrd2.f and rgrd1.f must be loaded with rgrd3.f. they\nc include subroutines called by the routines in rgrd3.f\nc\nc ... requirements\nc\nc each of the x,y,z grids must be strictly montonically increasing\nc and each of the xx,yy,zz grids must be montonically increasing\nc (see ier = 4). in addition the (X,Y,Z) region\nc\nc [xx(1),xx(mx)] X [yy(1),yy(my)] X [zz(1),zz(mz)]\nc\nc must lie within the (X,Y,Z) region\nc\nc [x(1),x(nx)] X [y(1),y(ny)] X [z(1),z(nz)].\nc\nc extrapolation is not allowed (see ier=3). if these (X,Y,Z)\nc regions are identical and the orthogonal grids are UNIFORM\nc in each direction then subroutine rgrd3u (see file rgrd3u.f)\nc should be used instead of rgrd3.\nc\nc ... efficiency\nc\nc inner most loops in regridpack software vectorize. if\nc the integer arguments mx,my,mz (see below) have different values,\nc optimal vectorization will be achieved if mx > my > mz.\nc\nc *** input arguments\nc\nc ... nx\nc\nc the integer dimension of the grid vector x and the first dimension of p.\nc nx > 1 if intpol(1) = 1 or nx > 3 if intpol(1) = 3 is required.\nc\nc ... ny\nc\nc the integer dimension of the grid vector y and the second dimension of p.\nc ny > 1 if intpol(2) = 1 or ny > 3 if intpol(2) = 3 is required.\nc\nc ... nz\nc\nc the integer dimension of the grid vector z and the third dimension of p.\nc nz > 1 if intpol(3) = 1 or nz > 3 if intpol(3) = 3 is required.\nc\nc ... x\nc\nc a real nx vector of strictly increasing values which defines the x\nc portion of the orthogonal grid on which p is given\nc\nc ... y\nc\nc a real ny vector of strictly increasing values which defines the y\nc portion of the orthogonal grid on which p is given\nc\nc ... z\nc\nc a real nz vector of strictly increasing values which defines the z\nc portion of the orthogonal grid on which p is given\nc\nc ... p\nc\nc a real nx by ny by nz array of values given on the (x,y,z) grid\nc\nc ... mx\nc\nc the integer dimension of the grid vector xx and the first dimension of q.\nc mx > 0 is required.\nc\nc ... my\nc\nc the integer dimension of the grid vector yy and the second dimension of q.\nc my > 0 is required.\nc\nc ... mz\nc\nc the integer dimension of the grid vector zz and the third dimension of q.\nc mz > 0 is required.\nc\nc ... xx\nc\nc a real mx vector of increasing values which defines the x portion of the\nc orthogonal grid on which q is defined. xx(1) < x(1) or xx(mx) > x(nx)\nc is not allowed (see ier = 3)\nc\nc ... yy\nc\nc a real my vector of increasing values which defines the y portion of the\nc orthogonal grid on which q is defined. yy(1) < y(1) or yy(my) > y(ny)\nc is not allowed (see ier = 3)\nc\nc ... zz\nc\nc a real mz vector of increasing values which defines the z portion of the\nc orthogonal grid on which q is defined. zz(1) < z(1) or zz(mz) > z(nz)\nc is not allowed (see ier = 3)\nc\nc ... intpol\nc\nc an integer vector of dimension 3 which sets linear or cubic\nc interpolation in each of the x,y,z directions as follows:\nc\nc intpol(1) = 1 sets linear interpolation in the x direction\nc intpol(1) = 3 sets cubic interpolation in the x direction.\nc\nc intpol(2) = 1 sets linear interpolation in the y direction\nc intpol(2) = 3 sets cubic interpolation in the y direction.\nc\nc intpol(3) = 1 sets linear interpolation in the z direction\nc intpol(3) = 3 sets cubic interpolation in the z direction.\nc\nc values other than 1 or 3 in intpol are not allowed (ier = 5).\nc\nc ... w\nc\nc a real work space of length at least lw which must be provided in the\nc routine calling rgrd3\nc\nc\nc ... lw\nc\nc the integer length of the real work space w. let\nc\nc lwx = mx if intpol(1) = 1\nc lwx = 4*mx if intpol(1) = 3\nc\nc lwy = my+2*mx if intpol(2) = 1\nc lwy = 4*(mx+my) if intpol(2) = 3\nc\nc lwz = 2*mx*my+mz if intpol(3) = 1\nc lwz = 4*(mx*my+mz) if intpol(3) = 3\nc\nc then lw must be greater than or equal to lwx+lwy+lwz\nc\nc ... iw\nc\nc an integer work space of length at least liw which must be provided in the\nc routine calling rgrd3\nc\nc ... liw\nc\nc the integer length of the integer work space iw. liw must be at least mx+my+mz\nc\nc *** output arguments\nc\nc\nc ... q\nc\nc a real mx by my by mz array of values on the (xx,yy,zz) grid which are\nc interpolated from p on the (x,y,z) grid\nc\nc ... ier\nc\nc an integer error flag set as follows:\nc\nc ier = 0 if no errors in input arguments are detected\nc\nc ier = 1 if min0(mx,my,mz) < 1\nc\nc ier = 2 if nx < 2 when intpol(1)=1 or nx < 4 when intpol(1)=3 (or)\nc ny < 2 when intpol(2)=1 or ny < 4 when intpol(2)=3 (or)\nc nz < 2 when intpol(3)=1 or nz < 4 when intpol(3)=3.\nc\nc ier = 3 if xx(1) < x(1) or x(nx) < xx(mx) (or)\nc yy(1) < y(1) or y(ny) < yy(my) (or)\nc zz(1) < z(1) or z(nz) < zz(mz)\nc\nc *** to avoid this flag when end points are intended to be the\nc same but may differ slightly due to roundoff error, they\nc should be set exactly in the calling routine (e.g., if both\nc grids have the same y boundaries then yy(1)=y(1) and yy(my)=y(ny)\nc should be set before calling rgrd3)\nc\nc ier = 4 if one of the grids x,y,z is not strictly monotonically\nc increasing or if one of the grids xx,yy,zz is not\nc montonically increasing. more precisely if:\nc\nc x(i+1) <= x(i) for some i such that 1 <= i < nx (or)\nc\nc y(j+1) <= y(j) for some j such that 1 <= j < ny (or)\nc\nc z(k+1) <= z(k) for some k such that 1 <= k < nz (or)\nc\nc xx(ii+1) < xx(ii) for some ii such that 1 <= ii < mx (or)\nc\nc yy(jj+1) < yy(jj) for some jj such that 1 <= jj < my (or)\nc\nc zz(kk+1) < zz(k) for some kk such that 1 <= kk < mz\nc\nc ier = 5 if lw or liw is too small (insufficient work space)\nc\nc ier = 6 if any of intpol(1),intpol(2),intpol(3) is not equal to 1 or 3\nc\nc ************************************************************************\nc\nc end of rgrd3 documentation, fortran code follows:\nc\nc ************************************************************************\nc\n subroutine rgrd3(nx,ny,nz,x,y,z,p,mx,my,mz,xx,yy,zz,q,intpol,\n + w,lw,iw,liw,ier)\n implicit none\n integer nx,ny,nz,mx,my,mz,lw,liw,ier\n integer lwx,lwy,lwz,jy,kz,mxmy\n real x(nx),y(ny),z(nz),p(nx,ny,nz)\n real xx(mx),yy(my),zz(mz),q(mx,my,mz)\n real w(lw)\n integer intpol(3),iw(liw)\n integer i,ii,j,jj,k,kk\n integer i2,i3,i4,i5\n integer j2,j3,j4,j5,j6,j7,j8,j9\n integer k2,k3,k4,k5,k6,k7,k8,k9\nc\nc check input arguments\nc\n ier = 1\nc\nc check (xx,yy,zz) grid resolution\nc\n if (min0(mx,my,mz) .lt. 1) return\nc\nc check intpol\nc\n ier = 6\n if (intpol(1).ne.1 .and. intpol(1).ne.3) return\n if (intpol(2).ne.1 .and. intpol(2).ne.3) return\n if (intpol(3).ne.1 .and. intpol(3).ne.3) return\nc\nc check (x,y,z) grid resolution\nc\n ier = 2\n if (intpol(1).eq.1 .and. nx.lt.2) return\n if (intpol(1).eq.3 .and. nx.lt.4) return\n if (intpol(2).eq.1 .and. ny.lt.2) return\n if (intpol(2).eq.3 .and. ny.lt.4) return\n if (intpol(3).eq.1 .and. nz.lt.2) return\n if (intpol(3).eq.3 .and. nz.lt.4) return\nc\nc check work space length input and set minimum\nc\n ier = 5\n mxmy = mx*my\n if (intpol(1).eq.1) then\n\tlwx = mx\n else\n\tlwx = 4*mx\n end if\n if (intpol(2).eq.1) then\n\tlwy = (my+2*mx)\n else\n\tlwy = 4*(my+mx)\n end if\n if (intpol(3).eq.1) then\n\tlwz = (2*mxmy+mz)\n else\n\tlwz = 4*(mxmy+mz)\n end if\n if (lw .lt. lwx+lwy+lwz) return\n if (liw .lt. mx+my+mz) return\nc\nc check (xx,yy,zz) grid contained in (x,y,z) grid\nc\n ier = 3\n if (xx(1).lt.x(1) .or. xx(mx).gt.x(nx)) return\n if (yy(1).lt.y(1) .or. yy(my).gt.y(ny)) return\n if (zz(1).lt.z(1) .or. zz(mz).gt.z(nz)) return\nc\nc check montonicity of grids\nc\n ier = 4\n do i=2,nx\n\tif (x(i-1).ge.x(i)) return\n end do\n do j=2,ny\n\tif (y(j-1).ge.y(j)) return\n end do\n do k=2,nz\n\tif (z(k-1).ge.z(k)) return\n end do\n do ii=2,mx\n\tif (xx(ii-1).gt.xx(ii)) return\n end do\n do jj=2,my\n\tif (yy(jj-1).gt.yy(jj)) return\n end do\n do kk=2,mz\n\tif (zz(kk-1).gt.zz(kk)) return\n end do\nc\nc arguments o.k.\nc\n ier = 0\n jy = mx+1\n kz = mx+my+1\n if (intpol(3).eq.1) then\nc\nc linearly interpolate in nz, set work space pointers and scales\nc\n\tk2 = 1\n\tk3 = k2\n\tk4 = k3+mz\n\tk5 = k4\n\tk6 = k5\n\tk7 = k6\n\tk8 = k7+mxmy\n\tk9 = k8+mxmy\n\tcall linmx(nz,z,mz,zz,iw(kz),w(k3))\n\tj2 = k9\nc\nc set indices and scales which depend on y interpolation\nc\n\tif (intpol(2) .eq. 1) then\nc linear in y\n\t j3 = j2\n\t j4 = j3+my\n\t j5 = j4\n\t j6 = j5\n\t j7 = j6\n\t j8 = j7+mx\n\t j9 = j8+mx\n\t call linmx(ny,y,my,yy,iw(jy),w(j3))\n\t i2 = j9\n\telse\nc cubic in y\n\t j3 = j2+my\n\t j4 = j3+my\n\t j5 = j4+my\n\t j6 = j5+my\n\t j7 = j6+mx\n\t j8 = j7+mx\n\t j9 = j8+mx\n\t call cubnmx(ny,y,my,yy,iw(jy),w(j2),w(j3),w(j4),w(j5))\n\t i2 = j9+mx\n\tend if\nc\nc set indices and scales which depend on x interpolation\nc\n\tif (intpol(1) .eq. 1) then\nc linear in x\n\t i3 = i2\n\t i4 = i3\n\t i5 = i4\n\t call linmx(nx,x,mx,xx,iw,w(i3))\n\telse\nc cubic in x\n\t i3 = i2+mx\n\t i4 = i3+mx\n\t i5 = i4+mx\n\t call cubnmx(nx,x,mx,xx,iw,w(i2),w(i3),w(i4),w(i5))\n\tend if\n\tcall lint3(nx,ny,nz,p,mx,my,mxmy,mz,q,intpol,iw(kz),\n + w(k3),w(k7),w(k8),iw(jy),w(j2),w(j3),w(j4),w(j5),w(j6),\n + w(j7),w(j8),w(j9),iw,w(i2),w(i3),w(i4),w(i5))\n\treturn\n else\nc\nc cubically interpolate in z\nc\n\tk2 = 1\n\tk3 = k2+mz\n\tk4 = k3+mz\n\tk5 = k4+mz\n\tk6 = k5+mz\n\tk7 = k6+mxmy\n\tk8 = k7+mxmy\n\tk9 = k8+mxmy\n\tcall cubnmx(nz,z,mz,zz,iw(kz),w(k2),w(k3),w(k4),w(k5))\n\tj2 = k9+mxmy\nc\nc set indices which depend on y interpolation\nc\n\tif (intpol(2) .eq. 1) then\n\t j3 = j2\n\t j4 = j3+my\n\t j5 = j4\n\t j6 = j5\n\t j7 = j6\n\t j8 = j7+mx\n\t j9 = j8+mx\n\t call linmx(ny,y,my,yy,iw(jy),w(j3))\n\t i2 = j9\n\telse\n\t j3 = j2+my\n\t j4 = j3+my\n\t j5 = j4+my\n\t j6 = j5+my\n\t j7 = j6+mx\n\t j8 = j7+mx\n\t j9 = j8+mx\n\t call cubnmx(ny,y,my,yy,iw(jy),w(j2),w(j3),w(j4),w(j5))\n\t i2 = j9+mx\n\tend if\nc\nc set work space portion and indices which depend on x interpolation\nc\n\tif (intpol(1) .eq. 1) then\n\t i3 = i2\n\t i4 = i3\n\t i5 = i4\n\tcall linmx(nx,x,mx,xx,iw,w(i3))\n\telse\n\t i3 = i2+mx\n\t i4 = i3+mx\n\t i5 = i4+mx\n\tcall cubnmx(nx,x,mx,xx,iw,w(i2),w(i3),w(i4),w(i5))\n\tend if\n\tcall cubt3(nx,ny,nz,p,mx,my,mxmy,mz,q,intpol,\n + iw(kz),w(k2),w(k3),w(k4),w(k5),w(k6),w(k7),w(k8),w(k9),\n + iw(jy),w(j2),w(j3),w(j4),w(j5),w(j6),w(j7),w(j8),w(j9),\n + iw,w(i2),w(i3),w(i4),w(i5))\n\treturn\n\n end if\n\n end\n\n subroutine lint3(nx,ny,nz,p,mx,my,mxmy,mz,q,intpol,kz,\n +dz,pk,pkp,jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,ix,dxm,dx,dxp,dxpp)\nc\nc linearly interpolate in z direction\nc\n implicit none\n integer nx,ny,nz,mx,my,mz,mxmy\n real p(nx,ny,nz),q(mxmy,mz)\n real dz(mz),pk(mxmy),pkp(mxmy)\n real dym(my),dy(my),dyp(my),dypp(my)\n real pjm(mx),pj(mx),pjp(mx),pjpp(mx)\n real dxm(mx),dx(mx),dxp(mx),dxpp(mx)\n integer intpol(3),kz(mz),jy(my),ix(mx)\n integer k,kk,iijj,ksave\n if (intpol(2) .eq. 1) then\nc\nc linear in y\nc\n\tksave = -1\n\tdo kk=1,mz\n\t k = kz(kk)\n\t if (k.eq.ksave) then\nc\nc k pointer has not moved since last pass (no updates or interpolation)\nc\n\t else if (k.eq.ksave+1) then\nc\nc update k and interpolate k+1\nc\n\t do iijj=1,mxmy\n\t pk(iijj) = pkp(iijj)\n\t end do\n\t call lint2(nx,ny,p(1,1,k+1),mx,my,pkp,intpol,jy,dy,\n + pj,pjp,ix,dxm,dx,dxp,dxpp)\n\t else\nc\nc interpolate k,k+1 in pk,pkp on xx,yy mesh\nc\n\t call lint2(nx,ny,p(1,1,k),mx,my,pk,intpol,jy,dy,\n + pj,pjp,ix,dxm,dx,dxp,dxpp)\n\t call lint2(nx,ny,p(1,1,k+1),mx,my,pkp,intpol,jy,dy,\n + pj,pjp,ix,dxm,dx,dxp,dxpp)\n\t end if\nc\nc save k pointer for next pass\nc\n\t ksave = k\nc\nc linearly interpolate q(ii,jj,k) from pk,pkp in z direction\nc\n\t do iijj=1,mxmy\n\t q(iijj,kk) = pk(iijj)+dz(kk)*(pkp(iijj)-pk(iijj))\n\t end do\n\tend do\n\treturn\n\n else\nc\nc cubic in y\nc\n\tksave = -1\n\tdo kk=1,mz\n\t k = kz(kk)\n\t if (k.eq.ksave) then\nc\nc k pointer has not moved since last pass (no updates or interpolation)\nc\n\t else if (k.eq.ksave+1) then\nc\nc update k and interpolate k+1\nc\n\t do iijj=1,mxmy\n\t pk(iijj) = pkp(iijj)\n\t end do\n\t call cubt2(nx,ny,p(1,1,k+1),mx,my,pkp,intpol,\n + jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,ix,dxm,dx,dxp,dxpp)\n\t else\nc\nc interpolate k,k+1 in pk,pkp on xx,yy mesh\nc\n\t call cubt2(nx,ny,p(1,1,k),mx,my,pk,intpol,\n + jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,ix,dxm,dx,dxp,dxpp)\n\t call cubt2(nx,ny,p(1,1,k+1),mx,my,pkp,intpol,\n + jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,ix,dxm,dx,dxp,dxpp)\n\t end if\nc\nc save k pointer for next pass\nc\n\t ksave = k\nc\nc linearly interpolate q(ii,jj,k) from pk,pkp in z direction\nc\n\t do iijj=1,mxmy\n\t q(iijj,kk) = pk(iijj)+dz(kk)*(pkp(iijj)-pk(iijj))\n\t end do\n\tend do\n\treturn\n\n end if\n end\n\n subroutine cubt3(nx,ny,nz,p,mx,my,mxmy,mz,q,intpol,\n +kz,dzm,dz,dzp,dzpp,pkm,pk,pkp,pkpp,jy,dym,dy,dyp,dypp,pjm,pj,\n +pjp,pjpp,ix,dxm,dx,dxp,dxpp)\nc\nc cubically interpolate in z\nc\n implicit none\n integer nx,ny,nz,mx,my,mxmy,mz,k,kk,ksave,iijj\n real p(nx,ny,nz),q(mxmy,mz)\n real pkm(mxmy),pk(mxmy),pkp(mxmy),pkpp(mxmy)\n real pjm(mx),pj(mx),pjp(mx),pjpp(mx)\n real dzm(mz),dz(mz),dzp(mz),dzpp(mz)\n real dym(my),dy(my),dyp(my),dypp(my)\n real dxm(mx),dx(mx),dxp(mx),dxpp(mx)\n integer intpol(3),kz(mz),jy(my),ix(mx)\n if (intpol(2) .eq. 1) then\nc\nc linear in y\nc\n\tksave = -3\n\tdo kk=1,mz\n\t k = kz(kk)\n\t if (k.eq.ksave) then\nc\nc k pointer has not moved since last pass (no updates or interpolation)\nc\n\t else if (k.eq.ksave+1) then\nc\nc update k-1,k,k+1 and interpolate k+2\nc\n\t do iijj=1,mxmy\n\t pkm(iijj) = pk(iijj)\n\t pk(iijj) = pkp(iijj)\n\t pkp(iijj) = pkpp(iijj)\n\t end do\n\t call lint2(nx,ny,p(1,1,k+2),mx,my,pkpp,\n + intpol,jy,dy,pj,pjp,ix,dxm,dx,dxp,dxpp)\n\t else if (k.eq.ksave+2) then\nc\nc update k-1,k and interpolate k+1,k+2\nc\n\t do iijj=1,mxmy\n\t pkm(iijj) = pkp(iijj)\n\t pk(iijj) = pkpp(iijj)\n\t end do\n\t call lint2(nx,ny,p(1,1,k+1),mx,my,pkp,\n + intpol,jy,dy,pj,pjp,ix,dxm,dx,dxp,dxpp)\n\t call lint2(nx,ny,p(1,1,k+2),mx,my,pkpp,\n + intpol,jy,dy,pj,pjp,ix,dxm,dx,dxp,dxpp)\n\t else if (k.eq.ksave+3) then\nc\nc update k-1 and interpolate k,k+1,k+2\nc\n\t do iijj=1,mxmy\n\t pkm(iijj) = pkpp(iijj)\n\t end do\n\t call lint2(nx,ny,p(1,1,k),mx,my,pk,\n + intpol,jy,dy,pj,pjp,ix,dxm,dx,dxp,dxpp)\n\t call lint2(nx,ny,p(1,1,k+1),mx,my,pkp,\n + intpol,jy,dy,pj,pjp,ix,dxm,dx,dxp,dxpp)\n\t call lint2(nx,ny,p(1,1,k+2),mx,my,pkpp,\n + intpol,jy,dy,pj,pjp,ix,dxm,dx,dxp,dxpp)\n\t else\nc\nc interpolate all four k-1,k,k+1,k+2\nc\n\t call lint2(nx,ny,p(1,1,k-1),mx,my,pkm,\n + intpol,jy,dy,pj,pjp,ix,dxm,dx,dxp,dxpp)\n\t call lint2(nx,ny,p(1,1,k),mx,my,pk,\n + intpol,jy,dy,pj,pjp,ix,dxm,dx,dxp,dxpp)\n\t call lint2(nx,ny,p(1,1,k+1),mx,my,pkp,\n + intpol,jy,dy,pj,pjp,ix,dxm,dx,dxp,dxpp)\n\t call lint2(nx,ny,p(1,1,k+2),mx,my,pkpp,\n + intpol,jy,dy,pj,pjp,ix,dxm,dx,dxp,dxpp)\n\t end if\nc\nc save k pointer for next pass\nc\n\t ksave = k\nc\nc cubically interpolate q(ii,jj,kk) from pkm,pk,pkp,pkpp in z direction\nc\n\t do iijj=1,mxmy\n\t q(iijj,kk) = dzm(kk)*pkm(iijj) + dz(kk)*pk(iijj) +\n + dzp(kk)*pkp(iijj) + dzpp(kk)*pkpp(iijj)\n\t end do\n\tend do\n\treturn\n\n else\nc\nc cubic in y\nc\n\tksave = -3\n\tdo kk=1,mz\n\t k = kz(kk)\n\t if (k.eq.ksave) then\nc\nc k pointer has not moved since last pass (no updates or interpolation)\nc\n\t else if (k.eq.ksave+1) then\nc\nc update k-1,k,k+1 and interpolate k+2\nc\n\t do iijj=1,mxmy\n\t pkm(iijj) = pk(iijj)\n\t pk(iijj) = pkp(iijj)\n\t pkp(iijj) = pkpp(iijj)\n\t end do\n\t call cubt2(nx,ny,p(1,1,k+2),mx,my,pkpp,intpol,jy,dym,dy,\n + dyp,dypp,pjm,pj,pjp,pjpp,ix,dxm,dx,dxp,dxpp)\n\t else if (k.eq.ksave+2) then\nc\nc update k-1,k and interpolate k+1,k+2\nc\n\t do iijj=1,mxmy\n\t pkm(iijj) = pkp(iijj)\n\t pk(iijj) = pkpp(iijj)\n\t end do\n\t call cubt2(nx,ny,p(1,1,k+1),mx,my,pkp,intpol,jy,dym,dy,\n + dyp,dypp,pjm,pj,pjp,pjpp,ix,dxm,dx,dxp,dxpp)\n\t call cubt2(nx,ny,p(1,1,k+2),mx,my,pkpp,intpol,jy,dym,dy,\n + dyp,dypp,pjm,pj,pjp,pjpp,ix,dxm,dx,dxp,dxpp)\n\t else if (k.eq.ksave+3) then\nc\nc update k-1 and interpolate k,k+1,k+2\nc\n\t do iijj=1,mxmy\n\t pkm(iijj) = pkpp(iijj)\n\t end do\n\t call cubt2(nx,ny,p(1,1,k),mx,my,pk,intpol,\n + jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,ix,dxm,dx,dxp,dxpp)\n\t call cubt2(nx,ny,p(1,1,k+1),mx,my,pkp,intpol,\n + jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,ix,dxm,dx,dxp,dxpp)\n\t call cubt2(nx,ny,p(1,1,k+2),mx,my,pkpp,intpol,\n + jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,ix,dxm,dx,dxp,dxpp)\n\t else\nc\nc interpolate all four k-1,k,k+1,k+2\nc\n\t call cubt2(nx,ny,p(1,1,k-1),mx,my,pkm,intpol,\n + jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,ix,dxm,dx,dxp,dxpp)\n\t call cubt2(nx,ny,p(1,1,k),mx,my,pk,intpol,\n + jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,ix,dxm,dx,dxp,dxpp)\n\t call cubt2(nx,ny,p(1,1,k+1),mx,my,pkp,intpol,\n + jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,ix,dxm,dx,dxp,dxpp)\n\t call cubt2(nx,ny,p(1,1,k+2),mx,my,pkpp,intpol,\n + jy,dym,dy,dyp,dypp,pjm,pj,pjp,pjpp,ix,dxm,dx,dxp,dxpp)\n\n\t end if\nc\nc save k pointer for next pass\nc\n\t ksave = k\nc\nc cubically interpolate q(ii,jj,kk) from pkm,pk,pkp,pkpp in z direction\nc\n\t do iijj=1,mxmy\n\t q(iijj,kk) = dzm(kk)*pkm(iijj) + dz(kk)*pk(iijj) +\n + dzp(kk)*pkp(iijj) + dzpp(kk)*pkpp(iijj)\n\t end do\n\tend do\n\treturn\n end if\n\n end\n", "meta": {"hexsha": "fff43467e9e6fd82a981ad9fcdadf7fbfddfe1ff", "size": 19162, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "contrib/regridpack/Src/rgrd3.f", "max_stars_repo_name": "xylar/cdat", "max_stars_repo_head_hexsha": "8a5080cb18febfde365efc96147e25f51494a2bf", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 62, "max_stars_repo_stars_event_min_datetime": "2018-03-30T15:46:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-08T23:30:24.000Z", "max_issues_repo_path": "contrib/regridpack/Src/rgrd3.f", "max_issues_repo_name": "xylar/cdat", "max_issues_repo_head_hexsha": "8a5080cb18febfde365efc96147e25f51494a2bf", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 114, "max_issues_repo_issues_event_min_datetime": "2018-03-21T01:12:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-05T12:29:54.000Z", "max_forks_repo_path": "contrib/regridpack/Src/rgrd3.f", "max_forks_repo_name": "CDAT/uvcdat", "max_forks_repo_head_hexsha": "5133560c0c049b5c93ee321ba0af494253b44f91", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2018-06-06T02:42:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-26T03:27:00.000Z", "avg_line_length": 26.6880222841, "max_line_length": 85, "alphanum_fraction": 0.5817764325, "num_tokens": 7832, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392848011834, "lm_q2_score": 0.7490872187162397, "lm_q1q2_score": 0.6622225290876123}} {"text": "subroutine EigValVecSym(ain, n, eig, evec, ul, K)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis subroutine will return the eigenvalues and eigenvectors\n!\tof the symmetric square matrix Ain. The output eigenvectors\n!\tare ordered from greatest to least, and the norm of the eigenvectors\n!\tis unity. If the optional parameter K is specified, only the K largest\n!\teigenvalues and corresponding vectors will be output.\n!\n!\tCalling Parameters\n!\t\tIN\n!\t\t\tAin\tInput symmetric matrix. By default, only the\n!\t\t\t\tupper portion is used.\n!\t\t\tn\tOrder of the matrix Ain.\n!\t\tOUT\n!\t\t\teig\tVector of length n of the eigenvalues of Ain.\n!\t\t\tevec\tMatrix of dimension n of the \n!\t\t\t\teigenvectors of Ain.\n!\t\tOPTIONAL\n!\t\t\tul\tUse the upper 'U' or lower 'L' portion of the \n!\t\t\t\tinput symmetric matrix.\n!\t\t\tK\tThe K largest eigenvalues and corresponding eigenvectors\n!\t\t\t\tto calculate and output.\n!\n!\tNotes:\n!\t\t\n!\t1.\tThe eigenvalues and eigenvectors are determined by reducing the matrix to\n!\t\t\tA = Z L Z = Q (S L S') Q' \n!\t\tby the two operations:\n!\n!\t\t(1) The real symmetric square matrix is reduced to tridiagonal form\n!\t\t\tA = Q T Q'\n!\t\twhere Q is orthogonal, and T is symmetric tridiagonal.\n!\t\t(2) The tridiagonal matrix is reduced to \n!\t\t\tT = S L S'\n!\n!\t\tThe eigenvalues of A correspond to the L (which is a diagonal), and the\n!\t\teigenvectors correspond to Z = Q S.\n!\t2. \tThe sign convention for the eigenvalues might want to be changed.\n!\t\tFor instance, IMSL chooses the sign such that the value with \n!\t\tmax(abs(evec)) is positive.\n!\t\t\n!\tDependencies: LAPACK, BLAS\n!\n!\tWritten by Mark Wieczorek June 2004.\n!\tModified August 15:\tOption to only calcuate K largest eigenvectors and corresponding eigenvalues. Also,\n!\t\t\t\twith LAPACK3.1, the DSTEGR routine no longer uses ABSTOL, so this parameter does\n!\t\t\t\tnot need to be specified.\n!\n!\tCopyright (c) 2005-2009, Mark A. Wieczorek\n!\tAll rights reserved.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\timplicit none\n\treal*8, intent(in) ::\t\tain(:,:)\n\tinteger, intent(in) ::\t\tn\n\treal*8, intent(out) ::\t\teig(:), evec(:,:)\n\tcharacter, intent(in), optional ::\tul\n\tinteger, intent(in), optional ::\tK\n\tinteger, parameter ::\t\t\tnb = 80, nbl = 10\n\tcharacter ::\t\t\tuplo\n\treal*8 ::\t\t\td(n), e(n), tau(n-1), work(nb*n), vl, vu, &\n\t\t\t\t\tabstol, w(n)\n\treal*8, allocatable :: \t\ta(:,:), z(:,:)\n\tinteger ::\t\t\tlwork, info, il, iu, m, isuppz(2*n), liwork, iwork(nbl*n), &\n\t\t\t\t\ti, astat(2)\n\texternal\t \t\tdsytrd_, dstegr_, dormtr_\n\t\n\t\n\tif (size(ain(:,1)) < n .or. size(ain(1,:)) < n) then\n\t\tprint*, \"Error --- EigValVecSym\"\n\t\tprint*, \"AIN must be dimensioned as (N, N) where N is \", n\n\t\tprint*, \"Input array is dimensioned as \", size(ain(:,1)), size(ain(1,:))\n\t\tstop\n\tendif\n\t\n\tif (present(K)) then\n\t\tif(size(eig) < K) then\n\t\t\tprint*, \"Error --- EigValVecSym\"\n\t\t\tprint*, \"EIG must be dimensioned as (K) where K is \", K\n\t\t\tprint*, \"Input array is dimensioned as \", size(eig)\n\t\t\tstop\n\t\telseif(size(evec(:,1)) < n .or. size(evec(1,:)) < K) then\n\t\t\tprint*, \"Error --- EigValVecSym\"\n\t\t\tprint*, \"EVEC must be dimensioned as (N, K).\"\n\t\t\tprint*, \"N = \", n\n\t\t\tprint*, \"K = \", k\n\t\t\tprint*, \"Input array is dimensioned as \", size(evec(:,1)), size(evec(1,:))\n\t\t\tstop\n\t\tendif\n\telse\n\t\tif(size(eig) < n) then\n\t\t\tprint*, \"Error --- EigValVecSym\"\n\t\t\tprint*, \"EIG must be dimensioned as (N) where N is \", n\n\t\t\tprint*, \"Input array is dimensioned as \", size(eig)\n\t\t\tstop\n\t\telseif(size(evec(:,1)) < n .or. size(evec(1,:)) < n) then\n\t\t\tprint*, \"Error --- EigValVecSym\"\n\t\t\tprint*, \"EVEC must be dimensioned as (N, N) where N is \", n\n\t\t\tprint*, \"Input array is dimensioned as \", size(evec(:,1)), size(evec(1,:))\n\t\t\tstop\n\t\tendif\n\tendif\n\n\tallocate(a(n,n), stat = astat(1))\n\tallocate(z(n,n), stat = astat(2))\n\t\n\tif (astat(1) /= 0 .or. astat(2) /= 0) then\n\t\tprint*, \"Error --- EigValVecSym2\"\n\t\tprint*, \"Problem allocating arrays A and Z\", astat(1), astat(2)\n\t\tstop\n\tendif\n\n\t\n\tlwork = nb*n\n\tliwork = nbl*n\n\t\n\teig = 0.0d0\n\tevec = 0.0d0\n\ta(1:n,1:n) = ain(1:n,1:n)\n\t\n\tif (present(ul)) then\n\t\tuplo = ul\n\telse\n\t\tuplo = \"U\"\n\tendif\n\t\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t!\n\t!\tFactor A to Q T Q' where T is a tridiagonal matrix.\n\t!\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\tcall dsytrd_(uplo, n, a, n, d, e(1:n-1), tau, work, lwork, info)\n\n\tif (info /= 0) then\n\t\tprint*, \"Error --- EigValVecSym\"\n\t\tprint*, \"Problem tri-diagonalizing input matrix\"\n\t\tprint*, \"DSYTRD info = \", info\n\t\tstop\n\telse\n\t\tif ( work(1) > dble(lwork) ) then\n\t\t\tprint*, \"Warning --- EigValVecSym\"\n\t\t\tprint*, \"Consider changing value of nb to \", work(1)/n, \" and recompile.\"\n\t\tendif\n\tendif\n\t\t\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t!\n\t!\tFactor T to S L S' where L is a diagonal matrix.\n\t!\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t\n\tabstol = 0.0d0\n\t\n\tif (present(K)) then\n\t\tcall dstegr_('v','I', n, d, e, vl, vu, n-K+1, n, abstol, m, w, &\n\t\t\tz, n, isuppz, work, lwork, iwork, liwork, info)\n\telse\n\t\tcall dstegr_('v','I', n, d, e, vl, vu, il, iu, abstol, m, w, &\n\t\t\tz, n, isuppz, work, lwork, iwork, liwork, info)\n\tendif\n\t\n \tif (info /= 0) then\n\t\tprint*, \"Error --- EigValVecSym\"\n\t\tprint*, \"Problem determining eigenvalues and eigenvectors of tridiagonal matrix.\"\n\t\tif (info==1) print*, \"Internal error in DLARRE\"\n\t\tif (info==2) print*, \"Internal error in DLARRV\"\n\t\tprint*, \"DSTEGR info = \", info\n\t\tstop\n\telse\n\t\tif (work(1) > dble(lwork) ) then\n\t\t\tprint*, \"Warning --- EigValVecSym\"\n\t\t\tprint*, \"Consider changing value of nb to \", work(1)/n, \" and recompile SHTOOLS archive.\"\n\t\tendif\n\t\t\n\t\tif (iwork(1) > liwork ) then\n\t\t\tprint*, \"Warning --- EigValVecSym\"\n\t\t\tprint*, \"Consider changing value of nb to \", iwork(1)/n, \" and recompile SHTOOLS archive.\"\n\t\tendif\n\tendif\n\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t!\n\t!\tDetermine eigenvalues Z = Q S (note that Q is stored in a\n\t!\tbizarre manner, see LAPACK notes), and reorder eigenvalues and\n\t!\teigenvectors from greatest to least.\n\t!\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t\n\tcall dormtr_('L', uplo, 'N', n, n, a, n, tau, z, n, work, lwork, info)\n\n\tif (info /= 0) then\n\t\tprint*, \"Error --- EigValVecSym\"\n\t\tprint*, \"Problem multiplying matrices.\"\n\t\tprint*, \"DORMTR info = \", info\n\t\tstop\n\telse\n\t\tif ( work(1) > dble(lwork) ) then\n\t\t\tprint*, \"Warning --- EigValVecSym\"\n\t\t\tprint*, \"Consider changing value of nb to \", work(1)/n, \" and recompile.\"\n\t\tendif\n\tendif\n\n\tif (present(k)) then\n\t\tdo i=n-K+1, n\n\t\t\teig(i-n+k) = w(n+1-i)\n\t\t\tevec(1:n,i-n+k) = z(1:n,n+1-i)\n\t\tenddo\n\telse\n\t\tdo i=1, n\n\t\t\teig(i) = w(n+1-i)\n\t\t\tevec(1:n,i) = z(1:n,n+1-i)\n\t\tenddo\n\tendif\n\t\n\tdeallocate(a)\n\tdeallocate(z)\n\t\nend subroutine EigValVecSym\n", "meta": {"hexsha": "8ef5a70544408446bc089d3396e3ba5e0c1017c7", "size": 6746, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "spherical_splines/SHTOOLS/src/EigValVecSym2.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/EigValVecSym2.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/EigValVecSym2.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.5248868778, "max_line_length": 105, "alphanum_fraction": 0.5819745034, "num_tokens": 2214, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972818382005, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.6622203953730286}} {"text": "\nSpectrum-analysis-program: Integrate the supplied spectrum\n\nKeys:\n\n infile nokeyok input spectrum file [-]\n xc x-column [1]\n yc y-column [2]\n xmin } range over which to integrate\n xmax } [full range of x]\n\n\nA simple integration of the data within the specified range is performed.\nThe y data are integrated with respect to x using a trapezoidal rule and\nthe result of the integration is printed on the standard output.\n\nExample:\n\nIntegrate column-3 with respect to column 1 in the range 0,100\n\n sp_integrate my_data.dat xmin 0.0 xmax 100.0 xc 1 yc 3\n\n\n", "meta": {"hexsha": "fc2ffdde2bfd8832d4df6132330ca9bb14b380cc", "size": 708, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "help/Spectrum_Analysis/sp_integrate.f", "max_stars_repo_name": "CavendishAstrophysics/anmap", "max_stars_repo_head_hexsha": "efb611d7f80a3d14dc55e46cd01e8a622f6fd294", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-09-01T12:40:45.000Z", "max_stars_repo_stars_event_max_datetime": "2015-09-01T12:40:45.000Z", "max_issues_repo_path": "help/Spectrum_Analysis/sp_integrate.f", "max_issues_repo_name": "CavendishAstrophysics/anmap", "max_issues_repo_head_hexsha": "efb611d7f80a3d14dc55e46cd01e8a622f6fd294", "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": "help/Spectrum_Analysis/sp_integrate.f", "max_forks_repo_name": "CavendishAstrophysics/anmap", "max_forks_repo_head_hexsha": "efb611d7f80a3d14dc55e46cd01e8a622f6fd294", "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.5, "max_line_length": 73, "alphanum_fraction": 0.5960451977, "num_tokens": 150, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972818382005, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6622203906493004}} {"text": "! This is free and unencumbered software released into the public domain.\n!\n! Anyone is free to copy, modify, publish, use, compile, sell, or\n! distribute this software, either in source code form or as a compiled\n! binary, for any purpose, commercial or non-commercial, and by any\n! means.\n!\n! In jurisdictions that recognize copyright laws, the author or authors\n! of this software dedicate any and all copyright interest in the\n! software to the public domain. We make this dedication for the benefit\n! of the public at large and to the detriment of our heirs and\n! successors. We intend this dedication to be an overt act of\n! relinquishment in perpetuity of all present and future rights to this\n! software under copyright law.\n!\n! THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n! EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n! MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n! IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR\n! OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,\n! ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\n! OTHER DEALINGS IN THE SOFTWARE.\n!\n! For more information, please refer to \n\n!> Analytical implementation of the 3x3 eigenproblem and its solution.\nmodule diag3x3\n implicit none\n private\n\n public :: eigval3x3, eigvec3x3\n\n\n !> Floating point precision\n integer, parameter :: wp = selected_real_kind(15)\n\n !> 2\u03c0/3\n real(wp), parameter :: twothirdpi = 8.0_wp * atan(1.0_wp) / 3.0_wp\n\n !> Numerical precision\n real(wp), parameter :: eps = epsilon(1.0_wp)\n\n\ncontains\n\n\n!> Calculates eigenvalues based on the trigonometric solution of A = pB + qI\npure subroutine eigval3x3(a, w)\n\n !> The symmetric input matrix\n real(wp), intent(in) :: a(3, 3)\n\n !> Contains eigenvalues on exit\n real(wp), intent(out) :: w(3)\n\n real(wp) :: q, p, r\n\n r = a(1, 2) * a(1, 2) + a(1, 3) * a(1, 3) + a(2, 3) * a(2, 3)\n q = (a(1, 1) + a(2, 2) + a(3, 3)) / 3.0_wp\n w(1) = a(1, 1) - q\n w(2) = a(2, 2) - q\n w(3) = a(3, 3) - q\n p = sqrt((w(1) * w(1) + w(2) * w(2) + w(3) * w(3) + 2*r) / 6.0_wp)\n r = (w(1) * (w(2) * w(3) - a(2, 3) * a(2, 3)) &\n & - a(1, 2) * (a(1, 2) * w(3) - a(2, 3) * a(1, 3)) &\n & + a(1, 3) * (a(1, 2) * a(2, 3) - w(2) * a(1, 3))) / (p*p*p) * 0.5_wp\n\n if (r <= -1.0_wp) then\n r = 0.5_wp * twothirdpi\n else if (r >= 1.0_wp) then\n r = 0.0_wp\n else\n r = acos(r) / 3.0_wp\n end if\n\n w(3) = q + 2 * p * cos(r)\n w(1) = q + 2 * p * cos(r + twothirdpi)\n w(2) = 3 * q - w(1) - w(3)\n\nend subroutine eigval3x3\n\n\n!> Calculates eigenvector using an analytical method based on vector cross\n! products.\npure subroutine eigvec3x3(a, w, q)\n\n !> The symmetric input matrix, destroyed while solving\n real(wp), intent(inout) :: a(3,3)\n\n !> Contains eigenvalues on exit\n real(wp), intent(out) :: w(3)\n\n !> Contains eigenvectors on exit\n real(wp), intent(out) :: q(3,3)\n\n !> Local variables\n real(wp) :: norm, n1, n2, n3, precon\n integer :: i\n\n w(1) = max(abs(a(1, 1)), abs(a(1, 2)))\n w(2) = max(abs(a(1, 3)), abs(a(2, 2)))\n w(3) = max(abs(a(2, 3)), abs(a(3, 3)))\n precon = max(w(1), max(w(2), w(3)))\n\n ! null matrix\n if (precon < eps) then\n w(1) = 0.0_wp\n w(2) = 0.0_wp\n w(3) = 0.0_wp\n q(1, 1) = 1.0_wp\n q(2, 2) = 1.0_wp\n q(3, 3) = 1.0_wp\n q(1, 2) = 0.0_wp\n q(1, 3) = 0.0_wp\n q(2, 3) = 0.0_wp\n q(2, 1) = 0.0_wp\n q(3, 1) = 0.0_wp\n q(3, 2) = 0.0_wp\n return\n end if\n\n norm = 1.0_wp / precon\n\n a(1, 1) = a(1, 1) * norm\n a(1, 2) = a(1, 2) * norm\n a(2, 2) = a(2, 2) * norm\n a(1, 3) = a(1, 3) * norm\n a(2, 3) = a(2, 3) * norm\n a(3, 3) = a(3, 3) * norm\n\n ! Calculate eigenvalues\n call eigval3x3(a, w)\n\n ! Compute first eigenvector\n a(1, 1) = a(1, 1) - w(1)\n a(2, 2) = a(2, 2) - w(1)\n a(3, 3) = a(3, 3) - w(1)\n\n q(1, 1) = a(1, 2) * a(2, 3) - a(1, 3) * a(2, 2)\n q(2, 1) = a(1, 3) * a(1, 2) - a(1, 1) * a(2, 3)\n q(3, 1) = a(1, 1) * a(2, 2) - a(1, 2) * a(1, 2)\n q(1, 2) = a(1, 2) * a(3, 3) - a(1, 3) * a(2, 3)\n q(2, 2) = a(1, 3) * a(1, 3) - a(1, 1) * a(3, 3)\n q(3, 2) = a(1, 1) * a(2, 3) - a(1, 2) * a(1, 3)\n q(1, 3) = a(2, 2) * a(3, 3) - a(2, 3) * a(2, 3)\n q(2, 3) = a(2, 3) * a(1, 3) - a(1, 2) * a(3, 3)\n q(3, 3) = a(1, 2) * a(2, 3) - a(2, 2) * a(1, 3)\n n1 = q(1, 1) * q(1, 1) + q(2, 1) * q(2, 1) + q(3, 1) * q(3, 1)\n n2 = q(1, 2) * q(1, 2) + q(2, 2) * q(2, 2) + q(3, 2) * q(3, 2)\n n3 = q(1, 3) * q(1, 3) + q(2, 3) * q(2, 3) + q(3, 3) * q(3, 3)\n\n norm = n1\n i = 1\n if (n2 > norm) then\n i = 2\n norm = n1\n end if\n if (n3 > norm) then\n i = 3\n end if\n\n if (i == 1) then\n norm = sqrt(1.0_wp / n1)\n q(1, 1) = q(1, 1) * norm\n q(2, 1) = q(2, 1) * norm\n q(3, 1) = q(3, 1) * norm\n else if (i == 2) then\n norm = sqrt(1.0_wp / n2)\n q(1, 1) = q(1, 2) * norm\n q(2, 1) = q(2, 2) * norm\n q(3, 1) = q(3, 2) * norm\n else\n norm = sqrt(1.0_wp / n3)\n q(1, 1) = q(1, 3) * norm\n q(2, 1) = q(2, 3) * norm\n q(3, 1) = q(3, 3) * norm\n end if\n\n ! Robustly compute a right-hand orthonormal set (ev1, u, v)\n if (abs(q(1, 1)) > abs(q(2, 1))) then\n norm = sqrt(1.0_wp / (q(1, 1) * q(1, 1) + q(3, 1) * q(3, 1)))\n q(1, 2) = -q(3, 1) * norm\n q(2, 2) = 0.0_wp\n q(3, 2) = +q(1, 1) * norm\n else\n norm = sqrt(1.0_wp / (q(2, 1) * q(2, 1) + q(3, 1) * q(3, 1)))\n q(1, 2) = 0.0_wp\n q(2, 2) = +q(3, 1) * norm\n q(3, 2) = -q(2, 1) * norm\n end if\n q(1, 3) = q(2, 1) * q(3, 2) - q(3, 1) * q(2, 2)\n q(2, 3) = q(3, 1) * q(1, 2) - q(1, 1) * q(3, 2)\n q(3, 3) = q(1, 1) * q(2, 2) - q(2, 1) * q(1, 2)\n\n ! Reset A\n a(1, 1) = a(1, 1) + w(1)\n a(2, 2) = a(2, 2) + w(1)\n a(3, 3) = a(3, 3) + w(1)\n\n ! A*U\n n1 = a(1, 1) * q(1, 2) + a(1, 2) * q(2, 2) + a(1, 3) * q(3, 2)\n n2 = a(1, 2) * q(1, 2) + a(2, 2) * q(2, 2) + a(2, 3) * q(3, 2)\n n3 = a(1, 3) * q(1, 2) + a(2, 3) * q(2, 2) + a(3, 3) * q(3, 2)\n\n ! A*V, note out of order computation\n a(3, 3) = a(1, 3) * q(1, 3) + a(2, 3) * q(2, 3) + a(3, 3) * q(3, 3)\n a(1, 3) = a(1, 1) * q(1, 3) + a(1, 2) * q(2, 3) + a(1, 3) * q(3, 3)\n a(2, 3) = a(1, 2) * q(1, 3) + a(2, 2) * q(2, 3) + a(2, 3) * q(3, 3)\n\n ! UT*(A*U) - l2*E\n n1 = q(1, 2) * n1 + q(2, 2) * n2 + q(3, 2) * n3 - w(2)\n ! UT*(A*V)\n n2 = q(1, 2) * a(1, 3) + q(2, 2) * a(2, 3) + q(3, 2) * a(3, 3)\n ! VT*(A*V) - l2*E\n n3 = q(1, 3) * a(1, 3) + q(2, 3) * a(2, 3) + q(3, 3) * a(3, 3) - w(2)\n\n if (abs(n1) >= abs(n3)) then\n norm = max(abs(n1), abs(n2))\n if (norm > eps) then\n if (abs(n1) >= abs(n2)) then\n n2 = n2 / n1\n n1 = sqrt(1.0_wp / (1.0_wp + n2 * n2))\n n2 = n2 * n1\n else\n n1 = n1 / n2\n n2 = sqrt(1.0_wp / (1.0_wp + n1 * n1))\n n1 = n1 * n2\n end if\n q(1, 2) = n2 * q(1, 2) - n1 * q(1, 3)\n q(2, 2) = n2 * q(2, 2) - n1 * q(2, 3)\n q(3, 2) = n2 * q(3, 2) - n1 * q(3, 3)\n end if\n else\n norm = max(abs(n3), abs(n2))\n if (norm > eps) then\n if (abs(n3) >= abs(n2)) then\n n2 = n2 / n3\n n3 = sqrt(1.0_wp / (1.0_wp + n2 * n2))\n n2 = n2 * n3\n else\n n3 = n3 / n2\n n2 = sqrt(1.0_wp / (1.0_wp + n3 * n3))\n n3 = n3 * n2\n end if\n q(1, 2) = n3 * q(1, 2) - n2 * q(1, 3)\n q(2, 2) = n3 * q(2, 2) - n2 * q(2, 3)\n q(3, 2) = n3 * q(3, 2) - n2 * q(3, 3)\n end if\n end if\n\n ! Calculate third eigenvector from cross product\n q(1, 3) = q(2, 1) * q(3, 2) - q(3, 1) * q(2, 2)\n q(2, 3) = q(3, 1) * q(1, 2) - q(1, 1) * q(3, 2)\n q(3, 3) = q(1, 1) * q(2, 2) - q(2, 1) * q(1, 2)\n\n w(1) = w(1) * precon\n w(2) = w(2) * precon\n w(3) = w(3) * precon\n\nend subroutine eigvec3x3\n\n\nend module diag3x3\n", "meta": {"hexsha": "574f844dfe8590f77d1c52465fbe9a3685acd24b", "size": 7921, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "diag3x3.f90", "max_stars_repo_name": "awvwgk/diag3x3", "max_stars_repo_head_hexsha": "3c1d37560be7d01f617e9627964e3cbd336b8e80", "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": "diag3x3.f90", "max_issues_repo_name": "awvwgk/diag3x3", "max_issues_repo_head_hexsha": "3c1d37560be7d01f617e9627964e3cbd336b8e80", "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": "diag3x3.f90", "max_forks_repo_name": "awvwgk/diag3x3", "max_forks_repo_head_hexsha": "3c1d37560be7d01f617e9627964e3cbd336b8e80", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-05-11T13:46:35.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-11T13:46:35.000Z", "avg_line_length": 30.0037878788, "max_line_length": 76, "alphanum_fraction": 0.4698901654, "num_tokens": 3975, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972684083609, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6622203757101559}} {"text": "!------------------------------------------------------------------------------!\n!> Numerical operations.\n!------------------------------------------------------------------------------!\nmodule num_ops\n#include \n use str_utilities\n use messages\n use num_vars, only: dp, iu, max_str_ln, pi\n use num_utilities\n use output_ops\n \n implicit none\n private\n public calc_zero_HH, calc_zero_Zhang\n#if ldebug\n public debug_calc_zero\n#endif\n \n ! global variables\n#if ldebug\n !> \\ldebug\n logical :: debug_calc_zero = .false. !< plot debug information for calc_zero\n#endif\n\n ! interfaces\n \n !> \\public Finds the zero of a function using Householder iteration.\n !!\n !! If something goes wrong, by default multiple tries can be attempted, by\n !! backtracking on the correction by multiplying it by a relaxation factor.\n !! This can be done \\c max_nr_backtracks times.\n !!\n !! If still nothing is achieved, an error message is returned,\n !! that is empty otherwise.\n interface calc_zero_HH\n !> \\public\n module procedure calc_zero_HH_0D\n !> \\public\n module procedure calc_zero_HH_3D\n end interface\n \ncontains\n !> \\private 0-D version\n !! \\param[inout] fun fun(x,ord) with\n !! - x abscissa\n !! - ord order of derivative\n !! - fun ordinate\n function calc_zero_HH_0D(zero,fun,ord,guess,max_nr_backtracks,output) &\n &result(err_msg)\n use num_vars, only: max_it_zero, tol_zero, max_nr_backtracks_HH\n \n ! input / output\n real(dp), intent(inout) :: zero !< output\n interface\n function fun(x,ord) ! the function\n use num_vars, only: dp\n real(dp), intent(in) :: x\n integer, intent(in) :: ord\n real(dp) :: fun\n end function fun\n end interface\n integer, intent(in) :: ord !< order of solution\n real(dp), intent(in) :: guess !< first guess\n integer, intent(in), optional :: max_nr_backtracks !< max nr. of tries with different relaxation factors\n logical, intent(in), optional :: output !< give output on convergence\n character(len=max_str_ln) :: err_msg !< possible error message\n \n ! local variables\n integer :: id, jd, kd ! counters\n integer :: max_nr_backtracks_loc ! local max_nr_backtracks\n logical :: output_loc ! local output\n logical :: relaxed_enough ! whether step was relaxed enough to get a smaller new value\n real(dp) :: zero_new ! new zero calculated\n real(dp) :: fun_new ! function value at new zero\n real(dp) :: corr ! correction\n real(dp), allocatable :: fun_vals(:) ! function values\n#if ldebug\n real(dp), allocatable :: corrs(:) ! corrections for all steps\n real(dp), allocatable :: values(:) ! values for all steps\n#endif\n \n ! initialize error message\n err_msg = ''\n \n ! set up local output\n output_loc = .false.\n if (present(output)) output_loc = output\n \n ! set up zero\n zero = guess\n \n ! set up local max_nr_backtracks\n max_nr_backtracks_loc = max_nr_backtracks_HH\n if (present(max_nr_backtracks)) &\n &max_nr_backtracks_loc = max_nr_backtracks\n \n ! initialize function values\n allocate(fun_vals(0:ord))\n \n#if ldebug\n if (debug_calc_zero) then\n ! set up corrs\n allocate(corrs(max_it_zero))\n allocate(values(max_it_zero))\n end if\n#endif\n \n ! loop over iterations\n HH: do jd = 1,max_it_zero\n ! calculate function values\n do kd = 0,ord\n fun_vals(kd) = fun(zero,kd)\n end do\n \n ! correction to theta_HH\n select case (ord)\n case (1) ! Newton-Rhapson\n corr = -fun_vals(0)/fun_vals(1)\n case (2) ! Halley\n corr = -fun_vals(0)*fun_vals(1)/&\n &(fun_vals(1)**2 - 0.5_dp*&\n &fun_vals(0)*fun_vals(2))\n case (3) ! 3rd order\n corr = -(6*fun_vals(0)*fun_vals(1)**2-&\n &3*fun_vals(0)**2*fun_vals(2))/&\n &(6*fun_vals(1)**3 - 6*fun_vals(0)*&\n &fun_vals(1)*fun_vals(2)+&\n &fun_vals(0)**2*fun_vals(3))\n end select\n#if ldebug\n if (debug_calc_zero) then\n corrs(jd) = corr\n values(jd) = zero\n end if\n#endif\n relaxed_enough = .false.\n do id = 1,max_nr_backtracks_loc\n zero_new = zero + corr ! propose a new zero\n \n fun_new = fun(zero_new,0) ! calculate function value there\n \n if (abs(fun_new)-abs(fun_vals(0)).le.0._dp) then ! error has decreased\n relaxed_enough = .true.\n zero = zero_new\n exit\n end if\n corr = corr*0.5_dp\n end do\n \n ! check for relaxation\n if (.not.relaxed_enough) then\n err_msg = trim(i2str(max_nr_backtracks_HH))//' backtracks were &\n ¬ sufficient to get a better guess for the zero'\n zero = 0.0_dp\n else\n ! output\n if (output_loc) call writo(trim(i2str(jd))//' / '&\n &//trim(i2str(max_it_zero))//&\n &' - relative error: '//&\n &trim(r2str(abs(corr)))//' (tol: '//&\n &trim(r2str(tol_zero))//')')\n \n ! check for convergence\n if (abs(corr).lt.tol_zero) then\n#if ldebug\n if (debug_calc_zero) &\n &call plot_evolution(corrs(1:jd),values(1:jd))\n#endif\n return\n else if (jd .eq. max_it_zero) then\n#if ldebug\n if (debug_calc_zero) then\n call plot_evolution(corrs,values)\n deallocate(corrs)\n deallocate(values)\n end if\n#endif\n err_msg = 'Not converged after '//trim(i2str(jd))//&\n &' iterations, with residual '//&\n &trim(r2strt(corr))//' and final value '//&\n &trim(r2strt(zero))\n zero = 0.0_dp\n end if\n end if\n end do HH\n#if ldebug\n contains\n ! plots corrections\n !> \\private\n subroutine plot_evolution(corrs,values)\n ! input / output\n real(dp), intent(in) :: corrs(:) ! corrections\n real(dp), intent(in) :: values(:) ! values\n \n ! local variables\n real(dp) :: min_x, max_x ! min. and max. x for which to plot the function\n real(dp) :: extra_x = 1._dp ! how much bigger to take the plot interval than just min and max\n real(dp) :: delta_x ! interval between zero and guess\n integer :: n_x = 200 ! how many x values to plot\n real(dp), allocatable :: x_out(:,:) ! output x of plot\n real(dp), allocatable :: y_out(:,:) ! output y of plot\n \n ! set up min and max x\n min_x = min(zero,guess)\n max_x = max(zero,guess)\n delta_x = max_x-min_x\n min_x = min_x - delta_x*extra_x\n max_x = max_x + delta_x*extra_x\n \n ! set up output of plot\n allocate(x_out(n_x,2))\n allocate(y_out(n_x,2))\n x_out(:,1) = [(min_x+(max_x-min_x)*(jd-1._dp)/(n_x-1),jd=1,n_x)]\n x_out(:,2) = [(min_x+(max_x-min_x)*(jd-1._dp)/(n_x-1),jd=1,n_x)]\n y_out(:,1) = [(fun(min_x+(max_x-min_x)*(jd-1._dp)/(n_x-1),0),&\n &jd=1,n_x)]\n y_out(:,2) = [(fun(min_x+(max_x-min_x)*(jd-1._dp)/(n_x-1),1),&\n &jd=1,n_x)]\n \n ! plot function\n call writo('Initial guess: '//trim(r2str(guess)))\n call writo('Resulting zero: '//trim(r2str(zero)))\n call print_ex_2D(['function ','derivative'],'',y_out,x=x_out)\n \n ! user output\n call writo('Last correction '//trim(r2strt(corrs(size(corrs))))&\n &//' with tolerance '//trim(r2strt(tol_zero)))\n \n ! plot corrections and values\n call print_ex_2D('corrs','',corrs)\n call print_ex_2D('values','',values)\n end subroutine plot_evolution\n#endif\n end function calc_zero_HH_0D\n !> \\private 3-D version\n !! \\param[inout] fun fun(dims,x,ord) with\n !! - dims(3) dimension of abscissa and ordinate\n !! - x(dims(1),dims(2),dims(3)) abscissa\n !! - ord order of derivative\n !! - fun(dims(1),dims(2),dims(3)) ordinate\n function calc_zero_HH_3D(dims,zero,fun,ord,guess,max_nr_backtracks,output) &\n &result(err_msg)\n use num_vars, only: max_it_zero, tol_zero, max_nr_backtracks_HH\n \n ! input / output\n integer, intent(in) :: dims(3) !< dimensions of the problem\n real(dp), intent(inout) :: zero(dims(1),dims(2),dims(3)) !< output\n interface\n function fun(dims,x,ord) ! the function\n use num_vars, only: dp\n integer, intent(in) :: dims(3)\n real(dp), intent(in) :: x(dims(1),dims(2),dims(3))\n integer, intent(in) :: ord\n real(dp) :: fun(dims(1),dims(2),dims(3))\n end function fun\n end interface\n integer, intent(in) :: ord !< order of solution\n real(dp), intent(in) :: guess(dims(1),dims(2),dims(3)) !< first guess\n integer, intent(in), optional :: max_nr_backtracks !< max nr. of backtracks\n logical, intent(in), optional :: output !< give output on convergence\n character(len=max_str_ln) :: err_msg !< possible error message\n \n ! local variables\n integer :: id, jd, kd ! counters\n integer :: max_nr_backtracks_loc ! local max_nr_backtracks\n integer :: mc_ind(3) ! index of maximum correction\n logical :: output_loc ! local output\n logical :: relaxed_enough ! relaxed enough\n real(dp) :: zero_new(dims(1),dims(2),dims(3)) ! new zeros calculated\n real(dp) :: fun_new(dims(1),dims(2),dims(3)) ! function values at new zero\n real(dp) :: corr(dims(1),dims(2),dims(3)) ! correction\n real(dp), allocatable :: fun_vals(:,:,:,:) ! function values\n#if ldebug\n real(dp), allocatable :: corrs(:,:,:,:) ! corrections for all steps\n real(dp), allocatable :: values(:,:,:,:) ! values for all steps\n#endif\n \n ! initialize error message\n err_msg = ''\n \n ! test\n if (ord.lt.1 .or. ord.gt.3) then\n zero = 0.0_dp\n err_msg = 'only orders 1 (Newton-Rhapson), 2 (Halley) and 3 &\n &implemented, not '//trim(i2str(ord))\n return\n end if\n \n ! set up local output\n output_loc = .false.\n if (present(output)) output_loc = output\n \n ! set up zero\n zero = guess\n \n ! set up local max_nr_backtracks\n max_nr_backtracks_loc = max_nr_backtracks_HH\n if (present(max_nr_backtracks)) &\n &max_nr_backtracks_loc = max_nr_backtracks\n \n ! initialize function values\n allocate(fun_vals(dims(1),dims(2),dims(3),0:ord))\n \n#if ldebug\n if (debug_calc_zero) then\n ! set up corrs\n allocate(corrs(dims(1),dims(2),dims(3),max_it_zero))\n allocate(values(dims(1),dims(2),dims(3),max_it_zero))\n end if\n#endif\n \n ! loop over iterations\n HH: do jd = 1,max_it_zero\n ! calculate function values\n do kd = 0,ord\n fun_vals(:,:,:,kd) = fun(dims,zero,kd)\n end do\n \n ! correction to theta_HH\n select case (ord)\n case (1) ! Newton-Rhapson\n corr = -fun_vals(:,:,:,0)/fun_vals(:,:,:,1)\n case (2) ! Halley\n corr = -fun_vals(:,:,:,0)*fun_vals(:,:,:,1)/&\n &(fun_vals(:,:,:,1)**2 - 0.5_dp*&\n &fun_vals(:,:,:,0)*fun_vals(:,:,:,2))\n case (3) ! 3rd order\n corr = -(6*fun_vals(:,:,:,0)*fun_vals(:,:,:,1)**2-&\n &3*fun_vals(:,:,:,0)**2*fun_vals(:,:,:,2))/&\n &(6*fun_vals(:,:,:,1)**3 - 6*fun_vals(:,:,:,0)*&\n &fun_vals(:,:,:,1)*fun_vals(:,:,:,2)+&\n &fun_vals(:,:,:,0)**2*fun_vals(:,:,:,3))\n end select\n#if ldebug\n if (debug_calc_zero) then\n corrs(:,:,:,jd) = corr\n values(:,:,:,jd) = zero\n end if\n#endif\n relaxed_enough = .false.\n do id = 1,max_nr_backtracks_loc\n zero_new = zero ! otherwise some values might stay unitialized\n where (abs(corr).gt.tol_zero) zero_new = zero + corr ! propose a new zero\n \n fun_new = fun(dims,zero_new,0) ! calculate function value there\n \n#if ldebug\n if (debug_calc_zero) &\n &call writo('backtrack '//trim(i2str(id))//' of max. '//&\n &trim(i2str(max_nr_backtracks_loc))//' - criterion: '//&\n &trim(r2str(maxval(abs(fun_new)-abs(fun_vals(:,:,:,0)))))//&\n &' <= 0?')\n#endif\n if (maxval(abs(fun_new)-abs(fun_vals(:,:,:,0))).le.0._dp) then ! error has decreased\n relaxed_enough = .true.\n zero = zero_new\n exit\n end if\n corr = corr*0.5_dp\n end do\n \n ! check for relaxation\n if (.not.relaxed_enough) then\n err_msg = trim(i2str(max_nr_backtracks_HH))//' backtracks were &\n ¬ sufficient to get a better guess for the zero'\n zero = 0.0_dp\n exit\n else\n ! output\n if (output_loc) call writo(trim(i2str(jd))//' / '&\n &//trim(i2str(max_it_zero))//&\n &' - maximum relative error: '//&\n &trim(r2str(maxval(abs(corr))))//' (tol: '//&\n &trim(r2str(tol_zero))//')')\n \n ! check for convergence\n if (maxval(abs(corr)).lt.tol_zero) then\n#if ldebug\n if (debug_calc_zero) call &\n &plot_evolution(corrs(:,:,:,1:jd),values(:,:,:,1:jd))\n#endif\n return\n else if (jd .eq. max_it_zero) then\n#if ldebug\n if (debug_calc_zero) then\n call plot_evolution(corrs,values)\n deallocate(corrs)\n deallocate(values)\n end if\n#endif\n mc_ind = maxloc(abs(corr))\n err_msg = 'Not converged after '//trim(i2str(jd))//&\n &' iterations, with maximum residual '//&\n &trim(r2strt(corr(mc_ind(1),mc_ind(2),mc_ind(3))))&\n &//' and final value '//trim(r2strt(&\n &zero(mc_ind(1),mc_ind(2),mc_ind(3))))\n zero = 0.0_dp\n end if\n end if\n end do HH\n#if ldebug\n contains\n ! plots corrections\n !> \\private\n subroutine plot_evolution(corrs,values)\n ! input / output\n real(dp), intent(in) :: corrs(:,:,:,:) ! corrections\n real(dp), intent(in) :: values(:,:,:,:) ! values\n \n ! local variables\n integer :: n_corrs ! number of corrections\n character(len=max_str_ln) :: var_name(1) ! names of variable\n character(len=max_str_ln) :: file_name ! name of file\n \n ! initialize\n n_corrs = size(corrs,4)\n mc_ind = maxloc(abs(corrs(:,:,:,n_corrs)))\n \n ! user output\n call writo('Last maximum correction '//&\n &trim(r2strt(corrs(mc_ind(1),mc_ind(2),mc_ind(3),n_corrs)))&\n &//' and final value '//trim(r2strt(&\n &values(mc_ind(1),mc_ind(2),mc_ind(3),n_corrs)))//&\n &' with tolerance '//trim(r2strt(tol_zero)))\n \n ! plot corrs\n file_name = 'corrs'\n var_name = 'var'\n \n call plot_HDF5(var_name,file_name,corrs,col=2,&\n &descr='corrections')\n \n ! plot values\n file_name = 'values'\n var_name = 'var'\n \n call plot_HDF5(var_name,file_name,values,col=2,&\n &descr='values')\n end subroutine plot_evolution\n#endif\n end function calc_zero_HH_3D\n \n !> Finds the zero of a function using Zhang's method, which is simpler than\n !! Brent's method.\n !!\n !! Taken from from Steven Stage's correction of Zhang's paper \n !! \\cite zhang2011improvement.\n !!\n !! Unlike Householder, Zhang's method needs an interval \\c x_int_in to work\n !! in, not a guess. Also, it does not require the derivative of the\n !! function.\n !!\n !! The routine returns an error message if no zero is found, and which is\n !! empty otherwise.\n !!\n !! \\note The interval \\c x_int_in needs to be so that the function values at\n !! either end are of different value.\n !! \\param[inout] fun fun(x) with\n !! - x abscissa\n !! - fun ordinate\n function calc_zero_Zhang(zero,fun,x_int_in) result(err_msg)\n use num_vars, only: max_it_zero, tol_zero\n \n ! input / output\n real(dp), intent(inout) :: zero !< output\n interface\n function fun(x) ! the function\n use num_vars, only: dp\n real(dp), intent(in) :: x \n real(dp) :: fun \n end function fun\n end interface\n real(dp), intent(in) :: x_int_in(2) !< interval\n character(len=max_str_ln) :: err_msg !< possible error message\n \n ! local variables\n logical :: converged ! whether converged\n integer :: jd ! counter\n integer :: id_loc ! local id (either 1 or 2)\n real(dp) :: x_int(2) ! points of current interval [a,b]\n real(dp) :: x_mid ! x at midpoint [c]\n real(dp) :: x_rule ! x found with rule [s]\n real(dp) :: x_temp ! temporary x\n real(dp) :: fun_int(2) ! function at x_int\n real(dp) :: fun_mid ! function at x_mid\n real(dp) :: fun_rule ! function at x_rule\n#if ldebug\n real(dp), allocatable :: x_ints(:,:) ! bounds for all steps\n#endif\n \n ! initialize error message and zero\n err_msg = ''\n zero = 0.0_dp\n \n ! initialize from input\n x_int(1) = minval(x_int_in)\n x_int(2) = maxval(x_int_in)\n fun_int = [fun(x_int(1)),fun(x_int(2))]\n \n ! test whether already zero\n if (abs(fun_int(1)).lt.tol_zero) then\n zero = x_int(1)\n return\n end if\n if (abs(fun_int(2)).lt.tol_zero) then\n zero = x_int(2)\n return\n end if\n \n ! test whether different sign\n if (product(fun_int).gt.0) then\n err_msg = 'Function values on starting interval have same sign'\n return\n end if\n \n ! intialize converged\n converged = .false.\n \n#if ldebug\n if (debug_calc_zero) then\n ! set up x_ints\n allocate(x_ints(max_it_zero,2))\n end if\n#endif\n \n ! iterations\n do jd = 1,max_it_zero\n ! calculate midpoint and function value\n x_mid = 0.5_dp*sum(x_int)\n fun_mid = fun(x_mid)\n \n if (abs(fun_int(1)-fun_mid).gt.tol_zero .and. &\n &abs(fun_int(2)-fun_mid).gt.tol_zero) then\n ! three different function values: use inverse quadratic\n ! interpolation\n x_rule = fun_mid*fun_int(2)*x_int(1)/&\n &((fun_int(1)-fun_mid)*(fun_int(1)-fun_int(2))) + &\n &fun_int(1)*fun_int(2)*x_mid/&\n &((fun_mid-fun_int(1))*(fun_mid-fun_int(2))) + &\n &fun_int(1)*fun_mid*x_int(2)/&\n &((fun_int(2)-fun_mid)*(fun_int(2)-fun_mid))\n \n if (x_int(1).lt.x_rule .and. x_rule.lt.x_int(2)) then\n ! found x within interval\n else\n ! use bisection instead\n if (fun_int(1)*fun_mid.lt.0) then ! [a,c] contains sign change\n id_loc = 1\n else if (fun_int(2)*fun_mid.lt.0) then ! [b,c] contains sign change\n id_loc = 2\n else\n err_msg = 'Something went wrong...'\n converged = .true.\n end if\n if (.not.converged) x_rule = 0.5_dp*(x_int(id_loc)+x_mid)\n end if\n else\n ! two function values overlap so use secant rule\n if (fun_int(1)*fun_mid.lt.0) then ! [a,c] contains sign change\n id_loc = 1\n else if (fun_int(2)*fun_mid.lt.0) then ! [b,c] contains sign change\n id_loc = 2\n else\n err_msg = 'Something went wrong...'\n converged = .true.\n end if\n if (.not.converged) x_rule = x_int(id_loc) - &\n &fun_int(id_loc)*(x_int(id_loc)-x_mid)/&\n &(fun_int(id_loc)-fun_mid)\n end if\n \n ! calculate fun(s)\n fun_rule = fun(x_rule)\n \n ! make sure x_mid < x_rule\n if (x_mid.gt.x_rule) then\n x_temp = x_rule\n x_rule = x_mid\n x_mid = x_temp\n end if\n \n ! check whether [c,s] contains root\n if (fun_mid*fun_rule.lt.0) then\n x_int(1) = x_mid\n x_int(2) = x_rule\n else\n if (fun_int(1)*fun_mid.lt.0) then\n x_int(2) = x_mid\n else\n x_int(1) = x_rule\n end if\n end if\n \n#if ldebug\n if (debug_calc_zero) then\n x_ints(jd,:) = x_int\n end if\n#endif\n \n ! check for convergence\n fun_int = [fun(x_int(1)),fun(x_int(2))]\n if (abs(fun_int(1)).lt.tol_zero) then\n zero = x_int(1)\n converged = .true.\n end if\n if (abs(fun_int(2)).lt.tol_zero) then\n zero = x_int(2)\n converged = .true.\n end if\n if ((x_int(2)-x_int(1)).lt.tol_zero) then\n zero = 0.5_dp*sum(x_int)\n converged = .true.\n end if\n \n if (converged) then\n#if ldebug\n if (debug_calc_zero) call plot_evolution(x_ints(1:jd,:))\n#endif\n return\n end if\n end do\n#if ldebug\n contains\n ! plots corrections\n !> \\private\n subroutine plot_evolution(x_ints)\n ! input / output\n real(dp), intent(in) :: x_ints(:,:) ! x_intervals\n \n ! local variables\n real(dp) :: min_x, max_x ! min. and max. x for which to plot the function\n integer :: n_x = 200 ! how many x values to plot\n integer :: n_ints ! nr. of intervals\n real(dp), allocatable :: x_out(:) ! output x of plot\n real(dp), allocatable :: y_out(:) ! output y of plot\n \n ! set up nr. of intervals\n n_ints = size(x_ints,1)\n \n ! set up min and max x\n min_x = x_int_in(1)\n max_x = x_int_in(2)\n \n ! set up output of plot\n allocate(x_out(n_x))\n allocate(y_out(n_x))\n x_out = [(min_x+(max_x-min_x)*(jd-1._dp)/(n_x-1),jd=1,n_x)]\n y_out = [(fun(min_x+(max_x-min_x)*(jd-1._dp)/(n_x-1)),jd=1,n_x)]\n \n ! plot function\n call writo('Initial interval: ['//trim(r2str(x_int_in(1)))//&\n &'..'//trim(r2str(x_int_in(2)))//']')\n call writo('Resulting zero: '//trim(r2str(zero)))\n call print_ex_2D('function','',y_out,x=x_out)\n \n ! user output\n call writo('Final interval ['//trim(r2str(x_ints(n_ints,1)))//&\n &'..'//trim(r2str(x_ints(n_ints,2)))//'] with tolerance '//&\n &trim(r2strt(tol_zero)))\n \n ! plot intervals\n call print_ex_2D(['x_intervals'],'',x_ints)\n end subroutine plot_evolution\n#endif\n end function calc_zero_Zhang\nend module num_ops\n", "meta": {"hexsha": "bcbf72b901f8fb4e5782fa18b6c64448d997d846", "size": 29000, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Modules/num_ops.f90", "max_stars_repo_name": "ToonWeyens/PB3D", "max_stars_repo_head_hexsha": "a7d1958c20c57387e6c9125f0d3df4b2104329e0", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-05-09T21:41:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-18T18:10:15.000Z", "max_issues_repo_path": "Modules/num_ops.f90", "max_issues_repo_name": "ToonWeyens/PB3D", "max_issues_repo_head_hexsha": "a7d1958c20c57387e6c9125f0d3df4b2104329e0", "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": "Modules/num_ops.f90", "max_forks_repo_name": "ToonWeyens/PB3D", "max_forks_repo_head_hexsha": "a7d1958c20c57387e6c9125f0d3df4b2104329e0", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.4782608696, "max_line_length": 145, "alphanum_fraction": 0.4335172414, "num_tokens": 6460, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972549785203, "lm_q2_score": 0.7606506418255927, "lm_q1q2_score": 0.6622203607710107}} {"text": "program mathtool\n\n! The Mathematician's Toolkit\n! Version date: 2004-07-14\n! Copyright 2002, 2003, 2004\n\n! Author: David H Bailey (LBNL)\n! Contact email: dhbailey@lbl.gov\n\n! This software is provided for research purposes only. \n! Commercial usage requires license agreement.\n\n! This work was supported by the Director, Office of Science, Division\n! of Mathematical, Information, and Computational Sciences of the\n! U.S. Department of Energy under contract number DE-AC03-76SF00098.\n\nuse mpmodule\nuse globdata\nimplicit none\ninteger i, i1, i2, ires, j, k, lfname, lnam1, lnam2, lnblk, lstr, lstx, &\n lst1, lst2, ndig, nres, nunit\nparameter (lstx = 2048)\ncharacter*1 st1(lstx), stout(lstx+100)\ncharacter*16 lcase, strx1, strx2\ncharacter*40 fname\ncharacter*160 str1, str2\ncharacter*2048 string\ntype (mp_real) res(ntmpx)\ndouble precision tm0, tm1, second\nexternal lnblk, lcase\n\nwrite (6, 1)\n1 format ('Welcome to the Experimental Mathematician''s Toolkit'/&\n 'Initializing...')\ncall mpinit (ndigmx2)\ncall toolinit\nires = 0\nnunit = 5\nlfname = 0\nfname = ' '\n\n100 continue\n\ni1 = lnblk (quadn(nquadt))\nwrite (6, 2) ndebug, ndigits1, ndigits2, nepsilon1, nepsilon2, npslqb, npslql, &\n nquadl, nquadt, quadn(nquadt)(1:i1)\n2 format (/'Current settings:'/&\n 'Debug level =',i4/&\n 'Primary precision level =',i6,' digits'/&\n 'Secondary precision level =',i6,' digits'/&\n 'Primary epsilon = 10^',i6/&\n 'Secondary epsilon = 10^',i6/&\n 'PSLQ bound =',i4/&\n 'PSLQ level =',i4/&\n 'Quadrature level =',i4/&\n 'Quadrature type =',i4,' (',a,')')\nwrite (6, 3)\n3 format (/'Sample expressions (case insensitive):'/ &\n 'e + pi + log2 + log10 + catalan Adds these pre-defined constants.'/&\n 'result[1] + result[2] Adds result #1 to result #2.'/&\n 'alpha = arctan[3] - 3*log[2] Defines or sets user variable alpha.'/&\n 'fun1[x,y] = 2*sqrt[x]*erf[y] Defines user function fun1.'/&\n 'clear[nam1] Clears definition of variable or function.'/&\n 'integrate[1/(1+x^2), {x, 0, 1}] Integrates 1/(1+x^2) from x=0 to 1.'/&\n 'sum[1/2^k, {k, 0, infinity}] Sums 1/2^k from k=0 to infinity.'/&\n 'binomial[20,10]*factorial[10] Evaluates binomial coeff and factorial.'/&\n 'zeta[3] + zetaz[1,1,2] Evaluates zeta and multi-zeta functions.'/&\n 'table[x^k, {k, 1, 4}] Forms the list [x^1, x^2, x^3, x^4].'/&\n 'pslq[table[x^k, {k, 0, n}]] Finds coeffs of degree-n poly for x.'/&\n 'polyroot[1,-1,-1,{0.618}] Finds real root of 1-x-x^2=0 near 0.618.'/&\n 'polyroot[1,2,3,{-0.33, 0.47}] Complex root of 1+2x+3x^2 near -0.33+0.47i.'/&\n 'digits = 200 Sets working precision to 200 digits.'/&\n 'epsilon = -190 Sets epsilon level to 10^(-190).'/&\n 'eformat[190,180] Display using E format with 180 digits.'/&\n 'fformat[60,50] Display using F format with 50 digits.'/&\n 'input file.dat Inputs commands from file file.dat.'/&\n 'output file.dat Outputs user vars and funs to file.dat.'/&\n 'help polyroot Displays a brief explanation of polyroot.'/&\n 'functions Displays a list of all defined functions.'/&\n 'variables Displays a list of all defined variables.'/&\n 'prompt Displays this message.'/&\n 'exit Exits this program.'/&\n 'Expressions may be continued on next line by typing \\ at end of line.')\n\n! Input expression string.\n\n110 continue\n\nnerror = 0\nlstr = 0\nstring = ' '\nwrite (6, '()')\n\n120 continue\n\nread (nunit, '(a160)', end = 300) str1\nlst1 = lnblk (str1)\n\nif (lst1 == 0 .and. lstr == 0) then\n\n! Null string.\n\n goto 110\nelseif (lstr + lst1 > lstx) then\n\n! Input string exceeds maximum length.\n\n write (6, 4) lstx\n4 format ('Combined input string too long; max length = ',i5)\n goto 110\nelseif (str1(lst1:lst1) == '\\') then\n\n! Input string is continued on next line.\n\n string(lstr+1:lstr+lst1-1) = str1(1:lst1-1)\n lstr = lstr + lst1 - 1\n goto 120\nelseif (str1 == 'prompt') then\n\n! Prompt.\n\n goto 100\nelseif (str1 == 'exit') then\n\n! Exit\n\n goto 400\nelseif (str1(1:5) == 'input') then\n\n! Input definitions from file.\n\n do i = 6, lst1\n if (str1(i:i) /= ' ') goto 130\n enddo\n\n130 continue\n\n lfname = lst1 - i + 1\n fname = str1(i:lst1)\n if (lfname <= 0 .or. lfname > 40 .or. fname == ' ') then\n write (6, 5)\n5 format ('Input file name missing or too long; max 40 chars.')\n goto 110\n endif\n nunit = 10\n open (nunit, file = fname, status = 'old', form = 'formatted', err = 140)\n rewind (nunit)\n goto 110\n\n140 continue\n\n write (6, 6) fname(1:lfname)\n6 format ('Input file does not exist: ',a)\n nunit = 5\n goto 110\nelseif (str1(1:6) == 'output') then\n\n! Output variables and function definitions to file.\n\n do i = 7, lst1 \n if (str1(i:i) /= ' ') goto 150\n enddo\n \n150 continue \n \n lfname = lst1 - i + 1 \n fname = str1(i:lst1) \n if (lfname <= 0 .or. lfname > 40 .or. fname == ' ') then \n write (6, 7) \n7 format ('Output file name missing or too long; max 40 chars.') \n goto 110 \n endif \n open (10, file = fname, form = 'formatted')\n rewind 10\n\n! Output variable names and numerical values to file.\n\n do i = nvara + nvarb + nvarc + 1, nvar\n lnam1 = lnblk (varn(i))\n lst2 = lnam1\n str2(1:lst2) = varn(i)(1:lst2)\n str2(lst2+1:lst2+4) = ' = \\'\n lst2 = lst2 + 4\n write (10, '(a)') str2(1:lst2)\n call mpeform (var(i), ndigits1+20, ndigits1, stout)\n lnam2 = ndigits1 + 20\n\n do k = 0, lnam2 - 1, 80\n lst2 = min (lnam2 - k, 80)\n str2 = ' '\n\n do j = 1, lst2\n str2(j:j) = stout(j+k)\n enddo\n\n if (k + lst2 < lnam2 - 1) then\n str2(lst2+1:lst2+1) = '\\'\n lst2 = lst2 + 1\n endif\n write (10, '(a)') str2(1:lst2)\n enddo\n enddo\n\n! Output function definitions to file.\n\n do i = nfuna + 1, nfun\n lnam1 = lnblk (funn(i))\n lnam2 = lnblk (fund(i))\n str2(1:lnam1) = funn(i)(1:lnam1)\n str2(lnam1+1:lnam1+1) = '['\n lst2 = lnam1 + 1\n\n do j = 1, narg(i)\n write (strx1, '(\"arg\",i1,\",\")') j\n str2(lst2+1:lst2+5) = strx1(1:5)\n lst2 = lst2 + 5\n enddo\n\n str2(lst2:lst2+4) = '] = \\'\n lst2 = lst2 + 4\n write (10, '(a)') str2(1:lst2)\n lst2 = 0\n str2 = ' '\n\n do k = 0, lnam2 - 1, 80\n lst2 = min (lnam2 - k, 80)\n str2(1:lst2) = fund(i)(k+1:k+lst2)\n if (k + lst2 < lnam2 - 1) then\n str2(lst2+1:lst2+1) = '\\'\n lst2 = lst2 + 1\n endif\n write (10, '(a)') str2(1:lst2)\n enddo\n enddo\n\n rewind 10\n close (10)\n write (6, 8) fname(1:lfname)\n8 format ('User variables and function definitions output to file: ',a)\n goto 110 \nelseif (str1(1:5) == 'clear') then\n\n! Clear a function or variable name.\n\n i1 = index (str1, ']')\n if (str1(6:6) /= '[' .or. i1 == 0) then\n write (6, 9)\n9 format ('Syntax eror in clear command.')\n goto 110\n endif\n strx1 = str1(7:i1-1)\n\n do j = nvara + nvarb + nvarc + 1, nvar\n if (varn(j) == strx1) then\n do i = j, nvar - 1\n varn(i) = varn(i+1)\n var(i) = var(i+1)\n enddo\n\n nvar = nvar - 1\n write (6, 10) strx1(1:16)\n10 format ('Variable name removed: ',a)\n goto 110\n endif\n enddo\n\n do j = nfuna + 1, nfun\n if (funn(j) == strx1) then\n do i = j, nfun - 1\n narg(i) = narg(i+1)\n funn(i) = funn(i+1)\n fund(i) = fund(i+1)\n enddo\n\n nfun = nfun - 1\n write (6, 11) strx1(1:16)\n11 format ('Function name removed: ',a)\n goto 110\n endif\n enddo\n\n write (6, 12) strx1\n12 format ('No user variable or function by this name: ',a)\n goto 110\nelseif (str1(1:7) == 'eformat') then\n\n! Switch to E Format.\n\n i1 = index (str1, ',')\n i2 = index (str1, ']')\n if (str1(8:8) /= '[' .or. i1 == 0 .or. i2 == 0 .or. i2 < i1 .or. lst1 > i2) &\n then\n write (6, 13)\n13 format ('Syntax error in eformat command.')\n goto 110\n endif\n strx1 = str1(9:i1-1)\n strx2 = str1(i1+1:i2-1)\n read (strx1, '(i16)') i1\n read (strx2, '(i16)') i2\n if (i1 < 0 .or. i1 > lstx .or. i2 > ndigits1 .or. i2 < 0 .or. i2 > i1 - 5) then\n write (6, 14) i1, i2\n14 format ('Improper arguments in eformat command:',2i7)\n goto 110\n endif\n nef = 1\n nef1 = i1\n nef2 = i2\n goto 110\nelseif (str1(1:7) == 'fformat') then\n\n! Switch to F Format.\n\n i1 = index (str1, ',')\n i2 = index (str1, ']')\n if (str1(8:8) /= '[' .or. i1 == 0 .or. i2 == 0 .or. i2 < i1 .or. lst1 > i2) &\n then\n write (6, 15)\n15 format ('Syntax error in fformat command.')\n goto 110\n endif\n strx1 = str1(9:i1-1)\n strx2 = str1(i1+1:i2-1)\n read (strx1, '(i16)') i1\n read (strx2, '(i16)') i2\n if (i1 < 0 .or. i1 > lstx .or. i2 > ndigits1 .or. i2 < 0 .or. i2 > i1 - 5) then\n write (6, 16) i1, i2\n16 format ('Improper arguments in fformat command:',2i7)\n goto 110\n endif\n nef = 2\n nef1 = i1\n nef2 = i2\n goto 110\nelseif (str1(1:4) == 'help') then\n\n do i = 5, lst1\n if (str1(i:i) /= ' ') goto 160\n enddo\n\n160 continue\n\n i1 = lst1 - i + 1\n strx1 = str1(i:lst1)\n if (i1 <= 0 .or. strx1 == ' ') strx1 = '[blank]'\n i2 = 0\n\n do j = 1, nfuna\n if (lcase (strx1) == lcase (funn(j))) then\n i2 = j\n\n do i = 1, 4\n if (funhelp(i,j) /= ' ') write (6, '(a)') funhelp(i,j)\n enddo\n endif\n enddo\n\n if (i2 == 0) write (6, 17) strx1, (funn(i), i = 1, nfuna)\n17 format ('This is not a valid predefined function name: ',a/ &\n 'Help information available for:'/ (a,' ',a,' ',a,' ',a))\n goto 110\nelseif (str1(1:9) == 'variables') then\n write (6, '(a,\" \",a,\" \",a,\" \",a)') (varn(i), i = 1, nvar)\n goto 110\nelseif (str1(1:9) == 'functions') then\n write (6, '(a,\" \",a,\" \",a,\" \",a)') (funn(i), i = 1, nfun)\n goto 110\nendif\n\n! Form full input string.\n\nif (lst1 > 0) then\n string(lstr+1:lstr+lst1) = str1(1:lst1)\n lstr = lstr + lst1\nendif\n\n! Check if string is function name without brackets.\n\nif (lstr <= 16) then\n do j = nfuna + 1, nfun\n if (string(1:lstr) == funn(j)) then\n i1 = lnblk (fund(j))\n\n do i = 1, i1, 76\n if (i + 76 < i1) then\n write (6, '(a,\"\\\")') fund(j)(i:i+75)\n else\n write (6, '(a)') fund(j)(i:i1)\n endif\n enddo\n\n goto 110\n endif\n\n enddo\nendif\n\n! Parse input string.\n\ncall mpsetpar ('mpier', 0)\ntm0 = second ()\ncall parse (string, nres, res)\ntm1 = second ()\n\nif (nerror > 0) then\n\n! Error code resulted during execution.\n\n write (6, 18) nerror\n18 format ('Error; code =',i3)\nelse\n\n! Output results, and post results to % and to Result array.\n\n if (nres > 0) then\n if (ires + nres > mxres) ires = 0\n if (nres == 1) then\n write (6, 19) ires + 1\n19 format ('Result[',i3,'] =')\n elseif (nres > 1) then\n write (6, 20) ires + 1, ires + nres\n20 format ('Result[',i3,'] through Result[',i3,'] =')\n endif\n\n do i = 1, nres\n ires = ires + 1\n result(ires) = res(i)\n if (nef == 1) then\n call mpeform (res(i), nef1, nef2, stout)\n elseif (nef == 2) then\n call mpfform (res(i), nef1, nef2, stout)\n endif\n lnam2 = nef1\n\n do k = 0, lnam2 - 1, 80\n lst2 = min (lnam2 - k, 80)\n str2 = ' '\n\n do j = 1, lst2\n str2(j:j) = stout(j+k)\n enddo\n\n if (k + lst2 < lnam2 - 1) then\n str2(lst2+1:lst2+1) = '\\'\n lst2 = lst2 + 1\n endif\n write (6, '(a)') str2(1:lst2)\n enddo\n enddo\n endif\n if (ndebug > 0) then\n write (6, 21) tm1 - tm0\n21 format ('CPU time =',f12.4)\n endif\nendif\n\ngoto 110\n\n! End of file for input data from file.\n\n300 continue\n\nwrite (6, 22) fname(1:lfname)\n22 format ('Input commands read from file: ',a)\nrewind (10)\nclose (10)\nnunit = 5\nlfname = 0\nfname = ' '\ngoto 110\n\n400 continue\n\nstop\nend\n\nsubroutine toolinit\n\n! This subroutine initializes data for the Toolkit.\n\nuse mpmodule\nuse globdata\nimplicit none\ninteger i, i1, i2, ndeb0, nq0, nq3\ntype (mp_real) catalan, eulergamma, t1, t2, t3\nparameter (ndeb0 = 2, nq0 = 3)\n\n! Set basic parameters.\n\ni1 = 1\n\ndo i = 1, 72\n call mpsetpar ('mpker', i1, i)\nenddo\n\nnfun = nfuna\nnvar = nvara + nvarb + nvarc\nndebug = ndeb0\nndigits1 = min (ndigi, ndigmx1)\nndigits2 = min (2 * ndigits1, ndigmx2)\nnepsilon1 = -ndigits1\nnepsilon2 = -ndigits2\nmpoud = ndigits1\nnquadl = int (log (dble (ndigits1)) / log (2.d0))\nnpslqb = 100\nnpslql = 1\nnquadt = nq0\nnef = 1\nnef1 = 78\nnef2 = 68\n\n! Read constants and quadrature arrays from files.\n\nopen (11, file = 'const.dat', form = 'unformatted')\nrewind (11)\nread (11) t1, t2\nrewind (11)\nclose (11)\n\nif (nquadt == 1) then\n open (11, file = 'quadgs.dat', form = 'unformatted')\nelseif (nquadt == 2) then\n open (11, file = 'quaderf.dat', form = 'unformatted')\nelseif (nquadt == 3) then\n open (11, file = 'quadts.dat', form = 'unformatted')\nendif\nrewind (11)\nread (11) nq3\nread (11) (quadwk(i), i = -1, nq3)\nread (11) (quadxk(i), i = -1, nq3)\nrewind (11)\nclose (11)\n\n! Initialize var array with basic constants.\n\nt3 = 1.d0\nvar(1) = exp (t3)\nvar(2) = mpl02\nvar(3) = mpl10\nvar(4) = mppic\nvar(5) = t1\nvar(6) = t2\nvar(7) = mplrg\n\ndo i = 1, nvarb\n var(nvara+i) = 0.d0\nenddo\n\ndo i = nvara + nvarb + 1, nvara + nvarb + nvarc\n if (varn(i) == 'Debug') then\n var(i) = dble (ndebug)\n elseif (varn(i) == 'Digits') then\n var(i) = dble (ndigits1)\n elseif (varn(i) == 'Digits2') then\n var(i) = dble (ndigits2)\n elseif (varn(i) == 'Epsilon') then\n var(i) = dble (nepsilon1)\n elseif (varn(i) == 'Epsilon2') then\n var(i) = dble (nepsilon2)\n elseif (varn(i) == 'Pslqbound') then\n var(i) = dble (npslqb)\n elseif (varn(i) == 'Pslqlevel') then\n var(i) = dble (npslql)\n elseif (varn(i) == 'Quadlevel') then\n var(i) = dble (nquadl)\n elseif (varn(i) == 'Quadtype') then\n var(i) = dble (nquadt)\n else\n write (6, 1) \n1 format ('toolinit: impossible case -- please contact author.')\n stop\n endif\nenddo\n\ndo i = 1, nvarz\n var(nvara+nvarb+nvarc+i) = 0.d0\nenddo\n\n! Set precision to ndigits1. This must be done last, so as to insure\n! that the constants in var (see above) are stored to full precision.\n\ncall mpsetprec (ndigits2)\ncall mpgetprecwords (nwords2)\ncall mpsetprec (ndigits1)\ncall mpgetprecwords (nwords1)\n\nreturn\nend\n\nrecursive subroutine parse (string, nres, res)\n\n! This subroutine parses and processes the input character string.\n\nuse mpmodule\nuse globdata\nimplicit none\ninteger i, inam, inum, ioper, iop(8), iprec(0:7), iasgn, i1, i2, i3, j, &\n k, ks, k1, k2, lnam, lnam1, lnam2, lnamx, lnblk, lnum, lnum1, lnum2, &\n lnumx, lstr, nop, nres, ntmp1, ntmp2\ncharacter*27 alphal, alphau\ncharacter*11 digits\ncharacter*13 delim\nparameter (lnamx = 16, lnumx = 2048, &\n alphal = 'abcdefghijklmnopqrstuvwxyz_', &\n alphau = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_', &\n digits = '0123456789.', delim = ' +-*/^:=,()[]')\ncharacter*2048 num, num1, num2\ncharacter*2048 string, str1, str2, str3\ncharacter*16 lcase, nam, nam1, nam2, argn(nvarb)\ncharacter*1 char\ntype (mp_real) res(ntmpx), tmp1(ntmpx), tmp2(ntmpx), t1, t2, t3\ntype (mp_real) t300\nexternal lnblk, lcase\ndata iprec /3, 1, 1, 2, 2, 4, 0, 0/\n\nt300 = 1.d300\nlstr = lnblk (string)\n\n! write (6, *) 'parse: enter; string ='\n! write (6, *) string(1:lstr)\n\nioper = 0\niasgn = 0\nk = 0\nlnam = 0\nlnum = 0\nnam = ' '\nnum = ' '\nnop = 0\nnres = 0\nntmp1 = 0\nntmp2 = 0\n\n100 continue\n\nk = k + 1\nif (k > lstr) goto 200\nchar = string(k:k)\n\n! Check for alphabetic.\n\n! write (6, *) 'parse: k, lstr, char =', k, lstr, '#'//char//'#'\n! write (6, *) 'nop, iop array =', nop, (iop(i), i = 1, nop), &\n! (delim(iop(i)+1:iop(i)+1), i = 1, nop)\n! write (6, *) 'nres, res array =', nres\n! write (6, '(1p,d20.10)') (dble(min(max(res(i),-t300),t300)), i=1,nres)\n\ni1 = index (alphau, char)\ni2 = index (alphal, char)\ni3 = max (i1, i2)\nif (i3 > 0 .and. (char /= 'e' .or. lnum == 0)) then\n if (ioper /= 0) then\n write (6, 1) \n1 format ('parse: operator expected, variable name found.'/ &\n 'If multiplication is intended, use * between operands.')\n nerror = 1\n goto 400\n endif\n if (lnum > 0) then\n write (6, 2) \n2 format ('parse: alphabetic character in digit string.')\n nerror = 2\n goto 400\n endif\n lnam = lnam + 1\n if (lnam > lnamx) then\n write (6, 3) lnamx\n3 format ('parse: name too long; max chars =',i4)\n nerror = 3\n goto 400\n endif\n nam(lnam:lnam) = char\n goto 100\nendif\n\n! Check for numeric.\n\ni1 = index (digits, char)\n\nif (i1 > 0 .or. i3 > 0) then\n if (ioper /= 0) then\n write (6, 4) \n4 format ('parse: operator expected, numeric constant found.'/ &\n 'If multiplication is intended, use * between operands.')\n nerror = 4\n goto 400\n endif\n if (lnam > 0) then\n if (i1 == 11) then\n write (6, 31) nam(1:lnam)\n31 format ('parse: period after name =',a)\n goto 400\n endif\n lnam = lnam + 1\n if (lnam > lnamx) then\n write (6, 3) lnamx\n nerror = 5\n goto 400\n endif\n nam(lnam:lnam) = char\n else\n lnum = lnum + 1\n if (lnum > lnumx) then\n write (6, 5) lnumx\n5 format ('parse: digit string too long; max chars =',i6)\n nerror = 6\n goto 400\n endif\n num(lnum:lnum) = char\n\n! If this is an 'e' (in an e-format number), check if next char is '-'.\n\n if (char == 'e' .and. k < lstr .and. lnum < lnumx) then\n if (string(k+1:k+1) == '-') then\n k = k + 1\n lnum = lnum + 1\n num(lnum:lnum) = string(k:k)\n endif\n endif\n endif\n goto 100\nendif\n\n200 continue\n\n! Check if this is end of name.\n\nif (lnam > 0) then\n\n! Look for brackets containing dummy argument list.\n\n call findbrackets (k, string, k1, k2)\n if (nerror > 0) goto 400\n if (k1 == 0) then\n\n! Check table of defined variables.\n\n do j = 1, nvar\n if (lcase (nam) == lcase (varn(j))) then\n\n! Add variable's value to res array.\n\n nres = nres + 1\n if (nres > ntmpx) then\n write (6, 6) ntmpx\n6 format ('parse: vector too long; max =',i4)\n nerror = 7\n goto 400\n endif\n res(nres) = var(j)\n if (nres == 1) iasgn = j\n lnam = 0\n nam = ' '\n ioper = 1\n goto 300\n endif\n enddo\n\n! New name is not found in variable name table. Check if it appears in \n! function name table.\n\n do i = 1, nfun\n if (lcase (nam) == lcase (funn(i))) then\n write (6, 7) nam\n7 format ('parse: function name is not followed by brackets = ',a)\n nerror = 8\n goto 400\n endif\n enddo\n\n! If new name appears after first variable or numeric string, it is undefined.\n\n if (nres > 0) then\n write (6, 8) nam\n8 format ('parse: variable name not found: ',a/ &\n 'Currently defined variable names =')\n write (6, '(4a18)') (varn(i), i = 1, nvar)\n nerror = 9\n goto 400\n endif\n\n! Add new name to variable table.\n\n nvar = nvar + 1\n if (nvar > nvarx) then\n write (6, 9) nvarx\n9 format ('parse: too many variable names; max =',i4)\n nerror = 10\n goto 400\n endif\n var(nvar) = 0.d0\n varn(nvar) = nam\n nres = 1\n res(1) = 0.d0\n iasgn = nvar\n write (6, 10) nam\n10 format ('parse: new variable name = ',a)\n lnam = 0\n nam = ' '\n ioper = 1\n\n! Make sure that new variable name is followed by = or :=\n\n do i = k, lstr - 1\n if (string(i:i) /= ' ') then\n if (string(i:i) /= '=' .and. string(i:i+1) /= ':=') then\n goto 210\n else\n goto 300\n endif\n endif\n enddo\n\n210 continue\n\n write (6, 11) \n11 format ('parse: new variable name is not followed by = or :=')\n nerror = 11\n goto 400\n else\n\n! Pair of brackets found -- check table of defined functions for name.\n\n do j = 1, nfun\n if (lcase (nam) == lcase (funn(j))) then\n\n! Evaluate function arguments, then evaluate function.\n\n str1 = string(k1+1:k2-1)\n call evalfun (j, str1, tmp1, ntmp2, tmp2)\n if (nerror > 0) goto 400\n\n! Append function value(s) to res array.\n\n if (nres + ntmp2 > ntmpx) then\n write (6, 6) ntmpx\n nerror = 12\n goto 400\n endif\n\n do i = 1, ntmp2\n nres = nres + 1\n res(nres) = tmp2(i)\n enddo\n\n k = k2 + 1\n ioper = ntmp2\n if (k > lstr) goto 300\n char = string(k:k)\n lnam = 0\n nam = ' '\n goto 300\n endif\n enddo\n\n! New name is not found in function name table. Check if it appears in \n! variable name table.\n\n do i = 1, nvar\n if (lcase (nam) == lcase (varn(i))) then\n write (6, 13) nam\n13 format ('parse: variable name is followed by brackets = ',a)\n nerror = 13\n goto 400\n endif\n enddo\n\n! If new name appears after first variable or numeric string, it is undefined.\n\n if (nres > 0) then\n write (6, 14) nam\n14 format ('parse: function name not found: ',a/ &\n 'Currently defined function names =')\n write (6, '(4a18)') (funn(i), i = 1, nfun)\n nerror = 14\n goto 400\n endif\n\n! Add new name to function table.\n\n nfun = nfun + 1\n if (nfun > nfunx) then\n write (6, 15) nfunx\n15 format ('parse: too many function names; max =',i4)\n nerror = 15\n goto 400\n endif\n funn(nfun) = nam\n write (6, 16) nam\n16 format ('parse: new function name = ',a)\n k = k1 + 1\n\n! Make sure the new function is followed by a valid dummy argument list.\n\n do j = 1, nvarb\n do i = k, k2\n if (string(i:i) /= ' ') goto 220\n enddo\n\n220 continue\n\n k = i\n if (k == k2) then\n write (6, 17) nvarb\n17 format ('parse: syntax error in dummy argument list; max args =',i2)\n nerror = 16\n goto 400\n endif\n\n i1 = index (string(k:k2), ',')\n if (i1 == 0) i1 = k2 - k + 1\n i2 = k - 1 + i1\n nam1 = string (k:i2-1)\n i3 = lnblk (nam1)\n\n do i = 1, i3\n if (index (delim, nam1(i:i)) > 0) then\n write (6, 17) nvarb\n nerror = 17\n goto 400\n endif\n enddo\n\n argn(j) = nam1\n k = i2 + 1\n if (k >= k2) goto 240\n enddo\n\n write (6, 17) nvarb\n nerror = 18\n goto 400\n\n240 continue\n\n narg(nfun) = j\n k = k + 1\n \n! Make sure that new function argument list is followed by = or :=\n\n do i = k, lstr - 1\n if (string(i:i) /= ' ') then\n if (string(i:i) == '=') then\n k = i + 1\n goto 260\n elseif (string(i:i+1) == ':=') then\n k = i + 2\n goto 260\n else\n goto 250\n endif\n endif\n enddo\n\n250 continue\n\n write (6, 19)\n19 format ('parse: new function name is not followed by = or :=')\n nerror = 19\n goto 400\n\n260 continue\n\n! Replace dummy argument names in function definition with arg1, arg2, etc.\n\n\n do i = k, lstr\n if (string(i:i) /= ' ') goto 270\n enddo\n\n270 continue\n\n k = i\n str1 = string(k:lstr)\n\n do i = 1, j\n write (nam1, '(\"arg\",i1)') i\n call replace (argn(i), nam1, str1, str2)\n str1 = str2\n enddo\n\n! Insert remainder of input string into function definition array.\n\n fund(nfun) = str1\n goto 400\n endif\nelseif (lnum > 0) then\n\n! End of digit string. Append value to res array.\n\n nres = nres + 1\n if (nres > ntmpx) then\n write (6, 6) ntmpx\n nerror = 20\n goto 400\n endif\n res(nres) = num(1:lnum)\n lnum = 0\n num = ' '\n ioper = 1\n goto 300\nendif\n\n300 continue\n\n! write (6, *) 'parse: after 300:'\n! write (6, *) 'nop, iop array =', nop, (iop(i), i = 1, nop), &\n! (delim(iop(i)+1:iop(i)+1), i = 1, nop)\n! write (6, '(1p,d20.10)') (dble(min(max(res(i),-t300),t300)), i=1,nres)\n\n! Check for end-of-line -- if so, clear pending arithmetic operation(s).\n\nif (k > lstr) then\n\n! write (6, *) 'parse: end of line'\n\n if (ioper == 0) then\n write (6, 20)\n20 format ('parse: premature end of line.')\n nerror = 21\n goto 400\n elseif (ioper > 1 .and. nop > 0) then\n write (6, 102)\n102 format ('parse: illegal operator with array result.')\n nerror = 22\n goto 400\n endif\n\n do i = nop, 1, -1\n i1 = iop(i)\n call oper (i1, iasgn, nres, res)\n if (nerror > 0) goto 400\n enddo\n\n goto 400\nendif\n\n! Check for delimiters.\n\ni1 = index (delim, char)\n\n! Handle other delimiters.\n\nif (i1 == 0) then\n write (6, 21) char\n21 format ('parse: illegal character =',a)\n nerror = 23\n goto 400\nelseif (i1 == 1) then\n\n! Delimiter is a blank.\n\n goto 100\nelseif (ioper == 0 .and. (i1 == 2 .or. i1 >= 4 .and. i1 <= 9)) then\n\n! Consecutive operators.\n\n write (6, 22)\n22 format ('parse: illegal operator syntax.')\n nerror = 24\n goto 400\nelseif (i1 >= 2 .and. i1 <= 8) then\n if (ioper > 1) then\n write (6, 22)\n nerror = 25\n goto 400\n endif\n\n! write (6, *) 'parse: start of arith op block:'\n! write (6, *) 'nop, iop array =', nop, (iop(i), i = 1, nop), &\n! (delim(iop(i)+1:iop(i)+1), i = 1, nop)\n! write (6, '(1p,d20.10)') (dble(min(max(res(i),-t300),t300)), i=1,nres)\n\n! Delimiter is arithmetic operator or equal.\n\n if (i1 == 7) then\n if (k == lstr .or. string(k:k+1) /= ':=') then\n write (6, 23)\n23 format ('parse: colon is not followed by equal sign.')\n nerror = 26\n goto 400\n endif\n endif\n if (ioper == 0 .and. i1 == 3) then\n\n! Unary minus case.\n\n i2 = 0\n else\n i2 = i1 - 1\n endif\n\n! Compare precedence with pending operations, and clear as needed.\n\n do i = nop, 1, -1\n if (iprec(iop(i)) < iprec(i2)) goto 350\n i3 = iop(i)\n call oper (i3, iasgn, nres, res)\n if (nerror > 0) goto 400\n enddo\n\n i = 0\n\n350 continue\n\n nop = i + 1\n iop(nop) = i2\n if (i2 == 6) k = k + 1\n ioper = 0\n\n! write (6, *) 'parse: end of arith op block:'\n! write (6, *) 'nop, iop array =', nop, (iop(i), i = 1, nop), &\n! (delim(iop(i)+1:iop(i)+1), i = 1, nop)\n! write (6, '(1p,d20.10)') (dble(min(max(res(i),-t300),t300)), i=1,nres)\n\n goto 100\nelseif (i1 == 9) then\n\n! Delimiter is a comma -- clear pending arithmetic operation(s).\n\n do i = nop, 1, -1\n i1 = iop(i)\n call oper (i1, iasgn, nres, res)\n if (nerror > 0) goto 400\n enddo\n\n nop = 0\n ioper = 0\n goto 100\nelseif (i1 == 10) then\n\n! Delimiter is left parentheses.\n\n if (ioper > 0) then\n write (6, 24)\n24 format ('parse: illegal parenthesis syntax.')\n nerror = 27\n goto 400\n endif\n\n! find matching right parenthesis.\n\n call findpars (k, string, k1, k2)\n if (nerror > 0) goto 400\n\n! Evaluate expression inside parentheses.\n\n str1 = string(k1+1:k2-1)\n\n! write (6, *) 'parse: before recursive call to parse'\n\n call parse (str1, ntmp1, tmp1)\n\n! write (6, *) 'parse: after recursive call to parse'\n\n if (nerror > 0) goto 400\n if (ntmp1 > 1) then\n write (6, 25)\n25 format ('parse: expression inside parentheses has multiple values.')\n nerror = 28\n goto 400\n endif\n\n! Append value to res array.\n\n nres = nres + 1\n if (nres > ntmpx) then\n write (6, 6) ntmpx\n nerror = 29\n goto 400\n endif\n res(nres) = tmp1(1)\n k = k2\n ioper = 1\n goto 100\nelseif (i1 == 11) then\n\n! Delimiter is right parenthesis.\n\n write (6, 26)\n26 format ('parse: mismatched right parenthesis.')\n nerror = 30\n goto 400\nelseif (i1 == 12) then\n\n! Delimiter is left bracket.\n\n write (6, 27)\n27 format ('parse: illegal left bracket.')\n nerror = 31\n goto 400\nelseif (i1 == 13) then\n\n! Delimiter is right bracket.\n\n write (6, 28)\n28 format ('parse: illegal right bracket.')\n nerror = 32\n goto 400\nelse\n write (6, 29) char\n29 format ('parse: illegal delimiter =',a)\n nerror = 33\n goto 400\nendif\n\n400 continue\n\n! write (6, *) 'parse: exit; nerror, nres =', nerror, nres\n! write (6, '(1p,d20.10)') (dble(min(max(res(i),-t300),t300)), i=1,nres)\n\nreturn\nend\n\nsubroutine oper (ix, iasgn, nres, res)\n\n! This evaluates arithmetic operations.\n\nuse mpmodule\nuse globdata\nimplicit none\ninteger i, i1, i2, ix, iasgn, k, k1, lnblk, lnm, ierror, nq3, nres\ncharacter*16 delim, lcase, nam\nparameter (delim = ' +-*/^:=,()[]')\ntype (mp_real) res(ntmpx), t1, t2\n! type (mp_real) t300\nexternal lnblk, lcase\n\n! t300 = 1.d300\n\n! Handle the five basic arithmetic operations.\n\n! write (6, *) 'oper input: ix, iasgn, symbol =', ix, iasgn, delim(ix+1:ix+1)\n! write (6, *) 'nres, res array =', nres\n! write (6, '(1p,d20.10)') (dble(min(max(res(i),-t300),t300)), i=1,nres)\n\nif (ix == 0) then\n if (nres <= 0) goto 100\n res(nres) = - res(nres)\n goto 200\nelseif (ix == 1) then\n if (nres <= 1) goto 100\n t1 = res(nres-1) + res(nres)\n nres = nres - 1\n res(nres) = t1\n goto 200\nelseif (ix == 2) then\n if (nres <= 1) goto 100\n t1 = res(nres-1) - res(nres)\n nres = nres - 1\n res(nres) = t1\n goto 200\nelseif (ix == 3) then\n if (nres <= 1) goto 100\n t1 = res(nres-1) * res(nres)\n nres = nres - 1\n res(nres) = t1\n goto 200\nelseif (ix == 4) then\n if (nres <= 1) goto 100\n t1 = res(nres-1) / res(nres)\n nres = nres - 1\n res(nres) = t1\n goto 200\nelseif (ix == 5) then\n if (nres <= 1) goto 100\n t1 = aint (res(nres))\n if (t1 == res(nres) .and. abs (t1) < 1.d9) then\n k = t1\n t1 = res(nres-1) ** k\n else\n t1 = res(nres-1) ** res(nres)\n endif\n nres = nres - 1\n res(nres) = t1\n goto 200\nelseif (ix == 6 .or. ix == 7) then\n\n! Assignment.\n\n if (nres <= 1 .or. nres > 2) then\n goto 100\n elseif (iasgn <= 0) then\n write (6, 1) iasgn\n1 format ('oper: illegal assignment; iasgn =',i3)\n nerror = 41\n elseif (iasgn <= nvara + nvarb) then\n write (6, 2) varn(iasgn)\n2 format ('oper: illegal assignment to reserved name = ',a)\n nerror = 42\n elseif (iasgn <= nvara + nvarb + nvarc) then\n\n! Variable is one of the special names: Debug, Digits, Epsilon, etc.\n\n nam = lcase (varn(iasgn))\n lnm = lnblk (nam)\n t1 = res(2)\n if (abs (t1) > 1.d6) then\n write (6, 3) varn(iasgn)(1:lnm)\n3 format ('oper: improper value assigned to ',a)\n nerror = 43\n goto 200\n endif\n var(iasgn) = res(2)\n nres = 0\n k1 = dble (var(iasgn))\n\n select case (nam)\n case ('debug')\n if (k1 < 0 .or. k1 > 10) then\n write (6, 4) 0, 10\n4 format ('oper: improper value assigned to Debug; min, max =',2i8)\n nerror = 44\n goto 200\n endif\n ndebug = k1\n var(iasgn) = dble (ndebug)\n case ('digits')\n if (k1 < 30 .or. k1 > ndigmx1) then\n write (6, 5) 30, ndigmx1\n5 format ('oper: improper value assigned to Digits; min, max =',2i8)\n nerror = 45\n goto 200\n elseif (k1 > ndigits1 .and. nvar > nvara + nvarb + nvarc) then\n write (6, 6)\n6 format ('oper: user variables should be recalculated before use.')\n endif\n ndigits1 = k1\n var(iasgn) = dble (ndigits1)\n call mpsetprec (ndigits1)\n mpoud = ndigits1\n ndigits2 = min (2 * ndigits1, ndigmx2)\n nepsilon1 = - ndigits1\n nepsilon2 = - ndigits2\n nquadl = int (log (dble (ndigits1)) / log (2.d0))\n call mpsetprec (ndigits2)\n call mpgetprecwords (nwords2)\n call mpsetprec (ndigits1)\n call mpgetprecwords (nwords1)\n\n do i = nvara + nvarb + 1, nvara + nvarb + nvarc\n if (varn(i) == 'Digits2') then\n var(i) = dble (ndigits2)\n elseif (varn(i) == 'Epsilon') then\n var(i) = dble (nepsilon1)\n elseif (varn(i) == 'Epsilon2') then\n var(i) = dble (nepsilon2)\n elseif (varn(i) == 'Quadlevel') then\n var(i) = dble (nquadl)\n endif\n enddo\n\n write (6, 7) ndigits1, ndigits2, nepsilon1, nepsilon2, nquadl\n7 format ('oper: Digits changed to ',i5/'Digits2 changed to ',i5/ &\n 'Epsilon changed to ',i5/'Epsilon2 changed to ',i5/ &\n 'Quadlevel changed to ',i2)\n case ('digits2')\n if (k1 < 30 .or. k1 > ndigmx2) then\n write (6, 25) 30, ndigmx2\n25 format ('oper: improper value assigned to Digits2; min, max =',2i8)\n nerror = 53\n goto 200\n endif\n ndigits2 = k1\n var(iasgn) = dble (ndigits2)\n nepsilon2 = - ndigits2\n call mpsetprec (ndigits2)\n call mpgetprecwords (nwords2)\n call mpsetprec (ndigits1)\n\n do i = nvara + nvarb + 1, nvara + nvarb + nvarc\n if (varn(i) == 'Epsilon2') var(i) = dble (nepsilon2)\n enddo\n\n write (6, 27) ndigits2, nepsilon2\n27 format ('oper: digits2 changed to ',i5/'epsilon2 changed to ',i5)\n case ('epsilon')\n if (k1 > -10) then\n write (6, 8) -10\n8 format ('oper: improper value assigned to Epsilon; max =',i8)\n nerror = 46\n goto 200\n elseif (k1 < - ndigits1) then\n write (6, 9) ndigits1\n9 format ('oper: warning - Epsilon exceeds -Digits; Digits =',i5)\n endif\n nepsilon1 = k1\n var(iasgn) = dble (nepsilon1)\n case ('epsilon2')\n if (k1 > -10) then\n write (6, 8) k1\n28 format ('oper: improper value assigned to Epsilon2; max =',i8)\n nerror = 54\n goto 200\n elseif (k1 < - ndigits2) then\n write (6, 9) ndigits2\n29 format ('oper: warning - Epsilon2 exceeds -Digits2; Digits2 =',i5)\n endif\n nepsilon2 = k1\n var(iasgn) = dble (nepsilon2)\n case ('pslqbound')\n if (k1 < 1 .or. k1 > 1000) then\n write (6, 10) 1, 1000\n10 format ('oper: improper value assigned to Pslqbound; min, max =',2i8)\n nerror = 47\n goto 200\n endif\n npslqb = k1\n var(iasgn) = dble (npslqb)\n case ('pslqlevel')\n if (k1 < 1 .or. k1 > 3) then\n write (6, 11) 1, 3\n11 format ('oper: improper value assigned to Pslqlevel; min, max =',2i8)\n nerror = 48\n goto 200\n endif\n npslql = k1\n var(iasgn) = dble (npslql)\n case ('quadlevel')\n if (k1 < 2 .or. k1 > nquadx) then\n write (6, 12) 2, nquadx\n12 format ('oper: improper value assigned to QuadLevel; min, max =',2i8)\n nerror = 49\n goto 200\n endif\n nquadl = k1\n var(iasgn) = dble (nquadl)\n case ('quadtype')\n if (k1 < 1 .or. k1 > 3) then\n write (6, 13) 1, 3\n13 format ('oper: improper value assigned to Quadtype; min, max =',2i8)\n nerror = 50\n goto 200\n endif\n nquadt = k1\n var(iasgn) = dble (nquadt)\n if (ndebug > 0) write (6, 14) quadn(k1)\n14 format ('New quadrature type: ',a)\n if (k1 == 1) then\n open (11, file = 'quadgs.dat', form = 'unformatted')\n elseif (k1 == 2) then\n open (11, file = 'quaderf.dat', form = 'unformatted')\n elseif (k1 == 3) then\n open (11, file = 'quadts.dat', form = 'unformatted')\n else\n write (6, 15)\n15 format ('oper: impossible case; please contact author.')\n stop\n endif\n rewind (11)\n read (11, end = 110) nq3\n read (11, end = 110) (quadwk(i), i = -1, nq3)\n read (11, end = 110) (quadxk(i), i = -1, nq3)\n case default\n goto 100\n end select\n goto 200\n elseif (iasgn <= nvar) then\n var(iasgn) = res(2)\n nres = 0\n goto 200\n else\n write (6, 1) iasgn\n nerror = 51\n endif\n goto 200\nelse\n goto 100\nendif\n\n100 continue\n\nwrite (6, 16) ix, nres\n16 format ('oper: stack error or assignment error; ix, nres =',2i4,';'/&\n 'please contact author.')\nstop\n\n110 continue\n\nwrite (6, 17)\n17 format (&\n 'End-of-file encountered when reading quadrature data. Most likely the'/ &\n 'quadrature type selected has not been initialized. Select another type.')\nnerror = 52\n\n200 continue\n\ncall mpgetpar ('mpier', ierror)\nif (ierror > 0) nerror = ierror + 1000\n\n! write (6, *) 'oper exit:'\n! write (6, *) 'nres, res array =', nres\n! write (6, '(1p,d20.10)') (dble(min(max(res(i),-t300),t300)), i=1,nres)\n\n210 continue\n\nreturn\nend\n\nrecursive subroutine evalfun (ix, string, tmp, nvalue, value)\n\n! This evaluates function references.\n\nuse mpmodule\nuse globdata\nimplicit none\ninteger i, idb, iq, ix, izeta(100), k, k1, k2, lnblk, ierror, ntmp, nvalue\ncharacter*16 lcase, nam\ncharacter*2048 string, stx1\ntype (mp_real) binomial, factorial, qinteg, qsum, tmp(ntmpx), t1, t2, t3, &\n value(ntmpx), zetap, zetaz\nexternal binomial, factorial, lcase, lnblk, qinteg, qsum, zetap, zetaz\n\n! write (6, *) 'evalfun: enter; ix, name =', ix, funn(ix)\n! write (6, *) 'string =', string(1:64)\n\nnvalue = 1\nnam = lcase (funn(ix))\n\nif (nam /= 'polyroot' .and. nam /= 'integrate' .and. nam /= 'sum' &\n .and. nam /= 'table') then\n call parse (string, ntmp, tmp)\n if (nerror > 0) goto 300\n if (ntmp /= narg(ix) .and. narg(ix) /= 1000) then\n write (6, 1) nam, narg(ix)\n1 format ('parse: wrong number of arguments for function ',a,i2)\n nerror = 61\n goto 300\n endif\nendif\n\nselect case (nam)\ncase ('abs')\n value(1) = abs (tmp(1))\ncase ('arccos')\n value(1) = acos (tmp(1))\ncase ('arcsin')\n value(1) = asin (tmp(1))\ncase ('arctan')\n value(1) = atan (tmp(1))\ncase ('arctan2')\n value(1) = atan2 (tmp(1), tmp(2))\ncase ('bessel')\n value(1) = bessel (tmp(1))\ncase ('besselexp')\n value(1) = besselexp (tmp(1))\ncase ('binomial')\n value(1) = binomial (tmp(1), tmp(2))\ncase ('cos')\n value(1) = cos (tmp(1))\ncase ('erf')\n value(1) = erf (tmp(1))\ncase ('exp')\n value(1) = exp (tmp(1))\ncase ('factorial')\n value(1) = factorial (tmp(1))\ncase ('gamma')\n value(1) = gamma (tmp(1))\ncase ('integrate')\n value(1) = qinteg (string, tmp(1))\ncase ('log')\n value(1) = log (tmp(1))\ncase ('max')\n value(1) = max (tmp(1), tmp(2))\ncase ('min')\n value(1) = min (tmp(1), tmp(2))\ncase ('polyroot')\n call polyroot (string, tmp(1), nvalue, value)\ncase ('pslq')\n call qpslq (ntmp, tmp(1), string, value)\n nvalue = ntmp\ncase ('result')\n k = dble (tmp(1))\n if (k <= 0 .or. k > mxres) then\n write (6, 3) dble (tmp(1)), mxres\n3 format ('evalfun: illegal argument to Result =',1pd15.6/ &\n 'Must be integer between zero and ',i4)\n nerror = 62\n goto 300\n endif\n value(1) = result(k)\ncase ('sin')\n value(1) = sin (tmp(1))\ncase ('sqrt')\n value(1) = sqrt (tmp(1))\ncase ('sum')\n value(1) = qsum (string, tmp(1))\ncase ('table')\n call table (string, tmp(1), nvalue, value)\ncase ('tan')\n value(1) = tan (tmp(1))\ncase ('zeta')\n do i = 1, ntmp\n t1 = tmp(i)\n if (i > 1 .or. t1 > 100.d0 .or. t1 /= aint (t1)) then\n write (6, 4) 1, 100\n4 format ('evalfun: improper argument to Zeta; integer, min, max =',2i8)\n call mpwrite (6, t1)\n nerror = 63\n goto 300\n endif\n izeta(i) = t1\n enddo\n\n nvalue = 1\n value(1) = zetaz (ntmp, izeta)\n if (nerror > 0) goto 300\ncase ('zetap')\n do i = 1, ntmp\n t1 = tmp(i)\n if (t1 > 100.d0 .or. t1 /= aint (t1)) then\n write (6, 5) 100\n5 format ('evalfun: improper argument to Zetap; integer, max =',i8)\n call mpwrite (6, t1)\n nerror = 64\n goto 300\n endif\n izeta(i) = t1\n enddo\n\n nvalue = 1\n value(1) = zetap (ntmp, izeta)\n if (nerror > 0) goto 300\ncase ('zetaz')\n do i = 1, ntmp\n t1 = tmp(i)\n if (t1 > 100.d0 .or. t1 /= aint (t1)) then\n write (6, 6) 100\n6 format ('evalfun: improper argument to Zetaz; integer, max =',i8)\n call mpwrite (6, t1)\n nerror = 65\n goto 300\n endif\n izeta(i) = t1\n enddo\n\n nvalue = 1\n value(1) = zetaz (ntmp, izeta)\n if (nerror > 0) goto 300\ncase default\n if (ix <= nfuna) then\n write (6, 7) \n7 format ('evalfun: impossible case; contact author.')\n stop\n endif\n\n! Evaluate one of the user-defined functions.\n\n stx1 = fund(ix)\n\n do i = 1, ntmp\n var(i+nvara) = tmp(i)\n enddo\n\n call parse (stx1, nvalue, value)\n if (nerror > 0) goto 300\nend select\n\ncall mpgetpar ('mpier', ierror)\nif (ierror > 0) nerror = ierror + 1000\n\n300 continue\n\n! write (6, *) 'evalfun: exit; nvalue, value array =', nvalue\n! write (6, '(1p,4d19.12)') (dble (value(i)), i = 1, nvalue)\n\nreturn\nend\n \nfunction binomial (a1, a2)\n\n! This evaluates the binomial function. Computation is accelerated by\n! accumulating products in double precision before updating the multiprecision\n! value.\n\nuse mpmodule\nuse globdata\ntype (mp_real) a1, a2, binomial, t1, t2, t3\nreal*8 d1, d2, t53\nparameter (t53 = 2.d0 ** 53)\ninteger i, k1, k2, n1, n2\n\nif (a1 == 0.d0 .and. a2 == 0.d0) then\n binomial = 1.d0\n goto 100\nelseif (a1 < 1.d0 .or. a1 > 1.d5 .or. a1 /= aint (a1) .or. a2 < 1.d0 &\n .or. a2 > 1.d5 .or. a2 /= aint (a2) .or. a2 > a1) then\n call decmd (a1, d1, n1)\n call decmd (a2, d2, n2)\n write (6, 1) d1, n1, d2, n2\n1 format ('binomial: improper arguments; values =', &\n f10.6,' x 10^',i5,3x,f10.6,'x 10^',i5)\n nerror = 71\n goto 100\nendif\n\nk1 = a1\nk2 = min (a2, a1 - a2)\nt1 = 1.d0\nd1 = 1.d0\n\ndo k = 1, k2\n d2 = (k1 + 1 - k) * d1\n if (d2 > t53) then\n t1 = d1 * t1\n d2 = k1 + 1 - k\n endif\n d1 = d2\nenddo\n\nt1 = d1 * t1\nd1 = 1.d0\n\ndo k = 1, k2\n d2 = k * d1\n if (d2 > t53) then\n t1 = t1 / d1\n d2 = k\n endif\n d1 = d2\nenddo\n\nbinomial = t1 / d1\n\n100 continue\n\n! write (6, *) 'binomial: exit'\n\nreturn\nend\n\nfunction factorial (a1)\n\n! This evaluates the factorial function. Computation is accelerated by\n! accumulating products in double precision before updating the multiprecision\n! value.\n\nuse mpmodule\nuse globdata\ntype (mp_real) a1, factorial, t1, t2, t3\nreal*8 d1, d2, t53\nparameter (t53 = 2.d0 ** 53)\ninteger i, k1, n1\n\n! write (6, *) 'factorial: enter'\n\nif (a1 == 0.d0) then\n factorial = 1.d0\n goto 100\nelseif (a1 < 1.d0 .or. a1 > 1.d5 .or. a1 /= aint (a1)) then\n call decmd (a1, d1, n1)\n write (6, 1) d1, n1\n1 format ('factorial: improper argument; value =', &\n f10.6,' x 10^',i5,3x,f10.6,'x 10^',i5)\n nerror = 81\n goto 100\nendif\n\nk1 = anint (a1)\nt1 = 1.d0\nd1 = 1.d0\n\ndo k = 1, k1\n d2 = k * d1\n if (d2 > t53) then\n t1 = d1 * t1\n d2 = k\n endif\n d1 = d2\nenddo\n\nfactorial = d1 * t1\n\n100 continue\n\n! write (6, *) 'factorial: exit'\n\nreturn\nend\n\nrecursive subroutine polyroot (string, tmp1, nvalue, value)\n\n! This handles calls to polyroot, which finds real or complex roots of\n! polynomials.\n\nuse mpmodule\nuse globdata\nimplicit none\ninteger i, j, k, k1, k2, lnblk, lstr, lx1, lx2, ierror, ntmp1, ntmp2, nr, nvalue\ncharacter*2048 string, stx1, stx2\ntype (mp_real) tmp1(ntmpx), tmp2(ntmpx), t1, value(ntmpx)\nexternal lcase, lnblk\n\n! write (6, *) 'polyroot: enter, string ='\n! write (6, '(a)') string(1:76)\n\nlstr = lnblk (string)\n\n! Look for starting value braces.\n\nk = index (string, '{')\nif (k == 0) goto 300\ncall findbraces (k, string, k1, k2)\nif (nerror > 0) goto 300\nif (k1 == 0) goto 200\n\n! Find comma before braces.\n\ndo i = k - 1, 1, -1\n if (string(i:i) /= ' ') then\n if (string(i:i) == ',') then\n goto 100\n else\n goto 200\n endif\n endif\nenddo\n\ngoto 200\n\n100 continue\n\nstx1 = string(1:i-1)\nlx1 = lnblk (stx1)\ncall parse (stx1, ntmp1, tmp1)\nif (nerror > 0) goto 300\n\n! write (6, *) 'polyroot: coefficients ='\n! write (6, '(1p,4d19.11)') (dble (tmp1(i)), i = 1, ntmp1)\n\n! Find starting value(s).\n\nstx2 = string(k1+1:k2-1)\nlx2 = lnblk (stx2)\ncall parse (stx2, ntmp2, tmp2)\nif (nerror > 0) goto 300\nif (ntmp2 == 0 .or. ntmp2 > 2) goto 200\n\n! write (6, *) 'polyroot: starting value(s) ='\n! write (6, '(1p,2d25.15)') (dble (tmp2(i)), i = 1, ntmp2)\n\n! Find root, real or complex according to ntmp2 = 1 or 2.\n\nif (ntmp2 == 1) then\n call rroot (ntmp1 - 1, tmp2(1), tmp1, nr, value)\n if (nerror > 0) goto 250\n nvalue = 1\nelse\n call croot (ntmp1 - 1, tmp2(1), tmp1, nr, value)\n if (nerror > 0) goto 250\n nvalue = 2\nendif\n\ngoto 300\n\n200 continue\n\nwrite (6, 5)\n5 format ('polyroot: syntax error in arguments to polyroot.'/ &\n 'Examples: \"polyroot[1, -1, -1, {0.618}]\" (real root of 1-x-x^2=0 near 0.618)'/&\n '\"polyroot[1, 1, 1, {-0.5, 0.866}]\" (complex root of 1+x+x^2 near .5+.866i)')\nnerror = 91\ngoto 300\n\n250 continue\n\nwrite (6, 6)\n6 format ('polyroot: root not found')\nnerror = 92\n\n300 continue\n\n! write (6, *) 'polyroot: exit'\n\nreturn\nend\n\nsubroutine qpslq (n, x, str, r)\n\n! This handles calls to pslq.\n\nuse mpmodule\nuse globdata\nimplicit none\ninteger i, i1, i2, j, k, ks, k1, k2, k3, lnblk, lstr, n, nsq, iq, lnamx(ntmpx), &\n nstring1\nparameter (nstring1 = 1024)\ncharacter*1 string1(nstring1)\ncharacter*60 nam1, nam2, namx(ntmpx)\ncharacter*2048 str, str1\ntype (mp_real) t300, x(n), r(n)\nreal*8 d1, d2, dplog10q, gam, rb\nparameter (nsq = 8, gam = 1.1547005438d0)\ninteger is0(3*n)\nreal*8 s1(7*n*n+nsq*n+3*n)\ntype (mp_real) s2(3*n*n+nsq*n+2*n)\nexternal dplog10q, lnblk\n\nt300 = 1.d300\nrb = npslqb\nif (npslql == 1) then\n call pslqm1 (ndebug, gam, n, nsq, rb, x, is0, s1, s2, iq, r)\nelseif (npslql == 2) then\n call pslqm2 (ndebug, gam, n, nsq, rb, x, is0, s1, s2, iq, r)\nelseif (npslql == 3) then\n write (6, *) 'qpslq: 3-level PSLQ not available yet.'\n iq = 0\nendif\nif (iq == 0) then\n write (6, 1) \n1 format ('evalfun: integer relation not found.')\n nerror = 101\nelseif (ndebug > 0) then\n write (6, 2)\n2 format ('Relation: 0 =')\n k = 0\n ks = 0\n lstr = lnblk (str)\n\n! Parse the string to identify each term.\n\n do j = 1, n\n\n100 continue\n\n k = k + 1\n if (k > lstr) then\n goto 110\n elseif (str(k:k) == ',') then\n goto 110\n elseif (str(k:k) == '(') then\n call findpars (k, str, k1, k2)\n k = k2\n goto 100\n elseif (str(k:k) == '[') then\n call findbrackets (k, str, k1, k2)\n k = k2\n goto 100\n elseif (str(k:k) == '{') then\n call findbraces (k, str, k1, k2)\n k = k2\n goto 100\n else\n goto 100\n endif\n\n110 continue\n if (k - 1 < ks + 1) goto 120\n nam1 = str(ks+1:k-1)\n k1 = k - ks - 1\n ks = k\n nam2 = ' '\n k2 = 0\n\n do i = 1, k1\n if (nam1(i:i) /= ' ') then\n k2 = k2 + 1\n nam2(k2:k2) = nam1(i:i)\n endif\n enddo\n\n lnamx(j) = k2\n namx(j) = nam2\n enddo\n\n if (k <= lstr) goto 120\n goto 200\n\n120 continue\n\n! Parsing failed -- construct a series of simple names, e.g. pslqnnn.\n\n do j = 1, n\n lnamx(j) = 7\n write (nam1, '(i3.3)') j\n namx(j) = 'pslq'//nam1(1:3)\n enddo\n\n200 continue\n\n! Find the length, in digits, of the largest r(j).\n\n d1 = 0.d0\n\n do j = 1, n\n if (r(j) == 0.d0) then\n d2 = 1.d0\n else\n d2 = 1.d0 + abs (dplog10q (r(j)))\n endif\n d1 = max (d1, d2)\n enddo\n\n k1 = min (int (d1 + 3.d0), nstring1)\n\n! Convert each r(j) to decimal (Fortran F format), then append * and name.\n! Output resulting string in 80-character blocks (almost always it will be\n! less than 80 characters total).\n\n do j = 1, n\n call mpfform (r(j), k1, 0, string1)\n k2 = lnamx(j)\n str1 = '+'\n\n do i = 1, k1\n str1(i+1:i+1) = string1(i)\n enddo\n\n str1(k1+2:k1+3) = '* '\n str1(k1+4:k1+k2+3) = namx(j)(1:k2)\n \n do i1 = 1, k1 + k2 + 3, 80\n i2 = min (i1 + 79, k1 + k2 + 3)\n write (6, '(80a1)') (str1(i:i), i = i1, i2)\n enddo\n enddo\nendif\nreturn\nend\n\nrecursive function qinteg (string, tmp1)\n\n! This handles calls to integrate (numerical quadrature).\n\nuse mpmodule\nuse globdata\nimplicit none\ninteger i, i1, i2, i3, j, k, kvar, k1, k2, lnam1, lnblk, lstr, lr1, lr2, &\n lx1, lx2, lx3, ntmp1\ncharacter*2048 string, stx1, stx2, stx3\ncharacter*16 lcase, nam1, str1, str2\ncharacter*27 alphal, alphau\ncharacter*10 digits\nparameter (digits = '0123456789', &\n alphal = 'abcdefghijklmnopqrstuvwxyz_', &\n alphau = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_')\ntype (mp_real) qinteg, quad, tmp1(ntmpx), t1, t2, t3, x1, x2\ntype (mp_real) t300\nexternal lcase, lnblk, quad\n\nt300 = 1.d300\n\n! write (6, *) 'qinteg: enter, string ='\n! write (6, '(a)') string(1:76)\n\nqinteg = 0.d0\nk = 0\nlstr = lnblk (string)\n\n! Look for function definition.\n\n100 continue\n\nk = k + 1\nif (k > lstr) then\n goto 200\nelseif (string(k:k) == '[') then\n call findbrackets (k, string, k1, k2)\n if (nerror > 0) goto 300\n k = k2\n goto 100\nelseif (string(k:k) == '(') then\n call findpars (k, string, k1, k2)\n if (nerror > 0) goto 300\n k = k2\n goto 100\nelseif (string(k:k) == ',') then\n goto 110\nelse\n goto 100\nendif\n\n110 continue\n\nstx1 = string(1:k-1)\nlx1 = lnblk (stx1)\n\n! write (6, *) 'qinteg: stx1 ='\n! write (6, '(a)') stx1(1:lx1)\n\n! Look for variable of integration and limits of integration.\n\nk = k + 1\ncall findbraces (k, string, k1, k2)\nif (nerror > 0) goto 300\nif (k1 == 0) goto 200\nk = k1 + 1\n\ndo i = k, lstr\n if (string(i:i) /= ' ') goto 120\nenddo\n\n120 continue\n\nk = i\nk1 = k + index (string(k+1:k2-1), ',')\nif (k1 <= k) goto 200\nlnam1 = lnblk (string(k:k1-1))\nif (lnam1 > 16) goto 200\nnam1 = string(k:k1-1)\n\ndo i = 1, lnam1\n i1 = index (alphal, nam1(i:i))\n i2 = index (alphau, nam1(i:i))\n i3 = index (digits, nam1(i:i))\n if (i == 1 .and. i1 + i2 == 0 .or. i1 + i2 + i3 == 0) goto 200\nenddo\n\ndo i = 1, nvar\n if (lcase (nam1) == lcase (varn(i))) goto 130\nenddo\n\nif (nvar + 1 > nvarx) then\n write (6, 1) nvarz\n1 format ('qinteg: too many user variables; max =',i5)\n nerror = 111\n goto 300\nendif\nnvar = nvar + 1\ni = nvar\nvarn(i) = nam1\n\n130 continue\n\nkvar = i\nstx2 = string(k1+1:k2-1)\nlx2 = lnblk (stx2)\n \n! write (6, *) 'qinteg: before parse; stx2 =', stx2(1:lx2)\n\ncall mpsetprecwords (nwords2)\ncall parse (stx2, ntmp1, tmp1)\nif (nerror > 0) goto 300\nif (ntmp1 /= 2) goto 200\nx1 = tmp1(1)\nx2 = tmp1(2)\ncall mpsetprec (nwords1)\n\n! write (6, *) 'x1, x2 =', dble(min(max(x1,-t300),t300)), &\n! dble(min(max(x2,-t300),t300))\n\n! Perform quadrature.\n\nif (x2 <= x1) then\n qinteg = 0.d0\nelseif (x1 > - mplrg .and. x2 < mplrg) then\n\n! Neither limit is infinite.\n\n t1 = quad (kvar, stx1, x1, x2, tmp1)\n if (nerror > 0) goto 300\n qinteg = t1\nelse\n\n! Handle cases when one or both of the limits is infinite.\n\n str1 = varn(kvar)\n lr1 = lnblk (str1)\n lr2 = lnblk (varn(kvar))\n str2 = '(1/' // varn(kvar)(1:lr2) // ')'\n lr2 = lnblk (str2)\n call replace (str1, str2, stx1, stx2)\n lx2 = lnblk (stx2)\n stx3 = '(' // stx2(1:lx2) // ')/' // str1(1:lr1) // '^2'\n lx3 = lnblk (stx3)\n\n if (x1 > 0.d0 .and. x2 == mplrg) then\n x2 = 1.d0 / x1\n x1 = 0.d0\n t1 = quad (kvar, stx3, x1, x2, tmp1)\n if (nerror > 0) goto 300\n qinteg = t1\n elseif (x1 <= 0.d0 .and. x1 > -mplrg .and. x2 == mplrg) then\n x2 = 1.d0\n t1 = quad (kvar, stx1, x1, x2, tmp1)\n if (nerror > 0) goto 300\n x1 = 0.d0\n x2 = 1.d0\n t2 = quad (kvar, stx3, x1, x2, tmp1)\n if (nerror > 0) goto 300\n qinteg = t1 + t2\n elseif (x1 == -mplrg .and. x2 < 0.d0) then\n x1 = 1.d0 / x2\n x2 = 0.d0\n t1 = quad (kvar, stx3, x1, x2, tmp1)\n if (nerror > 0) goto 300\n qinteg = t1\n elseif (x1 == -mplrg .and. x2 >= 0.d0 .and. x2 < mplrg) then\n x1 = -1.d0\n t1 = quad (kvar, stx1, x1, x2, tmp1)\n if (nerror > 0) goto 300\n x2 = -1.d0\n x1 = 0.d0\n t2 = quad (kvar, stx3, x1, x2, tmp1)\n if (nerror > 0) goto 300\n qinteg = t1 + t2\n elseif (x1 == -mplrg .and. x2 == mplrg) then\n x1 = -1.d0\n x2 = 1.d0\n t1 = quad (kvar, stx1, x1, x2, tmp1)\n if (nerror > 0) goto 300\n x1 = -1.d0\n x2 = 0.d0\n t2 = quad (kvar, stx3, x1, x2, tmp1)\n if (nerror > 0) goto 300\n x1 = 0.d0\n x2 = 1.d0\n t3 = quad (kvar, stx3, x1, x2, tmp1)\n if (nerror > 0) goto 300\n qinteg = t1 + t2 + t3\n endif\nendif\ngoto 300\n \n200 continue\n\nwrite (6, 2)\n2 format ('qinteg: syntax error in arguments to integrate.'/ &\n 'Example of proper call: \"integrate[cos[x]*exp[-x], {x, 0, 1}]\"')\nnerror = 112\n\n300 continue\n\nreturn\nend\n\nfunction quad (kvar, stx1, x1, x2, tmp1)\nuse mpmodule\nuse globdata\nimplicit none\ninteger kvar\ncharacter*2048 stx1\ntype (mp_real) quad, quadgs, quaderf, quadts, tmp1(ntmpx), x1, x2\nexternal quadgs, quaderf, quadts\n\nif (nquadt == 1) then\n quad = quadgs (kvar, stx1, x1, x2, tmp1, nquadl, nquadz, quadwk, quadxk)\nelseif (nquadt == 2) then\n quad = quaderf (kvar, stx1, x1, x2, tmp1, nquadl, nquadz, quadwk, quadxk)\nelseif (nquadt == 3) then\n quad = quadts (kvar, stx1, x1, x2, tmp1, nquadl, nquadz, quadwk, quadxk)\nelse\n write (6, *) 'quad: impossible case; contact author'\n stop\nendif\nreturn\nend\n\nrecursive function qsum (string, tmp1)\n\n! This handles calls to sum (numerical summation).\n\nuse mpmodule\nuse globdata\nimplicit none\ninteger i, i1, i2, i3, j, k, kvar, k1, k2, lnam1, lnblk, lstr, lx1, lx2, &\n ierror, ntmp1\ncharacter*2048 string, stx1, stx2\ncharacter*16 lcase, nam1\ncharacter*27 alphal, alphau\ncharacter*10 digits\nparameter (digits = '0123456789', &\n alphal = 'abcdefghijklmnopqrstuvwxyz_', &\n alphau = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_')\nreal*8 d1, d2\ntype (mp_real) eps, qsum, tmp1(ntmpx), t1, t2, t3\nexternal lcase, lnblk\n\n! write (6, *) 'qsum: enter, string ='\n! write (6, '(a)') string(1:76)\n\nqsum = 0.d0\nk = 0\nlstr = lnblk (string)\n\n! Look for function definition.\n\n100 continue\n\nk = k + 1\nif (k > lstr) then\n goto 200\nelseif (string(k:k) == '[') then\n call findbrackets (k, string, k1, k2)\n if (nerror > 0) goto 300\n k = k2\n goto 100\nelseif (string(k:k) == '(') then\n call findpars (k, string, k1, k2)\n if (nerror > 0) goto 300\n k = k2\n goto 100\nelseif (string(k:k) == ',') then\n goto 110\nelse\n goto 100\nendif\n\n110 continue\n\nstx1 = string(1:k-1)\nlx1 = lnblk (stx1)\n\n! write (6, *) 'qsum: stx1 ='\n! write (6, '(a)') stx1(1:lx1)\n\n! Look for index of summation and limits of summation.\n\nk = k + 1\ncall findbraces (k, string, k1, k2)\nif (nerror > 0) goto 300\nif (k1 == 0) goto 200\nk = k1 + 1\n\ndo i = k, lstr\n if (string(i:i) /= ' ') goto 120\nenddo\n\ngoto 200\n\n120 continue\n\nk = i\nk1 = k + index (string(k+1:k2-1), ',')\nif (k1 <= k) goto 200\nlnam1 = lnblk (string(k:k1-1))\nif (lnam1 > 16) goto 200\nnam1 = string(k:k1-1)\n\ndo i = 1, lnam1\n i1 = index (alphal, nam1(i:i))\n i2 = index (alphau, nam1(i:i))\n i3 = index (digits, nam1(i:i))\n if (i == 1 .and. i1 + i2 == 0 .or. i1 + i2 + i3 == 0) goto 200\nenddo\n\ndo i = 1, nvar\n if (lcase (nam1) == lcase (varn(i))) goto 130\nenddo\n\nif (nvar + 1 > nvarx) then\n write (6, 1) nvarz\n1 format ('qsum: too many user variables; max =',i5)\n nerror = 121\n goto 300\nendif\nnvar = nvar + 1\ni = nvar\nvarn(i) = nam1\n\n130 continue\n\nkvar = i\nstx2 = string(k1+1:k2-1)\nlx2 = lnblk (stx2)\n\n! write (6, *) 'qsum: before parse; stx2 =', stx2(1:lx2)\n\ncall parse (stx2, ntmp1, tmp1)\n\n! write (6, *) 'qsum: after parse'\n\nif (nerror > 0) goto 300\nif (ntmp1 /= 2) goto 200\n\nd1 = min (max (tmp1(1), mpreal (-1.d300)), mpreal (1.d300))\nd2 = min (max (tmp1(2), mpreal (-1.d300)), mpreal (1.d300))\n\nif (abs (d1) >= 1.d9 .or. abs (d2) >= 1.d9 .and. d2 < 1.d300 .or. &\n d1 /= anint (d1) .or. d2 /= anint (d2) .and. d2 < 1.d300) then\n write (6, 2) d1, d2\n2 format ('qsum: improper limits of sum; values =',1p,2d25.15)\n nerror = 122\n goto 300\nendif\n\nk1 = anint (d1)\nk2 = anint (min (d2, 1.d9))\nt1 = 0.d0\nj = 0\neps = mpreal (10.d0) ** nepsilon1\n\n! write (6, *) 'k1, k2 =', k1, k2\n\n! Perform summation.\n\ndo k = k1, k2\n\n! write (6, *) 'qsum: before call to parse; k =', k\n\n var(kvar) = k\n call parse (stx1, ntmp1, tmp1(1))\n call mpgetpar ('mpier', ierror)\n if (ierror > 0 .or. nerror > 0) goto 300\n if (ntmp1 > 1) then\n write (6, 3)\n3 format ('qsum: function returns more than one value per call.')\n nerror = 123\n goto 300\n endif\n t1 = t1 + tmp1(1)\n \n! write (6, *) 'qsum: after call to parse; tmp1 =', dble (tmp1(1))\n\n! For infinite sums, check for convergence (ten consecutive terms < eps).\n\n if (k2 == 1000000000) then\n if (abs (tmp1(1)) < eps) then\n j = j + 1\n if (j == 10) goto 140\n else\n j = 0\n endif\n endif\nenddo\n\n140 continue\n\nqsum = t1\ngoto 300\n \n200 continue\n\nwrite (6, 5)\n5 format ('qsum: syntax error in arguments to sum.'/ &\n 'Example of proper call: \"sum[n/(1+2^n), {n, 0, Infinity}]\"')\nnerror = 124\n\n300 continue\n\n! write (6, *) 'qsum: exit'\n\nreturn\nend\n\nrecursive subroutine table (string, tmp1, nvalue, value)\n\n! This handles calls to table, which forms lists.\n\nuse mpmodule\nuse globdata\nimplicit none\ninteger i, i1, i2, i3, j, k, kvar, k1, k2, lnam1, lnblk, lstr, lx1, lx2, &\n ierror, ntmp1, nvalue\ncharacter*2048 string, stx1, stx2\ncharacter*16 lcase, nam1\ncharacter*27 alphal, alphau\ncharacter*10 digits\nparameter (digits = '0123456789', &\n alphal = 'abcdefghijklmnopqrstuvwxyz_', &\n alphau = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_')\nreal*8 d1, d2\ntype (mp_real) tmp1(ntmpx), t1, value(ntmpx)\nexternal lcase, lnblk\n\n! write (6, *) 'table: enter, string ='\n! write (6, '(a)') string(1:76)\n\nk = 0\nlstr = lnblk (string)\n\n! Look for function definition.\n\n100 continue\n\nk = k + 1\nif (k > lstr) then\n goto 200\nelseif (string(k:k) == '[') then\n call findbrackets (k, string, k1, k2)\n if (nerror > 0) goto 300\n k = k2\n goto 100\nelseif (string(k:k) == '(') then\n call findpars (k, string, k1, k2)\n if (nerror > 0) goto 300\n k = k2\n goto 100\nelseif (string(k:k) == ',') then\n goto 110\nelse\n goto 100\nendif\n\n110 continue\n\nstx1 = string(1:k-1)\nlx1 = lnblk (stx1)\n\n! write (6, *) 'table: stx1 ='\n! write (6, '(a)') stx1(1:lx1)\n\n! Look for index of table and limits of table.\n\nk = k + 1\ncall findbraces (k, string, k1, k2)\nif (nerror > 0) goto 300\nif (k1 == 0) goto 200\nk = k1 + 1\n\ndo i = k, lstr\n if (string(i:i) /= ' ') goto 120\nenddo\n\ngoto 200\n\n120 continue\n\nk = i\nk1 = k + index (string(k+1:k2-1), ',')\nif (k1 <= k) goto 200\nlnam1 = lnblk (string(k:k1-1))\nif (lnam1 > 16) goto 200\nnam1 = string(k:k1-1)\n\ndo i = 1, lnam1\n i1 = index (alphal, nam1(i:i))\n i2 = index (alphau, nam1(i:i))\n i3 = index (digits, nam1(i:i))\n if (i == 1 .and. i1 + i2 == 0 .or. i1 + i2 + i3 == 0) goto 200\nenddo\n\ndo i = 1, nvar\n if (lcase (nam1) == lcase (varn(i))) goto 130\nenddo\n\nif (nvar + 1 > nvarx) then\n write (6, 1) nvarz\n1 format ('table: too many user variables; max =',i5)\n nerror = 131\n goto 300\nendif\nnvar = nvar + 1\ni = nvar\nvarn(i) = nam1\n\n130 continue\n\nkvar = i\nstx2 = string(k1+1:k2-1)\nlx2 = lnblk (stx2)\n\n! write (6, *) 'table: before parse; stx2 =', stx2(1:lx2)\n\ncall parse (stx2, ntmp1, tmp1)\n\n! write (6, *) 'table: after parse'\n\nif (nerror > 0) goto 300\nif (ntmp1 /= 2) goto 200\n\nd1 = min (max (tmp1(1), mpreal (-1.d300)), mpreal (1.d300))\nd2 = min (max (tmp1(2), mpreal (-1.d300)), mpreal (1.d300))\n\nif (abs (d1) > 1.d9 .or. abs (d2) > 1.d9) then\n write (6, 2) d1, d2\n2 format ('table: index limit is too large; values =',1p,2d25.15)\n nerror = 132\n goto 300\nendif\n\nk1 = anint (d1)\nk2 = anint (d2)\nif (k2 - k1 + 1 > ntmpx) then\n write (6, 3) ntmpx\n3 format ('table: too many elements in list; max =',i4)\n nerror = 133\n goto 300\nendif\ni = 0\n\n! Form list.\n\ndo k = k1, k2\n\n! write (6, *) 'table: before call to parse; k =', k\n\n var(kvar) = k\n call parse (stx1, ntmp1, tmp1(1))\n call mpgetpar ('mpier', ierror)\n if (ierror > 0 .or. nerror > 0) goto 300\n if (ntmp1 > 1) then\n write (6, 4)\n4 format ('table: function returns more than one value per call.')\n nerror = 134\n goto 300\n endif\n \n! write (6, *) 'table: after call to parse; t1 =', dble (t1)\n\n i = i + 1\n value(i) = tmp1(1)\nenddo\n\nnvalue = i\n\ngoto 300\n \n200 continue\n\nwrite (6, 5)\n5 format ('table: syntax error in arguments to table.'/ &\n 'Example of proper call: \"table[alpha^n, {n, 0, 10}]\"')\nnerror = 135\n\n300 continue\n\n! write (6, *) 'table: exit'\n\nreturn\nend\n\nfunction lnblk (string)\n\n! This finds the index of the last non-blank character in string.\n\ninteger i, lnblk\ncharacter*(*) string\n\ndo i = len (string), 1, -1\n if (string(i:i) .ne. ' ') goto 110\nenddo\n\ni = 0\n\n110 continue\n\nlnblk = i\nreturn\nend\n\nfunction lcase (string)\n\n! This converts string to lower case.\n\ninteger i, k\ncharacter*16 string, lcase\ncharacter*27 alphal, alphau\nparameter (alphal = 'abcdefghijklmnopqrstuvwxyz%', &\n alphau = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ%')\n\nlcase = string\n\ndo i = 1, 16\n k = index (alphau, string(i:i))\n if (k > 0) lcase(i:i) = alphal(k:k)\nenddo\n\nreturn\nend\n\nsubroutine findbraces (k, string, k1, k2)\n\n! This routine finds a set of matching braces beginning at position k\n! in string. The positions are returned in k1 and k2.\n\nuse globdata\nimplicit none\ninteger i1, i2, j, k, k1, k2, k3, lnblk, lstr\ncharacter*2048 string\nexternal lnblk\n\ni1 = 0\ni2 = 0\nk1 = 0\nk2 = 0\nlstr = lnblk (string)\n\ndo j = k, lstr\n if (string(j:j) == '{') then\n i1 = i1 + 1\n i2 = 1\n if (i1 == 1) k1 = j\n elseif (string(j:j) == '}') then\n i1 = i1 - 1\n i2 = 1\n if (i1 == 0) then\n k2 = j\n goto 200\n elseif (i1 < 0) then\n write (6, 1) \n1 format ('findbraces: mismatched right brace.')\n nerror = 141\n goto 200\n endif\n elseif (i2 == 0 .and. string(j:j) /= ' ') then\n goto 200\n endif\nenddo\n\nif (i1 > 0) then\n write (6, 2) \n2 format ('findbraces: mismatched left brace.')\n nerror = 142\nendif\n\n200 continue\n\nreturn\nend\n\nsubroutine findbrackets (k, string, k1, k2)\n\n! This routine finds a set of matching brackets beginning at position k\n! in string. The positions are returned in k1 and k2.\n\nuse globdata\nimplicit none\ninteger i1, i2, j, k, k1, k2, k3, lnblk, lstr\ncharacter*2048 string\nexternal lnblk\n\ni1 = 0\ni2 = 0\nk1 = 0\nk2 = 0\nlstr = lnblk (string)\n\ndo j = k, lstr\n if (string(j:j) == '[') then\n i1 = i1 + 1\n i2 = 1\n if (i1 == 1) k1 = j\n elseif (string(j:j) == ']') then\n i1 = i1 - 1\n i2 = 1\n if (i1 == 0) then\n k2 = j\n goto 200\n elseif (i1 < 0) then\n write (6, 1) \n1 format ('findbrackets: mismatched right bracket.')\n nerror = 151\n goto 200\n endif\n elseif (i2 == 0 .and. string(j:j) /= ' ') then\n goto 200\n endif\nenddo\n\nif (i1 > 0) then\n write (6, 2) \n2 format ('findbrackets: mismatched left bracket.')\n nerror = 152\nendif\n\n200 continue\n\nreturn\nend\n\nsubroutine findpars (k, string, k1, k2)\n\n! This routine finds a set of matching parentheses beginning at position k\n! in string. The positions are returned in k1 and k2.\n\nuse globdata\nimplicit none\ninteger i1, i2, j, k, k1, k2, k3, lnblk, lstr\ncharacter*2048 string\nexternal lnblk\n\ni1 = 0\ni2 = 0\nk1 = 0\nk2 = 0\nlstr = lnblk (string)\n\ndo j = k, lstr\n if (string(j:j) == '(') then\n i1 = i1 + 1\n i2 = 1\n if (i1 == 1) k1 = j\n elseif (string(j:j) == ')') then\n i1 = i1 - 1\n i2 = 1\n if (i1 == 0) then\n k2 = j\n goto 200\n elseif (i1 < 0) then\n write (6, 1) \n1 format ('findpars: mismatched right parenthesis.')\n nerror = 161\n goto 200\n endif\n elseif (i2 == 0 .and. string(j:j) /= ' ') then\n goto 200\n endif\nenddo\n\nif (i1 > 0) then\n write (6, 2) \n2 format ('findpars: mismatched left parenthesis.')\n nerror = 162\nendif\n\n200 continue\n\nreturn\nend\n\nsubroutine replace (str1, str2, stx1, stx2)\n\n! This routine replaces string str1 with str2 in stx1, returning stx2,\n! provided str1 is delimited by one of the characters in delim.\n\nimplicit none\ninteger i, j, k, koff, lnblk, lr1, lr2, lx1, lx2\ncharacter*16 str1, str2\ncharacter*2048 stx1, stx2\ncharacter*27 alphal, alphau\ncharacter*11 digits\ncharacter*13 delim\nparameter ( &\n alphal = 'abcdefghijklmnopqrstuvwxyz%', &\n alphau = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ%', &\n digits = '0123456789.', delim = ' +-*/^:=,()[]')\nexternal lnblk\n\nlr1 = lnblk (str1)\nlr2 = lnblk (str2)\nlx1 = lnblk (stx1)\nlx2 = lx1\nstx2 = stx1\nk = 0\nkoff = 0\n\n100 continue\n\nif (k > lx1) goto 200\ni = index (stx1(k:lx1), str1(1:lr1))\nif (i == 0) goto 200\nj = i + k - 1\n\nif (j == 1) then\n if (j + lr1 - 1 == lx1 .or. index (delim, stx1(j+lr1:j+lr1)) > 0) then\n goto 110\n endif\nelseif (index (delim, stx1(j-1:j-1)) > 0 .and. (j + lr1 - 1 == lx1 .or. &\n index (delim, stx1(j+lr1:j+lr1)) > 0)) then\n goto 110\nendif\nk = j + lr1\ngoto 100\n\n110 continue\n\nstx2 = stx2(1:j-1+koff) // str2(1:lr2) // stx2(j+lr1+koff:lx2)\nkoff = koff + (lr2 - lr1)\nlx2 = lx2 + (lr2 - lr1)\nk = j + lr1\ngoto 100\n\n200 continue\n\nreturn\nend\n\nfunction dplog10q (a)\n\n! For input MP value a, this routine returns a DP approximation to log10 (a).\n\nuse mpmodule\nimplicit none\ninteger ia\ndouble precision da, dplog10q, t1\ntype (mp_real) a\n\ncall mpmdc (a%mpr, da, ia)\nif (da .eq. 0.d0) then\n dplog10q = -9999.d0\nelse\n dplog10q = log10 (abs (da)) + ia * log10 (2.d0)\nendif\n\n100 continue\nreturn\nend\n", "meta": {"hexsha": "436f9f90b878c76aa48612429a43dfd525373899", "size": 63416, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "MPFUN90/mpfun90/toolkit/mathtool.f90", "max_stars_repo_name": "paveloom-p/P3", "max_stars_repo_head_hexsha": "57df3b6263db81685f137a7ed9428dbd3c1b4a5b", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MPFUN90/mpfun90/toolkit/mathtool.f90", "max_issues_repo_name": "paveloom-p/P3", "max_issues_repo_head_hexsha": "57df3b6263db81685f137a7ed9428dbd3c1b4a5b", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MPFUN90/mpfun90/toolkit/mathtool.f90", "max_forks_repo_name": "paveloom-p/P3", "max_forks_repo_head_hexsha": "57df3b6263db81685f137a7ed9428dbd3c1b4a5b", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.0347463516, "max_line_length": 82, "alphanum_fraction": 0.5837012741, "num_tokens": 24995, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569016, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.6621862136275001}} {"text": "MODULE unit_test_acc_parallel\n#define rstd 8\n\nimplicit none\ncontains\n SUBROUTINE print_time(title, T1, T2, iter)\n character(len = 3) :: title\n ! Time measurement\n real :: T1, T2\n integer :: iter\n print *, \"///\",title, \"///////////////////\"\n print *, \" total:\", T2-T1\n print *, \" iter:\", ITER\n print *, \"average:\", (T2-T1)/ITER\n print *, \"/////////////////////////\"\n \n END SUBROUTINE print_time\n\n SUBROUTINE compute_cpu(io_data)\n REAL(rstd), INTENT(INOUT), DIMENSION(:,:,:) :: io_data\n integer:: i, j, k\n REAL(rstd) :: A(3,3), a11,a12,a13,a21,a22,a23,a31,a32,a33\n REAL(rstd) :: x1,x2,x3\n do i = 1, SIZE(io_data, 1)\n do j = 1, SIZE(io_data, 2)\n do k = 1, SIZE(io_DATA, 3) \n A(1,1)=i; A(1,2)=j; A(1,3)=k\n A(2,1)=j; A(2,2)=j; A(2,3)=k\n A(3,1)=k; A(3,2)=k; A(3,3)=k\n\n! CALL determinant(A(1,1),A(2,1),A(3,1),A(1,2),A(2,2),A(3,2),A(1,3),A(2,3),A(3,3),det) \n a11=A(1,1) ; a12=A(2,1) ; a13=A(3,1)\n a21=A(1,2) ; a22=A(2,2) ; a23=A(3,2)\n a31=A(1,3) ; a32=A(2,3) ; a33=A(3,3)\n \n x1 = a11 * (a22 * a33 - a23 * a32)\n x2 = a12 * (a21 * a33 - a23 * a31)\n x3 = a13 * (a21 * a32 - a22 * a31)\n io_data(i,j,k) = x1 - x2 + x3\n\n !print*, \"(i, j, k): \", i, j, k\n end do\n end do\n end do\n END SUBROUTINE compute_cpu\n\n SUBROUTINE compute_dir(io_data, ondevice)\n REAL(rstd), INTENT(INOUT), DIMENSION(:,:,:) :: io_data\n integer:: i, j, k\n LOGICAL, value :: ondevice\n REAL(rstd) :: A(3,3), a11,a12,a13,a21,a22,a23,a31,a32,a33\n REAL(rstd) :: x1,x2,x3\n !$omp target teams distribute parallel do simd collapse(3) private(A) nowait if(ondevice) !FAIL\n! !$omp target teams distribute parallel do simd collapse(3) private(A) nowait !PASS\n do i = 1, SIZE(io_data, 1)\n do j = 1, SIZE(io_data, 2)\n do k = 1, SIZE(io_DATA, 3)\n A(1,1)=i; A(1,2)=j; A(1,3)=k\n A(2,1)=j; A(2,2)=j; A(2,3)=k\n A(3,1)=k; A(3,2)=k; A(3,3)=k\n\n! CALL determinant(A(1,1),A(2,1),A(3,1),A(1,2),A(2,2),A(3,2),A(1,3),A(2,3),A(3,3),det) \n a11=A(1,1) ; a12=A(2,1) ; a13=A(3,1)\n a21=A(1,2) ; a22=A(2,2) ; a23=A(3,2)\n a31=A(1,3) ; a32=A(2,3) ; a33=A(3,3)\n \n x1 = a11 * (a22 * a33 - a23 * a32)\n x2 = a12 * (a21 * a33 - a23 * a31)\n x3 = a13 * (a21 * a32 - a22 * a31)\n io_data(i,j,k) = x1 - x2 + x3\n !print*, \"(i, j, k): \", i, j, k\n end do\n end do\n end do\n !$omp end target teams distribute parallel do\n END SUBROUTINE compute_dir\nEND MODULE unit_test_acc_parallel\n\n\nprogram unit_test_1\n#define WARM 10\n#define ITER 100\n#define i_len 50\n#define j_len 50\n#define k_len 50\nuse unit_test_acc_parallel\n\nimplicit none\n REAL(rstd) :: io_data(i_len, j_len, k_len)\n REAL(rstd) :: io_data_dir(i_len, j_len, k_len)\n integer:: i, j, k\n double precision :: error\n double precision, parameter :: error_max = 1.0d-10\n double precision :: speedup = 0\n real :: T1 = 0, T2 = 0\n\n do i = 1, WARM\n! CALL compute_cpu(io_data)\n end do\n\n call cpu_time(T1)\n do i = 1, ITER\n CALL compute_cpu(io_data)\n end do\n call cpu_time(T2)\n\n speedup = T2-T1 \n call print_time(\"CPU\", T1, T2, ITER)\n\n !$omp target data map(tofrom: io_data_dir)\n do i = 1, WARM\n CALL compute_dir(io_data_dir, .TRUE.)\n end do\n\n call cpu_time(T1)\n do i = 1, ITER\n CALL compute_dir(io_data_dir, .TRUE.)\n end do\n call cpu_time(T2)\n !$omp taskwait\n call print_time(\"GPU\", T1, T2, ITER)\n !$omp end target data\n\n speedup = speedup / (T2-T1)\n print *,\"\\n speedup ratio:\", speedup\n\n ! Verification\n do i = 1, i_len\n do j = 1, j_len\n do k = 1, k_len\n error = abs(io_data_dir(i,j,k) - io_data(i,j,k))\n if( error .gt. error_max ) then\n write(*,*) \"Accuracy Verification FAILED! Error bigger than max! Error = \", error, \" i = \", i, \" j = \", j,\" io_data_dir = \",&\n io_data_dir(i,j,k), \" y = \", io_data(i,j,k)\n call exit(1)\n endif\n end do\n end do\n end do\n write(*,*) \"Accuracy Verification PASSED!\"\nend program unit_test_1\n", "meta": {"hexsha": "f7bdcac1eb875a9ceebdfdc0d65f52b43de171da", "size": 4457, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/smoke/flang-273807/flang-273807.f90", "max_stars_repo_name": "raramakr/aomp", "max_stars_repo_head_hexsha": "9a224fe01ca8eff4209b8b79aa1fa15a18da65db", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 106, "max_stars_repo_stars_event_min_datetime": "2019-02-05T13:07:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T11:15:03.000Z", "max_issues_repo_path": "test/smoke/flang-273807/flang-273807.f90", "max_issues_repo_name": "raramakr/aomp", "max_issues_repo_head_hexsha": "9a224fe01ca8eff4209b8b79aa1fa15a18da65db", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 195, "max_issues_repo_issues_event_min_datetime": "2019-02-26T23:42:40.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T10:08:19.000Z", "max_forks_repo_path": "test/smoke/flang-273807/flang-273807.f90", "max_forks_repo_name": "raramakr/aomp", "max_forks_repo_head_hexsha": "9a224fe01ca8eff4209b8b79aa1fa15a18da65db", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 27, "max_forks_repo_forks_event_min_datetime": "2019-05-17T10:33:28.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-25T16:17:48.000Z", "avg_line_length": 31.3873239437, "max_line_length": 140, "alphanum_fraction": 0.5043751402, "num_tokens": 1635, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199714402812, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.6621639870804492}} {"text": " function RP2(m_N, tau, taup, term, j_chi, coupling_Array)\n implicit none\n double precision :: RP2, m_N, j_chi\n double precision :: coupling_Array(14,2)\n integer :: tau,taup\n integer :: term\n integer :: c, q2, q4\n double precision :: c3, c3p\n double precision :: c12, c12p\n double precision :: c15, c15p\nc\n c = 0\n q2 = 2\n q4 = 4\nc\n c3 = coupling_Array(2,tau)\n c3p = coupling_Array(2,taup)\n c12 = coupling_Array(11,tau)\n c12p = coupling_Array(11,taup)\n c15 = coupling_Array(14,tau)\n c15p = coupling_Array(14,taup)\nc\n if (term.eq.c) then\n RP2 = (j_chi*(j_chi+1))/12. * c12*c12p\n else if (term.eq.q2) then\n RP2 = 1/m_N**2 * (1/4. * c3*c3p +\n & (j_chi*(j_chi+1))/12. * (-c12*c15p-c15*c12p)) \n else if (term.eq.q4) then\n RP2 = 1/m_N**4 * (j_chi*(j_chi+1))/12. * c15*c15p\n else\n RP2 = 0.\n end if\nc\n end function RP2\n", "meta": {"hexsha": "b279fd4f57f77378fd50c2d807b72926ef83abd9", "size": 976, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Rfunctions/RP2.f", "max_stars_repo_name": "Laen111/captnoper", "max_stars_repo_head_hexsha": "f90c75d3bf8725895f729be5671059da3b9c38c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-09-15T07:43:03.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-18T08:31:43.000Z", "max_issues_repo_path": "Rfunctions/RP2.f", "max_issues_repo_name": "Laen111/captnoper", "max_issues_repo_head_hexsha": "f90c75d3bf8725895f729be5671059da3b9c38c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 15, "max_issues_repo_issues_event_min_datetime": "2020-11-03T05:21:31.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-25T20:06:40.000Z", "max_forks_repo_path": "Rfunctions/RP2.f", "max_forks_repo_name": "Laen111/captnoper", "max_forks_repo_head_hexsha": "f90c75d3bf8725895f729be5671059da3b9c38c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-17T03:32:34.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-17T03:32:34.000Z", "avg_line_length": 27.8857142857, "max_line_length": 63, "alphanum_fraction": 0.5430327869, "num_tokens": 358, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067276593032, "lm_q2_score": 0.7025300573952054, "lm_q1q2_score": 0.6621393054778575}} {"text": " subroutine setrot(ang1,ang2,ang3,anis1,anis2,ind,MAXROT,rotmat)\r\n!-----------------------------------------------------------------------\r\n!\r\n! Sets up an Anisotropic Rotation Matrix\r\n! **************************************\r\n!\r\n! Sets up the matrix to transform cartesian coordinates to coordinates\r\n! accounting for angles and anisotropy (see manual for a detailed\r\n! definition):\r\n!\r\n!\r\n! INPUT PARAMETERS:\r\n!\r\n! ang1 Azimuth angle for principal direction\r\n! ang2 Dip angle for principal direction\r\n! ang3 Third rotation angle\r\n! anis1 First anisotropy ratio\r\n! anis2 Second anisotropy ratio\r\n! ind matrix indicator to initialize\r\n! MAXROT maximum number of rotation matrices dimensioned\r\n! rotmat rotation matrices\r\n!\r\n!\r\n! NO EXTERNAL REFERENCES\r\n!\r\n!\r\n!-----------------------------------------------------------------------\r\n parameter(DEG2RAD=3.141592654/180.0,EPSLON=1.e-20)\r\n real*8 rotmat(MAXROT,3,3),afac1,afac2,sina,sinb,sint, &\r\n cosa,cosb,cost\r\n!\r\n! Converts the input angles to three angles which make more\r\n! mathematical sense:\r\n!\r\n! alpha angle between the major axis of anisotropy and the\r\n! E-W axis. Note: Counter clockwise is positive.\r\n! beta angle between major axis and the horizontal plane.\r\n! (The dip of the ellipsoid measured positive down)\r\n! theta Angle of rotation of minor axis about the major axis\r\n! of the ellipsoid.\r\n!\r\n if(ang1.ge.0.0.and.ang1.lt.270.0) then\r\n alpha = (90.0 - ang1) * DEG2RAD\r\n else\r\n alpha = (450.0 - ang1) * DEG2RAD\r\n endif\r\n beta = -1.0 * ang2 * DEG2RAD\r\n theta = ang3 * DEG2RAD\r\n!\r\n! Get the required sines and cosines:\r\n!\r\n sina = dble(sin(alpha))\r\n sinb = dble(sin(beta))\r\n sint = dble(sin(theta))\r\n cosa = dble(cos(alpha))\r\n cosb = dble(cos(beta))\r\n cost = dble(cos(theta))\r\n!\r\n! Construct the rotation matrix in the required memory:\r\n!\r\n afac1 = 1.0 / dble(max(anis1,EPSLON))\r\n afac2 = 1.0 / dble(max(anis2,EPSLON))\r\n rotmat(ind,1,1) = (cosb * cosa)\r\n rotmat(ind,1,2) = (cosb * sina)\r\n rotmat(ind,1,3) = (-sinb)\r\n rotmat(ind,2,1) = afac1*(-cost*sina + sint*sinb*cosa)\r\n rotmat(ind,2,2) = afac1*(cost*cosa + sint*sinb*sina)\r\n rotmat(ind,2,3) = afac1*( sint * cosb)\r\n rotmat(ind,3,1) = afac2*(sint*sina + cost*sinb*cosa)\r\n rotmat(ind,3,2) = afac2*(-sint*cosa + cost*sinb*sina)\r\n rotmat(ind,3,3) = afac2*(cost * cosb)\r\n!\r\n! Return to calling program:\r\n!\r\n return\r\n end\r\n", "meta": {"hexsha": "9d2e607cee53e5d4b0f908720ebb292e9976c737", "size": 2755, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/legacy/gslib/setrot.f90", "max_stars_repo_name": "exepulveda/gslib2.0", "max_stars_repo_head_hexsha": "5c021000eb3da8703ced3ee9be145d6c0ecb2608", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-07-09T06:03:38.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T11:11:19.000Z", "max_issues_repo_path": "src/legacy/gslib/setrot.f90", "max_issues_repo_name": "exepulveda/gslib2.0", "max_issues_repo_head_hexsha": "5c021000eb3da8703ced3ee9be145d6c0ecb2608", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/legacy/gslib/setrot.f90", "max_forks_repo_name": "exepulveda/gslib2.0", "max_forks_repo_head_hexsha": "5c021000eb3da8703ced3ee9be145d6c0ecb2608", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.7792207792, "max_line_length": 73, "alphanum_fraction": 0.5361161525, "num_tokens": 766, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067276593032, "lm_q2_score": 0.702530051167069, "lm_q1q2_score": 0.662139299607797}} {"text": "program midpoint_error\n implicit none\n integer :: i, N, k\n real :: x, t, h, k1\n real, external :: f\n\n do k=0,10 \n N = 2**k\n h = 1. / N\n\n x = 1.\n do i=1,N\n t = (i - 1) * h\n k1 = f(x, t)\n x = x + h * f(x + k1 * h / 2, t + h / 2)\n end do\n write(*,*)h,abs(x - exp(1. * (1. + 2.) / 2))\n end do\nend program\n\nreal function f(x, t)\n implicit none\n real, intent(in) :: x, t\n\n f = x * (1 + t)\nend function\n", "meta": {"hexsha": "8b45c7f1eebd04ca08acfcd0e14f183cc45cd61f", "size": 498, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lec04/midpoint-error.f90", "max_stars_repo_name": "rekka/intro-fortran-2016", "max_stars_repo_head_hexsha": "72310e04254bde150e78609eef74158620f2fa72", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-05T01:54:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T01:54:57.000Z", "max_issues_repo_path": "lec04/midpoint-error.f90", "max_issues_repo_name": "rekka/intro-fortran-2016", "max_issues_repo_head_hexsha": "72310e04254bde150e78609eef74158620f2fa72", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lec04/midpoint-error.f90", "max_forks_repo_name": "rekka/intro-fortran-2016", "max_forks_repo_head_hexsha": "72310e04254bde150e78609eef74158620f2fa72", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-06-22T12:39:34.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-25T04:45:37.000Z", "avg_line_length": 18.4444444444, "max_line_length": 52, "alphanum_fraction": 0.3975903614, "num_tokens": 192, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206870747657, "lm_q2_score": 0.7341195385342971, "lm_q1q2_score": 0.6621175985898632}} {"text": "*DECK CPPCO\n SUBROUTINE CPPCO (AP, N, RCOND, Z, INFO)\nC***BEGIN PROLOGUE CPPCO\nC***PURPOSE Factor a complex Hermitian positive definite matrix stored\nC in packed form and estimate the condition number of the\nC matrix.\nC***LIBRARY SLATEC (LINPACK)\nC***CATEGORY D2D1B\nC***TYPE COMPLEX (SPPCO-S, DPPCO-D, CPPCO-C)\nC***KEYWORDS CONDITION NUMBER, LINEAR ALGEBRA, LINPACK,\nC MATRIX FACTORIZATION, PACKED, POSITIVE DEFINITE\nC***AUTHOR Moler, C. B., (U. of New Mexico)\nC***DESCRIPTION\nC\nC CPPCO factors a complex Hermitian positive definite matrix\nC stored in packed form and estimates the condition of the matrix.\nC\nC If RCOND is not needed, CPPFA is slightly faster.\nC To solve A*X = B , follow CPPCO by CPPSL.\nC To compute INVERSE(A)*C , follow CPPCO by CPPSL.\nC To compute DETERMINANT(A) , follow CPPCO by CPPDI.\nC To compute INVERSE(A) , follow CPPCO by CPPDI.\nC\nC On Entry\nC\nC AP COMPLEX (N*(N+1)/2)\nC the packed form of a Hermitian matrix A . The\nC columns of the upper triangle are stored sequentially\nC in a one-dimensional array of length N*(N+1)/2 .\nC See comments below for details.\nC\nC N INTEGER\nC the order of the matrix A .\nC\nC On Return\nC\nC AP an upper triangular matrix R , stored in packed\nC form, so that A = CTRANS(R)*R .\nC If INFO .NE. 0 , the factorization is not complete.\nC\nC RCOND REAL\nC an estimate of the reciprocal condition of A .\nC For the system A*X = B , relative perturbations\nC in A and B of size EPSILON may cause\nC relative perturbations in X of size EPSILON/RCOND .\nC If RCOND is so small that the logical expression\nC 1.0 + RCOND .EQ. 1.0\nC is true, then A may be singular to working\nC precision. In particular, RCOND is zero if\nC exact singularity is detected or the estimate\nC underflows. If INFO .NE. 0 , RCOND is unchanged.\nC\nC Z COMPLEX(N)\nC a work vector whose contents are usually unimportant.\nC If A is singular to working precision, then Z is\nC an approximate null vector in the sense that\nC NORM(A*Z) = RCOND*NORM(A)*NORM(Z) .\nC If INFO .NE. 0 , Z is unchanged.\nC\nC INFO INTEGER\nC = 0 for normal return.\nC = K signals an error condition. The leading minor\nC of order K is not positive definite.\nC\nC Packed Storage\nC\nC The following program segment will pack the upper\nC triangle of a Hermitian matrix.\nC\nC K = 0\nC DO 20 J = 1, N\nC DO 10 I = 1, J\nC K = K + 1\nC AP(K) = A(I,J)\nC 10 CONTINUE\nC 20 CONTINUE\nC\nC***REFERENCES J. J. Dongarra, J. R. Bunch, C. B. Moler, and G. W.\nC Stewart, LINPACK Users' Guide, SIAM, 1979.\nC***ROUTINES CALLED CAXPY, CDOTC, CPPFA, CSSCAL, SCASUM\nC***REVISION HISTORY (YYMMDD)\nC 780814 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890831 Modified array declarations. (WRB)\nC 890831 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900326 Removed duplicate information from DESCRIPTION section.\nC (WRB)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE CPPCO\n INTEGER N,INFO\n COMPLEX AP(*),Z(*)\n REAL RCOND\nC\n COMPLEX CDOTC,EK,T,WK,WKM\n REAL ANORM,S,SCASUM,SM,YNORM\n INTEGER I,IJ,J,JM1,J1,K,KB,KJ,KK,KP1\n COMPLEX ZDUM,ZDUM2,CSIGN1\n REAL CABS1\n CABS1(ZDUM) = ABS(REAL(ZDUM)) + ABS(AIMAG(ZDUM))\n CSIGN1(ZDUM,ZDUM2) = CABS1(ZDUM)*(ZDUM2/CABS1(ZDUM2))\nC\nC FIND NORM OF A\nC\nC***FIRST EXECUTABLE STATEMENT CPPCO\n J1 = 1\n DO 30 J = 1, N\n Z(J) = CMPLX(SCASUM(J,AP(J1),1),0.0E0)\n IJ = J1\n J1 = J1 + J\n JM1 = J - 1\n IF (JM1 .LT. 1) GO TO 20\n DO 10 I = 1, JM1\n Z(I) = CMPLX(REAL(Z(I))+CABS1(AP(IJ)),0.0E0)\n IJ = IJ + 1\n 10 CONTINUE\n 20 CONTINUE\n 30 CONTINUE\n ANORM = 0.0E0\n DO 40 J = 1, N\n ANORM = MAX(ANORM,REAL(Z(J)))\n 40 CONTINUE\nC\nC FACTOR\nC\n CALL CPPFA(AP,N,INFO)\n IF (INFO .NE. 0) GO TO 180\nC\nC RCOND = 1/(NORM(A)*(ESTIMATE OF NORM(INVERSE(A)))) .\nC ESTIMATE = NORM(Z)/NORM(Y) WHERE A*Z = Y AND A*Y = E .\nC THE COMPONENTS OF E ARE CHOSEN TO CAUSE MAXIMUM LOCAL\nC GROWTH IN THE ELEMENTS OF W WHERE CTRANS(R)*W = E .\nC THE VECTORS ARE FREQUENTLY RESCALED TO AVOID OVERFLOW.\nC\nC SOLVE CTRANS(R)*W = E\nC\n EK = (1.0E0,0.0E0)\n DO 50 J = 1, N\n Z(J) = (0.0E0,0.0E0)\n 50 CONTINUE\n KK = 0\n DO 110 K = 1, N\n KK = KK + K\n IF (CABS1(Z(K)) .NE. 0.0E0) EK = CSIGN1(EK,-Z(K))\n IF (CABS1(EK-Z(K)) .LE. REAL(AP(KK))) GO TO 60\n S = REAL(AP(KK))/CABS1(EK-Z(K))\n CALL CSSCAL(N,S,Z,1)\n EK = CMPLX(S,0.0E0)*EK\n 60 CONTINUE\n WK = EK - Z(K)\n WKM = -EK - Z(K)\n S = CABS1(WK)\n SM = CABS1(WKM)\n WK = WK/AP(KK)\n WKM = WKM/AP(KK)\n KP1 = K + 1\n KJ = KK + K\n IF (KP1 .GT. N) GO TO 100\n DO 70 J = KP1, N\n SM = SM + CABS1(Z(J)+WKM*CONJG(AP(KJ)))\n Z(J) = Z(J) + WK*CONJG(AP(KJ))\n S = S + CABS1(Z(J))\n KJ = KJ + J\n 70 CONTINUE\n IF (S .GE. SM) GO TO 90\n T = WKM - WK\n WK = WKM\n KJ = KK + K\n DO 80 J = KP1, N\n Z(J) = Z(J) + T*CONJG(AP(KJ))\n KJ = KJ + J\n 80 CONTINUE\n 90 CONTINUE\n 100 CONTINUE\n Z(K) = WK\n 110 CONTINUE\n S = 1.0E0/SCASUM(N,Z,1)\n CALL CSSCAL(N,S,Z,1)\nC\nC SOLVE R*Y = W\nC\n DO 130 KB = 1, N\n K = N + 1 - KB\n IF (CABS1(Z(K)) .LE. REAL(AP(KK))) GO TO 120\n S = REAL(AP(KK))/CABS1(Z(K))\n CALL CSSCAL(N,S,Z,1)\n 120 CONTINUE\n Z(K) = Z(K)/AP(KK)\n KK = KK - K\n T = -Z(K)\n CALL CAXPY(K-1,T,AP(KK+1),1,Z(1),1)\n 130 CONTINUE\n S = 1.0E0/SCASUM(N,Z,1)\n CALL CSSCAL(N,S,Z,1)\nC\n YNORM = 1.0E0\nC\nC SOLVE CTRANS(R)*V = Y\nC\n DO 150 K = 1, N\n Z(K) = Z(K) - CDOTC(K-1,AP(KK+1),1,Z(1),1)\n KK = KK + K\n IF (CABS1(Z(K)) .LE. REAL(AP(KK))) GO TO 140\n S = REAL(AP(KK))/CABS1(Z(K))\n CALL CSSCAL(N,S,Z,1)\n YNORM = S*YNORM\n 140 CONTINUE\n Z(K) = Z(K)/AP(KK)\n 150 CONTINUE\n S = 1.0E0/SCASUM(N,Z,1)\n CALL CSSCAL(N,S,Z,1)\n YNORM = S*YNORM\nC\nC SOLVE R*Z = V\nC\n DO 170 KB = 1, N\n K = N + 1 - KB\n IF (CABS1(Z(K)) .LE. REAL(AP(KK))) GO TO 160\n S = REAL(AP(KK))/CABS1(Z(K))\n CALL CSSCAL(N,S,Z,1)\n YNORM = S*YNORM\n 160 CONTINUE\n Z(K) = Z(K)/AP(KK)\n KK = KK - K\n T = -Z(K)\n CALL CAXPY(K-1,T,AP(KK+1),1,Z(1),1)\n 170 CONTINUE\nC MAKE ZNORM = 1.0\n S = 1.0E0/SCASUM(N,Z,1)\n CALL CSSCAL(N,S,Z,1)\n YNORM = S*YNORM\nC\n IF (ANORM .NE. 0.0E0) RCOND = YNORM/ANORM\n IF (ANORM .EQ. 0.0E0) RCOND = 0.0E0\n 180 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "6b4fdb830c244bc2e2360f72ee0ff6239305f208", "size": 7894, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/cppco.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/cppco.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/cppco.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.1680672269, "max_line_length": 71, "alphanum_fraction": 0.4963263238, "num_tokens": 2700, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9019206870747657, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6621175933433392}} {"text": "! file: bratu2df90.f90\n! to build a Python module, use this:\n! $$ f2py -m bratu2df90 -c bratu2df90.f90\n\nsubroutine bratu2d (m, n, alpha, x, f)\n !f2py intent(hide) :: m = shape(x,0)\n !f2py intent(hide) :: n = shape(x,1)\n integer :: m, n\n real(kind=8) :: alpha\n real(kind=8), intent(in), target :: x(m,n)\n real(kind=8), intent(inout) :: f(m,n)\n real(kind=8) :: hx, hy\n real(kind=8), pointer, &\n dimension(:,:) :: u, uN, uS, uE, uW\n ! setup 5-points stencil\n u => x(2:m-1, 2:n-1) ! center\n uN => x(2:m-1, 1:n-2) ! north\n uS => x(2:m-1, 3:n ) ! south\n uW => x(1:m-2, 2:n-1) ! west\n uE => x(3:m, 2:n-1) ! east\n ! compute nonlinear function\n hx = 1.0/(m-1) ! x grid spacing\n hy = 1.0/(n-1) ! y grid spacing\n f(:,:) = x\n f(2:m-1, 2:n-1) = &\n (2*u - uE - uW) * (hy/hx) &\n + (2*u - uN - uS) * (hx/hy) &\n - alpha * exp(u) * (hx*hy)\nend subroutine bratu2d\n", "meta": {"hexsha": "df2a21407b266f0eee363d924d4c0f452e94132b", "size": 946, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "demo/bratu2d/bratu2df90.f90", "max_stars_repo_name": "underworldcode/petsc4py", "max_stars_repo_head_hexsha": "fdfdd79be39b8cbe95cf57010f29a6cb2ef463a6", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-11T05:00:53.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-11T05:00:53.000Z", "max_issues_repo_path": "demo/bratu2d/bratu2df90.f90", "max_issues_repo_name": "underworldcode/petsc4py", "max_issues_repo_head_hexsha": "fdfdd79be39b8cbe95cf57010f29a6cb2ef463a6", "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": "demo/bratu2d/bratu2df90.f90", "max_forks_repo_name": "underworldcode/petsc4py", "max_forks_repo_head_hexsha": "fdfdd79be39b8cbe95cf57010f29a6cb2ef463a6", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.5333333333, "max_line_length": 44, "alphanum_fraction": 0.4957716702, "num_tokens": 410, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206738932334, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6621175836665188}} {"text": "module mf_tools\n\n double precision, parameter :: pi=3.141592653589793\n\ncontains\n\n!***************************************************\n\n subroutine calcmf(f,m,npix,mf,numin,dnu,nbin)\n\n!***************************************************\n\n implicit none\n\n integer :: n,umpix,ib,nb\n integer, intent(in) :: npix,nbin\n real, pointer :: m(:)\n double precision, pointer :: f(:,:)\n double precision, intent(in) :: numin,dnu\n double precision, intent(out) :: mf(nbin,0:2)\n double precision :: u0,u1,u2,u11,u12,u22,g2,nu,b,numax\n\n numax=numin+dnu*nbin\n mf=0.d0\n umpix=0\n \n do n=1,npix\n if (m(n)==0.) cycle\n umpix=umpix+1\n \n u0=f(n,1)\n u1=f(n,2)\n u2=f(n,3)\n u11=f(n,4)\n u12=f(n,5)\n u22=f(n,6)\n\n g2=u1*u1+u2*u2\n\n if (u0numax) then\n do nb=1,nbin\n mf(nb,0)=mf(nb,0)+1\n enddo\n cycle\n else\n b=(u0-numin)/dnu\n ib=int(b)+1\n do nb=1,ib-1\n mf(nb,0)=mf(nb,0)+1.d0\n enddo\n if (b-ib>-0.5) mf(ib,0)=mf(ib,0)+1.d0\n mf(ib,1)=mf(ib,1)+sqrt(g2)/4.d0/dnu\n mf(ib,2)=mf(ib,2)+(2*u1*u2*u12-u1*u1*u22-u2*u2*u11)/(2*pi*g2)/dnu\n endif\n enddo\n\n mf=mf/umpix\n \n end subroutine calcmf\n\n!***************************************************\n\n subroutine calcmoment(f,m,npix,sig,sk)\n\n!***************************************************\n\n implicit none\n\n integer :: n,umpix\n integer, intent(in) :: npix\n real, pointer :: m(:)\n double precision, pointer :: f(:,:)\n double precision, intent(out) :: sk(0:2)\n double precision, intent(inout) :: sig(0:1)\n double precision :: u0,u1,u2,u11,u12,u22,g2,lap,tau\n\n sk=0.d0\n umpix=0\n tau=0.d0\n \n do n=1,npix\n if (m(n)==0.) cycle\n umpix=umpix+1\n \n u0=f(n,1)\n u1=f(n,2)\n u2=f(n,3)\n u11=f(n,4)\n u12=f(n,5)\n u22=f(n,6)\n\n lap=u11+u22\n g2=u1*u1+u2*u2\n tau=tau+g2/2.\n\n sk(0)=sk(0)+u0*u0*u0\n sk(1)=sk(1)+u0*u0*lap\n sk(2)=sk(2)+2*g2*lap\n\n enddo\n tau=sqrt(tau/umpix)\n sig(1)=tau*sqrt(2.)*sig(0)\n \n sk=sk/umpix\n sk(1)=sk(1)/(2*tau*tau)\n sk(2)=sk(2)/(4*tau**4)\n\n write(*,*) 'sigma',real(sig)\n write(*,*) 'skewness:',real(sk)\n\n end subroutine calcmoment\n\n!***************************************************\n\n subroutine out_mf(outf,mf,sig,sk,numin,dnu,nbin)\n\n! 1st line: sigma, skewness values\n! After 2nd line:\n! 1st col: threshold value\n! 2-4th cols: MFs for the input data with mask\n! 5-7th cols: Gaussian formulae using sigma for the input data\n! 8-10th cols: 1st order perturbative component from skewness\n!\n!***************************************************\n\n implicit none\n\n integer :: n\n integer, intent(in) :: nbin\n double precision, intent(in) :: mf(nbin,0:2),sig(0:1),sk(0:2),numin,dnu\n double precision :: mfg(0:2),dmfp1(0:2),nu,tau\n character(100) :: outf\n tau=sig(1)/sig(0)/sqrt(2.)\n\n write(*,*) 'Output file of Minkowski Functionals: ',outf(1:len_trim(outf))\n open(2,file=outf,status='unknown')\n write(2,'(5(1pe15.8,1x))') real(sig),real(sk)\n do n=1,nbin\n nu=numin+(n-0.5)*dnu\n call mf_gauss(2,nu,tau,mfg)\n call dmf_pb1(2,nu,tau,sk,sig(0),dmfp1)\n write(2,'(10(1pe15.8,1x))') nu,mf(n,:),mfg,dmfp1\n enddo\n close(2)\n\n end subroutine out_mf\n\n!***************************************************\n \n subroutine convert_covderiv(f,npix)\n\n! inclination angle of each pixel in HEALPix format\n! pixel numbering scheme is \"Ring\" \n\n!***************************************************\n\n implicit none\n\n integer :: n,nside,i,j\n integer, intent(in) :: npix\n double precision, pointer :: f(:,:)\n double precision :: z, theta(npix)\n\n nside=nint(sqrt(npix/12.))\n n=0\n do i=1,nside-1\n z=1.-i**2/3./float(nside)**2\n do j=1,4*i\n n=n+1\n theta(n)=acos(z)\n enddo\n enddo\n\n do i=nside,3*nside\n z=4./3.-2.*i/3./float(nside)\n do j=1,4*nside\n n=n+1\n theta(n)=acos(z)\n enddo\n enddo\n\n do i=3*nside+1,4*nside-1\n z=-1.+(4*nside-i)**2/3./float(nside)**2\n do j=1,4*(4*nside-i)\n n=n+1\n theta(n)=acos(z)\n enddo\n enddo\n\n! convert covariant derivative \n\n do n=1,npix\n f(n,5)=f(n,5)-f(n,3)/tan(theta(n))\n f(n,6)=f(n,6)+f(n,2)/tan(theta(n))\n enddo\n\n end subroutine convert_covderiv\n\n!*******************************************\n\n subroutine norm(f,m,sig0,npix)\n\n! normalize data by its standard deviation\n\n!*******************************************\n\n implicit none\n\n integer n,i\n integer, intent(in) :: npix\n real, pointer :: m(:)\n double precision, pointer :: f(:,:)\n double precision :: mean,sig0\n\n mean=0.d0\n sig0=0.d0\n i=0\n do n=1,npix\n if (m(n)>0.) then\n i=i+1\n mean=mean+f(n,1)\n sig0=sig0+f(n,1)*f(n,1)\n endif\n enddo\n mean=mean/i\n sig0=sqrt((sig0-i*mean*mean)/(i-1))\n do n=1,npix\n f(n,1)=f(n,1)-mean\n enddo\n f=f/sig0\n\n end subroutine norm\n\n!***************************************************\n\n subroutine readmask(inf,m,npix,fsky)\n\n! read mask file in binary\n! mask(i)=0: i-th pixel is masked\n! mask(i)=1: i-th pixel is unmasked and then used for MFs calculation\n! pixel numbering scheme is RING scheme\n!\n!***************************************************\n \n implicit none\n \n integer :: status,unit,readwrite,blocksize,hdutype,ntable,n\n integer :: nfound,irow,i,range(2),irowmax,tfields,nb,nf,npix2\n integer*8 :: felem,nelems\n integer, parameter :: nbite=4\n integer, intent(in) :: npix\n real, pointer :: m(:)\n real :: nulle,nobs\n double precision, intent(out) :: fsky\n character(100) :: inf,comment\n logical :: anynull\n\n allocate(m(npix))\n \n if (inf(1:6)=='nomask') then \n m=1.\n return\n endif\n\n status=0\n call ftgiou(unit,status)\n readwrite=0\n call ftopen(unit,inf,readwrite,blocksize,status)\n ntable=2\n call ftmahd(unit,ntable,hdutype,status)\n call ftgkyj(unit,'TFIELDS',tfields,comment,status)\n call ftgknj(unit,'NAXIS',1,2,range,nfound,status)\n\n nelems=range(1)/nbite/tfields\n irowmax=range(2)\n npix2=nelems*irowmax\n if (npix/=npix2) then\n write(*,*) 'pixel number does not agree'\n stop\n endif\n\n nulle=0.d0\n i=0\n do irow=1,irowmax\n call ftgcve(unit,1,irow,1,nelems,nulle,m(irow),anynull,status)\n if (m(irow)>0.) i=i+1\n enddo\n\n fsky=float(i)/float(irowmax)\n write(*,*) 'fraction of unmasked area:', fsky\n \n call ftclos(unit, status)\n call ftfiou(unit, status)\n\n if (status>0) call printerror(status)\n\n return\n\n end subroutine readmask\n\n!*******************************************************\n\n double precision function mf_amp(d,k,tau)\n\n!*******************************************************\n\n! amplitude of MFs for the Gaussian distribution in d-dimension\n! tau=(sig1/sig0)/sqrt(d)\n\n implicit none\n \n integer, intent(in) :: d,k\n double precision, intent(in) :: tau\n\n mf_amp=tau**k/(2.*pi)**((k+1)/2.)*om(d)/(om(d-k)*om(k))\n\n return\n \n end function mf_amp\n \n!*******************************************************\n\n subroutine mf_gauss(d,nu,tau,mf)\n\n!*******************************************************\n\n! MFs for the Gaussian distribution in d-dimension\n! tau=(sig1/sig0)/sqrt(d)\n\n implicit none\n \n integer, intent(in) :: d\n double precision, intent(in) :: nu,tau\n double precision, intent(out) :: mf(0:d)\n integer :: k\n\n do k=0,d\n mf(k)=mf_amp(d,k,tau)*exp(-nu**2/2.)*herm(k-1,nu)\n enddo\n\n return\n \n end subroutine mf_gauss\n\n!*******************************************************\n\n subroutine dmf_pb1(d,nu,tau,sk,sig0,dmf)\n\n!*******************************************************\n\n! MFs for the weakly non-Gaussian distribution in d-dimension\n\n implicit none\n \n integer, intent(in) :: d\n double precision, intent(in) :: nu,tau,sk(0:d),sig0\n double precision, intent(out) :: dmf(0:d)\n double precision :: dmf_sk\n integer :: k\n\n do k=0,d\n dmf_sk=sk(0)/6.*herm(k+2,nu)-k*sk(1)/4.*herm(k,nu)-k*(k-1)*sk(2)/4*herm(k-2,nu)\n dmf(k)=mf_amp(d,k,tau)*exp(-nu**2/2.)*dmf_sk\n enddo\n\n return\n \n end subroutine dmf_pb1\n\n!*****************************************\n \n double precision function om(m)\n\n! om = pi**(k/2)/Gamma(k/2+1)\n\n!*****************************************\n \n integer, intent(in) :: m\n \n if (m<0) then\n om=0\n else if (m==0) then\n om=1\n else if (m==1) then\n om=2\n else if (m==2) then\n om=pi\n else if (m==3) then\n om=4*pi/3\n else if (m==4) then\n om=pi*pi/2.\n else if (m==5) then\n om=8*pi*pi/15.\n else if (m==6) then\n om=pi**3/6.\n else if (m==7) then\n om=16*pi**3/105.\n else if (m==8) then\n om=pi**4/24.\n else if (m==9) then\n om=32*pi**4/945.\n else if (m==10) then\n om=pi**5/120.\n else\n write(*,*) 'omega with m>10 is not described' \n stop\n endif\n \n return\n \n end function om\n\n!*****************************************\n\n double precision function herm(m,x)\n\n! m-th order Hermite polynomials\n!\n!*****************************************\n\n implicit none\n \n integer, intent(in) :: m\n double precision, intent(in) :: x\n\n if (m<-1) then\n herm=0.\n else if (m==-1) then\n herm=sqrt(pi/2.)*exp(x**2/2.)*erfcc(dble(x/sqrt(2.)))\n elseif (m==0) then\n herm=1.\n elseif (m==1) then\n herm=x\n elseif (m==2) then\n herm=x*x-1.\n elseif (m==3) then\n herm=x**3-3*x\n elseif (m==4) then\n herm=x**4-6*x*x+3\n elseif (m==5) then\n herm=x**5-10*x**3+15*x\n elseif (m==6) then\n herm=x**6-15*x**4+45*x*x-15\n elseif (m==7) then\n herm=x**7-21*x**5+105*x**3-105*x\n elseif (m==8) then\n herm=x**8-28*x**6+210*x**4-420*x*x+105\n elseif (m==9) then\n herm=x**9-36*x**7+378*x**5-1260*x**3+945*x\n elseif (m==10) then\n herm=x**10-45*x**8+630*x**6-3150*x**4+4725*x*x-945\n else\n write(*,*) '>10-th order hermite polynomials are not described'\n stop\n endif\n\n return\n\n end function herm\n\n!*****************************************\n\n double precision FUNCTION erfcc(x)\n\n! calculates the complimentary error function\n! Taken from Numerical Recipes. \n\n!*****************************************\n\n DOUBLE PRECISION, intent(in) :: x\n DOUBLE PRECISION :: t,z\n z=abs(x)\n t=1./(1.+0.5*z)\n erfcc=t*exp(-z*z-1.26551223+t*(1.00002368+t*(.37409196+t* &\n (.09678418+t*(-.18628806+t*(.27886807+t*(-1.13520398+t* &\n (1.48851587+t*(-.82215223+t*.17087277)))))))))\n if (x<0.) erfcc=2.-erfcc\n return\n\n END FUNCTION erfcc\n\n!***************************************************\n\n subroutine read_synfast(inf,f,npix)\n\n! read Temperature + 1st & 2nd derivatives\n! output of synfast routine of HEALPix\n! pixel numbering scheme is RING scheme\n!\n! 1st col T\n! 2nd col dT/dtheta\n! 3rd col dT/dphi/sin(theta)\n! 4th col d^2 T/dtheta^2, \n! 5th col d^2T/dtheta/dphi/sin(theta)\n! 6th col d^2T/dphi^2/sin^2(theta)\n! theta: elevation angle, phi: azimuth angle\n\n!***************************************************\n \n implicit none\n \n integer :: status,unit,readwrite,blocksize,hdutype,ntable,n\n integer :: nfound,irow,i,range(2),irowmax,tfields,nb,nf\n integer*8 :: felem,nelems\n integer, parameter :: nbite=4\n integer, intent(out) :: npix\n double precision, pointer :: f(:,:)\n double precision :: nulld\n character(100) :: inf,comment\n logical :: anynull\n \n status=0\n call ftgiou(unit,status)\n \n readwrite=0\n call ftopen(unit,inf,readwrite,blocksize,status)\n\n ntable=2\n call ftmahd(unit,ntable,hdutype,status)\n\n call ftgkyj(unit,'TFIELDS',tfields,comment,status)\n call ftgknj(unit,'NAXIS',1,2,range,nfound,status)\n\n nelems=range(1)/nbite/tfields\n irowmax=range(2)\n npix=nelems*irowmax\n\n felem=1\n nulld=0.d0\n\n allocate(f(npix,tfields))\n \n do irow=1,irowmax\n nb=1+nelems*(irow-1)\n nf=nelems*irow\n do i=1,tfields\n call ftgcvd(unit,i,irow,felem,nelems,nulld,f(nb:nf,i),anynull,status)\n enddo\n enddo\n \n call ftclos(unit, status)\n call ftfiou(unit, status)\n\n if (status>0) call printerror(status)\n\n return\n\n end subroutine read_synfast\n\n!********************************************************\n\n subroutine correct_binning(mf,sig,numin,dnu,nbin)\n\n! correction of finite binning size (ref. Lim and Simon arXiv:1103.4300)\n\n!********************************************************\n\n implicit none\n\n integer, intent(in) :: nbin\n double precision, intent(inout) :: mf(nbin,0:2)\n double precision, intent(in) :: numin,dnu,sig(0:1)\n double precision :: dmf(0:2),nu,tau\n integer :: n,k\n tau=sig(1)/sig(0)/sqrt(2.)\n\n do n=1,nbin\n nu=numin+(n-0.5)*dnu\n do k=1,2\n dmf(k)=dnu*dnu/24*herm(k+1,nu)*mf_amp(2,k,tau)*exp(-nu*nu/2)\n mf(n,k)=mf(n,k)-dmf(k)\n enddo\n enddo\n\n end subroutine correct_binning\n\n! *************************************************************************\n \n subroutine printerror(status)\n\n! This subroutine prints out the descriptive text corresponding to the\n! error status value and prints out the contents of the internal\n! error message stack generated by FITSIO whenever an error occurs.\n\n! *************************************************************************\n\n integer :: status\n character :: errtext*30,errmessage*80\n\n! Check if status is OK (no error); if so, simply return\n if (status<=0)return\n \n! The FTGERR subroutine returns a descriptive 30-character text string that\n! corresponds to the integer error status number. A complete list of all\n! the error numbers can be found in the back of the FITSIO User's Guide.\n call ftgerr(status,errtext)\n write(*,*) 'FITSIO Error Status =',status,': ',errtext\n\n! FITSIO usually generates an internal stack of error messages whenever\n! an error occurs. These messages provide much more information on the\n! cause of the problem than can be provided by the single integer error\n! status value. The FTGMSG subroutine retrieves the oldest message from\n! the stack and shifts any remaining messages on the stack down one\n! position. FTGMSG is called repeatedly until a blank message is\n! returned, which indicates that the stack is empty. Each error message\n! may be up to 80 characters in length. Another subroutine, called\n! FTCMSG, is available to simply clear the whole error message stack in\n! cases where one is not interested in the contents.\n call ftgmsg(errmessage)\n do while (errmessage .ne. ' ')\n print *,errmessage\n call ftgmsg(errmessage)\n end do\n\n end subroutine printerror\n\nend module mf_tools\n", "meta": {"hexsha": "60f11feb2d229dd14ba6df1b980042ae393c7ece", "size": 15124, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mf_tools.f90", "max_stars_repo_name": "chiaki-hikage/MinkowskiFunctionals2D", "max_stars_repo_head_hexsha": "e59ddaf64da14cd34e6f1de4d250c98229076ddc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "mf_tools.f90", "max_issues_repo_name": "chiaki-hikage/MinkowskiFunctionals2D", "max_issues_repo_head_hexsha": "e59ddaf64da14cd34e6f1de4d250c98229076ddc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "mf_tools.f90", "max_forks_repo_name": "chiaki-hikage/MinkowskiFunctionals2D", "max_forks_repo_head_hexsha": "e59ddaf64da14cd34e6f1de4d250c98229076ddc", "max_forks_repo_licenses": ["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.3935483871, "max_line_length": 86, "alphanum_fraction": 0.530349114, "num_tokens": 4782, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206659843131, "lm_q2_score": 0.7341195385342971, "lm_q1q2_score": 0.6621175831069499}} {"text": "! ==========================================================\n! satellites_linear.f95\n! \n! This program calculates the control and state of a\n! fully actuated satellite using optimal control with\n! quadratic cost\n!\tI(u) = 1/2 * integ( x*Qx + u*Ru ) dt\n!\n! It uses a linearised model of the form\n!\tx' = Ax + Bu\n! Presented by Yang in [Yang, Y. Analytic LQR design for\n! spacecraft control system based on quaternion model.\n! Journal of Aerospace Engineering, 25(3):448-453, jul 2012]\n! \n! INPUT:\n! - \"input_file\": This file is created by the user.\n! It contains the simulation parameters as follows:\n! T_0: Initial time\n! T_1: Final time\n! j1 j2 j3: Moments of inertia\n! q1 q2 q3 q4 q5 q6: Elemets of diagonal matrix q\n! r1 r2 r3: Elements of diagonal matrix R\n! omega_0(1) omega_0(2), omega_0(3): Initial ang. vel.\n! omega_1(1) omega_1(2), omega_1(3): Final ang. vel.\n! eul_0(1) eul_0(2) eul_0(3): Initial Euler angles\n! eul_1(1) eul_1(2) eul_1(3): Final Euler angles\n! m: Number of intervals in the discretization\n!\n! OUTPUT:\n! - \"results_control\": Control\n! - \"results_angveloc\": Angular velocities\n! - \"results_eulerang\": Euler angles\n! - \"results_quaternion\": Quaternion\n! - \"results_time\": Time vector\n! - \"results_misc\": Miscelaneous results (Cost, CPU time...)\n! \n! The convention for quaternion and\n! Euler angles is as follows:\n! q = (epsilon,eta)\n! eul = (phi,theta,rho) = (yaw,pitch,roll)\n!\n! This program depends on LAPACK library: It must be\n! compiled with -llapack and -lblas.\n! ==========================================================\n\n! ======== INITIALIZATION ========\n! Variables declared here are passed to all subroutines\nmodule initialization\nimplicit none \nreal:: q1, q2, q3, q4, q5, q6 \nreal:: r1, r2, r3\nreal:: j1, j2, j3\nend module initialization\n\n! ======== MAIN PROGRAM ========\nprogram main\nuse initialization\nimplicit none\ninterface\n\tsubroutine func(n,x,t,y)\n\tinteger, intent(in):: n\n\treal, intent(in):: x(n), t\n\treal, intent(out):: y(n)\n\tend subroutine func\nend interface\n\ninteger, allocatable:: ipiv(:)\nreal, allocatable:: state_0(:), state_1(:)\nreal, allocatable:: state_aux_0(:), aux_solution_0_T(:)\nreal, allocatable:: aux_solutions(:,:), costate_0(:)\nreal, allocatable:: lu_fact(:,:)\nreal, allocatable:: state(:,:), state_costate(:,:), time(:)\ninteger:: n, nm, m, i, j, k\ninteger:: info\nreal:: omega_0(3), omega_1(3), eul_0(3), eul_1(3)\nreal:: quat_0(4), quat_1(4), eulang(3)\nreal:: t_0, t_1, pi, cpu_clock_ini, cpu_clock_fin\nreal:: cost, h\nn = 6 ! Dimension of the problem\nnm = 3 ! Dimension of control\npi = 4.*atan(1.)\n\n! Open input file\nopen (11,file='input_file',status='old')\n! Load input parameters from file\nread(11,*) T_0\nread(11,*) T_1\nread(11,*) j1, j2, j3\nread(11,*) q1, q2, q3, q4, q5, q6\nread(11,*) r1, r2, r3\nread(11,*) omega_0(1), omega_0(2), omega_0(3)\nread(11,*) omega_1(1), omega_1(2), omega_1(3)\nread(11,*) eul_0(1), eul_0(2), eul_0(3)\nread(11,*) eul_1(1), eul_1(2), eul_1(3)\nread(11,*) m\nclose(11)\n\nallocate (state_0(n), state_1(n))\nallocate (lu_fact(n,n), ipiv(n))\nallocate (state_aux_0(2*n), aux_solution_0_T(n))\nallocate (aux_solutions(n,n), costate_0(n))\nallocate (state(m+1,n), state_costate(m+1,2*n), time(m+1))\n\n! Here the state is (w,epsilon).\n! Eta is calculated afterwards imposing |q|=1\ncall eul2quat(eul_0,quat_0)\ncall eul2quat(eul_1,quat_1)\nstate_0 = (/omega_0,quat_0(1:3)/)\nstate_1 = (/omega_1,quat_1(1:3)/)\n\ncall CPU_TIME(cpu_clock_ini)\n\n! Solve n+1 auxiliary problems\n! Problem i=0\nstate_aux_0 = 0. ! Construct initial condition\ndo k = 1,n\n\tstate_aux_0(k) = state_0(k)\nend do\n\n! Call the solver\ncall rk4(func,2*n,state_aux_0,t_0,t_1,m,state_costate,time) \ndo k = 1,n ! Save solution at final time\n\taux_solution_0_T(k) = state_costate(m+1,k)\nend do\n\n! Problems i=1,...,N\naux_solutions = 0.\ndo i = 1,n\n\t! Construct init. condition (Canonical basis of Rn)\n\tstate_aux_0 = 0. \n\tstate_aux_0(n+i) = 1.\n\t! Call the solver\n\tcall rk4(func,2*n,state_aux_0,t_0,t_1, & \n\tm,state_costate,time)\n\tdo k = 1,n ! Save solution at final time\n\t\taux_solutions(k,i) = state_costate(m+1,k)\n\tend do\nend do\n\n! Solve p_0 = A^-1 (x_T-x_0(T)) \n! costate_0 = inv(aux_solutions)*(state_1-aux_solution_0_T)\n! LU factorization\nlu_fact = aux_solutions\ncall sgetrf(n,n,lu_fact,n,ipiv,info) \ncostate_0 = state_1-aux_solution_0_T\n! Solve linear problem\ncall sgetrs('n',n,1,lu_fact,n,ipiv,costate_0,n,info) \n\n! Final problem\ndo k = 1,n\n\tstate_aux_0(k) = state_0(k)\n\tstate_aux_0(k+n) = costate_0(k)\nend do\n\ncall rk4(func,2*n,state_aux_0,t_0,t_1,m,state_costate,time)\t \n\ncall CPU_TIME(cpu_clock_fin)\n\ncost = 0. ! Calculate cost\nh = (t_1-t_0)/m\ndo i = 1,m+1\n\tcost = cost + h*(q1*state_costate(i,1)**2 & \n\t+ q2*state_costate(i,2)**2 & \n\t+ q3*state_costate(i,3)**2 &\n\t+ q4*state_costate(i,4)**2 & \n\t+ q5*state_costate(i,5)**2 & \n\t+ q6*state_costate(i,6)**2 &\n\t+ r1*(-state_costate(i,7)/(j1*r1))**2 & \n\t+ r2*(-state_costate(i,8)/(j2*r2))**2 &\n\t+ r3*(-state_costate(i,9)/(j3*r3))**2)\nend do\n\n! Save results\nopen(11,file='results_misc', &\nstatus='replace',action='write')\nwrite(11,*) 'LINEAR MODEL;'\nwrite(11,*) 'Initial time T_0;', t_0\nwrite(11,*) 'Final time T_1;', t_1\nwrite(11,*) 'Moments of inertia;', j1, j2, j3\nwrite(11,*) 'Q (diagonal matix);', q1, q2, q3, q4, q5, q6\nwrite(11,*) 'R (diagonal matix);', r1, r2, r3\nwrite(11,*) 'Initial angular velocity w_0;', omega_0\nwrite(11,*) 'Initial angular velocity w_1;', omega_1\nwrite(11,*) 'Initial orientation (yaw,pitch,roll);', eul_0\nwrite(11,*) 'Final orientation (yaw,pitch,roll);', eul_1\nwrite(11,*) '# Intervals discretization;', m\nwrite(11,*) 'Cost I(u) = ', cost\nwrite(11,*) 'CPU time (s);', cpu_clock_fin-cpu_clock_ini\nclose(11)\n\nopen(11,file='results_control_LQR', &\nstatus='replace',action='write')\ndo i = 1,m+1\n\twrite(11,*) -state_costate(i,7)/(j1*r1), & \n\t\t -state_costate(i,8)/(j2*r2), &\n\t\t -state_costate(i,9)/(j3*r3)\nend do\nclose(11)\n\nopen(11,file='results_control', &\nstatus='replace',action='write')\ndo i = 1,m \n\twrite(11,*) &\n\t(state_costate(i+1,1) - & \n\tstate_costate(i,1))*m/(T_1-T_0), &\n\t(state_costate(i+1,2) - & \n\tstate_costate(i,2))*m/(T_1-T_0), &\n\t(state_costate(i+1,3) - & \n\tstate_costate(i,3))*m/(T_1-T_0)\nend do\nclose(11)\n\nopen(11,file='results_quaternion', &\nstatus='replace',action='write')\ndo i = 1,m+1\n\twrite(11,*) & \n\tstate_costate(i,4:6), & \n\t(1-state_costate(i,4)**2 & \n\t-state_costate(i,5)**2 &\n\t-state_costate(i,6)**2)**.5\nend do\nclose(11)\n\nopen(11,file='results_eulerang', &\nstatus='replace',action='write')\ndo i = 1,m+1\n\tcall quat2eul((/state_costate(i,4:6), &\n\t(1-state_costate(i,4)**2 &\n\t-state_costate(i,5)**2 &\n\t-state_costate(i,6)**2)**.5/) &\n\t,eulang)\n\twrite (11,*) eulang\nend do\nclose(11)\n\nopen(11,file='results_angveloc', &\nstatus='replace',action='write')\ndo i = 1,m+1\n\twrite (11,*) state_costate(i,1:3)\nend do\nclose(11)\n\nopen(11, file='results_time', &\nstatus='replace',action='write')\ndo i = 1, m+1\n write (11,*) T_0+(T_1-T_0)*(i-1)/m\nend do\nclose (11)\n\ndeallocate (ipiv)\ndeallocate (state_0, state_1)\ndeallocate (state_aux_0, aux_solution_0_T)\ndeallocate (aux_solutions, costate_0)\ndeallocate (lu_fact)\ndeallocate (state, state_costate, time)\n\nend program main\n\n! ======== 4TH ORDER RUNGE-KUTTA METHOD ========\nsubroutine rk4(func,n,x0,t0,t1,m,x,time)\nimplicit none\ninteger, intent(in):: n, m\nreal, intent(in):: x0(n), t0, t1\nreal, intent(out):: x(m+1,n), time(m+1)\nreal:: h, a1(N), a2(N), a3(N), a4(N)\ninteger:: i, k\nh = (t1-t0)/m\n\ndo i = 1,n\n\tx(1,i) = x0(i)\nend do\n\ndo k = 1,m\n\ttime(k) = t0 + (k-1)*h\n\tcall func(n,x(k,:),time(k),a1)\n\ta1 = h*a1\n\tcall func(n,x(k,:)+.5*a1,time(k)+h/2.,a2)\n\ta2 = h*a2\n\tcall func(n,x(k,:)+.5*a2,time(k)+h/2.,a3)\n\ta3 = h*a3 \n\tcall func(n,x(k,:)+a3,time(k)+h,a4)\n\ta4 = h*a4\n\tdo i = 1,n\n\t\tx(k+1,i) = x(k,i) &\n\t\t+ (a1(i) + 2*a2(i) +2*a3(i) + a4(i))/6.\n\tend do\nend do\ntime(m+1) = t1\nend subroutine rk4\n\n! ======== DYNAMICS ======== \nsubroutine func(n,x,t,y)\nuse initialization\nimplicit none\ninteger, intent(in):: n\nreal, intent(in):: x(n), t\nreal, intent(out):: y(n)\ny(1) = -x(7)/(r1*j1**2)\ny(2) = -x(8)/(r2*j2**2)\ny(3) = -x(9)/(r3*j3**2)\ny(4) = x(1)*.5\ny(5) = x(2)*.5\ny(6) = x(3)*.5\ny(7) = -x(10)*.5 - q1*x(1)\ny(8) = -x(11)*.5 - q2*x(2)\ny(9) = -x(12)*.5 - q3*x(3)\ny(10) = -q4*x(4)\ny(11) = -q5*x(5)\ny(12) = -q6*x(6)\nend subroutine func\n\n! ======== EULER ANGLES TO QUATERNION ========\nsubroutine eul2quat(eul,q)\nreal, intent(in):: eul(3)\nreal, intent(out):: q(4)\nreal:: cy, sy, cp, sp, cr, sr\ncy = cos(eul(1)*.5);\nsy = sin(eul(1)*.5);\ncp = cos(eul(2)*.5);\nsp = sin(eul(2)*.5);\ncr = cos(eul(3)*.5);\nsr = sin(eul(3)*.5);\nq(1) = cy * cp * sr - sy * sp * cr\nq(2) = sy * cp * sr + cy * sp * cr\nq(3) = sy * cp * cr - cy * sp * sr\nq(4) = cy * cp * cr + sy * sp * sr\nend subroutine eul2quat\n\n! ======== QUATERNION TO EULER ANGLES ========\nsubroutine quat2eul(q,eul)\nreal, intent(in):: q(4)\nreal, intent(out):: eul(3)\neul(1) = atan2(2.*(q(4)*q(3)+q(1)*q(2)), & \n1.-2.*(q(2)**2.+q(3)**2.))\neul(2) = asin(2.*(q(4)*q(2)-q(3)*q(1)))\neul(3) = atan2(2.*(q(4)*q(1)+q(2)*q(3)), &\n1.-2.*(q(1)**2.+q(2)**2.))\nend subroutine quat2eul\n", "meta": {"hexsha": "a4a7a382fea8b5e132c73261a1c8781e07cbc2b6", "size": 9006, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Algorithm/Satellites_linear/satellites_linear.f95", "max_stars_repo_name": "vicubso/optimal-attitude-control-of-satellites", "max_stars_repo_head_hexsha": "ab7d7b378a81805b669b1a1a2164f20918e014c3", "max_stars_repo_licenses": ["MIT"], "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/Satellites_linear/satellites_linear.f95", "max_issues_repo_name": "vicubso/optimal-attitude-control-of-satellites", "max_issues_repo_head_hexsha": "ab7d7b378a81805b669b1a1a2164f20918e014c3", "max_issues_repo_licenses": ["MIT"], "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/Satellites_linear/satellites_linear.f95", "max_forks_repo_name": "vicubso/optimal-attitude-control-of-satellites", "max_forks_repo_head_hexsha": "ab7d7b378a81805b669b1a1a2164f20918e014c3", "max_forks_repo_licenses": ["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.5663716814, "max_line_length": 61, "alphanum_fraction": 0.6328003553, "num_tokens": 3556, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.901920681802153, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.662117578979563}} {"text": "SUBROUTINE IMF_WEIGHT(mini,wght,nmass)\n\n !weight each star by the initial mass function (IMF)\n !such that the total initial population consists of \n !one solar mass of stars.\n\n !This weighting scheme assumes that the luminosity, mass, etc.\n !does not vary within the mass bin. The point is that we\n !want each element to represent the whole bin, from \n !mass+/-0.5dm, rather than just the values at point i.\n !Then every intergral over mass is just a sum.\n\n USE sps_vars; USE sps_utils, ONLY : imf, funcint\n IMPLICIT NONE\n\n REAL(SP), INTENT(inout), DIMENSION(nm) :: wght\n REAL(SP), INTENT(in), DIMENSION(nm) :: mini\n INTEGER, INTENT(in) :: nmass\n INTEGER :: i\n REAL(SP) :: m1,m2\n\n !--------------------------------------------------------!\n !--------------------------------------------------------!\n\n wght = 0.0\n\n DO i=1,nmass\n\n IF (mini(i).LT.imf_lower_limit.OR.&\n mini(i).GT.imf_upper_limit) CYCLE\n\n IF (i.EQ.1) THEN\n !note that this is not equal to imf_lower_limit\n !only for the Geneva models, which do not extend below 1.0 Msun\n m1 = imf_lower_bound\n ELSE\n m1 = mini(i) - 0.5*(mini(i)-mini(i-1))\n ENDIF\n IF (i.EQ.nmass) THEN\n m2 = mini(i)\n ELSE\n m2 = mini(i) + 0.5*(mini(i+1)-mini(i))\n ENDIF\n\n IF (m2.LT.m1) THEN\n WRITE(*,*) 'IMF_WEIGHT WARNING: non-monotonic mass!',m1,m2,m2-m1\n CYCLE\n ENDIF\n\n IF (m2.EQ.m1) CYCLE\n\n wght(i) = funcint(imf,m1,m2)\n\n ENDDO\n\n !normalize the weights as an integral from lower to upper limits\n imf_type = imf_type + 10\n wght = wght / funcint(imf,imf_lower_limit,imf_upper_limit)\n imf_type = imf_type - 10\n\n RETURN\n\nEND SUBROUTINE IMF_WEIGHT\n\n", "meta": {"hexsha": "e7d3f0da2d7c10d613fec26daf679f56399a9d91", "size": 1715, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/imf_weight.f90", "max_stars_repo_name": "christopherlovell/fsps", "max_stars_repo_head_hexsha": "1c09a47d7b0fb15a7f245ee3e9b2a7c54122ffdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 55, "max_stars_repo_stars_event_min_datetime": "2015-04-17T18:36:36.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-15T01:47:28.000Z", "max_issues_repo_path": "src/imf_weight.f90", "max_issues_repo_name": "christopherlovell/fsps", "max_issues_repo_head_hexsha": "1c09a47d7b0fb15a7f245ee3e9b2a7c54122ffdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 27, "max_issues_repo_issues_event_min_datetime": "2015-11-04T03:19:44.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-15T22:03:19.000Z", "max_forks_repo_path": "src/imf_weight.f90", "max_forks_repo_name": "christopherlovell/fsps", "max_forks_repo_head_hexsha": "1c09a47d7b0fb15a7f245ee3e9b2a7c54122ffdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 43, "max_forks_repo_forks_event_min_datetime": "2015-04-29T09:24:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T19:31:46.000Z", "avg_line_length": 26.3846153846, "max_line_length": 72, "alphanum_fraction": 0.5982507289, "num_tokens": 540, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206659843131, "lm_q2_score": 0.7341195152660688, "lm_q1q2_score": 0.6621175621208538}} {"text": " subroutine pvYcalc(q1,q2,q3,m1s,m2s,m3s,m4s)\n implicit none\n integer nu\n logical qlzero,qlnonzero\n double precision q1(4),q2(4),q3(4),q4(4),m1s,m2s,m3s,m4s, \n . Y(4,4),pvdot\n do nu=1,4\n q4(nu)=0d0\n enddo\n\n Y(1,1)=m1s\n Y(2,2)=m2s\n Y(3,3)=m3s\n Y(4,4)=m4s\n\n Y(1,2)=0.5d0*(m1s+m2s-pvdot(q4,q4)-pvdot(q1,q1)+2d0*pvdot(q1,q4))\n Y(1,3)=0.5d0*(m1s+m3s-pvdot(q4,q4)-pvdot(q2,q2)+2d0*pvdot(q2,q4))\n Y(1,4)=0.5d0*(m1s+m4s-pvdot(q4,q4)-pvdot(q3,q3)+2d0*pvdot(q3,q4))\n\n Y(2,3)=0.5d0*(m2s+m3s-pvdot(q1,q1)-pvdot(q2,q2)+2d0*pvdot(q1,q2))\n Y(2,4)=0.5d0*(m2s+m4s-pvdot(q1,q1)-pvdot(q3,q3)+2d0*pvdot(q1,q3))\n\n Y(3,4)=0.5d0*(m3s+m4s-pvdot(q2,q2)-pvdot(q3,q3)+2d0*pvdot(q2,q3))\n\nc write(6,*) 'row1',Y(1,1),Y(1,2),Y(1,3),Y(1,4)\nc write(6,*) 'row2',Y(1,2),Y(2,2),Y(2,3),Y(2,4)\nc write(6,*) 'row3',Y(1,3),Y(2,3),Y(3,3),Y(3,4)\nc write(6,*) 'row4',Y(1,4),Y(2,4),Y(3,4),Y(4,4)\n\n if (qlzero(Y(1,3)) \n . .and. qlnonzero(Y(1,2)) .and. qlnonzero(Y(3,4))) then\n write(6,*) 'swapping 1 and 2'\n call pvswap(q1,q2,m2s,m3s)\n\n elseif (qlzero(Y(2,4)) \n . .and. qlnonzero(Y(1,4)) .and. qlnonzero(Y(2,3))) then\n call pvswap(q2,q3,m3s,m4s)\n write(6,*) 'swapping 2 and 3'\n\n elseif (qlzero(Y(2,4)) \n . .and. qlnonzero(Y(1,2)) .and. qlnonzero(Y(3,4))) then\n call pvswap(q2,q3,m3s,m4s)\n call pvswap(q1,q2,m2s,m3s)\n write(6,*) '231 --> 123'\n endif\n\nc Y(1,2)=0.5d0*(m1s+m2s-pvdot(q4,q4)-pvdot(q1,q1)+2d0*pvdot(q1,q4))\nc Y(1,3)=0.5d0*(m1s+m3s-pvdot(q4,q4)-pvdot(q2,q2)+2d0*pvdot(q2,q4))\nc Y(1,4)=0.5d0*(m1s+m4s-pvdot(q4,q4)-pvdot(q3,q3)+2d0*pvdot(q3,q4))\n\nc Y(2,3)=0.5d0*(m2s+m3s-pvdot(q1,q1)-pvdot(q2,q2)+2d0*pvdot(q1,q2))\nc Y(2,4)=0.5d0*(m2s+m4s-pvdot(q1,q1)-pvdot(q3,q3)+2d0*pvdot(q1,q3))\n\nc Y(3,4)=0.5d0*(m3s+m4s-pvdot(q2,q2)-pvdot(q3,q3)+2d0*pvdot(q2,q3))\n\nc write(6,*) 'new1',Y(1,1),Y(1,2),Y(1,3),Y(1,4)\nc write(6,*) 'new2',Y(1,2),Y(2,2),Y(2,3),Y(2,4)\nc write(6,*) 'new3',Y(1,3),Y(2,3),Y(3,3),Y(3,4)\nc write(6,*) 'new4',Y(1,4),Y(2,4),Y(3,4),Y(4,4)\n\n\n return\n end\n", "meta": {"hexsha": "61a43e810cc0008bc27a202f62c48ea53023f919", "size": 2168, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "MCFM-JHUGen/TensorReduction/pv/pvYcalc.f", "max_stars_repo_name": "tmartini/JHUGen", "max_stars_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-06-08T13:09:28.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-04T19:59:36.000Z", "max_issues_repo_path": "MCFM-JHUGen/TensorReduction/pv/pvYcalc.f", "max_issues_repo_name": "tmartini/JHUGen", "max_issues_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 64, "max_issues_repo_issues_event_min_datetime": "2015-06-24T15:08:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-25T04:59:32.000Z", "max_forks_repo_path": "MCFM-JHUGen/TensorReduction/pv/pvYcalc.f", "max_forks_repo_name": "tmartini/JHUGen", "max_forks_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2015-05-04T22:15:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-06T10:04:40.000Z", "avg_line_length": 33.875, "max_line_length": 72, "alphanum_fraction": 0.5350553506, "num_tokens": 1213, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240142763573, "lm_q2_score": 0.7057850402140659, "lm_q1q2_score": 0.6621138951418197}} {"text": "** Copyright (c) 1989, NVIDIA CORPORATION. All rights reserved.\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 implied.\n** See the License for the specific language governing permissions and\n** limitations under the License.\n\n* Integer arithmetic operations (+, *, - , /), including\n* constant folding.\n\n\tprogram p\n \tparameter (n=24)\n\tinteger rslts(N), expect(N)\n\tdata expect / -7, -398, 7, 1,\n + 6, 87, 2, -8,\n + -8, 73, -4, -2,\n + -7, 560, -3, 15,\n + -7, 1, 0, -2,\n + 100000000, 10, 90, -1 /\n\n\tdata i7, in1, i4, in4, i9 / 7, -1, 4, -4, 9 /\n\nc tests 1 - 4: unary minus and plus operators:\n\n \trslts(1) = -i7\n\trslts(2) = +(-398)\n \trslts(3) = -(-(+i7))\n \trslts(4) = -(-1)\n\nc tests 5 - 8: plus operator:\n\n \trslts(5) = i7 + in1\n \trslts(6) = i7 + 80\n \trslts(7) = 3 + in1\n \trslts(8) = -3+(-5)\n\nc tests 9 - 12: minus operator:\n\n \trslts(9) = in1 - i7\n \trslts(10) = 80 - i7\n \trslts(11) = in1 - 3\n \trslts(12) = -5-(-3)\n\nc tests 13 - 16: multiply operator:\n\n\trslts(13) = in1 * i7\n\trslts(14) = 80 * i7\n\trslts(15) = in1 * 3\n\trslts(16) = -5 * (-3)\n\nc tests 17 - 24: divide operator:\n\n\trslts(17) = i7 / in1\n rslts(18) = i7 / i4\n rslts(19) = 1 / in4\n\trslts(20) = (-8) / 3\n\trslts(21) = 900000000 / i9\n\trslts(22) = -51 / (-5)\n rslts(23) = 900000000 / 10000000\n\trslts(24) = i7 / (-4)\n\nc check results:\n\n\tcall check(rslts, expect, N)\n\tend\n", "meta": {"hexsha": "624365ddc0e9899394b91f3aa43c16d2b5aa1e44", "size": 1885, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "test/f90_correct/src/gb00.f", "max_stars_repo_name": "kammerdienerb/flang", "max_stars_repo_head_hexsha": "8cc4a02b94713750f09fe6b756d33daced0b4a74", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-02T19:47:29.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T19:47:29.000Z", "max_issues_repo_path": "test/f90_correct/src/gb00.f", "max_issues_repo_name": "kammerdienerb/flang", "max_issues_repo_head_hexsha": "8cc4a02b94713750f09fe6b756d33daced0b4a74", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 58, "max_issues_repo_issues_event_min_datetime": "2017-10-25T17:21:13.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-22T13:35:09.000Z", "max_forks_repo_path": "test/f90_correct/src/gb00.f", "max_forks_repo_name": "kammerdienerb/flang", "max_forks_repo_head_hexsha": "8cc4a02b94713750f09fe6b756d33daced0b4a74", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-12-21T06:35:35.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-07T23:18:58.000Z", "avg_line_length": 25.8219178082, "max_line_length": 75, "alphanum_fraction": 0.5575596817, "num_tokens": 714, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424411924672, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6620874123636439}} {"text": "SUBROUTINE tfpoint(thetas,phis,tweights,ln)\n !************************************************!\n ! GENERATES POINTS ON A UNIT SPHERE !\n !************************************************!\n IMPLICIT NONE\n !\n REAL*8, intent(out) :: thetas(ln+1), phis(2*ln+1), tweights(ln+1)! spt(2,(ln+1)*(2*ln+1)),weight((ln+1)*(2*ln+1))\n INTEGER, intent(in) :: ln\n !\n REAL*8 :: dsum\n REAL*8 :: fake_shift, phi, pi\n INTEGER :: i, j, lg\n !\n PI=4.D0*ATAN(1.D0)\n lg = ln+1\n !\n CALL GRULE(lg,thetas,tweights) ! Gauss points in the interval [1...0]\n !\n do i=1,(lg+1)/2 ! adding symmetrical points to [0,...-1]\n j = lg+1-i\n thetas(j)=-thetas(i)\n tweights(j)=tweights(i)\n enddo\n do i=1,lg\n thetas(i) = dacos(thetas(i))\n enddo\n !\n fake_shift=EXP(-4.D0) ! small shift such that we do not start at phi=0\n DO i=0,2*lg-2 ! 2*l-1 points in phi direction\n PHI=PI*(2*dble(i)/dble(2*lg-1) + fake_shift)\n phis(i+1)=PHI\n ENDDO\n !\n dsum = sum(tweights)\n tweights(:) = tweights(:)*2./dsum\n !write(6,*)'Gauss-Legendre grid of ',lg,'x',2*lg-1\n return\nend SUBROUTINE tfpoint\n\nSUBROUTINE apoint(spt,weight,ln)\n !************************************************!\n ! GENERATES POINTS ON A UNIT SPHERE !\n !************************************************!\n IMPLICIT NONE\n !\n REAL*8, intent(out) :: spt(2,(ln+1)*(2*ln+1)),weight((ln+1)*(2*ln+1))\n INTEGER, intent(in) :: ln\n !\n REAL*8 :: XX((ln+1)*(2*ln+1))\n REAL*8 :: dsum\n REAL*8 :: fake_shift, phi, pi\n REAL*8 :: weight0(ln+1)\n INTEGER :: i, j, index, lg\n !\n PI=4.D0*ATAN(1.D0)\n lg = ln+1\n !\n CALL GRULE(lg,XX,WEIGHT) ! Gauss points in the interval [0...1]\n !\n DO i=1,(lg+1)/2\n j = lg+1-i\n XX(j)=-XX(i)\n WEIGHT(j)=WEIGHT(i)\n ENDDO\n weight0(:) = WEIGHT(:lg)\n !\n fake_shift=EXP(-4.D0) ! small shift such that we do not start at phi=0\n INDEX=0\n DO j=1,lg ! over all theta points\n DO i=0,2*lg-2 ! 2*l-1 points in phi direction\n PHI=PI*(2*dble(i)/dble(2*lg-1) + fake_shift)\n !INDEX=lg*i+j\n INDEX=INDEX+1\n WEIGHT(INDEX)=weight0(j)\n SPT(1,INDEX)=dacos(XX(j))\n SPT(2,INDEX)=PHI\n ENDDO\n ENDDO\n !\n dsum = sum(weight)\n weight(:) = weight(:)*4.D0*PI/dsum\n write(6,*)'Gauss-Legendre grid of ',lg,'x',2*lg-1\n return\nend SUBROUTINE apoint\n\nSUBROUTINE gpoint(spt,weight,ln)\n !************************************************!\n ! GENERATES POINTS ON A UNIT SPHERE !\n !************************************************!\n IMPLICIT NONE\n !\n REAL*8, intent(out) :: spt(3,(ln+1)*(2*ln+1)),weight((ln+1)*(2*ln+1))\n INTEGER, intent(in) :: ln\n !\n REAL*8 :: XX((ln+1)*(2*ln+1))\n REAL*8 :: dsum\n REAL*8 :: fake_shift, phi, pi, rxy, z\n INTEGER :: i, j, index, lg\n !\n PI=4.D0*ATAN(1.D0)\n lg = ln+1\n !\n CALL GRULE(lg,XX,WEIGHT) ! Gauss points in the interval [0...1]\n !\n DO i=1,(lg+1)/2\n j = lg+1-i\n XX(j)=-XX(i)\n WEIGHT(j)=WEIGHT(i)\n ENDDO\n !\n fake_shift=EXP(-4.D0) ! small shift such that we do not start at phi=0\n DO j=1,lg ! over all theta points\n Z=XX(j) ! z = cos(theta)\n RXY=sqrt(1.D0-Z*Z) ! rxy = sin(theta)\n DO i=0,2*lg-2 ! 2*l-1 points in phi direction\n PHI=PI*(2*dble(i)/dble(2*lg-1) + fake_shift)\n INDEX=lg*i+j\n WEIGHT(INDEX)=WEIGHT(j)\n SPT(1,INDEX)=COS(PHI)*RXY\n SPT(2,INDEX)=SIN(PHI)*RXY\n SPT(3,INDEX)=Z\n ENDDO\n ENDDO\n !\n dsum = sum(weight)\n weight(:) = weight(:)*4.D0*PI/dsum\n write(6,*)'Gauss-Legendre grid of ',lg,'x',2*lg-1\n return\nend SUBROUTINE gpoint\n\nSUBROUTINE GRULE(N,X,W)\n IMPLICIT NONE\n !\n ! DETERMINES THE (N+1)/2 NONNEGATIVE POINTS X(I) AND\n ! THE CORRESPONDING WEIGHTS W(I) OF THE N-POINT\n ! GAUSS-LEGENDRE INTEGRATION RULE, NORMALIZED TO THE\n ! INTERVAL \\-1,1\\. THE X(I) APPEAR IN DESCENDING ORDER.\n !\n ! THIS ROUTINE IS FROM 'METHODS OF NUMERICAL INTEGRATION',\n ! P.J. DAVIS AND P. RABINOWITZ, PAGE 369.\n !\n INTEGER, intent(in) :: N\n REAL*8, intent(out) :: X(*), W(*)\n !\n REAL*8 :: D1, d2pn, d3pn, d4pn, den, dp, dpn, e1, fx, h, p, pi, pk, pkm1, pkp1, t, t1, u, v, x0\n INTEGER :: i, it, k, m\n !\n PI=4.D0*ATAN(1.D0)\n M=(N+1)/2\n E1=N*(N+1)\n DO I=1,M ! 1\n T=(4*I-1)*PI/(4*N+2)\n X0=(1.D0-(1.D0-1.D0/N)/(8.D0*N*N))*COS(T)\n !---> ITERATE ON THE VALUE (M.W. JAN. 1982)\n DO IT=1,3 ! 2\n PKM1=1.D0\n PK=X0\n DO K=2,N ! 3\n T1=X0*PK\n PKP1=T1-PKM1-(T1-PKM1)/K+T1\n PKM1=PK\n PK=PKP1\n ENDDO ! 3\n DEN=1.D0-X0*X0\n D1=N*(PKM1-X0*PK)\n DPN=D1/DEN\n D2PN=(2.D0*X0*DPN-E1*PK)/DEN\n D3PN=(4.D0*X0*D2PN+(2.D0-E1)*DPN)/DEN\n D4PN=(6.D0*X0*D3PN+(6.D0-E1)*D2PN)/DEN\n U=PK/DPN\n V=D2PN/DPN\n H=-U*(1.D0+.5D0*U*(V+U*(V*V-U*D3PN/(3.D0*DPN))))\n P=PK+H*(DPN+.5D0*H*(D2PN+H/3.D0*(D3PN+.25D0*H*D4PN)))\n DP=DPN+H*(D2PN+.5D0*H*(D3PN+H*D4PN/3.D0))\n H=H-P/DP\n X0=X0+H\n ENDDO\n X(I)=X0\n FX=D1-H*E1*(PK+.5D0*H*(DPN+H/3.D0*(D2PN+.25D0*H*(D3PN+.2D0*H*D4PN))))\n W(I)=2.D0*(1.D0-X(I)*X(I))/(FX*FX)\n ENDDO\n IF(M+M.GT.N) X(M)=0.D0\n RETURN\nEND SUBROUTINE GRULE\n", "meta": {"hexsha": "b52127d369590a7e260e4af092ee5c135fc6c5ce", "size": 5238, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/exactDC/gpoint.f90", "max_stars_repo_name": "chanul13/EDMFTF", "max_stars_repo_head_hexsha": "967d85d898924991b31861b4e1f45129e3eff180", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2018-04-03T06:37:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-08T11:44:06.000Z", "max_issues_repo_path": "src/putils/XCscreen/gpoint.f90", "max_issues_repo_name": "chanul13/EDMFTF", "max_issues_repo_head_hexsha": "967d85d898924991b31861b4e1f45129e3eff180", "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/putils/XCscreen/gpoint.f90", "max_forks_repo_name": "chanul13/EDMFTF", "max_forks_repo_head_hexsha": "967d85d898924991b31861b4e1f45129e3eff180", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-10-27T20:23:34.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-13T13:54:11.000Z", "avg_line_length": 28.3135135135, "max_line_length": 116, "alphanum_fraction": 0.5084001527, "num_tokens": 2158, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424217727027, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6620873971645228}} {"text": "c\nc file tcud3cr.f\nc\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc . .\nc . copyright (c) 1999 by UCAR .\nc . .\nc . UNIVERSITY CORPORATION for ATMOSPHERIC RESEARCH .\nc . .\nc . all rights reserved .\nc . .\nc . .\nc . MUDPACK version 5.0 .\nc . .\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc\nc\nc ... author and specialist\nc\nc John C. Adams (National Center for Atmospheric Research)\nc email: johnad@ucar.edu, phone: 303-497-1213\n\nc ... For MUDPACK 5.0 information, visit the website:\nc (http://www.scd.ucar.edu/css/software/mudpack)\nc\nc\nc ... purpose\nc\nc test program for the MUDPACK solver cud3cr\nc\nc ... required MUDPACK files\nc\nc cud3cr.f, cudcom.f\nc\nc\nc *********************************************************\nc *********************************************************\nc\nc sample program/test driver for cud3cr (see cud3cr.d)\nc\nc **********************************************************\nc **********************************************************\nc\nc a sample program/test driver for cud3cr is below. it can be\nc executed as an initial test. The output from executing\nc the code in this file is listed after the problem description.\nc\nc Problem Description:\nc\nc test cud3cr by solving the complex nonseparable 3-d elliptic pde\nc with cross derivative terms:\nc\nc cxx*pxx + cyy*pyy + czz*pzz + cx*px + cy*py + cz*pz + ce*pe +\nc\nc cxy*pxy + cxz*pxz + cyz*pyz = r(x,y,z).\nc\nc on the region 0 < x < 1, 0 < y < (pi+pi), 0 < z < 1.\nc let s = sin(y), c = cos(y). the complex coefficients are\nc given by:\nc\nc cxx = cmplx(1.0+0.5*s*z,1.0+0.5*c*z)\nc\nc cyy = (1.,1.)+cmplx(x,z)\nc\nc czz = cmplx(1.0+0.5*s*x,1.0+0.5*c*x)\nc\nc cx = cy = cz = (0.0,0.0)\nc\nc ce = -cmplx(z,x)\nc\nc cxy = cmplx(sqrt(real(cxx)*real(cyy),sqrt(aimag(cxx)*aimag(cyy))\nc\nc cxz = (0.0,0.0)\nc\nc cyz = cmplx(sqrt(real(cyy)*real(czz),sqrt(aimag(cyy)*aimag(czz))\nc\nc assume the solution is periodic in y and is specified at x=0 and z=0.\nc further assume mixed oblique derivative conditions of the form\nc\nc px + cmplx(z,1-z)*py + cmplx(s,c)*pz - p(1,y,z) = g(y,z)\nc\nc at x=1 and mixed normal derivative conditions of the form\nc\nc pz + cmplx(x,s*s)*p(x,y,1) = h(x,y)\nc\nc at z=1. for testing purposes, use the exact solution\nc\nc p(x,y,z) = exp(x*z)*cmplx(c,s)\nc\nc to set boundary conditions, the right hand side, and compute\nc exact error. results from approximating this problem on a\nc 25 by 65 by 25 x-y-z grid using cud3cr are given below. point\nc relaxation and an error tolerance of .001 are used.\nc\nc ******************************************************\nc output (32 bit floating point arithmetic)\nc *******************************************************\nc\nc cud3cr test\nc\nc input arguments\nc intl = 0\nc nxa = 1 nxb = 2\nc nyc = 0 nyd = 0\nc nze = 1 nzf = 2\nc ixp = 3 jyq = 2 kzr = 3\nc iex = 3 jey = 6 kez = 3\nc nx = 13 ny = 65 nz = 13\nc iguess = 0 maxcy = 2\nc method = 0 work space input = 173394\nc xa = 0.00 xb = 1.00\nc yc = 0.00 yd = 6.28\nc ze = 0.00 zf = 1.00\nc tolmax = 0.000E+00\nc\nc multigrid options\nc mgopt(1) = 0\nc\nc new cud3cr arguments\nc icrs\nc 1 0 1\nc tol = 0.0010\nc maxit = 10\nc\nc initial call\nc intl = 0\nc iguess = 0\nc ierror = 0\nc minimum required work space length = 173394\nc\nc approximation call\nc intl = 1\nc iguess = 0\nc ierror = 0\nc number of outer iterations executed = 9\nc relative difference profile:\nc 0.6567 0.1462 0.0638 0.0203 0.0099 0.0051 0.0016 0.0011 0.0004\nc exact least squares error = 0.127E-02\nc\nc ************************************************************\nc end of output\nc ************************************************************\nc\n program tcd3cr\n implicit none\nc\nc set grid sizes and predetermined minimal required equired work\nc with parameter statements\nc\n integer iixp,jjyq,kkzr,iiex,jjey,kkez,nnx,nny,nnz,llengt,mmaxit\n parameter(iixp=3,jjyq=2,kkzr=3)\n parameter (iiex=3,jjey=6,kkez=3)\n parameter(nnx = iixp*2**(iiex-1)+1)\n parameter(nny = jjyq*2**(jjey-1)+1)\n parameter(nnz = kkzr*2**(kkez-1)+1)\n parameter(llengt=173394)\n parameter(mmaxit = 10)\n complex rhs(nnx,nny,nnz),phi(nnx,nny,nnz),work(llengt)\n integer iparm(23),mgopt(4),icrs(3)\n integer i,j,k,ierror,maxit,iouter\n real fparm(8),rmax(mmaxit)\n\nc\nc use labelled common to identify integer and floating point arguments\nc\n integer intl,nxa,nxb,nyc,nyd,nze,nzf,ixp,jyq,kzr,iex,jey,\n +kez,nx,ny,nz,iguess,maxcy,method,meth2,nwork,lwkmin,itero\n common /iprm/intl,nxa,nxb,nyc,nyd,nze,nzf,ixp,jyq,kzr,iex,jey,\n +kez,nx,ny,nz,iguess,maxcy,method,meth2,nwork,lwkmin,itero\n real xa,xb,yc,yd,ze,zf,tolmax,relmax\n common/fprm/xa,xb,yc,yd,ze,zf,tolmax,relmax\n real pi,dx,dy,dz,c,s,x,y,z,tol,err2\n complex cxx,cyy,czz,cx,cy,cz,ce,cxy,cyz\n complex pxx,pyy,pzz,px,py,pz,pxy,pxz,pyz,pe\n equivalence(iparm,intl)\n equivalence(fparm,xa)\n external cof,bd3cr,cxyf,cxzf,cyzf\n pi = 4.*atan(1.)\nc\nc set interval end points\nc\n xa = 0.0\n xb = 1.0\n yc = 0.0\n yd = pi+pi\n ze = 0.0\n zf = 1.0\nc\nc set required no error control within multigrid cycling\nc\n tolmax = 0.0\nc\nc set integer input arguments\nc\n intl = 0\nc\nc set boundary condition flags\nc\n nxa = 1\n nxb = 2\n nyc = 0\n nyd = 0\n nze = 1\n nzf = 2\nc\nc set grid size arguments from parameter statements\nc\n ixp = iixp\n jyq = jjyq\n kzr = kkzr\n iex = iiex\n jey = jjey\n kez = kkez\n nx = nnx\n ny = nny\n nz = nnz\nc\nc flag nonzero xy and yz and zero xz cross derivatives terms\nc\n icrs(1) = 1\n icrs(2) = 0\n icrs(3) = 1\nc\nc set two multigrid cycles per outer iteration\nc\n maxcy = 2\nc\nc set point relaxation\nc\n method = 0\n meth2 = 0\nc\nc set work space length input\nc\n nwork = llengt\nc\nc set uniform grid interval lengths in each dimension\nc\n dx = (xb-xa)/(nx-1)\n dy = (yd-yc)/(ny-1)\n dz = (zf-ze)/(nz-1)\nc\nc set right hand side and preset solution to zero\nc this also sets specified (Dirchlet) b.c. in phi\nc\n do j=1,ny\n\ty = (j-1)*dy\n\ts = sin(y)\n\tdo k=1,nz\n\t z = (k-1)*dz\n\t do i=1,nx\n\t x = (i-1)*dx\n\t call exact(x,y,z,pe,px,py,pz,pxx,pyy,pzz,pxy,pxz,pyz)\n\t call cof(x,y,z,cxx,cyy,czz,cx,cy,cz,ce)\n\t call cxyf(x,y,z,cxy)\n\t call cyzf(x,y,z,cyz)\n\t rhs(i,j,k) = cxx*pxx+cyy*pyy+czz*pzz+cxy*pxy+cyz*pyz+\n + cx*px+cy*py+cz*pz+ce*pe\n\t phi(i,j,k) = 0.0\n\t end do\n\tend do\n end do\nc\nc set default multigrid options\nc\n mgopt(1) = 0\nc\nc set error control tolerance and outer iteration limit of 10\nc\n tol = .001\n maxit = mmaxit\nc\nc print input arguments shared with cud3\nc\n write(*,50)\n 50 format(//' cud3cr test ' )\n write(*,100)intl,nxa,nxb,nyc,nyd,nze,nzf,ixp,jyq,kzr,iex,jey,kez,\n + nx,ny,nz,iguess,maxcy,method,nwork,xa,xb,yc,yd,ze,zf,\n + tolmax,mgopt(1)\n 100 format(/' input arguments ',\n +/' intl = ',i2,\n +/' nxa = ',i2,' nxb = ',i2,\n +/' nyc = ',i2,' nyd = ',i2,\n +/' nze = ',i2,' nzf = ',i2,\n +/' ixp = ',i2,' jyq = ',i2,' kzr = ',i2,\n +/' iex = ',i2, ' jey = ',i2, ' kez = ',i2,\n +/' nx = ',i3,' ny = ',i3,' nz = ',i3,\n +/' iguess = ',i2,' maxcy = ',i2,\n +/' method = ',i2, ' work space input = ',i7,\n +/' xa = ',f5.2,' xb = ',f5.2,\n +/' yc = ',f5.2,' yd = ',f5.2,\n +/' ze = ',f5.2,' zf = ',f5.2,\n +/' tolmax = ' ,e10.3\n +//' multigrid options '\n +/' mgopt(1) = ',i2)\nc\nc print new cud3cr arguments\nc\n write(*,101) (icrs(i),i=1,3),tol,maxit\n 101 format(/' new cud3cr arguments ', / ' icrs '/ 3i5,\n +/' tol = ',f6.4 /' maxit = ',i3)\nc\nc *** initialization call\nc\n intl = 0\n iguess = 0\n call cud3cr(iparm,fparm,work,cof,bd3cr,rhs,phi,mgopt,icrs,\n +cxyf,cxzf,cyzf,tol,maxit,iouter,rmax,ierror)\n write (*,200) intl,iguess,ierror,iparm(22)\n 200 format(/' initial call', /' intl = ',i2, /' iguess = ',i2,\n +/' ierror = ',i2, /' minimum required work space length = ',i8)\n if (ierror.gt.0) call exit(0)\nc\nc *** noninitial call\nc\n intl = 1\n iguess = 0\n call cud3cr(iparm,fparm,work,cof,bd3cr,rhs,phi,mgopt,icrs,\n +cxyf,cxzf,cyzf,tol,maxit,iouter,rmax,ierror)\n write (*,201) intl,iguess,ierror,iouter,(rmax(i),i=1,iouter)\n 201 format(/' approximation call ', /' intl = ',i2, /' iguess = ',i2,\n +/' ierror = ',i3,\n +/' number of outer iterations executed = ',i3,\n +/' relative difference profile:', /(10(f6.4,2x)))\nc\nc compute and print exact least squares error after iouter iterations\nc\n err2 = 0.\n do j=1,ny\n\ty = (j-1)*dy\n\tc = cos(y)\n\tdo k=1,nz\n\t z = (k-1)*dz\n\t do i=1,nx\n\t x = (i-1)*dx\n\t pe = cmplx((x*c*z)**3,0.0)\n\t err2 = err2 + cabs(pe - phi(i,j,k))**2\n\t end do\n\tend do\n end do\n err2 = sqrt(err2/(nx*ny*nz))\n write(*,202) err2\n 202 format(' exact least squares error = ',e10.3)\n end\n\n subroutine exact(x,y,z,pe,px,py,pz,pxx,pyy,pzz,pxy,pxz,pyz)\nc\nc set exact solution and partial derivatives: p(x,y,z) = (x*cos(y)*z)**3\nc\n implicit none\n real x,y,z\n complex pe,px,py,pz,pxx,pyy,pzz,pxy,pxz,pyz\n real s,c,exz\n real xc,xz,cz,xcz\n c = cos(y)\n s = sin(y)\n xc = x*c\n xz = x*z\n cz = c*z\n xcz = xc*z\n pe = cmplx(xcz**3,0.0)\n px = cmplx(3.*x*x*cz**3,0.0)\n pxx = cmplx(6.*x*cz**3,0.0)\n py =cmplx( -3.*c*c*s*xz**3,0.0)\n pyy = cmplx(-3.*xz**3*(c**3-2.*c*s**2),0.0)\n pz = cmplx(3.*z*z*xc**3,0.0)\n pzz = cmplx(6.*z*xc**3,0.0)\n pxy = cmplx(-9.*x**2*c*c*s*z**3,0.0)\n pxz = cmplx(9.*xz**2*c**3,0.0)\n pyz =cmplx( -9.*c*c*s*x**3*z**2,0.0)\n return\n exz = exp(x*z)\n pe = exz*cmplx(c,z)\n px = z*pe\n py = -exz*s\n pz = x*pe +exz*cmplx(c,1.0)\n pxx = z*px\n pyy = -exz*c\n pzz = x*(pz+exz*cmplx(c,1.0))\n return\n end\n\n subroutine cof(x,y,z,cxx,cyy,czz,cx,cy,cz,ce)\nc\nc set noncross derivative pde coefficients\nc\n implicit none\n real x,y,z,s,c\n complex cxx,cyy,czz,cx,cy,cz,ce\n s = sin(y)\n c = cos(y)\n cxx = cmplx(1.+0.5*s*z, 1.+0.5*c*z)\n cyy = cmplx(1.+x,1.+z)\n czz = cmplx(1+0.5*s*x,1.+0.5*c*x)\n cx = (0.,0.)\n cy = cx\n cz = cz\n ce = -cmplx(x+z,0.0)\n return\n\n cxx = cmplx(1.+0.5*s*z,0.0)\n cyy = cmplx(1.+x*z,0.0)\n czz = cmplx(1.+0.5*x*s,0.0)\n cx = (0.0,0.0)\n cy = cmplx(-x*z,0.0)\n cz = (0.0,0.0)\n ce = cmplx(-(x+z),0.0)\n return\n\n cxx = (1.0,1.0)+0.5*cmplx(s*z,c*z)\n cyy = (1.0,1.0)+cmplx(x,z)\n czz = (1.0,1.0)+0.5*cmplx(x*s,x*c)\n cx = (0.0,0.0)\n cy = cmplx(-x*z,x*z)\n cz = (0.0,0.0)\n ce = -cmplx((x+z),0.0)\n return\n end\n\n subroutine cxyf(x,y,z,cxy)\nc\nc set x-y cross term coefficient at (x,y,z)\nc\n implicit none\n real x,y,z,cxxr,cxxi,cyyr,cyyi,cxyr,cxyi\n complex cxx,cyy,czz,cx,cy,cz,ce,cxy\n call cof(x,y,z,cxx,cyy,czz,cx,cy,cz,ce)\n cxxr = cxx\n cxxi = aimag(cxx)\n cyyr = cyy\n cyyi = aimag(cyy)\n cxyr = sqrt(cxxr*cyyr)\n cxyi = sqrt (cxxi*cyyi)\n cxy = cmplx(cxyr,cxyi)\n return\n end\n\n subroutine cxzf(x,y,z,cxz)\nc\nc this is a dummy subroutine since cxz=0.0 for all (x,y,z)\nc\n return\n end\n\n subroutine cyzf(x,y,z,cyz)\nc\nc set y-z cross term coefficient at (x,y,z)\nc\n real x,y,z,czzr,czzi,cyyr,cyyi,cyzr,cyzi\n complex cxx,cyy,czz,cx,cy,cz,ce,cyz\n call cof(x,y,z,cxx,cyy,czz,cx,cy,cz,ce)\n cyyr = cyy\n cyyi = aimag(cyy)\n czzr = czz\n czzi = aimag(czz)\n cyzr = sqrt(cyyr*cyyi)\n cyzi = sqrt (cyyi*czzi)\n cyz = cmplx(cyzr,cyzi)\n return\n end\n\n subroutine bd3cr(kbdy,xory,yorz,a,b,c,g)\nc\nc pass mixed derivative boundary conditions to cud3cr\nc\n implicit none\n integer kbdy\n real x,y,z,xory,yorz\n complex a,b,c,g\n complex pe,px,py,pz,pxx,pyy,pzz,pxy,pxz,pyz\n if (kbdy.eq.2) then\nc\nc upper x boundary (mixed oblique)\nc\n\tx = 1.0\n\ty = xory\n\tz = yorz\n\ta = cmplx(z,1.-z)\n\tb = cmplx(sin(y),cos(y))\n\tc = - (1.0,1.0)\n\tcall exact(x,y,z,pe,px,py,pz,pxx,pyy,pzz,pxy,pxz,pyz)\n\tg = px + a*py + b*pz + c*pe\n\treturn\n else if (kbdy.eq.6) then\nc\nc upper z boundary (mixed normal)\nc\n\tz = 1.0\n\tx = xory\n\ty = yorz\n\tc = cmplx(x,sin(y)**2)\n\tcall exact(x,y,z,pe,px,py,pz,pxx,pyy,pzz,pxy,pxz,pyz)\n\tg = pz + a*px + b*py + c*pe\n\treturn\n end if\n end\n\n", "meta": {"hexsha": "44294dcf4871cd4103f99ce3a907fdbdb6ca0ffa", "size": 13494, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "external/mudpack/tcud3cr.f", "max_stars_repo_name": "utastudents/selalib", "max_stars_repo_head_hexsha": "84af43d0e82d4686a837c64384bbd173412df50e", "max_stars_repo_licenses": ["CECILL-B"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-03-11T15:22:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-22T16:26:18.000Z", "max_issues_repo_path": "external/mudpack/tcud3cr.f", "max_issues_repo_name": "utastudents/selalib", "max_issues_repo_head_hexsha": "84af43d0e82d4686a837c64384bbd173412df50e", "max_issues_repo_licenses": ["CECILL-B"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2021-06-30T20:39:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-15T12:42:50.000Z", "max_forks_repo_path": "external/mudpack/tcud3cr.f", "max_forks_repo_name": "utastudents/selalib", "max_forks_repo_head_hexsha": "84af43d0e82d4686a837c64384bbd173412df50e", "max_forks_repo_licenses": ["CECILL-B"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-03-13T17:09:10.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-22T00:30:19.000Z", "avg_line_length": 27.0963855422, "max_line_length": 77, "alphanum_fraction": 0.5094856973, "num_tokens": 5180, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424217727028, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.6620873885876272}} {"text": "PROGRAM LA_DGEEVX_ET_EXAMPLE\n!\n! -- LAPACK95 interface driver routine (version 3.0) --\n! UNI-C, Denmark; Univ. of Tennessee, USA; NAG Ltd., UK\n! September, 2000\n!\n! .. USE STATEMENTS\n USE LA_PRECISION, ONLY: WP => DP\n USE F95_LAPACK, ONLY: LA_GEEVX\n! .. IMPLICIT STATEMENT ..\n IMPLICIT NONE\n! .. PARAMETERS ..\n CHARACTER(LEN=*), PARAMETER :: FMT = '(8(1X,F10.3))'\n INTEGER, PARAMETER :: NIN=5, NOUT=6\n! .. LOCAL SCALARS ..\n INTEGER :: I, INFO, N, ILO, IHI\n REAL(WP) :: ABNRM\n! .. LOCAL ARRAYS ..\n REAL(WP), ALLOCATABLE :: AA(:,:), SCALE(:), RCONDE(:), RCONDV(:)\n REAL(WP), ALLOCATABLE :: A(:,:), WR(:), WI(:), VL(:,:), VR(:,:), DUMMY(:,:)\n! .. EXECUTABLE STATEMENTS ..\n WRITE (NOUT,*) 'DGEEVX ET_Example Program Results.'\n READ ( NIN, * ) ! SKIP HEADING IN DATA FILE\n READ ( NIN, * ) N\n PRINT *, 'N = ', N\n ALLOCATE ( A(N,N), AA(N,N), WR(N), WI(N), VL(N,N), VR(N,N), SCALE(N), &\n RCONDE(N), RCONDV(N) )\n!\n READ (NIN, *) AA\n A=AA\n WRITE(NOUT,*) 'The matrix A:'\n DO I = 1, N; WRITE (NOUT,*) 'I = ', I; WRITE (NOUT,FMT) A(I,:); ENDDO\n!\n WRITE ( NOUT, * )'---------------------------------------------------------'\n WRITE ( NOUT, * )\n WRITE ( NOUT, * )'Details of LA_DGEEVX LAPACK Subroutine Results.'\n WRITE ( NOUT, * )\n!\n WRITE(NOUT,*)\n WRITE(NOUT,*) 'CALL LA_GEEVX( A, WR, WI, VL, VR, BALANC, &'\n WRITE(NOUT,*) ' ILO, IHI, SCALE, ABNRM, RCONDE, RCONDV, INFO )'\n A=AA\n CALL LA_GEEVX( A, WR, WI, VL, VR, 'N', ILO, IHI, SCALE, &\n ABNRM, RCONDE, RCONDV, INFO )\n WRITE(NOUT,*) ' ILO, IHI, INFO:', ILO, IHI, INFO\n WRITE(NOUT,*) ' SCALE, ABNRM, RCONDE, RCONDV:'\n WRITE(NOUT,*) SCALE, ABNRM, RCONDE, RCONDV\n WRITE(NOUT,*) ' Eigenvalues:'\n WRITE(NOUT,FMT) WR\n WRITE(NOUT,FMT) WI\n WRITE(NOUT,*) 'Eigenvectors ( VL and VR ):'\n DO I = 1, N; WRITE(NOUT,*) 'I = ', I; WRITE (NOUT,FMT) VL(:,I); END DO\n DO I = 1, N; WRITE(NOUT,*) 'I = ', I; WRITE (NOUT,FMT) VR(:,I); END DO\n!\n WRITE(NOUT,*)\n WRITE(NOUT,*) 'CALL LA_GEEVX( A, WR, WI, VL )'\n A=AA\n CALL LA_GEEVX( A, WR, WI, VL )\n WRITE(NOUT,*) 'INFO = ', INFO, ' Eigenvalues:'\n WRITE(NOUT,FMT) WR\n WRITE(NOUT,FMT) WI\n WRITE(NOUT,*) 'Eigenvectors ( Only VL ):'\n DO I = 1, N; WRITE(NOUT,*) 'I = ', I; WRITE (NOUT,FMT) VL(:,I); END DO\n!\n WRITE(NOUT,*)\n WRITE(NOUT,*) 'CALL LA_GEEVX( A, WR, WI, VR )'\n A=AA\n CALL LA_GEEVX( A, WR, WI, VR )\n WRITE(NOUT,*) 'INFO = ', INFO, ' Eigenvalues:'\n WRITE(NOUT,FMT) WR\n WRITE(NOUT,FMT) WI\n WRITE(NOUT,*) 'Eigenvectors ( Only VR ):'\n DO I = 1, N; WRITE(NOUT,*) 'I = ', I; WRITE (NOUT,FMT) VR(:,I); END DO\n!\n WRITE(NOUT,*)\n WRITE(NOUT,*) 'CALL LA_GEEVX( A, WR, WI, INFO=INFO )'\n A=AA\n CALL LA_GEEVX( A, WR, WI, INFO=INFO )\n WRITE(NOUT,*) 'INFO = ', INFO, ' Eigenvalues:'\n WRITE(NOUT,FMT) WR\n WRITE(NOUT,FMT) WI\n!\n WRITE(NOUT,*)\n WRITE(NOUT,*) 'CALL LA_GEEVX( A, WR, WI, BALANC=''P'', INFO=INFO )'\n A=AA\n CALL LA_GEEVX( A, WR, WI, BALANC='P', INFO=INFO )\n WRITE(NOUT,*) 'INFO = ', INFO, ' Eigenvalues:'\n WRITE(NOUT,FMT) WR\n WRITE(NOUT,FMT) WI\n!\n WRITE(NOUT,*)\n WRITE(NOUT,*) 'CALL LA_GEEVX( A, WR, WI, BALANC=''S'', INFO=INFO )'\n A=AA\n CALL LA_GEEVX( A, WR, WI, BALANC='S', INFO=INFO )\n WRITE(NOUT,*) 'INFO = ', INFO, ' Eigenvalues:'\n WRITE(NOUT,FMT) WR\n WRITE(NOUT,FMT) WI\n!\n WRITE(NOUT,*)\n WRITE(NOUT,*) 'CALL LA_GEEVX( A, WR, WI, BALANC=''B'', INFO=INFO )'\n A=AA\n CALL LA_GEEVX( A, WR, WI, BALANC='B', INFO=INFO )\n WRITE(NOUT,*) 'INFO = ', INFO, ' Eigenvalues:'\n WRITE(NOUT,FMT) WR\n WRITE(NOUT,FMT) WI\n!\n WRITE(NOUT,*)\n WRITE(NOUT,*) 'CALL LA_GEEVX( A, WR, WI, BALANC=''1'', INFO=INFO )'\n A=AA\n CALL LA_GEEVX( A, WR, WI, BALANC='1', INFO=INFO )\n WRITE(NOUT,*) 'INFO = ', INFO, ' Eigenvalues:'\n WRITE(NOUT,FMT) WR\n WRITE(NOUT,FMT) WI\n!\n WRITE(NOUT,*)\n WRITE(NOUT,*) 'CALL LA_GEEVX( DUMMY, WR, WI, VL, VR, INFO=INFO )'\n A=AA\n CALL LA_GEEVX( DUMMY, WR, WI, VL, VR, INFO=INFO )\n WRITE(NOUT,*) 'INFO = ', INFO\n!\n WRITE(NOUT,*)\n WRITE(NOUT,*) 'CALL LA_GEEVX( A, WR(1:N-1), WI, VL, VR, INFO=INFO )'\n A=AA\n CALL LA_GEEVX( A, WR(1:N-1), WI, VL, VR, INFO=INFO )\n WRITE(NOUT,*) 'INFO = ', INFO\n!\n WRITE(NOUT,*)\n WRITE(NOUT,*) 'CALL LA_GEEVX( A, WR, WI(1:N-1), VL, VR, INFO=INFO )'\n A=AA\n CALL LA_GEEVX( A, WR, WI(1:N-1), VL, VR, INFO=INFO )\n WRITE(NOUT,*) 'INFO = ', INFO\n!\n WRITE(NOUT,*)\n WRITE(NOUT,*) 'CALL LA_GEEVX( A, WR, WI, VL(1:N-1,:), VR, INFO=INFO )'\n A=AA\n CALL LA_GEEVX( A, WR, WI, VL(1:N-1,:), VR, INFO=INFO )\n WRITE(NOUT,*) 'INFO = ', INFO\n!\n WRITE(NOUT,*)\n WRITE(NOUT,*) 'CALL LA_GEEVX( A, WR, WI, VL(:,1:N-1), VR, INFO=INFO )'\n A=AA\n CALL LA_GEEVX( A, WR, WI, VL(:,1:N-1), VR, INFO=INFO )\n WRITE(NOUT,*) 'INFO = ', INFO\n!\n WRITE(NOUT,*)\n WRITE(NOUT,*) 'CALL LA_GEEVX( A, WR, WI, VL, VR(1:N-1,:), INFO=INFO )'\n A=AA\n CALL LA_GEEVX( A, WR, WI, VL, VR(1:N-1,:), INFO=INFO )\n WRITE(NOUT,*) 'INFO = ', INFO\n!\n WRITE(NOUT,*)\n WRITE(NOUT,*) 'CALL LA_GEEVX( A, WR, WI, VL, VR(:,1:N-1), INFO=INFO )'\n A=AA\n CALL LA_GEEVX( A, WR, WI, VL, VR(:,1:N-1), INFO=INFO )\n WRITE(NOUT,*) 'INFO = ', INFO\n!\nEND PROGRAM LA_DGEEVX_ET_EXAMPLE\n", "meta": {"hexsha": "ec3973db218bb5f21495d5d06db818561dfe9cae", "size": 5204, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "EXAMPLES2/dgeevxet.f90", "max_stars_repo_name": "MattBurn/LAPACK95", "max_stars_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-12-29T15:07:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T10:09:22.000Z", "max_issues_repo_path": "EXAMPLES2/dgeevxet.f90", "max_issues_repo_name": "MattBurn/LAPACK95", "max_issues_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-12-30T15:38:47.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-31T06:45:11.000Z", "max_forks_repo_path": "EXAMPLES2/dgeevxet.f90", "max_forks_repo_name": "MattBurn/LAPACK95", "max_forks_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-12-29T15:34:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-15T07:12:40.000Z", "avg_line_length": 32.9367088608, "max_line_length": 80, "alphanum_fraction": 0.5497694081, "num_tokens": 2117, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6620627389921138}} {"text": "!==============================================================================!\n real function Normalized_Root_Mean_Square(ni, r, a, x, norm)\n!------------------------------------------------------------------------------!\n! Calculates root means square of vector r, normalizing it with entries !\n! in the system matrix (a), values of unknown (x) and optional norm. !\n!------------------------------------------------------------------------------!\n implicit none\n!---------------------------------[Arguments]----------------------------------!\n integer :: ni\n real :: r(:) ! this may be only in inner cells\n type(Matrix_Type) :: a\n real :: x(:) ! presumably, this goes to buffer cells\n real, optional :: norm ! optional number for normalization\n!-----------------------------------[Locals]-----------------------------------!\n real :: rms, x_max, x_min\n integer :: i\n!==============================================================================!\n\n ! Compute rms normalizing it with main diagonal in the system matrix\n rms = 0.0\n do i = 1, ni\n rms = rms + r(i)**2 / a % val(a % dia(i))**2\n end do\n call Comm_Mod_Global_Sum_Real(rms)\n rms = sqrt(rms)\n\n ! Normalize it with absolute values of the unknown\n if(.not. present(norm)) then\n x_min = minval(x(1:ni))\n x_max = maxval(x(1:ni))\n else\n x_min = 0.0\n x_max = norm\n endif\n call Comm_Mod_Global_Min_Real(x_min)\n call Comm_Mod_Global_Max_Real(x_max)\n\n ! Create a plateau for very small sources and values\n if( (x_max-x_min) < NANO .and. rms < NANO ) then\n rms = PICO\n else\n rms = rms / (x_max - x_min + TINY)\n end if\n\n Normalized_Root_Mean_Square = rms\n\n end function\n", "meta": {"hexsha": "03541edd085e9e50e8688a41020972e2525d97b8", "size": 1730, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Sources/Process/Solver_Mod/Normalized_Root_Mean_Square.f90", "max_stars_repo_name": "Dundj/Convex_Geomotry", "max_stars_repo_head_hexsha": "38507824d97270b3e4ead194a16148ff6158b59f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 64, "max_stars_repo_stars_event_min_datetime": "2018-05-29T09:39:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T13:59:18.000Z", "max_issues_repo_path": "Sources/Process/Solver_Mod/Normalized_Root_Mean_Square.f90", "max_issues_repo_name": "EdinSmartLab/T-Flows", "max_issues_repo_head_hexsha": "5a7f70421f18069453977142e6515cdc959a9e50", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 124, "max_issues_repo_issues_event_min_datetime": "2018-05-28T12:58:20.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-03T11:12:31.000Z", "max_forks_repo_path": "Sources/Process/Solver_Mod/Normalized_Root_Mean_Square.f90", "max_forks_repo_name": "EdinSmartLab/T-Flows", "max_forks_repo_head_hexsha": "5a7f70421f18069453977142e6515cdc959a9e50", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 39, "max_forks_repo_forks_event_min_datetime": "2018-05-28T13:13:06.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-27T17:41:08.000Z", "avg_line_length": 36.0416666667, "max_line_length": 80, "alphanum_fraction": 0.4664739884, "num_tokens": 416, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6620627389921138}} {"text": " PROGRAM xtoeplz\r\nC driver for routine toeplz\r\n INTEGER N,N2\r\n PARAMETER(N=5,N2=2*N)\r\n INTEGER i,j\r\n REAL sum,x(N),y(N),r(N2)\r\n do 11 i=1,N\r\n y(i)=0.1*i\r\n11 continue\r\n do 12 i=1,2*N-1\r\n r(i)=1./i\r\n12 continue\r\n call toeplz(r,x,y,N)\r\n write(*,*) 'Solution vector:'\r\n do 13 i=1,N\r\n write(*,'(5x,a2,i1,a4,e13.6)') 'X(',i,') = ',x(i)\r\n13 continue\r\n write(*,'(/1x,a)') 'Test of solution:'\r\n write(*,'(1x,t6,a,t19,a)') 'mtrx*soln','original'\r\n do 15 i=1,N\r\n sum=0.0\r\n do 14 j=1,N\r\n sum=sum+r(N+i-j)*x(j)\r\n14 continue\r\n write(*,'(1x,2f12.4)') sum,y(i)\r\n15 continue\r\n END\r\n", "meta": {"hexsha": "307bebf6f7404d49bdd18804eeb267547f150a11", "size": 707, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xtoeplz.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xtoeplz.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xtoeplz.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.25, "max_line_length": 58, "alphanum_fraction": 0.4582743989, "num_tokens": 269, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619885, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6620627356013556}} {"text": "PROGRAM freq2d\r\n! Generate pairs of random numbers and put into 256 x 256 bins.\r\n\r\nIMPLICIT NONE\r\nINTEGER :: i, j, k, l, lower, ndf, nrows, ncols, upper\r\nREAL :: x(2), aver, stdev, chisq\r\nINTEGER, ALLOCATABLE :: freq(:,:), seed(:)\r\nCHARACTER (LEN=200) :: text\r\n\r\nWRITE(*, *) 'Enter number of rows & columns (e.g. 24 64): '\r\nREAD(*, *) nrows, ncols\r\nALLOCATE( freq(0:nrows-1,0:ncols-1) )\r\n\r\n! Set the random number seed.\r\n\r\nCALL RANDOM_SEED(size=k)\r\nALLOCATE (seed(k))\r\nCALL RANDOM_SEED(get=seed)\r\nWRITE(*, *)'Old random number seeds: ', seed\r\n\r\nWRITE(*, '(a, i4, a)') ' Enter ', k, ' integers as random number seeds: '\r\nREAD(*, *) seed\r\nCALL RANDOM_SEED(put=seed)\r\n\r\n! Generate 4096 x 4096 pairs of random numbers\r\n\r\nfreq = 0\r\nDO i = 1, 4096\r\n DO j = 1, 4096\r\n CALL RANDOM_NUMBER(x)\r\n k = nrows * x(1)\r\n l = ncols * x(2)\r\n freq(k,l) = freq(k,l) + 1\r\n END DO\r\nEND DO\r\n\r\n! Average & variance of number in each cell = 4096 x 4096 / (nrows x ncols)\r\naver = 4096. * 4096. / (nrows * ncols)\r\nstdev = SQRT(aver)\r\nupper = aver + 3.*stdev + 0.5\r\nlower = aver - 3.*stdev + 0.5\r\n\r\nchisq = 0.0\r\nDO k = 0, nrows-1\r\n text = ' '\r\n DO l = 0, ncols-1\r\n IF (freq(k,l) >= lower .AND. freq(k,l) <= upper) THEN\r\n text(l+3:l+3) = '+'\r\n ELSE IF (freq(k,l) > upper) THEN\r\n text(l+3:l+3) = CHAR(219)\r\n END IF\r\n chisq = chisq + (freq(k,l) - aver)**2\r\n END DO\r\n WRITE(*, '(a)') TRIM(text)\r\nEND DO\r\n\r\nWRITE(*, *) ' If most of the cells are NOT pluses, its a bad generator'\r\n\r\nchisq = chisq / aver\r\nndf = nrows * ncols - 1\r\nWRITE(*, '(a, f10.1, a, i6, a)') &\r\n ' Chi-squared =', chisq, ' with', ndf, ' deg. of freedom'\r\nchisq = ndf + 2.0*SQRT(2.0*ndf)\r\nWRITE(*, '(a, f10.1)') ' Chi-squared should be less than', chisq\r\n\r\nSTOP\r\nEND PROGRAM freq2d\r\n", "meta": {"hexsha": "3447dff4ff9d335a4475568a65c4a9c1860a2843", "size": 1803, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/freq2d.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/freq2d.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/freq2d.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.5147058824, "max_line_length": 76, "alphanum_fraction": 0.5679423184, "num_tokens": 661, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6620627344903562}} {"text": "! DART software - Copyright UCAR. This open source software is provided\n! by UCAR, \"as is\", without charge, subject to all terms of use at\n! http://www.image.ucar.edu/DAReS/DART/DART_download\n!\n! $Id$\n\nprogram sys_sim502\n\n! Looks at how to deal with correlation errors given null assumption about \n! a uniform distribution for the underlying true correlation distirubtions.\n! Generates a huge sample of [-1, 1) uniform correlations, then samples these,\n! and keeps track of the sample correlation / true correlation pairs. Then\n! it bins these together over small sample correlation ranges and looks at\n! the value of alpha that would minimize errors. NOTE: this gives much less\n! info than group filter because group filter draws from a much more \n! meaningful prior (i.e. from what the model and assim have generated).\n\nuse types_mod, only : r8\nuse random_seq_mod, only : random_seq_type, init_random_seq, random_gaussian, &\n twod_gaussians, random_uniform\n\nimplicit none\n\n! version controlled file description for error handling, do not edit\ncharacter(len=256), parameter :: source = &\n \"$URL$\"\ncharacter(len=32 ), parameter :: revision = \"$Revision$\"\ncharacter(len=128), parameter :: revdate = \"$Date$\"\n\ninteger, parameter :: num_bins = 50\nreal(r8) :: sum(num_bins) = 0.0, sum2(num_bins)\ninteger :: num(num_bins) = 0.0\ntype (random_seq_type) :: r\nreal(r8) :: correl, cov(2, 2), zero_2(2) = 0.0, correl_mean, correl_var, sd\nreal(r8) :: q, alpha, alpha2, mean_abs_correl, sample_correl, real_correl\nreal(r8), allocatable :: pairs(:, :)\nreal(r8) :: bottom_cor, top_cor, sum_sample2, sum_sample_real, sum_real\nreal(r8) :: q_factor\ninteger :: ens_size, n_samples, i, j, k, sample_size, bin\n\n! Generate a bazillion cases where the background correlation is assumed to \n! be U(-1, 1)\n! For each case sampled from this, create a SAMPLE correlation\n! and store the sample correlation and the actual correlation in a huge\n! array.\n\n! Initialize repeatable random sequence\ncall init_random_seq(r) \n\n! For now have a set of free parameters that may be too large\nwrite(*, *) 'Input ensemble size'\nread(*, *) ens_size \nwrite(*, *) 'Input number of samples for statistics'\nread(*, *) n_samples\n\n! Allocate storage for sample from this correlation\nallocate(pairs(2, ens_size))\n\n! Loop through a set of sample draws from uniform (-1, 1)\ndo k = 1, n_samples\n 111 real_correl = -1.0 + 2.0 * random_uniform(r)\n ! Generate the covariance matrix for this correlation\n cov(1, 1) = 1.0; cov(2, 2) = 1.0\n cov(1, 2) = real_correl; cov(2, 1) = real_correl\n\n ! Loop to generate an ensemble size sample from this correl\n ! Generate a random sample of size ens_size from something with this correlation\n do i = 1, ens_size\n call twod_gaussians(r, zero_2, cov, pairs(:, i))\n end do\n\n ! Compute the sample correlation\n call comp_correl(pairs, ens_size, sample_correl) \n\n !!! if(sample_correl > 0.1 .or. sample_correl < -0.1) goto 111\n \n !!!write(*, *) k, real_correl, sample_correl\n\n ! Now adjust the information for the appropriate sample_correl bin\n bin = (sample_correl + 1.0) / 2.0 * (num_bins) + 1\n\n num(bin) = num(bin) + 1\n sum(bin) = sum(bin) + real_correl\n sum2(bin) = sum2(bin) + real_correl*real_correl\n\nend do\n\ndo i = 1, num_bins\n ! Output sample and mean real for this bin\n sample_correl = ((i - 0.5) / num_bins) * 2.0 - 1.0\n real_correl = sum(i) / num(i)\n sd = sqrt((sum2(i) - num(i) * real_correl**2) / (num(i) - 1.0))\n q = sd / abs(real_correl)\n q_factor = (num(i) - q**2) / ((num(i) - 1) * q + num(i))\n write(*, 11) i, num(i), sample_correl, real_correl, &\n real_correl / sample_correl, sd, q_factor\n 11 format(i4, 1x, i8, 1x, 5(e10.4, 1x))\nend do\n\nif(1 == 1) stop\n\n!!! write(*, *) 'optimal alpha is ', sum_sample_real / sum_sample2, sample_size\n!!! write(*, *) 'mean real_correl is ', sum_real / sample_size\n\nend program sys_sim502\n\n!-----------------------------------------------------\n\nsubroutine comp_correl(ens, n, correl)\n\nimplicit none\n\ninteger, intent(in) :: n\ndouble precision, intent(in) :: ens(2, n)\ndouble precision, intent(out) :: correl\ndouble precision :: sum_x, sum_y, sum_xy, sum_x2, sum_y2\n\n\nsum_x = sum(ens(2, :))\nsum_y = sum(ens(1, :))\nsum_xy = sum(ens(2, :) * ens(1, :))\nsum_x2 = sum(ens(2, :) * ens(2, :))\n\n! Computation of correlation\nsum_y2 = sum(ens(1, :) * ens(1, :))\n\ncorrel = (n * sum_xy - sum_x * sum_y) / &\n sqrt((n * sum_x2 - sum_x**2) * (n * sum_y2 - sum_y**2))\n\nend subroutine comp_correl\n\n!----------------------------------------------------------------\n\n!----------------------------------------------------------------\n\nsubroutine sample_mean_var(x, n, mean, var)\n\nimplicit none\n\ninteger, intent(in) :: n\ndouble precision, intent(in) :: x(n)\ndouble precision, intent(out) :: mean, var\n\ndouble precision :: sx, s_x2\n\nsx = sum(x)\ns_x2 = sum(x * x)\nmean = sx / n\nvar = (s_x2 - sx**2 / n) / (n - 1)\n\nend subroutine sample_mean_var\n\n", "meta": {"hexsha": "854424f77e59be29111a5330de0e323ae5b6878a", "size": 4935, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "assimilation_code/programs/system_simulation/sys_sim502.f90", "max_stars_repo_name": "hkershaw-brown/feature-preprocess", "max_stars_repo_head_hexsha": "fe2bd77b38c63fa0566c83ebc4d2fac1623aef66", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-07-05T03:43:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-05T11:39:49.000Z", "max_issues_repo_path": "assimilation_code/programs/system_simulation/sys_sim502.f90", "max_issues_repo_name": "hkershaw-brown/feature-preprocess", "max_issues_repo_head_hexsha": "fe2bd77b38c63fa0566c83ebc4d2fac1623aef66", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-03-31T04:16:45.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-31T04:16:45.000Z", "max_forks_repo_path": "assimilation_code/programs/system_simulation/sys_sim502.f90", "max_forks_repo_name": "hkershaw-brown/feature-preprocess", "max_forks_repo_head_hexsha": "fe2bd77b38c63fa0566c83ebc4d2fac1623aef66", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-20T23:36:16.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-20T23:36:16.000Z", "avg_line_length": 32.2549019608, "max_line_length": 83, "alphanum_fraction": 0.6616008105, "num_tokens": 1476, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680904463333, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6620627187630841}} {"text": " double complex function Aslcphiqarbmppm(j1,j2,j3,j4,za,zb) \n implicit none \n include 'constants.f'\n include 'zprods_decl.f'\n include 'sprods_com.f'\n include 'epinv.f'\n include 'scale.f'\n include 'deltar.f'\n double precision s12,s13,s41,s23,s24,s34\n double precision s123,s234,s341,s412,mhsq\n double complex Vslc,Lsm1_2me,L0,L1,lnrat,A0phiqarbmppm\n integer j1,j2,j3,j4\n s12=s(j1,j2)\n s13=s(j1,j3)\n s41=s(j4,j1)\n s23=s(j2,j3)\n s24=s(j2,j4)\n s34=s(j3,j4)\n s123=s12+s13+s23\n s234=s23+s24+s34\n s341=s34+s41+s13\n s412=s41+s12+s24\n mhsq=s12+s13+s41+s23+s24+s34\n\nC---arXIv:09060008v1 Eq.(4.11)\n Vslc=\n & -epinv**2*2d0\n & -epinv*lnrat(musq,-s12)-epinv*lnrat(musq,-s34)\n & -0.5d0*lnrat(musq,-s12)**2-0.5d0*lnrat(musq,-s34)**2\n & -3d0/2d0*(2d0*epinv+lnrat(musq,-s12)+lnrat(musq,-s34))\n & -Lsm1_2me(s412,s123,s12,mhsq)\n & -Lsm1_2me(s234,s341,s34,mhsq)\n & -7d0-deltar\n\nC---arXIv:09060008v1 Eq.(4.10)\nc--- the function defined in this routine is in fact (-i*A_4),\nc--- i.e. complete LHS\n Aslcphiqarbmppm=A0phiqarbmppm(j1,j2,j3,j4,za,zb)*Vslc\n & +0.5d0*za(j1,j2)*za(j3,j4)*zb(j2,j3)**2\n & *(L1(-s123,-s12)/s12**2 + L1(-s234,-s34)/s34**2)\n & - za(j1,j4)*zb(j2,j3)*(L0(-s123,-s12)/s12+L0(-s234,-s34)/s34)\n return\n end\n\n", "meta": {"hexsha": "9c15449be52c4b208827c23fb33ffb534a25af3e", "size": 1380, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "MCFM-JHUGen/src/H4pCode/Aslcphiqarbmppm.f", "max_stars_repo_name": "tmartini/JHUGen", "max_stars_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-06-08T13:09:28.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-04T19:59:36.000Z", "max_issues_repo_path": "MCFM-JHUGen/src/H4pCode/Aslcphiqarbmppm.f", "max_issues_repo_name": "tmartini/JHUGen", "max_issues_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 64, "max_issues_repo_issues_event_min_datetime": "2015-06-24T15:08:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-25T04:59:32.000Z", "max_forks_repo_path": "MCFM-JHUGen/src/H4pCode/Aslcphiqarbmppm.f", "max_forks_repo_name": "tmartini/JHUGen", "max_forks_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2015-05-04T22:15:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-06T10:04:40.000Z", "avg_line_length": 30.6666666667, "max_line_length": 68, "alphanum_fraction": 0.5927536232, "num_tokens": 621, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9603611586300241, "lm_q2_score": 0.6893056231680122, "lm_q1q2_score": 0.661982346915823}} {"text": "function ifft2(yh) result(y)\n! IFFT2 function\ncomplex(kind=8), intent(in) :: yh(:,:)\ninteger(kind=8) :: plan_backward\ncomplex(kind=8), allocatable :: y(:,:)\nallocate(yh(size(y,1),size(y,2)))\ncall dfftw_plan_dft_2d_ (plan_backward, size(yh,1), size(yh,2), yh, y, FFTW_BACKWARD, FFTW_MEASURE)\ncall dfftw_execute(plan_backward)\ny = y/real(size(y,1) * size(y,2),dp)\nend function ifft2", "meta": {"hexsha": "6d070f0a05b1774021e227944294fce29b9d753d", "size": 403, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "partitioned/fortran/tools/functions/ifft2.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/ifft2.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/ifft2.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": 40.3, "max_line_length": 99, "alphanum_fraction": 0.6724565757, "num_tokens": 140, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045817875224, "lm_q2_score": 0.7461390043208003, "lm_q1q2_score": 0.661977943283794}} {"text": "module elemental_procedure\n implicit none\ncontains\n elemental real function f(x,y)\n real, intent(in) :: x,y\n f = sqrt(x**2 + y**2)\n end function f\nend module elemental_procedure\n", "meta": {"hexsha": "12c7e678e03faf9d98a9019189426f831aadc78b", "size": 188, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/modules/elemental_procedure.f90", "max_stars_repo_name": "annefou/Fortran", "max_stars_repo_head_hexsha": "9d3d81de1ae32723e64eb3d07195867293a82c5e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 32, "max_stars_repo_stars_event_min_datetime": "2016-04-08T19:04:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-13T15:44:37.000Z", "max_issues_repo_path": "src/modules/elemental_procedure.f90", "max_issues_repo_name": "inandi2/Fortran-1", "max_issues_repo_head_hexsha": "9d3d81de1ae32723e64eb3d07195867293a82c5e", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/modules/elemental_procedure.f90", "max_forks_repo_name": "inandi2/Fortran-1", "max_forks_repo_head_hexsha": "9d3d81de1ae32723e64eb3d07195867293a82c5e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2016-04-08T19:05:49.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-08T19:57:51.000Z", "avg_line_length": 20.8888888889, "max_line_length": 32, "alphanum_fraction": 0.7021276596, "num_tokens": 53, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8872045817875224, "lm_q2_score": 0.7461389930307512, "lm_q1q2_score": 0.6619779332672107}} {"text": "!/*******************************************************\n! * Calculating Pi with using midpoint rectangle method:*\n! * integral 4.0/(1+x^2) dx = pi\t \t \t*\n! * or \t\t\t\t\t\t*\n! * summation (for i=0 to n) 4.0/(1+x_i^2) *\n! * \twhere x_i = (i + 1/2) * delta x\t\t\t*\n! * \t OpenMP Version 1\t \t\t\t*\n! *******************************************************/\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,omp_get_wtime\nstart=omp_get_wtime()\nstep = 1/(1.0 * num_steps)\n\tdo i =1,num_steps\n ! Write an algorithm which first evaluates the \n ! \tevaluate midpoint of ith rectangle (x_i)\n ! \tupdates the sum by evaluating f(x) at x\n\tend do\n ! Uptade value of pi\nfinish=omp_get_wtime() \n\twrite(*,*) \"Estimated value of pi =\",pi\n\twrite(*,*) \"Error =\", abs(PI_ref - pi)\n\twrite(*,*) \"Compute time=\", (finish-start),\" seconds\"\n\tend\n\n\n", "meta": {"hexsha": "64344693d77eb2f2c802d122e56359e19b03a852", "size": 961, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Workbench/Exercise1/ftn/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": "Workbench/Exercise1/ftn/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": "Workbench/Exercise1/ftn/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": 31.0, "max_line_length": 58, "alphanum_fraction": 0.5525494277, "num_tokens": 295, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403959948494, "lm_q2_score": 0.7122321964553657, "lm_q1q2_score": 0.6619773747137565}} {"text": "SUBROUTINE linmul_sky(kv,disps,loads,kdiag)\n!\n! This subroutine forms the product of symmetric matrix stored as\n! a skyline and a vector.\n!\n IMPLICIT NONE\n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\n REAL(iwp),INTENT(IN)::kv(:),disps(0:)\n REAL(iwp),INTENT(OUT)::loads(0:)\n INTEGER,INTENT(IN)::kdiag(:)\n INTEGER::n,i,j,low,lup,k\n REAL(iwp)::x,zero=0.0_iwp\n n=UBOUND(disps,1)\n DO i=1,n\n x=zero \n lup=kdiag(i)\n IF(i==1)low=lup\n IF(i/=1)low=kdiag(i-1)+1\n DO j=low,lup\n x=x+kv(j)*disps(i+j-lup) \n END DO\n loads(i)=x\n IF(i==1)CYCLE \n lup=lup-1\n DO j=low,lup\n k=i+j-lup-1\n loads(k)=loads(k)+kv(j)*disps(i) \n END DO\n END DO\nRETURN\nEND SUBROUTINE linmul_sky \n", "meta": {"hexsha": "3e5cf2aa418230ab8d7f8de30225a3662b892d1c", "size": 697, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "main/linmul_sky.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/linmul_sky.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/linmul_sky.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": 21.78125, "max_line_length": 65, "alphanum_fraction": 0.6384505022, "num_tokens": 270, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357735451835, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6619677355224839}} {"text": "program ising ! 2D Monte Carlo Simulation of Ising Model\n! Lisa Larrimore, lisal@sccs.swarthmore.edu\n! 3 May 2002\n! Physics 114 Final Project\n! This program is adapted from the Ising Model program written in\n! BASIC by Elaine Chandler that appears on p. 184 of David Chandler\u2019s\n! Introduction to Modern Statistical Mechanics.\n\n ! The input parameters for this program are in \"ising.in\", and they\n ! allow the size, length, and initial configuration of the simulation\n ! to be changed. See comments in file.\n\n ! This program has three output files:\n !\n ! \"spin-array\" Contains snapshots of the spin lattice at the end of\n ! each temperature run (or throughout the middle of the\n ! run, if only looking at one temperature). Can be\n ! visualized with the IDL program see_spins.pro\n !\n ! \"magnetization\" Contains four columns: each temperature, the\n ! average magnetization at that temp, the ave magnetizaion\n ! squared at that temp, and the susceptibility.\n !\n ! \"energy\" Contains four columns: each temperature, the\n ! average energy at that temp, the ave energy squared\n ! at that temp, and the heat capacity.\n\n implicit none\n\n ! Variable declarations:\n integer :: i, j, m, n, m2, n2 ! dummy integers\n integer, allocatable :: A(:,:) ! matrix containing spins\n integer :: nrows, ncols ! number of rows and cols of A\n real :: temp, beta ! temperature, inverse temperature\n integer :: ConfigType ! starting configuration type\n integer :: npass ! number of passes for MC algorithm\n integer :: ipass ! the current pass number\n integer :: nequil ! number of equilibration steps\n integer :: trial_spin ! values of changed spin\n real :: high_temp ! starting temp for scan\n real :: low_temp ! final temp for scan\n real :: temp_interval ! interval between scan points\n integer :: nscans ! number of scans (each at diff T)\n integer :: iscan ! current scan number\n logical :: MovieOn ! set to .true. to make movie of 1 temp\n real :: deltaU ! change in energy between 2 configs\n real :: deltaU1 ! energy changes for lattice gas\n real :: log_eta ! log of random number to compare to\n real :: magnetization ! magnetization of all spins in lattice\n real :: magnetization_ave ! cumulative average magnetization\n real :: magnetization2_ave ! cumulative average of mag. squared\n real :: energy ! energy of all spins in lattice\n real :: energy_ave ! cumulative average of energy\n real :: energy2_ave ! cumulative average of energy squared\n integer :: output_count ! # times things have been added to averages\n\n print*, \"________________MONTE CARLO 2D ISING MODEL________________\"\n print*, \"Monte Carlo Statistics for 2D Ising Model with\"\n print*, \" periodic boundary conditions.\"\n print*, \"The critical temperature is approximately 2.3, as seen on\"\n print*, \" Chandler p. 123.\"\n\n ! Read in input parameters from file \"ising.in\"\n open(UNIT=11,FILE='ising.in',STATUS='old',ACTION='read')\n read(11,*);read(11,*) nrows\n read(11,*);read(11,*) ncols\n read(11,*);read(11,*) npass\n read(11,*);read(11,*) nequil\n read(11,*);read(11,*) high_temp\n read(11,*);read(11,*) low_temp\n read(11,*);read(11,*) temp_interval\n read(11,*);read(11,*) ConfigType\n read(11,*);read(11,*) MovieOn\n close(11)\n\n ! Set the dimensions of the matrix of spin arrays. This program uses\n ! periodic boundary conditions, so the first two rows and columns are\n ! the same as the last two.\n allocate(A(nrows+2,ncols+2))\n\n ! Open output files:\n open(unit=32,file='spin-array',status='replace',action='write')\n write(32,*) nrows\n write(32,*) ncols\n nscans = int((high_temp - low_temp)/temp_interval) + 1\n if (MovieOn) then\n write(32,*) 51\n write(32,*) 1\n else\n write(32,*) nscans\n write(32,*) 2\n endif\n\n open(unit=33,file='magnetization',status='replace',action='write')\n write(33,*) \"temp ave_magnetization ave_magnetization^2 susceptibility\"\n open(unit=34,file='energy',status='replace',action='write')\n write(34,*) \"temp ave_energy ave_energy^2 C_v\"\n\n scan_loop: do iscan = 1, nscans\n temp = high_temp - temp_interval*(iscan-1)\n print*, \"Running program for T =\", temp\n\n ! Initialize variables\n beta = 1.0/temp\n output_count = 0\n energy_ave = 0.0\n energy2_ave = 0.0\n magnetization_ave = 0.0\n magnetization2_ave = 0.0\n\n ! Set up the initial spin configuration.\n select case(ConfigType)\n case(1) ! checkerboard setup\n \n !A(1,1) = 1\n do i = 1, nrows+2\n !A(i+1,1) = -A(i,1)\n \n do j = 1, ncols+2\n A(i,j) = 1\n !A(:,j+1) = -A(:,j)\n enddo\n enddo\n ! (note: the requirement that nrows and ncols are even is to\n ! ensure that the first two rows/cols start out the same as the\n ! last two)\n case(2) ! interface\n do i = 1, nrows+2\n do j = 1, (ncols+2)/2\n A(i,j) = 1\n enddo\n do j = (ncols+2)/2 + 1, ncols+2\n A(i,j) = -1\n enddo\n enddo\n case(3) ! unequal interface\n do i = 1, nrows+2\n do j = 1, (ncols+2)/4\n A(i,j) = 1\n enddo\n do j = (ncols+2)/4 + 1, ncols+2\n A(i,j) = -1\n enddo\n enddo\n case default\n print*, \"Error! Check ConfigType parameter in ising.in\"\n stop\n end select\n\n ! Main loop containing Monte Carlo algorithm:\n MC_passes: do ipass = 0, npass\n\n ! If MovieOn is .true., write the spin array to an output every\n ! npass/50 steps.\n if ((MovieOn) .and. (mod(ipass,npass/50) == 0)) then\n do i = 2, nrows+1\n do j = 2, ncols+1\n write(32,*) A(i,j)\n enddo\n enddo\n endif\n\n ! If ipass is greater than nequil (the number of equilibration steps),\n ! calculate the magnetization and energy:\n if (ipass > nequil) then\n output_count = output_count + 1\n magnetization = sum(A(2:nrows+1,2:nrows+1))/(ncols*nrows*1.0)\n magnetization_ave = magnetization_ave + magnetization\n magnetization2_ave = magnetization2_ave + magnetization**2\n energy = 0.0\n do i = 2, nrows + 1\n do j = 2, ncols + 1\n energy = energy - A(m,n)*(A(m-1,n)+A(m+1,n)+A(m,n-1)+A(m,n+1))\n enddo\n enddo\n ! Divide the energy by the total number of spins to get the ave\n ! energy per spin, and divide by 2 to account for double counting.\n energy = energy/(ncols*nrows*2.0)\n energy_ave = energy_ave + energy\n energy2_ave = energy2_ave + energy**2\n endif\n\n ! Randomly choose a spin to change:\n m = nint((nrows-1)*ran1(5) + 2) ! choose a random row\n n = nint((ncols-1)*ran1(5) + 2) ! choose a random column\n trial_spin = -A(m,n) ! trial spin value\n\n ! Find change in energy (deltaU) due to trial move.\n ! If exp(-beta*deltaU) > eta, where eta is random, accept move:\n deltaU = -trial_spin*(A(m-1,n)+A(m+1,n)+A(m,n-1)+A(m,n+1))*2\n log_eta = dlog(ran1(5) + 1.0d-10) ! random number 0-1 (+ tiny offset)\n if (-beta*deltaU > log_eta) then\n A(m,n) = trial_spin\n if (m == 2) A(nrows+2,n) = trial_spin\n if (m == nrows+1) A(1,n) = trial_spin\n if (n == 2) A(m,ncols+2) = trial_spin\n if (n == ncols+1) A(m,1) = trial_spin\n endif\n\n enddo MC_passes\n\n ! Write final spin array to output file\n if (.not. MovieOn) then\n do i = 2, nrows + 1\n do j = 2, ncols + 1\n write(32,*) A(i,j)\n enddo\n enddo\n endif\n write(33,*) temp, abs(magnetization_ave/output_count), &\n magnetization2_ave/output_count, &\n beta*(magnetization2_ave/output_count - (magnetization_ave/output_count)**2)\n write(34,*) temp, energy_ave/output_count, energy2_ave/output_count, &\n (beta**2)*(energy2_ave/output_count - (energy_ave/output_count)**2)\n\n enddo scan_loop\n\n close(32)\n close(33)\n close(34)\n\n print*, \"Program ising.f90 complete!\"\n print*, \"Look at \u2019spin-array\u2019 with IDL program see_spins.pro\"\n\n contains\n\n\n !_______RANDOM NUMBER GENERATING FUNCTION______!\n\n double precision function ran1(idum)\n implicit none\n double precision :: r(97)\n integer, intent(IN) :: idum\n save\n integer, parameter :: M1=259200,IA1=7141,IC1=54773\n real, parameter :: RM1=1.0d0/M1\n integer, parameter :: M2=134456,IA2=8121,IC2=28411\n real, parameter :: RM2=1.0d0/M2\n integer, parameter :: M3=243000,IA3=4561,IC3=51349\n integer :: IX1, IX2, IX3, jjj\n integer :: iff=0\n if (idum < 0 .or. iff == 0) then\n iff = 1\n IX1 = mod(IC1-idum,M1)\n IX1 = mod(IA1*IX1+IC1,M1)\n IX2 = mod(IX1,M2)\n IX1 = mod(IA1*IX1+IC1,M1)\n IX3 = mod(IX1,M3)\n do jjj = 1,97\n IX1 = mod(IA1*IX1+IC1,M1)\n IX2 = mod(IA2*IX2+IC2,M2)\n r(jjj) = (dfloat(IX1)+dfloat(IX2)*RM2)*RM1\n end do\n end if\n IX1 = mod(IA1*IX1+IC1,M1)\n IX2 = mod(IA2*IX2+IC2,M2)\n IX3 = mod(IA3*IX3+IC3,M3)\n jjj = 1+(97*IX3)/M3\n if (jjj > 97 .or. jjj < 1) write(*,*) \"asd\"\n ran1 = r(jjj)\n r(jjj) = (dfloat(IX1)+dfloat(IX2)*RM2)*RM1\n end function ran1\n\n end program ising", "meta": {"hexsha": "ddd37ab13c44835a60638489f82b84bceb20982f", "size": 8214, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "v1 otro/ising.f95", "max_stars_repo_name": "mattborghi/Thesis", "max_stars_repo_head_hexsha": "ca186a812f7aa0cefbd5848684d1e3cc36fecaae", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-10-15T09:02:43.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-15T09:02:43.000Z", "max_issues_repo_path": "v1 otro/ising.f95", "max_issues_repo_name": "mattborghi/Thesis", "max_issues_repo_head_hexsha": "ca186a812f7aa0cefbd5848684d1e3cc36fecaae", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "v1 otro/ising.f95", "max_forks_repo_name": "mattborghi/Thesis", "max_forks_repo_head_hexsha": "ca186a812f7aa0cefbd5848684d1e3cc36fecaae", "max_forks_repo_licenses": ["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.1136363636, "max_line_length": 77, "alphanum_fraction": 0.6968590212, "num_tokens": 2652, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357735451834, "lm_q2_score": 0.7634837527911057, "lm_q1q2_score": 0.6619677261904159}} {"text": " double complex function A51mmppp(j1,j2,j3,j4,j5,za,zb)\n implicit none\n include 'constants.f'\n include 'sprods_com.f'\n include 'zprods_decl.f'\n include 'epinv.f'\n include 'scale.f'\n double complex Vf,Vs,Ff,Fs,L0,L2,miA5tree,lnrat\n integer j1,j2,j3,j4,j5\nC----Eq.(8,10) of hep-ph/9302280v1 of BDK multiplied by 16*pi^2*(-i)\nC--- to give (16*pi^2)*(-i)*A^{[1/2]}_{5;1}\n miA5tree=za(j1,j2)**4\n & /(za(j1,j2)*za(j2,j3)*za(j3,j4)*za(j4,j5)*za(j5,j1))\n Vf=dcmplx(-2.5d0*epinv-2d0)\n & -0.5d0*(lnrat(musq,-s(j2,j3))+lnrat(musq,-s(j5,j1)))\n Vs=-Vf/3d0+dcmplx(2d0/9d0)\n Ff=-za(j1,j2)**2*L0(-s(j2,j3),-s(j5,j1))\n & *(za(j2,j3)*zb(j3,j4)*za(j4,j1)+za(j2,j4)*zb(j4,j5)*za(j5,j1))\n & /(2d0*za(j2,j3)*za(j3,j4)*za(j4,j5)*za(j5,j1)*s(j5,j1))\n Fs=-Ff/3d0\n & -zb(j3,j4)*za(j4,j1)*za(j2,j4)*zb(j4,j5)*L2(-s(j2,j3),-s(j5,j1))\n & *(za(j2,j3)*zb(j3,j4)*za(j4,j1)+za(j2,j4)*zb(j4,j5)*za(j5,j1))\n & /(3d0*za(j3,j4)*za(j4,j5)*s(j5,j1)**3)\n & -za(j3,j5)*zb(j3,j5)**3\n & /(3d0*zb(j1,j2)*zb(j2,j3)*za(j3,j4)*za(j4,j5)*zb(j5,j1))\n & +za(j1,j2)*zb(j3,j5)**2\n & /(3d0*zb(j2,j3)*za(j3,j4)*za(j4,j5)*zb(j5,j1))\n & +za(j1,j2)*zb(j3,j4)*za(j4,j1)*za(j2,j4)*zb(j4,j5)\n & /(6d0*s(j2,j3)*za(j3,j4)*za(j4,j5)*s(j5,j1))\n A51mmppp=-(Vf+Vs)*miA5tree-(Ff+Fs)\n\nc write(6,*) 'j1,j2,j3,j4,j5,miA5tree',j1,j2,j3,j4,j5,miA5tree\n return\n end\n", "meta": {"hexsha": "902b088653c594daa6c36d5bd832db88164e1672", "size": 1435, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "MCFM-JHUGen/src/Gamgam/A51mmppp.f", "max_stars_repo_name": "tmartini/JHUGen", "max_stars_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-06-08T13:09:28.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-04T19:59:36.000Z", "max_issues_repo_path": "MCFM-JHUGen/src/Gamgam/A51mmppp.f", "max_issues_repo_name": "tmartini/JHUGen", "max_issues_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 64, "max_issues_repo_issues_event_min_datetime": "2015-06-24T15:08:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-25T04:59:32.000Z", "max_forks_repo_path": "MCFM-JHUGen/src/Gamgam/A51mmppp.f", "max_forks_repo_name": "tmartini/JHUGen", "max_forks_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2015-05-04T22:15:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-06T10:04:40.000Z", "avg_line_length": 41.0, "max_line_length": 71, "alphanum_fraction": 0.5407665505, "num_tokens": 734, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422158380862, "lm_q2_score": 0.6959583124210896, "lm_q1q2_score": 0.6619553314071303}} {"text": " MODULE mod_kep\r\n CONTAINS\r\n SUBROUTINE kep(kep_io)\r\n IMPLICIT NONE \r\n INCLUDE 'kep_struct.h'\r\n TYPE(kep_struct) :: kep_io\r\n!=======================================================================\r\n!\r\n! SUBROUTINE kep computes the k-th eigenpair of generalized symmetric\r\n! definite eigenproblems. \r\n! \r\n! TYPE(kep_struct) kep_io includes the following variables:\r\n!\r\n! n : \r\n! matrix size\r\n!\r\n! nz_a : \r\n! number of non-zero elements of matrix A\r\n! indx_a : \r\n! row index of non-zero elements of matrix A.\r\n! ALLOCATE with dimension nz_a and assign values before call\r\n! jndx_a : \r\n! column index of non-zero elements of matrix A.\r\n! ALLOCATE with dimension nz_a and assign values before call\r\n! rval_a : \r\n! value of non-zero elements of matrix A.\r\n! ALLOCATE with dimension nz_a and assign values before call \r\n!\r\n! nz_b : \r\n! number of non-zero elements of matrix B\r\n! indx_b : \r\n! row index of non-zero elements of matrix B.\r\n! ALLOCATE with dimension nz_b and assign values before call\r\n! jndx_b : \r\n! column index of non-zero elements of matrix B.\r\n! ALLOCATE with dimension nz_b and assign values before call\r\n! rval_b : \r\n! value of non-zero elements of matrix B.\r\n! ALLOCATE with dimension nz_b and assign values before call \r\n!\r\n! k : \r\n! target index.\r\n! Required to satisfy 1 < k < n\r\n!\r\n! iprm : \r\n! parameters for SUBROUTINE kep\r\n! iprm(1) : stopping criterion for bisection\r\n! ( = maximum number of eigenpairs computed together).\r\n! Required to satisfy 1 <= iprm(1) < n.\r\n! See m_max in reference [1] \r\n! iprm(2) : 10**-iprm(2) is tolerance for relative residual 2-norm.\r\n! Required to satisfy 1 <= iprm(2) <= 16.\r\n! See tau_res in [1]\r\n! iprm(3) : 10**-iprm(3) is tolerance for relative difference 2-norm.\r\n! Required to satisfy 1 <= iprm(3) <= 16.\r\n! See tau_diff in [1] \r\n! iprm(11): maximum iterations to set an initial interval\r\n! ( = maximum iterations for Lanczos).\r\n! Required to satisfy 2 <= iprm(11) <= n.\r\n! See Algorithm 2 in [1]\r\n! iprm(12): maximum iterations to narrow down the interval\r\n! ( = maximum iterations for Bisection).\r\n! Required to satisfy 0 <= iprm(12) <= 64.\r\n! See Algorithm 1' in [1]\r\n! iprm(13): maximum iterations to compute eigenpairs of the interval\r\n! ( = maximum iterations for shift-and-invert Lanczos).\r\n! Required to satisfy iprm(1) <= iprm(13) <= n.\r\n! See Algorithm 3 in [1] \r\n! iprm(21): If iprm(21) > 0, print details of computation to terminal\r\n! iprm(22): If iprm(22) =< 0, output only the k-th eigenpair.\r\n! Otherwise, output all computed eigenpairs.\r\n! See the description of kndx, kval, and kvec below\r\n!\r\n! kndx : \r\n! If iprm(22) =< 0, kndx includes only the index k.\r\n! Otherwise, kndx includes the index of all computed\r\n! eigenpairs in increasing order\r\n! kval : \r\n! If iprm(22) =< 0, kval includes only the k-th eigenvalue.\r\n! Otherwise, kval includes all computed eigenvalues in\r\n! increasing order\r\n! kvec : \r\n! If iprm(22) =< 0, kvec includes only the k-th eigenvector\r\n! normalized with respect to 2-norm. Otherwise, kvec\r\n! includes all computed eigenvectors\r\n!\r\n! info : \r\n! diagonostic information\r\n! info = 0: successful exit\r\n! info < 0: illegal value in k, iprm\r\n! info > 0: failed to find the k-th eigenpair\r\n!\r\n!-----------------------------------------------------------------------\r\n!\r\n! References\r\n! [1] D. Lee, T. Hoshi, T. Sogabe, Y. Miyatake, S.-L. Zhang,\r\n! Solution of the k-th eigenvalue problem\r\n! in large-scale electronic structure calculations,\r\n! https://arxiv.org/abs/1710.05134.\r\n!\r\n!=======================================================================\r\n!\r\n! Convert data to Compressed Row Storage (CRS) format\r\n INTEGER :: row_pntr_a,col_indx_a,row_pntr_b,col_indx_b\r\n DOUBLE PRECISION :: a,b\r\n DIMENSION :: row_pntr_a(kep_io%n+1),col_indx_a(kep_io%nz_a),&\r\n & row_pntr_b(kep_io%n+1),col_indx_b(kep_io%nz_b),&\r\n & a(kep_io%nz_a),b(kep_io%nz_b)\r\n!\r\n! MUMPS\r\n INCLUDE 'mpif.h'\r\n INCLUDE 'dmumps_struc.h'\r\n INTEGER :: ierr,m_ord\r\n TYPE(DMUMPS_STRUC) :: m_1,m_2,m_3\r\n ALLOCATABLE :: m_ord\r\n DIMENSION :: m_ord(:)\r\n!\r\n! Lanczos\r\n INTEGER :: imax_lanc,its_lanc,ijob\r\n DOUBLE PRECISION :: v,bv,alpha,beta,theta\r\n ALLOCATABLE :: v,bv,alpha,beta,theta\r\n DIMENSION :: alpha(:),theta(:),beta(:)\r\n DIMENSION :: v(:,:),bv(:,:)\r\n!\r\n! Bisection\r\n INTEGER :: imax_bi,mmax\r\n!\r\n! Shift-and-invert Lanczos\r\n INTEGER :: imax_si,its_si,ijob_si,ijob_test,info_test\r\n DOUBLE PRECISION :: tol_res,tol_dif, &\r\n & v_si,bv_si,alpha_si,beta_si,theta_si, &\r\n & y,lngth,egnval,egnvec,egnvec_old,resnorm,difnorm\r\n ALLOCATABLE :: v_si,bv_si,alpha_si,beta_si,theta_si,y, &\r\n & egnval,egnvec,egnvec_old,resnorm,difnorm\r\n DIMENSION :: alpha_si(:),theta_si(:),beta_si(:), &\r\n & egnval(:),resnorm(:),difnorm(:)\r\n DIMENSION :: v_si(:,:),bv_si(:,:),y(:,:),egnvec(:,:),egnvec_old(:,:)\r\n!\r\n! Time\r\n INTEGER :: clock_1,clock_2,clock_rate,clock_max\r\n REAL :: cmpt_time\r\n DIMENSION :: cmpt_time(10)\r\n!\r\n! Results\r\n INTEGER :: icnt\r\n DIMENSION :: icnt(10)\r\n TYPE :: shift_inertia\r\n SEQUENCE\r\n DOUBLE PRECISION, ALLOCATABLE, DIMENSION(:) :: shift\r\n INTEGER, ALLOCATABLE, DIMENSION(:) :: inertia\r\n END TYPE shift_inertia\r\n TYPE(shift_inertia) :: si_1,si_2_l,si_2_r,si_3\r\n!\r\n! Local arguments\r\n INTEGER :: i,j\r\n DOUBLE PRECISION :: dtmp\r\n!\r\n!---Initialize----------------------------------------------------------\r\n!\r\n! Check matrices\r\n kep_io%info=0\r\n IF(.NOT.(ALLOCATED(kep_io%indx_a).AND.ALLOCATED(kep_io%jndx_a).AND.&\r\n & ALLOCATED(kep_io%indx_b).AND.ALLOCATED(kep_io%jndx_b).AND.&\r\n & ALLOCATED(kep_io%rval_a).AND.ALLOCATED(kep_io%rval_b)) )&\r\n & kep_io%info=-1 \r\n IF(kep_io%info.NE.0) THEN \r\n CALL kep_info(kep_io%info)\r\n RETURN\r\n END IF \r\n! \r\n! Check parameters \r\n CALL kep_checkprm(kep_io%n,kep_io%k,kep_io%iprm,kep_io%info)\r\n IF(kep_io%info.NE.0) THEN\r\n CALL kep_info(kep_io%info)\r\n RETURN\r\n END IF\r\n!\r\n! Initialize counts and info\r\n icnt=0\r\n info_test=0\r\n!\r\n! Lanczos\r\n imax_lanc=kep_io%iprm(11)\r\n its_lanc=1\r\n ijob=1\r\n!\r\n! Bisection\r\n imax_bi=kep_io%iprm(12)\r\n mmax=kep_io%iprm(1)\r\n!\r\n! Shift-and-invert Lanczos\r\n imax_si=kep_io%iprm(13)\r\n its_si=1\r\n ijob_si=1\r\n ijob_test=1\r\n tol_res=1.0D1**(-REAL(2*kep_io%iprm(2)))\r\n tol_dif=1.0D1**(-REAL(2*kep_io%iprm(3)))\r\n!\r\n! Time and results\r\n cmpt_time=0.0E0\r\n!\r\n ALLOCATE(si_1%shift(0:imax_lanc),si_1%inertia(0:imax_lanc))\r\n ALLOCATE(si_2_l%shift(0:imax_bi),si_2_l%inertia(0:imax_bi), &\r\n & si_2_r%shift(0:imax_bi),si_2_r%inertia(0:imax_bi))\r\n ALLOCATE(si_3%shift(1),si_3%inertia(1))\r\n ALLOCATE(egnval(mmax),egnvec(kep_io%n,mmax+2), &\r\n & egnvec_old(kep_io%n,mmax),resnorm(mmax),difnorm(mmax))\r\n!\r\n! Convert data to Compressed Row Storage (CRS) format\r\n CALL kep_mtx2crs(kep_io%n,kep_io%nz_a,kep_io%indx_a,kep_io%jndx_a,&\r\n & kep_io%rval_a,row_pntr_a,col_indx_a,a)\r\n CALL kep_mtx2crs(kep_io%n,kep_io%nz_b,kep_io%indx_b,kep_io%jndx_b,&\r\n & kep_io%rval_b,row_pntr_b,col_indx_b,b)\r\n!\r\n! MUMPS\r\n CALL mpi_init(ierr)\r\n INCLUDE 'm_1'\r\n INCLUDE 'm_2'\r\n!\r\n!---Step 1 : set an initial interval------------------------------------\r\n!\r\n! Task (i) : symbolic factorizaion of B\r\n CALL SYSTEM_CLOCK(clock_1,clock_rate,clock_max)\r\n m_1%job=1\r\n CALL dmumps(m_1)\r\n IF(m_1%infog(1).NE.0) THEN\r\n kep_io%info=11\r\n CALL kep_info(kep_io%info)\r\n RETURN\r\n END IF\r\n CALL SYSTEM_CLOCK(clock_2,clock_rate,clock_max)\r\n cmpt_time(1)=REAL(clock_2-clock_1)/REAL(clock_rate)\r\n!\r\n! Recycle and reuse fill-reducing ordering\r\n m_ord=m_1%sym_perm\r\n m_2%perm_in=m_ord\r\n!\r\n! Task (ii) : numerical factorizaion of B\r\n CALL SYSTEM_CLOCK(clock_1,clock_rate,clock_max)\r\n m_1%JOB=2\r\n CALL dmumps(m_1)\r\n IF(m_1%infog(1).NE.0) THEN\r\n kep_io%info=12\r\n CALL kep_info(kep_io%info)\r\n RETURN\r\n END IF\r\n CALL SYSTEM_CLOCK(clock_2,clock_rate,clock_max)\r\n cmpt_time(2)=REAL(clock_2-clock_1)/REAL(clock_rate)\r\n!\r\n! Task (iii) : Lanczos method with reverse communication==============\r\n!\r\n ALLOCATE(alpha(imax_lanc),theta(imax_lanc),beta(0:imax_lanc),&\r\n & v(kep_io%n,imax_lanc+1),bv(kep_io%n,0:imax_lanc+1))\r\n!\r\n! Initialize\r\n CALL SYSTEM_CLOCK(clock_1,clock_rate,clock_max)\r\n CALL kep_lanczos(kep_io%n,imax_lanc,its_lanc,ijob,v,bv,&\r\n & alpha,beta,theta)\r\n CALL kep_matvec(kep_io%n,kep_io%nz_b,row_pntr_b,col_indx_b,b,&\r\n & v(:,1),bv(:,1))\r\n CALL SYSTEM_CLOCK(clock_2,clock_rate,clock_max)\r\n cmpt_time(3)=cmpt_time(3)+REAL(clock_2-clock_1)/REAL(clock_rate)\r\n!\r\n DO i=1,imax_lanc\r\n! Expand subspace and solve tridiagonal eigenproblem\r\n CALL SYSTEM_CLOCK(clock_1,clock_rate,clock_max)\r\n CALL kep_lanczos(kep_io%n,imax_lanc,its_lanc,ijob,v,bv,&\r\n & alpha,beta,theta)\r\n CALL kep_matvec(kep_io%n,kep_io%nz_a,row_pntr_a,col_indx_a,a,&\r\n & v(:,its_lanc),bv(:,its_lanc+1))\r\n CALL kep_lanczos(kep_io%n,imax_lanc,its_lanc,ijob,v,bv,&\r\n & alpha,beta,theta)\r\n m_1%rhs=bv(:,its_lanc+1)\r\n m_1%job=3\r\n CALL dmumps(m_1)\r\n IF(m_1%infog(1).NE.0) THEN\r\n kep_io%info=13\r\n CALL kep_info(kep_io%info)\r\n RETURN\r\n END IF\r\n v(:,its_lanc+1)=m_1%rhs\r\n CALL kep_lanczos(kep_io%n,imax_lanc,its_lanc,ijob,v,&\r\n & bv,alpha,beta,theta)\r\n CALL SYSTEM_CLOCK(clock_2,clock_rate,clock_max)\r\n cmpt_time(3)=cmpt_time(3)+REAL(clock_2-clock_1)/REAL(clock_rate)\r\n!\r\n! Task (iv) : inertia computation\r\n CALL SYSTEM_CLOCK(clock_1,clock_rate,clock_max)\r\n IF(si_1%inertia(i-1).GE.kep_io%k) THEN\r\n si_1%shift(i)=theta(1)\r\n ELSE\r\n si_1%shift(i)=theta(i)\r\n END IF\r\n m_2%a(1:kep_io%nz_a)=a\r\n m_2%a(kep_io%nz_a+1:kep_io%nz_a+kep_io%nz_b)=-si_1%shift(i)*b\r\n m_2%job=4\r\n CALL dmumps(m_2)\r\n IF(m_2%infog(1).NE.0) THEN\r\n kep_io%info=14\r\n CALL kep_info(kep_io%info)\r\n RETURN\r\n END IF\r\n si_1%inertia(i)=m_2%infog(12)\r\n CALL SYSTEM_CLOCK(clock_2,clock_rate,clock_max)\r\n cmpt_time(4)=cmpt_time(4)+REAL(clock_2-clock_1)/REAL(clock_rate)\r\n!\r\n icnt(1)=i\r\n IF(i.NE.1) THEN\r\n IF((si_1%inertia(i-1).GE.kep_io%k).AND.&\r\n & (si_1%inertia(i).LT.kep_io%k)) THEN\r\n EXIT\r\n ELSE IF((si_1%inertia(i-1).LT.kep_io%k).AND.&\r\n & (si_1%inertia(i).GE.kep_io%k)) THEN\r\n EXIT\r\n ELSE IF(i.EQ.imax_lanc) THEN\r\n! Failed to find an initial interval\r\n kep_io%info=1\r\n DEALLOCATE(alpha,theta,beta,v,bv)\r\n DEALLOCATE(m_1%irn,m_1%jcn,m_1%a,m_1%rhs)\r\n DEALLOCATE(m_ord)\r\n DEALLOCATE(m_2%irn,m_2%jcn,m_2%a,m_2%perm_in)\r\n m_1%job=-2\r\n m_2%job=-2\r\n CALL dmumps(m_1)\r\n CALL dmumps(m_2)\r\n CALL mpi_finalize(ierr)\r\n CALL kep_info(kep_io%info)\r\n IF(kep_io%iprm(21).GT.0) CALL kep_summary(mmax,icnt,cmpt_time,&\r\n & si_1,si_2_l,si_2_r,si_3,egnval,resnorm,difnorm,kep_io%info)\r\n DEALLOCATE(si_1%shift,si_1%inertia, &\r\n & si_2_l%shift,si_2_l%inertia,si_2_r%shift,si_2_r%inertia,&\r\n & si_3%shift,si_3%inertia,egnval,resnorm,difnorm,egnvec,egnvec_old)\r\n RETURN\r\n END IF\r\n END IF\r\n END DO\r\n!\r\n! End of Lanczos method===============================================\r\n!\r\n DEALLOCATE(alpha,theta,beta,v,bv)\r\n DEALLOCATE(m_1%irn,m_1%jcn,m_1%a,m_1%rhs)\r\n m_1%job=-2\r\n CALL dmumps(m_1)\r\n!\r\n!---Step 2 : narrow down the interval-----------------------------------\r\n!\r\n! Initialize\r\n si_2_l%shift(0)=MIN(si_1%shift(icnt(1)-1),si_1%shift(icnt(1)))\r\n si_2_r%shift(0)=MAX(si_1%shift(icnt(1)-1),si_1%shift(icnt(1)))\r\n si_2_l%inertia(0)=MIN(si_1%inertia(icnt(1)-1),si_1%inertia(icnt(1)))\r\n si_2_r%inertia(0)=MAX(si_1%inertia(icnt(1)-1),si_1%inertia(icnt(1)))\r\n!\r\n! Bisection===========================================================\r\n!\r\n DO i=1,imax_bi+1\r\n !\r\n icnt(2)=i-1\r\n icnt(3)=si_2_r%inertia(i-1)-si_2_l%inertia(i-1)\r\n IF(icnt(3).LE.mmax) THEN\r\n EXIT\r\n ELSE IF(i-1.EQ.imax_bi) THEN\r\n! Failed to narrow down an interval\r\n kep_io%info=2\r\n DEALLOCATE(m_ord)\r\n DEALLOCATE(m_2%irn,m_2%jcn,m_2%a,m_2%perm_in)\r\n m_2%job=-2\r\n CALL dmumps(m_2)\r\n CALL mpi_finalize(ierr)\r\n CALL kep_info(kep_io%info)\r\n IF(kep_io%iprm(21).GT.0) CALL kep_summary(mmax,icnt,cmpt_time,&\r\n & si_1,si_2_l,si_2_r,si_3,egnval,resnorm,difnorm,kep_io%info)\r\n DEALLOCATE(si_1%shift,si_1%inertia, &\r\n & si_2_l%shift,si_2_l%inertia,si_2_r%shift,si_2_r%inertia,&\r\n & si_3%shift,si_3%inertia,egnval,resnorm,difnorm,egnvec,egnvec_old)\r\n RETURN\r\n END IF\r\n!\r\n! Task (v) : bisection and inertia computation\r\n CALL SYSTEM_CLOCK(clock_1,clock_rate,clock_max)\r\n dtmp=(si_2_l%shift(i-1)+si_2_r%shift(i-1))*0.5D0\r\n m_2%a(1:kep_io%nz_a)=a\r\n m_2%a(kep_io%nz_a+1:kep_io%nz_a+kep_io%nz_b)=-dtmp*b\r\n m_2%job=4\r\n CALL dmumps(m_2)\r\n IF(m_2%infog(1).NE.0) THEN\r\n kep_io%info=15\r\n CALL kep_info(kep_io%info)\r\n RETURN\r\n END IF\r\n!\r\n si_2_l%shift(i) = si_2_l%shift(i-1)\r\n si_2_r%shift(i) = si_2_r%shift(i-1)\r\n si_2_l%inertia(i) = si_2_l%inertia(i-1)\r\n si_2_r%inertia(i) = si_2_r%inertia(i-1)\r\n!\r\n IF(m_2%infog(12).GE.kep_io%k) THEN\r\n si_2_r%shift(i)=dtmp\r\n si_2_r%inertia(i)=m_2%infog(12)\r\n ELSE\r\n si_2_l%shift(i)=dtmp\r\n si_2_l%inertia(i)=m_2%infog(12)\r\n END IF\r\n CALL SYSTEM_CLOCK(clock_2,clock_rate,clock_max)\r\n cmpt_time(5)=cmpt_time(5)+REAL(clock_2-clock_1)/REAL(clock_rate)\r\n END DO\r\n!\r\n! End of bisection====================================================\r\n!\r\n DEALLOCATE(m_2%irn,m_2%jcn,m_2%a,m_2%perm_in)\r\n m_2%job=-2\r\n CALL dmumps(m_2)\r\n!\r\n!---Step 3 : compute eigenpairs of the interval-------------------------\r\n!\r\n! Initialize\r\n lngth=(si_2_r%shift(icnt(2))-si_2_l%shift(icnt(2)))*0.5D0\r\n egnvec_old=0.0D0\r\n!\r\n! MUMPS\r\n INCLUDE 'm_3'\r\n!\r\n! Reuse fill-reducing ordering\r\n m_3%perm_in=m_ord\r\n DEALLOCATE(m_ord)\r\n!\r\n! Task (vi) : numerical factorization of A-sigma*B\r\n CALL SYSTEM_CLOCK(clock_1,clock_rate,clock_max)\r\n dtmp=(si_2_l%shift(icnt(2))+si_2_r%shift(icnt(2)))*0.5D0\r\n m_3%a(1:kep_io%nz_a)=a\r\n m_3%a(kep_io%nz_a+1:kep_io%nz_a+kep_io%nz_b)=-dtmp*b\r\n m_3%JOB=4\r\n CALL dmumps(m_3)\r\n IF(m_3%infog(1).NE.0) THEN\r\n kep_io%info=16\r\n CALL kep_info(kep_io%info)\r\n RETURN\r\n END IF\r\n si_3%shift(1)=dtmp\r\n si_3%inertia(1)=m_3%infog(12)\r\n CALL SYSTEM_CLOCK(clock_2,clock_rate,clock_max)\r\n cmpt_time(6)=REAL(clock_2-clock_1)/REAL(clock_rate)\r\n!\r\n! Task (vii) : shift-and-invert Lanczos with reverse communication====\r\n!\r\n ALLOCATE(alpha_si(imax_si),theta_si(imax_si),beta_si(0:imax_si),&\r\n & v_si(kep_io%n,imax_si+1),bv_si(kep_io%n,0:imax_si+1),y(imax_si,imax_si))\r\n!\r\n! Initialize shift-and-invert Lanczos\r\n CALL SYSTEM_CLOCK(clock_1,clock_rate,clock_max)\r\n CALL kep_silanczos(kep_io%n,imax_si,its_si,ijob_si,&\r\n & v_si,bv_si,alpha_si,beta_si,theta_si,y,icnt(3))\r\n CALL kep_matvec(kep_io%n,kep_io%nz_b,row_pntr_b,col_indx_b,b,&\r\n & bv_si(:,1),v_si(:,1))\r\n CALL SYSTEM_CLOCK(clock_2,clock_rate,clock_max)\r\n cmpt_time(7)=cmpt_time(7)+REAL(clock_2-clock_1)/REAL(clock_rate)\r\n!\r\n DO i=1,imax_si\r\n! Expand subspace and solve tridiagonal eigenproblem\r\n CALL SYSTEM_CLOCK(clock_1,clock_rate,clock_max)\r\n CALL kep_silanczos(kep_io%n,imax_si,its_si,ijob_si,&\r\n & v_si,bv_si,alpha_si,beta_si,theta_si,y,icnt(3))\r\n m_3%rhs=v_si(:,its_si)\r\n m_3%job=3\r\n CALL dmumps(m_3)\r\n IF(m_3%infog(1).NE.0) THEN\r\n kep_io%info=17\r\n CALL kep_info(kep_io%info)\r\n RETURN\r\n END IF\r\n bv_si(:,its_si+1)=m_3%rhs\r\n CALL kep_silanczos(kep_io%n,imax_si,its_si,ijob_si,&\r\n & v_si,bv_si,alpha_si,beta_si,theta_si,y,icnt(3))\r\n CALL kep_matvec(kep_io%n,kep_io%nz_b,row_pntr_b,col_indx_b,b,&\r\n & bv_si(:,its_si+1),v_si(:,its_si+1))\r\n CALL kep_silanczos(kep_io%n,imax_si,its_si,ijob_si,&\r\n & v_si,bv_si,alpha_si,beta_si,theta_si,y,icnt(3))\r\n!\r\n! Convergence test with reverse communication\r\n CALL kep_convtest(kep_io%n,imax_si,mmax,tol_res,tol_dif,i,j,&\r\n & ijob_test,v_si,bv_si,beta_si,theta_si,&\r\n & y,icnt(3),lngth,si_3%shift(1),&\r\n & egnval,egnvec,egnvec_old,resnorm,difnorm,info_test)\r\n DO j=1,icnt(3)\r\n IF(info_test.EQ.0) THEN\r\n CALL kep_convtest(kep_io%n,imax_si,mmax,tol_res,tol_dif,i,j,&\r\n & ijob_test,v_si,bv_si,beta_si,theta_si,&\r\n & y,icnt(3),lngth,si_3%shift(1),&\r\n & egnval,egnvec,egnvec_old,resnorm,difnorm,info_test)\r\n CALL kep_matvec(kep_io%n,kep_io%nz_a,row_pntr_a,col_indx_a,a,&\r\n & egnvec(:,j),egnvec(:,mmax+1))\r\n CALL kep_matvec(kep_io%n,kep_io%nz_b,row_pntr_b,col_indx_b,b,&\r\n & egnvec(:,j),egnvec(:,mmax+2))\r\n CALL kep_convtest(kep_io%n,imax_si,mmax,tol_res,tol_dif,i,j,&\r\n & ijob_test,v_si,bv_si,beta_si,theta_si,&\r\n & y,icnt(3),lngth,si_3%shift(1),&\r\n & egnval,egnvec,egnvec_old,resnorm,difnorm,info_test)\r\n END IF\r\n END DO\r\n IF(info_test.EQ.0) THEN\r\n ijob_test=4\r\n CALL kep_convtest(kep_io%n,imax_si,mmax,tol_res,tol_dif,i,j,&\r\n & ijob_test,v_si,bv_si,beta_si,theta_si,&\r\n & y,icnt(3),lngth,si_3%shift(1),&\r\n & egnval,egnvec,egnvec_old,resnorm,difnorm,info_test)\r\n END IF\r\n CALL SYSTEM_CLOCK(clock_2,clock_rate,clock_max)\r\n cmpt_time(7)=cmpt_time(7)+REAL(clock_2-clock_1)/REAL(clock_rate)\r\n!\r\n icnt(4)=i\r\n IF(info_test.EQ.0) THEN\r\n EXIT\r\n ELSE IF(i.EQ.imax_si) THEN\r\n! Failed to be converged\r\n kep_io%info=3\r\n DEALLOCATE(alpha_si,theta_si,beta_si,v_si,bv_si,y)\r\n DEALLOCATE(m_3%irn,m_3%jcn,m_3%a,m_3%perm_in,m_3%rhs)\r\n m_3%job=-2\r\n CALL dmumps(m_3)\r\n CALL mpi_finalize(ierr)\r\n CALL kep_info(kep_io%info)\r\n IF(kep_io%iprm(21).GT.0) CALL kep_summary(mmax,icnt,cmpt_time,&\r\n & si_1,si_2_l,si_2_r,si_3,egnval,resnorm,difnorm,kep_io%info)\r\n DEALLOCATE(si_1%shift,si_1%inertia, &\r\n & si_2_l%shift,si_2_l%inertia,si_2_r%shift,si_2_r%inertia,&\r\n & si_3%shift,si_3%inertia,egnval,resnorm,difnorm,egnvec,egnvec_old)\r\n RETURN\r\n ELSE IF(info_test.GE.3) THEN\r\n egnvec_old(:,1:icnt(3))=egnvec(:,1:icnt(3))\r\n END IF\r\n info_test=0\r\n ijob_test=1\r\n END DO\r\n!\r\n IF(ALLOCATED(kep_io%kndx).AND.ALLOCATED(kep_io%kval).AND.&\r\n & ALLOCATED(kep_io%kvec)) THEN\r\n DEALLOCATE(kep_io%kndx,kep_io%kval,kep_io%kvec)\r\n END IF \r\n! \r\n IF(kep_io%iprm(22).LE.0) THEN \r\n ALLOCATE(kep_io%kndx(1),kep_io%kval(1),kep_io%kvec(kep_io%n,1))\r\n kep_io%kndx=kep_io%k\r\n kep_io%kval=egnval(kep_io%k-si_2_l%inertia(icnt(2)))\r\n kep_io%kvec(:,1)=egnvec(:,kep_io%k-si_2_l%inertia(icnt(2)))\r\n ELSE \r\n ALLOCATE(kep_io%kndx(icnt(3)),kep_io%kval(icnt(3)),&\r\n & kep_io%kvec(kep_io%n,icnt(3)))\r\n DO i=1,icnt(3)\r\n kep_io%kndx(i)=si_2_l%inertia(icnt(2))+i\r\n END DO \r\n kep_io%kval=egnval(1:icnt(3))\r\n kep_io%kvec=egnvec(:,1:icnt(3))\r\n END IF\r\n!\r\n! End of Shift-and-invert Lanczos method==============================\r\n!\r\n DEALLOCATE(alpha_si,theta_si,beta_si,v_si,bv_si,y)\r\n DEALLOCATE(m_3%irn,m_3%jcn,m_3%a,m_3%perm_in,m_3%rhs)\r\n m_3%job=-2\r\n CALL dmumps(m_3)\r\n CALL mpi_finalize(ierr)\r\n!\r\n!---Time and results----------------------------------------------------\r\n!\r\n IF(kep_io%iprm(21).GT.0) CALL kep_summary(mmax,icnt,cmpt_time,&\r\n & si_1,si_2_l,si_2_r,si_3,egnval,resnorm,difnorm,kep_io%info)\r\n DEALLOCATE(si_1%shift,si_1%inertia, &\r\n & si_2_l%shift,si_2_l%inertia,si_2_r%shift,si_2_r%inertia,&\r\n & si_3%shift,si_3%inertia,egnval,resnorm,difnorm,egnvec,egnvec_old)\r\n!\r\n!-----------------------------------------------------------------------\r\n!\r\n RETURN\r\n END SUBROUTINE kep\r\n END MODULE mod_kep\r\n ", "meta": {"hexsha": "8d3a252e371b19d3ea693ab8b465ddfe2ca03804", "size": 22558, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/kep.f90", "max_stars_repo_name": "lee-djl/k-ep", "max_stars_repo_head_hexsha": "f1285b59233c12b77790e0640da12c0b187ef642", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-28T08:44:11.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-28T08:44:11.000Z", "max_issues_repo_path": "src/kep.f90", "max_issues_repo_name": "lee-djl/k-ep", "max_issues_repo_head_hexsha": "f1285b59233c12b77790e0640da12c0b187ef642", "max_issues_repo_licenses": ["MIT"], "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/kep.f90", "max_forks_repo_name": "lee-djl/k-ep", "max_forks_repo_head_hexsha": "f1285b59233c12b77790e0640da12c0b187ef642", "max_forks_repo_licenses": ["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.2313043478, "max_line_length": 86, "alphanum_fraction": 0.5710612643, "num_tokens": 7510, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299653388752, "lm_q2_score": 0.7154239957834733, "lm_q1q2_score": 0.6619317188213426}} {"text": "\n\\ this example is from KsanaVM forth lesson 16, thanks to Sir yap.\n\n\\ calculate factorial using recursion\n: fac ( n -- fac_n )\n dup 2 < if\n drop 1 \\ fac(0) = fac(1) = 1\n else \n dup 1 - recurse * \\ fac(n) = n * fac(n-1) when we want to call 'fac' here, use 'recurse' instead when 'fac' is still under construction.\n then \n;\ncr .( fac of 10 is ) 10 fac . cr cr bye", "meta": {"hexsha": "ba769022f1f50ab366fdbed92a6e3a3da43c7335", "size": 399, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "demo/demo-recurse.f", "max_stars_repo_name": "hcchengithub/weforth", "max_stars_repo_head_hexsha": "73c76c05a13f943af5e05a8c5bc679f0d9ce8b0d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "demo/demo-recurse.f", "max_issues_repo_name": "hcchengithub/weforth", "max_issues_repo_head_hexsha": "73c76c05a13f943af5e05a8c5bc679f0d9ce8b0d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "demo/demo-recurse.f", "max_forks_repo_name": "hcchengithub/weforth", "max_forks_repo_head_hexsha": "73c76c05a13f943af5e05a8c5bc679f0d9ce8b0d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-09-24T02:39:07.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-24T02:39:07.000Z", "avg_line_length": 33.25, "max_line_length": 152, "alphanum_fraction": 0.5889724311, "num_tokens": 129, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299632771662, "lm_q2_score": 0.7154239897159439, "lm_q1q2_score": 0.6619317117324865}} {"text": " subroutine irev_eqrpsi(n_a1,n_alpha,n_beta,n_rPHI,n_rPI,nm1_rpsi,n\n &p1_rpsi,Nx,ht,res)\n implicit none\n integer i\n integer Nx\n real*8 ht\n real*8 n_a1(Nx)\n real*8 n_alpha(Nx)\n real*8 n_beta(Nx)\n real*8 n_rPHI(Nx)\n real*8 n_rPI(Nx)\n real*8 nm1_rpsi(Nx)\n real*8 np1_rpsi(Nx)\n real*8 res(Nx)\n real*8 qb\n do i=1, Nx, 1\n qb = 0.5000000000000000D0 * (-0.1D1 * nm1_rpsi(i) + np1_rpsi(i)) /\n # ht - 0.1D1 * n_alpha(i) / n_a1(i) * n_rPI(i) - 0.1D1 * n_beta(i) \n #* n_rPHI(i)\n res(i)=qb\n end do\n END\n", "meta": {"hexsha": "b9bca7663c632170a69601282743d7af370f32fd", "size": 597, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/FD/irev_eqrpsi.f", "max_stars_repo_name": "rmanak/bssn_spher", "max_stars_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/FD/irev_eqrpsi.f", "max_issues_repo_name": "rmanak/bssn_spher", "max_issues_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/FD/irev_eqrpsi.f", "max_forks_repo_name": "rmanak/bssn_spher", "max_forks_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.9565217391, "max_line_length": 72, "alphanum_fraction": 0.5443886097, "num_tokens": 252, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299529686201, "lm_q2_score": 0.7154239836484144, "lm_q1q2_score": 0.6619316987436453}} {"text": " subroutine SBESPQ(X,V,P,Q)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nC>> 2001-05-25 SBESPQ Krogh Minor change for making .f90 version.\nC>> 1998-10-29 SBESPQ Krogh Moved external statement up for mangle.\nC>> 1995-11-13 SBESPQ Krogh Converted SFTRAN to Fortran\nC>> 1994-10-19 SBESPQ Krogh Changes to use M77CON\nC>> 1994-04-19 SBESPQ CLL Edited to make DP & SP files similar.\nC>> 1992-03-13 SBESPQ FTK Removed implicit statements.\nC>> 1986-03-18 SBESPQ Lawson Initial code.\nc--S replaces \"?\": ?BESPQ, ?ERM1, ?ERV1\nC\nc This subr evaluates asymptotic series for P and Q.\nc These can be used to compute Bessel functions by the formulas\nc\nc J = sqrt(2/(pi*X)) * (P * cos(chi) - Q * sin(chi))\nc\nc Y = sqrt(2/(pi*X)) * (P * sin(chi) + Q * cos(chi))\nc where\nc chi = X - (0.5 * V + 0.25) * pi\nc\nC Reference: NBS AMS55 Eqs 9,2.9 and 9,2.10\nc\nc We assume V is limited to the range [0,2].\nc To compute P with a relative accuracy of at least\nc 10**(-s), X must be restricted to be not less than XPQ,\nc where XPQ = 1.1293 * s - 0.59\nc (This formula for XPQ was determined for s in the range from\nc 5 to 25, and limiting V to [0,2].)\nc Let s0 = -log10( machine_eps )\nc and let s1 = s0 + .3, s2 = s0 + .6\nc We will set XPQ using s2, and then sum the series till a\nc term less than 10**(-s1) is reached.\nc By setting XPQ using s2 we provide some tolerance to assure\nc that the series will contain a term less than 10**(-s1).\nc We add the constant term of each series in last to\nc reduce the amount of accumulated rounding error.\nc\nc 1984 Apr 2, JPL, C. L. Lawson and S. Chan.\nc ------------------------------------------------------------------\nc\nc > Let the terms of these two series be numbered\nc 1, 3, 5,... in the P series, and 2, 4, 6,... in the Q series.\nc For X >> V these terms decrease in magnitude in the order 1, 2,\nc 3, 4,... to some smallest term, say number N, and then\nc following terms increase in magnitude.\nc > For V = 2 and for given X, let N be the number of the\nc smallest term, and let SIZE be the magitude of this\nc smallest term. Here are some values of X, N, and -LOG10(SIZE):\nc\nc X = 5 10 15 20 25 30 35\nc N =12 22 32 42 52 62 72\nc -LOG10(SIZE)= 4.79 9.35 13.81 18.23 22.63 27.02 31.40\nc ------------------------------------------------------------------\n external R1MACH, SERM1, SERV1\n real R1MACH\n real A0,A1,A2,B,C11293,C59,C9,CP3,EIGHT,EMU\n real FOUR,HALF,ONE,P,PSUM,Q,Q1,QSUM,SIG,SMALL,TERM\n real TWO,V,X,X8,XPQ,ZERO\n parameter ( ZERO = 0.E0)\n save XPQ, SMALL\nc ----------\nC\n data ONE,TWO,FOUR,EIGHT,C9 / 1.E0,2.E0,4.E0,8.E0,9.E0 /\n data XPQ, C11293, CP3, C59 / ZERO, 1.1293E0, 0.30103E0, 0.59E0/\n data HALF / 0.5E0 /\nc ------------------------------------------------------------------\nC\n if ( XPQ .EQ. ZERO ) then\n SMALL = HALF * R1MACH(3)\n XPQ = C11293 * (CP3 - log10(SMALL)) - C59\n end if\nc ------------------------------------------------------------------\n if ( X .lt. XPQ .or. V .lt. ZERO .or. V .gt. TWO) then\n call SERM1('SBESPQ',1,0,\n * 'Require X .ge. XPQ and V in [0.,2.].',\n * 'X', X, ',')\n call SERV1( 'V', V, ',')\n call SERV1( 'XPQ', XPQ, '.')\n P = ZERO\n Q = ZERO\n return\n end if\nc ------------------------------------------------------------------\n EMU = FOUR * (V*V)\n X8 = EIGHT * X\n A0 = C9\n A1 = EIGHT\n A2 = EIGHT\n B = TWO\n SIG = -ONE\n PSUM = ZERO\n TERM = (EMU - ONE) / X8\n Q1 = TERM\n QSUM = ZERO\nC\n 20 continue\n TERM = TERM * (EMU-A0) / (B*X8)\n if ( ABS(TERM) .LE. SMALL ) go to 40\n PSUM = PSUM + SIG*TERM\n A1 = A1 + A2\n A0 = A0 + A1\n B = B + 1\nc\n TERM = TERM * (EMU-A0) / (B*X8)\n if ( ABS(TERM) .LE. SMALL ) go to 40\n QSUM = QSUM + SIG*TERM\n A1 = A1 + A2\n A0 = A0 + A1\n B = B + 1\nc\n SIG = -SIG\n go to 20\nC\n 40 continue\n P = HALF + ( HALF + PSUM )\n Q = Q1 + QSUM\n return\n end\n", "meta": {"hexsha": "454e7f499ba7ef7685135723f1ffcfd9492501d7", "size": 4481, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/sbespq.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/sbespq.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/sbespq.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": 37.0330578512, "max_line_length": 72, "alphanum_fraction": 0.5068065164, "num_tokens": 1525, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333483, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.661743413278701}} {"text": " SUBROUTINE ZGELSS( M, N, NRHS, A, LDA, B, LDB, S, RCOND, RANK,\n $ WORK, LWORK, RWORK, INFO )\n*\n* -- LAPACK driver routine (version 3.2) --\n* -- LAPACK is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n* November 2006\n*\n* .. Scalar Arguments ..\n INTEGER INFO, LDA, LDB, LWORK, M, N, NRHS, RANK\n DOUBLE PRECISION RCOND\n* ..\n* .. Array Arguments ..\n DOUBLE PRECISION RWORK( * ), S( * )\n COMPLEX*16 A( LDA, * ), B( LDB, * ), WORK( * )\n* ..\n*\n* Purpose\n* =======\n*\n* ZGELSS computes the minimum norm solution to a complex linear\n* least squares problem:\n*\n* Minimize 2-norm(| b - A*x |).\n*\n* using the singular value decomposition (SVD) of A. A is an M-by-N\n* matrix which may be rank-deficient.\n*\n* Several right hand side vectors b and solution vectors x can be\n* handled in a single call; they are stored as the columns of the\n* M-by-NRHS right hand side matrix B and the N-by-NRHS solution matrix\n* X.\n*\n* The effective rank of A is determined by treating as zero those\n* singular values which are less than RCOND times the largest singular\n* value.\n*\n* Arguments\n* =========\n*\n* M (input) INTEGER\n* The number of rows of the matrix A. M >= 0.\n*\n* N (input) INTEGER\n* The number of columns of the matrix A. N >= 0.\n*\n* NRHS (input) INTEGER\n* The number of right hand sides, i.e., the number of columns\n* of the matrices B and X. NRHS >= 0.\n*\n* A (input/output) COMPLEX*16 array, dimension (LDA,N)\n* On entry, the M-by-N matrix A.\n* On exit, the first min(m,n) rows of A are overwritten with\n* its right singular vectors, stored rowwise.\n*\n* LDA (input) INTEGER\n* The leading dimension of the array A. LDA >= max(1,M).\n*\n* B (input/output) COMPLEX*16 array, dimension (LDB,NRHS)\n* On entry, the M-by-NRHS right hand side matrix B.\n* On exit, B is overwritten by the N-by-NRHS solution matrix X.\n* If m >= n and RANK = n, the residual sum-of-squares for\n* the solution in the i-th column is given by the sum of\n* squares of the modulus of elements n+1:m in that column.\n*\n* LDB (input) INTEGER\n* The leading dimension of the array B. LDB >= max(1,M,N).\n*\n* S (output) DOUBLE PRECISION array, dimension (min(M,N))\n* The singular values of A in decreasing order.\n* The condition number of A in the 2-norm = S(1)/S(min(m,n)).\n*\n* RCOND (input) DOUBLE PRECISION\n* RCOND is used to determine the effective rank of A.\n* Singular values S(i) <= RCOND*S(1) are treated as zero.\n* If RCOND < 0, machine precision is used instead.\n*\n* RANK (output) INTEGER\n* The effective rank of A, i.e., the number of singular values\n* which are greater than RCOND*S(1).\n*\n* WORK (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK))\n* On exit, if INFO = 0, WORK(1) returns the optimal LWORK.\n*\n* LWORK (input) INTEGER\n* The dimension of the array WORK. LWORK >= 1, and also:\n* LWORK >= 2*min(M,N) + max(M,N,NRHS)\n* For good performance, LWORK should generally be larger.\n*\n* If LWORK = -1, then a workspace query is assumed; the routine\n* only calculates the optimal size of the WORK array, returns\n* this value as the first entry of the WORK array, and no error\n* message related to LWORK is issued by XERBLA.\n*\n* RWORK (workspace) DOUBLE PRECISION array, dimension (5*min(M,N))\n*\n* INFO (output) INTEGER\n* = 0: successful exit\n* < 0: if INFO = -i, the i-th argument had an illegal value.\n* > 0: the algorithm for computing the SVD failed to converge;\n* if INFO = i, i off-diagonal elements of an intermediate\n* bidiagonal form did not converge to zero.\n*\n* =====================================================================\n*\n* .. Parameters ..\n DOUBLE PRECISION ZERO, ONE\n PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )\n COMPLEX*16 CZERO, CONE\n PARAMETER ( CZERO = ( 0.0D+0, 0.0D+0 ),\n $ CONE = ( 1.0D+0, 0.0D+0 ) )\n* ..\n* .. Local Scalars ..\n LOGICAL LQUERY\n INTEGER BL, CHUNK, I, IASCL, IBSCL, IE, IL, IRWORK,\n $ ITAU, ITAUP, ITAUQ, IWORK, LDWORK, MAXMN,\n $ MAXWRK, MINMN, MINWRK, MM, MNTHR\n DOUBLE PRECISION ANRM, BIGNUM, BNRM, EPS, SFMIN, SMLNUM, THR\n* ..\n* .. Local Arrays ..\n COMPLEX*16 VDUM( 1 )\n* ..\n* .. External Subroutines ..\n EXTERNAL DLABAD, DLASCL, DLASET, XERBLA, ZBDSQR, ZCOPY,\n $ ZDRSCL, ZGEBRD, ZGELQF, ZGEMM, ZGEMV, ZGEQRF,\n $ ZLACPY, ZLASCL, ZLASET, ZUNGBR, ZUNMBR, ZUNMLQ,\n $ ZUNMQR\n* ..\n* .. External Functions ..\n INTEGER ILAENV\n DOUBLE PRECISION DLAMCH, ZLANGE\n EXTERNAL ILAENV, DLAMCH, ZLANGE\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC MAX, MIN\n* ..\n* .. Executable Statements ..\n*\n* Test the input arguments\n*\n INFO = 0\n MINMN = MIN( M, N )\n MAXMN = MAX( M, N )\n LQUERY = ( LWORK.EQ.-1 )\n IF( M.LT.0 ) THEN\n INFO = -1\n ELSE IF( N.LT.0 ) THEN\n INFO = -2\n ELSE IF( NRHS.LT.0 ) THEN\n INFO = -3\n ELSE IF( LDA.LT.MAX( 1, M ) ) THEN\n INFO = -5\n ELSE IF( LDB.LT.MAX( 1, MAXMN ) ) THEN\n INFO = -7\n END IF\n*\n* Compute workspace\n* (Note: Comments in the code beginning \"Workspace:\" describe the\n* minimal amount of workspace needed at that point in the code,\n* as well as the preferred amount for good performance.\n* CWorkspace refers to complex workspace, and RWorkspace refers\n* to real workspace. NB refers to the optimal block size for the\n* immediately following subroutine, as returned by ILAENV.)\n*\n IF( INFO.EQ.0 ) THEN\n MINWRK = 1\n MAXWRK = 1\n IF( MINMN.GT.0 ) THEN\n MM = M\n MNTHR = ILAENV( 6, 'ZGELSS', ' ', M, N, NRHS, -1 )\n IF( M.GE.N .AND. M.GE.MNTHR ) THEN\n*\n* Path 1a - overdetermined, with many more rows than\n* columns\n*\n MM = N\n MAXWRK = MAX( MAXWRK, N + N*ILAENV( 1, 'ZGEQRF', ' ', M,\n $ N, -1, -1 ) )\n MAXWRK = MAX( MAXWRK, N + NRHS*ILAENV( 1, 'ZUNMQR', 'LC',\n $ M, NRHS, N, -1 ) )\n END IF\n IF( M.GE.N ) THEN\n*\n* Path 1 - overdetermined or exactly determined\n*\n MAXWRK = MAX( MAXWRK, 2*N + ( MM + N )*ILAENV( 1,\n $ 'ZGEBRD', ' ', MM, N, -1, -1 ) )\n MAXWRK = MAX( MAXWRK, 2*N + NRHS*ILAENV( 1, 'ZUNMBR',\n $ 'QLC', MM, NRHS, N, -1 ) )\n MAXWRK = MAX( MAXWRK, 2*N + ( N - 1 )*ILAENV( 1,\n $ 'ZUNGBR', 'P', N, N, N, -1 ) )\n MAXWRK = MAX( MAXWRK, N*NRHS )\n MINWRK = 2*N + MAX( NRHS, M )\n END IF\n IF( N.GT.M ) THEN\n MINWRK = 2*M + MAX( NRHS, N )\n IF( N.GE.MNTHR ) THEN\n*\n* Path 2a - underdetermined, with many more columns\n* than rows\n*\n MAXWRK = M + M*ILAENV( 1, 'ZGELQF', ' ', M, N, -1,\n $ -1 )\n MAXWRK = MAX( MAXWRK, 3*M + M*M + 2*M*ILAENV( 1,\n $ 'ZGEBRD', ' ', M, M, -1, -1 ) )\n MAXWRK = MAX( MAXWRK, 3*M + M*M + NRHS*ILAENV( 1,\n $ 'ZUNMBR', 'QLC', M, NRHS, M, -1 ) )\n MAXWRK = MAX( MAXWRK, 3*M + M*M + ( M - 1 )*ILAENV( 1,\n $ 'ZUNGBR', 'P', M, M, M, -1 ) )\n IF( NRHS.GT.1 ) THEN\n MAXWRK = MAX( MAXWRK, M*M + M + M*NRHS )\n ELSE\n MAXWRK = MAX( MAXWRK, M*M + 2*M )\n END IF\n MAXWRK = MAX( MAXWRK, M + NRHS*ILAENV( 1, 'ZUNMLQ',\n $ 'LC', N, NRHS, M, -1 ) )\n ELSE\n*\n* Path 2 - underdetermined\n*\n MAXWRK = 2*M + ( N + M )*ILAENV( 1, 'ZGEBRD', ' ', M,\n $ N, -1, -1 )\n MAXWRK = MAX( MAXWRK, 2*M + NRHS*ILAENV( 1, 'ZUNMBR',\n $ 'QLC', M, NRHS, M, -1 ) )\n MAXWRK = MAX( MAXWRK, 2*M + M*ILAENV( 1, 'ZUNGBR',\n $ 'P', M, N, M, -1 ) )\n MAXWRK = MAX( MAXWRK, N*NRHS )\n END IF\n END IF\n MAXWRK = MAX( MINWRK, MAXWRK )\n END IF\n WORK( 1 ) = MAXWRK\n*\n IF( LWORK.LT.MINWRK .AND. .NOT.LQUERY )\n $ INFO = -12\n END IF\n*\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'ZGELSS', -INFO )\n RETURN\n ELSE IF( LQUERY ) THEN\n RETURN\n END IF\n*\n* Quick return if possible\n*\n IF( M.EQ.0 .OR. N.EQ.0 ) THEN\n RANK = 0\n RETURN\n END IF\n*\n* Get machine parameters\n*\n EPS = DLAMCH( 'P' )\n SFMIN = DLAMCH( 'S' )\n SMLNUM = SFMIN / EPS\n BIGNUM = ONE / SMLNUM\n CALL DLABAD( SMLNUM, BIGNUM )\n*\n* Scale A if max element outside range [SMLNUM,BIGNUM]\n*\n ANRM = ZLANGE( 'M', M, N, A, LDA, RWORK )\n IASCL = 0\n IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN\n*\n* Scale matrix norm up to SMLNUM\n*\n CALL ZLASCL( 'G', 0, 0, ANRM, SMLNUM, M, N, A, LDA, INFO )\n IASCL = 1\n ELSE IF( ANRM.GT.BIGNUM ) THEN\n*\n* Scale matrix norm down to BIGNUM\n*\n CALL ZLASCL( 'G', 0, 0, ANRM, BIGNUM, M, N, A, LDA, INFO )\n IASCL = 2\n ELSE IF( ANRM.EQ.ZERO ) THEN\n*\n* Matrix all zero. Return zero solution.\n*\n CALL ZLASET( 'F', MAX( M, N ), NRHS, CZERO, CZERO, B, LDB )\n CALL DLASET( 'F', MINMN, 1, ZERO, ZERO, S, MINMN )\n RANK = 0\n GO TO 70\n END IF\n*\n* Scale B if max element outside range [SMLNUM,BIGNUM]\n*\n BNRM = ZLANGE( 'M', M, NRHS, B, LDB, RWORK )\n IBSCL = 0\n IF( BNRM.GT.ZERO .AND. BNRM.LT.SMLNUM ) THEN\n*\n* Scale matrix norm up to SMLNUM\n*\n CALL ZLASCL( 'G', 0, 0, BNRM, SMLNUM, M, NRHS, B, LDB, INFO )\n IBSCL = 1\n ELSE IF( BNRM.GT.BIGNUM ) THEN\n*\n* Scale matrix norm down to BIGNUM\n*\n CALL ZLASCL( 'G', 0, 0, BNRM, BIGNUM, M, NRHS, B, LDB, INFO )\n IBSCL = 2\n END IF\n*\n* Overdetermined case\n*\n IF( M.GE.N ) THEN\n*\n* Path 1 - overdetermined or exactly determined\n*\n MM = M\n IF( M.GE.MNTHR ) THEN\n*\n* Path 1a - overdetermined, with many more rows than columns\n*\n MM = N\n ITAU = 1\n IWORK = ITAU + N\n*\n* Compute A=Q*R\n* (CWorkspace: need 2*N, prefer N+N*NB)\n* (RWorkspace: none)\n*\n CALL ZGEQRF( M, N, A, LDA, WORK( ITAU ), WORK( IWORK ),\n $ LWORK-IWORK+1, INFO )\n*\n* Multiply B by transpose(Q)\n* (CWorkspace: need N+NRHS, prefer N+NRHS*NB)\n* (RWorkspace: none)\n*\n CALL ZUNMQR( 'L', 'C', M, NRHS, N, A, LDA, WORK( ITAU ), B,\n $ LDB, WORK( IWORK ), LWORK-IWORK+1, INFO )\n*\n* Zero out below R\n*\n IF( N.GT.1 )\n $ CALL ZLASET( 'L', N-1, N-1, CZERO, CZERO, A( 2, 1 ),\n $ LDA )\n END IF\n*\n IE = 1\n ITAUQ = 1\n ITAUP = ITAUQ + N\n IWORK = ITAUP + N\n*\n* Bidiagonalize R in A\n* (CWorkspace: need 2*N+MM, prefer 2*N+(MM+N)*NB)\n* (RWorkspace: need N)\n*\n CALL ZGEBRD( MM, N, A, LDA, S, RWORK( IE ), WORK( ITAUQ ),\n $ WORK( ITAUP ), WORK( IWORK ), LWORK-IWORK+1,\n $ INFO )\n*\n* Multiply B by transpose of left bidiagonalizing vectors of R\n* (CWorkspace: need 2*N+NRHS, prefer 2*N+NRHS*NB)\n* (RWorkspace: none)\n*\n CALL ZUNMBR( 'Q', 'L', 'C', MM, NRHS, N, A, LDA, WORK( ITAUQ ),\n $ B, LDB, WORK( IWORK ), LWORK-IWORK+1, INFO )\n*\n* Generate right bidiagonalizing vectors of R in A\n* (CWorkspace: need 3*N-1, prefer 2*N+(N-1)*NB)\n* (RWorkspace: none)\n*\n CALL ZUNGBR( 'P', N, N, N, A, LDA, WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, INFO )\n IRWORK = IE + N\n*\n* Perform bidiagonal QR iteration\n* multiply B by transpose of left singular vectors\n* compute right singular vectors in A\n* (CWorkspace: none)\n* (RWorkspace: need BDSPAC)\n*\n CALL ZBDSQR( 'U', N, N, 0, NRHS, S, RWORK( IE ), A, LDA, VDUM,\n $ 1, B, LDB, RWORK( IRWORK ), INFO )\n IF( INFO.NE.0 )\n $ GO TO 70\n*\n* Multiply B by reciprocals of singular values\n*\n THR = MAX( RCOND*S( 1 ), SFMIN )\n IF( RCOND.LT.ZERO )\n $ THR = MAX( EPS*S( 1 ), SFMIN )\n RANK = 0\n DO 10 I = 1, N\n IF( S( I ).GT.THR ) THEN\n CALL ZDRSCL( NRHS, S( I ), B( I, 1 ), LDB )\n RANK = RANK + 1\n ELSE\n CALL ZLASET( 'F', 1, NRHS, CZERO, CZERO, B( I, 1 ), LDB )\n END IF\n 10 CONTINUE\n*\n* Multiply B by right singular vectors\n* (CWorkspace: need N, prefer N*NRHS)\n* (RWorkspace: none)\n*\n IF( LWORK.GE.LDB*NRHS .AND. NRHS.GT.1 ) THEN\n CALL ZGEMM( 'C', 'N', N, NRHS, N, CONE, A, LDA, B, LDB,\n $ CZERO, WORK, LDB )\n CALL ZLACPY( 'G', N, NRHS, WORK, LDB, B, LDB )\n ELSE IF( NRHS.GT.1 ) THEN\n CHUNK = LWORK / N\n DO 20 I = 1, NRHS, CHUNK\n BL = MIN( NRHS-I+1, CHUNK )\n CALL ZGEMM( 'C', 'N', N, BL, N, CONE, A, LDA, B( 1, I ),\n $ LDB, CZERO, WORK, N )\n CALL ZLACPY( 'G', N, BL, WORK, N, B( 1, I ), LDB )\n 20 CONTINUE\n ELSE\n CALL ZGEMV( 'C', N, N, CONE, A, LDA, B, 1, CZERO, WORK, 1 )\n CALL ZCOPY( N, WORK, 1, B, 1 )\n END IF\n*\n ELSE IF( N.GE.MNTHR .AND. LWORK.GE.3*M+M*M+MAX( M, NRHS, N-2*M ) )\n $ THEN\n*\n* Underdetermined case, M much less than N\n*\n* Path 2a - underdetermined, with many more columns than rows\n* and sufficient workspace for an efficient algorithm\n*\n LDWORK = M\n IF( LWORK.GE.3*M+M*LDA+MAX( M, NRHS, N-2*M ) )\n $ LDWORK = LDA\n ITAU = 1\n IWORK = M + 1\n*\n* Compute A=L*Q\n* (CWorkspace: need 2*M, prefer M+M*NB)\n* (RWorkspace: none)\n*\n CALL ZGELQF( M, N, A, LDA, WORK( ITAU ), WORK( IWORK ),\n $ LWORK-IWORK+1, INFO )\n IL = IWORK\n*\n* Copy L to WORK(IL), zeroing out above it\n*\n CALL ZLACPY( 'L', M, M, A, LDA, WORK( IL ), LDWORK )\n CALL ZLASET( 'U', M-1, M-1, CZERO, CZERO, WORK( IL+LDWORK ),\n $ LDWORK )\n IE = 1\n ITAUQ = IL + LDWORK*M\n ITAUP = ITAUQ + M\n IWORK = ITAUP + M\n*\n* Bidiagonalize L in WORK(IL)\n* (CWorkspace: need M*M+4*M, prefer M*M+3*M+2*M*NB)\n* (RWorkspace: need M)\n*\n CALL ZGEBRD( M, M, WORK( IL ), LDWORK, S, RWORK( IE ),\n $ WORK( ITAUQ ), WORK( ITAUP ), WORK( IWORK ),\n $ LWORK-IWORK+1, INFO )\n*\n* Multiply B by transpose of left bidiagonalizing vectors of L\n* (CWorkspace: need M*M+3*M+NRHS, prefer M*M+3*M+NRHS*NB)\n* (RWorkspace: none)\n*\n CALL ZUNMBR( 'Q', 'L', 'C', M, NRHS, M, WORK( IL ), LDWORK,\n $ WORK( ITAUQ ), B, LDB, WORK( IWORK ),\n $ LWORK-IWORK+1, INFO )\n*\n* Generate right bidiagonalizing vectors of R in WORK(IL)\n* (CWorkspace: need M*M+4*M-1, prefer M*M+3*M+(M-1)*NB)\n* (RWorkspace: none)\n*\n CALL ZUNGBR( 'P', M, M, M, WORK( IL ), LDWORK, WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, INFO )\n IRWORK = IE + M\n*\n* Perform bidiagonal QR iteration, computing right singular\n* vectors of L in WORK(IL) and multiplying B by transpose of\n* left singular vectors\n* (CWorkspace: need M*M)\n* (RWorkspace: need BDSPAC)\n*\n CALL ZBDSQR( 'U', M, M, 0, NRHS, S, RWORK( IE ), WORK( IL ),\n $ LDWORK, A, LDA, B, LDB, RWORK( IRWORK ), INFO )\n IF( INFO.NE.0 )\n $ GO TO 70\n*\n* Multiply B by reciprocals of singular values\n*\n THR = MAX( RCOND*S( 1 ), SFMIN )\n IF( RCOND.LT.ZERO )\n $ THR = MAX( EPS*S( 1 ), SFMIN )\n RANK = 0\n DO 30 I = 1, M\n IF( S( I ).GT.THR ) THEN\n CALL ZDRSCL( NRHS, S( I ), B( I, 1 ), LDB )\n RANK = RANK + 1\n ELSE\n CALL ZLASET( 'F', 1, NRHS, CZERO, CZERO, B( I, 1 ), LDB )\n END IF\n 30 CONTINUE\n IWORK = IL + M*LDWORK\n*\n* Multiply B by right singular vectors of L in WORK(IL)\n* (CWorkspace: need M*M+2*M, prefer M*M+M+M*NRHS)\n* (RWorkspace: none)\n*\n IF( LWORK.GE.LDB*NRHS+IWORK-1 .AND. NRHS.GT.1 ) THEN\n CALL ZGEMM( 'C', 'N', M, NRHS, M, CONE, WORK( IL ), LDWORK,\n $ B, LDB, CZERO, WORK( IWORK ), LDB )\n CALL ZLACPY( 'G', M, NRHS, WORK( IWORK ), LDB, B, LDB )\n ELSE IF( NRHS.GT.1 ) THEN\n CHUNK = ( LWORK-IWORK+1 ) / M\n DO 40 I = 1, NRHS, CHUNK\n BL = MIN( NRHS-I+1, CHUNK )\n CALL ZGEMM( 'C', 'N', M, BL, M, CONE, WORK( IL ), LDWORK,\n $ B( 1, I ), LDB, CZERO, WORK( IWORK ), M )\n CALL ZLACPY( 'G', M, BL, WORK( IWORK ), M, B( 1, I ),\n $ LDB )\n 40 CONTINUE\n ELSE\n CALL ZGEMV( 'C', M, M, CONE, WORK( IL ), LDWORK, B( 1, 1 ),\n $ 1, CZERO, WORK( IWORK ), 1 )\n CALL ZCOPY( M, WORK( IWORK ), 1, B( 1, 1 ), 1 )\n END IF\n*\n* Zero out below first M rows of B\n*\n CALL ZLASET( 'F', N-M, NRHS, CZERO, CZERO, B( M+1, 1 ), LDB )\n IWORK = ITAU + M\n*\n* Multiply transpose(Q) by B\n* (CWorkspace: need M+NRHS, prefer M+NHRS*NB)\n* (RWorkspace: none)\n*\n CALL ZUNMLQ( 'L', 'C', N, NRHS, M, A, LDA, WORK( ITAU ), B,\n $ LDB, WORK( IWORK ), LWORK-IWORK+1, INFO )\n*\n ELSE\n*\n* Path 2 - remaining underdetermined cases\n*\n IE = 1\n ITAUQ = 1\n ITAUP = ITAUQ + M\n IWORK = ITAUP + M\n*\n* Bidiagonalize A\n* (CWorkspace: need 3*M, prefer 2*M+(M+N)*NB)\n* (RWorkspace: need N)\n*\n CALL ZGEBRD( M, N, A, LDA, S, RWORK( IE ), WORK( ITAUQ ),\n $ WORK( ITAUP ), WORK( IWORK ), LWORK-IWORK+1,\n $ INFO )\n*\n* Multiply B by transpose of left bidiagonalizing vectors\n* (CWorkspace: need 2*M+NRHS, prefer 2*M+NRHS*NB)\n* (RWorkspace: none)\n*\n CALL ZUNMBR( 'Q', 'L', 'C', M, NRHS, N, A, LDA, WORK( ITAUQ ),\n $ B, LDB, WORK( IWORK ), LWORK-IWORK+1, INFO )\n*\n* Generate right bidiagonalizing vectors in A\n* (CWorkspace: need 3*M, prefer 2*M+M*NB)\n* (RWorkspace: none)\n*\n CALL ZUNGBR( 'P', M, N, M, A, LDA, WORK( ITAUP ),\n $ WORK( IWORK ), LWORK-IWORK+1, INFO )\n IRWORK = IE + M\n*\n* Perform bidiagonal QR iteration,\n* computing right singular vectors of A in A and\n* multiplying B by transpose of left singular vectors\n* (CWorkspace: none)\n* (RWorkspace: need BDSPAC)\n*\n CALL ZBDSQR( 'L', M, N, 0, NRHS, S, RWORK( IE ), A, LDA, VDUM,\n $ 1, B, LDB, RWORK( IRWORK ), INFO )\n IF( INFO.NE.0 )\n $ GO TO 70\n*\n* Multiply B by reciprocals of singular values\n*\n THR = MAX( RCOND*S( 1 ), SFMIN )\n IF( RCOND.LT.ZERO )\n $ THR = MAX( EPS*S( 1 ), SFMIN )\n RANK = 0\n DO 50 I = 1, M\n IF( S( I ).GT.THR ) THEN\n CALL ZDRSCL( NRHS, S( I ), B( I, 1 ), LDB )\n RANK = RANK + 1\n ELSE\n CALL ZLASET( 'F', 1, NRHS, CZERO, CZERO, B( I, 1 ), LDB )\n END IF\n 50 CONTINUE\n*\n* Multiply B by right singular vectors of A\n* (CWorkspace: need N, prefer N*NRHS)\n* (RWorkspace: none)\n*\n IF( LWORK.GE.LDB*NRHS .AND. NRHS.GT.1 ) THEN\n CALL ZGEMM( 'C', 'N', N, NRHS, M, CONE, A, LDA, B, LDB,\n $ CZERO, WORK, LDB )\n CALL ZLACPY( 'G', N, NRHS, WORK, LDB, B, LDB )\n ELSE IF( NRHS.GT.1 ) THEN\n CHUNK = LWORK / N\n DO 60 I = 1, NRHS, CHUNK\n BL = MIN( NRHS-I+1, CHUNK )\n CALL ZGEMM( 'C', 'N', N, BL, M, CONE, A, LDA, B( 1, I ),\n $ LDB, CZERO, WORK, N )\n CALL ZLACPY( 'F', N, BL, WORK, N, B( 1, I ), LDB )\n 60 CONTINUE\n ELSE\n CALL ZGEMV( 'C', M, N, CONE, A, LDA, B, 1, CZERO, WORK, 1 )\n CALL ZCOPY( N, WORK, 1, B, 1 )\n END IF\n END IF\n*\n* Undo scaling\n*\n IF( IASCL.EQ.1 ) THEN\n CALL ZLASCL( 'G', 0, 0, ANRM, SMLNUM, N, NRHS, B, LDB, INFO )\n CALL DLASCL( 'G', 0, 0, SMLNUM, ANRM, MINMN, 1, S, MINMN,\n $ INFO )\n ELSE IF( IASCL.EQ.2 ) THEN\n CALL ZLASCL( 'G', 0, 0, ANRM, BIGNUM, N, NRHS, B, LDB, INFO )\n CALL DLASCL( 'G', 0, 0, BIGNUM, ANRM, MINMN, 1, S, MINMN,\n $ INFO )\n END IF\n IF( IBSCL.EQ.1 ) THEN\n CALL ZLASCL( 'G', 0, 0, SMLNUM, BNRM, N, NRHS, B, LDB, INFO )\n ELSE IF( IBSCL.EQ.2 ) THEN\n CALL ZLASCL( 'G', 0, 0, BIGNUM, BNRM, N, NRHS, B, LDB, INFO )\n END IF\n 70 CONTINUE\n WORK( 1 ) = MAXWRK\n RETURN\n*\n* End of ZGELSS\n*\n END\n", "meta": {"hexsha": "f59b829f7b8a803a5d93445a96413ae6dd02ef16", "size": 22211, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Code/External/Ipopt-3.10.2/ThirdParty/Lapack/LAPACK/SRC/zgelss.f", "max_stars_repo_name": "fbudin69500/calatk", "max_stars_repo_head_hexsha": "3cee90488feab7e3ef2ade1f791106aa7f11e404", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-09-15T12:51:02.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-08T14:03:58.000Z", "max_issues_repo_path": "Code/External/Ipopt-3.10.2/ThirdParty/Lapack/LAPACK/SRC/zgelss.f", "max_issues_repo_name": "cpatrick/calatk", "max_issues_repo_head_hexsha": "849c17919ac5084b5b067c7631bc2aa1efd650df", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Code/External/Ipopt-3.10.2/ThirdParty/Lapack/LAPACK/SRC/zgelss.f", "max_forks_repo_name": "cpatrick/calatk", "max_forks_repo_head_hexsha": "849c17919ac5084b5b067c7631bc2aa1efd650df", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-10-20T16:38:28.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-20T16:38:28.000Z", "avg_line_length": 34.9229559748, "max_line_length": 76, "alphanum_fraction": 0.4783665751, "num_tokens": 7481, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953003183443, "lm_q2_score": 0.7371581568543044, "lm_q1q2_score": 0.661743412999442}} {"text": "SUBROUTINE beam_km(km,ei,ell)\r\n!\r\n! This subroutine forms the stiffness matrix of a\r\n! beam element (bending only).\r\n!\r\n IMPLICIT NONE\r\n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\r\n REAL(iwp),INTENT(IN)::ei,ell\r\n REAL(iwp),INTENT(OUT)::km(:,:)\r\n REAL(iwp)::two=2.0_iwp,d4=4.0_iwp,d6=6.0_iwp,d12=12.0_iwp\r\n km(1,1)=d12*ei/(ell*ell*ell) \r\n km(3,3)=km(1,1)\r\n km(1,2)=d6*ei/(ell*ell) \r\n km(2,1)=km(1,2) \r\n km(1,4)=km(1,2)\r\n km(4,1)=km(1,4) \r\n km(1,3)=-km(1,1) \r\n km(3,1)=km(1,3) \r\n km(3,4)=-km(1,2)\r\n km(4,3)=km(3,4) \r\n km(2,3)=km(3,4) \r\n km(3,2)=km(2,3)\r\n km(2,2)=d4*ei/ell\r\n km(4,4)=km(2,2) \r\n km(2,4)=two*ei/ell \r\n km(4,2)=km(2,4)\r\nRETURN\r\nEND SUBROUTINE beam_km \r\n", "meta": {"hexsha": "61b703dbed50a776e5f9f9cd5835154b1edb273a", "size": 720, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "src/libs/main/beam_km.f03", "max_stars_repo_name": "leemargetts/PoreFEM", "max_stars_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/libs/main/beam_km.f03", "max_issues_repo_name": "leemargetts/PoreFEM", "max_issues_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/libs/main/beam_km.f03", "max_forks_repo_name": "leemargetts/PoreFEM", "max_forks_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.8275862069, "max_line_length": 77, "alphanum_fraction": 0.5472222222, "num_tokens": 334, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191297273498, "lm_q2_score": 0.6926419958239132, "lm_q1q2_score": 0.6616941486631154}} {"text": "\n\nSUBROUTINE classico(uint,vint,wint)\n\n\tUSE velpre\n\tUSE parametros\n\n\tIMPLICIT NONE\n\n\t!===================================================================================================================\n\treal(8), dimension(nx1,ny,nz) :: uint\n\treal(8), dimension(nx,ny1,nz) :: vint\n\treal(8), dimension(nx,ny,nz1) :: wint\n\n\treal(8), dimension(nx1,ny,nz) :: dudx, dudy, dudz, bma, dma, dudxa, dudya, dudza\n\treal(8), dimension(nx,ny1,nz) :: dvdx, dvdy, dvdz, amb, dmb, dvdxa, dvdya, dvdza\n\treal(8), dimension(nx,ny,nz1) :: dwdx, dwdy, dwdz, amd, bmd, dwdxa, dwdya, dwdza\n\treal(8), dimension(nx,ny,nz) :: aux\n\n\t!contadores\n\tinteger :: i, j, k\n\n\t!auxiliares\n\treal(8) :: aux1, aux2\n\n\n\n\n\t!===================================================================================================================\n\t!RESOLU\u00c7\u00c3O DO PROBLEMA\n\t!===================================================================================================================\n\n\tif (der == 1) then\n\t! upwind\n\n\tdo k = 1, nz\n\tdo j = 1, ny\n\tdo i = 1, nx1\n\n\tbma(i,j,k) = (v(i,j,k) + v(i-1,j,k) + v(i,j+1,k) + v(i-1,j+1,k)) * 0.25\n\tdma(i,j,k) = (w(i,j,k) + w(i-1,j,k) + w(i,j,k+1) + w(i-1,j,k+1)) * 0.25\n\n\taux1 = max(u(i,j,k),0.)\n\taux2 = min(u(i,j,k),0.)\n\tdudx(i,j,k) = aux1*(u(i,j,k)-u(i-1,j,k))/dx + aux2*(u(i+1,j,k)-u(i,j,k))/dx\n\n\taux1 = max(bma(i,j,k),0.)\n\taux2 = min(bma(i,j,k),0.)\n\tdudy(i,j,k) = aux1*(u(i,j,k)-u(i,j-1,k))/dy + aux2*(u(i,j+1,k)-u(i,j,k))/dy\n\n\taux1 = max(dma(i,j,k),0.)\n\taux2 = min(dma(i,j,k),0.)\n\tdudz(i,j,k) = aux1*(u(i,j,k)-u(i,j,k-1))/dz + aux2*(u(i,j,k+1)-u(i,j,k))/dz\n\n\tuint(i,j,k) = dudx(i,j,k) + dudy(i,j,k) + dudz(i,j,k)\n\n\tenddo\n\tenddo\n\tenddo\n\n\n\n\tdo k = 1, nz\n\tdo j = 1, ny1\n\tdo i = 1, nx\n\n\tamb(i,j,k) = (u(i,j,k) + u(i+1,j,k) + u(i,j-1,k) + u(i+1,j-1,k)) * 0.25\n\tdmb(i,j,k) = (w(i,j,k) + w(i,j-1,k) + w(i,j,k+1) + w(i,j-1,k+1)) * 0.25\n\n\taux1 = max(amb(i,j,k),0.)\n\taux2 = min(amb(i,j,k),0.)\n\tdvdx(i,j,k) = aux1*(v(i,j,k)-v(i-1,j,k))/dx + aux2*(v(i+1,j,k)-v(i,j,k))/dx\n\n\taux1 = max(v(i,j,k),0.)\n\taux2 = min(v(i,j,k),0.)\n\tdvdy(i,j,k) = aux1*(v(i,j,k)-v(i,j-1,k))/dy + aux2*(v(i,j+1,k)-v(i,j,k))/dy\n\n\taux1 = max(dmb(i,j,k),0.)\n\taux2 = min(dmb(i,j,k),0.)\n\tdvdz(i,j,k) = aux1*(v(i,j,k)-v(i,j,k-1))/dz + aux2*(v(i,j,k+1)-v(i,j,k))/dz\n\n\tvint(i,j,k) = dvdx(i,j,k) + dvdy(i,j,k) + dvdz(i,j,k)\n\n\tenddo\n\tenddo\n\tenddo\n\n\n\tdo k = 1, nz1\n\tdo j = 1, ny\n\tdo i = 1, nx\n\n\tamd(i,j,k) = (u(i,j,k) + u(i+1,j,k) + u(i,j,k-1) + u(i+1,j,k-1)) * 0.25\n\tbmd(i,j,k) = (v(i,j,k) + v(i,j+1,k) + v(i,j,k-1) + v(i,j+1,k-1)) * 0.25\n\n\taux1 = max(amd(i,j,k),0.)\n\taux2 = min(amd(i,j,k),0.)\n\tdwdx(i,j,k) = aux1*(w(i,j,k)-w(i-1,j,k))/dx + aux2*(w(i+1,j,k)-w(i,j,k))/dx\n\n\taux1 = max(bmd(i,j,k),0.)\n\taux2 = min(bmd(i,j,k),0.)\n\tdwdy(i,j,k) = aux1*(w(i,j,k)-w(i,j-1,k))/dy + aux2*(w(i,j+1,k)-w(i,j,k))/dy\n\n\taux1 = max(w(i,j,k),0.)\n\taux2 = min(w(i,j,k),0.)\n\tdwdz(i,j,k) = aux1*(w(i,j,k)-w(i,j,k-1))/dz + aux2*(w(i,j,k+1)-w(i,j,k))/dz\n\n\twint(i,j,k) = dwdx(i,j,k) + dwdy(i,j,k) + dwdz(i,j,k)\n\n\tenddo\n\tenddo\n\tenddo\n\n\n\telseif (der == 2) then\n\n\n\tCALL derivax(u,nx1,ny,nz,dudx)\n\tCALL derivay(u,nx1,ny,nz,dudy)\n\tCALL derivaz(u,nx1,ny,nz,dudz)\n\n\tCALL derivax(v,nx,ny1,nz,dvdx)\n\tCALL derivay(v,nx,ny1,nz,dvdy)\n\tCALL derivaz(v,nx,ny1,nz,dvdz)\n\n\tCALL derivax(w,nx,ny,nz1,dwdx)\n\tCALL derivay(w,nx,ny,nz1,dwdy)\n\tCALL derivaz(w,nx,ny,nz1,dwdz)\n\n\tcall interpy_fc(v(1:nx,1:ny1,1:nz),nx,ny1,nz,aux) !(nx,ny,nz)\n\tcall interpx_cf(aux,nx,ny,nz,bma) !(nx1,ny,nz)\n\n\tcall interpz_fc(w(1:nx,1:ny,1:nz1),nx,ny,nz1,aux) !(nx,ny,nz)\n\tcall interpx_cf(aux,nx,ny,nz,dma) !(nx1,ny,nz)\n\n\tcall interpx_fc(u(1:nx1,1:ny,1:nz),nx1,ny,nz,aux) !(nx,ny,nz)\n\tcall interpy_cf(aux,nx,ny,nz,amb) !(nx,ny1,nz)\n\n\tcall interpz_fc(w(1:nx,1:ny,1:nz1),nx,ny,nz1,aux) !(nx,ny,nz)\n\tcall interpy_cf(aux,nx,ny,nz,dmb) !(nx,ny1,nz)\n\n\tcall interpx_fc(u(1:nx1,1:ny,1:nz),nx1,ny,nz,aux) !(nx,ny,nz)\n\tcall interpz_cf(aux,nx,ny,nz,amd) !(nx,ny,nz1)\n\n\tcall interpy_fc(v(1:nx,1:ny1,1:nz),nx,ny1,nz,aux) !(nx,ny,nz)\n\tcall interpz_cf(aux,nx,ny,nz,bmd) !(nx,ny,nz1)\n\n\tdo k = 1, nz\n\tdo j = 1, ny\n\tdo i = 1, nx1\n\tuint(i,j,k) = u(i,j,k)*dudx(i,j,k) + bma(i,j,k)*dudy(i,j,k) + dma(i,j,k)*dudz(i,j,k)\n\tenddo\n\tenddo\n\tenddo\n\n\tdo k = 1, nz\n\tdo j = 1, ny1\n\tdo i = 1, nx\n\tvint(i,j,k) = amb(i,j,k)*dvdx(i,j,k) + v(i,j,k)*dvdy(i,j,k) + dmb(i,j,k)*dvdz(i,j,k)\n\tenddo\n\tenddo\n\tenddo\n\n\tdo k = 1, nz1\n\tdo j = 1, ny\n\tdo i = 1, nx\n\twint(i,j,k) = amd(i,j,k)*dwdx(i,j,k) + bmd(i,j,k)*dwdy(i,j,k) + w(i,j,k)*dwdz(i,j,k)\n\tenddo\n\tenddo\n\tenddo\n\n\n\n\telseif (der == 3) then\n\t! upwind 2nd order\n\n\n\tcall interpy_fc(v(1:nx,1:ny1,1:nz),nx,ny1,nz,aux) !(nx,ny,nz)\n\tcall interpx_cf(aux,nx,ny,nz,bma) !(nx1,ny,nz)\n\n\tcall interpz_fc(w(1:nx,1:ny,1:nz1),nx,ny,nz1,aux) !(nx,ny,nz)\n\tcall interpx_cf(aux,nx,ny,nz,dma) !(nx1,ny,nz)\n\n\tcall interpx_fc(u(1:nx1,1:ny,1:nz),nx1,ny,nz,aux) !(nx,ny,nz)\n\tcall interpy_cf(aux,nx,ny,nz,amb) !(nx,ny1,nz)\n\n\tcall interpz_fc(w(1:nx,1:ny,1:nz1),nx,ny,nz1,aux) !(nx,ny,nz)\n\tcall interpy_cf(aux,nx,ny,nz,dmb) !(nx,ny1,nz)\n\n\tcall interpx_fc(u(1:nx1,1:ny,1:nz),nx1,ny,nz,aux) !(nx,ny,nz)\n\tcall interpz_cf(aux,nx,ny,nz,amd) !(nx,ny,nz1)\n\n\tcall interpy_fc(v(1:nx,1:ny1,1:nz),nx,ny1,nz,aux) !(nx,ny,nz)\n\tcall interpz_cf(aux,nx,ny,nz,bmd) !(nx,ny,nz1)\n\n\n\tCALL derivaxu2n(u,nx1,ny,nz,dudxa)\n\tCALL derivaxu2p(u,nx1,ny,nz,dudx)\n\tCALL derivayu2n(u,nx1,ny,nz,dudya)\n\tCALL derivayu2p(u,nx1,ny,nz,dudy)\n\tCALL derivazu2n(u,nx1,ny,nz,dudza)\n\tCALL derivazu2p(u,nx1,ny,nz,dudz)\n\n\tCALL derivaxu2n(v,nx,ny1,nz,dvdxa)\n\tCALL derivaxu2p(v,nx,ny1,nz,dvdx)\n\tCALL derivayu2n(v,nx,ny1,nz,dvdya)\n\tCALL derivayu2p(v,nx,ny1,nz,dvdy)\n\tCALL derivazu2n(v,nx,ny1,nz,dvdza)\n\tCALL derivazu2p(v,nx,ny1,nz,dvdz)\n\n\tCALL derivaxu2n(w,nx,ny,nz1,dwdxa)\n\tCALL derivaxu2p(w,nx,ny,nz1,dwdx)\n\tCALL derivayu2n(w,nx,ny,nz1,dwdya)\n\tCALL derivayu2p(w,nx,ny,nz1,dwdy)\n\tCALL derivazu2n(w,nx,ny,nz1,dwdza)\n\tCALL derivazu2p(w,nx,ny,nz1,dwdz)\n\n\n\tdo k = 1, nz\n\tdo j = 1, ny\n\tdo i = 1, nx1\n\n\taux1 = max(u(i,j,k),0.)\n\taux2 = min(u(i,j,k),0.)\n\tdudx(i,j,k) = aux1*dudxa(i,j,k) + aux2*dudx(i,j,k)\n\n\taux1 = max(bma(i,j,k),0.)\n\taux2 = min(bma(i,j,k),0.)\n\tdudy(i,j,k) = aux1*dudya(i,j,k) + aux2*dudy(i,j,k)\n\n\taux1 = max(dma(i,j,k),0.)\n\taux2 = min(dma(i,j,k),0.)\n\tdudz(i,j,k) = aux1*dudza(i,j,k) + aux2*dudz(i,j,k)\n\n\tuint(i,j,k) = dudx(i,j,k) + dudy(i,j,k) + dudz(i,j,k)\n\n\tenddo\n\tenddo\n\tenddo\n\n\tdo k = 1, nz\n\tdo j = 1, ny1\n\tdo i = 1, nx\n\n\taux1 = max(amb(i,j,k),0.)\n\taux2 = min(amb(i,j,k),0.)\n\tdvdx(i,j,k) = aux1*dvdxa(i,j,k) + aux2*dvdx(i,j,k)\n\n\taux1 = max(v(i,j,k),0.)\n\taux2 = min(v(i,j,k),0.)\n\tdvdy(i,j,k) = aux1*dvdya(i,j,k) + aux2*dvdy(i,j,k)\n\n\taux1 = max(dmb(i,j,k),0.)\n\taux2 = min(dmb(i,j,k),0.)\n\tdvdz(i,j,k) = aux1*dvdza(i,j,k) + aux2*dvdz(i,j,k)\n\n\tvint(i,j,k) = dvdx(i,j,k) + dvdy(i,j,k) + dvdz(i,j,k)\n\n\tenddo\n\tenddo\n\tenddo\n\n\tdo k = 1, nz1\n\tdo j = 1, ny\n\tdo i = 1, nx\n\n\taux1 = max(amd(i,j,k),0.)\n\taux2 = min(amd(i,j,k),0.)\n\tdwdx(i,j,k) = aux1*dwdxa(i,j,k) + aux2*dwdx(i,j,k)\n\n\taux1 = max(bmd(i,j,k),0.)\n\taux2 = min(bmd(i,j,k),0.)\n\tdwdy(i,j,k) = aux1*dwdya(i,j,k) + aux2*dwdy(i,j,k)\n\n\taux1 = max(w(i,j,k),0.)\n\taux2 = min(w(i,j,k),0.)\n\tdwdz(i,j,k) = aux1*dwdza(i,j,k) + aux2*dwdz(i,j,k)\n\n\twint(i,j,k) = dwdx(i,j,k) + dwdy(i,j,k) + dwdz(i,j,k)\n\n\tenddo\n\tenddo\n\tenddo\n\n\n\n\tendif\n\n!==================================================================================================================\nEND SUBROUTINE classico\n\n\nSUBROUTINE rotacional(uint,vint,wint)\n\n\tUSE velpre\n\tUSE parametros\n\n\tIMPLICIT NONE\n\n\t!===================================================================================================================\n\treal(8), dimension(nx1,ny,nz) :: uint\n\treal(8), dimension(nx,ny1,nz) :: vint\n\treal(8), dimension(nx,ny,nz1) :: wint\n\n\treal(8), dimension(0:nx1+1,0:ny1+1,0:nz1+1) :: ap, an, bma, dma\n\treal(8), dimension(0:nx1+1,0:ny1+1,0:nz1+1) :: bp, bn, amb, dmb\n\treal(8), dimension(0:nx1+1,0:ny1+1,0:nz1+1) :: dp, dn, amd, bmd\n\n\t!\n\treal(8), dimension(nx1,ny1,nz1) :: dudx, dvdx, dwdx\n\treal(8), dimension(nx1,ny1,nz1) :: dudy, dvdy, dwdy\n\treal(8), dimension(nx1,ny1,nz1) :: dudz, dvdz, dwdz\n\n\t!\n\treal(8) :: aa, bb, dd\n\n\t!contadores\n\tinteger :: i, j, k, ai, bi, di\n\n\t!plotagem\n\treal(8) :: acont, bcont, dcont \n\tinteger :: loca(3), locb(3), locd(3)\n\n\t!auxiliares\n\treal(8) :: aux1, aux2\n\n\n\t!===================================================================================================================\n\t!RESOLU\u00c7\u00c3O DO PROBLEMA\n\t!===================================================================================================================\n\n\tif (der == 1) then\n\t! upwind\n\n\tdo k = 0, nz+1\n\tdo j = 0, ny+1\n\tdo i = 1, nx+1\n\n\tbma(i,j,k) = (v(i,j,k) + v(i-1,j,k) + v(i,j+1,k) + v(i-1,j+1,k)) * 0.25\n\tdma(i,j,k) = (w(i,j,k) + w(i-1,j,k) + w(i,j,k+1) + w(i-1,j,k+1)) * 0.25\n\n\tap(i,j,k) = max(u(i,j,k),0.)\n\tan(i,j,k) = min(u(i,j,k),0.)\n\n\tbp(i,j,k) = max(bma(i,j,k),0.)\n\tbn(i,j,k) = min(bma(i,j,k),0.)\n\n\tdp(i,j,k) = max(dma(i,j,k),0.)\n\tdn(i,j,k) = min(dma(i,j,k),0.)\n\n\tenddo\n\tenddo\n\tenddo\n\n\tap(0,0:ny+1,0:nz+1) = max(u(0,0:ny+1,0:nz+1),0.)\n\tan(nx1+1,0:ny+1,0:nz+1) = min(u(nx1+1,0:ny+1,0:nz+1),0.)\n\n\tdo k = 1, nz\n\tdo j = 1, ny\n\tdo i = 1, nx1\n\n\tdudx(i,j,k) = (ap(i,j,k)*u(i,j,k)-ap(i-1,j,k)*u(i-1,j,k))/dx + (an(i+1,j,k)*u(i+1,j,k)-an(i,j,k)*u(i,j,k))/dx\n\tdudy(i,j,k) = (bp(i,j,k)*u(i,j,k)-bp(i,j-1,k)*u(i,j-1,k))/dy + (bn(i,j+1,k)*u(i,j+1,k)-bn(i,j,k)*u(i,j,k))/dy\n\tdudz(i,j,k) = (dp(i,j,k)*u(i,j,k)-dp(i,j,k-1)*u(i,j,k-1))/dz + (dn(i,j,k+1)*u(i,j,k+1)-dn(i,j,k)*u(i,j,k))/dz\n\n\tuint(i,j,k) = dudx(i,j,k) + dudy(i,j,k) + dudz(i,j,k)\n\n\tenddo\n\tenddo\n\tenddo\n\n\n\tdo k = 0, nz+1\n\tdo j = 1, ny+1\n\tdo i = 0, nx+1\n\n\tamb(i,j,k) = (u(i,j,k) + u(i+1,j,k) + u(i,j-1,k) + u(i+1,j-1,k)) * 0.25\n\tdmb(i,j,k) = (w(i,j,k) + w(i,j-1,k) + w(i,j,k+1) + w(i,j-1,k+1)) * 0.25\n\n\tap(i,j,k) = max(amb(i,j,k),0.)\n\tan(i,j,k) = min(amb(i,j,k),0.)\n\n\tbp(i,j,k) = max(v(i,j,k),0.)\n\tbn(i,j,k) = min(v(i,j,k),0.)\n\n\tdp(i,j,k) = max(dmb(i,j,k),0.)\n\tdn(i,j,k) = min(dmb(i,j,k),0.)\n\n\n\tenddo\n\tenddo\n\tenddo\n\n\tbp(0:nx+1,0,0:nz+1) = max(v(0:nx+1,0,0:nz+1),0.)\n\tbn(0:nx+1,ny1+1,0:nz+1) = min(v(0:nx+1,ny1+1,0:nz+1),0.)\n\n\n\tdo k = 1, nz\n\tdo j = 1, ny1\n\tdo i = 1, nx\n\n\tdvdx(i,j,k) = (ap(i,j,k)*v(i,j,k)-ap(i-1,j,k)*v(i-1,j,k))/dx + (an(i+1,j,k)*v(i+1,j,k)-an(i,j,k)*v(i,j,k))/dx\n\tdvdy(i,j,k) = (bp(i,j,k)*v(i,j,k)-bp(i,j-1,k)*v(i,j-1,k))/dy + (bn(i,j+1,k)*v(i,j+1,k)-bn(i,j,k)*v(i,j,k))/dy\n\tdvdz(i,j,k) = (dp(i,j,k)*v(i,j,k)-dp(i,j,k-1)*v(i,j,k-1))/dz + (dn(i,j,k+1)*v(i,j,k+1)-dn(i,j,k)*v(i,j,k))/dz\n\n\tvint(i,j,k) = dvdx(i,j,k) + dvdy(i,j,k) + dvdz(i,j,k)\n\n\tenddo\n\tenddo\n\tenddo\n\n\tdo k = 1, nz+1\n\tdo j = 0, ny+1\n\tdo i = 0, nx+1\n\n\tamd(i,j,k) = (u(i,j,k) + u(i+1,j,k) + u(i,j,k-1) + u(i+1,j,k-1)) * 0.25\n\tbmd(i,j,k) = (v(i,j,k) + v(i,j+1,k) + v(i,j,k-1) + v(i,j+1,k-1)) * 0.25\n\n\tap(i,j,k) = max(amd(i,j,k),0.)\n\tan(i,j,k) = min(amd(i,j,k),0.)\n\n\tbp(i,j,k) = max(bmd(i,j,k),0.)\n\tbn(i,j,k) = min(bmd(i,j,k),0.)\n\n\tdp(i,j,k) = max(w(i,j,k),0.)\n\tdn(i,j,k) = min(w(i,j,k),0.)\n\n\tenddo\n\tenddo\n\tenddo\n\n\tdp(0:nx+1,0:ny+1,0) = max(w(0:nx+1,0:ny+1,0),0.)\n\tdp(0:nx+1,0:ny+1,nz1+1) = min(w(0:nx+1,0:ny+1,nz1+1),0.)\n\tdo k = 1, nz1\n\tdo j = 1, ny\n\tdo i = 1, nx\n\n\tdwdx(i,j,k) = (ap(i,j,k)*w(i,j,k)-ap(i-1,j,k)*w(i-1,j,k))/dx + (an(i+1,j,k)*w(i+1,j,k)-an(i,j,k)*w(i,j,k))/dx\n\tdwdy(i,j,k) = (bp(i,j,k)*w(i,j,k)-bp(i,j-1,k)*w(i,j-1,k))/dy + (bn(i,j+1,k)*w(i,j+1,k)-bn(i,j,k)*w(i,j,k))/dy\n\tdwdz(i,j,k) = (dp(i,j,k)*w(i,j,k)-dp(i,j,k-1)*w(i,j,k-1))/dz + (dn(i,j,k+1)*w(i,j,k+1)-dn(i,j,k)*w(i,j,k))/dz\n\n\twint(i,j,k) = dwdx(i,j,k) + dwdy(i,j,k) + dwdz(i,j,k)\n\n\tenddo\n\tenddo\n\tenddo\n\n\telse\n\n\twrite(*,*) \"n\u00e3o possui este esquema para o rotacional\"\n\tSTOP\n\n\tendif\n\n\n!==================================================================================================================\nEND SUBROUTINE rotacional\n\n\nSUBROUTINE antissim(uint,vint,wint)\n\n\tUSE velpre\n\tUSE parametros\n\n\tIMPLICIT NONE\n\n\t!===================================================================================================================\n\treal(8), dimension(nx1,ny,nz) :: uint\n\treal(8), dimension(nx,ny1,nz) :: vint\n\treal(8), dimension(nx,ny,nz1) :: wint\n\n\treal(8), dimension(0:nx1+1,0:ny1+1,0:nz1+1) :: ap, an\n\treal(8), dimension(0:nx1+1,0:ny1+1,0:nz1+1) :: bp, bn\n\treal(8), dimension(0:nx1+1,0:ny1+1,0:nz1+1) :: dp, dn\n\n\t!\n\treal(8), dimension(nx1,ny1,nz1) :: dudx, dvdx, dwdx\n\treal(8), dimension(nx1,ny1,nz1) :: dudy, dvdy, dwdy \n\treal(8), dimension(nx1,ny1,nz1) :: dudz, dvdz, dwdz\n\treal(8), dimension(nx1,ny1,nz1) :: bma, dma,amb, dmb, amd, bmd\n\n\t!\n\treal(8) :: aa, bb, dd\n\n\t!contadores\n\tinteger :: i, j, k, ai, bi, di\n\n\t!plotagem\n\treal(8) :: acont, bcont, dcont \n\tinteger :: loca(3), locb(3), locd(3)\n\n\t!auxiliares\n\treal(8) :: aux1, aux2\n\n\n\t!===================================================================================================================\n\t!RESOLU\u00c7\u00c3O DO PROBLEMA\n\t!===================================================================================================================\n\n\tif (der == 1) then\n\t! upwind\n\n\tdo k = 1, nz+1\n\tdo j = 1, ny+1\n\tdo i = 1, nx+1\n\tbma(i,j,k) = (v(i,j,k) + v(i-1,j,k) + v(i,j+1,k) + v(i-1,j+1,k)) * 0.25\n\tdma(i,j,k) = (w(i,j,k) + w(i-1,j,k) + w(i,j,k+1) + w(i-1,j,k+1)) * 0.25\n\n\tap(i,j,k) = max(u(i,j,k),0.)\n\tan(i,j,k) = min(u(i,j,k),0.)\n\n\tbp(i,j,k) = max(bma(i,j,k),0.)\n\tbn(i,j,k) = min(bma(i,j,k),0.)\n\n\tdp(i,j,k) = max(dma(i,j,k),0.)\n\tdn(i,j,k) = min(dma(i,j,k),0.)\n\tenddo\n\tenddo\n\tenddo\n\n\tap(0,:,:) = ap(1,:,:)\n\tbp(:,0,:) = bp(:,1,:)\n\tdp(:,:,0) = dp(:,:,1)\n an(nx1+1,:,:)=an(nx1,:,:)\n\n\n\tdo k = 1, nz\n\tdo j = 1, ny\n\tdo i = 1, nx1\n\n\tdudx(i,j,k) = ((ap(i,j,k)*u(i,j,k)-ap(i-1,j,k)*u(i-1,j,k))/dx + (an(i+1,j,k)*u(i+1,j,k)-an(i,j,k)*u(i,j,k))/dx & \n\t+ ap(i,j,k)*(u(i,j,k)-u(i-1,j,k))/dx + an(i,j,k)*(u(i+1,j,k)-u(i,j,k))/dx) * 0.5\n\n\n\tdudy(i,j,k) = ((bp(i,j,k)*u(i,j,k)-bp(i,j-1,k)*u(i,j-1,k))/dy + (bn(i,j+1,k)*u(i,j+1,k)-bn(i,j,k)*u(i,j,k))/dy &\n\t+ bp(i,j,k)*(u(i,j,k)-u(i,j-1,k))/dy + bn(i,j,k)*(u(i,j+1,k)-u(i,j,k))/dy) * 0.5\n\n\tdudz(i,j,k) = ((dp(i,j,k)*u(i,j,k)-dp(i,j,k-1)*u(i,j,k-1))/dz+(dn(i,j,k+1)*u(i,j,k+1)-dn(i,j,k)*u(i,j,k))/dz &\n\t+ dp(i,j,k)*(u(i,j,k)-u(i,j,k-1))/dz + dn(i,j,k)*(u(i,j,k+1)-u(i,j,k))/dz) * 0.5\n\n\n\tuint(i,j,k) = dudx(i,j,k) + dudy(i,j,k) + dudz(i,j,k)\n\n\tenddo\n\tenddo\n\tenddo\n\n\n\tdo k = 1, nz+1\n\tdo j = 1, ny+1\n\tdo i = 1, nx+1\n\n\tamb(i,j,k) = (u(i,j,k) + u(i+1,j,k) + u(i,j-1,k) + u(i+1,j-1,k)) * 0.25\n\tdmb(i,j,k) = (w(i,j,k) + w(i,j-1,k) + w(i,j,k+1) + w(i,j-1,k+1)) * 0.25\n\n\tap(i,j,k) = max(amb(i,j,k),0.)\n\tan(i,j,k) = min(amb(i,j,k),0.)\n\n\tbp(i,j,k) = max(v(i,j,k),0.)\n\tbn(i,j,k) = min(v(i,j,k),0.)\n\n\tdp(i,j,k) = max(dmb(i,j,k),0.)\n\tdn(i,j,k) = min(dmb(i,j,k),0.)\n\n\n\tenddo\n\tenddo\n\tenddo\n\n\n\tap(0,:,:) = ap(1,:,:)\n\tbp(:,0,:) = bp(:,1,:)\n\tdp(:,:,0) = dp(:,:,1)\n bn(:,ny1+1,:)=bn(:,ny1,:)\n\n\tdo k = 1, nz\n\tdo j = 1, ny1\n\tdo i = 1, nx\n\n\tdvdx(i,j,k) = ((ap(i,j,k)*v(i,j,k)-ap(i-1,j,k)*v(i-1,j,k))/dx + (an(i+1,j,k)*v(i+1,j,k)-an(i,j,k)*v(i,j,k))/dx &\n\t+ ap(i,j,k)*(v(i,j,k)-v(i-1,j,k))/dx + an(i,j,k)*(v(i+1,j,k)-v(i,j,k))/dx) * 0.5\n\n\n\tdvdy(i,j,k) = ((bp(i,j,k)*v(i,j,k)-bp(i,j-1,k)*v(i,j-1,k))/dy + (bn(i,j+1,k)*v(i,j+1,k)-bn(i,j,k)*v(i,j,k))/dy &\n\t+ bp(i,j,k)*(v(i,j,k)-v(i,j-1,k))/dy + bn(i,j,k)*(v(i,j+1,k)-v(i,j,k))/dy) * 0.5\n\n\n\tdvdz(i,j,k) = ((dp(i,j,k)*v(i,j,k)-dp(i,j,k-1)*v(i,j,k-1))/dz+(dn(i,j,k+1)*v(i,j,k+1)-dn(i,j,k)*v(i,j,k))/dz &\n\t+ dp(i,j,k)*(v(i,j,k)-v(i,j,k-1))/dz + dn(i,j,k)*(v(i,j,k+1)-v(i,j,k))/dz) * 0.5\n\n\n\tvint(i,j,k) = dvdx(i,j,k) + dvdy(i,j,k) + dvdz(i,j,k)\n\n\tenddo\n\tenddo\n\tenddo\n\n\tdo k = 1, nz+1\n\tdo j = 1, ny+1\n\tdo i = 1, nx+1\n\n\tamd(i,j,k) = (u(i,j,k) + u(i+1,j,k) + u(i,j,k-1) + u(i+1,j,k-1)) * 0.25\n\tbmd(i,j,k) = (v(i,j,k) + v(i,j+1,k) + v(i,j,k-1) + v(i,j+1,k-1)) * 0.25\n\n\tap(i,j,k) = max(amd(i,j,k),0.)\n\tan(i,j,k) = min(amd(i,j,k),0.)\n\n\tbp(i,j,k) = max(bmd(i,j,k),0.)\n\tbn(i,j,k) = min(bmd(i,j,k),0.)\n\n\tdp(i,j,k) = max(w(i,j,k),0.)\n\tdn(i,j,k) = min(w(i,j,k),0.)\n\n\tenddo\n\tenddo\n\tenddo\n\n\tap(0,:,:) = ap(1,:,:)\n\tbp(:,0,:) = bp(:,1,:)\n\tdp(:,:,0) = dp(:,:,1)\n dn(:,:,nz1+1)=dn(:,:,nz1)\n\n\tdo k = 1, nz1\n\tdo j = 1, ny\n\tdo i = 1, nx\n\n\tdwdx(i,j,k) = ((ap(i,j,k)*w(i,j,k)-ap(i-1,j,k)*w(i-1,j,k))/dx + (an(i+1,j,k)*w(i+1,j,k)-an(i,j,k)*w(i,j,k))/dx &\n\t+ ap(i,j,k)*(w(i,j,k)-w(i-1,j,k))/dx + an(i,j,k)*(w(i+1,j,k)-w(i,j,k))/dx) * 0.5\n\n\tdwdy(i,j,k) = ((bp(i,j,k)*w(i,j,k)-bp(i,j-1,k)*w(i,j-1,k))/dy + (bn(i,j+1,k)*w(i,j+1,k)-bn(i,j,k)*w(i,j,k))/dy &\n\t+ bp(i,j,k)*(w(i,j,k)-w(i,j-1,k))/dy + bn(i,j,k)*(w(i,j+1,k)-w(i,j,k))/dy) * 0.5\n\n\tdwdz(i,j,k) = ((dp(i,j,k)*w(i,j,k)-dp(i,j,k-1)*w(i,j,k-1))/dz+(dn(i,j,k+1)*w(i,j,k+1)-dn(i,j,k)*w(i,j,k))/dz &\n\t+ dp(i,j,k)*(w(i,j,k)-w(i,j,k-1))/dz + dn(i,j,k)*(w(i,j,k+1)-w(i,j,k))/dz) * 0.5\n\n\n\twint(i,j,k) = dwdx(i,j,k) + dwdy(i,j,k) + dwdz(i,j,k)\n\n\n\tenddo\n\tenddo\n\tenddo\n\n\telse\n\n\twrite(*,*) \"n\u00e3o possui esquema para o antissim\u00e9trico\"\n\tSTOP\n\n\tendif\n\n\n!==================================================================================================================\nEND SUBROUTINE antissim\n", "meta": {"hexsha": "1f58d5afd3e49df649874d79224d875f1efaf687", "size": 16655, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "SuLi_ic/7_advectivo.f90", "max_stars_repo_name": "pemiguell/SuLi", "max_stars_repo_head_hexsha": "8d9feb8f89bc44e2f870fb68023ef3b90e5ecfa6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "SuLi_ic/7_advectivo.f90", "max_issues_repo_name": "pemiguell/SuLi", "max_issues_repo_head_hexsha": "8d9feb8f89bc44e2f870fb68023ef3b90e5ecfa6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SuLi_ic/7_advectivo.f90", "max_forks_repo_name": "pemiguell/SuLi", "max_forks_repo_head_hexsha": "8d9feb8f89bc44e2f870fb68023ef3b90e5ecfa6", "max_forks_repo_licenses": ["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.4663608563, "max_line_length": 117, "alphanum_fraction": 0.481717202, "num_tokens": 7851, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896758909756, "lm_q2_score": 0.7185943925708562, "lm_q1q2_score": 0.6616742978323912}} {"text": " double complex function pvfndd(n,x,iep)\nC----Implementation of DD Eq. 4.11\n implicit none\n include 'TRonshellcutoff.f'\n integer j,n,infty\n double complex xm1,x,cln,cone\n double precision iep\n parameter(cone=(1d0,0d0),infty=16) ! number of terms in sum\n\n xm1=x-cone\n if (abs(x) .lt. 10d0) then\n if (abs(x-cone) .lt. onshellcutoff) then\n pvfndd=0d0\n else\n pvfndd=(cone-x**(n+1))*(cln(xm1,iep)-cln(x,iep))\n endif\n do j=0,n\n pvfndd=pvfndd-x**(n-j)/dfloat(j+1)\n enddo\n else\n pvfndd=cln(cone-cone/x,iep)\n do j=n+1,n+infty\n pvfndd=pvfndd+x**(n-j)/dfloat(j+1)\n enddo\n endif\n\n return\n end\n", "meta": {"hexsha": "bee6609b49bc7125c1be9729e15755a76cb6af06", "size": 738, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "MCFM-JHUGen/TensorReduction/pv/pvfndd.f", "max_stars_repo_name": "tmartini/JHUGen", "max_stars_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-06-08T13:09:28.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-04T19:59:36.000Z", "max_issues_repo_path": "MCFM-JHUGen/TensorReduction/pv/pvfndd.f", "max_issues_repo_name": "tmartini/JHUGen", "max_issues_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 64, "max_issues_repo_issues_event_min_datetime": "2015-06-24T15:08:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-25T04:59:32.000Z", "max_forks_repo_path": "MCFM-JHUGen/TensorReduction/pv/pvfndd.f", "max_forks_repo_name": "tmartini/JHUGen", "max_forks_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2015-05-04T22:15:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-06T10:04:40.000Z", "avg_line_length": 25.4482758621, "max_line_length": 65, "alphanum_fraction": 0.5447154472, "num_tokens": 271, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436482, "lm_q2_score": 0.7185943925708562, "lm_q1q2_score": 0.6616742947084261}} {"text": "program tmod\n\n! This is the test progrm for the F-90 based MP translation modules.\n\n! David H. Bailey 2004-07-12\n\nuse mpmodule\nimplicit type (mp_real) (a-h, o-z)\ntype (mp_integer) ia, ib, ic\ntype (mp_complex) c, d, e\nparameter (n = 25)\ndimension a(n), b(n)\n\ncall mpinit (1000)\n\n! Character-to-MP assignment, generic MPREAL function, pi and e.\n\nx = '1.234567890 1234567890 1234567890 D-100'\nee = exp (mpreal (1.d0))\ncall mpwrite (6, x, mppic, ee)\ns = 0.d0\n\n! Loop with subscripted MP variables.\n\ndo i = 1, n\n a(i) = 2 * i + 1\n b(i) = 2.d0 * a(i) * (a(i) + 1.d0)\n s = s + b(i) ** 2\nenddo\ncall mpwrite (6, s)\n\n! Expression with mixed MPI and MPR entities.\n\nia = s\nib = 262144\ns = (s + 327.25d0) * mod (ia, 4 * ib)\ncall mpwrite (6, s)\n\n! A complex square root reference.\n\ne = sqrt (mpcmpl (2.d0 * s, s))\ncall mpwrite (6, e)\n\n! External and intrinsic MP function references in expressions.\n\ns = dot (n, a, b)\nt = 2.d0 * sqrt (s) ** 2\ncall mpwrite (6, s, t)\n\ns = s / 1048576.d0\nt = s + 2.d0 * log (s)\nx = 3 + nint (t) * 5\ncall mpwrite (6, s, t, x)\n\n! A deeply nested expression with function references.\n\nx = (s + (2 * (s - 5) + 3 * (t - 5))) * exp (cos (log (s)))\ncall mpwrite (6, x)\n\n! A special MP subroutine call (computes both cos and sin of S).\n\ncall mpcssnf (s, x, y)\nt = 1.d0 - (x ** 2 + y ** 2)\n\n! IF-THEN-ELSE construct involving MP variables.\n\nif (abs (t) .lt. mpeps) then\n call mpwrite (6, t)\nelse\n call mpwrite (6, mpeps)\nendif\n\nstop\nend\n\nfunction dot (n, a, b)\n\n! MP function subprogram.\n\nuse mpmodule\ntype (mp_real) a(n), b(n), dot, s\n\ns = 0.d0\n\ndo i = 1, n\n s = s + a(i) * b(i)\nenddo\n\ndot = s\nreturn\nend\n", "meta": {"hexsha": "12baece51714fd3d0493c66a849b4d0a2f0ea163", "size": 1642, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/mpfun/tmpmod90.f", "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/mpfun/tmpmod90.f", "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/mpfun/tmpmod90.f", "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": 17.847826087, "max_line_length": 69, "alphanum_fraction": 0.6071863581, "num_tokens": 651, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339837155239, "lm_q2_score": 0.787931190663057, "lm_q1q2_score": 0.6616525976292048}} {"text": "!!!! Chuong trinh tinh standard deviation\n\n PROGRAM standard_deviation\n IMPLICIT NONE\n\n INTEGER (KIND=8),PARAMETER::N=32768\n INTEGER (KIND=8):: i,j,ia,ib\n REAL (KIND=8):: Sa_av,dev_a,Sb_av,dev_b,pi\n\n REAL (KIND=8),DIMENSION(N) :: Ks,S,Sa,Sb\n\n!!!=======================================================================================\n!!!======================================================================================= \n\n pi=acos(-1.)\n\n OPEN(unit=11,file='phi_equi.dat')\n OPEN(unit=12,file='phi_av.txt')\n\n\n S(:)=0. ; Sa(:)=0. ; Sb(:)=0.\n\n!!! Doc gia tri\n ia=0 ; ib=0 \n DO i=1,N\n READ(11,*)j,Ks(j),S(j)\n\n S(i)=S(i)-int(S(i)/2./pi)*2.*pi\n \n IF (S(i)<0.) THEN\n S(i)=S(i)+2.*pi\n END IF\n\n IF (Ks(j)>0.) THEN\n ia=ia+1\n Sa(ia)=S(j)\n ELSE\n ib=ib+1\n Sb(ib)=S(j)\n END IF\n END DO\n\n!!! Tinh gia tri trung binh\n Sa_av=0. \n DO i=1,ia\n Sa_av=Sa_av+Sa(i)\n END DO\n Sa_av=Sa_av/ia\n\n Sb_av=0. \n DO i=1,ib\n Sb_av=Sb_av+Sb(i)\n END DO\n Sb_av=Sb_av/ib\n\n!!! Tinh standard deviation\n dev_a=0. \n DO i=1,ia\n dev_a=dev_a+(Sa(i)-Sa_av)**2.\n END DO\n dev_a=dev_a/ia\n\n dev_b=0. \n DO i=1,ib\n dev_b=dev_b+(Sb(i)-Sb_av)**2.\n END DO\n dev_b=dev_b/ib\n\n WRITE(12,*)N,ia,ib\n WRITE(12,*)Sa_av,dev_a,Sb_av,dev_b\n\n CLOSE(11)\n CLOSE(12)\n \n END PROGRAM standard_deviation\n\n", "meta": {"hexsha": "b6b41b0121fcdb0be2223e707e0c922212f0a319", "size": 1412, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "figure_data_pub/23Q005_L16_p80_Fig2g/0mean_phase.f90", "max_stars_repo_name": "danhtaihoang/conformist-contrarian", "max_stars_repo_head_hexsha": "56772c06543cbecc858f3265b7d07a8fa9d160d7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "figure_data_pub/23Q005_L16_p80_Fig2g/0mean_phase.f90", "max_issues_repo_name": "danhtaihoang/conformist-contrarian", "max_issues_repo_head_hexsha": "56772c06543cbecc858f3265b7d07a8fa9d160d7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "figure_data_pub/23Q005_L16_p80_Fig2g/0mean_phase.f90", "max_forks_repo_name": "danhtaihoang/conformist-contrarian", "max_forks_repo_head_hexsha": "56772c06543cbecc858f3265b7d07a8fa9d160d7", "max_forks_repo_licenses": ["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.3376623377, "max_line_length": 91, "alphanum_fraction": 0.459631728, "num_tokens": 514, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.7879312056025699, "lm_q1q2_score": 0.661652597533417}} {"text": "program demo_math_all_close\n use forlab_math, only: all_close\n use stdlib_error, only: check\n real :: x(2) = [1, 2], random(4, 4)\n complex :: z(4, 4)\n \n call check(all_close(x, [2.0, 2.0], rel_tol=1.0e-6, abs_tol=1.0e-3), &\n msg=\"all_close(x, [2.0, 2.0]) failed.\", warn=.true.)\n !! all_close(x, [2.0, 2.0]) failed.\n call random_number(random(4, 4))\n z = 1.0\n print *, all_close(z+1.0e-11*random, z) !! T\n \nend program demo_math_all_close", "meta": {"hexsha": "b7ea336b6ae21d0f59e1d94a0ec34711e66ec01c", "size": 503, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/math/demo_math_all_close.f90", "max_stars_repo_name": "zoziha/forlab_z", "max_stars_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2021-08-31T15:23:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T02:44:46.000Z", "max_issues_repo_path": "example/math/demo_math_all_close.f90", "max_issues_repo_name": "zoziha/forlab_z", "max_issues_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-08-22T11:47:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-31T00:57:16.000Z", "max_forks_repo_path": "example/math/demo_math_all_close.f90", "max_forks_repo_name": "zoziha/forlab_z", "max_forks_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-07-16T03:16:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-31T13:09:42.000Z", "avg_line_length": 35.9285714286, "max_line_length": 74, "alphanum_fraction": 0.564612326, "num_tokens": 187, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.828938825225204, "lm_q2_score": 0.7981867825403176, "lm_q1q2_score": 0.6616480138292563}} {"text": "program test\nuse easy_scalapack\nimplicit none\ninteger, parameter :: p = 2, q = 2, m = 9, n = 9, mb = 2, nb = 2\ntype(process_grid) :: pc\ntype(dense_matrix) :: dm, b\ntype(subarray) :: sa, sb\ninteger :: i, j, info\nreal :: rnd\n\npc = process_grid(p,q)\ndm = dense_matrix( m, n, mb, nb, pc )\nb = dense_matrix( m, 1, mb, nb, pc )\n\n!call dm%print_mapping()\n\ndo i = 1, dm%mg\n do j = 1, dm%ng\n call random_number(rnd)\n call dm%set( i, j, rnd )\n end do\n call b%set( i, 1, 1.0 )\nend do\n\n!call dm%print_matrix(6)\n\nsa = subarray( dm )\n\n! LU factorization\ncall psgetrf( sa%m, sa%n, sa%la, sa%ia, sa%ja, sa%desc, sa%ipiv, info )\nif( info /= 0 ) call pc%stop_all(\"LU factorization unsuccessful\")\n\nsb = subarray(b)\ncall psgetrs( 'N', sa%m, 1, sa%la, sa%ia, sa%ja, sa%desc, sa%ipiv, sb%la, sb%ia, sb%ja, sb%desc, info )\n\n!call psgetri( sa%n, sa%la, sa%ia, sa%ja, sa%desc, sa%ipiv, sa%work, sa%lwork, sa%iwork, sa%liwork, info ) still problematic!\n\ncall b%print_matrix(6)\n\ncall pc%destroy()\ncall pc%stop_all()\n\nend program\n\n", "meta": {"hexsha": "9186af4b81da34ff399a8c86d7397d38c558f211", "size": 1055, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "scalapack/main.f08", "max_stars_repo_name": "amirhajibabaei/fortran-examples", "max_stars_repo_head_hexsha": "bddc74d5dcd41e725c7bbcfaf856448153ae1464", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "scalapack/main.f08", "max_issues_repo_name": "amirhajibabaei/fortran-examples", "max_issues_repo_head_hexsha": "bddc74d5dcd41e725c7bbcfaf856448153ae1464", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "scalapack/main.f08", "max_forks_repo_name": "amirhajibabaei/fortran-examples", "max_forks_repo_head_hexsha": "bddc74d5dcd41e725c7bbcfaf856448153ae1464", "max_forks_repo_licenses": ["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.4444444444, "max_line_length": 125, "alphanum_fraction": 0.6123222749, "num_tokens": 402, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436395, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6616381964970373}} {"text": "C * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC * *\nC * copyright (c) 1999 by UCAR *\nC * *\nC * UNIVERSITY CORPORATION for ATMOSPHERIC RESEARCH *\nC * *\nC * all rights reserved *\nC * *\nC * FISHPACK version 4.1 *\nC * *\nC * A PACKAGE OF FORTRAN SUBPROGRAMS FOR THE SOLUTION OF *\nC * *\nC * SEPARABLE ELLIPTIC PARTIAL DIFFERENTIAL EQUATIONS *\nC * *\nC * BY *\nC * *\nC * JOHN ADAMS, PAUL SWARZTRAUBER AND ROLAND SWEET *\nC * *\nC * OF *\nC * *\nC * THE NATIONAL CENTER FOR ATMOSPHERIC RESEARCH *\nC * *\nC * BOULDER, COLORADO (80307) U.S.A. *\nC * *\nC * WHICH IS SPONSORED BY *\nC * *\nC * THE NATIONAL SCIENCE FOUNDATION *\nC * *\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC\nC\nC\nC EXAMPLE SHOWING THE USE OF SEPX4 TO SOLVE THE ELLIPTIC PDE\nC (X+1)**2*UXX+2*(X+1)*UX+UYY-X*U=G(X,Y) ON THE REGION\nC 0.LE.X.LE.1, 0.LE.Y.LE.1 WITH SPECIFIED BOUNDARY CONDITIONS\nC AT Y=0,1 AND MIXED BOUNDARY CONDITIONS OF THE FORM\nC UX(0,Y)+U(0,Y), UX(1,Y)+U(1,Y) AT X=0,1.\nC THE APPROXIMATION IS GENERATED ON A UNIFORM 33 BY 33 GRID.\nC THE EXACT SOLUTION U(X,Y)=(X*Y)**3+1 IS USED TO SET THE\nC RIGHT HAND SIDE, BOUNDARY CONDITIONS, AND COMPUTE SECOND AND\nC FOURTH ORDER DISCRETIZATION ERROR\nC THE EXACT WORK SPACE LENGTH REQUIRED IS 1005 WORDS. THIS\nC WAS DETERMINED BY A PREVIOUS CALL TO SEPX4 AND PRINT OUT OF\nC W(1).\nC\n DIMENSION USOL(33,33),GRHS(33,33),BDA(33) ,BDB(33) ,\n 1 W(1024)\n EXTERNAL COFX4\nC\nC DEFINE ARITHMETIC FUNCTIONS GIVING EXACT SOLUTION\nC\n UE(S,T)=(S*T)**3+1.0\n UXE(S,T)=3.0*S**2*T**3\n UXXE(S,T)=6.0*S*T**3\n UYE(S,T)=3.0*S**3*T**2\n UYYE(S,T)=6.0*S**3*T\nC\nC SET LIMITS ON REGION\nC\n A = 0.0\n B = 1.0\n C = 0.0\n D = 1.0\nC\nC SET GRID SIZE\nC\n M = 32\n N = 32\n DLX = (B-A)/FLOAT(M)\n DLY = (D-C)/FLOAT(N)\n NX = M+1\n NY = N+1\n DO 102 I=1,NX\n X = A+FLOAT(I-1)*DLX\nC\nC SET SPECIFIED BOUNDARY CONDITIONS AT Y=C,D\nC\n USOL(I,1) = UE(X,C)\n USOL(I,NY) = UE(X,D)\n CALL COFX4 (X,AF,BF,CF)\n DO 101 J=1,NY\n Y = C+FLOAT(J-1)*DLY\nC\nC SET RIGHT HAND SIDE\nC\n GRHS(I,J) = AF*UXXE(X,Y)+BF*UXE(X,Y)+CF*UE(X,Y)+UYYE(X,Y)\n 101 CONTINUE\n 102 CONTINUE\nC\nC SET MIXED BOUNDARY CONDITIONS AT X=A,B\nC\n ALPHA = 1.0\n BETA = 1.0\n DO 103 J=1,NY\n Y = C+FLOAT(J-1)*DLY\n BDA(J) = UXE(A,Y)+ALPHA*UE(A,Y)\n BDB(J) = UXE(B,Y)+BETA*UE(B,Y)\n 103 CONTINUE\nC\nC SET BOUNDARY SWITHCES\nC\n MBDCND = 3\n NBDCND = 1\nC\nC SET FIRST DIMENSION OF USOL,GRHS AND WORK SPACE LENGTH\nC\n IDMN = 33\n W(1) = 1024.\nC\nC OBTAIN SECOND ORDER APPROXIMATION\nC\n IORDER = 2\n CALL SEPX4 (IORDER,A,B,M,MBDCND,BDA,ALPHA,BDB,BETA,C,D,N,NBDCND,\n 1 DUM,DUM,COFX4,GRHS,USOL,IDMN,W,PERTRB,IERROR)\nC\nC COMPUTE SECOND ORDER DISCRETIZATION ERROR (RELATIVE)\nC ALSO RESET SPECIFIED BOUNDARIES AND RIGHT HAND SIDE.\nC\n ERR = 0.0\n DO 105 I=1,NX\n X = A+FLOAT(I-1)*DLX\n USOL(I,1) = UE(X,C)\n USOL(I,NY) = UE(X,D)\n CALL COFX4 (X,AF,BF,CF)\n DO 104 J=1,NY\n Y = C+FLOAT(J-1)*DLY\n ERR = AMAX1(ERR,ABS((USOL(I,J)-UE(X,Y))/UE(X,Y)))\n GRHS(I,J) = AF*UXXE(X,Y)+BF*UXE(X,Y)+CF*UE(X,Y)+UYYE(X,Y)\n 104 CONTINUE\n 105 CONTINUE\n ERR2=ERR\nC\nC OBTAIN FOURTH ORDER APPROXIMATION\nC\n IORDER = 4\n CALL SEPX4 (IORDER,A,B,M,MBDCND,BDA,ALPHA,BDB,BETA,C,D,N,NBDCND,\n 1 DUM,DUM,COFX4,GRHS,USOL,IDMN,W,PERTRB,IERROR)\nC\nC COMPUTE FOURTH ORDER DISCRETIZATION ERROR (RELATIVE)\nC\n ERR = 0.0\n DO 107 J=1,NY\n Y = C+FLOAT(J-1)*DLY\n DO 106 I=1,NX\n X = A+FLOAT(I-1)*DLX\n ERR = AMAX1(ERR,ABS((USOL(I,J)-UE(X,Y))/UE(X,Y)))\n 106 CONTINUE\n 107 CONTINUE\n ERR4=ERR\n IW = INT(W(1)+0.5)\n PRINT 1001,IERROR,ERR2,ERR4,IW\n STOP IERROR\n\n 1001 FORMAT(1H1,20X,25HSUBROUTINE SEPX4 EXAMPLE ///\n 120X,46HTHE OUTPUT FROM THE NCAR CONTROL DATA 7600 WAS //\n 220X,10HIERROR = 0 /\n 320X,48HSECOND ORDER DISCRETIZATION ERROR = 1.5985E-04 /\n 420X,48HFOURTH ORDER DISCRETIZATION ERROR = 1.85749E-06 /\n 520X,33HREQUIRED LENGTH OF W ARRAY = 1024 //\n 620X, 32HTHE OUTPUT FROM YOUR COMPUTER IS //\n 720X, 8HIERROR = I2 /\n 820X,36HSECOND ORDER DISCRETIZATION ERROR = E12.5 /\n 920X,36HFOURTH ORDER DISCRETIZATION ERROR = E12.5 /\n 920X,29HREQUIRED LENGTH OF W ARRAY = I5)\nC\n END\n SUBROUTINE COFX4(X,AF,BF,CF)\nC\nC SET COEFFICIENTS IN THE X-DIRECTION.\nC\n AF = (X+1.)**2\n BF = 2.0*(X+1.)\n CF = -X\n RETURN\n END\n", "meta": {"hexsha": "41249fd4216da339fd5f3a191fbd4012276296a0", "size": 6195, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "test/tsepx4.f", "max_stars_repo_name": "dmey/fishpack-cmake", "max_stars_repo_head_hexsha": "3db092535f4070a875e8f22045cec3cd1d3b6d1c", "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": "test/tsepx4.f", "max_issues_repo_name": "dmey/fishpack-cmake", "max_issues_repo_head_hexsha": "3db092535f4070a875e8f22045cec3cd1d3b6d1c", "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": "test/tsepx4.f", "max_forks_repo_name": "dmey/fishpack-cmake", "max_forks_repo_head_hexsha": "3db092535f4070a875e8f22045cec3cd1d3b6d1c", "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": 35.1988636364, "max_line_length": 71, "alphanum_fraction": 0.4263115416, "num_tokens": 1960, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.74316801430083, "lm_q1q2_score": 0.6616381964970373}} {"text": "FUNCTION gammq(a,x)\nREAL a,gammq,x\n!CU USES gcf,gser\nREAL gammcf,gamser,gln\nif(x.lt.0..or.a.le.0.)pause 'bad arguments in gammq'\nif(x.lt.a+1.)then\n call gser(gamser,a,x,gln)\n gammq=1.-gamser\nelse\n call gcf(gammcf,a,x,gln)\n gammq=gammcf\nendif\nreturn\nEND\n", "meta": {"hexsha": "06df1f315aa1a0766accbd65cd9c5fb581233196", "size": 260, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tchi/gammq.f90", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tchi/gammq.f90", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tchi/gammq.f90", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.3333333333, "max_line_length": 52, "alphanum_fraction": 0.7038461538, "num_tokens": 109, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8902942261220291, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6616381871062984}} {"text": " SUBROUTINE slXYXY (X1,Y1,COEFFS,X2,Y2)\n*+\n* - - - - - -\n* X Y X Y\n* - - - - - -\n*\n* Transform one [X,Y] into another using a linear model of the type\n* produced by the slFTXY routine.\n*\n* Given:\n* X1 d x-coordinate\n* Y1 d y-coordinate\n* COEFFS d(6) transformation coefficients (see note)\n*\n* Returned:\n* X2 d x-coordinate\n* Y2 d y-coordinate\n*\n* The model relates two sets of [X,Y] coordinates as follows.\n* Naming the elements of COEFFS:\n*\n* COEFFS(1) = A\n* COEFFS(2) = B\n* COEFFS(3) = C\n* COEFFS(4) = D\n* COEFFS(5) = E\n* COEFFS(6) = F\n*\n* the present routine performs the transformation:\n*\n* X2 = A + B*X1 + C*Y1\n* Y2 = D + E*X1 + F*Y1\n*\n* See also slFTXY, slPXY, slINVF, slDCMF\n*\n* P.T.Wallace Starlink 5 December 1994\n*\n* Copyright (C) 1995 Rutherford Appleton Laboratory\n*\n* License:\n* This program is free software; you can redistribute it and/or modify\n* it under the terms of the GNU General Public License as published by\n* the Free Software Foundation; either version 2 of the License, or\n* (at your option) any later version.\n*\n* This program is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU General Public License for more details.\n*\n* You should have received a copy of the GNU General Public License\n* along with this program (see SLA_CONDITIONS); if not, write to the\n* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,\n* Boston, MA 02110-1301 USA\n*\n* Copyright (C) 1995 Association of Universities for Research in Astronomy Inc.\n*-\n\n IMPLICIT NONE\n\n DOUBLE PRECISION X1,Y1,COEFFS(6),X2,Y2\n\n\n X2=COEFFS(1)+COEFFS(2)*X1+COEFFS(3)*Y1\n Y2=COEFFS(4)+COEFFS(5)*X1+COEFFS(6)*Y1\n\n END\n", "meta": {"hexsha": "b9c770a37775d0a9cf90249d6e4f9d0d94cefb94", "size": 1953, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iraf.v2161/math/slalib/xy2xy.f", "max_stars_repo_name": "ysBach/irafdocgen", "max_stars_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:19:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T16:48:42.000Z", "max_issues_repo_path": "math/slalib/xy2xy.f", "max_issues_repo_name": "kirxkirx/iraf", "max_issues_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-30T13:48:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-02T19:40:25.000Z", "max_forks_repo_path": "math/slalib/xy2xy.f", "max_forks_repo_name": "kirxkirx/iraf", "max_forks_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.7205882353, "max_line_length": 80, "alphanum_fraction": 0.6308243728, "num_tokens": 626, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6616381777155594}} {"text": "\tFUNCTION PR_HGFS ( hgft )\nC************************************************************************\nC* PR_HGFS\t\t\t\t\t\t\t\t*\t\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes HGML, height in miles, from HGFT. The \t*\nC* following equation is used:\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* HGML = HGFT / 5280. \t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PR_HGFS ( HGFT )\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*\tHGFT\t\tREAL\t \tHeight in feet \t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPR_HGFS\t\tREAL\t\tHeight in statute miles \t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* S. Schotz \t10/89\tOriginal source\t\t\t\t*\nC************************************************************************\n INCLUDE 'GEMPRM.PRM'\nC\n\tREAL ft2ml\n\tPARAMETER (ft2ml = 1.0 / 5280.0)\nC\n INCLUDE 'ERMISS.FNC'\nC------------------------------------------------------------------------\nC*\tCheck for missing values.\nC\t\n\tIF ( ERMISS ( hgft ) ) THEN\n\t PR_HGFS = RMISSD\n\t ELSE\n\t PR_HGFS = hgft * ft2ml\n\tEND IF\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "65be8bd599ef270f143e83fb7fec14121979a365", "size": 1010, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/pr/prhgfs.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/prhgfs.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/prhgfs.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": 26.5789473684, "max_line_length": 73, "alphanum_fraction": 0.400990099, "num_tokens": 309, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942173896132, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.661638175552342}} {"text": "!> Orchid -- 2D/3D Euler/MagnetoHydroDynamics solver.\n!> Copyright (C) Butakov Oleg 2019.\n\nModule orchid_solver_grid_gauss_const\nImplicit None\nContains\n!########################################################################################################\n!########################################################################################################\n!########################################################################################################\nFunction mhd_grid_gauss_point(Npoints, k) Result(x)\n !> Points of the Gauss quadrature.\n !> {{{\n Integer, Intent(In) :: Npoints\n Integer, Intent(In) :: k\n Real(8) :: x\n !> }}}\n Real(8), Dimension(1:1), Parameter :: x1 = [ +0.000000000D0 ]\n Real(8), Dimension(1:2), Parameter :: x2 = [ -0.577350269D0, +0.577350269D0 ]\n Real(8), Dimension(1:3), Parameter :: x3 = [ -0.774596669D0, +0.000000000D0, +0.774596669D0 ]\n Real(8), Dimension(1:4), Parameter :: x4 = [ -0.861136312D0, -0.339981044D0, +0.339981044D0, &\n +0.861136312D0 ]\n Real(8), Dimension(1:5), Parameter :: x5 = [ -0.906179846D0, -0.538469310D0, +0.000000000D0, &\n +0.538469310D0, +0.906179846D0 ]\n Select Case ( Npoints )\n Case ( 1 )\n x = x1(k)\n Case ( 2 )\n x = x2(k)\n Case ( 3 )\n x = x3(k)\n Case ( 4 )\n x = x4(k)\n Case ( 5 )\n x = x5(k)\n Case Default\n Write (0,*) 'Too many points for Gauss quadratures.'\n Error Stop -1\n End Select\nEnd Function mhd_grid_gauss_point\n!########################################################################################################\n!########################################################################################################\n!########################################################################################################\nFunction mhd_grid_gauss_weight(Npoints, k) Result(w)\n !> Weights of the Gauss quadrature.\n !> {{{\n Integer, Intent(In) :: Npoints\n Integer, Intent(In) :: k\n Real(8) :: w\n !> }}}\n Real(8), Dimension(1:1), Parameter :: w1 = [ +1.000000000D0 ]\n Real(8), Dimension(1:2), Parameter :: w2 = [ +0.500000000D0, +0.50000000D0 ]\n Real(8), Dimension(1:3), Parameter :: w3 = [ +0.277777778D0, +0.444444444D0, +0.277777778D0 ]\n Real(8), Dimension(1:4), Parameter :: w4 = [ +0.173927423D0, +0.326072577D0, +0.326072577D0, &\n +0.173927423D0 ]\n Real(8), Dimension(1:5), Parameter :: w5 = [ +0.118463443D0, +0.239314335D0, +0.284444444D0, &\n +0.239314335D0, +0.118463443D0 ]\n Select Case ( Npoints )\n Case ( 1 )\n w = w1(k)\n Case ( 2 )\n w = w2(k)\n Case ( 3 )\n w = w3(k)\n Case ( 4 )\n w = w4(k)\n Case ( 5 )\n w = w5(k)\n Case Default\n Write (0,*) 'Too many points for Gauss quadratures.'\n Error Stop -1\n End Select\nEnd Function mhd_grid_gauss_weight\n!########################################################################################################\n!########################################################################################################\n!########################################################################################################\nEnd Module orchid_solver_grid_gauss_const\n\n\n \nModule orchid_solver_grid_gauss\nUse orchid_solver_params\nUse orchid_solver_grid\nUse orchid_solver_grid_gauss_const\nImplicit None\nType :: MhdGridGaussNode\n Real(8) :: x, y, z, w\n Contains\nEnd Type MhdGridGaussNode\nType :: MhdGridGaussCell\n Integer :: nnode, nnode_end\n Contains\nEnd Type MhdGridGaussCell\nType :: MhdGridGaussFace\n Integer :: nnode, nnode_end\n Contains\nEnd Type MhdGridGaussFace\nType, Extends(MhdGrid) :: MhdGridGauss\n Integer :: ncell_nodes_min, ncell_nodes_max\n Integer :: nface_nodes_min, nface_nodes_max\n Type(MhdGridGaussCell), Dimension(:), Allocatable :: gcells\n Type(MhdGridGaussFace), Dimension(:), Allocatable :: gfaces\n Type(MhdGridGaussNode), Dimension(:), Allocatable :: cell_nodes, face_nodes\n Contains\n Procedure, Public, Non_Overridable :: init_gauss => mhd_grid_gauss_init\n Procedure, Public, Non_Overridable :: init_gauss1D => mhd_grid_gauss_init1D\n Procedure, Public, Non_Overridable :: init_gauss_dummy => mhd_grid_gauss_init_dummy\nEnd Type MhdGridGauss\nPrivate :: mhd_grid_gauss_init1D, &\n mhd_grid_gauss_init_dummy\nContains\n!########################################################################################################\n!########################################################################################################\n!########################################################################################################\nSubroutine mhd_grid_gauss_init(This, Npoints)\n !> Initialize a Gauss grid.\n !> {{{\n Class(MhdGridGauss), Intent(InOut) :: This\n Integer, Intent(In), Optional :: Npoints\n !> }}}\n If ( Present(Npoints) ) Then\n Select Case ( This%ndims )\n Case ( 1 )\n Call This%init_gauss1D(Npoints)\n !Case ( 2 )\n ! Call This%init_gauss2D(Npoints)\n !Case ( 3 )\n ! Call This%init_gauss3D(Npoints)\n Case Default\n Write (0,*) 'Invalid amount of the grid dimensions. ', &\n 'Was grid initialized?'\n Error Stop -1\n End Select\n Else\n Call This%init_gauss_dummy()\n End If\nEnd Subroutine mhd_grid_gauss_init\n!########################################################################################################\n!########################################################################################################\n!########################################################################################################\nSubroutine mhd_grid_gauss_init1D(This, Npoints)\n !> Initialize a 1D Gauss grid.\n !> {{{\n Class(MhdGridGauss), Intent(InOut) :: This\n Integer, Intent(In) :: Npoints\n !> }}}\n Integer :: n, k, kk\n Real(8) :: h, x\n !>-------------------------------------------------------------------------------\n !> Allocate the Gauss Grid.\n This%ncell_nodes_min = This%ncells_min\n This%ncell_nodes_max = This%ncells_max*Npoints\n This%nface_nodes_min = This%nfaces_min\n This%nface_nodes_max = This%nfaces_max\n Allocate(This%gcells(This%ncells_min:This%ncells_max))\n Allocate(This%gfaces(This%nfaces_min:This%nfaces_max))\n Allocate(This%cell_nodes(This%ncell_nodes_min:This%ncell_nodes_max))\n Allocate(This%face_nodes(This%nface_nodes_min:This%nface_nodes_max))\n !>-------------------------------------------------------------------------------\n\n !>-------------------------------------------------------------------------------\n !> Initialize Cells and CellNodes.\n !$OMP Parallel Do Private(k, kk, h, x)\n Do n = This%ncells_min, This%ncells_max\n h = This%cells(n)%Vcell\n x = This%nodes(This%cell2node(This%cells(n)%nnode))%x\n This%gcells(n)%nnode = Npoints*( n - 1 ) + 1\n This%gcells(n)%nnode_end = Npoints*n\n Do k = This%gcells(n)%nnode, This%gcells(n)%nnode_end\n kk = k - This%gcells(n)%nnode + 1\n This%cell_nodes(k)%w = mhd_grid_gauss_weight(Npoints, kk)\n This%cell_nodes(k)%x = mhd_grid_gauss_point(Npoints, kk)\n This%cell_nodes(k)%x = x + 0.5D0*h*( This%cell_nodes(k)%x + 1.0D0 )\n This%cell_nodes(k)%y = 0.0D0\n This%cell_nodes(k)%z = 0.0D0\n End Do\n End Do\n !$OMP End Parallel Do\n !> Initialize Faces and FaceNodes.\n !$OMP Parallel Do\n Do n = This%nfaces_min, This%nfaces_max\n This%gfaces(n)%nnode = n\n This%gfaces(n)%nnode_end = n\n This%face_nodes(n)%x = This%faces(n)%x\n This%face_nodes(n)%y = This%faces(n)%y\n This%face_nodes(n)%z = This%faces(n)%z\n This%face_nodes(n)%w = 1.0D0\n End Do\n !$OMP End Parallel Do\n !>-------------------------------------------------------------------------------\nEnd Subroutine mhd_grid_gauss_init1D\n!########################################################################################################\n!########################################################################################################\n!########################################################################################################\nSubroutine mhd_grid_gauss_init_dummy(This)\n !> Initialize a dummy Gauss grid (for first-order integration).\n !> {{{\n Class(MhdGridGauss), Intent(InOut) :: This\n !> }}}\n Integer :: n\n !>-------------------------------------------------------------------------------\n !> Allocate the Gauss Grid.\n This%ncell_nodes_min = This%ncells_min\n This%ncell_nodes_max = This%ncells_max\n This%nface_nodes_min = This%nfaces_min\n This%nface_nodes_max = This%nfaces_max\n Allocate(This%gcells(This%ncells_min:This%ncells_max))\n Allocate(This%gfaces(This%nfaces_min:This%nfaces_max))\n Allocate(This%cell_nodes(This%ncell_nodes_min:This%ncell_nodes_max))\n Allocate(This%face_nodes(This%nface_nodes_min:This%nface_nodes_max))\n !>-------------------------------------------------------------------------------\n \n !>-------------------------------------------------------------------------------\n !> Initialize Cells and CellNodes.\n !$OMP Parallel Do\n Do n = This%ncells_min, This%ncells_max\n This%gcells(n)%nnode = n\n This%gcells(n)%nnode_end = n\n This%cell_nodes(n)%x = This%cells(n)%x\n This%cell_nodes(n)%y = This%cells(n)%y\n This%cell_nodes(n)%z = This%cells(n)%z\n This%cell_nodes(n)%w = 1.0D0\n End Do\n !$OMP End Parallel Do\n !> Initialize Faces and FaceNodes.\n !$OMP Parallel Do\n Do n = This%nfaces_min, This%nfaces_max\n This%gfaces(n)%nnode = n\n This%gfaces(n)%nnode_end = n\n This%face_nodes(n)%x = This%faces(n)%x\n This%face_nodes(n)%y = This%faces(n)%y\n This%face_nodes(n)%z = This%faces(n)%z\n This%face_nodes(n)%w = 1.0D0\n End Do\n !$OMP End Parallel Do\n !>-------------------------------------------------------------------------------\nEnd Subroutine mhd_grid_gauss_init_dummy\n!########################################################################################################\n!########################################################################################################\n!########################################################################################################\nEnd Module orchid_solver_grid_gauss\n\n\n\n", "meta": {"hexsha": "55f895560e2cf25f5617a1ee8d76b7cc38f00c4d", "size": 10804, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "OrchidSolver/OrchidGridGauss.f90", "max_stars_repo_name": "Jhuighuy/OrchidSolver", "max_stars_repo_head_hexsha": "469776e641980225bf8ab9c77bfcde8f7c583cd8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-07-30T17:04:06.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-30T17:04:06.000Z", "max_issues_repo_path": "OrchidSolver/OrchidGridGauss.f90", "max_issues_repo_name": "Jhuighuy/OrchidSolver", "max_issues_repo_head_hexsha": "469776e641980225bf8ab9c77bfcde8f7c583cd8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "OrchidSolver/OrchidGridGauss.f90", "max_forks_repo_name": "Jhuighuy/OrchidSolver", "max_forks_repo_head_hexsha": "469776e641980225bf8ab9c77bfcde8f7c583cd8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.2786885246, "max_line_length": 105, "alphanum_fraction": 0.4494631618, "num_tokens": 2602, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.743167997235783, "lm_q1q2_score": 0.661638172651255}} {"text": "\nmodule gaussinte\n implicit none\n double precision, private, parameter :: pai = 4.0d0 * atan(1.0d0)\n private\n public gaussinte_w, gaussinte_fx, gaussinte_fv\n\ncontains\n\n! Description: Gauss quadrature for the following integral\n\n! | b\n! | f(x) dx\n! | a\n\n! gaussinte_w: make points and weights for n discrete points\n! n (in): the number of points. This is the size of both x and w.\n! x (out): x-axis points in the interval [-1, 1].\n! w (out): weights for the points.\n! eps (in): tolerance error.\n\n! gaussinte_fx: make x points for the interval [a,b]\n! n (in): the number of points.\n! x (in): the x points for interval [-1, 1].\n! a, b (in): lower and upper points for the integral\n! fx (out): x point for the interval [a, b]\n! return value: (b-a)/2\n\n! gaussinte_fv: compute the integral\n! n (in): the number of points.\n! w (in): weights for the x points in [-1,1]\n! c (in): (b-a)/2 ?\n! fv (in): function values at x points derived by gauss_inte_fx\n! return value: the interal value\n\n subroutine gaussinte_w(n, x, w, eps)\n integer, intent(in) :: n\n double precision, intent(out) :: x(1:n), w(1:n)\n double precision, intent(in) :: eps\n\n integer :: m, i, l\n double precision :: npai, tmp, dt\n double precision :: p0, p1, p2\n double precision :: q0, q1, q2\n\n select case (n)\n case (1)\n x(1) = 0.0d0\n w(1) = 2.0d0\n return\n case (2)\n x(1) = -sqrt(1.0d0/3.0d0)\n w(1) = 1.0d0\n x(2) = -x(1)\n w(2) = w(1)\n return\n case (3)\n x(1) = -sqrt(0.6d0)\n w(1) = 5.0d0/9.0d0\n x(2) = 0.0d0\n w(2) = 8.0d0/9.0d0\n x(3) = -x(1)\n w(3) = w(1)\n return\n end select\n\n m = n / 2\n npai = pai / (dble(n) + 0.5d0)\n do i = 1, m\n tmp = cos((i - 0.25d0) * npai)\n dt = tmp\n do while (abs(dt) > abs(tmp) * eps)\n p1 = tmp\n p2 = (3.0d0 * tmp**2 - 1.0d0) * 0.5d0\n q1 = 1.0d0\n q2 = 3.0d0 * tmp\n do l = 3, n\n p0 = p1\n p1 = p2\n p2 = ((l + l - 1) * tmp * p1 - (l-1) * p0) / l\n q0 = q1\n q1 = q2\n q2 = ((l + l - 1) * (tmp * q1 + p1) - (l-1) * q0) / l\n end do\n dt = p2 / q2\n tmp = tmp - dt\n end do\n x(i) = tmp\n w(i) = 2.0d0 / (n * p1 * q2)\n end do\n\n if (mod(n, 2) == 1) then\n tmp = dble(n)\n do i = 1, m\n tmp = tmp * (0.5d0 - i) / dble(i)\n end do\n x(m+1) = 0.0d0\n w(m+1) = 2.0d0 / tmp**2\n end if\n\n do i = 1, m\n x(n+1-i) = x(i)\n x(i) = -x(i) ! reverse order\n w(n+1-i) = w(i)\n end do\n end subroutine gaussinte_w\n\n function gaussinte_fx(n, x, a, b, fx) result(t1)\n integer, intent(in) :: n\n double precision, intent(in) :: x(1:n), a, b\n double precision, intent(out) :: fx(1:n)\n\n integer :: i\n double precision :: t1, t2\n\n t1 = (b - a)/2.0d0\n t2 = (b + a)/2.0d0\n do i = 1, n\n fx(i) = t1 * x(i) + t2\n end do\n end function gaussinte_fx\n\n function gaussinte_fv(n, w, c, fv) result(s)\n integer, intent(in) :: n\n double precision, intent(in) :: w(1:n), c, fv(1:n)\n\n integer :: i\n double precision :: s\n\n s = 0.0d0\n do i = 1, n\n s = s + w(i) * fv(i)\n end do\n s = s * c\n end function gaussinte_fv\n\nend module gaussinte\n", "meta": {"hexsha": "c741792fd7161aadc960fc93e3904bcb8bfc618e", "size": 3364, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "math/gaussinte_mod.f90", "max_stars_repo_name": "okamumu/Markov.core", "max_stars_repo_head_hexsha": "3de31b2f7e02da6a2da71183154bd7c6fac0752c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "math/gaussinte_mod.f90", "max_issues_repo_name": "okamumu/Markov.core", "max_issues_repo_head_hexsha": "3de31b2f7e02da6a2da71183154bd7c6fac0752c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "math/gaussinte_mod.f90", "max_forks_repo_name": "okamumu/Markov.core", "max_forks_repo_head_hexsha": "3de31b2f7e02da6a2da71183154bd7c6fac0752c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.3768115942, "max_line_length": 69, "alphanum_fraction": 0.4979191439, "num_tokens": 1309, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391624034103, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.661611517599115}} {"text": "! ==========================================================\n! satellites_nonlinear.f95\n! \n! This program calculates the control and state of a\n! fully actuated satellite using optimal control with\n! quadratic cost\n!\tI(u) = 1/2 * integ( x*Qx + u*Ru ) dt\n!\n! And constraints on control\n! \tui_min <= u_i <= ui_max, i=1,2,3.\n!\n! It uses the fully non-linear model\n!\tJw' = -w x Jw + u\n!\tq' = 1/2 * Omega(w) * q\n! \n! INPUT:\n! - \"input_file\": This file is created by the user.\n! It contains the simulation parameters as follows:\n! T_0: Initial time\n! T_1: Final time\n! j1 j2 j3: Moments of inertia\n! q1 q2 q3 q4 q5 q6 q7: Elemets of diagonal matrix q\n! r1 r2 r3: Elements of diagonal matrix R\n! omega_0(1) omega_0(2), omega_0(3): Initial ang. vel.\n! omega_1(1) omega_1(2), omega_1(3): Final ang. vel.\n! eul_0(1) eul_0(2) eul_0(3): Initial Euler angles\n! eul_1(1) eul_1(2) eul_1(3): Final Euler angles\n! m: Number of intervals in the discretization\n! u1min u2min u3min u1max u2max u3max: Control constraints\n! mask(1) ... mask(7): Natural/Essential bound. constraints\n! prec: Precission of the algorithm\n!\n! OUTPUT:\n! - \"results_control\": Control\n! - \"results_angveloc\": Angular velocities\n! - \"results_eulerang\": Euler angles\n! - \"results_quaternion\": Quaternion\n! - \"results_quatnorm\": Norm of quaternion\n! - \"results_time\": Time vector\n! - \"results_converg\": Convergence\n! - \"results_misc\": Miscelaneous results (Cost, CPU time...)\n!\n! The convention for quaternion and\n! Euler angles is as follows:\n! q = (epsilon,eta)\n! eul = (phi,theta,rho) = (yaw,pitch,roll)\n! ==========================================================\n\n! ======== INITIALIZATION ========\n! Variables declares here are passed to all rubroutines\nmodule initialization\nimplicit none\ninteger:: N, m, nn\nreal:: T_0, T_1\nreal:: j1, j2, j3\nreal:: q1, q2, q3, q4, q5, q6, q7\nreal:: r1, r2, r3\nreal:: u1min, u1max, u2min, u2max, u3min, u3max\nend module initialization\n\n! ======== MAIN ========\nprogram main\nuse initialization\nimplicit none\n\ninteger, allocatable:: mask(:)\nreal, allocatable:: state_0(:), state_1(:), state(:, :)\ninteger:: i\nreal:: cpu_clock_ini, cpu_clock_fin\nreal:: prec, cost, eulang(3), pi\nreal:: omega_0(3), omega_1(3)\nreal:: eul_0(3), eul_1(3), quat_0(4), quat_1(4)\nN=7; ! Dimension of state\nnn=14; ! Number of constraints\npi = 4*atan(1.)\nallocate (state_0(N), state_1(N), mask(N))\n\n! Open input file\nopen (11,file='input_file',status='old')\n! Read input parameters\nread(11,*) T_0\nread(11,*) T_1\nread(11,*) j1, j2, j3\nread(11,*) q1, q2, q3, q4, q5, q6, q7\nread(11,*) r1, r2, r3\nread(11,*) omega_0(1), omega_0(2), omega_0(3)\nread(11,*) omega_1(1), omega_1(2), omega_1(3)\nread(11,*) eul_0(1), eul_0(2), eul_0(3)\nread(11,*) eul_1(1), eul_1(2), eul_1(3)\nread(11,*) m\nread(11,*) u1min, u2min, u3min, u1max, u2max, u3max\nread(11,*) mask(1), mask(2), mask(3), mask(4),&\n\t mask(5), mask(6), mask(7)\nread(11,*) prec\nclose(11)\n\nallocate (state(m+1,N))\n\ncall eul2quat(eul_0,quat_0)\ncall eul2quat(eul_1,quat_1)\nstate_0 = (/omega_0,quat_0/)\nstate_1 = (/omega_1,quat_1/)\n\ndo i=1, m+1 \n\tstate(i, :)=((m+1.-i)/m)*state_0+((i-1.)/m)*state_1\nend do\n\ncall CPU_TIME(cpu_clock_ini)\ncall optimalcontrol(prec, mask, state, cost)\ncall CPU_TIME(cpu_clock_fin)\n\nopen(11,file='results_misc', &\nstatus='replace',action='write')\nwrite(11,*) 'NONLINEAR MODEL;'\nwrite(11,*) 'Initial time T_0;', t_0\nwrite(11,*) 'Final time T_1;', t_1\nwrite(11,*) 'Moments of inertia;', j1, j2, j3\nwrite(11,*) 'Q (diagonal matix);', q1, q2, q3, q4, q5, q6\nwrite(11,*) 'R (diagonal matix);', r1, r2, r3\nwrite(11,*) 'Initial angular velocity w_0;', omega_0\nwrite(11,*) 'Initial angular velocity w_1;', omega_1\nwrite(11,*) 'Initial orientation (yaw,pitch,roll);', eul_0\nwrite(11,*) 'Final orientation (yaw,pitch,roll);', eul_1\nwrite(11,*) '# Intervals discretization;', m\nwrite(11,*) 'Precision;', prec\nwrite(11,*) 'Mask (1=bound.cond./0=natural);', mask\nwrite(11,*) 'Cost I(u);', cost\nwrite(11,*) 'CPU time (s);', cpu_clock_fin-cpu_clock_ini\nclose(11)\n\nopen(11,file='results_control', &\nstatus='replace',action='write')\ndo i = 1,m \n\twrite(11,*) &\n\t(state(i+1,1) - state(i,1))*m/(T_1-T_0), &\n\t(state(i+1,2) - state(i,2))*m/(T_1-T_0), &\n\t(state(i+1,3) - state(i,3))*m/(T_1-T_0)\nend do\nclose(11)\n\nopen(11,file='results_quaternion', &\nstatus='replace',action='write')\ndo i = 1,m+1\n\twrite(11,*) state(i,4:7)\nend do\nclose(11)\nopen(11,file='results_eulerang', &\nstatus='replace',action='write')\n\ndo i = 1,m+1\n\tcall quat2eul(state(i,4:7),eulang)\n\twrite (11,*) eulang\nend do\nclose(11)\n\nopen(11,file='results_angveloc', &\nstatus='replace',action='write')\ndo i = 1,m+1\n\twrite (11,*) state(i,1:3)\nend do\nclose(11)\n\nopen(11,file='results_quatnorm', &\nstatus='replace',action='write')\ndo i = 1, m+1\n write (11,*) & \n\tstate(i,4)**2+state(i,5)**2+ &\n\tstate(i,6)**2+state(i,7)**2\nend do\nclose (11)\n\nopen(11,file='results_time', &\nstatus='replace',action='write')\ndo i = 1, m+1\n write (11,*) T_0+(T_1-T_0)*(i-1)/m\nend do\nclose (11)\n\ndeallocate (state_0, state_1, state, mask)\nend program main\n\n! ======== CONSTRAINTS ========\nsubroutine constraints(s, x, p, R)\nuse initialization\nimplicit none\nreal:: s, x(N), p(N), R(nn)\nR (1) = j1*p(1) + (j3-j2)*(x(2)*x(3)) - u1max\nR (2) = -j1*p(1) - (j3-j2)*(x(2)*x(3)) + u1min\nR (3) = j2*p(2) + (j1-j3)*(x(1)*x(3)) - u2max\nR (4) = -j2*p(2) - (j1-j3)*(x(1)*x(3)) + u2min\nR (5) = j3*p(3) + (j2-j1)*(x(1)*x(2)) - u3max\nR (6) = -j3*p(3) - (j2-j1)*(x(1)*x(2)) + u3min\nR (7) = p(4) - .5*(+ x(1)*x(7) - x(2)*x(6) + x(3)*x(5))\nR (8) = -p(4) + .5*(+ x(1)*x(7) - x(2)*x(6) + x(3)*x(5))\nR (9) = p(5) - .5*(+ x(1)*x(6) - x(3)*x(4) + x(2)*x(7))\nR (10) = -p(5) + .5*(+ x(1)*x(6) - x(3)*x(4) + x(2)*x(7))\nR (11) = p(6) - .5*(+ x(2)*x(4) - x(1)*x(5) + x(3)*x(7))\nR (12) = -p(6) + .5*(+ x(2)*x(4) - x(1)*x(5) + x(3)*x(7))\nR (13) = p(7) - .5*(- x(1)*x(4) - x(2)*x(5) - x(3)*x(6))\nR (14) = -p(7) + .5*(- x(1)*x(4) - x(2)*x(5) - x(3)*x(6))\nend subroutine constraints\n\n! ======== INTEGRAND ========\nsubroutine integrand(s, x, p, y, F)\nuse initialization\nimplicit none\nreal, intent(in):: s, x(N), p(N), y(m, nn)\nreal, intent(out):: F\nreal:: l(nn), R(nn) \ninteger:: i\ncall constraints(s, x, p, R)\ncall indexfunction(s, y, l)\n\nF = (r1*(j1*p(1) - j2*x(2)*x(3) + j3*x(2)*x(3))**2)/2 \nF = F + (r2*(j2*p(2) + j1*x(1)*x(3) - j3*x(1)*x(3))**2)/2\nF = F + (r3*(j3*p(3) - j1*x(1)*x(2) + j2*x(1)*x(2))**2)/2\n\nF = F + (q1*x(1)**2)/2 \nF = F + (q2*x(2)**2)/2\nF = F + (q3*x(3)**2)/2\nF = F + (q4*x(4)**2)/2\nF = F + (q5*x(5)**2)/2\nF = F + (q6*x(6)**2)/2\nF = F + (q7*x(7)**2)/2\nF = F - nn\ndo i = 1,nn\n F = F + exp(l(i)*R(i))\nend do\nend subroutine integrand\n\n! ======== AUX INTEGRAND 1 ========\nsubroutine auxintegrand1(s, x, p, y, H)\nuse initialization\nimplicit none\nreal, intent(in):: s, x(N), p(N), y(m, nn)\nreal, intent(out):: H(N)\nreal:: l(nn)!, R(nn)\n!call constraints(s, x, p, R)\ncall indexfunction(s, y, l)\nH(1)=q1*x(1)-(l(7)*x(7)*exp(l(7)*(p(4)-&\n\t(x(1)*x(7))/2+(x(2)*x(6))/2-(x(3)*x(5))/2)))/2\nH(1)=H(1)+(l(8)*x(7)*exp(-l(8)*(p(4)-&\n\t(x(1)*x(7))/2+(x(2)*x(6))/2-(x(3)*x(5))/2)))/2\nH(1)=H(1)-(l(9)*x(6)*exp(l(9)*(p(5)-&\n\t(x(1)*x(6))/2+(x(3)*x(4))/2-(x(2)*x(7))/2)))/2\nH(1)=H(1)+(l(10)*x(6)*exp(-l(10)*(p(5)-&\n\t(x(1)*x(6))/2+(x(3)*x(4))/2-(x(2)*x(7))/2)))/2\nH(1)=H(1)+(l(11)*x(5)*exp(l(11)*(p(6)+&\n\t(x(1)*x(5))/2-(x(2)*x(4))/2-(x(3)*x(7))/2)))/2\nH(1)=H(1)-(l(12)*x(5)*exp(-l(12)*(p(6)+&\n\t(x(1)*x(5))/2-(x(2)*x(4))/2-(x(3)*x(7))/2)))/2\nH(1)=H(1)+(l(13)*x(4)*exp(l(13)*(p(7)+&\n\t(x(1)*x(4))/2+(x(2)*x(5))/2+(x(3)*x(6))/2)))/2\nH(1)=H(1)-(l(14)*x(4)*exp(-l(14)*(p(7)+&\n\t(x(1)*x(4))/2+(x(2)*x(5))/2+(x(3)*x(6))/2)))/2\nH(1)=H(1)-r3*(j1*x(2)-j2*x(2))*&\n\t(j3*p(3)-j1*x(1)*x(2)+j2*x(1)*x(2))\nH(1)=H(1)+r2*(j1*x(3)-j3*x(3))*&\n\t(j2*p(2)+j1*x(1)*x(3)-j3*x(1)*x(3))\nH(1)=H(1)+l(3)*x(3)*&\n\texp(l(3)*(j2*p(2)+x(1)*x(3)*(j1-j3)-1))*(j1-j3)\nH(1)=H(1)-l(4)*x(3)*&\n\texp(-l(4)*(j2*p(2)+x(1)*x(3)*(j1-j3)+1))*(j1-j3)\nH(1)=H(1)-l(5)*x(2)*&\n\texp(-l(5)*(x(1)*x(2)*(j1-j2)-j3*p(3)+1))*(j1-j2)\nH(1)=H(1)+l(6)*x(2)*&\n\texp(-l(6)*(j3*p(3)-x(1)*x(2)*(j1-j2)+1))*(j1-j2)\n\nH(2)=q2*x(2)+(l(7)*x(6)*exp(l(7)*(p(4)-&\n\t(x(1)*x(7))/2+(x(2)*x(6))/2-(x(3)*x(5))/2)))/2\nH(2)=H(2)-(l(8)*x(6)*exp(-l(8)*(p(4)-&\n\t(x(1)*x(7))/2+(x(2)*x(6))/2-(x(3)*x(5))/2)))/2\nH(2)=H(2)-(l(9)*x(7)*exp(l(9)*(p(5)-&\n\t(x(1)*x(6))/2+(x(3)*x(4))/2-(x(2)*x(7))/2)))/2\nH(2)=H(2)-(l(11)*x(4)*exp(l(11)*(p(6)+&\n\t(x(1)*x(5))/2-(x(2)*x(4))/2-(x(3)*x(7))/2)))/2\nH(2)=H(2)+(l(10)*x(7)*exp(-l(10)*(p(5)-&\n\t(x(1)*x(6))/2+(x(3)*x(4))/2-(x(2)*x(7))/2)))/2\nH(2)=H(2)+(l(12)*x(4)*exp(-l(12)*(p(6)+&\n\t(x(1)*x(5))/2-(x(2)*x(4))/2-(x(3)*x(7))/2)))/2\nH(2)=H(2)+(l(13)*x(5)*exp(l(13)*(p(7)+&\n\t(x(1)*x(4))/2+(x(2)*x(5))/2+(x(3)*x(6))/2)))/2\nH(2)=H(2)-(l(14)*x(5)*exp(-l(14)*(p(7)+&\n\t(x(1)*x(4))/2+(x(2)*x(5))/2+(x(3)*x(6))/2)))/2\nH(2)=H(2)-r3*(j1*x(1)-j2*x(1))*&\n\t(j3*p(3)-j1*x(1)*x(2)+j2*x(1)*x(2))\nH(2)=H(2)-r1*(j2*x(3)-j3*x(3))*&\n\t(j1*p(1)-j2*x(2)*x(3)+j3*x(2)*x(3))\nH(2)=H(2)-l(1)*x(3)*&\n\texp(-l(1)*(x(2)*x(3)*(j2-j3)-j1*p(1)+1))*(j2-j3)\nH(2)=H(2)+l(2)*x(3)*&\n\texp(-l(2)*(j1*p(1)-x(2)*x(3)*(j2-j3)+1))*(j2-j3)\nH(2)=H(2)-l(5)*x(1)*&\n\texp(-l(5)*(x(1)*x(2)*(j1-j2)-j3*p(3)+1))*(j1-j2)\nH(2)=H(2)+l(6)*x(1)*&\n\texp(-l(6)*(j3*p(3)-x(1)*x(2)*(j1-j2)+1))*(j1-j2)\n\nH(3)=q3*x(3)-(l(7)*x(5)*exp(l(7)*(p(4)-&\n\t(x(1)*x(7))/2+(x(2)*x(6))/2-(x(3)*x(5))/2)))/2\nH(3)=H(3)+(l(8)*x(5)*exp(-l(8)*(p(4)-&\n\t(x(1)*x(7))/2+(x(2)*x(6))/2-(x(3)*x(5))/2)))/2\nH(3)=H(3)+(l(9)*x(4)*exp(l(9)*(p(5)-&\n\t(x(1)*x(6))/2+(x(3)*x(4))/2-(x(2)*x(7))/2)))/2\nH(3)=H(3)-(l(10)*x(4)*exp(-l(10)*(p(5)-&\n\t(x(1)*x(6))/2+(x(3)*x(4))/2-(x(2)*x(7))/2)))/2\nH(3)=H(3)-(l(11)*x(7)*exp(l(11)*(p(6)+&\n\t(x(1)*x(5))/2-(x(2)*x(4))/2-(x(3)*x(7))/2)))/2\nH(3)=H(3)+(l(12)*x(7)*exp(-l(12)*(p(6)+&\n\t(x(1)*x(5))/2-(x(2)*x(4))/2-(x(3)*x(7))/2)))/2\nH(3)=H(3)+(l(13)*x(6)*exp(l(13)*(p(7)+&\n\t(x(1)*x(4))/2+(x(2)*x(5))/2+(x(3)*x(6))/2)))/2\nH(3)=H(3)-(l(14)*x(6)*exp(-l(14)*(p(7)+&\n\t(x(1)*x(4))/2+(x(2)*x(5))/2+(x(3)*x(6))/2)))/2\nH(3)=H(3)+r2*(j1*x(1)-j3*x(1))*&\n\t(j2*p(2)+j1*x(1)*x(3)-j3*x(1)*x(3))\nH(3)=H(3)-r1*(j2*x(2)-j3*x(2))*&\n\t(j1*p(1)-j2*x(2)*x(3)+j3*x(2)*x(3))\nH(3)=H(3)-l(1)*x(2)*&\n\texp(-l(1)*(x(2)*x(3)*(j2-j3)-j1*p(1)+1))*(j2-j3)\nH(3)=H(3)+l(3)*x(1)*&\n\texp(l(3)*(j2*p(2)+x(1)*x(3)*(j1-j3)-1))*(j1-j3)\nH(3)=H(3)+l(2)*x(2)*&\n\texp(-l(2)*(j1*p(1)-x(2)*x(3)*(j2-j3)+1))*(j2-j3)\nH(3)=H(3)-l(4)*x(1)*&\n\texp(-l(4)*(j2*p(2)+x(1)*x(3)*(j1-j3)+1))*(j1-j3)\n\nH(4)=q4*x(4)+(l(9)*x(3)*exp(l(9)*(p(5)-&\n\t(x(1)*x(6))/2+(x(3)*x(4))/2-(x(2)*x(7))/2)))/2\nH(4)=H(4)-(l(10)*x(3)*exp(-l(10)*(p(5)-&\n\t(x(1)*x(6))/2+(x(3)*x(4))/2-(x(2)*x(7))/2)))/2\nH(4)=H(4)-(l(11)*x(2)*exp(l(11)*(p(6)+&\n\t(x(1)*x(5))/2-(x(2)*x(4))/2-(x(3)*x(7))/2)))/2\nH(4)=H(4)+(l(12)*x(2)*exp(-l(12)*(p(6)+&\n\t(x(1)*x(5))/2-(x(2)*x(4))/2-(x(3)*x(7))/2)))/2\nH(4)=H(4)+(l(13)*x(1)*exp(l(13)*(p(7)+&\n\t(x(1)*x(4))/2+(x(2)*x(5))/2+(x(3)*x(6))/2)))/2\nH(4)=H(4)-(l(14)*x(1)*exp(-l(14)*(p(7)+&\n\t(x(1)*x(4))/2+(x(2)*x(5))/2+(x(3)*x(6))/2)))/2\n\nH(5)=q5*x(5)-(l(7)*x(3)*exp(l(7)*(p(4)-&\n\t(x(1)*x(7))/2+(x(2)*x(6))/2-(x(3)*x(5))/2)))/2\nH(5)=H(5)+(l(8)*x(3)*exp(-l(8)*(p(4)-&\n\t(x(1)*x(7))/2+(x(2)*x(6))/2-(x(3)*x(5))/2)))/2\nH(5)=H(5)+(l(11)*x(1)*exp(l(11)*(p(6)+&\n\t(x(1)*x(5))/2-(x(2)*x(4))/2-(x(3)*x(7))/2)))/2\nH(5)=H(5)-(l(12)*x(1)*exp(-l(12)*(p(6)+&\n\t(x(1)*x(5))/2-(x(2)*x(4))/2-(x(3)*x(7))/2)))/2\nH(5)=H(5)+(l(13)*x(2)*exp(l(13)*(p(7)+&\n\t(x(1)*x(4))/2+(x(2)*x(5))/2+(x(3)*x(6))/2)))/2\nH(5)=H(5)-(l(14)*x(2)*exp(-l(14)*(p(7)+&\n\t(x(1)*x(4))/2+(x(2)*x(5))/2+(x(3)*x(6))/2)))/2\n\nH(6)=q6*x(6)+(l(7)*x(2)*exp(l(7)*(p(4)-&\n\t(x(1)*x(7))/2+(x(2)*x(6))/2-(x(3)*x(5))/2)))/2\nH(6)=H(6)-(l(8)*x(2)*exp(-l(8)*(p(4)-&\n\t(x(1)*x(7))/2+(x(2)*x(6))/2-(x(3)*x(5))/2)))/2\nH(6)=H(6)-(l(9)*x(1)*exp(l(9)*(p(5)-&\n\t(x(1)*x(6))/2+(x(3)*x(4))/2-(x(2)*x(7))/2)))/2\nH(6)=H(6)+(l(10)*x(1)*exp(-l(10)*(p(5)-&\n\t(x(1)*x(6))/2+(x(3)*x(4))/2-(x(2)*x(7))/2)))/2\nH(6)=H(6)+(l(13)*x(3)*exp(l(13)*(p(7)+&\n\t(x(1)*x(4))/2+(x(2)*x(5))/2+(x(3)*x(6))/2)))/2\nH(6)=H(6)-(l(14)*x(3)*exp(-l(14)*(p(7)+&\n\t(x(1)*x(4))/2+(x(2)*x(5))/2+(x(3)*x(6))/2)))/2\n\nH(7)=q7*x(7)-(l(7)*x(1)*exp(l(7)*(p(4)-&\n\t(x(1)*x(7))/2+(x(2)*x(6))/2-(x(3)*x(5))/2)))/2\nH(7)=H(7)+(l(8)*x(1)*exp(-l(8)*(p(4)-&\n\t(x(1)*x(7))/2+(x(2)*x(6))/2-(x(3)*x(5))/2)))/2\nH(7)=H(7)-(l(9)*x(2)*exp(l(9)*(p(5)-&\n\t(x(1)*x(6))/2+(x(3)*x(4))/2-(x(2)*x(7))/2)))/2\nH(7)=H(7)+(l(10)*x(2)*exp(-l(10)*(p(5)-&\n\t(x(1)*x(6))/2+(x(3)*x(4))/2-(x(2)*x(7))/2)))/2\nH(7)=H(7)-(l(11)*x(3)*exp(l(11)*(p(6)+&\n\t(x(1)*x(5))/2-(x(2)*x(4))/2-(x(3)*x(7))/2)))/2\nH(7)=H(7)+(l(12)*x(3)*exp(-l(12)*(p(6)+&\n\t(x(1)*x(5))/2-(x(2)*x(4))/2-(x(3)*x(7))/2)))/2\nend subroutine auxintegrand1\n\n! ======== AUX INTEGRAND 2 ========\nsubroutine auxintegrand2(s, x, p, y, T, G)\nuse initialization\nimplicit none\nreal, intent(in):: s, x(N), p(N), y(m, nn), T\nreal, intent(out):: G(N)\ninteger:: i\nreal:: l(nn), H(N)!, R(nn)\n!call constraints(s, x, p, R)\ncall indexfunction(s, y, l)\ncall auxintegrand1(s, x, p, y, H)\nG(1)=j1*r1*(j1*p(1)-j2*x(2)*x(3)+j3*x(2)*x(3))\nG(1)=G(1)+j1*l(1)*exp(-l(1)*(x(2)*x(3)*(j2-j3)-j1*p(1)+1))\nG(1)=G(1)-j1*l(2)*exp(-l(2)*(j1*p(1)-x(2)*x(3)*(j2-j3)+1))\nG(1)=G(1)-(T-s)*H(1)\n\nG(2)=j2*r2*(j2*p(2)+j1*x(1)*x(3)-j3*x(1)*x(3))\nG(2)=G(2)+j2*l(3)*exp(l(3)*(j2*p(2)+x(1)*x(3)*(j1-j3)-1))\nG(2)=G(2)-j2*l(4)*exp(-l(4)*(j2*p(2)+x(1)*x(3)*(j1-j3)+1))\nG(2)=G(2)-(T-s)*H(2)\n\nG(3)=j3*r3*(j3*p(3)-j1*x(1)*x(2)+j2*x(1)*x(2))\nG(3)=G(3)+j3*l(5)*exp(-l(5)*(x(1)*x(2)*(j1-j2)-j3*p(3)+1))\nG(3)=G(3)-j3*l(6)*exp(-l(6)*(j3*p(3)-x(1)*x(2)*(j1-j2)+1))\nG(3)=G(3)-(T-s)*H(3)\n\nG(4)=l(7)*exp(l(7)*(p(4)-(x(1)*x(7))/2+&\n\t(x(2)*x(6))/2-(x(3)*x(5))/2))\nG(4)=G(4)-l(8)*exp(-l(8)*(p(4)-(x(1)*x(7))/2+&\n\t(x(2)*x(6))/2-(x(3)*x(5))/2))\nG(4)=G(4)-(T-s)*H(4)\n\nG(5)=l(9)*exp(l(9)*(p(5)-(x(1)*x(6))/2+&\n\t(x(3)*x(4))/2-(x(2)*x(7))/2))\nG(5)=G(5)-l(10)*exp(-l(10)*(p(5)-(x(1)*x(6))/2+&\n\t(x(3)*x(4))/2-(x(2)*x(7))/2))\nG(5)=G(5)-(T-s)*H(5)\n\nG(6)=l(11)*exp(l(11)*(p(6)+(x(1)*x(5))/2-&\n\t(x(2)*x(4))/2-(x(3)*x(7))/2))\nG(6)=G(6)-l(12)*exp(-l(12)*(p(6)+(x(1)*x(5))/2-&\n\t(x(2)*x(4))/2-(x(3)*x(7))/2))\nG(6)=G(6)-(T-s)*H(6)\n\nG(7)=l(13)*exp(l(13)*(p(7)+(x(1)*x(4))/2+&\n\t(x(2)*x(5))/2+(x(3)*x(6))/2))\nG(7)=G(7)-l(14)*exp(-l(14)*(p(7)+(x(1)*x(4))/2+&\n\t(x(2)*x(5))/2+(x(3)*x(6))/2))\nG(7)=G(7)-(T-s)*H(7)\nend subroutine auxintegrand2\n\n! ======== EULER ANGLES TO QUATERNION ========\nsubroutine eul2quat(eul,q) \nreal, intent(in):: eul(3)\nreal, intent(out):: q(4)\nreal:: cy, sy, cp, sp, cr, sr\ncy = cos(eul(1)*.5);\nsy = sin(eul(1)*.5);\ncp = cos(eul(2)*.5);\nsp = sin(eul(2)*.5);\ncr = cos(eul(3)*.5);\nsr = sin(eul(3)*.5);\nq(1) = cy * cp * sr - sy * sp * cr\nq(2) = sy * cp * sr + cy * sp * cr\nq(3) = sy * cp * cr - cy * sp * sr\nq(4) = cy * cp * cr + sy * sp * sr\nend subroutine eul2quat\n\n! ======== QUATERNION TO EULER ANGLES ========\nsubroutine quat2eul(q,eul) \nreal, intent(in):: q(4)\nreal, intent(out):: eul(3)\neul(1) = atan2(2.*(q(4)*q(3)+q(1)*q(2)), &\n\t1.-2.*(q(2)**2.+q(3)**2.))\neul(2) = asin(2.*(q(4)*q(2)-q(3)*q(1)))\neul(3) = atan2(2.*(q(4)*q(1)+q(2)*q(3)), &\n\t1.-2.*(q(1)**2.+q(2)**2.))\nend subroutine quat2eul\n\n! ======== INDEX FUNCTION ========\nsubroutine indexfunction(s, z, L)\nuse initialization\nimplicit none\nreal:: s, z(m, nn), L(nn)\ninteger:: k\nk=int((s-T_0)*m/(T_1-T_0))+1\nL=z(k, :)\nend subroutine indexfunction\n\n! ======== OPTIMAL CONTROL ========\nsubroutine optimalcontrol(prec, mask, state, cost)\nuse initialization\nimplicit none\nexternal integrand\ninteger:: i, j, k, mask(N)\nreal:: deriv(N), midpoint(N), r(nn), y(m, nn)\nreal:: convergence, prec, state(m+1, N), hh\nreal:: cost_prev, cost\nreal:: H(m, N), y_0, G_aux(m, N), G_auxx(m, N)\nreal:: G(m, N), integ(N),norm, aux(m, N), tam, eta, F\n\nopen(11,file='results_converg', &\nstatus='replace',action='write') \n\nhh = (T_1-T_0)/m\ny_0 = 1.\ny = 1.\neta = 1.e-01; \n\n! // Optimal control algorithm ========\ndo \n\nconvergence=0.\ndo i=1, m\n\tderiv=(state(i+1, :)-state(i, :))/hh\n\tmidpoint=0.5*(state(i, :)+state(i+1, :))\n\tcall &\n\tconstraints(T_0+hh*(i-0.5), midpoint, deriv, r)\n\tdo k=1, nn\n\t\tif (convergence int32\n\nimplicit none\n\ninteger,parameter :: chunk_size = 256\n\ninteger :: n, iunit, istat, i, j, best_bus, bus\ncharacter(len=:),allocatable :: line\nlogical :: status_ok\ninteger(ip) :: earliest_timestamp, timestamp, best_timestamp, wait_time\ntype(string),dimension(:),allocatable :: vals\n\nopen(newunit=iunit, file='input.txt', iostat=istat)\n\ncall read_line_from_file(iunit,chunk_size,line,status_ok)\nread(line,'(I10)') earliest_timestamp\n\ncall read_line_from_file(iunit,chunk_size,line,status_ok)\ncall split(line,',',chunk_size,vals)\n\nn = size(vals)\nbest_bus = 0 ! closest so far to earliest_timestamp\nbest_timestamp = huge(1_ip) !\n\ndo i = 1, n\n if (vals(i)%str == 'x') cycle\n read(vals(i)%str, '(I10)') bus\n\n timestamp = 0\n do\n timestamp = timestamp + bus\n if (timestamp >= earliest_timestamp) then\n write(*,*) 'for bus ', bus, ' : ', timestamp\n if (timestamp a2 ) THEN \n dist(1) = SQRT( (x-a2)**2.0 + (y-b1)**2.0)\n dist(2) = SQRT( (x-a2)**2.0 + (y-b2)**2.0)\n ELSE \n dist(1) = ABS(y - b1)\n dist(2) = ABS(y - b2)\n END IF\n \n ! distance from vertical lines\n IF( y < b1 ) THEN\n dist(3) = SQRT( (x-a1)**2.0 + (y-b1)**2.0)\n dist(4) = SQRT( (x-a2)**2.0 + (y-b1)**2.0)\n ELSE IF( y > b2 ) THEN \n dist(3) = SQRT( (x-a1)**2.0 + (y-b2)**2.0)\n dist(4) = SQRT( (x-a2)**2.0 + (y-b2)**2.0)\n ELSE \n dist(3) = ABS(x - a1)\n dist(4) = ABS(x - a2)\n END IF\n \n ! minimum distance to the sides of the rectangle\n f = MINVAL( ABS( dist ) )\n \n ! set negative sign inside the rectangle \n IF( .NOT. (x > a1 .AND. x < a2 .AND. y > b1 .AND. y < b2) ) THEN\n f = -f\n END IF\n\n END FUNCTION InitSquare\n", "meta": {"hexsha": "0d306070898d2f0e7226593997b23c917aa34daa", "size": 1546, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "benchmark_apps/elmerfem/fem/tests/levelset1/InitSquare.f90", "max_stars_repo_name": "readex-eu/readex-apps", "max_stars_repo_head_hexsha": "38493b11806c306f4e8f1b7b2d97764b45fac8e2", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-11-25T13:10:11.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-15T20:26:35.000Z", "max_issues_repo_path": "elmerfem/fem/tests/levelset1/InitSquare.f90", "max_issues_repo_name": "jcmcmurry/pipelining", "max_issues_repo_head_hexsha": "8fface1a501b5050f58e7b902aacdcdde68e9648", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "elmerfem/fem/tests/levelset1/InitSquare.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": 25.3442622951, "max_line_length": 68, "alphanum_fraction": 0.4624838292, "num_tokens": 628, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127455162773, "lm_q2_score": 0.7745833841649232, "lm_q1q2_score": 0.6614266242035589}} {"text": "! A reference is https://www.nag.com/nagware/np/r70_doc/ieee_arithmetic.html\r\nprogram test_ieee_exceptions\r\nuse :: ieee_exceptions, only: ieee_set_halting_mode, ieee_invalid, &\r\n ieee_overflow, ieee_underflow, ieee_divide_by_zero, ieee_inexact\r\nimplicit none\r\nreal :: a, b, c, d, e, f, g\r\nlogical, parameter :: halt_program = .true.\r\ncall ieee_set_halting_mode([ieee_divide_by_zero, ieee_underflow, &\r\n ieee_overflow, ieee_invalid],halting=halt_program)\r\n! causes halt if divide_by_zero, underflow, overflow, or NaN conditions occur\r\n! remove element from array constructor to have program continue with that condition\r\nf = 1.0\r\nprint*,\"computing 1.0/0.0\"\r\nprint*,f/0.0\r\ne = tiny(e)\r\nprint*,\"tiny =\",e,\", computing tiny/10\"\r\nprint*,e/10\r\nd = huge(d)\r\nprint*,\"huge =\",d,\", computing huge**2\"\r\nprint*,d**2\r\na = 0.0\r\nb = 0.0\r\nprint*,\"a, b=\",a,b\r\nprint*,\"computing c = a/b\"\r\nc = a/b\r\nprint*,\"c=\",c\r\n! since floating point roundoff is ubiquitous, probably\r\n! do not want the following mode\r\ncall ieee_set_halting_mode(ieee_inexact, halting=halt_program)\r\nprint*,\"computing 2.0/3.0\"\r\ng = 2.0/3.0\r\nprint*,\"2.0/3.0 =\",g\r\nend program test_ieee_exceptions\r\n! output on Windows with ifort -traceback ieee_exceptions.f90\r\n! computing 1.0/0.0\r\n! forrtl: error (73): floating divide by zero\r\n! Image PC Routine Line Source \r\n! ieee_exceptions.e 00007FF6EBBF112A MAIN__ 14 ieee_exceptions.f90\r\n", "meta": {"hexsha": "4086888f4592014537dd8c69a1ef66ef2d5b7c1a", "size": 1471, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ieee_exceptions.f90", "max_stars_repo_name": "awvwgk/FortranTip", "max_stars_repo_head_hexsha": "3810038667e3d5d2ab33c39d4bd0f41870025420", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ieee_exceptions.f90", "max_issues_repo_name": "awvwgk/FortranTip", "max_issues_repo_head_hexsha": "3810038667e3d5d2ab33c39d4bd0f41870025420", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ieee_exceptions.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": 37.7179487179, "max_line_length": 90, "alphanum_fraction": 0.6852481305, "num_tokens": 439, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517043, "lm_q2_score": 0.7745833737577158, "lm_q1q2_score": 0.66142662107607}} {"text": "module random\n\nuse types, only: dp\nuse utils, only: stop_error\nimplicit none\nprivate\npublic randn, rand_gamma\n\ninterface randn\n module procedure randn_scalar\n module procedure randn_vector\n module procedure randn_matrix\n module procedure randn_vector_n\nend interface\n\ninterface rand_gamma\n module procedure rand_gamma_scalar\n module procedure rand_gamma_vector\n module procedure rand_gamma_matrix\n module procedure rand_gamma_vector_n\nend interface\n\ncontains\n\nsubroutine randn_scalar(x)\n! Returns a psuedorandom scalar drawn from the standard normal distribution.\n!\n! [1] Marsaglia, G., & Bray, T. A. (1964). A Convenient Method for Generating\n! Normal Variables. SIAM Review, 6(3), 260\u2013264.\nreal(dp), intent(out) :: x\nlogical, save :: first = .true.\nreal(dp), save :: u(2)\nreal(dp) :: r2\nif (first) then\n do\n call random_number(u)\n u = 2*u-1\n r2 = sum(u**2)\n if (r2 < 1 .and. r2 > 0) exit\n end do\n u = u * sqrt(-2*log(r2)/r2)\n x = u(1)\nelse\n x = u(2)\nend if\nfirst = .not. first\nend subroutine\n\nsubroutine randn_vector_n(n, x)\ninteger, intent(in) :: n\nreal(dp), intent(out) :: x(n)\ninteger :: i\ndo i = 1, size(x)\n call randn(x(i))\nend do\nend subroutine\n\nsubroutine randn_vector(x)\nreal(dp), intent(out) :: x(:)\ncall randn_vector_n(size(x), x)\nend subroutine\n\nsubroutine randn_matrix(x)\nreal(dp), intent(out) :: x(:, :)\ncall randn_vector_n(size(x), x)\nend subroutine\n\nsubroutine rand_gamma0(a, first, fn_val)\n! Returns a psuedorandom scalar drawn from the gamma distribution.\n!\n! The shape parameter a >= 1.\n!\n! [1] Marsaglia, G., & Tsang, W. W. (2000). A Simple Method for Generating\n! Gamma Variables. ACM Transactions on Mathematical Software (TOMS), 26(3),\n! 363\u2013372.\nreal(dp), intent(in) :: a\nlogical, intent(in) :: first\nreal(dp), intent(out) :: fn_val\nreal(dp), save :: c, d\nreal(dp) :: U, v, x\nif (a < 1) call stop_error(\"Shape parameter must be >= 1\")\nif (first) then\n d = a - 1._dp/3\n c = 1/sqrt(9*d)\nend if\ndo\n do\n call randn(x)\n v = (1 + c*x)**3\n if (v > 0) exit\n end do\n call random_number(U)\n ! Note: the number 0.0331 below is exact, see [1].\n if (U < 1 - 0.0331_dp*x**4) then\n fn_val = d*v\n exit\n else if (log(U) < x**2/2 + d*(1 - v + log(v))) then\n fn_val = d*v\n exit\n end if\nend do\nend subroutine\n\nsubroutine rand_gamma_scalar(a, x)\nreal(dp), intent(in) :: a\nreal(dp), intent(out) :: x\ncall rand_gamma0(a, .true., x)\nend subroutine\n\nsubroutine rand_gamma_vector_n(a, n, x)\nreal(dp), intent(in) :: a\ninteger, intent(in) :: n\nreal(dp), intent(out) :: x(n)\ninteger :: i\ncall rand_gamma0(a, .true., x(1))\ndo i = 2, size(x)\n call rand_gamma0(a, .false., x(i))\nend do\nend subroutine\n\nsubroutine rand_gamma_vector(a, x)\nreal(dp), intent(in) :: a\nreal(dp), intent(out) :: x(:)\ncall rand_gamma_vector_n(a, size(x), x)\nend subroutine\n\nsubroutine rand_gamma_matrix(a, x)\nreal(dp), intent(in) :: a\nreal(dp), intent(out) :: x(:, :)\ncall rand_gamma_vector_n(a, size(x), x)\nend subroutine\n\nend module\n", "meta": {"hexsha": "65e577ee604a18c156e6e52ca7c6ab6893de47c6", "size": 3058, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/random.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/random.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/random.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": 22.8208955224, "max_line_length": 77, "alphanum_fraction": 0.654676259, "num_tokens": 958, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778258, "lm_q2_score": 0.7799928900257126, "lm_q1q2_score": 0.6614088225057455}} {"text": " SUBROUTINE asolve(n,b,x,itrnsp)\r\n INTEGER n,itrnsp,ija,NMAX,i\r\n DOUBLE PRECISION x(n),b(n),sa\r\n PARAMETER (NMAX=1000)\r\n COMMON /mat/ sa(NMAX),ija(NMAX)\r\n do 11 i=1,n\r\n x(i)=b(i)/sa(i)\r\n11 continue\r\n return\r\n END\r\n", "meta": {"hexsha": "41272dc967f72e9cd0cfa09d469a1a8e9f64d677", "size": 264, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/asolve.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/asolve.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/asolve.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.0, "max_line_length": 38, "alphanum_fraction": 0.5303030303, "num_tokens": 91, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. Yes\n2. Yes", "lm_q1_score": 0.7799928900257126, "lm_q2_score": 0.8479677583778257, "lm_q1q2_score": 0.6614088225057454}} {"text": " PROGRAM xconvlv\r\nC driver for routine convlv\r\n INTEGER N,N2,M\r\n REAL PI\r\n PARAMETER(N=16,N2=32,M=9,PI=3.14159265)\r\n INTEGER i,isign,j\r\n REAL cmp,data(N),respns(M),resp(N),ans(N2)\r\n do 11 i=1,N\r\n data(i)=0.0\r\n if ((i.ge.(N/2-N/8)).and.(i.le.(N/2+N/8))) data(i)=1.0\r\n11 continue\r\n do 12 i=1,M\r\n respns(i)=0.0\r\n if (i.gt.2 .and. i.lt.7) respns(i)=1.0\r\n resp(i)=respns(i)\r\n12 continue\r\n isign=1\r\n call convlv(data,N,resp,M,isign,ans)\r\nC compare with a direct convolution\r\n write(*,'(/1x,t4,a,t13,a,t24,a)') 'I','CONVLV','Expected'\r\n do 14 i=1,N\r\n cmp=0.0\r\n do 13 j=1,M/2\r\n cmp=cmp+data(mod(i-j-1+N,N)+1)*respns(j+1)\r\n cmp=cmp+data(mod(i+j-1,N)+1)*respns(M-j+1)\r\n13 continue\r\n cmp=cmp+data(i)*respns(1)\r\n write(*,'(1x,i3,3x,2f12.6)') i,ans(i),cmp\r\n14 continue\r\n END\r\n", "meta": {"hexsha": "5443176fb22f5cea01964804edc1e7784388105a", "size": 931, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xconvlv.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xconvlv.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xconvlv.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": 30.0322580645, "max_line_length": 64, "alphanum_fraction": 0.5069817401, "num_tokens": 354, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677430095495, "lm_q2_score": 0.7799928900257126, "lm_q1q2_score": 0.6614088105185992}} {"text": "C GE WITH SCALED PARTIAL PIVOTING\r\n\r\n SUBROUTINE GESPP(N,A,IA,L,S) \r\n DIMENSION A(IA,N),L(N),S(N) \r\n DO 3 I = 1,N\r\n L(I) = I \r\n SMAX = 0.0\r\n DO 2 J = 1,N\r\n SMAX = AMAX1(SMAX,ABS(A(I,J)))\r\n 2 CONTINUE \r\n S(I) = SMAX \r\n 3 CONTINUE \r\n DO 7 K = 1,N-1\r\n RMAX = 0.0\r\n DO 4 I = K,N\r\n R = ABS(A(L(I),K))/S(L(I)) \r\n IF(R .LE. RMAX) GO TO 4 \r\n J = I \r\n RMAX = R\r\n 4 CONTINUE \r\n LK = L(J) \r\n L(J) = L(K) \r\n L(K) = LK \r\n DO 6 I = K+1,N \r\n XMULT = A(L(I),K)/A(LK,K) \r\n DO 5 J = K+1,N \r\n A(L(I),J) = A(L(I),J) - XMULT*A(LK,J) \r\n 5 CONTINUE\r\n A(L(I),K) = XMULT \r\n 6 CONTINUE \r\n 7 CONTINUE \r\n RETURN \r\n END \r\n ", "meta": {"hexsha": "2fefedd5a732b074e1bcc259f7b17f4eb7ba8cc6", "size": 845, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "04-Nonlinear-System/fortran_source_files/gespp.f", "max_stars_repo_name": "0x00000024/numerical-analysis", "max_stars_repo_head_hexsha": "a0af414675241fe3b1ed02687981c7a3a4d790f6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2022-01-05T01:49:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-19T04:15:53.000Z", "max_issues_repo_path": "04-Nonlinear-System/fortran_source_files/gespp.f", "max_issues_repo_name": "0x00000024/numerical-analysis", "max_issues_repo_head_hexsha": "a0af414675241fe3b1ed02687981c7a3a4d790f6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "04-Nonlinear-System/fortran_source_files/gespp.f", "max_forks_repo_name": "0x00000024/numerical-analysis", "max_forks_repo_head_hexsha": "a0af414675241fe3b1ed02687981c7a3a4d790f6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.8529411765, "max_line_length": 51, "alphanum_fraction": 0.3443786982, "num_tokens": 320, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361604769413, "lm_q2_score": 0.724870282120402, "lm_q1q2_score": 0.6613978570617769}} {"text": " SUBROUTINE SMPINT( ND, NF, MINCLS, MAXCLS, FUNSUB,\n & EPSABS, EPSREL, KEY, SBRGNS, WRKLEN, VRTWRK, \n & RESTAR, VALUE, ERROR, FUNCLS, INFORM )\n*\n****BEGIN PROLOGUE SMPINT\n****AUTHOR\n*\n* Alan Genz \n* Department of Mathematics\n* Washington State University \n* Pullman, WA 99164-3113, USA\n* Email: alangenz@wsu.edu\n*\n****LAST MODIFICATION 2002-9\n****KEYWORDS automatic multidimensional integrator,\n* n-dimensional simplex, general purpose, global adaptive\n****PURPOSE To calculate an approximation to a vector of integrals\n*\n* I = I (F ,F ,...,F ) DS\n* S 1 2 NF \n*\n* where S is a collection ND-dimensional simplices,\n* and F = F (X ,X ,...,X ), K = 1, 2, ..., NF,\n* K K 1 2 ND\n* and try to satisfy for each component I(K) of I \n* ABS( I(K) - VALUE(K) ) < MAX( EPSABS, EPSREL*ABS(I(K)) )\n*\n****DESCRIPTION Computation of integrals over simplical regions.\n* SMPINT is a driver for the integration routine SMPSAD, \n* which repeatedly subdivides the region of integration and \n* estimates the integrals and the errors over the subregions \n* with greatest estimated errors until the error request\n* is met or MAXCLS function evaluations have been used.\n*\n* ON ENTRY\n*\n* ND Integer, number of variables. 1 < ND \n* NF Integer, number of components of the integral.\n* MINCLS Integer, minimum number of FUNSUB calls.\n* MAXCLS Integer, maximum number of FUNSUB calls.\n* RULCLS is number FUNSUB calls for each subregion (see WRKLEN),\n* DIFCLS = 1 + 2*ND*( ND + 1 ). \n* If RESTAR = 0, MAXCLS must be >= MAX(SBRGNS*RULCLS,MINCLS).\n* If RESTAR = 1, MAXCLS must be >= MAX(4*RULCLS+DIFCLS,MINCLS).\n* FUNSUB Externally declared subroutine for computing components of\n* the integrand at the given evaluation point.\n* It must have parameters (ND,X,NF,FUNVLS)\n* Input parameters:\n* ND Integer that gives the dimension of I\n* X Real array of dimension ND that contains the \n* evaluation point.\n* NF Integer that gives the number of components of I.\n* Output parameter:\n* FUNVLS Real array of dimension NF that contains the\n* components of the integrand.\n* EPSABS Real.\n* Requested absolute accuracy.\n* EPSREL Real requested relative accuracy.\n* KEY Integer, key to selected local integration rule.\n* KEY = 3 gives the user a (default) degree 7 integration rule.\n* KEY = 1 gives the user a degree 3 integration rule.\n* KEY = 2 gives the user a degree 5 integration rule.\n* KEY = 3 gives the user a degree 7 integration rule.\n* KEY = 4 gives the user a degree 9 integration rule.\n* WRKLEN Integer, length of the working array VRTWRK.\n* WRKLEN should be >= WRKSBS*( ND*(ND+1) + 2*NF + 3 ) \n* + (ND+1)*(ND+2) + 7*NF, where \n* WRKSBS = SBRGNS + 3*( MAXCLS/RULCLS - SBRGNS*(1-RESTAR) )/4. \n* If \n* KEY = 0, RULCLS = (ND+4)*(ND+3)*(ND+2)/6 + (ND+2)*(ND+1);\n* KEY = 1, RULCLS = 2*ND+3;\n* KEY = 2, RULCLS = (ND+3)*(ND+2)/2 + 2*(ND+1);\n* KEY = 3, RULCLS = (ND+4)*(ND+3)*(ND+2)/6 + (ND+2)*(ND+1);\n* KEY = 4, RULCLS = (ND+5)*(ND+4)*(ND+3)*(ND+2)/24 \n* + 5*(ND+2)*(ND+1)/2 . \n* SBRGNS Integer, initial number of simplices.\n* VRTWRK Real array of dimension WRKLEN.\n* Work should contain the simplex vertices for SBRGNS \n* simplices; the coordinates of vertex J for simplex K\n* must be in VRTWRK(I+J*ND+(K-1)*ND*(ND+1)), \n* for I = 1, ..., ND; J = 0, ..., ND; K = 1, ..., SBRGNS.\n* The rest of VRTWRK is used as working storage; see below.\n* RESTAR Integer.\n* If RESTAR = 0, this is the first attempt to compute\n* the integrals over SBRGNS simplices.\n* If RESTAR = 1, then we restart a previous attempt.\n* In this case the only parameters for SMPINT that may\n* be changed (with respect to the previous call of SMPINT)\n* are MINCLS, MAXCLS, EPSABS, EPSREL, KEY and RESTAR.\n* ON RETURN\n*\n* SBRGNS Integer.\n* SBRGNS contains the current number of simplices. They\n* were obtained by subdividing the input simplicies.\n* VRTWRK Real array of dimension WRKLEN.\n* Used as working storage.\n* Let MAXSUB = (WRKLEN-(ND+1)*(ND+2)-7*NF)/(ND*(ND+1)+2*NF+3). \n* VRTWRK(1), ..., VRTWRK(ND*(ND+1)), ..., \n* VRTWRK(ND*(ND+1)*SBRGNS) contain subregion vertices.\n* VRTWRK(ND*(ND+1)*MAXSUB+1), ..., \n* VRTWRK(ND*(ND+1)*MAXSUB+NF*SBRGNS) contain\n* estimated components of the integrals over the subregions.\n* VRTWRK(ND*(ND+1)*MAXSUB+NF*MAXSUB+1), ..., \n* VRTWRK(ND*(ND+1)*MAXSUB+NF*(MAXSUB+SBRGNS)) \n* contain estimated errors for the subregions.\n* VRTWRK(ND*(ND+1)*MAXSUB+2*NF*MAXSUB+1), ..., \n* VRTWRK(ND*(ND+1)*MAXSUB+2*NF*MAXSUB+SBRGNS)) \n* contain volumes of the subregions (scaled by ND!).\n* VRTWRK(ND*(ND+1)*MAXSUB+(2*NF+1)*MAXSUB+1), ..., \n* VRTWRK(ND*(ND+1)*MAXSUB+(2*NF+1)*MAXSUB+SBRGNS) \n* contain greatest errors in each subregion.\n* VRTWRK(ND*(ND+1)*MAXSUB+(2*NF+2)*MAXSUB+1), ..., \n* VRTWRK(ND*(ND+1)*MAXSUB+(2*NF+2)*MAXSUB+SBRGNS) \n* contain pointers for the subregion heap.\n* The rest of VRTWRK is used as temporary storage in SMPSAD.\n* VALUE Real array of dimension NF of integral approximations.\n* ERROR Real array of dimension NF, of absolute accuracy estimates.\n* FUNCLS Integer, number of FUNSUB calls used by SMPINT.\n* INFORM Integer.\n* INFORM = 0 for normal exit, when ERROR(K) <= EPSABS or\n* ERROR(K) <= ABS(VALUE(K))*EPSREL with MAXCLS or less\n* function evaluations for all values of K, 1 <= K <= NF.\n* INFORM = 1 if MAXCLS was too small for SMPINT to obtain\n* the required accuracy. In this case SMPINT returns\n* values VALUE with estimated absolute accuracies ERROR.\n* INFORM = 2 if KEY < 0 or KEY > 4,\n* INFORM = 3 if ND < 2, \n* INFORM = 4 if NF < 1,\n* INFORM = 5 if EPSABS < 0 and EPSREL < 0,\n* INFORM = 6 if WRKLEN is too small,\n* INFORM = 7 if RESTAR < 0 or RESTAR > 1,\n* INFORM = 8 if SBRGNS <= 0.\n*\n****ROUTINES CALLED SMPCHC,SMPSAD\n****END PROLOGUE SMPINT\n*\n* Global variables.\n*\n EXTERNAL FUNSUB\n INTEGER ND, NF, MINCLS, MAXCLS, SBRGNS\n INTEGER KEY, WRKLEN, RESTAR, FUNCLS, INFORM\n DOUBLE PRECISION EPSABS, EPSREL\n DOUBLE PRECISION VALUE(NF), ERROR(NF), VRTWRK(WRKLEN)\n*\n* Local variables.\n*\n* MAXSUB Integer, maximum allowed number of subdivisions\n* for the given values of KEY, ND and NF.\n*\n INTEGER MAXSUB, RULCLS, I1, I2, I3, I4, I5, I6\n*\n****FIRST PROCESSING STATEMENT SMPINT\n*\n* Compute MAXSUB and RULCLS, and check the input parameters.\n*\n* \n CALL SMPCHC( ND, NF, MINCLS, MAXCLS, EPSABS, EPSREL, SBRGNS,\n & KEY, WRKLEN, RESTAR, RULCLS, MAXSUB, INFORM )\n IF ( INFORM .EQ. 0 ) THEN\n*\n* Split up the work space and call SMPSAD.\n*\n I1 = 1 + MAXSUB*ND*(ND+1)\n I2 = I1 + MAXSUB*NF\n I3 = I2 + MAXSUB*NF\n I4 = I3 + MAXSUB\n I5 = I4 + MAXSUB\n I6 = I5 + MAXSUB\n CALL SMPSAD( ND, NF, FUNSUB, MINCLS, MAXCLS, EPSABS, EPSREL,\n & RESTAR, KEY, RULCLS, MAXSUB, SBRGNS, VRTWRK, \n & VRTWRK(I1), VRTWRK(I2), VRTWRK(I3), VRTWRK(I4), \n & VRTWRK(I5), VRTWRK(I6), VALUE, ERROR, FUNCLS, INFORM )\n ELSE\n FUNCLS = 0\n ENDIF\n*\n****END SMPINT\n*\n END\n SUBROUTINE SMPCHC( ND, NF, MINCLS, MAXCLS, EPSABS, EPSREL, SBRGNS,\n & KEY, WRKLEN, RESTAR, RULCLS, MAXSUB, INFORM )\n*\n****BEGIN PROLOGUE SMPCHC\n****AUTHOR\n*\n* Alan Genz \n* Department of Mathematics \n* Washington State University \n* Pullman, WA 99164-3113, USA\n*\n****LAST MODIFICATION 2001-07\n****PURPOSE SMPCHC checks validity of input parameters for SMPINT.\n****DESCRIPTION\n* SMPCHC computes MAXSUB, RULCLS and INFORM as functions of \n* input parameters for SMPINT, and checks the validity of\n* input parameters for SMPINT.\n*\n* ON ENTRY\n*\n* ND Integer, number of variables, ND > 1. \n* NF Integer, number of components of the integral.\n* MINCLS Integer, minimum number of new FUNSUB calls.\n* MAXCLS Integer, maximum number of new FUNSUB calls.\n* The number of function values for each subregion is RULCLS. \n* If\n* KEY = 0, RULCLS = (ND+4)*(ND+3)*(ND+2)/6 + (ND+2)*(ND+1);\n* KEY = 1, RULCLS = 2*ND+3;\n* KEY = 2, RULCLS = (ND+3)*(ND+2)/2 + 2*(ND+1);\n* KEY = 3, RULCLS = (ND+4)*(ND+3)*(ND+2)/6 + (ND+2)*(ND+1);\n* KEY = 4, RULCLS = (ND+5)*(ND+4)*(ND+3)*(ND+2)/24 \n* + 5*(ND+2)*(ND+1)/2 .\n* DIFCLS = 1 + 2*ND*( ND + 1 ). \n* If RESTAR = 0, MAXCLS must be >= MAX(SBRGNS*RULCLS,MINCLS).\n* If RESTAR = 1, MAXCLS must be >= MAX(4*RULCLS+DIFCLS,MINCLS).\n* EPSABS Real, requested absolute accuracy.\n* EPSREL Real, requested relative accuracy.\n* SBRGNS Integer, initial number of simplices.\n* KEY Integer, key to selected local integration rule.\n* KEY = 0 gives the user a (default)degree 7 integration rule.\n* KEY = 1 gives the user a degree 3 integration rule.\n* KEY = 2 gives the user a degree 5 integration rule.\n* KEY = 3 gives the user a degree 7 integration rule.\n* KEY = 4 gives the user a degree 9 integration rule.\n* WRKLEN Integer, length of the working array WORK.\n* WRKLEN should be >= WRKSBS*( ND*(ND+1) + 2*NF + 3 )\n* + (ND+1)*(ND+2) + 7*NF, where\n* WRKSBS = SBRGNS + 3*( MAXCLS/RULCLS - SBRGNS*(1-RESTAR) )/4. \n* RESTAR Integer.\n* If RESTAR = 0, this is the first attempt to compute\n* the integral over the SBRGNS input simplices.\n* If RESTAR = 1, then we restart a previous attempt.\n*\n* ON RETURN\n*\n* RULCLS Integer, number of function values for each subregion. \n* If\n* KEY = 0, RULCLS = (ND+4)*(ND+3)*(ND+2)/6 + (ND+2)*(ND+1);\n* KEY = 1, RULCLS = 2*ND+3;\n* KEY = 2, RULCLS = (ND+3)*(ND+2)/2 + 2*(ND+1);\n* KEY = 3, RULCLS = (ND+4)*(ND+3)*(ND+2)/6 + (ND+2)*(ND+1);\n* KEY = 4, RULCLS = (ND+5)*(ND+4)*(ND+3)*(ND+2)/24 \n* + 5*(ND+2)*(ND+1)/2 .\n* MAXSUB Integer, maximum allowed number of subregions for the\n* given values of MAXCLS, WRKLEN, KEY and ND.\n* INFORM Integer.\n* INFORM = 0 for normal exit,\n* INFORM = 2 if KEY < 0 or KEY > 4,\n* INFORM = 3 if ND < 2, \n* INFORM = 4 if NF < 1,\n* INFORM = 5 if EPSABS < 0 and EPSREL < 0.,\n* INFORM = 6 if WRKLEN is too small,\n* INFORM = 7 if RESTAR < 0 or RESTAR > 1,\n* INFORM = 8 if SBRGNS <= 0.\n*\n****END PROLOGUE SMPCHC\n*\n* Global variables.\n*\n INTEGER ND, NF, MINCLS, MAXCLS, KEY, MAXSUB\n INTEGER WRKLEN, INFORM, RESTAR, RULCLS, SBRGNS\n DOUBLE PRECISION EPSABS, EPSREL\n*\n* Local variables.\n*\n INTEGER WRKDIF, DIFCLS\n*\n****FIRST PROCESSING STATEMENT SMPCHC\n*\n INFORM = 0\n*\n* Check valid KEY.\n* \n IF ( KEY .LT. 0 .OR. KEY .GT. 4 ) INFORM = 2\n*\n* Check valid ND.\n*\n IF ( ND .LT. 2 ) INFORM = 3\n*\n* Check positive NF.\n*\n IF ( NF .LT. 1 ) INFORM = 4\n*\n* Check valid accuracy requests.\n*\n IF ( EPSABS .LT. 0 .AND. EPSREL .LT. 0 ) INFORM = 5\n*\n* Check workspace.\n*\n WRKDIF = (ND+1)*(ND+2) + 7*NF\n MAXSUB = ( WRKLEN - WRKDIF )/( (ND+1)*ND + 2*NF + 3 ) \n IF ( MAXSUB .LE. SBRGNS ) INFORM = 6\n*\n* Check valid RESTAR.\n*\n IF ( RESTAR .NE. 0 .AND. RESTAR .NE. 1 ) INFORM = 7\n*\n* Check valid SBRGNS.\n*\n IF ( SBRGNS .LE. 0 ) INFORM = 8\n*\n* Compute RULCLS as a function of KEY and ND and check MAXCLS.\n*\n IF ( INFORM .EQ. 0 ) THEN\n DIFCLS = 1 + 2*ND*( ND + 1 )\n IF (KEY .EQ. 0) RULCLS = (ND+4)*(ND+3)*(ND+2)/6 + (ND+2)*(ND+1)\n IF (KEY .EQ. 1) RULCLS = 2*ND + 3\n IF (KEY .EQ. 2) RULCLS = (ND+3)*(ND+2)/2 + 2*(ND+1)\n IF (KEY .EQ. 3) RULCLS = (ND+4)*(ND+3)*(ND+2)/6 + (ND+2)*(ND+1)\n IF (KEY .EQ. 4) RULCLS = (ND+5)*(ND+4)*(ND+3)*(ND+2)/24 \n & + 5*(ND+2)*(ND+1)/2\n IF ( RESTAR.EQ.0 .AND. MAXCLS.LT.MAX(SBRGNS*RULCLS,MINCLS) .OR.\n & RESTAR.EQ.1 .AND. MAXCLS.LT.MAX(4*RULCLS+DIFCLS,MINCLS) ) \n & INFORM = 1\n ENDIF\n*\n****END SMPCHC\n*\n END\n*\n SUBROUTINE SMPSAD( ND, NF, FUNSUB, MINCLS, MAXCLS, EPSABS, EPSREL, \n & RESTAR, KEY, RULCLS, MAXSUB, SBRGNS, VERTCS, VALUES, ERRORS,\n & VOLUMS, GREATS, PONTRS, WORK, VALUE, ERROR, FUNCLS, INFORM )\n*\n****BEGIN PROLOGUE SMPSAD\n****KEYWORDS automatic multidimensional integrator,\n* n-dimensional simplex,\n* general purpose, global adaptive\n****AUTHOR\n*\n* Alan Genz \n* Department of Mathematics \n* Washington State University \n* Pullman, WA 99164-3113, USA\n*\n****LAST MODIFICATION 2001-07\n****PURPOSE The routine calculates an approximation to a given\n* vector of definite integrals, I, over a hyper-rectangular\n* region hopefully satisfying for each component of I the\n* following claim for accuracy:\n* ABS( I(K) - VALUE(K) ) .LE. MAX( EPSABS, EPSREL*ABS(I(K) ) )\n****DESCRIPTION Computation of integrals over hyper-rectangular regions.\n* SMPSAD repeatedly subdivides the regions of integration \n* and estimates the integrals and the errors over the \n* subregions with greatest estimated errors until the error\n* request is met or MAXSUB subregions are stored. The regions \n* are divided into three or four equally sized parts along\n* the direction(s) with greatest absolute fourth difference.\n*\n* ON ENTRY\n*\n* ND Integer, number of variables, ND > 1.\n* NF Integer, number of components of the integral.\n* FUNSUB Externally declared subroutine for computing components of\n* the integrand at the given evaluation point.\n* It must have parameters (ND,X,NF,FUNVLS)\n* Input parameters:\n* ND Integer that gives the dimension of I\n* X Real array of dimension ND that contains the \n* evaluation point.\n* NF Integer that gives the number of components of I.\n* Output parameter:\n* FUNVLS Real array of dimension NF that contains the\n* components of the integrand.\n* MINCLS Integer.\n* The computations proceed until there are at least\n* MINCLS FUNSUB calls.\n* MAXCLS Integer.\n* The computations proceed until further subdivision would\n* require more than MAXCLS FUNSUB calls. When RESTAR = 1,\n* this is the number of new FUNSUB calls.\n* EPSABS Real, requested absolute accuracy.\n* EPSREL Real, requested relative accuracy.\n* RESTAR Integer.\n* If RESTAR = 0, this is the first attempt to compute\n* the integral.\n* If RESTAR = 1, then we restart a previous attempt.\n* (In this case the output parameters from SMPSAD\n* must not be changed since the last exit from SMPSAD.)\n* KEY Integer, key to selected local integration rule.\n* KEY = 1 gives the user a degree 3 integration rule.\n* KEY = 2 gives the user a degree 5 integration rule.\n* KEY = 3 gives the user a degree 7 integration rule.\n* KEY = 4 gives the user a degree 9 integration rule.\n* RULCLS Integer, number of FUNSUB calls needed for each subregion.\n* MAXSUB Integer; computations proceed until there are at most\n* MAXSUB subregions in the data structure.\n* SBRGNS Integer.\n* If RESTAR = 0, then SBRGNS must specify the number\n* of subregions stored in a previous call to SMPSAD.\n* VERTCS Real array of dimension (ND,0:ND,*).\n* Simplex vertices for each subregion; for subregion K vertex\n* J must have components VERTEX(I,J,K), I = 1, 2, ..., ND.\n* VALUES Real array of dimension (NF,*), for estimated values of the \n* integrals over the subregions.\n* ERRORS Real array of dimension (NF,*).\n* Used to store the corresponding estimated errors.\n* Used to store the half widths of the stored subregions.\n* GREATS Real array of dimension (*).\n* Used to store the greatest estimated errors in subregions.\n* PONTRS Real array of dimension (*), for the pointers from the \n* subregion heap to the actual subregions.\n* WORK Real array, used in SMPVOL, SMPDFS, and SMPRUL.\n*\n* ON RETURN\n*\n* SBRGNS Integer, number of stored subregions.\n* VALUE Real array of dimension NF.\n* Approximations to all components of the integral.\n* ERROR Real array of dimension NF.\n* Estimates of absolute accuracies.\n* FUNCLS Integer, number of new FUNSUB calls used by SMPSAD.\n* INFORM Integer.\n* INFORM = 0 for normal exit, when ERROR(K) <= EPSABS or\n* ERROR(K) <= ABS(VALUE(K))*EPSREL, 1 <= K <= NF, \n* with MAXSUB or fewer subregions processed. \n* INFORM = 1 if MAXSUB was too small for SMPSAD\n* to obtain the required accuracy. In this case SMPSAD\n* returns values of VALUE with estimated absolute\n* accuracies ERROR.\n*\n****REFERENCES\n****ROUTINES CALLED SMPSTR, SMPVOL, SMPRUL\n****END PROLOGUE SMPSAD\n*\n* Global variables.\n*\n EXTERNAL FUNSUB\n INTEGER ND, NF, RULCLS, MINCLS, MAXCLS, MAXSUB, KEY, RESTAR\n INTEGER FUNCLS, SBRGNS, INFORM\n DOUBLE PRECISION EPSABS, EPSREL, VALUE(NF), ERROR(NF)\n DOUBLE PRECISION VALUES(NF,*), ERRORS(NF,*), VERTCS(ND,0:ND,*)\n DOUBLE PRECISION VOLUMS(*), GREATS(*), PONTRS(*), WORK(*)\n*\n* Local variables.\n*\n*\n* MXNWSB is the maxiumum number of new subregions per subdivision.\n*\n INTEGER I, INDEX, J, TOP, MXNWSB, NEWSBS, DFCOST, RGNCLS\n PARAMETER ( MXNWSB = 4 )\n DOUBLE PRECISION SMPVOL, TUNE\n PARAMETER( TUNE = 1 )\n*\n****FIRST PROCESSING STATEMENT SMPSAD\n* \n*\n* Initialize for rule parameters.\n*\n FUNCLS = 0\n DFCOST = 1 + 2*ND*( ND + 1 )\n*\n* If RESTAR = 0, initialize for first call.\n*\n IF ( RESTAR .EQ. 0 ) THEN\n*\n* Initialize FUNCLS, and VALUE and ERROR arrays.\n* \n DO J = 1, NF\n VALUE(J) = 0\n ERROR(J) = 0\n END DO\n DO INDEX = 1, SBRGNS\n* \n* Call SMPVOL to compute the simplex volume(s).\n* \n VOLUMS(INDEX) = SMPVOL( ND, VERTCS(1,0,INDEX), WORK )\n*\n* Apply basic rule over each simplex.\n*\n CALL SMPRUL( TUNE, ND, VERTCS(1,0,INDEX), VOLUMS(INDEX), \n & NF, FUNSUB, KEY, VALUES(1,INDEX), ERRORS(1,INDEX), \n & GREATS(INDEX), WORK, WORK(2*ND+2) )\n*\n* Add new contributions to VALUE and ERROR.\n* Store results in heap.\n* \n DO J = 1, NF\n VALUE(J) = VALUE(J) + VALUES(J,INDEX)\n ERROR(J) = ERROR(J) + ERRORS(J,INDEX)\n END DO\n CALL SMPSTR( INDEX, INDEX, PONTRS, GREATS )\n FUNCLS = FUNCLS + RULCLS\n END DO\n END IF\n INFORM = MAX( 0, MIN( MINCLS - FUNCLS, 1 ) )\n DO J = 1, NF\n IF( ERROR(J) .GT. MAX(EPSABS,EPSREL*ABS(VALUE(J))) ) INFORM = 1\n END DO\n*\n* End initialisation.\n*\n DO WHILE ( INFORM .GT. 0 .AND. SBRGNS + MXNWSB - 1 .LE. MAXSUB \n & .AND. FUNCLS + DFCOST + MXNWSB*RULCLS .LE. MAXCLS )\n*\n* Begin loop while error is too large, and FUNCLS and SBRGNS\n* are not too large.\n*\n* Adjust VALUE and ERROR.\n* \n TOP = PONTRS(1)\n DO J = 1, NF\n VALUE(J) = VALUE(J) - VALUES(J,TOP)\n ERROR(J) = ERROR(J) - ERRORS(J,TOP)\n END DO\n* \n* Determine NEWSBS new subregions.\n*\n CALL SMPDFS( ND, NF, FUNSUB, TOP, SBRGNS, VERTCS, \n & VOLUMS, WORK, WORK(ND+1), WORK(2*ND+1), \n & WORK(3*ND+1), WORK(3*ND+1+5*NF), NEWSBS ) \n*\n* Apply basic rule, store results in heap and\n* add new contributions to VALUE and ERROR.\n* \n INDEX = TOP\n DO I = 1, NEWSBS\n CALL SMPRUL( TUNE, ND, VERTCS(1,0,INDEX), VOLUMS(INDEX), NF,\n & FUNSUB, KEY, VALUES(1,INDEX), ERRORS(1,INDEX), \n & GREATS(INDEX), WORK, WORK(2*ND+2) )\n CALL SMPSTR( INDEX, SBRGNS+I-1, PONTRS, GREATS )\n DO J = 1, NF \n VALUE(J) = VALUE(J) + VALUES(J,INDEX)\n ERROR(J) = ERROR(J) + ERRORS(J,INDEX)\n END DO\n INDEX = SBRGNS + I\n END DO\n FUNCLS = FUNCLS + DFCOST + NEWSBS*RULCLS\n SBRGNS = SBRGNS + NEWSBS - 1\n* \n* Check for error termination.\n*\n INFORM = MAX( 0, MIN( MINCLS - FUNCLS, 1 ) )\n DO J = 1, NF\n IF( ERROR(J) .GT. MAX(EPSABS,EPSREL*ABS(VALUE(J))) ) \n & INFORM = 1\n END DO\n END DO\n*\n* Compute more accurate values of VALUE and ERROR.\n*\n DO I = 1, NF\n VALUE(I) = 0\n ERROR(I) = 0\n DO J = 1, SBRGNS\n VALUE(I) = VALUE(I) + VALUES(I,J)\n ERROR(I) = ERROR(I) + ERRORS(I,J)\n END DO\n END DO\n*\n****END SMPSAD\n*\n END\n*\n DOUBLE PRECISION FUNCTION SMPVOL( ND, VERTEX, WORK )\n*\n****BEGIN PROLOGUE SMPVOL\n****KEYWORDS simplex volume\n****PURPOSE Function to compute the scaled volume of a simplex.\n****AUTHOR\n*\n* Alan Genz \n* Department of Mathematics \n* Washington State University \n* Pullman, WA 99164-3113, USA\n*\n****LAST MODIFICATION 96-12\n****DESCRIPTION SMPVOL computes the volume of an ND-simplex scaled by\n* using Gauss elimination to compute a determinant.\n*\n* ON ENTRY\n*\n* ND Integer, number of variables.\n* VERTEX Real array of dimension (ND,0:ND), of simplex vertices; \n* vertex J must have components VERTEX(I,J), I = 1, 2, ..., ND.\n* WORK Real work array of dimension at least ND*ND.\n*\n* ON RETURN\n*\n* SMPVOL Real, value for the volume. \n*\n****ROUTINES CALLED: None.\n*\n****END PROLOGUE SMPVOL\n*\n* Global variables.\n*\n INTEGER ND\n DOUBLE PRECISION VERTEX(ND,0:ND), WORK(ND,*)\n*\n* Local variables.\n*\n INTEGER I, J, K, PIVPOS\n DOUBLE PRECISION MULT, VOL, WTEMP\n*\n****FIRST PROCESSING STATEMENT SMPVOL\n*\n*\n* Copy vertex differences to WORK array.\n*\n DO J = 1, ND\n DO I = 1, ND\n WORK(I,J) = VERTEX(I,J) - VERTEX(I,0)\n END DO\n END DO\n*\n* Use Gauss elimination with partial pivoting.\n*\n VOL = 1\n DO K = 1, ND\n PIVPOS = K\n DO J = K+1, ND\n IF ( ABS(WORK(K,J)) .GT. ABS(WORK(K,PIVPOS)) ) PIVPOS = J\n END DO\n DO I = K, ND\n WTEMP = WORK(I,K)\n WORK(I,K) = WORK(I,PIVPOS)\n WORK(I,PIVPOS) = WTEMP\n END DO\n VOL = VOL*WORK(K,K)/K\n DO J = K+1, ND\n MULT = WORK(K,J)/WORK(K,K)\n DO I = K+1, ND\n WORK(I,J) = WORK(I,J) - MULT*WORK(I,K)\n END DO\n END DO\n END DO\n SMPVOL = ABS(VOL)\n*\n****END SMPVOL\n*\n END\n*\n SUBROUTINE SMPRUL( TUNE, ND, VERTEX, VOLUME, NF, INTGND,\n & INKEY, BASVAL, RGNERR, GREAT, GT, RULE )\n*\n****BEGIN PROLOGUE SMPRUL\n****KEYWORDS basic numerical integration rule\n****PURPOSE To compute basic integration rule values.\n****AUTHOR\n*\n* Alan Genz\n* Department of Mathematics\n* Washington State University\n* Pullman, WA 99164-3113, USA\n* AlanGenz@wsu.edu\n*\n****LAST MODIFICATION 2001-07\n****DESCRIPTION SMPRUL computes basic integration rule values for a\n* vector of integrands over a hyper-rectangular region.\n* These are estimates for the integrals. SMPRUL also computes\n* estimates for the errors.\n*\n* ON ENTRY\n*\n* TUNE Real, tuning parameter, with 0 <= TUNE <= 1, with\n* TUNE = 1 for the most conservative error estimates. \n* If TUNE < 0, only the rule parameters are computed.\n* ND Integer, number of variables.\n* VERTEX Real array of dimension (ND,0:ND).\n* The simplex vertices; vertex J must have components\n* VERTEX(I,J), I = 1, 2, ..., ND.\n* NF Integer, number of components for the vector integrand.\n* INTGND Subroutine for computing components of the integrand at Z.\n* It must have parameters (ND,X,NF,FUNVLS)\n* Input parameters:\n* ND Integer that gives the dimension.\n* X Real array of dimension ND that contains the \n* evaluation point.\n* NF Integer that gives the number of components of I.\n* Output parameter:\n* FUNVLS Real array of dimension NF that contains the\n* components of the integrand.\n* INKEY Integer rule parameter. \n* If INKEY .GT. 0 and INKEY .LT. 5 then a rule of degree \n* 2*INKEY + 1; otherwise default degree 7 rule is used.\n* GT Real work array of length 2*ND+1.\n* RULE Real work array of dimension (NF,7).\n*\n* ON RETURN\n*\n* BASVAL Real array of length NF, values for the basic rule for \n* each component of the integrand.\n* RGNERR Real array of length NF, error estimates for BASVAL.\n* GREAT Real, maximum component of RGNERR.\n*\n*\n****ROUTINES CALLED: SMPRMS, SYMRUL\n*\n****END PROLOGUE SMPRUL\n*\n* Global variables.\n*\n EXTERNAL INTGND\n INTEGER NF, ND, INKEY\n DOUBLE PRECISION VERTEX(ND,0:ND), BASVAL(NF), RGNERR(NF)\n DOUBLE PRECISION VOLUME, TUNE, GREAT\n*\n* Local variables.\n*\n* WTS Integer number of weights in the integration rules.\n* W Real array of dimension (WTS,RLS).\n* The weights for the basic and null rules.\n* W(1,1),...,W(WTS,1) are weights for the basic rule.\n* W(1,I),...,W(WTS,I), for I > 1 are null rule weights.\n* G Real array of dimension (0:4, WTS).\n* The fully symmetric sum generators for the rules.\n*\n INTEGER KEY, NUMNUL, RLS, WTS, MXW, MXRLS, MXG\n PARAMETER( MXW = 21, MXRLS = 7, MXG = 4 )\n DOUBLE PRECISION W( MXW, MXRLS ), G( 0:MXG, MXW ), WTSUM\n DOUBLE PRECISION GT( 0:2*ND ), RULE( NF, MXRLS )\n DOUBLE PRECISION NORMCF, NORMNL, NORMCP, ALPHA(MXRLS)\n DOUBLE PRECISION RATIO, ERRCOF, RATMIN, SMALL, SMPROD\n PARAMETER( RATMIN = 1D-1, SMALL = 1D-12 )\n INTEGER I, J, K, OLDKEY, OLDN, PTS(MXW)\n SAVE OLDKEY, OLDN, KEY, PTS, W, G, RLS, WTS\n DATA OLDKEY, OLDN/ -1, 0 /\n*\n****FIRST PROCESSING STATEMENT SMPRUL\n* \n IF ( OLDKEY .NE. INKEY .OR. OLDN .NE. ND ) THEN\n OLDN = ND\n OLDKEY = INKEY\n IF ( INKEY .GT. 0 .AND. INKEY .LT. 5 ) THEN\n KEY = INKEY\n ELSE\n KEY = 3\n END IF\n*\n* Compute WTS, RLS, weights, generators, ERRCOF and PTS.\n*\n CALL SMPRMS( ND, KEY, MXW, W, MXG, G, WTS, RLS, PTS )\n*\n* Orthogonalize and normalize null rules.\n*\n NORMCF = SMPROD( WTS, PTS, W(1,1), W(1,1) )\n DO K = 2, RLS\n DO J = 2, K-1\n ALPHA(J) = -SMPROD( WTS, PTS, W(1,J), W(1,K) ) \n END DO\n DO I = 1, WTS\n WTSUM = 0\n DO J = 2, K-1\n WTSUM = WTSUM + W(I,J)*ALPHA(J)\n END DO\n W(I,K) = W(I,K) + WTSUM/NORMCF\n END DO\n NORMNL = SMPROD( WTS, PTS, W(1,K), W(1,K) )\n DO I = 1, WTS\n W(I,K) = W(I,K)*SQRT( NORMCF/NORMNL )\n END DO\n END DO\n ENDIF\n IF ( TUNE .GE. 0 ) THEN\n*\n* Compute the rule values.\n*\n DO I = 1, NF\n DO J = 1, RLS\n RULE(I,J) = 0\n END DO\n END DO\n DO K = 1, WTS\n IF ( PTS(K) .GT. 0 ) THEN\n DO I = 0, MIN(ND,MXG-1)\n GT(I) = G(I,K)\n END DO\n IF ( ND .GE. MXG ) CALL SMPCPY( MXG, ND, GT, G(MXG,K) )\n CALL SMPSMS( ND, VERTEX, NF, INTGND, GT, BASVAL, \n & GT(ND+1), RGNERR )\n DO J = 1, RLS\n DO I = 1, NF\n RULE(I,J) = RULE(I,J) + W(K,J)*BASVAL(I)\n END DO\n END DO\n END IF\n END DO\n*\n* Scale integral values and compute the error estimates.\n*\n ERRCOF = ( 8*TUNE + ( 1 - TUNE ) )\n GREAT = 0\n DO I = 1, NF\n BASVAL(I) = RULE(I,1)\n NORMCF = ABS( BASVAL(I) )\n RGNERR(I) = 0\n RATIO = RATMIN\n DO K = RLS, 3, -2\n NORMNL = MAX( ABS( RULE(I,K) ), ABS( RULE(I,K-1) ) )\n IF ( NORMNL .GT. SMALL*NORMCF .AND. K .LT. RLS )\n & RATIO = MAX( NORMNL/NORMCP, RATIO )\n RGNERR(I) = MAX( NORMNL, RGNERR(I) )\n NORMCP = NORMNL \n END DO\n IF( RATIO .GE. 1 ) THEN\n RGNERR(I) = TUNE*RGNERR(I) + ( 1 - TUNE )*NORMCP\n ELSE IF ( KEY .GT. 1 ) THEN\n RGNERR(I) = RATIO*NORMCP\n END IF\n RGNERR(I) = VOLUME*MAX( ERRCOF*RGNERR(I), SMALL*NORMCF ) \n BASVAL(I) = VOLUME*BASVAL(I)\n GREAT = MAX( GREAT, RGNERR(I) )\n END DO\n END IF\n*\n****END SMPRUL\n*\n END \n*\n DOUBLE PRECISION FUNCTION SMPROD( N, W, X, Y )\n INTEGER N, I, W(*)\n DOUBLE PRECISION X(*), Y(*), SUM\n SUM = 0\n DO I = 1, N\n SUM = SUM + W(I)*X(I)*Y(I)\n END DO\n SMPROD = SUM\n END\n*\n SUBROUTINE SMPRMS( ND, KEY, MXW, W, MXG, G, WTS, RLS, PTS )\n*\n****BEGIN PROLOGUE SMPRMS\n****KEYWORDS basic integration rule, degree 2*KEY+1\n****PURPOSE To initialize a degree 2*KEY+1 basic rule and null rules.\n****AUTHOR\n*\n* Alan Genz\n* Department of Mathematics\n* Washington State University\n* Pullman, WA 99164-3113, USA\n* AlanGenz@wsu.edu\n*\n****LAST MODIFICATION 2001-07\n****DESCRIPTION SMPRMS initializes a degree 2*KEY+1 rule, and\n* and max(2*KEY,2) lower degree null rules.\n*\n* ON ENTRY\n*\n* ND Integer, number of variables.\n* KEY Integer, < 5 and >= 0, rule parameter.\n* If KEY > 0 a degree 2*KEY+1 rule is initialized.\n* If KEY = 0 a degree 7 rule is initialized.\n*\n* ON RETURN\n* RLS Integer, total number of rules.\n* WTS Integer, total number of weights in each of the rules.\n* W Real array of dimension (MXW,*).\n* The weights for the basic and null rules.\n* W(1,1),...,W(WTS,1) are weights for the basic rule.\n* W(I,1),...,W(WTS,I) for I .GT. 1 are null rule weights.\n* G Real array of dimension (0:MXG,MXW).\n* The fully symmetric sum generators for the rules.\n* G(0,J), ..., G(MXG,J) are the generators for the\n* points associated with the Jth weights.\n* PTS Integer array of length (MXW). PTS(J) is number of integrand \n* values needed for generator J.\n*\n****REFERENCES\n*\n* Axel Grundmann and H. M. Moller\n* \"Invariant Integration Formulas for the n-Simplex by Combinatorial \n* Methods\", SIAM J Numer. Anal. 15(1978), 282--290,\n* and\n* A. H. Stroud\n* \"A Fifth Degree Integration Formula for the n-Simplex\n* SIAM J Numer. Anal. 6(1969), 90--98,\n* and \n* I. P. Mysovskikh\n* \"On a cubature formula for the simplex\"\n* Vopros. Vycisl. i Prikl. Mat., Tashkent 51(1978), 74--90.\n*\n*\n****ROUTINES CALLED NONE\n****END PROLOGUE SMPRMS\n*\n* Global variables\n*\n INTEGER ND, KEY, WTS, MXW, RLS, MXG\n INTEGER PTS(MXW)\n DOUBLE PRECISION W(MXW,*), G(0:MXG,*)\n*\n* Local Variables\n*\n DOUBLE PRECISION ONE, FFTEEN\n PARAMETER( ONE = 1, FFTEEN = 15 )\n DOUBLE PRECISION DR, DR2, DR4, DR6, DR8\n DOUBLE PRECISION R1, S1, R2, S2, U1, V1, U2, V2, L1, L2, D1, D2\n DOUBLE PRECISION A1, A2, A3, P0, P1, P2, P3, U5, U6, U7, SG\n DOUBLE PRECISION R, A, P, Q, TH, TP\n INTEGER IW, GMS, I, J\n*\n****FIRST PROCESSING STATEMENT SMPRMS\n*\n*\n* Initialize RLS and GMS.\n*\n IF ( KEY .EQ. 1 ) THEN\n RLS = 3\n GMS = 2\n WTS = 3\n ELSE IF ( KEY .EQ. 2 ) THEN\n RLS = 5\n GMS = 4\n WTS = 6\n ELSE IF ( KEY .EQ. 3 .OR. KEY .EQ. 0 ) THEN\n RLS = 7\n GMS = 7\n WTS = 11\n ELSE IF ( KEY .EQ. 4 ) THEN\n RLS = 7\n IF ( ND .EQ. 2 ) THEN\n GMS = 11\n WTS = 20\n ELSE\n GMS = 12\n WTS = 21\n END IF\n END IF\n*\n* Initialize generators, weights and PTS.\n*\n DO I = 1, WTS\n DO J = 1, RLS\n W(I,J) = 0\n END DO\n PTS(I) = 0\n END DO\n*\n* Compute generator, PTS and weight values for all rules.\n*\n DR = ND\n DR2 = ( DR + 1 )*( DR + 2 )\n DR4 = DR2*( DR + 3 )*( DR + 4 )\n DR6 = DR4*( DR + 5 )*( DR + 6 )\n DR8 = DR6*( DR + 7 )*( DR + 8 )\n CALL SMPCPY( 0, MXG, G(0,1), 1/( DR + 1 ) )\n PTS(1) = 1\n R1 = ( DR + 4 - SQRT(FFTEEN) )/( DR*DR + 8*DR + 1 )\n S1 = 1 - DR*R1\n L1 = S1 - R1\n G(0 ,GMS+1) = S1\n CALL SMPCPY( 1, MXG, G(0,GMS+1), R1 )\n DO I = 1, MXG\n G(I,GMS+1) = R1\n END DO\n PTS(GMS+1) = DR + 1\n IW = RLS\n IF ( KEY .LT. 4 ) THEN\n*\n* Compute weights for special degree 1 rule.\n*\n W(1,IW) = 1\n IW = IW - 1\n W(GMS+1,IW) = 1/( DR + 1 )\n IW = IW - 1\n END IF\n*\n* Compute weights, generators and PTS for degree 3 rule.\n*\n G(0,2) = 3/( DR + 3 )\n CALL SMPCPY( 1, MXG, G(0,2), 1/( DR + 3 ) )\n PTS(2) = DR + 1\n W(2,IW) = ( DR + 3 )**3/( 4*DR2*( DR + 3 ) )\n IF ( KEY .GT. 1 ) THEN\n IW = IW - 1\n*\n* Compute weights, generators and PTS for degree 3 and 5 rules.\n*\n IF ( ND .EQ. 2 ) THEN\n*\n* Special degree 3 rule.\n*\n L2 = .62054648267200632589046034361711D0\n L1 = -SQRT( ONE/2 - L2**2 )\n R1 = ( 1 - L1 )/3\n S1 = 1 - 2*R1\n G(0,GMS+1) = S1\n CALL SMPCPY( 1, MXG, G(0,GMS+1), R1 )\n PTS(GMS+1) = 3\n W(GMS+1,IW) = ONE/6\n R2 = ( 1 - L2 )/3\n S2 = 1 - 2*R2\n G(0,GMS+2) = S2\n CALL SMPCPY( 1, MXG, G(0,GMS+2), R2 )\n PTS(GMS+2) = 3\n W(GMS+2,IW) = ONE/6\n ELSE\n*\n* Degree 3 rule using Stroud points.\n*\n R2 = ( DR + 4 + SQRT(FFTEEN) )/( DR*DR + 8*DR + 1 )\n S2 = 1 - DR*R2\n L2 = S2 - R2\n G(0,GMS+2) = S2\n CALL SMPCPY( 1, MXG, G(0,GMS+2), R2 )\n PTS(GMS+2) = DR + 1\n W(GMS+2,IW) = ( 2/(DR+3) - L1 )/( DR2*(L2-L1)*L2**2 )\n W(GMS+1,IW) = ( 2/(DR+3) - L2 )/( DR2*(L1-L2)*L1**2 )\n END IF\n IW = IW - 1\n*\n* Grundmann-Moller degree 5 rule.\n*\n G(0,3) = 5/( DR + 5 )\n CALL SMPCPY( 1, MXG, G(0,3), 1/( DR + 5 ) )\n PTS(3) = DR + 1\n G(0,4) = 3/( DR + 5 )\n G(1,4) = 3/( DR + 5 )\n CALL SMPCPY( 2, MXG, G(0,4), 1/( DR + 5 ) )\n PTS(4) = ( ( DR + 1 )*DR )/2\n W(2,IW) = -( DR + 3 )**5/( 16*DR4 )\n W(3,IW) = ( DR + 5 )**5/( 16*DR4*( DR + 5 ) )\n W(4,IW) = ( DR + 5 )**5/( 16*DR4*( DR + 5 ) )\n END IF\n IF ( KEY .GT. 2 ) THEN\n IW = IW - 1\n*\n* Compute weights, generators and PTS for degree 5 and 7 rules.\n*\n*\n* Stroud degree 5 rule.\n*\n U1 = ( DR + 7 + 2*SQRT(FFTEEN) )/( DR*DR + 14*DR - 11 )\n V1 = ( 1 - ( DR - 1 )*U1 )/2\n D1 = V1 - U1\n G(0,GMS+3) = V1\n G(1,GMS+3) = V1\n CALL SMPCPY( 2, MXG, G(0,GMS+3), U1 )\n PTS(GMS+3) = ( ( DR + 1 )*DR )/2\n U2 = ( DR + 7 - 2*SQRT(FFTEEN) )/( DR*DR + 14*DR - 11 )\n V2 = ( 1 - ( DR - 1 )*U2 )/2\n D2 = V2 - U2\n G(0,GMS+4) = V2\n G(1,GMS+4) = V2\n CALL SMPCPY( 2, MXG, G(0,GMS+4), U2 )\n PTS(GMS+4) = ( ( DR + 1 )*DR )/2\n IF ( ND .EQ. 2 ) THEN\n W(GMS+3,IW) = ( 155 - SQRT(FFTEEN) )/1200\n W(GMS+4,IW) = ( 155 + SQRT(FFTEEN) )/1200\n W(1, IW) = 1 - 3*( W(GMS+3,IW) + W(GMS+4,IW) ) \n ELSE IF ( ND .EQ. 3 ) THEN\n W(GMS+1,IW) = ( 2665 + 14*SQRT(FFTEEN) )/37800\n W(GMS+2,IW) = ( 2665 - 14*SQRT(FFTEEN) )/37800\n W(GMS+3,IW) = 2*FFTEEN/567\n PTS(GMS+4) = 0\n ELSE\n W(GMS+1,IW) = ( 2*(27-DR)/(DR+5)-L2*(13-DR) )\n & /( L1**4*(L1-L2)*DR4 )\n W(GMS+2,IW) = ( 2*(27-DR)/(DR+5)-L1*(13-DR) )\n & /( L2**4*(L2-L1)*DR4 )\n W(GMS+3,IW)=( 2/( DR + 5 ) - D2 )/( DR4*( D1 - D2 )*D1**4 )\n W(GMS+4,IW)=( 2/( DR + 5 ) - D1 )/( DR4*( D2 - D1 )*D2**4 )\n END IF\n IW = IW - 1\n*\n* Grundmann-Moller degree 7 rule.\n*\n G(0,5) = 7/( DR + 7 )\n CALL SMPCPY( 1, MXG, G(0,5), 1/( DR + 7 ) )\n PTS(5) = DR + 1 \n G(0,6) = 5/( DR + 7 )\n G(1,6) = 3/( DR + 7 )\n CALL SMPCPY( 2, MXG, G(0,6), 1/( DR + 7 ) )\n PTS(6) = ( DR + 1 )*DR\n G(0,7) = 3/( DR + 7 )\n G(1,7) = 3/( DR + 7 )\n G(2,7) = 3/( DR + 7 )\n CALL SMPCPY( 3, MXG, G(0,7), 1/( DR + 7 ) )\n PTS(7) = ( ( DR + 1 )*DR*( DR - 1 ) )/6\n W(2,IW) = ( DR + 3 )**7/( 2*64*DR4*( DR + 5 ) )\n W(3,IW) = -( DR + 5 )**7/( 64*DR6 )\n W(4,IW) = -( DR + 5 )**7/( 64*DR6 )\n W(5,IW) = ( DR + 7 )**7/( 64*DR6*( DR + 7 ) )\n W(6,IW) = ( DR + 7 )**7/( 64*DR6*( DR + 7 ) )\n W(7,IW) = ( DR + 7 )**7/( 64*DR6*( DR + 7 ) )\n END IF\n IF ( KEY .EQ. 4 ) THEN\n IW = IW - 1\n*\n* Compute weights, generators and PTS for degree 7, 9 rules.\n*\n* Mysovskikh degree 7 rule.\n*\n SG = 1/( 23328*DR6 )\n U5 = -6**3*SG*( 52212 - DR*( 6353 + DR*( 1934 - DR*27 ) ) ) \n U6 = 6**4*SG*( 7884 - DR*( 1541 - DR*9 ) )\n U7 = -6**5*SG*( 8292 - DR*( 1139 - DR*3 ) )/( DR + 7 )\n P0 = -144*( 142528 + DR*( 23073 - DR*115 ) )\n P1 = -12*( 6690556 + DR*( 2641189 + DR*( 245378 - DR*1495 ) ) )\n P2 = -16*(6503401 + DR*(4020794+DR*(787281+DR*(47323-DR*385)))) \n P3 = -( 6386660 + DR*(4411997+DR*(951821+DR*(61659-DR*665))) )\n & *( DR + 7 )\n A = P2/( 3*P3 )\n P = A*( P1/P2 - A )\n Q = A*( 2*A*A - P1/P3 ) + P0/P3\n R = SQRT( -P**3 )\n TH = ACOS( -Q/( 2*R ) )/3\n R = 2*R**( ONE/3 )\n TP = 2*ACOS(-ONE)/3\n A1 = -A + R*COS( TH ) \n A2 = -A + R*COS( TH + TP + TP )\n A3 = -A + R*COS( TH + TP )\n G(0,GMS+5) = ( 1 - DR*A1 )/( DR + 1 )\n CALL SMPCPY( 1, MXG, G(0,GMS+5), ( 1 + A1 )/( DR + 1 ) )\n PTS(GMS+5) = DR + 1\n G(0,GMS+6) = ( 1 - DR*A2 )/( DR + 1 )\n CALL SMPCPY( 1, MXG, G(0,GMS+6), ( 1 + A2 )/( DR + 1 ) )\n PTS(GMS+6) = DR + 1\n G(0,GMS+7) = ( 1 - DR*A3 )/( DR + 1 )\n CALL SMPCPY( 1, MXG, G(0,GMS+7), ( 1 + A3 )/( DR + 1 ) )\n PTS(GMS+7) = DR + 1\n W(GMS+5,IW) = ( U7-(A2+A3)*U6+A2*A3*U5 )\n & /( A1**2-(A2+A3)*A1+A2*A3 )/A1**5\n W(GMS+6,IW) = ( U7-(A1+A3)*U6+A1*A3*U5 )\n & /( A2**2-(A1+A3)*A2+A1*A3 )/A2**5\n W(GMS+7,IW) = ( U7-(A2+A1)*U6+A2*A1*U5 )\n & /( A3**2-(A2+A1)*A3+A2*A1 )/A3**5\n G(0,GMS+8) = 4/( DR + 7 )\n G(1,GMS+8) = 4/( DR + 7 )\n CALL SMPCPY( 2, MXG, G(0,GMS+8), 1/( DR + 7 ) )\n PTS(GMS+8) = ( ( DR + 1 )*DR )/2\n W(GMS+8,IW) = 10*(DR+7)**6/( 729*DR6 )\n G(0,GMS+9) = 11/( DR + 7 )/2\n G(1,GMS+9) = 5/( DR + 7 )/2\n CALL SMPCPY( 2, MXG, G(0,GMS+9), 1/( DR + 7 ) )\n PTS(GMS+9) = ( ( DR + 1 )*DR )\n W(GMS+9,IW) = 64*(DR+7)**6/( 6561*DR6 )\n W( 4,IW) = W(4,IW+1)\n W( 7,IW) = W(7,IW+1)\n IW = IW - 1\n*\n* Grundmann-Moller degree 9 rule.\n*\n G(0,8) = 9/( DR + 9 )\n CALL SMPCPY( 1, MXG, G(0, 8), 1/( DR + 9 ) )\n PTS(8) = DR + 1 \n G(0,9) = 7/( DR + 9 )\n G(1,9) = 3/( DR + 9 )\n CALL SMPCPY( 2, MXG, G(0, 9), 1/( DR + 9 ) )\n PTS(9) = ( DR + 1 )*DR \n G(0,10) = 5/( DR + 9 )\n G(1,10) = 5/( DR + 9 )\n CALL SMPCPY( 2, MXG, G(0,10), 1/( DR + 9 ) )\n PTS(10) = ( ( DR + 1 )*DR )/2\n G(0,11) = 5/( DR + 9 )\n G(1,11) = 3/( DR + 9 )\n G(2,11) = 3/( DR + 9 )\n CALL SMPCPY( 3, MXG, G(0,11), 1/( DR + 9 ) )\n PTS(11) = ( ( DR + 1 )*DR*( DR - 1 ) )/2\n W(2 ,IW) = -( DR + 3 )**9/( 6*256*DR6 )\n W(3 ,IW) = ( DR + 5 )**9/( 2*256*DR6*( DR + 7 ) )\n W(4 ,IW) = ( DR + 5 )**9/( 2*256*DR6*( DR + 7 ) )\n W(5 ,IW) = -( DR + 7 )**9/( 256*DR8 )\n W(6 ,IW) = -( DR + 7 )**9/( 256*DR8 )\n W(7 ,IW) = -( DR + 7 )**9/( 256*DR8 )\n W(8 ,IW) = ( DR + 9 )**9/( 256*DR8*( DR + 9 ) )\n W(9 ,IW) = ( DR + 9 )**9/( 256*DR8*( DR + 9 ) )\n W(10,IW) = ( DR + 9 )**9/( 256*DR8*( DR + 9 ) )\n W(11,IW) = ( DR + 9 )**9/( 256*DR8*( DR + 9 ) )\n IF ( ND .GT. 2 ) THEN\n G(0,12) = 3/( DR + 9 )\n G(1,12) = 3/( DR + 9 )\n G(2,12) = 3/( DR + 9 )\n G(3,12) = 3/( DR + 9 )\n CALL SMPCPY( 4, MXG, G(0,12), 1/( DR + 9 ) )\n PTS(12) = ( ( DR + 1 )*DR*( DR - 1 )*( DR - 2 ) )/24\n W(12,IW) = W(8,IW)\n END IF \n END IF\n*\n* Compute constant weight values.\n*\n DO J = 1, RLS\n W(1,J) = 1\n DO I = 2, WTS\n W(1,J) = W(1,J) - PTS(I)*W(I,J) \n END DO\n END DO\n*\n* Compute final weight values; null rule weights are computed as \n* differences between weights from highest degree and lower degree rules.\n*\n DO J = 2, RLS\n DO I = 1, WTS\n W(I,J) = W(I,J) - W(I,1) \n END DO\n END DO\n*\n****END SMPRMS\n*\n END\n*\n SUBROUTINE SMPCPY( START, END, PARAM, VALUE )\n DOUBLE PRECISION VALUE, PARAM(0:*)\n INTEGER START, END, I\n DO I = START, END\n PARAM(I) = VALUE\n END DO\n END \n*\n SUBROUTINE SMPSMS( N, VERTEX, NF, F, G, SYMSMS, X, FUNVLS )\n*\n****BEGIN PROLOGUE SMPSMS\n****KEYWORDS fully symmetric sum\n****PURPOSE To compute fully symmetric basic rule sums\n****AUTHOR\n*\n* Alan Genz\n* Department of Mathematics\n* Washington State University\n* Pullman, WA 99164-3113, USA\n*\n****LAST MODIFICATION 97-04\n****DESCRIPTION SMPSMS computes a fully symmetric sum for a vector\n* of integrand values over a simplex. The sum is taken over\n* all permutations of the generators for the sum.\n*\n* ON ENTRY\n*\n* N Integer, number of variables.\n* VERTEX Real array of dimension (N,0:N)\n* The vertices of the simplex, one vertex per column.\n* NF Integer, number of components for the vector integrand.\n* F Subroutine for computing components of the integrand at X.\n* It must have parameters ( N, X, NF, FUNVLS ); \n* Input parameters:\n* N Integer dimension of integral.\n* X Real array of length N, the evaluation point.\n* NF Integer number of components of the integrand.\n* Output parameter:\n* FUNVLS Real array of length NF, the integrand values at X.\n* G Real Array of dimension (0:N).\n* The generators for the fully symmetric sum. \n*\n* ON RETURN\n*\n* SYMSMS Real array of length NF, the values for the fully symmetric \n* sums for each component of the integrand.\n*\n****ROUTINES CALLED: Integrand\n*\n****END PROLOGUE SMPSMS\n*\n* Global variables.\n*\n INTEGER N, NF\n DOUBLE PRECISION VERTEX(N,0:N),G(0:N), SYMSMS(NF),FUNVLS(NF), X(N)\n*\n* Local variables.\n*\n INTEGER IX, LX, I, J, K, L\n DOUBLE PRECISION GL, GI\n*\n****FIRST PROCESSING STATEMENT SymSum\n*\n DO I = 1, NF\n SYMSMS(I) = 0\n END DO\n*\n* Sort generators if necessary\n*\n K = 0\n DO I = 1, N\n IF ( G(I) .GT. G(I-1) ) K = 1\n END DO\n IF ( K .GT. 0 ) THEN\n DO I = 1, N\n K = I - 1\n DO J = I, N\n IF ( G(J) .GT. G(K) ) K = J\n END DO\n IF ( K .GE. I ) THEN\n GI = G(I-1)\n G(I-1) = G(K)\n G(K) = GI\n END IF\n END DO\n END IF\n*\n* Compute integrand value for permutations of G\n*\n 10 DO I = 1, N\n X(I) = VERTEX(I,0)*G(0)\n DO J = 1, N\n X(I) = X(I) + VERTEX(I,J)*G(J)\n END DO\n END DO\n CALL F( N, X, NF, FUNVLS )\n DO J = 1, NF\n SYMSMS(J) = SYMSMS(J) + FUNVLS(J)\n END DO\n*\n* Find next distinct permuation of G and loop back for value.\n* Permutations are generated in reverse lexicographic order.\n*\n DO I = 1, N\n IF ( G(I-1) .GT. G(I) ) THEN\n GI = G(I)\n IX = I - 1\n DO L = 0, I/2-1\n GL = G(L)\n G(L) = G(I-L-1)\n G(I-L-1) = GL\n IF ( GL .LE. GI ) IX = IX - 1\n IF ( G(L) .GT. GI ) LX = L\n END DO\n IF ( G(IX) .LE. GI ) IX = LX\n G(I) = G(IX)\n G(IX) = GI\n GO TO 10\n END IF\n END DO\n*\n****END SMPSMS\n*\n END \n*\n SUBROUTINE SMPSTR( POINTR, SBRGNS, PONTRS, RGNERS )\n*\n****BEGIN PROLOGUE SMPSTR\n****AUTHOR\n*\n* Alan Genz \n* Department of Mathematics \n* Washington State University \n* Pullman, WA 99164-3113, USA\n*\n****LAST MODIFICATION 2001-07\n****PURPOSE SMPSTR maintains a heap for subregions.\n****DESCRIPTION SMPSTR maintains a heap for subregions.\n* The subregions are ordered according to the size of the\n* greatest error estimates of each subregion (RGNERS).\n*\n* PARAMETERS\n*\n* POINTR Integer.\n* The index for the subregion to be inserted in the heap.\n* SBRGNS Integer.\n* Number of subregions in the heap.\n* PONTRS Real array of dimension SBRGNS.\n* Used to store the indices for the greatest estimated errors\n* for each subregion.\n* RGNERS Real array of dimension SBRGNS.\n* Used to store the greatest estimated errors for each \n* subregion.\n*\n****ROUTINES CALLED NONE\n****END PROLOGUE SMPSTR\n*\n* Global variables.\n*\n INTEGER POINTR, SBRGNS\n DOUBLE PRECISION PONTRS(*), RGNERS(*)\n*\n* Local variables.\n*\n* RGNERR Intermediate storage for the greatest error of a subregion.\n* SUBRGN Position of child/parent subregion in the heap.\n* SUBTMP Position of parent/child subregion in the heap.\n*\n INTEGER SUBRGN, SUBTMP, PT, PTP\n DOUBLE PRECISION RGNERR\n*\n****FIRST PROCESSING STATEMENT SMPSTR\n* \n RGNERR = RGNERS(POINTR)\n IF ( POINTR .EQ. PONTRS(1) ) THEN\n*\n* Move the new subregion inserted at the top of the heap \n* to its correct position in the heap.\n*\n SUBRGN = 1\n 10 SUBTMP = 2*SUBRGN\n IF ( SUBTMP .LE. SBRGNS ) THEN\n IF ( SUBTMP .NE. SBRGNS ) THEN\n* \n* Find maximum of left and right child.\n*\n PT = PONTRS(SUBTMP)\n PTP = PONTRS(SUBTMP+1)\n IF ( RGNERS(PT) .LT. RGNERS(PTP) ) SUBTMP = SUBTMP + 1\n ENDIF\n*\n* Compare maximum child with parent.\n* If parent is maximum, then done.\n*\n PT = PONTRS(SUBTMP)\n IF ( RGNERR .LT. RGNERS(PT) ) THEN\n* \n* Move the pointer at position subtmp up the heap.\n* \n PONTRS(SUBRGN) = PT\n SUBRGN = SUBTMP\n GO TO 10\n ENDIF\n ENDIF\n ELSE\n*\n* Insert new subregion in the heap.\n*\n SUBRGN = SBRGNS\n 20 SUBTMP = SUBRGN/2\n IF ( SUBTMP .GE. 1 ) THEN\n*\n* Compare child with parent. If parent is maximum, then done.\n* \n PT = PONTRS(SUBTMP)\n IF ( RGNERR .GT. RGNERS(PT) ) THEN\n* \n* Move the pointer at position subtmp down the heap.\n*\n PONTRS(SUBRGN) = PT\n SUBRGN = SUBTMP\n GO TO 20\n ENDIF\n ENDIF\n ENDIF\n PONTRS(SUBRGN) = POINTR\n*\n****END SMPSTR\n*\n END\n*\n SUBROUTINE SMPDFS( ND, NF, FUNSUB, TOP, SBRGNS, VERTCS, VOLUMS,\n * X, H, CENTER, WORK, FRTHDF, NEWSBS )\n*\n****BEGIN PROLOGUE SMPDFS\n****PURPOSE To compute new subregions\n****AUTHOR\n*\n* Alan Genz \n* Department of Mathematics \n* Washington State University \n* Pullman, WA 99164-3113, USA\n*\n****LAST MODIFICATION 2001-07\n****DESCRIPTION SMPDFS computes fourth differences along each edge\n* direction. It uses these differences to determine a \n* subdivision of the orginal subregion into either three or \n* four new subregions.\n*\n* ON ENTRY\n*\n* ND Integer, number of variables.\n* NF Integer, number of components for the vector integrand.\n* FUNSUB Externally declared subroutine.\n* For computing the components of the integrand at a point X.\n* It must have parameters (ND, X, NF, FUNVLS).\n* Input Parameters:\n* X Real array of dimension ND, the evaluation point.\n* ND Integer, number of variables for the integrand.\n* NF Integer, number of components for the vector integrand.\n* Output Parameters:\n* FUNVLS Real array of dimension NF.\n* The components of the integrand at the point X.\n* TOP Integer, location in VERTCS array for original subregion.\n* SBRGNS Integer, number of subregions in VERTCS BEFORE subdivision.\n* VERTCS Real array of dimension (ND,0:ND,*), vertices of orginal \n* subregion must be in VERTCS(1:ND,0:ND,TOP).\n* VOLUMS Real array of dimension (*) of volumes for subregions.\n* X Real work array of dimension ND.\n* H Real work array of dimension ND.\n* CENTER Real work array of dimension (0:ND).\n* WORK Real work array of dimension 5*NF.\n* FRTHDF Real work array of dimension (0:ND-1,ND).\n*\n* ON RETURN\n*\n* NEWSBS Integer, number of new subregions (3 or 4).\n* FUNCLS Integer, number of FUNSUB calls used by SMPDFS.\n* VERTCS Real array of dimension (ND,0:ND,*).\n* The vertices of the of new subegions will be at locations \n* TOP, SBRGNS+1, ..., SBRGNS+NEWSBS-1.\n* VOLUMS Real Array of dimension (*).\n* VOLUMS has been updated for new subregions.\n*\n****ROUTINES CALLED: FUNSUB\n*\n****END PROLOGUE SMPDFS\n*\n EXTERNAL FUNSUB\n INTEGER ND, NF, TOP, SBRGNS, NEWSBS\n DOUBLE PRECISION VERTCS(ND,0:ND,*), VOLUMS(*), WORK(NF,*)\n DOUBLE PRECISION X(ND), H(ND), CENTER(ND), FRTHDF(0:ND-1,ND)\n DOUBLE PRECISION DIFFER, DIFMAX, DIFMID, DIFNXT, EWIDTH, EDGMAX\n DOUBLE PRECISION CUTTF, CUTTB, DIFIL, DIFLJ, DFSMAX, VTI, VTJ, VTL \n PARAMETER ( CUTTF = 2, CUTTB = 8 )\n INTEGER I, J, K, L, IE, JE, IS, JS, LS, IT, JT, LT\n DOUBLE PRECISION SMPVOL\n*\n****FIRST PROCESSING STATEMENT SMPDFS\n*\n*\n* Compute the differences.\n*\n IS = 0\n JS = 1\n DIFMAX = 0\n EDGMAX = 0\n DO K = 1, ND\n CENTER(K) = VERTCS(K,0,TOP)\n DO L = 1, ND\n CENTER(K) = CENTER(K) + VERTCS(K,L,TOP)\n END DO\n CENTER(K) = CENTER(K)/( ND + 1 )\n END DO\n CALL FUNSUB(ND, CENTER, NF, WORK(1,3))\n DO I = 0, ND-1\n DO J = I+1, ND\n EWIDTH = 0\n DO K = 1, ND\n H(K) = 2*( VERTCS(K,I,TOP)-VERTCS(K,J,TOP) )/( 5*(ND+1) )\n EWIDTH = EWIDTH + ABS( H(K) )\n X(K) = CENTER(K) - 3*H(K)\n END DO\n DO L = 1, 5\n DO K = 1, ND\n X(K) = X(K) + H(K)\n END DO\n IF ( L. NE. 3 ) CALL FUNSUB(ND, X, NF, WORK(1,L))\n END DO\n IF ( EWIDTH .GE. EDGMAX ) THEN\n IE = I\n JE = J\n EDGMAX = EWIDTH\n END IF\n DIFFER = 0\n DIFMID = 0\n DO K = 1, NF\n DIFMID = DIFMID + ABS( WORK(K,3) )\n DIFFER = DIFFER + ABS( WORK(K,1) + WORK(K,5)+ 6*WORK(K,3)\n & - 4*( WORK(K,2) + WORK(K,4) ) )\n END DO\n IF ( DIFMID + DIFFER/8 .EQ. DIFMID ) DIFFER = 0 \n DIFFER = DIFFER*EWIDTH\n FRTHDF(I,J) = DIFFER\n IF ( DIFFER .GE. DIFMAX ) THEN\n IT = IS\n JT = JS\n DIFNXT = DIFMAX\n IS = I\n JS = J\n DIFMAX = DIFFER\n ELSE IF ( DIFFER .GE. DIFNXT ) THEN\n IT = I\n JT = J\n DIFNXT = DIFFER\n END IF\n END DO\n END DO\n*\n* Determine whether to compute three or four new subregions.\n*\n IF ( DIFNXT .GT. DIFMAX/CUTTF ) THEN\n NEWSBS = 4\n ELSE\n NEWSBS = 3 \n IF ( DIFMAX .EQ. 0 ) THEN\n IS = IE\n JS = JE\n ELSE\n DFSMAX = 0\n DO L = 0, ND\n IF ( L .NE. IS .AND. L .NE. JS ) THEN\n IT = MIN( L, IS, JS )\n JT = MAX( L, IS, JS )\n LT = IS + JS + L - IT - JT\n DIFFER = FRTHDF(IT,LT) + FRTHDF(LT,JT)\n IF ( DIFFER .GE. DFSMAX ) THEN\n DFSMAX = DIFFER\n LS = L\n END IF\n END IF\n END DO\n DIFIL = FRTHDF( MIN(IS,LS), MAX(IS,LS) )\n DIFLJ = FRTHDF( MIN(JS,LS), MAX(JS,LS) )\n DIFNXT = DIFIL + DIFLJ - MIN( DIFIL,DIFLJ )\n IF ( DIFMAX/CUTTB .LT. DIFNXT .AND. DIFIL .GT. DIFLJ ) THEN \n IT = IS\n IS = JS\n JS = IT\n END IF\n END IF\n END IF\n*\n* Copy vertices and volume for TOP to new subregions\n*\n VOLUMS(TOP) = VOLUMS(TOP)/NEWSBS\n DO L = SBRGNS + 1, SBRGNS + NEWSBS - 1\n VOLUMS(L) = VOLUMS(TOP)\n DO J = 0, ND\n DO K = 1, ND\n VERTCS(K,J,L) = VERTCS(K,J,TOP)\n END DO\n END DO\n END DO\n DO K = 1, ND\n VTI = VERTCS(K,IS,TOP)\n VTJ = VERTCS(K,JS,TOP)\n IF ( NEWSBS .EQ. 4 ) THEN\n* \n* Compute four new subregions.\n* \n VERTCS(K,JS,TOP) = ( VTI + VTJ )/2\n VERTCS(K,IS,SBRGNS+1) = VTI\n VERTCS(K,JS,SBRGNS+1) = ( VTI + VTJ )/2\n VERTCS(K,IS,SBRGNS+2) = ( VTI + VTJ )/2\n VERTCS(K,JS,SBRGNS+2) = VTJ\n VERTCS(K,IS,SBRGNS+3) = ( VTI + VTJ )/2\n VERTCS(K,JS,SBRGNS+3) = VTJ\n VTI = VERTCS(K,IT,TOP)\n VTJ = VERTCS(K,JT,TOP)\n VERTCS(K,JT,TOP) = ( VTI + VTJ )/2\n VERTCS(K,IT,SBRGNS+1) = ( VTI + VTJ )/2\n VERTCS(K,JT,SBRGNS+1) = VTJ\n VTI = VERTCS(K,IT,SBRGNS+2)\n VTJ = VERTCS(K,JT,SBRGNS+2)\n VERTCS(K,JT,SBRGNS+2) = ( VTI + VTJ )/2\n VERTCS(K,IT,SBRGNS+3) = ( VTI + VTJ )/2\n VERTCS(K,JT,SBRGNS+3) = VTJ\n ELSE\n*\n* Compute three new subregions.\n*\n VERTCS(K,JS,TOP) = ( 2*VTI + VTJ )/3\n VERTCS(K,IS,SBRGNS+1) = ( 2*VTI + VTJ )/3\n IF ( DIFMAX/CUTTF .LT. DIFNXT ) THEN\n VERTCS(K,JS,SBRGNS+1) = VTJ\n VERTCS(K,IS,SBRGNS+2) = ( 2*VTI + VTJ )/3\n VERTCS(K,JS,SBRGNS+2) = VTJ\n VTJ = VERTCS(K,JS,SBRGNS+1)\n VTL = VERTCS(K,LS,SBRGNS+1)\n VERTCS(K,LS,SBRGNS+1) = ( VTJ + VTL )/2\n VERTCS(K,JS,SBRGNS+2) = ( VTJ + VTL )/2\n VERTCS(K,LS,SBRGNS+2) = VTL\n ELSE\n VERTCS(K,JS,SBRGNS+1) = ( VTI + 2*VTJ )/3\n VERTCS(K,IS,SBRGNS+2) = ( VTI + 2*VTJ )/3\n VERTCS(K,JS,SBRGNS+2) = VTJ\n END IF\n END IF\n END DO\n* \n****END SMPDFS\n*\n END\n\n\n", "meta": {"hexsha": "917b80a0756d3651dd17f517b5a6fc3071ce8932", "size": 57442, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "LIBSTELL/Sources/NumerMeth/smpint.f", "max_stars_repo_name": "joseluisvelasco/STELLOPT", "max_stars_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2020-05-08T01:47:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T10:35:28.000Z", "max_issues_repo_path": "LIBSTELL/Sources/NumerMeth/smpint.f", "max_issues_repo_name": "joseluisvelasco/STELLOPT", "max_issues_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 77, "max_issues_repo_issues_event_min_datetime": "2020-05-08T07:18:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:20:33.000Z", "max_forks_repo_path": "Sources/SMPINT/smpint.f", "max_forks_repo_name": "ORNL-Fusion/LIBSTELL", "max_forks_repo_head_hexsha": "ba938c678d776b84d7bb260ea541a9b45deb37e2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-02-10T13:47:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T12:53:43.000Z", "avg_line_length": 34.8344451183, "max_line_length": 78, "alphanum_fraction": 0.5063542356, "num_tokens": 19103, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361533336451, "lm_q2_score": 0.72487026428967, "lm_q1q2_score": 0.6613978356144092}} {"text": "subroutine MakeGridDH(griddh, n, cilm, lmax, norm, sampling, csphase, lmax_calc)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tGiven the Spherical Harmonic coefficients CILM, this subroutine\n!\twill evalate the function on a grid with an equal number of samples N in \n!\tboth latitude and longitude (or N by 2N by specifying the optional parameter\n!\tSAMPLING = 2). This is the inverse of the routine SHExpandDH, both of which\n!\tare done quickly using FFTs for each degree of each latitude band. \n!\tThe number of samples is determined by the spherical harmonic bandwidth LMAX.\n!\tNevertheless, the coefficients can be evaluated up to smaller spherical harmonic \n!\tdegree by specifying the optional parameter LMAX_CALC. Note that N is always \n!\tEVEN for this routine. \n!\t\n!\tThe Legendre functions are computed on the fly using the scaling methodolgy \n!\tpresented in Holmes and Featherston (2002). When NORM = 1, 2 or 4, these are \n!\taccurate to about degree 2800. When NORM = 3, the routine is only stable to about \n!\tdegree 15!\n!\n!\tThe output grid contains N samples in latitude from 90 to -90+interval, and in \n!\tlongitude from 0 to 360-2*interval (or N x 2N, see below), where interval is the \n!\tsampling interval, and n=2*(LMAX+1). Note that the datum at 90 degees latitude \n!\tis ultimately downweighted to zero, so this point does not contribute to the \n!\tspherical harmonic coefficients.\n!\n!\tCalling Parameters\n!\t\tIN\n!\t\t\tcilm\t\tInput spherical harmonic coefficients with \n!\t\t\t\t\tdimension (2, lmax+1, lmax+1).\n!\t\t\tlmax\t\tMaximum spherical harmonic degree used in the expansion.\n!\t\t\t\t\tThis determines the spacing of the output grid.\n!\t\tOUT\n!\t\t\tgriddh\t\tGridded data of the spherical harmonic\n!\t\t\t\t\tcoefficients CILM with dimensions (2*LMAX+2 , 2*LMAX+2). \n!\t\t\tn\t\tNumber of samples in the grid, always even, which is 2*(LMAX+2).\n!\t\tOPTIONAL (IN)\n!\t\t\tnorm:\t\tNormalization to be used when calculating Legendre functions\n!\t\t\t\t\t\t(1) \"geodesy\" (default)\n!\t\t\t\t\t\t(2) Schmidt\n!\t\t\t\t\t\t(3) unnormalized\n!\t\t\t\t\t\t(4) orthonormalized\n!\t\t\tsampling\t(1) Grid is N latitudes by N longitudes (default).\n!\t\t\t\t\t(2) Grid is N by 2N. The higher frequencies resulting\n!\t\t\t\t\tfrom this oversampling in longitude are discarded, and hence not\n!\t\t\t\t\taliased into lower frequencies.\n!\t\t\tcsphase\t\t1: Do not include the phase factor of (-1)^m\n!\t\t\t\t\t-1: Apply the phase factor of (-1)^m.\n!\t\t\tlmax_calc\tThe maximum spherical harmonic degree to evaluate\n!\t\t\t\t\tthe coefficients up to.\n!\n!\tNotes:\n!\t\t1.\tIf lmax is greater than the the maximum spherical harmonic\n!\t\t\tdegree of the input file, then this file will be ZERO PADDED!\n!\t\t\t(i.e., those degrees after lmax are assumed to be zero).\n!\t\t2. \tLatitude is geocentric latitude.\n!\n!\tDependencies:\tFFTW3, CSPHASE_DEFAULT\n!\n!\tWritten by Mark Wieczorek 2004.\n!\n!\tSeptember 3, 2005. \tModifed so that the array plx is now optional.\n!\tSeptember 26, 2005. \tAdded optional argument NORM.\n!\tMay 30, 2006. \t\tModified routine to take into acount the symmetry of the\n!\t\t\t\tLegendre functions about the equator, i.e., (-1)^(l+m).\n!\tOctober 16, 2006. \tThe Legendre functions are now computed within this program\n!\t\t\t\tduring the summations over l and m. This leads to an increase in speed\n!\t\t\t\tof about a factor of 2. Added optional argument SAMPLING.\n!\tJuly 22, 2007.\t\tAdded optional parameter LMAX_CALC for evaluating coefficients up\n!\t\t\t\tto a maximum degree smaller than LMAX. \n!\tNovember 21, 2011\tFixed problem where saved variables used in Plm recursion were not recalculated\n!\t\t\t\tif NORM changed from one call to the next (with the same value of N).\n!\n!\tCopyright (c) 2006-2011, Mark A. Wieczorek\n!\tAll rights reserved.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\tuse FFTW3\n\tuse SHTOOLS, only: CSPHASE_DEFAULT\n\t\n\timplicit none\n\t\n\treal*8, intent(in) :: \tcilm(:,:,:)\n\treal*8, intent(out) ::\tgriddh(:,:)\n\tinteger, intent(in) :: \tlmax\n\tinteger, intent(out) ::\tn\n\tinteger, intent(in), optional :: norm, sampling, csphase, lmax_calc\n\tinteger :: \t\tl, m, i, l1, m1, lmax_comp, i_eq, i_s, phase, astat(4), lnorm, &\n\t\t\t\tk, kstart, nlong\n\treal*8 :: \t\tgrid(4*lmax+4), pi, theta, coef0, scalef, rescalem, u, p, pmm, &\n\t\t\t\tpm1, pm2, z, coef0s, tempr\n\tcomplex*16 ::\t\tcoef(2*lmax+3), coefs(2*lmax+3), tempc\n\tinteger*8 ::\t\tplan\n\treal*8, save, allocatable ::\tf1(:), f2(:), sqr(:), symsign(:)\n\tinteger, save ::\tlmax_old=0, norm_old = 0\n\t\n\tn = 2*lmax+2\n\t\n\tif (present(sampling)) then\n\t\tif (sampling /= 1 .and. sampling /=2) then\n\t\t\tprint*, \"Error --- MakeGridDH\"\n\t\t\tprint*, \"Optional parameter SAMPLING must be 1 (N by N) or 2 (N by 2N).\"\n\t\t\tprint*, \"Input value is \", sampling\n\t\t\tstop\n\t\tendif\n\tendif\n\t\n\tif (size(cilm(:,1,1)) < 2) then\n\t\tprint*, \"Error --- MakeGridDH\"\n\t\tprint*, \"CILM must be dimensioned as (2, *, *).\"\n\t\tprint*, \"Input dimension is \", size(cilm(:,1,1)), size(cilm(1,:,1)), size(cilm(1,1,:))\n\t\tstop\n\tendif \n\t\n\tif (present(sampling)) then\n\t\tif (sampling == 1) then\n\t\t\tif (size(griddh(:,1)) < n .or. size(griddh(1,:)) < n) then\n\t\t\t\tprint*, \"Error --- MakeGridDH\"\n\t\t\t\tprint*, \"GRIDDH must be dimensioned as (N, N) where N is \", n\n\t\t\t\tprint*, \"Input dimension is \", size(griddh(:,1)), size(griddh(1,:))\n\t\t\t\tstop\n\t\t\tendif\n\t\telseif (sampling ==2) then\n\t\t\tif (size(griddh(:,1)) < n .or. size(griddh(1,:)) < 2*n) then\n\t\t\t\tprint*, \"Error --- MakeGriddDH\"\n\t\t\t\tprint*, \"GRIDDH must be dimensioned as (N, 2*N) where N is \", n\n\t\t\t\tprint*, \"Input dimension is \", size(griddh(:,1)), size(griddh(1,:))\n\t\t\t\tstop\n\t\t\tendif\n\t\tendif\n\telse\n\t\t\n\t\tif (size(griddh(:,1)) < n .or. size(griddh(1,:)) < n) then\n\t\t\tprint*, \"Error --- MakeGridDH\"\n\t\t\tprint*, \"GRIDDH must be dimensioned as (N, N) where N is \", n\n\t\t\tprint*, \"Input dimension is \", size(griddh(:,1)), size(griddh(1,:))\n\t\t\tstop\n\t\tendif\n\n\tendif\n\t\t\n\tif (present(norm)) then\n\t\tif (norm > 4 .or. norm < 1) then\n\t\t\tprint*, \"Error --- MakeGridDH\"\n\t\t\tprint*, \"Parameter NORM must be 1 (geodesy), 2 (Schmidt), 3 (unnormalized), or 4 (orthonormalized).\"\n\t\t\tprint*, \"Input value is \", norm\n\t\t\tstop\n\t\tendif\n\t\t\n\t\tlnorm = norm\n\t\t\n\telse\n\t\tlnorm = 1\n\tendif\n\t\n\tif (present(csphase)) then\n \t\tif (csphase /= -1 .and. csphase /= 1) then\n \t\t\tprint*, \"MakeGridDH --- Error\"\n \t\t\tprint*, \"CSPHASE must be 1 (exclude) or -1 (include)\"\n \t\t\tprint*, \"Input valuse is \", csphase\n \t\t\tstop\n \t\telse\n \t\t\tphase = csphase\n \t\tendif\n \telse\n \t\tphase = CSPHASE_DEFAULT\n \tendif\n\n\tpi = acos(-1.0d0)\n\t\n\tscalef = 1.0d-280\n\t\n\tif (present(lmax_calc)) then\n\t\tlmax_comp = min(lmax, size(cilm(1,1,:))-1, size(cilm(1,:,1))-1, lmax_calc)\n\telse\n\t\tlmax_comp = min(lmax, size(cilm(1,1,:))-1, size(cilm(1,:,1))-1)\n\tendif\n\t\n\tif (present(sampling)) then\n\t\tif (sampling == 1) then\n\t\t\tnlong = n\n\t\telse\n\t\t\tnlong = 2*n\n\t\tendif\n\telse\n\t\tnlong = n\n\tendif\n\t\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t!\n\t!\tCalculate recursion constants used in computing the Legendre polynomials\n\t!\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t\n\tif (lmax_comp /= lmax_old .or. lnorm /= norm_old) then\n\t\t\n\t\tif (allocated(sqr)) deallocate(sqr)\n\t\tif (allocated(f1)) deallocate(f1)\n\t\tif (allocated(f2)) deallocate(f2)\n\t\tif (allocated(symsign)) deallocate(symsign)\n\t\t\n\t\tallocate(sqr(2*lmax_comp+1), stat=astat(1))\n\t\tallocate(f1((lmax_comp+1)*(lmax_comp+2)/2), stat=astat(2))\n\t\tallocate(f2((lmax_comp+1)*(lmax_comp+2)/2), stat=astat(3))\n\t\tallocate(symsign((lmax_comp+1)*(lmax_comp+2)/2), stat=astat(4))\n\t\t\n\t\tif (astat(1) /= 0 .or. astat(2) /= 0 .or. astat(3) /= 0 .or. astat(4) /= 0) then\n\t\t\tprint*, \"MakeGridDH --- Error\"\n\t\t\tprint*, \"Problem allocating arrays SQR, F1, F2, or SYMSIGN\", astat(1), astat(2), astat(3), astat(4)\n\t\t\tstop\n\t\tendif\n\t\t\n\t\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t\t!\n\t\t! \tCalculate signs used for symmetry of Legendre functions about equator\n\t\t!\n\t\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t\t\n\t\tk = 0\n\t\tdo l = 0, lmax_comp, 1\n\t\t\tdo m = 0, l, 1\n\t\t\t\tk = k + 1\n\t\t\t\tif (mod(l-m,2) == 0) then\n\t\t\t\t\tsymsign(k) = 1.0d0\n\t\t\t\telse\n\t\t\t\t\tsymsign(k) = -1.0d0\n\t\t\t\tendif\n\t\t\tenddo\n\t\tenddo\n\t\t\t\n\t\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t\t!\n\t\t!\tPrecompute square roots of integers that are used several times.\n\t\t!\n\t\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t\n\t\tdo l=1, 2*lmax_comp+1\n\t\t\tsqr(l) = sqrt(dble(l))\n\t\tenddo\n\n\t\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t\t!\n\t\t! \tPrecompute multiplicative factors used in recursion relationships\n\t\t! \t\tP(l,m) = x*f1(l,m)*P(l-1,m) - P(l-2,m)*f2(l,m)\n\t\t!\t\tk = l*(l+1)/2 + m + 1\n\t\t!\tNote that prefactors are not used for the case when m=l as a different \n\t\t!\trecursion is used. Furthermore, for m=l-1, Plmbar(l-2,m) is assumed to be zero.\n\t\t!\n\t\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t\n\t\tk = 1\n\t\t\n\t\tselect case(lnorm)\n\t\t\n\t\t\tcase(1,4)\n\t\n\t\t\t\tif (lmax_comp /= 0) then\n\t\t\t\t\tk = k + 1\n\t\t\t\t\tf1(k) = sqr(3)\n\t\t\t\t\tf2(k) = 0.0d0\n\t\t\t\t\tk = k + 1\n\t\t\t\tendif\n\t\t\t\t\n\t\t\t\tdo l=2, lmax_comp, 1\n\t\t\t\t\tk = k + 1\n\t\t\t\t\tf1(k) = sqr(2*l-1) * sqr(2*l+1) / dble(l)\n\t\t\t\t\tf2(k) = dble(l-1) * sqr(2*l+1) / sqr(2*l-3) / dble(l)\n\t\t\t\t\tdo m=1, l-2, 1\n\t\t\t\t\t\tk = k+1\n\t\t\t\t\t\tf1(k) = sqr(2*l+1) * sqr(2*l-1) / sqr(l+m) / sqr(l-m)\n \t\t\t\tf2(k) = sqr(2*l+1) * sqr(l-m-1) * sqr(l+m-1) &\n \t\t\t\t \t/ sqr(2*l-3) / sqr(l+m) / sqr(l-m) \n\t\t\t\t\tenddo\n\t\t\t\t\tk = k+1\n\t\t\t\t\tf1(k) = sqr(2*l+1) * sqr(2*l-1) / sqr(l+m) / sqr(l-m)\n \t\t\tf2(k) = 0.0d0\n\t\t\t\t\tk = k + 1\n\t\t\t\tenddo\n\t\t\t\n\t\t\tcase(2)\n\t\t\t\n\t\t\t\tif (lmax_comp /= 0) then\n\t\t\t\t\tk = k + 1\n\t\t\t\t\tf1(k) = 1.0d0\n\t\t\t\t\tf2(k) = 0.0d0\n\t\t\t\t\tk = k + 1\n\t\t\t\tendif\n\t\t\t\t\n\t\t\t\tdo l=2, lmax_comp, 1\n\t\t\t\t\tk = k + 1\n\t\t\t\t\tf1(k) = dble(2*l-1) /dble(l)\n\t\t\t\t\tf2(k) = dble(l-1) /dble(l)\n\t\t\t\t\tdo m=1, l-2, 1\n\t\t\t\t\t\tk = k+1\n\t\t\t\t\t\tf1(k) = dble(2*l-1) / sqr(l+m) / sqr(l-m)\n \t\t\t\tf2(k) = sqr(l-m-1) * sqr(l+m-1) / sqr(l+m) / sqr(l-m)\n\t\t\t\t\tenddo\n\t\t\t\t\tk = k+1\n\t\t\t\t\tf1(k) = dble(2*l-1) / sqr(l+m) / sqr(l-m)\n \t\t\tf2(k) = 0.0d0\n\t\t\t\t\tk = k + 1\n\t\t\t\tenddo\n\t\t\t\n\t\t\tcase(3)\n\t\t\n\t\t\t\tdo l=1, lmax_comp, 1\n\t\t\t\t\tk = k + 1\n\t\t\t\t\tf1(k) = dble(2*l-1) /dble(l)\n\t\t\t\t\tf2(k) = dble(l-1) /dble(l)\n\t\t\t\t\tdo m=1, l-1, 1\n\t\t\t\t\t\tk = k+1\n\t\t\t\t\t\tf1(k) = dble(2*l-1) / dble(l-m)\n \t\t\t\tf2(k) = dble(l+m-1) / dble(l-m)\n\t\t\t\t\tenddo\n\t\t\t\t\tk = k + 1\n\t\t\t\tenddo\n\n\t\tend select\n\t\n\t\tlmax_old = lmax_comp\n\t\tnorm_old = lnorm\n\t\n\tendif\n\t\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t!\n\t!\tDo special case of lmax_comp = 0\n\t!\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t\n\tif (lmax_comp == 0) then\n\t\n\t\tselect case(lnorm)\n\t\t\tcase(1,2,3);\tpm2 = 1.0d0\n\t\t\tcase(4);\tpm2 = 1.0d0 / sqrt(4.0d0*pi)\n\t\tend select\n\t\t\n\t\tif (present(sampling)) then\n\t\t\n\t\t\tif (sampling == 1) then\n\t\t\t\tgriddh(1:n, 1:n) = cilm(1,1,1) * pm2\n\t\t\telse\n\t\t\t\tgriddh(1:n, 1:2*n) = cilm(1,1,1) * pm2\n\t\t\tendif\n\t\t\t\n\t\telse\n\t\t\n\t\t\tgriddh(1:n, 1:n) = cilm(1,1,1) * pm2\n\t\t\n\t\tendif\n\t\n\t\treturn\n\t\n\tendif\n\t\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t!\n\t!\tDetermine Clms one l at a time by intergrating over latitude.\n\t!\t\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\t\n\tcall dfftw_plan_dft_c2r_1d(plan, nlong, coef(1:nlong/2+1), grid(1:nlong), FFTW_MEASURE)\n\n\ti_eq = n/2 + 1\t! Index correspondong to zero latitude\n\n\tdo i=1, i_eq - 1, 1\n\t\n\t\ti_s = 2*i_eq -i\n\t\n\t\ttheta = pi * dble(i-1)/dble(n)\n\t\tz = cos(theta)\n\t\tu = sqrt( (1.0d0-z) * (1.0d0+z) )\n\n\t\tcoef(1:lmax+1) = dcmplx(0.0d0,0.0d0)\n\t\tcoef0 = 0.0d0\n\t\tcoefs(1:lmax+1) = dcmplx(0.0d0,0.0d0)\n\t\tcoef0s = 0.0d0\n\t\t\n\t\tselect case(lnorm)\n\t\t\tcase(1,2,3);\tpm2 = 1.0d0\n\t\t\tcase(4);\tpm2 = 1.0d0 / sqrt(4.0d0*pi)\n\t\tend select\n\n\t\ttempr = cilm(1,1,1) * pm2\n\t\tcoef0 = coef0 + tempr\n\t\tcoef0s = coef0s + tempr \t! symsign is always 1 for l=m=0\n\t\t\t\t\n\t\tk = 2\n\t\tpm1 = f1(k) * z * pm2\n\t\ttempr = cilm(1,2,1) * pm1\n\t\tcoef0 = coef0 + tempr\n\t\tcoef0s = coef0s - tempr \t! symsign = -1\n\t\t\t\t\n\t\tdo l=2, lmax_comp, 1\n\t\t\tl1 = l+1\n\t\t\tk = k+l\n\t\t\tp = f1(k) * z * pm1 - f2(k) * pm2\n\t\t\ttempr = cilm(1,l1,1) * p\n\t\t\tcoef0 = coef0 + tempr\n\t\t\tcoef0s = coef0s + tempr * symsign(k)\n\t\t\tpm2 = pm1\n\t\t\tpm1 = p\n\t\tenddo\n\t\t\t\t\n\t\tselect case(lnorm)\n\t\t\tcase(1,2);\tpmm = sqr(2) * scalef\n\t\t\tcase(3);\tpmm = scalef\n\t\t\tcase(4);\tpmm = sqr(2) * scalef / sqrt(4.0d0*pi)\n\t\tend select\n\t\t\t\t\n\t\trescalem = 1.0d0/scalef\n\t\tkstart = 1\n\t\t\t\n\t\tdo m = 1, lmax_comp-1, 1\n\t\t\t\n\t\t\tm1 = m+1\n\t\t\trescalem = rescalem * u\n\t\t\tkstart = kstart+m+1\n\t\t\t\t\t\n\t\t\tselect case(lnorm)\n\t\t\t\tcase(1,4)\n\t\t\t\t\tpmm = phase * pmm * sqr(2*m+1) / sqr(2*m)\n\t\t\t\t\tpm2 = pmm\n\t\t\t\tcase(2)\n\t\t\t\t\tpmm = phase * pmm * sqr(2*m+1) / sqr(2*m)\n\t\t\t\t\tpm2 = pmm / sqr(2*m+1)\n\t\t\t\tcase(3)\n\t\t\t\t\tpmm = phase * pmm * dble(2*m-1)\n\t\t\t\t\tpm2 = pmm\n\t\t\tend select\n\t\t\t\n\t\t\ttempc = dcmplx(cilm(1,m1,m1), - cilm(2,m1,m1)) * pm2\n\t\t\tcoef(m1) = coef(m1) + tempc\n\t\t\tcoefs(m1) = coefs(m1) + tempc\n\t\t\t! symsign(kstart) = 1\n\t\t\t\t\t\t\t\t\t\t\n\t\t\tk = kstart+m+1\n\t \t\tpm1 = z * f1(k) * pm2\n\t \t\t\t\t\n\t \t\ttempc = dcmplx(cilm(1,m1+1,m1), - cilm(2,m1+1,m1)) * pm1\n\t \t\tcoef(m1) = coef(m1) + tempc\t\n\t\t\tcoefs(m1) = coefs(m1) - tempc\n\t\t\t! symsign = -1\n\t \t\t\t\t\n\t\t\tdo l = m+2, lmax_comp, 1\n\t\t\t\tl1 = l+1\n\t\t\t\tk = k + l\n\t\t\t\tp = z * f1(k) * pm1 - f2(k) * pm2\n\t\t\t\tpm2 = pm1\n \t\t\t\tpm1 = p\n \t\t\t\ttempc = dcmplx(cilm(1,l1,m1), - cilm(2,l1,m1)) * p\n\t\t\t\tcoef(m1) = coef(m1) + tempc\n\t\t\t\tcoefs(m1) = coefs(m1) + tempc * symsign(k)\n\t\t\tenddo\n\t\t\t\t\t\n\t\t\tcoef(m1) = coef(m1) * rescalem\n\t\t\tcoefs(m1) = coefs(m1) * rescalem\n\t\t\t\t\t\n\t\tenddo\t\t\t\n\t\t\t\t\t\t\t\t\n\t\trescalem = rescalem * u\n\t\t\t\t\n \tselect case(lnorm)\n \t\tcase(1,4);\tpmm = phase * pmm * sqr(2*lmax_comp+1) / sqr(2*lmax_comp) * rescalem\n \t\tcase(2);\tpmm = phase * pmm / sqr(2*lmax_comp) * rescalem\n \t\tcase(3);\tpmm = phase * pmm * dble(2*lmax_comp-1) * rescalem\n \tend select\n \t\t\t\n \ttempc = dcmplx(cilm(1,lmax_comp+1,lmax_comp+1), - cilm(2,lmax_comp+1,lmax_comp+1)) * pmm\n \tcoef(lmax_comp+1) = coef(lmax_comp+1) + tempc\n\t\tcoefs(lmax_comp+1) = coefs(lmax_comp+1) + tempc\n\t\t! symsign = 1\n\t\t\n\t\tcoef(1) = dcmplx(coef0,0.0d0)\n\t\tcoef(2:lmax+1) = coef(2:lmax+1)/2.0d0\n\t\t\n\t\tif (present(sampling)) then\n\t\t\tif (sampling == 2) then\n\t\t\t\tcoef(lmax+2:2*lmax+3) = dcmplx(0.0d0,0.0d0)\t\n\t\t\tendif\n\t\tendif\n \t\t\t\n \tcall dfftw_execute(plan)\t! take fourier transform\n \tgriddh(i,1:nlong) = grid(1:nlong)\n \t\n \tif (i /= 1) then\t! don't compute value for south pole.\n \t\tcoef(1) = dcmplx(coef0s,0.0d0)\n\t\t\tcoef(2:lmax+1) = coefs(2:lmax+1)/2.0d0\n\t\t\n\t\t\tif (present(sampling)) then\n\t\t\t\tif (sampling == 2) then\n\t\t\t\t\tcoef(lmax+2:2*lmax+3) = dcmplx(0.0d0,0.0d0)\t\n\t\t\t\tendif\n\t\t\tendif\n \t\n \t\tcall dfftw_execute(plan)\t! take fourier transform\n \t\tgriddh(i_s,1:nlong) = grid(1:nlong)\n \tendif\n\t\t\t\n\tenddo\n\t\n\t! Finally, do equator\n\t\n\tz = 0.0d0\n\tu = 1.0d0\n\n\tcoef(1:lmax+1) = dcmplx(0.0d0,0.0d0)\n\tcoef0 = 0.0d0\n\t\n\tselect case(lnorm)\n\t\tcase(1,2,3);\tpm2 = 1.0d0\n\t\tcase(4);\tpm2 = 1.0d0 / sqrt(4.0d0*pi)\n\tend select\n\t\n\tcoef0 = coef0 + cilm(1,1,1) * pm2\n\t\t\t\t\n\tk = 2\n\t\t\t\t\n\tdo l=2, lmax_comp, 2\n\t\tl1 = l+1\n\t\tk = k+l\n\t\tp = - f2(k) * pm2\n\t\tpm2 = p\n\t\tcoef0 = coef0 + cilm(1,l1,1) * p\n\t\tk = k + l + 1\n\tenddo\n\t\t\t\t\n\tselect case(lnorm)\n\t\tcase(1,2);\tpmm = sqr(2) * scalef\n\t\tcase(3);\tpmm = scalef\n\t\tcase(4);\tpmm = sqr(2) * scalef / sqrt(4.0d0*pi)\n\tend select\n\t\t\t\t\n\trescalem = 1.0d0/scalef\n\tkstart = 1\n\t\t\t\n\tdo m = 1, lmax_comp-1, 1\n\t\t\t\t\n\t\tm1 = m + 1\n\t\tkstart = kstart+m+1\n\t\t\t\t\t\n\t\tselect case(lnorm)\n\t\t\tcase(1,4)\n\t\t\t\tpmm = phase * pmm * sqr(2*m+1) / sqr(2*m)\n\t\t\t\tpm2 = pmm\n\t\t\tcase(2)\n\t\t\t\tpmm = phase * pmm * sqr(2*m+1) / sqr(2*m)\n\t\t\t\tpm2 = pmm / sqr(2*m+1)\n\t\t\tcase(3)\n\t\t\t\tpmm = phase * pmm * dble(2*m-1)\n\t\t\t\tpm2 = pmm\n\t\tend select\n\t\t\t\t\t\n\t\tcoef(m1) = coef(m1) + dcmplx(cilm(1,m1,m1), &\n\t\t\t\t- cilm(2,m1,m1)) * pm2\n\t\t\t\t\t\n\t\tk = kstart+m+1 \n\t \t\t\t\t\n\t\tdo l = m+2, lmax_comp, 2\n\t\t\tl1 = l+1\n\t\t\tk = k + l\n\t\t\tp = - f2(k) * pm2\n\t\t\tcoef(m1) = coef(m1) + dcmplx(cilm(1,l1,m1), &\n\t\t\t\t- cilm(2,l1,m1)) * p\n\t\t\tpm2 = p\n \tk = k + l + 1\n\t\tenddo\n\t\t\t\t\t\n\tenddo\t\t\t\n\t\t\t\t\n select case(lnorm)\n \tcase(1,4);\tpmm = phase * pmm * sqr(2*lmax_comp+1) / sqr(2*lmax_comp)\n \tcase(2);\tpmm = phase * pmm / sqr(2*lmax_comp)\n \tcase(3);\tpmm = phase * pmm * dble(2*lmax_comp-1)\n end select\n \t\t\t\n coef(lmax_comp+1) = coef(lmax_comp+1) + dcmplx(cilm(1,lmax_comp+1,lmax_comp+1), &\n\t\t\t\t- cilm(2,lmax_comp+1,lmax_comp+1)) * pmm\n\t\t\n\tcoef(1) = dcmplx(coef0,0.0d0)\n\tcoef(2:lmax+1) = coef(2:lmax+1) * rescalem /2.0d0\n\t\n\tif (present(sampling)) then\n\t\tif (sampling == 2) then\n\t\t\tcoef(lmax+2:2*lmax+3) = dcmplx(0.0d0,0.0d0)\t\n\t\tendif\n\tendif\n\t\n call dfftw_execute(plan)\t! take fourier transform\n \n\tgriddh(i_eq,1:nlong) = grid(1:nlong)\n\n\tcall dfftw_destroy_plan(plan)\n\t\t\t\t\nend subroutine MakeGridDH\n\n", "meta": {"hexsha": "2506bc381655d97a4e7d61fd65520ece176a3673", "size": 17000, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "spherical_splines/SHTOOLS/src/MakeGridDH.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/MakeGridDH.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/MakeGridDH.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": 28.5714285714, "max_line_length": 103, "alphanum_fraction": 0.5382941176, "num_tokens": 6413, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505325302034, "lm_q2_score": 0.731058584489497, "lm_q1q2_score": 0.6613525377692002}} {"text": "C Copyright (C) 2007: Leslie Greengard\r\nC Contact: greengard@cims.nyu.edu\r\nC\r\nC All rights reserved.\r\nC This copy is not for distribution without permission of the author.\r\nC\r\nC**********************************************************************C\r\n subroutine spheresolver(nsphere,nterms,nquad,nn1,nn,x0y0z0,\r\n 1 sphererads,scale,zk0,zk,beta0,delta0,beta,delta,\r\n 1 multfmm3dt,rhs,rhs2,rhsjoin,eps,numit,sol,\r\n 1 niter,errs,ngmrec,cw,www,lcw,ierr)\r\nc\r\nc See Notes for a discussion of mathematical approach.\r\nc \r\nc Step 1: create rhs for linear system by combining the \r\nc jump condition data in rhs and rhs2 into a single vector.\r\nc\r\nc INPUT:\r\nc \r\nc nsphere = number of spheres\r\nc nterms = order of expansions (currently the same for all\r\nc spheres)\r\nc nquad = number of quadrature nodes used in projection\r\nc 2*nterms is generally sufficient.\r\nc nn1 = number of unknowns associated with a single sphere\r\nc nn = total number of unknowns \r\nc x0y0z0 = sphere centers\r\nc sphererads = sphere radii\r\nc scale = scale parameters for each sphere\r\nc zk0 = exterior Helmholtz coefficient\r\nc zk = vector of interior Helmholtz coefficients for\r\nc all spheres\r\nc beta0, delta0 = material coefficients for exterior region.\r\nc beta, delta = material coefficients for interior regions.\r\nc\r\nc [beta phi] = rhs\r\nc [delta phi_n] = rhs2\r\nc\r\nc multfmm3dt = user-supplied subroutine to carry out matrix-vector\r\nc products\r\nc rhs = first jump condition [beta phi]\r\nc rhs2 = second jump condition [delta phi_n]\r\nc eps = tolerance for GMRES scheme.\r\nc numit = maximum number of iterations allowed for GMRES.\r\nc ngmrec = maximum number of iterations before restarting GMRES.\r\nc cw = workspace\r\nc www = second workspace\r\nc lcw = length of BOTH workspaces.\r\nc\r\nc OUTPUT:\r\nc\r\nc rhsjoin = right-hand side for scattering solver - a linear \r\nc combination of rhs and rhs2.\r\nc\r\nc------------------------------------------------------- \r\nc sol = solution vector.\r\nc\r\nc i.e. compact (unrolled) H-expansion coefficients\r\nc for spheres 1,2,...,nsphere\r\nc------------------------------------------------------- \r\nc\r\nc niter = number of iterations used.\r\nc errs = errors at each iteration.\r\nc ierr = error return code, not fully implemented\r\nc\r\nc\r\n implicit none\r\n integer *4 lcw,nterms,nsphere,nn,nn1,ier,ierr\r\n integer *4 numit,ngmrec,iflag,lw,niter,i,iffld,lused\r\n integer *4 nquad,nsp,ltemp,ifder,ntop,next,j,k\r\n real *8 sphererads(nsphere)\r\n real *8 x0y0z0(3,nsphere)\r\n complex *16 zk(nsphere)\r\n complex *16 beta(nsphere),delta(nsphere)\r\nc\r\n complex *16 sol(nn)\r\n complex *16 rhs(nn),rhs2(nn),rhsjoin(nn)\r\n complex *16 beta0,delta0,zk0,z\r\n complex *16 cw(lcw),eye\r\n complex *16 www(lcw),hout\r\n real *8 targ(3),scale(nsphere),eps\r\n real *8 errs(1000)\r\n external multfmm3dt\r\n data eye/(0.0d0,1.0d0)/\r\nc\r\n ierr = 0\r\nc\r\nc Combine f and g according to formula to construct\r\nc right-hand side for integral equation and store in vector\r\nc rhs.\r\nc\r\n do nsp = 1,nsphere\r\n z = zk(nsp)*sphererads(nsp)\r\n ltemp = (lcw-2)/3\r\n ifder = 1\r\n call jfuns3d(ier,nterms,z,scale(nsp),cw(1),ifder,\r\n 1 cw(ltemp+1),ltemp,cw(2*ltemp+1),ntop)\r\n next = (nsp-1)*nn1+1\r\n do j = 0,nterms\r\n do k = -j,j\r\n hout = beta(nsp)*cw(j+1)*rhs2(next) -\r\n 1 delta(nsp)*zk(nsp)*cw(ltemp+1+j)*rhs(next)\r\n rhsjoin(next) = hout\r\n\t next = next+1\r\n enddo\r\n enddo\r\n enddo\r\nc\r\nc now solve iteratively using GMRES with input parameters.\r\nc\r\n iflag = 0\r\n call diagprec3dt(rhsjoin,nsphere,nterms,x0y0z0,sphererads,\r\n 1 scale,zk0,zk,beta0,delta0,beta,delta,cw,lw,iflag)\r\nccc call prin2('after diagprec, rhs=*',rhs,2*nn)\r\n call multini3dt(nsphere,nterms,nquad,x0y0z0,sphererads,\r\n 1 scale,zk0,zk,beta0,delta0,beta,delta,ier)\r\n call cgmrespc(ier,nn,multfmm3dt,rhsjoin,eps,numit,sol,\r\n 1 niter,errs,ngmrec,cw,www,lcw)\r\nccc call prin2(' errs is *',errs,niter)\r\n return\r\n end\r\n", "meta": {"hexsha": "5aac96949a03b566f1050f3218e60a7c5d006caa", "size": 4616, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "scratchspace/SphereScat/spheresolver.f", "max_stars_repo_name": "flatironinstitute/maxwell-slice", "max_stars_repo_head_hexsha": "5941ca10098070f7df7f44cf662174c598a7521c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-23T01:11:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-23T01:11:18.000Z", "max_issues_repo_path": "scratchspace/SphereScat/spheresolver.f", "max_issues_repo_name": "flatironinstitute/maxwell-slice", "max_issues_repo_head_hexsha": "5941ca10098070f7df7f44cf662174c598a7521c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2021-01-04T18:30:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-09T19:30:51.000Z", "max_forks_repo_path": "scratchspace/SphereScat/spheresolver.f", "max_forks_repo_name": "flatironinstitute/maxwell-slice", "max_forks_repo_head_hexsha": "5941ca10098070f7df7f44cf662174c598a7521c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-09-23T01:11:19.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-23T01:11:19.000Z", "avg_line_length": 37.8360655738, "max_line_length": 75, "alphanum_fraction": 0.5654246101, "num_tokens": 1347, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505428129515, "lm_q2_score": 0.7310585727705126, "lm_q1q2_score": 0.6613525346849058}} {"text": " DOUBLE PRECISION FUNCTION DMPVAL (P, NDEG, X)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nC>> 1994-10-20 DMPVAL Krogh Changes to use M77CON\nC>> 1994-04-20 DMPVAL CLL Making DP and SP versions similar.\nC>> 1987-12-09 DMPVAL Lawson Initial code.\nC Evaluation of polynomial using monomial basis and a\nc linear transformation of the argument.\nC C.L.LAWSON, JPL, 1974 NOV 19\nc ------------------------------------------------------------------\nc--D replaces \"?\": ?MPVAL\nc ------------------------------------------------------------------\n integer j, ndeg\n double precision p(*), x, u\nc ------------------------------------------------------------------\n DMPVAL=0.0d0\n u=(x-p(1))/p(2)\n do 20 j = ndeg, 0, -1\n DMPVAL=DMPVAL*u + p(j+3)\n 20 continue\n end\n", "meta": {"hexsha": "8becb986c6276bed1c9b05c70e61b6abb0fd173f", "size": 923, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/dmpval.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/dmpval.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/dmpval.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": 40.1304347826, "max_line_length": 72, "alphanum_fraction": 0.5124593716, "num_tokens": 248, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008906, "lm_q2_score": 0.7310585727705127, "lm_q1q2_score": 0.6613525290469376}} {"text": "c # ---------------------------------------------------\nc # Trace back solution to initial position \nc # Input arguments should be the coordinates\nc # for the canonical swirl mapping in terms of \nc # (x,y)\nc # \nc # T = (R*cos(2*pi*x), R*sin(2*pi*x), r*sin(2*pi*y))\nc #\nc # r = alpha*(1 + beta*sin(2*pi*x))\nc # R = 1 + r*cos(2*pi*y)\nc # \nc # The solution proceeds in two steps. If we are\nc # solving an incompressible problem, we only need\nc # to evolve (x(t), y(t)). If we have a compressible\nc # problem, we first evolve (x(t),y(t)) back to a starting\nc # location (x0,y0), and then evolve x, y and q from \nc # the starting location back to final position.\nc # --------------------------------------------------------\n\n double precision function qexact(x,y,tfinal)\n implicit none\n\n external map_rhs_divfree, map_rhs_nondivfree\n external solout\n\n integer mapping\n common /mapping_comm/ mapping\n\n integer example\n common /example_comm/ example\n\n double precision x,y,tfinal\n integer blockno\n\n double precision xc0, yc0\nc double precision xc1, yc1\n\nc integer blockno_dummy\n double precision t0\n double precision xp,yp,zp\n\n double precision sigma(3), rtol, atol\n integer itol, iout\n\n integer Nmax, lwork,nrdens, liwork\n parameter(Nmax=3, nrdens=0)\n parameter(lwork=8*Nmax+5*nrdens+21)\n parameter(liwork=nrdens+21)\n\n double precision work(lwork), rpar\n double precision q0_physical, q0\n integer iwork(liwork), ipar(2), idid\n\n double precision tol\n\n logical evolve_q\n\n integer*8 cont, get_context\n\n integer i\n\n cont = get_context()\n\nc # ------------------------------------------\nc # Numerical parameters\nc # ------------------------------------------\n itol = 0\n rtol = 1.d-12\n atol = 1.d-12\n iout = 0\n\n do i = 1,20\n work(i) = 0\n iwork(i) = 0\n enddo\n\n\nc # Evolve from t=t0 to t=tfinal\n t0 = 0\n\nc # Initial conditions for ODE\n sigma(1) = x\n sigma(2) = y\n\n\nc # This traces the velocity field back to the origin.\n call dopri5(2,map_rhs_divfree,t0,sigma,tfinal,\n & rtol,atol,itol,\n & solout,iout, work,lwork,iwork,liwork,\n & rpar,ipar,idid)\n\n if (idid .ne. 1) then\n write(6,*) 'DOPRI5 : idid .ne. 1'\n stop\n endif\n\nc # Initial position traced back from (xc1,yc1)\n xc0 = sigma(1)\n yc0 = sigma(2)\n\nc # Our physical domain is a unit square, which is the same\nc # as our computational domain\n xp = xc0\n yp = yc0\n zp = 0\n\n q0 = q0_physical(xp,yp,zp)\n \nc # Evolve q along characteristics for variable coefficient case \n if (example .eq. 0) then\n evolve_q = .false.\n else\n evolve_q = .true.\n endif\n if (evolve_q) then\nc # Variable coefficient case \nc # We now need to evolve q along with (x,y), starting from\nc # from (xc0,yc0)\n sigma(1) = xc0\n sigma(2) = yc0\n sigma(3) = q0\n\n do i = 1,20\n work(i) = 0\n iwork(i) = 0\n enddo\n\n t0 = 0\n call dopri5(3,map_rhs_nondivfree,t0,sigma,tfinal,\n & rtol,atol,itol,\n & solout,iout, work,lwork,iwork,liwork,\n & rpar,ipar,idid)\n\n if (idid .ne. 1) then\n write(6,*) 'DOPRI5 : idid .ne. 1'\n stop\n endif\n\n tol = 1e-8\n if (abs(sigma(1)-x) .gt. tol) then\n write(6,*) 'qexact.f : Did not evolve x correctly'\n write(6,100) xc0,yc0\n write(6,100) x,y\n write(6,100) sigma(1), sigma(2)\n write(6,105) abs(x-sigma(1)), abs(y-sigma(2))\n stop\n endif\n if (abs(sigma(2)-y) .gt. tol) then\n write(6,*) 'qexact.f : Did not evolve y correctly'\n write(6,100) xc0,yc0\n write(6,100) x,y\n write(6,100) sigma(1), sigma(2)\n write(6,105) abs(x-sigma(1)), abs(y-sigma(2))\n stop\n endif\n100 format(2F24.16)\n105 format(2E24.4) \n\n qexact = sigma(3)\n else\n qexact = q0\n endif\n\n end\n\nc # --------------------------------------------------------------- \n subroutine solout(nr,xold,x,y,n,con,icomp,nd,rpar,ipar,irtrn)\n dimension y(n),con(5*nd),icomp(nd)\n\nc # Dummy routine\n\n end\n\n\nc # ----------------------------------------------------------------\nc # RHS functions for ODE solver DOPRI5 (original ode45)\nc # -- divfree field\nc # -- field with divergence\nc # ----------------------------------------------------------------\n\n subroutine map_rhs_divfree(n,t,sigma,f,rpar,ipar)\n implicit none\n\n external velocity_components\n integer n, ipar(2)\n double precision t, sigma(n), f(n), rpar\n\n\n integer m, i\n double precision xc1,yc1, q, u1,u2, x,y\n double precision p, px, py\n double precision t1(3), t2(3), t1xt2(3), w\n double precision u(2)\n\n x = sigma(1)\n y = sigma(2)\n\n\n call velocity_components(x,y,u)\n\nc # We are tracing these back, so use negative velocities \n f(1) = -u(1)\n f(2) = -u(2)\n\n end\n\n subroutine map_rhs_nondivfree(n,t,sigma,f,rpar,ipar)\n implicit none\n\n integer n, ipar(2)\n double precision t, sigma(n), f(n), rpar\n\n\n double precision x,y, q\n double precision u(2)\n double precision divu, map_divergence\n\n double precision t1(3), t2(3), t1xt2(3), w\n double precision p,px,py\n\nc # Track evolution of these three quantities\n\n x = sigma(1)\n y = sigma(2)\n q = sigma(3)\n\n call velocity_components(x,y,u)\n\n divu = map_divergence(x,y)\n\n f(1) = u(1)\n f(2) = u(2)\n f(3) = -divu*q !! Non-conservative case\n\n end\n\n\n\n", "meta": {"hexsha": "3e159cf2ff2753916c3c7b48e7bd07609150fc25", "size": 6129, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "applications/clawpack/transport/2d/square/qexact.f", "max_stars_repo_name": "jbsnively/forestclaw", "max_stars_repo_head_hexsha": "6ab96f3b7c83b0f2928df54d1212249f2c98bdc5", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "applications/clawpack/transport/2d/square/qexact.f", "max_issues_repo_name": "jbsnively/forestclaw", "max_issues_repo_head_hexsha": "6ab96f3b7c83b0f2928df54d1212249f2c98bdc5", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "applications/clawpack/transport/2d/square/qexact.f", "max_forks_repo_name": "jbsnively/forestclaw", "max_forks_repo_head_hexsha": "6ab96f3b7c83b0f2928df54d1212249f2c98bdc5", "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.6443514644, "max_line_length": 77, "alphanum_fraction": 0.5008973731, "num_tokens": 1769, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008906, "lm_q2_score": 0.7310585727705126, "lm_q1q2_score": 0.6613525290469375}} {"text": "\n\ninteger grid,gridz\n\nreal*4,allocatable :: rho(:,:,:)\n\ndouble precision ss,ss2,totval\n\ncharacter*80 filename\n\nprint*, ' Input densfield'\n\nread (*,'(A)') filename\n\nopen(1,file=filename, form='unformatted',status='old')\n\nread (1) grid,grid, gridz\n\nallocate(rho(grid,grid,gridz))\n\n\n do kk=1,gridz\n read(1) ((RHO(II,JJ,KK), ii=1,GRID),jj=1,GRID)\n enddo\n\nclose(1)\n\n\nss=0.\n\n!$OMP PARALLEL DO DEFAULT (SHARED) PRIVATE(I,J,K) REDUCTION(+:ss)\ndo K=1,grid\n do J=1,grid\n do I=1,grid\n ss = ss + rho(i,j,k)\n enddo\n enddo\nenddo\n\ntotval = float(grid)**3\n\nss = ss / totval\n\nprint*, ' Mean valuel=', ss\n\nss2=0.\n\n!$OMP PARALLEL DO DEFAULT (SHARED) PRIVATE(I,J,K) REDUCTION(+:ss2)\ndo K=1,grid\n do J=1,grid\n do I=1,grid\n ss2 = (ss-rho(i,j,k))**2 + ss2\n enddo\n enddo\nenddo\n\nprint*, ' Min-Max values ', Minval(rho), Maxval(rho)\n\n\n\nss2 = sqrt(ss2) / totval\n\nprint*, ' RMS=', ss2\n\nstop\nend\n\n\n\n", "meta": {"hexsha": "f9b01e1e18373369700f782ba1055137daf53156", "size": 921, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "bin/bin_MD/check_densfields.f90", "max_stars_repo_name": "JohanComparat/nbody-npt-functions", "max_stars_repo_head_hexsha": "a034db4e5a9b2f87dc42eeb6059c4dd280589e4a", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2017-11-07T02:15:46.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-03T01:35:53.000Z", "max_issues_repo_path": "bin/bin_MD/check_densfields.f90", "max_issues_repo_name": "JohanComparat/nbody-npt-functions", "max_issues_repo_head_hexsha": "a034db4e5a9b2f87dc42eeb6059c4dd280589e4a", "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": "bin/bin_MD/check_densfields.f90", "max_forks_repo_name": "JohanComparat/nbody-npt-functions", "max_forks_repo_head_hexsha": "a034db4e5a9b2f87dc42eeb6059c4dd280589e4a", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-08-12T14:26:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-14T06:08:58.000Z", "avg_line_length": 13.1571428571, "max_line_length": 66, "alphanum_fraction": 0.6091205212, "num_tokens": 348, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430394931457, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.661305697724723}} {"text": "! { dg-do run }\n! { dg-options \"-ffrontend-optimize -fdump-tree-optimized -Wrealloc-lhs\" }\n! PR 37131 - check basic functionality of inlined matmul, making\n! sure that the library is not called, with and without reallocation.\n\nprogram main\n implicit none\n integer, parameter :: offset = -2\n real, dimension(3,2) :: a\n real, dimension(2,4) :: b\n real, dimension(3,4) :: c\n real, dimension(3,4) :: cres\n real, dimension(:,:), allocatable :: c_alloc\n integer, parameter :: a1_lower_p = 1 + offset, a1_upper_p = size(a,1) + offset\n integer, parameter :: a2_lower_p = 1 + offset, a2_upper_p = size(a,2) + offset\n integer, parameter :: b1_lower_p = 1 + offset, b1_upper_p = size(b,1) + offset\n integer, parameter :: b2_lower_p = 1 + offset, b2_upper_p = size(b,2) + offset\n integer, parameter :: c1_lower_p = 1 + offset, c1_upper_p = size(c,1) + offset\n integer, parameter :: c2_lower_p = 1 + offset, c2_upper_p = size(c,2) + offset\n real, dimension(a1_lower_p:a1_upper_p, a2_lower_p:a2_upper_p) :: ap\n real, dimension(b1_lower_p:b1_upper_p, b2_lower_p:b2_upper_p) :: bp\n real, dimension(c1_lower_p:c1_upper_p, c2_lower_p:c2_upper_p) :: cp\n real, dimension(4,8,4) :: f, fresult\n integer :: eight = 8, two = 2\n\n type foo\n real :: a\n integer :: i\n end type foo\n\n type(foo), dimension(3,2) :: afoo\n type(foo), dimension(2,4) :: bfoo\n type(foo), dimension(3,4) :: cfoo\n\n data a / 2., -3., 5., -7., 11., -13./\n data b /17., -23., 29., -31., 37., -39., 41., -47./\n data cres /195., -304., 384., 275., -428., 548., 347., -540., 692., 411., -640., 816./\n data fresult / &\n 0., 0., 195., 0., 0., 17., 0., 0., 0., -23.,-304., 0., 0., 0., 0., 0., &\n 0., 0., 384., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., &\n 2., 0., 275., 0., -3., 29., 0., 0., 5., -31.,-428., 0., 0., 0., 0., 0., &\n 0., 0., 548., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., &\n -7., 0., 347., 0., 11., 37., 0., 0., -13., -39.,-540., 0., 0., 0., 0., 0., &\n 0., 0., 692., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., &\n 0., 0., 411., 0., 0., 41., 0., 0., 0., -47.,-640., 0., 0., 0., 0., 0., &\n 0., 0., 816., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0./\n\n integer :: a1 = size(a,1), a2 = size(a,2)\n integer :: b1 = size(b,1), b2 = size(b,2)\n integer :: c1 = size(c,1), c2 = size(c,2)\n\n integer :: a1_lower, a1_upper, a2_lower, a2_upper\n integer :: b1_lower, b1_upper, b2_lower, b2_upper\n integer :: c1_lower, c1_upper, c2_lower, c2_upper\n\n a1_lower = 1 + offset ; a1_upper = a1 + offset\n a2_lower = 1 + offset ; a2_upper = a2 + offset\n b1_lower = 1 + offset ; b1_upper = b1 + offset\n b2_lower = 1 + offset ; b2_upper = b2 + offset\n c1_lower = 1 + offset ; c1_upper = c1 + offset\n c2_lower = 1 + offset ; c2_upper = c2 + offset\n\n c = matmul(a,b)\n if (sum(abs(c-cres))>1e-4) call abort\n\n c_alloc = matmul(a,b) ! { dg-warning \"Code for reallocating the allocatable array\" }\n if (sum(abs(c_alloc-cres))>1e-4) call abort\n if (any([size(c_alloc,1), size(c_alloc,2)] /= [3,4])) call abort\n deallocate(c_alloc)\n\n allocate(c_alloc(4,4))\n c_alloc = matmul(a,b) ! { dg-warning \"Code for reallocating the allocatable array\" }\n if (sum(abs(c_alloc-cres))>1e-4) call abort\n if (any([size(c_alloc,1), size(c_alloc,2)] /= [3,4])) call abort\n deallocate(c_alloc)\n\n allocate(c_alloc(3,3))\n c_alloc = matmul(a,b) ! { dg-warning \"Code for reallocating the allocatable array\" }\n if (sum(abs(c_alloc-cres))>1e-4) call abort\n if (any([size(c_alloc,1), size(c_alloc,2)] /= [3,4])) call abort\n\n c_alloc = 42.\n c_alloc(:,:) = matmul(a,b)\n if (sum(abs(c_alloc-cres))>1e-4) call abort\n if (any([size(c_alloc,1), size(c_alloc,2)] /= [3,4])) call abort\n\n deallocate(c_alloc)\n \n ap = a\n bp = b\n cp = matmul(ap, bp)\n if (sum(abs(cp-cres)) > 1e-4) call abort\n\n f = 0\n f(1,1:3,2:3) = a\n f(2,2:3,:) = b\n c = matmul(f(1,1:3,2:3), f(2,2:3,:))\n if (sum(abs(c-cres))>1e-4) call abort\n\n f(3,1:eight:2,:) = matmul(a, b)\n if (sum(abs(f(3,1:eight:2,:)-cres))>1e-4) call abort\n\n afoo%a = a\n bfoo%a = b\n cfoo%a = matmul(afoo%a, bfoo%a)\n\n if (sum(abs(cfoo%a-cres)) > 1e-4) call abort\n\n block\n real :: aa(a1, a2), bb(b1, b2), cc(c1, c2)\n real :: am(a1_lower:a1_upper, a2_lower:a2_upper)\n real :: bm(b1_lower:b1_upper, b2_lower:b2_upper)\n real :: cm(c1_lower:c1_upper, c2_lower:c2_upper)\n\n aa = a\n bb = b\n am = a\n bm = b\n\n cc = matmul(aa,bb)\n if (sum(cc-cres)>1e-4) call abort\n c_alloc = matmul(aa,bb) ! { dg-warning \"Code for reallocating the allocatable array\" }\n if (sum(abs(c_alloc-cres))>1e-4) call abort\n if (any([size(c_alloc,1), size(c_alloc,2)] /= [3,4])) call abort\n c_alloc = 42.\n deallocate(c_alloc)\n\n allocate(c_alloc(4,4))\n c_alloc = matmul(aa,bb) ! { dg-warning \"Code for reallocating the allocatable array\" }\n if (sum(abs(c_alloc-cres))>1e-4) call abort\n if (any([size(c_alloc,1), size(c_alloc,2)] /= [3,4])) call abort\n deallocate(c_alloc)\n\n allocate(c_alloc(3,3))\n c_alloc = matmul(aa,bb) ! { dg-warning \"Code for reallocating the allocatable array\" }\n if (sum(abs(c_alloc-cres))>1e-4) call abort\n if (any([size(c_alloc,1), size(c_alloc,2)] /= [3,4])) call abort\n deallocate(c_alloc)\n\n cm = matmul(am, bm)\n if (sum(abs(cm-cres)) > 1e-4) call abort\n\n cm = 42.\n\n cm(:,:) = matmul(a,bm)\n if (sum(abs(cm-cres)) > 1e-4) call abort\n\n end block\n\nend program main\n\n! { dg-final { scan-tree-dump-times \"_gfortran_matmul\" 0 \"optimized\" } }\n", "meta": {"hexsha": "c3177d72361556fba3ebc104e9fa7164cd4dd8c2", "size": 5701, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.dg/inline_matmul_1.f90", "max_stars_repo_name": "best08618/asylo", "max_stars_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-05-02T17:34:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-17T10:15:18.000Z", "max_issues_repo_path": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.dg/inline_matmul_1.f90", "max_issues_repo_name": "best08618/asylo", "max_issues_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "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": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.dg/inline_matmul_1.f90", "max_forks_repo_name": "best08618/asylo", "max_forks_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-27T00:22:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-01T09:41:02.000Z", "avg_line_length": 37.2614379085, "max_line_length": 98, "alphanum_fraction": 0.5665672689, "num_tokens": 2343, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430394931456, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.661305693697462}} {"text": "PROGRAM AVRAGE\n ! This program reads in three numbers and Sums \n ! and average them. \n ! with :: we can assign variable while declaring \n IMPLICIT NONE\n REAL :: Num1, Num2, NUM3, Average, Total = 0.0\n INTEGER :: N = 3\n PRINT *, \"Type three numbers\"\n READ *, Num1, Num2, NUM3\n Total = Num1 + Num2 + NUM3\n Average = Total / N\n PRINT *, \"Total OF NUMBERS IS = \", Total\n PRINT *, \" AVERAGE IS = \", Average\nEND", "meta": {"hexsha": "72c78db1e0fb1951b63cc43f05f955ff9d736e47", "size": 442, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Learning FORTRAN Concepts/2.f90", "max_stars_repo_name": "arpitkekri/Code_With_FORTRAN", "max_stars_repo_head_hexsha": "fb731e6f8d8a47cfe38896fffd74a55d17efb2e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-02-21T05:24:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-27T10:25:24.000Z", "max_issues_repo_path": "Learning FORTRAN Concepts/2.f90", "max_issues_repo_name": "akhil18soni/Code_With_FORTRAN", "max_issues_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Learning FORTRAN Concepts/2.f90", "max_forks_repo_name": "akhil18soni/Code_With_FORTRAN", "max_forks_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-02-27T12:14:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T23:30:55.000Z", "avg_line_length": 31.5714285714, "max_line_length": 53, "alphanum_fraction": 0.6085972851, "num_tokens": 133, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581000631542, "lm_q2_score": 0.8311430415844384, "lm_q1q2_score": 0.6613056933477854}} {"text": "! { dg-do run }\n!\n! PR fortran/34404\n!\n! Contributed by Joost VandeVondele.\n!\nimplicit none\ncomplex :: x\ncharacter(len=80) :: t=\"(1.0E-7,4.0E-3)\"\nread(t,*) x\nif (real(x) /= 1.0e-7 .or. aimag(x)/=4.0e-3) call abort()\nEND\n", "meta": {"hexsha": "d12dcef71ebb4296a2992a8c4689b8e110cfca8d", "size": 220, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/read_2.f90", "max_stars_repo_name": "maurizioabba/rose", "max_stars_repo_head_hexsha": "7597292cf14da292bdb9a4ef573001b6c5b9b6c0", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/read_2.f90", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/read_2.f90", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 16.9230769231, "max_line_length": 57, "alphanum_fraction": 0.6136363636, "num_tokens": 97, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8311430311279742, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.6613056810007537}} {"text": "program integration4\n\n use usermodule2\n\n implicit none\n\n real(8) :: x, y, integ, init\n real(8), dimension(2) :: step\n real(8), dimension(4) :: boundary\n\n\n call loadinput('input.dat', init, boundary, step)\n\n integ = init\n\n y = boundary(3)\n\n do while (y <= boundary(4))\n\n x = boundary(1)\n\n do while (x <= boundary(2))\n\n integ = integ + userfunc(x, y)\n\n x = x + step(1)\n\n end do\n\n y = y + step(2)\n\n end do\n\n call writeoutput('integration4.dat', integ, boundary, x, y)\n\nend program integration4\n", "meta": {"hexsha": "92c9b3a38d7b6398100a3fc60e0f0679c666911a", "size": 532, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lectures1and2/example/integration4.f90", "max_stars_repo_name": "sdm900/fortran_course", "max_stars_repo_head_hexsha": "6f2db3fcc7b616b94c4e1fe8875a3158a01117b2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lectures1and2/example/integration4.f90", "max_issues_repo_name": "sdm900/fortran_course", "max_issues_repo_head_hexsha": "6f2db3fcc7b616b94c4e1fe8875a3158a01117b2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lectures1and2/example/integration4.f90", "max_forks_repo_name": "sdm900/fortran_course", "max_forks_repo_head_hexsha": "6f2db3fcc7b616b94c4e1fe8875a3158a01117b2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 14.3783783784, "max_line_length": 61, "alphanum_fraction": 0.5902255639, "num_tokens": 164, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.831143031127974, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.6613056810007536}} {"text": "! 2017, S.A. Sato, Modified the format of the code\n! ----------------------------------------------------------------------------\n! Numerical diagonalization of 3x3 matrcies\n! Copyright (C) 2006 Joachim Kopp\n! ----------------------------------------------------------------------------\n! This library is free software; you can redistribute it and/or\n! modify it under the terms of the GNU Lesser General Public\n! License as published by the Free Software Foundation; either\n! version 2.1 of the License, or (at your option) any later version.\n!\n! This library is distributed in the hope that it will be useful,\n! but WITHOUT ANY WARRANTY; without even the implied warranty of\n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n! Lesser General Public License for more details.\n!\n! You should have received a copy of the GNU Lesser General Public\n! License along with this library; if not, write to the Free Software\n! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n! ----------------------------------------------------------------------------\n\n\n! ----------------------------------------------------------------------------\n SUBROUTINE ZHEEVC3(A, W)\n! ----------------------------------------------------------------------------\n! Calculates the eigenvalues of a hermitian 3x3 matrix A using Cardano's\n! analytical algorithm.\n! Only the diagonal and upper triangular parts of A are accessed. The access\n! is read-only.\n! ----------------------------------------------------------------------------\n! Parameters:\n! A: The hermitian input matrix\n! W: Storage buffer for eigenvalues\n! ----------------------------------------------------------------------------\n! Dependencies:\n! SQRABS()\n! ---------------------------------------------------------------------------\n! .. Arguments ..\n COMPLEX(8) A(3,3)\n DOUBLE PRECISION W(3)\n\n! .. Parameters ..\n DOUBLE PRECISION SQRT3\n PARAMETER ( SQRT3 = 1.73205080756887729352744634151D0 )\n\n! .. Local Variables ..\n DOUBLE PRECISION M, C1, C0\n COMPLEX(8) DE\n DOUBLE PRECISION DD, EE, FF\n DOUBLE PRECISION P, SQRTP, Q, C, S, PHI\n \n! .. External Functions ..\n DOUBLE PRECISION SQRABS\n EXTERNAL SQRABS\n\n! Determine coefficients of characteristic poynomial. We write\n! | A D F |\n! A = | D* B E |\n! | F* E* C |\n DE = A(1,2) * A(2,3)\n DD = SQRABS(A(1,2))\n EE = SQRABS(A(2,3))\n FF = SQRABS(A(1,3))\n M = DREAL(A(1,1)) + DREAL(A(2,2)) + DREAL(A(3,3))\n C1 = ( DREAL(A(1,1)) * DREAL(A(2,2)) &\n + DREAL(A(1,1)) * DREAL(A(3,3)) &\n + DREAL(A(2,2)) * DREAL(A(3,3)) ) &\n - (DD + EE + FF)\n C0 = DREAL(A(3,3))*DD + DREAL(A(1,1))*EE + DREAL(A(2,2))*FF &\n - DREAL(A(1,1))*DREAL(A(2,2))*DREAL(A(3,3)) &\n - 2.0D0*(DREAL(A(1,3))*DREAL(DE)+DIMAG(A(1,3))*DIMAG(DE))\n\n P = M**2 - 3.0D0 * C1\n Q = M*(P - (3.0D0/2.0D0)*C1) - (27.0D0/2.0D0)*C0\n SQRTP = SQRT(ABS(P))\n\n PHI = 27.0D0 * ( 0.25D0 * C1**2 * (P - C1) &\n + C0 * (Q + (27.0D0/4.0D0)*C0) )\n PHI = (1.0D0/3.0D0) * ATAN2(SQRT(ABS(PHI)), Q)\n\n C = SQRTP * COS(PHI)\n S = (1.0D0/SQRT3) * SQRTP * SIN(PHI)\n\n W(2) = (1.0D0/3.0D0) * (M - C)\n W(3) = W(2) + S\n W(1) = W(2) + C\n W(2) = W(2) - S\n\n END SUBROUTINE\n! End of subroutine ZHEEVC3\n\n", "meta": {"hexsha": "d82ba1336c386b5dbba20b2d40fdd8e5307beb29", "size": 3472, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ext_lib/zheevh3-F-1.2/zheevc3.f90", "max_stars_repo_name": "shunsuke-sato/three_band_model_vcc", "max_stars_repo_head_hexsha": "80dd03cc8aa065a51fdd953ae21425ca7901ab97", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ext_lib/zheevh3-F-1.2/zheevc3.f90", "max_issues_repo_name": "shunsuke-sato/three_band_model_vcc", "max_issues_repo_head_hexsha": "80dd03cc8aa065a51fdd953ae21425ca7901ab97", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ext_lib/zheevh3-F-1.2/zheevc3.f90", "max_forks_repo_name": "shunsuke-sato/three_band_model_vcc", "max_forks_repo_head_hexsha": "80dd03cc8aa065a51fdd953ae21425ca7901ab97", "max_forks_repo_licenses": ["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.1538461538, "max_line_length": 78, "alphanum_fraction": 0.4726382488, "num_tokens": 1038, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094117351309, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.661204729054477}} {"text": " subroutine resid_betagd2(n_Lamx,n_beta,np1_Lamx,np1_beta,x,Nx,ck,e\n &psal,ht,myzero,phys_bdy,res)\n implicit none\n integer i\n integer Nx\n real*8 ck\n real*8 epsal\n real*8 ht\n real*8 myzero\n real*8 n_Lamx(Nx)\n real*8 n_beta(Nx)\n real*8 np1_Lamx(Nx)\n real*8 np1_beta(Nx)\n real*8 x(Nx)\n integer phys_bdy(2)\n real*8 res\n real*8 qb\n res = 0.0D0\n if (phys_bdy(1) .eq. 1) then\n do i=1, 1, 1\n qb = (-0.1D1 * n_beta(i) + np1_beta(i)) / ht + epsal * (-0.1D1 * n\n #_Lamx(i) + np1_Lamx(i)) / ht + 0.5000000000000000D0 * epsal * ck *\n # np1_Lamx(i) + 0.5000000000000000D0 * epsal * ck * n_Lamx(i)\n res = res + qb**2\n end do\n endif\n do i=2, Nx-1, 1\n qb = (-0.1D1 * n_beta(i) + np1_beta(i)) / ht + epsal * (-0.1D1 * n\n #_Lamx(i) + np1_Lamx(i)) / ht + 0.5000000000000000D0 * epsal * ck *\n # np1_Lamx(i) + 0.5000000000000000D0 * epsal * ck * n_Lamx(i)\n res = res + qb**2\n end do\n if (phys_bdy(2) .eq. 1) then\n do i=Nx, Nx, 1\n qb = np1_beta(i) + myzero * x(i)\n res = res + qb**2\n end do\n endif\n res = sqrt(res/(1*Nx))\n END\n", "meta": {"hexsha": "b2789b9d87c9b5b9d5a0c29f64e77668a48417c5", "size": 1199, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/FD/resid_betagd2.f", "max_stars_repo_name": "rmanak/bssn_spher", "max_stars_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/FD/resid_betagd2.f", "max_issues_repo_name": "rmanak/bssn_spher", "max_issues_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/FD/resid_betagd2.f", "max_forks_repo_name": "rmanak/bssn_spher", "max_forks_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.243902439, "max_line_length": 72, "alphanum_fraction": 0.5246038365, "num_tokens": 512, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094117351309, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.661204729054477}} {"text": " SUBROUTINE DOT(L,X,Y,P)\n DIMENSION X(1),Y(1) DOT40010\nC\nC DOT IS THE DOT PRODUCT OF TWO VECTORS\nC REFERENCE: EAR MULTICHANNEL VOLUME, P. 20.\nC DOT70040\nC INPUTS ARE DOT70070\nC L=LENGTH OF THE VECTORS X AND Y DOT70080\nC X=THE VECTOR X, X(1),X(2),...,X(L) DOT70090\nC Y=THE VECTOR Y Y(1),Y(2),...,Y(L) DOT70100\nC OUTPUTS ARE DOT70110\nC P=DOT PRODUCT OF X AND Y\nC\nC L DOT70160\nC COMPUTES P= SUM(X(I)*Y(I)) IF L GRTHN 0 DOT70170\nC I=1 DOT70180\nC DOT70190\nC P= 0 IF L EQLSTHN 0 DOT70200\nC DOT70210\n P=0.0 DOT70220\n IF (L)3,3,1 DOT70230\n 1 DO 2 I=1,L DOT70240\n 2 P=P+X(I)*Y(I) DOT70250\n 3 RETURN DOT70260\n END DOT70270\n", "meta": {"hexsha": "fd1590091482fbdbb76bab4c82d423e0d4ceb716", "size": 1700, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "dot.f", "max_stars_repo_name": "apthorpe/sioseis", "max_stars_repo_head_hexsha": "28965a8b4a5b3ffaf169588dd1a385a1f9c9ccce", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-12-21T12:46:47.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-22T14:17:08.000Z", "max_issues_repo_path": "dot.f", "max_issues_repo_name": "henkart/sioseis", "max_issues_repo_head_hexsha": "9a3d9d87eb6e9d7c8e754bc2a81eea51b30d4fa5", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 10, "max_issues_repo_issues_event_min_datetime": "2019-12-23T21:23:23.000Z", "max_issues_repo_issues_event_max_datetime": "2020-03-06T13:30:22.000Z", "max_forks_repo_path": "dot.f", "max_forks_repo_name": "henkart/sioseis", "max_forks_repo_head_hexsha": "9a3d9d87eb6e9d7c8e754bc2a81eea51b30d4fa5", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-01-16T19:48:54.000Z", "max_forks_repo_forks_event_max_datetime": "2020-01-24T02:35:07.000Z", "avg_line_length": 65.3846153846, "max_line_length": 80, "alphanum_fraction": 0.2535294118, "num_tokens": 318, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543488, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6612047146097526}} {"text": "program energy\n != unit :: speed = m/s\n\n != unit (m / s** (2)) :: gravity\n != unit (m) :: height\n != unit (kg) :: mass\n real, parameter :: mass = 3.00, gravity = 9.81, height = 4.20\n != unit (kg m** (2) / s** (2)) :: potential_energy\n real :: potential_energy\n\n != unit (1) :: half\n != unit (speed) :: velocity\n real, parameter :: half = 0.5, velocity = 4.00\n != unit (kg m** (2) / s** (2)) :: kinetic_energy\n != unit (kg m** (2) / s** (2)) :: total_energy\n real :: kinetic_energy, total_energy\n\n potential_energy = mass * gravity * height\n kinetic_energy = half * mass * square(velocity)\n\n total_energy = potential_energy + kinetic_energy\n\n contains\n\n real function square(x)\n real x\n square = x * x\n end function square\nend program energy\n", "meta": {"hexsha": "a6b51c8c22c141255ba95bc3a717a08501a2a40d", "size": 758, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "samples/units/dst-example/ex1.f90", "max_stars_repo_name": "raehik/camfort", "max_stars_repo_head_hexsha": "2f5ac9a478116ae8c7aa2a5e079b81aa58988e45", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 90, "max_stars_repo_stars_event_min_datetime": "2016-06-02T15:37:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-30T20:10:14.000Z", "max_issues_repo_path": "samples/units/dst-example/ex1.f90", "max_issues_repo_name": "apthorpe/camfort", "max_issues_repo_head_hexsha": "1e307ae972b2fe6f63af6d3b0a3d106eec77e8a8", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 124, "max_issues_repo_issues_event_min_datetime": "2016-05-25T13:21:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-10T14:26:03.000Z", "max_forks_repo_path": "samples/units/dst-example/ex1.f90", "max_forks_repo_name": "raehik/camfort", "max_forks_repo_head_hexsha": "2f5ac9a478116ae8c7aa2a5e079b81aa58988e45", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 16, "max_forks_repo_forks_event_min_datetime": "2016-06-02T14:51:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-14T15:59:33.000Z", "avg_line_length": 25.2666666667, "max_line_length": 63, "alphanum_fraction": 0.6068601583, "num_tokens": 235, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096181702032, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6611958986213289}} {"text": " SUBROUTINE svdcmp(A, M, N, MP, NP, W, V)\n USE stel_kinds\n IMPLICIT NONE\nC-----------------------------------------------\nC D u m m y A r g u m e n t s\nC-----------------------------------------------\n INTEGER :: M, N, MP, NP\n REAL(rprec), DIMENSION(MP,NP), INTENT(inout), TARGET :: A\n REAL(rprec), DIMENSION(MIN(MP,NP)) :: W\n REAL(rprec), DIMENSION(NP,NP) :: V\nC-----------------------------------------------\nC L o c a l P a r a m e t e r s\nC-----------------------------------------------\n REAL(rprec) :: ZERO = 0, ONE = 1, TWO = 2\nC-----------------------------------------------\nC L o c a l V a r i a b l e s\nC-----------------------------------------------\n INTEGER :: I, L, K, J, ITS, NM\n INTEGER :: M1, N1\n REAL(rprec), DIMENSION(MP*NP) :: RV1\n REAL(rprec), POINTER :: A1(:,:)\n REAL(rprec) :: G, SCALE, ANORM, S, F, H, C, Y, Z, X\n LOGICAL :: LTRANS\nC-----------------------------------------------\nC E x t e r n a l F u n c t i o n s\nC-----------------------------------------------\n REAL(rprec) , EXTERNAL :: PYTHAG\nC-----------------------------------------------\n!\n! COMPUTES THE SVD DECOMPOSITION OF THE MATRIX A SUCH\n! THAT A = U * W * VT, WHERE U=A ON OUTPUT. W IS A DIAGONAL\n! MATRIX OF SINGULAR VALUES.\n!\n! TAKEN FROM NUMERICAL RECIPES. GENERALIZED BY SPH TO ACCEPT M < N CASE,\n! BY ANALYZING TRANSPOSE AND SWITCHING U,V AT END\n!\n IF (M .GT. MP) STOP 'M > MP IN SVDCMP'\n IF (N .GT. NP) STOP 'N > NP IN SVDCMP'\n! IF (M .LT. N) STOP 'M < N IN SVDCMP'\n LTRANS = (M .LT. N)\n IF (LTRANS) THEN\n M1 = N; N1 = M\n ALLOCATE (A1(M1,N1))\n A1 = TRANSPOSE(A)\n ELSE\n M1 = M; N1 = N\n A1 => A\n END IF\n\n! 1. Householder reduction to bidiagonal form\n\n G = zero\n SCALE = zero\n ANORM = zero\n DO I = 1, N1\n L = I + 1\n RV1(I) = SCALE*G\n G = zero\n S = zero\n SCALE = zero\n IF (I .le. M1) THEN\n SCALE = SUM(ABS(A1(I:M1,I)))\n IF (SCALE .ne. zero) THEN\n A1(I:M1,I) = A1(I:M1,I)/SCALE\n S = SUM(A1(I:M1,I)*A1(I:M1,I))\n F = A1(I,I)\n G = -SIGN(SQRT(S),F)\n H = F*G - S\n A1(I,I) = F - G\n IF (I .ne. N1) THEN\n DO J = L, N1\n S = SUM(A1(I:M1,I)*A1(I:M1,J))\n F = S/H\n A1(I:M1,J) = A1(I:M1,J) + F*A1(I:M1,I)\n END DO\n ENDIF\n A1(I:M1,I) = SCALE*A1(I:M1,I)\n ENDIF\n ENDIF\n W(I) = SCALE*G\n G = zero\n S = zero\n SCALE = zero\n IF (I.le.M1 .AND. I.ne.N1) THEN\n SCALE = SUM(ABS(A1(I,L:N1)))\n IF (SCALE .ne. zero) THEN\n A1(I,L:N1) = A1(I,L:N1)/SCALE\n S = SUM(A1(I,L:N1)*A1(I,L:N1))\n F = A1(I,L)\n G = -SIGN(SQRT(S),F)\n H = F*G - S\n A1(I,L) = F - G\n RV1(L:N1) = A1(I,L:N1)/H\n IF (I .ne. M1) THEN\n DO J = L, M1\n S = SUM(A1(J,L:N1)*A1(I,L:N1))\n A1(J,L:N1) = A1(J,L:N1) + S*RV1(L:N1)\n END DO\n ENDIF\n A1(I,L:N1) = SCALE*A1(I,L:N1)\n ENDIF\n ENDIF\n ANORM = MAX(ANORM,ABS(W(I))+ABS(RV1(I)))\n END DO\n\n! 2. Accumulation of right-hand (V) transformations\n DO I = N1, 1, -1\n IF (I .lt. N1) THEN\n IF (G .ne. zero) THEN\n V(L:N1,I) = (A1(I,L:N1)/A1(I,L))/G\n DO J = L, N1\n S = SUM(A1(I,L:N1)*V(L:N1,J))\n V(L:N1,J) = V(L:N1,J) + S*V(L:N1,I)\n END DO\n ENDIF\n V(I,L:N1) = zero\n V(L:N1,I) = zero\n ENDIF\n V(I,I) = one\n G = RV1(I)\n L = I\n END DO\n\n! 3. Accumulation of left-hand (A) transformations\n DO I = N1, 1, -1\n L = I + 1\n G = W(I)\n IF (I .lt. N1) THEN\n A1(I,L:N1) = zero\n ENDIF\n IF (G .ne. zero) THEN\n G = one/G\n IF (I .ne. N1) THEN\n DO J = L, N1\n S = SUM(A1(L:M1,I)*A1(L:M1,J))\n F = (S/A1(I,I))*G\n A1(I:M1,J) = A1(I:M1,J) + F*A1(I:M1,I)\n END DO\n ENDIF\n A1(I:M1,I) = A1(I:M1,I)*G\n ELSE\n A1(I:M1,I) = zero\n ENDIF\n A1(I,I) = A1(I,I) + one\n END DO\n\n! 4. Diagonalization of the bidiagonal form\n! 4a.Loop over singular values\n L49: DO K = N1, 1, -1\n! 4b. Loop over allowed iterations\n DO ITS = 1, 50\n! 4c. Test for splitting\n DO L = K, 1, -1\n NM = L - 1\n IF (ABS(RV1(L)) + ANORM .eq. ANORM) GO TO 2\n IF (ABS(W(NM)) + ANORM .eq. ANORM) EXIT\n END DO\n! 4d. Cancellation of RV1(L), if L>1\n C = zero\n S = one\n DO I = L, K\n F = S*RV1(I)\n IF (ABS(F) + ANORM .ne. ANORM) THEN\n G = W(I)\n H = PYTHAG(F,G)\nc H=SQRT(F*F+G*G)\n W(I) = H\n H = one/H\n C = G*H\n S = -F*H\n \n CALL ROTATE_SVD (A1(1,NM), A1(1,I), C, S, M1)\n! DO J = 1, M\n! Y = A(J,NM)\n! Z = A(J,I)\n! A(J,NM) = Y*C + Z*S\n! A(J,I) =-Y*S + Z*C\n! END DO\n\n ENDIF\n END DO\n 2 CONTINUE\n Z = W(K)\n\n! 4e. Convergence, make singular value non-negative\n IF (L .eq. K) THEN\n IF (Z .lt. zero) THEN\n W(K) = -Z\n V(:N1,K) = -V(:N1,K)\n ENDIF\n CYCLE L49\n ENDIF\n IF (ITS .eq. 50) THEN\n WRITE (*, '(2A)') 'PAUSE ',\n 1 'No convergence in 50 iterations'\n READ *\n ENDIF\n! 4f. Shift from bottom 2 X 2 minor\n X = W(L)\n NM = K - 1\n Y = W(NM)\n G = RV1(NM)\n H = RV1(K)\n F = ((Y - Z)*(Y + Z) + (G - H)*(G + H))/(TWO*H*Y)\n G = PYTHAG(F,one)\nc G=SQRT(F*F + one)\n F = ((X - Z)*(X + Z) + H*(Y/(F + SIGN(G,F)) - H))/X\n\n! 4f. Next QR transformation\n C = one\n S = one\n DO J = L, NM\n I = J + 1\n G = RV1(I)\n Y = W(I)\n H = S*G\n G = C*G\n Z = PYTHAG(F,H)\nc Z=SQRT(F*F+H*H)\n RV1(J) = Z\n C = F/Z\n S = H/Z\n F = X*C + G*S\n G =-X*S + G*C\n H = Y*S\n Y = Y*C\n\n CALL ROTATE_SVD (V(1,J), V(1,I), C, S, N1)\n! DO JJ = 1, N\n! X = V(JJ,J)\n! Z = V(JJ,I)\n! V(JJ,J) = X*C + Z*S\n! V(JJ,I) =-X*S + Z*C\n! END DO\n Z = PYTHAG(F,H)\nc Z=SQRT(F*F+H*H)\n W(J) = Z\n\n! 4g. Rotation can be arbitrary if Z=0\n IF (Z .ne. zero) THEN\n Z = one/Z\n C = F*Z\n S = H*Z\n ENDIF\n F = C*G + S*Y\n X =-S*G + C*Y\n CALL ROTATE_SVD(A1(1,J), A1(1,I), C, S, M1)\n! DO JJ = 1, M\n! Y = A(JJ,J)\n! Z = A(JJ,I)\n! A(JJ,J) = Y*C + Z*S\n! A(JJ,I) =-Y*S + Z*C\n! END DO\n END DO\n RV1(L) = zero\n RV1(K) = F\n W(K) = X\n END DO\n END DO L49\n\n IF (LTRANS) THEN\n A(1:M,1:M) = V(1:N1,1:N1) !U is now square: M X M\n V(1:N,1:M) = A1(1:N,1:M) !V not square anymore, but N X M\n DEALLOCATE (A1)\n END IF\n\n END SUBROUTINE SVDCMP\n\n\n SUBROUTINE ROTATE_SVD (A, B, C, S, M)\n USE stel_kinds\n IMPLICIT NONE\nC-----------------------------------------------\nC D u m m y A r g u m e n t s\nC-----------------------------------------------\n INTEGER, INTENT(in) :: M\n REAL(rprec), INTENT(inout) :: A, B\n REAL(rprec), INTENT(in) :: C, S\nC-----------------------------------------------\n REAL(rprec) :: YTEMP\nC-----------------------------------------------\n YTEMP = A\n A = YTEMP*C + B*S\n B =-YTEMP*S + B*C\n\n END SUBROUTINE ROTATE_SVD\n", "meta": {"hexsha": "d66d89c8dad504e547006f86b3159d8258210b80", "size": 8746, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Sources/SVDpack/svdcmp.f", "max_stars_repo_name": "ORNL-Fusion/libstell", "max_stars_repo_head_hexsha": "92ac5c339b31e29d9d734c20eae3e7571de8f490", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-10-19T06:24:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-08T21:10:12.000Z", "max_issues_repo_path": "Sources/SVDpack/svdcmp.f", "max_issues_repo_name": "ORNL-Fusion/libstell", "max_issues_repo_head_hexsha": "92ac5c339b31e29d9d734c20eae3e7571de8f490", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-09-21T14:00:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-03T00:48:39.000Z", "max_forks_repo_path": "Sources/SVDpack/svdcmp.f", "max_forks_repo_name": "ORNL-Fusion/LIBSTELL", "max_forks_repo_head_hexsha": "ba938c678d776b84d7bb260ea541a9b45deb37e2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.4738675958, "max_line_length": 76, "alphanum_fraction": 0.3352389664, "num_tokens": 2823, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096181702031, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6611958986213288}} {"text": "C NCLFORTSTART\n subroutine thorn2(t,ntim,tmsg,lat,etp,ier)\n implicit none\nC INPUT\n integer ntim, ier\n double precision t(ntim), lat, tmsg\nC OUTPUT\n double precision etp(ntim)\nC NCLEND\nC --------------------------------------------------------------------\nC Computation of evapotranspiration using the method of Thornthwaite\nC --------------------------------------------------------------------\nC This allows missing values \nC --------------------------------------------------------------------\nC Original C-code: http://sac.csic.es/spei/spei_index.html\nC --------------------------------------------------------------------\nC LOCAL\n integer nt, nmo, nmos, nyrs, knt\n double precision J, J2, J3, c, N, K(12), pi, rad, tmo\n double precision tanlat, tanLatMonth, omega\n + , tanDelta(12), days(12), julian(12)\n\n data days / 31,28,31,30,31,30,31,31,30,31,30,31/\n data julian / 16, 45.5, 75 ,105.5,136 ,166.5\n + , 197,228 ,258.5,289 ,319.5,350 /\n data pi /3.14159265358979d0/\n data rad /0.0174532925d0/\n\nC average solar declination angle for each month of the year\n\n data tanDelta / -0.37012566,-0.23853358,-0.04679872, 0.16321764\n\n + , 0.32930908, 0.40677729, 0.3747741 , 0.239063\n + , 0.04044485,-0.16905776,-0.33306377,-0.40743608 /\n\n nmos = 12\n nyrs = ntim/nmos\n\n do nt=1,ntim\n etp(nt) = tmsg \n end do\n\n ier = 0\n if (mod(ntim,nyrs).ne.0) then\n ier = 1\n return\n end if\n\nc calculate climatological monthly temperatures and use these\nc . to calculate a climatological annual temp. efficiency index (J)\n\n J = 0.0d0\n do nmo=1,nmos\n knt = 0\n tmo = 0.0d0\nc ! every 12-th value (eg: all Januaries)\n do nt=nmo,ntim,nmos \n if (t(nt).ne.tmsg) then\n tmo = tmo + t(nt)\n knt = knt + 1\n end if\n end do\nc ! monthly climatology\n if (knt.gt.0) then\n tmo = tmo/knt\n if (tmo.gt.0.0d0) J = J + (tmo/5d0)**1.514\n end if\n end do\nc ! if J=0 ... nothing else matters\n if (J.eq.0.0d0) then\n do nt=1,ntim\n if (t(nt).ne.tmsg) then\n etp(nt) = 0.0d0 \n end if\n end do\n return\n end if\n\nC Compute exponent (c)\n\n J2 = J*J\n J3 = J*J2\n c = 0.000000675d0*J3 - 0.0000771d0*J2 + 0.01792d0*J + 0.49239d0\n\nC Compute K: monthly correction factor which is a function of latitude\n\n tanLat = tan(rad*lat)\n do nmo=1,nmos\n tanLatMonth = tanLat*tanDelta(nmo) \n if (tanLatMonth.gt.-1.0d0 .and. tanLatMonth.lt.1.0d0) then\n omega = acos(-tanLatMonth)\n elseif (tanLatMonth.le.-1.0d0) then\n omega = 0\n else\n omega = pi\n end if\n N = 24d0*omega/pi ! monthly average number of sun hours\n K(nmo) = (N/12d0)*days(nmo)/30d0\n end do\n\nC Calculate evapotranspiration\n\n do nmo=1,nmos\n do nt=nmo,ntim,nmos\n if (t(nt).ne.tmsg) then\n if (t(nt).gt.0.0d0) then\n etp(nt) = K(nmo)*16*((10*t(nt)/J))**c \n else\n etp(nt) = 0.0d0\n end if\n end if\n end do\n end do\n \n end\n", "meta": {"hexsha": "262779e3de2c353307ad1083190f8930caba36dd", "size": 3673, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ni/src/lib/nfpfort/thornthwaite_v2.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "ni/src/lib/nfpfort/thornthwaite_v2.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "ni/src/lib/nfpfort/thornthwaite_v2.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 31.6637931034, "max_line_length": 71, "alphanum_fraction": 0.4481350395, "num_tokens": 1115, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096204605947, "lm_q2_score": 0.7217432003123989, "lm_q1q2_score": 0.6611958893082067}} {"text": "Program Hickerson\n! 3 February 2014\n! not all Fortran compilers provide REAL*16 and INTEGER*8\nimplicit none\nreal(kind=kind(1q0)) :: s\ninteger(kind=kind(1_8)) :: i,n,f,is\n\ndo n = 1, 17\n s = 0.5q0 / log(2q0)\n do i = 1,n\n s = (s * i) / log(2q0)\n end do\n\n is = s\n f = (s-is)*10 !first digit after decimal point\n if (f == 0 .or. f == 9) then\n write(*,10)n,s,''\n else\n write(*,10)n,s,' NOT'\n endif\nend do\n10 format('h(',i2,') = ',F23.3,' is',A,' an almost-integer')\nend program Hickerson\n", "meta": {"hexsha": "a19d0672cb5901947d0c15cdaf329694aff19bd4", "size": 562, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Hickerson-series-of-almost-integers/Fortran/hickerson-series-of-almost-integers.f", "max_stars_repo_name": "djgoku/RosettaCodeData", "max_stars_repo_head_hexsha": "91df62d46142e921b3eacdb52b0316c39ee236bc", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Hickerson-series-of-almost-integers/Fortran/hickerson-series-of-almost-integers.f", "max_issues_repo_name": "djgoku/RosettaCodeData", "max_issues_repo_head_hexsha": "91df62d46142e921b3eacdb52b0316c39ee236bc", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Hickerson-series-of-almost-integers/Fortran/hickerson-series-of-almost-integers.f", "max_forks_repo_name": "djgoku/RosettaCodeData", "max_forks_repo_head_hexsha": "91df62d46142e921b3eacdb52b0316c39ee236bc", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 23.4166666667, "max_line_length": 68, "alphanum_fraction": 0.5284697509, "num_tokens": 205, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418241572634, "lm_q2_score": 0.7154239836484143, "lm_q1q2_score": 0.6611532252947018}} {"text": "!file: coord_desc_init.f90\nsubroutine coord_desc_init(prec, corr, latent, weight, & !outputs\n observation, dims_pop, & !inputs :: data\n lambda_ridge, prec_init, weight_init, & !inputs :: parameters\n num_pop, dim_obs, num_trial) !inputs :: dimensions\n \n implicit none\n \n !inputs :: dimensions\n integer, intent(in) :: num_pop, dim_obs, num_trial\n \n !inputs :: data\n real(8), dimension(dim_obs, num_trial), intent(in) :: observation\n integer, dimension(num_pop), intent(in) :: dims_pop\n \n !inputs :: parameters\n real(8), dimension(num_pop), intent(in) :: lambda_ridge\n real(8), dimension(num_pop, num_pop), intent(in) :: prec_init\n real(8), dimension(dim_obs), intent(in) :: weight_init\n \n!f2py real(8) optional, dimension(num_pop, num_pop), intent(in) :: prec_init = 0\n!f2py real(8) optional, dimension(dim_obs), intent(in) :: weight_init = 1\n \n !outputs\n real(8), dimension(num_pop, num_pop), intent(out) :: prec, corr\n real(8), dimension(num_pop, num_trial), intent(out) :: latent\n real(8), dimension(dim_obs), intent(out) :: weight\n\n !local variables\n integer :: i, j, info, ind_from, ind_to\n integer, dimension(num_pop) :: ipiv\n real(8), dimension(num_pop) :: latent_mean, std, work\n \n external DGETRF\n external DGETRI\n \n if (sum(dims_pop) /= dim_obs) then\n stop 'Dimensions of population does not match with observation'\n end if \n \n !initialie correlation\n weight = weight_init\n do i = 1, num_pop\n ind_from = sum(dims_pop(:i-1)) + 1\n ind_to = sum(dims_pop(:i))\n \n latent(i,:) = sum(spread(weight(ind_from:ind_to), 2, num_trial) * &\n observation(ind_from:ind_to,:), 1)\n latent_mean(i) = sum(latent(i,:)) / num_trial\n \n std(i) = sqrt(dot_product(latent(i,:), latent(i,:)) / num_trial - &\n latent_mean(i) * latent_mean(i) + lambda_ridge(i))\n weight(ind_from:ind_to) = weight(ind_from:ind_to) / std(i)\n latent(i,:) = latent(i,:) / std(i)\n latent_mean(i) = latent_mean(i) / std(i)\n \n corr(i,i) = 1\n do j = 1, i-1\n corr(i,j) = dot_product(latent(i,:), latent(j,:)) / num_trial - &\n latent_mean(i) * latent_mean(j)\n corr(j,i) = corr(i,j)\n end do\n end do\n \n !initialize precision\n if (all(prec_init == 0)) then\n prec = corr\n\n call DGETRF(num_pop, num_pop, prec, num_pop, ipiv, info)\n\n if (info /= 0) then\n stop 'Initial correlation is numerically singular!'\n end if\n\n call DGETRI(num_pop, prec, num_pop, ipiv, work, num_pop, info)\n\n if (info /= 0) then\n stop 'Initial correlation inversion failed!'\n end if\n else\n prec = prec_init\n end if\n \nend subroutine coord_desc_init", "meta": {"hexsha": "d0cd060672ee7595a2789cb6f8f6ac4b3c5f0e24", "size": 2966, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "miccs/optimize/coord_desc_init.f90", "max_stars_repo_name": "HeejongBong/MICCS", "max_stars_repo_head_hexsha": "68b57cead8849e0c4bafb38521c08f4b7bf18b1a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "miccs/optimize/coord_desc_init.f90", "max_issues_repo_name": "HeejongBong/MICCS", "max_issues_repo_head_hexsha": "68b57cead8849e0c4bafb38521c08f4b7bf18b1a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "miccs/optimize/coord_desc_init.f90", "max_forks_repo_name": "HeejongBong/MICCS", "max_forks_repo_head_hexsha": "68b57cead8849e0c4bafb38521c08f4b7bf18b1a", "max_forks_repo_licenses": ["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.3095238095, "max_line_length": 88, "alphanum_fraction": 0.5778826703, "num_tokens": 777, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007394, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.6611504111235985}} {"text": "module hybrid\r\nuse MyUtility\r\n! This module is for solving system of nonlinear equations using modified Powell's \r\n! Hybrid method. Original code is from in MINPACK.\r\n\r\n! subroutine list\r\n! FsolveHybrid : main subroutine to perform the modified Powell's Hybrid\r\n! method. It calls UpdateDelta, dogleg, QRfactorization, QRupdate\r\n! and GetJacobian.\r\n! UpdateDelta : It updates Delta, the size of the trust region\r\n! dogleg : It finds the next step p within the trust region\r\n! QRfactorization : It performs QR factorization\r\n! QRupdate : It updates QR factorization after the Broyden's update\r\n! applyGivens : It apply Givens transformation. It is called by QRupdate.\r\n! \r\n! FsolveHybridTest: Sample subroutine to illustrate the usage of FsolveHybrid\r\n! It contains funstest1 and funstest2. \r\n! Just call FsolveHybrid from the main program. \r\n\r\n! Last Updated : Feb 17, 2009\r\n\r\n\r\ncontains\r\n\tsubroutine FsolveHybrid(fun, x0, xout, xtol, info, fvalout, JacobianOut, &\r\n\t\tJacobianStep, display, MaxFunCall, factor, NoUpdate,deltaSpeed)\r\n\t! Solve system of nonlinear equations using modified Powell's Hybrid method. \r\n\timplicit none\r\n\t\tINTERFACE\r\n\t\t\tSUBroutine fun (x, fval0)\r\n\t\t\tuse myutility; \r\n\t\t\timplicit none\r\n\t\t\treal(kind=db), intent(IN), dimension(:) :: x \r\n\t\t\treal(kind=db), intent(OUT), dimension(:) :: fval0\r\n\t\t\tend subroutine fun\r\n\t\tEND INTERFACE\r\n\r\n\t!. Declearation of variables\r\n\treal(kind=db), intent(IN), dimension(:) :: x0 ! Initial value\r\n\treal(kind=db), intent(OUT),dimension(size(x0)) :: xout ! solution \r\n\treal(kind=db), intent(IN), optional :: xtol ! Relative tol of X\r\n\tinteger , intent(OUT), optional :: info ! Information on output\r\n\r\n\r\n\t! output function value and Jacobian \r\n\treal(kind=db), intent(OUT), dimension(size(x0)), optional :: fvalOut\r\n\treal(kind=db), intent(OUT), dimension(size(x0),size(x0)), optional :: JacobianOut\r\n\r\n\r\n\treal(kind=db), intent(IN), optional :: JacobianStep ! Relative step for Derivative\r\n\treal(kind=db), intent(IN), optional :: factor ! inital value of delta \r\n\tinteger , intent(IN), optional :: display ! Controls display on iteration\r\n\tinteger , intent(IN), optional :: MaxFunCall ! Max number of Function call\r\n\tinteger , intent(IN), optional :: NoUpdate ! Jacobian Recalculation info\r\n\treal(kind=db), intent(IN), optional :: deltaSpeed ! How fast Delta should decrease\r\n\t\r\n\tinteger :: n ! number of variables\r\n\tinteger :: IterationCount ! number of iterations\r\n\tinteger :: FunctionCount ! number of function calls\r\n\tinteger :: GoodJacobian ! number of concective sucessfull iterations\r\n\tinteger :: BadJacobian ! number of concective failing iterations\r\n\tinteger :: SlowJacobian ! Degree of slowness after repeated Jacobian Update\r\n\tinteger :: SlowFunction ! number of concective failure of improving \r\n\tinteger :: info2 ! information for the termination\r\n\tinteger :: i ! index for the loop\r\n\tinteger :: display2 ! varible to control displaying information\r\n\tinteger :: MaxFunCall2 ! Maximum number of Function call\r\n\tinteger :: NoUpdate2 ! variable to control Jacobian Update \r\n\tinteger :: DirectionFlag ! Flag for the output of dogleg\r\n\tinteger :: UpdateJacobian ! Mark for the updating Jacobian \r\n\r\n\treal(kind=db) :: temp \r\n\treal(kind=db) :: Delta ! size of trust region\r\n\treal(kind=db) :: pnorm ! norm of step\r\n\treal(kind=db) :: ActualReduction ! 1 - norm(fvalold)/norm(fvalnew)\r\n\treal(kind=db) :: ReductionRatio ! ActuanReduction / PredictedReduction\r\n\treal(kind=db) :: xtol2 ! torelance of x\r\n\treal(kind=db) :: JacobianStep2 ! Finite difference step size\r\n\treal(kind=db) :: factor2 ! initial value of delta\r\n\treal(kind=db) :: DeltaOld ! Used for display purpose\r\n\treal(kind=db) :: deltaSpeed2 ! How fast Delta should decrease\r\n\t\r\n\r\n\treal(kind=db), dimension(size(x0)) :: xbest ! best x so far\r\n\treal(kind=db), dimension(size(x0)) :: xold ! x befor update\r\n\treal(kind=db), dimension(size(x0)) :: xnew ! xold + p\r\n\treal(kind=db), dimension(size(x0)) :: fvalbest ! fun(xbest)\r\n\treal(kind=db), dimension(size(x0)) :: fvalpredicted ! fun(xold)+ J*p\r\n\treal(kind=db), dimension(size(x0)) :: fvalold ! fun(xold) \r\n\treal(kind=db), dimension(size(x0)) :: fvalnew ! fun(xold+p)\r\n\treal(kind=db), dimension(size(x0)) :: p ! predicted direction\r\n\treal(kind=db), dimension(size(x0)) :: Psidiag ! Normaization coefs\r\n\treal(kind=db), dimension(size(x0)) :: Qtfval ! Q^T * fvalbest\r\n\r\n\treal(kind=db), dimension(size(x0),size(x0)) :: Q,R ! results of QR factorization\r\n\treal(kind=db), dimension(size(x0),size(x0)) :: J ! Jacobian\r\n\treal(kind=db), dimension(size(x0),size(x0)) :: PsiInv ! Inverse of nomarization mat\r\n\t\r\n\tCHARACTER(LEN=79) :: st1, st2 ! used for output\r\n\tCHARACTER(LEN=6) :: st6 ! used for output\r\n\tCHARACTER(LEN=12) :: st12 ! used for output\r\n\r\n\t\r\n\t!. Initialize values\r\n\t! counters\r\n\tIterationCount = 0\r\n\tFunctionCount = 0\r\n\tGoodJacobian = 0\r\n\tBadJacobian = 0\r\n\tSlowFunction = 0\r\n\tSlowJacobian = 0\r\n\tinfo2 = 0\r\n\tn = size(x0)\r\n\r\n\t! Set default values for optional inputs\r\n\txtol2 = p0001\r\n\tdisplay2 = 0\r\n\tMaxFunCall2 = n*100\r\n\tNoUpdate2 = 0\r\n\tfactor2 = 100\r\n\tdeltaSpeed2 = 0.25_db \r\n\r\n\tif (present(xtol)) xtol2 = xtol\r\n\tif (present(display)) display2 = display\r\n\tif (present(MaxFunCall)) MaxFunCall2 = MaxFunCall\r\n\tif (present(NoUpdate)) NoUpdate2 = NoUpdate\r\n\tif (present(factor)) factor2 = factor\r\n\tif (present(deltaSpeed)) deltaSpeed2 = deltaSpeed\r\n\t\r\n\r\n\tJacobianStep2 = xtol * p1\r\n\tif (present(JacobianStep)) JacobianStep2 = JacobianStep\r\n\r\n\t! Jacobian and function values\r\n\txbest = x0\r\n\tcall fun(xbest, fvalbest) ! output: fvalbest\r\n\tFunctionCount = FunctionCount + 1\r\n\tcall GetJacobian(J, fun, xbest, JacobianStep2,fvalbest) ! output : J \r\n\tFunctionCount = FunctionCount + n\r\n\tcall QRfactorization(J,Q,R) ! output: Q, R\r\n\tQtfval = matmul(transpose(Q),fvalbest)\r\n\r\n\t! calculate normalzation matrix Psi\r\n\tPsiInv = 0\r\n\tdo i = 1, n\r\n\t\t! normalization factor is R(i,i) unless R(i,i) = 0\r\n\t\ttemp = 1\r\n\t\tif(R(i,i) /= zero) temp = abs(R(i,i))\r\n\t\tPsiInv(i,i) = 1/temp\r\n\t\tPsiDiag(i) = temp\r\n\tend do\r\n\r\n\t! calculate initial value of Delta\r\n\tDelta = factor2 * norm(PsiDiag * xbest)\r\n\tif(Delta == 0 ) Delta = 1\r\n\r\n\t! check initial guess is good or not\r\n\tif (norm(fvalbest) == zero) info2 = 1\r\n\t\r\n\t! display first line\r\n\tif(display2 ==1) then\r\n\t\twrite(*,*) 'FsolveHybrid:'\r\n\t st1= \" Norm Actual Trust-Region Step Jacobian Direction\"\r\n \tst2= \" iter f(x) Reduction Size Size Recalculate Type\"\r\n\t\twrite(*,*) st1\r\n\t\twrite(*,*) st2\r\n\t\tst1 = \"(' 0 ',1G11.5)\" \r\n\t\twrite(*,st1) norm(fvalbest)\r\n\tend if \r\n\r\n\r\n\t! ****************************\r\n\t! main loop\r\n\t! ****************************\r\n\tdo\r\n\t\tIterationCount = IterationCount + 1\r\n\t\t\r\n\t\t! old values are values at the start of the iteration\r\n\t\tfvalold = fvalbest\r\n\t\txold = xbest\r\n\t\t\r\n\t\t!. *** calculate the best direction *** \r\n\t\tcall dogleg(p,Q,matmul(R,PsiInv),Delta,Qtfval,DirectionFlag)\r\n\t\t! output: p, DirectionFlag\r\n\t\tp = matmul(PsiInv, p)\r\n\t\t\r\n\t\t!. update the trust region\r\n\t\tcall fun(xold + p, fvalnew)\r\n\t\tFunctionCount = FunctionCount +1\r\n\t\tfvalpredicted = fvalbest + matmul(Q,matmul(R,p))\r\n\t\tDeltaOld = Delta\r\n\t\tcall UpdateDelta(Delta,GoodJacobian,BadJacobian,&\r\n\t\t\tActualReduction, ReductionRatio,fvalold,fvalnew,&\r\n\t\t\tfvalpredicted, PsiDiag*p,deltaSpeed2 )\r\n\t\t! output: Delta, GoodJacobian, BadJacobian, \r\n\t\t! ActualReduction, ReductionRatio\r\n\t\t\r\n\t\t! get the best value so far\r\n\t\tif(norm(fvalnew) < norm(fvalold) .and. ReductionRatio > p0001) then\r\n\t\t\txbest = xold +p\r\n\t\t\tfvalbest = fvalnew\r\n\t\tend if\r\n\r\n\t\t\r\n\t\t!. *** Check convergence ***\r\n\t\t! Sucessful Convergence\r\n\t\tif(Delta < xtol*norm(PsiDiag*xbest) .or. norm(fvalbest) == 0) info2 = 1\r\n\t\t\r\n\t\t! Too much function call\r\n\t\tif(FunctionCount > MaxFunCall2) info = 2\r\n\t\t\r\n\t\t! tol is too small \r\n\t\tif(Delta < 100 * epsilon(Delta) * norm(PsiDiag * xbest)) info2 = 3\r\n\t\t\r\n\t\t! Not successful based on Jacobian\r\n\t\tif(ActualReduction > p1) SlowJacobian = 0\r\n\t\tif(SlowJacobian == 5) info2 = 4\r\n\t\t! if Jacobian is recalculated every time, we do not performe this test\r\n\t\tif(noupdate2 == 1) SlowJacobian = 0\r\n\t\t\r\n\t\t! Not sucessful based on Function Value\r\n\t\tSlowFunction = SlowFunction + 1\r\n\t\tif(ActualReduction > p01) SlowFunction = 0\r\n\t\tif( SlowFunction == 10) info2 = 5\r\n\t\t\r\n\t\t\r\n\t\t!.*** Update Jacobian *** \r\n\t\tpnorm = norm(p)\r\n\t\tUpdateJacobian = 0\r\n\t\tif(BadJacobian == 2 .or. pnorm == 0 .or. noupdate == 1) then\r\n\t\t\t! calculate Jacobian using finite difference\r\n\t\t\tcall GetJacobian(J, fun, xbest, JacobianStep2,fvalbest) ! output : J \r\n\t\t\tFunctionCount = FunctionCount + n\r\n\t\t\tcall QRfactorization(J,Q,R) ! output: Q, R\r\n\t\t\tQtfval = matmul(transpose(Q),fvalbest)\r\n\r\n\t\t\t! recalculate normalzation matrix Psi\r\n\t\t\tdo i = 1, n\r\n\t\t\t\t! normalization factor is R(i,i) unless R(i,i) = 0\r\n\t\t\t\ttemp = 1\r\n\t\t\t\tif(R(i,i) /= zero) temp = abs(R(i,i))\r\n\t\t\t\tPsiInv(i,i) = min(PsiInv(i,i), 1/temp)\r\n\t\t\t\tPsiDiag(i) = 1/PsiInv(i,i) \r\n\t\t\tend do\r\n\t\t\t\r\n\t\t\t! take care of counts\r\n\t\t\tBadJacobian = 0\r\n\t\t\tSlowJacobian = SlowJacobian +1\r\n\t\t\tUpdateJacobian = 1\r\n\t\telse if (ReductionRatio > p0001) then\r\n\t\t\t! Broyden's Rank 1 update\r\n\t\t\tcall QRupdate(Q,R,fvalnew - fvalpredicted,p/((pnorm)**2))\r\n\t\t\tQtfval = matmul(transpose(Q),fvalbest)\r\n\t\tend if\r\n\t\t\r\n\t\t! display iteration\r\n\t\tif(display2 ==1) then\r\n\t\t\tst1 = \"(1I4,' ',1G11.5,' ',1G11.5,' ', 1G11.5,' ', 1G11.5,' ', 2A)\" \r\n\t\t\tst6 = \" \"\r\n\t\t\tif(UpdateJacobian == 1) st6 = ' Yes '\r\n\t\t\tselect case (DirectionFlag)\r\n\t\t\t\tcase (1)\r\n\t\t\t\t\tst12 = 'Newton'\r\n\t\t\t\tcase (2)\r\n\t\t\t\t\tst12 = 'Cauchy'\r\n\t\t\t\tcase (3)\r\n\t\t\t\t\tst12 = 'Combination'\r\n\t\t\tend select\r\n\t\t\twrite(*,st1) IterationCount, norm(fvalbest), 100.0_db * ActualReduction, &\r\n\t\t\t\t DeltaOld, norm(PsiDiag *p),st6, st12\r\n\t\tend if \r\n\r\n\t\t\r\n\t\t! exit check \r\n\t\tif( info2 /= 0) exit \r\n\tend do\r\n\r\n\t!. prepare output\r\n\txout = xbest\r\n\tfvalOut = fvalbest\r\n\tJacobianOut = J\r\n\t\r\n\t! display result\r\n\tif(display2 ==1) then\r\n\t\tselect case (info2)\r\n\t\t\tcase (0)\r\n\t\t\t\twrite(*,*) 'Bad input'\r\n\t\t\tcase (1)\r\n\t\t\t\tif(norm(fvalbest)>p1) then\r\n\t\t\t\t\twrite(*,*) ' Trust Region shrinks enough so no progress is possible.'\r\n\t\t\t\t\twrite(*,*) ' Make sure function value is close to zero enough'\r\n\t\t\t\telse\r\n\t\t\t\t\twrite(*,*) ' Sucessful convergence'\r\n\t\t\t\tend if\r\n\t\t\tcase (2)\r\n\t\t\t\twrite(*,*) ' Too much Function call'\r\n\t\t\tcase (3)\r\n\t\t\t\twrite(*,*) ' Tol too small'\r\n\t\t\tcase (4)\r\n\t\t\t\twrite(*,*) ' Too much Jacobian '\r\n\t\t\tcase (5)\r\n\t\t\t\twrite(*,*) ' Slow Objective function Improvement'\r\n\t\tend select\r\n\t\tif (norm(fvalbest)1 .or. ReductionRatio > p5 ) then \r\n\t\t\t! prediction was fair. expand trust egion\r\n\t\t\tDelta = max(Delta, two * pnorm) \r\n\t\t\t\r\n\t\telse if (abs(1 -ReductionRatio) < p1 ) then\r\n\t\t\t! prediction was very good. (the ratio is close to one).\r\n\t\t\t! Expand trust region \r\n\t\t\tDelta = two * pnorm\r\n\t\tend if\r\n\tend if\t\r\n\t\r\n\tend subroutine updateDelta\r\n\t\r\n\r\n\r\n\tpure subroutine dogleg(p,Q,R,delta,Qtf,flag)\r\n\t! find linear combination of newton direction and steepest descent \r\n\t! direction. \r\n\t\r\n\t! flag : it indicates the type of the p (optional)\r\n\t! flag = 1 : newton direction\r\n\t! flag = 2 : Steepest descent direction\r\n\t! flag = 3 : Linear combination of bot\r\n\t\r\n\timplicit none\r\n\treal(kind=db), intent(out), dimension(:) :: p\t! output direction\r\n\treal(kind=db), intent(in), &\r\n\t\tdimension(size(p),size(p)) \t:: Q, R\t\t! QR decomposition of Jacobian\r\n\treal(kind=db), intent(in)\t\t:: delta ! trust region parameter\r\n\treal(kind=db), intent(in), &\r\n\t\t\t\tdimension(size(p)) :: Qtf\t\t\t! Q^T * f(x)\r\n\tinteger, intent(out), optional \t:: flag \t\t! flag about the type of p\r\n\r\n\tinteger \t\t\t\t\t\t\t:: i, tempflag\r\n\tinteger \t\t\t\t\t\t\t:: n\t\t! number of variables = size(p)\r\n\treal(kind=db) \t\t\t\t\t\t:: gnorm, mu, nunorm, theta, mugnorm, temp\r\n\treal(kind=db) \t\t\t\t\t\t:: Jgnorm\r\n\treal(kind=db), dimension(size(p)) \t:: nu\t\t! Newton direction\r\n\treal(kind=db), dimension(size(p)) \t:: g\t\t! Steepest descent direction\r\n\treal(kind=db), dimension(size(p)) \t:: mug\r\n\t\r\n\tn = size(p)\r\n\t\r\n\t! ******************************\r\n\t! calculate newton direction\r\n\t! ******************************\r\n\t! prepare a small value in case diagonal element of R is zero\r\n\ttemp = epsilon(mu) * maxval(abs(diag(R)))\r\n\t\r\n\tnu(n) = -1* Qtf(n) /temp ! this is special value in case\r\n\tif (R(n,n) /= zero) nu(n) = -1* Qtf(n) / R(n,n) ! normal case\r\n\t\r\n\t! solve backwards \r\n\tdo i = n-1, 1, -1\r\n\t\tif (R(i,i)==0) then \r\n\t\t\t! special value\r\n\t\t\tnu(i) = (-1*Qtf(i) - dot_product(R(i,i+1:n),nu(i+1:n))) / temp\r\n\t\telse\r\n\t\t\t! normal value\r\n\t\t\tnu(i) = (-1*Qtf(i) - dot_product(R(i,i+1:n),nu(i+1:n))) / R(i,i) \r\n\t\tend if\r\n\tend do\r\n\tnunorm = norm(nu)\r\n\r\n\t\r\n\tif (nunorm < delta) then \r\n\t\t! newton direction \r\n\t\tp = nu\r\n\t\ttempflag = 1\r\n\telse\r\n\t\t! newton direction was not accepted. \r\n\t\tg = - one * matmul(transpose(R),Qtf) ! Steepest descent\r\n\t\tgnorm = norm(g)\r\n\t\tJgnorm = norm(matmul(Q,matmul(R,g)))\r\n\t\t\r\n\t\tif (Jgnorm == 0) then \r\n\t\t\t! special attention if steepest direction is zero\r\n\t\t\tp = delta * nu/nunorm\r\n\t\t\tflag = 3\r\n\t\t\t\r\n\t\telse if ((gnorm**2) *gnorm / (Jgnorm**2) > delta) then\r\n\t\t\t! accept steepest descent direction\r\n\t\t\tp = delta *g /gnorm\r\n\t\t\ttempflag = 2\r\n\t\telse\r\n\t\t\t! linear combination of both\r\n\t\t\t! calculate the weight of each direction\r\n\t\t\tmu = gnorm**2 / Jgnorm**2\r\n\t\t\tmug = mu *g\r\n\t\t\tmugnorm = norm(mug)\r\n\t\t\ttheta = (delta**2 - mugnorm**2) / (dot_product(mug, nu-mug) + &\r\n\t\t\t\t((dot_product(nu,mug)-delta**2)**2 + (nunorm**2-delta**2) &\r\n\t\t\t\t\t* (delta**two - mugnorm**2))**p5)\r\n\t\t\t\r\n\t\t\tp = (1-theta) * mu * g + theta*nu\r\n\t\t\ttempflag = 3\r\n\t\t\t\r\n\t\tend if\r\n\tend if\r\n\r\n\tif (present(flag)) flag = tempflag\r\n\tend subroutine dogleg\r\n\t\r\n\tsubroutine QRfactorization(A,Q,R)\r\n\t! Calculate QR factorizaton using Householder transformation. \r\n\t! You can obtain better speed and stability by using LAPACK routine.\t\r\n\t\r\n\t! It finds ortogonal matrix Q and upper triangular R such that\r\n\t!\r\n\t! A = Q * [R; ZeroMatrix]\r\n\t!\r\n\t! Arguments for this subroutine\r\n\t! A: m by n (m>=n) input matrix for the QR factorization to be computed \r\n\t! Q: m by m output orthogonal matrix \r\n\t! R: m by n output upper triangular matrix. \r\n\t! \r\n\t! Written by Yoki Okawa\r\n\t! Date: Feb 10, 08\r\n\r\n\r\n\timplicit none\r\n\t\r\n\treal(kind=db), INTENT(IN), dimension(:,:) :: A\r\n\treal(kind=db), INTENT(INOUT), dimension(:,:) :: Q,R\r\n\treal(kind=db), allocatable, dimension(:,:) :: X2\r\n\r\n\treal(kind=db), dimension(size(A,1)) :: u\r\n\treal(kind=db), dimension(size(A,1),size(A,1)) :: P\r\n\r\n\tinteger :: m, n, mQ1,mQ2, nR, mR,i,j\r\n\t\r\n\tm = size(A,1)\t\t! number of rows in A\r\n\tn = size(A,2)\t\t! number of columns in A\r\n\t\r\n\t! check size of the outputs\r\n\tmQ1 = size(Q,1) ! number of rows in Q\r\n\tmQ2 = size(Q,2)\t\t! number of columns in Q\r\n\tmR = size(R,1) ! number of rows in R\r\n\tnR = size(R,2)\t\t! number of columns in R\r\n\tif (n /= nR .or. m /= mQ1 .or. m /= mQ2 .or. m/=mR ) then \r\n\t call myerror &\r\n\t ('QRfactorization : output matrix dimensions do not match with inputs')\r\n\tend if\r\n\t\r\n\tif (m QR +u*v\r\n\t! Q: (inout) n by n Orthogonal matrix\r\n\t! R: (inout) n by n upper triangular matrix\r\n\t! u,v: n dimensional vector\r\n\t\r\n\timplicit none\r\n\treal(kind=db), intent(INOUT), dimension(:,:) :: Q,R\r\n\treal(kind=db), intent(IN), dimension(:) :: u, v\r\n \r\n \tinteger :: N ! dimension of Q or R\r\n \treal(kind=db), allocatable, dimension(:) :: w ! Qt * w\r\n \treal(kind=db), allocatable, dimension(:,:) ::Qt ! transpose(Q)\r\n \tinteger :: i, j\r\n \treal(kind=db) :: s,c, t, wnorm ! sin, cos, tan\r\n \t\r\n \tN = size(u)\r\n \tallocate(w(N))\r\n \tallocate(Qt(N,N)) \r\n\r\n \tQt = transpose(Q)\r\n\tw = matmul(Qt,u)\r\n \twnorm = norm(w) ! norm of w\r\n \t\r\n \t! make w to unit vector\r\n \tdo i = N, 2,-1\r\n \t\t! calculate cos and sin\r\n \t\tif (w(i-1) == zero) then \r\n \t\t\tc = zero\r\n \t\t\ts = one\r\n \t\telse\r\n \t\t\tt = w(i)/w(i-1)\r\n \t\t\tc = one /( (t**2+one)**p5)\r\n \t\t\ts = t * c\r\n \t\tend if\r\n \t\t\r\n \t\tcall applyGivens(R,c,s,i-1,i)\r\n \t\tcall applyGivens(Qt,c,s,i-1,i)\r\n \t\tw(i-1) = c *w(i-1) + s* w(i)\r\n \t\tw(i) = c*w(i) - s*w(i-1)\r\n\tend do\r\n \t\r\n \t! update R\r\n \tR(1,:) = R(1,:) + w(1) *v\r\n \t\r\n \t! Transform upper Hessenberg matrix R to upper triangular matrix\r\n \t! H in the documentation is currentry R\r\n \tdo i = 1, N-1\r\n \t\tif (R(i,i) == zero) then \r\n \t\t\tc = zero\r\n \t\t\ts = one\r\n \t\telse\r\n \t\t\tt = R(i+1,i)/R(i,i)\r\n \t\t\tc = one /( (t**2+one)**p5)\r\n \t\t\ts = t * c\r\n \t\tend if\r\n \t\tcall applyGivens(R,c,s,i,i+1)\r\n \t\tcall applyGivens(Qt,c,s,i,i+1)\r\n\tend do\r\n \t\r\n \tQ = transpose(Qt)\r\n\t\r\n\tend subroutine QRupdate\r\n\t\r\n\tpure subroutine applyGivens(A,c2,s2,i2,j2)\r\n\t! apply givens transformation with cos, sin, index i and j to matrix A.\r\n\t! A <- P * A, P: givens transformation. \r\n\t! P(i2,j2) = -s2; P(j2, i2) = s2; P(i2,i2) = P(j2,j2) = c2\t\r\n\t\r\n\timplicit none\r\n\treal(kind=db), intent(INOUT), dimension(:,:) :: A\r\n\treal(kind=db), intent(IN) :: c2, s2\r\n\treal(kind=db), allocatable, dimension(:) :: ai, aj\r\n\tinteger, intent(IN) :: i2, j2\r\n\tinteger :: N\r\n\r\n\t! store original input\r\n\tN = size(A,2)\r\n\tallocate(ai(N))\r\n\tallocate(aj(N))\r\n\t\r\n\tai = A(i2,:)\r\n\taj = A(j2,:)\r\n\t\r\n\t! only row i and row j changes\r\n\tA(i2,:) = A(i2,:) + (c2-1) * ai\r\n\tA(i2,:) = A(i2,:) + s2 * aj\r\n\t\r\n\t! change in row j\r\n\tA(j2,:) = A(j2,:) - s2 * ai\r\n\tA(j2,:) = A(j2,:) + (c2-1) * aj\r\n\r\n\tend subroutine applyGivens\r\n\t\r\n\tsubroutine GetJacobian(Jacobian, fun, x0, xrealEPS,fval)\r\n\t! Calculate Jacobian using forward difference\r\n\t! Jacobian(i,j) : derivative of fun(i) with respect to x(j)\r\n\t! \r\n\t! n : number of dimensions of fun\r\n\t! m : number of dimensions of x0\r\n\t! fun: function to evaluate (actually, subroutine)\r\n\t! x0 : position to evaluate\r\n\t! xreleps : relative amount of x to change\r\n\t! fval : value of fun(x) ( used to save time)\r\n\t\r\n\t\r\n\timplicit none\r\n\tINTERFACE\r\n\t\tsubroutine fun(x, fval0)\r\n\t\tuse myutility; \r\n\t\timplicit none\r\n\t\treal(kind=db), intent(IN), dimension(:) :: x\r\n\t\treal(kind=db), intent(OUT), dimension(:) :: fval0\r\n\t\tend subroutine fun\r\n\tEND INTERFACE\r\n\t\r\n\treal(kind=db), intent(in), dimension(:)\t\t:: x0, fval\r\n\treal(kind=db), intent(out), &\r\n\t\tdimension(size(fval),size(x0) ) \t\t:: Jacobian\r\n\treal(kind=db), intent(in) \t\t:: xrealEPS\r\n\t\r\n\treal(kind=db), dimension(size(fval))\t\t:: fval0, fval1 \r\n\treal(kind=db) \t\t\t\t\t\t\t\t:: xdx\r\n\treal(kind=db), dimension(size(x0)) \t\t\t:: xtemp\r\n\tinteger :: j , m\r\n\t\r\n\tm = size(x0) ! number of variables\r\n\t\r\n\t! main loop (make it forall for speed)\r\n\tdo j = 1,m\r\n\t\t! special treatment if x0 = 0\r\n\t\tif(x0(j) == 0) then\r\n\t\t\txdx = 0.001_db\r\n\t\telse\r\n\t\t\txdx = x0(j) * (one + xrealEPS)\r\n\t\tend if\r\n\r\n\t\txtemp = x0\r\n\t\txtemp(j) = xdx\r\n\t\t\r\n\t\tcall fun(xtemp, fval1) ! evaluate function at xtemp\r\n\t\tJacobian(:,j) = (fval1 - fval) / (xdx - x0(j))\r\n\tend do\r\n\t\r\n\tend subroutine GetJacobian\r\n\t\r\n\t\r\n\tsubroutine FsolveHybridTest\r\n\t! test subroutine FsolveHybrid\r\n\r\n\timplicit none\r\n\treal(kind=db), dimension(2,2) :: jacob, Q, R\r\n\treal(kind=db), dimension(2) :: xout2, fval\r\n\tinteger ::fsolveinfo\r\n\r\n\tcall FsolveHybrid( &\r\n\t\tfun = funstest1, & ! Function to be solved\r\n\t\tx0 =(/-1.2_db,1.0_db/), & ! Initial value\r\n\t\txout =xout2, & ! output \r\n\t\txtol =0.00001_db, & ! error torelance\r\n\t\tinfo =fsolveinfo, & ! info for the solution\r\n\t\tfvalout =fval, & ! f(xout)\r\n\t\tJacobianOut =jacob, & ! Jacobian at x = xout\r\n\t\tJacobianStep =0.000001_db, & ! Stepsize for the Jacobian\r\n\t\tdisplay =1, & ! Control for the display\r\n\t\tMaxFunCall = 1000, & ! Max number of function call\r\n\t\tfactor =1.0_db, & ! Initial value of delta\r\n\t\tNoUpdate = 0) ! control for update of Jacobian\r\n\r\n\twrite(*,*) ' '\r\n\twrite(*,*) 'Solution:'\r\n\tcall VectorWrite(xout2)\r\n\twrite(*,*) ' '\r\n\twrite(*,*) 'Function Value at the solution:'\r\n\tcall VectorWrite(fval)\r\n\t\t\r\n\tcontains\r\n\t\tsubroutine funstest1(x, fval0)\r\n\t\t! badly scaled function if we start from (-1.2, 1.0)\r\n\t\t! solution x1 = x2 = 1\r\n\t\timplicit none\r\n\t\treal(kind=db), intent(IN), dimension(:) :: x\r\n\t\treal(kind=db), intent(OUT), dimension(:) :: fval0\r\n\r\n\t\tfval0(1) = 10_db*(x(2) - x(1)**2)\r\n\t\tfval0(2) = 1 - x(1) \r\n\r\n\t\tend subroutine funstest1\r\n\r\n\r\n\t\tsubroutine funstest2(x, fval0)\r\n\t\t! a little difficult function\r\n\t\t! solution x = [0.50, 1.00. 1.50 ] (+ 2pi*n)\r\n\r\n\t\timplicit none\r\n\t\treal(kind=db), intent(IN), dimension(:) :: x\r\n\t\treal(kind=db), intent(OUT), dimension(:) :: fval0\r\n\r\n\t\tfval0(1) = 1.20_db * sin(x(1)) -1.40_db*cos(x(2))+ 0.70_db*sin(x(3)) & \r\n\t\t\t\t\t- 0.517133908732486_db\r\n\r\n\t\tfval0(2) = 0.80_db * cos(x(1)) -0.50_db*sin(x(2))+ 1.00_db*cos(x(3)) &\r\n\t\t\t\t\t- 0.352067758776053_db\r\n\r\n\t\tfval0(3) = 3.50_db * sin(x(1)) -4.25_db*cos(x(2))+ 2.80_db*cos(x(3)) &\r\n\t\t\t\t\t+ 0.4202312501553165_db\r\n\r\n\t\tend subroutine funstest2\r\n\tend subroutine FsolveHybridTest\r\n\r\nend module hybrid\r\n\r\n\r\n\r\n", "meta": {"hexsha": "51104873688feb4b9ad2077964322e541412e99f", "size": 23975, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "hybrid.f90", "max_stars_repo_name": "yoki/Optimization", "max_stars_repo_head_hexsha": "49f3707ab5778b23c440ebc67dfa35354662565d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-10-26T16:18:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-08T09:14:51.000Z", "max_issues_repo_path": "hybrid.f90", "max_issues_repo_name": "yoki/Optimization", "max_issues_repo_head_hexsha": "49f3707ab5778b23c440ebc67dfa35354662565d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hybrid.f90", "max_forks_repo_name": "yoki/Optimization", "max_forks_repo_head_hexsha": "49f3707ab5778b23c440ebc67dfa35354662565d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-04-05T18:05:05.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-08T15:15:45.000Z", "avg_line_length": 32.2244623656, "max_line_length": 86, "alphanum_fraction": 0.6030031283, "num_tokens": 7575, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007394, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6611504065735977}} {"text": "program jump\n\n use jump_integration\n use eispack\n\n implicit none\n\n real (kind = 8) interval, x_test\n integer (kind = 4) row, col, test\n\n real (kind = 8), dimension(:, :), allocatable :: realMatrix, imagMatrix\n\n real (kind = 8), dimension(:), allocatable :: w\n real (kind = 8), dimension(:, :), allocatable :: zi, zr\n\n integer ( kind = 4 ) ierr\n real (kind = 8), dimension(:), allocatable :: points\n\n complex (kind = 8) tempVar\n\n integer :: MODEL_N\n real(kind = 8) :: MODEL_P_CUTOFF\n real(kind = 8) :: MODEL_ALPHA\n real(kind = 8) :: MODEL_X_LOW\n real(kind = 8) :: MODEL_X_HIGH\n integer :: MODEL_X_STEPS\n integer :: MODEL_FUN_TYPE\n integer :: MODEL_FAST_MODE\n\n integer :: n_args, iarg\n character(len=16), dimension(7) :: args\n\n character(8) :: date\n character(10) :: time\n\n character(255) :: datetime\n character(255) :: logfile\n character(255) :: datafile\n character(255) :: gpltfile\n character(255) :: plotfile\n character(255) :: mlabfile\n character(255) :: cwd\n character(255) :: n_char\n character(255) :: p_char\n character(255) :: a_char\n\n write(*,'(a)') \"********************\"\n write(*,'(a)') \"JUMP MODEL TEST\"\n write(*,'(a)') \"********************\"\n write(*,*) \"\"\n\n ! Find out how many arguments have been provided. If it's not 8, warning\n n_args = command_argument_count()\n if (n_args /= 8) then\n write(*,'(a,I3)') \"WARNING: Expected 8 arguments, but got\", n_args\n write(*,*) \"\"\n write(*,*) \"Usage:\"\n write(*,*) \" ./backflow \"\n write(*,*) \"\"\n write(*,*) \"Example:\"\n write(*,*) \" ./backflow 1000 200.0 0.1 -1.0 1.0 100 1 1\"\n write(*,*) \"\"\n write(*,*) \"Using default parameters\"\n write(*,*) \"\"\n\n MODEL_N = 150\n MODEL_P_CUTOFF = 50.0D0\n MODEL_ALPHA = 0.1D0\n MODEL_X_LOW = - 0.5D0\n MODEL_X_HIGH = 0.5D0\n MODEL_X_STEPS = 6\n MODEL_FUN_TYPE = 1\n MODEL_FAST_MODE = 1\n else\n ! If we got the right number of arguments, put them into an array of characters\n do iarg=1, n_args\n call get_command_argument(iarg, args(iarg))\n end do\n\n ! Read from the array of arguments into the appropriate variables\n read(args(1), *) MODEL_N\n read(args(2), *) MODEL_P_CUTOFF\n read(args(3), *) MODEL_ALPHA\n read(args(4), *) MODEL_X_LOW\n read(args(5), *) MODEL_X_HIGH\n read(args(6), *) MODEL_X_STEPS\n read(args(7), *) MODEL_FUN_TYPE\n read(args(8), *) MODEL_FAST_MODE\n end if\n\n write(n_char, '(i0)') MODEL_N\n write(p_char, '(i0)') int(MODEL_P_CUTOFF)\n write(a_char, '(i0)') int(1000*MODEL_ALPHA)\n\n call date_and_time(date = date, time = time)\n call getcwd(cwd)\n\n datetime = date(1:4)//\"_\"//date(5:6)//\"_\"//date(7:8)\n datetime = trim(datetime)//\"__\"//time(1:2)//\"_\"//time(3:4)//\"_\"//time(5:6)\n datetime = trim(datetime)//\"__N_\"//trim(n_char)//\"__P_\"//trim(p_char)//\"__A_\"//trim(a_char)\n\n logfile = trim(cwd)//\"/out/log__\"//trim(datetime)//\".txt\"\n datafile = trim(cwd)//\"/out/data__\"//trim(datetime)//\".csv\"\n gpltfile = trim(cwd)//\"/out/gplt__\"//trim(datetime)//\".plt\"\n plotfile = trim(cwd)//\"/out/plot__\"//trim(datetime)//\".pdf\"\n mlabfile = trim(cwd)//\"/out/mlab__\"//trim(datetime)//\".m\"\n\n open(1, file = logfile, status = 'new')\n open(2, file = datafile, status = 'new')\n open(4, file = mlabfile, status = 'new')\n\n ! Write some information about the parameters being used this run\n write(*,'(a)') \"********************\"\n write(*,'(a)') \"\"\n write(*,'(a)') \"Running with parameters:\"\n write(*,'(a,I7)') \" MODEL_N = \", MODEL_N\n write(*,'(a,F12.4)') \" MODEL_P_CUTOFF = \", MODEL_P_CUTOFF\n write(*,'(a,F12.4)') \" MODEL_ALPHA = \", MODEL_ALPHA\n write(*,'(a,F12.4)') \" MODEL_X_LOW = \", MODEL_X_LOW\n write(*,'(a,F12.4)') \" MODEL_X_HIGH = \", MODEL_X_HIGH\n write(*,'(a,I7)') \" MODEL_X_STEPS = \", MODEL_X_STEPS\n write(*,'(a,I7)') \" FUN_TYPE = \", MODEL_FUN_TYPE\n write(*,'(a)') \"\"\n write(*,'(a)') \"********************\"\n write(*,*) \"\"\n\n ! Write some information about the parameters being used this run\n write(1,'(a)') \"********************\"\n write(1,'(a)') \"\"\n write(1,'(a)') \"Running with parameters:\"\n write(1,'(a,I7)') \" MODEL_N = \", MODEL_N\n write(1,'(a,F12.4)') \" MODEL_P_CUTOFF = \", MODEL_P_CUTOFF\n write(1,'(a,F12.4)') \" MODEL_ALPHA = \", MODEL_ALPHA\n write(1,'(a,F12.4)') \" MODEL_X_LOW = \", MODEL_X_LOW\n write(1,'(a,F12.4)') \" MODEL_X_HIGH = \", MODEL_X_HIGH\n write(1,'(a,I7)') \" MODEL_X_STEPS = \", MODEL_X_STEPS\n write(1,'(a,I7)') \" FUN_TYPE = \", MODEL_FUN_TYPE\n write(1,'(a)') \"\"\n write(1,'(a)') \"********************\"\n write(1,*) \"\"\n\n allocate(points(MODEL_X_STEPS + 1))\n allocate(realMatrix(MODEL_N, MODEL_N))\n allocate(imagMatrix(MODEL_N, MODEL_N))\n\n allocate(w(MODEL_N))\n allocate(zi(MODEL_N, MODEL_N))\n allocate(zr(MODEL_N, MODEL_N))\n\n interval = (MODEL_X_HIGH - (MODEL_X_LOW)) / MODEL_X_STEPS\n\n call JumpModel(MODEL_N, MODEL_P_CUTOFF, MODEL_ALPHA, MODEL_FUN_TYPE)\n call GeneratePlotFile(gpltfile, datafile, plotfile, MODEL_X_LOW, MODEL_X_HIGH)\n\n write(*,'(a,F12.4)') \"backflow1 (bf1): MODEL_ALPHA = \", - MODEL_ALPHA\n write(*,'(a,F12.4)') \"backflow2 (bf2): MODEL_ALPHA = \", MODEL_ALPHA\n write(*,*) \"\"\n\n write(1,'(a,F12.4)') \"backflow1 (bf1): MODEL_ALPHA = \", - MODEL_ALPHA\n write(1,'(a,F12.4)') \"backflow2 (bf2): MODEL_ALPHA = \", MODEL_ALPHA\n write(1,*) \"\"\n\n write(4,'(a)') \"POINTS = [\"\n\n!Previously, started writting here; may comment it all\n\n! do test = 0, MODEL_X_STEPS\n! x_test = MODEL_X_LOW + test*interval\n!\n! write(*, fmt = '(A, F6.2, A)', advance = \"no\") \"x = \", x_test, \", bf1 = \"\n! write(1, fmt = '(A, F6.2, A)', advance = \"no\") \"x = \", x_test, \", bf1 = \"\n! write(2, fmt = '(F6.2, A)', advance = \"no\") x_test, \"; \"\n! write(4, fmt = '(F6.2, A)', advance = \"no\") x_test, \", \"\n!\n! call SetAlpha(- MODEL_ALPHA)\n!\n! call GaussianCurrentKernel(0.1D0, x_test)\n!\n! do row = 1, MODEL_N\n! do col = 1, row\n! tempVar = BasisMatrixElement(row - 1, col - 1)\n!\n! realMatrix(row, col) = DREAL(tempVar)\n! imagMatrix(row, col) = DIMAG(tempVar)\n! end do\n!\n! ! print*, \"Row = \", row\n! end do\n!\n! call ch(MODEL_N, realMatrix, imagMatrix, w, .FALSE., zr,zi,ierr)\n!\n! write(*, fmt = '(F12.8, A)', advance = \"no\") w(1), \", bf2 = \"\n! write(1, fmt = '(F12.8, A)', advance = \"no\") w(1), \", bf2 = \"\n! write(2, fmt = '(F12.8, A)', advance = \"no\") w(1), \"; \"\n! write(4, fmt = '(F12.8, A)', advance = \"no\") w(1), \", \"\n!\n! call SetAlpha(MODEL_ALPHA)\n!\n! call GaussianCurrentKernel(0.1D0, x_test)\n!\n! do row = 1, MODEL_N\n! do col = 1, row\n! tempVar = BasisMatrixElement(row - 1, col - 1)\n!\n! realMatrix(row, col) = DREAL(tempVar)\n! imagMatrix(row, col) = DIMAG(tempVar)\n! end do\n!\n! ! print*, \"Row = \", row\n! end do\n!\n! call ch(MODEL_N, realMatrix, imagMatrix, w, .FALSE., zr,zi,ierr)\n!\n! write(*, fmt = '(F12.8)') w(1)\n! write(1, fmt = '(F12.8)') w(1)\n! write(2, fmt = '(F12.8)') w(1)\n! write(4, fmt = '(F12.8 a)') w(1), \";\"\n!\n! call system(\"gnuplot -p \"//trim(gpltfile))\n!\n! end do\n\n!finished original writing process here\n!from here I call the code for working out the fixed conservation of momentum\n\ndo test = 0, MODEL_X_STEPS\n x_test = MODEL_X_LOW + test*interval\n\n write(*, fmt = '(A, F6.2, A)', advance = \"no\") \"x = \", x_test, \", bf1 = \"\n write(1, fmt = '(A, F6.2, A)', advance = \"no\") \"x = \", x_test, \", bf1 = \"\n write(2, fmt = '(F6.2, A)', advance = \"no\") x_test, \"; \"\n write(4, fmt = '(F6.2, A)', advance = \"no\") x_test, \", \"\n\n call SetAlpha(- MODEL_ALPHA)\n\n call GaussianCurrentKernel(0.1D0, x_test)\n\n do row = 1, MODEL_N\n do col = 1, row\n tempVar = BasisMatrixElement(row - 1, col - 1)\n\n realMatrix(row, col) = DREAL(tempVar)\n imagMatrix(row, col) = DIMAG(tempVar)\n end do\n\n! print*, \"Row = \", row\n end do\n\n call ch(MODEL_N, realMatrix, imagMatrix, w, .FALSE., zr,zi,ierr)\n\n write(*, fmt = '(F12.8, A)', advance = \"no\") w(1), \", bf2 = \"\n write(1, fmt = '(F12.8, A)', advance = \"no\") w(1), \", bf2 = \"\n write(2, fmt = '(F12.8, A)', advance = \"no\") w(1), \"; \"\n write(4, fmt = '(F12.8, A)', advance = \"no\") w(1), \", \"\n\n call SetAlpha(MODEL_ALPHA)\n\n call GaussianCurrentKernel(0.1D0, x_test)\n\n do row = 1, MODEL_N\n do col = 1, row\n tempVar = BasisMatrixElement(row - 1, col - 1)\n\n realMatrix(row, col) = DREAL(tempVar)\n imagMatrix(row, col) = DIMAG(tempVar)\n end do\n\n! print*, \"Row = \", row\n end do\n\n call ch(MODEL_N, realMatrix, imagMatrix, w, .FALSE., zr,zi,ierr)\n\n write(*, fmt = '(F12.8, A)', advance = \"no\") w(1), \", bf3 = \"\n write(1, fmt = '(F12.8, A)', advance = \"no\") w(1), \", bf3 = \"\n write(2, fmt = '(F12.8, A)', advance = \"no\") w(1), \"; \"\n write(4, fmt = '(F12.8, A)', advance = \"no\") w(1), \", \"\n\n\n !!!\n\n call SetAlpha(- MODEL_ALPHA)\n\n call GaussianCurrentKernel(0.1D0, x_test)\n\n do row = 1, MODEL_N\n do col = 1, row\n tempVar = BasisMatrixElement2(row - 1, col - 1)\n\n realMatrix(row, col) = DREAL(tempVar)\n imagMatrix(row, col) = DIMAG(tempVar)\n end do\n\n ! print*, \"Row = \", row\n end do\n\n call ch(MODEL_N, realMatrix, imagMatrix, w, .FALSE., zr,zi,ierr)\n\n write(*, fmt = '(F12.8, A)', advance = \"no\") w(1), \", bf4 = \"\n write(1, fmt = '(F12.8, A)', advance = \"no\") w(1), \", bf4 = \"\n write(2, fmt = '(F12.8, A)', advance = \"no\") w(1), \"; \"\n write(4, fmt = '(F12.8, A)', advance = \"no\") w(1), \", \"\n\n call SetAlpha(MODEL_ALPHA)\n\n call GaussianCurrentKernel(0.1D0, x_test)\n\n do row = 1, MODEL_N\n do col = 1, row\n tempVar = BasisMatrixElement2(row - 1, col - 1)\n\n realMatrix(row, col) = DREAL(tempVar)\n imagMatrix(row, col) = DIMAG(tempVar)\n end do\n\n ! print*, \"Row = \", row\n end do\n\n call ch(MODEL_N, realMatrix, imagMatrix, w, .FALSE., zr,zi,ierr)\n\n write(*, fmt = '(F12.8)') w(1)\n write(1, fmt = '(F12.8)') w(1)\n write(2, fmt = '(F12.8)') w(1)\n write(4, fmt = '(F12.8 a)') w(1), \";\"\n\n !!!\n\n call system(\"gnuplot -p \"//trim(gpltfile))\n\nend do\n!until here\n\n\n write(4, fmt = '(a)') \"];\"\n write(4, fmt = '(a)') \"\"\n write(4, fmt = '(a)') \"plot(POINTS(:,1), POINTS(:,2:3:4:5));\"\n!edited the line above for more plotting graphs\n close(1)\n close(2)\n close(4)\n\nend program\n", "meta": {"hexsha": "7393affc3a04d93611bae4ab19c8ee2236f90040", "size": 11090, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/main.f90", "max_stars_repo_name": "Alexandre-Hefren/Backflow_Defects", "max_stars_repo_head_hexsha": "3e6b8c8c923d4b18602b5a901c24168eeffc5216", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/main.f90", "max_issues_repo_name": "Alexandre-Hefren/Backflow_Defects", "max_issues_repo_head_hexsha": "3e6b8c8c923d4b18602b5a901c24168eeffc5216", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/main.f90", "max_forks_repo_name": "Alexandre-Hefren/Backflow_Defects", "max_forks_repo_head_hexsha": "3e6b8c8c923d4b18602b5a901c24168eeffc5216", "max_forks_repo_licenses": ["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.4269005848, "max_line_length": 104, "alphanum_fraction": 0.5305680794, "num_tokens": 3779, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099168, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.661150405593279}} {"text": "program attractors\n use ode\n use dyn_sys\n implicit none\n real(dp) :: t, start, finish, step, min_step, desired_error\n real(dp) :: y(3)\n integer :: i, nstepwrite\n\n open(unit = 1, file = \"parameters.dat\")\n\n ! Chen\n ! Read integration parameters\n read(1,*) start, finish, step, min_step, desired_error, nstepwrite\n read(1,*) a, c, b\n read(1,*) y\n open(unit = 2, file = \"chen.dat\")\n\n ! Write initial conditions.\n write(2,*) y\n t = 0._dp\n i = 0\n\n ! Integrate\n dchen: do while (t < finish)\n call rkcka(chen, t, y, desired_error, step, min_step)\n i = i + 1\n if(mod(i, nstepwrite) == 0) write(2,*) y\n end do dchen\n close(2)\n\n ! Lu Chen\n ! Read integration parameters.\n read(1,*) start, finish, step, min_step, desired_error, nstepwrite\n read(1,*) a, c, b, u\n read(1,*) y\n open(2, file = \"lu_chen.dat\")\n\n write(2,*) y\n t = 0._dp\n i = 0\n dlu_chen:do while (t < finish)\n call rkcka(lu_chen, t, y, desired_error, step, min_step)\n i = i + 1\n if(mod(i, nstepwrite) == 0) write(2,*) y\n end do dlu_chen\n close(2)\n\n\n ! Modified Chaotic Chua\n ! Read integration parameters.\n read(1,*) start, finish, step, min_step, desired_error, nstepwrite\n read(1,*) alpha, beta, a, b, c, d\n read(1,*) y\n open(2, file = \"mc_chua.dat\")\n\n write(2,*) y\n t = 0._dp\n i = 0\n dmc_chua:do while (t < finish)\n call rkcka(mc_Chua, t, y, desired_error, step, min_step)\n i = i + 1\n if(mod(i, nstepwrite) == 0) write(2,*) y\n end do dmc_chua\n close(2)\n\n\nend program attractors\n", "meta": {"hexsha": "3e2b82c9bb9f30d6f99db52d51c813b54b106611", "size": 1504, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "dynamical_systems/attractors.f08", "max_stars_repo_name": "dcelisgarza/applied_math", "max_stars_repo_head_hexsha": "a8a6e49ce225392bafffb02b51c22299ffb9d20e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2015-09-30T19:22:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T23:33:04.000Z", "max_issues_repo_path": "dynamical_systems/attractors.f08", "max_issues_repo_name": "dcelisgarza/applied_math", "max_issues_repo_head_hexsha": "a8a6e49ce225392bafffb02b51c22299ffb9d20e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "dynamical_systems/attractors.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.1176470588, "max_line_length": 68, "alphanum_fraction": 0.6150265957, "num_tokens": 576, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099168, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.661150405593279}} {"text": "c=======================================================================\nc\nc subroutine VHORET \nc\nc Arithmetic h-returns for one assets\nc\nc r(t+h) = [ price(t+h) - price(t)]/price(t+h) for t = 1,...,n-h\nc\nc-----------------------------------------------------------------------\n SUBROUTINE vhoret ( n, X, h, R, info )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : number of value(s) (n > h) integer\nc X : asset values (>0) (n) double\nc h : horizon (h > 0) integer\nc\nc OUTPUT \nc R : arithmetic returns (n-h) double\nc info : diagnostic argument integer\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\nc\nc arguments i/o\n INTEGER n, h, info\n DOUBLE PRECISION X(*), R(*)\nc\nc local variables\n INTEGER i\n DOUBLE PRECISION value, myzero\n PARAMETER ( myzero = 1.E-30 )\nc\nc-----------------------------------------------------------------------\nc\nc initialization\n info = 0\nc\nc test if the number of values > h)\n IF (n .le. h) THEN\n info = -2\n RETURN\n ENDIF \nc\nc arithmetic return(s)\n DO i = 1,n-h\n value = X(i)\n IF (value .lt. myzero) THEN\n info = -103\n RETURN\n ENDIF\n R(i) = ( X(i + h)- value ) / value\n ENDDO\nc\n RETURN\n END\n\n", "meta": {"hexsha": "acd1fc5e26bae3bac16bd3f634e19c787ec81f51", "size": 1606, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/analysis/return/vhoret.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/analysis/return/vhoret.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/analysis/return/vhoret.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": 27.2203389831, "max_line_length": 72, "alphanum_fraction": 0.3405977584, "num_tokens": 370, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099167, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.6611503964932771}} {"text": " FUNCTION RAN(ISEED)\r\n PARAMETER(IA=7141,IC=54773,IM=259200)\r\n ISEED=MOD(ISEED*IA+IC,IM)\r\n RAN=FLOAT(ISEED)/FLOAT(IM)\r\n RETURN\r\n END\r\n", "meta": {"hexsha": "85475e5fa81d6ecec5b9117058363c95e6947bee", "size": 164, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "Math3/NumRec/misc/ran.for", "max_stars_repo_name": "domijin/MM3", "max_stars_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Math3/NumRec/misc/ran.for", "max_issues_repo_name": "domijin/MM3", "max_issues_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Math3/NumRec/misc/ran.for", "max_forks_repo_name": "domijin/MM3", "max_forks_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.4285714286, "max_line_length": 44, "alphanum_fraction": 0.5731707317, "num_tokens": 61, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757870046160257, "lm_q2_score": 0.7549149978955811, "lm_q1q2_score": 0.6611447447466843}} {"text": "module mod_diff\n\n use iso_fortran_env, only: int32, real32\n implicit none\n private\n public diff_centered\n\ncontains\n\n pure function diff_centered(levels) result(diff)\n real(real32), intent(in) :: levels(:)\n real(real32) :: diff(size(levels))\n integer :: imax\n\n imax = size(levels)\n\n diff(1) = .5 * (levels(2) - levels(imax))\n diff(2:imax-1) = .5 * (levels(3:imax) - levels(1:imax-2))\n diff(imax) = .5 * (levels(1) - levels(imax-1))\n end function diff_centered\n\nend module mod_diff", "meta": {"hexsha": "8cbb69874fa889b5cc5b81be0203320c906b6ce1", "size": 547, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/mod_diff.f90", "max_stars_repo_name": "AJSKirk/tsunami_simulator", "max_stars_repo_head_hexsha": "a5ddd367ee2ab847fcb8e66f0203305d03e84b88", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/mod_diff.f90", "max_issues_repo_name": "AJSKirk/tsunami_simulator", "max_issues_repo_head_hexsha": "a5ddd367ee2ab847fcb8e66f0203305d03e84b88", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/mod_diff.f90", "max_forks_repo_name": "AJSKirk/tsunami_simulator", "max_forks_repo_head_hexsha": "a5ddd367ee2ab847fcb8e66f0203305d03e84b88", "max_forks_repo_licenses": ["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.8636363636, "max_line_length": 65, "alphanum_fraction": 0.6069469835, "num_tokens": 162, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869851639066, "lm_q2_score": 0.7549149758396752, "lm_q1q2_score": 0.6611447107457125}} {"text": "subroutine inverse(N,A,inv_A)\n!\n! Copyright 2017, Viktor Reshiak, All rights reserved. \n! \n!\n! Purpose\n! =======\n! Find inverse of a matrix\n!\n!\n! Method\n! ======\n! wrapper to MKL LAPACK\n!\n!\n! IN\n! ==\n! 1) N - dimension of the matrix\n! 2) A - matrix\n!\n!\n\timplicit none \n\n\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n ! dummy arguments\n\n integer(kind=4), intent(in) :: N\n real(kind=8), intent(in), dimension(N,N) :: A\n real(kind=8), intent(out), dimension(N,N), optional :: inv_A\n\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\t! parameters of the sumsl/smsno solver\n\n integer, dimension(N) :: ipiv\n integer, dimension(2*N) :: work\n integer :: info\n\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n if ( present(inv_A) ) then\n inv_A = A\n call dgetrf( N, N, inv_A, N, ipiv, info )\n call dgetri( N, inv_A, N, ipiv, work, 2*N, info )\n else\n call dgetrf( N, N, A, N, ipiv, info )\n call dgetri( N, A, N, ipiv, work, 2*N, info )\n endif\n\nend subroutine inverse", "meta": {"hexsha": "7649809e9d3a661d3e4626274db3583ca9a3216b", "size": 1567, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/OMP/inverse.f90", "max_stars_repo_name": "revitmt/ChemicalKinetics", "max_stars_repo_head_hexsha": "61f174a1250c2bd248270ce1ef408e23e542b83b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fortran/OMP/inverse.f90", "max_issues_repo_name": "revitmt/ChemicalKinetics", "max_issues_repo_head_hexsha": "61f174a1250c2bd248270ce1ef408e23e542b83b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/OMP/inverse.f90", "max_forks_repo_name": "revitmt/ChemicalKinetics", "max_forks_repo_head_hexsha": "61f174a1250c2bd248270ce1ef408e23e542b83b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.4909090909, "max_line_length": 98, "alphanum_fraction": 0.3267389917, "num_tokens": 398, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095294, "lm_q2_score": 0.7520125848754472, "lm_q1q2_score": 0.661129433119735}} {"text": "! binenc_mod.f90 -- A Binomial-coefficient-based state encoding algorithm\n!\n! Copyright (C) 2008 Jason Blevins \n! All rights reserved.\n!\n! This software may be modified and distributed under the terms\n! of the BSD license. See the LICENSE file for details.\n!\n! Description:\n!\n! This is a Fortran 2003 implementation of the Binomial coefficient\n! based state vector encoding method described in Section 3 of the\n! paper\n!\n! Pakes A., G. Gowrisankaran, and P. McGuire (1993). \"Implementing\n! the Pakes-McGuire Algorithm for Computing Markov Perfect\n! Equilibria in Gauss.\" Mimeo, Yale University.\n!\n! This algorithm implements a bijective mapping from the state space\n! $\\mathcal X$ of all vectors $x$ of length $N$ where each component\n! of $x$ may take the values $0, 1, \\dots, M$ and where the components\n! are sorted in descending order: $x_1 \\ge x_2 \\ge \\dots \\ge x_n$.\n! The encode function maps $x$ to an integer between 1 and\n! $o(\\mathcal X)$ while the decode function implements the inverse\n! mapping.\n!\n! Caveats:\n!\n! It is important that the state vector be sorted before calling\n! encode. This code is intended as an example and as such no error\n! checking is performed.\n\nmodule binenc_mod\nimplicit none\n\n private\n public :: binenc_init, binenc_free\n public :: encode, decode\n public :: n_state\n\n ! Binomial coefficient matrix\n integer, allocatable, dimension(:,:) :: binom\n\n integer :: n_state\n integer :: N_\n integer :: M_\n\ncontains\n\n ! Allocate memory and initialize the Binomial coefficient matrix\n ! used for encoding and decoding.\n subroutine binenc_init(N, M)\n integer, intent(in) :: N, M\n integer :: i\n\n ! Store the dimensions\n N_ = N\n M_ = M\n\n ! Allocate memory for storing Binomial coefficients.\n allocate(binom(N + M + 1, N + M + 2))\n\n ! Generate the matrix of binomial coefficients to use for encoding\n ! and decoding market structures.\n binom = 0\n\n ! Upper-diagonal entries are 1.\n do i = 1, N + M + 1\n binom(i,i+1) = 1\n end do\n\n ! Construct the binomial coefficients.\n do i = 2, N + M + 1\n binom(i,2:i) = binom(i-1,2:i) + binom(i-1,1:i-1)\n end do\n\n ! Get the number of states (See Claim 1 on page 26 of Pakes,\n ! Gowrisankaran, and McGuire, 1993).\n n_state = binom(N + M + 1, N + 2)\n end subroutine binenc_init\n\n\n ! Free allocated memory\n subroutine binenc_free\n deallocate(binom)\n end subroutine binenc_free\n\n\n ! Implements a bijective mapping taking vectors in the state space\n ! to the integers between 0 and n_state. The vector x must be\n ! sorted in decreasing order (e.g., [ 5, 5, 4, 2, 0 ] ).\n function encode(x) result(ix)\n integer, dimension(N_), intent(in) :: x\n integer :: ix\n integer :: n\n\n ix = 1\n do n = 1, N_\n ix = ix + binom(x(n) + N_ + 1 - n, x(n) + 1)\n end do\n end function encode\n\n\n ! Bijectively maps the integers from 0 to n_state to vectors in the\n ! state space.\n function decode(ix) result(x)\n integer, intent(in) :: ix\n integer, dimension(N_) :: x\n integer :: digit, n, code\n\n code = ix - 1\n do n = 1, N_\n digit = 0\n do while (binom(digit + N_ - n + 2, digit + 2) <= code)\n digit = digit + 1\n end do\n\n x(n) = digit\n code = code - binom(digit + N_ - n + 1, digit + 1)\n end do\n end function decode\n\nend module binenc_mod\n", "meta": {"hexsha": "d1eca6f6b5b389445bf4ac53c7bc12774fa94b0e", "size": 3385, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "numeric/binenc_mod.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": "numeric/binenc_mod.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": "numeric/binenc_mod.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": 27.2983870968, "max_line_length": 73, "alphanum_fraction": 0.6608567208, "num_tokens": 1009, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095294, "lm_q2_score": 0.7520125793176223, "lm_q1q2_score": 0.6611294282335912}} {"text": "program ex2p4\r\n use MC_randoms\r\n implicit none\r\n integer(kind=ik), parameter :: N=100000, NTAB=32\r\n integer(kind=ik) :: i, j, k\r\n real(kind=rk), dimension(N) :: C=0, x\r\n real(kind=rk), dimension(NTAB) :: RN_TAB\r\n real(kind=rk) :: sqrmean=0, meanpow=0, numerator=0, RN, iy\r\n\r\n !-----------------------------------------------------------------------------------\r\n !LCG without the shuffle\r\n !-----------------------------------------------------------------------------------\r\n \r\n !Initialization of RN's and variables that don't change with k\r\n call seed_lcg(int(876123, ik))\r\n x = [(rand_lcg(), i=1, N, 1)]\r\n\r\n !^2\r\n sqrmean = sum(x)/N\r\n sqrmean = sqrmean*sqrmean\r\n\r\n !\r\n do i=1, N\r\n meanpow=meanpow+x(i)*x(i)\r\n end do\r\n meanpow=meanpow/N\r\n\r\n !Function itself\r\n do k=1, N-1\r\n\r\n ! term and numerator\r\n do i=1, N-k\r\n numerator=numerator+x(i+k)*x(i)\r\n end do\r\n numerator=numerator/(N-k)-sqrmean\r\n\r\n !Combine the values and reset the numerator\r\n C(k)=numerator/(meanpow-sqrmean)\r\n numerator=0\r\n end do\r\n\r\n !Save the results\r\n open(1,action=\"write\",file=\"data_lcg.txt\",status=\"replace\")\r\n do i=1, N-1\r\n write(1,*) i, c(i) \r\n end do\r\n close(1)\r\n\r\n !-----------------------------------------------------------------------------------\r\n !Park-Miller similarly to LCG\r\n !-----------------------------------------------------------------------------------\r\n\r\n call seed_pm(int(987123, ik))\r\n \r\n !Variables\r\n x = [(rand_pm(), i=1, N, 1)]\r\n sqrmean = sum(x)/N\r\n sqrmean = sqrmean*sqrmean\r\n do i=1, N\r\n meanpow=meanpow+x(i)*x(i)\r\n end do\r\n meanpow=meanpow/N\r\n\r\n !Function\r\n do k=1, N-1\r\n do i=1, N-k\r\n numerator=numerator+x(i+k)*x(i)\r\n end do\r\n numerator=numerator/(N-k)-sqrmean\r\n C(k)=numerator/(meanpow-sqrmean)\r\n numerator=0\r\n end do\r\n\r\n !Saving\r\n open(1,action=\"write\",file=\"data_pm.txt\",status=\"replace\")\r\n do i=1, N-1\r\n write(1,*) i, c(i) \r\n end do\r\n close(1)\r\n\r\n !-----------------------------------------------------------------------------------\r\n !LCG with the shuffle\r\n !-----------------------------------------------------------------------------------\r\n \r\n call seed_lcg(int(879961, ik))\r\n\r\n !Shuffle:\r\n !Generate a table and pick the first number\r\n RN_TAB=[(rand_lcg(), j=1, NTAB, 1)]\r\n iy=RN_TAB(1)\r\n\r\n !Use the table to generate an array for the correlation test\r\n do i=1, N\r\n\r\n !New random number to replace a value from the table\r\n RN=rand_lcg()\r\n\r\n !Random number from the table with iy\r\n !iy*(NTAB-1) sets the interval of possible numbers to [0,31] so we add one to it\r\n iy=RN_TAB(int(iy*(NTAB-1))+1)\r\n\r\n !Change the \"taken\" value to the new RN and store the taken value for the test\r\n RN_TAB(int(iy*(NTAB-1)+1))=RN\r\n x(i)=iy\r\n end do\r\n\r\n !Correlation test as before:\r\n sqrmean = sum(x)/N\r\n sqrmean = sqrmean*sqrmean\r\n do i=1, N\r\n meanpow=meanpow+x(i)*x(i)\r\n end do\r\n meanpow=meanpow/N\r\n\r\n !Function\r\n do k=1, N-1\r\n do i=1, N-k\r\n numerator=numerator+x(i+k)*x(i)\r\n end do\r\n numerator=numerator/(N-k)-sqrmean\r\n C(k)=numerator/(meanpow-sqrmean)\r\n numerator=0\r\n end do\r\n\r\n !Saving\r\n open(1,action=\"write\", file=\"data_lcg_shuffle.txt\", status=\"replace\")\r\n do i=1, N-1\r\n write(1,*) i, c(i) \r\n end do\r\n close(1)\r\n \r\nend program ex2p4\r\n", "meta": {"hexsha": "ecb9fe582860305841c31fe035411e84210f2f09", "size": 3640, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Nico_Toikka_ex2/p04/ex2p4.f95", "max_stars_repo_name": "toicca/basics-of-mc", "max_stars_repo_head_hexsha": "71f2fc2ac4252c359a6c6bbf46d9bac743aaec25", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Nico_Toikka_ex2/p04/ex2p4.f95", "max_issues_repo_name": "toicca/basics-of-mc", "max_issues_repo_head_hexsha": "71f2fc2ac4252c359a6c6bbf46d9bac743aaec25", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Nico_Toikka_ex2/p04/ex2p4.f95", "max_forks_repo_name": "toicca/basics-of-mc", "max_forks_repo_head_hexsha": "71f2fc2ac4252c359a6c6bbf46d9bac743aaec25", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.3684210526, "max_line_length": 89, "alphanum_fraction": 0.4651098901, "num_tokens": 1026, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095292, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.661129428233591}} {"text": " module LibMod\n use PrecisionMod\n implicit none\n!\n contains\n!\n!----------------------------------------\n subroutine InverseUsingLapack(A)\n use MathConstantsMod, only : zero, one\n implicit none\n complex(dpc), dimension(:,:) :: A\n!\n integer(i4b) :: n, lda, lwork, info, i0, j0\n Complex(dpc) :: det,tmp \n integer(i4b), dimension(:), pointer :: ipiv\n complex(dpc), dimension(:), pointer :: work\n character(len=1) :: uplo = 'U'\n!\n n = size(A, dim=1)\n i0 = lbound(A, dim=1)\n j0 = lbound(A, dim=2) \n if (n .eq. 1) then\n A(i0,j0)= One/A(i0,j0)\n! else if (n .eq. 2) then \n! det = A(i0,j0) * A(i0+1, j0+1) - A(i0+1,j0) * A(i0, j0+1) \n! if (abs(det) < 1.0E-9) then\n! write(*,*) A \n! stop 'InverseUsingLapack: det(A) is zero'\n! end if \n! tmp = A(i0,j0)\n! A(i0,j0) = A(i0+1, j0+1)\n! A(i0+1, j0+1) = tmp\n! A(i0+1,j0) = -One*A(i0+1,j0)\n! A(i0, j0+1)= -One*A(i0, j0+1)\n! A = A/det \n else\n lda = n\n lwork = 2*n\n allocate(ipiv(n), work(lwork)) \n call zgetrf( n, n, a, lda, ipiv, info )\n if (info .ne. 0) then \n write(*,*) \"******* ERROR *******\" \n write(*,*) \"from ZGETRF library info = \",info \n stop \n end if \n\n call zgetri( n, a, lda, ipiv, work, lwork, info )\n!! call zhetrf(uplo, n, a, lda, ipiv, work, lwork, info)\n!! call zhetri(uplo, n, a, lda, ipiv, work, info)\n if (info .ne. 0) then \n write(*,*) \"******* ERROR *******\" \n write(*,*) \"from ZGETRI library info = \",info \n stop \n end if \n deallocate(ipiv, work)\n end if\n!\n \n end subroutine InverseUsingLapack\n!\n!----------------------------------------\n end module LibMod\n", "meta": {"hexsha": "353d19d0136e29295c20373391eedf49ab2464f9", "size": 1697, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/LibMod.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/LibMod.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/LibMod.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": 26.9365079365, "max_line_length": 64, "alphanum_fraction": 0.4926340601, "num_tokens": 634, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467643431002, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6611294258523966}} {"text": "module integration\n\n use pde\n use global_module\n\n implicit none\n \n real(kind=8), dimension(Neq,Nx) :: U_new ! Working variable\n\n contains\n\n ! ======================================================================== \n \n subroutine forward_Euler_step(U, dt)\n\n ! This function performs one step of the Forward Euler explicit time integrator \n\n implicit none\n \n real(kind=8), dimension(Neq,Nx), intent(inout) :: U\n\n real(kind=8), intent(in) :: dt\n integer :: i, j, eqID\n \n real(kind=8), dimension(Neq) :: F_W, F_E\n\n ! First, assign BCs. Wall BCs need to be updated in time, taking the value\n ! from neighboring cells.\n call assign_BCs(U) ! See the pde.f03 module\n\n ! Update solution using the forward Euler integrator - INTERNAL CELLS only\n do i = 5, Nx-4\n\n call compute_fluxes(U, i, F_W, F_E)\n\n ! Advect remaining stuff\n U_new(:,i) = U(:,i) - dt/dx*(F_E - F_W) ! No source term\n\n ! Check that the solution did not diverge\n do eqID = 1, Neq\n if (isnan(U_new(eqID,i))) then \n print*, 'Solution diverged, try with a smaller time step! Aborting.'\n print*, 'Solution that diverged: ', U_new(:,i)\n print*, 'in cell i = ', i\n stop\n end if\n end do\n\n end do\n\n ! Save solution (internal cells ONLY! Do not overwrite ghost cells!)\n U(:,5:Nx-4) = U_new(:,5:Nx-4)\n\n end subroutine\n\n ! ======================================================================== \n \n subroutine midpoint_Euler_step(U, dt)\n\n ! This function performs one step of the Forward Euler explicit time integrator \n\n implicit none\n \n real(kind=8), dimension(Neq,Nx), intent(inout) :: U\n\n real(kind=8), intent(in) :: dt\n integer :: i, j, eqID\n \n real(kind=8), dimension(Neq) :: F_W, F_E\n\n ! First, assign BCs. Wall BCs need to be updated in time, taking the value\n ! from neighboring cells.\n call assign_BCs(U) ! See the pde.f03 module\n\n U_new = U ! Init (for ghost cells)\n\n ! Compute first half step - Create U_new (it is actually \"U_half\")\n do i = 5, Nx-4 ! Only internal cells\n call compute_fluxes(U, i, F_W, F_E)\n U_new(:,i) = U(:,i) - dt/2.0/dx*(F_E - F_W) ! No source term\n end do \n\n call assign_BCs(U_new) ! See the pde.f03 module\n\n ! Now compute the second half step:\n ! use U_new to compute the fluxes (!!!), then update U.\n do i = 5, Nx-4 ! Internal cells only\n\n call compute_fluxes(U_new, i, F_W, F_E)\n\n ! Update U\n U(:,i) = U(:,i) - dt/dx*(F_E - F_W) ! No source term\n\n ! Check that the solution did not diverge\n do eqID = 1, Neq\n if (isnan(U(eqID,i))) then \n print*, 'Solution diverged, try with a smaller time step! Aborting.'\n print*, 'Solution that diverged: ', U_new(:,i)\n print*, 'in cell i = ', i\n stop\n end if\n end do\n\n end do\n\n ! Save solution (internal cells ONLY! Do not overwrite ghost cells!)\n ! Nope, U was already updated.\n\n end subroutine\n\n ! ======================================================================== \n \n subroutine RK3_step(U, dt)\n\n ! This function performs one time integration step using the \n ! 3rd order Runge Kutta explicit method of Gottlieb & Shu (1998)\n\n implicit none\n \n real(kind=8), dimension(Neq,Nx), intent(inout) :: U\n\n real(kind=8), intent(in) :: dt\n integer :: i, j, eqID\n \n real(kind=8), dimension(Neq,Nx) :: U1, U2\n real(kind=8), dimension(Neq) :: F_W, F_E\n\n ! First, assign BCs. Wall BCs need to be updated in time, taking the value\n ! from neighboring cells.\n call assign_BCs(U) ! See the pde.f03 module\n\n ! Update solution using the forward Euler integrator - INTERNAL CELLS only\n\n U1 = U ! Init\n U2 = U ! Init\n\n do i = 5, Nx-4 ! Internal cells only\n call compute_fluxes(U, i, F_W, F_E)\n U1(:,i) = U(:,i) - dt/dx*(F_E - F_W) ! No source term\n end do\n call assign_BCs(U1) ! See the pde.f03 module\n\n do i = 5, Nx-4\n call compute_fluxes(U1, i, F_W, F_E)\n U2(:,i) = 3.0d0/4.0d0*U(:,i) + 1.0d0/4.0d0*U1(:,i) - 1.0d0/4.0d0*dt/dx*(F_E - F_W) ! No source term\n end do\n call assign_BCs(U2) ! See the pde.f03 module\n \n do i = 5, Nx-4\n call compute_fluxes(U2, i, F_W, F_E)\n U_new(:,i) = 1.0d0/3.0d0*U(:,i) + 2.0d0/3.0d0*U2(:,i) - 2.0d0/3.0d0*dt/dx*(F_E - F_W) ! No source term\n\n ! Check that the solution did not diverge\n do eqID = 1, Neq\n if (isnan(U_new(eqID,i))) then \n print*, 'Solution diverged, try with a smaller time step! Aborting.'\n print*, 'Solution that diverged: ', U_new(:,i)\n print*, 'in cell i = ', i\n stop\n end if\n end do\n\n end do\n\n ! Save solution (internal cells ONLY! Do not overwrite ghost cells!)\n U(:,5:Nx-4) = U_new(:,5:Nx-4)\n\n end subroutine\n\n ! ======================================================================== \n\n subroutine RK4_step(U, dt)\n\n ! This function performs one time integration step using the \n ! 3rd order Runge Kutta explicit method of Gottlieb & Shu (1998)\n\n implicit none\n \n real(kind=8), dimension(Neq,Nx), intent(inout) :: U\n\n real(kind=8), intent(in) :: dt\n integer :: i, j, eqID\n \n real(kind=8), dimension(Neq,Nx) :: U1, U2, U3\n real(kind=8), dimension(Neq) :: F0_W, F0_E, F1_W, F1_E, F2_W, F2_E, F3_W, F3_E\n\n ! First, assign BCs. Wall BCs need to be updated in time, taking the value\n ! from neighboring cells.\n call assign_BCs(U) ! See the pde.f03 module\n\n ! Update solution using the forward Euler integrator - INTERNAL CELLS only\n\n U1 = U ! Init\n U2 = U ! Init\n U3 = U ! Init\n\nprint*, \"WRONG! NEED TO USE TILDE OPERATOR!!!! WRONGGGGG\"\nprint*, \"WRONG! NEED TO USE TILDE OPERATOR!!!! WRONGGGGG\"\nprint*, \"WRONG! NEED TO USE TILDE OPERATOR!!!! WRONGGGGG\"\nprint*, \"WRONG! NEED TO USE TILDE OPERATOR!!!! WRONGGGGG\"\nprint*, \"WRONG! NEED TO USE TILDE OPERATOR!!!! WRONGGGGG\"\nprint*, \"WRONG! NEED TO USE TILDE OPERATOR!!!! WRONGGGGG\"\nprint*, \"WRONG! NEED TO USE TILDE OPERATOR!!!! WRONGGGGG\"\nprint*, \"WRONG! NEED TO USE TILDE OPERATOR!!!! WRONGGGGG\"\nprint*, \"WRONG! NEED TO USE TILDE OPERATOR!!!! WRONGGGGG\"\nprint*, \"WRONG! NEED TO USE TILDE OPERATOR!!!! WRONGGGGG\"\nprint*, \"WRONG! NEED TO USE TILDE OPERATOR!!!! WRONGGGGG\"\n\n do i = 5, Nx-4\n call compute_fluxes(U, i, F0_W, F0_E)\n U1(:,i) = U(:,i) - dt/(2.0d0*dx)*(F0_E - F0_W) ! No source term\n end do\n call assign_BCs(U1) ! See the pde.f03 module\n\n do i = 5, Nx-4\n call compute_fluxes(U1, i, F1_W, F1_E)\n U2(:,i) = 2.0d0/5.0d0*U(:,i) + 2.0/5.0*dt/dx*(F0_E - F0_W) &\n + 3.0d0/5.0d0*U1(:,i) - 3.0d0/5.0d0*dt/dx*(F1_E - F1_W) ! No source term\n end do\n call assign_BCs(U2) ! See the pde.f03 module\n\n do i = 5, Nx-4\n call compute_fluxes(U2, i, F2_W, F2_E)\n U3(:,i) = 831.0d0/20000.0d0*U(:,i) + 1769.0d0/40000.0d0*dt/dx*(F0_E - F0_W) &\n + 4669.0d0/20000.0d0*U1(:,i) + 161.0d0/600.0d0*dt/dx*(F1_E - F1_W) &\n + 29.0d0/40.0d0*U2(:,i) - 5.0d0/6.0d0*dt/dx*(F2_E - F2_W) ! No source term\n end do\n call assign_BCs(U3) ! See the pde.f03 module\n \n do i = 5, Nx-4\n call compute_fluxes(U3, i, F3_W, F3_E)\n U_new(:,i) = 1.0d0/3.0d0*U(:,i) + 1.0d0/3.0d0*U1(:,1) - 1.0d0/3.0d0*dt/dx*(F1_E - F1_W) &\n + 1.0d0/3.0d0*U3(:,i) - 1.0d0/6.0d0*dt/dx*(F3_E - F3_W) ! No source term\n\n ! Check that the solution did not diverge\n do eqID = 1, Neq\n if (isnan(U_new(eqID,i))) then \n print*, 'Solution diverged, try with a smaller time step! Aborting.'\n print*, 'Solution that diverged: ', U_new(:,i)\n print*, 'in cell i = ', i\n stop\n end if\n end do\n\n end do\n\n ! Save solution (internal cells ONLY! Do not overwrite ghost cells!)\n U(:,5:Nx-4) = U_new(:,5:Nx-4)\n\n end subroutine\n\n ! ======================================================================== \n\n subroutine compute_fluxes(U, i, F_W, F_E)\n\n ! A subroutine to select which fluxes I want to use. Just for simpler\n ! implementation\n\n implicit none\n\n real(kind=8), dimension(Neq,Nx), intent(in) :: U\n real(kind=8), dimension(Neq), intent(out) :: F_W, F_E\n integer, intent(in) :: i\n\n if (flux_type_Rusanov .eqv. .true.) then\n\n call compute_fluxes_Rusanov(U, i, F_W, F_E)\n\n else if (flux_type_HLL .eqv. .true.) then\n\n call compute_fluxes_HLL(U, i, F_W, F_E)\n\n else\n\n write(*,*) \"Attention! No flux type was selected! See global_module file!\"\n write(*,*) \"ABORTING!\"\n stop\n\n end if\n\n end subroutine \n\n ! ======================================================================== \n\n subroutine compute_fluxes_HLL(U, i, F_W, F_E)\n\n ! Computes HLL numerical fluxes for the cell \"i\"\n ! 'F_W' and 'F_E' are the complete fluxes at the cell interfaces, to be then\n ! added in the time-discretized PDE.\n ! The variables 'F_L' and 'F_R' are temporary variables used for the \n ! fluxes at the left and right of an interface.\n\n implicit none\n\n real(kind=8), dimension(Neq,Nx), intent(in) :: U\n real(kind=8), dimension(Neq), intent(out) :: F_W, F_E\n integer, intent(in) :: i\n\n integer :: eqID\n real(kind=8), dimension(Neq) :: U_im3, U_im2, U_im1, U_i, U_ip1, U_ip2, U_ip3\n real(kind=8), dimension(Neq) :: U_L, U_R, F_L, F_R\n real(kind=8) :: ws_min_L, ws_max_L, ws_min_R, ws_max_R, ws_min, ws_max ! wave speeds\n\n U_im3 = U(:,i-3)\n U_im2 = U(:,i-2)\n U_im1 = U(:,i-1)\n U_i = U(:,i)\n U_ip1 = U(:,i+1)\n U_ip2 = U(:,i+2)\n U_ip3 = U(:,i+3)\n\n ! ---- West interface -----\n\n call reconstruct_sol_interface(U_im3, U_im2, U_im1, U_i, U_ip1, U_ip1, U_L, U_R) ! UL and UR are sol across the west interface\n call compute_flux_ws_x(U_L, F_L, ws_max_L, ws_min_L)\n call compute_flux_ws_x(U_R, F_R, ws_max_R, ws_min_R)\n\n ws_min = MIN(ws_min_L, ws_min_R)\n ws_max = MAX(ws_max_L, ws_max_R)\n\n ! HLL fluxes\n if (ws_min .ge. 0.0) then\n F_W = F_L\n else if (ws_max .lt. 0.0) then\n F_W = F_R\n else\n F_W = (ws_min*ws_max*(U_R - U_L) + ws_max*F_L - ws_min*F_R)/(ws_max - ws_min);\n end if\n\n ! Update global maximum wave speed (used for setting the time step)\n ws_max = MAX(ABS(ws_max_R), ABS(ws_min_R), ABS(ws_max_L), ABS(ws_min_L))\n ws_maxabs = MAX(ws_maxabs, ws_max)\n\n ! ---- East interface -----\n\n call reconstruct_sol_interface(U_im2, U_im1, U_i, U_ip1, U_ip2, U_ip3, U_L, U_R) ! UL and UR are sol across the east interface\n call compute_flux_ws_x(U_L, F_L, ws_max_L, ws_min_L)\n call compute_flux_ws_x(U_R, F_R, ws_max_R, ws_min_R)\n\n ws_min = MIN(ws_min_L, ws_min_R)\n ws_max = MAX(ws_max_L, ws_max_R)\n\n ! HLL fluxes\n if (ws_min .ge. 0.0) then\n F_E = F_L\n else if (ws_max .lt. 0.0) then\n F_E = F_R\n else\n F_E = (ws_min*ws_max*(U_R - U_L) + ws_max*F_L - ws_min*F_R)/(ws_max - ws_min);\n end if\n\n ! Update global maximum wave speed (used for setting the time step)\n ws_max = MAX(ABS(ws_max_R), ABS(ws_min_R), ABS(ws_max_L), ABS(ws_min_L))\n ws_maxabs = MAX(ws_maxabs, ws_max)\n\n end subroutine\n\n ! ======================================================================== \n\n subroutine compute_fluxes_Rusanov(U, i, F_W, F_E)\n\n ! Computes HLL numerical fluxes for the cell \"i\"\n ! 'F_W' and 'F_E' are the complete fluxes at the cell interfaces, to be then\n ! added in the time-discretized PDE.\n ! The variables 'F_L' and 'F_R' are temporary variables used for the \n ! fluxes at the left and right of an interface.\n\n implicit none\n\n real(kind=8), dimension(Neq,Nx), intent(in) :: U\n real(kind=8), dimension(Neq), intent(out) :: F_W, F_E\n integer, intent(in) :: i\n\n integer :: eqID\n real(kind=8), dimension(Neq) :: U_im3, U_im2, U_im1, U_i, U_ip1, U_ip2, U_ip3\n real(kind=8), dimension(Neq) :: U_L, U_R, F_L, F_R\n real(kind=8) :: ws_min_L, ws_max_L, ws_min_R, ws_max_R, ws_min, ws_max ! wave speeds\n\n U_im3 = U(:,i-3)\n U_im2 = U(:,i-2)\n U_im1 = U(:,i-1)\n U_i = U(:,i)\n U_ip1 = U(:,i+1)\n U_ip2 = U(:,i+2)\n U_ip3 = U(:,i+3)\n\n ! ---- West interface -----\n\n call reconstruct_sol_interface(U_im3, U_im2, U_im1, U_i, U_ip1, U_ip2, U_L, U_R) ! UL and UR are sol across the west interface\n call compute_flux_ws_x(U_L, F_L, ws_max_L, ws_min_L)\n call compute_flux_ws_x(U_R, F_R, ws_max_R, ws_min_R)\n\n ws_max = MAX(ABS(ws_max_L), ABS(ws_min_L), ABS(ws_max_R), ABS(ws_min_R))\n\n ! West interface\n F_W = 0.5*(F_R + F_L) - ws_max/2.0*(U_R-U_L) ! Rusanov flux\n\n ws_maxabs = MAX(ws_maxabs, ws_max)\n\n ! ---- East interface -----\n\n call reconstruct_sol_interface(U_im2, U_im1, U_i, U_ip1, U_ip2, U_ip3, U_L, U_R) ! UL and UR are sol across the west interface\n call compute_flux_ws_x(U_L, F_L, ws_max_L, ws_min_L)\n call compute_flux_ws_x(U_R, F_R, ws_max_R, ws_min_R)\n\n ws_max = MAX(ABS(ws_max_L), ABS(ws_min_L), ABS(ws_max_R), ABS(ws_min_R))\n\n ! West interface\n F_E = 0.5*(F_R + F_L) - ws_max/2.0*(U_R-U_L) ! Rusanov flux\n\n ws_maxabs = MAX(ws_maxabs, ws_max)\n\n end subroutine\n\n ! =========================================================================\n\n subroutine reconstruct_sol_interface(U_m3, U_m2, U_m1, U_p1, U_p2, U_p3, U_L, U_R)\n \n ! Takes the four points around an interface (minus_1, minus_2, plus_1, plus_2) and \n ! computes the left and right states using first order or MUSCL TVD-limited reconstruction\n \n real(kind=8), dimension(Neq), intent(in) :: U_m3, U_m2, U_m1, U_p1, U_p2, U_p3\n real(kind=8), dimension(Neq), intent(out) :: U_L, U_R\n\n ! Working variables\n integer :: eID ! equation ID\n real(kind=8) :: theta_L, theta_R ! ratio of consecutive gradients\n real(kind=8), dimension(Neq) :: P_m3, P_m2, P_m1, P_p1, P_p2, P_p3, P_L, P_R ! primitive variables \n \n real(kind=8) :: d0, d1, b0, b1, a0, a1, omega0, omega1, P0, P1 ! WENO 3rd order\n real(kind=8) :: b2, a2, omega2, P2 ! additional for WENO 5th order\n \n if (space_order .EQ. 1) then ! ============================================================================\n ! ***** First order solution *****\n \n U_L = U_m1\n U_R = U_p1\n \n else if (space_order .EQ. 2) then ! ============================================================================\n ! ***** Second order solution - MUSCL with TVD slope limiter *****\n \n ! Perform reconstruction in primitive variables \n call compute_primitive_from_conserved(U_m2, P_m2)\n call compute_primitive_from_conserved(U_m1, P_m1)\n call compute_primitive_from_conserved(U_p1, P_p1)\n call compute_primitive_from_conserved(U_p2, P_p2)\n\n do eID = 1, Neq ! Loop on the quantities\n \n ! Compute ratio of consecutive gradients\n theta_L = (P_p1(eID) - P_m1(eID))/(P_m1(eID) - P_m2(eID) + 1.0d-15) ! Add a small tolerance\n theta_R = (P_p2(eID) - P_p1(eID))/(P_p1(eID) - P_m1(eID) + 1.0d-15) ! Add a small tolerance\n \n ! Limited linear reconstruction \n P_L(eID) = P_m1(eID) + phi_limiter(theta_L)*(P_m1(eID) - P_m2(eID))/2.0\n P_R(eID) = P_p1(eID) - phi_limiter(1.0d0/(theta_R+1.0d-10))*(P_p2(eID) - P_p1(eID))/2.0\n\n end do\n\n ! Compute conservative variables\n call compute_conserved_from_primitive(P_L, U_L)\n call compute_conserved_from_primitive(P_R, U_R)\n\n else if (space_order .EQ. 3) then ! ============================================================================\n ! ***** Third order solution - WENO 3 *****\n \n ! Perform reconstruction in primitive variables \n call compute_primitive_from_conserved(U_m2, P_m2)\n call compute_primitive_from_conserved(U_m1, P_m1)\n call compute_primitive_from_conserved(U_p1, P_p1)\n call compute_primitive_from_conserved(U_p2, P_p2)\n\n do eID = 1, Neq ! Loop on the quantities\n \n ! ---------- APPROXIMATE v_int^L (left state) ------------\n\n d0 = 2.0d0/3.0d0\n d1 = 1.0d0/3.0d0\n\n b0 = (P_p1(eID) - P_m1(eID))**2\n b1 = (P_m1(eID) - P_m2(eID))**2\n \n a0 = d0/(1.0d-6 + b0)**2\n a1 = d1/(1.0d-6 + b1)**2\n \n omega0 = a0/(a0+a1) ! Rescale\n omega1 = a1/(a0+a1) ! Rescale\n \n ! Approximate v for r=0 and r=1\n P0 = 0.5d0*P_m1(eID) + 0.5d0*P_p1(eID)\n P1 = -0.5d0*P_m2(eID) + 3.0d0/2.0d0*P_m1(eID)\n \n P_L(eID) = omega0*P0 + omega1*P1\n \n ! ---------- APPROXIMATE v_int^R (right state) ------------\n \n b0 = (P_p1(eID) - P_m1(eID))**2\n b1 = (P_p2(eID) - P_p1(eID))**2 \n\n a0 = d0/(1.0d-6 + b0)**2\n a1 = d1/(1.0d-6 + b1)**2 \n \n omega0 = a0/(a0+a1) ! Rescale\n omega1 = a1/(a0+a1) ! Rescale\n \n ! Approximate v for r=0 and r=1\n P0 = 0.5d0*P_m1(eID) + 0.5d0*P_p1(eID)\n P1 = -0.5d0*P_p2(eID) + 3.0d0/2.0d0*P_p1(eID)\n \n P_R(eID) = omega0*P0 + omega1*P1;\n\n end do\n\n ! Compute conservative variables\n call compute_conserved_from_primitive(P_L, U_L)\n call compute_conserved_from_primitive(P_R, U_R)\n\n else if (space_order .EQ. 5) then ! ============================================================================\n ! ***** Fifth order solution - WENO 5 *****\n \n ! Perform reconstruction in primitive variables \n call compute_primitive_from_conserved(U_m2, P_m2)\n call compute_primitive_from_conserved(U_m1, P_m1)\n call compute_primitive_from_conserved(U_p1, P_p1)\n call compute_primitive_from_conserved(U_p2, P_p2)\n\n do eID = 1, Neq ! Loop on the quantities\n\n call compute_primitive_from_conserved(U_m3, P_m3)\n call compute_primitive_from_conserved(U_p3, P_p3)\n\n ! ---------- APPROXIMATE v_int^L (left state) ------------\n\n b0 = 13.0d0/12.0d0*(P_m3(eID)-2.0*P_m2(eID) + P_m1(eID))**2 &\n + 1.0d0/4.0d0*(P_m3(eID)-4.0*P_m2(eID)+3.0*P_m1(eID))**2\n\n b1 = 13.0d0/12.0d0*(P_m2(eID)-2.0*P_m1(eID) + P_p1(eID))**2 &\n + 1.0d0/4.0d0*(P_m2(eID)-P_p1(eID))**2\n\n b2 = 13.0d0/12.0d0*(P_m1(eID)-2.0*P_p1(eID) + P_m2(eID))**2 &\n + 1.0d0/4.0d0*(3.0*P_m1(eID)-4.0*P_p1(eID)+P_p2(eID))**2\n\n a0 = 1.0d0/10.0d0*(1.0d0/(1.0d-6 + b0)**2)\n a1 = 6.0d0/10.0d0*(1.0d0/(1.0d-6 + b1)**2)\n a2 = 3.0d0/10.0d0*(1.0d0/(1.0d-6 + b2)**2)\n\n omega0 = a0/(a0+a1+a2)\n omega1 = a1/(a0+a1+a2)\n omega2 = a2/(a0+a1+a2)\n\n P_L(eID) = omega0*(2.0d0/6.0d0*P_m3(eID) - 7.0d0/6.0d0*P_m2(eID) + 11.0d0/6.0d0*P_m1(eID)) &\n + omega1*(-1.0d0/6.0d0*P_m2(eID) + 5.0d0/6.0d0*P_m1(eID) + 2.0d0/6.0d0*P_p1(eID)) &\n + omega2*(2.0d0/6.0d0*P_m1(eID) + 5.0d0/6.0d0*P_p1(eID) - 1.0d0/6.0d0*P_p2(eID))\n\n ! ---------- APPROXIMATE v_int^R (right state) ------------\n\n b0 = 13.0d0/12.0d0*(P_p1(eID)-2.0*P_p2(eID) + P_p3(eID))**2 &\n + 1.0d0/4.0d0*(3.0*P_p1(eID)-4.0*P_p2(eID)+P_p3(eID))**2\n\n b1 = 13.0d0/12.0d0*(P_m1(eID)-2.0*P_p1(eID) + P_p2(eID))**2 &\n + 1.0d0/4.0d0*(P_m1(eID)-P_p2(eID))**2\n\n b2 = 13.0d0/12.0d0*(P_m2(eID)-2.0*P_m1(eID) + P_p1(eID))**2 &\n + 1.0d0/4.0d0*(P_m2(eID)-4.0*P_m1(eID)+3.0*P_p1(eID))**2\n\n a0 = 1.0d0/10.0d0*(1.0d0/(1.0d-6 + b0)**2)\n a1 = 6.0d0/10.0d0*(1.0d0/(1.0d-6 + b1)**2)\n a2 = 3.0d0/10.0d0*(1.0d0/(1.0d-6 + b2)**2)\n\n omega0 = a0/(a0+a1+a2)\n omega1 = a1/(a0+a1+a2)\n omega2 = a2/(a0+a1+a2)\n\n P_R(eID) = omega2*(-1.0d0/6.0d0*P_m2(eID) + 5.0d0/6.0d0*P_m1(eID) + 2.0d0/6.0d0*P_p1(eID)) &\n + omega1*(2.0d0/6.0d0*P_m1(eID) + 5.0d0/6.0d0*P_p1(eID) - 1.0d0/6.0d0*P_p2(eID)) &\n + omega0*(11.0d0/6.0d0*P_p1(eID) - 7.0d0/6.0d0*P_p2(eID) + 2.0d0/6.0d0*P_p3(eID)) \n \n end do\n\n ! Compute conservative variables\n call compute_conserved_from_primitive(P_L, U_L)\n call compute_conserved_from_primitive(P_R, U_R)\n\n else \n\n write(*,*) \"Attention! Order of the space integration not implemented! Check global_module file!\"\n write(*,*) \"Aborting!\"\n stop\n\n end if \n\n end subroutine\n\n ! ========================================================================\n\n real(kind=8) function phi_limiter(theta)\n\n real(kind=8), intent(in) :: theta ! ratio of consecutive gradients\n\n phi_limiter = (theta*theta + theta)/(theta*theta + 1.0) ! van Albada symmetric limiter\n ! phi_limiter = (theta + abs(theta))/(1.0 + abs(theta)) ! van Leer limiter\n\n end function \n\nend module\n", "meta": {"hexsha": "9b3d770cccc1c9d6366b3e43245d8e0b2f565134", "size": 20538, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "hyper1D/src_hyper1D/integration.f03", "max_stars_repo_name": "sbocce/hyper2D", "max_stars_repo_head_hexsha": "7d1510ac3947b2c154aa0c09945ff05db4bfc8c4", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2022-02-17T14:26:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T01:56:37.000Z", "max_issues_repo_path": "hyper1D/src_hyper1D/integration.f03", "max_issues_repo_name": "sbocce/hyper2D", "max_issues_repo_head_hexsha": "7d1510ac3947b2c154aa0c09945ff05db4bfc8c4", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2022-02-28T10:22:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-01T06:25:03.000Z", "max_forks_repo_path": "hyper1D/src_hyper1D/integration.f03", "max_forks_repo_name": "sbocce/hyper2D", "max_forks_repo_head_hexsha": "7d1510ac3947b2c154aa0c09945ff05db4bfc8c4", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.8910891089, "max_line_length": 130, "alphanum_fraction": 0.5705521472, "num_tokens": 7272, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467580102418, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6611294113177196}} {"text": "!\n! CalculiX - A 3-dimensional finite element program\n! Copyright (C) 1998-2015 Guido Dhondt\n!\n! This program is free software; you can redistribute it and/or\n! modify it under the terms of the GNU General Public License as\n! published by the Free Software Foundation(version 2);\n! \n!\n! This program is distributed in the hope that it will be useful,\n! but WITHOUT ANY WARRANTY; without even the implied warranty of \n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \n! GNU General Public License for more details.\n!\n! You should have received a copy of the GNU General Public License\n! along with this program; if not, write to the Free Software\n! Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n!\n subroutine shape6tri(xi,et,xl,xsj,xs,shp,iflag)\n!\n! iflag=1: calculate only the value of the shape functions\n! iflag=2: calculate the value of the shape functions,\n! their derivatives w.r.t. the local coordinates\n! and the Jacobian vector (local normal to the\n! surface)\n! iflag=3: calculate the value of the shape functions, the\n! value of their derivatives w.r.t. the global\n! coordinates and the Jacobian vector (local normal\n! to the surface)\n! iflag=4: calculate the value of the shape functions, the\n! value of their 1st and 2nd order derivatives \n! w.r.t. the local coordinates, the Jacobian vector \n! (local normal to the surface)\n!\n! shape functions and derivatives for a 6-node quadratic\n! isoparametric triangular element. 0<=xi,et<=1,xi+et<=1 \n!\n implicit none\n!\n integer i,j,k,iflag\n!\n real*8 shp(7,6),xs(3,7),xsi(2,3),xl(3,6),sh(3),xsj(3),xi,et\n!\n intent(in) xi,et,xl,iflag\n!\n intent(out) shp,xs,xsj\n!\n! shape functions and their glocal derivatives for an element\n! described with two local parameters and three global ones.\n!\n! shape functions\n!\n shp(4,1)=2.d0*(0.5d0-xi-et)*(1.d0-xi-et)\n shp(4,2)=xi*(2.d0*xi-1.d0)\n shp(4,3)=et*(2.d0*et-1.d0)\n shp(4,4)=4.d0*xi*(1.d0-xi-et)\n shp(4,5)=4.d0*xi*et\n shp(4,6)=4.d0*et*(1.d0-xi-et) \n!\n if(iflag.eq.1) return\n!\n! local derivatives of the shape functions: xi-derivative\n!\n shp(1,1)=4.d0*(xi+et)-3.d0\n shp(1,2)=4.d0*xi-1.d0\n shp(1,3)=0.d0\n shp(1,4)=4.d0*(1.d0-2.d0*xi-et)\n shp(1,5)=4.d0*et\n shp(1,6)=-4.d0*et\n!\n! local derivatives of the shape functions: eta-derivative\n!\n shp(2,1)=4.d0*(xi+et)-3.d0\n shp(2,2)=0.d0\n shp(2,3)=4.d0*et-1.d0\n shp(2,4)=-4.d0*xi\n shp(2,5)=4.d0*xi\n shp(2,6)=4.d0*(1.d0-xi-2.d0*et)\n!\n! computation of the local derivative of the global coordinates\n! (xs)\n!\n do i=1,3\n do j=1,2\n xs(i,j)=0.d0\n do k=1,6\n xs(i,j)=xs(i,j)+xl(i,k)*shp(j,k)\n enddo\n enddo\n enddo\n!\n! computation of the jacobian vector\n!\n xsj(1)=xs(2,1)*xs(3,2)-xs(3,1)*xs(2,2)\n xsj(2)=xs(1,2)*xs(3,1)-xs(3,2)*xs(1,1)\n xsj(3)=xs(1,1)*xs(2,2)-xs(2,1)*xs(1,2)\n!\n if(iflag.eq.3) then\n! \n! computation of the global derivative of the local coordinates\n! (xsi) (inversion of xs)\n! \nc xsi(1,1)=xs(2,2)/xsj(3)\nc xsi(2,1)=-xs(2,1)/xsj(3)\nc xsi(1,2)=-xs(1,2)/xsj(3)\nc xsi(2,2)=xs(1,1)/xsj(3)\nc xsi(1,3)=-xs(2,2)/xsj(1)\nc xsi(2,3)=xs(2,1)/xsj(1)\n if(dabs(xsj(3)).gt.1.d-10) then\n xsi(1,1)=xs(2,2)/xsj(3)\n xsi(2,2)=xs(1,1)/xsj(3)\n xsi(1,2)=-xs(1,2)/xsj(3)\n xsi(2,1)=-xs(2,1)/xsj(3)\n if(dabs(xsj(2)).gt.1.d-10) then\n xsi(2,3)=xs(1,1)/(-xsj(2))\n xsi(1,3)=-xs(1,2)/(-xsj(2))\n elseif(dabs(xsj(1)).gt.1.d-10) then\n xsi(2,3)=xs(2,1)/xsj(1)\n xsi(1,3)=-xs(2,2)/xsj(1)\n else\n xsi(2,3)=0.d0\n xsi(1,3)=0.d0\n endif\n elseif(dabs(xsj(2)).gt.1.d-10) then\n xsi(1,1)=xs(3,2)/(-xsj(2))\n xsi(2,3)=xs(1,1)/(-xsj(2))\n xsi(1,3)=-xs(1,2)/(-xsj(2))\n xsi(2,1)=-xs(3,1)/(-xsj(2))\n if(dabs(xsj(1)).gt.1.d-10) then\n xsi(1,2)=xs(3,2)/xsj(1)\n xsi(2,2)=-xs(3,1)/xsj(1)\n else\n xsi(1,2)=0.d0\n xsi(2,2)=0.d0\n endif\n else\n xsi(1,2)=xs(3,2)/xsj(1)\n xsi(2,3)=xs(2,1)/xsj(1)\n xsi(1,3)=-xs(2,2)/xsj(1)\n xsi(2,2)=-xs(3,1)/xsj(1)\n xsi(1,1)=0.d0\n xsi(2,1)=0.d0\n endif\n! \n! computation of the global derivatives of the shape functions\n! \n do k=1,6\n do j=1,3\n sh(j)=shp(1,k)*xsi(1,j)+shp(2,k)*xsi(2,j)\n enddo\n do j=1,3\n shp(j,k)=sh(j)\n enddo\n enddo\n!\n elseif(iflag.eq.4) then\n!\n! local 2nd order derivatives of the shape functions: xi,xi-derivative\n! \n shp(5,1)=4.d0\n shp(5,2)=4.d0\n shp(5,3)=0.d0\n shp(5,4)=-8.d0\n shp(5,5)=0.d0\n shp(5,6)=0.d0\n!\n! local 2nd order derivatives of the shape functions: xi,eta-derivative\n! \n shp(6,1)=4.d0\n shp(6,2)=0.d0\n shp(6,3)=0.d0\n shp(6,4)=-4.d0\n shp(6,5)=4.d0\n shp(6,6)=-4.d0\n! \n! local 2nd order derivatives of the shape functions: eta,eta-derivative\n! \n shp(7,1)=4.d0\n shp(7,2)=0.d0\n shp(7,3)=4.d0\n shp(7,4)=0.d0\n shp(7,5)=0.d0\n shp(7,6)=-8.d0\n!\n! computation of the local 2nd derivatives of the global coordinates\n! (xs)\n!\n do i=1,3\n do j=5,7\n xs(i,j)=0.d0\n do k=1,6\n xs(i,j)=xs(i,j)+xl(i,k)*shp(j,k)\n enddo\n enddo\n enddo\n endif\n! \n return\n end\n", "meta": {"hexsha": "de8ed6abd4893f6fee70b056e42957d913d191a6", "size": 6014, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ccx_prool/CalculiX/ccx_2.9/src/shape6tri.f", "max_stars_repo_name": "alleindrach/calculix-desktop", "max_stars_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ccx_prool/CalculiX/ccx_2.9/src/shape6tri.f", "max_issues_repo_name": "alleindrach/calculix-desktop", "max_issues_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ccx_prool/CalculiX/ccx_2.9/src/shape6tri.f", "max_forks_repo_name": "alleindrach/calculix-desktop", "max_forks_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.07, "max_line_length": 76, "alphanum_fraction": 0.5069837047, "num_tokens": 2239, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533032291501, "lm_q2_score": 0.7090191276365462, "lm_q1q2_score": 0.6611272276173479}} {"text": " BLOCK DATA CMATHB\n IMPLICIT None\nC\nC 1. CMABD\nC\nC 1.1 CMABD PROGRAM SPECIFICATION\nC\nC 1.1.1 CMABD is the block data which initializes the mathematical\nC constants. Rather than obtaining the mathematical constants\nC from the database, they must be initialized here because of\nC the problems with differing representations of the constants\nC in ASCII and binary.\nC\nC 1.1.2 RESTRICTIONS - NONE\nC\nC 1.1.3 REFERENCES - CHEMICAL RUBBER COMPANY HANDBOOK\nC\nC 1.2 CMABD PROGRAM INTERFACE\nC\nC 1.2.1 CALLING SEQUENCE - NONE\nC \nC 1.2.2 COMMON BLOCK\nC \n Real*8 PI, TWOPI, HALFPI, CONVD, CONVDS, CONVHS, SECDAY \n COMMON /CMATH/ PI, TWOPI, HALFPI, CONVD, CONVDS, CONVHS, SECDAY \nC \nC VARIABLES \"TO\": \nC \nC 1. PI - THE MATHEMATICAL CONSTANT PI (UNITLESS) \nC 2. TWOPI - PI * 2.0D0 (UNITLESS) \nC 3. HALFPI - PI / 2.0D0 (UNITLESS) \nC 4. CONVD - THE CONVERSION FACTOR FROM DEGREES TO RADIANS (RAD/DEG) \nC 5. CONVDS - THE CONVERSION FACTOR FROM ARCSECONDS TO RADIANS\nC (RAD/ARCSECOND) \nC 6. CONVHS - THE CONVERSION FACTOR FROM TIME SECONDS TO RADIANS\nC (RADIANS / TIME SECOND) \nC 7. SECDAY - THE NUMBER OF TIME SECONDS PER DAY (SECONDS / DAY)\nC \nC VARIABLES \"FROM\": NONE\nC \nC 1.2.3 PROGRAM SPECIFICATIONS -\nC \n DATA PI /3.1415926535897932D0/, \n 1 TWOPI /6.2831853071795865D0/, \n 2 HALFPI /1.5707963267948966D0/, \n 3 CONVD /1.7453292519943296D-02/, \n 4 CONVDS /4.8481368110953599D-06/, \n 5 CONVHS /7.2722052166430399D-05/, \n 6 SECDAY /8.6400D04/ \nC \nC 1.2.4 CONSTANTS USED - PI, TWOPI, HALFPI, CONVD, CONVDS, CONVHS, SECDAY \nC \nC 1.2.5 PROGRAMMER - BRUCE SCHUPLER 02/15/78\nC SAVITA GOEL 06/04/87 (CDS FOR A900) \nC David Gordon 94.04.14 Converted to Implicit None\nC \nC 1.3 PROGRAM STRUCTURE - NONE\nC \n END \n", "meta": {"hexsha": "f2f41315e229e53ab055954faa3984d197e7b863", "size": 1926, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "calc9.1/cmabd.f", "max_stars_repo_name": "liulei/VOLKS", "max_stars_repo_head_hexsha": "eb459cef8f10a8f27a37eb633c5d070fa39f5279", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "calc9.1/cmabd.f", "max_issues_repo_name": "liulei/VOLKS", "max_issues_repo_head_hexsha": "eb459cef8f10a8f27a37eb633c5d070fa39f5279", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "calc9.1/cmabd.f", "max_forks_repo_name": "liulei/VOLKS", "max_forks_repo_head_hexsha": "eb459cef8f10a8f27a37eb633c5d070fa39f5279", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-12-13T21:30:39.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-06T03:06:51.000Z", "avg_line_length": 32.1, "max_line_length": 74, "alphanum_fraction": 0.6422637591, "num_tokens": 713, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178929, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6610965057828238}} {"text": "program energy\n\n != unit (m) :: height\n != unit (kg) :: mass\n real, parameter :: mass = 3.00, gravity = .81, height = 4.20\n\n != unit (kg m** (2) / s** (2)) :: potential_energy\n real :: potential_energy\n \n potential_energy = mass * gravity * height\nend program energy\n", "meta": {"hexsha": "9bb5bccd58df7909d9a11e3fb3bcd517dcea6d69", "size": 270, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/fixtures/Specification/Units/ex2.f90", "max_stars_repo_name": "raehik/camfort", "max_stars_repo_head_hexsha": "2f5ac9a478116ae8c7aa2a5e079b81aa58988e45", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 90, "max_stars_repo_stars_event_min_datetime": "2016-06-02T15:37:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-30T20:10:14.000Z", "max_issues_repo_path": "tests/fixtures/Specification/Units/ex2.f90", "max_issues_repo_name": "apthorpe/camfort", "max_issues_repo_head_hexsha": "1e307ae972b2fe6f63af6d3b0a3d106eec77e8a8", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 124, "max_issues_repo_issues_event_min_datetime": "2016-05-25T13:21:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-10T14:26:03.000Z", "max_forks_repo_path": "tests/fixtures/Specification/Units/ex2.f90", "max_forks_repo_name": "raehik/camfort", "max_forks_repo_head_hexsha": "2f5ac9a478116ae8c7aa2a5e079b81aa58988e45", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 16, "max_forks_repo_forks_event_min_datetime": "2016-06-02T14:51:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-14T15:59:33.000Z", "avg_line_length": 22.5, "max_line_length": 62, "alphanum_fraction": 0.6185185185, "num_tokens": 82, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297754396142, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6610964979436909}} {"text": "module global_module\n\n implicit none\n \n ! Time integration\n\n real(kind=8), parameter :: dt = 1.0d-4 ! [s] time step for the simulation\n real(kind=8), parameter :: t_end = 0.5d-0 ! [s] total simulated time (from 0 to t_end)\n\n real(kind=8), parameter :: c = 299792458.0 ! [m/s] speed of light in vacuum\n\n ! Specify domain and discretization\n\n real(kind=8), parameter :: x_min = -c/10.0 ! [m]\n real(kind=8), parameter :: x_max = c ! [m] \n real(kind=8), parameter :: y_min = -0.5*9.109d-31*c ! [kg*m/s] THIS IS A MOMENTUM\n real(kind=8), parameter :: y_max = 4.0*9.109d-31*c ! [kg*m/s] THIS IS A MOMENTUM\n\n ! Total number of cells (including 2 ghost cells for each side)\n ! (using 2 ghost cells makes it easy to reach second order accuracy)\n\n integer, parameter :: Nx = 256 ! Physical space\n integer, parameter :: Ny = 256*4 ! Momentum space\n\n ! Periodicity and second order\n logical, parameter :: x_periodic_bool = .False.\n logical, parameter :: second_order_bool = .True.\n\n real(kind=8), parameter :: dx = (x_max-x_min)/(Nx-4) ! discretization in physical space\n real(kind=8), parameter :: dy = (y_max-y_min)/(Ny-4) ! discretization in velocity space\n\n! ! Initial 1D1V maxwellian \n! real(kind=8), parameter :: n0 = 1.0d16 ! [1/m3] number density\n! real(kind=8), parameter :: u0 = 0.0d0 ! [m/s] average velocity\n! real(kind=8), parameter :: T0 = 116045.0d0 ! [K] temperature\n\nend module\n", "meta": {"hexsha": "15b6fd77bfac46f640d4c47a6d20e032864d2bae", "size": 1445, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "hyper2D_single_core/hyper2D_kinetic/relativistic/src/global_module.f03", "max_stars_repo_name": "sbocce/hyper2D", "max_stars_repo_head_hexsha": "7d1510ac3947b2c154aa0c09945ff05db4bfc8c4", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2022-02-17T14:26:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T01:56:37.000Z", "max_issues_repo_path": "hyper2D_single_core/hyper2D_kinetic/relativistic/src/global_module.f03", "max_issues_repo_name": "sbocce/hyper2D", "max_issues_repo_head_hexsha": "7d1510ac3947b2c154aa0c09945ff05db4bfc8c4", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2022-02-28T10:22:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-01T06:25:03.000Z", "max_forks_repo_path": "hyper2D_single_core/hyper2D_kinetic/relativistic/src/global_module.f03", "max_forks_repo_name": "sbocce/hyper2D", "max_forks_repo_head_hexsha": "7d1510ac3947b2c154aa0c09945ff05db4bfc8c4", "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": 38.0263157895, "max_line_length": 89, "alphanum_fraction": 0.6484429066, "num_tokens": 473, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.900529786117893, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6610964953059575}} {"text": "program rzf\n\ndouble precision pi, pi_squared_over_6, zeta_2, zeta\ninteger*8 N \npi = 3.1415926535897\npi_squared_over_6 = pi*pi / 6.0\nN = 16000000000_8\nzeta_2 = zeta(N,2_8)\n\nprint *,\" zeta(2) = \",zeta_2\nprint *,\"pi^2 / 6.0 = \",pi_squared_over_6\nprint *,\" error = \",pi_squared_over_6 - zeta_2\n\n\nend\n\ndouble precision function zeta(N,a)\ninteger*8 N,a,k,upper,lower\ninteger unr\ndouble precision xsum, ri\ndouble precision, dimension(4) :: r,ik,dk = (/ 4.0d0,4.0d0,4.0d0,4.0d0/), qsum = 0.0d0\n\n\nxsum = 0.0\nupper = (N) - ((modulo(N,4))) \nlower = 4\n\ndo k=N-1,upper+1,-1\n ri = 1.0d0/k\n xsum = xsum + ri**a\nenddo\n\ndo unr=1,4\n ik(unr) = dble( upper - (unr-1) )\nenddo \n\ndo k=upper,2*lower,-4\n r = 1.0d0 / ik\n ik = ik - dk\n qsum = qsum + r**a\nenddo \n\ndo k=lower,1,-1\n ri = 1.0d0/k\n xsum = xsum + ri**a\nenddo\n\nzeta = xsum + sum(qsum)\n\nend function\n\n", "meta": {"hexsha": "567e02b96b3ab8ad9f5ece7125266d792e0bcbea", "size": 883, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gfortran/frzf_vect.f", "max_stars_repo_name": "joelandman/rzf", "max_stars_repo_head_hexsha": "11f88f846da27ea355578c517fe5a3caf8b80315", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2017-11-15T23:33:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-24T06:01:16.000Z", "max_issues_repo_path": "gfortran/frzf_vect.f", "max_issues_repo_name": "joelandman/rzf", "max_issues_repo_head_hexsha": "11f88f846da27ea355578c517fe5a3caf8b80315", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gfortran/frzf_vect.f", "max_forks_repo_name": "joelandman/rzf", "max_forks_repo_head_hexsha": "11f88f846da27ea355578c517fe5a3caf8b80315", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.9807692308, "max_line_length": 86, "alphanum_fraction": 0.6081540204, "num_tokens": 393, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178929, "lm_q2_score": 0.7341195210831261, "lm_q1q2_score": 0.6610964953059575}} {"text": "\tSUBROUTINE OA_WFSR ( deltan, search, weight, srad, iret )\nC************************************************************************\nC* OA_WFSR\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This subroutine computes the weighting factor and search radius to\t*\nC* be used in the Barnes analysis. The weighting factor is computed\t*\nC* using the formula:\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* WEIGHT = [ 5.051457 * ( DELTAN * 2. / PI ) ** 2 ]\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* The search radius, SRAD, is computed as SEARCH * WEIGHT. This\t*\nC* limits the search area to stations whose weights will be larger\t*\nC* than [ EXP ( -SEARCH ) ] . If SEARCH is non-positive, a value\t*\nC* of 20 will be used. Both the weighting factor and search radius\t*\nC* should be multiplied by GAMMA for the second pass analysis.\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* OA_WFSR ( DELTAN, SEARCH, WEIGHT, SRAD, IRET )\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tDELTAN\t\tREAL\t\tStation spacing\t\t\t*\nC*\tSEARCH\t\tREAL\t\tUser input search condition\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tWEIGHT\t\tREAL\t\tWeighting factor\t\t*\nC*\tSRAD\t\tREAL\t\tSearch radius\t\t\t*\nC*\tIRET\t\tINTEGER\t\tReturn code\t\t\t*\nC*\t\t\t\t\t 0 = normal return\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* M. desJardins/GSFC\t 7/86\t\t\t\t\t\t*\nC* M. desJardins/GSFC\t10/88\tDocumentation\t\t\t\t*\nC* K. Brill/GSC 4/90 Changed default SEARCH to 7.\t\t*\nC* K. Brill/NMC 9/90 Changed default SEARCH back to 20.\t*\nC* M. Linda/GSC\t\t 9/97\tCorrected right border of prologue\t*\nC************************************************************************\n\tINCLUDE\t\t'GEMPRM.PRM'\nC------------------------------------------------------------------------\n\tiret = 0\nC\nC*\tCompute the weighting factor using S. Koch's formula (documented\nC*\tin his tech memo and paper).\nC\n\tweight = 5.051457 * ( deltan * 2. / PI ) **2\nC\nC*\tThe search radius is set to 20. * weight if no value is entered.\nC\n\tIF ( search .le. 0. ) THEN\n\t srad = 20. * weight\n\t ELSE\n\t srad = search * weight\n\tEND IF\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "595d9520d5b46ad883460780d3394eafd9e45591", "size": 1967, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/oalib/oawfsr.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/oalib/oawfsr.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/oalib/oawfsr.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": 35.7636363636, "max_line_length": 73, "alphanum_fraction": 0.548551093, "num_tokens": 621, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178929, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6610964953059574}} {"text": "module two_point_flux_mod\n\nuse globals_mod\n\nprivate\n\npublic :: xflux, yflux\n\ncontains\n\npure elemental function logmean(a,b) result(r)\n\n real(dp), intent(in) :: a,b\n real(dp) :: x,u,r\n\n real(dp), parameter :: eps = 1e-5\n real(dp), parameter :: c1 = 1.0/6.0\n real(dp), parameter :: c2 = 2.0/45.0\n real(dp), parameter :: c3 = 22.0/945.0\n\n x = a/b\n\n if (abs(a-b) < eps) then\n u = (x*(x-2.0)+1.0)/(x*(x+2.0)+1.0)\n r = (a+b)*(0.5 - u*(c1 - u*(c2 - c3*u)))\n else\n r = (a-b)/log(x)\n endif\n\nend function\n\npure function xflux(u,v) result(f)\n\n use equations_mod\n use config_mod, only: kappa\n\n real(dp), intent(in) :: u(N_VARS)\n real(dp), intent(in) :: v(N_VARS)\n real(dp) :: f(N_VARS)\n\n real(dp) :: dens,pres,velx,vely,enth\n real(dp) :: bu,bv !! beta\n real(dp) :: pu,pv !! pressure\n real(dp) :: vu, wu, vv, wv !! velocity\n\n pu = pressure(u)\n pv = pressure(v)\n\n bu = 0.5*u(DENS_VAR)/pu\n bv = 0.5*v(DENS_VAR)/pv\n\n vu = u(MOMX_VAR)/u(DENS_VAR)\n wu = u(MOMY_VAR)/u(DENS_VAR)\n\n vv = v(MOMX_VAR)/v(DENS_VAR)\n wv = v(MOMY_VAR)/v(DENS_VAR)\n\n dens = logmean(u(DENS_VAR),v(DENS_VAR))\n velx = 0.5*(vu + vv)\n vely = 0.5*(wu + wv)\n pres = 0.5*(u(DENS_VAR)+v(DENS_VAR))/(bu+bv)\n\n enth = 0.5/(kappa-1)/logmean(bu,bv) &\n + pres/dens + velx*velx + vely*vely &\n - 0.25*(vu*vu + wu*wu + vv*vv + wv*wv)\n\n f(DENS_VAR) = dens * velx \n f(MOMX_VAR) = f(DENS_VAR) * velx + pres\n f(MOMY_VAR) = f(DENS_VAR) * vely \n f(ENER_VAR) = f(DENS_VAR) * enth \n\nend function\n\npure function yflux(uL,uR) result(f)\n\n use equations_mod, only: N_VARS\n use equations_mod, only: DENS_VAR\n use equations_mod, only: MOMX_VAR\n use equations_mod, only: MOMY_VAR\n use equations_mod, only: ENER_VAR\n\n real(dp), intent(in) :: uL(N_VARS), uR(N_VARS)\n real(dp) :: f(N_VARS)\n\n real(dp) :: ruL(N_VARS), ruR(N_VARS), rf(N_VARS) !! rotated\n\n ruL(DENS_VAR) = uL(DENS_VAR)\n ruL(MOMX_VAR) = uL(MOMY_VAR)\n ruL(MOMY_VAR) = uL(MOMX_VAR)\n ruL(ENER_VAR) = uL(ENER_VAR)\n \n ruR(DENS_VAR) = uR(DENS_VAR)\n ruR(MOMX_VAR) = uR(MOMY_VAR)\n ruR(MOMY_VAR) = uR(MOMX_VAR)\n ruR(ENER_VAR) = uR(ENER_VAR)\n\n rf = xflux(ruL,ruR)\n\n f(DENS_VAR) = rf(DENS_VAR)\n f(MOMX_VAR) = rf(MOMY_VAR)\n f(MOMY_VAR) = rf(MOMX_VAR)\n f(ENER_VAR) = rf(ENER_VAR)\n \nend function\n\nend module\n", "meta": {"hexsha": "ce9e31310c9ae7b71cd90c780ee1537e46b30260", "size": 2503, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/equations/euler/two_point_flux/chandrashekar/two_point_flux_mod.f90", "max_stars_repo_name": "jmark/nemo2d", "max_stars_repo_head_hexsha": "a508f192d0f6da49e485ee9c8d1c049dbb81d033", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source/equations/euler/two_point_flux/chandrashekar/two_point_flux_mod.f90", "max_issues_repo_name": "jmark/nemo2d", "max_issues_repo_head_hexsha": "a508f192d0f6da49e485ee9c8d1c049dbb81d033", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/equations/euler/two_point_flux/chandrashekar/two_point_flux_mod.f90", "max_forks_repo_name": "jmark/nemo2d", "max_forks_repo_head_hexsha": "a508f192d0f6da49e485ee9c8d1c049dbb81d033", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.3925233645, "max_line_length": 63, "alphanum_fraction": 0.554135038, "num_tokens": 932, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297887874625, "lm_q2_score": 0.7341195152660687, "lm_q1q2_score": 0.6610964920273071}} {"text": " SUBROUTINE cyclic(a,b,c,alpha,beta,r,x,n)\r\n INTEGER n,NMAX\r\n REAL alpha,beta,a(n),b(n),c(n),r(n),x(n)\r\n PARAMETER (NMAX=500)\r\nCU USES tridag\r\n INTEGER i\r\n REAL fact,gamma,bb(NMAX),u(NMAX),z(NMAX)\r\n if(n.le.2)pause 'n too small in cyclic'\r\n if(n.gt.NMAX)pause 'NMAX too small in cyclic'\r\n gamma=-b(1)\r\n bb(1)=b(1)-gamma\r\n bb(n)=b(n)-alpha*beta/gamma\r\n do 11 i=2,n-1\r\n bb(i)=b(i)\r\n11 continue\r\n call tridag(a,bb,c,r,x,n)\r\n u(1)=gamma\r\n u(n)=alpha\r\n do 12 i=2,n-1\r\n u(i)=0.\r\n12 continue\r\n call tridag(a,bb,c,u,z,n)\r\n fact=(x(1)+beta*x(n)/gamma)/(1.+z(1)+beta*z(n)/gamma)\r\n do 13 i=1,n\r\n x(i)=x(i)-fact*z(i)\r\n13 continue\r\n return\r\n END\r\n", "meta": {"hexsha": "4537e3dc5ceea01c3e8ba1e3cda002db4b97e23d", "size": 772, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/cyclic.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/cyclic.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/cyclic.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": 26.6206896552, "max_line_length": 60, "alphanum_fraction": 0.5025906736, "num_tokens": 279, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178929, "lm_q2_score": 0.7341195152660687, "lm_q1q2_score": 0.661096490067524}} {"text": "PROGRAM main\n IMPLICIT NONE\n ! ...Local Scalars...\n INCLUDE 'mpif.h'\n INTEGER :: i,n,myid, ntasks, ierr, islave\n INTEGER, DIMENSION(MPI_STATUS_SIZE) :: status\n INTEGER, PARAMETER :: master=0, msgtag1=11, msgtag2=12\n DOUBLE PRECISION, PARAMETER :: pi25dt = 3.141592653589793238462643d0\n DOUBLE PRECISION :: a,h,pi,sum,x,mypi\n !\n !...Executable Statements...\n !\n CALL MPI_INIT(ierr)\n CALL MPI_COMM_RANK(MPI_COMM_WORLD, myid, ierr)\n CALL MPI_COMM_SIZE(MPI_COMM_WORLD, ntasks, ierr)\n\n DO\n IF (myid == 0) THEN ! only master\n ! Input\n WRITE (6,10000)\n READ (5,10001) n\n END IF\n CALL MPI_Bcast(n, 1, MPI_INTEGER, master,MPI_COMM_WORLD,ierr)\n IF (n==0) EXIT\n !\n h = 1.0d0 / n ! stride\n !Calculation of the quadrature formula(summation)\n sum = 0.0d0\n\n DO i = 1+myid,n,ntasks\n x = h * (DBLE(i) - 0.5d0)\n sum = sum + 4.0 / (1.0 + x * x)\n END DO\n mypi = h * sum\n CALL MPI_Reduce(mypi, pi, 1, MPI_DOUBLE_PRECISION, MPI_SUM, 0, MPI_COMM_WORLD, ierr)\n ! Output of the solution\n IF (myid == 0) THEN ! only master\n WRITE (*,*) pi, ABS(pi - pi25dt)\n END IF\n END DO\n \n CALL MPI_FINALIZE(ierr)\n\n !\n ! ...Format Declarations...\n !\n 10000 format ( \"Enter the number of intervals : (0 quits )\" )\n 10001 format ( i10 )\n\nEND PROGRAM main\n", "meta": {"hexsha": "b44bdcd474dbe1c6e5796910c068031b1fb390ea", "size": 1312, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran90/mpi.f90", "max_stars_repo_name": "mhrusz/openmp", "max_stars_repo_head_hexsha": "b66cc8ead78086483e692b5d50c8426db72c9398", "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": "fortran90/mpi.f90", "max_issues_repo_name": "mhrusz/openmp", "max_issues_repo_head_hexsha": "b66cc8ead78086483e692b5d50c8426db72c9398", "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": "fortran90/mpi.f90", "max_forks_repo_name": "mhrusz/openmp", "max_forks_repo_head_hexsha": "b66cc8ead78086483e692b5d50c8426db72c9398", "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.7254901961, "max_line_length": 89, "alphanum_fraction": 0.6265243902, "num_tokens": 453, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256472515683, "lm_q2_score": 0.7853085909370422, "lm_q1q2_score": 0.6610929128577926}} {"text": "c\nc * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nc * *\nc * copyright (c) 1998 by UCAR *\nc * *\nc * University Corporation for Atmospheric Research *\nc * *\nc * all rights reserved *\nc * *\nc * SPHEREPACK version 3.2 *\nc * *\nc * A Package of Fortran77 Subroutines and Programs *\nc * *\nc * for Modeling Geophysical Processes *\nc * *\nc * by *\nc * *\nc * John Adams and Paul Swarztrauber *\nc * *\nc * of *\nc * *\nc * the National Center for Atmospheric Research *\nc * *\nc * Boulder, Colorado (80307) U.S.A. *\nc * *\nc * which is sponsored by *\nc * *\nc * the National Science Foundation *\nc * *\nc * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nc\nc\nc\nc ... geo2math.f\nc\nc file geo2math.f contains subroutines for converting scalar and\nc vector fields between geophysical and mathematical spherical\nc coordinates. The latter is required when using most spherepack\nc software. The four main subroutines in geo2math.f are described\nc as follows:\nc\nc (1) subroutine geo2maths(ig,nlon,nlat,sg,sm,work)\nc\nc converts the nlon by nlat scalar field sg given in\nc geophysical coordinates to the nlat by nlon scalar\nc field sm given in mathematical coordinates. sg and sm\nc can be identical in the program calling geo2maths.\nc\nc (2) subroutine math2geos(ig,nlat,nlon,sm,sg,work)\nc\nc converts the nlat by nlon scalar field sm given in\nc mathematical coordinates to the nlon by nlat scalar\nc field sg given in geophysical coordinates. sm and\nc sg can be identical in the program calling math2geos.\nc\nc (3) subroutine geo2mathv(ig,nlon,nlat,ug,vg,vm,wm,work)\nc\nc converts the nlon by nlat vector field (ug,vg) given\nc in geophysical coordinates to the nlat by nlon vector\nc field (vm,wm) in mathematical coordinates. ug and wm\nc can be identical in the program calling geo2mathv. vg\nc and vm can be identical in the program calling geo2mathv.\nc\nc (4) subroutine math2geov(ig,nlat,nlon,vm,wm,ug,vg,work)\nc\nc converts the nlat by nlon vector field (vm,wm) given\nc in mathematical coordinates to the nlon by nlat vector\nc field (ug,vg) in spherical coordinates. vm and vg can\nc be identical in the program calling math2geov. wm and\nc ug can be identical in the program calling math2geov.\nc\nc *** (1),(2),(3),(4) argument description.\nc\nc ... ig\nc\nc = 0 if the latitude values in the geophysical arrays sg,ug,vg are\nc ordered south to north with increasing latitude subscript\nc i=1,2,...,nlat.\nc\nc = 1 if the latitude values in the geophysical arrays sg,ug,vg are\nc ordered north to south with increasing latitude subscript\nc i=1,2,...,nlat.\nc\nc ... nlon\nc\nc the number of distinct londitude points. nlon determines\nc the grid increment in longitude as 2*pi/nlon. nlon is the first\nc dimension of the geophysical arrays sg,ug,vg and the second\nc dimension of the mathematical arrays sm,vm,wm. The longitude\nc grid is given by phi(j) = (j-1)*2*pi/nlon j=1,...,nlon.\nc\nc ... nlat\nc\nc the number of distinct latitude and colatitude points and the\nc first dimension of sm,vm,wm and second dimension of sg,ug,vg.\nc If the (co)latitude grid is equally spaced then the grid increment\nc is dlat=pi/(nlat-1). In this case the south to north latitude grid\nc underlying is\nc\nc lat(i) = -0.5*pi + (i-1)*dlat (i=1,...,nlat)\nc\nc and the north to south colatitude grid underlying sm,vm,wm is\nc\nc colat(i) = (i-1)*dlat (i=1,...,nlat)\nc\nc If the grid is Gaussian let thetag(i) be the north to south colatitude\nc grid (as computed by the spherepack routine gaqd). In this case\nc\nc colat(i) = thetag(i) (i=1,...,nlat)\nc\nc and\nc\nc lat(i) = -0.5*pi + thetag(i) (i=1,...,nlat)\nc\nc In either case lat(i) = colat(nlat-i+1) for all i.\nc If nlat is odd the equator is located at the (nlat+1)/2\nc latitude or colatitude point. If nlat is even the equator is\nc half way between the nlat/2 and nlat/2+1 latitude or colatitude\nc points. The equally spaced (co)latitude grid includes the poles.\nc The Gaussian grid excludes the poles.\nc\nc ... sg,sm\nc\nc In (1),(2) sg is a nlon by nlat array containing the scalar field\nc in geophysical coordinates. Latitude values in sg are ordered from\nc the southern to the northern hemisphere with increasing latitude\nc subscript if ig = 0 or ordered from the northern hemisphere to the\nc southern hemisphere if ig = 1. sm is a nlat by nlon array containing\nc the scalar field in mathematical coordinates. Colatitude values in sm\nc are ordered from the north to the south hemisphere with increasing\nc colatitude subscript (i=1,...,nlat). The (co)latitude grid for sg and\nc sm can be equally spaced or Gaussian. sg and sm can be equivalenced or\nc be identical in the routine calling geo2maths or math2geos. sg and\nc sm are related by\nc\nc sm(nlat-i+1,j) = sg(j,i) (if ig = 0)\nc\nc or\nc\nc sm(i,j) = sg(j,i) (if ig = 1)\nc\nc for i=1,...,nlat and j=1,...,nlon. This formula is not used because\nc the two arrays can be equivalenced or identical arguments in the\nc program calling geo2maths or math2geos.\nc\nc ... ug,vg,vm,wm\nc\nc In (3),(4) ug is a nlon by nlat array containing the longitudinal\nc vector component. vg is a nlon by nlat array containing the\nc latitudinal vector component. Values in (ug,vg) are ordered\nc from the southern to the northern hemisphere with increasing\nc latitude subscript if ig = 0 or from the northern to southern\nc hemisphere if ig = 1. vm is a nlat by nlon array containing the\nc the colatitudinal vector component. wm is a nlat by nlon array\nc containing the east longitudinal vector component. Values in\nc (vm,wm) are ordered from the northern to the southern hemisphere\nc with increasing colatitude subscript. The (co)latitude grid for\nc both vector fields can be equally spaced or Gaussian. ug,wm and\nc vg,vm can be equivalenced or be identical in the program calling\nc geo2mathv or math2geov. They are related by\nc\nc ug(j,nlat-i+1) = wm(i,j)\nc (ig = 0)\nc vg(j,nlat-i+1) = -vm(i,j)\nc\nc or\nc\nc ug(j,i) = wm(i,j)\nc (ig = 1)\nc vg(j,i) = -vm(i,j)\nc\nc\nc for i=1,...,nlat and j=1,...,nlon. These formulas are not\nc used because ug,wm and vg,vm can be equivalenced or identical\nc arguments in the program calling math2geov or geo2mathv.\nc\nc Let ib = nlat-i+1 for i=1,...,nlat. Summarizing:\nc sg(j,i) or ug(j,i),vg(j,i) are values at (phi(j),lat(i)) if ig = 0\nc sg(j,i) or ug(j,i),vg(j,i) are values at (phi(j),lat(ib)) if ig = 1\nc sm(i,j) or vm(i,j),wm(i,j) are values at (colat(i),phi(j))\nc\nc ... work is an unsaved real work space of length at least nlon*nlat\nc in the routine calling (1),(2),(3), or (4). It is used to simplify\nc a nonsquare array transposition in case it is required.\nc\nc *** example (1)\nc\nc suppose you wish to compute the divergence of (ug,vg) on a Gaussian\nc grid in geophysical coordinates using the stored Legendre polynomial\nc routines of SPHEREPACK\nc\nc (1) call geo2mathv to set vm,wm from ug,vg\nc\nc (2) call vhags to compute the vector harmonic coefficients of vm,wm\nc\nc (3) call divgs with the coefficients from (2) to compute the divergence\nc dv in mathematical spherical coordinates on the UNIT sphere.\nc\nc (4) call math2geos to convert the scalar divergence dv back to\nc geophysical spherical coordinates.\nc\nc (5) divide dv by R (the radius of the earth) to compute divergence\nc on the earth (scaling from unit sphere computation in (3)).\nc\nc *** example (2)\nc\nc suppose you wish to compute a vector field (ug,vg) corresponding\nc to a given divergence dvg and vorticity vtg (all in geophysical\nc coordinates) on an equally spaced (co)latitude grid using the\nc computed Legendre polynomial software.\nc\nc (1) call geo2maths to set dvm from dvg\nc\nc (2) call geo2maths to set vtm from vts\nc\nc (3) call shaec to compute the scalar harmonic coefficients of dvm\nc\nc (4) call shaec to compute the scalar harmonic coefficients of vtm\nc\nc (5) call idvtec to compute (vm,wm) using the coefficients from (3),(4).\nc\nc (6) call math2geov to set (ug,vg) from (vm,wm)\nc\nc (7) multiply (ug,vg) by the earth's radius R for scaling\nc from the unit sphere computation in (5)\nc\nc *** END OF DOCUMENTATION ... CODE FOLLOWS:\nc\nc\n subroutine geo2maths(ig,nlon,nlat,sg,sm,work)\n implicit none\n integer ig,nlon,nlat,i,j,ij\n real sg(nlon,nlat),sm(nlat,nlon),work(*)\nc\nc transpose sg into sm and reverse colatitude subscript order\nc if necessary\nc\n do i=1,nlat\n\tdo j=1,nlon\n\t ij = (j-1)*nlat+i\n\t work(ij) = sg(j,i)\n\tend do\n end do\n if (ig.eq.0) then\n do i=1,nlat\n\tdo j=1,nlon\n\t ij = (j-1)*nlat+i\n\t sm(nlat-i+1,j) = work(ij)\n\tend do\n end do\n else\n do i=1,nlat\n\tdo j=1,nlon\n\t ij = (j-1)*nlat+i\n\t sm(i,j) = work(ij)\n\tend do\n end do\n end if\n return\n end\n\n subroutine math2geos(ig,nlat,nlon,sm,sg,work)\n implicit none\n integer ig,nlon,nlat,i,j,ij\n real sm(nlat,nlon),sg(nlon,nlat),work(*)\nc\nc transpose sm into sg and reverse colatitude subscript order\nc if necessary\nc\n do i=1,nlat\n\tdo j=1,nlon\n\t ij = (j-1)*nlat+i\n\t work(ij) = sm(i,j)\n\tend do\n end do\n if (ig.eq.0) then\n do i=1,nlat\n\tdo j=1,nlon\n\t ij = (j-1)*nlat+i\n\t sg(j,nlat-i+1) = work(ij)\n\tend do\n end do\n else\n do i=1,nlat\n\tdo j=1,nlon\n\t ij = (j-1)*nlat+i\n\t sg(j,i) = work(ij)\n\tend do\n end do\n end if\n return\n end\n\n subroutine geo2mathv(ig,nlon,nlat,ug,vg,vm,wm,work)\n implicit none\n integer ig,nlon,nlat,i,j,ij\n real ug(nlon,nlat),vg(nlon,nlat),work(*)\n real vm(nlat,nlon),wm(nlat,nlon)\nc\nc convert vg to vm, ug to wm\nc\n if (ig.eq.0) then\n\tdo i=1,nlat\n\t do j=1,nlon\n\t ij = (j-1)*nlat+i\n\t work(ij) = vg(j,i)\n\t end do\n\tend do\n\tdo i=1,nlat\n\t do j=1,nlon\n\t ij = (j-1)*nlat+i\n\t vm(nlat-i+1,j) = -work(ij)\n\t end do\n\tend do\n\tdo i=1,nlat\n\t do j=1,nlon\n\t ij = (j-1)*nlat+i\n\t work(ij) = ug(j,i)\n\t end do\n\tend do\n\tdo i=1,nlat\n\t do j=1,nlon\n\t ij = (j-1)*nlat+i\n\t wm(nlat-i+1,j) = work(ij)\n\t end do\n\tend do\n else\n\tdo i=1,nlat\n\t do j=1,nlon\n\t ij = (j-1)*nlat+i\n\t work(ij) = vg(j,i)\n\t end do\n\tend do\n\tdo i=1,nlat\n\t do j=1,nlon\n\t ij = (j-1)*nlat+i\n\t vm(i,j) = -work(ij)\n\t end do\n\tend do\n\tdo i=1,nlat\n\t do j=1,nlon\n\t ij = (j-1)*nlat+i\n\t work(ij) = ug(j,i)\n\t end do\n\tend do\n\tdo i=1,nlat\n\t do j=1,nlon\n\t ij = (j-1)*nlat+i\n\t wm(i,j) = work(ij)\n\t end do\n\tend do\n end if\n return\n end\n\n subroutine math2geov(ig,nlat,nlon,vm,wm,ug,vg,work)\n implicit none\n integer ig,nlon,nlat,i,j,ij\n real vm(nlat,nlon),wm(nlat,nlon),work(*)\n real ug(nlon,nlat),vg(nlon,nlat)\nc\nc convert vm to vg, wm to ug\nc\n if (ig.eq.0) then\n\tdo i=1,nlat\n\t do j=1,nlon\n\t ij = (j-1)*nlat+i\n\t work(ij) = vm(i,j)\n\t end do\n\tend do\n\tdo i=1,nlat\n\t do j=1,nlon\n\t ij = (j-1)*nlat+i\n\t vg(j,nlat-i+1) = -work(ij)\n\t end do\n\tend do\n\tdo i=1,nlat\n\t do j=1,nlon\n\t ij = (j-1)*nlat+i\n\t work(ij) = wm(i,j)\n\t end do\n\tend do\n\tdo i=1,nlat\n\t do j=1,nlon\n\t ij = (j-1)*nlat+i\n\t ug(j,nlat-i+1) = work(ij)\n\t end do\n\tend do\n else\n\tdo i=1,nlat\n\t do j=1,nlon\n\t ij = (j-1)*nlat+i\n\t work(ij) = vm(i,j)\n\t end do\n\tend do\n\tdo i=1,nlat\n\t do j=1,nlon\n\t ij = (j-1)*nlat+i\n\t vg(j,i) = -work(ij)\n\t end do\n\tend do\n\tdo i=1,nlat\n\t do j=1,nlon\n\t ij = (j-1)*nlat+i\n\t work(ij) = wm(i,j)\n\t end do\n\tend do\n\tdo i=1,nlat\n\t do j=1,nlon\n\t ij = (j-1)*nlat+i\n\t ug(j,i) = work(ij)\n\t end do\n\tend do\n end if\n return\n end\n", "meta": {"hexsha": "7cc3baecc79557169970490bbc38894230ef39a1", "size": 13504, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "install/spherepack3.2/src/geo2math.f", "max_stars_repo_name": "comp-physics/RBC3D", "max_stars_repo_head_hexsha": "2891a1e3b356e2cff0cfa74ba26d4aef3336641d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "install/spherepack3.2/src/geo2math.f", "max_issues_repo_name": "comp-physics/RBC3D", "max_issues_repo_head_hexsha": "2891a1e3b356e2cff0cfa74ba26d4aef3336641d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "install/spherepack3.2/src/geo2math.f", "max_forks_repo_name": "comp-physics/RBC3D", "max_forks_repo_head_hexsha": "2891a1e3b356e2cff0cfa74ba26d4aef3336641d", "max_forks_repo_licenses": ["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.3836930456, "max_line_length": 77, "alphanum_fraction": 0.5590936019, "num_tokens": 4098, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256472515683, "lm_q2_score": 0.7853085808877581, "lm_q1q2_score": 0.6610929043980476}} {"text": "c program DRSINT1R\nc>> 1994-10-19 DRSINT1R Krogh Changes to use M77CON\nc>> 1994-08-08 DRSINT1R Snyder Took '0' out of formats for C conversion\nc>> 1991-11-20 CLL Edited for Fortran 90.\nc>> 1987-12-09 DRSINT1R Snyder Initial Code.\nc--S replaces \"?\": DR?INT1R, ?INT1, ?INTA\nc\nc DEMO DRIVER for 1 dimensional quadrature subprogram SINT1.\nc\nc Compute the integral for X = 0.0 to X = PI of SIN(X), then\nc subtract 2.0 from the ANSWER. The result should be zero.\nc\nc The integrand is evaluated using reverse communication.\nc\n real A, B, ANSWER, WORK(1)\n integer IOPT(10)\nc\n10 format (/' DRSINT1R:'/\n 1' Compute the integral for X = 0.0 to X = PI of SIN(X), then'/\n 2' subtract 2.0 from the ANSWER. The result should be zero.')\n20 format (/' ANSWER =',G15.8/\n 1 ' ERROR ESTIMATE =',G15.8/\n 2 ' STATUS FLAG =',I6/\n 3 ' FUNCTION VALUES =',I6)\nc\n print 10\n A = 0.0E0\n B = 4.0E0 * ATAN(1.0E0)\n IOPT(2) = 10\n IOPT(3) = 0\n IOPT(4) = 6\n IOPT(5) = 0\n call SINT1 (A, B, ANSWER, WORK, IOPT)\n 30 continue\n call SINTA (ANSWER, WORK, IOPT)\n if (IOPT(1) .eq. 0) then\n ANSWER = SIN(WORK(1))\n go to 30\n end if\n print 20, ANSWER, WORK(1), IOPT(1), IOPT(3)\n stop\n end\n", "meta": {"hexsha": "9b916ecc9ffef6c4a2953f75877f4b6c5802ff26", "size": 1342, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drsint1r.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drsint1r.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drsint1r.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": 31.2093023256, "max_line_length": 72, "alphanum_fraction": 0.5730253353, "num_tokens": 507, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.7577943822145998, "lm_q1q2_score": 0.6610599398708017}} {"text": "module prescribe_grav_module\n\n use amrex_fort_module, only : rt => amrex_real\n implicit none\n\ncontains\n \n subroutine ca_prescribe_grav (lo,hi,grav,g_lo,g_hi,dx) &\n bind(C, name=\"ca_prescribe_grav\")\n\n use amrex_constants_module, only: ZERO\n use prob_params_module, only: dim\n\n use amrex_fort_module, only : rt => amrex_real\n implicit none\n\n integer, intent(in) :: lo(3), hi(3)\n integer, intent(in) :: g_lo(3), g_hi(3)\n real(rt), intent(out):: grav(g_lo(1):g_hi(1),g_lo(2):g_hi(2),g_lo(3):g_hi(3),dim)\n real(rt), intent(in) :: dx(3)\n\n ! Local variables\n ! integer :: i, j, k\n ! real(rt) :: x, y, z\n ! real(rt) :: r, maggrav\n ! real(rt) :: r_c, rho_c\n\n ! This is an example of how to specify a radial profile.\n ! Note that in this example r_c and rho_c could be saved \n ! in another module instead, like a probdata_module.\n ! Note also that you'll have to be careful if you're working\n ! in fewer than three dimensions; you may want to set\n ! z = 0 for 2D and y = 0 for 1D.\n !\n ! r_c = 1.0e9_rt\n ! rho_c = 1.0e8_rt\n !\n ! do k = lo(3), hi(3)\n ! if (dim .eq. 3) then \n ! z = problo(3) + (dble(k)+HALF) * dx(3) - center(3)\n ! else\n ! z = ZERO\n ! endif\n !\n ! do j = lo(2), hi(2)\n ! if (dim .ge. 2) then\n ! y = problo(2) + (dble(j)+HALF) * dx(2) - center(2)\n ! else\n ! y = ZERO\n ! endif\n !\n ! do i = lo(1), hi(1)\n ! x = problo(1) + (dble(i)+HALF) * dx(1) - center(1)\n !\n ! r = sqrt(x**2+y**2+z**2)\n !\n ! maggrav =-rho_c*Gconst*2*M_PI*(1/sqrt(1+(r/r_c)**2)-atanh(1/sqrt(1+(r/r_c)**2)))\n !\n ! Put in angular dependence\n !\n ! grav(i,j,k,1) = maggrav* ...\n ! grav(i,j,k,2) = maggrav* ...\n ! grav(i,j,k,3) = maggrav* ...\n !\n ! enddo\n ! enddo\n ! enddo\n\n grav(lo(1):hi(1),lo(2):hi(2),lo(3):hi(3),:) = ZERO\n\n end subroutine ca_prescribe_grav\n\nend module prescribe_grav_module\n", "meta": {"hexsha": "b08a77d82e99e6c9ecd921de11f6430fe9866552", "size": 2249, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Source/gravity/prescribe_grav_nd.f90", "max_stars_repo_name": "harpolea/Castro", "max_stars_repo_head_hexsha": "96f45b5b0ffe1be4a660bbe9ff38ce5216760ff4", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-06-05T19:23:47.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-05T19:23:47.000Z", "max_issues_repo_path": "Source/gravity/prescribe_grav_nd.f90", "max_issues_repo_name": "harpolea/Castro", "max_issues_repo_head_hexsha": "96f45b5b0ffe1be4a660bbe9ff38ce5216760ff4", "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": "Source/gravity/prescribe_grav_nd.f90", "max_forks_repo_name": "harpolea/Castro", "max_forks_repo_head_hexsha": "96f45b5b0ffe1be4a660bbe9ff38ce5216760ff4", "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": 30.3918918919, "max_line_length": 99, "alphanum_fraction": 0.4815473544, "num_tokens": 757, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6610599350990793}} {"text": "program problem21\n use euler\n implicit none\n integer, parameter :: n = 10000\n integer*8 :: i, temp, sum\n\n sum = 0\n do i=1,n-1\n temp=sum_of_divisors(i)\n if ((i /= temp) .and. (sum_of_divisors(temp) == i)) then\n sum=sum+i\n end if\n end do\n\n print *, sum\n\nend program problem21\n\n", "meta": {"hexsha": "fce928f89873f7522c23986de0b8b94d8ec83291", "size": 311, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "problem21.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": "problem21.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": "problem21.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": 16.3684210526, "max_line_length": 61, "alphanum_fraction": 0.5852090032, "num_tokens": 103, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8723473813156294, "lm_q2_score": 0.7577943658046609, "lm_q1q2_score": 0.661059930585434}} {"text": "program HC_SCE\n implicit none\n INTEGER,parameter :: dp=8\n REAL(dp),allocatable :: H(:,:),S(:,:),C(:,:),E(:),B(:),A(:,:),X(:),Y(:),work(:),iwork(:),wr(:),wi(:),vs(:,:)\n INTEGER,allocatable :: ipiv(:)\n INTEGER :: m,n,k,i,j,INFO,NRHS,incx,lwork,liwork,sdim,ldvs\n LOGICAL,allocatable :: select(:,:),bwork(:)\n \n m=5\n n=5\n k=5\n allocate(H(m,k),S(k,n),B(n),C(m,n))\n H = reshape((/ -0.42400401342556060 , -0.40143227390650277 , -6.9120337961858791E-006 , &\n& 8.6134463450626697E-010 , -6.9147694707777760E-006 , -0.40143227390650238 , &\n& -0.29964623883643193 , -8.9726936647882560E-006 , 4.9061116280668671E-010 , &\n& -8.9740202969982782E-006 , -6.9120337962066958E-006 , -8.9726936648298894E-006 , &\n& 0.80413378049744566 , -1.8838840210033680E-010 , -3.8197224985613721E-007 , &\n& 8.5924509174439834E-010 , 4.8774366490089704E-010 , -1.8838840210033680E-010 , &\n& 0.80417210170273057 , 1.5203947981790279E-011 , -6.9147694707755170E-006 , &\n& -8.9740202969951222E-006 , -3.8197224985613721E-007 , 1.5203950672231617E-011 ,&\n& 0.80413378335169927/),(/m,k/))\n S = reshape( (/1.0000000107623999 , 0.95479507666315644 , 0.0000000000000000 , 5.3953328491069285E-013 , 0.0000000000000000 , 0.95479507666315644 , 0.99999999999886702 , 0.0000000000000000 , 6.3781864686742656E-013 , 0.0000000000000000 , 0.0000000000000000 , 0.0000000000000000 , 1.0000000364970107 , 0.0000000000000000 , 0.0000000000000000 , -5.3953328491104808E-013 , -6.3781864686711637E-013 , 0.0000000000000000 , 1.0000000364970068 , 0.0000000000000000 , 0.0000000000000000 , 0.0000000000000000 , 0.0000000000000000 , 0.0000000000000000 , &\n & 1.0000000364970110/),(/k,n/))\n \n B = reshape( (/1.0,2.0,3.0,4.0,5.0/),(/5/))\n write(*,*) \"H is ------------------\"\n do i =1,5\n write(*,*) \" \",H(i,:)\n enddo\n write(*,*) \"S is ------------------\"\n do i =1,5\n write(*,*) \" \",S(i,:)\n enddo\n write(*,*) \"B is ------------------\"\n write(*,*) B \n!-----------------------------------------------------------------------------------------------------------------------------------\n! BLACS\u57fa\u7840\u529f\u80fd\n!-----------------------------------------------------------------------------------------------------------------------------------\n \n \n!********************************\n!GEMV \u77e9\u9635\u5411\u91cf\u4e58\n!********************************\n!call dgemv(trans, m, n, alpha, a, lda, x, incx, beta, y, incy)\n allocate(X(2*n),Y(n))\n X(1:n)=B\n X(n+1:2*n)=B\n Y=0\n incx=1\n call dgemv('N',m,n,1.0_dp,H,m,X,incx,1.0_dp,Y,1)\n !X(incx,incx+n-1)\n !Y(incy,incy+m-1)\n !incx \u5411\u91cf\u7684\u521d\u59cb\u5143\u7d20\n write(*,*) \"H*B is --------------------\"\n write(*,*) Y\n deallocate(X,Y)\n!********************************\n!SYMV \u5bf9\u79f0\u77e9\u9635*\u5411\u91cf\n!********************************\n!\u9488\u5bf9A\u662f\u7279\u6b8a\u7684\u5bf9\u79f0\u77e9\u9635\u65f6\n!\u53c2\u6570\u548cGESV\u4e0d\u540c\n!call dsymv(uplo, n, alpha, a, lda, x, incx, beta, y, incy)\n!y := alpha*A*x + beta*y,\n!uplo \n! If uplo = 'U' or 'u', then the upper triangular part of the array a is used.\n! If uplo = 'L' or 'l', then the low triangular part of the array a is used.\n!https://scc.ustc.edu.cn/zlsc/tc4600/intel/2017.0.098/mkl/common/mklman_f/index.htm#GUID-2EB693ED-69F3-48C7-B100-31F030797DDD.htm\n\n allocate(X(2*n),Y(n))\n X(1:n)=B\n X(n+1:2*n)=B\n incx=2\n !X(1,1+incx,1+2*incx,....,1+n*incx)`,\u5411\u91cf\u7684\u53d6\u6837\u95f4\u9694\n call dsymv('U',m,1.0_dp,H,m,X,incx,0.0_dp,Y,1)\n write(*,*) \"H*[B,B](1:2:2n) symv is --------------\"\n write(*,*) Y\n deallocate(X,Y)\n\n!********************************\n!GEMM \u77e9\u9635\u4e58\n!********************************\n!DGEMM\n!D:double precision\n!GE:general matrix\n!MM:matrix-matrix\n call DGEMM('N','N',m,n,k,1.0_dp,H,m,S,k,0.0_dp,C,m)\n !C=alpha*OP(H)*OP(S)+beta*C\n write(*,*) \"*********DGEMM***********\"\n write(*,*) \"H*S is ------------------\"\n do i =1,5\n write(*,*) \" \",C(i,:)\n enddo\n\n!!```\n!\n!******************************\n! ![](/uploads/2019/08/gemm.jpg)\n!******************************\n!-----------------------------------------------------------------------------------------------------------------------------------\n! Driver Routines\n!-----------------------------------------------------------------------------------------------------------------------------------\n\n\n! ### Driver Routines\n! Driver Routines \u4f7f\u7528\u6765\u89e3\u7edd\u7279\u5b9a\u95ee\u9898(\u5982HC=SCE)\u7684\u7a0b\u5e8f\n! Computational Routines \u5b8c\u6210\u7279\u5b9a\u7684\u8ba1\u7b97\u4efb\u52a1\u6bd4\u5982LU\u5206\u89e3\n! \u53ef\u4ee5\u7406\u89e3Driver Routines\u8c03\u7528Computational Routines\u5b8c\u6210\u7279\u5b9a\u95ee\u9898\n! #### \u7ebf\u6027\u65b9\u7a0b\u7ec4 | AX=B \n\n!!```\n write(*,*) \"=================================================================\"\n write(*,*) \"======================Driver Routines============================\"\n write(*,*) \"=================================================================\"\n\n \n write(*,*) \"***************************************\"\n write(*,*) \"************* AX=B ******************\"\n write(*,*) \"***************************************\"\n!********************************\n![A]{X}={B} \u7ebf\u6027\u95ee\u9898,B\u53ef\u4e3a\u77e9\u9635\u6216\u5411\u91cf\n!-SV simple,LU\u5206\u89e3\u6c42\u89e3,B\u662f\u6807\u91cf\n!-SVX expert,LU\u5206\u89e3\uff0c\u6bd4-SV\u63d0\u4f9b\u66f4\u591a\u7684\u529f\u80fd\uff0c\u6bd4\u5982\u8bef\u5dee\u5206\u6790\u7b49\n!-SVM B\u662f\u77e2\u91cf\n!-TRSM B(m,n) Solves a triangular matrix equation.\n !call dtrsm(side, uplo, transa, diag, m, n, alpha, a, lda, b, ldb)\n !X and B are m-by-n matrices,\n!-TRSVB(m) Solves a system of linear equations whose coefficients are in a triangular matrix.\n !call dtrsv(uplo, trans, diag, n, a, lda, x, incx)\n !b and x are n-element vectors,\n!********************************\n allocate(A(m,m),X(m),ipiv(m))\n A=H\n X=B\n NRHS=1\n call DGESV(m,NRHS,A,m,ipiv,X,m,INFO)\n !Hx=X,\u7ed3\u679c\u4fdd\u5b58\u5230X\u4e2d\uff0c\n !A LU\u5206\u89e3\u540e\u4fdd\u5b58\u5230A\u4e2d\n ! A\u7684\u4e0a\u4e09\u89d2\u662fU\n ! A\u7684\u4e0b\u4e09\u89d2(\u4e0d\u5305\u62ec\u5bf9\u89d2\u7ebf)\u662fL\n ! MATLAB [l,u,p]=lu(H)\n !m: A(m,m)\n !NRHS=1: X\u662f\u4e00\u7ef4\u7684,\u82e5\u4e3aAX=C(m,:)\u65f6\uff0cNRHS=m\n write(*,*) \"H LU is ------------------\"\n do i =1,5\n write(*,*)\" \", A(i,:)\n enddo\n write(*,*) \"root of HX=B(-GESV) is ----------\"\n write(*,*) X\n \n A=H\n X=B\n NRHS=1\n lwork=1!INTEGER. The size of the work array; lwork \u2265 1.\n allocate(work(lwork))!work is a workspace array, dimension at least max(1,lwork).\n !call dsysv( uplo, n, nrhs, a, lda, ipiv, b, ldb, work, lwork, info )\n call DSYSV('U',m,NRHS,A,m,ipiv,X,m,work,lwork,INFO)\n deallocate(work)\n write(*,*) \"root of HX=B(-SYSV) is ----------\"\n write(*,*) X\n\n A=H\n C=S\n NRHS=m\n call DGESV(m,NRHS,A,m,ipiv,C,m,INFO)\n write(*,*) \"root of HX=C is ----------\"\n do i =1,5\n write(*,*) \" \",C(i,:)\n enddo\n deallocate(A,X,ipiv) \n \n!!```\n!********************************\n! ![](/uploads/2019/08/gesv.jpg)\n!********************************\n\n \n! #### \u6700\u5c0f\u4e8c\u4e58\u95ee\u9898 | LLS(Linear Leqat squares problems)\n! `||Ax-b||2`\n\n!!```\n write(*,*) \"***************************************\"\n write(*,*) \"********* min(||AX-B||2) ************\"\n write(*,*) \"***************************************\"\n!*******************************\n!\u627e\u5230X\u4f7f\u5f97 (b(m)-A(m,n))\u76842\u8303\u6570||AX-B||2\u6700\u5c0f\n! -LS \u4f7f\u7528LU\u6216QR\u5206\u89e3\u8ba1\u7b97\n! -LSX \n! -LSS SVD\u5947\u5f02\u503c\u5206\u89e3\n!*******************************\n!QR \u8bbe A(m,n). \u5219\u5b58\u5728\u4e00\u4e2a\u5355\u4f4d\u5217\u6b63\u4ea4\u77e9\u9635 Q(M,n) (\u5373 Q\u2217Q = I ) \u548c\u4e00\u4e2a\u4e0a\u4e09\u89d2\u77e9\u9635 R \u2208Cn\u00d7n, \u4f7f\u5f97A=Q*R\n!call dgels(trans, m, n, nrhs, a, lda, b, ldb, work, lwork, info)\n allocate(A(m,n),X(n))\n A=H\n X=B\n NRHS=1\n lwork=min(m,n)+max(1,m,m,NRHS) !The size of the work array; must be at least min (m, n)+max(1, m, n, nrhs).\n allocate(work(max(1,lwork)))\n call DGELS('N',m,n,NRHS,A,m,X,n,work,lwork,INFO)\n !\u8fd4\u56de\u503cA\u4e0eMATLAB X=qr(H)\u8fd4\u56de\u503c\u4e00\u6837\n !A\u7684\u53f3\u4e0a\u89d2\u4e0e[Q,R]=qr(H)\u4e2d\u7684R\u4e00\u6837,\u6682\u65f6\u4e0d\u77e5\u9053QR\u5206\u89e3\u7684\u4e0b\u77e9\u9635\u662f\u4ec0\u4e48\n deallocate(work)\n write(*,*) \"H QR is ------------------\"\n do i =1,5\n write(*,*) \" \",A(i,:)\n enddo \n write(*,*) \"min(||AH-B||2), when X is (-GELS)\"\n write(*,*) X\n deallocate(A,X)\n \n!! ```\n\n! #### \u6807\u51c6\u672c\u5f81\u503c\u95ee\u9898AX=EX\n! ##### \u5bf9\u79f0\u672c\u5f81\u503c\u95ee\u9898|SEP(Symmetric eigenproblems)\n! Ax=Ex ,A=A^T(real) A=A^H(complex)\n!!```\n write(*,*) \"***************************************\"\n write(*,*) \"************* AX=EX *****************\"\n write(*,*) \"***************************************\"\n!********************************\n!********************************\n!AX=EX \u672c\u5f81\u503c\u95ee\u9898\n!-SYEV simple,L U \u5206\u89e3\n!-SYEVX expert,\u6bd4-EV\u63d0\u4f9b\u66f4\u591a\u7684\u529f\u80fd\uff0c\u6bd4\u5982\u8bef\u5dee\u5206\u6790\u7b49\n!-SYEVD \u4e0d\u540c\u7684\u7b97\u6cd5\u800c\u5df2;\u6839\u636e\u6d4b\u8bd5EVR\u6700\u5feb,EVD\u6b21\u4e4b,SIESTA\u91c7\u7528\u7684EVD\n!-SYEVR \u4e0d\u540c\u7684\u7b97\u6cd5\u800c\u5df2;\u6d4b\u8bd5[LAPACK Benchmark](https://www.netlib.org/lapack/lug/node71.html)\n!-SYEVX \u4e0d\u540c\u7684\u7b97\u6cd5\u800c\u5df2;\u5982\u56fe![Figure 3.2: Timings of driver routines for computing all eigenvalues and eigenvectors of a dense symmetric matrix. The upper graph shows times in seconds on an IBM Power3. The lower graph shows times relative to the fastest routine DSYEVR, which appears as a horizontal line at 1.](/uploads/2019/08/img255.gif)\n!********************************\n!call dsyev(jobz, uplo, n, a, lda, w, work, lwork, info)\n!jobz = 'N', then only eigenvalues are computed.\n!jobz = 'V', then eigenvalues and eigenvectors are computed.\n!uplo=\"U\" or \"L\", \u5206\u89e3\u5b58\u50a8A\u7684\u65b9\u5f0f\n!work is a workspace array, its dimension max(1, lwork). \n!lwork \u2265 max(1, 3n-1).\n!w\u672c\u5f81\u503cArray, size at least max(1, n)\n!\u82e5jobz='V',A\u5b58\u50a8\u672c\u5f81\u77e2\u91cf,\u4e00\u5217\u662f\u4e00\u4e2a\u672c\u5f81\u77e2,A(i,:)\u7684\u672c\u5f81\u503c\u4e3aw(i)\n!\u82e5jobz='N',A\u5b58\u50a8A\u7684L/U(uplo='L'/'U')\u4f1a\u88ab\u7528\u4e8e\u8ba1\u7b97\uff0c\u5e76\u65e0\u610f\u4e49\uff0c\u4e0d\u662fLU\u5206\u89e3\n!MATLAB\u4e2dlu(H),[l,u]=lu(H),[l,u,p]=lu(H)\u7684\u7ed3\u679c\u4e0d\u4e00\u6837\n allocate(A(n,n),E(n))\n A=H\n E=0\n lwork=max(1,3*n-1)\n allocate(work(lwork))\n call DSYEV('V','U',n,A,n,E,work,lwork,INFO)\n deallocate(work)\n write(*,*) \"HX=wX; w is ------------------\"\n write(*,*) E\n write(*,*) \"HX=wX; vectors is ------------------\"\n do i =1,5\n write(*,*) \" \",A(i,:)\n enddo\n !H=U*U^T;U*U^T*X=EX\n !C=U^T*U;Cy=Ey, y=U^T*X\n deallocate(A,E)\n!! ```\n\n! ##### \u975e\u5bf9\u79f0\u672c\u5f81\u503c\u95ee\u9898|NEP(Nonsymmetric eigenproblems) \n! Ax=Ex ,A=QTQ^T(real) A=QTQ^H(complex)\n! Q\u5e7a\u6b63\u77e9\u9635,T\u4e0a\u4e09\u89d2\u77e9\u9635\n!!```\n!********************************\n!AX=EX \u672c\u5f81\u503c\u95ee\u9898\n!-GEES simple Schur\u56e0\u5b50\n!-GEESX expert,\u6bd4-GEES\u63d0\u4f9b\u66f4\u591a\u7684\u529f\u80fd\uff0c\u6bd4\u5982\u8bef\u5dee\u5206\u6790\u7b49\n!-GEEV \u672c\u5f81\u503c\u672c\u5f81\u77e2\n!-GEEVX expert\n!********************************\n!\u7a0b\u5e8f\u9047\u5230\u95ee\u9898\uff0c\u5148\u6401\u7f6e\n\n\n!Error: ! !call dgees(jobvs, sort, select, n, a, lda, sdim, wr, wi, vs, ldvs, work, lwork, bwork, info)\n!Error: ! !wr(>=n),wi(>=n)\u672c\u5f81\u503c\u7684\u5b9e\u90e8\u865a\u90e8,\u662fT\u7684\u5bf9\u89d2\u5143\u7d20\n!Error: ! !Arrays, size at least max (1, n) each. \n!Error: ! !Contain the real and imaginary parts, respectively, of the computed eigenvalues, \n!Error: ! !in the same order that they appear on the diagonal of the output real-Schur form T. Complex conjugate pairs of eigenvalues appear consecutively with the eigenvalue having positive imaginary part first.\n!Error: ! !select:\u662f\u4e00\u4e2a\u51fd\u6570\u53c2\u6570\uff0c\u903b\u8f91\u578b\n!Error: ! allocate(A(n,n),E(n))\n!Error: ! A=H\n!Error: ! E=0\n!Error: ! allocate(wr(n),wi(n))\n!Error: ! lwork=max(1,3*n)\n!Error: ! allocate(work(lwork))\n!Error: ! ldvs=n\n!Error: ! allocate(vs(ldvs,n))\n!Error: ! allocate(bwork(n))\n!Error: ! allocate(select(n,n))\n!Error: ! select=.true.\n!Error: ! bwork=.true.\n!Error: ! \n!Error: ! call DGEES('V','S',select,n,A,n,sdim,wr,wi,vs,ldvs,work,lwork,bwork,info)\n!Error: ! \n!Error: ! \n!Error: ! deallocate(bwork)\n!Error: ! deallocate(vs)\n!Error: ! deallocate(work)\n!Error: ! deallocate(wr,wi)\n!Error: ! deallocate(A,E)\n \n!! ```\n\n\n! ##### \u5947\u5f02\u503c\u95ee\u9898|SVD(Singular value decomposion)\n!! ```\n!********************************\n!\u6682\u65f6\u8fd8\u4e0d\u61c2\n!-GESVD \n!********************************\n!! ```\n\n! ### \u5e7f\u4e49\u7684\u672c\u5f81\u503c\u95ee\u9898 | Generalized eigenvalue problems\n! #### \u5bf9\u79f0\u7684\u672c\u5f81\u503c\u95ee\u9898|**GSEP** Generalized symmetric-definite eigenproblems\n! AX=EBX\n! ABX=EX\n! BAX=EX\n! \u5176\u4e2dA,B\u662f\u5bf9\u79f0\u7684\u6216\u54c8\u5bc6\u987f\u91cf \uff0c **B\u662f\u6b63\u5b9a\u7684**\n!! ```\n!********************************\n!-SYGV\n!-HEGV\n!-SPGV\n!-HPGV\n!********************************\n!call dsygv(itype, jobz, uplo, n, a, lda, b, ldb, w, work, lwork, info)\n!itype\n! itype = 1, the problem type is A*x = lambda*B*x;\n! itype = 2, the problem type is A*B*x = lambda*x;\n! itype = 3, the problem type is B*A*x = lambda*x.\n! jobz = 'N' or 'U'\n! B\u8f93\u5165\u77e9\u9635\u548c\u8f93\u51fa\u672c\u5f81\u77e2\u91cf\n\n allocate(A(n,n),E(n))\n A=H\n C=S\n E=0\n lwork=max(1,3*n-1)\n allocate(work(lwork)) \n call DSYGV(1,'V','U',n,A,n,C,n,E,work,lwork,INFO)\n !\u7b97\u5b8c\u540e\uff0cA\u88ab\u8986\u76d6\u4e86\u4e00\u5806\u4e2d\u95f4\u6570\u636e\n write(*,*) \"HC=SCE; E is ------------------\" \n write(*,*) E\n write(*,*) \"HC=SCE; C is ------------------\" \n do i =1,5\n write(*,*) \" \",C(i,:)\n enddo \n deallocate(work)\n deallocate(A,E)\n\n!! ```\n\n! #### \u5e7f\u4e49\u975e\u5bf9\u79f0\u7684\u672c\u5f81\u503c\u95ee\u9898|**GNEP** Generalized nonsymmetric eigenproblems\n!! ```\n!********************************\n!-GEES\n!-GEESX\n!-GEEV\n!-GEEVX\n!********************************\n!\u6682\u65f6\u61d2\u5f97\u770b\u4e86\n!! ```\n\n\n\n\n\n\n\n\n!-----------------------------------------------------------------------------------------------------------------------------------\n!Computational Routines\n!-----------------------------------------------------------------------------------------------------------------------------------\n! ### Computational Routines\n!\u81ea\u5df1\u7ec4\u5408Computational Routines\u6765\u89e3\u51b3\u4e00\u4e2a\u95ee\u9898\uff0c\u5982\u5206\u89e3\uff0c\u53d8\u4e3a\u4e09\u89d2\u9635\n!\u901a\u5e38\u7684\u8fc7\u7a0b,\u5148\u5206\u89e3(factorize -TRF)\u518d\u5904\u7406,\u5982\u6c42\u9006(-TRI)\u3001\u6c42GSEP(-SYGST)\u7b49\n! \u901a\u8fc7\u8fd9\u4e9b\u7a0b\u5e8f\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u4e00\u6b65\u6b65\u5b9e\u73b0\u5206\u89e3(LU,chol,QR...),\u89e3\u51b3\u7ebf\u6027\u65b9\u7a0b,LLS,SVD,(\u5e7f\u4e49)\u672c\u5f81\u503c\u95ee\u9898\n! \u4e0b\u9762\u4e3a\u51e0\u4e2a\u793a\u4f8b\n! #### Facrotize\u5206\u89e3(-TRF)\n! \u4e0d\u540c\u7c7b\u578b\u7684\u77e9\u9635\u5206\u89e3\u7ed3\u679c\u4e0d\u540c\uff0c\u5982[Routines for Matrix Factorization](https://scc.ustc.edu.cn/zlsc/tc4600/intel/2017.0.098/mkl/common/mklman_f/index.htm#GUID-2EB693ED-69F3-48C7-B100-31F030797DDD.htm)\n!! ```\n write(*,*) \"=================================================================\"\n write(*,*) \"======================Computational Routine======================\"\n write(*,*) \"=================================================================\"\n!*********************************\n!- \u901a\u5e38\u7684\u77e9\u9635:\uff1aLU\u5206\u89e3 `-GETRF` A=PLU\n!- \u6b63\u5b9a\u5bf9\u79f0\u77e9\u9635\uff1aCholesky \u5206\u89e3 `-POTRF` A=U^T*U or L*L^T\n!- \u5bf9\u79f0\u975e\u6b63\u5b9a\u77e9\u9635\uff1a\u7cfb\u7edf\u975e\u6b63\u5b9a\u5206\u89e3 `-SYTRF` A=P^TU^TDUP or PLDL^TP^T\n!*********************************\n\n!******\n!LU\u5206\u89e3\n!******\n write(*,*) \"***************************************\"\n write(*,*) \"********* LU -> AX=B H^-1************\"\n write(*,*) \"***************************************\"\n!call dgetrf( m, n, a, lda, ipiv, info )\n!\u8fd4\u56de\u503cA,ipiv\u53ef\u7528\u4e8e\u540e\u7eed\u8ba1\u7b97\n allocate(A(m,n),E(n))\n A=H\n E=B\n allocate(ipiv(m))\n call DGETRF(m,n,A,m,ipiv,INFO)\n write(*,*) \"lu(H) is ------------------\"\n do i =1,5\n write(*,*) \" \",A(i,:)\n enddo\n!LU\u5206\u89e3\u6c42HX=B\u793a\u4f8b \n!call dgetrs( trans, n, nrhs, a, lda, ipiv, b, ldb, info )\n!Solves a system of linear equations with an LU-factored square coefficient matrix, with multiple right-hand sides.\n!ldbINTEGER. The leading dimension of b; ldb \u2265 max(1, n)\n!**ipiv \u662f-GETRF\u7684\u8fd4\u56de\u503c**\n!**A\u4e5f\u662f-GERTF\u7684LU\u5206\u89e3\u540e\u7684\u77e9\u9635***\n!ipiv Array, size at least max(1, n). The ipiv array, as returned by ?getrf.\n call DGETRS('N', n,1,A,m,ipiv,E,n,INFO)\n write(*,*) \"use lu(H) to solve HX=B, X is \"\n write(*,*) E\n!\u8ba1\u7b97\u4e4b\u540e\uff0c\u4e0d\u4f1a\u6539\u53d8A\u548cipiv\u7684\u503c\n\n!LU\u5206\u89e3\u6c42\u9006A^-1\u793a\u4f8b\n! invert using factorization\n!call dgetri( n, a, lda, ipiv, work, lwork, info )\n lwork=n\n allocate(work(lwork))\n call DGETRI(n,A,m,ipiv,work,lwork,INFO)\n write(*,*) \"use lu(H) to get H^-1:\"\n do i =1,5\n write(*,*) \" \",A(i,:)\n enddo \n deallocate(work) \n deallocate(ipiv)\n deallocate(A,E)\n\n\n\n!********************** \n!Cholesky factorization\n!********************** \n write(*,*) \"***************************************\"\n write(*,*) \"***** Cholesky -> S^-1 HC=ESC ********\"\n write(*,*) \"***************************************\" \n!call dpotrf( uplo, n, a, lda, info ) \n allocate(A(m,n),E(n))\n A=H\n C=S\n E=B\n call DPOTRF('U',n,C,m,INFO)\n !\u4e0a\u90e8\u5206\u53d8\u4e3aU,\u4e0b\u4e09\u89d2\u90e8\u5206\u4e0d\u53d8\n write(*,*) \"chol(S) is: -----------\"\n do i =1,5\n write(*,*) \" \",C(i,:)\n enddo\n!chol\u5206\u89e3\u6c42HX=B\u793a\u4f8b \n!call dpotrs( uplo, n, nrhs, a, lda, b, ldb, info )\n call DPOTRS('U',n,1,C,m,E,m,INFO)\n write(*,*) \"use chol(S) to solve SX=B, X is \"\n write(*,*) E \n!chol\u5206\u89e3\u6c42\u9006A^-1\u793a\u4f8b\n!call dpotri( uplo, n, a, lda, info ) \n call DPOTRI('U',n,C,m,INFO)\n !\u7ed3\u679cinv(C)\u4e5f\u662f\u5bf9\u79f0\u7684\uff0c\u6240\u4ee5\uff0cC\u7684\u4e0a\u4e09\u89d2\u77e9\u9635\u662f\u9006\uff0c\u4e0b\u4e09\u89d2\u4f9d\u65e7\u6ca1\u53d8\n write(*,*) \"use chol(S) to get S^-1:\"\n do i =1,5\n write(*,*) \" \",C(i,:)\n enddo \n!chol\u5206\u89e3\u6c42\u5e7f\u4e49\u672c\u5f81\u503cHC=SCE\u793a\u4f8b\n\n\n A=H\n C=S\n E=0.0_dp\n write(*,*) \"use chol(S) to solve HC=SCE\"\n write(*,*) \" HC=SCE(-POTRF): 1. S=U^T*U,y=UC\"\n!***\n call DPOTRF('U',n,C,m,INFO)\n !C=U*U^T,\u4ec5\u6539\u53d8C\u7684\u4e0a\u4e09\u89d2\n!***\n write(*,*) \" HC=SCE(-SYGST): 2. tmpC=inv(U^-T)*H*inv(U)\"\n!call dsygst(itype, uplo, n, a, lda, b, ldb, info)\n!The routine reduces real symmetric-definite generalized eigenproblems\n!A*z = \u03bb*B*z, A*B*z = \u03bb*z, or B*A*z = \u03bb*z\n!itype=1, 2, 3\n!to the standard form C*y = \u03bb*y. \n!Here A is a real symmetric matrix, \n!and B is a real symmetric positive-definite matrix. \n!Before calling this routine, call ?potrf to compute the Cholesky factorization: B = UT*U or B = L*LT.\n call DSYGST(1,'U',n,A,m,C,m,INFO)\n !A=inv(U^T)*A*inv(U)\uff0c\u4ec5\u6539\u53d8A\u7684\u4e0a\u4e09\u89d2\n!***\n write(*,*) \" HC=SCE(-SYEV?): 3. tmpCy=Ey(\u672c\u5f81\u503c\u95ee\u9898)\"\n!call dsyevd(jobz, uplo, n, a, lda, w, work, lwork, iwork, liwork, info)\n lwork=2*n*n + 6*n + 1\n allocate(work(lwork))\n liwork= 5*n + 3\n allocate(iwork(liwork))\n call DSYEVD('V','U',n,A,m,E,work,lwork,iwork,liwork,INFO)\n !y\u4fdd\u5b58\u5230A\u4e2d\u4e86\n write(*,*) \" HC=SCE(-SYEV?): E is:\"\n write(*,*) \" \", E\n!***\n write(*,*) \" HC=SCE(-SYEV?): 4. y=UC,(\u7ebf\u6027\u65b9\u7a0b\u95ee\u9898)\"\n !\u53ef\u9009\u65b9\u6848\u5f88\u591a\uff0c\n !a. inv(U)*y\n !\u56e0\u4e3aU\u5df2\u7ecf\u4e0a\u4e09\u89d2\u4e86\n !b. Dirver routines\u89e3\u65b9\u7a0b -TRSM(B(m,n), -TRSV(B(n)) \n !c. Computational routines -TRTRS \n!call dtrsm(side, uplo, transa, diag, m, n, alpha, a, lda, b, ldb) B=AX\n!call dtrtrs( uplo, trans, diag, n, nrhs, a, lda, b, ldb, info )\n!AX=B\u7ed3\u679c\u8f93\u51fa\u5230B\n![Fortran\u4f7f\u7528Scalapack\u6c42\u89e3HC=SCE](/2019/08/04/HC_SCE)\u6b64\u6587\u91c7\u7528\u7684TRSM\n!\u6b64\u5904\u91c7\u7528TRTRS\n call DTRTRS('U','N','N',n,n,C,m,A,m,INFO)\n write(*,*) \" HC=SCE(-TRTRS): C is:\"\n do i =1,5\n write(*,*) \" \",A(i,:)\n enddo \n deallocate(work,iwork)\n \n!! ```\n! \u9664\u4e86\u4e0a\u8ff0\u4e4b\u5916\uff0c\u8fd8\u6709\u5f88\u591a\u7684computational routines\n! \u5148\u8fd9\u6837\u5427,\u8865\u5145\u76f8\u5173\u77e5\u8bc6\u540e\u518d\u56de\u6765\u8865\u5145\n\n deallocate(H,S,B,C)\n\n \nend program HC_SCE\n", "meta": {"hexsha": "64f0655f60e032e84737da7600889e0b2b12b7a0", "size": 18071, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "web/file/2019/main.f90", "max_stars_repo_name": "cndaqiang/cndaqiang.github.io", "max_stars_repo_head_hexsha": "e85b0531cf9f8c58fd475ee993473ecc41485495", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-09-13T12:28:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T10:10:33.000Z", "max_issues_repo_path": "web/file/2019/main.f90", "max_issues_repo_name": "cndaqiang/cndaqiang.github.io", "max_issues_repo_head_hexsha": "e85b0531cf9f8c58fd475ee993473ecc41485495", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 55, "max_issues_repo_issues_event_min_datetime": "2019-06-18T06:50:38.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-20T07:43:54.000Z", "max_forks_repo_path": "web/file/2019/main.f90", "max_forks_repo_name": "cndaqiang/cndaqiang.github.io", "max_forks_repo_head_hexsha": "e85b0531cf9f8c58fd475ee993473ecc41485495", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2017-11-17T00:09:53.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-22T08:09:03.000Z", "avg_line_length": 34.552581262, "max_line_length": 549, "alphanum_fraction": 0.4721376792, "num_tokens": 6770, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544911, "lm_q2_score": 0.7490872131147276, "lm_q1q2_score": 0.6610154312571698}} {"text": "!------------------------------------------------------------------------------\n!\n! PROGRAM: RK_method\n!\n! DESCRIPTION: \n!> Solution of n-rank ordinary differential equation (ODE)\n! by superposition and Runge-Kutta method\n!\n! REVISION HISTORY:\n! 13 11 2021 - Initial Version\n! TODO_dd_mmm_yyyy - TODO_describe_appropriate_changes - TODO_name\n!------------------------------------------------------------------------------\n!------------------------------------------------------------------------------\n! \ninclude \"RK-file/module.f90\"\ninclude \"RK-file/subroutine.f90\"\n\nprogram RK_method\n use parameters\n use func_param\n implicit none\n\n integer i ! loop dummy number\n ! integer count\n\n character(30) :: rank\n character(30) :: stepsize\n character(30) :: selection\n\n write (rank, *) n\n write (stepsize, \"(f15.3)\") h\n write (selection, *) select\n\n\n!---Output for monitor \n write (*, *) \"\"\n write (*, *) \"-----------------------------------------------------------\"\n write (*, *) \" Solving the n-rank ODE PROGRAM \"\n write (*, *) \"-----------------------------------------------------------\"\n write (*, *) \" rank = \"//adjustl(trim(rank))//\" h = \"//adjustl(trim(stepsize))\n write (*, *) \" select = \"//adjustl(trim(selection))\n write (*, *) \"\"\n\n!---Main calculation part\n !---Airy, Lecture\n if (select == 1 .or. select == 2) then\n write (*, *) \" -------- solution --------- \"\n call initialize\n\n do i = 1, loop\n call RK(i)\n end do\n\n !---calculate report ploblem\n else if (select == 3) then\n open (10, file = \"output.csv\", status = \"replace\")\n\n do count = 1, n\n\n write (*, *) \" -------- intial solution --------- \"\n call initialize\n write (*, *) \"\"\n\n if (count == 1) then\n write (*, *) \" -------- solution u --------- \"\n write (10, *) \"u\"\n\n do i = 1, loop\n call RK(i) ! Output u and z\n end do\n\n else if (count == 2) then\n write (*, *) \" -------- solution z --------- \"\n write (10, *) \"z\"\n\n do i = 1, loop\n call RK(i) ! Output u and z\n end do\n \n end if\n end do\n\n write (*, *) \" -------- Final solution ---------\"\n call calculate_C\n \n close (10)\n\n end if\n\n stop\nend program\n", "meta": {"hexsha": "cec9171cb14cd13d65faadab809879a599e22d25", "size": 2526, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Integral/RK-method/RK.f90", "max_stars_repo_name": "DiaSird/Mathmatics-Lecture-code", "max_stars_repo_head_hexsha": "cb9d06f1b16915483276a227efe1a1b69f3fd2fd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Integral/RK-method/RK.f90", "max_issues_repo_name": "DiaSird/Mathmatics-Lecture-code", "max_issues_repo_head_hexsha": "cb9d06f1b16915483276a227efe1a1b69f3fd2fd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Integral/RK-method/RK.f90", "max_forks_repo_name": "DiaSird/Mathmatics-Lecture-code", "max_forks_repo_head_hexsha": "cb9d06f1b16915483276a227efe1a1b69f3fd2fd", "max_forks_repo_licenses": ["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.4565217391, "max_line_length": 87, "alphanum_fraction": 0.3966745843, "num_tokens": 571, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544912, "lm_q2_score": 0.7490872075132152, "lm_q1q2_score": 0.6610154263142393}} {"text": "*> \\brief \\b SSYRK\n*\n* =========== DOCUMENTATION ===========\n*\n* Online html documentation available at\n* http://www.netlib.org/lapack/explore-html/\n*\n* Definition:\n* ===========\n*\n* SUBROUTINE SSYRK(UPLO,TRANS,N,K,ALPHA,A,LDA,BETA,C,LDC)\n*\n* .. Scalar Arguments ..\n* REAL ALPHA,BETA\n* INTEGER K,LDA,LDC,N\n* CHARACTER TRANS,UPLO\n* ..\n* .. Array Arguments ..\n* REAL A(LDA,*),C(LDC,*)\n* ..\n*\n*\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*>\n*> SSYRK performs one of the symmetric rank k operations\n*>\n*> C := alpha*A*A**T + beta*C,\n*>\n*> or\n*>\n*> C := alpha*A**T*A + beta*C,\n*>\n*> where alpha and beta are scalars, C is an n by n symmetric matrix\n*> and A is an n by k matrix in the first case and a k by n matrix\n*> in the second case.\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in] UPLO\n*> \\verbatim\n*> UPLO is CHARACTER*1\n*> On entry, UPLO specifies whether the upper or lower\n*> triangular part of the array C is to be referenced as\n*> follows:\n*>\n*> UPLO = 'U' or 'u' Only the upper triangular part of C\n*> is to be referenced.\n*>\n*> UPLO = 'L' or 'l' Only the lower triangular part of C\n*> is to be referenced.\n*> \\endverbatim\n*>\n*> \\param[in] TRANS\n*> \\verbatim\n*> TRANS is CHARACTER*1\n*> On entry, TRANS specifies the operation to be performed as\n*> follows:\n*>\n*> TRANS = 'N' or 'n' C := alpha*A*A**T + beta*C.\n*>\n*> TRANS = 'T' or 't' C := alpha*A**T*A + beta*C.\n*>\n*> TRANS = 'C' or 'c' C := alpha*A**T*A + beta*C.\n*> \\endverbatim\n*>\n*> \\param[in] N\n*> \\verbatim\n*> N is INTEGER\n*> On entry, N specifies the order of the matrix C. N must be\n*> at least zero.\n*> \\endverbatim\n*>\n*> \\param[in] K\n*> \\verbatim\n*> K is INTEGER\n*> On entry with TRANS = 'N' or 'n', K specifies the number\n*> of columns of the matrix A, and on entry with\n*> TRANS = 'T' or 't' or 'C' or 'c', K specifies the number\n*> of rows of the matrix A. K must be at least zero.\n*> \\endverbatim\n*>\n*> \\param[in] ALPHA\n*> \\verbatim\n*> ALPHA is REAL\n*> On entry, ALPHA specifies the scalar alpha.\n*> \\endverbatim\n*>\n*> \\param[in] A\n*> \\verbatim\n*> A is REAL array of DIMENSION ( LDA, ka ), where ka is\n*> k when TRANS = 'N' or 'n', and is n otherwise.\n*> Before entry with TRANS = 'N' or 'n', the leading n by k\n*> part of the array A must contain the matrix A, otherwise\n*> the leading k by n part of the array A must contain the\n*> matrix A.\n*> \\endverbatim\n*>\n*> \\param[in] LDA\n*> \\verbatim\n*> LDA is INTEGER\n*> On entry, LDA specifies the first dimension of A as declared\n*> in the calling (sub) program. When TRANS = 'N' or 'n'\n*> then LDA must be at least max( 1, n ), otherwise LDA must\n*> be at least max( 1, k ).\n*> \\endverbatim\n*>\n*> \\param[in] BETA\n*> \\verbatim\n*> BETA is REAL\n*> On entry, BETA specifies the scalar beta.\n*> \\endverbatim\n*>\n*> \\param[in,out] C\n*> \\verbatim\n*> C is REAL array of DIMENSION ( LDC, n ).\n*> Before entry with UPLO = 'U' or 'u', the leading n by n\n*> upper triangular part of the array C must contain the upper\n*> triangular part of the symmetric matrix and the strictly\n*> lower triangular part of C is not referenced. On exit, the\n*> upper triangular part of the array C is overwritten by the\n*> upper triangular part of the updated matrix.\n*> Before entry with UPLO = 'L' or 'l', the leading n by n\n*> lower triangular part of the array C must contain the lower\n*> triangular part of the symmetric matrix and the strictly\n*> upper triangular part of C is not referenced. On exit, the\n*> lower triangular part of the array C is overwritten by the\n*> lower triangular part of the updated matrix.\n*> \\endverbatim\n*>\n*> \\param[in] LDC\n*> \\verbatim\n*> LDC is INTEGER\n*> On entry, LDC specifies the first dimension of C as declared\n*> in the calling (sub) program. LDC must be at least\n*> max( 1, n ).\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee\n*> \\author Univ. of California Berkeley\n*> \\author Univ. of Colorado Denver\n*> \\author NAG Ltd.\n*\n*> \\date November 2011\n*\n*> \\ingroup single_blas_level3\n*\n*> \\par Further Details:\n* =====================\n*>\n*> \\verbatim\n*>\n*> Level 3 Blas routine.\n*>\n*> -- Written on 8-February-1989.\n*> Jack Dongarra, Argonne National Laboratory.\n*> Iain Duff, AERE Harwell.\n*> Jeremy Du Croz, Numerical Algorithms Group Ltd.\n*> Sven Hammarling, Numerical Algorithms Group Ltd.\n*> \\endverbatim\n*>\n* =====================================================================\n SUBROUTINE SSYRK(UPLO,TRANS,N,K,ALPHA,A,LDA,BETA,C,LDC)\n*\n* -- Reference BLAS level3 routine (version 3.4.0) --\n* -- Reference BLAS is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n* November 2011\n*\n* .. Scalar Arguments ..\n REAL ALPHA,BETA\n INTEGER K,LDA,LDC,N\n CHARACTER TRANS,UPLO\n* ..\n* .. Array Arguments ..\n REAL A(LDA,*),C(LDC,*)\n* ..\n*\n* =====================================================================\n*\n* .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\n* ..\n* .. External Subroutines ..\n EXTERNAL XERBLA\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC MAX\n* ..\n* .. Local Scalars ..\n REAL TEMP\n INTEGER I,INFO,J,L,NROWA\n LOGICAL UPPER\n* ..\n* .. Parameters ..\n REAL ONE,ZERO\n PARAMETER (ONE=1.0E+0,ZERO=0.0E+0)\n* ..\n*\n* Test the input parameters.\n*\n IF (LSAME(TRANS,'N')) THEN\n NROWA = N\n ELSE\n NROWA = K\n END IF\n UPPER = LSAME(UPLO,'U')\n*\n INFO = 0\n IF ((.NOT.UPPER) .AND. (.NOT.LSAME(UPLO,'L'))) THEN\n INFO = 1\n ELSE IF ((.NOT.LSAME(TRANS,'N')) .AND.\n + (.NOT.LSAME(TRANS,'T')) .AND.\n + (.NOT.LSAME(TRANS,'C'))) THEN\n INFO = 2\n ELSE IF (N.LT.0) THEN\n INFO = 3\n ELSE IF (K.LT.0) THEN\n INFO = 4\n ELSE IF (LDA.LT.MAX(1,NROWA)) THEN\n INFO = 7\n ELSE IF (LDC.LT.MAX(1,N)) THEN\n INFO = 10\n END IF\n IF (INFO.NE.0) THEN\n CALL XERBLA('SSYRK ',INFO)\n RETURN\n END IF\n*\n* Quick return if possible.\n*\n IF ((N.EQ.0) .OR. (((ALPHA.EQ.ZERO).OR.\n + (K.EQ.0)).AND. (BETA.EQ.ONE))) RETURN\n*\n* And when alpha.eq.zero.\n*\n IF (ALPHA.EQ.ZERO) THEN\n IF (UPPER) THEN\n IF (BETA.EQ.ZERO) THEN\n DO 20 J = 1,N\n DO 10 I = 1,J\n C(I,J) = ZERO\n 10 CONTINUE\n 20 CONTINUE\n ELSE\n DO 40 J = 1,N\n DO 30 I = 1,J\n C(I,J) = BETA*C(I,J)\n 30 CONTINUE\n 40 CONTINUE\n END IF\n ELSE\n IF (BETA.EQ.ZERO) THEN\n DO 60 J = 1,N\n DO 50 I = J,N\n C(I,J) = ZERO\n 50 CONTINUE\n 60 CONTINUE\n ELSE\n DO 80 J = 1,N\n DO 70 I = J,N\n C(I,J) = BETA*C(I,J)\n 70 CONTINUE\n 80 CONTINUE\n END IF\n END IF\n RETURN\n END IF\n*\n* Start the operations.\n*\n IF (LSAME(TRANS,'N')) THEN\n*\n* Form C := alpha*A*A**T + beta*C.\n*\n IF (UPPER) THEN\n DO 130 J = 1,N\n IF (BETA.EQ.ZERO) THEN\n DO 90 I = 1,J\n C(I,J) = ZERO\n 90 CONTINUE\n ELSE IF (BETA.NE.ONE) THEN\n DO 100 I = 1,J\n C(I,J) = BETA*C(I,J)\n 100 CONTINUE\n END IF\n DO 120 L = 1,K\n IF (A(J,L).NE.ZERO) THEN\n TEMP = ALPHA*A(J,L)\n DO 110 I = 1,J\n C(I,J) = C(I,J) + TEMP*A(I,L)\n 110 CONTINUE\n END IF\n 120 CONTINUE\n 130 CONTINUE\n ELSE\n DO 180 J = 1,N\n IF (BETA.EQ.ZERO) THEN\n DO 140 I = J,N\n C(I,J) = ZERO\n 140 CONTINUE\n ELSE IF (BETA.NE.ONE) THEN\n DO 150 I = J,N\n C(I,J) = BETA*C(I,J)\n 150 CONTINUE\n END IF\n DO 170 L = 1,K\n IF (A(J,L).NE.ZERO) THEN\n TEMP = ALPHA*A(J,L)\n DO 160 I = J,N\n C(I,J) = C(I,J) + TEMP*A(I,L)\n 160 CONTINUE\n END IF\n 170 CONTINUE\n 180 CONTINUE\n END IF\n ELSE\n*\n* Form C := alpha*A**T*A + beta*C.\n*\n IF (UPPER) THEN\n DO 210 J = 1,N\n DO 200 I = 1,J\n TEMP = ZERO\n DO 190 L = 1,K\n TEMP = TEMP + A(L,I)*A(L,J)\n 190 CONTINUE\n IF (BETA.EQ.ZERO) THEN\n C(I,J) = ALPHA*TEMP\n ELSE\n C(I,J) = ALPHA*TEMP + BETA*C(I,J)\n END IF\n 200 CONTINUE\n 210 CONTINUE\n ELSE\n DO 240 J = 1,N\n DO 230 I = J,N\n TEMP = ZERO\n DO 220 L = 1,K\n TEMP = TEMP + A(L,I)*A(L,J)\n 220 CONTINUE\n IF (BETA.EQ.ZERO) THEN\n C(I,J) = ALPHA*TEMP\n ELSE\n C(I,J) = ALPHA*TEMP + BETA*C(I,J)\n END IF\n 230 CONTINUE\n 240 CONTINUE\n END IF\n END IF\n*\n RETURN\n*\n* End of SSYRK .\n*\n END\n", "meta": {"hexsha": "f09b521bce37849161f3f6dc7be97a4dd0a873f0", "size": 10681, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "BLAS/SRC/ssyrk.f", "max_stars_repo_name": "sydha/Lapack", "max_stars_repo_head_hexsha": "1290e6b39b73b2431976e0a9b7fb7d78aeab3ba7", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "BLAS/SRC/ssyrk.f", "max_issues_repo_name": "sydha/Lapack", "max_issues_repo_head_hexsha": "1290e6b39b73b2431976e0a9b7fb7d78aeab3ba7", "max_issues_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "BLAS/SRC/ssyrk.f", "max_forks_repo_name": "sydha/Lapack", "max_forks_repo_head_hexsha": "1290e6b39b73b2431976e0a9b7fb7d78aeab3ba7", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.2630136986, "max_line_length": 80, "alphanum_fraction": 0.4425615579, "num_tokens": 2981, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278571786139, "lm_q2_score": 0.749087201911703, "lm_q1q2_score": 0.6610154144228678}} {"text": "! Demonstrate overloading with an interface and module procedures\r\nmodule m\r\nimplicit none\r\ninterface mean\r\n module procedure mean_1d, mean_2d\r\nend interface mean\r\ncontains\r\npure function mean_1d(x) result(y)\r\nreal, intent(in) :: x(:)\r\nreal :: y\r\ny = sum(x)/max(1,size(x))\r\nend function mean_1d\r\n!\r\npure function mean_2d(x) result(y)\r\nreal, intent(in) :: x(:,:)\r\nreal :: y\r\ny = sum(x)/max(1,size(x))\r\nend function mean_2d\r\nend module m\r\n!\r\nprogram main\r\nuse m, only: mean\r\nimplicit none\r\nreal :: x1(3),x2(2,3)\r\nx1 = real([1,4,10])\r\nx2(1,:) = x1\r\nx2(2,:) = x1*3\r\nprint*,mean(x1),mean(x2) ! 5.0 10.0\r\nend program main", "meta": {"hexsha": "4057f9f08580142111be49fc78713697f0155d51", "size": 641, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "interface.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": "interface.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": "interface.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": 22.1034482759, "max_line_length": 66, "alphanum_fraction": 0.6365054602, "num_tokens": 214, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246035907932, "lm_q2_score": 0.7931059536292271, "lm_q1q2_score": 0.6609147044135737}} {"text": "\nc$$$ AddNumbers.for\nc$$$ Copyright (C) 2019 Sriram C.\nc$$$\nc$$$ Redistribution and use in source and binary forms, with or without\nc$$$ modification, are permitted provided that the following conditions \nc$$$ are met:\nc$$$\nc$$$ 1. Redistributions of source code must retain the above copyright notice\nc$$$ this list of conditions and the following disclaimer.\nc$$$ 2. Redistributions in binary form must reproduce the above copyright \nc$$$ notice, this list of conditions and the following disclaimer in the \nc$$$ documentation and/or other materials provided with the distribution.\nc$$$\nc$$$ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \nc$$$ \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \nc$$$ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A \nc$$$ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER\nc$$$ OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \nc$$$ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \nc$$$ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\nc$$$ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER \nc$$$ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT \nc$$$ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY \nc$$$ WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY \nc$$$ OF SUCH DAMAGE. \n\n\nc Add 2 numbers A and B and store the result in C\n SUBROUTINE ADD(L,M,N)\n INTEGER L,M,N\n\n N = L + M\n\n RETURN\n END\n\nc Add 2 matrices A and B and store the result in C\nC In this example, we assume the matrices are 2x2 matrices\n SUBROUTINE MATRIXADD(A,B,C)\n REAL A(2,2), B(2,2), C(2,2)\n\n DO I = 1,2\n DO J = 1,2\n C(I,J)=A(I,J)+B(I,J)\n END DO\n END DO\n\n RETURN\n END\n\n", "meta": {"hexsha": "0fdba77af9b05fcc45949bc84592c69b3f1640d0", "size": 1972, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/main/fortran/AddNumbers.for", "max_stars_repo_name": "s6ch13/AppFortranExample", "max_stars_repo_head_hexsha": "a3fcfee61a49cd3fee66995d995896b21a17a918", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/main/fortran/AddNumbers.for", "max_issues_repo_name": "s6ch13/AppFortranExample", "max_issues_repo_head_hexsha": "a3fcfee61a49cd3fee66995d995896b21a17a918", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-03-04T13:04:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-04T13:39:35.000Z", "max_forks_repo_path": "src/main/fortran/AddNumbers.for", "max_forks_repo_name": "s6ch13/AppFortranExample", "max_forks_repo_head_hexsha": "a3fcfee61a49cd3fee66995d995896b21a17a918", "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": 37.9230769231, "max_line_length": 80, "alphanum_fraction": 0.6607505071, "num_tokens": 482, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245953120234, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.6609147019227812}} {"text": "\n!#########################################################################\n!# ***********************************************************************\n!# transform_basicRoutines \n!# ***********************************************************************\n!#\n!# \n!# This module contains basic transformation routines for lines and\n!# line segments.\n!#\n!# \n!#########################################################################\n\nmodule transform_basicRoutines\n\n use fsystem\n\n implicit none \n\n contains \n\n! \n !REAL(DP) FUNCTION DPO2SG(dpx,dpy,Pstart,Pend) \n real(DP) function pdist_point_StrghtLineSeg(dpx,dpy,Pstart,Pend) \n \n !\n ! Determine minimum (Euclidean) distance from a point (dpx,dpy) to \n ! a straight line segment. \n !\n ! Return value = minimum distance\n !\n\n !\n\n ! dpx - x-coodinate of point\n real(DP), intent(IN) :: dpx \n\n ! dpy - y-coodinate of point\n real(DP), intent(IN) :: dpy \n\n ! Pstart - starting point of the line segment.\n ! Pstart(1) = x-coordinate\n ! Pstart(2) = y-coordinate\n real(DP), dimension(:), intent(IN) :: Pstart \n\n ! Pend - endpoint of the line segment.\n ! Pend(1) = x-coordinate\n ! Pend(2) = y-coordinate\n real(DP), dimension(:), intent(IN) :: Pend\n\n !\n \n!\n\n ! local variables\n real(DP) :: dsx1,dsy1,dsx2,dsy2,dvx,dvy,dwx,dwy\n real(DP) :: dbx,dby,db\n real(DP) :: dvl,dpl\n\n dsx1 = Pstart(1)\n dsy1 = Pstart(2) \n dsx2 = Pend(1)\n dsy2 = Pend(2)\n\n ! Vector Pstart -> Pend and its length\n dvx = dsx2-dsx1\n dvy = dsy2-dsy1\n dvl = sqrt(dvx*dvx+dvy*dvy)\n\n ! Vector Pstart -> (dpx,dpy) \n dwx = dpx-dsx1\n dwy = dpy-dsy1\n\n ! Scalar product to calculate the length of the\n ! projected vector\n dpl = dwx*dvx+dwy*dvy\n \n ! Relative length of the projection:\n db = dpl/(dvl*dvl)\n \n ! Relative Length <= 0 \n ! => Connection between Pstart and (dpx,dpy) is shortest distance\n ! \n ! Relative Length >= 1\n ! => Connection between Pend and (dpx,dpy) is shortest distance\n if (db.le.0D0) then\n pdist_point_StrghtLineSeg = sqrt((dpx-dsx1)**2+(dpy-dsy1)**2)\n else if (db.ge.1D0) then\n pdist_point_StrghtLineSeg = sqrt((dpx-dsx2)**2+(dpy-dsy2)**2)\n else\n ! Calculate the projection and the distance to that point.\n ! Remember to take the square root of the distances as they \n ! are squared...\n dbx = dsx1+dvx*db\n dby = dsy1+dvy*db\n pdist_point_StrghtLineSeg = sqrt((dpx-dbx)**2+(dpy-dby)**2)\n endif\n\n end function pdist_point_StrghtLineSeg\n\n\n\n! \n !SUBROUTINE PPO2SG(dpx,dpy,Pstart,Pend,DPARM,DPROJ)\n subroutine pproj_point_StrghtLineSeg(dpx,dpy,Pstart,Pend,dparm,Dproj)\n \n !\n ! Project a point (dpx,dpy) onto a line segment.\n !\n\n !\n\n ! dpx - x-coodinate of point\n real(DP), intent(IN) :: dpx \n\n ! dpy - y-coodinate of point\n real(DP), intent(IN) :: dpy \n\n ! Pstart - starting point of the line segment.\n ! Pstart(1) = x-coordinate\n ! Pstart(2) = y-coordinate\n real(DP), dimension(:), intent(IN) :: Pstart \n\n ! Pend - endpoint of the line segment.\n ! Pend(1) = x-coordinate\n ! Pend(2) = y-coordinate\n real(DP), dimension(:), intent(IN) :: Pend\n\n !\n \n !\n \n ! Dproj - Projection of (dpx,dpy) onto the line segment.\n ! Dproj(1) = x-coordinate\n ! Dproj(2) = y-coordinate\n real(DP), dimension(:), intent(OUT) :: Dproj\n\n ! dparm - Parameter value of the projected point along the line\n ! segment. Values in [0,1].\n ! Dproj = Pstart + dparm*(Pend-Pstart)\n real(DP), intent(OUT) :: dparm \n\n !\n\n! \n\n ! local variables\n real(DP) :: dsx1,dsy1,dsx2,dsy2,dvx,dvy,dwx,dwy\n real(DP) :: dvl, dpl\n\n dsx1 = Pstart(1)\n dsy1 = Pstart(2)\n dsx2 = Pend(1)\n dsy2 = Pend(2)\n\n ! Vector Pstart -> Pend and its length\n dvx = dsx2-dsx1\n dvy = dsy2-dsy1\n dvl = sqrt(dvx*dvx+dvy*dvy)\n\n ! Vector Pstart -> (dpx,dpy) \n dwx = dpx-dsx1\n dwy = dpy-dsy1\n \n ! Scalar product to calculate the length of the\n ! projected vector \n dpl = dwx*dvx+dwy*dvy\n\n ! Relative length of our projected vector:\n dparm = dpl/(dvl*dvl)\n\n ! Length <= 0 \n ! => Point is projected onto the starting point Pstart\n ! \n ! Length >= 1\n ! => Point is projected onto the endpoint Pend\n if (dparm.le.0D0) then\n dparm = 0D0\n Dproj(1)=dsx1\n Dproj(2)=dsy1\n else if (dparm.ge.1D0) then\n dparm = 1D0\n Dproj(1)=dsx2\n Dproj(2)=dsy2\n else\n ! Calculate the projection and the distance to that point.\n ! Remember to take the square root of the distances as they \n ! are squared...\n Dproj(1) = dsx1+dvx*dparm\n Dproj(2) = dsy1+dvy*dparm\n endif\n\n end subroutine pproj_point_StrghtLineSeg\n\n\n! \n !REAL(DP) FUNCTION DPO2SL(dpx,dpy,PPT1,PPT2)\n real(DP) function pdist_point_StrghtLine(dpx,dpy,Ppt1,Ppt2)\n\n !\n ! Determine minimum (Euclidean) distance from a point (dpx,dpy) to \n ! a straight line, given by two points on the line. \n ! \n ! In contrast to pdist_point_StrghtLineSeg the line has no starting/ending point!\n !\n ! Return value = minimum distance, >= 0.\n ! < 0 indicates an error: Ppt1=Ppt2\n !\n\n !\n\n ! dpx - x-coodinate of point\n real(DP), intent(IN) :: dpx \n\n ! dpy - y-coodinate of point\n real(DP), intent(IN) :: dpy \n\n ! Ppt1 - one point of the line segment.\n ! Ppt1(1) = x-coordinate\n ! Ppt1(2) = y-coordinate\n real(DP), dimension(:), intent(IN) :: Ppt1 \n\n ! Ppt2 - another point of the line segment. \n ! Ppt2(1) = x-coordinate\n ! Ppt2(2) = y-coordinate\n real(DP), dimension(:), intent(IN) :: Ppt2\n\n !\n\n!\n \n ! local variables\n real(DP) :: dsx1,dsy1,dsx2,dsy2,dvx,dvy,dwx,dwy\n real(DP) :: db,dbx,dby\n real(DP) :: dvl,dpl\n\n dsx1 = Ppt1(1)\n dsy1 = Ppt1(2)\n dsx2 = Ppt2(1)\n dsy2 = Ppt2(2)\n\n ! Vector Pstart -> Pend and its length DC2\n dvx = dsx2-dsx1\n dvy = dsy2-dsy1\n dvl = sqrt(dvx*dvx+dvy*dvy)\n \n ! Stop calculation if both points are the same.\n if (dvl.eq.0D0) then\n pdist_point_StrghtLine = -1\n return\n end if\n\n ! Vector Pstart -> (dpx,dpy) \n dwx = dpx-dsx1\n dwy = dpy-dsy1\n \n !Calculate length of projected vector\n dpl = dwx*dvx+dwy*dvy\n\n ! Calculate the projection\n db = dpl/dvl\n dbx = dsx1+dvx*db\n dby = dsy1+dvy*db\n pdist_point_StrghtLine = sqrt((dpx-dby)**2+(dpy-dby)**2)\n\n end function pdist_point_StrghtLine\n\n\n! \n !SUBROUTINE PPO2SL(dpx,dpy,Ppt1,Ppt2,dparm,Dproj)\n subroutine pproj_point_StrghtLine(dpx,dpy,Ppt1,Ppt2,dparm,Dproj) \n\n !\n ! In contrast to pproj_point_StrghtLineSeg the line has no starting/ending point!\n !\n\n !\n\n ! dpx - x-coodinate of point\n real(DP), intent(IN) :: dpx \n\n ! dpy - y-coodinate of point\n real(DP), intent(IN) :: dpy \n\n ! Ppt1 - one point of the line segment.\n ! Ppt1(1) = x-coordinate\n ! Ppt1(2) = y-coordinate\n real(DP), dimension(:), intent(IN) :: Ppt1 \n\n ! Ppt2 - another point of the line segment. \n ! Ppt2(1) = x-coordinate\n ! Ppt2(2) = y-coordinate\n real(DP), dimension(:), intent(IN) :: Ppt2\n\n !\n \n !\n \n ! Dproj - Projection of (dpx,dpy) onto the line segment.\n ! Dproj(1) = x-coordinate\n ! Dproj(2) = y-coordinate\n real(DP), dimension(:), intent(OUT) :: Dproj\n\n ! dparm - Parameter value of the projected point along the line\n ! segment. Values in [0,1].\n ! Dproj = Pstart + dparm*(Pend-Pstart)\n real(DP), intent(OUT) :: dparm \n\n !\n\n! \n\n ! local variables\n real(DP) :: dsx1,dsy1,dsx2,dsy2,dvx,dvy,dwx,dwy\n real(DP) :: dvl,dpl\n\n dsx1 = Ppt1(1)\n dsy1 = Ppt1(2)\n dsx2 = Ppt2(1)\n dsy2 = Ppt2(2)\n\n ! Vector Pstart -> Pend and its length DC2\n dvx = dsx2-dsx1\n dvy = dsy2-dsy1\n dvl = sqrt(dvx*dvx+dvy*dvy)\n\n ! Stop calculation if both points are the same.\n if (dvl.eq.0D0) then\n dparm = 1D99\n return\n end if\n\n ! Vector Pstart -> (dpx,dpy) \n dwx = dpx-dsx1\n dwy = dpy-dsy1\n \n ! Calculate length of projected vector\n dpl = dwx*dvx+dwy*dvy\n\n ! Calculate the projection and the distance to that point\n dparm = dpl/(dvl*dvl)\n Dproj(1) = dsx1+dvx*dparm\n Dproj(2) = dsy1+dvy*dparm\n \n end subroutine pproj_point_StrghtLine\n\n\n! \n !INTEGER FUNCTION PTROLN (dpx,dpy,Ppt1,Ppt2)\n integer function ptest_pointRightLeftOnLine(dpx,dpy,Ppt1,Ppt2)\n\n !\n ! Test if a point is right-side of a line\n !\n ! This routine tests, if a given point (dpx,dpy) is right-side or\n ! left-side of a line, given by two points.\n !\n ! Return value > 0, if the point is right-side of the line Ppt1->Ppt2\n ! < 0, if the point if left-side of the line\n ! = 0, if the point is on the line or if an error\n ! occurred (Ppt1=Ppt2)\n !\n ! Remark: More specifically the return value is the squared scalar\n ! product of the normal vector of the line with the vector\n ! Ppt1->point...\n !\n\n !\n\n ! dpx - x-coodinate of point\n real(DP), intent(IN) :: dpx \n\n ! dpy - y-coodinate of point\n real(DP), intent(IN) :: dpy \n\n ! Ppt1 - one point of the line segment.\n ! Ppt1(1) = x-coordinate\n ! Ppt1(2) = y-coordinate\n real(DP), dimension(:), intent(IN) :: Ppt1 \n\n ! Ppt2 - another point of the line segment. \n ! Ppt2(1) = x-coordinate\n ! Ppt2(2) = y-coordinate\n real(DP), dimension(:), intent(IN) :: Ppt2\n\n !\n\n ! local variables \n real(DP) :: dnx,dny\n\n ! To distinguish where the point is, relative to the line, we check\n ! the vector Ppt1->point in relation to the normal vector of the line.\n !\n ! At first build the normal vector by rotating the tangential vector\n ! by -90 degrees; this points to the right side of the line.\n dnx = (Ppt2(2)-Ppt1(2))\n dny = -(Ppt2(1)-Ppt1(1))\n\n ! If this normal vector points into the \"same\" direction like the\n ! vector Ppt1->point, the point is on the right.\n ! So we build the scalar product. This is:\n ! > 0, if the point is on the right\n ! < 0, if the point is on the left\n ! = 0, if the point is on the line\n ! and thus a candidate to serve as a return value of this function!\n ptest_pointRightLeftOnLine = dnx*(dpx-Ppt1(1)) + dny*(dpy-Ppt1(2))\n \n end function ptest_pointRightLeftOnLine \n \nend module transform_basicRoutines\n", "meta": {"hexsha": "8cd6d7de80d56c27183191ea41b36f1d7d1c35d1", "size": 10547, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "incoming/ltrafo.f90", "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": "incoming/ltrafo.f90", "max_issues_repo_name": "tudo-math-ls3/FeatFlow2", "max_issues_repo_head_hexsha": "56159aff28f161aca513bc7c5e2014a2d11ff1b3", "max_issues_repo_licenses": ["Intel", "Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "incoming/ltrafo.f90", "max_forks_repo_name": "tudo-math-ls3/FeatFlow2", "max_forks_repo_head_hexsha": "56159aff28f161aca513bc7c5e2014a2d11ff1b3", "max_forks_repo_licenses": ["Intel", "Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.6618004866, "max_line_length": 83, "alphanum_fraction": 0.606807623, "num_tokens": 3578, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267864276108, "lm_q2_score": 0.760650658103136, "lm_q1q2_score": 0.660873666873795}} {"text": "program test_general_ub\n use mod_orrb\n implicit none\n\n character(len=40) :: test_name\n character(len=*), parameter :: fmt=\"(A40, 'Time: ',ES8.2,', ubw: ',I3,', error: ',ES8.2, ', ', A10)\"\n \n real(kind=dp) :: t0, t1\n type(error_info) :: error\n integer(kind=int32) :: na, lbwa, ubwa, j\n real(kind=dp), parameter :: tol=1e-14, c=9\n !\n real(kind=dp), dimension(:,:), allocatable :: a_d, a0_d, a1_d\n complex(kind=dp), dimension(:,:), allocatable :: a_z, a0_z, a1_z\n type(d_ub), allocatable :: ub_d\n type(z_ub), allocatable :: ub_z\n\n call initialize_errors\n\n print *\n print *, \"--------------------------------\"\n print *\n print *, \"Real UB Decomposition Tests\"\n print *\n\n na=40\n lbwa=3; ubwa=5\n ub_d=d_random_ub(na,lbwa,ubwa,error=error)\n a_d=general(ub_d,error)\n a1_d=a_d\n call cpu_time(t0)\n ub_d=ub(a_d,lbwa,lbwa,ubwa+1,tol,error)\n call cpu_time(t1)\n a0_d = general(ub_d,error)\n test_name=\"Random Real UB;\" \n call d_output_result(test_name,a0_d,a1_d,ubwa,ub_d%ubw,t0,t1,c*tol,error)\n\n na=40\n lbwa=3; ubwa=1\n ub_d=d_random_ub(na,lbwa,ubwa,error=error)\n a_d=general(ub_d,error)\n a1_d=a_d\n call cpu_time(t0)\n ub_d=ub(a_d,lbwa,lbwa,ubwa+1,tol,error)\n call cpu_time(t1)\n a0_d = general(ub_d,error)\n test_name=\"Random Real UB, ubwa=1\" \n call d_output_result(test_name,a0_d,a1_d,ubwa,ub_d%ubw,t0,t1,c*tol,error)\n\n na=40\n lbwa=3; ubwa=0\n ub_d=d_random_ub(na,lbwa,ubwa,error=error)\n a_d=general(ub_d,error)\n a1_d=a_d\n call cpu_time(t0)\n ub_d=ub(a_d,lbwa,lbwa,ubwa+1,tol,error)\n call cpu_time(t1)\n a0_d = general(ub_d,error)\n test_name=\"Random Real UB, ubwa=0\" \n call d_output_result(test_name,a0_d,a1_d,ubwa,ub_d%ubw,t0,t1,c*tol,error)\n\n na=1\n lbwa=0; ubwa=0\n ub_d=d_random_ub(na,lbwa,ubwa,error=error)\n a_d=general(ub_d,error)\n a1_d=a_d\n call cpu_time(t0)\n ub_d=ub(a_d,lbwa,lbwa,ubwa+1,tol,error)\n call cpu_time(t1)\n a0_d = general(ub_d,error)\n test_name=\"Random Real UB, na=1\" \n call d_output_result(test_name,a0_d,a1_d,ubwa,ub_d%ubw,t0,t1,c*tol,error)\n\n na=2\n lbwa=1; ubwa=1\n ub_d=d_random_ub(na,lbwa,ubwa,error=error)\n a_d=general(ub_d,error)\n a1_d=a_d\n call cpu_time(t0)\n ub_d=ub(a_d,lbwa,lbwa,ubwa+1,tol,error)\n call cpu_time(t1)\n a0_d = general(ub_d,error)\n test_name=\"Random Real UB, na=2\" \n call d_output_result(test_name,a0_d,a1_d,ubwa,ub_d%ubw,t0,t1,c*tol,error)\n\n na=3\n lbwa=1; ubwa=1\n ub_d=d_random_ub(na,lbwa,ubwa,error=error)\n a_d=general(ub_d,error)\n a1_d=a_d\n call cpu_time(t0)\n ub_d=ub(a_d,lbwa,lbwa,ubwa+1,tol,error)\n call cpu_time(t1)\n a0_d = general(ub_d,error)\n test_name=\"Random Real UB, na=3\"\n call d_output_result(test_name,a0_d,a1_d,ubwa,ub_d%ubw,t0,t1,c*tol,error)\n\n na=4\n lbwa=2; ubwa=2\n ub_d=d_random_ub(na,lbwa,ubwa,error=error)\n a_d=general(ub_d,error)\n a1_d=a_d\n call cpu_time(t0)\n ub_d=ub(a_d,lbwa,lbwa,ubwa+1,tol,error)\n call cpu_time(t1)\n a0_d = general(ub_d,error)\n test_name=\"Random Real UB, na=4\"\n call d_output_result(test_name,a0_d,a1_d,ubwa,ub_d%ubw,t0,t1,c*tol,error)\n\n \n na=50\n lbwa=3; ubwa=13\n ub_d=d_random_ub(na,[ (lbwa, j=1,na) ], &\n [ (ubwa-1, j=1,na-ubwa), (ubwa, j=na-ubwa+1,na) ], error=error )\n a_d=general(ub_d,error)\n a1_d=a_d\n ub_d=ub(a_d,lbwa,lbwa,ubwa+1,tol,error)\n call cpu_time(t0)\n a0_d = general(ub_d,error)\n call cpu_time(t1)\n test_name=\"Random Real Square Termination UB;\" \n call d_output_result(test_name,a0_d,a1_d,ubwa,ub_d%ubw,t0,t1,c*tol,error)\n deallocate(ub_d)\n\n !\n ! Complex UB test\n !\n print *\n print *, \"--------------------------------\"\n print *\n print *, \"Complex UB Decomposition Tests\"\n print *\n\n na=40\n lbwa=3; ubwa=5\n ub_z=z_random_ub(na,lbwa,ubwa,error=error)\n a_z=general(ub_z,error)\n a1_z=a_z\n call cpu_time(t0)\n ub_z=ub(a_z, lbwa, lbwa, ubwa+1, tol,error)\n call cpu_time(t1)\n a0_z=general(ub_z,error)\n test_name=\"Random Complex UB;\" \n call z_output_result(test_name,a0_z,a1_z,ubwa,ub_z%ubw,t0,t1,c*tol,error)\n\n na=40\n lbwa=3; ubwa=1\n ub_z=z_random_ub(na,lbwa,ubwa,error=error)\n a_z=general(ub_z,error)\n a1_z=a_z\n call cpu_time(t0)\n ub_z=ub(a_z, lbwa, lbwa, ubwa+1, tol,error)\n call cpu_time(t1)\n a0_z=general(ub_z,error)\n test_name=\"Random Complex UB, ubwa=1;\"\n call z_output_result(test_name,a0_z,a1_z,ubwa,ub_z%ubw,t0,t1,c*tol,error)\n\n na=40\n lbwa=3; ubwa=0\n ub_z=z_random_ub(na,lbwa,ubwa,error=error)\n a_z=general(ub_z,error)\n a1_z=a_z\n call cpu_time(t0)\n ub_z=ub(a_z, lbwa, lbwa, ubwa+1, tol,error)\n call cpu_time(t1)\n a0_z=general(ub_z,error)\n test_name=\"Random Complex UB, ubwa=0;\"\n call z_output_result(test_name,a0_z,a1_z,ubwa,ub_z%ubw,t0,t1,c*tol,error)\n\n na=1\n lbwa=0; ubwa=0\n ub_z=z_random_ub(na,lbwa,ubwa,error=error)\n a_z=general(ub_z,error)\n a1_z=a_z\n call cpu_time(t0)\n ub_z=ub(a_z, lbwa, lbwa, ubwa+1, tol,error)\n call cpu_time(t1)\n a0_z=general(ub_z,error)\n test_name=\"Random Complex UB, na=1;\"\n call z_output_result(test_name,a0_z,a1_z,ubwa,ub_z%ubw,t0,t1,c*tol,error)\n\n na=2\n lbwa=1; ubwa=1\n ub_z=z_random_ub(na,lbwa,ubwa,error=error)\n a_z=general(ub_z,error)\n a1_z=a_z\n call cpu_time(t0)\n ub_z=ub(a_z, lbwa, lbwa, ubwa+1, tol,error)\n call cpu_time(t1)\n a0_z=general(ub_z,error)\n test_name=\"Random Complex UB, na=2;\"\n call z_output_result(test_name,a0_z,a1_z,ubwa,ub_z%ubw,t0,t1,c*tol,error)\n\n na=3\n lbwa=1; ubwa=1\n ub_z=z_random_ub(na,lbwa,ubwa,error=error)\n a_z=general(ub_z,error)\n a1_z=a_z\n call cpu_time(t0)\n ub_z=ub(a_z, lbwa, lbwa, ubwa+1, tol,error)\n call cpu_time(t1)\n a0_z=general(ub_z,error)\n test_name=\"Random Complex UB, na=3;\"\n call z_output_result(test_name,a0_z,a1_z,ubwa,ub_z%ubw,t0,t1,c*tol,error)\n\n na=4\n lbwa=2; ubwa=2\n ub_z=z_random_ub(na,lbwa,ubwa,error=error)\n a_z=general(ub_z,error)\n a1_z=a_z\n call cpu_time(t0)\n ub_z=ub(a_z, lbwa, lbwa, ubwa+1, tol,error)\n call cpu_time(t1)\n a0_z=general(ub_z,error)\n test_name=\"Random Complex UB, na=4;\"\n call z_output_result(test_name,a0_z,a1_z,ubwa,ub_z%ubw,t0,t1,c*tol,error)\n \n na=50\n lbwa=3; ubwa=13\n ub_z=z_random_ub(na,[ (lbwa, j=1,na) ], &\n [ (ubwa-1, j=1,na-ubwa), (ubwa, j=na-ubwa+1,na) ], error = error)\n a_z=general(ub_z,error)\n a1_z=a_z\n call cpu_time(t0)\n ub_z=ub(a_z,lbwa,lbwa,ubwa+1,tol,error)\n call cpu_time(t1)\n a0_z = general(ub_z,error)\n test_name=\"Random Complex Square Termination UB;\" \n call z_output_result(test_name,a0_z,a1_z,ubwa,ub_z%ubw,t0,t1,c*tol,error)\n print *\n\ncontains\n\n subroutine d_output_result(name,a0,a1,ubw0,ubw1,t0,t1,bnd,error)\n character(len=*) :: name\n real(kind=dp), dimension(:,:) :: a0, a1 \n real(kind=dp) :: bnd, t0, t1\n integer(kind=int32) :: ubw0, ubw1\n type(error_info) :: error\n\n real(kind=dp) :: berr\n character(len=10) :: test_result\n\n if (error%code > 0) then\n print *, \"Calling error in test: \", name\n else\n berr = maxabs(a1-a0)\n if (ubw0==ubw1 .and. berr < bnd) then\n test_result=\"PASSED\"\n else\n test_result=\" FAILED\"\n end if\n write (*,fmt) name, t1-t0, ubw1, berr, test_result\n end if\n end subroutine d_output_result\n\n subroutine z_output_result(name,a0,a1,ubw0,ubw1,t0,t1,bnd,error)\n character(len=*) :: name\n complex(kind=dp), dimension(:,:) :: a0, a1 \n real(kind=dp) :: bnd, t0, t1\n integer(kind=int32) :: ubw0, ubw1\n type(error_info) :: error\n\n real(kind=dp) :: berr\n character(len=10) :: test_result\n\n if (error%code > 0) then\n print *, \"Calling error in test: \", name\n else\n berr = maxabs(a1-a0)\n if (ubw0==ubw1 .and. berr < bnd) then\n test_result=\"PASSED\"\n else\n test_result=\" FAILED\"\n end if\n write (*,fmt) name, t1-t0, ubw1, berr, test_result\n end if\n end subroutine z_output_result\n\nend program test_general_ub\n", "meta": {"hexsha": "dff3d426a3f80c0e1be95cdc64491124e6c5249f", "size": 7742, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/test_general_ub.f90", "max_stars_repo_name": "m-a-stewart/BandGivensWeight", "max_stars_repo_head_hexsha": "f7858d3d0dd95e87a891dc583233e64650209288", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/test_general_ub.f90", "max_issues_repo_name": "m-a-stewart/BandGivensWeight", "max_issues_repo_head_hexsha": "f7858d3d0dd95e87a891dc583233e64650209288", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/test_general_ub.f90", "max_forks_repo_name": "m-a-stewart/BandGivensWeight", "max_forks_repo_head_hexsha": "f7858d3d0dd95e87a891dc583233e64650209288", "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.5516014235, "max_line_length": 102, "alphanum_fraction": 0.6712735727, "num_tokens": 3065, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267728417087, "lm_q2_score": 0.760650658103136, "lm_q1q2_score": 0.6608736565396697}} {"text": "*\n* -------------------------------------------------------------\n* N I N E 1 3\n* -------------------------------------------------------------\n*\n* *\n* THIS PACKAGE DETERMINES THE VALUES OF 9j COEFFICIENT *\n* *\n* | J1/2 J2/2 J3/2+1 | *\n* | L1/2 L2/2 J3/2 | *\n* | K1/2 + 1 K1/2 1 | *\n* *\n* Written by G. Gaigalas, * \n* Vilnius, LITHUANIA January 1997 *\n*\n SUBROUTINE NINE13(J1,J2,J3,L1,L2,K1,A)\n IMPLICIT DOUBLEPRECISION (A-H,O-Z)\n COMMON/CONSTS/ZERO,TENTH,HALF,ONE,TWO,THREE,FOUR,SEVEN,ELEVEN,EPS\n A=ZERO\n K2=K1-2\n L3=J3-2\n IV=J3*(J1-L1)*(J1+L1+2)-K1*(J1-J2)*(J1+J2+2)+K1*J3*(K2-L3)\n IF(IV.EQ.0) THEN\n CALL NINE(J1,J2,J3,L1,L2,L3,K1,K2,2,0,IN,A)\n ELSE\n IS=L3-K2\n IF(IS.EQ.0) THEN\n S1=ZERO\n ELSE\n CALL SIXJ(J1,L1,K2,L2,J2,L3,1,S1)\n CALL ACONST(J1+1,L1,K2+1,J2,L3+1,A1)\n S1=S1*A1*DBLE(IS)/TWO\n ENDIF\n CALL ACONST(L1+1,J1,K2+1,L2,L3+1,A2)\n IF(DABS(A2).LT.EPS) THEN\n S2=ZERO\n ELSE\n CALL SIXJ(J1,J2,J3,L2,L1,K2,1,S2)\n S2=S2*A2*DBLE(J3)/TWO\n ENDIF\n CALL ACONST(J2+1,J1,L3+1,L2,K2+1,A3)\n IF(DABS(A3).LT.EPS) THEN\n S3=ZERO\n ELSE\n CALL SIXJ(J1,J2,L3,L2,L1,K1,1,S3)\n S3=S3*A3*DBLE(K1)/TWO\n ENDIF\n S=S1+S2-S3\n IF(DABS(S).LT.EPS) RETURN\n VAR2=DBLE(K2+3)*DBLE(K2+2)*DBLE(K2+1)*\n : DBLE(L3+3)*DBLE(L3+2)*DBLE(L3+1)\n A=S*DBLE(8)/(DBLE(IV)*DSQRT(VAR2))\n IF(MOD(J2+L3+L1+K2,4).NE.0) A=-A \n ENDIF\n RETURN\n END\n\n\n", "meta": {"hexsha": "cfa8093560107acb5452b9dcc39fcd6026cf4e48", "size": 2010, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/lib/libang/nine13.f", "max_stars_repo_name": "mansour2014/ATSP2K_plus", "max_stars_repo_head_hexsha": "30842b9f086d1e497aeb778e2a352d1e8e520ec3", "max_stars_repo_licenses": ["BSD-4-Clause-UC"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-07-21T14:03:39.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-21T14:03:39.000Z", "max_issues_repo_path": "src/lib/libang/nine13.f", "max_issues_repo_name": "mzmansour/ATSP2K_plus", "max_issues_repo_head_hexsha": "30842b9f086d1e497aeb778e2a352d1e8e520ec3", "max_issues_repo_licenses": ["BSD-4-Clause-UC"], "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/libang/nine13.f", "max_forks_repo_name": "mzmansour/ATSP2K_plus", "max_forks_repo_head_hexsha": "30842b9f086d1e497aeb778e2a352d1e8e520ec3", "max_forks_repo_licenses": ["BSD-4-Clause-UC"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.0677966102, "max_line_length": 71, "alphanum_fraction": 0.3656716418, "num_tokens": 713, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425311777928, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6608499716162757}} {"text": "PROGRAM CriticalMass\n implicit none\n real :: massU, R, sigT, xBank(10000000, 2), yBank(10000000, 2), &\n zBank(10000000, 2), nU, ran1, L, theta, phi, x, y, z\n real, parameter :: rhoU = 19.E3, sigS = 4.2E-28, sigA = 0.1E-28, &\n sigF = 1.3E-28, prob2 = 0.56, prob3 = 0.44\n integer :: n, i, j, numNeutrons, iBank, numBank, current, next\n\n ! Open the data file\n open(unit = 2, file = 'critical_mass.dat', status = 'replace')\n\n ! Establish constants\n\n ! Mass of Uranium-235 in kg\n massU = 1.8E1\n ! Number of starting neutrons\n numNeutrons = 1.0E9\n ! Radius of sphere\n R = (3. * massU / (4. * acos(-1.0) * rhoU)) ** (1. / 3.)\n ! Number density of Uranium-235\n nU = rhoU / (235. * 1.661E-27)\n ! Total cross section\n sigT = sigS + sigA + sigF\n\n print *, \"MassU:\", massU, \"Radius:\", R\n write(2, *) 0, numNeutrons\n\n ! For 200 generations of neutrons,\n do j = 1, 200\n ! Reset neutron bank index\n iBank = 0\n\n ! Alternate between the database column indicies\n if(mod(j, 2).eq.0) then\n current = 2\n next = 1\n else\n current = 1\n next = 2\n endif\n\n ! For every neutron,\n do n = 1, numNeutrons\n if(j.eq.1) then\n ! Emit neutrons on first generation\n call emitNeutron(x, y, z, theta, phi)\n else\n ! Load locations from bank otherwise\n x = xBank(n, current)\n y = yBank(n, current)\n z = zBank(n, current)\n\n ! Get new directions\n call scatter(theta, phi)\n endif\n\n ! While neutron is still inside of the sphere,\n do while(sqrt(x*x + y*y + z*z).le.R)\n ! Generate random\n call random_number(ran1)\n\n ! Find distance traveled\n L = -log(ran1) / (nU * sigT)\n ! And update the neutron positions\n x = x + L * sin(theta) * cos(phi)\n y = y + L * sin(theta) * sin(phi)\n z = z + L * cos(theta)\n\n ! If still inside of the sphere,\n if(sqrt(x*x + y*y + z*z).le.R) then\n ! Generate random\n call random_number(ran1)\n\n ! and find interaction type from the probabilities\n if(ran1.lt.(sigA / sigT)) then\n ! Neutron absorbed, go to next neutron\n goto 2\n elseif(ran1.lt.((sigA + sigS) / sigT)) then\n ! Neutron scattered\n call scatter(theta, phi)\n else\n ! Fission event, find number of neutrons produced\n call random_number(ran1)\n if(ran1.lt.prob2) then\n ! 2 produced\n numBank = 2\n else\n ! 3 produced\n numBank = 3\n endif\n\n ! Bank neutrons' positions\n do i = 1, numBank\n iBank = iBank + 1\n\n ! Exit if the bank is full\n if (iBank.gt.9999999) goto 3\n\n xBank(iBank, next) = x\n yBank(iBank, next) = y\n zBank(iBank, next) = z\n enddo\n endif\n endif\n enddo\n\n2 continue\n enddo\n\n print *, \"Gen:\", j, \"Number:\", iBank\n ! update the number of neutrons for next generation\n numNeutrons = iBank\n ! Save to file\n write(2, *) j, numNeutrons\n enddo\n ! Close the file\n3 close(2)\n print *, \"Done.\"\nend PROGRAM CriticalMass\n\nSUBROUTINE emitNeutron(x, y, z, theta, phi)\n! Creates a photon packet by initializing its coordinates and direction vector\n! x R4 x-coordinate\n! y R4 y-coordinate\n! z R4 z-coordinate\n! theta R4 angle\n! phi R4 angle\n implicit none\n real, intent(out) :: x, y, z, theta, phi\n\n ! Start a center of sphere\n x = 0.0\n y = 0.0\n z = 0.0\n\n call scatter(theta, phi)\nend SUBROUTINE emitNeutron\n\nSUBROUTINE scatter(theta, phi)\n! Scatters the photon isotropically by giving it new direction vectors\n! theta R4 angle\n! phi R4 angle\n implicit none\n real, intent(out) :: theta, phi\n real :: ran\n\n call random_number(ran)\n theta = acos(2.0 * ran - 1.0)\n\n call random_number(ran)\n phi = 2.0 * ran * acos(-1.0) ! arccos(-1) = pi\nend SUBROUTINE scatter\n", "meta": {"hexsha": "87f74ca4036582290016125f6c7d1b7c91b804bf", "size": 4767, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "critical_mass.f90", "max_stars_repo_name": "patricksandquist/Monte-Carlo-Critical-Mass-Calculations", "max_stars_repo_head_hexsha": "76a2dd7733893cd3fb12b382b5b3e96cec322945", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "critical_mass.f90", "max_issues_repo_name": "patricksandquist/Monte-Carlo-Critical-Mass-Calculations", "max_issues_repo_head_hexsha": "76a2dd7733893cd3fb12b382b5b3e96cec322945", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "critical_mass.f90", "max_forks_repo_name": "patricksandquist/Monte-Carlo-Critical-Mass-Calculations", "max_forks_repo_head_hexsha": "76a2dd7733893cd3fb12b382b5b3e96cec322945", "max_forks_repo_licenses": ["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.1568627451, "max_line_length": 80, "alphanum_fraction": 0.4751415985, "num_tokens": 1280, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.919642528975397, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6608499700336464}} {"text": "program problem44\n implicit none\n integer :: answer,j,k,Pj,Pk,D\n\n answer=huge(answer)\n\n do k=2,huge(k)\n Pk=P(k)\n if (Pk - P(k-1) > answer .or. Pk < 0) exit ! already too large, short circuit\n do j=k-1,1,-1\n Pj=P(j)\n D = Pk-Pj\n if (D > answer .or. Pj < 0) exit ! already too large, short circuit\n if (is_P(Pj + Pk) .and. is_P(D)) then\n print *, j,k,Pj,Pk,D\n if (D= 0.\nC\nC A (input/output) DOUBLE PRECISION array, dimension (LDA,N)\nC On entry, the leading N-by-N part of this array must\nC contain the given matrix A.\nC On exit, the leading N-by-N upper quasi-triangular part of\nC this array contains the real Schur canonical form of A.\nC\nC LDA INTEGER\nC The leading dimension of array A. LDA >= max(1,N).\nC\nC WR (output) DOUBLE PRECISION array, dimension (N)\nC WI (output) DOUBLE PRECISION array, dimension (N)\nC WR and WI contain the real and imaginary parts,\nC respectively, of the computed eigenvalues. Complex\nC conjugate pairs of eigenvalues appear consecutively\nC with the eigenvalue having the positive imaginary part\nC first.\nC\nC R (output) DOUBLE PRECISION array, dimension (LDR,N)\nC The leading N-by-N upper triangular part of this array\nC contains the matrix of right eigenvectors R, in the same\nC order as their eigenvalues. The real and imaginary parts\nC of a complex eigenvector corresponding to an eigenvalue\nC with positive imaginary part are stored in consecutive\nC columns. (The corresponding conjugate eigenvector is not\nC stored.) The eigenvectors are not backward transformed\nC for balancing (when BALANC = 'S').\nC\nC LDR INTEGER\nC The leading dimension of array R. LDR >= max(1,N).\nC\nC Q (output) DOUBLE PRECISION array, dimension (LDQ,N)\nC The leading N-by-N part of this array contains the\nC orthogonal matrix Q which has reduced A to real Schur\nC form.\nC\nC LDQ INTEGER\nC The leading dimension of array Q. LDQ >= MAX(1,N).\nC\nC Workspace\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0, DWORK(1) returns the optimal LDWORK.\nC If BALANC = 'S' and LDWORK > 0, DWORK(2),...,DWORK(N+1)\nC return the scaling factors used for balancing.\nC\nC LDWORK INTEGER\nC The length of the array DWORK. LDWORK >= max(1,4*N).\nC For good performance, LDWORK must generally be larger.\nC\nC If LDWORK = -1, then a workspace query is assumed;\nC the routine only calculates the optimal size of the\nC DWORK array, returns this value as the first entry of\nC the DWORK array, and no error message related to LDWORK\nC is issued by XERBLA.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value;\nC > 0: if INFO = i, the QR algorithm failed to compute all\nC the eigenvalues, and no eigenvectors have been\nC computed; elements i+1:N of WR and WI contain\nC eigenvalues which have converged.\nC\nC METHOD\nC\nC This routine uses the QR algorithm to obtain the real Schur form\nC T of matrix A. Then, the right eigenvectors of T are computed,\nC but they are not backtransformed into the eigenvectors of A.\nC MB05MY is a modification of the LAPACK driver routine DGEEV.\nC\nC REFERENCES\nC\nC [1] Anderson, E., Bai, Z., Bischof, C., Demmel, J., Dongarra, J.,\nC Du Croz, J., Greenbaum, A., Hammarling, S., McKenney, A.,\nC Ostrouchov, S., and Sorensen, D.\nC LAPACK Users' Guide: Second Edition.\nC SIAM, Philadelphia, 1995.\nC\nC NUMERICAL ASPECTS\nC 3\nC The algorithm requires 0(N ) operations.\nC\nC CONTRIBUTOR\nC\nC Release 3.0: V. Sima, Katholieke Univ. Leuven, Belgium, Apr. 1997.\nC Supersedes Release 2.0 routine MB05AY.\nC\nC REVISIONS\nC\nC V. Sima, April 25, 2003, Feb. 15, 2004, Aug. 2011.\nC\nC KEYWORDS\nC\nC Eigenvalue, eigenvector decomposition, real Schur form.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, ONE\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )\nC .. Scalar Arguments ..\n CHARACTER BALANC\n INTEGER INFO, LDA, LDQ, LDR, LDWORK, N\nC ..\nC .. Array Arguments ..\n DOUBLE PRECISION A( LDA, * ), DWORK( * ), Q( LDQ, * ),\n $ R( LDR, * ), WI( * ), WR( * )\nC ..\nC .. Local Scalars ..\n LOGICAL LQUERY, SCALE, SCALEA\n INTEGER IBAL, IERR, IHI, ILO, ITAU, JWORK, K, MAXWRK,\n $ MINWRK, NOUT\n DOUBLE PRECISION ANRM, BIGNUM, CSCALE, EPS, SMLNUM\nC ..\nC .. Local Arrays ..\n LOGICAL SELECT( 1 )\n DOUBLE PRECISION DUM( 1 )\nC ..\nC .. External Functions ..\n LOGICAL LSAME\n DOUBLE PRECISION DLAMCH, DLANGE\n EXTERNAL DLAMCH, DLANGE, LSAME\nC ..\nC .. External Subroutines ..\n EXTERNAL DGEBAL, DGEHRD, DHSEQR, DLABAD, DLACPY, DLASCL,\n $ DORGHR, DTREVC, XERBLA\nC ..\nC .. Intrinsic Functions ..\n INTRINSIC INT, MAX, MIN, SQRT\nC ..\nC .. Executable Statements ..\nC\nC Test the input scalar arguments.\nC\n INFO = 0\n SCALE = LSAME( BALANC, 'S' )\n IF( .NOT.( LSAME( BALANC, 'N' ) .OR. SCALE ) ) THEN\n INFO = -1\n ELSE IF( N.LT.0 ) THEN\n INFO = -2\n ELSE IF( LDA.LT.MAX( 1, N ) ) THEN\n INFO = -4\n ELSE IF( LDR.LT.MAX( 1, N ) ) THEN\n INFO = -8\n ELSE IF( LDQ.LT.MAX( 1, N ) ) THEN\n INFO = -10\n ELSE\nC\nC Compute workspace.\nC (Note: Comments in the code beginning \"Workspace:\" describe the\nC minimal amount of workspace needed at that point in the code,\nC as well as the preferred amount for good performance.\nC NB refers to the optimal block size for the immediately\nC following subroutine, as returned by ILAENV.\nC HSDWOR refers to the workspace preferred by DHSEQR; it is\nC computed assuming ILO=1 and IHI=N, the worst case.)\nC\n MINWRK = MAX( 1, 4*N )\n LQUERY = LDWORK.EQ.-1\n IF( LDWORK.LT.MINWRK .AND. .NOT.LQUERY ) THEN\n INFO = -12\n ELSE IF( LQUERY ) THEN\n CALL DGEHRD( N, 1, N, A, LDA, DWORK, DWORK, -1, INFO )\n MAXWRK = INT( DWORK( 1 ) )\n CALL DORGHR( N, 1, N, Q, LDQ, DWORK, DWORK, -1, INFO )\n MAXWRK = 2*N + MAX( MAXWRK, INT( DWORK( 1 ) ) )\n CALL DHSEQR( 'S', 'V', N, 1, N, A, LDA, WR, WI, Q, LDQ,\n $ DWORK, -1, INFO )\n MAXWRK = MAX( MAXWRK, N + INT( DWORK( 1 ) ), MINWRK )\n END IF\n END IF\nC\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'MB05MY', -INFO )\n RETURN\n ELSE IF( LQUERY ) THEN\n DWORK( 1 ) = MAXWRK\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF( N.EQ.0 ) THEN\n DWORK( 1 ) = ONE\n RETURN\n END IF\nC\nC Get machine constants.\nC\n EPS = DLAMCH( 'P' )\n SMLNUM = DLAMCH( 'S' )\n BIGNUM = ONE / SMLNUM\n CALL DLABAD( SMLNUM, BIGNUM )\n SMLNUM = SQRT( SMLNUM ) / EPS\n BIGNUM = ONE / SMLNUM\nC\nC Scale A if max element outside range [SMLNUM,BIGNUM].\nC\n ANRM = DLANGE( 'M', N, N, A, LDA, DUM )\n SCALEA = .FALSE.\n IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN\n SCALEA = .TRUE.\n CSCALE = SMLNUM\n ELSE IF( ANRM.GT.BIGNUM ) THEN\n SCALEA = .TRUE.\n CSCALE = BIGNUM\n END IF\n IF( SCALEA )\n $ CALL DLASCL( 'G', 0, 0, ANRM, CSCALE, N, N, A, LDA, IERR )\nC\nC Balance the matrix, if requested. (Permutation is not possible.)\nC (Workspace: need N)\nC\n IBAL = 1\n CALL DGEBAL( BALANC, N, A, LDA, ILO, IHI, DWORK( IBAL ), IERR )\nC\nC Reduce to upper Hessenberg form.\nC (Workspace: need 3*N, prefer 2*N+N*NB)\nC\n ITAU = IBAL + N\n JWORK = ITAU + N\n CALL DGEHRD( N, ILO, IHI, A, LDA, DWORK( ITAU ), DWORK( JWORK ),\n $ LDWORK-JWORK+1, IERR )\n MAXWRK = INT( DWORK( JWORK ) )\nC\nC Compute right eigenvectors of T.\nC Copy Householder vectors to Q.\nC\n CALL DLACPY( 'Lower', N, N, A, LDA, Q, LDQ )\nC\nC Generate orthogonal matrix in Q.\nC (Workspace: need 3*N-1, prefer 2*N+(N-1)*NB)\nC\n CALL DORGHR( N, ILO, IHI, Q, LDQ, DWORK( ITAU ), DWORK( JWORK ),\n $ LDWORK-JWORK+1, IERR )\n MAXWRK = 2*N + MAX( MAXWRK, INT( DWORK( JWORK ) ) )\nC\nC Perform QR iteration, accumulating Schur vectors in Q.\nC (Workspace: need N+1, prefer N+HSDWOR (see comments) )\nC\n JWORK = ITAU\n CALL DHSEQR( 'S', 'V', N, ILO, IHI, A, LDA, WR, WI, Q, LDQ,\n $ DWORK( JWORK ), LDWORK-JWORK+1, INFO )\n MAXWRK = MAX( MAXWRK, N + INT( DWORK( JWORK ) ), MINWRK )\nC\nC If INFO > 0 from DHSEQR, then quit.\nC\n IF( INFO.GT.0 )\n $ GO TO 10\nC\nC Compute right eigenvectors of T in R.\nC (Workspace: need 4*N)\nC\n CALL DTREVC( 'Right', 'All', SELECT, N, A, LDA, DUM, 1, R, LDR, N,\n $ NOUT, DWORK( JWORK ), IERR )\nC\nC Undo scaling if necessary.\nC\n 10 CONTINUE\n IF( SCALEA ) THEN\n CALL DLASCL( 'G', 0, 0, CSCALE, ANRM, N-INFO, 1, WR( INFO+1 ),\n $ MAX( N-INFO, 1 ), IERR )\n CALL DLASCL( 'G', 0, 0, CSCALE, ANRM, N-INFO, 1, WI( INFO+1 ),\n $ MAX( N-INFO, 1 ), IERR )\n IF( INFO.GT.0 ) THEN\n CALL DLASCL( 'G', 0, 0, CSCALE, ANRM, ILO-1, 1, WR, N,\n $ IERR )\n CALL DLASCL( 'G', 0, 0, CSCALE, ANRM, ILO-1, 1, WI, N,\n $ IERR )\n END IF\n END IF\nC\n IF ( SCALE ) THEN\n DO 20 K = N, 1, -1\n DWORK( K+1 ) = DWORK( K )\n 20 CONTINUE\n END IF\n DWORK( 1 ) = MAXWRK\nC\n RETURN\nC *** Last line of MB05MY ***\n END\n", "meta": {"hexsha": "039e9d7a9229b0dce13180b182941ce37d90aec3", "size": 11183, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB05MY.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB05MY.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB05MY.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 34.5154320988, "max_line_length": 72, "alphanum_fraction": 0.5525350979, "num_tokens": 3484, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9449947055100817, "lm_q2_score": 0.6992544210587585, "lm_q1q2_score": 0.6607917257050441}} {"text": "program plotter\nuse gnuplot_fortran\nimplicit none\n\ninteger, parameter :: n=100\ndouble precision, dimension(0:n) :: x,y ! index goes from 0 to n\ndouble precision :: x_start = 0.0, x_end = 20, dx\ninteger :: i\n\n\n! make x array\ndx = (x_end - x_start )/n\nx(0:n) = [ (i*dx,i=0,n ) ]\n\n! make y array\ny = sin(x)/(x+1)\n\n! generate data for plot\ncall plot(x,y)\n\n\n\nend program plotter\n", "meta": {"hexsha": "0d212bfebf262e10632305a77ebd6b51f34f20f4", "size": 376, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "ROMlab_Fortran/bin/gnu_plot_use/plotter.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/gnu_plot_use/plotter.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/gnu_plot_use/plotter.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": 15.6666666667, "max_line_length": 65, "alphanum_fraction": 0.6569148936, "num_tokens": 131, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8128673087708699, "lm_q2_score": 0.8128673201042492, "lm_q1q2_score": 0.6607532708809303}} {"text": " SUBROUTINE MB04AD( JOB, COMPQ1, COMPQ2, COMPU1, COMPU2, N, Z, LDZ,\n $ H, LDH, Q1, LDQ1, Q2, LDQ2, U11, LDU11, U12,\n $ LDU12, U21, LDU21, U22, LDU22, T, LDT, ALPHAR,\n $ ALPHAI, BETA, IWORK, LIWORK, DWORK, LDWORK,\n $ INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute the eigenvalues of a real N-by-N skew-Hamiltonian/\nC Hamiltonian pencil aS - bH with\nC\nC ( 0 I )\nC S = T Z = J Z' J' Z, where J = ( ), (1)\nC ( -I 0 )\nC\nC via generalized symplectic URV decomposition. That is, orthogonal\nC matrices Q1 and Q2 and orthogonal symplectic matrices U1 and U2\nC are computed such that\nC\nC ( T11 T12 )\nC Q1' T U1 = Q1' J Z' J' U1 = ( ) = Tout,\nC ( 0 T22 )\nC\nC ( Z11 Z12 )\nC U2' Z Q2 = ( ) = Zout, (2)\nC ( 0 Z22 )\nC\nC ( H11 H12 )\nC Q1' H Q2 = ( ) = Hout,\nC ( 0 H22 )\nC\nC where T11, T22', Z11, Z22', H11 are upper triangular and H22' is\nC upper quasi-triangular. The notation M' denotes the transpose of\nC the matrix M.\nC Optionally, if COMPQ1 = 'I' or COMPQ1 = 'U', the orthogonal\nC transformation matrix Q1 will be computed.\nC Optionally, if COMPQ2 = 'I' or COMPQ2 = 'U', the orthogonal\nC transformation matrix Q2 will be computed.\nC Optionally, if COMPU1 = 'I' or COMPU1 = 'U', the orthogonal\nC symplectic transformation matrix\nC\nC ( U11 U12 )\nC U1 = ( )\nC ( -U12 U11 )\nC\nC will be computed.\nC Optionally, if COMPU2 = 'I' or COMPU2 = 'U', the orthogonal\nC symplectic transformation matrix\nC\nC ( U21 U22 )\nC U2 = ( )\nC ( -U22 U21 )\nC\nC will be computed.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC JOB CHARACTER*1\nC Specifies the computation to be performed, as follows:\nC = 'E': compute the eigenvalues only; Z, T, and H will not\nC necessarily be put into the forms in (2); H22' is\nC upper Hessenberg;\nC = 'T': put Z, T, and H into the forms in (2), and return\nC the eigenvalues in ALPHAR, ALPHAI and BETA.\nC\nC COMPQ1 CHARACTER*1\nC Specifies whether to compute the orthogonal transformation\nC matrix Q1, as follows:\nC = 'N': Q1 is not computed;\nC = 'I': the array Q1 is initialized internally to the unit\nC matrix, and the orthogonal matrix Q1 is returned;\nC = 'U': the array Q1 contains an orthogonal matrix Q01 on\nC entry, and the product Q01*Q1 is returned, where Q1\nC is the product of the orthogonal transformations\nC that are applied to the pencil aT*Z - bH on the\nC left to reduce T, Z, and H to the forms in (2),\nC for COMPQ1 = 'I'.\nC\nC COMPQ2 CHARACTER*1\nC Specifies whether to compute the orthogonal transformation\nC matrix Q2, as follows:\nC = 'N': Q2 is not computed;\nC = 'I': the array Q2 is initialized internally to the unit\nC matrix, and the orthogonal matrix Q2 is returned;\nC = 'U': the array Q2 contains an orthogonal matrix Q02 on\nC entry, and the product Q02*Q2 is returned, where Q2\nC is the product of the orthogonal transformations\nC that are applied to the pencil aT*Z - bH on the\nC right to reduce T, Z, and H to the forms in (2),\nC for COMPQ2 = 'I'.\nC\nC COMPU1 CHARACTER*1\nC Specifies whether to compute the orthogonal symplectic\nC transformation matrix U1, as follows:\nC = 'N': U1 is not computed;\nC = 'I': the arrays U11 and U12 are initialized internally\nC to the unit and zero matrices, respectively, and\nC the corresponding submatrices of the orthogonal\nC symplectic matrix U1 are returned;\nC = 'U': the arrays U11 and U12 contain the corresponding\nC submatrices of an orthogonal symplectic matrix U01\nC on entry, and the updated submatrices U11 and U12\nC of the matrix product U01*U1 are returned, where U1\nC is the product of the orthogonal symplectic\nC transformations that are applied to the pencil\nC aT*Z - bH to reduce T, Z, and H to the forms in\nC (2), for COMPU1 = 'I'.\nC\nC COMPU2 CHARACTER*1\nC Specifies whether to compute the orthogonal symplectic\nC transformation matrix U2, as follows:\nC = 'N': U2 is not computed;\nC = 'I': the arrays U21 and U22 are initialized internally\nC to the unit and zero matrices, respectively, and\nC the corresponding submatrices of the orthogonal\nC symplectic matrix U2 are returned;\nC = 'U': the arrays U21 and U22 contain the corresponding\nC submatrices of an orthogonal symplectic matrix U02\nC on entry, and the updated submatrices U21 and U22\nC of the matrix product U02*U2 are returned, where U2\nC is the product of the orthogonal symplectic\nC transformations that are applied to the pencil\nC aT*Z - bH to reduce T, Z, and H to the forms in\nC (2), for COMPU2 = 'I'.\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The order of the pencil aS - bH. N >= 0, even.\nC\nC Z (input/output) DOUBLE PRECISION array, dimension (LDZ, N)\nC On entry, the leading N-by-N part of this array must\nC contain the matrix Z.\nC On exit, if JOB = 'T', the leading N-by-N part of this\nC array contains the matrix Zout; otherwise, it contains the\nC matrix Z obtained just before the application of the\nC periodic QZ algorithm.\nC The elements of the (2,1) block, i.e., in the rows N/2+1\nC to N and in the columns 1 to N/2 are not set to zero, but\nC are unchanged on exit.\nC\nC LDZ INTEGER\nC The leading dimension of the array Z. LDZ >= MAX(1, N).\nC\nC H (input/output) DOUBLE PRECISION array, dimension (LDH, N)\nC On entry, the leading N-by-N part of this array must\nC contain the Hamiltonian matrix H (H22 = -H11', H12 = H12',\nC H21 = H21').\nC On exit, if JOB = 'T', the leading N-by-N part of this\nC array contains the matrix Hout; otherwise, it contains the\nC matrix H obtained just before the application of the\nC periodic QZ algorithm.\nC\nC LDH INTEGER\nC The leading dimension of the array H. LDH >= MAX(1, N).\nC\nC Q1 (input/output) DOUBLE PRECISION array, dimension (LDQ1, N)\nC On entry, if COMPQ1 = 'U', then the leading N-by-N part of\nC this array must contain a given matrix Q01, and on exit,\nC the leading N-by-N part of this array contains the product\nC of the input matrix Q01 and the transformation matrix Q1\nC used to transform the matrices Z, T and H.\nC On exit, if COMPQ1 = 'I', then the leading N-by-N part of\nC this array contains the orthogonal transformation matrix\nC Q1.\nC If COMPQ1 = 'N', this array is not referenced.\nC\nC LDQ1 INTEGER\nC The leading dimension of the array Q1.\nC LDQ1 >= 1, if COMPQ1 = 'N';\nC LDQ1 >= MAX(1, N), if COMPQ1 = 'I' or COMPQ1 = 'U'.\nC\nC Q2 (input/output) DOUBLE PRECISION array, dimension (LDQ2, N)\nC On entry, if COMPQ2 = 'U', then the leading N-by-N part of\nC this array must contain a given matrix Q02, and on exit,\nC the leading N-by-N part of this array contains the product\nC of the input matrix Q02 and the transformation matrix Q2\nC used to transform the matrices Z, T and H.\nC On exit, if COMPQ2 = 'I', then the leading N-by-N part of\nC this array contains the orthogonal transformation matrix\nC Q2.\nC If COMPQ2 = 'N', this array is not referenced.\nC\nC LDQ2 INTEGER\nC The leading dimension of the array Q2.\nC LDQ2 >= 1, if COMPQ2 = 'N';\nC LDQ2 >= MAX(1, N), if COMPQ2 = 'I' or COMPQ2 = 'U'.\nC\nC U11 (input/output) DOUBLE PRECISION array, dimension\nC (LDU11, N/2)\nC On entry, if COMPU1 = 'U', then the leading N/2-by-N/2\nC part of this array must contain the upper left block of a\nC given matrix U01, and on exit, the leading N/2-by-N/2 part\nC of this array contains the updated upper left block U11 of\nC the product of the input matrix U01 and the transformation\nC matrix U1 used to transform the matrices Z, T, and H.\nC On exit, if COMPU1 = 'I', then the leading N/2-by-N/2 part\nC of this array contains the upper left block U11 of the\nC orthogonal symplectic transformation matrix U1.\nC If COMPU1 = 'N' this array is not referenced.\nC\nC LDU11 INTEGER\nC The leading dimension of the array U11.\nC LDU11 >= 1, if COMPU1 = 'N';\nC LDU11 >= MAX(1, N/2), if COMPU1 = 'I' or COMPU1 = 'U'.\nC\nC U12 (input/output) DOUBLE PRECISION array, dimension\nC (LDU12, N/2)\nC On entry, if COMPU1 = 'U', then the leading N/2-by-N/2\nC part of this array must contain the upper right block of a\nC given matrix U01, and on exit, the leading N/2-by-N/2 part\nC of this array contains the updated upper right block U12\nC of the product of the input matrix U01 and the\nC transformation matrix U1 used to transform the matrices\nC Z, T, and H.\nC On exit, if COMPU1 = 'I', then the leading N/2-by-N/2 part\nC of this array contains the upper right block U12 of the\nC orthogonal symplectic transformation matrix U1.\nC If COMPU1 = 'N' this array is not referenced.\nC\nC LDU12 INTEGER\nC The leading dimension of the array U12.\nC LDU12 >= 1, if COMPU1 = 'N';\nC LDU12 >= MAX(1, N/2), if COMPU1 = 'I' or COMPU1 = 'U'.\nC\nC U21 (input/output) DOUBLE PRECISION array, dimension\nC (LDU21, N/2)\nC On entry, if COMPU2 = 'U', then the leading N/2-by-N/2\nC part of this array must contain the upper left block of a\nC given matrix U02, and on exit, the leading N/2-by-N/2 part\nC of this array contains the updated upper left block U21 of\nC the product of the input matrix U02 and the transformation\nC matrix U2 used to transform the matrices Z, T, and H.\nC On exit, if COMPU2 = 'I', then the leading N/2-by-N/2 part\nC of this array contains the upper left block U21 of the\nC orthogonal symplectic transformation matrix U2.\nC If COMPU2 = 'N' this array is not referenced.\nC\nC LDU21 INTEGER\nC The leading dimension of the array U21.\nC LDU21 >= 1, if COMPU2 = 'N';\nC LDU21 >= MAX(1, N/2), if COMPU2 = 'I' or COMPU2 = 'U'.\nC\nC U22 (input/output) DOUBLE PRECISION array, dimension\nC (LDU22, N/2)\nC On entry, if COMPU2 = 'U', then the leading N/2-by-N/2\nC part of this array must contain the upper right block of a\nC given matrix U02, and on exit, the leading N/2-by-N/2 part\nC of this array contains the updated upper right block U22\nC of the product of the input matrix U02 and the\nC transformation matrix U2 used to transform the matrices\nC Z, T, and H.\nC On exit, if COMPU2 = 'I', then the leading N/2-by-N/2 part\nC of this array contains the upper right block U22 of the\nC orthogonal symplectic transformation matrix U2.\nC If COMPU2 = 'N' this array is not referenced.\nC\nC LDU22 INTEGER\nC The leading dimension of the array U22.\nC LDU22 >= 1, if COMPU2 = 'N';\nC LDU22 >= MAX(1, N/2), if COMPU2 = 'I' or COMPU2 = 'U'.\nC\nC T (output) DOUBLE PRECISION array, dimension (LDT, N)\nC If JOB = 'T', the leading N-by-N part of this array\nC contains the matrix Tout; otherwise, it contains the\nC matrix T obtained just before the application of the\nC periodic QZ algorithm.\nC\nC LDT INTEGER\nC The leading dimension of the array T. LDT >= MAX(1, N).\nC\nC ALPHAR (output) DOUBLE PRECISION array, dimension (N/2)\nC The real parts of each scalar alpha defining an eigenvalue\nC of the pencil aS - bH.\nC\nC ALPHAI (output) DOUBLE PRECISION array, dimension (N/2)\nC The imaginary parts of each scalar alpha defining an\nC eigenvalue of the pencil aS - bH.\nC If ALPHAI(j) is zero, then the j-th eigenvalue is real.\nC\nC BETA (output) DOUBLE PRECISION array, dimension (N/2)\nC The scalars beta defining the eigenvalues of the pencil\nC aS - bH.\nC Together, the quantities alpha = (ALPHAR(j),ALPHAI(j)) and\nC beta = BETA(j) represent the j-th eigenvalue of the pencil\nC aS - bH, in the form lambda = alpha/beta. Since lambda may\nC overflow, the ratios should not, in general, be computed.\nC Due to the skew-Hamiltonian/Hamiltonian structure of the\nC pencil, for every eigenvalue lambda, -lambda is also an\nC eigenvalue, and thus it has only to be saved once in\nC ALPHAR, ALPHAI and BETA.\nC Specifically, only eigenvalues with imaginary parts\nC greater than or equal to zero are stored; their conjugate\nC eigenvalues are not stored. If imaginary parts are zero\nC (i.e., for real eigenvalues), only positive eigenvalues\nC are stored. The remaining eigenvalues have opposite signs.\nC As a consequence, pairs of complex eigenvalues, stored in\nC consecutive locations, are not complex conjugate.\nC\nC Workspace\nC\nC IWORK INTEGER array, dimension (LIWORK)\nC On exit, if INFO = 3, IWORK(1) contains the number of\nC (pairs of) possibly inaccurate eigenvalues, q <= N/2, and\nC IWORK(2), ..., IWORK(q+1) indicate their indices.\nC Specifically, a positive value is an index of a real or\nC purely imaginary eigenvalue, corresponding to a 1-by-1\nC block, while the absolute value of a negative entry in\nC IWORK is an index to the first eigenvalue in a pair of\nC consecutively stored eigenvalues, corresponding to a\nC 2-by-2 block. A 2-by-2 block may have two complex, two\nC real, two purely imaginary, or one real and one purely\nC imaginary eigenvalue.\nC For i = q+2, ..., 2*q+1, IWORK(i) contains a pointer to\nC the starting location in DWORK of the i-th quadruple of\nC 1-by-1 blocks, if IWORK(i-q) > 0, or 2-by-2 blocks,\nC if IWORK(i-q) < 0, defining unreliable eigenvalues.\nC IWORK(2*q+2) contains the number of the 1-by-1 blocks, and\nC IWORK(2*q+3) contains the number of the 2-by-2 blocks,\nC corresponding to unreliable eigenvalues. IWORK(2*q+4)\nC contains the total number t of the 2-by-2 blocks.\nC If INFO = 0, then q = 0, therefore IWORK(1) = 0.\nC\nC LIWORK INTEGER\nC The dimension of the array IWORK. LIWORK >= N+18.\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0 or INFO = 3, DWORK(1) returns the\nC optimal LDWORK, and DWORK(2), ..., DWORK(7) contain the\nC Frobenius norms of the factors of the formal matrix\nC product used by the algorithm. In addition, DWORK(8), ...,\nC DWORK(7+6*s) contain the s sextuple values corresponding\nC to the 1-by-1 blocks. Their eigenvalues are real or purely\nC imaginary. Such an eigenvalue is obtained from\nC -i*sqrt((a1/a2/a3)*(a4/a5/a6)), but always taking a\nC positive sign, where a1, ..., a6 are the corresponding\nC sextuple values.\nC Moreover, DWORK(8+6*s), ..., DWORK(7+6*s+24*t) contain the\nC t groups of sextuple 2-by-2 matrices corresponding to the\nC 2-by-2 blocks. Their eigenvalue pairs are either complex,\nC or placed on the real and imaginary axes. Such an\nC eigenvalue pair is obtained as -1i*sqrt(ev), but taking\nC positive imaginary parts, where ev are the eigenvalues of\nC the product A1*inv(A2)*inv(A3)*A4*inv(A5)*inv(A6), where\nC A1, ..., A6 define the corresponding 2-by-2 matrix\nC sextuple.\nC On exit, if INFO = -31, DWORK(1) returns the minimum value\nC of LDWORK.\nC\nC LDWORK INTEGER\nC The dimension of the array DWORK.\nC If JOB = 'E' and COMPQ1 = 'N' and COMPQ2 = 'N' and\nC COMPU1 = 'N' and COMPU2 = 'N', then\nC LDWORK >= 3/2*N**2 + MAX(6*N,54);\nC else, LDWORK >= 3*N**2 + MAX(6*N,54).\nC For good performance LDWORK should generally be larger.\nC\nC If LDWORK = -1, then a workspace query is assumed; the\nC routine only calculates the optimal size of the DWORK\nC array, returns this value as the first entry of the DWORK\nC array, and no error message related to LDWORK is issued by\nC XERBLA.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: succesful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal value;\nC = 1: the periodic QZ algorithm was not able to reveal\nC information about the eigenvalues from the 2-by-2\nC blocks in the SLICOT Library routine MB03BD;\nC = 2: the periodic QZ algorithm did not converge in the\nC SLICOT Library routine MB03BD;\nC = 3: some eigenvalues might be inaccurate, and details can\nC be found in IWORK and DWORK. This is a warning.\nC\nC METHOD\nC\nC The algorithm uses Givens rotations and Householder reflections to\nC annihilate elements in T, Z, and H such that T11, T22', Z11, Z22',\nC and H11 are upper triangular and H22' is upper Hessenberg. Finally\nC the periodic QZ algorithm is applied to transform H22' to upper\nC quasi-triangular form while T11, T22', Z11, Z22', and H11 stay in\nC upper triangular form.\nC See also page 17 in [1] for more details.\nC\nC REFERENCES\nC\nC [1] Benner, P., Byers, R., Losse, P., Mehrmann, V. and Xu, H.\nC Numerical Solution of Real Skew-Hamiltonian/Hamiltonian\nC Eigenproblems.\nC Tech. Rep., Technical University Chemnitz, Germany,\nC Nov. 2007.\nC\nC NUMERICAL ASPECTS\nC 3\nC The algorithm is numerically backward stable and needs O(N ) real\nC floating point operations.\nC\nC CONTRIBUTOR\nC\nC Matthias Voigt, Fakultaet fuer Mathematik, Technische Universitaet\nC Chemnitz, December 03, 2008.\nC V. Sima, Dec. 2009 (SLICOT version of the routine DGEURV).\nC\nC REVISIONS\nC\nC V. Sima, Feb. 2010, Nov. 2010, Aug. 2011, Nov. 2011, July 2012,\nC Oct. 2012, July 2013, Aug. 2014, Mar. 2020, Apr. 2020, May 2020.\nC M. Voigt, Jan. 2012.\nC\nC KEYWORDS\nC\nC generalized symplectic URV decomposition, periodic QZ algorithm,\nC upper (quasi-)triangular matrix.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, HALF, ONE, SEVEN\n PARAMETER ( ZERO = 0.0D+0, HALF = 0.5D+0, ONE = 1.0D+0,\n $ SEVEN = 7.0D+0 )\nC\nC .. Scalar Arguments ..\n CHARACTER COMPQ1, COMPQ2, COMPU1, COMPU2, JOB\n INTEGER INFO, LDH, LDQ1, LDQ2, LDT, LDU11, LDU12,\n $ LDU21, LDU22, LDWORK, LDZ, LIWORK, N\nC\nC .. Array Arguments ..\n INTEGER IWORK( * )\n DOUBLE PRECISION ALPHAI( * ), ALPHAR( * ), BETA( * ),\n $ DWORK( * ), H( LDH, * ), Q1( LDQ1, * ),\n $ Q2( LDQ2, * ), T( LDT, * ), U11( LDU11, * ),\n $ U12( LDU12, * ), U21( LDU21, * ),\n $ U22( LDU22, * ), Z( LDZ, * )\nC\nC .. Local Scalars ..\n LOGICAL LCMPQ1, LCMPQ2, LCMPU1, LCMPU2, LINIQ1, LINIQ2,\n $ LINIU1, LINIU2, LQUERY, LTRI, LUPDQ1, LUPDQ2,\n $ LUPDU1, LUPDU2, UNREL\n CHARACTER*16 CMPQ, CMPSC\n INTEGER EMAX, EMIN, I, I11, I22, I2X2, IMAT, IQ, ITAU,\n $ IW, IWARN, IWRK, J, K, L, M, MINDW, MM, NBETA0,\n $ NINF, OPTDW, P\n DOUBLE PRECISION BASE, CO, SI, TEMP, TMP1, TMP2\n COMPLEX*16 EIG\nC\nC .. Local Arrays ..\n INTEGER IDUM( 1 )\n DOUBLE PRECISION DUM( 6 )\nC\nC .. External Functions ..\n LOGICAL LSAME\n INTEGER IDAMAX\n DOUBLE PRECISION DLAMCH, DLANTR, DLAPY2\n EXTERNAL DLAMCH, DLAPY2, IDAMAX, LSAME\nC\nC .. External Subroutines ..\n EXTERNAL DCOPY, DGEMM, DGEQRF, DGERQF, DLACPY, DLARTG,\n $ DLASET, DORMQR, DORMRQ, DROT, DSCAL, DSWAP,\n $ MA02AD, MB03BD, XERBLA\nC\nC .. Intrinsic Functions ..\n INTRINSIC ABS, DBLE, DCMPLX, DIMAG, INT, MAX, MOD, SQRT\nC\nC .. Executable Statements ..\nC\nC Decode the input arguments.\nC\n M = N/2\n MM = M*M\nC\n LTRI = LSAME( JOB, 'T' )\n LINIQ1 = LSAME( COMPQ1, 'I' )\n LUPDQ1 = LSAME( COMPQ1, 'U' )\n LINIQ2 = LSAME( COMPQ2, 'I' )\n LUPDQ2 = LSAME( COMPQ2, 'U' )\n LINIU1 = LSAME( COMPU1, 'I' )\n LUPDU1 = LSAME( COMPU1, 'U' )\n LINIU2 = LSAME( COMPU2, 'I' )\n LUPDU2 = LSAME( COMPU2, 'U' )\n LCMPQ1 = LINIQ1 .OR. LUPDQ1\n LCMPQ2 = LINIQ2 .OR. LUPDQ2\n LCMPU1 = LINIU1 .OR. LUPDU1\n LCMPU2 = LINIU2 .OR. LUPDU2\n IF( N.EQ.0 ) THEN\n MINDW = 7\n ELSE IF( LTRI .OR. LCMPQ1 .OR. LCMPQ2 .OR. LCMPU1 .OR. LCMPU2 )\n $ THEN\n MINDW = 12*MM + MAX( 6*N, 54 )\n ELSE\n MINDW = 6*MM + MAX( 6*N, 54 )\n END IF\n LQUERY = LDWORK.EQ.-1\nC\nC Test the input arguments.\nC\n INFO = 0\n IF( .NOT.( LSAME( JOB, 'E' ) .OR. LTRI ) ) THEN\n INFO = -1\n ELSE IF( .NOT.( LSAME( COMPQ1, 'N' ) .OR. LCMPQ1 ) ) THEN\n INFO = -2\n ELSE IF( .NOT.( LSAME( COMPQ2, 'N' ) .OR. LCMPQ2 ) ) THEN\n INFO = -3\n ELSE IF( .NOT.( LSAME( COMPU1, 'N' ) .OR. LCMPU1 ) ) THEN\n INFO = -4\n ELSE IF( .NOT.( LSAME( COMPU2, 'N' ) .OR. LCMPU2 ) ) THEN\n INFO = -5\n ELSE IF( N.LT.0 .OR. MOD( N, 2 ).NE.0 ) THEN\n INFO = -6\n ELSE IF( LDZ.LT.MAX( 1, N ) ) THEN\n INFO = -8\n ELSE IF( LDH.LT.MAX( 1, N ) ) THEN\n INFO = -10\n ELSE IF( LDQ1.LT.1 .OR. ( LCMPQ1 .AND. LDQ1.LT.N ) ) THEN\n INFO = -12\n ELSE IF( LDQ2.LT.1 .OR. ( LCMPQ2 .AND. LDQ2.LT.N ) ) THEN\n INFO = -14\n ELSE IF( LDU11.LT.1 .OR. ( LCMPU1 .AND. LDU11.LT.M ) ) THEN\n INFO = -16\n ELSE IF( LDU12.LT.1 .OR. ( LCMPU1 .AND. LDU12.LT.M ) ) THEN\n INFO = -18\n ELSE IF( LDU21.LT.1 .OR. ( LCMPU2 .AND. LDU21.LT.M ) ) THEN\n INFO = -20\n ELSE IF( LDU22.LT.1 .OR. ( LCMPU2 .AND. LDU22.LT.M ) ) THEN\n INFO = -22\n ELSE IF( LDT.LT.MAX( 1, N ) ) THEN\n INFO = -24\n ELSE IF( LIWORK.LT.N+18 ) THEN\n INFO = -29\n ELSE IF( .NOT.LQUERY .AND. LDWORK.LT.MINDW ) THEN\n DWORK( 1 ) = MINDW\n INFO = -31\n END IF\nC\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'MB04AD', -INFO )\n RETURN\n ELSE IF( N.GT.0 ) THEN\nC\nC Compute optimal workspace.\nC\n IF( LQUERY ) THEN\n CALL DORMQR( 'Left', 'Transpose', N, N, M, T, LDT, DWORK, T,\n $ LDT, DWORK, -1, INFO )\n CALL DORMRQ( 'Right', 'Transpose', N, M, M, Z, LDZ, DWORK,\n $ H, LDH, DUM, -1, INFO )\n I = INT( DUM( 1 ) )\n OPTDW = MAX( INT( DWORK( 1 ) ), I )\n CALL DGERQF( M, M, DWORK, M, DWORK, DWORK, -1, INFO )\n CALL DORMRQ( 'Left', 'No Transpose', M, N, M, DWORK, M,\n $ DWORK, H, LDH, DUM, -1, INFO )\n OPTDW = M + MAX( OPTDW, MM + MAX( INT( DWORK( 1 ) ),\n $ INT( DUM( 1 ) ) ) )\n IF( LCMPQ1 )\n $ OPTDW = MAX( OPTDW, M + MM + I )\n CALL DGEQRF( N, M, DWORK, N, DWORK, DWORK, -1, INFO )\n CALL DORMQR( 'Right', 'No Transpose', N, N, M, DWORK, N,\n $ DWORK, H, LDH, DUM, -1, INFO )\n OPTDW = MAX( OPTDW, M + M*N + MAX( INT( DWORK( 1 ) ),\n $ INT( DUM( 1 ) ) ) )\n IF( LCMPQ2 ) THEN\n CALL DORMQR( 'Left', 'No Transpose', N, N, M, DWORK, N,\n $ DWORK, Q2, LDQ2, DWORK, -1, INFO )\n OPTDW = MAX( OPTDW, M + M*N + INT( DWORK( 1 ) ) )\n END IF\n DWORK( 1 ) = MAX( OPTDW, MINDW )\n RETURN\n END IF\n END IF\nC\nC Quick return if possible.\nC\n DUM( 1 ) = ZERO\nC\n IF( N.EQ.0 ) THEN\n IWORK( 1 ) = 0\n DWORK( 1 ) = SEVEN\n CALL DCOPY( 6, DUM, 0, DWORK( 2 ), 1 )\n RETURN\n END IF\nC\nC Determine machine constants.\nC\n BASE = DLAMCH( 'Base' )\n EMIN = INT( DLAMCH( 'Minimum Exponent' ) )\n EMAX = INT( DLAMCH( 'Largest Exponent' ) )\nC\nC Find half of the number of infinite eigenvalues if Z is diagonal.\nC Otherwise, find a lower bound of this number.\nC\n NINF = 0\n IF( N.EQ.1 ) THEN\n IF( Z( 1, 1 ).EQ.ZERO )\n $ NINF = 1\n ELSE\n IF( DLANTR( 'Max', 'Lower', 'No-diag', N-1, N-1, Z( 2, 1 ),\n $ LDZ, DWORK ).EQ.ZERO .AND.\n $ DLANTR( 'Max', 'Upper', 'No-diag', N-1, N-1, Z( 1, 2 ),\n $ LDZ, DWORK ).EQ.ZERO ) THEN\n DO 10 J = 1, M\n IF( Z( J, J ).EQ.ZERO .OR. Z( J+M, J+M ).EQ.ZERO )\n $ NINF = NINF + 1\n 10 CONTINUE\n ELSE\n DO 20 J = 1, M\n I = IDAMAX( N, Z( 1, J ), 1 )\n K = IDAMAX( N, Z( 1, M+J ), 1 )\n L = IDAMAX( N, Z( J, 1 ), LDZ )\n P = IDAMAX( N, Z( M+J, 1 ), LDZ )\n IF( Z( I, J ).EQ.ZERO .OR. Z( K, M+J ).EQ.ZERO .OR.\n $ Z( J, L ).EQ.ZERO .OR. Z( M+J, P ).EQ.ZERO )\n $ NINF = NINF + 1\n 20 CONTINUE\n END IF\n END IF\nC\nC Initializations.\nC\nC Set T = J Z' J'.\nC\n CALL MA02AD( 'Full', M, M, Z( M+1, M+1 ), LDZ, T, LDT )\n CALL MA02AD( 'Full', M, M, Z( 1, M+1 ), LDZ, T( 1, M+1 ), LDT )\nC\n DO 30 I = 1, M\n CALL DSCAL( M, -ONE, T( 1, M+I ), 1 )\n 30 CONTINUE\nC\n CALL MA02AD( 'Full', M, M, Z( M+1, 1 ), LDZ, T( M+1, 1 ), LDT )\nC\n DO 40 I = 1, M\n CALL DSCAL( M, -ONE, T( M+1, I ), 1 )\n 40 CONTINUE\nC\n CALL MA02AD( 'Full', M, M, Z, LDZ, T( M+1, M+1 ), LDT )\nC\n IF( LINIQ1 )\n $ CALL DLASET( 'Full', N, N, ZERO, ONE, Q1, LDQ1 )\nC\n IF( LINIQ2 )\n $ CALL DLASET( 'Full', N, N, ZERO, ONE, Q2, LDQ2 )\nC\n IF( LINIU1 ) THEN\n CALL DLASET( 'Full', M, M, ZERO, ONE, U11, LDU11 )\n CALL DLASET( 'Full', M, M, ZERO, ZERO, U12, LDU12 )\n END IF\nC\n IF( LINIU2 ) THEN\n CALL DLASET( 'Full', M, M, ZERO, ONE, U21, LDU21 )\n CALL DLASET( 'Full', M, M, ZERO, ZERO, U22, LDU22 )\n END IF\nC\nC STEP 1: Block triangularize T and Z.\nC\nC (Note: Comments in the code beginning \"Workspace:\" describe the\nC minimal amount of real workspace needed at that point in the\nC code, as well as the preferred amount for good performance.\nC NB refers to the optimal block size for the immediately\nC following subroutine, as returned by ILAENV.)\nC\n ITAU = 1\n IWRK = ITAU + M\nC\nC ( T11 )\nC Perform a QR decomposition, ( ) = Q1*R1.\nC ( T21 )\nC\nC Workspace: need IWRK + M - 1;\nC prefer IWRK + M*NB - 1.\nC\n CALL DGEQRF( N, M, T, LDT, DWORK( ITAU ), DWORK( IWRK ),\n $ LDWORK-IWRK+1, INFO )\nC\nC ( T12 )\nC Update ( ).\nC ( T22 )\nC\nC Workspace: need IWRK + M - 1;\nC prefer IWRK + M*NB - 1.\nC\n CALL DORMQR( 'Left', 'Transpose', N, M, M, T, LDT, DWORK( ITAU ),\n $ T( 1, M+1 ), LDT, DWORK( IWRK ), LDWORK-IWRK+1, INFO\n $ )\nC\nC Update H.\nC\nC Workspace: need IWRK + N - 1;\nC prefer IWRK + N*NB - 1.\nC\n CALL DORMQR( 'Left', 'Transpose', N, N, M, T, LDT, DWORK( ITAU ),\n $ H, LDH, DWORK( IWRK ), LDWORK-IWRK+1, INFO )\n OPTDW = MAX( MINDW, INT( DWORK( IWRK ) ) + IWRK - 1 )\nC\n IF( LCMPQ1 ) THEN\nC\nC Update Q1.\nC\n CALL DORMQR( 'Right', 'No Transpose', N, N, M, T, LDT,\n $ DWORK( ITAU ), Q1, LDQ1, DWORK( IWRK ),\n $ LDWORK-IWRK+1, INFO )\n END IF\nC\nC Set the strictly lower triangular part of [ T11; T21 ] to zero.\nC\n CALL DLASET( 'Lower', N-1, M, ZERO, ZERO, T( 2, 1 ), LDT )\nC\nC Perform an RQ decomposition, T22 = R2*Q2.\nC\nC Workspace: need IWRK + M - 1;\nC prefer IWRK + M*NB - 1.\nC\n ITAU = MM + 1\n IWRK = ITAU + M\n CALL MA02AD( 'Full', M, M, T( M+1, M+1 ), LDT, DWORK, M )\n CALL DGERQF( M, M, DWORK, M, DWORK( ITAU ), DWORK( IWRK ),\n $ LDWORK-IWRK+1, INFO )\n OPTDW = MAX( OPTDW, INT( DWORK( IWRK ) ) + IWRK - 1 )\n CALL MA02AD( 'Upper', M, M, DWORK, M, T( M+1, M+1 ), LDT )\nC\nC Set the strictly upper triangular part of T22 to zero.\nC\n IF( M.GT.1 )\n $ CALL DLASET( 'Upper', M-1, M-1, ZERO, ZERO, T( M+1, M+2 ), LDT\n $ )\nC\nC Update H.\nC\nC Workspace: need IWRK + N - 1;\nC prefer IWRK + N*NB - 1.\nC\n CALL DORMRQ( 'Left', 'No Transpose', M, N, M, DWORK, M,\n $ DWORK( ITAU ), H( M+1, 1 ), LDH, DWORK( IWRK ),\n $ LDWORK-IWRK+1, INFO )\n OPTDW = MAX( OPTDW, INT( DWORK( IWRK ) ) + IWRK - 1 )\nC\n IF( LCMPQ1 ) THEN\nC\nC Update Q1.\nC\n CALL DORMRQ( 'Right', 'Transpose', N, M, M, DWORK, M,\n $ DWORK( ITAU ), Q1( 1, M+1 ), LDQ1, DWORK( IWRK ),\n $ LDWORK-IWRK+1, INFO )\n OPTDW = MAX( OPTDW, INT( DWORK( IWRK ) ) + IWRK - 1 )\n END IF\nC\nC Perform a QR decomposition, ( Z21 Z22 )' = Q3*R3.\nC\nC Workspace: need IWRK + M - 1;\nC prefer IWRK + M*NB - 1.\nC\n ITAU = M*N + 1\n IWRK = ITAU + M\n CALL MA02AD( 'Full', M, N, Z( M+1, 1 ), LDZ, DWORK, N )\n CALL DGEQRF( N, M, DWORK, N, DWORK( ITAU ), DWORK( IWRK ),\n $ LDWORK-IWRK+1, INFO )\n OPTDW = MAX( OPTDW, INT( DWORK( IWRK ) ) + IWRK - 1 )\nC\nC Update ( Z11 Z12 ).\nC\n CALL DORMQR( 'Right', 'No Transpose', M, N, M, DWORK, N,\n $ DWORK( ITAU ), Z, LDZ, DWORK( IWRK ),\n $ LDWORK-IWRK+1, INFO )\n CALL MA02AD( 'Upper', M, M, DWORK, N, Z( M+1, M+1 ), LDZ )\nC\nC Set the strictly upper triangular part of Z22 to zero.\nC\n IF( M.GT.1 )\n $ CALL DLASET( 'Upper', M-1, M-1, ZERO, ZERO, Z( M+1, M+2 ), LDZ\n $ )\nC\nC Update H.\nC\n CALL DORMQR( 'Right', 'No Transpose', N, N, M, DWORK, N,\n $ DWORK( ITAU ), H, LDH, DWORK( IWRK ), LDWORK-IWRK+1,\n $ INFO )\n OPTDW = MAX( OPTDW, INT( DWORK( IWRK ) ) + IWRK - 1 )\nC\n DO 50 I = 1, M\n CALL DSWAP( N, H( 1, I ), 1, H( 1, M+I ), 1 )\n 50 CONTINUE\nC\n IF( LCMPQ2 ) THEN\nC\nC Update Q2.\nC\n CALL DORMQR( 'Right', 'No Transpose', N, N, M, DWORK, N,\n $ DWORK( ITAU ), Q2, LDQ2, DWORK( IWRK ),\n $ LDWORK-IWRK+1, INFO )\n OPTDW = MAX( OPTDW, INT( DWORK( IWRK ) ) + IWRK - 1 )\nC\n DO 60 I = 1, M\n CALL DSWAP( N, Q2( 1, I ), 1, Q2( 1, M+I ), 1 )\n 60 CONTINUE\n END IF\nC\nC Perform an RQ decomposition Z12 = R4*Q4.\nC\n ITAU = 1\n IWRK = ITAU + M\n CALL DGERQF( M, M, Z( 1, M+1 ), LDZ, DWORK( ITAU ), DWORK( IWRK ),\n $ LDWORK-IWRK+1, INFO )\nC\nC Update H.\nC\n CALL DORMRQ( 'Right', 'Transpose', N, M, M, Z( 1, M+1 ), LDZ,\n $ DWORK( ITAU ), H, LDH, DWORK( IWRK ), LDWORK-IWRK+1,\n $ INFO )\n OPTDW = MAX( OPTDW, INT( DWORK( IWRK ) ) + IWRK - 1 )\nC\n IF( LCMPQ2 ) THEN\nC\nC Update Q2.\nC\n CALL DORMRQ( 'Right', 'Transpose', N, M, M, Z( 1, M+1 ), LDZ,\n $ DWORK( ITAU ), Q2, LDQ2, DWORK( IWRK ),\n $ LDWORK-IWRK+1, INFO )\n END IF\nC\nC Exchange Z11 and Z12 and set the strictly lower triangular part\nC of Z11 to zero.\nC\n DO 70 I = 1, M - 1\n CALL DSWAP( M, Z( 1, I ), 1, Z( 1, M+I ), 1 )\n CALL DCOPY( M-I, DUM, 0, Z( I+1, I ), 1 )\n 70 CONTINUE\nC\n CALL DSWAP( M, Z( 1, M ), 1, Z( 1, N ), 1 )\nC\nC STEP 2: Eliminations in H.\nC\n DO 120 K = 1, M\nC\nC I. Annihilate H(m+k:n-1,k).\nC\n DO 80 J = K, M-1\nC\nC Determine a Givens rotation to annihilate H(m+j,k) from the\nC left.\nC\n CALL DLARTG( H( M+J+1, K ), H( M+J, K ), CO, SI, TMP1 )\nC\nC Update H.\nC\n H( M+J+1, K ) = TMP1\n H( M+J, K ) = ZERO\n CALL DROT( N-K, H( M+J+1, K+1 ), LDH, H( M+J, K+1 ), LDH,\n $ CO, SI )\nC\nC Update T.\nC\n CALL DROT( J+1, T( M+J+1, M+1 ), LDT, T( M+J, M+1 ), LDT,\n $ CO, SI )\nC\n IF( LCMPQ1 ) THEN\nC\nC Update Q1.\nC\n CALL DROT( N, Q1( 1, M+J+1 ), 1, Q1( 1, M+J ), 1, CO, SI\n $ )\n END IF\nC\nC Determine a Givens rotation to annihilate T(m+j,m+j+1) from\nC the right.\nC\n CALL DLARTG( T( M+J, M+J ), T( M+J, M+J+1 ), CO, SI, TMP1 )\nC\nC Update T.\nC\n CALL DROT( M, T( 1, M+J ), 1, T( 1, M+J+1 ), 1, CO , SI )\n T( M+J, M+J ) = TMP1\n T( M+J, M+J+1 ) = ZERO\n CALL DROT( M-J, T( M+J+1, M+J ), 1, T( M+J+1, M+J+1 ), 1,\n $ CO, SI )\n CALL DROT( J+1, T( 1, J ), 1, T( 1, J+1 ), 1, CO, SI )\nC\n IF( LCMPU1 ) THEN\nC\nC Update U11 and U12.\nC\n CALL DROT( M, U11( 1, J ), 1, U11( 1, J+1 ), 1, CO, SI )\n CALL DROT( M, U12( 1, J ), 1, U12( 1, J+1 ), 1, CO, SI )\n END IF\nC\nC Determine a Givens rotation to annihilate T(j+1,j) from the\nC left.\nC\n CALL DLARTG( T( J, J ), T( J+1, J ), CO, SI, TMP1 )\nC\nC Update T.\nC\n T( J, J ) = TMP1\n T( J+1, J ) = ZERO\n CALL DROT( N-J, T( J, J+1 ), LDT, T( J+1, J+1 ), LDT, CO, SI\n $ )\nC\nC Update H.\nC\n CALL DROT( N-K+1, H( J, K ), LDH, H( J+1, K ), LDH, CO, SI )\nC\n IF( LCMPQ1 ) THEN\nC\nC Update Q1.\nC\n CALL DROT( N, Q1( 1, J ), 1, Q1( 1, J+1 ), 1, CO, SI )\n END IF\n 80 CONTINUE\nC\nC II. Annihilate H(n,k).\nC\nC Determine a Givens rotation to annihilate H(n,k) form the left.\nC\n CALL DLARTG( H( M, K ), H( N, K ), CO, SI, TMP1 )\nC\nC Update H.\nC\n H( M, K ) = TMP1\n H( N, K ) = ZERO\n CALL DROT( N-K, H( M, K+1 ), LDH, H( N, K+1 ), LDH, CO, SI )\nC\nC Update T.\nC\n CALL DROT( M, T( M, M+1 ), LDT, T( N, M+1 ), LDT, CO, SI )\n TMP1 = -SI*T( M, M )\n T( M, M ) = CO*T( M, M )\nC\n IF( LCMPQ1 ) THEN\nC\nC Update Q1.\nC\n CALL DROT( N, Q1( 1, M ), 1, Q1( 1, N ), 1, CO, SI )\n END IF\nC\nC Determine a Givens rotation to annihilate T(n,m) from the\nC right.\nC\n CALL DLARTG( T( N, N ), TMP1, CO, SI, TMP2 )\nC\nC Update T.\nC\n CALL DROT( M, T( 1, N ), 1, T( 1, M ), 1, CO, SI )\n T( N, N ) = TMP2\nC\n IF( LCMPU1 ) THEN\nC\nC Update U11 and U12.\nC\n CALL DROT( M, U12( 1, M ), 1, U11( 1, M ), 1, CO, SI )\n END IF\nC\nC III. Annihilate H(k+1:m,k).\nC\n DO 90 J = M, K+1, -1\nC\nC Determine a Givens rotation to annihilate H(j,k) from the\nC left.\nC\n CALL DLARTG( H( J-1, K ), H( J, K ), CO, SI, TMP1 )\nC\nC Update H.\nC\n H( J-1, K ) = TMP1\n H( J, K ) = ZERO\n CALL DROT( N-K, H( J-1, K+1 ), LDH, H( J, K+1 ), LDH, CO, SI\n $ )\nC\nC Update T.\nC\n CALL DROT( N-J+2, T( J-1, J-1 ), LDT, T( J, J-1 ), LDT, CO,\n $ SI )\nC\n IF( LCMPQ1 ) THEN\nC\nC Update Q1.\nC\n CALL DROT( N, Q1( 1, J-1 ), 1, Q1( 1, J ), 1, CO, SI )\n END IF\nC\nC Determine a Givens rotation to annihilate T(j,j-1) from the\nC right.\nC\n CALL DLARTG( T( J, J ), T( J, J-1 ), CO, SI, TMP1 )\nC\nC Update T.\nC\n CALL DROT( M, T( 1, M+J ), 1, T( 1, M+J-1 ), 1, CO, SI )\n CALL DROT( M-J+2, T( M+J-1, M+J ), 1, T( M+J-1, M+J-1 ), 1,\n $ CO, SI )\n T( J, J ) = TMP1\n T( J, J-1 ) = ZERO\n CALL DROT( J-1, T( 1, J ), 1, T( 1, J-1 ), 1, CO, SI )\nC\n IF( LCMPU1 ) THEN\nC\nC Update U11 and U12.\nC\n CALL DROT( M, U11( 1, J ), 1, U11( 1, J-1 ), 1, CO, SI )\n CALL DROT( M, U12( 1, J ), 1, U12( 1, J-1 ), 1, CO, SI )\n END IF\nC\nC Determine a Givens rotation to annihilate T(m+j-1,m-j) from\nC the left.\nC\n CALL DLARTG( T( M+J, M+J ), T( M+J-1, M+J ), CO, SI, TMP1 )\nC\nC Update T.\nC\n T( M+J, M+J ) = TMP1\n T( M+J-1, M+J ) = ZERO\n CALL DROT( J-1, T( M+J, M+1 ), LDT, T( M+J-1, M+1 ), LDT,\n $ CO, SI )\nC\nC Update H.\nC\n CALL DROT( N-K+1, H( M+J, K ), LDH, H( M+J-1, K ), LDH, CO,\n $ SI )\nC\n IF( LCMPQ1 ) THEN\nC\nC Update Q1.\nC\n CALL DROT( N, Q1( 1, M+J ), 1, Q1( 1, M+J-1 ), 1, CO, SI\n $ )\n END IF\n 90 CONTINUE\nC\nC IV. Annihilate H(m+k,k+1:m-1).\nC\n DO 100 J = K+1, M-1\nC\nC Determine a Givens rotation to annihilate H(m+k,j) from the\nC right.\nC\n CALL DLARTG( H( M+K, J+1 ), H( M+K, J ), CO, SI, TMP1 )\nC\nC Update H.\nC\n CALL DROT( M, H( 1, J+1 ), 1, H( 1, J ), 1, CO, SI )\n H( M+K, J+1 ) = TMP1\n H( M+K, J ) = ZERO\n CALL DROT( M-K, H( M+K+1, J+1 ), 1, H( M+K+1, J ), 1, CO, SI\n $ )\nC\nC Update Z.\nC\n CALL DROT( J+1, Z( 1, J+1 ), 1, Z( 1, J ), 1, CO, SI )\nC\n IF( LCMPQ2 ) THEN\nC\nC Update Q2.\nC\n CALL DROT( N, Q2( 1, J+1 ), 1, Q2( 1, J ), 1, CO, SI )\n END IF\nC\nC Determine a Givens rotation to annihilate Z(j+1,j) from the\nC left.\nC\n CALL DLARTG( Z( J, J ), Z( J+1, J ), CO, SI, TMP1 )\nC\nC Update Z.\nC\n Z( J, J ) = TMP1\n Z( J+1, J ) = ZERO\n CALL DROT( N-J, Z( J, J+1 ), LDZ, Z( J+1, J+1 ), LDZ, CO, SI\n $ )\n CALL DROT( J+1, Z( M+J, M+1 ), LDZ, Z( M+J+1, M+1 ), LDZ,\n $ CO, SI )\nC\n IF( LCMPU2 ) THEN\nC\nC Update U21 and U22.\nC\n CALL DROT( M, U21( 1, J ), 1, U21( 1, J+1 ), 1, CO, SI )\n CALL DROT( M, U22( 1, J ), 1, U22( 1, J+1 ), 1, CO, SI )\n END IF\nC\nC Determine a Givens rotation to annihilate Z(m+j,m+j+1) from\nC the right.\nC\n CALL DLARTG( Z( M+J, M+J ), Z( M+J, M+J+1 ), CO, SI, TMP1 )\nC\nC Update Z.\nC\n Z( M+J, M+J ) = TMP1\n Z( M+J, M+J+1 ) = ZERO\n CALL DROT( M, Z( 1, M+J ), 1, Z( 1, M+J+1 ), 1, CO, SI )\n CALL DROT( M-J, Z( M+J+1, M+J ), 1, Z( M+J+1, M+J+1 ), 1,\n $ CO, SI )\nC\nC Update H.\nC\n CALL DROT( M, H( 1, M+J ), 1, H( 1, M+J+1 ), 1, CO, SI )\n CALL DROT( M-K+1, H( M+K, M+J ), 1, H( M+K, M+J+1 ), 1, CO,\n $ SI )\nC\n IF( LCMPQ2 ) THEN\nC\nC Update Q2.\nC\n CALL DROT( N, Q2( 1, M+J ), 1, Q2( 1, M+J+1 ), 1, CO, SI\n $ )\n END IF\n 100 CONTINUE\nC\nC V. Annihilate H(m+k,m).\nC\n IF( K.LT.M ) THEN\nC\nC Determine a Givens rotation to annihilate H(m+k,m) from the\nC right.\nC\n CALL DLARTG( H( M+K, N ), H( M+K, M ), CO, SI, TMP1 )\nC\nC Update H.\nC\n H( M+K, N ) = TMP1\n H( M+K, M ) = ZERO\n CALL DROT( M, H( 1, N ), 1, H( 1, M ), 1, CO, SI )\n CALL DROT( M-K, H( M+K+1, N ), 1, H( M+K+1, M ), 1, CO, SI )\nC\nC Update Z.\nC\n CALL DROT( M, Z( 1, N ), 1, Z( 1, M ), 1, CO, SI )\n TMP1 = -SI*Z( N, N )\n Z( N, N ) = CO*Z( N, N )\nC\n IF( LCMPQ2 ) THEN\nC\nC Update Q2.\nC\n CALL DROT( N, Q2( 1, N ), 1, Q2( 1, M ), 1, CO, SI )\n END IF\nC\nC Determine a Givens rotation to annihilate Z(n,m) from the\nC left.\nC\n CALL DLARTG( Z( M, M ), TMP1, CO, SI, TMP2 )\nC\nC Update Z.\nC\n CALL DROT( M, Z( M, M+1 ), LDZ, Z( N, M+1 ), LDZ, CO, SI )\n Z( M, M ) = TMP2\nC\n IF( LCMPU2 ) THEN\nC\nC Update U2.\nC\n CALL DROT( M, U21( 1, M ), 1, U22( 1, M ), 1, CO, SI )\n END IF\n ELSE\nC\nC Determine a Givens rotation to annihilate H(n,m) from the\nC left.\nC\n CALL DLARTG( H( M, M ), H( N, M ), CO, SI, TMP1 )\nC\nC Update H.\nC\n H( M, M ) = TMP1\n H( N, M ) = ZERO\n CALL DROT( M, H( M, M+1 ), LDH, H( N, M+1 ), LDH, CO, SI )\nC\nC Update T.\nC\n CALL DROT( M, T( M, M+1 ), LDT, T( N, M+1 ), LDT, CO, SI )\n T( M, M ) = CO*T( M, M )\nC\n IF( LCMPQ1 ) THEN\nC\nC Update Q1.\nC\n CALL DROT( N, Q1( 1, M ), 1, Q1( 1, N ), 1, CO, SI )\n END IF\nC\nC Determine a Givens rotation to annihilate T( N, M ) from the\nC right.\nC\n CALL DLARTG( T( N, N ), -SI*T( M, M ), CO, SI, TMP2 )\nC\nC Update T.\nC\n CALL DROT( M, T( 1, N ), 1, T( 1, M ), 1, CO, SI )\n T( N, N ) = TMP2\nC\n IF( LCMPU1 ) THEN\nC\nC Update U1.\nC\n CALL DROT( M, U12( 1, M ), 1, U11( 1, M ), 1, CO, SI )\n END IF\n END IF\nC\nC VI. Annihilate H(m+k,m+k+2:n).\nC\n DO 110 J = M, K+2, -1\nC\nC Determine a Givens rotation to annihilate H(m+k,m+j) from\nC the right.\nC\n CALL DLARTG( H( M+K, M+J-1 ), H( M+K, M+J ), CO, SI, TMP1 )\nC\nC Update H.\nC\n CALL DROT( M, H( 1, M+J-1 ), 1, H( 1, M+J ), 1, CO, SI )\n H( M+K, M+J-1 ) = TMP1\n H( M+K, M+J ) = ZERO\n CALL DROT( M-K, H( M+K+1, M+J-1 ), 1, H( M+K+1, M+J ), 1,\n $ CO, SI )\nC\nC Update Z.\nC\n CALL DROT( M, Z( 1, M+J-1 ), 1, Z( 1, M+J ), 1, CO, SI )\n CALL DROT( M-J+2, Z( M+J-1, M+J-1 ), 1, Z( M+J-1, M+J ), 1,\n $ CO, SI )\nC\n IF( LCMPQ2 ) THEN\nC\nC Update Q2.\nC\n CALL DROT( N, Q2( 1, M+J-1 ), 1, Q2( 1, M+J ), 1, CO, SI\n $ )\n END IF\nC\nC Determine a Givens rotation to annihilate Z(m+j-1,m+j) from\nC the left.\nC\n CALL DLARTG( Z( M+J, M+J ), Z( M+J-1, M+J ), CO, SI, TMP1 )\nC\nC Update Z.\nC\n Z( M+J, M+J ) = TMP1\n Z( M+J-1, M+J ) = ZERO\n CALL DROT( J-1, Z( M+J, M+1 ), LDZ, Z( M+J-1, M+1 ), LDZ,\n $ CO, SI )\n CALL DROT( N-J+2, Z( J, J-1 ), LDZ, Z( J-1, J-1 ), LDZ, CO,\n $ SI )\nC\n IF( LCMPU2 ) THEN\nC\nC Update U2.\nC\n CALL DROT( M, U21( 1, J ), 1, U21( 1, J-1 ), 1, CO, SI )\n CALL DROT( M, U22( 1, J ), 1, U22( 1, J-1 ), 1, CO, SI )\n END IF\nC\nC Determine a Givens rotation to annihilate Z(j,j-1) from the\nC right.\nC\n CALL DLARTG( Z( J, J ), Z( J, J-1 ), CO, SI, TMP1 )\nC\nC Update Z.\nC\n Z( J, J ) = TMP1\n Z( J, J-1 ) = ZERO\n CALL DROT( J-1, Z( 1, J ), 1, Z( 1, J-1 ), 1, CO, SI )\nC\nC Update H.\nC\n CALL DROT( M, H( 1, J ), 1, H( 1, J-1 ), 1, CO, SI )\n CALL DROT( M-K+1, H( M+K, J ), 1, H( M+K, J-1 ), 1, CO, SI )\nC\n IF( LCMPQ2 ) THEN\nC\nC Update Q2.\nC\n CALL DROT( N, Q2( 1, J ), 1, Q2( 1, J-1 ), 1, CO, SI )\n END IF\n 110 CONTINUE\nC\n 120 CONTINUE\nC\nC Now T, Z, H are in block forms (1) and H22' is upper Hessenberg.\nC\nC STEP 3: Apply periodic QZ algorithm to the generalized matrix\nC\nC -1 -1 -1 -1\nC product H22 T22 T11 H11 Z11 Z22 to transform H22'\nC to upper quasi-triangular form while T11, T22', Z11, Z22',\nC and H11 stay in upper triangular form.\nC\nC Determine the mode of computations.\nC\n IQ = 1\n IF( LTRI .OR. LCMPQ1 .OR. LCMPQ2 .OR. LCMPU1 .OR. LCMPU2 ) THEN\n CMPQ = 'Initialize'\n IMAT = 6*MM + 1\n IWRK = 12*MM + 1\n ELSE\n CMPQ = 'No Computation'\n IMAT = 1\n IWRK = 6*MM + 1\n END IF\nC\n IF( LTRI ) THEN\n CMPSC = 'Schur Form'\n ELSE\n CMPSC = 'Eigenvalues Only'\n END IF\nC\nC Save matrices in structure that is required by MB03BD.\nC\n CALL MA02AD( 'Lower', M, M, H( M+1, M+1 ), LDH, DWORK( IMAT ), M )\n CALL DCOPY( M-1, H( M+1, M+2 ), LDH+1, DWORK( IMAT+1 ), M+1 )\n CALL DLASET( 'Lower', M-2, M-2, ZERO, ZERO, DWORK( IMAT+2 ), M )\n CALL MA02AD( 'Lower', M, M, T( M+1, M+1 ), LDT, DWORK( IMAT+MM ),\n $ M )\n CALL DLASET( 'Lower', M-1, M-1, ZERO, ZERO, DWORK( IMAT+MM+1 ),\n $ M )\n CALL DLACPY( 'Upper', M, M, T, LDT, DWORK( IMAT+2*MM ), M )\n CALL DLASET( 'Lower', M-1, M-1, ZERO, ZERO, DWORK( IMAT+2*MM+1 ),\n $ M )\n CALL DLACPY( 'Upper', M, M, H, LDH, DWORK( IMAT+3*MM ), M )\n CALL DLASET( 'Lower', M-1, M-1, ZERO, ZERO, DWORK( IMAT+3*MM+1 ),\n $ M )\n CALL DLACPY( 'Upper', M, M, Z, LDZ, DWORK( IMAT+4*MM ), M )\n CALL DLASET( 'Lower', M-1, M-1, ZERO, ZERO, DWORK( IMAT+4*MM+1 ),\n $ M )\n CALL MA02AD( 'Lower', M, M, Z( M+1, M+1 ), LDZ,\n $ DWORK( IMAT+5*MM ), M )\n CALL DLASET( 'Lower', M-1, M-1, ZERO, ZERO, DWORK( IMAT+5*MM+1 ),\n $ M )\nC\n IWORK( 1 ) = 1\n IWORK( 2 ) = -1\n IWORK( 3 ) = -1\n IWORK( 4 ) = 1\n IWORK( 5 ) = -1\n IWORK( 6 ) = -1\nC\nC Apply periodic QZ algorithm.\nC Workspace: need IWRK + MAX( N, 48 ) + 5.\nC Integer workspace: need N + 18.\nC\n CALL MB03BD( CMPSC, 'Careful', CMPQ, IDUM, 6, M, 1, 1, M, IWORK,\n $ DWORK( IMAT ), M, M, DWORK( IQ ), M, M, ALPHAR,\n $ ALPHAI, BETA, IWORK( 7 ), IWORK( M+7 ),\n $ LIWORK-( M+6 ), DWORK( IWRK ), LDWORK-IWRK+1, IWARN,\n $ INFO )\n IF( IWARN.GT.0 .AND. IWARN.LT.M ) THEN\n INFO = 1\n RETURN\n ELSE IF( IWARN.EQ.M+1 ) THEN\n INFO = 3\n ELSE IF( INFO.GT.0 ) THEN\n INFO = 2\n RETURN\n END IF\n NBETA0 = 0\n I11 = 0\n I22 = 0\n I2X2 = 0\nC\nC Compute the \"non-negative\" eigenvalues of the pencil aTZ - bH.\nC These are the eigenvalues with positive real parts or with\nC non-negative imaginary parts, when real parts are zero.\nC Also, count the number of 2-by-2 diagonal blocks, I2X2, and the\nC number of 1-by-1 and 2-by-2 blocks with unreliable eigenvalues,\nC I11 and I22, respectively.\nC\n I = 1\nC WHILE( I.LE.M ) DO\n 130 CONTINUE\n IF( I.LE.M ) THEN\n IF( NINF.GT.0 ) THEN\n IF( BETA( I ).EQ.ZERO )\n $ NBETA0 = NBETA0 + 1\n END IF\n IF( IWORK( I+6 ).GE.2*EMIN .AND. IWORK( I+6 ).LE.2*EMAX ) THEN\nC\nC B = SQRT(BASE**IWORK(i+6)) is between underflow and overflow\nC threshold, BETA(i) is divided by B.\nC\n BETA( I ) = BETA( I )/BASE**( HALF*IWORK( I+6 ) )\n IF( BETA( I ).NE.ZERO ) THEN\n IF( IWORK( M+I+7 ).LT.0 ) THEN\n I22 = I22 + 1\n ELSE IF( IWORK( M+I+7 ).GT.0 ) THEN\n I11 = I11 + 1\n END IF\n EIG = SQRT( DCMPLX( ALPHAR( I ), ALPHAI( I ) ) )\n ALPHAR( I ) = DIMAG( EIG )\n ALPHAI( I ) = DBLE( EIG )\n IF( ALPHAR( I ).LT.ZERO )\n $ ALPHAR( I ) = -ALPHAR( I )\n IF( ALPHAI( I ).LT.ZERO )\n $ ALPHAI( I ) = -ALPHAI( I )\n IF( ALPHAR( I ).NE.ZERO .AND. ALPHAI( I ).NE.ZERO ) THEN\n ALPHAR( I+1 ) = -ALPHAR( I )\n ALPHAI( I+1 ) = ALPHAI( I )\n BETA( I+1 ) = BETA( I )\n I2X2 = I2X2 + 1\n I = I + 1\n END IF\n END IF\n ELSE IF( IWORK( I+6 ).LT.2*EMIN ) THEN\nC\nC Set to zero the numerator part of the eigenvalue.\nC\n ALPHAR( I ) = ZERO\n ALPHAI( I ) = ZERO\n I11 = I11 + 1\n ELSE\nC\nC Set an infinite eigenvalue.\nC\n IF( NINF.GT.0 )\n $ NBETA0 = NBETA0 + 1\n BETA( I ) = ZERO\n I11 = I11 + 1\n END IF\n I = I + 1\n GO TO 130\n END IF\nC END WHILE 130\nC\n IWORK( 1 ) = I11 + I22\nC\nC Set to infinity the largest eigenvalues, if necessary.\nC\n L = 0\n IF( NINF.GT.0 ) THEN\n DO 150 J = 1, NINF - NBETA0\n TMP1 = ZERO\n TMP2 = ONE\n P = 1\n DO 140 I = 1, M\n IF( BETA( I ).GT.ZERO ) THEN\n TEMP = DLAPY2( ALPHAR( I ), ALPHAI( I ) )\n IF( TEMP.GT.TMP1 .AND. TMP2.GE.BETA( I ) ) THEN\n TMP1 = TEMP\n TMP2 = BETA( I )\n P = I\n END IF\n END IF\n 140 CONTINUE\n L = L + 1\n BETA( P ) = ZERO\n 150 CONTINUE\nC\n IF( L.EQ.IWORK( 1 ) ) THEN\nC\nC All unreliable eigenvalues found have been set to infinity.\nC\n INFO = 0\n I11 = 0\n I22 = 0\n IWORK( 1 ) = 0\n END IF\n END IF\nC\nC Save the norms of the factors.\nC\n CALL DCOPY( 6, DWORK( IWRK+1 ), 1, DUM, 1 )\nC\nC Save the sextuples of the 1-by-1 and 2-by-2 diagonal blocks.\nC All 1-by-1 diagonal blocks come first.\nC Save also information about blocks with possible loss of accuracy.\nC\nC Workspace: IWRK+w-1, where w = 6 if M = 1, or w = 6*N, otherwise.\nC\n K = IWRK\n IW = IWORK( 1 )\n I = 1\n J = 1\n L = 6*( M - 2*I2X2 ) + K\nC\nC WHILE( I.LE.N ) DO\n UNREL = .FALSE.\n 160 CONTINUE\n IF( I.LE.M ) THEN\n IF( J.LE.IW )\n $ UNREL = I.EQ.ABS( IWORK( M+I+7 ) )\n IF( ALPHAR( I ).NE.ZERO .AND. BETA( I ).NE.ZERO .AND.\n $ ALPHAI( I ).NE.ZERO ) THEN\n IF( UNREL ) THEN\n J = J + 1\n IWORK( J ) = IWORK( M+I+7 )\n IWORK( IW+J ) = L - IWRK + 1\n UNREL = .FALSE.\n END IF\n CALL DLACPY( 'Full', 2, 2, DWORK( IMAT+(M+1)*(I-1) ), M,\n $ DWORK( L ), 2 )\n CALL DLACPY( 'Full', 2, 2, DWORK( IMAT+(M+1)*(I-1)+MM ), M,\n $ DWORK( L+4 ), 2 )\n CALL DLACPY( 'Full', 2, 2, DWORK( IMAT+(M+1)*(I-1)+2*MM ),\n $ M, DWORK( L+8 ), 2 )\n CALL DLACPY( 'Full', 2, 2, DWORK( IMAT+(M+1)*(I-1)+3*MM ),\n $ M, DWORK( L+12 ), 2 )\n CALL DLACPY( 'Full', 2, 2, DWORK( IMAT+(M+1)*(I-1)+4*MM ),\n $ M, DWORK( L+16 ), 2 )\n CALL DLACPY( 'Full', 2, 2, DWORK( IMAT+(M+1)*(I-1)+5*MM ),\n $ M, DWORK( L+20 ), 2 )\n L = L + 24\n I = I + 2\n ELSE\n IF ( UNREL ) THEN\n J = J + 1\n IWORK( J ) = I\n IWORK( IW+J ) = K - IWRK + 1\n UNREL = .FALSE.\n END IF\n CALL DCOPY( 6, DWORK( IMAT+(M+1)*(I-1) ), MM, DWORK( K ),\n $ 1 )\n K = K + 6\n I = I + 1\n END IF\n GO TO 160\n END IF\nC END WHILE 160\nC\n IWORK( 2*IW+2 ) = I11\n IWORK( 2*IW+3 ) = I22\n IWORK( 2*IW+4 ) = I2X2\nC\n IF( LTRI ) THEN\nC\nC Update H.\nC\n CALL DLACPY( 'Upper', M, M, DWORK( IMAT+3*MM ), M, H, LDH )\n CALL MA02AD( 'Full', M, M, DWORK( IMAT ), M, H( M+1, M+1 ),\n $ LDH )\n CALL DGEMM( 'Transpose', 'No Transpose', M, M, M, ONE,\n $ DWORK( IQ+3*MM ), M, H( 1, M+1 ), LDH, ZERO,\n $ DWORK( IMAT ), M )\n CALL DGEMM( 'No Transpose', 'No Transpose', M, M, M, ONE,\n $ DWORK( IMAT ), M, DWORK, M, ZERO, H( 1, M+1 ),\n $ LDH )\nC\nC Update T.\nC\n CALL DLACPY( 'Upper', M, M, DWORK( IMAT+2*MM ), M, T, LDT )\n CALL DGEMM( 'Transpose', 'No Transpose', M, M, M, ONE,\n $ DWORK( IQ+3*MM ), M, T( 1, M+1 ), LDT, ZERO,\n $ DWORK( IMAT ), M )\n CALL DGEMM( 'No Transpose', 'No Transpose', M, M, M, ONE,\n $ DWORK( IMAT ), M, DWORK( IQ+2*MM ), M, ZERO,\n $ T( 1, M+1 ), LDT )\n CALL MA02AD( 'Upper', M, M, DWORK( IMAT+MM ), M, T( M+1, M+1 ),\n $ LDT )\nC\nC Update Z.\nC\n CALL DLACPY( 'Upper', M, M, DWORK( IMAT+4*MM ), M, Z, LDZ )\n CALL DGEMM( 'Transpose', 'No Transpose', M, M, M, ONE,\n $ DWORK( IQ+5*MM ), M, Z( 1, M+1 ), LDZ, ZERO,\n $ DWORK( IMAT ), M )\n CALL DGEMM( 'No Transpose', 'No Transpose', M, M, M, ONE,\n $ DWORK( IMAT ), M, DWORK, M, ZERO, Z( 1, M+1 ),\n $ LDZ )\n CALL MA02AD( 'Upper', M, M, DWORK( IMAT+5*MM ), M,\n $ Z( M+1, M+1 ), LDZ )\nC\n IF( LCMPQ1 ) THEN\nC\nC Update Q1.\nC\n CALL DGEMM( 'No Transpose', 'No Transpose', N, M, M, ONE,\n $ Q1, LDQ1, DWORK( IQ+3*MM ), M, ZERO,\n $ DWORK( IMAT ), N )\n CALL DLACPY( 'Full', N, M, DWORK( IMAT ), N, Q1, LDQ1 )\n CALL DGEMM( 'No Transpose', 'No Transpose', N, M, M, ONE,\n $ Q1( 1, M+1 ), LDQ1, DWORK( IQ+MM ), M, ZERO,\n $ DWORK( IMAT ), N )\n CALL DLACPY( 'Full', N, M, DWORK( IMAT ), N, Q1( 1, M+1 ),\n $ LDQ1 )\n END IF\nC\n IF( LCMPQ2 ) THEN\nC\nC Update Q2.\nC\n CALL DGEMM( 'No Transpose', 'No Transpose', N, M, M, ONE,\n $ Q2, LDQ2, DWORK( IQ+4*MM ), M, ZERO,\n $ DWORK( IMAT ), N )\n CALL DLACPY( 'Full', N, M, DWORK( IMAT ), N, Q2, LDQ2 )\n CALL DGEMM( 'No Transpose', 'No Transpose', N, M, M, ONE,\n $ Q2( 1, M+1 ), LDQ2, DWORK, M, ZERO,\n $ DWORK( IMAT ), N )\n CALL DLACPY( 'Full', N, M, DWORK( IMAT ), N, Q2( 1, M+1 ),\n $ LDQ2 )\n END IF\nC\n IF( LCMPU1 ) THEN\nC\nC Update U11 and U12.\nC\n CALL DGEMM( 'No Transpose', 'No Transpose', M, M, M, ONE,\n $ U11, LDU11, DWORK( IQ+2*MM ), M, ZERO,\n $ DWORK( IMAT ), M )\n CALL DLACPY( 'Full', M, M, DWORK( IMAT ), M, U11, LDU11 )\n CALL DGEMM( 'No Transpose', 'No Transpose', M, M, M, ONE,\n $ U12, LDU12, DWORK( IQ+2*MM ), M, ZERO,\n $ DWORK( IMAT ), M )\n CALL DLACPY( 'Full', M, M, DWORK( IMAT ), M, U12, LDU12 )\n END IF\nC\n IF( LCMPU2 ) THEN\nC\nC Update U21 and U22.\nC\n CALL DGEMM( 'No Transpose', 'No Transpose', M, M, M, ONE,\n $ U21, LDU21, DWORK( IQ+5*MM ), M, ZERO,\n $ DWORK( IMAT ), M )\n CALL DLACPY( 'Full', M, M, DWORK( IMAT ), M, U21, LDU21 )\n CALL DGEMM( 'No Transpose', 'No Transpose', M, M, M, ONE,\n $ U22, LDU22, DWORK( IQ+5*MM ), M, ZERO,\n $ DWORK( IMAT ), M )\n CALL DLACPY( 'Full', M, M, DWORK( IMAT ), M, U22, LDU22 )\n END IF\n END IF\nC\nC Move the norms, and the sextuples of 1-by-1 and 2-by-2 blocks\nC in front.\nC\n K = 6*( M - 2*I2X2 ) + 24*I2X2\n CALL DCOPY( K, DWORK( IWRK ), 1, DWORK( 8 ), 1 )\n CALL DCOPY( 6, DUM, 1, DWORK( 2 ), 1 )\nC\n DWORK( 1 ) = OPTDW\n RETURN\nC *** Last line of MB04AD ***\n END\n", "meta": {"hexsha": "136816ea46ae3fbb692f3a4b2b152e3797b9bd23", "size": 58747, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB04AD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB04AD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB04AD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 36.0853808354, "max_line_length": 72, "alphanum_fraction": 0.4760243076, "num_tokens": 20313, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9585377249197138, "lm_q2_score": 0.6893056295505783, "lm_q1q2_score": 0.6607254499237624}} {"text": "program test_transfer\r\nuse iso_fortran_env, only: int64, real64\r\nimplicit none\r\ntype :: point\r\n real :: a,b\r\nend type point\r\nreal :: x(2)\r\ncomplex :: z\r\ntype(point) :: p\r\ninteger(kind=int64) :: i\r\nreal(kind=real64) :: d\r\ncharacter(8) :: s\r\nz = (3.0,4.0)\r\nx = transfer(z,x) ! copy complex to 2 reals\r\nprint*,x ! 3.0 4.0\r\np = transfer(x,p) ! copy 2 reals to type(point)\r\nprint*,p ! 3.0 4.0\r\nx = transfer(p,x) ! copy type(point) to 2 reals\r\nprint*,x ! 3.0 4.0\r\ni = huge(i)\r\n! converting from int64 to real64 and back using\r\n! nint and real does not work for huge(1_int64)\r\nprint*,i,nint(real(i,kind=real64),kind=real64)\r\n! transferring from int64 to real64 and back works\r\nprint*,i,transfer(transfer(i,d),i)\r\n! transfer character (len=8) to real64 and back\r\ns = \"aeio+-*/\"\r\nprint*,s // \" \" // transfer(transfer(s,d),s)\r\nend program test_transfer\r\n! output:\r\n! 3.00000000 4.00000000 \r\n! 3.00000000 4.00000000 \r\n! 3.00000000 4.00000000 \r\n! 9223372036854775807 -9223372036854775808\r\n! 9223372036854775807 9223372036854775807\r\n! aeio+-*/ aeio+-*/", "meta": {"hexsha": "4be90e5560fb332c6c917211ea437c0f8fee57a5", "size": 1085, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "transfer.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": "transfer.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": "transfer.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": 30.1388888889, "max_line_length": 51, "alphanum_fraction": 0.6479262673, "num_tokens": 391, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711832583695, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.6606824915190931}} {"text": "submodule(euler_interface_m) euler_prob_0031_m\n implicit none\n\ncontains\n\n module character(len=20) function euler0031()\n write (euler0031, \"(i20)\") ans(200)\n end function euler0031\n\n integer function ans(n)\n integer, intent(in) :: n\n integer :: coins(0:7), i, j\n integer :: ans_arr(0:7, 0:n)\n\n coins = [1, 2, 5, 10, 20, 50, 100, 200]\n ans_arr(1:7, :) = 0\n ans_arr(0, :) = 1\n\n outer: do j = 0, n\n inner: do i = 1, 7\n associate (next => ans_arr(i, j), prev => ans_arr(i - 1, j))\n if (j < coins(i)) then\n next = prev\n else\n next = prev + ans_arr(i, j - coins(i))\n end if\n end associate\n end do inner\n end do outer\n ans = ans_arr(7, n)\n end function ans\n\nend submodule euler_prob_0031_m\n", "meta": {"hexsha": "3b1692116db3bac5a6f59814db6b01c2ae00faf2", "size": 923, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "docs/src/prob_0031_m.f90", "max_stars_repo_name": "han190/PE-Fortran", "max_stars_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-02-09T07:07:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-31T07:45:48.000Z", "max_issues_repo_path": "docs/src/prob_0031_m.f90", "max_issues_repo_name": "han190/PE-Fortran", "max_issues_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-14T00:48:58.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-14T00:48:58.000Z", "max_forks_repo_path": "docs/src/prob_0031_m.f90", "max_forks_repo_name": "han190/PE-Fortran", "max_forks_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-04T21:29:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T21:29:45.000Z", "avg_line_length": 27.1470588235, "max_line_length": 76, "alphanum_fraction": 0.4842903575, "num_tokens": 267, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711756575749, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.6606824680712473}} {"text": "!\n! Copyright (C) 2004-2006 Quantum ESPRESSO group\n! This file is distributed under the terms of the\n! GNU General Public License. See the file `License'\n! in the root directory of the present distribution,\n! or http://www.gnu.org/copyleft/gpl.txt .\n!\n!---------------------------------------------------------------------------\nMODULE splinelib\n !---------------------------------------------------------------------------\n !\n USE kinds, ONLY : DP\n !\n IMPLICIT NONE\n !\n PRIVATE\n !\n PUBLIC :: dosplineint, spline, splint, splint_deriv\n !\n INTERFACE dosplineint\n !\n MODULE PROCEDURE dosplineint_1D, dosplineint_2D\n !\n END INTERFACE\n !\n CONTAINS\n !\n !------------------------------------------------------------------------\n SUBROUTINE spline( xdata, ydata, startu, startd, d2y )\n !------------------------------------------------------------------------\n !\n IMPLICIT NONE\n !\n REAL(DP), INTENT(IN) :: xdata(:), ydata(:), startu, startd \n REAL(DP), INTENT(OUT) :: d2y(:)\n !\n INTEGER :: i, k, ydim\n REAL(DP) :: p, sig\n REAL(DP), ALLOCATABLE :: u(:)\n !\n !\n ydim = SIZE( ydata )\n !\n ALLOCATE( u( ydim ) )\n !\n u(1) = startu\n d2y(1) = startd\n !\n DO i = 2, ydim - 1\n !\n sig = ( xdata(i) - xdata(i-1) ) / ( xdata(i+1) - xdata(i-1) ) \n p = sig * d2y(i- 1) + 2.0_DP \n d2y(i) = ( sig - 1.0_DP ) / p \n u(i) = ( 6.0_DP * ( ( ydata(i+1) - ydata(i) ) / &\n ( xdata(i+1) - xdata(i) ) - ( ydata(i) - ydata(i-1) ) / &\n ( xdata(i) - xdata(i-1) ) ) / &\n ( xdata(i+1) - xdata(i-1) ) - sig * u(i-1) ) / p \n ! \n END DO\n !\n d2y(ydim) = 0 \n !\n DO k = ydim - 1, 1, -1 \n !\n d2y(k) = d2y(k) * d2y(k+1) + u(k) \n !\n END DO\n !\n DEALLOCATE( u )\n !\n END SUBROUTINE spline\n !\n !------------------------------------------------------------------------\n FUNCTION splint( xdata, ydata, d2y, x )\n !------------------------------------------------------------------------\n !\n IMPLICIT NONE\n !\n REAL(DP), INTENT(IN) :: xdata(:), ydata(:), d2y(:)\n REAL(DP), INTENT(IN) :: x\n !\n REAL(DP) :: splint\n INTEGER :: khi, klo, xdim\n REAL(DP) :: a, b, h\n !\n !\n xdim = SIZE( xdata )\n !\n klo = 1\n khi = xdim\n !\n klo = MAX( MIN( locate( xdata, x ), ( xdim - 1 ) ), 1 )\n !\n khi = klo + 1\n !\n h = xdata(khi) - xdata(klo)\n !\n a = ( xdata(khi) - x ) / h\n b = ( x - xdata(klo) ) / h\n !\n splint = a * ydata(klo) + b * ydata(khi) + &\n ( ( a**3 - a ) * d2y(klo) + ( b**3 - b ) * d2y(khi) ) * &\n ( h**2 ) / 6.0_DP\n\n END FUNCTION splint\n\n\n !------------------------------------------------------------------------\n FUNCTION splint_deriv( xdata, ydata, d2y, x )\n !------------------------------------------------------------------------\n !\n IMPLICIT NONE\n !\n REAL(DP), INTENT(IN) :: xdata(:), ydata(:), d2y(:)\n REAL(DP), INTENT(IN) :: x\n !\n REAL(DP) :: splint_deriv\n INTEGER :: khi, klo, xdim\n REAL(DP) :: a, b, da, db, h\n !\n !\n xdim = SIZE( xdata )\n !\n klo = 1\n khi = xdim\n !\n klo = MAX( MIN( locate( xdata, x ), ( xdim - 1 ) ), 1 )\n !\n khi = klo + 1\n !\n h = xdata(khi) - xdata(klo)\n !\n a = ( xdata(khi) - x ) / h\n b = ( x - xdata(klo) ) / h\n da = -1.0_DP / h\n db = 1.0_DP / h\n !\n splint_deriv = da * ydata(klo) + db * ydata(khi) + &\n ( ( 3.0_DP*a**2 - 1.0_DP ) * da * d2y(klo) + &\n ( 3.0_DP*b**2 - 1.0_DP ) * db * d2y(khi) ) * &\n ( h**2 ) / 6.0_DP\n\n END FUNCTION splint_deriv\n\n !-------------------------------------------------------------------\n FUNCTION locate( xx, x )\n !-------------------------------------------------------------------\n !\n IMPLICIT NONE\n !\n REAL(DP), INTENT(IN) :: xx(:)\n REAL(DP), INTENT(IN) :: x\n !\n INTEGER :: locate\n INTEGER :: n, jl, jm, ju\n LOGICAL :: ascnd\n !\n !\n n = SIZE( xx )\n ascnd = ( xx(n) >= xx(1) )\n jl = 0\n ju = n + 1\n !\n main_loop: DO\n !\n IF ( ( ju - jl ) <= 1 ) EXIT main_loop\n ! \n jm = ( ju + jl ) / 2\n !\n IF ( ascnd .EQV. ( x >= xx(jm) ) ) THEN\n !\n jl = jm\n !\n ELSE\n !\n ju = jm\n !\n END IF\n !\n END DO main_loop\n !\n IF ( x == xx(1) ) THEN\n !\n locate = 1\n !\n ELSE IF ( x == xx(n) ) THEN\n !\n locate = n - 1\n !\n ELSE \n !\n locate = jl\n !\n END IF\n !\n END FUNCTION locate \n !\n !\n !------------------------------------------------------------------------\n SUBROUTINE dosplineint_1D( old_mesh, old_vec, new_mesh, new_vec )\n !------------------------------------------------------------------------\n !\n IMPLICIT NONE\n !\n REAL (DP), INTENT(IN) :: old_mesh(:), new_mesh(:)\n REAL (DP), INTENT(IN) :: old_vec(:)\n REAL (DP), INTENT(OUT) :: new_vec(:)\n !\n REAL (DP), ALLOCATABLE :: d2y(:)\n INTEGER :: i\n INTEGER :: old_dim, new_dim\n !\n !\n old_dim = SIZE( old_vec )\n new_dim = SIZE( new_vec )\n !\n IF ( old_dim /= SIZE( old_mesh ) ) &\n CALL errore( 'dosplineint', &\n 'dimensions of old_mesh and old_vec do not match', 1 ) \n !\n IF ( new_dim /= SIZE( new_mesh ) ) &\n CALL errore( 'dosplineint', &\n 'dimensions of new_mesh and new_vec do not match', 1 ) \n !\n ALLOCATE( d2y( old_dim ) )\n !\n d2y = 0\n !\n CALL spline( old_mesh , old_vec(:), 0.0_DP, 0.0_DP, d2y ) \n !\n DO i = 1, new_dim\n !\n new_vec(i) = splint( old_mesh, old_vec(:), d2y, new_mesh(i) )\n !\n END DO\n !\n DEALLOCATE( d2y )\n !\n END SUBROUTINE dosplineint_1D\n ! \n !------------------------------------------------------------------------\n SUBROUTINE dosplineint_2D( old_mesh, old_vec, new_mesh, new_vec )\n !------------------------------------------------------------------------\n !\n IMPLICIT NONE\n !\n REAL (DP), INTENT(IN) :: old_mesh(:), new_mesh(:)\n REAL (DP), INTENT(IN) :: old_vec(:,:)\n REAL (DP), INTENT(OUT) :: new_vec(:,:)\n !\n REAL (DP), ALLOCATABLE :: d2y(:)\n INTEGER :: dim, i, j\n INTEGER :: old_dim, new_dim\n !\n !\n dim = SIZE( old_vec, 1 )\n !\n IF( dim /= SIZE( new_vec, 1 ) ) &\n CALL errore( 'dosplineint', &\n 'dimensions of old_vec and new_vec do not match', 1 )\n !\n old_dim = SIZE( old_vec, 2 )\n new_dim = SIZE( new_vec, 2 )\n !\n IF ( old_dim /= SIZE( old_mesh, 1 ) ) &\n CALL errore( 'dosplineint', &\n 'dimensions of old_mesh and old_vec do not match', 1 ) \n !\n IF ( new_dim /= SIZE( new_mesh, 1 ) ) &\n CALL errore( 'dosplineint', &\n 'dimensions of new_mesh and new_vec do not match', 1 ) \n !\n ALLOCATE( d2y( old_dim ) )\n !\n DO i = 1, dim\n ! \n d2y = 0\n !\n CALL spline( old_mesh , old_vec(i,:), 0.0_DP, 0.0_DP, d2y ) \n !\n DO j = 1, new_dim\n !\n new_vec(i,j) = splint( old_mesh, old_vec(i,:), d2y, new_mesh(j) )\n !\n END DO\n !\n END DO\n !\n DEALLOCATE( d2y )\n !\n END SUBROUTINE dosplineint_2D\n !\nEND MODULE splinelib\n", "meta": {"hexsha": "ced4a78add3086d187f9ec577a608fc9ba785334", "size": 8292, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/apps/miniDFT/tests/src/splinelib.f90", "max_stars_repo_name": "utdsimmons/ohpc", "max_stars_repo_head_hexsha": "70dc728926a835ba049ddd3f4627ef08db7c95a0", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 692, "max_stars_repo_stars_event_min_datetime": "2015-11-12T13:56:43.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T03:45:59.000Z", "max_issues_repo_path": "tests/apps/miniDFT/tests/src/splinelib.f90", "max_issues_repo_name": "utdsimmons/ohpc", "max_issues_repo_head_hexsha": "70dc728926a835ba049ddd3f4627ef08db7c95a0", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1096, "max_issues_repo_issues_event_min_datetime": "2015-11-12T09:08:22.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:48:41.000Z", "max_forks_repo_path": "tests/apps/miniDFT/tests/src/splinelib.f90", "max_forks_repo_name": "utdsimmons/ohpc", "max_forks_repo_head_hexsha": "70dc728926a835ba049ddd3f4627ef08db7c95a0", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 224, "max_forks_repo_forks_event_min_datetime": "2015-11-12T21:17:03.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T00:57:48.000Z", "avg_line_length": 28.2040816327, "max_line_length": 85, "alphanum_fraction": 0.351905451, "num_tokens": 2360, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711642563823, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.6606824679789766}} {"text": " subroutine dplog(u,n,gg)\n!----------------------------------------------------------------------\n!\n! m\n! Purpose - calculates derivatives (-d/du) [ln(1+u)/u]\n!\n!----------------------------------------------------------------------\n implicit real (16) (a-h,o-z)\n parameter (lenl=200,lenl2=3*lenl)\n dimension gg(0:lenl2),ff(0:lenl2)\n real (16), parameter :: zero = 0.0q0\n real (16), parameter :: one = 1.0q0\n real (16), parameter :: threshold = 0.05q0 \n\n epsm = epsilon(one)\n au = abs(u)\n!\n if (au > threshold) then\n uinv = one/u\n u1inv = one/(one+u)\n ff(0) = log(one+u)\n ff(1) = -u1inv\n gg(0) = ff(0)*uinv\n gg(1) = uinv*(gg(0)+ff(1))\n do i=2,n\n ff(i) = (i-1)*ff(i-1)*u1inv\n gg(i) = uinv*(i*gg(i-1)+ff(i))\n end do\n else if (au == zero) then\n u1inv = one\n ff(0) = zero\n ff(1) = -u1inv\n do i=2,n+1\n ff(i) = (i-1)*ff(i-1)\n end do\n!\n do i=n+1,1,-1\n gg(i-1) = -ff(i)/i\n end do\n else\n nadd = int(log(epsm)/log(au))+5\n if (n+nadd > lenl2) then\n write (*,*) 'Error!!! Insufficient array length in DPLOG!'\n stop\n end if\n!\n u1inv = one/(one+u)\n ff(0) = log(one+u)\n ff(1) = -u1inv\n do i=2,n+nadd\n ff(i) = (i-1)*ff(i-1)*u1inv\n end do\n!\n gg(n+nadd) = one\n do i=n+nadd,1,-1\n gg(i-1) = (u*gg(i)-ff(i))/i\n end do\n end if\n!\n return\n end\n\n", "meta": {"hexsha": "b33be3c35a93b48e9341723df24eb598ccc93a6b", "size": 1683, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "General Code/Short-Range/Quadruple Precision/Pachucki/ydplog.f90", "max_stars_repo_name": "DentonW/Ps-H-Scattering", "max_stars_repo_head_hexsha": "943846d1deadbe99a98d2c2e26bcebf55986d8e7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-08-02T03:50:06.000Z", "max_stars_repo_stars_event_max_datetime": "2017-08-02T03:50:06.000Z", "max_issues_repo_path": "P-Wave/Short/Pachucki/ydplog.f90", "max_issues_repo_name": "DentonW/Ps-H-Scattering", "max_issues_repo_head_hexsha": "943846d1deadbe99a98d2c2e26bcebf55986d8e7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "P-Wave/Short/Pachucki/ydplog.f90", "max_forks_repo_name": "DentonW/Ps-H-Scattering", "max_forks_repo_head_hexsha": "943846d1deadbe99a98d2c2e26bcebf55986d8e7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-09-28T22:09:05.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-28T22:09:05.000Z", "avg_line_length": 26.7142857143, "max_line_length": 71, "alphanum_fraction": 0.3642305407, "num_tokens": 545, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336202, "lm_q2_score": 0.7371581684030621, "lm_q1q2_score": 0.660679020647909}} {"text": "chapter xvi, example 3. two parametrizations of some data\nc from * a practical guide to splines * by c. de boor \ncalls splint(bsplvb,banfac/slv),bsplpp(bsplvb*),banslv*,ppvalu(interv)\nc parameter k=4,kpkm1=7, n=8,npk=12, npiece=6,npoint=21\nc integer i,icount,iflag,kp1,l\nc real bcoef(n),break(npiece),ds,q(n,kpkm1),s(n),scrtch(k,k)\nc * ,ss,t(npk),x(n),xcoef(k,npiece),xx(npoint),y(n)\nc * ,ycoef(k,npiece),yy(npoint)\n integer i,icount,iflag,k,kpkm1,kp1,l,n,npoint\n data k,kpkm1,n,npoint /4,7,8,21/ \n real bcoef(8),break(6),ds,q(8,7),s(8),scrtch(4,4)\n * ,ss,t(12),x(8),xcoef(4,6),xx(21),y(8)\n * ,ycoef(4,6),yy(21)\n data x /0.,.1,.2,.3,.301,.4,.5,.6/\nc *** compute y-component and set 'natural' parametrization\n do 1 i=1,n\n y(i) = (x(i)-.3)**2\n 1 s(i) = x(i)\n print 601\n 601 format(26h 'natural' parametrization/6x,1hx,11x,1hy)\n icount = 1\nc *** convert data abscissae to knots. note that second and second\nc last data abscissae are not knots.\n 5 do 6 i=1,k\n t(i) = s(1)\n 6 t(n+i) = s(n)\n kp1 = k+1\n do 7 i=kp1,n\n 7 t(i) = s(i+2-k)\nc *** interpolate to x-component\n call splint(s,x,t,n,k,q,bcoef,iflag)\n call bsplpp(t,bcoef,n,k,scrtch,break,xcoef,l)\nc *** interpolate to y-component. since data abscissae and knots are\nc the same for both components, we only need to use backsubstitution\n do 10 i=1,n\n 10 bcoef(i) = y(i)\n call banslv(q,kpkm1,n,k-1,k-1,bcoef)\n call bsplpp(t,bcoef,n,k,scrtch,break,ycoef,l)\nc *** evaluate curve at some points near the potential trouble spot,\nc the fourth and fifth data points.\n ss = s(3)\n ds = (s(6)-s(3))/float(npoint-1)\n do 20 i=1,npoint\n xx(i) = ppvalu(break,xcoef,l,k,ss,0)\n yy(i) = ppvalu(break,ycoef,l,k,ss,0)\n 20 ss = ss + ds\n print 620,(xx(i),yy(i),i=1,npoint)\n 620 format(2f12.7)\n if (icount .ge. 2) stop\nc *** now repeat the whole process with uniform parametrization\n icount = icount + 1\n do 30 i=1,n\n 30 s(i) = float(i)\n print 630\n 630 format(/26h 'uniform' parametrization/6x,1hx,11x,1hy)\n go to 5\n end\n", "meta": {"hexsha": "103df9677ada01ec3f95d42b6e9b5618d6b2741a", "size": 2253, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "bsplines/porlasdudas/xviex3.f", "max_stars_repo_name": "hakyimlab/semiparametric-spectral-density", "max_stars_repo_head_hexsha": "88ed7054eb16540952c34df6910aed1bf5597970", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "bsplines/porlasdudas/xviex3.f", "max_issues_repo_name": "hakyimlab/semiparametric-spectral-density", "max_issues_repo_head_hexsha": "88ed7054eb16540952c34df6910aed1bf5597970", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "bsplines/porlasdudas/xviex3.f", "max_forks_repo_name": "hakyimlab/semiparametric-spectral-density", "max_forks_repo_head_hexsha": "88ed7054eb16540952c34df6910aed1bf5597970", "max_forks_repo_licenses": ["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.8448275862, "max_line_length": 72, "alphanum_fraction": 0.581003107, "num_tokens": 866, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336204, "lm_q2_score": 0.7371581626286833, "lm_q1q2_score": 0.660679015472614}} {"text": " Program zhgeqz_example\n\n! ZHGEQZ Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_example_aux, Only: nagf_sort_realvec_rank, &\n nagf_file_print_matrix_complex_gen_comp, &\n nagf_sort_cmplxvec_rank_rearrange\n Use lapack_interfaces, Only: zgeqrf, zggbal, zgghd3, zhgeqz, zunmqr\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nin = 5, nout = 6\n! .. Local Scalars ..\n Integer :: i, ifail, ihi, ilo, info, irows, jwork, lda, ldb, ldq, ldz, &\n lwork, n, ni\n Character (1) :: compq, compz, job\n! .. Local Arrays ..\n Complex (Kind=dp), Allocatable :: a(:, :), alpha(:), b(:, :), beta(:), &\n e(:), q(:, :), tau(:), work(:), z(:, :)\n Real (Kind=dp), Allocatable :: emod(:), lscale(:), rscale(:), rwork(:)\n Integer, Allocatable :: irank(:)\n Character (1) :: clabs(1), rlabs(1)\n! .. Intrinsic Procedures ..\n Intrinsic :: abs, aimag, nint, real\n! .. Executable Statements ..\n Write (nout, *) 'ZHGEQZ Example Program Results'\n Flush (nout)\n\n! Skip heading in data file\n\n Read (nin, *)\n Read (nin, *) n\n ldq = 1\n ldz = 1\n lda = n\n ldb = n\n lwork = 6*n\n Allocate (a(lda,n), alpha(n), b(ldb,n), beta(n), q(ldq,ldq), tau(n), &\n work(lwork), z(ldz,ldz), lscale(n), rscale(n), rwork(6*n))\n\n! READ matrix A from data file\n Read (nin, *)(a(i,1:n), i=1, n)\n\n! READ matrix B from data file\n Read (nin, *)(b(i,1:n), i=1, n)\n\n! Balance matrix pair (A,B)\n job = 'B'\n Call zggbal(job, n, a, lda, b, ldb, ilo, ihi, lscale, rscale, rwork, &\n info)\n\n! Matrix A after balancing\n\n! ifail: behaviour on error exit\n! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft\n ifail = 0\n Call nagf_file_print_matrix_complex_gen_comp('General', ' ', n, n, a, &\n lda, 'Bracketed', 'F7.4', 'Matrix A after balancing', 'Integer', &\n rlabs, 'Integer', clabs, 80, 0, ifail)\n\n Write (nout, *)\n Flush (nout)\n\n! Matrix B after balancing\n\n ifail = 0\n Call nagf_file_print_matrix_complex_gen_comp('General', ' ', n, n, b, &\n ldb, 'Bracketed', 'F7.4', 'Matrix B after balancing', 'Integer', &\n rlabs, 'Integer', clabs, 80, 0, ifail)\n\n Write (nout, *)\n Flush (nout)\n\n! Reduce B to triangular form using QR\n irows = ihi + 1 - ilo\n\n Call zgeqrf(irows, irows, b(ilo,ilo), ldb, tau, work, lwork, info)\n\n! Apply the orthogonal transformation to A\n Call zunmqr('L', 'C', irows, irows, irows, b(ilo,ilo), ldb, tau, &\n a(ilo,ilo), lda, work, lwork, info)\n\n! Compute the generalized Hessenberg form of (A,B) -> (H,T)\n compq = 'N'\n compz = 'N'\n\n Call zgghd3(compq, compz, irows, 1, irows, a(ilo,ilo), lda, b(ilo,ilo), &\n ldb, q, ldq, z, ldz, work, lwork, info)\n\n! Matrix A (H) in generalized Hessenberg form\n ifail = 0\n Call nagf_file_print_matrix_complex_gen_comp('General', ' ', n, n, a, &\n lda, 'Bracketed', 'F7.3', 'Matrix A in Hessenberg form', 'Integer', &\n rlabs, 'Integer', clabs, 80, 0, ifail)\n\n Write (nout, *)\n Flush (nout)\n\n! Matrix B (T) in generalized Hessenberg form\n ifail = 0\n Call nagf_file_print_matrix_complex_gen_comp('General', ' ', n, n, b, &\n ldb, 'Bracketed', 'F7.3', 'Matrix B is triangular', 'Integer', rlabs, &\n 'Integer', clabs, 80, 0, ifail)\n\n! Routine ZHGEQZ\n! Workspace query: jwork = -1\n\n jwork = -1\n job = 'E'\n Call zhgeqz(job, compq, compz, n, ilo, ihi, a, lda, b, ldb, alpha, beta, &\n q, ldq, z, ldz, work, jwork, rwork, info)\n Write (nout, *)\n Write (nout, 100) nint(real(work(1)))\n Write (nout, 110) lwork\n Write (nout, *)\n Write (nout, 120)\n Write (nout, *)\n Flush (nout)\n\n! Compute the generalized Schur form\n! if the workspace lwork is adequate\n\n If (nint(real(work(1)))<=lwork) Then\n\n Call zhgeqz(job, compq, compz, n, ilo, ihi, a, lda, b, ldb, alpha, &\n beta, q, ldq, z, ldz, work, lwork, rwork, info)\n\n! Print the generalized eigenvalues in descending size order\n! Note: the actual values of beta are real and non-negative\n\n! Calculate the moduli of the finite eigenvalues.\n Allocate (e(n), emod(n), irank(n))\n ni = 0\n Do i = 1, n\n If (real(beta(i))/=0.0_dp) Then\n ni = ni + 1\n e(ni) = alpha(i)/beta(i)\n emod(ni) = abs(e(ni))\n Else\n Write (nout, 130) i\n End If\n End Do\n\n! Rearrange the finite eigenvalues in descending order of modulus.\n ifail = 0\n Call nagf_sort_realvec_rank(emod, 1, ni, 'Descending', irank, ifail)\n ifail = 0\n Call nagf_sort_cmplxvec_rank_rearrange(e, 1, ni, irank, ifail)\n\n Write (nout, 140)(i, '(', real(e(i)), ',', aimag(e(i)), ')', i=1, ni)\n Else\n Write (nout, 150)\n End If\n\n100 Format (1X, 'Minimal required LWORK = ', I6)\n110 Format (1X, 'Actual value of LWORK = ', I6)\n120 Format (1X, 'Generalized eigenvalues')\n130 Format (1X, I4, 5X, 'Infinite eigenvalue')\n140 Format (1X, I4, 5X, A, F7.3, A, F7.3, A)\n150 Format (1X, 'Insufficient workspace allocated for call to ZHGEQZ')\n End Program\n", "meta": {"hexsha": "0b19c809ad4b82e7edde910f19464145666ea093", "size": 5580, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/zhgeqz_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/zhgeqz_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/zhgeqz_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 33.2142857143, "max_line_length": 90, "alphanum_fraction": 0.5682795699, "num_tokens": 1842, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336202, "lm_q2_score": 0.7371581626286833, "lm_q1q2_score": 0.660679015472614}} {"text": " SUBROUTINE AB08NY( FIRST, N, M, P, SVLMAX, ABCD, LDABCD, NINFZ,\n $ NR, PR, DINFZ, NKRONL, INFZ, KRONL, TOL, IWORK,\n $ DWORK, LDWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To extract from the (N+P)-by-(M+N) system pencil\nC ( B A-lambda*I )\nC ( D C )\nC an (NR+PR)-by-(M+NR) \"reduced\" system pencil,\nC ( Br Ar-lambda*I ),\nC ( Dr Cr )\nC having the same transmission zeros, but with Dr of full row rank.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC FIRST LOGICAL\nC Specifies if AB08NY is called first time, or it is called\nC for an already reduced system, with D of full column rank,\nC with the last M rows in upper triangular form:\nC FIRST = .TRUE. : first time called;\nC FIRST = .FALSE. : not first time called.\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The number of rows of the matrix B, the number of columns\nC of the matrix C, and the order of the square matrix A.\nC N >= 0.\nC\nC M (input) INTEGER\nC The number of columns of the matrices B and D. M >= 0.\nC M <= P, if FIRST = .FALSE.\nC\nC P (input) INTEGER\nC The number of rows of the matrices C and D. P >= 0.\nC\nC SVLMAX (input) DOUBLE PRECISION\nC An estimate of the largest singular value of the original\nC matrix ABCD (for instance, the Frobenius norm of ABCD).\nC SVLMAX >= 0.\nC\nC ABCD (input/output) DOUBLE PRECISION array, dimension\nC (LDABCD,M+N)\nC On entry, the leading (N+P)-by-(M+N) part of this array\nC must contain the compound matrix\nC ( B A ),\nC ( D C )\nC where A is an N-by-N matrix, B is an N-by-M matrix,\nC C is a P-by-N matrix, and D is a P-by-M matrix.\nC If FIRST = .FALSE., then D must be a full column rank\nC matrix, with the last M rows in an upper triangular form.\nC On exit, the leading (NR+PR)-by-(M+NR) part of this array\nC contains the reduced compound matrix\nC ( Br Ar ),\nC ( Dr Cr )\nC where Ar is an NR-by-NR matrix, Br is an NR-by-M matrix,\nC Cr is a PR-by-NR matrix, and Dr is a PR-by-M full row rank\nC left upper-trapezoidal matrix, with the first PR columns\nC in an upper triangular form.\nC\nC LDABCD INTEGER\nC The leading dimension of the array ABCD.\nC LDABCD >= MAX(1,N+P).\nC\nC NINFZ (input/output) INTEGER\nC On entry, the currently computed number of infinite zeros.\nC It should be initialized to zero on the first call.\nC NINFZ >= 0.\nC If FIRST = .FALSE., then NINFZ is not modified.\nC On exit, the number of infinite zeros.\nC\nC NR (output) INTEGER\nC The order of the reduced matrix Ar; also, the number of\nC rows of the reduced matrix Br and the number of columns of\nC the reduced matrix Cr.\nC If Dr is invertible, NR is also the number of finite Smith\nC zeros.\nC\nC PR (output) INTEGER\nC The normal rank of the transfer-function matrix of the\nC original system; also, the number of rows of the reduced\nC matrices Cr and Dr.\nC\nC DINFZ (output) INTEGER\nC The maximal multiplicity of infinite zeros.\nC DINFZ = 0 if FIRST = .FALSE. .\nC\nC NKRONL (output) INTEGER\nC The maximal dimension of left elementary Kronecker blocks.\nC\nC INFZ (output) INTEGER array, dimension (N)\nC INFZ(i) contains the number of infinite zeros of degree i,\nC where i = 1,2,...,DINFZ.\nC INFZ is not referenced if FIRST = .FALSE. .\nC\nC KRONL (output) INTEGER array, dimension (N+1)\nC KRONL(i) contains the number of left elementary Kronecker\nC blocks of dimension i-by-(i-1), where i = 1,2,...,NKRONL.\nC\nC Tolerances\nC\nC TOL DOUBLE PRECISION\nC A tolerance used in rank decisions to determine the\nC effective rank, which is defined as the order of the\nC largest leading (or trailing) triangular submatrix in the\nC QR (or RQ) factorization with column (or row) pivoting\nC whose estimated condition number is less than 1/TOL.\nC NOTE that when SVLMAX > 0, the estimated ranks could be\nC less than those defined above (see SVLMAX).\nC If the user sets TOL to be less than or equal to zero,\nC then the tolerance is taken as (N+P)*(N+M)*EPS, where EPS\nC is the machine precision (see LAPACK Library Routine\nC DLAMCH). TOL < 1.\nC\nC Workspace\nC\nC IWORK INTEGER array, dimension (MAX(M,P))\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0, DWORK(1) returns the optimal value\nC of LDWORK.\nC\nC LDWORK INTEGER\nC The length of the array DWORK.\nC LDWORK >= 1, if MIN(P, MAX(N,M)) = 0; otherwise,\nC LDWORK >= MAX( MIN(P,M) + M + MAX(2*M,N) - 1,\nC MIN(P,N) + MAX(N + MAX( P, M), 3*P - 1 ) ).\nC For optimum performance LDWORK should be larger.\nC\nC If LDWORK = -1, then a workspace query is assumed;\nC the routine only calculates the optimal size of the\nC DWORK array, returns this value as the first entry of\nC the DWORK array, and no error message related to LDWORK\nC is issued by XERBLA.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value.\nC\nC REFERENCES\nC\nC [1] Svaricek, F.\nC Computation of the Structural Invariants of Linear\nC Multivariable Systems with an Extended Version of the\nC Program ZEROS.\nC System & Control Letters, 6, pp. 261-266, 1985.\nC\nC [2] Emami-Naeini, A. and Van Dooren, P.\nC Computation of Zeros of Linear Multivariable Systems.\nC Automatica, 18, pp. 415-430, 1982.\nC\nC NUMERICAL ASPECTS\nC\nC The algorithm is numerically backward stable and requires\nC 0( (P+N)*(M+N)*N ) floating point operations.\nC\nC FURTHER COMMENTS\nC\nC The number of infinite zeros is computed (if FIRST = .TRUE.) as\nC\nC DINFZ\nC NINFZ = Sum (INFZ(i)*i .\nC i=1\nC\nC Note that each infinite zero of multiplicity k corresponds to an\nC infinite eigenvalue of multiplicity k+1.\nC The multiplicities of the infinite eigenvalues can be determined\nC from PR, DINFZ and INFZ(i), i = 1, ..., DINFZ, as follows:\nC\nC DINFZ\nC - there are PR - Sum (INFZ(i)) simple infinite eigenvalues;\nC i=1\nC\nC - there are INFZ(i) infinite eigenvalues with multiplicity i+1,\nC for i = 1, ..., DINFZ.\nC\nC The left Kronecker indices are:\nC\nC [ 0 0 ... 0 | 1 1 ... 1 | .... | NKRONL ... NKRONL ]\nC |<- KRONL(1) ->|<- KRONL(2) ->| |<- KRONL(NKRONL) ->|\nC\nC CONTRIBUTOR\nC\nC V. Sima, Katholieke Univ. Leuven, Belgium.\nC A. Varga, DLR Oberpfaffenhofen, Germany, May 1999.\nC Supersedes Release 3.0 routine AB08BX.\nC\nC REVISIONS\nC\nC A. Varga, DLR Oberpfaffenhofen, Germany, March 2002.\nC V. Sima, Dec. 2016, Jan. 2017, Feb. 2018.\nC\nC KEYWORDS\nC\nC Generalized eigenvalue problem, Kronecker indices, multivariable\nC system, orthogonal transformation, structural invariant.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, ONE\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )\nC .. Scalar Arguments ..\n LOGICAL FIRST\n INTEGER DINFZ, INFO, LDABCD, LDWORK, M, N, NINFZ,\n $ NKRONL, NR, P, PR\n DOUBLE PRECISION SVLMAX, TOL\nC .. Array Arguments ..\n INTEGER INFZ(*), IWORK(*), KRONL(*)\n DOUBLE PRECISION ABCD(LDABCD,*), DWORK(*)\nC .. Local Scalars ..\n LOGICAL LQUERY\n INTEGER I, I1, ICOL, IRC, IROW, ITAU, JWORK, K, MN, MNR,\n $ MNTAU, MP1, MPM, MPN, MUI, MUIM1, NBLCKS, PN,\n $ RANK, RO, RO1, SIGMA, TAUI, WRKOPT\n DOUBLE PRECISION RCOND\nC .. Local Arrays ..\n DOUBLE PRECISION SVAL(3)\nC .. External Functions ..\n DOUBLE PRECISION DLAMCH\n EXTERNAL DLAMCH\nC .. External Subroutines ..\n EXTERNAL DLAPMT, DLASET, DORMQR, DORMRQ, MB03OY, MB03PY,\n $ MB04ID, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC DBLE, INT, MAX, MIN\nC .. Executable Statements ..\nC\n INFO = 0\n PN = P + N\n MN = M + N\n MPN = MIN( P, N )\n MPM = MIN( P, M )\nC\nC Test the input scalar arguments.\nC\n IF( N.LT.0 ) THEN\n INFO = -2\n ELSE IF( M.LT.0 .OR. (.NOT.FIRST .AND. M.GT.P ) ) THEN\n INFO = -3\n ELSE IF( P.LT.0 ) THEN\n INFO = -4\n ELSE IF( SVLMAX.LT.ZERO ) THEN\n INFO = -5\n ELSE IF( LDABCD.LT.MAX( 1, PN ) ) THEN\n INFO = -7\n ELSE IF( NINFZ.LT.0 .OR. ( FIRST .AND. NINFZ.GT.0 ) ) THEN\n INFO = -8\n ELSE IF( TOL.GE.ONE ) THEN\n INFO = -15\n ELSE\n LQUERY = ( LDWORK.EQ.-1 )\n IF( MIN( P, MAX( N, M ) ).EQ.0 ) THEN\n JWORK = 1\n ELSE\n JWORK = MAX( MPM + M + MAX( 2*M, N ) - 1,\n $ MPN + MAX( N + MAX( P, M) , 3*P - 1 ) )\n END IF\n IF( LQUERY ) THEN\n IF( M.GT.0 ) THEN\n CALL MB04ID( P, MPM, M-1, N, ABCD, LDABCD, ABCD, LDABCD,\n $ DWORK, DWORK, -1, INFO )\n WRKOPT = MAX( JWORK, MPM + INT( DWORK(1) ) )\n CALL DORMQR( 'Left', 'Transpose', P, N, MPM, ABCD,\n $ LDABCD, DWORK, ABCD, LDABCD, DWORK, -1,\n $ INFO )\n WRKOPT = MAX( WRKOPT, MPM + INT( DWORK(1) ) )\n ELSE\n WRKOPT = JWORK\n END IF\n CALL DORMRQ( 'Right', 'Transpose', PN, N, MPN, ABCD, LDABCD,\n $ DWORK, ABCD, LDABCD, DWORK, -1, INFO )\n WRKOPT = MAX( WRKOPT, MPN + INT( DWORK(1) ) )\n CALL DORMRQ( 'Left', 'NoTranspose', N, MN, MPN, ABCD,\n $ LDABCD, DWORK, ABCD, LDABCD, DWORK, -1, INFO )\n WRKOPT = MAX( WRKOPT, MPN + INT( DWORK(1) ) )\n ELSE IF( LDWORK.LT.JWORK ) THEN\n INFO = -18\n END IF\n END IF\nC\n IF ( INFO.NE.0 ) THEN\nC\nC Error return.\nC\n CALL XERBLA( 'AB08NY', -INFO )\n RETURN\n ELSE IF( LQUERY ) THEN\n DWORK(1) = WRKOPT\n RETURN\n END IF\nC\nC Initialize output variables.\nC\n PR = P\n NR = N\nC\n DINFZ = 0\n NKRONL = 0\nC\nC Quick return if possible.\nC\n IF( P.EQ.0 ) THEN\n DWORK(1) = ONE\n RETURN\n END IF\nC\n IF( MAX( N, M ).EQ.0 ) THEN\n PR = 0\n NKRONL = 1\n KRONL(1) = P\n DWORK(1) = ONE\n RETURN\n END IF\nC\n WRKOPT = 1\n RCOND = TOL\n IF( RCOND.LE.ZERO ) THEN\nC\nC Use the default tolerance in rank determination.\nC\n RCOND = DBLE( PN*MN )*DLAMCH( 'EPSILON' )\n END IF\nC\nC The D matrix is (RO+SIGMA)-by-M, where RO = P - SIGMA and\nC SIGMA = 0, for FIRST = .TRUE., and SIGMA = M, for FIRST = .FALSE..\nC The leading (RO+SIGMA)-by-SIGMA submatrix of D has full column\nC rank, with the trailing SIGMA-by-SIGMA submatrix upper triangular.\nC\n IF( FIRST ) THEN\n SIGMA = 0\n ELSE\n SIGMA = M\n END IF\n RO = P - SIGMA\n MP1 = M + 1\n MUI = 0\nC\n NBLCKS = 0\n ITAU = 1\nC\n 10 CONTINUE\nC\nC Main reduction loop:\nC\nC M NR M NR\nC NR [ B A ] NR [ B A ]\nC PR [ D C ] --> SIGMA [ RD C1 ] (SIGMA = rank(D) =\nC TAU [ 0 C2 ] row size of RD)\nC\nC M NR-MUI MUI\nC NR-MUI [ B1 A11 A12 ]\nC --> MUI [ B2 A21 A22 ] (MUI = rank(C2) =\nC SIGMA [ RD C11 C12 ] col size of LC)\nC TAU [ 0 0 LC ]\nC\nC M NR-MUI\nC NR-MUI [ B1 A11 ] NR := NR - MUI\nC [----------] PR := MUI + SIGMA\nC --> MUI [ B2 A21 ] D := [B2;RD]\nC SIGMA [ RD C11 ] C := [A21;C11]\nC\n IF ( PR.EQ.0 )\n $ GO TO 20\nC\nC (Note: Comments in the code beginning \"Workspace:\" describe the\nC minimal amount of real workspace needed at that point in the\nC code, as well as the preferred amount for good performance.)\nC\n RO1 = RO\n MNR = M + NR\nC\n IF ( M.GT.0 ) THEN\nC\nC Compress columns of D; first, exploit the trapezoidal shape of\nC the (RO+SIGMA)-by-SIGMA matrix in the first SIGMA columns of D;\nC compress the first SIGMA columns without column pivoting:\nC\nC ( x x x x x ) ( x x x x x )\nC ( x x x x x ) ( 0 x x x x )\nC ( x x x x x ) - > ( 0 0 x x x )\nC ( 0 x x x x ) ( 0 0 0 x x )\nC ( 0 0 x x x ) ( 0 0 0 x x )\nC\nC where SIGMA = 3 and RO = 2.\nC\n IROW = NR + 1\n IF ( SIGMA.GT.0 ) THEN\n JWORK = ITAU + SIGMA\nC\nC Compress rows of D. First, exploit the triangular shape.\nC Workspace: need min(P,M) + M+N-1;\nC prefer larger.\nC\n CALL MB04ID( RO+SIGMA, SIGMA, SIGMA-1, MNR-SIGMA,\n $ ABCD(IROW,1), LDABCD, ABCD(IROW,SIGMA+1),\n $ LDABCD, DWORK(ITAU), DWORK(JWORK),\n $ LDWORK-JWORK+1, INFO )\n CALL DLASET( 'Lower', RO+SIGMA-1, SIGMA, ZERO, ZERO,\n $ ABCD(IROW+1,1), LDABCD )\n WRKOPT = MAX( WRKOPT, INT( DWORK(JWORK) ) + JWORK - 1 )\n END IF\nC\n IF( FIRST ) THEN\nC\nC Continue with Householder with column pivoting.\nC\nC ( x x x x x ) ( x x x x x )\nC ( 0 x x x x ) ( 0 x x x x )\nC ( 0 0 x x x ) -> ( 0 0 x x x )\nC ( 0 0 0 x x ) ( 0 0 0 x x )\nC ( 0 0 0 x x ) ( 0 0 0 0 0 )\nC\nC Workspace: need min(P,M) + 3*M-1.\nC Int.work. need M.\nC\n JWORK = ITAU + MIN( RO1, M-SIGMA )\nC\n IROW = MIN( NR+SIGMA+1, PN )\n ICOL = MIN( SIGMA+1,M )\n CALL MB03OY( RO1, M-SIGMA, ABCD(IROW,ICOL), LDABCD, RCOND,\n $ SVLMAX, RANK, SVAL, IWORK, DWORK(ITAU),\n $ DWORK(JWORK), INFO )\n WRKOPT = MAX( WRKOPT, JWORK + 3*( M-SIGMA ) - 1 )\nC\nC Apply the column permutations to B and part of D.\nC\n CALL DLAPMT( .TRUE., NR+SIGMA, M-SIGMA, ABCD(1,ICOL),\n $ LDABCD, IWORK )\nC\n IF ( RANK.GT.0 ) THEN\nC\nC Apply the Householder transformations to the submatrix C.\nC Workspace: need min(P,M) + N.\nC prefer min(P,M) + N*NB.\nC\n CALL DORMQR( 'Left', 'Transpose', RO1, NR, RANK,\n $ ABCD(IROW,ICOL), LDABCD, DWORK(ITAU),\n $ ABCD(IROW,MP1), LDABCD, DWORK(JWORK),\n $ LDWORK-JWORK+1, INFO )\n WRKOPT = MAX( WRKOPT, INT( DWORK(JWORK) ) + JWORK - 1 ) \n CALL DLASET( 'Lower', RO1-1, MIN( RO1-1, RANK ), ZERO,\n $ ZERO, ABCD(MIN( PN, IROW+1 ),ICOL), LDABCD )\n RO1 = RO1 - RANK\n END IF\n END IF\nC\nC Terminate if Dr has maximal row rank.\nC\n IF( RO1.EQ.0 )\n $ GO TO 30\nC\n END IF\nC\nC Update SIGMA.\nC\n SIGMA = PR - RO1\nC\n NBLCKS = NBLCKS + 1\n TAUI = RO1\nC\n IF ( NR.LE.0 ) THEN\n PR = SIGMA\n RANK = 0\n ELSE\nC\nC Compress the columns of C using RQ factorization with row\nC pivoting, P * C = R * Q.\nC The current C is the TAUI-by-NR matrix delimited by rows\nC IRC+1 to IRC+TAUI and columns M+1 to M+NR of ABCD.\nC The rank of the current C is computed in MUI.\nC Workspace: need min(P,N) + 3*P-1.\nC Int.work. need P.\nC\n IRC = NR + SIGMA\n I1 = IRC + 1\n MNTAU = MIN( TAUI, NR )\n JWORK = ITAU + MNTAU\nC\n CALL MB03PY( TAUI, NR, ABCD(I1,MP1), LDABCD, RCOND, SVLMAX,\n $ RANK, SVAL, IWORK, DWORK(ITAU), DWORK(JWORK),\n $ INFO )\n WRKOPT = MAX( WRKOPT, JWORK + 3*TAUI - 1 )\nC\n IF ( RANK.GT.0 ) THEN\n IROW = I1 + TAUI - RANK\nC\nC Apply Q' to the first NR columns of [A; C1] from the right.\nC Workspace: need min(P,N) + N + SIGMA; SIGMA <= P;\nC prefer min(P,N) + (N + SIGMA)*NB.\nC\n CALL DORMRQ( 'Right', 'Transpose', IRC, NR, RANK,\n $ ABCD(IROW,MP1), LDABCD, DWORK(MNTAU-RANK+1),\n $ ABCD(1,MP1), LDABCD, DWORK(JWORK),\n $ LDWORK-JWORK+1, INFO )\n WRKOPT = MAX( WRKOPT, INT( DWORK(JWORK) ) + JWORK - 1 )\nC\nC Apply Q to the first NR rows and M + NR columns of [ B A ]\nC from the left.\nC Workspace: need min(P,N) + M + N;\nC prefer min(P,N) + (M + N)*NB.\nC\n CALL DORMRQ( 'Left', 'NoTranspose', NR, MNR, RANK,\n $ ABCD(IROW,MP1), LDABCD, DWORK(MNTAU-RANK+1),\n $ ABCD, LDABCD, DWORK(JWORK), LDWORK-JWORK+1,\n $ INFO )\n WRKOPT = MAX( WRKOPT, INT( DWORK(JWORK) ) + JWORK - 1 )\nC\n CALL DLASET( 'Full', RANK, NR-RANK, ZERO, ZERO,\n $ ABCD(IROW,MP1), LDABCD )\n IF ( RANK.GT.1 )\n $ CALL DLASET( 'Lower', RANK-1, RANK-1, ZERO, ZERO,\n $ ABCD(IROW+1,MP1+NR-RANK), LDABCD )\n END IF\n END IF\nC\n 20 CONTINUE\n MUI = RANK\n NR = NR - MUI\n PR = SIGMA + MUI\nC\nC Set number of left Kronecker blocks of order (i-1)-by-i.\nC\n KRONL(NBLCKS) = TAUI - MUI\nC\nC Set number of infinite divisors of order i-1.\nC\n IF( FIRST .AND. NBLCKS.GT.1 )\n $ INFZ(NBLCKS-1) = MUIM1 - TAUI\n MUIM1 = MUI\n RO = MUI\nC\nC Continue reduction if rank of current C is positive.\nC\n IF( MUI.GT.0 )\n $ GO TO 10\nC\nC Determine the maximal degree of infinite zeros and the number of\nC infinite zeros.\nC\n 30 CONTINUE\n IF( FIRST ) THEN\n IF( MUI.EQ.0 ) THEN\n DINFZ = MAX( 0, NBLCKS - 1 )\n ELSE\n DINFZ = NBLCKS\n INFZ(NBLCKS) = MUI\n END IF\n K = DINFZ\nC\n DO 40 I = K, 1, -1\n IF( INFZ(I).NE.0 )\n $ GO TO 50\n DINFZ = DINFZ - 1\n 40 CONTINUE\nC\n 50 CONTINUE\nC\n DO 60 I = 1, DINFZ\n NINFZ = NINFZ + INFZ(I)*I\n 60 CONTINUE\nC\n END IF\nC\nC Determine the maximal order of left elementary Kronecker blocks.\nC\n NKRONL = NBLCKS\nC\n DO 70 I = NBLCKS, 1, -1\n IF( KRONL(I).NE.0 )\n $ GO TO 80\n NKRONL = NKRONL - 1\n 70 CONTINUE\nC\n 80 CONTINUE\nC\n DWORK(1) = WRKOPT\n RETURN\nC *** Last line of AB08NY ***\n END\n", "meta": {"hexsha": "a4a923ede1d9097056dc389181e84281f7924ed3", "size": 20042, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/AB08NY.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/AB08NY.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/AB08NY.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 33.9120135364, "max_line_length": 72, "alphanum_fraction": 0.4991517813, "num_tokens": 6350, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8962513620489618, "lm_q2_score": 0.7371581568543044, "lm_q1q2_score": 0.6606790021261726}} {"text": "PROGRAM Cubes\n! IMPLICIT NONE\n\n INTEGER, PARAMETER :: Iterations = 10\n INTEGER :: i\n REAL :: x\n\n DO i = 1, Iterations\n x = i\n WRITE(*,*) i, x, rntCube(i)\n END DO\n\n! If contains is used then intCube(i) will not have an implicitly defined return type!\n! contains\nEND PROGRAM Cubes\n\nINTEGER FUNCTION intCube(Number)\n IMPLICIT NONE\n\n INTEGER, INTENT(IN) :: Number\n\n intCube = Number*Number*Number\nEND FUNCTION intCube\n\n", "meta": {"hexsha": "6d4516300204a4cc31ef5ade8f9f78cd0b460b71", "size": 477, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/CompileTests/Fortran_tests/test2008_32.f90", "max_stars_repo_name": "maurizioabba/rose", "max_stars_repo_head_hexsha": "7597292cf14da292bdb9a4ef573001b6c5b9b6c0", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/CompileTests/Fortran_tests/test2008_32.f90", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/CompileTests/Fortran_tests/test2008_32.f90", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 19.08, "max_line_length": 86, "alphanum_fraction": 0.6205450734, "num_tokens": 138, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8080671950640465, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.6606551155296478}} {"text": "module mod_initgrid\n use mod_param, only:pi\n use mod_types\n implicit none\n private\n public initgrid\n contains\n subroutine initgrid(inivel,n,gr,lz,dzc,dzf,zc,zf)\n !\n ! initializes the non-uniform grid in z\n !\n implicit none\n character(len=3), intent(in) :: inivel\n integer , intent(in) :: n\n real(rp), intent(in) :: gr,lz\n real(rp), intent(out), dimension(0:n+1) :: dzc,dzf,zc,zf\n real(rp) :: z0\n integer :: k\n procedure (), pointer :: gridpoint => null()\n select case(inivel)\n case('zer','log','poi','cou')\n gridpoint => gridpoint_cluster_two_end\n case('hcl','hcp')\n gridpoint => gridpoint_cluster_one_end\n case default\n gridpoint => gridpoint_cluster_two_end\n end select\n !\n ! step 1) determine coordinates of cell faces zf\n !\n do k=1,n\n z0 = (k-0.)/(1.*n)\n call gridpoint(gr,z0,zf(k))\n zf(k) = zf(k)*lz\n enddo\n zf(0) = 0.\n !\n ! step 2) determine grid spacing between faces dzf\n !\n do k=1,n\n dzf(k) = zf(k)-zf(k-1)\n enddo\n dzf(0 ) = dzf(1)\n dzf(n+1) = dzf(n)\n !\n ! step 3) determine grid spacing between centers dzc\n !\n do k=0,n\n dzc(k) = .5*(dzf(k)+dzf(k+1))\n enddo\n dzc(n+1) = dzc(n)\n !\n ! step 4) compute coordinates of cell centers zc and faces zf\n !\n zc(0) = -dzc(0)/2.\n zf(0) = 0.\n do k=1,n+1\n zc(k) = zc(k-1) + dzc(k-1)\n zf(k) = zf(k-1) + dzf(k)\n enddo\n return\n end subroutine initgrid\n !\n ! grid stretching functions \n ! see e.g., Fluid Flow Phenomena -- A Numerical Toolkit, by P. Orlandi\n ! Pirozzoli et al. JFM 788, 614\u2013639 (commented)\n !\n subroutine gridpoint_cluster_two_end(alpha,z0,z)\n !\n ! clustered at the two sides\n !\n implicit none\n real(rp), intent(in) :: alpha,z0\n real(rp), intent(out) :: z\n if(alpha.ne.0.) then\n z = 0.5*(1.+tanh((z0-0.5)*alpha)/tanh(alpha/2.))\n !z = 0.5*(1.+erf( (z0-0.5)*alpha)/erf( alpha/2.))\n else\n z = z0\n endif\n return\n end subroutine gridpoint_cluster_two_end\n subroutine gridpoint_cluster_one_end(alpha,z0,z)\n !\n ! clustered at the lower side\n !\n implicit none\n real(rp), intent(in) :: alpha,z0\n real(rp), intent(out) :: z\n if(alpha.ne.0.) then\n z = 1.0*(1.+tanh((z0-1.0)*alpha)/tanh(alpha/1.))\n !z = 1.0*(1.+erf( (z0-1.0)*alpha)/erf( alpha/1.))\n else\n z = z0\n endif\n return\n end subroutine gridpoint_cluster_one_end\n subroutine gridpoint_cluster_middle(alpha,z0,z)\n !\n ! clustered in the middle\n !\n implicit none\n real(rp), intent(in) :: alpha,z0\n real(rp), intent(out) :: z\n if(alpha.ne.0.) then\n if( z0.le.0.5) then \n z = 0.5*(1.-1.+tanh(2.*alpha*(z0-0.))/tanh(alpha))\n !z = 0.5*(1.-1.+erf( 2.*alpha*(z0-0.))/erf( alpha))\n elseif(z0.gt.0.5) then\n z = 0.5*(1.+1.+tanh(2.*alpha*(z0-1.))/tanh(alpha))\n !z = 0.5*(1.+1.+erf( 2.*alpha*(z0-1.))/erf( alpha))\n endif\n else\n z = z0\n endif\n return\n end subroutine gridpoint_cluster_middle\nend module mod_initgrid\n", "meta": {"hexsha": "e968752674e20aa1ee89194a4480abf7ca34e1dd", "size": 3091, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/initgrid.f90", "max_stars_repo_name": "zhoutengye/VSIAM-fft", "max_stars_repo_head_hexsha": "eb2b87c045e20592dc1eea2dfc56f2f4a889e059", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2019-11-20T15:15:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-26T08:02:23.000Z", "max_issues_repo_path": "src/initgrid.f90", "max_issues_repo_name": "kaolagithub/CaNS", "max_issues_repo_head_hexsha": "c61401b5192f47f70111623a3ef3039b1b35f894", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-05-08T10:28:13.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-16T17:41:05.000Z", "max_forks_repo_path": "src/initgrid.f90", "max_forks_repo_name": "kaolagithub/CaNS", "max_forks_repo_head_hexsha": "c61401b5192f47f70111623a3ef3039b1b35f894", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-08-30T02:49:58.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-29T09:13:13.000Z", "avg_line_length": 25.974789916, "max_line_length": 72, "alphanum_fraction": 0.5681009382, "num_tokens": 1103, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240860523328, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6605845461933421}} {"text": "! { dg-do run }\n\nmodule task_dep5_mod\ncontains\n subroutine matmul_depend (N, BS, A, B, C)\n implicit none\n integer :: N, BS, BM\n real, dimension(N, N) :: A, B, C\n integer :: i, j, k, ii, jj, kk\n BM = BS - 1\n do i = 1, N, BS\n do j = 1, N, BS\n do k = 1, N, BS\n !$omp task shared(A,B,C) private(ii,jj,kk) & ! I,J,K are firstprivate by default\n !$omp depend ( in: A(i:i+BM, k:k+BM), B(k:k+BM, j:j+BM) ) &\n !$omp depend ( inout: C(i:i+BM, j:j+BM) )\n do ii = i, i+BM\n do jj = j, j+BM\n do kk = k, k+BM\n C(jj,ii) = C(jj,ii) + A(kk,ii) * B(jj,kk)\n end do\n end do\n end do\n !$omp end task\n end do\n end do\n end do\n end subroutine\n\n subroutine matmul_ref (N, A, B, C)\n implicit none\n integer :: N\n real, dimension(N, N) :: A, B, C\n integer :: i, j, k\n do i = 1, N\n do j = 1, N\n do k = 1, N\n C(j,i) = C(j,i) + A(k,i) * B(j,k)\n end do\n end do\n end do\n end subroutine\n\n subroutine check (N, A, B)\n integer :: N\n integer :: i, j\n real, parameter :: EPS = 0.000001\n real, dimension(N,N) :: A, B\n real :: diff\n do i = 1, N\n do j = 1, N\n diff = A(i, j) - B(i, j)\n if (diff > EPS .or. -diff > EPS) then\n call abort ()\n end if\n end do\n end do\n end subroutine\n\n subroutine init (N, A, B)\n integer :: N\n integer :: i, j, s\n real, dimension(N,N) :: A, B\n s = -1\n do i = 1, N\n do j = 1, N\n A(i, j) = i*j*s\n B(i, j) = i+j\n s = -s\n end do\n end do\n end subroutine\n\n subroutine zero_init (N, A, B)\n integer :: N\n integer :: i, j\n real, dimension(N,N) :: A, B\n do i = 1, N\n do j = 1, N\n A(i, j) = 0\n B(i, j) = 0\n end do\n end do\n end subroutine\n\nend module\n\nprogram main\n use task_dep5_mod\n real, dimension(32, 32) :: A, B, C, C_ref\n\n call init (32, A, B)\n call zero_init (32, C, C_ref)\n\n call matmul_depend(32, 4, A, B, C)\n call matmul_ref(32, A, B, C_ref)\n\n call check (32, C, C_ref)\n\nend program\n", "meta": {"hexsha": "0746531728e301a4213e7ce33d4aaf00f6f4a06e", "size": 2180, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gcc-gcc-7_3_0-release/libgomp/testsuite/libgomp.fortran/examples-4/task_dep-5.f90", "max_stars_repo_name": "best08618/asylo", "max_stars_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-05-02T17:34:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-17T10:15:18.000Z", "max_issues_repo_path": "gcc-gcc-7_3_0-release/libgomp/testsuite/libgomp.fortran/examples-4/task_dep-5.f90", "max_issues_repo_name": "best08618/asylo", "max_issues_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "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": "gcc-gcc-7_3_0-release/libgomp/testsuite/libgomp.fortran/examples-4/task_dep-5.f90", "max_forks_repo_name": "best08618/asylo", "max_forks_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-27T00:22:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-01T09:41:02.000Z", "avg_line_length": 21.5841584158, "max_line_length": 82, "alphanum_fraction": 0.4610091743, "num_tokens": 795, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240686758841, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.6605845375829895}} {"text": "!*****************************************************************************************\n!> author: Jacob Williams\n!\n! Halo Orbit generation example (Earth-Moon system).\n!\n!@note Requires pyplot-fortran module.\n\n program halo_test\n\n use fortran_astrodynamics_toolkit\n use pyplot_module\n use halo_orbit_module\n\n implicit none\n\n real(wp),parameter :: mu_earth = 398600.436233_wp !! \\( \\mu_{Earth} ~ (\\mathrm{km}^3/\\mathrm{s}^2) \\)\n real(wp),parameter :: mu_moon = 4902.800076_wp !! \\( \\mu_{Moon} ~ (\\mathrm{km}^3/\\mathrm{s}^2) \\)\n real(wp),parameter :: em_distance = 384400.0_wp !! earth-moon distance [km]\n\n real(wp),parameter :: A_z = 1000.0_wp !! halo z-amplitude\n integer,parameter :: sol_family = 1 !! 1 or 3 (family)\n real(wp),parameter :: t1 = 0.0_wp !! tau for halo orbit\n\n integer,parameter :: n = 6 !! number of state variables\n real(wp),parameter :: t0 = 0.0_wp !! initial time (normalized)\n real(wp),parameter :: tmax = 1000.0_wp !! max final time (normalized)\n real(wp),parameter :: dt = 0.001_wp !! time step (normalized)\n\n real(wp),parameter :: tol = 1.0e-8_wp !! tolerance for event finding\n real(wp),parameter :: xtol = 1.0e-6_wp !! tolerance for [[hybrd]]\n integer,parameter :: maxfev = 1000 !! max number of function evaluations for [[hybrd]]\n\n !< initial state (normalized)\n real(wp),dimension(:),allocatable :: x_crtbp,y_crtbp,z_crtbp\n real(wp),dimension(:),allocatable :: x_vec\n real(wp),dimension(:),allocatable :: y_vec\n real(wp),dimension(:,:),allocatable :: c_mat\n real(wp),dimension(2) :: xy_L4,xy_L5\n real(wp),dimension(2) :: x_vy0,vx_vzf\n real(wp),dimension(n) :: x0\n real(wp) :: mu !! CRTPB parameter\n real(wp) :: c !! CRTPB Jacobi constant\n type(rk8_10_class) :: prop !! integrator\n real(wp),dimension(n) :: xf !! final state\n type(pyplot) :: plt !! for making the plot\n real(wp),dimension(6) :: x0_km,x1\n real(wp),dimension(6) :: x_zvc\n integer :: i,j,nx,ny\n real(wp) :: x,y,gf,tf_actual\n real(wp) :: x_L1,x_L2,x_L3\n integer :: info\n real(wp) :: Az\n integer :: libpoint !! libration point\n real(wp) :: period !! halo orbit period\n integer :: istat\n\n character(len=1),dimension(4),parameter :: colors = ['r','g','b','k'] !! line colors for plots\n\n !for zero-velocity countours:\n real(wp),parameter :: xmin = -2.0_wp\n real(wp),parameter :: xmax = 2.0_wp\n real(wp),parameter :: xstep = 0.01_wp\n real(wp),parameter :: ymin = -2.0_wp\n real(wp),parameter :: ymax = 2.0_wp\n real(wp),parameter :: ystep = 0.01_wp\n\n ! get the halo orbit initial guess using the analytic approximation:\n libpoint = 2 ! L2 point\n call halo_to_rv(libpoint,mu_earth,mu_moon,em_distance,A_z,sol_family,t1,x0)\n\n call unnormalize_variables(mu_earth,mu_moon,em_distance,x_crtbp=x0,x=x0_km)\n\n write(*,*) ''\n write(*,*) ' initial guess in km,km/s: '\n write(*,'(*(F30.16,1X))') x0_km\n write(*,*) ''\n\n !compute the CRTBP parameter & Jacobi constant:\n mu = compute_crtpb_parameter(mu_earth,mu_moon)\n c = compute_jacobi_constant(mu,x0)\n\n ! !*************************************************\n ! !compute the zero velocity surface for this c\n\n !Just get the number of elements by counting...\n i=0\n nx=0\n do\n i=i+1\n x = xmin + (i-1)*xstep\n if (x>xmax) exit\n nx = nx + 1\n end do\n j=0\n ny=0\n do\n j=j+1\n y = ymin + (j-1)*ystep\n if (y>ymax) exit\n ny = ny + 1\n end do\n\n !size the arrays:\n allocate(x_vec(nx))\n allocate(y_vec(ny))\n allocate(c_mat(nx,ny))\n\n !compute the jacobi constant for each combo:\n do i = 1, nx\n x = xmin + (i-1)*xstep\n x_vec(i) = x\n do j = 1, ny\n y = ymin + (j-1)*ystep\n if (i==1) y_vec(j) = y\n x_zvc(1:3) = [x,y,zero]\n x_zvc(4:6) = zero\n c_mat(i,j) = compute_jacobi_constant(mu,x_zvc)\n end do\n end do\n\n !*************************************************\n !compute the libration point locations:\n\n call compute_libration_points(mu,x_L1,x_L2,x_L3,xy_L4,xy_L5)\n\n write(*,*) ''\n write(*,*) 'mu: ', mu\n write(*,*) 'Jacobi constant: ', c\n write(*,*) 'x_L1:', x_L1\n write(*,*) 'x_L2:', x_L2\n write(*,*) 'x_L3:', x_L3\n write(*,*) ''\n write(*,*) 'x_moon :', 1.0_wp - mu\n write(*,*) 'x_earth:', -mu\n\n !*************************************************\n !integrate initial guess:\n\n write(*,*) ''\n write(*,*) ' Halo Initial Guess'\n write(*,*) ''\n write(*,*) 't0=',t0\n write(*,*) 'r0=',x0(1:3)\n write(*,*) 'v0=',x0(4:6)\n\n call prop%initialize(n,func,report,x_axis_crossing)\n call prop%integrate_to_event(t0,x0,dt,tmax,tol,tf_actual,xf,gf)\n\n write(*,*) ''\n write(*,*) 'tf=',tf_actual\n write(*,*) 'rf=',xf(1:3)\n write(*,*) 'vf=',xf(4:6)\n\n !plot the 2D trajectory, zero-velocity curves, and libration point locations:\n call plt%initialize(grid=.true.,xlabel='x',ylabel='y',&\n title='Halo Initial Guess',legend=.false.,figsize=[10,10],&\n use_numpy=.true.,axis_equal=.true.,mplot3d=.true.)\n\n !trajectory:\n call plt%add_3d_plot(x_crtbp,y_crtbp,z_crtbp,label='trajectory',linestyle='b-',linewidth=2,istat=istat)\n !bodies:\n call plt%add_3d_plot([-mu],[zero],[zero], label='B1',linestyle='bo',markersize=5,linewidth=5,istat=istat)\n call plt%add_3d_plot([1.0_wp-mu],[zero],[zero], label='B2',linestyle='ko',markersize=5,linewidth=5,istat=istat)\n !libration point locations:\n call plt%add_3d_plot([x_L1],[zero],[zero], label='L1',linestyle='rx',markersize=3,linewidth=3,istat=istat)\n call plt%add_3d_plot([x_L2],[zero],[zero], label='L2',linestyle='rx',markersize=3,linewidth=3,istat=istat)\n call plt%add_3d_plot([x_L3],[zero],[zero], label='L3',linestyle='rx',markersize=3,linewidth=3,istat=istat)\n !zero-velocity curve (for this jacobi constant):\n call plt%add_contour(x_vec, y_vec, c_mat, label='zero velocity curve', &\n linestyle='-', linewidth=2, &\n levels=[c], color='r',istat=istat)\n call plt%savefig('halo_guess.png',pyfile='halo_guess.py',istat=istat)\n call plt%destroy()\n\n !-------------------------------------------\n !\n ! solve for a Halo using HYBRD\n !\n\n write(*,*) ''\n write(*,*) 'solve for halo...'\n\n !turn off integration reporting for iterations:\n call prop%destroy()\n call prop%initialize(n,func,g=x_axis_crossing)\n\n !initialize the plot:\n call plt%initialize(grid=.true.,xlabel='x',ylabel='y',&\n title='Earth-Moon Halo Orbits',&\n legend=.false.,figsize=[10,10],&\n use_numpy=.true.,axis_equal=.true.,&\n mplot3d=.true.)\n\n ! see also: http://ccar.colorado.edu/asen5050/projects/projects_2012/bezrouk/Mission%20Analysis.html\n\n do libpoint=1,2 ! libration point L1, L2, L3\n do i=1,10\n\n Az = A_z+(i-1)*1000.0_wp ! in km\n !Az = A_z+(i-1)*10000.0_wp ! in km - for L3 cases\n\n call prop%destroy()\n call prop%initialize(n,func,g=x_axis_crossing)\n\n call halo_to_rv(libpoint,mu_earth,mu_moon,em_distance,&\n Az,sol_family,t1,x0,period=period)\n if (period==zero) cycle\n\n write(*,*) ''\n write(*,*) ' r0=',x0(1:3)\n write(*,*) ' v0=',x0(4:6)\n\n if (allocated(x_crtbp)) then ! clear these for new trajectory\n deallocate(x_crtbp)\n deallocate(y_crtbp)\n deallocate(z_crtbp)\n end if\n\n !now, solve for a halo:\n ! [note: we could also use the STM for better derivatives here....]\n x_vy0 = [x0(1),x0(5)]\n call hybrd1(halo_fcn,2,x_vy0,vx_vzf,tol=xtol,info=info)\n write(*,*) ''\n write(*,*) ' info=',info\n write(*,*) ' Az =',Az\n write(*,*) ' x0 =',x_vy0(1)\n write(*,*) ' vy0=',x_vy0(2)\n write(*,*) ' vxf=',vx_vzf(1)\n write(*,*) ' vzf=',vx_vzf(2)\n\n !now plot solution:\n call prop%initialize(n,func,report,g=x_axis_crossing)\n x1 = x0\n x1(1) = x_vy0(1) !solution from hybrd\n x1(5) = x_vy0(2) !solution from hybrd\n !integrate one full rev (two x-axis crossings):\n call prop%integrate_to_event(t0,x1,dt,tmax,tol,tf_actual,xf,gf) !1/2 rev\n call prop%integrate_to_event(t0,xf,dt,tmax,tol,tf_actual,x1,gf) !1 rev\n\n write(*,*) 'period: ', 2.0_wp * tf_actual\n\n !plot the 3D trajectory:\n call plt%add_3d_plot(x_crtbp,y_crtbp,z_crtbp,label='solution',&\n linestyle=colors(1+mod(i,size(colors)))//'-',linewidth=2,istat=istat)\n\n end do\n end do\n\n !also plot the libration point locations:\n call plt%add_3d_plot([x_L1],[zero],[zero], label='L1',linestyle='rx',markersize=4,linewidth=3,istat=istat)\n call plt%add_3d_plot([x_L2],[zero],[zero], label='L2',linestyle='rx',markersize=4,linewidth=3,istat=istat)\n !call plt%add_3d_plot([x_L3],[zero],[zero], label='L3',linestyle='rx',markersize=3,linewidth=3,istat=istat)\n !call plt%add_3d_plot([-mu],[zero],[zero], label='B1',linestyle='bo',markersize=5,linewidth=5,istat=istat)\n call plt%add_3d_plot([1.0_wp-mu],[zero],[zero], label='B2',linestyle='ko',markersize=5,linewidth=5,istat=istat)\n call plt%savefig('halos.png',pyfile='halos.py',istat=istat)\n call plt%destroy()\n\n contains\n\n!**************************************************************************\n subroutine halo_fcn(n,xvec,fvec,iflag) !! Halo function for [[hybrd1]]\n\n implicit none\n\n integer,intent(in) :: n !! `n=2` in this case\n real(wp),dimension(n),intent(in) :: xvec !! x_vy0\n real(wp),dimension(n),intent(out) :: fvec !! [vxf,vzf]\n integer,intent(inout) :: iflag\n\n real(wp) :: gf,t0\n real(wp),dimension(6) :: x,x1,xf\n\n real(wp),parameter :: tol = 1.0e-8_wp !! event finding tolerance\n\n t0 = zero ! epoch doesn't matter for crtbp\n x = x0 ! initial guess state\n x(1) = xvec(1) ! x0\n x(5) = xvec(2) ! vy0\n\n !integrate to the next x-axis crossing:\n call prop%integrate_to_event(t0,x,dt,tmax,tol,tf_actual,xf,gf)\n\n !want x and z-velocity at the x-axis crossing to be zero:\n fvec = [xf(4),xf(6)]\n\n end subroutine halo_fcn\n!**************************************************************************\n\n!**************************************************************************\n subroutine func(me,t,x,xdot) !! CRTBP derivative function\n implicit none\n class(rk_class),intent(inout) :: me\n real(wp),intent(in) :: t\n real(wp),dimension(me%n),intent(in) :: x\n real(wp),dimension(me%n),intent(out) :: xdot\n\n call crtbp_derivs(mu,x,xdot)\n\n end subroutine func\n!**************************************************************************\n\n!**************************************************************************\n subroutine x_axis_crossing(me,t,x,g) !! x-axis crossing event function\n implicit none\n class(rk_class),intent(inout) :: me\n real(wp),intent(in) :: t\n real(wp),dimension(me%n),intent(in) :: x\n real(wp),intent(out) :: g\n\n g = x(2) ! y = 0 at x-z-plane crossing\n\n end subroutine x_axis_crossing\n!**************************************************************************\n\n!**************************************************************************\n subroutine report(me,t,x) !! report function\n\n implicit none\n\n class(rk_class),intent(inout) :: me\n real(wp),intent(in) :: t\n real(wp),dimension(me%n),intent(in) :: x\n\n !write(*,'(*(F30.16,1X))') t, x, compute_jacobi_constant(mu,x)\n\n if (allocated(x_crtbp)) then ! uses Fortran 2008 auto LHS reallocations\n x_crtbp = [x_crtbp, x(1)]\n y_crtbp = [y_crtbp, x(2)]\n z_crtbp = [z_crtbp, x(3)]\n else\n x_crtbp = [x(1)]\n y_crtbp = [x(2)]\n z_crtbp = [x(3)]\n end if\n\n end subroutine report\n!**************************************************************************\n\n end program halo_test\n!*****************************************************************************************\n", "meta": {"hexsha": "36cc4c109bf46347fa20e3eaa6e22e2a4d424ed9", "size": 12766, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/halo/halo_test.f90", "max_stars_repo_name": "gandymagic/Fortran-Astrodynamics-Toolkit", "max_stars_repo_head_hexsha": "7f176fabc8c36cc1981349b02eeb6d8112f2bfbc", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-12-26T03:54:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-12-26T03:54:38.000Z", "max_issues_repo_path": "tests/halo/halo_test.f90", "max_issues_repo_name": "gandymagic/Fortran-Astrodynamics-Toolkit", "max_issues_repo_head_hexsha": "7f176fabc8c36cc1981349b02eeb6d8112f2bfbc", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/halo/halo_test.f90", "max_forks_repo_name": "gandymagic/Fortran-Astrodynamics-Toolkit", "max_forks_repo_head_hexsha": "7f176fabc8c36cc1981349b02eeb6d8112f2bfbc", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.4369501466, "max_line_length": 115, "alphanum_fraction": 0.5263199123, "num_tokens": 3819, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240756264638, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6605845289207921}} {"text": "C Copyright 2021 Dennis Decker Jensen\nC Date: 9 May 2021\nC Purpose: Prime number test\nC Tectonics: gfortran --std=f95 -ffixed-form -c primetest.f\n LOGICAL FUNCTION PRIME(NUM)\n IROOT = INT(SQRT(REAL(NUM)))\n\n DO 10 I=2,IROOT\n IF (MOD(NUM,I).EQ.0) THEN\n PRIME=.FALSE.\n RETURN\n ENDIF\n 10 CONTINUE\n PRIME=.TRUE.\n END\n", "meta": {"hexsha": "12c7053e5547e748d2c08d4f889f74b4d69ca3c6", "size": 401, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "euler/primetest.f", "max_stars_repo_name": "dennisdjensen/Sketchbook", "max_stars_repo_head_hexsha": "efb4c7df592ba4fe84e9cdcb0883c93823d04bf5", "max_stars_repo_licenses": ["0BSD"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-04-26T19:30:58.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-12T16:34:23.000Z", "max_issues_repo_path": "euler/primetest.f", "max_issues_repo_name": "dennisdjensen/sketchbook", "max_issues_repo_head_hexsha": "efb4c7df592ba4fe84e9cdcb0883c93823d04bf5", "max_issues_repo_licenses": ["0BSD"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "euler/primetest.f", "max_forks_repo_name": "dennisdjensen/sketchbook", "max_forks_repo_head_hexsha": "efb4c7df592ba4fe84e9cdcb0883c93823d04bf5", "max_forks_repo_licenses": ["0BSD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.0625, "max_line_length": 59, "alphanum_fraction": 0.5610972569, "num_tokens": 122, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8558511396138365, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6605831417207987}} {"text": "program matrix_clip_zero\n use, intrinsic :: iso_fortran_env, only : dp => REAL64\n implicit none\n integer, parameter :: m = 3, n = 3\n real(kind=dp), dimension(m, n) :: A = reshape([ 3.0, 1.0, 4.0, &\n -3.0, -0.5, -2.0, &\n -0.5, 2.0, -1.0 ], [m, n])\n integer :: i\n\n do i = 1, m\n print *, A(i, :)\n end do\n call clip_zeros(A, 1.0_dp)\n print *, 'clipped'\n do i = 1, m\n print *, A(i, :)\n end do\n\ncontains\n\n subroutine clip_zeros(A, epsilon)\n use, intrinsic :: iso_fortran_env, only : dp => REAL64\n implicit none\n real(kind=dp), dimension(:, :), intent(inout) :: A\n real(kind=dp), intent(in) :: epsilon\n where (abs(A) < epsilon)\n A = 0.0_dp\n end where\n end subroutine clip_zeros\n\nend program matrix_clip_zero\n", "meta": {"hexsha": "0b428a77a785f64f0f98a51356de072d6b660c44", "size": 913, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "hands-on/session_02/exercise_05.f90", "max_stars_repo_name": "gjbex/FortranForProgrammers", "max_stars_repo_head_hexsha": "0b23d3a4c325fa833333f83ef5326378e9e5e854", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-15T14:56:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-15T14:56:20.000Z", "max_issues_repo_path": "hands-on/session_02/exercise_05.f90", "max_issues_repo_name": "gjbex/FortranForProgrammers", "max_issues_repo_head_hexsha": "0b23d3a4c325fa833333f83ef5326378e9e5e854", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hands-on/session_02/exercise_05.f90", "max_forks_repo_name": "gjbex/FortranForProgrammers", "max_forks_repo_head_hexsha": "0b23d3a4c325fa833333f83ef5326378e9e5e854", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.53125, "max_line_length": 79, "alphanum_fraction": 0.4808324206, "num_tokens": 275, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390746, "lm_q2_score": 0.8558511451289037, "lm_q1q2_score": 0.6605831414858705}} {"text": "module solvergmres_module\n\n implicit none\n\ncontains\n\n !===================================================\n subroutine findnorm(norm,v1,n)\n\n integer,intent(in) :: n\n real*8,intent(in) :: v1(n)\n real*8, intent(out) :: norm\n\n integer :: i\n\n norm=0.d0\n\n do i=1,n\n norm=norm+v1(i)*v1(i)\n enddo\n\n norm=sqrt(norm)\n\n end subroutine findnorm\n !===================================================\n subroutine innerproduct(v1dotv2,v1,v2,n)\n\n integer, intent(in) :: n\n real*8, intent(in) :: v1(n),v2(n)\n real*8, intent(out) :: v1dotv2\n\n integer :: i\n\n v1dotv2=0.d0\n\n do i=1,n\n v1dotv2=v1dotv2+v1(i)*v2(i)\n enddo\n\n end subroutine innerproduct\n !===================================================\n subroutine arnoldialgorithm(v1,m,n,Hmat,kspvecs,findAX,precond,lucky)\n\n\t\t integer,intent(in) :: m,n\n\t\t real*8,intent(in) :: v1(n)\n\t\t real*8, intent(inout) :: Hmat(m+1,m)\n\t\t real*8, intent(inout) :: kspvecs(n,m+1)\n\t\t logical,intent(inout) :: lucky\n\n\t\t external :: findAX\n\t\t external :: precond\n\n\n\t\t real*8 :: Avj(n)\n\t\t real*8 :: MinvAvj(n)\n\t\t real*8 :: wj(n)\n\t\t real*8 :: vi(n),vj(n)\n\t\t integer :: i,j,k\n\n\t\t kspvecs(:,1)=v1\n\t\t lucky = .false.\n\n\t\t do j=1,m\n\t\t \n\t \t vj = kspvecs(:,j)\n\n\t\t\tcall findAX(Avj,vj,n)\n\t\t\tcall precond(MinvAvj,Avj,n)\n\n\t\t\tdo i=1,j\n\t\t\t\tvi = kspvecs(:,i)\t\n\t\t\t\tcall innerproduct(Hmat(i,j),MinvAvj,vi,n)\n\t\t\tenddo\n\n\t\t\twj=MinvAvj\n\n\t\t\tdo i=1,j\n\t\t\t\tvi = kspvecs(:,i)\n\t\t\t\twj=wj-Hmat(i,j)*vi\n\t\t\tenddo\n\n\t\t\tcall findnorm(Hmat(j+1,j),wj,n)\n\n\t\t\tif(Hmat(j+1,j) > 0.d0) then\n\t\t\t\tkspvecs(:,j+1)=wj(:)/Hmat(j+1,j)\n\t\t\telse\n\t\t\t\tlucky=.true.\n\t\t\tendif\n\t\tenddo\n\n\n end subroutine arnoldialgorithm\n !===================================================\n subroutine leastsquaresminimize(y,Hmat,m,beta)\n\n\t\t integer,intent(in) :: m\n\t\t real*8,intent(inout) :: Hmat(m+1,m)\n\t\t real*8,intent(out) :: y(m)\n\t\t real*8,intent(in) :: beta\n\n\t\t real*8 :: c,s,h_up,h_down,dtr\n\t\t real*8 :: val1,val2\n\t\t real*8 :: beta_e1(m+1)\n\n\t\t integer :: i,j\n\n\t\t beta_e1(:) = 0.d0\n\t\t beta_e1(1) = beta;\n\n\t\t do i=1,m\n\n\t\t \th_up = Hmat(i,i)\n\t\t\th_down = Hmat(i+1,i)\n\n\t\t\tdtr = sqrt(h_up*h_up+h_down*h_down)\n\n\t\t\tc = h_up/dtr\n\t\t\ts = h_down/dtr\n\n\t\t\tdo j=1,m\n\t\t\t\t\n\t\t\t\th_up = Hmat(i,j)\n\t\t\t\th_down = Hmat(i+1,j)\n\n\t\t\t\tHmat(i,j) = c*h_up + s*h_down\n\t\t\t\tHmat(i+1,j) = -s*h_up + c*h_down \n\n\t\t\tenddo\n\n\t\t\tval1 = c*beta_e1(i) + s*beta_e1(i+1); \n\t\t\tval2 = -s*beta_e1(i) + c*beta_e1(i+1);\n\n\t\t\tbeta_e1(i) = val1\n\t\t\tbeta_e1(i+1) = val2\t\n\t\tenddo\n\n\n\t\ty(m) = beta_e1(m)/Hmat(m,m)\n\n\t\tdo i=m-1,1,-1\n\n\t\t\ty(i)=beta_e1(i)\n\n\t\t\tdo j=i+1,m\n\t\t\t\ty(i)=y(i)-Hmat(i,j)*y(j)\n\t\t\tenddo\n\n\t\t\ty(i) = y(i)/Hmat(i,i)\n\n\t\tenddo\n\n end subroutine leastsquaresminimize\n !===================================================\n subroutine performgmres(b,x0,x,m,n,nrestarts,findAX,precond)\n\n\t\t integer,intent(in) :: m,n,nrestarts\n\t\t real*8, intent(in) :: b(n),x0(n)\n\t\t real*8, intent(out) :: x(n)\n\t\t external :: findAX, precond\n\n\t\t integer :: i,j,k\n\n\t\t real*8 :: r0(n)\n\t\t real*8 :: Minvr0(n)\n\t\t real*8 :: Ax0(n),Ax(n)\n\t\t real*8 :: r(n),v1(n)\n\t\t real*8 :: beta\n\t\t real*8 :: y(m)\n\n\t\t real*8 :: kspvectors(n,m+1)\n\t\t real*8 :: Hmat(m+1,m)\n\n\t\t real*8 :: eps\n\n\t\t logical :: lucky\n\n\t\t call findAX(Ax0,x0,n)\n\t\t r0 = b-Ax0\n\t\t call precond(Minvr0,r0,n)\n\t\t r=Minvr0\n\t\t x=x0\n\n\t\t Hmat = 0.d0\n\t\t kspvectors = 0.d0\n\t\t lucky = .false.\n\t\t eps = 1e-6 \n\n\t\t do i=1,nrestarts\n\t\t \t\n\t\t \tcall findnorm(beta,r,n)\n\t\t\tprint *,\"restart iteration:\",i,\"residual norm:\",beta\n\n\t\t\tif(beta .le. eps) then\n\t\t\t\texit\n\t\t\tendif\n\n\t\t\tv1=r/beta\n\n \t\t\tcall arnoldialgorithm(v1,m,n,Hmat,kspvectors,findAX,precond,lucky)\n\n\t\t\tif(lucky .eqv. .true.) then\n\t\t\t\tprint *,\"lucky condition\"\n\t\t\t\texit\n\t\t\tendif\n\n \t\t\tcall leastsquaresminimize(y,Hmat,m,beta)\n\n\t\t\tdo j=1,m\n\t\t\t\tx=x+y(j)*kspvectors(:,j)\n\t\t\tenddo\n\n\t\t\tcall findAX(Ax,x,n)\n\t\t\tr=b-Ax\n\t\t\tcall precond(Minvr0,r,n)\n\t\t\tr=Minvr0\n\t\tenddo\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n end subroutine performgmres\n !===================================================\n\nend module solvergmres_module\n", "meta": {"hexsha": "f1728f429d4bc2c151a32c99460ae0d751cf79c1", "size": 4035, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "pretreatment_model/src/gmres.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/gmres.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/gmres.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": 18.0133928571, "max_line_length": 71, "alphanum_fraction": 0.5164807931, "num_tokens": 1478, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511543206819, "lm_q2_score": 0.7718434873426302, "lm_q1q2_score": 0.6605831395970907}} {"text": "PROGRAM PolynomialBasisMappingTest\n\n USE KindModule, ONLY: &\n DP, TwoPi\n USE UtilitiesModule, ONLY: &\n NodeNumber, &\n WriteVector, &\n WriteMatrix\n USE ProgramHeaderModule, ONLY: &\n nNodes, nNodesE, nNodesX, nDOF, nDOFX, &\n nDims, nDimsX\n USE QuadratureModule, ONLY: &\n InitializeQuadratures, &\n GetQuadrature\n USE PolynomialBasisModule_Lagrange, ONLY: &\n InitializePolynomialBasis_Lagrange, &\n EvalL\n USE PolynomialBasisModule_Legendre, ONLY: &\n InitializePolynomialBasis_Legendre, &\n EvalP\n USE PolynomialBasisMappingModule, ONLY: &\n InitializePolynomialBasisMapping, &\n MapNodalToModal_Radiation, &\n MapModalToNodal_Radiation\n\n IMPLICIT NONE\n\n INTEGER :: iNodeE, iNodeX1, iNodeX2, iNodeX3, iNode\n INTEGER :: iPointE, iPointX1\n INTEGER, PARAMETER :: nPointsE = 64, nPointsX1 = 64\n REAL(DP), PARAMETER :: eL = - 0.5_DP, eR = + 0.5_DP\n REAL(DP), PARAMETER :: xL = - 0.5_DP, xR = + 0.5_DP\n REAL(DP), DIMENSION(:), ALLOCATABLE :: U, U_2, C, C_2\n REAL(DP), DIMENSION(:), ALLOCATABLE :: NodesE, WeightsE\n REAL(DP), DIMENSION(:), ALLOCATABLE :: NodesX1, WeightsX1\n REAL(DP), DIMENSION(:), ALLOCATABLE :: NodesX2, WeightsX2\n REAL(DP), DIMENSION(:), ALLOCATABLE :: NodesX3, WeightsX3\n REAL(DP), DIMENSION(:), ALLOCATABLE :: PointsE\n REAL(DP), DIMENSION(:), ALLOCATABLE :: PointsX1\n REAL(DP), DIMENSION(:,:), ALLOCATABLE :: U_2D_L, U_2_2D_L\n REAL(DP), DIMENSION(:,:), ALLOCATABLE :: U_2D_P, U_2_2D_P\n\n nNodes = 4\n nNodesE = nNodes\n nNodesX(1) = nNodes\n nNodesX(2) = 1\n nNodesX(3) = 1\n nDOFX = PRODUCT( nNodesX )\n nDOF = nDOFX * nNodesE\n nDimsX = 1\n nDims = 2\n\n CALL InitializeQuadratures\n\n CALL InitializePolynomialBasis_Lagrange\n\n CALL InitializePolynomialBasis_Legendre\n\n ALLOCATE( U(nDOF), U_2(nDOF), C(nDOF), C_2(nDOF) )\n ALLOCATE( NodesE(nNodesE), WeightsE(nNodesE) )\n ALLOCATE( NodesX1(nNodesX(1)), WeightsX1(nNodesX(1)) )\n ALLOCATE( NodesX2(nNodesX(2)), WeightsX2(nNodesX(2)) )\n ALLOCATE( NodesX3(nNodesX(3)), WeightsX3(nNodesX(3)) )\n ALLOCATE( U_2D_L(nPointsE,nPointsX1), U_2_2D_L(nPointsE,nPointsX1) )\n ALLOCATE( U_2D_P(nPointsE,nPointsX1), U_2_2D_P(nPointsE,nPointsX1) )\n\n CALL GetQuadrature( nNodesE, NodesE, WeightsE )\n CALL GetQuadrature( nNodesX(1), NodesX1, WeightsX1 )\n CALL GetQuadrature( nNodesX(2), NodesX2, WeightsX2 )\n CALL GetQuadrature( nNodesX(3), NodesX3, WeightsX3 )\n\n CALL InitializePolynomialBasisMapping &\n ( NodesE, NodesX1, NodesX2, NodesX3 )\n\n DO iNodeX3 = 1, nNodesX(3)\n DO iNodeX2 = 1, nNodesX(2)\n DO iNodeX1 = 1, nNodesX(1)\n DO iNodeE = 1, nNodesE\n\n iNode = NodeNumber( iNodeE, iNodeX1, iNodeX2, iNodeX3 )\n\n U(iNode) = COS( TwoPi * ( eL - NodesE(iNodeE) ) ) &\n * SIN( TwoPi * ( xL - NodesX1(iNodeX1) ) )\n\n END DO\n END DO\n END DO\n END DO\n\n CALL MapNodalToModal_Radiation( U, C )\n\n ! --- Damp Higher Modal Coefficients ---\n\n C_2(1) = C(1)\n C_2(2:nDOF) = 0.9_DP * C(2:nDOF)\n\n CALL MapModalToNodal_Radiation( U_2, C_2 )\n\n ALLOCATE( PointsE(nPointsE) )\n DO iPointE = 1, nPointsE\n PointsE(iPointE) &\n = eL + REAL(iPointE-1)/REAL(nPointsE-1)\n END DO\n\n ALLOCATE( PointsX1(nPointsX1) )\n DO iPointX1 = 1, nPointsX1\n PointsX1(iPointX1) &\n = xL + REAL(iPointX1-1)/REAL(nPointsX1-1)\n END DO\n\n DO iPointX1 = 1, nPointsX1\n DO iPointE = 1, nPointsE\n\n U_2D_L(iPointE,iPointX1) &\n = EvalL( U, PointsE(iPointE), PointsX1(iPointX1), 0.0_DP, 0.0_DP )\n\n U_2D_P(iPointE,iPointX1) &\n = EvalP( C, PointsE(iPointE), PointsX1(iPointX1), 0.0_DP, 0.0_DP )\n\n U_2_2D_L(iPointE,iPointX1) &\n = EvalL( U_2, PointsE(iPointE), PointsX1(iPointX1), 0.0_DP, 0.0_DP )\n\n U_2_2D_P(iPointE,iPointX1) &\n = EvalP( C_2, PointsE(iPointE), PointsX1(iPointX1), 0.0_DP, 0.0_DP )\n\n END DO\n END DO\n\n CALL WriteVector( nPointsE, PointsE, 'E.dat' )\n CALL WriteVector( nPointsX1, PointsX1, 'X.dat' )\n CALL WriteVector( nDOF, U, 'U.dat' )\n CALL WriteVector( nDOF, C, 'C.dat' )\n CALL WriteMatrix( nPointsE, nPointsX1, U_2D_L, 'U_2D_L.dat' )\n CALL WriteMatrix( nPointsE, nPointsX1, U_2D_P, 'U_2D_P.dat' )\n CALL WriteMatrix( nPointsE, nPointsX1, U_2_2D_L, 'U_2_2D_L.dat' )\n CALL WriteMatrix( nPointsE, nPointsX1, U_2_2D_P, 'U_2_2D_P.dat' )\n\n DEALLOCATE( U, U_2, C, C_2 )\n DEALLOCATE( NodesE, WeightsE )\n DEALLOCATE( NodesX1, WeightsX1 )\n DEALLOCATE( NodesX2, WeightsX2 )\n DEALLOCATE( NodesX3, WeightsX3 )\n DEALLOCATE( U_2D_L, U_2_2D_L )\n DEALLOCATE( U_2D_P, U_2_2D_P )\n DEALLOCATE( PointsE )\n DEALLOCATE( PointsX1 )\n\nEND PROGRAM PolynomialBasisMappingTest\n", "meta": {"hexsha": "a2622ce9b4a4e10dee61d6621e41553ad6534850", "size": 4654, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "SandBox/PolynomialBasis/PolynomialBasisMappingTest.f90", "max_stars_repo_name": "srichers/thornado", "max_stars_repo_head_hexsha": "bc6666cbf9ae8b39b1ba5feffac80303c2b1f9a8", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-12-08T16:16:55.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-24T19:31:21.000Z", "max_issues_repo_path": "SandBox/PolynomialBasis/PolynomialBasisMappingTest.f90", "max_issues_repo_name": "srichers/thornado", "max_issues_repo_head_hexsha": "bc6666cbf9ae8b39b1ba5feffac80303c2b1f9a8", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2019-07-10T20:13:15.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-11T13:21:00.000Z", "max_forks_repo_path": "SandBox/PolynomialBasis/PolynomialBasisMappingTest.f90", "max_forks_repo_name": "srichers/thornado", "max_forks_repo_head_hexsha": "bc6666cbf9ae8b39b1ba5feffac80303c2b1f9a8", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2018-11-14T01:13:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-24T02:08:20.000Z", "avg_line_length": 31.2348993289, "max_line_length": 76, "alphanum_fraction": 0.6669531586, "num_tokens": 1879, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511432905479, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6605831355752506}} {"text": "! { dg-do run }\n! { dg-additional-options \"-mfp-rounding-mode=d\" { target alpha*-*-* } }\n\n use, intrinsic :: ieee_features\n use, intrinsic :: ieee_arithmetic\n implicit none\n\n ! k1 and k2 will be large real kinds, if supported, and single/double\n ! otherwise\n integer, parameter :: k1 = &\n max(ieee_selected_real_kind(precision(0.d0) + 1), kind(0.))\n integer, parameter :: k2 = &\n max(ieee_selected_real_kind(precision(0._k1) + 1), kind(0.d0))\n\n interface check_equal\n procedure check_equal1, check_equal2\n end interface\n\n interface check_not_equal\n procedure check_not_equal1, check_not_equal2\n end interface\n\n interface divide\n procedure divide1, divide2\n end interface\n\n real(kind=k1) :: x1, x2, x3\n real(kind=k2) :: y1, y2, y3\n type(ieee_round_type) :: mode\n\n if (ieee_support_rounding(ieee_up, x1) .and. &\n ieee_support_rounding(ieee_down, x1) .and. &\n ieee_support_rounding(ieee_nearest, x1) .and. &\n ieee_support_rounding(ieee_to_zero, x1)) then\n\n x1 = 1\n x2 = 3\n x1 = divide(x1, x2, ieee_up)\n\n x3 = 1\n x2 = 3\n x3 = divide(x3, x2, ieee_down)\n call check_not_equal(x1, x3)\n call check_equal(x3, nearest(x1, -1._k1))\n call check_equal(x1, nearest(x3, 1._k1))\n\n call check_equal(1._k1/3._k1, divide(1._k1, 3._k1, ieee_nearest))\n call check_equal(-1._k1/3._k1, divide(-1._k1, 3._k1, ieee_nearest))\n\n call check_equal(divide(3._k1, 7._k1, ieee_to_zero), &\n divide(3._k1, 7._k1, ieee_down))\n call check_equal(divide(-3._k1, 7._k1, ieee_to_zero), &\n divide(-3._k1, 7._k1, ieee_up))\n\n end if\n\n if (ieee_support_rounding(ieee_up, y1) .and. &\n ieee_support_rounding(ieee_down, y1) .and. &\n ieee_support_rounding(ieee_nearest, y1) .and. &\n ieee_support_rounding(ieee_to_zero, y1)) then\n\n y1 = 1\n y2 = 3\n y1 = divide(y1, y2, ieee_up)\n\n y3 = 1\n y2 = 3\n y3 = divide(y3, y2, ieee_down)\n call check_not_equal(y1, y3)\n call check_equal(y3, nearest(y1, -1._k2))\n call check_equal(y1, nearest(y3, 1._k2))\n\n call check_equal(1._k2/3._k2, divide(1._k2, 3._k2, ieee_nearest))\n call check_equal(-1._k2/3._k2, divide(-1._k2, 3._k2, ieee_nearest))\n\n call check_equal(divide(3._k2, 7._k2, ieee_to_zero), &\n divide(3._k2, 7._k2, ieee_down))\n call check_equal(divide(-3._k2, 7._k2, ieee_to_zero), &\n divide(-3._k2, 7._k2, ieee_up))\n\n end if\n\ncontains\n\n real(kind=k1) function divide1 (x, y, rounding) result(res)\n use, intrinsic :: ieee_arithmetic\n real(kind=k1), intent(in) :: x, y\n type(ieee_round_type), intent(in) :: rounding\n type(ieee_round_type) :: old\n\n call ieee_get_rounding_mode (old)\n call ieee_set_rounding_mode (rounding)\n\n res = x / y\n\n call ieee_set_rounding_mode (old)\n end function\n\n real(kind=k2) function divide2 (x, y, rounding) result(res)\n use, intrinsic :: ieee_arithmetic\n real(kind=k2), intent(in) :: x, y\n type(ieee_round_type), intent(in) :: rounding\n type(ieee_round_type) :: old\n\n call ieee_get_rounding_mode (old)\n call ieee_set_rounding_mode (rounding)\n\n res = x / y\n\n call ieee_set_rounding_mode (old)\n end function\n\n subroutine check_equal1 (x, y)\n real(kind=k1), intent(in) :: x, y\n if (x /= y) then\n print *, x, y\n STOP 1\n end if\n end subroutine\n\n subroutine check_equal2 (x, y)\n real(kind=k2), intent(in) :: x, y\n if (x /= y) then\n print *, x, y\n STOP 2\n end if\n end subroutine\n\n subroutine check_not_equal1 (x, y)\n real(kind=k1), intent(in) :: x, y\n if (x == y) then\n print *, x, y\n STOP 3\n end if\n end subroutine\n\n subroutine check_not_equal2 (x, y)\n real(kind=k2), intent(in) :: x, y\n if (x == y) then\n print *, x, y\n STOP 4\n end if\n end subroutine\n\nend\n", "meta": {"hexsha": "0ec429a006ff39d831f91c7a70d4e316d6ce093d", "size": 3829, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/ieee/large_2.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/ieee/large_2.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/ieee/large_2.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": 26.2260273973, "max_line_length": 72, "alphanum_fraction": 0.635675111, "num_tokens": 1303, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511396138366, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.660583132737405}} {"text": "!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%!\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%! \nMODULE monter_carlo\nIMPLICIT NONE\n INTEGER (KIND=8),PARAMETER :: nx=10,ny=10,nz=10,nT=21,n_average=5000\n REAL (KIND=8),PARAMETER :: Tmin=2.0,Tmax=6.0\n INTEGER (KIND=8) :: iT,i,j,k,i_loop,im,ip,jm,jp,km,kp\n REAL (KIND=8) :: T,delT,rdn_mtp,real_na\n REAL (KIND=8) :: E_tmp1,E_tmp2,energy,energy_2,E_av,E_2_av,Cv,S_tmp,M,M_av\n\n REAL (KIND=8),DIMENSION(0:nx+1,0:ny+1,0:nz+1) :: S\n\n CONTAINS\n\n!!!=======================================================================================\n!!!=======================================================================================\n SUBROUTINE average_thermal()\n IMPLICIT NONE\n\n CALL ini_rdm_number()\n\n real_na=real(nx*ny*nz)\n \n S(:,:,:)=0.\n S(1:nx,1:ny,1:nz)=1. \n \n E_av=0. ; E_2_av=0. ; M_av=0.\n \n DO i_loop=1,n_average\n CALL value_thermal() \n E_av=E_av+energy\n E_2_av=E_2_av+energy_2\n M_av=M_av+M \n END DO\n\n E_av=E_av/real(n_average)\n E_2_av=E_2_av/real(n_average)\n M_av=M_av/real(n_average)\n Cv = real_na*(E_2_av-E_av**2.)/(T**2.)\n\n END SUBROUTINE average_thermal\n\n!!!=======================================================================================\n!!!=======================================================================================\n SUBROUTINE ini_rdm_number()\n IMPLICIT NONE\n \n INTEGER (KIND=8),DIMENSION(8) :: time\n INTEGER (KIND=8),DIMENSION(50) :: seed\n\n CALL DATE_AND_TIME(values=time) ! Get the current time\n seed(1) = time(4)*(360000*time(5) + 6000*time(6) + 100*time(7) + time(8))\n CALL RANDOM_SEED(PUT=seed)\n\n END SUBROUTINE ini_rdm_number\n\n!!!=======================================================================================\n!!!=======================================================================================\n SUBROUTINE value_thermal()\n IMPLICIT NONE\n \n energy=0.\n\n DO i=1,nx\n ip=i+1\n im=i-1\n DO j=1,ny\n jp=j+1\n jm=j-1\n DO k=1,nz\n kp=k+1\n km=k-1\n\n E_tmp1=-S(i,j,k)*(S(ip,j,k)+S(im,j,k)+S(i,jp,k)+S(i,jm,k)+S(i,j,kp)+S(i,j,km)) \n E_tmp2=-E_tmp1\n S_tmp=S(i,j,k)\n\n CALL random_number(rdn_mtp)\n IF (exp(-(E_tmp2-E_tmp1)/T) > rdn_mtp) THEN\n S(i,j,k)=-S_tmp\n E_tmp1=E_tmp2\n END IF\n energy=energy+E_tmp1\n M=M+S(i,j,k)\n END DO\n END DO\n END DO\n\n energy=energy/(2.*real_na)\n energy_2=energy**2.\n M=abs(M)/real_na\n\n END SUBROUTINE value_thermal \n\nEND MODULE monter_carlo\n\n!!!=======================================================================================\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%!\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%! \n PROGRAM main_ising\n USE monter_carlo\n IMPLICIT NONE\n\n CALL system('rm CPU_result.dat')\n!!!---------------------------------------------------------------------\n\n IF (nT==1) THEN\n delT=0.\n ELSE\n delT=(Tmax-Tmin)/real(nT-1)\n END IF\n\n OPEN(unit=20,file='CPU_result.dat')\n\n DO iT=1,nT\n WRITE(*,*)'iT = ', iT \n T=Tmin+delT*real(iT-1)\n CALL average_thermal()\n WRITE(20,*) T,E_av,M_av,Cv\n !WRITE(*,*) T,E_av,M_av,Cv\n END DO \n\n CLOSE(20)\n\n!!!@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n END PROGRAM main_ising\n \n", "meta": {"hexsha": "62cd2d12a75ee92dfadd350d260d80c217438d83", "size": 3905, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "codes/ex_GPU_MC/2main_FORTRAN.f90", "max_stars_repo_name": "danhtaihoang/cudafortran", "max_stars_repo_head_hexsha": "02d422f237e64ac9b212acdd897cd5a00594b110", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "codes/ex_GPU_MC/2main_FORTRAN.f90", "max_issues_repo_name": "danhtaihoang/cudafortran", "max_issues_repo_head_hexsha": "02d422f237e64ac9b212acdd897cd5a00594b110", "max_issues_repo_licenses": ["MIT"], "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/ex_GPU_MC/2main_FORTRAN.f90", "max_forks_repo_name": "danhtaihoang/cudafortran", "max_forks_repo_head_hexsha": "02d422f237e64ac9b212acdd897cd5a00594b110", "max_forks_repo_licenses": ["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.2713178295, "max_line_length": 102, "alphanum_fraction": 0.3605633803, "num_tokens": 996, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511322604133, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6605831270617131}} {"text": "! --------------------------------------------------------------------\n!\n! Copyright (C) 2015 Rocco Meli\n!\n! This program is free software: you can redistribute it and/or modify\n! it under the terms of the GNU General Public License as published by\n! the Free Software Foundation, either version 3 of the License, or\n! (at your option) any later version.\n!\n! This program is distributed in the hope that it will be useful,\n! but WITHOUT ANY WARRANTY; without even the implied warranty of\n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n! GNU General Public License for more details.\n!\n! You should have received a copy of the GNU General Public License\n! along with this program. If not, see .\n!\n! ---------------------------------------------------------------------\n\nPROGRAM eigs_test\n\n USE LA, only: EIGS\n USE OUTPUT, only: print_real_matrix\n\n INTEGER, PARAMETER :: d = 2\n\n REAL*8, dimension(d,d) :: A\n REAL*8, dimension(d,d) :: V\n REAL*8, dimension(d) :: l\n\n A(1,:) = (/-1.53866, -0.515838/)\n A(2,:) = (/-0.515838, -2.43973/)\n\n CALL EIGS(d,A,V,l)\n\n WRITE(*,*) \"Matrix A\"\n CALL print_real_matrix(d,d,A)\n\n WRITE(*,*) \"Matrix V\"\n CALL print_real_matrix(d,d,V)\n\n WRITE(*,*) \"Vector l\"\n CALL print_real_matrix(d,1,l)\n\nEND PROGRAM eigs_test\n", "meta": {"hexsha": "757312a0290bc869fe25efc2c967820243b0f45b", "size": 1331, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran90/tests/eigs_test.f90", "max_stars_repo_name": "RMeli/Hartree-Fock", "max_stars_repo_head_hexsha": "dda0102ab2a88f3f2f666c2479a858140505ea60", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2016-09-16T09:26:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T16:09:53.000Z", "max_issues_repo_path": "Fortran90/tests/eigs_test.f90", "max_issues_repo_name": "RMeli/Hartree-Fock", "max_issues_repo_head_hexsha": "dda0102ab2a88f3f2f666c2479a858140505ea60", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran90/tests/eigs_test.f90", "max_forks_repo_name": "RMeli/Hartree-Fock", "max_forks_repo_head_hexsha": "dda0102ab2a88f3f2f666c2479a858140505ea60", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2016-01-20T13:47:43.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-28T03:18:22.000Z", "avg_line_length": 28.9347826087, "max_line_length": 71, "alphanum_fraction": 0.6048084147, "num_tokens": 343, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933447152498, "lm_q2_score": 0.8056321959813275, "lm_q1q2_score": 0.6605324757734222}} {"text": "program ch0810\n ! Rank 1 Array and the Sum Intrinsic Function\n implicit none\n\n integer, parameter :: n = 12\n real :: total = 0., average = 0.\n real, dimension(1:n) :: rainfall = &\n [ 3.1, 2., 2.4, 2.1, 2.2, 2.2, 1.8, 2.2, 2.7, 2.9, 3.1, 3.1 ]\n\n total = sum(rainfall)\n average = total/n\n print *, ' Average monthly rainfall was'\n print *, average\nend program\n", "meta": {"hexsha": "058db0930fb5ccd5225246dcf897276c7c09639f", "size": 392, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ch08/ch0810.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": "ch08/ch0810.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": "ch08/ch0810.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": 26.1333333333, "max_line_length": 69, "alphanum_fraction": 0.5739795918, "num_tokens": 148, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.819893353516963, "lm_q2_score": 0.8056321843145404, "lm_q1q2_score": 0.6605324732988446}} {"text": "PROGRAM stress_test_nested_implied_do\n ! Test that a nested implied do loop can be used to initialize an array.\n ! Array constructors, and implicit DO loops are detailed in sec. 7.8\n ! of the Standard.\n IMPLICIT NONE\n INTEGER, PARAMETER :: n=4\n INTEGER, PARAMETER :: m=10\n INTEGER, PARAMETER :: o=2\n INTEGER, PARAMETER :: p=3\n INTEGER :: i, j, k, l\n\n ! 1 level of nesting\n INTEGER :: array1(n) = (/ (i, i=1, n) /)\n INTEGER :: expect1(n)\n data expect1/1, 2, 3, 4/\n\n ! 2 levels of nesting\n INTEGER :: array2(m) = (/ ((i, j=1, i), i=1, n ) /)\n INTEGER :: expect2(m)\n data expect2/1, 2, 2, 3, 3, 3, 4, 4, 4, 4/\n\n ! 3 levels of nesting\n INTEGER :: array3(m*o) = (/ (((i, j=1, i), i=1,n ), k=1, o) /)\n INTEGER :: expect3(m*o)\n data expect3/1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4/\n\n ! 4 levels of nesting\n INTEGER :: array4(m*o*p) = (/ ((((i, j=1, i), i=1,n ), k=1, o), l=1, p) /)\n INTEGER :: expect4(m*o*p)\n data expect4/1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4,&\n 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4,&\n 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4/\n\n ! 3 levels of nesting and multiple items\n INTEGER :: array5(3*m*o) = (/ (((i, i+10, i+100, j=1, i), i=1,n ), k=1, o) /)\n INTEGER :: expect5(3*m*o)\n data expect5/1, 11, 101,&\n 2, 12, 102, 2, 12, 102,&\n 3, 13, 103, 3, 13, 103, 3, 13, 103,&\n 4, 14, 104, 4, 14, 104, 4, 14, 104, 4, 14, 104,&\n 1, 11, 101,&\n 2, 12, 102, 2, 12, 102,&\n 3, 13, 103, 3, 13, 103, 3, 13, 103,&\n 4, 14, 104, 4, 14, 104, 4, 14, 104, 4, 14, 104/\n\n INTEGER(KIND=1) :: i8, j8 ! TY_BINT\n INTEGER(KIND=2) :: i16, j16 ! TY_SINT\n INTEGER(KIND=4) :: i32, j32 ! TY_INT\n INTEGER(KIND=8) :: i64, j64 ! TY_INT8\n\n ! Different integers fitting into each other\n ! Array contents are intentionally oversized to show that a warning rather than an error is thrown\n\n INTEGER(KIND=1) :: array_i1_i1(6) = (/ ((256_1, j8=1_1, i8), i8=1_1, 3_1 ) /)\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 61}\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 61}\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 61}\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 61}\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 61}\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 61}\n INTEGER(KIND=1) :: array_i1_i2(6) = (/ ((257_2, j16=1_2, i16), i16=1_2, 3_2 ) /)\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 68}\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 68}\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 68}\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 68}\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 68}\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 68}\n INTEGER(KIND=1) :: array_i1_i4(6) = (/ ((257_4, j32=1_4, i32), i32=1_4, 3_4 ) /)\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 75}\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 75}\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 75}\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 75}\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 75}\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 75}\n INTEGER(KIND=1) :: array_i1_i8(6) = (/ ((257_8, j64=1_8, i64), i64=1_8, 3_8 ) /)\n\n INTEGER(KIND=2) :: array_i2_i1(6) = (/ ((256_1, j8=1_1, i8), i8=1_1, 3_1 ) /)\n INTEGER(KIND=2) :: array_i2_i2(6) = (/ ((65536_2, j16=1_2, i16), i16=1_2, 3_2 ) /)\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 85}\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 85}\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 85}\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 85}\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 85}\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 85}\n INTEGER(KIND=2) :: array_i2_i4(6) = (/ ((65537_4, j32=1_4, i32), i32=1_4, 3_4 ) /)\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 92}\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 92}\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 92}\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 92}\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 92}\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 92}\n INTEGER(KIND=2) :: array_i2_i8(6) = (/ ((65537_8, j64=1_8, i64), i64=1_8, 3_8 ) /)\n\n INTEGER(KIND=4) :: array_i4_i1(6) = (/ ((256_1, j8=1_1, i8), i8=1_1, 3_1 ) /)\n INTEGER(KIND=4) :: array_i4_i2(6) = (/ ((65536_2, j16=1_2, i16), i16=1_2, 3_2 ) /)\n INTEGER(KIND=4) :: array_i4_i4(6) = (/ ((4294967296_4, j32=1_4, i32), i32=1_4, 3_4 ) /)\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 103}\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 103}\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 103}\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 103}\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 103}\n !{warning \"PGF90-W-0128-Integer constant truncated to fit data type: 1\" 103}\n INTEGER(KIND=4) :: array_i4_i8(6) = (/ ((4294967297_8, j64=1_8, i64), i64=1_8, 3_8 ) /)\n\n INTEGER(KIND=8) :: array_i8_i1(6) = (/ ((256_1, j8=1_1, i8), i8=1_1, 3_1 ) /)\n INTEGER(KIND=8) :: array_i8_i2(6) = (/ ((65536_2, j16=1_2, i16), i16=1_2, 3_2 ) /)\n INTEGER(KIND=8) :: array_i8_i4(6) = (/ ((4294967296_4, j32=1_4, i32), i32=1_4, 3_4 ) /)\n INTEGER(KIND=8) :: array_i8_i8(6) = (/ ((4294967297_8, j64=1_8, i64), i64=1_8, 3_8 ) /)\n\n ! Integers initializing real arrays\n\n REAL(KIND=4) :: array_r4_i1(6) = (/ ((256_1, j8=1_1, i8), i8=1_1, 3_1 ) /)\n REAL(KIND=4) :: array_r4_i2(6) = (/ ((65536_2, j16=1_2, i16), i16=1_2, 3_2 ) /)\n REAL(KIND=4) :: array_r4_i4(6) = (/ ((4294967296_4, j32=1_4, i32), i32=1_4, 3_4 ) /)\n REAL(KIND=4) :: array_r4_i8(6) = (/ ((4294967297_8, j64=1_8, i64), i64=1_8, 3_8 ) /)\n\n REAL(KIND=8) :: array_r8_i1(6) = (/ ((256_1, j8=1_1, i8), i8=1_1, 3_1 ) /)\n REAL(KIND=8) :: array_r8_i2(6) = (/ ((65536_2, j16=1_2, i16), i16=1_2, 3_2 ) /)\n REAL(KIND=8) :: array_r8_i4(6) = (/ ((4294967296_4, j32=1_4, i32), i32=1_4, 3_4 ) /)\n REAL(KIND=8) :: array_r8_i8(6) = (/ ((4294967297_8, j64=1_8, i64), i64=1_8, 3_8 ) /)\n\n call check(array1, expect1, n)\n call check(array2, expect2, m)\n call check(array3, expect3, m*o)\n call check(array4, expect4, m*o*p)\n call check(array5, expect5, 3*m*o)\n\nEND PROGRAM stress_test_nested_implied_do\n", "meta": {"hexsha": "ee0602fdb29778623a981e900a2436ef2b82752b", "size": 7098, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/f90_correct/src/array_constructor_nested_implied_do.f90", "max_stars_repo_name": "abrahamtovarmob/flang", "max_stars_repo_head_hexsha": "bcd84b29df046b6d6574f0bfa34ea5059092615a", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 716, "max_stars_repo_stars_event_min_datetime": "2017-05-17T17:58:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T11:20:58.000Z", "max_issues_repo_path": "test/f90_correct/src/array_constructor_nested_implied_do.f90", "max_issues_repo_name": "abrahamtovarmob/flang", "max_issues_repo_head_hexsha": "bcd84b29df046b6d6574f0bfa34ea5059092615a", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 794, "max_issues_repo_issues_event_min_datetime": "2017-05-18T19:27:40.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T23:22:11.000Z", "max_forks_repo_path": "test/f90_correct/src/array_constructor_nested_implied_do.f90", "max_forks_repo_name": "abrahamtovarmob/flang", "max_forks_repo_head_hexsha": "bcd84b29df046b6d6574f0bfa34ea5059092615a", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 157, "max_forks_repo_forks_event_min_datetime": "2017-05-17T18:50:33.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T07:06:45.000Z", "avg_line_length": 55.023255814, "max_line_length": 100, "alphanum_fraction": 0.6258100873, "num_tokens": 3167, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933183101078, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.6605324487612773}} {"text": "! This routine propagates forward the inputs through a rectangular Artificial\n! Neural Network, and returns the result at the output nodes.\n! W(l, i, j) represents the synaptic strength from neuron j in the\n! layer l-1 to neuron i in layer l. Beta(l, i) is the bias added to the signal\n! in neuron i, layer l. nonlin(l) is an integer vector whose elements are 0 \n! if l is a linear layer, or 1 if l is a non-linear layer (tanh is then used\n! as activation function). input and output are the inputs and outputs vectors,\n! of size ninputs and noutputs, respectively. nperlayer is the number of\n! neurons per layer and nlayers is the number of layers (note: the input\n! is _NOT_ considered a layer). If the keyword Y is present, the\n! neuron values are returned.\n!\n! Note that nmaxperlayer _MUST BE_ larger than both ninputs and noutputs!!\n!\nSubroutine ANN_forward(W, Beta, Nonlin, Input, Output, nlayers, &\n nmaxperlayer, nperlayer, ninputs, noutputs, y)\nImplicit None\nReal (Kind=8), Parameter :: a=1.7159, b=0.666666, bovera=0.388523, asq=2.94431\n!Real (Kind=8), Parameter :: a=1., b=1., bovera=1., asq=1.\nInteger :: nlayers, nmaxperlayer, ninputs, noutputs, i, j, k, l\nInteger, Dimension(nlayers) :: Nonlin\nInteger, Dimension(0:nlayers) :: nperlayer\nReal (Kind=8), Dimension(nlayers, nmaxperlayer, nmaxperlayer) :: W\nReal (Kind=8), Dimension(0:nlayers, nmaxperlayer) :: y\nReal (Kind=8), Dimension(nlayers, nmaxperlayer) :: Beta\nReal (Kind=8), Dimension(ninputs) :: Input\nReal (Kind=8), Dimension(noutputs) :: Output\n!\n! Set input values\n!\ny(0, 1:ninputs)=Input(1:ninputs)\n!\n! Propagate forward\n!\nDo l=1, nlayers\n!\n! Do the matrix multiplications using the intrinsic F90 function\n!\n! y(l, 1:nperlayer(l))=Matmul(W(l, 1:nperlayer(l), 1:nperlayer(l-1)), &\n! y(l-1, 1:nperlayer(l-1)))+Beta(l, 1:nperlayer(l))\n!\n! Spell out the matrix multiplications (some compilers have trouble\n! optimizing this function)\n!\n Do j=1, nperlayer(l)\n y(l, j)=0.\n Do k=1, nperlayer(l-1)\n y(l, j)=y(l, j)+W(l, j, k)*y(l-1, k)\n End do\n y(l, j)=y(l, j)+Beta(l, j)\n End do\n!\n If (Nonlin(l) .ne. 0) & ! It's a non-linear layer\n y(l, 1:nperlayer(l))=a*Tanh(b*y(l, 1:nperlayer(l)))\nEnd do\n!\n! Network output\n!\nOutput(1:noutputs)=y(nlayers, 1:noutputs)\n!\n! Done\n!\nReturn\n!\nEnd Subroutine ANN_forward\n", "meta": {"hexsha": "5c702907661c1f95ecb9c0f2adcfb1e67ab8a981", "size": 2326, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "inversor/database/NICOLE/forward/ann/ANN_forward.f90", "max_stars_repo_name": "aasensio/DeepLearning", "max_stars_repo_head_hexsha": "71838115ce93e0ca96c8314cff3f07de1d64c235", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "inversor/database/NICOLE/forward/ann/ANN_forward.f90", "max_issues_repo_name": "aasensio/DeepLearning", "max_issues_repo_head_hexsha": "71838115ce93e0ca96c8314cff3f07de1d64c235", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "inversor/database/NICOLE/forward/ann/ANN_forward.f90", "max_forks_repo_name": "aasensio/DeepLearning", "max_forks_repo_head_hexsha": "71838115ce93e0ca96c8314cff3f07de1d64c235", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.2424242424, "max_line_length": 79, "alphanum_fraction": 0.6908856406, "num_tokens": 761, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122238669025, "lm_q2_score": 0.7279754548076477, "lm_q1q2_score": 0.6605010288220465}} {"text": "module user_interface\r\n\r\n\tuse rhs\t\r\n\timplicit none\r\n\t\r\n\t! file name : general system parameters\r\n\tcharacter (len = 20) :: filename1, filename2, filename3\r\n\r\n\t!inital conditions\r\n\r\ncontains\r\n\r\n\tsubroutine read_inputfile()\r\n\r\n\t implicit none\r\n\t integer :: i, j, numb_dx\r\n double precision :: dpg1, segmag1, dpg2, segmag2, dp_same, &\r\n sum_ync, fi, delta_dp, dp1, dp2\r\n \r\n dpg1 = 1e-9\r\n segmag1 = 1.2\r\n dpg2 = 3e-9\r\n segmag2 = 1.2\r\n dp_same = 1.7321e-9 !the same diameter for bi-lognormal distribution\r\n \r\n numb_dx = 100\r\n \r\n\t open(unit = 1234, file = \"input.txt\", status =\"old\")\r\n\t\r\n\t !reading info from file\r\n read(1234,*)flag\r\n\t read(1234,*)n_discrete\t\r\n\t read(1234,*)mw, rho, dp0\r\n v0 = (pi/6)*(dp0)**3\r\n\t \r\n !allocate(nc0(n_discrete))\r\n\t !allocate(nc(n_discrete))\r\n\t allocate(ync(n_discrete))\r\n allocate(dp_dis(n_discrete)) !Huang Zhang, 2018\r\n\t\t allocate(atol(n_discrete))\r\n \t\r\n\t\t neq = n_discrete\r\n \r\n do i = 1, n_discrete\t\r\n \r\n dp_dis(i) = (i*v0*6.0/PI)**(1.0/3)\r\n if (dp_dis(i) > dp_same) then \r\n \r\n fi = get_lognormal(dp_dis(i)*1e+9, dpg2*1e+9, segmag2)\r\n dp1 = dp_dis(i)*1e+9 !nm\r\n dp2 = ((i+1)*v0*6.0/PI)**(1.0/3)*1e+9 !nm\r\n ync(i) = get_prob_lognormal(dp1, dp2, numb_dx, dpg2*1e+9, segmag2)\r\n \r\n else\r\n \r\n fi = get_lognormal(dp_dis(i)*1e+9, dpg1*1e+9, segmag1)\r\n dp1 = dp_dis(i)*1e+9 !nm\r\n dp2 = ((i+1)*v0*6.0/PI)**(1.0/3)*1e+9 !nm\r\n ync(i) = get_prob_lognormal(dp1, dp2, numb_dx, dpg1*1e+9, segmag1)\r\n \r\n end if\r\n \r\n end do\r\n !ync(1:n_discrete) = 0.0\r\n !ync(1) = 1.0\r\n sum_ync = sum(ync)\r\n \r\n write(*,*)'dp_dis(end) = (nm)'\r\n write(*, '(D12.4)') dp_dis(n_discrete)*1e+9\r\n\t \r\n\t\t read(1234,*)N_infi_0\r\n read(1234,*) tf\r\n read(1234,*) dt\r\n read(1234,*) N_track_min\r\n \r\n atol(1:n_discrete) = 0.1*N_track_min/N_infi_0\r\n !rtol = 10**-(log10(N_infi_0/N_track_min) + 1)\r\n rtol = 10**(-(log10(N_infi_0/N_track_min) + 1))\r\n \r\n\t close(unit = 1234)\r\n\r\n end subroutine read_inputfile\r\n\t\r\n function get_lognormal(x, x0, sg0)\r\n \r\n implicit none\r\n \r\n double precision :: get_lognormal\r\n double precision, intent (in) :: x, x0, sg0\r\n get_lognormal = 1/((2*PI)**0.5*x*log(sg0))* &\r\n exp(-(log(x)-log(x0))**2/(2*(log(sg0))**2))\r\n return\r\n \r\n end function get_lognormal\r\n \r\n function get_prob_lognormal(x_begin, x_end, numb_dx, x0, sg0)\r\n \r\n implicit none \r\n integer :: i_dx\r\n integer, intent (in) :: numb_dx\r\n double precision, intent (in) :: x_begin, x_end, x0, sg0\r\n double precision :: get_prob_lognormal, x1, x2, dx\r\n dx = (x_end - x_begin)/numb_dx\r\n \r\n get_prob_lognormal = 0.\r\n x1 = x_begin\r\n do i_dx = 1, numb_dx\r\n \r\n x2 = x1 + dx\r\n get_prob_lognormal = get_prob_lognormal + (get_lognormal(x2, x0, sg0) + get_lognormal(x1, x0, sg0))*dx/2\r\n x1 = x2\r\n \r\n end do\r\n \r\n return \r\n \r\n end function get_prob_lognormal\r\n \r\nend module user_interface\r\n \r\n \r\n!program test_user_interface\r\n! use user_interface \r\n! implicit none\r\n! \r\n! call read_inputfile()\r\n! print*, nc0\r\n! \r\n!end program test_user_interface\r\n\r\n \r\n\r\n\t\r\n\r\n\t\r\n\r\n\t\r\n", "meta": {"hexsha": "4684ebdb362a15be188a9c2fdc6c48feaa3cb9d6", "size": 3814, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "purecoag_bi-lognormal/user_interface.f90", "max_stars_repo_name": "chengzhanghuang87/aerosol_dynamic_models", "max_stars_repo_head_hexsha": "14984f57659806ff5122df413c299c58e2c94bdc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "purecoag_bi-lognormal/user_interface.f90", "max_issues_repo_name": "chengzhanghuang87/aerosol_dynamic_models", "max_issues_repo_head_hexsha": "14984f57659806ff5122df413c299c58e2c94bdc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "purecoag_bi-lognormal/user_interface.f90", "max_forks_repo_name": "chengzhanghuang87/aerosol_dynamic_models", "max_forks_repo_head_hexsha": "14984f57659806ff5122df413c299c58e2c94bdc", "max_forks_repo_licenses": ["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.6376811594, "max_line_length": 113, "alphanum_fraction": 0.4837441007, "num_tokens": 1149, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122213606241, "lm_q2_score": 0.727975443004307, "lm_q1q2_score": 0.6605010162882222}} {"text": "program langtons_ant\n implicit none\n\n integer, parameter :: dp = selected_real_kind(15,300)\n real(kind=dp), parameter :: pi = 3.1415926535897932_dp\n\n integer, parameter :: grid_size = 100\n integer, dimension(:,:), allocatable :: grid\n integer, dimension(3) :: ant = (/ grid_size/2, grid_size/2, 0 /)\n integer :: i\n\n allocate(grid(1:grid_size, 1:grid_size))\n grid = 1 !Grid initially white\n\n do\n grid(ant(1) , ant(2)) = -grid(ant(1) , ant(2)) ! Flip the color of the current square\n ant(3) = modulo(ant(3) + grid(ant(1),ant(2)),4) ! Rotate the ant depending on the current square\n ant(1) = ant(1) + nint( sin(ant(3) * pi / 2.0_dp) ) ! Move the ant in x\n ant(2) = ant(2) + nint( cos(ant(3) * pi / 2.0_dp) ) ! Move the ant in y\n\n !exit if the ant is outside the grid\n if (((ant(1) < 1) .or. (ant(1) > grid_size)) .or. ((ant(2) < 1) .or. (ant(2) > grid_size))) exit\n\n end do\n\n !Print out the final grid\n open(unit=21, file=\"ant.dat\")\n do i = 1, grid_size\n write(21,*) int(grid(:,i) + 1 / 2.0_dp)\n end do\n close(21)\n\n deallocate(grid)\n\nend program langtons_ant\n", "meta": {"hexsha": "ae7b4428242ece73dfdd601bc6a551b2cbbe2ee4", "size": 1189, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Langtons-ant/Fortran/langtons-ant.f", "max_stars_repo_name": "djgoku/RosettaCodeData", "max_stars_repo_head_hexsha": "91df62d46142e921b3eacdb52b0316c39ee236bc", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Task/Langtons-ant/Fortran/langtons-ant.f", "max_issues_repo_name": "djgoku/RosettaCodeData", "max_issues_repo_head_hexsha": "91df62d46142e921b3eacdb52b0316c39ee236bc", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Langtons-ant/Fortran/langtons-ant.f", "max_forks_repo_name": "djgoku/RosettaCodeData", "max_forks_repo_head_hexsha": "91df62d46142e921b3eacdb52b0316c39ee236bc", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.0277777778, "max_line_length": 104, "alphanum_fraction": 0.5710681245, "num_tokens": 416, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.727975443004307, "lm_q1q2_score": 0.6605010162882221}} {"text": "!==============================================================================!\n subroutine Compute_Eigenvalues(a,n,np,d,v,nrot) \n!------------------------------------------------------------------------------!\n implicit none\n!-----------------------------------[Locals]-----------------------------------!\n integer, parameter :: NMAX=500\n integer :: n,np,nrot\n integer :: i,ip,iq,j \n real :: a(np,np),d(np),v(np,np) \n real :: c,g,h,s,sm,t,tau,theta,tresh,b(NMAX),z(NMAX) \n!------------------------------------------------------------------------------!\n! Uses Jacobi algorithm to computes eigenvalues and eigenvectors of a real !\n! symmetric matrix a, which is of size n by n, stored in a physical np by !\n! np array. On output, elements of a above the diagonal are destroyed. !\n! d returns the eigenvalues of a in its rst n elements. v is a matrix with !\n! the same logical and physical dimensions as a, whose columns contain, on !\n! output, the normalized eigenvectors of a. nrot returns the number of !\n! Jacobi rotations that were required. !\n!==============================================================================!\n\n do ip=1,n ! initialize to the identity matrix. \n do iq=1,n \n v(ip,iq)=0. \n end do \n v(ip,ip)=1. \n end do \n\n do ip=1,n \n b(ip)=a(ip,ip) ! initialize b and d to the diagonal of a. \n d(ip)=b(ip) \n z(ip)=0. ! this vector will accumulate terms of the form \n ! tapq as in equation (11.1.14). \n end do \n\n nrot=0 \n do i=1,50 \n\n sm=0. \n do ip=1,n-1 ! sum o -diagonal elements. \n do iq=ip+1,n \n sm=sm+abs(a(ip,iq)) \n end do \n end do \n if(sm.eq.0.) return ! the normal return, which relies on quadratic \n ! convergence to machine under ow. \n if(i.lt.4) then \n tresh=0.2*sm/n**2 ! ...on the rst three sweeps. \n else \n tresh=0. ! ...thereafter. \n endif \n\n do ip=1,n-1 \n do iq=ip+1,n \n g=100.*abs(a(ip,iq)) ! after four sweeps, skip the rotation if the \n ! offdiagonal element is small. \n if((i.gt.4).and.(abs(d(ip))+g.eq.abs(d(ip))) &\n .and.(abs(d(iq))+g.eq.abs(d(iq)))) then \n a(ip,iq)=0. \n else if(abs(a(ip,iq)).gt.tresh) then \n h=d(iq)-d(ip) \n if(abs(h)+g.eq.abs(h)) then\n t=a(ip,iq)/h ! t = 1/(2 theta) \n else \n theta=0.5*h/a(ip,iq) ! equation (11.1.10). \n t=1./(abs(theta)+sqrt(1.+theta**2)) \n if(theta.lt.0.) t=-t \n endif \n c=1./sqrt(1+t**2) \n s=t*c \n tau=s/(1.+c) \n h=t*a(ip,iq) \n z(ip)=z(ip)-h \n z(iq)=z(iq)+h \n d(ip)=d(ip)-h \n d(iq)=d(iq)+h \n a(ip,iq)=0. \n do j=1,ip-1 ! case of rotations 1 j rsp\nimplicit none\n\nlogical,private,save::pri_lin_eqn=.true.\n\ncontains\n\n\nsubroutine lin_eqns_solver(a_ij,phi,rhs,norm,ja,ia,n_iter,reduc,isol,id)\n use matrix_utils_m\n use vector_utils_m\n\n real(rp),dimension(:), intent(in)::a_ij\n real(rp),dimension(:), intent(inout)::phi\n real(rp),dimension(:), intent(inout)::rhs\n real(rp), intent(inout)::norm\n real(rp), intent(in)::reduc\n integer,dimension(:), intent(in)::ja,ia\n integer, intent(in)::n_iter\n integer, intent(in)::isol,id\n\n select case(isol)\n case(1)\n call cg_solver(a_ij,phi,rhs,norm,ja,ia,n_iter,reduc)\n case (2)\n call bicg_solver(a_ij,phi,rhs,norm,ja,ia,n_iter,reduc)\n end select\nend subroutine\n\n\nsubroutine cg_solver(a_ij,phi,res,norm,ja,ia,n_iter,reduc)\n use constants_m\n use matrix_utils_m\n use vector_utils_m\n\n real(rp),dimension(:), intent(in)::a_ij\n real(rp),dimension(:), intent(inout)::phi\n real(rp),dimension(:), intent(inout)::res\n real(rp), intent(inout)::norm\n real(rp), intent(in)::reduc\n integer,dimension(:), intent(in)::ja,ia\n integer, intent(in)::n_iter\n\n real(rp),dimension(size(ia)-1,6)::wk\n real(rp),dimension(6)::cof\n real(rp)::norm0\n integer,parameter::p=1\n integer::i,kii,j,kij,kji,iter\n\n ! calculate residual vector and norm\n call csr_matvec_prod(a_ij,phi,ja,ia,wk(:,1))\n res=res-wk(:,1)\n norm=p_norm(res,p)\n norm0=norm\n\n ! calculate preconditioning vector: C = M^{-1}\n call preconditioner(a_ij,ja,ia,wk(:,6))\n\n ! cof: res_n=1 alpha=2 beta=3 s=4\n cof=0; cof(4)=large\n\n ! wk: res=1 p=2 z=3\n wk(:,1)=res\n wk(:,2:3)=0\n\n\n ! iterate:\n do iter=1,n_iter\n cof(1)=0\n\n ! solve: M z = res\n call direct_solve(a_ij,wk(:,6),wk(:,1),ja,ia,wk(:,3))\n\n ! beta = 1 / s\n cof(3)=one/(cof(4)+small)\n\n ! s = p.dot.z\n cof(4)=sum(wk(:,1)*wk(:,3))\n\n ! beta = beta * s\n cof(3)=cof(3)*cof(4)\n\n ! p = z + beta.p\n wk(:,2)=wk(:,3)+cof(3)*wk(:,2)\n\n ! calculate: z = A.p\n call csr_matvec_prod(a_ij,wk(:,2),ja,ia,wk(:,3))\n\n ! alpha = s / p.dot.z\n cof(2)=sum(wk(:,2)*wk(:,3))\n cof(2)=cof(4)/(cof(2)+small)\n\n ! phi = phi + alpha.p\n ! res = res - alpha.z\n ! res_n = sum |res|\n phi=phi+cof(2)*wk(:,2)\n wk(:,1)=wk(:,1)-cof(2)*wk(:,3)\n norm=p_norm(wk(:,1),p)\n\n ! res_n = res_n / res0_n\n cof(1)=norm/(norm0+small)\n if(cof(1)i)then\n summ=summ-a_ij(kij)*x(j)\n else\n exit\n end if\n end do\n x(i)=summ*c(i)\n end do\nend subroutine\n\nend module\n", "meta": {"hexsha": "99496bba1ee3ab5752c83808573db566949a42e7", "size": 6093, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/solv_m.f90", "max_stars_repo_name": "DominicJones/pcns", "max_stars_repo_head_hexsha": "8097d78d190066cab82c64b96076c37a539efb92", "max_stars_repo_licenses": ["MIT"], "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/solv_m.f90", "max_issues_repo_name": "DominicJones/pcns", "max_issues_repo_head_hexsha": "8097d78d190066cab82c64b96076c37a539efb92", "max_issues_repo_licenses": ["MIT"], "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/solv_m.f90", "max_forks_repo_name": "DominicJones/pcns", "max_forks_repo_head_hexsha": "8097d78d190066cab82c64b96076c37a539efb92", "max_forks_repo_licenses": ["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.8664383562, "max_line_length": 72, "alphanum_fraction": 0.5893648449, "num_tokens": 2306, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632976542185, "lm_q2_score": 0.7122321903471563, "lm_q1q2_score": 0.660497992735826}} {"text": "\tFUNCTION XPADC(F)\nC\nC\tTHIS FUNCTION RETURNS THE GAIN OF THE DC CHANNEL OF THE WIND X PREAMP\nC\tTHE FUNCTION ITSELF RETURNS THE MAGNITUDE OF THE GAIN, AND THE PHASE\nC\tAND THE COMPLEX GAIN ARE RETURNED IN A COMMON BLOCK\nC\n\tCOMMON /GAINBLK/ PHASE,CGAIN \t\t ! PHASE IS IN RADIANS\n\tCOMMON /COMPBLK/ CVAR(5)\nC\n\tCOMPLEX CGAIN,Y1,Z1,Y2,Z2\n\tDATA R9,C9,R10,CINP /5.E8, 23.6E-12, 5.E8, 4.37E-12/\n\tDATA R33,C16 /2.2E+03, 1.203E-9/\n\tDATA R1C,R2C,CCOMP / 0., 4.64E3, .947E-6/ ! as shown on drawing\nC\tDATA R1C,R2C,CCOMP / 0., 5.E3, .947E-6/\n\tDATA R5 /22.1E3/\n\tDATA TWOPI /6.2831853/\nC\nC\tC16 = 1.203E-9 ! ADJUSTING EX\nC\tC9 = 23.6E-12 ! ADJUSTING EX\nC\tCINP = 4.37E-12 ! ADJUSTING EX\nC\nC\tC16 = CVAR(1)\nC\tC9 = CVAR(2)\nC\tCINP = CVAR(3)\nC\n\tW = TWOPI*F\n\tCGAIN = 1.\nC\tDIVISION OF SIGNAL BEFORE FOLLOWER\n\tY1 = CMPLX(1./R9,W*C9)\n\tY2 = CMPLX(1./R10,W*CINP)\n\tZ1 = 1./Y1\n\tZ2 = 1./Y2\n\tCGAIN = CGAIN*Z2/(Z1+Z2)\nC\tEFFECT OF OUTPUT RC\n\tWC16 = 1./(W*C16)\nC\tPRINT*,'W,Z1,WC16',W,Z1,WC16\nC\tPRINT*,'F,CGAIN,PHASE\n\tCGAIN = CGAIN*CMPLX(0.,-WC16)/CMPLX(R33,-WC16)\nC***************** effect of compensation\nC\nC\tEFFECT OF INPUT (211) BOARD\nC\n\tWCC = W*CCOMP\n\tZ2 = CMPLX(R2C,-1./WCC)\t\n\tY1 = 1./R5 + 1./(R1C + Z2) + CMPLX(0.,W*C16)\t\n\tCGAIN = CGAIN*(Z2/(R1C+Z2))/(1. + R33*Y1)\nC*************\nC\n\tGNIP = AIMAG(CGAIN)\n\tGNRP = CGAIN\n\tPHASE = ATAN2(GNIP,GNRP)\n\tXPADC = CABS(CGAIN)\n\tRETURN\n\tEND\n\n", "meta": {"hexsha": "2f9846abdeab20ba04054ee953ff01444e872a0b", "size": 1438, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/xpadc_13.for", "max_stars_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_stars_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/xpadc_13.for", "max_issues_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_issues_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/xpadc_13.for", "max_forks_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_forks_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.6785714286, "max_line_length": 71, "alphanum_fraction": 0.6015299026, "num_tokens": 667, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632976542184, "lm_q2_score": 0.7122321720225278, "lm_q1q2_score": 0.6604979757422379}} {"text": "Real Function ppk1(srt)\n Real xarray(7), earray(7)\n Save\n Data xarray/0.013, 0.025, 0.016, 0.012, 0.017, 0.029, 0.025/\n Data earray/3.67, 4.95, 5.52, 5.97, 6.05, 6.92, 7.87/\n pmass = 0.9383\n ppk1 = 0.\n If (srt<=2.63) Return\n If (srt>4.08) Then\n ppk1 = 0.025\n Return\n End If\n plab = sqrt(((srt**2-2.*pmass**2)/(2.*pmass))**2-pmass**2)\n If (plabplab) Then\n ymin = alog(xarray(ie-1))\n ymax = alog(xarray(ie))\n xmin = alog(earray(ie-1))\n xmax = alog(earray(ie))\n ppk1 = exp(ymin+(alog(plab)-xmin)*(ymax-ymin)/(xmax-xmin))\n Goto 10\n End If\n End Do\n10 Continue\n Return\nEnd Function ppk1\n", "meta": {"hexsha": "3c7af15d3036b9880ba5c5ed72708e148954d411", "size": 822, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/ppk1.f90", "max_stars_repo_name": "xiaohaijin/AMPT", "max_stars_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-12-24T19:37:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-14T12:58:59.000Z", "max_issues_repo_path": "src/ppk1.f90", "max_issues_repo_name": "xiaohaijin/AMPT", "max_issues_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_issues_repo_licenses": ["MIT"], "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/ppk1.f90", "max_forks_repo_name": "xiaohaijin/AMPT", "max_forks_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_forks_repo_licenses": ["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.1764705882, "max_line_length": 66, "alphanum_fraction": 0.5559610706, "num_tokens": 368, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587817066391, "lm_q2_score": 0.7431680199891789, "lm_q1q2_score": 0.6604971040489179}} {"text": "program constantsex\nimplicit none \nreal,parameter :: g = 9.81\nreal:: s ! displacement\nreal:: t ! time\nreal:: u ! initial speed\n\nt = 2.0\nu = 10.01\n\ns = u*t -g*(t**2)/2\nprint*,\"time =\",t\nprint*, \"displacement =\",s\nprint*,\"initial speed =\",u\nendprogram constantsex\n", "meta": {"hexsha": "03fc4d66b8ac562b3659963d0dffc7a85d806d57", "size": 262, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "constants/constants.f90", "max_stars_repo_name": "akkiturb/Ilkay-s-Fortran-Class", "max_stars_repo_head_hexsha": "0600640574354052a5a7d87bad520b8a03650d0e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-12-18T19:31:01.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-18T19:31:01.000Z", "max_issues_repo_path": "constants/constants.f90", "max_issues_repo_name": "akkiturb/Scientific-computing-in-Fortran", "max_issues_repo_head_hexsha": "0600640574354052a5a7d87bad520b8a03650d0e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "constants/constants.f90", "max_forks_repo_name": "akkiturb/Scientific-computing-in-Fortran", "max_forks_repo_head_hexsha": "0600640574354052a5a7d87bad520b8a03650d0e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-02-04T19:45:56.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-10T14:22:05.000Z", "avg_line_length": 16.375, "max_line_length": 26, "alphanum_fraction": 0.6564885496, "num_tokens": 92, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8887587934924569, "lm_q2_score": 0.7431680086124812, "lm_q1q2_score": 0.6604971026966207}} {"text": " subroutine sort2(n, ra, rb)\nc heap sort real array ra of length n to ascending order,\nc and make the corresponding rearrangement to rb.\n implicit none\n integer n, l, ir, i, j\n double precision ra(*), rb(*), xa, xb\n l = n / 2 + 1\n ir = n\nc heap creation phase\nc index l is decremented from its initial value down to 1\n 10 continue\n if (l.gt.1) then\n l = l - 1\n xa = ra(l)\n xb = rb(l)\nc heap selection phase\nc index ir is decremented from its initial value to to 1\n else\n xa = ra(ir)\n xb = rb(ir)\n ra(ir) = ra(1)\n rb(ir) = rb(1)\n ir = ir - 1\n if (ir.eq.1) then\n ra(1) = xa\n rb(1) = xb\n go to 50\n end if\n end if\nc sift down xa\n i = l\n j = l + l\n 20 continue\n if (j.le.ir) then\nc found better low element\n if ((j.lt.ir).and.(ra(j).lt.ra(j+1))) j = j + 1\nc demote xa\n if (xa.lt.ra(j)) then\n ra(i) = ra(j)\n rb(i) = rb(j)\n i = j\n j = j + j\n else\n j = ir + 1\n end if\nc ends the sift-down\n go to 20\n end if\nc restore xa and xb\n ra(i) = xa\n rb(i) = xb\n go to 10\nc return\n 50 continue\n\n return\nc end subroutine sort2\n end\n integer function sort_xy(e, x, n, delta)\nc\nc check and sort a pair of energy/xmu data to \nc ensure that energy is monotonically increasing\nc\nc returns 0 for data that needs no sort or rearrangement\nc 1 if sorting or rearrangement were needed\n\n implicit none\n double precision e(*), x(*), de, delta, dm\n integer n, i, k, j\n logical sort, near\n\n near = .false.\n sort = .false.\ncc print*, ' in sort_xy '\nc first, look for problems\n do 10 i = 1, n-1\n de = e(i+1)-e(i)\n if (de.lt.0) sort = .true.\n 10 continue \nc\ncc print*, ' in sort_xy ', sort, near\n\nc if needed, sort\n if (sort) call sort2(n, e, x)\nc\nc if needed, handle coincident x points\nc by slightly incrementing values\n do 100 i = 1, n-1\n de = e(i+1)-e(i)\n if (abs(de).lt.delta) then\n near = .true.\n dm = delta*10.d0\n if (i .eq. n-1.and.i.ge.2) then\n dm = max(delta,(e(i)-e(i-1))*0.01d0)\n else\n dm = max(delta,(e(i+2)-e(i))*0.01d0)\n endif\n e(i+1) = e(i) + dm\ncc print*, ' moving energy point ', i, e(i+1)\n endif\n 100 continue \n sort_xy = 0\n if (sort.or.near) sort_xy = 1\n return \n end\n\n\n\n\n", "meta": {"hexsha": "e488f81c2bd0b384662b3c26c3012571c47cac62", "size": 2688, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/lib/sort2.f", "max_stars_repo_name": "keechul/ifeffit", "max_stars_repo_head_hexsha": "306444e500cb3ecb1795fcbde9219369b003f1fa", "max_stars_repo_licenses": ["Naumen", "Condor-1.1", "MS-PL"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2017-09-16T12:41:43.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-08T05:17:16.000Z", "max_issues_repo_path": "src/lib/sort2.f", "max_issues_repo_name": "bruceravel/ifeffit", "max_issues_repo_head_hexsha": "97f6458584e237a6a9e3681bb9b604c9d1ec9743", "max_issues_repo_licenses": ["Naumen", "Condor-1.1", "MS-PL"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-07-20T01:15:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-20T02:09:08.000Z", "max_forks_repo_path": "src/lib/sort2.f", "max_forks_repo_name": "bruceravel/ifeffit", "max_forks_repo_head_hexsha": "97f6458584e237a6a9e3681bb9b604c9d1ec9743", "max_forks_repo_licenses": ["Naumen", "Condor-1.1", "MS-PL"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-03-22T19:27:11.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-23T07:47:31.000Z", "avg_line_length": 24.4363636364, "max_line_length": 57, "alphanum_fraction": 0.4858630952, "num_tokens": 828, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318196, "lm_q2_score": 0.743167997235783, "lm_q1q2_score": 0.6604970991546115}} {"text": "module maths\r\nuse hamiltonian_types\r\nimplicit none\r\ncontains\r\n\r\n!----------------------------------------------------------------------\r\n!----------------------------------------------------------------------\r\n! Jacobi diagonalization of a symmetric real matrix\r\n!----------------------------------------------------------------------\r\n!----------------------------------------------------------------------\r\n\r\n\tsubroutine jacobi(a,d,v,nrot)\r\n\t\treal(kind=8) :: a(:,:), d(:), v(:,:)\r\n\t\tinteger :: nrot\r\n\t\r\n\t\tinteger :: i, ip, iq, j, n\r\n\t\treal(kind=8) :: c, g, h, s, sm, t, tau, theta, thres, b(size(d)), z(size(d))\r\n\t\t\r\n\t\tn = size(d)\r\n\t\t\r\n\t\tv = 0.d0\r\n\t\tdo i = 1, n\r\n\t\t\tv(i,i) = 1.d0\r\n\t\tenddo\r\n\r\n\t\tdo ip = 1, n\r\n\t\t\tb(ip) = a(ip,ip)\r\n\t\t\td(ip) = b(ip)\r\n\t\t\tz(ip) = 0.d0\r\n\t\tenddo\r\n\r\n\t\tnrot = 0\r\n\r\n\t\tdo i = 1, 50\r\n\t\t\tsm = 0.d0\r\n\t\t\tdo ip = 1, n-1\r\n\t\t\t\tdo iq = ip+1,n\r\n\t\t\t\t\tsm = sm + abs(a(ip,iq))\r\n\t\t\t\tenddo\r\n\t\t\tenddo\r\n\t\t\tif (sm == 0.d0) return\r\n\t\t\tif (i < 4) then\r\n\t\t\t\tthres = 0.2d0 * sm / n**2\r\n\t\t\telse\r\n\t\t\t\tthres = 0.d0\r\n\t\t\tendif\r\n\t\t\tdo ip = 1, n-1\r\n\t\t\t\tdo iq = ip+1,n\r\n\t\t\t\t\tg = 100.d0 * abs(a(ip,iq))\r\n\t\t\t\t\tif ( (i>4) .and. (abs(d(ip))+g == abs(d(ip))) .and. (abs(d(iq))+g == abs(d(iq))) ) then\r\n\t\t\t\t\t\ta(ip,iq) = 0.d0\r\n\t\t\t\t\telse if (abs(a(ip,iq)) > thres ) then\r\n\t\t\t\t\t\th = d(iq) - d(ip)\r\n\t\t\t\t\t\tif (abs(h)+g == abs(h)) then\r\n\t\t\t\t\t\t\tt = a(ip,iq) / h\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\ttheta = 0.5d0 * h / a(ip,iq)\r\n\t\t\t\t\t\t\tt = 1.d0 / (abs(theta)+sqrt(1.d0+theta**2))\r\n\t\t\t\t\t\t\tif (theta < 0.d0) t = -t\r\n\t\t\t\t\t\tendif\r\n\t\t\t\t\t\tc = 1.d0 / sqrt(1.d0+t**2)\r\n\t\t\t\t\t\ts = t*c\r\n\t\t\t\t\t\ttau = s / (1.d0+c)\r\n\t\t\t\t\t\th = t * a(ip,iq)\r\n\t\t\t\t\t\tz(ip) = z(ip)-h\r\n\t\t\t\t\t\tz(iq) = z(iq)+h\r\n\t\t\t\t\t\td(ip) = d(ip)-h\r\n\t\t\t\t\t\td(iq) = d(iq)+h\r\n\t\t\t\t\t\ta(ip,iq) = 0.d0\r\n\t\t\t\t\t\tdo j = 1, ip-1\r\n\t\t\t\t\t\t\tg = a(j,ip)\r\n\t\t\t\t\t\t\th = a(j,iq)\r\n\t\t\t\t\t\t\ta(j,ip) = g - s*(h+g*tau)\r\n\t\t\t\t\t\t\ta(j,iq) = h + s*(g-h*tau)\r\n\t\t\t\t\t\tenddo\r\n\t\t\t\t\t\tdo j = ip+1, iq-1\r\n\t\t\t\t\t\t\tg = a(ip,j)\r\n\t\t\t\t\t\t\th = a(j,iq)\r\n\t\t\t\t\t\t\ta(ip,j) = g - s*(h+g*tau)\r\n\t\t\t\t\t\t\ta(j,iq) = h + s*(g-h*tau)\r\n\t\t\t\t\t\tenddo\r\n\t\t\t\t\t\tdo j = iq+1, n\r\n\t\t\t\t\t\t\tg = a(ip,j)\r\n\t\t\t\t\t\t\th = a(iq,j)\r\n\t\t\t\t\t\t\ta(ip,j) = g - s*(h+g*tau)\r\n\t\t\t\t\t\t\ta(iq,j) = h + s*(g-h*tau)\r\n\t\t\t\t\t\tenddo\r\n\t\t\t\t\t\tdo j = 1, n\r\n\t\t\t\t\t\t\tg = v(j,ip)\r\n\t\t\t\t\t\t\th = v(j,iq)\r\n\t\t\t\t\t\t\tv(j,ip) = g - s*(h+g*tau)\r\n\t\t\t\t\t\t\tv(j,iq) = h + s*(g-h*tau)\r\n\t\t\t\t\t\tenddo\r\n\t\t\t\t\t\tnrot = nrot+1\r\n\t\t\t\t\tendif\r\n\t\t\t\tenddo\r\n\t\t\tenddo\r\n\t\t\tdo ip = 1, n\r\n\t\t\t\tb(ip) = b(ip)+z(ip)\r\n\t\t\t\td(ip) = b(ip)\r\n\t\t\t\tz(ip) = 0.d0\r\n\t\t\tenddo\r\n\t\tenddo\r\n\r\n\tend subroutine jacobi\r\n\r\n!----------------------------------------------------------------------\r\n!----------------------------------------------------------------------\r\n! Wigner 3-j symbol\r\n!----------------------------------------------------------------------\r\n!----------------------------------------------------------------------\r\n\tfunction w3js(j1,j2,j3,m1,m2,m3)\r\n\t\tinteger :: m1, m2, m3, j1, j2, j3\r\n\t\tinteger :: ia, ib, ic, id, ie, im, ig, ih, z, zmin, zmax, jsum\r\n\t\treal(kind=8) :: w3js, denom, cc, cc1, cc2\r\n\t\tcomplex(kind=8) :: ccc, cccc\r\n\r\n \tw3js = 0.d0\r\n \tif (m1+m2+m3 /= 0) goto 1000\r\n \tia = j1 + j2\r\n \tif (j3 > ia) goto 1000\r\n \tib = j1 - j2\r\n \tif (j3 < abs(ib)) goto 1000\r\n \tjsum = j3 + ia\r\n \tic = j1 - m1\r\n \tid = j2 - m2\r\n\r\n \tif (abs(m1) > j1) goto 1000\r\n\t\t\tif (abs(m2) > j2) goto 1000\r\n\t\t\tif (abs(m3) > j3) goto 1000\r\n\t\t\tie = j3 - j2 + m1\r\n\t\t\tim = j3 - j1 - m2\r\n\t\t\tzmin = max0(0,-ie,-im)\r\n\t\t\tig = ia - j3\r\n\t\t\tih = j2 + m2\r\n\t\t\tzmax = min0(ig,ih,ic)\r\n\t\t\t\r\n\t\t\tccc = 0.d0\r\n\t\t\tdenom = fact2(zmin/2) + fact2((ig-zmin)/2) + fact2((ic-zmin)/2) + fact2((ih-zmin)/2) + &\r\n\t\t\t\t\tfact2((ie+zmin)/2) + fact2((im+zmin)/2) \r\n\t\t\t\r\n\t\t\tif (mod(zmin,4) /= 0) then\r\n\t\t\t\tcccc = -1.d0\r\n\t\t\t\tccc = -denom + log(cccc)\r\n\t\t\telse\r\n\t\t\t\tccc = -denom\r\n\t\t\tendif\t\t\t\r\n\r\n\t\t\tdo z = zmin+2, zmax, 2\r\n\t\t\t\tdenom = fact2(z/2) + fact2((ig-z)/2) + fact2((ic-z)/2) + fact2((ih-z)/2) + &\r\n\t\t\t\t\tfact2((ie+z)/2) + fact2((im+z)/2)\r\n\r\n\t\t\t\tif (mod(z,4) /= 0) then\t\t\t\t\t\r\n\t\t\t\t\tccc = ccc + log(1.d0-exp(-denom-ccc))\r\n\t\t\t\telse\r\n\t\t\t\t\tccc = ccc + log(1.d0+exp(-denom-ccc))\r\n\t\t\t\tendif\r\n\t\t\t\t\r\n\t\t\tenddo\r\n\t\t\tcc1 = fact2(ig/2) + fact2((j3+ib)/2) + fact2((j3-ib)/2) - fact2((jsum+2)/2)\r\n \t\tcc2 = fact2((j1+m1)/2) + fact2(ic/2) + fact2(ih/2) + fact2(id/2) + fact2((j3-m3)/2) + fact2((j3+m3)/2)\r\n\t\t\tccc = ccc + 0.5d0 * (cc1 + cc2)\t\t\t\r\n\r\n\t\t\tif (real(ccc) < -1.d50) then\r\n\t\t\t\tccc = 0.d0\r\n\t\t\telse\r\n\t\t\t\tccc = exp(ccc)\t\t\t\r\n\t\t\tendif\r\n\r\n\t\t\tif (mod(ib-m3,4) /= 0) ccc = -ccc\r\n\t\t\tw3js = ccc\r\n\t\t\tif (abs(w3js) < 1.d-8) w3js = 0.d0\r\n1000 \t\treturn\r\n end function w3js\r\n\r\n!----------------------------------------------------------------------\r\n!----------------------------------------------------------------------\r\n! Initialize factorials\r\n!----------------------------------------------------------------------\r\n!----------------------------------------------------------------------\r\n\tsubroutine factrl\r\n\t\tinteger :: i\r\n\t\treal(kind=8), parameter :: PI = 3.14159265359d0\r\n\t\treal(kind=8) :: fact_local\r\n\r\n\t\tnfac = 301 \r\n\t\tfact_local = 1.d0\r\n\t\tfact2(0) = 0.d0\r\n \tdo i=1,nfac\r\n\t\t\tfact_local = fact_local * i\r\n\t\t\tif (i < 170) then\r\n\t\t\t\tfact2(i) = log(fact_local)\r\n\t\t\telse\r\n\t\t\t\tfact2(i) = 0.5d0 * log(2.d0*PI*i) + i * log(float(i)) - float(i)\r\n\t\t\tendif\r\n\t\tenddo\t\t\r\n\tend subroutine factrl\r\n\r\n!----------------------------------------------------------------------\r\n!----------------------------------------------------------------------\r\n! Initialize factorials\r\n!----------------------------------------------------------------------\r\n!----------------------------------------------------------------------\r\n\tfunction delta(a, b)\r\n\treal(kind=8) :: a, b, delta\r\n\t\tdelta = 0.d0\r\n\t\tif (a == b) delta = 1.d0\r\n\tend function delta\r\n\r\n!----------------------------------------------------------------------\r\n!----------------------------------------------------------------------\r\n! Reverse of a vector\r\n!----------------------------------------------------------------------\r\n!----------------------------------------------------------------------\r\n\tfunction reverse(a)\r\n\tinteger :: a(:), reverse(size(a))\r\n\tinteger :: n, i\r\n\t\tn = size(a)\r\n\t\tdo i = 1, n\r\n\t\t\treverse(i) = a(n-i+1)\r\n\t\tenddo\t\t\r\n\tend function reverse\r\n\r\n!----------------------------------------------------------------------\r\n!----------------------------------------------------------------------\r\n! Return the number of elements in a vector equal to a given number\r\n!----------------------------------------------------------------------\r\n!----------------------------------------------------------------------\r\n\tfunction where_index(a,b,n)\r\n\tinteger :: n\r\n\treal(kind=8) :: where_index(n)\r\n\treal(kind=8) :: a(:), b\r\n\tinteger :: i, j, n2\r\n\tlogical :: found\r\n\t\tn2 = size(a)\r\n\t\tj = 1\r\n\t\ti = 1\r\n\t\tfound = .false.\r\n\t\tdo while(i <= n2 .and. .not.found)\r\n\t\t\tif (a(i) == b) then\r\n\t\t\t\twhere_index(j) = i\r\n\t\t\t\tj = j + 1\r\n\t\t\t\tif (j > n) then\r\n\t\t\t\t\tfound = .true.\r\n\t\t\t\tendif\t\t\t\t\r\n\t\t\tendif\r\n\t\t\ti = i + 1\r\n\t\tenddo\r\n\tend function where_index\r\n\t\r\n!----------------------------------------------------------------------\r\n!----------------------------------------------------------------------\r\n! Return the number of elements in a vector equal to a given number\r\n!----------------------------------------------------------------------\r\n!----------------------------------------------------------------------\r\n\tsubroutine uniq(a,b)\r\n\treal(kind=8) :: a(:), b(:), dif\r\n\tinteger, allocatable :: indx(:)\r\n\tinteger :: i, l, n\r\n\t\t\r\n\t\tn = size(a)\r\n\t\t\r\n\t\tallocate(indx(n))\r\n\t\t\r\n\t\tcall indexx(a,indx)\r\n\t\t\r\n\t\tb(1) = a(indx(1))\r\n\t\tl = 2\r\n\t\tdo i = 2, n\r\n\t\t\tdif = abs(a(indx(i)) - b(l-1))\r\n\t\t\tif (dif > 1.d-9) then\r\n\t\t\t\tb(l) = a(indx(i))\r\n\t\t\t\tl = l + 1\r\n\t\t\tendif\r\n\t\tenddo\t\t\r\n\t\t\r\n\tend subroutine uniq\t\r\n\t\r\n!----------------------------------------------------------------------\r\n!----------------------------------------------------------------------\r\n! Return the number of elements in a vector equal to a given number\r\n!----------------------------------------------------------------------\r\n!----------------------------------------------------------------------\r\n\tfunction count(a,b)\r\n\tinteger :: count\r\n\treal(kind=8) :: a(:), b\r\n\tinteger :: i, l, n\r\n\t\t\r\n\t\tn = size(a)\r\n\t\t\r\n\t\tl = 0\t\t\r\n\t\tdo i = 1, n\r\n\t\t\tif (a(i) == b) then\r\n\t\t\t\tl = l + 1\r\n\t\t\tendif\r\n\t\tenddo\r\n\t\t\r\n\t\tcount = l\r\n\t\t\r\n\tend function count\t\r\n\r\n!----------------------------------------------------------------------\r\n!----------------------------------------------------------------------\r\n! Return the time\r\n!----------------------------------------------------------------------\r\n!----------------------------------------------------------------------\r\n\tfunction second()\r\n\treal(kind=4) :: second\r\n\tinteger :: time_array(8)\r\n\treal(kind=4) :: tiempo\r\n\t\tcall date_and_time(values=time_array)\r\n\t\ttiempo = time_array(5)*3600.*1000.+time_array(6)*60.*1000.+time_array(7)*1000.+time_array(8)\r\n\t\tsecond = tiempo / 1000.\r\n\tend function second\r\n\r\n!----------------------------------------------------------------------\r\n!----------------------------------------------------------------------\r\n! Sort an array in ascending order returning the index array in indx\r\n!----------------------------------------------------------------------\r\n!----------------------------------------------------------------------\r\n\tsubroutine indexx(arr,indx)\r\n\tinteger :: n,indx(:)\r\n\treal(kind=8) :: arr(:)\r\n integer, parameter :: M=7,NSTACK=50\r\n integer :: i,indxt,ir,itemp,j,jstack,k,l,istack(NSTACK)\r\n real(kind=8) :: a\r\n\r\n\tn = size(arr)\r\n do j=1,n\r\n\t\tindx(j)=j\r\n\tenddo\r\n jstack=0\r\n l=1\r\n ir=n\r\n1 if(ir-l.lt.M)then\r\n\t\tdo j=l+1,ir\r\n\t\t\tindxt=indx(j)\r\n\t\t\ta=arr(indxt)\r\n\t\t\tdo i=j-1,1,-1\r\n\t\t\t\tif(arr(indx(i)).le.a)goto 2\r\n\t\t\t\tindx(i+1)=indx(i)\r\n\t\t\tenddo\r\n\t\t\ti=0\r\n2\t\t\tindx(i+1)=indxt\r\n\t\tenddo\r\n if(jstack.eq.0)return\r\n ir=istack(jstack)\r\n l=istack(jstack-1)\r\n jstack=jstack-2\r\n else\r\n k=(l+ir)/2\r\n itemp=indx(k)\r\n indx(k)=indx(l+1)\r\n indx(l+1)=itemp\r\n if(arr(indx(l+1)).gt.arr(indx(ir)))then\r\n itemp=indx(l+1)\r\n indx(l+1)=indx(ir)\r\n indx(ir)=itemp\r\n endif\r\n if(arr(indx(l)).gt.arr(indx(ir)))then\r\n itemp=indx(l)\r\n indx(l)=indx(ir)\r\n indx(ir)=itemp\r\n endif\r\n if(arr(indx(l+1)).gt.arr(indx(l)))then\r\n itemp=indx(l+1)\r\n indx(l+1)=indx(l)\r\n indx(l)=itemp\r\n endif\r\n i=l+1\r\n j=ir\r\n indxt=indx(l)\r\n a=arr(indxt)\r\n3 continue\r\n i=i+1\r\n if(arr(indx(i)).lt.a)goto 3\r\n4 continue\r\n j=j-1\r\n if(arr(indx(j)).gt.a)goto 4\r\n if(j.lt.i)goto 5\r\n itemp=indx(i)\r\n indx(i)=indx(j)\r\n indx(j)=itemp\r\n goto 3\r\n5 indx(l)=indx(j)\r\n indx(j)=indxt\r\n jstack=jstack+2\r\n if(jstack.gt.NSTACK)pause 'NSTACK too small in indexx'\r\n if(ir-i+1.ge.j-l)then\r\n istack(jstack)=ir\r\n istack(jstack-1)=i\r\n ir=j-1\r\n else\r\n istack(jstack)=j-1\r\n istack(jstack-1)=l\r\n l=i\r\n endif\r\n endif\r\n goto 1\r\n end subroutine indexx\r\nend module maths\r\n", "meta": {"hexsha": "ca54f87e12ca8d8bad884a563f98445da22d7d4c", "size": 11125, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/maths.f90", "max_stars_repo_name": "aasensio/diatomic", "max_stars_repo_head_hexsha": "0d7abe37bc9401f9f0452b6ee097fb9136e6830e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-03-13T00:31:23.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-13T00:31:23.000Z", "max_issues_repo_path": "src/maths.f90", "max_issues_repo_name": "aasensio/diatomic", "max_issues_repo_head_hexsha": "0d7abe37bc9401f9f0452b6ee097fb9136e6830e", "max_issues_repo_licenses": ["MIT"], "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/maths.f90", "max_forks_repo_name": "aasensio/diatomic", "max_forks_repo_head_hexsha": "0d7abe37bc9401f9f0452b6ee097fb9136e6830e", "max_forks_repo_licenses": ["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.6741293532, "max_line_length": 111, "alphanum_fraction": 0.3544269663, "num_tokens": 3326, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587934924569, "lm_q2_score": 0.743167997235783, "lm_q1q2_score": 0.6604970925854801}} {"text": "module gramschmidt\n!Modified based on\n! Numerical Analysis:\n! Mathematics of Scientific Computing\n! Third Edition\n! D.R. Kincaid & E.W. Cheney\n! Brooks/Cole Publ., 2002\n! Copyright (c) 1996\n! Section 5.3\n! Example of modified Gram-Schmidt algorithm\n! file: qrshif.f\n!Original program only accepts square matrices\n\n use prep, only : i16b\n use, intrinsic :: iso_fortran_env, only: rk => real64\n use projection, only : REAL_MIN\n\n implicit none\n contains\n\n subroutine orth(a, q, r, m, n)\n real(rk) :: a(:, :), q(:, :), r(:, :), z\n integer, intent(in) :: m, n\n integer :: i, k\n do k = 1, m\n print *,' Matrix A'\n call prtmtx(n,a)\n z = a(n,n)\n do i=1,n\n a(i,i)= a(i,i) - z\n end do\n call mgs(a, q, r, n, n)\n print *,' Matrix Q'\n call prtmtx(n,q)\n print *,' Matrix R'\n call prtmtx(n,r)\n call mult(r,q, n, n, n, a)\n do i=1,n\n a(i,i)=a(i,i) + z\n end do\n enddo\n end subroutine orth\n \n subroutine prtmtx(n,a)\n real(rk), intent(in):: a(:,:)\n integer, intent(in) :: n\n\n integer :: i, j\n do i=1,n\n write(*, '(4f10.6)') (a(i,j),j=1,n)\n enddo\n end subroutine\n\n \n\n subroutine mgs(a, q, t, m, n)\n !a(m, n), q(m, n), t(n, n)\n real(rk) :: a(:, :), q(:, :), t(:, :), z\n integer, intent(in) :: m, n\n integer :: i, j, k\n\n !if(size(a, 1).ne.m.OR.size(a, 2).ne.n.OR.size(q, 1).ne.m.OR.&\n ! &size(q, 2).ne.n.OR.size(t, 1).ne.n.OR.size(t, 2).ne.n) then\n ! write(*, *) 'matrix size not right in subroutine mgs'\n ! return\n !endif\n\n do j = 1, n\n do i = 1, n\n t(i, j) = 0.\n enddo\n do i = 1, m\n q(i, j) = a(i, j)\n enddo\n enddo\n\n do k = 1, n\n z = 0.\n do i = 1, m\n z = z + q(i, k)**2\n end do\n t(k, k) = sqrt(z)\n do i = 1, m\n q(i, k) = q(i, k) / t(k, k)\n end do\n do j = k+1, n\n z = 0.\n do i = 1, m\n z = z + q(i, j) * q(i, k)\n end do\n t(k, j) = z\n do i = 1, m\n q(i, j) = q(i, j) - t(k, j) * q(i, k)\n enddo\n enddo\n enddo\n end subroutine mgs\n\n\n subroutine mult(A, B, n1, m, n2, C)\n ! Matrix product C(n1, n2) = A(n1, m)*B(m, n2)\n integer, intent(in) :: n1, m, n2\n real(rk), intent(in) :: A(:, :), B(:, :)\n real(rk) :: C(:, :), tp\n integer :: i, j, k\n\n do i = 1, n1\n do j = 1, n2\n tp = 0.0\n do k = 1, m\n tp = tp + A(i, k) * B(k, j)\n enddo\n C(i, j) = tp\n end do\n end do\n end subroutine mult\n\nend module gramschmidt\n", "meta": {"hexsha": "79ebc8a748c71b1184888fd1f360e5dceece8089", "size": 3214, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gramschmidt.f90", "max_stars_repo_name": "MingtongH/csfcal", "max_stars_repo_head_hexsha": "712b6d098426a0c84731575288b033736096ebd9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "gramschmidt.f90", "max_issues_repo_name": "MingtongH/csfcal", "max_issues_repo_head_hexsha": "712b6d098426a0c84731575288b033736096ebd9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gramschmidt.f90", "max_forks_repo_name": "MingtongH/csfcal", "max_forks_repo_head_hexsha": "712b6d098426a0c84731575288b033736096ebd9", "max_forks_repo_licenses": ["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.0084033613, "max_line_length": 75, "alphanum_fraction": 0.3718108276, "num_tokens": 996, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995482, "lm_q2_score": 0.743167997235783, "lm_q1q2_score": 0.6604970882060589}} {"text": "!\n!\n!*******************************************************************************\n!\nreal(kind=8) function tco_interpolate(e,nume,e_grid,tco)\n!\n!*******************************************************************************\n!\n! Discussion:\n!\n! This subroutine finds the transmission coeeficient at a \n! specific energy e by interpolating from a list of nume values \n! in the array tco on a energy grid defined by e_grid \n! Interpolate using a log-log linear approximation\n! \n! Improved 6 Jan 2021 making use of the constant grid in log(e) to\n! find mid points. Sped up by 6x.\n!\n! Dependencies:\n!\n! Modules:\n!\n! nodeinfo\n! variable_kinds\n!\n! Subroutines:\n!\n! None\n!\n! External functions:\n!\n! None\n!\n! MPI routines:\n!\n! None\n!\n! Licensing:\n!\n! SPDX-License-Identifier: MIT \n!\n! Date:\n!\n! 11 May 2021\n!\n! Author:\n!\n! Erich Ormand, LLNL\n!\n!*******************************************************************************\n!\n use nodeinfo\n use variable_kinds\n implicit none\n real(kind=8), intent(in) :: e\n integer(kind=4), intent(in) :: nume\n real(kind=8), intent(in) :: e_grid(nume),tco(nume)\n!-----------------------------------------------------------------------------\n integer(kind=4) :: i1, i2 \n real(kind=8) :: x1, x2, y1, y2, x, y, a, b \n\n real(kind=8) :: delta\n!-----------------------------------------------------------------------------\n tco_interpolate = 1.0d-9\n if(e <= 0.0d0)return\n tco_interpolate = tco(1)\n if(e <= e_grid(1))return\n\n x = log(e)\n x1 = log(e_grid(1))\n\n delta = log(e_grid(2)) - x1\n i1 = int((x - x1)/delta) + 1\n i2 = i1 + 1\n\n\n x1 = log(e_grid(i1))\n x2 = log(e_grid(i2))\n!------ Put in lower threshold\n y1 = log(max(tco(i1),1.0d-9))\n y2 = log(max(tco(i2),1.0d-9))\n a = (y2-y1)/(x2-x1)\n b = y1 - a*x1\n y = a*x + b\n tco_interpolate = exp(y)\n\n return\nend function tco_interpolate\n\n", "meta": {"hexsha": "1a31f74f26b9d710748921a93b3021ed5d1eb059", "size": 1949, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Src/tco_interpolate.f90", "max_stars_repo_name": "LLNL/Yet-Another-Hauser-Feshbach-Code", "max_stars_repo_head_hexsha": "18af2fea77d0263986648b057c06bd96f87ae8e0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-11-05T23:37:51.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-05T23:37:53.000Z", "max_issues_repo_path": "Src/tco_interpolate.f90", "max_issues_repo_name": "LLNL/Yet-Another-Hauser-Feshbach-Code", "max_issues_repo_head_hexsha": "18af2fea77d0263986648b057c06bd96f87ae8e0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Src/tco_interpolate.f90", "max_forks_repo_name": "LLNL/Yet-Another-Hauser-Feshbach-Code", "max_forks_repo_head_hexsha": "18af2fea77d0263986648b057c06bd96f87ae8e0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-11-05T23:38:28.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-10T21:34:37.000Z", "avg_line_length": 21.6555555556, "max_line_length": 80, "alphanum_fraction": 0.4648537712, "num_tokens": 568, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797100118214, "lm_q2_score": 0.724870282120402, "lm_q1q2_score": 0.6604870934586551}} {"text": " SUBROUTINE CGELSY_F95( A, B, RANK, JPVT, RCOND, INFO )\n!\n! -- LAPACK95 interface driver routine (version 3.0) --\n! UNI-C, Denmark; Univ. of Tennessee, USA; NAG Ltd., UK\n! September, 2000\n!\n! .. USE STATEMENTS ..\n USE LA_PRECISION, ONLY: WP => SP\n USE LA_AUXMOD, ONLY: ERINFO\n USE F77_LAPACK, ONLY: GELSY_F77 => LA_GELSY\n! .. IMPLICIT STATEMENT ..\n IMPLICIT NONE\n! .. SCALAR ARGUMENTS ..\n INTEGER, INTENT(OUT), OPTIONAL :: RANK\n INTEGER, INTENT(OUT), OPTIONAL :: INFO\n REAL(WP), INTENT(IN), OPTIONAL :: RCOND\n! .. ARRAY ARGUMENTS ..\n INTEGER, INTENT(INOUT), OPTIONAL, TARGET :: JPVT(:)\n COMPLEX(WP), INTENT(INOUT) :: A(:,:), B(:,:)\n!----------------------------------------------------------------------\n! \n! Purpose\n! =======\n! \n! LA_GELSY computes the minimum-norm least squares solution to one \n! or more real or complex linear systems A*x = b using a complete \n! orthogonal factorization of A. Matrix A is rectangular and may be \n! rankdeficient. The vectors b and corresponding solution vectors x are \n! the columns of matrices denoted B and X, respectively.\n! The routine computes a QR factorization of A with column pivoting:\n! A * P = Q * [ R11 R12 ]\n! [ 0 R22 ]\n! where R11 is the largest leading submatrix whose estimated condition \n! number is less than 1/RCOND. The order of R11, RANK, is the effective \n! rank of A. R22 is considered to be negligible, and R12 is annihilated \n! by orthogonal (unitary) transformations from the right, yielding the \n! complete orthogonal (unitary) factorization\n! A * P = Q * [ T11 0 ] * Z\n! \t [ 0 0 ]\n! The minimum-norm least squares solution is then\n! x = P * Z^H [ T11^-1 * Q1^H * b ]\n! \t [ 0 ]\n! where Q1 consists of the first RANK columns of Q.\n! \n! =========\n! \n! SUBROUTINE LA_GELSY( A, B, RANK=rank, &\n! JPVT= jpvt, RCOND= rcond, INFO= info )\n! (), INTENT(INOUT) :: A(:,:), \n! INTEGER, INTENT(OUT), OPTIONAL :: RANK\n! INTEGER, INTENT(INOUT), OPTIONAL :: JPVT(:)\n! REAL(), INTENT(IN), OPTIONAL :: RCOND\n! INTEGER, INTENT(OUT), OPTIONAL :: INFO\n! where\n! ::= REAL | COMPLEX\n! ::= KIND(1.0) | KIND(1.0D0)\n! ::= B(:,:) | B(:)\n! \n! Arguments\n! =========\n! \n! A (input/output) REAL or COMPLEX array, shape (:,:).\n! On entry, the matrix A.\n! \t On exit, A has been overwritten by details of its complete\n! orthogonal factorization.\n! B (input/output) REAL or COMPLEX array, shape (:,:) with \n! size(B,1) = max(size(A,1),size(A,2)) or shape (:) with \n! \t size(B) = max(size(A,1), size(A,2)).\n! \t On entry, the matrix B.\n! \t On exit, rows 1 to size(A,2) contain the solution matrix X .\n! \t If size(A,1) >= size(A,2) and RANK = size(A,2), the residual\n! \t sum-of-squares for the solution vector in a column of B is \n! \t given by the sum of squares of elements in rows size(A,2)+1 :\n! size(A,1) of that column.\n! RANK Optional (output) INTEGER.\n! The effective rank of A, i.e., the order of the submatrix R11.\n! \t This is the same as the order of the submatrix T11 in the \n! \t complete orthogonal factorization of A.\n! JPVT Optional (input/output) INTEGER array, shape (:) with \n! size(JPVT) = size(A,2).\n! \t On entry, if JPVT(i) /= 0, the i-th column of A is an initial \n! \t column, otherwise it is a free column.\n! \t Before the QR factorization of A, all initial columns are \n! \t permuted to the leading positions; only the remaining free \n! \t columns are moved as a result of column pivoting during the \n! \t factorization.\n! \t On exit, if JPVT(i) = k, then the i-th column of the matrix \n! \t product A*P was the k-th column of A.\n! RCOND Optional (input) REAL.\n! RCOND is used to determine the effective rank of A. This is \n! \t defined as the order of the largest leading triangular \n! \t submatrix R11 in the QR factorization of A, with pivoting, \n! \t whose estimated condition number < 1/RCOND.\n! Default value: 10*max(size(A,1),size(A,2))*BEPSILON(1.0_),\n! \t where is the working precision.\n! INFO Optional (output) INTEGER.\n! = 0: successful exit\n! \t < 0: if INFO = -i, the i-th argument had an illegal value\n! \t If INFO is not present and an error occurs, then the program \n! \t is terminated with an error message.\n!----------------------------------------------------------------------\n! .. PARAMETERS ..\n CHARACTER(LEN=8), PARAMETER :: SRNAME = 'LA_GELSY'\n! .. LOCAL SCALARS ..\n INTEGER :: LINFO, ISTAT, ISTAT1, LWORK, N, M, MN, NRHS, LRANK, SJPVT\n REAL(WP) :: LRCOND\n! .. LOCAL POINTERS ..\n INTEGER, POINTER :: LJPVT(:)\n COMPLEX(WP), POINTER :: WORK(:)\n COMPLEX(WP) :: WORKMIN(1)\n REAL(WP), POINTER :: RWORK(:)\n! .. INTRINSIC FUNCTIONS ..\n INTRINSIC SIZE, PRESENT, MAX, MIN, EPSILON\n! .. EXECUTABLE STATEMENTS ..\n LINFO = 0; ISTAT = 0; M = SIZE(A,1); N = SIZE(A,2); NRHS = SIZE(B,2)\n MN = MIN(M,N)\n IF( PRESENT(RCOND) )THEN; LRCOND = RCOND; ELSE\n LRCOND = 100*EPSILON(1.0_WP) ; ENDIF\n IF( PRESENT(JPVT) )THEN; SJPVT = SIZE(JPVT); ELSE; SJPVT = N; ENDIF\n! .. TEST THE ARGUMENTS\n IF( M < 0 .OR. N < 0 ) THEN; LINFO = -1\n ELSE IF( SIZE( B, 1 ) /= MAX(1,M,N) .OR. NRHS < 0 ) THEN; LINFO = -2\n ELSE IF( SJPVT /= N ) THEN; LINFO = -4\n ELSE IF( LRCOND <= 0.0_WP ) THEN; LINFO = -5\n ELSE\n IF( PRESENT(JPVT) )THEN; LJPVT => JPVT\n ELSE; ALLOCATE( LJPVT(N), STAT = ISTAT ); LJPVT = 0; END IF\n\t\n ALLOCATE(RWORK(2*N), STAT=ISTAT)\n\tIF( ISTAT /= 0 ) CALL ERINFO( -200, SRNAME, LINFO ) \n\t\n! .. DETERMINE THE WORKSPACE ..\n! .. QUERING THE SIZE OF WORKSPACE ..\n LWORK = -1\n\t CALL GELSY_F77( M, N, NRHS, A, MAX(1,M), B, MAX(1,M,N), &\n & LJPVT, LRCOND, LRANK, WORKMIN, LWORK, RWORK, LINFO )\n LWORK = WORKMIN(1)\n IF( ISTAT == 0 ) THEN\n ALLOCATE( WORK(LWORK), STAT = ISTAT )\n IF( ISTAT /= 0 ) CALL ERINFO( -200, SRNAME, LINFO )\n END IF\n\n IF ( ISTAT == 0 ) THEN\n CALL GELSY_F77( M, N, NRHS, A, MAX(1,M), B, MAX(1,M,N), &\n & LJPVT, LRCOND, LRANK, WORK, LWORK, RWORK, LINFO )\n ELSE; LINFO = -100; END IF\n IF( PRESENT(RANK) ) RANK = LRANK\n IF( PRESENT(JPVT) ) JPVT = LJPVT\n DEALLOCATE(WORK, RWORK, STAT = ISTAT1 )\n END IF\n CALL ERINFO( LINFO, SRNAME, INFO, ISTAT )\n END SUBROUTINE CGELSY_F95\n", "meta": {"hexsha": "4fe1c255cfd7bb78e1ac6f55e5ce9e20e63ea67c", "size": 6700, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/la_cgelsy.f90", "max_stars_repo_name": "MattBurn/LAPACK95", "max_stars_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-12-29T15:07:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T10:09:22.000Z", "max_issues_repo_path": "src/la_cgelsy.f90", "max_issues_repo_name": "MattBurn/LAPACK95", "max_issues_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-02-21T10:46:38.000Z", "max_issues_repo_issues_event_max_datetime": "2017-10-20T17:03:14.000Z", "max_forks_repo_path": "src/la_cgelsy.f90", "max_forks_repo_name": "MattBurn/LAPACK95", "max_forks_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-12-29T15:34:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-15T07:12:40.000Z", "avg_line_length": 43.7908496732, "max_line_length": 74, "alphanum_fraction": 0.5682089552, "num_tokens": 2069, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797003640646, "lm_q2_score": 0.724870282120402, "lm_q1q2_score": 0.6604870864652829}} {"text": "MODULE OPT_MOD\n\n ! Interface for the gradient.\n INTERFACE\n SUBROUTINE GRAD(DIMS, X, G)\n USE REAL_PRECISION\n INTEGER :: DIMS\n REAL(KIND=R8) :: X(DIMS), G(DIMS)\n END SUBROUTINE GRAD\n END INTERFACE\n\nCONTAINS\n\n SUBROUTINE SGD(D, GRAD, X, IBUDGET, ALPHA, TAU)\n ! Standard SGD optimization algorithm.\n ! INTEGER (IN) D : Dimension of space.\n ! REAL(KIND=R8), FUNCTION (IN) GRAD : Gradient of objective function \n ! \tg : R^D --> R.\n ! REAL(KIND=R8) (INOUT) X(D) : On input, starting position in R^D; On \n !\toutput, computed minima.\n ! INTEGER, OPTIONAL (IN) IBUDGET : Gradient evaluation budget.\n ! REAL(KIND=R8), OPTIONAL (IN) ALPHA : Step size/learning rate.\n ! REAL(KIND=R8), OPTIONAL (IN) TAU : Rate at which to decay step size\n USE REAL_PRECISION\n IMPLICIT NONE\n ! Parameter list.\n INTEGER, INTENT(IN) :: D\n EXTERNAL :: GRAD\n REAL(KIND=R8), INTENT(INOUT) :: X(D)\n ! Optional parameters.\n INTEGER, OPTIONAL, INTENT(IN) :: IBUDGET\n REAL(KIND=R8), OPTIONAL, INTENT(IN) :: ALPHA\n REAL(KIND=R8), OPTIONAL, INTENT(IN) :: TAU\n ! Local variables.\n REAL(KIND=R8) :: ALPHAL, TAUL\n INTEGER :: IBUDGETL, T\n REAL(KIND=R8) :: G(D)\n ! Set default values for the optional inputs.\n IBUDGETL = 1000\n ALPHAL = 0.01_R8\n TAUL = 0.99_R8\n ! Get the optional inputs.\n IF(PRESENT(IBUDGET)) THEN\n IBUDGETL = IBUDGET\n END IF\n IF(PRESENT(ALPHA)) THEN\n ALPHAL = ALPHA\n END IF\n IF(PRESENT(TAU)) THEN\n TAUL = TAU\n END IF\n ! Main loop over budget.\n DO T=1, IBUDGETL\n ! Set the current gradient.\n CALL GRAD(D,X,G)\n IF (ALL(G .EQ. 0.0_R8)) RETURN\n ! Take the update step.\n X = X - ALPHAL * G\n ! Decay the step size.\n ALPHAL = ALPHAL * TAUL\n END DO\n RETURN\n END SUBROUTINE SGD\n\n SUBROUTINE ADAM(D, GRAD, X, IBUDGET, ALPHA, BETA1, BETA2, EPS)\n ! ADaM optimization algorithm as proposed by D. P. Kingma and J. L. Ba.\n ! INTEGER (IN) D : Dimension of space.\n ! REAL(KIND=R8), FUNCTION (IN) GRAD : Gradient of objective function \n ! \tg : R^D --> R.\n ! REAL(KIND=R8) (INOUT) X(D) : On input, starting position in R^D; On \n !\toutput, computed minima.\n ! INTEGER, OPTIONAL (IN) IBUDGET : Gradient evaluation budget.\n ! REAL(KIND=R8), OPTIONAL (IN) ALPHA : Step size.\n ! REAL(KIND=R8), OPTIONAL (IN) BETA1 : Decay rate for first moment.\n ! REAL(KIND=R8), OPTIONAL (IN) BETA2 : Decay rate for second moment.\n ! REAL(KIND=R8), OPTIONAL (IN) EPS : Decay rate for second moment.\n USE REAL_PRECISION\n IMPLICIT NONE\n ! Parameter list.\n INTEGER, INTENT(IN) :: D\n EXTERNAL :: GRAD\n REAL(KIND=R8), INTENT(INOUT) :: X(D)\n ! Optional parameters.\n INTEGER, OPTIONAL, INTENT(IN) :: IBUDGET\n REAL(KIND=R8), OPTIONAL, INTENT(IN) :: ALPHA\n REAL(KIND=R8), OPTIONAL, INTENT(IN) :: BETA1\n REAL(KIND=R8), OPTIONAL, INTENT(IN) :: BETA2\n REAL(KIND=R8), OPTIONAL, INTENT(IN) :: EPS\n ! Local variables.\n REAL(KIND=R8) :: ALPHAL, BETA1L, BETA2L, EPSL\n INTEGER :: IBUDGETL, T\n REAL(KIND=R8) :: M(D), V(D), M_HAT(D), V_HAT(D), G(D)\n ! Set default values for the optional parameters.\n IBUDGETL = 1000\n ALPHAL = 0.01_R8\n BETA1L = 0.9_R8\n BETA2L = 0.999_R8\n EPSL = SQRT(EPSILON(0.0_R8))\n ! Get optional inputs.\n IF(PRESENT(IBUDGET)) THEN\n IBUDGETL = IBUDGET\n END IF\n IF(PRESENT(ALPHA)) THEN\n ALPHAL = ALPHA\n END IF\n IF(PRESENT(BETA1)) THEN\n BETA1L = BETA1\n END IF\n IF(PRESENT(BETA2)) THEN\n BETA2L = BETA2\n END IF\n IF(PRESENT(EPS)) THEN\n EPSL = EPS\n END IF\n ! Initialize the first and second moments.\n M = 0.0_R8\n V = 0.0_R8\n ! Main loop over budget.\n DO T=1, IBUDGETL\n ! Get the current gradient.\n CALL GRAD(D,X,G)\n IF (ALL(G .EQ. 0.0_R8)) RETURN\n ! Compute the biased first and second moments.\n M = BETA1L * M + (1.0_R8 - BETA1L) * G\n V = BETA2L * V + (1.0_R8 - BETA2L) * G * G\n ! Correct m and v for bias.\n M_HAT = M / (1.0_R8 - BETA1L ** REAL(T,KIND=R8))\n V_HAT = V / (1.0_R8 - BETA2L ** REAL(T,KIND=R8))\n ! Take a step according to nonbiased adaptive gradient.\n X = X - ALPHAL * M_HAT / (SQRT(V_HAT) + EPSL)\n END DO\n RETURN\n END SUBROUTINE ADAM\n\n SUBROUTINE ADAGRAD(D, GRAD, X, IBUDGET, ALPHA, EPS)\n ! ADAGRAD optimization algorithm as described by Duchi, Hazan, and Singer.\n ! INTEGER (IN) D : Dimension of space.\n ! REAL(KIND=R8), FUNCTION (IN) GRAD : Gradient of objective function \n ! \tg : R^D --> R.\n ! REAL(KIND=R8) (INOUT) X(D) : On input, starting position in R^D; On \n !\toutput, computed minima.\n ! INTEGER, OPTIONAL (IN) IBUDGET : Gradient evaluation budget.\n ! REAL(KIND=R8), OPTIONAL (IN) ALPHA : Step size in the adjusted space \n !\tparameterized by the matrix norm induced by G.\n ! REAL(KIND=R8), OPTIONAL (IN) EPS : \"Fudge factor\" for adjusting the \n !\tmatrix norm G, avoiding pathological cases where the gradient\n !\tdisappears in one dimension. Should be a VERY small number \n !\t(default: SQRT(EPSILON)).\n USE REAL_PRECISION\n IMPLICIT NONE\n ! Parameter list.\n INTEGER, INTENT(IN) :: D\n EXTERNAL :: GRAD\n REAL(KIND=R8), INTENT(INOUT) :: X(D)\n ! Optional parameters.\n INTEGER, OPTIONAL, INTENT(IN) :: IBUDGET\n REAL(KIND=R8), OPTIONAL, INTENT(IN) :: ALPHA\n REAL(KIND=R8), OPTIONAL, INTENT(IN) :: EPS\n ! Local variables.\n REAL(KIND=R8) :: EPSL, ALPHAL \n INTEGER :: IBUDGETL, T\n REAL(KIND=R8) :: G(D), STEP(D)\n ! Set default values for the optional parameters.\n IBUDGETL = 1000\n ALPHAL = 0.01_R8\n EPSL = SQRT(EPSILON(0.0_R8))\n ! Get optional inputs.\n IF(PRESENT(IBUDGET)) THEN\n IBUDGETL = IBUDGET\n END IF\n IF(PRESENT(EPS)) THEN\n EPSL = EPS\n END IF\n IF(PRESENT(ALPHA)) THEN\n ALPHAL = ALPHA\n END IF\n ! Initialize the matrix norm.\n G = 0.0_R8\n ! Main loop over budget.\n DO T=1, IBUDGETL\n ! Get the current gradient.\n CALL GRAD(D, X, STEP)\n IF (ALL(G .EQ. 0.0_R8)) RETURN\n ! Update the adaptive norm.\n G = G + STEP ** 2.0_R8\n ! Take the adjusted trust region step according to the current norm.\n STEP = STEP / (EPSL + SQRT(G))\n X = X - (ALPHAL * STEP)\n END DO\n RETURN\n END SUBROUTINE ADAGRAD\n\nEND MODULE OPT_MOD\n", "meta": {"hexsha": "6bed76d1d993f283a13bf313b4ffdd6784ea3bd0", "size": 6404, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/optimizers.f90", "max_stars_repo_name": "thchang/NN_MOD", "max_stars_repo_head_hexsha": "1f2b8991900dda36b40d997da77d287c25541bac", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-02-07T00:29:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-07T00:29:25.000Z", "max_issues_repo_path": "src/optimizers.f90", "max_issues_repo_name": "thchang/NN_MOD", "max_issues_repo_head_hexsha": "1f2b8991900dda36b40d997da77d287c25541bac", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-02-07T00:28:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-13T19:40:30.000Z", "max_forks_repo_path": "src/optimizers.f90", "max_forks_repo_name": "thchang/NN_MOD", "max_forks_repo_head_hexsha": "1f2b8991900dda36b40d997da77d287c25541bac", "max_forks_repo_licenses": ["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.0103092784, "max_line_length": 78, "alphanum_fraction": 0.6118051218, "num_tokens": 2123, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951025545426, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6604850372196508}} {"text": "c prog3\nc c.l.lawson and r.j.hanson, jet propulsion laboratory, 1973 jun 12\nc to appear in 'solving least squares problems', prentice-hall, 1974\nc\t demonstrate the use of subroutine svdrs to compute the\nc singular value decomposition of a matrix, a, and solve a least\nc squares problem,\ta*x=b.\nc\nc the s.v.d. a= u*(s,0)**t*v**t is\nc computed so that..\nc (1) u**t*b replaces the m+1 st. col. of\tb.\nc\nc (2) u**t replaces the m by m identity in\nc the first m cols. of b.\nc\nc (3) v replaces the first n rows and cols.\nc of a.\nc\nc (4) the diagonal entries of the s matrix\nc replace the first n entries of the array s.\nc\nc the array s( ) must be dimensioned at least 3*n .\nc\n dimension a(8,8),b(8,9),s(24),x(8),aa(8,8)\n real gen,anoise\n double precision sm\n data mda,mdb/8,8/\nc\n do 150 noise=1,2\n anoise = 0.\n rho = 1.e-3\n if(noise .eq. 1) go to 5\n anoise = 1.e-4\n rho = 10. * anoise\n 5 continue\n write(6,230)\n write(6,240) anoise,rho\nc initialize data generation function\nc ..\n dummy= gen(-1.)\nc\n\t do 150 mn1=1,6,5\n\t mn2=mn1+2\n\t\tdo 150 m=mn1,mn2\n\t\tdo 150 n=mn1,mn2\n\t\twrite (6,160) m,n\n\t\t do 20 i=1,m\n\t\t\t do 10 j=1,m\n 10\t\t\t b(i,j)=0.\n\t\t b(i,i)=1.\n\t\t\t do 20 j=1,n\n\t\t\t a(i,j)= gen(anoise)\n 20\t\t\t aa(i,j)=a(i,j)\n\t\t do 30 i=1,m\n 30\t\t b(i,m+1)= gen(anoise)\nc\nc the arrays are now filled in..\nc compute the s.v.d.\nc ******************************************************\n\t\tcall svdrs (a,mda,m,n,b,mdb,m+1,s)\nc ******************************************************\nc\n\t\twrite (6,170)\n\t\twrite (6,220) (i,s(i),i=1,n)\n\t\twrite (6,180)\n\t\twrite (6,220) (i,b(i,m+1),i=1,m)\nc\nc test for disparity of ratio of singular values.\nc ..\n\t\tkrank=n\n\t\ttau=rho*s(1)\n\t\t do 40 i=1,n\n\t\t if (s(i).le.tau) go to 50\n 40\t\t continue\n\t\tgo to 55\n 50\t\tkrank=i-1\n 55 write(6,250) tau, krank\nc compute solution vector assuming pseudorank is krank\nc ..\n 60\t\t do 70 i=1,krank\n 70\t\t b(i,m+1)=b(i,m+1)/s(i)\n\t\t do 90 i=1,n\n\t\t sm=0.d0\n\t\t\t do 80 j=1,krank\n 80\t\t\t sm=sm+a(i,j)*dble(b(j,m+1))\n 90\t\t x(i)=sm\nc compute predicted norm of residual vector.\nc ..\n\t\tsrsmsq=0.\n\t\tif (krank.eq.m) go to 110\n\t\tkp1=krank+1\n\t\t do 100 i=kp1,m\n 100\t\t srsmsq=srsmsq+b(i,m+1)**2\n\t\tsrsmsq=sqrt(srsmsq)\nc\n 110\t\tcontinue\n\t\twrite (6,190)\n\t\twrite (6,220) (i,x(i),i=1,n)\n\t\twrite (6,200) srsmsq\nc compute the frobenius norm of a**t- v*(s,0)*u**t.\nc\nc compute v*s first.\nc\n\t\tminmn=min0(m,n)\n\t\t do 120 j=1,minmn\n\t\t\t do 120 i=1,n\n 120\t\t\t a(i,j)=a(i,j)*s(j)\n\t\tdn=0.\n\t\t do 140 j=1,m\n\t\t\t do 140 i=1,n\n\t\t\t sm=0.d0\n\t\t\t do 130 l=1,minmn\n 130\t\t\t sm=sm+a(i,l)*dble(b(l,j))\nc computed difference of (i,j) th entry\nc of a**t-v*(s,0)*u**t.\nc ..\n\t\t\t t=aa(j,i)-sm\n 140\t\t\t dn=dn+t**2\n\t\tdn=sqrt(dn)/(sqrt(float(n))*s(1))\n\t\twrite (6,210) dn\n 150\t\tcontinue\n stop\n 160 format (1h0////9h0 m n/1x,2i4)\n 170 format (1h0,8x,25hsingular values of matrix)\n 180 format (1h0,8x,30htransformed right side, u**t*b)\n 190 format (1h0,8x,33hestimated parameters, x=a**(+)*b,21h computed b\n 1y 'svdrs' )\n 200 format (1h0,8x,24hresidual vector length =,e12.4)\n 210 format (1h0,8x,43hfrobenius norm (a-u*(s,0)**t*v**t)/(sqrt(n),\n *22h*spectral norm of a) =,e12.4)\n 220 format (9x,i5,e16.8,i5,e16.8,i5,e16.8,i5,e16.8,i5,e16.8)\n 230 format(51h1prog3. this program demonstrates the algorithm,\n * 9h, svdrs. )\n 240 format(55h0the relative noise level of the generated data will be,\n *e16.4/44h0the relative tolerance, rho, for pseudorank,\n *17h determination is,e16.4)\n 250 format(1h0,8x,36habsolute pseudorank tolerance, tau =,\n *e12.4,10x,12hpseudorank =,i5)\n end\n", "meta": {"hexsha": "290f8161975768db7718fc6ff99a7afcb3d1a0cd", "size": 3829, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iraf.v2161/math/llsq/progs/prog3.f", "max_stars_repo_name": "ysBach/irafdocgen", "max_stars_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:19:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T16:48:42.000Z", "max_issues_repo_path": "math/llsq/progs/prog3.f", "max_issues_repo_name": "kirxkirx/iraf", "max_issues_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-30T13:48:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-02T19:40:25.000Z", "max_forks_repo_path": "math/llsq/progs/prog3.f", "max_forks_repo_name": "kirxkirx/iraf", "max_forks_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.5467625899, "max_line_length": 72, "alphanum_fraction": 0.5591538261, "num_tokens": 1540, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950947024555, "lm_q2_score": 0.782662489091802, "lm_q1q2_score": 0.6604850353521858}} {"text": "! Program to test array constructors\nprogram constructors\n integer, dimension (4) :: a\n integer, dimension (3, 2) :: b\n integer i, j, k, l, m, n\n\n a = (/1, (i,i=2,4)/)\n do i = 1, 4\n if (a(i) .ne. i) call abort\n end do\n\n b = reshape ((/0, 1, 2, 3, 4, 5/), (/3, 2/)) + 1\n do i=1,3\n if (b(i, 1) .ne. i) call abort\n if (b(i, 2) .ne. i + 3) call abort\n end do\n\n k = 1\n l = 2\n m = 3\n n = 4\n ! The remainder assumes constant constructors work ok.\n a = (/n, m, l, k/)\n if (any (a .ne. (/4, 3, 2, 1/))) call abort\n a = (/((/i+10, 42/), i = k, l)/)\n if (any (a .ne. (/11, 42, 12, 42/))) call abort\n a = (/(I, I=k,l) , (J, J=m,n)/)\n if (any (a .ne. (/1, 2, 3, 4/))) call abort\nend program\n", "meta": {"hexsha": "96cb89d721c7435eff74279394c4bb4c4a356938", "size": 733, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.fortran-torture/execute/constructor.f90", "max_stars_repo_name": "best08618/asylo", "max_stars_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-05-02T17:34:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-17T10:15:18.000Z", "max_issues_repo_path": "llvm-gcc-4.2-2.9/gcc/testsuite/gfortran.fortran-torture/execute/constructor.f90", "max_issues_repo_name": "vidkidz/crossbridge", "max_issues_repo_head_hexsha": "ba0bf94aee0ce6cf7eb5be882382e52bc57ba396", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "llvm-gcc-4.2-2.9/gcc/testsuite/gfortran.fortran-torture/execute/constructor.f90", "max_forks_repo_name": "vidkidz/crossbridge", "max_forks_repo_head_hexsha": "ba0bf94aee0ce6cf7eb5be882382e52bc57ba396", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-27T00:22:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-01T09:41:02.000Z", "avg_line_length": 24.4333333333, "max_line_length": 57, "alphanum_fraction": 0.4720327422, "num_tokens": 339, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951104066293, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.6604850348090463}} {"text": "\nprogram main_bvp\n\n use bvp_solvers, only: solve_bvp_direct\n use problem, only: u_true\n implicit none\n integer :: n, i\n real(kind=8) :: u_left, u_right, error_max, dx\n real(kind=8), dimension(:), allocatable :: x, u, ustar\n\n open(unit=21, file='input_data.txt', status='old')\n read(21,*) n\n print *, \"n = \",n\n allocate(x(0:n+1), u(0:n+1), ustar(0:n+1))\n\n dx = 1.d0 / (n+1)\n do i=0,n+1\n x(i) = i*dx\n ustar(i) = u_true(x(i))\n enddo\n\n u_left = 20.d0\n u_right = 60.d0\n\n ! check for consistency with \"true solution\":\n if (abs(ustar(0) - u_left) .gt. 1.d-14) then\n print *, \"u_left doesn't match true solution\", ustar(0)\n stop\n endif\n if (abs(ustar(n+1) - u_right) .gt. 1.d-14) then\n print *, \"u_right doesn't match true solution\", ustar(n+1)\n stop\n endif\n\n\n call solve_bvp_direct(x, u_left, u_right, u)\n\n\n error_max = 0.d0\n do i=1,n\n error_max = max(error_max, abs(u(i) - ustar(i)))\n enddo\n\n print *, \"error_max = \",error_max\n\n\nend program main_bvp\n", "meta": {"hexsha": "9e22acd24a525f894303de1b2484d7308380259c", "size": 1084, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/homeworks/project/part1/main1.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/homeworks/project/part1/main1.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/homeworks/project/part1/main1.f90", "max_forks_repo_name": "philipwangdk/HPC", "max_forks_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.5833333333, "max_line_length": 66, "alphanum_fraction": 0.5645756458, "num_tokens": 375, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951104066295, "lm_q2_score": 0.7826624688140726, "lm_q1q2_score": 0.6604850305309771}} {"text": "module mergesort_module\n ! overloading interfaces\n ! main bottom up merge sort subroutines\n interface sort\n module procedure sort_integers\n module procedure sort_reals\n module procedure sort_strings\n end interface sort\n ! merge sort auxliary merge subroutine\n interface merge_arrays\n module procedure merge_integers\n module procedure merge_reals\n module procedure merge_strings\n end interface merge_arrays\n ! unit test functions\n interface sorted\n module procedure sorted_integers\n module procedure sorted_reals\n module procedure sorted_strings\n end interface sorted\ncontains\n subroutine sort_integers(n, x, y, order)\n implicit none\n ! dummy arguments\n integer, intent(in) :: n\n integer, intent(inout), dimension(n) :: x, y\n character (len = *), intent(in) :: order\n ! local data\n integer i, j, rnsz, m, l, r\n\n rnsz = 1\n do\n if (2*rnsz > n) exit\n l = 1\n r = l+rnsz\n do\n if (r+rnsz > n+1) exit\n call merge_arrays(rnsz, rnsz, x(l:), x(r:), y(l:), order)\n l = l+2*rnsz\n r = l+rnsz\n end do\n m = mod(n, 2*rnsz)\n if (m > rnsz) then\n l = (n-m)+1\n r = l+rnsz\n call merge_arrays(rnsz, m-rnsz, x(l:), x(r:), y(l:), order)\n else if (m > 0) then\n l = (n-m)+1\n y(l:) = x(l:)\n end if\n x = y\n rnsz = 2*rnsz\n end do\n call merge_arrays(rnsz, n-rnsz, x(1:rnsz), x(rnsz+1:n), y, order)\n end subroutine sort_integers\n\n subroutine sort_reals(n, x, y, order)\n implicit none\n ! dummy arguments\n integer, intent(in) :: n\n double precision, intent(inout), dimension(n) :: x, y\n character (len = *), intent(in) :: order\n ! local data\n integer i, j, rnsz, m, l, r\n\n rnsz = 1\n do\n if (2*rnsz > n) exit\n l = 1\n r = l+rnsz\n do\n if (r+rnsz > n+1) exit\n call merge_arrays(rnsz, rnsz, x(l:), x(r:), y(l:), order)\n l = l+2*rnsz\n r = l+rnsz\n end do\n m = mod(n, 2*rnsz)\n if (m > rnsz) then\n l = (n-m)+1\n r = l+rnsz\n call merge_arrays(rnsz, m-rnsz, x(l:), x(r:), y(l:), order)\n else if (m > 0) then\n l = (n-m)+1\n y(l:) = x(l:)\n end if\n x = y\n rnsz = 2*rnsz\n end do\n call merge_arrays(rnsz, n-rnsz, x(1:rnsz), x(rnsz+1:n), y, order)\n end subroutine sort_reals\n\n subroutine sort_strings(n, x, y, order)\n implicit none\n ! dummy arguments\n integer, intent(in) :: n\n character (len = *), intent(inout), dimension(n) :: x, y\n character (len = *), intent(in) :: order\n ! local data\n integer i, j, rnsz, m, l, r\n\n rnsz = 1\n do\n if (2*rnsz > n) exit\n l = 1\n r = l+rnsz\n do\n if (r+rnsz > n+1) exit\n call merge_arrays(rnsz, rnsz, x(l:), x(r:), y(l:), order)\n l = l+2*rnsz\n r = l+rnsz\n end do\n m = mod(n, 2*rnsz)\n if (m > rnsz) then\n l = (n-m)+1\n r = l+rnsz\n call merge_arrays(rnsz, m-rnsz, x(l:), x(r:), y(l:), order)\n else if (m > 0) then\n l = (n-m)+1\n y(l:) = x(l:)\n end if\n x = y\n rnsz = 2*rnsz\n end do\n call merge_arrays(rnsz, n-rnsz, x(1:rnsz), x(rnsz+1:n), y, order)\n end subroutine sort_strings \n\n subroutine merge_integers(m, n, x, y, z, order)\n implicit none\n ! dummy arguments\n integer, intent(in) :: m, n\n integer, dimension(m), intent(in) :: x\n integer, dimension(n), intent(in) :: y\n integer, dimension(m+n), intent(out) :: z\n character (len = *), intent(in) :: order\n ! local data\n integer :: i, j, k\n ! processing\n i = 1\n j = 1\n k = 1\n do\n if (k > m+n) exit\n if (i > m) then\n z(k:m+n) = y(j:n)\n return\n else if (j > n) then\n z(k:m+n) = x(i:m)\n return\n else if (order == 'ASC' .and. x(i) <= y(j)) then\n z(k) = x(i)\n i = i+1\n else if (order == 'DESC' .and. x(i) >= y(j)) then\n z(k) = x(i)\n i = i + 1\n else\n z(k) = y(j)\n j = j+1\n end if\n k = k+1\n end do\n end subroutine merge_integers\n\n subroutine merge_reals(m, n, x, y, z, order)\n implicit none\n ! dummy arguments\n integer, intent(in) :: m, n\n double precision, dimension(m), intent(in) :: x\n double precision, dimension(n), intent(in) :: y\n double precision, dimension(m+n), intent(out) :: z\n character (len = *), intent(in) :: order\n ! local data\n integer :: i, j, k\n ! processing\n i = 1\n j = 1\n k = 1\n do\n if (k > m+n) exit\n if (i > m) then\n z(k:m+n) = y(j:n)\n return\n else if (j > n) then\n z(k:m+n) = x(i:m)\n return\n else if (order == 'ASC' .and. x(i) <= y(j)) then\n z(k) = x(i)\n i = i+1\n else if (order == 'DESC' .and. x(i) >= y(j)) then\n z(k) = x(i)\n i = i+1\n else\n z(k) = y(j)\n j = j+1\n end if\n k = k+1\n end do\n end subroutine merge_reals\n\n subroutine merge_strings(m, n, x, y, z, order)\n implicit none\n ! dummy arguments\n integer, intent(in) :: m, n\n character (len = *), dimension(m), intent(in) :: x\n character (len = *), dimension(n), intent(in) :: y\n character (len = *), dimension(m+n), intent(out) :: z\n character (len = *), intent(in) :: order\n ! local data\n integer :: i, j, k\n ! processing\n i = 1\n j = 1\n k = 1\n do\n if (k > m+n) exit\n if (i > m) then\n z(k:m+n) = y(j:n)\n return\n else if (j > n) then\n z(k:m+n) = x(i:m)\n return\n else if (order == 'ASC' .and. x(i) <= y(j)) then\n z(k) = x(i)\n i = i+1\n else if (order == 'DESC' .and. x(i) >= y(j)) then\n z(k) = x(i)\n i = i+1\n else\n z(k) = y(j)\n j = j+1\n end if\n k = k+1\n end do\n end subroutine merge_strings \n\n function sorted_integers(n, a, order) result(b)\n implicit none\n ! dummy arguments\n integer, intent(in) :: n\n integer, dimension(n), intent(in) :: a\n character (len = *), intent(in) :: order\n ! function return location\n logical :: b\n ! local data\n integer :: i\n ! processing\n i = 1\n do\n if (i == n-1) exit\n if (order == 'ASC' .and. a(i+1) < a(i)) exit\n if (order == 'DESC' .and. a(i+1) > a(i)) exit\n i = i + 1\n end do\n if (i == n-1) then\n b = .true.\n else\n b = .false.\n end if\n end function sorted_integers\n\n function sorted_reals(n, a, order) result(b)\n implicit none\n ! dummy arguments\n integer, intent(in) :: n\n double precision, dimension(n), intent(in) :: a\n character (len = *), intent(in) :: order\n ! function return location\n logical :: b\n ! local data\n integer :: i\n ! processing\n i = 1\n do\n if (i == n-1) then\n exit\n else if (order == 'ASC' .and. a(i+1) < a(i)) then\n exit\n else if (order == 'DESC' .and. a(i+1) > a(i)) then\n exit\n else\n i = i + 1\n end if\n end do\n if (i == n-1) then\n b = .true.\n else\n b = .false.\n end if\n end function sorted_reals\n\n function sorted_strings(n, a, order) result(b)\n implicit none\n ! dummy arguments\n integer, intent(in) :: n\n character (len = *), dimension(n), intent(in) :: a\n character (len = *), intent(in) :: order\n ! function return location\n logical :: b\n ! local data\n integer :: i\n ! processing\n i = 1\n do\n if (i == n-1) then\n exit\n else if (order == 'ASC' .and. a(i+1) < a(i)) then\n exit\n else if (order == 'DESC' .and. a(i+1) > a(i)) then\n exit\n else\n i = i + 1\n end if \n end do\n if (i == n-1) then\n b = .true.\n else\n b = .false.\n end if\n end function sorted_strings \nend module\n", "meta": {"hexsha": "827be8df3626a71f5ca0ee2cb18f4e1d2283ebf8", "size": 8594, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "mergesort_module.f95", "max_stars_repo_name": "joshroybal/mergesort-fortran", "max_stars_repo_head_hexsha": "33aabb835ae358510e5251c51b430d88fb373bda", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "mergesort_module.f95", "max_issues_repo_name": "joshroybal/mergesort-fortran", "max_issues_repo_head_hexsha": "33aabb835ae358510e5251c51b430d88fb373bda", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "mergesort_module.f95", "max_forks_repo_name": "joshroybal/mergesort-fortran", "max_forks_repo_head_hexsha": "33aabb835ae358510e5251c51b430d88fb373bda", "max_forks_repo_licenses": ["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.85625, "max_line_length": 71, "alphanum_fraction": 0.4617174773, "num_tokens": 2678, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835289107309, "lm_q2_score": 0.7905303137346446, "lm_q1q2_score": 0.6604750562299281}} {"text": " subroutine pldp(l,pp,d)\n common/gfgmp/p1(2),p2(2)\n real l(3),p(2) ,pp(2),l1(3)\n l1(1)=-l(2)\n l1(2)=l(1)\n l1(3)=l(2)*pp(1)-l(1)*pp(2)\n s=l1(2)*l(1)-l(2)*l1(1)\n p(1)=(l1(3)*l(2)-l(3)*l1(2))/s\n p(2)=(l(3)*l1(1)-l1(3)*l(1))/s\n if(l(2).eq.0.) goto 20\n alp=l(1)**2+l(2)**2\n bet=l(1)*l(3)+l(1)*l(2)*p(2)-l(2)**2*p(1)\n gam=l(2)**2*p(1)**2+(l(3)+l(2)*p(2))**2-l(2)**2*d**2\n e=bet**2-alp*gam\n p1(1)=(-bet+sqrt(e))/alp\n p1(2)=-(l(1)*p1(1)+l(3))/l(2)\n p2(1)=(-bet-sqrt(e))/alp\n p2(2)=-(l(1)*p2(1)+l(3))/l(2)\n return\n 20 f=d**2-(l(3)/l(1)+p(1))**2\n p1(1)=-l(3)/l(1)\n p1(2)=p(2)-sqrt(f)\n p2(1)=-l(3)/l(1)\n p2(2)=p(2)+sqrt(f)\n return\n end\n", "meta": {"hexsha": "8ace64ec97885d50943fcead89cc005292919306", "size": 798, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ftn/pldp.f", "max_stars_repo_name": "sergev/grafor", "max_stars_repo_head_hexsha": "2b7b244d84b739bdcdf1717824ee895eb015c4a0", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-11-23T08:32:55.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-12T14:05:06.000Z", "max_issues_repo_path": "ftn/pldp.f", "max_issues_repo_name": "sergev/grafor", "max_issues_repo_head_hexsha": "2b7b244d84b739bdcdf1717824ee895eb015c4a0", "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": "ftn/pldp.f", "max_forks_repo_name": "sergev/grafor", "max_forks_repo_head_hexsha": "2b7b244d84b739bdcdf1717824ee895eb015c4a0", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.5555555556, "max_line_length": 60, "alphanum_fraction": 0.3684210526, "num_tokens": 431, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625088705931, "lm_q2_score": 0.7090191399336401, "lm_q1q2_score": 0.6604247469198585}} {"text": "subroutine compute_Cv(heat_cap) ! compute the heat capacity of the lattice using density of state\r\n use parameters\r\n integer :: tot_E\r\n double precision :: Z, E_avg, M_avg, E2_avg, weight\r\n double precision, intent(out) :: heat_cap\r\n \r\n Z = 0, E_avg = 0, M_avg = 0, E2_avg = 0, weight = 0\r\n do tot_E = -2*(latt_leng**2), 2*(latt_leng**2), 4\r\n weight = exp(-tot_E / T) * dens_of_tot_E\r\n Z = Z + weight\r\n E_avg = E_avg + weight * tot_E\r\n E2_avg = E2_avg + weight * tot_E ** 2\r\n end do\r\n E_avg = E_avg / Z\r\n E2_avg = E2_avg/ Z\r\n heat_cap = (E2_avg - E_avg ** 2) / (real (latt_leng**2, 8) * T**2)\r\nend subroutine\r\n\r\n\r\nsubroutine compute_density_of_state_E(dens_of_tot_E)\r\n use parameters\r\n integer :: tot_E\r\n integer, dimension(-2*(latt_leng**2) : 2*(latt_leng**2) : 4), intent(out) :: dens_of_tot_E\r\n \r\n do tot_E = -2*(latt_leng**2), 2*(latt_leng**2), 4 ! compute density of state for each possible E\r\n dens_of_tot_E(tot_E) = \r\nend subroutine\r\n", "meta": {"hexsha": "76ff6874bbc77a6b1fd2fedeb6cd8b4bf841ca0f", "size": 1003, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src-fortran/compute_Cv_brute_force.f95", "max_stars_repo_name": "swlee23/ising-model", "max_stars_repo_head_hexsha": "4fc88612a5330d8e52ce3809673b3689c65aeac7", "max_stars_repo_licenses": ["MIT"], "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-fortran/compute_Cv_brute_force.f95", "max_issues_repo_name": "swlee23/ising-model", "max_issues_repo_head_hexsha": "4fc88612a5330d8e52ce3809673b3689c65aeac7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src-fortran/compute_Cv_brute_force.f95", "max_forks_repo_name": "swlee23/ising-model", "max_forks_repo_head_hexsha": "4fc88612a5330d8e52ce3809673b3689c65aeac7", "max_forks_repo_licenses": ["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.8214285714, "max_line_length": 100, "alphanum_fraction": 0.6251246261, "num_tokens": 344, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625145783428, "lm_q2_score": 0.7090191337850932, "lm_q1q2_score": 0.6604247452396214}} {"text": "! This module contains all mathematical and physical constants\n! This does not include constants which are configurable through input files,\nmodule constants\n use real_kind\n\n implicit none\n\n ! Mathematical constants: pi, 4pi, log(10) and 1/3\n real(double), parameter :: CPI = 3.1415926535897932384626433832795029D0\n real(double), parameter :: CPI4 = 4.0D0 * CPI\n real(double), parameter :: CLN = 2.3025850929940456840179914546843642D0\n real(double), parameter :: C3RD = 1.0D0/3.0D0\n\n ! Physical constants\n real(double), parameter :: CL = 2.99792458D10 ! Speed of light\n real(double), parameter :: PLANCK = 6.6260693D-27 ! Planck constant\n real(double), parameter :: CG = 6.6742D-8 ! Newton constant\n real(double), parameter :: BOLTZM = 1.3806505D-16 ! Boltzmann constant\n real(double), parameter :: ECHAR = 4.80320441D-10 ! Electrostatic charge\n\n real(double), parameter :: AMU = 1.660538862D-24 ! Atomic mass unit\n real(double), parameter :: AME = 9.1093826D-28 ! Electron mass\n\n ! Astrophysical parameters\n real(double), parameter :: CMSN = 1.98844D0 ! Solar mass\n real(double), parameter :: CLSN = 3.844D0 ! Solar luminosity\n real(double), parameter :: CRSN = 0.69598D0 ! Solar radius\n real(double), parameter :: CASN = 4.57D9 ! Solar age\n real(double), parameter :: CZSN = 0.02 ! solar metallicity \n\n ! Units\n real(double), parameter :: CSY = 3.155692597D7 ! Seconds per year\n real(double), parameter :: CSDAY = 86400D0 ! Seconds per day\n real(double), parameter :: EVOLT = ECHAR/CL*1.0D8 ! erg/electron volt\n\n ! Derived constants\n real(double), parameter :: CA = 8.0D0*CPI**5*BOLTZM**4 / (15.0D0 * (CL*PLANCK)**3)\n real(double), parameter :: CME = 1.0D6*EVOLT/AMU ! (erg/MeV) / (gram/amu)\n real(double), parameter :: CEVB = EVOLT/BOLTZM \n real(double), parameter :: CR = BOLTZM/AMU ! gas constant\n\n real(double), parameter :: LAMC = PLANCK/(AME*CL) ! Compton length of electron\n real(double), parameter :: CRHO = 8.0D0*CPI/LAMC**3\n\n real(double), parameter :: CB = CRHO*AME*CL**2 \n real(double), parameter :: CD = CRHO*AMU \n\n real(double), parameter :: CTE = BOLTZM/(AME*CL**2) \n real(double), parameter :: CGRT = 6.4D0*(CPI/4.32D4)**6*(1.0D11/CL)**5 \n\n ! Constants that cannot be computed at compile time\n real(double) :: CEN\n real(double) :: CPL\n real(double) :: CG1\n real(double) :: CG2\n\n !Debug:\n integer, parameter :: debug_level = 0 ! Debugging info: 0 - no debugging, 2 - print routine names when called\n\ncontains\n\n\n subroutine initialise_constants\n use real_kind\n use paquette_coefficients\n\n implicit none\n call initialise_collision_integrals\n CEN = (PLANCK/(2.0D0*CPI*AMU*BOLTZM)**0.5D0)**3 / AMU \n CPL = (CPI4/(AMU*BOLTZM**3))**0.5D0 * ECHAR**3 \n CG1 = 1.0D5*CG**0.5D0 \n CG2 = CG1*(CSDAY*1.0D-5) / (2.0D0 * CPI) \n end subroutine initialise_constants\n\nend module constants\n\n\n\n! Initialise constants, read in tables of physical data that are unchanged\n! during the course of one run \nsubroutine setsup\n use real_kind\n use constants\n use neutrinos\n use ltm2ubv\n\n implicit none\n\n ! Initialise some constants that cannot be computed at compile time on some\n ! compilers\n call initialise_constants\n\n ! Read nuclear reaction rates and neutrino loss parameters\n ! Used to be read from the same file as the opacity data, which is stupid\n ! since this is independent of metalicity\n call load_reaction_neutrino_rates(42)\n\n ! Read Bol. Corr, U-B, B-V table. \n call load_colour_conversion_table(21)\n\n ! Read nuclear reaction (QRT) and neutrino (QNT) Q values, in MeV; constants \n ! for electron screening (CZA, CZB, CZC, CZD, VZ); atomic parameters (CBN, KZN),\n ! with masses (CAN) consistent with Q-values; ionization potentials (CHI) and \n ! statistical weights (COM); molecular hydrogen parameters (CH2)\n call load_atomic_data(26)\n\nend subroutine setsup\n\n\n", "meta": {"hexsha": "9ad5184bba48297018058ca00bad417a69bf3e88", "size": 3967, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/amuse/community/evtwin/src/trunk/code/constants.f90", "max_stars_repo_name": "rknop/amuse", "max_stars_repo_head_hexsha": "85d5bdcc29cfc87dc69d91c264101fafd6658aec", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 131, "max_stars_repo_stars_event_min_datetime": "2015-06-04T09:06:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-01T12:11:29.000Z", "max_issues_repo_path": "src/amuse/community/evtwin/src/trunk/code/constants.f90", "max_issues_repo_name": "rknop/amuse", "max_issues_repo_head_hexsha": "85d5bdcc29cfc87dc69d91c264101fafd6658aec", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 690, "max_issues_repo_issues_event_min_datetime": "2015-10-17T12:18:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:15:58.000Z", "max_forks_repo_path": "src/amuse/community/evtwin/src/trunk/code/constants.f90", "max_forks_repo_name": "rieder/amuse", "max_forks_repo_head_hexsha": "3ac3b6b8f922643657279ddee5c8ab3fc0440d5e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 102, "max_forks_repo_forks_event_min_datetime": "2015-01-22T10:00:29.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-09T13:29:43.000Z", "avg_line_length": 36.0636363636, "max_line_length": 131, "alphanum_fraction": 0.6828837913, "num_tokens": 1238, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391727723469, "lm_q2_score": 0.7154240079185319, "lm_q1q2_score": 0.6603643844505986}} {"text": "! *********************************************************************\r\n! * *\r\n! * subroutine intr2d *\r\n! * *\r\n! *********************************************************************\r\n! Mixed Precision Version 2.31\r\n! Written by Gordon A. Fenton, TUNS, Aug. 26, 1992\r\n! Latest Update: Jun 9, 1999\r\n!\r\n! PURPOSE creates the parameter matrices required for the interior cell\r\n! subdivision of LAS2G.\r\n!\r\n! Requires:\r\n! 1) from libGAFsim:\tDSIFA, DSISL, DCHOL2, DAXPY, DSWAP, DDOT, IDAMAX\r\n!\r\n! n is the rank of [CC][CC^T]. It can be either n = 3 for the 2-D case or\r\n! n = 7 for the 3-D case.\r\n! mi is the mapping from the global covariance matrix `R' into the local\r\n! `interior' covariance matrix (in the 2-D case, this is 1-to-1).\r\n!\r\n! REVISION HISTORY:\r\n! 2.31\treplaced dummy dimensions with a (*) for GNU's compiler (Jun 9/99)\r\n!-----------------------------------------------------------------------------\r\n subroutine intr2d( R, ir, B, ib, S, is, CI, n, AI, mi, iout, tol )\r\n real*8 R(ir,*), B(ib,*), S(is,*)\r\n real*8 RI(9,9), DA(9), BB(7,7)\r\n real CI(*), AI(9,*)\r\n integer mi(*), indx(9)\r\n\r\n 1 format(a,a,a)\r\n 2 format(a,e13.4)\r\n!\t\t\t\t\t\t\textract R\r\n do 10 j = 1, 9\r\n do 10 i = 1, j\r\n RI(i,j) = R(mi(i),mi(j))\r\n 10 continue\r\n!\t\t\t\t\t\t\tfactorize R\r\n call dsifa( RI, 9, 9, indx, ierr )\r\n if( ierr .ne. 0 ) then\r\n write(iout,1)'Error: unable to factorize interior covariance matrix in INTR2D.'\r\n stop\r\n endif\r\n!\t\t\t\t\t\t\tmake a copy of S\r\n do 50 j = 1, n\r\n do 20 i = 1, 9\r\n DA(i) = S(mi(i),j)\r\n 20 continue\r\n!\t\t\t\t\t\t\tand solve for A\r\n call dsisl( RI, 9, 9, indx, DA )\r\n!\t\t\t\t\t\t\tstore in real*4\r\n do 30 i = 1, 9\r\n AI(i,j) = DA(i)\r\n 30 continue\r\n!\t\t\t\t\t\t\tupdate B\r\n do 40 i = 1, j\r\n BB(i,j) = B(i,j) &\r\n - S(mi(1),i)*DA(1)-S(mi(2),i)*DA(2)-S(mi(3),i)*DA(3) &\r\n - S(mi(4),i)*DA(4)-S(mi(5),i)*DA(5)-S(mi(6),i)*DA(6) &\r\n - S(mi(7),i)*DA(7)-S(mi(8),i)*DA(8)-S(mi(9),i)*DA(9) \r\n 40 continue\r\n 50 continue\r\n!\t\t\t\t\t\t\tCholesky Decomposition\r\n call dchol2( BB, 7, n, rerr )\r\n if( rerr .gt. tol ) then\r\n write(iout,1)'Intr2d: Cholesky decomposition of interior covariance matrix BB'\r\n write(iout,2)' has maximum relative error of ',rerr\r\n endif\r\n!\t\t\t\t\t\t\tstore in real*4\r\n ii = 0\r\n do 60 j = 1, n\r\n do 60 i = 1, j\r\n ii = ii + 1\r\n CI(ii) = BB(i,j)\r\n 60 continue\r\n\r\n return\r\n end\r\n", "meta": {"hexsha": "7dfbec8a5d5ce25b350e39612d2848003d933bbf", "size": 2857, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/libs/gaf95/intr2d.f95", "max_stars_repo_name": "leemargetts/PoreFEM", "max_stars_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/libs/gaf95/intr2d.f95", "max_issues_repo_name": "leemargetts/PoreFEM", "max_issues_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/libs/gaf95/intr2d.f95", "max_forks_repo_name": "leemargetts/PoreFEM", "max_forks_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.6282051282, "max_line_length": 89, "alphanum_fraction": 0.4133706685, "num_tokens": 887, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391706552536, "lm_q2_score": 0.7154239836484143, "lm_q1q2_score": 0.6603643605337101}} {"text": "C$Procedure VREL ( Vector relative difference, 3 dimensions )\n \n DOUBLE PRECISION FUNCTION VREL ( V1, V2 )\n \nC$ Abstract\nC\nC Return the relative difference between two 3-dimensional vectors.\nC\nC$ Disclaimer\nC\nC THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE\nC CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.\nC GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE\nC ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE\nC PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED \"AS-IS\"\nC TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY\nC WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A\nC PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC\nC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE\nC SOFTWARE AND RELATED MATERIALS, HOWEVER USED.\nC\nC IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA\nC BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT\nC LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,\nC INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,\nC REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE\nC REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.\nC\nC RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF\nC THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY\nC CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE\nC ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.\nC\nC$ Required_Reading\nC\nC None.\nC\nC$ Keywords\nC\nC MATH\nC VECTOR\nC\nC$ Declarations\n \n DOUBLE PRECISION V1 ( 3 )\n DOUBLE PRECISION V2 ( 3 )\n \nC$ Brief_I/O\nC\nC Variable I/O Description\nC -------- --- --------------------------------------------------\nC V1,V2 I Input vectors.\nC\nC$ Detailed_Input\nC\nC V1, V2 are two 3-dimensional vectors for which the\nC relative difference is to be computed.\nC\nC$ Detailed_Output\nC\nC VREL is the relative difference between V1 and V2.\nC It is defined as:\nC || V1 - V2 ||\nC VREL = ----------------------\nC MAX ( ||V1||, ||V2|| )\nC\nC where || X || indicates the Euclidean norm of\nC the vector X.\nC\nC VREL assumes values in the range [0,2]. If both\nC V1 and V2 are zero vectors then VREL is defined\nC to be zero.\nC\nC\nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC Error free.\nC\nC If both V1 and V2 are zero vectors then VREL is defined\nC to be zero.\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC This function computes the relative difference between two\nC 3-dimensional vectors as defined above.\nC\nC The function VRELG may be used to find the relative difference\nC for two vectors of general dimension.\nC\nC$ Examples\nC\nC This example code fragment computes the relative difference\nC between the geometric and light time corrected state of Io\nC with respect to Voyager 2 at a given UTC time.\nC\nC C\nC C The NAIF integer code for Io is 501 and the code for\nC C Voyager 2 is -32.\nC C\nC\nC INTEGER IO\nC PARAMETER ( IO = 501 )\nC\nC INTEGER VG2\nC PARAMETER ( VG2 = -32 )\nC\nC C\nC C Spicelib function\nC C\nC DOUBLE PRECISION VREL\nC C\nC C Local variables\nC C\nC DOUBLE PRECISION STATE ( 6 )\nC DOUBLE PRECISION POS1 ( 3 )\nC DOUBLE PRECISION POS2 ( 3 )\nC DOUBLE PRECISION DIFF\nC DOUBLE PRECISION LT\nC DOUBLE PRECISION ET\nC\nC INTEGER HANDLE\nC\nC CHARACTER*(20) UTC\nC\nC DATA UTC / '1979 JUN 25 12:00:00' /\nC\nC C\nC C Load the sample SPK ephemeris file.\nC C\nC CALL SPKLEF ( 'VG2_JUP.BSP', HANDLE )\nC C\nC C Convert the UTC time string to ephemeris time.\nC C\nC CALL UTC2ET ( UTC, ET )\nC C\nC C First calculate the geometric state and then the light\nC C time corrected state.\nC C\nC CALL SPKEZ ( IO, ET, 'J2000', 'NONE', VG2, STATE, LT )\nC\nC CALL VEQU ( STATE, POS1 )\nC\nC CALL SPKEZ ( IO, ET, 'J2000', 'LT', VG2, STATE, LT )\nC\nC CALL VEQU ( STATE, POS2 )\nC C\nC C Call VREL to find the relative difference between the\nC C two states.\nC C\nC DIFF = VREL ( POS1, POS2 )\nC\nC .\nC .\nC .\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC J.M. Lynch (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.0, 15-JUN-1992 (JML)\nC\nC-&\n \nC$ Index_Entries\nC\nC relative difference of 3-dimensional vectors\nC\nC-&\n \n \n \nC\nC SPICELIB functions\nC\n DOUBLE PRECISION VNORM\n DOUBLE PRECISION VDIST\n \n \nC\nC Local variables\nC\n DOUBLE PRECISION NUNORM\n DOUBLE PRECISION DENORM\n \n \n \n \n \n \nC\nC If the numerator is zero then set VREL equal to zero. Otherwise,\nC perform the rest of the calculation.\nC\nC This handles the case where both vectors are zero vectors since\nC the distance between them will be zero.\nC\n NUNORM = VDIST ( V1, V2 )\n \n IF ( NUNORM .EQ. 0.D0 ) THEN\n \n VREL = 0.D0\n \n ELSE\n \n DENORM = MAX ( VNORM(V1), VNORM(V2) )\n \n VREL = NUNORM / DENORM\n \n END IF\n \n \n RETURN\n END\n", "meta": {"hexsha": "6d6920350b6051326a976bae930302a4569a3681", "size": 5766, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/vrel.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/vrel.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/vrel.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.8534482759, "max_line_length": 71, "alphanum_fraction": 0.5863683663, "num_tokens": 1621, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.903294209307224, "lm_q2_score": 0.7310585844894971, "lm_q1q2_score": 0.6603609860336987}} {"text": "function ifft(yh) result(y)\n! FFT function\ncomplex(kind=8), intent(in) :: yh(:)\ninteger(kind=8) :: plan_backward\ncomplex(kind=8), allocatable :: y(:)\nallocate(y(size(yh)))\ncall dfftw_plan_dft_1d_ (plan_backward, size(yh), yh, y, FFTW_BACKWARD, FFTW_ESTIMATE)\ncall dfftw_execute(plan_backward)\ny = y/real(size(y),8)\nend function ifft", "meta": {"hexsha": "a33598fd4bd0f93dce1ea3f4f057fbca15565258", "size": 333, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "partitioned/fortran/tools/functions/ifft.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/ifft.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/ifft.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.3, "max_line_length": 86, "alphanum_fraction": 0.7357357357, "num_tokens": 109, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941962904956, "lm_q2_score": 0.731058584489497, "lm_q1q2_score": 0.6603609765177075}} {"text": "!***********************************************************************\n! *\n REAL(KIND(0.0D0)) FUNCTION WIGNER_3j(JA,JB,JC,MA,MB,MC)\n! *\n! Calculates the Wigner 3-j symbol by its algebraic formulae as *\n! displayed in many texts on the theory of angular momentum *\n! ((5.1) see R. D. Cowan, The Theory of Atomic Structure and *\n! Spectra; University of California Press, 1981, p. 142). *\n! The integer arguments ja,... of this function must be the double *\n! of the corresponding quantum numbers in the 3-j symbol, i.e. *\n! jk = jk' + jk', mk = mk' + mk' in *\n! *\n! ( ja' jb' jc' ) *\n! ( ) *\n! ( ma' mb' mc' ) *\n! *\n! *\n! Written by G. Gaigalas and D. Kato *\n! NIFS, Japan, September 2013 *\n! The last modification made by G. Gaigalas June 2018 *\n! *\n!***********************************************************************\n!\n!-----------------------------------------------\n! M o d u l e s\n!-----------------------------------------------\n USE vast_kind_param, ONLY: DOUBLE\n USE CONS_C, ONLY: ZERO, ONE\n USE FACTS_C\n!-----------------------------------------------\n! I n t e r f a c e B l o c k s\n!-----------------------------------------------\n USE ittk_I\n IMPLICIT NONE\n!-----------------------------------------------\n! D u m m y A r g u m e n t s\n!-----------------------------------------------\n INTEGER, INTENT(IN) :: JA, JB, JC, MA, MB, MC\n!-----------------------------------------------\n! L o c a l V a r i a b l e s\n!----------------------------------------------\n INTEGER, DIMENSION(14) :: IK\n INTEGER :: K, KMIN, KMAX, I\n REAL(DOUBLE) :: DELTA, SUMK, SUM\n!----------------------------------------------\n!\n! Test the triangular condition and that for magnetic quantum numbers\n!\n IF(MA+MB+MC /= 0 ) THEN\n WIGNER_3j = ZERO\n RETURN\n ELSE IF(ITTK(JA,JB,JC) == 0) THEN\n WIGNER_3j = ZERO\n RETURN\n ELSE IF(IABS(MA) > JA .OR. IABS(MB) > JB &\n .OR. IABS(MC) > JC) THEN\n WIGNER_3j = ZERO\n RETURN\n END IF\n IK( 1) = JA+JB-JC\n IK( 2) = JA-JB+JC\n IK( 3) = -JA+JB+JC\n IK( 4) = JA+JB+JC+2\n IK( 5) = JA-MA\n IK( 6) = JA+MA\n IK( 7) = JB-MB\n IK( 8) = JB+MB\n IK( 9) = JC-MC\n IK(10) = JC+MC\n IK(11) = JB-JC-MA\n IK(12) = JA-JC+MB\n IK(13) = JC-JB+MA\n IK(14) = JA-JB-MC\n DO I = 1,14\n IF(MOD(IK(I),2) /= 0) THEN\n WRITE(0,*) 'Antras',I,IK(I)\n WIGNER_3j = ZERO\n RETURN\n END IF\n IK(I) = IK(I)/2\n END DO\n!\n! Calculate the 3-j delta factor\n DELTA = DEXP(GAM(IK(1)+1))*DEXP(GAM(IK(2)+1))*DEXP(GAM(IK(3)+1)) &\n * DEXP(GAM(IK(5)+1))*DEXP(GAM(IK(6)+1))*DEXP(GAM(IK(7)+1)) &\n * DEXP(GAM(IK(8)+1))*DEXP(GAM(IK(9)+1))*DEXP(GAM(IK(10)+1))&\n /DEXP(GAM(IK(4)+1))\n!\n! Find out the intervall of summation k and sum up\n KMIN = MAX(0,IK(11),IK(12))\n KMAX = MIN(IK(1),IK(5),IK(8))\n !\n SUM = 0.0\n DO K = KMIN,KMAX\n SUMK = DEXP(GAM(K+1)) * DEXP(GAM(IK(1)-K+1)) &\n * DEXP(GAM(IK( 5)-K+1))* DEXP(GAM(IK(8)-K+1)) &\n * DEXP(GAM(IK(13)+K+1))* DEXP(GAM(K-IK(12)+1))\n SUMK = 1.0/SUMK\n IF(MOD(K,2) == 0) THEN\n SUM = SUM + SUMK\n ELSE\n SUM = SUM - SUMK\n END IF\n END DO\n IF(MOD(IK(14),2) /= 0) THEN\n WIGNER_3j = -SQRT(DELTA) * SUM\n ELSE\n WIGNER_3j = SQRT(DELTA) * SUM\n END IF\n RETURN\n END FUNCTION WIGNER_3j\n", "meta": {"hexsha": "ec7871aa92f6866523912ad1bcd7d8e8672a3141", "size": 4391, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "wigner_3j.f90", "max_stars_repo_name": "compas/cf_hamiltonian", "max_stars_repo_head_hexsha": "1f092bea271ed43829890466fa17f064a58082c7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "wigner_3j.f90", "max_issues_repo_name": "compas/cf_hamiltonian", "max_issues_repo_head_hexsha": "1f092bea271ed43829890466fa17f064a58082c7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-01-11T16:42:53.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-11T16:42:53.000Z", "max_forks_repo_path": "wigner_3j.f90", "max_forks_repo_name": "compas/cf_hamiltonian", "max_forks_repo_head_hexsha": "1f092bea271ed43829890466fa17f064a58082c7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.2053571429, "max_line_length": 75, "alphanum_fraction": 0.3384194944, "num_tokens": 1265, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941988938414, "lm_q2_score": 0.7310585727705127, "lm_q1q2_score": 0.6603609678352154}} {"text": " SUBROUTINE MD03BY( COND, N, R, LDR, IPVT, DIAG, QTB, DELTA, PAR,\n $ RANK, X, RX, TOL, DWORK, LDWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To determine a value for the parameter PAR such that if x solves\nC the system\nC\nC A*x = b , sqrt(PAR)*D*x = 0 ,\nC\nC in the least squares sense, where A is an m-by-n matrix, D is an\nC n-by-n nonsingular diagonal matrix, and b is an m-vector, and if\nC DELTA is a positive number, DXNORM is the Euclidean norm of D*x,\nC then either PAR is zero and\nC\nC ( DXNORM - DELTA ) .LE. 0.1*DELTA ,\nC\nC or PAR is positive and\nC\nC ABS( DXNORM - DELTA ) .LE. 0.1*DELTA .\nC\nC It is assumed that a QR factorization, with column pivoting, of A\nC is available, that is, A*P = Q*R, where P is a permutation matrix,\nC Q has orthogonal columns, and R is an upper triangular matrix\nC with diagonal elements of nonincreasing magnitude.\nC The routine needs the full upper triangle of R, the permutation\nC matrix P, and the first n components of Q'*b (' denotes the\nC transpose). On output, MD03BY also provides an upper triangular\nC matrix S such that\nC\nC P'*(A'*A + PAR*D*D)*P = S'*S .\nC\nC Matrix S is used in the solution process.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC COND CHARACTER*1\nC Specifies whether the condition of the matrices R and S\nC should be estimated, as follows:\nC = 'E' : use incremental condition estimation for R and S;\nC = 'N' : do not use condition estimation, but check the\nC diagonal entries of R and S for zero values;\nC = 'U' : use the rank already stored in RANK (for R).\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The order of the matrix R. N >= 0.\nC\nC R (input/output) DOUBLE PRECISION array, dimension (LDR, N)\nC On entry, the leading N-by-N upper triangular part of this\nC array must contain the upper triangular matrix R.\nC On exit, the full upper triangle is unaltered, and the\nC strict lower triangle contains the strict upper triangle\nC (transposed) of the upper triangular matrix S.\nC\nC LDR INTEGER\nC The leading dimension of array R. LDR >= MAX(1,N).\nC\nC IPVT (input) INTEGER array, dimension (N)\nC This array must define the permutation matrix P such that\nC A*P = Q*R. Column j of P is column IPVT(j) of the identity\nC matrix.\nC\nC DIAG (input) DOUBLE PRECISION array, dimension (N)\nC This array must contain the diagonal elements of the\nC matrix D. DIAG(I) <> 0, I = 1,...,N.\nC\nC QTB (input) DOUBLE PRECISION array, dimension (N)\nC This array must contain the first n elements of the\nC vector Q'*b.\nC\nC DELTA (input) DOUBLE PRECISION\nC An upper bound on the Euclidean norm of D*x. DELTA > 0.\nC\nC PAR (input/output) DOUBLE PRECISION\nC On entry, PAR must contain an initial estimate of the\nC Levenberg-Marquardt parameter. PAR >= 0.\nC On exit, it contains the final estimate of this parameter.\nC\nC RANK (input or output) INTEGER\nC On entry, if COND = 'U', this parameter must contain the\nC (numerical) rank of the matrix R.\nC On exit, this parameter contains the numerical rank of\nC the matrix S.\nC\nC X (output) DOUBLE PRECISION array, dimension (N)\nC This array contains the least squares solution of the\nC system A*x = b, sqrt(PAR)*D*x = 0.\nC\nC RX (output) DOUBLE PRECISION array, dimension (N)\nC This array contains the matrix-vector product -R*P'*x.\nC\nC Tolerances\nC\nC TOL DOUBLE PRECISION\nC If COND = 'E', the tolerance to be used for finding the\nC rank of the matrices R and S. If the user sets TOL > 0,\nC then the given value of TOL is used as a lower bound for\nC the reciprocal condition number; a (sub)matrix whose\nC estimated condition number is less than 1/TOL is\nC considered to be of full rank. If the user sets TOL <= 0,\nC then an implicitly computed, default tolerance, defined by\nC TOLDEF = N*EPS, is used instead, where EPS is the machine\nC precision (see LAPACK Library routine DLAMCH).\nC This parameter is not relevant if COND = 'U' or 'N'.\nC\nC Workspace\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, the first N elements of this array contain the\nC diagonal elements of the upper triangular matrix S.\nC\nC LDWORK INTEGER\nC The length of the array DWORK.\nC LDWORK >= 4*N, if COND = 'E';\nC LDWORK >= 2*N, if COND <> 'E'.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value.\nC\nC METHOD\nC\nC The algorithm computes the Gauss-Newton direction. A least squares\nC solution is found if the Jacobian is rank deficient. If the Gauss-\nC Newton direction is not acceptable, then an iterative algorithm\nC obtains improved lower and upper bounds for the parameter PAR.\nC Only a few iterations are generally needed for convergence of the\nC algorithm. If, however, the limit of ITMAX = 10 iterations is\nC reached, then the output PAR will contain the best value obtained\nC so far. If the Gauss-Newton step is acceptable, it is stored in x,\nC and PAR is set to zero, hence S = R.\nC\nC REFERENCES\nC\nC [1] More, J.J., Garbow, B.S, and Hillstrom, K.E.\nC User's Guide for MINPACK-1.\nC Applied Math. Division, Argonne National Laboratory, Argonne,\nC Illinois, Report ANL-80-74, 1980.\nC\nC NUMERICAL ASPECTS\nC 2\nC The algorithm requires 0(N ) operations and is backward stable.\nC\nC FURTHER COMMENTS\nC\nC This routine is a LAPACK-based modification of LMPAR from the\nC MINPACK package [1], and with optional condition estimation.\nC The option COND = 'U' is useful when dealing with several\nC right-hand side vectors, but RANK should be reset.\nC If COND = 'E', but the matrix S is guaranteed to be nonsingular\nC and well conditioned relative to TOL, i.e., rank(R) = N, and\nC min(DIAG) > 0, then its condition is not estimated.\nC\nC CONTRIBUTORS\nC\nC V. Sima, Research Institute for Informatics, Bucharest, Dec. 2001.\nC\nC REVISIONS\nC\nC V. Sima, Research Institute for Informatics, Bucharest, Mar. 2005.\nC\nC KEYWORDS\nC\nC Linear system of equations, matrix operations, plane rotations.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n INTEGER ITMAX\n PARAMETER ( ITMAX = 10 )\n DOUBLE PRECISION P1, P001, ZERO, SVLMAX\n PARAMETER ( P1 = 1.0D-1, P001 = 1.0D-3, ZERO = 0.0D0,\n $ SVLMAX = 0.0D0 )\nC .. Scalar Arguments ..\n CHARACTER COND\n INTEGER INFO, LDR, LDWORK, N, RANK\n DOUBLE PRECISION DELTA, PAR, TOL\nC .. Array Arguments ..\n INTEGER IPVT(*)\n DOUBLE PRECISION DIAG(*), DWORK(*), QTB(*), R(LDR,*), RX(*), X(*)\nC .. Local Scalars ..\n INTEGER ITER, J, L, N2\n DOUBLE PRECISION DMINO, DWARF, DXNORM, FP, GNORM, PARC, PARL,\n $ PARU, TEMP, TOLDEF\n LOGICAL ECOND, NCOND, SING, UCOND\n CHARACTER CONDL\nC .. Local Arrays ..\n DOUBLE PRECISION DUM(3)\nC .. External Functions ..\n DOUBLE PRECISION DDOT, DLAMCH, DNRM2\n LOGICAL LSAME\n EXTERNAL DDOT, DLAMCH, DNRM2, LSAME\nC .. External Subroutines ..\n EXTERNAL DAXPY, DCOPY, DSWAP, DTRMV, DTRSV, MB02YD,\n $ MB03OD, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC ABS, DBLE, MAX, MIN, SQRT\nC ..\nC .. Executable Statements ..\nC\nC Check the scalar input parameters.\nC\n ECOND = LSAME( COND, 'E' )\n NCOND = LSAME( COND, 'N' )\n UCOND = LSAME( COND, 'U' )\n INFO = 0\n IF( .NOT.( ECOND .OR. NCOND .OR. UCOND ) ) THEN\n INFO = -1\n ELSEIF( N.LT.0 ) THEN\n INFO = -2\n ELSEIF ( LDR.LT.MAX( 1, N ) ) THEN\n INFO = -4\n ELSEIF ( DELTA.LE.ZERO ) THEN\n INFO = -8\n ELSEIF( PAR.LT.ZERO ) THEN\n INFO = -9\n ELSEIF ( UCOND .AND. ( RANK.LT.0 .OR. RANK.GT.N ) ) THEN\n INFO = -10\n ELSEIF ( LDWORK.LT.2*N .OR. ( ECOND .AND. LDWORK.LT.4*N ) ) THEN\n INFO = -15\n ELSEIF ( N.GT.0 ) THEN\n DMINO = DIAG(1)\n SING = .FALSE.\nC\n DO 10 J = 1, N\n IF ( DIAG(J).LT.DMINO )\n $ DMINO = DIAG(J)\n SING = SING .OR. DIAG(J).EQ.ZERO\n 10 CONTINUE\nC\n IF ( SING )\n $ INFO = -6\n END IF\nC\nC Return if there are illegal arguments.\nC\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'MD03BY', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF ( N.EQ.0 ) THEN\n PAR = ZERO\n RANK = 0\n RETURN\n END IF\nC\nC DWARF is the smallest positive magnitude.\nC\n DWARF = DLAMCH( 'Underflow' )\n N2 = N\nC\nC Estimate the rank of R, if required.\nC\n IF ( ECOND ) THEN\n N2 = 2*N\n TEMP = TOL\n IF ( TEMP.LE.ZERO ) THEN\nC\nC Use the default tolerance in rank determination.\nC\n TEMP = DBLE( N )*DLAMCH( 'Epsilon' )\n END IF\nC\nC Estimate the reciprocal condition number of R and set the rank.\nC Workspace: 2*N.\nC\n CALL MB03OD( 'No QR', N, N, R, LDR, IPVT, TEMP, SVLMAX, DWORK,\n $ RANK, DUM, DWORK, LDWORK, INFO )\nC\n ELSEIF ( NCOND ) THEN\n J = 1\nC\n 20 CONTINUE\n IF ( R(J,J).NE.ZERO ) THEN\n J = J + 1\n IF ( J.LE.N )\n $ GO TO 20\n END IF\nC\n RANK = J - 1\n END IF\nC\nC Compute and store in x the Gauss-Newton direction. If the\nC Jacobian is rank-deficient, obtain a least squares solution.\nC The array RX is used as workspace.\nC\n CALL DCOPY( RANK, QTB, 1, RX, 1 )\n DUM(1) = ZERO\n IF ( RANK.LT.N )\n $ CALL DCOPY( N-RANK, DUM, 0, RX(RANK+1), 1 )\n CALL DTRSV( 'Upper', 'No transpose', 'Non unit', RANK, R, LDR,\n $ RX, 1 )\nC\n DO 30 J = 1, N\n L = IPVT(J)\n X(L) = RX(J)\n 30 CONTINUE\nC\nC Initialize the iteration counter.\nC Evaluate the function at the origin, and test\nC for acceptance of the Gauss-Newton direction.\nC\n ITER = 0\nC\n DO 40 J = 1, N\n DWORK(J) = DIAG(J)*X(J)\n 40 CONTINUE\nC\n DXNORM = DNRM2( N, DWORK, 1 )\n FP = DXNORM - DELTA\n IF ( FP.GT.P1*DELTA ) THEN\nC\nC Set an appropriate option for estimating the condition of\nC the matrix S.\nC\n IF ( UCOND ) THEN\n IF ( LDWORK.GE.4*N ) THEN\n CONDL = 'E'\n TOLDEF = DBLE( N )*DLAMCH( 'Epsilon' )\n ELSE\n CONDL = 'N'\n TOLDEF = TOL\n END IF\n ELSE\n CONDL = COND\n TOLDEF = TOL\n END IF\nC\nC If the Jacobian is not rank deficient, the Newton\nC step provides a lower bound, PARL, for the zero of\nC the function. Otherwise set this bound to zero.\nC\n IF ( RANK.EQ.N ) THEN\nC\n DO 50 J = 1, N\n L = IPVT(J)\n RX(J) = DIAG(L)*( DWORK(L)/DXNORM )\n 50 CONTINUE\nC\n CALL DTRSV( 'Upper', 'Transpose', 'Non unit', N, R, LDR,\n $ RX, 1 )\n TEMP = DNRM2( N, RX, 1 )\n PARL = ( ( FP/DELTA )/TEMP )/TEMP\nC\nC For efficiency, use CONDL = 'U', if possible.\nC\n IF ( .NOT.LSAME( CONDL, 'U' ) .AND. DMINO.GT.ZERO )\n $ CONDL = 'U'\n ELSE\n PARL = ZERO\n END IF\nC\nC Calculate an upper bound, PARU, for the zero of the function.\nC\n DO 60 J = 1, N\n L = IPVT(J)\n RX(J) = DDOT( J, R(1,J), 1, QTB, 1 )/DIAG(L)\n 60 CONTINUE\nC\n GNORM = DNRM2( N, RX, 1 )\n PARU = GNORM/DELTA\n IF ( PARU.EQ.ZERO )\n $ PARU = DWARF/MIN( DELTA, P1 )/P001\nC\nC If the input PAR lies outside of the interval (PARL,PARU),\nC set PAR to the closer endpoint.\nC\n PAR = MAX( PAR, PARL )\n PAR = MIN( PAR, PARU )\n IF ( PAR.EQ.ZERO )\n $ PAR = GNORM/DXNORM\nC\nC Beginning of an iteration.\nC\n 70 CONTINUE\n ITER = ITER + 1\nC\nC Evaluate the function at the current value of PAR.\nC\n IF ( PAR.EQ.ZERO )\n $ PAR = MAX( DWARF, P001*PARU )\n TEMP = SQRT( PAR )\nC\n DO 80 J = 1, N\n RX(J) = TEMP*DIAG(J)\n 80 CONTINUE\nC\nC Solve the system A*x = b , sqrt(PAR)*D*x = 0 , in a least\nC square sense. The first N elements of DWORK contain the\nC diagonal elements of the upper triangular matrix S, and\nC the next N elements contain the vector z, so that x = P*z.\nC The vector z is preserved if COND = 'E'.\nC Workspace: 4*N, if CONDL = 'E';\nC 2*N, if CONDL <> 'E'.\nC\n CALL MB02YD( CONDL, N, R, LDR, IPVT, RX, QTB, RANK, X,\n $ TOLDEF, DWORK, LDWORK, INFO )\nC\n DO 90 J = 1, N\n DWORK(N2+J) = DIAG(J)*X(J)\n 90 CONTINUE\nC\n DXNORM = DNRM2( N, DWORK(N2+1), 1 )\n TEMP = FP\n FP = DXNORM - DELTA\nC\nC If the function is small enough, accept the current value\nC of PAR. Also test for the exceptional cases where PARL\nC is zero or the number of iterations has reached ITMAX.\nC\n IF ( ABS( FP ).GT.P1*DELTA .AND.\n $ ( PARL.NE.ZERO .OR. FP.GT.TEMP .OR. TEMP.GE.ZERO ) .AND.\n $ ITER.LT.ITMAX ) THEN\nC\nC Compute the Newton correction.\nC\n DO 100 J = 1, RANK\n L = IPVT(J)\n RX(J) = DIAG(L)*( DWORK(N2+L)/DXNORM )\n 100 CONTINUE\nC\n IF ( RANK.LT.N )\n $ CALL DCOPY( N-RANK, DUM, 0, RX(RANK+1), 1 )\n CALL DSWAP( N, R, LDR+1, DWORK, 1 )\n CALL DTRSV( 'Lower', 'No transpose', 'Non Unit', RANK,\n $ R, LDR, RX, 1 )\n CALL DSWAP( N, R, LDR+1, DWORK, 1 )\n TEMP = DNRM2( RANK, RX, 1 )\n PARC = ( ( FP/DELTA )/TEMP )/TEMP\nC\nC Depending on the sign of the function, update PARL\nC or PARU.\nC\n IF ( FP.GT.ZERO ) THEN\n PARL = MAX( PARL, PAR )\n ELSE IF ( FP.LT.ZERO ) THEN\n PARU = MIN( PARU, PAR )\n END IF\nC\nC Compute an improved estimate for PAR.\nC\n PAR = MAX( PARL, PAR + PARC )\nC\nC End of an iteration.\nC\n GO TO 70\n END IF\n END IF\nC\nC Compute -R*P'*x = -R*z.\nC\n IF ( ECOND .AND. ITER.GT.0 ) THEN\nC\n DO 110 J = 1, N\n RX(J) = -DWORK(N+J)\n 110 CONTINUE\nC\n CALL DTRMV( 'Upper', 'NoTranspose', 'NonUnit', N, R, LDR,\n $ RX, 1 )\n ELSE\nC\n DO 120 J = 1, N\n RX(J) = ZERO\n L = IPVT(J)\n CALL DAXPY( J, -X(L), R(1,J), 1, RX, 1 )\n 120 CONTINUE\nC\n END IF\nC\nC Termination. If PAR = 0, set S.\nC\n IF ( ITER.EQ.0 ) THEN\n PAR = ZERO\nC\n DO 130 J = 1, N - 1\n DWORK(J) = R(J,J)\n CALL DCOPY( N-J, R(J,J+1), LDR, R(J+1,J), 1 )\n 130 CONTINUE\nC\n DWORK(N) = R(N,N)\n END IF\nC\n RETURN\nC\nC *** Last line of MD03BY ***\n END\n", "meta": {"hexsha": "5103acb823d8889bc9d977765e7762349ae0f533", "size": 16165, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MD03BY.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MD03BY.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MD03BY.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 32.2654690619, "max_line_length": 72, "alphanum_fraction": 0.5364676771, "num_tokens": 4896, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.7217432182679957, "lm_q1q2_score": 0.6603235596530959}} {"text": "!---------------------------------------------------------------------!\n! OWNER: Ithaca Combustion Enterprise, LLC !\n! COPYRIGHT: \u00a9 2012, Ithaca Combustion Enterprise, LLC !\n! LICENSE: BSD 3-Clause License (The complete text of the license can !\n! be found in the `LICENSE-ICE.txt' file included in the ISAT-CK7 !\n! source directory.) !\n!---------------------------------------------------------------------!\n\nsubroutine ell_rad_lower( n, gg, r )\n\n! Determine the radius r of the ball inscribed in the ellipsoid E given\n! by { x | norm(G^T * x) <=1 ), where G is an n x n lower triangular\n! matrix. The array gg contains the matrix G in packed format.\n\n! Method: r = 1 / sqrt(lam_max) where lam_max is the largest\n! eigenvalue of G * G^T\n\n! S.B. Pope 6/12/04\n\nimplicit none\n\ninteger, parameter :: k_dp = kind(1.d0)\ninteger, intent(in) :: n\nreal(k_dp), intent(in) :: gg((n*(n+1))/2)\nreal(k_dp), intent(out) :: r\n\ninteger :: info, i, j, k, nev, lwork, iwork(5*n), ifail(n)\nreal(k_dp) :: g(n,n), a(n,n), dum(1), ev(n), dumz(n,1), work(n*(n+8))\n\nlwork = n*(n+8)\n\n! unpack gg into g\nk = 0\ng = 0.d0\ndo j = 1, n\n do i = j, n\n k = k + 1\n\t g(i,j) = gg(k)\n end do\nend do\n\n! form a = A = G * G^T\na = g\ncall dtrmm ( 'R', 'L', 'T', 'N', n, n, 1.d0, g, n, a, n )\n\n! find first (smallest) eigenvalues of A\n\ncall dsyevx( 'N', 'I', 'L', n, a, n, dum, dum, n, n, 0.d0, nev, ev, dumz, n, &\n work, lwork, iwork, ifail, info )\n\nif( info /= 0 ) then ! use SVD instead\n call ell_chol2eig( n, gg, a, work )\n r = 1.d0 / work(1)\n return\nendif\n\nif( ev(1) <= 0.d0 ) then\n write(0,*)'ell_rad_lower: lam_min <=0 ', ev(1)\n stop\nendif\n\nr = 1.d0 / sqrt( ev(1) )\n\nreturn\nend subroutine ell_rad_lower\n", "meta": {"hexsha": "f5467a270353414add1ba881d002a880da25d168", "size": 1829, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/isat/ell_lib/ell_rad_lower.f90", "max_stars_repo_name": "xuhan425/isat_ffd", "max_stars_repo_head_hexsha": "3a5449f7e49b686c33fe0e97ca90ea8d92fc2f00", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-04-10T20:16:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-15T11:09:44.000Z", "max_issues_repo_path": "src/isat/ell_lib/ell_rad_lower.f90", "max_issues_repo_name": "xuhan425/isat_ffd", "max_issues_repo_head_hexsha": "3a5449f7e49b686c33fe0e97ca90ea8d92fc2f00", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-06-07T14:10:25.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-07T14:10:25.000Z", "max_forks_repo_path": "src/isat/ell_lib/ell_rad_lower.f90", "max_forks_repo_name": "xuhan425/isat_ffd", "max_forks_repo_head_hexsha": "3a5449f7e49b686c33fe0e97ca90ea8d92fc2f00", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-06-07T03:44:12.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-05T05:54:10.000Z", "avg_line_length": 27.7121212121, "max_line_length": 78, "alphanum_fraction": 0.5139420448, "num_tokens": 624, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900945711678, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6603235474785152}} {"text": "!*********************************************\n!To compile program:\n!\n! gfortran spin_hyperfine_module.F90 -lblas -fopenmp -llapack -o spin_hyperfine.exe\n!\n! Program can also be compiled without -lblas, -llapack and/or -fopenmp for debugging\n!\n!Tested with LAPACK-3.4.2\n!*********************************************\n\n\nmodule decoherence_stuff\n implicit none\n \n !Simulation parameters\n integer, parameter :: N = 1 \t\t\t\t!Number of Nuclei in simulation\n integer, parameter :: t_max = 10000 \t\t\t!Maximum number of timesteps\n integer, parameter :: dp=selected_real_kind(15,300)\t\t!precision of numerical values\n real(kind=dp), parameter :: interaction_constant = -0.04_dp \t!Interaction constant for hyperfine interaction\n complex(kind=dp), parameter :: TDSE_constant = (0.0_dp, 1.0E-5_dp)\t!TDSE wavefunction constant\n integer , parameter :: QN = 2**(N+1)\t\t\t\t!'Quantum' N, defined as 2^(N+1) which is the number of possible states\n \n \n !Simulation Variables\n complex(kind=dp), save, dimension(1:QN) :: C !Complex numbers corresponding to basis states\n real(kind=dp), save, dimension(1:QN,1:QN) :: H !Hamiltonian matrix for system\n real(kind=dp), save, dimension(1:QN,1:QN) :: basis !matrix of basis vectors (diagonalised)\n real(kind=dp), save, dimension(1:QN) :: e_spin_up_wf !Wavefunction corresponding to superpositon of electron spin up states\n \n !Error reporting\n integer, save :: ierr !Error integer\n \n \ncontains\n\n !*********************************************\n !\n !Performs Kronecker product of two matrices A and B producing matrix P\n !n and m correspond to the dimensions of A and x and y correspond to the dimensions of B\n !dimensions of P are assumed to be n*x and m*y\n !\n !*********************************************\n subroutine kronecker_product(A, B, P, n, m, x, y)\n implicit none\n integer :: i, j, k, l\n integer :: n, m, x, y\n complex(kind=dp), dimension(n, m) :: A\n complex(kind=dp), dimension(x, y) :: B\n complex(kind=dp), dimension(x*n, y*m) :: P\n \n do i = 1, n\n do j = 1, m\n \n\tdo k = 1, x\n\t do l = 1, y\n\t \n\t P((i-1)*x + k, (j-1)*y + l) = A(i, j) * B(k, l)\n\n\t end do\n\tend do\n\n end do\n end do\n \n return\n \n end subroutine kronecker_product\n \n !*********************************************\n !Generates a hamiltonian for the hyperfine interaction from pauli matrices\n !*********************************************\n subroutine hyperfine_hamiltonian\n implicit none\n integer :: i, j, k\n complex(kind=dp), dimension(3,2,2) :: pauli\n real(kind=dp), dimension(2,2) :: identity\n integer, dimension(1:N,1:N) :: diag_matrix\n complex(kind=dp), dimension(:,:), Allocatable :: A\n complex(kind=dp), dimension(2,2) :: B\n complex(kind=dp), dimension(:,:), Allocatable :: P\n \n pauli(1, 1, 2) = 1.0_dp\t\t!Pauli x\n pauli(1, 1, 1) = 0.0_dp\t\t!Pauli x\n pauli(1, 2, 2) = 0.0_dp\t\t!Pauli x\n pauli(1, 2, 1) = 1.0_dp\t\t!Pauli x\n \n pauli(2, 1, 1) = 1.0_dp\t\t!Pauli z\n pauli(2, 1, 2) = 0.0_dp\t\t!Pauli z\n pauli(2, 2, 1) = 0.0_dp\t\t!Pauli z\n pauli(2, 2, 2) = -1.0_dp\t\t!Pauli z\n \n pauli(3, 1, 2) = (0.0_dp, -1.0_dp) !Pauli y\n pauli(3, 1, 1) = 0.0_dp\t\t!Pauli y\n pauli(3, 2, 2) = 0.0_dp\t\t!Pauli y\n pauli(3, 2, 1) = (0.0_dp, 1.0_dp) !Pauli y\n \n identity(1, 1) = 1.0_dp\t\t!Identity matrix\n identity(2, 2) = 1.0_dp\t\t!Identity matrix\n identity(1, 2) = 0.0_dp\t\t!Identity matrix\n identity(2, 1) = 0.0_dp\t\t!Identity matrix\n \n !Creates a diagonal matrix for permuations of spin matrices\n do i = 1, N\n diag_matrix(i, i) = 1\n end do\n \n !k signifies each of the cartesian dimensions\n !x = 1\n !z = 2\n !y = 3\n do k = 1, 3\n \n !Loops over number of possible combinations of identity and pauli matrices\n do i = 1, N\n\t\n\t!Allocates A input matrix for kronecker_product first iteration\n\tAllocate(A(1:2, 1:2))\n\tif (ierr/=0) stop 'Error in allocating matrix initial A'\n\t\n\t!Allocate matrix result for kronecker product so it set as first pauli matrix\n\t!and then can be deallocated in loop\n\tAllocate(P(1:2, 1:2))\n\tif (ierr/=0) stop 'Error in allocating matrix initial P'\n\t\n\t!Sets up the first A input matrix as the k dimension pauli matrix\n\tP = pauli(k, 1:2, 1:2)\n\t\n\t!Loops over each matrix to be multiplied for this iteration\n\t!Each j is a possible interaction pair\n\tdo j = 1, N\n\t \n\t !Sets previous product as next input\n\t A = P\n\t \n\t !Deallocates product matrix so it can be reshaped\n\t Deallocate(P)\n\t if (ierr/=0) stop 'Error in deallocating matrix P in loop'\n\t \n\t !Finds the next matrix product based on diagonlised matrix\n\t if(diag_matrix(i, j) == 1) then\n\t !Sets the B input matrix as the kth dimensional pauli matrix\n\t B(1:2, 1:2) = pauli(k, 1:2, 1:2)\n\t else\n\t !Sets the B input matrix as the identity matrix (non-interaction)\n\t B(1:2, 1:2) = identity(1:2, 1:2)\n\t end if\n\t \n\t !Allocates P matrix to the size of size of the next k_product matrix\n\t Allocate(P(1:2**(j+1), 1:2**(j+1)))\n\t \n\t !Calls the tensor product for A and B producing P\n\t !Dimensions of A are determined by place in j loop\n\t call kronecker_product(A, B, P, 2**j, 2**j, 2, 2)\n\t \n\t !Deallocates input matrix A to prepare for next loop\n\t Deallocate(A)\n\t if (ierr/=0) stop 'Error in deallocating matrix A in loop'\n\t \n\t !Allocates input matrix A in next size to prepare for next loop\n\t Allocate(A(1:2**(j+1), 1:2**(j+1)))\n\t if (ierr/=0) stop 'Error in allocating matrix A in loop'\n\t \n\tend do\n\t\n\t!Deallocates A for this interaction\n\tDeallocate(A)\n\tif (ierr/=0) stop 'Error in deallocating matrix A at end of loop'\n\t\n\t!Adds P to hamiltonian in matrix at each loop\n\t!Allows for additional hamiltonian elements to be added later\n\tH(1:QN,1:QN) = H(1:QN,1:QN) + P(1:QN, 1:QN)\n\t\n\tDeallocate(P)\n\tif (ierr/=0) stop 'Error in deallocating matrix P at end'\n\t\n end do\n end do\n\n !Writes Hamiltonian to file for debugging\n open(400, file=\"hamiltonian.dat\")\n do i = 1, QN\n write(400, *) (INT(H(i, j)), j = 1, QN)\n end do\n close(400)\n \n !Multiplies all hamiltonian elements by hyperfine interaction constant\n !H = interaction_constant * H\n \n return\n \n end subroutine hyperfine_hamiltonian\n \n !*********************************************\n !\n !*********************************************\n subroutine magnetic_hamiltonian\n !placeholder\n end subroutine magnetic_hamiltonian\n \n !*********************************************\n ! Uses LAPACK to find eigenstates of hamiltonian H using DGEEV functions\n ! DSYEVD finds the eigenvectors and eigenvalues of symmetric matrices\n !\n ! LAPACK reference:\n !@BOOK{laug,\n ! AUTHOR = {Anderson, E. and Bai, Z. and Bischof, C. and\n ! Blackford, S. and Demmel, J. and Dongarra, J. and\n ! Du Croz, J. and Greenbaum, A. and Hammarling, S. and\n ! McKenney, A. and Sorensen, D.},\n ! TITLE = {{LAPACK} Users' Guide},\n ! EDITION = {Third},\n ! PUBLISHER = {Society for Industrial and Applied Mathematics},\n ! YEAR = {1999},\n ! ADDRESS = {Philadelphia, PA},\n ! ISBN = {0-89871-447-8 (paperback)} }\n !*********************************************\n subroutine find_eigenstates\n implicit none\n \n integer :: i, j\t\t\t\t\t\t\t!Loop integers\n integer, parameter :: LIWORK = 64\n\n \n real(kind=dp), dimension(1:QN) :: WR\t\t\t!Work (real)\n real(kind=dp), dimension(1:QN) :: WI\t\t\t!Work (imaginary)\n real(kind=dp), dimension(1:QN, 1:QN) :: A\n real(kind=dp), dimension(1:QN,1:QN) :: VL\n real(kind=dp), dimension(1:QN,1:QN) :: VR\n integer, dimension(1:LIWORK) :: WORK\n \n \n !Because A is overwritten by function\n A = H\n \n\n call DGEEV( 'N', 'V', QN, A, QN, WR, WI, VL, 1, VR, QN, WORK, LIWORK, ierr)\n\n\n if (ierr/=0) then\n print *, 'Error in solving eigenstates of hamiltonian'\n if (ierr<0) then\n\tprint *, 'value', ierr, 'had illegal value'\n else\n\tprint *, 'dgeev failed to converge'\n end if\n stop\n end if\n\n open(600, file='eigenstates.dat', iostat=ierr)\n if (ierr==0) then\n do j=1, QN\n\tif(WI(j)==0.0_dp) then\n\t write(600,*) 'Eigenvalue', j, '=', WR(j)\n\telse\n\t write(600,*) 'Eigenvalue', j, '=', WR(j), '+', WI(i), 'i'\n\tend if\n\t\n\twrite(600,*)\n\twrite(600,*) 'Eigenvector', j, '='\n\twrite(600,*)\n\t\n\tif(WI(j)==0.0_dp) then\n\t do i=1, QN\n\t write(600, *) VR(i, j)\n\t end do\n\telseif(WI(j)>=0.0_dp) then\n\t do i=1, QN\n\t write(600,*) VR(i, j), '+', VR(i, j+1), 'i'\n\t end do\n\telse\n\t do i=1, QN\n\t write(600,*) VR(i, j-1), '+', VR(i, j), 'i'\n\t end do\n\t end if\n\t \n\twrite(600,*)\n\t\n end do\n else\n stop 'Error in opening file eigenstates.dat'\n end if\n \n close(600, iostat=ierr)\n if (ierr/=0) stop 'Error in closing file eigenstates.dat'\n \n end subroutine find_eigenstates\n \n !*********************************************\n !Generates basis functions\n !\n !\n !\n !\n !*********************************************\n subroutine init_basis\n implicit none\n integer :: i, j !loop variables\n \n !Sets all values in basis matrix to 0 with double precision \n basis(:, :) = 0.0_dp\n \n !Sets up basis functions\n do i = 1, QN\n basis(i,i) = 1.0_dp\n end do\n \n !sets up complex values and \n e_spin_up_wf(:) = 0.0_dp\n C(:) = 0.0_dp\n \n do i = 1, (2**N)\n e_spin_up_wf(i) = 1.0_dp / (SQRT(REAL(2**N, kind=dp)))\n C(i) = 1.0_dp / (SQRT(REAL(2**N, kind=dp)))\n end do\n \n \n end subroutine init_basis\n \n !*********************************************\n !Finds \"fidelity\" of system in current state\n !\n !\n !\n !\n !\n !*********************************************\n subroutine fidelity(Fid)\n implicit none\n \n \n !Subroutine variables\n real(kind=dp) :: Fid !Fidelity variable for subroutine\n real(kind=dp) :: DDOT !DDOT for blas library\n \n!If BLAS is enabled when compiling (-lblas), this code segment\n!will be compiled into final program using BLAS functions\n#ifdef lblas\n \n Fid = (abs(DDOT(QN, e_spin_up_wf,1, C, 1)))**2\n \n!If BLAS is not enabled when compiling, this section of intrinsic functions\n!will be used instead.\n#else\n \n Fid = (abs(DOT_PRODUCT(e_spin_up_wf, C)))**2\n \n!ends the preprocessor if statement\n#endif\n \n !returns value of Fid from subroutine to main program\n return\n \n end subroutine fidelity\n \n !*********************************************\n !Integrates time dependant schroedinger equation with simple numeric differnetiation\n !\n !\n !\n !\n !\n !*********************************************\n subroutine intergrate_TDSE\n implicit none\n \n !Library header for OpenMP\n !Required for single memory multiple processor operations\n !Requires compiler flag -fopenmp in gnu compilers to enable\n include 'omp_lib.h'\n \n !subroutine variables\n integer :: i, j !Loop integers\n real(kind=dp) :: DDOT !BLAS library double precision dot product (required)\n\n real(kind=dp) :: Hij !Dot product of Hi and transpose of basis(j)\n complex(kind=dp) :: sum_C_H !Sum of Complex values multipled by Hij\n real(kind=dp), dimension(1:QN):: Hi !Vector resulting from matrix vector multiply of H and basis(i)\n \n \n !iterate j from 1 to QN\n do j=1,QN\n \n !Set summation to zero to initial addition in next loop\n sum_C_H = 0.0_dp\n \n !$OMP parallel do private(i, Hij, Hi) shared(C, H, j) reduction(+:sum_C_H)\n !iterate i from 1 to QN\n !With OpenMP enabled this loop is performed on each thread seperately\n !Values of sum_C_H are added together from each thread at end of loop\n do i=1,QN\n\t\n!If BLAS is enabled when compiling (-lblas), this code segment\n!will be compiled into final program using BLAS functions\n#ifdef lblas\n\t\n\t !call for double precision matrix vector multiply from BLAS\n\t !Multiplies Hamiltonian matrix with basis(i) to form vector Hi\n\t call DGEMV( 'N', QN, QN, 1.0_dp, H(1:QN, 1:QN), QN, &\n\t basis(i,1:QN), 1, 0.0_dp, Hi(1:QN), 1) \n \n\t !call for double precision dot product from BLAS\n\t !Performs dot product of transpose of basis(j) with Hi to form value Hij\n\t Hij = DDOT(QN,basis(j, 1:QN),1,Hi(1:QN),1)\n\t\n!If BLAS is not enabled when compiling, this section of intrinsic functions\n!will be used instead.\n#else\n\t\n\t !call for intrinsic matrix vector multiply\n\t !Multiplies Hamiltonian matrix with basis(i) to form vector Hi\n\t Hi = MATMUL(H, basis(i, 1:QN))\n \n\t !call for intrinsic dot product\n\t !Performs dot product of transpose of basis(j) with Hi to form value Hij\n\t Hij = DOT_PRODUCT(basis(j, 1:QN), Hi)\n\t\n!Ends preprocessor if block\n#endif\n\t\n\n\t!Adds product of C(i) and Hij to summation\n\t!This is processed individually on each thread then summed at end\n\t!if openMP is enabled (-fopenmp)\n\tsum_C_H = sum_C_H + C(i) * Hij \n\n end do\n !$OMP end parallel do\n !ends the parallel do loop for openMP\n \n !Find C(j) by multiplying TDSE_constant with sum_C_H\n C(j) = C(j) - TDSE_constant * sum_C_H\n \n end do\n\n \n \n end subroutine intergrate_TDSE\n\n \nend module decoherence_stuff\n\n!*********************************************\n!\n!Main program\n!\n!\n!\n!\n!*********************************************\nprogram hyperfine_spin_interaction\n use decoherence_stuff\n implicit none\n integer :: t\n integer :: i, j\n real(kind=dp) :: Fid\n real(kind=dp) :: sum_C_H\n real(kind=dp), dimension(1:QN):: Hi\n real(kind=dp) :: Hij\n \n !calls the hyperfine interaction hamiltonian subroutine\n !adds a hyperfine interaction hamiltonian for N nuclei and 1 electron\n !to H\n call hyperfine_hamiltonian\n\n!If LAPACK is enabled when compiling (-llapack), this code segment\n!will be compiled into final program using LAPACK functions \n!#ifdef llapack\n\n !calls the eigenstate solution subroutine which finds the\n !eigenvectors and eigenvalues of the hamiltonian\n !and writes them to file eigenstates.dat\n call find_eigenstates\n \n!#endif\n \n !calls the subroutine to initiate basis states\n call init_basis\n \n \n !Open output files for use in time loop\n !Opens file for c_vs_time.dat and assigns it value 100 and reports error if failure\n open(100, file=\"c_vs_time.dat\",iostat=ierr)\n if (ierr/=0) stop 'Error in opening file c_vs_time.dat'\n \n !Opens file for sum_c_vs_time.dat and assigns it value 200 and reports error if failure\n open(200, file=\"sum_c_vs_time.dat\",iostat=ierr)\n if (ierr/=0) stop 'Error in opening file sum_c_vs_time.dat'\n \n !Opens file for fidelity_vs_time.dat and assigns it value 300 and reports error if failure\n open(300, file=\"fidelity_vs_time.dat\",iostat=ierr)\n if (ierr/=0) stop 'Error in opening file fidelity_vs_time.dat'\n \n !Loops over time from t= 1 to tmax which is set in module header\n do t = 1, t_max\n \n !Calls the subroutine to integrate the TDSE\n call intergrate_TDSE\n \n !Calls the fidelity function which finds the fidelity\n !of the system compared to e_spin_up_wf which\n !is a superpostion of the states which contain a spin up electron\n call fidelity(Fid)\n\n\n !write to output file\n !writes probability of each state to file in sequence as well as timesteps\n !writes to c_vs_time.dat\n write(100, *) t, (abs(C(i))**2.0_dp, i = 1, QN)\n \n !writes sum of probabilities and time step to file\n !writes to sum_c_vs_time.dat\n write(200, *) t, sum(abs(C)**2.0_dp)\n \n !writes fidelity of system compared to stated value with timestep\n !writes to fidelity_vs_time.dat\n write(300, *) t, Fid\n \n \n end do\n \n !Closes files\n !Closes file c_vs_time.dat and reports error if failure\n close(100,iostat=ierr)\n if (ierr/=0) stop 'Error in closing file c_vs_time.dat'\n \n !Closes file sum_c_vs_time.dat and reports error if failure\n close(200,iostat=ierr)\n if (ierr/=0) stop 'Error in closing file sum_c_vs_time.dat'\n \n !Closes file fidelity_vs_time.dat and reports error if failure\n close(300,iostat=ierr)\n if (ierr/=0) stop 'Error in opening file fidelity_vs_time.dat'\n \nend program hyperfine_spin_interaction\n \n \n", "meta": {"hexsha": "e594e392d568de4b2a91927ebdb8f747261e6d7f", "size": 16286, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "spin_hyperfine.f90", "max_stars_repo_name": "jchildren/hyperfine_spin_qubits", "max_stars_repo_head_hexsha": "2a294345f2b189012eeb289aad50ffffddd47578", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "spin_hyperfine.f90", "max_issues_repo_name": "jchildren/hyperfine_spin_qubits", "max_issues_repo_head_hexsha": "2a294345f2b189012eeb289aad50ffffddd47578", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "spin_hyperfine.f90", "max_forks_repo_name": "jchildren/hyperfine_spin_qubits", "max_forks_repo_head_hexsha": "2a294345f2b189012eeb289aad50ffffddd47578", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-03-26T18:20:48.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-26T18:20:48.000Z", "avg_line_length": 30.3277467412, "max_line_length": 133, "alphanum_fraction": 0.6076998649, "num_tokens": 4901, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900945711678, "lm_q2_score": 0.7217432003123989, "lm_q1q2_score": 0.6603235365267869}} {"text": " SUBROUTINE MC03MD( RP1, CP1, CP2, DP1, DP2, DP3, ALPHA, P1,\n $ LDP11, LDP12, P2, LDP21, LDP22, P3, LDP31,\n $ LDP32, DWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute the coefficients of the real polynomial matrix\nC\nC P(x) = P1(x) * P2(x) + alpha * P3(x),\nC\nC where P1(x), P2(x) and P3(x) are given real polynomial matrices\nC and alpha is a real scalar.\nC\nC Each of the polynomial matrices P1(x), P2(x) and P3(x) may be the\nC zero matrix.\nC\nC ARGUMENTS\nC\nC Input/Output Parameters\nC\nC RP1 (input) INTEGER\nC The number of rows of the matrices P1(x) and P3(x).\nC RP1 >= 0.\nC\nC CP1 (input) INTEGER\nC The number of columns of matrix P1(x) and the number of\nC rows of matrix P2(x). CP1 >= 0.\nC\nC CP2 (input) INTEGER\nC The number of columns of the matrices P2(x) and P3(x).\nC CP2 >= 0.\nC\nC DP1 (input) INTEGER\nC The degree of the polynomial matrix P1(x). DP1 >= -1.\nC\nC DP2 (input) INTEGER\nC The degree of the polynomial matrix P2(x). DP2 >= -1.\nC\nC DP3 (input/output) INTEGER\nC On entry, the degree of the polynomial matrix P3(x).\nC DP3 >= -1.\nC On exit, the degree of the polynomial matrix P(x).\nC\nC ALPHA (input) DOUBLE PRECISION\nC The scalar value alpha of the problem.\nC\nC P1 (input) DOUBLE PRECISION array, dimension (LDP11,LDP12,*)\nC If DP1 >= 0, then the leading RP1-by-CP1-by-(DP1+1) part\nC of this array must contain the coefficients of the\nC polynomial matrix P1(x). Specifically, P1(i,j,k) must\nC contain the coefficient of x**(k-1) of the polynomial\nC which is the (i,j)-th element of P1(x), where i = 1,2,...,\nC RP1, j = 1,2,...,CP1 and k = 1,2,...,DP1+1.\nC If DP1 = -1, then P1(x) is taken to be the zero polynomial\nC matrix, P1 is not referenced and can be supplied as a\nC dummy array (i.e. set the parameters LDP11 = LDP12 = 1 and\nC declare this array to be P1(1,1,1) in the calling\nC program).\nC\nC LDP11 INTEGER\nC The leading dimension of array P1.\nC LDP11 >= MAX(1,RP1) if DP1 >= 0,\nC LDP11 >= 1 if DP1 = -1.\nC\nC LDP12 INTEGER\nC The second dimension of array P1.\nC LDP12 >= MAX(1,CP1) if DP1 >= 0,\nC LDP12 >= 1 if DP1 = -1.\nC\nC P2 (input) DOUBLE PRECISION array, dimension (LDP21,LDP22,*)\nC If DP2 >= 0, then the leading CP1-by-CP2-by-(DP2+1) part\nC of this array must contain the coefficients of the\nC polynomial matrix P2(x). Specifically, P2(i,j,k) must\nC contain the coefficient of x**(k-1) of the polynomial\nC which is the (i,j)-th element of P2(x), where i = 1,2,...,\nC CP1, j = 1,2,...,CP2 and k = 1,2,...,DP2+1.\nC If DP2 = -1, then P2(x) is taken to be the zero polynomial\nC matrix, P2 is not referenced and can be supplied as a\nC dummy array (i.e. set the parameters LDP21 = LDP22 = 1 and\nC declare this array to be P2(1,1,1) in the calling\nC program).\nC\nC LDP21 INTEGER\nC The leading dimension of array P2.\nC LDP21 >= MAX(1,CP1) if DP2 >= 0,\nC LDP21 >= 1 if DP2 = -1.\nC\nC LDP22 INTEGER\nC The second dimension of array P2.\nC LDP22 >= MAX(1,CP2) if DP2 >= 0,\nC LDP22 >= 1 if DP2 = -1.\nC\nC P3 (input/output) DOUBLE PRECISION array, dimension\nC (LDP31,LDP32,n), where n = MAX(DP1+DP2,DP3,0)+1.\nC On entry, if DP3 >= 0, then the leading\nC RP1-by-CP2-by-(DP3+1) part of this array must contain the\nC coefficients of the polynomial matrix P3(x). Specifically,\nC P3(i,j,k) must contain the coefficient of x**(k-1) of the\nC polynomial which is the (i,j)-th element of P3(x), where\nC i = 1,2,...,RP1, j = 1,2,...,CP2 and k = 1,2,...,DP3+1.\nC If DP3 = -1, then P3(x) is taken to be the zero polynomial\nC matrix.\nC On exit, if DP3 >= 0 on exit (ALPHA <> 0.0 and DP3 <> -1,\nC on entry, or DP1 <> -1 and DP2 <> -1), then the leading\nC RP1-by-CP2-by-(DP3+1) part of this array contains the\nC coefficients of P(x). Specifically, P3(i,j,k) contains the\nC coefficient of x**(k-1) of the polynomial which is the\nC (i,j)-th element of P(x), where i = 1,2,...,RP1, j = 1,2,\nC ...,CP2 and k = 1,2,...,DP3+1.\nC If DP3 = -1 on exit, then the coefficients of P(x) (the\nC zero polynomial matrix) are not stored in the array.\nC\nC LDP31 INTEGER\nC The leading dimension of array P3. LDP31 >= MAX(1,RP1).\nC\nC LDP32 INTEGER\nC The second dimension of array P3. LDP32 >= MAX(1,CP2).\nC\nC Workspace\nC\nC DWORK DOUBLE PRECISION array, dimension (CP1)\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value.\nC\nC METHOD\nC\nC Given real polynomial matrices\nC\nC DP1 i\nC P1(x) = SUM (A(i+1) * x ),\nC i=0\nC\nC DP2 i\nC P2(x) = SUM (B(i+1) * x ),\nC i=0\nC\nC DP3 i\nC P3(x) = SUM (C(i+1) * x )\nC i=0\nC\nC and a real scalar alpha, the routine computes the coefficients\nC d ,d ,..., of the polynomial matrix\nC 1 2\nC\nC P(x) = P1(x) * P2(x) + alpha * P3(x)\nC\nC from the formula\nC\nC s\nC d = SUM (A(k+1) * B(i-k+1)) + alpha * C(i+1),\nC i+1 k=r\nC\nC where i = 0,1,...,DP1+DP2 and r and s depend on the value of i\nC (e.g. if i <= DP1 and i <= DP2, then r = 0 and s = i).\nC\nC NUMERICAL ASPECTS\nC\nC None.\nC\nC FURTHER COMMENTS\nC\nC Other elementary operations involving polynomial matrices can\nC easily be obtained by calling the appropriate BLAS routine(s).\nC\nC CONTRIBUTOR\nC\nC Release 3.0: V. Sima, Katholieke Univ. Leuven, Belgium, Mar. 1997.\nC Supersedes Release 2.0 routine MC03AD by A.J. Geurts.\nC\nC REVISIONS\nC\nC -\nC\nC KEYWORDS\nC\nC Elementary polynomial operations, input output description,\nC polynomial matrix, polynomial operations.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO\n PARAMETER ( ZERO = 0.0D0 )\nC .. Scalar Arguments ..\n INTEGER CP1, CP2, DP1, DP2, DP3, INFO, LDP11, LDP12,\n $ LDP21, LDP22, LDP31, LDP32, RP1\n DOUBLE PRECISION ALPHA\nC .. Array Arguments ..\n DOUBLE PRECISION DWORK(*), P1(LDP11,LDP12,*), P2(LDP21,LDP22,*),\n $ P3(LDP31,LDP32,*)\nC .. Local Scalars ..\n LOGICAL CFZERO\n INTEGER DPOL3, E, H, I, J, K\nC .. External Functions ..\n DOUBLE PRECISION DDOT\n EXTERNAL DDOT\nC .. External Subroutines ..\n EXTERNAL DCOPY, DLASET, DSCAL, XERBLA\nC .. Executable Statements ..\nC\nC Test the input scalar arguments.\nC\n INFO = 0\n IF( RP1.LT.0 ) THEN\n INFO = -1\n ELSE IF( CP1.LT.0 ) THEN\n INFO = -2\n ELSE IF( CP2.LT.0 ) THEN\n INFO = -3\n ELSE IF( DP1.LT.-1 ) THEN\n INFO = -4\n ELSE IF( DP2.LT.-1 ) THEN\n INFO = -5\n ELSE IF( DP3.LT.-1 ) THEN\n INFO = -6\n ELSE IF( ( DP1.EQ.-1 .AND. LDP11.LT.1 ) .OR.\n $ ( DP1.GE. 0 .AND. LDP11.LT.MAX( 1, RP1 ) ) ) THEN\n INFO = -9\n ELSE IF( ( DP1.EQ.-1 .AND. LDP12.LT.1 ) .OR.\n $ ( DP1.GE. 0 .AND. LDP12.LT.MAX( 1, CP1 ) ) ) THEN\n INFO = -10\n ELSE IF( ( DP2.EQ.-1 .AND. LDP21.LT.1 ) .OR.\n $ ( DP2.GE. 0 .AND. LDP21.LT.MAX( 1, CP1 ) ) ) THEN\n INFO = -12\n ELSE IF( ( DP2.EQ.-1 .AND. LDP22.LT.1 ) .OR.\n $ ( DP2.GE. 0 .AND. LDP22.LT.MAX( 1, CP2 ) ) ) THEN\n INFO = -13\n ELSE IF( LDP31.LT.MAX( 1, RP1 ) ) THEN\n INFO = -15\n ELSE IF( LDP32.LT.MAX( 1, CP2 ) ) THEN\n INFO = -16\n END IF\nC\n IF ( INFO.NE.0 ) THEN\nC\nC Error return.\nC\n CALL XERBLA( 'MC03MD', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF ( RP1.EQ.0 .OR. CP2.EQ.0 )\n $ RETURN\nC\n IF ( ALPHA.EQ.ZERO )\n $ DP3 = -1\nC\n IF ( DP3.GE.0 ) THEN\nC\nC P3(x) := ALPHA * P3(x).\nC\n DO 40 K = 1, DP3 + 1\nC\n DO 20 J = 1, CP2\n CALL DSCAL( RP1, ALPHA, P3(1,J,K), 1 )\n 20 CONTINUE\nC\n 40 CONTINUE\n END IF\nC\n IF ( ( DP1.EQ.-1 ) .OR. ( DP2.EQ.-1 ) .OR. ( CP1.EQ.0 ) )\n $ RETURN\nC\nC Neither of P1(x) and P2(x) is the zero polynomial.\nC\n DPOL3 = DP1 + DP2\n IF ( DPOL3.GT.DP3 ) THEN\nC\nC Initialize the additional part of P3(x) to zero.\nC\n DO 80 K = DP3 + 2, DPOL3 + 1\n CALL DLASET( 'Full', RP1, CP2, ZERO, ZERO, P3(1,1,K),\n $ LDP31 )\n 80 CONTINUE\nC\n DP3 = DPOL3\n END IF\nC k-1\nC The inner product of the j-th row of the coefficient of x of P1\nC i-1\nC and the h-th column of the coefficient of x of P2(x) contribute\nC k+i-2\nC the (j,h)-th element of the coefficient of x of P3(x).\nC\n DO 160 K = 1, DP1 + 1\nC\n DO 140 J = 1, RP1\n CALL DCOPY( CP1, P1(J,1,K), LDP11, DWORK, 1 )\nC\n DO 120 I = 1, DP2 + 1\n E = K + I - 1\nC\n DO 100 H = 1, CP2\n P3(J,H,E) = DDOT( CP1, DWORK, 1, P2(1,H,I), 1 ) +\n $ P3(J,H,E)\n 100 CONTINUE\nC\n 120 CONTINUE\nC\n 140 CONTINUE\nC\n 160 CONTINUE\nC\nC Computation of the exact degree of P3(x).\nC\n CFZERO = .TRUE.\nC WHILE ( DP3 >= 0 and CFZERO ) DO\n 180 IF ( ( DP3.GE.0 ) .AND. CFZERO ) THEN\n DPOL3 = DP3 + 1\nC\n DO 220 J = 1, CP2\nC\n DO 200 I = 1, RP1\n IF ( P3(I,J,DPOL3 ).NE.ZERO ) CFZERO = .FALSE.\n 200 CONTINUE\nC\n 220 CONTINUE\nC\n IF ( CFZERO ) DP3 = DP3 - 1\n GO TO 180\n END IF\nC END WHILE 180\nC\n RETURN\nC *** Last line of MC03MD ***\n END\n", "meta": {"hexsha": "bc863b81e55e1132e4d59618e79ac4513e388378", "size": 10854, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MC03MD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MC03MD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MC03MD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 32.1124260355, "max_line_length": 72, "alphanum_fraction": 0.5015662429, "num_tokens": 3629, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9399133464597458, "lm_q2_score": 0.7025300573952054, "lm_q1q2_score": 0.6603173772348847}} {"text": "PROGRAM LA_DGGLSE_EXAMPLE\n!\n! -- LAPACK95 interface driver routine (version 3.0) --\n! UNI-C, Denmark; Univ. of Tennessee, USA; NAG Ltd., UK\n! September, 2000\n!\n! .. USE STATEMENTS\n USE LA_PRECISION, ONLY: WP => DP\n USE F95_LAPACK, ONLY: LA_GGLSE\n! .. IMPLICIT STATEMENT ..\n IMPLICIT NONE\n! .. PARAMETERS ..\n CHARACTER(LEN=*), PARAMETER :: FMT = '(8(1X,F10.2))'\n INTEGER, PARAMETER :: NIN=5, NOUT=6\n! .. LOCAL SCALARS ..\n INTEGER :: I, INFO, M, N, P\n! .. LOCAL ARRAYS ..\n REAL(WP), ALLOCATABLE :: AA(:,:), BB(:,:), CC(:), DD(:)\n REAL(WP), ALLOCATABLE :: A(:, :), B(:,:), C(:), D(:), X(:)\n! .. INTRINSIC FUNCTIONS ..\n INTRINSIC MATMUL\n! .. EXECUTABLE STATEMENTS ..\n WRITE (NOUT,*) 'DGGLSE Example Program Results'\n READ ( NIN, * ) ! SKIP HEADING IN DATA FILE\n READ ( NIN, * ) M, N, P\n PRINT *, 'M = ', M, ' N = ', N, ' P = ', P\n ALLOCATE ( A(M,N), AA(M,N), B(P,N), BB(P,N), C(M), CC(M), D(P), DD(P), X(N) )\n READ (NIN,*) AA, BB, CC, DD\n A = AA; B=BB; C = CC; D = DD\n WRITE(NOUT,*) 'The matrix A'\n DO I = 1, M; WRITE (NOUT,FMT) A(I,:); ENDDO\n WRITE(NOUT,*) 'The RHS matrix B:'\n DO I = 1, P; WRITE (NOUT,FMT) B(I,:); ENDDO\n WRITE(NOUT,*) 'The vector C:'; WRITE (NOUT,FMT) C\n WRITE(NOUT,*) 'The vector D:'; WRITE (NOUT,FMT) D\n!\n WRITE ( NOUT, * )'--------------------------------------------'\n WRITE ( NOUT, * )\n WRITE ( NOUT, * )'Details of LA_DGELSE LAPACK Subroutine Results.'\n WRITE ( NOUT, * )\n!\n WRITE (NOUT,*)\n WRITE (NOUT,*) 'CALL LA_GGLSE (A, B, C, D, X)'\n A = AA; B=BB; C = CC; D = DD\n CALL LA_GGLSE (A, B, C, D, X)\n WRITE(NOUT,*)' C - MATMUL(AA, X), MATMUL(BB, X), X'\n WRITE (NOUT,FMT) C - MATMUL( AA, X )\n WRITE (NOUT,FMT) MATMUL( BB, X )\n WRITE(NOUT,FMT) X\n!\n WRITE (NOUT,*)\n WRITE (NOUT,*) 'CALL LA_GGLSE (A, B, C, D, X, INFO)'\n A = AA; B=BB; C = CC; D = DD\n CALL LA_GGLSE (A, B, C, D, X, INFO)\n WRITE(NOUT,*)'INFO = ', INFO, ' C - MATMUL(AA, X), MATMUL(BB, X), X'\n WRITE (NOUT,FMT) C - MATMUL( AA, X )\n WRITE (NOUT,FMT) MATMUL( BB, X )\n WRITE(NOUT,FMT) X\n!\n WRITE (NOUT,*)\n WRITE (NOUT,*) 'CALL LA_GGLSE (A(:,1:N-1), B, C, D, X, INFO)'\n A = AA; B=BB; C = CC; D = DD\n CALL LA_GGLSE (A(:,1:N-1), B, C, D, X, INFO)\n WRITE(NOUT,*)'INFO = ', INFO\n!\n WRITE (NOUT,*)\n WRITE (NOUT,*) 'CALL LA_GGLSE (A, B(1:1,:), C, D, X, INFO)'\n A = AA; B=BB; C = CC; D = DD\n CALL LA_GGLSE (A, B(1:1,:), C, D, X, INFO)\n WRITE(NOUT,*)'INFO = ', INFO\n!\n WRITE (NOUT,*)\n WRITE (NOUT,*) 'CALL LA_GGLSE (A, B, C(1:1), D, X, INFO)'\n A = AA; B=BB; C = CC; D = DD\n CALL LA_GGLSE (A, B, C(1:1), D, X, INFO)\n WRITE(NOUT,*)'INFO = ', INFO\n!\n WRITE (NOUT,*)\n WRITE (NOUT,*) 'CALL LA_GGLSE (A, B, C, D(1:1), X, INFO)'\n A = AA; B=BB; C = CC; D = DD\n CALL LA_GGLSE (A, B, C, D(1:1), X, INFO)\n WRITE(NOUT,*)'INFO = ', INFO\n!\n WRITE (NOUT,*)\n WRITE (NOUT,*) 'CALL LA_GGLSE (A, B, C, D, X(1:1))'\n A = AA; B=BB; C = CC; D = DD\n CALL LA_GGLSE (A, B, C, D, X(1:1))\n WRITE(NOUT,*)'INFO = ', INFO\n!\nEND!PROGRAM LA_DGGLSE_EXAMPLE\n", "meta": {"hexsha": "86af1f0308addbc86c324125f78b5e0ca66abec1", "size": 3048, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "EXAMPLES2/dgglseet.f90", "max_stars_repo_name": "MattBurn/LAPACK95", "max_stars_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-12-29T15:07:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T10:09:22.000Z", "max_issues_repo_path": "EXAMPLES2/dgglseet.f90", "max_issues_repo_name": "MattBurn/LAPACK95", "max_issues_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-12-30T15:38:47.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-31T06:45:11.000Z", "max_forks_repo_path": "EXAMPLES2/dgglseet.f90", "max_forks_repo_name": "MattBurn/LAPACK95", "max_forks_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-12-29T15:34:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-15T07:12:40.000Z", "avg_line_length": 33.4945054945, "max_line_length": 80, "alphanum_fraction": 0.5193569554, "num_tokens": 1294, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382129861583, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6601912604851576}} {"text": " SUBROUTINE INITIAL\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!!! set up for 2D lattices \n!!!! K.Travis 05/05/12 Univ. of Sheffield\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n USE header_file \n IMPLICIT NONE\n\n REAL(kind = double), DIMENSION(N) :: ATEMP,BTEMP \n REAL(kind = double) :: VX0,VY0,XLEN,XLEN2,YLEN,YLEN2\n REAL(kind = double) :: RA,RB,RXX,RYY,SPACING \n REAL(kind = double) :: XSUM,YSUM,PSQSUM,TSFAC,T0 \n REAL(kind = double) :: FACT,VAR,R1,R2,RANDNUM \n INTEGER :: IX,IY,I, J, NX, NY,MM,M,IA,IB,INTX,INTY \n\n NX = NINT(SQRT(DBLE(N))) ! atoms along each row/column\n\n IF(LATTICE_TYPE == 1) THEN\n GAMMA = PI/2.0D0\n ALEN = SQRT(DBLE(N)/DENSITY) \n BLEN = ALEN\n ELSE IF (LATTICE_TYPE == 2) THEN\n GAMMA = PI/3.0D0\n SPACING = (1.0d0/SQRT(DENSITY))*SQRT(2.0d0)/(3.0d0**0.25d0)\n ALEN = SPACING*DBLE(NX)\n BLEN = ALEN\n END IF\n\n INTX = 0\n INTY = 0\n XYZ_FILE_STAT = 'REPLACE'\n\n CALL CELLVECT\n WRITE(*,*) 'Calculated spacing = ',SPACING \n WRITE(*,*) 'Calculated density = ',N/(EFC(1,1)*EFC(2,2)) \n\n WRITE(*,*) 'Building lattice with NX = ',NX\n\n!! create a regular unit spaced grid using fractional coords along unit cell vectors as basis\n M = 0\n DO IA = 0,NX-1\n DO IB = 0,NX-1\n M = M + 1\n ATEMP(M) = (DBLE(IA) + 0.5D0)/DBLE(NX) \n BTEMP(M) = (DBLE(IB) + 0.5D0)/DBLE(NX) \n END DO\n END DO\n WRITE(*,*) 'Successfully constructed a regular grid!'\n\n!! now need to change them to cartesian coordinates\n\n DO I = 1,N\n RA = ATEMP(I) \n RB = BTEMP(I) \n CALL FRACCART(RA,RB,RXX,RYY)\n X(I) = RXX\n Y(I) = RYY\n END DO\n\n!!! assign velocities from a maxwell-boltzmann distribution\n DO I = 1,N\n MASS(I) = 1.0D00 !! assumes unit mass (can easily relax this)\n R1 = RANDNUM(INTX,INTY)\n R2 = RANDNUM(INTX,INTY)\n VAR = TREQ/MASS(I)\n FACT = SQRT(-2.0D0*LOG(R1)*VAR)\n VX0 = FACT*COS(2.0D0*PI*R2)\n VY0 = FACT*SIN(2.0D0*PI*R2)\n PX(I) = MASS(I)*VX0 \n PY(I) = MASS(I)*VY0 \n END DO\n\n!!! zero the total linear momentum\n XSUM = 0.0D0\n YSUM = 0.0D0\n DO I = 1,N\n XSUM = XSUM + PX(I)\n YSUM = YSUM + PY(I)\n END DO\n WRITE(*,*) 'X-compt momentum at start = ',XSUM/N\n WRITE(*,*) 'Y-compt momentum at start = ',YSUM/N\n PSQSUM = 0.0d0\n DO I = 1,N\n PX(I) = PX(I) - XSUM/N\n PY(I) = PY(I) - YSUM/N\n PSQSUM = PSQSUM + (PX(I)**2 + PY(I)**2)/MASS(I)\n END DO\n IF(ITHERM == 0) THEN\n DEGFREE = 2.0D0*N - 2.0d0\n ELSE\n DEGFREE = 2.0D0*N - 3.0d0\n END IF\n T0 = PSQSUM/DEGFREE\n WRITE(*,*) 'INitial temperature = ',T0\n\n!!! rescale the temperature\n TSFAC = SQRT(TREQ/T0) \n DO I = 1,N\n PX(I) = PX(I)*TSFAC\n PY(I) = PY(I)*TSFAC\n END DO \n\n END SUBROUTINE\n\n FUNCTION RANDNUM(INTX,INTY)\n IMPLICIT NONE\n INTEGER, PARAMETER :: double = SELECTED_REAL_KIND(15,99)\n INTEGER :: I,J,INTX,INTY\n REAL(kind = double) :: RANDNUM \n I = 1029*INTX + 1731\n J = I + 1029*INTY + 507*INTX - 1731\n INTX = MOD(I,2048)\n J = J + (I - INTX)/2048\n INTY = MOD(J,2048)\n RANDNUM = (INTX + 2048*INTY)/4194304.0D00\n\n END FUNCTION\n\n", "meta": {"hexsha": "921812b3a87112a5adf56cf785d673205d447a28", "size": 3427, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "synthetic_NEMD/src/src_2dsllod/initial.f90", "max_stars_repo_name": "niallj/ImperialNESS-Sep14", "max_stars_repo_head_hexsha": "0cd309273cdb89f8055c2aa51422584e2284ca94", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "synthetic_NEMD/src/src_2dsllod/initial.f90", "max_issues_repo_name": "niallj/ImperialNESS-Sep14", "max_issues_repo_head_hexsha": "0cd309273cdb89f8055c2aa51422584e2284ca94", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "synthetic_NEMD/src/src_2dsllod/initial.f90", "max_forks_repo_name": "niallj/ImperialNESS-Sep14", "max_forks_repo_head_hexsha": "0cd309273cdb89f8055c2aa51422584e2284ca94", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.7983193277, "max_line_length": 93, "alphanum_fraction": 0.5086081121, "num_tokens": 1250, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412809, "lm_q2_score": 0.7662936324115011, "lm_q1q2_score": 0.6601912494147445}} {"text": "SUBROUTINE gcount(n, apply, ifault)\r\n \r\n! Code converted using TO_F90 by Alan Miller\r\n! Date: 2003-04-26 Time: 20:20:16\r\n\r\n! ALGORITHM AS227 APPL. STATIST. (1987) VOL. 36, NO. 2, pp. 245-9.\r\n\r\n! Generates all possible N-bit binary codes, and applies a users\r\n! procedure for each code generated.\r\n\r\n! Translated from Algol 60.\r\n\r\nIMPLICIT NONE\r\n\r\nINTEGER, INTENT(IN) :: n\r\nINTEGER, INTENT(OUT) :: ifault\r\n\r\n! EXTERNAL apply\r\n\r\nINTERFACE\r\n SUBROUTINE apply(n, change, STATUS)\r\n IMPLICIT NONE\r\n INTEGER, INTENT(IN) :: n, change\r\n LOGICAL, INTENT(IN) :: STATUS(n)\r\n END SUBROUTINE apply\r\nEND INTERFACE\r\n\r\n! Local variables\r\n\r\nINTEGER :: change, i, tpoint(n)\r\nLOGICAL :: STATUS(n)\r\n\r\nIF (n < 1) THEN\r\n ifault = 1\r\n RETURN\r\nEND IF\r\nifault = 0\r\n\r\n! Initialize and make first call to user's routine.\r\n\r\nDO i = 1, n\r\n STATUS(i) = .false.\r\n tpoint(i) = i + 1\r\nEND DO\r\nCALL apply(n, n, STATUS)\r\n\r\n! Generate a new code. The user's routine is called twice each\r\n! cycle; the first time the bit which changes is bit 1.\r\n\r\n20 IF (STATUS(1)) THEN\r\n STATUS(1) = .false.\r\n change = tpoint(2)\r\nELSE\r\n STATUS(1) = .true.\r\n change = 2\r\nEND IF\r\nCALL apply(n, 1, STATUS)\r\n\r\n! Check if count exhausted.\r\n\r\nIF (change > n) RETURN\r\n\r\nIF (STATUS(change)) THEN\r\n STATUS(change) = .false.\r\n tpoint(change) = tpoint(change+1)\r\nELSE\r\n STATUS(change) = .true.\r\n tpoint(change) = change + 1\r\nEND IF\r\nCALL apply(n, change, STATUS)\r\n\r\nGO TO 20\r\nEND SUBROUTINE gcount\r\n\r\n\r\n\r\nSUBROUTINE print_comb(n, change, STATUS)\r\nIMPLICIT NONE\r\nINTEGER, INTENT(IN) :: n, change\r\nLOGICAL, INTENT(IN) :: STATUS(n)\r\n\r\nWRITE(*, '(\" \", 4L2)') STATUS\r\nRETURN\r\nEND SUBROUTINE print_comb\r\n\r\n\r\n\r\nPROGRAM t_as227\r\n! A simple program to print out the combinations when n = 4.\r\n\r\nIMPLICIT NONE\r\n\r\nINTEGER :: n = 4, ifault\r\n\r\nINTERFACE\r\n SUBROUTINE gcount(n, apply, ifault)\r\n IMPLICIT NONE\r\n INTEGER, INTENT(IN) :: n\r\n INTEGER, INTENT(OUT) :: ifault\r\n INTERFACE\r\n SUBROUTINE apply(n, change, STATUS)\r\n IMPLICIT NONE\r\n INTEGER, INTENT(IN) :: n, change\r\n LOGICAL, INTENT(IN) :: STATUS(n)\r\n END SUBROUTINE apply\r\n END INTERFACE\r\n END SUBROUTINE gcount\r\n\r\n SUBROUTINE print_comb(n, change, STATUS)\r\n IMPLICIT NONE\r\n INTEGER, INTENT(IN) :: n, change\r\n LOGICAL, INTENT(IN) :: STATUS(n)\r\n END SUBROUTINE print_comb\r\nEND INTERFACE\r\n\r\nCALL gcount(n, print_comb, ifault)\r\n\r\nSTOP\r\nEND PROGRAM t_as227\r\n", "meta": {"hexsha": "052a4cc862eef29623998cb27bf7ec45ae44e007", "size": 2435, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/as227.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/as227.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/as227.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": 20.2916666667, "max_line_length": 68, "alphanum_fraction": 0.6427104723, "num_tokens": 741, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7662936430859597, "lm_q2_score": 0.8615382040983515, "lm_q1q2_score": 0.6601912490762608}} {"text": "! **********************************************************************************\r\n! * INTERPOLATION ROUTINES *\r\n! * -------------------------------------------------------------------- *\r\n! * Partial list of subroutines: *\r\n! * Interp, linterp, spline, splint, dpchim, dpchfe, dchfev, dpchst, *\r\n! * readinputInterp *\r\n! ********************************************************************************** \r\nsubroutine Interp (n, x, y, xpoint, ypoint)\r\n!------------------------------------------------------------------------------------ \r\n! Given the pairs (x_1,y_1), (x_2,y_2),..., (x_n,y_n), the routine computes the !\r\n! value ypoint at xpoint using linear, spline or cubic Hermite interpolation. !\r\n! !\r\n! Input parameters: !\r\n! - n (integer) - number of data points. !\r\n! - x (real array) - set of discrete points (abscissas). !\r\n! - y (real array) - function values at discrete points. ! \r\n! - xpoint (real) - evaluation point. !\r\n! !\r\n! Output parameters: !\r\n! - ypoint (real) - value of the function at xpoint. !\r\n! !\r\n! The parameter TypeInterp (specified in the group statement \"Interpolation\" !\r\n! from the input file \"../INPUTFILES/Input.dat\") provides the type of !\r\n! interpolation method. ! \r\n!------------------------------------------------------------------------------------\r\n use parameters\r\n implicit none\r\n integer :: n\r\n real(O) :: x(n), y(n), xpoint, ypoint\r\n!\r\n integer :: i\r\n real(O) :: yd1, ydn\r\n character(20) :: TypeInterp\r\n logical :: ascending\r\n real(O),allocatable :: x1(:), y1(:), yd(:) \r\n! \r\n call readinputInterp ( TypeInterp ) \r\n allocate (x1(n), y1(n)) \r\n ascending = .true.\r\n do i = 1, n - 1\r\n if (x(i) > x(i+1)) then\r\n ascending = .false.\r\n exit\r\n end if\r\n end do\r\n do i = 1, n\r\n if (ascending) then\r\n x1(i) = x(i)\r\n y1(i) = y(i)\r\n else\r\n x1(i) = x(n-i+1)\r\n y1(i) = y(n-i+1)\r\n end if\r\n end do \r\n if (xpoint < x1(1) .and. xpoint > x1(n)) then\r\n print \"(/,2x,'Error in subroutine Interp in file Interp.f90:')\"\r\n print \"( 2x, a)\", &\r\n 'the interpolation point does not belong to the set of discrete points;' \r\n stop \r\n end if \r\n if (TypeInterp(1:6) == 'LINEAR') then\r\n call linterp (x1, y1, n, xpoint, ypoint) \r\n else if (TypeInterp(1:6) == 'SPLINE') then \r\n allocate (yd(n))\r\n yd1 = 0._O\r\n ydn = 0._O \r\n call spline (x1, y1, n, yd1, ydn, yd) \r\n call splint (x1, y1, yd, n, xpoint, ypoint)\r\n deallocate (yd)\r\n else if (TypeInterp(1:7) == 'HERMITE') then \r\n allocate ( yd(n)) \r\n call dpchim (n, x1, y1, yd) \r\n call dpchfe (n, x1, y1, yd, xpoint, ypoint)\r\n deallocate (yd)\r\n end if\r\n deallocate (x1, y1) \r\nend subroutine Interp\r\n! ************************************************************************************\r\nsubroutine readinputInterp ( TypeInterp ) \r\n use parameters\r\n implicit none\r\n integer :: ios\r\n character(20) :: TypeInterp\r\n character(80) :: string\r\n logical :: XFindPar\r\n!\r\n open (unit = iInput, file = FileInput, status = \"old\", position = \"rewind\") \r\n TypeInterp = 'LINEAR' \r\n string = 'Interpolation'\r\n if (XFindPar (iInput, string)) then\r\n read (iInput, *, iostat = ios) TypeInterp\r\n if (ios /= 0) then\r\n print \"(/,2x,'Error by reading the input variable TypeInterp;')\"\r\n stop\r\n end if\r\n else\r\n print \"(/,2x,'Group name Interpolation not found;')\"\r\n stop \r\n end if \r\n call check_Interpolation (TypeInterp) \r\n close (unit = iInput) \r\nend subroutine readinputInterp \r\n! ************************************************************************************\r\n! * LINEAR INTERPOLATION ROUTINE *\r\n! ************************************************************************************\r\nsubroutine linterp (xa, ya, n, x, y)\r\n use parameters\r\n use derived_parameters\r\n implicit none\r\n integer :: n\r\n real(O) :: xa(n), ya(n), x, y\r\n! \r\n integer :: i,ix\r\n real(O) :: xs, xd, csi, dx\r\n logical :: found \r\n! \r\n found = .false. \r\n do i = 1, n - 1\r\n xs = xa(i)\r\n xd = xa(i+1)\r\n dx = xd - xs\r\n if (abs(dx) < MachEps) then\r\n print \"(/,2x,'Error in subroutine linterp in file Interp.f90:')\"\r\n print \"( 2x,'coincident knots;')\"\r\n stop \r\n end if \r\n if (x >= xs .and. x < xd) then\r\n ix = i\r\n csi = (x - xs) / dx\r\n found = .true.\r\n exit\r\n end if \r\n end do\r\n if (found) then\r\n y = (1._O - csi) * ya(ix) + csi * ya(ix+1)\r\n else\r\n y = ya(n)\r\n end if \r\nend subroutine linterp \r\n! ************************************************************************************\r\n! * SPLINE INTERPOLATION ROUTINE - F90-VERSION FROM NUMERICAL RECIPES *\r\n! ************************************************************************************\r\nsubroutine spline (x, y, n, yp1, ypn, y2)\r\n!-----------------------------------------------------------------------------------\r\n! The routine computes the derivatives needed to determine a spline interpolant !\r\n! to given data. !\r\n!-----------------------------------------------------------------------------------\r\n use parameters\r\n use derived_parameters\r\n implicit none \r\n integer :: n\r\n real(O) :: x(n), y(n), yp1, ypn, y2(n)\r\n! \r\n integer :: i, k\r\n real(O) :: sig, p, qn, un, dy, dx, dyp, dym, dxp, dxm\r\n real(O),allocatable :: u(:)\r\n! \r\n allocate (u(n))\r\n if (yp1 > LargestSplineVal) then\r\n y2(1) = 0._O\r\n u (1) = 0._O\r\n else\r\n y2(1) = - 0.5_O\r\n dy = y(2) - y(1)\r\n dx = x(2) - x(1)\r\n if (abs(dx) < MachEps) then\r\n print \"(/,2x,'Error in subroutine spline in file Interp.f90:')\"\r\n print \"( 2x,'coincident knots;')\"\r\n stop \r\n end if \r\n u (1) = (3._O / dx ) * (dy / dx - yp1) \r\n end if\r\n do i = 2, n - 1\r\n sig = (x(i) - x(i-1)) / (x(i+1) - x(i-1))\r\n p = sig * y2(i-1) + 2._O\r\n y2(i) = (sig - 1._O) / p\r\n dyp = y(i+1) - y(i)\r\n dym = y(i) - y(i-1)\r\n dxp = x(i+1) - x(i)\r\n dxm = x(i) - x(i-1)\r\n dx = x(i+1) - x(i-1)\r\n if (abs(dxp) < MachEps ) then\r\n print \"(/,2x,'Error in subroutine spline in file Interp.f90:')\"\r\n print \"( 2x,'coincident knots;')\"\r\n stop \r\n end if \r\n u(i) = (6._O * (dyp / dxp - dym / dxm) / dx - sig * u(i-1)) / p \r\n end do\r\n if (ypn > LargestSplineVal) then\r\n qn = 0._O\r\n un = 0._O\r\n else\r\n qn = 0.5_O\r\n dy = y(n) - y(n-1)\r\n dx = x(n) - x(n-1)\r\n un = (3._O / dx) * (ypn - dy / dx) \r\n end if\r\n y2(n) = (un - qn * u(n-1)) / (qn * y2(n-1) + 1._O)\r\n do k = n - 1, 1, - 1\r\n y2(k) = y2(k) * y2(k+1) + u(k)\r\n end do\r\n deallocate (u)\r\nend subroutine spline\r\n! *********************************************************************************** \r\nsubroutine splint (xa, ya, y2a, n, x, y) \r\n!------------------------------------------------------------------------------------\r\n! The routine evaluates a spline interpolant at a point. !\r\n!------------------------------------------------------------------------------------ \r\n use parameters\r\n implicit none\r\n integer :: n\r\n real(O) :: xa(n), ya(n), y2a(n), x, y\r\n! \r\n integer :: klo, khi, k\r\n real(O) :: h, a, b \r\n logical :: more\r\n! \r\n klo = 1\r\n khi = n\r\n more = .true.\r\n do while (more)\r\n k = (khi + klo) / 2\r\n if (xa(k) > x) then\r\n khi = k\r\n else\r\n klo = k\r\n end if\r\n if (khi - klo <= 1) more = .false.\r\n end do\r\n h = xa(khi) - xa(klo)\r\n a = (xa(khi) - x) / h\r\n b = (x - xa(klo)) / h\r\n y = a * ya(klo) + b * ya(khi) + ((a**3 - a) * y2a(klo) + &\r\n (b**3 - b) * y2a(khi)) * (h**2) / 6._O \r\nend subroutine splint \r\n! ************************************************************************************\r\n! * HERMITE INTERPOLATION ROUTINE - F90-VERSION FROM SLATEC LIBRARY *\r\n! ************************************************************************************ \r\nsubroutine dpchim (n, x, f, d)\r\n!-----------------------------------------------------------------------------------\r\n! The routine computes the derivatives needed to determine a monotone piecewise !\r\n! cubic Hermite interpolant to given data. !\r\n!-----------------------------------------------------------------------------------\r\n use parameters\r\n implicit none\r\n integer :: n\r\n real(O) :: x(n), f(n), d(n)\r\n!\r\n integer :: i, nless1\r\n real(O) :: del1, del2, dmax, dmin, drat1, drat2, h1, h2, hsum, hsumt3, &\r\n w1, w2, dpchst \r\n! \r\n if (n < 2) then\r\n print \"(/,2x,'Error in subroutine dpchfe in file Interp.f90:')\"\r\n print \"( 2x,'number of data points less than two;')\"\r\n stop \r\n end if \r\n nless1 = n - 1\r\n h1 = x(2) - x(1)\r\n del1 = (f(2) - f(1)) / h1 \r\n if (nless1 > 1) then\r\n h2 = x(3) - x(2)\r\n del2 = (f(3) - f(2)) / h2\r\n hsum = h1 + h2\r\n w1 = (h1 + hsum) / hsum\r\n w2 = - h1 / hsum\r\n d(1) = w1 * del1 + w2 * del2\r\n if (dpchst (d(1), del1) <= 0._O) then\r\n d(1) = 0._O\r\n else if (dpchst (del1, del2) < 0._O) then\r\n dmax = 3._O * del1\r\n if (abs(d(1)) > abs(dmax)) d(1) = dmax\r\n end if\r\n do i = 2, nless1 \r\n if (i /= 2) then\r\n h1 = h2\r\n h2 = x(i+1) - x(i)\r\n hsum = h1 + h2\r\n del1 = del2\r\n del2 = (f(i+1) - f(i)) / h2\r\n end if \r\n d(i) = 0._O\r\n if (dpchst (del1, del2) > 0._O) then\r\n hsumt3 = hsum + hsum + hsum\r\n w1 = (hsum + h1) / hsumt3\r\n w2 = (hsum + h2) / hsumt3\r\n dmax = max(abs(del1), abs(del2) )\r\n dmin = min(abs(del1), abs(del2) )\r\n drat1 = del1 / dmax\r\n drat2 = del2 / dmax\r\n d(i) = dmin / (w1 * drat1 + w2 * drat2)\r\n end if \r\n end do \r\n w1 = - h2 / hsum\r\n w2 = (h2 + hsum) / hsum\r\n d(n) = w1 * del1 + w2 * del2\r\n if (dpchst (d(n), del2) <= 0._O) then\r\n d(n) = 0._O\r\n else if (dpchst (del1, del2) < 0._O) then\r\n dmax = 3._O * del2\r\n if (abs(d(n)) > abs(dmax)) d(n) = dmax\r\n end if\r\n else\r\n d(1) = del1\r\n d(n) = del1\r\n end if \r\nend subroutine dpchim\r\n!************************************************************************************\r\nsubroutine dpchfe (n, x, f, d, xe, fe)\r\n!------------------------------------------------------------------------------------\r\n! The routine evaluates a cubic polynomial given in Hermite form at a point. !\r\n!------------------------------------------------------------------------------------ \r\n use parameters \r\n implicit none\r\n integer :: n\r\n real(O) :: x(n), f(n), d(n), xe, fe\r\n!\r\n integer :: i, ix\r\n real(O) :: xs, xd, x1, x2, f1, f2, d1, d2\r\n logical :: found\r\n! \r\n found = .false.\r\n do i = 1, n - 1\r\n xs = x(i)\r\n xd = x(i+1) \r\n if (xe >= xs .and. xe < xd) then\r\n ix = i\r\n found = .true. \r\n exit \r\n end if \r\n end do\r\n if (found) then \r\n x1 = x(ix)\r\n x2 = x(ix+1)\r\n f1 = f(ix)\r\n f2 = f(ix+1)\r\n d1 = d(ix)\r\n d2 = d(ix+1) \r\n call dchfev (x1, x2, f1, f2, d1, d2, xe, fe)\r\n else\r\n fe = f(n)\r\n end if \r\nend subroutine dpchfe\r\n! ***********************************************************************************\r\nsubroutine dchfev (x1, x2, f1, f2, d1, d2, xe, fe) \r\n use parameters\r\n use derived_parameters \r\n implicit none \r\n real(O) :: x1, x2, f1, f2, d1, d2, xe, fe\r\n!\r\n real(O) :: c2, c3, del1, del2, delta, h, x \r\n! \r\n h = x2 - x1\r\n if (abs(h) < MachEps) then\r\n print \"(/,2x,'Error in subroutine dchfev in file Interp.f90:')\"\r\n print \"( 2x,'coincident knots;')\"\r\n stop \r\n end if \r\n delta = (f2 - f1) / h\r\n del1 = (d1 - delta) / h\r\n del2 = (d2 - delta) / h \r\n c2 = - (del1 + del1 + del2)\r\n c3 = (del1 + del2) / h\r\n x = xe - x1\r\n fe = f1 + x * (d1 + x * (c2 + x * c3)) \r\nend subroutine dchfev\r\n! ***********************************************************************************\r\nfunction dpchst (arg1, arg2) result (func)\r\n use parameters\r\n implicit none\r\n real(O),intent(in) :: arg1, arg2\r\n real(O) :: func\r\n! \r\n func = 0._O\r\n if ((arg1 /= 0._O) .and. (arg2 /= 0._O)) then\r\n func = sign(1._O,arg1) * sign(1._O,arg2)\r\n end if \r\nend function dpchst\r\n", "meta": {"hexsha": "caea1ec0f1f8ba01347c6a434fe7e2de1b824f1f", "size": 13616, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "miepy/tmatrix/nfmds/Interp.f90", "max_stars_repo_name": "johnaparker/MiePy", "max_stars_repo_head_hexsha": "5c5bb5a07c8ab79e9e2a9fc79fb9779e690147be", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2016-05-30T06:45:29.000Z", "max_stars_repo_stars_event_max_datetime": "2017-08-30T19:58:56.000Z", "max_issues_repo_path": "miepy/tmatrix/nfmds/Interp.f90", "max_issues_repo_name": "johnaparker/MiePy", "max_issues_repo_head_hexsha": "5c5bb5a07c8ab79e9e2a9fc79fb9779e690147be", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "miepy/tmatrix/nfmds/Interp.f90", "max_forks_repo_name": "johnaparker/MiePy", "max_forks_repo_head_hexsha": "5c5bb5a07c8ab79e9e2a9fc79fb9779e690147be", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2016-12-13T02:05:31.000Z", "max_forks_repo_forks_event_max_datetime": "2018-03-23T07:11:30.000Z", "avg_line_length": 35.926121372, "max_line_length": 99, "alphanum_fraction": 0.3757344301, "num_tokens": 4064, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310358, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.6601912485644359}} {"text": "module mod_diagnostics\n\n ! Provides various diagnostic functions.\n\n use mod_kinds, only: ik, rk\n\n implicit none\n\n private\n public :: ke, mean\n\n interface mean\n module procedure :: mean_1d, mean_2d\n end interface mean\n\ncontains\n\n pure elemental real(rk) function ke(u, v)\n ! Computes the kinetic energy as 1/2 (u^2 + v^2)\n real(rk), intent(in) :: u, v\n ke = 0.5_rk * sqrt(u**2 + v**2)\n end function ke\n\n pure real(rk) function mean_1d(x) result(mean)\n real(rk), intent(in) :: x(:)\n mean = sum(x) / size(x)\n end function mean_1d\n\n pure real(rk) function mean_2d(x) result(mean)\n real(rk), intent(in) :: x(:, :)\n mean = sum(x) / size(x)\n end function mean_2d\n\nend module mod_diagnostics\n", "meta": {"hexsha": "6999198fa5c410c14c39d4c05b627ea61e70a5dc", "size": 721, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/extras/mod_diagnostics.f90", "max_stars_repo_name": "AAGAN/tsunami", "max_stars_repo_head_hexsha": "82635516dcb7f85eb6434ffdb98a9ddc4c1403ad", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 103, "max_stars_repo_stars_event_min_datetime": "2018-03-29T23:39:31.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T12:24:25.000Z", "max_issues_repo_path": "src/extras/mod_diagnostics.f90", "max_issues_repo_name": "AAGAN/tsunami", "max_issues_repo_head_hexsha": "82635516dcb7f85eb6434ffdb98a9ddc4c1403ad", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2018-04-06T14:33:04.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T19:50:12.000Z", "max_forks_repo_path": "src/extras/mod_diagnostics.f90", "max_forks_repo_name": "AAGAN/tsunami", "max_forks_repo_head_hexsha": "82635516dcb7f85eb6434ffdb98a9ddc4c1403ad", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 32, "max_forks_repo_forks_event_min_datetime": "2018-04-01T19:54:12.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-27T14:06:03.000Z", "avg_line_length": 20.6, "max_line_length": 52, "alphanum_fraction": 0.6477115118, "num_tokens": 231, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.86153820232079, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6601912477141268}} {"text": "program test_random\n\n use random_mod\n\n implicit none\n\n print*, \"-------------------------------------\"\n print*, \"test_normal_to_cdf_conversion\"\n call test_normal_to_cdf_conversion()\n\n print*, \"-------------------------------------\"\n print*, \"test_box_muller_random(10000)\"\n call test_box_muller_random(10000)\n print*, \"-------------------------------------\"\n print*, \"test_box_muller_random(999)\"\n call test_box_muller_random(9999)\n\n print*, \"-------------------------------------\"\n print*, \"test_uniform_to_normal\"\n call test_uniform_to_normal()\n\ncontains\n\n subroutine test_uniform_to_normal()\n\n implicit none\n integer, parameter :: ntest_values = 23\n\n ! hard coded expected CDF values for given normal value from scipy.stats.norm.cdf\n real :: normal_values(ntest_values) = [-5.50, -5.00, -4.50, -4.00, -3.50, -3.00, -2.50, -2.00, &\n -1.50, -1.00, -0.50, 0.000, 0.500, 1.00, 1.50, 2.00, &\n 2.50, 3.00, 3.50, 4.00, 4.50, 5.00, 5.50]\n\n real :: cdf_values(ntest_values) = [0.000000019, 0.0000002, 0.0000033, 0.0000316, 0.0002326, &\n 0.0013498, 0.0062096, 0.0227501, 0.0668072, 0.1586552, &\n 0.3085375, 0.5000000, 0.6914624, 0.8413447, 0.9331927, &\n 0.9772498, 0.9937903, 0.9986501, 0.9997673, 0.9999683, &\n 0.9999966, 0.9999997, 0.9999999810]\n logical :: passing\n integer :: i\n real :: normal\n\n passing = .True.\n print*, \"WARNING: Passing criteria may not be strict enough, errors can be up to 20%\"\n\n ! iterate over all values to test, if expected value is more than 2e-3 away from the actual result it fails\n do i = 1, ntest_values\n normal = get_normal_from_cdf( cdf_values(i) )\n if ((abs(normal_values(i) - normal ) > 1e-2) .and. (abs(normal_values(i) - normal )/abs(normal_values(i)) > 2e-1)) then\n passing = .False.\n print*, \"\"\n print*, \" Error = \",normal_values(i) - normal, (normal_values(i) - normal)/normal_values(i)\n print*, \" Expected = \", normal_values(i)\n print*, \" Got: \",normal, \" for:\",cdf_values(i)\n endif\n end do\n\n if (passing) then\n print*, \" PASSED\"\n else\n print*, \" FAILED\"\n endif\n end subroutine test_uniform_to_normal\n\n\n subroutine test_normal_to_cdf_conversion()\n\n implicit none\n integer, parameter :: ntest_values = 23\n\n ! hard coded expected CDF values for given normal value from scipy.stats.norm.cdf\n real :: normal_values(ntest_values) = [-5.50, -5.00, -4.50, -4.00, -3.50, -3.00, -2.50, -2.00, &\n -1.50, -1.00, -0.50, 0.000, 0.500, 1.00, 1.50, 2.00, &\n 2.50, 3.00, 3.50, 4.00, 4.50, 5.00, 5.50]\n\n real :: cdf_values(ntest_values) = [0.000000019, 0.0000002, 0.0000033, 0.0000316, 0.0002326, &\n 0.0013498, 0.0062096, 0.0227501, 0.0668072, 0.1586552, &\n 0.3085375, 0.5000000, 0.6914624, 0.8413447, 0.9331927, &\n 0.9772498, 0.9937903, 0.9986501, 0.9997673, 0.9999683, &\n 0.9999966, 0.9999997, 0.9999999810]\n logical :: passing\n integer :: i\n\n passing = .True.\n\n ! iterate over all values to test, if expected value is more than 2e-3 away from the actual result it fails\n do i = 1, ntest_values\n if (abs(cdf_values(i) - normal_cdf( normal_values(i) ) ) > 2e-3) then\n passing = .False.\n print*, \"\"\n print*, \" Error = \",cdf_values(i) - normal_cdf( normal_values(i))\n print*, \" Expected = \", cdf_values(i)\n print*, \" Got: \",normal_cdf( normal_values(i)), \" for:\",normal_values(i)\n endif\n end do\n\n if (passing) then\n print*, \" PASSED\"\n else\n print*, \" FAILED\"\n endif\n end subroutine test_normal_to_cdf_conversion\n\n subroutine test_box_muller_random(n_random_values)\n implicit none\n\n integer, intent(in) :: n_random_values\n\n real :: random_values(n_random_values)\n real :: sigma, mean\n integer :: i\n logical :: passing\n\n passing = .True.\n\n call box_muller_random(random_values)\n\n mean = sum(random_values) / size(random_values)\n if (abs(mean) > 1e-2) then\n print*, \" Error failed computing mean: \",mean\n passing = .False.\n endif\n\n sigma = 0\n do i = 1, n_random_values\n sigma = sigma + (random_values(i) - mean)**2\n enddo\n sigma = sqrt(sigma / (n_random_values - 1))\n if (abs(sigma - 1) > 1e-1) then\n print*, \" Error failed computing standard deviation: \", sigma\n passing = .False.\n endif\n\n\n if (minval(random_values) > (-3)) then\n print*, \" Error failed computing minimum value: \", minval(random_values)\n passing = .False.\n endif\n\n if (maxval(random_values) < (3)) then\n print*, \" Error failed computing maximum value: \", maxval(random_values)\n passing = .False.\n endif\n\n if (passing) then\n print*, \" PASSED\"\n else\n print*, \" FAILED\"\n endif\n end subroutine test_box_muller_random\n\nend program test_random\n", "meta": {"hexsha": "43d9fe0f05b450180c1faf8f84b144bdf848c964", "size": 5794, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/test_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/tests/test_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/tests/test_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": 37.8692810458, "max_line_length": 131, "alphanum_fraction": 0.5110459096, "num_tokens": 1621, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.86153820232079, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6601912477141268}} {"text": "subroutine set_coordinates(delx, dely, xt, yt, nx, ny)\nuse kind_parameters\nimplicit none\n\ninteger:: nx, ny\nreal(kind=dp), intent(out), dimension(nx):: xt\nreal(kind=dp), intent(out), dimension(ny):: yt\nreal(kind=dp), dimension(nx-1):: delx\nreal(kind=dp), dimension(ny-1):: dely\ninteger:: it, jt\n\n! locate the t position in x direction\n\nxt(1) = 0.0\n\ndo it = 2,nx\n \n xt(it) = xt(it-1) + delx(it-1)\n \nend do\n\n! locate the t position in y direction\n\nyt(1) = 0.0\n\ndo jt = 2,ny\n \n yt(jt) = yt(jt-1) + dely(jt-1)\n \nend do\n\nend subroutine set_coordinates\n", "meta": {"hexsha": "288374eb240c6ab9348d22e7450a4ff48964cb1a", "size": 564, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "set_coordinates.f90", "max_stars_repo_name": "pratanuroy/Multigrid_Cavity", "max_stars_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-09-11T12:01:52.000Z", "max_stars_repo_stars_event_max_datetime": "2017-09-11T12:01:52.000Z", "max_issues_repo_path": "set_coordinates.f90", "max_issues_repo_name": "pratanuroy/Multigrid_Cavity", "max_issues_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "set_coordinates.f90", "max_forks_repo_name": "pratanuroy/Multigrid_Cavity", "max_forks_repo_head_hexsha": "b0f54b0d59e070cd063cfc41c2553b680fed54af", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.0909090909, "max_line_length": 54, "alphanum_fraction": 0.6436170213, "num_tokens": 195, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920116079209, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.6601400765978556}} {"text": "PROGRAM boundaries_test\n\nUSE boundaries, only : periodic, InitializeBoundaries, FinalizeBoundaries\n\nIMPLICIT NONE\n\nDOUBLE PRECISION, PARAMETER :: pi = 3.1415926535897932_8 ! underscore indicates rounding to real(8) precision\n\nDOUBLE PRECISION, ALLOCATABLE, DIMENSION(:,:,:) :: Q, Qall\nDOUBLE PRECISION :: dx, dy, dz, x, y, z\nINTEGER :: Nx, Ny, Nz, seed_size, i, j, k, clock\nINTEGER, PARAMETER :: N_min = 25, N_max = 256\nINTEGER, ALLOCATABLE, DIMENSION(:) :: seed\nREAL random_real\n\nCALL RANDOM_SEED(size = seed_size)\nALLOCATE(seed(seed_size))\nCALL SYSTEM_CLOCK(count = clock)\nseed = clock + 37 * (/ (i - 1, i = 1, seed_size) /)\nCALL RANDOM_SEED(put = seed)\nDEALLOCATE(seed)\n\n! Create random integer values for Nx, Ny, Nz\nCALL RANDOM_NUMBER(random_real)\nNx = N_min + FLOOR( (N_max+1-N_min)*random_real )\nCALL RANDOM_NUMBER(random_real)\nNy = N_min + FLOOR( (N_max+1-N_min)*random_real )\nCALL RANDOM_NUMBER(random_real)\nNz = N_min + FLOOR( (N_max+1-N_min)*random_real )\n\ndx = 1.0/DBLE(Nx)\ndy = 1.0/DBLE(Ny)\ndz = 1.0/DBLE(Nz)\nALLOCATE(Q( -2:Nx+3, -2:Ny+3, -2:Nz+3))\nALLOCATE(Qall(-2:Nx+3, -2:Ny+3, -2:Nz+3))\n\nCALL InitializeBoundaries(Nx, Ny, Nz)\n\n! Initialize Q with -100\nQ = DBLE(-100)\n\n! Fill inner values of Q\nDO k=1,Nz\n DO j=1,Ny\n DO i=1,Nx\n\n x = 0.5*dx + DBLE(i - 1)*dx\n y = 0.5*dy + DBLE(j - 1)*dy\n z = 0.5*dz + DBLE(k - 1)*dz\n \n Q(i,j,k) = SIN(2.0*pi*x)*SIN(2.0*pi*y)*SIN(2.0*pi*z)\n END DO\n END DO\nEND DO\n\n! Fill Qall, including correctly set halo values\n! Fill inner values of Q\nDO k=-2,Nz+3\n DO j=-2,Ny+3\n DO i=-2,Nx+3\n\n x = 0.5*dx + DBLE(i - 1)*dx\n y = 0.5*dy + DBLE(j - 1)*dy\n z = 0.5*dz + DBLE(k - 1)*dz\n \n Qall(i,j,k) = SIN(2.0*pi*x)*SIN(2.0*pi*y)*SIN(2.0*pi*z)\n END DO\n END DO\nEND DO\n\nCALL periodic(Q)\n\nIF (MAXVAL(ABS(Q(-2:0,1:Ny,1:Nz) - Qall(-2:0,1:Ny,1:Nz)))>1e-14) THEN\n WRITE(*,*) 'Mismatch between Q and Qall in i-ghostcells with indices -2,-1,0'\n STOP\nELSE IF (MAXVAL(ABS(Q(Nx+1:Nx+3,1:Ny,1:Nz) - Qall(Nx+1:Nx+3,1:Ny,1:Nz)))>1e-14) THEN\n WRITE(*,*) 'Mismatch between Q and Qall in i-ghostcells with indices Nx+1, Nx+2, Nx+3'\n STOP\nELSE IF (MAXVAL(ABS(Q(1:Nx,-2:0,1:Nz) - Qall(1:Nx,-2:0,1:Nz)))>1e-14) THEN\n WRITE(*,*) 'Mismatch between Q and Qall in j-ghostcells with indices -2,-1,0'\n STOP\nELSE IF (MAXVAL(ABS(Q(1:Nx,Ny+1:Ny+3,1:Nz) - Qall(1:Nx,Ny+1:Ny+3,1:Nz)))>1e-14) THEN\n WRITE(*,*) 'Mismatch between Q and Qall in j-ghostcells with indices Ny+1, Ny+2, Ny+3'\n STOP \nELSE IF (MAXVAL(ABS(Q(1:Nx,1:Ny,-2:0)-Qall(1:Nx,1:Ny,-2:0)))>1e-14) THEN \n WRITE(*,*) 'Mismatch between Q and Qall in k-ghostcells with indices -2,-1,0'\n STOP \nELSE IF (MAXVAL(ABS(Q(1:Nx,1:Ny,Nz+1:Nz+3)-Qall(1:Nx,1:Ny,Nz+1:Nz+3)))>1e-14) THEN \n WRITE(*,*) 'Mismatch between Q and Qall in k-ghostcells with indices Nz+1, Nz+2, Nz+3'\n STOP \nEND IF\n\nIF (MAXVAL(ABS(Q(-2:0,1:Ny,1:Nz) - Q(Nx-2:Nx,1:Ny,1:Nz)))>1e-14) THEN\n WRITE(*,*) 'Mismatch in i-ghostcells with index -2,-1,0 and other side Q values'\n STOP\nELSE IF (MAXVAL(ABS(Q(Nx+1:Nx+3,1:Ny,1:Nz)-Q(1:3,1:Ny,1:Nz)))>1e-14) THEN\n WRITE(*,*) 'Mismatch in i-ghostcells with index Nx+1, Nx+2, Nx+3 and other side Q values'\n STOP \nELSE IF (MAXVAL(ABS(Q(1:Nx,-2:0,1:Nz)-Q(1:Nx,Ny-2:Ny,1:Nz)))>1e-14) THEN \n WRITE(*,*) 'Mismatch in j-ghostcells with index -2,-1,0 and other side Q values'\n STOP\nELSE IF (MAXVAL(ABS(Q(1:Nx,Ny+1:Ny+3,1:Nz)-Q(1:Nx,1:3,1:Nz)))>1e-14) THEN\n WRITE(*,*) 'Mismatch in j-ghostcells with index Nx+1, Nx+2, Nx+3 and other side Q values'\n STOP \nELSE IF (MAXVAL(ABS(Q(1:Nx,1:Ny,-2:0)-Q(1:Nx,1:Ny,Nz-2:Nz)))>1e-14) THEN\n WRITE(*,*) 'Mismatch in k-ghostcells with index -2,-1,0 and other side Q values'\n STOP \nELSE IF (MAXVAL(ABS(Q(1:Nx,1:Ny,Nz+1:Nz+3)-Q(1:Nx,1:Ny,1:3)))>1e-14) THEN\n WRITE(*,*) 'Mismatch in k-ghostcells with index Nx+1, Nx+2, Nx+3 and other side Q values'\n STOP \nEND IF\n\nDEALLOCATE(Q)\nDEALLOCATE(Qall)\n\nPRINT*, '\\x1B[32m[0] -- Successful: Ghost cell values generated by boundaries module match directly inserted values.\\x1B[0m'\n\nEND PROGRAM boundaries_test\n", "meta": {"hexsha": "ada0d01ce7e6f4b55adcd302c840cea4deb42ee3", "size": 4151, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/src/boundaries_test.f90", "max_stars_repo_name": "Parallel-in-Time/PararealF90", "max_stars_repo_head_hexsha": "a8318a79b92465a8a3cf775cc7fd096ff0494529", "max_stars_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2017-03-17T15:04:00.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-10T08:05:52.000Z", "max_issues_repo_path": "test/src/boundaries_test.f90", "max_issues_repo_name": "Parallel-in-Time/PararealF90", "max_issues_repo_head_hexsha": "a8318a79b92465a8a3cf775cc7fd096ff0494529", "max_issues_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2015-09-23T09:08:12.000Z", "max_issues_repo_issues_event_max_datetime": "2015-09-23T09:32:24.000Z", "max_forks_repo_path": "test/src/boundaries_test.f90", "max_forks_repo_name": "Parallel-in-Time/PararealF90", "max_forks_repo_head_hexsha": "a8318a79b92465a8a3cf775cc7fd096ff0494529", "max_forks_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-10-24T20:15:26.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-10T08:05:36.000Z", "avg_line_length": 34.8823529412, "max_line_length": 124, "alphanum_fraction": 0.6251505661, "num_tokens": 1689, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920020959544, "lm_q2_score": 0.8244619220634457, "lm_q1q2_score": 0.6601400670288591}} {"text": "! { dg-do run }\n! Check that simplification of maxloc works\nprogram main\n implicit none\n integer :: d\n real, dimension(2), parameter :: a = [1.0, 0.0]\n character(len=3), dimension(3), parameter :: c = [ \"fgh\", \"asd\", \"jkl\" ]\n integer, parameter :: b = maxloc(a,dim=1)\n integer, parameter :: b2 = maxloc(a,dim=1,mask=[.false.,.false.])\n integer, parameter :: b3 = maxloc(c,dim=1)\n integer, parameter :: b4 = maxloc(c,dim=1,mask=[c<\"iii\"])\n integer, parameter,dimension(2,2) :: i1 = reshape([4,5,3,2],shape(i1))\n integer, parameter, dimension(2) :: b5 = maxloc(i1)\n integer, parameter, dimension(2) :: b6 = maxloc(i1,mask=i1>7)\n integer, parameter, dimension(2) :: b7 = maxloc(i1, mask=i1<5)\n integer, parameter, dimension(2) :: b8 = maxloc(i1, mask=.true.)\n integer, parameter, dimension(2) :: b9 = maxloc(i1, mask=.false.)\n integer, parameter, dimension(2,3) :: i2 = &\n reshape([2, -1, -3, 4, -5, 6], shape(i2))\n integer, parameter, dimension(3) :: b10 = maxloc(i2, dim=1)\n integer, parameter, dimension(2) :: b11 = maxloc(i2, dim=2)\n integer, parameter, dimension(3) :: b12 = maxloc(i2,dim=1,mask=i2<0)\n integer, parameter, dimension(2) :: b13 = maxloc(i2,dim=2, mask=i2<-10)\n if (b /= 1) STOP 1\n if (b2 /= 0) STOP 2\n if (b3 /= 3) STOP 3\n if (b4 /= 1) STOP 4\n if (any(b5 /= [2,1])) STOP 5\n if (any(b6 /= [0, 0])) STOP 6\n if (any(b7 /= [1,1])) STOP 7\n if (any(b8 /= b5)) STOP 8\n if (any(b9 /= [0, 0])) STOP 9\n d = 1\n if (any(b10 /= maxloc(i2,dim=d))) STOP 10\n d = 2\n if (any(b11 /= maxloc(i2,dim=2))) STOP 11\n d = 1\n if (any(b12 /= maxloc(i2, dim=d,mask=i2<0))) STOP 12\n if (any(b13 /= 0)) STOP 13\nend program main\n", "meta": {"hexsha": "b17a55f5a30717d3119ace89836dba84a06938e7", "size": 1657, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/maxloc_4.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/maxloc_4.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/maxloc_4.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": 40.4146341463, "max_line_length": 74, "alphanum_fraction": 0.6010863005, "num_tokens": 657, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619091240701, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.6601400605895316}} {"text": " SUBROUTINE cntab2(nn,ni,nj,h,hx,hy,hygx,hxgy,uygx,uxgy,uxy)\r\n INTEGER ni,nj,nn(ni,nj),MAXI,MAXJ\r\n REAL h,hx,hxgy,hy,hygx,uxgy,uxy,uygx,TINY\r\n PARAMETER (MAXI=100,MAXJ=100,TINY=1.e-30)\r\n INTEGER i,j\r\n REAL p,sum,sumi(MAXI),sumj(MAXJ)\r\n sum=0\r\n do 12 i=1,ni\r\n sumi(i)=0.0\r\n do 11 j=1,nj\r\n sumi(i)=sumi(i)+nn(i,j)\r\n sum=sum+nn(i,j)\r\n11 continue\r\n12 continue\r\n do 14 j=1,nj\r\n sumj(j)=0.\r\n do 13 i=1,ni\r\n sumj(j)=sumj(j)+nn(i,j)\r\n13 continue\r\n14 continue\r\n hx=0.\r\n do 15 i=1,ni\r\n if(sumi(i).ne.0.)then\r\n p=sumi(i)/sum\r\n hx=hx-p*log(p)\r\n endif\r\n15 continue\r\n hy=0.\r\n do 16 j=1,nj\r\n if(sumj(j).ne.0.)then\r\n p=sumj(j)/sum\r\n hy=hy-p*log(p)\r\n endif\r\n16 continue\r\n h=0.\r\n do 18 i=1,ni\r\n do 17 j=1,nj\r\n if(nn(i,j).ne.0)then\r\n p=nn(i,j)/sum\r\n h=h-p*log(p)\r\n endif\r\n17 continue\r\n18 continue\r\n hygx=h-hx\r\n hxgy=h-hy\r\n uygx=(hy-hygx)/(hy+TINY)\r\n uxgy=(hx-hxgy)/(hx+TINY)\r\n uxy=2.*(hx+hy-h)/(hx+hy+TINY)\r\n return\r\n END\r\n", "meta": {"hexsha": "187bf4f070272470ae87b8548b242fef688c9e94", "size": 1210, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/cntab2.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/cntab2.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/cntab2.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.7254901961, "max_line_length": 66, "alphanum_fraction": 0.4570247934, "num_tokens": 458, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888302, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.6600956809844266}} {"text": "\r\n!\t\tThis program uses the modified Cholesky decomposition\r\n!\t\tin lu to solve the equation lusolve = b.\r\nfunction solve(lu,b)\r\nimplicit none\r\n\r\nreal(kind=8),intent(in)::lu(:,:)\r\nreal(kind=8),intent(in)::b(:)\r\nreal(kind=8)::solve(size(b))\r\ninteger:: row,col,n\r\nn=size(b)\r\n!\t Lower triangle.\r\nsolve(1) = b(1)\r\nif(lu(1,1)<=0.0_8) solve(1) = 0.0_8\r\nif(n>1)then\r\n\tdo row=2,n\r\n\t\tif(lu(row,row)<=0.0_8) then\r\n\t\t\tsolve(row)=0.0_8\r\n\t\telse\r\n\t\t\tsolve(row)=b(row)-dot_product(lu(row,1:row-1),solve(1:row-1))\r\n\t \tend if\r\n\t end do\r\n!\t Upper triangle.\r\nend if\r\nif(lu(n,n)>0.0_8)then\r\n \tsolve(n) = solve(n)/lu(n,n)\r\nelse\r\n \tsolve(n) = 0.0_8\r\nend if\r\nif(n==1) return\r\ndo col=n,2,-1\r\n\trow=col-1\r\n \tif(lu(row,row)<=0.0_8)then \r\n \t\tsolve(row) = 0.0_8\r\n \telse\r\n \t\tsolve(row) = (solve(row)-dot_product(lu(row,col:n),solve(col:n)))/lu(row,row)\r\n \tend if\r\nend do \r\nreturn\r\nend function solve\r\n", "meta": {"hexsha": "bff8f35408d2eceb4824e03589c16cc6e0f6b4c0", "size": 870, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Source/dsolvef.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/dsolvef.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/dsolvef.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": 21.2195121951, "max_line_length": 82, "alphanum_fraction": 0.6149425287, "num_tokens": 341, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110396870287, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6600956673596983}} {"text": "use ArrayClass\nuse IOClass\nimplicit none\n\nreal(real64),allocatable :: t(:),Ft(:)\nreal(real64) :: tau\ntype(IO_) :: f\n\ntau = 100.0d0\nt = linspace([0.0d0,2.0d0*tau],10000)\nFt = t\n\n! accel.\nFt(1 :5000) = 1.0d0\nFt(5001:6000) = -10.0d0\nFt(6001:7000) = 1.0d0\nFt(7001:8000) = -3.0d0\nFt(8001:9000) = 10.0d0\nFt(9001:10000) = -1.0d0\n\ncall f%plot(t,Ft)\n! velocity\ncall f%plot(t, I_dx(t,Ft) )\n! displacement\ncall f%plot(t, I_dx(t,I_dx(t,Ft)) )\n\nend", "meta": {"hexsha": "c5276cc8b61566c8604e9efd4ae1e3aabd4a99ac", "size": 441, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/plotFunctionAndIntegral.f90", "max_stars_repo_name": "kazulagi/faba", "max_stars_repo_head_hexsha": "7ef140f1ebea0e0ca496d14fdb94a3c024393cfa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-05T06:04:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:04:25.000Z", "max_issues_repo_path": "Tutorial/std/plotFunctionAndIntegral.f90", "max_issues_repo_name": "kazulagi/plantFEM_binary", "max_issues_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Tutorial/std/plotFunctionAndIntegral.f90", "max_forks_repo_name": "kazulagi/plantFEM_binary", "max_forks_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.3333333333, "max_line_length": 38, "alphanum_fraction": 0.6349206349, "num_tokens": 226, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6600625693063391}} {"text": " IMPLICIT NONE \n REAL::x,vel,F,m,H\n INTEGER::ixx\n INTEGER,PARAMETER::itime = 10000\n\t\tREAL,PARAMETER::xposeq = 0.0, val=1.000,delta=0.02\n\t\t\n\t\t\n\n\n\t\tx = 0.00\n\t\tvel = 1\n F= -val*(x-xposeq)\n m=1.00\n ixx=0\n \n !write(16,*) ixx*delta,x\n !write(18,*) ixx*delta,vel\n H = 0.5 *(vel**2) + 0.5 * val *(x**2)\n !write(20,*) x,vel\n write(28,*) ixx*delta,H\n \n\n\n\t\t\n\t\tdo ixx = 1, itime \n\n\n \n\t\tvel = vel + (0.5*(F/m)*delta)\n x=x + (vel*delta)\n F = -val*(x-xposeq)\n vel = vel + (0.5*(F/m)*delta)\n \n \n\t\t\n\n\t\t!write(16,*) ixx*delta,x\n !write(18,*) ixx*delta,vel\n H = 0.5 *(vel**2) + 0.5 * val *(x**2)\n !write(20,*) x,vel\n write(28,*) ixx*delta,H\n\n\t\tend do \n\n\n\t\tstop\n\t\tend\n", "meta": {"hexsha": "e0ce6dc546e3aa8da4681c5a298ed04ee9ddcb26", "size": 993, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "verlet_harmonic/change_1/shmfinal.f90", "max_stars_repo_name": "promitray/MD_FORTRAN", "max_stars_repo_head_hexsha": "e349f55a572fe68caf04725ff4b99389a3aaa51e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "verlet_harmonic/change_1/shmfinal.f90", "max_issues_repo_name": "promitray/MD_FORTRAN", "max_issues_repo_head_hexsha": "e349f55a572fe68caf04725ff4b99389a3aaa51e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "verlet_harmonic/change_1/shmfinal.f90", "max_forks_repo_name": "promitray/MD_FORTRAN", "max_forks_repo_head_hexsha": "e349f55a572fe68caf04725ff4b99389a3aaa51e", "max_forks_repo_licenses": ["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.6875, "max_line_length": 53, "alphanum_fraction": 0.3484390735, "num_tokens": 331, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213853793452, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.660062566060522}} {"text": "C SUBROUTINE MATINV.F \nC\nC SOURCE\t\t\t\t\t\t\t\t \nC BEVINGTON, PAGES 302-303.\nC\nC PURPOSE\nC INVERT A SYMMETRIC MATRIX AND CALCULATE ITS DETERMINANT\nC\nC USAGE \nC CALL MATINV (ARRAY, NORDER, DET)\nC\nC DESCRIPTION OF PARAMETERS\nC ARRAY - INPUT MATRIX WHICH IS REPLACED BY ITS INVERSE\nC NORDER - DEGREE OF MATRIX (ORDER OF DETERMINANT)\nC DET - DETERMINANT OF INPUT MATRIX\nC\nC SUBROUTINES AND FUNCTION SUBPROGRAMS REQUIRED \nC NONE\nC\nC COMMENT\nC DIMENSION STATEMENT VALID FOR NORDER UP TO 10\nC\n\tSUBROUTINE MATINV (ARRAY,NORDER,DET)\n\tDOUBLE PRECISION ARRAY,AMAX,SAVE\n\tDIMENSION ARRAY(10,10),IK(10),JK(10)\nC\n10\tDET=1.\n11\tDO 100 K=1,NORDER\nC\nC FIND LARGEST ELEMENT ARRAY(I,J) IN REST OF MATRIX\nC\n\tAMAX=0. \n21\tDO 30 I=K,NORDER\n\tDO 30 J=K,NORDER\n23\tIF (DABS(AMAX)-DABS(ARRAY(I,J))) 24,24,30\n24\tAMAX=ARRAY(I,J) \n\tIK(K)=I \n\tJK(K)=J \n30\tCONTINUE\nC\nC INTERCHANGE ROWS AND COLUMNS TO PUT AMAX IN ARRAY(K,K)\nC\n31\tIF (AMAX) 41,32,41\n32\tDET=0.\n\tGOTO 140\n41\tI=IK(K) \n\tIF (I-K) 21,51,43\n43\tDO 50 J=1,NORDER\n\tSAVE=ARRAY(K,J) \n\tARRAY(K,J)=ARRAY(I,J)\n50\tARRAY(I,J)=-SAVE\n51\tJ=JK(K) \n\tIF (J-K) 21,61,53\n53\tDO 60 I=1,NORDER\n\tSAVE=ARRAY(I,K) \n\tARRAY(I,K)=ARRAY(I,J)\n60\tARRAY(I,J)=-SAVE\nC\nC ACCUMULATE ELEMENTS OF INVERSE MATRIX \nC\n61\tDO 70 I=1,NORDER\n\tIF (I-K) 63,70,63\n63\tARRAY(I,K)=-ARRAY(I,K)/AMAX\n70\tCONTINUE\n71\tDO 80 I=1,NORDER\n\tDO 80 J=1,NORDER\n\tIF (I-K) 74,80,74\n74\tIF (J-K) 75,80,75\n75\tARRAY(I,J)=ARRAY(I,J)+ARRAY(I,K)*ARRAY(K,J)\n80\tCONTINUE\n81\tDO 90 J=1,NORDER\n\tIF (J-K) 83,90,83\n83\tARRAY(K,J)=ARRAY(K,J)/AMAX\n90\tCONTINUE\n\tARRAY(K,K)=1./AMAX\n100\tDET=DET*AMAX\nC\nC RESTORE ORDERING OF MATRIX\nC\n101\tDO 130 L=1,NORDER\n\tK=NORDER-L+1\n\tJ=IK(K) \n\tIF (J-K) 111,111,105\n105\tDO 110 I=1,NORDER\n\tSAVE=ARRAY(I,K) \n\tARRAY(I,K)=-ARRAY(I,J)\n110\tARRAY(I,J)=SAVE \n111\tI=JK(K) \n\tIF (I-K) 130,130,113\n113\tDO 120 J=1,NORDER\n\tSAVE=ARRAY(K,J) \n\tARRAY(K,J)=-ARRAY(I,J)\n120\tARRAY(I,J)=SAVE \n130\tCONTINUE\n140\tRETURN\n\tEND\n", "meta": {"hexsha": "5b1815c25913f8dd99d89ef1bfecd4dcaaae60cc", "size": 1894, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iraf.v2161/math/bevington/matinv.f", "max_stars_repo_name": "ysBach/irafdocgen", "max_stars_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:19:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T16:48:42.000Z", "max_issues_repo_path": "math/bevington/matinv.f", "max_issues_repo_name": "kirxkirx/iraf", "max_issues_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-30T13:48:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-02T19:40:25.000Z", "max_forks_repo_path": "math/bevington/matinv.f", "max_forks_repo_name": "kirxkirx/iraf", "max_forks_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.5257731959, "max_line_length": 59, "alphanum_fraction": 0.6842661035, "num_tokens": 822, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.6600625640760988}} {"text": "program main\n use plantFEM\n implicit none\n\n real(real64),parameter :: duration=10.0d0\n integer(int32),parameter :: sampling = 4096\n type(Random_) :: random\n type(IO_) :: f,z\n type(Math_) :: Math\n integer(int32) :: i\n complex(complex64 ),allocatable :: wave(:),spectre(:)\n real(real64),allocatable :: omega(:), t(:)\n real(real64) :: dt,set_omega\n\n set_omega = (20.0d0/2.0d0/math%PI) ! 15.92356687898089\n\n print *, set_omega\n create_input_wave: block\n t = linspace([0.0d0, duration], sampling)\n dt = duration/dble(sampling)\n wave = zeros(4096)\n do i=1, size(wave)\n wave(i) = random%gauss(mu=0.0d0, sigma=1.0d0)\n wave(i) = sin( set_omega*t(i) )!+sin( 3.0d0*dt*dble(i) )!+random%gauss(mu=0.0d0, sigma=1.0d0)\n enddo\n end block create_input_wave\n\n show_input_wave: block\n call f%open(\"input_wave.txt\")\n call f%write( t,real(wave) )\n call f%close()\n call f%plot(option=\"with lines\")\n end block show_input_wave\n\n run_FFT: block\n omega = linspace([0.0d0, dble(sampling)/duration*2.0d0*math%PI ], sampling)\n spectre = zeros(sampling)\n spectre = FFT(wave)\n call z%open(\"spectre.txt\")\n do i=1,size(spectre)/2\n call z%write(omega(i),abs( spectre(i)))\n enddo\n call z%close()\n call z%plot(option=\"with lines\",logscale=true)\n end block run_FFT\n\nend program main", "meta": {"hexsha": "c1a9ed7fc034c572c5175ac63571a18ef3ecf7d8", "size": 1462, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/simpleFFT.f90", "max_stars_repo_name": "kazulagi/faba", "max_stars_repo_head_hexsha": "7ef140f1ebea0e0ca496d14fdb94a3c024393cfa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-05T06:04:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:04:25.000Z", "max_issues_repo_path": "Tutorial/std/simpleFFT.f90", "max_issues_repo_name": "kazulagi/plantFEM_binary", "max_issues_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Tutorial/std/simpleFFT.f90", "max_forks_repo_name": "kazulagi/plantFEM_binary", "max_forks_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.1063829787, "max_line_length": 105, "alphanum_fraction": 0.5950752394, "num_tokens": 467, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699435, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.660062560107252}} {"text": " program Day9\r\n implicit none\r\n\r\nc locals \r\n double precision values(1024)\r\n double precision valid,sum,value\r\n double precision validate,weakness\r\n\r\n integer i,j,io,count,preamble\r\n\r\n\r\nc read input file \r\n count = 0\r\n open(1,FILE='input.txt',STATUS='OLD')\r\n do\r\n read(1,*,IOSTAT=io) value\r\n if (io.gt.0) then\r\n write(*,*) 'Error'\r\n exit\r\n else if(io.lt.0) then\r\n exit\r\n else\r\n count = count+1\r\n values(count) = value\r\n endif\r\n enddo\r\n close(1)\r\n\r\nc preamble for `input.txt` \r\n preamble = 25\r\n\r\nc preamble for `test.txt`\r\nc preamble = 5 \r\n\r\nc iterate over the values\r\n do i=preamble+1,count\r\n\r\nc check invalid\r\n valid = validate(values,values(i),i-preamble, i-1)\r\n if (valid.eq.0) then\r\n write(*,*) 'Part 1'\r\n write(*,*) 'Invalid: ',values(i)\r\n\r\n write(*,*) 'Part 2'\r\n sum = weakness(values,count,values(i))\r\n write(*,*) 'Weakness: ',sum\r\n endif\r\n enddo \r\n end\r\n\r\nc validates the value by finding a matching sum in the \r\nc preamble values\r\n double precision function validate(values,value,sindex,eindex)\r\n implicit none\r\n\r\n double precision values(*),value,sum\r\n integer sindex,eindex,i,j\r\n\r\n validate = 0\r\n do i=sindex,eindex-1\r\n do j=i+1,eindex\r\n sum=values(i) + values(j)\r\nc write(*,*) i,j,values(i),values(j),sum\r\n if(sum.eq.value) then\r\n validate = 1\r\n goto 200\r\n endif\r\n enddo\r\n enddo\r\n 200 continue\r\nc write(*,*) ''\r\n return\r\n end\r\n\r\nc finds the encryption weakness by returning the sum\r\nc of the minimum and maximum values in the preamble values\r\n double precision function weakness(values,count,value)\r\n implicit none\r\n\r\n double precision values(*),value,sum\r\n double precision minimum,maximum\r\n integer count,i,j\r\n\r\nc iterate over values\r\n weakness = -1\r\n do i=1,count-1\r\nc initial minimum, maximum, and sum\r\n minimum = values(i)\r\n maximum = values(j)\r\n sum = values(i)\r\n\r\nc build continguous range\r\n do j=i+1,count\r\n\r\nc update minimum\r\n if(values(j).lt.minimum) then\r\n minimum = values(j)\r\n endif\r\n\r\nc update maximum\r\n if(values(j).gt.maximum) then\r\n maximum = values(j)\r\n endif\r\n\r\nc update sum \r\n sum = sum+values(j)\r\n\r\nc check sum \r\n if(sum.eq.value) then \r\n weakness = minimum + maximum\r\n goto 300\r\n else if(sum.gt.value) then\r\n goto 325\r\n endif\r\n enddo\r\n 325 continue\r\n enddo\r\n 300 continue \r\n return\r\n end\r\n", "meta": {"hexsha": "a74ac1aa0a6dfbd8e0c6d5abd4053547503678fc", "size": 3724, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Day9/main.f", "max_stars_repo_name": "SleepingBearSystems/AdventOfCode2020", "max_stars_repo_head_hexsha": "a37fcedc1178bd20c8e7b5f805cf86b9502aa7bc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Day9/main.f", "max_issues_repo_name": "SleepingBearSystems/AdventOfCode2020", "max_issues_repo_head_hexsha": "a37fcedc1178bd20c8e7b5f805cf86b9502aa7bc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Day9/main.f", "max_forks_repo_name": "SleepingBearSystems/AdventOfCode2020", "max_forks_repo_head_hexsha": "a37fcedc1178bd20c8e7b5f805cf86b9502aa7bc", "max_forks_repo_licenses": ["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.7768595041, "max_line_length": 71, "alphanum_fraction": 0.4019871106, "num_tokens": 696, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6600625588458583}} {"text": "*DECK DBSKES\n SUBROUTINE DBSKES (XNU, X, NIN, BKE)\nC***BEGIN PROLOGUE DBSKES\nC***PURPOSE Compute a sequence of exponentially scaled modified Bessel\nC functions of the third kind of fractional order.\nC***LIBRARY SLATEC (FNLIB)\nC***CATEGORY C10B3\nC***TYPE DOUBLE PRECISION (BESKES-S, DBSKES-D)\nC***KEYWORDS EXPONENTIALLY SCALED, FNLIB, FRACTIONAL ORDER,\nC MODIFIED BESSEL FUNCTION, SEQUENCE OF BESSEL FUNCTIONS,\nC SPECIAL FUNCTIONS, THIRD KIND\nC***AUTHOR Fullerton, W., (LANL)\nC***DESCRIPTION\nC\nC DBSKES(XNU,X,NIN,BKE) computes a double precision sequence\nC of exponentially scaled modified Bessel functions\nC of the third kind of order XNU + I at X, where X .GT. 0,\nC XNU lies in (-1,1), and I = 0, 1, ... , NIN - 1, if NIN is positive\nC and I = 0, -1, ... , NIN + 1, if NIN is negative. On return, the\nC vector BKE(.) contains the results at X for order starting at XNU.\nC XNU, X, and BKE are double precision. NIN is integer.\nC\nC***REFERENCES (NONE)\nC***ROUTINES CALLED D1MACH, D9KNUS, XERMSG\nC***REVISION HISTORY (YYMMDD)\nC 770601 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890911 Removed unnecessary intrinsics. (WRB)\nC 890911 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\nC***END PROLOGUE DBSKES\n DOUBLE PRECISION XNU, X, BKE(*), BKNU1, V, VINCR, VEND, ALNBIG,\n 1 D1MACH, DIRECT\n SAVE ALNBIG\n DATA ALNBIG / 0.D0 /\nC***FIRST EXECUTABLE STATEMENT DBSKES\n IF (ALNBIG.EQ.0.D0) ALNBIG = LOG (D1MACH(2))\nC\n V = ABS(XNU)\n N = ABS(NIN)\nC\n IF (V .GE. 1.D0) CALL XERMSG ('SLATEC', 'DBSKES',\n + 'ABS(XNU) MUST BE LT 1', 2, 2)\n IF (X .LE. 0.D0) CALL XERMSG ('SLATEC', 'DBSKES', 'X IS LE 0', 3,\n + 2)\n IF (N .EQ. 0) CALL XERMSG ('SLATEC', 'DBSKES',\n + 'N THE NUMBER IN THE SEQUENCE IS 0', 4, 2)\nC\n CALL D9KNUS (V, X, BKE(1), BKNU1, ISWTCH)\n IF (N.EQ.1) RETURN\nC\n VINCR = SIGN (1.0, REAL(NIN))\n DIRECT = VINCR\n IF (XNU.NE.0.D0) DIRECT = VINCR*SIGN(1.D0, XNU)\n IF (ISWTCH .EQ. 1 .AND. DIRECT .GT. 0.) CALL XERMSG ('SLATEC',\n + 'DBSKES', 'X SO SMALL BESSEL K-SUB-XNU+1 OVERFLOWS', 5, 2)\n BKE(2) = BKNU1\nC\n IF (DIRECT.LT.0.) CALL D9KNUS (ABS(XNU+VINCR), X, BKE(2), BKNU1,\n 1 ISWTCH)\n IF (N.EQ.2) RETURN\nC\n VEND = ABS (XNU+NIN) - 1.0D0\n IF ((VEND-.5D0)*LOG(VEND)+0.27D0-VEND*(LOG(X)-.694D0) .GT.\n + ALNBIG) CALL XERMSG ('SLATEC', 'DBSKES',\n + 'X SO SMALL OR ABS(NU) SO BIG THAT BESSEL K-SUB-NU ' //\n + 'OVERFLOWS', 5, 2)\nC\n V = XNU\n DO 10 I=3,N\n V = V + VINCR\n BKE(I) = 2.0D0*V*BKE(I-1)/X + BKE(I-2)\n 10 CONTINUE\nC\n RETURN\n END\n", "meta": {"hexsha": "221234396a8652f34fbec30976dd7a70227cca4d", "size": 2821, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/dbskes.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "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": "slatec/src/dbskes.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/dbskes.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.1666666667, "max_line_length": 71, "alphanum_fraction": 0.6114852889, "num_tokens": 1120, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636754, "lm_q2_score": 0.734119526900183, "lm_q1q2_score": 0.6600625561384049}} {"text": "*> \\brief \\b ZPFTRF\n*\n* =========== DOCUMENTATION ===========\n*\n* Online html documentation available at\n* http://www.netlib.org/lapack/explore-html/\n*\n*> \\htmlonly\n*> Download ZPFTRF + dependencies\n*> \n*> [TGZ]\n*> \n*> [ZIP]\n*> \n*> [TXT]\n*> \\endhtmlonly\n*\n* Definition:\n* ===========\n*\n* SUBROUTINE ZPFTRF( TRANSR, UPLO, N, A, INFO )\n*\n* .. Scalar Arguments ..\n* CHARACTER TRANSR, UPLO\n* INTEGER N, INFO\n* ..\n* .. Array Arguments ..\n* COMPLEX*16 A( 0: * )\n*\n*\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*>\n*> ZPFTRF computes the Cholesky factorization of a complex Hermitian\n*> positive definite matrix A.\n*>\n*> The factorization has the form\n*> A = U**H * U, if UPLO = 'U', or\n*> A = L * L**H, if UPLO = 'L',\n*> where U is an upper triangular matrix and L is lower triangular.\n*>\n*> This is the block version of the algorithm, calling Level 3 BLAS.\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in] TRANSR\n*> \\verbatim\n*> TRANSR is CHARACTER*1\n*> = 'N': The Normal TRANSR of RFP A is stored;\n*> = 'C': The Conjugate-transpose TRANSR of RFP A is stored.\n*> \\endverbatim\n*>\n*> \\param[in] UPLO\n*> \\verbatim\n*> UPLO is CHARACTER*1\n*> = 'U': Upper triangle of RFP A is stored;\n*> = 'L': Lower triangle of RFP A is stored.\n*> \\endverbatim\n*>\n*> \\param[in] N\n*> \\verbatim\n*> N is INTEGER\n*> The order of the matrix A. N >= 0.\n*> \\endverbatim\n*>\n*> \\param[in,out] A\n*> \\verbatim\n*> A is COMPLEX*16 array, dimension ( N*(N+1)/2 );\n*> On entry, the Hermitian matrix A in RFP format. RFP format is\n*> described by TRANSR, UPLO, and N as follows: If TRANSR = 'N'\n*> then RFP A is (0:N,0:k-1) when N is even; k=N/2. RFP A is\n*> (0:N-1,0:k) when N is odd; k=N/2. IF TRANSR = 'C' then RFP is\n*> the Conjugate-transpose of RFP A as defined when\n*> TRANSR = 'N'. The contents of RFP A are defined by UPLO as\n*> follows: If UPLO = 'U' the RFP A contains the nt elements of\n*> upper packed A. If UPLO = 'L' the RFP A contains the elements\n*> of lower packed A. The LDA of RFP A is (N+1)/2 when TRANSR =\n*> 'C'. When TRANSR is 'N' the LDA is N+1 when N is even and N\n*> is odd. See the Note below for more details.\n*>\n*> On exit, if INFO = 0, the factor U or L from the Cholesky\n*> factorization RFP A = U**H*U or RFP A = L*L**H.\n*> \\endverbatim\n*>\n*> \\param[out] INFO\n*> \\verbatim\n*> INFO is INTEGER\n*> = 0: successful exit\n*> < 0: if INFO = -i, the i-th argument had an illegal value\n*> > 0: if INFO = i, the leading minor of order i is not\n*> positive definite, and the factorization could not be\n*> completed.\n*>\n*> Further Notes on RFP Format:\n*> ============================\n*>\n*> We first consider Standard Packed Format when N is even.\n*> We give an example where N = 6.\n*>\n*> AP is Upper AP is Lower\n*>\n*> 00 01 02 03 04 05 00\n*> 11 12 13 14 15 10 11\n*> 22 23 24 25 20 21 22\n*> 33 34 35 30 31 32 33\n*> 44 45 40 41 42 43 44\n*> 55 50 51 52 53 54 55\n*>\n*> Let TRANSR = 'N'. RFP holds AP as follows:\n*> For UPLO = 'U' the upper trapezoid A(0:5,0:2) consists of the last\n*> three columns of AP upper. The lower triangle A(4:6,0:2) consists of\n*> conjugate-transpose of the first three columns of AP upper.\n*> For UPLO = 'L' the lower trapezoid A(1:6,0:2) consists of the first\n*> three columns of AP lower. The upper triangle A(0:2,0:2) consists of\n*> conjugate-transpose of the last three columns of AP lower.\n*> To denote conjugate we place -- above the element. This covers the\n*> case N even and TRANSR = 'N'.\n*>\n*> RFP A RFP A\n*>\n*> -- -- --\n*> 03 04 05 33 43 53\n*> -- --\n*> 13 14 15 00 44 54\n*> --\n*> 23 24 25 10 11 55\n*>\n*> 33 34 35 20 21 22\n*> --\n*> 00 44 45 30 31 32\n*> -- --\n*> 01 11 55 40 41 42\n*> -- -- --\n*> 02 12 22 50 51 52\n*>\n*> Now let TRANSR = 'C'. RFP A in both UPLO cases is just the conjugate-\n*> transpose of RFP A above. One therefore gets:\n*>\n*> RFP A RFP A\n*>\n*> -- -- -- -- -- -- -- -- -- --\n*> 03 13 23 33 00 01 02 33 00 10 20 30 40 50\n*> -- -- -- -- -- -- -- -- -- --\n*> 04 14 24 34 44 11 12 43 44 11 21 31 41 51\n*> -- -- -- -- -- -- -- -- -- --\n*> 05 15 25 35 45 55 22 53 54 55 22 32 42 52\n*>\n*> We next consider Standard Packed Format when N is odd.\n*> We give an example where N = 5.\n*>\n*> AP is Upper AP is Lower\n*>\n*> 00 01 02 03 04 00\n*> 11 12 13 14 10 11\n*> 22 23 24 20 21 22\n*> 33 34 30 31 32 33\n*> 44 40 41 42 43 44\n*>\n*> Let TRANSR = 'N'. RFP holds AP as follows:\n*> For UPLO = 'U' the upper trapezoid A(0:4,0:2) consists of the last\n*> three columns of AP upper. The lower triangle A(3:4,0:1) consists of\n*> conjugate-transpose of the first two columns of AP upper.\n*> For UPLO = 'L' the lower trapezoid A(0:4,0:2) consists of the first\n*> three columns of AP lower. The upper triangle A(0:1,1:2) consists of\n*> conjugate-transpose of the last two columns of AP lower.\n*> To denote conjugate we place -- above the element. This covers the\n*> case N odd and TRANSR = 'N'.\n*>\n*> RFP A RFP A\n*>\n*> -- --\n*> 02 03 04 00 33 43\n*> --\n*> 12 13 14 10 11 44\n*>\n*> 22 23 24 20 21 22\n*> --\n*> 00 33 34 30 31 32\n*> -- --\n*> 01 11 44 40 41 42\n*>\n*> Now let TRANSR = 'C'. RFP A in both UPLO cases is just the conjugate-\n*> transpose of RFP A above. One therefore gets:\n*>\n*> RFP A RFP A\n*>\n*> -- -- -- -- -- -- -- -- --\n*> 02 12 22 00 01 00 10 20 30 40 50\n*> -- -- -- -- -- -- -- -- --\n*> 03 13 23 33 11 33 11 21 31 41 51\n*> -- -- -- -- -- -- -- -- --\n*> 04 14 24 34 44 43 44 22 32 42 52\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee\n*> \\author Univ. of California Berkeley\n*> \\author Univ. of Colorado Denver\n*> \\author NAG Ltd.\n*\n*> \\ingroup complex16OTHERcomputational\n*\n* =====================================================================\n SUBROUTINE ZPFTRF( TRANSR, UPLO, N, A, INFO )\n*\n* -- LAPACK computational routine --\n* -- LAPACK is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n*\n* .. Scalar Arguments ..\n CHARACTER TRANSR, UPLO\n INTEGER N, INFO\n* ..\n* .. Array Arguments ..\n COMPLEX*16 A( 0: * )\n*\n* =====================================================================\n*\n* .. Parameters ..\n DOUBLE PRECISION ONE\n COMPLEX*16 CONE\n PARAMETER ( ONE = 1.0D+0, CONE = ( 1.0D+0, 0.0D+0 ) )\n* ..\n* .. Local Scalars ..\n LOGICAL LOWER, NISODD, NORMALTRANSR\n INTEGER N1, N2, K\n* ..\n* .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\n* ..\n* .. External Subroutines ..\n EXTERNAL XERBLA, ZHERK, ZPOTRF, ZTRSM\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC MOD\n* ..\n* .. Executable Statements ..\n*\n* Test the input parameters.\n*\n INFO = 0\n NORMALTRANSR = LSAME( TRANSR, 'N' )\n LOWER = LSAME( UPLO, 'L' )\n IF( .NOT.NORMALTRANSR .AND. .NOT.LSAME( TRANSR, 'C' ) ) THEN\n INFO = -1\n ELSE IF( .NOT.LOWER .AND. .NOT.LSAME( UPLO, 'U' ) ) THEN\n INFO = -2\n ELSE IF( N.LT.0 ) THEN\n INFO = -3\n END IF\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'ZPFTRF', -INFO )\n RETURN\n END IF\n*\n* Quick return if possible\n*\n IF( N.EQ.0 )\n $ RETURN\n*\n* If N is odd, set NISODD = .TRUE.\n* If N is even, set K = N/2 and NISODD = .FALSE.\n*\n IF( MOD( N, 2 ).EQ.0 ) THEN\n K = N / 2\n NISODD = .FALSE.\n ELSE\n NISODD = .TRUE.\n END IF\n*\n* Set N1 and N2 depending on LOWER\n*\n IF( LOWER ) THEN\n N2 = N / 2\n N1 = N - N2\n ELSE\n N1 = N / 2\n N2 = N - N1\n END IF\n*\n* start execution: there are eight cases\n*\n IF( NISODD ) THEN\n*\n* N is odd\n*\n IF( NORMALTRANSR ) THEN\n*\n* N is odd and TRANSR = 'N'\n*\n IF( LOWER ) THEN\n*\n* SRPA for LOWER, NORMAL and N is odd ( a(0:n-1,0:n1-1) )\n* T1 -> a(0,0), T2 -> a(0,1), S -> a(n1,0)\n* T1 -> a(0), T2 -> a(n), S -> a(n1)\n*\n CALL ZPOTRF( 'L', N1, A( 0 ), N, INFO )\n IF( INFO.GT.0 )\n $ RETURN\n CALL ZTRSM( 'R', 'L', 'C', 'N', N2, N1, CONE, A( 0 ), N,\n $ A( N1 ), N )\n CALL ZHERK( 'U', 'N', N2, N1, -ONE, A( N1 ), N, ONE,\n $ A( N ), N )\n CALL ZPOTRF( 'U', N2, A( N ), N, INFO )\n IF( INFO.GT.0 )\n $ INFO = INFO + N1\n*\n ELSE\n*\n* SRPA for UPPER, NORMAL and N is odd ( a(0:n-1,0:n2-1)\n* T1 -> a(n1+1,0), T2 -> a(n1,0), S -> a(0,0)\n* T1 -> a(n2), T2 -> a(n1), S -> a(0)\n*\n CALL ZPOTRF( 'L', N1, A( N2 ), N, INFO )\n IF( INFO.GT.0 )\n $ RETURN\n CALL ZTRSM( 'L', 'L', 'N', 'N', N1, N2, CONE, A( N2 ), N,\n $ A( 0 ), N )\n CALL ZHERK( 'U', 'C', N2, N1, -ONE, A( 0 ), N, ONE,\n $ A( N1 ), N )\n CALL ZPOTRF( 'U', N2, A( N1 ), N, INFO )\n IF( INFO.GT.0 )\n $ INFO = INFO + N1\n*\n END IF\n*\n ELSE\n*\n* N is odd and TRANSR = 'C'\n*\n IF( LOWER ) THEN\n*\n* SRPA for LOWER, TRANSPOSE and N is odd\n* T1 -> A(0,0) , T2 -> A(1,0) , S -> A(0,n1)\n* T1 -> a(0+0) , T2 -> a(1+0) , S -> a(0+n1*n1); lda=n1\n*\n CALL ZPOTRF( 'U', N1, A( 0 ), N1, INFO )\n IF( INFO.GT.0 )\n $ RETURN\n CALL ZTRSM( 'L', 'U', 'C', 'N', N1, N2, CONE, A( 0 ), N1,\n $ A( N1*N1 ), N1 )\n CALL ZHERK( 'L', 'C', N2, N1, -ONE, A( N1*N1 ), N1, ONE,\n $ A( 1 ), N1 )\n CALL ZPOTRF( 'L', N2, A( 1 ), N1, INFO )\n IF( INFO.GT.0 )\n $ INFO = INFO + N1\n*\n ELSE\n*\n* SRPA for UPPER, TRANSPOSE and N is odd\n* T1 -> A(0,n1+1), T2 -> A(0,n1), S -> A(0,0)\n* T1 -> a(n2*n2), T2 -> a(n1*n2), S -> a(0); lda = n2\n*\n CALL ZPOTRF( 'U', N1, A( N2*N2 ), N2, INFO )\n IF( INFO.GT.0 )\n $ RETURN\n CALL ZTRSM( 'R', 'U', 'N', 'N', N2, N1, CONE, A( N2*N2 ),\n $ N2, A( 0 ), N2 )\n CALL ZHERK( 'L', 'N', N2, N1, -ONE, A( 0 ), N2, ONE,\n $ A( N1*N2 ), N2 )\n CALL ZPOTRF( 'L', N2, A( N1*N2 ), N2, INFO )\n IF( INFO.GT.0 )\n $ INFO = INFO + N1\n*\n END IF\n*\n END IF\n*\n ELSE\n*\n* N is even\n*\n IF( NORMALTRANSR ) THEN\n*\n* N is even and TRANSR = 'N'\n*\n IF( LOWER ) THEN\n*\n* SRPA for LOWER, NORMAL, and N is even ( a(0:n,0:k-1) )\n* T1 -> a(1,0), T2 -> a(0,0), S -> a(k+1,0)\n* T1 -> a(1), T2 -> a(0), S -> a(k+1)\n*\n CALL ZPOTRF( 'L', K, A( 1 ), N+1, INFO )\n IF( INFO.GT.0 )\n $ RETURN\n CALL ZTRSM( 'R', 'L', 'C', 'N', K, K, CONE, A( 1 ), N+1,\n $ A( K+1 ), N+1 )\n CALL ZHERK( 'U', 'N', K, K, -ONE, A( K+1 ), N+1, ONE,\n $ A( 0 ), N+1 )\n CALL ZPOTRF( 'U', K, A( 0 ), N+1, INFO )\n IF( INFO.GT.0 )\n $ INFO = INFO + K\n*\n ELSE\n*\n* SRPA for UPPER, NORMAL, and N is even ( a(0:n,0:k-1) )\n* T1 -> a(k+1,0) , T2 -> a(k,0), S -> a(0,0)\n* T1 -> a(k+1), T2 -> a(k), S -> a(0)\n*\n CALL ZPOTRF( 'L', K, A( K+1 ), N+1, INFO )\n IF( INFO.GT.0 )\n $ RETURN\n CALL ZTRSM( 'L', 'L', 'N', 'N', K, K, CONE, A( K+1 ),\n $ N+1, A( 0 ), N+1 )\n CALL ZHERK( 'U', 'C', K, K, -ONE, A( 0 ), N+1, ONE,\n $ A( K ), N+1 )\n CALL ZPOTRF( 'U', K, A( K ), N+1, INFO )\n IF( INFO.GT.0 )\n $ INFO = INFO + K\n*\n END IF\n*\n ELSE\n*\n* N is even and TRANSR = 'C'\n*\n IF( LOWER ) THEN\n*\n* SRPA for LOWER, TRANSPOSE and N is even (see paper)\n* T1 -> B(0,1), T2 -> B(0,0), S -> B(0,k+1)\n* T1 -> a(0+k), T2 -> a(0+0), S -> a(0+k*(k+1)); lda=k\n*\n CALL ZPOTRF( 'U', K, A( 0+K ), K, INFO )\n IF( INFO.GT.0 )\n $ RETURN\n CALL ZTRSM( 'L', 'U', 'C', 'N', K, K, CONE, A( K ), N1,\n $ A( K*( K+1 ) ), K )\n CALL ZHERK( 'L', 'C', K, K, -ONE, A( K*( K+1 ) ), K, ONE,\n $ A( 0 ), K )\n CALL ZPOTRF( 'L', K, A( 0 ), K, INFO )\n IF( INFO.GT.0 )\n $ INFO = INFO + K\n*\n ELSE\n*\n* SRPA for UPPER, TRANSPOSE and N is even (see paper)\n* T1 -> B(0,k+1), T2 -> B(0,k), S -> B(0,0)\n* T1 -> a(0+k*(k+1)), T2 -> a(0+k*k), S -> a(0+0)); lda=k\n*\n CALL ZPOTRF( 'U', K, A( K*( K+1 ) ), K, INFO )\n IF( INFO.GT.0 )\n $ RETURN\n CALL ZTRSM( 'R', 'U', 'N', 'N', K, K, CONE,\n $ A( K*( K+1 ) ), K, A( 0 ), K )\n CALL ZHERK( 'L', 'N', K, K, -ONE, A( 0 ), K, ONE,\n $ A( K*K ), K )\n CALL ZPOTRF( 'L', K, A( K*K ), K, INFO )\n IF( INFO.GT.0 )\n $ INFO = INFO + K\n*\n END IF\n*\n END IF\n*\n END IF\n*\n RETURN\n*\n* End of ZPFTRF\n*\n END\n", "meta": {"hexsha": "6d18f2cb32139d88a5997dbd8ffa4a4d3125ce96", "size": 15289, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "SRC/zpftrf.f", "max_stars_repo_name": "sergey-v-kuznetsov/lapack", "max_stars_repo_head_hexsha": "799ef93faa5878aa8702f7cf9980cfc649cc39cc", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 998, "max_stars_repo_stars_event_min_datetime": "2016-05-04T20:50:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T17:43:13.000Z", "max_issues_repo_path": "SRC/zpftrf.f", "max_issues_repo_name": "sergey-v-kuznetsov/lapack", "max_issues_repo_head_hexsha": "799ef93faa5878aa8702f7cf9980cfc649cc39cc", "max_issues_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_issues_count": 603, "max_issues_repo_issues_event_min_datetime": "2016-06-04T07:28:21.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T21:16:50.000Z", "max_forks_repo_path": "SRC/zpftrf.f", "max_forks_repo_name": "sergey-v-kuznetsov/lapack", "max_forks_repo_head_hexsha": "799ef93faa5878aa8702f7cf9980cfc649cc39cc", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 373, "max_forks_repo_forks_event_min_datetime": "2016-06-04T06:05:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T17:25:45.000Z", "avg_line_length": 32.5991471215, "max_line_length": 111, "alphanum_fraction": 0.4169664465, "num_tokens": 5167, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802484881361, "lm_q2_score": 0.7185943805178139, "lm_q1q2_score": 0.66001474518018}} {"text": "c\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc . .\nc . copyright (c) 1998 by UCAR .\nc . .\nc . University Corporation for Atmospheric Research .\nc . .\nc . all rights reserved .\nc . .\nc . .\nc . SPHEREPACK .\nc . .\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc\nc\nc\nc ... file testsshifte.f contains a test program illustrating the\nc use of subroutine sshifte (see documentation for sshifte)\nc\nc ... required files off spherepack3.0\nc\nc hrfft.f, sshifte.f\nc\nc The \"offset\" scalar field goff is set equal to exp(x+y+z) where\nc x,y,z are the cartesian coordinates restricted to the surface\nc of the unit sphere. This is transferred to the \"regular\" grid\nc in greg. greg is then compared with exp(x+y+z) on the regular grid.\nc Finally greg is transferred back to goff which is again compared\nc with exp(x+y+z). The least squares error after each transformation\nc with sshifte is computed and printed. Output from running the\nc program below on a 2.5 degree equally spaced regular and offset\nc grid is listed below.\nc\nc *** OUTPUT (from execution on 32 bit machine)\nc\nc sshifte arguments\nc ioff = 0 nlon = 144 nlat = 72\nc lsave = 608 lwork = 21024\nc ier = 0\nc least squares error = 0.500E-06\nc sshifte arguments\nc ioff = 1 nlon = 144 nlat = 72\nc lsave = 608 lwork = 21024\nc ier = 0\nc least squares error = 0.666E-06\nc\nc *** END OF OUTPUT\nc\n program testsshifte\n implicit none\n integer nnlon,nnlat,nnlatp1,nnlat2,llsave,llwork\n parameter(nnlon=144,nnlat=72)\n parameter (nnlatp1 = nnlat+1, nnlat2 = nnlat+nnlat)\n parameter (llsave=2*(2*nnlat+nnlon)+32)\nc for nnlon even\n parameter (llwork = 2*(nnlat+1)*nnlon)\nc for nnlon odd\nc parameter (llwork = nnlon*(5*nnlat+1))\n integer ioff,nlon,nlat,nlat2,j,i,lsave,lwork,ier\n real pi,dlat,dlon,dlat2,dlon2,lat,long,x,y,z,gexact,err2\n real goff(nnlon,nnlat),greg(nnlon,nnlatp1)\n real wsave(llsave),work(llwork)\nc\nc set resolution, work space lengths, and grid increments\nc\n nlat = nnlat\n nlon = nnlon\n lsave = llsave\n nlat2 = nnlat2\n lwork = llwork\n pi = 4.0*atan(1.0)\n dlat = pi/nlat\n dlon = (pi+pi)/nlon\n dlat2 = 0.5*dlat\n dlon2 = 0.5*dlon\nc\nc set offset grid values in goff\nc\n do j=1,nlon\n\tlong = dlon2+(j-1)*dlon\n\tdo i=1,nlat\n\t lat = -0.5*pi + dlat2+(i-1)*dlat\n\t x = cos(lat)*cos(long)\n\t y = cos(lat)*sin(long)\n\t z = sin(lat)\n\t goff(j,i) = exp(x+y+z)\n\tend do\n end do\nc\nc initialize wsav for offset to regular shift\nc\n ioff = 0\n call sshifti(ioff,nlon,nlat,lsave,wsave,ier)\nc\nc write input arguments to sshifte\nc\n write(*,100) ioff,nlon,nlat,lsave,lwork\n 100 format(' sshifte arguments',\n +/' ioff = ',i2, ' nlon = ',i3,' nlat = ',i3,\n +/' lsave = ',i5, ' lwork = ',i5)\nc\nc shift offset to regular grid\nc\n call sshifte(ioff,nlon,nlat,goff,greg,wsave,lsave,work,lwork,ier)\n\n write(*,200) ier\n 200 format(' ier = ',i2)\n\n if (ier.eq.0) then\nc\nc compute error in greg\nc\n err2 = 0.0\n do j=1,nlon\n\tlong = (j-1)*dlon\n\tdo i=1,nlat+1\n\t lat = -0.5*pi+(i-1)*dlat\n\t x = cos(lat)*cos(long)\n\t y = cos(lat)*sin(long)\n\t z = sin(lat)\n\t gexact = exp(x+y+z)\n\t err2 = err2 + (greg(j,i)-gexact)**2\n\tend do\n end do\n err2 = sqrt(err2/(nlon*(nlat+1)))\n write(*,300) err2\n 300 format(' least squares error = ', e10.3)\n end if\nc initialize wsav for regular to offset shift\nc\n ioff = 1\n call sshifti(ioff,nlon,nlat,lsave,wsave,ier)\nc\nc now transfer regular grid values in greg back to offset grid in goff\nc\n do j=1,nlon\n\tdo i=1,nlat\n\t goff(j,i) = 0.0\n\tend do\n end do\n write(*,100) ioff,nlon,nlat,lsave,lwork\n call sshifte(ioff,nlon,nlat,goff,greg,wsave,lsave,work,lwork,ier)\n write(*,200) ier\n if (ier .eq. 0) then\nc\nc compute error in goff by comparing with exp(x+y+z) on offset grid\nc\n err2 = 0.0\n do j=1,nlon\n\tlong = dlon2+(j-1)*dlon\n\tdo i=1,nlat\n\t lat = -0.5*pi+dlat2+(i-1)*dlat\n\t x = cos(lat)*cos(long)\n\t y = cos(lat)*sin(long)\n\t z = sin(lat)\n\t gexact = exp(x+y+z)\n\t err2 = err2 + (goff(j,i)-gexact)**2\n\tend do\n end do\n err2 = sqrt(err2/(nlon*(nlat+1)))\n write(*,300) err2\n end if\n end\n", "meta": {"hexsha": "e2a09680c3b1e1dc77a4215ee6e170e3efb42356", "size": 4933, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/drivers/testsshifte.f", "max_stars_repo_name": "jprules321/colas", "max_stars_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/drivers/testsshifte.f", "max_issues_repo_name": "jprules321/colas", "max_issues_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/drivers/testsshifte.f", "max_forks_repo_name": "jprules321/colas", "max_forks_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.0792682927, "max_line_length": 74, "alphanum_fraction": 0.5301033854, "num_tokens": 1637, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.6599868992035561}} {"text": "module search_bisec_mod\n implicit none\n save\n\n contains\n subroutine search_bisec(v,x,lower,upper)\n! -------------------------------------------------------------\n! given value v; search an (**ascending order**) array x(n) \n! by bisection, returning the indices that bracket value v\n! -------------------------------------------------------------\n implicit none\n real*8, intent(in):: v, x(:)\n integer :: n,mid\n integer, intent(out)::lower,upper\n\n n=size(x)\n upper=n\n lower=1\n \n do while ((upper - lower) .gt. 1)\n mid= (upper + lower)/2\n if ( v .gt. x(mid)) then\n upper=upper\n lower=mid\n else\n upper=mid\n lower=lower\n endif\n enddo\n\n return\n end subroutine \n!***********************************************************************\nend module search_bisec_mod\n", "meta": {"hexsha": "fe0f54317c78895676c4dec2819a2bab7a9020ff", "size": 916, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uvc/search_bisec.f90", "max_stars_repo_name": "i-brnrd/code_underpinning_PhD_thesis", "max_stars_repo_head_hexsha": "b3b66f05b5a66246c449340d8d154b13003a95e6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "uvc/search_bisec.f90", "max_issues_repo_name": "i-brnrd/code_underpinning_PhD_thesis", "max_issues_repo_head_hexsha": "b3b66f05b5a66246c449340d8d154b13003a95e6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "uvc/search_bisec.f90", "max_forks_repo_name": "i-brnrd/code_underpinning_PhD_thesis", "max_forks_repo_head_hexsha": "b3b66f05b5a66246c449340d8d154b13003a95e6", "max_forks_repo_licenses": ["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.1714285714, "max_line_length": 72, "alphanum_fraction": 0.4257641921, "num_tokens": 201, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428946, "lm_q2_score": 0.8376199592797929, "lm_q1q2_score": 0.65998689600968}} {"text": "module ccm_numz\n! basic real types\n integer, parameter:: b8 = selected_real_kind(10)\ncontains\n function ccm_time()\n implicit none\n integer i\n integer :: ccm_start_time(8) = (/(-100,i=1,8)/)\n real(b8) :: ccm_time,tmp\n integer,parameter :: norm(13)=(/ & \n 0, 2678400, 5097600, 7776000,10368000,13046400,&\n 15638400,18316800,20995200,23587200,26265600,28857600,31536000/)\n integer,parameter :: leap(13)=(/ & \n 0, 2678400, 5184000, 7862400,10454400,13132800,&\n 15724800,18403200,21081600,23673600,26352000,28944000,31622400/)\n integer :: values(8),m,sec\n save\n call date_and_time(values=values)\n if(mod(values(1),4) .eq. 0)then\n m=leap(values(2))\n else\n m=norm(values(2))\n endif\n sec=((values(3)*24+values(5))*60+values(6))*60+values(7)\n tmp=real(m,b8)+real(sec,b8)+real(values(8),b8)/1000.0_b8\n !write(*,*)\"vals \",values\n if(values(1) .ne. ccm_start_time(1))then\n if(mod(ccm_start_time(1),4) .eq. 0)then\n tmp=tmp+real(leap(13),b8)\n else\n tmp=tmp+real(norm(13),b8)\n endif\n endif\n ccm_time=tmp\n end function\n\nsubroutine invert (matrix,size)\n\timplicit none\n\treal(b8) matrix(:,:)\n\tinteger size\n\tinteger switch,k, jj, kp1, i, j, l, krow, irow,nmax\n\tparameter (nmax=1000)\n\tdimension switch(nmax,2)\n\treal(b8) pivot,temp\n\tdo k = 1,size\n\t\tjj = k\n\t\tif (k .ne. size) then\n\t\t\tkp1 = k + 1\n\t\t\tpivot = (matrix(k, k))\n\t\t\tdo i = kp1,size\n\t\t\t\ttemp = (matrix(i, k))\n\t\t\t\tif ( abs(pivot) .lt. abs(temp)) then\n\t\t\t\t\tpivot = temp\n\t\t\t\t\tjj = i\n\t\t\t\tendif\n\t\t\tenddo\n\t\tendif\n\t\tswitch(k, 1) = k\n\t\tswitch(k, 2) = jj\n\t\tif (jj .ne. k) then\n\t\t\tdo j = 1 ,size \n\t\t\t\ttemp = matrix(jj, j)\n\t\t\t\tmatrix(jj, j) = matrix(k, j)\n\t\t\t\tmatrix(k, j) = temp\n\t\t\tenddo\n\t\tendif\n\t\tdo j = 1,size\n\t\t\tif (j .ne. k)matrix(k, j) = matrix(k, j) / matrix(k, k)\n\t\tenddo\n\t\tmatrix(k, k) = 1.0_b8 / matrix(k, k)\n\t\tdo i = 1,size\n\t\t\tif (i.ne.k) then\n\t\t\t\tdo j = 1,size\n\t\t\t\t\tif(j.ne.k)matrix(i,j)=matrix(i,j)-matrix(k,j)*matrix(i,k)\n\t\t\t\tenddo\n\t\t\tendif\n\t\tenddo\n\t\tdo i = 1, size\n\t\t\tif (i .ne. k)matrix(i, k) = -matrix(i, k) * matrix(k, k)\n\t\tenddo\n\tenddo \n\tdo l = 1,size\n\t\tk = size - l + 1\n\t\tkrow = switch(k, 1)\n\t\tirow = switch(k, 2)\n\t\tif (krow .ne. irow) then\n\t\t\tdo i = 1,size\n\t\t\t\ttemp = matrix(i, krow)\n\t\t\t\tmatrix(i, krow) = matrix(i, irow)\n\t\t\t\tmatrix(i, irow) = temp\n\t\t\tenddo\n\t\tendif\n\tenddo\nend subroutine\n\nsubroutine mset(m, n, in)\n\treal(b8) :: m(:,:)\n\tinteger n,in\n\tinteger i,j\n\tdo i=1,n\n\t\tdo j=1,n\n\t\t\tif( i .eq. j)then\n\t\t\t\tm(i,j)=in\n\t\t\telse\n\t\t\t\tm(i,j)=i+j\n\t\t\tendif\n\t\tenddo\n\tenddo\nend subroutine\n\nfunction mcheck(m, n, in)\n\treal(b8) :: m(:,:)\n\treal(b8) mcheck,x\n\tinteger n,in\n\tinteger i,j\n\tx=0\n\tdo i=1,n\n\t\tdo j=1,n\n\t\t\tif( i .eq. j)then\n\t\t\t\tx=x+abs(m(i,j)-in)\n\t\t\telse\n\t\t\t\tx=x+abs(m(i,J)-(i+j))\n\t\t\tendif\n\t\tenddo\n\tenddo\n\tmcheck=x\nend function\nend module ccm_numz\n\nprogram tover\n\tuse ccm_numz\n\treal(b8),allocatable :: m1(:,:),m2(:,:),m3(:,:),m4(:,:)\n\tinteger n\n\treal(b8) t0_start,t0_end\n real(b8) t1_start,t1_end,e1\n real(b8) t2_start,t2_end,e2\n real(b8) t3_start,t3_end,e3\n real(b8) t4_start,t4_end,e4\n real(b8) s1,t1\n\n\tn=750\n\te1=1\n\te2=1\n\te3=1\n\te4=1\n\tallocate(m1(n,n),m2(n,n),m3(n,n),m4(n,n))\n\tcall mset(m1,n,1)\n\tcall mset(m2,n,2)\n\tcall mset(m3,n,3)\n\tcall mset(m4,n,4)\n\tt0_start=ccm_time()\n!*** parallel is required lest it runs in serial mode\n!*** single is required lest you get 4 sets for each thread\n!$omp parallel\n!$omp single\n!$omp task \n\tt1_start=ccm_time()\n\ts1=t1_start\n\tcall invert(m1,n)\n\tcall invert(m1,n)\n\tt1_end=ccm_time()\n!\te1=mcheck(m1,n,1)\n\tt1_start=t1_start-t0_start\n\tt1=t1_start\n\tt1_end=t1_end-t0_start\n!$omp end task\n\n!$omp task\n\tt2_start=ccm_time()\n\tcall invert(m2,n)\n\tcall invert(m2,n)\n!$omp end task\t\n\tt2_end=ccm_time()\n!\te2=mcheck(m2,n,2)\n\tt2_start=t2_start-t0_start\n\tt2_end=t2_end-t0_start\n\n!$omp task\n\tt3_start=ccm_time()\n\tcall invert(m3,n)\n\tcall invert(m3,n)\n!$omp end task\n\tt3_end=ccm_time()\n!\te3=mcheck(m3,n,3)\n\tt3_start=t3_start-t0_start\n\tt3_end=t3_end-t0_start\n\n!$omp task\n\tt4_start=ccm_time()\n\tcall invert(m4,n)\n\tcall invert(m4,n)\n!$omp end task\n\tt4_end=ccm_time()\n!\te4=mcheck(m4,n,4)\n\tt4_start=t4_start-t0_start\n\tt4_end=t4_end-t0_start\n!$omp end single\n!$omp end parallel\n t0_end=ccm_time()\n t0_end=t0_end-t0_start\n write(*,1)1,t1_start,t1_end,e1\n write(*,1)2,t2_start,t2_end,e2\n write(*,1)3,t3_start,t3_end,e3\n write(*,1)4,t4_start,t4_end,e4\n write(*,2)t0_start,t0_end\n1 format(\"section \",i4,\" start time= \",f20.10,\" end time= \",g15.5,\" error=\",g15.5)\n2 format(\"taskwait\",4x,\" start time= \",f20.10,\" end time= \",g15.5)\n e1=mcheck(m1,n,1)\n e2=mcheck(m2,n,2)\n e3=mcheck(m3,n,3)\n e4=mcheck(m4,n,4)\n write(*,3)e1,e2,e3,e4\n3 format(\"final errors \",4(1x,g15.5))\n write(*,*)s1,t1\n end program\n\n\t\n", "meta": {"hexsha": "e7a93916214cf0c1bdbf69408a0c787ec1614a1c", "size": 4840, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "openmp/task.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": "openmp/task.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": "openmp/task.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": 22.2018348624, "max_line_length": 82, "alphanum_fraction": 0.6084710744, "num_tokens": 1915, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199552262967, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.6599868928158039}} {"text": "C * KDELF - Calculate the increment of the deformation gradient for\nC a given perturbation in (i,j), with epsilon\nC\nC * KPRINTER - Print out a matrix of any size\nC\nC * KMTMS - Multiply two matrices\nC\nC * KMATRIX2VECTOR - Convert a 3x3 matrix to a 6x1 vector\nC \nC * KDOTPROD - Dot product of two vectors\nC\nC------------------------------------------------------------ \n subroutine kdotprod(A, B, dotp, n)\n \n INCLUDE 'ABA_PARAM.INC'\n \n intent(in) :: A, B, n\n intent(out):: dotp \n \n dimension A(n), B(n)\n dotp = 0.0\n \n do i = 1,n\n dotp = dotp + A(i)*B(i)\n end do\n \n end subroutine kdotprod \nC \nC------------------------------------------------------- \nC\nC-------------------------------------------------------\nC \n subroutine kmatrix2vector(XMAT, VEC, NSHR)\n \n INCLUDE 'ABA_PARAM.INC'\n \n intent(in) :: XMAT, NSHR\n intent(out):: VEC\n \n dimension xmat(3,3), vec(6)\n \n do i=1,3\n vec(i) = xmat(i,i);\n end do\n \n vec(4) = xmat(1,2);\n \n IF (NSHR==3) then\n vec(5) = xmat(1,3);\n vec(6) = xmat(2,3);\n END IF\n \n end subroutine kmatrix2vector \nC\nC------------------------------------------------------- \nC\nC-------------------------------------------------------\nC \n SUBROUTINE KMTMS (M, N, L, A, KA, B, KB, C, KC)\n \n INCLUDE 'ABA_PARAM.INC'\nC \n intent(in) :: M, N, L, A, KA, B, KB, KC\n intent(out):: C \nC \nC\nC PRODUCT OF REAL MATRICES\nC\n DIMENSION A(KA,N), B(KB,L), C(KC,L)\n DOUBLE PRECISION W\nC \nC\n DO 30 J = 1,L\n DO 20 I = 1,M\n W = 0.D0\n DO 10 K = 1,N\n W = W + A(I,K) * B(K,J)\n 10 CONTINUE\n C(I,J) = W\n 20 CONTINUE\n 30 CONTINUE\n RETURN\n END SUBROUTINE KMTMS \nC\nC------------------------------------------------------- \nC\nC-------------------------------------------------------\nC \n subroutine kprinter(tens, m, n)\n \n INCLUDE 'ABA_PARAM.INC'\n \n intent(in):: tens, m, n \n \n dimension tens(m,n)\n \n write(6,*)\n do i = 1,m\n do j = 1,n\n write(6,'(e19.9)',advance='no'),tens(i,j)\n end do\n write(6,*)\n end do\n write(6,*)\n return\n end subroutine kprinter \nC\nC------------------------------------------------------- \nC\nC-------------------------------------------------------\nC \n subroutine kdelF(m, n, DGRAD, eps, DF)\n \n INCLUDE 'ABA_PARAM.INC'\n \n intent (in) :: DGRAD, eps, m, n\n intent (out):: DF \n \nC Input: the index's i & j; The current deformation gradient (DGRAD). The perturbation\nC increment (eps)\nC\nC Output: The perturbed increment DF\nC\n dimension dyad1(3,3), dyad2(3,3), DGRAD(3,3), DF(3,3), DFp1(3,3)\n \nc Zero the dyad matrices\nc\n do i = 1,3\n do j = 1,3\n dyad1(i,j) = zero\n dyad2(i,j) = zero\n end do\n end do\n \nc Place the 1's in the correct location \n dyad1(m,n) = 1.0;\nc\n dyad2(n,m) = 1.0;\nc \nc KMTMS (M, N, L, A, KA, B, KB, C, KC) \n call KMTMS(3, 3, 3, dyad1, 3, DGRAD, 3, DFp1, 3)\n DF = DFp1\n \n \n call KMTMS(3, 3, 3, dyad2, 3, DGRAD, 3, DFp1, 3)\n DF = DF + DFp1\n \n \n DF = 0.5*DF*eps \n \n end subroutine kdelF \nC\nC------------------------------------------------------- \nC\nC-------------------------------------------------------\nC ", "meta": {"hexsha": "85fee9974659250b324915263867a73ee50d98b6", "size": 3772, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Lesson C - fibre reinforced anistropic models/Abaqus/utilities.f", "max_stars_repo_name": "vicky-9993/localBasisAbaqus", "max_stars_repo_head_hexsha": "d988ec4403a46923142f6599021aab7d1b233ce6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-04-02T00:11:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-16T15:36:44.000Z", "max_issues_repo_path": "Lesson C - fibre reinforced anistropic models/Abaqus/utilities.f", "max_issues_repo_name": "vicky-9993/localBasisAbaqus", "max_issues_repo_head_hexsha": "d988ec4403a46923142f6599021aab7d1b233ce6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Lesson C - fibre reinforced anistropic models/Abaqus/utilities.f", "max_forks_repo_name": "vicky-9993/localBasisAbaqus", "max_forks_repo_head_hexsha": "d988ec4403a46923142f6599021aab7d1b233ce6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-03-20T08:30:59.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-16T03:56:11.000Z", "avg_line_length": 24.1794871795, "max_line_length": 86, "alphanum_fraction": 0.3780487805, "num_tokens": 1080, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.851952809486198, "lm_q2_score": 0.7745833841649232, "lm_q1q2_score": 0.6599084903206334}} {"text": " SUBROUTINE cdfnbn(which,p,q,s,xn,pr,ompr,status,bound)\nC**********************************************************************\nC\nC SUBROUTINE CDFNBN ( WHICH, P,Q, S, XN, PR, STATUS, BOUND )\nC Cumulative Distribution Function\nC Negative BiNomial distribution\nC\nC\nC Function\nC\nC\nC Calculates any one parameter of the negative binomial\nC distribution given values for the others.\nC\nC The cumulative negative binomial distribution returns the\nC probability that there will be F or fewer failures before the\nC XNth success in binomial trials each of which has probability of\nC success PR.\nC\nC The individual term of the negative binomial is the probability of\nC S failures before XN successes and is\nC Choose( S, XN+S-1 ) * PR^(XN) * (1-PR)^S\nC\nC\nC Arguments\nC\nC\nC WHICH --> Integer indicating which of the next four argument\nC values is to be calculated from the others.\nC Legal range: 1..4\nC iwhich = 1 : Calculate P and Q from S,XN,PR and OMPR\nC iwhich = 2 : Calculate S from P,Q,XN,PR and OMPR\nC iwhich = 3 : Calculate XN from P,Q,S,PR and OMPR\nC iwhich = 4 : Calculate PR and OMPR from P,Q,S and XN\nC INTEGER WHICH\nC\nC P <--> The cumulation from 0 to S of the negative\nC binomial distribution.\nC Input range: [0,1].\nC DOUBLE PRECISION P\nC\nC Q <--> 1-P.\nC Input range: (0, 1].\nC P + Q = 1.0.\nC DOUBLE PRECISION Q\nC\nC S <--> The upper limit of cumulation of the binomial distribution.\nC There are F or fewer failures before the XNth success.\nC Input range: [0, +infinity).\nC Search range: [0, 1E300]\nC DOUBLE PRECISION S\nC\nC XN <--> The number of successes.\nC Input range: [0, +infinity).\nC Search range: [0, 1E300]\nC DOUBLE PRECISION XN\nC\nC PR <--> The probability of success in each binomial trial.\nC Input range: [0,1].\nC Search range: [0,1].\nC DOUBLE PRECISION PR\nC\nC OMPR <--> 1-PR\nC Input range: [0,1].\nC Search range: [0,1]\nC PR + OMPR = 1.0\nC DOUBLE PRECISION OMPR\nC\nC STATUS <-- 0 if calculation completed correctly\nC -I if input parameter number I is out of range\nC 1 if answer appears to be lower than lowest\nC search bound\nC 2 if answer appears to be higher than greatest\nC search bound\nC 3 if P + Q .ne. 1\nC 4 if PR + OMPR .ne. 1\nC INTEGER STATUS\nC\nC BOUND <-- Undefined if STATUS is 0\nC\nC Bound exceeded by parameter number I if STATUS\nC is negative.\nC\nC Lower search bound if STATUS is 1.\nC\nC Upper search bound if STATUS is 2.\nC\nC\nC Method\nC\nC\nC Formula 26.5.26 of Abramowitz and Stegun, Handbook of\nC Mathematical Functions (1966) is used to reduce calculation of\nC the cumulative distribution function to that of an incomplete\nC beta.\nC\nC Computation of other parameters involve a seach for a value that\nC produces the desired value of P. The search relies on the\nC monotinicity of P with the other parameter.\nC\nC\nC**********************************************************************\nC .. Parameters ..\n DOUBLE PRECISION tol\n PARAMETER (tol=1.0D-13)\n DOUBLE PRECISION atol\n PARAMETER (atol=1.0D-50)\n DOUBLE PRECISION inf\n PARAMETER (inf=1.0D300)\n DOUBLE PRECISION one\n PARAMETER (one=1.0D0)\nC ..\nC .. Scalar Arguments ..\n DOUBLE PRECISION bound,p,q,pr,ompr,s,xn\n INTEGER status,which\nC ..\nC .. Local Scalars ..\n DOUBLE PRECISION fx,xhi,xlo,pq,prompr,cum,ccum\n LOGICAL qhi,qleft,qporq\nC ..\nC .. External Functions ..\n DOUBLE PRECISION spmpar\n EXTERNAL spmpar\nC ..\nC .. External Subroutines ..\n EXTERNAL dinvr,dstinv,dstzr,dzror,cumnbn\nC ..\nC .. Executable Statements ..\nC\nC Check arguments\nC\n IF (.NOT. ((which.LT.1).OR. (which.GT.4))) GO TO 30\n IF (.NOT. (which.LT.1)) GO TO 10\n bound = 1.0D0\n GO TO 20\n\n 10 bound = 4.0D0\n 20 status = -1\n RETURN\n\n 30 IF (which.EQ.1) GO TO 70\nC\nC P\nC\n IF (.NOT. ((p.LT.0.0D0).OR. (p.GT.1.0D0))) GO TO 60\n IF (.NOT. (p.LT.0.0D0)) GO TO 40\n bound = 0.0D0\n GO TO 50\n\n 40 bound = 1.0D0\n 50 status = -2\n RETURN\n\n 60 CONTINUE\n 70 IF (which.EQ.1) GO TO 110\nC\nC Q\nC\n IF (.NOT. ((q.LE.0.0D0).OR. (q.GT.1.0D0))) GO TO 100\n IF (.NOT. (q.LE.0.0D0)) GO TO 80\n bound = 0.0D0\n GO TO 90\n\n 80 bound = 1.0D0\n 90 status = -3\n RETURN\n\n 100 CONTINUE\n 110 IF (which.EQ.2) GO TO 130\nC\nC S\nC\n IF (.NOT. (s.LT.0.0D0)) GO TO 120\n bound = 0.0D0\n status = -4\n RETURN\n\n 120 CONTINUE\n 130 IF (which.EQ.3) GO TO 150\nC\nC XN\nC\n IF (.NOT. (xn.LT.0.0D0)) GO TO 140\n bound = 0.0D0\n status = -5\n RETURN\n\n 140 CONTINUE\n 150 IF (which.EQ.4) GO TO 190\nC\nC PR\nC\n IF (.NOT. ((pr.LT.0.0D0).OR. (pr.GT.1.0D0))) GO TO 180\n IF (.NOT. (pr.LT.0.0D0)) GO TO 160\n bound = 0.0D0\n GO TO 170\n\n 160 bound = 1.0D0\n 170 status = -6\n RETURN\n\n 180 CONTINUE\n 190 IF (which.EQ.4) GO TO 230\nC\nC OMPR\nC\n IF (.NOT. ((ompr.LT.0.0D0).OR. (ompr.GT.1.0D0))) GO TO 220\n IF (.NOT. (ompr.LT.0.0D0)) GO TO 200\n bound = 0.0D0\n GO TO 210\n\n 200 bound = 1.0D0\n 210 status = -7\n RETURN\n\n 220 CONTINUE\n 230 IF (which.EQ.1) GO TO 270\nC\nC P + Q\nC\n pq = p + q\n IF (.NOT. (abs(((pq)-0.5D0)-0.5D0).GT.\n + (3.0D0*spmpar(1)))) GO TO 260\n IF (.NOT. (pq.LT.0.0D0)) GO TO 240\n bound = 0.0D0\n GO TO 250\n\n 240 bound = 1.0D0\n 250 status = 3\n RETURN\n\n 260 CONTINUE\n 270 IF (which.EQ.4) GO TO 310\nC\nC PR + OMPR\nC\n prompr = pr + ompr\n IF (.NOT. (abs(((prompr)-0.5D0)-0.5D0).GT.\n + (3.0D0*spmpar(1)))) GO TO 300\n IF (.NOT. (prompr.LT.0.0D0)) GO TO 280\n bound = 0.0D0\n GO TO 290\n\n 280 bound = 1.0D0\n 290 status = 4\n RETURN\n\n 300 CONTINUE\n 310 IF (.NOT. (which.EQ.1)) qporq = p .LE. q\nC\nC Select the minimum of P or Q\nC\nC\nC Calculate ANSWERS\nC\n IF ((1).EQ. (which)) THEN\nC\nC Calculating P\nC\n CALL cumnbn(s,xn,pr,ompr,p,q)\n status = 0\n\n ELSE IF ((2).EQ. (which)) THEN\nC\nC Calculating S\nC\n s = 5.0D0\n CALL dstinv(0.0D0,inf,0.5D0,0.5D0,5.0D0,atol,tol)\n status = 0\n CALL dinvr(status,s,fx,qleft,qhi)\n 320 IF (.NOT. (status.EQ.1)) GO TO 350\n CALL cumnbn(s,xn,pr,ompr,cum,ccum)\n IF (.NOT. (qporq)) GO TO 330\n fx = cum - p\n GO TO 340\n\n 330 fx = ccum - q\n 340 CALL dinvr(status,s,fx,qleft,qhi)\n GO TO 320\n\n 350 IF (.NOT. (status.EQ.-1)) GO TO 380\n IF (.NOT. (qleft)) GO TO 360\n status = 1\n bound = 0.0D0\n GO TO 370\n\n 360 status = 2\n bound = inf\n 370 CONTINUE\n 380 CONTINUE\n\n ELSE IF ((3).EQ. (which)) THEN\nC\nC Calculating XN\nC\n xn = 5.0D0\n CALL dstinv(0.0D0,inf,0.5D0,0.5D0,5.0D0,atol,tol)\n status = 0\n CALL dinvr(status,xn,fx,qleft,qhi)\n 390 IF (.NOT. (status.EQ.1)) GO TO 420\n CALL cumnbn(s,xn,pr,ompr,cum,ccum)\n IF (.NOT. (qporq)) GO TO 400\n fx = cum - p\n GO TO 410\n\n 400 fx = ccum - q\n 410 CALL dinvr(status,xn,fx,qleft,qhi)\n GO TO 390\n\n 420 IF (.NOT. (status.EQ.-1)) GO TO 450\n IF (.NOT. (qleft)) GO TO 430\n status = 1\n bound = 0.0D0\n GO TO 440\n\n 430 status = 2\n bound = inf\n 440 CONTINUE\n 450 CONTINUE\n\n ELSE IF ((4).EQ. (which)) THEN\nC\nC Calculating PR and OMPR\nC\n CALL dstzr(0.0D0,1.0D0,atol,tol)\n IF (.NOT. (qporq)) GO TO 480\n status = 0\n CALL dzror(status,pr,fx,xlo,xhi,qleft,qhi)\n ompr = one - pr\n 460 IF (.NOT. (status.EQ.1)) GO TO 470\n CALL cumnbn(s,xn,pr,ompr,cum,ccum)\n fx = cum - p\n CALL dzror(status,pr,fx,xlo,xhi,qleft,qhi)\n ompr = one - pr\n GO TO 460\n\n 470 GO TO 510\n\n 480 status = 0\n CALL dzror(status,ompr,fx,xlo,xhi,qleft,qhi)\n pr = one - ompr\n 490 IF (.NOT. (status.EQ.1)) GO TO 500\n CALL cumnbn(s,xn,pr,ompr,cum,ccum)\n fx = ccum - q\n CALL dzror(status,ompr,fx,xlo,xhi,qleft,qhi)\n pr = one - ompr\n GO TO 490\n\n 500 CONTINUE\n 510 IF (.NOT. (status.EQ.-1)) GO TO 540\n IF (.NOT. (qleft)) GO TO 520\n status = 1\n bound = 0.0D0\n GO TO 530\n\n 520 status = 2\n bound = 1.0D0\n 530 CONTINUE\n 540 END IF\n\n RETURN\n\n END\n", "meta": {"hexsha": "2dd86ac9b51e4add680fad4835d030f35458879c", "size": 9178, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/rnd/cdfnbn.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/cdfnbn.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/cdfnbn.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": 25.2142857143, "max_line_length": 72, "alphanum_fraction": 0.5225539333, "num_tokens": 3217, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527944504227, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.6599084875406209}} {"text": "*DECK CGECO\n SUBROUTINE CGECO (A, LDA, N, IPVT, RCOND, Z)\nC***BEGIN PROLOGUE CGECO\nC***PURPOSE Factor a matrix using Gaussian elimination and estimate\nC the condition number of the matrix.\nC***LIBRARY SLATEC (LINPACK)\nC***CATEGORY D2C1\nC***TYPE COMPLEX (SGECO-S, DGECO-D, CGECO-C)\nC***KEYWORDS CONDITION NUMBER, GENERAL MATRIX, LINEAR ALGEBRA, LINPACK,\nC MATRIX FACTORIZATION\nC***AUTHOR Moler, C. B., (U. of New Mexico)\nC***DESCRIPTION\nC\nC CGECO factors a complex matrix by Gaussian elimination\nC and estimates the condition of the matrix.\nC\nC If RCOND is not needed, CGEFA is slightly faster.\nC To solve A*X = B , follow CGECO By CGESL.\nC To Compute INVERSE(A)*C , follow CGECO by CGESL.\nC To compute DETERMINANT(A) , follow CGECO by CGEDI.\nC To compute INVERSE(A) , follow CGECO by CGEDI.\nC\nC On Entry\nC\nC A COMPLEX(LDA, N)\nC the matrix to be factored.\nC\nC LDA INTEGER\nC the leading dimension of the array A .\nC\nC N INTEGER\nC the order of the matrix A .\nC\nC On Return\nC\nC A an upper triangular matrix and the multipliers\nC which were used to obtain it.\nC The factorization can be written A = L*U where\nC L is a product of permutation and unit lower\nC triangular matrices and U is upper triangular.\nC\nC IPVT INTEGER(N)\nC an integer vector of pivot indices.\nC\nC RCOND REAL\nC an estimate of the reciprocal condition of A .\nC For the system A*X = B , relative perturbations\nC in A and B of size EPSILON may cause\nC relative perturbations in X of size EPSILON/RCOND .\nC If RCOND is so small that the logical expression\nC 1.0 + RCOND .EQ. 1.0\nC is true, then A may be singular to working\nC precision. In particular, RCOND is zero if\nC exact singularity is detected or the estimate\nC underflows.\nC\nC Z COMPLEX(N)\nC a work vector whose contents are usually unimportant.\nC If A is close to a singular matrix, then Z is\nC an approximate null vector in the sense that\nC NORM(A*Z) = RCOND*NORM(A)*NORM(Z) .\nC\nC***REFERENCES J. J. Dongarra, J. R. Bunch, C. B. Moler, and G. W.\nC Stewart, LINPACK Users' Guide, SIAM, 1979.\nC***ROUTINES CALLED CAXPY, CDOTC, CGEFA, CSSCAL, SCASUM\nC***REVISION HISTORY (YYMMDD)\nC 780814 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890831 Modified array declarations. (WRB)\nC 890831 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900326 Removed duplicate information from DESCRIPTION section.\nC (WRB)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE CGECO\n INTEGER LDA,N,IPVT(*)\n COMPLEX A(LDA,*),Z(*)\n REAL RCOND\nC\n COMPLEX CDOTC,EK,T,WK,WKM\n REAL ANORM,S,SCASUM,SM,YNORM\n INTEGER INFO,J,K,KB,KP1,L\n COMPLEX ZDUM,ZDUM1,ZDUM2,CSIGN1\n REAL CABS1\n CABS1(ZDUM) = ABS(REAL(ZDUM)) + ABS(AIMAG(ZDUM))\n CSIGN1(ZDUM1,ZDUM2) = CABS1(ZDUM1)*(ZDUM2/CABS1(ZDUM2))\nC\nC COMPUTE 1-NORM OF A\nC\nC***FIRST EXECUTABLE STATEMENT CGECO\n ANORM = 0.0E0\n DO 10 J = 1, N\n ANORM = MAX(ANORM,SCASUM(N,A(1,J),1))\n 10 CONTINUE\nC\nC FACTOR\nC\n CALL CGEFA(A,LDA,N,IPVT,INFO)\nC\nC RCOND = 1/(NORM(A)*(ESTIMATE OF NORM(INVERSE(A)))) .\nC ESTIMATE = NORM(Z)/NORM(Y) WHERE A*Z = Y AND CTRANS(A)*Y = E .\nC CTRANS(A) IS THE CONJUGATE TRANSPOSE OF A .\nC THE COMPONENTS OF E ARE CHOSEN TO CAUSE MAXIMUM LOCAL\nC GROWTH IN THE ELEMENTS OF W WHERE CTRANS(U)*W = E .\nC THE VECTORS ARE FREQUENTLY RESCALED TO AVOID OVERFLOW.\nC\nC SOLVE CTRANS(U)*W = E\nC\n EK = (1.0E0,0.0E0)\n DO 20 J = 1, N\n Z(J) = (0.0E0,0.0E0)\n 20 CONTINUE\n DO 100 K = 1, N\n IF (CABS1(Z(K)) .NE. 0.0E0) EK = CSIGN1(EK,-Z(K))\n IF (CABS1(EK-Z(K)) .LE. CABS1(A(K,K))) GO TO 30\n S = CABS1(A(K,K))/CABS1(EK-Z(K))\n CALL CSSCAL(N,S,Z,1)\n EK = CMPLX(S,0.0E0)*EK\n 30 CONTINUE\n WK = EK - Z(K)\n WKM = -EK - Z(K)\n S = CABS1(WK)\n SM = CABS1(WKM)\n IF (CABS1(A(K,K)) .EQ. 0.0E0) GO TO 40\n WK = WK/CONJG(A(K,K))\n WKM = WKM/CONJG(A(K,K))\n GO TO 50\n 40 CONTINUE\n WK = (1.0E0,0.0E0)\n WKM = (1.0E0,0.0E0)\n 50 CONTINUE\n KP1 = K + 1\n IF (KP1 .GT. N) GO TO 90\n DO 60 J = KP1, N\n SM = SM + CABS1(Z(J)+WKM*CONJG(A(K,J)))\n Z(J) = Z(J) + WK*CONJG(A(K,J))\n S = S + CABS1(Z(J))\n 60 CONTINUE\n IF (S .GE. SM) GO TO 80\n T = WKM - WK\n WK = WKM\n DO 70 J = KP1, N\n Z(J) = Z(J) + T*CONJG(A(K,J))\n 70 CONTINUE\n 80 CONTINUE\n 90 CONTINUE\n Z(K) = WK\n 100 CONTINUE\n S = 1.0E0/SCASUM(N,Z,1)\n CALL CSSCAL(N,S,Z,1)\nC\nC SOLVE CTRANS(L)*Y = W\nC\n DO 120 KB = 1, N\n K = N + 1 - KB\n IF (K .LT. N) Z(K) = Z(K) + CDOTC(N-K,A(K+1,K),1,Z(K+1),1)\n IF (CABS1(Z(K)) .LE. 1.0E0) GO TO 110\n S = 1.0E0/CABS1(Z(K))\n CALL CSSCAL(N,S,Z,1)\n 110 CONTINUE\n L = IPVT(K)\n T = Z(L)\n Z(L) = Z(K)\n Z(K) = T\n 120 CONTINUE\n S = 1.0E0/SCASUM(N,Z,1)\n CALL CSSCAL(N,S,Z,1)\nC\n YNORM = 1.0E0\nC\nC SOLVE L*V = Y\nC\n DO 140 K = 1, N\n L = IPVT(K)\n T = Z(L)\n Z(L) = Z(K)\n Z(K) = T\n IF (K .LT. N) CALL CAXPY(N-K,T,A(K+1,K),1,Z(K+1),1)\n IF (CABS1(Z(K)) .LE. 1.0E0) GO TO 130\n S = 1.0E0/CABS1(Z(K))\n CALL CSSCAL(N,S,Z,1)\n YNORM = S*YNORM\n 130 CONTINUE\n 140 CONTINUE\n S = 1.0E0/SCASUM(N,Z,1)\n CALL CSSCAL(N,S,Z,1)\n YNORM = S*YNORM\nC\nC SOLVE U*Z = V\nC\n DO 160 KB = 1, N\n K = N + 1 - KB\n IF (CABS1(Z(K)) .LE. CABS1(A(K,K))) GO TO 150\n S = CABS1(A(K,K))/CABS1(Z(K))\n CALL CSSCAL(N,S,Z,1)\n YNORM = S*YNORM\n 150 CONTINUE\n IF (CABS1(A(K,K)) .NE. 0.0E0) Z(K) = Z(K)/A(K,K)\n IF (CABS1(A(K,K)) .EQ. 0.0E0) Z(K) = (1.0E0,0.0E0)\n T = -Z(K)\n CALL CAXPY(K-1,T,A(1,K),1,Z(1),1)\n 160 CONTINUE\nC MAKE ZNORM = 1.0\n S = 1.0E0/SCASUM(N,Z,1)\n CALL CSSCAL(N,S,Z,1)\n YNORM = S*YNORM\nC\n IF (ANORM .NE. 0.0E0) RCOND = YNORM/ANORM\n IF (ANORM .EQ. 0.0E0) RCOND = 0.0E0\n RETURN\n END\n", "meta": {"hexsha": "7da7dadc8e3cedfe14f28e91ce2650c1b5282c85", "size": 6831, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/cgeco.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/cgeco.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/cgeco.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.2216981132, "max_line_length": 72, "alphanum_fraction": 0.5259844825, "num_tokens": 2517, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527982093666, "lm_q2_score": 0.774583389368527, "lm_q1q2_score": 0.659908486019012}} {"text": "program tarefaa\n print *, \"Digite o valor inteiro de N:\"\n read (*,*) N\n \n ! N\u00famero de \"Andarilhos\" M \n M = 1000\n \n ! loop do passo\n do i = 1, N\n ! zera a soma\n soma = 0e0 \n \n ! loop do andarilho\n do j = 1, M\n ! soma os passos de cada andarilho\n soma = soma + rand()**i\n end do\n \n ! Escreve a media no terminal\n write (*,'(A,I0,A,1F5.3)') \": \", soma/M\n end do\n\nend program tarefaa\n", "meta": {"hexsha": "2c438594106da63b7e4beac62887861bf9268241", "size": 500, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "projeto-2/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-2/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-2/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": 20.8333333333, "max_line_length": 56, "alphanum_fraction": 0.464, "num_tokens": 169, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774768002981829, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6598735918836106}} {"text": "MODULE date_sub\r\n\r\n! COLLECTED AND PUT TOGETHER JANUARY 1972, H. D. KNOBLE .\r\n! ORIGINAL REFERENCES ARE CITED IN EACH ROUTINE.\r\n\r\n! Code converted using TO_F90 by Alan Miller\r\n! Date: 1999-12-22 Time: 10:23:47\r\n\r\nIMPLICIT NONE\r\n\r\nCONTAINS\r\n\r\n! ARITHMETIC FUNCTIONS 'IZLR' AND 'IDAY' ARE TAKEN FROM REMARK ON\r\n! ALGORITHM 398, BY J. DOUGLAS ROBERTSON, CACM 15(10):918.\r\n\r\nFUNCTION iday(yyyy, mm, dd) RESULT(ival)\r\n!------IDAY IS A COMPANION TO CALEND; GIVEN A CALENDAR DATE, YYYY, MM,\r\n! DD, IDAY IS RETURNED AS THE DAY OF THE YEAR.\r\n! EXAMPLE: IDAY(1984, 4, 22) = 113\r\n\r\nINTEGER, INTENT(IN) :: yyyy, mm, dd\r\nINTEGER :: ival\r\n\r\nival = 3055*(mm+2)/100 - (mm+10)/13*2 -91 + (1-(MOD(yyyy, 4)+3)/4 + &\r\n (MOD(yyyy, 100) + 99)/100 - (MOD(yyyy, 400)+399)/400)*(mm+10)/13 + dd\r\n\r\nRETURN\r\nEND FUNCTION iday\r\n\r\n\r\nFUNCTION izlr(yyyy, mm, dd) RESULT(ival)\r\n!------IZLR(YYYY, MM, DD) GIVES THE WEEKDAY NUMBER 0 = SUNDAY, 1 = MONDAY,\r\n! ... 6 = SATURDAY. EXAMPLE: IZLR(1970, 1, 1) = 4 = THURSDAY\r\n\r\nINTEGER, INTENT(IN) :: yyyy, mm, dd\r\nINTEGER :: ival\r\n\r\nival = MOD((13*(mm+10-(mm+10)/13*12)-1)/5 + dd + 77 + 5*(yyyy+(mm-14)/12 - &\r\n (yyyy+(mm-14)/12)/100*100)/4 + (yyyy+(mm-14)/12)/400 - &\r\n (yyyy+(mm-14)/12)/100*2, 7)\r\n\r\nRETURN\r\nEND FUNCTION izlr\r\n\r\n\r\nSUBROUTINE calend(yyyy, ddd, mm, dd)\r\n!=============CALEND WHEN GIVEN A VALID YEAR, YYYY, AND DAY OF THE YEAR, DDD,\r\n! RETURNS THE MONTH, MM, AND DAY OF THE MONTH, DD.\r\n! SEE ACM ALGORITHM 398, TABLELESS DATE CONVERSION, BY\r\n! DICK STONE, CACM 13(10):621.\r\n\r\nINTEGER, INTENT(IN) :: yyyy\r\nINTEGER, INTENT(IN) :: ddd\r\nINTEGER, INTENT(OUT) :: mm\r\nINTEGER, INTENT(OUT) :: dd\r\n\r\nINTEGER :: t\r\n\r\nt = 0\r\nIF(MOD(yyyy, 4) == 0) t = 1\r\n\r\n!-----------THE FOLLOWING STATEMENT IS NECESSARY IF YYYY IS < 1900 OR > 2100.\r\nIF(MOD(yyyy, 400) /= 0 .AND. MOD(yyyy, 100) == 0) t = 0\r\n\r\ndd = ddd\r\nIF(ddd > 59+t) dd = dd + 2 - t\r\nmm = ((dd+91)*100)/3055\r\ndd = (dd+91) - (mm*3055)/100\r\nmm = mm - 2\r\n!----------MM WILL BE CORRECT IFF DDD IS CORRECT FOR YYYY.\r\nIF(mm >= 1 .AND. mm <= 12) RETURN\r\nWRITE(*,1) ddd\r\n1 FORMAT('0$$$CALEND: DAY OF THE YEAR INPUT =', i11, ' IS OUT OF RANGE.')\r\n\r\nSTOP\r\nEND SUBROUTINE calend\r\n\r\n\r\nSUBROUTINE cdate(jd, yyyy, mm, dd)\r\n!=======GIVEN A JULIAN DAY NUMBER, NNNNNNNN, YYYY,MM,DD ARE RETURNED AS THE\r\n! CALENDAR DATE. JD = NNNNNNNN IS THE JULIAN DATE FROM AN EPOCH\r\n! IN THE VERY DISTANT PAST. SEE CACM 1968 11(10):657,\r\n! LETTER TO THE EDITOR BY FLIEGEL AND VAN FLANDERN.\r\n! EXAMPLE CALL CDATE(2440588, YYYY, MM, DD) RETURNS 1970 1 1 .\r\n\r\nINTEGER, INTENT(IN) :: jd\r\nINTEGER, INTENT(OUT) :: yyyy\r\nINTEGER, INTENT(OUT) :: mm\r\nINTEGER, INTENT(OUT) :: dd\r\n\r\nINTEGER :: l, n\r\n\r\nl = jd + 68569\r\nn = 4*l/146097\r\nl = l - (146097*n + 3)/4\r\nyyyy = 4000*(l+1)/1461001\r\nl = l - 1461*yyyy/4 + 31\r\nmm = 80*l/2447\r\ndd = l - 2447*mm/80\r\nl = mm/11\r\nmm = mm + 2 - 12*l\r\nyyyy = 100*(n-49) + yyyy + l\r\nRETURN\r\nEND SUBROUTINE cdate\r\n\r\n\r\nSUBROUTINE daysub(jd, yyyy, mm, dd, wd, ddd)\r\n!========GIVEN JD, A JULIAN DAY # (SEE ASF JD), THIS ROUTINE CALCULATES DD,\r\n! THE DAY NUMBER OF THE MONTH; MM, THE MONTH NUMBER; YYYY THE YEAR;\r\n! WD THE WEEKDAY NUMBER, AND DDD THE DAY NUMBER OF THE YEAR.\r\n\r\n! EXAMPLE: CALL DAYSUB(2440588, YYYY, MM, DD, WD, DDD) YIELDS 1970 1 1 4 1.\r\n\r\nINTEGER, INTENT(IN) :: jd\r\nINTEGER, INTENT(OUT) :: yyyy\r\nINTEGER, INTENT(OUT) :: mm\r\nINTEGER, INTENT(OUT) :: dd\r\nINTEGER, INTENT(OUT) :: wd\r\nINTEGER, INTENT(OUT) :: ddd\r\n\r\nCALL cdate(jd, yyyy, mm, dd)\r\nwd = izlr(yyyy, mm, dd)\r\nddd = iday(yyyy, mm, dd)\r\n\r\nRETURN\r\nEND SUBROUTINE daysub\r\n\r\n\r\nFUNCTION jd(yyyy, mm, dd) RESULT(ival)\r\n\r\nINTEGER, INTENT(IN) :: yyyy\r\nINTEGER, INTENT(IN) :: mm\r\nINTEGER, INTENT(IN) :: dd\r\nINTEGER :: ival\r\n\r\n! DATE ROUTINE JD(YYYY, MM, DD) CONVERTS CALENDER DATE TO\r\n! JULIAN DATE. SEE CACM 1968 11(10):657, LETTER TO THE\r\n! EDITOR BY HENRY F. FLIEGEL AND THOMAS C. VAN FLANDERN.\r\n! EXAMPLE JD(1970, 1, 1) = 2440588\r\n\r\nival = dd - 32075 + 1461*(yyyy+4800+(mm-14)/12)/4 + &\r\n 367*(mm-2-((mm-14)/12)*12)/12 - 3*((yyyy+4900+(mm-14)/12)/100)/4\r\n\r\nRETURN\r\nEND FUNCTION jd\r\n\r\n\r\nFUNCTION ndays(mm1, dd1, yyyy1, mm2, dd2, yyyy2) RESULT(ival)\r\n\r\nINTEGER, INTENT(IN) :: mm1\r\nINTEGER, INTENT(IN) :: dd1\r\nINTEGER, INTENT(IN) :: yyyy1\r\nINTEGER, INTENT(IN) :: mm2\r\nINTEGER, INTENT(IN) :: dd2\r\nINTEGER, INTENT(IN) :: yyyy2\r\nINTEGER :: ival\r\n\r\n!==============NDAYS IS RETURNED AS THE NUMBER OF DAYS BETWEEN TWO\r\n! DATES; THAT IS MM1/DD1/YYYY1 MINUS MM2/DD2/YYYY2,\r\n! WHERE DATEI AND DATEJ HAVE ELEMENTS MM, DD, YYYY.\r\n!-------NDAYS WILL BE POSITIVE IFF DATE1 IS MORE RECENT THAN DATE2.\r\n\r\nival = jd(yyyy1, mm1, dd1) - jd(yyyy2, mm2, dd2)\r\n\r\nRETURN\r\nEND FUNCTION ndays\r\n\r\n\r\nSUBROUTINE date_stamp( string, want_day, short )\r\nCHARACTER (LEN=*), INTENT(OUT) :: string\r\nLOGICAL, INTENT(IN), OPTIONAL :: want_day, short\r\n\r\n! Returns the current date as a character string\r\n! e.g.\r\n! want_day short string\r\n! .TRUE. .TRUE. Thursday, 23 Dec 1999\r\n! .TRUE. .FALSE. Thursday, 23 December 1999 <- default\r\n! .FALSE. .TRUE. 23 Dec 1999\r\n! .FALSE. .FALSE. 23 December 1999\r\n\r\nINTEGER :: val(8), pos\r\nLOGICAL :: want_d, sh\r\nCHARACTER (LEN=9) :: day(0:6) = (/ 'Sunday ', 'Monday ', 'Tuesday ', &\r\n 'Wednesday', 'Thursday ', 'Friday ', 'Saturday ' /)\r\nCHARACTER (LEN=9) :: month(1:12) = (/ 'January ', 'February ', 'March ', &\r\n 'April ', 'May ', 'June ', 'July ', &\r\n 'August ', 'September', 'October ', 'November ', &\r\n 'December ' /)\r\n\r\nwant_d = .TRUE.\r\nIF (PRESENT(want_day)) want_d = want_day\r\nsh = .FALSE.\r\nIF (PRESENT(short)) sh = short\r\n\r\nCALL DATE_AND_TIME(VALUES=val)\r\n\r\nIF (want_d) THEN\r\n pos = izlr(val(1), val(2), val(3))\r\n string = TRIM( day(pos) ) // ','\r\n pos = LEN_TRIM( string ) + 2\r\nELSE\r\n pos = 1\r\n string = ' '\r\nEND IF\r\n\r\nWRITE(string(pos:pos+1), '(i2)') val(3)\r\nIF (sh) THEN\r\n string(pos+3:pos+5) = month(val(2))(1:3)\r\n pos = pos + 7\r\nELSE\r\n string(pos+3:) = month(val(2))\r\n pos = LEN_TRIM( string ) + 2\r\nEND IF\r\n\r\nWRITE( string(pos:pos+3), '(i4)') val(1)\r\n\r\nRETURN\r\nEND SUBROUTINE date_stamp\r\n\r\nEND MODULE date_sub\r\n\r\n\r\n\r\nPROGRAM test_datesub\r\n\r\n!======DATESUB.FOR with Sample Drivers.\r\n\r\nUSE date_sub\r\nIMPLICIT NONE\r\nINTEGER :: yyyy, mm, dd, wd, ddd, mma, dda, ndiff, val(8)\r\nCHARACTER (LEN=50) :: message\r\n\r\n! Test date_stamp\r\nmessage = ' date_stamp = '\r\nCALL date_stamp( message(15:) )\r\nWRITE(*, '(a)') message\r\nmessage = ' date_stamp = '\r\nCALL date_stamp( message(15:), want_day=.FALSE.)\r\nWRITE(*, '(a)') message\r\nmessage = ' date_stamp = '\r\nCALL date_stamp( message(15:), short=.TRUE.)\r\nWRITE(*, '(a)') message\r\nmessage = ' date_stamp = '\r\nCALL date_stamp( message(15:), want_day=.FALSE., short=.TRUE.)\r\nWRITE(*, '(a)') message\r\n\r\n! Is this a leap year? I.e. is 12/31/yyyy the 366th day of the year?\r\nCALL DATE_AND_TIME(VALUES=val)\r\nyyyy = val(1)\r\n\r\nIF(iday(yyyy, 12, 31) == 366) THEN\r\n WRITE(*,*) yyyy, ' is a Leap Year'\r\nELSE\r\n WRITE(*,*) yyyy, ' is not a Leap Year'\r\nEND IF\r\n\r\n! DAYSUB SHOULD RETURN: 1970, 1, 1, 4, 1\r\nCALL daysub(jd(1970, 1, 1), yyyy, mm, dd, wd, ddd)\r\nIF(yyyy /= 1970 .OR. mm /= 1 .OR. dd /= 1 .OR. wd /= 4 .OR. ddd /= 1) THEN\r\n WRITE(*,*) 'DAYSUB Failed; YYYY, MM, DD, WD, DDD = ', yyyy, mm, dd, wd, ddd\r\n STOP\r\nEND IF\r\n\r\n! DIFFERENCE BETWEEN TO SAME MONTHS AND DAYS OVER 1 LEAP YEAR IS 366.\r\nndiff = ndays(5, 22, 1984, 5, 22, 1983)\r\nIF(ndiff /= 366) THEN\r\n WRITE(*,*) 'NDAYS FAILED; NDIFF = ', ndiff\r\nELSE\r\n! RECOVER MONTH AND DAY FROM YEAR AND DAY NUMBER.\r\n CALL calend(yyyy, ddd, mma, dda)\r\n IF(mma /= 1 .AND. dda /= 1) THEN\r\n WRITE(*,*) 'CALEND FAILED; MMA, DDA = ', mma, dda\r\n ELSE\r\n WRITE(*,*) '** DATE MANIPULATION SUBROUTINES SIMPLE TEST OK.'\r\n END IF\r\nEND IF\r\n\r\nSTOP\r\nEND PROGRAM test_datesub\r\n", "meta": {"hexsha": "96e3da2340b2b82a1d0b0f674c8493e5fb04070f", "size": 8095, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/datesub.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/datesub.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/datesub.f90", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 28.9107142857, "max_line_length": 80, "alphanum_fraction": 0.5813465102, "num_tokens": 2862, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818409, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6598735724918353}} {"text": " subroutine get_ALI(AL,ALI)\n******************************************\ncc Written by Lin-Wang Wang, March 30, 2001. \n*************************************************************************\n** copyright (c) 2003, The Regents of the University of California,\n** through Lawrence Berkeley National Laboratory (subject to receipt of any\n** required approvals from the U.S. Dept. of Energy). All rights reserved.\n*************************************************************************\n\n******************************************\n\n\n real*8 AL(3,3),ALI(3,3)\n real*8 tmp(3)\n\n do i=1,3\n do j=1,3\n ALI(j,i)=AL(i,j)\n enddo\n tmp(i)=1\n enddo\n\n call gaussj(ALI,3,3,tmp,1,1)\n\n*****************************************\n* * \\sum_i AL(i,j1)*ALI(i,j2)= \\delta_j1,j2\n* * 2*pi*ALI(i,j) is the jth G vector unit in (i)x,y,z components\n*****************************************\n return\n end\n\n", "meta": {"hexsha": "f96bc42089ad8eea7ab40020a11f29037d71b5d5", "size": 967, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "lsda_p/get_ALI.f", "max_stars_repo_name": "qsnake/petot", "max_stars_repo_head_hexsha": "bed334c6639fb02104821ce77d89ed83114febfe", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-07-13T07:57:59.000Z", "max_stars_repo_stars_event_max_datetime": "2016-07-13T07:57:59.000Z", "max_issues_repo_path": "lsda_p/get_ALI.f", "max_issues_repo_name": "qsnake/petot", "max_issues_repo_head_hexsha": "bed334c6639fb02104821ce77d89ed83114febfe", "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": "lsda_p/get_ALI.f", "max_forks_repo_name": "qsnake/petot", "max_forks_repo_head_hexsha": "bed334c6639fb02104821ce77d89ed83114febfe", "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": 30.21875, "max_line_length": 76, "alphanum_fraction": 0.3908996898, "num_tokens": 232, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6598735724918352}} {"text": "!\n!\n!\n FUNCTION COSDD(ALFA)\n implicit NONE\n!\n! --- Assuming that ALFA is given in DEGREES, it returns the COSINE of ALFA\n! ************************ GS and FC 11-02-2009 ***********************\n!\t\n REAL*8, PARAMETER :: PI=3.14159265358979323840D0 \n REAL*8 COSDD, ALFA, ALFARAD\t\t \n ALFARAD=ALFA*PI/180D0\t \n COSDD=COS(ALFARAD)\t \n END FUNCTION COSDD\n!\n!\n!\n", "meta": {"hexsha": "b0681cb71a98709fefa9fff47f66b91348bd0ca7", "size": 359, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/cosdd.f90", "max_stars_repo_name": "gassmoeller/selen", "max_stars_repo_head_hexsha": "796ed0c3b994e0a8d447934f3ec2863a2d2804ab", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2016-01-15T16:22:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-11T03:05:48.000Z", "max_issues_repo_path": "src/cosdd.f90", "max_issues_repo_name": "gassmoeller/selen", "max_issues_repo_head_hexsha": "796ed0c3b994e0a8d447934f3ec2863a2d2804ab", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2015-10-14T21:07:01.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T20:08:24.000Z", "max_forks_repo_path": "src/cosdd.f90", "max_forks_repo_name": "gassmoeller/selen", "max_forks_repo_head_hexsha": "796ed0c3b994e0a8d447934f3ec2863a2d2804ab", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2015-08-26T10:55:15.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-01T16:31:11.000Z", "avg_line_length": 19.9444444444, "max_line_length": 75, "alphanum_fraction": 0.5821727019, "num_tokens": 121, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8774767810736693, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6598735676728098}} {"text": "! { dg-do run }\n! { dg-options \"-fno-range-check\" }\n!\n! PR fortran/34342\n!\n! Test for Fortran 2003 BOZ.\n!\nprogram f2003\nimplicit none\n\nreal,parameter :: r2c = real(int(z'3333'))\nreal,parameter :: rc = real(z'50CB9F09')\ndouble precision,parameter :: dc = dble(Z'3FD34413509F79FF')\ncomplex,parameter :: z1c = cmplx(b'11000001010001101101110110000011', 3.049426e-10)\ncomplex,parameter :: z2c = cmplx(4.160326e16, o'6503667306')\n\nreal :: r2 = real(int(z'3333'))\nreal :: r = real(z'50CB9F09')\ndouble precision :: d = dble(Z'3FD34413509F79FF')\ncomplex :: z1 = cmplx(b'11000001010001101101110110000011', 3.049426e-10)\ncomplex :: z2 = cmplx(4.160326e16, o'6503667306')\n\nif (r2c /= 13107.0) STOP 1\nif (rc /= 2.732958e10) STOP 2\nif (dc /= 0.30102999566398120d0) STOP 3\nif (real(z1c) /= -1.242908e1 .or. aimag(z1c) /= 3.049426e-10) STOP 4\nif (real(z2c) /= 4.160326e16 .or. aimag(z2c) /= 5.343285e-7) STOP 5\n\nif (r2 /= 13107.0) STOP 6\nif (r /= 2.732958e10) STOP 7\nif (d /= 0.30102999566398120d0) STOP 8\nif (real(z1) /= -1.242908e1 .or. aimag(z1) /= 3.049426e-10) STOP 9\nif (real(z2) /= 4.160326e16 .or. aimag(z2) /= 5.343285e-7) STOP 10\n\nr2 = dble(int(z'3333'))\nr = real(z'50CB9F09')\nd = dble(Z'3FD34413509F79FF')\nz1 = cmplx(b'11000001010001101101110110000011', 3.049426e-10)\nz2 = cmplx(4.160326e16, o'6503667306')\n\nif (r2 /= 13107d0) STOP 11\nif (r /= 2.732958e10) STOP 12\nif (d /= 0.30102999566398120d0) STOP 13\nif (real(z1) /= -1.242908e1 .or. aimag(z1) /= 3.049426e-10) STOP 14\nif (real(z2) /= 4.160326e16 .or. aimag(z2) /= 5.343285e-7) STOP 15\n\ncall test4()\ncall test8()\n\ncontains\n\nsubroutine test4\nreal,parameter :: r2c = real(int(z'3333', kind=4), kind=4)\nreal,parameter :: rc = real(z'50CB9F09', kind=4)\ncomplex,parameter :: z1c = cmplx(b'11000001010001101101110110000011', 3.049426e-10, kind=4)\ncomplex,parameter :: z2c = cmplx(4.160326e16, o'6503667306', kind=4)\n\nreal :: r2 = real(int(z'3333', kind=4), kind=4)\nreal :: r = real(z'50CB9F09', kind=4)\ncomplex :: z1 = cmplx(b'11000001010001101101110110000011', 3.049426e-10, kind=4)\ncomplex :: z2 = cmplx(4.160326e16, o'6503667306', kind=4)\n\nif (r2c /= 13107.0) STOP 16\nif (rc /= 2.732958e10) STOP 17\nif (real(z1) /= -1.242908e1 .or. aimag(z1) /= 3.049426e-10) STOP 18\nif (real(z2) /= 4.160326e16 .or. aimag(z2) /= 5.343285e-7) STOP 19\n\nif (r2 /= 13107.0) STOP 20\nif (r /= 2.732958e10) STOP 21\nif (real(z1) /= -1.242908e1 .or. aimag(z1) /= 3.049426e-10) STOP 22\nif (real(z2) /= 4.160326e16 .or. aimag(z2) /= 5.343285e-7) STOP 23\n\nr2 = real(int(z'3333'), kind=4)\nr = real(z'50CB9F09', kind=4)\nz1 = cmplx(b'11000001010001101101110110000011', 3.049426e-10, kind=4)\nz2 = cmplx(4.160326e16, o'6503667306', kind=4)\n\nif (r2 /= 13107.0) STOP 24\nif (r /= 2.732958e10) STOP 25\nif (real(z1) /= -1.242908e1 .or. aimag(z1) /= 3.049426e-10) STOP 26\nif (real(z2) /= 4.160326e16 .or. aimag(z2) /= 5.343285e-7) STOP 27\nend subroutine test4\n\n\nsubroutine test8\nreal(8),parameter :: r2c = real(int(z'FFFFFF3333', kind=8), kind=8)\nreal(8),parameter :: rc = real(z'AAAAAFFFFFFF3333', kind=8)\ncomplex(8),parameter :: z1c = cmplx(b'11111011111111111111111111111111111111111111111111111111110101',-4.0, kind=8)\ncomplex(8),parameter :: z2c = cmplx(5.0, o'442222222222233301245', kind=8)\n\nreal(8) :: r2 = real(int(z'FFFFFF3333',kind=8),kind=8)\nreal(8) :: r = real(z'AAAAAFFFFFFF3333', kind=8)\ncomplex(8) :: z1 = cmplx(b'11111011111111111111111111111111111111111111111111111111110101',-4.0, kind=8)\ncomplex(8) :: z2 = cmplx(5.0, o'442222222222233301245', kind=8)\n\nif (r2c /= 1099511575347.0d0) STOP 28\nif (rc /= -3.72356884822177915d-103) STOP 29\nif (real(z1c) /= 3.05175781249999627d-5 .or. aimag(z1c) /= -4.0) STOP 30\nif (real(z2c) /= 5.0 .or. aimag(z2c) /= 3.98227593015308981d41) STOP 31\n\nif (r2 /= 1099511575347.0d0) STOP 32\nif (r /= -3.72356884822177915d-103) STOP 33\nif (real(z1) /= 3.05175781249999627d-5 .or. aimag(z1) /= -4.0) STOP 34\nif (real(z2) /= 5.0 .or. aimag(z2) /= 3.98227593015308981d41) STOP 35\n\nr2 = real(int(z'FFFFFF3333',kind=8),kind=8)\nr = real(z'AAAAAFFFFFFF3333', kind=8)\nz1 = cmplx(b'11111011111111111111111111111111111111111111111111111111110101',-4.0, kind=8)\nz2 = cmplx(5.0, o'442222222222233301245', kind=8)\n\nif (r2 /= 1099511575347.0d0) STOP 36\nif (r /= -3.72356884822177915d-103) STOP 37\nif (real(z1) /= 3.05175781249999627d-5 .or. aimag(z1) /= -4.0) STOP 38\nif (real(z2) /= 5.0 .or. aimag(z2) /= 3.98227593015308981d41) STOP 39\n\nend subroutine test8\n\nend program f2003\n", "meta": {"hexsha": "17920edc39d443196b8a15e9f1ac1b7206dcce99", "size": 4658, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/boz_9.f90", "max_stars_repo_name": "brugger1/testsuite", "max_stars_repo_head_hexsha": "9b504db668cdeaf7c561f15b76c95d05bfdd1517", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2019-02-12T18:20:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-09T19:46:19.000Z", "max_issues_repo_path": "validation_tests/llvm/f18/gfortran.dg/boz_9.f90", "max_issues_repo_name": "brugger1/testsuite", "max_issues_repo_head_hexsha": "9b504db668cdeaf7c561f15b76c95d05bfdd1517", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 24, "max_issues_repo_issues_event_min_datetime": "2020-08-31T22:05:07.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T18:30:03.000Z", "max_forks_repo_path": "validation_tests/llvm/f18/gfortran.dg/boz_9.f90", "max_forks_repo_name": "brugger1/testsuite", "max_forks_repo_head_hexsha": "9b504db668cdeaf7c561f15b76c95d05bfdd1517", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2020-08-31T21:59:10.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-23T22:06:46.000Z", "avg_line_length": 39.1428571429, "max_line_length": 116, "alphanum_fraction": 0.6502790897, "num_tokens": 2072, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767746654976, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6598735628537841}} {"text": "program demo_math_is_close\n\n use mini_test, only: check, is_close\n real :: x(2) = [1, 2]\n\n print *, is_close(x,[real :: 1, 2.1]) !! [T, F]\n print *, is_close(2.0, 2.1, atol=0.1) !! T\n\n call check(all(is_close(x, [2.0, 2.0])), msg=\"all(is_close(x, [2.0, 2.0])) failed.\", warn=.true.)\n !! all(is_close(x, [2.0, 2.0])) failed.\n \nend program demo_math_is_close", "meta": {"hexsha": "9695955edb8ccbbc7f97133fde45ebe999bfc061", "size": 389, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/demo_mini_test_is_close.f90", "max_stars_repo_name": "zoziha/mini-test", "max_stars_repo_head_hexsha": "4049670396acfefdc91c887589e61059965ebab1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "example/demo_mini_test_is_close.f90", "max_issues_repo_name": "zoziha/mini-test", "max_issues_repo_head_hexsha": "4049670396acfefdc91c887589e61059965ebab1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "example/demo_mini_test_is_close.f90", "max_forks_repo_name": "zoziha/mini-test", "max_forks_repo_head_hexsha": "4049670396acfefdc91c887589e61059965ebab1", "max_forks_repo_licenses": ["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.4166666667, "max_line_length": 101, "alphanum_fraction": 0.557840617, "num_tokens": 148, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706734, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.6598704190598196}} {"text": "\nprogram main\n\n use random_util2, only: init_random_seed\n\n implicit none\n integer :: seed\n real (kind=8) :: x(3)\n\n print *, \"input seed\"\n read *, seed\n\n call init_random_seed(seed) \n\n call random_number(x)\n print *, \"Three random numbers: \",x\n call random_number(x)\n print *, \"Three more random numbers: \",x\n\n\nend program main\n\n", "meta": {"hexsha": "16e0f5bdef9e66143835c70883eecb28a27745f6", "size": 362, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/labs/lab11/main.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/lab11/main.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/lab11/main.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": 15.7391304348, "max_line_length": 44, "alphanum_fraction": 0.6298342541, "num_tokens": 96, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8267117855317474, "lm_q2_score": 0.7981867777396212, "lm_q1q2_score": 0.6598704162129543}} {"text": "! { dg-do run }\n! { dg-options \"-std=f2003 \" }\n\n\n! PR fortran/38936\n! Association to derived-type, where the target type is not know\n! during parsing (only resolution).\n\n! Contributed by Daniel Kraft, d@domob.eu.\n\nMODULE m\n IMPLICIT NONE\n\n TYPE :: mynum\n INTEGER :: comp\n END TYPE mynum\n\n INTERFACE OPERATOR(+)\n MODULE PROCEDURE add\n END INTERFACE OPERATOR(+)\n\nCONTAINS\n\n PURE FUNCTION add (a, b)\n TYPE(mynum), INTENT(IN) :: a, b\n TYPE(mynum) :: add\n\n add%comp = a%comp + b%comp\n END FUNCTION add\n\nEND MODULE m\n\nPROGRAM main\n USE :: m\n IMPLICIT NONE\n\n TYPE(mynum) :: a\n a = mynum (5)\n\n ASSOCIATE (x => add (a, a))\n IF (x%comp /= 10) STOP 1\n END ASSOCIATE\n\n ASSOCIATE (x => a + a)\n IF (x%comp /= 10) STOP 2\n END ASSOCIATE\nEND PROGRAM main\n", "meta": {"hexsha": "f5f4fe2a8ad4c898be689b2822c3f0957647000d", "size": 774, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/associate_9.f03", "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/associate_9.f03", "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/associate_9.f03", "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": 16.125, "max_line_length": 64, "alphanum_fraction": 0.6304909561, "num_tokens": 259, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.826711776992821, "lm_q2_score": 0.7981867681382279, "lm_q1q2_score": 0.6598704014597111}} {"text": "cc Copyright (C) 2010-2011: Leslie Greengard, Zydrunas Gimbustas \ncc and Manas Rachh\ncc Contact: greengard@cims.nyu.edu\ncc \ncc This program is free software; you can redistribute it and/or modify \ncc it under the terms of the GNU General Public License as published by \ncc the Free Software Foundation; either version 2 of the License, or \ncc (at your option) any later version. This program is distributed in \ncc the hope that it will be useful, but WITHOUT ANY WARRANTY; without \ncc even the implied warranty of MERCHANTABILITY or FITNESS FOR A \ncc PARTICULAR PURPOSE. See the GNU General Public License for more \ncc details. You should have received a copy of the GNU General Public \ncc License along with this program; \ncc if not, see .\n\n\n\nc \nc Helmholtz FMM in R^2: evaluate all pairwise particle\nc interactions (ignoring self-interaction) \nc and interactions with targets.\nc\nc We use H_0(kr)*(i/4) for the Green's function.\nc Self-interactions are not included\nc\nc h2d: charge and dipstr are complex valued, x in \\R^2\nc\nc \\phi(x_i) = (i/4)\\sum_{j\\ne i} charge_j H^{(1)}_0(k |x_i - x_j|)\nc + dipstr_j (dipvec_j \\dot (x_i - x_j)) H^{(1)}_1(k |x_i - x_j|*\nc k/|x_i-x_j|\nc\nc\n\nc\nc\nc\nc\nc\nc\n\n subroutine hfmm2d_s_c_p(eps,zk,ns,sources,\n 1 charge,pot,ier)\ncf2py intent(in) eps\ncf2py intent(in) zk\ncf2py intent(in) ns,sources,charge\ncf2py intent(out) pot,ier\n\nc----------------------------------------------\nc INPUT PARAMETERS:\nc eps : FMM precision requested\nc zk : Helmholtz parameter\nc ns : number of sources\nc sources(2,ns) : source locations\nc charge(ns) : charge strengths\nc\nc OUTPUT PARAMETERS\nc pot(ns) : potential at the source locations\nc\n\n\n implicit none\nc\ncc calling sequence variables\nc \n real *8 eps\n complex *16 zk\n integer ns,ier\n real *8 sources(2,ns)\n complex *16 charge(ns)\n\n complex *16 pot(ns)\n\nc\ncc temporary variables\nc\n complex *16 dipstr\n real *8 dipvec(2)\n integer nt\n real *8 targ(2)\n complex *16 pottarg(1)\n complex *16 grad(2),gradtarg(2)\n complex *16 hess(3),hesstarg(3)\n integer ifcharge,ifdipole,iper\n integer ifpgh,ifpghtarg\n\n\n integer nd\n\n ifcharge = 1\n ifdipole = 0\n \n ifpgh = 1\n ifpghtarg = 0\n\n nt = 0\n\n nd = 1\n\n call hfmm2d(nd,eps,zk,ns,sources,ifcharge,charge,\n 1 ifdipole,dipstr,dipvec,iper,ifpgh,pot,grad,hess,\n 2 nt,targ,ifpghtarg,pottarg,gradtarg,\n 3 hesstarg,ier)\n return\n end\nc------------------------------\n\n\n subroutine hfmm2d_s_c_g(eps,zk,ns,sources,\n 1 charge,pot,grad,ier)\ncf2py intent(in) eps\ncf2py intent(in) zk\ncf2py intent(in) ns,sources,charge\ncf2py intent(out) pot,grad,ier\n\nc----------------------------------------------\nc INPUT PARAMETERS:\nc eps : FMM precision requested\nc zk : Helmholtz parameter\nc ns : number of sources\nc sources(2,ns) : source locations\nc charge(ns) : charge strengths\nc\nc OUTPUT PARAMETERS\nc pot(ns) : potential at the source locations\nc grad(2,ns) : gradients at the source locations\nc\n\n\n implicit none\nc\ncc calling sequence variables\nc \n real *8 eps\n complex *16 zk\n integer ns,ier\n real *8 sources(2,ns)\n complex *16 charge(ns)\n\n complex *16 pot(ns),grad(2,ns)\n\nc\ncc temporary variables\nc\n complex *16 dipstr\n real *8 dipvec(2)\n integer nt\n real *8 targ(2)\n complex *16 pottarg(1)\n complex *16 gradtarg(2)\n complex *16 hess(3),hesstarg(3)\n integer ifcharge,ifdipole,iper\n integer ifpgh,ifpghtarg\n integer nd\n\n ifcharge = 1\n ifdipole = 0\n\n nt = 0\n \n ifpgh = 2\n ifpghtarg = 0\n\n nd = 1\n\n call hfmm2d(nd,eps,zk,ns,sources,ifcharge,charge,\n 1 ifdipole,dipstr,dipvec,iper,ifpgh,pot,grad,hess,\n 2 nt,targ,ifpghtarg,pottarg,gradtarg,\n 3 hesstarg,ier)\n return\n end\nc------------------------------\nc\nc\nc\nc\nc\n subroutine hfmm2d_s_c_h(eps,zk,ns,sources,\n 1 charge,pot,grad,hess,ier)\ncf2py intent(in) eps\ncf2py intent(in) zk\ncf2py intent(in) ns,sources,charge\ncf2py intent(out) pot,grad,hess,ier\n\nc----------------------------------------------\nc INPUT PARAMETERS:\nc eps : FMM precision requested\nc zk : Helmholtz parameter\nc ns : number of sources\nc sources(2,ns) : source locations\nc charge(ns) : charge strengths\nc\nc OUTPUT PARAMETERS\nc pot(ns) : potential at the source locations\nc grad(2,ns) : gradients at the source locations\nc hess(3,ns) : hessian at the source locations\nc\n\n\n implicit none\nc\ncc calling sequence variables\nc \n real *8 eps\n complex *16 zk\n integer ns,ier\n real *8 sources(2,ns)\n complex *16 charge(ns)\n\n complex *16 pot(ns),grad(2,ns),hess(3,ns)\n\nc\ncc temporary variables\nc\n complex *16 dipstr\n real *8 dipvec(2)\n integer nt\n real *8 targ(2)\n complex *16 pottarg(1)\n complex *16 gradtarg(2)\n complex *16 hesstarg(3)\n integer ifcharge,ifdipole,iper\n integer ifpgh,ifpghtarg\n integer nd\n\n ifcharge = 1\n ifdipole = 0\n \n ifpgh = 3\n ifpghtarg = 0\n\n nd = 1\n\n nt = 0\n\n call hfmm2d(nd,eps,zk,ns,sources,ifcharge,charge,\n 1 ifdipole,dipstr,dipvec,iper,ifpgh,pot,grad,hess,\n 2 nt,targ,ifpghtarg,pottarg,gradtarg,\n 3 hesstarg,ier)\n return\n end\n\n\nc------------------------------- \n\n subroutine hfmm2d_s_d_p(eps,zk,ns,sources,\n 1 dipstr,dipvec,pot,ier)\ncf2py intent(in) eps\ncf2py intent(in) zk\ncf2py intent(in) ns,sources,dipstr,dipvec\ncf2py intent(out) pot,ier\n\nc----------------------------------------------\nc INPUT PARAMETERS:\nc eps : FMM precision requested\nc zk : Helmholtz parameter\nc ns : number of sources\nc sources(2,ns) : source locations\nc dipstr(ns) : dipole strengths\nc dipvec(2,ns) : dipole orientation vectors\nc\nc OUTPUT PARAMETERS\nc pot(ns) : potential at the source locations\nc\n\n\n implicit none\nc\ncc calling sequence variables\nc \n real *8 eps\n complex *16 zk\n integer ns,ier\n real *8 sources(2,ns)\n real *8 dipvec(2,ns)\n complex *16 dipstr(ns)\n\n complex *16 pot(ns)\n\nc\ncc temporary variables\nc\n complex *16 charge\n integer nt\n real *8 targ(2)\n complex *16 pottarg(1)\n complex *16 grad(2),gradtarg(2)\n complex *16 hess(3),hesstarg(3)\n integer ifcharge,ifdipole,iper\n integer ifpgh,ifpghtarg\n\n integer nd\n\n ifcharge = 0\n ifdipole = 1\n \n ifpgh = 1\n ifpghtarg = 0\n \n nt = 0\n\n nd = 1\n\n call hfmm2d(nd,eps,zk,ns,sources,ifcharge,charge,\n 1 ifdipole,dipstr,dipvec,iper,ifpgh,pot,grad,hess,\n 2 nt,targ,ifpghtarg,pottarg,gradtarg,\n 3 hesstarg,ier)\n return\n end\nc------------------------------\n\n\n subroutine hfmm2d_s_d_g(eps,zk,ns,sources,\n 1 dipstr,dipvec,pot,grad,ier)\ncf2py intent(in) eps\ncf2py intent(in) zk\ncf2py intent(in) ns,sources,dipstr,dipvec\ncf2py intent(out) pot,grad,ier\n\nc----------------------------------------------\nc INPUT PARAMETERS:\nc eps : FMM precision requested\nc zk : Helmholtz parameter\nc ns : number of sources\nc sources(2,ns) : source locations\nc dipstr(ns) : dipole strengths\nc dipvec(2,ns) : dipole orientation vectors\nc\nc OUTPUT PARAMETERS\nc pot(ns) : potential at the source locations\nc grad(2,ns) : gradients at the source locations\nc\n\n\n implicit none\nc\ncc calling sequence variables\nc \n real *8 eps\n complex *16 zk\n integer ns,ier\n real *8 sources(2,ns)\n real *8 dipvec(2,ns)\n complex *16 dipstr(ns)\n\n complex *16 pot(ns),grad(2,ns)\n\nc\ncc temporary variables\nc\n complex *16 charge\n integer nt\n real *8 targ(2)\n complex *16 pottarg(1)\n complex *16 gradtarg(2)\n complex *16 hess(3),hesstarg(3)\n integer ifcharge,ifdipole,iper\n integer ifpgh,ifpghtarg\n integer nd\n\n ifcharge = 0\n ifdipole = 1\n \n ifpgh = 2\n ifpghtarg = 0\n\n nt = 0\n\n nd = 1\n\n call hfmm2d(nd,eps,zk,ns,sources,ifcharge,charge,\n 1 ifdipole,dipstr,dipvec,iper,ifpgh,pot,grad,hess,\n 2 nt,targ,ifpghtarg,pottarg,gradtarg,\n 3 hesstarg,ier)\n return\n end\nc------------------------------\nc\nc\nc\nc\nc\n subroutine hfmm2d_s_d_h(eps,zk,ns,sources,\n 1 dipstr,dipvec,pot,grad,hess,ier)\ncf2py intent(in) eps\ncf2py intent(in) zk\ncf2py intent(in) ns,sources,dipstr,dipvec\ncf2py intent(out) pot,grad,hess,ier\n\nc----------------------------------------------\nc INPUT PARAMETERS:\nc eps : FMM precision requested\nc zk : Helmholtz parameter\nc ns : number of sources\nc sources(2,ns) : source locations\nc dipstr(ns) : dipole strengths\nc dipvec(2,ns) : dipole orientation vectors\nc\nc OUTPUT PARAMETERS\nc pot(ns) : potential at the source locations\nc grad(2,ns) : gradients at the source locations\nc hess(3,ns) : hessian at the source locations\nc\n\n\n implicit none\nc\ncc calling sequence variables\nc \n real *8 eps\n complex *16 zk\n integer ns,ier\n real *8 sources(2,ns)\n real *8 dipvec(2,ns)\n complex *16 dipstr(ns)\n\n complex *16 pot(ns),grad(2,ns),hess(3,ns)\n\nc\ncc temporary variables\nc\n complex *16 charge\n integer nt\n real *8 targ(2)\n complex *16 pottarg(1)\n complex *16 gradtarg(2)\n complex *16 hesstarg(3)\n integer ifcharge,ifdipole,iper\n integer ifpgh,ifpghtarg\n integer nd\n\n ifcharge = 0\n ifdipole = 1\n \n ifpgh = 3\n ifpghtarg = 0\n\n nt = 0\n\n nd = 1\n\n call hfmm2d(nd,eps,zk,ns,sources,ifcharge,charge,\n 1 ifdipole,dipstr,dipvec,iper,ifpgh,pot,grad,hess,\n 2 nt,targ,ifpghtarg,pottarg,gradtarg,\n 3 hesstarg,ier)\n return\n end\n\n\nc------------------------------- \n\n subroutine hfmm2d_s_cd_p(eps,zk,ns,sources,charge,\n 1 dipstr,dipvec,pot,ier)\ncf2py intent(in) eps\ncf2py intent(in) zk\ncf2py intent(in) ns,sources,dipstr,dipvec,charge\ncf2py intent(out) pot,ier\n\nc----------------------------------------------\nc INPUT PARAMETERS:\nc eps : FMM precision requested\nc zk : Helmholtz parameter\nc ns : number of sources\nc sources(2,ns) : source locations\nc charge(ns) : charge strengths\nc dipstr(ns) : dipole strengths\nc dipvec(2,ns) : dipole orientation vectors\nc\nc OUTPUT PARAMETERS\nc pot(ns) : potential at the source locations\nc\n\n\n implicit none\nc\ncc calling sequence variables\nc \n real *8 eps\n complex *16 zk\n integer ns,ier\n real *8 sources(2,ns)\n real *8 dipvec(2,ns)\n complex *16 charge(ns),dipstr(ns)\n\n complex *16 pot(ns)\n\nc\ncc temporary variables\nc\n integer nt\n real *8 targ(2)\n complex *16 pottarg(1)\n complex *16 grad(2),gradtarg(2)\n complex *16 hess(3),hesstarg(3)\n integer ifcharge,ifdipole,iper\n integer ifpgh,ifpghtarg\n\n integer nd\n\n ifcharge = 1\n ifdipole = 1\n \n ifpgh = 1\n ifpghtarg = 0\n\n nt = 0\n\n nd = 1\n\n call hfmm2d(nd,eps,zk,ns,sources,ifcharge,charge,\n 1 ifdipole,dipstr,dipvec,iper,ifpgh,pot,grad,hess,\n 2 nt,targ,ifpghtarg,pottarg,gradtarg,\n 3 hesstarg,ier)\n return\n end\nc------------------------------\nc\nc\nc\nc\n\n subroutine hfmm2d_s_cd_g(eps,zk,ns,sources,charge,\n 1 dipstr,dipvec,pot,grad,ier)\ncf2py intent(in) eps\ncf2py intent(in) zk\ncf2py intent(in) ns,sources,dipstr,dipvec,charge\ncf2py intent(out) pot,grad,ier\n\nc----------------------------------------------\nc INPUT PARAMETERS:\nc eps : FMM precision requested\nc zk : Helmholtz parameter\nc ns : number of sources\nc sources(2,ns) : source locations\nc charge(ns) : charge strengths\nc dipstr(ns) : dipole strengths\nc dipvec(2,ns) : dipole orientation vectors\nc\nc OUTPUT PARAMETERS\nc pot(ns) : potential at the source locations\nc grad(2,ns) : gradients at the source locations\nc\n\n implicit none\nc\ncc calling sequence variables\nc \n real *8 eps\n complex *16 zk\n integer ns,ier\n real *8 sources(2,ns)\n real *8 dipvec(2,ns)\n complex *16 charge(ns),dipstr(ns)\n\n complex *16 pot(ns),grad(2,ns)\n\nc\ncc temporary variables\nc\n integer nt\n real *8 targ(2)\n complex *16 pottarg(1)\n complex *16 gradtarg(2)\n complex *16 hess(3),hesstarg(3)\n integer ifcharge,ifdipole,iper\n integer ifpgh,ifpghtarg\n integer nd\n\n ifcharge = 1\n ifdipole = 1\n \n ifpgh = 2\n ifpghtarg = 0\n\n nt = 0\n\n nd = 1\n\n call hfmm2d(nd,eps,zk,ns,sources,ifcharge,charge,\n 1 ifdipole,dipstr,dipvec,iper,ifpgh,pot,grad,hess,\n 2 nt,targ,ifpghtarg,pottarg,gradtarg,\n 3 hesstarg,ier)\n return\n end\nc------------------------------\nc\nc\nc\nc\nc\n subroutine hfmm2d_s_cd_h(eps,zk,ns,sources,charge,\n 1 dipstr,dipvec,pot,grad,hess,ier)\ncf2py intent(in) eps\ncf2py intent(in) zk\ncf2py intent(in) ns,sources,dipstr,dipvec,charge\ncf2py intent(out) pot,grad,hess,ier\n\nc----------------------------------------------\nc INPUT PARAMETERS:\nc eps : FMM precision requested\nc zk : Helmholtz parameter\nc ns : number of sources\nc sources(2,ns) : source locations\nc charge(ns) : charge strengths\nc dipstr(ns) : dipole strengths\nc dipvec(2,ns) : dipole orientation vectors\nc\nc OUTPUT PARAMETERS\nc pot(ns) : potential at the source locations\nc grad(2,ns) : gradients at the source locations\nc hess(3,ns) : hessian at the source locations\nc\n\n\n implicit none\nc\ncc calling sequence variables\nc \n real *8 eps\n complex *16 zk\n integer ns,ier\n real *8 sources(2,ns)\n real *8 dipvec(2,ns)\n complex *16 charge(ns),dipstr(ns)\n\n complex *16 pot(ns),grad(2,ns),hess(3,ns)\n\nc\ncc temporary variables\nc\n integer nt\n real *8 targ(2)\n complex *16 pottarg(1)\n complex *16 gradtarg(2)\n complex *16 hesstarg(3)\n integer ifcharge,ifdipole,iper\n integer ifpgh,ifpghtarg\n integer nd\n\n ifcharge = 1\n ifdipole = 1\n \n ifpgh = 3\n ifpghtarg = 0\n\n nt = 0\n\n nd = 1\n\n call hfmm2d(nd,eps,zk,ns,sources,ifcharge,charge,\n 1 ifdipole,dipstr,dipvec,iper,ifpgh,pot,grad,hess,\n 2 nt,targ,ifpghtarg,pottarg,gradtarg,\n 3 hesstarg,ier)\n return\n end\n\n\n subroutine hfmm2d_t_c_p(eps,zk,ns,sources,\n 1 charge,nt,targ,pottarg,ier)\ncf2py intent(in) eps\ncf2py intent(in) zk\ncf2py intent(in) ns,sources,charge,nt,targ\ncf2py intent(out) pottarg,ier\n\nc----------------------------------------------\nc INPUT PARAMETERS:\nc eps : FMM precision requested\nc zk : Helmholtz parameter\nc ns : number of sources\nc sources(2,ns) : source locations\nc charge(ns) : charge strengths\nc nt : number of targets\nc targ(2,nt) : target locations\nc\nc OUTPUT PARAMETERS\nc pottarg(nt) : potential at the target locations\nc\n\n\n implicit none\nc\ncc calling sequence variables\nc \n real *8 eps\n complex *16 zk\n integer ns,nt,ier\n real *8 sources(2,ns),targ(2,nt)\n complex *16 charge(ns)\n\n complex *16 pottarg(nt)\n\nc\ncc temporary variables\nc\n complex *16 dipstr\n real *8 dipvec(2)\n complex *16 pot(1)\n complex *16 grad(2),gradtarg(2)\n complex *16 hess(3),hesstarg(3)\n integer ifcharge,ifdipole,iper\n integer ifpgh,ifpghtarg\n\n integer nd\n\n ifcharge = 1\n ifdipole = 0\n \n ifpgh = 0\n ifpghtarg = 1\n\n nd = 1\n\n call hfmm2d(nd,eps,zk,ns,sources,ifcharge,charge,\n 1 ifdipole,dipstr,dipvec,iper,ifpgh,pot,grad,hess,\n 2 nt,targ,ifpghtarg,pottarg,gradtarg,\n 3 hesstarg,ier)\n return\n end\nc------------------------------\n\n\n subroutine hfmm2d_t_c_g(eps,zk,ns,sources,\n 1 charge,nt,targ,pottarg,gradtarg,ier)\ncf2py intent(in) eps\ncf2py intent(in) zk\ncf2py intent(in) ns,sources,charge,nt,targ\ncf2py intent(out) pottarg,gradtarg,ier\n\nc----------------------------------------------\nc INPUT PARAMETERS:\nc eps : FMM precision requested\nc zk : Helmholtz parameter\nc ns : number of sources\nc sources(2,ns) : source locations\nc charge(ns) : charge strengths\nc nt : number of targets\nc targ(2,nt) : target locations\nc\nc OUTPUT PARAMETERS\nc pottarg(nt) : potential at the target locations\nc gradtarg(2,nt): gradient at the target locations\nc\n\n\n implicit none\nc\ncc calling sequence variables\nc \n real *8 eps\n complex *16 zk\n integer ns,nt,ier\n real *8 sources(2,ns),targ(2,nt)\n complex *16 charge(ns)\n\n complex *16 pottarg(nt),gradtarg(2,nt)\n\nc\ncc temporary variables\nc\n complex *16 dipstr\n real *8 dipvec(2)\n complex *16 pot(1)\n complex *16 grad(2)\n complex *16 hess(3),hesstarg(3)\n integer ifcharge,ifdipole,iper\n integer ifpgh,ifpghtarg\n integer nd\n\n ifcharge = 1\n ifdipole = 0\n \n ifpgh = 0\n ifpghtarg = 2\n\n nd = 1\n\n call hfmm2d(nd,eps,zk,ns,sources,ifcharge,charge,\n 1 ifdipole,dipstr,dipvec,iper,ifpgh,pot,grad,hess,\n 2 nt,targ,ifpghtarg,pottarg,gradtarg,\n 3 hesstarg,ier)\n return\n end\nc------------------------------\nc\nc\nc\nc\nc\n subroutine hfmm2d_t_c_h(eps,zk,ns,sources,\n 1 charge,nt,targ,pottarg,\n 2 gradtarg,hesstarg,ier)\ncf2py intent(in) eps\ncf2py intent(in) zk\ncf2py intent(in) ns,sources,charge,nt,targ\ncf2py intent(out) pottarg,gradtarg,hesstarg,ier\n\nc----------------------------------------------\nc INPUT PARAMETERS:\nc eps : FMM precision requested\nc zk : Helmholtz parameter\nc ns : number of sources\nc sources(2,ns) : source locations\nc charge(ns) : charge strengths\nc nt : number of targets\nc targ(2,nt) : target locations\nc\nc OUTPUT PARAMETERS\nc pottarg(nt) : potential at the target locations\nc gradtarg(2,nt): gradient at the target locations\nc hesstarg(3,nt): hessian at the target locations\nc\n\n\n implicit none\nc\ncc calling sequence variables\nc \n real *8 eps\n complex *16 zk\n integer ns,nt,ier\n real *8 sources(2,ns),targ(2,nt)\n complex *16 charge(ns)\n\n complex *16 pottarg(nt),gradtarg(2,nt),hesstarg(3,nt)\n\nc\ncc temporary variables\nc\n complex *16 dipstr\n real *8 dipvec(2)\n complex *16 pot(1)\n complex *16 grad(2)\n complex *16 hess(3)\n integer ifcharge,ifdipole,iper\n integer ifpgh,ifpghtarg\n integer nd\n\n ifcharge = 1\n ifdipole = 0\n \n ifpgh = 0\n ifpghtarg = 3\n\n nd = 1\n\n call hfmm2d(nd,eps,zk,ns,sources,ifcharge,charge,\n 1 ifdipole,dipstr,dipvec,iper,ifpgh,pot,grad,hess,\n 2 nt,targ,ifpghtarg,pottarg,gradtarg,\n 3 hesstarg,ier)\n return\n end\n\n\nc------------------------------- \n\n subroutine hfmm2d_t_d_p(eps,zk,ns,sources,\n 1 dipstr,dipvec,nt,targ,pottarg,ier)\ncf2py intent(in) eps\ncf2py intent(in) zk\ncf2py intent(in) ns,sources,dipstr,dipvec,nt,targ\ncf2py intent(out) pottarg,ier\n\nc----------------------------------------------\nc INPUT PARAMETERS:\nc eps : FMM precision requested\nc zk : Helmholtz parameter\nc ns : number of sources\nc sources(2,ns) : source locations\nc dipstr(ns) : dipole strengths\nc dipvec(2,ns) : dipole orientation vectors\nc nt : number of targets\nc targ(2,nt) : target locations\nc\nc OUTPUT PARAMETERS\nc pottarg(nt) : potential at the target locations\nc\n\n\n implicit none\nc\ncc calling sequence variables\nc \n real *8 eps\n complex *16 zk\n integer ns,nt,ier\n real *8 sources(2,ns),targ(2,nt)\n real *8 dipvec(2,ns)\n complex *16 dipstr(ns)\n\n complex *16 pottarg(nt)\n\nc\ncc temporary variables\nc\n complex *16 charge\n complex *16 pot(1)\n complex *16 grad(2),gradtarg(2)\n complex *16 hess(3),hesstarg(3)\n integer ifcharge,ifdipole,iper\n integer ifpgh,ifpghtarg\n\n integer nd\n\n ifcharge = 0\n ifdipole = 1\n \n ifpgh = 0\n ifpghtarg = 1\n\n nd = 1\n\n call hfmm2d(nd,eps,zk,ns,sources,ifcharge,charge,\n 1 ifdipole,dipstr,dipvec,iper,ifpgh,pot,grad,hess,\n 2 nt,targ,ifpghtarg,pottarg,gradtarg,\n 3 hesstarg,ier)\n return\n end\nc------------------------------\n\n\n subroutine hfmm2d_t_d_g(eps,zk,ns,sources,\n 1 dipstr,dipvec,nt,targ,pottarg,gradtarg,ier)\ncf2py intent(in) eps\ncf2py intent(in) zk\ncf2py intent(in) ns,sources,dipstr,dipvec,nt,targ\ncf2py intent(out) pottarg,gradtarg,ier\n\nc----------------------------------------------\nc INPUT PARAMETERS:\nc eps : FMM precision requested\nc zk : Helmholtz parameter\nc ns : number of sources\nc sources(2,ns) : source locations\nc dipstr(ns) : dipole strengths\nc dipvec(2,ns) : dipole orientation vectors\nc nt : number of targets\nc targ(2,nt) : target locations\nc\nc OUTPUT PARAMETERS\nc pottarg(nt) : potential at the target locations\nc gradtarg(2,nt): gradient at the target locations\nc\n\n\n implicit none\nc\ncc calling sequence variables\nc \n real *8 eps\n complex *16 zk\n integer ns,nt,ier\n real *8 sources(2,ns),targ(2,nt)\n real *8 dipvec(2,ns)\n complex *16 dipstr(ns)\n\n complex *16 pottarg(nt),gradtarg(2,nt)\n\nc\ncc temporary variables\nc\n complex *16 charge\n complex *16 pot(1)\n complex *16 grad(2)\n complex *16 hess(3),hesstarg(3)\n integer ifcharge,ifdipole,iper\n integer ifpgh,ifpghtarg\n integer nd\n\n ifcharge = 0\n ifdipole = 1\n \n ifpgh = 0\n ifpghtarg = 2\n\n nd = 1\n\n call hfmm2d(nd,eps,zk,ns,sources,ifcharge,charge,\n 1 ifdipole,dipstr,dipvec,iper,ifpgh,pot,grad,hess,\n 2 nt,targ,ifpghtarg,pottarg,gradtarg,\n 3 hesstarg,ier)\n return\n end\nc------------------------------\nc\nc\nc\nc\nc\n subroutine hfmm2d_t_d_h(eps,zk,ns,sources,\n 1 dipstr,dipvec,nt,targ,pottarg,\n 2 gradtarg,hesstarg,ier)\ncf2py intent(in) eps\ncf2py intent(in) zk\ncf2py intent(in) ns,sources,dipstr,dipvec,nt,targ\ncf2py intent(out) pottarg,gradtarg,hesstarg,ier\n\nc----------------------------------------------\nc INPUT PARAMETERS:\nc eps : FMM precision requested\nc zk : Helmholtz parameter\nc ns : number of sources\nc sources(2,ns) : source locations\nc dipstr(ns) : dipole strengths\nc dipvec(2,ns) : dipole orientation vectors\nc nt : number of targets\nc targ(2,nt) : target locations\nc\nc OUTPUT PARAMETERS\nc pottarg(nt) : potential at the target locations\nc gradtarg(2,nt): gradient at the target locations\nc hesstarg(3,nt): hessian at the target locations\nc\n\n\n implicit none\nc\ncc calling sequence variables\nc \n real *8 eps\n complex *16 zk\n integer ns,nt,ier\n real *8 sources(2,ns),targ(2,nt)\n real *8 dipvec(2,ns)\n complex *16 dipstr(ns)\n\n complex *16 pottarg(nt),gradtarg(2,nt),hesstarg(3,nt)\n\nc\ncc temporary variables\nc\n complex *16 charge\n complex *16 pot(1)\n complex *16 grad(2)\n complex *16 hess(3)\n integer ifcharge,ifdipole,iper\n integer ifpgh,ifpghtarg\n integer nd\n\n ifcharge = 0\n ifdipole = 1\n \n ifpgh = 0\n ifpghtarg = 3\n\n nd = 1\n\n call hfmm2d(nd,eps,zk,ns,sources,ifcharge,charge,\n 1 ifdipole,dipstr,dipvec,iper,ifpgh,pot,grad,hess,\n 2 nt,targ,ifpghtarg,pottarg,gradtarg,\n 3 hesstarg,ier)\n return\n end\n\n\nc------------------------------- \n\n subroutine hfmm2d_t_cd_p(eps,zk,ns,sources,charge,\n 1 dipstr,dipvec,nt,targ,pottarg,ier)\ncf2py intent(in) eps\ncf2py intent(in) zk\ncf2py intent(in) ns,sources,charge,dipstr,dipvec,nt,targ\ncf2py intent(out) pottarg,ier\n\nc----------------------------------------------\nc INPUT PARAMETERS:\nc eps : FMM precision requested\nc zk : Helmholtz parameter\nc ns : number of sources\nc sources(2,ns) : source locations\nc charge(ns) : charge strengths\nc dipstr(ns) : dipole strengths\nc dipvec(2,ns) : dipole orientation vectors\nc nt : number of targets\nc targ(2,nt) : target locations\nc\nc OUTPUT PARAMETERS\nc pottarg(nt) : potential at the target locations\nc\n\n\n implicit none\nc\ncc calling sequence variables\nc \n real *8 eps\n complex *16 zk\n integer ns,nt,ier\n real *8 sources(2,ns),targ(2,nt)\n real *8 dipvec(2,ns)\n complex *16 charge(ns),dipstr(ns)\n\n complex *16 pottarg(nt)\n\nc\ncc temporary variables\nc\n complex *16 pot(1)\n complex *16 grad(2),gradtarg(2)\n complex *16 hess(3),hesstarg(3)\n integer ifcharge,ifdipole,iper\n integer ifpgh,ifpghtarg\n\n integer nd\n\n ifcharge = 1\n ifdipole = 1\n \n ifpgh = 0\n ifpghtarg = 1\n\n nd = 1\n\n call hfmm2d(nd,eps,zk,ns,sources,ifcharge,charge,\n 1 ifdipole,dipstr,dipvec,iper,ifpgh,pot,grad,hess,\n 2 nt,targ,ifpghtarg,pottarg,gradtarg,\n 3 hesstarg,ier)\n return\n end\nc------------------------------\nc\nc\nc\nc\n\n subroutine hfmm2d_t_cd_g(eps,zk,ns,sources,charge,\n 1 dipstr,dipvec,nt,targ,pottarg,gradtarg,ier)\ncf2py intent(in) eps\ncf2py intent(in) zk\ncf2py intent(in) ns,sources,charge,dipstr,dipvec,nt,targ\ncf2py intent(out) pottarg,gradtarg,ier\n\nc----------------------------------------------\nc INPUT PARAMETERS:\nc eps : FMM precision requested\nc zk : Helmholtz parameter\nc ns : number of sources\nc sources(2,ns) : source locations\nc charge(ns) : charge strengths\nc dipstr(ns) : dipole strengths\nc dipvec(2,ns) : dipole orientation vectors\nc nt : number of targets\nc targ(2,nt) : target locations\nc\nc OUTPUT PARAMETERS\nc pottarg(nt) : potential at the target locations\nc gradtarg(2,nt): gradient at the target locations\nc\n\n implicit none\nc\ncc calling sequence variables\nc \n real *8 eps\n complex *16 zk\n integer ns,nt,ier\n real *8 sources(2,ns),targ(2,nt)\n real *8 dipvec(2,ns)\n complex *16 charge(ns),dipstr(ns)\n\n complex *16 pottarg(nt),gradtarg(2,nt)\n\nc\ncc temporary variables\nc\n complex *16 pot(1)\n complex *16 grad(2)\n complex *16 hess(3),hesstarg(3)\n integer ifcharge,ifdipole,iper\n integer ifpgh,ifpghtarg\n integer nd\n\n ifcharge = 1\n ifdipole = 1\n \n ifpgh = 0\n ifpghtarg = 2\n\n nd = 1\n\n call hfmm2d(nd,eps,zk,ns,sources,ifcharge,charge,\n 1 ifdipole,dipstr,dipvec,iper,ifpgh,pot,grad,hess,\n 2 nt,targ,ifpghtarg,pottarg,gradtarg,\n 3 hesstarg,ier)\n return\n end\nc------------------------------\nc\nc\nc\nc\nc\n subroutine hfmm2d_t_cd_h(eps,zk,ns,sources,charge,\n 1 dipstr,dipvec,nt,targ,pottarg,\n 2 gradtarg,hesstarg,ier)\ncf2py intent(in) eps\ncf2py intent(in) zk\ncf2py intent(in) ns,sources,charge,dipstr,dipvec,nt,targ\ncf2py intent(out) pottarg,gradtarg,hesstarg,ier\n\nc----------------------------------------------\nc INPUT PARAMETERS:\nc eps : FMM precision requested\nc zk : Helmholtz parameter\nc ns : number of sources\nc sources(2,ns) : source locations\nc charge(ns) : charge strengths\nc dipstr(ns) : dipole strengths\nc dipvec(2,ns) : dipole orientation vectors\nc nt : number of targets\nc targ(2,nt) : target locations\nc\nc OUTPUT PARAMETERS\nc pottarg(nt) : potential at the target locations\nc gradtarg(2,nt): gradient at the target locations\nc hesstarg(3,nt): hessian at the target locations\nc\n\n\n implicit none\nc\ncc calling sequence variables\nc \n real *8 eps\n complex *16 zk\n integer ns,nt,ier\n real *8 sources(2,ns),targ(2,nt)\n real *8 dipvec(2,ns)\n complex *16 charge(ns),dipstr(ns)\n\n complex *16 pottarg(nt),gradtarg(2,nt),hesstarg(3,nt)\n\nc\ncc temporary variables\nc\n integer ifcharge,ifdipole,iper\n integer ifpgh,ifpghtarg\n integer nd\n complex *16 pot(1)\n complex *16 grad(2)\n complex *16 hess(3)\n\n ifcharge = 1\n ifdipole = 1\n \n ifpgh = 0\n ifpghtarg = 3\n\n nd = 1\n\n call hfmm2d(nd,eps,zk,ns,sources,ifcharge,charge,\n 1 ifdipole,dipstr,dipvec,iper,ifpgh,pot,grad,hess,\n 2 nt,targ,ifpghtarg,pottarg,gradtarg,\n 3 hesstarg,ier)\n return\n end\n\n\nc\nc\nc\nc\nc\nc\n\n subroutine hfmm2d_st_c_p(eps,zk,ns,sources,\n 1 charge,pot,nt,targ,pottarg,ier)\ncf2py intent(in) eps\ncf2py intent(in) zk\ncf2py intent(in) ns,sources,charge,nt,targ\ncf2py intent(out) pot,pottarg,ier\n\nc----------------------------------------------\nc INPUT PARAMETERS:\nc eps : FMM precision requested\nc zk : Helmholtz parameter\nc ns : number of sources\nc sources(2,ns) : source locations\nc charge(ns) : charge strengths\nc nt : number of targets\nc targ(2,nt) : target locations\nc\nc OUTPUT PARAMETERS\nc pot(ns) : potential at the source locations\nc pottarg(nt) : potential at the target locations\nc\n\n\n implicit none\nc\ncc calling sequence variables\nc \n real *8 eps\n complex *16 zk\n integer ns,nt,ier\n real *8 sources(2,ns),targ(2,nt)\n complex *16 charge(ns)\n\n complex *16 pot(ns)\n complex *16 pottarg(nt)\n\nc\ncc temporary variables\nc\n complex *16 dipstr\n real *8 dipvec(2)\n complex *16 grad(2),gradtarg(2)\n complex *16 hess(3),hesstarg(3)\n integer ifcharge,ifdipole,iper\n integer ifpgh,ifpghtarg\n\n integer nd\n\n ifcharge = 1\n ifdipole = 0\n \n ifpgh = 1\n ifpghtarg = 1\n\n nd = 1\n\n call hfmm2d(nd,eps,zk,ns,sources,ifcharge,charge,\n 1 ifdipole,dipstr,dipvec,iper,ifpgh,pot,grad,hess,\n 2 nt,targ,ifpghtarg,pottarg,gradtarg,\n 3 hesstarg,ier)\n return\n end\nc------------------------------\n\n\n subroutine hfmm2d_st_c_g(eps,zk,ns,sources,\n 1 charge,pot,grad,nt,targ,pottarg,gradtarg,ier)\ncf2py intent(in) eps\ncf2py intent(in) zk\ncf2py intent(in) ns,sources,charge,nt,targ\ncf2py intent(out) pot,pottarg,grad,gradtarg,ier\n\nc----------------------------------------------\nc INPUT PARAMETERS:\nc eps : FMM precision requested\nc zk : Helmholtz parameter\nc ns : number of sources\nc sources(2,ns) : source locations\nc charge(ns) : charge strengths\nc nt : number of targets\nc targ(2,nt) : target locations\nc\nc OUTPUT PARAMETERS\nc pot(ns) : potential at the source locations\nc grad(2,ns) : gradients at the source locations\nc pottarg(nt) : potential at the target locations\nc gradtarg(2,nt): gradient at the target locations\nc\n\n\n implicit none\nc\ncc calling sequence variables\nc \n real *8 eps\n complex *16 zk\n integer ns,nt,ier\n real *8 sources(2,ns),targ(2,nt)\n complex *16 charge(ns)\n\n complex *16 pot(ns),grad(2,ns)\n complex *16 pottarg(nt),gradtarg(2,nt)\n\nc\ncc temporary variables\nc\n complex *16 dipstr\n real *8 dipvec(2)\n complex *16 hess(3),hesstarg(3)\n integer ifcharge,ifdipole,iper\n integer ifpgh,ifpghtarg\n integer nd\n\n ifcharge = 1\n ifdipole = 0\n \n ifpgh = 2\n ifpghtarg = 2\n\n nd = 1\n\n call hfmm2d(nd,eps,zk,ns,sources,ifcharge,charge,\n 1 ifdipole,dipstr,dipvec,iper,ifpgh,pot,grad,hess,\n 2 nt,targ,ifpghtarg,pottarg,gradtarg,\n 3 hesstarg,ier)\n return\n end\nc------------------------------\nc\nc\nc\nc\nc\n subroutine hfmm2d_st_c_h(eps,zk,ns,sources,\n 1 charge,pot,grad,hess,nt,targ,pottarg,\n 2 gradtarg,hesstarg,ier)\ncf2py intent(in) eps\ncf2py intent(in) zk\ncf2py intent(in) ns,sources,charge,nt,targ\ncf2py intent(out) pot,pottarg,grad,gradtarg,hess,hesstarg,ier\n\nc----------------------------------------------\nc INPUT PARAMETERS:\nc eps : FMM precision requested\nc zk : Helmholtz parameter\nc ns : number of sources\nc sources(2,ns) : source locations\nc charge(ns) : charge strengths\nc nt : number of targets\nc targ(2,nt) : target locations\nc\nc OUTPUT PARAMETERS\nc pot(ns) : potential at the source locations\nc grad(2,ns) : gradients at the source locations\nc hess(3,ns) : hessian at the source locations\nc pottarg(nt) : potential at the target locations\nc gradtarg(2,nt): gradient at the target locations\nc hesstarg(3,nt): hessian at the target locations\nc\n\n\n implicit none\nc\ncc calling sequence variables\nc \n real *8 eps\n complex *16 zk\n integer ns,nt,ier\n real *8 sources(2,ns),targ(2,nt)\n complex *16 charge(ns)\n\n complex *16 pot(ns),grad(2,ns),hess(3,ns)\n complex *16 pottarg(nt),gradtarg(2,nt),hesstarg(3,nt)\n\nc\ncc temporary variables\nc\n complex *16 dipstr\n real *8 dipvec(2)\n integer ifcharge,ifdipole,iper\n integer ifpgh,ifpghtarg\n integer nd\n\n ifcharge = 1\n ifdipole = 0\n \n ifpgh = 3\n ifpghtarg = 3\n\n nd = 1\n\n call hfmm2d(nd,eps,zk,ns,sources,ifcharge,charge,\n 1 ifdipole,dipstr,dipvec,iper,ifpgh,pot,grad,hess,\n 2 nt,targ,ifpghtarg,pottarg,gradtarg,\n 3 hesstarg,ier)\n return\n end\n\n\nc------------------------------- \n\n subroutine hfmm2d_st_d_p(eps,zk,ns,sources,\n 1 dipstr,dipvec,pot,nt,targ,pottarg,ier)\ncf2py intent(in) eps\ncf2py intent(in) zk\ncf2py intent(in) ns,sources,dipstr,dipvec,nt,targ\ncf2py intent(out) pot,pottarg,ier\n\nc----------------------------------------------\nc INPUT PARAMETERS:\nc eps : FMM precision requested\nc zk : Helmholtz parameter\nc ns : number of sources\nc sources(2,ns) : source locations\nc dipstr(ns) : dipole strengths\nc dipvec(2,ns) : dipole orientation vectors\nc nt : number of targets\nc targ(2,nt) : target locations\nc\nc OUTPUT PARAMETERS\nc pot(ns) : potential at the source locations\nc pottarg(nt) : potential at the target locations\nc\n\n\n implicit none\nc\ncc calling sequence variables\nc \n real *8 eps\n complex *16 zk\n integer ns,nt,ier\n real *8 sources(2,ns),targ(2,nt)\n real *8 dipvec(2,ns)\n complex *16 dipstr(ns)\n\n complex *16 pot(ns)\n complex *16 pottarg(nt)\n\nc\ncc temporary variables\nc\n complex *16 charge\n complex *16 grad(2),gradtarg(2)\n complex *16 hess(3),hesstarg(3)\n integer ifcharge,ifdipole,iper\n integer ifpgh,ifpghtarg\n\n integer nd\n\n ifcharge = 0\n ifdipole = 1\n \n ifpgh = 1\n ifpghtarg = 1\n\n nd = 1\n\n call hfmm2d(nd,eps,zk,ns,sources,ifcharge,charge,\n 1 ifdipole,dipstr,dipvec,iper,ifpgh,pot,grad,hess,\n 2 nt,targ,ifpghtarg,pottarg,gradtarg,\n 3 hesstarg,ier)\n return\n end\nc------------------------------\n\n\n subroutine hfmm2d_st_d_g(eps,zk,ns,sources,\n 1 dipstr,dipvec,pot,grad,nt,targ,pottarg,gradtarg,ier)\ncf2py intent(in) eps\ncf2py intent(in) zk\ncf2py intent(in) ns,sources,dipstr,dipvec,nt,targ\ncf2py intent(out) pot,pottarg,grad,gradtarg,ier\n\nc----------------------------------------------\nc INPUT PARAMETERS:\nc eps : FMM precision requested\nc zk : Helmholtz parameter\nc ns : number of sources\nc sources(2,ns) : source locations\nc dipstr(ns) : dipole strengths\nc dipvec(2,ns) : dipole orientation vectors\nc nt : number of targets\nc targ(2,nt) : target locations\nc\nc OUTPUT PARAMETERS\nc pot(ns) : potential at the source locations\nc grad(2,ns) : gradients at the source locations\nc pottarg(nt) : potential at the target locations\nc gradtarg(2,nt): gradient at the target locations\nc\n\n\n implicit none\nc\ncc calling sequence variables\nc \n real *8 eps\n complex *16 zk\n integer ns,nt,ier\n real *8 sources(2,ns),targ(2,nt)\n real *8 dipvec(2,ns)\n complex *16 dipstr(ns)\n\n complex *16 pot(ns),grad(2,ns)\n complex *16 pottarg(nt),gradtarg(2,nt)\n\nc\ncc temporary variables\nc\n complex *16 charge\n complex *16 hess(3),hesstarg(3)\n integer ifcharge,ifdipole,iper\n integer ifpgh,ifpghtarg\n integer nd\n\n ifcharge = 0\n ifdipole = 1\n \n ifpgh = 2\n ifpghtarg = 2\n\n nd = 1\n\n call hfmm2d(nd,eps,zk,ns,sources,ifcharge,charge,\n 1 ifdipole,dipstr,dipvec,iper,ifpgh,pot,grad,hess,\n 2 nt,targ,ifpghtarg,pottarg,gradtarg,\n 3 hesstarg,ier)\n return\n end\nc------------------------------\nc\nc\nc\nc\nc\n subroutine hfmm2d_st_d_h(eps,zk,ns,sources,\n 1 dipstr,dipvec,pot,grad,hess,nt,targ,pottarg,\n 2 gradtarg,hesstarg,ier)\ncf2py intent(in) eps\ncf2py intent(in) zk\ncf2py intent(in) ns,sources,dipstr,dipvec,nt,targ\ncf2py intent(out) pot,pottarg,grad,gradtarg,hess,hesstarg,ier\n\nc----------------------------------------------\nc INPUT PARAMETERS:\nc eps : FMM precision requested\nc zk : Helmholtz parameter\nc ns : number of sources\nc sources(2,ns) : source locations\nc dipstr(ns) : dipole strengths\nc dipvec(2,ns) : dipole orientation vectors\nc nt : number of targets\nc targ(2,nt) : target locations\nc\nc OUTPUT PARAMETERS\nc pot(ns) : potential at the source locations\nc grad(2,ns) : gradients at the source locations\nc hess(3,ns) : hessian at the source locations\nc pottarg(nt) : potential at the target locations\nc gradtarg(2,nt): gradient at the target locations\nc hesstarg(3,nt): hessian at the target locations\nc\n\n\n implicit none\nc\ncc calling sequence variables\nc \n real *8 eps\n complex *16 zk\n integer ns,nt,ier\n real *8 sources(2,ns),targ(2,nt)\n real *8 dipvec(2,ns)\n complex *16 dipstr(ns)\n\n complex *16 pot(ns),grad(2,ns),hess(3,ns)\n complex *16 pottarg(nt),gradtarg(2,nt),hesstarg(3,nt)\n\nc\ncc temporary variables\nc\n complex *16 charge\n integer ifcharge,ifdipole,iper\n integer ifpgh,ifpghtarg\n integer nd\n\n ifcharge = 0\n ifdipole = 1\n \n ifpgh = 3\n ifpghtarg = 3\n\n nd = 1\n\n call hfmm2d(nd,eps,zk,ns,sources,ifcharge,charge,\n 1 ifdipole,dipstr,dipvec,iper,ifpgh,pot,grad,hess,\n 2 nt,targ,ifpghtarg,pottarg,gradtarg,\n 3 hesstarg,ier)\n return\n end\n\n\nc------------------------------- \n\n subroutine hfmm2d_st_cd_p(eps,zk,ns,sources,charge,\n 1 dipstr,dipvec,pot,nt,targ,pottarg,ier)\ncf2py intent(in) eps\ncf2py intent(in) zk\ncf2py intent(in) ns,sources,charge,dipstr,dipvec,nt,targ\ncf2py intent(out) pot,pottarg,ier\n\nc----------------------------------------------\nc INPUT PARAMETERS:\nc eps : FMM precision requested\nc zk : Helmholtz parameter\nc ns : number of sources\nc sources(2,ns) : source locations\nc charge(ns) : charge strengths\nc dipstr(ns) : dipole strengths\nc dipvec(2,ns) : dipole orientation vectors\nc nt : number of targets\nc targ(2,nt) : target locations\nc\nc OUTPUT PARAMETERS\nc pot(ns) : potential at the source locations\nc pottarg(nt) : potential at the target locations\nc\n\n\n implicit none\nc\ncc calling sequence variables\nc \n real *8 eps\n complex *16 zk\n integer ns,nt,ier\n real *8 sources(2,ns),targ(2,nt)\n real *8 dipvec(2,ns)\n complex *16 charge(ns),dipstr(ns)\n\n complex *16 pot(ns)\n complex *16 pottarg(nt)\n\nc\ncc temporary variables\nc\n complex *16 grad(2),gradtarg(2)\n complex *16 hess(3),hesstarg(3)\n integer ifcharge,ifdipole,iper\n integer ifpgh,ifpghtarg\n\n integer nd\n\n ifcharge = 1\n ifdipole = 1\n \n ifpgh = 1\n ifpghtarg = 1\n\n nd = 1\n\n call hfmm2d(nd,eps,zk,ns,sources,ifcharge,charge,\n 1 ifdipole,dipstr,dipvec,iper,ifpgh,pot,grad,hess,\n 2 nt,targ,ifpghtarg,pottarg,gradtarg,\n 3 hesstarg,ier)\n return\n end\nc------------------------------\nc\nc\nc\nc\n\n subroutine hfmm2d_st_cd_g(eps,zk,ns,sources,charge,\n 1 dipstr,dipvec,pot,grad,nt,targ,pottarg,gradtarg,ier)\ncf2py intent(in) eps\ncf2py intent(in) zk\ncf2py intent(in) ns,sources,charge,dipstr,dipvec,nt,targ\ncf2py intent(out) pot,pottarg,grad,gradtarg,ier\n\nc----------------------------------------------\nc INPUT PARAMETERS:\nc eps : FMM precision requested\nc zk : Helmholtz parameter\nc ns : number of sources\nc sources(2,ns) : source locations\nc charge(ns) : charge strengths\nc dipstr(ns) : dipole strengths\nc dipvec(2,ns) : dipole orientation vectors\nc nt : number of targets\nc targ(2,nt) : target locations\nc\nc OUTPUT PARAMETERS\nc pot(ns) : potential at the source locations\nc grad(2,ns) : gradients at the source locations\nc pottarg(nt) : potential at the target locations\nc gradtarg(2,nt): gradient at the target locations\nc\n\n implicit none\nc\ncc calling sequence variables\nc \n real *8 eps\n complex *16 zk\n integer ns,nt,ier\n real *8 sources(2,ns),targ(2,nt)\n real *8 dipvec(2,ns)\n complex *16 charge(ns),dipstr(ns)\n\n complex *16 pot(ns),grad(2,ns)\n complex *16 pottarg(nt),gradtarg(2,nt)\n\nc\ncc temporary variables\nc\n complex *16 hess(3),hesstarg(3)\n integer ifcharge,ifdipole,iper\n integer ifpgh,ifpghtarg\n integer nd\n\n ifcharge = 1\n ifdipole = 1\n \n ifpgh = 2\n ifpghtarg = 2\n\n nd = 1\n\n call hfmm2d(nd,eps,zk,ns,sources,ifcharge,charge,\n 1 ifdipole,dipstr,dipvec,iper,ifpgh,pot,grad,hess,\n 2 nt,targ,ifpghtarg,pottarg,gradtarg,\n 3 hesstarg,ier)\n return\n end\nc------------------------------\nc\nc\nc\nc\nc\n subroutine hfmm2d_st_cd_h(eps,zk,ns,sources,charge,\n 1 dipstr,dipvec,pot,grad,hess,nt,targ,pottarg,\n 2 gradtarg,hesstarg,ier)\ncf2py intent(in) eps\ncf2py intent(in) zk\ncf2py intent(in) ns,sources,charge,dipstr,dipvec,nt,targ\ncf2py intent(out) pot,pottarg,grad,gradtarg,hess,hesstarg,ier\n\nc----------------------------------------------\nc INPUT PARAMETERS:\nc eps : FMM precision requested\nc zk : Helmholtz parameter\nc ns : number of sources\nc sources(2,ns) : source locations\nc charge(ns) : charge strengths\nc dipstr(ns) : dipole strengths\nc dipvec(2,ns) : dipole orientation vectors\nc nt : number of targets\nc targ(2,nt) : target locations\nc\nc OUTPUT PARAMETERS\nc pot(ns) : potential at the source locations\nc grad(2,ns) : gradients at the source locations\nc hess(3,ns) : hessian at the source locations\nc pottarg(nt) : potential at the target locations\nc gradtarg(2,nt): gradient at the target locations\nc hesstarg(3,nt): hessian at the target locations\nc\n\n\n implicit none\nc\ncc calling sequence variables\nc \n real *8 eps\n complex *16 zk\n integer ns,nt,ier\n real *8 sources(2,ns),targ(2,nt)\n real *8 dipvec(2,ns)\n complex *16 charge(ns),dipstr(ns)\n\n complex *16 pot(ns),grad(2,ns),hess(3,ns)\n complex *16 pottarg(nt),gradtarg(2,nt),hesstarg(3,nt)\n\nc\ncc temporary variables\nc\n integer ifcharge,ifdipole,iper\n integer ifpgh,ifpghtarg\n integer nd\n\n ifcharge = 1\n ifdipole = 1\n \n ifpgh = 3\n ifpghtarg = 3\n\n nd = 1\n\n call hfmm2d(nd,eps,zk,ns,sources,ifcharge,charge,\n 1 ifdipole,dipstr,dipvec,iper,ifpgh,pot,grad,hess,\n 2 nt,targ,ifpghtarg,pottarg,gradtarg,\n 3 hesstarg,ier)\n return\n end\n\n", "meta": {"hexsha": "89d34690b81e1a948cb36332f7d7b6300f7c570c", "size": 45561, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/helmholtz/hfmm2dwrap.f", "max_stars_repo_name": "lu1and10/fmm2d", "max_stars_repo_head_hexsha": "a7450e271a794760676d8d9ea692562ce329e2de", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2020-12-22T16:01:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-01T05:47:18.000Z", "max_issues_repo_path": "src/helmholtz/hfmm2dwrap.f", "max_issues_repo_name": "lu1and10/fmm2d", "max_issues_repo_head_hexsha": "a7450e271a794760676d8d9ea692562ce329e2de", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-12-15T16:25:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-21T21:03:32.000Z", "max_forks_repo_path": "src/helmholtz/hfmm2dwrap.f", "max_forks_repo_name": "lu1and10/fmm2d", "max_forks_repo_head_hexsha": "a7450e271a794760676d8d9ea692562ce329e2de", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2020-12-23T04:45:28.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-15T18:09:44.000Z", "avg_line_length": 24.3381410256, "max_line_length": 72, "alphanum_fraction": 0.5839424069, "num_tokens": 14550, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772384450967, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6598540021624316}} {"text": "program demo_stats_randu\n\n use forlab_stats, only: randu\n\n print *, \"running `demo_stats_randu`..\"\n\n print *, randu(start=1, end=2)\n print *, randu(start=1.0, end=2.0, ndim=3)\n print *, reshape(randu(1.0, 2.0, 2*2), [2,2])\n\n !> Possible output:\n\n !! 2\n !! 1.65676987 1.11625218 1.03502560\n !! 1.74973476 1.82997108 1.77998054 1.14384007\n\nend program demo_stats_randu", "meta": {"hexsha": "f2d9c88ff807e365dbe5fd15743a8334b9b5ca27", "size": 423, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/stats/demo_stats_randu.f90", "max_stars_repo_name": "zoziha/forlab_z", "max_stars_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2021-08-31T15:23:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T02:44:46.000Z", "max_issues_repo_path": "example/stats/demo_stats_randu.f90", "max_issues_repo_name": "zoziha/forlab_z", "max_issues_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-08-22T11:47:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-31T00:57:16.000Z", "max_forks_repo_path": "example/stats/demo_stats_randu.f90", "max_forks_repo_name": "zoziha/forlab_z", "max_forks_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-07-16T03:16:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-31T13:09:42.000Z", "avg_line_length": 24.8823529412, "max_line_length": 68, "alphanum_fraction": 0.5933806147, "num_tokens": 161, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424528443251, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.6598291115684345}} {"text": "\nmodule gamblers\n\n implicit none\n integer :: kwalks, max_steps\n save\n\ncontains\n\n subroutine walk(n1in, n2in, p, verbose, nsteps, winner)\n\n implicit none\n integer, intent(in) :: n1in,n2in\n real(kind=8), intent(in) :: p\n logical, intent(in) :: verbose\n integer, intent(out) :: nsteps, winner\n\n ! local variables\n real(kind=8) :: r\n integer :: nstep, n1, n2\n\n ! initialize n1 and n2 with input values\n ! need to change n1 and n2 internally during this walk but do not\n ! want to affect n1 and n2 in main program. \n n1 = n1in\n n2 = n2in\n\n ! CONTINUE WRITING THIS SUBROUTINE....\n\n end subroutine walk\n\nend module gamblers\n", "meta": {"hexsha": "f4dabb4d50c53ca46a96210c2fbe2159494a6f02", "size": 674, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/homeworks/homework4/part2/gamblers.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/homeworks/homework4/part2/gamblers.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/homeworks/homework4/part2/gamblers.f90", "max_forks_repo_name": "philipwangdk/HPC", "max_forks_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.4242424242, "max_line_length": 69, "alphanum_fraction": 0.6454005935, "num_tokens": 204, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7799929002541068, "lm_q2_score": 0.8459424334245618, "lm_q1q2_score": 0.6598290920948406}} {"text": " LOGICAL FUNCTION DTLEAP (YEAR)\r\n IMPLICIT NONE\r\n\r\n* FORMAL_PARAMETERS:\r\n INTEGER YEAR\r\n\r\n** no local variables\r\n SAVE\r\n\r\n DTLEAP = MOD (YEAR,4).EQ.0\r\n IF (MOD (YEAR,100).EQ.0) DTLEAP = .FALSE.\r\n IF (MOD (YEAR,400).EQ.0) DTLEAP = .TRUE.\r\n\r\n RETURN\r\n END\r\n\r\n", "meta": {"hexsha": "75865d64342bc004092510b0b64e477cc3436988", "size": 309, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "tests/data/program_analysis/DSSAT/CSM/dtleap.for", "max_stars_repo_name": "mikiec84/delphi", "max_stars_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2018-03-03T11:57:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-16T21:19:54.000Z", "max_issues_repo_path": "tests/data/program_analysis/DSSAT/CSM/dtleap.for", "max_issues_repo_name": "mikiec84/delphi", "max_issues_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 385, "max_issues_repo_issues_event_min_datetime": "2018-02-21T16:52:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-17T07:44:56.000Z", "max_forks_repo_path": "tests/data/program_analysis/DSSAT/CSM/dtleap.for", "max_forks_repo_name": "mikiec84/delphi", "max_forks_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2018-03-20T01:08:11.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-29T01:04:49.000Z", "avg_line_length": 18.1764705882, "max_line_length": 48, "alphanum_fraction": 0.5242718447, "num_tokens": 95, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. Yes\n2. Yes", "lm_q1_score": 0.7799928797973181, "lm_q2_score": 0.8459424411924673, "lm_q1q2_score": 0.659829080848486}} {"text": "! Calculate velocity magnitude from momenta and density. NOTE the resulting units are km/s, NOT cm/s.\n\nsubroutine calc_abs_v(xmom, ymom, zmom, mom_ng, density, density_ng, lo, hi, abs_v)\n use, intrinsic :: iso_c_binding\n implicit none\n\n integer(c_int), intent(in) :: lo(3), hi(3), mom_ng, density_ng\n real(c_double), intent(in) :: xmom (lo(1)-mom_ng:hi(1)+mom_ng, &\n lo(2)-mom_ng:hi(2)+mom_ng, &\n lo(3)-mom_ng:hi(3)+mom_ng, 1)\n real(c_double), intent(in) :: ymom (lo(1)-mom_ng:hi(1)+mom_ng, &\n lo(2)-mom_ng:hi(2)+mom_ng, &\n lo(3)-mom_ng:hi(3)+mom_ng, 1)\n real(c_double), intent(in) :: zmom (lo(1)-mom_ng:hi(1)+mom_ng, &\n lo(2)-mom_ng:hi(2)+mom_ng, &\n lo(3)-mom_ng:hi(3)+mom_ng, 1)\n real(c_double), intent(in) :: density (lo(1)-density_ng:hi(1)+density_ng, &\n lo(2)-density_ng:hi(2)+density_ng, &\n lo(3)-density_ng:hi(3)+density_ng, 1)\n\n real(c_double), intent(out) :: abs_v(lo(1)-mom_ng:hi(1)+mom_ng, &\n lo(2)-mom_ng:hi(2)+mom_ng, &\n lo(3)-mom_ng:hi(3)+mom_ng, 1)\n\n integer :: i, j, k\n real(c_double) :: xvel, yvel, zvel\n\n do k = lo(3), hi(3)\n do j = lo(2), hi(2)\n do i = lo(1), hi(1)\n xvel = xmom(i, j, k, 1) / density(i, j, k, 1)\n yvel = ymom(i, j, k, 1) / density(i, j, k, 1)\n zvel = zmom(i, j, k, 1) / density(i, j, k, 1)\n\n ! NOTE: THE UNITS ARE KM/S, NOT CM/S\n abs_v(i, j, k, 1) = sqrt(xvel*xvel + yvel*yvel + zvel*zvel)\n end do\n end do\n end do\nend subroutine calc_abs_v\n", "meta": {"hexsha": "00f86d0a19d5da2cc7d2de9beffffb21f81af140", "size": 1817, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "calc_abs_v.f90", "max_stars_repo_name": "bcfriesen/gimlet", "max_stars_repo_head_hexsha": "153771cfb5bf810e4f1ca9a8ec4549935a51320a", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-12-14T16:19:12.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-14T16:19:12.000Z", "max_issues_repo_path": "calc_abs_v.f90", "max_issues_repo_name": "bcfriesen/gimlet", "max_issues_repo_head_hexsha": "153771cfb5bf810e4f1ca9a8ec4549935a51320a", "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": "calc_abs_v.f90", "max_forks_repo_name": "bcfriesen/gimlet", "max_forks_repo_head_hexsha": "153771cfb5bf810e4f1ca9a8ec4549935a51320a", "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": 44.3170731707, "max_line_length": 101, "alphanum_fraction": 0.4821133737, "num_tokens": 590, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970873650401, "lm_q2_score": 0.7490872187162397, "lm_q1q2_score": 0.6597938404276428}} {"text": " FUNCTION FHYDCN(VOID,BMECH4,BMECH5,BMECH6,IBMECHK) \n INTEGER::IBMECHK\n REAL::FHYDCN,BMECH4,TMP,VOID,BMECH5,BMECH6,FHYDCNLOG \nC CHANGE RECORD \nC ADDED STANDARD EXPONENTIAL FORM CONSTITUTIVE RELATIONSHIP \nC \nC \nC ** FHYDCN IS HYDRAULIC CONDUCTIVITY DIVIDED BY 1+VOID RATIO \nC \n IF(BMECH4.GT.0.0)THEN \n TMP=(VOID-BMECH5)/BMECH6 \n IF(IBMECHK.EQ.0) THEN \n FHYDCN=BMECH4*EXP(TMP)/(1.+VOID) \n ELSE \n FHYDCN=BMECH4*EXP(TMP) \n END IF \n ELSE \n FHYDCNLOG=0.00816448*(VOID**3)-0.232453*(VOID**2)+2.5759*VOID \n & -28.581 \n FHYDCN=EXP(FHYDCNLOG) \n END IF \n RETURN \n END \n\n", "meta": {"hexsha": "efa8731be6849a45d399d7ef91bf5a7c0a1334d6", "size": 692, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "EFDC_src/FHYDCN.f", "max_stars_repo_name": "T-Carlotto/SW2D-EFDC", "max_stars_repo_head_hexsha": "7b01a41a308cb79db569a0e6291fe40797f3ef28", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 32, "max_stars_repo_stars_event_min_datetime": "2018-03-31T22:19:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-14T01:35:23.000Z", "max_issues_repo_path": "EFDC_src/FHYDCN.f", "max_issues_repo_name": "T-Carlotto/SW2D-EFDC", "max_issues_repo_head_hexsha": "7b01a41a308cb79db569a0e6291fe40797f3ef28", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-04-02T06:13:13.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-10T07:15:07.000Z", "max_forks_repo_path": "EFDC_src/FHYDCN.f", "max_forks_repo_name": "T-Carlotto/SW2D-EFDC", "max_forks_repo_head_hexsha": "7b01a41a308cb79db569a0e6291fe40797f3ef28", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2018-06-27T02:55:23.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-09T07:51:23.000Z", "avg_line_length": 27.68, "max_line_length": 71, "alphanum_fraction": 0.5852601156, "num_tokens": 266, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741295151718, "lm_q2_score": 0.6926419831347362, "lm_q1q2_score": 0.6597928341502337}} {"text": "program Montecarlo\n implicit none\n\n integer :: total_points\n real :: calculate_pi\n real :: pi\n\n print*, \"Enter the total amount of points for the calculation...\"\n read*, total_points\n\n pi = calculate_pi(total_points)\n\n write(*,*) 'PI = ', pi\nend\n\nreal function calculate_pi(p)\n integer :: p\n real in_area, x, y\n\n in_area = 0\n x = 0\n y = 0\n\n do i=1,p\n x = rand(0)\n y = rand(0)\n z = calculate_z(x,y)\n if (z .le. 1.) then\n in_area = in_area + 1\n write(*,*) 'In Area = ', in_area, 'X = ', x, ' Y = ', y, ' Z = ', z\n else\n write(*,*) 'NOT In Area = X = ', x, ' Y = ', y, ' Z = ', z\n end if\n enddo\n\n calculate_pi = 4 * (p / in_area)\n\n return\nend\n\nreal function calculate_z(x,y)\n real :: x, y\n real :: square_x, square_y\n square_x = x**2\n square_y = y**2\n calculate_z = sqrt(square_x + square_y)\nend\n", "meta": {"hexsha": "d45fe61e7748ceda0bae33704c593354bf3dd82d", "size": 1002, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "PSP01/montecarlo.f", "max_stars_repo_name": "locorider/zhaw_fs2015_psp", "max_stars_repo_head_hexsha": "4ea52ea9e98abc649c5037e8e0694d779230254b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "PSP01/montecarlo.f", "max_issues_repo_name": "locorider/zhaw_fs2015_psp", "max_issues_repo_head_hexsha": "4ea52ea9e98abc649c5037e8e0694d779230254b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "PSP01/montecarlo.f", "max_forks_repo_name": "locorider/zhaw_fs2015_psp", "max_forks_repo_head_hexsha": "4ea52ea9e98abc649c5037e8e0694d779230254b", "max_forks_repo_licenses": ["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.875, "max_line_length": 83, "alphanum_fraction": 0.4790419162, "num_tokens": 296, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037384317887, "lm_q2_score": 0.7122321720225279, "lm_q1q2_score": 0.6597433235758604}} {"text": "PROGRAM temp_avgs\nIMPLICIT NONE\nCHARACTER(LEN=80) :: msg\nINTEGER :: status, i, j\nREAL, DIMENSION(6, 6) :: t\n\nOPEN(UNIT=1, FILE=\"temps.txt\", STATUS='OLD', ACTION='READ', &\n IOSTAT=status, IOMSG=msg)\nREAD(1, *) t\nWRITE(*, *) \"Temperature Readings:\"\nWRITE(*, '(6F6.1)') ((t(i, j), j=1, 6), i=1, 6)\nWRITE(*, *) \"Latitute Averages:\"\nWRITE(*, '(6F6.1)') (SUM(t(i,1:6)) / 6., i = 1, 6)\nWRITE(*, *) \"Longitute Averages:\"\nWRITE(*, '(6F6.1)') (SUM(t(1:6,i)) / 6., i = 1, 6)\nCLOSE(1)\nEND PROGRAM temp_avgs\n", "meta": {"hexsha": "d45c8ff5fcd12d4911a56f3a926ce3cd3ca32ac9", "size": 499, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap8/temp_avgs.f90", "max_stars_repo_name": "evanmacbride/fortran-practice", "max_stars_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/chap8/temp_avgs.f90", "max_issues_repo_name": "evanmacbride/fortran-practice", "max_issues_repo_head_hexsha": "1d9d851c35baedf52444db65157bd9a987dec60d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/chap8/temp_avgs.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.7222222222, "max_line_length": 61, "alphanum_fraction": 0.5851703407, "num_tokens": 214, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232809, "lm_q2_score": 0.7577943822145997, "lm_q1q2_score": 0.6597337242597605}} {"text": " SUBROUTINE QTRAP(FUNC,A,B,S)\n PARAMETER (EPS=1.E-6, JMAX=20)\n OLDS=-1.E30\n DO 11 J=1,JMAX\n CALL TRAPZD(FUNC,A,B,S,J)\n IF (ABS(S-OLDS).LT.EPS*ABS(OLDS)) RETURN\n OLDS=S\n11 CONTINUE\n PAUSE 'Too many steps.'\n END\n", "meta": {"hexsha": "a8880c5fddcda770882fa1805877dddf102d31b7", "size": 264, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "Math3/NumRec/source/qtrap.for", "max_stars_repo_name": "domijin/MM3", "max_stars_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Math3/NumRec/source/qtrap.for", "max_issues_repo_name": "domijin/MM3", "max_issues_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Math3/NumRec/source/qtrap.for", "max_forks_repo_name": "domijin/MM3", "max_forks_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.0, "max_line_length": 48, "alphanum_fraction": 0.5378787879, "num_tokens": 101, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8705972684083609, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6597337096469333}} {"text": "\tSUBROUTINE VC_NBTS ( adat, nxy, mxsgdg, nmbts, iret )\nC************************************************************************\nC* VC_NBTS\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This subroutine computes the number of packing bits given the\t*\nC* maximum number of significant digits to preserve.\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* VC_NBTS ( ADAT, NXY, MXSGDG, NMBTS, IRET )\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*\tADAT (NXY)\tREAL\t\tArray of data values\t\t*\nC*\tNXY\t\tINTEGER\t\tNumber of data values\t\t*\nC*\tMXSGDG\t\tINTEGER\t\tMaximum # of significant digits\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tNMBTS\t\tINTEGER\t\tNumber of bits for packing\t*\nC*\tIRET\t\tINTEGER\t\tReturn code\t\t\t*\nC*\t\t\t\t\t 0 = normal return\t\t*\nC*\t\t\t\t\t +1 = all missing\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* K. Brill/NMC\t\t06/92\t\t\t\t\t\t*\nC* K. Brill/NMC\t\t08/92\tAdd all missing check\t\t\t*\nC* J. Wu/GSC 07/00 Moved INCLUDE 'ERMISS.FNC' before the * \nC* DATA statement *\nC************************************************************************\n\tINCLUDE\t\t'GEMPRM.PRM'\n\tREAL\t\tadat (*)\nC*\n\tINCLUDE\t\t'ERMISS.FNC'\n\tDATA\t\trln2/0.69314718/\nC-----------------------------------------------------------------------\n\tiret = 0\n\ticnt = 0\nC\nC*\tFind the maximum and minimum.\nC\n\tamax = -1.e33\n\tamin = 1.e33\n\tDO i = 1, nxy\n\t IF ( .not. ERMISS ( adat (i) ) ) THEN\n\t\tIF ( adat (i) .gt. amax ) amax = adat (i)\n\t\tIF ( adat (i) .lt. amin ) amin = adat (i)\n\t ELSE\n\t\ticnt = icnt + 1\n\t END IF\n\tEND DO\n\tIF ( icnt .eq. nxy ) THEN\n\t nmbts = 8\n\t iret = +1\n\t RETURN\n\tEND IF\n\trange = amax - amin\n\tIF ( range .le. 0.00 ) THEN\n\t nmbts = 8\n\t RETURN\n\tEND IF\n\tipo = INT ( ALOG10 ( range ) )\n\tIF ( range .lt. 1.00 ) ipo = ipo - 1\n\tipo = ipo - mxsgdg + 1\n\trr = range * 10. ** ( -ipo )\n\tnmbts = INT ( ALOG ( rr ) / rln2 ) + 1\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "de7c0e92abc3b311d7ad6f732d4bcc1066e2fa0f", "size": 1833, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/programs/gd/gdvint/vcnbts.f", "max_stars_repo_name": "oxelson/gempak", "max_stars_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2015-06-03T15:26:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T22:36:03.000Z", "max_issues_repo_path": "gempak/source/programs/gd/gdvint/vcnbts.f", "max_issues_repo_name": "oxelson/gempak", "max_issues_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 60, "max_issues_repo_issues_event_min_datetime": "2015-05-11T21:36:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T16:22:42.000Z", "max_forks_repo_path": "gempak/source/programs/gd/gdvint/vcnbts.f", "max_forks_repo_name": "oxelson/gempak", "max_forks_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 27, "max_forks_repo_forks_event_min_datetime": "2016-06-06T21:55:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T18:23:28.000Z", "avg_line_length": 27.7727272727, "max_line_length": 75, "alphanum_fraction": 0.4789961811, "num_tokens": 657, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972583359806, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6597337067762895}} {"text": " function inverf(x)\n!***********************************************************************\n! $Id: inverf.f,v 1.1 2006/05/17 15:23:22 zvd Exp $\n!***********************************************************************\n! Copyright, 2004, The Regents of the University of California.\n! This program was prepared by the Regents of the University of \n! California at Los Alamos National Laboratory (the University) under \n! contract No. W-7405-ENG-36 with the U.S. Department of Energy (DOE). \n! All rights in the program are reserved by the DOE and the University. \n! Permission is granted to the public to copy and use this software \n! without charge, provided that this Notice and any statement of \n! authorship are reproduced on all copies. Neither the U.S. Government \n! nor the University makes any warranty, express or implied, or \n! assumes any liability or responsibility for the use of this software.\n!***********************************************************************\n!\n! PURPOSE\n!\n! This subroutine calculates the inverse of the error function\n! for a value of x between 0 and 1. It does so using linear \n! interpolation between chosen values of the erf(x) curve.\n!\n!***********************************************************************\n!\n! Initial implementation: 03/16/95, Programmer: B. Robinson\n! for FEHM V1.0\n!\n!***********************************************************************\n\n implicit none\n\n integer i\n real inverf,ef(8),a(8),b(8), x\n data ef/.2227,.42839,.60386,.79691,.91031,.97635,.99532,1./\n data a/.8980691,.972337,-1.255877,-1.033911,-0.8452046,\n + -0.6909501,-0.5685161,-0.4299497/\n data b/0.,-1.653945e-2,9.494722e-2,0.1842109,0.3148551,0.476399,\n + 0.6754972,0.9983227/\n\n if(x.lt.0.) x=-x\n if(x.gt.1.) then\n write(6,110)\n 110 format(1x,'value of x greater than 1')\n return\n end if\n do i=1,2\n if(x.lt.ef(i)) then\n inverf=a(i)*x+b(i)\n return\n end if\n enddo\n do i=3,7\n if(x.lt.ef(i)) goto 11\n enddo\n i=8\n 11 inverf=a(i)*alog10(1.-x)+b(i)\n\n return\n end\n", "meta": {"hexsha": "e53f169ad30e9c9a8b88979058cc7a8b84a423cb", "size": 2182, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/inverf.f", "max_stars_repo_name": "lanl/PLUMECALC", "max_stars_repo_head_hexsha": "70a15749a1f21b8d4289d696a401b283265d49a9", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-03-19T07:37:40.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-10T11:35:29.000Z", "max_issues_repo_path": "src/inverf.f", "max_issues_repo_name": "lanl/PLUMECALC", "max_issues_repo_head_hexsha": "70a15749a1f21b8d4289d696a401b283265d49a9", "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/inverf.f", "max_forks_repo_name": "lanl/PLUMECALC", "max_forks_repo_head_hexsha": "70a15749a1f21b8d4289d696a401b283265d49a9", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-01-12T12:55:43.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-19T07:37:40.000Z", "avg_line_length": 36.3666666667, "max_line_length": 73, "alphanum_fraction": 0.5311640697, "num_tokens": 605, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972549785201, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6597337042320249}} {"text": " Program dgbcon_example\n\n! DGBCON Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_interfaces, Only: dgbcon, dgbtrf, dlangb\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nin = 5, nout = 6\n Character (1), Parameter :: norm = '1'\n! .. Local Scalars ..\n Real (Kind=dp) :: anorm, rcond\n Integer :: i, info, j, k, kl, ku, ldab, n\n! .. Local Arrays ..\n Real (Kind=dp), Allocatable :: ab(:, :), work(:)\n Integer, Allocatable :: ipiv(:), iwork(:)\n! .. Intrinsic Procedures ..\n Intrinsic :: epsilon, max, min\n! .. Executable Statements ..\n Write (nout, *) 'DGBCON Example Program Results'\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n, kl, ku\n ldab = 2*kl + ku + 1\n Allocate (ab(ldab,n), work(3*n), ipiv(n), iwork(n))\n\n! Read A from data file\n\n k = kl + ku + 1\n Read (nin, *)((ab(k+i-j,j),j=max(i-kl,1),min(i+ku,n)), i=1, n)\n\n! Compute norm of A\n anorm = dlangb(norm, n, kl, ku, ab(kl+1,1), ldab, work)\n\n! Factorize A\n\n Call dgbtrf(n, n, kl, ku, ab, ldab, ipiv, info)\n\n Write (nout, *)\n If (info==0) Then\n\n! Estimate condition number\n\n Call dgbcon(norm, n, kl, ku, ab, ldab, ipiv, anorm, rcond, work, &\n iwork, info)\n\n If (rcond>=epsilon(1.0E0_dp)) Then\n Write (nout, 100) 'Estimate of condition number =', 1.0_dp/rcond\n Else\n Write (nout, *) 'A is singular to working precision'\n End If\n Else\n Write (nout, *) 'The factor U is singular'\n End If\n\n100 Format (1X, A, 1P, E10.2)\n End Program\n", "meta": {"hexsha": "2d12a84ae2a6028b76ab42017a145d78340cb00f", "size": 1895, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/dgbcon_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/dgbcon_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/dgbcon_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 29.609375, "max_line_length": 90, "alphanum_fraction": 0.563060686, "num_tokens": 604, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972549785203, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6597336994698757}} {"text": "************************************************************************\r\n*\r\n* Subroutine PCTL\r\n*\r\n* Called by: INPUTE,OUTHEAD,OUTSUMM2,OUTSUMM3,OUTSUMMC\r\n*\r\n* calculate the minimum and maximum values, and 10th, 25th, 50th,\r\n* 75th, 90th, 95th, and 99th percentiles\r\n*\r\n* Local variable\r\n* --------------\r\n* X2 copy of X sorted in ascending order\r\n*\r\n************************************************************************\r\n SUBROUTINE PCTL(X,NUM,XMIN,P10,P25,P50,P75,P90,P95,P99,XMAX)\r\n*\r\n* subroutine arguments\r\n*\r\n INTEGER*4 NUM \r\n DOUBLE PRECISION XMIN,P10,P25,P50,P75,P90,P95,P99,XMAX\r\n DOUBLE PRECISION X(*)\r\n*\r\n* local vars\r\n*\r\n INTEGER*4 I\r\n DOUBLE PRECISION X2(NUM)\r\n*\r\n* function declaration\r\n*\r\n DOUBLE PRECISION PTILE\r\n*\r\n* create copy of X and sort [all operations are done on the copy\r\n* (X2) so that X is passed back to the calling program unaltered]\r\n*\r\n DO 10 I = 1,NUM\r\n X2(I) = X(I)\r\n 10 CONTINUE\r\n CALL SORT(X2,NUM)\r\n*\r\n* the minimum and maximum values correspond to the first and last\r\n* elements of X2\r\n*\r\n XMIN = X2(1)\r\n XMAX = X2(NUM)\r\n*\r\n* set percentiles\r\n*\r\n*\r\n P10 = PTILE(X2,NUM,0.10D0)\r\n P25 = PTILE(X2,NUM,0.25D0)\r\n P50 = PTILE(X2,NUM,0.50D0)\r\n P75 = PTILE(X2,NUM,0.75D0)\r\n P90 = PTILE(X2,NUM,0.90D0)\r\n P95 = PTILE(X2,NUM,0.95D0)\r\n P99 = PTILE(X2,NUM,0.99D0)\r\n\r\n RETURN\r\n END\r\n", "meta": {"hexsha": "0ad61f633d8170e428f37a7556730f424a9a2fe8", "size": 1485, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "codeNexampls/[loadest]/loadsrc/loadest/source_USGS/pctl.f", "max_stars_repo_name": "lthiamodelers/baseflow-coefficients", "max_stars_repo_head_hexsha": "183fef49548fa2e1bf0bb8cff57e96e75d629760", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "codeNexampls/[loadest]/loadsrc/loadest/source_USGS/pctl.f", "max_issues_repo_name": "lthiamodelers/baseflow-coefficients", "max_issues_repo_head_hexsha": "183fef49548fa2e1bf0bb8cff57e96e75d629760", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "codeNexampls/[loadest]/loadsrc/loadest/source_USGS/pctl.f", "max_forks_repo_name": "lthiamodelers/baseflow-coefficients", "max_forks_repo_head_hexsha": "183fef49548fa2e1bf0bb8cff57e96e75d629760", "max_forks_repo_licenses": ["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.1694915254, "max_line_length": 73, "alphanum_fraction": 0.5131313131, "num_tokens": 459, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972549785201, "lm_q2_score": 0.757794360334681, "lm_q1q2_score": 0.6597336899455768}} {"text": " SUBROUTINE fixrts(d,m)\r\n INTEGER m,MMAX\r\n REAL d(m)\r\n PARAMETER (MMAX=100)\r\nCU USES zroots\r\n INTEGER i,j\r\n LOGICAL polish\r\n COMPLEX a(MMAX),roots(MMAX)\r\n a(m+1)=cmplx(1.,0.)\r\n do 11 j=m,1,-1\r\n a(j)=cmplx(-d(m+1-j),0.)\r\n11 continue\r\n polish=.true.\r\n call zroots(a,m,roots,polish)\r\n do 12 j=1,m\r\n if(abs(roots(j)).gt.1.)then\r\n roots(j)=1./conjg(roots(j))\r\n endif\r\n12 continue\r\n a(1)=-roots(1)\r\n a(2)=cmplx(1.,0.)\r\n do 14 j=2,m\r\n a(j+1)=cmplx(1.,0.)\r\n do 13 i=j,2,-1\r\n a(i)=a(i-1)-roots(j)*a(i)\r\n13 continue\r\n a(1)=-roots(j)*a(1)\r\n14 continue\r\n do 15 j=1,m\r\n d(m+1-j)=-real(a(j))\r\n15 continue\r\n return\r\n END\r\n", "meta": {"hexsha": "688477d675cb6f61e5c8cde201ff1b0e99aeba91", "size": 784, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/fixrts.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/fixrts.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/fixrts.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.0588235294, "max_line_length": 38, "alphanum_fraction": 0.4579081633, "num_tokens": 285, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582554941719, "lm_q2_score": 0.7090191399336402, "lm_q1q2_score": 0.659712712054633}} {"text": "c\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc . .\nc . copyright (c) 1998 by UCAR .\nc . .\nc . University Corporation for Atmospheric Research .\nc . .\nc . all rights reserved .\nc . .\nc . .\nc . SPHEREPACK3.0 .\nc . .\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc\nc\nc\nc ... file vhagc.f\nc\nc this file contains code and documentation for subroutines\nc vhagc and vhagci\nc\nc ... files which must be loaded with vhagc.f\nc\nc sphcom.f, hrfft.f, gaqd.f\nc\nc \nc subroutine vhagc(nlat,nlon,ityp,nt,v,w,idvw,jdvw,br,bi,cr,ci,\nc + mdab,ndab,wvhagc,lvhagc,work,lwork,ierror)\nc\nc subroutine vhagc performs the vector spherical harmonic analysis\nc on the vector field (v,w) and stores the result in the arrays\nc br,bi,cr, and ci. v(i,j) and w(i,j) are the colatitudinal\nc (measured from the north pole) and east longitudinal components\nc respectively, located at the gaussian colatitude point theta(i)\nc and longitude phi(j) = (j-1)*2*pi/nlon. the spectral\nc representation of (v,w) is given at output parameters v,w in \nc subroutine vhsec. \nc\nc input parameters\nc\nc nlat the number of points in the gaussian colatitude grid on the\nc full sphere. these lie in the interval (0,pi) and are computed\nc in radians in theta(1) <...< theta(nlat) by subroutine gaqd.\nc if nlat is odd the equator will be included as the grid point\nc theta((nlat+1)/2). if nlat is even the equator will be\nc excluded as a grid point and will lie half way between\nc theta(nlat/2) and theta(nlat/2+1). nlat must be at least 3.\nc note: on the half sphere, the number of grid points in the\nc colatitudinal direction is nlat/2 if nlat is even or\nc (nlat+1)/2 if nlat is odd.\nc\nc nlon the number of distinct londitude points. nlon determines\nc the grid increment in longitude as 2*pi/nlon. for example\nc nlon = 72 for a five degree grid. nlon must be greater\nc than zero. the axisymmetric case corresponds to nlon=1.\nc the efficiency of the computation is improved when nlon\nc is a product of small prime numbers.\nc\nc ityp = 0 no symmetries exist about the equator. the analysis\nc is performed on the entire sphere. i.e. on the\nc arrays v(i,j),w(i,j) for i=1,...,nlat and \nc j=1,...,nlon. \nc\nc = 1 no symmetries exist about the equator. the analysis\nc is performed on the entire sphere. i.e. on the\nc arrays v(i,j),w(i,j) for i=1,...,nlat and \nc j=1,...,nlon. the curl of (v,w) is zero. that is, \nc (d/dtheta (sin(theta) w) - dv/dphi)/sin(theta) = 0. \nc the coefficients cr and ci are zero.\nc\nc = 2 no symmetries exist about the equator. the analysis\nc is performed on the entire sphere. i.e. on the\nc arrays v(i,j),w(i,j) for i=1,...,nlat and \nc j=1,...,nlon. the divergence of (v,w) is zero. i.e., \nc (d/dtheta (sin(theta) v) + dw/dphi)/sin(theta) = 0. \nc the coefficients br and bi are zero.\nc\nc = 3 v is symmetric and w is antisymmetric about the \nc equator. the analysis is performed on the northern\nc hemisphere only. i.e., if nlat is odd the analysis\nc is performed on the arrays v(i,j),w(i,j) for \nc i=1,...,(nlat+1)/2 and j=1,...,nlon. if nlat is\nc even the analysis is performed on the the arrays\nc v(i,j),w(i,j) for i=1,...,nlat/2 and j=1,...,nlon.\nc\nc = 4 v is symmetric and w is antisymmetric about the \nc equator. the analysis is performed on the northern\nc hemisphere only. i.e., if nlat is odd the analysis\nc is performed on the arrays v(i,j),w(i,j) for \nc i=1,...,(nlat+1)/2 and j=1,...,nlon. if nlat is\nc even the analysis is performed on the the arrays\nc v(i,j),w(i,j) for i=1,...,nlat/2 and j=1,...,nlon.\nc the curl of (v,w) is zero. that is, \nc (d/dtheta (sin(theta) w) - dv/dphi)/sin(theta) = 0. \nc the coefficients cr and ci are zero.\nc\nc = 5 v is symmetric and w is antisymmetric about the \nc equator. the analysis is performed on the northern\nc hemisphere only. i.e., if nlat is odd the analysis\nc is performed on the arrays v(i,j),w(i,j) for \nc i=1,...,(nlat+1)/2 and j=1,...,nlon. if nlat is\nc even the analysis is performed on the the arrays\nc v(i,j),w(i,j) for i=1,...,nlat/2 and j=1,...,nlon.\nc the divergence of (v,w) is zero. i.e., \nc (d/dtheta (sin(theta) v) + dw/dphi)/sin(theta) = 0. \nc the coefficients br and bi are zero.\nc\nc = 6 v is antisymmetric and w is symmetric about the \nc equator. the analysis is performed on the northern\nc hemisphere only. i.e., if nlat is odd the analysis\nc is performed on the arrays v(i,j),w(i,j) for \nc i=1,...,(nlat+1)/2 and j=1,...,nlon. if nlat is\nc even the analysis is performed on the the arrays\nc v(i,j),w(i,j) for i=1,...,nlat/2 and j=1,...,nlon.\nc\nc = 7 v is antisymmetric and w is symmetric about the \nc equator. the analysis is performed on the northern\nc hemisphere only. i.e., if nlat is odd the analysis\nc is performed on the arrays v(i,j),w(i,j) for \nc i=1,...,(nlat+1)/2 and j=1,...,nlon. if nlat is\nc even the analysis is performed on the the arrays\nc v(i,j),w(i,j) for i=1,...,nlat/2 and j=1,...,nlon.\nc the curl of (v,w) is zero. that is, \nc (d/dtheta (sin(theta) w) - dv/dphi)/sin(theta) = 0. \nc the coefficients cr and ci are zero.\nc\nc = 8 v is antisymmetric and w is symmetric about the \nc equator. the analysis is performed on the northern\nc hemisphere only. i.e., if nlat is odd the analysis\nc is performed on the arrays v(i,j),w(i,j) for \nc i=1,...,(nlat+1)/2 and j=1,...,nlon. if nlat is\nc even the analysis is performed on the the arrays\nc v(i,j),w(i,j) for i=1,...,nlat/2 and j=1,...,nlon.\nc the divergence of (v,w) is zero. i.e., \nc (d/dtheta (sin(theta) v) + dw/dphi)/sin(theta) = 0. \nc the coefficients br and bi are zero.\nc\nc\nc nt the number of analyses. in the program that calls vhagc,\nc the arrays v,w,br,bi,cr, and ci can be three dimensional\nc in which case multiple analyses will be performed.\nc the third index is the analysis index which assumes the \nc values k=1,...,nt. for a single analysis set nt=1. the\nc discription of the remaining parameters is simplified\nc by assuming that nt=1 or that all the arrays are two\nc dimensional.\nc\nc v,w two or three dimensional arrays (see input parameter nt)\nc that contain the vector function to be analyzed.\nc v is the colatitudnal component and w is the east \nc longitudinal component. v(i,j),w(i,j) contain the\nc components at colatitude theta(i) = (i-1)*pi/(nlat-1)\nc and longitude phi(j) = (j-1)*2*pi/nlon. the index ranges\nc are defined above at the input parameter ityp.\nc\nc idvw the first dimension of the arrays v,w as it appears in\nc the program that calls vhagc. if ityp .le. 2 then idvw\nc must be at least nlat. if ityp .gt. 2 and nlat is\nc even then idvw must be at least nlat/2. if ityp .gt. 2\nc and nlat is odd then idvw must be at least (nlat+1)/2.\nc\nc jdvw the second dimension of the arrays v,w as it appears in\nc the program that calls vhagc. jdvw must be at least nlon.\nc\nc mdab the first dimension of the arrays br,bi,cr, and ci as it\nc appears in the program that calls vhagc. mdab must be at\nc least min0(nlat,nlon/2) if nlon is even or at least\nc min0(nlat,(nlon+1)/2) if nlon is odd.\nc\nc ndab the second dimension of the arrays br,bi,cr, and ci as it\nc appears in the program that calls vhagc. ndab must be at\nc least nlat.\nc\nc wvhagc an array which must be initialized by subroutine vhagci.\nc once initialized, wvhagc can be used repeatedly by vhagc\nc as long as nlon and nlat remain unchanged. wvhagc must\nc not be altered between calls of vhagc.\nc\nc lvhagc the dimension of the array wvhagc as it appears in the\nc program that calls vhagc. define\nc\nc l1 = min0(nlat,nlon/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc and\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc then lvhagc must be at least\nc\nc 4*nlat*l2+3*max0(l1-2,0)*(2*nlat-l1-1)+nlon+l2+15\nc\nc\nc work a work array that does not have to be saved.\nc\nc lwork the dimension of the array work as it appears in the\nc program that calls vhagc. define\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc if ityp .le. 2 then lwork must be at least\nc\nc 2*nlat*(2*nlon*nt+3*l2)\nc\nc if ityp .gt. 2 then lwork must be at least\nc\nc 2*l2*(2*nlon*nt+3*nlat)\nc\nc\nc\nc **************************************************************\nc\nc output parameters\nc\nc br,bi two or three dimensional arrays (see input parameter nt)\nc cr,ci that contain the vector spherical harmonic coefficients\nc in the spectral representation of v(i,j) and w(i,j) given \nc in the discription of subroutine vhsec. br(mp1,np1),\nc bi(mp1,np1),cr(mp1,np1), and ci(mp1,np1) are computed \nc for mp1=1,...,mmax and np1=mp1,...,nlat except for np1=nlat\nc and odd mp1. mmax=min0(nlat,nlon/2) if nlon is even or \nc mmax=min0(nlat,(nlon+1)/2) if nlon is odd. \nc \nc ierror = 0 no errors\nc = 1 error in the specification of nlat\nc = 2 error in the specification of nlon\nc = 3 error in the specification of ityp\nc = 4 error in the specification of nt\nc = 5 error in the specification of idvw\nc = 6 error in the specification of jdvw\nc = 7 error in the specification of mdab\nc = 8 error in the specification of ndab\nc = 9 error in the specification of lvhagc\nc = 10 error in the specification of lwork\nc\nc ****************************************************************\nc\nc subroutine vhagci(nlat,nlon,wvhagc,lvhagc,dwork,ldwork,ierror)\nc\nc subroutine vhagci initializes the array wvhagc which can then be\nc used repeatedly by subroutine vhagc until nlat or nlon is changed.\nc\nc input parameters\nc\nc nlat the number of points in the gaussian colatitude grid on the\nc full sphere. these lie in the interval (0,pi) and are computed\nc in radians in theta(1) <...< theta(nlat) by subroutine gaqd.\nc if nlat is odd the equator will be included as the grid point\nc theta((nlat+1)/2). if nlat is even the equator will be\nc excluded as a grid point and will lie half way between\nc theta(nlat/2) and theta(nlat/2+1). nlat must be at least 3.\nc note: on the half sphere, the number of grid points in the\nc colatitudinal direction is nlat/2 if nlat is even or\nc (nlat+1)/2 if nlat is odd.\nc\nc nlon the number of distinct londitude points. nlon determines\nc the grid increment in longitude as 2*pi/nlon. for example\nc nlon = 72 for a five degree grid. nlon must be greater\nc than zero. the axisymmetric case corresponds to nlon=1.\nc the efficiency of the computation is improved when nlon\nc is a product of small prime numbers.\nc\nc lvhagc the dimension of the array wvhagc as it appears in the\nc program that calls vhagci. define\nc\nc l1 = min0(nlat,nlon/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc and\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc then lvhagc must be at least\nc\nc 4*nlat*l2+3*max0(l1-2,0)*(2*nlat-l1-1)+nlon+l2+15\nc\nc\nc dwork a double precision work array that does not need to be saved\nc\nc ldwork the dimension of the array dwork as it appears in the\nc program that calls vhagci. ldwork must be at least\nc\nc 2*nlat*(nlat+1)+1\nc\nc\nc **************************************************************\nc\nc output parameters\nc\nc wvhagc an array which is initialized for use by subroutine vhagc.\nc once initialized, wvhagc can be used repeatedly by vhagc\nc as long as nlat and nlon remain unchanged. wvhagc must not\nc be altered between calls of vhagc.\nc\nc\nc ierror = 0 no errors\nc = 1 error in the specification of nlat\nc = 2 error in the specification of nlon\nc = 3 error in the specification of lvhagc\nc = 4 error in the specification of lwork\nc\n subroutine vhagc(nlat,nlon,ityp,nt,v,w,idvw,jdvw,br,bi,cr,ci,\n 1 mdab,ndab,wvhagc,lvhagc,work,lwork,ierror)\n dimension v(idvw,jdvw,1),w(idvw,jdvw,1),br(mdab,ndab,1),\n 1 bi(mdab,ndab,1),cr(mdab,ndab,1),ci(mdab,ndab,1),\n 2 work(1),wvhagc(1)\n ierror = 1\n if(nlat .lt. 3) return\n ierror = 2\n if(nlon .lt. 1) return\n ierror = 3\n if(ityp.lt.0 .or. ityp.gt.8) return\n ierror = 4\n if(nt .lt. 0) return\n ierror = 5\n imid = (nlat+1)/2\n if((ityp.le.2 .and. idvw.lt.nlat) .or.\n + (ityp.gt.2 .and. idvw.lt.imid)) return\n ierror = 6\n if(jdvw .lt. nlon) return\n ierror = 7\n mmax = min0(nlat,(nlon+1)/2)\n if(mdab .lt. mmax) return\n ierror = 8\n if(ndab .lt. nlat) return\n ierror = 9\n lzz1 = 2*nlat*imid\n labc = 3*(max0(mmax-2,0)*(nlat+nlat-mmax-1))/2\n if(lvhagc .lt. 2*(lzz1+labc)+nlon+imid+15) return\n ierror = 10\n if (ityp.le.2 .and. lwork.lt.nlat*(4*nlon*nt+6*imid)) return\n if (ityp.gt.2 .and. lwork.lt.imid*(4*nlon*nt+6*nlat)) return\n ierror = 0\n idv = nlat\n if(ityp .gt. 2) idv = imid\n lnl = nt*idv*nlon\n ist = 0\n if(ityp .le. 2) ist = imid\n iw1 = ist+1\n iw2 = lnl+1\n iw3 = iw2+ist\n iw4 = iw2+lnl\n iw5 = iw4+3*imid*nlat\n lwzvin = lzz1+labc\n jw1 = (nlat+1)/2+1\n jw2 = jw1+lwzvin\n jw3 = jw2+lwzvin\n call vhagc1(nlat,nlon,ityp,nt,imid,idvw,jdvw,v,w,mdab,ndab,\n +br,bi,cr,ci,idv,work,work(iw1),work(iw2),work(iw3),\n +work(iw4),work(iw5),wvhagc,wvhagc(jw1),wvhagc(jw2),wvhagc(jw3))\n return\n end\n subroutine vhagc1(nlat,nlon,ityp,nt,imid,idvw,jdvw,v,w,mdab,\n +ndab,br,bi,cr,ci,idv,ve,vo,we,wo,vb,wb,wts,wvbin,wwbin,wrfft)\n dimension v(idvw,jdvw,1),w(idvw,jdvw,1),br(mdab,ndab,1),\n 1 bi(mdab,ndab,1),cr(mdab,ndab,1),ci(mdab,ndab,1),\n 2 ve(idv,nlon,1),vo(idv,nlon,1),we(idv,nlon,1),\n 3 wo(idv,nlon,1),wts(*),wvbin(1),wwbin(1),wrfft(1),\n 4 vb(imid,nlat,3),wb(imid,nlat,3)\n nlp1 = nlat+1\n tsn = 2./nlon\n fsn = 4./nlon\n mlat = mod(nlat,2)\n mlon = mod(nlon,2)\n mmax = min0(nlat,(nlon+1)/2)\n imm1 = imid\n if(mlat .ne. 0) imm1 = imid-1\n if(ityp .gt. 2) go to 3 \n do 5 k=1,nt \n do 5 i=1,imm1\n do 5 j=1,nlon\n ve(i,j,k) = tsn*(v(i,j,k)+v(nlp1-i,j,k))\n vo(i,j,k) = tsn*(v(i,j,k)-v(nlp1-i,j,k))\n we(i,j,k) = tsn*(w(i,j,k)+w(nlp1-i,j,k))\n wo(i,j,k) = tsn*(w(i,j,k)-w(nlp1-i,j,k))\n 5 continue\n go to 2\n 3 do 8 k=1,nt\n do 8 i=1,imm1 \n do 8 j=1,nlon\n ve(i,j,k) = fsn*v(i,j,k)\n vo(i,j,k) = fsn*v(i,j,k)\n we(i,j,k) = fsn*w(i,j,k)\n wo(i,j,k) = fsn*w(i,j,k)\n 8 continue\n 2 if(mlat .eq. 0) go to 7\n do 6 k=1,nt \n do 6 j=1,nlon\n ve(imid,j,k) = tsn*v(imid,j,k)\n we(imid,j,k) = tsn*w(imid,j,k)\n 6 continue\n 7 do 9 k=1,nt\n call hrfftf(idv,nlon,ve(1,1,k),idv,wrfft,vb)\n call hrfftf(idv,nlon,we(1,1,k),idv,wrfft,vb)\n 9 continue \n ndo1 = nlat\n ndo2 = nlat\n if(mlat .ne. 0) ndo1 = nlat-1\n if(mlat .eq. 0) ndo2 = nlat-1\n if(ityp.eq.2 .or. ityp.eq.5 .or. ityp.eq.8) go to 11 \n do 10 k=1,nt\n do 10 mp1=1,mmax\n do 10 np1=mp1,nlat\n br(mp1,np1,k)=0.\n bi(mp1,np1,k)=0.\n 10 continue\n 11 if(ityp.eq.1 .or. ityp.eq.4 .or. ityp.eq.7) go to 13 \n do 12 k=1,nt\n do 12 mp1=1,mmax\n do 12 np1=mp1,nlat\n cr(mp1,np1,k)=0.\n ci(mp1,np1,k)=0.\n 12 continue\n 13 itypp = ityp+1\n go to (1,100,200,300,400,500,600,700,800),itypp\nc\nc case ityp=0 , no symmetries\nc\n 1 call vbin(0,nlat,nlon,0,vb,iv,wvbin)\nc\nc case m=0\nc\n do 15 k=1,nt\n do 1015 i=1,imid\n tv = ve(i,1,k)*wts(i)\n tw = we(i,1,k)*wts(i)\n do 10015 np1=2,ndo2,2\n br(1,np1,k) = br(1,np1,k)+vb(i,np1,iv)*tv\n cr(1,np1,k) = cr(1,np1,k)-vb(i,np1,iv)*tw\n10015 continue\n 1015 continue\n 15 continue\n do 16 k=1,nt\n do 1016 i=1,imm1\n tv = vo(i,1,k)*wts(i)\n tw = wo(i,1,k)*wts(i)\n do 10016 np1=3,ndo1,2\n br(1,np1,k) = br(1,np1,k)+vb(i,np1,iv)*tv\n cr(1,np1,k) = cr(1,np1,k)-vb(i,np1,iv)*tw\n10016 continue\n 1016 continue\n 16 continue\nc\nc case m = 1 through nlat-1\nc\n if(mmax .lt. 2) return\n do 20 mp1=2,mmax\n m = mp1-1\n mp2 = mp1+1\n call vbin(0,nlat,nlon,m,vb,iv,wvbin)\n call wbin(0,nlat,nlon,m,wb,iw,wwbin)\n if(mp1 .gt. ndo1) go to 17\n do 23 k=1,nt\n do 1023 i=1,imm1\nc\nc set temps to optimize quadrature\nc\n tvo1 = vo(i,2*mp1-1,k)*wts(i)\n tvo2 = vo(i,2*mp1-2,k)*wts(i)\n tve1 = ve(i,2*mp1-1,k)*wts(i)\n tve2 = ve(i,2*mp1-2,k)*wts(i)\n two1 = wo(i,2*mp1-1,k)*wts(i)\n two2 = wo(i,2*mp1-2,k)*wts(i)\n twe1 = we(i,2*mp1-1,k)*wts(i)\n twe2 = we(i,2*mp1-2,k)*wts(i)\n do 10023 np1=mp1,ndo1,2\n br(mp1,np1,k) = br(mp1,np1,k)+vb(i,np1,iv)*tvo2\n + +wb(i,np1,iw)*twe1\n bi(mp1,np1,k) = bi(mp1,np1,k)+vb(i,np1,iv)*tvo1\n + -wb(i,np1,iw)*twe2\n cr(mp1,np1,k) = cr(mp1,np1,k)-vb(i,np1,iv)*two2\n + +wb(i,np1,iw)*tve1\n ci(mp1,np1,k) = ci(mp1,np1,k)-vb(i,np1,iv)*two1\n + -wb(i,np1,iw)*tve2\n10023 continue\n 1023 continue\n 23 continue\n\n if(mlat .eq. 0) go to 17\n i = imid\n do 24 k=1,nt\n do 1024 np1=mp1,ndo1,2\n br(mp1,np1,k)=br(mp1,np1,k)+wb(i,np1,iw)*we(i,2*mp1-1,k)*wts(i)\n bi(mp1,np1,k)=bi(mp1,np1,k)-wb(i,np1,iw)*we(i,2*mp1-2,k)*wts(i)\n cr(mp1,np1,k)=cr(mp1,np1,k)+wb(i,np1,iw)*ve(i,2*mp1-1,k)*wts(i)\n ci(mp1,np1,k)=ci(mp1,np1,k)-wb(i,np1,iw)*ve(i,2*mp1-2,k)*wts(i)\n 1024 continue\n 24 continue\n 17 if(mp2 .gt. ndo2) go to 20\n do 21 k=1,nt\n do 1021 i=1,imm1\n tvo1 = vo(i,2*mp1-1,k)*wts(i)\n tvo2 = vo(i,2*mp1-2,k)*wts(i)\n tve1 = ve(i,2*mp1-1,k)*wts(i)\n tve2 = ve(i,2*mp1-2,k)*wts(i)\n two1 = wo(i,2*mp1-1,k)*wts(i)\n two2 = wo(i,2*mp1-2,k)*wts(i)\n twe1 = we(i,2*mp1-1,k)*wts(i)\n twe2 = we(i,2*mp1-2,k)*wts(i)\n do 10021 np1=mp2,ndo2,2\n br(mp1,np1,k) = br(mp1,np1,k)+vb(i,np1,iv)*tve2\n 1 +wb(i,np1,iw)*two1\n bi(mp1,np1,k) = bi(mp1,np1,k)+vb(i,np1,iv)*tve1\n 1 -wb(i,np1,iw)*two2\n cr(mp1,np1,k) = cr(mp1,np1,k)-vb(i,np1,iv)*twe2\n 1 +wb(i,np1,iw)*tvo1\n ci(mp1,np1,k) = ci(mp1,np1,k)-vb(i,np1,iv)*twe1\n 1 -wb(i,np1,iw)*tvo2\n10021 continue\n 1021 continue\n 21 continue\n\n if(mlat .eq. 0) go to 20\n i = imid\n do 22 k=1,nt\n do 1022 np1=mp2,ndo2,2\n br(mp1,np1,k)=br(mp1,np1,k)+vb(i,np1,iv)*ve(i,2*mp1-2,k)*wts(i)\n bi(mp1,np1,k)=bi(mp1,np1,k)+vb(i,np1,iv)*ve(i,2*mp1-1,k)*wts(i)\n cr(mp1,np1,k)=cr(mp1,np1,k)-vb(i,np1,iv)*we(i,2*mp1-2,k)*wts(i)\n ci(mp1,np1,k)=ci(mp1,np1,k)-vb(i,np1,iv)*we(i,2*mp1-1,k)*wts(i)\n 1022 continue\n 22 continue\n 20 continue\n return\nc\nc case ityp=1 , no symmetries but cr and ci equal zero\nc\n 100 call vbin(0,nlat,nlon,0,vb,iv,wvbin)\nc\nc case m=0\nc\n do 115 k=1,nt\n do 115 i=1,imid\n tv = ve(i,1,k)*wts(i)\n do 115 np1=2,ndo2,2\n br(1,np1,k) = br(1,np1,k)+vb(i,np1,iv)*tv\n 115 continue\n do 116 k=1,nt\n do 116 i=1,imm1\n tv = vo(i,1,k)*wts(i)\n do 116 np1=3,ndo1,2\n br(1,np1,k) = br(1,np1,k)+vb(i,np1,iv)*tv\n 116 continue\nc\nc case m = 1 through nlat-1\nc\n if(mmax .lt. 2) return\n do 120 mp1=2,mmax\n m = mp1-1\n mp2 = mp1+1\n call vbin(0,nlat,nlon,m,vb,iv,wvbin)\n call wbin(0,nlat,nlon,m,wb,iw,wwbin)\n if(mp1 .gt. ndo1) go to 117\n do 123 k=1,nt\n do 123 i=1,imm1\n tvo1 = vo(i,2*mp1-1,k)*wts(i)\n tvo2 = vo(i,2*mp1-2,k)*wts(i)\n twe1 = we(i,2*mp1-1,k)*wts(i)\n twe2 = we(i,2*mp1-2,k)*wts(i)\n do 123 np1=mp1,ndo1,2\n br(mp1,np1,k) = br(mp1,np1,k)+vb(i,np1,iv)*tvo2\n + +wb(i,np1,iw)*twe1\n bi(mp1,np1,k) = bi(mp1,np1,k)+vb(i,np1,iv)*tvo1\n + -wb(i,np1,iw)*twe2\n 123 continue\n if(mlat .eq. 0) go to 117\n i = imid\n do 124 k=1,nt\n do 124 np1=mp1,ndo1,2\n br(mp1,np1,k) = br(mp1,np1,k)+wb(i,np1,iw)*we(i,2*mp1-1,k)*wts(i)\n bi(mp1,np1,k) = bi(mp1,np1,k)-wb(i,np1,iw)*we(i,2*mp1-2,k)*wts(i)\n 124 continue\n 117 if(mp2 .gt. ndo2) go to 120\n do 121 k=1,nt\n do 121 i=1,imm1\n tve1 = ve(i,2*mp1-1,k)*wts(i)\n tve2 = ve(i,2*mp1-2,k)*wts(i)\n two1 = wo(i,2*mp1-1,k)*wts(i)\n two2 = wo(i,2*mp1-2,k)*wts(i)\n do 121 np1=mp2,ndo2,2\n br(mp1,np1,k) = br(mp1,np1,k)+vb(i,np1,iv)*tve2\n + +wb(i,np1,iw)*two1\n bi(mp1,np1,k) = bi(mp1,np1,k)+vb(i,np1,iv)*tve1\n + -wb(i,np1,iw)*two2\n 121 continue\n if(mlat .eq. 0) go to 120\n i = imid\n do 122 k=1,nt\n do 122 np1=mp2,ndo2,2\n br(mp1,np1,k) = br(mp1,np1,k)+vb(i,np1,iv)*ve(i,2*mp1-2,k)*wts(i)\n bi(mp1,np1,k) = bi(mp1,np1,k)+vb(i,np1,iv)*ve(i,2*mp1-1,k)*wts(i)\n 122 continue\n 120 continue\n return\nc\nc case ityp=2 , no symmetries but br and bi equal zero \nc\n 200 call vbin(0,nlat,nlon,0,vb,iv,wvbin)\nc\nc case m=0\nc\n do 215 k=1,nt\n do 215 i=1,imid\n tw = we(i,1,k)*wts(i)\n do 215 np1=2,ndo2,2\n cr(1,np1,k) = cr(1,np1,k)-vb(i,np1,iv)*tw\n 215 continue\n do 216 k=1,nt\n do 216 i=1,imm1\n tw = wo(i,1,k)*wts(i)\n do 216 np1=3,ndo1,2\n cr(1,np1,k) = cr(1,np1,k)-vb(i,np1,iv)*tw\n 216 continue\nc\nc case m = 1 through nlat-1\nc\n if(mmax .lt. 2) return\n do 220 mp1=2,mmax\n m = mp1-1\n mp2 = mp1+1\n call vbin(0,nlat,nlon,m,vb,iv,wvbin)\n call wbin(0,nlat,nlon,m,wb,iw,wwbin)\n if(mp1 .gt. ndo1) go to 217\n do 223 k=1,nt\n do 223 i=1,imm1\n tve1 = ve(i,2*mp1-1,k)*wts(i)\n tve2 = ve(i,2*mp1-2,k)*wts(i)\n two1 = wo(i,2*mp1-1,k)*wts(i)\n two2 = wo(i,2*mp1-2,k)*wts(i)\n do 223 np1=mp1,ndo1,2\n cr(mp1,np1,k) = cr(mp1,np1,k)-vb(i,np1,iv)*two2\n + +wb(i,np1,iw)*tve1\n ci(mp1,np1,k) = ci(mp1,np1,k)-vb(i,np1,iv)*two1\n + -wb(i,np1,iw)*tve2\n 223 continue\n if(mlat .eq. 0) go to 217\n i = imid\n do 224 k=1,nt\n do 224 np1=mp1,ndo1,2\n cr(mp1,np1,k) = cr(mp1,np1,k)+wb(i,np1,iw)*ve(i,2*mp1-1,k)*wts(i)\n ci(mp1,np1,k) = ci(mp1,np1,k)-wb(i,np1,iw)*ve(i,2*mp1-2,k)*wts(i)\n 224 continue\n 217 if(mp2 .gt. ndo2) go to 220\n do 221 k=1,nt\n do 221 i=1,imm1\n twe1 = we(i,2*mp1-1,k)*wts(i)\n twe2 = we(i,2*mp1-2,k)*wts(i)\n tvo1 = vo(i,2*mp1-1,k)*wts(i)\n tvo2 = vo(i,2*mp1-2,k)*wts(i)\n do 221 np1=mp2,ndo2,2\n cr(mp1,np1,k) = cr(mp1,np1,k)-vb(i,np1,iv)*twe2\n + +wb(i,np1,iw)*tvo1\n ci(mp1,np1,k) = ci(mp1,np1,k)-vb(i,np1,iv)*twe1\n + -wb(i,np1,iw)*tvo2\n 221 continue\n if(mlat .eq. 0) go to 220\n i = imid\n do 222 k=1,nt\n do 222 np1=mp2,ndo2,2\n cr(mp1,np1,k) = cr(mp1,np1,k)-vb(i,np1,iv)*we(i,2*mp1-2,k)*wts(i)\n ci(mp1,np1,k) = ci(mp1,np1,k)-vb(i,np1,iv)*we(i,2*mp1-1,k)*wts(i)\n 222 continue\n 220 continue\n return\nc\nc case ityp=3 , v even , w odd\nc\n 300 call vbin(0,nlat,nlon,0,vb,iv,wvbin)\nc\nc case m=0\nc\n do 315 k=1,nt\n do 315 i=1,imid\n tv = ve(i,1,k)*wts(i)\n do 315 np1=2,ndo2,2\n br(1,np1,k) = br(1,np1,k)+vb(i,np1,iv)*tv\n 315 continue\n do 316 k=1,nt\n do 316 i=1,imm1\n tw = wo(i,1,k)*wts(i)\n do 316 np1=3,ndo1,2\n cr(1,np1,k) = cr(1,np1,k)-vb(i,np1,iv)*tw\n 316 continue\nc\nc case m = 1 through nlat-1\nc\n if(mmax .lt. 2) return\n do 320 mp1=2,mmax\n m = mp1-1\n mp2 = mp1+1\n call vbin(0,nlat,nlon,m,vb,iv,wvbin)\n call wbin(0,nlat,nlon,m,wb,iw,wwbin)\n if(mp1 .gt. ndo1) go to 317\n do 323 k=1,nt\n do 323 i=1,imm1\n two1 = wo(i,2*mp1-1,k)*wts(i)\n two2 = wo(i,2*mp1-2,k)*wts(i)\n tve1 = ve(i,2*mp1-1,k)*wts(i)\n tve2 = ve(i,2*mp1-2,k)*wts(i)\n do 323 np1=mp1,ndo1,2\n cr(mp1,np1,k) = cr(mp1,np1,k)-vb(i,np1,iv)*two2\n + +wb(i,np1,iw)*tve1\n ci(mp1,np1,k) = ci(mp1,np1,k)-vb(i,np1,iv)*two1\n + -wb(i,np1,iw)*tve2\n 323 continue\n if(mlat .eq. 0) go to 317\n i = imid\n do 324 k=1,nt\n do 324 np1=mp1,ndo1,2\n cr(mp1,np1,k) = cr(mp1,np1,k)+wb(i,np1,iw)*ve(i,2*mp1-1,k)*wts(i)\n ci(mp1,np1,k) = ci(mp1,np1,k)-wb(i,np1,iw)*ve(i,2*mp1-2,k)*wts(i)\n 324 continue\n 317 if(mp2 .gt. ndo2) go to 320\n do 321 k=1,nt\n do 321 i=1,imm1\n two1 = wo(i,2*mp1-1,k)*wts(i)\n two2 = wo(i,2*mp1-2,k)*wts(i)\n tve1 = ve(i,2*mp1-1,k)*wts(i)\n tve2 = ve(i,2*mp1-2,k)*wts(i)\n do 321 np1=mp2,ndo2,2\n br(mp1,np1,k) = br(mp1,np1,k)+vb(i,np1,iv)*tve2\n + +wb(i,np1,iw)*two1\n bi(mp1,np1,k) = bi(mp1,np1,k)+vb(i,np1,iv)*tve1\n + -wb(i,np1,iw)*two2\n 321 continue\n if(mlat .eq. 0) go to 320\n i = imid\n do 322 k=1,nt\n do 322 np1=mp2,ndo2,2\n br(mp1,np1,k) = br(mp1,np1,k)+vb(i,np1,iv)*ve(i,2*mp1-2,k)*wts(i)\n bi(mp1,np1,k) = bi(mp1,np1,k)+vb(i,np1,iv)*ve(i,2*mp1-1,k)*wts(i)\n 322 continue\n 320 continue\n return\nc\nc case ityp=4 , v even, w odd, and cr and ci equal 0. \nc\n 400 call vbin(1,nlat,nlon,0,vb,iv,wvbin)\nc\nc case m=0\nc\n do 415 k=1,nt\n do 415 i=1,imid\n tv = ve(i,1,k)*wts(i)\n do 415 np1=2,ndo2,2\n br(1,np1,k) = br(1,np1,k)+vb(i,np1,iv)*tv\n 415 continue\nc\nc case m = 1 through nlat-1\nc\n if(mmax .lt. 2) return\n do 420 mp1=2,mmax\n m = mp1-1\n mp2 = mp1+1\n call vbin(1,nlat,nlon,m,vb,iv,wvbin)\n call wbin(1,nlat,nlon,m,wb,iw,wwbin)\n if(mp2 .gt. ndo2) go to 420\n do 421 k=1,nt\n do 421 i=1,imm1\n two1 = wo(i,2*mp1-1,k)*wts(i)\n two2 = wo(i,2*mp1-2,k)*wts(i)\n tve1 = ve(i,2*mp1-1,k)*wts(i)\n tve2 = ve(i,2*mp1-2,k)*wts(i)\n do 421 np1=mp2,ndo2,2\n br(mp1,np1,k) = br(mp1,np1,k)+vb(i,np1,iv)*tve2\n + +wb(i,np1,iw)*two1\n bi(mp1,np1,k) = bi(mp1,np1,k)+vb(i,np1,iv)*tve1\n + -wb(i,np1,iw)*two2\n 421 continue\n if(mlat .eq. 0) go to 420\n i = imid\n do 422 k=1,nt\n do 422 np1=mp2,ndo2,2\n br(mp1,np1,k) = br(mp1,np1,k)+vb(i,np1,iv)*ve(i,2*mp1-2,k)*wts(i)\n bi(mp1,np1,k) = bi(mp1,np1,k)+vb(i,np1,iv)*ve(i,2*mp1-1,k)*wts(i)\n 422 continue\n 420 continue\n return\nc\nc case ityp=5 v even, w odd, and br and bi equal zero\nc\n 500 call vbin(2,nlat,nlon,0,vb,iv,wvbin)\nc\nc case m=0\nc\n do 516 k=1,nt\n do 516 i=1,imm1\n tw = wo(i,1,k)*wts(i)\n do 516 np1=3,ndo1,2\n cr(1,np1,k) = cr(1,np1,k)-vb(i,np1,iv)*tw\n 516 continue\nc\nc case m = 1 through nlat-1\nc\n if(mmax .lt. 2) return\n do 520 mp1=2,mmax\n m = mp1-1\n mp2 = mp1+1\n call vbin(2,nlat,nlon,m,vb,iv,wvbin)\n call wbin(2,nlat,nlon,m,wb,iw,wwbin)\n if(mp1 .gt. ndo1) go to 520\n do 523 k=1,nt\n do 523 i=1,imm1\n two1 = wo(i,2*mp1-1,k)*wts(i)\n two2 = wo(i,2*mp1-2,k)*wts(i)\n tve1 = ve(i,2*mp1-1,k)*wts(i)\n tve2 = ve(i,2*mp1-2,k)*wts(i)\n do 523 np1=mp1,ndo1,2\n cr(mp1,np1,k) = cr(mp1,np1,k)-vb(i,np1,iv)*two2\n + +wb(i,np1,iw)*tve1\n ci(mp1,np1,k) = ci(mp1,np1,k)-vb(i,np1,iv)*two1\n + -wb(i,np1,iw)*tve2\n 523 continue\n if(mlat .eq. 0) go to 520\n i = imid\n do 524 k=1,nt\n do 524 np1=mp1,ndo1,2\n cr(mp1,np1,k) = cr(mp1,np1,k)+wb(i,np1,iw)*ve(i,2*mp1-1,k)*wts(i)\n ci(mp1,np1,k) = ci(mp1,np1,k)-wb(i,np1,iw)*ve(i,2*mp1-2,k)*wts(i)\n 524 continue\n 520 continue\n return\nc\nc case ityp=6 , v odd , w even\nc\n 600 call vbin(0,nlat,nlon,0,vb,iv,wvbin)\nc\nc case m=0\nc\n do 615 k=1,nt\n do 615 i=1,imid\n tw = we(i,1,k)*wts(i)\n do 615 np1=2,ndo2,2\n cr(1,np1,k) = cr(1,np1,k)-vb(i,np1,iv)*tw\n 615 continue\n do 616 k=1,nt\n do 616 i=1,imm1\n tv = vo(i,1,k)*wts(i)\n do 616 np1=3,ndo1,2\n br(1,np1,k) = br(1,np1,k)+vb(i,np1,iv)*tv\n 616 continue\nc\nc case m = 1 through nlat-1\nc\n if(mmax .lt. 2) return\n do 620 mp1=2,mmax\n m = mp1-1\n mp2 = mp1+1\n call vbin(0,nlat,nlon,m,vb,iv,wvbin)\n call wbin(0,nlat,nlon,m,wb,iw,wwbin)\n if(mp1 .gt. ndo1) go to 617\n do 623 k=1,nt\n do 623 i=1,imm1\n twe1 = we(i,2*mp1-1,k)*wts(i)\n twe2 = we(i,2*mp1-2,k)*wts(i)\n tvo1 = vo(i,2*mp1-1,k)*wts(i)\n tvo2 = vo(i,2*mp1-2,k)*wts(i)\n do 623 np1=mp1,ndo1,2\n br(mp1,np1,k) = br(mp1,np1,k)+vb(i,np1,iv)*tvo2\n + +wb(i,np1,iw)*twe1\n bi(mp1,np1,k) = bi(mp1,np1,k)+vb(i,np1,iv)*tvo1\n + -wb(i,np1,iw)*twe2\n 623 continue\n if(mlat .eq. 0) go to 617\n i = imid\n do 624 k=1,nt\n do 624 np1=mp1,ndo1,2\n br(mp1,np1,k) = br(mp1,np1,k)+wb(i,np1,iw)*we(i,2*mp1-1,k)*wts(i)\n bi(mp1,np1,k) = bi(mp1,np1,k)-wb(i,np1,iw)*we(i,2*mp1-2,k)*wts(i)\n 624 continue\n 617 if(mp2 .gt. ndo2) go to 620\n do 621 k=1,nt\n do 621 i=1,imm1\n twe1 = we(i,2*mp1-1,k)*wts(i)\n twe2 = we(i,2*mp1-2,k)*wts(i)\n tvo1 = vo(i,2*mp1-1,k)*wts(i)\n tvo2 = vo(i,2*mp1-2,k)*wts(i)\n do 621 np1=mp2,ndo2,2\n cr(mp1,np1,k) = cr(mp1,np1,k)-vb(i,np1,iv)*twe2\n + +wb(i,np1,iw)*tvo1\n ci(mp1,np1,k) = ci(mp1,np1,k)-vb(i,np1,iv)*twe1\n + -wb(i,np1,iw)*tvo2\n 621 continue\n if(mlat .eq. 0) go to 620\n i = imid\n do 622 k=1,nt\n do 622 np1=mp2,ndo2,2\n cr(mp1,np1,k) = cr(mp1,np1,k)-vb(i,np1,iv)*we(i,2*mp1-2,k)*wts(i)\n ci(mp1,np1,k) = ci(mp1,np1,k)-vb(i,np1,iv)*we(i,2*mp1-1,k)*wts(i)\n 622 continue\n 620 continue\n return\nc\nc case ityp=7 v odd, w even, and cr and ci equal zero\nc\n 700 call vbin(2,nlat,nlon,0,vb,iv,wvbin)\nc\nc case m=0\nc\n do 716 k=1,nt\n do 716 i=1,imm1\n tv = vo(i,1,k)*wts(i)\n do 716 np1=3,ndo1,2\n br(1,np1,k) = br(1,np1,k)+vb(i,np1,iv)*tv\n 716 continue\nc\nc case m = 1 through nlat-1\nc\n if(mmax .lt. 2) return\n do 720 mp1=2,mmax\n m = mp1-1\n mp2 = mp1+1\n call vbin(2,nlat,nlon,m,vb,iv,wvbin)\n call wbin(2,nlat,nlon,m,wb,iw,wwbin)\n if(mp1 .gt. ndo1) go to 720\n do 723 k=1,nt\n do 723 i=1,imm1\n twe1 = we(i,2*mp1-1,k)*wts(i)\n twe2 = we(i,2*mp1-2,k)*wts(i)\n tvo1 = vo(i,2*mp1-1,k)*wts(i)\n tvo2 = vo(i,2*mp1-2,k)*wts(i)\n do 723 np1=mp1,ndo1,2\n br(mp1,np1,k) = br(mp1,np1,k)+vb(i,np1,iv)*tvo2\n + +wb(i,np1,iw)*twe1\n bi(mp1,np1,k) = bi(mp1,np1,k)+vb(i,np1,iv)*tvo1\n + -wb(i,np1,iw)*twe2\n 723 continue\n if(mlat .eq. 0) go to 720\n i = imid\n do 724 k=1,nt\n do 724 np1=mp1,ndo1,2\n br(mp1,np1,k) = br(mp1,np1,k)+wb(i,np1,iw)*we(i,2*mp1-1,k)*wts(i)\n bi(mp1,np1,k) = bi(mp1,np1,k)-wb(i,np1,iw)*we(i,2*mp1-2,k)*wts(i)\n 724 continue\n 720 continue\n return\nc\nc case ityp=8 v odd, w even, and both br and bi equal zero\nc\n 800 call vbin(1,nlat,nlon,0,vb,iv,wvbin)\nc\nc case m=0\nc\n do 815 k=1,nt\n do 815 i=1,imid\n tw = we(i,1,k)*wts(i)\n do 815 np1=2,ndo2,2\n cr(1,np1,k) = cr(1,np1,k)-vb(i,np1,iv)*tw\n 815 continue\nc\nc case m = 1 through nlat-1\nc\n if(mmax .lt. 2) return\n do 820 mp1=2,mmax\n m = mp1-1\n mp2 = mp1+1\n call vbin(1,nlat,nlon,m,vb,iv,wvbin)\n call wbin(1,nlat,nlon,m,wb,iw,wwbin)\n if(mp2 .gt. ndo2) go to 820\n do 821 k=1,nt\n do 821 i=1,imm1\n twe1 = we(i,2*mp1-1,k)*wts(i)\n twe2 = we(i,2*mp1-2,k)*wts(i)\n tvo1 = vo(i,2*mp1-1,k)*wts(i)\n tvo2 = vo(i,2*mp1-2,k)*wts(i)\n do 821 np1=mp2,ndo2,2\n cr(mp1,np1,k) = cr(mp1,np1,k)-vb(i,np1,iv)*twe2\n + +wb(i,np1,iw)*tvo1\n ci(mp1,np1,k) = ci(mp1,np1,k)-vb(i,np1,iv)*twe1\n + -wb(i,np1,iw)*tvo2\n 821 continue\n if(mlat .eq. 0) go to 820\n i = imid\n do 822 k=1,nt\n do 822 np1=mp2,ndo2,2\n cr(mp1,np1,k) = cr(mp1,np1,k)-vb(i,np1,iv)*we(i,2*mp1-2,k)*wts(i)\n ci(mp1,np1,k) = ci(mp1,np1,k)-vb(i,np1,iv)*we(i,2*mp1-1,k)*wts(i)\n 822 continue\n 820 continue\n return\n end\n subroutine vhagci(nlat,nlon,wvhagc,lvhagc,dwork,ldwork,ierror)\n dimension wvhagc(1)\n double precision dwork(*)\n ierror = 1\n if(nlat .lt. 3) return\n ierror = 2\n if(nlon .lt. 1) return\n ierror = 3\n imid = (nlat+1)/2\n lzz1 = 2*nlat*imid\n mmax = min0(nlat,(nlon+1)/2)\n labc = 3*(max0(mmax-2,0)*(nlat+nlat-mmax-1))/2\n imid = (nlat+1)/2\n if(lvhagc .lt. 2*(lzz1+labc)+nlon+imid+15) return\n ierror = 4\n if (ldwork .lt. 2*nlat*(nlat+1)+1) return\n ierror = 0\nc\nc compute gaussian points in first nlat+1 words of dwork\nc double precision\nc\n lwk = nlat*(nlat+2)\n\n jw1 = 1\nc jw2 = jw1+nlat+nlat\nc jw3 = jw2+nlat+nlat\n jw2 = jw1+nlat\n jw3 = jw2+nlat\n call gaqd(nlat,dwork(jw1),dwork(jw2),dwork(jw3),lwk,ierror)\n imid = (nlat+1)/2\nc\nc set first imid words of double precision weights in dwork\nc as single precision in first imid words of wvhagc\nc\n call setwts(imid,dwork(nlat+1),wvhagc)\nc\nc first nlat+1 words of dwork contain double theta\nc\nc iwrk = nlat+2\n iwrk = (nlat+1)/2 +1\n iw1 = imid+1\n call vbgint (nlat,nlon,dwork,wvhagc(iw1),dwork(iwrk))\n lwvbin = lzz1+labc\n iw2 = iw1+lwvbin\n call wbgint (nlat,nlon,dwork,wvhagc(iw2),dwork(iwrk))\n iw3 = iw2+lwvbin\n call hrffti(nlon,wvhagc(iw3))\n return\n end\n subroutine setwts(imid,dwts,wts)\nc\nc set first imid =(nlat+1)/2 of double precision weights in dwts\nc as single precision in wts\nc\n dimension dwts(imid),wts(imid)\n double precision dwts\n do 1 i=1,imid\n wts(i) = dwts(i)\n 1 continue\n return\n end\n", "meta": {"hexsha": "066c6b3d6e10b078c717ae93f919bcfbd274e4eb", "size": 36843, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "contrib/spherepack/Src/vhagc.f", "max_stars_repo_name": "xylar/cdat", "max_stars_repo_head_hexsha": "8a5080cb18febfde365efc96147e25f51494a2bf", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 62, "max_stars_repo_stars_event_min_datetime": "2018-03-30T15:46:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-08T23:30:24.000Z", "max_issues_repo_path": "contrib/spherepack/Src/vhagc.f", "max_issues_repo_name": "xylar/cdat", "max_issues_repo_head_hexsha": "8a5080cb18febfde365efc96147e25f51494a2bf", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 114, "max_issues_repo_issues_event_min_datetime": "2018-03-21T01:12:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-05T12:29:54.000Z", "max_forks_repo_path": "contrib/spherepack/Src/vhagc.f", "max_forks_repo_name": "CDAT/uvcdat", "max_forks_repo_head_hexsha": "5133560c0c049b5c93ee321ba0af494253b44f91", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2018-06-06T02:42:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-26T03:27:00.000Z", "avg_line_length": 35.2227533461, "max_line_length": 79, "alphanum_fraction": 0.5287571588, "num_tokens": 14421, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582497090321, "lm_q2_score": 0.7090191337850933, "lm_q1q2_score": 0.659712702231892}} {"text": " SUBROUTINE MB03XD( BALANC, JOB, JOBU, JOBV, N, A, LDA, QG, LDQG,\n $ T, LDT, U1, LDU1, U2, LDU2, V1, LDV1, V2, LDV2,\n $ WR, WI, ILO, SCALE, DWORK, LDWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute the eigenvalues of a Hamiltonian matrix,\nC\nC [ A G ] T T\nC H = [ T ], G = G, Q = Q, (1)\nC [ Q -A ]\nC\nC where A, G and Q are real n-by-n matrices.\nC\nC Due to the structure of H all eigenvalues appear in pairs\nC (lambda,-lambda). This routine computes the eigenvalues of H\nC using an algorithm based on the symplectic URV and the periodic\nC Schur decompositions as described in [1],\nC\nC T [ T G ]\nC U H V = [ T ], (2)\nC [ 0 S ]\nC\nC where U and V are 2n-by-2n orthogonal symplectic matrices,\nC S is in real Schur form and T is upper triangular.\nC\nC The algorithm is backward stable and preserves the eigenvalue\nC pairings in finite precision arithmetic.\nC\nC Optionally, a symplectic balancing transformation to improve the\nC conditioning of eigenvalues is computed (see MB04DD). In this\nC case, the matrix H in decomposition (2) must be replaced by the\nC balanced matrix.\nC\nC The SLICOT Library routine MB03ZD can be used to compute invariant\nC subspaces of H from the output of this routine.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC BALANC CHARACTER*1\nC Indicates how H should be diagonally scaled and/or\nC permuted to reduce its norm.\nC = 'N': Do not diagonally scale or permute;\nC = 'P': Perform symplectic permutations to make the matrix\nC closer to Hamiltonian Schur form. Do not diagonally\nC scale;\nC = 'S': Diagonally scale the matrix, i.e., replace A, G and\nC Q by D*A*D**(-1), D*G*D and D**(-1)*Q*D**(-1) where\nC D is a diagonal matrix chosen to make the rows and\nC columns of H more equal in norm. Do not permute;\nC = 'B': Both diagonally scale and permute A, G and Q.\nC Permuting does not change the norm of H, but scaling does.\nC\nC JOB CHARACTER*1\nC Indicates whether the user wishes to compute the full\nC decomposition (2) or the eigenvalues only, as follows:\nC = 'E': compute the eigenvalues only;\nC = 'S': compute matrices T and S of (2);\nC = 'G': compute matrices T, S and G of (2).\nC\nC JOBU CHARACTER*1\nC Indicates whether or not the user wishes to compute the\nC orthogonal symplectic matrix U of (2) as follows:\nC = 'N': the matrix U is not computed;\nC = 'U': the matrix U is computed.\nC\nC JOBV CHARACTER*1\nC Indicates whether or not the user wishes to compute the\nC orthogonal symplectic matrix V of (2) as follows:\nC = 'N': the matrix V is not computed;\nC = 'V': the matrix V is computed.\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The order of the matrix A. N >= 0.\nC\nC A (input/output) DOUBLE PRECISION array, dimension (LDA,N)\nC On entry, the leading N-by-N part of this array must\nC contain the matrix A.\nC On exit, this array is overwritten. If JOB = 'S' or\nC JOB = 'G', the leading N-by-N part of this array contains\nC the matrix S in real Schur form of decomposition (2).\nC\nC LDA INTEGER\nC The leading dimension of the array A. LDA >= max(1,N).\nC\nC QG (input/output) DOUBLE PRECISION array, dimension\nC (LDQG,N+1)\nC On entry, the leading N-by-N+1 part of this array must\nC contain in columns 1:N the lower triangular part of the\nC matrix Q and in columns 2:N+1 the upper triangular part\nC of the matrix G.\nC On exit, this array is overwritten. If JOB = 'G', the\nC leading N-by-N+1 part of this array contains in columns\nC 2:N+1 the matrix G of decomposition (2).\nC\nC LDQG INTEGER\nC The leading dimension of the array QG. LDQG >= max(1,N).\nC\nC T (output) DOUBLE PRECISION array, dimension (LDT,N)\nC On exit, if JOB = 'S' or JOB = 'G', the leading N-by-N\nC part of this array contains the upper triangular matrix T\nC of the decomposition (2). Otherwise, this array is used as\nC workspace.\nC\nC LDT INTEGER\nC The leading dimension of the array T. LDT >= MAX(1,N).\nC\nC U1 (output) DOUBLE PRECISION array, dimension (LDU1,N)\nC On exit, if JOBU = 'U', the leading N-by-N part of this\nC array contains the (1,1) block of the orthogonal\nC symplectic matrix U of decomposition (2).\nC\nC LDU1 INTEGER\nC The leading dimension of the array U1. LDU1 >= 1.\nC LDU1 >= N, if JOBU = 'U'.\nC\nC U2 (output) DOUBLE PRECISION array, dimension (LDU2,N)\nC On exit, if JOBU = 'U', the leading N-by-N part of this\nC array contains the (2,1) block of the orthogonal\nC symplectic matrix U of decomposition (2).\nC\nC LDU2 INTEGER\nC The leading dimension of the array U2. LDU2 >= 1.\nC LDU2 >= N, if JOBU = 'U'.\nC\nC V1 (output) DOUBLE PRECISION array, dimension (LDV1,N)\nC On exit, if JOBV = 'V', the leading N-by-N part of this\nC array contains the (1,1) block of the orthogonal\nC symplectic matrix V of decomposition (2).\nC\nC LDV1 INTEGER\nC The leading dimension of the array V1. LDV1 >= 1.\nC LDV1 >= N, if JOBV = 'V'.\nC\nC V2 (output) DOUBLE PRECISION array, dimension (LDV2,N)\nC On exit, if JOBV = 'V', the leading N-by-N part of this\nC array contains the (2,1) block of the orthogonal\nC symplectic matrix V of decomposition (2).\nC\nC LDV2 INTEGER\nC The leading dimension of the array V2. LDV2 >= 1.\nC LDV2 >= N, if JOBV = 'V'.\nC\nC WR (output) DOUBLE PRECISION array, dimension (N)\nC WI (output) DOUBLE PRECISION array, dimension (N)\nC On exit, the leading N elements of WR and WI contain the\nC real and imaginary parts, respectively, of N eigenvalues\nC that have nonnegative imaginary part. Their complex\nC conjugate eigenvalues are not stored. If imaginary parts\nC are zero (i.e., for real eigenvalues), only positive\nC eigenvalues are stored.\nC\nC ILO (output) INTEGER\nC ILO is an integer value determined when H was balanced.\nC The balanced A(i,j) = 0 if I > J and J = 1,...,ILO-1.\nC The balanced Q(i,j) = 0 if J = 1,...,ILO-1 or\nC I = 1,...,ILO-1.\nC\nC SCALE (output) DOUBLE PRECISION array, dimension (N)\nC On exit, if BALANC <> 'N', the leading N elements of this\nC array contain details of the permutation and/or scaling\nC factors applied when balancing H, see MB04DD.\nC This array is not referenced if BALANC = 'N'.\nC\nC Workspace\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0, DWORK(1) returns the optimal\nC value of LDWORK, and DWORK(2) returns the 1-norm of the\nC scaled (if BALANC = 'S' or 'B') Hamiltonian matrix.\nC On exit, if INFO = -25, DWORK(1) returns the minimum\nC value of LDWORK.\nC\nC LDWORK (input) INTEGER\nC The dimension of the array DWORK. LDWORK >= max( 2, 8*N ).\nC Moreover:\nC If JOB = 'E' or 'S' and JOBU = 'N' and JOBV = 'N',\nC LDWORK >= 7*N+N*N.\nC If JOB = 'G' and JOBU = 'N' and JOBV = 'N',\nC LDWORK >= max( 7*N+N*N, 2*N+3*N*N ).\nC If JOB = 'G' and JOBU = 'U' and JOBV = 'N',\nC LDWORK >= 7*N+2*N*N.\nC If JOB = 'G' and JOBU = 'N' and JOBV = 'V',\nC LDWORK >= 7*N+2*N*N.\nC If JOB = 'G' and JOBU = 'U' and JOBV = 'V',\nC LDWORK >= 7*N+N*N.\nC For good performance, LDWORK must generally be larger.\nC\nC If LDWORK = -1, then a workspace query is assumed;\nC the routine only calculates the optimal size of the\nC DWORK array, returns this value as the first entry of\nC the DWORK array, and no error message related to LDWORK\nC is issued by XERBLA.\nC\nC Error Indicator\nC\nC INFO (output) INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value;\nC > 0: if INFO = i, the periodic QR algorithm failed to\nC compute all the eigenvalues, elements i+1:N of WR\nC and WI contain eigenvalues which have converged.\nC\nC REFERENCES\nC\nC [1] Benner, P., Mehrmann, V., and Xu, H.\nC A numerically stable, structure preserving method for\nC computing the eigenvalues of real Hamiltonian or symplectic\nC pencils.\nC Numer. Math., Vol. 78(3), pp. 329-358, 1998.\nC\nC [2] Benner, P., Mehrmann, V., and Xu, H.\nC A new method for computing the stable invariant subspace of a\nC real Hamiltonian matrix, J. Comput. Appl. Math., vol. 86,\nC pp. 17-43, 1997.\nC\nC CONTRIBUTORS\nC\nC D. Kressner, Technical Univ. Berlin, Germany, and\nC P. Benner, Technical Univ. Chemnitz, Germany, December 2003.\nC\nC REVISIONS\nC\nC V. Sima, May 2008 (SLICOT version of the HAPACK routine DHAESU).\nC V. Sima, Aug. 2011, Oct. 2011, July 2012, Mar. 2015, May 2015.\nC\nC KEYWORDS\nC\nC Eigenvalues, invariant subspace, Hamiltonian matrix.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, ONE, TWO\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0, TWO = 2.0D0 )\nC .. Scalar Arguments ..\n CHARACTER BALANC, JOB, JOBU, JOBV\n INTEGER ILO, INFO, LDA, LDQG, LDT, LDU1, LDU2, LDV1,\n $ LDV2, LDWORK, N\nC .. Array Arguments ..\n DOUBLE PRECISION A(LDA,*), DWORK(*), QG(LDQG,*), SCALE(*),\n $ T(LDT,*), U1(LDU1,*), U2(LDU2,*), V1(LDV1,*),\n $ V2(LDV2,*), WI(*), WR(*)\nC .. Local Scalars ..\n CHARACTER UCHAR, VCHAR\n LOGICAL LPERM, LQUERY, LSCAL, SCALEH, WANTG, WANTS,\n $ WANTU, WANTV\n INTEGER I, IERR, ILO1, J, K, L, PBETA, PCSL, PCSR, PDW,\n $ PQ, PTAUL, PTAUR, PZ, WRKMIN, WRKOPT\n DOUBLE PRECISION BIGNUM, CSCALE, EPS, HNR1, HNRM, SMLNUM, TEMP,\n $ TEMPI, TEMPR\nC .. External Functions ..\n LOGICAL LSAME\n DOUBLE PRECISION DLAMCH, MA02ID\n EXTERNAL DLAMCH, LSAME, MA02ID\nC .. External Subroutines ..\n EXTERNAL DCOPY, DGEMM, DLABAD, DLACPY, DLASCL, DLASET,\n $ DSCAL, MA01AD, MB03XP, MB04DD, MB04QB, MB04TB,\n $ XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC ABS, DBLE, INT, MAX, SQRT\nC\nC .. Executable Statements ..\nC\nC Decode the scalar input parameters.\nC\n INFO = 0\n LPERM = LSAME( BALANC, 'P' ) .OR. LSAME( BALANC, 'B' )\n LSCAL = LSAME( BALANC, 'S' ) .OR. LSAME( BALANC, 'B' )\n WANTS = LSAME( JOB, 'S' ) .OR. LSAME( JOB, 'G' )\n WANTG = LSAME( JOB, 'G' )\n WANTU = LSAME( JOBU, 'U' )\n WANTV = LSAME( JOBV, 'V' )\nC\n IF ( WANTG ) THEN\n IF ( WANTU .AND. WANTV ) THEN\n WRKMIN = MAX( 2, 7*N + N*N )\n ELSE IF ( .NOT.WANTU .AND. .NOT.WANTV ) THEN\n WRKMIN = MAX( 2, 7*N + N*N, 2*N + 3*N*N )\n ELSE\n WRKMIN = MAX( 2, 7*N + 2*N*N )\n END IF\n ELSE\n IF ( .NOT.WANTU .AND. .NOT.WANTV ) THEN\n WRKMIN = MAX( 2, 7*N + N*N )\n ELSE\n WRKMIN = MAX( 2, 8*N )\n END IF\n END IF\nC\nC Test the scalar input parameters.\nC\n IF ( .NOT.LPERM .AND. .NOT.LSCAL\n $ .AND. .NOT.LSAME( BALANC, 'N' ) ) THEN\n INFO = -1\n ELSE IF ( .NOT.WANTS .AND. .NOT.LSAME( JOB, 'E' ) ) THEN\n INFO = -2\n ELSE IF ( .NOT.WANTU .AND. .NOT.LSAME( JOBU, 'N' ) ) THEN\n INFO = -3\n ELSE IF ( .NOT.WANTV .AND. .NOT.LSAME( JOBV, 'N' ) ) THEN\n INFO = -4\n ELSE IF ( N.LT.0 ) THEN\n INFO = -5\n ELSE IF ( LDA.LT.MAX( 1, N ) ) THEN\n INFO = -7\n ELSE IF ( LDQG.LT.MAX( 1, N ) ) THEN\n INFO = -9\n ELSE IF ( LDT.LT.MAX( 1, N ) ) THEN\n INFO = -11\n ELSE IF ( LDU1.LT.1 .OR. ( WANTU .AND. LDU1.LT.N ) ) THEN\n INFO = -13\n ELSE IF ( LDU2.LT.1 .OR. ( WANTU .AND. LDU2.LT.N ) ) THEN\n INFO = -15\n ELSE IF ( LDV1.LT.1 .OR. ( WANTV .AND. LDV1.LT.N ) ) THEN\n INFO = -17\n ELSE IF ( LDV2.LT.1 .OR. ( WANTV .AND. LDV2.LT.N ) ) THEN\n INFO = -19\n ELSE\n LQUERY = LDWORK.EQ.-1\n IF ( LQUERY ) THEN\n IF ( N.EQ.0 ) THEN\n WRKOPT = TWO\n ELSE\n PTAUR = 5*N\n PDW = PTAUR + N\n IF ( .NOT.WANTU .AND. .NOT.WANTV )\n $ PDW = PDW + N*N\n CALL MB04TB( 'No Transpose', 'Transpose', N, N, DWORK,\n $ LDT, DWORK, LDT, DWORK, LDT, DWORK, LDT,\n $ DWORK, DWORK, DWORK, DWORK, DWORK, -1,\n $ IERR )\n WRKOPT = MAX( WRKMIN, INT( DWORK(1) ) + PDW )\nC\n IF ( WANTU .OR. WANTV ) THEN\n IF ( .NOT.WANTG ) THEN\n PDW = PTAUR + N\n IF ( WANTU .AND. WANTV )\n $ PDW = PDW + N\n ELSE\n PDW = PTAUR + N*N\n IF ( .NOT.WANTU .AND. WANTV )\n $ PDW = PDW + 2*N\n END IF\n CALL MB04QB( 'No Transpose', 'No Transpose',\n $ 'No Transpose','Columnwise',\n $ 'Columnwise', N, N, N, DWORK, LDT, DWORK,\n $ LDT, DWORK, LDT, DWORK, LDT, DWORK,\n $ DWORK, DWORK, -1, IERR )\n WRKOPT = MAX( WRKOPT, INT( DWORK(1) ) + PDW )\n END IF\n END IF\n DWORK(1) = DBLE( WRKOPT )\n RETURN\n ELSE IF ( LDWORK.LT.WRKMIN ) THEN\n DWORK(1) = DBLE( WRKMIN )\n INFO = -25\n END IF\n END IF\nC\nC Return if there were illegal values.\nC\n IF ( INFO.NE.0 ) THEN\n CALL XERBLA( 'MB03XD', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n ILO = 0\n IF( N.EQ.0 ) THEN\n DWORK(1) = TWO\n DWORK(2) = ZERO\n RETURN\n END IF\nC\n EPS = DLAMCH( 'P' )\n SMLNUM = DLAMCH( 'S' )\n BIGNUM = ONE / SMLNUM\n CALL DLABAD( SMLNUM, BIGNUM )\n SMLNUM = SQRT( SMLNUM ) / EPS\n BIGNUM = ONE / SMLNUM\nC\nC Scale H if maximal element is outside range [SMLNUM,BIGNUM].\nC\n HNRM = MA02ID( 'Hamiltonian', 'MaxElement', N, A, LDA, QG, LDQG,\n $ DWORK )\n SCALEH = .FALSE.\n IF ( HNRM.GT.ZERO .AND. HNRM.LT.SMLNUM ) THEN\n SCALEH = .TRUE.\n CSCALE = SMLNUM\n ELSE IF( HNRM.GT.BIGNUM ) THEN\n SCALEH = .TRUE.\n CSCALE = BIGNUM\n END IF\n IF ( SCALEH ) THEN\n CALL DLASCL( 'General', 0, 0, HNRM, CSCALE, N, N, A, LDA, IERR )\n CALL DLASCL( 'General', 0, 0, HNRM, CSCALE, N, N+1, QG, LDQG,\n $ IERR )\n END IF\nC\nC Balance the matrix and compute the 1-norm.\nC\n IF ( LPERM .OR. LSCAL ) THEN\n CALL MB04DD( BALANC, N, A, LDA, QG, LDQG, ILO, SCALE, IERR )\n ELSE\n ILO = 1\n END IF\n HNR1 = MA02ID( 'Hamiltonian', '1-norm', N, A, LDA, QG, LDQG,\n $ DWORK )\nC\nC Copy A to T and multiply A by -1.\nC\n CALL DLACPY( 'All', N, N, A, LDA, T, LDT )\n CALL DLASCL( 'General', 0, 0, ONE, -ONE, N, N, A, LDA, IERR )\nC\nC ---------------------------------------------\nC Step 1: Compute symplectic URV decomposition.\nC ---------------------------------------------\nC\n PCSL = 1\n PCSR = PCSL + 2*N\n PTAUL = PCSR + 2*N\n PTAUR = PTAUL + N\n PDW = PTAUR + N\n\n IF ( .NOT.WANTU .AND. .NOT.WANTV ) THEN\nC\nC Copy Q and Q' to workspace.\nC\n PQ = PDW\n PDW = PDW + N*N\n DO 20 J = 1, N\n K = PQ + (N+1)*(J-1)\n L = K\n DWORK(K) = QG(J,J)\n DO 10 I = J+1, N\n K = K + 1\n L = L + N\n TEMP = QG(I,J)\n DWORK(K) = TEMP\n DWORK(L) = TEMP\n 10 CONTINUE\n 20 CONTINUE\n ELSE IF ( WANTU ) THEN\nC\nC Copy Q and Q' to U2.\nC\n DO 40 J = 1, N\n U2(J,J) = QG(J,J)\n DO 30 I = J+1, N\n TEMP = QG(I,J)\n U2(I,J) = TEMP\n U2(J,I) = TEMP\n 30 CONTINUE\n 40 CONTINUE\n ELSE\nC\nC Copy Q and Q' to V2.\nC\n DO 60 J = 1, N\n V2(J,J) = QG(J,J)\n DO 50 I = J+1, N\n TEMP = QG(I,J)\n V2(I,J) = TEMP\n V2(J,I) = TEMP\n 50 CONTINUE\n 60 CONTINUE\n END IF\nC\nC Transpose G.\nC\n DO 80 J = 1, N\n DO 70 I = J+1, N\n QG(I,J+1) = QG(J,I+1)\n 70 CONTINUE\n 80 CONTINUE\nC\n IF ( .NOT.WANTU .AND. .NOT.WANTV ) THEN\n CALL MB04TB( 'No Transpose', 'Transpose', N, ILO, T, LDT, A,\n $ LDA, QG(1,2), LDQG, DWORK(PQ), N, DWORK(PCSL),\n $ DWORK(PCSR), DWORK(PTAUL), DWORK(PTAUR),\n $ DWORK(PDW), LDWORK-PDW+1, IERR )\n ELSE IF ( WANTU ) THEN\n CALL MB04TB( 'No Transpose', 'Transpose', N, ILO, T, LDT, A,\n $ LDA, QG(1,2), LDQG, U2, LDU2, DWORK(PCSL),\n $ DWORK(PCSR), DWORK(PTAUL), DWORK(PTAUR),\n $ DWORK(PDW), LDWORK-PDW+1, IERR )\n ELSE\n CALL MB04TB( 'No Transpose', 'Transpose', N, ILO, T, LDT, A,\n $ LDA, QG(1,2), LDQG, V2, LDV2, DWORK(PCSL),\n $ DWORK(PCSR), DWORK(PTAUL), DWORK(PTAUR),\n $ DWORK(PDW), LDWORK-PDW+1, IERR )\n END IF\n WRKOPT = MAX( WRKOPT, INT( DWORK(PDW) ) + PDW - 1 )\nC\n IF ( WANTU .AND. .NOT.WANTV .AND. .NOT.WANTG ) THEN\n IF ( N.GT.1 )\n $ CALL DLACPY( 'Lower', N-1, N-1, T(2,1), LDT, QG(2,1), LDQG )\n ELSE IF ( .NOT.WANTU .AND. WANTV .AND. .NOT.WANTG ) THEN\n IF ( N.GT.1 ) THEN\n CALL DLACPY( 'Lower', N-1, N-1, A(2,1), LDA, QG(2,1), LDQG )\n CALL DLACPY( 'Upper', N-1, N-1, V2(1,2), LDV2, QG(1,2),\n $ LDQG )\n END IF\n ELSE IF ( WANTU .AND. WANTV .AND. .NOT.WANTG ) THEN\n IF ( N.GT.1 ) THEN\n CALL DLACPY( 'Lower', N-1, N-1, T(2,1), LDT, V2(2,1), LDV2 )\n CALL DLACPY( 'Lower', N-1, N-1, A(2,1), LDA, QG(2,1), LDQG )\n END IF\n ELSE IF ( WANTU .AND. .NOT.WANTV .AND. WANTG ) THEN\n IF ( N.GT.1 )\n $ CALL DLACPY( 'Lower', N-1, N-1, T(2,1), LDT,\n $ DWORK(PDW+N*N+N), N-1 )\n ELSE IF ( .NOT.WANTU .AND. WANTV .AND. WANTG ) THEN\n IF ( N.GT.2 )\n $ CALL DLACPY( 'Lower', N-2, N-2, A(3,1), LDA,\n $ DWORK(PDW+N*N+N), N-2 )\n ELSE IF ( WANTU .AND. WANTV .AND. WANTG ) THEN\n IF ( N.GT.1 )\n $ CALL DLACPY( 'Lower', N-1, N-1, T(2,1), LDT,\n $ DWORK(PDW+N), N-1 )\n IF ( N.GT.2 )\n $ CALL DLACPY( 'Lower', N-2, N-2, A(3,1), LDA, V2(3,1), LDV2 )\n END IF\nC\nC ----------------------------------------------\nC Step 2: Compute periodic Schur decomposition.\nC ----------------------------------------------\nC\n IF ( N.GT.2 )\n $ CALL DLASET( 'Lower', N-2, N-2, ZERO, ZERO, A(3,1), LDA )\n IF ( N.GT.1 )\n $ CALL DLASET( 'Lower', N-1, N-1, ZERO, ZERO, T(2,1), LDT )\n IF ( .NOT.WANTU .AND. .NOT.WANTV ) THEN\n PBETA = 1\n ELSE\n PBETA = PDW\n END IF\nC\n IF ( .NOT.WANTG ) THEN\nC\nC Workspace requirements: 2*N (8*N with U or V).\nC\n PDW = PBETA + N\n IF ( WANTU ) THEN\n UCHAR = 'I'\n ELSE\n UCHAR = 'N'\n END IF\n IF ( WANTV ) THEN\n VCHAR = 'I'\n ELSE\n VCHAR = 'N'\n END IF\n CALL MB03XP( JOB, VCHAR, UCHAR, N, ILO, N, A, LDA, T, LDT, V1,\n $ LDV1, U1, LDU1, WR, WI, DWORK(PBETA), DWORK(PDW),\n $ LDWORK-PDW+1, INFO )\n IF ( INFO.NE.0 )\n $ GO TO 90\n WRKOPT = MAX( WRKOPT, INT( DWORK(PDW) ) + PDW - 1 )\nC\n ELSE IF ( .NOT.WANTU .AND. .NOT.WANTV ) THEN\nC\nC Workspace requirements: 3*N*N + 2*N.\nC\n PQ = PBETA + N\n PZ = PQ + N*N\n PDW = PZ + N*N\n CALL MB03XP( 'Schur', 'Init', 'Init', N, ILO, N, A, LDA, T,\n $ LDT, DWORK(PQ), N, DWORK(PZ), N, WR, WI,\n $ DWORK(PBETA), DWORK(PDW), LDWORK-PDW+1, INFO )\n IF ( INFO.NE.0 )\n $ GO TO 90\n WRKOPT = MAX( WRKOPT, INT( DWORK(PDW) ) + PDW - 1 )\n CALL DGEMM( 'Transpose', 'No Transpose', N, N, N, ONE,\n $ DWORK(PZ), N, QG(1,2), LDQG, ZERO, DWORK(PDW), N )\n CALL DGEMM( 'No Transpose', 'No Transpose', N, N, N, ONE,\n $ DWORK(PDW), N, DWORK(PQ), N, ZERO, QG(1,2), LDQG )\n ELSE IF ( WANTU .AND. .NOT.WANTV ) THEN\nC\nC Workspace requirements: 2*N*N + 7*N.\nC\n PQ = PBETA + N\n PDW = PQ + N*N\n CALL MB03XP( 'Schur', 'Init', 'Init', N, ILO, N, A, LDA, T,\n $ LDT, DWORK(PQ), N, U1, LDU1, WR, WI, DWORK(PBETA),\n $ DWORK(PDW+(N-1)*(N-1)), LDWORK-PDW-(N-1)*(N-1)+1,\n $ INFO )\n IF ( INFO.NE.0 )\n $ GO TO 90\n WRKOPT = MAX( WRKOPT, INT( DWORK(PDW+(N-1)*(N-1)) ) + PDW\n $ + (N-1)*(N-1) - 1 )\n IF ( N.GT.1 )\n $ CALL DLACPY( 'Lower', N-1, N-1, DWORK(PDW), N-1, T(2,1),\n $ LDT )\n CALL DGEMM( 'Transpose', 'No Transpose', N, N, N, ONE,\n $ U1, LDU1, QG(1,2), LDQG, ZERO, DWORK(PDW), N )\n CALL DGEMM( 'No Transpose', 'No Transpose', N, N, N, ONE,\n $ DWORK(PDW), N, DWORK(PQ), N, ZERO, QG(1,2), LDQG )\nC\n ELSE IF ( .NOT.WANTU .AND. WANTV ) THEN\nC\nC Workspace requirements: 2*N*N + 7*N\nC\n PZ = PBETA + N\n PDW = PZ + N*N\n CALL MB03XP( 'Schur', 'Init', 'Init', N, ILO, N, A, LDA, T,\n $ LDT, V1, LDV1, DWORK(PZ), N, WR, WI, DWORK(PBETA),\n $ DWORK(PDW+(N-1)*(N-1)), LDWORK-PDW-(N-1)*(N-1)+1,\n $ INFO )\n IF ( INFO.NE.0 )\n $ GO TO 90\n WRKOPT = MAX( WRKOPT, INT( DWORK(PDW+(N-1)*(N-1)) ) + PDW\n $ + (N-1)*(N-1) - 1 )\n IF ( N.GT.2 )\n $ CALL DLACPY( 'Lower', N-2, N-2, DWORK(PDW), N-2, A(3,1),\n $ LDA )\n CALL DGEMM( 'Transpose', 'No Transpose', N, N, N, ONE,\n $ DWORK(PZ), N, QG(1,2), LDQG, ZERO, DWORK(PDW), N )\n CALL DGEMM( 'No Transpose', 'No Transpose', N, N, N, ONE,\n $ DWORK(PDW), N, V1, LDV1, ZERO, QG(1,2), LDQG )\nC\n ELSE\nC\nC Workspace requirements: N*N + 7*N.\nC\n PDW = PBETA + N\n CALL MB03XP( 'Schur', 'Init', 'Init', N, ILO, N, A, LDA, T,\n $ LDT, V1, LDV1, U1, LDU1, WR, WI, DWORK(PBETA),\n $ DWORK(PDW+(N-1)*(N-1)), LDWORK-PDW-(N-1)*(N-1)+1,\n $ INFO )\n IF ( INFO.NE.0 )\n $ GO TO 90\n WRKOPT = MAX( WRKOPT, INT( DWORK(PDW+(N-1)*(N-1)) ) + PDW\n $ + (N-1)*(N-1) - 1 )\n IF ( N.GT.1 )\n $ CALL DLACPY( 'Lower', N-1, N-1, DWORK(PDW), N-1, T(2,1),\n $ LDT )\n IF ( N.GT.2 )\n $ CALL DLACPY( 'Lower', N-2, N-2, V2(3,1), LDV2, A(3,1), LDA )\n CALL DGEMM( 'Transpose', 'No Transpose', N, N, N, ONE,\n $ U1, LDU1, QG(1,2), LDQG, ZERO, DWORK(PDW), N )\n CALL DGEMM( 'No Transpose', 'No Transpose', N, N, N, ONE,\n $ DWORK(PDW), N, V1, LDV1, ZERO, QG(1,2), LDQG )\n END IF\nC\n 90 CONTINUE\nC\nC Compute square roots of eigenvalues and rescale.\nC\n I = INFO + 1\nC WHILE I <= N\n 100 CONTINUE\n IF ( I.LE.N ) THEN\n TEMPR = WR(I)\n TEMPI = WI(I)\n TEMP = DWORK(PBETA + I - 1)\n IF ( TEMP.GT.ZERO )\n $ TEMPR = -TEMPR\n TEMP = ABS( TEMP )\n IF ( TEMPI.EQ.ZERO ) THEN\n IF ( TEMPR.LT.ZERO ) THEN\n WR(I) = ZERO\n WI(I) = SQRT( TEMP ) * SQRT( -TEMPR )\n ELSE\n WR(I) = SQRT( TEMP ) * SQRT( TEMPR )\n WI(I) = ZERO\n END IF\n I = I + 1\n ELSE\n CALL MA01AD( TEMPR, TEMPI, WR(I), WI(I) )\n WR(I) = WR(I) * SQRT( TEMP )\n IF ( TEMP.GT.ZERO ) THEN\n WI(I) = WI(I) * SQRT( TEMP )\n ELSE\n WI(I) = ZERO\n END IF\n WR(I+1) = -WR(I)\n WI(I+1) = WI(I)\n I = I + 2\n END IF\n GO TO 100\nC END WHILE\n END IF\nC\n IF ( SCALEH ) THEN\nC\nC Undo scaling.\nC\n CALL DLASCL( 'Hessenberg', 0, 0, CSCALE, HNRM, N, N, A, LDA,\n $ IERR )\n CALL DLASCL( 'Upper', 0, 0, CSCALE, HNRM, N, N, T, LDT, IERR )\n If ( WANTG )\n $ CALL DLASCL( 'General', 0, 0, CSCALE, HNRM, N, N, QG(1,2),\n $ LDQG, IERR )\n CALL DLASCL( 'General', 0, 0, CSCALE, HNRM, N, 1, WR, N, IERR )\n CALL DLASCL( 'General', 0, 0, CSCALE, HNRM, N, 1, WI, N, IERR )\n HNR1 = HNR1 * HNRM / CSCALE\n END IF \nC\n IF ( INFO.NE.0 )\n $ RETURN\nC\n IF ( ILO.GT.N ) THEN\n DWORK(1) = DBLE( WRKOPT )\n DWORK(2) = HNR1\n RETURN\n END IF \nC\nC -----------------------------------------------\nC Step 3: Compute orthogonal symplectic factors.\nC -----------------------------------------------\nC\nC Fix CSL and CSR for MB04QB.\nC\n IF ( WANTU )\n $ CALL DSCAL( N, -ONE, DWORK(PCSL+1), 2 )\n IF ( WANTV )\n $ CALL DSCAL( N-1, -ONE, DWORK(PCSR+1), 2 )\n ILO1 = MIN( N, ILO + 1 )\nC\n IF ( WANTU .AND. .NOT.WANTV .AND. .NOT.WANTG ) THEN\nC\nC Workspace requirements: 7*N.\nC\n PDW = PTAUR\n CALL DCOPY( N, T(1,1), LDT+1, DWORK(PDW), 1 )\n CALL DLACPY( 'Lower', N, N, U2, LDU2, T, LDT )\n CALL DLASET( 'All', N, N, ZERO, ZERO, U2, LDU2 )\n CALL MB04QB( 'No Transpose', 'No Transpose', 'No Transpose',\n $ 'Columnwise', 'Columnwise', N-ILO+1, N, N-ILO+1,\n $ QG(ILO,ILO), LDQG, T(ILO,ILO), LDT, U1(ILO,1),\n $ LDU1, U2(ILO,1), LDU2, DWORK(PCSL+2*ILO-2),\n $ DWORK(PTAUL+ILO-1), DWORK(PDW+N), LDWORK-PDW-N+1,\n $ IERR )\n WRKOPT = MAX( WRKOPT, INT( DWORK(PDW+N) ) + PDW + N - 1 )\n CALL DCOPY( N, DWORK(PDW), 1, T(1,1), LDT+1 )\n IF ( N.GT.1 )\n $ CALL DLASET( 'Lower', N-1, N-1, ZERO, ZERO, T(2,1), LDT )\nC\n ELSE IF ( .NOT.WANTU .AND. WANTV .AND. .NOT.WANTG ) THEN\nC\nC Workspace requirements: 7*N.\nC\n PDW = PTAUR + N\n CALL DLASET( 'All', N, N, ZERO, ZERO, V2, LDV2 )\n CALL MB04QB( 'No Transpose', 'No Transpose', 'No Transpose',\n $ 'Columnwise', 'Rowwise', N-ILO, N, N-ILO,\n $ QG(ILO1,ILO), LDQG, QG(ILO,ILO1), LDQG,\n $ V1(ILO1,1), LDV1, V2(ILO1,1), LDV2,\n $ DWORK(PCSR+2*ILO-2), DWORK(PTAUR+ILO-1),\n $ DWORK(PDW), LDWORK-PDW+1, IERR )\n WRKOPT = MAX( WRKOPT, INT( DWORK(PDW) ) + PDW - 1 )\nC\n ELSE IF ( WANTU .AND. WANTV .AND. .NOT.WANTG ) THEN\nC\nC Workspace requirements: 8*N.\nC\n PDW = PTAUR + N\n CALL DCOPY( N, T(1,1), LDT+1, DWORK(PDW), 1 )\n CALL DLACPY( 'Lower', N, N, V2, LDV2, T, LDT )\n CALL DLASET( 'All', N, N, ZERO, ZERO, V2, LDV2 )\n CALL MB04QB( 'No Transpose', 'No Transpose', 'No Transpose',\n $ 'Columnwise', 'Rowwise', N-ILO, N, N-ILO,\n $ QG(ILO1,ILO), LDQG, U2(ILO,ILO1), LDU2,\n $ V1(ILO1,1), LDV1, V2(ILO1,1), LDV2,\n $ DWORK(PCSR+2*ILO-2), DWORK(PTAUR+ILO-1),\n $ DWORK(PDW+N), LDWORK-PDW-N+1, IERR )\n WRKOPT = MAX( WRKOPT, INT( DWORK(PDW+N) ) + PDW + N - 1 )\nC\n CALL DLACPY( 'Lower', N, N, U2, LDU2, QG, LDQG )\n CALL DLASET( 'All', N, N, ZERO, ZERO, U2, LDU2 )\n CALL MB04QB( 'No Transpose', 'No Transpose', 'No Transpose',\n $ 'Columnwise', 'Columnwise', N-ILO+1, N, N-ILO+1,\n $ T(ILO,ILO), LDT, QG(ILO,ILO), LDQG, U1(ILO,1),\n $ LDU1, U2(ILO,1), LDU2, DWORK(PCSL+2*ILO-2),\n $ DWORK(PTAUL+ILO-1), DWORK(PDW+N), LDWORK-PDW-N+1,\n $ IERR )\n WRKOPT = MAX( WRKOPT, INT( DWORK(PDW+N) ) + PDW + N - 1 )\n CALL DCOPY( N, DWORK(PDW), 1, T(1,1), LDT+1 )\n IF ( N.GT.1 )\n $ CALL DLASET( 'Lower', N-1, N-1, ZERO, ZERO, T(2,1), LDT )\nC\n ELSE IF ( WANTU .AND. .NOT.WANTV .AND. WANTG ) THEN\nC\nC Workspace requirements: 6*N + N*N.\nC\n PQ = PTAUR\n PDW = PQ + N*N\n CALL DLACPY( 'Lower', N, N, U2, LDU2, DWORK(PQ), N )\n CALL DLASET( 'All', N, N, ZERO, ZERO, U2, LDU2 )\n CALL MB04QB( 'No Transpose', 'No Transpose', 'No Transpose',\n $ 'Columnwise', 'Columnwise', N-ILO+1, N, N-ILO+1,\n $ T(ILO,ILO), LDT, DWORK(PQ+(ILO-1)*(N+1)), N,\n $ U1(ILO,1), LDU1, U2(ILO,1), LDU2,\n $ DWORK(PCSL+2*ILO-2), DWORK(PTAUL+ILO-1),\n $ DWORK(PDW), LDWORK-PDW+1, IERR )\n WRKOPT = MAX( WRKOPT, INT( DWORK(PDW) ) + PDW - 1 )\n IF ( N.GT.1 )\n $ CALL DLASET( 'Lower', N-1, N-1, ZERO, ZERO, T(2,1), LDT )\nC\n ELSE IF ( .NOT.WANTU .AND. WANTV .AND. WANTG ) THEN\nC\nC Workspace requirements: 7*N + N*N.\nC\n PQ = PTAUR + N\n PDW = PQ + N*N\n CALL DLACPY( 'Upper', N, N, V2, LDV2, DWORK(PQ), N )\n CALL DLASET( 'All', N, N, ZERO, ZERO, V2, LDV2 )\n CALL MB04QB( 'No Transpose', 'No Transpose', 'No Transpose',\n $ 'Columnwise', 'Rowwise', N-ILO, N, N-ILO,\n $ A(ILO1,ILO), LDA, DWORK(PQ+ILO*N+ILO-1),\n $ N, V1(ILO1,1), LDV1, V2(ILO1,1), LDV2,\n $ DWORK(PCSR+2*ILO-2), DWORK(PTAUR+ILO-1),\n $ DWORK(PDW+N), LDWORK-PDW-N+1, IERR )\n WRKOPT = MAX( WRKOPT, INT( DWORK(PDW+N) ) + PDW + N - 1 )\n IF ( N.GT.2 )\n $ CALL DLASET( 'Lower', N-2, N-2, ZERO, ZERO, A(3,1), LDA )\nC\n ELSE IF ( WANTU .AND. WANTV .AND. WANTG ) THEN\nC\nC Workspace requirements: 6*N + N*N.\nC\n PDW = PTAUR + N\n CALL DLASET( 'All', N, N, ZERO, ZERO, V2, LDV2 )\n CALL MB04QB( 'No Transpose', 'No Transpose', 'No Transpose',\n $ 'Columnwise', 'Rowwise', N-ILO, N, N-ILO,\n $ A(ILO1,ILO), LDA, U2(ILO,ILO1), LDU2, V1(ILO1,1),\n $ LDV1, V2(ILO1,1), LDV2, DWORK(PCSR+2*ILO-2),\n $ DWORK(PTAUR+ILO-1), DWORK(PDW), LDWORK-PDW+1,\n $ IERR )\n WRKOPT = MAX( WRKOPT, INT( DWORK(PDW) ) + PDW - 1 )\nC\n PQ = PTAUR\n PDW = PQ + N*N\n CALL DLACPY( 'Lower', N, N, U2, LDU2, DWORK(PQ), N )\n CALL DLASET( 'All', N, N, ZERO, ZERO, U2, LDU2 )\n CALL MB04QB( 'No Transpose', 'No Transpose', 'No Transpose',\n $ 'Columnwise', 'Columnwise', N-ILO+1, N, N-ILO+1,\n $ T(ILO,ILO), LDT, DWORK(PQ+(ILO-1)*(N+1)), N,\n $ U1(ILO,1), LDU1, U2(ILO,1), LDU2,\n $ DWORK(PCSL+2*ILO-2), DWORK(PTAUL+ILO-1),\n $ DWORK(PDW), LDWORK-PDW+1, IERR )\n WRKOPT = MAX( WRKOPT, INT( DWORK(PDW) ) + PDW - 1 )\n IF ( N.GT.2 )\n $ CALL DLASET( 'Lower', N-2, N-2, ZERO, ZERO, A(3,1), LDA )\n IF ( N.GT.1 )\n $ CALL DLASET( 'Lower', N-1, N-1, ZERO, ZERO, T(2,1), LDT )\n END IF\nC\n DWORK(1) = DBLE( WRKOPT )\n DWORK(2) = HNR1\n RETURN\nC *** Last line of MB03XD ***\n END\n", "meta": {"hexsha": "a60dcc5a274bab85a861bc587c723e4c9bc955dc", "size": 33227, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB03XD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB03XD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB03XD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 38.412716763, "max_line_length": 72, "alphanum_fraction": 0.4746742107, "num_tokens": 11461, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9390248140158417, "lm_q2_score": 0.7025300698514778, "lm_q1q2_score": 0.6596931681828202}} {"text": " SUBROUTINE FD01AD( JP, L, LAMBDA, XIN, YIN, EFOR, XF, EPSBCK,\r\n $ CTETA, STETA, YQ, EPOS, EOUT, SALPH, IWARN,\r\n $ INFO )\r\nC\r\nC SLICOT RELEASE 5.5.\r\nC\r\nC Copyright (c) 2002-2012 NICONET e.V.\r\nC\r\nC PURPOSE\r\nC\r\nC To solve the least-squares filtering problem recursively in time.\r\nC Each subroutine call implements one time update of the solution.\r\nC The algorithm uses a fast QR-decomposition based approach.\r\nC\r\nC ARGUMENTS\r\nC\r\nC Mode Parameters\r\nC\r\nC JP CHARACTER*1\r\nC Indicates whether the user wishes to apply both prediction\r\nC and filtering parts, as follows:\r\nC = 'B': Both prediction and filtering parts are to be\r\nC applied;\r\nC = 'P': Only the prediction section is to be applied.\r\nC\r\nC Input/Output Parameters\r\nC\r\nC L (input) INTEGER\r\nC The length of the impulse response of the equivalent\r\nC transversal filter model. L >= 1.\r\nC\r\nC LAMBDA (input) DOUBLE PRECISION\r\nC Square root of the forgetting factor.\r\nC For tracking capabilities and exponentially stable error\r\nC propagation, LAMBDA < 1.0 (strict inequality) should\r\nC be used. 0.0 < LAMBDA <= 1.0.\r\nC\r\nC XIN (input) DOUBLE PRECISION\r\nC The input sample at instant n.\r\nC (The situation just before and just after the call of\r\nC the routine are denoted by instant (n-1) and instant n,\r\nC respectively.)\r\nC\r\nC YIN (input) DOUBLE PRECISION\r\nC If JP = 'B', then YIN must contain the reference sample\r\nC at instant n.\r\nC Otherwise, YIN is not referenced.\r\nC\r\nC EFOR (input/output) DOUBLE PRECISION\r\nC On entry, this parameter must contain the square root of\r\nC exponentially weighted forward prediction error energy\r\nC at instant (n-1). EFOR >= 0.0.\r\nC On exit, this parameter contains the square root of the\r\nC exponentially weighted forward prediction error energy\r\nC at instant n.\r\nC\r\nC XF (input/output) DOUBLE PRECISION array, dimension (L)\r\nC On entry, this array must contain the transformed forward\r\nC prediction variables at instant (n-1).\r\nC On exit, this array contains the transformed forward\r\nC prediction variables at instant n.\r\nC\r\nC EPSBCK (input/output) DOUBLE PRECISION array, dimension (L+1)\r\nC On entry, the leading L elements of this array must\r\nC contain the normalized a posteriori backward prediction\r\nC error residuals of orders zero through L-1, respectively,\r\nC at instant (n-1), and EPSBCK(L+1) must contain the\r\nC square-root of the so-called \"conversion factor\" at\r\nC instant (n-1).\r\nC On exit, this array contains the normalized a posteriori\r\nC backward prediction error residuals, plus the square root\r\nC of the conversion factor at instant n.\r\nC\r\nC CTETA (input/output) DOUBLE PRECISION array, dimension (L)\r\nC On entry, this array must contain the cosines of the\r\nC rotation angles used in time updates, at instant (n-1).\r\nC On exit, this array contains the cosines of the rotation\r\nC angles at instant n.\r\nC\r\nC STETA (input/output) DOUBLE PRECISION array, dimension (L)\r\nC On entry, this array must contain the sines of the\r\nC rotation angles used in time updates, at instant (n-1).\r\nC On exit, this array contains the sines of the rotation\r\nC angles at instant n.\r\nC\r\nC YQ (input/output) DOUBLE PRECISION array, dimension (L)\r\nC On entry, if JP = 'B', then this array must contain the\r\nC orthogonally transformed reference vector at instant\r\nC (n-1). These elements are also the tap multipliers of an\r\nC equivalent normalized lattice least-squares filter.\r\nC Otherwise, YQ is not referenced and can be supplied as\r\nC a dummy array (i.e., declare this array to be YQ(1) in\r\nC the calling program).\r\nC On exit, if JP = 'B', then this array contains the\r\nC orthogonally transformed reference vector at instant n.\r\nC\r\nC EPOS (output) DOUBLE PRECISION\r\nC The a posteriori forward prediction error residual.\r\nC\r\nC EOUT (output) DOUBLE PRECISION\r\nC If JP = 'B', then EOUT contains the a posteriori output\r\nC error residual from the least-squares filter at instant n.\r\nC\r\nC SALPH (output) DOUBLE PRECISION array, dimension (L)\r\nC The element SALPH(i), i=1,...,L, contains the opposite of\r\nC the i-(th) reflection coefficient for the least-squares\r\nC normalized lattice predictor (whose value is -SALPH(i)).\r\nC\r\nC Warning Indicator\r\nC\r\nC IWARN INTEGER\r\nC = 0: no warning;\r\nC = 1: an element to be annihilated by a rotation is less\r\nC than the machine precision (see LAPACK Library\r\nC routine DLAMCH).\r\nC\r\nC Error Indicator\r\nC\r\nC INFO INTEGER\r\nC = 0: successful exit;\r\nC < 0: if INFO = -i, the i-th argument had an illegal\r\nC value.\r\nC\r\nC METHOD\r\nC\r\nC The output error EOUT at instant n, denoted by EOUT(n), is the\r\nC reference sample minus a linear combination of L successive input\r\nC samples:\r\nC\r\nC L-1\r\nC EOUT(n) = YIN(n) - SUM h_i * XIN(n-i),\r\nC i=0\r\nC\r\nC where YIN(n) and XIN(n) are the scalar samples at instant n.\r\nC A least-squares filter uses those h_0,...,h_{L-1} which minimize\r\nC an exponentially weighted sum of successive output errors squared:\r\nC\r\nC n\r\nC SUM [LAMBDA**(2(n-k)) * EOUT(k)**2].\r\nC k=1\r\nC\r\nC Each subroutine call performs a time update of the least-squares\r\nC filter using a fast least-squares algorithm derived from a\r\nC QR decomposition, as described in references [1] and [2] (the\r\nC notation from [2] is followed in the naming of the arrays).\r\nC The algorithm does not compute the parameters h_0,...,h_{L-1} from\r\nC the above formula, but instead furnishes the parameters of an\r\nC equivalent normalized least-squares lattice filter, which are\r\nC available from the arrays SALPH (reflection coefficients) and YQ\r\nC (tap multipliers), as well as the exponentially weighted input\r\nC signal energy\r\nC\r\nC n L\r\nC SUM [LAMBDA**(2(n-k)) * XIN(k)**2] = EFOR**2 + SUM XF(i)**2.\r\nC k=1 i=1\r\nC\r\nC For more details on reflection coefficients and tap multipliers,\r\nC references [2] and [4] are recommended.\r\nC\r\nC REFERENCES\r\nC\r\nC [1] Proudler, I. K., McWhirter, J. G., and Shepherd, T. J.\r\nC Fast QRD based algorithms for least-squares linear\r\nC prediction.\r\nC Proceedings IMA Conf. Mathematics in Signal Processing\r\nC Warwick, UK, December 1988.\r\nC\r\nC [2] Regalia, P. A., and Bellanger, M. G.\r\nC On the duality between QR methods and lattice methods in\r\nC least-squares adaptive filtering.\r\nC IEEE Trans. Signal Processing, SP-39, pp. 879-891,\r\nC April 1991.\r\nC\r\nC [3] Regalia, P. A.\r\nC Numerical stability properties of a QR-based fast\r\nC least-squares algorithm.\r\nC IEEE Trans. Signal Processing, SP-41, June 1993.\r\nC\r\nC [4] Lev-Ari, H., Kailath, T., and Cioffi, J.\r\nC Least-squares adaptive lattice and transversal filters:\r\nC A unified geometric theory.\r\nC IEEE Trans. Information Theory, IT-30, pp. 222-236,\r\nC March 1984.\r\nC\r\nC NUMERICAL ASPECTS\r\nC\r\nC The algorithm requires O(L) operations for each subroutine call.\r\nC It is backward consistent for all input sequences XIN, and\r\nC backward stable for persistently exciting input sequences,\r\nC assuming LAMBDA < 1.0 (see [3]).\r\nC If the condition of the signal is very poor (IWARN = 1), then the\r\nC results are not guaranteed to be reliable.\r\nC\r\nC FURTHER COMMENTS\r\nC\r\nC 1. For tracking capabilities and exponentially stable error\r\nC propagation, LAMBDA < 1.0 should be used. LAMBDA is typically\r\nC chosen slightly less than 1.0 so that \"past\" data are\r\nC exponentially forgotten.\r\nC 2. Prior to the first subroutine call, the variables must be\r\nC initialized. The following initial values are recommended:\r\nC\r\nC XF(i) = 0.0, i=1,...,L\r\nC EPSBCK(i) = 0.0 i=1,...,L\r\nC EPSBCK(L+1) = 1.0\r\nC CTETA(i) = 1.0 i=1,...,L\r\nC STETA(i) = 0.0 i=1,...,L\r\nC YQ(i) = 0.0 i=1,...,L\r\nC\r\nC EFOR = 0.0 (exact start)\r\nC EFOR = \"small positive constant\" (soft start).\r\nC\r\nC Soft starts are numerically more reliable, but result in a\r\nC biased least-squares solution during the first few iterations.\r\nC This bias decays exponentially fast provided LAMBDA < 1.0.\r\nC If sigma is the standard deviation of the input sequence\r\nC XIN, then initializing EFOR = sigma*1.0E-02 usually works\r\nC well.\r\nC\r\nC CONTRIBUTOR\r\nC\r\nC P. A. Regalia (October 1994).\r\nC Release 4.0: V. Sima, Katholieke Univ. Leuven, Belgium, Dec. 1999.\r\nC\r\nC REVISIONS\r\nC\r\nC -\r\nC\r\nC KEYWORDS\r\nC\r\nC Kalman filtering, least-squares estimator, optimal filtering,\r\nC orthogonal transformation, recursive estimation, QR decomposition.\r\nC\r\nC ******************************************************************\r\nC\r\nC .. Parameters ..\r\n DOUBLE PRECISION ONE, ZERO\r\n PARAMETER ( ONE = 1.0D0, ZERO = 0.0D0 )\r\nC .. Scalar Arguments ..\r\n CHARACTER JP\r\n INTEGER INFO, IWARN, L\r\n DOUBLE PRECISION EFOR, EOUT, EPOS, LAMBDA, XIN, YIN\r\nC .. Array Arguments ..\r\n DOUBLE PRECISION CTETA(*), EPSBCK(*), SALPH(*), STETA(*), XF(*),\r\n $ YQ(*)\r\nC .. Local Scalars ..\r\n LOGICAL BOTH\r\n INTEGER I\r\n DOUBLE PRECISION CTEMP, EPS, FNODE, NORM, TEMP, XFI, YQI\r\nC .. External Functions ..\r\n LOGICAL LSAME\r\n DOUBLE PRECISION DLAMCH, DLAPY2, DNRM2\r\n EXTERNAL DLAMCH, DLAPY2, DNRM2, LSAME\r\nC .. External Subroutines ..\r\n EXTERNAL DLARTG, XERBLA\r\nC .. Intrinsic Functions\r\n INTRINSIC ABS, SQRT\r\nC .. Executable statements ..\r\nC\r\nC Test the input scalar arguments.\r\nC\r\n BOTH = LSAME( JP, 'B' )\r\n IWARN = 0\r\n INFO = 0\r\nC\r\n IF( .NOT.BOTH .AND. .NOT.LSAME( JP, 'P' ) ) THEN\r\n INFO = -1\r\n ELSE IF( L.LT.1 ) THEN\r\n INFO = -2\r\n ELSE IF( ( LAMBDA.LE.ZERO ) .OR. ( LAMBDA.GT.ONE ) ) THEN\r\n INFO = -3\r\n END IF\r\nC\r\n IF ( INFO.NE.0 ) THEN\r\nC\r\nC Error return.\r\nC\r\n CALL XERBLA( 'FD01AD', -INFO )\r\n RETURN\r\n END IF\r\nC\r\nC Computation of the machine precision EPS.\r\nC\r\n EPS = DLAMCH( 'Epsilon' )\r\nC\r\nC Forward prediction rotations.\r\nC\r\n FNODE = XIN\r\nC\r\n DO 10 I = 1, L\r\n XFI = XF(I) * LAMBDA\r\n XF(I) = STETA(I) * FNODE + CTETA(I) * XFI\r\n FNODE = CTETA(I) * FNODE - STETA(I) * XFI\r\n 10 CONTINUE\r\nC\r\n EPOS = FNODE * EPSBCK(L+1)\r\nC\r\nC Update the square root of the prediction energy.\r\nC\r\n EFOR = EFOR * LAMBDA\r\n TEMP = DLAPY2( FNODE, EFOR )\r\n IF ( TEMP.LT.EPS ) THEN\r\n FNODE = ZERO\r\n IWARN = 1\r\n ELSE\r\n FNODE = FNODE * EPSBCK(L+1)/TEMP\r\n END IF\r\n EFOR = TEMP\r\nC\r\nC Calculate the reflection coefficients and the backward prediction\r\nC errors.\r\nC\r\n DO 20 I = L, 1, -1\r\n IF ( ABS( XF(I) ).LT.EPS )\r\n $ IWARN = 1\r\n CALL DLARTG( TEMP, XF(I), CTEMP, SALPH(I), NORM )\r\n EPSBCK(I+1) = CTEMP * EPSBCK(I) - SALPH(I) * FNODE\r\n FNODE = CTEMP * FNODE + SALPH(I) * EPSBCK(I)\r\n TEMP = NORM\r\n 20 CONTINUE\r\nC\r\n EPSBCK(1) = FNODE\r\nC\r\nC Update to new rotation angles.\r\nC\r\n NORM = DNRM2( L, EPSBCK, 1 )\r\n TEMP = SQRT( ( ONE + NORM )*( ONE - NORM ) )\r\n EPSBCK(L+1) = TEMP\r\nC\r\n DO 30 I = L, 1, -1\r\n IF ( ABS( EPSBCK(I) ).LT.EPS )\r\n $ IWARN = 1\r\n CALL DLARTG( TEMP, EPSBCK(I), CTETA(I), STETA(I), NORM )\r\n TEMP = NORM\r\n 30 CONTINUE\r\nC\r\nC Joint process section.\r\nC\r\n IF ( BOTH) THEN\r\n FNODE = YIN\r\nC\r\n DO 40 I = 1, L\r\n YQI = YQ(I) * LAMBDA\r\n YQ(I) = STETA(I) * FNODE + CTETA(I) * YQI\r\n FNODE = CTETA(I) * FNODE - STETA(I) * YQI\r\n 40 CONTINUE\r\nC\r\n EOUT = FNODE * EPSBCK(L+1)\r\n END IF\r\nC\r\n RETURN\r\nC *** Last line of FD01AD ***\r\n END\r\n", "meta": {"hexsha": "addc9bb9d6d20979e02f4dbb20f6530a21915b0b", "size": 13132, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "External/SLICOT/FD01AD.f", "max_stars_repo_name": "bgin/MissileSimulation", "max_stars_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2016-08-28T23:20:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-15T14:43:58.000Z", "max_issues_repo_path": "External/SLICOT/FD01AD.f", "max_issues_repo_name": "bgin/MissileSimulation", "max_issues_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-06-02T21:29:51.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-05T05:59:31.000Z", "max_forks_repo_path": "External/SLICOT/FD01AD.f", "max_forks_repo_name": "bgin/MissileSimulation", "max_forks_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-07-04T22:38:22.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-04T22:38:22.000Z", "avg_line_length": 37.0960451977, "max_line_length": 73, "alphanum_fraction": 0.5725708194, "num_tokens": 3584, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248157222395, "lm_q2_score": 0.7025300573952054, "lm_q1q2_score": 0.659693157684867}} {"text": " SUBROUTINE AB01OD( STAGES, JOBU, JOBV, N, M, A, LDA, B, LDB, U,\n $ LDU, V, LDV, NCONT, INDCON, KSTAIR, TOL, IWORK,\n $ DWORK, LDWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To reduce the matrices A and B using (and optionally accumulating)\nC state-space and input-space transformations U and V respectively,\nC such that the pair of matrices\nC\nC Ac = U' * A * U, Bc = U' * B * V\nC\nC are in upper \"staircase\" form. Specifically,\nC\nC [ Acont * ] [ Bcont ]\nC Ac = [ ], Bc = [ ],\nC [ 0 Auncont ] [ 0 ]\nC\nC and\nC\nC [ A11 A12 . . . A1,p-1 A1p ] [ B1 ]\nC [ A21 A22 . . . A2,p-1 A2p ] [ 0 ]\nC [ 0 A32 . . . A3,p-1 A3p ] [ 0 ]\nC Acont = [ . . . . . . . ], Bc = [ . ],\nC [ . . . . . . ] [ . ]\nC [ . . . . . ] [ . ]\nC [ 0 0 . . . Ap,p-1 App ] [ 0 ]\nC\nC where the blocks B1, A21, ..., Ap,p-1 have full row ranks and\nC p is the controllability index of the pair. The size of the\nC block Auncont is equal to the dimension of the uncontrollable\nC subspace of the pair (A, B). The first stage of the reduction,\nC the \"forward\" stage, accomplishes the reduction to the orthogonal\nC canonical form (see SLICOT library routine AB01ND). The blocks\nC B1, A21, ..., Ap,p-1 are further reduced in a second, \"backward\"\nC stage to upper triangular form using RQ factorization. Each of\nC these stages is optional.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC STAGES CHARACTER*1\nC Specifies the reduction stages to be performed as follows:\nC = 'F': Perform the forward stage only;\nC = 'B': Perform the backward stage only;\nC = 'A': Perform both (all) stages.\nC\nC JOBU CHARACTER*1\nC Indicates whether the user wishes to accumulate in a\nC matrix U the state-space transformations as follows:\nC = 'N': Do not form U;\nC = 'I': U is internally initialized to the unit matrix (if\nC STAGES <> 'B'), or updated (if STAGES = 'B'), and\nC the orthogonal transformation matrix U is\nC returned.\nC\nC JOBV CHARACTER*1\nC Indicates whether the user wishes to accumulate in a\nC matrix V the input-space transformations as follows:\nC = 'N': Do not form V;\nC = 'I': V is initialized to the unit matrix and the\nC orthogonal transformation matrix V is returned.\nC JOBV is not referenced if STAGES = 'F'.\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The actual state dimension, i.e. the order of the\nC matrix A. N >= 0.\nC\nC M (input) INTEGER\nC The actual input dimension. M >= 0.\nC\nC A (input/output) DOUBLE PRECISION array, dimension (LDA,N)\nC On entry, the leading N-by-N part of this array must\nC contain the state transition matrix A to be transformed.\nC If STAGES = 'B', A should be in the orthogonal canonical\nC form, as returned by SLICOT library routine AB01ND.\nC On exit, the leading N-by-N part of this array contains\nC the transformed state transition matrix U' * A * U.\nC The leading NCONT-by-NCONT part contains the upper block\nC Hessenberg state matrix Acont in Ac, given by U' * A * U,\nC of a controllable realization for the original system.\nC The elements below the first block-subdiagonal are set to\nC zero. If STAGES <> 'F', the subdiagonal blocks of A are\nC triangularized by RQ factorization, and the annihilated\nC elements are explicitly zeroed.\nC\nC LDA INTEGER\nC The leading dimension of array A. LDA >= MAX(1,N).\nC\nC B (input/output) DOUBLE PRECISION array, dimension (LDB,M)\nC On entry, the leading N-by-M part of this array must\nC contain the input matrix B to be transformed.\nC If STAGES = 'B', B should be in the orthogonal canonical\nC form, as returned by SLICOT library routine AB01ND.\nC On exit with STAGES = 'F', the leading N-by-M part of\nC this array contains the transformed input matrix U' * B,\nC with all elements but the first block set to zero.\nC On exit with STAGES <> 'F', the leading N-by-M part of\nC this array contains the transformed input matrix\nC U' * B * V, with all elements but the first block set to\nC zero and the first block in upper triangular form.\nC\nC LDB INTEGER\nC The leading dimension of array B. LDB >= MAX(1,N).\nC\nC U (input/output) DOUBLE PRECISION array, dimension (LDU,N)\nC If STAGES <> 'B' or JOBU = 'N', then U need not be set\nC on entry.\nC If STAGES = 'B' and JOBU = 'I', then, on entry, the\nC leading N-by-N part of this array must contain the\nC transformation matrix U that reduced the pair to the\nC orthogonal canonical form.\nC On exit, if JOBU = 'I', the leading N-by-N part of this\nC array contains the transformation matrix U that performed\nC the specified reduction.\nC If JOBU = 'N', the array U is not referenced and can be\nC supplied as a dummy array (i.e. set parameter LDU = 1 and\nC declare this array to be U(1,1) in the calling program).\nC\nC LDU INTEGER\nC The leading dimension of array U.\nC If JOBU = 'I', LDU >= MAX(1,N); if JOBU = 'N', LDU >= 1.\nC\nC V (output) DOUBLE PRECISION array, dimension (LDV,M)\nC If JOBV = 'I', then the leading M-by-M part of this array\nC contains the transformation matrix V.\nC If STAGES = 'F', or JOBV = 'N', the array V is not\nC referenced and can be supplied as a dummy array (i.e. set\nC parameter LDV = 1 and declare this array to be V(1,1) in\nC the calling program).\nC\nC LDV INTEGER\nC The leading dimension of array V.\nC If STAGES <> 'F' and JOBV = 'I', LDV >= MAX(1,M);\nC if STAGES = 'F' or JOBV = 'N', LDV >= 1.\nC\nC NCONT (input/output) INTEGER\nC The order of the controllable state-space representation.\nC NCONT is input only if STAGES = 'B'.\nC\nC INDCON (input/output) INTEGER\nC The number of stairs in the staircase form (also, the\nC controllability index of the controllable part of the\nC system representation).\nC INDCON is input only if STAGES = 'B'.\nC\nC KSTAIR (input/output) INTEGER array, dimension (N)\nC The leading INDCON elements of this array contain the\nC dimensions of the stairs, or, also, the orders of the\nC diagonal blocks of Acont.\nC KSTAIR is input if STAGES = 'B', and output otherwise.\nC\nC Tolerances\nC\nC TOL DOUBLE PRECISION\nC The tolerance to be used in rank determination when\nC transforming (A, B). If the user sets TOL > 0, then\nC the given value of TOL is used as a lower bound for the\nC reciprocal condition number (see the description of the\nC argument RCOND in the SLICOT routine MB03OD); a\nC (sub)matrix whose estimated condition number is less than\nC 1/TOL is considered to be of full rank. If the user sets\nC TOL <= 0, then an implicitly computed, default tolerance,\nC defined by TOLDEF = N*N*EPS, is used instead, where EPS\nC is the machine precision (see LAPACK Library routine\nC DLAMCH).\nC TOL is not referenced if STAGES = 'B'.\nC\nC Workspace\nC\nC IWORK INTEGER array, dimension (M)\nC IWORK is not referenced if STAGES = 'B'.\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0, DWORK(1) returns the optimal value\nC of LDWORK.\nC\nC LDWORK INTEGER\nC The length of the array DWORK.\nC If STAGES <> 'B', LDWORK >= MAX(1, N + MAX(N,3*M));\nC If STAGES = 'B', LDWORK >= MAX(1, M + MAX(N,M)).\nC For optimum performance LDWORK should be larger.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value.\nC\nC METHOD\nC\nC Staircase reduction of the pencil [B|sI - A] is used. Orthogonal\nC transformations U and V are constructed such that\nC\nC\nC |B |sI-A * . . . * * |\nC | 1| 11 . . . |\nC | | A sI-A . . . |\nC | | 21 22 . . . |\nC | | . . * * |\nC [U'BV|sI - U'AU] = |0 | 0 . . |\nC | | A sI-A * |\nC | | p,p-1 pp |\nC | | |\nC |0 | 0 0 sI-A |\nC | | p+1,p+1|\nC\nC\nC where the i-th diagonal block of U'AU has dimension KSTAIR(i),\nC for i = 1,...,p. The value of p is returned in INDCON. The last\nC block contains the uncontrollable modes of the (A,B)-pair which\nC are also the generalized eigenvalues of the above pencil.\nC\nC The complete reduction is performed in two stages. The first,\nC forward stage accomplishes the reduction to the orthogonal\nC canonical form. The second, backward stage consists in further\nC reduction to triangular form by applying left and right orthogonal\nC transformations.\nC\nC REFERENCES\nC\nC [1] Van Dooren, P.\nC The generalized eigenvalue problem in linear system theory.\nC IEEE Trans. Auto. Contr., AC-26, pp. 111-129, 1981.\nC\nC [2] Miminis, G. and Paige, C.\nC An algorithm for pole assignment of time-invariant multi-input\nC linear systems.\nC Proc. 21st IEEE CDC, Orlando, Florida, 1, pp. 62-67, 1982.\nC\nC NUMERICAL ASPECTS\nC\nC The algorithm requires O((N + M) x N**2) operations and is\nC backward stable (see [1]).\nC\nC FURTHER COMMENTS\nC\nC If the system matrices A and B are badly scaled, it would be\nC useful to scale them with SLICOT routine TB01ID, before calling\nC the routine.\nC\nC CONTRIBUTOR\nC\nC Release 3.0: V. Sima, Katholieke Univ. Leuven, Belgium, Nov. 1996.\nC Supersedes Release 2.0 routine AB01CD by M. Vanbegin, and\nC P. Van Dooren, Philips Research Laboratory, Brussels, Belgium.\nC\nC REVISIONS\nC\nC January 14, 1997, February 12, 1998, September 22, 2003.\nC\nC KEYWORDS\nC\nC Controllability, generalized eigenvalue problem, orthogonal\nC transformation, staircase form.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, ONE\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )\nC .. Scalar Arguments ..\n CHARACTER JOBU, JOBV, STAGES\n INTEGER INDCON, INFO, LDA, LDB, LDU, LDV, LDWORK, M, N,\n $ NCONT\n DOUBLE PRECISION TOL\nC .. Array Arguments ..\n INTEGER IWORK(*), KSTAIR(*)\n DOUBLE PRECISION A(LDA,*), B(LDB,*), DWORK(*), U(LDU,*), V(LDV,*)\nC .. Local Scalars ..\n LOGICAL LJOBUI, LJOBVI, LSTAGB, LSTGAB\n INTEGER I, I0, IBSTEP, ITAU, J0, JINI, JWORK, MCRT, MM,\n $ NCRT, WRKOPT\nC .. External Functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\nC .. External Subroutines ..\n EXTERNAL AB01ND, DGERQF, DLACPY, DLASET, DORGRQ, DORMRQ,\n $ DSWAP, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC INT, MAX, MIN\nC .. Executable Statements ..\nC\n INFO = 0\n LJOBUI = LSAME( JOBU, 'I' )\nC\n LSTAGB = LSAME( STAGES, 'B' )\n LSTGAB = LSAME( STAGES, 'A' ).OR.LSTAGB\nC\n IF ( LSTGAB ) THEN\n LJOBVI = LSAME( JOBV, 'I' )\n END IF\nC\nC Test the input scalar arguments.\nC\n IF( .NOT.LSTGAB .AND. .NOT.LSAME( STAGES, 'F' ) ) THEN\n INFO = -1\n ELSE IF( .NOT.LJOBUI .AND. .NOT.LSAME( JOBU, 'N' ) ) THEN\n INFO = -2\n ELSE IF( N.LT.0 ) THEN\n INFO = -4\n ELSE IF( M.LT.0 ) THEN\n INFO = -5\n ELSE IF( LDA.LT.MAX( 1, N ) ) THEN\n INFO = -7\n ELSE IF( LDB.LT.MAX( 1, N ) ) THEN\n INFO = -9\n ELSE IF( LDU.LT.1 .OR. ( LJOBUI .AND. LDU.LT.N ) ) THEN\n INFO = -11\n ELSE IF( .NOT.LSTAGB .AND. LDWORK.LT.MAX( 1, N + MAX( N, 3*M ) )\n $ .OR. LSTAGB .AND. LDWORK.LT.MAX( 1, M + MAX( N, M ) ) )\n $ THEN\n INFO = -20\n ELSE IF( LSTAGB .AND. NCONT.GT.N ) THEN\n INFO = -14\n ELSE IF( LSTAGB .AND. INDCON.GT.N ) THEN\n INFO = -15\n ELSE IF( LSTGAB ) THEN\n IF( .NOT.LJOBVI .AND. .NOT.LSAME( JOBV, 'N' ) ) THEN\n INFO = -3\n ELSE IF( LDV.LT.1 .OR. ( LJOBVI .AND. LDV.LT.M ) ) THEN\n INFO = -13\n END IF\n END IF\nC\n IF ( INFO.NE.0 ) THEN\nC\nC Error return.\nC\n CALL XERBLA( 'AB01OD', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF ( MIN( N, M ).EQ.0 ) THEN\n NCONT = 0\n INDCON = 0\n IF( N.GT.0 .AND. LJOBUI )\n $ CALL DLASET( 'F', N, N, ZERO, ONE, U, LDU )\n IF( LSTGAB ) THEN\n IF( M.GT.0 .AND. LJOBVI )\n $ CALL DLASET( 'F', M, M, ZERO, ONE, V, LDV )\n END IF\n DWORK(1) = ONE\n RETURN\n END IF\nC\nC (Note: Comments in the code beginning \"Workspace:\" describe the\nC minimal amount of real workspace needed at that point in the\nC code, as well as the preferred amount for good performance.\nC NB refers to the optimal block size for the immediately\nC following subroutine, as returned by ILAENV.)\nC\n ITAU = 1\n WRKOPT = 1\nC\n IF ( .NOT.LSTAGB ) THEN\nC\nC Perform the forward stage computations of the staircase\nC algorithm on B and A: reduce the (A, B) pair to orthogonal\nC canonical form.\nC\nC Workspace: N + MAX(N,3*M).\nC\n JWORK = N + 1\n CALL AB01ND( JOBU, N, M, A, LDA, B, LDB, NCONT, INDCON,\n $ KSTAIR, U, LDU, DWORK(ITAU), TOL, IWORK,\n $ DWORK(JWORK), LDWORK-JWORK+1, INFO )\nC\n WRKOPT = INT( DWORK(JWORK) ) + JWORK - 1\n END IF\nC\nC Exit if no further reduction to triangularize B1 and subdiagonal\nC blocks of A is required, or if the order of the controllable part\nC is 0.\nC\n IF ( .NOT.LSTGAB ) THEN\n DWORK(1) = WRKOPT\n RETURN\n ELSE IF ( NCONT.EQ.0 .OR. INDCON.EQ.0 ) THEN\n IF( LJOBVI )\n $ CALL DLASET( 'F', M, M, ZERO, ONE, V, LDV )\n DWORK(1) = WRKOPT\n RETURN\n END IF\nC\nC Now perform the backward steps except the last one.\nC\n MCRT = KSTAIR(INDCON)\n I0 = NCONT - MCRT + 1\n JWORK = M + 1\nC\n DO 10 IBSTEP = INDCON, 2, -1\n NCRT = KSTAIR(IBSTEP-1)\n J0 = I0 - NCRT\n MM = MIN( NCRT, MCRT )\nC\nC Compute the RQ factorization of the current subdiagonal block\nC of A, Ai,i-1 = R*Q (where i is IBSTEP), of dimension\nC MCRT-by-NCRT, starting in position (I0,J0).\nC The matrix Q' should postmultiply U, if required.\nC Workspace: need M + MCRT;\nC prefer M + MCRT*NB.\nC\n CALL DGERQF( MCRT, NCRT, A(I0,J0), LDA, DWORK(ITAU),\n $ DWORK(JWORK), LDWORK-JWORK+1, INFO )\n WRKOPT = MAX( WRKOPT, INT( DWORK(JWORK) )+JWORK-1 )\nC\nC Set JINI to the first column number in A where the current\nC transformation Q is to be applied, taking the block Hessenberg\nC form into account.\nC\n IF ( IBSTEP.GT.2 ) THEN\n JINI = J0 - KSTAIR(IBSTEP-2)\n ELSE\n JINI = 1\nC\nC Premultiply the first block row (B1) of B by Q.\nC Workspace: need 2*M;\nC prefer M + M*NB.\nC\n CALL DORMRQ( 'Left', 'No transpose', NCRT, M, MM, A(I0,J0),\n $ LDA, DWORK(ITAU), B, LDB, DWORK(JWORK),\n $ LDWORK-JWORK+1, INFO )\n WRKOPT = MAX( WRKOPT, INT( DWORK(JWORK) )+JWORK-1 )\n END IF\nC\nC Premultiply the appropriate block row of A by Q.\nC Workspace: need M + N;\nC prefer M + N*NB.\nC\n CALL DORMRQ( 'Left', 'No transpose', NCRT, N-JINI+1, MM,\n $ A(I0,J0), LDA, DWORK(ITAU), A(J0,JINI), LDA,\n $ DWORK(JWORK), LDWORK-JWORK+1, INFO )\n WRKOPT = MAX( WRKOPT, INT( DWORK(JWORK) )+JWORK-1 )\nC\nC Postmultiply the appropriate block column of A by Q'.\nC Workspace: need M + I0-1;\nC prefer M + (I0-1)*NB.\nC\n CALL DORMRQ( 'Right', 'Transpose', I0-1, NCRT, MM, A(I0,J0),\n $ LDA, DWORK(ITAU), A(1,J0), LDA, DWORK(JWORK),\n $ LDWORK-JWORK+1, INFO )\n WRKOPT = MAX( WRKOPT, INT( DWORK(JWORK) )+JWORK-1 )\nC\n IF ( LJOBUI ) THEN\nC\nC Update U, postmultiplying it by Q'.\nC Workspace: need M + N;\nC prefer M + N*NB.\nC\n CALL DORMRQ( 'Right', 'Transpose', N, NCRT, MM, A(I0,J0),\n $ LDA, DWORK(ITAU), U(1,J0), LDU, DWORK(JWORK),\n $ LDWORK-JWORK+1, INFO )\n WRKOPT = MAX( WRKOPT, INT( DWORK(JWORK) )+JWORK-1 )\n END IF\nC\nC Zero the subdiagonal elements of the current subdiagonal block\nC of A.\nC\n CALL DLASET( 'F', MCRT, NCRT-MCRT, ZERO, ZERO, A(I0,J0), LDA )\n IF ( I0.LT.N )\n $ CALL DLASET( 'L', MCRT-1, MCRT-1, ZERO, ZERO,\n $ A(I0+1,I0-MCRT), LDA )\nC\n MCRT = NCRT\n I0 = J0\nC\n 10 CONTINUE\nC\nC Now perform the last backward step on B, V = Qb'.\nC\nC Compute the RQ factorization of the first block of B, B1 = R*Qb.\nC Workspace: need M + MCRT;\nC prefer M + MCRT*NB.\nC\n CALL DGERQF( MCRT, M, B, LDB, DWORK(ITAU), DWORK(JWORK),\n $ LDWORK-JWORK+1, INFO )\n WRKOPT = MAX( WRKOPT, INT( DWORK(JWORK) )+JWORK-1 )\nC\n IF ( LJOBVI ) THEN\nC\nC Accumulate the input-space transformations V.\nC Workspace: need 2*M; prefer M + M*NB.\nC\n CALL DLACPY( 'F', MCRT, M-MCRT, B, LDB, V(M-MCRT+1,1), LDV )\n IF ( MCRT.GT.1 )\n $ CALL DLACPY( 'L', MCRT-1, MCRT-1, B(2,M-MCRT+1), LDB,\n $ V(M-MCRT+2,M-MCRT+1), LDV )\n CALL DORGRQ( M, M, MCRT, V, LDV, DWORK(ITAU), DWORK(JWORK),\n $ LDWORK-JWORK+1, INFO )\nC\n DO 20 I = 2, M\n CALL DSWAP( I-1, V(I,1), LDV, V(1,I), 1 )\n 20 CONTINUE\nC\n WRKOPT = MAX( WRKOPT, INT( DWORK(JWORK) )+JWORK-1 )\n END IF\nC\nC Zero the subdiagonal elements of the submatrix B1.\nC\n CALL DLASET( 'F', MCRT, M-MCRT, ZERO, ZERO, B, LDB )\n IF ( MCRT.GT.1 )\n $ CALL DLASET( 'L', MCRT-1, MCRT-1, ZERO, ZERO, B(2,M-MCRT+1),\n $ LDB )\nC\nC Set optimal workspace dimension.\nC\n DWORK(1) = WRKOPT\n RETURN\nC *** Last line of AB01OD ***\n END\n", "meta": {"hexsha": "6ba6cec8cfffd587405b7130a0acac68b9337af4", "size": 19997, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/AB01OD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/AB01OD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/AB01OD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 38.3084291188, "max_line_length": 72, "alphanum_fraction": 0.533179977, "num_tokens": 6037, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9390248242542283, "lm_q2_score": 0.7025300449389326, "lm_q1q2_score": 0.6596931519820962}} {"text": "!!# FUNCTION MODULE: \nMODULE FUN_xyINTEGRALXY\n\n!!## PURPOSE\n!! Integrates the function $XY$ over a polygon in 2D.\n\n\n!*******************************************************************************\n!\n!! xyINTEGRALXY_Pg integrates the function X*Y over a polygon in 2D.\n!\n! Discussion:\n!\n! The polygon is bounded by the points (X(1:N), Y(1:N)).\n!\n! INTEGRAL = (1/24) * sum ( 1 <= I <= N )\n! ( Y(I) * ( 3 * X(I)**2 + 2 * X(I) * X(I-1) + X(I-1)**2 )\n! + Y(I-1) * ( X(I)**2 + 2 * X(I) * X(I-1) + 3 * X(I-1)**2 ) )\n! * ( Y(I) - Y(I-1) )\n!\n! where X(0) and Y(0) should be replaced by X(N) and Y(N).\n!\n! Modified:\n!\n! 10 July 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Reference:\n!\n! SF Bockman,\n! Generalizing the Formula for Areas of Polygons to Moments,\n! American Mathematical Society Monthly,\n! 1989, pages 131-132.\n!\n! Parameters:\n!\n! Input, integer N, the number of vertices of the polygon.\n! N should be at least 3 for a nonzero INTEGRALXY.\n!\n! Input, real ( kind = 8 ) Pg(2,N), the coordinates of the vertices\n! of the polygon. These vertices should be given in\n! counter clockwise order.\n!\n! Output, real ( kind = 8 ) INTEGRALXY, the value of the integral.\n!\n\n!!## EXTERNAL MODULES\nUSE FUN_Error !!((04-A-FUN_Error.f90))\nUSE FUN_xyAVERAGEX !!((05-A-FUN_xyAVERAGEX.f90))\nUSE FUN_xyINTEGRAL1 !!((06-A-FUN_xyINTEGRAL1.f90))\n\n!!## DEFAULT IMPLICIT\nIMPLICIT NONE\n\n!!## PROCEDURE OVERLOADING\nINTERFACE xyINTEGRALXY_Pg\n MODULE PROCEDURE xyINTEGRALXY_Pg_Rsp\n MODULE PROCEDURE xyINTEGRALXY_Pg_Rdp\nEND INTERFACE\n\n!!## PROCEDURE OVERLOADING\n!INTERFACE xyINTEGRALXY_Ls\n! MODULE PROCEDURE xyINTEGRALXY_Ls_Rsp\n! MODULE PROCEDURE xyINTEGRALXY_Ls_Rdp\n!END INTERFACE\n!\n!!!## PUBLIC ACCESS LIST\n!PUBLIC :: xyINTEGRALXY_Ls\n!PUBLIC :: xyINTEGRALXY_Ls_Rsp\n!PUBLIC :: xyINTEGRALXY_Ls_Rdp\n\n!!## PUBLIC ACCESS LIST\nPUBLIC :: xyINTEGRALXY_Pg\nPUBLIC :: xyINTEGRALXY_Pg_Rsp\nPUBLIC :: xyINTEGRALXY_Pg_Rdp\n\n\n!!## CONTAINED PROCEDURES\nCONTAINS\n\n\n!\n!!!### FUNCTION \n!FUNCTION xyINTEGRALXY_Ls_Rsp( Ls ) RESULT(INTEGRALX)\n!\n!!!#### LOCAL MAPPINGS\n!USE PAR_Constants_Rsp !!((02-A-PAR_Constants_Rsp.f90))\n!USE KND_IntrinsicTypes,ONLY: KIND_R => KIND_Rsp !!((01-A-KND_IntrinsicTypes.f90))\n!INCLUDE \"06-A-FUN_xyINTEGRALXY_Ls.f90.hdr\"\n!!!--begin--\n!INCLUDE \"06-A-FUN_xyINTEGRALXY_Ls.f90.bdy\"\n!!!--end--\n!END FUNCTION\n!\n!\n!\n!!!### FUNCTION \n!FUNCTION xyINTEGRALXY_Ls_Rdp( Ls ) RESULT(INTEGRALX)\n!\n!!!#### LOCAL MAPPINGS\n!USE PAR_Constants_Rdp !!((02-A-PAR_Constants_Rsp.f90))\n!USE KND_IntrinsicTypes,ONLY: KIND_R => KIND_Rdp !!((01-A-KND_IntrinsicTypes.f90))\n!INCLUDE \"06-A-FUN_xyINTEGRALXY_Ls.f90.hdr\"\n!!!--begin--\n!INCLUDE \"06-A-FUN_xyINTEGRALXY_Ls.f90.bdy\"\n!!!--end--\n!END FUNCTION\n\n\n\n\n!!### FUNCTION \nFUNCTION xyINTEGRALXY_Pg_Rsp( N , Pg ) RESULT(INTEGRALXY)\n\n!!#### LOCAL MAPPINGS\nUSE PAR_Constants_Rsp !!((02-A-PAR_Constants_Rsp.f90))\nUSE KND_IntrinsicTypes,ONLY: KIND_R => KIND_Rsp !!((01-A-KND_IntrinsicTypes.f90))\n\nINCLUDE \"07-A-FUN_xyINTEGRALXY_Pg.f90.hdr\"\n\n!!--begin--\nINCLUDE \"07-A-FUN_xyINTEGRALXY_Pg.f90.bdy\"\n!!--end--\n\nEND FUNCTION\n\n\n\n!!### FUNCTION \nFUNCTION xyINTEGRALXY_Pg_Rdp( N , Pg ) RESULT(INTEGRALXY)\n\n!!#### LOCAL MAPPINGS\nUSE PAR_Constants_Rdp !!((02-A-PAR_Constants_Rdp.f90))\nUSE KND_IntrinsicTypes,ONLY: KIND_R => KIND_Rdp !!((01-A-KND_IntrinsicTypes.f90))\n\nINCLUDE \"07-A-FUN_xyINTEGRALXY_Pg.f90.hdr\"\n!!--begin--\nINCLUDE \"07-A-FUN_xyINTEGRALXY_Pg.f90.bdy\"\n\n!!--end--\nEND FUNCTION\n\n\n\n\nEND MODULE\n", "meta": {"hexsha": "fb6f1ee894361778e54faf5eb060628250ddde04", "size": 3754, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/07-A-FUN_xyINTEGRALXY.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/07-A-FUN_xyINTEGRALXY.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/07-A-FUN_xyINTEGRALXY.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.0266666667, "max_line_length": 82, "alphanum_fraction": 0.6417155035, "num_tokens": 1239, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619883, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6596925031301609}} {"text": " subroutine spline_cubic(x,y,xx,yy,n,iflag)\n USE stel_kinds\n implicit none\n!----------------------------------------------------------------------\n! iflag = 0 normal return\n! iflag =-1 x-request outside of bounds\n! iflag =-2 xx arrays with two equal entries or not in correct order\n!----------------------------------------------------------------------\n!-----------------------------------------------\n! D u m m y A r g u m e n t s\n!-----------------------------------------------\n integer, intent(in) :: n\n integer, intent(inout) :: iflag\n real(rprec), intent(in) :: x\n real(rprec), dimension(n), intent(in) :: xx,yy\n!-----------------------------------------------\n! L o c a l V a r i a b l e s\n!-----------------------------------------------\n real(rprec), intent(out) :: y\n real(rprec), dimension(n) :: y2, dxx\n real(rprec) :: yp1, ypn\n real(rprec) :: c\n!-----------------------------------------------\n\n iflag = 0 !initialization\n if(x < xx(1) .or. x > xx(n)) then\n iflag = -1\n y=0.d+0\n return\n endif\n dxx(1:n-1)=xx(2:n)-xx(1:n-1)\n if(minval(dxx(1:n-1)) <= 0.d+0) then\n iflag=-2\n return\n endif\n\n! fix boundary derivatives by quadratic fit\n! left part\n c=((yy(3)-yy(1))/(xx(3)-xx(1))-(yy(2)-yy(1))/(xx(2)-xx(1)))\n > /(xx(3)-xx(2))\n yp1=(yy(2)-yy(1))/(xx(2)-xx(1))-c*(xx(2)-xx(1))\n! right part\n c=((yy(n-2)-yy(n))/(xx(n-2)-xx(n)) \n > -(yy(n-1)-yy(n))/(xx(n-1)-xx(n)))\n > /(xx(n-2)-xx(n-1))\n ypn=(yy(n-1)-yy(n))/(xx(n-1)-xx(n))-c*(xx(n-1)-xx(n))\n\n call spline_nr(xx,yy,n,yp1,ypn,y2)\n call splint_nr(xx,yy,y2,n,x,y)\n\n return\n\n contains\n\n subroutine spline_nr(x,y,n,yp1,ypn,y2)\n! taken from numerical recipes f77 and recoded.\n! Given the arrays x(1:n) and y(1:n) containing the tabulated function\n! with x(1) < x(2) <...< x(n) and given values yp1 and ypn for the first\n! derivative of the interpolating function at points q and n, respectively,\n! this routine returns an array y2(1:n) of length n which contains the\n! second derivatives of the interpolating function at the tabulated points x(i).\n! If yp1 and/or ypn are equatl to 1ed+30 or larger, the routine is signaled\n! to set the correspoinding boundary condition for a natural spline with zero\n! derivative on that boundary.\n! nmax is the largest anticipated value of n.\n integer, intent(in) :: n\n integer, parameter :: nmax=500\n real(rprec), intent(in) :: yp1, ypn\n real(rprec), dimension(n), intent(in) :: x, y\n real(rprec), dimension(n), intent(out) :: y2\n integer :: i,k\n real(rprec) :: p, qn, sig, un\n real(rprec), dimension(n) :: u\n\n if(yp1 > .99d+30) then\n y2(1)=0.d+0\n u(1) =0.d+0\n else\n y2(1)=-0.5d+0\n u(1)=(3.d+0/(x(2)-x(1)))*((y(2)-y(1))/(x(2)-x(1))-yp1)\n endif\n\n do i=2,n-1\n sig=(x(i)-x(i-1))/(x(i+1)-x(i-1))\n p=sig*y2(i-1)+2.d+0\n y2(i)=(sig-1.d+0)/p\n u(i)=(6.d+0*((y(i+1)-y(i))/(x(i+1)-x(i))-(y(i)-y(i-1))\n > /(x(i)-x(i-1)))/(x(i+1)-x(i-1))-sig*u(i-1))/p\n enddo\n if (ypn > .99d+30)then\n qn=0.d+0\n un=0.d+0\n else\n qn=0.5d+0\n un=(3.d+0/(x(n)-x(n-1)))*(ypn-(y(n)-y(n-1))/(x(n)-x(n-1)))\n endif\n y2(n)=(un-qn*u(n-1))/(qn*y2(n-1)+1.d+0)\n do k=n-1,1,-1\n y2(k)=y2(k)*y2(k+1)+u(k)\n enddo\n return\n end subroutine spline_nr\n\n subroutine splint_nr(xa,ya,y2a,n,x,y)\n! Given the arrays xa(1:n) and ya(1:n) of length n, which tabulate a function\n! with the xa(i)'s in order), and given the array y2a(1:n), which is the\n! output from spline above, and given a value of x, this routine returns\n! a cubic-spline interpolated value y.\n implicit none\n integer, intent(in) :: n\n real(rprec), intent(in) :: x\n real(rprec), intent(out) :: y\n real(rprec), dimension(n), intent(in) :: xa, ya, y2a\n!- local -------------------\n real(rprec) :: a, b, h\n integer :: k, khi, klo\n\n klo=1\n khi=n\n do\n if (khi-klo <= 1) exit !inverted num.rec. condition for endless do-loop exit\n k=(khi+klo)/2\n if(xa(k) > x) then\n khi=k\n else\n klo=k\n endif\n enddo\n\n h=xa(khi)-xa(klo)\n if(h ==0.d+0)\n > stop \"spline_cubic: bad xa input! xa(i) have to be distinct!\"\n a=(xa(khi)-x)/h\n b=(x-xa(klo))/h\n y=a*ya(klo)+b*ya(khi) +\n > ((a**3-a)*y2a(klo)+(b**3-b)*y2a(khi))*(h**2)/6.d+0\n return\n end subroutine splint_nr\n\n end subroutine spline_cubic\n\n", "meta": {"hexsha": "31c554a347c236cf99f94c93cb00031e11a306ec", "size": 4637, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "LIBSTELL/Sources/Miscel/spline_cubic.f", "max_stars_repo_name": "joseluisvelasco/STELLOPT", "max_stars_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2020-05-08T01:47:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T10:35:28.000Z", "max_issues_repo_path": "LIBSTELL/Sources/Miscel/spline_cubic.f", "max_issues_repo_name": "joseluisvelasco/STELLOPT", "max_issues_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 77, "max_issues_repo_issues_event_min_datetime": "2020-05-08T07:18:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:20:33.000Z", "max_forks_repo_path": "Sources/LIBSTELL_minimal/spline_cubic.f", "max_forks_repo_name": "mbkumar/VMEC2000", "max_forks_repo_head_hexsha": "334e3bd478f2432b6fe8cbb321f0d81d9a952152", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-02-10T13:47:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T12:53:43.000Z", "avg_line_length": 32.6549295775, "max_line_length": 85, "alphanum_fraction": 0.4906189347, "num_tokens": 1582, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619883, "lm_q2_score": 0.76908023177796, "lm_q1q2_score": 0.6596924985901932}} {"text": " PROGRAM xgaucof\r\nC driver for routine gaucof\r\n INTEGER NP\r\n REAL SQRTPI\r\n PARAMETER(NP=64,SQRTPI=1.7724539)\r\n INTEGER i,n\r\n REAL amu0,check,a(NP),b(NP),x(NP),w(NP)\r\n1 write(*,*) 'Enter N'\r\n read(*,*,END=99) n\r\n do 11 i=1,n-1\r\n a(i)=0.\r\n b(i+1)=i*.5\r\n11 continue\r\n a(n)=0.\r\nC b(1) is arbitrary for call to TQLI\r\n amu0=SQRTPI\r\n call gaucof(n,a,b,amu0,x,w)\r\n write(*,'(/1x,t3,a,t10,a,t22,a/)') '#','X(I)','W(I)'\r\n do 12 i=1,n\r\n write(*,'(1x,i2,2e14.6)') i,x(i),w(i)\r\n12 continue\r\n check=0.\r\n do 13 i=1,n\r\n check=check+w(i)\r\n13 continue\r\n write(*,'(/1x,a,e15.7,a,e15.7)') 'Check value:',check,\r\n * ' should be:',SQRTPI\r\n go to 1\r\n99 stop\r\n END\r\n", "meta": {"hexsha": "6474fbfc61530834d2c3e4d81ef89257b798f601", "size": 790, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xgaucof.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xgaucof.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xgaucof.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.4838709677, "max_line_length": 61, "alphanum_fraction": 0.4772151899, "num_tokens": 310, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182186, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.6596924964848027}} {"text": " SUBROUTINE SPOINT(ALP,X,Y,D,SD,CD,DISL1,DISL2,DISL3,\n * U1,U2,U3,U11,U12,U21,U22,U31,U32)\nC*****\nC***** SURFACE DISPLACEMENT,STRAIN,TILT DUE TO BURIED POINT SOURCE\nC***** IN A SEMIINFINITE MEDIUM CODED BY Y.OKADA ... JAN 1985\nC*****\nC***** INPUT\nC***** ALP : MEDIUM CONSTANT MYU/(LAMDA+MYU)\nC***** X,Y : COORDINATE OF STATION\nC***** D : SOURCE DEPTH\nC***** SD,CD : SIN,COS OF DIP-ANGLE\nC***** (CD=0.D0, SD=+/-1.D0 SHOULD BE GIVEN FOR VERTICAL FAULT)\nC***** DISL1,DISL2,DISL3 : STRIKE-, DIP- AND TENSILE-DISLOCATION\nC*****\nC***** OUTPUT\nC***** U1, U2, U3 : DISPLACEMENT ( UNIT= UNIT OF DISL / AREA )\nC***** U11,U12,U21,U22 : STRAIN ( UNIT= UNIT OF DISL /\nC***** U31,U32 : TILT UNIT OF X,Y,D /AREA )\nC*****\n IMPLICIT REAL*8 (A-H,O-Z)\n DATA F0,F1,F2,F3,F4,F5,F8,F9\n * /0.D0, 1.D0, 2.D0, 3.D0, 4.D0, 5.D0, 8.D0, 9.D0/\n PI2=6.283185307179586D0\nC*****\n P =Y*CD + D*SD\n Q =Y*SD - D*CD\n S =P*SD + Q*CD\n X2=X*X\n Y2=Y*Y\n XY=X*Y\n D2=D*D\n R2=X2 + Y2 + D2\n R =SQRT(R2)\n R3=R *R2\n R5=R3*R2\n QR=F3*Q/R5\n XR =F5*X2/R2\n YR =F5*Y2/R2\n XYR=F5*XY/R2\n DR =F5*D /R2\n RD =R + D\n R12=F1/(R*RD*RD)\n R32=R12*(F2*R + D)/ R2\n R33=R12*(F3*R + D)/(R2*RD)\n R53=R12*(F8*R2 + F9*R*D + F3*D2)/(R2*R2*RD)\n R54=R12*(F5*R2 + F4*R*D + D2)/R3*R12\nC*****\n A1= ALP*Y*(R12-X2*R33)\n A2= ALP*X*(R12-Y2*R33)\n A3= ALP*X/R3 - A2\n A4=-ALP*XY*R32\n A5= ALP*( F1/(R*RD) - X2*R32 )\n B1= ALP*(-F3*XY*R33 + F3*X2*XY*R54)\n B2= ALP*( F1/R3 - F3*R12 + F3*X2*Y2*R54)\n B3= ALP*( F1/R3 - F3*X2/R5) - B2\n B4=-ALP*F3*XY/R5 - B1\n C1=-ALP*Y*(R32 - X2*R53)\n C2=-ALP*X*(R32 - Y2*R53)\n C3=-ALP*F3*X*D/R5 - C2\nC*****\n U1 =F0\n U2 =F0\n U3 =F0\n U11=F0\n U12=F0\n U21=F0\n U22=F0\n U31=F0\n U32=F0\nC**************************************\nC***** *****\nC***** STRIKE-SLIP CONTRIBUTION *****\nC***** *****\nC**************************************\n IF(DISL1.EQ.F0) GO TO 200\n UN=DISL1/PI2\n QRX=QR*X\n FX=F3*X/R5*SD\n U1 =U1 - UN*( QRX*X + A1*SD )\n U2 =U2 - UN*( QRX*Y + A2*SD )\n U3 =U3 - UN*( QRX*D + A4*SD )\n U11=U11- UN*( QRX* (F2-XR) + B1*SD )\n U12=U12- UN*(-QRX*XYR + FX*X + B2*SD )\n U21=U21- UN*( QR*Y*(F1-XR) + B2*SD )\n U22=U22- UN*( QRX *(F1-YR) + FX*Y + B4*SD )\n U31=U31- UN*( QR*D*(F1-XR) + C1*SD )\n U32=U32- UN*(-QRX*DR*Y + FX*D + C2*SD )\nC**************************************\nC***** *****\nC***** DIP-SLIP CONTRIBUTION *****\nC***** *****\nC**************************************\n 200 IF(DISL2.EQ.F0) GO TO 300\n UN=DISL2/PI2\n SDCD=SD*CD\n QRP=QR*P\n FS=F3*S/R5\n U1 =U1 - UN*( QRP*X - A3*SDCD )\n U2 =U2 - UN*( QRP*Y - A1*SDCD )\n U3 =U3 - UN*( QRP*D - A5*SDCD )\n U11=U11- UN*( QRP*(F1-XR) - B3*SDCD )\n U12=U12- UN*(-QRP*XYR + FS*X - B1*SDCD )\n U21=U21- UN*(-QRP*XYR - B1*SDCD )\n U22=U22- UN*( QRP*(F1-YR) + FS*Y - B2*SDCD )\n U31=U31- UN*(-QRP*DR*X - C3*SDCD )\n U32=U32- UN*(-QRP*DR*Y + FS*D - C1*SDCD )\nC****************************************\nC***** *****\nC***** TENSILE-FAULT CONTRIBUTION *****\nC***** *****\nC****************************************\n 300 IF(DISL3.EQ.F0) GO TO 900\n UN=DISL3/PI2\n SDSD=SD*SD\n QRQ=QR*Q\n FQ=F2*QR*SD\n U1 =U1 + UN*( QRQ*X - A3*SDSD )\n U2 =U2 + UN*( QRQ*Y - A1*SDSD )\n U3 =U3 + UN*( QRQ*D - A5*SDSD )\n U11=U11+ UN*( QRQ*(F1-XR) - B3*SDSD )\n U12=U12+ UN*(-QRQ*XYR + FQ*X - B1*SDSD )\n U21=U21+ UN*(-QRQ*XYR - B1*SDSD )\n U22=U22+ UN*( QRQ*(F1-YR) + FQ*Y - B2*SDSD )\n U31=U31+ UN*(-QRQ*DR*X - C3*SDSD )\n U32=U32+ UN*(-QRQ*DR*Y + FQ*D - C1*SDSD )\nC*****\n 900 RETURN\n END\n SUBROUTINE SRECTF(ALP,X,Y,DEP,AL,AW,SD,CD,DISL1,DISL2,DISL3,\n * U1,U2,U3,U11,U12,U21,U22,U31,U32)\nC*****\nC***** SURFACE DISPLACEMENTS,STRAINS AND TILTS DUE TO RECTANGULAR\nC***** FAULT IN A HALF-SPACE CODED BY Y.OKADA ... JAN 1985\nC*****\nC***** INPUT\nC***** ALP : MEDIUM CONSTANT MYU/(LAMDA+MYU)\nC***** X,Y : COORDINATE OF STATION\nC***** DEP : SOURCE DEPTH\nC***** AL,AW : LENGTH AND WIDTH OF FAULT\nC***** SD,CD : SIN,COS OF DIP-ANGLE\nC***** (CD=0.D0, SD=+/-1.D0 SHOULD BE GIVEN FOR VERTICAL FAULT)\nC***** DISL1,DISL2,DISL3 : STRIKE-, DIP- AND TENSILE-DISLOCATION\nC*****\nC***** OUTPUT\nC***** U1, U2, U3 : DISPLACEMENT ( UNIT= UNIT OF DISL )\nC***** U11,U12,U21,U22 : STRAIN ( UNIT= UNIT OF DISL /\nC***** U31,U32 : TILT UNIT OF X,Y,,,AW )\nC*****\nC***** SUBROUTINE USED...SRECTG\nC*****\n IMPLICIT REAL*8 (A-H,O-Z)\n DIMENSION U(9),DU(9)\n DATA F0, F1 / 0.D0, 1.D0 /\nC*****\n P = Y*CD + DEP*SD\n Q = Y*SD - DEP*CD\nC*****\n DO 1111 I=1,9\n 1111 U(I)=F0\nC*****\n DO 5555 K=1,2\n IF(K.EQ.1) ET=P\n IF(K.EQ.2) ET=P-AW\n DO 4444 J=1,2\n IF(J.EQ.1) XI=X\n IF(J.EQ.2) XI=X-AL\n JK=J+K\n IF(JK.NE.3) SIGN= F1\n IF(JK.EQ.3) SIGN=-F1\n CALL SRECTG(ALP,XI,ET,Q,SD,CD,DISL1,DISL2,DISL3,\n * DU(1),DU(2),DU(3),DU(4),DU(5),DU(6),DU(7),DU(8),DU(9))\n DO 3333 I=1,9\n U(I)=U(I)+SIGN*DU(I)\n 3333 CONTINUE\n 4444 CONTINUE\n 5555 CONTINUE\n U1 =U(1)\n U2 =U(2)\n U3 =U(3)\n U11=U(4)\n U12=U(5)\n U21=U(6)\n U22=U(7)\n U31=U(8)\n U32=U(9)\n RETURN\n END\n SUBROUTINE SRECTG(ALP,XI,ET,Q,SD,CD,DISL1,DISL2,DISL3,\n * U1,U2,U3,U11,U12,U21,U22,U31,U32)\nC*****\nC***** INDEFINITE INTEGRAL OF SURFACE DISPLACEMENTS, STRAINS AND TILTS\nC***** DUE TO FINITE FAULT IN A SEMIINFINITE MEDIUM\nC***** CODED BY Y.OKADA ... JAN 1985\nC***** INPUT\nC***** ALP : MEDIUM CONSTANT MYU/(LAMDA+MYU)\nC***** XI,ET,Q : FAULT COORDINATE\nC***** SD,CD : SIN,COS OF DIP-ANGLE\nC***** (CD=0.D0, SD=+/-1.D0 SHOULD BE GIVEN FOR VERTICAL FAULT)\nC***** DISL1,DISL2,DISL3 : STRIKE-, DIP- AND TENSILE-DISLOCATION\nC*****\nC***** OUTPUT\nC***** U1, U2, U3 : DISPLACEMENT ( UNIT= UNIT OF DISL )\nC***** U11,U12,U21,U22 : STRAIN ( UNIT= UNIT OF DISL /\nC***** U31,U32 : TILT UNIT OF XI,ET,Q )\nC*****\n IMPLICIT REAL*8 (A-H,O-Z)\n DATA F0,F1,F2/ 0.D0, 1.D0, 2.D0 /\n PI2=6.283185307179586D0\nC*****\n XI2=XI*XI\n ET2=ET*ET\n Q2=Q*Q\n R2=XI2+ET2+Q2\n R =DSQRT(R2)\n R3=R*R2\n D =ET*SD-Q*CD\n Y =ET*CD+Q*SD\n RET=R+ET\n IF(RET.LT.F0) RET=F0\n RD =R+D\n RRD=F1/(R*RD)\nC*****\n IF( Q .NE.F0) TT = DATAN( XI*ET/(Q*R) )\n IF( Q .EQ.F0) TT = F0\n IF(RET.NE.F0) RE = F1/RET\n IF(RET.EQ.F0) RE = F0\n IF(RET.NE.F0) DLE= DLOG(RET)\n IF(RET.EQ.F0) DLE=-DLOG(R-ET)\n! === Modification to prevent zero-division. ===================================\n! RRX=F1/(R*(R+XI))\n IF(ABS(R*(R+XI)).LT.1.0D-6) THEN\n RRX=1.0D6\n ELSE\n RRX=F1/(R*(R+XI))\n ENDIF\n! ==============================================================================\n RRE=RE/R\n AXI=(F2*R+XI)*RRX*RRX/R\n AET=(F2*R+ET)*RRE*RRE/R\n IF(CD.EQ.F0) GO TO 20\nC*****\nC***** INCLINED FAULT\nC*****\n TD=SD/CD\n X =DSQRT(XI2+Q2)\n IF(XI.EQ.F0) A5=F0\n IF(XI.NE.F0)\n *A5= ALP*F2/CD*DATAN( (ET*(X+Q*CD)+X*(R+X)*SD) / (XI*(R+X)*CD) )\n A4= ALP/CD*( DLOG(RD) - SD*DLE )\n A3= ALP*(Y/RD/CD - DLE) + TD*A4\n A1=-ALP/CD*XI/RD - TD*A5\n C1= ALP/CD*XI*(RRD - SD*RRE)\n C3= ALP/CD*(Q*RRE - Y*RRD)\n B1= ALP/CD*(XI2*RRD - F1)/RD - TD*C3\n B2= ALP/CD*XI*Y*RRD/RD - TD*C1\n GO TO 30\nC*****\nC***** VERTICAL FAULT\nC*****\n 20 RD2=RD*RD\n A1=-ALP/F2*XI*Q/RD2\n A3= ALP/F2*( ET/RD + Y*Q/RD2 - DLE )\n A4=-ALP*Q/RD\n A5=-ALP*XI*SD/RD\n B1= ALP/F2* Q /RD2*(F2*XI2*RRD - F1)\n B2= ALP/F2*XI*SD/RD2*(F2*Q2 *RRD - F1)\n C1= ALP*XI*Q*RRD/RD\n C3= ALP*SD/RD*(XI2*RRD - F1)\nC*****\n 30 A2=-ALP*DLE - A3\n B3=-ALP*XI*RRE - B2\n B4=-ALP*( CD/R + Q*SD*RRE ) - B1\n C2= ALP*(-SD/R + Q*CD*RRE ) - C3\nC*****\n U1 =F0\n U2 =F0\n U3 =F0\n U11=F0\n U12=F0\n U21=F0\n U22=F0\n U31=F0\n U32=F0\nC**************************************\nC***** *****\nC***** STRIKE-SLIP CONTRIBUTION *****\nC***** *****\nC**************************************\n IF(DISL1.EQ.F0) GO TO 200\n UN=DISL1/PI2\n REQ=RRE*Q\n U1 =U1 - UN*( REQ*XI + TT + A1*SD )\n U2 =U2 - UN*( REQ*Y + Q*CD*RE + A2*SD )\n U3 =U3 - UN*( REQ*D + Q*SD*RE + A4*SD )\n U11=U11+ UN*( XI2*Q*AET - B1*SD )\n U12=U12+ UN*( XI2*XI*( D/(ET2+Q2)/R3 - AET*SD ) - B2*SD )\n U21=U21+ UN*( XI*Q/R3*CD + (XI*Q2*AET - B2)*SD )\n U22=U22+ UN*( Y *Q/R3*CD + (Q*SD*(Q2*AET-F2*RRE)\n * -(XI2+ET2)/R3*CD - B4)*SD )\n U31=U31+ UN*(-XI*Q2*AET*CD + (XI*Q/R3 - C1)*SD )\n U32=U32+ UN*( D*Q/R3*CD + (XI2*Q*AET*CD - SD/R + Y*Q/R3 - C2)*SD )\nC**************************************\nC***** *****\nC***** DIP-SLIP CONTRIBUTION *****\nC***** *****\nC**************************************\n 200 IF(DISL2.EQ.F0) GO TO 300\n UN=DISL2/PI2\n SDCD=SD*CD\n U1 =U1 - UN*( Q/R - A3*SDCD )\n U2 =U2 - UN*( Y*Q*RRX + CD*TT - A1*SDCD )\n U3 =U3 - UN*( D*Q*RRX + SD*TT - A5*SDCD )\n U11=U11+ UN*( XI*Q/R3 + B3*SDCD )\n U12=U12+ UN*( Y *Q/R3 - SD/R + B1*SDCD )\n U21=U21+ UN*( Y *Q/R3 + Q*CD*RRE + B1*SDCD )\n U22=U22+ UN*( Y*Y*Q*AXI - (F2*Y*RRX + XI*CD*RRE)*SD + B2*SDCD )\n U31=U31+ UN*( D *Q/R3 + Q*SD*RRE + C3*SDCD )\n U32=U32+ UN*( Y*D*Q*AXI - (F2*D*RRX + XI*SD*RRE)*SD + C1*SDCD )\nC****************************************\nC***** *****\nC***** TENSILE-FAULT CONTRIBUTION *****\nC***** *****\nC****************************************\n 300 IF(DISL3.EQ.F0) GO TO 900\n UN=DISL3/PI2\n SDSD=SD*SD\n U1 =U1 + UN*( Q2*RRE - A3*SDSD )\n U2 =U2 + UN*(-D*Q*RRX - SD*(XI*Q*RRE - TT) - A1*SDSD )\n U3 =U3 + UN*( Y*Q*RRX + CD*(XI*Q*RRE - TT) - A5*SDSD )\n U11=U11- UN*( XI*Q2*AET + B3*SDSD )\n U12=U12- UN*(-D*Q/R3 - XI2*Q*AET*SD + B1*SDSD )\n U21=U21- UN*( Q2*(CD/R3 + Q*AET*SD) + B1*SDSD )\n U22=U22- UN*((Y*CD-D*SD)*Q2*AXI - F2*Q*SD*CD*RRX\n * - (XI*Q2*AET - B2)*SDSD )\n U31=U31- UN*( Q2*(SD/R3 - Q*AET*CD) + C3*SDSD )\n U32=U32- UN*((Y*SD+D*CD)*Q2*AXI + XI*Q2*AET*SD*CD\n * - (F2*Q*RRX - C1)*SDSD )\nC*****\n 900 RETURN\n END\n", "meta": {"hexsha": "74407d67f1828d2cb4109bec5075dfaa75d8d545", "size": 11173, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/okada.sub.f", "max_stars_repo_name": "J-Taniguchi/jagurs", "max_stars_repo_head_hexsha": "f9c9eb711fbd6b2cff45563ca95e99cedab32b4a", "max_stars_repo_licenses": ["MIT"], "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/okada.sub.f", "max_issues_repo_name": "J-Taniguchi/jagurs", "max_issues_repo_head_hexsha": "f9c9eb711fbd6b2cff45563ca95e99cedab32b4a", "max_issues_repo_licenses": ["MIT"], "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/okada.sub.f", "max_forks_repo_name": "J-Taniguchi/jagurs", "max_forks_repo_head_hexsha": "f9c9eb711fbd6b2cff45563ca95e99cedab32b4a", "max_forks_repo_licenses": ["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.7653958944, "max_line_length": 80, "alphanum_fraction": 0.4220889645, "num_tokens": 4813, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9664104972521579, "lm_q2_score": 0.6825737408694988, "lm_q1q2_score": 0.6596464283249579}} {"text": "!==========================================================================\nelemental function gsw_z_from_p (p, lat) \n!==========================================================================\n!\n! Calculates the height z from pressure p\n!\n! p : sea pressure [dbar]\n! lat : latitude [deg]\n! \n! gsw_z_from_p : height [m]\n!--------------------------------------------------------------------------\n\nuse gsw_mod_toolbox, only : gsw_enthalpy_sso_0\n\nuse gsw_mod_teos10_constants, only : deg2rad, gamma\n\nuse gsw_mod_kinds\n\nimplicit none\n\nreal (r8), intent(in) :: p, lat \n\nreal (r8) :: gsw_z_from_p\n\nreal (r8) :: sin2, b, c, a\n\nsin2 = sin(lat*deg2rad)**2\nb = 9.780327_r8*(1.0_r8 + (5.2792e-3_r8 + (2.32e-5_r8*sin2))*sin2) \na = -0.5_r8*gamma*b \nc = gsw_enthalpy_sso_0(p)\n\ngsw_z_from_p = -2.0_r8*c/(b + sqrt(b*b - 4.0_r8*a*c))\n\nreturn \nend function\n\n!--------------------------------------------------------------------------\n", "meta": {"hexsha": "3007f487495cf25ad3102289a0e0d7fec02fb067", "size": 1034, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "MOM6-interface/MOM6/pkg/GSW-Fortran/toolbox/gsw_z_from_p.f90", "max_stars_repo_name": "minsukji/ci-debug", "max_stars_repo_head_hexsha": "3e8bbbe6652b702b61d2896612f6aa8e4aa6c803", "max_stars_repo_licenses": ["Apache-2.0", "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": "MOM6-interface/MOM6/pkg/GSW-Fortran/toolbox/gsw_z_from_p.f90", "max_issues_repo_name": "minsukji/ci-debug", "max_issues_repo_head_hexsha": "3e8bbbe6652b702b61d2896612f6aa8e4aa6c803", "max_issues_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-05-21T20:21:16.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-06T17:52:34.000Z", "max_forks_repo_path": "MOM6-interface/MOM6/pkg/GSW-Fortran/toolbox/gsw_z_from_p.f90", "max_forks_repo_name": "minsukji/ci-debug", "max_forks_repo_head_hexsha": "3e8bbbe6652b702b61d2896612f6aa8e4aa6c803", "max_forks_repo_licenses": ["Apache-2.0", "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": 27.2105263158, "max_line_length": 75, "alphanum_fraction": 0.4023210832, "num_tokens": 270, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475683211323, "lm_q2_score": 0.6992544210587585, "lm_q1q2_score": 0.659639957743581}} {"text": "* STERN-BROCOT SEQUENCE - FORTRAN IV\n DIMENSION ISB(2400)\n NN=2400\n ISB(1)=1\n ISB(2)=1\n I=1\n J=2\n K=2\n 1 IF(K.GE.NN) GOTO 2\n K=K+1\n ISB(K)=ISB(K-I)+ISB(K-J)\n K=K+1\n ISB(K)=ISB(K-J)\n I=I+1\n J=J+1\n GOTO 1\n 2 N=15\n WRITE(*,101) N\n 101 FORMAT(1X,'FIRST',I4)\n WRITE(*,102) (ISB(I),I=1,15)\n 102 FORMAT(15I4)\n DO 5 J=1,11\n JJ=J\n IF(J.EQ.11) JJ=100\n DO 3 I=1,K\n IF(ISB(I).EQ.JJ) GOTO 4\n 3 CONTINUE\n 4 WRITE(*,103) JJ,I\n 103 FORMAT(1X,'FIRST',I4,' AT ',I4)\n 5 CONTINUE\n END\n", "meta": {"hexsha": "308acfad8b9d4fa188d14ea0b918edbb914daf90", "size": 623, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Stern-Brocot-sequence/Fortran/stern-brocot-sequence-1.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-05T13:42:20.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-05T13:42:20.000Z", "max_issues_repo_path": "Task/Stern-Brocot-sequence/Fortran/stern-brocot-sequence-1.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Stern-Brocot-sequence/Fortran/stern-brocot-sequence-1.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.46875, "max_line_length": 39, "alphanum_fraction": 0.4446227929, "num_tokens": 283, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392909114836, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6596161913107371}} {"text": " SUBROUTINE KPLTST (G1,G2,G3,G4)\r\nC\r\nC THIS ROUTINE WILL VERIFY THAT THE 4 GRID POINTS IN 3 SPACE LIE IN\r\nC AN APPROXIMATE PLANE. IF NOT THE NOGO FLAG IS SET TRUE AND A\r\nC MESSAGE IS WRITEN.\r\nC\r\n LOGICAL NOGO\r\n INTEGER OUT\r\n REAL G1(3),G2(3),G3(3),G4(3)\r\n CHARACTER UFM*23,UWM*25\r\n COMMON /XMSSG / UFM,UWM\r\n COMMON /SYSTEM/ SYSBUF,OUT,NOGO\r\n COMMON /SMA1ET/ ID\r\n COMMON /SMA1DP/ R13(3),R24(3),RXR(3),R(3)\r\nC\r\n R13(1) = G3(1) - G1(1)\r\n R13(2) = G3(2) - G1(2)\r\n R13(3) = G3(3) - G1(3)\r\n R24(1) = G4(1) - G2(1)\r\n R24(2) = G4(2) - G2(2)\r\n R24(3) = G4(3) - G2(3)\r\n CALL SAXB (R13,R24,RXR)\r\nC\r\nC NORMALIZE\r\nC\r\n DL = SQRT(RXR(1)**2 + RXR(2)**2 + RXR(3)**2)\r\n IF (DL) 20,20,10\r\n 10 RXR(1) = RXR(1)/DL\r\n RXR(2) = RXR(2)/DL\r\n RXR(3) = RXR(3)/DL\r\n R1L = SQRT(R13(1)**2 + R13(2)**2 + R13(3)**2)\r\n R2L = SQRT(R24(1)**2 + R24(2)**2 + R24(3)**2)\r\n DL = AMIN1(R1L,R2L)\r\n R(1) = G2(1) - G1(1)\r\n R(2) = G2(2) - G1(2)\r\n R(3) = G2(3) - G1(3)\r\n DH = SADOTB(R,RXR)\r\n IF (DL) 20,20,15\r\n 15 IF (ABS(DH/DL) .LE. 0.10) RETURN\r\nC\r\nC NOT PLANER\r\nC\r\n 20 CALL PAGE2 (-2)\r\n WRITE (OUT,30) UWM,ID\r\n 30 FORMAT (A25,' 4000, ONE SIDE OF ELEMENT',I10,\r\n 1 ' CONNECTING FOUR POINTS IS NOT APPROXIMATELY PLANER.')\r\n RETURN\r\n END\r\n", "meta": {"hexsha": "3849518475b89af7d1c644321f329ee41bb15443", "size": 1443, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "mis/kpltst.f", "max_stars_repo_name": "ldallolio/NASTRAN-95", "max_stars_repo_head_hexsha": "6d2c175f5b53ebaec4ba2b5186f7926ef9d0ed47", "max_stars_repo_licenses": ["NASA-1.3"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2016-01-09T14:33:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-18T11:51:42.000Z", "max_issues_repo_path": "mis/kpltst.f", "max_issues_repo_name": "gassive/NASTRAN95", "max_issues_repo_head_hexsha": "98cb3acaa7990d639360601648498834c7782056", "max_issues_repo_licenses": ["NASA-1.3"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2016-01-17T07:30:19.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-06T19:37:44.000Z", "max_forks_repo_path": "mis/kpltst.f", "max_forks_repo_name": "gassive/NASTRAN95", "max_forks_repo_head_hexsha": "98cb3acaa7990d639360601648498834c7782056", "max_forks_repo_licenses": ["NASA-1.3"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-04-07T20:51:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T14:16:01.000Z", "avg_line_length": 29.4489795918, "max_line_length": 72, "alphanum_fraction": 0.4753984754, "num_tokens": 644, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460333, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6596161844720373}} {"text": " subroutine gauinv(p,xp,ierr)\n!-----------------------------------------------------------------------\n\n! Computes the inverse of the standard normal cumulative distribution\n! function with a numerical approximation from : Statistical Computing,\n! by W.J. Kennedy, Jr. and James E. Gentle, 1980, p. 95.\n\n\n\n! INPUT/OUTPUT:\n\n! p = double precision cumulative probability value: dble(psingle)\n! xp = G^-1 (p) in single precision\n! ierr = 1 - then error situation (p out of range), 0 - OK\n\n\n!-----------------------------------------------------------------------\n real*8 :: p0,p1,p2,p3,p4,q0,q1,q2,q3,q4,y,pp,lim,p\n save p0,p1,p2,p3,p4,q0,q1,q2,q3,q4,lim\n\n! Coefficients of approximation:\n\n data lim/1.0e-10/\n data p0/-0.322232431088/,p1/-1.0/,p2/-0.342242088547/, &\n p3/-0.0204231210245/,p4/-0.0000453642210148/\n data q0/0.0993484626060/,q1/0.588581570495/,q2/0.531103462366/, &\n q3/0.103537752850/,q4/0.0038560700634/\n\n! Check for an error situation:\n\n ierr = 1\n if(p < lim) then\n xp = -1.0e10\n return\n end if\n if(p > (1.0-lim)) then\n xp = 1.0e10\n return\n end if\n ierr = 0\n\n! Get k for an error situation:\n\n pp = p\n if(p > 0.5) pp = 1 - pp\n xp = 0.0\n if(p == 0.5) return\n\n! Approximate the function:\n\n y = dsqrt(dlog(1.0/(pp*pp)))\n xp = real( y + ((((y*p4+p3)*y+p2)*y+p1)*y+p0) / &\n ((((y*q4+q3)*y+q2)*y+q1)*y+q0) )\n if(real(p) == real(pp)) xp = -xp\n\n! Return with G^-1(p):\n\n return\n end subroutine gauinv\n", "meta": {"hexsha": "d23ca766fab10709d3966b87b1f612eaee3fdbf7", "size": 1524, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gslib/gslib/gauinv.f90", "max_stars_repo_name": "opengeostat/gslib_new_code", "max_stars_repo_head_hexsha": "ecd00cfcb9654ef8d0fe28c649405fb71595e42e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "gslib/gslib/gauinv.f90", "max_issues_repo_name": "opengeostat/gslib_new_code", "max_issues_repo_head_hexsha": "ecd00cfcb9654ef8d0fe28c649405fb71595e42e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gslib/gslib/gauinv.f90", "max_forks_repo_name": "opengeostat/gslib_new_code", "max_forks_repo_head_hexsha": "ecd00cfcb9654ef8d0fe28c649405fb71595e42e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-01-03T12:19:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-03T12:19:42.000Z", "avg_line_length": 25.4, "max_line_length": 72, "alphanum_fraction": 0.5393700787, "num_tokens": 539, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460333, "lm_q2_score": 0.746138993030751, "lm_q1q2_score": 0.6596161794816137}} {"text": "program matrix\n implicit none\n integer, parameter :: ROWS = 3, COLS = 5\n real, dimension(ROWS, COLS) :: A\n integer :: i, j\n real :: total\n\n A = reshape([ (((i - 1)*size(A, 2) + j, j=1,size(A, 2)), i=1,size(A, 1)) ], &\n shape(A))\n do i = 1, size(A, 1)\n print *, A(i, :)\n end do\n total = 0.0\n do j = 1, size(A, 2)\n do i = 1, size(A, 1)\n total = total + A(i, j)**2\n end do\n end do\n print '(/, A, F10.2)', 'total = ', total\nend program matrix\n", "meta": {"hexsha": "bd9b244973af5fd7bf8b28413c66bc91d6fbfb6a", "size": 522, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source_code/arrays/matrix.f90", "max_stars_repo_name": "caguerra/Fortran-MOOC", "max_stars_repo_head_hexsha": "fb8a9c24e62ce5f388deb06b21e3009aea6b78d4", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2021-05-20T12:03:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-16T19:46:26.000Z", "max_issues_repo_path": "source_code/arrays/matrix.f90", "max_issues_repo_name": "caguerra/Fortran-MOOC", "max_issues_repo_head_hexsha": "fb8a9c24e62ce5f388deb06b21e3009aea6b78d4", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-09-30T04:25:50.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-06T08:21:30.000Z", "max_forks_repo_path": "source_code/arrays/matrix.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": 24.8571428571, "max_line_length": 81, "alphanum_fraction": 0.4578544061, "num_tokens": 193, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563336, "lm_q2_score": 0.7461389873857264, "lm_q1q2_score": 0.6596161790503234}} {"text": "program ch0501\n ! Simple Arithmetic Expressions in Fortran\n implicit none\n\n real :: gross_wage, net_wage, tax\n real :: tax_rate = 0.25\n integer :: personal_allowance = 10000\n character(60) :: their_name\n\n print *, ' Input employees name'\n read *, their_name\n print *, ' Input Gross wage'\n read *, gross_wage\n tax = (gross_wage-personal_allowance)*tax_rate\n net_wage = gross_wage-tax\n print *, ' Employee: ', their_name\n print *, ' Gross Pay: ', gross_wage\n print *, ' Tax: ', tax\n print *, ' Net Pay:', net_wage\nend program\n", "meta": {"hexsha": "96e66a2ed6c304dfe23d270232cdaf3d1e4f1476", "size": 572, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ch05/ch0501.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": "ch05/ch0501.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": "ch05/ch0501.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": 27.2380952381, "max_line_length": 50, "alphanum_fraction": 0.6433566434, "num_tokens": 162, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357327, "lm_q2_score": 0.7461389873857264, "lm_q1q2_score": 0.6596161699320566}} {"text": "| simple Body Mass Index calculator\n\nvariable height\nvariable weight\n\n: hello cr .\" BMI calculator 1.0\" cr ;\n: getheight\n\tcr\n\t.\" Please enter your height, in centimeters: \"\n\tpad 10 accept\n\tdup if\n\t\tpad swap eval height !\n\t;then\n\tdrop\n\tgetheight\n\t;\n: getweight\n\tcr\n\t.\" Please enter your weight in kilograms: \"\n\tpad 10 accept\n\tdup if\n\t\tpad swap eval weight !\n\t;then\n\tdrop\n\tgetweight\n\t;\n\n: showbmi\n\tcr\n\t.\" For a weight of \" weight ? .\" kg,\" \n\t.\" and height of \" height ? .\" cm,\" \n\t.\" the BMI is: \"\n\t\tweight @\n\t\t100000 height @ dup * */ \n\t\t10 /mod (.) type '. emit .\n\tcr\n\t;\nhello getheight getweight showbmi bye\n", "meta": {"hexsha": "011b7c67234062ab227f8166cb84737ee6ec629f", "size": 608, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "examples/bmi.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/bmi.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/bmi.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": 15.5897435897, "max_line_length": 47, "alphanum_fraction": 0.6480263158, "num_tokens": 197, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894661025424, "lm_q2_score": 0.7371581741774411, "lm_q1q2_score": 0.6596013691053575}} {"text": "!\n! Spin-weighted associated Legendre function routines, along with\n! Legendre polynomial roots and weights for Gaussian qudrature to\n! go to/from coefficient and real space\n!\nmodule mod_swal \n!=============================================================================\n use mod_prec\n use mod_field, only: field, set_level\n use mod_io, only: set_arr\n use mod_params, only: &\n nx, ny, nl, max_l, &\n min_m, max_m, min_s, max_s\n\n implicit none\n!=============================================================================\n private\n\n ! gauss points y, cos(y), sin(y)\n real(rp), allocatable, protected, public :: Yvec(:), cyvec(:), syvec(:) \n real(rp), allocatable, protected, public :: Yarr(:,:), cyarr(:,:), syarr(:,:)\n\n ! subroutines \n public :: swal_init, compute_swal_laplacian, swal_lower, swal_raise\n\n public :: swal_filter\n\n public :: swal_test_orthonormal, swal_test_to_from\n\n public :: swal_real_to_coef\n\n ! weights for Gaussian integration \n real(rp), allocatable :: weights(:)\n\n ! going to/from swal sapce\n real(rp), allocatable, protected, public :: swal(:,:,:,:)\n\n ! evaluate in real space \n real(rp), allocatable :: &\n laplacian(:,:,:,:), lower(:,:,:,:), raise(:,:,:,:), low_pass(:,:,:,:) \n!=============================================================================\ncontains\n!=============================================================================\n integer(ip) function compute_lmin(spin, m_ang) result(lmin)\n integer(ip), intent(in) :: spin, m_ang\n\n lmin = max(abs(spin),abs(m_ang))\n end function compute_lmin\n!=============================================================================\n subroutine swal_init()\n character(:), allocatable :: mstr, sstr\n integer(ip) :: m_ang, spin, i, j, k, min_l\n !-----------------------------------------------------------------\n allocate(Yvec(ny))\n allocate(cyvec(ny))\n allocate(syvec(ny))\n allocate(Yarr(nx,ny))\n allocate(cyarr(nx,ny)) \n allocate(syarr(nx,ny)) \n\n allocate(weights(ny))\n\n allocate(swal(ny,0:max_l,min_m:max_m,min_s:max_s))\n allocate(laplacian(ny,ny,min_m:max_m,min_s:max_s)) \n allocate(lower( ny,ny,min_m:max_m,min_s:max_s))\n allocate(raise( ny,ny,min_m:max_m,min_s:max_s))\n allocate(low_pass( ny,ny,min_m:max_m,min_s:max_s))\n !-----------------------------------------------------------------\n call set_arr('roots_legendre.txt', ny, Yvec)\n\n call set_arr('cos.txt', ny, cyvec)\n call set_arr('sin.txt', ny, syvec)\n\n do i=1,nx\n Yarr(i,:) = Yvec\n cyarr(i,:) = cyvec\n syarr(i,:) = syvec\n end do\n !-----------------------------------------------------------------\n ! weights for Gaussian quadrature\n call set_arr('weights_legendre.txt', ny, weights)\n !-----------------------------------------------------------------\n ! spin-weighted spherical associated Legendre polynomials \n do spin=min_s,max_s\n\n sstr = ' '\n write (sstr,'(i5)') spin\n sstr = trim(adjustl(sstr))\n\n do m_ang=min_m,max_m\n\n mstr = ' '\n write (mstr,'(i5)') m_ang\n mstr = trim(adjustl(mstr))\n\n call set_arr('s_'//sstr//'_m_' //mstr//'.txt', ny,nl,swal(:,:,m_ang,spin))\n end do\n end do\n !-----------------------------------------------------------------\n ! precompute swal laplacian array\n !-----------------------------------------------------------------\n laplacian = 0\n do spin =min_s,max_s\n do m_ang=min_m,max_m\n do i=1,ny\n do j=1,ny\n min_l = compute_lmin(spin, m_ang)\n\n do k=min_l,max_l\n laplacian(j,i,m_ang,spin) = laplacian(j,i,m_ang,spin) &\n - real(k-spin,rp)*real(k+spin+1,rp) &\n *weights(j)*swal(j,k,m_ang,spin) &\n *swal(i,k,m_ang,spin)\n end do\n end do\n end do\n end do\n end do\n !-----------------------------------------------------------------\n ! precompute raising array\n !-----------------------------------------------------------------\n raise = 0\n do spin =min_s,max_s-1\n do m_ang=min_m,max_m\n do i=1,ny\n do j=1,ny\n min_l = max(abs(spin), abs(spin+1), abs(m_ang))\n\n do k=min_l,max_l\n raise(j,i,m_ang,spin) = raise(j,i,m_ang,spin) &\n + sqrt(real(k-spin,rp)*real(k+spin+1.0_rp,rp)) &\n *weights(j)*swal(j,k,m_ang,spin) &\n *swal(i,k,m_ang,spin+1)\n end do\n end do\n end do\n end do\n end do\n !-----------------------------------------------------------------\n ! precompute lowering array\n !-----------------------------------------------------------------\n lower = 0\n do spin =min_s+1,max_s\n do m_ang=min_m, max_m\n do i=1,ny\n do j=1,ny\n min_l = max(abs(spin), abs(spin-1), abs(m_ang))\n\n do k=min_l,max_l\n lower(j,i,m_ang,spin) = lower(j,i,m_ang,spin) &\n - sqrt(real(k+spin,rp)*real(k-spin+1,rp)) &\n *weights(j)*swal(j,k,m_ang,spin) &\n *swal(i,k,m_ang,spin-1)\n end do\n end do\n end do\n end do\n end do\n !-----------------------------------------------------------------\n ! precompute swal low-pass filter array\n !-----------------------------------------------------------------\n low_pass = 0\n do spin =min_s,max_s\n do m_ang=min_m,max_m\n do i=1,ny\n do j=1,ny\n do k=0,max_l\n low_pass(j,i,m_ang,spin) = low_pass(j,i,m_ang,spin) &\n + exp(-40.0_rp*(real(k,rp)/real(max_l,rp))**16) &\n *weights(j)*swal(j,k,m_ang,spin) &\n *swal(i,k,m_ang,spin)\n end do\n end do\n end do\n end do\n end do\n !-----------------------------------------------------------------\n !-----------------------------------------------------------------\n end subroutine swal_init\n!=============================================================================\n! Gaussian quadrature.\n! Integrate against complex conjugate cc[s_Y^m_l]=(-1)^{m+s} {-s}_Y^{-m}_l\n!=============================================================================\n subroutine swal_real_to_coef(spin,m_ang,vals,coefs)\n integer(ip), intent(in) :: spin\n integer(ip), intent(in) :: m_ang\n complex(rp), dimension(nx, ny,min_m:max_m), intent(in) :: vals\n complex(rp), dimension(nx,0:max_l,min_m:max_m), intent(out) :: coefs\n\n integer(ip) :: lmin, j, k\n\n lmin = compute_lmin(spin,m_ang)\n\n coefs(:,:,m_ang) = 0.0_rp\n\n do k=lmin,max_l\n do j=1,ny\n coefs(:,k,m_ang) = &\n coefs(:,k,m_ang) &\n + (vals(:,j,m_ang) * weights(j) * swal(j,k,m_ang,spin))\n end do\n end do\n end subroutine swal_real_to_coef\n!=============================================================================\n! coefficient synthesis\n!=============================================================================\n subroutine swal_coef_to_real(spin,m_ang,coefs,vals)\n integer(ip), intent(in) :: spin\n integer(ip), intent(in) :: m_ang\n complex(rp), dimension(nx,0:max_l,min_m:max_m), intent(in) :: coefs\n complex(rp), dimension(nx, ny,min_m:max_m), intent(out) :: vals\n\n integer(ip) :: lmin, j, k\n\n lmin = compute_lmin(spin,m_ang)\n vals(:,:,m_ang) = 0.0_rp\n\n do j=1,ny\n do k=lmin,max_l\n vals(:,j,m_ang) = &\n vals(:,j,m_ang) &\n + (coefs(:,k,m_ang) * swal(j,k,m_ang,spin))\n end do\n end do\n end subroutine swal_coef_to_real\n!=============================================================================\n subroutine swal_laplacian(spin,m_ang,vals,vals_lap)\n integer(ip), intent(in) :: spin\n integer(ip), intent(in) :: m_ang\n complex(rp), dimension(nx,ny,min_m:max_m), intent(in) :: vals\n complex(rp), dimension(nx,ny,min_m:max_m), intent(out) :: vals_lap\n\n integer(ip) :: j, jp\n\n vals_lap(:,:,m_ang) = 0\n\n do j =1,ny\n do jp=1,ny\n vals_lap(:,j,m_ang) = vals_lap(:,j,m_ang) &\n + vals(:,jp,m_ang)*laplacian(jp,j,m_ang,spin)\n end do\n end do\n\n end subroutine swal_laplacian\n!=============================================================================\n subroutine compute_swal_laplacian(step,m_ang,f)\n integer(ip), intent(in) :: step, m_ang\n type(field), intent(inout) :: f\n\n call set_level(step,m_ang,f)\n\n call swal_laplacian(f%spin,m_ang,f%level,f%swal_lap)\n\n end subroutine compute_swal_laplacian\n!=============================================================================\n subroutine swal_lower(spin,m_ang,vals,vals_lowered)\n integer(ip), intent(in) :: spin\n integer(ip), intent(in) :: m_ang\n complex(rp), dimension(nx,ny,min_m:max_m), intent(in) :: vals\n complex(rp), dimension(nx,ny,min_m:max_m), intent(out) :: vals_lowered \n\n integer(ip) :: j, jp\n\n vals_lowered(:,:,m_ang) = 0\n\n do j =1,ny\n do jp=1,ny\n vals_lowered(:,j,m_ang) = vals_lowered(:,j,m_ang) &\n + vals(:,jp,m_ang)*lower(jp,j,m_ang,spin)\n end do\n end do\n\n end subroutine swal_lower\n!=============================================================================\n subroutine swal_raise(spin,m_ang,vals,vals_raised)\n integer(ip), intent(in) :: spin\n integer(ip), intent(in) :: m_ang\n complex(rp), dimension(nx,ny,min_m:max_m), intent(in) :: vals\n complex(rp), dimension(nx,ny,min_m:max_m), intent(out) :: vals_raised\n\n integer(ip) :: j, jp\n\n vals_raised(:,:,m_ang) = 0\n\n do j =1,ny\n do jp=1,ny\n vals_raised(:,j,m_ang) = vals_raised(:,j,m_ang) &\n + vals(:,jp,m_ang)*raise(jp,j,m_ang,spin)\n end do\n end do\n\n end subroutine swal_raise\n!=============================================================================\n! Low pass filter. A smooth filter appears to help prevent Gibbs-like ringing\n!=============================================================================\n subroutine swal_filter(m_ang,f)\n integer(ip), intent(in) :: m_ang\n type(field), intent(inout) :: f\n\n integer(ip) :: j, jp\n\n f%level(:,:,m_ang) = 0\n\n do j =1,ny\n do jp=1,ny\n f%level(:,j,m_ang) = f%level(:,j,m_ang) &\n + f%np1(:,jp,m_ang)*low_pass(jp,j,m_ang,f%spin)\n end do\n end do\n\n f%np1(:,:,m_ang) = f%level(:,:,m_ang)\n\n end subroutine swal_filter\n!=============================================================================\n! test that the swal are orthogonal\n!=============================================================================\n subroutine swal_test_orthonormal()\n\n integer(ip) :: s, m, l1, l2, j\n real(rp) :: integral\n\n write (*,*) 'swal_test_orthonormal'\n\n do s=min_s,max_s\n do m=min_m,max_m\n do l1= 0,max_l\n do l2=l1,max_l\n integral = 0.0_rp\n do j=1,ny \n integral = integral + weights(j)*swal(j,l1,m,s)*swal(j,l2,m,s)!*(((-1.0_rp)**(m+s))*swal(j,l2,-m,-s))\n end do\n if (abs(integral)>1e-14) then\n write (*,*) s,m,l1,l2,integral\n end if\n end do \n end do \n end do \n end do \n\n end subroutine swal_test_orthonormal\n!=============================================================================\n subroutine swal_test_to_from(spin,m_ang,vals_in,coefs,vals_out)\n integer(ip), intent(in) :: spin, m_ang\n complex(rp), dimension(nx,ny, min_m:max_m), intent(in) :: vals_in\n complex(rp), dimension(nx,0:max_l,min_m:max_m), intent(inout) :: coefs\n complex(rp), dimension(nx,ny, min_m:max_m), intent(out) :: vals_out\n\n write(*,*) \"swal_test_to_from. spin: \", spin, \", m_ang: \", m_ang\n\n call swal_real_to_coef(spin,m_ang,vals_in,coefs)\n call swal_coef_to_real(spin,m_ang,coefs,vals_out)\n\n end subroutine swal_test_to_from\n!=============================================================================\nend module mod_swal\n", "meta": {"hexsha": "c5aed64f6bea5780a8a0eb7360805a4e21dba4d9", "size": 12272, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/mod_swal.f90", "max_stars_repo_name": "JLRipley314/teuk-fortran", "max_stars_repo_head_hexsha": "18e04c9ad70db4e0d26f96dc27349f79323f44c8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-11-02T18:31:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-24T21:22:39.000Z", "max_issues_repo_path": "src/mod_swal.f90", "max_issues_repo_name": "JLRipley314/teuk-fortran", "max_issues_repo_head_hexsha": "18e04c9ad70db4e0d26f96dc27349f79323f44c8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/mod_swal.f90", "max_forks_repo_name": "JLRipley314/teuk-fortran", "max_forks_repo_head_hexsha": "18e04c9ad70db4e0d26f96dc27349f79323f44c8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-07-06T01:42:52.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-24T21:22:42.000Z", "avg_line_length": 34.4719101124, "max_line_length": 113, "alphanum_fraction": 0.4534713168, "num_tokens": 3088, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894717137996, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6596013680748882}} {"text": "!==============================================================================\n! CALCULO DE LOS COEFICIENTES DE VAN DER WAALS A PARTIR DE LOS ARCHIVOS DE\n! LOS ARCHIVOS DE LA G(r) OBTENIDOS DE LA SIMULACION CON POTENCIAL SW \n!\n! AUTOR : MARTIN ALEJANDRO PAREDES SOSA\n!==============================================================================\n\n!DECLARACION DE VARIABLES\nProgram Waals\n !Use Basic\n Implicit None\n Integer :: DENS ! PARA NOMBRE DE ARCHIVO\n Integer :: State ! ESTADO DE LECTURA\n Integer :: k, i, j ! CONTADOR\n Character (len=3), Parameter :: Start = \"gdr\" ! NOMBRE DE ARCHIVO DE ENTRADA\n Character (len=4), Parameter :: En = \".dat\" ! EXTENSION ARCHIVO DE ENTRADA\n Character (len=10):: Filename, cons ! NOMBRE DE ARCHIVO\n Real, Parameter :: PI = 4.0 * ATAN(1.0) ! VALOR DE PI\n Real, Parameter :: TP = 1.0 ! TEMPERATURA REDUCIDA\n Real, Parameter :: Lambda = 1.25 ! FIN POZO\n Real, Dimension(:),Allocatable :: R , G ! RADIO | DISTRIBUCION RADIAL\n Real :: a, b, a74 ! PARAMETROS VAN DER WAALS\n Real :: ctea, ctea74, cteb, delta , gr1 ! PARAMETROS PARA CALCULO DE a Y b VAN DER WAALS\n Real :: Intg ! ACUMULADOR PARA INTEGRACION\n\n Write(*,*) \"========================\"\n Open(8, File = \"a_starT1.dat\", Action= \"write\") !ARCHIVO DE SALIDA T*=1.0\n Open(9, File = \"a_starT74.dat\", Action= \"write\") !ARCHIVO DE SALIDA T*=0.74\n Archivo: Do Dens = 1, 10\n !TAMANO DEL ARCHIVO POR LEER\n Write(Cons,256) Dens\n Filename = start//trim(Cons)//En\n Write(*,*) \"Archivo: \",Filename\n\n Open( 1, File = Trim(Filename), action= \"read\", Status =\"old\" ) !ARCHIVO DE ENTRADA\n k = 0 !REINICIA CONTADOR\n Sizes: Do !BUSCANDO TAMA\u00d1O DE ARCHIVO (RENGLONES QUE QUE TIENE)\n \n Read( 1,*, iostat = state )\n k = k + 1\n If ( state .LT. 0 ) Exit\n \n End Do Sizes\n \n Write(*,*) \"Tiene\", k, \"Renglones\" !DEBUG LINE (SIZE OF FILE)\n\n Rewind 1 !REINICIAR ARCHIVO DE ENTRADA\n Allocate ( R(k), G(k) )\n\n !SAVING FILE DATA\n Saves : Do i = 1, k+1\n\n Read( 1,*, iostat = state ) R(i), G(i)\n If ( state .LT. 0 ) Exit\n\n End Do Saves\n\n Write(*,*) \"DATOS GUARDADOS EN MEMORIA\"\n\n !CALC DE a VAN DER WAALS\n Ctea = (2.0*Pi) / TP\n Ctea74 = (2.0*Pi)/ 0.74\n Cteb = (2.0/3.0)*PI\n Delta = 0.05 ! CAMBIAR SEGUN EL ARCHIVO\n\n Locate: Do i = 1, k ! BUSCANDO EL PRIMER DATO .GE. 1.0\n\n If (R(i) .GE. 1.0) Exit\n\n End Do Locate\n\n gr1 = G(i) ! Ghd(1+)\n b = cteb*gr1 ! b DE VAN DER WAALS\n \n ! ALGORITMO DE INTEGRACION POR TRAPECIO\n Intg = R(i)*R(i)*G(i)*0.5\n IntegrandoA: Do j = i+1 ,k\n\n If ( R(j+1) .GT. lambda) Exit\n Intg = Intg + R(j)*R(j) * G(j)\n\n End Do IntegrandoA\n \n Intg = Intg + 0.5*R(j)*R(j)*G(j)\n\n a = Intg*delta*ctea ! a DE VAN DER WAALS\n a74 = Intg*delta*ctea74\n Write(*,*) \"a*= \", a\n Write(*,*) \"a74*= \", a74\n Write(*,*) \"b*= \", b\n Write(8,*) Dens*0.1, a , b\n Write(9,*) Dens*0.1, a74, b\n \n Deallocate(R,G)\n Write(*,*) \"========================\"\n End Do Archivo\n \n512 Format (I5.5)\n256 Format (I2.2)\nEnd Program Waals\n", "meta": {"hexsha": "818facbd4e56bf86ea3d07ea8514d0001c5497f0", "size": 3472, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "Proyecto_MC/GDR/Calc.f03", "max_stars_repo_name": "maps16/DesExpII", "max_stars_repo_head_hexsha": "d9d12b445e0fe86e32fce028be4f5b8bcfd2391f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Proyecto_MC/GDR/Calc.f03", "max_issues_repo_name": "maps16/DesExpII", "max_issues_repo_head_hexsha": "d9d12b445e0fe86e32fce028be4f5b8bcfd2391f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Proyecto_MC/GDR/Calc.f03", "max_forks_repo_name": "maps16/DesExpII", "max_forks_repo_head_hexsha": "d9d12b445e0fe86e32fce028be4f5b8bcfd2391f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.3762376238, "max_line_length": 98, "alphanum_fraction": 0.4910714286, "num_tokens": 1138, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894689081711, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6596013660066963}} {"text": "SUBROUTINE LUDCMP(A,N,NP,INDX,D)\n IMPLICIT NONE\n \n !Transferred variables\n INTEGER::N,NP,INDX(N)\n REAL(8)::D,A(NP,NP)\n \n !Local variables\n INTEGER,PARAMETER::NMAX=500\n REAL(8),PARAMETER::TINY=1D-20\n INTEGER::I,IMAX,J,K\n REAL(8)::AAMAX,DUM,SUM,VV(NMAX)\n \n D=1.0\n DO I=1,N\n AAMAX=0.0\n DO J=1,N\n IF (ABS(A(I,J)).GT.AAMAX) AAMAX=ABS(A(I,J))\n END DO\n IF (AAMAX.EQ.0.0) PAUSE 'Singular matrix.'\n VV(I)=1.0/AAMAX\n END DO\n DO J=1,N\n IF (J.GT.1) THEN\n DO I=1,J-1\n SUM=A(I,J)\n IF (I.GT.1)THEN\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 IF\n END DO\n END IF\n AAMAX=0.0\n DO I=J,N\n SUM=A(I,J)\n IF (J.GT.1) THEN\n DO K=1,J-1\n SUM=SUM-A(I,K)*A(K,J)\n END DO\n A(I,J)=SUM\n END IF\n DUM=VV(I)*ABS(SUM)\n IF (DUM.GE.AAMAX) THEN\n IMAX=I\n AAMAX=DUM\n END IF\n END DO\n IF (J.NE.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 D=-D\n VV(IMAX)=VV(J)\n END IF\n INDX(J)=IMAX\n IF (J.NE.N) THEN\n IF (A(J,J).EQ.0.0) A(J,J)=TINY\n DUM=1.0/A(J,J)\n DO I=J+1,N\n A(I,J)=A(I,J)*DUM\n END DO\n END IF\n END DO\n IF (A(N,N).EQ.0.0) A(N,N)=TINY\n \nEND SUBROUTINE LUDCMP\n", "meta": {"hexsha": "a653ae7ee95d6dcebcb2c608c4dda211fd2a8f8f", "size": 1344, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "code/SourceCode/Package_Matrix/Ludcmp.f90", "max_stars_repo_name": "giorgk/IWFM-SAFE", "max_stars_repo_head_hexsha": "849abb22bd7b29c113d0537d228340abe6672b40", "max_stars_repo_licenses": ["MIT"], "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/SourceCode/Package_Matrix/Ludcmp.f90", "max_issues_repo_name": "giorgk/IWFM-SAFE", "max_issues_repo_head_hexsha": "849abb22bd7b29c113d0537d228340abe6672b40", "max_issues_repo_licenses": ["MIT"], "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/SourceCode/Package_Matrix/Ludcmp.f90", "max_forks_repo_name": "giorgk/IWFM-SAFE", "max_forks_repo_head_hexsha": "849abb22bd7b29c113d0537d228340abe6672b40", "max_forks_repo_licenses": ["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.9295774648, "max_line_length": 49, "alphanum_fraction": 0.4754464286, "num_tokens": 580, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789468908171, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6596013660066962}} {"text": "!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 1998 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Spherepack *\n! * *\n! * A Package of Fortran Subroutines and Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams and Paul Swarztrauber *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\nsubmodule(colatitudinal_derivative_routines) colatitudinal_derivative_regular_grid\n \ncontains\n ! subroutine vtsec(nlat, nlon, ityp, nt, vt, wt, idvw, jdvw, br, bi, cr, ci, &\n ! mdab, ndab, wvts, ierror)\n !\n ! given the vector harmonic analysis br, bi, cr, and ci (computed\n ! by subroutine vhaec) of some vector function (v, w), this\n ! subroutine computes the vector function (vt, wt) which is\n ! the derivative of (v, w) with respect to colatitude theta. vtsec\n ! is similar to vhsec except the vector harmonics are replaced by\n ! their derivative with respect to colatitude with the result that\n ! (vt, wt) is computed instead of (v, w). vt(i, j) is the derivative\n ! of the colatitudinal component v(i, j) at the point theta(i) =\n ! (i-1)*pi/(nlat-1) and longitude phi(j) = (j-1)*2*pi/nlon. the\n ! spectral representation of (vt, wt) is given below at output\n ! parameters vt, wt.\n !\n ! input parameters\n !\n ! nlat the number of colatitudes on the full sphere including the\n ! poles. for example, nlat = 37 for a five degree grid.\n ! nlat determines the grid increment in colatitude as\n ! pi/(nlat-1). if nlat is odd the equator is located at\n ! grid point i=(nlat + 1)/2. if nlat is even the equator is\n ! located half way between points i=nlat/2 and i=nlat/2+1.\n ! nlat must be at least 3. note: on the half sphere, the\n ! number of grid points in the colatitudinal direction is\n ! nlat/2 if nlat is even or (nlat + 1)/2 if nlat is odd.\n !\n ! nlon the number of distinct londitude points. nlon determines\n ! the grid increment in longitude as 2*pi/nlon. for example\n ! nlon = 72 for a five degree grid. nlon must be greater\n ! than zero. the axisymmetric case corresponds to nlon=1.\n ! the efficiency of the computation is improved when nlon\n ! is a product of small prime numbers.\n !\n ! ityp = 0 no symmetries exist about the equator. the synthesis\n ! is performed on the entire sphere. i.e. the arrays\n ! vt(i, j), wt(i, j) are computed for i=1, ..., nlat and\n ! j=1, ..., nlon.\n !\n ! = 1 no symmetries exist about the equator however the\n ! the coefficients cr and ci are zero. the synthesis\n ! is performed on the entire sphere. i.e. the arrays\n ! vt(i, j), wt(i, j) are computed for i=1, ..., nlat and\n ! j=1, ..., nlon.\n !\n ! = 2 no symmetries exist about the equator however the\n ! the coefficients br and bi are zero. the synthesis\n ! is performed on the entire sphere. i.e. the arrays\n ! vt(i, j), wt(i, j) are computed for i=1, ..., nlat and\n ! j=1, ..., nlon.\n !\n ! = 3 vt is odd and wt is even about the equator. the\n ! synthesis is performed on the northern hemisphere\n ! only. i.e., if nlat is odd the arrays vt(i, j), wt(i, j)\n ! are computed for i=1, ..., (nlat + 1)/2 and j=1, ..., nlon.\n ! if nlat is even the arrays vt(i, j), wt(i, j) are computed\n ! for i=1, ..., nlat/2 and j=1, ..., nlon.\n !\n ! = 4 vt is odd and wt is even about the equator and the\n ! coefficients cr and ci are zero. the synthesis is\n ! performed on the northern hemisphere only. i.e. if\n ! nlat is odd the arrays vt(i, j), wt(i, j) are computed\n ! for i=1, ..., (nlat + 1)/2 and j=1, ..., nlon. if nlat is\n ! even the arrays vt(i, j), wt(i, j) are computed for\n ! i=1, ..., nlat/2 and j=1, ..., nlon.\n !\n ! = 5 vt is odd and wt is even about the equator and the\n ! coefficients br and bi are zero. the synthesis is\n ! performed on the northern hemisphere only. i.e. if\n ! nlat is odd the arrays vt(i, j), wt(i, j) are computed\n ! for i=1, ..., (nlat + 1)/2 and j=1, ..., nlon. if nlat is\n ! even the arrays vt(i, j), wt(i, j) are computed for\n ! i=1, ..., nlat/2 and j=1, ..., nlon.\n !\n ! = 6 vt is even and wt is odd about the equator. the\n ! synthesis is performed on the northern hemisphere\n ! only. i.e., if nlat is odd the arrays vt(i, j), wt(i, j)\n ! are computed for i=1, ..., (nlat + 1)/2 and j=1, ..., nlon.\n ! if nlat is even the arrays vt(i, j), wt(i, j) are computed\n ! for i=1, ..., nlat/2 and j=1, ..., nlon.\n !\n ! = 7 vt is even and wt is odd about the equator and the\n ! coefficients cr and ci are zero. the synthesis is\n ! performed on the northern hemisphere only. i.e. if\n ! nlat is odd the arrays vt(i, j), wt(i, j) are computed\n ! for i=1, ..., (nlat + 1)/2 and j=1, ..., nlon. if nlat is\n ! even the arrays vt(i, j), wt(i, j) are computed for\n ! i=1, ..., nlat/2 and j=1, ..., nlon.\n !\n ! = 8 vt is even and wt is odd about the equator and the\n ! coefficients br and bi are zero. the synthesis is\n ! performed on the northern hemisphere only. i.e. if\n ! nlat is odd the arrays vt(i, j), wt(i, j) are computed\n ! for i=1, ..., (nlat + 1)/2 and j=1, ..., nlon. if nlat is\n ! even the arrays vt(i, j), wt(i, j) are computed for\n ! i=1, ..., nlat/2 and j=1, ..., nlon.\n !\n ! nt the number of syntheses. in the program that calls vtsec,\n ! the arrays vt, wt, br, bi, cr, and ci can be three dimensional\n ! in which case multiple syntheses will be performed.\n ! the third index is the synthesis index which assumes the\n ! values k=1, ..., nt. for a single synthesis set nt=1. the\n ! discription of the remaining parameters is simplified\n ! by assuming that nt=1 or that all the arrays are two\n ! dimensional.\n !\n ! idvw the first dimension of the arrays vt, wt as it appears in\n ! the program that calls vtsec. if ityp <= 2 then idvw\n ! must be at least nlat. if ityp > 2 and nlat is\n ! even then idvw must be at least nlat/2. if ityp > 2\n ! and nlat is odd then idvw must be at least (nlat + 1)/2.\n !\n ! jdvw the second dimension of the arrays vt, wt as it appears in\n ! the program that calls vtsec. jdvw must be at least nlon.\n !\n ! br, bi two or three dimensional arrays (see input parameter nt)\n ! cr, ci that contain the vector spherical harmonic coefficients\n ! of (v, w) as computed by subroutine vhaec.\n !\n ! mdab the first dimension of the arrays br, bi, cr, and ci as it\n ! appears in the program that calls vtsec. mdab must be at\n ! least min(nlat, nlon/2) if nlon is even or at least\n ! min(nlat, (nlon + 1)/2) if nlon is odd.\n !\n ! ndab the second dimension of the arrays br, bi, cr, and ci as it\n ! appears in the program that calls vtsec. ndab must be at\n ! least nlat.\n !\n ! wvts an array which must be initialized by subroutine vtseci.\n ! once initialized, wvts can be used repeatedly by vtsec\n ! as long as nlon and nlat remain unchanged. wvts must\n ! not be altered between calls of vtsec.\n !\n ! lwvts the dimension of the array wvts as it appears in the\n ! program that calls vtsec. define\n !\n ! l1 = min(nlat, nlon/2) if nlon is even or\n ! l1 = min(nlat, (nlon + 1)/2) if nlon is odd\n !\n ! and\n !\n ! l2 = nlat/2 if nlat is even or\n ! l2 = (nlat + 1)/2 if nlat is odd\n !\n ! then lwvts must be at least\n !\n ! 4*nlat*l2+3*max(l1-2, 0)*(2*nlat-l1-1)+nlon+15\n !\n ! output parameters\n !\n ! vt, wt two or three dimensional arrays (see input parameter nt)\n ! in which the derivative of (v, w) with respect to\n ! colatitude theta is stored. vt(i, j), wt(i, j) contain the\n ! derivatives at colatitude theta(i) = (i-1)*pi/(nlat-1)\n ! and longitude phi(j) = (j-1)*2*pi/nlon. the index ranges\n ! are defined above at the input parameter ityp. vt and wt\n ! are computed from the formulas for v and w given in\n ! subroutine vhsec but with vbar and wbar replaced with\n ! their derivatives with respect to colatitude. these\n ! derivatives are denoted by vtbar and wtbar.\n !\n ! in terms of real variables this expansion takes the form\n !\n ! for i=1, ..., nlat and j=1, ..., nlon\n !\n ! vt(i, j) = the sum from n=1 to n=nlat-1 of\n !\n ! .5*br(1, n+1)*vtbar(0, n, theta(i))\n !\n ! plus the sum from m=1 to m=mmax-1 of the sum from n=m to\n ! n=nlat-1 of the real part of\n !\n ! (br(m+1, n+1)*vtbar(m, n, theta(i))\n ! -ci(m+1, n+1)*wtbar(m, n, theta(i)))*cos(m*phi(j))\n ! -(bi(m+1, n+1)*vtbar(m, n, theta(i))\n ! +cr(m+1, n+1)*wtbar(m, n, theta(i)))*sin(m*phi(j))\n !\n ! and for i=1, ..., nlat and j=1, ..., nlon\n !\n ! wt(i, j) = the sum from n=1 to n=nlat-1 of\n !\n ! -.5*cr(1, n+1)*vtbar(0, n, theta(i))\n !\n ! plus the sum from m=1 to m=mmax-1 of the sum from n=m to\n ! n=nlat-1 of the real part of\n !\n ! -(cr(m+1, n+1)*vtbar(m, n, theta(i))\n ! +bi(m+1, n+1)*wtbar(m, n, theta(i)))*cos(m*phi(j))\n ! +(ci(m+1, n+1)*vtbar(m, n, theta(i))\n ! -br(m+1, n+1)*wtbar(m, n, theta(i)))*sin(m*phi(j))\n !\n !\n ! br(m+1, nlat), bi(m+1, nlat), cr(m+1, nlat), and ci(m+1, nlat) are\n ! assumed zero for m even.\n !\n !\n ! ierror = 0 no errors\n ! = 1 error in the specification of nlat\n ! = 2 error in the specification of nlon\n ! = 3 error in the specification of ityp\n ! = 4 error in the specification of nt\n ! = 5 error in the specification of idvw\n ! = 6 error in the specification of jdvw\n ! = 7 error in the specification of mdab\n ! = 8 error in the specification of ndab\n ! = 9 error in the specification of lwvts\n !\n module subroutine vtsec(nlat, nlon, ityp, nt, vt, wt, idvw, jdvw, br, bi, cr, ci, &\n mdab, ndab, wvts, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n integer(ip), intent(in) :: ityp\n integer(ip), intent(in) :: nt\n real(wp), intent(out) :: vt(idvw, jdvw, nt)\n real(wp), intent(out) :: wt(idvw, jdvw, nt)\n integer(ip), intent(in) :: idvw\n integer(ip), intent(in) :: jdvw\n real(wp), intent(in) :: br(mdab, ndab, nt)\n real(wp), intent(in) :: bi(mdab, ndab, nt)\n real(wp), intent(in) :: cr(mdab, ndab, nt)\n real(wp), intent(in) :: ci(mdab, ndab, nt)\n integer(ip), intent(in) :: mdab\n integer(ip), intent(in) :: ndab\n real(wp), intent(in) :: wvts(:)\n integer(ip), intent(out) :: ierror\n\n ! Local variables\n integer(ip) :: idv, imid, ist, labc, lzz1, mmax, lwork\n\n ! Check calling arguments\n call check_calling_arguments(nlat, nlon, ityp, nt, &\n idvw, jdvw, mdab, ndab, wvts, ierror, get_lwvts(nlat,nlon))\n\n ! Check error flag\n if (ierror /= 0) return\n\n mmax = min(nlat, (nlon + 1)/2)\n imid = (nlat + 1)/2\n lzz1 = 2*nlat*imid\n labc = 3*(max(mmax-2, 0)*(2*nlat-mmax-1))/2\n\n ! Set required workspace size\n select case (ityp)\n case (0:2)\n ist = imid\n idv = nlat\n lwork = nlat*(2*nt*nlon+max(6*imid, nlon))\n case default\n ist = 0\n idv = imid\n lwork = imid*(2*nt*nlon+max(6*nlat, nlon))\n end select\n\n block\n real(wp) :: work(lwork)\n integer(ip) :: lnl, lwzvin, jw1, jw2\n integer(ip) :: iw1, iw2, iw3, iw4, iw5\n\n lnl = nt*idv*nlon\n iw1 = ist+1\n iw2 = lnl+1\n iw3 = iw2+ist\n iw4 = iw2+lnl\n iw5 = iw4+3*imid*nlat\n lwzvin = lzz1+labc\n jw1 = lwzvin+1\n jw2 = jw1+lwzvin\n\n call vtsec_lower_utility_routine(nlat, nlon, ityp, nt, imid, idvw, jdvw, &\n vt, wt, mdab, ndab, br, bi, cr, ci, idv, work, work(iw1:), work(iw2:), &\n work(iw3:), work(iw4:), work(iw5:), wvts, wvts(jw1:), wvts(jw2:))\n end block\n\n end subroutine vtsec\n !\n ! subroutine vtseci(nlat, nlon, wvts, ierror)\n !\n ! subroutine vtseci initializes the array wvts which can then be\n ! used repeatedly by subroutine vtsec until nlat or nlon is changed.\n !\n ! input parameters\n !\n ! nlat the number of colatitudes on the full sphere including the\n ! poles. for example, nlat = 37 for a five degree grid.\n ! nlat determines the grid increment in colatitude as\n ! pi/(nlat-1). if nlat is odd the equator is located at\n ! grid point i=(nlat + 1)/2. if nlat is even the equator is\n ! located half way between points i=nlat/2 and i=nlat/2+1.\n ! nlat must be at least 3. note: on the half sphere, the\n ! number of grid points in the colatitudinal direction is\n ! nlat/2 if nlat is even or (nlat + 1)/2 if nlat is odd.\n !\n ! nlon the number of distinct londitude points. nlon determines\n ! the grid increment in longitude as 2*pi/nlon. for example\n ! nlon = 72 for a five degree grid. nlon must be greater\n ! than zero. the axisymmetric case corresponds to nlon=1.\n ! the efficiency of the computation is improved when nlon\n ! is a product of small prime numbers.\n !\n ! lwvts the dimension of the array wvts as it appears in the\n ! program that calls vtsec. define\n !\n ! l1 = min(nlat, nlon/2) if nlon is even or\n ! l1 = min(nlat, (nlon + 1)/2) if nlon is odd\n !\n ! and\n !\n ! l2 = nlat/2 if nlat is even or\n ! l2 = (nlat + 1)/2 if nlat is odd\n !\n ! then lwvts must be at least\n !\n ! 4*nlat*l2+3*max(l1-2, 0)*(2*nlat-l1-1)+nlon+15\n !\n ! output parameters\n !\n ! wvts an array which is initialized for use by subroutine vtsec.\n ! once initialized, wvts can be used repeatedly by vtsec\n ! as long as nlat or nlon remain unchanged. wvts must not\n ! be altered between calls of vtsec.\n !\n !\n ! ierror = 0 no errors\n ! = 1 error in the specification of nlat\n ! = 2 error in the specification of nlon\n ! = 3 error in the specification of lwvts\n !\n module subroutine vtseci(nlat, nlon, wvts, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n real(wp), intent(out) :: wvts(:)\n integer(ip), intent(out) :: ierror\n\n ! Local variables\n integer(ip) :: imid, labc, lzz1\n integer(ip) :: mmax, ldwork\n type(SpherepackUtility) :: util\n\n ! Check calling arguments\n call check_init_calling_arguments(&\n nlat, nlon, wvts, ierror, get_lwvts(nlat,nlon))\n\n ! Check error flag\n if (ierror /= 0) return\n\n imid = (nlat + 1)/2\n lzz1 = 2*nlat*imid\n mmax = min(nlat, (nlon + 1)/2)\n labc = 3*(max(mmax-2, 0)*(2*nlat-mmax-1))/2\n\n ! Set required workspace length\n ldwork = 2*nlat + 2\n\n block\n real(wp) :: dwork(ldwork)\n integer(ip) :: lwvbin, iw1, iw2\n\n ! Set workspace index pointers\n lwvbin = lzz1+labc\n iw1 = lwvbin+1\n iw2 = iw1+lwvbin\n\n call util%initialize_polar_components_regular_colat_deriv(nlat, nlon, wvts, dwork)\n\n call util%initialize_azimuthal_components_regular_colat_deriv(nlat, nlon, wvts(iw1:), dwork)\n\n call util%hfft%initialize(nlon, wvts(iw2:))\n end block\n\n end subroutine vtseci\n\n subroutine vtsec_lower_utility_routine(nlat, nlon, ityp, nt, imid, idvw, jdvw, vt, wt, mdab, &\n ndab, br, bi, cr, ci, idv, vte, vto, wte, wto, vb, wb, wvbin, wwbin, wrfft)\n\n real(wp) :: bi\n real(wp) :: br\n real(wp) :: ci\n real(wp) :: cr\n integer(ip) :: i\n integer(ip) :: idv\n integer(ip) :: idvw\n integer(ip) :: imid\n integer(ip) :: imm1\n integer(ip) :: ityp\n integer(ip) :: iv\n integer(ip) :: iw\n integer(ip) :: j\n integer(ip) :: jdvw\n integer(ip) :: k\n integer(ip) :: m\n integer(ip) :: mdab\n integer(ip) :: mlat\n integer(ip) :: mlon\n integer(ip) :: mmax\n integer(ip) :: mp1\n integer(ip) :: mp2\n integer(ip) :: ndab\n integer(ip) :: ndo1\n integer(ip) :: ndo2\n integer(ip) :: nlat\n integer(ip) :: nlon\n integer(ip) :: nlp1\n integer(ip) :: np1\n integer(ip) :: nt\n real(wp) :: vb\n real(wp) :: vt\n real(wp) :: vte\n real(wp) :: vto\n real(wp) :: wb\n real(wp) :: wrfft\n real(wp) :: wt\n real(wp) :: wte\n real(wp) :: wto\n real(wp) :: wvbin\n real(wp) :: wwbin\n dimension vt(idvw, jdvw, nt), wt(idvw, jdvw, nt), br(mdab, ndab, nt), &\n bi(mdab, ndab, nt), cr(mdab, ndab, nt), ci(mdab, ndab, nt), &\n vte(idv, nlon, nt), vto(idv, nlon, nt), wte(idv, nlon, nt), &\n wto(idv, nlon, nt), wvbin(*), wwbin(*), wrfft(*), &\n vb(imid, nlat, 3), wb(imid, nlat, 3)\n \n type(SpherepackUtility) :: util\n\n nlp1 = nlat+1\n mlat = mod(nlat, 2)\n mlon = mod(nlon, 2)\n mmax = min(nlat, (nlon + 1)/2)\n\n select case(mlat)\n case(0)\n imm1 = imid\n ndo1 = nlat\n ndo2 = nlat-1\n case default\n imm1 = imid-1\n ndo1 = nlat-1\n ndo2 = nlat\n end select\n\n ! Preset even fields to zero\n vte = ZERO\n wte = ZERO\n\n vector_symmetry_cases: select case (ityp)\n case (0)\n ! case ityp=0 no symmetries\n call util%compute_polar_component(0, nlat, nlon, 0, vb, iv, wvbin)\n !\n ! case m = 0\n !\n do k=1, nt\n do np1=2, ndo2, 2\n do i=1, imm1\n vto(i, 1, k)=vto(i, 1, k)+br(1, np1, k)*vb(i, np1, iv)\n wto(i, 1, k)=wto(i, 1, k)-cr(1, np1, k)*vb(i, np1, iv)\n end do\n end do\n end do\n do k=1, nt\n do np1=3, ndo1, 2\n do i=1, imid\n vte(i, 1, k)=vte(i, 1, k)+br(1, np1, k)*vb(i, np1, iv)\n wte(i, 1, k)=wte(i, 1, k)-cr(1, np1, k)*vb(i, np1, iv)\n end do\n end do\n end do\n !\n ! case m = 1 through nlat-1\n !\n if (mmax < 2) exit vector_symmetry_cases\n do mp1=2, mmax\n m = mp1-1\n mp2 = mp1+1\n call util%compute_polar_component(0, nlat, nlon, m, vb, iv, wvbin)\n call util%compute_azimuthal_component(0, nlat, nlon, m, wb, iw, wwbin)\n if (mp1 <= ndo1) then\n do k=1, nt\n do np1=mp1, ndo1, 2\n do i=1, imm1\n vte(i, 2*mp1-2, k) = vte(i, 2*mp1-2, k)+br(mp1, np1, k)*vb(i, np1, iv)\n vto(i, 2*mp1-2, k) = vto(i, 2*mp1-2, k)-ci(mp1, np1, k)*wb(i, np1, iw)\n vte(i, 2*mp1-1, k) = vte(i, 2*mp1-1, k)+bi(mp1, np1, k)*vb(i, np1, iv)\n vto(i, 2*mp1-1, k) = vto(i, 2*mp1-1, k)+cr(mp1, np1, k)*wb(i, np1, iw)\n wte(i, 2*mp1-2, k) = wte(i, 2*mp1-2, k)-cr(mp1, np1, k)*vb(i, np1, iv)\n wto(i, 2*mp1-2, k) = wto(i, 2*mp1-2, k)-bi(mp1, np1, k)*wb(i, np1, iw)\n wte(i, 2*mp1-1, k) = wte(i, 2*mp1-1, k)-ci(mp1, np1, k)*vb(i, np1, iv)\n wto(i, 2*mp1-1, k) = wto(i, 2*mp1-1, k)+br(mp1, np1, k)*wb(i, np1, iw)\n end do\n if (mlat /= 0) then\n vte(imid, 2*mp1-2, k) = vte(imid, 2*mp1-2, k) &\n +br(mp1, np1, k)*vb(imid, np1, iv)\n vte(imid, 2*mp1-1, k) = vte(imid, 2*mp1-1, k) &\n +bi(mp1, np1, k)*vb(imid, np1, iv)\n wte(imid, 2*mp1-2, k) = wte(imid, 2*mp1-2, k) &\n -cr(mp1, np1, k)*vb(imid, np1, iv)\n wte(imid, 2*mp1-1, k) = wte(imid, 2*mp1-1, k) &\n -ci(mp1, np1, k)*vb(imid, np1, iv)\n end if\n end do\n end do\n end if\n if (mp2 <= ndo2) then\n do k=1, nt\n do np1=mp2, ndo2, 2\n do i=1, imm1\n vto(i, 2*mp1-2, k) = vto(i, 2*mp1-2, k)+br(mp1, np1, k)*vb(i, np1, iv)\n vte(i, 2*mp1-2, k) = vte(i, 2*mp1-2, k)-ci(mp1, np1, k)*wb(i, np1, iw)\n vto(i, 2*mp1-1, k) = vto(i, 2*mp1-1, k)+bi(mp1, np1, k)*vb(i, np1, iv)\n vte(i, 2*mp1-1, k) = vte(i, 2*mp1-1, k)+cr(mp1, np1, k)*wb(i, np1, iw)\n wto(i, 2*mp1-2, k) = wto(i, 2*mp1-2, k)-cr(mp1, np1, k)*vb(i, np1, iv)\n wte(i, 2*mp1-2, k) = wte(i, 2*mp1-2, k)-bi(mp1, np1, k)*wb(i, np1, iw)\n wto(i, 2*mp1-1, k) = wto(i, 2*mp1-1, k)-ci(mp1, np1, k)*vb(i, np1, iv)\n wte(i, 2*mp1-1, k) = wte(i, 2*mp1-1, k)+br(mp1, np1, k)*wb(i, np1, iw)\n end do\n if (mlat /= 0) then\n vte(imid, 2*mp1-2, k) = vte(imid, 2*mp1-2, k) &\n -ci(mp1, np1, k)*wb(imid, np1, iw)\n vte(imid, 2*mp1-1, k) = vte(imid, 2*mp1-1, k) &\n +cr(mp1, np1, k)*wb(imid, np1, iw)\n wte(imid, 2*mp1-2, k) = wte(imid, 2*mp1-2, k) &\n -bi(mp1, np1, k)*wb(imid, np1, iw)\n wte(imid, 2*mp1-1, k) = wte(imid, 2*mp1-1, k) &\n +br(mp1, np1, k)*wb(imid, np1, iw)\n end if\n end do\n end do\n end if\n end do\n case(1)\n ! case ityp=1 no symmetries, cr and ci equal zero\n call util%compute_polar_component(0, nlat, nlon, 0, vb, iv, wvbin)\n !\n ! case m = 0\n !\n do k=1, nt\n do np1=2, ndo2, 2\n do i=1, imm1\n vto(i, 1, k)=vto(i, 1, k)+br(1, np1, k)*vb(i, np1, iv)\n end do\n end do\n end do\n do k=1, nt\n do np1=3, ndo1, 2\n do i=1, imid\n vte(i, 1, k)=vte(i, 1, k)+br(1, np1, k)*vb(i, np1, iv)\n end do\n end do\n end do\n !\n ! case m = 1 through nlat-1\n !\n if (mmax < 2) exit vector_symmetry_cases\n do mp1=2, mmax\n m = mp1-1\n mp2 = mp1+1\n call util%compute_polar_component(0, nlat, nlon, m, vb, iv, wvbin)\n call util%compute_azimuthal_component(0, nlat, nlon, m, wb, iw, wwbin)\n if (mp1 <= ndo1) then\n do k=1, nt\n do np1=mp1, ndo1, 2\n do i=1, imm1\n vte(i, 2*mp1-2, k) = vte(i, 2*mp1-2, k)+br(mp1, np1, k)*vb(i, np1, iv)\n vte(i, 2*mp1-1, k) = vte(i, 2*mp1-1, k)+bi(mp1, np1, k)*vb(i, np1, iv)\n wto(i, 2*mp1-2, k) = wto(i, 2*mp1-2, k)-bi(mp1, np1, k)*wb(i, np1, iw)\n wto(i, 2*mp1-1, k) = wto(i, 2*mp1-1, k)+br(mp1, np1, k)*wb(i, np1, iw)\n end do\n if (mlat /= 0) then\n vte(imid, 2*mp1-2, k) = vte(imid, 2*mp1-2, k) &\n +br(mp1, np1, k)*vb(imid, np1, iv)\n vte(imid, 2*mp1-1, k) = vte(imid, 2*mp1-1, k) &\n +bi(mp1, np1, k)*vb(imid, np1, iv)\n end if\n end do\n end do\n end if\n if (mp2 <= ndo2) then\n do k=1, nt\n do np1=mp2, ndo2, 2\n do i=1, imm1\n vto(i, 2*mp1-2, k) = vto(i, 2*mp1-2, k)+br(mp1, np1, k)*vb(i, np1, iv)\n vto(i, 2*mp1-1, k) = vto(i, 2*mp1-1, k)+bi(mp1, np1, k)*vb(i, np1, iv)\n wte(i, 2*mp1-2, k) = wte(i, 2*mp1-2, k)-bi(mp1, np1, k)*wb(i, np1, iw)\n wte(i, 2*mp1-1, k) = wte(i, 2*mp1-1, k)+br(mp1, np1, k)*wb(i, np1, iw)\n end do\n if (mlat /= 0) then\n wte(imid, 2*mp1-2, k) = wte(imid, 2*mp1-2, k) &\n -bi(mp1, np1, k)*wb(imid, np1, iw)\n wte(imid, 2*mp1-1, k) = wte(imid, 2*mp1-1, k) &\n +br(mp1, np1, k)*wb(imid, np1, iw)\n end if\n end do\n end do\n end if\n end do\n case(2)\n ! case ityp=2 no symmetries, br and bi are equal to zero\n call util%compute_polar_component(0, nlat, nlon, 0, vb, iv, wvbin)\n !\n ! case m = 0\n !\n do k=1, nt\n do np1=2, ndo2, 2\n do i=1, imm1\n wto(i, 1, k)=wto(i, 1, k)-cr(1, np1, k)*vb(i, np1, iv)\n end do\n end do\n end do\n do k=1, nt\n do np1=3, ndo1, 2\n do i=1, imid\n wte(i, 1, k)=wte(i, 1, k)-cr(1, np1, k)*vb(i, np1, iv)\n end do\n end do\n end do\n !\n ! case m = 1 through nlat-1\n !\n if (mmax < 2) exit vector_symmetry_cases\n do mp1=2, mmax\n m = mp1-1\n mp2 = mp1+1\n call util%compute_polar_component(0, nlat, nlon, m, vb, iv, wvbin)\n call util%compute_azimuthal_component(0, nlat, nlon, m, wb, iw, wwbin)\n if (mp1 <= ndo1) then\n do k=1, nt\n do np1=mp1, ndo1, 2\n do i=1, imm1\n vto(i, 2*mp1-2, k) = vto(i, 2*mp1-2, k)-ci(mp1, np1, k)*wb(i, np1, iw)\n vto(i, 2*mp1-1, k) = vto(i, 2*mp1-1, k)+cr(mp1, np1, k)*wb(i, np1, iw)\n wte(i, 2*mp1-2, k) = wte(i, 2*mp1-2, k)-cr(mp1, np1, k)*vb(i, np1, iv)\n wte(i, 2*mp1-1, k) = wte(i, 2*mp1-1, k)-ci(mp1, np1, k)*vb(i, np1, iv)\n end do\n if (mlat /= 0) then\n wte(imid, 2*mp1-2, k) = wte(imid, 2*mp1-2, k) &\n -cr(mp1, np1, k)*vb(imid, np1, iv)\n wte(imid, 2*mp1-1, k) = wte(imid, 2*mp1-1, k) &\n -ci(mp1, np1, k)*vb(imid, np1, iv)\n end if\n end do\n end do\n end if\n if (mp2 <= ndo2) then\n do k=1, nt\n do np1=mp2, ndo2, 2\n do i=1, imm1\n vte(i, 2*mp1-2, k) = vte(i, 2*mp1-2, k)-ci(mp1, np1, k)*wb(i, np1, iw)\n vte(i, 2*mp1-1, k) = vte(i, 2*mp1-1, k)+cr(mp1, np1, k)*wb(i, np1, iw)\n wto(i, 2*mp1-2, k) = wto(i, 2*mp1-2, k)-cr(mp1, np1, k)*vb(i, np1, iv)\n wto(i, 2*mp1-1, k) = wto(i, 2*mp1-1, k)-ci(mp1, np1, k)*vb(i, np1, iv)\n end do\n if (mlat /= 0) then\n vte(imid, 2*mp1-2, k) = vte(imid, 2*mp1-2, k) &\n -ci(mp1, np1, k)*wb(imid, np1, iw)\n vte(imid, 2*mp1-1, k) = vte(imid, 2*mp1-1, k) &\n +cr(mp1, np1, k)*wb(imid, np1, iw)\n end if\n end do\n end do\n end if\n end do\n case(3)\n ! case ityp=3 v odd, w even\n call util%compute_polar_component(0, nlat, nlon, 0, vb, iv, wvbin)\n !\n ! case m = 0\n !\n do k=1, nt\n do np1=2, ndo2, 2\n do i=1, imm1\n vto(i, 1, k)=vto(i, 1, k)+br(1, np1, k)*vb(i, np1, iv)\n end do\n end do\n end do\n do k=1, nt\n do np1=3, ndo1, 2\n do i=1, imid\n wte(i, 1, k)=wte(i, 1, k)-cr(1, np1, k)*vb(i, np1, iv)\n end do\n end do\n end do\n !\n ! case m = 1 through nlat-1\n !\n if (mmax < 2) exit vector_symmetry_cases\n do mp1=2, mmax\n m = mp1-1\n mp2 = mp1+1\n call util%compute_polar_component(0, nlat, nlon, m, vb, iv, wvbin)\n call util%compute_azimuthal_component(0, nlat, nlon, m, wb, iw, wwbin)\n if (mp1 <= ndo1) then\n do k=1, nt\n do np1=mp1, ndo1, 2\n do i=1, imm1\n vto(i, 2*mp1-2, k) = vto(i, 2*mp1-2, k)-ci(mp1, np1, k)*wb(i, np1, iw)\n vto(i, 2*mp1-1, k) = vto(i, 2*mp1-1, k)+cr(mp1, np1, k)*wb(i, np1, iw)\n wte(i, 2*mp1-2, k) = wte(i, 2*mp1-2, k)-cr(mp1, np1, k)*vb(i, np1, iv)\n wte(i, 2*mp1-1, k) = wte(i, 2*mp1-1, k)-ci(mp1, np1, k)*vb(i, np1, iv)\n end do\n if (mlat /= 0) then\n wte(imid, 2*mp1-2, k) = wte(imid, 2*mp1-2, k) &\n -cr(mp1, np1, k)*vb(imid, np1, iv)\n wte(imid, 2*mp1-1, k) = wte(imid, 2*mp1-1, k) &\n -ci(mp1, np1, k)*vb(imid, np1, iv)\n end if\n end do\n end do\n end if\n if (mp2 <= ndo2) then\n do k=1, nt\n do np1=mp2, ndo2, 2\n do i=1, imm1\n vto(i, 2*mp1-2, k) = vto(i, 2*mp1-2, k)+br(mp1, np1, k)*vb(i, np1, iv)\n vto(i, 2*mp1-1, k) = vto(i, 2*mp1-1, k)+bi(mp1, np1, k)*vb(i, np1, iv)\n wte(i, 2*mp1-2, k) = wte(i, 2*mp1-2, k)-bi(mp1, np1, k)*wb(i, np1, iw)\n wte(i, 2*mp1-1, k) = wte(i, 2*mp1-1, k)+br(mp1, np1, k)*wb(i, np1, iw)\n end do\n if (mlat /= 0) then\n wte(imid, 2*mp1-2, k) = wte(imid, 2*mp1-2, k) &\n -bi(mp1, np1, k)*wb(imid, np1, iw)\n wte(imid, 2*mp1-1, k) = wte(imid, 2*mp1-1, k) &\n +br(mp1, np1, k)*wb(imid, np1, iw)\n end if\n end do\n end do\n end if\n end do\n case(4)\n ! case ityp=4 v odd, w even, and both cr and ci equal zero\n call util%compute_polar_component(1, nlat, nlon, 0, vb, iv, wvbin)\n !\n ! case m = 0\n !\n do k=1, nt\n do np1=2, ndo2, 2\n do i=1, imm1\n vto(i, 1, k)=vto(i, 1, k)+br(1, np1, k)*vb(i, np1, iv)\n end do\n end do\n end do\n !\n ! case m = 1 through nlat-1\n !\n if (mmax < 2) exit vector_symmetry_cases\n do mp1=2, mmax\n m = mp1-1\n mp2 = mp1+1\n call util%compute_polar_component(1, nlat, nlon, m, vb, iv, wvbin)\n call util%compute_azimuthal_component(1, nlat, nlon, m, wb, iw, wwbin)\n if (mp2 <= ndo2) then\n do k=1, nt\n do np1=mp2, ndo2, 2\n do i=1, imm1\n vto(i, 2*mp1-2, k) = vto(i, 2*mp1-2, k)+br(mp1, np1, k)*vb(i, np1, iv)\n vto(i, 2*mp1-1, k) = vto(i, 2*mp1-1, k)+bi(mp1, np1, k)*vb(i, np1, iv)\n wte(i, 2*mp1-2, k) = wte(i, 2*mp1-2, k)-bi(mp1, np1, k)*wb(i, np1, iw)\n wte(i, 2*mp1-1, k) = wte(i, 2*mp1-1, k)+br(mp1, np1, k)*wb(i, np1, iw)\n end do\n if (mlat /= 0) then\n wte(imid, 2*mp1-2, k) = wte(imid, 2*mp1-2, k) &\n -bi(mp1, np1, k)*wb(imid, np1, iw)\n wte(imid, 2*mp1-1, k) = wte(imid, 2*mp1-1, k) &\n +br(mp1, np1, k)*wb(imid, np1, iw)\n end if\n end do\n end do\n end if\n end do\n case(5)\n ! case ityp=5 v odd, w even, br and bi equal zero\n call util%compute_polar_component(2, nlat, nlon, 0, vb, iv, wvbin)\n !\n ! case m = 0\n !\n do k=1, nt\n do np1=3, ndo1, 2\n do i=1, imid\n wte(i, 1, k)=wte(i, 1, k)-cr(1, np1, k)*vb(i, np1, iv)\n end do\n end do\n end do\n !\n ! case m = 1 through nlat-1\n !\n if (mmax < 2) exit vector_symmetry_cases\n do mp1=2, mmax\n m = mp1-1\n mp2 = mp1+1\n call util%compute_polar_component(2, nlat, nlon, m, vb, iv, wvbin)\n call util%compute_azimuthal_component(2, nlat, nlon, m, wb, iw, wwbin)\n if (mp1 <= ndo1) then\n do k=1, nt\n do np1=mp1, ndo1, 2\n do i=1, imm1\n vto(i, 2*mp1-2, k) = vto(i, 2*mp1-2, k)-ci(mp1, np1, k)*wb(i, np1, iw)\n vto(i, 2*mp1-1, k) = vto(i, 2*mp1-1, k)+cr(mp1, np1, k)*wb(i, np1, iw)\n wte(i, 2*mp1-2, k) = wte(i, 2*mp1-2, k)-cr(mp1, np1, k)*vb(i, np1, iv)\n wte(i, 2*mp1-1, k) = wte(i, 2*mp1-1, k)-ci(mp1, np1, k)*vb(i, np1, iv)\n end do\n if (mlat /= 0) then\n wte(imid, 2*mp1-2, k) = wte(imid, 2*mp1-2, k) &\n -cr(mp1, np1, k)*vb(imid, np1, iv)\n wte(imid, 2*mp1-1, k) = wte(imid, 2*mp1-1, k) &\n -ci(mp1, np1, k)*vb(imid, np1, iv)\n end if\n end do\n end do\n end if\n end do\n case(6)\n ! case ityp=6 v even , w odd\n call util%compute_polar_component(0, nlat, nlon, 0, vb, iv, wvbin)\n !\n ! case m = 0\n do k=1, nt\n do np1=2, ndo2, 2\n do i=1, imm1\n wto(i, 1, k)=wto(i, 1, k)-cr(1, np1, k)*vb(i, np1, iv)\n end do\n end do\n end do\n do k=1, nt\n do np1=3, ndo1, 2\n do i=1, imid\n vte(i, 1, k)=vte(i, 1, k)+br(1, np1, k)*vb(i, np1, iv)\n end do\n end do\n end do\n !\n ! case m = 1 through nlat-1\n !\n if (mmax < 2) exit vector_symmetry_cases\n do mp1=2, mmax\n m = mp1-1\n mp2 = mp1+1\n call util%compute_polar_component(0, nlat, nlon, m, vb, iv, wvbin)\n call util%compute_azimuthal_component(0, nlat, nlon, m, wb, iw, wwbin)\n if (mp1 <= ndo1) then\n do k=1, nt\n do np1=mp1, ndo1, 2\n do i=1, imm1\n vte(i, 2*mp1-2, k) = vte(i, 2*mp1-2, k)+br(mp1, np1, k)*vb(i, np1, iv)\n vte(i, 2*mp1-1, k) = vte(i, 2*mp1-1, k)+bi(mp1, np1, k)*vb(i, np1, iv)\n wto(i, 2*mp1-2, k) = wto(i, 2*mp1-2, k)-bi(mp1, np1, k)*wb(i, np1, iw)\n wto(i, 2*mp1-1, k) = wto(i, 2*mp1-1, k)+br(mp1, np1, k)*wb(i, np1, iw)\n end do\n if (mlat /= 0) then\n vte(imid, 2*mp1-2, k) = vte(imid, 2*mp1-2, k) &\n +br(mp1, np1, k)*vb(imid, np1, iv)\n vte(imid, 2*mp1-1, k) = vte(imid, 2*mp1-1, k) &\n +bi(mp1, np1, k)*vb(imid, np1, iv)\n end if\n end do\n end do\n end if\n if (mp2 <= ndo2) then\n do k=1, nt\n do np1=mp2, ndo2, 2\n do i=1, imm1\n vte(i, 2*mp1-2, k) = vte(i, 2*mp1-2, k)-ci(mp1, np1, k)*wb(i, np1, iw)\n vte(i, 2*mp1-1, k) = vte(i, 2*mp1-1, k)+cr(mp1, np1, k)*wb(i, np1, iw)\n wto(i, 2*mp1-2, k) = wto(i, 2*mp1-2, k)-cr(mp1, np1, k)*vb(i, np1, iv)\n wto(i, 2*mp1-1, k) = wto(i, 2*mp1-1, k)-ci(mp1, np1, k)*vb(i, np1, iv)\n end do\n if (mlat /= 0) then\n vte(imid, 2*mp1-2, k) = vte(imid, 2*mp1-2, k) &\n -ci(mp1, np1, k)*wb(imid, np1, iw)\n vte(imid, 2*mp1-1, k) = vte(imid, 2*mp1-1, k) &\n +cr(mp1, np1, k)*wb(imid, np1, iw)\n end if\n end do\n end do\n end if\n end do\n case(7)\n ! case ityp=7 v even, w odd cr and ci equal zero\n call util%compute_polar_component(2, nlat, nlon, 0, vb, iv, wvbin)\n !\n ! case m = 0\n !\n do k=1, nt\n do np1=3, ndo1, 2\n do i=1, imid\n vte(i, 1, k)=vte(i, 1, k)+br(1, np1, k)*vb(i, np1, iv)\n end do\n end do\n end do\n !\n ! case m = 1 through nlat-1\n !\n if (mmax < 2) exit vector_symmetry_cases\n do mp1=2, mmax\n m = mp1-1\n mp2 = mp1+1\n call util%compute_polar_component(2, nlat, nlon, m, vb, iv, wvbin)\n call util%compute_azimuthal_component(2, nlat, nlon, m, wb, iw, wwbin)\n if (mp1 <= ndo1) then\n do k=1, nt\n do np1=mp1, ndo1, 2\n do i=1, imm1\n vte(i, 2*mp1-2, k) = vte(i, 2*mp1-2, k)+br(mp1, np1, k)*vb(i, np1, iv)\n vte(i, 2*mp1-1, k) = vte(i, 2*mp1-1, k)+bi(mp1, np1, k)*vb(i, np1, iv)\n wto(i, 2*mp1-2, k) = wto(i, 2*mp1-2, k)-bi(mp1, np1, k)*wb(i, np1, iw)\n wto(i, 2*mp1-1, k) = wto(i, 2*mp1-1, k)+br(mp1, np1, k)*wb(i, np1, iw)\n end do\n if (mlat /= 0) then\n vte(imid, 2*mp1-2, k) = vte(imid, 2*mp1-2, k) &\n +br(mp1, np1, k)*vb(imid, np1, iv)\n vte(imid, 2*mp1-1, k) = vte(imid, 2*mp1-1, k) &\n +bi(mp1, np1, k)*vb(imid, np1, iv)\n end if\n end do\n end do\n end if\n end do\n case(8)\n ! case ityp=8 v even, w odd br and bi equal zero\n call util%compute_polar_component(1, nlat, nlon, 0, vb, iv, wvbin)\n !\n ! case m = 0\n !\n do k=1, nt\n do np1=2, ndo2, 2\n do i=1, imm1\n wto(i, 1, k)=wto(i, 1, k)-cr(1, np1, k)*vb(i, np1, iv)\n end do\n end do\n end do\n !\n ! case m = 1 through nlat-1\n !\n if (mmax < 2) exit vector_symmetry_cases\n do mp1=2, mmax\n m = mp1-1\n mp2 = mp1+1\n call util%compute_polar_component(1, nlat, nlon, m, vb, iv, wvbin)\n call util%compute_azimuthal_component(1, nlat, nlon, m, wb, iw, wwbin)\n if (mp2 <= ndo2) then\n do k=1, nt\n do np1=mp2, ndo2, 2\n do i=1, imm1\n vte(i, 2*mp1-2, k) = vte(i, 2*mp1-2, k)-ci(mp1, np1, k)*wb(i, np1, iw)\n vte(i, 2*mp1-1, k) = vte(i, 2*mp1-1, k)+cr(mp1, np1, k)*wb(i, np1, iw)\n wto(i, 2*mp1-2, k) = wto(i, 2*mp1-2, k)-cr(mp1, np1, k)*vb(i, np1, iv)\n wto(i, 2*mp1-1, k) = wto(i, 2*mp1-1, k)-ci(mp1, np1, k)*vb(i, np1, iv)\n end do\n if (mlat /= 0) then\n vte(imid, 2*mp1-2, k) = vte(imid, 2*mp1-2, k) &\n -ci(mp1, np1, k)*wb(imid, np1, iw)\n vte(imid, 2*mp1-1, k) = vte(imid, 2*mp1-1, k) &\n +cr(mp1, np1, k)*wb(imid, np1, iw)\n end if\n end do\n end do\n end if\n end do\n end select vector_symmetry_cases\n\n do k=1, nt\n call util%hfft%backward(idv, nlon, vte(:, :, k), idv, wrfft)\n call util%hfft%backward(idv, nlon, wte(:, :, k), idv, wrfft)\n end do\n\n select case (ityp)\n case(0:1)\n do k=1, nt\n do j=1, nlon\n do i=1, imm1\n vt(i, j, k) = HALF *(vte(i, j, k)+vto(i, j, k))\n wt(i, j, k) = HALF *(wte(i, j, k)+wto(i, j, k))\n vt(nlp1-i, j, k) = HALF *(vte(i, j, k)-vto(i, j, k))\n wt(nlp1-i, j, k) = HALF *(wte(i, j, k)-wto(i, j, k))\n end do\n end do\n end do\n case default\n do k=1, nt\n do j=1, nlon\n do i=1, imm1\n vt(i, j, k) = HALF *vte(i, j, k)\n wt(i, j, k) = HALF *wte(i, j, k)\n end do\n end do\n end do\n end select\n\n if (mlat /= 0) then\n do k=1, nt\n do j=1, nlon\n vt(imid, j, k) = HALF *vte(imid, j, k)\n wt(imid, j, k) = HALF *wte(imid, j, k)\n end do\n end do\n end if\n\n end subroutine vtsec_lower_utility_routine\n\nend submodule colatitudinal_derivative_regular_grid\n", "meta": {"hexsha": "2978eb527b6e7dd65b34ba45683b02188bf103d6", "size": 50435, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/colatitudinal_derivative_regular_grid.f90", "max_stars_repo_name": "jlokimlin/spherepack4.1", "max_stars_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-06-28T14:01:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T21:59:28.000Z", "max_issues_repo_path": "src/colatitudinal_derivative_regular_grid.f90", "max_issues_repo_name": "jlokimlin/spherepack4.1", "max_issues_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2016-05-07T23:00:35.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-22T23:52:30.000Z", "max_forks_repo_path": "src/colatitudinal_derivative_regular_grid.f90", "max_forks_repo_name": "jlokimlin/spherepack4.1", "max_forks_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-06-28T14:03:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T12:53:54.000Z", "avg_line_length": 48.6824324324, "max_line_length": 106, "alphanum_fraction": 0.3791811242, "num_tokens": 15141, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789457685656, "lm_q2_score": 0.7371581741774411, "lm_q1q2_score": 0.6596013629007809}} {"text": "module rpoisson\n\n! Routines in this module solve the radial Poisson equation outward using\n! the predictor-corrector method (with Adams extrapolation/interpolation).\n\nuse types, only: dp\nuse utils, only: stop_error\nuse constants, only: pi\nuse ode1d, only: adams_extrapolation_outward, adams_interp_outward\nuse ode1d, only: integrate, get_midpoints, rk4_integrate3\n\nimplicit none\n\nprivate\npublic rpoisson_outward_pc\n\ncontains\n\nfunction rpoisson_outward_pc(R, Rp, rho) result(V)\n! Solves the equation V''(r) + 2/r*V'(r) = -4*pi*rho\n!\n! Uses predictor corrector Adams method.\n!\n! It rewrites it to the equivalent system of first order ODEs on a uniform\n! grid:\n! u1 = V\n! u2 = V'\n! u1p = u2 * Rp\n! u2p = -(4*pi*rho + 2*u2/r) * Rp\n! and integrates outward using Adams method. The initial conditions are:\n! V (R(1)) = u1(1) = 4*pi * \\int r * rho(r) dr\n! V'(R(1)) = u2(1) = 0\nreal(dp), intent(in) :: R(:), Rp(:), rho(:)\nreal(dp) :: V(size(R))\n\nreal(dp), dimension(size(R)) :: u1, u2, u1p, u2p\ninteger :: N, i, it\ninteger, parameter :: max_it = 2\nreal(dp) :: rho_mid(3)\n\nN = size(R)\nrho_mid = get_midpoints(R(:4), rho(:4))\ncall rpoisson_outward_rk4(rho(:4), rho_mid, R(:4), &\n 4*pi*integrate(Rp, rho*R), &\n 0.0_dp, &\n u1(:4), u2(:4))\n\nu1p(:4) = u2(:4) * Rp(:4)\nu2p(:4) = -(4*pi*rho(:4) + 2*u2(:4)/R(:4)) * Rp(:4)\n\ndo i = 4, N-1\n u1(i+1) = u1(i) + adams_extrapolation_outward(u1p, i)\n u2(i+1) = u2(i) + adams_extrapolation_outward(u2p, i)\n do it = 1, max_it\n u1p(i+1) = +Rp(i+1) * u2(i+1)\n u2p(i+1) = -Rp(i+1) * (4*pi*rho(i+1) + 2*u2(i+1)/R(i+1))\n u1(i+1) = u1(i) + adams_interp_outward(u1p, i)\n u2(i+1) = u2(i) + adams_interp_outward(u2p, i)\n end do\nend do\nV = u1\nend function\n\nsubroutine rpoisson_outward_rk4(density, density_mid, R, V0, V0d, V, Vd)\n! Solves V''(r) + 2/r*V'(r) = -4*pi*density (in this form) with initial\n! conditions V(R(1)) = V0 and V'(R(1)) = V0d using 4th order Runge-Kutta method\n! by rewriting it to the equivalent first order ODEs (see the documentation\n! of rk4_integrate3() for more details). Returns V (value) and Vd (derivative).\nreal(dp), intent(in), dimension(:) :: density, density_mid ! density at the\n ! mesh points R and at midpoints\nreal(dp), intent(in), dimension(:) :: R ! radial grid\nreal(dp), intent(in) :: V0 ! value of V(r) at r=R(1)\nreal(dp), intent(in) :: V0d ! value of V'(r) at r=R(1)\nreal(dp), intent(out), dimension(:) :: V, Vd ! V(r) and V'(r) on the grid R\n\nreal(dp) :: y(2)\nreal(dp), dimension(size(R)) :: C1, C2\nreal(dp), dimension(size(R)-1) :: C1mid, C2mid\nreal(dp), dimension(size(R)-1) :: Rmid\ninteger :: imax\n\ny(1) = V0\ny(2) = V0d\n\nC1 = -4*pi*density\nC2 = -2 / R\nRmid = (R(:size(R)-1) + R(2:)) / 2\nC1mid = -4*pi*density_mid\nC2mid = -2 / Rmid\ncall rk4_integrate3(R, y, C1, C2, C1mid, C2mid, 1e10_dp, V, Vd, imax)\nif (imax /= size(R)) call stop_error(\"Poisson solver diverged.\")\nend subroutine\n\nend module\n", "meta": {"hexsha": "bd655ca4246e09f5d09da28375ca950ba8acbfa2", "size": 2928, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/rpoisson.f90", "max_stars_repo_name": "rc/dftatom", "max_stars_repo_head_hexsha": "fe479fd27a7e0f77c6a88a1949996406ec935ac2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 40, "max_stars_repo_stars_event_min_datetime": "2015-03-19T16:00:14.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-29T03:06:10.000Z", "max_issues_repo_path": "src/rpoisson.f90", "max_issues_repo_name": "rc/dftatom", "max_issues_repo_head_hexsha": "fe479fd27a7e0f77c6a88a1949996406ec935ac2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2015-06-23T21:59:56.000Z", "max_issues_repo_issues_event_max_datetime": "2019-09-04T20:36:51.000Z", "max_forks_repo_path": "src/rpoisson.f90", "max_forks_repo_name": "rc/dftatom", "max_forks_repo_head_hexsha": "fe479fd27a7e0f77c6a88a1949996406ec935ac2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2015-06-07T15:14:49.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-05T07:03:24.000Z", "avg_line_length": 30.8210526316, "max_line_length": 79, "alphanum_fraction": 0.6335382514, "num_tokens": 1143, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894604912849, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6596013598021199}} {"text": "SUBROUTINE Easter(year, day, month)\r\n! U.S. Naval Observatory Astronomical Applications Department\r\n\r\n! The Date of Easter (Sunday)\r\n\r\n! The algorithm is due to J.-M. Oudin (1940) and is reprinted in the Explanatory\r\n! Supplement to the Astronomical Almanac, ed. P. K. Seidelmann (1992).\r\n! See Chapter 12, \"Calendars\", by L. E. Doggett.\r\n\r\n! The following are dates of Easter from 1980 to 2024:\r\n\r\n! 1980 April 6 1995 April 16 2010 April 4\r\n! 1981 April 19 1996 April 7 2011 April 24\r\n! 1982 April 11 1997 March 30 2012 April 8\r\n! 1983 April 3 1998 April 12 2013 March 31\r\n! 1984 April 22 1999 April 4 2014 April 20\r\n! 1985 April 7 2000 April 23 2015 April 5\r\n! 1986 March 30 2001 April 15 2016 March 27\r\n! 1987 April 19 2002 March 31 2017 April 16\r\n! 1988 April 3 2003 April 20 2018 April 1\r\n! 1989 March 26 2004 April 11 2019 April 21\r\n! 1990 April 15 2005 March 27 2020 April 12\r\n! 1991 March 31 2006 April 16 2021 April 4\r\n! 1992 April 19 2007 April 8 2022 April 17\r\n! 1993 April 11 2008 March 23 2023 April 9\r\n! 1994 April 3 2009 April 12 2024 March 31\r\n\r\n! N.B. The date of Easter for the Eastern Orthodox Church may be different.\r\n\r\n! This code assembled by Alan Miller\r\n! Reference web site:\r\n! http://aa.usno.navy.mil/faq/docs/easter.html\r\n! Latest revision 8 April 2002\r\n\r\nIMPLICIT NONE\r\nINTEGER, INTENT(IN) :: year\r\nINTEGER, INTENT(OUT) :: day, month\r\n\r\n! Local variables\r\nINTEGER :: c, i, j, k, l, n\r\n\r\nc = year / 100\r\nn = year - 19 * ( year / 19 )\r\nk = ( c - 17 ) / 25\r\ni = c - c / 4 - ( c - k ) / 3 + 19 * n + 15\r\ni = i - 30 * ( i / 30 )\r\ni = i - (i / 28) * (1 - (i / 28) * (29 / (i + 1 )) * ( (21 - n) / 11) )\r\nj = year + year / 4 + i + 2 - c + c / 4\r\nj = j - 7 * ( j / 7 )\r\nl = i - j\r\nmonth = 3 + ( l + 40 ) / 44\r\nday = l + 28 - 31 * ( month / 4 )\r\n\r\nRETURN\r\nEND SUBROUTINE Easter\r\n\r\n\r\n\r\nPROGRAM test_Easter\r\n! Generate the table contained in the subroutine.\r\n\r\nIMPLICIT NONE\r\n\r\nINTERFACE\r\n SUBROUTINE Easter(year, day, month)\r\n IMPLICIT NONE\r\n INTEGER, INTENT(IN) :: year\r\n INTEGER, INTENT(OUT) :: day, month\r\n END SUBROUTINE Easter\r\nEND INTERFACE\r\n\r\nINTEGER :: day(1980:2024), month(1980:2024), year, y2, y3\r\nCHARACTER (LEN=5) :: mon(3:4) = (/ 'March', 'April' /)\r\n\r\nDO year = 1980, 2024\r\n CALL Easter(year, day(year), month(year))\r\nEND DO\r\n\r\nDO year = 1980, 1994\r\n y2 = year + 15\r\n y3 = y2 + 15\r\n WRITE(*, '(3(\" \", i4, \" \", a5, i3, \" \"))') &\r\n year, mon(month(year)), day(year), &\r\n y2, mon(month(y2)), day(y2), &\r\n y3, mon(month(y3)), day(y3)\r\nEND DO\r\nSTOP\r\nEND PROGRAM test_Easter\r\n", "meta": {"hexsha": "2628f25240750c3168802f76a7387974caa9cb68", "size": 2858, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/easter.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/easter.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/easter.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": 32.1123595506, "max_line_length": 81, "alphanum_fraction": 0.5542337299, "num_tokens": 1059, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969137, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6596013567034587}} {"text": "program pernicious\n implicit none\n\n integer :: i, n\n\n i = 1\n n = 0\n do\n if(isprime(popcnt(i))) then\n write(*, \"(i0, 1x)\", advance = \"no\") i\n n = n + 1\n if(n == 25) exit\n end if\n i = i + 1\n end do\n\n write(*,*)\n do i = 888888877, 888888888\n if(isprime(popcnt(i))) write(*, \"(i0, 1x)\", advance = \"no\") i\n end do\n\ncontains\n\nfunction popcnt(x)\n integer :: popcnt\n integer, intent(in) :: x\n integer :: i\n\n popcnt = 0\n do i = 0, 31\n if(btest(x, i)) popcnt = popcnt + 1\n end do\n\nend function\n\nfunction isprime(number)\n logical :: isprime\n integer, intent(in) :: number\n integer :: i\n\n if(number == 2) then\n isprime = .true.\n else if(number < 2 .or. mod(number,2) == 0) then\n isprime = .false.\n else\n isprime = .true.\n do i = 3, int(sqrt(real(number))), 2\n if(mod(number,i) == 0) then\n isprime = .false.\n exit\n end if\n end do\n end if\nend function\nend program\n", "meta": {"hexsha": "72827c287ffc847b21531ef4816dbb9dd6031371", "size": 941, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Pernicious-numbers/Fortran/pernicious-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/Pernicious-numbers/Fortran/pernicious-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/Pernicious-numbers/Fortran/pernicious-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": 16.8035714286, "max_line_length": 65, "alphanum_fraction": 0.5536663124, "num_tokens": 344, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789452074398, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6596013535975429}} {"text": "function relief_surf(fi,tet)\r\n\r\ncommon/topo/hsurf,nfi,fmin,fmax,ntet,tmin,tmax,htopo(1500,1500)\r\n\r\nhhh=0.\r\n\r\n!write(*,*)' nfi=',nfi,' fi=',fi,' fmin=',fmin,' fmax=',fmax\r\n\r\nif (nfi.eq.0) then\r\n\th_lim=0\r\n\treturn\r\nend if\r\n\r\nif ((fi-fmin)*(fi-fmax).gt.0) then\r\n\th_lim=0\r\n\treturn\r\nend if\r\n\r\nif ((tet-tmin)*(tet-tmax).gt.0) then\r\n\th_lim=0\r\n\treturn\r\nend if\r\n\r\ndf=(fmax-fmin)/nfi\r\ndt=(tmax-tmin)/ntet\r\n\r\ndo ifi=1,nfi\r\n\tf1=fmin+df*(ifi-1)\r\n\tf2=fmin+df*ifi\r\n\tif ((fi-f1)*(fi-f2).gt.0.) cycle\r\n\texit\r\nend do\r\n\r\ndo itet=1,ntet\r\n\tt1=tmin+dt*(itet-1)\r\n\tt2=tmin+dt*itet\r\n\tif ((tet-t1)*(tet-t2).gt.0.) cycle\r\n\texit\r\nend do\r\n\r\nh11=htopo(ifi,itet)\r\nh12=htopo(ifi,itet+1)\r\nh21=htopo(ifi+1,itet)\r\nh22=htopo(ifi+1,itet+1)\r\n\r\n\r\nh1=h11+(h11-h12)*(tet-t1)/(t1-t2)\r\nh2=h21+(h21-h22)*(tet-t1)/(t1-t2)\r\n\r\nhhh=h1+(h1-h2)*(fi-f1)/(f1-f2)\r\n\r\nrelief_surf=-hhh\r\n\r\nreturn\r\nend\t", "meta": {"hexsha": "47580ec8e8d214a81e5bac89a7c20b1dc62494f6", "size": 845, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "PROGRAMS/subr/rays_locate/relief_surf.f90", "max_stars_repo_name": "ilyasnsk/colima_lotos_2019", "max_stars_repo_head_hexsha": "d3ff4f32034e49a32560f170e980b6847b6ea9c7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-10-28T06:16:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-16T02:52:23.000Z", "max_issues_repo_path": "PROGRAMS/subr/rays_locate/relief_surf.f90", "max_issues_repo_name": "ilyasnsk/colima_lotos_2019", "max_issues_repo_head_hexsha": "d3ff4f32034e49a32560f170e980b6847b6ea9c7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "PROGRAMS/subr/rays_locate/relief_surf.f90", "max_forks_repo_name": "ilyasnsk/colima_lotos_2019", "max_forks_repo_head_hexsha": "d3ff4f32034e49a32560f170e980b6847b6ea9c7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.3636363636, "max_line_length": 64, "alphanum_fraction": 0.6059171598, "num_tokens": 373, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218262741297, "lm_q2_score": 0.7154240018510026, "lm_q1q2_score": 0.6595650023468227}} {"text": "\tSUBROUTINE TUPPOW(ALPHA,BETA,N,M,P0,R,PSIMAX,INCRE,PSI)\r\n\tIMPLICIT NONE\r\nC\r\nC-Description-----------------------------------------------------------\r\nC\r\nC Function:\r\nC\tPower calculations for matched 2XM tables\r\nC Arguments:\r\nC i\tALPHA\t(REAL)\r\nC\tType I error\r\nC i\tBETA\t(REAL)\r\nC\tType II error\r\nC i\tN\t(Integer)\r\nC\tNumber of case patients\r\nC i\tM\t(Integer)\r\nC\tNumber of matched controls per case patient\r\nC i\tP0\t(REAL)\r\nC\tProbability of exposure in control group\r\nC i\tR\t(REAL)\r\nC\tCorrelation coefficient\r\nC i\tPSIMAX\t(REAL)\r\nC\tAn odds ratio - See output\r\nC i\tINCRE\t(REAL)\r\nC\tIncrement size\r\nC o\tPSI\t(REAL)\r\nC = the value of the odds ratio that can be detected with power 1-BETA\r\nC\tif this PSI is less than or equal to PSIMAX.\r\nC = -1 if the power associated with the odds ratio (PSIMAX) is less\r\nC\tthan 1-BETA or if N is too small to permit valid normal\r\nC\tapproximations.\r\nC = -2 if no PSI exists with the required power givenx P0 and R.\r\nC = -3 if N is too small to permit valid normal approximations.\r\nC Notes:\r\nC .\tThis routine was written by Dale Plummer.\r\nC .\tDesigned by Dr. William Dupont. This program was written to\r\nC\tproduce the isographs in Dupont (Biometrics, 1988; 44:1157-1168)\r\nC .\tThe minimum value of N that will permit valid normal approxiamations\r\nC\tdepends on P0, R, and M.\r\nC .\tWe will find PSI by either the secant method or the method of\r\nC\tfalse position. The latter method will be used whenever the\r\nC\tsecant method threatens to diverge.\r\nC\r\nC-Declarations----------------------------------------------------------\r\nC\r\nC\r\nC Arguments\r\nC\r\n\tREAL ALPHA,BETA,P0,R,PSIMAX,PSI,INCRE\r\n\tINTEGER N,M\r\nC\r\nC Functions\r\nC\r\n\tREAL ZCRVALUE\r\nC\r\nC Locals\r\nC\r\n\tREAL ZALPHA,POWER,TPOWER,PU,PSIU,PL,PSIL,POLD,PSIOLD,P\r\n\tREAL SLOPE,PSINEW,PNEW,PSITOP\r\n\tINTEGER ERR\r\nC\r\nC-Code------------------------------------------------------------------\r\nC\r\n\tPOWER=1.-BETA\r\n\tZALPHA=ZCRVALUE(ALPHA/2.)\r\n\tCALL POWFCN(ZALPHA,N,R,P0,M,PSIMAX,TPOWER,ERR)\r\n\tIF (ERR.GE.1) THEN\r\n\t PSI=-1-ERR\r\n\t RETURN\r\n\tEND IF\r\n\tIF (TPOWER.LT.POWER) THEN\r\n\t PSI=-1.\r\n\t RETURN\r\n\tEND IF\r\n\tPU=TPOWER\r\n\tPSIU=PSIMAX\r\nC\r\nC Find a valid lower value for PSIL.\r\nC\r\n\tPSITOP=PSIMAX\r\n\tPSIL=1.0\r\n10\tCONTINUE\r\n\t IF (PSITOP-PSIL.LE.0.1) GO TO 20\r\n\t PSI=((PSITOP-PSIL)/2.)+PSIL\r\n\t CALL POWFCN(ZALPHA,N,R,P0,M,PSI,P,ERR)\r\n\t IF (ERR.EQ.0) THEN\r\n\t\t\tIF (P.LE.POWER) THEN\r\n\t\t\t\tPL=P\r\n\t\t\t\tPSIL=PSI\r\n\t\t\t\tGOTO 2\r\n\t\t\tEND IF\r\n\t\t\tPSITOP=PSI\r\n\t ELSE\r\n\t\t\tPSIL=PSI\r\n\t END IF\r\n\tGO TO 10\r\n20\tCONTINUE\r\nC No valid lower bound exists.\r\n\tPSI=-2\r\n\tRETURN\r\nC Come to here when found valid lower bound on PSI.\r\n2\tCONTINUE\r\n\tIF (PU-POWER.GE.POWER-PL) THEN\r\n\t POLD=PU\r\n\t PSIOLD=PSIU\r\n\t P=PL\r\n\t PSI=PSIL\r\n\tELSE\r\n\t POLD=PL\r\n\t PSIOLD=PSIL\r\n\t P=PU\r\n\t PSI=PSIU\r\n\tEND IF\r\nC\r\nC Try an iteration of the secant method.\r\nC\r\n30\tCONTINUE\r\n\t IF (ABS(P-POWER).LT.INCRE) GO TO 40\r\n\t SLOPE=(POLD-P)/(PSIOLD-PSI)\r\n\t PSINEW=(POWER+SLOPE*PSI-P)/SLOPE\r\n\t IF (PSIL.LT.PSINEW.AND.PSINEW.LT.PSIU) THEN\r\nC\r\nC The secant method looks OK.\r\nC\r\n\t\t\tCALL POWFCN(ZALPHA,N,R,P0,M,PSINEW,PNEW,ERR)\r\n\t\t\tIF (ABS(PNEW-POWER).LT.ABS(P-POWER))THEN\r\nC\r\nC The secant method *is* OK.\r\nC\r\n\t\t\t\tIF (POLD.GE.POWER) THEN\r\nC\r\nC Reduce PU.\r\nC\r\n\t\t\t\t\tPU=POLD\r\n\t\t\t\t\tPSIU=PSIOLD\r\n\t\t\t\tELSE\r\nC\r\nC Increase PL.\r\nC\r\n\t\t\t\t\tPL=POLD\r\n\t\t\t\t\tPSIL=PSIOLD\r\n\t\t\t\tEND IF\r\n\t\t\t\tPOLD=P\r\n\t\t\t\tPSIOLD=PSI\r\n\t\t\t\tP=PNEW\r\n\t\t\t\tPSI=PSINEW\r\nC\r\nC This iteration is finished.\r\nC\r\n\t\t\t\tGOTO 1\r\n\t\t\tELSE\r\nC\r\nC Prepare for iteration of false position method.\r\nC\r\n\t\t\t\tIF (PNEW.GE.POWER.AND.PNEW.LT.PU) THEN\r\nC\r\nC Reduce PU.\r\nC\r\n\t\t\t\t\tPU=PNEW\r\n\t\t\t\t\tPSIU=PSINEW\r\n\t\t\t\tELSE IF (PNEW.LT.POWER.AND.PL.LT.PNEW) THEN\r\nC\r\nC Increase PL.\r\nC\r\n\t\t\t\t\tPL=PNEW\r\n\t\t\t\t\tPSIL=PSINEW\r\n\t\t\t\tEND IF\r\n\t\t\tEND IF\r\n\t END IF\r\nC\r\nC Now do an iteration of false position method.\r\nC\r\n\t SLOPE=(PU-PL)/(PSIU-PSIL)\r\n\t PSI=(POWER+SLOPE*PSIL-PL)/SLOPE\r\n\t CALL POWFCN(ZALPHA,N,R,P0,M,PSI,P,ERR)\r\n\t IF (P.GE.POWER) THEN\r\nC\r\nC Reduce PU.\r\nC\r\n\t\t\tPU=P\r\n\t\t\tPSIU=PSI\r\n\t ELSE\r\nC\r\nC Increase PL.\r\nC\r\n\t\t\tPL=P\r\n\t\t\tPSIL=PSI\r\n\t END IF\r\nC\r\nC Get ready to try secant method again.\r\nC\r\n\t IF (POWER-PL.LE.PU-POWER) THEN\r\n\t\t\tP=PL\r\n\t\t\tPSI=PSIL\r\n\t\t\tPOLD=PU\r\n\t\t\tPSIOLD=PSIU\r\n\t ELSE\r\n\t\t\tP=PU\r\n\t\t\tPSI=PSIU\r\n\t\t\tPOLD=PL\r\n\t\t\tPSIOLD=PSIL\r\n\t END IF\r\nC\r\nC Continue with the secant method.\r\nC\r\n1\t CONTINUE\r\n\tGO TO 30\r\n40\tCONTINUE\r\nC\r\nC Finished.\r\nC\r\n\tRETURN\r\n\tEND", "meta": {"hexsha": "7c954f723dfab3a94b0958cdec4d03c5ddcb7706", "size": 4436, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "misc/old_ps/ps-development-version/psDll/tuppow.for", "max_stars_repo_name": "vubiostat/ps", "max_stars_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2017-12-29T14:19:14.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-06T15:08:46.000Z", "max_issues_repo_path": "misc/old_ps/ps-development-version/psDll/tuppow.for", "max_issues_repo_name": "vubiostat/ps", "max_issues_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2020-04-30T16:57:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-07T00:26:02.000Z", "max_forks_repo_path": "misc/old_ps/ps-development-version/psDll/tuppow.for", "max_forks_repo_name": "vubiostat/ps", "max_forks_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-07T20:11:54.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-11T19:18:59.000Z", "avg_line_length": 20.9245283019, "max_line_length": 75, "alphanum_fraction": 0.6052750225, "num_tokens": 1613, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.7248702880639791, "lm_q1q2_score": 0.6595645571200686}} {"text": "module finite_differences\n!+Description\n! This module contains routines to approximate mixed first derivatives to a discretely sampled function\n! using repeated one-dimensional parabolic interpolation. The function need not be sampled uniformly, but\n! it is assumed that the grid is Cartesian with coordinate grids that are independent of all other coordinates\n! (e.g. this does not work for AMR/nested grids)\n!\n! The purpose of these routines is to approximate derivatives for use with the tricubic interpolation routines\n! that are used in our particle stepper. This hard-coded 2nd order method is much faster than the N-th order\n! Lagrange method. This is very similar to the finite_differences_qp module that had been previously used,\n! but a somewhat different formulation of the coefficients is used and it is a little more flexible.\n!\n!+Routines\n! deriv1 Approximate the first derivative of a 1-d function \n! deriv2 Approximate the mixed 2nd derivative of a 2-d function\n! deriv3 Approximate the mixed 3rd derivative of a 3-d function\n!\n!+Author\n! Jesse Woodroffe\n! jwoodroffe@lanl.gov\n\nuse global\n\ncontains\n\n function deriv1(x,f,idx) result(der)\n !+Description \n ! Approximates the derivatives of a discretely sampled function by fitting a parabola \n ! and then differentiating the parabola:\n !\n ! f = A(x-x0)^2 + B(x-x0) + C\n ! fp = 2A(x-x0) + B\n !\n ! The optional parameter idx allows us to specify if the derivative at the left (idx < 0) or right (idx>0) \n ! cell is desired instead of the center value. Derivatives at the center are slightly more accurate, but this\n ! option allows us to get derivatives at the edge of the grid. \n !\n !+Inputs\n ! x(3) double precision array of grid points\n ! f(3) double precision array of function values at the grid points\n ! idx integer that specifies the grid point at which the derivative is to be evaluated\n !\n !+Outputs\n ! der double precision scalar with derivative at desired grid point\n !\n ! Author:\n ! Jesse Woodroffe\n ! jwoodroffe@lanl.gov\n\n implicit none\n\n real(dp), dimension(3) :: x\n real(dp), dimension(3) :: f\n real(dp) :: A, B, p, q, dxp, dxm, dxtot, dfp, dfm, denom\n real(dp) :: der\n integer, intent(in) :: idx\n\n dxp = x(3)-x(2)\n dxm = x(2)-x(1)\n dxtot = dxp+dxm\n denom = 1.d0/(dxtot*dxp*dxm)\n\n dfp = f(3)-f(2)\n dfm = f(1)-f(2)\n\n p = dfm*dxp\n q = dfp*dxm\n\n B = denom*(dxm*q-dxp*p)\n\n der = 0.d0\n if(idx==0) then ! Evaluate at center\n der = B\n else if(idx==1) then ! Evaluate at right\n A = denom*(p+q)\n der = B+2*A*dxp\n else if(idx==-1) then ! Evaluate at left\n A = denom*(p+q)\n der = B-2*A*dxm\n endif\n \n return\n\n end function deriv1\n\n!\n\n function deriv2(x,y,f,idx,idy) result(der)\n !+Description\n ! Calculate 2-d derivative using repeated application of 1d derivative.\n !\n !+Inputs\n ! x(3) double precision array of grid points for dimension 1\n ! y(3) double precision array of grid points for dimension 2\n ! f(3,3) double precision array of function values at the grid points\n ! idx integer that specifies the grid point at which the derivative is to be evaluated in x\n ! idy integer that specifies the grid point at which the derivative is to be evaluated in y\n !\n !+Outputs\n ! der double precision scalar with derivative at desired grid point specified by idx, idy\n !\n !+Author\n ! Jesse Woodroffe\n ! jwoodroffe@lanl.gov\n !\n implicit none\n\n real(dp), dimension(3), intent(in) :: x, y\n real(dp), dimension(3,3), intent(in) :: f\n real(dp), dimension(3) :: temp \n real(dp) :: der\n integer, intent(in) :: idx, idy\n integer :: i \n \n do i=1,3\n temp(i) = deriv1(x,f(:,i),idx=idx)\n enddo\n\n der = deriv1(y,temp,idx=idy)\n\n return\n\n end function deriv2\n\n!\n\n function deriv3(x,y,z,f,idx,idy,idz) result(der)\n !+Description\n ! Calculate 3-d derivative using repeated application of 1d derivative.\n !\n !+Inputs\n ! x(3) double precision array of grid points for dimension 1\n ! y(3) double precision array of grid points for dimension 2\n ! z(3) double precision array of grid points for dimension 3\n ! f(3,3,3) double precision array of function values at the grid points\n ! idx integer that specifies the grid point at which the derivative is to be evaluated in x\n ! idy integer that specifies the grid point at which the derivative is to be evaluated in y\n ! idz integer that specifies the grid point at which the derivative is to be evaluated in z\n !\n !+Outputs\n ! der double precision scalar with derivative at desired grid point specified by idx, idy, idz\n !\n !+Author\n ! Jesse Woodroffe\n ! jwoodroffe@lanl.gov\n !\n implicit none\n\n real(dp), intent(in), dimension(3) :: x, y, z\n real(dp), intent(in), dimension(3,3,3) :: f\n real(dp), dimension(3) :: temp\n real(dp) :: der\n integer, intent(in) :: idx, idy, idz\n\n integer :: i\n\n do i=1,3\n temp(i) = deriv2(y,z,f(i,:,:),idx=idy,idy=idz)\n enddo\n\n der = deriv1(x,temp,idx=idx)\n\n return\n\n end function deriv3\n\nend module finite_differences\n", "meta": {"hexsha": "a8e5ebda2dc75455669f6457a889b9bbda44560e", "size": 5069, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/finite_differences.f90", "max_stars_repo_name": "Pheosics/SHIELDS-PTM", "max_stars_repo_head_hexsha": "b6bdad6a9184530e03e01ef7d20a6a83be460044", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/finite_differences.f90", "max_issues_repo_name": "Pheosics/SHIELDS-PTM", "max_issues_repo_head_hexsha": "b6bdad6a9184530e03e01ef7d20a6a83be460044", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2021-06-01T22:22:01.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-20T19:58:27.000Z", "max_forks_repo_path": "src/finite_differences.f90", "max_forks_repo_name": "Pheosics/SHIELDS-PTM", "max_forks_repo_head_hexsha": "b6bdad6a9184530e03e01ef7d20a6a83be460044", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-06-01T23:29:34.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-11T17:57:48.000Z", "avg_line_length": 30.1726190476, "max_line_length": 112, "alphanum_fraction": 0.6859341093, "num_tokens": 1531, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070084811306, "lm_q2_score": 0.7248702880639792, "lm_q1q2_score": 0.6595645553491507}} {"text": " MODULE biomath_mathlib_mod\n! .. Use Statements ..\n USE biomath_constants_mod\n! ..\n! .. Default Accessibility ..\n PUBLIC\n! ..\n! FUNCTION log_beta(a0,b0) -- An exact renamed copy of betaln\n! FUNCTION log_gamma(a) -- An exact renamed copy of gamln\n! FUNCTION log_bicoef( k, n )\n! FUNCTION algdiv(a,b)\n! FUNCTION alnrel(a)\n! FUNCTION bcorr(a0,b0)\n! FUNCTION betaln(a0,b0)\n! FUNCTION brcomp(a,b,x,y)\n! FUNCTION erf(x)\n! FUNCTION erfc1(ind,x)\n! FUNCTION exparg(l)\n! FUNCTION gam1(a)\n! FUNCTION gamln(a)\n! FUNCTION gamln1(a)\n! FUNCTION gsumln(a,b)\n! FUNCTION rexp(x)\n! FUNCTION rlog1(x)\n CONTAINS\n\n!*********************************************************************\n\n FUNCTION algdiv(a,b)\n!-----------------------------------------------------------------------\n! COMPUTATION OF LN(GAMMA(B)/GAMMA(A+B)) WHEN B .GE. 8\n! --------\n! IN THIS ALGORITHM, DEL(X) IS THE FUNCTION DEFINED BY\n! LN(GAMMA(X)) = (X - 0.5)*LN(X) - X + 0.5*LN(2*PI) + DEL(X).\n!-----------------------------------------------------------------------\n! .. Function Return Value ..\n REAL (dpkind) :: algdiv\n! ..\n! .. Scalar Arguments ..\n REAL (dpkind), INTENT (IN) :: a, b\n! ..\n! .. Local Scalars ..\n REAL (dpkind) :: c, d, h, s11, s3, s5, s7, s9, t, u, v, w, x, x2\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC LOG\n! ..\n! .. Parameters ..\n REAL (dpkind), PARAMETER :: c0 = .833333333333333E-01_dpkind\n REAL (dpkind), PARAMETER :: c1 = -.277777777760991E-02_dpkind\n REAL (dpkind), PARAMETER :: c2 = .793650666825390E-03_dpkind\n REAL (dpkind), PARAMETER :: c3 = -.595202931351870E-03_dpkind\n REAL (dpkind), PARAMETER :: c4 = .837308034031215E-03_dpkind\n REAL (dpkind), PARAMETER :: c5 = -.165322962780713E-02_dpkind\n! ..\n!------------------------\n IF (a>b) THEN\n h = b/a\n c = one/(one+h)\n x = h/(one+h)\n d = a + (b-half)\n ELSE\n h = a/b\n c = h/(one+h)\n x = one/(one+h)\n d = b + (a-half)\n END IF\n\n! SET SN = (1 - X**N)/(1 - X)\n\n x2 = x*x\n s3 = one + (x+x2)\n s5 = one + (x+x2*s3)\n s7 = one + (x+x2*s5)\n s9 = one + (x+x2*s7)\n s11 = one + (x+x2*s9)\n\n! SET W = DEL(B) - DEL(A + B)\n\n t = (one/b)**2\n w = ((((c5*s11*t+c4*s9)*t+c3*s7)*t+c2*s5)*t+c1*s3)*t + c0\n w = w*(c/b)\n\n! COMBINE THE RESULTS\n\n u = d*alnrel(a/b)\n v = a*(LOG(b)-one)\n\n IF (u>v) THEN\n algdiv = (w-v) - u\n ELSE\n algdiv = (w-u) - v\n END IF\n\n END FUNCTION algdiv\n\n!*********************************************************************\n\n FUNCTION alngam(x)\n!**********************************************************************\n! DOUBLE PRECISION FUNCTION ALNGAM(X)\n! double precision LN of the GAMma function\n! Function\n! Returns the natural logarithm of GAMMA(X).\n! Arguments\n! X --> value at which scaled log gamma is to be returned\n! X is DOUBLE PRECISION\n! Method\n! If X .le. 6.0, then use recursion to get X below 3\n! then apply rational approximation number 5236 of\n! Hart et al, Computer Approximations, John Wiley and Sons, NY, 1968.\n! If X .gt. 6.0, then use recursion to get X to at least 12 and\n! then use formula 5423 of the same source.\n!**********************************************************************\n! .. Parameters ..\n REAL (dpkind), PARAMETER :: coef(5) = (/ &\n 0.83333333333333023564E-1_dpkind, - &\n 0.27777777768818808E-2_dpkind, 0.79365006754279E-3_dpkind, &\n -0.594997310889E-3_dpkind, 0.8065880899E-3_dpkind/)\n REAL (dpkind), PARAMETER :: scoefd(4) = (/ &\n 0.62003838007126989331E2_dpkind, 0.9822521104713994894E1_dpkind &\n , -0.8906016659497461257E1_dpkind, &\n 0.1000000000000000000E1_dpkind/)\n REAL (dpkind), PARAMETER :: scoefn(9) = (/ &\n 0.62003838007127258804E2_dpkind, &\n 0.36036772530024836321E2_dpkind, &\n 0.20782472531792126786E2_dpkind, 0.6338067999387272343E1_dpkind &\n , 0.215994312846059073E1_dpkind, 0.3980671310203570498E0_dpkind &\n , 0.1093115956710439502E0_dpkind, 0.92381945590275995E-2_dpkind &\n , 0.29737866448101651E-2_dpkind/)\n REAL (dpkind), PARAMETER :: hln2pi = &\n 0.91893853320467274178E0_dpkind\n REAL (dpkind), PARAMETER :: two = 2.0_dpkind\n! ..\n! .. Function Return Value ..\n REAL (dpkind) :: alngam\n! ..\n! .. Scalar Arguments ..\n REAL (dpkind) :: x\n! ..\n! .. Local Scalars ..\n REAL (dpkind) :: offset, prod, xx\n INTEGER :: i, n\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC INT, LOG, REAL\n! ..\n IF (x<=six) THEN\n prod = one\n xx = x\n IF (x>three) THEN\n10 CONTINUE\n IF ( .NOT. xx>three) GO TO 20\n xx = xx - one\n prod = prod*xx\n GO TO 10\n\n20 CONTINUE\n END IF\n\n IF (x0) THEN\n prod = one\n DO i = 1, n\n prod = prod*(x+REAL(i-1,kind=dpkind))\n END DO\n\n offset = offset - LOG(prod)\n xx = x + REAL(n,kind=dpkind)\n ELSE\n\n xx = x\n\n! COMPUTE POWER SERIES\n\n END IF\n\n alngam = evaluate_polynomial(coef,one/xx**2)/xx\n alngam = alngam + offset + (xx-half)*LOG(xx) - xx\n END IF\n\n END FUNCTION alngam\n\n!*********************************************************************\n\n FUNCTION alnrel(a)\n!-----------------------------------------------------------------------\n! EVALUATION OF THE FUNCTION LN(1 + A)\n!-----------------------------------------------------------------------\n! .. Function Return Value ..\n REAL (dpkind) :: alnrel\n! ..\n! .. Scalar Arguments ..\n REAL (dpkind), INTENT (IN) :: a\n! ..\n! .. Local Scalars ..\n REAL (dpkind) :: t, t2, w\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC ABS, LOG\n! ..\n! .. Parameters ..\n REAL (dpkind), PARAMETER :: p(4) = (/ one, &\n -.129418923021993E+01_dpkind, .405303492862024E+00_dpkind, &\n -.178874546012214E-01_dpkind/)\n REAL (dpkind), PARAMETER :: q(4) = (/ one, &\n -.162752256355323E+01_dpkind, .747811014037616E+00_dpkind, &\n -.845104217945565E-01_dpkind/)\n! ..\n!--------------------------\n IF (ABS(a)<=0.375_dpkind) THEN\n t = a/(a+two)\n t2 = t*t\n\n w = evaluate_polynomial(p,t2)/evaluate_polynomial(q,t2)\n\n alnrel = two*t*w\n\n ELSE IF (a<-one) THEN\n alnrel = -one\n ELSE\n alnrel = LOG(a+one)\n END IF\n\n END FUNCTION alnrel\n\n!*********************************************************************\n\n FUNCTION apser(a,b,x,eps)\n!-----------------------------------------------------------------------\n! APSER YIELDS THE INCOMPLETE BETA RATIO I(SUB(1-X))(B,A) FOR\n! A .LE. MIN(EPS,EPS*B), B*X .LE. 1, AND X .LE. 0.5. USED WHEN\n! A IS VERY SMALL. USE ONLY IF ABOVE INEQUALITIES ARE SATISFIED.\n!-----------------------------------------------------------------------\n! .. Function Return Value ..\n REAL (dpkind) :: apser\n! ..\n! .. Scalar Arguments ..\n REAL (dpkind), INTENT (IN) :: a, b, eps, x\n! ..\n! .. Local Scalars ..\n REAL (dpkind) :: aj, bx, c, j, s, t, tol\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC ABS, LOG\n! ..\n! .. Parameters ..\n REAL (dpkind), PARAMETER :: g = .577215664901533_dpkind\n! ..\n bx = b*x\n t = x - bx\n\n IF (b*eps<=2.E-2_dpkind) THEN\n c = LOG(x) + psi(b) + g + t\n ELSE\n c = LOG(bx) + g + t\n END IF\n\n tol = five*eps*ABS(c)\n j = one\n s = zero\n\n DO\n j = j + one\n t = t*(x-bx/j)\n aj = t/j\n s = s + aj\n\n IF (ABS(aj)<=tol) EXIT\n END DO\n\n apser = -a*(c+s)\n\n RETURN\n\n END FUNCTION apser\n\n!*********************************************************************\n\n FUNCTION basym(a,b,lambda,eps)\n!-----------------------------------------------------------------------\n! ASYMPTOTIC EXPANSION FOR IX(A,B) FOR LARGE A AND B.\n! LAMBDA = (A + B)*Y - B AND EPS IS THE TOLERANCE USED.\n! IT IS ASSUMED THAT LAMBDA IS NONNEGATIVE AND THAT\n! A AND B ARE GREATER THAN OR EQUAL TO 15.\n!-----------------------------------------------------------------------\n!------------------------\n! ****** NUM IS THE MAXIMUM VALUE THAT N CAN TAKE IN THE DO LOOP\n! ENDING AT STATEMENT 50. IT IS REQUIRED THAT NUM BE EVEN.\n! THE ARRAYS A0, B0, C, D HAVE DIMENSION NUM + 1.\n!------------------------\n! E0 = 2/SQRT(PI)\n! E1 = 2**(-3/2)\n!------------------------\n! .. Function Return Value ..\n REAL (dpkind) :: basym\n! ..\n! .. Scalar Arguments ..\n REAL (dpkind), INTENT (IN) :: a, b, eps, lambda\n! ..\n! .. Local Scalars ..\n REAL (dpkind) :: bsum, dsum, f, h, h2, hn, j0, j1, r, r0, r1, s, &\n sum, t, t0, t1, u, w, w0, z, z0, z2, zn, znm1\n INTEGER :: i, im1, imj, j, m, mm1, mmj, n, np1\n! ..\n! .. Local Arrays ..\n REAL (dpkind) :: a0(21), b0(21), c(21), d(21)\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC ABS, EXP, SQRT\n! ..\n! .. Parameters ..\n REAL (dpkind), PARAMETER :: e0 = 1.12837916709551_dpkind\n REAL (dpkind), PARAMETER :: e1 = .353553390593274_dpkind\n INTEGER, PARAMETER :: num = 20\n! ..\n basym = zero\n\n IF (a=eight) GO TO 50\n IF (a>=one) GO TO 10\n\n!-----------------------------------------------------------------------\n! PROCEDURE WHEN A .LT. 1\n!-----------------------------------------------------------------------\n IF (btwo) GO TO 20\n IF (b<=two) THEN\n betaln = gamln(a) + gamln(b) - gsumln(a,b)\n RETURN\n\n END IF\n\n w = zero\n IF (bthousand) GO TO 40\n n = a - one\n w = one\n\n DO i = 1, n\n a = a - one\n h = a/b\n w = w*(h/(one+h))\n END DO\n\n w = LOG(w)\n\n IF (b>=eight) THEN\n betaln = w + gamln(a) + algdiv(a,b)\n RETURN\n\n! REDUCTION OF B WHEN B .LT. 8\n\n END IF\n\n30 CONTINUE\n n = b - one\n z = one\n\n DO i = 1, n\n b = b - one\n z = z*(b/(a+b))\n END DO\n\n betaln = w + LOG(z) + (gamln(a)+(gamln(b)-gsumln(a,b)))\n RETURN\n\n! REDUCTION OF A WHEN B .GT. 1000\n\n40 CONTINUE\n n = a - one\n w = one\n\n DO i = 1, n\n a = a - one\n w = w*(a/(one+a/b))\n END DO\n\n betaln = (LOG(w)-n*LOG(b)) + (gamln(a)+algdiv(a,b))\n RETURN\n\n!-----------------------------------------------------------------------\n! PROCEDURE WHEN A .GE. 8\n!-----------------------------------------------------------------------\n50 CONTINUE\n w = bcorr(a,b)\n h = a/b\n c = h/(one+h)\n u = -(a-half)*LOG(c)\n v = b*alnrel(h)\n\n IF (u>v) THEN\n betaln = ((((-half*LOG(b))+e)+w)-v) - u\n RETURN\n\n END IF\n\n betaln = ((((-half*LOG(b))+e)+w)-u) - v\n\n END FUNCTION betaln\n\n!*********************************************************************\n\n FUNCTION bfrac(a,b,x,y,lambda,eps)\n!-----------------------------------------------------------------------\n! CONTINUED FRACTION EXPANSION FOR IX(A,B) WHEN A,B .GT. 1.\n! IT IS ASSUMED THAT LAMBDA = (A + B)*Y - B.\n!-----------------------------------------------------------------------\n! .. Function Return Value ..\n REAL (dpkind) :: bfrac\n! ..\n! .. Scalar Arguments ..\n REAL (dpkind), INTENT (IN) :: a, b, eps, lambda, x, y\n! ..\n! .. Local Scalars ..\n REAL (dpkind) :: alpha, an, anp1, beta, bn, bnp1, c, c0, c1, e, &\n n, p, r, r0, s, t, w, yp1\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC ABS\n! ..\n bfrac = brcomp(a,b,x,y)\n\n IF (bfrac==zero) RETURN\n\n c = one + lambda\n c0 = b/a\n c1 = one + one/a\n yp1 = y + one\n\n n = zero\n p = one\n s = a + one\n an = zero\n bn = one\n anp1 = one\n bnp1 = c/c1\n r = c1/c\n\n! CONTINUED FRACTION CALCULATION\n\n10 CONTINUE\n n = n + one\n t = n/a\n w = n*(b-n)*x\n e = a/s\n alpha = (p*(p+c0)*e*e)*(w*x)\n e = (one+t)/(c1+t+t)\n beta = n + w/s + e*(c+n*yp1)\n p = one + t\n s = s + two\n\n! UPDATE AN, BN, ANP1, AND BNP1\n\n t = alpha*an + beta*anp1\n an = anp1\n anp1 = t\n t = alpha*bn + beta*bnp1\n bn = bnp1\n bnp1 = t\n\n r0 = r\n r = anp1/bnp1\n IF (ABS(r-r0)<=eps*r) GO TO 20\n\n! RESCALE AN, BN, ANP1, AND BNP1\n\n an = an/bnp1\n bn = bn/bnp1\n anp1 = r\n bnp1 = one\n GO TO 10\n\n20 CONTINUE\n bfrac = bfrac*r\n\n RETURN\n\n END FUNCTION bfrac\n\n!*********************************************************************\n\n SUBROUTINE bgrat(a,b,x,y,w,eps,ierr)\n! .. Scalar Arguments ..\n REAL (dpkind), INTENT (IN) :: a, b, eps, x, y\n REAL (dpkind), INTENT (INOUT) :: w\n INTEGER, INTENT (OUT) :: ierr\n! ..\n! .. Local Scalars ..\n REAL (dpkind) :: bm1, bp2n, cn, coef, dj, j, l, lnx, n2, nu, p, &\n q, r, s, sum, t, t2, u, v, z\n INTEGER :: i, n, nm1\n! ..\n! .. Local Arrays ..\n REAL (dpkind) :: c(30), d(30)\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC ABS, EXP, LOG\n! ..\n!-----------------------------------------------------------------------\n! ASYMPTOTIC EXPANSION FOR IX(A,B) WHEN A IS LARGER THAN B.\n! THE RESULT OF THE EXPANSION IS ADDED TO W. IT IS ASSUMED\n! THAT A .GE. 15 AND B .LE. 1. EPS IS THE TOLERANCE USED.\n! IERR IS A VARIABLE THAT REPORTS THE STATUS OF THE RESULTS.\n!-----------------------------------------------------------------------\n bm1 = (b-half) - half\n nu = a + half*bm1\n\n IF (y<=0.375_dpkind) THEN\n lnx = alnrel(-y)\n ELSE\n lnx = LOG(x)\n END IF\n\n z = -nu*lnx\n IF (b*z==zero) GO TO 10\n\n! COMPUTATION OF THE EXPANSION\n! SET R = EXP(-Z)*Z**B/GAMMA(B)\n\n r = b*(one+gam1(b))*EXP(b*LOG(z))\n r = r*EXP(a*lnx)*EXP(half*bm1*lnx)\n u = algdiv(b,a) + b*LOG(nu)\n u = r*EXP(-u)\n\n IF (u/=zero) THEN\n CALL grat1(b,z,r,p,q,eps)\n\n v = fourth*(one/nu)**2\n t2 = fourth*lnx*lnx\n l = w/u\n j = q/r\n sum = j\n t = one\n cn = one\n n2 = zero\n DO n = 1, 30\n bp2n = b + n2\n j = (bp2n*(bp2n+one)*j+(z+bp2n+one)*t)*v\n n2 = n2 + two\n t = t*t2\n cn = cn/(n2*(n2+one))\n c(n) = cn\n s = zero\n\n IF (n/=1) THEN\n nm1 = n - 1\n coef = b - n\n DO i = 1, nm1\n s = s + coef*c(i)*d(n-i)\n coef = coef + b\n END DO\n END IF\n\n d(n) = bm1*cn + s/n\n dj = d(n)*j\n sum = sum + dj\n IF (sum<=zero) GO TO 10\n IF (ABS(dj)<=eps*(sum+l)) EXIT\n END DO\n\n! ADD THE RESULTS TO W\n\n ierr = 0\n w = w + u*sum\n RETURN\n\n END IF\n\n! THE EXPANSION CANNOT BE COMPUTED\n\n10 CONTINUE\n ierr = 1\n\n RETURN\n\n END SUBROUTINE bgrat\n\n!*********************************************************************\n\n FUNCTION bpser(a,b,x,eps)\n!-----------------------------------------------------------------------\n! POWER SERIES EXPANSION FOR EVALUATING IX(A,B) WHEN B .LE. 1\n! OR B*X .LE. 0.7. EPS IS THE TOLERANCE USED.\n!-----------------------------------------------------------------------\n! .. Function Return Value ..\n REAL (dpkind) :: bpser\n! ..\n! .. Scalar Arguments ..\n REAL (dpkind), INTENT (IN) :: a, b, eps, x\n! ..\n! .. Local Scalars ..\n REAL (dpkind) :: a0, apb, b0, c, n, sum, t, tol, u, w, z\n INTEGER :: i, m\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC ABS, EXP, LOG, MAX, MIN, REAL\n! ..\n bpser = zero\n IF (x==zero) RETURN\n!-----------------------------------------------------------------------\n! COMPUTE THE FACTOR X**A/(A*BETA(A,B))\n!-----------------------------------------------------------------------\n a0 = MIN(a,b)\n IF (a0=eight) GO TO 30\n IF (b0>one) GO TO 20\n\n! PROCEDURE FOR A0 .LT. 1 AND B0 .LE. 1\n\n bpser = x**a\n IF (bpser==zero) RETURN\n\n apb = a + b\n IF (apb<=one) THEN\n z = one + gam1(apb)\n ELSE\n u = REAL(a,kind=dpkind) + REAL(b,kind=dpkind) - one\n z = (one+gam1(u))/apb\n END IF\n\n c = (one+gam1(a))*(one+gam1(b))/z\n bpser = bpser*c*(b/apb)\n GO TO 40\n\n! PROCEDURE FOR A0 .LT. 1 AND 1 .LT. B0 .LT. 8\n\n20 CONTINUE\n u = gamln1(a0)\n m = b0 - one\n\n IF (m>=1) THEN\n c = one\n DO i = 1, m\n b0 = b0 - one\n c = c*(b0/(a0+b0))\n END DO\n\n u = LOG(c) + u\n END IF\n\n z = a*LOG(x) - u\n b0 = b0 - one\n apb = a0 + b0\n\n IF (apb<=one) THEN\n t = one + gam1(apb)\n ELSE\n u = REAL(a0,kind=dpkind) + REAL(b0,kind=dpkind) - one\n t = (one+gam1(u))/apb\n END IF\n\n bpser = EXP(z)*(a0/a)*(one+gam1(b0))/t\n GO TO 40\n\n! PROCEDURE FOR A0 .LT. 1 AND B0 .GE. 8\n\n30 CONTINUE\n u = gamln1(a0) + algdiv(a0,b0)\n z = a*LOG(x) - u\n bpser = (a0/a)*EXP(z)\n\n40 CONTINUE\n IF (bpser==zero .OR. a<=0.1_dpkind*eps) RETURN\n!-----------------------------------------------------------------------\n! COMPUTE THE SERIES\n!-----------------------------------------------------------------------\n sum = zero\n n = zero\n c = one\n tol = eps/a\n\n50 CONTINUE\n n = n + one\n c = c*(half+(half-b/n))*x\n w = c/(a+n)\n sum = sum + w\n IF (ABS(w)>tol) GO TO 50\n\n bpser = bpser*(one+a*sum)\n\n RETURN\n\n END FUNCTION bpser\n\n!*********************************************************************\n\n SUBROUTINE bratio(a,b,x,y,w,w1,ierr)\n!----------------------------------------------------------------------\n! EVALUATION OF THE INCOMPLETE BETA FUNCTION IX(A,B)\n! --------------------\n! IT IS ASSUMED THAT A AND B ARE NONNEGATIVE, AND THAT X .LE. 1\n! AND Y = 1 - X. BRATIO ASSIGNS W AND W1 THE VALUES\n! W = IX(A,B)\n! W1 = 1 - IX(A,B)\n! IERR IS A VARIABLE THAT REPORTS THE STATUS OF THE RESULTS.\n! IF NO INPUT ERRORS ARE DETECTED THEN IERR IS SET TO 0 AND\n! W AND W1 ARE COMPUTED. OTHERWISE, IF AN ERROR IS DETECTED,\n! THEN W AND W1 ARE ASSIGNED THE VALUE 0 AND IERR IS SET TO\n! ONE OF THE FOLLOWING VALUES ...\n! IERR = 1 IF A OR B IS NEGATIVE\n! IERR = 2 IF A = B = 0\n! IERR = 3 IF X .LT. 0 OR X .GT. 1\n! IERR = 4 IF Y .LT. 0 OR Y .GT. 1\n! IERR = 5 IF X + Y .NE. 1\n! IERR = 6 IF X = A = 0\n! IERR = 7 IF Y = B = 0\n!--------------------\n! WRITTEN BY ALFRED H. MORRIS, JR.\n! NAVAL SURFACE WARFARE CENTER\n! DAHLGREN, VIRGINIA\n! REVISED ... NOV 1991\n!-----------------------------------------------------------------------\n! .. Scalar Arguments ..\n REAL (dpkind), INTENT (IN) :: a, b, x, y\n REAL (dpkind), INTENT (OUT) :: w, w1\n INTEGER, INTENT (OUT) :: ierr\n! ..\n! .. Local Scalars ..\n REAL (dpkind) :: a0, b0, eps, lambda, t, x0, y0, z\n INTEGER :: ierr1, ind, n\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC ABS, EPSILON, MAX, MIN\n! ..\n eps = EPSILON(one)\n\n w = zero\n w1 = zero\n\n IF (aone) THEN\n ierr = 3\n RETURN\n END IF\n\n IF (yone) THEN\n ierr = 4\n RETURN\n END IF\n\n z = ((x+y)-half) - half\n\n IF (ABS(z)>three*eps) THEN\n ierr = 5\n RETURN\n END IF\n\n ierr = 0\n IF (x==zero) GO TO 150\n IF (y==zero) GO TO 170\n IF (a==zero) GO TO 180\n IF (b==zero) GO TO 160\n\n eps = MAX(eps,1.E-15_dpkind)\n\n IF (MAX(a,b)<1.E-3_dpkind*eps) GO TO 200\n\n ind = 0\n a0 = a\n b0 = b\n x0 = x\n y0 = y\n IF (MIN(a0,b0)>one) GO TO 30\n\n! PROCEDURE FOR A0 .LE. 1 OR B0 .LE. 1\n\n IF (x>half) THEN\n ind = 1\n a0 = b\n b0 = a\n x0 = y\n y0 = x\n END IF\n\n IF (b0one) GO TO 10\n IF (a0>=MIN(0.2_dpkind,b0)) GO TO 70\n IF (x0**a0<=0.9_dpkind) GO TO 70\n IF (x0>=0.3_dpkind) GO TO 80\n n = 20\n GO TO 100\n\n10 CONTINUE\n IF (b0<=one) GO TO 70\n IF (x0>=0.3_dpkind) GO TO 80\n IF (x0>=0.1_dpkind) GO TO 20\n IF ((x0*b0)**a0<=0.7_dpkind) GO TO 70\n\n20 CONTINUE\n IF (b0>15.0_dpkind) GO TO 110\n n = 20\n GO TO 100\n\n! PROCEDURE FOR A0 .GT. 1 AND B0 .GT. 1\n\n30 CONTINUE\n IF (a<=b) THEN\n lambda = a - (a+b)*x\n ELSE\n lambda = (a+b)*y - b\n END IF\n\n IF (lambdab0) GO TO 40\n IF (a0<=hundred) GO TO 90\n IF (lambda>0.03_dpkind*a0) GO TO 90\n GO TO 140\n\n40 CONTINUE\n IF (b0<=hundred) GO TO 90\n IF (lambda>0.03_dpkind*b0) GO TO 90\n GO TO 140\n\n! EVALUATION OF THE APPROPRIATE ALGORITHM\n\n50 CONTINUE\n w = fpser(a0,b0,x0,eps)\n w1 = half + (half-w)\n GO TO 190\n\n60 CONTINUE\n w1 = apser(a0,b0,x0,eps)\n w = half + (half-w1)\n GO TO 190\n\n70 CONTINUE\n w = bpser(a0,b0,x0,eps)\n w1 = half + (half-w)\n GO TO 190\n\n80 CONTINUE\n w1 = bpser(b0,a0,y0,eps)\n w = half + (half-w1)\n GO TO 190\n\n90 CONTINUE\n w = bfrac(a0,b0,x0,y0,lambda,15.0_dpkind*eps)\n\n w1 = half + (half-w)\n GO TO 190\n\n100 CONTINUE\n w1 = bup(b0,a0,y0,x0,n,eps)\n b0 = b0 + n\n\n110 CONTINUE\n CALL bgrat(b0,a0,y0,x0,w1,15.0_dpkind*eps,ierr1)\n\n w = half + (half-w1)\n GO TO 190\n\n120 CONTINUE\n n = b0\n b0 = b0 - n\n IF (b0==zero) THEN\n n = n - 1\n b0 = one\n END IF\n\n w = bup(b0,a0,y0,x0,n,eps)\n\n IF (x0>0.7_dpkind) GO TO 130\n\n w = w + bpser(a0,b0,x0,eps)\n w1 = half + (half-w)\n GO TO 190\n\n130 CONTINUE\n IF (a0<=15.0_dpkind) THEN\n n = 20\n w = w + bup(a0,b0,x0,y0,n,eps)\n a0 = a0 + n\n END IF\n\n CALL bgrat(a0,b0,x0,y0,w,15.0_dpkind*eps,ierr1)\n\n w1 = half + (half-w)\n GO TO 190\n\n140 CONTINUE\n\n w = basym(a0,b0,lambda,100.0_dpkind*eps)\n\n w1 = half + (half-w)\n GO TO 190\n\n! TERMINATION OF THE PROCEDURE\n\n150 CONTINUE\n IF (a==zero) THEN\n ierr = 6\n RETURN\n END IF\n\n160 CONTINUE\n w = zero\n w1 = one\n RETURN\n\n170 CONTINUE\n IF (b==zero) THEN\n ierr = 7\n RETURN\n END IF\n\n180 CONTINUE\n w = one\n w1 = zero\n RETURN\n\n190 CONTINUE\n IF (ind==0) RETURN\n t = w\n w = w1\n w1 = t\n RETURN\n\n! PROCEDURE FOR A AND B .LT. 1.E-3*EPS\n\n200 CONTINUE\n w = b/(a+b)\n w1 = a/(a+b)\n\n RETURN\n\n END SUBROUTINE bratio\n\n!*********************************************************************\n\n FUNCTION brcmp1(mu,a,b,x,y)\n!-----------------------------------------------------------------------\n! EVALUATION OF EXP(MU) * (X**A*Y**B/BETA(A,B))\n!-----------------------------------------------------------------------\n!-----------------\n! CONST = 1/SQRT(2*PI)\n!-----------------\n! .. Function Return Value ..\n REAL (dpkind) :: brcmp1\n! ..\n! .. Scalar Arguments ..\n REAL (dpkind), INTENT (IN) :: a, b, x, y\n INTEGER, INTENT (IN) :: mu\n! ..\n! .. Local Scalars ..\n REAL (dpkind) :: a0, apb, b0, c, e, h, lambda, lnx, lny, t, u, v, &\n x0, y0, z\n INTEGER :: i, n\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC ABS, EXP, LOG, MAX, MIN, SQRT\n! ..\n! .. Parameters ..\n REAL (dpkind), PARAMETER :: const = .398942280401433_dpkind\n! ..\n a0 = MIN(a,b)\n\n IF (a0>=eight) GO TO 30\n\n IF (x<=0.375_dpkind) THEN\n lnx = LOG(x)\n lny = alnrel(-x)\n ELSE\n\n IF (y<=0.375_dpkind) THEN\n lnx = alnrel(-y)\n lny = LOG(y)\n ELSE\n lnx = LOG(x)\n lny = LOG(y)\n END IF\n END IF\n\n z = a*lnx + b*lny\n\n IF (a0>=one) THEN\n z = z - betaln(a,b)\n brcmp1 = esum(mu,z)\n\n RETURN\n END IF\n\n!-----------------------------------------------------------------------\n! PROCEDURE FOR A .LT. 1 OR B .LT. 1\n!-----------------------------------------------------------------------\n b0 = MAX(a,b)\n IF (b0>=eight) GO TO 20\n IF (b0>one) GO TO 10\n\n! ALGORITHM FOR B0 .LE. 1\n\n brcmp1 = esum(mu,z)\n\n IF (brcmp1==zero) RETURN\n\n apb = a + b\n IF (apb<=one) THEN\n z = one + gam1(apb)\n ELSE\n u = a + b - one\n z = (one+gam1(u))/apb\n END IF\n\n c = (one+gam1(a))*(one+gam1(b))/z\n brcmp1 = brcmp1*(a0*c)/(one+a0/b0)\n\n RETURN\n\n! ALGORITHM FOR 1 .LT. B0 .LT. 8\n\n10 CONTINUE\n u = gamln1(a0)\n n = b0 - one\n\n IF (n>=1) THEN\n c = one\n DO i = 1, n\n b0 = b0 - one\n c = c*(b0/(a0+b0))\n END DO\n u = LOG(c) + u\n\n END IF\n\n z = z - u\n b0 = b0 - one\n apb = a0 + b0\n\n IF (apb<=one) THEN\n t = one + gam1(apb)\n ELSE\n u = a0 + b0 - one\n t = (one+gam1(u))/apb\n END IF\n\n brcmp1 = a0*esum(mu,z)*(one+gam1(b0))/t\n\n RETURN\n\n! ALGORITHM FOR B0 .GE. 8\n\n20 CONTINUE\n u = gamln1(a0) + algdiv(a0,b0)\n brcmp1 = a0*esum(mu,z-u)\n\n RETURN\n!-----------------------------------------------------------------------\n! PROCEDURE FOR A .GE. 8 AND B .GE. 8\n!-----------------------------------------------------------------------\n30 CONTINUE\n IF (a<=b) THEN\n h = a/b\n x0 = h/(one+h)\n y0 = one/(one+h)\n lambda = a - (a+b)*x\n ELSE\n h = b/a\n x0 = one/(one+h)\n y0 = h/(one+h)\n lambda = (a+b)*y - b\n END IF\n\n e = -lambda/a\n IF (ABS(e)<=0.6_dpkind) THEN\n u = rlog1(e)\n ELSE\n u = e - LOG(x/x0)\n END IF\n\n e = lambda/b\n\n IF (ABS(e)<=0.6_dpkind) THEN\n v = rlog1(e)\n ELSE\n v = e - LOG(y/y0)\n END IF\n\n z = esum(mu,-(a*u+b*v))\n\n brcmp1 = const*SQRT(b*x0)*z*EXP(-bcorr(a,b))\n\n END FUNCTION brcmp1\n\n!*********************************************************************\n\n FUNCTION brcomp(a,b,x,y)\n!-----------------------------------------------------------------------\n! EVALUATION OF X**A*Y**B/BETA(A,B)\n!-----------------------------------------------------------------------\n!-----------------\n! CONST = 1/SQRT(2*PI)\n!-----------------\n! .. Function Return Value ..\n REAL (dpkind) :: brcomp\n! ..\n! .. Scalar Arguments ..\n REAL (dpkind), INTENT (IN) :: a, b, x, y\n! ..\n! .. Local Scalars ..\n REAL (dpkind) :: a0, apb, b0, c, e, h, lambda, lnx, lny, t, u, v, &\n x0, y0, z\n INTEGER :: i, n\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC ABS, EXP, LOG, MAX, MIN, SQRT\n! ..\n! .. Parameters ..\n REAL (dpkind), PARAMETER :: const = .398942280401433_dpkind\n! ..\n brcomp = zero\n\n IF (x<=zero .OR. y<=zero) RETURN\n\n a0 = MIN(a,b)\n\n IF (a0>=8.0_dpkind) GO TO 30\n\n IF (x<=0.375_dpkind) THEN\n lnx = LOG(x)\n lny = alnrel(-x)\n ELSE\n IF (y<=0.375_dpkind) THEN\n lnx = alnrel(-y)\n lny = LOG(y)\n ELSE\n lnx = LOG(x)\n lny = LOG(y)\n END IF\n END IF\n\n z = a*lnx + b*lny\n\n IF (a0>=one) THEN\n z = z - betaln(a,b)\n brcomp = EXP(z)\n\n RETURN\n END IF\n\n!-----------------------------------------------------------------------\n! PROCEDURE FOR A .LT. 1 OR B .LT. 1\n!-----------------------------------------------------------------------\n\n b0 = MAX(a,b)\n\n IF (b0>=eight) GO TO 20\n IF (b0>one) GO TO 10\n\n! ALGORITHM FOR B0 .LE. 1\n\n brcomp = EXP(z)\n\n IF (brcomp==zero) RETURN\n\n apb = a + b\n\n IF (apb<=one) THEN\n z = one + gam1(apb)\n ELSE\n u = a + b - one\n z = (one+gam1(u))/apb\n END IF\n\n c = (one+gam1(a))*(one+gam1(b))/z\n brcomp = brcomp*(a0*c)/(one+a0/b0)\n RETURN\n\n! ALGORITHM FOR 1 .LT. B0 .LT. 8\n\n10 CONTINUE\n u = gamln1(a0)\n n = b0 - one\n\n IF (n>=1) THEN\n c = one\n DO i = 1, n\n b0 = b0 - one\n c = c*(b0/(a0+b0))\n END DO\n\n u = LOG(c) + u\n\n END IF\n\n z = z - u\n b0 = b0 - one\n apb = a0 + b0\n\n IF (apb<=one) THEN\n t = one + gam1(apb)\n ELSE\n u = a0 + b0 - one\n t = (one+gam1(u))/apb\n END IF\n\n brcomp = a0*EXP(z)*(one+gam1(b0))/t\n RETURN\n\n! ALGORITHM FOR B0 .GE. 8\n\n20 CONTINUE\n u = gamln1(a0) + algdiv(a0,b0)\n brcomp = a0*EXP(z-u)\n RETURN\n!-----------------------------------------------------------------------\n! PROCEDURE FOR A .GE. 8 AND B .GE. 8\n!-----------------------------------------------------------------------\n30 CONTINUE\n IF (a<=b) THEN\n h = a/b\n x0 = h/(one+h)\n y0 = one/(one+h)\n lambda = a - (a+b)*x\n ELSE\n h = b/a\n x0 = one/(one+h)\n y0 = h/(one+h)\n lambda = (a+b)*y - b\n END IF\n\n e = -lambda/a\n\n IF (ABS(e)<=0.6_dpkind) THEN\n u = rlog1(e)\n ELSE\n u = e - LOG(x/x0)\n END IF\n\n e = lambda/b\n\n IF (ABS(e)<=0.6_dpkind) THEN\n v = rlog1(e)\n ELSE\n v = e - LOG(y/y0)\n END IF\n z = EXP(-(a*u+b*v))\n\n brcomp = const*SQRT(b*x0)*z*EXP(-bcorr(a,b))\n\n END FUNCTION brcomp\n\n!*********************************************************************\n\n FUNCTION bup(a,b,x,y,n,eps)\n!-----------------------------------------------------------------------\n! EVALUATION OF IX(A,B) - IX(A+N,B) WHERE N IS A POSITIVE INTEGER.\n! EPS IS THE TOLERANCE USED.\n!-----------------------------------------------------------------------\n! .. Function Return Value ..\n REAL (dpkind) :: bup\n! ..\n! .. Scalar Arguments ..\n REAL (dpkind), INTENT (IN) :: a, b, eps, x, y\n INTEGER, INTENT (IN) :: n\n! ..\n! .. Local Scalars ..\n REAL (dpkind) :: ap1, apb, d, l, r, t, w\n INTEGER :: i, k, kp1, mu, nm1\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC ABS, EXP, MIN\n! ..\n! OBTAIN THE SCALING FACTOR EXP(-MU) AND\n! EXP(MU)*(X**A*Y**B/BETA(A,B))/A\n apb = a + b\n ap1 = a + one\n mu = 0\n d = one\n\n IF (n/=1 .AND. a>=one) THEN\n IF (apb>=1.1_dpkind*ap1) THEN\n mu = ABS(exparg(1))\n k = exparg(0)\n mu = MIN(k,mu)\n t = mu\n d = EXP(-t)\n\n END IF\n END IF\n\n bup = brcmp1(mu,a,b,x,y)/a\n\n IF (n==1 .OR. bup==zero) RETURN\n\n nm1 = n - 1\n w = d\n\n! LET K BE THE INDEX OF THE MAXIMUM TERM\n\n k = 0\n IF (b<=one) GO TO 30\n IF (y>1.E-4_dpkind) GO TO 10\n k = nm1\n GO TO 20\n\n10 CONTINUE\n r = (b-one)*x/y - a\n IF (rfour) GO TO 10\n\n top = evaluate_polynomial(p,ax)\n bot = evaluate_polynomial(q,ax)\n\n erfc1 = top/bot\n\n GO TO 30\n\n! ABS(X) .GT. 4\n\n10 CONTINUE\n\n IF (x<=(-5.6_dpkind)) GO TO 40\n\n IF (ind/=0) GO TO 20\n\n IF (x>hundred) GO TO 50\n\n IF (x*x>-exparg(1)) GO TO 50\n\n20 CONTINUE\n\n t = (one/x)**2\n\n top = evaluate_polynomial(r,t)\n bot = evaluate_polynomial(s,t)\n\n erfc1 = (c-t*top/bot)/ax\n\n! FINAL ASSEMBLY\n\n30 CONTINUE\n\n IF (ind/=0) THEN\n IF (xzero) GO TO 10\n\n IF (mu<0) GO TO 20\n\n w = mu + x\n\n IF (w>zero) GO TO 20\n esum = EXP(w)\n RETURN\n\n10 CONTINUE\n IF (mu>0) GO TO 20\n\n w = mu + x\n\n IF (w>=zero) THEN\n esum = EXP(w)\n RETURN\n\n END IF\n\n20 CONTINUE\n w = mu\n esum = EXP(w)*EXP(x)\n\n RETURN\n\n END FUNCTION esum\n\n!*********************************************************************\n\n FUNCTION evaluate_polynomial(a,x)\n!----------------------------------------------------------------------\n! Evaluate a PoLynomial at x\n! Function\n! Returns:\n! A(1) + A(2)*X + ... + A(N)*X**(N-1)\n! Arguments\n! A --> Array of coefficients of the polynomial.\n! X --> Point at which the polynomial is to be evaluated.\n!----------------------------------------------------------------------\n! .. Function Return Value ..\n REAL (dpkind) :: evaluate_polynomial\n! ..\n! .. Scalar Arguments ..\n REAL (dpkind), INTENT (IN) :: x\n! ..\n! .. Array Arguments ..\n REAL (dpkind), INTENT (IN) :: a(:)\n! ..\n! .. Local Scalars ..\n REAL (dpkind) :: term\n INTEGER :: i, n\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC SIZE\n! ..\n n = SIZE(a)\n term = a(n)\n\n DO i = n - 1, 1, -1\n term = a(i) + term*x\n END DO\n\n evaluate_polynomial = term\n\n END FUNCTION evaluate_polynomial\n\n!*********************************************************************\n\n FUNCTION exparg(l)\n! .. Function Return Value ..\n REAL (dpkind) :: exparg\n! ..\n! .. Scalar Arguments ..\n INTEGER :: l\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC HUGE, LOG, TINY\n! ..\n!--------------------------------------------------------------------\n! IF L = 0 THEN EXPARG(L) = THE LARGEST POSITIVE W FOR WHICH\n! EXP(W) CAN BE COMPUTED.\n! IF L IS NONZERO THEN EXPARG(L) = THE LARGEST NEGATIVE W FOR\n! WHICH THE COMPUTED VALUE OF EXP(W) IS NONZERO.\n! NOTE... ONLY AN APPROXIMATE VALUE FOR EXPARG(L) IS NEEDED.\n!--------------------------------------------------------------------\n IF (l==0) THEN\n exparg = LOG(HUGE(one))\n ELSE\n exparg = LOG(TINY(one))\n END IF\n\n END FUNCTION exparg\n\n!*********************************************************************\n\n FUNCTION fpser(a,b,x,eps)\n!-----------------------------------------------------------------------\n! EVALUATION OF I (A,B)\n! X\n! FOR B .LT. MIN(EPS,EPS*A) AND X .LE. 0.5.\n!-----------------------------------------------------------------------\n! .. Function Return Value ..\n REAL (dpkind) :: fpser\n! ..\n! .. Scalar Arguments ..\n REAL (dpkind), INTENT (IN) :: a, b, eps, x\n! ..\n! .. Local Scalars ..\n REAL (dpkind) :: an, c, s, t, tol\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC ABS, EXP, LOG\n! ..\n! SET FPSER = X**A\n fpser = one\n\n IF (a>1.E-3_dpkind*eps) THEN\n fpser = zero\n t = a*LOG(x)\n IF (tzero) t = d - half\n\n IF (t==zero) THEN\n gam1 = zero\n ELSE IF (t>zero) THEN\n w = evaluate_polynomial(p,t)/evaluate_polynomial(q,t)\n\n IF (d<=zero) THEN\n gam1 = a*w\n ELSE\n gam1 = (t/a)*((w-half)-half)\n END IF\n\n ELSE\n w = evaluate_polynomial(r,t)/((s2*t+s1)*t+one)\n\n IF (d<=zero) THEN\n gam1 = a*((w+half)+half)\n ELSE\n gam1 = t*w/a\n END IF\n END IF\n\n END FUNCTION gam1\n\n!*********************************************************************\n\n FUNCTION gamln(a)\n!-----------------------------------------------------------------------\n! EVALUATION OF LN(GAMMA(A)) FOR POSITIVE A\n!-----------------------------------------------------------------------\n! WRITTEN BY ALFRED H. MORRIS\n! NAVAL SURFACE WARFARE CENTER\n! DAHLGREN, VIRGINIA\n!--------------------------\n! D = 0.5*(LN(2*PI) - 1)\n!--------------------------\n!--------------------------\n! .. Function Return Value ..\n REAL (dpkind) :: gamln\n! ..\n! .. Scalar Arguments ..\n REAL (dpkind), INTENT (IN) :: a\n! ..\n! .. Local Scalars ..\n REAL (dpkind) :: t, w\n INTEGER :: i, n\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC LOG\n! ..\n! .. Parameters ..\n REAL (dpkind), PARAMETER :: c(6) = (/ .833333333333333E-01_dpkind &\n , -.277777777760991E-02_dpkind, .793650666825390E-03_dpkind, &\n -.595202931351870E-03_dpkind, .837308034031215E-03_dpkind, &\n -.165322962780713E-02_dpkind/)\n REAL (dpkind), PARAMETER :: d = .418938533204673_dpkind\n! ..\n!-----------------------------------------------------------------------\n IF (a<=zero) THEN\n gamln = -one\n ELSE IF (a<=0.8_dpkind) THEN\n gamln = gamln1(a) - LOG(a)\n ELSE IF (a<=2.25_dpkind) THEN\n t = (a-half) - half\n gamln = gamln1(t)\n ELSE IF (a<10.0_dpkind) THEN\n n = a - 1.25_dpkind\n t = a\n w = one\n\n DO i = 1, n\n t = t - one\n w = t*w\n END DO\n\n gamln = gamln1(t-one) + LOG(w)\n ELSE\n\n t = (one/a)**2\n\n w = evaluate_polynomial(c,t)/a\n\n gamln = (d+w) + (a-half)*(LOG(a)-one)\n END IF\n\n END FUNCTION gamln\n\n!*********************************************************************\n\n FUNCTION gamln1(a)\n!-----------------------------------------------------------------------\n! EVALUATION OF LN(GAMMA(1 + A)) FOR -0.2 .LE. A .LE. 1.25\n!-----------------------------------------------------------------------\n! .. Function Return Value ..\n REAL (dpkind) :: gamln1\n! ..\n! .. Scalar Arguments ..\n REAL (dpkind), INTENT (IN) :: a\n! ..\n! .. Local Scalars ..\n REAL (dpkind) :: w, x\n! ..\n! .. Parameters ..\n REAL (dpkind), PARAMETER :: p(7) = (/ .577215664901533E+00_dpkind &\n , .844203922187225E+00_dpkind, -.168860593646662E+00_dpkind, &\n -.780427615533591E+00_dpkind, -.402055799310489E+00_dpkind, &\n -.673562214325671E-01_dpkind, -.271935708322958E-02_dpkind/)\n REAL (dpkind), PARAMETER :: q(7) = (/ one, &\n .288743195473681E+01_dpkind, .312755088914843E+01_dpkind, &\n .156875193295039E+01_dpkind, .361951990101499E+00_dpkind, &\n .325038868253937E-01_dpkind, .667465618796164E-03_dpkind/)\n REAL (dpkind), PARAMETER :: r(6) = (/ .422784335098467E+00_dpkind &\n , .848044614534529E+00_dpkind, .565221050691933E+00_dpkind, &\n .156513060486551E+00_dpkind, .170502484022650E-01_dpkind, &\n .497958207639485E-03_dpkind/)\n REAL (dpkind), PARAMETER :: s(6) = (/ one, &\n .124313399877507E+01_dpkind, .548042109832463E+00_dpkind, &\n .101552187439830E+00_dpkind, .713309612391000E-02_dpkind, &\n .116165475989616E-03_dpkind/)\n! ..\n IF (a<0.6_dpkind) THEN\n w = evaluate_polynomial(p,a)/evaluate_polynomial(q,a)\n\n gamln1 = -a*w\n\n ELSE\n\n x = (a-half) - half\n\n w = evaluate_polynomial(r,x)/evaluate_polynomial(s,x)\n\n gamln1 = x*w\n END IF\n\n END FUNCTION gamln1\n\n!*********************************************************************\n\n FUNCTION gamma(a)\n!-----------------------------------------------------------------------\n! EVALUATION OF THE GAMMA FUNCTION FOR REAL ARGUMENTS\n! -----------\n! GAMMA(A) IS ASSIGNED THE VALUE 0 WHEN THE GAMMA FUNCTION CANNOT\n! BE COMPUTED.\n!-----------------------------------------------------------------------\n! WRITTEN BY ALFRED H. MORRIS, JR.\n! NAVAL SURFACE WEAPONS CENTER\n! DAHLGREN, VIRGINIA\n!-----------------------------------------------------------------------\n!--------------------------\n! D = 0.5*(LN(2*PI) - 1)\n!--------------------------\n!--------------------------\n! .. Scalar Arguments ..\n REAL (dpkind), INTENT (IN) :: a\n! ..\n! .. Local Scalars ..\n REAL (dpkind) :: g, lnx, s, t, w, x, z\n INTEGER :: j, m, n\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC ABS, EXP, HUGE, INT, LOG, MOD, SIN\n! ..\n! .. Parameters ..\n REAL (dpkind), PARAMETER :: d = .41893853320467274178E0_dpkind\n REAL (dpkind), PARAMETER :: pi = 3.1415926535898E0_dpkind\n REAL (dpkind), PARAMETER :: p(7) = (/ one, &\n .553413866010467E+00_dpkind, .279648642639792E+00_dpkind, &\n .730981088720487E-01_dpkind, .204493667594920E-01_dpkind, &\n .261939260042690E-02_dpkind, .539637273585445E-03_dpkind/)\n REAL (dpkind), PARAMETER :: q(7) = (/ one, &\n .113062953091122E+01_dpkind, -.567902761974940E-01_dpkind, &\n -.170458969313360E+00_dpkind, .225211131035340E-01_dpkind, &\n .470059485860584E-02_dpkind, -.832979206704073E-03_dpkind/)\n REAL (dpkind), PARAMETER :: r(5) = (/ .833333333333333E-01_dpkind &\n , -.277777777770481E-02_dpkind, .793650663183693E-03_dpkind, &\n -.595156336428591E-03_dpkind, .820756370353826E-03_dpkind/)\n! ..\n! .. Function Return Value ..\n REAL (dpkind) :: gamma\n! ..\n!--------------------------\n gamma = zero\n x = a\n\n IF (ABS(a)>=15.0E0_dpkind) GO TO 40\n\n!-----------------------------------------------------------------------\n! EVALUATION OF GAMMA(A) FOR ABS(A) .LT. 15\n!-----------------------------------------------------------------------\n t = one\n m = INT(a) - 1\n\n IF (m<0) GO TO 10\n IF (m/=0) THEN\n\n! LET T BE THE PRODUCT OF A-J WHEN A .GE. 2\n\n DO j = 1, m\n x = x - one\n t = x*t\n END DO\n END IF\n\n x = x - one\n GO TO 30\n\n! LET T BE THE PRODUCT OF A+J WHEN A .LT. 1\n\n10 CONTINUE\n t = a\n IF (a>zero) GO TO 20\n\n m = (-m) - 1\n IF (m/=0) THEN\n DO j = 1, m\n x = x + one\n t = x*t\n END DO\n END IF\n\n x = (x+half) + half\n t = x*t\n IF (t==zero) RETURN\n\n20 CONTINUE\n\n! THE FOLLOWING CODE CHECKS IF 1/T CAN OVERFLOW. THIS\n! CODE MAY BE OMITTED IF DESIRED.\n\n IF (ABS(t)>=1.E-30_dpkind) GO TO 30\n IF (ABS(t)*HUGE(one)<=1.0001E0_dpkind) RETURN\n\n gamma = one/t\n RETURN\n\n! COMPUTE GAMMA(1 + X) FOR 0 .LE. X .LT. 1\n\n30 CONTINUE\n\n gamma = evaluate_polynomial(p,x)/evaluate_polynomial(q,x)\n\n! TERMINATION\n\n IF (a>=one) THEN\n gamma = gamma*t\n RETURN\n\n END IF\n\n gamma = gamma/t\n RETURN\n\n!-----------------------------------------------------------------------\n! EVALUATION OF GAMMA(A) FOR ABS(A) .GE. 15\n!-----------------------------------------------------------------------\n40 CONTINUE\n IF (ABS(a)>=1.E3_dpkind) RETURN\n\n IF (a>zero) GO TO 50\n\n x = -a\n n = x\n t = x - n\n\n IF (t>0.9E0_dpkind) t = one - t\n\n s = SIN(pi*t)/pi\n\n IF (MOD(n,2)==0) s = -s\n\n IF (s==zero) RETURN\n\n! COMPUTE THE MODIFIED ASYMPTOTIC SUM\n\n50 CONTINUE\n t = one/(x*x)\n\n g = evaluate_polynomial(r,t)/x\n\n! ONE MAY REPLACE THE NEXT STATEMENT WITH LNX = ALOG(X)\n! BUT LESS ACCURACY WILL NORMALLY BE OBTAINED.\n\n lnx = LOG(x)\n\n! FINAL ASSEMBLY\n\n z = x\n g = (d+g) + (z-half)*(lnx-1.E0_dpkind)\n w = g\n t = g - w\n\n IF (w>0.99999E0_dpkind*exparg(0)) RETURN\n\n gamma = EXP(w)*(one+t)\n\n IF (atol) GO TO 20\n\n j = a*x*((sum/six-half/(a+two))*x+one/(a+one))\n\n z = a*LOG(x)\n h = gam1(a)\n g = one + h\n\n IF (x(-.13394E0_dpkind)) GO TO 50\n\n40 CONTINUE\n w = EXP(z)\n p = w*g*(half+(half-j))\n q = half + (half-p)\n RETURN\n\n50 CONTINUE\n l = rexp(z)\n w = half + (half+l)\n q = (w*j-l)*g - h\n IF (q=eps*an0) GO TO 70\n\n q = r*an0\n p = half + (half-q)\n RETURN\n\n! SPECIAL CASES\n\n80 CONTINUE\n p = zero\n q = one\n RETURN\n\n90 CONTINUE\n p = one\n q = zero\n RETURN\n\n100 CONTINUE\n IF (x=one) GO TO 10\n IF (a==half) GO TO 320\n IF (x<1.1E0_dpkind) GO TO 120\n\n t1 = a*LOG(x) - x\n u = a*EXP(t1)\n\n IF (u==zero) GO TO 310\n\n r = u*(one+gam1(a))\n GO TO 200\n\n10 CONTINUE\n IF (a>=big(iop)) GO TO 30\n\n IF (a>x .OR. x>=x0) GO TO 20\n\n twoa = a + a\n m = INT(twoa)\n\n IF (twoa/=REAL(m,kind=dpkind)) GO TO 20\n\n i = m/2\n\n IF (a==REAL(i,kind=dpkind)) GO TO 170\n GO TO 180\n\n20 CONTINUE\n t1 = a*LOG(x) - x\n r = EXP(t1)/gamma(a)\n GO TO 40\n\n30 CONTINUE\n l = x/a\n\n IF (l==zero) GO TO 300\n\n s = half + (half-l)\n z = rlog(l)\n\n IF (z>=700.0E0_dpkind/a) GO TO 330\n\n y = a*z\n rta = SQRT(a)\n\n IF (ABS(s)<=e0/rta) GO TO 260\n\n IF (ABS(s)<=0.4E0_dpkind) GO TO 220\n\n t = (one/a)**2\n\n t1 = evaluate_polynomial(d7,t)/(a*1260.0E0_dpkind)\n\n t1 = t1 - y\n r = rt2pin*rta*EXP(t1)\n\n40 CONTINUE\n IF (r==zero) GO TO 340\n IF (x<=DMAX1(a,alog10)) GO TO 50\n IF (xtol) GO TO 70\n\n max = n - 1\n DO m = 1, max\n n = n - 1\n sum = sum + wk(n)\n END DO\n\n ans = (r/a)*(one+sum)\n qans = half + (half-ans)\n\n RETURN\n\n! ASYMPTOTIC EXPANSION\n\n80 CONTINUE\n amn = a - one\n t = amn/x\n wk(1) = t\n\n DO n = 2, 20\n amn = amn - one\n t = t*(amn/x)\n IF (ABS(t)<=1.E-3_dpkind) GO TO 90\n wk(n) = t\n END DO\n n = 20\n\n90 CONTINUE\n sum = t\n\n100 CONTINUE\n IF (ABS(t)<=acc) GO TO 110\n\n amn = amn - one\n t = t*(amn/x)\n sum = sum + t\n GO TO 100\n\n110 CONTINUE\n max = n - 1\n DO m = 1, max\n n = n - 1\n sum = sum + wk(n)\n END DO\n\n qans = (r/x)*(one+sum)\n ans = half + (half-qans)\n RETURN\n\n! TAYLOR SERIES FOR P(A,X)/X**A\n\n120 CONTINUE\n an = three\n c = x\n sum = x/(a+three)\n tol = three*acc/(a+one)\n\n130 CONTINUE\n an = an + one\n c = -c*(x/an)\n t = c/(a+an)\n sum = sum + t\n\n IF (ABS(t)>tol) GO TO 130\n\n j = a*x*((sum/six-half/(a+two))*x+one/(a+one))\n\n z = a*LOG(x)\n h = gam1(a)\n g = one + h\n\n IF (x(-.13394E0_dpkind)) GO TO 160\n\n150 CONTINUE\n w = EXP(z)\n ans = w*g*(half+(half-j))\n qans = half + (half-ans)\n\n RETURN\n\n160 CONTINUE\n l = rexp(z)\n w = half + (half+l)\n qans = (w*j-l)*g - h\n\n IF (qans0) THEN\n DO n = n1, i - 1\n c = c + one\n t = (x*t)/c\n sum = sum + t\n END DO\n END IF\n\n qans = sum\n ans = half + (half-qans)\n RETURN\n\n! CONTINUED FRACTION EXPANSION\n\n200 CONTINUE\n tol = DMAX1(five*e,acc)\n a2nm1 = one\n a2n = one\n b2nm1 = x\n b2n = x + (one-a)\n c = one\n210 CONTINUE\n a2nm1 = x*a2n + c*a2nm1\n b2nm1 = x*b2n + c*b2nm1\n am0 = a2nm1/b2nm1\n c = c + one\n cma = c - a\n a2n = a2nm1 + cma*a2n\n b2n = b2nm1 + cma*b2n\n an0 = a2n/b2n\n IF (ABS(an0-am0)>=tol*an0) GO TO 210\n\n qans = r*an0\n ans = half + (half-qans)\n RETURN\n\n! GENERAL TEMME EXPANSION\n\n220 CONTINUE\n IF (ABS(s)<=two*e .AND. a*e*e>3.28E-3_dpkind) GO TO 350\n c = EXP(-y)\n w = half*erfc1(1,SQRT(y))\n u = one/a\n z = SQRT(z+z)\n\n IF (l0) GO TO 240\n IF (iop-2==0) GO TO 230\n\n IF (ABS(s)<=thousandth) GO TO 270\n\n c1(1) = evaluate_polynomial(d0,z)\n\n c1(2) = evaluate_polynomial(d1,z)\n\n c1(3) = evaluate_polynomial(d2,z)\n\n c1(4) = evaluate_polynomial(d3,z)\n\n c1(5) = evaluate_polynomial(d4,z)\n\n c1(6) = evaluate_polynomial(d5,z)\n\n c1(7) = evaluate_polynomial(d6,z)\n\n t = evaluate_polynomial(c1,u)\n\n GO TO 250\n\n230 CONTINUE\n c1(1) = evaluate_polynomial(d0(1:7),z)\n\n c1(2) = evaluate_polynomial(d1(1:5),z)\n\n c1(3) = d2(2)*z + d2(1)\n\n t = evaluate_polynomial(c1(1:3),u)\n\n GO TO 250\n\n240 CONTINUE\n t = evaluate_polynomial(d0(1:4),z)\n\n250 CONTINUE\n IF (l>=one) THEN\n qans = c*(w+rt2pin*t/rta)\n ans = half + (half-qans)\n RETURN\n\n END IF\n\n ans = c*(w-rt2pin*t/rta)\n qans = half + (half-ans)\n RETURN\n\n! TEMME EXPANSION FOR L = 1\n\n260 CONTINUE\n IF (a*e*e>3.28E-3_dpkind) GO TO 350\n\n c = half + (half-y)\n w = (half-SQRT(y)*(half+(half-y/three))/rtpi)/c\n u = one/a\n z = SQRT(z+z)\n\n IF (l0) GO TO 290\n IF (iop-2==0) GO TO 280\n\n270 CONTINUE\n c1(1) = evaluate_polynomial(d0(1:8),z)\n\n c1(2) = evaluate_polynomial(d1(1:7),z)\n\n c1(3) = evaluate_polynomial(d2(1:5),z)\n\n c1(4) = evaluate_polynomial(d3(1:5),z)\n\n c1(5) = evaluate_polynomial(d4(1:3),z)\n\n c1(6) = evaluate_polynomial(d5(1:3),z)\n\n c1(7) = d6(2)*z + d6(1)\n\n t = evaluate_polynomial(c1,u)\n GO TO 250\n\n280 CONTINUE\n c1(1) = (d0(3)*z+d0(2))*z - d0(1)\n c1(2) = d1(2)*z + d1(1)\n\n t = (d2(1)*u+c1(2))*u + c1(1)\n GO TO 250\n\n290 CONTINUE\n t = d0(2)*z - d0(1)\n GO TO 250\n\n! SPECIAL CASES\n\n300 CONTINUE\n ans = zero\n qans = one\n RETURN\n\n310 CONTINUE\n ans = one\n qans = zero\n RETURN\n\n320 CONTINUE\n IF (x=eight) GO TO 50\n IF (a>=one) GO TO 10\n!-----------------------------------------------------------------------\n! PROCEDURE WHEN A .LT. 1\n!-----------------------------------------------------------------------\n IF (btwo) GO TO 20\n IF (b<=two) THEN\n log_beta = gamln(a) + gamln(b) - gsumln(a,b)\n RETURN\n\n END IF\n\n w = zero\n IF (bthousand) GO TO 40\n n = a - one\n w = one\n\n DO i = 1, n\n a = a - one\n h = a/b\n w = w*(h/(one+h))\n END DO\n\n w = LOG(w)\n\n IF (b>=eight) THEN\n log_beta = w + gamln(a) + algdiv(a,b)\n RETURN\n\n! REDUCTION OF B WHEN B .LT. 8\n\n END IF\n\n30 CONTINUE\n n = b - one\n z = one\n\n DO i = 1, n\n b = b - one\n z = z*(b/(a+b))\n END DO\n\n log_beta = w + LOG(z) + (gamln(a)+(gamln(b)-gsumln(a,b)))\n RETURN\n\n! REDUCTION OF A WHEN B .GT. 1000\n\n40 CONTINUE\n n = a - one\n w = one\n DO i = 1, n\n a = a - one\n w = w*(a/(one+a/b))\n END DO\n\n log_beta = (LOG(w)-n*LOG(b)) + (gamln(a)+algdiv(a,b))\n RETURN\n!-----------------------------------------------------------------------\n! PROCEDURE WHEN A .GE. 8\n!-----------------------------------------------------------------------\n50 CONTINUE\n w = bcorr(a,b)\n h = a/b\n c = h/(one+h)\n u = -(a-half)*LOG(c)\n v = b*alnrel(h)\n\n IF (u>v) THEN\n log_beta = ((((-half*LOG(b))+e)+w)-v) - u\n RETURN\n\n END IF\n\n log_beta = ((((-half*LOG(b))+e)+w)-u) - v\n\n END FUNCTION log_beta\n\n!*********************************************************************\n\n FUNCTION log_bicoef(k,n)\n! .. Function Return Value ..\n REAL (dpkind) :: log_bicoef\n! ..\n! .. Scalar Arguments ..\n REAL (dpkind), INTENT (IN) :: k, n\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC LOG\n! ..\n log_bicoef = -log_beta(k+one,n-k+one) - LOG(n+one)\n\n END FUNCTION log_bicoef\n\n!*********************************************************************\n\n FUNCTION log_gamma(a)\n!-----------------------------------------------------------------------\n! EVALUATION OF LN(GAMMA(A)) FOR POSITIVE A\n!-----------------------------------------------------------------------\n! WRITTEN BY ALFRED H. MORRIS\n! NAVAL SURFACE WARFARE CENTER\n! DAHLGREN, VIRGINIA\n!--------------------------\n! D = 0.5*(LN(2*PI) - 1)\n!--------------------------\n!--------------------------\n! .. Function Return Value ..\n REAL (dpkind) :: log_gamma\n! ..\n! .. Scalar Arguments ..\n REAL (dpkind), INTENT (IN) :: a\n! ..\n! .. Local Scalars ..\n REAL (dpkind) :: t, w\n INTEGER :: i, n\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC LOG\n! ..\n! .. Parameters ..\n REAL (dpkind), PARAMETER :: c(6) = (/ .833333333333333E-01_dpkind &\n , -.277777777760991E-02_dpkind, .793650666825390E-03_dpkind, &\n -.595202931351870E-03_dpkind, .837308034031215E-03_dpkind, &\n -.165322962780713E-02_dpkind/)\n REAL (dpkind), PARAMETER :: d = .418938533204673_dpkind\n! ..\n!-----------------------------------------------------------------------\n IF (a<=0.8_dpkind) THEN\n log_gamma = gamln1(a) - LOG(a)\n\n ELSE IF (a<=2.25_dpkind) THEN\n t = (a-half) - half\n log_gamma = gamln1(t)\n\n ELSE IF (a<10.0_dpkind) THEN\n n = a - 1.25_dpkind\n t = a\n w = one\n\n DO i = 1, n\n t = t - one\n w = t*w\n END DO\n\n log_gamma = gamln1(t-one) + LOG(w)\n\n ELSE\n\n t = (one/a)**2\n w = evaluate_polynomial(c,t)/a\n\n log_gamma = (d+w) + (a-half)*(LOG(a)-one)\n\n END IF\n\n END FUNCTION log_gamma\n\n!*********************************************************************\n\n FUNCTION psi(xx)\n!---------------------------------------------------------------------\n! EVALUATION OF THE DIGAMMA FUNCTION\n! -----------\n! PSI(XX) IS ASSIGNED THE VALUE 0 WHEN THE DIGAMMA FUNCTION CANNOT\n! BE COMPUTED.\n! THE MAIN COMPUTATION INVOLVES EVALUATION OF RATIONAL CHEBYSHEV\n! APPROXIMATIONS PUBLISHED IN MATH. COMP. 27, 123-127(1973) BY\n! CODY, STRECOK AND THACHER.\n!---------------------------------------------------------------------\n! PSI WAS WRITTEN AT ARGONNE NATIONAL LABORATORY FOR THE FUNPACK\n! PACKAGE OF SPECIAL FUNCTION SUBROUTINES. PSI WAS MODIFIED BY\n! A.H. MORRIS (NSWC).\n!---------------------------------------------------------------------\n!---------------------------------------------------------------------\n! PIOV4 = PI/4\n! DX0 = ZERO OF PSI TO EXTENDED PRECISION\n!---------------------------------------------------------------------\n! COEFFICIENTS FOR RATIONAL APPROXIMATION OF\n! PSI(X) / (X - X0), 0.5 .LE. X .LE. 3.0\n!---------------------------------------------------------------------\n! COEFFICIENTS FOR RATIONAL APPROXIMATION OF\n! PSI(X) - LN(X) + 1 / (2*X), X .GT. 3.0\n!---------------------------------------------------------------------\n! .. Function Return Value ..\n REAL (dpkind) :: psi\n! ..\n! .. Scalar Arguments ..\n REAL (dpkind) :: xx\n! ..\n! .. Local Scalars ..\n REAL (dpkind) :: aug, den, sgn, w, x, xmax1, xmx0, xsmall, z\n INTEGER :: m, n, nq\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC ABS, COS, EPSILON, HUGE, INT, LOG, MIN, REAL, SIN\n! ..\n! .. Parameters ..\n REAL (dpkind), PARAMETER :: dx0 = &\n 1.461632144968362341262659542325721325_dpkind\n REAL (dpkind), PARAMETER :: piov4 = .785398163397448_dpkind\n REAL (dpkind), PARAMETER :: p1(7) = (/ &\n .130560269827897E+04_dpkind, .413810161269013E+04_dpkind, &\n .363351846806499E+04_dpkind, .118645200713425E+04_dpkind, &\n .142441585084029E+03_dpkind, .477762828042627E+01_dpkind, &\n .895385022981970E-02_dpkind/)\n REAL (dpkind), PARAMETER :: p2(5) = (/ zero, &\n -.648157123766197E+00_dpkind, -.448616543918019E+01_dpkind, &\n -.701677227766759E+01_dpkind, -.212940445131011E+01_dpkind/)\n REAL (dpkind), PARAMETER :: q1(7) = (/ &\n .691091682714533E-05_dpkind, .190831076596300E+04_dpkind, &\n .364127349079381E+04_dpkind, .221000799247830E+04_dpkind, &\n .520752771467162E+03_dpkind, .448452573429826E+02_dpkind, one/)\n REAL (dpkind), PARAMETER :: q2(5) = (/ &\n .777788548522962E+01_dpkind, .546117738103215E+02_dpkind, &\n .892920700481861E+02_dpkind, .322703493791143E+02_dpkind, one/)\n! ..\n!---------------------------------------------------------------------\n! MACHINE DEPENDENT CONSTANTS ...\n! XMAX1 = THE SMALLEST POSITIVE FLOATING POINT CONSTANT\n! WITH ENTIRELY INTEGER REPRESENTATION. ALSO USED\n! AS NEGATIVE OF LOWER BOUND ON ACCEPTABLE NEGATIVE\n! ARGUMENTS AND AS THE POSITIVE ARGUMENT BEYOND WHICH\n! PSI MAY BE REPRESENTED AS ALOG(X).\n! XSMALL = ABSOLUTE ARGUMENT BELOW WHICH PI*COTAN(PI*X)\n! MAY BE REPRESENTED BY 1/X.\n!---------------------------------------------------------------------\n xmax1 = HUGE(1)\n xmax1 = MIN(xmax1,one/EPSILON(one))\n xsmall = 1.E-9_dpkind\n!---------------------------------------------------------------------\n x = xx\n aug = zero\n\n IF (x>=half) GO TO 40\n\n!---------------------------------------------------------------------\n! X .LT. 0.5, USE REFLECTION FORMULA\n! PSI(1-X) = PSI(X) + PI * COTAN(PI*X)\n!---------------------------------------------------------------------\n IF (ABS(x)>xsmall) GO TO 10\n IF (x==zero) GO TO 50\n\n!---------------------------------------------------------------------\n! 0 .LT. ABS(X) .LE. XSMALL. USE 1/X AS A SUBSTITUTE\n! FOR PI*COTAN(PI*X)\n!---------------------------------------------------------------------\n aug = -one/x\n GO TO 30\n\n!---------------------------------------------------------------------\n! REDUCTION OF ARGUMENT FOR COTAN\n!---------------------------------------------------------------------\n10 CONTINUE\n w = -x\n sgn = piov4\n IF (w<=zero) THEN\n w = -w\n sgn = -sgn\n!---------------------------------------------------------------------\n! MAKE AN ERROR EXIT IF X .LE. -XMAX1\n!---------------------------------------------------------------------\n END IF\n\n IF (w>=xmax1) GO TO 50\n\n nq = INT(w)\n w = w - REAL(nq,kind=dpkind)\n nq = INT(w*4.0_dpkind)\n w = 4.0_dpkind*(w-REAL(nq,kind=dpkind)*.25_dpkind)\n\n!---------------------------------------------------------------------\n! W IS NOW RELATED TO THE FRACTIONAL PART OF 4.0 * X.\n! ADJUST ARGUMENT TO CORRESPOND TO VALUES IN FIRST\n! QUADRANT AND DETERMINE SIGN\n!---------------------------------------------------------------------\n n = nq/2\n IF (n+n/=nq) w = one - w\n\n z = piov4*w\n m = n/2\n\n IF (m+m/=n) sgn = -sgn\n\n!---------------------------------------------------------------------\n! DETERMINE FINAL VALUE FOR -PI*COTAN(PI*X)\n!---------------------------------------------------------------------\n n = (nq+1)/2\n m = n/2\n m = m + m\n IF (m/=n) GO TO 20\n\n!---------------------------------------------------------------------\n! CHECK FOR SINGULARITY\n!---------------------------------------------------------------------\n IF (z==zero) GO TO 50\n!---------------------------------------------------------------------\n! USE COS/SIN AS A SUBSTITUTE FOR COTAN, AND\n! SIN/COS AS A SUBSTITUTE FOR TAN\n!---------------------------------------------------------------------\n aug = sgn*((COS(z)/SIN(z))*four)\n GO TO 30\n\n20 CONTINUE\n aug = sgn*((SIN(z)/COS(z))*four)\n\n30 CONTINUE\n x = one - x\n\n40 CONTINUE\n IF (x<=three) THEN\n!---------------------------------------------------------------------\n! 0.5 .LE. X .LE. 3.0\n!---------------------------------------------------------------------\n\n den = evaluate_polynomial(p1,x)/evaluate_polynomial(q1,x)\n\n xmx0 = x - dx0\n psi = den*xmx0 + aug\n RETURN\n\n!---------------------------------------------------------------------\n! IF X .GE. XMAX1, PSI = LN(X)\n!---------------------------------------------------------------------\n END IF\n\n IF (x=0.61E0_dpkind .AND. x<=1.57E0_dpkind) THEN\n IF (x<0.82E0_dpkind) GO TO 10\n IF (x>1.18E0_dpkind) GO TO 20\n\n! ARGUMENT REDUCTION\n\n u = (x-half) - half\n w1 = zero\n GO TO 30\n\n10 CONTINUE\n u = x - 0.7E0_dpkind\n u = u/0.7E0_dpkind\n w1 = a - u*0.3E0_dpkind\n GO TO 30\n\n20 CONTINUE\n u = 0.75E0_dpkind*x - one\n w1 = b + u/three\n\n! SERIES EXPANSION\n\n30 CONTINUE\n r = u/(u+two)\n t = r*r\n w = evaluate_polynomial(p,t)/evaluate_polynomial(q,t)\n\n rlog = two*t*(one/(one-r)-r*w) + w1\n\n RETURN\n\n END IF\n\n r = (x-half) - half\n\n rlog = r - LOG(x)\n\n RETURN\n\n END FUNCTION rlog\n\n!*********************************************************************\n\n FUNCTION rlog1(x)\n!-----------------------------------------------------------------------\n! EVALUATION OF THE FUNCTION X - LN(1 + X)\n!-----------------------------------------------------------------------\n!------------------------\n! .. Function Return Value ..\n REAL (dpkind) :: rlog1\n! ..\n! .. Scalar Arguments ..\n REAL (dpkind), INTENT (IN) :: x\n! ..\n! .. Local Scalars ..\n REAL (dpkind) :: h, r, t, w, w1\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC LOG\n! ..\n! .. Parameters ..\n REAL (dpkind), PARAMETER :: a = .566749439387324E-01_dpkind\n REAL (dpkind), PARAMETER :: b = .456512608815524E-01_dpkind\n REAL (dpkind), PARAMETER :: p(3) = (/ .333333333333333E+00_dpkind &\n , -.224696413112536E+00_dpkind, .620886815375787E-02_dpkind/)\n REAL (dpkind), PARAMETER :: q(3) = (/ one, &\n -.127408923933623E+01_dpkind, .354508718369557E+00_dpkind/)\n! ..\n!------------------------\n IF (x<=-one) THEN\n rlog1 = -one\n ELSE IF (x>=(-0.39_dpkind) .AND. x<=0.57_dpkind) THEN\n IF (x<-0.18_dpkind) THEN\n h = x + 0.3_dpkind\n h = h/0.7_dpkind\n w1 = a - h*0.3_dpkind\n ELSE IF (x>0.18_dpkind) THEN\n h = 0.75_dpkind*x - 0.25_dpkind\n w1 = b + h/three\n ELSE\n! ARGUMENT REDUCTION\n\n h = x\n w1 = zero\n END IF\n\n! SERIES EXPANSION\n\n r = h/(h+two)\n t = r*r\n\n w = evaluate_polynomial(p,t)/evaluate_polynomial(q,t)\n\n rlog1 = two*t*(one/(one-r)-r*w) + w1\n\n ELSE\n w = (x+half) + half\n rlog1 = x - LOG(w)\n END IF\n\n END FUNCTION rlog1\n\n!*********************************************************************\n\n END MODULE biomath_mathlib_mod\n", "meta": {"hexsha": "be4c5c1a75dc77bb75c89e2545b0171216ca2d7e", "size": 95805, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mesas/sas/cdflib90/biomath_mathlib_mod.f90", "max_stars_repo_name": "OliverEvans96/mesas", "max_stars_repo_head_hexsha": "eb830074dd3b2977013cda1e2a30b79e10379190", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "mesas/sas/cdflib90/biomath_mathlib_mod.f90", "max_issues_repo_name": "OliverEvans96/mesas", "max_issues_repo_head_hexsha": "eb830074dd3b2977013cda1e2a30b79e10379190", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-12-14T03:16:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-14T16:37:17.000Z", "max_forks_repo_path": "mesas/sas/cdflib90/biomath_mathlib_mod.f90", "max_forks_repo_name": "OliverEvans96/mesas", "max_forks_repo_head_hexsha": "eb830074dd3b2977013cda1e2a30b79e10379190", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-09-09T18:20:55.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-09T18:20:55.000Z", "avg_line_length": 26.7611731844, "max_line_length": 75, "alphanum_fraction": 0.4219090862, "num_tokens": 29272, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380482, "lm_q2_score": 0.7248702880639791, "lm_q1q2_score": 0.6595645535782327}} {"text": "!=======================================================================\n!\n! Calculate the ortho-to-para ratio of H2 at thermal equilibrium\n! for the specified temperature, making use of energy level data\n! if available, or an approximation if not.\n!\n!-----------------------------------------------------------------------\nFUNCTION ORTHO_PARA_RATIO(TEMPERATURE)\n\n USE HEALPIX_TYPES\n USE MAIN_MODULE\n\n IMPLICIT NONE\n\n REAL(KIND=DP) :: ORTHO_PARA_RATIO\n REAL(KIND=DP), INTENT(IN) :: TEMPERATURE\n\n INTEGER(KIND=I4B) :: I,J,N,ORTHO_INDEX,PARA_INDEX\n REAL(KIND=DP) :: I_ORTHO,I_PARA,ORTHO_FRACTION,PARA_FRACTION\n\n! Check if coolant data is available for the ortho and para forms\n ORTHO_INDEX=0; PARA_INDEX=0\n DO N=1,NCOOL\n IF(COOLANT(N)%NAME.EQ.\"o-H2\") ORTHO_INDEX=N\n IF(COOLANT(N)%NAME.EQ.\"p-H2\") PARA_INDEX=N\n END DO\n\n! Calculate the exact ortho/para ratio if molecular data is available\n IF(ORTHO_INDEX.NE.0 .AND. PARA_INDEX.NE.0) THEN\n\n I_ORTHO=1.0D0; I_PARA=0.0D0 ! Total nuclear spins of the two forms\n\n! Calculate the ortho/para ratio of H2 using the expression\n! from Poelman & Spaans (2005, A&A, 440, 559, equation 11)\n ORTHO_FRACTION=0.0D0\n DO I=1,COOLANT(ORTHO_INDEX)%NLEVEL\n ORTHO_FRACTION=ORTHO_FRACTION+COOLANT(ORTHO_INDEX)%WEIGHT(I) &\n & *EXP(-COOLANT(ORTHO_INDEX)%ENERGY(I)/(KB*TEMPERATURE))\n END DO\n\n PARA_FRACTION=0.0D0\n DO I=1,COOLANT(PARA_INDEX)%NLEVEL\n PARA_FRACTION=PARA_FRACTION+COOLANT(PARA_INDEX)%WEIGHT(I) &\n & *EXP(-COOLANT(PARA_INDEX)%ENERGY(I)/(KB*TEMPERATURE))\n END DO\n\n ORTHO_PARA_RATIO=(2*I_ORTHO+1)/(2*I_PARA+1)*(ORTHO_FRACTION/PARA_FRACTION)\n\n ELSE\n\n! Approximate the ortho/para ratio of H2 using the expression\n! given by Flower & Watt (1985, MNRAS, 213, 991, equation 2)\n ORTHO_PARA_RATIO=9.0D0*EXP(-170.5D0/TEMPERATURE)\n\n! Limit the ortho/para ratio to its statistical limit\n IF(ORTHO_PARA_RATIO.GT.3.0D0) ORTHO_PARA_RATIO=3.0D0\n\n END IF\n\nEND FUNCTION ORTHO_PARA_RATIO\n!=======================================================================\n", "meta": {"hexsha": "0e6b33dad35b9c0bee29e4b207cdded829faf697", "size": 2141, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Source/ortho_para_ratio.f90", "max_stars_repo_name": "uclchem/uclpdr", "max_stars_repo_head_hexsha": "a1c5ece6f21852af040ddf0af463cff26757d208", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Source/ortho_para_ratio.f90", "max_issues_repo_name": "uclchem/uclpdr", "max_issues_repo_head_hexsha": "a1c5ece6f21852af040ddf0af463cff26757d208", "max_issues_repo_licenses": ["MIT"], "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/ortho_para_ratio.f90", "max_forks_repo_name": "uclchem/uclpdr", "max_forks_repo_head_hexsha": "a1c5ece6f21852af040ddf0af463cff26757d208", "max_forks_repo_licenses": ["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.5322580645, "max_line_length": 80, "alphanum_fraction": 0.6240074731, "num_tokens": 680, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.909907001151883, "lm_q2_score": 0.724870282120402, "lm_q1q2_score": 0.6595645446282945}} {"text": " subroutine merge_shifts(irr,mitot,mjtot,lwidth,hx,hy,xlow,ylow,\n . lstgrd, numHoods) \n\n! ! INPUTS:\n! ! REQUIRED GRID DATA\n! !\n! ! irr,mitot,mjtot,lwidth,hx,hy,xlow,ylow,lstgrd\n! !\n! ! REQUIRED MERGING DATA\n! ! volMerge, xcmerge, ycmerge, numHoods,\n! ! mi, mj, ncount\n! !\n! ! OUTPUT\n! ! qmshifts\n! !\n! ! NOTE qmshifts(1,k) = shift for xx\n! ! qmshifts(2,k) = shift for xy\n! ! qmshifts(3,k) = shift for yy\n! ! Called dmergeshift in AG code\n\n\n use amr_module\n implicit double precision (a-h, o-z)\n\n dimension irr(mitot,mjtot), numHoods(mitot,mjtot)\n\n\n include \"quadrature.i\"\n\n\n ! recompute the shifts\n do 719 j = 1, mjtot ! iterate over each cell in the grid\n do 719 i = 1, mitot ! iterate over each cell in the grid\n k = irr(i,j)\n\n\n if (k .eq. -1 .or. k .eq. lstgrd) cycle ! skip solid and whole cells\n\n shiftmxx = 0.d0\n shiftmxy = 0.d0\n shiftmyy = 0.d0\n\n x0 = xcentMerge(k)\n y0 = ycentMerge(k)\n arr = volMerge(k)\n\n do 340 ic = 0, ncount(k) ! my count 1 less than AG\n! AG data structure)\n! ioff = mi(k,ic)\n! joff = mj(k,ic)\n\n! my data structure\n if (ic .eq. 0) then\n ioff = i ! first do cell itself\n joff = j\n else ! now pointing to nbor\n ioff = iidx(ic,k)\n joff = jidx(ic,k)\n endif\n\n koff = irr(ioff, joff)\n\n if(koff .eq. lstgrd) then ! full cell\n itri = 2\n call makep(poly(1,1,lstgrd),ioff,joff,xlow,ylow,hx,hy)\n else ! cut cells\n ivert = 1\n do 239 while (poly(ivert+1,1,koff) .ne. -11.)\n ivert = ivert + 1\n 239 continue\n itri = ivert - 3\n endif\n idx1 = 1\n do 219 it = 1, itri ! for each triangle\n idx2 = it + 1\n idx3 = it + 2\n\n x1 = poly(idx1,1,koff)\n y1 = poly(idx1,2,koff)\n\n x2 = poly(idx2,1,koff)\n y2 = poly(idx2,2,koff)\n\n x3 = poly(idx3,1,koff)\n y3 = poly(idx3,2,koff)\n\n ! YOU MUST WEIGHT THE TRIANGLE AREA BY NUMHOODS\n artri = triangle_area(x1, x2, x3, y1, y2, y3) / \n . numHoods(ioff, joff)\n\n do 229 itq = 1,ntriquad\n\n xval = x1 * rtri(itq) + x2 * stri(itq)\n . + x3 * (1.d0-rtri(itq)-stri(itq))\n yval = y1 * rtri(itq) + y2 * stri(itq)\n . + y3 * (1.d0-rtri(itq)-stri(itq))\n\n shiftmxx = shiftmxx + (artri/arr)*wtri(itq)*\n . (xval-x0)**2 /(hx**2)\n shiftmxy = shiftmxy + (artri/arr)*wtri(itq)*\n . (xval-x0)*(yval-y0)/(hx * hy)\n shiftmyy = shiftmyy + (artri/arr)*wtri(itq)*\n . (yval-y0)**2 /(hy**2)\n\n 229 continue ! for each quadrature point on each triangle\n 219 continue ! for each triangle\n\n 340 continue ! iterate over each cell in the neighborhood\n\n ! save for use in merge nhood reconstruction\n qmshifts(1,k) = shiftmxx\n qmshifts(2,k) = shiftmxy\n qmshifts(3,k) = shiftmyy\n\n 719 continue ! iterate over each cell in the grid\n\n return\n end\n", "meta": {"hexsha": "bd01e21b4b087fe65fc9f7538eecb888b684c237", "size": 3425, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/2d/merge_shifts.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/merge_shifts.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/merge_shifts.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": 28.781512605, "max_line_length": 77, "alphanum_fraction": 0.481459854, "num_tokens": 1102, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070084811307, "lm_q2_score": 0.7248702761768248, "lm_q1q2_score": 0.6595645445329457}} {"text": " subroutine ire_eqipsi(n_a1,n_alpha,n_beta,n_iPHI,n_iPI,nm1_ipsi,np\n &1_ipsi,Nx,ht,res)\n implicit none\n integer i\n integer Nx\n real*8 ht\n real*8 n_a1(Nx)\n real*8 n_alpha(Nx)\n real*8 n_beta(Nx)\n real*8 n_iPHI(Nx)\n real*8 n_iPI(Nx)\n real*8 nm1_ipsi(Nx)\n real*8 np1_ipsi(Nx)\n real*8 res\n real*8 qb\n res = 0.0D0\n do i=1, Nx, 1\n qb = 0.5000000000000000D0 * (-0.1D1 * nm1_ipsi(i) + np1_ipsi(i)) /\n # ht - 0.1D1 * n_alpha(i) / n_a1(i) * n_iPI(i) - 0.1D1 * n_beta(i) \n #* n_iPHI(i)\n res = res + qb**2\n end do\n res = sqrt(res/(1*Nx))\n END\n", "meta": {"hexsha": "7af779bf7cff65544fa6583df02b42d65b6c12d0", "size": 647, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/FD/ire_eqipsi.f", "max_stars_repo_name": "rmanak/bssn_spher", "max_stars_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/FD/ire_eqipsi.f", "max_issues_repo_name": "rmanak/bssn_spher", "max_issues_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/FD/ire_eqipsi.f", "max_forks_repo_name": "rmanak/bssn_spher", "max_forks_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.88, "max_line_length": 72, "alphanum_fraction": 0.5332302937, "num_tokens": 271, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380482, "lm_q2_score": 0.7248702761768248, "lm_q1q2_score": 0.6595645427620277}} {"text": "*DECK HSTSSP\n SUBROUTINE HSTSSP (A, B, M, MBDCND, BDA, BDB, C, D, N, NBDCND,\n + BDC, BDD, ELMBDA, F, IDIMF, PERTRB, IERROR, W)\nC***BEGIN PROLOGUE HSTSSP\nC***PURPOSE Solve the standard five-point finite difference\nC approximation on a staggered grid to the Helmholtz\nC equation in spherical coordinates and on the surface of\nC the unit sphere (radius of 1).\nC***LIBRARY SLATEC (FISHPACK)\nC***CATEGORY I2B1A1A\nC***TYPE SINGLE PRECISION (HSTSSP-S)\nC***KEYWORDS ELLIPTIC, FISHPACK, HELMHOLTZ, PDE, SPHERICAL\nC***AUTHOR Adams, J., (NCAR)\nC Swarztrauber, P. N., (NCAR)\nC Sweet, R., (NCAR)\nC***DESCRIPTION\nC\nC HSTSSP solves the standard five-point finite difference\nC approximation on a staggered grid to the Helmholtz equation in\nC spherical coordinates and on the surface of the unit sphere\nC (radius of 1)\nC\nC (1/SIN(THETA))(d/dTHETA)(SIN(THETA)(dU/dTHETA)) +\nC\nC (1/SIN(THETA)**2)(d/dPHI)(dU/dPHI) + LAMBDA*U = F(THETA,PHI)\nC\nC where THETA is colatitude and PHI is longitude.\nC\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC\nC * * * * * * * * Parameter Description * * * * * * * * * *\nC\nC * * * * * * On Input * * * * * *\nC\nC A,B\nC The range of THETA (colatitude), i.e. A .LE. THETA .LE. B. A\nC must be less than B and A must be non-negative. A and B are in\nC radians. A = 0 corresponds to the north pole and B = PI\nC corresponds to the south pole.\nC\nC\nC * * * IMPORTANT * * *\nC\nC If B is equal to PI, then B must be computed using the statement\nC\nC B = PIMACH(DUM)\nC\nC This insures that B in the user's program is equal to PI in this\nC program which permits several tests of the input parameters that\nC otherwise would not be possible.\nC\nC * * * * * * * * * * * *\nC\nC\nC\nC M\nC The number of grid points in the interval (A,B). The grid points\nC in the THETA-direction are given by THETA(I) = A + (I-0.5)DTHETA\nC for I=1,2,...,M where DTHETA =(B-A)/M. M must be greater than 2.\nC\nC MBDCND\nC Indicates the type of boundary conditions at THETA = A and\nC THETA = B.\nC\nC = 1 If the solution is specified at THETA = A and THETA = B.\nC (see note 3 below)\nC\nC = 2 If the solution is specified at THETA = A and the derivative\nC of the solution with respect to THETA is specified at\nC THETA = B (see notes 2 and 3 below).\nC\nC = 3 If the derivative of the solution with respect to THETA is\nC specified at THETA = A (see notes 1, 2 below) and THETA = B.\nC\nC = 4 If the derivative of the solution with respect to THETA is\nC specified at THETA = A (see notes 1 and 2 below) and the\nC solution is specified at THETA = B.\nC\nC = 5 If the solution is unspecified at THETA = A = 0 and the\nC solution is specified at THETA = B. (see note 3 below)\nC\nC = 6 If the solution is unspecified at THETA = A = 0 and the\nC derivative of the solution with respect to THETA is\nC specified at THETA = B (see note 2 below).\nC\nC = 7 If the solution is specified at THETA = A and the\nC solution is unspecified at THETA = B = PI. (see note 3 below)\nC\nC = 8 If the derivative of the solution with respect to\nC THETA is specified at THETA = A (see note 1 below)\nC and the solution is unspecified at THETA = B = PI.\nC\nC = 9 If the solution is unspecified at THETA = A = 0 and\nC THETA = B = PI.\nC\nC NOTES: 1. If A = 0, do not use MBDCND = 3, 4, or 8,\nC but instead use MBDCND = 5, 6, or 9.\nC\nC 2. If B = PI, do not use MBDCND = 2, 3, or 6,\nC but instead use MBDCND = 7, 8, or 9.\nC\nC 3. When the solution is specified at THETA = 0 and/or\nC THETA = PI and the other boundary conditions are\nC combinations of unspecified, normal derivative, or\nC periodicity a singular system results. The unique\nC solution is determined by extrapolation to the\nC specification of the solution at either THETA = 0 or\nC THETA = PI. But in these cases the right side of the\nC system will be perturbed by the constant PERTRB.\nC\nC BDA\nC A one-dimensional array of length N that specifies the boundary\nC values (if any) of the solution at THETA = A. When\nC MBDCND = 1, 2, or 7,\nC\nC BDA(J) = U(A,PHI(J)) , J=1,2,...,N.\nC\nC When MBDCND = 3, 4, or 8,\nC\nC BDA(J) = (d/dTHETA)U(A,PHI(J)) , J=1,2,...,N.\nC\nC When MBDCND has any other value, BDA is a dummy variable.\nC\nC BDB\nC A one-dimensional array of length N that specifies the boundary\nC values of the solution at THETA = B. When MBDCND = 1,4, or 5,\nC\nC BDB(J) = U(B,PHI(J)) , J=1,2,...,N.\nC\nC When MBDCND = 2,3, or 6,\nC\nC BDB(J) = (d/dTHETA)U(B,PHI(J)) , J=1,2,...,N.\nC\nC When MBDCND has any other value, BDB is a dummy variable.\nC\nC C,D\nC The range of PHI (longitude), i.e. C .LE. PHI .LE. D.\nC C must be less than D. If D-C = 2*PI, periodic boundary\nC conditions are usually prescribed.\nC\nC N\nC The number of unknowns in the interval (C,D). The unknowns in\nC the PHI-direction are given by PHI(J) = C + (J-0.5)DPHI,\nC J=1,2,...,N, where DPHI = (D-C)/N. N must be greater than 2.\nC\nC NBDCND\nC Indicates the type of boundary conditions at PHI = C\nC and PHI = D.\nC\nC = 0 If the solution is periodic in PHI, i.e.\nC U(I,J) = U(I,N+J).\nC\nC = 1 If the solution is specified at PHI = C and PHI = D\nC (see note below).\nC\nC = 2 If the solution is specified at PHI = C and the derivative\nC of the solution with respect to PHI is specified at\nC PHI = D (see note below).\nC\nC = 3 If the derivative of the solution with respect to PHI is\nC specified at PHI = C and PHI = D.\nC\nC = 4 If the derivative of the solution with respect to PHI is\nC specified at PHI = C and the solution is specified at\nC PHI = D (see note below).\nC\nC NOTE: When NBDCND = 1, 2, or 4, do not use MBDCND = 5, 6, 7, 8,\nC or 9 (the former indicates that the solution is specified at\nC a pole; the latter indicates the solution is unspecified). Use\nC instead MBDCND = 1 or 2.\nC\nC BDC\nC A one dimensional array of length M that specifies the boundary\nC values of the solution at PHI = C. When NBDCND = 1 or 2,\nC\nC BDC(I) = U(THETA(I),C) , I=1,2,...,M.\nC\nC When NBDCND = 3 or 4,\nC\nC BDC(I) = (d/dPHI)U(THETA(I),C), I=1,2,...,M.\nC\nC When NBDCND = 0, BDC is a dummy variable.\nC\nC BDD\nC A one-dimensional array of length M that specifies the boundary\nC values of the solution at PHI = D. When NBDCND = 1 or 4,\nC\nC BDD(I) = U(THETA(I),D) , I=1,2,...,M.\nC\nC When NBDCND = 2 or 3,\nC\nC BDD(I) = (d/dPHI)U(THETA(I),D) , I=1,2,...,M.\nC\nC When NBDCND = 0, BDD is a dummy variable.\nC\nC ELMBDA\nC The constant LAMBDA in the Helmholtz equation. If LAMBDA is\nC greater than 0, a solution may not exist. However, HSTSSP will\nC attempt to find a solution.\nC\nC F\nC A two-dimensional array that specifies the values of the right\nC side of the Helmholtz equation. For I=1,2,...,M and J=1,2,...,N\nC\nC F(I,J) = F(THETA(I),PHI(J)) .\nC\nC F must be dimensioned at least M X N.\nC\nC IDIMF\nC The row (or first) dimension of the array F as it appears in the\nC program calling HSTSSP. This parameter is used to specify the\nC variable dimension of F. IDIMF must be at least M.\nC\nC W\nC A one-dimensional array that must be provided by the user for\nC work space. W may require up to 13M + 4N + M*INT(log2(N))\nC locations. The actual number of locations used is computed by\nC HSTSSP and is returned in the location W(1).\nC\nC\nC * * * * * * On Output * * * * * *\nC\nC F\nC Contains the solution U(I,J) of the finite difference\nC approximation for the grid point (THETA(I),PHI(J)) for\nC I=1,2,...,M, J=1,2,...,N.\nC\nC PERTRB\nC If a combination of periodic, derivative, or unspecified\nC boundary conditions is specified for a Poisson equation\nC (LAMBDA = 0), a solution may not exist. PERTRB is a con-\nC stant, calculated and subtracted from F, which ensures\nC that a solution exists. HSTSSP then computes this\nC solution, which is a least squares solution to the\nC original approximation. This solution plus any constant is also\nC a solution; hence, the solution is not unique. The value of\nC PERTRB should be small compared to the right side F.\nC Otherwise, a solution is obtained to an essentially different\nC problem. This comparison should always be made to insure that\nC a meaningful solution has been obtained.\nC\nC IERROR\nC An error flag that indicates invalid input parameters.\nC Except for numbers 0 and 14, a solution is not attempted.\nC\nC = 0 No error\nC\nC = 1 A .LT. 0 or B .GT. PI\nC\nC = 2 A .GE. B\nC\nC = 3 MBDCND .LT. 1 or MBDCND .GT. 9\nC\nC = 4 C .GE. D\nC\nC = 5 N .LE. 2\nC\nC = 6 NBDCND .LT. 0 or NBDCND .GT. 4\nC\nC = 7 A .GT. 0 and MBDCND = 5, 6, or 9\nC\nC = 8 A = 0 and MBDCND = 3, 4, or 8\nC\nC = 9 B .LT. PI and MBDCND .GE. 7\nC\nC = 10 B = PI and MBDCND = 2,3, or 6\nC\nC = 11 MBDCND .GE. 5 and NDBCND = 1, 2, or 4\nC\nC = 12 IDIMF .LT. M\nC\nC = 13 M .LE. 2\nC\nC = 14 LAMBDA .GT. 0\nC\nC Since this is the only means of indicating a possibly\nC incorrect call to HSTSSP, the user should test IERROR after\nC the call.\nC\nC W\nC W(1) contains the required length of W.\nC\nC *Long Description:\nC\nC * * * * * * * Program Specifications * * * * * * * * * * * *\nC\nC Dimension of BDA(N),BDB(N),BDC(M),BDD(M),F(IDIMF,N),\nC Arguments W(see argument list)\nC\nC Latest June 1, 1977\nC Revision\nC\nC Subprograms HSTSSP,POISTG,POSTG2,GENBUN,POISD2,POISN2,POISP2,\nC Required COSGEN,MERGE,TRIX,TRI3,PIMACH\nC\nC Special NONE\nC Conditions\nC\nC Common NONE\nC Blocks\nC\nC I/O NONE\nC\nC Precision Single\nC\nC Specialist Roland Sweet\nC\nC Language FORTRAN\nC\nC History Written by Roland Sweet at NCAR in April, 1977\nC\nC Algorithm This subroutine defines the finite-difference\nC equations, incorporates boundary data, adjusts the\nC right side when the system is singular and calls\nC either POISTG or GENBUN which solves the linear\nC system of equations.\nC\nC Space 8427(decimal) = 20353(octal) locations on the\nC Required NCAR Control Data 7600\nC\nC Timing and The execution time T on the NCAR Control Data\nC Accuracy 7600 for subroutine HSTSSP is roughly proportional\nC to M*N*log2(N). Some typical values are listed in\nC the table below.\nC The solution process employed results in a loss\nC of no more than four significant digits for N and M\nC as large as 64. More detailed information about\nC accuracy can be found in the documentation for\nC subroutine POISTG which is the routine that\nC actually solves the finite difference equations.\nC\nC\nC M(=N) MBDCND NBDCND T(MSECS)\nC ----- ------ ------ --------\nC\nC 32 1-9 1-4 56\nC 64 1-9 1-4 230\nC\nC Portability American National Standards Institute FORTRAN.\nC The machine dependent constant PI is defined in\nC function PIMACH.\nC\nC Required COS\nC Resident\nC Routines\nC\nC Reference Schumann, U. and R. Sweet,'A Direct Method For\nC The Solution Of Poisson's Equation With Neumann\nC Boundary Conditions On A Staggered Grid Of\nC Arbitrary Size,' J. Comp. Phys. 20(1976),\nC pp. 171-182.\nC\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC\nC***REFERENCES U. Schumann and R. Sweet, A direct method for the\nC solution of Poisson's equation with Neumann boundary\nC conditions on a staggered grid of arbitrary size,\nC Journal of Computational Physics 20, (1976),\nC pp. 171-182.\nC***ROUTINES CALLED GENBUN, PIMACH, POISTG\nC***REVISION HISTORY (YYMMDD)\nC 801001 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890531 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE HSTSSP\nC\nC\n DIMENSION F(IDIMF,*) ,BDA(*) ,BDB(*) ,BDC(*) ,\n 1 BDD(*) ,W(*)\nC***FIRST EXECUTABLE STATEMENT HSTSSP\n IERROR = 0\n PI = PIMACH(DUM)\n IF (A.LT.0. .OR. B.GT.PI) IERROR = 1\n IF (A .GE. B) IERROR = 2\n IF (MBDCND.LE.0 .OR. MBDCND.GT.9) IERROR = 3\n IF (C .GE. D) IERROR = 4\n IF (N .LE. 2) IERROR = 5\n IF (NBDCND.LT.0 .OR. NBDCND.GE.5) IERROR = 6\n IF (A.GT.0. .AND. (MBDCND.EQ.5 .OR. MBDCND.EQ.6 .OR. MBDCND.EQ.9))\n 1 IERROR = 7\n IF (A.EQ.0. .AND. (MBDCND.EQ.3 .OR. MBDCND.EQ.4 .OR. MBDCND.EQ.8))\n 1 IERROR = 8\n IF (B.LT.PI .AND. MBDCND.GE.7) IERROR = 9\n IF (B.EQ.PI .AND. (MBDCND.EQ.2 .OR. MBDCND.EQ.3 .OR. MBDCND.EQ.6))\n 1 IERROR = 10\n IF (MBDCND.GE.5 .AND.\n 1 (NBDCND.EQ.1 .OR. NBDCND.EQ.2 .OR. NBDCND.EQ.4)) IERROR = 11\n IF (IDIMF .LT. M) IERROR = 12\n IF (M .LE. 2) IERROR = 13\n IF (IERROR .NE. 0) RETURN\n DELTAR = (B-A)/M\n DLRSQ = DELTAR**2\n DELTHT = (D-C)/N\n DLTHSQ = DELTHT**2\n NP = NBDCND+1\n ISW = 1\n JSW = 1\n MB = MBDCND\n IF (ELMBDA .NE. 0.) GO TO 105\n GO TO (101,102,105,103,101,105,101,105,105),MBDCND\n 101 IF (A.NE.0. .OR. B.NE.PI) GO TO 105\n MB = 9\n GO TO 104\n 102 IF (A .NE. 0.) GO TO 105\n MB = 6\n GO TO 104\n 103 IF (B .NE. PI) GO TO 105\n MB = 8\n 104 JSW = 2\n 105 CONTINUE\nC\nC DEFINE A,B,C COEFFICIENTS IN W-ARRAY.\nC\n IWB = M\n IWC = IWB+M\n IWR = IWC+M\n IWS = IWR+M\n DO 106 I=1,M\n J = IWR+I\n W(J) = SIN(A+(I-0.5)*DELTAR)\n W(I) = SIN((A+(I-1)*DELTAR))/DLRSQ\n 106 CONTINUE\n MM1 = M-1\n DO 107 I=1,MM1\n K = IWC+I\n W(K) = W(I+1)\n J = IWR+I\n K = IWB+I\n W(K) = ELMBDA*W(J)-(W(I)+W(I+1))\n 107 CONTINUE\n W(IWR) = SIN(B)/DLRSQ\n W(IWC) = ELMBDA*W(IWS)-(W(M)+W(IWR))\n DO 109 I=1,M\n J = IWR+I\n A1 = W(J)\n DO 108 J=1,N\n F(I,J) = A1*F(I,J)\n 108 CONTINUE\n 109 CONTINUE\nC\nC ENTER BOUNDARY DATA FOR THETA-BOUNDARIES.\nC\n GO TO (110,110,112,112,114,114,110,112,114),MB\n 110 A1 = 2.*W(1)\n W(IWB+1) = W(IWB+1)-W(1)\n DO 111 J=1,N\n F(1,J) = F(1,J)-A1*BDA(J)\n 111 CONTINUE\n GO TO 114\n 112 A1 = DELTAR*W(1)\n W(IWB+1) = W(IWB+1)+W(1)\n DO 113 J=1,N\n F(1,J) = F(1,J)+A1*BDA(J)\n 113 CONTINUE\n 114 GO TO (115,117,117,115,115,117,119,119,119),MB\n 115 A1 = 2.*W(IWR)\n W(IWC) = W(IWC)-W(IWR)\n DO 116 J=1,N\n F(M,J) = F(M,J)-A1*BDB(J)\n 116 CONTINUE\n GO TO 119\n 117 A1 = DELTAR*W(IWR)\n W(IWC) = W(IWC)+W(IWR)\n DO 118 J=1,N\n F(M,J) = F(M,J)-A1*BDB(J)\n 118 CONTINUE\nC\nC ENTER BOUNDARY DATA FOR PHI-BOUNDARIES.\nC\n 119 A1 = 2./DLTHSQ\n GO TO (129,120,120,122,122),NP\n 120 DO 121 I=1,M\n J = IWR+I\n F(I,1) = F(I,1)-A1*BDC(I)/W(J)\n 121 CONTINUE\n GO TO 124\n 122 A1 = 1./DELTHT\n DO 123 I=1,M\n J = IWR+I\n F(I,1) = F(I,1)+A1*BDC(I)/W(J)\n 123 CONTINUE\n 124 A1 = 2./DLTHSQ\n GO TO (129,125,127,127,125),NP\n 125 DO 126 I=1,M\n J = IWR+I\n F(I,N) = F(I,N)-A1*BDD(I)/W(J)\n 126 CONTINUE\n GO TO 129\n 127 A1 = 1./DELTHT\n DO 128 I=1,M\n J = IWR+I\n F(I,N) = F(I,N)-A1*BDD(I)/W(J)\n 128 CONTINUE\n 129 CONTINUE\nC\nC ADJUST RIGHT SIDE OF SINGULAR PROBLEMS TO INSURE EXISTENCE OF A\nC SOLUTION.\nC\n PERTRB = 0.\n IF (ELMBDA) 139,131,130\n 130 IERROR = 14\n GO TO 139\n 131 GO TO (139,139,132,139,139,132,139,132,132),MB\n 132 GO TO (133,139,139,133,139),NP\n 133 CONTINUE\n ISW = 2\n DO 135 J=1,N\n DO 134 I=1,M\n PERTRB = PERTRB+F(I,J)\n 134 CONTINUE\n 135 CONTINUE\n A1 = N*(COS(A)-COS(B))/(2.*SIN(0.5*DELTAR))\n PERTRB = PERTRB/A1\n DO 137 I=1,M\n J = IWR+I\n A1 = PERTRB*W(J)\n DO 136 J=1,N\n F(I,J) = F(I,J)-A1\n 136 CONTINUE\n 137 CONTINUE\n A2 = 0.\n A3 = 0.\n DO 138 J=1,N\n A2 = A2+F(1,J)\n A3 = A3+F(M,J)\n 138 CONTINUE\n A2 = A2/W(IWR+1)\n A3 = A3/W(IWS)\n 139 CONTINUE\nC\nC MULTIPLY I-TH EQUATION THROUGH BY R(I)*DELTHT**2\nC\n DO 141 I=1,M\n J = IWR+I\n A1 = DLTHSQ*W(J)\n W(I) = A1*W(I)\n J = IWC+I\n W(J) = A1*W(J)\n J = IWB+I\n W(J) = A1*W(J)\n DO 140 J=1,N\n F(I,J) = A1*F(I,J)\n 140 CONTINUE\n 141 CONTINUE\n LP = NBDCND\n W(1) = 0.\n W(IWR) = 0.\nC\nC CALL POISTG OR GENBUN TO SOLVE THE SYSTEM OF EQUATIONS.\nC\n IF (NBDCND .EQ. 0) GO TO 142\n CALL POISTG (LP,N,1,M,W,W(IWB+1),W(IWC+1),IDIMF,F,IERR1,W(IWR+1))\n GO TO 143\n 142 CALL GENBUN (LP,N,1,M,W,W(IWB+1),W(IWC+1),IDIMF,F,IERR1,W(IWR+1))\n 143 CONTINUE\n W(1) = W(IWR+1)+3*M\n IF (ISW.NE.2 .OR. JSW.NE.2) GO TO 150\n IF (MB .NE. 8) GO TO 145\n A1 = 0.\n DO 144 J=1,N\n A1 = A1+F(M,J)\n 144 CONTINUE\n A1 = (A1-DLRSQ*A3/16.)/N\n IF (NBDCND .EQ. 3) A1 = A1+(BDD(M)-BDC(M))/(D-C)\n A1 = BDB(1)-A1\n GO TO 147\n 145 A1 = 0.\n DO 146 J=1,N\n A1 = A1+F(1,J)\n 146 CONTINUE\n A1 = (A1-DLRSQ*A2/16.)/N\n IF (NBDCND .EQ. 3) A1 = A1+(BDD(1)-BDC(1))/(D-C)\n A1 = BDA(1)-A1\n 147 DO 149 I=1,M\n DO 148 J=1,N\n F(I,J) = F(I,J)+A1\n 148 CONTINUE\n 149 CONTINUE\n 150 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "1f9d6eff58c0e8db04957f74760b5bf55bc12177", "size": 18605, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/hstssp.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/hstssp.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/hstssp.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.8578767123, "max_line_length": 72, "alphanum_fraction": 0.5592045149, "num_tokens": 6782, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070035949657, "lm_q2_score": 0.7248702702332476, "lm_q1q2_score": 0.6595645355830073}} {"text": "!\n!.... Driver routines that mimic the IMSL Bspline routine\n!\n!.... Author: S. Scott Collis\n!\n!.... Copyright: (c)2020 S. Scott Collis\n!\n!.... Be sure to compile with -r8 otherwise you'll get roundoff errors for\n!.... large nx\n!\n subroutine BSNAK( nx, x, korder, knot )\n!\n!.... Make a Not-a-Knot sequence. Modeled on IMSL routine BSNAK\n!\n!.... S. Collis\n!\n integer nx, korder\n real x(nx), knot(nx+korder)\n\n do i = 1, korder\n knot(i) = x(1)\n knot(nx+i) = x(nx)\n end do\n\n if (mod(korder,2).eq.0) then\n do i = korder+1, nx\n knot(i) = x(i-korder/2)\n end do\n else\n do i = korder+1, nx\n knot(i) = 0.5 * ( x(i-(korder+1)+korder/2 + 1) + &\n x(i-(korder+1)+korder/2 + 2) )\n end do\n end if\n\n return\n end\n\n subroutine BSINT( nx, x, u, korder, knot, bs )\n\n implicit none\n\n integer :: nx, korder\n real :: x(nx), u(nx), knot(nx+korder), bs(nx) \n\n real :: work(nx*(2*korder-1)), work2(2*korder)\n integer :: iflag\n \n call BINTK( x, u, knot, nx, korder, bs, work, work2 )\n\n! call splint( x, u, knot, nx, korder, work, bs, iflag )\n! if (iflag.ne.1) then\n!\t write(*,*) 'Error in BSINT'\n!\t stop\n! end if\n\n return\n end\n\n real function BSDER( ider, x, korder, knot, nx, bs )\n\n implicit none\n\n integer :: ider, korder, nx\n real :: x, knot(nx+korder), bs(nx)\n real, external :: bvalue, BVALU\n real :: work(3*korder)\n integer :: inbv=1\n\n BSDER = BVALU( knot, bs, nx, korder, ider, x, inbv, work)\n\n! BSDER = bvalue( knot, bs, nx, korder, x, ider )\n\n return\n end\n\n real function BSVAL( x, korder, knot, nx, bs )\n\n implicit none\n\n integer :: ider=1, korder, nx\n real :: x, knot(nx+korder), bs(nx)\n real, external :: bvalue, BVALU\n real :: work(3*korder)\n integer :: inbv=1\n\n BSVAL = BVALU( knot, bs, nx, korder, ider, x, inbv, work)\n\n! BSVAL = bvalue( knot, bs, nx, korder, x, ider )\n\n return\n end\n\n real function BSITG( x1, x2, korder, knot, nx, bs )\n\n implicit none\n\n integer :: korder, nx\n real :: x1, x2, knot(nx+korder), bs(nx)\n real :: work(3*korder)\n integer :: inbv=1\n\n call BSQAD( knot, bs, nx, korder, x1, x2, BSITG, work)\n\n return\n end\n\n subroutine QDAG( fun, x1, x2, err1, err2, idum, val, errest)\n\n implicit none\n\n external fun\n real :: x1, x2, err1, err2, errest, val\n integer :: idum, ierr\n\n errest = min(err1,err2)\n call GAUS8( fun, x1, x2, errest, val, ierr)\n\n return\n end\n", "meta": {"hexsha": "9301a94268abbf868a6b29422c6593f74d38531b", "size": 2690, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "bslib2.f90", "max_stars_repo_name": "sscollis/fsc", "max_stars_repo_head_hexsha": "84560a0916ae7cf4fee42428509bf06e26bb640c", "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": "bslib2.f90", "max_issues_repo_name": "sscollis/fsc", "max_issues_repo_head_hexsha": "84560a0916ae7cf4fee42428509bf06e26bb640c", "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": "bslib2.f90", "max_forks_repo_name": "sscollis/fsc", "max_forks_repo_head_hexsha": "84560a0916ae7cf4fee42428509bf06e26bb640c", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.2314049587, "max_line_length": 74, "alphanum_fraction": 0.5241635688, "num_tokens": 907, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289387998695209, "lm_q2_score": 0.7956581049086031, "lm_q1q2_score": 0.6595518745893948}} {"text": " function ran2(idum)\n!---------------------------------------------------------------------\n! See NUMERICAL RECIPES for detail of the function under the same\n! name\n! PARAMETERS:\n! idum : random seed\n!---------------------------------------------------------------------\n implicit none\n\n real :: ran2\n integer, intent(inout) :: idum\n integer, parameter :: im1=2147483563, im2=2147483399, imm1=im1-1\n integer, parameter :: ia1=40014, ia2=40692, iq1=53668, iq2=52774\n integer, parameter :: ir1=12211, ir2=3791, ntab=32, ndiv=1+imm1/ntab\n real, parameter :: am=1./im1, eps=1.2e-7, rnmx=1.-eps\n integer :: idum2=123456789, iy=0, j, k\n integer, dimension(ntab) :: iv\n \n save iv,iy,idum2\n \n do j=1,ntab\n iv(j)=0\n enddo\n\n if(idum.le.0) then\n idum=max(-idum,1)\n idum2=idum\n do j=ntab+8,1,-1\n k=idum/iq1\n idum=ia1*(idum-k*iq1)-k*ir1\n if(idum.lt.0) idum=idum+im1\n if(j.le.ntab) iv(j)=idum\n enddo\n iy=iv(1)\n endif\n k=idum/iq1\n idum=ia1*(idum-k*iq1)-k*ir1\n if(idum.lt.0) idum=idum+im1\n k=idum2/iq2\n idum2=ia2*(idum2-k*iq2)-k*ir2\n if(idum2.lt.0) idum2=idum2+im2\n j=1+iy/ndiv\n iy=iv(j)-idum2\n iv(j)=idum\n if(iy.lt.1) iy=iy+imm1\n ran2=min(am*iy,rnmx)\n \n end function ran2\n\n!**********************************************************************\n\n\n FUNCTION GASDEV(IDUM)\n!----------------------------------------------------------------------\n! Gaussian white noise generator using uniformly distributed white\n! noise generator\n!---------------------------------------------------------------------- \n\n implicit none\n real:: gasdev, ran2\n integer, intent(inout):: idum\n real :: v1, v2, gv1, gv2\n real, parameter :: pi=3.1415927\n\n V1=RAN2(IDUM)\n V2=RAN2(IDUM)\n\n gv1=sqrt(-2.0*log(v1))*cos(2.0*pi*v2)\n gv2=sqrt(-2.0*log(v2))*cos(2.0*pi*v1)\n\n gasdev=gv1\n\n END FUNCTION GASDEV\n\n\n\n", "meta": {"hexsha": "e1713917a81c0e4c8f1f46c0845f8611f7d61aa6", "size": 2065, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "eemdf90/gasdev.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/gasdev.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/gasdev.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": 26.8181818182, "max_line_length": 74, "alphanum_fraction": 0.4634382567, "num_tokens": 665, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289387914176258, "lm_q2_score": 0.795658104908603, "lm_q1q2_score": 0.6595518678645759}} {"text": "c subroutine lfpt (n,m,theta,cp,pb)\nc\nc dimension of\nc arguments\nc cp((n/2)+1)\nc\nc purpose routine lfpt uses coefficients computed by\nc routine alfk to compute the single precision\nc normalized associated legendre function pbar(n,\nc m,theta) at colatitude theta.\nc\nc usage call lfpt(n,m,theta,cp,pb)\nc\nc arguments\nc\nc on input n\nc nonnegative integer specifying the degree of\nc pbar(n,m,theta)\nc m\nc is the order of pbar(n,m,theta). m can be\nc any integer however pbar(n,m,theta) = 0\nc if abs(m) is greater than n and\nc pbar(n,m,theta) = (-1)**m*pbar(n,-m,theta)\nc for negative m.\nc\nc theta\nc single precision colatitude in radians\nc\nc cp\nc single precision array of length (n/2)+1\nc containing coefficients computed by routine\nc alfk\nc\nc on output pb\nc single precision variable containing\nc pbar(n,m,theta)\nc\nc special conditions calls to routine lfpt must be preceded by an\nc appropriate call to routine alfk.\nc\nc precision single\nc\nc algorithm the trigonometric series formula used by\nc routine lfpt to calculate pbar(n,m,th) at\nc colatitude th depends on m and n as follows:\nc\nc 1) for n even and m even, the formula is\nc .5*cp(1) plus the sum from k=1 to k=n/2\nc of cp(k)*cos(2*k*th)\nc 2) for n even and m odd. the formula is\nc the sum from k=1 to k=n/2 of\nc cp(k)*sin(2*k*th)\nc 3) for n odd and m even, the formula is\nc the sum from k=1 to k=(n+1)/2 of\nc cp(k)*cos((2*k-1)*th)\nc 4) for n odd and m odd, the formula is\nc the sum from k=1 to k=(n+1)/2 of\nc cp(k)*sin((2*k-1)*th)\nc\nc accuracy comparison between routines lfpt and double\nc precision dlfpt on the cray1 indicates greater\nc accuracy for greater values on input parameter\nc n. agreement to 13 places was obtained for\nc n=10 and to 12 places for n=100.\nc\nc timing time per call to routine lfpt is dependent on\nc the input parameter n.\nc\n SUBROUTINE DLFPT(N,M,THETA,CP,PB)\n DOUBLE PRECISION THETA\n DOUBLE PRECISION CP\n DOUBLE PRECISION PB\n DOUBLE PRECISION CDT\n DOUBLE PRECISION SDT\n DOUBLE PRECISION CT\n DOUBLE PRECISION ST\n DOUBLE PRECISION SUM\n DOUBLE PRECISION CTH\n DIMENSION CP(1)\nc\n PB = 0.D0\n MA = IABS(M)\n IF (MA.GT.N) RETURN\n IF (N) 10,10,30\n 10 IF (MA) 20,20,30\n 20 PB = SQRT(.5D0)\n GO TO 140\n 30 NP1 = N + 1\n NMOD = MOD(N,2)\n MMOD = MOD(MA,2)\n IF (NMOD) 40,40,90\n 40 IF (MMOD) 50,50,70\n 50 KDO = N/2 + 1\n CDT = COS(THETA+THETA)\n SDT = SIN(THETA+THETA)\n CT = 1.D0\n ST = 0.D0\n SUM = .5D0*CP(1)\n DO 60 KP1 = 2,KDO\n CTH = CDT*CT - SDT*ST\n ST = SDT*CT + CDT*ST\n CT = CTH\n SUM = SUM + CP(KP1)*CT\n 60 CONTINUE\n PB = SUM\n GO TO 140\n 70 KDO = N/2\n CDT = COS(THETA+THETA)\n SDT = SIN(THETA+THETA)\n CT = 1.D0\n ST = 0.D0\n SUM = 0.D0\n DO 80 K = 1,KDO\n CTH = CDT*CT - SDT*ST\n ST = SDT*CT + CDT*ST\n CT = CTH\n SUM = SUM + CP(K)*ST\n 80 CONTINUE\n PB = SUM\n GO TO 140\n 90 KDO = (N+1)/2\n IF (MMOD) 100,100,120\n 100 CDT = COS(THETA+THETA)\n SDT = SIN(THETA+THETA)\n CT = COS(THETA)\n ST = -SIN(THETA)\n SUM = 0.D0\n DO 110 K = 1,KDO\n CTH = CDT*CT - SDT*ST\n ST = SDT*CT + CDT*ST\n CT = CTH\n SUM = SUM + CP(K)*CT\n 110 CONTINUE\n PB = SUM\n GO TO 140\n 120 CDT = COS(THETA+THETA)\n SDT = SIN(THETA+THETA)\n CT = COS(THETA)\n ST = -SIN(THETA)\n SUM = 0.D0\n DO 130 K = 1,KDO\n CTH = CDT*CT - SDT*ST\n ST = SDT*CT + CDT*ST\n CT = CTH\n SUM = SUM + CP(K)*ST\n 130 CONTINUE\n PB = SUM\n 140 RETURN\n END\n", "meta": {"hexsha": "6d455a5079a43d5269bd13b689a7f712632243e9", "size": 4772, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "external/sphere3.1_dp/lfpt.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "external/sphere3.1_dp/lfpt.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "external/sphere3.1_dp/lfpt.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 31.8133333333, "max_line_length": 72, "alphanum_fraction": 0.462699078, "num_tokens": 1385, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898254600903, "lm_q2_score": 0.7279754371026367, "lm_q1q2_score": 0.6595383391998507}} {"text": " SUBROUTINE YLM(XLAT,XLON,LMAX,Y,WK1,WK2,WK3)\nC\n COMPLEX TEMP,FAC,DFAC\n DIMENSION WK1(1),WK2(1),WK3(1),Y(1)\nC\nC WK1,WK2,WK3 SHOULD BE DIMENSIONED AT LEAST (LMAX+1)*4\nC\n DATA RADIAN/57.2957795/\nC\n THETA=(90.-XLAT)/RADIAN\n PHI=XLON/RADIAN\nC\n IND=0\n LM1=LMAX+1\n DO 10 IL1=1,LM1\n L=IL1-1\n CALL LEGNDR(THETA,L,L,WK1,WK2,WK3)\nC\n FAC=(1.,0.)\n DFAC=CEXP(CMPLX(0.,PHI))\nC\n DO 20 IM=1,IL1\n TEMP=FAC*CMPLX(WK1(IM),0.)\n IND=IND+1\n Y(IND)=REAL(TEMP)\n IF(IM.EQ.1) GOTO 20\n IND=IND+1\n Y(IND)=AIMAG(TEMP)\n 20 FAC=FAC*DFAC\nC\n 10 CONTINUE\n RETURN\n END\nc\n SUBROUTINE LEGNDR(THETA,L,M,X,XP,XCOSEC)\n DIMENSION X(2),XP(2),XCOSEC(2)\n DOUBLE PRECISION SMALL,SUM,COMPAR,CT,ST,FCT,COT,FPI,X1,X2,X3,\n 1F1,F2,XM,TH,DFLOAT\n DATA FPI/12.56637062D0/\n DFLOAT(I)=FLOAT(I)\n SUM=0.D0\n LP1=L+1\n TH=THETA\n CT=DCOS(TH)\n ST=DSIN(TH)\n MP1=M+1\n FCT=DSQRT(DFLOAT(2*L+1)/FPI)\n SFL3=SQRT(FLOAT(L*(L+1)))\n COMPAR=DFLOAT(2*L+1)/FPI\n DSFL3=SFL3\n SMALL=1.D-16*COMPAR\n DO 1 I=1,MP1\n X(I)=0.\n XCOSEC(I)=0.\n 1 XP(I)=0.\n IF(L.GT.1.AND.ABS(THETA).GT.1.E-5) GO TO 3\n X(1)=FCT\n IF(L.EQ.0) RETURN\n X(1)=CT*FCT\n X(2)=-ST*FCT/DSFL3\n XP(1)=-ST*FCT\n XP(2)=-.5D0*CT*FCT*DSFL3\n IF(ABS(THETA).LT.1.E-5) XCOSEC(2)=XP(2)\n IF(ABS(THETA).GE.1.E-5) XCOSEC(2)=X(2)/ST\n RETURN\n 3 X1=1.D0\n X2=CT\n DO 4 I=2,L\n X3=(DFLOAT(2*I-1)*CT*X2-DFLOAT(I-1)*X1)/DFLOAT(I)\n X1=X2\n 4 X2=X3\n COT=CT/ST\n COSEC=1./ST\n X3=X2*FCT\n X2=DFLOAT(L)*(X1-CT*X2)*FCT/ST\n X(1)=X3\n X(2)=X2\n SUM=X3*X3\n XP(1)=-X2\n XP(2)=DFLOAT(L*(L+1))*X3-COT*X2\n X(2)=-X(2)/SFL3\n XCOSEC(2)=X(2)*COSEC\n XP(2)=-XP(2)/SFL3\n SUM=SUM+2.D0*X(2)*X(2)\n IF(SUM-COMPAR.GT.SMALL) RETURN\n X1=X3\n X2=-X2/DSQRT(DFLOAT(L*(L+1)))\n DO 5 I=3,MP1\n K=I-1\n F1=DSQRT(DFLOAT((L+I-1)*(L-I+2)))\n F2=DSQRT(DFLOAT((L+I-2)*(L-I+3)))\n XM=K\n X3=-(2.D0*COT*(XM-1.D0)*X2+F2*X1)/F1\n SUM=SUM+2.D0*X3*X3\n IF(SUM-COMPAR.GT.SMALL.AND.I.NE.LP1) RETURN\n X(I)=X3\n XCOSEC(I)=X(I)*COSEC\n X1=X2\n XP(I)=-(F1*X2+XM*COT*X3)\n 5 X2=X3\n RETURN\n end\n\n \n", "meta": {"hexsha": "5fe68ac56cabd4c23a8c69ee1ba1b695a7a4c552", "size": 2334, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "s362ani/PROGRAMS/src/ylm.f", "max_stars_repo_name": "nmancinelli/ss-precursors", "max_stars_repo_head_hexsha": "f27fbd20fad400fc7de3d95f1b83b831a7cc9487", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "s362ani/PROGRAMS/src/ylm.f", "max_issues_repo_name": "nmancinelli/ss-precursors", "max_issues_repo_head_hexsha": "f27fbd20fad400fc7de3d95f1b83b831a7cc9487", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "s362ani/PROGRAMS/src/ylm.f", "max_forks_repo_name": "nmancinelli/ss-precursors", "max_forks_repo_head_hexsha": "f27fbd20fad400fc7de3d95f1b83b831a7cc9487", "max_forks_repo_licenses": ["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.2285714286, "max_line_length": 67, "alphanum_fraction": 0.5115681234, "num_tokens": 1148, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989815306765, "lm_q2_score": 0.727975443004307, "lm_q1q2_score": 0.6595383371553326}} {"text": "! This file is an outline of a code to perform a calculation of a\n! charged particle scattered by a spherically-symmetric short-range local\n! potential.\n! There are a number of comments throughout the file beginning with !>>> which\n! indicate sections of code you will need to complete.\n\n! Last modified: May 25 2021\n! Liam Scarlett\n\nprogram main\n\n use constants\n implicit none\n\n real*8, allocatable :: &\n Vmat(:,:), & !V-matrix elements Vmat(kf,ki)\n V(:), & !radial potential function V(r)\n rgrid(:), & !radial grid\n rweights(:), & !radial integration weights\n kgrid(:), & !momentum-space grid\n kweights(:), & !momentum-space integration weights (and Green's func)\n contwaves(:,:), & !projectile radial continuum waves contwaves(k,r)\n DCS(:), & !array to hold differential cross section - DCS(theta)\n theta(:), & !array to hold values of theta - in degrees\n ICS(:) !integrated cross section per l\n\n real*8 :: &\n rmax, & !max value of radial grid\n dr, & !radial grid step size\n energy, & !projectile energy\n k, & !projectile momentum\n kg_A, kg_B, kg_P !some parameters for setting up kgrid\n\n complex*16, allocatable :: Ton(:) !on-shell T-matrix element per l\n\n integer :: &\n nrmax, & !number of rgrid points\n nkmax, & !number of kgrid points\n zproj, & !projectile charge\n l, & !partial-wave angular momentum\n lmin, lmax, & !min and max values of l\n iounit, & !a unit number for input/ouput\n ntheta, & !an index to iterate over theta\n nthetamax, & !max number of theta\n kg_Na, kg_Nb, kg_Np !some more parameters for setting up kgrid\n\n !! additional variables\n character(len=200) :: filename !! for file io\n integer :: status !! for error checking\n integer :: i_r, i_k !! for iterating through r, k grids\n integer :: ii, jj !! for iterating through V matrix\n\n !set kgrid parameters - leave this as is\n kg_Na = 30; kg_Nb = 30; kg_Np = 10\n kg_a = 0.85; kg_b = 2.5; kg_p = 4.0\n nkmax=kg_Na+kg_Nb+kg_Np+1\n\n!>>> open data.in file and read input parameters\n!>>> note: energy should be read in electron volts\n!>>> and grid parameters in atomic units\n !! open input file for reading\n filename=\"data/input/data.in\"\n open(unit=iounit, file=trim(adjustl(filename)), action=\"read\", &\n iostat=status)\n\n !! handle invalid open\n if (status /= 0) then\n write (*, *) \"[error] \", trim(adjustl(filename)), \" could not be opened\"\n call exit(status)\n end if\n\n !! read energy\n read(iounit, *) energy\n read(iounit, *) rmax, dr\n read(iounit, *) zproj, lmin, lmax\n\n ! debug\n write (*, *) \"[debug] read\"\n write (*, *) \"[debug] = \", energy\n write (*, *) \"[debug] = \", rmax\n write (*, *) \"[debug] = \", dr\n write (*, *) \"[debug] = \", zproj\n write (*, *) \"[debug] = \", lmin\n write (*, *) \"[debug] = \", lmax\n write (*, *) \"[debug] end read\"\n\n !! close input file\n close(iounit)\n\n!>>> do any input validation you think is necessary here\n !! check input validity\n status = 0\n\n if (energy < 0d0) status = 1\n if (rmax < 0d0) status = 1\n if (dr < 0d0) status = 1\n if (lmin < 0) status = 1\n if (lmax < 0) status = 1\n if (lmin > lmax) status = 1\n\n !! handle invalid input\n if (status /= 0) then\n write (*, *) \"[error] input data is invalid\"\n call exit(status)\n end if\n\n!>>> convert the energy to atomic units and calculate the\n!>>> projectile momentum\n !! scale energy\n energy = energy / 27.2113862459d0\n\n !! set momentum\n k = sqrt(2d0*energy)\n\n!>>> determine number of rgrid points nrmax\n!>>> note: nrmax should be even for simpson's integration\n!>>> to take into account that the r=0 point has been omitted\n !! set nrmax such that nrmax*dr >= rmax\n nrmax = ceiling(rmax / dr)\n\n !! increment nrmax if it is odd\n if (mod(nrmax, 2) == 1) nrmax = nrmax + 1\n\n !allocate memory\n allocate(rgrid(nrmax),rweights(nrmax))\n allocate(kgrid(nkmax),kweights(nkmax))\n allocate(contwaves(nkmax,nrmax))\n allocate(V(nrmax))\n allocate(Ton(lmin:lmax),ICS(lmin:lmax))\n allocate(Vmat(nkmax,nkmax))\n\n !setup grids\n call setup_rgrid(nrmax, dr, rgrid, rweights)\n call setup_kgrid(k, nkmax, kg_Na, kg_a, kg_Nb, kg_b, kg_Np, kg_p, kgrid, &\n kweights)\n\n!>>> define short-range potential V(r)\n !! v(r) = z*(1 + (1/r))*exp(-2r)\n do i_r = 1, nrmax\n V(i_r) = zproj*(1d0 + (1d0/rgrid(i_r)))*exp(-2d0*rgrid(i_r))\n end do\n\n ! !! debug: V(:)\n ! filename=\"data/output/potential.txt\"\n ! open(unit=iounit, file=trim(adjustl(filename)), action=\"write\", &\n ! iostat=status)\n ! do i_r = 1, nrmax, (nrmax/1000)\n ! write (iounit, *) rgrid(i_r), V(i_r)\n ! end do\n ! close (iounit)\n ! !! debug: end\n\n !begin loop over angular momenta\n do l=lmin, lmax\n !populate contwaves matrix with a continuum wave for each off-shell k\n call setup_contwaves(nkmax,kgrid,l,nrmax,rgrid,contwaves)\n\n ! !! debug: contwaves(:, :)\n ! if (l == 0) then\n ! filename=\"data/output/contwaves.txt\"\n ! open(unit=iounit, file=trim(adjustl(filename)), action=\"write\", &\n ! iostat=status)\n ! do i_r = 1, nrmax, (nrmax/1000)\n ! write (iounit, *) rgrid(i_r), contwaves(1:min(nkmax,100), i_r)\n ! end do\n ! close (iounit)\n ! end if\n ! !! debug: end\n\n !evaluate the V-matrix elements\n call calculate_Vmatrix(nkmax,kgrid,contwaves,nrmax,rgrid,rweights,V,Vmat)\n\n ! !! debug: V-matrix half-on-shell\n ! if (l == 0) then\n ! write (*, *) \"[debug] V-matrix half-on-shell\"\n ! filename=\"data/output/v-matrix-halfonshell.txt\"\n ! open(unit=iounit, file=trim(adjustl(filename)), action=\"write\", &\n ! iostat=status)\n ! do ii = 2, nkmax\n ! write (iounit, *) kgrid(ii), Vmat(ii, 1)\n ! end do\n ! close (iounit)\n ! end if\n ! !! debug: end\n\n !solve the Lippman-Schwinger equation for the on-shell T-matrix\n call tmatrix_solver(nkmax,kgrid,kweights,Vmat,Ton(l))\n enddo\n\n !populate theta - theta = 0, 1,..., 180 degrees\n nthetamax = 181\n allocate(theta(nthetamax),DCS(nthetamax))\n do ntheta = 1, nthetamax\n theta(ntheta) = dble(ntheta-1)\n enddo\n\n !call subroutines to calculate DCS and ICS\n call compute_dcs(nthetamax, theta, lmin, lmax, Ton, k, DCS)\n call compute_ics(lmin, lmax, Ton, k, ICS)\n\n!>>> output the DCS and ICS to files\n!>>> to easily study the convergence you can write the ics to file as a\n!>>> function of l along with a running total so that the running total in\n!>>> the final line is your total ICS summed over l\n !! open dcs output file for writing\n filename=\"data/output/dcs.txt\"\n open(unit=iounit, file=trim(adjustl(filename)), action=\"write\", &\n iostat=status)\n\n !! handle invalid open\n if (status /= 0) then\n write (*, *) \"[error] \", trim(adjustl(filename)), \" could not be opened\"\n call exit(status)\n end if\n\n !! write dcs to file\n ! write (iounit, *) \"# theta, dcs(theta)\"\n do ntheta = 1, nthetamax\n write (iounit, *) theta(ntheta), DCS(ntheta)\n end do\n\n !! close dcs output file\n close (iounit)\n\n !! open ics output file for writing\n filename=\"data/output/ics.txt\"\n open(unit=iounit, file=trim(adjustl(filename)), action=\"write\", &\n iostat=status)\n\n !! handle invalid open\n if (status /= 0) then\n write (*, *) \"[error] \", trim(adjustl(filename)), \" could not be opened\"\n call exit(status)\n end if\n\n !! write ics to file\n ! write (iounit, *) \"# l, ics(l), sum(ics(1:l))\"\n do l = lmin, lmax\n write (iounit, *) l, ics(l), sum(ics(lmin:l))\n end do\n\n !! close ics output file\n close (iounit)\n\nend program main\n\nsubroutine compute_ics(lmin, lmax, Ton, k, ICS)\n use constants\n implicit none\n integer, intent(in) :: lmin, lmax\n complex*16, intent(in) :: Ton(lmin:lmax)\n real*8, intent(in) :: k\n real*8, intent(out) :: ICS(lmin:lmax)\n integer :: l\n\n!>>> populate the ICS array with the partial-wave ICS per l\n !! calculate ics unscaled\n do l = lmin, lmax\n ics(l) = (2d0*l + 1d0)*((abs(Ton(l))) ** 2)\n end do\n\n !! scale by constant term\n ics(:) = ics(:) * ((4d0*(pi ** 3))/(k ** 4))\n\nend subroutine compute_ics\n\nsubroutine compute_dcs(nthetamax, theta, lmin, lmax, Ton, k, DCS)\n use constants\n implicit none\n integer, intent(in) :: nthetamax, lmin, lmax\n real*8, intent(in) :: theta(nthetamax), k\n complex*16, intent(in) :: Ton(0:lmax)\n real*8, intent(out) :: DCS(nthetamax)\n integer :: l, ntheta !loop indices\n real*8:: PL !Legendre polynomials - from file plql.f\n real*8 :: costheta !use this to store cos(theta in radians)\n complex*16 :: f(nthetamax) !scattering amplitude\n\n!>>> calculate the scattering amplitude f(theta) for each theta\n!>>> by iterating over l and using the partial-wave\n!>>> expansion of f\n !! calculate scattering amplitude unscaled\n f(:) = 0d0\n do ntheta = 1, nthetamax\n costheta = cos(theta(ntheta) * (pi/180d0))\n\n do l = lmin, lmax\n f(ntheta) = f(ntheta) + (2d0*l + 1d0)*Ton(l)*PL(l, costheta)\n end do\n\n end do\n !! scale scattering amplitude\n f(:) = f(:) * (-pi/(k ** 2))\n\n!>>> obtain the DCS from the scattering amplitude\n do ntheta = 1, nthetamax\n dcs(ntheta) = (abs(f(ntheta))) ** 2\n end do\n\nend subroutine compute_dcs\n\nsubroutine setup_rgrid(nrmax, dr, rgrid, rweights)\n implicit none\n integer, intent(in) :: nrmax\n real*8, intent(in) :: dr\n real*8, intent(out) :: rgrid(nrmax), rweights(nrmax)\n integer :: ir !index to iterate over r\n\n!>>> iterate over r and populate the rgrid and rweights arrays\n!>>> - rweights should contain Simpson's integration weights:\n!>>> (4, 2, 4, 2, ..., 2, 4) * dr / 3.0\n!>>> - you can make use of the intrinsic MOD function for the\n!>>> alternating 4, 2 terms\n!>>> - note we have neglected the terms with a coefficient of 1 (rather\n!>>> than 4 or 2) since the first term (r=0) is skipped and the last term\n!>>> corresponds to the end of the radial grid where we assume all\n!>>> functions should be zero (and if not the grid is not large enough)\n !! calculate radial grid\n do ir = 1, nrmax\n rgrid(ir) = dr * ir\n end do\n\n !! calculate simpson's integration weights\n rweights(1:nrmax:2) = 4d0\n rweights(2:nrmax:2) = 2d0\n !! scale weights appropriately\n rweights(:) = rweights(:) * (dr/3d0)\n\nend subroutine setup_rgrid\n\nsubroutine setup_contwaves(nkmax, kgrid, l, nrmax, rgrid, contwaves)\n implicit none\n integer, intent(in) :: nkmax, l, nrmax\n real*8, intent(in) :: kgrid(nkmax), rgrid(nrmax)\n real*8, intent(out) :: contwaves(nkmax,nrmax)\n real*8 :: ncontwaves(nkmax,nrmax)\n integer :: nk, nr !indices to loop over k and r\n real*8 :: E\n !! numerov variables\n real*8 :: s_grid(nrmax), g_grid(nrmax), v_grid(nrmax)\n real*8 :: step_size\n integer :: fact_term\n integer :: status\n integer :: ii\n\n!>>> iterate over k, populating the contwaves matrix\n !! set step_size\n step_size = rgrid(2) - rgrid(1)\n\n !! initialise numerov grids\n s_grid(:) = 0d0\n v_grid(:) = ((l)*(l + 1d0))/(rgrid(:) ** 2)\n\n !! calculate double factorial term\n fact_term = 1\n do ii = 1, (2*l + 1), 2\n fact_term = fact_term * ii\n end do\n\n !! iterate over k\n do nk = 1, nkmax\n !! todo: should inline this\n g_grid(:) = (kgrid(nk) ** 2) - v_grid(:)\n\n !! calculate boundary conditions\n contwaves(nk, 1:2) = ((rgrid(1:2)*kgrid(nk)) ** (l + 1))/dble(fact_term)\n\n !! perform numerov method\n status = 0\n call numerov_f(nrmax, step_size, s_grid, g_grid, &\n contwaves(nk, :), status)\n\n !! handle numerov_f failing\n if (status /= 0) then\n write (*, *) \"[error] numerov_f failed with = \", status\n call exit(status)\n end if\n end do\n\nend subroutine setup_contwaves\n\n\n!>>> your forwards Numerov subroutine can go here\n!! numerov_f\n!!\n!! Brief:\n!! Calculates the values of $y(x)$, defined by the differential equation\n!! $$ y''(x) = -g(x)y(x) + s(x) $$ ,\n!! on a grid to fourth-order accuracy using the forward Numerov method.\n!!\n!! Summary:\n!! Suppose, $X = \\{x_{1}, \\dotsc, x_{n_{x}}\\}$, is a grid with $n_{x}$ points,\n!! such that $x_{i+1} - x_{i} = h$ for all $i = 1, \\dotsc, n_{x}-1$,\n!! and that $g(x), s(x) : \\mathbb{R} \\to \\mathbb{R}$ have been evaluated on\n!! this grid.\n!! Suppose further that $y : \\mathbb{R} \\to \\mathbb{R}$ is defined by the\n!! differential equation,\n!! $$ y''(x) = -g(x)y(x) + s(x) $$ ,\n!! and the values of $y(x_{1}), y(x_{2})$ are known.\n!! The values of $y(x_{i})$ for $i = 3, \\dotsc, n_{x}$ are calculated to\n!! fourth-order accuracy using the forward Numerov method.\n!!\n!! Input:\n!! - `n_x` is the number of grid points.\n!! - `step_size` is the distance between consecutive points on the grid $X$.\n!! - `s_grid` is the evaluation of $s(x)$ on the grid $X$.\n!! - `g_grid` is the evaluation of $g(x)$ on the grid $X$.\n!!\n!! Output:\n!! - `y_grid` is the evaluation of $y(x)$ on the grid $X$, calculated via the\n!! forward Numerov method.\n!! - `status` integer status code which takes the following values:\n!! - `status == 0` indicates successful execution;\n!! - `status > 0` indicates that the arguments were invalid;\n!! - `status == -1` indicates that a numerical error (NaN or infinity)\n!! occured during execution.\nsubroutine numerov_f (n_x, step_size, s_grid, g_grid, y_grid, status)\n integer , intent(in) :: n_x\n double precision , intent(in) :: step_size\n double precision , intent(in) :: s_grid(n_x)\n double precision , intent(in) :: g_grid(n_x)\n double precision , intent(out) :: y_grid(n_x)\n integer , intent(out) :: status\n double precision :: step_s_grid(n_x)\n double precision :: step_g_grid(n_x)\n integer :: ii\n\n ! check if arguments are valid\n status = 0\n\n if (n_x < 1) then\n ! no grid points\n status = 1\n end if\n\n if (step_size < 0d0) then\n ! non-positive step_size\n status = 2\n end if\n\n ! terminate subroutine if arguments are invalid, otherwise proceed\n if (status /= 0) then\n y_grid(:) = 0d0\n return\n end if\n\n ! perform forward-numerov method\n step_s_grid(:) = s_grid(:) * (step_size ** 2) / 12d0\n step_g_grid(:) = g_grid(:) * (step_size ** 2) / 12d0\n\n if (n_x >= 3) then\n do ii = 2, n_x - 1\n y_grid(ii+1) = &\n ((2*y_grid(ii)*(1d0 - 5d0*step_g_grid(ii))) &\n - (y_grid(ii-1)*(1d0 + step_g_grid(ii-1))) &\n + (step_s_grid(ii+1) + 10d0*step_s_grid(ii) + step_s_grid(ii-1)) &\n ) / (1d0 + step_g_grid(ii+1))\n\n ! check for and handle numerical error (NaN or Infinity) and terminates\n if ((y_grid(ii+1) /= y_grid(ii+1)) .or. (y_grid(ii+1) > huge(0d0))) then\n status = -1\n\n if (ii + 2 <= n_x) then\n y_grid(ii+2:n_x) = 0d0\n end if\n\n return\n end if\n end do\n end if\n\nend subroutine numerov_f\n\nsubroutine calculate_Vmatrix(nkmax,kgrid,contwaves,nrmax,rgrid,rweights,V,Vmat)\n use constants\n implicit none\n integer, intent(in) :: nkmax, nrmax\n real*8, intent(in) :: kgrid(nkmax), contwaves(nkmax,nrmax), rgrid(nrmax), &\n rweights(nrmax), V(nrmax)\n real*8, intent(out) :: Vmat(nkmax,nkmax)\n integer :: nkf,nki !indices for looping over on- and off-shell k\n !! array intended to utilise cacheing\n real*8 :: cache(nrmax)\n\n!>>> evaluate the V-matrix elements and store in the Vmat matrix\n!>>> note: the V-matrix is symmetric, make use of this fact to reduce the\n!>>> amount of time spent in this subroutine\n !! loop in efficient order which utilises symmetry of V-matrix\n do nki = 1, nkmax\n !! moved parts of the integrand common to all kf outside for cacheing\n cache(:) = V(:) * contwaves(nki, :) * rweights(:)\n\n do nkf = 1, nki\n !! calculate V_{f, i} by integration\n Vmat(nkf, nki) = sum(contwaves(nkf, :) * cache(:))\n\n !! set V_{i, f} = V_{f, i} as consequence of symmetric V-matrix\n !! no check for diagonal since setting diagonal to itself is\n !! inconsequential\n Vmat(nki, nkf) = Vmat(nkf, nki)\n end do\n end do\n\n !! scale V-matrix\n Vmat(:, :) = Vmat(:, :) * (2d0/pi)\n\nend subroutine calculate_Vmatrix\n\nsubroutine tmatrix_solver(nkmax,kgrid,kweights,Vmat,Ton)\n use constants\n implicit none\n integer, intent(in) :: nkmax\n real*8, intent(in) :: kgrid(nkmax), kweights(nkmax), Vmat(nkmax,nkmax)\n complex*16, intent(out) :: Ton !on-shell T-matrix element\n real*8 :: &\n Koff(nkmax-1), & !half-off-shell K-matrix elements\n Kon, & !on-shell K-matrix element\n Von, & !on-shell V-matrix element\n A(nkmax-1,nkmax-1) !Coefficient matrix for the linear system Ax=b\n integer :: j, ipiv(nkmax-1), info\n !! local variables\n integer :: ff, nn ! loop variables\n\n!>>> store the on-shell V-matrix element in Von\n Von = Vmat(1, 1)\n\n!>>> populate the matrix A according to Eq (113) in the slides\n !! iterate through A matrix\n do nn = 1, nkmax-1\n !! set all elements (neglecting delta_{i, j} terms)\n do ff = 1, nkmax-1\n A(ff, nn) = - kweights(nn+1)*Vmat(ff+1, nn+1)\n end do\n !! add diagonal delta{i, i} terms\n A(nn, nn) = A(nn, nn) + 1d0\n end do\n\n!>>> populate the vector Koff with the half-on-shell V-matrix elements (RHS of\n!>>> Eq (112))\n do nn = 1, nkmax-1\n Koff(nn) = Vmat(nn+1, 1)\n end do\n\n !Here is the call to DGESV\n call dgesv( nkmax-1, 1, A, nkmax-1, ipiv, Koff, nkmax-1, info )\n if(info /= 0) then\n print*, 'ERROR in dgesv: info = ', info\n endif\n\n!>>> Now use the half-on-shell K matrix which has been stored in Koff to get the\n!>>> on-shell K-matrix element Kon\n Kon = Vmat(1,1) + sum(kweights(2:nkmax)*Vmat(1, 2:nkmax)*Koff(:))\n\n!>>> And then use Kon to get the on-shell T-matrix element Ton\n Ton = Kon / (1d0 + ((0d0,1d0)*pi*Kon)/kgrid(1))\n\n ! !! debug:\n ! write (*, *) \"[debug] = \", Von\n ! write (*, *) \"[debug] = \", Kon\n ! write (*, *) \"[debug] = \", Ton\n ! !! debug: end\nend subroutine tmatrix_solver\n\n!A subroutine provided for you to set up the kgrid and kweights\n!note: the kgrid is setup with the on-shell point in the first element\n! and the corresponding kweights include the integration weights\n! AND the Green's function\nsubroutine setup_kgrid(k,nkmax,Na,a,Nb,b,Np,p,kgrid,kweights)\n implicit none\n real*8, intent(in) :: k\n integer, intent(in) :: Na, Nb, Np\n integer, intent(in) :: nkmax\n real*8, intent(out) :: kgrid(nkmax), kweights(nkmax)\n integer :: nk\n real*8, intent(in) :: a, b, p\n real*8 :: grid1(nkmax-1), weight1(nkmax-1)\n\n call kgrid_igor(0.0,k,a,Na,b,Nb,p,Np,nkmax-1,grid1,weight1)\n\n kgrid(1) = k\n kgrid(2:nkmax) = grid1\n kweights(1) = 0.0d0\n kweights(2:nkmax) = weight1\n do nk=2, nkmax\n kweights(nk) = 2.0d0* kweights(nk) / (k**2 - kgrid(nk)**2)\n enddo\nend subroutine setup_kgrid\n", "meta": {"hexsha": "8ac730af2f3eb02b3cc21704649b56bf67d95507", "size": 18722, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/main.f90", "max_stars_repo_name": "dgsaf/acqm-workshop-4", "max_stars_repo_head_hexsha": "ac1b44f1b932fcba7a09cb9324c0044002abfa32", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/main.f90", "max_issues_repo_name": "dgsaf/acqm-workshop-4", "max_issues_repo_head_hexsha": "ac1b44f1b932fcba7a09cb9324c0044002abfa32", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/main.f90", "max_forks_repo_name": "dgsaf/acqm-workshop-4", "max_forks_repo_head_hexsha": "ac1b44f1b932fcba7a09cb9324c0044002abfa32", "max_forks_repo_licenses": ["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.8401360544, "max_line_length": 80, "alphanum_fraction": 0.6274970623, "num_tokens": 6187, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898127684335, "lm_q2_score": 0.7279754430043072, "lm_q1q2_score": 0.6595383353074896}} {"text": "************************************************************************\n* MATRIX PROCEDURES\n* D. Everhart\n************************************************************************\n* The MIT License (MIT)\n* \n* Copyright (c) 2016 Daniel Everhart\n* \n* Permission is hereby granted, free of charge, to any person obtaining\n* a copy of this software and associated documentation files (the \n* \"Software\"), to deal in the Software without restriction, including\n* without limitation the rights to use, copy, modify, merge, publish,\n* distribute, sublicense, and/or sell copies of the Software, and to\n* permit persons to whom the Software is furnished to do so, subject\n* to the following conditions:\n* \n* The above copyright notice and this permission notice shall be\n* included in all copies or substantial portions of the Software.\n* \n* THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n* \n************************************************************************\n* These subroutines have evolved significantly over the years.\n* They began as a undergraduate classroom assignment, and evolved to\n* what they are now. \n*\n* When writing code for numerical analysis, I inevitability have\n* the need to do some matrix operations and most of the time, this\n* includes matrix inversion.\n*\n* The PROGRAM and two (2) following SUBROUTINEs demonstrate how to use\n* this module. They may be commented out in order to compile this as a\n* library.\n************************************************************************\n* AE 227 FALL 1994 - Wichita State University\n* MGAUSJ - Gauss-Jordan elimination\n* AE 527 FALL 1996 - Wichita State University\n* MGAUSB - Gauss elimination with back substitution (more efficient)\n* 2004 - PRESENT - Abstraction of procedures and cleanup.\n* MAR 2016 - Cleanup and preparation of messages for use by others.\n************************************************************************\n PROGRAM MTEST\n IMPLICIT NONE\n CALL SMTEST\n WRITE(*,*)\n CALL BNMK\n 999 STOP\n END PROGRAM MTEST\n************************************************************************\n SUBROUTINE BNMK\n IMPLICIT NONE\n INTEGER ROWS,COLS,SZ,STIME,ETIME,TM(9)\n PARAMETER (ROWS=600, COLS=2*ROWS, SZ=ROWS*COLS)\n DOUBLE PRECISION D(ROWS,COLS)\n DOUBLE PRECISION D1(ROWS,ROWS), D2(ROWS,ROWS)\n EQUIVALENCE (D1(1,1), D(1,1)), (D2(1,1), D(1,ROWS+1))\n DATA D /SZ*0D0/\n*\n STIME = TIME()\n WRITE(*,810) 'START MGAUSJ'\n CALL MRND1(D1,ROWS*ROWS,0)\n CALL MIDEN(D2,ROWS,ROWS)\n CALL MGAUSJ(D,ROWS,COLS)\n ETIME = TIME()\n CALL GMTIME(ETIME-STIME, TM)\n WRITE(*,820) 'END MGAUSJ ', TM(3),':',TM(2),':',TM(1)\n* \n WRITE(*,*)\n* \n STIME = TIME()\n WRITE(*,810) 'START MGAUSB'\n CALL MRND1(D1,ROWS*ROWS,0)\n CALL MIDEN(D2,ROWS,ROWS)\n CALL MGAUSB(D,ROWS,COLS)\n ETIME = TIME()\n CALL GMTIME(ETIME-STIME, TM)\n WRITE(*,820) 'END MGAUSB ', TM(3),':',TM(2),':',TM(1)\n*\n 810 FORMAT('0*** ',A12)\n 820 FORMAT('0*** ',A12,I2.2,A,I2.2,A,I2.2)\n 999 RETURN\n END SUBROUTINE BNMK\n************************************************************************\n SUBROUTINE SMTEST\n IMPLICIT NONE\n INTEGER COLS, ROWS, SZ\n INTEGER I, J\n PARAMETER (COLS=6, ROWS=3, SZ=COLS*ROWS)\n DOUBLE PRECISION D(ROWS,COLS), E(ROWS,ROWS)\n DOUBLE PRECISION D1(ROWS,ROWS), D2(ROWS,ROWS)\n EQUIVALENCE (D1(1,1), D(1,1)), (D2(1,1), D(1,4))\n DATA D /SZ*0D0/\n*\n WRITE(6,910)\n WRITE(6,920)\n WRITE(6,910)\n WRITE(6,980)'MATRIX D IS COMPRISED OF D1 AND D2.'\n WRITE(6,980)' [ D ] = [ D1 | D2 ]'\n WRITE(6,980)'MATRIX E IS SQUARE DIMENSIONED THE SAME AS'\n WRITE(6,980)' D1 AND D2'\n WRITE(6,910)\n*\n WRITE(6,*)\n WRITE(6,990)'TESTING MINIT1 ON [D].'\n CALL MINIT1(D, COLS*ROWS, 1D0)\n CALL MPRT(D,ROWS,COLS)\n*\n WRITE(6,*)\n WRITE(6,990)'TESTING MINIT2 ON [D].'\n CALL MINIT2(D, ROWS, COLS, 2D0)\n CALL MPRT(D,ROWS,COLS)\n*\n WRITE(6,*)\n WRITE(6,990)'TESTING MRND1 ON [D1].'\n CALL MRND1(D1,ROWS*ROWS,0)\n CALL MPRT(D,ROWS,COLS)\n*\n WRITE(6,*)\n WRITE(6,990)'TESTING MIDEN ON [D2].'\n CALL MIDEN(D2,ROWS,COLS)\n CALL MPRT(D,ROWS,COLS)\n*\n WRITE(6,*)\n WRITE(6,990)'ZEROING ELEMENTS D(2,1), D(2,2), D(2,3)...'\n D(2,1) = 0D0\n D(2,2) = 0D0\n D(2,3) = 0D0\n CALL MPRT(D,ROWS,COLS)\n*\n WRITE(6,*)\n WRITE(6,990)'RUNNING GAUSS-JORDAN ELIMINATION ON [D]'\n CALL MGAUSJ(D, ROWS, COLS)\n CALL MPRT(D,ROWS,COLS)\n*\n WRITE(6,*)\n WRITE(6,990)'RANDOMIZE [D1].'\n CALL MRND1(D1,ROWS*ROWS,0)\n CALL MPRT(D,ROWS,COLS)\n*\n WRITE(6,*)\n WRITE(6,990)'IDENTITY [D2].'\n CALL MIDEN(D2,ROWS,ROWS)\n CALL MPRT(D,ROWS,COLS)\n*\n** Copy D1 into E\n*\n DO 110, I=1,ROWS\n DO 110, J=1,ROWS\n 110 E(I,J) = D1(I,J)\n*\n WRITE(6,*)\n WRITE(6,990)'RUNNING GAUSS ELIMINATION AND BACK SUBSTITUTION ON'\n & //' [D]'\n CALL MGAUSB(D, ROWS, COLS)\n CALL MPRT(D,ROWS,COLS)\n*\n WRITE(6,*)\n WRITE(6,990)'MULTIPLYING MATRIX BY INVERSE [D1] = [D2] * [E]'\n CALL MMUL(D2,ROWS,ROWS,E,ROWS,ROWS,D1,ROWS,ROWS)\n CALL MPRT(D1,ROWS,ROWS)\n*\n 910 FORMAT('********************************************************'\n 2 '************************')\n 920 FORMAT('******************************* RUNNING UNIT TESTS '\n 1 '*****************************')\n 980 FORMAT(15X,A)\n 990 FORMAT('0*** ',A)\n 999 RETURN\n END SUBROUTINE SMTEST\n************************************************************************\n* MINIT1: Matrix INITialize 1-D\n************************************************************************\n* Initialize matrix elements to a value based on a single dimension. \n* It matters not if the value is a 1, 2, N dimensional array, as long\n* as the SZ does not overrun the array.\n************************************************************************\n* M * Matrix to be initialized\n* SZ * Size of matrix\n* VAL * Value to which matrix is initialized.\n************************************************************************\n SUBROUTINE MINIT1(M, SZ, VAL)\n IMPLICIT NONE\n DOUBLE PRECISION M(*), VAL\n INTEGER SZ\n INTEGER I\n DO 110 I = 1, SZ\n 110 M(I) = VAL\n 999 RETURN\n END SUBROUTINE MINIT1\n************************************************************************\n* MINIT2: Matrix INITialize 2-D\n************************************************************************\n* Initialize matrix elements to a value based on a two dimensions. It\n* matters not if the value is a 1, 2, N dimensional array, as long as\n* the product of ROWS X COLS does not overrun the array.\n************************************************************************\n* M * Matrix to be initialized\n* ROWS * Rows (index 1)\n* COLS * Columns (index 2)\n* VAL * Value to which matrix is initialized.\n************************************************************************\n SUBROUTINE MINIT2(M, ROWS, COLS, VAL)\n IMPLICIT NONE\n DOUBLE PRECISION M(ROWS,COLS), VAL\n INTEGER COLS, ROWS\n INTEGER I, J\n DO 110 I = 1, ROWS\n DO 110 J = 1, COLS\n 110 M(I,J) = VAL\n 999 RETURN\n END SUBROUTINE MINIT2\n************************************************************************\n* MIDEN: Matrix IDENtity\n************************************************************************\n* Initializes given matrix as an identity based on the rows and columns.\n* Identity matricies are necessarily square. However, this procedure\n* does not require that ROWS .EQ. COLS. All elements on the diagonal\n* (A(I,J) where I.EQ.J) are initialized to 1D0, and all other element\n* are set to 0D0.\n************************************************************************\n* M * Matrix to be initialized to identity.\n* ROWS * Rows (index 1)\n* COLS * Columns (index 2)\n************************************************************************\n SUBROUTINE MIDEN(M,ROWS,COLS)\n IMPLICIT NONE\n DOUBLE PRECISION M(ROWS,COLS)\n INTEGER ROWS,COLS\n INTEGER I, J\n DO 110 I = 1, ROWS\n DO 110 J = 1, COLS\n IF (I.EQ.J) THEN\n M(I,J) = 1D0\n ELSE\n M(I,J) = 0D0\n END IF\n 110 CONTINUE\n 999 RETURN\n END SUBROUTINE MIDEN\n************************************************************************\n* MRND1: Matrix RaNDomize 1-D\n************************************************************************\n* Initialize matrix elements to a random value based on a single\n* dimension. It matters not if the value is a 1, 2, N dimensional\n* array, as long as the SZ does not overrun the array.\n************************************************************************\n* M * Matrix to be initialized\n* SZ * Size of matrix\n* SEED * Seed for random number generator\n************************************************************************\n SUBROUTINE MRND1(M,SZ,SEED)\n IMPLICIT NONE\n DOUBLE PRECISION M(*), VAL\n INTEGER SZ,SEED\n INTEGER I\n CALL SRAND(SEED)\n DO 110 I = 1,SZ\n 110 M(I) = DBLE(RAND())\n 999 RETURN\n END SUBROUTINE MRND1\n************************************************************************\n* MRND2: Matrix RaNDomize 2-D\n************************************************************************\n* Initialize matrix elements to a random value based on a two\n* dimensions. It matters not if the value is a 1, 2, N dimensional\n* array, as long as the product of ROWS X COLS does not overrun\n* the array.\n************************************************************************\n* M * Matrix to be initialized\n* ROWS * Rows (index 1)\n* COLS * Columns (index 2)\n* SEED * Seed for random number generator\n************************************************************************\n SUBROUTINE MRND2(M,ROWS,COLS,SEED)\n IMPLICIT NONE\n DOUBLE PRECISION M(ROWS,COLS)\n INTEGER COLS,ROWS,SEED\n INTEGER I,J\n CALL SRAND(SEED)\n DO 110 I = 1,ROWS\n DO 110 J = 1,COLS\n 110 M(I,J) = DBLE(RAND())\n 999 RETURN\n END SUBROUTINE MRND2\n************************************************************************\n* MGJAUS: Matrix GAUSs-Jordan elimination\n************************************************************************\n* M : Matrix\n* ROWS : Number of rows\n* COLS : Number of columns\n************************************************************************\n* Consider the matrix below representing the system of equations:\n*\n* [A]*[x] = B\n*\n* | A11 A12 A13 A14 A15 B16 B17 |\n* | A21 A22 A23 A24 A25 B26 B27 |\n* | A31 A32 A33 A34 A35 B36 B37 |\n* | A41 A42 A43 A44 A45 B46 B47 |\n* | A51 A52 A53 A54 A55 B56 B57 |\n*\n* This procedure performs Gauss-Jordan elimination with repeated calls\n* to MGJECOL to zero out non-diagonal elements, and normalize to 1.0 \n* resulting in the following:\n*\n* | 1.0 0.0 0.0 0.0 0.0 X16 X17 |\n* | 0.0 1.0 0.0 0.0 0.0 X26 X27 |\n* | 0.0 0.0 1.0 0.0 0.0 X36 X37 |\n* | 0.0 0.0 0.0 1.0 0.0 X46 X47 |\n* | 0.0 0.0 0.0 0.0 1.0 X56 X57 |\n*\n* X values are where the solution matrix is stored.\n*\n************************************************************************\n SUBROUTINE MGAUSJ(M, ROWS, COLS)\n IMPLICIT NONE\n DOUBLE PRECISION M(ROWS,COLS),TMP\n INTEGER ROWS, COLS\n INTEGER I,J\n*\n IF (ROWS.GT.COLS) THEN\n WRITE(0,910), ROWS, COLS\n STOP\n END IF\n*\n DO 110 I = 1, ROWS\n CALL MPPVT(M,ROWS,COLS,I)\n CALL MGJECOL(M,ROWS,COLS,I)\n TMP = M(I,I)\n DO 110 J = I, COLS\n M(I,J) = M(I,J) / TMP\n 110 CONTINUE\n*\n 910 FORMAT('*** FATAL ERRROR: MGAUSJ: MATRIX ROWS LARGER THAN'\n 1' COLUMNS',/,18X,I8, ' .GT. ',I8)\n 999 RETURN\n END SUBROUTINE\n************************************************************************\n* MGAUSB: Matrix GAUSs elimination with Back substitution\n************************************************************************\n* M : Matrix\n* ROWS : Number of rows\n* COLS : Number of columns\n************************************************************************\n* Consider the matrix below representing the system of equations:\n*\n* [A]*[x] = B\n*\n* | A11 A12 A13 A14 A15 B16 B17 |\n* | A21 A22 A23 A24 A25 B26 B27 |\n* | A31 A32 A33 A34 A35 B36 B37 |\n* | A41 A42 A43 A44 A45 B46 B47 |\n* | A51 A52 A53 A54 A55 B56 B57 |\n*\n* This procedure performs Gauss elimination with repeated calls\n* to MGECOL leave an upper triangle matrix. Junk values are left in\n* place below the diagonal to save operations. This results in the\n* following:\n*\n* | A11 A12 A13 A14 A15 B16 B17 |\n* | JNK A22 A23 A24 A25 B26 B27 |\n* | JNK JNK A33 A34 A35 B36 B37 |\n* | JNK JNK JNK A44 A45 B46 B47 |\n* | JNK JNK JNK JNK A55 B56 B57 |\n*\n* The final step is to perform back substitution callin MBSUB resulting\n* in the following:\n*\n* | A11 A12 A13 A14 A15 X16 X17 |\n* | JNK A22 A23 A24 A25 X26 X27 |\n* | JNK JNK A33 A34 A35 X36 X37 |\n* | JNK JNK JNK A44 A45 X46 X47 |\n* | JNK JNK JNK JNK A55 X56 X57 |\n*\n* X values are where the solution matrix is stored.\n*\n************************************************************************\n SUBROUTINE MGAUSB(M, ROWS, COLS)\n IMPLICIT NONE\n DOUBLE PRECISION M(ROWS,COLS)\n INTEGER ROWS, COLS\n INTEGER I\n*\n IF (ROWS.GT.COLS) THEN\n WRITE(0,910), ROWS, COLS\n STOP\n END IF\n*\n CALL MGAUS(M,ROWS,COLS)\n CALL MBSUB(M,ROWS,COLS)\n*\n 910 FORMAT('*** FATAL ERRROR: MGAUSB: MATRIX ROWS LARGER THAN'\n 1' COLUMNS',/,18X,I8, ' .GT. ',I8)\n 999 RETURN\n END SUBROUTINE\n************************************************************************\n* MGAUS: Matrix GAUSs elimination\n************************************************************************\n* M : Matrix\n* ROWS : Number of rows\n* COLS : Number of columns\n************************************************************************\n* Consider the matrix below representing the system of equations:\n*\n* [A]*[x] = B\n*\n* | A11 A12 A13 A14 A15 B16 B17 |\n* | A21 A22 A23 A24 A25 B26 B27 |\n* | A31 A32 A33 A34 A35 B36 B37 |\n* | A41 A42 A43 A44 A45 B46 B47 |\n* | A51 A52 A53 A54 A55 B56 B57 |\n*\n* This procedure performs Gauss elimination with repeated calls\n* to MGECOL leave an upper triangle matrix. Junk values are left in\n* place below the diagonal to save operations. This results in the\n* following:\n*\n* | A11 A12 A13 A14 A15 B16 B17 |\n* | JNK A22 A23 A24 A25 B26 B27 |\n* | JNK JNK A33 A34 A35 B36 B37 |\n* | JNK JNK JNK A44 A45 B46 B47 |\n* | JNK JNK JNK JNK A55 B56 B57 |\n*\n************************************************************************\n SUBROUTINE MGAUS(M, ROWS, COLS)\n IMPLICIT NONE\n DOUBLE PRECISION M(ROWS,COLS)\n INTEGER ROWS, COLS\n INTEGER I\n*\n IF (ROWS.GT.COLS) THEN\n WRITE(0,910), ROWS, COLS\n STOP\n END IF\n*\n DO 110 I = 1, ROWS\n CALL MPPVT(M,ROWS,COLS,I)\n 110 CALL MGECOL(M,ROWS,COLS,I)\n*\n 910 FORMAT('*** FATAL ERRROR: MGAUS: MATRIX ROWS LARGER THAN'\n 1' COLUMNS',/,18X,I8, ' .GT. ',I8)\n 999 RETURN\n END SUBROUTINE\n************************************************************************\n* MPPVT: Matrix Partial PiVoT\n************************************************************************\n SUBROUTINE MPPVT(M,ROWS,COLS,ROW)\n IMPLICIT NONE\n DOUBLE PRECISION M(ROWS,COLS)\n INTEGER COLS,ROWS,ROW\n INTEGER J,K\n DOUBLE PRECISION TOL,TMP\n PARAMETER (TOL=1.0D-12)\n*\n IF (ABS(M(ROW,ROW)).LE.TOL) THEN\n DO 110 J = ROW+1, ROWS\n 110 IF (ABS(M(J,ROW)).GE.TOL) EXIT\n DO 120 K = ROW,COLS\n TMP = M(ROW,K)\n M(ROW,K) = M(J,K)\n 120 M(J,K) = TMP\n END IF\n 999 RETURN\n END SUBROUTINE MPPVT\n************************************************************************\n* MGJECOL: Matrix Gauss-Jordan Eliminate COLumn\n************************************************************************\n* Performs Gauss elimination on a particular column. This procedure is\n* called multiple times to columns for Gauss-Jordan elimination.\n* Consider the following matrix:\n* \n* | A11 A12 A13 A14 A15 A16 A17 |\n* | 0.0 A22 A23 A24 A25 A26 A27 |\n* | 0.0 A32 A33 A34 A35 A36 A37 |\n* | 0.0 A42 A43 A44 A45 A46 A47 |\n* | 0.0 A52 A53 A54 A55 A56 A57 |\n*\n*\n* Column 2 is the next to be zeroed. This is done by repeated calls\n* to MGJEROW. The result is the following:\n*\n* | A11 0.0 A13 A14 A15 A16 A17 |\n* | 0.0 A22 A23 A24 A25 A26 A27 |\n* | 0.0 0.0 A33 A34 A35 A36 A37 |\n* | 0.0 0.0 A43 A44 A45 A46 A47 |\n* | 0.0 0.0 A53 A54 A55 A56 A57 |\n*\n* Note: This procedure calls MGJEROW for every row in the matrix. \n* Repeated calls, result in a matrix with non-zero values only on\n* the diagonal. This is less efficient that elimination resulting\n* in a upper diagonal matrix to be used for backward substitution.\n*\n************************************************************************\n* M : Matrix\n* ROWS : Matrix rows\n* COLS : Matrix columns\n* COL : Associated column to be zeroed for elimination.\n************************************************************************\n SUBROUTINE MGJECOL(M,ROWS,COLS,COL)\n IMPLICIT NONE\n DOUBLE PRECISION M(ROWS,COLS)\n INTEGER ROWS,COLS,COL\n INTEGER J\n*\n DO 110 J = 1, ROWS\n 110 IF (J.NE.COL) CALL MGEROW(M,ROWS,COLS,J,COL,1)\n 999 RETURN\n END SUBROUTINE MGJECOL\n************************************************************************\n* MGECOL: Matrix Gauss Eliminate COLumn\n************************************************************************\n* Performs Gauss elimination on a particular column. This procedure is\n* called multiple times to columns for Gauss-Jordan elimination.\n* Consider the following matrix:\n* \n* | A11 A12 A13 A14 A15 A16 A17 |\n* | JNK A22 A23 A24 A25 A26 A27 |\n* | JNK A32 A33 A34 A35 A36 A37 |\n* | JNK A42 A43 A44 A45 A46 A47 |\n* | JNK A52 A53 A54 A55 A56 A57 |\n*\n*\n* Column 2 is the next to be 'zeroed'. This is done by repeated calls\n* to MGEROW with SCOL=COL+1. The result is the following:\n*\n* | A11 A12 A13 A14 A15 A16 A17 |\n* | JNK A22 A23 A24 A25 A26 A27 |\n* | JNK JNK A33 A34 A35 A36 A37 |\n* | JNK JNK A43 A44 A45 A46 A47 |\n* | JNK JNK A53 A54 A55 A56 A57 |\n*\n* Note: This procedure calls MGEROW for rows below the diagonal at\n* the particular column in the matrix. \n*\n* Repeated calls, result in a matrix with junk (JNK) values below\n* the diagonal and actuals values on and above the diagonal. The\n* junk values are left in place to save operations for large systems.\n*\n************************************************************************\n* M : Matrix\n* ROWS : Matrix rows\n* COLS : Matrix columns\n* COL : Associated column to be zeroed for elimination.\n************************************************************************\n SUBROUTINE MGECOL(M,ROWS,COLS,COL)\n IMPLICIT NONE\n DOUBLE PRECISION M(ROWS,COLS)\n INTEGER ROWS,COLS,COL\n INTEGER J\n*\n DO 110 J = COL+1, ROWS\n 110 CALL MGEROW(M,ROWS,COLS,J,COL,COL+1)\n 999 RETURN\n END SUBROUTINE MGECOL\n************************************************************************\n* MGJEROW: Matrix Gauss-Jordan Eliminate ROW\n************************************************************************\n* Performs Gauss elimination on a particular row. This procedure is\n* called multiple times to eliminate a particular column. Consider\n* the following matrix:\n* \n* | A11 A12 A13 A14 A15 A16 A17 |\n* | 0.0 A22 A23 A24 A25 A26 A27 |\n* | 0.0 A32 A33 A34 A35 A36 A37 |\n* | 0.0 A42 A43 A44 A45 A46 A47 |\n* | 0.0 A52 A53 A54 A55 A56 A57 |\n*\n* Row 3, column 2 is the next to be zeroed. This is done by\n* subtracting a scaled row 2 from row 3. Scale factor RATIO is\n* calculated by:\n* \n* RATIO = A32 / A22\n*\n* This ratio is chosen so that the result at row 3, column 2 will\n* calculate to zero.\n* \n* A32 = A32 - A22 * A32 / A22 (Results in 0.0)\n* A33 = A33 - A23 * A32 / A22\n* A34 = A34 - A24 * A32 / A22\n* A35 = A35 - A25 * A32 / A22\n* A36 = A36 - A26 * A32 / A22\n* A37 = A37 - A27 * A32 / A22\n*\n* The resulting state of the matrix after this procedure is:\n*\n* | A11 A12 A13 A14 A15 A16 A17 |\n* | 0.0 A22 A23 A24 A25 A26 A27 |\n* | 0.0 0.0 A33 A34 A35 A36 A37 |\n* | 0.0 A42 A43 A44 A45 A46 A47 |\n* | 0.0 A52 A53 A54 A55 A56 A57 |\n*\n* Note: This procedure does not require that ROW .GT. COL. The\n* result is that in the above example, the same operation could be\n* performed on row 1 to zero out A12. This is useful if the\n* elimination is Gauss-Jordan where all elements not on the diagonal\n* are zeroed out.\n*\n* Additionally, this procedure is called with a starting column. To\n* save operations, the start column may be set to COL+1 when calling\n* and nothing will be done to the elements to the left of COL. This\n* is useful when reducing the matrix to a upper triangle matrix.\n*\n************************************************************************\n* M : Matrix\n* ROWS : Matrix rows\n* COLS : Matrix columns\n* ROW : Matrix row on which to perform elimination\n* COL : Associated column to be zeroed for elimination.\n* SCOL : Column to begin elimination\n************************************************************************\n SUBROUTINE MGEROW(M,ROWS,COLS,ROW,COL,SCOL)\n IMPLICIT NONE\n DOUBLE PRECISION M(ROWS,COLS)\n INTEGER ROWS,COLS,ROW,COL,SCOL\n DOUBLE PRECISION TOL,RATIO\n PARAMETER (TOL=1.0D-12)\n INTEGER I,J\n*\n IF (ABS(M(ROW,COL)).GE.TOL) THEN\n RATIO = M(ROW,COL) / M(COL,COL)\n DO 110 I = SCOL, COLS\n IF (I.EQ.COL) THEN\n*\n** By definition this location must be zero. Instead of doing the\n** calculation, just set the value to zero.\n*\n M(ROW,I) = 0D0\n ELSE\n M(ROW,I) = M(ROW,I) - RATIO * M(COL,I)\n ENDIF\n 110 CONTINUE\n ELSE\n M(ROW,COL) = 0D0\n END IF\n 999 RETURN\n END SUBROUTINE MGEROW\n************************************************************************\n* MBSUB: Matrix Back SUBstitution\n************************************************************************\n* Consider the reduced system.\n*\n* | A11 A12 A13 A14 A15 B16 B17 |\n* | JNK A22 A23 A24 A25 B26 B27 |\n* | JNK JNK A33 A34 A35 B36 B37 |\n* | JNK JNK JNK A44 A45 B46 B47 |\n* | JNK JNK JNK JNK A55 B56 B57 |\n* \n* JNK values are assumed to be 0.0. Recall that this is a set\n* of equations for each B column vector:\n*\n* A11*X16 + A12*X26 + A13*X36 + A14*X46 + A15*X56 = B16\n* A22*X26 + A23*X36 + A24*X46 + A25*X56 = B26\n* A33*X36 + A34*X46 + A35*X56 = B36\n* A44*X46 + A45*X56 = B46\n* A55*X56 = B56\n*\n* A11*X17 + A12*X27 + A13*X37 + A14*X47 + A15*X57 = B17\n* A22*X27 + A23*X37 + A24*X47 + A25*X57 = B27\n* A33*X37 + A34*X47 + A35*X57 = B37\n* A44*X47 + A45*X57 = B47\n* A55*X57 = B57\n*\n* These equations may be solved starting from the bottom:\n* \n* <------------- K --------------->\n* \n* | | X56 = (B56 ) / A55\n* | | X46 = (B46 - A45*X56 ) / A44\n* | J X36 = (B36 - A34*X46 - A35*X56 ) / A33\n* | | X26 = (B26 - A23*X36 - A24*X46 - A25*X56 ) / A22\n* | v X16 = (B16 - A12*X26 - A13*X36 - A14*X46 - A15*X56) / A11\n* I\n* | | X57 = (B57 ) / A55\n* | | X47 = (B47 - A45*X57 ) / A44\n* | J X37 = (B37 - A34*X47 - A35*X57 ) / A33\n* | | X27 = (B27 - A23*X37 - A24*X47 - A25*X57 ) / A22\n* v v X17 = (B17 - A12*X27 - A13*X37 - A14*X47 - A15*X57) / A11\n*\n* The resulting aray has the solution vectors in place of the B\n* vectors.\n*\n* | A11 A12 A13 A14 A15 X16 X17 |\n* | JNK A22 A23 A24 A25 X26 X27 |\n* | JNK JNK A33 A34 A35 X36 X37 |\n* | JNK JNK JNK A44 A45 X46 X47 |\n* | JNK JNK JNK JNK A55 X56 X57 |\n*\n************************************************************************\n* M : Matrix\n* ROWS : Matrix rows\n* COLS : Matrix columns\n************************************************************************\n SUBROUTINE MBSUB(M,ROWS,COLS)\n IMPLICIT NONE\n DOUBLE PRECISION M(ROWS,COLS)\n INTEGER ROWS,COLS\n INTEGER I,J,K\n DOUBLE PRECISION SUM\n*\n DO 110 I = ROWS+1, COLS\n DO 110 J = ROWS, 1, -1\n SUM = 0D0\n DO 120 K = ROWS, J+1, -1\n 120 SUM = SUM + M(J,K) * M(K,I)\n 110 M(J,I) = (M(J,I) - SUM) / M(J,J)\n 999 RETURN\n END SUBROUTINE MBSUB\n************************************************************************\n* MMUL: Matrix Multipliction\n************************************************************************\n* Product of [A]*[B] is placed in P.\n************************************************************************\n* A : Matrix A\n* AROWS : Rows of A\n* ACOLS : Cols of A (Must match BROWS)\n* B : Matrix B\n* BROWS : Rows of B (Must match ACOLS)\n* BCOLS : Cols of B\n* P : Matrix P (product: [P] = [A] * [B])\n* PROWS : Rows of P (Must be .GE. AROWS)\n* PCOLS : Cols of P (Must be .GE. BCOLS)\n************************************************************************\n*\n* [A] * [B] = [P]\n*\n* | A11 A12 | | B11 B12 B13 B14 | | P11 P12 P13 P14 |\n* | A21 A22 | * | B21 B22 B23 B12 | = | P21 P22 P23 P24 |\n* | A31 A32 | | P31 P32 P33 P34 |\n*\n*\n* <-------- K -------->\n*\n* P11 = A11 * B11 + A12 * B21 ^ ^\n* P21 = A21 * B11 + A22 * B21 I |\n* P31 = A31 * B11 + A32 * B21 v |\n* |\n* P12 = A11 * B12 + A12 * B22 ^ |\n* P22 = A21 * B12 + A22 * B22 I |\n* P32 = A31 * B12 + A32 * B22 v \n* J\n* P13 = A11 * B13 + A12 * B23 ^ \n* P23 = A21 * B13 + A22 * B23 I |\n* P33 = A31 * B13 + A32 * B23 v |\n* |\n* P14 = A11 * B14 + A12 * B24 ^ |\n* P24 = A21 * B14 + A22 * B24 I |\n* P34 = A31 * B14 + A32 * B24 v v\n*\n************************************************************************\n SUBROUTINE MMUL(A,AROWS,ACOLS,B,BROWS,BCOLS,P,PROWS,PCOLS)\n IMPLICIT NONE\n DOUBLE PRECISION A(AROWS,ACOLS), B(BROWS,BCOLS), P(PROWS,PCOLS)\n INTEGER AROWS, ACOLS, BROWS, BCOLS, PSIZE, PROWS, PCOLS\n INTEGER I, J, K\n DOUBLE PRECISION SUM\n*\n IF (ACOLS.NE.BROWS) THEN\n WRITE(0,910) ACOLS, BROWS\n STOP\n END IF\n IF (PROWS.LT.AROWS) THEN\n WRITE(0,920) PROWS, AROWS\n STOP\n END IF\n IF (PCOLS.LT.BCOLS) THEN\n WRITE(0,930) PCOLS, BCOLS\n STOP\n END IF\n*\n DO 10 I = 1, PROWS\n DO 10 J = 1, PCOLS\n SUM = 0D0\n DO 20 K = 1, ACOLS\n 20 SUM = SUM + A(I,K) * B(K,J)\n 10 P(I,J) = SUM\n*\n 910 FORMAT('*** FATAL ERRROR: MMUL: MATRIX A COLUMNS MUST MATCH'\n 1' MATRIX B ROWS:',/,18X,I8, ' .NE. ', I8)\n 920 FORMAT('*** FATAL ERRROR: MMUL: MATRIX P ROWS MUST AT LEAST'\n 1' EQUAL MATRIX A ROWS:',/,18X,I8, ' .LT. ', I8)\n 930 FORMAT('*** FATAL ERRROR: MMUL: MATRIX P COLUMNS MUST AT LEAST'\n 1' EQUAL MATRIX B COLUMNS:',/,18X,I8, ' .LT. ', I8)\n 999 RETURN\n END SUBROUTINE MMUL\n************************************************************************\n* MIPADD: Matrix In-Place ADDition\n************************************************************************\n SUBROUTINE MIPADD(A,AROWS,ACOLS,B,BROWS,BCOLS)\n IMPLICIT NONE\n DOUBLE PRECISION A(AROWS,ACOLS),B(BROWS,BCOLS)\n INTEGER AROWS,ACOLS,BROWS,BCOLS\n INTEGER I,J\n*\n DO 110 I = 1, MIN(AROWS,BROWS)\n DO 110 J = 1, MIN(ACOLS,BCOLS)\n 110 A(I,J) = A(I,J) + B(I,J)\n 999 RETURN\n END SUBROUTINE MIPADD\n************************************************************************\n* MIPSUB: Matrix In-Place SUBtraction\n************************************************************************\n SUBROUTINE MIPSUB(A,AROWS,ACOLS,B,BROWS,BCOLS)\n IMPLICIT NONE\n DOUBLE PRECISION A(AROWS,ACOLS),B(BROWS,BCOLS)\n INTEGER AROWS,ACOLS,BROWS,BCOLS\n INTEGER I,J\n*\n DO 110 I = 1, MIN(AROWS,BROWS)\n DO 110 J = 1, MIN(ACOLS,BCOLS)\n 110 A(I,J) = A(I,J) + B(I,J)\n 999 RETURN\n END SUBROUTINE MIPSUB\n************************************************************************\n* MPRT: Matrix PRinT\n************************************************************************\n SUBROUTINE MPRT(M,ROWS,COLS)\n IMPLICIT NONE\n DOUBLE PRECISION M(ROWS,COLS)\n INTEGER ROWS, COLS\n INTEGER I, J\n CHARACTER F*9\n*\n WRITE(F,'(A1I2A6)') '(', COLS, 'F10.4)'\n DO 10 I = 1, ROWS\n 10 WRITE(6,F) (M(I,J), J=1, COLS)\n 999 RETURN\n END SUBROUTINE MPRT\n************************************************************************\n", "meta": {"hexsha": "4e08be6121b0e29e3d5e59129e8ac6921d3c7acf", "size": 30855, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "matrix.f", "max_stars_repo_name": "AeroDME/octo-spork", "max_stars_repo_head_hexsha": "a90604b430a140f188bd4489d0c4b10bf8fb6f8a", "max_stars_repo_licenses": ["MIT"], "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.f", "max_issues_repo_name": "AeroDME/octo-spork", "max_issues_repo_head_hexsha": "a90604b430a140f188bd4489d0c4b10bf8fb6f8a", "max_issues_repo_licenses": ["MIT"], "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.f", "max_forks_repo_name": "AeroDME/octo-spork", "max_forks_repo_head_hexsha": "a90604b430a140f188bd4489d0c4b10bf8fb6f8a", "max_forks_repo_licenses": ["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.9520958084, "max_line_length": 72, "alphanum_fraction": 0.4722411279, "num_tokens": 8789, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357735451834, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6595113223372971}} {"text": "module mod_monolis_c2d4_shape\n use mod_monolis_prm\n use mod_monolis_shape_util\n implicit none\n\n private\n\n real(kdouble), parameter :: gsp(2,4) = reshape([ &\n -0.577350269189626d0,-0.577350269189626d0, &\n 0.577350269189626d0,-0.577350269189626d0, &\n -0.577350269189626d0, 0.577350269189626d0, &\n 0.577350269189626d0, 0.577350269189626d0 &\n ], [2,4])\n\n real(kdouble), parameter :: np(2,4) = reshape([ &\n -1.0d0, -1.0d0, &\n 1.0d0, -1.0d0, &\n 1.0d0, 1.0d0, &\n -1.0d0, 1.0d0 &\n ], [2,4])\n\n public :: monolis_C2D4_num_gauss_point\n public :: monolis_C2D4_weight\n public :: monolis_C2D4_integral_point\n public :: monolis_C2D4_node_point\n public :: monolis_C2D4_shapefunc\n public :: monolis_C2D4_shapefunc_deriv\n public :: monolis_C2D4_get_global_position\n public :: monolis_C2D4_get_global_deriv\n\ncontains\n\n function monolis_C2D4_num_gauss_point()\n implicit none\n integer(kint) :: monolis_C2D4_num_gauss_point\n monolis_C2D4_num_gauss_point = 4\n end function monolis_C2D4_num_gauss_point\n\n function monolis_C2D4_weight(i)\n implicit none\n integer(kint), optional :: i\n real(kdouble) :: monolis_C2D4_weight\n monolis_C2D4_weight = 1.0d0\n end function monolis_C2D4_weight\n\n subroutine monolis_C2D4_integral_point(i, r)\n implicit none\n integer(kint) :: i\n real(kdouble) :: r(2)\n\n r(1) = gsp(1,i)\n r(2) = gsp(2,i)\n end subroutine monolis_C2D4_integral_point\n\n subroutine monolis_C2D4_node_point(i, r)\n implicit none\n integer(kint) :: i\n real(kdouble) :: r(2)\n\n r(1) = np(1,i)\n r(2) = np(2,i)\n end subroutine monolis_C2D4_node_point\n\n subroutine monolis_C2D4_get_global_position(node, r, pos)\n implicit none\n real(kdouble) :: node(3,4), r(2), pos(3)\n real(kdouble) :: func(4)\n\n call monolis_C2D4_shapefunc(r, func)\n pos = matmul(node, func)\n end subroutine monolis_C2D4_get_global_position\n\n subroutine monolis_C2D4_get_global_deriv(node, r, dndx, det)\n implicit none\n real(kdouble) :: node(2,4), r(2), dndx(4,2), deriv(4,2)\n real(kdouble) :: xj(2,2), inv(2,2), det\n\n call monolis_C2D4_shapefunc_deriv(r, deriv)\n xj = matmul(node, deriv)\n call monolis_get_inverse_matrix_2d(xj, inv, det)\n dndx = matmul(deriv, inv)\n end subroutine monolis_C2D4_get_global_deriv\n\n subroutine monolis_C2D4_shapefunc(local, func)\n implicit none\n real(kdouble) :: local(2), func(4)\n\n func(1) = 0.25d0*(1.0d0-local(1))*(1.0d0-local(2))\n func(2) = 0.25d0*(1.0d0+local(1))*(1.0d0-local(2))\n func(3) = 0.25d0*(1.0d0+local(1))*(1.0d0+local(2))\n func(4) = 0.25d0*(1.0d0-local(1))*(1.0d0+local(2))\n end subroutine monolis_C2D4_shapefunc\n\n subroutine monolis_C2D4_shapefunc_deriv(local, func)\n implicit none\n real(kdouble) :: local(2), func(4,2)\n\n func(1,1) = -0.25d0*(1.0d0-local(2))\n func(2,1) = 0.25d0*(1.0d0-local(2))\n func(3,1) = 0.25d0*(1.0d0+local(2))\n func(4,1) = -0.25d0*(1.0d0+local(2))\n\n func(1,2) = -0.25d0*(1.0d0-local(1))\n func(2,2) = -0.25d0*(1.0d0+local(1))\n func(3,2) = 0.25d0*(1.0d0+local(1))\n func(4,2) = 0.25d0*(1.0d0-local(1))\n end subroutine monolis_C2D4_shapefunc_deriv\n\nend module mod_monolis_c2d4_shape\n", "meta": {"hexsha": "866176de3c4cd313a56dfbaf8c5251ca630e08fe", "size": 3210, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/shape/shape_C2D4.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_C2D4.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_C2D4.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.1818181818, "max_line_length": 62, "alphanum_fraction": 0.6744548287, "num_tokens": 1272, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736772, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6595113218148857}} {"text": "program test_var\n use stdlib_experimental_error, only: assert\n use stdlib_experimental_kinds, only: sp, dp, int32, int64\n use stdlib_experimental_stats, only: var\n implicit none\n\n\n real(sp), parameter :: sptol = 1000 * epsilon(1._sp)\n real(dp), parameter :: dptol = 1000 * epsilon(1._dp)\n\n integer(int32) :: i321(5) = [1, 2, 3, 4, 5]\n integer(int64) :: i641(5) = [1, 2, 3, 4, 5]\n\n integer(int32), allocatable :: i32(:,:), i323(:, :, :)\n integer(int64), allocatable :: i64(:,:), i643(:, :, :)\n\n real(sp) :: s1(5) = [1.0_sp, 2.0_sp, 3.0_sp, 4.0_sp, 5.0_sp]\n real(dp) :: d1(5) = [1.0_dp, 2.0_dp, 3.0_dp, 4.0_dp, 5.0_dp]\n\n real(sp), allocatable :: s(:, :), s3(:, :, :)\n real(dp), allocatable :: d3(:, :, :)\n real(dp) :: d(4, 3) = reshape([1._dp, 3._dp, 5._dp, 7._dp,&\n 2._dp, 4._dp, 6._dp, 8._dp,&\n 9._dp, 10._dp, 11._dp, 12._dp], [4, 3])\n\n\n complex(sp) :: cs1(5) = [ cmplx(0.57706_sp, 0.00000_sp),&\n cmplx(0.00000_sp, 1.44065_sp),&\n cmplx(1.26401_sp, 0.00000_sp),&\n cmplx(0.00000_sp, 0.88833_sp),&\n cmplx(1.14352_sp, 0.00000_sp)]\n complex(dp) :: cd1(5) = [ cmplx(0.57706_dp, 0.00000_dp),&\n cmplx(0.00000_dp, 1.44065_dp),&\n cmplx(1.26401_dp, 0.00000_dp),&\n cmplx(0.00000_dp, 0.88833_dp),&\n cmplx(1.14352_dp, 0.00000_dp)]\n complex(sp) :: cs(5,3)\n complex(dp) :: cd(5,3)\n\n\n !sp\n !1dim\n print*,' test_sp_1dim'\n call assert( abs(var(s1) - 2.5) < sptol)\n call assert( abs(var(s1, dim=1) - 2.5) < sptol)\n\n print*,' test_sp_1dim_mask'\n call assert( isnan(var(s1, .false.)))\n call assert( isnan(var(s1, 1, .false.)))\n\n print*,' test_sp_1dim_mask_array'\n call assert( abs(var(s1, s1 < 5) - 5./3.) < sptol)\n call assert( isnan((var(s1, s1 < 0.))))\n call assert( isnan((var(s1, s1 == 1.))))\n call assert( abs(var(s1, 1, s1 < 5) - 5./3.) < sptol)\n\n !2dim\n print*,' test_sp_2dim'\n s = d\n call assert( abs(var(s) - 13) < sptol)\n call assert( all( abs( var(s, 1) - [20. / 3., 20. / 3., 5. / 3.]) < sptol))\n call assert( all( abs( var(s, 2) - [19.0, 43. / 3., 31. / 3. , 7.0]) < sptol))\n\n print*,' test_sp_2dim_mask'\n call assert( isnan(var(s, .false.)))\n call assert( any(isnan(var(s, 1, .false.))))\n call assert( any(isnan(var(s, 2, .false.))))\n\n print*,' test_sp_2dim_mask_array'\n call assert( abs(var(s, s < 11) - 27.5 / 3.) < sptol)\n call assert( all( abs( var(s, 1, s < 11) - [20. / 3., 20. / 3., 0.5]) < sptol))\n call assert( all( abs( var(s, 2, s < 11) - [19.0, 43. / 3., 0.5 , 0.5]) < sptol))\n\n\n !3dim\n allocate(s3(size(s,1),size(s,2),3))\n s3(:,:,1)=s;\n s3(:,:,2)=s*2;\n s3(:,:,3)=s*4;\n\n print*,' test_sp_3dim'\n call assert( abs(var(s3) - 153.4) < sptol)\n call assert( all( abs( var(s3, 1) -&\n reshape([20. / 3., 20. / 3., 5. / 3.,&\n 4* 20. / 3., 4* 20. / 3., 4* 5. / 3.,&\n 16* 20. / 3., 16* 20. / 3., 16* 5. / 3.],&\n [size(s3,2), size(s3,3)]))&\n < sptol))\n call assert( all( abs( var(s3, 2) -&\n reshape([19.0, 43. / 3., 31. / 3. , 7.0,&\n 4* 19.0, 4* 43. / 3., 4* 31. / 3. , 4* 7.0,&\n 16* 19.0, 16* 43. / 3., 16* 31. / 3. , 16* 7.0],&\n [size(s3,1), size(s3,3)] ))&\n < sptol))\n call assert( all(abs( var(s3, 3) -&\n reshape([ 7./3., 21., 175./3.,&\n 343./3., 28./3., 112./3.,&\n 84., 448./3., 189.,&\n 700./3., 847./3., 336.], [size(s3,1), size(s3,2)] ))&\n < sptol))\n\n print*,' test_sp_3dim_mask'\n call assert( isnan(var(s3, .false.)))\n call assert( any(isnan(var(s3, 1, .false.))))\n call assert( any(isnan(var(s3, 2, .false.))))\n call assert( any(isnan(var(s3, 3, .false.))))\n\n print*,' test_sp_3dim_mask_array'\n call assert( abs(var(s3, s3 < 11) - 8.2205877_sp) < sptol)\n call assert( all( abs( var(s3, 1, s3 < 45) -&\n reshape([20./3., 20./3., 5./3., 80./3., 80./3., 20./3.,&\n 320./3., 320./3., 16.],&\n [size(s3, 2), size(s3, 3)])) < sptol ))\n call assert( any( isnan( var(s3, 2, s3 < 25))))\n call assert( all( abs( var(s3, 3, s3 < 25) -&\n reshape([ 7./3., 21., 175./3.,&\n 24.5, 28./3., 112./3.,&\n 84., 32., 40.5,&\n 50., 60.5, 72.], [size(s3,1), size(s3,2)] ))&\n < sptol ))\n\n\n !dp\n !1dim\n print*,' test_dp_1dim'\n call assert( abs(var(d1) - 2.5) < dptol)\n call assert( abs(var(d1, 1) - 2.5) < dptol)\n\n print*,' test_dp_1dim_mask'\n call assert( isnan(var(d1, .false.)))\n call assert( isnan(var(d1, 1, .false.)))\n\n print*,' test_dp_1dim_mask_array'\n call assert( abs(var(d1, d1 < 5) - 5._dp/3._dp) < dptol)\n call assert( isnan((var(d1, d1 < 0.))))\n call assert( isnan((var(d1, d1 == 1.))))\n call assert( abs(var(d1, 1, d1 < 5) - 5._dp/3._dp) < dptol)\n\n !2dim\n print*,' test_dp_2dim'\n call assert( abs(var(d) - 13) < dptol)\n call assert( all( abs( var(d,1) -&\n [20._dp/3._dp, 20._dp/3._dp, 5._dp/3._dp]) < dptol))\n call assert( all( abs( var(d,2) -&\n [19.0_dp, 43._dp/3._dp, 31._dp/3._dp, 7.0_dp]) < dptol))\n\n print*,' test_dp_2dim_mask'\n call assert( isnan(var(d, .false.)))\n call assert( any(isnan(var(d, 1, .false.))))\n call assert( any(isnan(var(d, 2, .false.))))\n\n print*,' test_dp_2dim_mask_array'\n call assert( abs(var(d, d < 11) - 27.5_dp / 3._dp) < dptol)\n call assert( all( abs( var(d, 1, d < 11) -&\n [20._dp / 3._dp, 20._dp / 3._dp, 0.5_dp]) < dptol))\n call assert( all( abs( var(d, 2, d < 11) -&\n [19.0_dp, 43._dp / 3._dp, 0.5_dp, 0.5_dp]) < dptol))\n\n !3dim\n allocate(d3(size(d,1),size(d,2),3))\n d3(:,:,1)=d;\n d3(:,:,2)=d*2;\n d3(:,:,3)=d*4;\n\n print*,' test_dp_3dim'\n call assert( abs(var(d3) - 153.4_dp) < dptol)\n call assert( all( abs( var(d3, 1) -&\n reshape([20._dp / 3._dp, 20._dp / 3._dp, 5._dp / 3._dp,&\n 4* 20._dp / 3._dp, 4* 20._dp / 3._dp, 4* 5._dp / 3._dp,&\n 16* 20._dp / 3._dp, 16* 20._dp / 3._dp, 16* 5._dp / 3._dp],&\n [size(d3,2), size(d3,3)]))&\n < dptol))\n print*,' test_dp_3dim'\n call assert( all( abs( var(d3, 2) -&\n reshape([19.0_dp, 43._dp / 3._dp, 31._dp / 3._dp , 7.0_dp,&\n 4* 19.0_dp, 4* 43._dp / 3._dp, 4* 31._dp / 3._dp , 4* 7.0_dp,&\n 16* 19.0_dp, 16* 43._dp / 3._dp, 16* 31._dp / 3._dp ,&\n 16* 7.0_dp],&\n [size(d3,1), size(d3,3)] ))&\n < dptol))\n print*,' test_dp_3dim'\n call assert( all(abs( var(d3, 3) -&\n reshape([ 7._dp/3._dp, 21._dp, 175._dp/3._dp,&\n 343._dp/3._dp, 28._dp/3._dp, 112._dp/3._dp,&\n 84._dp, 448._dp/3._dp, 189._dp,&\n 700._dp/3._dp, 847._dp/3._dp, 336._dp],&\n [size(d3,1), size(d3,2)] ))&\n < dptol))\n\n print*,' test_dp_3dim_mask'\n call assert( isnan(var(d3, .false.)))\n call assert( any(isnan(var(d3, 1, .false.))))\n call assert( any(isnan(var(d3, 2, .false.))))\n call assert( any(isnan(var(d3, 3, .false.))))\n\n print*,' test_dp_3dim_mask_array'\n call assert( abs(var(d3, d3 < 25) - 46.041379310344823_dp) < dptol)\n call assert( all( abs( var(d3, 1, d3 < 45) -&\n reshape([20._dp/3._dp, 20._dp/3._dp, 5._dp/3._dp,&\n 80._dp/3._dp, 80._dp/3._dp, 20._dp/3._dp,&\n 320._dp/3._dp, 320._dp/3._dp, 16._dp],&\n [size(d3, 2), size(d3, 3)]))&\n < dptol ))\n call assert( any( isnan( var(d3, 2, d3 < 25))))\n call assert( all( abs( var(d3, 3, d3 < 25) -&\n reshape([ 7._dp/3._dp, 21._dp, 175._dp/3._dp,&\n 24.5_dp, 28._dp/3._dp, 112._dp/3._dp,&\n 84._dp, 32._dp, 40.5_dp,&\n 50._dp, 60.5_dp, 72._dp],&\n [size(d3,1), size(d3,2)] ))&\n < dptol ))\n\n\n\n !int32\n !1dim\n print*,' test_int32_1dim'\n call assert( abs(var(i321) - 2.5) < dptol)\n call assert( abs(var(i321, 1) - 2.5) < dptol)\n\n print*,' test_int32_1dim_mask'\n call assert( isnan(var(i321, .false.)))\n call assert( isnan(var(i321, 1, .false.)))\n\n print*,' test_int32_1dim_mask_array'\n call assert( abs(var(i321, i321 < 5) - 5._dp/3._dp) < dptol)\n call assert( isnan((var(i321, i321 < 0))))\n call assert( isnan((var(i321, i321 == 1))))\n call assert( abs(var(i321, 1, i321 < 5) - 5._dp/3._dp) < dptol)\n\n !2dim\n print*,' test_int32_2dim'\n i32 = d\n call assert( abs(var(i32) - 13) < dptol)\n call assert( all( abs( var(i32,1) -&\n [20._dp/3._dp, 20._dp/3._dp, 5._dp/3._dp]) < dptol))\n call assert( all( abs( var(i32,2) -&\n [19.0_dp, 43._dp/3._dp, 31._dp/3._dp, 7.0_dp]) < dptol))\n\n print*,' test_int32_2dim_mask'\n call assert( isnan(var(i32, .false.)))\n call assert( any(isnan(var(i32, 1, .false.))))\n call assert( any(isnan(var(i32, 2, .false.))))\n\n print*,' test_int32_2dim_mask_array'\n call assert( abs(var(i32, i32 < 11) - 27.5_dp / 3._dp) < dptol)\n call assert( all( abs( var(i32, 1, i32 < 11) -&\n [20._dp / 3._dp, 20._dp / 3._dp, 0.5_dp]) < dptol))\n call assert( all( abs( var(i32, 2, i32 < 11) -&\n [19.0_dp, 43._dp / 3._dp, 0.5_dp, 0.5_dp]) < dptol))\n\n !3dim\n allocate(i323(size(d,1),size(d,2),3))\n i323(:,:,1)=d;\n i323(:,:,2)=d*2;\n i323(:,:,3)=d*4;\n\n print*,' test_int32_3dim'\n call assert( abs(var(i323) - 153.4_dp) < dptol)\n call assert( all( abs( var(i323, 1) -&\n reshape([20._dp / 3._dp, 20._dp / 3._dp, 5._dp / 3._dp,&\n 4* 20._dp / 3._dp, 4* 20._dp / 3._dp, 4* 5._dp / 3._dp,&\n 16* 20._dp / 3._dp, 16* 20._dp / 3._dp, 16* 5._dp / 3._dp],&\n [size(i323,2), size(i323,3)]))&\n < dptol))\n call assert( all( abs( var(i323, 2) -&\n reshape([19.0_dp, 43._dp / 3._dp, 31._dp / 3._dp , 7.0_dp,&\n 4* 19.0_dp, 4* 43._dp / 3._dp, 4* 31._dp / 3._dp , 4* 7.0_dp,&\n 16* 19.0_dp, 16* 43._dp / 3._dp, 16* 31._dp / 3._dp ,&\n 16* 7.0_dp],&\n [size(i323,1), size(i323,3)] ))&\n < dptol))\n call assert( all(abs( var(i323, 3) -&\n reshape([ 7._dp/3._dp, 21._dp, 175._dp/3._dp,&\n 343._dp/3._dp, 28._dp/3._dp, 112._dp/3._dp,&\n 84._dp, 448._dp/3._dp, 189._dp,&\n 700._dp/3._dp, 847._dp/3._dp, 336._dp],&\n [size(i323,1), size(i323,2)] ))&\n < dptol))\n\n print*,' test_int32_3dim_mask'\n call assert( isnan(var(i323, .false.)))\n call assert( any(isnan(var(i323, 1, .false.))))\n call assert( any(isnan(var(i323, 2, .false.))))\n call assert( any(isnan(var(i323, 3, .false.))))\n\n print*,' test_int32_3dim_mask_array'\n call assert( abs(var(i323, i323 < 25) - 46.041379310344823_dp) < dptol)\n call assert( all( abs( var(i323, 1, i323 < 45) -&\n reshape([20._dp/3._dp, 20._dp/3._dp, 5._dp/3._dp,&\n 80._dp/3._dp, 80._dp/3._dp, 20._dp/3._dp,&\n 320._dp/3._dp, 320._dp/3._dp, 16._dp],&\n [size(i323, 2), size(i323, 3)]))&\n < dptol ))\n call assert( any( isnan( var(i323, 2, i323 < 25))))\n call assert( all( abs( var(i323, 3, i323 < 25) -&\n reshape([ 7._dp/3._dp, 21._dp, 175._dp/3._dp,&\n 24.5_dp, 28._dp/3._dp, 112._dp/3._dp,&\n 84._dp, 32._dp, 40.5_dp,&\n 50._dp, 60.5_dp, 72._dp],&\n [size(i323,1), size(i323,2)] ))&\n < dptol ))\n\n\n !int64\n !1dim\n print*,' test_int64_1dim'\n call assert( abs(var(i641) - 2.5) < dptol)\n call assert( abs(var(i641, 1) - 2.5) < dptol)\n\n print*,' test_int64_1dim_mask'\n call assert( isnan(var(i641, .false.)))\n call assert( isnan(var(i641, 1, .false.)))\n\n print*,' test_int641_1dim_mask_array'\n call assert( abs(var(i641, i641 < 5) - 5._dp/3._dp) < dptol)\n call assert( isnan((var(i641, i641 < 0))))\n call assert( isnan((var(i641, i641 == 1))))\n call assert( abs(var(i641, 1, i641 < 5) - 5._dp/3._dp) < dptol)\n\n !2dim\n print*,' test_int64_2dim'\n i64 = d\n call assert( abs(var(i64) - 13) < dptol)\n call assert( all( abs( var(i64,1) -&\n [20._dp/3._dp, 20._dp/3._dp, 5._dp/3._dp]) < dptol))\n call assert( all( abs( var(i64,2) -&\n [19.0_dp, 43._dp/3._dp, 31._dp/3._dp, 7.0_dp]) < dptol))\n\n print*,' test_int64_2dim_mask'\n call assert( isnan(var(i64, .false.)))\n call assert( any(isnan(var(i64, 1, .false.))))\n call assert( any(isnan(var(i64, 2, .false.))))\n\n print*,' test_int64_2dim_mask_array'\n call assert( abs(var(i64, i64 < 11) - 27.5_dp / 3._dp) < dptol)\n call assert( all( abs( var(i64, 1, i64 < 11) -&\n [20._dp / 3._dp, 20._dp / 3._dp, 0.5_dp]) < dptol))\n call assert( all( abs( var(i64, 2, i64 < 11) -&\n [19.0_dp, 43._dp / 3._dp, 0.5_dp, 0.5_dp]) < dptol))\n\n !3dim\n allocate(i643(size(d,1),size(d,2),3))\n i643(:,:,1)=d;\n i643(:,:,2)=d*2;\n i643(:,:,3)=d*4;\n\n print*,' test_int32_3dim'\n call assert( abs(var(i643) - 153.4_dp) < dptol)\n call assert( all( abs( var(i643, 1) -&\n reshape([20._dp / 3._dp, 20._dp / 3._dp, 5._dp / 3._dp,&\n 4* 20._dp / 3._dp, 4* 20._dp / 3._dp, 4* 5._dp / 3._dp,&\n 16* 20._dp / 3._dp, 16* 20._dp / 3._dp, 16* 5._dp / 3._dp],&\n [size(i643,2), size(i643,3)]))&\n < dptol))\n call assert( all( abs( var(i643, 2) -&\n reshape([19.0_dp, 43._dp / 3._dp, 31._dp / 3._dp , 7.0_dp,&\n 4* 19.0_dp, 4* 43._dp / 3._dp, 4* 31._dp / 3._dp , 4* 7.0_dp,&\n 16* 19.0_dp, 16* 43._dp / 3._dp, 16* 31._dp / 3._dp ,&\n 16* 7.0_dp],&\n [size(i643,1), size(i643,3)] ))&\n < dptol))\n call assert( all(abs( var(i643, 3) -&\n reshape([ 7._dp/3._dp, 21._dp, 175._dp/3._dp,&\n 343._dp/3._dp, 28._dp/3._dp, 112._dp/3._dp,&\n 84._dp, 448._dp/3._dp, 189._dp,&\n 700._dp/3._dp, 847._dp/3._dp, 336._dp],&\n [size(i643,1), size(i643,2)] ))&\n < dptol))\n\n print*,' test_int32_3dim_mask'\n call assert( isnan(var(i643, .false.)))\n call assert( any(isnan(var(i643, 1, .false.))))\n call assert( any(isnan(var(i643, 2, .false.))))\n call assert( any(isnan(var(i643, 3, .false.))))\n\n print*,' test_int64_3dim_mask_array'\n call assert( abs(var(i643, i643 < 25) - 46.041379310344823_dp) < dptol)\n call assert( all( abs( var(i643, 1, i643 < 45) -&\n reshape([20._dp/3._dp, 20._dp/3._dp, 5._dp/3._dp,&\n 80._dp/3._dp, 80._dp/3._dp, 20._dp/3._dp,&\n 320._dp/3._dp, 320._dp/3._dp, 16._dp],&\n [size(i643, 2), size(i643, 3)]))&\n < dptol ))\n call assert( any( isnan( var(i643, 2, i643 < 25))))\n call assert( all( abs( var(i643, 3, i643 < 25) -&\n reshape([ 7._dp/3._dp, 21._dp, 175._dp/3._dp,&\n 24.5_dp, 28._dp/3._dp, 112._dp/3._dp,&\n 84._dp, 32._dp, 40.5_dp,&\n 50._dp, 60.5_dp, 72._dp],&\n [size(i643,1), size(i643,2)] ))&\n < dptol ))\n\n !csp\n !1dim\n print*,' test_csp_1dim'\n call assert( abs(var(cs1) - (var(real(cs1)) + var(aimag(cs1)))) < sptol)\n call assert( abs(var(cs1, dim=1) - (var(real(cs1),1) + var(aimag(cs1), 1)) ) < sptol)\n\n print*,' test_csp_1dim_mask'\n call assert( isnan(var(cs1, .false.)))\n call assert( isnan(var(cs1, 1, .false.)))\n\n print*,' test_csp_1dim_mask_array'\n call assert( abs(var(cs1, aimag(cs1) == 0) - var(real(cs1), aimag(cs1) == 0)) < sptol)\n call assert( abs(var(cs1, 1, aimag(cs1) == 0) - var(real(cs1), 1, aimag(cs1) == 0)) < sptol)\n\n !2dim\n cs(:,1) = cs1\n cs(:,2) = cs1*3_sp\n cs(:,3) = cs1*1.5_sp\n\n print*,' test_csp_2dim'\n call assert( abs(var(cs) - (var(real(cs)) + var(aimag(cs)))) < sptol)\n call assert( all( abs( var(cs, 1) - (var(real(cs), 1) + var(aimag(cs), 1))) < sptol))\n call assert( all( abs( var(cs, 2) - (var(real(cs), 2) + var(aimag(cs), 2))) < sptol))\n\n print*,' test_csp_2dim_mask'\n call assert( isnan(var(cs, .false.)))\n call assert( any(isnan(var(cs, 1, .false.))))\n call assert( any(isnan(var(cs, 2, .false.))))\n\n print*,' test_csp_2dim_mask_array'\n call assert( abs(var(cs, aimag(cs) == 0) - var(real(cs), aimag(cs) == 0)) < sptol)\n call assert( all( abs( var(cs, 1, aimag(cs) == 0) - var(real(cs), 1, aimag(cs) == 0)) < sptol))\n call assert( any( isnan( var(cs, 2, aimag(cs) == 0))))\n\n !cdp\n !1dim\n print*,' test_cdp_1dim'\n call assert( abs(var(cd1) - (var(real(cd1)) + var(aimag(cd1)))) < dptol)\n call assert( abs(var(cd1, dim=1) - (var(real(cd1),1) + var(aimag(cd1), 1)) ) < dptol)\n\n print*,' test_cdp_1dim_mask'\n call assert( isnan(var(cd1, .false.)))\n call assert( isnan(var(cd1, 1, .false.)))\n\n print*,' test_cdp_1dim_mask_array'\n call assert( abs(var(cd1, aimag(cd1) == 0) - var(real(cd1), aimag(cd1) == 0)) < dptol)\n call assert( abs(var(cd1, 1, aimag(cd1) == 0) - var(real(cd1), 1, aimag(cd1) == 0)) < dptol)\n\n !2dim\n cd(:,1) = cd1\n cd(:,2) = cd1*3_sp\n cd(:,3) = cd1*1.5_sp\n\n print*,' test_cdp_2dim'\n call assert( abs(var(cd) - (var(real(cd)) + var(aimag(cd)))) < dptol)\n call assert( all( abs( var(cd, 1) - (var(real(cd), 1) + var(aimag(cd), 1))) < dptol))\n call assert( all( abs( var(cd, 2) - (var(real(cd), 2) + var(aimag(cd), 2))) < dptol))\n\n print*,' test_cdp_2dim_mask'\n call assert( isnan(var(cd, .false.)))\n call assert( any(isnan(var(cd, 1, .false.))))\n call assert( any(isnan(var(cd, 2, .false.))))\n\n print*,' test_cdp_2dim_mask_array'\n call assert( abs(var(cd, aimag(cd) == 0) - var(real(cd), aimag(cd) == 0)) < dptol)\n call assert( all( abs( var(cd, 1, aimag(cd) == 0) - var(real(cd), 1, aimag(cd) == 0)) < dptol))\n call assert( any( isnan( var(cd, 2, aimag(cd) == 0))))\n\nend program\n", "meta": {"hexsha": "9651c72bcf5fb8c9e3ca62998b23d582f77f0704", "size": 19299, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/stats/test_var.f90", "max_stars_repo_name": "leonfoks/stdlib", "max_stars_repo_head_hexsha": "e258599ff585cba2f08568eb6a7364f1fb5d8723", "max_stars_repo_licenses": ["MIT"], "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/tests/stats/test_var.f90", "max_issues_repo_name": "leonfoks/stdlib", "max_issues_repo_head_hexsha": "e258599ff585cba2f08568eb6a7364f1fb5d8723", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/tests/stats/test_var.f90", "max_forks_repo_name": "leonfoks/stdlib", "max_forks_repo_head_hexsha": "e258599ff585cba2f08568eb6a7364f1fb5d8723", "max_forks_repo_licenses": ["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.6825053996, "max_line_length": 99, "alphanum_fraction": 0.4787294678, "num_tokens": 7606, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.867035752930664, "lm_q2_score": 0.7606506418255927, "lm_q1q2_score": 0.6595113019524457}} {"text": "C ===================================================\n SUBROUTINE GETDA (EE,EP,YJB,Q2JB,XDA,Q2DA,YDA,TH_E)\nC ===================================================\n\n IMPLICIT NONE\n\n REAL EE,EP,YJB,Q2JB,XDA,Q2DA,YDA,TH_E,A,B,COSG,G,SING,X0,\n & COSTH,SINTH,BETA,DELTA\n\n REAL NO_USE\n DATA NO_USE / -999.99 /\n\n A = Q2JB*(1.0-YJB)\n B = 4.0*(EE**2)*(YJB**2)\n\n IF ( (A+B).EQ.0 ) THEN\n YDA = NO_USE\n XDA = NO_USE\n Q2DA = NO_USE\n GOTO 100\n ENDIF\n\n COSG = (A-B)/(A+B)\n G = ACOS(COSG)\n SING = SIN(G)\n\n X0 = EE/EP\n COSTH = COS(TH_E)\n SINTH = SIN(TH_E)\n BETA = SING + SINTH - SIN(TH_E+G)\n DELTA = SING + SINTH + SIN(TH_E+G)\n\n IF (BETA.NE.0) THEN\n YDA = ( SINTH*(1-COSG) )/ BETA\n Q2DA = ( 4*(EE**2)*SING*(1+COSTH) )/ BETA\n XDA = (X0*DELTA) / BETA\n ELSE\n YDA = NO_USE\n XDA = NO_USE\n Q2DA = NO_USE\n ENDIF\n\n100 CONTINUE\n\n RETURN\n END\n\n\n", "meta": {"hexsha": "801cc3303f2fc5e4edbdc55dc791d4ec2efb45bd", "size": 1044, "ext": "fpp", "lang": "FORTRAN", "max_stars_repo_path": "data_preparation/src/analysis/getda.fpp", "max_stars_repo_name": "jscott7/ZEUS-Analysis", "max_stars_repo_head_hexsha": "ea60c084483706f1db38a2c23d36dc51d12237e6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "data_preparation/src/analysis/getda.fpp", "max_issues_repo_name": "jscott7/ZEUS-Analysis", "max_issues_repo_head_hexsha": "ea60c084483706f1db38a2c23d36dc51d12237e6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2022-02-22T19:14:44.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T19:09:58.000Z", "max_forks_repo_path": "data_preparation/src/analysis/getda.fpp", "max_forks_repo_name": "jscott7/ZEUS-Analysis", "max_forks_repo_head_hexsha": "ea60c084483706f1db38a2c23d36dc51d12237e6", "max_forks_repo_licenses": ["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.306122449, "max_line_length": 63, "alphanum_fraction": 0.4137931034, "num_tokens": 392, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951588871158, "lm_q2_score": 0.7057850278370112, "lm_q1q2_score": 0.6594821132259115}} {"text": "*DECK DBINT4\n SUBROUTINE DBINT4 (X, Y, NDATA, IBCL, IBCR, FBCL, FBCR, KNTOPT, T,\n + BCOEF, N, K, W)\nC***BEGIN PROLOGUE DBINT4\nC***PURPOSE Compute the B-representation of a cubic spline\nC which interpolates given data.\nC***LIBRARY SLATEC\nC***CATEGORY E1A\nC***TYPE DOUBLE PRECISION (BINT4-S, DBINT4-D)\nC***KEYWORDS B-SPLINE, CUBIC SPLINES, DATA FITTING, INTERPOLATION\nC***AUTHOR Amos, D. E., (SNLA)\nC***DESCRIPTION\nC\nC Abstract **** a double precision routine ****\nC\nC DBINT4 computes the B representation (T,BCOEF,N,K) of a\nC cubic spline (K=4) which interpolates data (X(I),Y(I)),\nC I=1,NDATA. Parameters IBCL, IBCR, FBCL, FBCR allow the\nC specification of the spline first or second derivative at\nC both X(1) and X(NDATA). When this data is not specified\nC by the problem, it is common practice to use a natural\nC spline by setting second derivatives at X(1) and X(NDATA)\nC to zero (IBCL=IBCR=2,FBCL=FBCR=0.0). The spline is defined\nC on T(4) .LE. X .LE. T(N+1) with (ordered) interior knots at\nC X(I) values where N=NDATA+2. The knots T(1),T(2),T(3) lie to\nC the left of T(4)=X(1) and the knots T(N+2), T(N+3), T(N+4)\nC lie to the right of T(N+1)=X(NDATA) in increasing order. If\nC no extrapolation outside (X(1),X(NDATA)) is anticipated, the\nC knots T(1)=T(2)=T(3)=T(4)=X(1) and T(N+2)=T(N+3)=T(N+4)=\nC T(N+1)=X(NDATA) can be specified by KNTOPT=1. KNTOPT=2\nC selects a knot placement for T(1), T(2), T(3) to make the\nC first 7 knots symmetric about T(4)=X(1) and similarly for\nC T(N+2), T(N+3), T(N+4) about T(N+1)=X(NDATA). KNTOPT=3\nC allows the user to make his own selection, in increasing\nC order, for T(1), T(2), T(3) to the left of X(1) and T(N+2),\nC T(N+3), T(N+4) to the right of X(NDATA) in the work array\nC W(1) through W(6). In any case, the interpolation on\nC T(4) .LE. X .LE. T(N+1) by using function DBVALU is unique\nC for given boundary conditions.\nC\nC Description of Arguments\nC\nC Input X,Y,FBCL,FBCR,W are double precision\nC X - X vector of abscissae of length NDATA, distinct\nC and in increasing order\nC Y - Y vector of ordinates of length NDATA\nC NDATA - number of data points, NDATA .GE. 2\nC IBCL - selection parameter for left boundary condition\nC IBCL = 1 constrain the first derivative at\nC X(1) to FBCL\nC = 2 constrain the second derivative at\nC X(1) to FBCL\nC IBCR - selection parameter for right boundary condition\nC IBCR = 1 constrain first derivative at\nC X(NDATA) to FBCR\nC IBCR = 2 constrain second derivative at\nC X(NDATA) to FBCR\nC FBCL - left boundary values governed by IBCL\nC FBCR - right boundary values governed by IBCR\nC KNTOPT - knot selection parameter\nC KNTOPT = 1 sets knot multiplicity at T(4) and\nC T(N+1) to 4\nC = 2 sets a symmetric placement of knots\nC about T(4) and T(N+1)\nC = 3 sets T(I)=W(I) and T(N+1+I)=W(3+I),I=1,3\nC where W(I),I=1,6 is supplied by the user\nC W - work array of dimension at least 5*(NDATA+2)\nC If KNTOPT=3, then W(1),W(2),W(3) are knot values to\nC the left of X(1) and W(4),W(5),W(6) are knot\nC values to the right of X(NDATA) in increasing\nC order to be supplied by the user\nC\nC Output T,BCOEF are double precision\nC T - knot array of length N+4\nC BCOEF - B spline coefficient array of length N\nC N - number of coefficients, N=NDATA+2\nC K - order of spline, K=4\nC\nC Error Conditions\nC Improper input is a fatal error\nC Singular system of equations is a fatal error\nC\nC***REFERENCES D. E. Amos, Computation with splines and B-splines,\nC Report SAND78-1968, Sandia Laboratories, March 1979.\nC Carl de Boor, Package for calculating with B-splines,\nC SIAM Journal on Numerical Analysis 14, 3 (June 1977),\nC pp. 441-472.\nC Carl de Boor, A Practical Guide to Splines, Applied\nC Mathematics Series 27, Springer-Verlag, New York,\nC 1978.\nC***ROUTINES CALLED D1MACH, DBNFAC, DBNSLV, DBSPVD, XERMSG\nC***REVISION HISTORY (YYMMDD)\nC 800901 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890531 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\nC 900326 Removed duplicate information from DESCRIPTION section.\nC (WRB)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE DBINT4\nC\n INTEGER I, IBCL, IBCR, IFLAG, ILB, ILEFT, IT, IUB, IW, IWP, J,\n 1 JW, K, KNTOPT, N, NDATA, NDM, NP, NWROW\n DOUBLE PRECISION BCOEF,FBCL,FBCR,T,TOL,TXN,TX1,VNIKX,W,WDTOL,\n 1 WORK,X,XL,Y\n DOUBLE PRECISION D1MACH\n DIMENSION X(*), Y(*), T(*), BCOEF(*), W(5,*), VNIKX(4,4), WORK(15)\nC***FIRST EXECUTABLE STATEMENT DBINT4\n WDTOL = D1MACH(4)\n TOL = SQRT(WDTOL)\n IF (NDATA.LT.2) GO TO 200\n NDM = NDATA - 1\n DO 10 I=1,NDM\n IF (X(I).GE.X(I+1)) GO TO 210\n 10 CONTINUE\n IF (IBCL.LT.1 .OR. IBCL.GT.2) GO TO 220\n IF (IBCR.LT.1 .OR. IBCR.GT.2) GO TO 230\n IF (KNTOPT.LT.1 .OR. KNTOPT.GT.3) GO TO 240\n K = 4\n N = NDATA + 2\n NP = N + 1\n DO 20 I=1,NDATA\n T(I+3) = X(I)\n 20 CONTINUE\n GO TO (30, 50, 90), KNTOPT\nC SET UP KNOT ARRAY WITH MULTIPLICITY 4 AT X(1) AND X(NDATA)\n 30 CONTINUE\n DO 40 I=1,3\n T(4-I) = X(1)\n T(NP+I) = X(NDATA)\n 40 CONTINUE\n GO TO 110\nC SET UP KNOT ARRAY WITH SYMMETRIC PLACEMENT ABOUT END POINTS\n 50 CONTINUE\n IF (NDATA.GT.3) GO TO 70\n XL = (X(NDATA)-X(1))/3.0D0\n DO 60 I=1,3\n T(4-I) = T(5-I) - XL\n T(NP+I) = T(NP+I-1) + XL\n 60 CONTINUE\n GO TO 110\n 70 CONTINUE\n TX1 = X(1) + X(1)\n TXN = X(NDATA) + X(NDATA)\n DO 80 I=1,3\n T(4-I) = TX1 - X(I+1)\n T(NP+I) = TXN - X(NDATA-I)\n 80 CONTINUE\n GO TO 110\nC SET UP KNOT ARRAY LESS THAN X(1) AND GREATER THAN X(NDATA) TO BE\nC SUPPLIED BY USER IN WORK LOCATIONS W(1) THROUGH W(6) WHEN KNTOPT=3\n 90 CONTINUE\n DO 100 I=1,3\n T(4-I) = W(4-I,1)\n JW = MAX(1,I-1)\n IW = MOD(I+2,5)+1\n T(NP+I) = W(IW,JW)\n IF (T(4-I).GT.T(5-I)) GO TO 250\n IF (T(NP+I).LT.T(NP+I-1)) GO TO 250\n 100 CONTINUE\n 110 CONTINUE\nC\n DO 130 I=1,5\n DO 120 J=1,N\n W(I,J) = 0.0D0\n 120 CONTINUE\n 130 CONTINUE\nC SET UP LEFT INTERPOLATION POINT AND LEFT BOUNDARY CONDITION FOR\nC RIGHT LIMITS\n IT = IBCL + 1\n CALL DBSPVD(T, K, IT, X(1), K, 4, VNIKX, WORK)\n IW = 0\n IF (ABS(VNIKX(3,1)).LT.TOL) IW = 1\n DO 140 J=1,3\n W(J+1,4-J) = VNIKX(4-J,IT)\n W(J,4-J) = VNIKX(4-J,1)\n 140 CONTINUE\n BCOEF(1) = Y(1)\n BCOEF(2) = FBCL\nC SET UP INTERPOLATION EQUATIONS FOR POINTS I=2 TO I=NDATA-1\n ILEFT = 4\n IF (NDM.LT.2) GO TO 170\n DO 160 I=2,NDM\n ILEFT = ILEFT + 1\n CALL DBSPVD(T, K, 1, X(I), ILEFT, 4, VNIKX, WORK)\n DO 150 J=1,3\n W(J+1,3+I-J) = VNIKX(4-J,1)\n 150 CONTINUE\n BCOEF(I+1) = Y(I)\n 160 CONTINUE\nC SET UP RIGHT INTERPOLATION POINT AND RIGHT BOUNDARY CONDITION FOR\nC LEFT LIMITS(ILEFT IS ASSOCIATED WITH T(N)=X(NDATA-1))\n 170 CONTINUE\n IT = IBCR + 1\n CALL DBSPVD(T, K, IT, X(NDATA), ILEFT, 4, VNIKX, WORK)\n JW = 0\n IF (ABS(VNIKX(2,1)).LT.TOL) JW = 1\n DO 180 J=1,3\n W(J+1,3+NDATA-J) = VNIKX(5-J,IT)\n W(J+2,3+NDATA-J) = VNIKX(5-J,1)\n 180 CONTINUE\n BCOEF(N-1) = FBCR\n BCOEF(N) = Y(NDATA)\nC SOLVE SYSTEM OF EQUATIONS\n ILB = 2 - JW\n IUB = 2 - IW\n NWROW = 5\n IWP = IW + 1\n CALL DBNFAC(W(IWP,1), NWROW, N, ILB, IUB, IFLAG)\n IF (IFLAG.EQ.2) GO TO 190\n CALL DBNSLV(W(IWP,1), NWROW, N, ILB, IUB, BCOEF)\n RETURN\nC\nC\n 190 CONTINUE\n CALL XERMSG ('SLATEC', 'DBINT4',\n + 'THE SYSTEM OF EQUATIONS IS SINGULAR', 2, 1)\n RETURN\n 200 CONTINUE\n CALL XERMSG ('SLATEC', 'DBINT4', 'NDATA IS LESS THAN 2', 2, 1)\n RETURN\n 210 CONTINUE\n CALL XERMSG ('SLATEC', 'DBINT4',\n + 'X VALUES ARE NOT DISTINCT OR NOT ORDERED', 2, 1)\n RETURN\n 220 CONTINUE\n CALL XERMSG ('SLATEC', 'DBINT4', 'IBCL IS NOT 1 OR 2', 2, 1)\n RETURN\n 230 CONTINUE\n CALL XERMSG ('SLATEC', 'DBINT4', 'IBCR IS NOT 1 OR 2', 2, 1)\n RETURN\n 240 CONTINUE\n CALL XERMSG ('SLATEC', 'DBINT4', 'KNTOPT IS NOT 1, 2, OR 3', 2,\n + 1)\n RETURN\n 250 CONTINUE\n CALL XERMSG ('SLATEC', 'DBINT4',\n + 'KNOT INPUT THROUGH W ARRAY IS NOT ORDERED PROPERLY', 2, 1)\n RETURN\n END\n", "meta": {"hexsha": "9e239dedf0bee0e5a982fda027306c9b201a3016", "size": 9349, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "external/SLATEC/src/dbint4.f", "max_stars_repo_name": "ygeorgi/MESS", "max_stars_repo_head_hexsha": "42db490295b08193dfc37496489467ccd2e5b6ae", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-02-09T05:03:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-26T10:20:02.000Z", "max_issues_repo_path": "external/SLATEC/src/dbint4.f", "max_issues_repo_name": "ygeorgi/MESS", "max_issues_repo_head_hexsha": "42db490295b08193dfc37496489467ccd2e5b6ae", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2020-04-28T17:09:50.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-01T16:24:43.000Z", "max_forks_repo_path": "external/SLATEC/src/dbint4.f", "max_forks_repo_name": "ygeorgi/MESS", "max_forks_repo_head_hexsha": "42db490295b08193dfc37496489467ccd2e5b6ae", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-06-22T07:53:00.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-10T19:59:53.000Z", "avg_line_length": 38.632231405, "max_line_length": 72, "alphanum_fraction": 0.5590972297, "num_tokens": 3421, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765257642906, "lm_q2_score": 0.7217432182679956, "lm_q1q2_score": 0.6594398361610403}} {"text": "program main\n use FEMSolverClass\n implicit none\n\n type(FEMSolver_) :: solver\n type(FEMDomain_),target :: domains(1)\n type(IO_) :: f\n integer(int32) :: i\n real(real64) :: Vs,t,dt,E_Al\n real(real64),allocatable :: Mode_U(:),mode_Ut(:),freq(:),eigen_value(:),eigen_vectors(:,:)\n integer(int32),allocatable :: node_list(:)\n integer(int32),allocatable :: node_list_x(:)\n integer(int32),allocatable :: node_list_y(:)\n integer(int32),allocatable :: node_list_z(:)\n ! Modal analysis\n !Create file or...\n call domains(1)%create(\"Cube3D\",x_num=2,y_num=4,z_num=20)\n call domains(1)%resize(x=1.0d0)\n call domains(1)%resize(y=5.0d0)\n call domains(1)%resize(z=50.0d0)\n call domains(1)%vtk(\"AlminiumBar\")\n \n !read file\n !call domains(1) % read(\"mesh.vtk\")\n \n call solver%init(NumDomain=1,NumInterfaceElement=0)\n call solver%setDomain(FEMDomain=domains(1),DomainID=1)\n call solver%setCRS(DOF=3)\n \n \n !$OMP parallel do\n do i=1,domains(1)%ne()\n call solver%setMatrix(&\n DomainID=1,&\n ElementID=i,&\n DOF=3,&\n Matrix=domains(1)%MassMatrix(ElementID=i,Density=2.70d0,DOF=3) &\n )\n enddo\n !$OMP end parallel do\n \n call solver%keepThisMatrixAs(\"B\")\n call solver%zeros()\n\n print *, \"Save Stiffness Matrix\"\n \n E_Al = 70.0d0*1000.0d0!*1000.0d0\n !$OMP parallel do\n do i=1,domains(1)%ne()\n call solver%setMatrix(&\n DomainID=1,&\n ElementID=i,&\n DOF=3,&\n Matrix=domains(1)%StiffnessMatrix(ElementID=i,E=E_Al,v=0.300d0) &\n )\n enddo\n !$OMP end parallel do\n\n call solver%keepThisMatrixAs(\"A\")\n \n ! Eigen value problem solver by scipy\n \n print *, \"solver%eig\"\n node_list = domains(1)%getNodeList(&\n zmin = domains(1)%zmax() )\n node_list_x =(node_list(:)-1)*3+1\n call solver%fix_eig(IDs=node_list_x)\n node_list_y =(node_list(:)-1)*3+2\n call solver%fix_eig(IDs=node_list_y)\n node_list_z =(node_list(:)-1)*3+3\n call solver%fix_eig(IDs=node_list_z)\n\n node_list = domains(1)%getNodeList(&\n zmax = domains(1)%zmin() )\n node_list_x =(node_list(:)-1)*3+1\n call solver%fix_eig(IDs=node_list_x)\n node_list_y =(node_list(:)-1)*3+2\n call solver%fix_eig(IDs=node_list_y)\n node_list_z =(node_list(:)-1)*3+3\n call solver%fix_eig(IDs=node_list_z)\n \n\n node_list = domains(1)%getNodeList(&\n ymax = domains(1)%ymin() )\n node_list_x =(node_list(:)-1)*3+1\n call solver%fix_eig(IDs=node_list_x)\n node_list_y =(node_list(:)-1)*3+2\n call solver%fix_eig(IDs=node_list_y)\n node_list_z =(node_list(:)-1)*3+3\n call solver%fix_eig(IDs=node_list_z)\n\n call solver%eig(eigen_value=eigen_value,eigen_vectors=eigen_vectors)\n \n ! read results\n freq = sqrt(abs(eigen_value))/2.0d0/3.141590d0\n dt = 0.10d0\n\n ! 20 modes\n do i_i=1,20\n mode_U = zeros(size(eigen_vectors,1))\n mode_U = eigen_vectors(:,i_i)\n dt = 1.0d0/freq(i_i)/100.0d0\n do j_j=1,100\n t = dt * dble(j_j-1)\n mode_Ut = mode_U*cos( 2.0d0*3.140d0*freq(i_i)*t )\n\n domains(1)%mesh%nodcoord = domains(1)%mesh%nodcoord &\n +10.0d0*reshape(mode_Ut,domains(1)%nn(),3 ) \n\n call domains(1)%vtk(\"Mode_Fortran_\"+str(i_i)+\"_t_\"+str(j_j))\n domains(1)%mesh%nodcoord = domains(1)%mesh%nodcoord &\n -10.0d0*reshape(mode_Ut,domains(1)%nn(),3 ) \n enddo\n enddo\n \n\n print *, \"Freq (Hz)\"\n call print(sqrt(abs(eigen_value(1:30)))/2.0d0/3.141590d0 )\n \nend program main\n", "meta": {"hexsha": "75b9d74a00aded42ae74fe7f4b26198b56d5fc5f", "size": 3635, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/fem/ModalAnalysis_FixBoundary.f90", "max_stars_repo_name": "kazulagi/plantFEM_binary", "max_stars_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-10T11:49:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-10T11:49:34.000Z", "max_issues_repo_path": "Tutorial/fem/ModalAnalysis_FixBoundary.f90", "max_issues_repo_name": "kazulagi/plantFEM_binary", "max_issues_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Tutorial/fem/ModalAnalysis_FixBoundary.f90", "max_forks_repo_name": "kazulagi/plantFEM_binary", "max_forks_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.041322314, "max_line_length": 94, "alphanum_fraction": 0.6055020633, "num_tokens": 1204, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765234137297, "lm_q2_score": 0.7217432062975979, "lm_q1q2_score": 0.6594398235274676}} {"text": "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC C\nC SUBROUTINE CALCULATING THE FINITE REAL PART OF THE C\nC GENERAL MASSIVE TWO POINT FUNCTION C\nC C\nC B02(P.P,M1,M2,MU**2) C\nC BP02(P.P,M1,M2,MU**2) C\nC C\nC LAST CHANGE: C\nC 24.02.99 [TP] : B02P CASES C\nC 28.05.01 [TP] : B(0,M,0) C\nC C\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n\nc ---------------------------------------------------------------------\n real*8 function B02(s,m1,m2,mu2)\n\n implicit none \n\n real*8 s,m1,m2,mu2,m12,m22 \n complex*16 zkappa,x1,x2 \n\n m12 = m1**2 \n m22 = m2**2 \n\n zkappa=sqrt(dcmplx(s**2+m12**2+m22**2\n & -2.D0*(s*m12+s*m22+m12*m22)))\n\n if (s.eq.0.D0) then\n if (m12.eq.m22) then\n B02=-log(m12/mu2) \n else\n if ((m12.ne.0.D0).and.(m22.ne.0.D0)) then \n B02=1.D0 - m12/(m12-m22)*log(m12/mu2)\n & + m22/(m12-m22)*log(m22/mu2) \n elseif (m12.eq.0.D0) then \n B02=1.D0 - log(m22/mu2)\n elseif (m22.eq.0.D0) then\n B02=1.D0 - log(m12/mu2)\n end if \n endif\n else \n if ((m12.eq.0.D0).and.(m22.eq.0.D0)) then \n B02=2.D0 - log(s/mu2)\n elseif ((m12.eq.s).and.(m22.eq.0.D0)) then \n B02=2.D0 - log(m12/mu2)\n elseif ((m22.eq.s).and.(m12.eq.0.D0)) then \n B02=2.D0 - log(m22/mu2)\n elseif (m12.eq.0.D0) then\n B02=2.D0 - (s-m22)/s*log( abs(m22-s)/m22 )\n & - log(m22/mu2)\n elseif (m22.eq.0.D0) then\n B02=2.D0 - (s-m12)/s*log( abs(m12-s)/m12 ) \n & - log(m12/mu2)\n else\n x1=dcmplx( (s-m22+m12+zkappa)/(2.D0*s) )\n x2=dcmplx( (s-m22+m12-zkappa)/(2.D0*s) )\n B02=real( 2.D0 + log(mu2/m22) \n & + x1*log(1.D0-1.D0/x1) \n & + x2*log(1.D0-1.D0/x2))\n endif\n endif \n\n return\n end\n\n\n\nc ---------------------------------------------------------------------\n real*8 function BP02(s,m1,m2,mu2)\n \n implicit none \n\n real*8 s,m1,m2,mu2,m12,m22 \n complex*16 zkappa,x1,x2\n \n m12 = m1**2\n m22 = m2**2 \n\n zkappa=sqrt(dcmplx(s**2+m12**2+m22**2\n & -2.D0*(s*m12+s*m22+m12*m22)))\n\n if (s.eq.0.D0) then\n if (m12.eq.m22) then\n BP02=1.D0/(6.D0*m12)\n else\n BP02=( (m12+m22)/2.D0 \n & - m12*m22/(m12-m22)*log(m12/m22) )/(m12-m22)**2 \n endif\n elseif ((s.eq.m12).and.(m22.eq.0.D0)) then \n BP02=( -1.D0 + log(m12/mu2)/2.D0 )/m12\n elseif ((s.eq.m22).and.(m12.eq.0.D0)) then \n BP02=( -1.D0 + log(m22/mu2)/2.D0 )/m22\n elseif ((m12.eq.0.D0).and.(m22.ne.0.D0)) then \n BP02=( -1.D0 - m22/s*log(abs(m22-s)/m22) )/s \n elseif ((m22.eq.0.D0).and.(m12.ne.0.D0)) then \n BP02=( -1.D0 - m12/s*log(abs(m12-s)/m12) )/s \n else \n x1=dcmplx( (s-m22+m12+zkappa)/(2.D0*s) )\n x2=dcmplx( (s-m22+m12-zkappa)/(2.D0*s) )\n BP02=real( -1.D0 + ( x1*(1.D0-x1)*log(1.D0-1.D0/x1)\n & - x2*(1.D0-x2)*log(1.D0-1.D0/x2) ) \n & /(x1-x2) )/s\n endif \n\n return\n end\n\n\n\n\n", "meta": {"hexsha": "41709e72f4a9d78fb69c5a4d74703650fc505fa4", "size": 3926, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "prospino/on_the_web_10_17_14/Pro2_integrals/Xtwopoint.f", "max_stars_repo_name": "sliem/docker-hep", "max_stars_repo_head_hexsha": "845de4c15e273cb68bc3a70a3bac1255474631be", "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": "prospino/on_the_web_10_17_14/Pro2_integrals/Xtwopoint.f", "max_issues_repo_name": "sliem/docker-hep", "max_issues_repo_head_hexsha": "845de4c15e273cb68bc3a70a3bac1255474631be", "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": "prospino/on_the_web_10_17_14/Pro2_integrals/Xtwopoint.f", "max_forks_repo_name": "sliem/docker-hep", "max_forks_repo_head_hexsha": "845de4c15e273cb68bc3a70a3bac1255474631be", "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.0535714286, "max_line_length": 71, "alphanum_fraction": 0.3841059603, "num_tokens": 1279, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206818021529, "lm_q2_score": 0.731058584489497, "lm_q1q2_score": 0.659356856960084}} {"text": "! RUN: %python %S/test_folding.py %s %flang_fc1\n! Tests folding of SQRT()\nmodule m\n implicit none\n ! +Inf\n real(8), parameter :: inf8 = z'7ff0000000000000'\n logical, parameter :: test_inf8 = sqrt(inf8) == inf8\n ! max finite\n real(8), parameter :: h8 = huge(1.0_8), h8z = z'7fefffffffffffff'\n logical, parameter :: test_h8 = h8 == h8z\n real(8), parameter :: sqrt_h8 = sqrt(h8), sqrt_h8z = z'5fefffffffffffff'\n logical, parameter :: test_sqrt_h8 = sqrt_h8 == sqrt_h8z\n real(8), parameter :: sqr_sqrt_h8 = sqrt_h8 * sqrt_h8, sqr_sqrt_h8z = z'7feffffffffffffe'\n logical, parameter :: test_sqr_sqrt_h8 = sqr_sqrt_h8 == sqr_sqrt_h8z\n ! -0 (sqrt is -0)\n real(8), parameter :: n08 = z'8000000000000000'\n real(8), parameter :: sqrt_n08 = sqrt(n08)\n!WARN: division by zero\n real(8), parameter :: inf_n08 = 1.0_8 / sqrt_n08, inf_n08z = z'fff0000000000000'\n logical, parameter :: test_n08 = inf_n08 == inf_n08z\n ! min normal\n real(8), parameter :: t8 = tiny(1.0_8), t8z = z'0010000000000000'\n logical, parameter :: test_t8 = t8 == t8z\n real(8), parameter :: sqrt_t8 = sqrt(t8), sqrt_t8z = z'2000000000000000'\n logical, parameter :: test_sqrt_t8 = sqrt_t8 == sqrt_t8z\n real(8), parameter :: sqr_sqrt_t8 = sqrt_t8 * sqrt_t8\n logical, parameter :: test_sqr_sqrt_t8 = sqr_sqrt_t8 == t8\n ! max subnormal\n real(8), parameter :: maxs8 = z'000fffffffffffff'\n real(8), parameter :: sqrt_maxs8 = sqrt(maxs8), sqrt_maxs8z = z'1fffffffffffffff'\n logical, parameter :: test_sqrt_maxs8 = sqrt_maxs8 == sqrt_maxs8z\n ! min subnormal\n real(8), parameter :: mins8 = z'1'\n real(8), parameter :: sqrt_mins8 = sqrt(mins8), sqrt_mins8z = z'1e60000000000000'\n logical, parameter :: test_sqrt_mins8 = sqrt_mins8 == sqrt_mins8z\n real(8), parameter :: sqr_sqrt_mins8 = sqrt_mins8 * sqrt_mins8\n logical, parameter :: test_sqr_sqrt_mins8 = sqr_sqrt_mins8 == mins8\n ! regression tests: cases near 1.\n real(4), parameter :: sqrt_under1 = sqrt(.96875)\n logical, parameter :: test_sqrt_under1 = sqrt_under1 == .984250962734222412109375\n ! oddball case: the value before 1. is also its own sqrt, but not its own square\n real(4), parameter :: before_1 = z'3f7fffff' ! .999999940395355224609375\n real(4), parameter :: sqrt_before_1 = sqrt(before_1)\n logical, parameter :: test_before_1 = sqrt_before_1 == before_1\n real(4), parameter :: sq_sqrt_before_1 = sqrt_before_1 * sqrt_before_1\n logical, parameter :: test_sq_before_1 = sq_sqrt_before_1 < before_1\nend module\n", "meta": {"hexsha": "dc7310be1296fef556210b62dd51b79933312a89", "size": 2462, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "flang/test/Evaluate/folding28.f90", "max_stars_repo_name": "mkinsner/llvm", "max_stars_repo_head_hexsha": "589d48844edb12cd357b3024248b93d64b6760bf", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2338, "max_stars_repo_stars_event_min_datetime": "2018-06-19T17:34:51.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T11:00:37.000Z", "max_issues_repo_path": "flang/test/Evaluate/folding28.f90", "max_issues_repo_name": "mkinsner/llvm", "max_issues_repo_head_hexsha": "589d48844edb12cd357b3024248b93d64b6760bf", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 3740, "max_issues_repo_issues_event_min_datetime": "2019-01-23T15:36:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T22:01:13.000Z", "max_forks_repo_path": "flang/test/Evaluate/folding28.f90", "max_forks_repo_name": "mkinsner/llvm", "max_forks_repo_head_hexsha": "589d48844edb12cd357b3024248b93d64b6760bf", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 500, "max_forks_repo_forks_event_min_datetime": "2019-01-23T07:49:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T02:59:37.000Z", "avg_line_length": 51.2916666667, "max_line_length": 91, "alphanum_fraction": 0.7112103981, "num_tokens": 858, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206844384594, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6593568536025813}} {"text": "! DART software - Copyright UCAR. This open source software is provided\n! by UCAR, \"as is\", without charge, subject to all terms of use at\n! http://www.image.ucar.edu/DAReS/DART/DART_download\n\nprogram sys_sim5\n\n! Work done during last week of January 2002 (28 Jan init) to investigate\n! impacts of sampling error from small ensembles on update for a single \n! variable that is exactly observed; applicable to observation variable \n! priors. Small sample estimates of variance have approximately normal\n! (or is it exactly normal) error distributions. BUT, when one computes\n! the updated variance there is a bias. Of course, one must also account\n! for the increased uncertainty in the estimate of the mean resulting from\n! errors in the computation of the variance.\n\n! This piece looks at what large sample MC gives for correct updated \n! distribution statistics in preparation for correcting EAKF for the small\n! sample problems.\n\nuse random_seq_mod, only : random_seq_type, init_random_seq, random_gaussian, &\n twod_gaussians, random_uniform\n\nimplicit none\n\ntype (random_seq_type) :: r\ndouble precision, allocatable :: rnum(:)\ndouble precision :: sigma_y_p, y_p, sigma_y_o, y_o, var_of_var\ndouble precision :: sum_mean, sum_mean_2, sum_var, var, sigma_y_u\ndouble precision :: y_u, sample_mean, sample_var, inf_var, inf_u\ndouble precision :: temp_mean, pre_var_sum, mean_var\ninteger :: n, n_samples, i, j\n\n! Initialize repeatable random sequence\ncall init_random_seq(r) \n\n! For now have a set of free parameters that may be too large\nwrite(*, *) 'Input prior variance of observation variable'\nread(*, *) sigma_y_p\nwrite(*, *) 'Input prior value of observation variable'\nread(*, *) y_p\nwrite(*, *) 'Input variance of observing instrument'\nread(*, *) sigma_y_o\nwrite(*, *) 'input value of observation '\nread(*, *) y_o\nwrite(*, *) 'Input ensemble size'\nread(*, *) n\n\nwrite(*, *) 'Input number of samples for statistics'\nread(*, *) n_samples\n\n! Allocate storage for computing sample variance\nallocate(rnum(n))\n\n! Compute the variance of the variance distribution\nvar_of_var = 2.0 * sigma_y_p**4 / (n - 1.0)\n\nwrite(*, *) 'var and var of var', real(sigma_y_p), real(var_of_var)\n\n! Initialize summations\nsum_mean = 0.0\nsum_mean_2 = 0.0\nsum_var = 0.0\npre_var_sum = 0.0\n\n! Loop through the number of samples\ndo i = 1, n_samples\n\n! We are given the sample variance, what is a sample of the underlying\n! variance distribution\n! Could do this from distribution, but it doesn't apply for small samples\n!!! var = random_gaussian(r, sigma_y_p, sqrt(var_of_var))\n\n! Compute the sample variance for this ensemble size\n do j = 1, n\n rnum(j) = random_gaussian(r, dble(0.0), sqrt(sigma_y_p))\n end do\n\n! Compute the sample variance\n call sample_mean_var(rnum, n, temp_mean, var)\n\n pre_var_sum = pre_var_sum + var\n\n\n\n! Given this var, compute updated var and mean\n sigma_y_u = (1.0 / (1.0 / var + 1.0 / sigma_y_o))\n y_u = sigma_y_u * (y_p / var + y_o / sigma_y_o)\n\n\nif(var < 0.0) write(*, *) 'var is , y_u, si', real(var), real(y_u), real(sigma_y_u)\n\n\n! Need to keep sum of the means, sum of the mean squared, sum of the var\n sum_mean = sum_mean + y_u\n sum_mean_2 = sum_mean_2 + (y_u)**2\n sum_var = sum_var + sigma_y_u\n\nend do\n\n! Output the mean and variance corresponding to finite sample\n! See working notes, 29 Jan 2002\nsample_mean = sum_mean / n_samples\nsample_var = (SUM_var + sum_mean_2) / n_samples - sample_mean**2\nwrite(*, *) 'sample mean and var ', real(sample_mean), real(sample_var)\n\n! What would happen without these assumptions\ninf_var = (1.0 / (1.0 / sigma_y_p + 1.0 / sigma_y_o))\ninf_u = inf_var * (y_p / sigma_y_p + y_o / sigma_y_o)\nwrite(*, *) 'infini mean and var ', real(inf_u), real(INF_var)\n\nmean_var = sum_var / n_samples\nwrite(*, *) 'mean var i s ', real(mean_var)\nwrite(*, *) 'pre mean var ', real(pre_var_sum / n_samples)\n\nwrite(*, *) '-----------------'\nwrite(*, *) 'normalized sample var - mean var ', real((sample_var - sum_var / n_samples) / (y_o - y_p)**2)\nwrite(*, *) 'ratio of mean_var to prior var ', real(mean_var /sigma_y_p) \nwrite(*, *) 'fraction of movement ', real((sample_mean - y_o) / (y_p - y_o))\nwrite(*, *) 'expected fraction of movement ', real((inf_u - y_o) / (y_p - y_o))\n\n\nend program sys_sim5\n\n!-----------------------------------------------------\n \nsubroutine comp_correl(ens, n, correl)\n \nimplicit none\n \ninteger, intent(in) :: n\ndouble precision, intent(in) :: ens(2, n)\ndouble precision, intent(out) :: correl\ndouble precision :: sum_x, sum_y, sum_xy, sum_x2, sum_y2\n\n\nsum_x = sum(ens(2, :))\nsum_y = sum(ens(1, :))\nsum_xy = sum(ens(2, :) * ens(1, :))\nsum_x2 = sum(ens(2, :) * ens(2, :))\n \n! Computation of correlation \nsum_y2 = sum(ens(1, :) * ens(1, :))\n\ncorrel = (n * sum_xy - sum_x * sum_y) / &\n sqrt((n * sum_x2 - sum_x**2) * (n * sum_y2 - sum_y**2))\n \nend subroutine comp_correl\n\n!----------------------------------------------------------------\n\nsubroutine sample_mean_var(x, n, mean, var)\n\nimplicit none\n\ninteger, intent(in) :: n\ndouble precision, intent(in) :: x(n)\ndouble precision, intent(out) :: mean, var\n\ndouble precision :: sx, s_x2\n\nsx = sum(x)\ns_x2 = sum(x * x)\nmean = sx / n\nvar = (s_x2 - sx**2 / n) / (n - 1)\n\nend subroutine sample_mean_var\n\n", "meta": {"hexsha": "4312074349b8eb258370ee6fe439ab994f5ea05d", "size": 5224, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "assimilation_code/programs/system_simulation/sys_sim5.f90", "max_stars_repo_name": "fairaque1999/DART", "max_stars_repo_head_hexsha": "7490f75cf9800cc841b66d87840ad96c5751b809", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 65, "max_stars_repo_stars_event_min_datetime": "2019-10-16T13:31:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-14T11:52:58.000Z", "max_issues_repo_path": "assimilation_code/programs/system_simulation/sys_sim5.f90", "max_issues_repo_name": "fairaque1999/DART", "max_issues_repo_head_hexsha": "7490f75cf9800cc841b66d87840ad96c5751b809", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 283, "max_issues_repo_issues_event_min_datetime": "2019-09-23T15:48:34.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:44:41.000Z", "max_forks_repo_path": "assimilation_code/programs/system_simulation/sys_sim5.f90", "max_forks_repo_name": "fairaque1999/DART", "max_forks_repo_head_hexsha": "7490f75cf9800cc841b66d87840ad96c5751b809", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 67, "max_forks_repo_forks_event_min_datetime": "2019-09-19T22:13:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-20T15:58:26.000Z", "avg_line_length": 31.0952380952, "max_line_length": 106, "alphanum_fraction": 0.6851071975, "num_tokens": 1502, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206765295399, "lm_q2_score": 0.731058584489497, "lm_q1q2_score": 0.659356853105495}} {"text": "program uranium\n! Calculates Hydrogen like relativistic energies for Z=92 (U)\n!\n! The purpose of this test is to check that:\n! a) all U energies can converge to 1e-6\n! b) that it converges when using very rough initial estimate\nuse dftatom\nimplicit none\n\n! Atomic number:\ninteger, parameter :: Z = 92\n! Mesh parameters:\nreal(dp), parameter :: r_min = 1e-8_dp, r_max = 50.0_dp, a = 6.2e7_dp\ninteger, parameter :: NN = 4500\n\nreal(dp), parameter :: c = 137.035999037_dp, eps = 5e-7_dp\ninteger :: n, l, relat, converged, relat_max\nreal(dp) :: r(NN+1), u(size(r)), Ein, E, E_exact, error, P(size(r)), Q(size(r))\nreal(dp) :: Rp(NN+1)\n\n\nr = mesh_exp(r_min, r_max, a, NN)\nRp = mesh_exp_deriv(r_min, r_max, a, NN)\nu(:) = -Z/r\n\nprint *, \"Hydrogen like relativistic energies for Z=92 (U)\"\nprint *, \"Mesh parameters (r_min, r_max, a, N):\"\nprint \"(ES10.2, F10.2, ES10.2, I10)\", r_min, r_max, a, NN\nprint *\nprint \"(A3, A3, A3, A15, A15, A10)\", \"n\", \"l\", \"k\", \"E\", \"E_exact\", \"Error\"\nprint *\ndo n = 1, 7\n do l = 0, n-1\n if (l == 0) then\n relat_max = 2\n else\n relat_max = 3\n end if\n do relat = 2, relat_max\n E_exact = E_nl(c, n, l, Z, relat)\n Ein = -100\n call solve_radial_eigenproblem(n, l, Ein, eps, 100, R, Rp, u, &\n Z, c, relat, .true., -10000._dp, 0._dp, converged, E, P, Q)\n error = abs(E - E_exact)\n if (converged /= 0) call stop_error(\"Not converged\")\n print \"(I3, I3, I3, F15.6, F15.6, ES10.2)\", n, l, relat-2, &\n E, E_exact, error\n if (error > 1e-6_dp) call stop_error(\"Error is higher than 1e-6\")\n end do\n end do\nend do\nend program\n", "meta": {"hexsha": "8667a3c6db1783afe8e6485ff19471b8db3982a8", "size": 1698, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/Z92n7all/Z92_rel.f90", "max_stars_repo_name": "rc/dftatom", "max_stars_repo_head_hexsha": "fe479fd27a7e0f77c6a88a1949996406ec935ac2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 40, "max_stars_repo_stars_event_min_datetime": "2015-03-19T16:00:14.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-29T03:06:10.000Z", "max_issues_repo_path": "tests/Z92n7all/Z92_rel.f90", "max_issues_repo_name": "rc/dftatom", "max_issues_repo_head_hexsha": "fe479fd27a7e0f77c6a88a1949996406ec935ac2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2015-06-23T21:59:56.000Z", "max_issues_repo_issues_event_max_datetime": "2019-09-04T20:36:51.000Z", "max_forks_repo_path": "tests/Z92n7all/Z92_rel.f90", "max_forks_repo_name": "rc/dftatom", "max_forks_repo_head_hexsha": "fe479fd27a7e0f77c6a88a1949996406ec935ac2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2015-06-07T15:14:49.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-05T07:03:24.000Z", "avg_line_length": 32.0377358491, "max_line_length": 79, "alphanum_fraction": 0.5806831567, "num_tokens": 599, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206870747658, "lm_q2_score": 0.7310585727705126, "lm_q1q2_score": 0.6593568502450784}} {"text": " function hru_erfc(xx)\n \n!! ~ ~ ~ PURPOSE ~ ~ ~\n!! erfc is the complementary error function; \n!! erf(B) is the error function for B\n!! ~ ~ ~ SUBROUTINES/FUNCTIONS CALLED ~ ~ ~\n!! Intrinsic: Abs\n\n!! ~ ~ ~ ~ ~ ~ END SPECIFICATIONS ~ ~ ~ ~ ~ ~\n\n implicit none\n\n real, parameter :: c1 = .19684 ! |\n real, parameter :: c2 = .115194 ! |\n real, parameter :: c3 = .00034 ! |\n real, parameter :: c4 = .019527 ! |\n real, intent (in) :: xx ! |\n real :: x !none |variable to hold intermediate \n ! |calculation result\n real :: erf ! |\n real :: hru_erfc ! |\n\n x = 0.\n erf = 0.\n hru_erfc = 0.\n\n x = Abs(1.4142 * xx)\n erf = 1. - (1. + c1 * x + c2 * x * x + c3 * x**3 + c4 * x**4) ** (-4)\n if (xx < 0.) erf = -erf\n\n hru_erfc = 1. - erf\n\n return\n end function", "meta": {"hexsha": "0aa6a2f762dc8060b2fab83bef3f3fc5c2486fed", "size": 1176, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source_codes_60.5/erfc.f90", "max_stars_repo_name": "ankwasa/wetlands_swatplus", "max_stars_repo_head_hexsha": "3cdf83cc6a4dc68ce4f53ce1d0ebacd7695b54cf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source_codes_60.5/erfc.f90", "max_issues_repo_name": "ankwasa/wetlands_swatplus", "max_issues_repo_head_hexsha": "3cdf83cc6a4dc68ce4f53ce1d0ebacd7695b54cf", "max_issues_repo_licenses": ["MIT"], "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_codes_60.5/erfc.f90", "max_forks_repo_name": "ankwasa/wetlands_swatplus", "max_forks_repo_head_hexsha": "3cdf83cc6a4dc68ce4f53ce1d0ebacd7695b54cf", "max_forks_repo_licenses": ["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.5882352941, "max_line_length": 95, "alphanum_fraction": 0.3460884354, "num_tokens": 309, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206765295399, "lm_q2_score": 0.7310585786300048, "lm_q1q2_score": 0.6593568478206977}} {"text": "module kramers_kronig\n use constants, only: zero, real12, cmplx_zero, cmplx_i, fatal_error_from_call\n use definedtypes\n use greensroutines\n use one_dimensional_FT, only: oneD_fft, forward_fft, backward_fft\n\n implicit none\n private\n public hilbert_transform\n\ncontains\n\n pure subroutine hilbert_transform(input, result, ierr)\n real(real12), intent(in) :: input(:)\n real(real12), intent(out) :: result(:)\n integer, intent(out) :: ierr\n\n complex(real12) :: full_freq(2*size(input)), positive_only(size(input))\n integer :: ierr1\n\n ierr = 0\n if (size(input) /= size(result)) ierr = 1\n if (ierr /= 0) return\n\n positive_only = cmplx_zero\n positive_only(1:size(input))%re = input(1:size(input))\n full_freq(1:size(input)) = conjg(positive_only(size(input):1)) ! impose negative frequency condition\n full_freq(size(input) + 1:2*size(input)) = positive_only(1:size(input))\n\n ! Hilbert transform (AIP Advances *2*, 032144 (2012) eqn (6))\n call oneD_fft(full_freq, forward_fft, ierr1)\n full_freq = cmplx_i*full_freq\n full_freq(1:size(input)) = -full_freq(1:size(input))\n call oneD_fft(full_freq, backward_fft, ierr1)\n\n result = full_freq(size(input) + 1:2*size(input))%re\n\n end subroutine hilbert_transform\n\nend module\n", "meta": {"hexsha": "8fd5a371ca89c001981dada4f96870955ee2af4a", "size": 1358, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "src/kramers_kronig.f08", "max_stars_repo_name": "IOThomas/Anderson-Phonon", "max_stars_repo_head_hexsha": "2797412a77414ec8fb35d5300af573ff7f0ab77c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-10-30T07:23:37.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-30T07:23:37.000Z", "max_issues_repo_path": "src/kramers_kronig.f08", "max_issues_repo_name": "IOThomas/Anderson-Phonon", "max_issues_repo_head_hexsha": "2797412a77414ec8fb35d5300af573ff7f0ab77c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2019-09-16T14:15:52.000Z", "max_issues_repo_issues_event_max_datetime": "2020-03-12T21:18:40.000Z", "max_forks_repo_path": "src/kramers_kronig.f08", "max_forks_repo_name": "IOThomas/Anderson-Phonon", "max_forks_repo_head_hexsha": "2797412a77414ec8fb35d5300af573ff7f0ab77c", "max_forks_repo_licenses": ["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.1219512195, "max_line_length": 108, "alphanum_fraction": 0.6597938144, "num_tokens": 359, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569267, "lm_q2_score": 0.7310585727705126, "lm_q1q2_score": 0.6593568386813115}} {"text": "program fisher_estimate\n\n USE healpix_types \n\n\timplicit none\n\tinteger(i4b)::i,jlo,l\n\tinteger,parameter :: lmax=3500\n\treal(dp), parameter ::fsky=1d0,thetaFWHM=1d0*0.000290888209d0\n\treal(dp), allocatable, dimension(:,:)::Cl\n\treal(dp), allocatable, dimension(:):: xa,ya,y2a,deltaCl,deltaCl_pol,y_pol,y_pol2,x_pol !! variable for spline the TT spectrum and EE\n\tcharacter(len=128) :: filename\n\tinteger :: ios,err,istat\n\treal(dp)::logCl,logCl_pol,fisher,fisher_pol, variance,variance_pol\n\tfilename='/Users/alessandromanzotti/Downloads/camb/test_scal2Cls.dat'\n\n\n\n\n\n\topen(unit=10, file=filename, iostat=ios, &\n status=\"old\", action=\"read\", form='formatted')\n \n\tif ( ios /= 0 ) stop \"Error opening file name\"\n\tallocate(cl(lmax,4), stat=err)\n\tif (err /= 0) print *, \"array: Allocation request denied\"\n\tallocate(xa(lmax),ya(lmax),y2a(lmax),deltaCl(lmax),y_pol(lmax),y_pol2(lmax),deltaCl_pol(lmax) ,stat=err)\n\tif (err /= 0) print *, \"array: Allocation request denied\"\n\t!! read the Cl from camb\n\n\n\tdo i = 1, lmax, 1\n\n\t\tread(10, *) cl(i,1),cl(i,2),cl(i,3)\n\t\tif ( istat /= 0 ) stop \"Read error in file 10\"\n\t\t\n\t\t\n\tend do\n\n\n\n!\twrite(*,*) cl(10,1),cl(10,2)\n\n!! normalize CAMB\n\tdo i = 1, lmax, 1\n\t\tl=cl(i,1)\n\t\tcl(i,2)=cl(i,2)*(twopi/(l*(l+1)))/(7.4311e12)\n\t\tcl(i,3)=cl(i,3)*(twopi/(l*(l+1)))/(7.4311e12)\n\n\tend do\t\n\twrite(*,*) cl(10,1),cl(10,2),cl(10,3)\n\n\t\n\n\t!!! spline the TT spectrum\n\n\txa=log(cl(:,1)) !log(l)\n\tya=log(cl(:,1)**2*cl(:,2)) !log (l^2 Cl)\n\tcall spline(xa,ya,lmax,1.d30,1.d30,y2a)\n\n!!! spline the EE spectrum\n\n\txa=log(cl(:,1)) !log(l)\n\ty_pol=log(cl(:,1)**2*cl(:,3)) !log (l^2 CEE)\n write(*,*) shape(y_pol),shape(xa),shape(y_pol2)\n\tcall spline(xa,y_pol,lmax,1.d30,1.d30,y_pol2)\n\n!\twrite(*,*) shape(y2a),y2a(10)\n\twrite(*,*) 'power spectrum TT&EE splined'\n!\tlogCl=logl2Cl(10._dp)\n!\twrite(*,*) 'power spectrum splined'!,logl2Cl(11._dp),dlnl2Cldlogl(11d0)\n\n\t!!! prepare for fishere elements, compute deltaCl\n\n\t!!! deltaCl=sqrt(2/(2l+1)fsky) (Cl+Nl) we need delta cl squared\n\n\tdo i = 1, lmax, 1\n l=cl(i,1)\n !deltaCl(i)=(2d0/((2*cl(i,1)+1)*fsky))*(cl(i,2)+((4d-6)*(3.1415926535d0/10800))**2*exp(l*(l+1)*((thetaFWHM)**2)/(8d0*log(2d0))))**2 !! add noise\n deltaCl(i)=(2d0/((2*cl(i,1)+1)))*(cl(i,2))**2 !! no noise\n deltaCl_pol(i)=(2d0/((2*cl(i,1)+1)))*(cl(i,3))**2 !! no noise POL\n\n\tend do\n\t\t\n\n !! COMPUTE OUTPUT ANS PRINT\n open(unit=30, file='variancenonoisenofsky_fisher.txt')\n\n!! fisher elements sum_l 1/deltaC (deriv)^2\n\tfisher=0d0\n\tdo i = 1, lmax, 1\n\t\twrite(*,*) fisher\n\t\tfisher=fisher+(1/deltaCl(i))*(dlnl2Cldlogl(DBLE(i)))**2*(cl(i,2))**2\n\t\twrite(30,*) cl(i,1),1/fisher\n\n\tend do\n close(30)\n!! now get variance of the parameter from fisher\n\n open(unit=60, file='variancenonoisenofsky_fisher_pol.txt')\n fisher_pol=0d0\n\tdo i = 1, lmax, 1\n\t!\twrite(*,*) fisher\n\t\tfisher_pol=fisher_pol+(1/deltaCl_pol(i))*(dlnl2Cldlogl_pol(DBLE(i)))**2*(cl(i,3))**2\n\t\twrite(60,*) cl(i,1),1/fisher_pol\n\n\tend do\n close(60)\n\n\topen(unit=20, file='derivatives.txt')\n\n\tdo i = 1, lmax, 1\n\n\t\twrite(20,*) cl(i,1),dlnl2Cldlogl(DBLE(i)),logl2Cl(dble(i))\n\t\t\n\tend do\n\tclose(unit=20)\n\n\topen(unit=20, file='derivatives_pol.txt')\n\n\tdo i = 1, lmax, 1\n\n\t\twrite(20,*) cl(i,1),dlnl2Cldlogl_pol(DBLE(i)),logl2Cl_pol(dble(i))\n\t\t\n\tend do\n\tclose(unit=20)\n\t\n\n\tvariance=(1/fisher)\n\n\twrite(*,*) 'your variance is sigma=',variance\n\n\tif (allocated(cl)) deallocate(cl, stat=err)\n\tif (err /= 0) print *, \"array: Deallocation request denied\"\n\n\t\n\n\tContains\n\n\t\t!!! the two functions to get lnl2Cl from spline\n\nreal(DP) FUNCTION logl2Cl(ak)\n IMPLICIT none\n real(dp) :: a,b,h,x,y,ak\n x = log(ak) \n CALL hunt(xa,lmax,x,jlo)\n h=xa(jlo+1)-xa(jlo)\n a=(xa(jlo+1)-x)/h\n b=(x-xa(jlo))/h\n y=a*ya(jlo)+b*ya(jlo+1)+((a**3-a)*y2a(jlo)+(b**3-b)*y2a(jlo+1))*(h**2)/6.\n logl2Cl = y\n 100 return\nEND FUNCTION logl2Cl\n\n\n\treal(DP) FUNCTION logl2Cl_pol(ak)\n IMPLICIT none\n real(dp) :: a,b,h,x,y,ak\n x = log(ak) \n CALL hunt(xa,lmax,x,jlo)\n h=xa(jlo+1)-xa(jlo)\n a=(xa(jlo+1)-x)/h\n b=(x-xa(jlo))/h\n y=a*y_pol(jlo)+b*y_pol(jlo+1)+((a**3-a)*y_pol2(jlo)+(b**3-b)*y_pol2(jlo+1))*(h**2)/6.\n logl2Cl_pol = y\n 100 return\nEND FUNCTION logl2Cl_pol\n\nDOUBLE PRECISION FUNCTION dlnl2Cldlogl(ak)\n IMPLICIT none\n DOUBLE PRECISION :: a,b,h,x,y,ak\n x = log(ak)\n CALL hunt(xa,lmax,x,jlo)\n h=xa(jlo+1)-xa(jlo)\n a=(xa(jlo+1)-x)/h\n b=(x-xa(jlo))/h\n y=(ya(jlo+1)-ya(jlo))/h+(-(3.*a**2-1.)*y2a(jlo)+(3.*b**2-1.)*y2a(jlo+1))*h/6.\n dlnl2Cldlogl = y\n return\n\tEND FUNCTION dlnl2Cldlogl\n\n\n\nDOUBLE PRECISION FUNCTION dlnl2Cldlogl_pol(ak)\n IMPLICIT none\n DOUBLE PRECISION :: a,b,h,x,y,ak\n x = log(ak)\n CALL hunt(xa,lmax,x,jlo)\n h=xa(jlo+1)-xa(jlo)\n a=(xa(jlo+1)-x)/h\n b=(x-xa(jlo))/h\n y=(y_pol(jlo+1)-y_pol(jlo))/h+(-(3.*a**2-1.)*y_pol2(jlo)+(3.*b**2-1.)*y_pol2(jlo+1))*h/6.\n dlnl2Cldlogl_pol = y\n return\nEND FUNCTION dlnl2Cldlogl_pol\n\t \n\tend program fisher_estimate\n\n\n\n", "meta": {"hexsha": "7d3e4662c295e34de90d041e0c506d620a336d16", "size": 4910, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Code/fisher_estimate_try.f90", "max_stars_repo_name": "amanzotti/super_sample_cov", "max_stars_repo_head_hexsha": "aedf4a08cdcab187c401a731fd8f8bbed593bcd7", "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": "Code/fisher_estimate_try.f90", "max_issues_repo_name": "amanzotti/super_sample_cov", "max_issues_repo_head_hexsha": "aedf4a08cdcab187c401a731fd8f8bbed593bcd7", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Code/fisher_estimate_try.f90", "max_forks_repo_name": "amanzotti/super_sample_cov", "max_forks_repo_head_hexsha": "aedf4a08cdcab187c401a731fd8f8bbed593bcd7", "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.55, "max_line_length": 155, "alphanum_fraction": 0.6217922607, "num_tokens": 2024, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569267, "lm_q2_score": 0.7310585669110202, "lm_q1q2_score": 0.6593568333965142}} {"text": " DOUBLE PRECISION FUNCTION dstrem(z)\n IMPLICIT DOUBLE PRECISION (a-h,o-p,r-z),INTEGER (i-n),LOGICAL (q)\nC**********************************************************************\nC\nC DOUBLE PRECISION FUNCTION DSTREM( Z )\nC Double precision Sterling Remainder\nC\nC\nC Function\nC\nC\nC Returns Log(Gamma(Z)) - Sterling(Z) where Sterling(Z) is\nC Sterling's Approximation to Log(Gamma(Z))\nC\nC Sterling(Z) = LOG( SQRT( 2*PI ) ) + ( Z-0.5 ) * LOG( Z ) - Z\nC\nC\nC Arguments\nC\nC\nC Z --> Value at which Sterling remainder calculated\nC Must be positive.\nC DOUBLE PRECISION Z\nC\nC\nC Method\nC\nC\nC\nC If Z >= 6 uses 9 terms of series in Bernoulli numbers\nC (Values calculated using Maple)\nC Otherwise computes difference explicitly\nC\nC**********************************************************************\n\nC .. Parameters ..\n DOUBLE PRECISION hln2pi\n PARAMETER (hln2pi=0.91893853320467274178D0)\n INTEGER ncoef\n PARAMETER (ncoef=10)\nC ..\nC .. Scalar Arguments ..\n DOUBLE PRECISION z\nC ..\nC .. Local Scalars ..\n DOUBLE PRECISION sterl\nC ..\nC .. Local Arrays ..\n DOUBLE PRECISION coef(ncoef)\nC ..\nC .. External Functions ..\n DOUBLE PRECISION devlpl,dlngam\n EXTERNAL devlpl,dlngam\nC ..\nC .. Intrinsic Functions ..\n INTRINSIC log\nC ..\nC .. Data statements ..\n DATA coef/0.0D0,0.0833333333333333333333333333333D0,\n + -0.00277777777777777777777777777778D0,\n + 0.000793650793650793650793650793651D0,\n + -0.000595238095238095238095238095238D0,\n + 0.000841750841750841750841750841751D0,\n + -0.00191752691752691752691752691753D0,\n + 0.00641025641025641025641025641026D0,\n + -0.0295506535947712418300653594771D0,\n + 0.179644372368830573164938490016D0/\nC ..\nC .. Executable Statements ..\n\nC For information, here are the next 11 coefficients of the\nC remainder term in Sterling's formula\nC -1.39243221690590111642743221691\nC 13.4028640441683919944789510007\nC -156.848284626002017306365132452\nC 2193.10333333333333333333333333\nC -36108.7712537249893571732652192\nC 691472.268851313067108395250776\nC -0.152382215394074161922833649589D8\nC 0.382900751391414141414141414141D9\nC -0.108822660357843910890151491655D11\nC 0.347320283765002252252252252252D12\nC -0.123696021422692744542517103493D14\nC\n\n IF (z.LE.0.0D0) STOP 'Zero or negative argument in DSTREM'\n IF (.NOT. (z.GT.6.0D0)) GO TO 10\n dstrem = devlpl(coef,10,1.0D0/z**2)*z\n GO TO 20\n\n 10 sterl = hln2pi + (z-0.5D0)*log(z) - z\n dstrem = dlngam(z) - sterl\n 20 RETURN\n\n END\n", "meta": {"hexsha": "5938cf0995c49af59f1fb2c240d523d85dae3973", "size": 2901, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/rnd/dstrem.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/dstrem.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/dstrem.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": 30.21875, "max_line_length": 71, "alphanum_fraction": 0.5911754567, "num_tokens": 908, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818986, "lm_q2_score": 0.743168019989179, "lm_q1q2_score": 0.6593420856708888}} {"text": " SUBROUTINE MB04MD( N, MAXRED, A, LDA, SCALE, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To reduce the 1-norm of a general real matrix A by balancing.\nC This involves diagonal similarity transformations applied\nC iteratively to A to make the rows and columns as close in norm as\nC possible.\nC\nC This routine can be used instead LAPACK Library routine DGEBAL,\nC when no reduction of the 1-norm of the matrix is possible with\nC DGEBAL, as for upper triangular matrices. LAPACK Library routine\nC DGEBAK, with parameters ILO = 1, IHI = N, and JOB = 'S', should\nC be used to apply the backward transformation.\nC\nC ARGUMENTS\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The order of the matrix A. N >= 0.\nC\nC MAXRED (input/output) DOUBLE PRECISION\nC On entry, the maximum allowed reduction in the 1-norm of\nC A (in an iteration) if zero rows or columns are\nC encountered.\nC If MAXRED > 0.0, MAXRED must be larger than one (to enable\nC the norm reduction).\nC If MAXRED <= 0.0, then the value 10.0 for MAXRED is\nC used.\nC On exit, if the 1-norm of the given matrix A is non-zero,\nC the ratio between the 1-norm of the given matrix and the\nC 1-norm of the balanced matrix. Usually, this ratio will be\nC larger than one, but it can sometimes be one, or even less\nC than one (for instance, for some companion matrices).\nC\nC A (input/output) DOUBLE PRECISION array, dimension (LDA,N)\nC On entry, the leading N-by-N part of this array must\nC contain the input matrix A.\nC On exit, the leading N-by-N part of this array contains\nC the balanced matrix.\nC\nC LDA INTEGER\nC The leading dimension of the array A. LDA >= max(1,N).\nC\nC SCALE (output) DOUBLE PRECISION array, dimension (N)\nC The scaling factors applied to A. If D(j) is the scaling\nC factor applied to row and column j, then SCALE(j) = D(j),\nC for j = 1,...,N.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit.\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value.\nC\nC METHOD\nC\nC Balancing consists of applying a diagonal similarity\nC transformation inv(D) * A * D to make the 1-norms of each row\nC of A and its corresponding column nearly equal.\nC\nC Information about the diagonal matrix D is returned in the vector\nC SCALE.\nC\nC REFERENCES\nC\nC [1] Anderson, E., Bai, Z., Bischof, C., Demmel, J., Dongarra, J.,\nC Du Croz, J., Greenbaum, A., Hammarling, S., McKenney, A.,\nC Ostrouchov, S., and Sorensen, D.\nC LAPACK Users' Guide: Second Edition.\nC SIAM, Philadelphia, 1995.\nC\nC NUMERICAL ASPECTS\nC\nC None.\nC\nC CONTRIBUTOR\nC\nC Release 3.0: V. Sima, Katholieke Univ. Leuven, Belgium, June 1997.\nC Supersedes Release 2.0 routine MB04AD by T.W.C. Williams,\nC Kingston Polytechnic, United Kingdom, October 1984.\nC This subroutine is based on LAPACK routine DGEBAL, and routine\nC BALABC (A. Varga, German Aerospace Research Establishment, DLR).\nC\nC\nC REVISIONS\nC\nC -\nC\nC KEYWORDS\nC\nC Balancing, eigenvalue, matrix algebra, matrix operations,\nC similarity transformation.\nC\nC *********************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, ONE\n PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )\n DOUBLE PRECISION SCLFAC\n PARAMETER ( SCLFAC = 1.0D+1 )\n DOUBLE PRECISION FACTOR, MAXR\n PARAMETER ( FACTOR = 0.95D+0, MAXR = 10.0D+0 )\nC ..\nC .. Scalar Arguments ..\n INTEGER INFO, LDA, N\n DOUBLE PRECISION MAXRED\nC ..\nC .. Array Arguments ..\n DOUBLE PRECISION A( LDA, * ), SCALE( * )\nC ..\nC .. Local Scalars ..\n LOGICAL NOCONV\n INTEGER I, ICA, IRA, J\n DOUBLE PRECISION ANORM, C, CA, F, G, MAXNRM, R, RA, S, SFMAX1,\n $ SFMAX2, SFMIN1, SFMIN2, SRED\nC ..\nC .. External Functions ..\n INTEGER IDAMAX\n DOUBLE PRECISION DLAMCH, DLANGE\n EXTERNAL DLAMCH, DLANGE, IDAMAX\nC ..\nC .. External Subroutines ..\n EXTERNAL DSCAL, XERBLA\nC ..\nC .. Intrinsic Functions ..\n INTRINSIC ABS, MAX, MIN\nC ..\nC .. Executable Statements ..\nC\nC Test the scalar input arguments.\nC\n INFO = 0\nC\n IF( N.LT.0 ) THEN\n INFO = -1\n ELSE IF( MAXRED.GT.ZERO .AND. MAXRED.LT.ONE ) THEN\n INFO = -2\n ELSE IF( LDA.LT.MAX( 1, N ) ) THEN\n INFO = -4\n END IF\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'MB04MD', -INFO )\n RETURN\n END IF\nC\n IF( N.EQ.0 )\n $ RETURN\nC\n DO 10 I = 1, N\n SCALE( I ) = ONE\n 10 CONTINUE\nC\nC Compute the 1-norm of matrix A and exit if it is zero.\nC\n ANORM = DLANGE( '1-norm', N, N, A, LDA, SCALE )\n IF( ANORM.EQ.ZERO )\n $ RETURN\nC\nC Set some machine parameters and the maximum reduction in the\nC 1-norm of A if zero rows or columns are encountered.\nC\n SFMIN1 = DLAMCH( 'S' ) / DLAMCH( 'P' )\n SFMAX1 = ONE / SFMIN1\n SFMIN2 = SFMIN1*SCLFAC\n SFMAX2 = ONE / SFMIN2\nC\n SRED = MAXRED\n IF( SRED.LE.ZERO ) SRED = MAXR\nC\n MAXNRM = MAX( ANORM/SRED, SFMIN1 )\nC\nC Balance the matrix.\nC\nC Iterative loop for norm reduction.\nC\n 20 CONTINUE\n NOCONV = .FALSE.\nC\n DO 80 I = 1, N\n C = ZERO\n R = ZERO\nC\n DO 30 J = 1, N\n IF( J.EQ.I )\n $ GO TO 30\n C = C + ABS( A( J, I ) )\n R = R + ABS( A( I, J ) )\n 30 CONTINUE\n ICA = IDAMAX( N, A( 1, I ), 1 )\n CA = ABS( A( ICA, I ) )\n IRA = IDAMAX( N, A( I, 1 ), LDA )\n RA = ABS( A( I, IRA ) )\nC\nC Special case of zero C and/or R.\nC\n IF( C.EQ.ZERO .AND. R.EQ.ZERO )\n $ GO TO 80\n IF( C.EQ.ZERO ) THEN\n IF( R.LE.MAXNRM)\n $ GO TO 80\n C = MAXNRM\n END IF\n IF( R.EQ.ZERO ) THEN\n IF( C.LE.MAXNRM )\n $ GO TO 80\n R = MAXNRM\n END IF\nC\nC Guard against zero C or R due to underflow.\nC\n G = R / SCLFAC\n F = ONE\n S = C + R\n 40 CONTINUE\n IF( C.GE.G .OR. MAX( F, C, CA ).GE.SFMAX2 .OR.\n $ MIN( R, G, RA ).LE.SFMIN2 )GO TO 50\n F = F*SCLFAC\n C = C*SCLFAC\n CA = CA*SCLFAC\n R = R / SCLFAC\n G = G / SCLFAC\n RA = RA / SCLFAC\n GO TO 40\nC\n 50 CONTINUE\n G = C / SCLFAC\n 60 CONTINUE\n IF( G.LT.R .OR. MAX( R, RA ).GE.SFMAX2 .OR.\n $ MIN( F, C, G, CA ).LE.SFMIN2 )GO TO 70\n F = F / SCLFAC\n C = C / SCLFAC\n G = G / SCLFAC\n CA = CA / SCLFAC\n R = R*SCLFAC\n RA = RA*SCLFAC\n GO TO 60\nC\nC Now balance.\nC\n 70 CONTINUE\n IF( ( C+R ).GE.FACTOR*S )\n $ GO TO 80\n IF( F.LT.ONE .AND. SCALE( I ).LT.ONE ) THEN\n IF( F*SCALE( I ).LE.SFMIN1 )\n $ GO TO 80\n END IF\n IF( F.GT.ONE .AND. SCALE( I ).GT.ONE ) THEN\n IF( SCALE( I ).GE.SFMAX1 / F )\n $ GO TO 80\n END IF\n G = ONE / F\n SCALE( I ) = SCALE( I )*F\n NOCONV = .TRUE.\nC\n CALL DSCAL( N, G, A( I, 1 ), LDA )\n CALL DSCAL( N, F, A( 1, I ), 1 )\nC\n 80 CONTINUE\nC\n IF( NOCONV )\n $ GO TO 20\nC\nC Set the norm reduction parameter.\nC\n MAXRED = ANORM/DLANGE( '1-norm', N, N, A, LDA, SCALE )\nC\n RETURN\nC *** End of MB04MD ***\n END\n", "meta": {"hexsha": "e21b3e5cf1989f6c7f1aefb487acb7f4f8672ad3", "size": 7957, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB04MD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB04MD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB04MD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 28.725631769, "max_line_length": 72, "alphanum_fraction": 0.5302249592, "num_tokens": 2561, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8872045996818986, "lm_q2_score": 0.7431680199891789, "lm_q1q2_score": 0.6593420856708887}} {"text": "MODULE interpolation_functions\n! Module containing functions necessary for 3DInterpolation\nCONTAINS\nINTEGER FUNCTION fact(n)\n ! Retruns the factorial of n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: n\n INTEGER p,i\n p = 1 \n do i = 1, n\n\t p = p * i\n end do\n fact = p\nEND FUNCTION fact\n\n! Returns the inverse of a matrix calculated by finding the LU\n! decomposition. Depends on LAPACK.\nfunction inv(A) result(Ainv)\nIMPLICIT NONE\n INTEGER, PARAMETER :: dp = selected_real_kind(15, 307)\n real(KIND=dp), dimension(:,:), intent(in) :: A\n real(KIND=dp), dimension(size(A,1),size(A,2)) :: Ainv\n\n real(KIND=dp), dimension(size(A,1)) :: work ! work array for LAPACK\n integer, dimension(size(A,1)) :: ipiv ! pivot indices\n integer :: N,M,info,i\n ! External procedures defined in LAPACK\n external DGETRF\n external DGETRI\n\n ! Store A in Ainv to prevent it from being overwritten by LAPACK\n Ainv = A(:,:)\n\n M = size(A,1)\n N = size(A,2)\n\n ! DGETRF computes an LU factorization of a general M-by-N matrix A\n ! using partial pivoting with row interchanges.\n call DGETRF(M, N, Ainv, M, ipiv, info)\n\n if (info /= 0) then\n stop 'Matrix is numerically singular!'\n end if\n\n ! DGETRI computes the inverse of a matrix using the LU factorization\n ! computed by DGETRF.\n call DGETRI(M, Ainv, M, ipiv, work, M, info)\n\n if (info /= 0) then\n stop 'Matrix inversion failed!'\n end if\nend function inv \nEND MODULE interpolation_functions\n", "meta": {"hexsha": "087e9d1f1d94d4b7da3b5ab7352370afb73a653f", "size": 1480, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/OpenFoam/interpolation_functions.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/OpenFoam/interpolation_functions.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/OpenFoam/interpolation_functions.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": 27.4074074074, "max_line_length": 70, "alphanum_fraction": 0.6756756757, "num_tokens": 436, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.7431680086124812, "lm_q1q2_score": 0.6593420711445878}} {"text": "module calculations\n use input\n use global_variables\n implicit none \n contains\n\n subroutine calc \n implicit none\n double precision :: sum1\n integer :: i,j,k\n \n allocate(N_result(N_modes,nlines))\n allocate(v_result(N_modes,nlines))\n allocate(t_result(nlines))\n allocate(N_total(nlines))\n allocate(dp_g(nlines))\n allocate(v_g(nlines))\n allocate(sigma_g(nlines))\n allocate(M(2*(N_modes+1)))\n\n \n OPEN(unit = 15, file = \"results_raw.dat\")\n\t\t DO i = 1,nlines\n\t\t\t READ(15,*)M\n t_result(i) = M(1)\n DO j = 1,N_modes\n N_result(j,i) = M(2*j);\n v_result(j,i) = M(2*j+1)/M(2*j);\n END DO\n \n !!! Geometric Mean Diameter Calculation\n sum1 = 0\n N_total(i) = 0\n DO k = 1,N_modes\n sum1 = sum1 + N_result(k,i)*log(v_result(k,i))\n N_total(i) = N_total(i) + N_result(k,i) \n END DO \n \n v_g(i) = exp((1/N_total(i))*(sum1))\n dp_g(i) = (6*v_g(i)/PI)**(1.0/3)\n \n !!! Geometric Std. Deviation Calculation\n sum1 = 0\n DO k = 1,N_modes\n sum1 = sum1 + N_result(k,i)*((log((6*v_result(k,i)/PI)**(1.0/3))-log(dp_g(i)))**2.0)/(N_total(i)-1)\n END DO \n sigma_g(i) = exp(sum1**(0.5))\n\t\t END DO\n\t\tCLOSE (unit = 15)\n \n \n OPEN(UNIT=7, FILE = 'results.dat')\n WRITE(7,*)\" t (s) \", \"N_total (#/m3)\", \" dp_g (m) \", \" sigma_g\"\n DO i = 1,nlines\n WRITE(7,67) time(i), N_total(i), dp_g(i), sigma_g(i)\n END DO\n 67 FORMAT(100E14.6)\n \n\n end subroutine calc\nend module calculations", "meta": {"hexsha": "cc4668fe7264ef1dd977b1f73610e3a73f73d7d0", "size": 1939, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "AAQRL-ADM/Modal model/calculations.f90", "max_stars_repo_name": "AAQRL/aerosol_dynamic_models", "max_stars_repo_head_hexsha": "5257ddb58b05254be0beb8b33119fe854cf80890", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-06-26T18:36:43.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-06T00:35:49.000Z", "max_issues_repo_path": "AAQRL-ADM/Modal model/calculations.f90", "max_issues_repo_name": "AAQRL/aerosol_dynamic_models", "max_issues_repo_head_hexsha": "5257ddb58b05254be0beb8b33119fe854cf80890", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-03-17T01:01:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-17T13:20:10.000Z", "max_forks_repo_path": "AAQRL-ADM/Modal model/calculations.f90", "max_forks_repo_name": "AAQRL/aerosol_dynamic_models", "max_forks_repo_head_hexsha": "5257ddb58b05254be0beb8b33119fe854cf80890", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-08-08T14:45:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-22T01:07:42.000Z", "avg_line_length": 31.7868852459, "max_line_length": 119, "alphanum_fraction": 0.4368231047, "num_tokens": 509, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818986, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6593420705307006}} {"text": "! =============================================================================\n! Module to compute 1D derivatives of Fourier series\n! =============================================================================\nmodule deriv1d\n use constants, only : pi, zero\n implicit none\n\n contains\n\n subroutine init_deriv(n, l, k)\n integer, intent(in) :: n\n double precision, intent(in) :: l\n double precision, intent(out) :: k(n)\n double precision :: sc\n integer :: i\n\n ! define wavenumber array:\n if (l .ne. zero) then\n ! define wavenumbers:\n sc = pi / l\n do i = 1, n\n k(i) = sc * dble(i)\n enddo\n else\n ! catastrophic end to run if wave number definition fails:\n write(*,*) '**********************************************'\n write(*,*) ' Wavenumber array definition not possible.'\n write(*,*) ' Domain length equal to zero not allowed.'\n write(*,*) ' STOPPING...'\n write(*,*) '**********************************************'\n stop\n endif\n end subroutine\n\n\n ! Calculates m derivatives of length n for the array var(m,n)\n ! and stores the result in der(m,n).\n ! *** Both var and der are assumed to be Fourier ***\n ! *** coeffiecients in their second argument ***\n subroutine deriv(m, n, k, var, der)\n integer, intent(in) :: m, n\n double precision, intent(in) :: k(n), var(m,n)\n double precision, intent(out) :: der(m,n)\n integer :: nw, np2, i, j, ic\n double precision :: ktmp\n\n nw = n / 2\n np2 = n + 2\n\n ! Carry out differentiation by wavenumber multiplication:\n do j=1,m\n der(j, 1) = zero\n enddo\n\n do i = 2, n - nw\n ktmp = k(2*(i-1))\n ic = np2 - i\n do j = 1, m\n der(j, i) = -ktmp * var(j,ic)\n der(j,ic) = ktmp * var(j ,i)\n enddo\n enddo\n\n if (mod(n,2) == 0) then\n ic=nw+1\n do j = 1, m\n der(j,ic) = zero\n enddo\n endif\n end subroutine\n\n\n ! Calculates m derivatives of length n for the array var(m,n)\n ! and stores the result in der(m,n), where var is represented by a\n ! cosine series. Note der is therefore a sine series.\n ! *** Both var and der are assumed to be Fourier ***\n ! *** coeffiecients in their second argument ***\n subroutine deriv_c(m, n, k, var, der)\n integer, intent(in) :: m, n\n double precision, intent(in) :: k(n), var(m,0:n)\n double precision, intent(out) :: der(m,n)\n integer :: i, j\n double precision :: ktmp\n\n ! Carry out differentiation by wavenumber multiplication:\n do i = 1, n-1\n ktmp = -k(i)\n do j = 1, m\n der(j,i) = ktmp * var(j,i)\n enddo\n enddo\n\n do j = 1, m\n der(j, n) = zero\n enddo\n end subroutine\n\n\n ! Calculates m derivatives of length n for the array var(m,n)\n ! and stores the result in der(m,n), where var is represented by a\n ! sine series. Note der is therefore a cosine series.\n ! *** Both var and der are assumed to be Fourier ***\n ! *** coeffiecients in their second argument ***\n subroutine deriv_s(m, n, k, var, der)\n integer, intent(in) :: m,n\n double precision, intent(in) :: k(n), var(m,n)\n double precision, intent(out) :: der(m, 0:n)\n integer :: i, j\n double precision :: ktmp\n\n ! Carry out differentiation by wavenumber multiplication:\n do i = 1, n-1\n ktmp = k(i)\n do j = 1, m\n der(j,i) = ktmp * var(j,i)\n enddo\n enddo\n\n do j = 1, m\n der(j, 0) = zero\n der(j, n) = zero\n enddo\n end subroutine\nend module\n", "meta": {"hexsha": "7fec59e982778948657ab218cd8329c735564635", "size": 4509, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/3d/utils/deriv1d.f90", "max_stars_repo_name": "matt-frey/epic", "max_stars_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2021-11-11T10:50:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T00:11:41.000Z", "max_issues_repo_path": "src/3d/utils/deriv1d.f90", "max_issues_repo_name": "matt-frey/epic", "max_issues_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 47, "max_issues_repo_issues_event_min_datetime": "2021-11-12T17:09:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-24T16:50:58.000Z", "max_forks_repo_path": "src/3d/utils/deriv1d.f90", "max_forks_repo_name": "matt-frey/epic", "max_forks_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.072, "max_line_length": 79, "alphanum_fraction": 0.4145043247, "num_tokens": 1012, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.659342066711745}} {"text": "!*********************************************************\n!>\n! Integration Functions:\n!\n! * Gauss-Legendre Integration:\n\nmodule integration\n implicit none\n\n private\n integer, parameter :: dp = kind(0.d0)\n real(dp) :: glx128(64), glw128(64)\n real(dp) :: glx512(256), glw512(256)\n real(dp) :: glx1024(512), glw1024(512)\n real(dp) :: g30k61_gx(15), g30k61_gw(15), g30k61_kx(31), g30k61_kw(31)\n\n public :: readGLParameters\n public :: gaussLegendre, gaussLegendreCmplx\n public :: readGKParameters\n\ncontains\n\n subroutine readGLParameters()\n implicit none\n integer :: i\n\n open(unit=1,file='data/gl128.dat',status='old')\n do i=1,64\n read(1,*) glx128(i), glw128(i)\n end do\n close(1)\n open(unit=1,file='data/gl512.dat',status='old')\n do i=1,256\n read(1,*) glx512(i), glw512(i)\n end do\n close(1)\n open(unit=1,file='data/gl1024.dat',status='old')\n do i=1,512\n read(1,*) glx1024(i), glw1024(i)\n end do\n close(1)\n end subroutine\n\n subroutine readGKParameters()\n implicit none\n integer :: i, numLines\n\n open(unit=1,file='data/g30k61.dat',status='old')\n read(1,*) numLines\n do i=1,numLines\n read(1,*) g30k61_gx(i), g30k61_gw(i)\n end do\n read(1,*) numLines\n do i=1,numLines\n read(1,*) g30k61_kx(i), g30k61_kw(i)\n end do\n close(1)\n end subroutine\n\n real(dp) function gaussLegendre(f,a,b,n,consts)\n implicit none\n integer :: i, n\n real(dp) :: consts(n), a, b, t0, dt, sumIntegral\n interface\n function f(n,c,x)\n integer, parameter :: dp = kind(0.d0)\n integer :: n\n real(dp) :: c(n), x, f\n end function f\n end interface\n\n t0 = (a+b)/2.d0\n dt = (b-a)/2.d0\n sumIntegral = 0.d0\n\n ! Using glx128 and glw128\n do i=64,1,-1\n sumIntegral = sumIntegral+glw128(i)*f(n,consts,t0-dt*glx128(i))\n end do\n do i=1,64\n sumIntegral = sumIntegral+glw128(i)*f(n,consts,t0+dt*glx128(i))\n end do\n\n ! Using glx512 and glw512\n ! do i=256,1,-1\n ! sumIntegral = sumIntegral+glw512(i)*f(n,consts,t0-dt*glx512(i))\n ! end do\n ! do i=1,256\n ! sumIntegral = sumIntegral+glw512(i)*f(n,consts,t0+dt*glx512(i))\n ! end do\n\n ! Using glx1024 and glw1024\n ! do i=512,1,-1\n ! sumIntegral = sumIntegral+glw1024(i)*f(n,consts,t0-dt*glx1024(i))\n ! end do\n ! do i=1,512\n ! sumIntegral = sumIntegral+glw1024(i)*f(n,consts,t0+dt*glx1024(i))\n ! end do\n gaussLegendre = sumIntegral*dt\n end function\n\n complex(dp) function gaussLegendreCmplx(f,a,b,n,consts)\n implicit none\n integer :: i, n\n real(dp) :: a, b, t0, dt, sumReal, sumCmplx\n complex(dp) :: consts(n)\n interface\n function f(n,c,x)\n integer, parameter :: dp = kind(0.d0)\n integer :: n\n real(dp) :: x\n complex(dp) :: c(n), f\n end function\n end interface\n\n t0 = (a+b)/2.d0\n dt = (b-a)/2.d0\n sumReal = 0.d0\n sumCmplx = 0.d0\n\n ! Using glx128 and glw128\n do i=64,1,-1\n sumReal = sumReal+glw128(i)*real(f(n,consts,t0-dt*glx128(i)))\n sumCmplx = sumCmplx+glw128(i)*aimag(f(n,consts,t0-dt*glx128(i)))\n end do\n do i=1,64\n sumReal = sumReal+glw128(i)*real(f(n,consts,t0+dt*glx128(i)))\n sumCmplx = sumCmplx+glw128(i)*aimag(f(n,consts,t0+dt*glx128(i)))\n end do\n\n ! Using glx512 and glw512\n ! do i=256,1,-1\n ! sumIntegral = sumIntegral+glw512(i)*f(n,consts,t0-dt*glx512(i))\n ! end do\n ! do i=1,256\n ! sumIntegral = sumIntegral+glw512(i)*f(n,consts,t0+dt*glx512(i))\n ! end do\n\n ! Using glx1024 and glw1024\n ! do i=512,1,-1\n ! sumIntegral = sumIntegral+glw1024(i)*f(n,consts,t0-dt*glx1024(i))\n ! end do\n ! do i=1,512\n ! sumIntegral = sumIntegral+glw1024(i)*f(n,consts,t0+dt*glx1024(i))\n ! end do\n gaussLegendreCmplx = cmplx(sumReal*dt,sumCmplx*dt,dp)\n end function\n\nend module\n", "meta": {"hexsha": "c019b637d8ecaade023c119673389831ce04d0fa", "size": 3859, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "srcOLD/integration.f90", "max_stars_repo_name": "joshhooker/numFortran", "max_stars_repo_head_hexsha": "14115d48e82a6bb898abd47ff749a9943aba52cb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "srcOLD/integration.f90", "max_issues_repo_name": "joshhooker/numFortran", "max_issues_repo_head_hexsha": "14115d48e82a6bb898abd47ff749a9943aba52cb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "srcOLD/integration.f90", "max_forks_repo_name": "joshhooker/numFortran", "max_forks_repo_head_hexsha": "14115d48e82a6bb898abd47ff749a9943aba52cb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.7266666667, "max_line_length": 73, "alphanum_fraction": 0.5941953874, "num_tokens": 1433, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6593420616650156}} {"text": " double precision function asGamma1(mt,besq,omsq)\nC-- Author: John M. Campbell and R.K. Ellis, January 2012 \nC-----Taken from formula (5) of\nC-----Fermilab-PUB-12-078-T\n implicit none\n include 'constants.f'\n include 'qcdcouple.f'\n include 'ewcouple.f'\n double precision mt,P0,P3,PP,PM,W0,WP,wm,YW,z,omsq,om,be,\n & P0b,P3b,Pmb,PPb,Ywb,Wmb,f,besq,ddilog,GammaInfty,term4,\n & term7,term9\n\nc Statement functions.\n P0(z)=0.5d0*(1d0-omsq+z)\n P3(z)=0.5d0*dsqrt(1d0+omsq**2+z**2-2d0*(omsq+z+omsq*z))\n PP(z)=P0(z)+P3(z)\n PM(z)=P0(z)-P3(z)\n W0(z)=0.5d0*(1d0+omsq-z)\n WP(z)=W0(z)+P3(z)\n WM(z)=W0(z)-P3(z)\n YW(z)=0.5d0*dlog(WP(z)/WM(z))\nc YP(z)=0.5d0*dlog(PP(z)/PM(z))\nc End statement functions.\n \n f=(1d0-besq)**2+omsq*(1d0+besq)-2d0*omsq**2\n om=sqrt(omsq)\n be=sqrt(besq)\n P0b=P0(besq)\n P3b=P3(besq)\n Pmb=PM(besq)\n Wmb=WM(besq)\nc WPb=WP(besq)\n PPb=PP(besq)\nc Ypb=YP(besq)\n Ywb=YW(besq)\n\n GammaInfty=Gf*mt**3/8d0/pi/rt2 \n if (besq .gt. 0d0) then\nc term4=Ypb*dlog(4d0*P3b**2/Ppb**2/Wpb)\n term4=(log(PPb)-log(be))*dlog(4d0*P3b**2*Wmb/(omsq*PPb**2))\n term7=\n & +(3d0-besq+11d0*besq**2-besq**3+omsq*(6d0-12d0*besq+2d0*besq**2)\n & -omsq**2*(21d0+5d0*besq)+12d0*omsq**3)*log(Ppb)\n & -(-besq+11d0*besq**2-besq**3+omsq*(-12d0*besq+2d0*besq**2)\n & -omsq**2*(5d0*besq))*log(be)\nc & -(3d0+6d0*omsq-omsq**2*21d0+12d0*omsq**3)*log(be)\n term9= \n & +6d0*(1d0-4d0*besq+3d0*besq**2+omsq*(3d0+besq)-4d0*omsq**2)\n & *(P3b-0.5d0*(1d0-omsq))*dlog(be)\n & +3d0*(1d0-omsq)*(-4d0*besq+3d0*besq**2+omsq*(besq))*dlog(be)\nc & +3d0*(1d0-omsq)*(1d0+3d0*omsq-4d0*omsq**2)*dlog(be)\n else\n term4=log(PPb)*dlog(4d0*P3b**2*Wmb/(omsq*PPb**2))\n term7=\n & +(3d0-besq+11d0*besq**2-besq**3+omsq*(6d0-12d0*besq+2d0*besq**2)\n & -omsq**2*(21d0+5d0*besq)+12d0*omsq**3)*log(Ppb)\n term9=0d0\n endif\n\n\nc--- equation for alphas*Gamma1 \n asGamma1=GammaInfty*ason2pi*Cf*(\n & 8d0*f*P0b*(ddilog(1d0-Pmb)-ddilog(1d0-Ppb)\n & -2d0*ddilog(1d0-Pmb/Ppb)+term4\n & +Ywb*dlog(Ppb))\n & +4d0*(1d0-besq)*((1d0-besq)**2+omsq*(1d0+besq)-4d0*omsq**2)*Ywb\n & +term7\n & +8d0*f*P3b*dlog(om/4d0/P3b**2)+term9\n & +(5d0-22d0*besq+5d0*besq**2+9d0*omsq*(1d0+besq)-6d0*omsq**2)*P3b)\n\n return\n end\n \n", "meta": {"hexsha": "0701fc84cdd68edb573dc4cbcdddd5796ab99f25", "size": 2422, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "MCFM-JHUGen/src/Topdecay/asGamma1.f", "max_stars_repo_name": "tmartini/JHUGen", "max_stars_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-06-08T13:09:28.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-04T19:59:36.000Z", "max_issues_repo_path": "MCFM-JHUGen/src/Topdecay/asGamma1.f", "max_issues_repo_name": "tmartini/JHUGen", "max_issues_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 64, "max_issues_repo_issues_event_min_datetime": "2015-06-24T15:08:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-25T04:59:32.000Z", "max_forks_repo_path": "MCFM-JHUGen/src/Topdecay/asGamma1.f", "max_forks_repo_name": "tmartini/JHUGen", "max_forks_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2015-05-04T22:15:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-06T10:04:40.000Z", "avg_line_length": 32.7297297297, "max_line_length": 72, "alphanum_fraction": 0.5598678778, "num_tokens": 1234, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810436809826, "lm_q2_score": 0.6959583187272711, "lm_q1q2_score": 0.6593377183543041}} {"text": "! annealing_revcom.f90 --\n! Template for the reverse communication interface\n! to the simulated annealing module\n!\n! Usage:\n! - Fill in the code to evaluate the function (in the\n! widest sense of the word) that must be minimised.\n! - If needed, fill in the code to write a report on\n! the progress\n! - Use the file as an include file for a function\n! or subroutine:\n!\n! subroutine minimize( f, range, params, x )\n! interface\n! real function f( x, params )\n! use PARAM_DEF\n! real, dimension(:), intent(in) :: x\n! type(FUNC_PARAMS), intent(in) :: params\n! end function\n! end interface\n!\n! real, dimension(2,:) :: range ! range and x are predefined\n! real, dimension(:) :: x ! variables, as are value and task\n!\n! type(FUNC_PARAMS) :: params\n!\n! include 'annealing_decl.f90'\n!\n! call set_parameters( anneal_data, ...)\n!\n! include 'filled_in.f90' ! Filled in template\n!\n! end subroutine\n!\n\n do\n call get_next_step( anneal_data, range, x, value, task )\n\n select case ( task )\n case ( annealing_value )\n !\n ! Fill in the evaluation of the function\n !\n value = f(x)\n\n case ( annealing_report )\n !\n ! Fill in the reporting code\n !\n write(*,*) 'Value so far: ', value ' - vector: ', x\n\n case ( annealing_done )\n exit\n end select\n enddo\n", "meta": {"hexsha": "2ece8884ddb0941116761377d680020b19c63455", "size": 1671, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/atlnts-backend-main/3rdparty/flibs-0.9/flibs/src/computing/annealing_revcom.f90", "max_stars_repo_name": "dorrabbkhan/atlnts-infrastructure", "max_stars_repo_head_hexsha": "2730b08317cc19fd74cc821c495788a0561b7983", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 828, "max_stars_repo_stars_event_min_datetime": "2016-06-20T15:08:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T06:32:10.000Z", "max_issues_repo_path": "flibs-0.9/flibs/src/computing/annealing_revcom.f90", "max_issues_repo_name": "TerribleDev/Fortran-docker-mvc", "max_issues_repo_head_hexsha": "0f44d444d9bcc6f4a6c6c59cc53b684c7b9a8e1a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2016-06-27T05:52:31.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-29T20:08:05.000Z", "max_forks_repo_path": "flibs-0.9/flibs/src/computing/annealing_revcom.f90", "max_forks_repo_name": "TerribleDev/Fortran-docker-mvc", "max_forks_repo_head_hexsha": "0f44d444d9bcc6f4a6c6c59cc53b684c7b9a8e1a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 46, "max_forks_repo_forks_event_min_datetime": "2016-06-21T02:15:50.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T06:32:39.000Z", "avg_line_length": 29.8392857143, "max_line_length": 79, "alphanum_fraction": 0.5038898863, "num_tokens": 378, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6591854765249733}} {"text": "program test_splines\nuse types, only: dp\nuse constants, only: pi\nuse utils, only: assert\nuse mesh, only: meshexp, linspace\nuse splines, only: spline3, iix, iixmin, spline3ders\nimplicit none\n\nreal(dp), parameter :: eps = 1e-12\nreal(dp), allocatable :: x(:), y(:), x2(:), y2(:)\ninteger :: N, N2, i, ip\nreal(dp) :: t1, t2\n\n! Basics:\nallocate(x(5), y(5))\nx = [0._dp, 1._dp, 2._dp, 3._dp, 4._dp]\ny = [0._dp, 1._dp, 2._dp, 3._dp, 4._dp]\ncall assert(all(abs(spline3(x, y, [0._dp]) - [0._dp]) < eps))\ncall assert(all(abs(spline3(x, y, [0._dp, 0.5_dp, 1._dp, 10._dp]) - &\n [0._dp, 0.5_dp, 1._dp, 10._dp]) < eps))\ncall assert(all(abs(spline3(x, y, [10._dp, 1._dp, 0._dp, 0.5_dp, 1._dp, &\n 10._dp]) - [10._dp, 1._dp, 0._dp, 0.5_dp, 1._dp, 10._dp]) < eps))\n\nx = linspace(0.0_dp, pi, 5)\ny = sin(x)\nallocate(x2(100))\nx2 = linspace(0.0_dp, pi, 100)\ncall assert(all(abs(spline3(x, y, x2) - sin(x2)) < 1.2e-2_dp))\ndeallocate(x, y, x2)\n\n! Test iix correctness:\nN = 100000\nN2 = 1000\nallocate(x(N+1), x2(N2+1))\nx = meshexp(1e-7_dp, 50._dp, 1e5_dp, N)\nx2 = meshexp(0._dp, 51._dp, 200._dp, N2)\ncall cpu_time(t1)\ndo i = 1, N2+1\n ip = iix(x2(i), x)\n if (x2(i) < x(1)) then\n call assert(ip == 1)\n elseif (x2(i) > x(size(x))) then\n call assert(ip == size(x)-1)\n else\n call assert(x(ip) <= x2(i) .and. x2(i) <= x(ip+1))\n end if\nend do\ncall cpu_time(t2)\nprint *, \"Pure iix:\", t2-t1\n\n! Test faster indexing:\ncall cpu_time(t1)\nip = 0\ndo i = 1, N2+1\n ip = iixmin(x2(i), x, ip)\n if (x2(i) < x(1)) then\n call assert(ip == 1)\n elseif (x2(i) > x(size(x))) then\n call assert(ip == size(x)-1)\n else\n call assert(x(ip) <= x2(i) .and. x2(i) <= x(ip+1))\n end if\nend do\ncall cpu_time(t2)\nprint *, \"Reducing size iix:\", t2-t1\ndeallocate(x, x2)\n\n! Correctness. This tests that BC at each end is correct:\nN = 10\nN2 = 1000\nallocate(x(N+1), y(N+1), x2(N2+1), y2(N2+1))\nx = meshexp(0._dp, pi/2, 1._dp, N)\ny = sin(x)\nx2 = meshexp(-pi/2, 3*pi/4, 1._dp, N2)\ny2 = spline3(x, y, x2)\ncall assert(abs(y2(1) - sin(x2(1))) < 5e-2_dp)\ncall assert(abs(y2(size(y2)) - sin(x2(size(x2)))) < 5e-2_dp)\n! 1st derivative\ncall spline3ders(x, y, x2, dynew=y2)\ncall assert(abs(y2(1) - cos(x2(1))) < 0.2_dp)\ncall assert(abs(y2(size(y2)) - cos(x2(size(x2)))) < 0.2_dp)\n! 2nd derivative\ncall spline3ders(x, y, x2, d2ynew=y2)\ncall assert(abs(y2(1) + sin(x2(1))) < 0.52_dp)\ncall assert(abs(y2(size(y2)) + sin(x2(size(x2)))) < 0.52_dp)\n\n\nx = meshexp(0._dp, 1._dp, 1._dp, N)\ny = x**2\nx2 = meshexp(-10._dp, 10._dp, 1._dp, N2)\ny2 = spline3(x, y, x2)\ncall assert(abs(y2(1) - x2(1)**2) < 1e-10_dp)\ncall assert(abs(y2(size(y2)) - x2(size(x2))**2) < 1e-10_dp)\n! 1st derivative\ncall spline3ders(x, y, x2, dynew=y2)\ncall assert(abs(y2(1) - 2*x2(1)) < 1e-10_dp)\ncall assert(abs(y2(size(y2)) - 2*x2(size(x2))) < 1e-10_dp)\n! 2nd derivative\ncall spline3ders(x, y, x2, d2ynew=y2)\ncall assert(maxval(abs(y2 - 2)) < 1e-10_dp)\ndeallocate(x, y, x2, y2)\n\n! Test speed\nN = 1000\nN2 = 10000\nallocate(x(N+1), y(N+1), x2(N2+1), y2(N2+1))\nx = meshexp(1e-7_dp, 50._dp, 1e5_dp, N)\nx2 = meshexp(0._dp, 51._dp, 200._dp, N2)\ny = sin(x)\ncall cpu_time(t1)\ny2 = spline3(x, y, x2)\ncall cpu_time(t2)\nprint *, \"Spline time:\", t2-t1\n\nend program\n", "meta": {"hexsha": "8fca7e215830003af0fc5ef9be8cfd7a31bf16e2", "size": 3222, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/splines/test_splines.f90", "max_stars_repo_name": "wave-scattering/fortran-utils", "max_stars_repo_head_hexsha": "464982bfc96359c7d37d9fd0185c6722e9a70046", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 163, "max_stars_repo_stars_event_min_datetime": "2015-02-12T09:55:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T23:08:58.000Z", "max_issues_repo_path": "tests/splines/test_splines.f90", "max_issues_repo_name": "wu2meng3/fortran-utils", "max_issues_repo_head_hexsha": "b43bd24cd421509a5bc6d3b9c3eeae8ce856ed88", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2016-10-08T21:18:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-24T15:11:50.000Z", "max_forks_repo_path": "tests/splines/test_splines.f90", "max_forks_repo_name": "wu2meng3/fortran-utils", "max_forks_repo_head_hexsha": "b43bd24cd421509a5bc6d3b9c3eeae8ce856ed88", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 48, "max_forks_repo_forks_event_min_datetime": "2015-03-20T10:26:44.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-23T11:09:47.000Z", "avg_line_length": 27.775862069, "max_line_length": 73, "alphanum_fraction": 0.5996275605, "num_tokens": 1446, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391595913457, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6591854604227305}} {"text": "module module1\n integer :: n\ncontains\n recursive subroutine sub1(x)\n integer, intent(inout) :: x\n integer :: y\n y = 0\n if (x < n) then\n x = x + 1\n y = x**2\n print *, 'x = ', x, ', y = ', y\n call sub1(x)\n print *, 'x = ', x, ', y = ', y\n end if\n end\nend\n\nprogram main\n use module1\n integer :: x = 0\n print *, 'Enter number of repeats'\n read (*, *) n\n call sub1(x)\nend program main\n", "meta": {"hexsha": "f6bb13052a09b36802225fb19091b36f7557219a", "size": 494, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "cnd/cnd.modelimpl/test/unit/data/org/netbeans/modules/cnd/modelimpl/trace/FortranFileModelTest/file1.f", "max_stars_repo_name": "leginee/netbeans", "max_stars_repo_head_hexsha": "814ad30e2d0a094f4aa3813bcbb5323a95a0b1d6", "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": "cnd/cnd.modelimpl/test/unit/data/org/netbeans/modules/cnd/modelimpl/trace/FortranFileModelTest/file1.f", "max_issues_repo_name": "leginee/netbeans", "max_issues_repo_head_hexsha": "814ad30e2d0a094f4aa3813bcbb5323a95a0b1d6", "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": "cnd/cnd.modelimpl/test/unit/data/org/netbeans/modules/cnd/modelimpl/trace/FortranFileModelTest/file1.f", "max_forks_repo_name": "leginee/netbeans", "max_forks_repo_head_hexsha": "814ad30e2d0a094f4aa3813bcbb5323a95a0b1d6", "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": 19.76, "max_line_length": 43, "alphanum_fraction": 0.4392712551, "num_tokens": 150, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430562234878, "lm_q2_score": 0.7931059511841119, "lm_q1q2_score": 0.6591845041761991}} {"text": "module input_parameters\n\timplicit none\n\tinteger,parameter :: n=10 !value of DEGREE of POLYNOMIAL -1 for eg. n=5 will generate 4th order polynomial \n\tinteger,parameter :: m=100 !number of discritisation points \n\treal(4),parameter :: lb=-1.0d0 !lower limit for x\n\treal(4),parameter :: rb=1.0d0 !upper limit for x\n\t\nend module input_parameters\n", "meta": {"hexsha": "e4650caa81cbc26f53edcb0bbed168aa37282fd0", "size": 342, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "newton_ip/newton_io/newton_io.f90", "max_stars_repo_name": "akkiturb/Ilkay-s-Fortran-Class", "max_stars_repo_head_hexsha": "0600640574354052a5a7d87bad520b8a03650d0e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-12-18T19:31:01.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-18T19:31:01.000Z", "max_issues_repo_path": "newton_ip/newton_io/newton_io.f90", "max_issues_repo_name": "akkiturb/Scientific-computing-in-Fortran", "max_issues_repo_head_hexsha": "0600640574354052a5a7d87bad520b8a03650d0e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "newton_ip/newton_io/newton_io.f90", "max_forks_repo_name": "akkiturb/Scientific-computing-in-Fortran", "max_forks_repo_head_hexsha": "0600640574354052a5a7d87bad520b8a03650d0e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-02-04T19:45:56.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-10T14:22:05.000Z", "avg_line_length": 38.0, "max_line_length": 108, "alphanum_fraction": 0.7514619883, "num_tokens": 101, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.6591844934772513}} {"text": " SUBROUTINE MB03RX( JOBV, N, KL, KU, A, LDA, X, LDX, WR, WI,\n $ DWORK )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To reorder the diagonal blocks of the principal submatrix between\nC the indices KL and KU (KU >= KL) of a real Schur form matrix A\nC together with their eigenvalues, using orthogonal similarity\nC transformations, such that the block specified by KU is moved in\nC the position KL. The transformations are optionally postmultiplied\nC in a given matrix X.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC JOBV CHARACTER*1\nC Specifies whether or not the transformations are\nC accumulated, as follows:\nC = 'N': The transformations are not accumulated;\nC = 'V': The transformations are accumulated in X (the\nC given matrix X is updated).\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The order of the matrices A and X. N >= 0.\nC\nC KL (input) INTEGER\nC The lower boundary index for the rows and columns of the\nC principal submatrix of A whose diagonal blocks are to be\nC reordered, and also the target position for the block to\nC be moved. 1 <= KL <= KU <= N.\nC\nC KU (input/output) INTEGER\nC On entry, KU specifies the upper boundary index for the\nC rows and columns of the principal submatrix of A whose\nC diagonal blocks are to be reordered, and also the original\nC position for the block to be moved. 1 <= KL <= KU <= N.\nC On exit, KU specifies the upper boundary index for the\nC rows and columns of the principal submatrix of A whose\nC diagonal blocks have been reordered. The given value will\nC be increased by 1 if the moved block was 2-by-2 and it has\nC been replaced by two 1-by-1 blocks. Otherwise, its input\nC value is preserved.\nC\nC A (input/output) DOUBLE PRECISION array, dimension (LDA,N)\nC On entry, the leading N-by-N part of this array must\nC contain the matrix A in real Schur canonical form.\nC On exit, the leading N-by-N part of this array contains\nC the ordered real Schur canonical form.\nC\nC LDA INTEGER\nC The leading dimension of array A. LDA >= MAX(1,N).\nC\nC X (input/output) DOUBLE PRECISION array, dimension (LDX,N)\nC On entry, if JOBV = 'V', the leading N-by-N part of this\nC array must contain a given matrix X.\nC On exit, if JOBV = 'V', the leading N-by-N part of this\nC array contains the product of the given matrix X and the\nC transformation matrix that performed the reordering of A.\nC If JOBV = 'N', this array is not referenced.\nC\nC LDX INTEGER\nC The leading dimension of array X.\nC LDX >= 1, if JOBV = 'N';\nC LDX >= MAX(1,N), if JOBV = 'V'.\nC\nC WR, (input/output) DOUBLE PRECISION arrays, dimension (N)\nC WI On entry, these arrays must contain the real and imaginary\nC parts, respectively, of the eigenvalues of the matrix A.\nC On exit, these arrays contain the real and imaginary\nC parts, respectively, of the eigenvalues of the matrix A,\nC possibly reordered.\nC\nC Workspace\nC\nC DWORK DOUBLE PRECISION array, dimension (N)\nC\nC METHOD\nC\nC An attempt is made to move the block in the position (KU,KU) to\nC the position (KL,KL) by a sequence of orthogonal similarity\nC transformations, each swapping two consecutive blocks. The\nC standard algorithm [1], [2] usually succeeds to perform this\nC reordering. A failure of this algorithm means that two consecutive\nC blocks (one of them being the desired block possibly moved) are\nC too close to swap. In such a case, the leading block of the two\nC is tried to be moved in the position (KL,KL) and the procedure is\nC repeated.\nC\nC REFERENCES\nC\nC [1] Stewart, G.W.\nC HQR3 and EXCHQZ: FORTRAN subroutines for calculating and\nC ordering the eigenvalues of a real upper Hessenberg matrix.\nC ACM TOMS, 2, pp. 275-280, 1976.\nC\nC [2] Anderson, E., Bai, Z., Bischof, C., Demmel, J., Dongarra, J.,\nC Du Croz, J., Greenbaum, A., Hammarling, S., McKenney, A.,\nC Ostrouchov, S., and Sorensen, D.\nC LAPACK Users' Guide: Second Edition.\nC SIAM, Philadelphia, 1995.\nC\nC NUMERICAL ASPECTS\nC\nC The algorithm is numerically stable. If some eigenvalues are\nC ill-conditioned, their returned values could differ much from\nC their input values.\nC\nC CONTRIBUTOR\nC\nC V. Sima, Katholieke Univ. Leuven, Belgium, June 1998.\nC\nC REVISIONS\nC\nC -\nC\nC KEYWORDS\nC\nC Eigenvalue, orthogonal transformation, real Schur form.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO\n PARAMETER ( ZERO = 0.0D0 )\nC .. Scalar Arguments ..\n CHARACTER JOBV\n INTEGER KL, KU, LDA, LDX, N\nC .. Array Arguments ..\n DOUBLE PRECISION A(LDA,*), DWORK(*), WI(*), WR(*), X(LDX,*)\nC .. Local Scalars ..\n INTEGER IERR, IFST, ILST, L\nC .. External Subroutines ..\n EXTERNAL DTREXC\nC .. Intrinsic Functions ..\n INTRINSIC ABS, SQRT\nC .. Executable Statements ..\nC\n IF ( KU.GT.KL ) THEN\nC\nC Try to move the block in position (KU,KU) to position (KL,KL).\nC\n IFST = KU\nC REPEAT\n 10 CONTINUE\n ILST = KL\n CALL DTREXC( JOBV, N, A, LDA, X, LDX, IFST, ILST, DWORK, IERR )\n IF ( IERR.NE.0 ) THEN\nC\nC During calculations, two adjacent blocks were too close\nC to swap; the desired block cannot be moved further, but the\nC block above it is suitable and is tried for moving. The\nC number of repeat cycles is usually 1, and at most the number\nC of blocks between the current position and the position KL.\nC\n IFST = ILST - 1\n IF ( IFST.GT.1 ) THEN\n IF ( A(IFST,IFST-1).NE.ZERO )\n $ IFST = ILST - 2\n END IF\n IF ( ILST.GT.KL )\n $ GO TO 10\n END IF\nC UNTIL ( ILST.EQ.KL on output from DTREXC )\nC\nC Recompute the eigenvalues for the modified part of A.\nC Note that KU must be incremented if the moved block was 2-by-2\nC and it has been replaced by two 1-by-1 blocks.\nC\n IF ( WI(KU).NE.ZERO ) THEN\n IF ( A(KU+1,KU).EQ.ZERO )\n $ KU = KU + 1\n END IF\nC\n L = KL\nC WHILE ( L.LT.KU .OR. ( L.EQ.KU .AND. L.LT.N ) ) DO\n 20 IF ( L.LT.KU .OR. ( L.EQ.KU .AND. L.LT.N ) ) THEN\n IF ( A(L+1,L).NE.ZERO ) THEN\nC\nC A 2x2 block.\nC\n WR(L) = A(L,L)\n WR(L+1) = WR(L)\n WI(L) = SQRT( ABS( A(L,L+1) ) )*\n $ SQRT( ABS( A(L+1,L) ) )\n WI(L+1) = -WI(L)\n L = L + 2\n ELSE\nC\nC An 1x1 block.\nC\n WR(L) = A(L,L)\n WI(L) = ZERO\n L = L + 1\n END IF\n GO TO 20\n ELSE IF ( L.EQ.N ) THEN\n WR(L) = A(L,L)\n WI(L) = ZERO\n END IF\nC END WHILE 20\n END IF\nC\n RETURN\nC *** Last line of MB03RX ***\n END\n", "meta": {"hexsha": "54641656970ffad38e9801effabe1c311ede24d4", "size": 7639, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB03RX.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB03RX.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB03RX.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 35.8638497653, "max_line_length": 72, "alphanum_fraction": 0.5698389842, "num_tokens": 2133, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072386, "lm_q2_score": 0.7185944046238981, "lm_q1q2_score": 0.6591685617740567}} {"text": "!*********************************************************************\n! This file is part of Polylogarithm.\n!\n! Polylogarithm is licenced under the MIT License.\n!*********************************************************************\n\n\n!*********************************************************************\n!> @brief Complex polylogarithm \\f$\\operatorname{Li}_5(z)\\f$\n!> @param z complex argument\n!> @return \\f$\\operatorname{Li}_5(z)\\f$\n!> @author Alexander Voigt\n!*********************************************************************\ndouble complex function cdli5(z)\n implicit none\n double complex :: z, u, u2, u4, u8, c4, lmz, rest, fast_pos_cdlog\n double precision :: rz, iz, nz, pz, lnz, arg\n double precision, parameter :: PI = 3.1415926535897932D0\n double precision, parameter :: PI2 = 9.8696044010893586D0\n double precision, parameter :: PI4 = 97.409091034002437D0\n double precision, parameter :: zeta5 = 1.0369277551433699D0\n double precision, parameter :: c1 = 1.0823232337111382D0 ! zeta(4)\n double precision, parameter :: c2 = 0.60102845157979714D0 ! zeta(3)/2\n double precision, parameter :: c3 = 0.27415567780803774D0\n double precision, parameter :: c5 = -1D0/240\n double precision, parameter :: bf(19) = (/ &\n 1.0D0 , -15.0D0/32.0D0 , &\n 1.3953189300411523D-01, -2.8633777006172840D-02, &\n 4.0317412551440329D-03, -3.3985018004115226D-04, &\n 4.5445184621617666D-06, 2.3916808048569012D-06, &\n -1.2762692600122747D-07, -3.1628984306505932D-08, &\n 3.2848118445335192D-09, 4.7613713995660579D-10, &\n -8.0846898171909830D-11, -7.2387648587737207D-12, &\n 1.9439760115173968D-12, 1.0256978405977236D-13, &\n -4.6180551009884830D-14, -1.1535857196470580D-15, &\n 1.0903545401333394D-15 /)\n double precision, parameter :: cs(6) = (/ &\n -1.1574074074074074D-04, 2.0667989417989418D-07, &\n -1.0935444136502338D-09, 8.6986487449450412D-12, &\n -8.6899587861588824D-14, 1.0081254080218813D-15 /)\n\n rz = real(z)\n iz = aimag(z)\n\n if (iz .eq. 0) then\n if (rz .eq. 0) then\n cdli5 = 0\n return\n endif\n if (rz .eq. 1) then\n cdli5 = zeta5\n return\n endif\n if (rz .eq. -1) then\n cdli5 = -15*zeta5/16\n return\n endif\n endif\n\n nz = rz**2 + iz**2\n pz = datan2(iz, rz)\n lnz = 0.5D0*log(nz)\n\n if (lnz**2 + pz**2 .lt. 1) then ! |log(z)| < 1\n u = dcmplx(lnz, pz) ! log(z)\n u2 = u**2\n c4 = (25D0/12 - fast_pos_cdlog(-u))/24\n cdli5 = &\n zeta5 + u * c1 + &\n u2 * (c2 + u * c3 + &\n u2 * (c4 + u * c5 + &\n u2 * (cs(1) + &\n u2 * (cs(2) + &\n u2 * (cs(3) + &\n u2 * (cs(4) + &\n u2 * (cs(5) + &\n u2 * (cs(6)))))))))\n return\n endif\n\n if (nz .le. 1) then\n u = -fast_pos_cdlog(1 - z)\n rest = 0\n else ! nz > 1\n if (pz .gt. 0) then\n arg = pz - PI\n else\n arg = pz + PI\n endif\n lmz = dcmplx(lnz, arg) ! log(-z)\n u = -fast_pos_cdlog(1 - 1/z)\n rest = -lmz*(7*PI4 + lmz**2*(10*PI2 + 3*lmz**2))/360\n endif\n\n u2 = u**2\n u4 = u2**2\n u8 = u4**2\n\n cdli5 = &\n rest + &\n u*bf(1) + &\n u2*(bf(2) + u*bf(3)) + &\n u4*(bf(4) + u*bf(5) + u2*(bf(6) + u*bf(7))) + &\n u8*(bf(8) + u*bf(9) + u2*(bf(10) + u*bf(11)) + &\n u4*(bf(12) + u*bf(13) + u2*(bf(14) + u*bf(15)))) + &\n u8*u8*(bf(16) + u*bf(17) + u2*(bf(18) + u*bf(19)))\n\nend function cdli5\n", "meta": {"hexsha": "92a81b20ec9a9751601e8966cd6f15c409f31ea9", "size": 3798, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/Li5.f90", "max_stars_repo_name": "Expander/dilogarithm", "max_stars_repo_head_hexsha": "ad86038206895ab5bff79a26294f4bb5c5634eb5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-05-04T14:47:41.000Z", "max_stars_repo_stars_event_max_datetime": "2017-08-02T13:13:45.000Z", "max_issues_repo_path": "src/fortran/Li5.f90", "max_issues_repo_name": "Expander/dilogarithm", "max_issues_repo_head_hexsha": "ad86038206895ab5bff79a26294f4bb5c5634eb5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/fortran/Li5.f90", "max_forks_repo_name": "Expander/dilogarithm", "max_forks_repo_head_hexsha": "ad86038206895ab5bff79a26294f4bb5c5634eb5", "max_forks_repo_licenses": ["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.8440366972, "max_line_length": 74, "alphanum_fraction": 0.4631384939, "num_tokens": 1398, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072387, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6591685562459131}} {"text": "PROGRAM NONSQUARES\n\n IMPLICIT NONE\n\n INTEGER :: m, n, nonsqr\n\n DO n = 1, 22\n nonsqr = n + FLOOR(0.5 + SQRT(REAL(n))) ! or could use NINT(SQRT(REAL(n)))\n WRITE(*,*) nonsqr\n END DO\n\n DO n = 1, 1000000\n nonsqr = n + FLOOR(0.5 + SQRT(REAL(n)))\n m = INT(SQRT(REAL(nonsqr)))\n IF (m*m == nonsqr) THEN\n WRITE(*,*) \"Square found, n=\", n\n END IF\n END DO\n\nEND PROGRAM NONSQUARES\n", "meta": {"hexsha": "6d06ffced145b56ca93139c70f92347ea6b9b69d", "size": 400, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Sequence-of-non-squares/Fortran/sequence-of-non-squares.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/Sequence-of-non-squares/Fortran/sequence-of-non-squares.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/Sequence-of-non-squares/Fortran/sequence-of-non-squares.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 19.0476190476, "max_line_length": 80, "alphanum_fraction": 0.565, "num_tokens": 161, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026550642019, "lm_q2_score": 0.7185943865443352, "lm_q1q2_score": 0.6591685386913501}} {"text": "C 12/12/2003 VERSION CHANGED ON AUG 26 2005. IMPLICIT NONE WAS ADDED.\r\nC Same as SUNLOC August 01, 1998, 01:04:31 PM, except this also returns R.\r\n\tSUBROUTINE SUNLOC1(LYEAR,IDAYJL,ISECDY, SUNLAT,SUNLON,R)\r\n\tIMPLICIT NONE\r\n\r\n\tREAL(8) XDAY,TX\r\n REAL(4) Z(3),X(3),TOSUN(3),PROJECT(3)\r\n\treal(8) D01,D11,S11,C11,S21,C21\r\n\treal(8) D02,D12,S12,C12,S22,C22\r\n\treal(8) slope,period,ecc,xinc,rad,xfac,alpha,t0,t,ang,cosinc\r\n\treal(8) amag,xphi,eot,hang,sinang,cosang,sinhang,coshang,corrlat,corrlon\r\n\treal(4) phi\r\n\tinteger(4) istart,lyear,idayjl,isecdy\r\n\treal(4) sunlat,sunlon,r\r\n\r\n\tDATA D01,D11,S11,C11,S21,C21/ -1.15538E-3, -6.86302E-8, -8.48082E-1, -1.29184E-1, -3.18681E-2, -5.59290E-4/\r\n\tDATA D02,D12,S12,C12,S22,C22/ -1.57115E-3, -3.82973E-5, -9.91281E-4, -2.75336E-2, 1.83422E-2, 1.09567E-3/\r\n\tDATA SLOPE/1.81818E-5/ !=0.2/11000.0\r\n\tDATA PERIOD,ECC,XINC/365.2422,0.016708617,23.43929111/\r\n DATA RAD/0.01745329252/\r\n\tDATA ISTART/1/\r\n\r\n\tIF(ISTART.EQ.1) THEN\r\n XFAC=360./PERIOD \r\n ALPHA=XFAC*(355.5674 - 0.3210) !WINTER SOLSTICES DEC 21 13:37, 2000; ADDITION OFFSET OF .321 TO COMPENSTATE FOR ECC\r\n\tT0=XFAC*2.2083 !PERIHELION JAN 3, 5 HOURS, 2000\r\n\tZ(1)=SIND(XINC)*COSD(ALPHA)\r\n\tZ(2)=SIND(XINC)*SIND(ALPHA)\r\n\tZ(3)=COSD(XINC)\r\n\tX(1)=COSD(XINC)*COSD(ALPHA+180)\r\n\tX(2)=COSD(XINC)*SIND(ALPHA+180)\r\n\tX(3)=SIND(XINC)\r\n\tENDIF\r\n\r\n\tIF(LYEAR.LT.1950 .OR. LYEAR.GT.2099) STOP 'ERROR IN LYEAR'\r\n\tXDAY=365.D0*(LYEAR-1950) + (IDAYJL-1) + ISECDY/86400.D0 + INT((LYEAR-1949)/4) - 18262.D0 !TDAY=0 FOR JAN 1 0Z, 2000 \r\n TX=XFAC*XDAY\r\n T=MOD(TX,360.D0)\r\n IF(T.LT.0) T=T+360. \r\n \r\n ANG=T+2.*ECC*(SIND(T-T0)+SIND(T0))/RAD \r\n R=1.-ECC*COSD(T-T0)\r\n\r\n TOSUN(1)=-COSD(ANG) \r\n TOSUN(2)=-SIND(ANG) \r\n TOSUN(3)=0\r\n COSINC=DOT_PRODUCT(TOSUN,Z) \r\n SUNLAT=90-ACOSD(COSINC) \r\n\r\n PROJECT=TOSUN - COSINC*Z \r\n\tAMAG=SQRT(PROJECT(1)**2 + PROJECT(2)**2 + PROJECT(3)**2)\r\n\tPROJECT=PROJECT/AMAG\r\n CALL FINDANG(X,PROJECT,Z, PHI) \r\n XPHI=PHI-9.6 -0.326\r\n\tEOT=T-XPHI\r\n\tIF(EOT.LT.-180) EOT=EOT+360\r\n\tIF(EOT.GT. 180) EOT=EOT-360\r\n\r\n\tSUNLON=180-360*ISECDY/86400. - EOT\r\n\tIF(SUNLON.LT.0) SUNLON=SUNLON+360.\r\n\r\n\tANG=XFAC*XDAY\r\n\tHANG=0.5*ANG\r\n\tSINANG=SIND(ANG)\r\n\tCOSANG=COSD(ANG)\r\n\tSINHANG=SIND(HANG)\r\n\tCOSHANG=COSD(HANG)\r\n\tCORRLAT = D01 + D11*XDAY + SLOPE*XDAY*(S11*SINANG + C11*COSANG + S21*SINHANG + C21*COSHANG)\r\n\tCORRLON = D02 + D12*XDAY + S12*SINANG + C12*COSANG + S22*SINHANG + C22*COSHANG\r\n\r\n\tSUNLAT=SUNLAT + CORRLAT\r\n\tSUNLON=SUNLON + CORRLON\r\n\tIF(SUNLON.LT. 0) SUNLON=SUNLON+360\r\n\tIF(SUNLON.GE.360) SUNLON=SUNLON-360\r\n\r\n RETURN\r\n END \r\n\r\n\r\n \r\n SUBROUTINE FINDANG(X,Y,Z, ANG) \r\n\timplicit none \r\n \r\n\tREAL(4) X(3),Y(3),Z(3),D(3)\r\n\treal(4) sinang,cosang,ang\r\n\r\n D(1)=X(2)*Y(3)-X(3)*Y(2) \r\n D(2)=X(3)*Y(1)-X(1)*Y(3) \r\n D(3)=X(1)*Y(2)-X(2)*Y(1) \r\n SINANG=SQRT(D(1)**2+D(2)**2+D(3)**2) \r\n\tIF(DOT_PRODUCT(D,Z).LT.0) SINANG=-SINANG \r\n COSANG=DOT_PRODUCT(X,Y) \r\n\tANG=ATAN2D(SINANG,COSANG)\r\n\tIF(ANG.LT.0) ANG=ANG+360.\r\n RETURN \r\n END \r\n\r\n\r\n", "meta": {"hexsha": "0198505ea2a7fb034a66ae1a98e280fb145262f4", "size": 3625, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "subroutines/sunloc1.f", "max_stars_repo_name": "cgentemann/posh_diurnal_model_fortran", "max_stars_repo_head_hexsha": "227fbea81016da29c3925a65fc2b3dcb5958e822", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-10-05T12:34:07.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-05T12:34:07.000Z", "max_issues_repo_path": "subroutines/sunloc1.f", "max_issues_repo_name": "cgentemann/posh_diurnal_model_fortran", "max_issues_repo_head_hexsha": "227fbea81016da29c3925a65fc2b3dcb5958e822", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "subroutines/sunloc1.f", "max_forks_repo_name": "cgentemann/posh_diurnal_model_fortran", "max_forks_repo_head_hexsha": "227fbea81016da29c3925a65fc2b3dcb5958e822", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.6161616162, "max_line_length": 122, "alphanum_fraction": 0.5197241379, "num_tokens": 1451, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026528034425, "lm_q2_score": 0.7185943805178139, "lm_q1q2_score": 0.6591685315386371}} {"text": " Program zcposv_example\n\n! ZCPOSV Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_interfaces, Only: zcposv\n Use lapack_precision, Only: sp, dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nin = 5, nout = 6\n! .. Local Scalars ..\n Integer :: i, info, iter, lda, ldb, ldx, n, r\n! .. Local Arrays ..\n Complex (Kind=dp), Allocatable :: a(:, :), b(:, :), work(:, :), x(:, :)\n Complex (Kind=sp), Allocatable :: swork(:)\n Real (Kind=dp), Allocatable :: rwork(:)\n! .. Executable Statements ..\n Write (nout, *) 'ZCPOSV Example Program Results'\n Write (nout, *)\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n, r\n lda = n\n ldb = n\n ldx = n\n Allocate (a(lda,n), b(ldb,r), work(n,r), x(ldx,r), swork(n*(n+ &\n r)), rwork(n))\n\n! Read A and B from data file\n\n Read (nin, *)(a(i,i:n), i=1, n)\n Read (nin, *)(b(i,1:r), i=1, n)\n\n! Solve the equations Ax = b for x\n Call zcposv('U', n, r, a, lda, b, ldb, x, ldx, work, swork, rwork, iter, &\n info)\n\n If (info==0) Then\n\n! Print solution\n\n Write (nout, *) 'Solution'\n Write (nout, 100)(x(i,1:r), i=1, n)\n\n Else\n Write (nout, 110) 'The leading minor of order ', info, &\n ' is not positive definite'\n End If\n\n100 Format ((3X,4(' (',F7.4,',',F7.4,')',:)))\n110 Format (1X, A, I3, A)\n End Program\n", "meta": {"hexsha": "0829327b998ae750488c46734fd26fe8161d3be9", "size": 1673, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/zcposv_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/zcposv_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/zcposv_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 28.8448275862, "max_line_length": 90, "alphanum_fraction": 0.5355648536, "num_tokens": 540, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677660619633, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.6591252312151789}} {"text": "!======================================================================================================\n!> Program: cpFlow !!\n!> Details: PROGRAM TO COMPUTE FLOW PARAMETERS FOR COUETTE-POISEUILLE FLOW USING MIXING LENGTH MODEL !!\n!> @Author: Aakash PATIL, IMP Turbulence !!\n!> Mentor: Dr. Jean-Philip LAVAL !! \n!======================================================================================================\nprogram cpflow\n\nuse module_parameters\nuse module_grid\nuse module_triSolve\nuse module_solver\nimplicit none \n INTEGER\t\t :: NUM_CASE !Case number under consideration \n\tREAL(8),ALLOCATABLE :: YHAD(:),YPAD(:) !Grid parameters \n CHARACTER(len=15) :: OUTPUTFILE !Output filename\n REAL(8) :: VW, H, DPDX !Input conditions for a given case number\n !VW is the Velocity of Wall, H is the Height of Channel, and DPDX is Pressure Gradient\n CHARACTER(len=100) :: EXCOMMAND !String for writing command line arguments\n \n print*, \"########################################\"\n print*, \"###### Couette_Poiseuille-FlowCode #####\" \n print*, \"########################################\"\n \n !CASE SELECTION\n print*,\"Please Enter a Case Number(from 1 to 18): \"\n read*, NUM_CASE\n !do NUM_CASE=1,18 !end of RunAllCasesLoop\n !NUM_CASE=15 !single case\n \n !Checking Case Number and Managing Filenames\n if (NUM_CASE<1 .OR. NUM_CASE>18) then\n print *, \"Invalid Case Number. Exiting\"\n STOP \n else if (NUM_CASE < 10) then\n write (OUTPUTFILE, \"(A6,I1,A8)\") \"Case_0\",NUM_CASE,\"_sim.dat\"\n else if (NUM_CASE<19) then\n write (OUTPUTFILE, \"(A5,I2,A8)\") \"Case_\",NUM_CASE,\"_sim.dat\"\n else\n print *, \"Invalid Case Number. Exiting\"\n STOP \n endif\n \n !Read the Parameters\n print *, \"### Fetching Values from the Parameters File ###\" \n CALL case_select(NUM_CASE,VW, H, DPDX)\n print *, \"The selected CASE NUMBER is \",NUM_CASE\n print *, \"Here, the values of VW, H, DPDX are \",VW, H, DPDX, \"respectively.\"\n print *, \"The data generated will be saved to file \", OUTPUTFILE \n\n\t!Call Main Functions\n\tprint *, \"### Generating Grid ###\"\n\tALLOCATE(YPAD(N),YHAD(N))\n\tCALL sGrid_Generator(H,N,ALPHA,YPAD,YHAD)\n\tprint *, \"### Solving for Flow Parameters ###\"\n CALL flowSolve(VW,H,N,YPAD,YHAD,ALPHA,DPDX,KIN_VIS,CONV_CRIT,MAX_ITER,OUTPUTFILE,NUM_CASE)\n DEALLOCATE(YPAD,YHAD) \t\n \t\n !Data Management\n print *, \"### Organizing Data Files ###\"\n print *, \"Copied Successfully \"\n print *, \"Copying Generated simulation data to the directory '../Simulated_Data'\"\n EXCOMMAND=\"cp \"//OUTPUTFILE//\" ../Simulated_Data/\"//OUTPUTFILE\n print *, trim(EXCOMMAND)\n call system(trim(EXCOMMAND))\n print *, \"Copied Successfully \"\n\n !Automatic Plotting\n print *, \"### Plotting ###\"\n EXCOMMAND=\"python autoplotting.py --file \"//OUTPUTFILE\n if (PLOT=='Y') then\n print *, \"Creating Plots\"\n print *, trim(EXCOMMAND)\n call system(trim(EXCOMMAND))\n else\n print *, \"Auto Plotting Disabled\" \n print *, \"For direct plotting, type 'python autoplotting.py --file \",OUTPUTFILE,\" '\"\n end if\n\n print*, \"Cleaning Execution Directory\"\n call system(\"rm *.dat\")\n\n !end do !end of RunAllCasesLoop\nend program\n", "meta": {"hexsha": "51d2e8f72da660159a67281caf1ca8a939b450a0", "size": 3818, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "dev/src/v9/cpFlow/src/cpFlow.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/v9/cpFlow/src/cpFlow.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/v9/cpFlow/src/cpFlow.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": 44.9176470588, "max_line_length": 104, "alphanum_fraction": 0.5065479309, "num_tokens": 855, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936878, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6591252105202169}} {"text": "! { dg-do run }\n! Tests the fix for pr32682, in which the scalarization loop variables\n! were not being determined when 'c' came first in an expression.\n!\n! Contributed by Janus Weil \n!\nprogram matrix\n\n implicit none\n real,dimension(2,2),parameter::c=reshape((/1,2,3,4/),(/2,2/))\n real,dimension(2,2)::m, n\n\n m=f()+c\n if (any (m .ne. reshape((/2,3,4,5/),(/2,2/)))) STOP 1\n m=c+f()\n if (any (m .ne. reshape((/2,3,4,5/),(/2,2/)))) STOP 2\n call sub(m+f())\n if (any (n .ne. reshape((/3,4,5,6/),(/2,2/)))) STOP 3\n call sub(c+m)\n if (any (n .ne. reshape((/3,5,7,9/),(/2,2/)))) STOP 4\n call sub(f()+c)\n if (any (n .ne. reshape((/2,3,4,5/),(/2,2/)))) STOP 5\n call sub(c+f())\n if (any (n .ne. reshape((/2,3,4,5/),(/2,2/)))) STOP 6\n\ncontains\n\n function f() \n implicit none\n real, dimension(2,2)::f\n f=1\n end function f\n\n subroutine sub(a)\n implicit none\n real, dimension(2,2)::a\n n = a\n end subroutine sub\n\nend program matrix\n", "meta": {"hexsha": "eeda602380a0d5ea5605ebf488a49b23b1c98ff1", "size": 976, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/scalarize_parameter_array_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/scalarize_parameter_array_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/scalarize_parameter_array_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": 23.8048780488, "max_line_length": 70, "alphanum_fraction": 0.5788934426, "num_tokens": 395, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7718434978390746, "lm_q2_score": 0.8539127566694178, "lm_q1q2_score": 0.65908700895713}} {"text": "C$Procedure SPHLAT ( Spherical to latitudinal coordinates )\n \n SUBROUTINE SPHLAT ( R, COLAT, LONGS, RADIUS, LONG, LAT )\n \nC$ Abstract\nC\nC Convert from spherical coordinates to latitudinal coordinates.\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 CONVERSION, COORDINATES\nC\nC$ Declarations\n \n DOUBLE PRECISION R\n DOUBLE PRECISION COLAT\n DOUBLE PRECISION LONGS\n DOUBLE PRECISION RADIUS\n DOUBLE PRECISION LONG\n DOUBLE PRECISION LAT\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC R I Distance of the point from the origin.\nC COLAT I Angle of the point from positive Z axis (radians).\nC LONGS I Angle of the point from the XZ plane (radians).\nC RADIUS O Distance of a point from the origin\nC LONG O Angle of the point from the XZ plane in radians\nC LAT O Angle of the point from the XY plane in radians\nC\nC$ Detailed_Input\nC\nC R Distance of the point from the origin.\nC\nC COLAT Angle between the vector from the origin to the point\nC and the positive Z axis in radians.\nC\nC LONGS Angle of the point from the XZ plane (radians).\nC\nC$ Detailed_Output\nC\nC RADIUS Distance of a point from the origin\nC\nC LONG Angle of the point from the XZ plane in radians. LONG\nC is set equal to LONGS.\nC\nC LAT Angle of the point from the XY plane in radians. LAT\nC is computed as pi/2 - COLAT.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC Error free.\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC This routine returns the latitudinal coordinates of a point\nC whose position is input in spherical coordinates.\nC\nC Latitudinal coordinates are defined by a distance from a central\nC reference point, an angle from a reference meridian, and an angle\nC above the equator of a sphere centered at the central reference\nC point.\nC\nC Spherical coordinates are defined by a distance from a central\nC reference point, an angle from a reference meridian, and an angle\nC from the z-axis.\nC\nC$ Examples\nC\nC\nC Latitude is obtained by subtracting co-latitude from HALFPI()\nC Radius and longitude mean the same thing in both latitudinal\nC and spherical coordinates. The table below lists LAT and\nC corresponding COLAT in terms of degrees.\nC\nC LAT COLAT\nC ------ ------\nC 0 90\nC 20 70\nC 45 45\nC -30 120\nC 90 0\nC -45 135\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC W.L. Taber (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.2, 26-JUL-2016 (BVS)\nC\nC Minor headers edits.\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 spherical to latitudinal coordinates\nC\nC-&\n \n \nC$ Revisions\nC\nC- Beta Version 1.0.1, 1-Feb-1989 (WLT)\nC\nC Example section of header upgraded.\nC\nC-&\n \n \nC\nC SPICELIB functions\nC\n DOUBLE PRECISION HALFPI\n \nC\nC Local Variables\nC\n DOUBLE PRECISION RR\n DOUBLE PRECISION LATTUD\n \nC\nC Convert to latitudinal coordinates, storing the results in\nC temporary variables\nC\n RR = R\n LATTUD = HALFPI() - COLAT\n \nC\nC Move the results to the output variables.\nC\n LONG = LONGS\n RADIUS = RR\n LAT = LATTUD\n \n RETURN\n END\n", "meta": {"hexsha": "e395d2268ac950a3fc4efd3eb75c502a5d4cb345", "size": 5136, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/sphlat.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/sphlat.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/sphlat.f", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 26.4742268041, "max_line_length": 71, "alphanum_fraction": 0.6536214953, "num_tokens": 1431, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127492339909, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6590870076996679}} {"text": "! -----------------------------------------------------------------------\n! This code computes the generalized Lomb-Scargle (GLS) periodogram\n! for one time-series read from an ASCII input file.\n! The following paper describes the method:\n! Zechmeister & Kuerster, 2009, A&A, 496, 577)\n! -----------------------------------------------------------------------\n\nPROGRAM gls\n\nuse gls_mod, only: dp, twopi, readfile, glsspec, sinefit, specwin\nuse mc_mod, only: gauss, ssort, interx1, shuffle, init_random_seed\n\nimplicit none\n\ninteger, parameter :: nmax=1000000, nsimmax=10000\ninteger :: i,N,wexp=2,io=0,index,iargc,en\n! wexp = weightening exponent (default Chi2)\n! weightening of errors: wexp=0 (variance), wexp=2 (Chi2)\ninteger :: numarg,nstep,istep,iter,nthread=1\ninteger :: iverb=1,isout=1,ilog=0,isim=0,nsim=100,iboot=0\nlogical :: isparfile, longhelp=.false.\ncharacter :: TV*40, name*80, fittype*8, logfile*80\ninteger, external :: ntokens\n\nreal(dp) :: tbase=0,FLXmean=0,wsum,YY=0, &\nrmssin=0,chisin=0,wrmssin=0,powSin=0,dFLXsin, &\nfbeg,fend,fendmax,step,ofac,PSin,Amp,CBest,ph, &\nw,M,FAP,prob,probMC=1,deferr,rms0=1,rms,PSin0,PowSin0=0\n \nreal(dp), dimension(:), allocatable :: flx,flxerr,t,ww\nreal(dp), allocatable, dimension(:) :: powMC,pp\ninteger, allocatable, dimension(:) :: indx\n\nfittype=\"unknown\"\nlogfile='gls.log'\nfendMax=50.0d0\nofac=20.0d0\ndeferr=0.001d0\n\n!========================= USER INTERFACE ========================\n \n! >>> Read parameter file.\n\ninquire(file=\"gls.par\", exist=isparfile)\nif (isparfile) then ! (else defaults will be used)\n open(unit=2, file= \"gls.par\", status= \"OLD\")\n read(2,*) ofac ! default oversampling factor = 20\n read(2,*) wexp ! default wexp = 0 (variance)\n read(2,*) Fbeg ! default Fbeg = 1./tbase/10.\n read(2,*) Fend ! default Fend = N*Fbeg*10. (average Nyquist frequency)\n read(2,*) deferr ! default error (if error value is 0 in input file)\n read(2,*) isim ! estimate significance by MC?\n read(2,*) nsim ! number of realizations in MC\n read(2,*) iboot ! use bootstrapping instead of white noise?\n read(2,*) iverb ! verbose mode?\n read(2,*) isout ! write out spectrum?\n read(2,*) ilog ! write logfile?\n read(2,*) nthread ! number of threads\n close(2)\nendif\n\nofac=DABS(ofac)\nnsim=ABS(nsim)\nnthread=ABS(nthread)\nif (nsim>nsimmax) then\n write(0,*) \"WARNING: nsim > \",nsimmax,\" !\"\n write(0,*) \" nsim = \",nsimmax,\" has been set.\"\n nsim=nsimmax\nend if\n\nif (fbeg>fend) then\n write(0,*) \"WARNING: minimum frequency is higher than maximum frequency!\"\n write(0,*) \" Minimum and maximum frequencies have been swapped.\"\n fbeg = fbeg + fend\n fend = fbeg - fend\n fbeg = fbeg - fend\nendif\n\nif (fend>fendmax) then\n fend=fendmax\n write(0,*) \"WARNING: maximum frequency is larger than \",fendmax,\" !\"\n write(0,*) \" Maximum frequency have been set to \",fendmax,\" .\"\nendif\n\nif (.NOT.(wexp==0 .or. wexp==2)) then\n write(0,*) \"WARNING: weightening exponent has an illegal value!\"\n write(0,*) \" Weightening exponent has been set to 0.\"\nendif\n\n! >>> Read command line arguments.\n\nnumarg=iargc()\n\nif (numarg==0) then\n call print_help(longhelp)\nendif\n\ncall getarg(1,name)\n\nif(name=='-help') then\n longhelp=.true.\n call print_help(longhelp)\nendif\n\nif (numarg>1) then ! if the are any command line arguments\n do i=1,numarg-1\n call getarg(i,name) ! testing i-th command line argument\n if (name=='-e2') wexp=2 ! i.e. chi2 (use error bars)\n if (name=='-e1') wexp=1 ! i.e. chi2 (use error bars)\n if (name=='-ne') wexp=0 ! i.e. variance (no error bars)\n if (name=='-s') isout=1 ! write out spectrum\n if (name=='-ns') isout=0 ! don't write out spectrum\n if (name=='-v') iverb=1\n enddo\nendif\n\nif (wexp==2) fittype = \"chi2\"\nif (wexp==0) fittype = \"variance\"\n\n! >>> Read input file name (last command line argument):\ncall getarg(numarg,name)\n\n\n!========================= DATA INPUT ========================\n\ncall readfile(name,nmax,wexp,deferr,wsum,t,flx,flxerr,ww)\n\nn=size(t)\n\n!========================= GLS SPECTRUM ========================\n\n! >>> Check if parameter file exists, if no, set Fbeg, Fend to defaults.\n\ntbase=MAXVAL(t)\n\nif(isparfile.eqv.(.false.)) then ! no parameter file -> no frequency range specified\n Fbeg = 1./tbase/10. ! default value\n Fend = N*Fbeg*10. ! default value (average Nyquist frequency)\n !if (Fbeg.lt.1./tbase/10.) Fbeg = 1./tbase/10. ! default value \nendif\n! Set Fbeg to small positive value:\nstep = 1.0d0/tbase/ofac\nif(Fbeg.lt.step) Fbeg=1./tbase/10.\n\n! >>> Compute GLS Spectrum: \ncall glsspec(nthread,name,isout,Fbeg,Fend,ofac,t,flx,ww,yy,psin,powsin,amp,ph,cbest,rms)\n\npowSin0=powSin\nPSin0=PSin\nrms0=rms\ndo i=1,N\n dFLXsin = FLX(i)-(Amp*sin(t(i)*twopi/PSin0+ph)+CBest)\n rmssin = rmssin + dFLXsin**2\n chisin = chisin + (dFLXsin/FLXerr(i))**2\nend do\nrmssin = sqrt(rmssin/(N-4)) ! unbiased rms\nwrmssin = sqrt(chisin/wsum*N/(N-4)) ! weighted rms\n\n! >>> Calculate analytical estimator of false alarm probability.\n\nprob= (1.0d0-powSin0)**((dfloat(N)-3.0d0)/2.0d0) ! spectral false alarm probability\nM = tbase * dabs(Fend-Fbeg) ! number of independent frequencies\nFAP = M * prob\nif (FAP>0.01d0) FAP = 1.0d0 - (1.0d0-prob)**M\n\n\n!========================= MONTE CARLO FAP ESTIMATION ========================\n\nif(isim==1) then ! Perform MC estimation of FAP.\n\n allocate(powmc(nsim))\n allocate(pp(nsim))\n allocate(indx(nsim))\n \n ww=1.0_dp/DFLOAT(n) ! No error bars in this case..\n do iter=1,nsim ! Loop for MC (will become iterated if isim=1)\n \n if(iboot.eq.0) then\n call gauss(flx,rms0,n)\n !open(7,file=\"tmp\")\n !do i=1,n\n ! write(7,*) t(i),flx(i)\n !enddo\n !close(7)\n else\n call shuffle(flx)\n end if\n \n call glsspec(nthread,name,isout,Fbeg,Fend,ofac,t,flx,ww,yy,psin,powsin,amp,ph,cbest,rms)\n \n powMC(iter)=powsin\n pp(iter)=1.0d0-DFLOAT(nsim-iter)/DFLOAT(nsim)\n \n end do ! End loop for MC.\n call ssort(powMC,indx)\n if(powSin0.le.powMC(1)) then\n call interx1(powMC,pp,powsin0,probmc)\n else\n probmc=pp(1)\n end if\n \n open(7,file=\"tmp1\")\n do i=1,nsim\n write(7,*) pp(i),powmc(i)\n end do\n close(7)\n \n deallocate(powmc)\n deallocate(pp)\n deallocate(indx)\n\nend if\n\nif (iverb.eq.1) then\n print *, \"Number of data points = \", N\n print *, \"Total time base =\", tbase,\" days\"\n print *, \"Number of independent frequencies = \", 1./tbase, \" 1/d\"\n print *, fittype(:lnblnk(fittype))//\"_0 = \", YY*wsum\n print *, \"rms_0 = \",rms\n write(6,*)\"Number of frequency steps = \",int((Fend-Fbeg)/step+1)\n endif\n\n\nif (iverb.eq.1) then\n print *\n write (*,'(1x,a,i3,a,i2)') 'Used parameters: ofac =',int(ofac),' , wexp =',int(wexp)\n print *, \" \",fittype(:lnblnk(fittype))//\" for constant:\",YY*wsum\n print *, \" RMS for constant: \",rms0\n if (wexp .eq. 2) print *, \" mean weighted internal error:\", sqrt(N/wsum)\n print *\n print *, \"Best sine fit values for \", name(:lnblnk(name))\n print *, \" best sine period [d] = \", PSin0,\" +/-\",sqrt(6./N)*2/twopi/tbase*wrmssin/Amp*PSin0**2\n print *, \" amplitude = \", Amp,\" +/-\",sqrt(2./N)*wrmssin\n write(6,*)\n print *, fittype(:lnblnk(fittype)),\" of residuals:\",(1.-powSin0)*YY*wsum,chisin ! variance after fit\n print *, \" weighted rms of residuals: \", wrmssin\n print *, \" rms of residuals: \", rmssin\n print *, \" highest power p[0..1]: \", powSin0\n print *, \" P[0..(N-1)/2]:\", powSin0*(N-1)/2\n print *, \" Analytical FAP(spectral)=(1-p)^((N-3)/2):\", prob\n print *, \" Analytical FAP: \", FAP\n if(isim.eq.1) then\n print *, \" FAP (MC):\", probMC\n print *, \" Number of realizations:\", nsim\n end if\n print *, \"----------------------------------------------------------------\"\n print *, \"RESULTS:\"\n print *\n endif\n\n! >>> Write results to STDOUT.\nif(isim.eq.0) then\n write(*,'(a,1x,i5,1x,f9.6,1x,f7.3,1x,f6.2,1x,i7,2x,e15.3e4,1x,f8.6)') &\n TRIM(name),N,1.0d0/PSin0,powSin0,Fend,int(M),FAP,1.0d0/tbase\nelse\n write(*,'(a,1x,i5,1x,f9.6,1x,f7.3,1x,f6.2,1x,i7,2x,2(e15.3e4,1x),f8.6)') &\n TRIM(name),N,1.0d0/PSin0,powSin0,Fend,int(M),FAP,probmc,1.0d0/tbase\nendif\n \nif (allocated(flx)) deallocate(flx)\nif (allocated(flxerr)) deallocate(flxerr)\nif (allocated(ww)) deallocate(ww)\nif (allocated(t)) deallocate(t)\n\n\n! TRIM(name),N,1.0d0/PSin0,powSin0*(N-1)/2,Fend,int(M),FAP\n\n! >>> Add results to logfile.\nif (ilog==1) then\n open(unit=3, file=TRIM(logfile) ,access='APPEND')\n write(3,*)\"file='\",name(:lnblnk(name)),\"'\"\n write(3,*)\"PSin=\",PSin0,\"; Amp=\",Amp,\";\"\n close(3)\nendif\n\ncontains\n\nsubroutine print_help(longhelp)\n implicit none\n logical, intent(in) :: longhelp\n \n if (longhelp) then\n print *,\"Usage: gls [] \"\n print *,\"Where:\"\n print *,\" contains the input time series in columns:\"\n print *,\" time, flux [, flux error]\"\n print *,\" may be one or more of the following options:\"\n print *,\" -e2 : use chi^2 weightening (= use error bars)\"\n print *,\" -ne : use variance weightening (= don't use error bars)\"\n print *,\" -s : write out spectrum (output file is .gls)\"\n print *,\" -ns : don't write out spectrum\"\n print *,\" -v : verbose mode (writes out information on STDOUT)\"\n print *,\"Optionally, a parameter file called 'gls.par' can be provided.\"\n print *,\"The parameter file overrides default settings, flags override both.\"\n print *,\"Normal output is one line to STDOUT with the following values:\"\n print *,\" , number of points in time series, main frequency [d^-1],\"\n print *,\" GLS power of main frequency, high frequency limit, number of independent frequencies,\"\n print *,\" analytical false alarm probability (FAP), [Monte Carlo FAP,] nominal frequency resolution\"\n print *,\"\"\n stop\n else\n print *,\"Usage: gls [] \"\n\t print *,\"Type 'gls -help' for more info.\"\n\t stop\n endif\n \nend subroutine print_help\n \nend program gls \n\n", "meta": {"hexsha": "bd81847269cf5af8ad05f361129cd96bfd54a40b", "size": 10673, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gls.f90", "max_stars_repo_name": "idekany/gls", "max_stars_repo_head_hexsha": "573130ed5ff593383fad111d9f69690735afafea", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "gls.f90", "max_issues_repo_name": "idekany/gls", "max_issues_repo_head_hexsha": "573130ed5ff593383fad111d9f69690735afafea", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gls.f90", "max_forks_repo_name": "idekany/gls", "max_forks_repo_head_hexsha": "573130ed5ff593383fad111d9f69690735afafea", "max_forks_repo_licenses": ["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.3183279743, "max_line_length": 109, "alphanum_fraction": 0.5795933664, "num_tokens": 3422, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127455162773, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6590870048301748}} {"text": "module ops\n use fstack\n contains\n subroutine ops_add(stack) ! Add 2 numbers from the stack\n type(fs_stack), intent(inout) :: stack\n real :: a,b,c\n call fs_pop(stack, a)\n call fs_pop(stack, b)\n c = a + b\n call fs_push(stack, c)\n end subroutine ops_add\n subroutine ops_sub(stack) ! See add\n type(fs_stack), intent(inout) :: stack\n real :: a,b,c\n call fs_pop(stack, a)\n call fs_pop(stack, b)\n c = b - a\n call fs_push(stack, c)\n end subroutine ops_sub\n subroutine ops_mul(stack) ! See add\n type(fs_stack), intent(inout) :: stack\n real :: a,b,c\n call fs_pop(stack, a)\n call fs_pop(stack, b)\n c = a * b\n call fs_push(stack, c)\n end subroutine ops_mul\n subroutine ops_div(stack) ! See add\n type(fs_stack), intent(inout) :: stack\n real :: a,b,c\n call fs_pop(stack, a)\n call fs_pop(stack, b)\n c = b / a\n call fs_push(stack, c)\n end subroutine ops_div\n subroutine ops_mod(stack) ! Modulo\n type(fs_stack), intent(inout) :: stack\n real :: a,b,c\n call fs_pop(stack, a)\n call fs_pop(stack, b)\n c = modulo(b,a)\n call fs_push(stack, c)\n end subroutine ops_mod\n subroutine ops_pow(stack) ! Powers\n type(fs_stack), intent(inout) :: stack\n real :: a,b,c\n call fs_pop(stack, a)\n call fs_pop(stack, b)\n c = b ** a\n call fs_push(stack, c)\n end subroutine ops_pow\n subroutine ops_inv_pow(stack) ! Roots, via inverse powers\n type(fs_stack), intent(inout) :: stack\n real :: a,b,c\n call fs_pop(stack, a)\n call fs_pop(stack, b)\n c = b ** (1/a)\n call fs_push(stack, c)\n end subroutine ops_inv_pow\n subroutine ops_sin(stack) ! Trig functions\n type(fs_stack), intent(inout) :: stack\n real :: a,c\n call fs_pop(stack, a)\n c = sind(a)\n call fs_push(stack, c)\n end subroutine ops_sin\n subroutine ops_cos(stack)\n type(fs_stack), intent(inout) :: stack\n real :: a,c\n call fs_pop(stack, a)\n c = cosd(a)\n call fs_push(stack, c)\n end subroutine ops_cos\n subroutine ops_tan(stack)\n type(fs_stack), intent(inout) :: stack\n real :: a,c\n call fs_pop(stack, a)\n c = tand(a)\n call fs_push(stack, c)\n end subroutine ops_tan\n subroutine ops_rtan(stack)\n type(fs_stack), intent(inout) :: stack\n real :: a,c\n call fs_pop(stack, a)\n c = tan(a)\n call fs_push(stack, c)\n end subroutine ops_rtan\n subroutine ops_rsin(stack)\n type(fs_stack), intent(inout) :: stack\n real :: a,c\n call fs_pop(stack, a)\n c = sin(a)\n call fs_push(stack, c)\n end subroutine ops_rsin\n subroutine ops_rcos(stack)\n type(fs_stack), intent(inout) :: stack\n real :: a,c\n call fs_pop(stack, a)\n c = cos(a)\n call fs_push(stack, c)\n end subroutine ops_rcos\n subroutine ops_acos(stack)\n type(fs_stack), intent(inout) :: stack\n real :: a,c\n call fs_pop(stack, a)\n c = acosd(a)\n call fs_push(stack, c)\n end subroutine ops_acos\n subroutine ops_asin(stack)\n type(fs_stack), intent(inout) :: stack\n real :: a,c\n call fs_pop(stack, a)\n c = asind(a)\n call fs_push(stack, c)\n end subroutine ops_asin\n subroutine ops_atan(stack)\n type(fs_stack), intent(inout) :: stack\n real :: a,c\n call fs_pop(stack, a)\n c = atand(a)\n call fs_push(stack, c)\n end subroutine ops_atan\n subroutine ops_acosr(stack)\n type(fs_stack), intent(inout) :: stack\n real :: a,c\n call fs_pop(stack, a)\n c = acos(a)\n call fs_push(stack, c)\n end subroutine ops_acosr\n subroutine ops_asinr(stack)\n type(fs_stack), intent(inout) :: stack\n real :: a,c\n call fs_pop(stack, a)\n c = asin(a)\n call fs_push(stack, c)\n end subroutine ops_asinr\n subroutine ops_atanr(stack)\n type(fs_stack), intent(inout) :: stack\n real :: a,c\n call fs_pop(stack, a)\n c = atan(a)\n call fs_push(stack, c)\n end subroutine ops_atanr\n subroutine ops_loge(stack) ! Natural Log\n type(fs_stack), intent(inout) :: stack\n real :: a,c\n call fs_pop(stack, a)\n c = log(a)\n call fs_push(stack, c)\n end subroutine ops_loge\n subroutine ops_log10(stack) ! Log 10\n type(fs_stack), intent(inout) :: stack\n real :: a,c\n call fs_pop(stack, a)\n c = log10(a)\n call fs_push(stack, c)\n end subroutine ops_log10\n subroutine ops_log(stack) ! Log with base of number off stack, via natural log division.\n type(fs_stack), intent(inout) :: stack\n real :: a,c,b\n call fs_pop(stack, a)\n call fs_pop(stack, b)\n c = log (a) / log (b)\n call fs_push(stack, c)\n end subroutine ops_log\nend module ops\n", "meta": {"hexsha": "3043a2da664ee178df9bbe2c9676164f9db3f847", "size": 5724, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/ops.f90", "max_stars_repo_name": "jake-87/fortran-calc", "max_stars_repo_head_hexsha": "6db0564d281bc68d99989a1377c3d566f3888bea", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-06-08T03:00:39.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-08T03:00:39.000Z", "max_issues_repo_path": "src/ops.f90", "max_issues_repo_name": "jake-87/fortran-calc", "max_issues_repo_head_hexsha": "6db0564d281bc68d99989a1377c3d566f3888bea", "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/ops.f90", "max_forks_repo_name": "jake-87/fortran-calc", "max_forks_repo_head_hexsha": "6db0564d281bc68d99989a1377c3d566f3888bea", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.2754491018, "max_line_length": 96, "alphanum_fraction": 0.5033193571, "num_tokens": 1347, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517043, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6590870016061132}} {"text": "!----------------------------------------------------------------------------- best with 100 columns\n\nfunction BDFNewtonKrylov1()\n use modSUNDIALS\n use iso_c_binding\n integer::BDFNewtonKrylov1\n type(BDFNewtonKrylov)::p\n double precision::t,s(2)\n \n BDFNewtonKrylov1=0\n call p%init(2,func)\n call p%setTol(1d-8,1d-12)\n call p%setMaxSteps(-1)\n t=0d0\n s(:)=[1d0,0d0]\n call p%setIV(t,s)\n do while(t<2d0)\n call p%step(2d0,t,s)\n end do\n if(norm2(s-[cos(t),-sin(t)])>1d-6)then\n BDFNewtonKrylov1=1\n end if\n call p%clear()\n \ncontains\n \n function func(ct,cx,cdx,dat)\n use iso_c_binding\n use modSUNDIALS\n real(C_DOUBLE),value::ct\n type(C_PTR),value::cx,cdx,dat\n integer(C_INT)::func\n double precision::t\n double precision,pointer::x(:)\n double precision,pointer::dx(:)\n type(C_PTR)::foo\n \n t=ct\n call associateVector(cx,x)\n call associateVector(cdx,dx)\n dx(1:2)=[x(2),-x(1)]\n func=0\n foo=dat\n end function\n \nend function\n", "meta": {"hexsha": "a9de8ebe7d097cf3bdf456b07e4b4ccf977904ef", "size": 985, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/test/BDFNewtonKrylov1.f90", "max_stars_repo_name": "mianzhi/fosolvers", "max_stars_repo_head_hexsha": "be4877a9cccd7bf6b97d4e01c58e10634684415d", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2015-08-05T14:10:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-26T10:50:06.000Z", "max_issues_repo_path": "src/test/BDFNewtonKrylov1.f90", "max_issues_repo_name": "mianzhi/fosolvers", "max_issues_repo_head_hexsha": "be4877a9cccd7bf6b97d4e01c58e10634684415d", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2019-11-24T15:46:54.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-30T13:30:29.000Z", "max_forks_repo_path": "src/test/BDFNewtonKrylov1.f90", "max_forks_repo_name": "mianzhi/fosolvers", "max_forks_repo_head_hexsha": "be4877a9cccd7bf6b97d4e01c58e10634684415d", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-08-23T03:10:35.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-01T05:17:19.000Z", "avg_line_length": 20.9574468085, "max_line_length": 100, "alphanum_fraction": 0.5979695431, "num_tokens": 353, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127455162773, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6590870003486511}} {"text": "\tFUNCTION BXPA(F)\nC\nC\tTHIS FUNCTION RETURNS THE GAIN OF THE WIND X SEARCH COIL,PREAMP AND\nC\tINPUT STAGE ON THE 212 BOARD.\nC\tTHE FUNCTION ITSELF RETURNS THE MAGNITUDE OF THE GAIN, AND THE PHASE\nC\tAND THE COMPLEX GAIN ARE RETURNED IN A COMMON BLOCK\nC\n\tCOMMON /GAINBLK/ PHASE,CGAIN \t\t ! PHASE IS IN RADIANS\n\tCOMMON /COMPBLK/ CVAR(5)\nC\n\tCOMPLEX CGAIN,Y1,Z1,Y2,Z2\n\tDATA Q,T0,F0 / 1.43,2.62E-3,1700./ \t\t! T0 is in Volts/nT\n\tDATA C10,R1,R2,C1/ .959E-6, 49.9E3, 1.E6, 1.005E-9/\n\tDATA TWOPI /6.2831853/\nC\nC\n\tW = TWOPI*F\nC\tOUTPUT OF SEARCH COIL PLUS PREAMP, VOLTS/nT\n\tCGAIN = T0/CMPLX(1.,Q*(F/F0 - F0/F))\nC\nC\tEFFECT OF INPUT ON 212 BOARD\nC\n\tY2 = CMPLX(1./R2,W*C1)\n\tZ1 = CMPLX(R1, -1./W/C10)\n\tCGAIN = CGAIN/(Z1*Y2)\nC\nC\tNORMALIZE TO E PREAMPS\nC\n\tCGAIN = 21.*CGAIN\nC\n\tGNIP = AIMAG(CGAIN)\n\tGNRP = CGAIN\n\tPHASE = ATAN2(GNIP,GNRP)\n\tXPADC = CABS(CGAIN)\n\tRETURN\n\tEND\n\n", "meta": {"hexsha": "543e3d6ed8b579229e2bb8a65dff1a526ea83ca0", "size": 862, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/bzpa_4.for", "max_stars_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_stars_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/bzpa_4.for", "max_issues_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_issues_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/bzpa_4.for", "max_forks_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_forks_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.6842105263, "max_line_length": 70, "alphanum_fraction": 0.680974478, "num_tokens": 391, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240177362488, "lm_q2_score": 0.7025300573952052, "lm_q1q2_score": 0.6590603200240673}} {"text": " module MOD_MOMADD\r\n contains\r\nC********** MODULNAME: MOMADD ******* 24/03/87 19.29.57.****** 109 KARTEN\r\n SUBROUTINE MOMADD (JP,LMAX,ND,NP,Z,RADIUS,P,W0,W1,W2,W3,\r\n $ WBMHO,WBMNO,WBMHI,WBMNI )\r\nC*** AT GIVEN IMPACT-PARAMETER INDEX JP, THIS SUBROUTINE CALCULATES THE\r\nC*** WEIGHTS FOR THE ANGLE INTEGRATION OF THE 0. TO 3. MOMENTS\r\nC*** THE WEIGHTS W0 AND W2 ARE CALCULATED FOR THE ORIGINAL DEPTH POINTS\r\nC*** THE WEIGHTS W1 AND W3 ARE CALCULATED FOR INTERMESH POINTS\r\nC*** SPECIAL WEIGHTS WBMH AND WBMN ARE CALCULATED FOR THE OUTER BOUNDARY\r\n implicit real*8(a-h,o-z)\r\n\r\n\tparameter (two=2.0d0,three=3.0d0,four=4.0d0,six=6.0d0,half=0.5d0)\r\n\r\n DIMENSION W0(ND),W1(ND),W2(ND),W3(ND)\r\n DIMENSION Z(ND,NP),P(NP),RADIUS(ND)\r\n \r\nC*** 0. AND 2. MOMENT. THE INTEGRATION IS PERFORMED IN THE Z VARIABLE\r\n DO 10 L=1,LMAX\r\n RL=RADIUS(L)\r\n RL2=RL+RL\r\n RRR12=RL*RL*RL*12.d0\r\n IF (JP.GT.1) GOTO 8\r\nC*** FIRST STEP IF JP=1\r\n B=Z(L,1)\r\n A=Z(L,2)\r\n W0(L)=(B-A)/RL2\r\n AA=A*A\r\n BB=B*B\r\n W2(L)=(B*(three*BB-AA)-A*(BB+AA))/RRR12\r\n GOTO 10\r\n 8 IF (L.EQ.LMAX .AND. JP.GT.(NP-ND) ) GOTO 9\r\nC*** INTERMEDIATE STEP\r\n A=Z(L,JP+1)\r\n B=Z(L,JP)\r\n C=Z(L,JP-1)\r\n W0(L)=(C-A)/RL2\r\n AA=A*A\r\n BB=B*B\r\n CC=C*C\r\n W2(L)=(B*(CC-AA)+C*(CC+BB)-A*(BB+AA))/RRR12\r\n GOTO 10\r\nC*** LAST STEP, IMPLYING Z(L,JMAX)=0\r\n 9 B=Z(L,JP-1)\r\n W0(L)=B/RL2\r\n W2(L)=B*B*B/RRR12\r\n 10 CONTINUE\r\n \r\nC*** THE FEAUTRIER FLUX V IS ADDED TO THE 1. AND 3. MOMENTS .\r\nC*** THE DEPTH POINTS FOR THE MOMENTS ARE ASSUMED TO LIE ON THE RADIUS-\r\nC*** INTERMESH. THIS IS ONLY APPROXIMATELY, BECAUSE FROM THE RAY-BY-RAY\r\nC*** FORMAL SOLUTION V RESULTS AT INTERSTICES IN THE Z COORDINATE.\r\nC*** THE INTEGRATION IS CARRIED OUT IN P\r\nC*** 1. MOMENT MUE DMUE = P DP / R**2\r\nC*** 3. MOMENT MUE**3 DMUE = P DP /R**2 - P**3 DP /R**4\r\nC*** THE WEIGHTS ARE INDEPENDENT OF THE DEPTH, EXCEPT OF THE DIVISOR\r\nC*** CONTAINING R, AND EXCEPT OF THE LAST POINT LZ\r\n LZ=LMAX-1\r\nC*** FIRST STEP\r\n IF (JP.GT.1 ) GOTO 2\r\n B=P(2)\r\n BB=B*B\r\n WW1=BB\r\n WW3=BB*BB\r\n GOTO 5\r\nC*** INTERMEDIATE STEPS\r\n 2 A=P(JP-1)\r\n B=P(JP)\r\n C=P(JP+1)\r\n WW1=(A+B+C)*(C-A)\r\n AA=A*A\r\n BB=B*B\r\n CC=C*C\r\n WW3=(B-A)*(AA*(A+two*B)+BB*(three*A+four*B))\r\n $ +(C-B)*(CC*(C+two*B)+BB*(three*C+four*B))\r\nC*** FOR THE LAST INTERVAL (L=LZ TO THE P AXIS), THE NEXT POINT IS AN\r\nC*** INTERMESH-POINT IN P\r\n C=half*(B+C)\r\n W1LZ=(A+B+C)*(C-A)\r\n CC=C*C\r\n W3LZ=(B-A)*(AA*(A+two*B)+BB*(three*A+four*B))\r\n $ +(C-B)*(CC*(C+two*B)+BB*(three*C+four*B))\r\nC*** NO WEIGHT FOR THE Z=0 POINT IS CALCULATED, AS V=0 THERE FOR SYMMETRY .\r\n \r\nC*** LOOP OVER DEPTH INDEX L\r\n 5 DO 1 L=1,LZ\r\n RZ=half*(RADIUS(L)+RADIUS(L+1))\r\n RZQ6=RZ*RZ*six\r\n RRRR20=RZ*RZ*RZ*RZ*20.d0\r\n IF (L.NE.LZ .OR. JP.LE.(NP-ND) ) GOTO 4\r\n W1(L)=W1LZ/RZQ6\r\n W3(L)=W1(L)-W3LZ/RRRR20\r\n GOTO 1\r\n 4 W1(L)=WW1/RZQ6\r\n W3(L)=W1(L)-WW3/RRRR20\r\n 1 CONTINUE\r\n \r\nC*** SPECIAL WEIGHTS AT THE OUTER BOUNDARY (FOR H AND N )\r\n R=RADIUS(1)\r\n WBMHO=WW1/R/R/six\r\n WBMNO=WBMHO-WW3/R/R/R/R/20.d0\r\nC*** SPECIAL WEIGHTS AT THE INNER BOUNDARY\r\n IF (LMAX.LT.ND) GOTO 99\r\n IF (JP.LE.NP-ND) GOTO 3\r\nC*** CORE TANGENT RAY, LAST STEP OF INTEGRATION\r\n WW1=(B-A)*(two*B+A)\r\n WW3=(B-A)*(AA*(A+2*B)+BB*(three*A+4*B))\r\n 3 CONTINUE\r\n WBMHI=WW1/six\r\n WBMNI=WBMHI-WW3/20.d0\r\n \r\n 99 RETURN\r\n end subroutine\r\n end module\r\n", "meta": {"hexsha": "8167db159c86a06071ff839d5fc45173138e9520", "size": 3662, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/momadd.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/momadd.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/momadd.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": 31.8434782609, "max_line_length": 81, "alphanum_fraction": 0.5466957946, "num_tokens": 1498, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240142763572, "lm_q2_score": 0.7025300573952054, "lm_q1q2_score": 0.6590603175933897}} {"text": " subroutine phi3m(xth,xphi,p0,p1,p2,m1,m2,wt,*)\nc massive particle p0 in rest frame\nc decaying into p1 fixed mass m1 and p2 fixed mass m2.\nc vectors returned p1 and p2 are in the frame in which\nC p0 is supplied\nc result is 1/8/pi * 2|p|/sqrts * domega/(4*pi)\nc factor of (2*pi)^4 included in definition of phase space\n implicit none\n include 'constants.f'\n include 'process.f'\n double precision p0(4),p1(4),p2(4),p1cm(4)\n double precision xth,xphi,phi,s,roots,costh,sinth\n double precision wt0,wt\n double precision m1,m2,m1sq,m2sq,lambda,lambda2,smin\n integer j\n parameter(wt0=one/eight/pi)\n\n wt=0d0\n\n s=p0(4)**2-p0(1)**2-p0(2)**2-p0(3)**2\n\n smin=(m1+m2)**2\n if (s .lt. smin) then\n if (case(1:4) .ne. 'vlch') then\n write(6,*) 's i.\n\n s = abs(e-z(i))\n sm = abs(e+z(i))\n do j = i + 1, n\n sm = sm + abs(z(j)+wm*r(i,j))\n end do\n if (i .lt. n) then\n call daxpy(n-i,w,r(i,i+1),ldr,z(i+1),1)\n s = s + dasum(n-i,z(i+1),1)\n end if\n if (s .lt. sm) then\n temp = wm - w\n w = wm\n if (i .lt. n) call daxpy(n-i,temp,r(i,i+1),ldr,z(i+1),1)\n end if\n z(i) = w\n\n end do\n\n ynorm = dnrm2(n,z,1)\n\nc Solve R*z = y.\n\n do j = n, 1, -1\n\nc Scale z.\n\n if (abs(z(j)) .gt. abs(r(j,j))) then\n temp = min(p01,abs(r(j,j))/abs(z(j)))\n call dscal(n,temp,z,1)\n ynorm = temp*ynorm\n end if\n if (r(j,j) .eq. zero) then\n z(j) = one\n else\n z(j) = z(j)/r(j,j)\n end if\n temp = -z(j)\n call daxpy(j-1,temp,r(1,j),1,z,1)\n\n end do\n\nc Compute svmin and normalize z.\n\n znorm = one/dnrm2(n,z,1)\n svmin = ynorm*znorm\n call dscal(n,znorm,z,1)\n\n end\n", "meta": {"hexsha": "5211de47bfcc14fe1b6bf6e99eef5d6fb13f6f92", "size": 4212, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/isat/ell_lib/destsv.f", "max_stars_repo_name": "xuhan425/isat_ffd", "max_stars_repo_head_hexsha": "3a5449f7e49b686c33fe0e97ca90ea8d92fc2f00", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-04-10T20:16:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-15T11:09:44.000Z", "max_issues_repo_path": "src/isat/ell_lib/destsv.f", "max_issues_repo_name": "xuhan425/isat_ffd", "max_issues_repo_head_hexsha": "3a5449f7e49b686c33fe0e97ca90ea8d92fc2f00", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-06-07T14:10:25.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-07T14:10:25.000Z", "max_forks_repo_path": "src/isat/ell_lib/destsv.f", "max_forks_repo_name": "xuhan425/isat_ffd", "max_forks_repo_head_hexsha": "3a5449f7e49b686c33fe0e97ca90ea8d92fc2f00", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-06-07T03:44:12.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-05T05:54:10.000Z", "avg_line_length": 26.6582278481, "max_line_length": 77, "alphanum_fraction": 0.5405982906, "num_tokens": 1260, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703477, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6590156463550274}} {"text": "module faddeeva_fortran_interface\n integer, parameter, public :: dp=kind(0.d0)\n interface\n !> @brief the error function\n !!\n !! computes erf(z), where erf - the error function\n !!\n !! @param[in] z a complex value\n !! @param[in] relerr demanding relative error\n !! @return a complex value of the mentioned function\n complex (c_double_complex) function Faddeeva_erf(z, relerr) bind(c, name = 'Faddeeva_erf')\n use iso_c_binding\n complex(c_double_complex), value :: z\n real(c_double), value :: relerr\n end function Faddeeva_erf\n\n !> @brief the imaginary error function\n !!\n !! computes erfi(z) = -i*erf(i*z), where erf is the error function\n !!\n !! @param[in] z a complex value\n !! @param[in] relerr demanding relative error\n !! @return a complex value of the mentioned function\n complex (c_double_complex) function Faddeeva_erfi(z, relerr) bind(c, name = 'Faddeeva_erfi')\n use iso_c_binding\n complex(c_double_complex), value :: z\n real(c_double), value :: relerr\n end function Faddeeva_erfi\n\n !> @brief the complementary error function\n !!\n !! computes erfc(z) = 1 - erf(z), where erf is the error function\n !!\n !! @param[in] z a complex value\n !! @param[in] relerr demanding relative error\n !! @return a complex value of the mentioned function\n complex (c_double_complex) function Faddeeva_erfc(z, relerr) bind(c, name = 'Faddeeva_erfc')\n use iso_c_binding\n complex(c_double_complex), value :: z\n real(c_double), value :: relerr\n end function Faddeeva_erfc\n\n !> @brief the scaled complementary error function\n !!\n !! computes erfcx(z) = exp(z*z)*erfc(z), where erfc is the complementary error function\n !!\n !! @param[in] z a complex value\n !! @param[in] relerr demanding relative error\n !! @return a complex value of the mentioned function\n complex (c_double_complex) function Faddeeva_erfcx(z, relerr) bind(c, name = 'Faddeeva_erfcx')\n use iso_c_binding\n complex(c_double_complex), value :: z\n real(c_double), value :: relerr\n end function Faddeeva_erfcx\n\n !> @brief the Faddeeva function of complex argument\n !!\n !! computes w(z) = exp(-z*z)*erfc(-i*z), where erfc - the complementary error function\n !!\n !! @param[in] z argument\n !! @param[in] relerr demanding relative error\n !! @return a complex value of the mentioned function\n complex (c_double_complex) function Faddeeva_w(z, relerr) bind(c, name = 'Faddeeva_w')\n use iso_c_binding\n complex(c_double_complex), value :: z\n real(c_double), value :: relerr\n end function Faddeeva_w\n\n !> @brief the dawson function\n !!\n !! computes Dawson(z) = sqrt(pi)/2*exp(-z*z)*erfi(z), the erfi is the imaginary error function\n !!\n !! @param[in] z a complex value\n !! @param[in] relerr demanding relative error\n !! @return a complex value of the mentioned function\n complex (c_double_complex) function Faddeeva_dawson(z, relerr) bind(c, name = 'Faddeeva_Dawson')\n use iso_c_binding\n complex(c_double_complex), value :: z\n real(c_double), value :: relerr\n end function Faddeeva_dawson\n end interface\n\n contains\n !> @brief provide an example of usage\n !!\n !! provide a terminal output of function name, input arguments,\n !! demanding relative error and computational results\n !!\n !! @param[in] func a pointer to the function\n !! @param[in] func_name function name as a string\n !! @param[in] z a complex value\n !! @param[in] relerr demanding relative error\n subroutine example(func, func_name, z, relerr)\n character(len=15), intent(in) :: func_name\n complex(dp) :: z\n real(dp) :: relerr\n\n interface AFunc\n function func(z, relerr)\n use iso_c_binding\n complex(c_double_complex), value :: z\n real(c_double), value :: relerr\n complex(c_double_complex) :: func\n end function\n end interface\n\n if (relerr < 2.22e-16_dp) relerr = 2.22e-16_dp !according to https://en.wikipedia.org/wiki/Machine_epsilon\n print *, func_name, ' of argument z =', z, 'with relative error' , relerr, 'equals ', func(z, relerr)\n\n end subroutine example\n\n !> @brief define a relative error between two real input arguments\n !!\n !! @param[in] a real argument\n !! @param[in] b real argument\n !! @return a relative error\n real(dp) function find_relerr(a, b)\n real(dp), intent(in) :: a, b\n\n find_relerr = abs((b-a)/a)\n\n end function find_relerr\nend module faddeeva_fortran_interface\n", "meta": {"hexsha": "f78899fbffaa63ee59eaf13751b2f53c044f9f08", "size": 5269, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/lib/faddeeva_fortran_interface.f90", "max_stars_repo_name": "ArtyomShalev/Faddeeva_Fortran", "max_stars_repo_head_hexsha": "4942a69081929355ed1bc0f14f69bea71eceae59", "max_stars_repo_licenses": ["MIT"], "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/faddeeva_fortran_interface.f90", "max_issues_repo_name": "ArtyomShalev/Faddeeva_Fortran", "max_issues_repo_head_hexsha": "4942a69081929355ed1bc0f14f69bea71eceae59", "max_issues_repo_licenses": ["MIT"], "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/faddeeva_fortran_interface.f90", "max_forks_repo_name": "ArtyomShalev/Faddeeva_Fortran", "max_forks_repo_head_hexsha": "4942a69081929355ed1bc0f14f69bea71eceae59", "max_forks_repo_licenses": ["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.4919354839, "max_line_length": 118, "alphanum_fraction": 0.5777187322, "num_tokens": 1301, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299570920386, "lm_q2_score": 0.7122321842389469, "lm_q1q2_score": 0.6589785532629697}} {"text": "! This routine will perform a coordinates conversion. It takes the \n! heliocentric angle (theta), the line-of-sight magnetic inclination \n! (Gamma_p) and azimuth (Chi_p) and returns the local inclination (Gamma) \n! and azimuth (Chi). All of these angles are real arrays of size npoints.\n!\n! It is assumed that the heliocentriz azimuth is zero, which means that\n! the observed point is on the E-W line that crosses the solar disk center.\n! If that is not the case, the azimuth obtained is uncalibrated by an\n! additive constant.\n!\n! navarro@hao.ucar.edu , Mar 2000\n!\nSubroutine los_to_local(npoints, Theta, Gamma_p, Chi_p, Gamma, Chi)\n Implicit None\n Integer :: npoints\n Real :: Theta\n Real, parameter :: Pi = 3.14159265389793D0, Deg_to_rad = Pi/180.\n Real, dimension (npoints) :: Gamma, Chi, Gamma_p, Chi_p\n!\n! Do NOT convert!\n!\n Chi=Chi_p\n Gamma=Gamma_p\n Return\n!\n!\n!\n!\n!\n! Piece of cake\n!\n Chi=Chi_p\n Gamma=Acos(Cos(Gamma_p*Deg_to_rad)*Cos(Theta*Deg_to_rad) + &\n Sin(Gamma_p*Deg_to_rad)*Cos(Chi_p*Deg_to_rad)*Sin(Theta*Deg_to_rad)) /&\n Deg_to_rad\n!\n! Done!\n!\n Return\nEnd Subroutine los_to_local\n", "meta": {"hexsha": "47430fac1de34b2905de001d658b24d70e3b27ae", "size": 1120, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "inversor/database/NICOLE/misc/los_to_local.f90", "max_stars_repo_name": "aasensio/DeepLearning", "max_stars_repo_head_hexsha": "71838115ce93e0ca96c8314cff3f07de1d64c235", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "inversor/database/NICOLE/misc/los_to_local.f90", "max_issues_repo_name": "aasensio/DeepLearning", "max_issues_repo_head_hexsha": "71838115ce93e0ca96c8314cff3f07de1d64c235", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "inversor/database/NICOLE/misc/los_to_local.f90", "max_forks_repo_name": "aasensio/DeepLearning", "max_forks_repo_head_hexsha": "71838115ce93e0ca96c8314cff3f07de1d64c235", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.3170731707, "max_line_length": 78, "alphanum_fraction": 0.7232142857, "num_tokens": 334, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299612154571, "lm_q2_score": 0.7122321781307374, "lm_q1q2_score": 0.6589785505483027}} {"text": "C$Procedure AXISAR ( Axis and angle to rotation )\n \n SUBROUTINE AXISAR ( AXIS, ANGLE, R )\n \nC$ Abstract\nC\nC Construct a rotation matrix that rotates vectors by a specified\nC angle about a specified axis.\nC\nC$ Disclaimer\nC\nC THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE\nC CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.\nC GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE\nC ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE\nC PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED \"AS-IS\"\nC TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY\nC WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A\nC PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC\nC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE\nC SOFTWARE AND RELATED MATERIALS, HOWEVER USED.\nC\nC IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA\nC BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT\nC LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,\nC INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,\nC REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE\nC REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.\nC\nC RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF\nC THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY\nC CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE\nC ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.\nC\nC$ Required_Reading\nC\nC ROTATION\nC\nC$ Keywords\nC\nC MATRIX\nC ROTATION\nC\nC$ Declarations\n \n DOUBLE PRECISION AXIS ( 3 )\n DOUBLE PRECISION ANGLE\n DOUBLE PRECISION R ( 3, 3 )\n \nC$ Brief_I/O\nC\nC Variable I/O Description\nC -------- --- --------------------------------------------------\nC AXIS I Rotation axis.\nC ANGLE I Rotation angle, in radians.\nC R O Rotation matrix corresponding to AXIS and ANGLE.\nC\nC$ Detailed_Input\nC\nC AXIS,\nC ANGLE are, respectively, a rotation axis and a rotation\nC angle. AXIS and ANGLE determine a coordinate\nC transformation whose effect on any vector V is to\nC rotate V by ANGLE radians about the vector AXIS.\nC\nC$ Detailed_Output\nC\nC R is a rotation matrix representing the coordinate\nC transformation determined by AXIS and ANGLE: for\nC each vector V, R*V is the vector resulting from\nC rotating V by ANGLE radians about AXIS.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC Error free.\nC\nC 1) If AXIS is the zero vector, the rotation generated is the\nC identity. This is consistent with the specification of VROTV.\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC AXISAR can be thought of as a partial inverse of RAXISA. AXISAR\nC really is a `left inverse': the code fragment\nC\nC CALL RAXISA ( R, AXIS, ANGLE )\nC CALL AXISAR ( AXIS, ANGLE, R )\nC\nC preserves R, except for round-off error, as long as R is a\nC rotation matrix.\nC\nC On the other hand, the code fragment\nC\nC CALL AXISAR ( AXIS, ANGLE, R )\nC CALL RAXISA ( R, AXIS, ANGLE )\nC\nC preserves AXIS and ANGLE, except for round-off error, only if\nC ANGLE is in the range (0, pi). So AXISAR is a right inverse\nC of RAXISA only over a limited domain.\nC\nC$ Examples\nC\nC 1) A matrix that rotates vectors by pi/2 radians about the z-axis\nC can be found using the code fragment\nC\nC AXIS(1) = 0.D0\nC AXIS(2) = 0.D0\nC AXIS(3) = 1.D0\nC\nC CALL AXISAR ( AXIS, HALFPI(), R )\nC\nC The returned matrix R will equal\nC\nC +- -+\nC | 0 -1 0 |\nC | |\nC | 1 0 0 |.\nC | |\nC | 0 0 1 |\nC +- -+\nC\nC\nC 2) Linear interpolation between two rotation matrices:\nC\nC Let R(t) be a time-varying rotation matrix; R could be\nC a C-matrix describing the orientation of a spacecraft\nC structure. Given two points in time t1 and t2 at which\nC R(t) is known, and given a third time t3, where\nC\nC t1 < t3 < t2,\nC\nC we can estimate R(t3) by linear interpolation. In other\nC words, we approximate the motion of R by pretending that\nC R rotates about a fixed axis at a uniform angular rate\nC during the time interval [t1, t2]. More specifically, we\nC assume that each column vector of R rotates in this\nC fashion. This procedure will not work if R rotates through\nC an angle of pi radians or more during the time interval\nC [t1, t2]; an aliasing effect would occur in that case.\nC\nC If we let\nC\nC R1 = R(t1)\nC R2 = R(t2), and\nC\nC -1\nC Q = R2 * R1 ,\nC\nC then the rotation axis and angle of Q define the rotation\nC that each column of R(t) undergoes from time t1 to time\nC t2. Since R(t) is orthogonal, we can find Q using the\nC transpose of R1. We find the rotation axis and angle via\nC RAXISA.\nC\nC CALL MXMT ( R2, R1, Q )\nC CALL RAXISA ( Q, AXIS, ANGLE )\nC\nC Find the fraction of the total rotation angle that R\nC rotates through in the time interval [t1, t3].\nC\nC FRAC = ( T3 - T1 ) / ( T2 - T1 )\nC\nC Finally, find the rotation DELTA that R(t) undergoes\nC during the time interval [t1, t3], and apply that rotation\nC to R1, yielding R(t3), which we'll call R3.\nC\nC CALL AXISAR ( AXIS, FRAC * ANGLE, DELTA )\nC CALL MXM ( DELTA, R1, R3 )\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC N.J. Bachman (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 1.1.0, 25-AUG-2005 (NJB)\nC\nC Updated to remove non-standard use of duplicate arguments\nC in VROTV call.\nC\nC- SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)\nC\nC Comment section for permuted index source lines was added\nC following the header.\nC\nC- SPICELIB Version 1.0.0, 30-AUG-1990 (NJB)\nC\nC-&\n \nC$ Index_Entries\nC\nC axis and angle to rotation\nC\nC-&\n \nC$ Revisions\nC\nC- SPICELIB Version 1.1.0, 25-AUG-2005 (NJB)\nC\nC Updated to remove non-standard use of duplicate arguments\nC in VROTV call. \nC \nC Identity matrix is now obtained from IDENT.\nC\nC-& \n \n \nC\nC Local variables\nC\n DOUBLE PRECISION VTEMP ( 3 )\n INTEGER I\n \nC\nC First, set R equal to the identity.\nC\n CALL IDENT ( R )\n \nC\nC The matrix we want rotates EVERY vector by ANGLE about AXIS.\nC In particular, it does so to our basis vectors. The columns\nC of R are the images of the basis vectors under this rotation.\nC\n DO I = 1, 3\n CALL VROTV ( R(1,I), AXIS, ANGLE, VTEMP )\n CALL VEQU ( VTEMP, R(1,I) )\n END DO\n \n RETURN\n END\n", "meta": {"hexsha": "24859ff19d62cc0703cce2587d7f0a418e3c648f", "size": 7405, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/axisar.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/axisar.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/axisar.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": 30.1016260163, "max_line_length": 72, "alphanum_fraction": 0.601215395, "num_tokens": 2101, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8902942348544447, "lm_q2_score": 0.7401743677704878, "lm_q1q2_score": 0.6589729724130988}} {"text": "\tSUBROUTINE SNDHLC ( nparms, nlevel, hdata, iret )\nC************************************************************************\nC* SNDHLC\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This routine will compute the Helicity for a sounding processed\t*\nC* with SNDIAG.\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* SNDHLC ( NPARMS, NLEVEL, HDATA, IRET )\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*\tNPARMS\t\tINTEGER\t\tNumber of parameters\t\t*\nC*\tNLEVEL\t\tINTEGER\t\tNumber of levels\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input/Output parameters:\t\t\t\t\t\t*\nC*\tHDATA (LLMXLV)\tREAL\t\tInterpolated sounding data\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tIRET\t\tINTEGER\t\tReturn code\t\t\t*\nC*\t\t\t\t\t 0 = normal\t\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* S. Jacobs/SSAI\t 4/92\t\t\t\t\t\t*\nC* J. Whistler/SSAI\t 4/93\t\tCleaned up header\t\t*\nC************************************************************************\n\tINCLUDE\t\t'GEMPRM.PRM'\n\tINCLUDE\t\t'sndiag.prm'\nC*\n\tREAL\t\thdata(*)\nC*\n\tINCLUDE\t\t'ERMISS.FNC'\nC------------------------------------------------------------------------\n\tiret = 0\nC\n\tDO i = 1, nlevel\n\t IF ( ( .not. ERMISS(hdata((i-1)*nparms+IUWND)) ) .and.\n + ( .not. ERMISS(hdata((i-1)*nparms+IVWND)) ) .and.\n + ( .not. ERMISS(hdata(0*nparms+IUWND)) ) .and.\n + ( .not. ERMISS(hdata(0*nparms+IVWND)) ) ) THEN\n\t\tIF ( hdata((i-1)*nparms+IHGHT) .ne.\n +\t\t hdata(0*nparms+IHGHT) ) THEN\n\t\t term1 = hdata((i-1)*nparms+IVWND) * \n +\t\t\t(hdata((i-1)*nparms+IUWND)-\n +\t\t\t\thdata(0*nparms+IUWND)) /\n +\t\t\t(hdata((i-1)*nparms+IHGHT)-\n +\t\t\t\thdata(0*nparms+IHGHT))\n\t\t term2 = hdata((i-1)*nparms+IUWND) * \n +\t\t \t(hdata((i-1)*nparms+IVWND)-\n +\t\t\t\thdata(0*nparms+IVWND)) /\n +\t\t \t(hdata((i-1)*nparms+IHGHT)-\n +\t\t\t\thdata(0*nparms+IHGHT))\n\t\t hdata((i-1)*nparms+IHELC) = term1 - term2\n\t\tELSE\n\t\t hdata((i-1)*nparms+IHELC) = RMISSD\n\t\tEND IF\n\t END IF\n\tEND DO\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "1321307563d1b9c1658ee61f6c02de022425b8f4", "size": 1881, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/programs/sn/sndiag/sndhlc.f", "max_stars_repo_name": "oxelson/gempak", "max_stars_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2015-06-03T15:26:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T22:36:03.000Z", "max_issues_repo_path": "gempak/source/programs/sn/sndiag/sndhlc.f", "max_issues_repo_name": "oxelson/gempak", "max_issues_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 60, "max_issues_repo_issues_event_min_datetime": "2015-05-11T21:36:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T16:22:42.000Z", "max_forks_repo_path": "gempak/source/programs/sn/sndiag/sndhlc.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.35, "max_line_length": 73, "alphanum_fraction": 0.4726209463, "num_tokens": 700, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942348544447, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6589729673104028}} {"text": "program rzf\nuse omp_lib\n\ndouble precision pi, pi_squared_over_6, zeta_2, zeta, z2, zeta_fixed2\ninteger*8 N, u, l, Nthr, thrid\npi = 4.0d0*atan(1.0d0)\npi_squared_over_6 = pi*pi / 6.0d0\nN = 16000000000_8\nzeta_2 = 0.0d0\n\n\n!$OMP PARALLEL shared(N) private(u,l,Nthr,thrid,i,z2) \nthrid = OMP_GET_THREAD_NUM()\nNthr = omp_get_num_threads()\n\nu = N/Nthr * (thrid + 1)\nl = N/Nthr * (thrid) + 1\n!z2 = zeta(u,l,2_8)\nz2 = zeta_fixed2(u,l)\n\n!$OMP ATOMIC\nzeta_2 = zeta_2 + z2\n\n\n!zeta(N,2_8)\n!$OMP END PARALLEL\n\n\n\nprint *,\" zeta(2) = \",zeta_2\nprint *,\"pi^2 / 6.0 = \",pi_squared_over_6\nprint *,\" error = \",pi_squared_over_6 - zeta_2\n\n\nend\n\ndouble precision function zeta(upper,lower,a)\ninteger*8 N,a,k,upper,lower\ninteger unr\ndouble precision xsum, ri\ndouble precision, dimension(4) :: r,ik,dk = (/ 4.0d0,4.0d0,4.0d0,4.0d0/), qsum = 0.0d0\n\n\nxsum = 0.0\n\ndo unr=1,4\n ik(unr) = dble( upper - (unr-1) )\nenddo \n\ndo k=upper,lower,-4\n r = 1.0d0 / ik\n ik = ik - dk\n qsum = qsum + r**a\nenddo \n\nzeta = xsum + sum(qsum)\n\nend function\n\ndouble precision function zeta_fixed2(upper,lower)\ninteger*8 N,k,upper,lower\ninteger unr\ndouble precision xsum, ri\ndouble precision, dimension(4) :: r,ik,dk = (/ 4.0d0,4.0d0,4.0d0,4.0d0/), qsum = 0.0d0\n\n\nxsum = 0.0\n\ndo unr=1,4\n ik(unr) = dble( upper - (unr-1) )\nenddo\n\ndo k=upper,lower,-4\n r = 1.0d0 / ik\n ik = ik - dk\n qsum = qsum + r*r ! r**a, when a is fixed at 2\nenddo\n\nzeta_fixed2 = xsum + sum(qsum)\n\nend function\n\n", "meta": {"hexsha": "16178f533d0a77c3a9332664ae8814f97120913a", "size": 1495, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gfortran/frzf_vect_omp.f", "max_stars_repo_name": "joelandman/rzf", "max_stars_repo_head_hexsha": "11f88f846da27ea355578c517fe5a3caf8b80315", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2017-11-15T23:33:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-24T06:01:16.000Z", "max_issues_repo_path": "gfortran/frzf_vect_omp.f", "max_issues_repo_name": "joelandman/rzf", "max_issues_repo_head_hexsha": "11f88f846da27ea355578c517fe5a3caf8b80315", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gfortran/frzf_vect_omp.f", "max_forks_repo_name": "joelandman/rzf", "max_forks_repo_head_hexsha": "11f88f846da27ea355578c517fe5a3caf8b80315", "max_forks_repo_licenses": ["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.0120481928, "max_line_length": 86, "alphanum_fraction": 0.6314381271, "num_tokens": 649, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.7401743735019595, "lm_q1q2_score": 0.6589729667432779}} {"text": "\tFUNCTION FLILO(X,B) \nC \nC \nC FLILO MEANS LINEAR FUNCTION FOR SMALL ARGUMENT\nC AND LOGARITHM FOR LARGE ARGUMENT\nC SIGN IS PRESERVED \nC FOR /X/.LT.B FLILO=X\nC FOR /X/.GT.B FLILO=A*LOG(X)+C IN SUCH A WAY \nC THAT FLILO AND ITS DERIVATIVE ARE CONTINUOUS AT /X/=/B/ \nC \n XM=ABS(X) \n IF(XM.GT.B) GO TO 1 \n\t FLILO=X\n RETURN\n 1 FT=B*ALOG(XM/B)+B \n FLILO=SIGN(FT,X)\n RETURN \n\tEND \n FUNCTION AFLILO(X,B) \nC \nC INVERSE OF FLILO\nC \n XM=ABS(X) \n IF(XM.GT.B) GO TO 1 \n AFLILO=X\n RETURN\n 1 FT=B*EXP(XM/B-1.) \n AFLILO=SIGN(FT,X) \n RETURN\n END \n\n", "meta": {"hexsha": "c107cc974c53014b543911deee2de5b13b915d8d", "size": 686, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/waves_dir/loglin_1.for", "max_stars_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_stars_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/waves_dir/loglin_1.for", "max_issues_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_issues_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/waves_dir/loglin_1.for", "max_forks_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_forks_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.4375, "max_line_length": 64, "alphanum_fraction": 0.5102040816, "num_tokens": 252, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436395, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6589729651558994}} {"text": "program P3\n implicit none\n real*8, external :: drand48\n real*8 :: I=0,x\n integer :: n,j\n n = 0\n ! do-while loop until reach desired accuracy\n do while (abs(I-155.0/6)>1E-4)\n x = 0\n n = n + 1\n ! do loop to scatter one point in 10-D space\n do j = 1,10\n x = x + drand48()\n enddo\n I = I * ( n - 1 ) + x**2 ! reverse the total value in 10-D space for n trails\n I = I / n ! average value of all the n possible points is the integration result\n print \"(i6,2x,f6.3)\", n, I\n enddo\nend program P3", "meta": {"hexsha": "9bb205256acea0a2e4e50b72e3a7565e89c2ab7b", "size": 532, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "HW3/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": "HW3/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": "HW3/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": 28.0, "max_line_length": 85, "alphanum_fraction": 0.5827067669, "num_tokens": 194, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6589729608468927}} {"text": "*----------------------------------------------------------------------*\n subroutine inv_svd(vx,amat,vb,ndim,inc_b)\n*----------------------------------------------------------------------*\n* solve A*x + b = 0 by singular value decomposition\n* A(ndim,ndim), vx(ndim), vb(inc_b,ndim)\n*----------------------------------------------------------------------*\n\n implicit none\n\n include 'stdunit.h'\n\n integer, intent(in) ::\n & ndim, inc_b\n real(8), intent(in) ::\n & amat(ndim,ndim)\n real(8), intent(inout) ::\n & vx(ndim)\n real(8), intent(in) ::\n & vb(inc_b,ndim)\n\n real(8), parameter ::\n & thrsh = 1d-12\n\n real(8), pointer ::\n & umat(:,:), vtmat(:,:), wrk(:), singval(:)\n\n integer ::\n & idx, kdx, info, lwrk\n\n lwrk=max(1024,ndim*ndim)\n allocate(umat(ndim,ndim),vtmat(ndim,ndim),\n & wrk(lwrk),singval(ndim))\n\n call dgesvd('A','A',ndim,ndim,\n & amat,ndim,singval,\n & umat,ndim,vtmat,ndim,\n & wrk,lwrk,info)\n\n if (info.ne.0) then\n write(lulog,*) 'WARNING: SVD seems to be in trouble'\n end if\n\n do idx = 1, ndim\n wrk(idx) = 0d0\n if (abs(singval(idx)).lt.thrsh) cycle\n do kdx = 1, ndim\n wrk(idx) = wrk(idx)+\n & umat(kdx,idx)*vb(1,kdx)\n end do\n wrk(idx) = wrk(idx)/singval(idx)\n end do\n \n do idx = 1, ndim\n vx(idx) = 0d0\n do kdx = 1, ndim\n vx(idx) = vx(idx) +\n & vtmat(kdx,idx)*wrk(kdx)\n end do\n end do\n \n return\n end\n\n", "meta": {"hexsha": "ffa187a9c5d57c41c9768b4451434fc03a774136", "size": 1625, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "solve/inv_svd.f", "max_stars_repo_name": "ak-ustutt/GeCCo-public", "max_stars_repo_head_hexsha": "8d43a6c9323aeba7eb54625b95553bfd4b2418c6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "solve/inv_svd.f", "max_issues_repo_name": "ak-ustutt/GeCCo-public", "max_issues_repo_head_hexsha": "8d43a6c9323aeba7eb54625b95553bfd4b2418c6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "solve/inv_svd.f", "max_forks_repo_name": "ak-ustutt/GeCCo-public", "max_forks_repo_head_hexsha": "8d43a6c9323aeba7eb54625b95553bfd4b2418c6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.390625, "max_line_length": 72, "alphanum_fraction": 0.4141538462, "num_tokens": 503, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004185, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6589729565378857}} {"text": " SUBROUTINE MCON(ETA,INFINY,SMALNO,BASE) MCON4840\nC MCON PROVIDES MACHINE CONSTANTS USED IN VARIOUS PARTS OF THE\nC PROGRAM. THE USER MAY EITHER SET THEM DIRECTLY OR USE THE\nC STATEMENTS BELOW TO COMPUTE THEM. THE MEANING OF THE FOUR\nC CONSTANTS ARE -\nC ETA THE MAXIMUM RELATIVE REPRESENTATION ERROR\nC WHICH CAN BE DESCRIBED AS THE SMALLEST POSITIVE\nC FLOATING-POINT NUMBER SUCH THAT 1.0D0 + ETA IS\nC GREATER THAN 1.0D0.\nC INFINY THE LARGEST FLOATING-POINT NUMBER\nC SMALNO THE SMALLEST POSITIVE FLOATING-POINT NUMBER\nC BASE THE BASE OF THE FLOATING-POINT NUMBER SYSTEM USED\nC LET T BE THE NUMBER OF BASE-DIGITS IN EACH FLOATING-POINT\nC NUMBER(DOUBLE PRECISION). THEN ETA IS EITHER .5*B**(1-T)\nC OR B**(1-T) DEPENDING ON WHETHER ROUNDING OR TRUNCATION\nC IS USED.\nC LET M BE THE LARGEST EXPONENT AND N THE SMALLEST EXPONENT\nC IN THE NUMBER SYSTEM. THEN INFINY IS (1-BASE**(-T))*BASE**M\nC AND SMALNO IS BASE**N.\nC THE VALUES FOR BASE,T,M,N BELOW CORRESPOND TO THE IBM/360.\n DOUBLE PRECISION ETA,INFINY,SMALNO,BASE\n INTEGER M,N,T\n BASE = 16.0D0\n T = 14\n M = 63\n N = -65\n ETA = BASE**(1-T)\n INFINY = BASE*(1.0D0-BASE**(-T))*BASE**(M-1)\n SMALNO = (BASE**(N+3))/BASE**3\n RETURN\n END\n", "meta": {"hexsha": "05fad78e12e8e3812276433d6a98100db59873b7", "size": 1278, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/f2cl/packages/toms/419/mcon.f", "max_stars_repo_name": "sbwhitecap/clocc-hg", "max_stars_repo_head_hexsha": "f6cf2591ceef8a3a80e04da9b414cdf60a25a90f", "max_stars_repo_licenses": ["MIT"], "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/f2cl/packages/toms/419/mcon.f", "max_issues_repo_name": "sbwhitecap/clocc-hg", "max_issues_repo_head_hexsha": "f6cf2591ceef8a3a80e04da9b414cdf60a25a90f", "max_issues_repo_licenses": ["MIT"], "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/f2cl/packages/toms/419/mcon.f", "max_forks_repo_name": "sbwhitecap/clocc-hg", "max_forks_repo_head_hexsha": "f6cf2591ceef8a3a80e04da9b414cdf60a25a90f", "max_forks_repo_licenses": ["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.9375, "max_line_length": 80, "alphanum_fraction": 0.6854460094, "num_tokens": 416, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.7401743505760728, "lm_q1q2_score": 0.6589729506415003}} {"text": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\ncc cc\ncc mncloc : clocur test program cc\ncc cc\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\n real x(38),w(19),u(19),t(40),c(80),wrk(1500),sp(40)\n integer iwrk(40)\n real al,del,fp,s\n integer i,idim,ier,iopt,ipar,is,i1,i2,j,j1,k,l,lwrk,l1,m,mx,\n * n,nc,nest,nk1\nc the data absciss values\n data x(1),x(3),x(5),x(7),x(9),x(11),x(13),x(15),x(17),x(19),x(21),\n * x(23),x(25),x(27),x(29),x(31),x(33),x(35)/-4.7,-7.048,-6.894,\n * -3.75,-1.042,0.938,2.5,3.524,4.511,5.0,4.886,3.524,3.2,1.302,\n * -1.424,-3.0,-3.064,-3.665/\nc the data ordinate values\n data x(2),x(4),x(6),x(8),x(10),x(12),x(14),x(16),x(18),x(20),\n * x(22),x(24),x(26),x(28),x(30),x(32),x(34),x(36)/0.0,2.565,\n * 5.785,6.495,5.909,5.318,4.33,2.957,1.642,0.0,-1.779,-2.957,\n * -5.543,-7.386,-8.075,-5.196,-2.571,-1.334/\nc m denotes the number of data points\n m = 19\nc the first and last data point coincide\n x(2*m-1) = x(1)\n x(2*m) = x(2)\nc we set up the weights and parameter values of the data points\n do 10 i=1,m\n w(i) = 1.0\n al = (i-1)*20\n u(i) = al\n 10 continue\nc we set up the dimension information.\n nest = 40\n lwrk = 1500\n nc = 80\n mx = 38\nc we will determine a planar closed curve x=sx(u) , y=sy(u)\n idim = 2\nc for the first approximations we will use cubic splines\n k = 3\nc we will also supply the parameter values u(i)\n ipar = 1\nc loop for the different approximating spline curves\n do 400 is=1,9\n go to (110,120,130,140,150,160,170,180,190),is\nc we start computing the least-squares point ( s very large)\n 110 iopt = 0\n s = 900.\n go to 300\nc iopt = 1 from the second call on\n 120 iopt = 1\n s = 10.\n go to 300\nc a smaller value for s to get a closer approximation\n 130 s = 0.1\n go to 300\nc a larger value for s to get a smoother approximation\n 140 s = 0.5\n go to 300\nc if a satisfactory fit is obtained we can calculate a curve of equal\nc quality of fit (same value for s) but possibly with fewer knots by\nc specifying iopt=0\n 150 iopt = 0\n s = 0.5\n go to 300\nc we determine a spline curve with respect to the same smoothing\nc factor s, but now we let the program determine parameter values u(i)\n 160 ipar = 0\n iopt = 0\n s = 0.5\n go to 300\nc we choose a different degree of spline approximation\n 170 k = 5\n iopt = 0\n s = 0.5\n go to 300\nc we determine an interpolating curve\n 180 s = 0.\n go to 300\nc finally we calculate a least-squares spline curve with specified\nc knots\n 190 iopt =-1\n n = 9+2*k\n j = k+2\n del = (u(m)-u(1))*0.125\n do 200 l=1,7\n al = l\n t(j) = u(1)+al*del\n j = j+1\n 200 continue\nc determine the approximating closed curve\n 300 call clocur(iopt,ipar,idim,m,u,mx,x,w,k,s,nest,n,t,nc,\n * c,fp,wrk,lwrk,iwrk,ier)\nc printing of the results.\n if(iopt.ge.0) go to 310\n write(6,910) k,ipar\n go to 320\n 310 write(6,915) k,ipar\n write(6,920) s\n 320 write(6,925) fp,ier\n write(6,930) n\n write(6,935)\n if(ipar.eq.1) write(6,940) (t(i),i=1,n)\n if(ipar.eq.0) write(6,950) (t(i),i=1,n)\n nk1 = n-k-1\n write(6,945)\n write(6,950) (c(l),l=1,nk1)\n write(6,955)\n i1 = n+1\n i2 = n+nk1\n write(6,950) (c(l),l=i1,i2)\n write(6,960)\nc we evaluate the spline curve\n call curev(idim,t,n,c,nc,k,u,m,sp,mx,ier)\n do 330 i=1,9\n l = (i-1)*4+1\n l1 = l+1\n j = l+2\n j1 = j+1\n write(6,965) x(l),x(l1),sp(l),sp(l1),x(j),x(j1),sp(j),sp(j1)\n 330 continue\n 400 continue\n stop\n 910 format(38h0least-squares closed curve of degree ,i1,7h ipar=,i1)\n 915 format(34h0smoothing closed curve of degree ,i1,7h ipar=,i1)\n 920 format(20h smoothing factor s=,f7.1)\n 925 format(1x,23hsum squared residuals =,e15.6,5x,11herror flag=,i2)\n 930 format(1x,24htotal number of knots n=,i3)\n 935 format(1x,22hposition of the knots )\n 940 format(5x,10f6.0)\n 945 format(1x,30hb-spline coefficients of sx(u))\n 950 format(5x,8f9.4)\n 955 format(1x,30hb-spline coefficients of sy(u))\n 960 format(1h0,2(4x,2hxi,7x,2hyi,6x,6hsx(ui),3x,6hsy(ui)))\n 965 format(1h ,8f9.4)\n end\n", "meta": {"hexsha": "03d80a694d347d4cd43760fe183aa1079f767594", "size": 4709, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ApproxSpline/Resources/F77-Sources/ex/mncloc.f", "max_stars_repo_name": "modelica-3rdparty/ApproxSpline", "max_stars_repo_head_hexsha": "28420f5c1a88c9cd069defbd8c05e4a78a090675", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-07-13T17:24:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-18T16:16:02.000Z", "max_issues_repo_path": "ApproxSpline/Resources/F77-Sources/ex/mncloc.f", "max_issues_repo_name": "tbeu/ApproxSpline", "max_issues_repo_head_hexsha": "28420f5c1a88c9cd069defbd8c05e4a78a090675", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-03-28T09:08:23.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T07:35:48.000Z", "max_forks_repo_path": "ApproxSpline/Resources/F77-Sources/ex/mncloc.f", "max_forks_repo_name": "modelica-3rdparty/ApproxSpline", "max_forks_repo_head_hexsha": "28420f5c1a88c9cd069defbd8c05e4a78a090675", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-10-21T07:46:49.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T20:02:06.000Z", "avg_line_length": 34.3722627737, "max_line_length": 72, "alphanum_fraction": 0.5574431939, "num_tokens": 1808, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942173896131, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6589729492806861}} {"text": " subroutine radcur(day,hr,rdlat,decl,ratio)\r\n\r\nc\r\nc +++PURPOSE+++\r\nc This function is from Jensen etal. 1990 ACSE No. 70\r\nc \"ET and Irrigation Water Requirements\". We are using\r\nc it to find the ratio between the hourly potential radiation\r\nc and the estimated radiation on a sloping surface for the day.\r\nc This function returns an hourly value which, in turn is used\r\nc in the sunmap routine to find the ratio of hourly to\r\nc daily. The daily radiation value is then broken up into\r\nc an hourly value distributed over a bell shaped curve.\r\nc\r\nc Author(s): John Witte, UofMn WCES @ USDA-ARS-NCSRL\r\nc Date: 03/24/93\r\n\r\nc Verified and tested by Reza Savabi, USDA-ARS, NSERL 317-494-5051\r\nc August 1994\r\nc\r\nc +++ARGUMENT DECLARATIONS+++\r\n real ratio,rdlat,decl\r\n integer day,hr\r\nc\r\nc +++ARGUMENT DEFINITIONS+++\r\nc ratio - The calculated factor with which to multiply daily\r\nc radiation to calculate hourly radiation.\r\nc rdlat - The latitude in radian units.\r\nc day - The julian day of year.\r\nc hr - The hour of the day being run.\r\nc decl - Declination of the sun in radian units.(+)North (-)Sth.\r\nc\r\nc +++COMMON BLOCKS+++\r\nc\r\nc +++LOCAL VARIABLES+++\r\n real pi,slrtm,hasun,haset,harise,solcon,rdsun,dfact\r\nc\r\nc +++LOCAL DEFINITIONS+++\r\nc dfact - Day factor used in solar time correction equation.\r\nc pi - Estimated value of 22/7.\r\nc slrtm - Seasonal correction for solar time (hrs).\r\nc hasun - Hour angle of the sun given the day of year (degrees).\r\nc haset - Hour angle at sunset (deg).\r\nc harise - Hour angle at sunrise (deg).\r\nc solcon - Solar constant--this time units are: (MJ/m^2.min).\r\nc rdsun - Relative distance between earth and sun.\r\nc\r\nc +++END SPECIFICATIONS+++\r\nc\r\n\r\n pi = 3.141593\r\n solcon = 0.082\r\n\r\n dfact = ((2 * pi) * (day - 81)) / 365\r\n\r\n slrtm = (0.1645 * sin(2 * dfact)) - (0.1255 * cos(dfact)) -\r\n 1 (0.025 * sin(dfact))\r\n\r\n hasun = ((hr + slrtm) - 12) * (pi / 12)\r\n\r\nc -- Could possibly add a longitude adjustment for locations between\r\nc -- longitudinal coordinates. However, such an adjustment is so\r\nc -- minute that Bob decided we didn't need it here.\r\n\r\n haset = hasun - (pi / 24)\r\n\r\n harise = hasun + (pi / 24)\r\n\r\n rdsun = 1 + 0.033 * cos((2 * pi * day) / 365)\r\n\r\n ratio = ((12 * 60) / pi) * solcon * rdsun * (cos(rdlat) *\r\n 1 cos(decl) * (sin(harise) - sin(haset)) +\r\n 2 (harise - haset) * sin(rdlat) * sin(decl))\r\n\r\n if (ratio .lt. 0.0) ratio = 0.0\r\n\r\n return\r\n\r\n end\r\n", "meta": {"hexsha": "14173372c35499b2c61a15042a35d5ef4ab74cb3", "size": 2699, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/wepp2010.1/radcur.for", "max_stars_repo_name": "jarad/dep", "max_stars_repo_head_hexsha": "fe73982f4c70039e1a31b9e8e2d9aac31502f803", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-11-26T17:49:19.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-26T17:49:19.000Z", "max_issues_repo_path": "src/wepp2010.1/radcur.for", "max_issues_repo_name": "jarad/dep", "max_issues_repo_head_hexsha": "fe73982f4c70039e1a31b9e8e2d9aac31502f803", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 54, "max_issues_repo_issues_event_min_datetime": "2018-12-12T18:02:31.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T19:14:25.000Z", "max_forks_repo_path": "src/wepp2010.1/radcur.for", "max_forks_repo_name": "akrherz/idep", "max_forks_repo_head_hexsha": "7189a26fbcec3d8c3cc7d7015107b8fb6c5f6a45", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-03-02T22:59:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-09T15:49:00.000Z", "avg_line_length": 34.164556962, "max_line_length": 71, "alphanum_fraction": 0.5983697666, "num_tokens": 814, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9653811611608242, "lm_q2_score": 0.6825737344123242, "lm_q1q2_score": 0.6589438243048495}} {"text": "! { dg-do run }\n! { dg-require-effective-target fortran_large_real }\n! PR 24174 and PR 24305\nprogram large_real_kind_form_io_1\n ! This should be 10 on systems that support kind=10\n integer, parameter :: k = selected_real_kind (precision (0.0_8) + 1)\n real(kind=k) :: a,b(2), c, eps\n complex(kind=k) :: d, e, f(2), g\n character(len=180) :: tmp\n ! Test real(k) scalar and array formatted IO\n eps = 10 * spacing (2.0_k) ! 10 ulp precision is enough.\n b(:) = 2.0_k\n write (tmp, *) b\n read (tmp, *) a, c\n if (abs (a - b(1)) > eps) call abort ()\n if (abs (c - b(2)) > eps) call abort ()\n ! Complex(k) scalar and array formatted and list formatted IO\n d = cmplx ( 1.0_k, 2.0_k, k)\n f = d\n write (tmp, *) f\n read (tmp, *) e, g\n if (abs (e - d) > eps) call abort ()\n if (abs (g - d) > eps) call abort ()\n write (tmp, '(2(e12.4e5, 2x))') d\n read (tmp, '(2(e12.4e5, 2x))') e\n if (abs (e - d) > eps) call abort()\nend program large_real_kind_form_io_1\n", "meta": {"hexsha": "c6fb76b7d1069c6073c2ace660345cbddbe053b9", "size": 961, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "llvm-gcc-4.2-2.9/gcc/testsuite/gfortran.dg/large_real_kind_form_io_1.f90", "max_stars_repo_name": "vidkidz/crossbridge", "max_stars_repo_head_hexsha": "ba0bf94aee0ce6cf7eb5be882382e52bc57ba396", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-04-09T02:58:13.000Z", "max_stars_repo_stars_event_max_datetime": "2016-04-09T02:58:13.000Z", "max_issues_repo_path": "llvm-gcc-4.2-2.9/gcc/testsuite/gfortran.dg/large_real_kind_form_io_1.f90", "max_issues_repo_name": "vidkidz/crossbridge", "max_issues_repo_head_hexsha": "ba0bf94aee0ce6cf7eb5be882382e52bc57ba396", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "llvm-gcc-4.2-2.9/gcc/testsuite/gfortran.dg/large_real_kind_form_io_1.f90", "max_forks_repo_name": "vidkidz/crossbridge", "max_forks_repo_head_hexsha": "ba0bf94aee0ce6cf7eb5be882382e52bc57ba396", "max_forks_repo_licenses": ["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.3214285714, "max_line_length": 70, "alphanum_fraction": 0.6077003122, "num_tokens": 367, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256551882382, "lm_q2_score": 0.782662489091802, "lm_q1q2_score": 0.6588653626709635}} {"text": "module m_ranmean3\r\ncontains\r\nsubroutine ranmean3(ens,ave,n_var,n_ens)\r\n! Return ensemble mean vector\r\n!\r\n implicit none \r\n integer :: j\r\n integer,intent(in) :: n_var,n_ens\r\n real(8),intent(in) :: ens(n_var,n_ens)\r\n real(8),intent(out) :: ave(n_var)\r\n!\r\n ave(:)=ens(:,1)\r\n do j=2,n_ens\r\n ave(:)=ave(:)+ens(:,j)\r\n enddo\r\n ave(:)=ave(:)/dble(n_ens)\r\n!\r\nend subroutine ranmean3\r\nend module\r\n", "meta": {"hexsha": "d0b57d555c64fefdda199e98c084a7bd4b284497", "size": 413, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/m_ranmean3.f90", "max_stars_repo_name": "DAE-Code/NS2D_EnKF", "max_stars_repo_head_hexsha": "bae47eb9f771d07dbd0d814c03cf4759ffc7c819", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-06-02T05:52:46.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-04T02:17:28.000Z", "max_issues_repo_path": "src/m_ranmean3.f90", "max_issues_repo_name": "DAE-Code/NS2D_EnKF", "max_issues_repo_head_hexsha": "bae47eb9f771d07dbd0d814c03cf4759ffc7c819", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/m_ranmean3.f90", "max_forks_repo_name": "DAE-Code/NS2D_EnKF", "max_forks_repo_head_hexsha": "bae47eb9f771d07dbd0d814c03cf4759ffc7c819", "max_forks_repo_licenses": ["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.65, "max_line_length": 42, "alphanum_fraction": 0.607748184, "num_tokens": 141, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.841825655188238, "lm_q2_score": 0.7826624738835052, "lm_q1q2_score": 0.658865349868229}} {"text": "module line_mod\n use :: types_mod, only : sp\n implicit none\n\n private\n real(kind=sp) :: epsilon = 1.0e-4_sp\n public :: on_line, line, set_epsilon, get_epsilon\n\ncontains\n\n subroutine set_epsilon(eps)\n implicit none\n real(kind=sp), intent(in) :: eps\n epsilon = eps\n end subroutine set_epsilon\n\n function get_epsilon() result(eps)\n implicit none\n real(kind=sp) :: eps\n eps = epsilon\n end function get_epsilon\n\n elemental function line(x) result(y)\n implicit none\n real(kind=sp), intent(in) :: x\n real(kind=sp) :: y\n y = 3.0 + 0.5*x\n end function line\n\n elemental function on_line(x, y) result(is_on_line)\n implicit none\n real(kind=sp), intent(in) :: x, y\n logical :: is_on_line\n real(kind=sp) :: y_exp\n y_exp = line(x)\n is_on_line = equal(y, y_exp)\n\n contains\n\n pure function equal(a, b) result(is_equal)\n implicit none\n real(kind=sp), intent(in) :: a, b\n logical :: is_equal\n is_equal = abs(a - b) < epsilon\n end function equal\n\n end function on_line\n\nend module line_mod\n", "meta": {"hexsha": "39e4e4c88de5175b78f94fdf220b78b39a2f5f65", "size": 1182, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran/Functions/line_mod.f90", "max_stars_repo_name": "Gjacquenot/training-material", "max_stars_repo_head_hexsha": "16b29962bf5683f97a1072d961dd9f31e7468b8d", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 115, "max_stars_repo_stars_event_min_datetime": "2015-03-23T13:34:42.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T00:27:21.000Z", "max_issues_repo_path": "Fortran/Functions/line_mod.f90", "max_issues_repo_name": "Gjacquenot/training-material", "max_issues_repo_head_hexsha": "16b29962bf5683f97a1072d961dd9f31e7468b8d", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 56, "max_issues_repo_issues_event_min_datetime": "2015-02-25T15:04:26.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-03T07:42:48.000Z", "max_forks_repo_path": "Fortran/Functions/line_mod.f90", "max_forks_repo_name": "Gjacquenot/training-material", "max_forks_repo_head_hexsha": "16b29962bf5683f97a1072d961dd9f31e7468b8d", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 59, "max_forks_repo_forks_event_min_datetime": "2015-11-26T11:44:51.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T00:27:22.000Z", "avg_line_length": 23.64, "max_line_length": 55, "alphanum_fraction": 0.5803722504, "num_tokens": 309, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256393148982, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6588653459799177}} {"text": "C NCLFORTSTART\n SUBROUTINE DRMSD(X,Y,NPTS,XMSG,YMSG,XYRMSD,NPTUSE,IER)\n IMPLICIT NONE\nc\nc NCL: rmsd = dim_rmsd(x,y)\nc interface must chk that the length of x and y are the same\nc input\n INTEGER NPTS\n DOUBLE PRECISION X(NPTS),Y(NPTS),XMSG,YMSG\nc output\n INTEGER NPTUSE,IER\n DOUBLE PRECISION XYRMSD\nC NCLEND\n\nc this routine will calculate estimates of the first two moments\nc . of the vector x containing missing data.\n\nc input arguments:\nc . x,y - input vectors\nc . npts - length of x and y\nc . xmsg,ymsg- missing code: if there are no msg values\nc . set xmsg to some value which will\nc . not be encountered.\n\nc output arguments:\nc . xyrmsd - root-mean-square-difference\nc . nptuse - no. of points used to calculate the estimates\nc . ier - if (ier.ne.0) an error has occurred\n\nc note :\nc . uncalculated quantities are set to xmsg (nptuse set to zero)\n\n INTEGER N\n DOUBLE PRECISION RN\n\n NPTUSE = 0\n XYRMSD = XMSG\n\n IF (NPTS.LT.1) THEN\n IER = 1\n RETURN\n END IF\n\n IER = 0\n XYRMSD = 0.D0\n RN = 0.D0\n DO N = 1,NPTS\n IF (X(N).NE.XMSG .AND. Y(N).NE.YMSG) THEN\n RN = RN + 1.0D0\n XYRMSD = XYRMSD + (X(N)-Y(N))**2\n END IF\n END DO\n\n NPTUSE = RN\n\n IF (RN.GT.0.D0) THEN\n XYRMSD = SQRT(XYRMSD/RN)\n ELSE\n XYRMSD = XMSG\nC error code for all msg values\n IER = 2\n END IF\n\n RETURN\n END\n", "meta": {"hexsha": "cf96f324513028c9afff48609155ab9c738e3a56", "size": 1649, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ni/src/lib/nfpfort/rmsd.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "ni/src/lib/nfpfort/rmsd.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "ni/src/lib/nfpfort/rmsd.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 24.9848484848, "max_line_length": 68, "alphanum_fraction": 0.5372953305, "num_tokens": 513, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256472515683, "lm_q2_score": 0.7826624738835051, "lm_q1q2_score": 0.6588653436564953}} {"text": "! caf -o bcast bcast.f90\n! cafrun -np 2 ./bcast\n! mwe for issue github.com/sourceryinstitute/OpenCoarrays/issues/503\n\nprogram main\n real, allocatable, dimension(:, :, :) :: arr1, arr2\n integer :: i, me, nimg\n real :: red1, sum1, red2, sum2\n \n allocate(arr1(10, 20, 8))\n allocate(arr2(10, 20, 30))\n\n me = this_image()\n nimg = num_images()\n\n if (me == 1) then\n arr1 = reshape([(i, i=1, size(arr1))], shape(arr1))\n arr2 = reshape([(i, i=1, size(arr2))], shape(arr2))\n end if\n\n call co_broadcast(arr1, source_image=1)\n call co_broadcast(arr2, source_image=1)\n\n sum1 = sum(arr1)\n sum2 = sum(arr2)\n\n red1 = sum1\n red2 = sum2\n\n call co_sum(red1)\n call co_sum(red2)\n\n sync all\n print *, me, ' sum1=', sum1, ' red1=', red1\n print *, me, ' sum2=', sum2, ' red2=', red2\n\n if (abs(red1 - nimg * sum1) > epsilon(0.) .or. abs(red2 - nimg * sum2) > epsilon(0.)) then\n write(*,*) 'Test failed!'\n error stop 5\n else\n write(*,*) 'Test passed.'\n end if\n deallocate(arr1, arr2)\nend program\n", "meta": {"hexsha": "06d1b3cab92cdfd5e864d088667d066e55ef9df4", "size": 1045, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/regression/reported/issue-503-multidim-array-broadcast.f90", "max_stars_repo_name": "neok-m4700/OpenCoarrays", "max_stars_repo_head_hexsha": "2a8134df5ec11a2e56c5a87cc935a9452cf25a2b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 144, "max_stars_repo_stars_event_min_datetime": "2017-02-18T19:30:00.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-16T19:53:23.000Z", "max_issues_repo_path": "src/tests/regression/reported/issue-503-multidim-array-broadcast.f90", "max_issues_repo_name": "neok-m4700/OpenCoarrays", "max_issues_repo_head_hexsha": "2a8134df5ec11a2e56c5a87cc935a9452cf25a2b", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 441, "max_issues_repo_issues_event_min_datetime": "2017-02-12T19:28:14.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-23T17:27:41.000Z", "max_forks_repo_path": "src/tests/regression/reported/issue-503-multidim-array-broadcast.f90", "max_forks_repo_name": "neok-m4700/OpenCoarrays", "max_forks_repo_head_hexsha": "2a8134df5ec11a2e56c5a87cc935a9452cf25a2b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 46, "max_forks_repo_forks_event_min_datetime": "2017-04-01T03:11:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T19:20:30.000Z", "avg_line_length": 23.2222222222, "max_line_length": 93, "alphanum_fraction": 0.5923444976, "num_tokens": 374, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673269042767, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.6588118295847607}} {"text": " subroutine trigl(x0,y0,w,h,theta,slope)\nC to draw a triangle by providing the base length less than height\nC and angle the side intersections at the start. point forms with\nC the base,x0, y0 x and y coordinates of the starting point of a\nC triangle.\nC w length of the base,\nC h height of the triangle\nC theta angle which is formed by two sides,\nC slope angle which the base of the triangle forms with the\nC positive direction of the x-axis.\n a=3.14159265/180.0\n x1=x0+w*cos(slope*a)\n y1=y0+w*sin(slope*a)\n s=h/sin(theta*a)\n x2=x0+s*cos(a*(slope+theta))\n y2=y0+s*sin(a*(slope+theta))\n call move(x0,y0,0)\n call move(x1,y1,1)\n call move(x2,y2,1)\n call move(x0,y0,1)\n return\n end\n", "meta": {"hexsha": "4c7362b62cd9a12f6775bbd217fe462fb020c3b3", "size": 842, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ftn/trigl.f", "max_stars_repo_name": "sergev/grafor", "max_stars_repo_head_hexsha": "2b7b244d84b739bdcdf1717824ee895eb015c4a0", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-11-23T08:32:55.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-12T14:05:06.000Z", "max_issues_repo_path": "ftn/trigl.f", "max_issues_repo_name": "sergev/grafor", "max_issues_repo_head_hexsha": "2b7b244d84b739bdcdf1717824ee895eb015c4a0", "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": "ftn/trigl.f", "max_forks_repo_name": "sergev/grafor", "max_forks_repo_head_hexsha": "2b7b244d84b739bdcdf1717824ee895eb015c4a0", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.6086956522, "max_line_length": 72, "alphanum_fraction": 0.5890736342, "num_tokens": 239, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966747198242, "lm_q2_score": 0.6959583187272712, "lm_q1q2_score": 0.6587918302508345}} {"text": "program main\n\n use clock_class, only : clock\n type(clock) :: timer\n\n call timer % start()\n call test_norm()\n call timer % stop()\n\n if (this_image() .eq. 1) then\n write(*, '(\"Model run time:\",F8.3,\" seconds\")') timer % getelapsed()\n end if\n\nend program main\n\n!=====================================================================!\n! Program to compute the norm of a large vector in a distributed\n! fashion using fortran coarrays and collective routines.\n!\n! Author : Komahan Boopathy (komahan@gatech.edu)\n!=====================================================================!\n\nsubroutine test_norm\n \n use vector_class, only : vector\n\n implicit none\n\n integer, parameter :: global_size = 2000000\n integer :: nimages = 1\n integer :: local_size\n\n ! Distributed work data\n real(8), allocatable :: x(:)\n type(vector) :: xvec\n real(8) :: xdot\n real(8) :: xnorm\n \n ! Determine partition\n nimages = num_images()\n local_size = global_size/nimages\n\n ! Create smaller vectors\n allocate(x(local_size))\n\n !-------------------------------------------------------------------!\n ! Test norm computations of large vector with random values\n !-------------------------------------------------------------------!\n\n test_random: block\n\n ! Set random values into the vector\n call random_number(x)\n\n ! Using direct procedure\n xdot = dot_product(x,x) \n call co_sum (xdot)\n if (this_image() == 1) then\n write(*,*) \"Norm of the array using direct procedure is\", sqrt(xdot) , this_image()\n end if\n\n ! Using CO_NORM2 function\n xnorm = co_norm2(x)\n if (this_image() == 1) then\n write(*,*) \"Norm of the vector using co_norm2 function is\", xnorm, this_image()\n end if\n\n ! Using derived datatype that uses direct procedure internally\n xvec % values = x\n xnorm = xvec % norm()\n if (this_image() == 1) then\n write(*,*) \"Norm of the vector datatype is\", xnorm , this_image()\n end if\n \n end block test_random\n\n !-------------------------------------------------------------------!\n ! Test norm computations of large vector with same values\n !-------------------------------------------------------------------!\n\n test_deterministic: block\n \n ! Set deterministic values into the vector\n x = 1.0d0\n\n ! Using direct procedure\n xdot = dot_product(x,x) \n call co_sum (xdot)\n if (this_image() == 1) then\n write(*,*) \"Norm of the array using direct procedure is\", sqrt(xdot) , this_image()\n end if\n\n ! Using CO_NORM2 function\n xnorm = co_norm2(x)\n if (this_image() == 1) then\n write(*,*) \"Norm of the vector using co_norm2 function is\", xnorm, this_image()\n end if\n \n ! Using derived datatype that uses direct procedure internally\n xvec % values = x\n xnorm = xvec % norm()\n if (this_image() == 1) then\n write(*,*) \"Norm of the vector datatype is\", xnorm , this_image()\n end if\n\n end block test_deterministic\n\n deallocate(x)\n\ncontains\n \n !===================================================================!\n ! Function to compute the norm of a distributed vector\n !===================================================================!\n \n function co_norm2(x) result(norm)\n\n real(8), intent(in) :: x(:) \n real(8) :: xdot, norm\n\n ! find dot product, sum over processors, take sqrt and return\n xdot = dot_product(x,x) \n call co_sum (xdot)\n norm = sqrt(xdot)\n\n end function co_norm2\n\n ! MPI_SUM\n pure function sum(a, b)\n real(8), intent(in) :: a, b\n real(8) :: sum\n sum = a + b\n end function sum\n\nend subroutine test_norm\n", "meta": {"hexsha": "ea4bf994a2fa52b8b74f2b709acc380b4a182a47", "size": 3600, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/norm-matmul/test.f90", "max_stars_repo_name": "komahanb/coarray-fortran", "max_stars_repo_head_hexsha": "9af9cab1c1e1083ca63cd024af16632cca17b617", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-07-04T19:56:26.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-12T08:05:41.000Z", "max_issues_repo_path": "test/norm-matmul/test.f90", "max_issues_repo_name": "komahanb/coarray-fortran", "max_issues_repo_head_hexsha": "9af9cab1c1e1083ca63cd024af16632cca17b617", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/norm-matmul/test.f90", "max_forks_repo_name": "komahanb/coarray-fortran", "max_forks_repo_head_hexsha": "9af9cab1c1e1083ca63cd024af16632cca17b617", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-07-04T19:57:48.000Z", "max_forks_repo_forks_event_max_datetime": "2018-07-04T19:57:48.000Z", "avg_line_length": 26.4705882353, "max_line_length": 90, "alphanum_fraction": 0.5444444444, "num_tokens": 886, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245870332531, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.6587683513426726}} {"text": "c # ------------------------------------------------------------\nc # Streamfunction, velocity components and derivatives\nc # \nc # Stream function depends on these global variables\nc # example (0=incompressible; 1=compressible)\nc # mapping (0=swirl; 1=twisted swirl)\nc # ------------------------------------------------------------\n double precision function swirl_psi(x,y)\n implicit none\n\n double precision x, y\n\n double precision pi, pi2\n common /compi/ pi, pi2\n\n double precision revs_per_s\n common /stream_comm/ revs_per_s\n\n integer example\n common /example_comm/ example \n\n double precision psi, r\n\n r = sqrt((x-0.5d0)**2 + (y-0.5d0)**2)\n\nc # Rigid body rotation\nc psi = r**2\n \nc # Filament formation (negative for clockwise rotation)\n psi = (4.d0/3.d0)*r**3\n\n swirl_psi = psi\n\n end\n\n\n subroutine swirl_psi_derivs(x,y,p,px,py)\n implicit none\n\n double precision x, y\n double precision p, px, py\n\n double precision pi, pi2\n common /compi/ pi, pi2\n\n double precision revs_per_s\n common /stream_comm/ revs_per_s\n\n double precision r, rx, ry\n\n r = sqrt((x-0.5d0)**2 + (y-0.5d0)**2) \n if (r .eq. 0) then\n write(5,*) 'swirl_psi_derivs (psi.f) : r .eq. 0'\n stop\n endif\n rx = x/r\n ry = y/r\n\n p = (4.d0/3.d0)*r**3 \n px = 4*r**2*rx\n py = 4*r**2*ry\n\n end\n\n subroutine swirl_velocity_components(x,y,u)\n implicit none\n\n double precision x, y, u(2)\n double precision uderivs(4)\n\n double precision pi, pi2\n common /compi/ pi, pi2\n\n double precision revs_per_s\n common /stream_comm/ revs_per_s\n\n integer example\n common /example_comm/ example \n\n double precision s\n\n call swirl_velocity_derivs(x,y,u,uderivs)\n\n end\n\n subroutine swirl_velocity_derivs(x,y,u,uderivs)\n implicit none\n\n double precision x, y, u(2)\n double precision uderivs(4)\n\n double precision pi, pi2\n common /compi/ pi, pi2\n\n double precision revs_per_s\n common /stream_comm/ revs_per_s\n\n integer example\n common /example_comm/ example \n\n double precision s, pim, u1x, u1y, u2x, u2y\n integer k\n\n\nc # uderivs(1) = u1x \nc # uderivs(2) = u1y \nc # uderivs(3) = u2x \nc # uderivs(4) = u2y \n\n u1x = 0\n u1y = 0\n u2x = 0\n u2y = 0\n\nc # Set non-zeros derivs only\n s = sqrt(2.d0)\n if (example .eq. 0) then\nc # Conservative for all solvers (rp=1,2,3,4) \n u(1) = 1\n u(2) = 1\n elseif (example .eq. 1) then\nc # Conservative for all solvers (rp=1,2,3,4) \n u(1) = s*(cos(pi*x)**2 + 0.5d0) \n u(2) = s*(sin(pi*y)**2 + 0.5d0)\n u1x = -pi*s*sin(pi*x)\n u2y = pi*s*cos(pi*y)\n elseif (example .eq. 2) then\n u(1) = s*(cos(pi*x)**2 - 0.5d0)\n u(2) = s*(sin(pi*y)**2 - 0.5d0)\n u1x = -pi*s*sin(pi*x)\n u2y = pi*s*cos(pi*y)\n else if (example .ge. 3) then \nc u = 1\nc u = s*(sin(pi*yc)**2 + 0.5d0)\nc u = s*sin(pi*yc)\n\nc v = 0\nc v = -s*(sin(pi*xc)**2 + 0.5d0)\nc v = s*sin(pi*xc)\n\nc r = sqrt((x-0.5d0)**2 + (y-0.5d0)**2)\n\nc # Rigid body rotation\nc psi = r**2\nc u(1) = 2*(yc-0.5)\nc u(2) = -2*(xc-0.5)\n \nc # Filament formation (negative for clockwise rotation)\nc psi = (4.d0/3.d0)*r**3\n\n else\n write(6,'(A,A)') 'clawpack46_setaux : ',\n & 'No valid example provided'\n stop\n endif\n\n uderivs(1) = u1x\n uderivs(2) = u1y\n uderivs(3) = u2x\n uderivs(4) = u2y\n\n end\n\n\n subroutine swirl_basis_complete(x,y, t, tinv,tderivs, flag)\n implicit none\n \n double precision x,y \n integer flag\n double precision t(3,2), tinv(3,2), tderivs(3,2,2)\n\n double precision pi, pi2\n common /compi/ pi, pi2\n\n double precision alpha, beta\n common /swirl_comm/ alpha, beta\n\n double precision pi4\n double precision swirl_dot\n\n integer k, kk, i\n logical compute_covariant, compute_contravariant\n logical compute_derivatives, b(32)\n\n if (flag > 7) then\n write(6,*) 'psi.f : flag > 7'\n stop\n endif\n\nc # flag = 0 NA\nc # flag = 1 Covariant basis only\nc # flag = 2 NA\nc # flag = 3 Covariant + contravariant basis\nc # flag = 4 Derivatives only\nc # flag = 5 Derivatives + covariant basis\nc # flag = 6 NA\nc # flag = 7 Covariant + contravariant + derivatives\n\n\n do i = 1,bit_size(flag)\n b(i) = btest(flag,i-1) \n enddo\n\n compute_covariant = b(1) .or. b(2)\n compute_contravariant = b(2)\n compute_derivatives = b(3)\n\n pi4 = pi2*pi2\n\n if (compute_covariant) then\n do k = 1,3\n t(k,1) = 0\n t(k,2) = 0\n enddo\n t(1,1) = 1\n t(2,2) = 1\n endif\n\n if (compute_contravariant) then\n do k = 1,3\n tinv(k,1) = 0\n tinv(k,2) = 0\n end do\n tinv(1,1) = 1\n tinv(2,2) = 1\n endif\n\n if (compute_derivatives) then\n do k = 1,3\n tderivs(k,1,1) = 0\n\nc # d(t1)/dy = d(g*fx + gx*f)/dy \n tderivs(k,1,2) = 0\n\nc # d(t2)/dx = d(g*fy + gy*f)/dx \n tderivs(k,2,1) = 0\n\nc # d(t2)/dy = d(g*fy + gy*f)/dy \n tderivs(k,2,2) = 0\n enddo\n endif\n\n end\n\n subroutine swirl_transform_coordinates(a,b,x,y,mapping)\n implicit none\n\n double precision a,b, x,y\n integer mapping\n double precision l0(4), l1(4), l2(4)\n\n data l0 /1., 0., 0., 1./\n data l1 /1., 0., 1., 1./\n data l2 /1., -1., 1., 0./\n\nc # This compute (x,y) from a1*t1 + a2*t2, where\nc # t1, t2 are the columns of the matrix L.\n\n x = a\n y = b\n\n \nc if (mapping .eq. 0) then\nc x = a\nc y = b\nc elseif (mapping .eq. 1) then\nc x = a*l1(1) + b*l1(2)\nc y = a*l1(3) + b*l1(4)\nc elseif (mapping .eq. 2) then\nc x = a*l2(1) + b*l2(2)\nc y = a*l2(3) + b*l2(4)\nc endif\n\n end\n\n\n\n\n\n", "meta": {"hexsha": "e6a25c724f4fd24c4185124e7869baeb787b1245", "size": 6461, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "applications/clawpack/transport/2d/sonic/psi.f", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2017-09-26T13:39:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:56:23.000Z", "max_issues_repo_path": "applications/clawpack/transport/2d/sonic/psi.f", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 75, "max_issues_repo_issues_event_min_datetime": "2017-08-02T19:56:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T12:36:32.000Z", "max_forks_repo_path": "applications/clawpack/transport/2d/sonic/psi.f", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-02-21T00:10:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T19:08:36.000Z", "avg_line_length": 23.075, "max_line_length": 68, "alphanum_fraction": 0.4889336016, "num_tokens": 2172, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245870332531, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.6587683513426726}} {"text": "MODULE TENSION_MOD\r\n\r\n! The Tension Spline Module is use to fit a tension spline curve \r\n! to a water column profile of water properties at the particle location. \r\n! This module uses a modified version of Tension Spline Curve Fitting \r\n! Package (TSPACK). TSPACK (TOMS/716) was created by Robert J. Renka \r\n! (renka@cs.unt.edu, Department of Computer Science and Engineering, \r\n! University of North Texas). TSPACK is copyrighted by the Association\r\n! for Computing Machinery (ACM). With the permission of Dr. Renka and ACM, \r\n! TSPACK was modified by Zachary Schlag for use in LTRANS by removing \r\n! unused code and call variables and updating it to Fortran 90. If you \r\n! would like to use LTRANS with the modified TSPACK software, please read \r\n! and respect the ACM Software Copyright and License Agreement found at:\r\n! http://www.acm.org/publications/policies/softwarecrnotice. \r\n\r\n IMPLICIT NONE\r\n PUBLIC\r\n SAVE\r\n\r\nCONTAINS\r\n\r\n! **************************************************************\r\n! * TSPACK * \r\n! **************************************************************\r\n! \r\n! Created by: Robert J. Renka \r\n! Date created on: 05/27/91\r\n! Modified by: Zachary Schlag\r\n! Date modified on: 09/03/08 \r\n! Copyright: Association for Computing Machinery \r\n\r\n\r\n! TSPACK: Tension Spline Curve Fitting Package\r\n!\r\n! Robert J. Renka\r\n! 05/27/91\r\n!\r\n! I. INTRODUCTION\r\n!\r\n! The primary purpose of TSPACK is to construct a smooth\r\n! function which interpolates a discrete set of data points.\r\n! The function may be required to have either one or two con-\r\n! tinuous derivatives, and, in the C-2 case, several options\r\n! are provided for selecting end conditions. If the accuracy\r\n! of the data does not warrant interpolation, a smoothing func-\r\n! tion (which does not pass through the data points) may be\r\n! constructed instead. The fitting method is designed to avoid\r\n! extraneous inflection points (associated with rapidly varying\r\n! data values) and preserve local shape properties of the data\r\n! (monotonicity and convexity), or to satisfy the more general\r\n! constraints of bounds on function values or first derivatives.\r\n! The package also provides a parametric representation for con-\r\n! structing general planar curves and space curves.\r\n!\r\n! The fitting function h(x) (or each component h(t) in the\r\n! case of a parametric curve) is defined locally, on each\r\n! interval associated with a pair of adjacent abscissae (knots),\r\n! by its values and first derivatives at the endpoints of the\r\n! interval, along with a nonnegative tension factor SIGMA\r\n! associated with the interval (h is a Hermite interpolatory\r\n! tension spline). With SIGMA = 0, h is the cubic function\r\n! defined by the endpoint values and derivatives, and, as SIGMA\r\n! increases, h approaches the linear interpolant of the endpoint\r\n! values. Since the linear interpolant preserves positivity,\r\n! monotonicity, and convexity of the data, h can be forced to\r\n! preserve these properties by choosing SIGMA sufficiently\r\n! large. Also, since SIGMA varies with intervals, no more\r\n! tension than necessary is used in each interval, resulting in\r\n! a better fit and greater efficiency than is achieved with a\r\n! single constant tension factor.\r\n!\r\n!\r\n! II. USAGE\r\n!\r\n!\r\n! TSPACK must be linked to a driver program which re-\r\n! serves storage, reads a data set, and calls the appropriate\r\n! procedures selected from those described below in section\r\n! III.B. Header comments in the software prodecures provide\r\n! details regarding the specification of input parameters and\r\n! the work space requirements. It is recommended that curves\r\n! be plotted in order to assess their appropriateness for the\r\n! application. This requires a user-supplied graphics package.\r\n!\r\n!\r\n! III. SOFTWARE\r\n!\r\n! A) Code\r\n!\r\n! The code was originally written in 1977 ANSI Standard \r\n! Fortran. Variable and array names conform to the following\r\n! default typing convention: I-N for type INTEGER and A-H or \r\n! O-Z for type REAL. There are no conventions used for LOGICAL \r\n! or DOUBLE PRECISION variables. There are many procedures. \r\n! Each consists of the following sections:\r\n!\r\n! 1) the procedure name and parameter list with spaces sepa-\r\n! rating the parameters into one to three subsets:\r\n! input parameters, I/O parameters, and output parame-\r\n! ters (in that order);\r\n! 2) type statements in which all parameters are typed\r\n! and arrays are dimensioned;\r\n! 3) a heading with the name of the package, identifica-\r\n! tion of the author, and date of the author's most\r\n! recent modification to the procedure;\r\n! 4) a description of the procedure's purpose and other rel-\r\n! evant information for the user;\r\n! 5) input parameter descriptions and output parameter\r\n! descriptions in the same order as the parameter\r\n! list;\r\n! 6) a list of other procedures required (called either\r\n! directly or indirectly);\r\n! 7) a list of intrinsic functions called, if any; and\r\n! 8) the code, including comments.\r\n!\r\n! Note that it is assumed that floating point underflow\r\n! results in assignment of the value zero. If not the default,\r\n! this may be specified as either a compiler option or an\r\n! operating system option. Also, overflow is avoided by re-\r\n! stricting arguments to the exponential function EXP to have\r\n! value at most SBIG=85. SBIG, which appears in DATA statements\r\n! in the evaluation functions, HVAL, and HPVAL, must be decreased \r\n! if it is necessary to accomodate a floating point number system \r\n! with fewer than 8 bits in the exponent. No other system \r\n! dependencies are present in the code.\r\n!\r\n! The procedure that solves nonlinear equations, SIGS, \r\n! includes diagnostic print capability which allows the iteration \r\n! to be traced. This can be enabled by altering logical unit \r\n! number LUN in a DATA statement in the relevant procedure.\r\n!\r\n! B) Procedure Descriptions\r\n!\r\n! The software procedures are divided into three categories,\r\n! referred to as level 1, level 2, and level 3, corresponding to\r\n! the hierarchy of calling sequences: level 1 procedures call\r\n! level 2 procedures which call level 3 procedures. For most\r\n! applications, the driver need only call two level 1 prodedures\r\n! -- one from each of groups (a) and (b). However, additional\r\n! control over various options can be obtained by directly\r\n! calling level 2 procedures. Also, additional fitting methods,\r\n! such as parametric smoothing, can be obtained by calling\r\n! level 2 procedures. Note that, in the case of smoothing or C-2\r\n! interpolation with automatically selected tension, the use\r\n! of level 2 procedures requires that an iteration be placed\r\n! around the computation of knot derivatives and tension factors.\r\n!\r\n! 1) Level 1 procedures\r\n!\r\n! a) The following procedure returns knots (in the parametric\r\n! case), knot derivatives, tension factors, and, in the\r\n! case of smoothing, knot function values, which define\r\n! the fitting function (or functions in the parametric\r\n! case).\r\n!\r\n! TSPSI Subroutine which constructs a shape-preserving or\r\n! unconstrained interpolatory function.\r\n!\r\n! 2) Level 2 procedures\r\n!\r\n! These are divided into three groups.\r\n!\r\n! a) The following procedures are called by the level 1, group (a)\r\n! procedures to obtain knot derivatives (and values in the case\r\n! of SMCRV).\r\n!\r\n! YPC1 Subroutine which employs a monotonicity-constrained\r\n! quadratic interpolation method to compute locally\r\n! defined derivative estimates, resulting in a C-1\r\n! fit.\r\n!\r\n! b) The following procedures are called by the level 1, group (a)\r\n! procedures to obtain tension factors associated with knot\r\n! intervals.\r\n!\r\n! SIGS Subroutine which, given a sequence of abscissae,\r\n! function values, and first derivative values,\r\n! determines the set of minimum tension factors for\r\n! which the Hermite interpolatory tension spline\r\n! preserves local shape properties (monotonicity\r\n! and convexity) of the data. SIGS is called by\r\n! TSPSI.\r\n!\r\n! c) The following functions are called by the level 1, group\r\n! (b) procedures to obtain values and derivatives. These pro-\r\n! vide a more convenient alternative to the level 1 routines\r\n! when a single value is needed.\r\n!\r\n! HVAL Function which evaluates a Hermite interpolatory ten-\r\n! sion spline at a specified point.\r\n!\r\n! HPVAL Function which evaluates the first derivative of a\r\n! Hermite interpolatory tension spline at a specified\r\n! point.\r\n!\r\n!\r\n! 3) Level 3 procedures\r\n!\r\n! a) The following procedures are of general utility.\r\n!\r\n!\r\n! INTRVL Function which, given an increasing sequence of ab-\r\n! scissae, returns the index of an interval containing\r\n! a specified point. INTRVL is called by the evalua-\r\n! tion functions HVAL, and HPVAL.\r\n!\r\n! SNHCSH Subroutine called by several procedures to compute\r\n! accurate approximations to the modified hyperbolic\r\n! functions which form a basis for exponential ten-\r\n! sion splines.\r\n!\r\n! STORE Function used by SIGS in computing the machine precision. \r\n! STORE forces a value to be stored in main memory so \r\n! that the precision of floating point numbers in memory \r\n! locations rather than registers is computed.\r\n!\r\n!\r\n! IV. REFERENCE\r\n!\r\n!\r\n! For the theoretical background, consult the following:\r\n!\r\n! RENKA, R. J. Interpolatory tension splines with automatic\r\n! selection of tension factors. SIAM J. Sci. Stat. Comput. 8\r\n! (1987), pp. 393-415.\r\n!\r\n\r\n\r\n! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n! ~~~~~~~~~~~~~~~~ TSPACK ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n SUBROUTINE TSPSI (N,X,Y, YP, SIGMA,IER,SigErr)\r\n INTEGER N, IER, SigErr\r\n DOUBLE PRECISION X(N), Y(N), YP(N), SIGMA(N)\r\n!***********************************************************\r\n! From TSPACK\r\n! Robert J. Renka\r\n! Dept. of Computer Science\r\n! Univ. of North Texas\r\n! renka@cs.unt.edu\r\n! 07/08/92\r\n! This subroutine computes a set of parameter values which\r\n! define a Hermite interpolatory tension spline H(x). The\r\n! parameters consist of knot derivative values YP computed\r\n! by Subroutine YPC1, and tension factors SIGMA computed by \r\n! Subroutine SIGS. Alternative methods for computing SIGMA\r\n! are provided by Subroutine TSPBI and Functions SIG0, SIG1,\r\n! and SIG2.\r\n! Refer to Subroutine TSPSS for a means of computing\r\n! parameters which define a smoothing curve rather than an\r\n! interpolatory curve.\r\n! The tension spline may be evaluated by Subroutine TSVAL1\r\n! or Functions HVAL (values), HPVAL (first derivatives),\r\n! HPPVAL (second derivatives), and TSINTL (integrals).\r\n! On input:\r\n! N = Number of data points. N .GE. 2 and N .GE. 3 if\r\n! PER = TRUE.\r\n! X = Array of length N containing a strictly in-\r\n! creasing sequence of abscissae: X(I) < X(I+1)\r\n! for I = 1,...,N-1.\r\n! Y = Array of length N containing data values asso-\r\n! ciated with the abscissae. H(X(I)) = Y(I) for\r\n! I = 1,...,N.\r\n! YP = Array of length N containing first derivatives\r\n! of H at the abscissae. Refer to Subroutine YPC1\r\n! On output:\r\n! YP = Array containing derivatives of H at the\r\n! abscissae. YP is not altered if -4 < IER < 0,\r\n! and YP is only partially defined if IER = -4.\r\n! SIGMA = Array containing tension factors. SIGMA(I)\r\n! is associated with interval (X(I),X(I+1))\r\n! for I = 1,...,N-1. SIGMA is not altered if\r\n! -4 < IER < 0 (unless IENDC is invalid), and\r\n! SIGMA is constant (not optimal) if IER = -4\r\n! or IENDC (if used) is invalid.\r\n! IER = Error indicator or iteration count:\r\n! IER = IC .GE. 0 if no errors were encountered\r\n! and IC calls to SIGS and IC+1 calls\r\n! to YPC1, YPC1P, YPC2 or YPC2P were\r\n! employed. (IC = 0 if NCD = 1).\r\n! IER = -1 if N, NCD, or IENDC is outside its\r\n! valid range.\r\n! IER = -2 if LWK is too small.\r\n! IER = -3 if UNIFRM = TRUE and SIGMA(1) is out-\r\n! side its valid range.\r\n! IER = -4 if the abscissae X are not strictly\r\n! increasing.\r\n! Procedures required by TSPSI: SIGS, STORE, YPC1\r\n! Intrinsic functions called by TSPSI: ABS, MAX\r\n!***********************************************************\r\n!\r\n INTEGER IERR\r\n\r\n IER = 0\r\n\r\n IF (N .LT. 2) THEN\r\n ! Invalid input parameter N\r\n IER = -1\r\n ELSE\r\n\r\n CALL YPC1 (N,X,Y,YP,IERR)\r\n\r\n IF (IERR .NE. 0) THEN\r\n !Abscissae are not strictly increasing.\r\n IER = -4\r\n ELSE\r\n CALL SIGS (N,X,Y,YP,SIGMA,IERR,SigErr)\r\n ENDIF\r\n\r\n ENDIF\r\n\r\n END SUBROUTINE\r\n\r\n\r\n SUBROUTINE SIGS (N,X,Y,YP, SIGMA,IER,SigErr)\r\n INTEGER N, IER,SigErr\r\n DOUBLE PRECISION X(N), Y(N), YP(N),SIGMA(N)\r\n!***********************************************************\r\n! From TSPACK\r\n! Robert J. Renka\r\n! Dept. of Computer Science\r\n! Univ. of North Texas\r\n! renka@cs.unt.edu\r\n! 11/17/96\r\n! Given a set of abscissae X with associated data values Y\r\n! and derivatives YP, this subroutine determines the small-\r\n! est (nonnegative) tension factors SIGMA such that the Her-\r\n! mite interpolatory tension spline H(x) preserves local\r\n! shape properties of the data. In an interval (X1,X2) with\r\n! data values Y1,Y2 and derivatives YP1,YP2, the properties\r\n! of the data are\r\n! Monotonicity: S, YP1, and YP2 are nonnegative or\r\n! nonpositive,\r\n! and\r\n! Convexity: YP1 .LE. S .LE. YP2 or YP1 .GE. S\r\n! .GE. YP2,\r\n! where S = (Y2-Y1)/(X2-X1). The corresponding properties\r\n! of H are constant sign of the first and second deriva-\r\n! tives, respectively. Note that, unless YP1 = S = YP2, in-\r\n! finite tension is required (and H is linear on the inter-\r\n! val) if S = 0 in the case of monotonicity, or if YP1 = S\r\n! or YP2 = S in the case of convexity.\r\n! SIGS may be used in conjunction with Subroutine YPC2\r\n! (or YPC2P) in order to produce a C-2 interpolant which\r\n! preserves the shape properties of the data. This is\r\n! achieved by calling YPC2 with SIGMA initialized to the\r\n! zero vector, and then alternating calls to SIGS with\r\n! calls to YPC2 until the change in SIGMA is small (refer to\r\n! the parameter descriptions for SIGMA, DSMAX and IER), or\r\n! the maximum relative change in YP is bounded by a toler-\r\n! ance (a reasonable value is .01). A similar procedure may\r\n! be used to produce a C-2 shape-preserving smoothing curve\r\n! (Subroutine SMCRV).\r\n! Refer to Subroutine SIGBI for a means of selecting mini-\r\n! mum tension factors to satisfy more general constraints.\r\n! On input:\r\n! N = Number of data points. N .GE. 2.\r\n! X = Array of length N containing a strictly in-\r\n! creasing sequence of abscissae: X(I) < X(I+1)\r\n! for I = 1,...,N-1.\r\n! Y = Array of length N containing data values (or\r\n! function values computed by SMCRV) associated\r\n! with the abscissae. H(X(I)) = Y(I) for I =\r\n! 1,...,N.\r\n! YP = Array of length N containing first derivatives\r\n! of H at the abscissae. Refer to Subroutines\r\n! YPC1, YPC1P, YPC2, YPC2P, and SMCRV.\r\n! The above parameters are not altered by this routine.\r\n! On output:\r\n! SIGMA = Array containing tension factors for which\r\n! H(x) preserves the properties of the data,\r\n! with the restriction that SIGMA(I) .LE. 85\r\n! for all I (unless the input value is larger).\r\n! The factors are as small as possible (within\r\n! the tolerance), but not less than their\r\n! input values. If infinite tension is re-\r\n! quired in interval (X(I),X(I+1)), then\r\n! SIGMA(I) = 85 (and H is an approximation to\r\n! the linear interpolant on the interval),\r\n! and if neither property is satisfied by the\r\n! data, then SIGMA(I) = 0 (unless the input\r\n! value is positive), and thus H is cubic in\r\n! the interval.\r\n! IER = Error indicator and information flag:\r\n! IER = I if no errors were encountered and I\r\n! components of SIGMA were altered from\r\n! their input values for 0 .LE. I .LE.\r\n! N-1.\r\n! IER = -1 if N < 2. SIGMA is not altered in\r\n! this case.\r\n! IER = -I if X(I) .LE. X(I-1) for some I in the\r\n! range 2,...,N. SIGMA(J-1) is unal-\r\n! tered for J = I,...,N in this case.\r\n! Procedures required by SIGS: SNHCSH, STORE\r\n! Intrinsic functions called by SIGS: ABS, EXP, MAX, MIN,\r\n! SIGN, SQRT\r\n!\r\n!***********************************************************\r\n!\r\n INTEGER I, ICNT, IP1, LUN, NIT, NM1\r\n DOUBLE PRECISION A, C1, C2, COSHM, COSHMM, D0, D1, &\r\n D1D2, D1PD2, D2, DMAX, DSIG, DSM, DX, &\r\n E, EMS, EMS2, F, F0, FMAX, FNEG, FP, &\r\n FTOL, RTOL, S, S1, S2, SBIG, SCM, &\r\n SGN, SIG, SIGIN, SINHM, SSINH, SSM, &\r\n STOL, T, T0, T1, T2, TM, TP1\r\n !DOUBLE PRECISION STORE\r\n DOUBLE PRECISION TOL, DSMAX !Added by Zachary Schlag\r\n LOGICAL CONT,FLAG !Added by Zachary Schlag\r\n\r\n! Initialize flag to .FALSE.\r\n\r\n FLAG = .FALSE.\r\n\r\n\r\n DATA SBIG/85.D0/, LUN/-1/\r\n NM1 = N - 1\r\n IF (NM1 .LT. 1) THEN\r\n ! N < 2.\r\n DSMAX = 0.D0\r\n IER = -1\r\n ELSE\r\n\r\n! Initialize the tolerance and sigma values\r\n\r\n TOL = 0.D0\r\n DO I = 1,NM1\r\n SIGMA(I) = 0.D0\r\n ENDDO\r\n\r\n! Compute an absolute tolerance FTOL = abs(TOL) and a\r\n! relative tolerance RTOL = 100*MACHEPS.\r\n\r\n FTOL = ABS(TOL)\r\n RTOL = 1.D0\r\n DO\r\n RTOL = RTOL/2.D0\r\n IF (STORE(RTOL+1.D0) .LE. 1.D0) EXIT\r\n ENDDO\r\n RTOL = RTOL*200.D0\r\n\r\n! Initialize change counter ICNT and maximum change DSM for\r\n! loop on intervals.\r\n\r\n ICNT = 0\r\n DSM = 0.D0\r\n DO I = 1,NM1\r\n IF (LUN .GE. 0) WRITE (LUN,100) I\r\n 100 FORMAT (//1X,'SIGS -- INTERVAL',I4)\r\n IP1 = I + 1\r\n DX = X(IP1) - X(I)\r\n IF (DX .LE. 0.D0) THEN\r\n ! X(I+1) .LE. X(I).\r\n DSMAX = DSM\r\n IER = -IP1\r\n EXIT\r\n ENDIF\r\n SIGIN = SIGMA(I)\r\n IF (SIGIN .GE. SBIG) CYCLE\r\n\r\n! Compute first and second differences.\r\n\r\n S1 = YP(I)\r\n S2 = YP(IP1)\r\n S = (Y(IP1)-Y(I))/DX\r\n D1 = S - S1\r\n D2 = S2 - S\r\n D1D2 = D1*D2\r\n\r\n! Test for infinite tension required to satisfy either\r\n! property.\r\n\r\n SIG = SBIG\r\n IF ((D1D2 .EQ. 0.D0 .AND. S1 .NE. S2) .OR. &\r\n (S .EQ. 0.D0 .AND. S1*S2 .GT. 0.D0)) THEN\r\n SIG = MIN(SIG,SBIG)\r\n IF (SIG .GT. SIGIN) THEN\r\n SIGMA(I) = SIG\r\n ICNT = ICNT + 1\r\n DSIG = SIG-SIGIN\r\n IF (SIGIN .GT. 0.D0) DSIG = DSIG/SIGIN\r\n DSM = MAX(DSM,DSIG)\r\n ENDIF\r\n CYCLE\r\n ENDIF\r\n\r\n! Test for SIGMA = 0 sufficient. The data satisfies convex-\r\n! ity iff D1D2 .GE. 0, and D1D2 = 0 implies S1 = S = S2.\r\n\r\n SIG = 0.D0\r\n IF (D1D2 .GE. 0.D0) THEN\r\n\r\n IF (D1D2 .EQ. 0.D0) THEN\r\n SIG = MIN(SIG,SBIG)\r\n IF (SIG .GT. SIGIN) THEN\r\n SIGMA(I) = SIG\r\n ICNT = ICNT + 1\r\n DSIG = SIG-SIGIN\r\n IF (SIGIN .GT. 0.D0) DSIG = DSIG/SIGIN\r\n DSM = MAX(DSM,DSIG)\r\n ENDIF\r\n CYCLE\r\n ENDIF\r\n\r\n T = MAX(D1/D2,D2/D1)\r\n\r\n IF (T .LE. 2.D0) THEN\r\n SIG = MIN(SIG,SBIG)\r\n IF (SIG .GT. SIGIN) THEN\r\n SIGMA(I) = SIG\r\n ICNT = ICNT + 1\r\n DSIG = SIG-SIGIN\r\n IF (SIGIN .GT. 0.D0) DSIG = DSIG/SIGIN\r\n DSM = MAX(DSM,DSIG)\r\n ENDIF\r\n CYCLE\r\n ENDIF\r\n\r\n TP1 = T + 1.D0\r\n\r\n! Convexity: Find a zero of F(SIG) = SIG*COSHM(SIG)/\r\n! SINHM(SIG) - TP1.\r\n!\r\n! F(0) = 2-T < 0, F(TP1) .GE. 0, the derivative of F\r\n! vanishes at SIG = 0, and the second derivative of F is\r\n! .2 at SIG = 0. A quadratic approximation is used to\r\n! obtain a starting point for the Newton method.\r\n\r\n SIG = SQRT(10.D0*T-20.D0)\r\n NIT = 0\r\n\r\n! Top of loop:\r\n\r\n DO\r\n IF (SIG .LE. .5D0) THEN\r\n CALL SNHCSH (SIG, SINHM,COSHM,COSHMM)\r\n T1 = COSHM/SINHM\r\n FP = T1 + SIG*(SIG/SINHM - T1*T1 + 1.D0)\r\n ELSE\r\n\r\n! Scale SINHM and COSHM by 2*EXP(-SIG) in order to avoid\r\n! overflow with large SIG.\r\n\r\n EMS = EXP(-SIG)\r\n SSM = 1.D0 - EMS*(EMS+SIG+SIG)\r\n T1 = (1.D0-EMS)*(1.D0-EMS)/SSM\r\n FP = T1 + SIG*(2.D0*SIG*EMS/SSM - T1*T1 + 1.D0)\r\n ENDIF\r\n\r\n F = SIG*T1 - TP1\r\n IF (LUN .GE. 0) WRITE (LUN,110) SIG, F, FP\r\n 110 FORMAT (5X,'CONVEXITY -- SIG = ',D15.8, &\r\n ', F(SIG) = ',D15.8/1X,35X,'FP(SIG) = ', &\r\n D15.8)\r\n NIT = NIT + 1\r\n !WRITE (*,*) NIT\r\n IF (NIT.GT.10000) THEN\r\n SigErr=SigErr+1\r\n RETURN\r\n END IF\r\n\r\n! Test for convergence.\r\n\r\n FLAG = .FALSE.\r\n IF (FP .LE. 0.D0) THEN\r\n FLAG = .TRUE.\r\n EXIT\r\n ENDIF\r\n DSIG = -F/FP\r\n IF (ABS(DSIG) .LE. RTOL*SIG .OR. (F .GE. 0.D0 &\r\n .AND. F .LE. FTOL) .OR. ABS(F) .LE. RTOL) &\r\n THEN\r\n FLAG = .TRUE.\r\n EXIT\r\n ENDIF\r\n\r\n! Update SIG.\r\n\r\n SIG = SIG + DSIG\r\n ENDDO\r\n ENDIF\r\n\r\n IF(FLAG)THEN\r\n FLAG = .FALSE.\r\n SIG = MIN(SIG,SBIG)\r\n IF (SIG .GT. SIGIN) THEN\r\n SIGMA(I) = SIG\r\n ICNT = ICNT + 1\r\n DSIG = SIG-SIGIN\r\n IF (SIGIN .GT. 0.D0) DSIG = DSIG/SIGIN\r\n DSM = MAX(DSM,DSIG)\r\n ENDIF\r\n CYCLE\r\n ENDIF\r\n\r\n\r\n! Convexity cannot be satisfied. Monotonicity can be satis-\r\n! fied iff S1*S .GE. 0 and S2*S .GE. 0 since S .NE. 0.\r\n\r\n IF (S1*S .LT. 0.D0 .OR. S2*S .LT. 0.D0) THEN\r\n SIG = MIN(SIG,SBIG)\r\n IF (SIG .GT. SIGIN) THEN\r\n SIGMA(I) = SIG\r\n ICNT = ICNT + 1\r\n DSIG = SIG-SIGIN\r\n IF (SIGIN .GT. 0.D0) DSIG = DSIG/SIGIN\r\n DSM = MAX(DSM,DSIG)\r\n ENDIF\r\n CYCLE\r\n ENDIF\r\n T0 = 3.D0*S - S1 - S2\r\n D0 = T0*T0 - S1*S2\r\n\r\n! SIGMA = 0 is sufficient for monotonicity iff S*T0 .GE. 0\r\n! or D0 .LE. 0.\r\n\r\n IF (D0 .LE. 0.D0 .OR. S*T0 .GE. 0.D0) THEN\r\n SIG = MIN(SIG,SBIG)\r\n IF (SIG .GT. SIGIN) THEN\r\n SIGMA(I) = SIG\r\n ICNT = ICNT + 1\r\n DSIG = SIG-SIGIN\r\n IF (SIGIN .GT. 0.D0) DSIG = DSIG/SIGIN\r\n DSM = MAX(DSM,DSIG)\r\n ENDIF\r\n CYCLE\r\n ENDIF\r\n\r\n! Monotonicity: find a zero of F(SIG) = SIGN(S)*HP(R),\r\n! where HPP(R) = 0 and HP, HPP denote derivatives of H.\r\n! F has a unique zero, F(0) < 0, and F approaches abs(S)\r\n! as SIG increases.\r\n!\r\n! Initialize parameters for the secant method. The method\r\n! uses three points: (SG0,F0), (SIG,F), and\r\n! (SNEG,FNEG), where SG0 and SNEG are defined implicitly\r\n! by DSIG = SIG - SG0 and DMAX = SIG - SNEG.\r\n\r\n SGN = SIGN(1.D0,S)\r\n SIG = SBIG\r\n FMAX = SGN*(SIG*S-S1-S2)/(SIG-2.D0)\r\n IF (FMAX .LE. 0.D0) THEN\r\n SIG = MIN(SIG,SBIG)\r\n IF (SIG .GT. SIGIN) THEN\r\n SIGMA(I) = SIG\r\n ICNT = ICNT + 1\r\n DSIG = SIG-SIGIN\r\n IF (SIGIN .GT. 0.D0) DSIG = DSIG/SIGIN\r\n DSM = MAX(DSM,DSIG)\r\n ENDIF\r\n CYCLE\r\n ENDIF\r\n STOL = RTOL*SIG\r\n F = FMAX\r\n F0 = SGN*D0/(3.D0*(D1-D2))\r\n FNEG = F0\r\n DSIG = SIG\r\n DMAX = SIG\r\n D1PD2 = D1 + D2\r\n NIT = 0\r\n\r\n! Top of loop: compute the change in SIG by linear\r\n! interpolation.\r\n\r\n DO\r\n DSIG = -F*DSIG/(F-F0)\r\n IF (LUN .GE. 0) WRITE (LUN,120) DSIG\r\n 120 FORMAT (5X,'MONOTONICITY -- DSIG = ',D15.8)\r\n IF ( ABS(DSIG) .GT. ABS(DMAX) .OR. &\r\n DSIG*DMAX .GT. 0. ) THEN\r\n DSIG = DMAX\r\n F0 = FNEG\r\n CYCLE\r\n ENDIF\r\n\r\n! Restrict the step-size such that abs(DSIG) .GE. STOL/2.\r\n! Note that DSIG and DMAX have opposite signs.\r\n\r\n IF (ABS(DSIG) .LT. STOL/2.D0) &\r\n DSIG = -SIGN(STOL/2.D0,DMAX)\r\n\r\n! Update SIG, F0, and F.\r\n\r\n SIG = SIG + DSIG\r\n F0 = F\r\n IF (SIG .LE. .5D0) THEN\r\n\r\n! Use approximations to the hyperbolic functions designed\r\n! to avoid cancellation error with small SIG.\r\n\r\n CALL SNHCSH (SIG, SINHM,COSHM,COSHMM)\r\n C1 = SIG*COSHM*D2 - SINHM*D1PD2\r\n C2 = SIG*(SINHM+SIG)*D2 - COSHM*D1PD2\r\n A = C2 - C1\r\n E = SIG*SINHM - COSHMM - COSHMM\r\n ELSE\r\n\r\n! Scale SINHM and COSHM by 2*EXP(-SIG) in order to avoid\r\n! overflow with large SIG.\r\n\r\n EMS = EXP(-SIG)\r\n EMS2 = EMS + EMS\r\n TM = 1.D0 - EMS\r\n SSINH = TM*(1.D0+EMS)\r\n SSM = SSINH - SIG*EMS2\r\n SCM = TM*TM\r\n C1 = SIG*SCM*D2 - SSM*D1PD2\r\n C2 = SIG*SSINH*D2 - SCM*D1PD2\r\n\r\n! R is in (0,1) and well-defined iff HPP(X1)*HPP(X2) < 0.\r\n\r\n F = FMAX\r\n CONT = .TRUE.\r\n IF (C1*(SIG*SCM*D1 - SSM*D1PD2) .GE. 0.D0) &\r\n CONT = .FALSE.\r\n IF(CONT) A = EMS2*(SIG*TM*D2 + (TM-SIG)*D1PD2)\r\n IF (A*(C2+C1) .LT. 0.D0) CONT = .FALSE.\r\n IF(CONT) E = SIG*SSINH - SCM - SCM\r\n ENDIF\r\n\r\n IF(CONT) F = (SGN*(E*S2-C2) + SQRT(A*(C2+C1)))/E\r\n\r\n! Update number of iterations NIT.\r\n\r\n NIT = NIT + 1\r\n IF (LUN .GE. 0) WRITE (LUN,130) NIT, SIG, F\r\n 130 FORMAT (1X,10X,I2,' -- SIG = ',D15.8, &\r\n ', F = ',D15.8)\r\n\r\n! Test for convergence.\r\n\r\n STOL = RTOL*SIG\r\n IF ( ABS(DMAX) .LE. STOL .OR. (F .GE. 0.D0 .AND. &\r\n F .LE. FTOL) .OR. ABS(F) .LE. RTOL ) THEN\r\n EXIT\r\n ENDIF\r\n DMAX = DMAX + DSIG\r\n IF ( F0*F .GT. 0.D0 .AND. ABS(F) .GE. ABS(F0) )THEN\r\n DSIG = DMAX\r\n F0 = FNEG\r\n CYCLE\r\n ENDIF\r\n IF (F0*F .LE. 0.D0) THEN\r\n\r\n! F and F0 have opposite signs. Update (SNEG,FNEG) to\r\n! (SG0,F0) so that F and FNEG always have opposite\r\n! signs. If SIG is closer to SNEG than SG0 and abs(F) <\r\n! abs(FNEG), then swap (SNEG,FNEG) with (SG0,F0).\r\n\r\n T1 = DMAX\r\n T2 = FNEG\r\n DMAX = DSIG\r\n FNEG = F0\r\n IF ( ABS(DSIG) .GT. ABS(T1) .AND. &\r\n ABS(F) .LT. ABS(T2) ) THEN\r\n\r\n DSIG = T1\r\n F0 = T2\r\n ENDIF\r\n ENDIF\r\n ENDDO\r\n\r\n! Bottom of loop: F0*F > 0 and the new estimate would\r\n! be outside of the bracketing interval of length\r\n! abs(DMAX). Reset (SG0,F0) to (SNEG,FNEG).\r\n\r\n\r\n! Update SIGMA(I), ICNT, and DSM if necessary.\r\n\r\n SIG = MIN(SIG,SBIG)\r\n IF (SIG .GT. SIGIN) THEN\r\n SIGMA(I) = SIG\r\n ICNT = ICNT + 1\r\n DSIG = SIG-SIGIN\r\n IF (SIGIN .GT. 0.D0) DSIG = DSIG/SIGIN\r\n DSM = MAX(DSM,DSIG)\r\n ENDIF\r\n ENDDO\r\n\r\n ENDIF\r\n\r\n END SUBROUTINE\r\n\r\n\r\n SUBROUTINE SNHCSH (X, SINHM,COSHM,COSHMM)\r\n DOUBLE PRECISION X, SINHM, COSHM, COSHMM\r\n!***********************************************************\r\n! From TSPACK\r\n! Robert J. Renka\r\n! Dept. of Computer Science\r\n! Univ. of North Texas\r\n! renka@cs.unt.edu\r\n! 11/20/96\r\n! This subroutine computes approximations to the modified\r\n! hyperbolic functions defined below with relative error\r\n! bounded by 3.4E-20 for a floating point number system with\r\n! sufficient precision.\r\n! Note that the 21-digit constants in the data statements\r\n! below may not be acceptable to all compilers.\r\n! On input:\r\n! X = Point at which the functions are to be\r\n! evaluated.\r\n! X is not altered by this routine.\r\n! On output:\r\n! SINHM = sinh(X) - X.\r\n! COSHM = cosh(X) - 1.\r\n! COSHMM = cosh(X) - 1 - X*X/2.\r\n! Procedures required by SNHCSH: None\r\n! Intrinsic functions called by SNHCSH: ABS, EXP\r\n!**********************************************************\r\n\r\n DOUBLE PRECISION AX, EXPX, F, P, P1, P2, P3, P4, Q, &\r\n Q1, Q2, Q3, Q4, XC, XS, XSD2, XSD4\r\n\r\n DATA P1/-3.51754964808151394800D5/, &\r\n P2/-1.15614435765005216044D4/, &\r\n P3/-1.63725857525983828727D2/, &\r\n P4/-7.89474443963537015605D-1/\r\n DATA Q1/-2.11052978884890840399D6/, &\r\n Q2/3.61578279834431989373D4/, &\r\n Q3/-2.77711081420602794433D2/, &\r\n Q4/1.D0/\r\n AX = ABS(X)\r\n XS = AX*AX\r\n IF (AX .LE. .5D0) THEN\r\n\r\n! Approximations for small X:\r\n\r\n XC = X*XS\r\n P = ((P4*XS+P3)*XS+P2)*XS+P1\r\n Q = ((Q4*XS+Q3)*XS+Q2)*XS+Q1\r\n SINHM = XC*(P/Q)\r\n XSD4 = .25D0*XS\r\n XSD2 = XSD4 + XSD4\r\n P = ((P4*XSD4+P3)*XSD4+P2)*XSD4+P1\r\n Q = ((Q4*XSD4+Q3)*XSD4+Q2)*XSD4+Q1\r\n F = XSD4*(P/Q)\r\n COSHMM = XSD2*F*(F+2.D0)\r\n COSHM = COSHMM + XSD2\r\n ELSE\r\n\r\n! Approximations for large X:\r\n\r\n EXPX = EXP(AX)\r\n SINHM = -(((1.D0/EXPX+AX)+AX)-EXPX)/2.D0\r\n IF (X .LT. 0.D0) SINHM = -SINHM\r\n COSHM = ((1.D0/EXPX-2.D0)+EXPX)/2.D0\r\n COSHMM = COSHM - XS/2.D0\r\n ENDIF\r\n END SUBROUTINE\r\n\r\n\r\n SUBROUTINE YPC1 (N,X,Y, YP,IER)\r\n INTEGER N, IER\r\n DOUBLE PRECISION X(N), Y(N), YP(N)\r\n!***********************************************************\r\n! From TSPACK\r\n! Robert J. Renka\r\n! Dept. of Computer Science\r\n! Univ. of North Texas\r\n! renka@cs.unt.edu\r\n! 06/10/92\r\n! This subroutine employs a three-point quadratic interpo-\r\n! lation method to compute local derivative estimates YP\r\n! associated with a set of data points. The interpolation\r\n! formula is the monotonicity-constrained parabolic method\r\n! described in the reference cited below. A Hermite int-\r\n! erpolant of the data values and derivative estimates pre-\r\n! serves monotonicity of the data. Linear interpolation is\r\n! used if N = 2. The method is invariant under a linear\r\n! scaling of the coordinates but is not additive.\r\n! On input:\r\n! N = Number of data points. N .GE. 2.\r\n! X = Array of length N containing a strictly in-\r\n! creasing sequence of abscissae: X(I) < X(I+1)\r\n! for I = 1,...,N-1.\r\n! Y = Array of length N containing data values asso-\r\n! ciated with the abscissae.\r\n! Input parameters are not altered by this routine.\r\n! On output:\r\n! YP = Array of length N containing estimated deriv-\r\n! atives at the abscissae unless IER .NE. 0.\r\n! YP is not altered if IER = 1, and is only par-\r\n! tially defined if IER > 1.\r\n! IER = Error indicator:\r\n! IER = 0 if no errors were encountered.\r\n! IER = 1 if N < 2.\r\n! IER = I if X(I) .LE. X(I-1) for some I in the\r\n! range 2,...,N.\r\n! Reference: J. M. Hyman, \"Accurate Monotonicity-preserving\r\n! Cubic Interpolation\", LA-8796-MS, Los\r\n! Alamos National Lab, Feb. 1982.\r\n! Procedures required by YPC1: None\r\n! Intrinsic functions called by YPC1: ABS, MAX, MIN, SIGN\r\n!***********************************************************\r\n\r\n INTEGER I, NM1\r\n DOUBLE PRECISION ASI, ASIM1, DX2, DXI, DXIM1, S2, SGN, &\r\n SI, SIM1, T\r\n\r\n NM1 = N - 1\r\n I = 1\r\n DXI = X(2) - X(1)\r\n IF (DXI .LE. 0.D0) THEN\r\n ! X(I+1) .LE. X(I).\r\n IER = I + 1\r\n RETURN\r\n ENDIF\r\n SI = (Y(2)-Y(1))/DXI\r\n IF (NM1 .EQ. 1) THEN\r\n\r\n! Use linear interpolation for N = 2.\r\n\r\n YP(1) = SI\r\n YP(2) = SI\r\n IER = 0\r\n RETURN\r\n ENDIF\r\n\r\n! N .GE. 3. YP(1) = S1 + DX1*(S1-S2)/(DX1+DX2) unless this\r\n! results in YP(1)*S1 .LE. 0 or abs(YP(1)) > 3*abs(S1).\r\n\r\n I = 2\r\n DX2 = X(3) - X(2)\r\n IF (DX2 .LE. 0.D0) THEN\r\n ! X(I+1) .LE. X(I).\r\n IER = I + 1\r\n RETURN\r\n ENDIF\r\n S2 = (Y(3)-Y(2))/DX2\r\n T = SI + DXI*(SI-S2)/(DXI+DX2)\r\n IF (SI .GE. 0.D0) THEN\r\n YP(1) = MIN(MAX(0.D0,T), 3.D0*SI)\r\n ELSE\r\n YP(1) = MAX(MIN(0.D0,T), 3.D0*SI)\r\n ENDIF\r\n\r\n! YP(I) = (DXIM1*SI+DXI*SIM1)/(DXIM1+DXI) subject to the\r\n! constraint that YP(I) has the sign of either SIM1 or\r\n! SI, whichever has larger magnitude, and abs(YP(I)) .LE.\r\n! 3*min(abs(SIM1),abs(SI)).\r\n\r\n DO I = 2,NM1\r\n DXIM1 = DXI\r\n DXI = X(I+1) - X(I)\r\n IF (DXI .LE. 0.D0) THEN\r\n ! X(I+1) .LE. X(I).\r\n IER = I + 1\r\n RETURN\r\n ENDIF\r\n SIM1 = SI\r\n SI = (Y(I+1)-Y(I))/DXI\r\n T = (DXIM1*SI+DXI*SIM1)/(DXIM1+DXI)\r\n ASIM1 = ABS(SIM1)\r\n ASI = ABS(SI)\r\n SGN = SIGN(1.D0,SI)\r\n IF (ASIM1 .GT. ASI) SGN = SIGN(1.D0,SIM1)\r\n IF (SGN .GT. 0.D0) THEN\r\n YP(I) = MIN(MAX(0.D0,T),3.D0*MIN(ASIM1,ASI))\r\n ELSE\r\n YP(I) = MAX(MIN(0.D0,T),-3.D0*MIN(ASIM1,ASI))\r\n ENDIF\r\n ENDDO\r\n\r\n! YP(N) = SNM1 + DXNM1*(SNM1-SNM2)/(DXNM2+DXNM1) subject to\r\n! the constraint that YP(N) has the sign of SNM1 and\r\n! abs(YP(N)) .LE. 3*abs(SNM1). Note that DXI = DXNM1 and\r\n! SI = SNM1.\r\n\r\n T = SI + DXI*(SI-SIM1)/(DXIM1+DXI)\r\n IF (SI .GE. 0.D0) THEN\r\n YP(N) = MIN(MAX(0.D0,T), 3.D0*SI)\r\n ELSE\r\n YP(N) = MAX(MIN(0.D0,T), 3.D0*SI)\r\n ENDIF\r\n IER = 0\r\n\r\n END SUBROUTINE\r\n\r\n\r\n DOUBLE PRECISION FUNCTION HVAL (T,N,X,Y,YP,SIGMA, IER)\r\n INTEGER N, IER\r\n DOUBLE PRECISION T, X(N), Y(N), YP(N), SIGMA(N)\r\n!***********************************************************\r\n! From TSPACK\r\n! Robert J. Renka\r\n! Dept. of Computer Science\r\n! Univ. of North Texas\r\n! renka@cs.unt.edu\r\n! 11/17/96\r\n! This function evaluates a Hermite interpolatory tension\r\n! spline H at a point T. Note that a large value of SIGMA\r\n! may cause underflow. The result is assumed to be zero.\r\n! Given arrays X, Y, YP, and SIGMA of length NN, if T is\r\n! known to lie in the interval (X(I),X(J)) for some I < J,\r\n! a gain in efficiency can be achieved by calling this\r\n! function with N = J+1-I (rather than NN) and the I-th\r\n! components of the arrays (rather than the first) as par-\r\n! ameters.\r\n! On input:\r\n! T = Point at which H is to be evaluated. Extrapo-\r\n! lation is performed if T < X(1) or T > X(N).\r\n! N = Number of data points. N .GE. 2.\r\n! X = Array of length N containing the abscissae.\r\n! These must be in strictly increasing order:\r\n! X(I) < X(I+1) for I = 1,...,N-1.\r\n! Y = Array of length N containing data values.\r\n! H(X(I)) = Y(I) for I = 1,...,N.\r\n! YP = Array of length N containing first deriva-\r\n! tives. HP(X(I)) = YP(I) for I = 1,...,N, where\r\n! HP denotes the derivative of H.\r\n! SIGMA = Array of length N-1 containing tension fac-\r\n! tors whose absolute values determine the\r\n! balance between cubic and linear in each\r\n! interval. SIGMA(I) is associated with int-\r\n! erval (I,I+1) for I = 1,...,N-1.\r\n! Input parameters are not altered by this function.\r\n! On output:\r\n! IER = Error indicator:\r\n! IER = 0 if no errors were encountered and\r\n! X(1) .LE. T .LE. X(N).\r\n! IER = 1 if no errors were encountered and\r\n! extrapolation was necessary.\r\n! IER = -1 if N < 2.\r\n! IER = -2 if the abscissae are not in strictly\r\n! increasing order. (This error will\r\n! not necessarily be detected.)\r\n! HVAL = Function value H(T), or zero if IER < 0.\r\n! Procedures required by HVAL: INTRVL, SNHCSH\r\n! Intrinsic functions called by HVAL: ABS, EXP\r\n!***********************************************************\r\n!\r\n INTEGER I, IP1\r\n DOUBLE PRECISION B1, B2, CM, CM2, CMM, D1, D2, DUMMY, &\r\n DX, E, E1, E2, EMS, S, S1, SB1, SB2, &\r\n SBIG, SIG, SM, SM2, TM, TP, TS, U, Y1\r\n\r\n DATA SBIG/85.D0/\r\n IF (N .LT. 2) THEN\r\n ! N is outside its valid range.\r\n HVAL = 0.D0\r\n IER = -1\r\n ELSE\r\n\r\n! Find the index of the left end of an interval containing\r\n! T. If T < X(1) or T > X(N), extrapolation is performed\r\n! using the leftmost or rightmost interval.\r\n\r\n IF (T .LT. X(1)) THEN\r\n I = 1\r\n IER = 1\r\n ELSEIF (T .GT. X(N)) THEN\r\n I = N-1\r\n IER = 1\r\n ELSE\r\n I = INTRVL (T,N,X)\r\n IER = 0\r\n ENDIF\r\n IP1 = I + 1\r\n\r\n! Compute interval width DX, local coordinates B1 and B2,\r\n! and second differences D1 and D2.\r\n\r\n DX = X(IP1) - X(I)\r\n IF (DX .LE. 0.D0) THEN\r\n ! X(I) .GE. X(I+1).\r\n HVAL = 0.D0\r\n IER = -2\r\n ELSE\r\n U = T - X(I)\r\n B2 = U/DX\r\n B1 = 1.D0 - B2\r\n Y1 = Y(I)\r\n S1 = YP(I)\r\n S = (Y(IP1)-Y1)/DX\r\n D1 = S - S1\r\n D2 = YP(IP1) - S\r\n SIG = ABS(SIGMA(I))\r\n IF (SIG .LT. 1.D-9) THEN\r\n\r\n! SIG = 0: H is the Hermite cubic interpolant.\r\n\r\n HVAL = Y1 + U*(S1 + B2*(D1 + B1*(D1-D2)))\r\n ELSEIF (SIG .LE. .5D0) THEN\r\n\r\n! 0 .LT. SIG .LE. .5: use approximations designed to avoid\r\n! cancellation error in the hyperbolic functions.\r\n\r\n SB2 = SIG*B2\r\n CALL SNHCSH (SIG, SM,CM,CMM)\r\n CALL SNHCSH (SB2, SM2,CM2,DUMMY)\r\n E = SIG*SM - CMM - CMM\r\n HVAL = Y1 + S1*U + DX*((CM*SM2-SM*CM2)*(D1+D2) + &\r\n SIG*(CM*CM2-(SM+SIG)*SM2)*D1) / (SIG*E)\r\n ELSE\r\n\r\n! SIG > .5: use negative exponentials in order to avoid\r\n! overflow. Note that EMS = EXP(-SIG). In the case of\r\n! extrapolation (negative B1 or B2), H is approximated by\r\n! a linear function if -SIG*B1 or -SIG*B2 is large.\r\n\r\n SB1 = SIG*B1\r\n SB2 = SIG - SB1\r\n IF (-SB1 .GT. SBIG .OR. -SB2 .GT. SBIG) THEN\r\n HVAL = Y1 + S*U\r\n ELSE\r\n E1 = EXP(-SB1)\r\n E2 = EXP(-SB2)\r\n EMS = E1*E2\r\n TM = 1.D0 - EMS\r\n TS = TM*TM\r\n TP = 1.D0 + EMS\r\n E = TM*(SIG*TP - TM - TM)\r\n HVAL = Y1 + S*U + DX*(TM*(TP-E1-E2)*(D1+D2) + &\r\n SIG* ((E2+EMS*(E1-2.D0)-B1*TS)*D1 + &\r\n (E1+EMS*(E2-2.D0)-B2*TS)*D2)) / (SIG*E)\r\n ENDIF\r\n ENDIF\r\n ENDIF\r\n ENDIF\r\n\r\n END FUNCTION\r\n\r\n\r\n DOUBLE PRECISION FUNCTION HPVAL (T,N,X,Y,YP,SIGMA, IER)\r\n INTEGER N, IER\r\n DOUBLE PRECISION T, X(N), Y(N), YP(N), SIGMA(N)\r\n!***********************************************************\r\n! From TSPACK\r\n! Robert J. Renka\r\n! Dept. of Computer Science\r\n! Univ. of North Texas\r\n! renka@cs.unt.edu\r\n! 11/17/96\r\n! This function evaluates the first derivative HP of a\r\n! Hermite interpolatory tension spline H at a point T.\r\n! On input:\r\n! T = Point at which HP is to be evaluated. Extrapo-\r\n! lation is performed if T < X(1) or T > X(N).\r\n! N = Number of data points. N .GE. 2.\r\n! X = Array of length N containing the abscissae.\r\n! These must be in strictly increasing order:\r\n! X(I) < X(I+1) for I = 1,...,N-1.\r\n! Y = Array of length N containing data values.\r\n! H(X(I)) = Y(I) for I = 1,...,N.\r\n! YP = Array of length N containing first deriva-\r\n! tives. HP(X(I)) = YP(I) for I = 1,...,N.\r\n! SIGMA = Array of length N-1 containing tension fac-\r\n! tors whose absolute values determine the\r\n! balance between cubic and linear in each\r\n! interval. SIGMA(I) is associated with int-\r\n! erval (I,I+1) for I = 1,...,N-1.\r\n! Input parameters are not altered by this function.\r\n! On output:\r\n! IER = Error indicator:\r\n! IER = 0 if no errors were encountered and\r\n! X(1) .LE. T .LE. X(N).\r\n! IER = 1 if no errors were encountered and\r\n! extrapolation was necessary.\r\n! IER = -1 if N < 2.\r\n! IER = -2 if the abscissae are not in strictly\r\n! increasing order. (This error will\r\n! not necessarily be detected.)\r\n! HPVAL = Derivative value HP(T), or zero if IER < 0.\r\n! Procedures required by HPVAL: INTRVL, SNHCSH\r\n! Intrinsic functions called by HPVAL: ABS, EXP\r\n!***********************************************************\r\n\r\n INTEGER I, IP1\r\n DOUBLE PRECISION B1, B2, CM, CM2, CMM, D1, D2, DUMMY, &\r\n DX, E, E1, E2, EMS, S, S1, SB1, SB2, &\r\n SBIG, SIG, SINH2, SM, SM2, TM\r\n\r\n DATA SBIG/85.D0/\r\n IF (N .LT. 2) THEN\r\n ! N is outside its valid range.\r\n HPVAL = 0.D0\r\n IER = -1\r\n ELSE\r\n\r\n! Find the index of the left end of an interval containing\r\n! T. If T < X(1) or T > X(N), extrapolation is performed\r\n! using the leftmost or rightmost interval.\r\n\r\n IF (T .LT. X(1)) THEN\r\n I = 1\r\n IER = 1\r\n ELSEIF (T .GT. X(N)) THEN\r\n I = N-1\r\n IER = 1\r\n ELSE\r\n I = INTRVL (T,N,X)\r\n IER = 0\r\n ENDIF\r\n IP1 = I + 1\r\n\r\n! Compute interval width DX, local coordinates B1 and B2,\r\n! and second differences D1 and D2.\r\n\r\n DX = X(IP1) - X(I)\r\n IF (DX .LE. 0.D0) THEN\r\n ! X(I) .GE. X(I+1).\r\n HPVAL = 0.D0\r\n IER = -2\r\n ELSE\r\n B1 = (X(IP1) - T)/DX\r\n B2 = 1.D0 - B1\r\n S1 = YP(I)\r\n S = (Y(IP1)-Y(I))/DX\r\n D1 = S - S1\r\n D2 = YP(IP1) - S\r\n SIG = ABS(SIGMA(I))\r\n IF (SIG .LT. 1.D-9) THEN\r\n\r\n! SIG = 0: H is the Hermite cubic interpolant.\r\n\r\n HPVAL = S1 + B2*(D1 + D2 - 3.D0*B1*(D2-D1))\r\n ELSEIF (SIG .LE. .5D0) THEN\r\n\r\n! 0 .LT. SIG .LE. .5: use approximations designed to avoid\r\n! cancellation error in the hyperbolic functions.\r\n\r\n SB2 = SIG*B2\r\n CALL SNHCSH (SIG, SM,CM,CMM)\r\n CALL SNHCSH (SB2, SM2,CM2,DUMMY)\r\n SINH2 = SM2 + SB2\r\n E = SIG*SM - CMM - CMM\r\n HPVAL = S1 + ((CM*CM2-SM*SINH2)*(D1+D2) + &\r\n SIG*(CM*SINH2-(SM+SIG)*CM2)*D1)/E\r\n ELSE\r\n\r\n! SIG > .5: use negative exponentials in order to avoid\r\n! overflow. Note that EMS = EXP(-SIG). In the case of\r\n! extrapolation (negative B1 or B2), H is approximated by\r\n! a linear function if -SIG*B1 or -SIG*B2 is large.\r\n\r\n SB1 = SIG*B1\r\n SB2 = SIG - SB1\r\n IF (-SB1 .GT. SBIG .OR. -SB2 .GT. SBIG) THEN\r\n HPVAL = S\r\n ELSE\r\n E1 = EXP(-SB1)\r\n E2 = EXP(-SB2)\r\n EMS = E1*E2\r\n TM = 1.D0 - EMS\r\n E = TM*(SIG*(1.D0+EMS) - TM - TM)\r\n HPVAL = S + (TM*((E2-E1)*(D1+D2) + TM*(D1-D2)) &\r\n + SIG*((E1*EMS-E2)*D1 + (E1-E2*EMS)*D2))/E\r\n ENDIF\r\n ENDIF\r\n ENDIF\r\n ENDIF\r\n\r\n END FUNCTION\r\n\r\n\r\n DOUBLE PRECISION FUNCTION STORE (X)\r\n DOUBLE PRECISION X\r\n!***********************************************************\r\n! From TSPACK\r\n! Robert J. Renka\r\n! Dept. of Computer Science\r\n! Univ. of North Texas\r\n! renka@cs.unt.edu\r\n! 06/10/92\r\n! This function forces its argument X to be stored in a\r\n! memory location, thus providing a means of determining\r\n! floating point number characteristics (such as the machine\r\n! precision) when it is necessary to avoid computation in\r\n! high precision registers.\r\n! On input:\r\n! X = Value to be stored.\r\n! X is not altered by this function.\r\n! On output:\r\n! STORE = Value of X after it has been stored and\r\n! possibly truncated or rounded to the single\r\n! precision word length.\r\n! Procedures required by STORE: None\r\n!***********************************************************\r\n\r\n DOUBLE PRECISION Y\r\n COMMON/STCOM/Y\r\n Y = X\r\n STORE = Y\r\n END FUNCTION\r\n\r\n\r\n INTEGER FUNCTION INTRVL (T,N,X)\r\n INTEGER N\r\n DOUBLE PRECISION T, X(N)\r\n!***********************************************************\r\n! From TSPACK\r\n! Robert J. Renka\r\n! Dept. of Computer Science\r\n! Univ. of North Texas\r\n! renka@cs.unt.edu\r\n! 06/10/92\r\n! This function returns the index of the left end of an\r\n! interval (defined by an increasing sequence X) which\r\n! contains the value T. The method consists of first test-\r\n! ing the interval returned by a previous call, if any, and\r\n! then using a binary search if necessary.\r\n! On input:\r\n! T = Point to be located.\r\n! N = Length of X. N .GE. 2.\r\n! X = Array of length N assumed (without a test) to\r\n! contain a strictly increasing sequence of\r\n! values.\r\n! Input parameters are not altered by this function.\r\n! On output:\r\n! INTRVL = Index I defined as follows:\r\n! I = 1 if T .LT. X(2) or N .LE. 2,\r\n! I = N-1 if T .GE. X(N-1), and\r\n! X(I) .LE. T .LT. X(I+1) otherwise.\r\n! Procedures required by INTRVL: None\r\n!***********************************************************\r\n\r\n INTEGER IH, IL, K\r\n DOUBLE PRECISION TT\r\n LOGICAL FLAG\r\n\r\n SAVE IL\r\n DATA IL/1/\r\n\r\n TT = T\r\n FLAG = .TRUE.\r\n IF (IL .GE. 1 .AND. IL .LT. N) THEN\r\n IF (X(IL) .LE. TT .AND. TT .LT. X(IL+1)) FLAG=.FALSE.\r\n ENDIF\r\n\r\n IF(FLAG) THEN\r\n! Initialize low and high indexes.\r\n\r\n IL = 1\r\n IH = N\r\n\r\n! Binary search:\r\n\r\n DO\r\n IF (IH .LE. IL+1) EXIT\r\n K = (IL+IH)/2\r\n IF (TT .LT. X(K)) THEN\r\n IH = K\r\n ELSE\r\n IL = K\r\n ENDIF\r\n ENDDO\r\n\r\n! X(IL) .LE. T .LT. X(IL+1) or (T .LT. X(1) and IL=1)\r\n! or (T .GE. X(N) and IL=N-1)\r\n\r\n ENDIF\r\n\r\n INTRVL = IL\r\n END FUNCTION\r\n\r\nEND MODULE TENSION_MOD", "meta": {"hexsha": "d8292188f568faeee923f990a64703ef1bdd73da", "size": 50180, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tension_module.f90", "max_stars_repo_name": "NOC-MSM/LTRANS-for-NEMO", "max_stars_repo_head_hexsha": "28ac1ae1b98d7b56d74110fa8f1f9cb6fcc305c8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-06-08T01:05:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-08T02:16:25.000Z", "max_issues_repo_path": "Model/tension_module.f90", "max_issues_repo_name": "Jhongesell/LTRANSv.2b", "max_issues_repo_head_hexsha": "18d4118df36597a1cdac1e1f15dc96b00bd8448d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-07-06T21:46:05.000Z", "max_issues_repo_issues_event_max_datetime": "2017-07-06T21:46:05.000Z", "max_forks_repo_path": "Model/tension_module.f90", "max_forks_repo_name": "Jhongesell/LTRANSv.2b", "max_forks_repo_head_hexsha": "18d4118df36597a1cdac1e1f15dc96b00bd8448d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2018-11-22T12:54:56.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-08T02:16:26.000Z", "avg_line_length": 37.005899705, "max_line_length": 79, "alphanum_fraction": 0.5043443603, "num_tokens": 14298, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436483, "lm_q2_score": 0.7154240079185319, "lm_q1q2_score": 0.6587550372657455}} {"text": " SUBROUTINE MB04BZ( JOB, COMPQ, N, A, LDA, DE, LDDE, B, LDB, FG,\r\n $ LDFG, Q, LDQ, ALPHAR, ALPHAI, BETA, DWORK,\r\n $ LDWORK, ZWORK, LZWORK, BWORK, INFO )\r\nC\r\nC SLICOT RELEASE 5.5.\r\nC\r\nC Copyright (c) 2002-2012 NICONET e.V.\r\nC\r\nC PURPOSE\r\nC\r\nC To compute the eigenvalues of a complex N-by-N skew-Hamiltonian/\r\nC Hamiltonian pencil aS - bH, with\r\nC\r\nC ( A D ) ( B F )\r\nC S = ( H ) and H = ( H ). (1)\r\nC ( E A ) ( G -B )\r\nC\r\nC This routine computes the eigenvalues using an embedding to a real\r\nC skew-Hamiltonian/skew-Hamiltonian pencil aB_S - bB_T, defined as\r\nC\r\nC\r\nC ( Re(A) -Im(A) | Re(D) -Im(D) )\r\nC ( | )\r\nC ( Im(A) Re(A) | Im(D) Re(D) )\r\nC ( | )\r\nC B_S = (-----------------+-----------------) , and\r\nC ( | T T )\r\nC ( Re(E) -Im(E) | Re(A ) Im(A ) )\r\nC ( | T T )\r\nC ( Im(E) Re(E) | -Im(A ) Re(A ) )\r\nC (2)\r\nC ( -Im(B) -Re(B) | -Im(F) -Re(F) )\r\nC ( | )\r\nC ( Re(B) -Im(B) | Re(F) -Im(F) )\r\nC ( | )\r\nC B_T = (-----------------+-----------------) , T = i*H.\r\nC ( | T T )\r\nC ( -Im(G) -Re(G) | -Im(B ) Re(B ) )\r\nC ( | T T )\r\nC ( Re(G) -Im(G) | -Re(B ) -Im(B ) )\r\nC\r\nC Optionally, if JOB = 'T', the pencil aB_S - bB_H (B_H = -i*B_T) is\r\nC transformed by a unitary matrix Q to the structured Schur form\r\nC\r\nC ( BA BD ) ( BB BF )\r\nC B_Sout = ( H ) and B_Hout = ( H ), (3)\r\nC ( 0 BA ) ( 0 -BB )\r\nC\r\nC where BA and BB are upper triangular, BD is skew-Hermitian, and\r\nC BF is Hermitian. The embedding doubles the multiplicities of the\r\nC eigenvalues of the pencil aS - bH. Optionally, if COMPQ = 'C', the\r\nC unitary matrix Q is computed.\r\nC \r\nC\r\nC ARGUMENTS\r\nC\r\nC Mode Parameters\r\nC\r\nC JOB CHARACTER*1\r\nC Specifies the computation to be performed, as follows:\r\nC = 'E': compute the eigenvalues only; S and H will not\r\nC necessarily be transformed as in (3).\r\nC = 'T': put S and H into the forms in (3) and return the\r\nC eigenvalues in ALPHAR, ALPHAI and BETA.\r\nC\r\nC COMPQ CHARACTER*1\r\nC Specifies whether to compute the unitary transformation\r\nC matrix Q, as follows:\r\nC = 'N': Q is not computed;\r\nC = 'C': compute the unitary transformation matrix Q.\r\nC\r\nC Input/Output Parameters\r\nC\r\nC N (input) INTEGER\r\nC The order of the pencil aS - bH. N >= 0, even.\r\nC\r\nC A (input/output) COMPLEX*16 array, dimension (LDA, K)\r\nC where K = N/2, if JOB = 'E', and K = N, if JOB = 'T'.\r\nC On entry, the leading N/2-by-N/2 part of this array must\r\nC contain the matrix A.\r\nC On exit, if JOB = 'T', the leading N-by-N part of this\r\nC array contains the upper triangular matrix BA in (3) (see\r\nC also METHOD). The strictly lower triangular part is not\r\nC zeroed, but it is preserved.\r\nC If JOB = 'E', this array is unchanged on exit.\r\nC\r\nC LDA INTEGER\r\nC The leading dimension of the array A. LDA >= MAX(1, K).\r\nC\r\nC DE (input/output) COMPLEX*16 array, dimension\r\nC (LDDE, MIN(K+1,N))\r\nC On entry, the leading N/2-by-N/2 lower triangular part of\r\nC this array must contain the lower triangular part of the\r\nC skew-Hermitian matrix E, and the N/2-by-N/2 upper\r\nC triangular part of the submatrix in the columns 2 to N/2+1\r\nC of this array must contain the upper triangular part of\r\nC the skew-Hermitian matrix D.\r\nC On exit, if JOB = 'T', the leading N-by-N part of this\r\nC array contains the skew-Hermitian matrix BD in (3) (see\r\nC also METHOD). The strictly lower triangular part of the\r\nC input matrix is preserved.\r\nC If JOB = 'E', this array is unchanged on exit.\r\nC\r\nC LDDE INTEGER\r\nC The leading dimension of the array DE. LDDE >= MAX(1, K).\r\nC\r\nC B (input/output) COMPLEX*16 array, dimension (LDB, K)\r\nC On entry, the leading N/2-by-N/2 part of this array must\r\nC contain the matrix B.\r\nC On exit, if JOB = 'T', the leading N-by-N part of this\r\nC array contains the upper triangular matrix BB in (3) (see\r\nC also METHOD). The strictly lower triangular part is not\r\nC zeroed; the elements below the first subdiagonal of the\r\nC input matrix are preserved.\r\nC If JOB = 'E', this array is unchanged on exit.\r\nC\r\nC LDB INTEGER\r\nC The leading dimension of the array B. LDB >= MAX(1, K).\r\nC\r\nC FG (input/output) COMPLEX*16 array, dimension\r\nC (LDFG, MIN(K+1,N))\r\nC On entry, the leading N/2-by-N/2 lower triangular part of\r\nC this array must contain the lower triangular part of the\r\nC Hermitian matrix G, and the N/2-by-N/2 upper triangular\r\nC part of the submatrix in the columns 2 to N/2+1 of this\r\nC array must contain the upper triangular part of the\r\nC Hermitian matrix F.\r\nC On exit, if JOB = 'T', the leading N-by-N part of this\r\nC array contains the Hermitian matrix BF in (3) (see also\r\nC METHOD). The strictly lower triangular part of the input\r\nC matrix is preserved. The diagonal elements might have tiny\r\nC imaginary parts.\r\nC If JOB = 'E', this array is unchanged on exit.\r\nC\r\nC LDFG INTEGER\r\nC The leading dimension of the array FG. LDFG >= MAX(1, K).\r\nC\r\nC Q (output) COMPLEX*16 array, dimension (LDQ, 2*N)\r\nC On exit, if COMPQ = 'C', the leading 2*N-by-2*N part of\r\nC this array contains the unitary transformation matrix Q\r\nC that reduced the matrices B_S and B_H to the form in (3).\r\nC However, if JOB = 'E', the reduction was possibly not\r\nC completed: the matrix B_H may have 2-by-2 diagonal blocks,\r\nC and the array Q returns the orthogonal matrix that\r\nC performed the partial reduction.\r\nC If COMPQ = 'N', this array is not referenced.\r\nC\r\nC LDQ INTEGER\r\nC The leading dimension of the array Q.\r\nC LDQ >= 1, if COMPQ = 'N';\r\nC LDQ >= MAX(1, 2*N), if COMPQ = 'C'.\r\nC\r\nC ALPHAR (output) DOUBLE PRECISION array, dimension (N)\r\nC The real parts of each scalar alpha defining an eigenvalue\r\nC of the pencil aS - bH.\r\nC\r\nC ALPHAI (output) DOUBLE PRECISION array, dimension (N)\r\nC The imaginary parts of each scalar alpha defining an\r\nC eigenvalue of the pencil aS - bH.\r\nC If ALPHAI(j) is zero, then the j-th eigenvalue is real.\r\nC\r\nC BETA (output) DOUBLE PRECISION array, dimension (N)\r\nC The scalars beta that define the eigenvalues of the pencil\r\nC aS - bH.\r\nC Together, the quantities alpha = (ALPHAR(j),ALPHAI(j)) and\r\nC beta = BETA(j) represent the j-th eigenvalue of the pencil\r\nC aS - bH, in the form lambda = alpha/beta. Since lambda may\r\nC overflow, the ratios should not, in general, be computed.\r\nC\r\nC Workspace\r\nC\r\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\r\nC On exit, if INFO = 0, DWORK(1) returns the optimal LDWORK.\r\nC On exit, if INFO = -18, DWORK(1) returns the minimum value\r\nC of LDWORK.\r\nC\r\nC LDWORK INTEGER\r\nC The dimension of the array DWORK.\r\nC If COMPQ = 'N',\r\nC LDWORK >= MAX( 1, 4*N*N + 3*N ), if JOB = 'E';\r\nC LDWORK >= MAX( 1, 5*N*N + 3*N ), if JOB = 'T';\r\nC LDWORK >= MAX( 1, 11*N*N + 2*N ), if COMPQ = 'C'.\r\nC For good performance LDWORK should be generally larger.\r\nC\r\nC If LDWORK = -1, then a workspace query is assumed;\r\nC the routine only calculates the optimal size of the\r\nC DWORK array, returns this value as the first entry of\r\nC the DWORK array, and no error message related to LDWORK\r\nC is issued by XERBLA.\r\nC\r\nC ZWORK COMPLEX*16 array, dimension (LZWORK)\r\nC On exit, if INFO = 0, ZWORK(1) returns the optimal LZWORK.\r\nC On exit, if INFO = -20, ZWORK(1) returns the minimum\r\nC value of LZWORK.\r\nC\r\nC LZWORK INTEGER\r\nC The dimension of the array ZWORK.\r\nC LZWORK >= 1, if JOB = 'E'; otherwise,\r\nC LZWORK >= 6*N + 4, if COMPQ = 'N';\r\nC LZWORK >= 8*N + 4, if COMPQ = 'C'.\r\nC\r\nC If LZWORK = -1, then a workspace query is assumed;\r\nC the routine only calculates the optimal size of the\r\nC ZWORK array, returns this value as the first entry of\r\nC the ZWORK array, and no error message related to LZWORK\r\nC is issued by XERBLA.\r\nC\r\nC BWORK LOGICAL array, dimension (LBWORK)\r\nC LBWORK >= 0, if JOB = 'E';\r\nC LBWORK >= N, if JOB = 'T'.\r\nC\r\nC Error Indicator\r\nC\r\nC INFO INTEGER\r\nC = 0: succesful exit;\r\nC < 0: if INFO = -i, the i-th argument had an illegal value;\r\nC = 1: QZ iteration failed in the SLICOT Library routine\r\nC MB04FD (QZ iteration did not converge or computation\r\nC of the shifts failed);\r\nC = 2: QZ iteration failed in the LAPACK routine ZHGEQZ when\r\nC trying to triangularize the 2-by-2 blocks.\r\nC\r\nC METHOD\r\nC\r\nC First, T = i*H is set. Then, the embeddings, B_S and B_T, of the\r\nC matrices S and T, are determined and, subsequently, the SLICOT\r\nC Library routine MB04FD is applied to compute the structured Schur\r\nC form, i.e., the factorizations\r\nC\r\nC ~ T T ( S11 S12 )\r\nC B_S = J Q J B_S Q = ( T ) and\r\nC ( 0 S11 )\r\nC\r\nC ~ T T ( T11 T12 )\r\nC B_T = J Q J B_T Q = ( T ),\r\nC ( 0 T11 )\r\nC\r\nC where Q is real orthogonal, S11 is upper triangular, and T11 is\r\nC upper quasi-triangular. If JOB = 'T', then the matrices above are\r\nC ~ \r\nC further transformed so that the 2-by-2 blocks in i*B_T are split\r\nC into 1-by-1 blocks. If COMPQ = 'C', the transformations are\r\nC accumulated in the unitary matrix Q.\r\nC See also page 22 in [1] for more details.\r\nC\r\nC REFERENCES\r\nC\r\nC [1] Benner, P., Byers, R., Mehrmann, V. and Xu, H.\r\nC Numerical Computation of Deflating Subspaces of Embedded\r\nC Hamiltonian Pencils.\r\nC Tech. Rep. SFB393/99-15, Technical University Chemnitz,\r\nC Germany, June 1999.\r\nC\r\nC NUMERICAL ASPECTS\r\nC 3\r\nC The algorithm is numerically backward stable and needs O(N )\r\nC complex floating point operations.\r\nC\r\nC FURTHER COMMENTS\r\nC\r\nC This routine does not perform any scaling of the matrices. Scaling\r\nC might sometimes be useful, and it should be done externally.\r\nC\r\nC CONTRIBUTOR\r\nC\r\nC V. Sima, Research Institute for Informatics, Bucharest, Romania,\r\nC Nov. 2011, July 2012.\r\nC\r\nC REVISIONS\r\nC\r\nC -\r\nC\r\nC KEYWORDS\r\nC\r\nC Deflating subspace, embedded pencil, skew-Hamiltonian/Hamiltonian\r\nC pencil, structured Schur form.\r\nC\r\nC ******************************************************************\r\nC\r\nC .. Parameters ..\r\n DOUBLE PRECISION ONE\r\n PARAMETER ( ONE = 1.0D+0 )\r\n COMPLEX*16 CZERO, CONE, CIMAG\r\n PARAMETER ( CZERO = ( 0.0D+0, 0.0D+0 ),\r\n $ CONE = ( 1.0D+0, 0.0D+0 ),\r\n $ CIMAG = ( 0.0D+0, 1.0D+0 ) )\r\nC\r\nC .. Scalar Arguments ..\r\n CHARACTER COMPQ, JOB\r\n INTEGER INFO, LDA, LDB, LDDE, LDFG, LDQ, LDWORK,\r\n $ LZWORK, N\r\nC\r\nC .. Array Arguments ..\r\n LOGICAL BWORK( * )\r\n DOUBLE PRECISION ALPHAI( * ), ALPHAR( * ), BETA( * ), DWORK( * )\r\n COMPLEX*16 A( LDA, * ), B( LDB, * ), DE( LDDE, * ),\r\n $ FG( LDFG, * ), Q( LDQ, * ), ZWORK( * )\r\nC\r\nC .. Local Scalars ..\r\n LOGICAL LCMPQ, LQUERY, LTRI\r\n CHARACTER*14 CMPQ, JOBF\r\n INTEGER I, I1, IA, IB, IDE, IEV, IFG, IQ, IQ2, IQB, IS,\r\n $ IW, IW1, IWRK, J, J1, J2, JM1, JP2, K, M,\r\n $ MINDB, MINDW, MINZW, N2, NB, NC, NN, OPTDW,\r\n $ OPTZW\r\n DOUBLE PRECISION EPS, NRMB\r\n COMPLEX*16 TMP\r\nC\r\nC .. External Functions ..\r\n LOGICAL LSAME\r\n DOUBLE PRECISION DLAMCH\r\n EXTERNAL DLAMCH, LSAME\r\nC\r\nC .. External Subroutines ..\r\n EXTERNAL DCOPY, DLACPY, DSCAL, MB04FD, XERBLA, ZGEMM,\r\n $ ZGEQRF, ZHGEQZ, ZLACPY, ZSCAL\r\nC\r\nC .. Intrinsic Functions ..\r\n INTRINSIC ABS, DBLE, DCMPLX, DIMAG, INT, MAX, MIN, MOD\r\nC\r\nC .. Executable Statements ..\r\nC\r\nC Decode the input arguments.\r\nC\r\n M = N/2\r\n NN = N*N\r\n N2 = 2*N\r\n LTRI = LSAME( JOB, 'T' )\r\n LCMPQ = LSAME( COMPQ, 'C' )\r\nC\r\n IF( LTRI ) THEN\r\n K = N\r\n ELSE\r\n K = M\r\n END IF\r\nC\r\n IF( N.EQ.0 ) THEN\r\n MINDW = 1\r\n MINZW = 1\r\n ELSE IF( LCMPQ ) THEN\r\n MINDB = 8*NN + N2\r\n MINDW = 11*NN + N2\r\n MINZW = 8*N + 4\r\n ELSE\r\n MINDB = 4*NN + N2\r\n IF( LTRI ) THEN\r\n MINDW = 5*NN + 3*N\r\n ELSE\r\n MINDW = 4*NN + 3*N\r\n END IF\r\n MINZW = 6*N + 4\r\n END IF\r\nC\r\n LQUERY = LDWORK.EQ.-1 .OR. LZWORK.EQ.-1\r\nC\r\nC Test the input arguments.\r\nC\r\n INFO = 0\r\n IF( .NOT.( LSAME( JOB, 'E' ) .OR. LTRI ) ) THEN\r\n INFO = -1\r\n ELSE IF( .NOT.( LSAME( COMPQ, 'N' ) .OR. LCMPQ ) ) THEN\r\n INFO = -2\r\n ELSE IF( N.LT.0 .OR. MOD( N, 2 ).NE.0 ) THEN\r\n INFO = -3\r\n ELSE IF( LDA.LT.MAX( 1, K ) ) THEN\r\n INFO = -5\r\n ELSE IF( LDDE.LT.MAX( 1, K ) ) THEN\r\n INFO = -7\r\n ELSE IF( LDB.LT.MAX( 1, K ) ) THEN\r\n INFO = -9\r\n ELSE IF( LDFG.LT.MAX( 1, K ) ) THEN\r\n INFO = -11\r\n ELSE IF( LDQ.LT.1 .OR. ( LCMPQ .AND. LDQ.LT.N2 ) ) THEN\r\n INFO = -13\r\n ELSE IF( .NOT. LQUERY ) THEN\r\n IF( LDWORK.LT.MINDW ) THEN\r\n DWORK( 1 ) = MINDW\r\n INFO = -18\r\n ELSE IF( LZWORK.LT.MINZW ) THEN\r\n ZWORK( 1 ) = MINZW\r\n INFO = -20\r\n END IF\r\n END IF\r\nC\r\n IF( INFO.NE.0) THEN\r\n CALL XERBLA( 'MB04BZ', -INFO )\r\n RETURN\r\n ELSE IF( N.GT.0 ) THEN\r\nC\r\nC Compute optimal workspace.\r\nC\r\n OPTZW = MINZW\r\n IF( LCMPQ ) THEN\r\n CMPQ = 'Initialize'\r\n ELSE\r\n CMPQ = 'No Computation'\r\n END IF\r\nC\r\n IF( LTRI ) THEN\r\n JOBF = 'Triangularize'\r\n CALL ZGEQRF( N, N, ZWORK, N, ZWORK, ZWORK, -1, INFO )\r\n I = INT( ZWORK( 1 ) )\r\n NB = MAX( I/N, 2 )\r\n ELSE\r\n JOBF = 'Eigenvalues'\r\n END IF\r\nC\r\n IF( LQUERY ) THEN\r\n CALL MB04FD( JOBF, CMPQ, N2, DWORK, N, DWORK, N, DWORK, N,\r\n $ DWORK, N, DWORK, N2, ALPHAI, ALPHAR, BETA,\r\n $ DWORK, -1, INFO )\r\n OPTDW = MAX( MINDW, MINDB + INT( DWORK( 1 ) ) )\r\n DWORK( 1 ) = OPTDW\r\n ZWORK( 1 ) = OPTZW\r\n RETURN\r\n END IF\r\n END IF\r\nC\r\nC Quick return if possible.\r\nC\r\n IF( N.EQ.0 ) THEN\r\n DWORK( 1 ) = ONE\r\n ZWORK( 1 ) = CONE\r\n RETURN\r\n END IF\r\nC\r\nC Set up the embeddings of the matrices S and H.\r\nC\r\nC Set the pointers for the inputs and outputs of MB04FD.\r\nC Real workspace: need 4*N**2 + 2*N, if COMPQ = 'N';\r\nC 8*N**2 + 2*N, if COMPQ = 'C'.\r\nC\r\n IQ = 1\r\n IF( LCMPQ ) THEN\r\n IA = IQ + N2*N2\r\n ELSE\r\n IA = 1\r\n END IF\r\nC\r\n IDE = IA + NN\r\n IB = IDE + NN + N\r\n IFG = IB + NN\r\n IWRK = IFG + NN + N\r\nC\r\nC Build the embedding of A.\r\nC\r\n IW = IA\r\n IS = IW + N*M\r\n DO 30 J = 1, M\r\n IW1 = IW\r\n DO 10 I = 1, M\r\n DWORK( IW ) = DBLE( A( I, J ) )\r\n IW = IW + 1\r\n 10 CONTINUE\r\nC\r\n DO 20 I = 1, M\r\n DWORK( IW ) = DIMAG( A( I, J ) )\r\n DWORK( IS ) = -DWORK( IW )\r\n IW = IW + 1\r\n IS = IS + 1\r\n 20 CONTINUE\r\n CALL DCOPY( M, DWORK( IW1 ), 1, DWORK( IS ), 1 )\r\n IS = IS + M\r\n 30 CONTINUE\r\nC\r\nC Build the embedding of D and E.\r\nC\r\n IW = IDE\r\n DO 60 J = 1, M + 1\r\n DO 40 I = 1, M\r\n DWORK( IW ) = DBLE( DE( I, J ) )\r\n IW = IW + 1\r\n 40 CONTINUE\r\nC\r\n IW = IW + J - 1\r\n IS = IW\r\n DO 50 I = J, M\r\n DWORK( IW ) = DIMAG( DE( I, J ) )\r\n DWORK( IS ) = DWORK( IW )\r\n IW = IW + 1\r\n IS = IS + N\r\n 50 CONTINUE\r\n 60 CONTINUE\r\nC\r\n IW1 = IW\r\n I1 = IW\r\n DO 80 J = 2, M + 1\r\n IS = I1\r\n I1 = I1 + 1\r\n DO 70 I = 1, J - 1\r\n DWORK( IW ) = -DIMAG( DE( I, J ) )\r\n DWORK( IS ) = DWORK( IW )\r\n IW = IW + 1\r\n IS = IS + N\r\n 70 CONTINUE\r\n IW = IW + N - J + 1\r\n 80 CONTINUE\r\n CALL DLACPY( 'Full', M, M+1, DWORK( IDE ), N, DWORK( IW1-M ), N )\r\nC\r\nC Build the embedding of B.\r\nC\r\n IW = IB\r\n IS = IW + N*M\r\n DO 110 J = 1, M\r\n IW1 = IW\r\n DO 90 I = 1, M\r\n DWORK( IW ) = -DIMAG( B( I, J ) )\r\n IW = IW + 1\r\n 90 CONTINUE\r\nC\r\n DO 100 I = 1, M\r\n DWORK( IW ) = DBLE( B( I, J ) )\r\n DWORK( IS ) = -DWORK( IW )\r\n IW = IW + 1\r\n IS = IS + 1\r\n 100 CONTINUE\r\n CALL DCOPY( M, DWORK( IW1 ), 1, DWORK( IS ), 1 )\r\n IS = IS + M\r\n 110 CONTINUE\r\nC\r\nC Build the embedding of F and G.\r\nC\r\n IW = IFG\r\n DO 140 J = 1, M + 1\r\n DO 120 I = 1, M\r\n DWORK( IW ) = -DIMAG( FG( I, J ) )\r\n IW = IW + 1\r\n 120 CONTINUE\r\nC\r\n IW = IW + J - 1\r\n IS = IW\r\n DO 130 I = J, M\r\n DWORK( IW ) = DBLE( FG( I, J ) )\r\n DWORK( IS ) = DWORK( IW )\r\n IW = IW + 1\r\n IS = IS + N\r\n 130 CONTINUE\r\n 140 CONTINUE\r\nC\r\n IW1 = IW\r\n I1 = IW\r\n DO 160 J = 2, M + 1\r\n IS = I1\r\n I1 = I1 + 1\r\n DO 150 I = 1, J - 1\r\n DWORK( IW ) = -DBLE( FG( I, J ) )\r\n DWORK( IS ) = DWORK( IW )\r\n IW = IW + 1\r\n IS = IS + N\r\n 150 CONTINUE\r\n IW = IW + N - J + 1\r\n 160 CONTINUE\r\n CALL DLACPY( 'Full', M, M+1, DWORK( IFG ), N, DWORK( IW1-M ), N )\r\nC\r\nC STEP 1: Apply MB04FD to transform the extended pencil to real\r\nC skew-Hamiltonian/skew-Hamiltonian Schur form.\r\nC\r\nC Real workspace:\r\nC need 4*N*N + 3*N, if JOB = 'E' and COMPQ = 'N';\r\nC 5*N*N + 3*N, if JOB = 'T' and COMPQ = 'N';\r\nC 11*N*N + 2*N, if COMPQ = 'C'.\r\nC prefer larger.\r\nC\r\n CALL MB04FD( JOBF, CMPQ, N2, DWORK( IA ), N, DWORK( IDE ), N,\r\n $ DWORK( IB ), N, DWORK( IFG ), N, DWORK( IQ ), N2,\r\n $ ALPHAI, ALPHAR, BETA, DWORK( IWRK ), LDWORK-IWRK+1,\r\n $ INFO )\r\n IF( INFO.GT.0 )\r\n $ RETURN\r\n OPTDW = MAX( MINDW, MINDB + INT( DWORK( IWRK ) ) )\r\nC\r\nC Scale the eigenvalues.\r\nC\r\n CALL DSCAL( N, -ONE, ALPHAI, 1 )\r\nC\r\n IF( LCMPQ ) THEN\r\nC\r\nC Set the transformation matrix.\r\nC\r\n IW = IQ\r\n DO 180 J = 1, N2\r\n DO 170 I = 1, N2\r\n Q( I, J ) = DCMPLX( DWORK( IW ) )\r\n IW = IW + 1\r\n 170 CONTINUE\r\n 180 CONTINUE\r\n END IF\r\nC\r\nC Return if further reduction is not required.\r\nC\r\n IF( .NOT.LTRI ) THEN\r\n DWORK( 1 ) = OPTDW\r\n ZWORK( 1 ) = OPTZW\r\n RETURN\r\n END IF\r\nC\r\nC Convert the results to complex datatype. D and F start in the\r\nC first column of DE and FG, respectively.\r\nC\r\n IW = IA\r\n DO 200 J = 1, N\r\n DO 190 I = 1, J\r\n A( I, J ) = DCMPLX( DWORK( IW ) )\r\n IW = IW + 1\r\n 190 CONTINUE\r\n IW = IW + N - J\r\n 200 CONTINUE\r\nC\r\n IW = IDE + N\r\n DO 220 J = 1, N\r\n DO 210 I = 1, J - 1\r\n DE( I, J ) = DCMPLX( DWORK( IW ) )\r\n IW = IW + 1\r\n 210 CONTINUE\r\n DE( J, J ) = CZERO\r\n IW = IW + N - J + 1\r\n 220 CONTINUE\r\nC\r\n IW = IB\r\n DO 240 J = 1, N\r\n DO 230 I = 1, MIN( J + 1, N )\r\n B( I, J ) = DCMPLX( DWORK( IW ) )\r\n IW = IW + 1\r\n 230 CONTINUE\r\n IW = IW + N - J - 1\r\n 240 CONTINUE\r\nC\r\n IW = IFG + N\r\n DO 260 J = 1, N\r\n DO 250 I = 1, J - 1\r\n FG( I, J ) = DCMPLX( DWORK( IW ) )\r\n IW = IW + 1\r\n 250 CONTINUE\r\n FG( J, J ) = CZERO\r\n IW = IW + N - J + 1\r\n 260 CONTINUE\r\nC\r\nC Triangularize the 2-by-2 diagonal blocks in B using the complex\r\nC version of the QZ algorithm.\r\nC\r\nC Determine machine constants.\r\nC\r\n EPS = DLAMCH( 'Precision' )\r\nC\r\nC Set up pointers on the outputs of ZHGEQZ.\r\nC A block algorithm is used for large N.\r\nC\r\n IQ2 = 1\r\n IEV = 5\r\n IQ = 9\r\n IWRK = IQ + 4*( N - 1 )\r\nC\r\n J = 1\r\n J1 = 1\r\n J2 = MIN( N, J1 + NB - 1 )\r\nC WHILE( J.LT.N ) DO\r\n 270 CONTINUE\r\n IF( J.LT.N ) THEN\r\n NRMB = ABS( B( J, J ) ) + ABS( B( J+1, J+1 ) )\r\n IF( ABS( B( J+1, J ) ).GT.NRMB*EPS ) THEN\r\nC\r\nC Triangularization step.\r\nC Complex workspace: need 4*N + 6.\r\nC Real workspace: need 2.\r\nC\r\n NC = MAX( J2-J-1, 0 )\r\n JM1 = MAX( J-1, 1 )\r\n JP2 = MIN( J+2, N )\r\n TMP = A( J+1, J )\r\n A( J+1, J ) = CZERO\r\n CALL ZHGEQZ( 'Schur Form', 'Initialize', 'Initialize', 2, 1,\r\n $ 2, B( J, J ), LDB, A( J, J ), LDA,\r\n $ ZWORK( IEV ), ZWORK( IEV+2 ), ZWORK( IQ ), 2,\r\n $ ZWORK( IQ2 ), 2, ZWORK( IWRK ), LZWORK-IWRK+1,\r\n $ DWORK, INFO )\r\n A( J+1, J ) = TMP\r\n IF( INFO.GT.0 ) THEN\r\n INFO = 2\r\n RETURN\r\n END IF\r\nC\r\nC Update A, DE, B, and FG.\r\nC Complex workspace: need 6*N + 4.\r\nC\r\nC Update A.\r\nC\r\n CALL ZGEMM( 'No Transpose', 'No Transpose', J-1, 2, 2,\r\n $ CONE, A( 1, J ), LDA, ZWORK( IQ2 ), 2, CZERO,\r\n $ ZWORK( IWRK ), JM1 )\r\n CALL ZLACPY( 'Full', J-1, 2, ZWORK( IWRK ), JM1, A( 1, J ),\r\n $ LDA )\r\n CALL ZGEMM( 'Conjugate Transpose', 'No Transpose', 2, NC,\r\n $ 2, CONE, ZWORK( IQ ), 2, A( J, JP2 ), LDA,\r\n $ CZERO, ZWORK( IWRK ), 2 )\r\n CALL ZLACPY( 'Full', 2, NC, ZWORK( IWRK ), 2, A( J, JP2 ),\r\n $ LDA )\r\nC\r\nC Update DE.\r\nC\r\n TMP = DE( J+1, J )\r\n DE( J+1, J ) = -DE( J, J+1 )\r\n CALL ZGEMM( 'No Transpose', 'No Transpose', J+1, 2, 2,\r\n $ CONE, DE( 1, J ), LDDE, ZWORK( IQ ), 2, CZERO,\r\n $ ZWORK( IWRK ), J+1 )\r\n CALL ZLACPY( 'Full', J+1, 2, ZWORK( IWRK ), J+1, DE( 1, J ),\r\n $ LDDE )\r\n CALL ZGEMM( 'Conjugate Transpose', 'No Transpose', 2,\r\n $ J2-J+1, 2, CONE, ZWORK( IQ ), 2, DE( J, J ),\r\n $ LDDE, CZERO, ZWORK( IWRK ), 2 )\r\n CALL ZLACPY( 'Full', 2, J2-J+1, ZWORK( IWRK ), 2,\r\n $ DE( J, J ), LDDE )\r\n DE( J+1, J ) = TMP\r\nC\r\nC Update B.\r\nC\r\n CALL ZGEMM( 'No Transpose', 'No Transpose', J-1, 2, 2,\r\n $ CONE, B( 1, J ), LDB, ZWORK( IQ2 ), 2, CZERO,\r\n $ ZWORK( IWRK ), JM1 )\r\n CALL ZLACPY( 'Full', J-1, 2, ZWORK( IWRK ), JM1, B( 1, J ),\r\n $ LDB )\r\n CALL ZGEMM( 'Conjugate Transpose', 'No Transpose', 2, NC,\r\n $ 2, CONE, ZWORK( IQ ), 2, B( J, JP2 ), LDB,\r\n $ CZERO, ZWORK( IWRK ), 2 )\r\n CALL ZLACPY( 'Full', 2, NC, ZWORK( IWRK ), 2, B( J, JP2 ),\r\n $ LDB )\r\nC\r\nC Update FG.\r\nC\r\n TMP = FG( J+1, J )\r\n FG( J+1, J ) = -FG( J, J+1 )\r\n CALL ZGEMM( 'No Transpose', 'No Transpose', J+1, 2, 2,\r\n $ CONE, FG( 1, J ), LDFG, ZWORK( IQ ), 2, CZERO,\r\n $ ZWORK( IWRK ), J+1 )\r\n CALL ZLACPY( 'Full', J+1, 2, ZWORK( IWRK ), J+1, FG( 1, J ),\r\n $ LDFG )\r\n CALL ZGEMM( 'Conjugate Transpose', 'No Transpose', 2,\r\n $ J2-J+1, 2, CONE, ZWORK( IQ ), 2, FG( J, J ),\r\n $ LDFG, CZERO, ZWORK( IWRK ), 2 )\r\n CALL ZLACPY( 'Full', 2, J2-J+1, ZWORK( IWRK ), 2,\r\n $ FG( J, J ), LDFG )\r\n FG( J+1, J ) = TMP\r\nC\r\n IF( LCMPQ ) THEN\r\nC\r\nC Update Q.\r\nC Complex workspace: need 8*N + 4.\r\nC\r\n CALL ZGEMM( 'No Transpose', 'No Transpose', N2, 2, 2,\r\n $ CONE, Q( 1, J ), LDQ, ZWORK( IQ2 ), 2,\r\n $ CZERO, ZWORK( IWRK ), N2 )\r\n CALL ZLACPY( 'Full', N2, 2, ZWORK( IWRK ), N2, Q( 1, J ),\r\n $ LDQ )\r\n CALL ZGEMM( 'No Transpose', 'No Transpose', N2, 2, 2,\r\n $ CONE, Q( 1, N+J ), LDQ, ZWORK( IQ ), 2,\r\n $ CZERO, ZWORK( IWRK ), N2 )\r\n CALL ZLACPY( 'Full', N2, 2, ZWORK( IWRK ), N2,\r\n $ Q( 1, N+J ), LDQ )\r\n END IF\r\nC\r\n BWORK( J ) = .TRUE.\r\n J = J + 2\r\n IQ = IQ + 4\r\n ELSE\r\n BWORK( J ) = .FALSE.\r\n B( J+1, J ) = CZERO\r\n J = J + 1\r\n END IF\r\nC\r\n IF( J.GE.J2 ) THEN\r\n J1 = J2 + 1\r\n J2 = MIN( N, J1 + NB - 1 )\r\n NC = J2 - J1 + 1\r\nC\r\nC Update the columns J1 to J2 of A, DE, B, and FG for previous\r\nC transformations.\r\nC\r\n I = 1\r\n IQB = 9\r\nC WHILE( I.LT.J ) DO\r\n 280 CONTINUE\r\n IF( I.LT.J ) THEN\r\n IF( BWORK( I ) ) THEN\r\n CALL ZGEMM( 'Conjugate Transpose', 'No Transpose', 2,\r\n $ NC, 2, CONE, ZWORK( IQB ), 2, A( I, J1 ),\r\n $ LDA, CZERO, ZWORK( IWRK ), 2 )\r\n CALL ZLACPY( 'Full', 2, NC, ZWORK( IWRK ), 2,\r\n $ A( I, J1 ), LDA )\r\nC\r\n CALL ZGEMM( 'Conjugate Transpose', 'No Transpose', 2,\r\n $ NC, 2, CONE, ZWORK( IQB ), 2,\r\n $ DE( I, J1 ), LDDE, CZERO, ZWORK( IWRK ),\r\n $ 2 )\r\n CALL ZLACPY( 'Full', 2, NC, ZWORK( IWRK ), 2,\r\n $ DE( I, J1 ), LDDE )\r\nC\r\n CALL ZGEMM( 'Conjugate Transpose', 'No Transpose', 2,\r\n $ NC, 2, CONE, ZWORK( IQB ), 2, B( I, J1 ),\r\n $ LDB, CZERO, ZWORK( IWRK ), 2 )\r\n CALL ZLACPY( 'Full', 2, NC, ZWORK( IWRK ), 2,\r\n $ B( I, J1 ), LDB )\r\nC\r\n CALL ZGEMM( 'Conjugate Transpose', 'No Transpose', 2,\r\n $ NC, 2, CONE, ZWORK( IQB ), 2,\r\n $ FG( I, J1 ), LDFG, CZERO, ZWORK( IWRK ),\r\n $ 2 )\r\n CALL ZLACPY( 'Full', 2, NC, ZWORK( IWRK ), 2,\r\n $ FG( I, J1 ), LDFG )\r\n IQB = IQB + 4\r\nC\r\n I = I + 2\r\n ELSE\r\n I = I + 1\r\n END IF\r\n GO TO 280\r\n END IF\r\nC END WHILE 280\r\n END IF\r\n GO TO 270\r\n END IF\r\nC END WHILE 270\r\nC\r\nC Scale B and FG by -i.\r\nC\r\n DO 290 I = 1, N\r\n CALL ZSCAL( I, -CIMAG, B( 1, I ), 1 )\r\n 290 CONTINUE\r\nC\r\n DO 300 I = 1, N\r\n CALL ZSCAL( I, -CIMAG, FG( 1, I ), 1 )\r\n 300 CONTINUE\r\nC\r\n DWORK( 1 ) = OPTDW\r\n ZWORK( 1 ) = OPTZW\r\n RETURN\r\nC *** Last line of MB04BZ ***\r\n END\r\n", "meta": {"hexsha": "17ae0744e2de3d73c6aa64384c464b2e82a38dd8", "size": 29853, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "External/SLICOT/MB04BZ.f", "max_stars_repo_name": "bgin/MissileSimulation", "max_stars_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2016-08-28T23:20:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-15T14:43:58.000Z", "max_issues_repo_path": "External/SLICOT/MB04BZ.f", "max_issues_repo_name": "bgin/MissileSimulation", "max_issues_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-06-02T21:29:51.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-05T05:59:31.000Z", "max_forks_repo_path": "External/SLICOT/MB04BZ.f", "max_forks_repo_name": "bgin/MissileSimulation", "max_forks_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-07-04T22:38:22.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-04T22:38:22.000Z", "avg_line_length": 35.6666666667, "max_line_length": 80, "alphanum_fraction": 0.4378789401, "num_tokens": 9499, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436483, "lm_q2_score": 0.7154240018510026, "lm_q1q2_score": 0.6587550316788272}} {"text": "!!# LIBRARY MODULE: <>\nMODULE LIB_BiVar\n\n!!## PURPOSE\n!! Contains a library of routines to\n!! interpolate irregular X,Y data via bivariate polynomial\n!! construction.\n\n\n\n!!## EXTERNAL KINDS\nUSE KND_IntrinsicTypes,ONLY: KIND_Rdp !!((01-A-KND_IntrinsicTypes.f90))\n\n\n\n!!## HISTORY\n! 1.[waw] Reorganizer = William A. Wieselquist\n! Modified = 105.2006\n! Contact = william.wieselquist AT gmail.com\n\n\n\n!!## DEFAULT IMPLICIT\nIMPLICIT NONE\n\n\n\n!!## DFEAULT ACCESS\nPRIVATE\n\n\n\n!!## PUBLIC ACCESS LIST\nPUBLIC :: idbvip,idsfft\n\n\n\n!!## LOCAL VARIABLES\nINTEGER :: itpv,itipv,ntsc(9)\nREAL( kind = KIND_Rdp ) :: xs1,xs2,ys1,ys2,&\n x0,y0,ap,bp,cp,dp,&\n p00,p10,p20,p30,p40,p50,p01,p11,p21,p31,p41, &\n p02,p12,p22,p32,p03,p13,p23,p04,p14,p05\n\n\n\n!!## MODULE PROCEDURES\nCONTAINS\n\n\n\nsubroutine idbvip ( md, ndp, xd, yd, zd, nip, xi, yi, zi , &\n errint , errmsg )\n\n!*******************************************************************************\n!\n!! IDBVIP performs bivariate interpolation of irregular X, Y data.\n!\n! Discussion:\n!\n! The data points must be distinct and their projections in the\n! X-Y plane must not be collinear, otherwise an error return\n! occurs.\n!\n! Purpose:\n!\n! To provide bivariate interpolation and smooth surface fitting for\n! values given at irregularly distributed points.\n!\n! The resulting interpolating function and its first-order partial\n! derivatives are continuous.\n!\n! The method employed is local, i.e. a change in the data in one area\n! of the plane does not affect the interpolating function except in\n! that local area. This is advantageous over global interpolation\n! methods.\n!\n! Also, the method gives exact results when all points lie in a plane.\n! This is advantageous over other methods such as two-dimensional\n! Fourier series interpolation.\n!\n! Usage:\n!\n! This package contains two USEr entries, IDBVIP and IDSFFT, both\n! requiring input data to be given at points\n! ( X(I), Y(I) ), I = 1,...,N.\n!\n! If the USEr desires the interpolated data to be output at grid\n! points, i.e. at points\n! ( XI(I), YI(J) ), I = 1,...,NXI, J=1,...,NYI,\n! then IDSFFT should be used. This is USEful for generating an\n! interpolating surface.\n!\n! The other USEr entry point, IDBVIP, will produce interpolated\n! values at scattered points\n! ( XI(I), YI(I) ), i = 1,...,NIP.\n! This is USEful for filling in missing data points on a grid.\n!\n! History:\n!\n! The original version of BIVAR was written by Hiroshi Akima in\n! August 1975 and rewritten by him in late 1976. It was incorporated\n! into NCAR's public software libraries in January 1977. In August\n! 1984 a new version of BIVAR, incorporating changes described in the\n! Rocky Mountain Journal of Mathematics article cited below, was\n! obtained from Dr Akima by Michael Pernice of NCAR's Scientific\n! Computing Division, who evaluated it and made it available in February,\n! 1985.\n!\n! Accuracy:\n!\n! Accurate to machine precision on the input data points. Accuracy at\n! other points greatly depends on the input data.\n!\n! Modified:\n!\n! 23 January 2003\n!\n! References:\n!\n! Hiroshi Akima,\n! Algorithm 526,\n! A Method of Bivariate Interpolation and Smooth Surface Fitting\n! for Values Given at Irregularly Distributed Points,\n! ACM Transactions on Mathematical Software,\n! Volume 4, Number 2, June 1978.\n!\n! Hiroshi Akima,\n! On Estimating Partial Derivatives for Bivariate Interpolation\n! of Scattered Data,\n! Rocky Mountain Journal of Mathematics,\n! Volume 14, Number 1, Winter 1984.\n!\n! Method:\n!\n! The XY plane is divided into triangular cells, each cell having\n! projections of three data points in the plane as its vertices, and\n! a bivariate quintic polynomial in X and Y is fitted to each\n! triangular cell.\n!\n! The coefficients in the fitted quintic polynomials are determined\n! by continuity requirements and by estimates of partial derivatives\n! at the vertices and along the edges of the triangles. The method\n! described in the rocky mountain journal reference guarantees that\n! the generated surface depends continuously on the triangulation.\n!\n! The resulting interpolating function is invariant under the following\n! types of linear coordinate transformations:\n! 1) a rotation of the XY coordinate system\n! 2) linear scale transformation of the Z axis\n! 3) tilting of the XY plane, i.e. new coordinates (u,v,w) given by\n! u = x\n! v = y\n! w = z + a*x + b*y\n! where a, b are arbitrary constants.\n!\n! complete details of the method are given in the reference publications.\n!\n! Parameters:\n!\n! Input, integer MD, mode of computation. MD must be 1,\n! 2, or 3, else an error return occurs.\n!\n! 1: if this is the first call to this subroutine, or if the\n! value of NDP has been changed from the previous call, or\n! if the contents of the XD or YD arrays have been changed\n! from the previous call.\n!\n! 2: if the values of NDP and the XD and YD arrays are unchanged\n! from the previous call, but new values for XI, YI are being\n! used. If MD = 2 and NDP has been changed since the previous\n! call to IDBVIP, an error return occurs.\n!\n! 3: if the values of NDP, NIP, XD, YD, XI, YI are unchanged from\n! the previous call, i.e. if the only change on input to IDBVIP is\n! in the ZD array. If MD = 3 and NDP or NIP has been changed since\n! the previous call to IDBVIP, an error return occurs.\n!\n! Between the call with MD = 2 or MD = 3 and the preceding call, the\n! IWK and WK work arrays should not be disturbed.\n!\n! Input, integer NDP, the number of data points (must be 4 or\n! greater, else an error return occurs).\n!\n! Input, real ( kind = KIND_Rdp ) XD(NDP), Y(NDP), the X and Y coordinates\n! of the data points.\n!\n! Input, real ( kind = KIND_Rdp ) ZD(NDP), the data values at the data points.\n!\n! Input, integer NIP, the number of output points at which\n! interpolation is to be performed (must be 1 or greater, else an\n! error return occurs).\n!\n! Input, real ( kind = KIND_Rdp ) XI(NIP), YI(NIP), the coordinates of the\n! points at which interpolation is to be performed.\n!\n! Output, real ( kind = KIND_Rdp ) ZI(NIP), the interpolated data values.\n!\n! Local parameters:\n!\n! Workspace, integer IWK(31*NDP+NIP).\n!\n! Workspace, real ( kind = KIND_Rdp ) WK(8*NDP).\n!\n implicit none\n\n integer ndp\n integer nip\n integer errint\n character ( len = * ) errmsg\n optional errint,errmsg\n integer iip\n integer iwk(31*ndp + nip)\n integer jwipl\n integer jwipt\n integer jwit\n integer jwit0\n integer jwiwk\n integer jwiwl\n integer jwiwp\n integer jwwpd\n integer md\n integer nl\n integer nt\n real ( kind = KIND_Rdp ) wk(8*ndp)\n real ( kind = KIND_Rdp ) xd(ndp)\n real ( kind = KIND_Rdp ) xi(nip)\n real ( kind = KIND_Rdp ) yd(ndp)\n real ( kind = KIND_Rdp ) yi(nip)\n real ( kind = KIND_Rdp ) zd(ndp)\n real ( kind = KIND_Rdp ) zi(nip)\n\n!\n! Error check.\n!\n IF( PRESENT(errmsg) )errmsg = \"\"\n IF( PRESENT(errint) )errint = 0\n if ( md < 1 .or. 3 < md ) then\n if( present(errint) )errint = -11\n if( present(errmsg) )then\n write (errmsg, '(a)' )'Input parameter MD out of range. [LIB_BiVar:IDBVIP]'\n end if\n return\n end if\n\n if ( ndp < 4 ) then\n if( present(errint) )errint = -12\n if( present(errmsg) )then\n write (errmsg, '(a)' ) 'Input parameter NDP out of range. [LIB_BiVar:IDBVIP]'\n end if\n return\n end if\n\n if ( nip < 1 ) then\n if( present(errint) )errint = -13\n if( present(errmsg) )then\n write (errmsg, '(a)' ) 'Input parameter NIP out of range. [LIB_BiVar:IDBVIP]'\n end if\n return\n end if\n\n if ( md == 1 ) then\n iwk(1) = ndp\n else\n if ( ndp /= iwk(1) ) then\n if( present(errint) )errint = -14\n if( present(errmsg) )then\n write (errmsg, '(a)' ) 'MD = 2 or 3 but NDP was changed since last call. [LIB_BiVar:IDBVIP]'\n end if\n return\n end if\n end if\n\n if ( md <= 2 ) then\n iwk(3) = nip\n else\n if ( nip < iwk(3) ) then\n if( present(errint) )errint = -15\n if( present(errmsg) )then\n write (errmsg, '(a)' ) 'MD = 3 but NIP was changed since last call. [LIB_BiVar:IDBVIP]'\n end if\n return\n end if\n end if\n!\n! Allocation of storage areas in the IWK array.\n!\n jwipt = 16\n jwiwl = 6*ndp+1\n jwiwk = jwiwl\n jwipl = 24*ndp+1\n jwiwp = 30*ndp+1\n jwit0 = 31*ndp\n jwwpd = 5*ndp+1\n!\n! Triangulate the XY plane.\n!\n if ( md == 1 ) then\n\n call idtang ( ndp, xd, yd, nt, iwk(jwipt), nl, iwk(jwipl), &\n iwk(jwiwl), iwk(jwiwp), wk )\n\n iwk(5) = nt\n iwk(6) = nl\n\n if ( nt == 0 ) then\n return\n end if\n\n else\n\n nt = iwk(5)\n nl = iwk(6)\n\n end if\n!\n! Locate all points at which interpolation is to be performed.\n!\n if ( md <= 2 ) then\n\n itipv = 0\n jwit = jwit0\n\n do iip = 1, nip\n\n jwit = jwit+1\n\n call idlctn ( ndp, xd, yd, nt, iwk(jwipt), nl, iwk(jwipl), &\n xi(iip), yi(iip), iwk(jwit) )\n\n end do\n\n end if\n!\n! Estimate the partial derivatives at all data points.\n!\n call idpdrv ( ndp, xd, yd, zd, nt, iwk(jwipt), wk, wk(jwwpd) )\n!\n! Interpolate the ZI values.\n!\n itpv = 0\n jwit = jwit0\n\n do iip = 1, nip\n\n jwit = jwit + 1\n\n call idptip ( ndp, xd, yd, zd, nt, iwk(jwipt), nl, iwk(jwipl), wk, &\n iwk(jwit), xi(iip), yi(iip), zi(iip) )\n\n end do\n\n return\nend subroutine\n\nsubroutine idgrid ( xd, yd, nt, ipt, nl, ipl, nxi, nyi, xi, yi, ngp, igp )\n\n!*******************************************************************************\n!\n!! IDGRID organizes grid points for surface fitting.\n!\n! Discussion:\n!\n! IDGRID sorts the points in ascending order of triangle numbers and\n! of the border line segment number.\n!\n! Reference:\n!\n! Hiroshi Akima,\n! Algorithm 526,\n! A Method of Bivariate Interpolation and Smooth Surface Fitting\n! for Values Given at Irregularly Distributed Points,\n! ACM Transactions on Mathematical Software,\n! Volume 4, Number 2, June 1978.\n!\n! Parameters:\n!\n! Input, real ( kind = KIND_Rdp ) XD(NDP), YD(NDP), the X and Y coordinates of\n! the data points.\n!\n! Input, integer NT, the number of triangles.\n!\n! Input, integer IPT(3*NT), the indices of the triangle vertexes.\n!\n! Input, integer NL, the number of border line segments.\n!\n! Input, integer IPL(3*NL), containing the point numbers of the end points\n! of the border line segments and their respective triangle numbers,\n!\n! Input, integer NXI, NYI, the number of grid points in the X and Y\n! coordinates.\n!\n! Input, real ( kind = KIND_Rdp ) XI(NXI), YI(NYI), the coordinates of the\n! grid points.\n!\n! Output, integer NGP(2*(NT+2*NL)) where the\n! number of grid points that belong to each of the\n! triangles or of the border line segments are to be stored.\n!\n! Output, integer IGP(NXI*NYI), where the grid point numbers are to be\n! stored in ascending order of the triangle number and the border line\n! segment number.\n!\n implicit none\n\n integer nl\n integer nt\n integer nxi\n integer nyi\n\n integer igp(nxi*nyi)\n integer il0\n integer il0t3\n integer ilp1\n integer ilp1t3\n integer insd\n integer ip1\n integer ip2\n integer ip3\n integer ipl(3*nl)\n integer ipt(3*nt)\n integer it0\n integer it0t3\n integer ixi\n integer iximn\n integer iximx\n integer iyi\n integer izi\n integer jigp0\n integer jigp1\n integer jigp1i\n integer jngp0\n integer jngp1\n integer l\n integer ngp(2*(nt+2*nl))\n integer ngp0\n integer ngp1\n integer nl0\n integer nt0\n integer nxinyi\n real ( kind = KIND_Rdp ) u1\n real ( kind = KIND_Rdp ) u2\n real ( kind = KIND_Rdp ) u3\n real ( kind = KIND_Rdp ) v1\n real ( kind = KIND_Rdp ) v2\n real ( kind = KIND_Rdp ) v3\n real ( kind = KIND_Rdp ) x1\n real ( kind = KIND_Rdp ) x2\n real ( kind = KIND_Rdp ) x3\n real ( kind = KIND_Rdp ) xd(*)\n real ( kind = KIND_Rdp ) xi(nxi)\n real ( kind = KIND_Rdp ) xii\n real ( kind = KIND_Rdp ) ximn\n real ( kind = KIND_Rdp ) ximx\n real ( kind = KIND_Rdp ) xmn\n real ( kind = KIND_Rdp ) xmx\n real ( kind = KIND_Rdp ) y1\n real ( kind = KIND_Rdp ) y2\n real ( kind = KIND_Rdp ) y3\n real ( kind = KIND_Rdp ) yd(*)\n real ( kind = KIND_Rdp ) yi(nyi)\n real ( kind = KIND_Rdp ) yii\n real ( kind = KIND_Rdp ) yimn\n real ( kind = KIND_Rdp ) yimx\n real ( kind = KIND_Rdp ) ymn\n real ( kind = KIND_Rdp ) ymx\n!\n! Preliminary processing\n!\n nt0 = nt\n nl0 = nl\n nxinyi = nxi * nyi\n ximn = min ( xi(1), xi(nxi) )\n ximx = max ( xi(1), xi(nxi) )\n yimn = min ( yi(1), yi(nyi) )\n yimx = max ( yi(1), yi(nyi) )\n!\n! Determine grid points inside the data area.\n!\n jngp0 = 0\n jngp1 = 2 * ( nt0 + 2 * nl0 ) + 1\n jigp0 = 0\n jigp1 = nxinyi + 1\n\n do it0 = 1, nt0\n\n ngp0 = 0\n ngp1 = 0\n it0t3 = it0 * 3\n ip1 = ipt(it0t3-2)\n ip2 = ipt(it0t3-1)\n ip3 = ipt(it0t3)\n x1 = xd(ip1)\n y1 = yd(ip1)\n x2 = xd(ip2)\n y2 = yd(ip2)\n x3 = xd(ip3)\n y3 = yd(ip3)\n xmn = min ( x1, x2, x3 )\n xmx = max ( x1, x2, x3 )\n ymn = min ( y1, y2, y3 )\n ymx = max ( y1, y2, y3 )\n insd = 0\n\n do ixi = 1, nxi\n\n if ( xi(ixi) < xmn .or. xmx < xi(ixi) ) then\n if ( insd == 0 ) then\n cycle\n end if\n iximx = ixi - 1\n go to 23\n end if\n\n if ( insd /= 1 ) then\n insd = 1\n iximn = ixi\n end if\n\n end do\n\n if ( insd == 0 ) then\n go to 38\n end if\n\n iximx = nxi\n\n23 continue\n\n do iyi = 1, nyi\n\n yii = yi(iyi)\n\n if ( yii < ymn .or. yii > ymx ) then\n go to 37\n end if\n\n do ixi = iximn, iximx\n\n xii = xi(ixi)\n l = 0\n if ( vpdt(x1,y1,x2,y2,xii,yii)<0._KIND_Rdp ) then\n goto 36\n else if( vpdt(x1,y1,x2,y2,xii,yii)==0._KIND_Rdp ) then\n goto 25\n else\n goto 26\n end if\n\n25 continue\n\n l = 1\n26 continue\n if ( vpdt ( x2,y2,x3,y3,xii,yii )<0._KIND_Rdp ) then\n goto 36\n else if( vpdt ( x2,y2,x3,y3,xii,yii )==0._KIND_Rdp ) then\n goto 27\n else\n goto 28\n end if\n\n27 continue\n l = 1\n28 continue\n if ( vpdt ( x3,y3,x1,y1,xii,yii)<0._KIND_Rdp ) then\n goto 36\n else if( vpdt ( x3,y3,x1,y1,xii,yii)==0._KIND_Rdp ) then\n goto 29\n else\n goto 30\n end if\n\n29 continue\n l = 1\n30 continue\n izi = nxi * ( iyi - 1 ) + ixi\n\n if ( l == 1 ) go to 31\n\n ngp0 = ngp0 + 1\n jigp0 = jigp0 + 1\n igp(jigp0) = izi\n go to 36\n\n31 continue\n\n do jigp1i = jigp1, nxinyi\n if ( izi == igp(jigp1i) ) then\n go to 36\n end if\n end do\n\n ngp1 = ngp1 + 1\n jigp1 = jigp1 - 1\n igp(jigp1) = izi\n\n36 continue\n\n end do\n\n37 continue\n\n end do\n\n38 continue\n\n jngp0 = jngp0 + 1\n ngp(jngp0) = ngp0\n jngp1 = jngp1 - 1\n ngp(jngp1) = ngp1\n\n end do\n!\n! Determine grid points outside the data area.\n! in semi-infinite rectangular area.\n!\n do il0 = 1, nl0\n\n ngp0 = 0\n ngp1 = 0\n il0t3 = il0*3\n ip1 = ipl(il0t3-2)\n ip2 = ipl(il0t3-1)\n x1 = xd(ip1)\n y1 = yd(ip1)\n x2 = xd(ip2)\n y2 = yd(ip2)\n\n xmn = ximn\n xmx = ximx\n ymn = yimn\n ymx = yimx\n\n if ( y2 >= y1 ) then\n xmn = min ( x1, x2 )\n end if\n\n if ( y2 <= y1 ) then\n xmx = max ( x1, x2 )\n end if\n\n if ( x2 <= x1 ) then\n ymn = min ( y1, y2 )\n end if\n\n if ( x2 >= x1 ) then\n ymx = max ( y1, y2 )\n end if\n\n insd = 0\n\n do ixi = 1, nxi\n\n if ( xi(ixi) < xmn .or. xi(ixi) > xmx ) then\n if ( insd == 0 ) then\n go to 42\n end if\n iximx = ixi-1\n go to 43\n end if\n\n if ( insd /= 1 ) then\n insd = 1\n iximn = ixi\n end if\n\n42 continue\n\n end do\n\n if ( insd == 0 ) then\n go to 58\n end if\n\n iximx = nxi\n\n43 continue\n\n do iyi = 1, nyi\n\n yii = yi(iyi)\n\n if ( yii < ymn .or. yii > ymx ) then\n go to 57\n end if\n\n do ixi = iximn,iximx\n\n xii = xi(ixi)\n l = 0\n if( vpdt(x1,y1,x2,y2,xii,yii)<0._KIND_Rdp ) then\n go to 46\n else if( vpdt(x1,y1,x2,y2,xii,yii)==0._KIND_Rdp ) then\n go to 45\n else\n go to 56\n end if\n\n 45 l = 1\n 46 continue\n if( spdt(x2,y2,x1,y1,xii,yii)<0._KIND_Rdp ) then\n go to 56\n else if( spdt(x2,y2,x1,y1,xii,yii)==0._KIND_Rdp ) then\n go to 47\n else\n go to 48\n end if\n 47 l = 1\n\n 48 continue\n if( spdt(x1,y1,x2,y2,xii,yii)<0._KIND_Rdp ) then\n go to 56\n else if( spdt(x1,y1,x2,y2,xii,yii)==0._KIND_Rdp ) then\n go to 49\n else\n go to 50\n end if\n\n 49 l = 1\n 50 izi = nxi*(iyi-1)+ixi\n\n if ( l /= 1 ) then\n ngp0 = ngp0+1\n jigp0 = jigp0+1\n igp(jigp0) = izi\n go to 56\n end if\n\n do jigp1i = jigp1, nxinyi\n if ( izi == igp(jigp1i) ) go to 56\n end do\n\n53 continue\n\n ngp1 = ngp1+1\n jigp1 = jigp1-1\n igp(jigp1) = izi\n\n56 continue\n\n end do\n\n57 continue\n\n end do\n\n58 continue\n\n jngp0 = jngp0+1\n ngp(jngp0) = ngp0\n jngp1 = jngp1-1\n ngp(jngp1) = ngp1\n!\n! In semi-infinite triangular area.\n!\n60 continue\n\n ngp0 = 0\n ngp1 = 0\n ilp1 = mod(il0,nl0)+1\n ilp1t3 = ilp1*3\n ip3 = ipl(ilp1t3-1)\n x3 = xd(ip3)\n y3 = yd(ip3)\n xmn = ximn\n xmx = ximx\n ymn = yimn\n ymx = yimx\n\n if ( y2 <= y3 .and. y1 <= y2 ) then\n xmn = x2\n end if\n\n if ( y3 <= y2 .and. y2 <= y1 ) then\n xmx = x2\n end if\n\n if ( x3 <= x2 .and. x2 <= x1 ) then\n ymn = y2\n end if\n\n if ( x2 <= x3 .and. x1 <= x2 ) then\n ymx = y2\n end if\n\n insd = 0\n\n do ixi = 1, nxi\n\n if ( xi(ixi) < xmn .or. xmx < xi(ixi) ) then\n if ( insd == 0 ) then\n go to 62\n end if\n iximx = ixi - 1\n go to 63\n end if\n\n if ( insd /= 1 ) then\n insd = 1\n iximn = ixi\n end if\n\n62 continue\n\n end do\n\n if ( insd == 0 ) then\n go to 78\n end if\n\n iximx = nxi\n\n63 continue\n\n do iyi = 1, nyi\n\n yii = yi(iyi)\n if ( yii < ymn .or. yii > ymx ) go to 77\n\n do ixi = iximn, iximx\n\n xii = xi(ixi)\n l = 0\n if ( spdt(x1,y1,x2,y2,xii,yii)<0._KIND_Rdp ) then\n go to 66\n else if ( spdt(x1,y1,x2,y2,xii,yii)==0._KIND_Rdp ) then\n go to 65\n else\n go to 76\n end if\n\n 65 l = 1\n 66 continue\n if ( spdt(x3,y3,x2,y2,xii,yii)<0._KIND_Rdp ) then\n go to 70\n else if( spdt(x3,y3,x2,y2,xii,yii)==0._KIND_Rdp ) then\n go to 67\n else\n go to 76\n end if\n\n 67 l = 1\n 70 izi = nxi*(iyi-1)+ixi\n\n if ( l /= 1 ) then\n ngp0 = ngp0+1\n jigp0 = jigp0+1\n igp(jigp0) = izi\n go to 76\n end if\n\n do jigp1i = jigp1, nxinyi\n if ( izi == igp(jigp1i) ) then\n go to 76\n end if\n end do\n\n ngp1 = ngp1+1\n jigp1 = jigp1-1\n igp(jigp1) = izi\n\n76 continue\n\n end do\n\n77 continue\n\n end do\n\n78 continue\n\n jngp0 = jngp0+1\n ngp(jngp0) = ngp0\n jngp1 = jngp1-1\n ngp(jngp1) = ngp1\n\n end do\n\n return\nend subroutine\n\nsubroutine idlctn ( ndp, xd, yd, nt, ipt, nl, ipl, xii, yii, iti )\n\n!*******************************************************************************\n!\n!! IDLCTN finds the triangle that contains a point.\n!\n! Discusstion:\n!\n! IDLCTN determines what triangle a given point (XII, YII) belongs to.\n! When the given point does not lie inside the data area, IDLCTN\n! determines the border line segment when the point lies in an outside\n! rectangular area, and two border line segments when the point\n! lies in an outside triangular area.\n!\n! Modified:\n!\n! 23 January 2003\n!\n! Reference:\n!\n! Hiroshi Akima,\n! Algorithm 526,\n! A Method of Bivariate Interpolation and Smooth Surface Fitting\n! for Values Given at Irregularly Distributed Points,\n! ACM Transactions on Mathematical Software,\n! Volume 4, Number 2, June 1978.\n!\n! Parameters:\n!\n! Input, integer NDP, the number of data points.\n!\n! Input, real ( kind = KIND_Rdp ) XD(NDP), YD(NDP), the X and Y coordinates\n! of the data.\n!\n! Input, integer NT, the number of triangles.\n!\n! Input, integer IPT(3*NT), the point numbers of the vertexes of\n! the triangles,\n!\n! Input, integer NL, the number of border line segments.\n!\n! Input, integer IPL(3*NL), the point numbers of the end points of\n! the border line segments and their respective triangle numbers.\n!\n! Input, real ( kind = KIND_Rdp ) XII, YII, the coordinates of the point\n! to be located.\n!\n! Output, integer ITI, the triangle number, when the point is inside the\n! data area, or two border line segment numbers, il1 and il2,\n! coded to il1*(nt+nl)+il2, when the point is outside the data area.\n!\n! Local parameters:\n!\n! Workspace, integer IWK(18*NDP).\n!\n! Workspace, real ( kind = KIND_Rdp ) WK(8*NDP).\n!\n implicit none\n\n integer ndp\n integer nl\n integer nt\n\n integer i1\n integer i2\n integer i3\n integer idp\n integer idsc(9)\n integer il1\n integer il1t3\n integer il2\n integer ip1\n integer ip2\n integer ip3\n integer ipl(3*nl)\n integer ipt(3*nt)\n integer isc\n integer it0\n integer it0t3\n integer iti\n integer itsc\n integer iwk(18*ndp)\n integer jiwk\n integer jwk\n integer nl0\n integer nt0\n integer ntl\n integer ntsci\n real ( kind = KIND_Rdp ) u1\n real ( kind = KIND_Rdp ) u2\n real ( kind = KIND_Rdp ) u3\n real ( kind = KIND_Rdp ) v1\n real ( kind = KIND_Rdp ) v2\n real ( kind = KIND_Rdp ) v3\n real ( kind = KIND_Rdp ) wk(8*ndp)\n real ( kind = KIND_Rdp ) x0\n real ( kind = KIND_Rdp ) x1\n real ( kind = KIND_Rdp ) x2\n real ( kind = KIND_Rdp ) x3\n real ( kind = KIND_Rdp ) xd(ndp)\n real ( kind = KIND_Rdp ) xii\n real ( kind = KIND_Rdp ) xmn\n real ( kind = KIND_Rdp ) xmx\n real ( kind = KIND_Rdp ) y0\n real ( kind = KIND_Rdp ) y1\n real ( kind = KIND_Rdp ) y2\n real ( kind = KIND_Rdp ) y3\n real ( kind = KIND_Rdp ) yd(ndp)\n real ( kind = KIND_Rdp ) yii\n real ( kind = KIND_Rdp ) ymn\n real ( kind = KIND_Rdp ) ymx\n\n!\n! Preliminary processing\n!\n nt0 = nt\n nl0 = nl\n ntl = nt0+nl0\n x0 = xii\n y0 = yii\n!\n! Processing for a new set of data points\n!\n if ( itipv /= 0 ) then\n go to 30\n end if\n!\n! Divide the x-y plane into nine rectangular sections.\n!\n xmn = xd(1)\n xmx = xd(1)\n ymn = yd(1)\n ymx = yd(1)\n do idp = 2, ndp\n xmn = min ( xd(idp), xmn )\n xmx = max ( xd(idp), xmx )\n ymn = min ( yd(idp), ymn )\n ymx = max ( yd(idp), ymx )\n end do\n\n xs1 = ( xmn + xmn + xmx ) / 3.0D+00\n xs2 = ( xmn + xmx + xmx ) / 3.0D+00\n ys1 = ( ymn + ymn + ymx ) / 3.0D+00\n ys2 = ( ymn + ymx + ymx ) / 3.0D+00\n!\n! Determine and store in the iwk array, triangle numbers of\n! the triangles associated with each of the nine sections.\n!\n ntsc(1:9) = 0\n idsc(1:9) = 0\n\n it0t3 = 0\n jwk = 0\n\n do it0 = 1, nt0\n\n it0t3 = it0t3+3\n i1 = ipt(it0t3-2)\n i2 = ipt(it0t3-1)\n i3 = ipt(it0t3)\n xmn = min ( xd(i1), xd(i2), xd(i3) )\n xmx = max ( xd(i1), xd(i2), xd(i3) )\n ymn = min ( yd(i1), yd(i2), yd(i3) )\n ymx = max ( yd(i1), yd(i2), yd(i3) )\n\n if ( ymn <= ys1 ) then\n\n if ( xmn <= xs1 ) then\n idsc(1) = 1\n end if\n\n if ( xmx>=xs1.and.xmn<=xs2 ) then\n idsc(2) = 1\n end if\n\n if ( xmx>=xs2 ) then\n idsc(3) = 1\n end if\n\n end if\n\n if ( ymx >= ys1 .and. ymn <= ys2 ) then\n if(xmn<=xs1) idsc(4) = 1\n if(xmx>=xs1.and.xmn<=xs2) idsc(5) = 1\n if(xmx>=xs2) idsc(6) = 1\n end if\n\n if ( ymx < ys2) go to 25\n if(xmn<=xs1) idsc(7) = 1\n if(xmx>=xs1.and.xmn<=xs2) idsc(8) = 1\n if(xmx>=xs2) idsc(9) = 1\n\n25 continue\n\n do isc = 1, 9\n if ( idsc(isc) /= 0 ) then\n jiwk = 9*ntsc(isc)+isc\n iwk(jiwk) = it0\n ntsc(isc) = ntsc(isc)+1\n idsc(isc) = 0\n end if\n end do\n!\n! Store in the wk array the minimum and maximum of the X and\n! Y coordinate values for each of the triangle.\n!\n jwk = jwk+4\n wk(jwk-3) = xmn\n wk(jwk-2) = xmx\n wk(jwk-1) = ymn\n wk(jwk) = ymx\n\n end do\n\n go to 60\n!\n! Check if in the same triangle as previous.\n!\n30 continue\n\n it0 = itipv\n\n if(it0>nt0) go to 40\n\n it0t3 = it0*3\n ip1 = ipt(it0t3-2)\n x1 = xd(ip1)\n y1 = yd(ip1)\n ip2 = ipt(it0t3-1)\n x2 = xd(ip2)\n y2 = yd(ip2)\n if(vpdt(x1,y1,x2,y2,x0,y0) < 0.0D+00 ) go to 60\n ip3 = ipt(it0t3)\n x3 = xd(ip3)\n y3 = yd(ip3)\n if(vpdt(x2,y2,x3,y3,x0,y0) < 0.0D+00 ) go to 60\n if(vpdt(x3,y3,x1,y1,x0,y0) < 0.0D+00 ) go to 60\n\n iti = it0\n itipv = it0\n\n return\n!\n! Check if on the same border line segment.\n!\n40 continue\n\n il1 = it0 / ntl\n il2 = it0-il1*ntl\n il1t3 = il1*3\n ip1 = ipl(il1t3-2)\n x1 = xd(ip1)\n y1 = yd(ip1)\n ip2 = ipl(il1t3-1)\n x2 = xd(ip2)\n y2 = yd(ip2)\n if(il2/=il1) go to 50\n if(spdt(x1,y1,x2,y2,x0,y0) < 0.0D+00 ) go to 60\n if(spdt(x2,y2,x1,y1,x0,y0) < 0.0D+00 ) go to 60\n if(vpdt(x1,y1,x2,y2,x0,y0) > 0.0D+00 ) go to 60\n\n iti = it0\n itipv = it0\n\n return\n!\n! Check if between the same two border line segments.\n!\n50 continue\n\n if(spdt(x1,y1,x2,y2,x0,y0) > 0.0D+00 ) go to 60\n\n ip3 = ipl(3*il2-1)\n x3 = xd(ip3)\n y3 = yd(ip3)\n\n if ( spdt(x3,y3,x2,y2,x0,y0) <= 0.0D+00 ) then\n iti = it0\n itipv = it0\n return\n end if\n!\n! Locate inside the data area.\n! Determine the section in which the point in question lies.\n!\n60 continue\n\n isc = 1\n\n if ( x0 >= xs1 ) then\n isc = isc+1\n end if\n\n if ( x0 >= xs2 ) then\n isc = isc+1\n end if\n\n if ( y0 >= ys1 ) then\n isc = isc+3\n end if\n\n if ( y0 >= ys2 ) then\n isc = isc+3\n end if\n!\n! Search through the triangles associated with the section.\n!\n ntsci = ntsc(isc)\n if(ntsci<=0) go to 70\n jiwk = -9+isc\n\n do itsc = 1, ntsci\n\n jiwk = jiwk+9\n it0 = iwk(jiwk)\n jwk = it0*4\n if(x0wk(jwk-2)) go to 61\n if(y0wk(jwk)) go to 61\n it0t3 = it0*3\n ip1 = ipt(it0t3-2)\n x1 = xd(ip1)\n y1 = yd(ip1)\n ip2 = ipt(it0t3-1)\n x2 = xd(ip2)\n y2 = yd(ip2)\n if(vpdt(x1,y1,x2,y2,x0,y0)<0.0D+00 ) go to 61\n ip3 = ipt(it0t3)\n x3 = xd(ip3)\n y3 = yd(ip3)\n\n if ( vpdt(x2,y2,x3,y3,x0,y0) >= 0.0D+00 ) then\n\n if ( vpdt(x3,y3,x1,y1,x0,y0) >= 0.0D+00 ) then\n iti = it0\n itipv = it0\n return\n end if\n\n end if\n\n61 continue\n\n end do\n!\n! Locate outside the data area.\n!\n70 continue\n\n do il1 = 1, nl0\n\n il1t3 = il1*3\n ip1 = ipl(il1t3-2)\n x1 = xd(ip1)\n y1 = yd(ip1)\n ip2 = ipl(il1t3-1)\n x2 = xd(ip2)\n y2 = yd(ip2)\n if(spdt(x2,y2,x1,y1,x0,y0)<0.0D+00 ) go to 72\n if(spdt(x1,y1,x2,y2,x0,y0)<0.0D+00 ) go to 71\n if(vpdt(x1,y1,x2,y2,x0,y0)>0.0D+00 ) go to 72\n il2 = il1\n go to 75\n\n 71 continue\n\n il2 = mod(il1,nl0)+1\n ip3 = ipl(3*il2-1)\n x3 = xd(ip3)\n y3 = yd(ip3)\n if(spdt(x3,y3,x2,y2,x0,y0)<=0.0D+00 ) go to 75\n\n 72 continue\n\n end do\n\n it0 = 1\n iti = it0\n itipv = it0\n\n return\n\n 75 continue\n\n it0 = il1*ntl+il2\n iti = it0\n itipv = it0\n\n return\nend subroutine\n\nsubroutine idpdrv ( ndp, xd, yd, zd, nt, ipt, pd, wk )\n\n!*******************************************************************************\n!\n!! IDPDRV estimates first and second partial derivatives at data points.\n!\n! Modified:\n!\n! 04 June 2003\n!\n! Reference:\n!\n! Hiroshi Akima,\n! Algorithm 526,\n! A Method of Bivariate Interpolation and Smooth Surface Fitting\n! for Values Given at Irregularly Distributed Points,\n! ACM Transactions on Mathematical Software,\n! Volume 4, Number 2, June 1978.\n!\n! Parameters:\n!\n! Input, integer NDP, the number of data points.\n!\n! Input, real ( kind = KIND_Rdp ) XD(NDP), YD(NDP), the X and Y coordinates\n! of the data.\n!\n! Input, real ( kind = KIND_Rdp ) ZD(NDP), the data values.\n!\n! Input, integer NT, the number of triangles.\n!\n! Input, integer IPT(3*NT), the point numbers of the vertexes of the\n! triangles.\n!\n! Output, real ( kind = KIND_Rdp ) PD(5*NDP), the estimated zx, zy, zxx, zxy,\n! and zyy values at the ith data point are to be stored as the\n! (5*i-4)th, (5*i-3)rd, (5*i-2)nd, (5*i-1)st and (5*i)th elements,\n! respectively, where i = 1, 2, ..., ndp.\n!\n! Workspace, real ( kind = KIND_Rdp ) WK(NDP).\n!\n implicit none\n\n integer ndp\n integer nt\n\n real ( kind = KIND_Rdp ) d12\n real ( kind = KIND_Rdp ) d23\n real ( kind = KIND_Rdp ) d31\n real ( kind = KIND_Rdp ) dx1\n real ( kind = KIND_Rdp ) dx2\n real ( kind = KIND_Rdp ) dy1\n real ( kind = KIND_Rdp ) dy2\n real ( kind = KIND_Rdp ) dz1\n real ( kind = KIND_Rdp ) dz2\n real ( kind = KIND_Rdp ) dzx1\n real ( kind = KIND_Rdp ) dzx2\n real ( kind = KIND_Rdp ) dzy1\n real ( kind = KIND_Rdp ) dzy2\n integer idp\n integer ipt(3*nt)\n integer ipti(3)\n integer it\n integer iv\n integer jpd0\n integer jpdmx\n integer jpt\n integer jpt0\n integer nt0\n real ( kind = KIND_Rdp ) pd(5*ndp)\n real ( kind = KIND_Rdp ) vpx\n real ( kind = KIND_Rdp ) vpxx\n real ( kind = KIND_Rdp ) vpxy\n real ( kind = KIND_Rdp ) vpy\n real ( kind = KIND_Rdp ) vpyx\n real ( kind = KIND_Rdp ) vpyy\n real ( kind = KIND_Rdp ) vpz\n real ( kind = KIND_Rdp ) vpzmn\n real ( kind = KIND_Rdp ) w1(3)\n real ( kind = KIND_Rdp ) w2(3)\n real ( kind = KIND_Rdp ) wi\n real ( kind = KIND_Rdp ) wk(ndp)\n real ( kind = KIND_Rdp ) xd(ndp)\n real ( kind = KIND_Rdp ) xv(3)\n real ( kind = KIND_Rdp ) yd(ndp)\n real ( kind = KIND_Rdp ) yv(3)\n real ( kind = KIND_Rdp ) zd(ndp)\n real ( kind = KIND_Rdp ) zv(3)\n real ( kind = KIND_Rdp ) zxv(3)\n real ( kind = KIND_Rdp ) zyv(3)\n!\n! Preliminary processing.\n!\n nt0 = nt\n!\n! Clear the PD array.\n!\n jpdmx = 5*ndp\n\n pd(1:jpdmx) = 0.0D+00\n\n wk(1:ndp) = 0.0D+00\n!\n! Estimate ZX and ZY.\n!\n do it = 1, nt0\n\n jpt0 = 3*(it-1)\n\n do iv = 1, 3\n jpt = jpt0+iv\n idp = ipt(jpt)\n ipti(iv) = idp\n xv(iv) = xd(idp)\n yv(iv) = yd(idp)\n zv(iv) = zd(idp)\n end do\n\n dx1 = xv(2)-xv(1)\n dy1 = yv(2)-yv(1)\n dz1 = zv(2)-zv(1)\n dx2 = xv(3)-xv(1)\n dy2 = yv(3)-yv(1)\n dz2 = zv(3)-zv(1)\n vpx = dy1*dz2-dz1*dy2\n vpy = dz1*dx2-dx1*dz2\n vpz = dx1*dy2-dy1*dx2\n vpzmn = abs ( dx1*dx2+dy1*dy2 )* epsilon ( vpzmn )\n\n if ( vpzmn < abs ( vpz ) ) then\n\n d12 = sqrt((xv(2)-xv(1))**2+(yv(2)-yv(1))**2)\n d23 = sqrt((xv(3)-xv(2))**2+(yv(3)-yv(2))**2)\n d31 = sqrt((xv(1)-xv(3))**2+(yv(1)-yv(3))**2)\n w1(1) = 1.0D+00 / (d31*d12)\n w1(2) = 1.0D+00 / (d12*d23)\n w1(3) = 1.0D+00 / (d23*d31)\n w2(1) = vpz*w1(1)\n w2(2) = vpz*w1(2)\n w2(3) = vpz*w1(3)\n\n do iv = 1, 3\n idp = ipti(iv)\n jpd0 = 5*(idp-1)\n wi = (w1(iv)**2)*w2(iv)\n pd(jpd0+1) = pd(jpd0+1)+vpx*wi\n pd(jpd0+2) = pd(jpd0+2)+vpy*wi\n wk(idp) = wk(idp)+vpz*wi\n end do\n\n end if\n\n end do\n\n do idp = 1, ndp\n jpd0 = 5*(idp-1)\n pd(jpd0+1) = -pd(jpd0+1)/wk(idp)\n pd(jpd0+2) = -pd(jpd0+2)/wk(idp)\n end do\n!\n! Estimate ZXX, ZXY, and ZYY.\n!\n do it = 1, nt0\n\n jpt0 = 3*(it-1)\n\n do iv = 1, 3\n jpt = jpt0+iv\n idp = ipt(jpt)\n ipti(iv) = idp\n xv(iv) = xd(idp)\n yv(iv) = yd(idp)\n jpd0 = 5*(idp-1)\n zxv(iv) = pd(jpd0+1)\n zyv(iv) = pd(jpd0+2)\n end do\n\n dx1 = xv(2)-xv(1)\n dy1 = yv(2)-yv(1)\n dzx1 = zxv(2)-zxv(1)\n dzy1 = zyv(2)-zyv(1)\n dx2 = xv(3)-xv(1)\n dy2 = yv(3)-yv(1)\n dzx2 = zxv(3)-zxv(1)\n dzy2 = zyv(3)-zyv(1)\n vpxx = dy1*dzx2-dzx1*dy2\n vpxy = dzx1*dx2-dx1*dzx2\n vpyx = dy1*dzy2-dzy1*dy2\n vpyy = dzy1*dx2-dx1*dzy2\n vpz = dx1*dy2-dy1*dx2\n vpzmn = abs ( dx1 * dx2 + dy1 * dy2 ) * epsilon ( vpzmn )\n\n if ( abs(vpz) > vpzmn ) then\n\n d12 = sqrt((xv(2)-xv(1))**2+(yv(2)-yv(1))**2)\n d23 = sqrt((xv(3)-xv(2))**2+(yv(3)-yv(2))**2)\n d31 = sqrt((xv(1)-xv(3))**2+(yv(1)-yv(3))**2)\n w1(1) = 1.0D+00 /(d31*d12)\n w1(2) = 1.0D+00 /(d12*d23)\n w1(3) = 1.0D+00 /(d23*d31)\n w2(1) = vpz*w1(1)\n w2(2) = vpz*w1(2)\n w2(3) = vpz*w1(3)\n\n do iv = 1, 3\n idp = ipti(iv)\n jpd0 = 5*(idp-1)\n wi = (w1(iv)**2)*w2(iv)\n pd(jpd0+3) = pd(jpd0+3)+vpxx*wi\n pd(jpd0+4) = pd(jpd0+4)+(vpxy+vpyx)*wi\n pd(jpd0+5) = pd(jpd0+5)+vpyy*wi\n end do\n\n end if\n\n end do\n\n do idp = 1, ndp\n jpd0 = 5*(idp-1)\n pd(jpd0+3) = -pd(jpd0+3) / wk(idp)\n pd(jpd0+4) = -pd(jpd0+4) / (2.0*wk(idp))\n pd(jpd0+5) = -pd(jpd0+5) / wk(idp)\n end do\n\n return\nend subroutine\n\nsubroutine idptip ( ndp,xd, yd, zd, nt, ipt, nl, ipl, pdd, iti, xii, yii, zii )\n\n!*******************************************************************************\n!\n!! IDPTIP performs interpolation, determining a value of Z given X and Y.\n!\n! Modified:\n!\n! 19 February 2001\n!\n! Reference:\n!\n! Hiroshi Akima,\n! Algorithm 526,\n! A Method of Bivariate Interpolation and Smooth Surface Fitting\n! for Values Given at Irregularly Distributed Points,\n! ACM Transactions on Mathematical Software,\n! Volume 4, Number 2, June 1978.\n!\n! Parameters:\n!\n! Input, integer NDP, the number of data values.\n!\n! Input, real ( kind = KIND_Rdp ) XD(NDP), YD(NDP), the X and Y coordinates\n! of the data.\n!\n! Input, real ( kind = KIND_Rdp ) ZD(NDP), the data values.\n!\n! Input, integer NT, the number of triangles.\n!\n! Input, integer IPT(3*NT), the point numbers of the vertexes of\n! the triangles.\n!\n! Input, integer NL, the number of border line segments.\n!\n! Input, integer IPL(3*NL), the point numbers of the end points of the\n! border line segments and their respective triangle numbers,\n!\n! Input, real ( kind = KIND_Rdp ) PDD(5*NDP). the partial derivatives at\n! the data points,\n!\n! Input, integer ITI, triangle number of the triangle in which lies\n! the point for which interpolation is to be performed,\n!\n! Input, real ( kind = KIND_Rdp ) XII, YII, the X and Y coordinates of the\n! point for which interpolation is to be performed.\n!\n! Output, real ( kind = KIND_Rdp ) ZII, the interpolated Z value.\n!\n implicit none\n\n integer ndp\n integer nl\n integer nt\n\n real ( kind = KIND_Rdp ) a\n real ( kind = KIND_Rdp ) aa\n real ( kind = KIND_Rdp ) ab\n real ( kind = KIND_Rdp ) ac\n real ( kind = KIND_Rdp ) act2\n real ( kind = KIND_Rdp ) ad\n real ( kind = KIND_Rdp ) adbc\n real ( kind = KIND_Rdp ) b\n real ( kind = KIND_Rdp ) bb\n real ( kind = KIND_Rdp ) bc\n real ( kind = KIND_Rdp ) bdt2\n real ( kind = KIND_Rdp ) c\n real ( kind = KIND_Rdp ) cc\n real ( kind = KIND_Rdp ) cd\n real ( kind = KIND_Rdp ) csuv\n real ( kind = KIND_Rdp ) d\n real ( kind = KIND_Rdp ) dd\n real ( kind = KIND_Rdp ) dlt\n real ( kind = KIND_Rdp ) dx\n real ( kind = KIND_Rdp ) dy\n real ( kind = KIND_Rdp ) g1\n real ( kind = KIND_Rdp ) g2\n real ( kind = KIND_Rdp ) h1\n real ( kind = KIND_Rdp ) h2\n real ( kind = KIND_Rdp ) h3\n integer i\n integer idp\n integer il1\n integer il2\n integer ipl(3*nl)\n integer ipt(3*nt)\n integer it0\n integer iti\n integer jipl\n integer jipt\n integer jpd\n integer jpdd\n integer kpd\n integer ntl\n real ( kind = KIND_Rdp ) lu\n real ( kind = KIND_Rdp ) lv\n real ( kind = KIND_Rdp ) p0\n real ( kind = KIND_Rdp ) p1\n real ( kind = KIND_Rdp ) p2\n real ( kind = KIND_Rdp ) p3\n real ( kind = KIND_Rdp ) p4\n real ( kind = KIND_Rdp ) p5\n real ( kind = KIND_Rdp ) pd(15)\n real ( kind = KIND_Rdp ) pdd(5*ndp)\n real ( kind = KIND_Rdp ) thsv\n real ( kind = KIND_Rdp ) thus\n real ( kind = KIND_Rdp ) thuv\n real ( kind = KIND_Rdp ) thxu\n real ( kind = KIND_Rdp ) u\n real ( kind = KIND_Rdp ) v\n real ( kind = KIND_Rdp ) x(3)\n real ( kind = KIND_Rdp ) xd(*)\n real ( kind = KIND_Rdp ) xii\n real ( kind = KIND_Rdp ) y(3)\n real ( kind = KIND_Rdp ) yd(*)\n real ( kind = KIND_Rdp ) yii\n real ( kind = KIND_Rdp ) z(3)\n real ( kind = KIND_Rdp ) z0\n real ( kind = KIND_Rdp ) zd(*)\n real ( kind = KIND_Rdp ) zii\n real ( kind = KIND_Rdp ) zu(3)\n real ( kind = KIND_Rdp ) zuu(3)\n real ( kind = KIND_Rdp ) zuv(3)\n real ( kind = KIND_Rdp ) zv(3)\n real ( kind = KIND_Rdp ) zvv(3)\n\n!\n! Preliminary processing\n!\n it0 = iti\n ntl = nt+nl\n\n if ( ntl < it0 ) then\n il1 = it0/ntl\n il2 = it0-il1*ntl\n if(il1==il2) go to 40\n go to 60\n end if\n!\n! Calculation of ZII by interpolation.\n! Check if the necessary coefficients have been calculated.\n!\n if ( it0 == itpv ) then\n go to 30\n end if\n!\n! Load coordinate and partial derivative values at the vertexes.\n!\n jipt = 3*(it0-1)\n jpd = 0\n\n do i = 1, 3\n\n jipt = jipt+1\n idp = ipt(jipt)\n x(i) = xd(idp)\n y(i) = yd(idp)\n z(i) = zd(idp)\n jpdd = 5*(idp-1)\n\n do kpd = 1, 5\n jpd = jpd+1\n jpdd = jpdd+1\n pd(jpd) = pdd(jpdd)\n end do\n\n end do\n!\n! Determine the coefficients for the coordinate system\n! transformation from the XY system to the UV system and vice versa.\n!\n x0 = x(1)\n y0 = y(1)\n a = x(2)-x0\n b = x(3)-x0\n c = y(2)-y0\n d = y(3)-y0\n ad = a*d\n bc = b*c\n dlt = ad-bc\n ap = d/dlt\n bp = -b/dlt\n cp = -c/dlt\n dp = a/dlt\n!\n! Convert the partial derivatives at the vertexes of the\n! triangle for the UV coordinate system.\n!\n aa = a*a\n act2 = 2.0D+00 *a*c\n cc = c*c\n ab = a*b\n adbc = ad+bc\n cd = c*d\n bb = b*b\n bdt2 = 2.0D+00 *b*d\n dd = d*d\n\n do i = 1, 3\n jpd = 5*i\n zu(i) = a*pd(jpd-4)+c*pd(jpd-3)\n zv(i) = b*pd(jpd-4)+d*pd(jpd-3)\n zuu(i) = aa*pd(jpd-2)+act2*pd(jpd-1)+cc*pd(jpd)\n zuv(i) = ab*pd(jpd-2)+adbc*pd(jpd-1)+cd*pd(jpd)\n zvv(i) = bb*pd(jpd-2)+bdt2*pd(jpd-1)+dd*pd(jpd)\n end do\n!\n! Calculate the coefficients of the polynomial.\n!\n p00 = z(1)\n p10 = zu(1)\n p01 = zv(1)\n p20 = 0.5D+00 * zuu(1)\n p11 = zuv(1)\n p02 = 0.5D+00 * zvv(1)\n h1 = z(2)-p00-p10-p20\n h2 = zu(2)-p10-zuu(1)\n h3 = zuu(2)-zuu(1)\n p30 = 10.0D+00 * h1 - 4.0D+00 * h2 + 0.5D+00 * h3\n p40 = -15.0D+00 * h1 + 7.0D+00 * h2 - h3\n p50 = 6.0D+00 * h1 - 3.0D+00 * h2 + 0.5D+00 * h3\n h1 = z(3)-p00-p01-p02\n h2 = zv(3)-p01-zvv(1)\n h3 = zvv(3)-zvv(1)\n p03 = 10.0D+00 * h1 - 4.0D+00 * h2 + 0.5D+00 * h3\n p04 = -15.0D+00 * h1 + 7.0D+00 * h2 -h3\n p05 = 6.0D+00 * h1 - 3.0D+00 * h2 + 0.5D+00 * h3\n lu = sqrt(aa+cc)\n lv = sqrt(bb+dd)\n thxu = atan2(c,a)\n thuv = atan2(d,b)-thxu\n csuv = cos(thuv)\n p41 = 5.0D+00*lv*csuv/lu*p50\n p14 = 5.0D+00*lu*csuv/lv*p05\n h1 = zv(2)-p01-p11-p41\n h2 = zuv(2)-p11-4.0D+00 * p41\n p21 = 3.0D+00 * h1-h2\n p31 = -2.0D+00 * h1+h2\n h1 = zu(3)-p10-p11-p14\n h2 = zuv(3)-p11- 4.0D+00 * p14\n p12 = 3.0D+00 * h1-h2\n p13 = -2.0D+00 * h1+h2\n thus = atan2(d-c,b-a)-thxu\n thsv = thuv-thus\n aa = sin(thsv)/lu\n bb = -cos(thsv)/lu\n cc = sin(thus)/lv\n dd = cos(thus)/lv\n ac = aa*cc\n ad = aa*dd\n bc = bb*cc\n g1 = aa * ac*(3.0D+00*bc+2.0D+00*ad)\n g2 = cc * ac*(3.0D+00*ad+2.0D+00*bc)\n h1 = -aa*aa*aa*(5.0D+00*aa*bb*p50+(4.0D+00*bc+ad)*p41) &\n -cc*cc*cc*(5.0D+00*cc*dd*p05+(4.0D+00*ad+bc)*p14)\n h2 = 0.5D+00 * zvv(2)-p02-p12\n h3 = 0.5D+00 * zuu(3)-p20-p21\n p22 = (g1*h2+g2*h3-h1)/(g1+g2)\n p32 = h2-p22\n p23 = h3-p22\n itpv = it0\n!\n! Convert XII and YII to UV system.\n!\n30 continue\n\n dx = xii-x0\n dy = yii-y0\n u = ap*dx+bp*dy\n v = cp*dx+dp*dy\n!\n! Evaluate the polynomial.\n!\n p0 = p00+v*(p01+v*(p02+v*(p03+v*(p04+v*p05))))\n p1 = p10+v*(p11+v*(p12+v*(p13+v*p14)))\n p2 = p20+v*(p21+v*(p22+v*p23))\n p3 = p30+v*(p31+v*p32)\n p4 = p40+v*p41\n p5 = p50\n zii = p0+u*(p1+u*(p2+u*(p3+u*(p4+u*p5))))\n return\n!\n! Calculation of ZII by extrapolation in the rectangle.\n! Check if the necessary coefficients have been calculated.\n!\n40 continue\n\n if ( it0 == itpv ) then\n go to 50\n end if\n!\n! Load coordinate and partial derivative values at the end\n! points of the border line segment.\n!\n jipl = 3*(il1-1)\n jpd = 0\n\n do i = 1, 2\n\n jipl = jipl+1\n idp = ipl(jipl)\n x(i) = xd(idp)\n y(i) = yd(idp)\n z(i) = zd(idp)\n jpdd = 5*(idp-1)\n\n do kpd = 1, 5\n jpd = jpd+1\n jpdd = jpdd+1\n pd(jpd) = pdd(jpdd)\n end do\n\n end do\n!\n! Determine the coefficients for the coordinate system\n! transformation from the XY system to the UV system\n! and vice versa.\n!\n x0 = x(1)\n y0 = y(1)\n a = y(2)-y(1)\n b = x(2)-x(1)\n c = -b\n d = a\n ad = a * d\n bc = b * c\n dlt = ad - bc\n ap = d / dlt\n bp = -b / dlt\n cp = -bp\n dp = ap\n!\n! Convert the partial derivatives at the end points of the\n! border line segment for the UV coordinate system.\n!\n aa = a*a\n act2 = 2.0D+00 * a * c\n cc = c*c\n ab = a*b\n adbc = ad+bc\n cd = c*d\n bb = b*b\n bdt2 = 2.0D+00 * b * d\n dd = d*d\n\n do i = 1, 2\n jpd = 5*i\n zu(i) = a*pd(jpd-4)+c*pd(jpd-3)\n zv(i) = b*pd(jpd-4)+d*pd(jpd-3)\n zuu(i) = aa*pd(jpd-2)+act2*pd(jpd-1)+cc*pd(jpd)\n zuv(i) = ab*pd(jpd-2)+adbc*pd(jpd-1)+cd*pd(jpd)\n zvv(i) = bb*pd(jpd-2)+bdt2*pd(jpd-1)+dd*pd(jpd)\n end do\n!\n! Calculate the coefficients of the polynomial.\n!\n p00 = z(1)\n p10 = zu(1)\n p01 = zv(1)\n p20 = 0.5D+00 * zuu(1)\n p11 = zuv(1)\n p02 = 0.5D+00 * zvv(1)\n\n h1 = z(2)-p00-p01-p02\n h2 = zv(2)-p01-zvv(1)\n h3 = zvv(2)-zvv(1)\n\n p03 = 10.0D+00 * h1 - 4.0D+00*h2+0.5D+00*h3\n p04 = -15.0D+00 * h1 + 7.0D+00*h2 -h3\n p05 = 6.0D+00 * h1 - 3.0D+00*h2+0.5D+00*h3\n\n h1 = zu(2)-p10-p11\n h2 = zuv(2)-p11\n\n p12 = 3.0D+00*h1-h2\n p13 = -2.0D+00*h1+h2\n p21 = 0.0D+00\n p23 = -zuu(2)+zuu(1)\n p22 = -1.5D+00*p23\n\n itpv = it0\n!\n! Convert XII and YII to UV system.\n!\n50 continue\n\n dx = xii-x0\n dy = yii-y0\n u = ap*dx+bp*dy\n v = cp*dx+dp*dy\n!\n! Evaluate the polynomial.\n!\n p0 = p00+v*(p01+v*(p02+v*(p03+v*(p04+v*p05))))\n p1 = p10+v*(p11+v*(p12+v*p13))\n p2 = p20+v*(p21+v*(p22+v*p23))\n zii = p0+u*(p1+u*p2)\n\n return\n!\n! Calculation of ZII by extrapolation in the triangle.\n! Check if the necessary coefficients have been calculated.\n!\n60 continue\n\n if ( it0 /= itpv ) then\n!\n! Load coordinate and partial derivative values at the vertex of the triangle.\n!\n jipl = 3*il2-2\n idp = ipl(jipl)\n x0 = xd(idp)\n y0 = yd(idp)\n z0 = zd(idp)\n jpdd = 5*(idp-1)\n\n do kpd = 1, 5\n jpdd = jpdd+1\n pd(kpd) = pdd(jpdd)\n end do\n!\n! Calculate the coefficients of the polynomial.\n!\n p00 = z0\n p10 = pd(1)\n p01 = pd(2)\n p20 = 0.5D+00*pd(3)\n p11 = pd(4)\n p02 = 0.5D+00*pd(5)\n itpv = it0\n\n end if\n!\n! Convert XII and YII to UV system.\n!\n u = xii-x0\n v = yii-y0\n!\n! Evaluate the polynomial.\n!\n p0 = p00+v*(p01+v*p02)\n p1 = p10+v*p11\n zii = p0+u*(p1+u*p20)\n\n return\nend subroutine\n\nsubroutine idsfft ( md, ndp, xd, yd, zd, nxi, nyi, nzi, xi, yi, zi , &\n errint , errmsg )\n\n!*******************************************************************************\n!\n!! IDSFFT fits a smooth surface Z(X,Y) given irregular (X,Y,Z) data.\n!\n! Discussion:\n!\n! IDSFFT performs smooth surface fitting when the projections of the\n! data points in the (X,Y) plane are irregularly distributed.\n!\n! Special conditions:\n!\n! The data points must be distinct and their projections in the XY\n! plane must not be collinear, otherwise an error return occurs.\n!\n! Reference:\n!\n! Hiroshi Akima,\n! Algorithm 526,\n! A Method of Bivariate Interpolation and Smooth Surface Fitting\n! for Values Given at Irregularly Distributed Points,\n! ACM Transactions on Mathematical Software,\n! Volume 4, Number 2, June 1978.\n!\n! Parameters:\n!\n! Input, integer MD, mode of computation (must be 1, 2, or 3,\n! else an error return will occur).\n!\n! 1, if this is the first call to this routine, or if the value of\n! NDP has been changed from the previous call, or if the contents of\n! the XD or YD arrays have been changed from the previous call.\n!\n! 2, if the values of NDP and the XD, YD arrays are unchanged from\n! the previous call, but new values for XI, YI are being used. If\n! MD = 2 and NDP has been changed since the previous call to IDSFFT,\n! an error return occurs.\n!\n! 3, if the values of NDP, NXI, NYI, XD, YD, XI, YI are unchanged\n! from the previous call, i.e. if the only change on input to idsfft\n! is in the ZD array. If MD = 3 and NDP, nxi or nyi has been changed\n! since the previous call to idsfft, an error return occurs.\n!\n! Between the call with MD = 2 or MD = 3 and the preceding call, the\n! iwk and wk work arrays should not be disturbed.\n!\n! Input, integer NDP, the number of data points. NDP must be at least 4.\n!\n! Input, real ( kind = KIND_Rdp ) XD(NDP), YD(NDP), the X and Y coordinates\n! of the data.\n!\n! Input, real ( kind = KIND_Rdp ) ZD(NDP), the data values.\n!\n! Input, integer NXI, NYI, the number of output grid points in the\n! X and Y directions. NXI and NYI must each be at least 1.\n!\n! Input, integer NZI, the first dimension of ZI. NZI must be at\n! least NXI.\n!\n! Input, real ( kind = KIND_Rdp ) XI(NXI), YI(NYI), the X and Y coordinates\n! of the grid points.\n!\n! Output, real ( kind = KIND_Rdp ) ZI(NZI,NYI), contains the interpolated Z\n! values at the grid points.\n!\n! Local parameters:\n!\n! Workspace, integer IWK(31*NDP+NXI*NYI).\n!\n! Workspace, real ( kind = KIND_Rdp ) WK(6*NDP).\n!\n implicit none\n\n integer ndp\n integer nxi\n integer nyi\n integer nzi\n\n integer il1\n integer il2\n integer iti\n integer iwk(31*ndp + nxi*nyi)\n integer ixi\n integer iyi\n integer izi\n integer jig0mn\n integer jig0mx\n integer jig1mn\n integer jig1mx\n integer jigp\n integer jngp\n integer jwigp\n integer jwigp0\n integer jwipl\n integer jwipt\n integer jwiwl\n integer jwiwp\n integer jwngp\n integer jwngp0\n integer jwwpd\n integer md\n integer ngp0\n integer ngp1\n integer nl\n integer nngp\n integer nt\n integer errint\n character ( len = * ) errmsg\n optional errint,errmsg\n real ( kind = KIND_Rdp ) wk(6*ndp)\n real ( kind = KIND_Rdp ) xd(ndp)\n real ( kind = KIND_Rdp ) xi(nxi)\n real ( kind = KIND_Rdp ) yd(ndp)\n real ( kind = KIND_Rdp ) yi(nyi)\n real ( kind = KIND_Rdp ) zd(ndp)\n real ( kind = KIND_Rdp ) zi(nzi,nyi)\n\n!\n! Error check.\n!\n IF( PRESENT(errmsg) )errmsg = \"\"\n IF( PRESENT(errint) )errint = 0\n if ( md < 1 .or. 3 < md ) then\n if( present(errint) )errint = -1\n if( present(errmsg) )then\n write (errmsg, '(a,i1,a)' )'Input parameter MD=',MD,&\n ' out of range. Should be 1-3. [LIB_BiVar:IDSFFT]'\n end if\n return\n end if\n\n if ( ndp < 4 ) then\n if( present(errint) )errint = -2\n if( present(errmsg) )then\n write (errmsg, '(a,i7,a)' )'Input parameter NDP=',NDP,&\n ' less than minimum number of data points of 4. [LIB_BiVar:IDSFFT]'\n end if\n return\n end if\n\n if ( nxi < 1 .or. nyi < 1 ) then\n if( present(errint) )errint = -3\n if( present(errmsg) )then\n write (errmsg, '(a,i7,1x,i7,a)' )'Input parameter NXI,NYI=',NXI,NYI,&\n ' are out of range. [LIB_BiVar:IDSFFT]'\n end if\n return\n end if\n\n if ( nxi > nzi ) then\n if( present(errint) )errint = -4\n if( present(errmsg) )then\n write (errmsg, '(a,i7,1x,i7,a)' )'Input parameter NZI,NXI=',NZI,NXI,&\n ' are out of range: NZI\",ndp,\" [LIB_BiVar:IDSFFT]\"\n end if\n return\n end if\n\n end if\n\n if ( md <= 2 ) then\n\n iwk(3) = nxi\n iwk(4) = nyi\n\n else\n\n if ( nxi /= iwk(3) ) then\n if( present(errint) )errint = -6\n if( present(errmsg) )then\n write (errmsg, '(a,i1,a,i7,a2,i7,a)' )'IDSFFT - Fatal error! Input parameter MD=',MD,&\n ' but NXI was changed since last call: ',iwk(3),\"=>\",nxi,\"[LIB_BiVar:IDSFFT]\"\n end if\n return\n end if\n\n if ( nyi /= iwk(4) ) then\n if( present(errint) )errint = -7\n if( present(errmsg) )then\n write (errmsg, '(a,i1,a,i7,a2,i7,a)' )'IDSFFT - Fatal error! Input parameter MD=',MD,&\n ' but NYI was changed since last call: ',iwk(4),\"=>\",nyi,\"[LIB_BiVar:IDSFFT]\"\n end if\n return\n end if\n\n end if\n!\n! Allocation of storage areas in the IWK array.\n!\n jwipt = 16\n jwiwl = 6*ndp+1\n jwngp0 = jwiwl-1\n jwipl = 24*ndp+1\n jwiwp = 30*ndp+1\n jwigp0 = 31*ndp\n jwwpd = 5*ndp+1\n!\n! Triangulate the XY plane.\n!\n if ( md == 1 ) then\n\n call idtang ( ndp, xd, yd, nt, iwk(jwipt), nl, iwk(jwipl), &\n iwk(jwiwl), iwk(jwiwp), wk )\n\n iwk(5) = nt\n iwk(6) = nl\n\n if ( nt == 0 ) then\n return\n end if\n\n else\n\n nt = iwk(5)\n nl = iwk(6)\n\n end if\n!\n! Sort output grid points in ascending order of the triangle\n! number and the border line segment number.\n!\n if ( md <= 2 ) then\n\n call idgrid ( xd, yd, nt, iwk(jwipt), nl, iwk(jwipl), nxi, &\n nyi, xi, yi, iwk(jwngp0+1), iwk(jwigp0+1) )\n\n end if\n!\n! Estimate partial derivatives at all data points.\n!\n call idpdrv ( ndp, xd, yd, zd, nt, iwk(jwipt), wk, wk(jwwpd) )\n!\n! Interpolate the ZI values.\n!\n itpv = 0\n jig0mx = 0\n jig1mn = nxi * nyi + 1\n nngp = nt + 2 * nl\n\n do jngp = 1, nngp\n\n iti = jngp\n\n if ( jngp > nt ) then\n il1 = (jngp-nt+1)/2\n il2 = (jngp-nt+2)/2\n if ( nl < il2 ) then\n il2 = 1\n end if\n iti = il1*(nt+nl)+il2\n end if\n\n jwngp = jwngp0+jngp\n ngp0 = iwk(jwngp)\n\n if ( ngp0 /= 0 ) then\n\n jig0mn = jig0mx+1\n jig0mx = jig0mx+ngp0\n\n do jigp = jig0mn, jig0mx\n\n jwigp = jwigp0+jigp\n izi = iwk(jwigp)\n iyi = (izi-1)/nxi+1\n ixi = izi-nxi*(iyi-1)\n\n call idptip ( ndp, xd, yd, zd, nt, iwk(jwipt), nl, iwk(jwipl), &\n wk, iti, xi(ixi), yi(iyi), zi(ixi,iyi) )\n\n end do\n\n end if\n\n jwngp = jwngp0+2*nngp+1-jngp\n ngp1 = iwk(jwngp)\n\n if ( ngp1 /= 0 ) then\n\n jig1mx = jig1mn-1\n jig1mn = jig1mn-ngp1\n\n do jigp = jig1mn, jig1mx\n\n jwigp = jwigp0+jigp\n izi = iwk(jwigp)\n iyi = (izi-1)/nxi+1\n ixi = izi-nxi*(iyi-1)\n\n call idptip ( ndp, xd, yd, zd, nt, iwk(jwipt), nl, iwk(jwipl), &\n wk, iti, xi(ixi), yi(iyi), zi(ixi,iyi) )\n\n end do\n\n end if\n\n end do\n\n return\nend subroutine\n\nsubroutine idtang ( ndp, xd, yd, nt, ipt, nl, ipl, iwl, iwp, wk , &\n errint , errmsg )\n\n!*******************************************************************************\n!\n!! IDTANG performs triangulation.\n!\n! Discussion:\n!\n! The routine divides the XY plane into a number of triangles according to\n! given data points in the plane, determines line segments that form\n! the border of data area, and determines the triangle numbers\n! corresponding to the border line segments.\n!\n! At completion, point numbers of the vertexes of each triangle\n! are listed counter-clockwise. Point numbers of the end points\n! of each border line segment are listed counter-clockwise,\n! listing order of the line segments being counter-clockwise.\n!\n! Modified:\n!\n! 04 June 2003\n!\n! Reference:\n!\n! Hiroshi Akima,\n! Algorithm 526,\n! A Method of Bivariate Interpolation and Smooth Surface Fitting\n! for Values Given at Irregularly Distributed Points,\n! ACM Transactions on Mathematical Software,\n! Volume 4, Number 2, June 1978.\n!\n! Parameters:\n!\n! Input, integer NDP, the number of data points.\n!\n! Input, real ( kind = KIND_Rdp ) XD(NDP), YD(NDP), the X and Y coordinates\n! of the data.\n!\n! Output, integer NT, the number of triangles,\n!\n! Output, integer IPT(6*NDP-15), where the point numbers of the\n! vertexes of the IT-th triangle are to be stored as entries\n! 3*IT-2, 3*IT-1, and 3*IT, for IT = 1 to NT.\n!\n! Output, integer NL, the number of border line segments.\n!\n! Output, integer IPL(6*NDP), where the point numbers of the end\n! points of the (il)th border line segment and its respective triangle\n! number are to be stored as the (3*il-2)nd, (3*il-1)st, and (3*il)th\n! elements, il = 1,2,..., nl.\n!\n! Workspace, integer IWL(18*NDP),\n!\n! Workspace, integer IWP(NDP),\n!\n! Workspace, real ( kind = KIND_Rdp ) WK(NDP).\n!\n implicit none\n\n integer ndp\n\n ![waw] real ( kind = KIND_Rdp ) dsqf\n real ( kind = KIND_Rdp ) dsqi\n real ( kind = KIND_Rdp ) dsqmn\n integer errint\n character( len = * ) errmsg\n optional errint,errmsg\n ![waw] integer idxchg\n integer il\n integer ilf\n integer iliv\n integer ilt3\n integer ilvs\n integer ip\n integer ip1\n integer ip1p1\n integer ip2\n integer ip3\n integer ipl(6*ndp)\n integer ipl1\n integer ipl2\n integer iplj1\n integer iplj2\n integer ipmn1\n integer ipmn2\n integer ipt(6*ndp-15)\n integer ipt1\n integer ipt2\n integer ipt3\n integer ipti\n integer ipti1\n integer ipti2\n integer irep\n integer it\n integer it1t3\n integer it2t3\n integer itf(2)\n integer its\n integer itt3\n integer itt3r\n integer iwl(18*ndp)\n integer iwp(ndp)\n integer ixvs\n integer ixvspv\n integer jl1\n integer jl2\n integer jlt3\n integer jp\n integer jp1\n integer jp2\n integer jpc\n integer jpmn\n integer jpmx\n integer jwl\n integer jwl1\n integer jwl1mn\n integer nl\n integer nl0\n integer nlf\n integer nlfc\n integer nlft2\n integer nln\n integer nlnt3\n integer nlsh\n integer nlsht3\n integer nlt3\n integer, parameter :: nrep = 100\n integer nt\n integer nt0\n integer ntf\n integer ntt3\n integer ntt3p3\n real ( kind = KIND_Rdp ) sp\n real ( kind = KIND_Rdp ) u1\n real ( kind = KIND_Rdp ) u2\n real ( kind = KIND_Rdp ) u3\n real ( kind = KIND_Rdp ) v1\n real ( kind = KIND_Rdp ) v2\n real ( kind = KIND_Rdp ) v3\n real ( kind = KIND_Rdp ) vp\n real ( kind = KIND_Rdp ) wk(ndp)\n real ( kind = KIND_Rdp ) x1\n real ( kind = KIND_Rdp ) x2\n real ( kind = KIND_Rdp ) x3\n real ( kind = KIND_Rdp ) xd(ndp)\n real ( kind = KIND_Rdp ) xdmp\n real ( kind = KIND_Rdp ) y1\n real ( kind = KIND_Rdp ) y2\n real ( kind = KIND_Rdp ) y3\n real ( kind = KIND_Rdp ) yd(ndp)\n real ( kind = KIND_Rdp ) ydmp\n!\n! Preliminary processing\n!\n IF( PRESENT(errmsg) )errmsg = \"\"\n IF( PRESENT(errint) )errint = 0\n if ( ndp < 4 ) then\n if( present(errint) )errint = -9\n if( present(errmsg) )then\n write(errmsg,\"(a)\")'Input parameter &\n &NDP=',NDP,' out of range. NDP >= 4. [LIB_BiVar:IDTANG]'\n end if\n return\n end if\n!\n! Determine IPMN1 and IPMN2, the closest pair of data points.\n!\n dsqmn = dsqf(xd(1),yd(1),xd(2),yd(2))\n ipmn1 = 1\n ipmn2 = 2\n\n do ip1 = 1, ndp-1\n\n x1 = xd(ip1)\n y1 = yd(ip1)\n ip1p1 = ip1+1\n\n do ip2 = ip1p1, ndp\n\n dsqi = dsqf(x1,y1,xd(ip2),yd(ip2))\n\n if ( dsqi == 0.0 ) then\n if( present(errint) )errint = -10\n if( present(errmsg) )then\n write(errmsg,\"(a)\")'Two of the input data points are&\n & identical. [LIB_Bivar:IDTANG]'\n end if\n return\n end if\n\n if ( dsqi < dsqmn ) then\n dsqmn = dsqi\n ipmn1 = ip1\n ipmn2 = ip2\n end if\n\n end do\n\n end do\n!\n! Compute the midpoint of the closest two data points.\n!\n xdmp = (xd(ipmn1)+xd(ipmn2)) / 2.0D+00\n ydmp = (yd(ipmn1)+yd(ipmn2)) / 2.0D+00\n!\n! Sort the other (NDP-2) data points in ascending order of\n! distance from the midpoint and store the sorted data point\n! numbers in the IWP array.\n!\n jp1 = 2\n\n do ip1 = 1, ndp\n if ( ip1 /= ipmn1 .and. ip1 /= ipmn2 ) then\n jp1 = jp1+1\n iwp(jp1) = ip1\n wk(jp1) = dsqf(xdmp,ydmp,xd(ip1),yd(ip1))\n end if\n end do\n\n do jp1 = 3, ndp-1\n\n dsqmn = wk(jp1)\n jpmn = jp1\n\n do jp2 = jp1, ndp\n if ( wk(jp2) < dsqmn ) then\n dsqmn = wk(jp2)\n jpmn = jp2\n end if\n end do\n\n its = iwp(jp1)\n iwp(jp1) = iwp(jpmn)\n iwp(jpmn) = its\n wk(jpmn) = wk(jp1)\n\n end do\n!\n! If necessary, modify the ordering in such a way that the\n! first three data points are not collinear.\n!\n x1 = xd(ipmn1)\n y1 = yd(ipmn1)\n x2 = xd(ipmn2)\n y2 = yd(ipmn2)\n\n do jp = 3, ndp\n\n ip = iwp(jp)\n sp = spdt(xd(ip),yd(ip),x1,y1,x2,y2)\n vp = vpdt(xd(ip),yd(ip),x1,y1,x2,y2)\n\n if ( ( abs ( sp ) * epsilon ( sp ) ) < abs ( vp ) ) then\n go to 37\n end if\n\n end do\n\n if( present(errint) )errint = -9\n if( present(errmsg) )then\n write(errmsg,\"(a)\")'All colinear data points. [LIB_Bivar:IDTANG]'\n end if\n return\n\n 37 continue\n\n if ( jp /= 3 ) then\n\n jpmx = jp\n\n do jpc = 4, jpmx\n jp = jpmx+4-jpc\n iwp(jp) = iwp(jp-1)\n end do\n\n iwp(3) = ip\n\n end if\n!\n! Form the first triangle.\n!\n! Store point numbers of the vertexes of the triangle in the IPT array,\n! store point numbers of the border line segments and the triangle number in\n! the IPL array.\n!\n ip1 = ipmn1\n ip2 = ipmn2\n ip3 = iwp(3)\n\n if ( vpdt(xd(ip1),yd(ip1),xd(ip2),yd(ip2),xd(ip3),yd(ip3)) < 0.0D+00 ) then\n ip1 = ipmn2\n ip2 = ipmn1\n end if\n\n nt0 = 1\n ntt3 = 3\n ipt(1) = ip1\n ipt(2) = ip2\n ipt(3) = ip3\n nl0 = 3\n nlt3 = 9\n ipl(1) = ip1\n ipl(2) = ip2\n ipl(3) = 1\n ipl(4) = ip2\n ipl(5) = ip3\n ipl(6) = 1\n ipl(7) = ip3\n ipl(8) = ip1\n ipl(9) = 1\n!\n! Add the remaining data points, one by one.\n!\n do jp1 = 4, ndp\n\n ip1 = iwp(jp1)\n x1 = xd(ip1)\n y1 = yd(ip1)\n!\n! Determine the first invisible and visible border line segments, iliv and\n! ilvs.\n!\n do il = 1, nl0\n\n ip2 = ipl(3*il-2)\n ip3 = ipl(3*il-1)\n x2 = xd(ip2)\n y2 = yd(ip2)\n x3 = xd(ip3)\n y3 = yd(ip3)\n sp = spdt(x1,y1,x2,y2,x3,y3)\n vp = vpdt(x1,y1,x2,y2,x3,y3)\n\n if ( il == 1 ) then\n ixvs = 0\n if ( vp <= - abs ( sp ) * epsilon ( sp ) ) then\n ixvs = 1\n end if\n iliv = 1\n ilvs = 1\n go to 53\n end if\n\n ixvspv = ixvs\n\n if ( vp <= - abs ( sp ) * epsilon ( sp ) ) then\n ixvs = 1\n if(ixvspv==1) go to 53\n ilvs = il\n if(iliv/=1) go to 54\n go to 53\n end if\n\n ixvs = 0\n\n if ( ixvspv /= 0 ) then\n iliv = il\n if ( ilvs /= 1 ) then\n go to 54\n end if\n end if\n\n53 continue\n\n end do\n\n if ( iliv == 1 .and. ilvs == 1 ) then\n ilvs = nl0\n end if\n\n54 continue\n\n if ( ilvs < iliv ) then\n ilvs = ilvs+nl0\n end if\n!\n! Shift (rotate) the IPL array to have the invisible border\n! line segments contained in the first part of the array.\n!\n55 continue\n\n if ( iliv /= 1 ) then\n\n nlsh = iliv-1\n nlsht3 = nlsh*3\n\n do jl1 = 1,nlsht3\n jl2 = jl1+nlt3\n ipl(jl2) = ipl(jl1)\n end do\n\n do jl1 = 1,nlt3\n jl2 = jl1+nlsht3\n ipl(jl1) = ipl(jl2)\n end do\n\n ilvs = ilvs-nlsh\n\n end if\n!\n! Add triangles to the IPT array,\n! update border line segments in the IPL array,\n! set flags for the border line segments to be reexamined in the IWL array.\n!\n jwl = 0\n\n do il = ilvs, nl0\n\n ilt3 = il*3\n ipl1 = ipl(ilt3-2)\n ipl2 = ipl(ilt3-1)\n it = ipl(ilt3)\n!\n! Add a triangle to the IPT array.\n!\n nt0 = nt0+1\n ntt3 = ntt3+3\n ipt(ntt3-2) = ipl2\n ipt(ntt3-1) = ipl1\n ipt(ntt3) = ip1\n!\n! Update border line segments in the IPL array.\n!\n if ( il == ilvs ) then\n ipl(ilt3-1) = ip1\n ipl(ilt3) = nt0\n end if\n\n if ( il == nl0 ) then\n nln = ilvs+1\n nlnt3 = nln*3\n ipl(nlnt3-2) = ip1\n ipl(nlnt3-1) = ipl(1)\n ipl(nlnt3) = nt0\n end if\n!\n! Determine the vertex that does not lie on the border\n! line segments.\n!\n itt3 = it*3\n ipti = ipt(itt3-2)\n\n if ( ipti == ipl1 .or. ipti == ipl2 ) then\n ipti = ipt(itt3-1)\n if ( ipti == ipl1 .or. ipti == ipl2 ) then\n ipti = ipt(itt3)\n end if\n end if\n!\n! Check if the exchange is necessary.\n!\n if ( idxchg(xd,yd,ip1,ipti,ipl1,ipl2) /= 0 ) then\n!\n! Modify the IPT array.\n!\n ipt(itt3-2) = ipti\n ipt(itt3-1) = ipl1\n ipt(itt3) = ip1\n ipt(ntt3-1) = ipti\n if(il==ilvs) ipl(ilt3) = it\n if(il==nl0.and.ipl(3)==it) ipl(3) = nt0\n!\n! Set flags in the IWL array.\n!\n jwl = jwl+4\n iwl(jwl-3) = ipl1\n iwl(jwl-2) = ipti\n iwl(jwl-1) = ipti\n iwl(jwl) = ipl2\n\n end if\n\n end do\n\n nl0 = nln\n nlt3 = nlnt3\n nlf = jwl/2\n\n if ( nlf == 0 ) then\n cycle\n end if\n!\n! Improve triangulation.\n!\n ntt3p3 = ntt3+3\n\n do irep = 1, nrep\n\n do ilf = 1,nlf\n\n ipl1 = iwl(2*ilf-1)\n ipl2 = iwl(2*ilf)\n!\n! Locate in the ipt array two triangles on both sides of\n! the flagged line segment.\n!\n ntf = 0\n\n do itt3r = 3,ntt3,3\n itt3 = ntt3p3-itt3r\n ipt1 = ipt(itt3-2)\n ipt2 = ipt(itt3-1)\n ipt3 = ipt(itt3)\n if(ipl1/=ipt1.and.ipl1/=ipt2.and. ipl1/=ipt3) go to 71\n if(ipl2/=ipt1.and.ipl2/=ipt2.and. ipl2/=ipt3) go to 71\n ntf = ntf+1\n itf(ntf) = itt3/3\n if(ntf==2) go to 72\n71 continue\n end do\n\n if ( ntf < 2 ) go to 76\n!\n! Determine the vertexes of the triangles that do not lie\n! on the line segment.\n!\n72 continue\n\n it1t3 = itf(1)*3\n ipti1 = ipt(it1t3-2)\n\n if ( ipti1 == ipl1 .or. ipti1 == ipl2 ) then\n\n ipti1 = ipt(it1t3-1)\n\n if ( ipti1 == ipl1 .or. ipti1 == ipl2 ) then\n ipti1 = ipt(it1t3)\n end if\n\n end if\n\n it2t3 = itf(2)*3\n ipti2 = ipt(it2t3-2)\n if(ipti2/=ipl1.and.ipti2/=ipl2) go to 74\n ipti2 = ipt(it2t3-1)\n if(ipti2/=ipl1.and.ipti2/=ipl2) go to 74\n ipti2 = ipt(it2t3)\n!\n! Check if the exchange is necessary.\n!\n74 continue\n\n if(idxchg(xd,yd,ipti1,ipti2,ipl1,ipl2)==0) then\n go to 76\n end if\n!\n! Modify the IPT array.\n!\n ipt(it1t3-2) = ipti1\n ipt(it1t3-1) = ipti2\n ipt(it1t3) = ipl1\n ipt(it2t3-2) = ipti2\n ipt(it2t3-1) = ipti1\n ipt(it2t3) = ipl2\n!\n! Set new flags.\n!\n jwl = jwl+8\n iwl(jwl-7) = ipl1\n iwl(jwl-6) = ipti1\n iwl(jwl-5) = ipti1\n iwl(jwl-4) = ipl2\n iwl(jwl-3) = ipl2\n iwl(jwl-2) = ipti2\n iwl(jwl-1) = ipti2\n iwl(jwl) = ipl1\n do jlt3 = 3,nlt3,3\n iplj1 = ipl(jlt3-2)\n iplj2 = ipl(jlt3-1)\n\n if((iplj1==ipl1.and.iplj2==ipti2).or. &\n (iplj2==ipl1.and.iplj1==ipti2)) then\n ipl(jlt3) = itf(1)\n end if\n\n if((iplj1==ipl2.and.iplj2==ipti1).or. &\n (iplj2==ipl2.and.iplj1==ipti1)) then\n ipl(jlt3) = itf(2)\n end if\n\n end do\n\n76 continue\n\n end do\n\n nlfc = nlf\n nlf = jwl/2\n!\n! Reset the IWL array for the next round.\n!\n if ( nlf == nlfc ) then\n exit\n end if\n\n jwl1mn = 2*nlfc+1\n nlft2 = nlf*2\n\n do jwl1 = jwl1mn,nlft2\n jwl = jwl1+1-jwl1mn\n iwl(jwl) = iwl(jwl1)\n end do\n\n nlf = jwl / 2\n\n end do\n\n end do\n!\n! Rearrange the IPT array so that the vertexes of each triangle\n! are listed counter-clockwise.\n!\n do itt3 = 3, ntt3, 3\n\n ip1 = ipt(itt3-2)\n ip2 = ipt(itt3-1)\n ip3 = ipt(itt3)\n\n if(vpdt(xd(ip1),yd(ip1),xd(ip2),yd(ip2),xd(ip3),yd(ip3)) < 0.0D+00 ) then\n ipt(itt3-2) = ip2\n ipt(itt3-1) = ip1\n end if\n\n end do\n\n nt = nt0\n nl = nl0\n\n return\nend subroutine\n\nfunction idxchg ( x, y, i1, i2, i3, i4 )\n\n!*******************************************************************************\n!\n!! IDXCHG determines whether two triangles should be exchanged.\n!\n! Discussion:\n!\n! The max-min-angle criterion of C L Lawson is used.\n!\n! Modified:\n!\n! 04 June 2003\n!\n! Reference:\n!\n! Hiroshi Akima,\n! Algorithm 526,\n! A Method of Bivariate Interpolation and Smooth Surface Fitting\n! for Values Given at Irregularly Distributed Points,\n! ACM Transactions on Mathematical Software,\n! Volume 4, Number 2, June 1978.\n!\n! Parameters:\n!\n! Input, real ( kind = KIND_Rdp ) X(*), Y(*), the coordinates of the data points.\n!\n! Input, integer I1, I2, I3, I4, are the point numbers of\n! four points P1, P2, P3, and P4 that form a quadrilateral,\n! with P3 and P4 connected diagonally.\n!\n! Output, integer IDXCHG, reports whether the triangles should be\n! exchanged:\n! 0, no exchange is necessary.\n! 1, an exchange is necessary.\n!\n implicit none\n\n real ( kind = KIND_Rdp ) a1sq\n real ( kind = KIND_Rdp ) a2sq\n real ( kind = KIND_Rdp ) a3sq\n real ( kind = KIND_Rdp ) a4sq\n real ( kind = KIND_Rdp ) c1sq\n real ( kind = KIND_Rdp ) c3sq\n integer i1\n integer i2\n integer i3\n integer i4\n integer idx\n integer idxchg\n real ( kind = KIND_Rdp ) c2sq\n real ( kind = KIND_Rdp ) c4sq\n real ( kind = KIND_Rdp ) b1sq\n real ( kind = KIND_Rdp ) b2sq\n real ( kind = KIND_Rdp ) b3sq\n real ( kind = KIND_Rdp ) b4sq\n real ( kind = KIND_Rdp ) s1sq\n real ( kind = KIND_Rdp ) s2sq\n real ( kind = KIND_Rdp ) s3sq\n real ( kind = KIND_Rdp ) s4sq\n real ( kind = KIND_Rdp ) u1\n real ( kind = KIND_Rdp ) u2\n real ( kind = KIND_Rdp ) u3\n real ( kind = KIND_Rdp ) u4\n real ( kind = KIND_Rdp ) x(*)\n real ( kind = KIND_Rdp ) x1\n real ( kind = KIND_Rdp ) x2\n real ( kind = KIND_Rdp ) x3\n real ( kind = KIND_Rdp ) x4\n real ( kind = KIND_Rdp ) y(*)\n real ( kind = KIND_Rdp ) y1\n real ( kind = KIND_Rdp ) y2\n real ( kind = KIND_Rdp ) y3\n real ( kind = KIND_Rdp ) y4\nEQUIVALENCE (C2SQ,C1SQ),(A3SQ,B2SQ),(B3SQ,A1SQ),&\n (A4SQ,B1SQ),(B4SQ,A2SQ),(C4SQ,C3SQ)\n!\n! Preliminary processing\n!\nx1=x(i1)\ny1=y(i1)\nx2=x(i2)\ny2=y(i2)\nx3=x(i3)\ny3=y(i3)\nx4=x(i4)\ny4=y(i4)\n\nidx=0\n\nu3=(y2-y3)*(x1-x3)-(x2-x3)*(y1-y3)\nu4=(y1-y4)*(x2-x4)-(x1-x4)*(y2-y4)\n\nif(u3*u4.le.0.0) go to 30\n\nu1=(y3-y1)*(x4-x1)-(x3-x1)*(y4-y1)\nu2=(y4-y2)*(x3-x2)-(x4-x2)*(y3-y2)\na1sq=(x1-x3)**2+(y1-y3)**2\nb1sq=(x4-x1)**2+(y4-y1)**2\nc1sq=(x3-x4)**2+(y3-y4)**2\na2sq=(x2-x4)**2+(y2-y4)**2\nb2sq=(x3-x2)**2+(y3-y2)**2\nc3sq=(x2-x1)**2+(y2-y1)**2\ns1sq=u1*u1/(c1sq*max(a1sq,b1sq))\ns2sq=u2*u2/(c2sq*max(a2sq,b2sq))\ns3sq=u3*u3/(c3sq*max(a3sq,b3sq))\ns4sq=u4*u4/(c4sq*max(a4sq,b4sq))\n\nif(min(s1sq,s2sq).lt.min(s3sq,s4sq)) idx=1\n30 CONTINUE\nidxchg=idx\n\nreturn\nend function\n\nfunction spdt(u1,v1,u2,v2,u3,v3)\n real ( kind = KIND_Rdp ) u1\n real ( kind = KIND_Rdp ) u2\n real ( kind = KIND_Rdp ) u3\n real ( kind = KIND_Rdp ) v1\n real ( kind = KIND_Rdp ) v2\n real ( kind = KIND_Rdp ) v3\n real ( kind = KIND_Rdp ) spdt\n\n spdt = (u1-u2)*(u3-u2)+(v1-v2)*(v3-v2)\n\nend function\n\nfunction vpdt(u1,v1,u2,v2,u3,v3)\n real ( kind = KIND_Rdp ) u1\n real ( kind = KIND_Rdp ) u2\n real ( kind = KIND_Rdp ) u3\n real ( kind = KIND_Rdp ) v1\n real ( kind = KIND_Rdp ) v2\n real ( kind = KIND_Rdp ) v3\n real ( kind = KIND_Rdp ) vpdt\n\n vpdt = (u1-u3)*(v2-v3)-(v1-v3)*(u2-u3)\n\nend function\n\nfunction dsqf(u1,v1,u2,v2)\n real ( kind = KIND_Rdp ) u1\n real ( kind = KIND_Rdp ) u2\n real ( kind = KIND_Rdp ) v1\n real ( kind = KIND_Rdp ) v2\n real ( kind = KIND_Rdp ) dsqf\n\n dsqf = (u2-u1)**2+(v2-v1)**2\n\nend function\nEND MODULE\n", "meta": {"hexsha": "41cb3517f66dc18993c815bf69803eb636d51cce", "size": 67276, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/04-A-LIB_BiVar.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/04-A-LIB_BiVar.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/04-A-LIB_BiVar.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": 22.0649393244, "max_line_length": 99, "alphanum_fraction": 0.569311493, "num_tokens": 26198, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436482, "lm_q2_score": 0.7154240018510026, "lm_q1q2_score": 0.6587550316788271}} {"text": "\tFUNCTION SND_BVS ( datain, nparm, k, deltaz, ivcord )\nC************************************************************************\nC* SND_BVS\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes the square of the Brunt-Vaisala Frequency.\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* SND_BVS ( DATAIN, NPARM, K, DELTAZ, IVCORD )\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tDATAIN (LLMXLV)\tREAL\t\tInterpolated sounding data\t*\nC*\tNPARM\t\tINTEGER\t\tNumber of parameters\t\t*\nC*\tK\t\tINTEGER\t\tCurrent level\t\t\t*\nC*\tDELTAZ\t\tINTEGER\t\tLevel increment\t\t\t*\nC*\tIVCORD\t\tINTEGER\t\tVertical coordinate type\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tSND_BVS\t\tREAL\t\tBrunt-Vaisala frequency\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* J. Nielsen/SUNYA\t 8/90\t\t\t\t\t\t*\nC* S. Jacobs/SSAI\t 4/92\tChanged initial depth to user input\t*\nC* J. Whistler/SSAI\t11/92\tCleaned up and added check for missing\t*\nC*\t\t\t\tdata\t\t\t\t\t*\nC************************************************************************\n\tINCLUDE\t\t'GEMPRM.PRM'\n\tINCLUDE\t\t'sndiag.prm'\nC*\n\tREAL\t\tdatain (*)\nC*\n\tINCLUDE\t\t'ERMISS.FNC'\nC------------------------------------------------------------------------\n\tSND_BVS = RMISSD\nC\nC*\tGet data at this layer, unless requested otherwise.\nC\n\tIF ( ERMISS ( datain((k-1+1)*nparm+ITHTV) ) .or.\n +\t ERMISS ( datain((k-1+1)*nparm+ITHTV) ) ) THEN \n\t RETURN\n\tELSE\n\t depth = deltaz * 2.\n\t thtop = datain((k-1+1)*nparm+ITHTV)\n\t thbot = datain((k-1-1)*nparm+ITHTV)\n theav = ( thtop + thbot ) / 2.\nC\nC*\t Compute N**2.\nC\n\t IF ( depth .gt. 0. ) THEN\n\t bvfsqd = ( GRAVTY / theav ) * ( thtop - thbot ) / depth\n\t ELSE \n\t\tbvfsqd = 0.0\n\t END IF\nC\n\t IF ( bvfsqd .lt. 0.0 ) RETURN\n\t SND_BVS = bvfsqd\n\tEND IF\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "b93233492166c107a040b3b5ad30df907c215be7", "size": 1712, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/programs/sn/sndiag/sndbvs.f", "max_stars_repo_name": "oxelson/gempak", "max_stars_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2015-06-03T15:26:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T22:36:03.000Z", "max_issues_repo_path": "gempak/source/programs/sn/sndiag/sndbvs.f", "max_issues_repo_name": "oxelson/gempak", "max_issues_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 60, "max_issues_repo_issues_event_min_datetime": "2015-05-11T21:36:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T16:22:42.000Z", "max_forks_repo_path": "gempak/source/programs/sn/sndiag/sndbvs.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": 28.5333333333, "max_line_length": 73, "alphanum_fraction": 0.5093457944, "num_tokens": 606, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896671963206, "lm_q2_score": 0.7154239957834733, "lm_q1q2_score": 0.6587550229817263}} {"text": "subroutine calc_dimensionless_numbers(j)\n\n use constants_module\n use arrays_module\n use var_module\n use arrays_section_module\n\n implicit none\n\n integer, intent(in) :: j\n integer(kind=4) :: i\n real(kind=4) :: wl_us, depth_us, q_us, v_us, pere_us, r_us, sk_us, ch_us\n real(kind=4) :: wl_ds, depth_ds, q_ds, v_ds, pere_ds, r_ds, sk_ds, ch_ds\n real(kind=4) :: ch_star_avg, channel_length, avg_celerity, avg_velocity, avg_depth\n real(kind=4) :: maxValue, dimlessWaveLength\n\n !avg_celerity = celerity(2)\n\n maxValue = 1e7\n\n do i=1, ncomp-1\n\n avg_celerity = (celerity(i,j) + celerity(i+1,j)) / 2.0 ! 'celerity2' is calculated celerity. 'celerity' is spatially averaged\n\n wl_us = newY(i,j)\n ! bo(i) and pere(i) has data for the latest river reach only\n depth_us = newArea(i,j) / bo(i,j)\n q_us = newQ(i,j)\n v_us = abs( newQ(i,j) / newArea(i,j) )\n pere_us = pere(i,j)\n r_us = newArea(i,j) / pere(i,j)\n sk_us = sk(i,j)\n ch_us = sk(i,j) * r_us ** (1./6.)\n\n\n wl_ds = newY(i+1,j)\n depth_ds = newArea(i+1,j) / bo(i+1,j)\n q_ds = newQ(i+1,j)\n v_ds = abs( newQ(i+1,j) / newArea(i+1,j) )\n pere_ds = pere(i+1,j)\n r_ds = newArea(i+1,j) / pere(i+1,j)\n sk_ds = sk(i+1,j)\n ch_ds = sk(i+1,j) * r_ds ** (1./6.)\n\n\n ch_star_avg = ((ch_us + ch_ds) / 2.) / sqrt( grav ) !! CORRECTED\n channel_length = dx(i,j)\n\n\n\n !wl_ds = newY(752)\n !depth_ds = newArea(752) / bo(752)\n !q_ds = newQ(752)\n !v_ds = abs( newQ(1) / newArea(752) )\n !pere_ds = pere(752)\n !r_ds = newArea(752) / pere(752)\n !sk_ds = sk(752)\n !ch_ds = sk(752) * r_ds ** (1./6.)\n\n\n !ch_star_avg = ((ch_us + ch_ds) / 2.) / sqrt( grav ) !! CORRECTED\n !channel_length = sum(dx(1:752-1))\n\n dimlessWaveLength= 4000. !! new\n\n\n\n avg_velocity = (v_us + v_ds) / 2.\n avg_depth = (depth_us + depth_ds) / 2.\n\n dimensionless_Cr(i,j) = abs(avg_velocity / avg_celerity)\n if (dimensionless_Cr(i,j) .gt. maxValue) dimensionless_Cr(i,j) = maxValue\n\n dimensionless_Fo(i,j) = avg_velocity / sqrt(grav * avg_depth)\n if (dimensionless_Fo(i,j) .gt. maxValue) dimensionless_Fo(i,j) = maxValue\n\n !dimensionless_Fi(i) = 2*dimensionless_Cr(i) / (ch_star_avg ** 2.) * (channel_length / avg_depth) !! CORRECTED\n dimensionless_Fi(i,j) = 2*dimensionless_Cr(i,j) / (ch_star_avg ** 2.) * dimlessWaveLength !(channel_length / avg_depth) !! CORRECTED\n if (dimensionless_Fi(i,j) .gt. maxValue) dimensionless_Fi(i,j) = maxValue\n\n dimensionless_Fc(i,j) = dimensionless_Cr(i,j) * dimensionless_Fi(i,j)\n if (dimensionless_Fc(i,j) .gt. maxValue) dimensionless_Fc(i,j) = maxValue\n\n dimensionless_Di(i,j) = (dimensionless_Cr(i,j) / dimensionless_Fo(i,j)) ** 2. !! CORRECTED\n if (dimensionless_Di(i,j) .gt. maxValue) dimensionless_Di(i,j) = maxValue\n\n dimensionless_D(i,j) = dimensionless_Di(i,j) / dimensionless_Fc(i,j)\n if (dimensionless_D(i,j) .gt. maxValue) dimensionless_D(i,j) = maxValue\n\n !print*, i, avg_velocity, avg_celerity, dimensionless_Cr(i)\n\n end do\n\n\n\n !print*, ch_star_avg, dimensionless_Cr, dimensionless_Fo, dimensionless_Fi\n !pause 5000\n\nend subroutine calc_dimensionless_numbers\n", "meta": {"hexsha": "7d0add58a6876031cd47497083b757b18d813fb6", "size": 3368, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src_combined_Y_network/mainLoop_calculateDimensionlessNumbers_allPoints.f90", "max_stars_repo_name": "MESH-Team/MESH_Code_irregular", "max_stars_repo_head_hexsha": "1edd0b60a8b2ccd95ec92b4fc7e381193cf6b936", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-01-30T22:53:41.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-30T22:53:41.000Z", "max_issues_repo_path": "src_combined_Y_network/mainLoop_calculateDimensionlessNumbers_allPoints.f90", "max_issues_repo_name": "MESH-Team/MESH_Code_irregular", "max_issues_repo_head_hexsha": "1edd0b60a8b2ccd95ec92b4fc7e381193cf6b936", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-10-16T21:11:19.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-17T22:21:51.000Z", "max_forks_repo_path": "src_combined_Y_network/mainLoop_calculateDimensionlessNumbers_allPoints.f90", "max_forks_repo_name": "MESH-Team/MESH_Code_irregular", "max_forks_repo_head_hexsha": "1edd0b60a8b2ccd95ec92b4fc7e381193cf6b936", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-01-06T17:11:11.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-28T22:36:23.000Z", "avg_line_length": 33.68, "max_line_length": 140, "alphanum_fraction": 0.6054038005, "num_tokens": 1119, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896693699844, "lm_q2_score": 0.7154239836484143, "lm_q1q2_score": 0.6587550133629806}} {"text": "! =============================================================================\n! Test free slip boundary condition\n!\n! This unit test checks the free slip boundary condition which is\n! implied in vertical direction. Ellipses with aspect ratio 3.5\n! are place such that the parcels at the bottom and ad the top have\n! one ellipse point reaching out the physical domain. We use 4\n! parcels per cell. After interpolating the parcel volume\n! (volume = 0.25 * vcell per parcel), the gridded volume is\n! ngrid * vcell where ngrid is the number of grid points.\n! =============================================================================\nprogram test_free_slip\n use unit_test\n use constants, only : pi, zero, one, two, f12, f14, f32\n use parcel_container\n use parcel_interpl, only : vol2grid\n use parameters, only : lower, extent, update_parameters, vcell, dx, nx, nz, ngrid\n use fields, only : volg\n use timer\n implicit none\n\n integer :: i, j, k, jj, ii\n double precision, parameter :: angle = f12 * pi\n double precision, parameter :: lam = 3.5d0 ! >= 3.5 --> 1 ellipse point outside domain\n double precision :: error\n\n nx = 4\n nz = 4\n lower = (/-f32, -f32/)\n extent = (/0.4d0, 0.4d0/)\n\n call update_parameters\n\n allocate(volg(-1:nz+1, 0:nx-1))\n\n call parcel_alloc(64)\n\n\n k = 1\n do j = 0, nz-1\n do i = 0, nx-1\n do jj = 1, 4, 2\n do ii = 1, 4, 2\n parcels%position(1, k) = lower(1) + i * dx(1) + f14 * dx(1) * ii\n parcels%position(2, k) = lower(2) + j * dx(2) + f14 * dx(2) * jj\n k = k + 1\n enddo\n enddo\n enddo\n enddo\n\n n_parcels = 64\n\n volg = zero\n\n parcels%volume = f14 * vcell\n\n ! b11\n parcels%B(1, :) = lam * dcos(angle) ** 2 + one / lam * dsin(angle) ** 2\n\n ! b12\n parcels%B(2, :) = f12 * (lam - one / lam) * dsin(two * angle)\n\n\n call vol2grid\n\n\n error = abs(sum(volg(0:nz, 0:nx-1)) - ngrid * vcell)\n\n call print_result_dp('Test free slip', error)\n\n call parcel_dealloc\n deallocate(volg)\n\nend program test_free_slip\n", "meta": {"hexsha": "28b89e536deb3d6a5e7ca9f4ea7bd66d9db4ba37", "size": 2206, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "unit-tests/2d/test_free_slip.f90", "max_stars_repo_name": "matt-frey/epic", "max_stars_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2021-11-11T10:50:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T00:11:41.000Z", "max_issues_repo_path": "unit-tests/2d/test_free_slip.f90", "max_issues_repo_name": "matt-frey/epic", "max_issues_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 47, "max_issues_repo_issues_event_min_datetime": "2021-11-12T17:09:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-24T16:50:58.000Z", "max_forks_repo_path": "unit-tests/2d/test_free_slip.f90", "max_forks_repo_name": "matt-frey/epic", "max_forks_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.0263157895, "max_line_length": 90, "alphanum_fraction": 0.5321849501, "num_tokens": 653, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007393, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6587548773056878}} {"text": "! -*- f90 -*-\n\nmodule bspline\ncontains\n\nfunction FindSpan(n,p,uu,U) result (span)\n implicit none\n integer(kind=4), intent(in) :: n, p\n real (kind=8), intent(in) :: uu, U(0:n+p+1)\n integer(kind=4) :: span\n integer(kind=4) low, high\n if (uu >= U(n+1)) then\n span = n\n return\n end if\n if (uu <= U(p)) then\n span = p\n return\n end if\n low = p\n high = n+1\n span = (low + high) / 2\n do while (uu < U(span) .or. uu >= U(span+1))\n if (uu < U(span)) then\n high = span\n else\n low = span\n end if\n span = (low + high) / 2\n end do\nend function FindSpan\n\nfunction FindMult(i,uu,p,U) result (mult)\n implicit none\n integer(kind=4), intent(in) :: i, p\n real (kind=8), intent(in) :: uu, U(0:i+p+1)\n integer(kind=4) :: mult\n integer(kind=4) :: j\n mult = 0\n do j = -p, p+1\n if (abs(uu - U(i+j))= k) then\n a(s2,0) = a(s1,0) / ndu(pk+1,rk)\n d = a(s2,0) * ndu(rk,pk)\n end if\n if (rk > -1) then\n j1 = 1\n else\n j1 = -rk\n end if\n if (r-1 <= pk) then\n j2 = k-1\n else\n j2 = p-r\n end if\n do j = j1, j2\n a(s2,j) = (a(s1,j) - a(s1,j-1)) / ndu(pk+1,rk+j)\n d = d + a(s2,j) * ndu(rk+j,pk)\n end do\n if (r <= pk) then\n a(s2,k) = - a(s1,k-1) / ndu(pk+1,r)\n d = d + a(s2,k) * ndu(r,pk)\n end if\n ders(r,k) = d\n j = s1; s1 = s2; s2 = j;\n end do\n end do\n r = p\n do k = 1, n\n ders(:,k) = ders(:,k) * r\n r = r * (p-k)\n end do\nend subroutine DersBasisFuns\n\nsubroutine CurvePoint(d,n,p,U,Pw,uu,C)\n implicit none\n integer(kind=4), intent(in) :: d\n integer(kind=4), intent(in) :: n, p\n real (kind=8), intent(in) :: U(0:n+p+1)\n real (kind=8), intent(in) :: Pw(d,0:n)\n real (kind=8), intent(in) :: uu\n real (kind=8), intent(out) :: C(d)\n integer(kind=4) :: j, span\n real (kind=8) :: basis(0:p)\n span = FindSpan(n,p,uu,U)\n call BasisFuns(span,uu,p,U,basis)\n C = 0\n do j = 0, p\n C = C + basis(j)*Pw(:,span-p+j)\n end do\nend subroutine CurvePoint\n\nsubroutine SurfacePoint(d,n,p,U,m,q,V,Pw,uu,vv,S)\n implicit none\n integer(kind=4), intent(in) :: d\n integer(kind=4), intent(in) :: n, p\n integer(kind=4), intent(in) :: m, q\n real (kind=8), intent(in) :: U(0:n+p+1)\n real (kind=8), intent(in) :: V(0:m+q+1)\n real (kind=8), intent(in) :: Pw(d,0:m,0:n)\n real (kind=8), intent(in) :: uu, vv\n real (kind=8), intent(out) :: S(d)\n integer(kind=4) :: uj, vj, uspan, vspan\n real (kind=8) :: ubasis(0:p), vbasis(0:q)\n uspan = FindSpan(n,p,uu,U)\n call BasisFuns(uspan,uu,p,U,ubasis)\n vspan = FindSpan(m,q,vv,V)\n call BasisFuns(vspan,vv,q,V,vbasis)\n S = 0\n do uj = 0, p\n do vj = 0, q\n S = S + ubasis(uj)*vbasis(vj)*Pw(:,vspan-q+vj,uspan-p+uj)\n end do\n end do\nend subroutine SurfacePoint\n\nsubroutine CurvePntByCornerCut(d,n,p,U,Pw,x,Cw)\n implicit none\n integer(kind=4), intent(in) :: d\n integer(kind=4), intent(in) :: n, p\n real (kind=8), intent(in) :: U(0:n+p+1)\n real (kind=8), intent(in) :: Pw(d,0:n)\n real (kind=8), intent(in) :: x\n real (kind=8), intent(out) :: Cw(d)\n integer(kind=4) :: i, j, k, s, r\n real (kind=8) :: uu, alpha, Rw(d,0:p)\n if (x <= U(p)) then\n uu = U(p)\n k = p\n s = FindMult(p,uu,p,U)\n if (s >= p) then\n Cw(:) = Pw(:,0)\n return\n end if\n elseif (x >= U(n+1)) then\n uu = U(n+1)\n k = n+1\n s = FindMult(n,uu,p,U)\n if (s >= p) then\n Cw(:) = Pw(:,n)\n return\n end if\n else\n uu = x\n k = FindSpan(n,p,uu,U)\n s = FindMult(k,uu,p,U)\n if (s >= p) then\n Cw(:) = Pw(:,k-p)\n return\n end if\n end if\n r = p-s\n do i = 0, r\n Rw(:,i) = Pw(:,k-p+i)\n end do\n do j = 1, r\n do i = 0, r-j\n alpha = (uu-U(k-p+j+i))/(U(i+k+1)-U(k-p+j+i))\n Rw(:,i) = alpha*Rw(:,i+1)+(1-alpha)*Rw(:,i)\n end do\n end do\n Cw(:) = Rw(:,0)\nend subroutine CurvePntByCornerCut\n\nsubroutine InsertKnot(d,n,p,U,Pw,uu,k,s,r,V,Qw)\n implicit none\n integer(kind=4), intent(in) :: d\n integer(kind=4), intent(in) :: n, p\n real (kind=8), intent(in) :: U(0:n+p+1)\n real (kind=8), intent(in) :: Pw(d,0:n)\n real (kind=8), intent(in) :: uu\n integer(kind=4), intent(in) :: k, s, r\n real (kind=8), intent(out) :: V(0:n+p+1+r)\n real (kind=8), intent(out) :: Qw(d,0:n+r)\n integer(kind=4) :: i, j, idx\n real (kind=8) :: alpha, Rw(d,0:p)\n ! Load new knot vector\n forall (i = 0:k) V(i) = U(i)\n forall (i = 1:r) V(k+i) = uu\n forall (i = k+1:n+p+1) V(i+r) = U(i)\n ! Save unaltered control points\n forall (i = 0:k-p) Qw(:,i) = Pw(:,i)\n forall (i = k-s:n) Qw(:,i+r) = Pw(:,i)\n forall (i = 0:p-s) Rw(:,i) = Pw(:,k-p+i)\n ! Insert the knot r times\n do j = 1, r\n idx = k-p+j\n do i = 0, p-j-s\n alpha = (uu-U(idx+i))/(U(i+k+1)-U(idx+i))\n Rw(:,i) = alpha*Rw(:,i+1)+(1-alpha)*Rw(:,i)\n end do\n Qw(:,idx) = Rw(:,0)\n Qw(:,k+r-j-s) = Rw(:,p-j-s)\n end do\n ! Load remaining control points\n idx = k-p+r\n do i = idx+1, k-s-1\n Qw(:,i) = Rw(:,i-idx)\n end do\nend subroutine InsertKnot\n\nsubroutine RemoveKnot(d,n,p,U,Pw,uu,r,s,num,t,TOL)\n implicit none\n integer(kind=4), intent(in) :: d\n integer(kind=4), intent(in) :: n, p\n real (kind=8), intent(inout) :: U(0:n+p+1)\n real (kind=8), intent(inout) :: Pw(d,0:n)\n real (kind=8), intent(in) :: uu\n integer(kind=4), intent(in) :: r, s, num\n integer(kind=4), intent(out) :: t\n real (kind=8), intent(in) :: TOL\n\n integer(kind=4) :: m,ord,fout,last,first,off\n integer(kind=4) :: i,j,ii,jj,k\n logical :: remflag\n real (kind=8) :: temp(d,0:2*p)\n real (kind=8) :: alfi,alfj\n\n m = n + p + 1\n ord = p + 1\n fout = (2*r-s-p)/2\n first = r - p\n last = r - s\n do t = 0,num-1\n off = first - 1\n temp(:,0) = Pw(:,off)\n temp(:,last+1-off) = Pw(:,last+1)\n i = first; ii = 1\n j = last; jj = last - off\n remflag = .false.\n do while (j-i > t)\n alfi = (uu-U(i))/(U(i+ord+t)-U(i))\n alfj = (uu-U(j-t))/(U(j+ord)-U(j-t))\n temp(:,ii) = (Pw(:,i)-(1-alfi)*temp(:,ii-1))/alfi\n temp(:,jj) = (Pw(:,j)-alfj*temp(:,jj+1))/(1-alfj)\n i = i + 1; ii = ii + 1\n j = j - 1; jj = jj - 1\n end do\n if (j-i < t) then\n if (Distance(d,temp(:,ii-1),temp(:,jj+1)) <= TOL) then\n remflag = .true.\n end if\n else\n alfi = (uu-U(i))/(U(i+ord+t)-U(i))\n if (Distance(d,Pw(:,i),alfi*temp(:,ii+t+1)+(1-alfi)*temp(:,ii-1)) <= TOL) then\n remflag = .true.\n end if\n end if\n if (remflag .eqv. .false.) then\n exit ! break out of the for loop\n else\n i = first\n j = last\n do while (j-i > t)\n Pw(:,i) = temp(:,i-off)\n Pw(:,j) = temp(:,j-off)\n i = i + 1\n j = j - 1\n end do\n end if\n first = first - 1\n last = last + 1\n end do\n if (t == 0) return\n do k = r+1,m\n U(k-t) = U(k)\n end do\n j = fout\n i = j\n do k = 1,t-1\n if (mod(k,2) == 1) then\n i = i + 1\n else\n j = j - 1\n end if\n end do\n do k = i+1,n\n Pw(:,j) = Pw(:,k)\n j = j + 1\n enddo\ncontains\n function Distance(d,P1,P2) result (dist)\n implicit none\n integer(kind=4), intent(in) :: d\n real (kind=8), intent(in) :: P1(d),P2(d)\n integer(kind=4) :: i\n real (kind=8) :: dist\n dist = 0\n do i = 1,d\n dist = dist + (P1(i)-P2(i))*(P1(i)-P2(i))\n end do\n dist = sqrt(dist)\n end function Distance\nend subroutine RemoveKnot\n\nsubroutine ClampKnot(d,n,p,U,Pw,l,r)\n implicit none\n integer(kind=4), intent(in) :: d\n integer(kind=4), intent(in) :: n, p\n real (kind=8), intent(inout) :: U(0:n+p+1)\n real (kind=8), intent(inout) :: Pw(d,0:n)\n logical(kind=4), intent(in) :: l, r\n real (kind=8) :: uu\n integer(kind=4) :: k, s\n if (l) then ! Clamp at left end\n uu = U(p)\n s = FindMult(p,uu,p,U)\n k = p\n if (s < p) call KntIns(d,n,p,U,Pw,uu,k,p-s)\n U(0:p-1) = U(p)\n end if\n if (r) then ! Clamp at right end\n uu = U(n+1)\n s = FindMult(n,uu,p,U)\n k = n+s\n if (s < p) call KntIns(d,n,p,U,Pw,uu,k,p-s)\n U(n+2:n+p+1) = U(n+1)\n end if\ncontains\n subroutine KntIns(d,n,p,U,Pw,uu,k,r)\n implicit none\n integer(kind=4), intent(in) :: d\n integer(kind=4), intent(in) :: n, p\n real (kind=8), intent(in) :: U(0:n+p+1)\n real (kind=8), intent(inout) :: Pw(d,0:n)\n real (kind=8), intent(in) :: uu\n integer(kind=4), intent(in) :: k, r\n integer(kind=4) :: i, j, idx\n real (kind=8) :: alpha, Rw(d,0:r), Qw(d,0:r+r-1)\n Qw(:,0) = Pw(:,k-p)\n Rw(:,0:r) = Pw(:,k-p:k-p+r)\n do j = 1, r\n idx = k-p+j\n do i = 0, r-j\n alpha = (uu-U(idx+i))/(U(k+i+1)-U(idx+i))\n Rw(:,i) = alpha*Rw(:,i+1)+(1-alpha)*Rw(:,i)\n end do\n Qw(:,j) = Rw(:,0)\n Qw(:,r+r-j) = Rw(:,r-j)\n end do\n if (k == p) then ! left end\n Pw(:,0:r-1) = Qw(:,r:r+r-1)\n else ! right end\n Pw(:,n-r+1:n) = Qw(:,1:r)\n end if\n end subroutine KntIns\nend subroutine ClampKnot\n\nsubroutine UnclampKnot(d,n,p,U,Pw,C,l,r)\n implicit none\n integer(kind=4), intent(in) :: d\n integer(kind=4), intent(in) :: n, p\n real (kind=8), intent(inout) :: U(0:n+p+1)\n real (kind=8), intent(inout) :: Pw(d,0:n)\n integer(kind=4), intent(in) :: C\n logical(kind=4), intent(in) :: l, r\n integer(kind=4) :: m, i, j\n real (kind=8) :: alpha\n if (l) then ! Unclamp at left end\n do i = 0, C\n U(C-i) = U(p) - U(n+1) + U(n-i)\n end do\n do i = p-C-1, p-2\n do j = i, 0, -1\n alpha = (U(p)-U(p+j-i-1))/(U(p+j+1)-U(p+j-i-1))\n Pw(:,j) = (Pw(:,j)-alpha*Pw(:,j+1))/(1-alpha)\n end do\n end do\n end if\n if (r) then ! Unclamp at right end\n m = n+p+1\n do i = 0, C\n U(m-C+i) = U(n+1) - U(p) + U(p+i+1)\n end do\n do i = p-C-1, p-2\n do j = i, 0, -1\n alpha = (U(n+1)-U(n-j))/(U(n-j+i+2)-U(n-j))\n Pw(:,n-j) = (Pw(:,n-j)-(1-alpha)*Pw(:,n-j-1))/alpha\n end do\n end do\n end if\nend subroutine UnclampKnot\n\nsubroutine RefineKnotVector(d,n,p,U,Pw,r,X,Ubar,Qw)\n implicit none\n integer(kind=4), intent(in) :: d\n integer(kind=4), intent(in) :: n, p\n real (kind=8), intent(in) :: U(0:n+p+1)\n real (kind=8), intent(in) :: Pw(d,0:n)\n integer(kind=4), intent(in) :: r\n real (kind=8), intent(in) :: X(0:r)\n real (kind=8), intent(out) :: Ubar(0:n+r+1+p+1)\n real (kind=8), intent(out) :: Qw(d,0:n+r+1)\n integer(kind=4) :: m, a, b\n integer(kind=4) :: i, j, k, l\n integer(kind=4) :: idx\n real (kind=8) :: alpha\n if (r < 0) then\n Ubar = U\n Qw = Pw\n return\n end if\n m = n + p + 1\n a = FindSpan(n,p,X(0),U)\n b = FindSpan(n,p,X(r),U)\n b = b + 1\n forall (j = 0:a-p) Qw(:,j) = Pw(:,j)\n forall (j = b-1:n) Qw(:,j+r+1) = Pw(:,j)\n forall (j = 0:a) Ubar(j) = U(j)\n forall (j = b+p:m) Ubar(j+r+1) = U(j)\n i = b + p - 1\n k = b + p + r\n do j = r, 0, -1\n do while (X(j) <= U(i) .and. i > a)\n Qw(:,k-p-1) = Pw(:,i-p-1)\n Ubar(k) = U(i)\n k = k - 1\n i = i - 1\n end do\n Qw(:,k-p-1) = Qw(:,k-p)\n do l = 1, p\n idx = k - p + l\n alpha = Ubar(k+l) - X(j)\n if (abs(alpha) < epsilon(alpha)) then\n Qw(:,idx-1) = Qw(:,idx)\n else\n alpha = alpha / (Ubar(k+l) - U(i-p+l))\n Qw(:,idx-1) = alpha*Qw(:,idx-1) + (1-alpha)*Qw(:,idx)\n end if\n end do\n Ubar(k) = X(j)\n k = k-1\n end do\nend subroutine RefineKnotVector\n\nsubroutine DegreeElevate(d,n,p,U,Pw,t,nh,Uh,Qw)\n implicit none\n integer(kind=4), intent(in) :: d\n integer(kind=4), intent(in) :: n, p\n real (kind=8), intent(in) :: U(0:n+p+1)\n real (kind=8), intent(in) :: Pw(d,0:n)\n integer(kind=4), intent(in) :: t\n integer(kind=4), intent(in) :: nh\n real (kind=8), intent(out) :: Uh(0:nh+p+t+1)\n real (kind=8), intent(out) :: Qw(d,0:nh)\n\n integer(kind=4) :: i, j, k, kj, tr, a, b\n integer(kind=4) :: m, ph, kind, cind, first, last\n integer(kind=4) :: r, oldr, s, mul, lbz, rbz\n\n real (kind=8) :: bezalfs(0:p+t,0:p)\n real (kind=8) :: bpts(d,0:p), ebpts(d,0:p+t), nextbpts(d,0:p-2)\n real (kind=8) :: alfs(0:p-2), ua, ub, alf, bet, gam, den\n if (t < 1) then\n Uh = U\n Qw = Pw\n return\n end if\n m = n + p + 1\n ph = p + t\n ! Bezier coefficients\n bezalfs(0,0) = 1\n bezalfs(ph,p) = 1\n do i = 1, ph/2\n den = Bin(ph,i)\n do j = max(0,i-t), min(p,i)\n bezalfs(i,j) = Bin(p,j)*Bin(t,i-j)/den\n end do\n end do\n do i = ph/2+1, ph-1\n do j = max(0,i-t), min(p,i)\n bezalfs(i,j) = bezalfs(ph-i,p-j)\n end do\n end do\n kind = ph+1\n cind = 1\n r = -1\n a = p\n b = p+1\n ua = U(a)\n Uh(0:ph) = ua\n Qw(:,0) = Pw(:,0)\n bpts = Pw(:,0:p)\n do while (b < m)\n i = b\n do while (b < m)\n if (abs(U(b) - U(b+1))>epsilon(U)) exit\n b = b + 1\n end do\n mul = b - i + 1\n oldr = r\n r = p - mul\n ub = U(b)\n if (oldr > 0) then\n lbz = (oldr+2)/2\n else\n lbz = 1\n end if\n if (r > 0) then\n rbz = ph - (r+1)/2\n else\n rbz = ph\n end if\n ! insert knots\n if (r > 0) then\n do k = p, mul+1, -1\n alfs(k-mul-1) = (ub-ua)/(U(a+k)-ua)\n end do\n do j = 1, r\n s = mul + j\n do k = p, s, -1\n bpts(:,k) = alfs(k-s) * bpts(:,k) + &\n (1-alfs(k-s)) * bpts(:,k-1)\n end do\n nextbpts(:,r-j) = bpts(:,p)\n end do\n end if\n ! degree elevate\n do i = lbz, ph\n ebpts(:,i) = 0\n do j = max(0,i-t), min(p,i)\n ebpts(:,i) = ebpts(:,i) + bezalfs(i,j)*bpts(:,j)\n end do\n end do\n ! remove knots\n if (oldr > 1) then\n first = kind-2\n last = kind\n den = ub-ua\n bet = (ub-Uh(kind-1))/den\n do tr = 1, oldr-1\n i = first\n j = last\n kj = j-kind+1\n do while (j-i > tr)\n if (i < cind) then\n alf = (ub-Uh(i))/(ua-Uh(i))\n Qw(:,i) = alf*Qw(:,i) + (1-alf)*Qw(:,i-1)\n end if\n if (j >= lbz) then\n if (j-tr <= kind-ph+oldr) then\n gam = (ub-Uh(j-tr))/den\n ebpts(:,kj) = gam*ebpts(:,kj) + (1-gam)*ebpts(:,kj+1)\n else\n ebpts(:,kj) = bet*ebpts(:,kj) + (1-bet)*ebpts(:,kj+1)\n end if\n end if\n i = i+1\n j = j-1\n kj = kj-1\n end do\n first = first-1\n last = last+1\n end do\n end if\n !\n if (a /= p) then\n do i = 0, ph-oldr-1\n Uh(kind) = ua\n kind = kind+1\n end do\n end if\n do j = lbz, rbz\n Qw(:, cind) = ebpts(:,j)\n cind = cind+1\n end do\n !\n if (b < m) then\n bpts(:,0:r-1) = nextbpts(:,0:r-1)\n bpts(:,r:p) = Pw(:,b-p+r:b)\n a = b\n b = b+1\n ua = ub\n else\n Uh(kind:kind+ph) = ub\n end if\n end do\ncontains\n pure function Bin(n,k) result (C)\n implicit none\n integer(kind=4), intent(in) :: n, k\n integer(kind=4) :: i, C\n C = 1\n do i = 0, min(k,n-k) - 1\n C = C * (n - i)\n C = C / (i + 1)\n end do\n end function Bin\nend subroutine DegreeElevate\n\nend module bspline\n\n!\n! ----------\n!\n\nmodule bspeval\ncontains\nsubroutine TensorProd1(ina,iN,N0,N1,N2,N3,N4)\n implicit none\n integer(kind=4), intent(in) :: ina\n real (kind=8), intent(in) :: iN(ina,0:4)\n real (kind=8), intent(out) :: N0( ina)\n real (kind=8), intent(out) :: N1(1,ina)\n real (kind=8), intent(out), optional :: N2( 1,1,ina)\n real (kind=8), intent(out), optional :: N3( 1,1,1,ina)\n real (kind=8), intent(out), optional :: N4(1,1,1,1,ina)\n integer(kind=4) :: ia\n do ia=1,ina\n N0(ia) = iN(ia,0)\n end do\n do ia=1,ina\n N1(1,ia) = iN(ia,1)\n end do\n if (.not. present(N2)) return\n do ia=1,ina\n N2(1,1,ia) = iN(ia,2)\n end do\n if (.not. present(N3)) return\n do ia=1,ina\n N3(1,1,1,ia) = iN(ia,3)\n end do\n if (.not. present(N4)) return\n do ia=1,ina\n N4(1,1,1,1,ia) = iN(ia,3)\n end do\nend subroutine TensorProd1\nsubroutine TensorProd2(ina,jna,iN,jN,N0,N1,N2,N3,N4)\n implicit none\n integer(kind=4), intent(in) :: ina, jna\n real (kind=8), intent(in) :: iN(ina,0:4)\n real (kind=8), intent(in) :: jN(jna,0:4)\n real (kind=8), intent(out) :: N0( ina,jna)\n real (kind=8), intent(out) :: N1(2,ina,jna)\n real (kind=8), intent(out), optional :: N2( 2,2,ina,jna)\n real (kind=8), intent(out), optional :: N3( 2,2,2,ina,jna)\n real (kind=8), intent(out), optional :: N4(2,2,2,2,ina,jna)\n integer(kind=4) :: ia, ja\n do ja=1,jna; do ia=1,ina\n N0(ia,ja) = iN(ia,0) * jN(ja,0)\n end do; end do\n do ja=1,jna; do ia=1,ina\n N1(1,ia,ja) = iN(ia,1) * jN(ja,0)\n N1(2,ia,ja) = iN(ia,0) * jN(ja,1)\n end do; end do\n if (.not. present(N2)) return\n do ja=1,jna; do ia=1,ina\n N2(1,1,ia,ja) = iN(ia,2) * jN(ja,0)\n N2(2,1,ia,ja) = iN(ia,1) * jN(ja,1)\n N2(1,2,ia,ja) = iN(ia,1) * jN(ja,1)\n N2(2,2,ia,ja) = iN(ia,0) * jN(ja,2)\n end do; end do\n if (.not. present(N3)) return\n do ja=1,jna; do ia=1,ina\n N3(1,1,1,ia,ja) = iN(ia,3) * jN(ja,0)\n N3(2,1,1,ia,ja) = iN(ia,2) * jN(ja,1)\n N3(1,2,1,ia,ja) = iN(ia,2) * jN(ja,1)\n N3(2,2,1,ia,ja) = iN(ia,1) * jN(ja,2)\n N3(1,1,2,ia,ja) = iN(ia,2) * jN(ja,1)\n N3(2,1,2,ia,ja) = iN(ia,1) * jN(ja,2)\n N3(1,2,2,ia,ja) = iN(ia,1) * jN(ja,2)\n N3(2,2,2,ia,ja) = iN(ia,0) * jN(ja,3)\n end do; end do\n if (.not. present(N4)) return\n do ja=1,jna; do ia=1,ina\n N4(1,1,1,1,ia,ja) = iN(ia,4) * jN(ja,0)\n N4(2,1,1,1,ia,ja) = iN(ia,3) * jN(ja,1)\n N4(1,2,1,1,ia,ja) = iN(ia,3) * jN(ja,1)\n N4(2,2,1,1,ia,ja) = iN(ia,2) * jN(ja,2)\n N4(1,1,2,1,ia,ja) = iN(ia,3) * jN(ja,1)\n N4(2,1,2,1,ia,ja) = iN(ia,2) * jN(ja,2)\n N4(1,2,2,1,ia,ja) = iN(ia,2) * jN(ja,2)\n N4(2,2,2,1,ia,ja) = iN(ia,1) * jN(ja,3)\n N4(1,1,1,2,ia,ja) = iN(ia,3) * jN(ja,1)\n N4(2,1,1,2,ia,ja) = iN(ia,2) * jN(ja,2)\n N4(1,2,1,2,ia,ja) = iN(ia,2) * jN(ja,2)\n N4(2,2,1,2,ia,ja) = iN(ia,1) * jN(ja,3)\n N4(1,1,2,2,ia,ja) = iN(ia,2) * jN(ja,2)\n N4(2,1,2,2,ia,ja) = iN(ia,1) * jN(ja,3)\n N4(1,2,2,2,ia,ja) = iN(ia,1) * jN(ja,3)\n N4(2,2,2,2,ia,ja) = iN(ia,0) * jN(ja,4)\n end do; end do\nend subroutine TensorProd2\nsubroutine TensorProd3(ina,jna,kna,iN,jN,kN,N0,N1,N2,N3,N4)\n implicit none\n integer(kind=4), intent(in) :: ina, jna, kna\n real (kind=8), intent(in) :: iN(ina,0:4)\n real (kind=8), intent(in) :: jN(jna,0:4)\n real (kind=8), intent(in) :: kN(kna,0:4)\n real (kind=8), intent(out) :: N0( ina,jna,kna)\n real (kind=8), intent(out) :: N1(3,ina,jna,kna)\n real (kind=8), intent(out), optional :: N2( 3,3,ina,jna,kna)\n real (kind=8), intent(out), optional :: N3( 3,3,3,ina,jna,kna)\n real (kind=8), intent(out), optional :: N4(3,3,3,3,ina,jna,kna)\n integer(kind=4) :: ia, ja, ka\n do ja=1,jna; do ia=1,ina; do ka=1,kna\n N0(ia,ja,ka) = iN(ia,0) * jN(ja,0) * kN(ka,0)\n end do; end do; end do\n do ja=1,jna; do ia=1,ina; do ka=1,kna\n N1(1,ia,ja,ka) = iN(ia,1) * jN(ja,0) * kN(ka,0)\n N1(2,ia,ja,ka) = iN(ia,0) * jN(ja,1) * kN(ka,0)\n N1(3,ia,ja,ka) = iN(ia,0) * jN(ja,0) * kN(ka,1)\n end do; end do; end do\n if (.not. present(N2)) return\n do ja=1,jna; do ia=1,ina; do ka=1,kna\n N2(1,1,ia,ja,ka) = iN(ia,2) * jN(ja,0) * kN(ka,0)\n N2(2,1,ia,ja,ka) = iN(ia,1) * jN(ja,1) * kN(ka,0)\n N2(3,1,ia,ja,ka) = iN(ia,1) * jN(ja,0) * kN(ka,1)\n N2(1,2,ia,ja,ka) = iN(ia,1) * jN(ja,1) * kN(ka,0)\n N2(2,2,ia,ja,ka) = iN(ia,0) * jN(ja,2) * kN(ka,0)\n N2(3,2,ia,ja,ka) = iN(ia,0) * jN(ja,1) * kN(ka,1)\n N2(1,3,ia,ja,ka) = iN(ia,1) * jN(ja,0) * kN(ka,1)\n N2(2,3,ia,ja,ka) = iN(ia,0) * jN(ja,1) * kN(ka,1)\n N2(3,3,ia,ja,ka) = iN(ia,0) * jN(ja,0) * kN(ka,2)\n end do; end do; end do\n if (.not. present(N3)) return\n do ja=1,jna; do ia=1,ina; do ka=1,kna\n N3(1,1,1,ia,ja,ka) = iN(ia,3) * jN(ja,0) * kN(ka,0)\n N3(2,1,1,ia,ja,ka) = iN(ia,2) * jN(ja,1) * kN(ka,0)\n N3(3,1,1,ia,ja,ka) = iN(ia,2) * jN(ja,0) * kN(ka,1)\n N3(1,2,1,ia,ja,ka) = iN(ia,2) * jN(ja,1) * kN(ka,0)\n N3(2,2,1,ia,ja,ka) = iN(ia,1) * jN(ja,2) * kN(ka,0)\n N3(3,2,1,ia,ja,ka) = iN(ia,1) * jN(ja,1) * kN(ka,1)\n N3(1,3,1,ia,ja,ka) = iN(ia,2) * jN(ja,0) * kN(ka,1)\n N3(2,3,1,ia,ja,ka) = iN(ia,1) * jN(ja,1) * kN(ka,1)\n N3(3,3,1,ia,ja,ka) = iN(ia,1) * jN(ja,0) * kN(ka,2)\n N3(1,1,2,ia,ja,ka) = iN(ia,2) * jN(ja,1) * kN(ka,0)\n N3(2,1,2,ia,ja,ka) = iN(ia,1) * jN(ja,2) * kN(ka,0)\n N3(3,1,2,ia,ja,ka) = iN(ia,1) * jN(ja,1) * kN(ka,1)\n N3(1,2,2,ia,ja,ka) = iN(ia,1) * jN(ja,2) * kN(ka,0)\n N3(2,2,2,ia,ja,ka) = iN(ia,0) * jN(ja,3) * kN(ka,0)\n N3(3,2,2,ia,ja,ka) = iN(ia,0) * jN(ja,2) * kN(ka,1)\n N3(1,3,2,ia,ja,ka) = iN(ia,1) * jN(ja,1) * kN(ka,1)\n N3(2,3,2,ia,ja,ka) = iN(ia,0) * jN(ja,2) * kN(ka,1)\n N3(3,3,2,ia,ja,ka) = iN(ia,0) * jN(ja,1) * kN(ka,2)\n N3(1,1,3,ia,ja,ka) = iN(ia,2) * jN(ja,0) * kN(ka,1)\n N3(2,1,3,ia,ja,ka) = iN(ia,1) * jN(ja,1) * kN(ka,1)\n N3(3,1,3,ia,ja,ka) = iN(ia,1) * jN(ja,0) * kN(ka,2)\n N3(1,2,3,ia,ja,ka) = iN(ia,1) * jN(ja,1) * kN(ka,1)\n N3(2,2,3,ia,ja,ka) = iN(ia,0) * jN(ja,2) * kN(ka,1)\n N3(3,2,3,ia,ja,ka) = iN(ia,0) * jN(ja,1) * kN(ka,2)\n N3(1,3,3,ia,ja,ka) = iN(ia,1) * jN(ja,0) * kN(ka,2)\n N3(2,3,3,ia,ja,ka) = iN(ia,0) * jN(ja,1) * kN(ka,2)\n N3(3,3,3,ia,ja,ka) = iN(ia,0) * jN(ja,0) * kN(ka,3)\n end do; end do; end do\n if (.not. present(N4)) return\n do ka=1,kna; do ja=1,jna; do ia=1,ina\n N4(1,1,1,1,ia,ja,ka) = iN(ia,4) * jN(ja,0) * kN(ka,0)\n N4(2,1,1,1,ia,ja,ka) = iN(ia,3) * jN(ja,1) * kN(ka,0)\n N4(3,1,1,1,ia,ja,ka) = iN(ia,3) * jN(ja,0) * kN(ka,1)\n N4(1,2,1,1,ia,ja,ka) = iN(ia,3) * jN(ja,1) * kN(ka,0)\n N4(2,2,1,1,ia,ja,ka) = iN(ia,2) * jN(ja,2) * kN(ka,0)\n N4(3,2,1,1,ia,ja,ka) = iN(ia,2) * jN(ja,1) * kN(ka,1)\n N4(1,3,1,1,ia,ja,ka) = iN(ia,3) * jN(ja,0) * kN(ka,1)\n N4(2,3,1,1,ia,ja,ka) = iN(ia,2) * jN(ja,1) * kN(ka,1)\n N4(3,3,1,1,ia,ja,ka) = iN(ia,2) * jN(ja,0) * kN(ka,2)\n N4(1,1,2,1,ia,ja,ka) = iN(ia,3) * jN(ja,1) * kN(ka,0)\n N4(2,1,2,1,ia,ja,ka) = iN(ia,2) * jN(ja,2) * kN(ka,0)\n N4(3,1,2,1,ia,ja,ka) = iN(ia,2) * jN(ja,1) * kN(ka,1)\n N4(1,2,2,1,ia,ja,ka) = iN(ia,2) * jN(ja,2) * kN(ka,0)\n N4(2,2,2,1,ia,ja,ka) = iN(ia,1) * jN(ja,3) * kN(ka,0)\n N4(3,2,2,1,ia,ja,ka) = iN(ia,1) * jN(ja,2) * kN(ka,1)\n N4(1,3,2,1,ia,ja,ka) = iN(ia,2) * jN(ja,1) * kN(ka,1)\n N4(2,3,2,1,ia,ja,ka) = iN(ia,1) * jN(ja,2) * kN(ka,1)\n N4(3,3,2,1,ia,ja,ka) = iN(ia,1) * jN(ja,1) * kN(ka,2)\n N4(1,1,3,1,ia,ja,ka) = iN(ia,3) * jN(ja,0) * kN(ka,1)\n N4(2,1,3,1,ia,ja,ka) = iN(ia,2) * jN(ja,1) * kN(ka,1)\n N4(3,1,3,1,ia,ja,ka) = iN(ia,2) * jN(ja,0) * kN(ka,2)\n N4(1,2,3,1,ia,ja,ka) = iN(ia,2) * jN(ja,1) * kN(ka,1)\n N4(2,2,3,1,ia,ja,ka) = iN(ia,1) * jN(ja,2) * kN(ka,1)\n N4(3,2,3,1,ia,ja,ka) = iN(ia,1) * jN(ja,1) * kN(ka,2)\n N4(1,3,3,1,ia,ja,ka) = iN(ia,2) * jN(ja,0) * kN(ka,2)\n N4(2,3,3,1,ia,ja,ka) = iN(ia,1) * jN(ja,1) * kN(ka,2)\n N4(3,3,3,1,ia,ja,ka) = iN(ia,1) * jN(ja,0) * kN(ka,3)\n N4(1,1,1,2,ia,ja,ka) = iN(ia,3) * jN(ja,1) * kN(ka,0)\n N4(2,1,1,2,ia,ja,ka) = iN(ia,2) * jN(ja,2) * kN(ka,0)\n N4(3,1,1,2,ia,ja,ka) = iN(ia,2) * jN(ja,1) * kN(ka,1)\n N4(1,2,1,2,ia,ja,ka) = iN(ia,2) * jN(ja,2) * kN(ka,0)\n N4(2,2,1,2,ia,ja,ka) = iN(ia,1) * jN(ja,3) * kN(ka,0)\n N4(3,2,1,2,ia,ja,ka) = iN(ia,1) * jN(ja,2) * kN(ka,1)\n N4(1,3,1,2,ia,ja,ka) = iN(ia,2) * jN(ja,1) * kN(ka,1)\n N4(2,3,1,2,ia,ja,ka) = iN(ia,1) * jN(ja,2) * kN(ka,1)\n N4(3,3,1,2,ia,ja,ka) = iN(ia,1) * jN(ja,1) * kN(ka,2)\n N4(1,1,2,2,ia,ja,ka) = iN(ia,2) * jN(ja,2) * kN(ka,0)\n N4(2,1,2,2,ia,ja,ka) = iN(ia,1) * jN(ja,3) * kN(ka,0)\n N4(3,1,2,2,ia,ja,ka) = iN(ia,1) * jN(ja,2) * kN(ka,1)\n N4(1,2,2,2,ia,ja,ka) = iN(ia,1) * jN(ja,3) * kN(ka,0)\n N4(2,2,2,2,ia,ja,ka) = iN(ia,0) * jN(ja,4) * kN(ka,0)\n N4(3,2,2,2,ia,ja,ka) = iN(ia,0) * jN(ja,3) * kN(ka,1)\n N4(1,3,2,2,ia,ja,ka) = iN(ia,1) * jN(ja,2) * kN(ka,1)\n N4(2,3,2,2,ia,ja,ka) = iN(ia,0) * jN(ja,3) * kN(ka,1)\n N4(3,3,2,2,ia,ja,ka) = iN(ia,0) * jN(ja,2) * kN(ka,2)\n N4(1,1,3,2,ia,ja,ka) = iN(ia,2) * jN(ja,1) * kN(ka,1)\n N4(2,1,3,2,ia,ja,ka) = iN(ia,1) * jN(ja,2) * kN(ka,1)\n N4(3,1,3,2,ia,ja,ka) = iN(ia,1) * jN(ja,1) * kN(ka,2)\n N4(1,2,3,2,ia,ja,ka) = iN(ia,1) * jN(ja,2) * kN(ka,1)\n N4(2,2,3,2,ia,ja,ka) = iN(ia,0) * jN(ja,3) * kN(ka,1)\n N4(3,2,3,2,ia,ja,ka) = iN(ia,0) * jN(ja,2) * kN(ka,2)\n N4(1,3,3,2,ia,ja,ka) = iN(ia,1) * jN(ja,1) * kN(ka,2)\n N4(2,3,3,2,ia,ja,ka) = iN(ia,0) * jN(ja,2) * kN(ka,2)\n N4(3,3,3,2,ia,ja,ka) = iN(ia,0) * jN(ja,1) * kN(ka,3)\n N4(1,1,1,3,ia,ja,ka) = iN(ia,3) * jN(ja,0) * kN(ka,1)\n N4(2,1,1,3,ia,ja,ka) = iN(ia,2) * jN(ja,1) * kN(ka,1)\n N4(3,1,1,3,ia,ja,ka) = iN(ia,2) * jN(ja,0) * kN(ka,2)\n N4(1,2,1,3,ia,ja,ka) = iN(ia,2) * jN(ja,1) * kN(ka,1)\n N4(2,2,1,3,ia,ja,ka) = iN(ia,1) * jN(ja,2) * kN(ka,1)\n N4(3,2,1,3,ia,ja,ka) = iN(ia,1) * jN(ja,1) * kN(ka,2)\n N4(1,3,1,3,ia,ja,ka) = iN(ia,2) * jN(ja,0) * kN(ka,2)\n N4(2,3,1,3,ia,ja,ka) = iN(ia,1) * jN(ja,1) * kN(ka,2)\n N4(3,3,1,3,ia,ja,ka) = iN(ia,1) * jN(ja,0) * kN(ka,3)\n N4(1,1,2,3,ia,ja,ka) = iN(ia,2) * jN(ja,1) * kN(ka,1)\n N4(2,1,2,3,ia,ja,ka) = iN(ia,1) * jN(ja,2) * kN(ka,1)\n N4(3,1,2,3,ia,ja,ka) = iN(ia,1) * jN(ja,1) * kN(ka,2)\n N4(1,2,2,3,ia,ja,ka) = iN(ia,1) * jN(ja,2) * kN(ka,1)\n N4(2,2,2,3,ia,ja,ka) = iN(ia,0) * jN(ja,3) * kN(ka,1)\n N4(3,2,2,3,ia,ja,ka) = iN(ia,0) * jN(ja,2) * kN(ka,2)\n N4(1,3,2,3,ia,ja,ka) = iN(ia,1) * jN(ja,1) * kN(ka,2)\n N4(2,3,2,3,ia,ja,ka) = iN(ia,0) * jN(ja,2) * kN(ka,2)\n N4(3,3,2,3,ia,ja,ka) = iN(ia,0) * jN(ja,1) * kN(ka,3)\n N4(1,1,3,3,ia,ja,ka) = iN(ia,2) * jN(ja,0) * kN(ka,2)\n N4(2,1,3,3,ia,ja,ka) = iN(ia,1) * jN(ja,1) * kN(ka,2)\n N4(3,1,3,3,ia,ja,ka) = iN(ia,1) * jN(ja,0) * kN(ka,3)\n N4(1,2,3,3,ia,ja,ka) = iN(ia,1) * jN(ja,1) * kN(ka,2)\n N4(2,2,3,3,ia,ja,ka) = iN(ia,0) * jN(ja,2) * kN(ka,2)\n N4(3,2,3,3,ia,ja,ka) = iN(ia,0) * jN(ja,1) * kN(ka,3)\n N4(1,3,3,3,ia,ja,ka) = iN(ia,1) * jN(ja,0) * kN(ka,3)\n N4(2,3,3,3,ia,ja,ka) = iN(ia,0) * jN(ja,1) * kN(ka,3)\n N4(3,3,3,3,ia,ja,ka) = iN(ia,0) * jN(ja,0) * kN(ka,4)\n end do; end do; end do\nend subroutine TensorProd3\nsubroutine Rationalize(nen,dim,W,R0,R1,R2,R3,R4)\n implicit none\n integer(kind=4), intent(in) :: dim\n integer(kind=4), intent(in) :: nen\n real (kind=8), intent(in) :: W(nen)\n real (kind=8), intent(inout) :: R0(nen)\n real (kind=8), intent(inout) :: R1(dim,nen)\n real (kind=8), intent(inout), optional :: R2( dim,dim,nen)\n real (kind=8), intent(inout), optional :: R3( dim,dim,dim,nen)\n real (kind=8), intent(inout), optional :: R4(dim,dim,dim,dim,nen)\n integer(kind=4) :: a, i, j, k, l\n real (kind=8) :: W0, W1(dim), W2(dim,dim)\n real (kind=8) :: W3(dim,dim,dim), W4(dim,dim,dim,dim)\n do a=1,nen\n R0(a) = W(a) * R0(a)\n end do\n W0 = sum(R0)\n R0 = R0 / W0\n do i=1,dim\n W1(i) = sum(W*R1(i,:))\n R1(i,:) = W*R1(i,:) - R0(:) * W1(i)\n end do\n R1 = R1 / W0\n if (.not. present(R2)) return\n do j=1,dim; do i=1,dim\n W2(i,j) = sum(W*R2(i,j,:))\n R2(i,j,:) = W*R2(i,j,:) - R0(:)*W2(i,j) &\n - R1(i,:)*W1(j) - R1(j,:)*W1(i)\n end do; end do\n R2 = R2 / W0\n if (.not. present(R3)) return\n do k=1,dim; do j=1,dim; do i=1,dim\n W3(i,j,k) = sum(W*R3(i,j,k,:))\n R3(i,j,k,:) = W*R3(i,j,k,:) - R0(:)*W3(i,j,k) &\n - R1(i,:)*W2(j,k) - R1(j,:)*W2(i,k) - R1(k,:)*W2(i,j) &\n - R2(j,k,:)*W1(i) - R2(i,k,:)*W1(j) - R2(i,j,:)*W1(k)\n end do; end do; end do\n R3 = R3 / W0\n if (.not. present(R4)) return\n do l=1,dim; do k=1,dim; do j=1,dim; do i=1,dim\n W4(i,j,k,l) = sum(W*R4(i,j,k,l,:))\n R4(i,j,k,l,:) = W*R4(i,j,k,l,:) &\n - R0(:)*W4(i,j,k,l) - R1(l,:)*W3(i,j,k) &\n - R1(k,:)*W3(i,j,l) - R2(k,l,:)*W2(i,j) &\n - R1(j,:)*W3(i,k,l) - R2(j,l,:)*W2(i,k) &\n - R2(j,k,:)*W2(i,l) - R3(j,k,l,:)*W1(i) &\n - R1(i,:)*W3(j,k,l) - R2(i,l,:)*W2(j,k) &\n - R2(i,k,:)*W2(j,l) - R3(i,k,l,:)*W1(j) &\n - R2(i,j,:)*W2(k,l) - R3(i,j,l,:)*W1(k)\n end do; end do; end do; end do\n R4 = R4 / W0\nend subroutine Rationalize\nsubroutine GeometryMap(nen,dim,dof,N1,X,G)\n implicit none\n integer(kind=4), intent(in) :: nen\n integer(kind=4), intent(in) :: dim\n integer(kind=4), intent(in) :: dof\n real (kind=8), intent(in) :: N1(dim,nen)\n real (kind=8), intent(in) :: X (dim,nen)\n real (kind=8), intent(inout) :: G (dim,dof)\n real (kind=8) :: X1(dim,dim)\n real (kind=8) :: E1(dim,dim)\n X1 = matmul(X,transpose(N1))\n E1 = Inverse(dim,X1)\n G = matmul(transpose(E1),G)\nend subroutine GeometryMap\nsubroutine Interpolate(nen,dim,dof,N,U,V)\n implicit none\n integer(kind=4), intent(in) :: nen,dim,dof\n real (kind=8), intent(in) :: N(dim,nen)\n real (kind=8), intent(in) :: U(dof,nen)\n real (kind=8), intent(out) :: V(dim,dof)\n V = matmul(N,transpose(U))\nend subroutine Interpolate\nfunction Determinant(dim,A) result (detA)\n implicit none\n integer(kind=4), intent(in) :: dim\n real (kind=8), intent(in) :: A(dim,dim)\n real (kind=8) :: detA\n select case (dim)\n case (1)\n detA = A(1,1)\n case (2)\n detA = + A(1,1)*A(2,2) - A(2,1)*A(1,2)\n case (3)\n detA = + A(1,1) * ( A(2,2)*A(3,3) - A(3,2)*A(2,3) ) &\n - A(2,1) * ( A(1,2)*A(3,3) - A(3,2)*A(1,3) ) &\n + A(3,1) * ( A(1,2)*A(2,3) - A(2,2)*A(1,3) )\n case default\n detA = 0\n end select\nend function Determinant\nfunction Inverse(dim,A) result (invA)\n implicit none\n integer(kind=4), intent(in) :: dim\n real (kind=8), intent(in) :: A(dim,dim)\n real (kind=8) :: invA(dim,dim)\n real (kind=8) :: detA\n detA = Determinant(dim,A)\n select case (dim)\n case (1)\n invA = 1/detA\n case (2)\n invA(1,1) = + A(2,2)\n invA(2,1) = - A(2,1)\n invA(1,2) = - A(1,2)\n invA(2,2) = + A(1,1)\n invA = invA/detA\n case (3)\n invA(1,1) = + A(2,2)*A(3,3) - A(2,3)*A(3,2)\n invA(2,1) = - A(2,1)*A(3,3) + A(2,3)*A(3,1)\n invA(3,1) = + A(2,1)*A(3,2) - A(2,2)*A(3,1)\n invA(1,2) = - A(1,2)*A(3,3) + A(1,3)*A(3,2)\n invA(2,2) = + A(1,1)*A(3,3) - A(1,3)*A(3,1)\n invA(3,2) = - A(1,1)*A(3,2) + A(1,2)*A(3,1)\n invA(1,3) = + A(1,2)*A(2,3) - A(1,3)*A(2,2)\n invA(2,3) = - A(1,1)*A(2,3) + A(1,3)*A(2,1)\n invA(3,3) = + A(1,1)*A(2,2) - A(1,2)*A(2,1)\n invA = invA/detA\n case default\n invA = 0\n end select\nend function Inverse\nend module bspeval\n\nmodule BSp\ncontains\n\nsubroutine FindSpan(p,m,U,uu,span)\n use bspline, FindS => FindSpan\n implicit none\n integer(kind=4), intent(in) :: p, m\n real (kind=8), intent(in) :: U(0:m), uu\n integer(kind=4), intent(out) :: span\n span = FindS(m-(p+1),p,uu,U)\nend subroutine FindSpan\n\nsubroutine FindMult(p,m,U,uu,span,mult)\n use bspline, FindM => FindMult\n implicit none\n integer(kind=4), intent(in) :: p, m\n real (kind=8), intent(in) :: U(0:m), uu\n integer(kind=4), intent(in) :: span\n integer(kind=4), intent(out) :: mult\n integer(kind=4) :: k\n if (span >= 0) then\n k = span\n else\n k = FindSpan(m-(p+1),p,uu,U)\n end if\n mult = FindM(k,uu,p,U)\nend subroutine FindMult\n\nsubroutine FindSpanMult(p,m,U,uu,k,s)\n use bspline, FindSM => FindSpanMult\n implicit none\n integer(kind=4), intent(in) :: p, m\n real (kind=8), intent(in) :: U(0:m), uu\n integer(kind=4), intent(out) :: k, s\n call FindSM(m-(p+1),p,uu,U,k,s)\nend subroutine FindSpanMult\n\nsubroutine EvalBasisFuns(p,m,U,uu,span,N)\n use bspline\n implicit none\n integer(kind=4), intent(in) :: p, m, span\n real (kind=8), intent(in) :: U(0:m), uu\n real (kind=8), intent(out):: N(0:p)\n integer(kind=4) :: i\n if (span >= 0) then\n i = span\n else\n i = FindSpan(m-(p+1),p,uu,U)\n end if\n call BasisFuns(i,uu,p,U,N)\nend subroutine EvalBasisFuns\n\nsubroutine EvalBasisFunsDers(p,m,U,uu,d,span,dN)\n use bspline\n implicit none\n integer(kind=4), intent(in) :: p, m, d, span\n real (kind=8), intent(in) :: U(0:m), uu\n real (kind=8), intent(out):: dN(0:p,0:d)\n integer(kind=4) :: i\n if (span >= 0) then\n i = span\n else\n i = FindSpan(m-(p+1),p,uu,U)\n end if\n call DersBasisFuns(i,uu,p,d,U,dN)\nend subroutine EvalBasisFunsDers\n\nsubroutine SpanIndex(p,m,U,r,I)\n integer(kind=4), intent(in) :: p, m\n real (kind=8), intent(in) :: U(0:m)\n integer(kind=4), intent(in) :: r\n integer(kind=4), intent(out) :: I(r)\n integer(kind=4) :: k, s\n s = 1\n do k = p, m-(p+1)\n if (abs(U(k) - U(k+1))>epsilon(U)) then\n I(s) = k; s = s + 1\n if (s > r) exit\n end if\n end do\nend subroutine SpanIndex\n\nsubroutine Greville(p,m,U,X)\n implicit none\n integer(kind=4), intent(in) :: p, m\n real (kind=8), intent(in) :: U(0:m)\n real (kind=8), intent(out) :: X(0:m-(p+1))\n integer(kind=4) :: i\n do i = 0, m-(p+1)\n X(i) = sum(U(i+1:i+p)) / p\n end do\nend subroutine Greville\n\nsubroutine InsertKnot(d,n,p,U,Pw,uu,r,V,Qw)\n use bspline, InsKnt => InsertKnot\n implicit none\n integer(kind=4), intent(in) :: d\n integer(kind=4), intent(in) :: n, p\n real (kind=8), intent(in) :: U(0:n+p+1)\n real (kind=8), intent(in) :: Pw(d,0:n)\n real (kind=8), intent(in) :: uu\n integer(kind=4), intent(in) :: r\n real (kind=8), intent(out) :: V(0:n+p+1+r)\n real (kind=8), intent(out) :: Qw(d,0:n+r)\n integer(kind=4) :: k, s\n if (r == 0) then\n V = U; Qw = Pw; return\n end if\n call FindSpanMult(n,p,uu,U,k,s)\n call InsKnt(d,n,p,U,Pw,uu,k,s,r,V,Qw)\nend subroutine InsertKnot\n\nsubroutine RemoveKnot(d,n,p,U,Pw,uu,r,t,V,Qw,TOL)\n use bspline, RemKnt => RemoveKnot\n implicit none\n integer(kind=4), intent(in) :: d\n integer(kind=4), intent(in) :: n, p\n real (kind=8), intent(in) :: U(0:n+p+1)\n real (kind=8), intent(in) :: Pw(d,0:n)\n real (kind=8), intent(in) :: uu\n integer(kind=4), intent(in) :: r\n integer(kind=4), intent(out) :: t\n real (kind=8), intent(out) :: V(0:n+p+1)\n real (kind=8), intent(out) :: Qw(d,0:n)\n real (kind=8), intent(in) :: TOL\n integer(kind=4) :: k, s\n t = 0\n V = U\n Qw = Pw\n if (r == 0) return\n if (uu <= U(p)) return\n if (uu >= U(n+1)) return\n call FindSpanMult(n,p,uu,U,k,s)\n call RemKnt(d,n,p,V,Qw,uu,k,s,r,t,TOL)\nend subroutine RemoveKnot\n\nsubroutine Clamp(d,n,p,U,Pw,l,r,V,Qw)\n use bspline\n implicit none\n integer(kind=4), intent(in) :: d\n integer(kind=4), intent(in) :: n, p\n real (kind=8), intent(in) :: U(0:n+p+1)\n real (kind=8), intent(in) :: Pw(d,0:n)\n logical(kind=4), intent(in) :: l, r\n real (kind=8), intent(out) :: V(0:n+p+1)\n real (kind=8), intent(out) :: Qw(d,0:n)\n V = U\n Qw = Pw\n call ClampKnot(d,n,p,V,Qw,l,r)\nend subroutine Clamp\n\nsubroutine Unclamp(d,n,p,U,Pw,C,l,r,V,Qw)\n use bspline\n implicit none\n integer(kind=4), intent(in) :: d\n integer(kind=4), intent(in) :: n, p\n real (kind=8), intent(in) :: U(0:n+p+1)\n real (kind=8), intent(in) :: Pw(d,0:n)\n integer(kind=4), intent(in) :: C\n logical(kind=4), intent(in) :: l, r\n real (kind=8), intent(out) :: V(0:n+p+1)\n real (kind=8), intent(out) :: Qw(d,0:n)\n V = U\n Qw = Pw\n call ClampKnot(d,n,p,V,Qw,l,r)\n call UnclampKnot(d,n,p,V,Qw,C,l,r)\nend subroutine Unclamp\n\nsubroutine RefineKnotVector(d,n,p,U,Pw,r,X,Ubar,Qw)\n use bspline, RefKnt => RefineKnotVector\n implicit none\n integer(kind=4), intent(in) :: d\n integer(kind=4), intent(in) :: n, p\n real (kind=8), intent(in) :: U(0:n+p+1)\n real (kind=8), intent(in) :: Pw(d,0:n)\n integer(kind=4), intent(in) :: r\n real (kind=8), intent(in) :: X(0:r)\n real (kind=8), intent(out) :: Ubar(0:n+r+1+p+1)\n real (kind=8), intent(out) :: Qw(d,0:n+r+1)\n call RefKnt(d,n,p,U,Pw,r,X,Ubar,Qw)\nend subroutine RefineKnotVector\n\nsubroutine DegreeElevate(d,n,p,U,Pw,t,nh,Uh,Qw)\n use bspline, DegElev => DegreeElevate\n implicit none\n integer(kind=4), intent(in) :: d\n integer(kind=4), intent(in) :: n, p\n real (kind=8), intent(in) :: U(0:n+p+1)\n real (kind=8), intent(in) :: Pw(d,0:n)\n integer(kind=4), intent(in) :: t\n integer(kind=4), intent(in) :: nh\n real (kind=8), intent(out) :: Uh(0:nh+p+t+1)\n real (kind=8), intent(out) :: Qw(d,0:nh)\n call DegElev(d,n,p,U,Pw,t,nh,Uh,Qw)\nend subroutine DegreeElevate\n\nsubroutine Extract(d,n,p,U,Pw,x,Cw)\n use bspline, CornerCut => CurvePntByCornerCut\n implicit none\n integer(kind=4), intent(in) :: d\n integer(kind=4), intent(in) :: n, p\n real (kind=8), intent(in) :: U(0:n+p+1)\n real (kind=8), intent(in) :: Pw(d,0:n)\n real (kind=8), intent(in) :: x\n real (kind=8), intent(out) :: Cw(d)\n call CornerCut(d,n,p,U,Pw,x,Cw)\nend subroutine Extract\n\nsubroutine Evaluate0(d,Pw,Cw)\n integer(kind=4), intent(in) :: d\n real (kind=8), intent(in) :: Pw(d)\n real (kind=8), intent(out) :: Cw(d)\n Cw = Pw\nend subroutine Evaluate0\n\nsubroutine Evaluate1(d,n,p,U,Pw,r,X,Cw)\n use bspline\n implicit none\n integer(kind=4), intent(in) :: d\n integer(kind=4), intent(in) :: n, p\n real (kind=8), intent(in) :: U(0:n+p+1)\n real (kind=8), intent(in) :: Pw(d,0:n)\n integer(kind=4), intent(in) :: r\n real (kind=8), intent(in) :: X(0:r)\n real (kind=8), intent(out) :: Cw(d,0:r)\n integer(kind=4) :: i, j, span\n real (kind=8) :: basis(0:p), C(d)\n !\n do i = 0, r\n span = FindSpan(n,p,X(i),U)\n call BasisFuns(span,X(i),p,U,basis)\n !\n C = 0\n do j = 0, p\n C = C + basis(j)*Pw(:,span-p+j)\n end do\n Cw(:,i) = C\n !\n end do\n !\nend subroutine Evaluate1\n\nsubroutine Evaluate2(d,nx,px,Ux,ny,py,Uy,Pw,rx,X,ry,Y,Cw)\n use bspline\n implicit none\n integer(kind=4), intent(in) :: d\n integer(kind=4), intent(in) :: nx, ny\n integer(kind=4), intent(in) :: px, py\n integer(kind=4), intent(in) :: rx, ry\n real (kind=8), intent(in) :: Ux(0:nx+px+1)\n real (kind=8), intent(in) :: Uy(0:ny+py+1)\n real (kind=8), intent(in) :: Pw(d,0:ny,0:nx)\n real (kind=8), intent(in) :: X(0:rx), Y(0:ry)\n real (kind=8), intent(out) :: Cw(d,0:ry,0:rx)\n integer(kind=4) :: ix, jx, iy, jy, ox, oy\n integer(kind=4) :: spanx(0:rx), spany(0:ry)\n real (kind=8) :: basisx(0:px,0:rx), basisy(0:py,0:ry)\n real (kind=8) :: M, C(d)\n !\n do ix = 0, rx\n spanx(ix) = FindSpan(nx,px,X(ix),Ux)\n call BasisFuns(spanx(ix),X(ix),px,Ux,basisx(:,ix))\n end do\n do iy = 0, ry\n spany(iy) = FindSpan(ny,py,Y(iy),Uy)\n call BasisFuns(spany(iy),Y(iy),py,Uy,basisy(:,iy))\n end do\n !\n do ix = 0, rx\n ox = spanx(ix) - px\n do iy = 0, ry\n oy = spany(iy) - py\n ! ---\n C = 0\n do jx = 0, px\n do jy = 0, py\n M = basisx(jx,ix) * basisy(jy,iy)\n C = C + M * Pw(:,oy+jy,ox+jx)\n end do\n end do\n Cw(:,iy,ix) = C\n ! ---\n end do\n end do\n !\nend subroutine Evaluate2\n\nsubroutine Evaluate3(d,nx,px,Ux,ny,py,Uy,nz,pz,Uz,Pw,rx,X,ry,Y,rz,Z,Cw)\n use bspline\n implicit none\n integer(kind=4), intent(in) :: d\n integer(kind=4), intent(in) :: nx, ny, nz\n integer(kind=4), intent(in) :: px, py, pz\n integer(kind=4), intent(in) :: rx, ry, rz\n real (kind=8), intent(in) :: Ux(0:nx+px+1)\n real (kind=8), intent(in) :: Uy(0:ny+py+1)\n real (kind=8), intent(in) :: Uz(0:nz+pz+1)\n real (kind=8), intent(in) :: Pw(d,0:nz,0:ny,0:nx)\n real (kind=8), intent(in) :: X(0:rx), Y(0:ry), Z(0:rz)\n real (kind=8), intent(out) :: Cw(d,0:rz,0:ry,0:rx)\n integer(kind=4) :: ix, jx, iy, jy, iz, jz, ox, oy, oz\n integer(kind=4) :: spanx(0:rx), spany(0:ry), spanz(0:rz)\n real (kind=8) :: basisx(0:px,0:rx), basisy(0:py,0:ry), basisz(0:pz,0:rz)\n real (kind=8) :: M, C(d)\n !\n do ix = 0, rx\n spanx(ix) = FindSpan(nx,px,X(ix),Ux)\n call BasisFuns(spanx(ix),X(ix),px,Ux,basisx(:,ix))\n end do\n do iy = 0, ry\n spany(iy) = FindSpan(ny,py,Y(iy),Uy)\n call BasisFuns(spany(iy),Y(iy),py,Uy,basisy(:,iy))\n end do\n do iz = 0, rz\n spanz(iz) = FindSpan(nz,pz,Z(iz),Uz)\n call BasisFuns(spanz(iz),Z(iz),pz,Uz,basisz(:,iz))\n end do\n !\n do ix = 0, rx\n ox = spanx(ix) - px\n do iy = 0, ry\n oy = spany(iy) - py\n do iz = 0, rz\n oz = spanz(iz) - pz\n ! ---\n C = 0\n do jx = 0, px\n do jy = 0, py\n do jz = 0, pz\n M = basisx(jx,ix) * basisy(jy,iy) * basisz(jz,iz)\n C = C + M * Pw(:,oz+jz,oy+jy,ox+jx)\n end do\n end do\n end do\n Cw(:,iz,iy,ix) = C\n ! ---\n end do\n end do\n end do\n !\nend subroutine Evaluate3\n\nsubroutine Gradient1(map,d,nx,px,Ux,Pw,F,rx,X,G)\n use bspline\n use bspeval\n implicit none\n integer(kind=4), intent(in) :: map\n integer(kind=4), parameter :: dim = 1\n integer(kind=4), intent(in) :: d\n integer(kind=4), intent(in) :: nx\n integer(kind=4), intent(in) :: px\n integer(kind=4), intent(in) :: rx\n real (kind=8), intent(in) :: Ux(0:nx+px+1)\n real (kind=8), intent(in) :: Pw(4,0:nx)\n real (kind=8), intent(in) :: F (d,0:nx)\n real (kind=8), intent(out) :: G (1,d,0:rx)\n real (kind=8), intent(in) :: X(0:rx)\n integer(kind=4) :: ix, jx, ox, spanx(0:rx)\n real (kind=8) :: Mx(0:px,0:1,0:rx)\n real (kind=8) :: N0( 0:px)\n real (kind=8) :: N1(1,0:px)\n real (kind=8) :: WW( 0:px)\n real (kind=8) :: XX(1,0:px)\n real (kind=8) :: FF(d,0:px)\n real (kind=8) :: GG(1,d)\n !\n do ix = 0, rx\n spanx(ix) = FindSpan(nx,px,X(ix),Ux)\n call DersBasisFuns(spanx(ix),X(ix),px,1,Ux,Mx(:,:,ix))\n end do\n !\n do ix = 0, rx\n ox = spanx(ix) - px\n ! ---\n do jx = 0, px\n FF(:,jx) = F (:,ox+jx)\n WW( jx) = Pw(4,ox+jx)\n if (map/=0) then\n XX(1,jx) = Pw(1,ox+jx) / WW(jx)\n end if\n end do\n ! ---\n call TensorProd1((px+1),Mx(:,:,ix),N0,N1)\n call Rationalize((px+1),dim,WW,N0,N1)\n call Interpolate((px+1),dim,d,N1,FF,GG)\n if (map/=0) call GeometryMap((px+1),dim,d,N1,XX,GG)\n ! --\n G(:,:,ix) = GG\n ! ---\n end do\n !\nend subroutine Gradient1\n\nsubroutine Gradient2(map,d,nx,px,Ux,ny,py,Uy,Pw,F,rx,X,ry,Y,G)\n use bspline\n use bspeval\n implicit none\n integer(kind=4), intent(in) :: map\n integer(kind=4), parameter :: dim = 2\n integer(kind=4), intent(in) :: d\n integer(kind=4), intent(in) :: nx, ny\n integer(kind=4), intent(in) :: px, py\n integer(kind=4), intent(in) :: rx, ry\n real (kind=8), intent(in) :: Ux(0:nx+px+1)\n real (kind=8), intent(in) :: Uy(0:ny+py+1)\n real (kind=8), intent(in) :: Pw(4,0:ny,0:nx)\n real (kind=8), intent(in) :: F (d,0:ny,0:nx)\n real (kind=8), intent(out) :: G (2,d,0:ry,0:rx)\n real (kind=8), intent(in) :: X(0:rx)\n real (kind=8), intent(in) :: Y(0:ry)\n integer(kind=4) :: ix, jx, ox, spanx(0:rx)\n integer(kind=4) :: iy, jy, oy, spany(0:ry)\n real (kind=8) :: Mx(0:px,0:1,0:rx)\n real (kind=8) :: My(0:py,0:1,0:ry)\n real (kind=8) :: N0( 0:px,0:py)\n real (kind=8) :: N1(2,0:px,0:py)\n real (kind=8) :: WW( 0:px,0:py)\n real (kind=8) :: XX(2,0:px,0:py)\n real (kind=8) :: FF(d,0:px,0:py)\n real (kind=8) :: GG(2,d)\n !\n do ix = 0, rx\n spanx(ix) = FindSpan(nx,px,X(ix),Ux)\n call DersBasisFuns(spanx(ix),X(ix),px,1,Ux,Mx(:,:,ix))\n end do\n do iy = 0, ry\n spany(iy) = FindSpan(ny,py,Y(iy),Uy)\n call DersBasisFuns(spany(iy),Y(iy),py,1,Uy,My(:,:,iy))\n end do\n !\n do ix = 0, rx\n ox = spanx(ix) - px\n do iy = 0, ry\n oy = spany(iy) - py\n ! ---\n do jx = 0, px\n do jy = 0, py\n FF(:,jx,jy) = F (:,oy+jy,ox+jx)\n WW( jx,jy) = Pw(4,oy+jy,ox+jx)\n if (map/=0) then\n XX(1,jx,jy) = Pw(1,oy+jy,ox+jx) / WW(jx,jy)\n XX(2,jx,jy) = Pw(2,oy+jy,ox+jx) / WW(jx,jy)\n end if\n end do\n end do\n ! ---\n call TensorProd2((px+1),(py+1),Mx(:,:,ix),My(:,:,iy),N0,N1)\n call Rationalize((px+1)*(py+1),dim,WW,N0,N1)\n call Interpolate((px+1)*(py+1),dim,d,N1,FF,GG)\n if (map/=0) call GeometryMap((px+1)*(py+1),dim,d,N1,XX,GG)\n ! --\n G(:,:,iy,ix) = GG\n ! ---\n end do\n end do\n !\nend subroutine Gradient2\n\nsubroutine Gradient3(map,d,nx,px,Ux,ny,py,Uy,nz,pz,Uz,Pw,F,rx,X,ry,Y,rz,Z,G)\n use bspline\n use bspeval\n implicit none\n integer(kind=4), parameter :: dim = 3\n integer(kind=4), intent(in) :: map\n integer(kind=4), intent(in) :: d\n integer(kind=4), intent(in) :: nx, ny, nz\n integer(kind=4), intent(in) :: px, py, pz\n integer(kind=4), intent(in) :: rx, ry, rz\n real (kind=8), intent(in) :: Ux(0:nx+px+1)\n real (kind=8), intent(in) :: Uy(0:ny+py+1)\n real (kind=8), intent(in) :: Uz(0:nz+pz+1)\n real (kind=8), intent(in) :: Pw(4,0:nz,0:ny,0:nx)\n real (kind=8), intent(in) :: F (d,0:nz,0:ny,0:nx)\n real (kind=8), intent(out) :: G (3,d,0:rz,0:ry,0:rx)\n real (kind=8), intent(in) :: X(0:rx)\n real (kind=8), intent(in) :: Y(0:ry)\n real (kind=8), intent(in) :: Z(0:rz)\n integer(kind=4) :: ix, jx, ox, spanx(0:rx)\n integer(kind=4) :: iy, jy, oy, spany(0:ry)\n integer(kind=4) :: iz, jz, oz, spanz(0:rz)\n real (kind=8) :: Mx(0:px,0:1,0:rx)\n real (kind=8) :: My(0:py,0:1,0:ry)\n real (kind=8) :: Mz(0:pz,0:1,0:rz)\n real (kind=8) :: N0( 0:px,0:py,0:pz)\n real (kind=8) :: N1(3,0:px,0:py,0:pz)\n real (kind=8) :: WW( 0:px,0:py,0:pz)\n real (kind=8) :: XX(3,0:px,0:py,0:pz)\n real (kind=8) :: FF(d,0:px,0:py,0:pz)\n real (kind=8) :: GG(3,d)\n !\n do ix = 0, rx\n spanx(ix) = FindSpan(nx,px,X(ix),Ux)\n call DersBasisFuns(spanx(ix),X(ix),px,1,Ux,Mx(:,:,ix))\n end do\n do iy = 0, ry\n spany(iy) = FindSpan(ny,py,Y(iy),Uy)\n call DersBasisFuns(spany(iy),Y(iy),py,1,Uy,My(:,:,iy))\n end do\n do iz = 0, rz\n spanz(iz) = FindSpan(nz,pz,Z(iz),Uz)\n call DersBasisFuns(spanz(iz),Z(iz),pz,1,Uz,Mz(:,:,iz))\n end do\n !\n do ix = 0, rx\n ox = spanx(ix) - px\n do iy = 0, ry\n oy = spany(iy) - py\n do iz = 0, rz\n oz = spanz(iz) - pz\n ! ---\n do jx = 0, px\n do jy = 0, py\n do jz = 0, pz\n FF(:,jx,jy,jz) = F (:,oz+jz,oy+jy,ox+jx)\n WW( jx,jy,jz) = Pw(4,oz+jz,oy+jy,ox+jx)\n if (map/=0) then\n XX(1,jx,jy,jz) = Pw(1,oz+jz,oy+jy,ox+jx) / WW(jx,jy,jz)\n XX(2,jx,jy,jz) = Pw(2,oz+jz,oy+jy,ox+jx) / WW(jx,jy,jz)\n XX(3,jx,jy,jz) = Pw(3,oz+jz,oy+jy,ox+jx) / WW(jx,jy,jz)\n end if\n end do\n end do\n end do\n ! ---\n call TensorProd3((px+1),(py+1),(pz+1),Mx(:,:,ix),My(:,:,iy),Mz(:,:,iz),N0,N1)\n call Rationalize((px+1)*(py+1)*(pz+1),dim,WW,N0,N1)\n call Interpolate((px+1)*(py+1)*(pz+1),dim,d,N1,FF,GG)\n if (map/=0) call GeometryMap((px+1)*(py+1)*(pz+1),dim,d,N1,XX,GG)\n ! --\n G(:,:,iz,iy,ix) = GG\n ! ---\n end do\n end do\n end do\n !\nend subroutine Gradient3\n\nsubroutine Hessian1(map,d,nx,px,Ux,Pw,F,rx,X,H)\n use bspline\n use bspeval\n implicit none\n integer(kind=4), intent(in) :: map\n integer(kind=4), parameter :: dim = 1\n integer(kind=4), intent(in) :: d\n integer(kind=4), intent(in) :: nx\n integer(kind=4), intent(in) :: px\n integer(kind=4), intent(in) :: rx\n real (kind=8), intent(in) :: Ux(0:nx+px+1)\n real (kind=8), intent(in) :: Pw(4,0:nx)\n real (kind=8), intent(in) :: F (d,0:nx)\n real (kind=8), intent(out) :: H (1,1,d,0:rx)\n real (kind=8), intent(in) :: X(0:rx)\n integer(kind=4) :: ix, jx, ox, spanx(0:rx)\n real (kind=8) :: Mx(0:px,0:2,0:rx)\n real (kind=8) :: N0( 0:px)\n real (kind=8) :: N1( 1,0:px)\n real (kind=8) :: N2(1,1,0:px)\n real (kind=8) :: WW( 0:px)\n real (kind=8) :: XX(1,0:px)\n real (kind=8) :: FF(d,0:px)\n real (kind=8) :: HH(1,1,d)\n !\n do ix = 0, rx\n spanx(ix) = FindSpan(nx,px,X(ix),Ux)\n call DersBasisFuns(spanx(ix),X(ix),px,2,Ux,Mx(:,:,ix))\n end do\n !\n do ix = 0, rx\n ox = spanx(ix) - px\n ! ---\n do jx = 0, px\n FF(:,jx) = F (:,ox+jx)\n WW( jx) = Pw(4,ox+jx)\n if (map/=0) then\n XX(1,jx) = Pw(1,ox+jx) / WW(jx)\n end if\n end do\n ! ---\n call TensorProd1((px+1),Mx(:,:,ix),N0,N1,N2)\n call Rationalize((px+1),dim,WW,N0,N1,N2)\n call Interpolate((px+1),dim**2,d,N2,FF,HH)\n !if (map/=0) call GeometryMap((px+1),dim,d,N1,XX,GG)\n if (map/=0) stop \"Geometry mapping not supported\"\n ! --\n H(:,:,:,ix) = HH\n ! ---\n end do\n !\nend subroutine Hessian1\n\nsubroutine Hessian2(map,d,nx,px,Ux,ny,py,Uy,Pw,F,rx,X,ry,Y,H)\n use bspline\n use bspeval\n implicit none\n integer(kind=4), intent(in) :: map\n integer(kind=4), parameter :: dim = 2\n integer(kind=4), intent(in) :: d\n integer(kind=4), intent(in) :: nx, ny\n integer(kind=4), intent(in) :: px, py\n integer(kind=4), intent(in) :: rx, ry\n real (kind=8), intent(in) :: Ux(0:nx+px+1)\n real (kind=8), intent(in) :: Uy(0:ny+py+1)\n real (kind=8), intent(in) :: Pw(4,0:ny,0:nx)\n real (kind=8), intent(in) :: F (d,0:ny,0:nx)\n real (kind=8), intent(out) :: H (2,2,d,0:ry,0:rx)\n real (kind=8), intent(in) :: X(0:rx)\n real (kind=8), intent(in) :: Y(0:ry)\n integer(kind=4) :: ix, jx, ox, spanx(0:rx)\n integer(kind=4) :: iy, jy, oy, spany(0:ry)\n real (kind=8) :: Mx(0:px,0:2,0:rx)\n real (kind=8) :: My(0:py,0:2,0:ry)\n real (kind=8) :: N0( 0:px,0:py)\n real (kind=8) :: N1( 2,0:px,0:py)\n real (kind=8) :: N2(2,2,0:px,0:py)\n real (kind=8) :: WW( 0:px,0:py)\n real (kind=8) :: XX(2,0:px,0:py)\n real (kind=8) :: FF(d,0:px,0:py)\n real (kind=8) :: HH(2,2,d)\n !\n do ix = 0, rx\n spanx(ix) = FindSpan(nx,px,X(ix),Ux)\n call DersBasisFuns(spanx(ix),X(ix),px,2,Ux,Mx(:,:,ix))\n end do\n do iy = 0, ry\n spany(iy) = FindSpan(ny,py,Y(iy),Uy)\n call DersBasisFuns(spany(iy),Y(iy),py,2,Uy,My(:,:,iy))\n end do\n !\n do ix = 0, rx\n ox = spanx(ix) - px\n do iy = 0, ry\n oy = spany(iy) - py\n ! ---\n do jx = 0, px\n do jy = 0, py\n FF(:,jx,jy) = F (:,oy+jy,ox+jx)\n WW( jx,jy) = Pw(4,oy+jy,ox+jx)\n if (map/=0) then\n XX(1,jx,jy) = Pw(1,oy+jy,ox+jx) / WW(jx,jy)\n XX(2,jx,jy) = Pw(2,oy+jy,ox+jx) / WW(jx,jy)\n end if\n end do\n end do\n ! ---\n call TensorProd2((px+1),(py+1),Mx(:,:,ix),My(:,:,iy),N0,N1,N2)\n call Rationalize((px+1)*(py+1),dim,WW,N0,N1,N2)\n call Interpolate((px+1)*(py+1),dim**2,d,N2,FF,HH)\n !if (map/=0) call GeometryMap((px+1)*(py+1),dim,d,N1,XX,HH)\n if (map/=0) stop \"Geometry mapping not supported\"\n ! --\n H(:,:,:,iy,ix) = HH\n ! ---\n end do\n end do\n !\nend subroutine Hessian2\n\nsubroutine Hessian3(map,d,nx,px,Ux,ny,py,Uy,nz,pz,Uz,Pw,F,rx,X,ry,Y,rz,Z,H)\n use bspline\n use bspeval\n implicit none\n integer(kind=4), parameter :: dim = 3\n integer(kind=4), intent(in) :: map\n integer(kind=4), intent(in) :: d\n integer(kind=4), intent(in) :: nx, ny, nz\n integer(kind=4), intent(in) :: px, py, pz\n integer(kind=4), intent(in) :: rx, ry, rz\n real (kind=8), intent(in) :: Ux(0:nx+px+1)\n real (kind=8), intent(in) :: Uy(0:ny+py+1)\n real (kind=8), intent(in) :: Uz(0:nz+pz+1)\n real (kind=8), intent(in) :: Pw(4,0:nz,0:ny,0:nx)\n real (kind=8), intent(in) :: F (d,0:nz,0:ny,0:nx)\n real (kind=8), intent(out) :: H (3,3,d,0:rz,0:ry,0:rx)\n real (kind=8), intent(in) :: X(0:rx)\n real (kind=8), intent(in) :: Y(0:ry)\n real (kind=8), intent(in) :: Z(0:rz)\n integer(kind=4) :: ix, jx, ox, spanx(0:rx)\n integer(kind=4) :: iy, jy, oy, spany(0:ry)\n integer(kind=4) :: iz, jz, oz, spanz(0:rz)\n real (kind=8) :: Mx(0:px,0:2,0:rx)\n real (kind=8) :: My(0:py,0:2,0:ry)\n real (kind=8) :: Mz(0:pz,0:2,0:rz)\n real (kind=8) :: N0( 0:px,0:py,0:pz)\n real (kind=8) :: N1( 3,0:px,0:py,0:pz)\n real (kind=8) :: N2(3,3,0:px,0:py,0:pz)\n real (kind=8) :: WW( 0:px,0:py,0:pz)\n real (kind=8) :: XX(3,0:px,0:py,0:pz)\n real (kind=8) :: FF(d,0:px,0:py,0:pz)\n real (kind=8) :: HH(3,3,d)\n !\n do ix = 0, rx\n spanx(ix) = FindSpan(nx,px,X(ix),Ux)\n call DersBasisFuns(spanx(ix),X(ix),px,2,Ux,Mx(:,:,ix))\n end do\n do iy = 0, ry\n spany(iy) = FindSpan(ny,py,Y(iy),Uy)\n call DersBasisFuns(spany(iy),Y(iy),py,2,Uy,My(:,:,iy))\n end do\n do iz = 0, rz\n spanz(iz) = FindSpan(nz,pz,Z(iz),Uz)\n call DersBasisFuns(spanz(iz),Z(iz),pz,2,Uz,Mz(:,:,iz))\n end do\n !\n do ix = 0, rx\n ox = spanx(ix) - px\n do iy = 0, ry\n oy = spany(iy) - py\n do iz = 0, rz\n oz = spanz(iz) - pz\n ! ---\n do jx = 0, px\n do jy = 0, py\n do jz = 0, pz\n FF(:,jx,jy,jz) = F (:,oz+jz,oy+jy,ox+jx)\n WW( jx,jy,jz) = Pw(4,oz+jz,oy+jy,ox+jx)\n if (map/=0) then\n XX(1,jx,jy,jz) = Pw(1,oz+jz,oy+jy,ox+jx) / WW(jx,jy,jz)\n XX(2,jx,jy,jz) = Pw(2,oz+jz,oy+jy,ox+jx) / WW(jx,jy,jz)\n XX(3,jx,jy,jz) = Pw(3,oz+jz,oy+jy,ox+jx) / WW(jx,jy,jz)\n end if\n end do\n end do\n end do\n ! ---\n call TensorProd3((px+1),(py+1),(pz+1),Mx(:,:,ix),My(:,:,iy),Mz(:,:,iz),N0,N1,N2)\n call Rationalize((px+1)*(py+1)*(pz+1),dim,WW,N0,N1,N2)\n call Interpolate((px+1)*(py+1)*(pz+1),dim**2,d,N2,FF,HH)\n !if (map/=0) call GeometryMap((px+1)*(py+1)*(pz+1),dim,d,N1,XX,HH)\n if (map/=0) stop \"Geometry mapping not supported\"\n ! --\n H(:,:,:,iz,iy,ix) = HH\n ! ---\n end do\n end do\n end do\n !\nend subroutine Hessian3\n\nsubroutine ThirdDer1(map,d,nx,px,Ux,Pw,F,rx,X,D3)\n use bspline\n use bspeval\n implicit none\n integer(kind=4), intent(in) :: map\n integer(kind=4), parameter :: dim = 1\n integer(kind=4), intent(in) :: d\n integer(kind=4), intent(in) :: nx\n integer(kind=4), intent(in) :: px\n integer(kind=4), intent(in) :: rx\n real (kind=8), intent(in) :: Ux(0:nx+px+1)\n real (kind=8), intent(in) :: Pw(4,0:nx)\n real (kind=8), intent(in) :: F (d,0:nx)\n real (kind=8), intent(out) :: D3(1,1,1,d,0:rx)\n real (kind=8), intent(in) :: X(0:rx)\n integer(kind=4) :: ix, jx, ox, spanx(0:rx)\n real (kind=8) :: Mx(0:px,0:3,0:rx)\n real (kind=8) :: N0( 0:px)\n real (kind=8) :: N1( 1,0:px)\n real (kind=8) :: N2( 1,1,0:px)\n real (kind=8) :: N3(1,1,1,0:px)\n real (kind=8) :: WW( 0:px)\n real (kind=8) :: XX(1,0:px)\n real (kind=8) :: FF(d,0:px)\n real (kind=8) :: DD(1,1,1,d)\n !\n do ix = 0, rx\n spanx(ix) = FindSpan(nx,px,X(ix),Ux)\n call DersBasisFuns(spanx(ix),X(ix),px,3,Ux,Mx(:,:,ix))\n end do\n !\n do ix = 0, rx\n ox = spanx(ix) - px\n ! ---\n do jx = 0, px\n FF(:,jx) = F (:,ox+jx)\n WW( jx) = Pw(4,ox+jx)\n if (map/=0) then\n XX(1,jx) = Pw(1,ox+jx) / WW(jx)\n end if\n end do\n ! ---\n call TensorProd1((px+1),Mx(:,:,ix),N0,N1,N2,N3)\n call Rationalize((px+1),dim,WW,N0,N1,N2,N3)\n call Interpolate((px+1),dim**3,d,N3,FF,DD)\n !if (map/=0) call GeometryMap((px+1),dim,d,N1,XX,GG)\n if (map/=0) stop \"Geometry mapping not supported\"\n ! --\n D3(:,:,:,:,ix) = DD\n ! ---\n end do\n !\nend subroutine ThirdDer1\n\nsubroutine ThirdDer2(map,d,nx,px,Ux,ny,py,Uy,Pw,F,rx,X,ry,Y,D3)\n use bspline\n use bspeval\n implicit none\n integer(kind=4), intent(in) :: map\n integer(kind=4), parameter :: dim = 2\n integer(kind=4), intent(in) :: d\n integer(kind=4), intent(in) :: nx, ny\n integer(kind=4), intent(in) :: px, py\n integer(kind=4), intent(in) :: rx, ry\n real (kind=8), intent(in) :: Ux(0:nx+px+1)\n real (kind=8), intent(in) :: Uy(0:ny+py+1)\n real (kind=8), intent(in) :: Pw(4,0:ny,0:nx)\n real (kind=8), intent(in) :: F (d,0:ny,0:nx)\n real (kind=8), intent(out) :: D3(2,2,2,d,0:ry,0:rx)\n real (kind=8), intent(in) :: X(0:rx)\n real (kind=8), intent(in) :: Y(0:ry)\n integer(kind=4) :: ix, jx, ox, spanx(0:rx)\n integer(kind=4) :: iy, jy, oy, spany(0:ry)\n real (kind=8) :: Mx(0:px,0:3,0:rx)\n real (kind=8) :: My(0:py,0:3,0:ry)\n real (kind=8) :: N0( 0:px,0:py)\n real (kind=8) :: N1( 2,0:px,0:py)\n real (kind=8) :: N2( 2,2,0:px,0:py)\n real (kind=8) :: N3(2,2,2,0:px,0:py)\n real (kind=8) :: WW( 0:px,0:py)\n real (kind=8) :: XX(2,0:px,0:py)\n real (kind=8) :: FF(d,0:px,0:py)\n real (kind=8) :: DD(2,2,2,d)\n !\n do ix = 0, rx\n spanx(ix) = FindSpan(nx,px,X(ix),Ux)\n call DersBasisFuns(spanx(ix),X(ix),px,3,Ux,Mx(:,:,ix))\n end do\n do iy = 0, ry\n spany(iy) = FindSpan(ny,py,Y(iy),Uy)\n call DersBasisFuns(spany(iy),Y(iy),py,3,Uy,My(:,:,iy))\n end do\n !\n do ix = 0, rx\n ox = spanx(ix) - px\n do iy = 0, ry\n oy = spany(iy) - py\n ! ---\n do jx = 0, px\n do jy = 0, py\n FF(:,jx,jy) = F (:,oy+jy,ox+jx)\n WW( jx,jy) = Pw(4,oy+jy,ox+jx)\n if (map/=0) then\n XX(1,jx,jy) = Pw(1,oy+jy,ox+jx) / WW(jx,jy)\n XX(2,jx,jy) = Pw(2,oy+jy,ox+jx) / WW(jx,jy)\n end if\n end do\n end do\n ! ---\n call TensorProd2((px+1),(py+1),Mx(:,:,ix),My(:,:,iy),N0,N1,N2,N3)\n call Rationalize((px+1)*(py+1),dim,WW,N0,N1,N2,N3)\n call Interpolate((px+1)*(py+1),dim**3,d,N3,FF,DD)\n !if (map/=0) call GeometryMap((px+1)*(py+1),dim,d,N1,XX,DD)\n if (map/=0) stop \"Geometry mapping not supported\"\n ! --\n D3(:,:,:,:,iy,ix) = DD\n ! ---\n end do\n end do\n !\nend subroutine ThirdDer2\n\nsubroutine ThirdDer3(map,d,nx,px,Ux,ny,py,Uy,nz,pz,Uz,Pw,F,rx,X,ry,Y,rz,Z,D3)\n use bspline\n use bspeval\n implicit none\n integer(kind=4), parameter :: dim = 3\n integer(kind=4), intent(in) :: map\n integer(kind=4), intent(in) :: d\n integer(kind=4), intent(in) :: nx, ny, nz\n integer(kind=4), intent(in) :: px, py, pz\n integer(kind=4), intent(in) :: rx, ry, rz\n real (kind=8), intent(in) :: Ux(0:nx+px+1)\n real (kind=8), intent(in) :: Uy(0:ny+py+1)\n real (kind=8), intent(in) :: Uz(0:nz+pz+1)\n real (kind=8), intent(in) :: Pw(4,0:nz,0:ny,0:nx)\n real (kind=8), intent(in) :: F (d,0:nz,0:ny,0:nx)\n real (kind=8), intent(out) :: D3(3,3,3,d,0:rz,0:ry,0:rx)\n real (kind=8), intent(in) :: X(0:rx)\n real (kind=8), intent(in) :: Y(0:ry)\n real (kind=8), intent(in) :: Z(0:rz)\n integer(kind=4) :: ix, jx, ox, spanx(0:rx)\n integer(kind=4) :: iy, jy, oy, spany(0:ry)\n integer(kind=4) :: iz, jz, oz, spanz(0:rz)\n real (kind=8) :: Mx(0:px,0:3,0:rx)\n real (kind=8) :: My(0:py,0:3,0:ry)\n real (kind=8) :: Mz(0:pz,0:3,0:rz)\n real (kind=8) :: N0( 0:px,0:py,0:pz)\n real (kind=8) :: N1( 3,0:px,0:py,0:pz)\n real (kind=8) :: N2( 3,3,0:px,0:py,0:pz)\n real (kind=8) :: N3(3,3,3,0:px,0:py,0:pz)\n real (kind=8) :: WW( 0:px,0:py,0:pz)\n real (kind=8) :: XX(3,0:px,0:py,0:pz)\n real (kind=8) :: FF(d,0:px,0:py,0:pz)\n real (kind=8) :: DD(3,3,3,d)\n !\n do ix = 0, rx\n spanx(ix) = FindSpan(nx,px,X(ix),Ux)\n call DersBasisFuns(spanx(ix),X(ix),px,3,Ux,Mx(:,:,ix))\n end do\n do iy = 0, ry\n spany(iy) = FindSpan(ny,py,Y(iy),Uy)\n call DersBasisFuns(spany(iy),Y(iy),py,3,Uy,My(:,:,iy))\n end do\n do iz = 0, rz\n spanz(iz) = FindSpan(nz,pz,Z(iz),Uz)\n call DersBasisFuns(spanz(iz),Z(iz),pz,3,Uz,Mz(:,:,iz))\n end do\n !\n do ix = 0, rx\n ox = spanx(ix) - px\n do iy = 0, ry\n oy = spany(iy) - py\n do iz = 0, rz\n oz = spanz(iz) - pz\n ! ---\n do jx = 0, px\n do jy = 0, py\n do jz = 0, pz\n FF(:,jx,jy,jz) = F (:,oz+jz,oy+jy,ox+jx)\n WW( jx,jy,jz) = Pw(4,oz+jz,oy+jy,ox+jx)\n if (map/=0) then\n XX(1,jx,jy,jz) = Pw(1,oz+jz,oy+jy,ox+jx) / WW(jx,jy,jz)\n XX(2,jx,jy,jz) = Pw(2,oz+jz,oy+jy,ox+jx) / WW(jx,jy,jz)\n XX(3,jx,jy,jz) = Pw(3,oz+jz,oy+jy,ox+jx) / WW(jx,jy,jz)\n end if\n end do\n end do\n end do\n ! ---\n call TensorProd3((px+1),(py+1),(pz+1),Mx(:,:,ix),My(:,:,iy),Mz(:,:,iz),N0,N1,N2,N3)\n call Rationalize((px+1)*(py+1)*(pz+1),dim,WW,N0,N1,N2,N3)\n call Interpolate((px+1)*(py+1)*(pz+1),dim**3,d,N3,FF,DD)\n !if (map/=0) call GeometryMap((px+1)*(py+1)*(pz+1),dim,d,N1,XX,DD)\n if (map/=0) stop \"Geometry mapping not supported\"\n ! --\n D3(:,:,:,:,iz,iy,ix) = DD\n ! ---\n end do\n end do\n end do\n !\nend subroutine ThirdDer3\n\nsubroutine FourthDer1(map,d,nx,px,Ux,Pw,F,rx,X,D4)\n use bspline\n use bspeval\n implicit none\n integer(kind=4), intent(in) :: map\n integer(kind=4), parameter :: dim = 1\n integer(kind=4), intent(in) :: d\n integer(kind=4), intent(in) :: nx\n integer(kind=4), intent(in) :: px\n integer(kind=4), intent(in) :: rx\n real (kind=8), intent(in) :: Ux(0:nx+px+1)\n real (kind=8), intent(in) :: Pw(4,0:nx)\n real (kind=8), intent(in) :: F (d,0:nx)\n real (kind=8), intent(out) :: D4(dim**4,d,0:rx)\n real (kind=8), intent(in) :: X(0:rx)\n integer(kind=4) :: ix, jx, ox, spanx(0:rx)\n real (kind=8) :: Mx(0:px,0:4,0:rx)\n real (kind=8) :: N0( 0:px)\n real (kind=8) :: N1( 1,0:px)\n real (kind=8) :: N2( 1,1,0:px)\n real (kind=8) :: N3( 1,1,1,0:px)\n real (kind=8) :: N4(1,1,1,1,0:px)\n real (kind=8) :: WW( 0:px)\n real (kind=8) :: XX(1,0:px)\n real (kind=8) :: FF(d,0:px)\n real (kind=8) :: DD(dim**4,d)\n !\n do ix = 0, rx\n spanx(ix) = FindSpan(nx,px,X(ix),Ux)\n call DersBasisFuns(spanx(ix),X(ix),px,4,Ux,Mx(:,:,ix))\n end do\n !\n do ix = 0, rx\n ox = spanx(ix) - px\n ! ---\n do jx = 0, px\n FF(:,jx) = F (:,ox+jx)\n WW( jx) = Pw(4,ox+jx)\n if (map/=0) then\n XX(1,jx) = Pw(1,ox+jx) / WW(jx)\n end if\n end do\n ! ---\n call TensorProd1((px+1),Mx(:,:,ix),N0,N1,N2,N3,N4)\n call Rationalize((px+1),dim,WW,N0,N1,N2,N3,N4)\n call Interpolate((px+1),dim**4,d,N4,FF,DD)\n if (map/=0) stop \"Geometry mapping not supported\"\n ! --\n D4(:,:,ix) = DD\n ! ---\n end do\n !\nend subroutine FourthDer1\n\nsubroutine FourthDer2(map,d,nx,px,Ux,ny,py,Uy,Pw,F,rx,X,ry,Y,D4)\n use bspline\n use bspeval\n implicit none\n integer(kind=4), intent(in) :: map\n integer(kind=4), parameter :: dim = 2\n integer(kind=4), intent(in) :: d\n integer(kind=4), intent(in) :: nx, ny\n integer(kind=4), intent(in) :: px, py\n integer(kind=4), intent(in) :: rx, ry\n real (kind=8), intent(in) :: Ux(0:nx+px+1)\n real (kind=8), intent(in) :: Uy(0:ny+py+1)\n real (kind=8), intent(in) :: Pw(4,0:ny,0:nx)\n real (kind=8), intent(in) :: F (d,0:ny,0:nx)\n real (kind=8), intent(out) :: D4(dim**4,d,0:ry,0:rx)\n real (kind=8), intent(in) :: X(0:rx)\n real (kind=8), intent(in) :: Y(0:ry)\n integer(kind=4) :: ix, jx, ox, spanx(0:rx)\n integer(kind=4) :: iy, jy, oy, spany(0:ry)\n real (kind=8) :: Mx(0:px,0:4,0:rx)\n real (kind=8) :: My(0:py,0:4,0:ry)\n real (kind=8) :: N0( 0:px,0:py)\n real (kind=8) :: N1( 2,0:px,0:py)\n real (kind=8) :: N2( 2,2,0:px,0:py)\n real (kind=8) :: N3( 2,2,2,0:px,0:py)\n real (kind=8) :: N4(2,2,2,2,0:px,0:py)\n real (kind=8) :: WW( 0:px,0:py)\n real (kind=8) :: XX(2,0:px,0:py)\n real (kind=8) :: FF(d,0:px,0:py)\n real (kind=8) :: DD(dim**4,d)\n !\n do ix = 0, rx\n spanx(ix) = FindSpan(nx,px,X(ix),Ux)\n call DersBasisFuns(spanx(ix),X(ix),px,4,Ux,Mx(:,:,ix))\n end do\n do iy = 0, ry\n spany(iy) = FindSpan(ny,py,Y(iy),Uy)\n call DersBasisFuns(spany(iy),Y(iy),py,4,Uy,My(:,:,iy))\n end do\n !\n do ix = 0, rx\n ox = spanx(ix) - px\n do iy = 0, ry\n oy = spany(iy) - py\n ! ---\n do jx = 0, px\n do jy = 0, py\n FF(:,jx,jy) = F (:,oy+jy,ox+jx)\n WW( jx,jy) = Pw(4,oy+jy,ox+jx)\n if (map/=0) then\n XX(1,jx,jy) = Pw(1,oy+jy,ox+jx) / WW(jx,jy)\n XX(2,jx,jy) = Pw(2,oy+jy,ox+jx) / WW(jx,jy)\n end if\n end do\n end do\n ! ---\n call TensorProd2((px+1),(py+1),Mx(:,:,ix),My(:,:,iy),N0,N1,N2,N3,N4)\n call Rationalize((px+1)*(py+1),dim,WW,N0,N1,N2,N3,N4)\n call Interpolate((px+1)*(py+1),dim**4,d,N4,FF,DD)\n if (map/=0) stop \"Geometry mapping not supported\"\n ! --\n D4(:,:,iy,ix) = DD\n ! ---\n end do\n end do\n !\nend subroutine FourthDer2\n\nsubroutine FourthDer3(map,d,nx,px,Ux,ny,py,Uy,nz,pz,Uz,Pw,F,rx,X,ry,Y,rz,Z,D4)\n use bspline\n use bspeval\n implicit none\n integer(kind=4), parameter :: dim = 3\n integer(kind=4), intent(in) :: map\n integer(kind=4), intent(in) :: d\n integer(kind=4), intent(in) :: nx, ny, nz\n integer(kind=4), intent(in) :: px, py, pz\n integer(kind=4), intent(in) :: rx, ry, rz\n real (kind=8), intent(in) :: Ux(0:nx+px+1)\n real (kind=8), intent(in) :: Uy(0:ny+py+1)\n real (kind=8), intent(in) :: Uz(0:nz+pz+1)\n real (kind=8), intent(in) :: Pw(4,0:nz,0:ny,0:nx)\n real (kind=8), intent(in) :: F (d,0:nz,0:ny,0:nx)\n real (kind=8), intent(out) :: D4(dim**4,d,0:rz,0:ry,0:rx)\n real (kind=8), intent(in) :: X(0:rx)\n real (kind=8), intent(in) :: Y(0:ry)\n real (kind=8), intent(in) :: Z(0:rz)\n integer(kind=4) :: ix, jx, ox, spanx(0:rx)\n integer(kind=4) :: iy, jy, oy, spany(0:ry)\n integer(kind=4) :: iz, jz, oz, spanz(0:rz)\n real (kind=8) :: Mx(0:px,0:4,0:rx)\n real (kind=8) :: My(0:py,0:4,0:ry)\n real (kind=8) :: Mz(0:pz,0:4,0:rz)\n real (kind=8) :: N0( 0:px,0:py,0:pz)\n real (kind=8) :: N1( 3,0:px,0:py,0:pz)\n real (kind=8) :: N2( 3,3,0:px,0:py,0:pz)\n real (kind=8) :: N3( 3,3,3,0:px,0:py,0:pz)\n real (kind=8) :: N4(3,3,3,3,0:px,0:py,0:pz)\n real (kind=8) :: WW( 0:px,0:py,0:pz)\n real (kind=8) :: XX(3,0:px,0:py,0:pz)\n real (kind=8) :: FF(d,0:px,0:py,0:pz)\n real (kind=8) :: DD(dim**4,d)\n !\n do ix = 0, rx\n spanx(ix) = FindSpan(nx,px,X(ix),Ux)\n call DersBasisFuns(spanx(ix),X(ix),px,4,Ux,Mx(:,:,ix))\n end do\n do iy = 0, ry\n spany(iy) = FindSpan(ny,py,Y(iy),Uy)\n call DersBasisFuns(spany(iy),Y(iy),py,4,Uy,My(:,:,iy))\n end do\n do iz = 0, rz\n spanz(iz) = FindSpan(nz,pz,Z(iz),Uz)\n call DersBasisFuns(spanz(iz),Z(iz),pz,4,Uz,Mz(:,:,iz))\n end do\n !\n do ix = 0, rx\n ox = spanx(ix) - px\n do iy = 0, ry\n oy = spany(iy) - py\n do iz = 0, rz\n oz = spanz(iz) - pz\n ! ---\n do jx = 0, px\n do jy = 0, py\n do jz = 0, pz\n FF(:,jx,jy,jz) = F (:,oz+jz,oy+jy,ox+jx)\n WW( jx,jy,jz) = Pw(4,oz+jz,oy+jy,ox+jx)\n if (map/=0) then\n XX(1,jx,jy,jz) = Pw(1,oz+jz,oy+jy,ox+jx) / WW(jx,jy,jz)\n XX(2,jx,jy,jz) = Pw(2,oz+jz,oy+jy,ox+jx) / WW(jx,jy,jz)\n XX(3,jx,jy,jz) = Pw(3,oz+jz,oy+jy,ox+jx) / WW(jx,jy,jz)\n end if\n end do\n end do\n end do\n ! ---\n call TensorProd3((px+1),(py+1),(pz+1),Mx(:,:,ix),My(:,:,iy),Mz(:,:,iz),N0,N1,N2,N3,N4)\n call Rationalize((px+1)*(py+1)*(pz+1),dim,WW,N0,N1,N2,N3,N4)\n call Interpolate((px+1)*(py+1)*(pz+1),dim**4,d,N4,FF,DD)\n if (map/=0) stop \"Geometry mapping not supported\"\n ! --\n D4(:,:,iz,iy,ix) = DD\n ! ---\n end do\n end do\n end do\n !\nend subroutine FourthDer3\n\nend module BSp\n\n!\n! ----------\n!\n\nmodule IGA\ncontains\n\nsubroutine KnotVector(E,p,C,Ui,Uf,wrap,m,U)\n implicit none\n integer(kind=4), intent(in) :: E,p,C\n real (kind=8), intent(in) :: Ui,Uf\n logical(kind=4), intent(in) :: wrap\n integer(kind=4), intent(in) :: m\n real (kind=8), intent(out) :: U(0:m)\n integer(kind=4) :: i, j, k, n\n real (kind=8) :: dU\n dU = (Uf-Ui)/E\n k = p+1\n do i = 1, (E-1)\n do j = 1, (p-C)\n U(k) = Ui + i*dU\n k = k+1\n end do\n end do\n do k = 0, p\n U(k) = Ui\n U(m-k) = Uf\n end do\n if (wrap) then\n n = m-(p+1)\n do k = 0, C\n U(C-k) = Ui - Uf + U(n-k)\n U(m-C+k) = Uf - Ui + U(p+1+k)\n end do\n end if\nend subroutine KnotVector\n\nsubroutine GaussLegendreRule(q,X,W)\n implicit none\n integer(kind=4), intent(in) :: q\n real (kind=8), intent(out) :: X(0:q-1)\n real (kind=8), intent(out) :: W(0:q-1)\n integer, parameter :: rk = 8\n select case (q)\n case (1) ! p <= 1\n X(0) = 0.0_rk\n W(0) = 2.0_rk\n case (2) ! p <= 3\n X(0) = -0.577350269189625764509148780501957456_rk ! 1/sqrt(3)\n X(1) = -X(0)\n W(0) = 1.0_rk ! 1\n W(1) = W(0)\n case (3) ! p <= 5\n X(0) = -0.774596669241483377035853079956479922_rk ! sqrt(3/5)\n X(1) = 0.0_rk ! 0\n X(2) = -X(0)\n W(0) = 0.555555555555555555555555555555555556_rk ! 5/9\n W(1) = 0.888888888888888888888888888888888889_rk ! 8/9\n W(2) = W(0)\n case (4) ! p <= 7\n X(0) = -0.861136311594052575223946488892809505_rk ! sqrt((3+2*sqrt(6/5))/7)\n X(1) = -0.339981043584856264802665759103244687_rk ! sqrt((3-2*sqrt(6/5))/7)\n X(2) = -X(1)\n X(3) = -X(0)\n W(0) = 0.347854845137453857373063949221999407_rk ! (18-sqrt(30))/36\n W(1) = 0.652145154862546142626936050778000593_rk ! (18+sqrt(30))/36\n W(2) = W(1)\n W(3) = W(0)\n case (5) ! p <= 9\n X(0) = -0.906179845938663992797626878299392965_rk ! 1/3*sqrt(5+2*sqrt(10/7))\n X(1) = -0.538469310105683091036314420700208805_rk ! 1/3*sqrt(5-2*sqrt(10/7))\n X(2) = 0.0_rk ! 0\n X(3) = -X(1)\n X(4) = -X(0)\n W(0) = 0.236926885056189087514264040719917363_rk ! (322-13*sqrt(70))/900\n W(1) = 0.478628670499366468041291514835638193_rk ! (322+13*sqrt(70))/900\n W(2) = 0.568888888888888888888888888888888889_rk ! 128/225\n W(3) = W(1)\n W(4) = W(0)\n case (6) ! p <= 11\n X(0) = -0.932469514203152027812301554493994609_rk\n X(1) = -0.661209386466264513661399595019905347_rk\n X(2) = -0.238619186083196908630501721680711935_rk\n X(3) = -X(2)\n X(4) = -X(1)\n X(5) = -X(0)\n W(0) = 0.171324492379170345040296142172732894_rk\n W(1) = 0.360761573048138607569833513837716112_rk\n W(2) = 0.467913934572691047389870343989550995_rk\n W(3) = W(2)\n W(4) = W(1)\n W(5) = W(0)\n case (7) ! p <= 13\n X(0) = -0.949107912342758524526189684047851262_rk\n X(1) = -0.741531185599394439863864773280788407_rk\n X(2) = -0.405845151377397166906606412076961463_rk\n X(3) = 0.0_rk\n X(4) = -X(2)\n X(5) = -X(1)\n X(6) = -X(0)\n W(0) = 0.129484966168869693270611432679082018_rk\n W(1) = 0.279705391489276667901467771423779582_rk\n W(2) = 0.381830050505118944950369775488975134_rk\n W(3) = 0.417959183673469387755102040816326531_rk\n W(4) = W(2)\n W(5) = W(1)\n W(6) = W(0)\n case (8) ! p <= 15\n X(0) = -0.960289856497536231683560868569472990_rk\n X(1) = -0.796666477413626739591553936475830437_rk\n X(2) = -0.525532409916328985817739049189246349_rk\n X(3) = -0.183434642495649804939476142360183981_rk\n X(4) = -X(3)\n X(5) = -X(2)\n X(6) = -X(1)\n X(7) = -X(0)\n W(0) = 0.101228536290376259152531354309962190_rk\n W(1) = 0.222381034453374470544355994426240884_rk\n W(2) = 0.313706645877887287337962201986601313_rk\n W(3) = 0.362683783378361982965150449277195612_rk\n W(4) = W(3)\n W(5) = W(2)\n W(6) = W(1)\n W(7) = W(0)\n case (9) ! p <= 17\n X(0) = -0.968160239507626089835576202903672870_rk\n X(1) = -0.836031107326635794299429788069734877_rk\n X(2) = -0.613371432700590397308702039341474185_rk\n X(3) = -0.324253423403808929038538014643336609_rk\n X(4) = 0.0_rk\n X(5) = -X(3)\n X(6) = -X(2)\n X(7) = -X(1)\n X(8) = -X(0)\n W(0) = 0.081274388361574411971892158110523651_rk\n W(1) = 0.180648160694857404058472031242912810_rk\n W(2) = 0.260610696402935462318742869418632850_rk\n W(3) = 0.312347077040002840068630406584443666_rk\n W(4) = 0.330239355001259763164525069286974049_rk\n W(5) = W(3)\n W(6) = W(2)\n W(7) = W(1)\n W(8) = W(0)\n case (10) ! p <= 19\n X(0) = -0.973906528517171720077964012084452053_rk\n X(1) = -0.865063366688984510732096688423493049_rk\n X(2) = -0.679409568299024406234327365114873576_rk\n X(3) = -0.433395394129247190799265943165784162_rk\n X(4) = -0.148874338981631210884826001129719985_rk\n X(5) = -X(4)\n X(6) = -X(3)\n X(7) = -X(2)\n X(8) = -X(1)\n X(9) = -X(0)\n W(0) = 0.066671344308688137593568809893331793_rk\n W(1) = 0.149451349150580593145776339657697332_rk\n W(2) = 0.219086362515982043995534934228163192_rk\n W(3) = 0.269266719309996355091226921569469353_rk\n W(4) = 0.295524224714752870173892994651338329_rk\n W(5) = W(4)\n W(6) = W(3)\n W(7) = W(2)\n W(8) = W(1)\n W(9) = W(0)\n case default\n X = 0.0_rk\n W = 0.0_rk\n end select\nend subroutine GaussLegendreRule\n\nsubroutine GaussLobattoRule(q,X,W)\n implicit none\n integer(kind=4), intent(in) :: q\n real (kind=8), intent(out) :: X(0:q-1)\n real (kind=8), intent(out) :: W(0:q-1)\n integer, parameter :: rk = 8\n select case (q)\n case (2) ! p <= 1\n X(0) = -1.0_rk\n X(1) = -X(0)\n W(0) = 1.0_rk\n W(1) = W(0)\n case (3) ! p <= 3\n X(0) = -1.0_rk ! 1\n X(1) = 0.0_rk ! 0\n X(2) = -X(0)\n W(0) = 0.333333333333333333333333333333333333_rk ! 1/3\n W(1) = 1.333333333333333333333333333333333333_rk ! 4/3\n W(2) = W(0)\n case (4) ! p <= 5\n X(0) = -1.0_rk ! 1\n X(1) = -0.447213595499957939281834733746255247_rk ! 1/sqrt(5)\n X(2) = -X(1)\n X(3) = -X(0)\n W(0) = 0.166666666666666666666666666666666667_rk ! 1/6\n W(1) = 0.833333333333333333333333333333333343_rk ! 5/6\n W(2) = W(1)\n W(3) = W(0)\n case (5) ! p <= 7\n X(0) = -1.0_rk ! 1\n X(1) = -0.654653670707977143798292456246858356_rk ! sqrt(3/7)\n X(2) = 0.0_rk ! 0\n X(3) = -X(1)\n X(4) = -X(0)\n W(0) = 0.1_rk ! 1/10\n W(1) = 0.544444444444444444444444444444444444_rk ! 49/90\n W(2) = 0.711111111111111111111111111111111111_rk ! 32/45\n W(3) = W(1)\n W(4) = W(0)\n case (6) ! p <= 9\n X(0) = -1.0_rk ! 1\n X(1) = -0.765055323929464692851002973959338150_rk ! sqrt((7+2*sqrt(7))/21)\n X(2) = -0.285231516480645096314150994040879072_rk ! sqrt((7-2*sqrt(7))/21)\n X(3) = -X(2)\n X(4) = -X(1)\n X(5) = -X(0)\n W(0) = 0.066666666666666666666666666666666667_rk ! 1/15\n W(1) = 0.378474956297846980316612808212024652_rk ! (14-sqrt(7))/30\n W(2) = 0.554858377035486353016720525121308681_rk ! (14+sqrt(7))/30\n W(3) = W(2)\n W(4) = W(1)\n W(5) = W(0)\n case (7) ! p <= 11\n X(0) = -1.0_rk\n X(1) = -0.830223896278566929872032213967465140_rk\n X(2) = -0.468848793470714213803771881908766329_rk\n X(3) = 0.0_rk\n X(4) = -X(2)\n X(5) = -X(1)\n X(6) = -X(0)\n W(0) = 0.047619047619047619047619047619047619_rk\n W(1) = 0.276826047361565948010700406290066293_rk\n W(2) = 0.431745381209862623417871022281362278_rk\n W(3) = 0.487619047619047619047619047619047619_rk\n W(4) = W(2)\n W(5) = W(1)\n W(6) = W(0)\n case (8) ! p <= 13\n X(0) = -1.0_rk\n X(1) = -0.871740148509606615337445761220663438_rk\n X(2) = -0.591700181433142302144510731397953190_rk\n X(3) = -0.209299217902478868768657260345351255_rk\n X(4) = -X(3)\n X(5) = -X(2)\n X(6) = -X(1)\n X(7) = -X(0)\n W(0) = 0.035714285714285714285714285714285714_rk\n W(1) = 0.210704227143506039382992065775756324_rk\n W(2) = 0.341122692483504364764240677107748172_rk\n W(3) = 0.412458794658703881567052971402209789_rk\n W(4) = W(3)\n W(5) = W(2)\n W(6) = W(1)\n W(7) = W(0)\n case (9) ! p <= 15\n X(0) = -1.0_rk\n X(1) = -0.899757995411460157312345244418337958_rk\n X(2) = -0.677186279510737753445885427091342451_rk\n X(3) = -0.363117463826178158710752068708659213_rk\n X(4) = 0.0_rk\n X(5) = -X(3)\n X(6) = -X(2)\n X(7) = -X(1)\n X(8) = -X(0)\n W(0) = 0.027777777777777777777777777777777778_rk\n W(1) = 0.165495361560805525046339720029208306_rk\n W(2) = 0.274538712500161735280705618579372726_rk\n W(3) = 0.346428510973046345115131532139718288_rk\n W(4) = 0.371519274376417233560090702947845805_rk\n W(5) = W(3)\n W(6) = W(2)\n W(7) = W(1)\n W(8) = W(0)\n case (10) ! p <= 17\n X(0) = -1.0_rk\n X(1) = -0.919533908166458813828932660822338134_rk\n X(2) = -0.738773865105505075003106174859830725_rk\n X(3) = -0.477924949810444495661175092731257998_rk\n X(4) = -0.165278957666387024626219765958173533_rk\n X(5) = -X(4)\n X(6) = -X(3)\n X(7) = -X(2)\n X(8) = -X(1)\n X(9) = -X(0)\n W(0) = 0.022222222222222222222222222222222222_rk\n W(1) = 0.133305990851070111126227170755392898_rk\n W(2) = 0.224889342063126452119457821731047843_rk\n W(3) = 0.292042683679683757875582257374443892_rk\n W(4) = 0.327539761183897456656510527916893145_rk\n W(5) = W(4)\n W(6) = W(3)\n W(7) = W(2)\n W(8) = W(1)\n W(9) = W(0)\n case default\n X = 0.0_rk\n W = 0.0_rk\n end select\nend subroutine GaussLobattoRule\n\nsubroutine BasisData(p,m,U,d,q,r,O,J,W,X,N)\n use bspline\n implicit none\n integer(kind=4), intent(in) :: p, m\n real (kind=8), intent(in) :: U(0:m)\n integer(kind=4), intent(in) :: d, q, r\n integer(kind=4), intent(out) :: O(r)\n real (kind=8), intent(out) :: J(r)\n real (kind=8), intent(out) :: W(q)\n real (kind=8), intent(out) :: X(q,r)\n real (kind=8), intent(out) :: N(0:d,0:p,q,r)\n\n integer(kind=4) i, iq, ir\n real (kind=8) uu, Xg(q)\n real (kind=8) basis(0:p,0:d)\n\n ir = 1\n do i = p, m-(p+1)\n if (abs(U(i) - U(i+1))>epsilon(U)) then\n O(ir) = i - p\n ir = ir + 1\n end if\n end do\n call GaussLegendreRule(q,Xg,W)\n do ir = 1, r\n i = O(ir) + p\n J(ir) = (U(i+1)-U(i))/2\n X(:,ir) = (Xg + 1) * J(ir) + U(i)\n do iq = 1, q\n uu = X(iq,ir)\n call DersBasisFuns(i,uu,p,d,U,basis)\n N(:,:,iq,ir) = transpose(basis)\n end do\n end do\nend subroutine BasisData\n\nsubroutine Greville(p,m,U,X)\n implicit none\n integer(kind=4), intent(in) :: p, m\n real (kind=8), intent(in) :: U(0:m)\n real (kind=8), intent(out) :: X(0:m-(p+1))\n integer(kind=4) :: i\n do i = 0, m-(p+1)\n X(i) = sum(U(i+1:i+p)) / p\n end do\nend subroutine Greville\n\nsubroutine BasisDataCol(p,m,U,r,X,d,O,N)\n use bspline\n implicit none\n integer(kind=4), intent(in) :: p, m\n real (kind=8), intent(in) :: U(0:m)\n integer(kind=4), intent(in) :: r, d\n real (kind=8), intent(in) :: X(r)\n integer(kind=4), intent(out) :: O(r)\n real (kind=8), intent(out) :: N(0:d,0:p,r)\n\n integer(kind=4) :: ir, ii\n real (kind=8) :: uu, basis(0:p,0:d)\n\n do ir = 1, r\n uu = X(ir)\n ii = FindSpan(m-(p+1),p,uu,U)\n call DersBasisFuns(ii,uu,p,d,U,basis)\n O(ir) = ii - p\n N(:,:,ir) = transpose(basis)\n end do\nend subroutine BasisDataCol\n\nend module IGA\n", "meta": {"hexsha": "fe2c7ed5da1ffbcad4f99b692aee96720a21c92d", "size": 81977, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "igakit/igalib.f90", "max_stars_repo_name": "XiaoxuanZhangCM/igakit", "max_stars_repo_head_hexsha": "71bc4237a561272f6189d067688c182aa705c5eb", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2022-03-21T09:38:55.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T23:33:55.000Z", "max_issues_repo_path": "igakit/igalib.f90", "max_issues_repo_name": "XiaoxuanZhangCM/igakit", "max_issues_repo_head_hexsha": "71bc4237a561272f6189d067688c182aa705c5eb", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-03-24T22:50:35.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-27T06:33:16.000Z", "max_forks_repo_path": "igakit/igalib.f90", "max_forks_repo_name": "XiaoxuanZhangCM/igakit", "max_forks_repo_head_hexsha": "71bc4237a561272f6189d067688c182aa705c5eb", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.3253154574, "max_line_length": 97, "alphanum_fraction": 0.5024092123, "num_tokens": 37852, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.859663754105328, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6587548745505469}} {"text": "*DECK SINTI\n SUBROUTINE SINTI (N, WSAVE)\nC***BEGIN PROLOGUE SINTI\nC***PURPOSE Initialize a work array for SINT.\nC***LIBRARY SLATEC (FFTPACK)\nC***CATEGORY J1A3\nC***TYPE SINGLE PRECISION (SINTI-S)\nC***KEYWORDS FFTPACK, FOURIER TRANSFORM\nC***AUTHOR Swarztrauber, P. N., (NCAR)\nC***DESCRIPTION\nC\nC Subroutine SINTI initializes the array WSAVE which is used in\nC subroutine SINT. The prime factorization of N together with\nC a tabulation of the trigonometric functions are computed and\nC stored in WSAVE.\nC\nC Input Parameter\nC\nC N the length of the sequence to be transformed. The method\nC is most efficient when N+1 is a product of small primes.\nC\nC Output Parameter\nC\nC WSAVE a work array with at least INT(3.5*N+16) locations.\nC Different WSAVE arrays are required for different values\nC of N. The contents of WSAVE must not be changed between\nC calls of SINT.\nC\nC***REFERENCES P. N. Swarztrauber, Vectorizing the FFTs, in Parallel\nC Computations (G. Rodrigue, ed.), Academic Press,\nC 1982, pp. 51-83.\nC***ROUTINES CALLED RFFTI\nC***REVISION HISTORY (YYMMDD)\nC 790601 DATE WRITTEN\nC 830401 Modified to use SLATEC library source file format.\nC 860115 Modified by Ron Boisvert to adhere to Fortran 77 by\nC (a) changing dummy array size declarations (1) to (*),\nC (b) changing references to intrinsic function FLOAT\nC to REAL, and\nC (c) changing definition of variable PI by using\nC FORTRAN intrinsic function ATAN instead of a DATA\nC statement.\nC 881128 Modified by Dick Valent to meet prologue standards.\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890531 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE SINTI\n DIMENSION WSAVE(*)\nC***FIRST EXECUTABLE STATEMENT SINTI\n IF (N .LE. 1) RETURN\n PI = 4.*ATAN(1.)\n NP1 = N+1\n NS2 = N/2\n DT = PI/NP1\n KS = N+2\n KF = KS+NS2-1\n FK = 0.\n DO 101 K=KS,KF\n FK = FK+1.\n WSAVE(K) = 2.*SIN(FK*DT)\n 101 CONTINUE\n CALL RFFTI (NP1,WSAVE(KF+1))\n RETURN\n END\n", "meta": {"hexsha": "d6703bfaf267e0b623f50cf754b89519c5b1b805", "size": 2298, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/sinti.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/sinti.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/sinti.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.8181818182, "max_line_length": 69, "alphanum_fraction": 0.6549173194, "num_tokens": 722, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007393, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6587548727174652}} {"text": " integer function fac(n)\n integer n\n* Local variable\n integer i\n\n fac = 1\n do 10 i = 1, n\n fac = fac * i\n 10 continue\n\n return\n end\n", "meta": {"hexsha": "ccaa20198f829040caff66a4928c22b56558dd83", "size": 181, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "fac.f", "max_stars_repo_name": "JONGHOKim-Raphael/fff", "max_stars_repo_head_hexsha": "bd0c3df4e7a5bcf072b5a28cb7ed46052b2dddd1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fac.f", "max_issues_repo_name": "JONGHOKim-Raphael/fff", "max_issues_repo_head_hexsha": "bd0c3df4e7a5bcf072b5a28cb7ed46052b2dddd1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fac.f", "max_forks_repo_name": "JONGHOKim-Raphael/fff", "max_forks_repo_head_hexsha": "bd0c3df4e7a5bcf072b5a28cb7ed46052b2dddd1", "max_forks_repo_licenses": ["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.9230769231, "max_line_length": 29, "alphanum_fraction": 0.4696132597, "num_tokens": 54, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099167, "lm_q2_score": 0.766293648423189, "lm_q1q2_score": 0.6587548717954063}} {"text": "program odd_number\n implicit none\n integer :: N, k\n \n! odd integers between 0 & N\n PRINT*, 'Enter an integer N: '\n READ(*,*) N\n WRITE(*,*) \"Odd number between 0 and \", N\n DO k = 1, N, 2\n WRITE(*,*) k, 'is an odd number between 0 and ', N\n END DO\n\nend program odd_number\n", "meta": {"hexsha": "8166e165c8396695bf87bc4b90ec4185f6e7cfca", "size": 280, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/gettingStarted/do_counter.f90", "max_stars_repo_name": "annefou/Fortran", "max_stars_repo_head_hexsha": "9d3d81de1ae32723e64eb3d07195867293a82c5e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 32, "max_stars_repo_stars_event_min_datetime": "2016-04-08T19:04:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-13T15:44:37.000Z", "max_issues_repo_path": "src/gettingStarted/do_counter.f90", "max_issues_repo_name": "inandi2/Fortran-1", "max_issues_repo_head_hexsha": "9d3d81de1ae32723e64eb3d07195867293a82c5e", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/gettingStarted/do_counter.f90", "max_forks_repo_name": "inandi2/Fortran-1", "max_forks_repo_head_hexsha": "9d3d81de1ae32723e64eb3d07195867293a82c5e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2016-04-08T19:05:49.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-08T19:57:51.000Z", "avg_line_length": 20.0, "max_line_length": 54, "alphanum_fraction": 0.6107142857, "num_tokens": 96, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8175744761936437, "lm_q2_score": 0.8056321866478978, "lm_q1q2_score": 0.6586643130033948}} {"text": "program i\n real(kind=8)::x = 5\n real::y = 10\n print* , cos(0.0)\n print* , sin(3.14)\n print* , log(2.77)\n print* , cos(sin(0.0))\n print* , log(sin(90.0))\n print* , log(cos(x))\n print* , sin(y * cos(log(y)))\nend program i\n", "meta": {"hexsha": "d5a817caa845f6675b63cd3ee1dd8f38cf4623fe", "size": 229, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/output_tests/intrin_cos_sin_log.f90", "max_stars_repo_name": "clementval/fc", "max_stars_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/output_tests/intrin_cos_sin_log.f90", "max_issues_repo_name": "clementval/fc", "max_issues_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/output_tests/intrin_cos_sin_log.f90", "max_forks_repo_name": "clementval/fc", "max_forks_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.0833333333, "max_line_length": 31, "alphanum_fraction": 0.5414847162, "num_tokens": 97, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.908617906830944, "lm_q2_score": 0.7248702880639791, "lm_q1q2_score": 0.6586301238646362}} {"text": " SUBROUTINE quadmx(a,n,np)\r\n INTEGER n,np,NMAX\r\n REAL a(np,np),PI\r\n DOUBLE PRECISION xx\r\n PARAMETER (PI=3.14159265,NMAX=257)\r\n COMMON /momcom/ xx\r\n EXTERNAL kermom\r\nCU USES wwghts,kermom\r\n INTEGER j,k\r\n REAL h,wt(NMAX),x,cx,y\r\n h=PI/(n-1)\r\n do 12 j=1,n\r\n x=(j-1)*h\r\n xx=x\r\n call wwghts(wt,n,h,kermom)\r\n cx=cos(x)\r\n do 11 k=1,n\r\n y=(k-1)*h\r\n a(j,k)=wt(k)*cx*cos(y)\r\n11 continue\r\n a(j,j)=a(j,j)+1.\r\n12 continue\r\n return\r\n END\r\n", "meta": {"hexsha": "4fd121fd6cf69d57c7f509ad4393b659abdc3bb6", "size": 561, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/quadmx.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/quadmx.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/quadmx.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.44, "max_line_length": 41, "alphanum_fraction": 0.4688057041, "num_tokens": 196, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818865, "lm_q2_score": 0.7248702702332475, "lm_q1q2_score": 0.6586301040758894}} {"text": " SUBROUTINE gaucof(n,a,b,amu0,x,w)\r\n INTEGER n,NMAX\r\n REAL amu0,a(n),b(n),w(n),x(n)\r\n PARAMETER (NMAX=64)\r\nCU USES eigsrt,tqli\r\n INTEGER i,j\r\n REAL z(NMAX,NMAX)\r\n do 12 i=1,n\r\n if(i.ne.1)b(i)=sqrt(b(i))\r\n do 11 j=1,n\r\n if(i.eq.j)then\r\n z(i,j)=1.\r\n else\r\n z(i,j)=0.\r\n endif\r\n11 continue\r\n12 continue\r\n call tqli(a,b,n,NMAX,z)\r\n call eigsrt(a,z,n,NMAX)\r\n do 13 i=1,n\r\n x(i)=a(i)\r\n w(i)=amu0*z(1,i)**2\r\n13 continue\r\n return\r\n END\r\n", "meta": {"hexsha": "fc19b7b2207c953fd169e3b4908fb4c5f540c226", "size": 579, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/gaucof.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/gaucof.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/gaucof.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.2692307692, "max_line_length": 40, "alphanum_fraction": 0.4386873921, "num_tokens": 200, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837706, "lm_q2_score": 0.7248702761768248, "lm_q1q2_score": 0.6586301023014801}} {"text": "#include \"eiscor.h\"\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! d_orthfact_mergebulge\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! This routine computes the product of two real Given's rotations and \n! and stores the output in one of the input arrays.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! INPUT VARIABLES:\n!\n! TOP LOGICAL\n! .TRUE.: merge bulge at top\n! .FALSE.: merge bulge at bottom\n!\n! Q REAL(8) array of dimension (2)\n! generator unitary matrix\n!\n! B REAL(8) array of dimension (2)\n! generator for bulge\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine d_orthfact_mergebulge(TOP,Q,B)\n\n implicit none\n\n ! input variables\n logical, intent(in) :: TOP\n real(8), intent(inout) :: Q(2), B(2)\n\n ! compute variables\n real(8) :: c, s, nrm\n\n ! merge at top\n if(TOP)then\n\n ! compute new generators\n c = B(1)*Q(1)-B(2)*Q(2)\n s = B(2)*Q(1)+B(1)*Q(2)\n \n ! compute new generators\n call d_rot2_vec2gen(c,s,Q(1),Q(2),nrm)\n \n ! merge at bottom\n else\n\n ! compute new generators\n c = Q(1)*B(1)-Q(2)*B(2)\n s = Q(2)*B(1)+Q(1)*B(2)\n \n ! compute new generators\n call d_rot2_vec2gen(c,s,Q(1),Q(2),nrm)\n \n end if\n\nend subroutine d_orthfact_mergebulge\n", "meta": {"hexsha": "1258d9438d8892aedb2c607624a69ade4dad9d31", "size": 1438, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/AMVW/src/double/d_orthfact_mergebulge.f90", "max_stars_repo_name": "trcameron/FPML", "max_stars_repo_head_hexsha": "f6aacfcd702f7ce74a45ffaf281e9586dceb1b7e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tests/AMVW/src/double/d_orthfact_mergebulge.f90", "max_issues_repo_name": "trcameron/FPML", "max_issues_repo_head_hexsha": "f6aacfcd702f7ce74a45ffaf281e9586dceb1b7e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/AMVW/src/double/d_orthfact_mergebulge.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": 23.9666666667, "max_line_length": 70, "alphanum_fraction": 0.4534075104, "num_tokens": 416, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818864, "lm_q2_score": 0.72487026428967, "lm_q1q2_score": 0.6586300986754485}} {"text": "***********************************************************************\nc ORBEL_EHIE.F\n***********************************************************************\n* PURPOSE: Solves Kepler's eqn. e is ecc. m is mean anomaly.\n*\n* Input:\n* e ==> eccentricity anomaly. (real scalar)\n* m ==> mean anomaly. (real scalar)\n* Returns:\n* orbel_ehybrid ==> eccentric anomaly. (real scalar)\n*\n* ALGORITHM: Use Danby's quartic for 3 iterations. \n* Eqn. is f(x) = x - e*sin(x+M). Note that\n*\t E = x + M. First guess is very good for e near 1.\n*\t Need to first get M between 0. and PI and use\n*\t\t symmetry to return right answer if M between PI and 2PI\n* REMARKS: Modifies M so that both E and M are in range (0,TWOPI)\n* AUTHOR: M. Duncan \n* DATE WRITTEN: May 25,1992.\n* REVISIONS: \n***********************************************************************\n\n real*8 function orbel_ehie(e,m)\n\n include '../swift.inc'\n\nc... Inputs Only: \n\treal*8 e,m\n\nc... Internals:\n integer iflag,nper,niter,NMAX\n real*8 dx,x,sa,ca,esa,eca,f,fp\n\n parameter (NMAX = 3)\n\nc----\nc... Executable code \n\nc In this section, bring M into the range (0,TWOPI) and if\nc the result is greater than PI, solve for (TWOPI - M).\n\tiflag = 0\n\tnper = m/TWOPI\n\tm = m - nper*TWOPI\n\tif (m .lt. 0.d0) m = m + TWOPI\n\n\tif (m.gt.PI) then\n\t m = TWOPI - m\n\t iflag = 1\n\tendif\n\nc Make a first guess that works well for e near 1.\n\tx = (6.d0*m)**(1.d0/3.d0) - m\n\tniter =0\n\nc Iteration loop\n\tdo niter =1,NMAX\n\t call orbel_scget(x + m,sa,ca)\n\t esa = e*sa\n\t eca = e*ca\n\t f = x - esa\n\t fp = 1.d0 -eca\n\t dx = -f/fp\n\t dx = -f/(fp + 0.5d0*dx*esa)\n\t dx = -f/(fp + 0.5d0*dx*(esa+0.3333333333333333d0*eca*dx))\n\t x = x + dx\n\tenddo\n\n\torbel_ehie = m + x\n\n\tif (iflag.eq.1) then\n\t orbel_ehie = TWOPI - orbel_ehie\n\t m = TWOPI - m\n\tendif\n\n\treturn\n\tend !orbel_ehie\nc------------------------------------------------------------------\n\n", "meta": {"hexsha": "bc9653caf3ae96aa27bfbe09faf41a8bb674d6e3", "size": 2085, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/swift_j/orbel/orbel_ehie.f", "max_stars_repo_name": "Simske/exostriker", "max_stars_repo_head_hexsha": "587b0af4c9cadb46637a4ac61a5392a596e966b1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 69, "max_stars_repo_stars_event_min_datetime": "2020-01-06T13:31:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T11:23:14.000Z", "max_issues_repo_path": "exostriker/source/swift_j/orbel/orbel_ehie.f", "max_issues_repo_name": "sai-33/Exostriker", "max_issues_repo_head_hexsha": "f59fa51c6bdce3a2ed51d6621fe42bfcd8c2846f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 67, "max_issues_repo_issues_event_min_datetime": "2019-11-30T14:45:05.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-14T20:26:06.000Z", "max_forks_repo_path": "exostriker/source/swift_j/orbel/orbel_ehie.f", "max_forks_repo_name": "sai-33/Exostriker", "max_forks_repo_head_hexsha": "f59fa51c6bdce3a2ed51d6621fe42bfcd8c2846f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2020-01-06T13:44:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T11:23:17.000Z", "avg_line_length": 26.3924050633, "max_line_length": 71, "alphanum_fraction": 0.4762589928, "num_tokens": 645, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319862, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6586028345306018}} {"text": "c///////////////////////////////////////////////////////////////////////////\nc---------------------------------------------------------------------------\n SUBROUTINE SGECO(A,LDA,N,IPVT,RCOND,Z)\nc---------------------------------------------------------------------------\n IMPLICIT NONE\n INTEGER LDA,N,IPVT(1)\n REAL A(LDA,1),Z(1)\n REAL RCOND\nC\nC SGECO FACTORS A REAL MATRIX BY GAUSSIAN ELIMINATION\nC AND ESTIMATES THE CONDITION OF THE MATRIX.\nC\nC IF RCOND IS NOT NEEDED, SGEFA IS SLIGHTLY FASTER.\nC TO SOLVE A*X = B , FOLLOW SGECO BY SGESL.\nC TO COMPUTE INVERSE(A)*C , FOLLOW SGECO BY SGESL.\nC TO COMPUTE DETERMINANT(A) , FOLLOW SGECO BY SGEDI.\nC TO COMPUTE INVERSE(A) , FOLLOW SGECO BY SGEDI.\nC\nC ON ENTRY\nC\nC A REAL(LDA, N)\nC THE MATRIX TO BE FACTORED.\nC\nC LDA INTEGER\nC THE LEADING DIMENSION OF THE ARRAY A .\nC\nC N INTEGER\nC THE ORDER OF THE MATRIX A .\nC\nC ON RETURN\nC\nC A AN UPPER TRIANGULAR MATRIX AND THE MULTIPLIERS\nC WHICH WERE USED TO OBTAIN IT.\nC THE FACTORIZATION CAN BE WRITTEN A = L*U WHERE\nC L IS A PRODUCT OF PERMUTATION AND UNIT LOWER\nC TRIANGULAR MATRICES AND U IS UPPER TRIANGULAR.\nC\nC IPVT INTEGER(N)\nC AN INTEGER VECTOR OF PIVOT INDICES.\nC\nC RCOND REAL\nC AN ESTIMATE OF THE RECIPROCAL CONDITION OF A .\nC FOR THE SYSTEM A*X = B , RELATIVE PERTURBATIONS\nC IN A AND B OF SIZE EPSILON MAY CAUSE\nC RELATIVE PERTURBATIONS IN X OF SIZE EPSILON/RCOND .\nC IF RCOND IS SO SMALL THAT THE LOGICAL EXPRESSION\nC 1.0 + RCOND .EQ. 1.0\nC IS TRUE, THEN A MAY BE SINGULAR TO WORKING\nC PRECISION. IN PARTICULAR, RCOND IS ZERO IF\nC EXACT SINGULARITY IS DETECTED OR THE ESTIMATE\nC UNDERFLOWS.\nC\nC Z REAL(N)\nC A WORK VECTOR WHOSE CONTENTS ARE USUALLY UNIMPORTANT.\nC IF A IS CLOSE TO A SINGULAR MATRIX, THEN Z IS\nC AN APPROXIMATE NULL VECTOR IN THE SENSE THAT\nC NORM(A*Z) = RCOND*NORM(A)*NORM(Z) .\nC\nC LINPACK. THIS VERSION DATED 08/14/78 .\nC CLEVE MOLER, UNIVERSITY OF NEW MEXICO, ARGONNE NATIONAL LAB.\nC\nC SUBROUTINES AND FUNCTIONS\nC\nC LINPACK SGEFA\nC BLAS SAXPY,SDOT,SSCAL,SASUM\nC FORTRAN ABS,AMAX1,SIGN\nC\nC INTERNAL VARIABLES\nC\n REAL SDOT,EK,T,WK,WKM\n REAL ANORM,S,SASUM,SM,YNORM\n INTEGER INFO,J,K,KB,KP1,L\nC\nC\nC COMPUTE 1-NORM OF A\nC\n ANORM = 0.0E0\n DO 10 J = 1, N\n ANORM = AMAX1(ANORM,SASUM(N,A(1,J),1))\n 10 CONTINUE\nC\nC FACTOR\nC\n CALL SGEFA(A,LDA,N,IPVT,INFO)\nC\nC RCOND = 1/(NORM(A)*(ESTIMATE OF NORM(INVERSE(A)))) .\nC ESTIMATE = NORM(Z)/NORM(Y) WHERE A*Z = Y AND TRANS(A)*Y = E .\nC TRANS(A) IS THE TRANSPOSE OF A . THE COMPONENTS OF E ARE\nC CHOSEN TO CAUSE MAXIMUM LOCAL GROWTH IN THE ELEMENTS OF W WHERE\nC TRANS(U)*W = E . THE VECTORS ARE FREQUENTLY RESCALED TO AVOID\nC OVERFLOW.\nC\nC SOLVE TRANS(U)*W = E\nC\n EK = 1.0E0\n DO 20 J = 1, N\n Z(J) = 0.0E0\n 20 CONTINUE\n DO 100 K = 1, N\n IF (Z(K) .NE. 0.0E0) EK = SIGN(EK,-Z(K))\n IF (ABS(EK-Z(K)) .LE. ABS(A(K,K))) GO TO 30\n S = ABS(A(K,K))/ABS(EK-Z(K))\n CALL SSCAL(N,S,Z,1)\n EK = S*EK\n 30 CONTINUE\n WK = EK - Z(K)\n WKM = -EK - Z(K)\n S = ABS(WK)\n SM = ABS(WKM)\n IF (A(K,K) .EQ. 0.0E0) GO TO 40\n WK = WK/A(K,K)\n WKM = WKM/A(K,K)\n GO TO 50\n 40 CONTINUE\n WK = 1.0E0\n WKM = 1.0E0\n 50 CONTINUE\n KP1 = K + 1\n IF (KP1 .GT. N) GO TO 90\n DO 60 J = KP1, N\n SM = SM + ABS(Z(J)+WKM*A(K,J))\n Z(J) = Z(J) + WK*A(K,J)\n S = S + ABS(Z(J))\n 60 CONTINUE\n IF (S .GE. SM) GO TO 80\n T = WKM - WK\n WK = WKM\n DO 70 J = KP1, N\n Z(J) = Z(J) + T*A(K,J)\n 70 CONTINUE\n 80 CONTINUE\n 90 CONTINUE\n Z(K) = WK\n 100 CONTINUE\n S = 1.0E0/SASUM(N,Z,1)\n CALL SSCAL(N,S,Z,1)\nC\nC SOLVE TRANS(L)*Y = W\nC\n DO 120 KB = 1, N\n K = N + 1 - KB\n IF (K .LT. N) Z(K) = Z(K) + SDOT(N-K,A(K+1,K),1,Z(K+1),1)\n IF (ABS(Z(K)) .LE. 1.0E0) GO TO 110\n S = 1.0E0/ABS(Z(K))\n CALL SSCAL(N,S,Z,1)\n 110 CONTINUE\n L = IPVT(K)\n T = Z(L)\n Z(L) = Z(K)\n Z(K) = T\n 120 CONTINUE\n S = 1.0E0/SASUM(N,Z,1)\n CALL SSCAL(N,S,Z,1)\nC\n YNORM = 1.0E0\nC\nC SOLVE L*V = Y\nC\n DO 140 K = 1, N\n L = IPVT(K)\n T = Z(L)\n Z(L) = Z(K)\n Z(K) = T\n IF (K .LT. N) CALL SAXPY(N-K,T,A(K+1,K),1,Z(K+1),1)\n IF (ABS(Z(K)) .LE. 1.0E0) GO TO 130\n S = 1.0E0/ABS(Z(K))\n CALL SSCAL(N,S,Z,1)\n YNORM = S*YNORM\n 130 CONTINUE\n 140 CONTINUE\n S = 1.0E0/SASUM(N,Z,1)\n CALL SSCAL(N,S,Z,1)\n YNORM = S*YNORM\nC\nC SOLVE U*Z = V\nC\n DO 160 KB = 1, N\n K = N + 1 - KB\n IF (ABS(Z(K)) .LE. ABS(A(K,K))) GO TO 150\n S = ABS(A(K,K))/ABS(Z(K))\n CALL SSCAL(N,S,Z,1)\n YNORM = S*YNORM\n 150 CONTINUE\n IF (A(K,K) .NE. 0.0E0) Z(K) = Z(K)/A(K,K)\n IF (A(K,K) .EQ. 0.0E0) Z(K) = 1.0E0\n T = -Z(K)\n CALL SAXPY(K-1,T,A(1,K),1,Z(1),1)\n 160 CONTINUE\nC MAKE ZNORM = 1.0\n S = 1.0E0/SASUM(N,Z,1)\n CALL SSCAL(N,S,Z,1)\n YNORM = S*YNORM\nC\n IF (ANORM .NE. 0.0E0) RCOND = YNORM/ANORM\n IF (ANORM .EQ. 0.0E0) RCOND = 0.0E0\n RETURN\n END\nc///////////////////////////////////////////////////////////////////////////\nc---------------------------------------------------------------------------\n SUBROUTINE SGESL(A,LDA,N,IPVT,B,JOB)\nc---------------------------------------------------------------------------\n IMPLICIT NONE\n INTEGER LDA,N,IPVT(1),JOB\n REAL A(LDA,1),B(1)\nC\nC SGESL SOLVES THE REAL SYSTEM\nC A * X = B OR TRANS(A) * X = B\nC USING THE FACTORS COMPUTED BY SGECO OR SGEFA.\nC\nC ON ENTRY\nC\nC A REAL(LDA, N)\nC THE OUTPUT FROM SGECO OR SGEFA.\nC\nC LDA INTEGER\nC THE LEADING DIMENSION OF THE ARRAY A .\nC\nC N INTEGER\nC THE ORDER OF THE MATRIX A .\nC\nC IPVT INTEGER(N)\nC THE PIVOT VECTOR FROM SGECO OR SGEFA.\nC\nC B REAL(N)\nC THE RIGHT HAND SIDE VECTOR.\nC\nC JOB INTEGER\nC = 0 TO SOLVE A*X = B ,\nC = NONZERO TO SOLVE TRANS(A)*X = B WHERE\nC TRANS(A) IS THE TRANSPOSE.\nC\nC ON RETURN\nC\nC B THE SOLUTION VECTOR X .\nC\nC ERROR CONDITION\nC\nC A DIVISION BY ZERO WILL OCCUR IF THE INPUT FACTOR CONTAINS A\nC ZERO ON THE DIAGONAL. TECHNICALLY THIS INDICATES SINGULARITY\nC BUT IT IS OFTEN CAUSED BY IMPROPER ARGUMENTS OR IMPROPER\nC SETTING OF LDA . IT WILL NOT OCCUR IF THE SUBROUTINES ARE\nC CALLED CORRECTLY AND IF SGECO HAS SET RCOND .GT. 0.0\nC OR SGEFA HAS SET INFO .EQ. 0 .\nC\nC TO COMPUTE INVERSE(A) * C WHERE C IS A MATRIX\nC WITH P COLUMNS\nC CALL SGECO(A,LDA,N,IPVT,RCOND,Z)\nC IF (RCOND IS TOO SMALL) GO TO ...\nC DO 10 J = 1, P\nC CALL SGESL(A,LDA,N,IPVT,C(1,J),0)\nC 10 CONTINUE\nC\nC LINPACK. THIS VERSION DATED 08/14/78 .\nC CLEVE MOLER, UNIVERSITY OF NEW MEXICO, ARGONNE NATIONAL LAB.\nC\nC SUBROUTINES AND FUNCTIONS\nC\nC BLAS SAXPY,SDOT\nC\nC INTERNAL VARIABLES\nC\n REAL SDOT,T\n INTEGER K,KB,L,NM1\nC\n NM1 = N - 1\n IF (JOB .NE. 0) GO TO 50\nC\nC JOB = 0 , SOLVE A * X = B\nC FIRST SOLVE L*Y = B\nC\n IF (NM1 .LT. 1) GO TO 30\n DO 20 K = 1, NM1\n L = IPVT(K)\n T = B(L)\n IF (L .EQ. K) GO TO 10\n B(L) = B(K)\n B(K) = T\n 10 CONTINUE\n CALL SAXPY(N-K,T,A(K+1,K),1,B(K+1),1)\n 20 CONTINUE\n 30 CONTINUE\nC\nC NOW SOLVE U*X = Y\nC\n DO 40 KB = 1, N\n K = N + 1 - KB\n B(K) = B(K)/A(K,K)\n T = -B(K)\n CALL SAXPY(K-1,T,A(1,K),1,B(1),1)\n 40 CONTINUE\n GO TO 100\n 50 CONTINUE\nC\nC JOB = NONZERO, SOLVE TRANS(A) * X = B\nC FIRST SOLVE TRANS(U)*Y = B\nC\n DO 60 K = 1, N\n T = SDOT(K-1,A(1,K),1,B(1),1)\n B(K) = (B(K) - T)/A(K,K)\n 60 CONTINUE\nC\nC NOW SOLVE TRANS(L)*X = Y\nC\n IF (NM1 .LT. 1) GO TO 90\n DO 80 KB = 1, NM1\n K = N - KB\n B(K) = B(K) + SDOT(N-K,A(K+1,K),1,B(K+1),1)\n L = IPVT(K)\n IF (L .EQ. K) GO TO 70\n T = B(L)\n B(L) = B(K)\n B(K) = T\n 70 CONTINUE\n 80 CONTINUE\n 90 CONTINUE\n 100 CONTINUE\n RETURN\n END\n SUBROUTINE SAXPY(n,sa,sx,incx,sy,incy)\n IMPLICIT NONE\nc\nc constant times a vector plus a vector.\nc uses unrolled loop for increments equal to one.\nc jack dongarra, linpack, 3/11/78.\nc\n real sx(1),sy(1),sa\n integer i,incx,incy,ix,iy,m,mp1,n\nc\n if(n.le.0)return\n if (sa .eq. 0.0) return\n if(incx.eq.1.and.incy.eq.1)go to 20\nc\nc code for unequal increments or equal increments\nc not equal to 1\nc\n ix = 1\n iy = 1\n if(incx.lt.0)ix = (-n+1)*incx + 1\n if(incy.lt.0)iy = (-n+1)*incy + 1\n do 10 i = 1,n\n sy(iy) = sy(iy) + sa*sx(ix)\n ix = ix + incx\n iy = iy + incy\n 10 continue\n return\nc\nc code for both increments equal to 1\nc\nc\nc clean-up loop\nc\n 20 m = mod(n,4)\n if( m .eq. 0 ) go to 40\n do 30 i = 1,m\n sy(i) = sy(i) + sa*sx(i)\n 30 continue\n if( n .lt. 4 ) return\n 40 mp1 = m + 1\n do 50 i = mp1,n,4\n sy(i) = sy(i) + sa*sx(i)\n sy(i + 1) = sy(i + 1) + sa*sx(i + 1)\n sy(i + 2) = sy(i + 2) + sa*sx(i + 2)\n sy(i + 3) = sy(i + 3) + sa*sx(i + 3)\n 50 continue\n return\n end\n real function sdot(n,sx,incx,sy,incy)\n IMPLICIT NONE\nc\nc forms the dot product of two vectors.\nc uses unrolled loops for increments equal to one.\nc jack dongarra, linpack, 3/11/78.\nc\n real sx(1),sy(1),stemp\n integer i,incx,incy,ix,iy,m,mp1,n\nc\n stemp = 0.0e0\n sdot = 0.0e0\n if(n.le.0)return\n if(incx.eq.1.and.incy.eq.1)go to 20\nc\nc code for unequal increments or equal increments\nc not equal to 1\nc\n ix = 1\n iy = 1\n if(incx.lt.0)ix = (-n+1)*incx + 1\n if(incy.lt.0)iy = (-n+1)*incy + 1\n do 10 i = 1,n\n stemp = stemp + sx(ix)*sy(iy)\n ix = ix + incx\n iy = iy + incy\n 10 continue\n sdot = stemp\n return\nc\nc code for both increments equal to 1\nc\nc\nc clean-up loop\nc\n 20 m = mod(n,5)\n if( m .eq. 0 ) go to 40\n do 30 i = 1,m\n stemp = stemp + sx(i)*sy(i)\n 30 continue\n if( n .lt. 5 ) go to 60\n 40 mp1 = m + 1\n do 50 i = mp1,n,5\n stemp = stemp + sx(i)*sy(i) + sx(i + 1)*sy(i + 1) +\n * sx(i + 2)*sy(i + 2) + sx(i + 3)*sy(i + 3) + sx(i + 4)*sy(i + 4)\n 50 continue\n 60 sdot = stemp\n return\n end\n SUBROUTINE SSCAL(n,sa,sx,incx)\n IMPLICIT NONE\nc\nc scales a vector by a constant.\nc uses unrolled loops for increment equal to 1.\nc jack dongarra, linpack, 3/11/78.\nc\n real sa,sx(1)\n integer i,incx,m,mp1,n,nincx\nc\n if(n.le.0)return\n if(incx.eq.1)go to 20\nc\nc code for increment not equal to 1\nc\n nincx = n*incx\n do 10 i = 1,nincx,incx\n sx(i) = sa*sx(i)\n 10 continue\n return\nc\nc code for increment equal to 1\nc\nc\nc clean-up loop\nc\n 20 m = mod(n,5)\n if( m .eq. 0 ) go to 40\n do 30 i = 1,m\n sx(i) = sa*sx(i)\n 30 continue\n if( n .lt. 5 ) return\n 40 mp1 = m + 1\n do 50 i = mp1,n,5\n sx(i) = sa*sx(i)\n sx(i + 1) = sa*sx(i + 1)\n sx(i + 2) = sa*sx(i + 2)\n sx(i + 3) = sa*sx(i + 3)\n sx(i + 4) = sa*sx(i + 4)\n 50 continue\n return\n end\n real function sasum(n,sx,incx)\n IMPLICIT NONE\nc\nc takes the sum of the absolute values.\nc uses unrolled loops for increment equal to one.\nc jack dongarra, linpack, 3/11/78.\nc\n real sx(1),stemp\n integer i,incx,m,mp1,n,nincx\nc\n sasum = 0.0e0\n stemp = 0.0e0\n if(n.le.0)return\n if(incx.eq.1)go to 20\nc\nc code for increment not equal to 1\nc\n nincx = n*incx\n do 10 i = 1,nincx,incx\n stemp = stemp + abs(sx(i))\n 10 continue\n sasum = stemp\n return\nc\nc code for increment equal to 1\nc\nc\nc clean-up loop\nc\n 20 m = mod(n,6)\n if( m .eq. 0 ) go to 40\n do 30 i = 1,m\n stemp = stemp + abs(sx(i))\n 30 continue\n if( n .lt. 6 ) go to 60\n 40 mp1 = m + 1\n do 50 i = mp1,n,6\n stemp = stemp + abs(sx(i)) + abs(sx(i + 1)) + abs(sx(i + 2))\n * + abs(sx(i + 3)) + abs(sx(i + 4)) + abs(sx(i + 5))\n 50 continue\n 60 sasum = stemp\n return\n end\n SUBROUTINE SGEFA(A,LDA,N,IPVT,INFO)\n IMPLICIT NONE\n INTEGER LDA,N,IPVT(1),INFO\n REAL A(LDA,1)\nC\nC SGEFA FACTORS A REAL MATRIX BY GAUSSIAN ELIMINATION.\nC\nC SGEFA IS USUALLY CALLED BY SGECO, BUT IT CAN BE CALLED\nC DIRECTLY WITH A SAVING IN TIME IF RCOND IS NOT NEEDED.\nC (TIME FOR SGECO) = (1 + 9/N)*(TIME FOR SGEFA) .\nC\nC ON ENTRY\nC\nC A REAL(LDA, N)\nC THE MATRIX TO BE FACTORED.\nC\nC LDA INTEGER\nC THE LEADING DIMENSION OF THE ARRAY A .\nC\nC N INTEGER\nC THE ORDER OF THE MATRIX A .\nC\nC ON RETURN\nC\nC A AN UPPER TRIANGULAR MATRIX AND THE MULTIPLIERS\nC WHICH WERE USED TO OBTAIN IT.\nC THE FACTORIZATION CAN BE WRITTEN A = L*U WHERE\nC L IS A PRODUCT OF PERMUTATION AND UNIT LOWER\nC TRIANGULAR MATRICES AND U IS UPPER TRIANGULAR.\nC\nC IPVT INTEGER(N)\nC AN INTEGER VECTOR OF PIVOT INDICES.\nC\nC INFO INTEGER\nC = 0 NORMAL VALUE.\nC = K IF U(K,K) .EQ. 0.0 . THIS IS NOT AN ERROR\nC CONDITION FOR THIS SUBROUTINE, BUT IT DOES\nC INDICATE THAT SGESL OR SGEDI WILL DIVIDE BY ZERO\nC IF CALLED. USE RCOND IN SGECO FOR A RELIABLE\nC INDICATION OF SINGULARITY.\nC\nC LINPACK. THIS VERSION DATED 08/14/78 .\nC CLEVE MOLER, UNIVERSITY OF NEW MEXICO, ARGONNE NATIONAL LAB.\nC\nC SUBROUTINES AND FUNCTIONS\nC\nC BLAS SAXPY,SSCAL,ISAMAX\nC\nC INTERNAL VARIABLES\nC\n REAL T\n INTEGER ISAMAX,J,K,KP1,L,NM1\nC\nC\nC GAUSSIAN ELIMINATION WITH PARTIAL PIVOTING\nC\n INFO = 0\n NM1 = N - 1\n IF (NM1 .LT. 1) GO TO 70\n DO 60 K = 1, NM1\n KP1 = K + 1\nC\nC FIND L = PIVOT INDEX\nC\n L = ISAMAX(N-K+1,A(K,K),1) + K - 1\n IPVT(K) = L\nC\nC ZERO PIVOT IMPLIES THIS COLUMN ALREADY TRIANGULARIZED\nC\n IF (A(L,K) .EQ. 0.0E0) GO TO 40\nC\nC INTERCHANGE IF NECESSARY\nC\n IF (L .EQ. K) GO TO 10\n T = A(L,K)\n A(L,K) = A(K,K)\n A(K,K) = T\n 10 CONTINUE\nC\nC COMPUTE MULTIPLIERS\nC\n T = -1.0E0/A(K,K)\n CALL SSCAL(N-K,T,A(K+1,K),1)\nC\nC ROW ELIMINATION WITH COLUMN INDEXING\nC\n DO 30 J = KP1, N\n T = A(L,J)\n IF (L .EQ. K) GO TO 20\n A(L,J) = A(K,J)\n A(K,J) = T\n 20 CONTINUE\n CALL SAXPY(N-K,T,A(K+1,K),1,A(K+1,J),1)\n 30 CONTINUE\n GO TO 50\n 40 CONTINUE\n INFO = K\n 50 CONTINUE\n 60 CONTINUE\n 70 CONTINUE\n IPVT(N) = N\n IF (A(N,N) .EQ. 0.0E0) INFO = N\n RETURN\n END\n integer function isamax(n,sx,incx)\n IMPLICIT NONE\nc\nc finds the index of element having max. absolute value.\nc jack dongarra, linpack, 3/11/78.\nc\n real sx(1),smax\n integer i,incx,ix,n\nc\n isamax = 0\n if( n .lt. 1 ) return\n isamax = 1\n if(n.eq.1)return\n if(incx.eq.1)go to 20\nc\nc code for increment not equal to 1\nc\n ix = 1\n smax = abs(sx(1))\n ix = ix + incx\n do 10 i = 2,n\n if(abs(sx(ix)).le.smax) go to 5\n isamax = i\n smax = abs(sx(ix))\n 5 ix = ix + incx\n 10 continue\n return\nc\nc code for increment equal to 1\nc\n 20 smax = abs(sx(1))\n do 30 i = 2,n\n if(abs(sx(i)).le.smax) go to 30\n isamax = i\n smax = abs(sx(i))\n 30 continue\n return\n end\n", "meta": {"hexsha": "8e09ee6f8138aaa38a1469f08af3ca41abaee3ba", "size": 17041, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/m1.f", "max_stars_repo_name": "NoiseCIEI/RayTomo", "max_stars_repo_head_hexsha": "8b9b7c216485cb2d23450991d23fb8323e24f21b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2019-05-14T07:01:11.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-26T10:05:06.000Z", "max_issues_repo_path": "src/m1.f", "max_issues_repo_name": "NoiseCIEI/RayTomo", "max_issues_repo_head_hexsha": "8b9b7c216485cb2d23450991d23fb8323e24f21b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-12-18T08:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-20T23:48:13.000Z", "max_forks_repo_path": "src/m1.f", "max_forks_repo_name": "NoiseCIEI/RayTomo", "max_forks_repo_head_hexsha": "8b9b7c216485cb2d23450991d23fb8323e24f21b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2018-12-11T02:11:14.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-03T12:10:52.000Z", "avg_line_length": 26.5023328149, "max_line_length": 76, "alphanum_fraction": 0.4849480664, "num_tokens": 6202, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479466, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6586028345219932}} {"text": "use plantfem\nuse iso_fortran_env\nimplicit none\ninteger(int32),parameter :: N = 10\ninteger(int32),parameter :: NRHS = 1\ninteger(int32),parameter :: LDA = 10\ninteger(int32),parameter :: LDB=10\nreal(real64) :: A( LDA, N )\nreal(real64) :: IPIV(N)\nreal(real64):: B( LDB, NRHS )\nreal(real64),allocatable :: A_0(:,:)\n\ninteger(int32) :: INFO, i\n\ntype(IO_) :: f\n\ncall f%open(\"input_file.txt\",\"r\")\ndo i=1,10\n read(f%fh,*) A(i,:)\nenddo\ndo i=1,10\n read(f%fh,*) B(i,1)\nenddo\n\nA_0 = A\nCALL DGESV ( N,NRHS,A,LDA,IPIV,B,LDB,INFO )\n\n\ncall print(B)\ncall print(\"-\")\ncall print(matmul(A_0,B))\n\nend", "meta": {"hexsha": "deb4ad290574dde1a0ec0051b0f05b8c0d9b6bd9", "size": 589, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/std/LAPACK_DGESV.f90", "max_stars_repo_name": "kazulagi/plantFEM_binary", "max_stars_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-03-10T11:49:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-10T11:49:34.000Z", "max_issues_repo_path": "Tutorial/std/LAPACK_DGESV.f90", "max_issues_repo_name": "kazulagi/plantFEM_binary", "max_issues_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Tutorial/std/LAPACK_DGESV.f90", "max_forks_repo_name": "kazulagi/plantFEM_binary", "max_forks_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.8484848485, "max_line_length": 43, "alphanum_fraction": 0.6434634975, "num_tokens": 227, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008906, "lm_q2_score": 0.7279754548076478, "lm_q1q2_score": 0.6585633847320528}} {"text": "*+**********************************************************************\n* This file contains code to calculate the aspect ratio of the elements\n* in the grid:\n*\n* WHCALC - Calculates width and height\n* ARCALC - Calculates the aspect ratios\n* SETARE - Calculates the area of all elements\n************************************************************************\n\n SUBROUTINE WHCALC (DM1M3,DM2M4,IELM,KVERT,DCORVG)\nC\nC returns:\nC DM1M3 - distance between midpoints M1, M3\nC DM2M4 - distance between midpoints M2, M4\nC \n IMPLICIT NONE\n\n DOUBLE PRECISION DCORVG(2,*)\n INTEGER KVERT(4,*)\n \n DOUBLE PRECISION DM1M3,DM2M4\n INTEGER IELM\n \n DOUBLE PRECISION XE1, XE2, XE3, XE4, XM1, XM2, XM3, XM4\n DOUBLE PRECISION YE1, YE2, YE3, YE4, YM1, YM2, YM3, YM4\n INTEGER IECK1, IECK2, IECK3, IECK4\n \n IECK1=KVERT(1,IELM) \n IECK2=KVERT(2,IELM) \n IECK3=KVERT(3,IELM) \n IECK4=KVERT(4,IELM) \n\n XE1=DCORVG(1,IECK1)\n YE1=DCORVG(2,IECK1)\n XE2=DCORVG(1,IECK2)\n YE2=DCORVG(2,IECK2)\n XE3=DCORVG(1,IECK3)\n YE3=DCORVG(2,IECK3)\n XE4=DCORVG(1,IECK4)\n YE4=DCORVG(2,IECK4)\n\n XM1=(XE2+XE1)/2D0\n YM1=(YE2+YE1)/2D0\n XM2=(XE3+XE2)/2D0\n YM2=(YE3+YE2)/2D0\n XM3=(XE4+XE3)/2D0\n YM3=(YE4+YE3)/2D0\n XM4=(XE1+XE4)/2D0\n YM4=(YE1+YE4)/2D0\n\n DM1M3 = DSQRT((XM3-XM1)**2+(YM3-YM1)**2)\n DM2M4 = DSQRT((XM4-XM2)**2+(YM4-YM2)**2)\n\n END\n\n\n SUBROUTINE ARCALC (RATIO,IELM,KVERT,DCORVG)\n****************************************************************\nc by Rainer Schmachtel\nC=======================================================================\nC Calculates the aspect ratio (AR) of element IELM,\nC and returns it on RATIO.\nC=======================================================================\nC-----------------------------------------------------------------------\n IMPLICIT NONE\n\n DOUBLE PRECISION RATIO, DCORVG(2,*)\n INTEGER KVERT(4,*)\n\n INTEGER IELM\n \n DOUBLE PRECISION NENNER, ZAEHLER\n DOUBLE PRECISION XE1, XE2, XE3, XE4, XM1, XM2, XM3, XM4\n DOUBLE PRECISION YE1, YE2, YE3, YE4, YM1, YM2, YM3, YM4\n INTEGER IECK1, IECK2, IECK3, IECK4\n\n IECK1=KVERT(1,IELM) \n IECK2=KVERT(2,IELM) \n IECK3=KVERT(3,IELM) \n IECK4=KVERT(4,IELM) \n\n XE1=DCORVG(1,IECK1)\n YE1=DCORVG(2,IECK1)\n XE2=DCORVG(1,IECK2)\n YE2=DCORVG(2,IECK2)\n XE3=DCORVG(1,IECK3)\n YE3=DCORVG(2,IECK3)\n XE4=DCORVG(1,IECK4)\n YE4=DCORVG(2,IECK4)\n\n XM1=(XE2+XE1)/2D0\n YM1=(YE2+YE1)/2D0\n XM2=(XE3+XE2)/2D0\n YM2=(YE3+YE2)/2D0\n XM3=(XE4+XE3)/2D0\n YM3=(YE4+YE3)/2D0\n XM4=(XE1+XE4)/2D0\n YM4=(YE1+YE4)/2D0\n\n ZAEHLER=(XM3-XM1)**2+(YM3-YM1)**2\n NENNER =(XM4-XM2)**2+(YM4-YM2)**2\n\n RATIO=DSQRT(ZAEHLER/MAX(NENNER,1D-10))\nC RATIO=DSQRT(ZAEHLER/NENNER)\n\n END\n\n************************************************************************\n*\n* SETARE\n*\n* Flaecheninhalt aller Elemente bestimmen.\n*\n* Purpose: - writes on AREA(IEL) the area of the element IEL,\n* IEL=1,...,NEL\n* - writes on AREA(NEL+1) the sum of all AREA(IEL)\n* - KVERT,DCORVG are the usual FEAT arrays\n*\n************************************************************************\nC SUBROUTINE SETARE (AREA,NEL,KVERT,DCORVG)\nC=======================================================================\nC Declarations\nC=======================================================================\nC IMPLICIT NONE\n\nC INTEGER NNVE\nC PARAMETER (NNVE=4)\nC DOUBLE PRECISION DCORVG(2,*)\nC INTEGER NEL,KVERT(NNVE,*)\n\nC DOUBLE PRECISION AREA(*)\n \nC DOUBLE PRECISION SUM,X1,X2,X3,X4,Y1,Y2,Y3,Y4,AAA\nC INTEGER IEL,I1,I2,I3,I4\nC=======================================================================\nC SUM=0.D0\nC DO 11 IEL=1,NEL\nC\nC I1=KVERT(1,IEL)\nC I2=KVERT(2,IEL)\nC I3=KVERT(3,IEL)\nC I4=KVERT(4,IEL)\nC\nC X1=DCORVG(1,I1)\nC X2=DCORVG(1,I2)\nC X3=DCORVG(1,I3)\nC X4=DCORVG(1,I4)\nC\nC Y1=DCORVG(2,I1)\nC Y2=DCORVG(2,I2)\nC Y3=DCORVG(2,I3)\nC Y4=DCORVG(2,I4)\nC\nC Berechnung des Flaecheninhaltes des Rechtecks.\nC Dazu wird der Flaecheninhalt der beiden Dreiecke\nC (X1,Y1)->(X2,Y2)->(X3,Y3) und (X1,Y1)->(X3,Y3)->(X4,Y4)\nC berechnet, indem die Determinante der Matrix aus den aufspannenden\nC Vektoren berechnet und halbiert wird.:\nC det ( X1-X2 X3-X2 ) + det (X1-X4 X3-X4 )\nC Y1-Y2 Y1-Y3 Y1-Y4 Y3-Y4\nC\nC AAA=0.5D0*( DABS((X1-X2)*(Y3-Y2)-(Y1-Y2)*(X3-X2))\nC * +DABS((X1-X4)*(Y3-Y4)-(Y1-Y4)*(X3-X4)) )\nC AREA(IEL)=AAA\nC SUM=SUM+AAA\nC 11 CONTINUE\nC\nC AREA(NEL+1)=SUM\nC\nC END\n", "meta": {"hexsha": "6aea435fe13a38b52b0191cb56801c676f041999", "size": 4801, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "area51/cc2d_movbc_structured_2/src/discr_linear/arcalc.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/discr_linear/arcalc.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/discr_linear/arcalc.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": 28.0760233918, "max_line_length": 72, "alphanum_fraction": 0.493022287, "num_tokens": 1799, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422644, "lm_q2_score": 0.7279754371026367, "lm_q1q2_score": 0.6585633724579989}} {"text": " program demo_random_int\n use M_random, only : random_int, init_random_seed_by_system_clock\n call init_random_seed_by_system_clock()\n write(*,'(*(i0:,1x))')(random_int(1,10),i=1,20)\n write(*,'(*(i0:,1x))')(random_int(-5,5),i=1,20)\n end program demo_random_int\n", "meta": {"hexsha": "7832f30d1ba44cfb4a2910cdf651bea5f57af857", "size": 284, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/demo_random_int.f90", "max_stars_repo_name": "urbanjost/M_random", "max_stars_repo_head_hexsha": "4da4a40a1a16ea3c153e34bcd40daef3cbba3a90", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "example/demo_random_int.f90", "max_issues_repo_name": "urbanjost/M_random", "max_issues_repo_head_hexsha": "4da4a40a1a16ea3c153e34bcd40daef3cbba3a90", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-01-16T21:22:23.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-17T20:53:49.000Z", "max_forks_repo_path": "example/demo_random_int.f90", "max_forks_repo_name": "urbanjost/M_random", "max_forks_repo_head_hexsha": "4da4a40a1a16ea3c153e34bcd40daef3cbba3a90", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.5714285714, "max_line_length": 70, "alphanum_fraction": 0.6725352113, "num_tokens": 89, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.879146780175245, "lm_q2_score": 0.7490872187162396, "lm_q1q2_score": 0.6585576164048116}} {"text": "#include \"macros.h\"\n\nmodule diffops\n use numbers\n use openmpi\n use io\n use parameters\n use fftw\n\n contains \n\n!==============================================================================\n\n complex(dpc) function nabla(ix, iy, iz, d)\n integer(i4), intent(in) :: ix, iy, iz, d\n\n select case (d)\n case(1)\n nabla = imag_1 * kx(ix)\n case(2)\n nabla = imag_1 * ky(iy)\n case(3)\n nabla = imag_1 * kz(iz)\n end select\n end function nabla\n\n!==============================================================================\n\n complex(dpc) function laplacian(ix, iy, iz)\n integer(i4), intent(in) :: ix, iy, iz\n\n laplacian = kx(ix)**2 + ky(iy)**2 + kz(iz)**2\n end function laplacian\n\n!==============================================================================\n\n complex(dpc) function inverse_laplacian(ix, iy, iz)\n integer(i4), intent(in) :: ix, iy, iz\n \n if (qx(ix) == 0 .and. qy(iy) == 0 .and. qz(iz) == 0) then\n inverse_laplacian = 0\n else\n inverse_laplacian = 1.0_dp / laplacian(ix,iy,iz)\n end if\n end function inverse_laplacian\n\n!==============================================================================\n\n subroutine diffops_div(vfieldk, div_vfieldk)\n\n complex(dpc), intent(in) :: vfieldk(:, :, :, :)\n complex(dpc), intent(out) :: div_vfieldk(:, :, :)\n integer(i4) :: dim\n _indices\n \n div_vfieldk = 0\n\n do dim = 1, 3\n _loop_spec_begin\n div_vfieldk(ix, iy, iz) = div_vfieldk(ix, iy, iz) + &\n nabla(ix, iy, iz, dim) * vfieldk(ix, iy, iz, dim)\n _loop_spec_end\n end do\n\n end subroutine diffops_div\n\n!==============================================================================\n\n subroutine diffops_partx(sfieldk, partx_sfieldk)\n\n complex(dpc), intent(in) :: sfieldk(:, :, :)\n complex(dpc), intent(out) :: partx_sfieldk(:, :, :)\n _indices\n \n _loop_spec_begin\n partx_sfieldk(ix, iy, iz) = imag_1 * kx(ix) * sfieldk(ix, iy, iz)\n _loop_spec_end\n \n end subroutine diffops_partx\n \n!==============================================================================\n\n subroutine diffops_party(sfieldk, party_sfieldk)\n\n complex(dpc), intent(in) :: sfieldk(:, :, :)\n complex(dpc), intent(out) :: party_sfieldk(:, :, :)\n _indices\n \n _loop_spec_begin\n party_sfieldk(ix, iy, iz) = imag_1 * ky(iy) * sfieldk(ix, iy, iz)\n _loop_spec_end\n \n end subroutine diffops_party\n \n!==============================================================================\n\n subroutine diffops_partz(sfieldk, partz_sfieldk)\n\n complex(dpc), intent(in) :: sfieldk(:, :, :)\n complex(dpc), intent(out) :: partz_sfieldk(:, :, :)\n _indices\n \n _loop_spec_begin\n partz_sfieldk(ix, iy, iz) = imag_1 * kz(iz) * sfieldk(ix, iy, iz)\n _loop_spec_end\n \n end subroutine diffops_partz\n \n!============================================================================== \n\nend module diffops", "meta": {"hexsha": "018e3fc05500e3b15046d84c06ed1760f081628f", "size": 3262, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "diffops.f90", "max_stars_repo_name": "gokhanyalniz/dnsbox", "max_stars_repo_head_hexsha": "4c5d6d5d2cd98dbd5b86423f9457b0df8f7ac947", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-18T08:11:15.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T08:11:15.000Z", "max_issues_repo_path": "diffops.f90", "max_issues_repo_name": "gokhanyalniz/dnsbox", "max_issues_repo_head_hexsha": "4c5d6d5d2cd98dbd5b86423f9457b0df8f7ac947", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-07-20T12:19:11.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-21T20:29:59.000Z", "max_forks_repo_path": "diffops.f90", "max_forks_repo_name": "gokhanyalniz/dnsbox", "max_forks_repo_head_hexsha": "4c5d6d5d2cd98dbd5b86423f9457b0df8f7ac947", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-12-12T08:18:37.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-03T14:52:53.000Z", "avg_line_length": 29.3873873874, "max_line_length": 81, "alphanum_fraction": 0.4301042305, "num_tokens": 799, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467770088163, "lm_q2_score": 0.7490872187162397, "lm_q1q2_score": 0.6585576140328804}} {"text": "! Author of the program Vladimir Fuka\n! Modified by\n! Donato Cecere\n! 1 July 2007 \n\nmodule CUeuler\n implicit none\n\n integer,parameter:: KND=KIND(1.0D0)\n\n integer RKtype !(1 - 1. order ... 3 - 3. order, 4. fully discrete)\n integer FLUXtype !(1 - KURGTADMOR, 2 - CENTUPW, 3 - LAXFRIED, 4 - LAXWENDROFF,5 - MUSTA)\n integer MUSTAstages!(Number of stages for MUSTA flux, for 1 it reduces to FORCE flux)\n integer RECtype !(1 - piecewise constant, 2 - piecewise linear)\n integer limitertype !(1 - minmod, 2 - modified minmod (MC), 3 - modified superbee)\n real(KND) limparam !(parameter for limiter - only if needed)\n integer extype !(1 - shock tube test, 2 - smooth test case with periodic BC)\n integer outputtype !(1 - single frame textfiles for gnuplot, 2- one Tecplot file) Tecplot output by Donato Cecere, beta\n integer nx,nt\n \n real(KND) time,dx,xl,xr,dt,tend,CFL,rhoLEFT,rhouLEFT,eLEFT,rhoRIGHT,rhouRIGHT,eRIGHT\n\n real(KND),parameter:: gamma=1.4_KND, pi=3.1415926535_KND\n \n interface MINMOD\n module procedure MINMOD2, MINMOD3\n end interface\n \n contains\n \n subroutine TMARCH(rho,rhou,e,x)\n integer i\n real(KND),dimension(-2:):: rho,rhou,e,x\n\t !real(KND),dimension(-2:nx+3):: rho,rhou,e\n\t real(KND),dimension(LBOUND(rho,1):UBOUND(rho,1)):: rho2,rhou2,e2,drho,drhou,de\n\n if (RKtype==1) then\n call DRK(drho,drhou,de,rho,rhou,e,x)\n rho=rho + dt*drho\n rhou=rhou + dt*drhou\n e=e + dt*de\n \n elseif (RKtype==2) then\n call DRK(drho,drhou,de,rho,rhou,e,x)\n rho2=rho + dt*drho\n rhou2=rhou + dt*drhou\n e2=e + dt*de\n\n call DRK(drho,drhou,de,rho2,rhou2,e2,x)\n rho=(1._KND/2._KND)*rho + (1._KND/2._KND)*rho2 + (1._KND/2._KND)*dt*drho\n rhou=(1._KND/2._KND)*rhou + (1._KND/2._KND)*rhou2 + (1._KND/2._KND)*dt*drhou\n e=(1._KND/2._KND)*e + (1._KND/2._KND)*e2 + (1._KND/2._KND)*dt*de\n\n elseif (RKtype==3) then\n\n call DRK(drho,drhou,de,rho,rhou,e,x) !1\n rho2=rho + dt*drho\n rhou2=rhou + dt*drhou\n e2=e + dt*de\n \n call DRK(drho,drhou,de,rho2,rhou2,e2,x) !2\n rho2=(3._KND/4._KND)*rho + (1._KND/4._KND)*rho2 + (1._KND/4._KND)*dt*drho\n rhou2=(3._KND/4._KND)*rhou + (1._KND/4._KND)*rhou2 + (1._KND/4._KND)*dt*drhou\n e2=(3._KND/4._KND)*e + (1._KND/4._KND)*e2 + (1._KND/4._KND)*dt*de\n \n call DRK(drho,drhou,de,rho2,rhou2,e2,x) !3\n rho=(1._KND/3._KND)*rho + (2._KND/3._KND)*rho2 + (2._KND/3._KND)*dt*drho\n rhou=(1._KND/3._KND)*rhou + (2._KND/3._KND)*rhou2 + (2._KND/3._KND)*dt*drhou\n e=(1._KND/3._KND)*e + (2._KND/3._KND)*e2 + (2._KND/3._KND)*dt*de\n \n elseif (RKtype==4) then\n call DFD(rho,rhou,e)\n endif \n endsubroutine TMARCH \n\n \n subroutine DRK(drho,drhou,de,rho,rhou,e,x)\n real(KND),dimension(-2:):: rho,rhou,e,drho,drhou,de,x\n real(KND),allocatable,dimension(:):: rhoL,rhouL,eL,rhoR,rhouR,eR\n drho=0\n drhou=0\n de=0\n\n allocate(rhoL(-2:nx+2))\n allocate(rhouL(-2:nx+2))\n allocate(eL(-2:nx+2))\n \n allocate(rhoR(-2:nx+2))\n allocate(rhouR(-2:nx+2))\n allocate(eR(-2:nx+2))\n \n \n call BOUND(rho,rhou,e) !boundary condition\n if (RECtype==1) then\n call PCONST(rhoL,rhouL,eL,rhoR,rhouR,eR,rho,rhou,e)\n elseif (RECtype==2) then\n call MUSCL(rhoL,rhouL,eL,rhoR,rhouR,eR,rho,rhou,e,x)\n endif\n\n if (FLUXtype==1) then\n call FLUXESKT(drho,drhou,de,rhoL,rhouL,eL,rhoR,rhouR,eR,x)\n elseif (FLUXtype==2) then\n call FLUXESCU(drho,drhou,de,rhoL,rhouL,eL,rhoR,rhouR,eR)\n elseif (FLUXtype==3) then\n call FLUXESLF(drho,drhou,de,rhoL,rhouL,eL,rhoR,rhouR,eR)\n elseif (FLUXtype==4) then\n call FLUXESLW(drho,drhou,de,rhoL,rhouL,eL,rhoR,rhouR,eR)\n elseif (FLUXtype==5) then\n call FLUXESMUSTA(drho,drhou,de,rhoL,rhouL,eL,rhoR,rhouR,eR)\n elseif (FLUXtype==6) then\n call FLUXESCULD(drho,drhou,de,rhoL,rhouL,eL,rhoR,rhouR,eR)\n endif\n\n deallocate(rhoL,rhoR,rhouL,rhouR,eL,eR)\n endsubroutine DRK\n\n subroutine DFD(rho,rhou,e)\n real(KND),dimension(-2:):: rho,rhou,e\n\n if (FLUXtype==3) then\n call FDLF(rho,rhou,e)\n elseif (FLUXtype==4) then\n call FDLW(rho,rhou,e)\n endif\n endsubroutine DFD\n \n\n! This procedure calculates extrapolated values of the dependent variables using \n! a central difference scheme: k = 1, see Tannehill-Anderson-Pletcher, pp. 204-205.\n! The values for the extrapolated variables on both sides of the interface are \n! calculated on the left of i point. \n\n subroutine MUSCL(rhoL,rhouL,eL,rhoR,rhouR,eR,rho,rhou,e,x)\n real(KND),dimension(-2:)::rhoL,rhouL,eL,rhoR,rhouR,eR,rho,rhou,e,x\n real(KND) sL,sC,sR\n integer i\n\n do i=0,nx+1\n! sL=(rho(i)-rho(i-1))\n sL=(rho(i)-rho(i-1))/(x(i)-x(i-1))\n! sR=(rho(i+1)-rho(i))\n sR=(rho(i+1)-rho(i))/(x(i+1)-x(i))\n sL=sL\n sR=sR\n sC=LIMITER(sL,sR)\n rhoR(i)=rho(i)-sC*(0.5_KND)*(x(i)-x(i-1))\n rhoL(i+1)=rho(i)+sC*(0.5_KND)*(x(i+1)-x(i))\n enddo\n do i=0,nx+1\n! sL=(rhou(i)-rhou(i-1))\n sL=(rhou(i)-rhou(i-1))/(x(i)-x(i-1)) \n! sR=(rhou(i+1)-rhou(i))\n sR=(rhou(i+1)-rhou(i))/(x(i+1)-x(i))\n sL=sL\n sR=sR\n sC=LIMITER(sL,sR)\n rhouR(i)=rhou(i)-sC*(0.5_KND)*(x(i)-x(i-1))\n rhouL(i+1)=rhou(i)+sC*(0.5_KND)*(x(i+1)-x(i))\n enddo\n do i=0,nx+1\n! sL=(e(i)-e(i-1))\n sL=(e(i)-e(i-1))/(x(i)-x(i-1))\n! sR=(e(i+1)-e(i))\n sR=(e(i+1)-e(i))/(x(i+1)-x(i))\n sL=sL\n sR=sR\n sC=LIMITER(sL,sR)\n eR(i)=e(i)-sC*(0.5_KND)*(x(i)-x(i-1))\n eL(i+1)=e(i)+sC*(0.5_KND)*(x(i+1)-x(i))\n enddo\n endsubroutine MUSCL\n! Linear Piecewise extrapolation \n subroutine PCONST(rhoL,rhouL,eL,rhoR,rhouR,eR,rho,rhou,e)\n real(KND),dimension(-2:)::rhoL,rhouL,eL,rhoR,rhouR,eR,rho,rhou,e\n\n integer i\n\n do i=0,nx+1\n rhoR(i)=rho(i)\n rhoL(i+1)=rho(i)\n enddo\n do i=0,nx+1\n rhouR(i)=rhou(i)\n rhouL(i+1)=rhou(i)\n enddo\n do i=0,nx+1\n eR(i)=e(i)\n eL(i+1)=e(i)\n enddo\n endsubroutine PCONST\n \n\n \n \n subroutine FLUXESLF(drho,drhou,de,rhoL,rhouL,eL,rhoR,rhouR,eR)\n real(KND),dimension(-2:)::rhoL,rhouL,eL,rhoR,rhouR,eR\n real(KND),dimension(LBOUND(rhoL,1):UBOUND(rhoL,1))::drho,drhou,de,pL,pR\n real(KND) p,A\n integer i\n\n do i=1,nx+1\n pL(i)=(gamma-1._KND)*(eL(i)-(1._KND/2._KND)*(rhouL(i)*rhouL(i))/rhoL(i))\n pR(i)=(gamma-1._KND)*(eR(i)-(1._KND/2._KND)*(rhouR(i)*rhouR(i))/rhoR(i))\n if ((pL(i)<0).or.(pR(i)<0)) write(*,*) \"ERROR! pressure < 0\",pL(i),pR(i)\n enddo\n\n A=dx/(dt)\n !\n !flux of rho\n !\n drho(1)=-(frho(rhoL(1),rhouL(1),eL(1),pL(1))+frho(rhoR(1),rhouR(1),eR(1),pR(1))&\n -A*(rhoR(1)-rhoL(1)))/dx\n\n do i=2,nx\n p=frho(rhoL(i),rhouL(i),eL(i),pL(i))+frho(rhoR(i),rhouR(i),eR(i),pR(i))&\n -A*(rhoR(i)-rhoL(i))\n drho(i-1)=drho(i-1)+p/dx\n drho(i)=drho(i)-p/dx\n enddo\n drho(nx)=drho(nx)+(frho(rhoL(nx+1),rhouL(nx+1),eL(nx+1),pL(1))&\n +frho(rhoR(nx+1),rhouR(nx+1),eR(nx+1),pR(1))&\n -A*(rhoR(nx+1)-rhoL(nx+1)))/dx\n\n drho=-drho/2._KND\n\n !\n !flux of rho*u\n !\n drhou(1)=-(frhou(rhoL(1),rhouL(1),eL(1),pL(1))+frhou(rhoR(1),rhouR(1),eR(1),pR(1))&\n -A*(rhouR(1)-rhouL(1)))/dx\n do i=2,nx\n p=frhou(rhoL(i),rhouL(i),eL(i),pL(i))+frhou(rhoR(i),rhouR(i),eR(i),pR(i))&\n -A*(rhouR(i)-rhouL(i))\n drhou(i-1)=drhou(i-1)+p/dx\n drhou(i)=drhou(i)-p/dx\n enddo\n drhou(nx)=drhou(nx)+(frhou(rhoL(nx+1),rhouL(nx+1),eL(nx+1),pL(nx+1))&\n +frhou(rhoR(nx+1),rhouR(nx+1),eR(nx+1),pR(nx+1))&\n -A*(rhouR(nx+1)-rhouL(nx+1)))/dx\n\n drhou=-drhou/2._KND\n\n\n !\n !flux ef energy\n !\n de(1)=-(fe(rhoL(1),rhouL(1),eL(1),pL(1))+fe(rhoR(1),rhouR(1),eR(1),pR(1))&\n -A*(eR(1)-eL(1)))/dx\n do i=2,nx\n p=fe(rhoL(i),rhouL(i),eL(i),pL(i))+fe(rhoR(i),rhouR(i),eR(i),pR(i))&\n -A*(eR(i)-eL(i))\n de(i-1)=de(i-1)+p/dx\n de(i)=de(i)-p/dx\n enddo\n de(nx)=de(nx)+(fe(rhoL(nx+1),rhouL(nx+1),eL(nx+1),pL(nx+1))&\n +fe(rhoR(nx+1),rhouR(nx+1),eR(nx+1),pR(nx+1))&\n -A*(eR(nx+1)-eL(nx+1)))/dx\n\n de=-de/2._KND\n endsubroutine FLUXESLF\n\n subroutine FLUXESLW(drho,drhou,de,rhoL,rhouL,eL,rhoR,rhouR,eR)\n real(KND),dimension(-2:)::rhoL,rhouL,eL,rhoR,rhouR,eR\n real(KND),dimension(LBOUND(rhoL,1):UBOUND(rhoL,1))::drho,drhou,de,flrho,flrhou,fle\n real(KND) A,pL,pR,pM\n real(KND),DIMENSION(1:3):: qL,qR,qM,fl,fr\n integer i\n real(KND),PARAMETER:: eps=0.0001\n\n A=dx/dt\n do i=1,nx+1\n qL=(/ rhoL(i),rhouL(i),eL(i) /)\n qR=(/ rhoR(i),rhouR(i),eR(i) /)\n pL=(gamma-1._KND)*(eL(i)-0.5_KND*(rhouL(i)*rhouL(i))/rhoL(i))\n pR=(gamma-1._KND)*(eR(i)-0.5_KND*(rhouR(i)*rhouR(i))/rhoR(i))\n if (pL<0) pL=0\n if (pR<0) pR=0\n\n fl(1)=frho(qL(1),qL(2),qL(3),pL)\n fl(2)=frhou(qL(1),qL(2),qL(3),pL)\n fl(3)=fe(qL(1),qL(2),qL(3),pL)\n fr(1)=frho(qR(1),qR(2),qR(3),pR)\n fr(2)=frhou(qR(1),qR(2),qR(3),pR)\n fr(3)=fe(qR(1),qR(2),qR(3),pR)\n\n qM=0.5_KND*(qL+qR)-(0.5_KND/A)*(fr-fl)\n if (qM(1)0._KND).and.(b>0._KND).and.(c>0._KND)) then \n MINMOD3=MIN(a,b,c)\n elseif ((a<0._KND).and.(b<0._KND).and.(c<0._KND)) then\n MINMOD3=MAX(a,b,c)\n else\n MINMOD3=0._KND\n endif\n endfunction MINMOD3\n\n real(KND) function SUPERBEE(a,b)\n real(KND) a,b,ab,b2\n\n ab=a*b\n b2=b*b\n if ((a*b)<=0._KND) then\n SUPERBEE=0._KND\n else if (limparam*ab 1.0d0)\n p%s(:) = 2.0d0-p%s(:)\n p%v(:) = -p%v(:)\n end where\n end subroutine bounds\n \nend module misc\n\n\n\nprogram nbody\n\n use globals\n use misc\n\n implicit none\n\n type(particle), dimension(n) :: particles\n integer :: i, j\n real(8) :: t, e, twrite\n\n\n call init(particles)\n\n t = 0.0d0\n twrite = 0.0d0\n\n do while ( t < 1.0d0)\n\n e = 0.0d0\n\n do j = 1, n\n particles(j)%a = 0.0d0\n e = e + kine(particles(j))\n\n do i = 1, n\n call acc(particles(j), particles(i))\n e = e + pote(particles(j), particles(i))\n end do\n end do\n\n do j = 1, n\n call vel(particles(j))\n call dis(particles(j))\n call bounds(particles(j))\n end do\n\n t = t + dt\n\n if (t > twrite) then\n write(*,*) e\n twrite = t+0.1d0\n end if\n end do\nend program nbody\n", "meta": {"hexsha": "d01883f80b96f417171b1c53755442a2b4597b92", "size": 2471, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lectures5and6/example/src/nbody.abstract.f90", "max_stars_repo_name": "sdm900/fortran_course", "max_stars_repo_head_hexsha": "6f2db3fcc7b616b94c4e1fe8875a3158a01117b2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lectures5and6/example/src/nbody.abstract.f90", "max_issues_repo_name": "sdm900/fortran_course", "max_issues_repo_head_hexsha": "6f2db3fcc7b616b94c4e1fe8875a3158a01117b2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lectures5and6/example/src/nbody.abstract.f90", "max_forks_repo_name": "sdm900/fortran_course", "max_forks_repo_head_hexsha": "6f2db3fcc7b616b94c4e1fe8875a3158a01117b2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.347826087, "max_line_length": 74, "alphanum_fraction": 0.5240793201, "num_tokens": 913, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095292, "lm_q2_score": 0.749087201911703, "lm_q1q2_score": 0.6585575921434317}} {"text": "module matrix_module\nreal(kind=8), allocatable :: a2(:,:)\nreal(kind=8), allocatable :: b2(:,:)\nreal(kind=8), allocatable :: c2(:,:)\ninteger matrix_size\nend module\n\n\nsubroutine sub_initialize\n\tuse matrix_module\n\tparameter (MAX_MATRIX=15000)\n\tinteger(kind=8) i8n\n\n\tmatrix_size=MAX_MATRIX\n\tn = matrix_size\n\ti8n = (n/1000)*(n/1000)*8*3\n\tallocate (a2(n,n), b2(n,n), c2(n,n), stat=ierr)\n\twrite(*,*) \" allocating\", i8n, \" MB of memory\"\n\tif(ierr.eq.0) then\n\t\twrite(*,*) \" was successful\"\n\telse\n\t\twrite(*,*) \"*** Error. failed: ierr=\", ierr\n\tendif\n!$omp parallel \n!$omp do \n\tdo j=1, n\n\tdo i=1, n\n\ta2(i,j) = 1.0\n\tb2(i,j) = 2.0\n\tc2(i,j) = 3.0\n\tend do\n\tend do\n!$omp end do\n!$omp end parallel\n\treturn\nend\n\t\nsubroutine sub_dgemm\n\tuse matrix_module\n\treal(kind=8) :: one, x\n\n!cx\twrite(*,*) \" matrix size:\", matrix_size\n\n\tif(.true.) then\n\tn = matrix_size\n\tone = 1.0\n\tcall dgemm (\"N\", \"N\", n, n, n, one, a2, n, b2, n, one, c2, n)\n\n\telse\n!$omp parallel \n!$omp do private(x)\n\tdo j=1, n\n\tdo i=1, n\n\tx = 0.0\n\tdo k=1, n\n\tx = x + a2(i,k)*b2(k,j)\n\tend do\n\tc2(i,j) = x\n\tend do\n\tend do\n!$omp end do\n!$omp end parallel\n\tendif\n\treturn\nend\n\n", "meta": {"hexsha": "294803edb25f9f1057b884a1a01e381c10ccdd97", "size": 1159, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "doc/src_advanced/sub_dgemm.f90", "max_stars_repo_name": "mikami3heart/PMlib", "max_stars_repo_head_hexsha": "d62172f64bb3d561959d7b91fb1f80f5465d85fa", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2015-01-11T15:48:02.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-24T05:13:58.000Z", "max_issues_repo_path": "doc/src_advanced/sub_dgemm.f90", "max_issues_repo_name": "mikami3heart/PMlib", "max_issues_repo_head_hexsha": "d62172f64bb3d561959d7b91fb1f80f5465d85fa", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2015-05-27T06:06:03.000Z", "max_issues_repo_issues_event_max_datetime": "2017-03-21T03:55:42.000Z", "max_forks_repo_path": "doc/src_advanced/sub_dgemm.f90", "max_forks_repo_name": "mikami3heart/PMlib", "max_forks_repo_head_hexsha": "d62172f64bb3d561959d7b91fb1f80f5465d85fa", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2015-01-06T08:39:31.000Z", "max_forks_repo_forks_event_max_datetime": "2017-07-14T01:14:06.000Z", "avg_line_length": 17.2985074627, "max_line_length": 63, "alphanum_fraction": 0.6272648835, "num_tokens": 452, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473879530491, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6585481217306889}} {"text": "FUNCTION hermite(npt, func, ier) RESULT(fn_val)\r\n\r\n! HERMITE INTEGRATION, I.E. EVALUATION OF THE INTEGRAL OF\r\n! exp(-x**2)*f(x) FROM -INFINITY TO +INFINITY\r\n\r\n! NPT = INPUT, NO. OF POINTS AT WHICH f(x) IS TO BE EVALUATED.\r\n! NPT MUST BE ONE OF 2, 4, 6, 8, 10, 12, 16, 20.\r\n! FUNC = INPUT, NAME OF THE USER'S FUNCTION TO SUPPLY VALUES\r\n! OF F(X). THE FUNCTION MAY HAVE ANY NAME BUT ONLY THE\r\n! ONE ARGUMENT, X.\r\n! IER = OUTPUT, ERROR INDICATOR\r\n! = 0 NO ERROR DETECTED\r\n! = 1 ILLEGAL VALUE OF NPT\r\n\r\n! LATEST REVISION - 5 December 1999\r\n\r\n!************************************************************************\r\n\r\nIMPLICIT NONE\r\nINTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(12, 60)\r\n\r\nINTEGER, INTENT(IN) :: npt\r\nINTEGER, INTENT(OUT) :: ier\r\nREAL (dp) :: fn_val\r\n\r\nINTERFACE\r\n FUNCTION func(x) RESULT(fn_val)\r\n IMPLICIT NONE\r\n INTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(12, 60)\r\n REAL (dp), INTENT(IN) :: x\r\n REAL (dp) :: fn_val\r\n END FUNCTION func\r\nEND INTERFACE\r\n\r\n! Local variables\r\n\r\nREAL (dp) :: xpt(39) = (/ 0.707106781186548_dp, &\r\n 0.524647623275290_dp, 1.650680123885785_dp, &\r\n 0.436077411927617_dp, 1.335849074013697_dp, 2.350604973674492_dp, &\r\n 0.381186990207322_dp, 1.157193712446780_dp, 1.981656756695843_dp, &\r\n 2.930637420257244_dp, &\r\n 0.342901327223705_dp, 1.036610829789514_dp, 1.756683649299882_dp, &\r\n 2.532731674232790_dp, 3.436159118837738_dp, &\r\n 0.314240376254359_dp, 0.947788391240164_dp, 1.597682635152605_dp, &\r\n 2.279507080501060_dp, 3.020637025120890_dp, 3.889724897869782_dp, &\r\n 0.27348104613815_dp, 0.82295144914466_dp, 1.38025853919888_dp, &\r\n 1.95178799091625_dp, 2.54620215784748_dp, 3.17699916197996_dp, &\r\n 3.86944790486012_dp, 4.68873893930582_dp, &\r\n 0.2453407083009_dp, 0.7374737285454_dp, 1.2340762153953_dp, &\r\n 1.7385377121166_dp, 2.2549740020893_dp, 2.7888060584281_dp, &\r\n 3.3478545673832_dp, 3.9447640401156_dp, 4.6036824495507_dp, &\r\n 5.3874808900112_dp /), &\r\n wt(39) = (/ 8.862269254528D-1, &\r\n 8.049140900055D-1, 8.131283544725D-2, &\r\n 7.246295952244D-1, 1.570673203229D-1, 4.530009905509D-3, &\r\n 6.611470125582D-1, 2.078023258149D-1, 1.707798300741D-2, &\r\n 1.996040722114D-4, &\r\n 6.108626337353D-1, 2.401386110823D-1, 3.387439445548D-2, &\r\n 1.343645746781D-3, 7.640432855233D-6, &\r\n 5.701352362625D-1, 2.604923102642D-1, 5.160798561588D-2, &\r\n 3.905390584629D-3, 8.573687043588D-5, 2.658551684356D-7, &\r\n 5.079294790166D-1, 2.806474585285D-1, 8.381004139899D-2, &\r\n 1.288031153551D-2, 9.322840086242D-4, 2.711860092538D-5, &\r\n 2.320980844865D-7, 2.654807474011D-10, &\r\n 4.622436696006D-1, 2.866755053628D-1, 1.090172060200D-1, &\r\n 2.481052088746D-2, 3.243773342238D-3, 2.283386360163D-4, &\r\n 7.802556478532D-6, 1.086069370769D-7, 4.399340992273D-10, &\r\n 2.229393645534D-13 /), zero = 0.0_dp, x\r\nINTEGER :: npts(8) = (/ 2, 4, 6, 8, 10, 12, 16, 20 /), ipos, i, nby2\r\n\r\n! CHECK FOR PERMISSIBLE VALUE OF NPT.\r\n\r\nfn_val = zero\r\nipos = 1\r\nDO i = 1, 8\r\n IF(npts(i).EQ.npt) GO TO 20\r\n ipos = ipos + (npts(i) + 1)/2\r\nEND DO\r\nier = 1\r\nRETURN\r\n\r\n! EVALUATE SUM OF WT(I) * FUNC(X(I))\r\n\r\n20 nby2 = (npt + 1)/2\r\nDO i = 1, nby2\r\n x = xpt(ipos)\r\n fn_val = fn_val + wt(ipos) * (func(x) + func(-x))\r\n ipos = ipos + 1\r\nEND DO\r\nier = 0\r\nRETURN\r\n\r\nEND FUNCTION hermite\r\n", "meta": {"hexsha": "0d42931f8e797ac736783be1e9d5502dd8c5c757", "size": 3869, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/hermite.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/hermite.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/hermite.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": 41.1595744681, "max_line_length": 83, "alphanum_fraction": 0.5657792711, "num_tokens": 1493, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473813156295, "lm_q2_score": 0.7549149978955811, "lm_q1q2_score": 0.6585481215301041}} {"text": "c\nc * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nc * *\nc * copyright (c) 1998 by UCAR *\nc * *\nc * University Corporation for Atmospheric Research *\nc * *\nc * all rights reserved *\nc * *\nc * SPHEREPACK version 3.2 *\nc * *\nc * A Package of Fortran77 Subroutines and Programs *\nc * *\nc * for Modeling Geophysical Processes *\nc * *\nc * by *\nc * *\nc * John Adams and Paul Swarztrauber *\nc * *\nc * of *\nc * *\nc * the National Center for Atmospheric Research *\nc * *\nc * Boulder, Colorado (80307) U.S.A. *\nc * *\nc * which is sponsored by *\nc * *\nc * the National Science Foundation *\nc * *\nc * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nc\nc\nc\nc\nc 6/98\nc\nc a program for testing all vorticity and ivnerse vorticity routines\nc\nc\nc (1) first set a stream function and velocity potential scalar fields as\nc polys in x,y,z restricted to the sphere\nc\nc (2) derive a vector field (v,w) from (1)\nc\nc (3) compute the vorticity vt of (2) and compare with the vorticity\nc computed analytically\nc\nc (4) compute vector field (ve,we) using br,bi,cr,ci from (v,w) with\nc br=bi=0.0\nc\nc (5) invert the vorticity in (3) and compare with (4)\nc\n\n program tvrt\nc\nc set dimensions with parameter statements\nc\n parameter(nnlat= 24,nnlon= 14, nnt = 3)\n parameter (mmdab = (nnlon+2)/2, mmdc = (nnlon+1)/2)\n parameter (lleng= 5*nnlat*nnlat*nnlon,llsav=5*nnlat*nnlat*nnlon)\n dimension work(lleng),wsave(llsav)\n parameter (lldwork = 4*nnlat*nnlat)\n dimension dwork(lldwork)\n dimension br(mmdc,nnlat,nnt),bi(mmdc,nnlat,nnt)\n dimension cr(mmdc,nnlat,nnt),ci(mmdc,nnlat,nnt)\n dimension a(mmdab,nnlat,nnt),b(mmdab,nnlat,nnt)\n dimension vt(nnlat,nnlon,nnt)\n dimension thetag(nnlat),dtheta(nnlat),dwts(nnlat)\n dimension v(nnlat,nnlon,nnt),w(nnlat,nnlon,nnt)\n dimension ve(nnlat,nnlon,nnt),we(nnlat,nnlon,nnt)\n dimension pertrb(nnt)\n double precision dtheta, dwts\nc\nc set dimension variables\nc\n nlat = nnlat\n nlon = nnlon\n nmax = max0(nlat,nlon)\n mdab = mmdab\n mdc = mmdc\n lwork = lleng\n lsave = llsav\n ldwork = lldwork\n nt = nnt\n call iout(nlat,\"nlat\")\n call iout(nlon,\"nlon\")\n call iout(nt,\" nt\")\n isym = 0\n ityp = 0\nc\nc set equally spaced colatitude and longitude increments\nc\n pi = 4.0*atan(1.0)\n dphi = (pi+pi)/nlon\n dlat = pi/(nlat-1)\nc\nc compute nlat gaussian points in thetag\nc\n call gaqd(nlat,dtheta,dwts,dwork,ldwork,ier)\n do i=1,nlat\n\tthetag(i) = dtheta(i)\n end do\n call name(\"gaqd\")\n call iout(ier,\" ier\")\n call vecout(thetag,\"thtg\",nlat)\nc\nc test all vorticity subroutines\nc\n do icase=1,4\n call name(\"****\")\n call name(\"****\")\n call iout(icase,\"icas\")\nc\nc\nc set scalar stream and velocity potential fields as polys in x,y,z\nc and then set v,w from st,sv scalar fields\nc\n do k=1,nt\n\tdo j=1,nlon\n\t phi = (j-1)*dphi\n\t sinp = sin(phi)\n\t cosp = cos(phi)\n\t do i=1,nlat\n\t theta = (i-1)*dlat\n\t if (icase.gt.2) theta=thetag(i)\n\t cost = cos(theta)\n\t sint = sin(theta)\n\t x = sint*cosp\n\t y = sint*sinp\n\t z = cost\n\t dxdt = cost*cosp\n\t dxdp = -sint*sinp\n\t dydt = cost*sinp\n\t dydp = sint*cosp\n\t dzdt = -sint\n\t dzdp = 0.0\n\t if (k.eq.1) then\nc st(i,j,k) = x\nc sv(i,j,k) = y\nc\nc v = -1/sin(theta)*dstdp + dsvdt\nc\nc w = 1/sin(theta)*dsvdp + dstdt\nc\n\t v(i,j,k) = sinp + cost*sinp\n\t w(i,j,k) = cosp + cost*cosp\n\t vt(i,j,k) = -2.0*sint*cosp\n\t else if (k.eq.2) then\nC st = y\nc sv = z\n\t v(i,j,k) = -cosp-sint\n\t w(i,j,k) = cost*sinp\nc sint*vt = -dvdp + sint*dwdt + cost*w\nc = sinp + sint*(-sint*sinp)+cost*cost*sinp\nc = sinp + (cost**2-sint**2)*sinp\n\t vt(i,j,k) = -2.*sint*sinp\n\t else if (k.eq.3) then\nc st = x\nc sv = z\n\t v(i,j,k) = sinp - sint\n\t w(i,j,k) = cost*cosp\nc sint*vt = -cosp-sint*sint*sinp+cost*cost*cosp\nc = -cosp + (1-2.*sint**2)*cosp =\n\t vt(i,j,k) = -2.*sint*cosp\n\t end if\n\t end do\n\tend do\n end do\n\nc do kk=1,nt\nc call iout(kk,\"**kk\")\nc call aout(v(1,1,kk),\" v\",nlat,nlon)\nc call aout(w(1,1,kk),\" w\",nlat,nlon)\nc call aout(vt(1,1,kk),\" vt\",nlat,nlon)\nc end do\n\n if (icase.eq.1) then\n\n call name(\"**ec\")\nc\nc analyze vector field\nc\n call vhaeci(nlat,nlon,wsave,lsave,dwork,ldwork,ierror)\n call name(\"vhai\")\n call iout(ierror,\"ierr\")\n\n call vhaec(nlat,nlon,isym,nt,v,w,nlat,nlon,br,bi,cr,ci,mdc,\n +nlat,wsave,lsave,work,lwork,ierror)\n call name(\"vha \")\n call iout(ierror,\"ierr\")\n\nc if (nmax.lt.10) then\nc do kk=1,nt\nc call iout(kk,\"**kk\")\nc call aout(br(1,1,kk),\" br\",mdc,nlat)\nc call aout(bi(1,1,kk),\" bi\",mdc,nlat)\nc call aout(cr(1,1,kk),\" cr\",mdc,nlat)\nc call aout(ci(1,1,kk),\" ci\",mdc,nlat)\nc end do\nc end if\nc\nc compute vorticity of (v,w) in vt\nc\n\n call shseci(nlat,nlon,wsave,lsave,dwork,ldwork,ierror)\n\n call name(\"vrti\")\n call iout(ierror,\"ierr\")\n\n call vrtec(nlat,nlon,isym,nt,vt,nlat,nlon,cr,ci,mdc,nlat,\n +wsave,lsave,work,lwork,ierror)\n\n call name(\"vrt \")\n call iout(ierror,\"ierr\")\n call iout(nlat,\"nlat\")\n call iout(nlon,\"nlon\")\n\n else if (icase.eq.2) then\n\n call name(\"**es\")\n call shsesi(nlat,nlon,wsave,lsave,work,lwork,dwork,ldwork,ierror)\n\n call name(\"vrti\")\n call iout(ierror,\"ierr\")\n\n call vrtes(nlat,nlon,isym,nt,vt,nlat,nlon,cr,ci,mdc,nlat,\n +wsave,lsave,work,lwork,ierror)\n\n call name(\"vrt \")\n call iout(ierror,\"ierr\")\n\n else if (icase .eq. 3) then\n\n call name(\"**gc\")\n\n call shsgci(nlat,nlon,wsave,lsave,dwork,ldwork,ierror)\n\n call name(\"vrti\")\n call iout(ierror,\"ierr\")\n\n call vrtgc(nlat,nlon,isym,nt,vt,nlat,nlon,cr,ci,mdc,nlat,\n +wsave,lsave,work,lwork,ierror)\n\n call name(\"vrt \")\n call iout(ierror,\"ierr\")\n\n else if (icase .eq. 4) then\n\n call name(\"**gs\")\n\n call shsgsi(nlat,nlon,wsave,lsave,work,lwork,dwork,ldwork,ierror)\n\n call name(\"vrti\")\n call iout(ierror,\"ierr\")\n\n call vrtgs(nlat,nlon,isym,nt,vt,nlat,nlon,cr,ci,mdc,nlat,\n +wsave,lsave,work,lwork,ierror)\n\n call name(\"vrt \")\n call iout(ierror,\"ierr\")\n end if\n\nc if (nmax.lt.10) then\nc do kk=1,nt\nc call iout(kk,\"**kk\")\nc call aout(vt(1,1,kk),\" vt\",nlat,nlon)\nc end do\nc end if\nc\nc compute \"error\" in vt\nc\n err2 = 0.0\n do k=1,nt\n\tdo j=1,nlon\n\t phi = (j-1)*dphi\n\t sinp = sin(phi)\n\t cosp = cos(phi)\n\t do i=1,nlat\n\t theta = (i-1)*dlat\n\t if (icase.gt.2) theta=thetag(i)\n\t cost = cos(theta)\n\t sint = sin(theta)\n\t x = sint*cosp\n\t y = sint*sinp\n\t z = cost\n\t dxdt = cost*cosp\n\t d2xdt2 = -sint*cosp\n\t dxdp = -sint*sinp\n\t d2xdp2 = -sint*cosp\n\t dydt = cost*sinp\n\t d2ydt2 = -sint*sinp\n\t dydp = sint*cosp\n\t d2ydp2 = -sint*sinp\n\t dzdt = -sint\n\t d2zdt2 = -cost\n\t dzdp = 0.0\n\t d2zdp2 = 0.0\n\t if (k.eq.1) then\n\t vte = -2.0*sint*cosp\n\t else if (k.eq.2) then\n\t vte = -2.*sint*sinp\n\t else if (k.eq.3) then\n\t vte = -2.*sint*cosp\n\t end if\n\t err2 = err2 + (vt(i,j,k)-vte)**2\n\t end do\n\tend do\n end do\n err2 = sqrt(err2/(nt*nlat*nlon))\n call vout(err2,\"err2\")\nc\nc now recompute (v,w) inverting vt using ivrt(ec,es,gc,gs)\nc and compare with (ve,we) generated by synthesizing br,bi,cr,ci\nc with br=bi=0.0\nc\n\n do k=1,nt\n\tdo i=1,mdc\n\t do j=1,nlat\n\t br(i,j,k) = 0.0\n\t bi(i,j,k) = 0.0\n\t end do\n\tend do\n end do\n\n if (icase.eq.1) then\n\n call name(\"**ec\")\n\nc\nc set vector field (ve,we) with br=bi=0.0 for comparison with inverted vt\nc\n call vhseci(nlat,nlon,wsave,lsave,dwork,ldwork,ierror)\n call name(\"vhsi\")\n call iout(ierror,\"ierr\")\n\n call vhsec(nlat,nlon,ityp,nt,ve,we,nlat,nlon,br,bi,cr,ci,\n + mdc,nlat,wsave,lsave,work,lwork,ierror)\n\n call name(\"vhs \")\n call iout(ierror,\"ierr\")\n\n call shaeci(nlat,nlon,wsave,lsave,dwork,ldwork,ierror)\n call name(\"shai\")\n call iout(ierror,\"ierr\")\n\n call shaec(nlat,nlon,isym,nt,vt,nlat,nlon,a,b,\n +mdab,nlat,wsave,lsave,work,lwork,ierror)\n call name(\"sha \")\n call iout(ierror,\"ierr\")\n call iout(lsave,\"lsav\")\n call iout(lwork,\"lwrk\")\n\nc if (nmax.lt.10) then\nc do kk=1,nt\nc call iout(kk,\"**kk\")\nc call aout(a(1,1,kk),\" a\",nlat,nlat)\nc call aout(b(1,1,kk),\" b\",nlat,nlat)\nc end do\nc end if\n\n call vhseci(nlat,nlon,wsave,lsave,dwork,ldwork,ierror)\n call name(\"vhsi\")\n call iout(ierror,\"ierr\")\n\n call ivrtec(nlat,nlon,isym,nt,v,w,nlat,nlon,a,b,\n +mdab,nlat,wsave,lsave,work,lwork,pertrb,ierror)\n call name(\"ivrt\")\n call iout(ierror,\"ierr\")\n call vout(pertrb,\"prtb\")\n\n else if (icase.eq.2) then\n\n call name(\"**es\")\nc\nc set vector field (ve,we) with br=bi=0.0 for comparison with inverted vt\nc\n call vhsesi(nlat,nlon,wsave,lsave,work,lwork,dwork,ldwork,ierror)\n call name(\"vhsi\")\n call iout(ierror,\"ierr\")\n\n call vhses(nlat,nlon,ityp,nt,ve,we,nlat,nlon,br,bi,cr,ci,\n + mdc,nlat,wsave,lsave,work,lwork,ierror)\n call name(\"vhs \")\n call iout(ierror,\"ierr\")\n\n\n call shaesi(nlat,nlon,wsave,lsave,work,lwork,dwork,ldwork,ierror)\n call name(\"shai\")\n call iout(ierror,\"ierr\")\n\n call shaes(nlat,nlon,isym,nt,vt,nlat,nlon,a,b,\n +mdab,nlat,wsave,lsave,work,lwork,ierror)\n call name(\"sha \")\n call iout(ierror,\"ierr\")\n call iout(lsave,\"lsav\")\n call iout(lwork,\"lwrk\")\n\n call vhsesi(nlat,nlon,wsave,lsave,work,lwork,dwork,ldwork,ierror)\n call name(\"ivti\")\n call iout(ierror,\"ierr\")\n\n call ivrtes(nlat,nlon,isym,nt,v,w,nlat,nlon,a,b,\n +mdab,nlat,wsave,lsave,work,lwork,pertrb,ierror)\n call name(\"ivrt\")\n call iout(ierror,\"ierr\")\n call vout(pertrb,\"prtb\")\n\n else if (icase.eq.3) then\n\n call name(\"**gc\")\nc\nc set vector field (ve,we) with br=bi=0.0 for comparison with inverted vt\nc\n call vhsgci(nlat,nlon,wsave,lsave,dwork,ldwork,ierror)\n call name(\"vhsi\")\n call iout(ierror,\"ierr\")\n\n call vhsgc(nlat,nlon,ityp,nt,ve,we,nlat,nlon,br,bi,cr,ci,\n + mdc,nlat,wsave,lsave,work,lwork,ierror)\n\n call name(\"vhs \")\n call iout(ierror,\"ierr\")\n\n call shagci(nlat,nlon,wsave,lsave,dwork,ldwork,ierror)\n call name(\"shai\")\n call iout(ierror,\"ierr\")\n\n call shagc(nlat,nlon,isym,nt,vt,nlat,nlon,a,b,\n +mdab,nlat,wsave,lsave,work,lwork,ierror)\n call name(\"sha \")\n call iout(ierror,\"ierr\")\n call iout(lsave,\"lsav\")\n call iout(lwork,\"lwrk\")\n\n call vhsgci(nlat,nlon,wsave,lsave,dwork,ldwork,ierror)\n call name(\"ivti\")\n call iout(ierror,\"ierr\")\n\n call ivrtgc(nlat,nlon,isym,nt,v,w,nlat,nlon,a,b,\n +mdab,nlat,wsave,lsave,work,lwork,pertrb,ierror)\n\n call name(\"ivrt\")\n call iout(ierror,\"ierr\")\n call vout(pertrb,\"prtb\")\n\n else if (icase.eq.4) then\n\n call name(\"**gs\")\nc\nc set vector field (ve,we) with br=bi=0.0 for comparison with inverted vt\nc\n call vhsgsi(nlat,nlon,wsave,lsave,work,lwork,dwork,ldwork,ierror)\n call name(\"vhsi\")\n call iout(ierror,\"ierr\")\n\n call vhsgs(nlat,nlon,ityp,nt,ve,we,nlat,nlon,br,bi,cr,ci,\n + mdc,nlat,wsave,lsave,work,lwork,ierror)\n call name(\"vhs \")\n call iout(ierror,\"ierr\")\n\n call shagsi(nlat,nlon,wsave,lsave,work,lwork,dwork,ldwork,ierror)\n call name(\"shai\")\n call iout(ierror,\"ierr\")\n\n call shags(nlat,nlon,isym,nt,vt,nlat,nlon,a,b,\n +mdab,nlat,wsave,lsave,work,lwork,ierror)\n call name(\"sha \")\n call iout(ierror,\"ierr\")\n call iout(lsave,\"lsav\")\n call iout(lwork,\"lwrk\")\n\n call vhsgsi(nlat,nlon,wsave,lsave,work,lwork,dwork,ldwork,ierror)\n call name(\"ivti\")\n call iout(ierror,\"ierr\")\n\n call ivrtgs(nlat,nlon,isym,nt,v,w,nlat,nlon,a,b,\n +mdab,nlat,wsave,lsave,work,lwork,pertrb,ierror)\n call name(\"ivrt\")\n call iout(ierror,\"ierr\")\n call vout(pertrb,\"prtb\")\n\n end if\n\n\nc if (nmax.lt.10) then\nc do kk=1,nt\nc call iout(kk,\"**kk\")\nc call aout(v(1,1,kk),\" v\",nlat,nlon)\nc call aout(w(1,1,kk),\" w\",nlat,nlon)\nc end do\nc end if\n\nc\nc compare this v,w with ve,we\nc\n err2v = 0.0\n err2w = 0.0\n do k=1,nt\n\tdo j=1,nlon\n\t do i=1,nlat\n\t err2v = err2v + (v(i,j,k)-ve(i,j,k))**2\n\t err2w = err2w + (w(i,j,k)-we(i,j,k))**2\n\t end do\n\tend do\n end do\n err2v = sqrt(err2v/(nlat*nlon*nt))\n err2w = sqrt(err2w/(nlat*nlon*nt))\n call vout(err2v,\"errv\")\n call vout(err2w,\"errw\")\nc\nc end of icase loop\nc\n end do\n end\nc\n subroutine iout(ivar,nam)\n real nam\n write(6,10) nam , ivar\n 10 format(1h a4, 3h = ,i8)\n return\n end\nc\n subroutine vout(var,nam)\n real nam\n write(6,10) nam , var\n 10 format(1h a4,3h = ,e12.5)\n return\n end\nc\n subroutine name(nam)\n real nam\n write(6,100) nam\n 100 format(1h a8)\n return\n end\nc\n subroutine vecout(vec,nam,len)\n dimension vec(len)\n real nam\n write(6,109) nam, (vec(l),l=1,len)\n 109 format(1h a4,/(1h 8e11.4))\n return\n end\n", "meta": {"hexsha": "e988cd617b5744ba51226c26fb500b3fba787d79", "size": 14967, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "install/spherepack3.2/test/tvrt.f", "max_stars_repo_name": "comp-physics/RBC3D", "max_stars_repo_head_hexsha": "2891a1e3b356e2cff0cfa74ba26d4aef3336641d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "install/spherepack3.2/test/tvrt.f", "max_issues_repo_name": "comp-physics/RBC3D", "max_issues_repo_head_hexsha": "2891a1e3b356e2cff0cfa74ba26d4aef3336641d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "install/spherepack3.2/test/tvrt.f", "max_forks_repo_name": "comp-physics/RBC3D", "max_forks_repo_head_hexsha": "2891a1e3b356e2cff0cfa74ba26d4aef3336641d", "max_forks_repo_licenses": ["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.4623853211, "max_line_length": 77, "alphanum_fraction": 0.5204783858, "num_tokens": 5126, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473813156295, "lm_q2_score": 0.7549149978955811, "lm_q1q2_score": 0.6585481215301041}} {"text": "subroutine rroot (n, r0, a, nr, r)\n\n! Finds a single arbitrary-precision real root, beginning at r0.\n! Modified for the toolkit.\n! David H Bailey 2004-05-27\n\nuse mpmodule\nuse globdata\nimplicit none\ninteger i, j, k, n, nit, nr, nwp\nparameter (nit = 100)\ntype (mp_real) a(0:n), ad(0:n-1), eps1\ntype (mp_real) t1, t2, t3, t4, r, r0\n\n! Compute derivative.\n\ndo i = 0, n - 1\n ad(i) = (i + 1) * a(i+1)\nenddo\n\nnwp = 3\ncall mpsetprecwords (nwp)\nt1 = r0\nt2 = 0.d0\nif (r0 /= t2) then\n eps1 = 2.d0 ** (-96) * abs (t1)\nelse\n eps1 = 2.d0 ** (-96)\nendif\n\n! Perform up to nit double-precision Newton iterations.\n\ndo j = 1, nit\n\n! Evaluate polynomial at t1.\n\n t2 = 0.d0\n\n do i = n, 0, -1\n t2 = t1 * t2 + a(i)\n enddo\n\n! Evaluate polynomial derivative at t1.\n\n t3 = 0.d0\n\n do i = n - 1, 0, -1\n t3 = t1 * t3 + ad(i)\n enddo\n\n t4 = t1 - t2 / t3\n if (nwp == 3) then\n if (abs (t1 - t4) < eps1) then\n nwp = min (2 * nwp - 1, nwords1)\n call mpsetprecwords (nwp)\n endif\n elseif (nwp < nwords1) then\n nwp = min (2 * nwp - 1, nwords1)\n call mpsetprecwords (nwp)\n else\n t1 = t4\n goto 100\n endif\n t1 = t4\nenddo\n\nwrite (6, 1)\n1 format ('rroot: failed to find arbitrary precision real root.')\nnr = 0\nr = 0.d0\ngoto 110\n\n100 continue\n\nnr = 1\nr = t1\n\n110 continue\n\ncall mpsetprecwords (nwords1)\nreturn\nend\n\nsubroutine croot (n, r0, a, nr, r)\n\n! Finds a single arbitrary-precision complex root, beginning at r0.\n\nuse mpmodule\nuse globdata\nimplicit none\ninteger i, j, k, n, nit, nr, nwp\nparameter (nit = 100)\ntype (mp_real) a(0:n), ad(0:n-1), eps1\ntype(mp_complex) t1, t2, t3, t4, r, r0\n\n! Compute derivative.\n\ndo i = 0, n - 1\n ad(i) = (i + 1) * a(i+1)\nenddo\n\nnwp = 3\ncall mpsetprecwords (nwp)\nt1 = r0\nt2 = (0.d0, 0.d0)\nif (r0 /= t2) then\n eps1 = 2.d0 ** (-96) * abs (t1)\nelse\n eps1 = 2.d0 ** (-96)\nendif\n\n! Perform up to nit double-precision Newton iterations.\n\ndo j = 1, nit\n\n! Evaluate polynomial at t1.\n\n t2 = (0.d0, 0.d0)\n\n do i = n, 0, -1\n t2 = t1 * t2 + a(i)\n enddo\n\n! Evaluate polynomial derivative at t1.\n\n t3 = (0.d0, 0.d0)\n\n do i = n - 1, 0, -1\n t3 = t1 * t3 + ad(i)\n enddo\n\n t4 = t1 - t2 / t3\n if (nwp == 3) then\n if (abs (t1 - t4) < eps1) then\n nwp = min (2 * nwp - 1, nwords1)\n call mpsetprecwords (nwp)\n endif\n elseif (nwp < nwords1) then\n nwp = min (2 * nwp - 1, nwords1)\n call mpsetprecwords (nwp)\n else\n t1 = t4\n goto 100\n endif\n t1 = t4\nenddo\n\nwrite (6, 1)\n1 format ('croot: failed to find multiple precision complex root.')\nnr = 0\nr = (0.d0, 0.d0)\ngoto 110\n\n100 continue\n\nnr = 1\nr = t1\n\n110 continue\n\ncall mpsetprecwords (nwords1)\nreturn\nend\n\n\n", "meta": {"hexsha": "e9af7ff02ae647532e49399fa89e3d93f325f297", "size": 2650, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "MPFUN90/mpfun90/toolkit/rootsub.f90", "max_stars_repo_name": "paveloom-p/P3", "max_stars_repo_head_hexsha": "57df3b6263db81685f137a7ed9428dbd3c1b4a5b", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MPFUN90/mpfun90/toolkit/rootsub.f90", "max_issues_repo_name": "paveloom-p/P3", "max_issues_repo_head_hexsha": "57df3b6263db81685f137a7ed9428dbd3c1b4a5b", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MPFUN90/mpfun90/toolkit/rootsub.f90", "max_forks_repo_name": "paveloom-p/P3", "max_forks_repo_head_hexsha": "57df3b6263db81685f137a7ed9428dbd3c1b4a5b", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.9638554217, "max_line_length": 69, "alphanum_fraction": 0.5920754717, "num_tokens": 1120, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.754914997895581, "lm_q1q2_score": 0.658548116519416}} {"text": " program main\n use debugging\n use matrices\n \n implicit none\n integer :: NN, dmn, N_max,N_min,ii,jj\n integer, allocatable :: seed(:)\n double precision :: start, finish, f, s\n double complex, allocatable :: matrix(:,:), O(:), Odag(:)\n\n\n\n ! Seeding\n call random_seed(size=NN)\n allocate(seed(NN))\n seed = 10\n call random_seed(put=seed)\n\n ! Parameters\n print *, \"Insert N_max:\"\n read *, N_max\n print *, \"Insert N_min:\"\n read *, N_min\n\n if(N_min>N_max) then\n print *, \"Error: Invalid limits.\"\n stop\n end if\n \n\n \n\n ! Open diagonalization file\n open(10,file=\"data/diagonalization.txt\", status=\"unknown\", access=\"append\")\n\n \n \n\n call cpu_time(s)\n\n do dmn=N_min,N_max\n allocate(matrix(dmn,dmn))\n allocate(O(dmn))\n allocate(Odag(dmn))\n O = complex(1d0,2d0)\n Odag = conjg(O)\n do ii=1,dmn\n do jj=1,dmn\n matrix(ii,jj) = Odag(ii)*O(jj)\n if(ii.eq.jj) then\n matrix(ii,ii) = matrix(ii,ii) +0.0001\n endif\n \n enddo\n enddo\n \n call cpu_time(start)\n call inv_herm(matrix)\n call cpu_time(finish)\n write(10,*) dmn, finish-start\n deallocate(matrix, O,Odag)\n\n enddo\n\n call cpu_time(f)\n\n close(10)\n\n print *, \"Total computation time (s):\", f-s\n\n \n \n end program main\n \n \n \n \n\n \n", "meta": {"hexsha": "39c978505a365ba3f4ff14aed9941c8a6bb1305d", "size": 1554, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/diagonalization.f90", "max_stars_repo_name": "lupoalberto98/QRBM", "max_stars_repo_head_hexsha": "8662124077370866aeb2c3d60673c1882d307299", "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/fortran/diagonalization.f90", "max_issues_repo_name": "lupoalberto98/QRBM", "max_issues_repo_head_hexsha": "8662124077370866aeb2c3d60673c1882d307299", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/fortran/diagonalization.f90", "max_forks_repo_name": "lupoalberto98/QRBM", "max_forks_repo_head_hexsha": "8662124077370866aeb2c3d60673c1882d307299", "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": 19.425, "max_line_length": 81, "alphanum_fraction": 0.490990991, "num_tokens": 400, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.7549149923816046, "lm_q1q2_score": 0.6585481117093132}} {"text": "subroutine para3d(X, n, m, l, ndim, S, u, v, w)\n !***DESCRIPTION\n !\n ! Written by Gaetan Kenway\n !\n ! Abstract para3d calculates the parametric locations for a 3d block\n !\n ! Description of Arguments\n\n ! Input\n ! X - Real, size(ndim, l, m, n): Coordiantes\n\n ! Output\n ! S - Real, size(ndim, l, m, n): The u, v, w parametric positions\n ! u - Real, size(n): The averaged u parameters\n ! v - Real, size(m): The averaged v parameters\n ! w - Real, size(l): The averaged w parameters\n\n use precision\n implicit none\n\n ! Input\n integer , intent(in) :: n, m, l, ndim\n real(kind=realType) , intent(in) :: X(ndim, l, m, n)\n \n\n ! Output\n real(kind=realType) , intent(out) :: S(ndim, l, m, n)\n real(kind=realType) , intent(out) :: u(n), v(m), w(l)\n\n ! Working \n integer :: i, j, k\n\n real(kind=realType) DELI, DELJ, DELK\n\n DELI(K, J, I) = SQRT ((X(1, K, J, I) - X(1, K, J, I-1)) ** 2 + &\n (X(2, K, J, I) - X(2, K, J, I-1)) ** 2 + &\n (X(3, K, J, I) - X(3, K, J, I-1)) ** 2)\n\n DELJ(K, J, I) = SQRT ((X(1, K, J, I) - X(1, K, J-1, I)) ** 2 + &\n (X(2, K, J, I) - X(2, K, J-1, I)) ** 2 + &\n (X(3, K, J, I) - X(3, K, J-1, I)) ** 2)\n\n DELK(K, J, I) = SQRT ((X(1, K, J, I) - X(1, K-1, J, I)) ** 2 + &\n (X(2, K, J, I) - X(2, K-1, J, I)) ** 2 + &\n (X(3, K, J, I) - X(3, K-1, J, I)) ** 2)\n\n \n u(:) = 0.0\n v(:) = 0.0\n w(:) = 0.0\n\n ! Zero the three low-end faces (or edges if one plane is specified).\n\n S(1, :, :, 1) = 0.0\n S(2, :, 1, :) = 0.0\n S(3, 1, :, :) = 0.0\n\n ! Set up the low-end edge lines because they are missed by the\n ! following loops over most of the low-end faces:\n\n DO I=2, n\n S(1, 1, 1, I) = S(1, 1, 1, I-1) + DELI(1, 1, I)\n END DO\n\n DO J=2, m\n S(2, 1, J, 1) = S(2, 1, J-1, 1) + DELJ(1, J, 1)\n END DO\n\n DO K=2, l\n S(3, K, 1, 1) = S(3, k-1, 1, 1) + DELK(K, 1, 1)\n END DO\n\n ! Set up the rest of the low-end face lines because they are\n ! missed by the the main loop over most of the volume.\n\n DO K=2, l\n DO J=2, m\n S(2, K, J, 1) = S(2, K, J-1, 1) + DELJ(K, J, 1)\n S(3, K, J, 1) = S(3, K-1, J, 1) + DELK(K, J, 1)\n END DO\n end DO\n\n DO I=2, n\n DO K=2, l\n S(1, K, 1, I) = S(1, K , 1, I-1) + DELI(K, 1, I)\n S(3, K, 1, I) = S(3, K-1, 1, I ) + DELK(K, 1, I)\n END DO\n\n END DO\n\n DO I=2, n\n DO J=2, m\n S(1, 1, J, I) = S(1, 1, J, I-1) + DELI(1, J, I)\n S(2, 1, J, I) = S(2, 1, J-1, I) + DELJ(1, J, I)\n END DO\n END DO\n\n ! Traverse the block just once for all lines except those within\n ! the low-end faces.\n\n DO I=2, n\n DO J=2, m\n DO K=2, l\n S(1, K, J, I) = S(1, K, J, I-1) + DELI(K, J, I)\n S(2, K, J, I) = S(2, K, J-1, I) + DELJ(K, J, I)\n S(3, K, J, I) = S(3, K-1, J, I) + DELK(K, J, I)\n END DO\n END DO\n END DO\n\n ! Normalizing requires another pass through the volume.\n ! Handle lines of zero length first by inserting uniform\n ! distributions. Then the standard normalization can be\n ! applied safely everywhere.\n\n DO J=1, m\n ! Zero-length lines in the I direction?\n\n DO K=1, l\n IF (S(1, K, J, n) == 0.0) THEN\n DO I=2, n\n S(1, K, J, I) = I-1\n END DO\n END IF\n END DO\n end DO\n\n ! Zero-length lines in the J direction?\n DO I=1, n\n DO K=1, l\n IF (S(2, K, m, I) == 0.0) THEN\n DO J=2, m\n S(2, K, J, I) = J-1\n END DO\n END IF\n END DO\n END DO\n\n ! Zero-length lines in the K direction?\n\n DO I=1, n\n DO J=1, m\n IF (S(3, l, J, I) == 0.0) THEN\n DO K=2, l\n S(3, K, J, I) = K-1\n END DO\n END IF\n END DO\n END DO\n\n ! Normalize:\n\n DO I=1, n\n DO J=1, m\n DO K=1, l\n S(1, K, J, I) = S(1, K, J, I) / S(1, K, J, N)\n S(2, K, J, I) = S(2, K, J, I) / S(2, K, M, I)\n S(3, K, J, I) = S(3, K, J, I) / S(3, L, J, I)\n END DO\n END DO\n END DO\n\n ! Finally, precise 1s for the three high-end faces:\n \n DO J=1, m\n DO K=1, l\n S(1, K, J, n) = 1.0\n END DO\n end DO\n\n DO I=1, n\n DO K=1, l\n S(2, K, M, I) = 1.0\n END DO\n END DO\n \n DO I=1, n\n DO J=1, m\n S(3, L, J, I) = 1.0\n END DO\n END DO\n\n ! Now get an average u, v, w\n\n ! Average u\n\n do j=1, m\n do k=1, l\n u = u + S(1, k, j, :)\n end do\n end do\n u = u/(l*m)\n\n ! Average v\n do i=1, n\n do k=1, l\n v = v + S(2, k, :, i)\n end do\n end do\n v = v/(n*l)\n\n ! Average w\n do i=1, n\n do j=1, m\n w = w + S(3, :, j, i)\n end do\n end do\n w = w/(n*m)\n\nend subroutine para3d\n\n", "meta": {"hexsha": "bb2e84f41169a144e416aee328bfedacd8c79b8e", "size": 4886, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/parameterizations.f90", "max_stars_repo_name": "eirikurj/pyspline", "max_stars_repo_head_hexsha": "91dd6d432deac3b1647508bf4fca985e704da77c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2019-04-18T00:49:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-20T14:40:08.000Z", "max_issues_repo_path": "src/parameterizations.f90", "max_issues_repo_name": "eirikurj/pyspline", "max_issues_repo_head_hexsha": "91dd6d432deac3b1647508bf4fca985e704da77c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 23, "max_issues_repo_issues_event_min_datetime": "2019-10-17T20:39:11.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T15:27:42.000Z", "max_forks_repo_path": "src/parameterizations.f90", "max_forks_repo_name": "eirikurj/pyspline", "max_forks_repo_head_hexsha": "91dd6d432deac3b1647508bf4fca985e704da77c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2019-05-29T16:56:15.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-08T13:51:24.000Z", "avg_line_length": 22.9389671362, "max_line_length": 77, "alphanum_fraction": 0.4244781007, "num_tokens": 2133, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473779969194, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6585481045944515}} {"text": "module STATE_INIT\n\nimplicit none\n! The initializations are always carried out in QUAD as to prevent rare problems\n! which could arise due to catastrophic cancellation.\ninteger,parameter :: ik = selected_int_kind(9)\ninteger,parameter :: dk = selected_real_kind(33)\ninteger,parameter :: qk = selected_real_kind(33)\n\ncontains\n\nsubroutine DINIT_KS(R0_d,V0_d,t0_d,mu,DU,TU,u0,Vpot_d)\n! Description:\n! Starting from dimensional Cartesian coordinates and time, initializes the extended state\n! vector of the Kustaanheimo-Stiefel formulation (from now on \"KS\"). We try to follow the\n! naming convention used in \"Stiefel E. L., Scheifele G. - Linear and Regular Celestial\n! Mechanics, 1974\".\n!\n! ==============================================================================================\n!\n! PREAMBLE\n!\n! ==============================================================================================\n\n! VARIABLES\nimplicit none\n! Arguments\nreal(dk),intent(in) :: R0_d(1:3),V0_d(1:3) ! Dimensional position and velocity [km,km/s]\nreal(dk),intent(in) :: t0_d ! Dimensional time [s]\nreal(qk),intent(in) :: mu ! Grav parameter of the main body [km^3/s^2]\nreal(qk),intent(in) :: DU,TU ! Ref. quantities for ND [km,1/s]\nreal(dk),intent(in) :: Vpot_d ! Dimensional potential [km^2/s^2]\nreal(dk),intent(out) :: u0(:) ! Extended KS state vector\n\n! Locals\n! -- State vectors and associated quantities\nreal(dk) :: x0(1:4) ! Radius vector in R^4, ND\nreal(dk) :: xdot0(1:4) ! Velocity vector in R^4, ND\nreal(dk) :: t0 ! Initial time, ND\nreal(dk) :: r ! Radius magnitude, ND\n! -- Energies and potentials\nreal(dk) :: h ! Total energy, ND\nreal(dk) :: Ksq ! Grav parameter of the main body, ND\nreal(dk) :: Kin ! Kinetic energy, ND\nreal(dk) :: Vpot ! Perturbing potential, ND\n\n! ==============================================================================================\n\n! STATE VECTOR DICTIONARY\n! u(1:4) u1,...,u4; KS-position, in R^4\n! u(5:8) u1',...,u4'; KS-velocity, in R^4\n! u(9) h; (-total energy) = (-Keplerian energy) + (-potential)\n! u(10) t; non-dimensional physical time\n\n! ==============================================================================================\n! 01. INITIALIZE POSITION AND VELOCITY IN R^4, NON-DIMENSIONALIZATIONS\n! ==============================================================================================\n\nx0(1:3) = R0_d/DU\nx0(4) = 0._dk\nr = sqrt(dot_product(x0,x0))\nt0 = t0_d*TU\n\nxdot0(1:3) = V0_d/(DU*TU)\nxdot0(4) = 0._dk\n\n! Also, non-dimensionalize potential and grav parameter\nVpot = Vpot_d/(DU*TU)**2_ik\nKsq = mu/(DU**3_ik*TU**2_ik)\n\n! ==============================================================================================\n! 02. INITIALIZE KS-POSITION AND KS-VELOCITY (state vector u)\n! ==============================================================================================\n\n! KS-POSITION\nif ( x0(1) >= 0.) then\n u0(1) = 0._dk\n u0(4) = sqrt(.5_dk*(r + x0(1)) - u0(1)**2_ik)\n u0(2) = (x0(2)*u0(1) + x0(3)*u0(4))/(r + x0(1))\n u0(3) = (x0(3)*u0(1) - x0(2)*u0(4))/(r + x0(1))\nelse\n u0(2) = 0._dk\n u0(3) = sqrt(.5_dk*(r - x0(1)) - u0(2)**2_ik)\n u0(1) = (x0(2)*u0(2) + x0(3)*u0(3))/(r - x0(1))\n u0(4) = (x0(3)*u0(2) - x0(2)*u0(3))/(r - x0(1))\nend if\n\n! KS-VELOCITY\nu0(5) = .5_dk*dot_product(u0(1:3),xdot0(1:3))\nu0(6) = .5_dk*dot_product([-u0(2),u0(1),u0(4)],xdot0(1:3))\nu0(7) = .5_dk*dot_product([-u0(3),-u0(4),u0(1)],xdot0(1:3))\nu0(8) = .5_dk*dot_product([u0(4),-u0(3),u0(2)],xdot0(1:3))\n\n! Total energy\nKin = .5_dk*dot_product(xdot0,xdot0)\nh = Ksq/r - Kin - Vpot\nu0(9) = h\n\n! Initial time\nu0(10) = t0\n\nend subroutine DINIT_KS\n\nfunction DFTIME_2D(R,V,mu)\n! Computes the initial value of the fictitious time as the eccentric\n! anomaly (for elliptic orbits) or Gudermannian anomaly (for hyperbolic orbits)\n! for the K-S formulation.\n! Only works for 2D.\n\n! VARIABLES\nimplicit none\n! Inputs\nreal(qk) :: R(1:3),V(1:3),mu\n! Function definition\nreal(dk) :: DFTIME_2D\n! Locals\nreal(dk) :: vsq,rv\nreal(dk) :: rN\nreal(dk) :: e_vec(1:3),ecc\nreal(dk) :: lon_per\nreal(dk) :: R_ep(1:2)\nreal(dk) :: f0\n\n! ==============================================================================\n\n! Compute eccentricity and eccentricity vector\nvsq = dot_product(V,V)\nrv = dot_product(R,V)\nrN = sqrt(dot_product(R,R))\ne_vec = ((vsq - mu/rN)*R - rv*V)/mu\necc = sqrt(dot_product(e_vec,e_vec))\n\n! Compute true anomaly\nlon_per = atan2(e_vec(2),e_vec(1))\nR_ep = [R(1)*cos(lon_per) + R(2)*sin(lon_per),&\n-R(1)*sin(lon_per) + R(2)*cos(lon_per)]/rN\nf0 = atan2(R_ep(2),R_ep(1))\n\n! Compute fictitious time\nif (ecc <= 1._dk) then\n ! s0 = Eccentric anomaly\n DFTIME_2D = atan2(sqrt(1._dk - ecc**2)*sin(f0),(ecc + cos(f0)))\nelse\n ! s0 = Gudermannian anomaly\n DFTIME_2D = 2._dk*atan(sqrt((ecc-1._dk)/(ecc+1._dk))*tan(.5_dk*f0))\nend if\n\nend function DFTIME_2D\n\nfunction DHYPAN(R,V)\n! Computes hyperbolic anomaly from DIMENSIONLESS R,V; where the reference\n! quantities are \"DU\" for the length and \"TU = sqrt(DU**3/mu)\" for time.\nreal(qk) :: R(1:3), V(1:3)\nreal(qk) :: vsq,rmag,En,rv\nreal(dk) :: DHYPAN\n\nvsq = dot_product(V,V)\nrmag = sqrt(dot_product(R,R))\nEn = .5_qk*vsq - 1._qk/rmag\nrv = dot_product(R,V)\nDHYPAN = atanh((sqrt(2._qk*En)*rv)/(1._qk + 2._qk*En*rmag))\n\nend function DHYPAN\n\nsubroutine DINIT_EDROMO(R0,V0,t0,DU,TU,z0,phi0,W_d,flag_time)\n! Description:\n! Initializes the state vector for the EDromo formulation, starting from Cartesian\n! coordinates.\n!\n! Author:\n! Davide Amato\n! Space Dynamics Group\n! Technical University of Madrid\n! d.amato@upm.es\n! Last revision: 05-09-2015\n! ==============================================================================================\n!\n! PREAMBLE\n!\n! ==============================================================================================\n \n! VARIABLES\nimplicit none\n\n! Arguments\ninteger(ik),parameter :: neq = 8\t\t ! Number of elements of EDromo state vector\nreal(dk),intent(in) :: R0(1:3),V0(1:3)\t\t! Dimensional position and velocity [km,km/s]\nreal(qk),intent(in) :: DU,TU ! Ref. quantities for non-dimensionalization\nreal(dk),intent(in) :: phi0 ! Initial phi value\nreal(dk),intent(in) :: t0 \t! Initial time value [s]\nreal(dk),intent(in) :: W_d ! Potential [km^2/s^2]\ninteger(ik),intent(in) :: flag_time\t\t ! = 0 physical time\n \t\t\t\t\t\t\t\t ! = 1 constant time element\n\t\t\t\t\t\t\t\t ! = 2 linear time element \nreal(dk),intent(out) :: z0(1:neq) ! EDromo state vector\n\n! Local variables\nreal(dk) :: y(1:6) \t\t ! Cartesian state vector, ND\nreal(dk) :: r0mag,v0mag \t ! Radius and velocity magnitudes, ND\nreal(dk) :: rv0 ! r dot v, ND\nreal(dk) :: h0(1:3),hmag0 \t ! Initial angular momentum and magnitude\nreal(dk) :: pot0 \t\t ! Potential, ND\nreal(dk) :: totEn0 \t\t ! Initial total energy, ND\nreal(dk) :: c0 ! Generalized angular momentum\nreal(dk) :: cph,sph\nreal(dk) :: nu0,cnu,snu \t ! Auxiliary variables\nreal(dk) :: i_vec(1:3),j_vec(1:3),k_vec(1:3) ! Orbital frame unit vectors in inertial RF\nreal(dk) :: x_vec(1:3),y_vec(1:3) ! Intermediate frame unit vectors in inertial RF\nreal(dk) :: aux \t ! Auxiliary variables\nreal(dk) :: zero \t\t ! Reference machine zero\n\n! ==============================================================================================\n!\n! EXECUTION\n!\n! ==============================================================================================\n\n! ==============================================================================================\n! 01. NON-DIMENSIONALIZATION\n! ==============================================================================================\ny(1:3) = R0/DU\ny(4:6) = V0/(DU*TU)\npot0 = W_d/(DU*TU)**2_ik\n\n! Compute machine zero for comparisons\nzero = 10._dk*epsilon(0._dk)\n\n! ==============================================================================================\n! 02. IN-PLANE ELEMENTS\n! ==============================================================================================\nr0mag = sqrt(dot_product(y(1:3),y(1:3)))\nv0mag = sqrt(dot_product(y(4:6),y(4:6)))\n\ncph = cos(phi0)\nsph = sin(phi0)\n\n! Total energy\ntotEn0 = .5_dk*v0mag**2_ik - 1._dk/r0mag + pot0\n\n! Angular momentum\nh0 = DCROSS_PRODUCT(y(1:3),y(4:6))\nhmag0 = sqrt(dot_product(h0,h0))\n\n! Generalized angular momentum\nc0 = sqrt(hmag0**2_ik + 2._dk*r0mag**2_ik*pot0)\n\n! Dot product\nrv0 = dot_product(y(1:3),y(4:6))\n\n! IN-PLANE ELEMENTS\nz0(1) = (1._dk + 2._dk*totEn0*r0mag)*cph + rv0*sqrt(-2._dk*totEn0)*sph\nz0(2) = (1._dk + 2._dk*totEn0*r0mag)*sph - rv0*sqrt(-2._dk*totEn0)*cph\nz0(3) = -1._dk/(2._dk*totEn0)\n\n! ==============================================================================================\n! 03. QUATERNION ELEMENTS\n! ==============================================================================================\n\nnu0 = phi0 + 2._dk*atan2(rv0,(c0 + r0mag*sqrt(-2._dk*totEn0)))\ncnu = cos(nu0); snu = sin(nu0)\n\n! Orbital frame unit vectors in IRF\ni_vec = y(1:3)/r0mag\nk_vec = h0/hmag0\nj_vec = DCROSS_PRODUCT(k_vec,i_vec)\n\n! Intermediate frame unit vectors in IRF\nx_vec = i_vec*cnu - j_vec*snu\ny_vec = j_vec*cnu + i_vec*snu\n\n! SAFE INITIALIZATION OF THE QUATERNION\n! The arguments of the roots have to be always positive, therefore we can safely use ABS()\naux = abs(1._dk + x_vec(1) + y_vec(2) + k_vec(3))\nz0(7) = .5_dk*sqrt(aux)\n! Check for singularities and NaNs\nif ( aux <= zero ) then\n aux = abs((.5_dk*(k_vec(3) + 1._dk)))\n z0(6) = sqrt(aux)\n if ( aux <= zero ) then\n aux = abs(.5_dk*(1._dk - y_vec(2)))\n z0(4) = sqrt(aux)\n if ( aux <= zero ) then\n z0(5) = 1._dk\n else\n z0(5) = y_vec(1)/(2._dk*z0(4))\n end if \n else\n z0(4) = k_vec(1)/(2._dk*z0(6))\n z0(5) = k_vec(2)/(2._dk*z0(6))\n end if\nelse\n z0(4) = (y_vec(3) - k_vec(2))/(4._dk*z0(7))\n z0(5) = (k_vec(1) - x_vec(3))/(4._dk*z0(7))\n z0(6) = (x_vec(2) - y_vec(1))/(4._dk*z0(7))\nend if\n\n! ==============================================================================\n! 04. TIME / TIME ELEMENT\n! ==============================================================================\n\nif ( flag_time == 0_ik ) then\n ! Physical time\n z0(8) = t0*TU\nelseif ( flag_time == 1_ik ) then\n ! Constant time element\n z0(8) = t0*TU + z0(3)**1.5_dk*(z0(1)*sph - z0(2)*cph - phi0)\nelseif ( flag_time == 2_ik ) then\n ! Linear time element\n z0(8) = t0*TU + z0(3)**1.5_dk*(z0(1)*sph - z0(2)*cph)\nend if\n\nend subroutine DINIT_EDROMO\n\nsubroutine DINIT_GDROMO(R0,V0,t0,DU,TU,z0,phi0,W_d,flag_time)\n! Description:\n! Initializes the state vector for the EDromo formulation, starting from Cartesian\n! coordinates.\n!\n! Author:\n! Davide Amato\n! Space Dynamics Group\n! Technical University of Madrid\n! d.amato@upm.es\n! Last revision: 05-09-2015\n! ==============================================================================================\n!\n! PREAMBLE\n!\n! ==============================================================================================\n \n! VARIABLES\n\nimplicit none\n\n! Arguments\ninteger(ik),parameter :: neq = 8\t\t ! Number of elements of HDromo state vector\nreal(dk),intent(in) :: R0(1:3),V0(1:3)\t\t! Dimensional position and velocity [km,km/s]\nreal(qk),intent(in) :: DU,TU ! Ref. quantities for non-dimensionalization\nreal(dk),intent(in) :: phi0 ! Initial phi value\nreal(dk),intent(in) :: t0 \t! Initial time value [s]\nreal(dk),intent(in) :: W_d ! Potential [km^2/s^2]\ninteger(ik),intent(in) :: flag_time\t\t ! = 0 physical time\n \t\t\t\t\t\t\t\t ! = 1 constant time element\n\t\t\t\t\t\t\t\t ! = 2 linear time element \nreal(dk),intent(out) :: z0(:) ! HDromo state vector\n\n! Local variables\nreal(dk) :: y(1:6) \t\t ! Cartesian state vector, ND\nreal(dk) :: r0mag,v0mag \t ! Radius and velocity magnitudes, ND\nreal(dk) :: h0(1:3),hmag0 \t ! Initial angular momentum and magnitude\nreal(dk) :: uu0,u0,lam0,s0 \t ! Initial radial and tangential velocities\nreal(dk) :: pot0 \t\t ! Potential, ND\nreal(dk) :: totEn0 \t\t ! Initial total energy, ND\nreal(dk) :: hg0,ecg0 ! Generalized angular momentum and eccentricity\nreal(dk) :: cnu_0,snu_0 \t ! Auxiliary variables\nreal(dk) :: zeta,gamma \t ! Auxiliary variables\nreal(dk) :: aux,aux1,aux2 \t ! Auxiliary variables\nreal(dk) :: zero \t\t ! Reference machine zero\nreal(dk) :: xO_0(1:3),yO_0(1:3),zO_0(1:3) ! Unit vectors of the LVLH reference frame (orbital frame)\nreal(dk) :: xI_0(1:3),yI_0(1:3)\t\t\t\t! Unit vectors of the intermediate reference frame\n\n! ==============================================================================================\n!\n! EXECUTION\n!\n! ==============================================================================================\n\n! ==============================================================================================\n! 01. NON-DIMENSIONALIZATION\n! ==============================================================================================\ny(1:3) = R0/DU\ny(4:6) = V0/(DU*TU)\npot0 = W_d/(DU*TU)**2_ik\n\n! Compute machine zero for comparison\nzero = 10._dk*epsilon(0._dk)\n\n! ==============================================================================================\n! 02. CONVERSION TO HDROMO ELEMENTS\n! ==============================================================================================\n\nr0mag = sqrt(dot_product(y(1:3),y(1:3)))\nv0mag = sqrt(dot_product(y(4:6),y(4:6)))\n\n! Radial velocity\nuu0 = dot_product(y(1:3),y(4:6))\nu0 = uu0/r0mag\n! Angular momentum\nh0 = DCROSS_PRODUCT(y(1:3),y(4:6))\nhmag0 = sqrt(dot_product(h0,h0))\n! Tangential velocity\nlam0 = hmag0/r0mag\n \n! Generalized transverse velocity\ns0 = sqrt(lam0**2_ik + 2._dk*pot0)\n \n! Total energy\ntotEn0 = v0mag**2_ik/2._dk - 1._dk/r0mag + pot0\n\nz0(1) = (1._dk + 2._dk*totEn0*r0mag)*cosh(phi0) - uu0*sqrt(2._dk*totEn0)*sinh(phi0)\nz0(2) = -(1._dk + 2._dk*totEn0*r0mag)*sinh(phi0) + uu0*sqrt(2._dk*totEn0)*cosh(phi0)\nz0(3) = 1._dk/(2._dk*totEn0)\n \n! Generalized angular momentum\nhg0 = r0mag*s0\n\n! Generalized eccentricity\necg0 = sqrt(z0(1)**2_ik - z0(2)**2_ik)\n \n! SAFE INITIALIZATION OF THE QUATERNION\n! Auxiliary variables \nzeta = z0(1)*sinh(phi0) + z0(2)*cosh(phi0)\ngamma = sqrt(z0(1)**2_ik + z0(2)**2_ik)\naux1 = u0*hg0/(ecg0*gamma)\naux2 = (hg0**2_ik/r0mag - 1._dk)/(ecg0*gamma)\n \n! Cosine and sine of the angle of rotation nu between the LVLH and the intermediate frames\ncnu_0 = z0(1)*aux2 - z0(2)*aux1\nsnu_0 = z0(1)*aux1 + z0(2)*aux2\n \n! x-y-z unit vectors of the LVLH reference frame (orbital frame)\nxO_0 = y(1:3)/r0mag\nzO_0 = h0/hmag0\nyO_0 = DCROSS_PRODUCT(zO_0,xO_0)\n! x-y-z unit vectors of the intermediate reference frame\nxI_0 = xO_0*cnu_0 - yO_0*snu_0\nyI_0 = xO_0*snu_0 + yO_0*cnu_0\n! zI_0 = zO_0\n \n! The arguments of the roots have to be always positive, therefore we can safely use ABS()\naux = abs(1._dk + xI_0(1) + yI_0(2) + zO_0(3))\nz0(7) = .5_dk*sqrt(aux)\n! Check for singularities and nans\nif ( aux <= zero ) then\n aux = abs((.5_dk*(zO_0(3) + 1._dk)))\n z0(6) = sqrt(aux)\n if ( aux <= zero ) then\n aux = abs((.5_dk*(1._dk-yI_0(2))))\n z0(4) = SQRT(aux)\n if ( aux <= zero ) then\n z0(5) = 1._dk\n else\n z0(5) = 1._dk/(2._dk*z0(4)) * yI_0(1)\n end if \n else\n z0(4) = 1._dk/(2._dk*z0(6)) * zO_0(1)\n z0(5) = 1._dk/(2._dk*z0(6)) * zO_0(2)\n end if\nelse\n z0(4) = 1._dk/(4._dk*z0(7))*( yI_0(3) - zO_0(2) )\n z0(5) = 1._dk/(4._dk*z0(7))*( zO_0(1) - xI_0(3) )\n z0(6) = 1._dk/(4._dk*z0(7))*( xI_0(2) - yI_0(1) )\nend if\n\n! Time/Time Element \nif ( flag_time == 0_ik ) then\n\t! Physical time\t\n z0(8) = t0*TU\nelseif ( flag_time == 1_ik ) then\n ! Constant time element\n z0(8) = t0*TU - z0(3)**1.5_dk*(zeta - phi0)\nelseif ( flag_time == 2 ) then\n ! Linear time element\n z0(8) = t0*TU - z0(3)**1.5_dk*zeta\nend if\n\nend subroutine DINIT_GDROMO\n\n\nfunction DCROSS_PRODUCT(a,b)\n! Description:\n! Computes cross product of a*b.\n!\n! ==============================================================================\n\n! VARIABLES\nimplicit none\n! Function definition\nreal(dk) :: DCROSS_PRODUCT(1:3)\n! Arguments IN\nreal(dk) :: a(1:3),b(1:3)\n\n! ==============================================================================\n\nDCROSS_PRODUCT(1) = a(2)*b(3) - a(3)*b(2)\nDCROSS_PRODUCT(2) = a(3)*b(1) - a(1)*b(3)\nDCROSS_PRODUCT(3) = a(1)*b(2) - a(2)*b(1)\n\nend function DCROSS_PRODUCT\n\n\nend module\n", "meta": {"hexsha": "ee1c53e35cd6b0983962b4f3e255bfd0b4ad1a9e", "size": 17637, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "state_init.f90", "max_stars_repo_name": "dkamato/NAPLES", "max_stars_repo_head_hexsha": "fbbf2be8fe861ecaf47051bc0811ad947bb9dc82", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2016-10-31T16:47:26.000Z", "max_stars_repo_stars_event_max_datetime": "2019-01-15T01:18:54.000Z", "max_issues_repo_path": "state_init.f90", "max_issues_repo_name": "dkamato/NAPLES", "max_issues_repo_head_hexsha": "fbbf2be8fe861ecaf47051bc0811ad947bb9dc82", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "state_init.f90", "max_forks_repo_name": "dkamato/NAPLES", "max_forks_repo_head_hexsha": "fbbf2be8fe861ecaf47051bc0811ad947bb9dc82", "max_forks_repo_licenses": ["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.7748478702, "max_line_length": 106, "alphanum_fraction": 0.4880648636, "num_tokens": 5638, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6585481020891074}} {"text": "subroutine antialias2d(yh)\n! performs 2d antialias 2/3 filter on vector yh\n! zeros out modes (Nx/2 - b) ... (Nx/2) and (-Nx/2 + 1) ... (-Nx / 2 + b)\n! === Parameters ===\n! yh - 1d solution in fourier space. Wave\n! === Output ===\n! yh - anti aliased 1d solution in fourier space\n complex(dp), intent(inout) :: yh(:,:)\n integer :: NpX, aX, bX, NpY, aY, bY\n \n NpX = size(yh, 1)\n NpY = size(yh, 2)\n \n aX = NpX / 2\n bX = NpX / 6\n\n aY = NpY / 2\n bY = NpY / 6\n \n yh( aX + 1 - bX : aX + 1 + bX, : ) = 0.0_dp;\n yh( : , aY + 1 - bY : aY + 1 + bY ) = 0.0_dp;\n\nend subroutine antialias2d", "meta": {"hexsha": "3f915b0c7c3f99d0f03533e1b7065bb677cc7210", "size": 621, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "partitioned/fortran/tools/subroutines/antialias2d.f90", "max_stars_repo_name": "buvoli/epbm", "max_stars_repo_head_hexsha": "32ffe175a2e3456799ebc3e6feeb085ff5c83f81", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "partitioned/fortran/tools/subroutines/antialias2d.f90", "max_issues_repo_name": "buvoli/epbm", "max_issues_repo_head_hexsha": "32ffe175a2e3456799ebc3e6feeb085ff5c83f81", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "partitioned/fortran/tools/subroutines/antialias2d.f90", "max_forks_repo_name": "buvoli/epbm", "max_forks_repo_head_hexsha": "32ffe175a2e3456799ebc3e6feeb085ff5c83f81", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.0, "max_line_length": 73, "alphanum_fraction": 0.5136876006, "num_tokens": 281, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.7549149758396752, "lm_q1q2_score": 0.6585480972790044}} {"text": "c Program TXPHO_ROUTINES\n\n\tINCLUDE 'VICMAIN_FOR'\n\n\tSUBROUTINE MAIN44\n\n INCLUDE 'pho'\n\n\tinteger cnt, i, num, MillMode, TillMode, SunShadow, ViewShadow, status\n\treal*4 temp\nc\treal*8 dval1, IncAng, EmAng, PhasAng, pval\n\treal*8 dval1, pval\n\treal*8 MIllum(3),TIllum(3) !Illum(1,2,3)=[cos(inc),cos(em),cos(phase)] \n\tcharacter*132 msg\n\tcharacter*(pho_max_func_name_length) cval1\nc\tcharacter*8 cval1\nc\tcharacter*(pho_max_key_length) keylist(4)\n\tcharacter*(pho_max_keywd_length) keylist(pho_max_param_func)\n\n\tinteger pho\n\n\tcall xvmessage(' program PHO_TEST', ' ')\n\tcall xvmessage( ' ', ' ')\n\n\tcall xveaction(' ',' ')\n\n\tcall pho_init( pho, status)\nc get the photometric function and there input parameters from the PDF\nc and set these in the photometric object :\n\n\tcall pho_get_Parms( pho, status)\n\n\ti = 0\n\nc get the list of parameter keywords for the current photometric function : \n\n\tcall pho_get_keys( pho, keylist, num, status)\n\nc get the photometric function name :\n\n\tcall pho_get_func( pho, cval1, status)\n\n\tmsg = ' Function = '//cval1\n\tcall xvmessage( msg, ' ')\n\n\tcall xvmessage( ' ', ' ')\n\n\t write( msg, 1000) num\n1000\t format( 'parameter number = ', i4)\n\t call xvmessage( msg, ' ')\n\n\tdo i=1,num\n\t call pho_get_val( pho, keylist(i), dval1, status)\n\t write( msg, 1010) keylist(i), dval1\n1010\t format( a, ' = ', 1pe10.3)\n\t call xvmessage( msg, ' ')\n\tenddo\n\nc reads in the function arguments from the PDF :\n\n\tcall xvp('INC_ANG', temp, cnt)\n\tMIllum(1) = temp\n\n\tcall xvp('EM_ANG', temp, cnt)\n\tMIllum(2) = temp\n\n\tcall xvp('PHAS_ANG', temp, cnt)\n\tMIllum(3) = temp\n\n\tcall xvmessage( ' ', ' ')\n\n\twrite( msg, 1001) MIllum(1)\n1001\tformat(' Incidence Angle = ', 1pd10.3)\n\tcall xvmessage( msg, ' ')\n\n\twrite( msg, 1002) MIllum(2)\n1002\tformat(' Emission Angle = ', 1pd10.3)\n\tcall xvmessage( msg, ' ')\n\n\twrite( msg, 1003) MIllum(3)\n1003\tformat(' Phase Angle = ', 1pd10.3)\n\tcall xvmessage( msg, ' ')\n\n\tcall xvmessage( ' ', ' ')\n\n\nc get the bidirectional reflectance value :\n\n\tMillMode = illEllCos\n\tMIllum(1)=cos(MIllum(1)*rad_deg)\n\tMIllum(2)=cos(MIllum(2)*rad_deg)\n\tMIllum(3)=cos(MIllum(3)*rad_deg)\n\n\tSunShadow = illNoShadow\n\tViewShadow = illNoShadow\n\tcall pho_bidi_ref(pho,MillMode,SunShadow,ViewShadow,MIllum,pval,status) \n\n\twrite( msg, 1004) pval\n1004\tformat(' Bidirectional Reflectance Value = ', 1pd10.3)\n\tcall xvmessage( msg, ' ')\n\n\nc get the photometric function value :\n\n\tMillMode = illEllCos\n\tcall pho_func(pho, MillMode, SunShadow, ViewShadow, MIllum, \n f\tpval, status)\n\n\twrite( msg, 1005) pval\n1005\tformat(' Photometric Function value = ', 1pd10.3)\n\tcall xvmessage( msg, ' ')\n\n\nc get the photometric correction function value to nadir :\n\n\tMillMode = illEllCos\n\tTillMode = illEllCos\n\n\tTIllum(1) =1.0\n\tTIllum(2) =1.0\n\tTIllum(3) =1.0\n\n\tcall pho_correct(pho,MillMode,SunShadow,ViewShadow,MIllum,\n f TillMode,SunShadow,ViewShadow,TIllum,pval,status)\n\n\twrite( msg, 1006) pval\n1006\tformat(' to-nadir Correction Value = ', 1pd10.3)\n\tcall xvmessage( msg, ' ')\n\n\tcall xvmessage( ' ', ' ')\n\n\tcall pho_free( pho, status)\n\treturn\n\tend\n", "meta": {"hexsha": "2fbf6151f568b761377c34073cc22f5394d2941d", "size": 3062, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "vos/p2/sub/pho_routines/test/txpho_routines.f", "max_stars_repo_name": "NASA-AMMOS/VICAR", "max_stars_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2020-10-21T05:56:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T10:02:01.000Z", "max_issues_repo_path": "vos/p2/sub/pho_routines/test/txpho_routines.f", "max_issues_repo_name": "NASA-AMMOS/VICAR", "max_issues_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "vos/p2/sub/pho_routines/test/txpho_routines.f", "max_forks_repo_name": "NASA-AMMOS/VICAR", "max_forks_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-03-09T01:51:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-23T00:23:24.000Z", "avg_line_length": 22.6814814815, "max_line_length": 76, "alphanum_fraction": 0.6943174396, "num_tokens": 1040, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.912436167620237, "lm_q2_score": 0.7217432062975979, "lm_q1q2_score": 0.6585446051601224}} {"text": " subroutine matinx2 ( a ,ierror)\n\nc\t'exact' inversion of 4 X 4 matrix\n\n implicit real*4 ( a-h, o-z )\n\n dimension a ( 4 , 4 ) , b ( 4 , 4 )\nc dimension c(4,4)\n integer i , j\n\n ierror=0\n absmax = 0.\n\n do 5010 i = 1 , 4\n do 5010 j = 1 , 4\nc c(i,j)=a(i,j) \n\t if ( abs ( a ( i , j ) ) .gt. absmax ) absmax =abs( a ( i , j ))\n5010 continue\n\n if ( absmax .eq. 0. ) then\nc stop 'singularity problem in matinx2'\n\t ierror=1\n return\n end if\n\n\n fabsmx = 1.d00 / absmax\n\n\n do 5020 i = 1 , 4\n do 5020 j = 1 , 4\n\t a ( i , j ) = a ( i , j ) * fabsmx\n5020 continue\n\n\n\n b(1,1) = a(2,2) * a(3,3) * a(4,4) + a(2,3) * a(3,4) * a(4,2)\n 1 + a(2,4) * a(3,2) * a(4,3) - a(2,2) * a(3,4) * a(4,3)\n 2 - a(2,3) * a(3,2) * a(4,4) - a(2,4) * a(3,3) * a(4,2)\n b(2,1) = a(2,3) * a(3,1) * a(4,4) + a(2,4) * a(3,3) * a(4,1)\n 1 + a(2,1) * a(3,4) * a(4,3) - a(2,3) * a(3,4) * a(4,1)\n 2 - a(2,4) * a(3,1) * a(4,3) - a(2,1) * a(3,3) * a(4,4)\n b(3,1) = a(2,4) * a(3,1) * a(4,2) + a(2,1) * a(3,2) * a(4,4)\n 1 + a(2,2) * a(3,4) * a(4,1) - a(2,4) * a(3,2) * a(4,1)\n 2 - a(2,1) * a(3,4) * a(4,2) - a(2,2) * a(3,1) * a(4,4)\n b(4,1) = a(2,1) * a(3,3) * a(4,2) + a(2,2) * a(3,1) * a(4,3)\n 1 + a(2,3) * a(3,2) * a(4,1) - a(2,1) * a(3,2) * a(4,3)\n 2 - a(2,2) * a(3,3) * a(4,1) - a(2,3) * a(3,1) * a(4,2)\n b(1,2) = a(3,2) * a(4,4) * a(1,3) + a(3,3) * a(4,2) * a(1,4)\n 1 + a(3,4) * a(4,3) * a(1,2) - a(3,2) * a(4,3) * a(1,4)\n 2 - a(3,3) * a(4,4) * a(1,2) - a(3,4) * a(4,2) * a(1,3)\n b(2,2) = a(3,3) * a(4,4) * a(1,1) + a(3,4) * a(4,1) * a(1,3)\n 1 + a(3,1) * a(4,3) * a(1,4) - a(3,3) * a(4,1) * a(1,4)\n 2 - a(3,4) * a(4,3) * a(1,1) - a(3,1) * a(4,4) * a(1,3)\n b(3,2) = a(3,4) * a(4,2) * a(1,1) + a(3,1) * a(4,4) * a(1,2)\n 1 + a(3,2) * a(4,1) * a(1,4) - a(3,4) * a(4,1) * a(1,2)\n 2 - a(3,1) * a(4,2) * a(1,4) - a(3,2) * a(4,4) * a(1,1)\n b(4,2) = a(3,1) * a(4,2) * a(1,3) + a(3,2) * a(4,3) * a(1,1)\n 1 + a(3,3) * a(4,1) * a(1,2) - a(3,1) * a(4,3) * a(1,2)\n 2 - a(3,2) * a(4,1) * a(1,3) - a(3,3) * a(4,2) * a(1,1)\n b(1,3) = a(4,2) * a(1,3) * a(2,4) + a(4,3) * a(1,4) * a(2,2)\n 1 + a(4,4) * a(1,2) * a(2,3) - a(4,2) * a(1,4) * a(2,3)\n 2 - a(4,3) * a(1,2) * a(2,4) - a(4,4) * a(1,3) * a(2,2)\n b(2,3) = a(4,3) * a(1,1) * a(2,4) + a(4,4) * a(1,3) * a(2,1)\n 1 + a(4,1) * a(1,4) * a(2,3) - a(4,3) * a(1,4) * a(2,1)\n 2 - a(4,4) * a(1,1) * a(2,3) - a(4,1) * a(1,3) * a(2,4)\n b(3,3) = a(4,4) * a(1,1) * a(2,2) + a(4,1) * a(1,2) * a(2,4)\n 1 + a(4,2) * a(1,4) * a(2,1) - a(4,4) * a(1,2) * a(2,1)\n 2 - a(4,1) * a(1,4) * a(2,2) - a(4,2) * a(1,1) * a(2,4)\n b(4,3) = a(4,1) * a(1,3) * a(2,2) + a(4,2) * a(1,1) * a(2,3)\n 1 + a(4,3) * a(1,2) * a(2,1) - a(4,1) * a(1,2) * a(2,3)\n 2 - a(4,2) * a(1,3) * a(2,1) - a(4,3) * a(1,1) * a(2,2)\n b(1,4) = a(1,2) * a(2,4) * a(3,3) + a(1,3) * a(2,2) * a(3,4)\n 1 + a(1,4) * a(2,3) * a(3,2) - a(1,2) * a(2,3) * a(3,4)\n 2 - a(1,3) * a(2,4) * a(3,2) - a(1,4) * a(2,2) * a(3,3)\n b(2,4) = a(1,3) * a(2,4) * a(3,1) + a(1,4) * a(2,1) * a(3,3)\n 1 + a(1,1) * a(2,3) * a(3,4) - a(1,3) * a(2,1) * a(3,4)\n 2 - a(1,4) * a(2,3) * a(3,1) - a(1,1) * a(2,4) * a(3,3)\n b(3,4) = a(1,4) * a(2,2) * a(3,1) + a(1,1) * a(2,4) * a(3,2)\n 1 + a(1,2) * a(2,1) * a(3,4) - a(1,4) * a(2,1) * a(3,2)\n 2 - a(1,1) * a(2,2) * a(3,4) - a(1,2) * a(2,4) * a(3,1)\n b(4,4) = a(1,1) * a(2,2) * a(3,3) + a(1,2) * a(2,3) * a(3,1)\n 1 + a(1,3) * a(2,1) * a(3,2) - a(1,1) * a(2,3) * a(3,2)\n 2 - a(1,2) * a(2,1) * a(3,3) - a(1,3) * a(2,2) * a(3,1)\n\n det = a ( 1 , 1 ) * b ( 1 , 1 ) + a ( 1 , 2 ) * b ( 2 , 1 )\n 1 + a ( 1 , 3 ) * b ( 3 , 1 ) + a ( 1 , 4 ) * b ( 4 , 1 )\nc\tif(abs(det).lt.1.e-2)then\nc\t\tprint*,det\nc do i=1,4\nc do j=1,4\nc print*,'c(',i,',',j,')=',sngl(c(i,j)) \nc end do\nc end do\nc\tend if\n\nc print*,'en matinx (4)',det\n\n fdeta = fabsmx / det\n\nc print*,'en matinx (5)',fdeta\n\n\n do 5000 i = 1 , 4\n do 5000 j = 1 , 4\n a ( i , j ) = b ( i , j ) * fdeta\n5000 continue\nc \tif(abs(det).lt.1.e-2)then\nc do i=1,4\nc do j=1,4\nc sum=0.\nc do l=1,4\nc sum=sum+a(i,l)*c(l,j)\nc end do\nc print*,'c*inversa(',i,',',j,')=',sum\nc end do\nc end do\nc end if \n\nc print*,'en matinx (6)',fdeta\n \n return\n end\n\n", "meta": {"hexsha": "edba94905daa69c1ca5d3e5313782eeb0daf6793", "size": 4608, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/sir/matinx2.f", "max_stars_repo_name": "fluxtransport/hazel2", "max_stars_repo_head_hexsha": "4121df2fa6bf96bf8f193f287bbf11c70c5a519e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2018-08-31T11:13:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-12T02:30:56.000Z", "max_issues_repo_path": "src/sir/matinx2.f", "max_issues_repo_name": "fluxtransport/hazel2", "max_issues_repo_head_hexsha": "4121df2fa6bf96bf8f193f287bbf11c70c5a519e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2018-04-03T15:09:21.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-27T10:10:45.000Z", "max_forks_repo_path": "src/sir/matinx2.f", "max_forks_repo_name": "fluxtransport/hazel2", "max_forks_repo_head_hexsha": "4121df2fa6bf96bf8f193f287bbf11c70c5a519e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-05-01T13:47:21.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-23T20:49:08.000Z", "avg_line_length": 36.864, "max_line_length": 67, "alphanum_fraction": 0.3407118056, "num_tokens": 2835, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361580958427, "lm_q2_score": 0.7217432122827967, "lm_q1q2_score": 0.6585446037470672}} {"text": "!-------------------------------------------------------------------------------!\r\n! ! \r\n\r\nsubroutine savgol(y,w,f,y1,next)\r\n\r\n! Iterative and adaptive Sawitzky-Golay filering !\r\n! !\r\n! Authors: !\r\n! Per J\\\"onsson, Malm\\\"o University, Sweden !\r\n! e-mail per.jonsson@ts.mah.se !\r\n! !\r\n! Lars Eklundh, Lund University, Sweden !\r\n! e-mail lars.eklundh@nateko.lu.se !\r\n! !\r\n! Updated 12/9-2006 !\r\n! !\r\n!-------------------------------------------------------------------------------!\r\n\r\nimplicit none\r\n\r\ninteger :: i,j,nyear,nptperyear,npt,nenvi,printflag,debugflag,win(3),next,m1,m2\r\ninteger :: failleft, failright\r\ndouble precision :: wfact,y(npt),w(npt),y1(npt),yext(1:npt+2*next) !! OBS next\r\ndouble precision :: yfit(1:npt+2*next),wfit(1:npt+2*next),ymed\r\ndouble precision :: yfitmean,yfitstd,ydiff,f(npt,3),c(3)\r\n\r\ncommon /parameters/ nyear,nptperyear,npt,nenvi,printflag,debugflag,wfact,win \r\n\r\n!---- Extend data circularly to improve fitting near the boundary of the -------\r\n! original data \r\n\r\nyext = (/y(npt-next+1:npt),y,y(1:next)/)\r\nwfit = (/w(npt-next+1:npt),w,w(1:next)/)\r\nyfit = yext\r\n\r\n!---- Iterative and adaptive Savitzky-Golay filter -----------------------------\r\n\r\ndo j = 1,nenvi\r\n\r\n!---- Compute mean and standard deviation -------------------------------------- \r\n\r\n yfitmean = sum(yfit)/(npt+2.d0*next)\r\n yfitstd = sqrt(dot_product(yfit-yfitmean,yfit-yfitmean)/(npt+2.d0*next-1.d0))\r\n\r\n do i = 1+next,npt+next\r\n \r\n!---- Set fitting window ------------------------------------------------------- \r\n \r\n m1 = i - win(j) \r\n m2 = i + win(j) \r\n \r\n!---- Adapt fitting interval. Large variation use a smaller window ------------- \r\n \r\n if (maxval(yfit(m1:m2)) - minval(yfit(m1:m2)) > 1.2d0*2.d0*yfitstd) then \r\n m1 = m1 + win(j)/3\r\n m2 = m2 - win(j)/3\r\n end if\r\n \r\n!---- Check so that there are enough points, at least 3 at either side, with --- \r\n! weights different from zero. If not, extend fitting window \r\n\r\n failleft = 0\r\n do while ( (count(abs(wfit(m1:i)) > 1.d-10) < 3) .and. (failleft == 0) ) \r\n m1 = m1 - 1\r\n\t if (m1 < 1) then \r\n failleft = 1\r\n m1 = 1\r\n end if\r\n end do\r\n\r\n failright = 0\r\n do while ( (count(abs(wfit(i:m2)) > 1.d-10) < 3) .and. (failright == 0) ) \r\n m2 = m2 + 1\r\n\t if (m2 > npt+2*next) then\r\n\t failright = 1\r\n\t\tm2 = npt+2*next\r\n\t end if\r\n end do\r\n \r\n!---- Fit polynomial if enough data values with non-zero weight ----------------\r\n\r\n if ((failleft == 0) .and. (failright == 0)) then\r\n\r\n!---- Fit polynomial of degree two to the datavalues in the interval [m1,m2] ---\r\n! Observe that the basis functions need to be shifted in order to get a \r\n! better conditioning \r\n\r\n call linlsq(m2-m1+1,3,f(1:m2-m1+1,:),yext(m1:m2),wfit(m1:m2),c)\r\n \r\n ! Compute the fitted function\r\n\r\n yfit(i) = c(1)*f(i-m1+1,1) + c(2)*f(i-m1+1,2) + c(3)*f(i-m1+1,3)\r\n\r\n!---- If not enough values with non-zero weigth replace with median value ------\r\n\r\n\telse\r\n\r\n\t call median(yext(m1:m2),m2-m1+1,ymed)\r\n\t yfit(i) = ymed\r\n\r\n end if\r\n \r\n end do\r\n\r\n!---- Modify weights -----------------------------------------------------------\r\n\r\n if (j < nenvi) then\r\n call modweight(j,npt+2*next,wfit,yext,yfit)\r\n end if\r\n \r\nend do\r\n\r\n!---- Transfer fitted points in the intervall [1,npt] to y1 --------------------\r\n\r\ny1 = yfit(1+next:npt+next)\r\n\r\n\r\n!---- Output for debug purposes ------------------------------------------------\r\n\r\n! write(*,*) 1,sum(y1)\r\n\r\nend subroutine savgol", "meta": {"hexsha": "2758c852a6bfc6ef4a5587233dad9f24645e6f92", "size": 4423, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/Smooth_Gapfill_LAI/savgol.f90", "max_stars_repo_name": "bucricket/projectMASpreprocess", "max_stars_repo_head_hexsha": "608495d7cd6890ecca6ad2a8be0d15b5ea80f7c1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-28T20:26:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T20:26:59.000Z", "max_issues_repo_path": "source/Smooth_Gapfill_LAI/savgol.f90", "max_issues_repo_name": "bucricket/projectMASpreprocess", "max_issues_repo_head_hexsha": "608495d7cd6890ecca6ad2a8be0d15b5ea80f7c1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/Smooth_Gapfill_LAI/savgol.f90", "max_forks_repo_name": "bucricket/projectMASpreprocess", "max_forks_repo_head_hexsha": "608495d7cd6890ecca6ad2a8be0d15b5ea80f7c1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-04-20T21:04:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-16T08:05:44.000Z", "avg_line_length": 36.2540983607, "max_line_length": 120, "alphanum_fraction": 0.4128419625, "num_tokens": 1126, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.912436167620237, "lm_q2_score": 0.7217432003123989, "lm_q1q2_score": 0.6585445996990104}} {"text": "! chk_reduce.f90 --\r\n! Check if the compiler supports the reduce intrinsic function\r\n!\r\nprogram chk_reduce\r\n implicit none\r\n\r\n real, dimension(100) :: array\r\n real :: x\r\n\r\n call random_number( array )\r\n\r\n x = reduce( array, select_max )\r\n\r\ncontains\r\nreal function select_max( a, b )\r\n real, intent(in) :: a, b\r\n\r\n select_max = max( a, b )\r\n\r\nend function select_max\r\n\r\nend program chk_reduce\r\n", "meta": {"hexsha": "3624f579fc5bc473ac3ebf6d05a74a941dd07f34", "size": 434, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "chkfeatures/chk_reduce.f90", "max_stars_repo_name": "timcera/flibs_from_svn", "max_stars_repo_head_hexsha": "7790369ac1f0ff6e35ef43546446b32446dccc6b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chkfeatures/chk_reduce.f90", "max_issues_repo_name": "timcera/flibs_from_svn", "max_issues_repo_head_hexsha": "7790369ac1f0ff6e35ef43546446b32446dccc6b", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chkfeatures/chk_reduce.f90", "max_forks_repo_name": "timcera/flibs_from_svn", "max_forks_repo_head_hexsha": "7790369ac1f0ff6e35ef43546446b32446dccc6b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.8695652174, "max_line_length": 67, "alphanum_fraction": 0.6129032258, "num_tokens": 103, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031738057795402, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.6585168527062842}} {"text": "function dnrm2_c(n, x, incx) bind(c)\n use iso_c_binding\n\n integer(c_int), value :: n, incx\n real(c_double) :: x(n), dnrm2_c\n\n real(kind(1.d0)) :: dnrm2\n\n dnrm2_c = dnrm2(n, x(1), incx)\n\n return\n\nend function dnrm2_c\n\n\nfunction dnrmf_c(m, n, a, lda) bind(c)\n\n use iso_c_binding\n \n integer(c_int), value :: m, n, lda\n real(c_double) :: a(lda,n), dnrmf_c\n\n real(kind(1.d0)) :: dlange, w\n\n \n dnrmf_c = dlange('F', m, n, a(1,1), lda, w)\n\nend function dnrmf_c\n", "meta": {"hexsha": "f8abd9913263529645edbe1b28953a54afb3ae40", "size": 481, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "2A/S8/OpenMP/BE/BE_2018_2019/lu_tasks/auxf.f90", "max_stars_repo_name": "MOUDDENEHamza/ENSEEIHT", "max_stars_repo_head_hexsha": "a90b1dee0c8d18a9578153a357278d99405bb534", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-05-02T12:32:32.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-12T20:20:35.000Z", "max_issues_repo_path": "2IMA/SystemesConcurrents/tp7/auxf.f90", "max_issues_repo_name": "LagOussama/enseeiht", "max_issues_repo_head_hexsha": "d3247880c66cd3754d0bd29781ab1ddec9f6536f", "max_issues_repo_licenses": ["FTL"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-01-14T20:03:26.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-30T01:10:00.000Z", "max_forks_repo_path": "2A/S8/OpenMP/BE/BE_2018_2019/lu_tasks/auxf.f90", "max_forks_repo_name": "MOUDDENEHamza/ENSEEIHT", "max_forks_repo_head_hexsha": "a90b1dee0c8d18a9578153a357278d99405bb534", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2020-11-11T21:28:11.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-19T13:54:22.000Z", "avg_line_length": 16.5862068966, "max_line_length": 45, "alphanum_fraction": 0.604989605, "num_tokens": 188, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933359135361, "lm_q2_score": 0.8031737963569014, "lm_q1q2_score": 0.658516843213399}} {"text": "Submodule ( statistical_data_mod ) statistical_std_dev_smod\n!\n Use kind_parameters_mod\n!\n Implicit None\n!\nContains\n!\n Module Procedure Statistical_Std_Dev\n!\n Real(KIND=rkind) :: mn\n If ( Size(this%data) .ne. 0 ) Then\n If ( Present ( mean ) ) Then\n mn = mean\n Else\n If ( this%Dmean ) Then\n mn = this%mean\n Else\n mn = Statistical_Mean ( this )\n End If\n End If\n If ( this%Dvariance ) Then\n std_dev = sqrt ( this%variance )\n Else\n std_dev = Sqrt ( Statistical_Variance ( this, mn ) )\n End If\n Else\n std_dev = Huge ( std_dev )\n End If\n this%std_dev = std_dev\n this%Dstd_dev = .true.\n!\n End Procedure Statistical_Std_Dev\n!\nEnd Submodule statistical_std_dev_smod\n", "meta": {"hexsha": "42fbd3bb49b4cc17ca5acb873ffa890133357525", "size": 798, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/modules/statistical_std_dev_smod.f90", "max_stars_repo_name": "rouson/statistics", "max_stars_repo_head_hexsha": "f73be960f2575940379b70df0a2ff62a84953ff6", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/modules/statistical_std_dev_smod.f90", "max_issues_repo_name": "rouson/statistics", "max_issues_repo_head_hexsha": "f73be960f2575940379b70df0a2ff62a84953ff6", "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/modules/statistical_std_dev_smod.f90", "max_forks_repo_name": "rouson/statistics", "max_forks_repo_head_hexsha": "f73be960f2575940379b70df0a2ff62a84953ff6", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.1666666667, "max_line_length": 62, "alphanum_fraction": 0.5877192982, "num_tokens": 217, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094117351309, "lm_q2_score": 0.737158174177441, "lm_q1q2_score": 0.658510334930193}} {"text": "program main\n implicit none \n integer::i,j,n=108\n !real(kind=8)::fx(200),fy(200),fz(200) \n !real(8)::v1,v2,f,k=0.0000001\n real(8),allocatable::a(:,:),rx(:),ry(:),rz(:),fx(:),fy(:),fz(:)\n\n allocate (a(n,n),rx(n),ry(n),rz(n),fx(n),fy(n),fz(n))\n \n open(1,file='argon.init')\n \n do i=1,n\n read(1,*) (a(i,j),j=1,3)\n write(10,*)(a(i,j),j=1,3)\n rx(i) =a(i,1)\n ry(i) =a(i,2)\n rz(i) =a(i,3)\n end do\n call calc_force(n,rx,ry,rz,fx,fy,fz)\n \n \n \nend program main\n\nsubroutine calc_force(n,rx,ry,rz,fx,fy,fz)\n implicit none\n integer::i,j,n\n real(8)::rx(200),ry(200),rz(200),boxl,sigsq,epslon,rxij,ryij,rzij,rijsq,sr2,sr6,sr12,rcutoffsq,rcutoff,sig,kb\n real(8)::fxij,fyij,fzij,fpr,fx(200),fy(200),fz(200)\n !real(8),allocatable::a(:,:)!,fx(:),fy(:),fz(:)\n n=108\n !do i=1,n\n !write(15,*)rx(i),ry(i),rz(i) \n !end do\n \n boxl =17.158d0\n sig = 3.405d0\n sigsq = sig * sig\n kb = 1.38E-23\n epslon = 120.0d0 !* kb\n\n rcutoff = 0.50d0 * boxl\n rcutoffsq = rcutoff * rcutoff\n\n do i=1,n\n rx(i) = rx(i) - (boxl * anint(rx(i)/boxl))\n ry(i) = ry(i) - (boxl * anint(ry(i)/boxl))\n rz(i) = rz(i) - (boxl * anint(rz(i)/boxl))\n end do\n\n do i=1,n\n fx(i)=0.0d0; fy(i)=0.0d0; fz(i)=0.0d0\n end do\n\n \n do i=1,n-1\n do j=i+1,n\n rxij = rx(i) - rx(j)\n ryij = ry(i) - ry(j)\n rzij = rz(i) - rz(j)\n \n rxij = rxij - (boxl * anint(rxij/boxl))\n ryij = ryij - (boxl * anint(ryij/boxl))\n rzij = rzij - (boxl * anint(rzij/boxl))\n \n \n rijsq = rxij**2 + ryij**2 + rzij**2\n sr2 = sigsq/rijsq\n sr6 = sr2 * sr2 * sr2\n sr12 = sr6 * sr6\n\n if(rijsq= 0.\r\nC\r\nC A (input) DOUBLE PRECISION array, dimension (LDA,N)\r\nC On entry, the leading N-by-N part of this array must\r\nC contain the matrix A.\r\nC\r\nC LDA INTEGER\r\nC The leading dimension of the array A. LDA >= MAX(1,N).\r\nC\r\nC QG (input) DOUBLE PRECISION array, dimension (LDQG,N+1)\r\nC On entry, the leading N-by-N+1 part of this array must\r\nC contain in columns 1:N the lower triangular part of the\r\nC matrix Q and in columns 2:N+1 the upper triangular part\r\nC of the matrix G. If TYP = 'S', the parts containing the\r\nC diagonal and the first supdiagonal of this array are not\r\nC referenced.\r\nC\r\nC LDQG INTEGER\r\nC The leading dimension of the array QG. LDQG >= MAX(1,N).\r\nC\r\nC Workspace\r\nC\r\nC\r\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\r\nC where LDWORK >= 2*N when NORM = '1', NORM = 'I' or\r\nC NORM = 'O'; otherwise, DWORK is not referenced.\r\nC\r\nC CONTRIBUTORS\r\nC\r\nC D. Kressner, Technical Univ. Berlin, Germany, and\r\nC P. Benner, Technical Univ. Chemnitz, Germany, December 2003.\r\nC\r\nC REVISIONS\r\nC\r\nC V. Sima, June 2008 (SLICOT version of the HAPACK routine DLANHA).\r\nC\r\nC KEYWORDS\r\nC\r\nC Elementary matrix operations, Hamiltonian matrix, skew-Hamiltonian\r\nC matrix.\r\nC\r\nC ******************************************************************\r\nC\r\nC .. Parameters ..\r\n DOUBLE PRECISION ONE, TWO, ZERO\r\n PARAMETER ( ONE = 1.0D+0, TWO = 2.0D+0, ZERO = 0.0D+0 )\r\nC .. Scalar Arguments ..\r\n CHARACTER NORM, TYP\r\n INTEGER LDA, LDQG, N\r\nC .. Array Arguments ..\r\n DOUBLE PRECISION A(LDA,*), DWORK(*), QG(LDQG,*)\r\nC .. Local Scalars ..\r\n LOGICAL LSH\r\n INTEGER I, J\r\n DOUBLE PRECISION DSCL, DSUM, SCALE, SUM, TEMP, VALUE\r\nC .. External Functions ..\r\n LOGICAL LSAME\r\n DOUBLE PRECISION DLANGE, DLAPY2\r\n EXTERNAL DLANGE, DLAPY2, LSAME\r\nC .. External Subroutines ..\r\n EXTERNAL DLASSQ\r\nC .. Intrinsic Functions ..\r\n INTRINSIC ABS, MAX, SQRT\r\nC\r\nC .. Executable Statements ..\r\nC\r\n LSH = LSAME( TYP, 'S' )\r\nC\r\n IF ( N.EQ.0 ) THEN\r\n VALUE = ZERO\r\nC\r\n ELSE IF ( LSAME( NORM, 'M' ) .AND. LSH ) THEN\r\nC\r\nC Find max(abs(A(i,j))).\r\nC\r\n VALUE = DLANGE( 'MaxElement', N, N, A, LDA, DWORK )\r\n IF ( N.GT.1 ) THEN\r\n DO 30 J = 1, N+1\r\n DO 10 I = 1, J-2\r\n VALUE = MAX( VALUE, ABS( QG(I,J) ) )\r\n 10 CONTINUE\r\n DO 20 I = J+1, N\r\n VALUE = MAX( VALUE, ABS( QG(I,J) ) )\r\n 20 CONTINUE\r\n 30 CONTINUE\r\n END IF\r\nC\r\n ELSE IF ( LSAME( NORM, 'M' ) ) THEN\r\nC\r\nC Find max( abs( A(i,j) ), abs( QG(i,j) ) ).\r\nC\r\n VALUE = MAX( DLANGE( 'MaxElement', N, N, A, LDA, DWORK ),\r\n $ DLANGE( 'MaxElement', N, N+1, QG, LDQG,\r\n $ DWORK ) )\r\nC\r\n ELSE IF ( ( LSAME( NORM, 'O' ) .OR. ( NORM.EQ.'1' ) .OR.\r\n $ LSAME( NORM, 'I' ) ) .AND. LSH ) THEN\r\nC\r\nC Find the column and row sums of A (in one pass).\r\nC\r\n VALUE = ZERO\r\n DO 40 I = 1, N\r\n DWORK(I) = ZERO\r\n 40 CONTINUE\r\nC\r\n DO 60 J = 1, N\r\n SUM = ZERO\r\n DO 50 I = 1, N\r\n TEMP = ABS( A(I,J) )\r\n SUM = SUM + TEMP\r\n DWORK(I) = DWORK(I) + TEMP\r\n 50 CONTINUE\r\n DWORK(N+J) = SUM\r\n 60 CONTINUE\r\nC\r\nC Compute the maximal absolute column sum.\r\nC\r\n DO 90 J = 1, N+1\r\n DO 70 I = 1, J-2\r\n TEMP = ABS( QG(I,J) )\r\n DWORK(I) = DWORK(I) + TEMP\r\n DWORK(J-1) = DWORK(J-1) + TEMP\r\n 70 CONTINUE\r\n IF ( J.LT.N+1 ) THEN\r\n SUM = DWORK(N+J)\r\n DO 80 I = J+1, N\r\n TEMP = ABS( QG(I,J) )\r\n SUM = SUM + TEMP\r\n DWORK(N+I) = DWORK(N+I) + TEMP\r\n 80 CONTINUE\r\n VALUE = MAX( VALUE, SUM )\r\n END IF\r\n 90 CONTINUE\r\n DO 100 I = 1, N\r\n VALUE = MAX( VALUE, DWORK(I) )\r\n 100 CONTINUE\r\nC\r\n ELSE IF ( LSAME( NORM, 'O' ) .OR. ( NORM.EQ.'1' ) .OR.\r\n $ LSAME( NORM, 'I' ) ) THEN\r\nC\r\nC Find the column and row sums of A (in one pass).\r\nC\r\n VALUE = ZERO\r\n DO 110 I = 1, N\r\n DWORK(I) = ZERO\r\n 110 CONTINUE\r\nC\r\n DO 130 J = 1, N\r\n SUM = ZERO\r\n DO 120 I = 1, N\r\n TEMP = ABS( A(I,J) )\r\n SUM = SUM + TEMP\r\n DWORK(I) = DWORK(I) + TEMP\r\n 120 CONTINUE\r\n DWORK(N+J) = SUM\r\n 130 CONTINUE\r\nC\r\nC Compute the maximal absolute column sum.\r\nC\r\n DO 160 J = 1, N+1\r\n DO 140 I = 1, J-2\r\n TEMP = ABS( QG(I,J) )\r\n DWORK(I) = DWORK(I) + TEMP\r\n DWORK(J-1) = DWORK(J-1) + TEMP\r\n 140 CONTINUE\r\n IF ( J.GT.1 )\r\n $ DWORK(J-1) = DWORK(J-1) + ABS( QG(J-1,J) )\r\n IF ( J.LT.N+1 ) THEN\r\n SUM = DWORK(N+J) + ABS( QG(J,J) )\r\n DO 150 I = J+1, N\r\n TEMP = ABS( QG(I,J) )\r\n SUM = SUM + TEMP\r\n DWORK(N+I) = DWORK(N+I) + TEMP\r\n 150 CONTINUE\r\n VALUE = MAX( VALUE, SUM )\r\n END IF\r\n 160 CONTINUE\r\n DO 170 I = 1, N\r\n VALUE = MAX( VALUE, DWORK(I) )\r\n 170 CONTINUE\r\nC\r\n ELSE IF ( ( LSAME( NORM, 'F' ) .OR.\r\n $ LSAME( NORM, 'E' ) ) .AND. LSH ) THEN\r\nC\r\nC Find normF(A).\r\nC\r\n SCALE = ZERO\r\n SUM = ONE\r\n DO 180 J = 1, N\r\n CALL DLASSQ( N, A(1,J), 1, SCALE, SUM )\r\n 180 CONTINUE\r\nC\r\nC Add normF(G) and normF(Q).\r\nC\r\n DO 190 J = 1, N+1\r\n IF ( J.GT.2 )\r\n $ CALL DLASSQ( J-2, QG(1,J), 1, SCALE, SUM )\r\n IF ( J.LT.N )\r\n $ CALL DLASSQ( N-J, QG(J+1,J), 1, SCALE, SUM )\r\n 190 CONTINUE\r\n VALUE = SQRT( TWO )*SCALE*SQRT( SUM )\r\n ELSE IF ( LSAME( NORM, 'F' ) .OR. LSAME( NORM, 'E' ) ) THEN\r\n SCALE = ZERO\r\n SUM = ONE\r\n DO 200 J = 1, N\r\n CALL DLASSQ( N, A(1,J), 1, SCALE, SUM )\r\n 200 CONTINUE\r\n DSCL = ZERO\r\n DSUM = ONE\r\n DO 210 J = 1, N+1\r\n IF ( J.GT.1 ) THEN\r\n CALL DLASSQ( J-2, QG(1,J), 1, SCALE, SUM )\r\n CALL DLASSQ( 1, QG(J-1,J), 1, DSCL, DSUM )\r\n END IF\r\n IF ( J.LT.N+1 ) THEN\r\n CALL DLASSQ( 1, QG(J,J), 1, DSCL, DSUM )\r\n CALL DLASSQ( N-J, QG(J+1,J), 1, SCALE, SUM )\r\n END IF\r\n 210 CONTINUE\r\n VALUE = DLAPY2( SQRT( TWO )*SCALE*SQRT( SUM ),\r\n $ DSCL*SQRT( DSUM ) )\r\n END IF\r\nC\r\n MA02ID = VALUE\r\n RETURN\r\nC *** Last line of MA02ID ***\r\n END\r\n", "meta": {"hexsha": "2ca18769b8e0160d76fb5ec0ee196da440fa9dde", "size": 8736, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "External/SLICOT/MA02ID.f", "max_stars_repo_name": "bgin/MissileSimulation", "max_stars_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2016-08-28T23:20:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-15T14:43:58.000Z", "max_issues_repo_path": "External/SLICOT/MA02ID.f", "max_issues_repo_name": "bgin/MissileSimulation", "max_issues_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-06-02T21:29:51.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-05T05:59:31.000Z", "max_forks_repo_path": "External/SLICOT/MA02ID.f", "max_forks_repo_name": "bgin/MissileSimulation", "max_forks_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-07-04T22:38:22.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-04T22:38:22.000Z", "avg_line_length": 31.2, "max_line_length": 73, "alphanum_fraction": 0.44253663, "num_tokens": 2776, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094117351309, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6585103297718861}} {"text": " subroutine acal(a,n1dim,nrow,nfunc,wk,dz) \nc---------------------------------------------------------------------\nc acal calculates the weights used in the sum for obtaining\nc model estimates in the backus gilbert inversion method for the \nc special case of integration quelling with orthonormal kernel \nc functions. in this case the weights can be calculated as simple \nc sums. the algorithm used here is a space economizer in that the \nc matrix of weights will overwrite the input matrix of discretized \nc kernels functions. \nc \nc arguments- \nc a-an nrow x nfunc matrix \nc on input a is assumed to contain the discretized orthonormal\nc kernels functions in it's first nfunc columns. these functions \nc are assumed to have been weighted by subroutine weight previous \nc to entry into this subroutine. on output a will contain the\nc weights. a(i,j) will contain the weight appropriate for the\nc jth function at the ith depth point.\nc n1dim-first dimension of a in calling program \nc nrow-number of rows in a \nc nfunc-number of columns in a\nc wk-work vector of length at least nrow\nc \nc modifications- \nc \nc june,1980-replaced earlier version that did not properly\nc take account of endpoint conditions but blindly did only a\nc simple sum. this version is now restricted to use with \nc quadrature weights appropriate to simpson's rule. \nc \nc---------------------------------------------------------------------\n dimension a(n1dim,nfunc),wk(nrow) \nc--inc is used by the blas\n data inc/1/ \n do 100 i=1,nrow \n 100 wk(i) = 1.0\n call weight(wk,nrow,nrow,1,dz)\n do 200 j=1,nfunc\n do 200 i=1,nrow\n 200 a(i,j) = wk(i)*a(i,j) \nc--now sum and shift \nc--endpoint corrections dependent upon the quadrature scheme \nc--being used. this version uses simpson's rule with \nc--trapezoidal endpoint corrections at even numbered points. \n do 400 j=1,nfunc\n call scopy(nrow,a(1,j),inc,wk,inc) \n a(1,j)=0.0 \nc--do odd numbered points first. they require no correction with \nc--simpson's rule.\n wk(1)=2.0*wk(1)\n do 300 i=3,nrow,2\n 300 a(i,j)=a(i-2,j)+wk(i-1)+(wk(i)+wk(i-2))/2.0 \nc--now pick up odd numbered points by using a trapezoidal endpoint. \n do 350 i=2,nrow,2\n 350 a(i,j) = a(i-1,j) + 0.75*wk(i-1) + 0.375*wk(i)\n 400 continue\n return\n end \n\nc $Id$ \n", "meta": {"hexsha": "20f29dd30805f3cc935f68837ce82781cdc9ab42", "size": 2477, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "lib/location/libglp/acal.f", "max_stars_repo_name": "jreyes1108/antelope_contrib", "max_stars_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_stars_repo_licenses": ["BSD-2-Clause", "MIT"], "max_stars_count": 30, "max_stars_repo_stars_event_min_datetime": "2015-02-20T21:44:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-27T02:53:14.000Z", "max_issues_repo_path": "lib/location/libglp/acal.f", "max_issues_repo_name": "jreyes1108/antelope_contrib", "max_issues_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_issues_repo_licenses": ["BSD-2-Clause", "MIT"], "max_issues_count": 14, "max_issues_repo_issues_event_min_datetime": "2015-07-07T19:17:24.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-19T19:18:53.000Z", "max_forks_repo_path": "lib/location/libglp/acal.f", "max_forks_repo_name": "jreyes1108/antelope_contrib", "max_forks_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_forks_repo_licenses": ["BSD-2-Clause", "MIT"], "max_forks_count": 46, "max_forks_repo_forks_event_min_datetime": "2015-02-06T16:22:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T11:46:37.000Z", "avg_line_length": 40.606557377, "max_line_length": 72, "alphanum_fraction": 0.6289866774, "num_tokens": 690, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543488, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6585103255842512}} {"text": "! *******************************************************************\r\n! * *\r\n! * Real*8 Function dlace1 *\r\n! * *\r\n! *******************************************************************\r\n! Double Precision Version 1.31\r\n! Written by Gordon A. Fenton, 1989\r\n! Latest Update: May 9, 2001\r\n!\r\n! PURPOSE returns the covariance between two points in a 1-D exponentially\r\n! damped oscillatory noise process.\r\n!\r\n! Returns the covariance between two points separated by distance T\r\n! in an exponentiallly damped oscillatory noise process.\r\n! The covariance function for such a process is given by\r\n!\r\n! B(T) = var*cos(dpb*T)*exp( -2*|T|/dthx )\r\n!\r\n! where var is the point variance, dthx is the scale of fluctuation, and\r\n! dpb is the frequency of the oscillation, and where var, dpb, and dthx\r\n! are brought into this routine through the common block DPARAM.\r\n!\r\n! If var < 0, then this function returns the variance of a local average\r\n! of the process, |var|*V(T), averaged over the distance T.\r\n! The variance function V(T) of the process averaged over a certain\r\n! distance T is calculated according to (see E.H. Vanmarcke, \"Random Fields:\r\n! Analysis and Synthesis\", MIT Press, 1984, Chapter 5).\r\n!\r\n! T\r\n! V(T) = (2/T) * INT (1-s/T)*r(s) ds,\r\n! 0\r\n!\r\n! where r(s) is the correlation function, r(s) = B(s)/B(0), so that\r\n! dlace1(T) = var * V(T).\r\n!\r\n! REVISION HISTORY:\r\n! 1.1\tadded lvarfn flag to end of /dparam/ common block. Set it to\r\n!\ttrue if the variance function is to be returned. Otherwise this\r\n!\tfunction returns the covariance. (Apr 29/00)\r\n! 1.2\teliminated lvarfn -- now return covariances only if var < 0 (Feb 27/01)\r\n! 1.3\treversed default - now return covariances if var > 0 (Apr 11/01)\r\n! 1.31\trevised above documentation to reflect revision 1.3 (May 9/01)\r\n! =======================================================================\r\n real*8 function dlace1( T )\r\n implicit real*8 (a-h,o-z)\r\n common/dparam/ var, dpb, dthx, dthy, dthz\r\n data zero/0.d0/, two/2.d0/\r\n abs(x) = dabs(x)\r\n cos(x) = dcos(x)\r\n sin(x) = dsin(x)\r\n exp(x) = dexp(x)\r\n\r\n if( var .lt. zero ) then\t\t\t! return variance function\r\n if( T .eq. zero ) then\r\n dlace1 = -var\r\n else\r\n ps = two/dthx\r\n s = ps*ps + dpb*dpb\r\n r = ps*ps - dpb*dpb\r\n a = -ps*abs(T)\r\n b = a*s + r\r\n c = dpb*abs(T)\r\n d = -two*var/(T*T*s*s)\r\n dlace1 = d*(exp(a)*(r*cos(c) - two*ps*dpb*sin(c)) - b)\r\n endif\r\n else\t\t\t\t\t! return covariance\r\n if( dthx .eq. zero ) then\r\n if( T .eq. zero ) then\r\n dlace1 = var\r\n else\r\n dlace1 = zero\r\n endif\r\n else\r\n dlace1 = var*cos(dpb*T)*exp( -two*abs(T)/dthx )\r\n endif\r\n endif\r\n\r\n return\r\n end\r\n", "meta": {"hexsha": "9ece2f90b29c43b174fe6db33b12a80fc4cde4fc", "size": 3140, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/libs/gaf95/dlace1.f95", "max_stars_repo_name": "leemargetts/PoreFEM", "max_stars_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/libs/gaf95/dlace1.f95", "max_issues_repo_name": "leemargetts/PoreFEM", "max_issues_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/libs/gaf95/dlace1.f95", "max_forks_repo_name": "leemargetts/PoreFEM", "max_forks_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.25, "max_line_length": 79, "alphanum_fraction": 0.4920382166, "num_tokens": 868, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543487, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6585103204259442}} {"text": " SUBROUTINE CFFTI1 (N,WA,IFAC)\n IMPLICIT NONE\n INTEGER :: N, IFAC(*), I, I1, IB, IDO, IDOT, II, IP, IPM, J, K1\n INTEGER :: L1, L2, LD, NF, NL, NQ, NR, NTRY, NTRYH(4)\n REAL :: WA(*), ARG, ARGH, ARGLD, FI, TPI\n DATA NTRYH(1),NTRYH(2),NTRYH(3),NTRYH(4)/3,4,2,5/\n NL = N\n NF = 0\n J = 0\n 101 J = J+1\n IF (J.le.4) GO TO 102\n GO TO 103\n 102 NTRY = NTRYH(J)\n GO TO 104\n 103 NTRY = NTRYH(4)+2*(J-4)\n 104 NQ = NL/NTRY\n NR = NL-NTRY*NQ\n IF (NR.eq.0) GO TO 105\n GO TO 101\n 105 NF = NF+1\n IFAC(NF+2) = NTRY\n NL = NQ\n IF (NTRY .NE. 2) GO TO 107\n IF (NF .EQ. 1) GO TO 107\n DO 106 I=2,NF\n IB = NF-I+2\n IFAC(IB+2) = IFAC(IB+1)\n 106 CONTINUE\n IFAC(3) = 2\n 107 IF (NL .NE. 1) GO TO 104\n IFAC(1) = N\n IFAC(2) = NF\n TPI = 6.28318530717959\n ARGH = TPI/FLOAT(N)\n I = 2\n L1 = 1\n DO 110 K1=1,NF\n IP = IFAC(K1+2)\n LD = 0\n L2 = L1*IP\n IDO = N/L2\n IDOT = IDO+IDO+2\n IPM = IP-1\n DO 109 J=1,IPM\n I1 = I\n WA(I-1) = 1.\n WA(I) = 0.\n LD = LD+L1\n FI = 0.\n ARGLD = FLOAT(LD)*ARGH\n DO 108 II=4,IDOT,2\n I = I+2\n FI = FI+1.\n ARG = FI*ARGLD\n WA(I-1) = COS(ARG)\n WA(I) = SIN(ARG)\n 108 CONTINUE\n IF (IP .LE. 5) GO TO 109\n WA(I1-1) = WA(I-1)\n WA(I1) = WA(I)\n 109 CONTINUE\n L1 = L2\n 110 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "252a8c8a756c07f4c498b15f1f8041195bac42d9", "size": 1594, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "scipy/fftpack/src/fftpack/cffti1.f", "max_stars_repo_name": "magnusja/scipy", "max_stars_repo_head_hexsha": "c4a5a1f984e28840010f20a7e41caa21b8f41979", "max_stars_repo_licenses": ["FSFAP"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-10-17T20:28:42.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-15T17:33:01.000Z", "max_issues_repo_path": "scipy/fftpack/src/fftpack/cffti1.f", "max_issues_repo_name": "magnusja/scipy", "max_issues_repo_head_hexsha": "c4a5a1f984e28840010f20a7e41caa21b8f41979", "max_issues_repo_licenses": ["FSFAP"], "max_issues_count": 19, "max_issues_repo_issues_event_min_datetime": "2018-07-18T07:15:44.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-22T17:00:18.000Z", "max_forks_repo_path": "scipy/fftpack/src/fftpack/cffti1.f", "max_forks_repo_name": "magnusja/scipy", "max_forks_repo_head_hexsha": "c4a5a1f984e28840010f20a7e41caa21b8f41979", "max_forks_repo_licenses": ["FSFAP"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-06-11T18:18:21.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-05T08:47:40.000Z", "avg_line_length": 24.1515151515, "max_line_length": 69, "alphanum_fraction": 0.4115432873, "num_tokens": 680, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094145755218, "lm_q2_score": 0.7371581510799253, "lm_q1q2_score": 0.6585103163907822}} {"text": "!\n! CalculiX - A 3-dimensional finite element program\n! Copyright (C) 1998-2015 Guido Dhondt\n!\n! This program is free software; you can redistribute it and/or\n! modify it under the terms of the GNU General Public License as\n! published by the Free Software Foundation(version 2);\n! \n!\n! This program is distributed in the hope that it will be useful,\n! but WITHOUT ANY WARRANTY; without even the implied warranty of \n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \n! GNU General Public License for more details.\n!\n! You should have received a copy of the GNU General Public License\n! along with this program; if not, write to the Free Software\n! Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n!\n subroutine calceigenvalues(c,al)\n!\n! calculates the eigenvalues al of the symmetric 3x3 matrix c\n! the eigenvalues are sorted in increasing order\n!\n implicit none\n!\n integer idummy(3),three,kflag,i\n!\n real*8 c(3,3),al(3),v1,v2,v3,bb,cc,cm,cn,tt,pi\n! \n data kflag /1/\n data three /3/\n!\n! calculation of the eigenvalues of c\n! Simo & Hughes Computational Inelasticity p 244\n!\n pi=4.d0*datan(1.d0)\n!\n v1=c(1,1)+c(2,2)+c(3,3)\n v2=c(2,2)*c(3,3)+c(1,1)*c(3,3)+c(1,1)*c(2,2)-\n & (c(2,3)*c(2,3)+c(1,3)*c(1,3)+c(1,2)*c(1,2))\n v3=c(1,1)*(c(2,2)*c(3,3)-c(2,3)*c(2,3))\n & -c(1,2)*(c(1,2)*c(3,3)-c(1,3)*c(2,3))\n & +c(1,3)*(c(1,2)*c(2,3)-c(1,3)*c(2,2))\n!\n bb=v2-v1*v1/3.d0\n cc=-2.d0*v1**3/27.d0+v1*v2/3.d0-v3\n if(dabs(bb).le.1.d-10) then\n if(dabs(cc).gt.1.d-10) then\n al(1)=-cc**(1.d0/3.d0)\n else\n al(1)=0.d0\n endif\n al(2)=al(1)\n al(3)=al(1)\n else\n cm=2.d0*dsqrt(-bb/3.d0)\n cn=3.d0*cc/(cm*bb)\n if(dabs(cn).gt.1.d0) then\n if(cn.gt.1.d0) then\n cn=1.d0\n else\n cn=-1.d0\n endif\n endif\n tt=datan2(dsqrt(1.d0-cn*cn),cn)/3.d0\n al(1)=cm*dcos(tt)\n al(2)=cm*dcos(tt+2.d0*pi/3.d0)\n al(3)=cm*dcos(tt+4.d0*pi/3.d0)\n endif\n do i=1,3\n al(i)=al(i)+v1/3.d0\n enddo\n! \n! sorting\n! \n call dsort(al,idummy,three,kflag)\n!\n return\n end\n", "meta": {"hexsha": "ff8a2185450c7eff4f6a62760b6b0c631e455ed7", "size": 2333, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ccx_prool/CalculiX/ccx_2.9/src/calceigenvalues.f", "max_stars_repo_name": "alleindrach/calculix-desktop", "max_stars_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ccx_prool/CalculiX/ccx_2.9/src/calceigenvalues.f", "max_issues_repo_name": "alleindrach/calculix-desktop", "max_issues_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2017-09-21T17:03:55.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-25T16:08:31.000Z", "max_forks_repo_path": "ccx_prool/CalculiX/ccx_2.9/src/calceigenvalues.f", "max_forks_repo_name": "alleindrach/calculix-desktop", "max_forks_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-08-29T18:41:28.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-29T18:41:28.000Z", "avg_line_length": 29.1625, "max_line_length": 71, "alphanum_fraction": 0.5417916845, "num_tokens": 860, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.7371581510799253, "lm_q1q2_score": 0.658510305921695}} {"text": " SUBROUTINE DOP853(N,FCN,X,Y,XEND,\n & RTOL,ATOL,ITOL,\n & SOLOUT,IOUT,\n & WORK,LWORK,IWORK,LIWORK,RPAR,IPAR,IDID)\nC ----------------------------------------------------------\nC NUMERICAL SOLUTION OF A SYSTEM OF FIRST 0RDER\nC ORDINARY DIFFERENTIAL EQUATIONS Y'=F(X,Y).\nC THIS IS AN EXPLICIT RUNGE-KUTTA METHOD OF ORDER 8(5,3) \nC DUE TO DORMAND & PRINCE (WITH STEPSIZE CONTROL AND\nC DENSE OUTPUT)\nC\nC AUTHORS: E. HAIRER AND G. WANNER\nC UNIVERSITE DE GENEVE, DEPT. DE MATHEMATIQUES\nC CH-1211 GENEVE 24, SWITZERLAND \nC E-MAIL: Ernst.Hairer@math.unige.ch\nC Gerhard.Wanner@math.unige.ch\nC \nC THIS CODE IS DESCRIBED IN:\nC E. HAIRER, S.P. NORSETT AND G. WANNER, SOLVING ORDINARY\nC DIFFERENTIAL EQUATIONS I. NONSTIFF PROBLEMS. 2ND EDITION. \nC SPRINGER SERIES IN COMPUTATIONAL MATHEMATICS, \nC SPRINGER-VERLAG (1993)\nC \nC VERSION OF APRIL 25, 1996\nC (latest correction of a small bug: August 8, 2005)\nC\nC Edited (22 Feb 2009) by J.C. Travers:\nC renamed HINIT->HINIT853 to avoid name collision with dopri5\nC\nC INPUT PARAMETERS \nC ---------------- \nC N DIMENSION OF THE SYSTEM \nC\nC FCN NAME (EXTERNAL) OF SUBROUTINE COMPUTING THE\nC VALUE OF F(X,Y):\nC SUBROUTINE FCN(N,X,Y,F,RPAR,IPAR)\nC DOUBLE PRECISION X,Y(N),F(N)\nC F(1)=... ETC.\nC\nC X INITIAL X-VALUE\nC\nC Y(N) INITIAL VALUES FOR Y\nC\nC XEND FINAL X-VALUE (XEND-X MAY BE POSITIVE OR NEGATIVE)\nC\nC RTOL,ATOL RELATIVE AND ABSOLUTE ERROR TOLERANCES. THEY\nC CAN BE BOTH SCALARS OR ELSE BOTH VECTORS OF LENGTH N.\nC ATOL SHOULD BE STRICTLY POSITIVE (POSSIBLY VERY SMALL)\nC\nC ITOL SWITCH FOR RTOL AND ATOL:\nC ITOL=0: BOTH RTOL AND ATOL ARE SCALARS.\nC THE CODE KEEPS, ROUGHLY, THE LOCAL ERROR OF\nC Y(I) BELOW RTOL*ABS(Y(I))+ATOL\nC ITOL=1: BOTH RTOL AND ATOL ARE VECTORS.\nC THE CODE KEEPS THE LOCAL ERROR OF Y(I) BELOW\nC RTOL(I)*ABS(Y(I))+ATOL(I).\nC\nC SOLOUT NAME (EXTERNAL) OF SUBROUTINE PROVIDING THE\nC NUMERICAL SOLUTION DURING INTEGRATION. \nC IF IOUT.GE.1, IT IS CALLED AFTER EVERY SUCCESSFUL STEP.\nC SUPPLY A DUMMY SUBROUTINE IF IOUT=0. \nC IT MUST HAVE THE FORM\nC SUBROUTINE SOLOUT (NR,XOLD,X,Y,N,CON,ICOMP,ND,\nC RPAR,IPAR,IRTRN)\nC DIMENSION Y(N),CON(8*ND),ICOMP(ND)\nC .... \nC SOLOUT FURNISHES THE SOLUTION \"Y\" AT THE NR-TH\nC GRID-POINT \"X\" (THEREBY THE INITIAL VALUE IS\nC THE FIRST GRID-POINT).\nC \"XOLD\" IS THE PRECEDING GRID-POINT.\nC \"IRTRN\" SERVES TO INTERRUPT THE INTEGRATION. IF IRTRN\nC IS SET <0, DOP853 WILL RETURN TO THE CALLING PROGRAM.\nC IF THE NUMERICAL SOLUTION IS ALTERED IN SOLOUT,\nC SET IRTRN = 2\nC \nC ----- CONTINUOUS OUTPUT: -----\nC DURING CALLS TO \"SOLOUT\", A CONTINUOUS SOLUTION\nC FOR THE INTERVAL [XOLD,X] IS AVAILABLE THROUGH\nC THE FUNCTION\nC >>> CONTD8(I,S,CON,ICOMP,ND) <<<\nC WHICH PROVIDES AN APPROXIMATION TO THE I-TH\nC COMPONENT OF THE SOLUTION AT THE POINT S. THE VALUE\nC S SHOULD LIE IN THE INTERVAL [XOLD,X].\nC \nC IOUT SWITCH FOR CALLING THE SUBROUTINE SOLOUT:\nC IOUT=0: SUBROUTINE IS NEVER CALLED\nC IOUT=1: SUBROUTINE IS USED FOR OUTPUT\nC IOUT=2: DENSE OUTPUT IS PERFORMED IN SOLOUT\nC (IN THIS CASE WORK(5) MUST BE SPECIFIED)\nC\nC WORK ARRAY OF WORKING SPACE OF LENGTH \"LWORK\".\nC WORK(1),...,WORK(20) SERVE AS PARAMETERS FOR THE CODE.\nC FOR STANDARD USE, SET THEM TO ZERO BEFORE CALLING.\nC \"LWORK\" MUST BE AT LEAST 11*N+8*NRDENS+21\nC WHERE NRDENS = IWORK(5)\nC\nC LWORK DECLARED LENGTH OF ARRAY \"WORK\".\nC\nC IWORK INTEGER WORKING SPACE OF LENGTH \"LIWORK\".\nC IWORK(1),...,IWORK(20) SERVE AS PARAMETERS FOR THE CODE.\nC FOR STANDARD USE, SET THEM TO ZERO BEFORE CALLING.\nC \"LIWORK\" MUST BE AT LEAST NRDENS+21 .\nC\nC LIWORK DECLARED LENGTH OF ARRAY \"IWORK\".\nC\nC RPAR, IPAR REAL AND INTEGER PARAMETERS (OR PARAMETER ARRAYS) WHICH \nC CAN BE USED FOR COMMUNICATION BETWEEN YOUR CALLING\nC PROGRAM AND THE FCN, JAC, MAS, SOLOUT SUBROUTINES. \nC\nC-----------------------------------------------------------------------\nC \nC SOPHISTICATED SETTING OF PARAMETERS\nC -----------------------------------\nC SEVERAL PARAMETERS (WORK(1),...,IWORK(1),...) ALLOW\nC TO ADAPT THE CODE TO THE PROBLEM AND TO THE NEEDS OF\nC THE USER. FOR ZERO INPUT, THE CODE CHOOSES DEFAULT VALUES.\nC\nC WORK(1) UROUND, THE ROUNDING UNIT, DEFAULT 2.3D-16.\nC\nC WORK(2) THE SAFETY FACTOR IN STEP SIZE PREDICTION,\nC DEFAULT 0.9D0.\nC\nC WORK(3), WORK(4) PARAMETERS FOR STEP SIZE SELECTION\nC THE NEW STEP SIZE IS CHOSEN SUBJECT TO THE RESTRICTION\nC WORK(3) <= HNEW/HOLD <= WORK(4)\nC DEFAULT VALUES: WORK(3)=0.333D0, WORK(4)=6.D0\nC\nC WORK(5) IS THE \"BETA\" FOR STABILIZED STEP SIZE CONTROL\nC (SEE SECTION IV.2). POSITIVE VALUES OF BETA ( <= 0.04 )\nC MAKE THE STEP SIZE CONTROL MORE STABLE.\nC NEGATIVE WORK(5) PROVOKE BETA=0.\nC DEFAULT 0.0D0.\nC\nC WORK(6) MAXIMAL STEP SIZE, DEFAULT XEND-X.\nC\nC WORK(7) INITIAL STEP SIZE, FOR WORK(7)=0.D0 AN INITIAL GUESS\nC IS COMPUTED WITH HELP OF THE FUNCTION HINIT\nC\nC IWORK(1) THIS IS THE MAXIMAL NUMBER OF ALLOWED STEPS.\nC THE DEFAULT VALUE (FOR IWORK(1)=0) IS 100000.\nC\nC IWORK(2) SWITCH FOR THE CHOICE OF THE COEFFICIENTS\nC IF IWORK(2).EQ.1 METHOD DOP853 OF DORMAND AND PRINCE\nC (SECTION II.6).\nC THE DEFAULT VALUE (FOR IWORK(2)=0) IS IWORK(2)=1.\nC\nC IWORK(3) SWITCH FOR PRINTING ERROR MESSAGES\nC IF IWORK(3).LT.0 NO MESSAGES ARE BEING PRINTED\nC IF IWORK(3).GT.0 MESSAGES ARE PRINTED WITH\nC WRITE (IWORK(3),*) ... \nC DEFAULT VALUE (FOR IWORK(3)=0) IS IWORK(3)=6\nC\nC IWORK(4) TEST FOR STIFFNESS IS ACTIVATED AFTER STEP NUMBER\nC J*IWORK(4) (J INTEGER), PROVIDED IWORK(4).GT.0.\nC FOR NEGATIVE IWORK(4) THE STIFFNESS TEST IS\nC NEVER ACTIVATED; DEFAULT VALUE IS IWORK(4)=1000\nC\nC IWORK(5) = NRDENS = NUMBER OF COMPONENTS, FOR WHICH DENSE OUTPUT\nC IS REQUIRED; DEFAULT VALUE IS IWORK(5)=0;\nC FOR 0 < NRDENS < N THE COMPONENTS (FOR WHICH DENSE\nC OUTPUT IS REQUIRED) HAVE TO BE SPECIFIED IN\nC IWORK(21),...,IWORK(NRDENS+20);\nC FOR NRDENS=N THIS IS DONE BY THE CODE.\nC\nC----------------------------------------------------------------------\nC\nC OUTPUT PARAMETERS \nC ----------------- \nC X X-VALUE FOR WHICH THE SOLUTION HAS BEEN COMPUTED\nC (AFTER SUCCESSFUL RETURN X=XEND).\nC\nC Y(N) NUMERICAL SOLUTION AT X\nC \nC H PREDICTED STEP SIZE OF THE LAST ACCEPTED STEP\nC\nC IDID REPORTS ON SUCCESSFULNESS UPON RETURN:\nC IDID= 1 COMPUTATION SUCCESSFUL,\nC IDID= 2 COMPUT. SUCCESSFUL (INTERRUPTED BY SOLOUT)\nC IDID=-1 INPUT IS NOT CONSISTENT,\nC IDID=-2 LARGER NMAX IS NEEDED,\nC IDID=-3 STEP SIZE BECOMES TOO SMALL.\nC IDID=-4 PROBLEM IS PROBABLY STIFF (INTERRUPTED).\nC\nC IWORK(17) NFCN NUMBER OF FUNCTION EVALUATIONS\nC IWORK(18) NSTEP NUMBER OF COMPUTED STEPS\nC IWORK(19) NACCPT NUMBER OF ACCEPTED STEPS\nC IWORK(20) NREJCT NUMBER OF REJECTED STEPS (DUE TO ERROR TEST),\nC (STEP REJECTIONS IN THE FIRST STEP ARE NOT COUNTED)\nC-----------------------------------------------------------------------\nC *** *** *** *** *** *** *** *** *** *** *** *** ***\nC DECLARATIONS \nC *** *** *** *** *** *** *** *** *** *** *** *** ***\n IMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION Y(N),ATOL(*),RTOL(*),WORK(LWORK),IWORK(LIWORK)\n DIMENSION RPAR(*),IPAR(*)\n LOGICAL ARRET\n EXTERNAL FCN,SOLOUT\nC *** *** *** *** *** *** ***\nC SETTING THE PARAMETERS \nC *** *** *** *** *** *** ***\n NFCN=0\n NSTEP=0\n NACCPT=0\n NREJCT=0\n ARRET=.FALSE.\nC -------- IPRINT FOR MONITORING THE PRINTING\n IF(IWORK(3).EQ.0)THEN\n IPRINT=6\n ELSE\n IPRINT=IWORK(3)\n END IF\nC -------- NMAX , THE MAXIMAL NUMBER OF STEPS ----- \n IF(IWORK(1).EQ.0)THEN\n NMAX=100000\n ELSE\n NMAX=IWORK(1)\n IF(NMAX.LE.0)THEN\n IF (IPRINT.GT.0) WRITE(IPRINT,*)\n & ' WRONG INPUT IWORK(1)=',IWORK(1)\n ARRET=.TRUE.\n END IF\n END IF\nC -------- METH COEFFICIENTS OF THE METHOD\n IF(IWORK(2).EQ.0)THEN\n METH=1\n ELSE\n METH=IWORK(2)\n IF(METH.LE.0.OR.METH.GE.4)THEN\n IF (IPRINT.GT.0) WRITE(IPRINT,*)\n & ' CURIOUS INPUT IWORK(2)=',IWORK(2)\n ARRET=.TRUE.\n END IF\n END IF \nC -------- NSTIFF PARAMETER FOR STIFFNESS DETECTION \n NSTIFF=IWORK(4) \n IF (NSTIFF.EQ.0) NSTIFF=1000\n IF (NSTIFF.LT.0) NSTIFF=NMAX+10\nC -------- NRDENS NUMBER OF DENSE OUTPUT COMPONENTS\n NRDENS=IWORK(5)\n IF(NRDENS.LT.0.OR.NRDENS.GT.N)THEN\n IF (IPRINT.GT.0) WRITE(IPRINT,*)\n & ' CURIOUS INPUT IWORK(5)=',IWORK(5)\n ARRET=.TRUE.\n ELSE\n IF(NRDENS.GT.0.AND.IOUT.LT.2)THEN\n IF (IPRINT.GT.0) WRITE(IPRINT,*)\n & ' WARNING: PUT IOUT=2 FOR DENSE OUTPUT '\n END IF \n IF (NRDENS.EQ.N) THEN\n DO I=1,NRDENS\n IWORK(I+20)=I\n END DO\n END IF\n END IF \nC -------- UROUND SMALLEST NUMBER SATISFYING 1.D0+UROUND>1.D0 \n IF(WORK(1).EQ.0.D0)THEN\n UROUND=2.3D-16\n ELSE\n UROUND=WORK(1)\n IF(UROUND.LE.1.D-35.OR.UROUND.GE.1.D0)THEN\n IF (IPRINT.GT.0) WRITE(IPRINT,*)\n & ' WHICH MACHINE DO YOU HAVE? YOUR UROUND WAS:',WORK(1)\n ARRET=.TRUE.\n END IF\n END IF\nC ------- SAFETY FACTOR -------------\n IF(WORK(2).EQ.0.D0)THEN\n SAFE=0.9D0\n ELSE\n SAFE=WORK(2)\n IF(SAFE.GE.1.D0.OR.SAFE.LE.1.D-4)THEN\n IF (IPRINT.GT.0) WRITE(IPRINT,*)\n & ' CURIOUS INPUT FOR SAFETY FACTOR WORK(2)=',WORK(2)\n ARRET=.TRUE.\n END IF\n END IF\nC ------- FAC1,FAC2 PARAMETERS FOR STEP SIZE SELECTION\n IF(WORK(3).EQ.0.D0)THEN\n FAC1=0.333D0\n ELSE\n FAC1=WORK(3)\n END IF\n IF(WORK(4).EQ.0.D0)THEN\n FAC2=6.D0\n ELSE\n FAC2=WORK(4)\n END IF\nC --------- BETA FOR STEP CONTROL STABILIZATION -----------\n IF(WORK(5).EQ.0.D0)THEN\n BETA=0.0D0\n ELSE\n IF(WORK(5).LT.0.D0)THEN\n BETA=0.D0\n ELSE\n BETA=WORK(5)\n IF(BETA.GT.0.2D0)THEN\n IF (IPRINT.GT.0) WRITE(IPRINT,*)\n & ' CURIOUS INPUT FOR BETA: WORK(5)=',WORK(5)\n ARRET=.TRUE.\n END IF\n END IF\n END IF\nC -------- MAXIMAL STEP SIZE\n IF(WORK(6).EQ.0.D0)THEN\n HMAX=XEND-X\n ELSE\n HMAX=WORK(6)\n END IF\nC -------- INITIAL STEP SIZE\n H=WORK(7)\nC ------- PREPARE THE ENTRY-POINTS FOR THE ARRAYS IN WORK -----\n IEK1=21\n IEK2=IEK1+N\n IEK3=IEK2+N\n IEK4=IEK3+N\n IEK5=IEK4+N\n IEK6=IEK5+N\n IEK7=IEK6+N\n IEK8=IEK7+N\n IEK9=IEK8+N\n IEK10=IEK9+N\n IEY1=IEK10+N\n IECO=IEY1+N\nC ------ TOTAL STORAGE REQUIREMENT -----------\n ISTORE=IECO+8*NRDENS-1\n IF(ISTORE.GT.LWORK)THEN\n IF (IPRINT.GT.0) WRITE(IPRINT,*)\n & ' INSUFFICIENT STORAGE FOR WORK, MIN. LWORK=',ISTORE\n ARRET=.TRUE.\n END IF\n ICOMP=21\n ISTORE=ICOMP+NRDENS-1\n IF(ISTORE.GT.LIWORK)THEN\n IF (IPRINT.GT.0) WRITE(IPRINT,*)\n & ' INSUFFICIENT STORAGE FOR IWORK, MIN. LIWORK=',ISTORE\n ARRET=.TRUE.\n END IF\nC -------- WHEN A FAIL HAS OCCURRED, WE RETURN WITH IDID=-1\n IF (ARRET) THEN\n IDID=-1\n RETURN\n END IF\nC -------- CALL TO CORE INTEGRATOR ------------\n CALL DP86CO(N,FCN,X,Y,XEND,HMAX,H,RTOL,ATOL,ITOL,IPRINT,\n & SOLOUT,IOUT,IDID,NMAX,UROUND,METH,NSTIFF,SAFE,BETA,FAC1,FAC2,\n & WORK(IEK1),WORK(IEK2),WORK(IEK3),WORK(IEK4),WORK(IEK5),\n & WORK(IEK6),WORK(IEK7),WORK(IEK8),WORK(IEK9),WORK(IEK10),\n & WORK(IEY1),WORK(IECO),IWORK(ICOMP),NRDENS,RPAR,IPAR,\n & NFCN,NSTEP,NACCPT,NREJCT)\n WORK(7)=H\n IWORK(17)=NFCN\n IWORK(18)=NSTEP\n IWORK(19)=NACCPT\n IWORK(20)=NREJCT\nC ----------- RETURN -----------\n RETURN\n END\nC\nC\nC\nC ----- ... AND HERE IS THE CORE INTEGRATOR ----------\nC\n SUBROUTINE DP86CO(N,FCN,X,Y,XEND,HMAX,H,RTOL,ATOL,ITOL,IPRINT,\n & SOLOUT,IOUT,IDID,NMAX,UROUND,METH,NSTIFF,SAFE,BETA,FAC1,FAC2,\n & K1,K2,K3,K4,K5,K6,K7,K8,K9,K10,Y1,CONT,ICOMP,NRD,RPAR,IPAR,\n & NFCN,NSTEP,NACCPT,NREJCT)\nC ----------------------------------------------------------\nC CORE INTEGRATOR FOR DOP853\nC PARAMETERS SAME AS IN DOP853 WITH WORKSPACE ADDED \nC ---------------------------------------------------------- \nC DECLARATIONS \nC ---------------------------------------------------------- \n IMPLICIT DOUBLE PRECISION (A-H,O-Z)\n parameter (\n & c2 = 0.526001519587677318785587544488D-01,\n & c3 = 0.789002279381515978178381316732D-01,\n & c4 = 0.118350341907227396726757197510D+00,\n & c5 = 0.281649658092772603273242802490D+00,\n & c6 = 0.333333333333333333333333333333D+00,\n & c7 = 0.25D+00,\n & c8 = 0.307692307692307692307692307692D+00,\n & c9 = 0.651282051282051282051282051282D+00,\n & c10 = 0.6D+00,\n & c11 = 0.857142857142857142857142857142D+00,\n & c14 = 0.1D+00,\n & c15 = 0.2D+00,\n & c16 = 0.777777777777777777777777777778D+00)\n parameter (\n & b1 = 5.42937341165687622380535766363D-2,\n & b6 = 4.45031289275240888144113950566D0,\n & b7 = 1.89151789931450038304281599044D0,\n & b8 = -5.8012039600105847814672114227D0,\n & b9 = 3.1116436695781989440891606237D-1,\n & b10 = -1.52160949662516078556178806805D-1,\n & b11 = 2.01365400804030348374776537501D-1,\n & b12 = 4.47106157277725905176885569043D-2)\n parameter (\n & bhh1 = 0.244094488188976377952755905512D+00,\n & bhh2 = 0.733846688281611857341361741547D+00,\n & bhh3 = 0.220588235294117647058823529412D-01)\n parameter (\n & er 1 = 0.1312004499419488073250102996D-01,\n & er 6 = -0.1225156446376204440720569753D+01,\n & er 7 = -0.4957589496572501915214079952D+00,\n & er 8 = 0.1664377182454986536961530415D+01,\n & er 9 = -0.3503288487499736816886487290D+00,\n & er10 = 0.3341791187130174790297318841D+00,\n & er11 = 0.8192320648511571246570742613D-01,\n & er12 = -0.2235530786388629525884427845D-01)\n parameter (\n & a21 = 5.26001519587677318785587544488D-2,\n & a31 = 1.97250569845378994544595329183D-2,\n & a32 = 5.91751709536136983633785987549D-2,\n & a41 = 2.95875854768068491816892993775D-2,\n & a43 = 8.87627564304205475450678981324D-2,\n & a51 = 2.41365134159266685502369798665D-1,\n & a53 = -8.84549479328286085344864962717D-1,\n & a54 = 9.24834003261792003115737966543D-1,\n & a61 = 3.7037037037037037037037037037D-2,\n & a64 = 1.70828608729473871279604482173D-1,\n & a65 = 1.25467687566822425016691814123D-1,\n & a71 = 3.7109375D-2,\n & a74 = 1.70252211019544039314978060272D-1,\n & a75 = 6.02165389804559606850219397283D-2,\n & a76 = -1.7578125D-2)\n parameter (\n & a81 = 3.70920001185047927108779319836D-2,\n & a84 = 1.70383925712239993810214054705D-1,\n & a85 = 1.07262030446373284651809199168D-1,\n & a86 = -1.53194377486244017527936158236D-2,\n & a87 = 8.27378916381402288758473766002D-3,\n & a91 = 6.24110958716075717114429577812D-1,\n & a94 = -3.36089262944694129406857109825D0,\n & a95 = -8.68219346841726006818189891453D-1,\n & a96 = 2.75920996994467083049415600797D1,\n & a97 = 2.01540675504778934086186788979D1,\n & a98 = -4.34898841810699588477366255144D1,\n & a101 = 4.77662536438264365890433908527D-1,\n & a104 = -2.48811461997166764192642586468D0,\n & a105 = -5.90290826836842996371446475743D-1,\n & a106 = 2.12300514481811942347288949897D1,\n & a107 = 1.52792336328824235832596922938D1,\n & a108 = -3.32882109689848629194453265587D1,\n & a109 = -2.03312017085086261358222928593D-2)\n parameter (\n & a111 = -9.3714243008598732571704021658D-1,\n & a114 = 5.18637242884406370830023853209D0,\n & a115 = 1.09143734899672957818500254654D0,\n & a116 = -8.14978701074692612513997267357D0,\n & a117 = -1.85200656599969598641566180701D1,\n & a118 = 2.27394870993505042818970056734D1,\n & a119 = 2.49360555267965238987089396762D0,\n & a1110 = -3.0467644718982195003823669022D0,\n & a121 = 2.27331014751653820792359768449D0,\n & a124 = -1.05344954667372501984066689879D1,\n & a125 = -2.00087205822486249909675718444D0,\n & a126 = -1.79589318631187989172765950534D1,\n & a127 = 2.79488845294199600508499808837D1,\n & a128 = -2.85899827713502369474065508674D0,\n & a129 = -8.87285693353062954433549289258D0,\n & a1210 = 1.23605671757943030647266201528D1,\n & a1211 = 6.43392746015763530355970484046D-1)\n parameter (\n & a141 = 5.61675022830479523392909219681D-2,\n & a147 = 2.53500210216624811088794765333D-1,\n & a148 = -2.46239037470802489917441475441D-1,\n & a149 = -1.24191423263816360469010140626D-1,\n & a1410 = 1.5329179827876569731206322685D-1,\n & a1411 = 8.20105229563468988491666602057D-3,\n & a1412 = 7.56789766054569976138603589584D-3,\n & a1413 = -8.298D-3)\n parameter (\n & a151 = 3.18346481635021405060768473261D-2,\n & a156 = 2.83009096723667755288322961402D-2,\n & a157 = 5.35419883074385676223797384372D-2,\n & a158 = -5.49237485713909884646569340306D-2,\n & a1511 = -1.08347328697249322858509316994D-4,\n & a1512 = 3.82571090835658412954920192323D-4,\n & a1513 = -3.40465008687404560802977114492D-4,\n & a1514 = 1.41312443674632500278074618366D-1,\n & a161 = -4.28896301583791923408573538692D-1,\n & a166 = -4.69762141536116384314449447206D0,\n & a167 = 7.68342119606259904184240953878D0,\n & a168 = 4.06898981839711007970213554331D0,\n & a169 = 3.56727187455281109270669543021D-1,\n & a1613 = -1.39902416515901462129418009734D-3,\n & a1614 = 2.9475147891527723389556272149D0,\n & a1615 = -9.15095847217987001081870187138D0)\n parameter (\n & d41 = -0.84289382761090128651353491142D+01,\n & d46 = 0.56671495351937776962531783590D+00,\n & d47 = -0.30689499459498916912797304727D+01,\n & d48 = 0.23846676565120698287728149680D+01,\n & d49 = 0.21170345824450282767155149946D+01,\n & d410 = -0.87139158377797299206789907490D+00,\n & d411 = 0.22404374302607882758541771650D+01,\n & d412 = 0.63157877876946881815570249290D+00,\n & d413 = -0.88990336451333310820698117400D-01,\n & d414 = 0.18148505520854727256656404962D+02,\n & d415 = -0.91946323924783554000451984436D+01,\n & d416 = -0.44360363875948939664310572000D+01)\n parameter (\n & d51 = 0.10427508642579134603413151009D+02,\n & d56 = 0.24228349177525818288430175319D+03,\n & d57 = 0.16520045171727028198505394887D+03,\n & d58 = -0.37454675472269020279518312152D+03,\n & d59 = -0.22113666853125306036270938578D+02,\n & d510 = 0.77334326684722638389603898808D+01,\n & d511 = -0.30674084731089398182061213626D+02,\n & d512 = -0.93321305264302278729567221706D+01,\n & d513 = 0.15697238121770843886131091075D+02,\n & d514 = -0.31139403219565177677282850411D+02,\n & d515 = -0.93529243588444783865713862664D+01,\n & d516 = 0.35816841486394083752465898540D+02)\n parameter (\n & d61 = 0.19985053242002433820987653617D+02,\n & d66 = -0.38703730874935176555105901742D+03,\n & d67 = -0.18917813819516756882830838328D+03,\n & d68 = 0.52780815920542364900561016686D+03,\n & d69 = -0.11573902539959630126141871134D+02,\n & d610 = 0.68812326946963000169666922661D+01,\n & d611 = -0.10006050966910838403183860980D+01,\n & d612 = 0.77771377980534432092869265740D+00,\n & d613 = -0.27782057523535084065932004339D+01,\n & d614 = -0.60196695231264120758267380846D+02,\n & d615 = 0.84320405506677161018159903784D+02,\n & d616 = 0.11992291136182789328035130030D+02)\n parameter (\n & d71 = -0.25693933462703749003312586129D+02,\n & d76 = -0.15418974869023643374053993627D+03,\n & d77 = -0.23152937917604549567536039109D+03,\n & d78 = 0.35763911791061412378285349910D+03,\n & d79 = 0.93405324183624310003907691704D+02,\n & d710 = -0.37458323136451633156875139351D+02,\n & d711 = 0.10409964950896230045147246184D+03,\n & d712 = 0.29840293426660503123344363579D+02,\n & d713 = -0.43533456590011143754432175058D+02,\n & d714 = 0.96324553959188282948394950600D+02,\n & d715 = -0.39177261675615439165231486172D+02,\n & d716 = -0.14972683625798562581422125276D+03)\n DOUBLE PRECISION Y(N),Y1(N),K1(N),K2(N),K3(N),K4(N),K5(N),K6(N)\n DOUBLE PRECISION K7(N),K8(N),K9(N),K10(N),ATOL(*),RTOL(*) \n DIMENSION CONT(8*NRD),ICOMP(NRD),RPAR(*),IPAR(*)\n LOGICAL REJECT,LAST \n EXTERNAL FCN\n COMMON /CONDO8/XOLD,HOUT\nC *** *** *** *** *** *** ***\nC INITIALISATIONS\nC *** *** *** *** *** *** *** \n FACOLD=1.D-4 \n EXPO1=1.d0/8.d0-BETA*0.2D0\n FACC1=1.D0/FAC1\n FACC2=1.D0/FAC2\n POSNEG=SIGN(1.D0,XEND-X) \nC --- INITIAL PREPARATIONS \n ATOLI=ATOL(1)\n RTOLI=RTOL(1) \n LAST=.FALSE. \n HLAMB=0.D0\n IASTI=0\n CALL FCN(N,X,Y,K1,RPAR,IPAR)\n HMAX=ABS(HMAX) \n IORD=8 \n IF (H.EQ.0.D0) H=HINIT853(N,FCN,X,Y,XEND,POSNEG,K1,K2,K3,IORD,\n & HMAX,ATOL,RTOL,ITOL,RPAR,IPAR)\n NFCN=NFCN+2\n REJECT=.FALSE.\n XOLD=X\n IF (IOUT.GE.1) THEN \n IRTRN=1 \n HOUT=1.D0\n CALL SOLOUT(NACCPT+1,XOLD,X,Y,N,CONT,ICOMP,NRD,\n & RPAR,IPAR,IRTRN)\n IF (IRTRN.LT.0) GOTO 79\n END IF\nC --- BASIC INTEGRATION STEP \n 1 CONTINUE\n IF (NSTEP.GT.NMAX) GOTO 78\n IF (0.1D0*ABS(H).LE.ABS(X)*UROUND)GOTO 77\n IF ((X+1.01D0*H-XEND)*POSNEG.GT.0.D0) THEN\n H=XEND-X \n LAST=.TRUE.\n END IF\n NSTEP=NSTEP+1\nC --- THE TWELVE STAGES\n IF (IRTRN.GE.2) THEN\n CALL FCN(N,X,Y,K1,RPAR,IPAR)\n END IF\n DO 22 I=1,N \n 22 Y1(I)=Y(I)+H*A21*K1(I) \n CALL FCN(N,X+C2*H,Y1,K2,RPAR,IPAR)\n DO 23 I=1,N \n 23 Y1(I)=Y(I)+H*(A31*K1(I)+A32*K2(I)) \n CALL FCN(N,X+C3*H,Y1,K3,RPAR,IPAR)\n DO 24 I=1,N \n 24 Y1(I)=Y(I)+H*(A41*K1(I)+A43*K3(I)) \n CALL FCN(N,X+C4*H,Y1,K4,RPAR,IPAR)\n DO 25 I=1,N \n 25 Y1(I)=Y(I)+H*(A51*K1(I)+A53*K3(I)+A54*K4(I))\n CALL FCN(N,X+C5*H,Y1,K5,RPAR,IPAR)\n DO 26 I=1,N \n 26 Y1(I)=Y(I)+H*(A61*K1(I)+A64*K4(I)+A65*K5(I))\n CALL FCN(N,X+C6*H,Y1,K6,RPAR,IPAR)\n DO 27 I=1,N \n 27 Y1(I)=Y(I)+H*(A71*K1(I)+A74*K4(I)+A75*K5(I)+A76*K6(I))\n CALL FCN(N,X+C7*H,Y1,K7,RPAR,IPAR)\n DO 28 I=1,N \n 28 Y1(I)=Y(I)+H*(A81*K1(I)+A84*K4(I)+A85*K5(I)+A86*K6(I)+A87*K7(I)) \n CALL FCN(N,X+C8*H,Y1,K8,RPAR,IPAR)\n DO 29 I=1,N \n 29 Y1(I)=Y(I)+H*(A91*K1(I)+A94*K4(I)+A95*K5(I)+A96*K6(I)+A97*K7(I)\n & +A98*K8(I))\n CALL FCN(N,X+C9*H,Y1,K9,RPAR,IPAR)\n DO 30 I=1,N \n 30 Y1(I)=Y(I)+H*(A101*K1(I)+A104*K4(I)+A105*K5(I)+A106*K6(I)\n & +A107*K7(I)+A108*K8(I)+A109*K9(I))\n CALL FCN(N,X+C10*H,Y1,K10,RPAR,IPAR)\n DO 31 I=1,N \n 31 Y1(I)=Y(I)+H*(A111*K1(I)+A114*K4(I)+A115*K5(I)+A116*K6(I)\n & +A117*K7(I)+A118*K8(I)+A119*K9(I)+A1110*K10(I))\n CALL FCN(N,X+C11*H,Y1,K2,RPAR,IPAR)\n XPH=X+H\n DO 32 I=1,N \n 32 Y1(I)=Y(I)+H*(A121*K1(I)+A124*K4(I)+A125*K5(I)+A126*K6(I)\n & +A127*K7(I)+A128*K8(I)+A129*K9(I)+A1210*K10(I)+A1211*K2(I))\n CALL FCN(N,XPH,Y1,K3,RPAR,IPAR)\n NFCN=NFCN+11\n DO 35 I=1,N \n K4(I)=B1*K1(I)+B6*K6(I)+B7*K7(I)+B8*K8(I)+B9*K9(I)\n & +B10*K10(I)+B11*K2(I)+B12*K3(I)\n 35 K5(I)=Y(I)+H*K4(I)\nC --- ERROR ESTIMATION \n ERR=0.D0\n ERR2=0.D0\n IF (ITOL.EQ.0) THEN \n DO 41 I=1,N \n SK=ATOLI+RTOLI*MAX(ABS(Y(I)),ABS(K5(I)))\n ERRI=K4(I)-BHH1*K1(I)-BHH2*K9(I)-BHH3*K3(I)\n ERR2=ERR2+(ERRI/SK)**2\n ERRI=ER1*K1(I)+ER6*K6(I)+ER7*K7(I)+ER8*K8(I)+ER9*K9(I)\n & +ER10*K10(I)+ER11*K2(I)+ER12*K3(I)\n 41 ERR=ERR+(ERRI/SK)**2\n ELSE\n DO 42 I=1,N \n SK=ATOL(I)+RTOL(I)*MAX(ABS(Y(I)),ABS(K5(I)))\n ERRI=K4(I)-BHH1*K1(I)-BHH2*K9(I)-BHH3*K3(I)\n ERR2=ERR2+(ERRI/SK)**2\n ERRI=ER1*K1(I)+ER6*K6(I)+ER7*K7(I)+ER8*K8(I)+ER9*K9(I)\n & +ER10*K10(I)+ER11*K2(I)+ER12*K3(I)\n 42 ERR=ERR+(ERRI/SK)**2\n END IF \n DENO=ERR+0.01D0*ERR2\n IF (DENO.LE.0.D0) DENO=1.D0\n ERR=ABS(H)*ERR*SQRT(1.D0/(N*DENO))\nC --- COMPUTATION OF HNEW\n FAC11=ERR**EXPO1\nC --- LUND-STABILIZATION\n FAC=FAC11/FACOLD**BETA\nC --- WE REQUIRE FAC1 <= HNEW/H <= FAC2\n FAC=MAX(FACC2,MIN(FACC1,FAC/SAFE))\n HNEW=H/FAC \n IF(ERR.LE.1.D0)THEN\nC --- STEP IS ACCEPTED \n FACOLD=MAX(ERR,1.0D-4)\n NACCPT=NACCPT+1\n CALL FCN(N,XPH,K5,K4,RPAR,IPAR)\n NFCN=NFCN+1\nC ------- STIFFNESS DETECTION\n IF (MOD(NACCPT,NSTIFF).EQ.0.OR.IASTI.GT.0) THEN\n STNUM=0.D0\n STDEN=0.D0\n DO 64 I=1,N \n STNUM=STNUM+(K4(I)-K3(I))**2\n STDEN=STDEN+(K5(I)-Y1(I))**2\n 64 CONTINUE \n IF (STDEN.GT.0.D0) HLAMB=ABS(H)*SQRT(STNUM/STDEN) \n IF (HLAMB.GT.6.1D0) THEN\n NONSTI=0\n IASTI=IASTI+1 \n IF (IASTI.EQ.15) THEN\n IF (IPRINT.GT.0) WRITE (IPRINT,*) \n & ' THE PROBLEM SEEMS TO BECOME STIFF AT X = ',X \n IF (IPRINT.LE.0) GOTO 76\n END IF\n ELSE\n NONSTI=NONSTI+1 \n IF (NONSTI.EQ.6) IASTI=0\n END IF\n END IF \nC ------- FINAL PREPARATION FOR DENSE OUTPUT\n IF (IOUT.GE.2) THEN\nC ---- SAVE THE FIRST FUNCTION EVALUATIONS \n DO 62 J=1,NRD\n I=ICOMP(J)\n CONT(J)=Y(I)\n YDIFF=K5(I)-Y(I)\n CONT(J+NRD)=YDIFF\n BSPL=H*K1(I)-YDIFF\n CONT(J+NRD*2)=BSPL\n CONT(J+NRD*3)=YDIFF-H*K4(I)-BSPL\n CONT(J+NRD*4)=D41*K1(I)+D46*K6(I)+D47*K7(I)+D48*K8(I)\n & +D49*K9(I)+D410*K10(I)+D411*K2(I)+D412*K3(I)\n CONT(J+NRD*5)=D51*K1(I)+D56*K6(I)+D57*K7(I)+D58*K8(I)\n & +D59*K9(I)+D510*K10(I)+D511*K2(I)+D512*K3(I)\n CONT(J+NRD*6)=D61*K1(I)+D66*K6(I)+D67*K7(I)+D68*K8(I)\n & +D69*K9(I)+D610*K10(I)+D611*K2(I)+D612*K3(I)\n CONT(J+NRD*7)=D71*K1(I)+D76*K6(I)+D77*K7(I)+D78*K8(I)\n & +D79*K9(I)+D710*K10(I)+D711*K2(I)+D712*K3(I)\n 62 CONTINUE \nC --- THE NEXT THREE FUNCTION EVALUATIONS\n DO 51 I=1,N \n 51 Y1(I)=Y(I)+H*(A141*K1(I)+A147*K7(I)+A148*K8(I)\n & +A149*K9(I)+A1410*K10(I)+A1411*K2(I)+A1412*K3(I)\n & +A1413*K4(I))\n CALL FCN(N,X+C14*H,Y1,K10,RPAR,IPAR)\n DO 52 I=1,N \n 52 Y1(I)=Y(I)+H*(A151*K1(I)+A156*K6(I)+A157*K7(I)\n & +A158*K8(I)+A1511*K2(I)+A1512*K3(I)+A1513*K4(I)\n & +A1514*K10(I))\n CALL FCN(N,X+C15*H,Y1,K2,RPAR,IPAR)\n DO 53 I=1,N \n 53 Y1(I)=Y(I)+H*(A161*K1(I)+A166*K6(I)+A167*K7(I)\n & +A168*K8(I)+A169*K9(I)+A1613*K4(I)+A1614*K10(I)\n & +A1615*K2(I))\n CALL FCN(N,X+C16*H,Y1,K3,RPAR,IPAR)\n NFCN=NFCN+3 \nC --- FINAL PREPARATION\n DO 63 J=1,NRD\n I=ICOMP(J)\n CONT(J+NRD*4)=H*(CONT(J+NRD*4)+D413*K4(I)+D414*K10(I)\n & +D415*K2(I)+D416*K3(I))\n CONT(J+NRD*5)=H*(CONT(J+NRD*5)+D513*K4(I)+D514*K10(I)\n & +D515*K2(I)+D516*K3(I))\n CONT(J+NRD*6)=H*(CONT(J+NRD*6)+D613*K4(I)+D614*K10(I)\n & +D615*K2(I)+D616*K3(I))\n CONT(J+NRD*7)=H*(CONT(J+NRD*7)+D713*K4(I)+D714*K10(I)\n & +D715*K2(I)+D716*K3(I))\n 63 CONTINUE\n HOUT=H\n END IF\n DO 67 I=1,N\n K1(I)=K4(I)\n 67 Y(I)=K5(I)\n XOLD=X\n X=XPH\n IF (IOUT.GE.1) THEN\n CALL SOLOUT(NACCPT+1,XOLD,X,Y,N,CONT,ICOMP,NRD,\n & RPAR,IPAR,IRTRN)\n IF (IRTRN.LT.0) GOTO 79\n END IF \nC ------- NORMAL EXIT\n IF (LAST) THEN\n H=HNEW\n IDID=1\n RETURN\n END IF\n IF(ABS(HNEW).GT.HMAX)HNEW=POSNEG*HMAX \n IF(REJECT)HNEW=POSNEG*MIN(ABS(HNEW),ABS(H))\n REJECT=.FALSE. \n ELSE \nC --- STEP IS REJECTED \n HNEW=H/MIN(FACC1,FAC11/SAFE)\n REJECT=.TRUE. \n IF(NACCPT.GE.1)NREJCT=NREJCT+1 \n LAST=.FALSE.\n END IF\n H=HNEW\n GOTO 1\nC --- FAIL EXIT\n 76 CONTINUE\n IDID=-4\n RETURN\n 77 CONTINUE\n IF (IPRINT.GT.0) WRITE(IPRINT,979)X \n IF (IPRINT.GT.0) WRITE(IPRINT,*)' STEP SIZE TOO SMALL, H=',H\n IDID=-3\n RETURN\n 78 CONTINUE\n IF (IPRINT.GT.0) WRITE(IPRINT,979)X \n IF (IPRINT.GT.0) WRITE(IPRINT,*)\n & ' MORE THAN NMAX =',NMAX,'STEPS ARE NEEDED' \n IDID=-2\n RETURN\n 79 CONTINUE\n IF (IPRINT.GT.0) WRITE(IPRINT,979)X\n 979 FORMAT(' EXIT OF DOP853 AT X=',E18.4) \n IDID=2\n RETURN\n END\nC\n FUNCTION HINIT853(N,FCN,X,Y,XEND,POSNEG,F0,F1,Y1,IORD,\n & HMAX,ATOL,RTOL,ITOL,RPAR,IPAR)\nC ----------------------------------------------------------\nC ---- COMPUTATION OF AN INITIAL STEP SIZE GUESS\nC ----------------------------------------------------------\n IMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION Y(N),Y1(N),F0(N),F1(N),ATOL(*),RTOL(*)\n DIMENSION RPAR(*),IPAR(*)\nC ---- COMPUTE A FIRST GUESS FOR EXPLICIT EULER AS\nC ---- H = 0.01 * NORM (Y0) / NORM (F0)\nC ---- THE INCREMENT FOR EXPLICIT EULER IS SMALL\nC ---- COMPARED TO THE SOLUTION\n DNF=0.0D0\n DNY=0.0D0 \n ATOLI=ATOL(1)\n RTOLI=RTOL(1) \n IF (ITOL.EQ.0) THEN \n DO 10 I=1,N \n SK=ATOLI+RTOLI*ABS(Y(I))\n DNF=DNF+(F0(I)/SK)**2\n 10 DNY=DNY+(Y(I)/SK)**2 \n ELSE\n DO 11 I=1,N \n SK=ATOL(I)+RTOL(I)*ABS(Y(I))\n DNF=DNF+(F0(I)/SK)**2\n 11 DNY=DNY+(Y(I)/SK)**2 \n END IF\n IF (DNF.LE.1.D-10.OR.DNY.LE.1.D-10) THEN\n H=1.0D-6\n ELSE\n H=SQRT(DNY/DNF)*0.01D0 \n END IF\n H=MIN(H,HMAX)\n H=SIGN(H,POSNEG) \nC ---- PERFORM AN EXPLICIT EULER STEP\n DO 12 I=1,N\n 12 Y1(I)=Y(I)+H*F0(I)\n CALL FCN(N,X+H,Y1,F1,RPAR,IPAR) \nC ---- ESTIMATE THE SECOND DERIVATIVE OF THE SOLUTION\n DER2=0.0D0\n IF (ITOL.EQ.0) THEN \n DO 15 I=1,N \n SK=ATOLI+RTOLI*ABS(Y(I))\n 15 DER2=DER2+((F1(I)-F0(I))/SK)**2 \n ELSE\n DO 16 I=1,N \n SK=ATOL(I)+RTOL(I)*ABS(Y(I))\n 16 DER2=DER2+((F1(I)-F0(I))/SK)**2 \n END IF\n DER2=SQRT(DER2)/H\nC ---- STEP SIZE IS COMPUTED SUCH THAT\nC ---- H**IORD * MAX ( NORM (F0), NORM (DER2)) = 0.01\n DER12=MAX(ABS(DER2),SQRT(DNF))\n IF (DER12.LE.1.D-15) THEN\n H1=MAX(1.0D-6,ABS(H)*1.0D-3)\n ELSE\n H1=(0.01D0/DER12)**(1.D0/IORD) \n END IF\n H=MIN(100*ABS(H),H1,HMAX)\n HINIT853=SIGN(H,POSNEG) \n RETURN\n END \nC\n FUNCTION CONTD8(II,X,CON,ICOMP,ND)\nC ----------------------------------------------------------\nC THIS FUNCTION CAN BE USED FOR CONINUOUS OUTPUT IN CONNECTION\nC WITH THE OUTPUT-SUBROUTINE FOR DOP853. IT PROVIDES AN\nC APPROXIMATION TO THE II-TH COMPONENT OF THE SOLUTION AT X.\nC ----------------------------------------------------------\n IMPLICIT DOUBLE PRECISION (A-H,O-Z)\n DIMENSION CON(8*ND),ICOMP(ND)\n COMMON /CONDO8/XOLD,H\nC ----- COMPUTE PLACE OF II-TH COMPONENT \n I=0 \n DO 5 J=1,ND \n IF (ICOMP(J).EQ.II) I=J\n 5 CONTINUE\n IF (I.EQ.0) THEN\n WRITE (6,*) ' NO DENSE OUTPUT AVAILABLE FOR COMP.',II \n CONTD8=-1\n RETURN\n END IF \n S=(X-XOLD)/H\n S1=1.D0-S\n CONPAR=CON(I+ND*4)+S*(CON(I+ND*5)+S1*(CON(I+ND*6)+S*CON(I+ND*7)))\n CONTD8=CON(I)+S*(CON(I+ND)+S1*(CON(I+ND*2)+S*(CON(I+ND*3)\n & +S1*CONPAR)))\n RETURN\n END\n\n", "meta": {"hexsha": "18b31feed61a92ef6ee9099ca9c872fb87412a88", "size": 33752, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "scipy/integrate/dop/dop853.f", "max_stars_repo_name": "Ennosigaeon/scipy", "max_stars_repo_head_hexsha": "2d872f7cf2098031b9be863ec25e366a550b229c", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9095, "max_stars_repo_stars_event_min_datetime": "2015-01-02T18:24:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T20:35:31.000Z", "max_issues_repo_path": "scipy/integrate/dop/dop853.f", "max_issues_repo_name": "Ennosigaeon/scipy", "max_issues_repo_head_hexsha": "2d872f7cf2098031b9be863ec25e366a550b229c", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 11500, "max_issues_repo_issues_event_min_datetime": "2015-01-01T01:15:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T23:07:35.000Z", "max_forks_repo_path": "scipy/integrate/dop/dop853.f", "max_forks_repo_name": "Ennosigaeon/scipy", "max_forks_repo_head_hexsha": "2d872f7cf2098031b9be863ec25e366a550b229c", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5838, "max_forks_repo_forks_event_min_datetime": "2015-01-05T11:56:42.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T23:21:19.000Z", "avg_line_length": 38.3110102157, "max_line_length": 75, "alphanum_fraction": 0.5461602275, "num_tokens": 12779, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093975331751, "lm_q2_score": 0.7371581510799252, "lm_q1q2_score": 0.6585103038278772}} {"text": "! \n! CalculiX - A 3-dimensional finite element program\n! Copyright (C) 1998-2021 Guido Dhondt\n! \n! This program is free software; you can redistribute it and/or\n! modify it under the terms of the GNU General Public License as\n! published by the Free Software Foundation(version 2);\n! \n! \n! This program is distributed in the hope that it will be useful,\n! but WITHOUT ANY WARRANTY; without even the implied warranty of \n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \n! GNU General Public License for more details.\n! \n! You should have received a copy of the GNU General Public License\n! along with this program; if not, write to the Free Software\n! Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n! \n subroutine calcdatarget(ifront,co,nnfront,istartfront,\n & iendfront,isubsurffront,damax,datarget,acrack,nstep)\n! \n! calculate the crack propagation increment:\n! it is the minimum of:\n! - the user-defined increment\n! - one fifth of the minimum crack front curvature\n! - one fifth of the smallest crack length\n!\n implicit none\n! \n integer i,j,ifront(*),nnfront,istartfront(*),nstep,m,\n & isubsurffront(*),iendfront(*),istart,iend\n! \n real*8 datarget,damax,acrack(nstep,*),co(3,*),\n & xp,yp,zp,xa,ya,za,xn,yn,zn,xlpa,xlan,xlnp,dd,rcur\n!\n datarget=damax\n!\n! loop over all fronts\n!\n do i=1,nnfront\n if(isubsurffront(i).eq.1) then\n istart=istartfront(i)\n iend=iendfront(i)\n else\n istart=istartfront(i)+1\n iend=iendfront(i)-1\n endif\n!\n! loop over nodes belonging to front\n!\n do j=istart,iend\n if(j.eq.istart) then\n!\n! previous node\n!\n if(isubsurffront(i).eq.1) then\n xp=co(1,ifront(iend))\n yp=co(2,ifront(iend))\n zp=co(3,ifront(iend))\n else\n xp=co(1,ifront(j-1))\n yp=co(2,ifront(j-1))\n zp=co(3,ifront(j-1))\n endif\n!\n! actual node\n!\n xa=co(1,ifront(j))\n ya=co(2,ifront(j))\n za=co(3,ifront(j))\n else\n!\n! new previous node is old actual node\n!\n xp=xa\n yp=ya\n zp=za\n!\n! new actual node is old next node\n!\n xa=xn\n ya=yn\n za=zn\n endif\n!\n! next node\n!\n if((j.eq.iend).and.(isubsurffront(i).eq.1)) then\n xn=co(1,ifront(istart))\n yn=co(2,ifront(istart))\n zn=co(3,ifront(istart))\n else\n xn=co(1,ifront(j+1))\n yn=co(2,ifront(j+1))\n zn=co(3,ifront(j+1))\n endif\n!\n! calculate the radius of a circle going through the previous,\n! actual and next node (formula of Heron)\n!\n if(j.eq.istart) then\n xlpa=dsqrt((xa-xp)**2+(ya-yp)**2+(za-zp)**2)\n else\n xlpa=xlan\n endif\n xlan=dsqrt((xn-xa)**2+(yn-ya)**2+(zn-za)**2)\n xlnp=dsqrt((xp-xn)**2+(yp-yn)**2+(zp-zn)**2)\n dd=(xlpa+xlan+xlnp)/2.d0\n!\n! radius of the circle\n!\n rcur=xlpa*xlan*xlnp/\n & (4.d0*dsqrt(dd*(dd-xlpa)*(dd-xlan)*(dd-xlnp)))\n!\nc datarget=min(datarget,rcur/5.d0,acrack(j)/5.d0)\n datarget=min(datarget,rcur/5.d0)\n do m=1,nstep\n datarget=min(datarget,acrack(m,j)/5.d0)\n enddo\n enddo\n enddo\n! \n return\n end\n \n", "meta": {"hexsha": "bd03a5653c130bc4dfc2705b82e9dda302dbffc1", "size": 3534, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ccx_prool/CalculiX/ccx_2.18/src/calcdatarget.f", "max_stars_repo_name": "alleindrach/calculix-desktop", "max_stars_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ccx_prool/CalculiX/ccx_2.18/src/calcdatarget.f", "max_issues_repo_name": "alleindrach/calculix-desktop", "max_issues_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ccx_prool/CalculiX/ccx_2.18/src/calcdatarget.f", "max_forks_repo_name": "alleindrach/calculix-desktop", "max_forks_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.0476190476, "max_line_length": 71, "alphanum_fraction": 0.5458404075, "num_tokens": 1085, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541593883189, "lm_q2_score": 0.6992544147913994, "lm_q1q2_score": 0.658455828158966}} {"text": " PROGRAM xtqli\r\nC driver for routine tqli\r\n INTEGER NP\r\n REAL TINY\r\n PARAMETER(NP=10,TINY=1.0e-6)\r\n INTEGER i,j,k\r\n REAL a(NP,NP),c(NP,NP),d(NP),e(NP),f(NP)\r\n DATA c/5.0,4.3,3.0,2.0,1.0,0.0,-1.0,-2.0,-3.0,-4.0,\r\n * 4.3,5.1,4.0,3.0,2.0,1.0,0.0,-1.0,-2.0,-3.0,\r\n * 3.0,4.0,5.0,4.0,3.0,2.0,1.0,0.0,-1.0,-2.0,\r\n * 2.0,3.0,4.0,5.0,4.0,3.0,2.0,1.0,0.0,-1.0,\r\n * 1.0,2.0,3.0,4.0,5.0,4.0,3.0,2.0,1.0,0.0,\r\n * 0.0,1.0,2.0,3.0,4.0,5.0,4.0,3.0,2.0,1.0,\r\n * -1.0,0.0,1.0,2.0,3.0,4.0,5.0,4.0,3.0,2.0,\r\n * -2.0,-1.0,0.0,1.0,2.0,3.0,4.0,5.0,4.0,3.0,\r\n * -3.0,-2.0,-1.0,0.0,1.0,2.0,3.0,4.0,5.0,4.0,\r\n * -4.0,-3.0,-2.0,-1.0,0.0,1.0,2.0,3.0,4.0,5.0/\r\n do 12 i=1,NP\r\n do 11 j=1,NP\r\n a(i,j)=c(i,j)\r\n11 continue\r\n12 continue\r\n call tred2(a,NP,NP,d,e)\r\n call tqli(d,e,NP,NP,a)\r\n write(*,'(/1x,a)') 'Eigenvectors for a real symmetric matrix'\r\n do 16 i=1,NP\r\n do 14 j=1,NP\r\n f(j)=0.0\r\n do 13 k=1,NP\r\n f(j)=f(j)+c(j,k)*a(k,i)\r\n13 continue\r\n14 continue\r\n write(*,'(/1x,a,i3,a,f10.6)') 'Eigenvalue',i,' =',d(i)\r\n write(*,'(/1x,t7,a,t17,a,t31,a)') 'Vector','Mtrx*Vect.','Ratio'\r\n do 15 j=1,NP\r\n if (abs(a(j,i)).lt.TINY) then\r\n write(*,'(1x,2f12.6,a12)') a(j,i),f(j),'div. by 0'\r\n else\r\n write(*,'(1x,2f12.6,e14.6)') a(j,i),f(j),\r\n * f(j)/a(j,i)\r\n endif\r\n15 continue\r\n write(*,'(/1x,a)') 'press ENTER to continue...'\r\n read(*,*)\r\n16 continue\r\n END\r\n", "meta": {"hexsha": "7aab079c45f22de37801addf6e7505b3fde50371", "size": 1639, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xtqli.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xtqli.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xtqli.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": 34.8723404255, "max_line_length": 72, "alphanum_fraction": 0.4209884076, "num_tokens": 840, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544912, "lm_q2_score": 0.7461389873857264, "lm_q1q2_score": 0.6584138347173011}} {"text": "!!## MODULE: FUNCTION HashP\nMODULE FUN_HashP\n!!### PURPOSE\n!! Turns string into a number based upon a prime-number oriented\n!! hashing rule.\n\n!!### DETAILS\n!! Testing this hash on a dictionary of words, these rules resulted\n!! in a very even distribution of hash values---the number of words\n!! far outweighed the number of available integers, but approximately\n!! the same number of words were hashed to the same value.\n!! Words that hashed to the same value were not similar, thus collision\n!! resolution would be somewhat simple, to use in a\n!! hash table implementation.\n\n!!### AUTHOR\n!! William A. Wieselquist | william.wieselquist@gmail.com\n\n!!### EXTERNAL KINDS\nUSE KND_IntrinsicTypes,ONLY: KIND_S !!((01-A-KND_IntrinsicTypes.f90))\n\n!!### EXTERNAL PROCEDURES\nUSE FUN_Default !!((04-A-FUN_Default.f90))\n\n!!### DEFAULT IMPLICIT\nIMPLICIT NONE\n\n!!### DEFAULT ACCESS\nPRIVATE\n\n!!### INTEFACE\nINTERFACE HashP\n MODULE PROCEDURE HashP_S\nEND INTERFACE\n\n!!### PUBLIC ACCESS\nPUBLIC :: HashP\n\n\n!!### LOCAL PARAMETERS\n!! @ mapping of ascii indices to hash numbers\n!! @ ascii value of lower case \"a\"\n!! @ ascii value of lower case \"z\"\n!! @ DEFAULT value for optional case sensitivity input [DEFAULT_CaseSensitive]\n!! @ DEFAULT value for optional full spectrum input [DEFAULT_FullSpectrum]\nINTEGER,PARAMETER :: hash_map(0:127) = &\n(/000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,&\n 000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,&\n 001,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,&\n 002,003,005,007,011,013,017,019,023,029,000,000,000,000,000,000,&\n 000,031,037,041,043,047,053,059,061,067,071,073,079,083,089,097,&\n 101,103,107,109,113,127,131,137,139,149,151,000,000,000,000,001,&\n 000,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,&\n 239,241,251,257,263,269,271,277,281,000,000,000,000,000,000,000/)\nINTEGER,PARAMETER :: ascii_a = IACHAR(\"a\")\nINTEGER,PARAMETER :: ascii_z = IACHAR(\"z\")\nLOGICAL,PARAMETER :: DEFAULT_CaseSensitive = .FALSE.\nLOGICAL,PARAMETER :: DEFAULT_FullSpectrum = .FALSE.\n\n!!## MODULE PROCEDURES\nCONTAINS\n\n\n!!### PURE FUNCTION: HashP_S\nPURE FUNCTION HashP_S( word , &\n CaseSensitive , &\n FullSpectrum ) &\n RESULT(Hash)\n\n!!#### REQUIRED INPUT\n!! @ input word to hash \nCHARACTER(LEN=*,KIND=KIND_S),INTENT(IN) :: word\n\n!!#### OPTIONAL INPUT\n!! @ whether or not to generate a case sensitive hash \n!! @ to have negative hash values and thus represent the whole spectrum\n!! of integers, words with an odd number of characters\n!! receive negative hash values if full spectrum is true \nLOGICAL,OPTIONAL,INTENT(IN) :: CaseSensitive\nLOGICAL,OPTIONAL,INTENT(IN) :: FullSpectrum\n\n!!#### REQUIRED OUTPUT\n!! @ integer hash value \nINTEGER :: HASH\n\n!!#### LOCAL VARIABLES\nLOGICAL :: LOCAL_CaseSensitive !LOCAL value for the optional CaseSensitive input\nLOGICAL :: LOCAL_FullSpectrum !LOCAL value for the optional FullSpectrum input\nINTEGER :: i,j !character index\nINTEGER :: ascii !ascii value for ith character\nINTEGER :: LEN_word !length of the word\nINTEGER,PARAMETER :: limit = HUGE(HASH)/1000\n!!--begin--\n!set options\nLOCAL_CaseSensitive = DEFAULT( DEFAULT_CaseSensitive , CaseSensitive )\nLOCAL_FullSpectrum = DEFAULT( DEFAULT_FullSpectrum , FullSpectrum )\n\n!get word length\nLEN_word = LEN(word)\n\n!get the hash\nHASH = 0\nIF( .NOT.LOCAL_CaseSensitive )THEN\n DO i=1,LEN_word\n ascii = IACHAR(word(i:i))\n IF( ascii_a<=ascii .AND. ascii<=ascii_z )THEN\n ascii = ascii - 32\n END IF\n j = LEN_word-i+1\n HASH = HASH + ( j + j**2 + j**3 - 2 )*hash_map(ascii)\n IF( HASH>limit )HASH = HASH/2 + MOD(HASH,limit)\n END DO\nELSE\n DO i=1,LEN_word\n ascii = IACHAR(word(i:i))\n j = LEN_word-i+1\n HASH = HASH + ( j + j**2 + j**3 - 2 )*hash_map(ascii)\n IF( HASH>limit )HASH = HASH/2 + MOD(HASH,limit)\n END DO\nEND IF\n\n!make odd-length words have negative hashes if FullSpectrum==.TRUE.\nIF( LOCAL_FullSpectrum )THEN\n IF( MOD(LEN_word,2)/=0 )THEN\n HASH = -HASH\n ENDIF\nENDIF\n\n!!--end--\nEND FUNCTION\n\n\nEND MODULE\n", "meta": {"hexsha": "1af8caf1ae8412d52723bbdb3f142b3a104be316", "size": 4133, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/05-B-FUN_HashP.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/05-B-FUN_HashP.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/05-B-FUN_HashP.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.8432835821, "max_line_length": 80, "alphanum_fraction": 0.6994918945, "num_tokens": 1263, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267830311354, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6583920505461126}} {"text": "!----------------------------------------------------------------------\n!----------------------------------------------------------------------\n! 1cl : A one-cell, two-substrate enzyme model \n!----------------------------------------------------------------------\n!----------------------------------------------------------------------\n\n SUBROUTINE FUNC(NDIM,U,ICP,PAR,IJAC,F,DFDU,DFDP)\n! ---------- ----\n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: NDIM, ICP(*), IJAC\n DOUBLE PRECISION, INTENT(IN) :: U(NDIM), PAR(*)\n DOUBLE PRECISION, INTENT(OUT) :: F(NDIM)\n DOUBLE PRECISION, INTENT(INOUT) :: DFDU(NDIM,NDIM), DFDP(NDIM,*)\n\n DOUBLE PRECISION S,A,S0,A0,AL,RH,RK,D,R,DRDS,DRDA,DRDK\n\n S=U(1)\n A=U(2)\n\n S0=PAR(1)\n A0=PAR(2)\n AL=PAR(3)\n RH=PAR(4)\n RK=PAR(5)\n\n D=1+S+RK*S**2\n R=S*A/D\n\n F(1)= (S0-S) - RH*R\n F(2)=AL*(A0-A) - RH*R\n\n IF(IJAC.EQ.0)RETURN\n\n DRDS=( A*D - S*A*(1+2*RK*S) ) / D**2\n DRDA=S/D\n DRDK=-S**3*A/D**2\n\n DFDU(1,1)=-1 - RH*DRDS\n DFDU(1,2)= - RH*DRDA\n DFDU(2,1)= - RH*DRDS\n DFDU(2,2)=-AL- RH*DRDA\n\n IF(IJAC.EQ.1)RETURN \n\n! *Parameter derivatives\n\n DFDP(1,1)=1\n DFDP(1,2)=0\n DFDP(1,3)=0\n DFDP(1,4)=-R\n DFDP(1,5)=-RH*DRDK\n\n DFDP(2,1)=0\n DFDP(2,2)=AL\n DFDP(2,3)=A0-A\n DFDP(2,4)=-R\n DFDP(2,5)=-RH*DRDK\n\n END SUBROUTINE FUNC\n\n SUBROUTINE STPNT(NDIM,U,PAR,T)\n! ---------- -----\n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: NDIM\n DOUBLE PRECISION, INTENT(INOUT) :: U(NDIM),PAR(*)\n DOUBLE PRECISION, INTENT(IN) :: T\n\n PAR(1)=110.\n PAR(2)=500.\n PAR(3)=0.2\n PAR(4)=2.021628\n PAR(5)=0.1\n\n U(1)=4.555974E+01\n U(2)=1.777987E+02\n\n END SUBROUTINE STPNT\n\n SUBROUTINE BCND\n END SUBROUTINE BCND\n\n SUBROUTINE ICND\n END SUBROUTINE ICND\n\n SUBROUTINE FOPT\n END SUBROUTINE FOPT\n\n SUBROUTINE PVLS\n END SUBROUTINE PVLS\n", "meta": {"hexsha": "e890e980feb9ca50a729e142b8d25f6c304b4860", "size": 2051, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "07p/demos/plp/plp.f90", "max_stars_repo_name": "st970703/AUTO07P-Update-to-Python-3.0", "max_stars_repo_head_hexsha": "fb2d2aebf2127fa914064d01ed62c0acb5f6421c", "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": "07p/demos/plp/plp.f90", "max_issues_repo_name": "st970703/AUTO07P-Update-to-Python-3.0", "max_issues_repo_head_hexsha": "fb2d2aebf2127fa914064d01ed62c0acb5f6421c", "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": "07p/demos/plp/plp.f90", "max_forks_repo_name": "st970703/AUTO07P-Update-to-Python-3.0", "max_forks_repo_head_hexsha": "fb2d2aebf2127fa914064d01ed62c0acb5f6421c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.2934782609, "max_line_length": 71, "alphanum_fraction": 0.4236957582, "num_tokens": 728, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267694452331, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6583920402507922}} {"text": "c fishpk29 from portlib 12/30/83\nc\nc * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nc * *\nc * f i s h p a k *\nc * *\nc * *\nc * a package of fortran subprograms for the solution of *\nc * *\nc * separable elliptic partial differential equations *\nc * *\nc * (version 3.1 , october 1980) *\nc * *\nc * by *\nc * *\nc * john adams, paul swarztrauber and roland sweet *\nc * *\nc * of *\nc * *\nc * the national center for atmospheric research *\nc * *\nc * boulder, colorado (80307) u.s.a. *\nc * *\nc * which is sponsored by *\nc * *\nc * the national science foundation *\nc * *\nc * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nc\nc\nc program to illustrate the use of hwscsp\nc\n program thwscsp\n dimension f(48,33) ,bdtf(33) ,w(775) ,r(33) ,\n 1 theta(48)\n dimension bdts(1), bdrs(1), bdrf(1)\nc\n pi = pimach(dum)\n intl = 0\n ts = 0.\n tf = pi/2.\n m = 36\n mbdcnd = 6\n rs = 0.\n rf = 1.\n n = 32\n nbdcnd = 5\n elmbda = 0.\n idimf = 48\nc\nc generate and store grid points for the purpose of computing the\nc boundary data and the right side of the equation.\nc\n mp1 = m+1\n dtheta = tf/float(m)\n do 101 i=1,mp1\n theta(i) = float(i-1)*dtheta\n 101 continue\n np1 = n+1\n dr = 1./float(n)\n do 102 j=1,np1\n r(j) = float(j-1)*dr\n 102 continue\nc\nc generate normal derivative data at equator\nc\n do 103 j=1,np1\n bdtf(j) = 0.\n 103 continue\nc\nc compute boundary data on the surface of the sphere\nc\n do 104 i=1,mp1\n f(i,n+1) = cos(theta(i))**4\n 104 continue\nc\nc compute right side of equation\nc\n do 106 i=1,mp1\n ci4 = 12.*cos(theta(i))**2\n do 105 j=1,n\n f(i,j) = ci4*r(j)**2\n 105 continue\n 106 continue\nc\n call hwscsp (intl,ts,tf,m,mbdcnd,bdts,bdtf,rs,rf,n,nbdcnd,bdrs,\n 1 bdrf,elmbda,f,idimf,pertrb,ierror,w)\nc\nc compute discretization error\nc\n err = 0.\n do 108 i=1,mp1\n ci4 = cos(theta(i))**4\n do 107 j=1,n\n z = abs(f(i,j)-ci4*r(j)**4)\n if (z .gt. err) err = z\n 107 continue\n 108 continue\n iw = int(w(1))\n print 1001 , ierror,err,iw\nc\nc the following program illustrates the use of hwscsp to solve\nc a three dimensional problem which has longitudnal dependence\nc\n mbdcnd = 2\n nbdcnd = 1\n dphi = pi/72.\n elmbda = -2.*(1.-cos(dphi))/dphi**2\nc\nc compute boundary data on the surface of the sphere\nc\n do 109 i=1,mp1\n f(i,n+1) = sin(theta(i))\n 109 continue\nc\nc compute right side of the equation\nc\n do 111 j=1,n\n do 110 i=1,mp1\n f(i,j) = 0.\n 110 continue\n 111 continue\nc\n call hwscsp (intl,ts,tf,m,mbdcnd,bdts,bdtf,rs,rf,n,nbdcnd,bdrs,\n 1 bdrf,elmbda,f,idimf,pertrb,ierror,w)\nc\nc compute discretization error (fourier coefficients)\nc\n err = 0\n do 113 i=1,mp1\n si = sin(theta(i))\n do 112 j=1,np1\n z = abs(f(i,j)-r(j)*si)\n if (z .gt. err) err = z\n 112 continue\n 113 continue\nc\n iw = int(w(1))\n print 1002 , ierror,err,iw\n stop\nc\n 1001 format (1h1,20x,27hsubroutine hwscsp example 1///\n 1 10x,46hthe output from the ncar control data 7600 was//\n 2 32x,10hierror = 0/\n 3 18x,34hdiscretization error = 7.99842e-04/\n 4 12x,32hrequired length of w array = 775//\n 5 10x,32hthe output from your computer is//\n 6 32x,8hierror =,i2/18x,22hdiscretization error =,e12.5/\n 7 12x,28hrequired length of w array =,i4)\n 1002 format (1h1,20x,27hsubroutine hwscsp example 2///\n 1 10x,46hthe output from the ncar control data 7600 was//\n 2 32x,10hierror = 0/\n 3 18x,34hdiscretization error = 5.86824e-05/\n 4 12x,32hrequired length of w array = 775//\n 5 10x,32hthe output from your computer is//\n 6 32x,8hierror =,i2/18x,22hdiscretization error =,e12.5/\n 7 12x,28hrequired length of w array =,i4)\nc\n end\n", "meta": {"hexsha": "0d72118f42af5a22721d4e20d64920bf01e453e7", "size": 5434, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/f2cl/packages/fishpack/ex/tsthwscsp.f", "max_stars_repo_name": "sbwhitecap/clocc-hg", "max_stars_repo_head_hexsha": "f6cf2591ceef8a3a80e04da9b414cdf60a25a90f", "max_stars_repo_licenses": ["MIT"], "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/f2cl/packages/fishpack/ex/tsthwscsp.f", "max_issues_repo_name": "sbwhitecap/clocc-hg", "max_issues_repo_head_hexsha": "f6cf2591ceef8a3a80e04da9b414cdf60a25a90f", "max_issues_repo_licenses": ["MIT"], "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/f2cl/packages/fishpack/ex/tsthwscsp.f", "max_forks_repo_name": "sbwhitecap/clocc-hg", "max_forks_repo_head_hexsha": "f6cf2591ceef8a3a80e04da9b414cdf60a25a90f", "max_forks_repo_licenses": ["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.9625, "max_line_length": 72, "alphanum_fraction": 0.4153478101, "num_tokens": 1606, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267762381844, "lm_q2_score": 0.7577943658046609, "lm_q1q2_score": 0.6583920358935229}} {"text": "! Identity matrix distribution\n!\n! Write a program that distributes an identity matrix over the processes. The\n! dimension and the number of processes are given. Distribute by rows (in\n! Fortran). The program reads the matrix size S, takes the number of processes\n! N, and calculates how many rows each process must have. Better if subarrays,\n! local to each rank, use through indexing. At the end, rank 0 collects the\n! matrix rows from the other ranks and prints the entire matrix.\n!\n! Compile and run:\n!\n! $ mpifort -O0 -Wall -Wextra -fcheck=bounds -fbacktrace identity_matrix.f90\n! $ mpirun -np 3 --oversubscribe ./a.out\n!\n! Enter size 10.\nprogram identity_matrix\n use mpi_f08\n implicit none\n type(MPI_Comm) :: comm\n type(MPI_Status) :: status\n integer :: my_rank, n_ranks\n integer :: ib, ie, i, s, rank\n integer, allocatable :: e(:, :)\n integer(kind=MPI_ADDRESS_KIND) :: lb, integer_extent\n type(MPI_Datatype) :: a_tmp_row, a_row\n\n call MPI_Init()\n comm = MPI_COMM_WORLD\n call MPI_Comm_rank(comm, my_rank)\n call MPI_Comm_size(comm, n_ranks)\n\n if (my_rank == 0) read *, s\n call MPI_Bcast(s, 1, MPI_INTEGER, 0, comm)\n\n call partition(my_rank, n_ranks, s, ib, ie)\n\n allocate(e(ib:ie, s), source=0)\n do i = ib, ie\n e(i, i) = 1\n end do\n\n call MPI_Type_get_extent(MPI_INTEGER, lb, integer_extent)\n call MPI_Type_vector(s, 1, ie - ib + 1, MPI_INTEGER, a_tmp_row)\n call MPI_Type_create_resized(a_tmp_row, lb, integer_extent, a_row)\n call MPI_Type_commit(a_row)\n\n if (my_rank == 0) then\n ! Rank 0 prints its own matrix,\n print \"(a, i0)\", \"Rank \", my_rank\n do i = ib, ie\n print \"(*(i1, 1x))\", e(i, :)\n end do\n print *\n ! then receives rows from the other processes and prints them.\n do rank = 1, n_ranks - 1\n call partition(rank, n_ranks, s, ib, ie)\n call MPI_Recv(e(1, 1), ie - ib + 1, a_row, rank, 0, comm, status)\n print \"(a, i0)\", \"Rank \", rank\n do i = 1, ie - ib + 1\n print \"(*(i1, 1x))\", e(i, :)\n end do\n print *\n end do\n else\n call MPI_Send(e(ib, 1), ie - ib + 1, a_row, 0, 0, comm)\n end if\n\n call MPI_Type_free(a_row)\n deallocate(e)\n\n call MPI_Finalize()\n\ncontains\n\n subroutine partition(id, n_ids, size, b, e)\n integer, intent(in) :: id, n_ids, size\n integer, intent(inout) :: b, e\n integer :: remainder, quotient\n\n remainder = modulo(size, n_ids)\n quotient = (size - remainder) / n_ids\n b = 1 + quotient * (id ) + min(remainder, id )\n e = quotient * (id + 1) + min(remainder, id + 1)\n return\n end subroutine partition\n\nend program identity_matrix\n", "meta": {"hexsha": "369cf217d0649efbd0a3b8cbb241458894abe561", "size": 2790, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Lecture_13/identity_matrix/identity_matrix.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_13/identity_matrix/identity_matrix.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_13/identity_matrix/identity_matrix.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": 31.7045454545, "max_line_length": 80, "alphanum_fraction": 0.6089605735, "num_tokens": 816, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833737577158, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.6583735437813811}} {"text": "c program DRDSVDRS\nc>> 1996-06-25 DRDSVDRS Krogh Changes for conversion to C.\nc>> 1996-05-28 DRDSVDRS Krogh Added external statement.\nc>> 1994-10-19 DRDSVDRS Krogh Changes to use M77CON\nc>> 1992-03-18 DRDSVDRS CLL Added \"c\" to \"program\" line above.\nc>> 1992-03-12 DRDSVDRS CLL\nc Demo driver for DSVDRS and DCOV3, Singular Value Decomposition\nc and Covariance matrix.\nc\nc The sample data was computed as\nc y = 0.5 + 0.25 * sin(2*pi*x) + 0.125 * exp(-x)\nc rounded to four decimal places.\nc ------------------------------------------------------------------\nc--D replaces \"?\": DR?SVDRS, ?SVDRS, ?COV3, ?DOT, ?NRM2\nc ------------------------------------------------------------------\n external DDOT, DNRM2\n double precision DDOT, DNRM2\n integer MMAX, NMAX\n parameter(MMAX = 11, NMAX = 3)\n double precision A(MMAX,NMAX), B(MMAX), C(NMAX), DOF, PI, RNORM\n double precision SING(NMAX), STDDEV\n double precision VAR, WORK(2*NMAX), X(MMAX),Y(MMAX)\n integer I, IERR, J, M, N\nc\n data X / 0.0d0, 0.1d0, 0.2d0, 0.3d0, 0.4d0, 0.5d0,\n * 0.6d0, 0.7d0, 0.8d0, 0.9d0, 1.0d0/\n data Y / 0.6250d0,0.7601d0,0.8401d0,0.8304d0,0.7307d0,0.5758d0,\n * 0.4217d0,0.3243d0,0.3184d0,0.4039d0,0.5460d0/\nc ------------------------------------------------------------------\n M = MMAX\n N = NMAX\n print*,' DRDSVDRS.. Demo driver for DSVDRS and DCOV3.'\nc\n PI = 4.0d0 * atan(1.0d0)\n do 10 I = 1, M\n A(I,1) = 1.0d0\n A(I,2) = sin(2.0d0 * PI * X(I))\n A(I,3) = exp(-X(I))\n B(I) = Y(I)\n 10 continue\n\n call DSVDRS(A, MMAX, M, N, B, MMAX, 1, SING, WORK)\nc\n print '(/'' Computed singular values:''/(1x,5g14.6))',\n * (SING(I),I=1,N)\n print '(/'' V matrix:'')'\n do 15 I = 1, N\n print '(1x,3f12.6)', (A(I,J),J=1,N)\n 15 continue\nc\n RNORM = DNRM2(M-N, B(N+1), 1)\n DOF = M - N\n VAR = RNORM**2 / DOF\n STDDEV = sqrt(VAR)\n print '(/a,f10.6)', ' Estimated Std. Dev. of data error =',STDDEV\nc\nc Writing the singular value decomposition of A as\nc A = U * S * Transpose(V),\nc the solution of the least-squares problem A*c ~ b will be\nc c = V * Inverse(S) *Transpose(U) * b.\nc We now have V in A(), S in SING(), and the product, Transpose(U)*b\nc in B(). So we can now compute c, as long as all singular values\nc are nonzero.\nc SING() contains the singular values as nonnegative\nc numbers in nonincreasing order, so we only need to test SING(N).\nc\n if(SING(N) .ne. 0.0d0) then\n do 20 I = 1,N\n B(I) = B(I) / SING(I)\n 20 continue\n do 30 I = 1,N\n C(I) = DDOT(N, A(I,1), MMAX, B, 1)\n 30 continue\n\n print '(1x,''Solution coefficients ='',3f10.6)',\n * (C(J),J=1,N)\n end if\nc\nc Compute covariance matrix.\nc\n call DCOV3(A, MMAX, N, SING, VAR, WORK, IERR)\n print '(/'' After DCOV3, IERR = '',i4)',IERR\n if(IERR .eq. 0) then\n print '(/'' Covariance matrix:'')'\n do 40 I = 1, N\n print '(1x,3g14.6)', (A(I,J),J=1,N)\n 40 continue\n end if\n end\n", "meta": {"hexsha": "8881cad06fdc24ea5ddc601454bd6fd9dde6775d", "size": 3248, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drdsvdrs.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drdsvdrs.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drdsvdrs.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 36.0888888889, "max_line_length": 72, "alphanum_fraction": 0.5086206897, "num_tokens": 1223, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84997116805678, "lm_q2_score": 0.7745833737577159, "lm_q1q2_score": 0.6583735349502071}} {"text": "! Generate hdif.gr3 (or hvis.gr3) with hdif=L_h^2 * gamma/dt (where \n! gamma is a dimensionless constant between [0,0.25), and L_h is a length scale)\n! Works for mixed tri/quads.\n! Inputs: screen (gamma1,dt; hdif_max); hgrid.gr3\n! Output: hdif.gr3\n\n! ifort -Bstatic -O3 -o gen_hdif gen_hdif.f90\n! pgf90 -O2 -mcmodel=medium -Mbounds -O2 -o gen_hdif gen_hdif.f90\n\n implicit real*8(a-h,o-z)\n parameter(mnp=500000)\n parameter(mne=1000000)\n parameter(mnei=30)\n integer :: i34(mne),elnode(4,mne)\n dimension x(mnp),y(mnp),dp(mnp),area(mne)\n dimension nne(mnp),indel(mnei,mnp),hdif(mnp),hdif_e(mne),rlh(4)\n\n print*, 'Input gamma \\in [0,0.25) and time step:' !stricter than necessary as dt' in transport is smaller\n read*, gamma1,dt\n if(gamma1>=0.25.or.gamma1<0) then\n print*, 'Choose a smaller gamma: ',gamma1\n stop\n endif\n print*, 'Input max. hdif:'\n read*, hdif_max\n\n open(14,file='hgrid.gr3')\n open(13,file='hdif.gr3')\n read(14,*)\n read(14,*) ne,np\n if(ne>mne.or.np>mnp) then\n write(*,*)'Increase mne/mnp',mne,mnp,ne,np\n stop\n endif\n\n do i=1,np\n read(14,*) j,x(i),y(i) !,dp(i)\n enddo !i=1,np\n do i=1,ne\n read(14,*) j,i34(i),elnode(1:i34(i),i)\n n1=elnode(1,i)\n n2=elnode(2,i)\n n3=elnode(3,i)\n area(i)=signa(x(n1),x(n2),x(n3),y(n1),y(n2),y(n3))\n if(area(i)<=0) then\n write(*,*)'Negative area at',i\n stop\n endif\n \n if(i34(i)==4) then\n n4=elnode(4,i)\n area(i)=area(i)+signa(x(n1),x(n3),x(n4),y(n1),y(n3),y(n4))\n endif\n\n! write(13,*)i,dmin1(hdif_max,gamma1*area(i))\n! hdif_e(i)=gamma1*area(i)/dt\n\n !Side length\n do j=1,i34(i)\n nd=elnode(j,i)\n j2=j+1\n if(j2>i34(i)) j2=j2-i34(i) \n nd2=elnode(j2,i)\n rlh(j)=sqrt((x(nd2)-x(nd))**2+(y(nd2)-y(nd))**2)\n enddo !j\n rlh_min=minval(rlh(1:i34(i)))\n hdif_e(i)=gamma1*rlh_min**2/dt\n enddo !i=1,ne \n\n! Neighborhood\n nne=0\n do i=1,ne\n do j=1,i34(i)\n nd=elnode(j,i)\n nne(nd)=nne(nd)+1\n if(nne(nd)>mnei) then\n write(*,*)'Too many neighbors',nd\n stop\n endif\n indel(nne(nd),nd)=i\n enddo\n enddo\n\n hdif=0\n do i=1,np\n do j=1,nne(i)\n ie=indel(j,i)\n hdif(i)=hdif(i)+hdif_e(ie)/nne(i)\n enddo !j\n hdif(i)=dmin1(hdif(i),hdif_max)\n enddo !i\n\n write(13,*)'gamma1= ',real(gamma1), ' ,dt= ',real(dt),' ,hdif_max= ',real(hdif_max)\n!'\n write(13,*)ne,np\n do i=1,np\n write(13,*)i,real(x(i)),real(y(i)),real(hdif(i))\n enddo !i\n do i=1,ne\n write(13,*) i,i34(i),elnode(1:i34(i),i)\n enddo !i\n\n print*, 'Min. diffusivity/viscosity= ',minval(hdif(1:np))\n\n stop\n end\n\n function signa(x1,x2,x3,y1,y2,y3)\n!... Compute signed area formed by pts 1,2,3\n implicit real*8(a-h,o-z)\n\n signa=((x1-x3)*(y2-y3)-(x2-x3)*(y1-y3))/2\n\n return\n end\n\n", "meta": {"hexsha": "4e04c2207008e53cfe973a731f75525fef02c699", "size": 3155, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/Utility/Pre-Processing/gen_hdif.f90", "max_stars_repo_name": "rustychris/schism", "max_stars_repo_head_hexsha": "3754530ef57b3a058906432b4a9fca4a670f395e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2019-08-12T21:48:24.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-03T03:08:10.000Z", "max_issues_repo_path": "src/Utility/Pre-Processing/gen_hdif.f90", "max_issues_repo_name": "rustychris/schism", "max_issues_repo_head_hexsha": "3754530ef57b3a058906432b4a9fca4a670f395e", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 42, "max_issues_repo_issues_event_min_datetime": "2019-08-19T21:57:12.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-03T17:42:01.000Z", "max_forks_repo_path": "src/Utility/Pre-Processing/gen_hdif.f90", "max_forks_repo_name": "rustychris/schism", "max_forks_repo_head_hexsha": "3754530ef57b3a058906432b4a9fca4a670f395e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 51, "max_forks_repo_forks_event_min_datetime": "2019-08-09T20:59:07.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T15:48:43.000Z", "avg_line_length": 26.9658119658, "max_line_length": 111, "alphanum_fraction": 0.5150554675, "num_tokens": 1172, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297941266013, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6583400313081641}} {"text": "!*==dlagv2.f90 processed by SPAG 7.51RB at 20:08 on 3 Mar 2022\n!> \\brief \\b DLAGV2 computes the Generalized Schur factorization of a real 2-by-2 matrix pencil (A,B) where B is upper triangular.\n!\n! =========== DOCUMENTATION ===========\n!\n! Online html documentation available at\n! http://www.netlib.org/lapack/explore-html/\n!\n!> \\htmlonly\n!> Download DLAGV2 + dependencies\n!> \n!> [TGZ]\n!> \n!> [ZIP]\n!> \n!> [TXT]\n!> \\endhtmlonly\n!\n! Definition:\n! ===========\n!\n! SUBROUTINE DLAGV2( A, LDA, B, LDB, ALPHAR, ALPHAI, BETA, CSL, SNL,\n! CSR, SNR )\n!\n! .. Scalar Arguments ..\n! INTEGER LDA, LDB\n! DOUBLE PRECISION CSL, CSR, SNL, SNR\n! ..\n! .. Array Arguments ..\n! DOUBLE PRECISION A( LDA, * ), ALPHAI( 2 ), ALPHAR( 2 ),\n! $ B( LDB, * ), BETA( 2 )\n! ..\n!\n!\n!> \\par Purpose:\n! =============\n!>\n!> \\verbatim\n!>\n!> DLAGV2 computes the Generalized Schur factorization of a real 2-by-2\n!> matrix pencil (A,B) where B is upper triangular. This routine\n!> computes orthogonal (rotation) matrices given by CSL, SNL and CSR,\n!> SNR such that\n!>\n!> 1) if the pencil (A,B) has two real eigenvalues (include 0/0 or 1/0\n!> types), then\n!>\n!> [ a11 a12 ] := [ CSL SNL ] [ a11 a12 ] [ CSR -SNR ]\n!> [ 0 a22 ] [ -SNL CSL ] [ a21 a22 ] [ SNR CSR ]\n!>\n!> [ b11 b12 ] := [ CSL SNL ] [ b11 b12 ] [ CSR -SNR ]\n!> [ 0 b22 ] [ -SNL CSL ] [ 0 b22 ] [ SNR CSR ],\n!>\n!> 2) if the pencil (A,B) has a pair of complex conjugate eigenvalues,\n!> then\n!>\n!> [ a11 a12 ] := [ CSL SNL ] [ a11 a12 ] [ CSR -SNR ]\n!> [ a21 a22 ] [ -SNL CSL ] [ a21 a22 ] [ SNR CSR ]\n!>\n!> [ b11 0 ] := [ CSL SNL ] [ b11 b12 ] [ CSR -SNR ]\n!> [ 0 b22 ] [ -SNL CSL ] [ 0 b22 ] [ SNR CSR ]\n!>\n!> where b11 >= b22 > 0.\n!>\n!> \\endverbatim\n!\n! Arguments:\n! ==========\n!\n!> \\param[in,out] A\n!> \\verbatim\n!> A is DOUBLE PRECISION array, dimension (LDA, 2)\n!> On entry, the 2 x 2 matrix A.\n!> On exit, A is overwritten by the ``A-part'' of the\n!> generalized Schur form.\n!> \\endverbatim\n!>\n!> \\param[in] LDA\n!> \\verbatim\n!> LDA is INTEGER\n!> THe leading dimension of the array A. LDA >= 2.\n!> \\endverbatim\n!>\n!> \\param[in,out] B\n!> \\verbatim\n!> B is DOUBLE PRECISION array, dimension (LDB, 2)\n!> On entry, the upper triangular 2 x 2 matrix B.\n!> On exit, B is overwritten by the ``B-part'' of the\n!> generalized Schur form.\n!> \\endverbatim\n!>\n!> \\param[in] LDB\n!> \\verbatim\n!> LDB is INTEGER\n!> THe leading dimension of the array B. LDB >= 2.\n!> \\endverbatim\n!>\n!> \\param[out] ALPHAR\n!> \\verbatim\n!> ALPHAR is DOUBLE PRECISION array, dimension (2)\n!> \\endverbatim\n!>\n!> \\param[out] ALPHAI\n!> \\verbatim\n!> ALPHAI is DOUBLE PRECISION array, dimension (2)\n!> \\endverbatim\n!>\n!> \\param[out] BETA\n!> \\verbatim\n!> BETA is DOUBLE PRECISION array, dimension (2)\n!> (ALPHAR(k)+i*ALPHAI(k))/BETA(k) are the eigenvalues of the\n!> pencil (A,B), k=1,2, i = sqrt(-1). Note that BETA(k) may\n!> be zero.\n!> \\endverbatim\n!>\n!> \\param[out] CSL\n!> \\verbatim\n!> CSL is DOUBLE PRECISION\n!> The cosine of the left rotation matrix.\n!> \\endverbatim\n!>\n!> \\param[out] SNL\n!> \\verbatim\n!> SNL is DOUBLE PRECISION\n!> The sine of the left rotation matrix.\n!> \\endverbatim\n!>\n!> \\param[out] CSR\n!> \\verbatim\n!> CSR is DOUBLE PRECISION\n!> The cosine of the right rotation matrix.\n!> \\endverbatim\n!>\n!> \\param[out] SNR\n!> \\verbatim\n!> SNR is DOUBLE PRECISION\n!> The sine of the right rotation matrix.\n!> \\endverbatim\n!\n! Authors:\n! ========\n!\n!> \\author Univ. of Tennessee\n!> \\author Univ. of California Berkeley\n!> \\author Univ. of Colorado Denver\n!> \\author NAG Ltd.\n!\n!> \\date December 2016\n!\n!> \\ingroup doubleOTHERauxiliary\n!\n!> \\par Contributors:\n! ==================\n!>\n!> Mark Fahey, Department of Mathematics, Univ. of Kentucky, USA\n!\n! =====================================================================\n SUBROUTINE DLAGV2(A,Lda,B,Ldb,Alphar,Alphai,Beta,Csl,Snl,Csr,Snr)\n IMPLICIT NONE\n!*--DLAGV2160\n!\n! -- LAPACK auxiliary routine (version 3.7.0) --\n! -- LAPACK is a software package provided by Univ. of Tennessee, --\n! -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n! December 2016\n!\n! .. Scalar Arguments ..\n INTEGER Lda , Ldb\n DOUBLE PRECISION Csl , Csr , Snl , Snr\n! ..\n! .. Array Arguments ..\n DOUBLE PRECISION A(Lda,*) , Alphai(2) , Alphar(2) , B(Ldb,*) , &\n & Beta(2)\n! ..\n!\n! =====================================================================\n!\n! .. Parameters ..\n DOUBLE PRECISION ZERO , ONE\n PARAMETER (ZERO=0.0D+0,ONE=1.0D+0)\n! ..\n! .. Local Scalars ..\n DOUBLE PRECISION anorm , ascale , bnorm , bscale , h1 , h2 , h3 , &\n & qq , r , rr , safmin , scale1 , scale2 , t , &\n & ulp , wi , wr1 , wr2\n! ..\n! .. External Subroutines ..\n EXTERNAL DLAG2 , DLARTG , DLASV2 , DROT\n! ..\n! .. External Functions ..\n DOUBLE PRECISION DLAMCH , DLAPY2\n EXTERNAL DLAMCH , DLAPY2\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC ABS , MAX\n! ..\n! .. Executable Statements ..\n!\n safmin = DLAMCH('S')\n ulp = DLAMCH('P')\n!\n! Scale A\n!\n anorm = MAX(ABS(A(1,1))+ABS(A(2,1)),ABS(A(1,2))+ABS(A(2,2)), &\n & safmin)\n ascale = ONE/anorm\n A(1,1) = ascale*A(1,1)\n A(1,2) = ascale*A(1,2)\n A(2,1) = ascale*A(2,1)\n A(2,2) = ascale*A(2,2)\n!\n! Scale B\n!\n bnorm = MAX(ABS(B(1,1)),ABS(B(1,2))+ABS(B(2,2)),safmin)\n bscale = ONE/bnorm\n B(1,1) = bscale*B(1,1)\n B(1,2) = bscale*B(1,2)\n B(2,2) = bscale*B(2,2)\n!\n! Check if A can be deflated\n!\n IF ( ABS(A(2,1))<=ulp ) THEN\n Csl = ONE\n Snl = ZERO\n Csr = ONE\n Snr = ZERO\n A(2,1) = ZERO\n B(2,1) = ZERO\n wi = ZERO\n!\n! Check if B is singular\n!\n ELSEIF ( ABS(B(1,1))<=ulp ) THEN\n CALL DLARTG(A(1,1),A(2,1),Csl,Snl,r)\n Csr = ONE\n Snr = ZERO\n CALL DROT(2,A(1,1),Lda,A(2,1),Lda,Csl,Snl)\n CALL DROT(2,B(1,1),Ldb,B(2,1),Ldb,Csl,Snl)\n A(2,1) = ZERO\n B(1,1) = ZERO\n B(2,1) = ZERO\n wi = ZERO\n!\n ELSEIF ( ABS(B(2,2))<=ulp ) THEN\n CALL DLARTG(A(2,2),A(2,1),Csr,Snr,t)\n Snr = -Snr\n CALL DROT(2,A(1,1),1,A(1,2),1,Csr,Snr)\n CALL DROT(2,B(1,1),1,B(1,2),1,Csr,Snr)\n Csl = ONE\n Snl = ZERO\n A(2,1) = ZERO\n B(2,1) = ZERO\n B(2,2) = ZERO\n wi = ZERO\n!\n ELSE\n!\n! B is nonsingular, first compute the eigenvalues of (A,B)\n!\n CALL DLAG2(A,Lda,B,Ldb,safmin,scale1,scale2,wr1,wr2,wi)\n!\n IF ( wi==ZERO ) THEN\n!\n! two real eigenvalues, compute s*A-w*B\n!\n h1 = scale1*A(1,1) - wr1*B(1,1)\n h2 = scale1*A(1,2) - wr1*B(1,2)\n h3 = scale1*A(2,2) - wr1*B(2,2)\n!\n rr = DLAPY2(h1,h2)\n qq = DLAPY2(scale1*A(2,1),h3)\n!\n IF ( rr>qq ) THEN\n!\n! find right rotation matrix to zero 1,1 element of\n! (sA - wB)\n!\n CALL DLARTG(h2,h1,Csr,Snr,t)\n!\n ELSE\n!\n! find right rotation matrix to zero 2,1 element of\n! (sA - wB)\n!\n CALL DLARTG(h3,scale1*A(2,1),Csr,Snr,t)\n!\n ENDIF\n!\n Snr = -Snr\n CALL DROT(2,A(1,1),1,A(1,2),1,Csr,Snr)\n CALL DROT(2,B(1,1),1,B(1,2),1,Csr,Snr)\n!\n! compute inf norms of A and B\n!\n h1 = MAX(ABS(A(1,1))+ABS(A(1,2)),ABS(A(2,1))+ABS(A(2,2)))\n h2 = MAX(ABS(B(1,1))+ABS(B(1,2)),ABS(B(2,1))+ABS(B(2,2)))\n!\n IF ( (scale1*h1)>=ABS(wr1)*h2 ) THEN\n!\n! find left rotation matrix Q to zero out B(2,1)\n!\n CALL DLARTG(B(1,1),B(2,1),Csl,Snl,r)\n!\n ELSE\n!\n! find left rotation matrix Q to zero out A(2,1)\n!\n CALL DLARTG(A(1,1),A(2,1),Csl,Snl,r)\n!\n ENDIF\n!\n CALL DROT(2,A(1,1),Lda,A(2,1),Lda,Csl,Snl)\n CALL DROT(2,B(1,1),Ldb,B(2,1),Ldb,Csl,Snl)\n!\n A(2,1) = ZERO\n B(2,1) = ZERO\n!\n ELSE\n!\n! a pair of complex conjugate eigenvalues\n! first compute the SVD of the matrix B\n!\n CALL DLASV2(B(1,1),B(1,2),B(2,2),r,t,Snr,Csr,Snl,Csl)\n!\n! Form (A,B) := Q(A,B)Z**T where Q is left rotation matrix and\n! Z is right rotation matrix computed from DLASV2\n!\n CALL DROT(2,A(1,1),Lda,A(2,1),Lda,Csl,Snl)\n CALL DROT(2,B(1,1),Ldb,B(2,1),Ldb,Csl,Snl)\n CALL DROT(2,A(1,1),1,A(1,2),1,Csr,Snr)\n CALL DROT(2,B(1,1),1,B(1,2),1,Csr,Snr)\n!\n B(2,1) = ZERO\n B(1,2) = ZERO\n!\n ENDIF\n!\n ENDIF\n!\n! Unscaling\n!\n A(1,1) = anorm*A(1,1)\n A(2,1) = anorm*A(2,1)\n A(1,2) = anorm*A(1,2)\n A(2,2) = anorm*A(2,2)\n B(1,1) = bnorm*B(1,1)\n B(2,1) = bnorm*B(2,1)\n B(1,2) = bnorm*B(1,2)\n B(2,2) = bnorm*B(2,2)\n!\n IF ( wi==ZERO ) THEN\n Alphar(1) = A(1,1)\n Alphar(2) = A(2,2)\n Alphai(1) = ZERO\n Alphai(2) = ZERO\n Beta(1) = B(1,1)\n Beta(2) = B(2,2)\n ELSE\n Alphar(1) = anorm*wr1/scale1/bnorm\n Alphai(1) = anorm*wi/scale1/bnorm\n Alphar(2) = Alphar(1)\n Alphai(2) = -Alphai(1)\n Beta(1) = ONE\n Beta(2) = ONE\n ENDIF\n!\n!\n! End of DLAGV2\n!\n END SUBROUTINE DLAGV2\n", "meta": {"hexsha": "09324d2495f3f7d3bb9bf4a11bf89cd81d56476c", "size": 10121, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/double/dlagv2.f90", "max_stars_repo_name": "urbanjost/spag_lapack", "max_stars_repo_head_hexsha": "1b082638c0ff5feb1a295a3aa4624c538d14847c", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2022-03-04T13:15:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-04T17:40:26.000Z", "max_issues_repo_path": "src/double/dlagv2.f90", "max_issues_repo_name": "urbanjost/spag_lapack", "max_issues_repo_head_hexsha": "1b082638c0ff5feb1a295a3aa4624c538d14847c", "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": "src/double/dlagv2.f90", "max_forks_repo_name": "urbanjost/spag_lapack", "max_forks_repo_head_hexsha": "1b082638c0ff5feb1a295a3aa4624c538d14847c", "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.2803234501, "max_line_length": 130, "alphanum_fraction": 0.4977768995, "num_tokens": 3732, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297887874624, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6583400274049408}} {"text": " subroutine global_local(i,xg,yg,zg,xl,yl,zl)\nc s kelkar March 24, 06\nc map from global coordinates to local coordinates, origin at \nc corn(i,1:3) and scale axis by ddx(i),ddy(i), ddz(i) where\nc i is a node# in the coarse grid, corn gives the lower, left, back\nc corner of the brick shaped control volume ofi, and dx,dy,dz\nc are the x,y,z cell sizes.\nc******************************************************************** \nc INPUT VARIABLES\nc \nc OUTOUT VARIABLES\nc \nc INTERNAL VARIABLES\nc********************************************************************\nc INPUT\nc i : node id in the coarse grid\nc xg,yg,zg: coordinates in the global system\nc corn(i,1:3): coordinates in the global system\nc of the corner to be used as the origin\nc dx(i),dy(i),dz(i): cell sizes in the global system \nc OUTOUT\nc xl,yl,zl: node coordinates in the local system\n \n use comparttr_sg\n use comunits\n\n implicit none\n\n integer i\n\n real*8 xg,yg,zg,xl,yl,zl,dx,dy,dz\n\n dx=dxyz(i,1)\n dy=dxyz(i,2)\n dz=dxyz(i,3)\n\n if(dx*dy*dz.eq.0.) then\n write(error_unit_number,*)' zero cell size in global_local',\n 1 'for cell# ',i\n write(error_unit_number,*)'STOP'\n stop\n else\n xl=(xg-corn(i,1))/dx\n yl=(yg-corn(i,2))/dy\n zl=(zg-corn(i,3))/dz\n endif\n\n return\n\n end\n\nc........................................................................\n", "meta": {"hexsha": "ff51e9925119495251fe547d16bcd656c014acee", "size": 1481, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/global_local.f", "max_stars_repo_name": "lanl/PLUMECALC", "max_stars_repo_head_hexsha": "70a15749a1f21b8d4289d696a401b283265d49a9", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-03-19T07:37:40.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-10T11:35:29.000Z", "max_issues_repo_path": "src/global_local.f", "max_issues_repo_name": "lanl/PLUMECALC", "max_issues_repo_head_hexsha": "70a15749a1f21b8d4289d696a401b283265d49a9", "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/global_local.f", "max_forks_repo_name": "lanl/PLUMECALC", "max_forks_repo_head_hexsha": "70a15749a1f21b8d4289d696a401b283265d49a9", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-01-12T12:55:43.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-19T07:37:40.000Z", "avg_line_length": 27.9433962264, "max_line_length": 73, "alphanum_fraction": 0.521944632, "num_tokens": 406, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297807787537, "lm_q2_score": 0.7310585727705127, "lm_q1q2_score": 0.6583400162734583}} {"text": "PROGRAM hello\n\n USE mpi\n\n INTEGER, PARAMETER:: dp=KIND(0.d0) \n\n INTEGER :: ierr, comm_size, comm_rank, length\n REAL(dp) :: RESULT\n CHARACTER (len=MPI_MAX_PROCESSOR_NAME) :: proc_name\n\n CALL MPI_Init(ierr)\n CALL MPI_Comm_size(MPI_COMM_WORLD, comm_size, ierr)\n CALL MPI_Comm_rank(MPI_COMM_WORLD, comm_rank, ierr)\n CALL MPI_Get_processor_name(proc_name, length, ierr)\n \n WRITE(*,*) \"Hello World from process = \", comm_rank, \" on processor \", proc_name\n\n RESULT = EXP(REAL(comm_rank, dp))\n\n WRITE(*,*) \"Exp(\", comm_rank, \") = \", RESULT \n\n CALL MPI_Barrier(MPI_COMM_WORLD, ierr);\n IF (comm_rank == 0) THEN\n WRITE(*,*) \"Number of mpi processes = \", comm_size\n ENDIF\n CALL MPI_Finalize(ierr);\n\nEND PROGRAM hello\n", "meta": {"hexsha": "ab9f19bbada229929834eabc2dd478663cd506bd", "size": 727, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "MPI/Lab/hello_f/mpi_hello.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/hello_f/mpi_hello.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/hello_f/mpi_hello.f90", "max_forks_repo_name": "rctraining/USGS-Advanced-HPC-Workshop", "max_forks_repo_head_hexsha": "4b206f6478fef8655eeffee025a43bb4414e7d83", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.0689655172, "max_line_length": 82, "alphanum_fraction": 0.6973865199, "num_tokens": 208, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891392358015, "lm_q2_score": 0.8006919949619793, "lm_q1q2_score": 0.6583202621307864}} {"text": "subroutine holoPy(x)\n implicit none\n real, parameter :: pi=3.141592653589793238460\n complex, dimension(:) :: x\n call fft(x)\n\nend\n\nrecursive subroutine fft(x,y)\n !integer, parameter :: dp=selected_real_kind(15,300)\n\n complex, dimension(:), intent(in) :: x\n complex, dimension(:), optional, intent(out) :: y\n complex :: t\n integer :: N\n integer :: i\n complex, dimension(:), allocatable :: even, odd\n\n N=size(x)\n\n !if(N .le. 1) return\n\n allocate(odd((N+1)/2))\n allocate(even(N/2))\n\n ! divide\n odd =x(1:N:2)\n even=x(2:N:2)\n print*,odd,even\n\n ! conquer\n call fft(odd)\n call fft(even)\n!\n! ! combine\n! do i=1,N/2\n!\n!\n! t=exp(cmplx(0.0_dp,-2.0_dp*pi*real(i-1,dp)/real(N,dp),KIND=DP))*even(i)\n! x(i) = odd(i) + t\n! x(i+N/2) = odd(i) - t\n! end do\n!\n! deallocate(odd)\n! deallocate(even)\n end subroutine fft\n\n\n\n", "meta": {"hexsha": "2a25fab79dda4c8d5006ec627ae08229d09b391b", "size": 1020, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "fft/newTest.f95", "max_stars_repo_name": "wesleybowman/fortran", "max_stars_repo_head_hexsha": "a704a79aa5ba7c20967db71552873adcdadb241f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-10-10T14:02:03.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-10T14:02:03.000Z", "max_issues_repo_path": "fft/newTest.f95", "max_issues_repo_name": "wesleybowman/fortran", "max_issues_repo_head_hexsha": "a704a79aa5ba7c20967db71552873adcdadb241f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fft/newTest.f95", "max_forks_repo_name": "wesleybowman/fortran", "max_forks_repo_head_hexsha": "a704a79aa5ba7c20967db71552873adcdadb241f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.4, "max_line_length": 76, "alphanum_fraction": 0.4970588235, "num_tokens": 319, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096044278532, "lm_q2_score": 0.7185944046238982, "lm_q1q2_score": 0.658311235764068}} {"text": "program cfd\n! Run the 2d cfd simulation\n\nuse parameters\nuse diff\nuse save\nuse actuator\nuse boundary\nimplicit none\n\ninteger,parameter :: seed = 86456\ninteger :: ix, iy, it, ii\n\n\n! gamma: how much upwinding will we use?\n! pow: temporary variable for power\n! powtotal: a aggregator for power\nreal :: gamma, pow, powtotal\n\n! u,v: velocities\n! ua,va: velocity averages (temp)\n! ud,vd: velocity derivatives (temp)\n! uvx, uvy,u2x,u2y: variables for the advective term in the NS equation\n! p: pressure\n! rhs: rhs for the pressure solver\nreal, allocatable,dimension(:,:) :: u,v,p,ua,va,ud,vd,uvx,uvy,u2x,v2y,rhs\n\ncall save_parameters()\n\nallocate( u(nnx,nny), &\n v(nnx,nny), &\n p(nnx,nny), &\n ua(nnx,nny), &\n va(nnx,nny), &\n ud(nnx,nny), &\n vd(nnx,nny), &\n uvx(nnx,nny), &\n uvy(nnx,nny), &\n u2x(nnx,nny), &\n v2y(nnx,nny), &\n rhs(nnx,nny) &\n)\n\n! create random initial pertubation\ncall srand(seed)\ndo ix=1,nnx\n do iy=1,nny\n p(ix,iy) = rand()/1000.0\n end do\nend do\n\n! seed u and v off this initial pertubation\nu = p\nv = p\ncall ddy(u,1.0)\ncall ddx(v,1.0)\nu = u + uvel\np = p*0.0\npowtotal = 0\ncall initialize_actuator()\n\ntime_step: do it=1,nts\n\n call apply_boundary(u,v,1,it)\n\n !! Calculate the uvx and uvy with upwinding\n gamma = min(1.2*dt*max(maxval(abs(u))/hx,maxval(abs(v))/hy),1.0);\n ua = u; call yavg(ua); ua = cshift(ua,shift=-1,dim=2);\n ud = u; call ddy(ud,2.0); ud = cshift(ud,shift=-1,dim=2);\n va = v; call xavg(va); va = cshift(va,shift=-1,dim=1);\n vd = v; call ddx(vd,2.0); vd = cshift(vd,shift=-1,dim=1);\n\n uvx = (ua * va) - (gamma * abs(ua) * vd)\n call ddx(uvx,hx);\n\n uvy = (ua * va) - (gamma * abs(va) * ud)\n call ddy(uvy,hy);\n\n !! Calculate the u2x and v2y terms\n ua = u; call xavg(ua);\n ud = u; call ddx(ud,2.0);\n va = v; call yavg(va);\n vd = v; call ddy(vd,2.0);\n\n u2x = ua*ua - gamma*abs(ua)*ud\n call ddx(u2x,hx); u2x = cshift(u2x,shift=-1,dim=1)\n\n v2y = va*va - gamma*abs(va)*vd\n call ddy(v2y,hy); v2y = cshift(v2y,shift=-1,dim=2)\n\n\n !! update the u and v variables\n u = u - dt*(uvy+u2x)\n v = v - dt*(uvx+v2y)\n\n !! Iteratively solve for pressure\n call apply_boundary(u,v,1,it)\n\n ud = u; call ddx(ud,hx)\n vd = v; call ddy(vd,hy)\n rhs = ud + vd\n iterate_pressure: do ii=1,niter\n p = 0.25*(myiter(p,hm) - hx*hy*rhs)\n end do iterate_pressure\n ud = cshift(p,shift=-1,dim=1); call ddx(ud,hx)\n vd = cshift(p,shift=-1,dim=2); call ddy(vd,hy)\n u = u - ud\n v = v - vd\n\n !! Apply actuator force\n call update_actuator(u)\n call apply_actuator(u,dt,hx,pow)\n\n !! driving pressure gradient\n u = u + dt*dpg\n powtotal = powtotal + pow*dt\n\n !! Save the information if requested\n if (mod(it,write_freq) == 0) then\n call save_vel(it,u,v)\n call save_pow(it,pow)\n end if \n\nend do time_step\n\nprint *, 'Total Power Produced: ', powtotal\n\n\n\nend program\n", "meta": {"hexsha": "8a380f88c3973440c0755d13a8f39887c58beb50", "size": 3014, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/cfd.f90", "max_stars_repo_name": "wme7/cfd", "max_stars_repo_head_hexsha": "56efea0f7997e029d9f7e19be090f161cf0ab068", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2015-01-25T09:16:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-03T23:42:58.000Z", "max_issues_repo_path": "src/cfd.f90", "max_issues_repo_name": "sAlexander/cfd", "max_issues_repo_head_hexsha": "cad8da9df68ae3287b9d7b96a92eb4921f010e4f", "max_issues_repo_licenses": ["MIT"], "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/cfd.f90", "max_forks_repo_name": "sAlexander/cfd", "max_forks_repo_head_hexsha": "cad8da9df68ae3287b9d7b96a92eb4921f010e4f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-05-12T09:45:55.000Z", "max_forks_repo_forks_event_max_datetime": "2017-12-23T23:39:00.000Z", "avg_line_length": 23.0076335878, "max_line_length": 73, "alphanum_fraction": 0.5862641009, "num_tokens": 1090, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096044278532, "lm_q2_score": 0.718594386544335, "lm_q1q2_score": 0.6583112192012066}} {"text": "\n\n subroutine stVenantKirchhoff_elasticity(matData,F,stre,cc,finite)\n\n implicit none\n\n integer finite,\n * i, round\n double precision matData(*), F(3,*), stre(*), cc(6,*),\n * mu, K, Lamb, b(6), fact,\n * det_u, r1dJ, J\n\n if (finite.eq.0) then\n call small_strain_elasticity(matData,F,stre,cc)\n return\n endif\n\n K = matData(1)\n mu = matData(2)\n Lamb = K - (mu + mu) / 3.d0\n\n call calcB(b,F)\n\n J = det_u(F)\n r1dJ = 1.d0 / J\n\n fact = r1dJ * (Lamb * 0.5d0 * (b(1)+b(2)+b(3)-3.d0) - mu)\n\n call set_s_f(stre,b,fact)\n\n fact = r1dJ * mu\n\n call mult_s_ss_af(stre,b,b,fact)\n\n fact = r1dJ * Lamb\n\n call mult_4_ss_f(cc,b,b,fact)\n\n fact = r1dJ * (mu + mu)\n\n cc(1,1) = cc(1,1) + fact * b(1)*b(1)\n cc(1,2) = cc(1,2) + fact * b(4)*b(4)\n cc(1,3) = cc(1,3) + fact * b(6)*b(6)\n cc(2,1) = cc(1,2)\n cc(2,2) = cc(2,2) + fact * b(2)*b(2)\n cc(2,3) = cc(2,3) + fact * b(5)*b(5)\n cc(3,1) = cc(1,3)\n cc(3,2) = cc(2,3)\n cc(3,3) = cc(3,3) + fact * b(3)*b(3)\n\n cc(1,4) = cc(1,4) + fact * b(1)*b(4)\n cc(1,5) = cc(1,5) + fact * b(4)*b(6)\n cc(1,6) = cc(1,6) + fact * b(1)*b(6)\n cc(2,4) = cc(2,4) + fact * b(2)*b(4)\n cc(2,5) = cc(2,5) + fact * b(2)*b(5)\n cc(2,6) = cc(2,6) + fact * b(4)*b(5)\n cc(3,4) = cc(3,4) + fact * b(5)*b(6)\n cc(3,5) = cc(3,5) + fact * b(3)*b(5)\n cc(3,6) = cc(3,6) + fact * b(3)*b(6)\n\n cc(4,1) = cc(1,4) \n cc(5,1) = cc(1,5)\n cc(6,1) = cc(1,6)\n cc(4,2) = cc(2,4)\n cc(5,2) = cc(2,5)\n cc(6,2) = cc(2,6)\n cc(4,3) = cc(3,4)\n cc(5,3) = cc(3,5)\n cc(6,3) = cc(3,6)\n\n fact = fact * 0.5d0\n\n cc(4,4) = cc(4,4) + fact * (b(1)*b(2) + b(4)*b(4))\n cc(4,5) = cc(4,5) + fact * (b(2)*b(6) + b(4)*b(5))\n cc(4,6) = cc(4,6) + fact * (b(1)*b(5) + b(4)*b(6))\n cc(5,4) = cc(4,5)\n cc(5,5) = cc(5,5) + fact * (b(2)*b(3) + b(5)*b(5))\n cc(5,6) = cc(5,6) + fact * (b(3)*b(4) + b(5)*b(6))\n cc(6,4) = cc(4,6)\n cc(6,5) = cc(5,6)\n cc(6,6) = cc(6,6) + fact * (b(1)*b(3) + b(6)*b(6))\n\n return\n\n end\n\n\n\n\n\n", "meta": {"hexsha": "9fc17ac88f787fc45bb7a41fa125a3b5b23181ba", "size": 2239, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/material/stVenantKirchhoff_elasticity.for", "max_stars_repo_name": "chennachaos/mpap", "max_stars_repo_head_hexsha": "99d02bc9075b72b899a167d1bbc2bf73584b85bc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-12-30T16:45:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-29T23:27:29.000Z", "max_issues_repo_path": "src/material/stVenantKirchhoff_elasticity.for", "max_issues_repo_name": "chennachaos/mpap", "max_issues_repo_head_hexsha": "99d02bc9075b72b899a167d1bbc2bf73584b85bc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2019-11-22T12:57:55.000Z", "max_issues_repo_issues_event_max_datetime": "2020-11-04T22:01:42.000Z", "max_forks_repo_path": "src/material/stVenantKirchhoff_elasticity.for", "max_forks_repo_name": "chennachaos/mpap", "max_forks_repo_head_hexsha": "99d02bc9075b72b899a167d1bbc2bf73584b85bc", "max_forks_repo_licenses": ["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.6043956044, "max_line_length": 71, "alphanum_fraction": 0.4010719071, "num_tokens": 1103, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096044278532, "lm_q2_score": 0.718594386544335, "lm_q1q2_score": 0.6583112192012066}} {"text": "#include \"eiscor.h\"\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! ZARNAR (Zomplex Auxiliary Routine Normalized ARgument)\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! This routine sorts the eigenvalues and optionally eigenvectors of a\n! unitary matrix. The eigenpairs are sorted in ascending order of the\n! argument of the eigenvalue. \n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! INPUT VARIABLES:\n!\n! A,B REAL(8)\n! real and imaginary part of complex number\n!\n! OUTPUT VARIABLES:\n!\n! ARG REAL(8)\n! arg of A + Bi in the interval [0,2pi)\n!\n! INFO INTEGER\n! INFO = 0 implies successful computation\n! INFO = -1 implies A is invalid\n! INFO = -2 implies B is invalid\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine ZARNAR(A,B,ARG,INFO)\n\n ! input variables\n real(8), intent(in) :: A, B\n real(8), intent(inout) :: ARG\n integer, intent(inout) :: INFO\n \n ! compute variables\n real(8), parameter :: PI = 3.14159265358979323846264338327950d0\n \n ! initialize INFO\n INFO = 0 \n \n ! check error in debug mode\n if (DEBUG) then\n \n ! check A\n call DARNAN(A,INFO)\n if (INFO.NE.0) then\n call UARERR(__FILE__,__LINE__,\"A is invalid\",INFO,-1)\n return\n end if\n call DARINF(A,INFO)\n if (INFO.NE.0) then\n call UARERR(__FILE__,__LINE__,\"A is invalid\",INFO,-1)\n return\n end if \n\n ! check B\n call DARNAN(B,INFO)\n if (INFO.NE.0) then\n call UARERR(__FILE__,__LINE__,\"B is invalid\",INFO,-2)\n return\n end if\n call DARINF(B,INFO)\n if (INFO.NE.0) then\n call UARERR(__FILE__,__LINE__,\"B is invalid\",INFO,-2)\n return\n end if\n\n end if\n \n ! compute arg 1\n if ((abs(A).EQ.0d0).AND.(abs(B).EQ.0d0)) then\n ARG = 0d0\n \n ! abs(A) > abs(B)\n else if (abs(A) > abs(B)) then\n \n ! compute ARG between [-pi/2,pi/2]\n ARG = atan(abs(B/A))\n \n ! abs(A) < abs(B)\n else\n \n ! compute ARG between [-pi/2,pi/2]\n ARG = atan(abs(A/B))\n ARG = PI/2d0 - ARG\n \n end if\n \n ! correct for [0,2pi)\n ! second quadrant\n if ((B >= 0).AND.(A < 0)) then\n ARG = PI-ARG\n \n ! third quadrant\n else if ((B < 0).AND.(A < 0)) then\n ARG = PI+ARG\n \n ! fourth quadrant\n else if ((B < 0).AND.(A > 0)) then\n ARG = 2d0*PI-ARG\n end if\n \nend subroutine ZARNAR\n", "meta": {"hexsha": "0a5cf5963f64f98bb71af13882b7a27e67ed895a", "size": 2497, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "deps/eiscor-master/src/complex_double/ZARNAR.f90", "max_stars_repo_name": "andreasnoack/EiSCor.jl", "max_stars_repo_head_hexsha": "d03d217e30e006b35263b99cb4adafd9d7e1e973", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "deps/eiscor-master/src/complex_double/ZARNAR.f90", "max_issues_repo_name": "andreasnoack/EiSCor.jl", "max_issues_repo_head_hexsha": "d03d217e30e006b35263b99cb4adafd9d7e1e973", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "deps/eiscor-master/src/complex_double/ZARNAR.f90", "max_forks_repo_name": "andreasnoack/EiSCor.jl", "max_forks_repo_head_hexsha": "d03d217e30e006b35263b99cb4adafd9d7e1e973", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.5566037736, "max_line_length": 70, "alphanum_fraction": 0.5050060072, "num_tokens": 754, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.835483553488848, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.6583035510798697}} {"text": "MODULE GravitySolutionModule_Newtonian_PointMass_Old\n\n USE KindModule, ONLY: &\n DP\n USE UnitsModule, ONLY: &\n GravitationalConstant, &\n UnitsDisplay\n USE ProgramHeaderModule, ONLY: &\n nX, nNodesX\n USE UtilitiesModule, ONLY: &\n NodeNumberX\n USE MeshModule, ONLY: &\n MeshX, &\n NodeCoordinate\n USE GeometryFieldsModule, ONLY: &\n uGF, iGF_Phi_N\n\n IMPLICIT NONE\n PRIVATE\n\n REAL(DP) :: PointMass\n\n PUBLIC :: InitializeGravitySolver_Newtonian_PointMass\n PUBLIC :: FinalizeGravitySolver_Newtonian_PointMass\n PUBLIC :: SolveGravity_Newtonian_PointMass\n\nCONTAINS\n\n\n SUBROUTINE InitializeGravitySolver_Newtonian_PointMass &\n ( PointMass_Option )\n\n REAL(DP), INTENT(in), OPTIONAL :: PointMass_Option\n\n PointMass = 1.0_DP\n IF( PRESENT( PointMass_Option ) ) &\n PointMass = PointMass_Option\n\n WRITE(*,*)\n WRITE(*,'(A7,A12,ES10.4E2,A1,A)') &\n '', 'PointMass = ', PointMass / UnitsDisplay % MassUnit, &\n '', UnitsDisplay % MassLabel\n\n END SUBROUTINE InitializeGravitySolver_Newtonian_PointMass\n\n\n SUBROUTINE FinalizeGravitySolver_Newtonian_PointMass\n\n PointMass = 1.0_DP\n\n END SUBROUTINE FinalizeGravitySolver_Newtonian_PointMass\n\n\n SUBROUTINE SolveGravity_Newtonian_PointMass\n\n INTEGER :: iX1, iX2, iX3\n INTEGER :: iNodeX1, iNodeX2, iNodeX3, iNode\n REAL(DP) :: X1\n\n DO iX3 = 1, nX(3)\n DO iX2 = 1, nX(2)\n DO iX1 = 1, nX(1)\n\n DO iNodeX3 = 1, nNodesX(3)\n DO iNodeX2 = 1, nNodesX(2)\n DO iNodeX1 = 1, nNodesX(1)\n\n X1 = NodeCoordinate( MeshX(1), iX1, iNodeX1 )\n\n iNode = NodeNumberX( iNodeX1, iNodeX2, iNodeX3 )\n\n uGF(iNode,iX1,iX2,iX3,iGF_Phi_N) &\n = - GravitationalConstant * PointMass / X1\n\n END DO\n END DO\n END DO\n\n END DO\n END DO\n END DO\n\n CALL SetBoundaryConditions\n\n END SUBROUTINE SolveGravity_Newtonian_PointMass\n\n\n SUBROUTINE SetBoundaryConditions\n\n CALL SetBoundaryConditions_X1\n\n END SUBROUTINE SetBoundaryConditions\n\n\n SUBROUTINE SetBoundaryConditions_X1\n\n INTEGER :: iX2, iX3\n INTEGER :: iNodeX1, iNodeX2, iNodeX3, iNodeX\n REAL(DP) :: X1\n\n DO iX3 = 1, nX(3)\n DO iX2 = 1, nX(2)\n\n DO iNodeX3 = 1, nNodesX(3)\n DO iNodeX2 = 1, nNodesX(2)\n DO iNodeX1 = 1, nNodesX(1)\n\n iNodeX = NodeNumberX( iNodeX1, iNodeX2, iNodeX3 )\n\n ! --- Inner Boundary: Dirichlet ---\n\n X1 = NodeCoordinate( MeshX(1), 0, iNodeX1 )\n\n uGF(iNodeX,0,iX2,iX3,iGF_Phi_N) &\n = - PointMass / X1\n\n ! --- Outer Boundary: Dirichlet ---\n\n X1 = NodeCoordinate( MeshX(1), nX(1)+1, iNodeX1 )\n\n uGF(iNodeX,nX(1)+1,iX2,iX3,iGF_Phi_N) &\n = - PointMass / X1\n\n END DO\n END DO\n END DO\n\n END DO\n END DO\n\n END SUBROUTINE SetBoundaryConditions_X1\n\n\nEND MODULE GravitySolutionModule_Newtonian_PointMass_Old\n", "meta": {"hexsha": "8656b86aa12b3939fdf6cbd2acbf9496d721797a", "size": 3011, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Modules/RadHydro/GravitySolutionModule_Newtonian_PointMass_Old.f90", "max_stars_repo_name": "srichers/thornado", "max_stars_repo_head_hexsha": "bc6666cbf9ae8b39b1ba5feffac80303c2b1f9a8", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-12-08T16:16:55.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-24T19:31:21.000Z", "max_issues_repo_path": "Modules/RadHydro/GravitySolutionModule_Newtonian_PointMass_Old.f90", "max_issues_repo_name": "srichers/thornado", "max_issues_repo_head_hexsha": "bc6666cbf9ae8b39b1ba5feffac80303c2b1f9a8", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2019-07-10T20:13:15.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-11T13:21:00.000Z", "max_forks_repo_path": "Modules/RadHydro/GravitySolutionModule_Newtonian_PointMass_Old.f90", "max_forks_repo_name": "srichers/thornado", "max_forks_repo_head_hexsha": "bc6666cbf9ae8b39b1ba5feffac80303c2b1f9a8", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2018-11-14T01:13:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-24T02:08:20.000Z", "avg_line_length": 22.3037037037, "max_line_length": 64, "alphanum_fraction": 0.6200597808, "num_tokens": 961, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835289107307, "lm_q2_score": 0.7879312056025699, "lm_q1q2_score": 0.6583035441957217}} {"text": " subroutine intrsc(x1,y1,x2,y2,x3,y3,x4,y4,x0,y0)\n a1=y2-y1\n b1=x1-x2\n a2=y4-y3\n b2=x3-x4\nC\n d=a1*b2-a2*b1\nC.....test: are the lines collinear to each other ?\n if(abs(d).le.1.e- 8) goto 1\n c1=x2*y1-x1*y2\n c2=x4*y3-x3*y4\nC.....compute the intersection point \"x0,y0\".\n x0=(c2*b1-b2*c1)/d\n y0=(c1*a2-c2*a1)/d\nC.....test: does the point \"x0,y0\" belong to both line segments ?\n if(x0.lt.amax1(amin1(x1,x2),amin1(x3,x4))) goto 1\n if(x0.gt.amin1(amax1(x1,x2),amax1(x3,x4))) goto 1\n if(y0.lt.amax1(amin1(y1,y2),amin1(y3,y4))) goto 1\n if(y0.gt.amin1(amax1(y1,y2),amax1(y3,y4))) goto 1\n return\n1 continue\nC....in unnormal situation: a half of the element of the \"screen\".\n x0=0.5*(x3+x4)\n y0=0.5*(y3+y4)\n return\n end\n", "meta": {"hexsha": "c2803d2b84b4cd9646db0971628766ed859cbd01", "size": 812, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ftn/intrsc.f", "max_stars_repo_name": "sergev/grafor", "max_stars_repo_head_hexsha": "2b7b244d84b739bdcdf1717824ee895eb015c4a0", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-11-23T08:32:55.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-12T14:05:06.000Z", "max_issues_repo_path": "ftn/intrsc.f", "max_issues_repo_name": "sergev/grafor", "max_issues_repo_head_hexsha": "2b7b244d84b739bdcdf1717824ee895eb015c4a0", "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": "ftn/intrsc.f", "max_forks_repo_name": "sergev/grafor", "max_forks_repo_head_hexsha": "2b7b244d84b739bdcdf1717824ee895eb015c4a0", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.0740740741, "max_line_length": 66, "alphanum_fraction": 0.5726600985, "num_tokens": 350, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109784205503, "lm_q2_score": 0.6926419831347361, "lm_q1q2_score": 0.6582945448862348}} {"text": "program gen_table\r\nimplicit none\r\n!real,parameter :: delr=0.002,rcut=1.0\r\nDOUBLE PRECISION, parameter :: delr=0.0005D0, rcut=3.0D0\r\nDOUBLE PRECISION :: r\r\ninteger :: nbins,j\r\n\r\nnbins=int( (rcut+1)/delr) + 1\r\nopen(unit=6,file='table_A_B.xvg')\r\n\r\ndo j=0,nbins\r\n r=delr*j\r\n \r\n ! for table_A_A\r\n IF (r < 0.96D0) THEN\r\n write(6,*) r*1.0D0, 0.0D0, 0.0D0, 0.0D0, 0.0D0, 10**5, 10**5\r\n else if (r <= 1.57D0) then\r\n !write(6,*) r*1.0D0, 0.0D0, 0.0D0, (-4.0D0)/(r**6), (-24.0D0)/(r**7), &\r\n ! 4.0D0/(r**12)-(4.0D0/(1.57D0**12)-4.0D0/(1.57D0**6)), 48.0D0/(r**13) ! A-A or B-B\r\n write(6,*) r*1.0D0, 0.0D0, 0.0D0, (-4.0D0)/((r/1.03D0)**6), (-24.0D0)/((r/1.03D0)**7), &\r\n 4.0D0/((r/1.03D0)**12)-(4.0D0/((1.57D0/1.03D0)**12)-4.0D0/((1.57D0/1.03D0)**6)),&\r\n 48.0D0/((r/1.03D0)**13) ! A-B\r\n ELSE\r\n write(6,*) r*1.0D0, 0.0D0, 0.0D0, 0.0D0, 0.0D0, 0.0D0, 0.0D0\r\n ENDIF\r\n \r\nend do\r\n\r\nclose(6)\r\n\r\nEnd program\r\n", "meta": {"hexsha": "a904954494a9ac67acbc99de55f4be9aee0dec89", "size": 988, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "userff/pb_pe.ff/tabulize.f90", "max_stars_repo_name": "jht0664/Utility_python_gromacs", "max_stars_repo_head_hexsha": "4457b62e2f0252bcb38021d5deda0cfb932e3ed9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-02T11:27:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-02T11:27:59.000Z", "max_issues_repo_path": "userff/pb_pe.ff/tabulize.f90", "max_issues_repo_name": "jht0664/Utility_python_gromacs", "max_issues_repo_head_hexsha": "4457b62e2f0252bcb38021d5deda0cfb932e3ed9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "userff/pb_pe.ff/tabulize.f90", "max_forks_repo_name": "jht0664/Utility_python_gromacs", "max_forks_repo_head_hexsha": "4457b62e2f0252bcb38021d5deda0cfb932e3ed9", "max_forks_repo_licenses": ["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.875, "max_line_length": 100, "alphanum_fraction": 0.5030364372, "num_tokens": 534, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088045171237, "lm_q2_score": 0.7090191399336402, "lm_q1q2_score": 0.6582596120855502}} {"text": " SUBROUTINE SGESV_F95( A, B, IPIV, INFO )\n!\n! -- LAPACK95 interface driver routine (version 3.0) --\n! UNI-C, Denmark; Univ. of Tennessee, USA; NAG Ltd., UK\n! September, 2000\n!\n! .. \"Use Statements\" ..\n USE LA_PRECISION, ONLY: WP => SP\n USE LA_AUXMOD, ONLY: ERINFO\n USE F77_LAPACK, ONLY: GESV_F77 => LA_GESV\n! .. \"Implicit Statement\" ..\n IMPLICIT NONE\n! .. \"Scalar Arguments\" ..\n INTEGER, INTENT(OUT), OPTIONAL :: INFO\n! .. \"Array Arguments\" ..\n INTEGER, INTENT(OUT), OPTIONAL, TARGET :: IPIV(:)\n REAL(WP), INTENT(INOUT) :: A(:,:), B(:,:)\n!----------------------------------------------------------------------\n! \n! Purpose\n! =======\n! \n! LA_GESV computes the solution to a real or complex linear system of\n! equations A*X = B, where A is a square matrix and X and B are \n! rectangular matrices or vectors. Gaussian elimination with row \n! interchanges is used to factor A as A = P*L*U , where P is a permutation\n! matrix, L is unit lower triangular, and U is upper triangular. The \n! factored form of A is then used to solve the above system.\n! \n! =========\n! \n! SUBROUTINE LA_GESV( A, B, IPIV=ipiv, INFO=info )\n! (), INTENT(INOUT) :: A(:,:), \n! INTEGER, INTENT(OUT), OPTIONAL :: IPIV(:)\n! INTEGER, INTENT(OUT), OPTIONAL :: INFO\n! where\n! ::= REAL | COMPLEX\n! ::= KIND(1.0) | KIND(1.0D0)\n! ::= B(:,:) | B(:)\n! \n! Arguments\n! =========\n! \n! A (input/output) REAL or COMPLEX square array, shape (:,:).\n! On entry, the matrix A.\n! On exit, the factors L and U from the factorization A = P*L*U; \n! the unit diagonal elements of L are not stored.\n! B (input/output) REAL or COMPLEX array, shape (:,:) with \n! size(B,1) = size(A,1) or shape (:) with size(B) = size(A,1).\n! On entry, the matrix B.\n! On exit, the solution matrix X .\n! IPIV Optional (output) INTEGER array, shape (:) with size(IPIV) = \n! size(A,1).\n! The pivot indices that define the permutation matrix P; row i of\n! the matrix was interchanged with row IPIV(i).\n! INFO Optional (output) INTEGER\n! = 0 : successful exit.\n! < 0 : if INFO = -i, the i-th argument has an illegal value.\n! > 0 : if INFO = i, then U(i,i) = 0. The factorization has been \n! completed, but the factor U is singular, so the solution could\n! not be computed.\n! If INFO is not present and an error occurs, then the program is \n! terminated with an error message.\n!----------------------------------------------------------------------\n! .. \"Parameters\" ..\n CHARACTER(LEN=7), PARAMETER :: SRNAME = 'LA_GESV'\n! .. LOCAL SCALARS ..\n INTEGER :: LINFO, ISTAT, ISTAT1, SIPIV\n! .. \"Local Pointers\" ..\n INTEGER, POINTER :: LPIV(:)\n! .. \"Intrinsic Functions\" ..\n INTRINSIC SIZE, PRESENT, MAX\n! .. \"Executable Statements\" ..\n LINFO = 0; ISTAT = 0\n IF( PRESENT(IPIV) )THEN\n SIPIV = SIZE(IPIV)\n ELSE\n SIPIV = SIZE(A,1)\n END IF\n! .. \"Test the arguments\" ..\n IF( SIZE( A, 2 ) /= SIZE(A,1) .OR. SIZE(A,1) < 0 ) THEN\n LINFO = -1\n ELSE IF( SIZE( B, 1 ) /= SIZE(A,1) .OR. SIZE(B,2) < 0 ) THEN\n LINFO = -2\n ELSE IF( SIPIV /= SIZE(A,1) )THEN\n LINFO = -3\n ELSE IF ( SIZE(A,1) > 0 ) THEN\n IF( PRESENT(IPIV) )THEN\n LPIV => IPIV\n ELSE\n ALLOCATE( LPIV(SIZE(A,1)), STAT = ISTAT )\n END IF\n IF ( ISTAT == 0 ) THEN\n! .. \"Call LAPACK77 routine\" ..\n CALL GESV_F77( SIZE(A,1), SIZE(B,2), A, MAX(1,SIZE(A,1)), LPIV, B, MAX(1,SIZE(A,1)), &\n LINFO )\n ELSE\n LINFO = -100\n END IF\n IF( .NOT.PRESENT(IPIV) )THEN\n DEALLOCATE(LPIV, STAT = ISTAT1 )\n END IF\n END IF\n CALL ERINFO( LINFO, SRNAME, INFO, ISTAT )\n END SUBROUTINE SGESV_F95\n", "meta": {"hexsha": "3ff324bcf3371ddaa91497177ba2b385f6266c57", "size": 4015, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/la_sgesv.f90", "max_stars_repo_name": "MattBurn/LAPACK95", "max_stars_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-12-29T15:07:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T10:09:22.000Z", "max_issues_repo_path": "src/la_sgesv.f90", "max_issues_repo_name": "MattBurn/LAPACK95", "max_issues_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-02-21T10:46:38.000Z", "max_issues_repo_issues_event_max_datetime": "2017-10-20T17:03:14.000Z", "max_forks_repo_path": "src/la_sgesv.f90", "max_forks_repo_name": "MattBurn/LAPACK95", "max_forks_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-12-29T15:34:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-15T07:12:40.000Z", "avg_line_length": 37.8773584906, "max_line_length": 98, "alphanum_fraction": 0.5267745953, "num_tokens": 1221, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951104066293, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6582321946763265}} {"text": "!==========================================\n! rng.f90\n! Author: Devansh Shukla\n!------------------------------------------\nprogram rng_generator\n implicit none\n ! Define the variables\n integer :: A=0, C=0, M=0, x_0=0, x_1=0, i=0, n=10\n character(len=*), parameter :: fmt=\"(xI2,I6,I6)\"\n ! Open data file\n open(unit=8, file=\"random_no.dat\")\n ! Get input from user\n print *, \"Enter A, C, M, x0\"\n read *, A, C, M, x_0\n print *, \"Enter no of random numbers(n)\"\n read *, n\n print *, \"-----------------\"\n\n print \"(xA2x, A6, xxA6)\", \"i\", \"I(i)\", \"I(i+1)\"\n ! Compute\n do i = 0, n, 1\n ! Compute the pseudorandom number according to the\n ! given formula\n x_1 = mod(A*x_0 + C, M)\n write (*, fmt) i, x_0, x_1\n ! Writing the computed parameters to the data file\n write (8, fmt) i, x_0, x_1\n x_0 = x_1\n end do\n print *, \"-----------------\"\n ! Close file\n close(8)\n\nend program rng_generator\n", "meta": {"hexsha": "834d2db7d41359aade900d0e81c99aa1683a6f59", "size": 982, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "M9/rng.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": "M9/rng.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": "M9/rng.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": 28.0571428571, "max_line_length": 58, "alphanum_fraction": 0.482688391, "num_tokens": 316, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.7690802317779601, "lm_q1q2_score": 0.6582181984770129}} {"text": "SUBROUTINE stability(kv,gv,kdiag,tol,limit,iters,evec,eval)\r\n!\r\n! This subroutine computes the smallest eigenvalue in a beam\r\n! stability analysis.\r\n!\r\n IMPLICIT NONE\r\n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\r\n INTEGER,INTENT(IN)::limit,kdiag(:)\r\n INTEGER,INTENT(OUT)::iters\r\n INTEGER::neq\r\n REAL(iwp),INTENT(IN OUT)::kv(:),gv(:),tol,eval\r\n REAL(iwp),INTENT(OUT)::evec(:)\r\n REAL(iwp)::big,zero=0.0_iwp,one=1.0_iwp\r\n LOGICAL::converged\r\n REAL(iwp),ALLOCATABLE::x0(:),x1(:)\r\n neq=UBOUND(kdiag,1)\r\n ALLOCATE(x0(0:neq),x1(0:neq))\r\n CALL sparin(kv,kdiag)\r\n iters=0\r\n x0=zero\r\n x0(1)=1.0_iwp\r\n DO\r\n iters=iters+1\r\n CALL linmul_sky(gv,x0,x1,kdiag)\r\n CALL spabac(kv,x1,kdiag) \r\n big=MAXVAL(x1(1:))\r\n IF(ABS(MINVAL(x1(1:)))>big)big=MINVAL(x1(1:))\r\n x1=x1/big\r\n converged=(MAXVAL(ABS(x1(1:)-x0(1:)))/MAXVAL(ABS(x1(1:))) one .OR. p < zero .OR. p > one) RETURN\r\nifault = 0\r\nIF (p == zero .OR. p == one) RETURN\r\n\r\n! Calculate the constants needed for each Newton's iteration\r\n\r\na = (m - 1) / two\r\nb = (size - m) / two\r\nab = (size - 1) / two\r\nIF (MOD(m + 1, 2) == 0) THEN\r\n na = a + half\r\n ga = one\r\n DO i = 1, na\r\n ga = ga * i\r\n END DO\r\nELSE\r\n na = a + one\r\n ga = rp\r\n DO i = 1, na\r\n ga = ga * (i - half)\r\n END DO\r\nEND IF\r\nIF (MOD(size - m, 2) == 0) THEN\r\n nb = b - half\r\n gb = one\r\n DO i = 1, nb\r\n gb = gb * i\r\n END DO\r\nELSE\r\n nb = b\r\n gb = rp\r\n DO i = 1, nb\r\n gb = gb * (i - half)\r\n END DO\r\nEND IF\r\nIF (MOD(size - 1, 2) == 0) THEN\r\n nab = ab - half\r\n gab = one\r\n DO i = 1, nab\r\n gab = gab * i\r\n END DO\r\nELSE\r\n nab = ab\r\n gab = rp\r\n DO i = 1, nab\r\n gab = gab * (i - half)\r\n END DO\r\nEND IF\r\nq0 = (one - rho2) ** ab\r\ncoeff = gab / ga / gb\r\n\r\n! Use 0.5 as a starting value for Newton's iterations\r\n\r\ny = half\r\n\r\n! Perform Newton's iterations\r\n\r\nDO iter = 1, itrmax\r\n \r\n! Evaluate the first terms of the series for CDF (distribution\r\n! function) and PDF (density)\r\n \r\n n = one\r\n yp = one - y\r\n t = coeff * y ** a * yp ** b\r\n s = a * t / y / yp\r\n q = q0\r\n v = q\r\n cdf = v * t\r\n pdf = q * s\r\n \r\n! Check if a + n > (a + b + n)y\r\n \r\n 80 IF (a + n > (a + b + n) * y) GO TO 90\r\n \r\n! Evaluate the next terms of two series and then the\r\n! partial sums\r\n \r\n q = q * (a + b + n - one) * rho2 / n\r\n v = v + q\r\n s = t * (a + b + n - one) / yp\r\n t = t * y * (a + b + n - one) / (a + n)\r\n cdf = cdf + v * t\r\n pdf = pdf + q * s\r\n n = n + one\r\n GO TO 80\r\n \r\n! Find the error bounds and check for convergence for both\r\n! series\r\n \r\n 90 bndcdf = t * y * (a + b + n - one) / (a + n - (a + b + n) * y)\r\n bndpdf = t * (a + b + n - one) * (one - v) / yp\r\n 100 IF (bndcdf <= eps .AND. bndpdf <= eps) GO TO 110\r\n \r\n! Continue to update the terms and then accumulate\r\n \r\n q = q * (a + b + n - one) * rho2 / n\r\n v = v + q\r\n IF (bndcdf <= eps) THEN\r\n s = s * y * (a + b + n - one) / (a + n - one)\r\n pdf = pdf + q * s\r\n n = n + one\r\n bndpdf = s * y * (a + b + n - one) * (one - v) / (a + n - one)\r\n GO TO 100\r\n ELSE IF (bndpdf <= eps) THEN\r\n t = t * y * (a + b + n - one) / (a + n)\r\n cdf = cdf + v * t\r\n n = n + one\r\n bndcdf = t * y * (a+b+n-one) / (a+n - (a+b+n)*y)\r\n GO TO 100\r\n ELSE\r\n s = t * (a + b + n - one) / yp\r\n t = t * y * (a + b + n - one) / (a + n)\r\n cdf = cdf + v * t\r\n pdf = pdf + q * s\r\n n = n + one\r\n GO TO 90\r\n END IF\r\n \r\n! Obtain a new Y and make changes if it is illegal\r\n \r\n 110 diff = (cdf - p) / pdf\r\n ynew = y - diff\r\n IF (ynew <= zero) THEN\r\n y = y / two\r\n ELSE IF (ynew >= one) THEN\r\n y = (y + one) / two\r\n ELSE\r\n y = ynew\r\n END IF\r\n \r\n! Check for convergence of Newton's iterations\r\n \r\n IF (ABS(diff) <= delta * y) THEN\r\n quantile = y\r\n RETURN\r\n END IF\r\nEND DO\r\nifault = 1\r\nRETURN\r\nEND FUNCTION qr2\r\n\r\nEND MODULE rsquared\r\n\r\n\r\n\r\nPROGRAM main\r\n\r\n! This is a driver program that calls QR2 and produces output\r\n\r\nUSE rsquared\r\nIMPLICIT NONE\r\n\r\nINTEGER :: m, size, icode, k\r\nREAL :: rho2, p, y\r\n\r\n10 WRITE (*, 11)\r\n11 FORMAT (/' ENTER M (>1), N (>M), RHO2 (BETWEEN 0 AND 1), and', &\r\n /' P (BETWEEN 0 AND 1) FOR QR2 ==> ')\r\nREAD (*,*) m, size, rho2, p\r\ny = qr2(m, size, rho2, p)\r\nicode = ifault + 1\r\nSELECT CASE (icode)\r\n CASE (1)\r\n WRITE (*, 21) m, size, rho2, p, y\r\n 21 FORMAT (/' qr2(', i3, ',', i3, ',', g13.4, ',', g13.4, ') = ', g13.5)\r\n CASE (2)\r\n WRITE (*, 31)\r\n 31 FORMAT (/' NO convergence after 10 Newton ITERATIONS')\r\n CASE (3)\r\n WRITE (*, 41)\r\n 41 FORMAT (/' THE INPUT VALUE IS ILLEGAL!')\r\nEND SELECT\r\nWRITE (*, 61)\r\n61 FORMAT (/ ' ENTER 1 TO CONTINUE OR 0 TO QUIT ==> ')\r\nREAD (*,*) k\r\nIF (k == 1) GO TO 10\r\n\r\nSTOP\r\nEND PROGRAM main\r\n", "meta": {"hexsha": "6367efbff610e978ef76476ed9d4f7927833d95f", "size": 5763, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/as261.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/as261.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/as261.f90", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 24.3164556962, "max_line_length": 79, "alphanum_fraction": 0.5155301058, "num_tokens": 2029, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418137109956, "lm_q2_score": 0.7122321964553657, "lm_q1q2_score": 0.6582035538156278}} {"text": " program main\nc\nc ... array declarations.\nc\n implicit double precision (a-h, o-z)\n dimension coef(120,5), rhs(100), u(100), wksp(600), ubar(1),\n a rparm(30)\n integer jcoef(5), iwksp(300), iparm(30), p(100), ip(100)\n integer patt(2)\n external sor, sor7\nc\n ndim = 120\n mdim = 5\n nw = 600\n inw = 300\nc\nc ... generate coef, jcoef, and rhs.\nc\n nx = 10\n ny = 10\n nz = 1\n n = nx*ny\n h = 1.0d0/dble(nx + 1)\n maxnz = 3\n do i = 1,n \n coef(i,1) = 6.0d0\n coef(i,2) = -1.0d0\n coef(i,3) = -2.0d0\n rhs(i) = 0.0d0\n enddo\n k = 0\n do j = 1,ny\n y = dble(j)*h\n do i = 1,nx\n x = dble(i)*h\n k = k + 1\n if (j .eq. 1) then\n rhs(k) = rhs(k) + 2.0d0\n endif\n if (j .eq. ny) then\n rhs(k) = rhs(k) + 2.0d0*(1.0d0 + x)\n coef(k,3) = 0.0d0\n endif\n if (i .eq. 1) then\n rhs(k) = rhs(k) + 1.0d0\n endif\n if (i .eq. nx) then\n rhs(k) = rhs(k) + 1.0d0 + y\n coef(k,2) = 0.0d0\n endif\n enddo\n enddo\n jcoef(1) = 0\n jcoef(2) = 1\n jcoef(3) = nx \n call dfault (iparm,rparm)\nc\nc ... now, reset some default values.\nc\n iparm(3) = 3\n iparm(14) = 1 \n iparm(19) = nx\nc\nc ... generate an initial guess for u and call nspcg.\nc\n call vfill (n,u,0.0d0)\nc\n nxp = 1\n nyp = 2\n nzp = 1\n patt(1) = 1\n patt(2) = 2\n call color (nxp,nyp,nzp,nx,ny,nz,patt,p)\n call nspcg (sor7,sor,ndim,mdim,n,maxnz,coef,jcoef,p,ip,\n a u,ubar,rhs,wksp,iwksp,nw,inw,iparm,rparm,ier)\n stop\n end \n", "meta": {"hexsha": "53b73119844f9950a44bab883850dbd79dec0bc7", "size": 1776, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "svSolver-master/Code/ThirdParty/nspcg/simvascular_nspcg/tstnsp4.f", "max_stars_repo_name": "mccsssk2/SimVascularPM3_March2020", "max_stars_repo_head_hexsha": "3cce6cc7be66545bea5dc3915a2db50a3892bf04", "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": "svSolver-master/Code/ThirdParty/nspcg/simvascular_nspcg/tstnsp4.f", "max_issues_repo_name": "mccsssk2/SimVascularPM3_March2020", "max_issues_repo_head_hexsha": "3cce6cc7be66545bea5dc3915a2db50a3892bf04", "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": "svSolver-master/Code/ThirdParty/nspcg/simvascular_nspcg/tstnsp4.f", "max_forks_repo_name": "mccsssk2/SimVascularPM3_March2020", "max_forks_repo_head_hexsha": "3cce6cc7be66545bea5dc3915a2db50a3892bf04", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.7692307692, "max_line_length": 66, "alphanum_fraction": 0.4318693694, "num_tokens": 707, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276224, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.6581332684112986}} {"text": "FUNCTION isPerfect(n)\n LOGICAL :: isPerfect\n INTEGER, INTENT(IN) :: n\n INTEGER :: i, factorsum\n\n isPerfect = .FALSE.\n factorsum = 1\n DO i = 2, INT(SQRT(REAL(n)))\n IF(MOD(n, i) == 0) factorsum = factorsum + i + (n / i)\n END DO\n IF (factorsum == n) isPerfect = .TRUE.\nEND FUNCTION isPerfect\n", "meta": {"hexsha": "9cba187468885d3d7e4d12d249ff7186b2772ddd", "size": 301, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Perfect-numbers/Fortran/perfect-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/Perfect-numbers/Fortran/perfect-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/Perfect-numbers/Fortran/perfect-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": 23.1538461538, "max_line_length": 59, "alphanum_fraction": 0.6179401993, "num_tokens": 108, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533126145179, "lm_q2_score": 0.7057850154599562, "lm_q1q2_score": 0.6581115756593249}} {"text": "program calculator\n real :: a, b, calcResult\n character*3 :: operation\n\n print *, \"Hello Fortran! Which Operation?(add, sub, mul, div)\"\n read *, operation\n\n print *, \"Which X?\"\n read *, a\n\n print *, \"Which Y?\"\n read *, b\n\n if (operation .EQ. 'add') then \n calcResult = a + b\n \n else if (operation .EQ. 'sub') then \n calcResult = a - b\n \n else if (operation .EQ. 'mul') then \n calcResult = a * b\n \n else if (operation .EQ. 'div') then \n if ( b .EQ. 0) then\n print *, \"Error: Division with Zero.\"\n else\n calcResult = a / b\n end if\n \n end if\n\n print *, \"Result is: \"\n print *, calcResult\nend program calculator\n", "meta": {"hexsha": "c176064822cf54f939ed057ce7dcd8094406114a", "size": 658, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "calculator.f90", "max_stars_repo_name": "lisprolog/calculators", "max_stars_repo_head_hexsha": "cbfbd602da396699739c47d44c613a0a2ee67f66", "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": "calculator.f90", "max_issues_repo_name": "lisprolog/calculators", "max_issues_repo_head_hexsha": "cbfbd602da396699739c47d44c613a0a2ee67f66", "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": "calculator.f90", "max_forks_repo_name": "lisprolog/calculators", "max_forks_repo_head_hexsha": "cbfbd602da396699739c47d44c613a0a2ee67f66", "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": 18.8, "max_line_length": 64, "alphanum_fraction": 0.5744680851, "num_tokens": 206, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619263765707, "lm_q2_score": 0.7981867705385762, "lm_q1q2_score": 0.6580746024465284}} {"text": " PROGRAM numint\n\n IMPLICIT none\n INTEGER NMAX\n PARAMETER (NMAX=100000)\n REAL*8 x(NMAX),f(NMAX),fint(NMAX),dx\n CHARACTER*30 ifile,ofile\n LOGICAL ex\n INTEGER i,ntot\n\nC----\nC Get file names from command line\nC----\n call gcmdln(ifile,ofile)\n inquire(file=ifile,EXIST=ex)\n if (.not.ex) then\n write(*,*) 'No input file:',ifile\n call usage()\n endif\n\nC----\nC Read data series\nC----\n open(unit=11,file=ifile,status='old')\n i = 1\n 101 read(11,*,end=102) x(i),f(i)\n i = i + 1\n goto 101\n 102 continue\n ntot = i - 1\n\nC----\nC Trapezoidal integration\nC----\n fint(1) = 0.0d0\n do 103 i = 2,ntot\n dx = x(i) - x(i-1)\n fint(i) = fint(i-1) + dx*0.5d0*(f(i)+f(i-1))\n 103 continue\n\nC----\nC Write integrated data series\nC----\n open(unit=12,file=ofile,status='unknown')\n do 104 i = 1,ntot\n write(12,*) x(i),fint(i)\n 104 continue\n END\n\nC======================================================================C\n\n SUBROUTINE gcmdln(ifile,ofile)\n IMPLICIT none\n CHARACTER*30 tag,ifile,ofile\n INTEGER i,narg\n\n ifile = 'numint.in'\n ofile = 'numint.out'\n \n narg = iargc()\n if (narg.eq.0) call usage()\n i = 0\n 101 i = i + 1\n if (i.gt.narg) goto 102\n call getarg(i,tag)\n if (tag(1:2).eq.'-h'.or.tag(1:2).eq.'-?') then\n call usage()\n elseif (tag(1:2).eq.'-f') then\n i = i + 1\n call getarg(i,ifile)\n elseif (tag(1:2).eq.'-o') then\n i = i + 1\n call getarg(i,ofile)\n endif\n goto 101\n 102 continue\n\n RETURN\n END\n\nC----------------------------------------------------------------------C\n\n SUBROUTINE usage()\n IMPLICIT none\n write(*,*)\n 1 'Usage: numint -f [IFILE] -o [OFILE] -h/-?'\n write(*,*)\n 1 ' -f [IFILE] (Default numint.in) name of input file'\n write(*,*)\n 1 ' -o [OFILE] (Default numint.out) name of output file'\n write(*,*)\n 1 ' -h/-? Online help (this screen)'\n write(*,*)\n write(*,*)\n 1 'numint numerically integrates a time series using trapezoidal',\n 2 ' integration'\n write(*,*)\n write(*,*)\n 1 ' Input files'\n write(*,*)\n 1 ' numint.in: data series'\n write(*,*)\n 1 ' t1 f(t1)'\n write(*,*)\n 1 ' :'\n write(*,*)\n write(*,*)\n 1 ' Output files'\n write(*,*)\n 1 ' numint.out: integral of data series (starting from first',\n 2 ' entry)'\n write(*,*)\n 1 ' t1 F(t1)'\n write(*,*)\n 1 ' :'\n STOP\n END\n", "meta": {"hexsha": "d9155c39b7b43b8a2e833d2d079c73f313608796", "size": 2730, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/numint.f", "max_stars_repo_name": "mherman09/src", "max_stars_repo_head_hexsha": "98667f7a2f2e724f2544b6aa1fe7ff278cbf4801", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/numint.f", "max_issues_repo_name": "mherman09/src", "max_issues_repo_head_hexsha": "98667f7a2f2e724f2544b6aa1fe7ff278cbf4801", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2017-06-27T16:35:46.000Z", "max_issues_repo_issues_event_max_datetime": "2017-07-16T14:55:39.000Z", "max_forks_repo_path": "src/numint.f", "max_forks_repo_name": "mherman09/src", "max_forks_repo_head_hexsha": "98667f7a2f2e724f2544b6aa1fe7ff278cbf4801", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.1355932203, "max_line_length": 72, "alphanum_fraction": 0.4538461538, "num_tokens": 861, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619177503205, "lm_q2_score": 0.7981867753392728, "lm_q1q2_score": 0.6580745995191611}} {"text": "!===================================================================\n! Randomly places parcels with variable volume in the domain\n!===================================================================\n\nprogram ranpar\n\n !Import parameters and constants:\nuse constants\n\nimplicit none\n\n !Total number of parcels:\ninteger:: n\n\n !Parcel positions (x,z) and area fractions:\ndouble precision:: x(nm),z(nm),v(nm)\n\n !Other variables:\ndouble precision:: vrange,fac\ninteger, dimension(:), allocatable :: seed\ninteger:: i,k,ngen\n\n!---------------------------------------------------------------------\n! Generate parcel positions and volumes:\nwrite(*,*) ' Enter the average number of parcels per grid cell:'\nread(*,*) fac\nn=nint(fac*dble(ncell))\n\nwrite(*,*) ' We assume any parcel area is equally probable.'\nwrite(*,*) ' Enter A_max/A_min:'\nread(*,*) vrange\n\nwrite(*,*) ' Enter an integer seed for the random number generator:'\nread(*,*) ngen\ncall random_seed(size=k)\nallocate(seed(1:k))\nseed(:)=ngen\ndo i=1,ngen\n call random_seed(put=seed)\nenddo\n\nvrange=vrange-1.d0\ndo i=1,n\n call random_number(fac)\n x(i)=ellx*fac+xmin\n call random_number(fac)\n z(i)=ellz*fac+zmin\n call random_number(fac)\n v(i)=vrange*fac+1.d0\nenddo\n\n! Re-normalise so that sum(v) = ncell = nx*nz:\nfac=dble(ncell)/sum(v(1:n))\nv(1:n)=fac*v(1:n)\n\n!---------------------------------------------------------------------\n! Write parcel positions and area fractions (of grid cell volume):\nopen(80,file='ini_parcels.asc',status='replace')\nwrite(80,*) n\ndo i=1,n\n write(80,*) x(i),z(i),v(i)\nenddo\nclose(80)\n\nwrite(*,*)\nwrite(*,*) ' The initial parcels are in ini_parcels.asc'\nwrite(*,*)\n\n !End main program\nend program ranpar\n", "meta": {"hexsha": "4bd7299effd2d5a8c968dad6ae4d3852529ad02c", "size": 1682, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "merging_standalone/2d/ranpar.f90", "max_stars_repo_name": "matt-frey/epic", "max_stars_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2021-11-11T10:50:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T00:11:41.000Z", "max_issues_repo_path": "merging_standalone/2d/ranpar.f90", "max_issues_repo_name": "matt-frey/epic", "max_issues_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 47, "max_issues_repo_issues_event_min_datetime": "2021-11-12T17:09:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-24T16:50:58.000Z", "max_forks_repo_path": "merging_standalone/2d/ranpar.f90", "max_forks_repo_name": "matt-frey/epic", "max_forks_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.6901408451, "max_line_length": 70, "alphanum_fraction": 0.5844233056, "num_tokens": 446, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513842182777, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6579556473795016}} {"text": "*dk, guass_elim_lg\n subroutine guass_elim_lg(flag,n,LDA,epsilon,A,b,x\n & ,wrkmat,ierror)\n \nC #####################################################################\nC\nC PURPOSE -\nC\nC solve general Ax=b using Gaussian elimination.\nC (A can be singular and non-symmetric, but must be square).\nC\nC INPUT ARGUMENTS -\nC\nC A - the array to invert\nC LDA - MAX first dimension of A to get storage correct\nC n - dimension of problem: A(1:n,1:n)*x(1:n)=b(1:n)\nC b - the (input) b vector in Ax=b\nC epsilon - relative accuracy\nC The average eigenvalue of b is computed as |Ab|/|b|,\nC and hence |x|~|b|/(|Ab|/|b|). Corrections dx to the estimate along\nC eigendirections of A with significantly smaller eigenvalues\nC give large changes to x for negligible improvement to |Ax-b|.\nC epsilon is used for the relative tests as appropriate.\nC flag - switch to indicate whether to calculate solution of\nC (1) Ax=b\nC (2) (A^2+eps^2*I)x=Ab where I(i,j)=(1 if i=j, 0 otherwise)\nC [solve (A+i*eps)x=b in sense of Hadamard principle part]\nC\nC OUTPUT ARGUMENTS -\nC\nC x - the (output) solution vector x to Ax=b\nC ierror - set on return to\nC -1 if A=0 and b.ne.0\nC 0 if (|Ax-b|/|b|)^2 < epsilon,\nC 1+min((|Ax-b|/|b|)^2/(10*epsilon),1000000)\nC otherwise\nC |Ax-b|/|b| < epsilon should also hold\nC but using this softer test for the error return.\nC\nC WORKSPACE ARGUMENTS -\nC\nC wrkmat - nxn matrix workspace (contents ignored)\nC\nC SPELLING NOTES -\nC\nC oops: Gauss is spelled \"gauss\" not \"guass\",\nC but since I checked in in that way I guess it'll stay ...\nC\nC PROGRAMMING NOTES -\nC\nC The basic code is a straightforward implementation of\nC Gaussian elimination. The modifications here are\nC giving the user the choice to solve (A^2+eps*I)x=Ab\nC (Hadamard principle part) for (nearly) singular matricies,\nC and putting in the epsilon tests (and calculating the scale\nC for epsilon). As it is a principle part, flag=2 approaches\nC epsilon=0 as a well defined limit, whereas flag=1 can be\nC \"unpredictable\" especially for the nearly singular case.\nC\nC For nearly singular matricies where \"wild\" contributions (essentially\nC unrestricted small eigenvalue components) to x are undesireable,\nC using flag=2 and epsilon \"relatively large\" (1.e-2 to 1.e-4)\nC is recommended. This also works pretty well for the non-singular cases.\nC\nC Using flag=1 (straightforward Ax=b solution)\nC has accuracy problems in certain cases, eg for the 2x2 problem\nC ( 0 1 ) (x1) ( 1 ) (x1) (0.999977878280)\nC ( 1 0 ) (x2) = ( 1 ) one gets (x2) = (0.999999999999) for epsilon=1.e-12;\nC flag=2 is more stable, although for large matricies it is slightly\nC more inefficient since the matrix has to be squared. (There is one\nC other \"N^3\" loop in this code, so it is not a huge overhead compare to\nC flag=1 -- the coding presumption is that the dimension of the matrix A\nC is typically n=3 and not n=1000...)\nC However, note that for flag=1 \"often\" |Ax-b|/|b| << epsilon,\nC whereas for flag=2 |Ax-b|/|b| ~ epsilon \"almost always\".\nC\nC Although not coded here, a \"best\" epsilon could also be selected\nC by minimizing a functional showing a minimum and having the\nC appropriate symmetry properties, such as\nC chisq=|x|^2*(Tr A^2 + 3 eps^2)^2\nC or looking to see if/where |x|-|b|/(|Ab|/|b|) change sign.\nC (These are 2 empirical tests that worked fairly well for\nC the set of small matricies I looked at, which came from\nC typical cases projecting face velocity onto node velocity.)\nC\nC Also compare solv_Mxb_schmidt_hilbert_lg (forms inverse with Schmidt-Hilbert).\nC For large matrices, using an iterative sparse solver such as GMRES is recommended\nC\nC CHANGE HISTORY -\nC\nC $Log: guass_elim_lg.f,v $\nC Revision 2.00 2007/11/03 00:49:10 spchu\nC Import to CVS\nC\nCPVCS \nCPVCS Rev 1.7 17 Feb 2001 14:19:24 jtg\nCPVCS fixed log line; Rev 1.6=correctly did Rev 1.5\nCPVCS \nCPVCS Rev 1.5 Wed Mar 08 15:40:30 2000 dcg\nCPVCS change debug flag so that error messages are not written\nCPVCS return flag will have error status\nCPVCS\nCPVCS Rev 1.2 Mon Dec 13 10:47:16 1999 jtg\nCPVCS Noted Gauss is spelled wrong\nCPVCS\nCPVCS Rev 1.1 Wed Dec 01 15:43:52 1999 jtg\nCPVCS set local_debug to 0\nCPVCS\nCPVCS Rev 1.0 Wed Dec 01 14:35:32 1999 jtg\nCPVCS Initial revision.\nC\nC ######################################################################\n \n implicit none\n \n integer n,LDA,flag,ierror\n \n real*8 x(n),b(n),A(LDA,n),wrkmat(n,n)\n & ,epsilon\n \n integer i,j,k,local_debug\n real*8 eps,b2,Ab2,xxx\n character*132 cbuf\n \nc ---------------------------------------------------------------\n local_debug=0\n \nc ...............................\nc fill wrkmat,x from A,b\n \n if (flag.eq.2) then\n ! set wrkmat=A^2, x=Ab\n ! obviously wrkmat and A, and x and b, need to be separate storage\n ! locations for this flag case.\n do i=1,n\n x(i)=0.d0\n do j=1,n\n x(i)=x(i)+A(i,j)*b(j)\n wrkmat(i,j)=0.d0\n do k=1,n\n wrkmat(i,j)=wrkmat(i,j)+A(i,k)*A(k,j)\n enddo\n enddo\n enddo\n else\n ! set wrkmat=A, x=b\n ! except for the final test comparing |Ax-b|/|b|,\n ! wrkmat and A, and x and b, could have been indentical storage locations.\n do i=1,n\n x(i)=b(i)\n do j=1,n\n wrkmat(i,j)=A(i,j)\n enddo\n enddo\n endif\n \nc ...............................\nc figure out eps from epsilon and |Ab|/|b|\nc eps is used to screen out singular components\n \nc calculate scale of A and b\n Ab2=0.d0\n b2=0.d0\n do i=1,n\n b2=b2+x(i)*x(i)\n xxx=0.d0\n do j=1,n\n xxx=xxx+wrkmat(i,j)*x(j)\n enddo\n Ab2=Ab2+xxx*xxx\n enddo\n \nc abort if solution trivial (b=0), or no soln possible (A=0)\n if (b2.eq.0.d0 .or. Ab2.eq.0.d0) then\n do i=1,n\n x(i)=0.d0\n enddo\n goto 100\n endif\n \nc set absolute eps for iteration, update diagonal for flag=2\n xxx=sqrt(Ab2/b2)\n eps=epsilon*xxx\n if (flag.eq.2) then\n ! vs using xxx=Tr(wrkmat)/dble(n) (average eigenvalue of A^2)\n ! if along small eigenvalue direction, I am presuming current\n ! xxx=sqrt(Ab2/b2) (average eigenvalue component in Ab) better ...\n xxx=eps*epsilon ! wrkmat = ( A^2 + epsilon^2 * scale(A^2) )\n do i=1,n\n wrkmat(i,i)=wrkmat(i,i)+xxx\n enddo\n ! solve as for unsquared case, but with smaller epsilon?\n ! which version to use ... does it make a difference?\n ! eps=eps\n eps=1.d-4*eps\n ! eps=epsilon*eps\n endif\n \nc ...............................\nc solve using Gaussian elimination,\nc testing the diagonals of A against eps to avoid dividing by zero\n \n do k=1,n-1\n do i=k+1,n\n xxx=wrkmat(k,k)\n if (abs(xxx).gt.eps) then\n xxx=1.d0/xxx\n elseif (xxx.lt.0.d0.and.flag.ne.2) then\n xxx=-1.d0/eps\n else\n xxx=1.d0/eps\n endif\n xxx=xxx*wrkmat(i,k)\n x(i)=x(i)-x(k)*xxx\n do j=k+1,n\n wrkmat(i,j)=wrkmat(i,j)-wrkmat(k,j)*xxx\n enddo\n enddo\n enddo\n \n do i=n,1,-1\n do j=i+1,n\n x(i)=x(i)-wrkmat(i,j)*x(j)\n enddo\n xxx=wrkmat(i,i)\n if (abs(xxx).gt.eps) then\n xxx=1.d0/xxx\n elseif (xxx.lt.0.d0.and.flag.ne.2) then\n xxx=-1.d0/eps\n else\n xxx=1.d0/eps\n endif\n x(i)=x(i)*xxx\n enddo\n \nc ...............................\nc test how good a solution and update ierror\nc have to redo b2 since for flag=2 it is |Ab| rather than |b|\n \n100 ierror=0\n \n b2=0.d0\n Ab2=0.d0\n do i=1,n\n xxx=-b(i)\n do j=1,n\n xxx=xxx+A(i,j)*x(j)\n enddo\n Ab2=Ab2+xxx*xxx\n b2=b2+b(i)*b(i)\n enddo\n \n if (local_debug.ne.0) then\n write(*,'(a,4g20.10)') 'gauss_elim_lg: |Ax-b|,|b|,epsilon='\n & ,sqrt(Ab2),sqrt(b2),(sqrt(Ab2)/sqrt(b2))/epsilon\n & ,epsilon\n endif\n \n if (b2.ne.0.d0) then\n ! actually, should test sqrt(Ab2/b2) against epsilon,\n ! but since this is a \"hard error flag\" (0 vs non-zero), use epsilon instead\n xxx=Ab2/b2\n if (epsilon.ne.0.d0) xxx=xxx/epsilon\n if (xxx.gt.1.d0) then\n if (xxx.gt.10000000.d0) then\n ierror=1000000\n else\n ierror=1+int(xxx*0.1d0)\n endif\n endif\n elseif (Ab2.ne.0.d0) then\n ierror=-1\n endif\n \n if (ierror.ne.0.and.local_debug.ne.0) then\n write(cbuf,'(a,3g15.5)')\n & 'gauss_elim_lg warning: (||Ax-b|/|b|)^2 > epsilon;'\n & //' |Ax-b|,|b|,epsilon=',sqrt(Ab2),sqrt(b2),epsilon\n call writloga('default',0,cbuf,0,i)\n endif\n \nc ...............................\n return\n end\n \nccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\n", "meta": {"hexsha": "3eedef6e5c13c251302819e60bacafdc0160b493", "size": 10035, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "lg_util/src/guass_elim_lg.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": "lg_util/src/guass_elim_lg.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_util/guass_elim_lg.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": 34.9651567944, "max_line_length": 90, "alphanum_fraction": 0.5288490284, "num_tokens": 2942, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513675912912, "lm_q2_score": 0.7341195327172401, "lm_q1q2_score": 0.657955635173306}} {"text": "!\r\n! Find statistics of mean and covariance matrix of underlying latent vector.\r\n!\r\n\r\n! covinverse is the estimated inverse of the covariance matrix of the underlying latent vector corresponding to beta.\r\n\r\n!\tcovlin is the estimated covariance matrix of the linear component of beta.\r\n!\tcovlinquad is the estimated covariance matrix of the linear and quadratic components of beta.\r\n! covmatrix is the estimated covariance matrix of the underlying latent vector corresponding to beta.\r\n!\tcovquad is the estimated covariance matrix of the quadratic component of beta.\r\n!\tmeanvec is the estimated mean of the underlying latent vector.\r\n\r\n! covcovmatrix is the estimated covariance matrix of covmatrix.\r\n! covmeanvec is the estimated covariance matrix of meanvec.\r\n! Note that this routine is for the case of an underlying normal latent vector.\r\nsubroutine covmatstat(covinverse,covlin, covlinquad,covmatrix,covquad,meanvec,covcovmatrix,covmeanvec)\r\nimplicit none\r\ninterface\r\n\r\n!\tAsymptotic covariance matrix of matrix inverse of symmetric matrix.\r\n!\tInput is matrix mat, its inverse matinv and its covariance matrix covmat.\r\n!\tOutput is the asymptotic covariance matrix of matinv.\r\n\tfunction covmatinv(mat,matinv,covmat)\r\n\t\timplicit none\r\n\t\treal(kind=8),intent(in)::mat(:,:),matinv(:,:),covmat(:,:,:,:)\r\n\t\treal(kind=8)::covmatinv(size(mat,1),size(mat,1),size(mat,1),size(mat,1))\r\n\tend function covmatinv\r\n! Expand covariance matrix of matrix from compact format.\r\n\tfunction expandcovmat(n,covmat)\r\n\t\timplicit none\r\n\t\tinteger,intent(in)::n\r\n\t\treal(kind=8),intent(in)::covmat(:,:)\r\n\t\treal(kind=8)::expandcovmat(n,n,n,n)\r\n\tend function expandcovmat\r\n!\tconvert an n by n symmetric matrix from compact to regular form.\r\n\tfunction expandmat(n,compmat)\r\n\t\timplicit none\r\n\t\tinteger,intent(in)::n\r\n\t\treal(kind=8),intent(in)::compmat(:)\r\n\t\treal(kind=8)::expandmat(n,n)\r\n\tend function expandmat\r\n\r\n!\t\tThis program uses the modified Cholesky decomposition\r\n!\t\tin lu to solve the equation lusolve = b.\r\n\r\n\tsubroutine makesym(matrix)\r\n!\tSymmetrize n by n matrix based on lower triangle.\r\n\t\timplicit none\r\n\t\treal(kind=8),intent(inout)::matrix(:,:)\r\n\tend subroutine makesym\r\n\r\n\r\nend interface\r\nreal(kind=8),intent(in)::covinverse(:,:),covlin(:,:),covlinquad(:,:),covmatrix(:,:),covquad(:,:),meanvec(:)\r\nreal(kind=8),intent(out)::covcovmatrix(:,:,:,:),covmeanvec(:,:)\r\n! dimlatin is the dimension of the underlying covariance matrix.\r\n\r\n! row counts elements of latent vectors.\r\n! row1 counts elements of latent vectors.\r\n\r\ninteger::dimlatin,row,row1\r\n! covmeanvec1,covmeanvec2, and covmeanvec3 are components of covmeanvec.\r\n! covquade is the expanded covariance matrix of the quadratic component of beta.\r\n\r\nreal(kind=8)::covmeanvec1(size(covmatrix,1),size(covmatrix,1)),&\r\n\tcovmeanvec2(size(covmatrix,1),size(covmatrix,1),size(covmatrix,1)),&\r\n\tcovmeanvec3(size(covmatrix,1),size(covmatrix,1)),&\r\n\tcovquade(size(covmatrix,1),size(covmatrix,1),size(covmatrix,1),size(covmatrix,1))\r\n\t\r\n! Find dimension of underlying latent vector.\r\ndimlatin=size(covmatrix,1)\r\n\r\n\r\n\r\n!\tCovariance matrix of linear part.\r\n\r\n\r\ncovquade=expandcovmat(dimlatin,covquad)\r\ncovcovmatrix=covmatinv(covinverse,covmatrix,covquade)\r\ndo row=1,dimlatin\r\n\t\r\n\tcovmeanvec1(row,:)=matmul(expandmat(dimlatin,covlinquad(row,:)),meanvec)\r\n\tdo row1=1,dimlatin\r\n\t\tcovmeanvec2(row,:,row1)=matmul(covquade(row,:,row1,:),meanvec)\r\n\t\tcovmeanvec3(row,row1)=sum(covmeanvec2(row,:,row1)*meanvec)\r\n\tend do\r\nend do\r\n\r\ndo row=1,dimlatin\r\n\tdo row1=1,row\r\n\t\tcovmeanvec(row,row1)=covlin(row,row1)-covmeanvec1(row,row1)-covmeanvec1(row1,row)+covmeanvec3(row,row1)\r\n\tend do\r\nend do\r\ncall makesym(covmeanvec)\r\ncovmeanvec=matmul(covinverse,matmul(covmeanvec,covinverse))\t\t\r\nend subroutine covmatstat", "meta": {"hexsha": "f3f28101f503200d754202dff425c64f9fed704d", "size": 3748, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Source/covmatstat.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/covmatstat.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/covmatstat.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": 39.0416666667, "max_line_length": 120, "alphanum_fraction": 0.7449306297, "num_tokens": 1019, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425311777929, "lm_q2_score": 0.7154239836484143, "lm_q1q2_score": 0.6579343231877277}} {"text": "C\nC\t$Id: csareas.f,v 1.5 2008-07-27 03:10:05 haley Exp $\nC \nC Copyright (C) 2000\nC University Corporation for Atmospheric Research\nC All Rights Reserved\nC\nC The use of this Software is governed by a License Agreement.\nC\n DOUBLE PRECISION FUNCTION CSAREAS (V1,V2,V3)\n DOUBLE PRECISION V1(3), V2(3), V3(3)\nC\nC***********************************************************\nC\nC From STRIPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 06/22/98\nC\nC This function returns the area of a spherical triangle\nC on the unit sphere.\nC\nC\nC On input:\nC\nC V1,V2,V3 = Arrays of length 3 containing the Carte-\nC sian coordinates of unit vectors (the\nC three triangle vertices in any order).\nC These vectors, if nonzero, are implicitly\nC scaled to have length 1.\nC\nC Input parameters are not altered by this function.\nC\nC On output:\nC\nC CSAREAS = Area of the spherical triangle defined by\nC V1, V2, and V3 in the range 0 to 2*PI (the\nC area of a hemisphere). CSAREAS = 0 (or 2*PI)\nC if and only if V1, V2, and V3 lie in (or\nC close to) a plane containing the origin.\nC\nC Modules required by CSAREAS: None\nC\nC Intrinsic functions called by CSAREAS: ACOS, SQRT\nC\nC***********************************************************\nC\n DOUBLE PRECISION A1, A2, A3, CA1, CA2, CA3, S12, S23,\n . S31, U12(3), U23(3), U31(3)\n INTEGER I\nC\nC Local parameters:\nC\nC A1,A2,A3 = Interior angles of the spherical triangle\nC CA1,CA2,CA3 = cos(A1), cos(A2), and cos(A3), respectively\nC I = DO-loop index and index for Uij\nC S12,S23,S31 = Sum of squared components of U12, U23, U31\nC U12,U23,U31 = Unit normal vectors to the planes defined by\nC pairs of triangle vertices\nC\nC\nC Compute cross products Uij = Vi X Vj.\nC\n U12(1) = V1(2)*V2(3) - V1(3)*V2(2)\n U12(2) = V1(3)*V2(1) - V1(1)*V2(3)\n U12(3) = V1(1)*V2(2) - V1(2)*V2(1)\nC\n U23(1) = V2(2)*V3(3) - V2(3)*V3(2)\n U23(2) = V2(3)*V3(1) - V2(1)*V3(3)\n U23(3) = V2(1)*V3(2) - V2(2)*V3(1)\nC\n U31(1) = V3(2)*V1(3) - V3(3)*V1(2)\n U31(2) = V3(3)*V1(1) - V3(1)*V1(3)\n U31(3) = V3(1)*V1(2) - V3(2)*V1(1)\nC\nC Normalize Uij to unit vectors.\nC\n S12 = 0.D0\n S23 = 0.D0\n S31 = 0.D0\n DO 2 I = 1,3\n S12 = S12 + U12(I)*U12(I)\n S23 = S23 + U23(I)*U23(I)\n S31 = S31 + U31(I)*U31(I)\n 2 CONTINUE\nC\nC Test for a degenerate triangle associated with collinear\nC vertices.\nC\n IF (S12 .EQ. 0.D0 .OR. S23 .EQ. 0.D0 .OR.\n . S31 .EQ. 0.D0) THEN\n CSAREAS = 0.D0\n RETURN\n ENDIF\n S12 = SQRT(S12)\n S23 = SQRT(S23)\n S31 = SQRT(S31)\n DO 3 I = 1,3\n U12(I) = U12(I)/S12\n U23(I) = U23(I)/S23\n U31(I) = U31(I)/S31\n 3 CONTINUE\nC\nC Compute interior angles Ai as the dihedral angles between\nC planes:\nC CA1 = cos(A1) = -\nC CA2 = cos(A2) = -\nC CA3 = cos(A3) = -\nC\n CA1 = -U12(1)*U31(1)-U12(2)*U31(2)-U12(3)*U31(3)\n CA2 = -U23(1)*U12(1)-U23(2)*U12(2)-U23(3)*U12(3)\n CA3 = -U31(1)*U23(1)-U31(2)*U23(2)-U31(3)*U23(3)\n IF (CA1 .LT. -1.D0) CA1 = -1.D0\n IF (CA1 .GT. 1.D0) CA1 = 1.D0\n IF (CA2 .LT. -1.D0) CA2 = -1.D0\n IF (CA2 .GT. 1.D0) CA2 = 1.D0\n IF (CA3 .LT. -1.D0) CA3 = -1.D0\n IF (CA3 .GT. 1.D0) CA3 = 1.D0\n A1 = ACOS(CA1)\n A2 = ACOS(CA2)\n A3 = ACOS(CA3)\nC\nC Compute CSAREAS = A1 + A2 + A3 - PI.\nC\n CSAREAS = A1 + A2 + A3 - ACOS(-1.D0)\n IF (CSAREAS .LT. 0.D0) CSAREAS = 0.D0\n RETURN\n END\n", "meta": {"hexsha": "1561eb79109c2e9e3e2d4ddc7dae7fa04293a7bd", "size": 4085, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ngmath/src/lib/gridpack/cssgrid/csareas.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "ngmath/src/lib/gridpack/cssgrid/csareas.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "ngmath/src/lib/gridpack/cssgrid/csareas.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 31.1832061069, "max_line_length": 71, "alphanum_fraction": 0.4913096695, "num_tokens": 1515, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853654, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.6578364824355207}} {"text": "module energies\n\n! Calculates Hydrogen nonrelativistic and relativistic energies (exact),\n! Thomas-Fermi (TF) energies (only very approximate), TF potential and charge\n! density (very accurate).\n\nuse types, only: dp\nuse utils, only: stop_error\nuse constants, only: pi\nimplicit none\nprivate\npublic E_nl, thomas_fermi_potential, get_tf_energies, get_hydrogen_energies, &\n thomas_fermi_density\n\ncontains\n\nreal(dp) function E_nl(c, n, l, Z, relat)\n! Calculates exact energy for the radial Schroedinger/Dirac equations\nreal(dp), intent(in) :: c ! speed of light in atomic units\ninteger, intent(in) :: n, l, Z, relat\n! quantum numbers (n, l), atomic number (z)\n! relat == 0 ... Schroedinger equation\n! relat == 2 ... Dirac equation, spin up\n! relat == 3 ... Dirac equation, spin down\n\ninteger :: kappa\nreal(dp) :: beta\nif (.not. (l >= 0)) call stop_error(\"'l' must be positive or zero\")\nif (.not. (n > l)) call stop_error(\"'n' must be greater than 'l'\")\nif (l == 0 .and. relat == 3) call stop_error(\"Spin must be up for l==0.\")\nif (relat == 0) then\n E_nl = - Z**2 / (2.0_dp * n**2)\nelse\n if (relat == 2) then\n kappa = -l - 1\n else\n kappa = l\n end if\n beta = sqrt(kappa**2 - (Z/c)**2)\n E_nl = c**2/sqrt(1 + (Z/c)**2/(n - abs(kappa) + beta)**2) - c**2\nend if\nend function\n\nfunction thomas_fermi_potential(R, Z, cut) result(V)\n! Generalized Thomas-Fermi atomic potential\nreal(dp), intent(in) :: R(:) ! Radial grid\ninteger, intent(in) :: Z ! Atomic number\nlogical, intent(in), optional :: cut ! Cut the potential, default .true.\nreal(dp) :: x(size(R)), Z_eff(size(R)), V(size(R))\nreal(dp) :: alpha, beta, gamma\n\nx = R * (128*Z/(9*pi**2)) ** (1.0_dp/3)\n! Z_eff(x) = Z * phi(x), where phi(x) satisfies the Thomas-Fermi equation:\n! phi'' = phi**(3/2) / sqrt(x)\n! with boundary conditions:\n! phi(0) = 1\n! phi(oo) = 0\n! There is no analytic solution, but one can solve this approximately. We use:\n! http://arxiv.org/abs/physics/0511017\nalpha = 0.7280642371_dp\nbeta = -0.5430794693_dp\ngamma = 0.3612163121_dp\nZ_eff = Z * (1 + alpha*sqrt(x) + beta*x*exp(-gamma*sqrt(x)))**2 * &\n exp(-2*alpha*sqrt(x))\n! This keeps all the eigenvalues of the radial problem negative:\nif (.not. present(cut)) where (Z_eff < 1) Z_eff = 1\nV = -Z_eff / r\nend function\n\nfunction thomas_fermi_density(R, Z) result(rho)\n! Generalized Thomas-Fermi atomic potential\nreal(dp), intent(in) :: R(:) ! Radial grid\ninteger, intent(in) :: Z ! Atomic number\nreal(dp) :: V(size(R)), rho(size(R))\nV = thomas_fermi_potential(R, Z, .false.)\nrho = -1 / (3*pi**2) * (-2*V)**(3._dp/2)\nend function\n\nfunction get_tf_energies(Z, no, fo) result(E)\ninteger, intent(in) :: Z, no(:)\nreal(dp), intent(in) :: fo(:)\nreal(dp) :: E(size(no))\n\ninteger :: Zeff, i\nZeff = Z + 1\ndo i = 1, size(no)\n if (i > 1) then\n if (no(i) < no(i-1)) call stop_error(\"State order wrong\")\n end if\n Zeff = Zeff - int(fo(i))\n if (Zeff <= 0) call stop_error(\"Negative ions not allowed\")\n E(i) = -(1.0_dp * Zeff / no(i))**2/2\nend do\nend function\n\nfunction get_hydrogen_energies(Z, no) result(E)\ninteger, intent(in) :: Z, no(:)\nreal(dp) :: E(size(no))\ninteger :: i\ndo i = 1, size(no)\n E(i) = -1.0_dp * Z**2 / (2*no(i)**2)\nend do\nend function\n\nend module\n", "meta": {"hexsha": "5848c8933893f91b98e78133c42458305d7f697a", "size": 3238, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/energies.f90", "max_stars_repo_name": "rc/dftatom", "max_stars_repo_head_hexsha": "fe479fd27a7e0f77c6a88a1949996406ec935ac2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 40, "max_stars_repo_stars_event_min_datetime": "2015-03-19T16:00:14.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-29T03:06:10.000Z", "max_issues_repo_path": "src/energies.f90", "max_issues_repo_name": "rc/dftatom", "max_issues_repo_head_hexsha": "fe479fd27a7e0f77c6a88a1949996406ec935ac2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2015-06-23T21:59:56.000Z", "max_issues_repo_issues_event_max_datetime": "2019-09-04T20:36:51.000Z", "max_forks_repo_path": "src/energies.f90", "max_forks_repo_name": "rc/dftatom", "max_forks_repo_head_hexsha": "fe479fd27a7e0f77c6a88a1949996406ec935ac2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2015-06-07T15:14:49.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-05T07:03:24.000Z", "avg_line_length": 30.5471698113, "max_line_length": 78, "alphanum_fraction": 0.6417541692, "num_tokens": 1097, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995483, "lm_q2_score": 0.7401743677704878, "lm_q1q2_score": 0.657836473711961}} {"text": " SUBROUTINE svdvar(v,ma,np,w,cvm,ncvm)\r\n INTEGER ma,ncvm,np,MMAX\r\n REAL cvm(ncvm,ncvm),v(np,np),w(np)\r\n PARAMETER (MMAX=20)\r\n INTEGER i,j,k\r\n REAL sum,wti(MMAX)\r\n do 11 i=1,ma\r\n wti(i)=0.\r\n if(w(i).ne.0.) wti(i)=1./(w(i)*w(i))\r\n11 continue\r\n do 14 i=1,ma\r\n do 13 j=1,i\r\n sum=0.\r\n do 12 k=1,ma\r\n sum=sum+v(i,k)*v(j,k)*wti(k)\r\n12 continue\r\n cvm(i,j)=sum\r\n cvm(j,i)=sum\r\n13 continue\r\n14 continue\r\n return\r\n END\r\n", "meta": {"hexsha": "d63919ecac689fd54a8c4935bf8f8c9f2cf00618", "size": 545, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/svdvar.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/svdvar.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/svdvar.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.6956521739, "max_line_length": 45, "alphanum_fraction": 0.4532110092, "num_tokens": 195, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995483, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6578364686180652}} {"text": "*DECK PSIFN\n SUBROUTINE PSIFN (X, N, KODE, M, ANS, NZ, IERR)\nC***BEGIN PROLOGUE PSIFN\nC***PURPOSE Compute derivatives of the Psi function.\nC***LIBRARY SLATEC\nC***CATEGORY C7C\nC***TYPE SINGLE PRECISION (PSIFN-S, DPSIFN-D)\nC***KEYWORDS DERIVATIVES OF THE GAMMA FUNCTION, POLYGAMMA FUNCTION,\nC PSI FUNCTION\nC***AUTHOR Amos, D. E., (SNLA)\nC***DESCRIPTION\nC\nC The following definitions are used in PSIFN:\nC\nC Definition 1\nC PSI(X) = d/dx (ln(GAMMA(X)), the first derivative of\nC the LOG GAMMA function.\nC Definition 2\nC K K\nC PSI(K,X) = d /dx (PSI(X)), the K-th derivative of PSI(X).\nC ___________________________________________________________________\nC PSIFN computes a sequence of SCALED derivatives of\nC the PSI function; i.e. for fixed X and M it computes\nC the M-member sequence\nC\nC ((-1)**(K+1)/GAMMA(K+1))*PSI(K,X)\nC for K = N,...,N+M-1\nC\nC where PSI(K,X) is as defined above. For KODE=1, PSIFN returns\nC the scaled derivatives as described. KODE=2 is operative only\nC when K=0 and in that case PSIFN returns -PSI(X) + LN(X). That\nC is, the logarithmic behavior for large X is removed when KODE=1\nC and K=0. When sums or differences of PSI functions are computed\nC the logarithmic terms can be combined analytically and computed\nC separately to help retain significant digits.\nC\nC Note that CALL PSIFN(X,0,1,1,ANS) results in\nC ANS = -PSI(X)\nC\nC Input\nC X - Argument, X .gt. 0.0E0\nC N - First member of the sequence, 0 .le. N .le. 100\nC N=0 gives ANS(1) = -PSI(X) for KODE=1\nC -PSI(X)+LN(X) for KODE=2\nC KODE - Selection parameter\nC KODE=1 returns scaled derivatives of the PSI\nC function.\nC KODE=2 returns scaled derivatives of the PSI\nC function EXCEPT when N=0. In this case,\nC ANS(1) = -PSI(X) + LN(X) is returned.\nC M - Number of members of the sequence, M .ge. 1\nC\nC Output\nC ANS - A vector of length at least M whose first M\nC components contain the sequence of derivatives\nC scaled according to KODE.\nC NZ - Underflow flag\nC NZ.eq.0, A normal return\nC NZ.ne.0, Underflow, last NZ components of ANS are\nC set to zero, ANS(M-K+1)=0.0, K=1,...,NZ\nC IERR - Error flag\nC IERR=0, A normal return, computation completed\nC IERR=1, Input error, no computation\nC IERR=2, Overflow, X too small or N+M-1 too\nC large or both\nC IERR=3, Error, N too large. Dimensioned\nC array TRMR(NMAX) is not large enough for N\nC\nC The nominal computational accuracy is the maximum of unit\nC roundoff (=R1MACH(4)) and 1.0E-18 since critical constants\nC are given to only 18 digits.\nC\nC DPSIFN is the Double Precision version of PSIFN.\nC\nC *Long Description:\nC\nC The basic method of evaluation is the asymptotic expansion\nC for large X.ge.XMIN followed by backward recursion on a two\nC term recursion relation\nC\nC W(X+1) + X**(-N-1) = W(X).\nC\nC This is supplemented by a series\nC\nC SUM( (X+K)**(-N-1) , K=0,1,2,... )\nC\nC which converges rapidly for large N. Both XMIN and the\nC number of terms of the series are calculated from the unit\nC roundoff of the machine environment.\nC\nC***REFERENCES Handbook of Mathematical Functions, National Bureau\nC of Standards Applied Mathematics Series 55, edited\nC by M. Abramowitz and I. A. Stegun, equations 6.3.5,\nC 6.3.18, 6.4.6, 6.4.9 and 6.4.10, pp.258-260, 1964.\nC D. E. Amos, A portable Fortran subroutine for\nC derivatives of the Psi function, Algorithm 610, ACM\nC Transactions on Mathematical Software 9, 4 (1983),\nC pp. 494-502.\nC***ROUTINES CALLED I1MACH, R1MACH\nC***REVISION HISTORY (YYMMDD)\nC 820601 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890531 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE PSIFN\n INTEGER I, IERR, J, K, KODE, M, MM, MX, N, NMAX, NN, NP, NX, NZ\n INTEGER I1MACH\n REAL ANS, ARG, B, DEN, ELIM, EPS, FLN, FN, FNP, FNS, FX, RLN,\n * RXSQ, R1M4, R1M5, S, SLOPE, T, TA, TK, TOL, TOLS, TRM, TRMR,\n * TSS, TST, TT, T1, T2, WDTOL, X, XDMLN, XDMY, XINC, XLN, XM,\n * XMIN, XQ, YINT\n REAL R1MACH\n DIMENSION B(22), TRM(22), TRMR(100), ANS(*)\n SAVE NMAX, B\n DATA NMAX /100/\nC-----------------------------------------------------------------------\nC BERNOULLI NUMBERS\nC-----------------------------------------------------------------------\n DATA B(1), B(2), B(3), B(4), B(5), B(6), B(7), B(8), B(9), B(10),\n * B(11), B(12), B(13), B(14), B(15), B(16), B(17), B(18), B(19),\n * B(20), B(21), B(22) /1.00000000000000000E+00,\n * -5.00000000000000000E-01,1.66666666666666667E-01,\n * -3.33333333333333333E-02,2.38095238095238095E-02,\n * -3.33333333333333333E-02,7.57575757575757576E-02,\n * -2.53113553113553114E-01,1.16666666666666667E+00,\n * -7.09215686274509804E+00,5.49711779448621554E+01,\n * -5.29124242424242424E+02,6.19212318840579710E+03,\n * -8.65802531135531136E+04,1.42551716666666667E+06,\n * -2.72982310678160920E+07,6.01580873900642368E+08,\n * -1.51163157670921569E+10,4.29614643061166667E+11,\n * -1.37116552050883328E+13,4.88332318973593167E+14,\n * -1.92965793419400681E+16/\nC\nC***FIRST EXECUTABLE STATEMENT PSIFN\n IERR = 0\n NZ=0\n IF (X.LE.0.0E0) IERR=1\n IF (N.LT.0) IERR=1\n IF (KODE.LT.1 .OR. KODE.GT.2) IERR=1\n IF (M.LT.1) IERR=1\n IF (IERR.NE.0) RETURN\n MM=M\n NX = MIN(-I1MACH(12),I1MACH(13))\n R1M5 = R1MACH(5)\n R1M4 = R1MACH(4)*0.5E0\n WDTOL = MAX(R1M4,0.5E-18)\nC-----------------------------------------------------------------------\nC ELIM = APPROXIMATE EXPONENTIAL OVER AND UNDERFLOW LIMIT\nC-----------------------------------------------------------------------\n ELIM = 2.302E0*(NX*R1M5-3.0E0)\n XLN = LOG(X)\n 41 CONTINUE\n NN = N + MM - 1\n FN = NN\n FNP = FN + 1.0E0\n T = FNP*XLN\nC-----------------------------------------------------------------------\nC OVERFLOW AND UNDERFLOW TEST FOR SMALL AND LARGE X\nC-----------------------------------------------------------------------\n IF (ABS(T).GT.ELIM) GO TO 290\n IF (X.LT.WDTOL) GO TO 260\nC-----------------------------------------------------------------------\nC COMPUTE XMIN AND THE NUMBER OF TERMS OF THE SERIES, FLN+1\nC-----------------------------------------------------------------------\n RLN = R1M5*I1MACH(11)\n RLN = MIN(RLN,18.06E0)\n FLN = MAX(RLN,3.0E0) - 3.0E0\n YINT = 3.50E0 + 0.40E0*FLN\n SLOPE = 0.21E0 + FLN*(0.0006038E0*FLN+0.008677E0)\n XM = YINT + SLOPE*FN\n MX = INT(XM) + 1\n XMIN = MX\n IF (N.EQ.0) GO TO 50\n XM = -2.302E0*RLN - MIN(0.0E0,XLN)\n FNS = N\n ARG = XM/FNS\n ARG = MIN(0.0E0,ARG)\n EPS = EXP(ARG)\n XM = 1.0E0 - EPS\n IF (ABS(ARG).LT.1.0E-3) XM = -ARG\n FLN = X*XM/EPS\n XM = XMIN - X\n IF (XM.GT.7.0E0 .AND. FLN.LT.15.0E0) GO TO 200\n 50 CONTINUE\n XDMY = X\n XDMLN = XLN\n XINC = 0.0E0\n IF (X.GE.XMIN) GO TO 60\n NX = INT(X)\n XINC = XMIN - NX\n XDMY = X + XINC\n XDMLN = LOG(XDMY)\n 60 CONTINUE\nC-----------------------------------------------------------------------\nC GENERATE W(N+MM-1,X) BY THE ASYMPTOTIC EXPANSION\nC-----------------------------------------------------------------------\n T = FN*XDMLN\n T1 = XDMLN + XDMLN\n T2 = T + XDMLN\n TK = MAX(ABS(T),ABS(T1),ABS(T2))\n IF (TK.GT.ELIM) GO TO 380\n TSS = EXP(-T)\n TT = 0.5E0/XDMY\n T1 = TT\n TST = WDTOL*TT\n IF (NN.NE.0) T1 = TT + 1.0E0/FN\n RXSQ = 1.0E0/(XDMY*XDMY)\n TA = 0.5E0*RXSQ\n T = FNP*TA\n S = T*B(3)\n IF (ABS(S).LT.TST) GO TO 80\n TK = 2.0E0\n DO 70 K=4,22\n T = T*((TK+FN+1.0E0)/(TK+1.0E0))*((TK+FN)/(TK+2.0E0))*RXSQ\n TRM(K) = T*B(K)\n IF (ABS(TRM(K)).LT.TST) GO TO 80\n S = S + TRM(K)\n TK = TK + 2.0E0\n 70 CONTINUE\n 80 CONTINUE\n S = (S+T1)*TSS\n IF (XINC.EQ.0.0E0) GO TO 100\nC-----------------------------------------------------------------------\nC BACKWARD RECUR FROM XDMY TO X\nC-----------------------------------------------------------------------\n NX = INT(XINC)\n NP = NN + 1\n IF (NX.GT.NMAX) GO TO 390\n IF (NN.EQ.0) GO TO 160\n XM = XINC - 1.0E0\n FX = X + XM\nC-----------------------------------------------------------------------\nC THIS LOOP SHOULD NOT BE CHANGED. FX IS ACCURATE WHEN X IS SMALL\nC-----------------------------------------------------------------------\n DO 90 I=1,NX\n TRMR(I) = FX**(-NP)\n S = S + TRMR(I)\n XM = XM - 1.0E0\n FX = X + XM\n 90 CONTINUE\n 100 CONTINUE\n ANS(MM) = S\n IF (FN.EQ.0.0E0) GO TO 180\nC-----------------------------------------------------------------------\nC GENERATE LOWER DERIVATIVES, J.LT.N+MM-1\nC-----------------------------------------------------------------------\n IF (MM.EQ.1) RETURN\n DO 150 J=2,MM\n FNP = FN\n FN = FN - 1.0E0\n TSS = TSS*XDMY\n T1 = TT\n IF (FN.NE.0.0E0) T1 = TT + 1.0E0/FN\n T = FNP*TA\n S = T*B(3)\n IF (ABS(S).LT.TST) GO TO 120\n TK = 3.0E0 + FNP\n DO 110 K=4,22\n TRM(K) = TRM(K)*FNP/TK\n IF (ABS(TRM(K)).LT.TST) GO TO 120\n S = S + TRM(K)\n TK = TK + 2.0E0\n 110 CONTINUE\n 120 CONTINUE\n S = (S+T1)*TSS\n IF (XINC.EQ.0.0E0) GO TO 140\n IF (FN.EQ.0.0E0) GO TO 160\n XM = XINC - 1.0E0\n FX = X + XM\n DO 130 I=1,NX\n TRMR(I) = TRMR(I)*FX\n S = S + TRMR(I)\n XM = XM - 1.0E0\n FX = X + XM\n 130 CONTINUE\n 140 CONTINUE\n MX = MM - J + 1\n ANS(MX) = S\n IF (FN.EQ.0.0E0) GO TO 180\n 150 CONTINUE\n RETURN\nC-----------------------------------------------------------------------\nC RECURSION FOR N = 0\nC-----------------------------------------------------------------------\n 160 CONTINUE\n DO 170 I=1,NX\n S = S + 1.0E0/(X+NX-I)\n 170 CONTINUE\n 180 CONTINUE\n IF (KODE.EQ.2) GO TO 190\n ANS(1) = S - XDMLN\n RETURN\n 190 CONTINUE\n IF (XDMY.EQ.X) RETURN\n XQ = XDMY/X\n ANS(1) = S - LOG(XQ)\n RETURN\nC-----------------------------------------------------------------------\nC COMPUTE BY SERIES (X+K)**(-(N+1)) , K=0,1,2,...\nC-----------------------------------------------------------------------\n 200 CONTINUE\n NN = INT(FLN) + 1\n NP = N + 1\n T1 = (FNS+1.0E0)*XLN\n T = EXP(-T1)\n S = T\n DEN = X\n DO 210 I=1,NN\n DEN = DEN + 1.0E0\n TRM(I) = DEN**(-NP)\n S = S + TRM(I)\n 210 CONTINUE\n ANS(1) = S\n IF (N.NE.0) GO TO 220\n IF (KODE.EQ.2) ANS(1) = S + XLN\n 220 CONTINUE\n IF (MM.EQ.1) RETURN\nC-----------------------------------------------------------------------\nC GENERATE HIGHER DERIVATIVES, J.GT.N\nC-----------------------------------------------------------------------\n TOL = WDTOL/5.0E0\n DO 250 J=2,MM\n T = T/X\n S = T\n TOLS = T*TOL\n DEN = X\n DO 230 I=1,NN\n DEN = DEN + 1.0E0\n TRM(I) = TRM(I)/DEN\n S = S + TRM(I)\n IF (TRM(I).LT.TOLS) GO TO 240\n 230 CONTINUE\n 240 CONTINUE\n ANS(J) = S\n 250 CONTINUE\n RETURN\nC-----------------------------------------------------------------------\nC SMALL X.LT.UNIT ROUND OFF\nC-----------------------------------------------------------------------\n 260 CONTINUE\n ANS(1) = X**(-N-1)\n IF (MM.EQ.1) GO TO 280\n K = 1\n DO 270 I=2,MM\n ANS(K+1) = ANS(K)/X\n K = K + 1\n 270 CONTINUE\n 280 CONTINUE\n IF (N.NE.0) RETURN\n IF (KODE.EQ.2) ANS(1) = ANS(1) + XLN\n RETURN\n 290 CONTINUE\n IF (T.GT.0.0E0) GO TO 380\n NZ=0\n IERR=2\n RETURN\n 380 CONTINUE\n NZ=NZ+1\n ANS(MM)=0.0E0\n MM=MM-1\n IF(MM.EQ.0) RETURN\n GO TO 41\n 390 CONTINUE\n IERR=3\n NZ=0\n RETURN\n END\n", "meta": {"hexsha": "34a882416ecc210c8126ff1a477ee8bb73559cb0", "size": 12891, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/psifn.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/psifn.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/psifn.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.9349593496, "max_line_length": 72, "alphanum_fraction": 0.4623380653, "num_tokens": 4367, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587846530938, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6578364664371752}} {"text": "!=====================================================|\nsubroutine model\n!=====================================================|\n use geometry_def, only: xmax,xmin,dx,x,qq &\n & ,nx,nxg,margin\n use const_def, only: cv,gm,pi\n implicit none\n integer :: i\n\n real(KIND(0.d0)) :: xm,dd,tmp\n real(KIND(0.d0)) :: pr ! pressure\n real(KIND(0.d0)) :: rol,ror,vxl,vxr,prl,prr,byl,byr\n!-----------------------------------------------------|\n\n xmax = 1.d0\n xmin = 0.d0\n\n dx = (xmax - xmin)/real(nx)\n x(1 + margin) = xmin + 0.5d0*dx\n do i = margin,1,-1\n x(i) = x(i+1) - dx\n enddo\n\n do i = 2 + margin,nxg\n x(i) = x(i-1) + dx\n enddo\n\n ! sound wave\n xm = 0.5d0*(xmax + xmin)\n dd = 0.05d0\n do i = 1,nxg\n qq(i,1) = 1.d0 + 0.01d0*exp(-((x(i)-xm)/dd)**2) ! density\n qq(i,2) = 0.d0 ! vx\n qq(i,3) = 0.d0 ! vy\n qq(i,4) = 0.d0 ! vz\n qq(i,5) = 1.d0 ! bx\n qq(i,6) = 1.d0 ! by\n qq(i,7) = 1.d0 ! bz\n pr = qq(i,1)**gm/gm\n qq(i,8) = cv*log(pr/qq(i,1)**gm) ! entropy\n enddo\n \n rol = 1.d0\n ror = 0.125d0\n vxl = 0.75d0\n vxr = 0.d0\n prl = 1.d0\n prr = 0.1d0\n ! hydrodynamic shock tube\n do i = 1,nxg\n! if( x(i) < 0.5d0) then\n! qq(i,1) = 1.d0\n! pr = 1.d0\n! qq(i,2) = 0.75d0\n! else\n! qq(i,1) = 0.125d0\n! pr = 0.1d0\n! qq(i,2) = 0d0\n! endif\n tmp = 0.5d0 + 0.5d0*tanh((x(i) - 0.5)/(1.d0*dx))\n qq(i,1) = rol + (ror - rol)*tmp\n qq(i,2) = vxl + (vxr - vxl)*tmp\n pr = prl + (prr - prl)*tmp\n \n qq(i,3) = 0.d0\n qq(i,4) = 0.d0\n qq(i,5) = 0.d0\n qq(i,6) = 0.d0\n qq(i,7) = 0.d0\n qq(i,8) = cv*log(pr/qq(i,1)**gm) ! entropy\n enddo\n\n! goto 1000\n \n ! mhd shock tube (Brio and Wu, 1988)\n rol = 1.d0\n ror = 0.125d0\n prl = 1.d0\n prr = 0.1d0\n byl = 1.d0*sqrt(4.d0*pi)\n byr = -1.d0*sqrt(4.d0*pi)\n do i = 1,nxg\n! if( x(i) < 0.5d0) then\n! qq(i,1) = 1.d0\n! pr = 1.d0\n! qq(i,6) = 1.d0*sqrt(4.d0*pi) ! by\n! else\n! qq(i,1) = 0.125d0\n! pr = 0.1d0\n! qq(i,6) = -1.d0*sqrt(4.d0*pi) ! by\n! endif\n tmp = 0.5d0 + 0.5d0*tanh((x(i) - 0.5)/(1.d0*dx))\n qq(i,1) = rol + (ror - rol)*tmp\n pr = prl + (prr - prl)*tmp\n qq(i,6) = byl + (byr - byl)*tmp\n\n \n qq(i,2) = 0.d0 ! vx\n qq(i,3) = 0.d0 ! vy\n qq(i,4) = 0.d0 ! vy\n qq(i,5) = 0.75d0*sqrt(4.d0*pi) !bx\n qq(i,7) = 0.d0 !bz\n qq(i,8) = cv*log(pr/qq(i,1)**gm) ! entropy\n enddo\n\n1000 continue\n \n return\nend subroutine model\n", "meta": {"hexsha": "b398b50b603428999efae8384238fd6993fee3c2", "size": 2487, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/model.f90", "max_stars_repo_name": "hottahd/shock_tube_entropy", "max_stars_repo_head_hexsha": "b0a4934cc054a73e96dbafdf741478e63b4abfab", "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/model.f90", "max_issues_repo_name": "hottahd/shock_tube_entropy", "max_issues_repo_head_hexsha": "b0a4934cc054a73e96dbafdf741478e63b4abfab", "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/model.f90", "max_forks_repo_name": "hottahd/shock_tube_entropy", "max_forks_repo_head_hexsha": "b0a4934cc054a73e96dbafdf741478e63b4abfab", "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": 22.6090909091, "max_line_length": 62, "alphanum_fraction": 0.4310414154, "num_tokens": 1189, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587817066392, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6578364642562851}} {"text": " SUBROUTINE qromo(func,a,b,ss,choose)\r\n INTEGER JMAX,JMAXP,K,KM\r\n REAL a,b,func,ss,EPS\r\n EXTERNAL func,choose\r\n PARAMETER (EPS=1.e-6, JMAX=14, JMAXP=JMAX+1, K=5, KM=K-1)\r\nCU USES polint\r\n INTEGER j\r\n REAL dss,h(JMAXP),s(JMAXP)\r\n h(1)=1.\r\n do 11 j=1,JMAX\r\n call choose(func,a,b,s(j),j)\r\n if (j.ge.K) then\r\n call polint(h(j-KM),s(j-KM),K,0.,ss,dss)\r\n if (abs(dss).le.EPS*abs(ss)) return\r\n endif\r\n s(j+1)=s(j)\r\n h(j+1)=h(j)/9.\r\n11 continue\r\n pause 'too many steps in qromo'\r\n END\r\n", "meta": {"hexsha": "ea0fafe5cc6d2cdf263a79fb84bece33df16a527", "size": 592, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/qromo.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/qromo.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/qromo.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.1904761905, "max_line_length": 64, "alphanum_fraction": 0.5084459459, "num_tokens": 218, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587817066392, "lm_q2_score": 0.7401743505760728, "lm_q1q2_score": 0.6578364540684933}} {"text": "!////////////////////////////////////////////////////////////////////////////////////////\n! This program solves the 1-D heat equation, with zero-temperature \n! boundary conditions, in serial. \n! EXERCISE: Parallelize this code by\n! 1) Adjusting the logic used to initialize my_imin and my_imax\n! 2) Filling in the ghost_zone_comm routine that communicates\n! boundary values between neighbors.\nPROGRAM MAIN\n USE ISO_FORTRAN_ENV, ONLY : output_unit,real64\n USE MPI\n IMPLICIT NONE\n REAL*8, ALLOCATABLE :: var(:), tmp(:)\n INTEGER :: nx,nt\n REAL( real64) :: ct_one, ct_two, ct_three\n REAL( real64) :: elapsed_time, loop_time, init_time\n INTEGER :: i,j,k,n, ierr\n\n !/////////////////////////////////////////\n ! These two variables are initialized in INIT_COMM below.\n INTEGER :: my_rank, ncpu ! Rank of this process; total number of MPI processes\n INTEGER :: my_imin, my_imax ! the range of x-indices that this rank owns\n INTEGER :: my_numx ! The number of-indices assinged to this processes\n ! my_numx = my_imax-my_imin+1\n\n CALL cpu_time( time= ct_one)\n\n !////////////////////////////////////////////////////\n ! Set some default values for the problem parameters.\n nx = 4096 ! x-dimension of our 3-D array\n nt = 4096 ! number of time steps to integrate over\n\n\n !////////////////////////////////////////////////////\n ! Check to see if the user has overridden\n ! these defaults at the command line.\n ! Command line calling syntax:\n ! ./ex5.out -nx 256 -nt 100 \n CALL grab_args(nx,nt)\n\n CALL INIT_COMM()\n\n IF (my_rank .eq. 0) THEN\n WRITE(output_unit,'(a)') ' ///////////////////////////'\n WRITE(output_unit,'(a)') ' 1-D Diffusion Equation '\n WRITE(output_unit,'(a)') ' --Problem Parameters-- '\n WRITE(output_unit,'(a,i0)')' nx =', nx\n WRITE(output_unit,'(a,i0)')' nt =', nt\n WRITE(output_unit,'(a,i0)')' ncpu =', ncpu\n WRITE(output_unit,'(a)') ' ///////////////////////////'\n WRITE(output_unit,'(a)') ' '\n ENDIF\n !/////////////////////////////////////////////////////\n ! Initialize var and the work array\n\n !NOTE: my_imin & my_numx are correct only for ncpu = 1\n ! It should be modified based on my_rank.\n my_numx = nx\n my_imin = 1\n my_imax = my_imin+my_numx-1\n\n DO i = 0, ncpu-1\n IF (i .eq. my_rank) THEN\n WRITE(6,*)'my_rank, my_imin, my_imax: ', my_rank, my_imin, my_imax\n ENDIF\n ! The use of a barrier here helps the line above to be printed out\n ! \"in order\"\n IF (ncpu .gt. 1) CALL MPI_BARRIER(MPI_COMM_WORLD,ierr)\n ENDDO\n\n \n ALLOCATE(var(my_imin-1:my_imax+1)) ! We allow space for two\n ALLOCATE(tmp(my_imin:my_imax)) ! \"ghost zones\" in the var array\n \n var(:) = 0.0d0\n tmp(:) = 0.0d0\n CALL INIT_ARR(var, 1.0d0, 2) ! single sine wave in x-direction\n\n\n !/////////////////////////////////////////////////////\n ! Evolve the system\n CALL cpu_time( time= ct_two)\n DO n = 1, nt\n IF (my_rank .eq. 0) THEN\n IF (MOD(n,100) .eq. 0) Write(output_unit,'(a,i5)')' Timestep: ',n\n ENDIF\n\n !* EDIT THIS FUNCTION to communicate ghost zones\n ! to left and right neighbor ranks.\n IF (ncpu .gt. 1) CALL GHOST_ZONE_COMM()\n\n\n CALL Laplacian(var,tmp)\n\n ENDDO\n ! We may want to write out the values for debugging\n !Write(output_unit,*) var(:) \n\n !//////////////////////////////////////////\n ! Write out some timing information.\n\n\n CALL cpu_time( time= ct_three)\n elapsed_time = ct_three-ct_one\n init_time = ct_two-ct_one\n loop_time = ct_three-ct_two\n IF (my_rank .eq. 0) THEN\n WRITE(output_unit,'(a)')' Complete!'\n WRITE(output_unit,'( a, ES14.4, a)')' Elapsed time: ', elapsed_time, ' seconds.'\n WRITE(output_unit, fmt= '( a, ES14.4, a)') ' Initialization time: ', init_time, ' seconds.'\n WRITE(output_unit, fmt= '( a, ES14.4, a)') ' Loop time: ', loop_time, ' seconds.'\n ENDIF\n\n ! Always call this at the end of the program so that all ranks exit together.\n ! Once your code is working, try removing this call. The code will still work,\n ! but sometimes you may not see the timing information printed out because other\n ! ranks exit before rank 0 can write.\n CALL MPI_FINALIZE(ierr)\nCONTAINS\n\n SUBROUTINE GHOST_ZONE_COMM()\n IMPLICIT NONE\n ! Communicate boundary values here...\n\n END SUBROUTINE GHOST_ZONE_COMM\n\n\n SUBROUTINE Laplacian(arrin, work)\n IMPLICIT NONE\n REAL*8, INTENT(InOut) :: arrin(my_imin-1:)\n REAL*8, INTENT(InOut) :: work(my_imin:)\n INTEGER :: ni, imin,imax\n\n ni = size(arrin)\n\n imin = max(my_imin,2) ! Avoid the boundaries, which are held fixed at zero\n imax = min(my_imax,nx)\n\n DO i = imin, imax\n work(i) = arrin(i-1) + arrin(i+1) \n ENDDO\n\n\n DO i = imin, imax\n arrin(i) = work(i)*0.5d0\n ENDDO\n\n END SUBROUTINE Laplacian\n\n SUBROUTINE grab_args(numx, numiter)\n IMPLICIT NONE\n\n INTEGER, INTENT(OUT) :: numx\n INTEGER, INTENT(OUT) :: numiter\n\n\n INTEGER :: n ! Number of command-line arguments\n INTEGER :: i \n CHARACTER(len=1024) :: argname ! Argument key\n CHARACTER(len=1024) :: val ! Argument value\n\n\n\n n = command_argument_count()\n DO i=1,n,2\n CALL get_command_argument(i, argname)\n CALL get_command_argument(i+1, val)\n SELECT CASE(argname)\n CASE('-nx')\n read(val, '(I8)') numx\n CASE('-nt')\n read(val, '(I8)') numiter\n CASE DEFAULT\n WRITE(output_unit,'(a)') ' '\n WRITE(output_unit,'(a)') &\n ' Unrecognized option: '// trim(argname)\n END SELECT\n ENDDO\n\n\n END SUBROUTINE grab_args\n\n SUBROUTINE INIT_COMM()\n IMPLICIT NONE\n INTEGER :: ierr\n !Initialize MPI (ierr is an error flag with nonzero value if there's a problem)\n Call MPI_INIT( ierr )\n IF (ierr .ne. 0) STOP 'Error intializing MPI'\n\n !Find number of MPI processes executing this program (ncpu)\n Call MPI_Comm_size(MPI_COMM_WORLD, ncpu,ierr)\n IF (ierr .ne. 0) STOP 'Error finding ncpu'\n\n !Find this process's rank (my_rank; unique numeric identifier for each MPI process)\n Call MPI_Comm_rank(MPI_COMM_WORLD, my_rank,ierr)\n IF (ierr .ne. 0) STOP 'Error finding my_rank'\n WRITE(output_unit,'(a,i0,a,i0,a)')'Rank ',my_rank,' of ', ncpu, ' is active.'\n CALL MPI_BARRIER(MPI_COMM_WORLD,ierr)\n END SUBROUTINE INIT_COMM\n\n\n SUBROUTINE INIT_ARR(arr, amp, orderx)\n IMPLICIT NONE\n REAL*8, INTENT(INOUT) :: arr(:)\n REAL*8, INTENT(IN) :: amp\n INTEGER, INTENT(IN) :: orderx\n REAL*8 :: sinkx\n REAL*8 :: kx\n REAL*8, PARAMETER :: pi = 3.1415926535897932384626433832795028841972d0\n INTEGER :: i,ni\n ni = size(arr)\n\n kx = orderx*(pi/(ni-1))\n\n DO i = my_imin, my_imax\n sinkx = sin(kx*(i-1))\n arr(i) = arr(i)+amp*sinkx\n ENDDO\n If (my_imin .eq. 1) arr(1) = 0\n If (my_imax .eq. ni) arr(ni) = 0\n\n END SUBROUTINE INIT_ARR\nEND PROGRAM MAIN\n", "meta": {"hexsha": "c2220cca64269a1f7e5046c9e15093e7976db80b", "size": 7699, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "MPI/Lab/session2/exercise2/ex2.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/session2/exercise2/ex2.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/session2/exercise2/ex2.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": 34.5246636771, "max_line_length": 100, "alphanum_fraction": 0.537991947, "num_tokens": 2077, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199714402813, "lm_q2_score": 0.7853085808877581, "lm_q1q2_score": 0.6577901510950118}} {"text": "program poisson_mpi1D\n\tuse poisson_module\n\tuse mpi\n\timplicit none\n\n\tinteger :: i,j,k,ret\n\treal, allocatable, dimension(:) :: u,u0,f,u_global\n\tinteger, allocatable, dimension(:) :: buf\n\treal :: h, l2\n\tinteger :: prank, psize, ierror, tag, status(MPI_STATUS_SIZE)\n\tdouble precision :: t_start, t_end\n\tinteger :: n_loc, offset, n_min;\n\tinteger :: j_start, j_end, i_start, i_end\n\treal :: x,y\n\n! Initialization of the MPI library\n\tcall MPI_INIT(ierror)\t\n\tcall MPI_COMM_RANK(MPI_COMM_WORLD, prank, ierror)\n\tcall MPI_COMM_SIZE(MPI_COMM_WORLD, psize, ierror)\n\n\tn_min = (N+1)\n\th = 1. / n_min\n! Divide n in psize and distribute the excess to the (n % psize) proc\n\tif (prank < mod(n_min,psize)) then\n\t\tn_loc = (n_min / psize) + 1\n\telse\n\t\tn_loc = (n_min / psize)\n\tendif\n! Computing the offset of where in the global array the local array is\n! located. (this is needed to initialize f) It could be computed locally\n! without communication but this way you see a Allgather\n\tallocate(buf(psize))\n\tcall MPI_ALLGATHER(n_loc, 1, MPI_INTEGER, buf, 1, MPI_INTEGER, MPI_COMM_WORLD,ierror)\n\toffset = 0\n\tdo i = 1, prank\n\t\toffset = offset + buf(i)\n\tenddo\n! add 2 for east and west ghost\n\tn_loc = n_loc + 2\n\n\tallocate(u(n_min*n_loc),u0(n_min*n_loc),f(n_min*n_loc))\n\tif (prank.eq.0) allocate(u_global(n_min*n_min))\n\n\tu = 0.\n\tu0 = 0.\n\tf = 0.\n\n\n\tdo i = 2, n_min-1\n\t\tdo j = 2, n_loc-1\n!\t\t\tx = real(i) * h\n!\t\t\ty = real(j - j_start + offset) * h\n!\t\t\tf(n_loc*i+j) = -2.*100. * M_PI * M_PI * sin(10.*M_PI*x) * sin(10.*M_PI*y)\n\t\t\tf(n_loc*i+j) = -2.*100. * M_PI * M_PI * sin(10.*M_PI*(i-1)*h) * sin(10.*M_PI*(j-1)*h)\n\n\t\tenddo\n\tenddo\t\n\t\n!if (prank.eq.1) write(*,*) prank, f\n\n\tk = 0\n\tl2 = 1.\n\tt_start = MPI_WTIME()\n\n\n!\tdo while (l2 > eps)\n\tdo while (k < 400)\n\t\tl2 = 0.\n\t\tj_start = 2\n\t\tj_end = n_loc-1\n\t\ti_start = 2\n\t\ti_end = n_min-1\n\n! send recv with left proc\n\t\tif (prank > 0) then \n\t\t\tcall MPI_SENDRECV(u0(n_min+2), n_min, MPI_REAL, prank - 1, NORTH, u0(1), n_min, MPI_REAL, prank - 1, SOUTH, MPI_COMM_WORLD, status, ierror)\n!\t\t\tcall MPI_SENDRECV(u0(n_min:2*n_min), n_min, MPI_REAL, prank - 1, NORTH, u0(1:n_min), n_min, MPI_REAL, prank - 1, SOUTH, MPI_COMM_WORLD, status, ierror)\n!\t\t\t\tcall MPI_SENDRECV(u0(:,2), n_min, MPI_REAL, prank - 1, NORTH, u0(:,1), n_min, MPI_REAL, prank - 1, SOUTH, MPI_COMM_WORLD, status, ierror)\n\t\tendif\n\n! send recv with right proc\n\t\tif(prank < psize - 1) then\n\t\t\tcall MPI_SENDRECV(u0(n_loc-1), n_min, MPI_REAL, prank + 1, SOUTH, u0(n_loc), n_min, MPI_REAL, prank + 1, NORTH, MPI_COMM_WORLD, status, ierror)\n!\t\t\tcall MPI_SENDRECV(u0((n_loc-1)*n_min:(n_loc-1)*2*n_min), n_min, MPI_REAL, prank + 1, SOUTH, u0(n_loc:n_loc+n_min), n_min, MPI_REAL, prank + 1, NORTH, MPI_COMM_WORLD, status, ierror)\n!\t\t\tcall MPI_SENDRECV(u0(:,n_loc-1), n_min, MPI_REAL, prank + 1, SOUTH, u0(:,n_loc), n_min, MPI_REAL, prank + 1, NORTH, MPI_COMM_WORLD, status, ierror)\n\t\tendif\n\n\t\tdo i = i_start, i_end\n\t\t\tdo j = j_start,j_end\n\t\t\t\tu(n_loc*i+j) = 0.25 * ( u0(n_loc*(i-1)+j) + u0(n_loc*(i+1)+j) + u0(n_loc*i+(j-1)) + u0(n_loc*i+(j+1)) - f(n_loc*i+j)*h*h);\n\t\t\t\t! L2 norm\n\t\t\t\tl2 = l2 + (u0(n_loc*i+j) - u(n_loc*i+j))*(u0(n_loc*i+j) - u(n_loc*i+j));\n\t\t\tenddo\n\t\tenddo\n\n\n! reduce the 12 norm to every proc\n\t\tcall MPI_ALLREDUCE(MPI_IN_PLACE, l2, 1, MPI_REAL, MPI_SUM, MPI_COMM_WORLD, ierror);\n\n\t\tcall MPI_Gather(u(1),(n_min*(n_loc-2)),MPI_REAL, u_global,(n_min*(n_loc-2)) , MPI_REAL, 0, MPI_COMM_WORLD,ierror)\n!\t\tif (prank.eq.0) call write_to_file_binary1D(n_min, u_global, k, -1., 1.)\n\n\t\t! output\n\t\tif (prank .eq. 0) then\n\t\t\twrite(*,*) 'iteration',k,l2\n\t\tendif\n\t\tk = k + 1\n\t\tu0 = u\n\tenddo\t\n\tt_end = MPI_WTIME()\n\tif (prank .eq. 0) then\n\t\twrite(*,*) 'T',(t_end - t_start),'[s]'\n\t\twrite(*,*) 'Nb steps',k,'l2',l2\n\t\twrite(*,*) 'Size',n_min\n\tendif\n\n\tdeallocate(u,u0,f)\n\tif (prank.eq.0) deallocate(u_global)\n\n\tcall MPI_FINALIZE(ierror)\n\nend program poisson_mpi1D\n", "meta": {"hexsha": "79913a444e16f0f5267a4c348fdf013f2480b682", "size": 3826, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Exos/old/codes_fortran/poisson_mpi1D.f90", "max_stars_repo_name": "vkeller/math-454", "max_stars_repo_head_hexsha": "0bf3a81214f094dbddec868d3d133986b31f4b01", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-19T13:31:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-19T13:31:49.000Z", "max_issues_repo_path": "Exos/old/codes_fortran/poisson_mpi1D.f90", "max_issues_repo_name": "vkeller/math-454", "max_issues_repo_head_hexsha": "0bf3a81214f094dbddec868d3d133986b31f4b01", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Exos/old/codes_fortran/poisson_mpi1D.f90", "max_forks_repo_name": "vkeller/math-454", "max_forks_repo_head_hexsha": "0bf3a81214f094dbddec868d3d133986b31f4b01", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.1056910569, "max_line_length": 185, "alphanum_fraction": 0.6552535285, "num_tokens": 1443, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199471193039, "lm_q2_score": 0.7853085808877581, "lm_q1q2_score": 0.6577901319955395}} {"text": "\nSUBROUTINE spl2d(nx,ny,hx,hy,mx,my,f,spl)\n\n! Makes a 2-dimensional cubic spline of function f(x,y)\n!\n! Input: nx, ny number of values in x and y\n! hx, hy step size in x and y (aequidistant)\n! mx, my spline mode (0: standard, 1: periodic)\n! f(nx,ny) f(x,y)-values\n! Output: spl Array with spline parameters\n\n USE neo_precision\n\n IMPLICIT NONE\n\n INTEGER, INTENT(in) :: nx, ny, mx, my\n REAL(kind=dp), INTENT(in) :: hx, hy\n REAL(kind=dp), DIMENSION(nx,ny) , INTENT(in) :: f\n REAL(kind=dp), DIMENSION(4,4,nx,ny), INTENT(out) :: spl\n\n REAL(kind=dp), DIMENSION(:), ALLOCATABLE :: bi, ci, di, s\n INTEGER :: i, j, k, l\n\n ALLOCATE ( bi(nx), ci(nx), di(nx), s(nx) )\n DO j = 1,ny\n DO i = 1,nx\n s(i) = f(i,j)\n END DO\n IF (mx .EQ. 0) THEN\n CALL splreg(nx,hx,s,bi,ci,di)\n ELSE\n CALL splper(nx,hx,s,bi,ci,di)\n ENDIF\n DO i = 1,nx\n spl(1,1,i,j) = s(i)\n spl(2,1,i,j) = bi(i)\n spl(3,1,i,j) = ci(i)\n spl(4,1,i,j) = di(i)\n END DO\n END DO\n DEALLOCATE ( bi, ci, di, s )\n\n ALLOCATE ( bi(ny), ci(ny), di(ny), s(ny) )\n DO k = 1,4\n DO i = 1,nx\n DO j = 1,ny\n s(j) = spl(k,1,i,j)\n END DO\n IF (my .EQ. 0) THEN\n CALL splreg(ny,hy,s,bi,ci,di)\n ELSE\n CALL splper(ny,hy,s,bi,ci,di)\n ENDIF\n DO j=1,ny\n spl(k,2,i,j)=bi(j)\n spl(k,3,i,j)=ci(j)\n spl(k,4,i,j)=di(j)\n END DO\n END DO\n END DO\n DEALLOCATE ( bi, ci, di, s )\n\n RETURN\nEND SUBROUTINE spl2d\n", "meta": {"hexsha": "a3ca348ef9ddbcf3bc48bede054b86eb267f526f", "size": 1717, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "NEO/Sources/spl2d.f90", "max_stars_repo_name": "joseluisvelasco/STELLOPT", "max_stars_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2020-05-08T01:47:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T10:35:28.000Z", "max_issues_repo_path": "NEO/Sources/spl2d.f90", "max_issues_repo_name": "joseluisvelasco/STELLOPT", "max_issues_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 77, "max_issues_repo_issues_event_min_datetime": "2020-05-08T07:18:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:20:33.000Z", "max_forks_repo_path": "NEO/Sources/spl2d.f90", "max_forks_repo_name": "joseluisvelasco/STELLOPT", "max_forks_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-02-10T13:47:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T12:53:43.000Z", "avg_line_length": 26.4153846154, "max_line_length": 68, "alphanum_fraction": 0.4606872452, "num_tokens": 613, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412808, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.6577704492836864}} {"text": "!\n! -----------------------------------------------------------------\n! F A C T R L\n! -----------------------------------------------------------------\n!\n!\n SUBROUTINE FACTRL(NFACT) \n!-----------------------------------------------\n! M o d u l e s \n!-----------------------------------------------\n USE vast_kind_param, ONLY: DOUBLE \n USE FACT_C \n!\n! GAM(I) = LOG( GAMMA(I-1) ), WHERE GAMMA(I) = FACTORIAL I-1\n!\n!...Translated by Pacific-Sierra Research 77to90 4.3E 21:52:17 11/14/01 \n!...Switches: \n IMPLICIT NONE\n!-----------------------------------------------\n! D u m m y A r g u m e n t s\n!-----------------------------------------------\n INTEGER , INTENT(IN) :: NFACT \n!-----------------------------------------------\n! L o c a l V a r i a b l e s\n!-----------------------------------------------\n INTEGER :: I \n REAL(DOUBLE) :: ZERO, ONE, TWO, GAMMA, X \n!-----------------------------------------------\n!\n DATA ZERO, ONE, TWO/ 0.D0, 1.D0, 2.D0/ \n!\n GAMMA = ONE \n GAM(1) = ZERO \n DO I = 1, NFACT - 1 \n GAMMA = I*GAMMA \n GAM(I+1) = DLOG(GAMMA) \n END DO \n DO I = NFACT + 1, 100 \n X = I - 1 \n GAM(I) = GAM(I-1) + DLOG(X) \n END DO \n RETURN \n END SUBROUTINE FACTRL \n", "meta": {"hexsha": "3339975b52fa75c1faca9d8f52c0424eba309c85", "size": 1339, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src90/lib/libcom90/factrl.f90", "max_stars_repo_name": "mansour2014/ATSP2K_plus", "max_stars_repo_head_hexsha": "30842b9f086d1e497aeb778e2a352d1e8e520ec3", "max_stars_repo_licenses": ["BSD-4-Clause-UC"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-07-21T14:03:39.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-21T14:03:39.000Z", "max_issues_repo_path": "src90/lib/libcom90/factrl.f90", "max_issues_repo_name": "mzmansour/ATSP2K_plus", "max_issues_repo_head_hexsha": "30842b9f086d1e497aeb778e2a352d1e8e520ec3", "max_issues_repo_licenses": ["BSD-4-Clause-UC"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src90/lib/libcom90/factrl.f90", "max_forks_repo_name": "mzmansour/ATSP2K_plus", "max_forks_repo_head_hexsha": "30842b9f086d1e497aeb778e2a352d1e8e520ec3", "max_forks_repo_licenses": ["BSD-4-Clause-UC"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.4318181818, "max_line_length": 76, "alphanum_fraction": 0.2994772218, "num_tokens": 355, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310357, "lm_q2_score": 0.7634837689358858, "lm_q1q2_score": 0.6577704392186816}} {"text": "!! # ----------------------------------------------------------------------------------\n!! # Output and diagnostics\n!! # ----------------------------------------------------------------------------------\nsubroutine fclaw3dx_clawpatch46_fort_conservation_check(mx,my,mz, & \n mbc,mfields,dx,dy,dz,area,q,sum,c_kahan)\n implicit none\n\n integer :: mx,my,mz,mbc,mfields\n double precision :: dx, dy,dz\n double precision :: sum(mfields), c_kahan(mfields)\n double precision :: q(1-mbc:mx+mbc,1-mbc:my+mbc,1-mbc:mz+mbc,mfields)\n double precision :: area(-mbc:mx+mbc+1,-mbc:my+mbc+1)\n\n integer :: i,j,k,m\n double precision :: t, y, area_ij, vol_ij\n integer*8 :: cont, get_context\n logical :: fclaw2d_map_is_used\n\n logical :: use_kahan\n\n use_kahan = .true.\n\n cont = get_context()\n\n area_ij = dx*dy !! Area in each mesh cell is constant\n do m = 1,mfields\n do k = 1,mz\n do j = 1,my\n do i = 1,mx\n if (fclaw2d_map_is_used(cont)) then\n area_ij = area(i,j) !! Area varies\n endif\n vol_ij = area_ij*dz\n if (use_kahan) then\n y = q(i,j,k,m)*vol_ij - c_kahan(m)\n t = sum(m) + y\n c_kahan(m) = (t-sum(m)) - y\n sum(m) = t\n else\n sum(m) = sum(m) + q(i,j,k,m)*vol_ij\n endif\n enddo \n enddo\n end do\n end do\nend subroutine fclaw3dx_clawpatch46_fort_conservation_check\n\n!! # Compute area of a patch\ndouble precision function fclaw3dx_clawpatch46_fort_compute_patch_area( & \n mx,my, mz, mbc,dx,dy,dz, area)\n implicit none\n\n integer :: mx,my, mz, mbc\n double precision :: dx, dy, dz\n double precision :: area(-mbc:mx+mbc+1,-mbc:my+mbc+1)\n\n integer :: i,j\n integer*8 :: cont, get_context\n logical :: fclaw2d_map_is_used\n double precision :: sum\n\n cont = get_context()\n\n if (fclaw2d_map_is_used(cont)) then\n sum = 0 \n do j = 1,my\n do i = 1,mx\n sum = sum + area(i,j)\n end do\n end do\n else\n sum = dx*dy*mx*my\n endif\n\n fclaw3dx_clawpatch46_fort_compute_patch_area = sum\n\nend function fclaw3dx_clawpatch46_fort_compute_patch_area\n\n\nsubroutine fclaw3dx_clawpatch46_fort_compute_error_norm( & \n blockno, mx,my,mz,mbc,mfields,dx,dy,dz,area,error,error_norm)\n implicit none\n\n integer :: mx,my,mz, mbc,mfields, blockno\n double precision :: dx, dy, dz\n double precision :: error_norm(mfields,3)\n double precision :: error(1-mbc:mx+mbc,1-mbc:my+mbc,1-mbc:mz+mbc,mfields)\n double precision :: area(-mbc:mx+mbc+1,-mbc:my+mbc+1)\n\n integer :: i,j,k,m\n double precision :: dxdydz, eij, vol_ij\n\n integer*8 :: cont, get_context\n logical :: fclaw2d_map_is_used\n\n cont = get_context()\n\n !! # error_norm(:) comes in with values; do not initialize it here!\n dxdydz = dx*dy*dz\n do m = 1,mfields\n if (fclaw2d_map_is_used(cont)) then\n do k = 1,mz\n do j = 1,my\n do i = 1,mx\n vol_ij = area(i,j)*dz\n eij = abs(error(i,j,k,m))\n error_norm(m,1) = error_norm(m,1) + & \n eij*vol_ij\n error_norm(m,2) = error_norm(m,2) + & \n eij**2*vol_ij\n error_norm(m,3) = max(eij,error_norm(m,3))\n end do\n end do\n end do\n else\n do k = 1,mz\n do j = 1,my\n do i = 1,mx\n eij = abs(error(i,j,k,m))\n error_norm(m,1) = error_norm(m,1) + & \n eij*dxdydz\n error_norm(m,2) = error_norm(m,2) + & \n eij**2*dxdydz\n error_norm(m,3) = max(eij,error_norm(m,3))\n end do\n end do\n end do\n endif\n end do\n\nend subroutine fclaw3dx_clawpatch46_fort_compute_error_norm\n", "meta": {"hexsha": "b370f3c4ff177e35d24b90fc06a6fe66aa09538d", "size": 4214, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/patches/clawpatch/fort3_4.6/fclaw3dx_clawpatch46_diagnostics.f90", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/patches/clawpatch/fort3_4.6/fclaw3dx_clawpatch46_diagnostics.f90", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-08-02T09:52:43.000Z", "max_issues_repo_issues_event_max_datetime": "2017-08-02T14:16:23.000Z", "max_forks_repo_path": "src/patches/clawpatch/fort3_4.6/fclaw3dx_clawpatch46_diagnostics.f90", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.9242424242, "max_line_length": 87, "alphanum_fraction": 0.4916943522, "num_tokens": 1205, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310357, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6577704392186815}} {"text": "! DART software - Copyright UCAR. This open source software is provided\n! by UCAR, \"as is\", without charge, subject to all terms of use at\n! http://www.image.ucar.edu/DAReS/DART/DART_download\n!\n! $Id$\n\nmodule meteor_mod\n\nuse types_mod, only : r8, deg2rad\n\nimplicit none\nprivate\n\npublic :: invert_altimeter, &\n pres_alt_to_pres, & \n sat_vapor_pressure, & \n specific_humidity, &\n theta_to_temp, & \n wind_dirspd_to_uv, &\n rh_and_temp_to_dewpoint, &\n temp_and_dewpoint_to_rh\n\nreal(r8), parameter :: grav = 9.81_r8, & ! gravitational constant\n Cp = 1004.5_r8, &\n Rd = 287.0_r8, &\n Rv = 461.6_r8, &\n Lvap = 2500000.0_r8, &\n R_earth = 6370.0_r8, &\n Pref = 100000.0, & ! reference pressure\n Pralt = 101325.0, & ! altimeter reference P\n Talt = 288.15, & ! altimeter reference T\n es0C = 611.0_r8, & ! vapor pressure at 0 C (Pa)\n Tfrez = 273.15_r8, & ! water freezing point (K)\n RvRd = Rv/Rd, & ! Rv/Rd\n RdRv = Rd/Rv, & ! Rd/Rv added 11/2009\n kappa = Rd/Cp, & ! kappa for pot. temp\n dTdzsta =0.0065 ! standard atmosphere lapse rate K/m\n\ncontains\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! invert_altimeter - function that computes the surface pressure\n! given an altimeter setting and the station\n! elevation.\n!\n! altimeter_setting - altimeter setting (hPa)\n! elevation - elevation of station (m)\n! invert_altimeter - surface pressure value (hPa)\n!\n! created Dec. 2007 Ryan Torn, NCAR/MMM\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nfunction invert_altimeter(altimeter_setting, elevation)\n\nuse types_mod, only : r8\n\nimplicit none\n\nreal(r8), parameter :: k1 = 0.190284_r8\nreal(r8), parameter :: k2 = 8.4228807E-5_r8\n\nreal(r8), intent(in) :: altimeter_setting, elevation\n\nreal(r8) :: invert_altimeter ! (hPa)\n\ninvert_altimeter = (altimeter_setting ** k1 - k2 * elevation) ** (1 / k1) + 0.3_r8\n\nreturn\nend function invert_altimeter\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! pres_alt_to_pres - function that computes the pressure level given\n! the pressure altitude. Used mostly for ACARS \n! observations.\n!\n! hght - pressure-height level (m)\n!\n! created Oct. 2007 Ryan Torn, NCAR/MMM\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nfunction pres_alt_to_pres(hght)\n\nreal(r8), parameter :: Po = 101325.0_r8\nreal(r8), intent(in) :: hght\n\nreal(r8) :: C1, pres_alt_to_pres\n\nC1 = grav / (dTdzsta * Rd)\npres_alt_to_pres = Po * exp( C1 * log( 1 - (dTdzsta * hght) / Talt) )\n\nend function pres_alt_to_pres\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! sat_vapor_pressure - function that computes the water vapor \n! saturation vapor pressure given a temperature.\n!\n! tmpk - temperature (K)\n!\n! created Oct. 2007 Ryan Torn, NCAR/MMM\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nfunction sat_vapor_pressure(tmpk)\n\nreal(r8), intent(in) :: tmpk\n\nreal(r8) :: sat_vapor_pressure\n! Clausius-Clapeyron w/ constant Lv in Pa\nsat_vapor_pressure = es0C * exp((Lvap/Rv)*(1.0_r8/Tfrez - 1.0_r8/tmpk))\n\nreturn\nend function sat_vapor_pressure\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! specific_humidity - function that computes the specific humidity \n! given the vapor pressure and atmospheric dry \n! air pressure.\n!\n! vapor_pres - vapor pressure (Pa)\n! pres - atmospheric pressure (Pa)\n!\n! created Dec. 2007 Ryan Torn, NCAR/MMM \n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nfunction specific_humidity(vapor_pres, pres)\n\nreal(r8), intent(in) :: vapor_pres, pres\n\nreal(r8) :: specific_humidity\n\n! 11/2009 changed to Emanuel (1994) eqn 4.1.4\n specific_humidity = (RdRv * vapor_pres) / (pres - vapor_pres*(1.0_r8-RdRv))\n\nreturn\nend function specific_humidity\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! theta_to_temp - function that computes the temperature given a \n! potential temperature and the pressure level.\n!\n! thta - potential temperature (K)\n! pres - pressure (Pa)\n!\n! created Oct. 2007 Ryan Torn, NCAR/MMM\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nfunction theta_to_temp(thta, pres)\n\nreal(r8), intent(in) :: thta, pres\n\nreal(r8) :: theta_to_temp\n\ntheta_to_temp = thta * (Pref/pres) ** (-kappa) \n\nreturn\nend function theta_to_temp\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! wind_dirspd_to_uv - subroutine that converts a wind direction and \n! wind speed to a zonal and meridional wind \n! component.\n!\n! wdir - wind direction\n! wspd - wind speed (m/s)\n! uwnd - u component of the wind (m/s)\n! vwnd - v component of the wind (m/s)\n!\n! created Oct. 2007 Ryan Torn, NCAR/MMM\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine wind_dirspd_to_uv(wdir, wspd, uwnd, vwnd)\n\nreal(r8), intent(in) :: wdir, wspd\nreal(r8), intent(out) :: uwnd, vwnd\n\nuwnd = wspd * cos(deg2rad * (90.0_r8 + wdir))\nvwnd = -wspd * sin(deg2rad * (90.0_r8 + wdir))\n\nreturn\nend subroutine wind_dirspd_to_uv\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! sat_vapor_press_bolton - function that uses Bolton's approximation to\n! compute saturation vapor pressure given\n! temperature.\n!\n! reference: Bolton 1980, MWR, 1046-1053\n!\n! sat_vapor_press_bolton - saturation vapor pressure (Pa)\n! tmpk - temperature (K)\n!\n! created Dec. 2008 David Dowell, NCAR/MMM\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nfunction sat_vapor_press_bolton(tmpk)\n\nreal(r8) :: sat_vapor_press_bolton\nreal(r8), intent(in) :: tmpk\n\nreal(r8) :: tmpc ! temperature (Celsius)\n\ntmpc = tmpk - Tfrez\nif ( tmpc <= -200.0_r8 ) then\n print*,'sat_vapor_press_bolton: tmpc too low ',tmpc\n stop\nend if\nsat_vapor_press_bolton = es0C * exp( 17.67_r8 * tmpc / (tmpc + 243.5_r8) )\n\nreturn\nend function sat_vapor_press_bolton\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! temp_and_dewpoint_to_rh - function that computes the relative humidity\n! given temperature and dewpoint\n!\n! temp_and_dewpoint_to_rh - relative humidity (0.00 - 1.00)\n! tmpk - temperature (Kelvin)\n! dptk - dewpoint (Kelvin)\n!\n! created Dec. 2008 David Dowell, NCAR/MMM\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nfunction temp_and_dewpoint_to_rh(tmpk, dptk)\n\nreal(r8) :: temp_and_dewpoint_to_rh\nreal(r8), intent(in) :: tmpk\nreal(r8), intent(in) :: dptk\n\nreal(r8) :: e ! vapor pressure (Pa)\nreal(r8) :: es ! saturation vapor pressure (Pa)\n\ne = sat_vapor_press_bolton(dptk)\nes = sat_vapor_press_bolton(tmpk)\n\ntemp_and_dewpoint_to_rh = e / es\n\nif (temp_and_dewpoint_to_rh > 1.00_r8) then\n print*,'rh = ', temp_and_dewpoint_to_rh, ', resetting to 1.00'\n temp_and_dewpoint_to_rh = 1.00_r8\nend if\n\nreturn\nend function temp_and_dewpoint_to_rh\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! rh_and_temp_to_dewpoint - function that computes the dewpoint\n! given relative humidity and temperature\n!\n! rh_and_temp_to_dewpoint - dewpoint (Kelvin)\n! rh - relative humidity (0.00 - 1.00)\n! tmpk - temperature (Kelvin)\n!\n! created Dec. 2008 David Dowell, NCAR/MMM\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nfunction rh_and_temp_to_dewpoint(rh, tmpk)\n\nreal(r8) :: rh_and_temp_to_dewpoint\nreal(r8), intent(in) :: rh\nreal(r8), intent(in) :: tmpk\n\nreal(r8) :: e ! vapor pressure (Pa)\nreal(r8) :: es ! saturation vapor pressure (Pa)\nreal(r8) :: dptc ! dptc (Celsius)\n\nif ( ( rh <= 0.00_r8 ) .or. ( rh > 1.00_r8 ) ) then\n print*,'rh_and_temp_to_dewpoint: bad rh ',rh\n stop\nend if\nif ( rh <= 0.01_r8 ) then\n print*,'rh_and_temp_to_dewpoint: low rh ',rh\nend if\n\nes = sat_vapor_press_bolton(tmpk)\ne = rh * es\n\ndptc = 243.5_r8 / (17.67_r8 / log(e/es0C) - 1.0_r8)\n\nrh_and_temp_to_dewpoint = dptc + Tfrez\n\nreturn\nend function rh_and_temp_to_dewpoint\n\n\nend module meteor_mod\n\n! \n! $URL$\n! $Id$\n! $Revision$\n! $Date$\n", "meta": {"hexsha": "9c24004f3c1bceb22b899881e5e33e7b21a5eed3", "size": 9288, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "observations/obs_converters/NCEP/netcdf/meteor_mod.f90", "max_stars_repo_name": "hkershaw-brown/feature-preprocess", "max_stars_repo_head_hexsha": "fe2bd77b38c63fa0566c83ebc4d2fac1623aef66", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 65, "max_stars_repo_stars_event_min_datetime": "2019-10-16T13:31:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-14T11:52:58.000Z", "max_issues_repo_path": "observations/obs_converters/NCEP/netcdf/meteor_mod.f90", "max_issues_repo_name": "hkershaw-brown/feature-preprocess", "max_issues_repo_head_hexsha": "fe2bd77b38c63fa0566c83ebc4d2fac1623aef66", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 283, "max_issues_repo_issues_event_min_datetime": "2019-09-23T15:48:34.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:44:41.000Z", "max_forks_repo_path": "observations/obs_converters/NCEP/netcdf/meteor_mod.f90", "max_forks_repo_name": "hkershaw-brown/feature-preprocess", "max_forks_repo_head_hexsha": "fe2bd77b38c63fa0566c83ebc4d2fac1623aef66", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 67, "max_forks_repo_forks_event_min_datetime": "2019-09-19T22:13:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-20T15:58:26.000Z", "avg_line_length": 30.96, "max_line_length": 85, "alphanum_fraction": 0.5163652024, "num_tokens": 2531, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850093037731, "lm_q2_score": 0.7025300449389326, "lm_q1q2_score": 0.6577683496618286}} {"text": "c\nc --- main program below module\nc\n MODULE EULER_ROTATION\n IMPLICIT NONE\n\n!-----------------------------------------------------------------------\n! euler rotation of model geometry\n!-----------------------------------------------------------------------\n! based on code fragments provided for AOMIP by David Holland.\n! http://fish.cims.nyu.edu/project_aomip/model_grid/overview.html\n!-----------------------------------------------------------------------\n!\n! C_ALPHA : rotation about z-axis\n! C_BETA : rotation about new y-axis \n! C_GAMMA : rotation about new z-axis \n! C_FORWARD : rotation matricies to geographic coordinates\n! C_REVERSE : rotation matricies to model coordinates\n!\n!-----------------------------------------------------------------------\n\n REAL*8 :: \n & C_ALPHA = 000.0 \n\n REAL*8 ::\n & C_BETA = 000.0 \n\n REAL*8 ::\n & C_GAMMA = 000.0 \n\n REAL*8,\n & DIMENSION (1:3, 1:3) ::\n & C_FORWARD = 0.0\n\n REAL*8,\n & DIMENSION (1:3, 1:3) ::\n & C_REVERSE = 0.0\n\n REAL*8, PRIVATE, PARAMETER :: C_EPSILON=1.0d-5\n REAL*8, PRIVATE, PARAMETER :: RADIAN=57.29577951D0\n REAL*8, PRIVATE, PARAMETER :: INVRADIAN=1.d0/RADIAN\n\n!-----------------------------------------------------------------------\n CONTAINS\n!-----------------------------------------------------------------------\n\n REAL*8 FUNCTION C_SIND(X)\n REAL*8 X\n C_SIND = SIN(X*INVRADIAN)\n END FUNCTION C_SIND\n\n REAL*8 FUNCTION C_COSD(X)\n REAL*8 X\n C_COSD = COS(X*INVRADIAN)\n END FUNCTION C_COSD\n\n REAL*8 FUNCTION C_INV_SIND(X)\n REAL*8 X\n C_INV_SIND = RADIAN*ASIN(X)\n END FUNCTION C_INV_SIND\n\n REAL*8 FUNCTION C_INV_COSD(X)\n REAL*8 X\n C_INV_COSD = RADIAN*ACOS(X)\n END FUNCTION C_INV_COSD\n\n SUBROUTINE C_EULER_ROTATION_MATRIX \n \n!-----------------------------------------------------------------------\n! purpose: compute euler rotation matrix \n!-----------------------------------------------------------------------\n!\n! C_ALPHA : rotation about z-axis \n! C_BETA : rotation about new y-axis \n! C_GAMMA : rotation about new z-axis \n! C_REVERSE : rotation to model coordinates \n! C_FORWARD : rotation to geographic coordinates\n!\n!-----------------------------------------------------------------------\n\n !local vars\n REAL*8 :: \n &\n & COSA, \n & SINA, \n & COSB, \n & SINB, \n & COSG, \n & SING\n\n!-----------------------------------------------------------------------\n\n !compute sin and cos of all angles in degrees\n COSA = C_COSD (C_ALPHA )\n SINA = C_SIND (C_ALPHA )\n COSB = C_COSD (C_BETA )\n SINB = C_SIND (C_BETA )\n COSG = C_COSD (C_GAMMA )\n SING = C_SIND (C_GAMMA )\n \n !compute rotation matrix into model coordinates\n C_REVERSE (1,1) = COSA * COSB * COSG - SINA * SING\n C_REVERSE (1,2) = SINA * COSB * COSG + COSA * SING\n C_REVERSE (1,3) = - SINB * COSG\n C_REVERSE (2,1) = - COSA * COSB * SING - SINA * COSG\n C_REVERSE (2,2) = - SINA * COSB * SING + COSA * COSG\n C_REVERSE (2,3) = SINB * SING\n C_REVERSE (3,1) = COSA * SINB\n C_REVERSE (3,2) = SINA * SINB\n C_REVERSE (3,3) = COSB\n \n !compute rotation matrix into geographical coordinates\n C_FORWARD (1,1) = COSG * COSB * COSA - SING * SINA\n C_FORWARD (1,2) = - SING * COSB * COSA - COSG * SINA\n C_FORWARD (1,3) = SINB * COSA\n C_FORWARD (2,1) = COSG * COSB * SINA + SING * COSA\n C_FORWARD (2,2) = - SING * COSB * SINA + COSG * COSA\n C_FORWARD (2,3) = SINB * SINA\n C_FORWARD (3,1) = - COSG * SINB\n C_FORWARD (3,2) = SING * SINB\n C_FORWARD (3,3) = COSB\n \n!-----------------------------------------------------------------------\n END SUBROUTINE C_EULER_ROTATION_MATRIX\n\n\n SUBROUTINE C_MODEL_TO_GEO (X_IN_ANGLE, \n & Y_IN_ANGLE, \n & X_OUT_ANGLE, \n & Y_OUT_ANGLE)\n\n!---------------------------------------------------------------------\n! purpose: a coordinate transformation from model coordinates\n! to geographic coordinates\n!--------------------------------------------------------------------\n!\n! variables\n!\n! X_IN_ANGLE : X-COORDINATE IN MODEL SYSTEM.\n! Y_IN_ANGLE : Y-COORDINATE IN MODEL SYSTEM.\n! X_OUT_ANGLE : X-COORDINATE IN GEOGRAPHICAL SYSTEM.\n! Y_OUT_ANGLE : Y-COORDINATE IN GEOGRAPHICAL SYSTEM.\n!\n! THE ROTATION FROM THE COORDINATE SYSTEM,\n! X''',Y''',Z''' BACK TO THE ORIGINAL COORDINATE SYTEM\n! CAN BE PERFORMED BY DOING THE ROTATION IN\n! REVERSED ORDER AND WITH OPPOSITE SIGN ON THE ROTATED ANGLES.\n!\n!---------------------------------------------------------------------\n\n !passed arguments\n REAL*8,\n & INTENT (IN) :: \n &\n & X_IN_ANGLE,\n & Y_IN_ANGLE\n\n !passed arguments\n REAL*8,\n & INTENT (OUT) :: \n &\n & X_OUT_ANGLE,\n & Y_OUT_ANGLE\n\n !local vars\n REAL*8 :: \n &\n & X_TMP_ANGLE,\n & Y_TMP_ANGLE,\n & XX,\n & YY,\n & ZZ, \n & XNEW,\n & YNEW,\n & ZNEW,\n & COSTN,\n & PHI_NEW,\n & THETA_NEW\n\n!---------------------------------------------------------------------\n\n !initial angles of rotation\n X_TMP_ANGLE = X_IN_ANGLE\n Y_TMP_ANGLE = Y_IN_ANGLE\n\n !avoid trouble of an exactly zero angle by adding offset\n X_TMP_ANGLE = X_TMP_ANGLE + C_EPSILON\n Y_TMP_ANGLE = Y_TMP_ANGLE + C_EPSILON\n write(6,*) 'X_TMP_ANGLE,Y_TMP_ANGLE = ',X_TMP_ANGLE,Y_TMP_ANGLE\n call flush(6)\n\n !spherical coordiantes to cartesian coordinates\n XX = C_COSD (Y_TMP_ANGLE) * C_COSD (X_TMP_ANGLE)\n YY = C_COSD (Y_TMP_ANGLE) * C_SIND (X_TMP_ANGLE)\n ZZ = C_SIND (Y_TMP_ANGLE)\n write(6,*) 'XX,YY,ZZ = ',XX,YY,ZZ\n call flush(6)\n \n !new cartesian coordinates are given by\n XNEW = C_FORWARD (1,1) * XX \n & + C_FORWARD (1,2) * YY \n & + C_FORWARD (1,3) * ZZ\n YNEW = C_FORWARD (2,1) * XX \n & + C_FORWARD (2,2) * YY \n & + C_FORWARD (2,3) * ZZ\n ZNEW = C_FORWARD (3,1) * XX \n & + C_FORWARD (3,2) * YY \n & + C_FORWARD (3,3) * ZZ\n write(6,*) 'XNEW,YNEW,ZNEW = ',XNEW,YNEW,ZNEW\n call flush(6)\n \n !obtain new angles THETA_NEW,COSTN,PHI_NEW\n THETA_NEW = C_INV_SIND (ZNEW)\n write(6,*) 'THETA_NEW = ',THETA_NEW\n call flush(6)\n COSTN = SQRT (1.0 - ZNEW**2)\n write(6,*) 'COSTN = ',COSTN\n call flush(6)\n\n IF ((XNEW > 0.0) .AND. (YNEW > 0.0)) THEN\n\n IF (XNEW < YNEW) THEN\n PHI_NEW = C_INV_COSD (XNEW/COSTN)\n ELSE\n PHI_NEW = C_INV_SIND (YNEW/COSTN)\n ENDIF\n\n ELSEIF ((XNEW < 0.0) .AND. (YNEW > 0.0)) THEN\n\n IF (ABS (XNEW) < YNEW) THEN\n PHI_NEW = 180.0 - C_INV_COSD (ABS (XNEW)/COSTN)\n ELSE\n PHI_NEW = 180.0 - C_INV_SIND (YNEW/COSTN)\n ENDIF\n\n ELSEIF ((XNEW < 0.0) .AND. (YNEW < 0.0)) THEN\n\n IF (ABS (XNEW) < ABS (YNEW)) THEN\n PHI_NEW =-180.0 + C_INV_COSD (ABS (XNEW)/COSTN)\n ELSE\n PHI_NEW =-180.0 + C_INV_SIND (ABS (YNEW)/COSTN)\n ENDIF\n\n ELSEIF ((XNEW > 0.0) .AND. (YNEW < 0.0)) THEN\n\n IF( XNEW < ABS (YNEW)) THEN\n PHI_NEW = - C_INV_COSD (ABS (XNEW)/COSTN)\n ELSE\n PHI_NEW = - C_INV_SIND (ABS (YNEW)/COSTN)\n ENDIF\n\n ENDIF\n write(6,*) 'PHI_NEW = ',PHI_NEW\n call flush(6)\n\n !new spherical coordinates \n X_OUT_ANGLE = PHI_NEW\n Y_OUT_ANGLE = THETA_NEW\n\n* IF (X_OUT_ANGLE < 0.0) X_OUT_ANGLE = X_OUT_ANGLE + 360.0\n\n !avoid trouble of an exactly zero angle by subtracting offset\n X_OUT_ANGLE = X_OUT_ANGLE - C_EPSILON\n Y_OUT_ANGLE = Y_OUT_ANGLE - C_EPSILON\n\n!-----------------------------------------------------------------------\n END SUBROUTINE C_MODEL_TO_GEO\n\n\n!-----------------------------------------------------------------------\n END MODULE EULER_ROTATION\n\n\n program test\n use euler_rotation\n implicit none\nc\n integer i,j\n real*8 xi,xo,yi,yo\nc\nc --- based on the AOMIP Euler rotation code fragments at\nc --- http://fish.cims.nyu.edu/project_aomip/model_grid/overview.html\nc\nc --- initialize rotated grid\nc\n c_alpha = -30.0\n c_beta = -90.0\n c_gamma = 0.0\nc\n call c_euler_rotation_matrix\nc\n write(6,*) 'c_angles = ',c_alpha,c_beta,c_gamma\n write(6,*)\n write(6,*) 'c_forward = ',C_FORWARD\n write(6,*)\n write(6,*) 'c_reverse = ',C_REVERSE\n write(6,*)\nc\n do j= -30,30,10\n do i= -30,30,10\n xi = i\n yi = j\n call c_model_to_geo(xi,yi, xo,yo)\n write(6,*) 'xi,yi = ',xi,yi\n write(6,*) 'xo,yo = ',xo,yo\n enddo\n enddo\n end\n", "meta": {"hexsha": "cfcec778e1fcceaa6b54e94e529a5c5b0d9420f7", "size": 9097, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "topo/src/grid_rotated_test.f", "max_stars_repo_name": "TillRasmussen/HYCOM-tools", "max_stars_repo_head_hexsha": "7d26b60ce65ac9d785e0e36add36aca05c0f496d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2019-05-31T02:47:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T19:21:04.000Z", "max_issues_repo_path": "topo/src/grid_rotated_test.f", "max_issues_repo_name": "TillRasmussen/HYCOM-tools", "max_issues_repo_head_hexsha": "7d26b60ce65ac9d785e0e36add36aca05c0f496d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2019-09-27T08:20:13.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-18T16:50:53.000Z", "max_forks_repo_path": "topo/src/grid_rotated_test.f", "max_forks_repo_name": "TillRasmussen/HYCOM-tools", "max_forks_repo_head_hexsha": "7d26b60ce65ac9d785e0e36add36aca05c0f496d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2019-03-21T08:43:56.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-24T08:08:56.000Z", "avg_line_length": 29.4401294498, "max_line_length": 72, "alphanum_fraction": 0.4768605035, "num_tokens": 2698, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122188543453, "lm_q2_score": 0.7248702880639791, "lm_q1q2_score": 0.6576836694449174}} {"text": "\n!-------------------------------------------------------------------------------\n!+\n! Generates Gaussian samples N(mu,sigma^2) using the Box-Muller Transform (in polar form)\n!+\n!-------------------------------------------------------------------------------\nsubroutine sample_gaussian(x,mu,sigma)\nuse stardata, only: ran2, iseed\nimplicit none\n\nreal, intent(inout) :: x\nreal, intent(in) :: mu, sigma\n\nreal :: w,y1,y2\n\nw = 10.0\n\ndo while(w>1.0)\n y1 = 2.0*ran2(iseed) - 1.0\n y2 = 2.0*ran2(iseed) - 1.0\n\n w = y1*y1 + y2*y2\nenddo\n\n! Gaussian variate of N(0,1)\nx = y1*sqrt(-log(w)/w)\n\n! Convert to N(mu, sigma^2)\nx = x*sigma + mu\n\nend subroutine sample_gaussian\n", "meta": {"hexsha": "64d899d9d68e380462d13b91f7c9e9b9096a7efc", "size": 663, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/embryo/sample_gaussian.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/embryo/sample_gaussian.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/embryo/sample_gaussian.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": 20.71875, "max_line_length": 89, "alphanum_fraction": 0.4947209653, "num_tokens": 208, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122313857378, "lm_q2_score": 0.7248702702332475, "lm_q1q2_score": 0.6576836623505105}} {"text": "program rutherford_scattering\n implicit none\n\n integer, parameter :: dp = selected_real_kind(14)\n real(kind=dp), parameter :: pi = real(4, kind=dp)*atan(real(1, kind=dp))\n integer, parameter :: n_pts = 100\n real(kind=dp), parameter :: Mn = 939.5654133, Mz = 938.2720813\n integer :: Zp, Zt, Np, Nt, Ap, At, i, j, k\n real(kind=dp) :: Mp, Mt, Rt, imp_param, KEp, Vp, dt\n real(kind=dp) :: t_list(n_pts), z(n_pts, 4) \n ! Bisection variables\n real(kind=dp) :: R_hi, R_lo, R_mid, Rt_th\n\n read(*,*) KEp\n imp_param = 0\n Zp=2;Np=2;Zt=79;Nt=118\n\n dt = 100\n Ap = Zp+Np; At = Zt+Nt;\n Mp = Zp*Mz + Np*Mn; Mt = Zt*Mz + Np*Mn;\n Vp = sqrt(2*KEp/Mp)\n\n Rt_th = 1.2*At**(1.0d0/3.0d0) !Theoretical value\n ! Set inital conditions\n z(1,:) = [-100.0d0, vp, imp_param, 0.0d0]\n\n\n ! Setting initial bounds for bisection\n R_hi = 100.0d0*Rt_th; R_lo=0.01d0*Rt_th;\n\n ! Bisection search for max radius\n do i=1,100\n R_mid = 0.5d0*(R_hi + R_lo)\n ! print *, i, R_mid\n Rt = R_mid \n if( abs(R_hi - R_lo) < 0.001d0) exit\n call rk4(t_list, z, dt, n_pts, 4, rf_scattering_deriv)\n if (maxval(z(:,1)) > -1.0d0*Rt) then\n R_hi = R_mid\n else \n R_lo = R_mid\n end if\n end do\n\n write(*, '(3f7.1,i3)') Rt, maxval(z(:,1)), Rt_th, i\n! do i=1, n_pts\n! write(*, \"(3f14.5)\") t_list(i), z(i,1), z(i,3)\n! end do\n\n\ncontains\n subroutine rf_scattering_deriv(t, z, dzdt)\n implicit none\n real(kind=dp), intent(in) :: t, z(4)\n real(kind=dp), intent(out) :: dzdt(4)\n real(kind=dp) :: r\n real(kind=dp), parameter :: e2 = 1.44\n integer :: qQ\n\n qQ = Zp*Zt\n r = max(sqrt(z(1)*z(1) + z(3)*z(3)), Rt)\n\n dzdt(1) = z(2); dzdt(3) = z(4);\n dzdt(2) = qQ*e2*z(1)/(Mp*r*r*r)\n dzdt(4) = qQ*e2*z(3)/(Mp*r*r*r)\n\n end subroutine rf_scattering_deriv\n \n\n\n subroutine rk4(x,y, dx,n_steps, n_eq, derivs)\n implicit none\n integer, intent(in) :: n_eq, n_steps\n integer :: i\n real(kind=dp), intent(inout) :: x(n_steps), y(n_steps, n_eq)\n real(kind=dp), intent(in) :: dx\n external :: derivs\n real(kind=dp) :: xt \n real(kind=dp), dimension(n_eq) :: dydx, k1, k2, k3, k4, yt\n\n do i=2, n_steps\n xt = x(i-1); yt = y(i-1,:)\n call derivs(xt,yt,dydx)\n k1 = dx*dydx\n call derivs(xt+0.5d0*dx, yt+0.5d0*k1,dydx)\n k2 = dx*dydx\n call derivs(xt+0.5d0*dx, yt+0.5d0*k2,dydx)\n k3 = dx*dydx\n call derivs(xt+dx,yt+k3,dydx)\n k4 = dx*dydx\n\n x(i) = xt + dx\n y(i,:) = yt +(0.5d0*(k1+k4) + k2 + k3)/3.0d0\n end do\n end subroutine rk4\n\nend program rutherford_scattering\n", "meta": {"hexsha": "6fec081324a0f21a89389890087840a2081541e3", "size": 3311, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mte/rfsc_mte.f90", "max_stars_repo_name": "deadbeatfour/phn624-comp-nuc-phy", "max_stars_repo_head_hexsha": "deaeaac5240a1f33425c4ca50539aee4fae2f370", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "mte/rfsc_mte.f90", "max_issues_repo_name": "deadbeatfour/phn624-comp-nuc-phy", "max_issues_repo_head_hexsha": "deaeaac5240a1f33425c4ca50539aee4fae2f370", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "mte/rfsc_mte.f90", "max_forks_repo_name": "deadbeatfour/phn624-comp-nuc-phy", "max_forks_repo_head_hexsha": "deaeaac5240a1f33425c4ca50539aee4fae2f370", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.7857142857, "max_line_length": 80, "alphanum_fraction": 0.4430685593, "num_tokens": 1090, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122188543453, "lm_q2_score": 0.7248702761768248, "lm_q1q2_score": 0.6576836586595569}} {"text": "! ======================================================================\n! NAME\n!\n! MOMENTUM\n!\n! DESCRIPTION\n!\n! MOMENTUM is a supporting program of GPECN1DTDPBC that computes the\n! coeffecients of the Fourier transform of its output wave functions'\n! to produce a momentum distribution for each simulation.\n!\n! AUTHOR\n!\n! Marty Kandes, Ph.D.\n! Computational & Data Science Research Specialist\n! User Services Group\n! San Diego Supercomputer Center\n! University of California, San Diego\n!\n! COPYRIGHT\n! \n! Copyright (c) 2010 - 2021 Martin Charles Kandes\n!\n! LICENSE\n!\n! The MIT License (MIT)\n!\n! LAST UPDATED\n!\n! Friday, March 31st, 2017 \n!\n! ----------------------------------------------------------------------\n PROGRAM MOMENTUM\n IMPLICIT NONE\n\n! Parameter Declarations:\n! -----------------------\n REAL, PARAMETER :: PI = 3.1415926535897932384626433832795028841971E0\n\n! Input Variable and Array Declarations:\n! --------------------------------------\n INTEGER :: NUMBER_OF_GRID_POINTS\n INTEGER :: CURRENT_FILE\n INTEGER :: OUTPUT_SHIFT\n INTEGER :: START_MOMENTUM\n INTEGER :: END_MOMENTUM\n\n REAL :: RADIUS\n\n! Internal Variable and Array Declarations:\n! -----------------------------------------\n CHARACTER(80) :: BUFFER\n\n INTEGER :: CURRENT_GRID_POINT\n INTEGER :: CURRENT_MOMENTUM\n INTEGER :: LENGTH\n INTEGER :: INFO\n\n REAL :: ANGULAR_GRID_SPACING_SIZE\n\n COMPLEX :: FOURIER_COEFFICIENT\n\n COMPLEX, ALLOCATABLE, DIMENSION(:) :: WAVEFUNCTION\n\n! Input Variable Assignment Read from Command-line Arguments:\n! -----------------------------------------------------------\n CALL GET_COMMAND_ARGUMENT(1,BUFFER,LENGTH,INFO)\n READ(BUFFER,*) NUMBER_OF_GRID_POINTS\n\n CALL GET_COMMAND_ARGUMENT(2,BUFFER,LENGTH,INFO)\n READ(BUFFER,*) CURRENT_FILE\n\n CALL GET_COMMAND_ARGUMENT(3,BUFFER,LENGTH,INFO)\n READ(BUFFER,*) OUTPUT_SHIFT\n\n CALL GET_COMMAND_ARGUMENT(4,BUFFER,LENGTH,INFO)\n READ(BUFFER,*) START_MOMENTUM\n\n CALL GET_COMMAND_ARGUMENT(5,BUFFER,LENGTH,INFO)\n READ(BUFFER,*) END_MOMENTUM\n\n CALL GET_COMMAND_ARGUMENT(6,BUFFER,LENGTH,INFO)\n READ(BUFFER,*) RADIUS\n\n! Internal Variable Assignment:\n! -----------------------------\n ANGULAR_GRID_SPACING_SIZE = 2.0E0*PI/FLOAT(NUMBER_OF_GRID_POINTS)\n\n! Allocate Arrays:\n! ----------------\n ALLOCATE(WAVEFUNCTION(NUMBER_OF_GRID_POINTS))\n\n! Main Program:\n! -------------\n OPEN(UNIT=CURRENT_FILE,ACTION='READ',FORM='UNFORMATTED')\n READ(UNIT=CURRENT_FILE) WAVEFUNCTION\n CLOSE(UNIT=CURRENT_FILE)\n OPEN(UNIT=CURRENT_FILE+OUTPUT_SHIFT,ACTION='WRITE',FORM='FORMATTED')\n DO CURRENT_MOMENTUM = START_MOMENTUM, END_MOMENTUM\n FOURIER_COEFFICIENT = CMPLX(0.0E0,0.0E0)\n DO CURRENT_GRID_POINT = 1, NUMBER_OF_GRID_POINTS\n FOURIER_COEFFICIENT = FOURIER_COEFFICIENT+WAVEFUNCTION(CURRENT_GRID_POINT)*EXP(CMPLX(0.0E0,-FLOAT(CURRENT_MOMENTUM)*FLOAT(CURRENT_GRID_POINT-1)*ANGULAR_GRID_SPACING_SIZE))\n ENDDO\n FOURIER_COEFFICIENT=FOURIER_COEFFICIENT*CMPLX(RADIUS*ANGULAR_GRID_SPACING_SIZE/SQRT(2.0E0*PI*RADIUS),0.0E0) \n WRITE(CURRENT_FILE+OUTPUT_SHIFT,900) CURRENT_MOMENTUM, ABS(FOURIER_COEFFICIENT)**2, REAL(FOURIER_COEFFICIENT), AIMAG(FOURIER_COEFFICIENT)\n ENDDO\n CLOSE(UNIT=CURRENT_FILE+OUTPUT_SHIFT)\n\n! Format Statements:\n! ------------------\n900 FORMAT(1X,1(I5),3(F23.15))\n\n! Deallocate Arrays:\n! ------------------\n DEALLOCATE(WAVEFUNCTION)\n\n\n STOP\n ENDPROGRAM MOMENTUM\n! ======================================================================\n", "meta": {"hexsha": "34d1512d5ce4182f73bd795293a0d4a1b7c827e8", "size": 3779, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/momentum.f", "max_stars_repo_name": "mkandes/gpecn1Dtdpbc", "max_stars_repo_head_hexsha": "51646d6804fcd6abfbac154c58d9e5739d795c6b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source/momentum.f", "max_issues_repo_name": "mkandes/gpecn1Dtdpbc", "max_issues_repo_head_hexsha": "51646d6804fcd6abfbac154c58d9e5739d795c6b", "max_issues_repo_licenses": ["MIT"], "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/momentum.f", "max_forks_repo_name": "mkandes/gpecn1Dtdpbc", "max_forks_repo_head_hexsha": "51646d6804fcd6abfbac154c58d9e5739d795c6b", "max_forks_repo_licenses": ["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.2314049587, "max_line_length": 183, "alphanum_fraction": 0.595130987, "num_tokens": 931, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.7248702702332475, "lm_q1q2_score": 0.6576836550836035}} {"text": " SUBROUTINE areaq(x,area,vn)\r\n!---------------------------------------------------\r\n!*** calculates area of a quad base (1GP scheme)\r\n!---------------------------------------------------\r\n\r\n IMPLICIT NONE\r\n\r\n REAL(kind=8):: area,x(3,4),vn(3)\r\n\r\n REAL(kind=8) :: x1(3),x2(3)\r\n\r\n x1(:) = (-x(:,1)+x(:,2)+x(:,3)-x(:,4))/2d0\r\n x2(:) = (-x(:,1)-x(:,2)+x(:,3)+x(:,4))/2d0\r\n CALL vecpro(x1,x2,vn)\r\n CALL vecuni(3,vn,area)\r\n\r\n END SUBROUTINE areaq\r\n", "meta": {"hexsha": "f21e11f92fe7b8c4b66ccd03ef899612e9940ca3", "size": 487, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/loads/areaq.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/loads/areaq.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/loads/areaq.f90", "max_forks_repo_name": "jerebenitez/IFE-simpact-openfoam", "max_forks_repo_head_hexsha": "2dbcbf3195b22fca1c80ad0da6b3822b6cad5cdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.0555555556, "max_line_length": 53, "alphanum_fraction": 0.3675564682, "num_tokens": 156, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480667, "lm_q2_score": 0.7248702702332475, "lm_q1q2_score": 0.6576836514501497}} {"text": "C\nC\t$Id$\nC\n SUBROUTINE CSCIRCUM (V1,V2,V3, C,IER)\n INTEGER IER\n DOUBLE PRECISION V1(3), V2(3), V3(3), C(3)\nC\nC***********************************************************\nC\nC From STRIPACK\nC Robert J. Renka\nC Dept. of Computer Science\nC Univ. of North Texas\nC renka@cs.unt.edu\nC 06/29/95\nC\nC This subroutine returns the circumcenter of a spherical\nC triangle on the unit sphere: the point on the sphere sur-\nC face that is equally distant from the three triangle\nC vertices and lies in the same hemisphere, where distance\nC is taken to be arc-length on the sphere surface.\nC\nC\nC On input:\nC\nC V1,V2,V3 = Arrays of length 3 containing the Carte-\nC sian coordinates of the three triangle\nC vertices (unit vectors) in CCW order.\nC\nC The above parameters are not altered by this routine.\nC\nC C = Array of length 3.\nC\nC On output:\nC\nC C = Cartesian coordinates of the circumcenter unless\nC IER > 0, in which case C is not defined. C =\nC (V2-V1) X (V3-V1) normalized to a unit vector.\nC\nC IER = Error indicator:\nC IER = 0 if no errors were encountered.\nC IER = 1 if V1, V2, and V3 lie on a common\nC line: (V2-V1) X (V3-V1) = 0.\nC (The vertices are not tested for validity.)\nC\nC Modules required by CSCIRCUM: None\nC\nC Intrinsic function called by CSCIRCUM: SQRT\nC\nC***********************************************************\nC\n INTEGER I\n DOUBLE PRECISION CNORM, CU(3), E1(3), E2(3)\nC\nC Local parameters:\nC\nC CNORM = Norm of CU: used to compute C\nC CU = Scalar multiple of C: E1 X E2\nC E1,E2 = Edges of the underlying planar triangle:\nC V2-V1 and V3-V1, respectively\nC I = DO-loop index\nC\n DO 1 I = 1,3\n E1(I) = V2(I) - V1(I)\n E2(I) = V3(I) - V1(I)\n 1 CONTINUE\nC\nC Compute CU = E1 X E2 and CNORM**2.\nC\n CU(1) = E1(2)*E2(3) - E1(3)*E2(2)\n CU(2) = E1(3)*E2(1) - E1(1)*E2(3)\n CU(3) = E1(1)*E2(2) - E1(2)*E2(1)\n CNORM = CU(1)*CU(1) + CU(2)*CU(2) + CU(3)*CU(3)\nC\nC The vertices lie on a common line if and only if CU is\nC the zero vector.\nC\n IF (CNORM .NE. 0.D0) THEN\nC\nC No error: compute C.\nC\n CNORM = SQRT(CNORM)\n DO 2 I = 1,3\n C(I) = CU(I)/CNORM\n 2 CONTINUE\n IER = 0\n ELSE\nC\nC CU = 0.\nC\n IER = 1\n ENDIF\n RETURN\n END\n", "meta": {"hexsha": "b23c89a8445b7a9528c514a1f2d36d2321c3d718", "size": 2663, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "contrib/cssgrid/Src/cscircum.f", "max_stars_repo_name": "xylar/cdat", "max_stars_repo_head_hexsha": "8a5080cb18febfde365efc96147e25f51494a2bf", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 62, "max_stars_repo_stars_event_min_datetime": "2018-03-30T15:46:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-08T23:30:24.000Z", "max_issues_repo_path": "contrib/cssgrid/Src/cscircum.f", "max_issues_repo_name": "xylar/cdat", "max_issues_repo_head_hexsha": "8a5080cb18febfde365efc96147e25f51494a2bf", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 114, "max_issues_repo_issues_event_min_datetime": "2018-03-21T01:12:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-05T12:29:54.000Z", "max_forks_repo_path": "contrib/cssgrid/Src/cscircum.f", "max_forks_repo_name": "CDAT/uvcdat", "max_forks_repo_head_hexsha": "5133560c0c049b5c93ee321ba0af494253b44f91", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2018-06-06T02:42:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-26T03:27:00.000Z", "avg_line_length": 28.0315789474, "max_line_length": 60, "alphanum_fraction": 0.5103266992, "num_tokens": 837, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797172476385, "lm_q2_score": 0.7217432182679956, "lm_q1q2_score": 0.6576377815468328}} {"text": "\tFUNCTION PS_STAB ( datain, nparm, clev, ivcord )\nC************************************************************************\nC* PS_STAB\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes the stability which is the potential\t\t*\nC* temperature lapse rate.\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PS_STAB ( DATAIN, NPARM, CLEV, IVCORD )\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tDATAIN\t\tREAL\t\tStation data\t\t\t*\nC*\tNPARM\t\tINTEGER\t\tNumber of data set parameters\t*\nC*\tCLEV\t\tREAL\t\tVertical level\t\t\t*\nC*\tIVCORD\t\tINTEGER \tVertical coordinate number\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPS_STAB\t\tREAL\t\tStability (d THETA / dz)\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* M. desJardins/GSFC\t 7/90\t\t\t\t\t\t*\nC* T. Lee/GSC\t\t 8/97\tChanged default depth to RMISSD\t\t*\nC************************************************************************\n\tINCLUDE\t\t'GEMPRM.PRM'\nC*\n\tREAL\t\tstndb (10), stndt (10), stndl (10)\nC*\n\tINCLUDE\t\t'ERMISS.FNC'\nC-----------------------------------------------------------------------------\n\tPS_STAB = RMISSD\nC\nC*\tGet depth information.\nC\n\tdfdpth = RMISSD\n\tidfcrd = 3\n\tCALL PC_DPTH ( datain, nparm, clev, ivcord, dfdpth, idfcrd, 1,\n +\t\t\tdepth, idcord, stndl, stndb, stndt, ier )\nC\nC*\tCheck for missing data.\nC\n\tIF ( ( ier .ne. 0 ) .or. ERMISS ( stndt (2) ) .or. \n +\t ERMISS ( stndb (2) ) .or. ERMISS ( stndt (6) ) .or.\n +\t ERMISS ( stndb (6) ) ) RETURN\n\tdepth = stndt (6) - stndb (6)\n\tIF ( depth .eq. 0.0 ) RETURN\nC*\n\tthtop = PR_THTA ( stndt (2), stndt (1) )\n\tthbot = PR_THTA ( stndb (2), stndb (1) )\n\n\tPS_STAB = ( thtop - thbot ) / depth\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "aaa2f77eb6d2bca0a2728d2594aa4b34f263f37f", "size": 1583, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/ps/psstab.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/ps/psstab.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/ps/psstab.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.8679245283, "max_line_length": 78, "alphanum_fraction": 0.5022109918, "num_tokens": 577, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797027760038, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.657637765648437}} {"text": "program test\n use rand_num_gen\n use precision\n integer(idp) :: loop1,loop2\n real(fdp) :: ave, var, inv\n complex(cdp) :: tmp\n real(fdp), parameter :: pi=3.14159265359\n open(unit=1,file=\"data/var.good.dat\")\n open(unit=2,file=\"data/ave.good.dat\")\n do loop1=0,8\n var=dble(0)\n ave=dble(0)\n do loop2=1,10**loop1\n tmp=sqrt(-2*log(random_num()))*exp(cmplx(0,2*pi*random_num()))\n \n inv=1/dble(loop2)\n ave=ave - (ave - real(tmp))*inv\n var=var - (var - real(tmp)**2)*inv\n \n end do\n \n write(1,'(e15.7)') var\n write(2,'(e15.7)') ave\n write(*,*) 'var ',var\n write(*,*) 'ave ',ave\n write(*,*) ' '\n end do\n close(1)\n close(2)\nend program test\n", "meta": {"hexsha": "868b87f72a91ef40ca1c7bf7083ae161cfa4c06e", "size": 721, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test_rand_num.f90", "max_stars_repo_name": "sdm900/quantum_chaos", "max_stars_repo_head_hexsha": "d82b8b3e8108a8de72cc4f86e73eb9d6583b26ec", "max_stars_repo_licenses": ["MIT"], "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_rand_num.f90", "max_issues_repo_name": "sdm900/quantum_chaos", "max_issues_repo_head_hexsha": "d82b8b3e8108a8de72cc4f86e73eb9d6583b26ec", "max_issues_repo_licenses": ["MIT"], "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_rand_num.f90", "max_forks_repo_name": "sdm900/quantum_chaos", "max_forks_repo_head_hexsha": "d82b8b3e8108a8de72cc4f86e73eb9d6583b26ec", "max_forks_repo_licenses": ["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.2580645161, "max_line_length": 70, "alphanum_fraction": 0.547850208, "num_tokens": 259, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998823, "lm_q2_score": 0.7217432062975979, "lm_q1q2_score": 0.6576377636764468}} {"text": "data Nat = Zero\n | S Nat\n\ndata Bool = True\n | False\n\nnot :: Bool -> Bool\nnot = [, ]\n\ninc :: Nat -> Nat\ninc = [, ]\n\nbool2nat :: Bool -> Nat\nbool2nat = [,]\n\nnat2bool :: Nat -> Bool\nnat2bool = [,,]\n\ncompose :: X. Y. Z. (X -> Y) -> (Y -> Z) -> (X -> Z)\ncompose = [<[Nat],[Nat],[Nat],inc,inc,S Zero,S (S (S Zero))>,\n <[Nat],[Bool],[Nat],nat2bool,bool2nat,S (S Zero),S Zero>]\n\nmain :: Unit\nmain = compose [Bool] [Nat] [Bool] bool2nat nat2bool True\n", "meta": {"hexsha": "17091dfbd3ba15307e20f5ca9073bf3088da6b14", "size": 594, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "test/compose.f", "max_stars_repo_name": "joeyginorio/learning_sysf", "max_stars_repo_head_hexsha": "8073a928db69ab5729682072be973132aaf4fadc", "max_stars_repo_licenses": ["MIT"], "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/compose.f", "max_issues_repo_name": "joeyginorio/learning_sysf", "max_issues_repo_head_hexsha": "8073a928db69ab5729682072be973132aaf4fadc", "max_issues_repo_licenses": ["MIT"], "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/compose.f", "max_forks_repo_name": "joeyginorio/learning_sysf", "max_forks_repo_head_hexsha": "8073a928db69ab5729682072be973132aaf4fadc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-07-07T22:47:43.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-07T22:47:43.000Z", "avg_line_length": 23.76, "max_line_length": 68, "alphanum_fraction": 0.5471380471, "num_tokens": 209, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9111797172476384, "lm_q2_score": 0.7217431943271999, "lm_q1q2_score": 0.6576377597324653}} {"text": "* MB03RD EXAMPLE PROGRAM TEXT\n* Copyright (c) 2002-2020 NICONET e.V.\n*\n* .. Parameters ..\n INTEGER NIN, NOUT\n PARAMETER ( NIN = 5, NOUT = 6 )\n INTEGER NMAX\n PARAMETER ( NMAX = 10 )\n INTEGER LDA, LDX\n PARAMETER ( LDA = NMAX, LDX = NMAX )\n INTEGER LDWORK\n PARAMETER ( LDWORK = 3*NMAX )\n* .. Local Scalars ..\n CHARACTER*1 JOBX, SORT\n INTEGER I, INFO, J, N, NBLCKS, SDIM\n DOUBLE PRECISION PMAX, TOL\n* .. Local Arrays ..\n DOUBLE PRECISION A(LDA,NMAX), DWORK(LDWORK), WI(NMAX), WR(NMAX),\n $ X(LDX,NMAX)\n INTEGER BLSIZE(NMAX)\n LOGICAL BWORK(NMAX)\n* .. External Functions ..\n LOGICAL SELECT\n* .. External Subroutines ..\n EXTERNAL DGEES, MB03RD\n* .. Executable Statements ..\n*\n WRITE ( NOUT, FMT = 99999 )\n* Skip the heading in the data file and read the data.\n READ ( NIN, FMT = '()' )\n READ ( NIN, FMT = * ) N, PMAX, TOL, JOBX, SORT\n IF ( N.LT.0 .OR. N.GT.NMAX ) THEN\n WRITE ( NOUT, FMT = 99972 ) N\n ELSE\n READ ( NIN, FMT = * ) ( ( A(I,J), J = 1,N ), I = 1,N )\n* Compute Schur form, eigenvalues and Schur vectors.\n CALL DGEES( 'Vectors', 'Not sorted', SELECT, N, A, LDA, SDIM,\n $ WR, WI, X, LDX, DWORK, LDWORK, BWORK, INFO )\n IF ( INFO.NE.0 ) THEN\n WRITE ( NOUT, FMT = 99998 ) INFO\n ELSE\n* Block-diagonalization.\n CALL MB03RD( JOBX, SORT, N, PMAX, A, LDA, X, LDX, NBLCKS,\n $ BLSIZE, WR, WI, TOL, DWORK, INFO )\n IF ( INFO.NE.0 ) THEN\n WRITE ( NOUT, FMT = 99997 ) INFO\n ELSE\n WRITE ( NOUT, FMT = 99995 ) NBLCKS\n WRITE ( NOUT, FMT = 99994 ) ( BLSIZE(I), I = 1,NBLCKS )\n WRITE ( NOUT, FMT = 99993 )\n DO 10 I = 1, N\n WRITE ( NOUT, FMT = 99992 ) ( A(I,J), J = 1,N )\n 10 CONTINUE\n WRITE ( NOUT, FMT = 99991 )\n DO 20 I = 1, N\n WRITE ( NOUT, FMT = 99992 ) ( X(I,J), J = 1,N )\n 20 CONTINUE\n END IF\n END IF\n END IF\n*\n STOP\n*\n99999 FORMAT (' MB03RD EXAMPLE PROGRAM RESULTS',/1X)\n99998 FORMAT (' INFO on exit from DGEES = ',I2)\n99997 FORMAT (' INFO on exit from MB03RD = ',I2)\n99995 FORMAT (' The number of blocks is ',I5)\n99994 FORMAT (' The orders of blocks are ',/(20(I3,2X)))\n99993 FORMAT (' The block-diagonal matrix is ')\n99992 FORMAT (8X,20(1X,F8.4))\n99991 FORMAT (' The transformation matrix is ')\n99972 FORMAT (/' N is out of range.',/' N = ',I5)\n END\n", "meta": {"hexsha": "88ab2b94a7ef19047f9cf67b0b8a9d76907ccf2d", "size": 2745, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "examples/TMB03RD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "examples/TMB03RD.f", "max_issues_repo_name": "bnavigator/SLICOT-Reference", "max_issues_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "examples/TMB03RD.f", "max_forks_repo_name": "bnavigator/SLICOT-Reference", "max_forks_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 37.0945945946, "max_line_length": 70, "alphanum_fraction": 0.4925318761, "num_tokens": 878, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9032942119105696, "lm_q2_score": 0.7279754548076477, "lm_q1q2_score": 0.6575760147407126}} {"text": "module derived_types\n use constants\n implicit none\n\n\t! save defined data values between different loads of the module\n\tsave\n\n\t! derived data type for storage of material/model parameters\n\ttype :: material_data\n\t\treal(kind=dbl) :: E1\t! elasticity modulus for loading in foliation plane\n\t\treal(kind=dbl) :: nu1\t! poisson ratio for lateral in plane strains due to in plane loading\n\t\treal(kind=dbl) :: E2\t! elasticity modulus perpendicular to foliation plane\n\t\treal(kind=dbl) :: G2\t! shear modulus in planes perependicular to the foliation plane\n\t\treal(kind=dbl) :: nu2\t! poisson ratio for lateral in plane strains due to loading perpendicular to the foliation plane\n\t\treal(kind=dbl) :: F2\t! independent components of transversely isotropic tsai-wu structural vector [F2, F2, F3, 0, 0, 0]\n\t\treal(kind=dbl) :: F3\n\t\treal(kind=dbl) :: F22\t! independent components of transversely isotropic tsau-wu structural matrix\n\t\treal(kind=dbl) :: F33\t! | F22 F12 F23 0 0 0 |\n\t\treal(kind=dbl) :: F44\t! | F22 F23 0 0 0 |\n\t\treal(kind=dbl) :: F12\t! | F33 0 0 0 |\n\t\treal(kind=dbl) :: F23\t! | F44 0 0 |\n\tend type material_data\t\t! | symm. F44 0 |\n\t\t\t\t\t\t\t\t! | 2(F22-F12) |\n\n\n\ttype(material_data) :: mat_pars\n\nend module derived_types\n", "meta": {"hexsha": "a888c59f46a96a42d695e1acca8349461972ab98", "size": 1327, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "derived_types.f90", "max_stars_repo_name": "yuyong1990/TsaiWu-Fortran", "max_stars_repo_head_hexsha": "a111ca1717adfbbaf3e9e34f4189a441e16441b8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2017-11-19T15:12:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T15:34:59.000Z", "max_issues_repo_path": "derived_types.f90", "max_issues_repo_name": "OVGULIU/TsaiWu-Fortran", "max_issues_repo_head_hexsha": "a111ca1717adfbbaf3e9e34f4189a441e16441b8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "derived_types.f90", "max_forks_repo_name": "OVGULIU/TsaiWu-Fortran", "max_forks_repo_head_hexsha": "a111ca1717adfbbaf3e9e34f4189a441e16441b8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 16, "max_forks_repo_forks_event_min_datetime": "2017-02-11T12:56:43.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-01T11:29:18.000Z", "avg_line_length": 45.7586206897, "max_line_length": 121, "alphanum_fraction": 0.6495855313, "num_tokens": 394, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971871, "lm_q2_score": 0.7279754548076478, "lm_q1q2_score": 0.6575760071600258}} {"text": "*DECK QAWF\n SUBROUTINE QAWF (F, A, OMEGA, INTEGR, EPSABS, RESULT, ABSERR,\n + NEVAL, IER, LIMLST, LST, LENIW, MAXP1, LENW, IWORK, WORK)\nC***BEGIN PROLOGUE QAWF\nC***PURPOSE The routine calculates an approximation result to a given\nC Fourier integral\nC I = Integral of F(X)*W(X) over (A,INFINITY)\nC where W(X) = COS(OMEGA*X) or W(X) = SIN(OMEGA*X).\nC Hopefully satisfying following claim for accuracy\nC ABS(I-RESULT).LE.EPSABS.\nC***LIBRARY SLATEC (QUADPACK)\nC***CATEGORY H2A3A1\nC***TYPE SINGLE PRECISION (QAWF-S, DQAWF-D)\nC***KEYWORDS AUTOMATIC INTEGRATOR, CONVERGENCE ACCELERATION,\nC FOURIER INTEGRALS, INTEGRATION BETWEEN ZEROS, QUADPACK,\nC QUADRATURE, SPECIAL-PURPOSE INTEGRAL\nC***AUTHOR Piessens, Robert\nC Applied Mathematics and Programming Division\nC K. U. Leuven\nC de Doncker, Elise\nC Applied Mathematics and Programming Division\nC K. U. Leuven\nC***DESCRIPTION\nC\nC Computation of Fourier integrals\nC Standard fortran subroutine\nC Real version\nC\nC\nC PARAMETERS\nC ON ENTRY\nC F - Real\nC Function subprogram defining the integrand\nC function F(X). The actual name for F needs to be\nC declared E X T E R N A L in the driver program.\nC\nC A - Real\nC Lower limit of integration\nC\nC OMEGA - Real\nC Parameter in the integrand WEIGHT function\nC\nC INTEGR - Integer\nC Indicates which of the WEIGHT functions is used\nC INTEGR = 1 W(X) = COS(OMEGA*X)\nC INTEGR = 2 W(X) = SIN(OMEGA*X)\nC IF INTEGR.NE.1.AND.INTEGR.NE.2, the routine\nC will end with IER = 6.\nC\nC EPSABS - Real\nC Absolute accuracy requested, EPSABS.GT.0.\nC If EPSABS.LE.0, the routine will end with IER = 6.\nC\nC ON RETURN\nC RESULT - Real\nC Approximation to the integral\nC\nC ABSERR - Real\nC Estimate of the modulus of the absolute error,\nC Which should equal or exceed ABS(I-RESULT)\nC\nC NEVAL - Integer\nC Number of integrand evaluations\nC\nC IER - Integer\nC IER = 0 Normal and reliable termination of the\nC routine. It is assumed that the requested\nC accuracy has been achieved.\nC IER.GT.0 Abnormal termination of the routine.\nC The estimates for integral and error are\nC less reliable. It is assumed that the\nC requested accuracy has not been achieved.\nC ERROR MESSAGES\nC If OMEGA.NE.0\nC IER = 1 Maximum number of cycles allowed\nC has been achieved, i.e. of subintervals\nC (A+(K-1)C,A+KC) where\nC C = (2*INT(ABS(OMEGA))+1)*PI/ABS(OMEGA),\nC FOR K = 1, 2, ..., LST.\nC One can allow more cycles by increasing\nC the value of LIMLST (and taking the\nC according dimension adjustments into\nC account). Examine the array IWORK which\nC contains the error flags on the cycles, in\nC order to look for eventual local\nC integration difficulties.\nC If the position of a local difficulty\nC can be determined (e.g. singularity,\nC discontinuity within the interval) one\nC will probably gain from splitting up the\nC interval at this point and calling\nC appropriate integrators on the subranges.\nC = 4 The extrapolation table constructed for\nC convergence acceleration of the series\nC formed by the integral contributions over\nC the cycles, does not converge to within\nC the requested accuracy.\nC As in the case of IER = 1, it is advised\nC to examine the array IWORK which contains\nC the error flags on the cycles.\nC = 6 The input is invalid because\nC (INTEGR.NE.1 AND INTEGR.NE.2) or\nC EPSABS.LE.0 or LIMLST.LT.1 or\nC LENIW.LT.(LIMLST+2) or MAXP1.LT.1 or\nC LENW.LT.(LENIW*2+MAXP1*25).\nC RESULT, ABSERR, NEVAL, LST are set to\nC zero.\nC = 7 Bad integrand behaviour occurs within\nC one or more of the cycles. Location and\nC type of the difficulty involved can be\nC determined from the first LST elements of\nC vector IWORK. Here LST is the number of\nC cycles actually needed (see below).\nC IWORK(K) = 1 The maximum number of\nC subdivisions (=(LENIW-LIMLST)\nC /2) has been achieved on the\nC K th cycle.\nC = 2 Occurrence of roundoff error\nC is detected and prevents the\nC tolerance imposed on the K th\nC cycle, from being achieved\nC on this cycle.\nC = 3 Extremely bad integrand\nC behaviour occurs at some\nC points of the K th cycle.\nC = 4 The integration procedure\nC over the K th cycle does\nC not converge (to within the\nC required accuracy) due to\nC roundoff in the extrapolation\nC procedure invoked on this\nC cycle. It is assumed that the\nC result on this interval is\nC the best which can be\nC obtained.\nC = 5 The integral over the K th\nC cycle is probably divergent\nC or slowly convergent. It must\nC be noted that divergence can\nC occur with any other value of\nC IWORK(K).\nC If OMEGA = 0 and INTEGR = 1,\nC The integral is calculated by means of DQAGIE,\nC and IER = IWORK(1) (with meaning as described\nC for IWORK(K),K = 1).\nC\nC DIMENSIONING PARAMETERS\nC LIMLST - Integer\nC LIMLST gives an upper bound on the number of\nC cycles, LIMLST.GE.3.\nC If LIMLST.LT.3, the routine will end with IER = 6.\nC\nC LST - Integer\nC On return, LST indicates the number of cycles\nC actually needed for the integration.\nC If OMEGA = 0, then LST is set to 1.\nC\nC LENIW - Integer\nC Dimensioning parameter for IWORK. On entry,\nC (LENIW-LIMLST)/2 equals the maximum number of\nC subintervals allowed in the partition of each\nC cycle, LENIW.GE.(LIMLST+2).\nC If LENIW.LT.(LIMLST+2), the routine will end with\nC IER = 6.\nC\nC MAXP1 - Integer\nC MAXP1 gives an upper bound on the number of\nC Chebyshev moments which can be stored, i.e. for\nC the intervals of lengths ABS(B-A)*2**(-L),\nC L = 0,1, ..., MAXP1-2, MAXP1.GE.1.\nC If MAXP1.LT.1, the routine will end with IER = 6.\nC LENW - Integer\nC Dimensioning parameter for WORK\nC LENW must be at least LENIW*2+MAXP1*25.\nC If LENW.LT.(LENIW*2+MAXP1*25), the routine will\nC end with IER = 6.\nC\nC WORK ARRAYS\nC IWORK - Integer\nC Vector of dimension at least LENIW\nC On return, IWORK(K) FOR K = 1, 2, ..., LST\nC contain the error flags on the cycles.\nC\nC WORK - Real\nC Vector of dimension at least\nC On return,\nC WORK(1), ..., WORK(LST) contain the integral\nC approximations over the cycles,\nC WORK(LIMLST+1), ..., WORK(LIMLST+LST) contain\nC the error estimates over the cycles.\nC further elements of WORK have no specific\nC meaning for the user.\nC\nC***REFERENCES (NONE)\nC***ROUTINES CALLED QAWFE, XERMSG\nC***REVISION HISTORY (YYMMDD)\nC 800101 DATE WRITTEN\nC 890831 Modified array declarations. (WRB)\nC 891009 Removed unreferenced variable. (WRB)\nC 891009 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\nC***END PROLOGUE QAWF\nC\n REAL A,ABSERR,EPSABS,F,OMEGA,RESULT,WORK\n INTEGER IER,INTEGR,LENIW,LIMIT,LIMLST,LVL,LST,L1,L2,L3,L4,L5,L6,\n 1 MAXP1,NEVAL\nC\n DIMENSION IWORK(*),WORK(*)\nC\n EXTERNAL F\nC\nC CHECK VALIDITY OF LIMLST, LENIW, MAXP1 AND LENW.\nC\nC***FIRST EXECUTABLE STATEMENT QAWF\n IER = 6\n NEVAL = 0\n RESULT = 0.0E+00\n ABSERR = 0.0E+00\n IF(LIMLST.LT.3.OR.LENIW.LT.(LIMLST+2).OR.MAXP1.LT.1.OR.LENW.LT.\n 1 (LENIW*2+MAXP1*25)) GO TO 10\nC\nC PREPARE CALL FOR QAWFE\nC\n LIMIT = (LENIW-LIMLST)/2\n L1 = LIMLST+1\n L2 = LIMLST+L1\n L3 = LIMIT+L2\n L4 = LIMIT+L3\n L5 = LIMIT+L4\n L6 = LIMIT+L5\n LL2 = LIMIT+L1\n CALL QAWFE(F,A,OMEGA,INTEGR,EPSABS,LIMLST,LIMIT,MAXP1,RESULT,\n 1 ABSERR,NEVAL,IER,WORK(1),WORK(L1),IWORK(1),LST,WORK(L2),\n 2 WORK(L3),WORK(L4),WORK(L5),IWORK(L1),IWORK(LL2),WORK(L6))\nC\nC CALL ERROR HANDLER IF NECESSARY\nC\n LVL = 0\n10 IF(IER.EQ.6) LVL = 1\n IF (IER .NE. 0) CALL XERMSG ('SLATEC', 'QAWF',\n + 'ABNORMAL RETURN', IER, LVL)\n RETURN\n END\n", "meta": {"hexsha": "13f281e29506a94d4b3bc1de84a0160eee8aafb7", "size": 11360, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/qawf.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/qawf.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/qawf.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.3673469388, "max_line_length": 72, "alphanum_fraction": 0.4778169014, "num_tokens": 2702, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971871, "lm_q2_score": 0.7279754489059774, "lm_q1q2_score": 0.6575760018290812}} {"text": "! =============================================================================\n! Test ellipsoid split\n!\n! This unit test checks the splitting of an ellipsoid. The ellipsoid\n! is centred at the origin and the orientation is varied.\n! =============================================================================\nprogram test_ellipsoid_split\n use unit_test\n use constants, only : pi, zero, one, three, four, five, ten, f12, f14, f34\n use parcel_container\n use parcel_ellipsoid, only : get_B33\n use parcel_split_mod, only : parcel_split, split_timer\n use parameters, only : update_parameters, nx, ny, nz, extent, lower, vmax\n use timer\n implicit none\n\n double precision, parameter :: lam = five\n double precision :: theta, phi, st, ct, sp, cp\n double precision :: B11, B12, B13, B22, B23, B33, abc, ab, evec(3)\n double precision :: h, pos(3, 2), error, a2, b2, c2\n integer :: i, j\n\n nx = 10\n ny = 10\n nz = 10\n extent = (/ten, ten, ten/)\n lower = (/-five, -five, -five/)\n call update_parameters\n\n vmax = one\n\n call register_timer('parcel split', split_timer)\n\n call parcel_alloc(2)\n\n abc = one\n ab = f34\n\n a2 = ab * lam\n b2 = ab / lam\n c2 = (abc / ab) ** 2\n\n error = zero\n\n do i = 0, 7\n theta = dble(i) * f14 * pi\n st = dsin(theta)\n ct = dcos(theta)\n do j = 0, 7\n phi = dble(j) * f14 * pi\n sp = dsin(phi)\n cp = dcos(phi)\n\n call setup_parcels\n\n ! numerical split\n call parcel_split(parcels, threshold=four)\n\n call check_result\n enddo\n enddo\n\n call print_result_dp('Test ellipsoid split', error, atol=1.0e-14)\n\n call parcel_dealloc\n\n\n contains\n\n subroutine setup_parcels\n n_parcels = 1\n\n parcels%position(:, 1) = zero\n parcels%volume(1) = four / three * abc * pi\n parcels%buoyancy(1) = one\n#ifndef ENABLE_DRY_MODE\n parcels%humidity(1) = one\n#endif\n ! 7 Nov 2021\n ! https://mathworld.wolfram.com/SphericalCoordinates.html\n B11 = a2 * ct ** 2 * sp ** 2 + b2 * st ** 2 + c2 * ct ** 2 * cp ** 2\n B12 = a2 * st * ct * sp ** 2 - b2 * st * ct + c2 * st * ct * cp ** 2\n B13 = (a2 - c2) * ct * sp * cp\n B22 = a2 * st ** 2 * sp ** 2 + b2 * ct ** 2 + c2 * st ** 2 * cp ** 2\n B23 = (a2 - c2) * st * sp * cp\n B33 = a2 * cp ** 2 + c2 * sp ** 2\n\n parcels%B(1, 1) = B11\n parcels%B(2, 1) = B12\n parcels%B(3, 1) = B13\n parcels%B(4, 1) = B22\n parcels%B(5, 1) = B23\n end subroutine setup_parcels\n\n subroutine check_result\n ! analytic split\n h = f12 * dsqrt(three / five * a2)\n B11 = B11 - f34 * a2 * ct ** 2 * sp ** 2\n B12 = B12 - f34 * a2 * st * ct * sp ** 2\n B13 = B13 - f34 * a2 * ct * sp * cp\n B22 = B22 - f34 * a2 * st ** 2 * sp ** 2\n B23 = B23 - f34 * a2 * st * sp * cp\n B33 = B33 - f34 * a2 * cp ** 2\n\n if ((a2 > b2) .and. (a2 > c2)) then\n evec = (/ct * sp, st * sp, cp/)\n else if ((b2 > a2) .and. (b2 > c2)) then\n evec = (/-st, ct, zero/)\n else if ((c2 > a2) .and. (c2 > b2)) then\n evec = (/ct * cp, st * cp, -sp/)\n else\n error = one\n endif\n\n pos(:, 1) = h * evec\n pos(:, 2) = - h * evec\n\n ! exchange position\n if (sum(abs(pos(:, 1) - parcels%position(:, 1))) > 1.0e-13) then\n pos = -pos\n endif\n\n ! first parcel\n error = max(error, abs(parcels%B(1, 1) - B11))\n error = max(error, abs(parcels%B(2, 1) - B12))\n error = max(error, abs(parcels%B(3, 1) - B13))\n error = max(error, abs(parcels%B(4, 1) - B22))\n error = max(error, abs(parcels%B(5, 1) - B23))\n error = max(error, abs(get_B33(parcels%B(:, 1), parcels%volume(1)) - B33))\n error = max(error, sum(abs(pos(:, 1) - parcels%position(:, 1))))\n error = max(error, abs(f12 * four / three * abc * pi - parcels%volume(1)))\n error = max(error, abs(parcels%buoyancy(1) - one))\n#ifndef ENABLE_DRY_MODE\n error = max(error, abs(parcels%humidity(1) - one))\n#endif\n\n ! second parcel\n error = max(error, abs(parcels%B(1, 2) - B11))\n error = max(error, abs(parcels%B(2, 2) - B12))\n error = max(error, abs(parcels%B(3, 2) - B13))\n error = max(error, abs(parcels%B(4, 2) - B22))\n error = max(error, abs(parcels%B(5, 2) - B23))\n error = max(error, abs(get_B33(parcels%B(:, 2), parcels%volume(2)) - B33))\n error = max(error, sum(abs(pos(:, 2) - parcels%position(:, 2))))\n error = max(error, abs(f12 * four / three * abc * pi - parcels%volume(2)))\n error = max(error, dble(abs(n_parcels - 2)))\n error = max(error, abs(parcels%buoyancy(2) - one))\n#ifndef ENABLE_DRY_MODE\n error = max(error, abs(parcels%humidity(2) - one))\n#endif\n end subroutine check_result\n\nend program test_ellipsoid_split\n", "meta": {"hexsha": "cd90741b0fdf2d3f7cc0c3725919f46177c12fe4", "size": 5309, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "unit-tests/3d/test_ellipsoid_split.f90", "max_stars_repo_name": "matt-frey/epic", "max_stars_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2021-11-11T10:50:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T00:11:41.000Z", "max_issues_repo_path": "unit-tests/3d/test_ellipsoid_split.f90", "max_issues_repo_name": "matt-frey/epic", "max_issues_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 47, "max_issues_repo_issues_event_min_datetime": "2021-11-12T17:09:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-24T16:50:58.000Z", "max_forks_repo_path": "unit-tests/3d/test_ellipsoid_split.f90", "max_forks_repo_name": "matt-frey/epic", "max_forks_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.474025974, "max_line_length": 86, "alphanum_fraction": 0.4823883971, "num_tokens": 1652, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971871, "lm_q2_score": 0.7279754430043072, "lm_q1q2_score": 0.6575759964981367}} {"text": "use, intrinsic:: iso_fortran_env, only: wp=>real32\nimplicit none\n\n! look at classic problems with any floating point usages.\n! To save agony, it's best for EVERY float constant to have a decimal point and _wp after EACH float number in an equation.\n\nreal(wp), parameter :: me = 9.10938356e-31_wp, mebad = 9.10938356_wp*10**(-31)\n\nprint *,'electron rest mass is',me,'kg., not',mebad\n\nend program\n", "meta": {"hexsha": "2f1c7b7995524d2104664fac2648e5a9c55a8d1a", "size": 395, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "real/precision_problems.f90", "max_stars_repo_name": "plasmasimulation/fortran2018-examples", "max_stars_repo_head_hexsha": "0a7d336e0fc8508b2d6c0e30eff0c3325c57f735", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-04-28T02:10:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-28T02:10:26.000Z", "max_issues_repo_path": "real/precision_problems.f90", "max_issues_repo_name": "plasmasimulation/fortran2018-examples", "max_issues_repo_head_hexsha": "0a7d336e0fc8508b2d6c0e30eff0c3325c57f735", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "real/precision_problems.f90", "max_forks_repo_name": "plasmasimulation/fortran2018-examples", "max_forks_repo_head_hexsha": "0a7d336e0fc8508b2d6c0e30eff0c3325c57f735", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.9166666667, "max_line_length": 123, "alphanum_fraction": 0.7392405063, "num_tokens": 114, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8519527944504228, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6575742248623886}} {"text": "program allocate_01\nimplicit none\ninteger, allocatable :: a(:), b(:), c(:)\ninteger :: n, ierr\nn = 10\nallocate(a(n), b(n), c(n), stat=ierr)\n\na = 1\nb = 2\nc = 3\n\nprint *, whole_square(a, b, c)\n\ncontains\n\ninteger function whole_square(a, b, c) result(status)\nimplicit none\n\ninteger, allocatable :: a(:), b(:), c(:)\ninteger, allocatable :: a_2(:), b_2(:), c_2(:)\ninteger, allocatable :: ab(:), bc(:), ca(:), abc(:)\n\ninteger :: n\nn = size(a)\nallocate(a_2(n), b_2(n), c_2(n))\nallocate(ab(n), bc(n), ca(n), abc(n))\n\nstatus = 0\n\na_2 = a*a\nb_2 = b*b\nc_2 = c*c\nab = 2*a*b\nbc = 2*b*c\nca = 2*c*a\nabc = 2*a*b*c\n\nstatus = 1\n\nend function whole_square\n\nend\n", "meta": {"hexsha": "a39e3c936e6a9bff15d95b1642e4e016da38d83c", "size": 641, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "integration_tests/allocate_02.f90", "max_stars_repo_name": "Thirumalai-Shaktivel/lfortran", "max_stars_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 316, "max_stars_repo_stars_event_min_datetime": "2019-03-24T16:23:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:28:33.000Z", "max_issues_repo_path": "integration_tests/allocate_02.f90", "max_issues_repo_name": "Thirumalai-Shaktivel/lfortran", "max_issues_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-07-29T04:58:03.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-04T16:40:06.000Z", "max_forks_repo_path": "integration_tests/allocate_02.f90", "max_forks_repo_name": "Thirumalai-Shaktivel/lfortran", "max_forks_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2019-03-28T19:40:07.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T07:28:55.000Z", "avg_line_length": 14.9069767442, "max_line_length": 53, "alphanum_fraction": 0.5975039002, "num_tokens": 246, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424450764199, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.6575509494838333}} {"text": "SUBROUTINE beam_mm(mm,fs,ell)\n!\n! This subroutine forms the consistent mass matrix of a beam element.\n!\n IMPLICIT NONE\n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\n REAL(iwp),INTENT(IN)::fs,ell\n REAL(iwp),INTENT(OUT)::mm(:,:)\n REAL(iwp)::fac\n fac=(fs*ell)/420.0_iwp \n mm(1,1)=156.0_iwp*fac\n mm(3,3)=mm(1,1)\n mm(1,2)=22.0_iwp*ell*fac\n mm(2,1)=mm(1,2)\n mm(3,4)=-mm(1,2)\n mm(4,3)=mm(3,4)\n mm(1,3)=54.0_iwp*fac\n mm(3,1)=mm(1,3)\n mm(1,4)=-13.0_iwp*ell*fac\n mm(4,1)=mm(1,4)\n mm(2,3)=-mm(1,4)\n mm(3,2)=mm(2,3)\n mm(2,2)=4.0_iwp*(ell**2)*fac\n mm(4,4)=mm(2,2)\n mm(2,4)=-3.0_iwp*(ell**2)*fac\n mm(4,2)=mm(2,4)\nRETURN\nEND SUBROUTINE beam_mm \n", "meta": {"hexsha": "09b10fd6640a1cc4fa53739a2993817b8b4621ee", "size": 632, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "main/beam_mm.f90", "max_stars_repo_name": "cunyizju/Programming-FEM-5th-Fortran", "max_stars_repo_head_hexsha": "7740d381c0871c7e860aee8a19c467bd97a4cf45", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 20, "max_stars_repo_stars_event_min_datetime": "2019-12-22T11:44:55.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-09T12:19:06.000Z", "max_issues_repo_path": "main/beam_mm.f90", "max_issues_repo_name": "cunyizju/Programming-FEM-5th-Fortran", "max_issues_repo_head_hexsha": "7740d381c0871c7e860aee8a19c467bd97a4cf45", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-03-13T06:51:33.000Z", "max_issues_repo_issues_event_max_datetime": "2020-03-13T06:51:33.000Z", "max_forks_repo_path": "main/beam_mm.f90", "max_forks_repo_name": "cunyizju/Programming-FEM-5th-Fortran", "max_forks_repo_head_hexsha": "7740d381c0871c7e860aee8a19c467bd97a4cf45", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-06-03T12:47:06.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-30T13:35:28.000Z", "avg_line_length": 21.7931034483, "max_line_length": 69, "alphanum_fraction": 0.6297468354, "num_tokens": 317, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9585377272885904, "lm_q2_score": 0.6859494614282922, "lm_q1q2_score": 0.6575084377923078}} {"text": "subroutine forward_loop(L, N, KU, LB, Bj,Cj,Pj,Sj, NRHS, INFO, LU ,UD,UE, LL)\n Use lapackinterface\n IMPLICIT NONE \n! PURPOSE forward iterative loop\n! Copyright (c) 2021 Anthony M de Beus\n INTEGER, PARAMETER :: wp = KIND(0.0D0) ! working precision\n\n! .. Scalar Arguments ..\n Integer, Intent(IN) :: L, LB, LU, KU, N, NRHS ! L is starting place, LB=size(B,2)=size(C/P/J,3) \n ! LU+1=size(UD,3)=size(UE,2) index 0 arrays\n INTEGER, INTENT(OUT) :: INFO,LL ! LL is number of steps \n REAL(wp),INTENT(IN) :: Bj(2*KU,LB,NRHS) \n REAL(wp),INTENT(IN) :: Cj(2*KU,2*KU,LB)\n REAL(wp),INTENT(IN) :: Pj(2*KU,2*KU,LB)\n REAL(wp),INTENT(IN) :: Sj(2*KU,2*KU,LB) \n REAL(wp),INTENT(INOUT) :: UD(2*KU,2*KU,0:LU) ! ud is my set of matrices Aj \n REAL(wp),INTENT(INOUT) :: UE(2*KU,0:LU,NRHS) ! ue is my vectors vj \n \n! .. Work space ..\n REAL(wp) :: A(2*KU,2*KU),AA(2*KU,2*KU),CC(2*KU,NRHS),EE(2*KU,2*KU+NRHS) ! working copies\n INTEGER :: i,j,k,kk,hh,p,ii,jj,ipiv(2*KU)\n\n p=mod(N,2*KU)\n\n!! FORWARD \n ! ALL BUT THE LAST EQUATION, GENERATE UD & UE ! (Cj+Sj*A(:,:,j-1))*A(:,:,j)=-Pj\n jj=0 !index of number of arrays\n do j=L,(N-p)/2,KU \n jj=jj+1 \n call DGEMM('N','N',2*KU,2*KU,2*KU,1.0_wp,Sj(:,:,jj),2*KU,UD(:,:,jj-1),2*KU,0.0_wp,AA,2*KU)\n A=Cj(:,:,jj)+AA\n! A=Cj(:,:,jj)+matmul(Sj(:,:,jj),UD(:,:,jj-1)) \n! concatenate Aj and vj solutions onto EE \n EE(:,1:2*KU)=-Pj(:,:,jj)\n do hh=1,NRHS\n call DGEMV('N',2*KU,2*KU,1.0_wp,Sj(:,:,jj),2*KU,UE(:,jj-1,hh),1,0.0_wp,CC(:,hh),1) \n EE(:,2*KU+hh)=Bj(:,jj,hh)-CC(:,hh) \n! EE(:,2*KU+hh)=Bj(:,jj,hh)-matmul(Sj(:,:,jj),UE(:,jj-1,hh))\n end do\n! compute next UD,UE using factored A\n call DGESV(2*KU,2*KU+NRHS,A,2*KU,IPIV,EE,2*KU,INFO) ! overwrites EE into solution \n! call GaussJordan( 2*KU, 2*KU+NRHS ,A ,2*KU , EE, 2*KU, INFO ) ! overwrites EE into solution \n if (info /= 0) then\n CALL XERBLA( 'DGETRS/DCBSV ', INFO )\n! RETURN\n else\n UD(:,:,jj)=EE(:,1:2*KU)\n do hh=1,NRHS \n UE(:,jj,hh)=EE(:,2*KU+hh) \n end do \n endif \n end do\n LL=jj\n \n end subroutine forward_loop\n", "meta": {"hexsha": "c82e6cc815c76bb3763ad360da7f4245011e0a1d", "size": 2293, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "forward_loop.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": "forward_loop.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": "forward_loop.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": 40.9464285714, "max_line_length": 117, "alphanum_fraction": 0.5224596598, "num_tokens": 913, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009642742805, "lm_q2_score": 0.7185943925708561, "lm_q1q2_score": 0.6574427026851671}} {"text": " program main\n\nc*********************************************************************72\nc\ncc MAIN is the main program for F77_INTRINSICS_PRB.\nc\nc Discussion:\nc\nc F77_INTRINSICS_PRB tests FORTRAN77 intrinsic routines.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n call timestamp ( )\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'F77_INTRINSICS_PRB'\n write ( *, '(a)' ) ' FORTRAN77 version'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' Test FORTRAN77 intrinsic routines.'\n \n call test_abs\n call test_acos\n call test_aimag\n call test_aint\n call test_anint\n call test_asin\n call test_atan\n call test_atan2\n call test_btest\n call test_char\n call test_cmplx\n call test_conjg\n call test_cos_c4\n call test_cos_r8\n call test_cosh\n call test_dble\n call test_dim\n call test_dprod\n call test_exp\n call test_iand_i4\n call test_ibclr\n call test_ibits\n call test_ibset\n call test_ichar\n call test_ieor_i4\n call test_index\n call test_int\n call test_ior_i4\n call test_ishft\n call test_ishftc\n call test_len\n call test_len_trim\n call test_lge\n call test_lgt\n call test_lle\n call test_llt\n call test_log\n call test_log10\n call test_max\n call test_min\n call test_mod_i4\n call test_mod_r4\n call test_mvbits\n call test_nint\n call test_not_i4\n call test_real_c4\n call test_sign\n call test_sin_r8\n call test_sinh\n call test_sqrt\n call test_tan\n call test_tanh\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'F77_INTRINSICS_PRB'\n write ( *, '(a)' ) ' Normal end of execution.'\n\n write ( *, '(a)' ) ' '\n call timestamp ( )\n\n stop\n end\n subroutine test_abs\n\nc*********************************************************************72\nc\ncc TEST_ABS tests ABS.\nc\nc Discussion:\nc\nc The FORTRAN77 function ABS returns the absolute value of a \nc number. For complex numbers, this is the magnitude.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n complex c4\n integer i4\n real r4\n double precision r8\n\n c4 = ( 1.0E+00, -2.0E+00 )\n i4 = -88\n r4 = 45.78E+00\n r8 = 45.78D+00\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_ABS'\n write ( *, '(a)' ) ' ABS is a FORTRAN77 function which returns'\n write ( *, '(a)' ) ' the absolute value of a numeric quantity'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) \n & ' Type VALUE ABS(VALUE)'\n write ( *, '(a)' ) ' '\n write ( *, '(a,i12,12x,i12)' ) \n & ' integer ', i4, abs ( i4 )\n write ( *, '(a,f12.4,12x,f12.4)' ) \n & ' Real ', r4, abs ( r4 )\n write ( *, '(a,f12.4,12x,f12.4)' ) \n & ' Double precision ', r8, abs ( r8 )\n write ( *, '(a,2f12.4,f12.4)' ) \n & ' Complex ', c4, abs ( c4 )\n\n return\n end\n subroutine test_acos\n\nc*********************************************************************72\nc\ncc TEST_ACOS tests ACOS.\nc\nc Discussion:\nc\nc The FORTRAN77 function ACOS returns the inverse cosine of a number X.\nc assuming -1 <= X <= 1.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n integer i\n double precision r8_uniform\n integer seed\n double precision x\n double precision x_hi\n double precision x_lo\n double precision y\n double precision z\n\n seed = 123456789\n x_hi = 1.0D+00\n x_lo = -1.0D+00\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_ACOS'\n write ( *, '(a)' ) ' ACOS is a FORTRAN77 function which returns'\n write ( *, '(a)' ) \n & ' the inverse cosine of a value between -1 and 1'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) \n & ' X ACOS(X) COS(ACOS(X))'\n write ( *, '(a)' ) ' '\n do i = 1, 10\n x = r8_uniform ( x_lo, x_hi, seed )\n y = acos ( x )\n z = cos ( y )\n write ( *, '(2x,g14.6,2x,g14.6,2x,g14.6)' ) x, y, z\n end do\n\n return\n end\n subroutine test_aimag\n\nc*********************************************************************72\nc\ncc TEST_AIMAG tests AIMAG.\nc\nc Discussion:\nc\nc The FORTRAN77 function AIMAG returns the imaginary part of a\nc complex number.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n complex c4_uniform_01\n complex c\n integer i\n integer seed\n real r\n\n seed = 123456789\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_AIMAG'\n write ( *, '(a)' ) \n & ' AIMAG is a FORTRAN77 function which returns the'\n write ( *, '(a)' ) ' imaginary part of a complex number.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) \n & ' X AIMAG(X)'\n write ( *, '(a)' ) ' '\n do i = 1, 10\n c = c4_uniform_01 ( seed )\n r = aimag ( c )\n write ( *, '(2x,f14.6,f14.6,6x,f14.6,f14.6)' ) c, r\n end do\n\n return\n end\n subroutine test_aint\n\nc*********************************************************************72\nc\ncc TEST_AINT tests AINT.\nc\nc Discussion:\nc\nc The FORTRAN77 function AINT returns a real number rounded towards\nc zero.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n integer i\n double precision r8_uniform\n integer seed\n double precision x\n double precision x_hi\n double precision x_lo\n double precision y\n\n seed = 123456789\n x_lo = -10.0D+00\n x_hi = 10.0D+00\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_AINT'\n write ( *, '(a)' ) \n & ' AINT is a FORTRAN77 function which returns the'\n write ( *, '(a)' ) \n & ' value of a real number rounded towards zero.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' X AINT(X)'\n write ( *, '(a)' ) ' '\n do i = 1, 10\n x = r8_uniform ( x_lo, x_hi, seed )\n y = aint ( x )\n write ( *, '(2x,g14.6,2x,g14.6)' ) x, y\n end do\n\n return\n end\n subroutine test_anint\n\nc*********************************************************************72\nc\ncc TEST_ANINT tests ANINT.\nc\nc Discussion:\nc\nc The FORTRAN77 function ANINT returns, as a real value, the nearest \nc integer to a given real value.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n integer i\n double precision r8_uniform\n integer seed\n double precision x\n double precision x_hi\n double precision x_lo\n double precision y\n\n seed = 123456789\n x_lo = -10.0D+00\n x_hi = 10.0D+00\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_ANINT'\n write ( *, '(a)' ) \n & ' ANINT is a FORTRAN77 function which returns,'\n write ( *, '(a)' ) ' as a real value, the nearest integer to a '\n write ( *, '(a)' ) ' given real number.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' X ANINT(X)'\n write ( *, '(a)' ) ' '\n do i = 1, 10\n x = r8_uniform ( x_lo, x_hi, seed )\n y = anint ( x )\n write ( *, '(2x,g14.6,2x,g14.6)' ) x, y\n end do\n\n return\n end\n subroutine test_asin\n\nc*********************************************************************72\nc\ncc TEST_ASIN tests ASIN.\nc\nc Discussion:\nc\nc The FORTRAN77 function ASIN returns the inverse sine of a number X.\nc assuming -1 <= X <= 1.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n integer i\n double precision r8_uniform\n integer seed\n double precision x\n double precision x_hi\n double precision x_lo\n double precision y\n double precision z\n\n seed = 123456789\n x_lo = -1.0D+00\n x_hi = 1.0D+00\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_ASIN'\n write ( *, '(a)' ) \n & ' ASIN is a FORTRAN77 function which returns the'\n write ( *, '(a)' ) ' inverse sine of a value between -1 and 1'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) \n & ' X ASIN(X) SIN(ASIN(X))'\n write ( *, '(a)' ) ' '\n do i = 1, 10\n x = r8_uniform ( x_lo, x_hi, seed )\n y = asin ( x )\n z = sin ( y )\n write ( *, '(2x,g14.6,2x,g14.6,2x,g14.6)' ) x, y, z\n end do\n\n return\n end\n subroutine test_atan\n\nc*********************************************************************72\nc\ncc TEST_ATAN tests ATAN.\nc\nc Discussion:\nc\nc The FORTRAN77 function ATAN returns the inverse tangent of a number X.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n integer i\n double precision r8_uniform\n integer seed\n double precision x\n double precision x_hi\n double precision x_lo\n double precision y\n double precision z\n\n seed = 123456789\n x_lo = -10.0D+00\n x_hi = 10.0D+00\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_ATAN'\n write ( *, '(a)' ) \n & ' ATAN is a FORTRAN77 function which returns the'\n write ( *, '(a)' ) ' inverse tangent of a value'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) \n & ' X ATAN(X) TAN(ATAN(X))'\n write ( *, '(a)' ) ' '\n do i = 1, 10\n x = r8_uniform ( x_lo, x_hi, seed )\n y = atan ( x )\n z = tan ( y )\n write ( *, '(2x,g14.6,2x,g14.6,2x,g14.6)' ) x, y, z\n end do\n\n return\n end\n subroutine test_atan2\n\nc*********************************************************************72\nc\ncc TEST_ATAN2 tests ATAN2.\nc\nc Discussion:\nc\nc The FORTRAN77 function ATAN2 returns the inverse tangent of a number X.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n double precision r8_uniform\n integer i\n integer seed\n double precision w\n double precision x\n double precision x_hi\n double precision x_lo\n double precision y\n double precision z\n\n seed = 123456789\n x_lo = -10.0D+00\n x_hi = 10.0D+00\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_ATAN2'\n write ( *, '(a)' ) \n & ' ATAN2 is a FORTRAN77 function which returns the'\n write ( *, '(a)' ) ' inverse tangent of a value'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) \n & ' X Y ATAN2(Y,X) TAN(ATAN2(Y,X))'\n write ( *, '(a)' ) ' '\n do i = 1, 10\n x = r8_uniform ( x_lo, x_hi, seed )\n y = r8_uniform ( x_lo, x_hi, seed )\n z = atan2 ( y, x )\n w = tan ( z )\n write ( *, '(2x,g14.6,2x,g14.6,2x,g14.6,2x,g14.6)' ) x, y, z, w\n end do\n\n return\n end\n subroutine test_btest\n\nc*********************************************************************72\nc\ncc TEST_BTEST tests BTEST.\nc\nc Discussion:\nc\nc The FORTRAN77 function BTEST reports whether a given bit is 0 or 1\nc in an integer word.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n integer i1\n integer i2\n logical l\n integer pos\n integer pos_high\n character*32 s\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_BTEST'\n write ( *, '(a)' ) \n & ' BTEST(I,POS) is a FORTRAN77 function which is TRUE'\n write ( *, '(a)' ) ' if bit POS of I is 1.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) \n & ' Here, we are only going to check the lowest 32 bits.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' I POS BTEST(I,POS)'\n write ( *, '(a)' ) ' '\n\n i1 = 213456\n pos_high = min ( 32, bit_size(i1) )\n\n do pos = 0, pos_high - 1\n\n l = btest ( i1, pos )\n\n if ( l ) then\n s(pos_high-pos:pos_high-pos) = '1'\n else\n s(pos_high-pos:pos_high-pos) = '0'\n end if\n\n write ( *, '(2x,i8,2x,i8,10x,l1)' ) i1, pos, l\n\n end do\n\n write ( *, '(a)' ) ' '\n write ( *, '(a,i12,a)' ) \n & ' The binary representation of ', i1, ' is:'\n write ( *, '(a)' ) ' \"' // s //'\".' \n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' I POS BTEST(I,POS)'\n write ( *, '(a)' ) ' '\n\n i1 = -28\n\n do pos = 0, pos_high - 1\n\n l = btest ( i1, pos )\n\n if ( l ) then\n s(pos_high-pos:pos_high-pos) = '1'\n else\n s(pos_high-pos:pos_high-pos) = '0'\n end if\n\n write ( *, '(2x,i8,2x,i8,10x,l1)' ) i1, pos, l\n\n end do\n\n write ( *, '(a)' ) ' '\n write ( *, '(a,i12,a)' ) \n & ' The binary representation of ', i1, ' is:'\n write ( *, '(a)' ) ' \"' // s //'\".' \n\n return\n end\n subroutine test_char\n\nc*********************************************************************72\nc\ncc TEST_CHAR tests CHAR\nc\nc Discussion:\nc\nc The FORTRAN77 function CHAR returns the character corresponding\nc to the given character index, between 0 and 255.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n character c\n logical ch_is_printable\n integer i\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_CHAR'\n write ( *, '(a)' ) \n & ' CHAR is a FORTRAN77 function which returns the'\n write ( *, '(a)' ) ' character of given character index.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' I CHAR(I)'\n write ( *, '(a)' ) ' '\n\n do i = 0, 255\n\n c = char ( i )\n\n if ( ch_is_printable ( c ) ) then\n write ( *, '(2x,i8,8x,a1)' ) i, c\n end if\n\n end do\n\n return\n end\n subroutine test_cmplx\n\nc*********************************************************************72\nc\ncc TEST_CMPLX tests CMPLX.\nc\nc Discussion:\nc\nc The FORTRAN77 function CMPLX returns a complex number given its\nc real and imaginary parts.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_CMPLX'\n write ( *, '(a)' ) \n & ' CMPLX is a FORTRAN77 function which returns the'\n write ( *, '(a)' ) \n & ' complex number formed by real and imaginary parts.'\n write ( *, '(a)' ) ' '\n write ( *, '(a,f14.6,f14.6)' ) ' CMPLX(1) ', cmplx ( 1 )\n write ( *, '(a,f14.6,f14.6)' ) \n & ' CMPLX(2,3) ', cmplx ( 2, 3 )\n write ( *, '(a,f14.6,f14.6)' ) \n & ' CMPLX(4.5) ', cmplx ( 4.5 )\n write ( *, '(a,f14.6,f14.6)' ) \n & ' CMPLX(6.7, 8.9 )', cmplx ( 6.7, 8.9 )\n\n return\n end\n subroutine test_conjg\n\nc*********************************************************************72\nc\ncc TEST_CONJG tests CONJG.\nc\nc Discussion:\nc\nc The FORTRAN77 function CONJG returns the conjugate of a complex number.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n complex c4_uniform_01\n complex c1\n complex c2\n integer i\n integer seed\n\n seed = 123456789\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_CONJG'\n write ( *, '(a)' ) ' CONJG is a FORTRAN77 function which'\n write ( *, '(a)' ) ' returns the conjugate of a complex number.'\n write ( *, '(a)' ) ' '\n write ( *, '(a,a)' ) ' X ',\n & ' CONJG(X)'\n write ( *, '(a,a)' ) \n & ' -------------------------- ',\n & '----------------------------'\n write ( *, '(a)' ) ' '\n do i = 1, 10\n c1 = c4_uniform_01 ( seed )\n c2 = conjg ( c1 )\n write ( *, '(2x,f14.6,f14.6,6x,f14.6,f14.6)' ) c1, c2\n end do\n\n return\n end\n subroutine test_cos_c4\n\nc*********************************************************************72\nc\ncc TEST_COS_C4 tests COS on complex arguments.\nc\nc Discussion:\nc\nc The FORTRAN77 function COS returns the cosine of a real or complex number.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n complex c4_uniform_01\n integer i\n integer seed\n complex x_c4\n complex y_c4\n\n seed = 123456789\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_COS_C4'\n write ( *, '(a)' ) ' COS is a FORTRAN77 function which returns'\n write ( *, '(a)' ) ' the cosine of a real or complex number.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' Here we use complex arguments.'\n write ( *, '(a)' ) ' '\n write ( *, '(a,a)' ) ' X',\n & ' COS(X)'\n write ( *, '(a,a)' ) \n & ' -------------------------- ', \n & '----------------------------'\n write ( *, '(a)' ) ' '\n do i = 1, 10\n x_c4 = c4_uniform_01 ( seed )\n y_c4 = cos ( x_c4 )\n write ( *, '(2x,2g14.6,2x,2g14.6)' ) x_c4, y_c4\n end do\n\n return\n end\n subroutine test_cos_r8\n\nc*********************************************************************72\nc\ncc TEST_COS_R8 tests COS on double precision arguments.\nc\nc Discussion:\nc\nc The FORTRAN77 function COS returns the cosine of a real or complex number.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n double precision r8_uniform\n integer i\n integer seed\n double precision x\n double precision x_hi\n double precision x_lo\n double precision y\n\n seed = 123456789\n x_lo = -10.0D+00\n x_hi = 10.0D+00\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_COS_R8'\n write ( *, '(a)' ) ' COS is a FORTRAN77 function which returns'\n write ( *, '(a)' ) ' the cosine of a real or complex number.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' Here we use double precision arguments.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' X COS(X)'\n write ( *, '(a)' ) ' '\n do i = 1, 10\n x = r8_uniform ( x_lo, x_hi, seed )\n y = cos ( x )\n write ( *, '(2x,g14.6,2x,g14.6)' ) x, y\n end do\n\n return\n end\n subroutine test_cosh\n\nc*********************************************************************72\nc\ncc TEST_COSH tests COSH.\nc\nc Discussion:\nc\nc The FORTRAN77 function COSH returns the hyperbolic cosine of a real number.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n double precision r8_uniform\n integer i\n integer seed\n double precision x\n double precision x_hi\n double precision x_lo\n double precision y\n\n seed = 123456789\n x_lo = -10.0D+00\n x_hi = 10.0D+00\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_COSH'\n write ( *, '(a)' ) ' COSH is a FORTRAN77 function which returns'\n write ( *, '(a)' ) ' the hyperbolic cosine of a real number.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' X COSH(X)'\n write ( *, '(a)' ) ' '\n do i = 1, 10\n x = r8_uniform ( x_lo, x_hi, seed )\n y = cosh ( x )\n write ( *, '(2x,g14.6,2x,g14.6)' ) x, y\n end do\n\n return\n end\n subroutine test_dble\n\nc*********************************************************************72\nc\ncc TEST_DBLE tests DBLE.\nc\nc Discussion:\nc\nc The FORTRAN77 function DBLE converts a numeric value to double precision.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n complex x_c4\n integer x_i4\n real x_r4\n double precision x_r8\n\n x_c4 = ( 1.1E+00, 2.2E+00 )\n x_i4 = 5\n x_r4 = 7.7E+00\n x_r8 = 8.8D+00\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_DBLE'\n write ( *, '(a)' ) ' DBLE is a FORTRAN77 function which converts'\n write ( *, '(a)' ) \n & ' a complex, integer or real value to double precision'\n write ( *, '(a)' ) ' real'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) \n & ' Type X DBLE(X)'\n write ( *, '(a)' ) ' '\n write ( *, '(a,f6.4,2x,f6.4,2x,f6.4)' ) ' complex ',\n & x_c4, dble ( x_c4 )\n write ( *, '(a,i6,10x,f6.4)' ) ' integer ', \n & x_i4, dble ( x_i4 )\n write ( *, '(a,f6.4,10x,f6.4)' ) ' real ', \n & x_r4, dble ( x_r4 )\n write ( *, '(a,f6.4,10x,f6.4)' ) ' double precision ', \n & x_r8, dble ( x_r8 )\n\n return\n end\n subroutine test_dim\n\nc*********************************************************************72\nc\ncc TEST_DIM tests DIM\nc\nc Discussion:\nc\nc The FORTRAN77 function DIM(X,Y) returns the maximum of (X-Y) and 0.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n integer i4_uniform\n real r\n integer seed\n integer test\n integer test_num\n parameter ( test_num = 5 )\n integer x\n integer y\n integer z\n\n seed = 123456789\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_DIM'\n write ( *, '(a)' ) ' DIM is a FORTRAN77 function which returns'\n write ( *, '(a)' ) ' the maximum of X-Y or 0.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' Arithmetic type: integer X, Y'\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' X Y DIM(X,Y)'\n write ( *, '(a)' ) ' '\n\n do test = 1, test_num\n\n x = i4_uniform ( 0, 100, seed )\n y = i4_uniform ( 0, 100, seed )\n\n z = dim ( x, y )\n\n write ( *, '(2x,i6,2x,i6,2x,i6)' ) x, y, z\n\n end do\n\n return\n end\n subroutine test_dprod\n\nc*********************************************************************72\nc\ncc TEST_DPROD tests DPROD\nc\nc Discussion:\nc\nc The FORTRAN77 function DPROD(X,Y) returns the product of real\nc numbers X and Y using double precision.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n integer i\n real r4_uniform_01\n integer seed\n real x_r4\n real y_r4\n\n seed = 123456789\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_DPROD'\n write ( *, '(a)' ) ' DPROD is a FORTRAN77 function which'\n write ( *, '(a)' ) ' returns the product of real values X and Y,'\n write ( *, '(a)' ) ' using double precision.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' real x, y'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' X Y DPROD(X,Y)'\n write ( *, '(a)' ) ' '\n do i = 1, 5\n x_r4 = 100.0E+00 * r4_uniform_01 ( seed )\n y_r4 = 100.0E+00 * r4_uniform_01 ( seed )\n write ( *, '(2x,f12.6,2x,f12.6,2x,f12.6)' ) \n & x_r4, y_r4, dprod ( x_r4, y_r4 )\n end do\n\n return\n end\n subroutine test_exp\n\nc*********************************************************************72\nc\ncc TEST_EXP tests EXP.\nc\nc Discussion:\nc\nc The FORTRAN77 function EXP returns the exponential of a real number.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n double precision r8_uniform\n integer i\n integer seed\n double precision x\n double precision x_hi\n double precision x_lo\n double precision y\n\n seed = 123456789\n x_lo = -10.0D+00\n x_hi = 10.0D+00\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_EXP'\n write ( *, '(a)' ) \n & ' EXP is a FORTRAN77 function which returns the'\n write ( *, '(a)' ) ' exponential of a real number.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' X EXP(X)'\n write ( *, '(a)' ) ' '\n do i = 1, 10\n x = r8_uniform ( x_lo, x_hi, seed )\n y = exp ( x )\n write ( *, '(2x,g14.6,2x,g14.6)' ) x, y\n end do\n\n return\n end\n subroutine test_iand_i4\n\nc*********************************************************************72\nc\ncc TEST_IAND_I4 tests IAND on integer arguments.\nc\nc Discussion:\nc\nc The FORTRAN77 function IAND returns the bitwise AND \nc of two integers.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n integer i\n integer i4_uniform\n integer j\n integer k\n integer seed\n integer test\n\n seed = 123456789\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_IAND_I4'\n write ( *, '(a)' ) \n & ' IAND is a FORTRAN77 function which returns the'\n write ( *, '(a)' ) ' bitwise AND of two integers.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' Here, I and J are integers.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' I J IAND(I,J)'\n write ( *, '(a)' ) ' '\n\n do test = 1, 10\n i = i4_uniform ( 0, 100, seed )\n j = i4_uniform ( 0, 100, seed )\n k = iand ( i, j )\n write ( *, '(2x,i8,2x,i8,2x,i8)' ) i, j, k\n end do\n\n return\n end\n subroutine test_ibclr\n\nc*********************************************************************72\nc\ncc TEST_IBCLR tests IBCLR.\nc\nc Discussion:\nc\nc The FORTRAN77 function IBCLR sets a given bit to zero in an integer word.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n integer i1\n integer i2\n integer pos\nc\nc Put 11 consecutive 1's into I1.\nc\n i1 = 0\n do pos = 0, 10\n i1 = 2 * i1 + 1\n end do\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_IBCLR'\n write ( *, '(a)' ) \n & ' IBCLR is a FORTRAN77 function which sets a given'\n write ( *, '(a)' ) ' bit to zero in an integer word.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' I POS IBCLR(I,POS)'\n write ( *, '(a)' ) ' '\n do pos = 0, 10\n i2 = ibclr ( i1, pos )\n write ( *, '(2x,i8,2x,i8,2x,i8)' ) i1, pos, i2\n end do\n\n return\n end\n subroutine test_ibits\n\nc*********************************************************************72\nc\ncc TEST_IBITS tests IBITS.\nc\nc Discussion:\nc\nc The FORTRAN77 function IBITS extracts a sequence of bits from\nc an integer word.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n integer byte\n integer i\n integer i1\n integer i2\n integer i4\n integer len\n integer pos\n\n i1 = 1396\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_IBITS'\n write ( *, '(a)' ) \n & ' IBITS is a FORTRAN77 function which extracts'\n write ( *, '(a)' ) ' LEN bits from word I start at position POS.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) \n & ' I POS LEN IBITS(I,POS,LEN)'\n write ( *, '(a)' ) ' '\n len = 3\n do pos = 0, 10\n i2 = ibits ( i1, pos, len )\n write ( *, '(2x,i8,2x,i8,2x,i8,2x,i8)' ) i1, pos, len, i2\n end do\n\n write ( *, '(a)' ) ' '\n\n pos = 2\n do len = 1, 10\n i2 = ibits ( i1, pos, len )\n write ( *, '(2x,i8,2x,i8,2x,i8,2x,i8)' ) i1, pos, len, i2\n end do\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) \n & ' Use IBITS to extract the 4 bytes that make up'\n write ( *, '(a)' ) ' an integer word.'\n write ( *, '(a)' ) ' '\nc\nc 3: 00111110 = 62\nc\nc 2: 00000100 = 4\nc\nc 1: 11010010 = 210\nc\nc 0: 00001111 = 15\nc\n i4 = 2**29 + 2**28 + 2**27 + 2**26 + 2**25 \n & + 2**18 \n & + 2**15 + 2**14 + 2**12 + 2**9 \n & + 2**3 + 2**2 + 2**1 + 2**0 \n\n write ( *, '(a,i12)' ) ' I4 = ', i4\n write ( *, '(a)' ) ' '\n len = 8\n do i = 0, 3\n pos = i * len\n byte = ibits ( i4, pos, len )\n write ( *, '(a,i8,a,i8)' ) ' Byte ', i, ' = ', byte\n end do\n\n return\n end\n subroutine test_ibset\n\nc*********************************************************************72\nc\ncc TEST_IBSET tests IBSET.\nc\nc Discussion:\nc\nc The FORTRAN77 function IBSET sets a given bit to one in an integer word.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n integer i1\n integer i2\n integer pos\n\n i1 = 0\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_IBSET'\n write ( *, '(a)' ) \n & ' IBSET is a FORTRAN77 function which sets a given'\n write ( *, '(a)' ) ' bit to one in an integer word.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' I POS IBSET(I,POS)'\n write ( *, '(a)' ) ' '\n do pos = 0, 10\n i2 = ibset ( i1, pos )\n write ( *, '(2x,i8,2x,i8,2x,i8)' ) i1, pos, i2\n i1 = i2\n end do\n\n return\n end\n subroutine test_ichar\n\nc*********************************************************************72\nc\ncc TEST_ICHAR tests ICHAR\nc\nc Discussion:\nc\nc The FORTRAN77 function ICHAR returns the character index (between 0 \nc and 255) of a character.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n character c1\n character c2\n integer i\n integer i1\n character*25 string\n\n string = 'This is a string of text!'\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_ICHAR'\n write ( *, '(a)' ) \n & ' ICHAR is a FORTRAN77 function which returns the'\n write ( *, '(a)' ) ' character index of a given character'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' C ICHAR(C) CHAR(ICHAR(C))'\n write ( *, '(a)' ) ' '\n\n do i = 1, len ( string )\n\n c1 = string (i:i)\n\n i1 = ichar ( c1 )\n\n c2 = char ( i1 )\n\n write ( *, '(2x,a1,8x,i8,8x,a1)' ) c1, i1, c2\n\n end do\n\n return\n end\n subroutine test_ieor_i4\n\nc*********************************************************************72\nc\ncc TEST_IEOR_I4 tests IEOR on integer arguments.\nc\nc Discussion:\nc\nc The FORTRAN77 function IEOR returns the bitwise exclusive OR \nc of two integers.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n integer i\n integer i4_uniform\n integer j\n integer k\n real r\n integer seed\n integer test\n\n seed = 123456789\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_IEOR_I4'\n write ( *, '(a)' ) ' IEOR is a FORTRAN77 function which returns'\n write ( *, '(a)' ) ' the bitwise exclusive OR of two integers.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' Here, I and J are integers.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' I J IEOR(I,J)'\n write ( *, '(a)' ) ' '\n\n do test = 1, 10\n i = i4_uniform ( 0, 100, seed )\n j = i4_uniform ( 0, 100, seed )\n k = ieor ( i, j )\n write ( *, '(2x,i8,2x,i8,2x,i8)' ) i, j, k\n end do\n\n return\n end\n subroutine test_index\n\nc*********************************************************************72\nc\ncc TEST_INDEX tests INDEX.\nc\nc Discussion:\nc\nc The FORTRAN77 function INDEX determines the first occurrence\nc of a substring in a string.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_INDEX'\n write ( *, '(a)' ) ' INDEX(S,SUB) is a FORTRAN77 function which'\n write ( *, '(a)' ) \n & ' returns the location of the first occurrence'\n write ( *, '(a)' ) ' of substring SUB in string S.'\n write ( *, '(a)' ) ' '\n write ( *, '(a,i8)' ) \n & ' index ( ''THE CATATONIC CAT'', ''CAT'' )', \n & index ( 'THE CATATONIC CAT', 'CAT' )\n write ( *, '(a,i8)' ) \n & ' index ( ''THE CATATONIC CAT'', ''cat'' )', \n & index ( 'THE CATATONIC CAT', 'cat' )\n\n return\n end\n subroutine test_int\n\nc*********************************************************************72\nc\ncc TEST_INT tests INT.\nc\nc Discussion:\nc\nc The FORTRAN77 function INT converts a numeric value to an integer.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n complex x_c4\n integer x_i4\n real x_r4\n double precision x_r8\n\n x_c4 = ( 1.1E+00, 2.2E+00 )\n x_i4 = 5\n x_r4 = 7.7E+00\n x_r8 = 8.8D+00\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_INT'\n write ( *, '(a)' ) ' INT is a FORTRAN77 function which converts'\n write ( *, '(a)' ) \n & ' a complex, integer or real value to integer.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' Type X INT(X)'\n write ( *, '(a)' ) ' '\n write ( *, '(a,f6.4,2x,f6.4,2x,i6)' ) ' complex ', \n & x_c4, int ( x_c4 )\n write ( *, '(a,i6,10x,i6)' ) ' integer ', \n & x_i4, int ( x_i4 )\n write ( *, '(a,f6.4,10x,i6)' ) ' real ', \n & x_r4, int ( x_r4 )\n write ( *, '(a,f6.4,10x,i6)' ) ' double precision ', \n & x_r8, int ( x_r8 )\n\n return\n end\n subroutine test_ior_i4\n\nc*********************************************************************72\nc\ncc TEST_IOR_I4 tests IOR on integer arguments.\nc\nc Discussion:\nc\nc The FORTRAN77 function IOR returns the bitwise inclusive OR \nc of two integers.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n integer i\n integer i4_uniform\n integer j\n integer k\n integer seed\n integer test\n\n seed = 123456789\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_IOR_I4'\n write ( *, '(a)' ) ' IOR is a FORTRAN77 function which returns'\n write ( *, '(a)' ) ' the bitwise inclusive OR of two integers.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' Here, I and J are integers.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' I J IOR(I,J)'\n write ( *, '(a)' ) ' '\n\n do test = 1, 10\n i = i4_uniform ( 0, 100, seed )\n j = i4_uniform ( 0, 100, seed )\n k = ior ( i, j )\n write ( *, '(2x,i8,2x,i8,2x,i8)' ) i, j, k\n end do\n\n return\n end\n subroutine test_ishft\n\nc*********************************************************************72\nc\ncc TEST_ISHFT tests ISHFT.\nc\nc Discussion:\nc\nc The FORTRAN77 function ISHFT shifts the bits in an integer word.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n integer i1\n integer i2\n integer shift\n\n i1 = 89\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_ISHFT'\n write ( *, '(a)' ) ' ISHFT is a FORTRAN77 function which shifts'\n write ( *, '(a)' ) ' the bits in an integer word.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' I SHIFT ISHFT(I,SHIFT)'\n write ( *, '(a)' ) ' '\n do shift = -5, 5\n i2 = ishft ( i1, shift )\n write ( *, '(2x,i8,2x,i8,2x,i8)' ) i1, shift, i2\n end do\n\n return\n end\n subroutine test_ishftc\n\nc*********************************************************************72\nc\ncc TEST_ISHFTC tests ISHFTC.\nc\nc Discussion:\nc\nc The FORTRAN77 function ISHFTC circular-shifts the bits in an integer word.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n integer i1\n integer i2\n integer shift\n integer size\n\n i1 = 89\n size = 32\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_ISHFTC'\n write ( *, '(a)' ) ' ISHFTC is a FORTRAN77 function which'\n write ( *, '(a)' ) \n & ' circular-shifts the bits in an integer word.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) \n & ' I SHIFT ISHFTC(I,SHIFT,SIZE)'\n write ( *, '(a)' ) ' '\n do shift = -5, 5\n i2 = ishftc ( i1, shift, size )\n write ( *, '(2x,i8,2x,i8,2x,i12)' ) i1, shift, i2\n end do\n\n return\n end\n subroutine test_len\n\nc*********************************************************************72\nc\ncc TEST_LEN tests LEN.\nc\nc Discussion:\nc\nc The FORTRAN77 function LEN returns the declared length of a\nc character string.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n character*1 s1\n character*2 s2\n character*4 s4\n character*8 s8\n character*16 s16\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_LEN'\n write ( *, '(a)' ) \n & ' LEN is a FORTRAN77 function which returns the'\n write ( *, '(a)' ) \n & ' declared length of a string variable, or the length of'\n write ( *, '(a)' ) ' a string constant'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' S LEN(S)'\n write ( *, '(a)' ) ' ---------- -----'\n write ( *, '(a)' ) ' '\n write ( *, '(a,i8)' ) ' character*1 ', len ( s1 )\n write ( *, '(a,i8)' ) ' character*2 ', len ( s2 )\n write ( *, '(a,i8)' ) ' character*4 ', len ( s4 )\n write ( *, '(a,i8)' ) ' character*8 ', len ( s8 )\n write ( *, '(a,i8)' ) ' character*16 ', len ( s16 )\n write ( *, '(a,i8)' ) \n & ' \"A STRING\" ', len ( 'A STRING' )\n\n return\n end\n subroutine test_len_trim\n\nc*********************************************************************72\nc\ncc TEST_LEN_TRIM tests LEN_TRIM.\nc\nc Discussion:\nc\nc The FORTRAN77 function LEN_TRIM returns the \"used\" length of a\nc character string, up to the last non_blank.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n character*10 s\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_LEN_TRIM'\n write ( *, '(a)' ) \n & ' LEN_TRIM is a FORTRAN77 function which returns the'\n write ( *, '(a)' ) \n & ' \"used\" length of a string variable up to the last'\n write ( *, '(a)' ) ' nonblank.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' S LEN_TRIM(S)'\n write ( *, '(a)' ) ' ---------- ----------'\n write ( *, '(a)' ) ' '\n s = '1234567890'\n write ( *, '(a,i8)' ) ' \"' // s // '\"', len_trim(s)\n s = '12345 '\n write ( *, '(a,i8)' ) ' \"' // s // '\"', len_trim(s)\n s = ' 67890'\n write ( *, '(a,i8)' ) ' \"' // s // '\"', len_trim(s)\n s = ' 5 '\n write ( *, '(a,i8)' ) ' \"' // s // '\"', len_trim(s)\n s = '1 3 5 7 9 '\n write ( *, '(a,i8)' ) ' \"' // s // '\"', len_trim(s)\n\n return\n end\n subroutine test_lge\n\nc*********************************************************************72\nc\ncc TEST_LGE tests LGE.\nc\nc Discussion:\nc\nc The FORTRAN77 function LGE(S1,S2) returns the value of\nc \"string S1 is lexically greater than or equal to string S2\".\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n character*3 s4\n character*3 s5\n character*4 s6\n character*3 s7\n character*3 s8\n\n s4 = 'boy' \n s5 = 'cat'\n s6 = 'cats'\n s7 = 'dog'\n s8 = 'CAT'\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_LGE'\n write ( *, '(a)' ) \n & ' LGE is a FORTRAN77 function which returns the value'\n write ( *, '(a)' ) ' of \"S1 >= S2\" where S1 and S2 are strings.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' S1 S2 LGE(S1,S2)'\n write ( *, '(a)' ) ' --- --- ----------'\n write ( *, '(a)' ) ' '\n write ( *, '(a,8x,l1)' ) \n & ' \"' // s4 // '\" \"' // s4 // '\" ', lge ( s4, s4 )\n write ( *, '(a,8x,l1)' ) \n & ' \"' // s4 // '\" \"' // s5 // '\" ', lge ( s4, s5 )\n write ( *, '(a,8x,l1)' ) \n & ' \"' // s5 // '\" \"' // s4 // '\" ', lge ( s5, s4 )\n write ( *, '(a,8x,l1)' ) \n & ' \"' // s5 // '\" \"' // s7 // '\" ', lge ( s5, s7 )\n write ( *, '(a,8x,l1)' ) \n & ' \"' // s5 // '\" \"' // s8 // '\" ', lge ( s5, s8 )\n write ( *, '(a,8x,l1)' ) \n & ' \"' // s5 // '\" \"' // s6 // '\" ', lge ( s5, s6 )\n\n return\n end\n subroutine test_lgt\n\nc*********************************************************************72\nc\ncc TEST_LGT tests LGT.\nc\nc Discussion:\nc\nc The FORTRAN77 function LGT(S1,S2) returns the value of\nc \"string S1 is lexically greater than string S2\".\nc\nc Modified:\nc\nc 05 July 2006\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n character*3 s4\n character*3 s5\n character*4 s6\n character*3 s7\n character*3 s8\n\n s4 = 'boy' \n s5 = 'cat'\n s6 = 'cats'\n s7 = 'dog'\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_LGT'\n write ( *, '(a)' ) \n & ' LGT is a FORTRAN77 function which returns the value'\n write ( *, '(a)' ) ' of \"S1 > S2\" where S1 and S2 are strings.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' S1 S2 LGT(S1,S2)'\n write ( *, '(a)' ) ' --- --- ----------'\n write ( *, '(a)' ) ' '\n write ( *, '(a,8x,l1)' ) \n & ' \"' // s4 // '\" \"' // s4 // '\" ', lgt ( s4, s4 )\n write ( *, '(a,8x,l1)' ) \n & ' \"' // s4 // '\" \"' // s5 // '\" ', lgt ( s4, s5 )\n write ( *, '(a,8x,l1)' ) \n & ' \"' // s5 // '\" \"' // s4 // '\" ', lgt ( s5, s4 )\n write ( *, '(a,8x,l1)' ) \n & ' \"' // s5 // '\" \"' // s7 // '\" ', lgt ( s5, s7 )\n write ( *, '(a,8x,l1)' ) \n & ' \"' // s5 // '\" \"' // s8 // '\" ', lgt ( s5, s8 )\n write ( *, '(a,8x,l1)' ) \n & ' \"' // s5 // '\" \"' // s6 // '\" ', lgt ( s5, s6 )\n\n return\n end\n subroutine test_lle\n\nc*********************************************************************72\nc\ncc TEST_LLE tests LLE.\nc\nc Discussion:\nc\nc The FORTRAN77 function LLE(S1,S2) returns the value of\nc \"string S1 is lexically less than or equal to string S2\".\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n character*3 s4\n character*3 s5\n character*4 s6\n character*3 s7\n character*3 s8\n\n s4 = 'boy' \n s5 = 'cat'\n s6 = 'cats'\n s7 = 'dog'\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_LLE'\n write ( *, '(a)' ) \n & ' LLE is a FORTRAN77 function which returns the value'\n write ( *, '(a)' ) ' of \"S1 <= S2\" where S1 and S2 are strings.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' S1 S2 LLE(S1,S2)'\n write ( *, '(a)' ) ' --- --- ----------'\n write ( *, '(a)' ) ' '\n write ( *, '(a,8x,l1)' ) \n & ' \"' // s4 // '\" \"' // s4 // '\" ', lle ( s4, s4 )\n write ( *, '(a,8x,l1)' ) \n & ' \"' // s4 // '\" \"' // s5 // '\" ', lle ( s4, s5 )\n write ( *, '(a,8x,l1)' ) \n & ' \"' // s5 // '\" \"' // s4 // '\" ', lle ( s5, s4 )\n write ( *, '(a,8x,l1)' ) \n & ' \"' // s5 // '\" \"' // s7 // '\" ', lle ( s5, s7 )\n write ( *, '(a,8x,l1)' ) \n & ' \"' // s5 // '\" \"' // s8 // '\" ', lle ( s5, s8 )\n write ( *, '(a,8x,l1)' ) \n & ' \"' // s5 // '\" \"' // s6 // '\" ', lle ( s5, s6 )\n\n return\n end\n subroutine test_llt\n\nc*********************************************************************72\nc\ncc TEST_LLT tests LLT.\nc\nc Discussion:\nc\nc The FORTRAN77 function LLT(S1,S2) returns the value of\nc \"string S1 is lexically less than string S2\".\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n character*3 s4\n character*3 s5\n character*4 s6\n character*3 s7\n character*3 s8\n\n s4 = 'boy' \n s5 = 'cat'\n s6 = 'cats'\n s7 = 'dog'\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_LGT'\n write ( *, '(a)' ) \n & ' LLT is a FORTRAN77 function which returns the'\n write ( *, '(a)' ) \n & ' value of \"S1 < S2\" where S1 and S2 are strings.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' S1 S2 LLT(S1,S2)'\n write ( *, '(a)' ) ' --- --- ----------'\n write ( *, '(a)' ) ' '\n write ( *, '(a,8x,l1)' ) \n & ' \"' // s4 // '\" \"' // s4 // '\" ', llt ( s4, s4 )\n write ( *, '(a,8x,l1)' ) \n & ' \"' // s4 // '\" \"' // s5 // '\" ', llt ( s4, s5 )\n write ( *, '(a,8x,l1)' ) \n & ' \"' // s5 // '\" \"' // s4 // '\" ', llt ( s5, s4 )\n write ( *, '(a,8x,l1)' ) \n & ' \"' // s5 // '\" \"' // s7 // '\" ', llt ( s5, s7 )\n write ( *, '(a,8x,l1)' ) \n & ' \"' // s5 // '\" \"' // s8 // '\" ', llt ( s5, s8 )\n write ( *, '(a,8x,l1)' ) \n & ' \"' // s5 // '\" \"' // s6 // '\" ', llt ( s5, s6 )\n\n return\n end\n subroutine test_log\n\nc*********************************************************************72\nc\ncc TEST_LOG tests LOG.\nc\nc Discussion:\nc\nc The FORTRAN77 function LOG returns the natural logarithm of a real number.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n double precision r8_uniform\n integer i\n integer seed\n double precision x\n double precision x_hi\n double precision x_lo\n double precision y\n double precision z\n\n seed = 123456789\n x_lo = 0.0D+00\n x_hi = 10.0D+00\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_LOG'\n write ( *, '(a)' ) ' LOG is a FORTRAN77 function which returns'\n write ( *, '(a)' ) ' the natural logarithm of a real number.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' X LOG(X) EXP(LOG(X))'\n write ( *, '(a)' ) ' '\n do i = 1, 10\n x = r8_uniform ( x_lo, x_hi, seed )\n y = log ( x )\n z = exp ( y )\n write ( *, '(2x,g14.6,2x,g14.6,2x,g14.6)' ) x, y, z\n end do\n\n return\n end\n subroutine test_log10\n\nc*********************************************************************72\nc\ncc TEST_LOG10 tests LOG10.\nc\nc Discussion:\nc\nc The FORTRAN77 function LOG10 returns the base 10 logarithm of a \nc real number.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n double precision r8_uniform\n integer i\n integer seed\n double precision x\n double precision x_hi\n double precision x_lo\n double precision y\n double precision z\n\n seed = 123456789\n x_lo = 0.0D+00\n x_hi = 10.0D+00\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_LOG10'\n write ( *, '(a)' ) ' LOG10 is a FORTRAN77 function which'\n write ( *, '(a)' ) ' returns the base 10 logarithm '\n write ( *, '(a)' ) ' of a real number.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) \n & ' X LOG10(X) 10**(LOG(X))'\n write ( *, '(a)' ) ' '\n do i = 1, 10\n x = r8_uniform ( x_lo, x_hi, seed )\n y = log10 ( x )\n z = 10.0D+00**y\n write ( *, '(2x,g14.6,2x,g14.6,2x,g14.6)' ) x, y, z\n end do\n\n return\n end\n subroutine test_max\n\nc*********************************************************************72\nc\ncc TEST_MAX tests MAX.\nc\nc Discussion:\nc\nc The FORTRAN77 function MAX returns the maximum value in a list.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_MAX'\n write ( *, '(a)' ) ' MAX is a FORTRAN77 function which returns'\n write ( *, '(a)' ) ' the maximum value in a list.'\n write ( *, '(a)' ) ' '\n write ( *, '(a,i8)' ) ' max(2,1) = ', max ( 2, 1 )\n write ( *, '(a,i8)' ) ' max(1,3,2) = ', max ( 1, 3, 2 )\n write ( *, '(a,i8)' ) ' max(3,2,4,1) = ', max ( 3, 2, 4, 1 )\n write ( *, '(a)' ) ' '\n write ( *, '(a,f4.1)' ) \n & ' max(2.1, 1.2) = ', max ( 2.1, 1.2 )\n write ( *, '(a,f4.1)' ) \n & ' max(1.1, 3.2, 2.3) = ', max ( 1.1, 3.2, 2.3 )\n write ( *, '(a,f4.1)' ) \n & ' max(3.1, 2.2, 4.3, 1.4) = ', max ( 3.1, 2.2, 4.3, 1.4 )\n\n return\n end\n subroutine test_min\n\nc*********************************************************************72\nc\ncc TEST_MIN tests MIN.\nc\nc Discussion:\nc\nc The FORTRAN77 function MIN returns the minimum value in a list.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_MIN'\n write ( *, '(a)' ) ' MIN is a FORTRAN77 function which returns'\n write ( *, '(a)' ) ' the minimum value in a list.'\n write ( *, '(a)' ) ' '\n write ( *, '(a,i8)' ) ' min(3, 4) = ', min ( 3, 4 )\n write ( *, '(a,i8)' ) ' min(4, 2, 3) = ', min ( 4, 2, 3 )\n write ( *, '(a,i8)' ) ' min(2, 3, 1, 4) = ', min ( 2, 3, 1, 4 )\n\n write ( *, '(a)' ) ' '\n write ( *, '(a,f4.1)' ) \n & ' min(3.1, 4.2) = ', min ( 3.1, 4.2 )\n write ( *, '(a,f4.1)' ) \n & ' min(4.1. 2.2, 3.3) = ', min ( 4.1, 2.2, 3.3 )\n write ( *, '(a,f4.1)' ) \n & ' min(2.1, 3.2, 1.3, 4.4) = ', min ( 2.1, 3.2, 1.3, 4.4 )\n\n return\n end\n subroutine test_mod_i4\n\nc*********************************************************************72\nc\ncc TEST_MOD_I4 tests MOD on integers.\nc\nc Discussion:\nc\nc The FORTRAN77 function MOD(A,B) returns the remainder after division.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n integer i\n integer i_hi\n integer i_lo\n integer i4_uniform\n integer j\n integer k\n integer seed\n integer test\n\n seed = 123456789\n i_lo = -10\n i_hi = 20\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_MOD_I4'\n write ( *, '(a)' ) ' MOD is a FORTRAN77 function which returns'\n write ( *, '(a)' ) ' the remainder after division.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' Here, the arguments are integers.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' I J MOD(I,J)'\n write ( *, '(a)' ) ' '\n do test = 1, 10\n\n i = i4_uniform ( i_lo, i_hi, seed )\n j = i4_uniform ( i_lo, i_hi, seed )\n\n if ( j == 0 ) then\n write ( *, '(2x,i8,2x,i8,2x,a)' ) i, j, 'Undefined'\n else\n k = mod ( i, j )\n write ( *, '(2x,i8,2x,i8,2x,i8)' ) i, j, k\n end if\n\n end do\n\n return\n end\n subroutine test_mod_r4\n\nc*********************************************************************72\nc\ncc TEST_MOD_R4 tests MOD on reals.\nc\nc Discussion:\nc\nc The FORTRAN77 function MOD(A,B) returns the remainder after division.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n real r4_uniform\n integer seed\n integer test\n real x\n real x_hi\n real x_lo\n real y\n real z\n\n seed = 123456789\n x_lo = -10.0D+00\n x_hi = 20.0D+00\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_MOD_R4'\n write ( *, '(a)' ) ' MOD is a FORTRAN77 function which returns'\n write ( *, '(a)' ) ' the remainder after division.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' Here, the arguments are reals.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) \n & ' X Y MOD(X,Y)'\n write ( *, '(a)' ) ' '\n do test = 1, 10\n x = r4_uniform ( x_lo, x_hi, seed )\n y = r4_uniform ( x_lo, x_hi, seed )\n z = mod ( x, y )\n write ( *, '(2x,f14.6,2x,f14.6,2x,f14.6)' ) x, y, z\n end do\n\n return\n end\n subroutine test_mvbits\n\nc*********************************************************************72\nc\ncc TEST_MVBITS tests MVBITS.\nc\nc Discussion:\nc\nc The FORTRAN77 function MVBITS copies a sequence of bits.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n integer i1\n integer i2\n\n i1 = 1396\n i2 = 0\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_MVBITS'\n write ( *, '(a)' ) ' MVBITS is a FORTRAN77 function which'\n write ( *, '(a)' ) ' extracts bits from one place and copies'\n write ( *, '(a)' ) ' them elsewhere.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' CALL MVBITS(FROM,FROMPOS,LEN,TO,TOPOS)'\n write ( *, '(a)' ) ' '\n write ( *, '(a,i8)' ) ' We will always use I1 = ', i1\n write ( *, '(a,i8)' ) ' We will always start with I2 = ', i2\n\n write ( *, '(a)' ) ' '\n call mvbits ( i1, 0, 5, i2, 0 )\n write ( *, '(a,i12)' ) ' CALL MVBITS(I1,0, 5,I2,0): I2 = ', i2\n\n i2 = 0\n call mvbits ( i1, 0, 32, i2, 0 )\n write ( *, '(a,i12)' ) ' CALL MVBITS(I1,0,32,I2,0): I2 = ', i2\n\n i2 = 0\n call mvbits ( i1, 5, 5, i2, 0 )\n write ( *, '(a,i12)' ) ' CALL MVBITS(I1,5, 5,I2,0): I2 = ', i2\n\n i2 = 0\n call mvbits ( i1, 5, 5, i2, 5 )\n write ( *, '(a,i12)' ) ' CALL MVBITS(I1,5, 5,I2,5): I2 = ', i2\n\n return\n end\n subroutine test_nint\n\nc*********************************************************************72\nc\ncc TEST_NINT tests NINT.\nc\nc Discussion:\nc\nc The FORTRAN77 function NINT returns, as an integer, the nearest \nc integer to a given real value.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n double precision r8_uniform\n integer i\n integer j\n integer seed\n double precision x\n double precision x_hi\n double precision x_lo\n integer y\n\n seed = 123456789\n x_lo = -10.0D+00\n x_hi = 10.0D+00\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_NINT'\n write ( *, '(a)' ) ' NINT is a FORTRAN77 function which returns,'\n write ( *, '(a)' ) ' as an integer, the nearest integer to a '\n write ( *, '(a)' ) ' given real number.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' X NINT(X)'\n write ( *, '(a)' ) ' '\n do i = 1, 10\n x = r8_uniform ( x_lo, x_hi, seed )\n j = nint ( x )\n write ( *, '(2x,g14.6,2x,i8)' ) x, j\n end do\n\n return\n end\n subroutine test_not_i4\n\nc*********************************************************************72\nc\ncc TEST_NOT_I4 tests NOT on integer arguments.\nc\nc Discussion:\nc\nc The FORTRAN77 function NOT returns the bitwise NOT of an integer.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n integer i\n integer i4_uniform\n integer j\n integer seed\n integer test\n\n seed = 123456789\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_NOT_I4'\n write ( *, '(a)' ) ' NOT is a FORTRAN77 function which returns'\n write ( *, '(a)' ) ' the bitwise NOT of an integer.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' Here, I is an integer.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' I NOT(I)'\n write ( *, '(a)' ) ' '\n\n do test = 1, 10\n i = i4_uniform ( 0, 100, seed )\n j = not ( i )\n write ( *, '(2x,i12,2x,i12)' ) i, j\n end do\n\n return\n end\n subroutine test_real_c4\n\nc*********************************************************************72\nc\ncc TEST_REAL_C4 tests REAL as applied to complex numbers.\nc\nc Discussion:\nc\nc The FORTRAN77 function REAL can return the real part of a complex number.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n complex c4_uniform_01\n complex c\n integer i\n real r\n integer seed\n\n seed = 123456789\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_REAL_C4'\n write ( *, '(a)' ) ' REAL is a FORTRAN77 function which returns'\n write ( *, '(a)' ) ' the real part of a complex number.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) \n & ' X REAL(X)'\n write ( *, '(a)' ) \n & ' ------------------------ ----------------'\n write ( *, '(a)' ) ' '\n do i = 1, 10\n c = c4_uniform_01 ( seed )\n r = real ( c )\n write ( *, '(2x,f14.6,f14.6,6x,f14.6)' ) c, r\n end do\n\n return\n end\n subroutine test_sign\n\nc*********************************************************************72\nc\ncc TEST_SIGN tests SIGN.\nc\nc Discussion:\nc\nc The FORTRAN77 function SIGN(X,Y) transfers the sign of Y to the\nc magnitude of X.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n double precision r8_uniform\n integer i\n integer seed\n double precision x\n double precision x_hi\n double precision x_lo\n double precision y\n double precision z\n\n seed = 123456789\n x_lo = -10.0D+00\n x_hi = 10.0D+00\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_SIGN'\n write ( *, '(a)' ) ' SIGN is a FORTRAN77 function which returns'\n write ( *, '(a)' ) ' the sign of Y times the magnitude of X.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' X Y SIGN(X,Y)'\n write ( *, '(a)' ) ' '\n do i = 1, 10\n x = r8_uniform ( x_lo, x_hi, seed )\n y = r8_uniform ( x_lo, x_hi, seed )\n z = sign ( x, y )\n write ( *, '(2x,g14.6,2x,g14.6,2x,g14.6)' ) x, y, z\n end do\n\n return\n end\n subroutine test_sin_r8\n\nc*********************************************************************72\nc\ncc TEST_SIN_R8 tests SIN on double precision arguments.\nc\nc Discussion:\nc\nc The FORTRAN77 function SIN returns the sine of a real or complex number.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n double precision r8_uniform\n integer i\n integer seed\n double precision x\n double precision x_hi\n double precision x_lo\n double precision y\n\n seed = 123456789\n x_lo = -10.0D+00\n x_hi = 10.0D+00\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_SIN_R8'\n write ( *, '(a)' ) ' SIN is a FORTRAN77 function which returns'\n write ( *, '(a)' ) ' the sine of a real or complex number.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' Here we use double precision arguments.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' X SIN(X)'\n write ( *, '(a)' ) ' '\n do i = 1, 10\n x = r8_uniform ( x_lo, x_hi, seed )\n y = sin ( x )\n write ( *, '(2x,g14.6,2x,g14.6)' ) x, y\n end do\n\n return\n end\n subroutine test_sinh\n\nc*********************************************************************72\nc\ncc TEST_SINH tests SINH.\nc\nc Discussion:\nc\nc The FORTRAN77 function SINH returns the hyperbolic sine of a real number.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n double precision r8_uniform\n integer i\n integer seed\n double precision x\n double precision x_hi\n double precision x_lo\n double precision y\n\n seed = 123456789\n x_lo = -10.0D+00\n x_hi = 10.0D+00\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_SINH'\n write ( *, '(a)' ) ' SINH is a FORTRAN77 function which returns'\n write ( *, '(a)' ) ' the hyperbolic sine of a real number.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' X SINH(X)'\n write ( *, '(a)' ) ' '\n do i = 1, 10\n x = r8_uniform ( x_lo, x_hi, seed )\n y = sinh ( x )\n write ( *, '(2x,g14.6,2x,g14.6)' ) x, y\n end do\n\n return\n end\n subroutine test_sqrt\n\nc*********************************************************************72\nc\ncc TEST_SQRT tests SQRT.\nc\nc Discussion:\nc\nc The FORTRAN77 function SQRT returns the square root of a real number.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n double precision r8_uniform\n integer i\n integer seed\n double precision x\n double precision x_hi\n double precision x_lo\n double precision y\n double precision z\n\n seed = 123456789\n x_lo = 0.0D+00\n x_hi = 10.0D+00\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_SQRT'\n write ( *, '(a)' ) ' SQRT is a FORTRAN77 function which returns'\n write ( *, '(a)' ) ' the square root of a real number.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) \n & ' X SQRT(X) (SQRT(X))**2'\n write ( *, '(a)' ) ' '\n do i = 1, 10\n x = r8_uniform ( x_lo, x_hi, seed )\n y = sqrt ( x )\n z = y * y\n write ( *, '(2x,g14.6,2x,g14.6,2x,g14.6)' ) x, y, z\n end do\n\n return\n end\n subroutine test_tan\n\nc*********************************************************************72\nc\ncc TEST_TAN tests TAN.\nc\nc Discussion:\nc\nc The FORTRAN77 function TAN returns the tangent of a real number.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n double precision r8_uniform\n integer i\n integer seed\n double precision x\n double precision x_hi\n double precision x_lo\n double precision y\n\n seed = 123456789\n x_lo = -10.0D+00\n x_hi = 10.0D+00\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_TAN'\n write ( *, '(a)' ) ' TAN is a FORTRAN77 function which returns'\n write ( *, '(a)' ) ' the tangent of a real number.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' X TAN(X)'\n write ( *, '(a)' ) ' '\n do i = 1, 10\n x = r8_uniform ( x_lo, x_hi, seed )\n y = tan ( x )\n write ( *, '(2x,g14.6,2x,g14.6)' ) x, y\n end do\n\n return\n end\n subroutine test_tanh\n\nc*********************************************************************72\nc\ncc TEST_TANH tests TANH.\nc\nc Discussion:\nc\nc The FORTRAN77 function TANH returns the hyperbolic tangent of a \nc real number.\nc\nc Modified:\nc\nc 02 June 2007\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n double precision r8_uniform\n integer i\n integer seed\n double precision x\n double precision x_hi\n double precision x_lo\n double precision y\n\n seed = 123456789\n x_lo = -10.0D+00\n x_hi = 10.0D+00\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'TEST_TANH'\n write ( *, '(a)' ) ' TANH is a FORTRAN77 function which returns'\n write ( *, '(a)' ) ' the hyperbolic tangent of a real number.'\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) ' X TANH(X)'\n write ( *, '(a)' ) ' '\n do i = 1, 10\n x = r8_uniform ( x_lo, x_hi, seed )\n y = tanh ( x )\n write ( *, '(2x,g14.6,2x,g14.6)' ) x, y\n end do\n\n return\n end\n function c4_uniform_01 ( seed )\n\nc*********************************************************************72\nc\ncc C4_UNIFORM_01 returns a unit pseudorandom C4.\nc\nc Discussion:\nc\nc A C4 is a complex single precision value.\nc\nc The angle should be uniformly distributed between 0 and 2 * PI,\nc the square root of the radius uniformly distributed between 0 and 1.\nc\nc This results in a uniform distribution of values in the unit circle.\nc\nc Modified:\nc\nc 15 March 2005\nc\nc Author:\nc\nc John Burkardt\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, complex C4_UNIFORM_01, a pseudorandom complex value.\nc\n implicit none\n\n complex c4_uniform_01\n integer i4_huge\n integer k\n real pi\n parameter ( pi = 3.1415926E+00 )\n real r\n integer seed\n real theta\n\n if ( seed .eq. 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'C4_UNIFORM_01 - Fatal error!'\n write ( *, '(a)' ) ' Input value of SEED = 0.'\n stop\n end if\n\n k = seed / 127773\n\n seed = 16807 * ( seed - k * 127773 ) - k * 2836\n\n if ( seed .lt. 0 ) then\n seed = seed + i4_huge ( )\n end if\n\n r = sqrt ( real ( dble ( seed ) * 4.656612875D-10 ) )\n\n k = seed / 127773\n\n seed = 16807 * ( seed - k * 127773 ) - k * 2836\n\n if ( seed .lt. 0 ) then\n seed = seed + i4_huge ( )\n end if\n\n theta = 2.0E+00 * pi \n & * real ( dble ( seed ) * 4.656612875D-10 )\n\n c4_uniform_01 = r * cmplx ( cos ( theta ), sin ( theta ) )\n\n return\n end\n function ch_is_printable ( ch )\n\nc*********************************************************************72\nc\ncc CH_IS_PRINTABLE is TRUE if C is printable.\nc\nc Discussion:\nc\nc Instead of ICHAR, we now use the IACHAR function, which\nc guarantees the ASCII collating sequence.\nc\nc Modified:\nc\nc 31 October 2001\nc\nc Author:\nc\nc John Burkardt\nc\nc Parameters:\nc\nc Input, character CH, a character to check.\nc\nc Output, logical CH_IS_PRINTABLE is TRUE if C is a printable character.\nc\n implicit none\n\n character ch\n logical ch_is_printable\n integer i\n\n i = ichar ( ch )\n\n if ( 32 <= i .and. i <= 126 ) then\n ch_is_printable = .true.\n else\n ch_is_printable = .false.\n end if\n\n return\n end\n function i4_huge ( )\n\nc*********************************************************************72\nc\ncc I4_HUGE returns a \"huge\" I4.\nc\nc Modified:\nc\nc 13 November 2006\nc\nc Author:\nc\nc John Burkardt\nc\nc Parameters:\nc\nc Output, integer I4_HUGE, a huge number.\nc\n implicit none\n\n integer i4_huge\n\n i4_huge = 2147483647\n\n return\n end\n function i4_uniform ( a, b, seed )\n\nc*********************************************************************72\nc\ncc I4_UNIFORM returns a scaled pseudorandom I4.\nc\nc Discussion:\nc\nc An I4 is an integer value.\nc\nc The pseudorandom number should be uniformly distributed\nc between A and B.\nc\nc Modified:\nc\nc 12 November 2006\nc\nc Author:\nc\nc John Burkardt\nc\nc Reference:\nc\nc Paul Bratley, Bennett Fox, Linus Schrage,\nc A Guide to Simulation,\nc Springer Verlag, pages 201-202, 1983.\nc\nc 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, integer A, B, the limits of the interval.\nc\nc Input/output, integer SEED, the \"seed\" value, which should NOT be 0.\nc On output, SEED has been updated.\nc\nc Output, integer I4_UNIFORM, a number between A and B.\nc\n implicit none\n\n integer a\n integer b\n integer i4_huge\n integer i4_uniform\n integer k\n real r\n integer seed\n integer value\n\n if ( seed .eq. 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'I4_UNIFORM - Fatal error!'\n write ( *, '(a)' ) ' Input value of SEED = 0.'\n stop\n end if\n\n k = seed / 127773\n\n seed = 16807 * ( seed - k * 127773 ) - k * 2836\n\n if ( seed .lt. 0 ) then\n seed = seed + i4_huge ( )\n end if\n\n r = real ( seed ) * 4.656612875E-10\nc\nc Scale R to lie between A-0.5 and B+0.5.\nc\n r = ( 1.0E+00 - r ) * ( real ( min ( a, b ) ) - 0.5E+00 )\n & + r * ( real ( max ( a, b ) ) + 0.5E+00 )\nc\nc Use rounding to convert R to an integer between A and B.\nc\n value = nint ( r )\n\n value = max ( value, min ( a, b ) )\n value = min ( value, max ( a, b ) )\n\n i4_uniform = value\n\n return\n end\n function r4_uniform ( a, b, seed )\n\nc*********************************************************************72\nc\ncc R4_UNIFORM returns a scaled pseudorandom R4.\nc\nc Discussion:\nc\nc The pseudorandom number should be uniformly distributed\nc between A and B.\nc\nc Modified:\nc\nc 29 January 2005\nc\nc Author:\nc\nc John Burkardt\nc\nc Parameters:\nc\nc Input, real A, B, the limits of the interval.\nc\nc Input/output, integer SEED, the \"seed\" value, which should NOT be 0.\nc On output, SEED has been updated.\nc\nc Output, real R4_UNIFORM, a number strictly between A and B.\nc\n implicit none\n\n real a\n real b\n integer i4_huge\n integer k\n integer seed\n real r4_uniform\n\n if ( seed .eq. 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R4_UNIFORM - Fatal error!'\n write ( *, '(a)' ) ' Input value of SEED = 0.'\n stop\n end if\n\n k = seed / 127773\n\n seed = 16807 * ( seed - k * 127773 ) - k * 2836\n\n if ( seed .lt. 0 ) then\n seed = seed + i4_huge ( )\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 r4_uniform = a + ( b - a ) \n & * real ( dble ( seed ) * 4.656612875D-10 )\n\n return\n end\n function r4_uniform_01 ( seed )\n\nc*********************************************************************72\nc\ncc R4_UNIFORM_01 returns a unit pseudorandom R4.\nc\nc Discussion:\nc\nc This routine implements the recursion\nc\nc seed = 16807 * seed mod ( 2**31 - 1 )\nc r4_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 R4_UNIFORM_01\nc SEED SEED\nc\nc 12345 207482415 0.096616\nc 207482415 1790989824 0.833995\nc 1790989824 2035175616 0.947702\nc\nc Modified:\nc\nc 11 August 2004\nc\nc Author:\nc\nc John Burkardt\nc\nc Reference:\nc\nc Paul Bratley, Bennett Fox, Linus Schrage,\nc A Guide to Simulation,\nc Springer Verlag, pages 201-202, 1983.\nc\nc Pierre L'Ecuyer,\nc Random Number Generation,\nc in Handbook of Simulation,\nc edited by Jerry Banks,\nc Wiley Interscience, page 95, 1998.\nc\nc Bennett Fox,\nc Algorithm 647:\nc Implementation and Relative Efficiency of Quasirandom\nc Sequence Generators,\nc ACM Transactions on Mathematical Software,\nc Volume 12, Number 4, pages 362-376, 1986.\nc\nc Peter Lewis, Allen Goodman, James Miller,\nc A Pseudo-Random Number Generator for the System/360,\nc IBM Systems Journal,\nc Volume 8, pages 136-143, 1969.\nc\nc Parameters:\nc\nc Input/output, integer SEED, the \"seed\" value, which should NOT be 0.\nc On output, SEED has been updated.\nc\nc Output, real R4_UNIFORM_01, a new pseudorandom variate,\nc strictly between 0 and 1.\nc\n implicit none\n\n integer i4_huge\n integer k\n integer seed\n real r4_uniform_01\n\n if ( seed .eq. 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R4_UNIFORM_01 - Fatal error!'\n write ( *, '(a)' ) ' Input value of SEED = 0.'\n stop\n end if\n\n k = seed / 127773\n\n seed = 16807 * ( seed - k * 127773 ) - k * 2836\n\n if ( seed .lt. 0 ) then\n seed = seed + i4_huge ( )\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 r4_uniform_01 = real ( dble ( seed ) * 4.656612875D-10 )\n\n return\n end\n function r8_uniform ( a, b, seed )\n\nc*********************************************************************72\nc\ncc R8_UNIFORM returns a scaled pseudorandom R8.\nc\nc Discussion:\nc\nc The pseudorandom number should be uniformly distributed\nc between A and B.\nc\nc Modified:\nc\nc 06 January 2006\nc\nc Author:\nc\nc John Burkardt\nc\nc Parameters:\nc\nc Input, double precision A, B, the limits of the interval.\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, a number strictly between A and B.\nc\n implicit none\n\n double precision a\n double precision b\n integer i4_huge\n integer k\n double precision r8_uniform\n integer seed\n\n if ( seed .eq. 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R8_UNIFORM - Fatal error!'\n write ( *, '(a)' ) ' Input value of SEED = 0.'\n stop\n end if\n\n k = seed / 127773\n\n seed = 16807 * ( seed - k * 127773 ) - k * 2836\n\n if ( seed .lt. 0 ) then\n seed = seed + i4_huge ( )\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 = a + ( b - a ) * dble ( seed ) * 4.656612875D-10\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 Modified:\nc\nc 11 August 2004\nc\nc Author:\nc\nc John Burkardt\nc\nc Reference:\nc\nc Paul Bratley, Bennett Fox, Linus Schrage,\nc A Guide to Simulation,\nc Springer Verlag, pages 201-202, 1983.\nc\nc Pierre L'Ecuyer,\nc Random Number Generation,\nc in Handbook of Simulation,\nc edited by Jerry Banks,\nc Wiley Interscience, page 95, 1998.\nc\nc Bennett Fox,\nc Algorithm 647:\nc Implementation and Relative Efficiency of Quasirandom\nc Sequence Generators,\nc ACM Transactions on Mathematical Software,\nc Volume 12, Number 4, pages 362-376, 1986.\nc\nc Peter Lewis, Allen Goodman, James Miller,\nc A Pseudo-Random Number Generator for the System/360,\nc IBM Systems Journal,\nc Volume 8, pages 136-143, 1969.\nc\nc Parameters:\nc\nc Input/output, integer SEED, the \"seed\" value, which should NOT be 0.\nc On output, SEED has been updated.\nc\nc Output, double precision R8_UNIFORM_01, a new pseudorandom variate,\nc strictly between 0 and 1.\nc\n implicit none\n\n integer i4_huge\n integer k\n double precision r8_uniform_01\n integer seed\n\n if ( seed .eq. 0 ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'R8_UNIFORM_01 - Fatal error!'\n write ( *, '(a)' ) ' Input value of SEED = 0.'\n stop\n end if\n\n k = seed / 127773\n\n seed = 16807 * ( seed - k * 127773 ) - k * 2836\n\n if ( seed .lt. 0 ) then\n seed = seed + i4_huge ( )\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 timestamp ( )\n\nc*********************************************************************72\nc\ncc TIMESTAMP prints out the current YMDHMS date as a timestamp.\nc\nc Discussion:\nc\nc This FORTRAN77 version is made available for cases where the\nc FORTRAN90 version cannot be used.\nc\nc Modified:\nc\nc 12 January 2007\nc\nc Author:\nc\nc John Burkardt\nc\nc Parameters:\nc\nc None\nc\n implicit none\n\n character * ( 8 ) ampm\n integer d\n character * ( 8 ) date\n integer h\n integer m\n integer mm\n character * ( 9 ) month(12)\n integer n\n integer s\n character * ( 10 ) time\n integer y\n\n save month\n\n data month /\n & 'January ', 'February ', 'March ', 'April ', \n & 'May ', 'June ', 'July ', 'August ', \n & 'September', 'October ', 'November ', 'December ' /\n\n call date_and_time ( date, time )\n\n read ( date, '(i4,i2,i2)' ) y, m, d\n read ( time, '(i2,i2,i2,1x,i3)' ) h, n, s, mm\n\n if ( h .lt. 12 ) then\n ampm = 'AM'\n else if ( h .eq. 12 ) then\n if ( n .eq. 0 .and. s .eq. 0 ) then\n ampm = 'Noon'\n else\n ampm = 'PM'\n end if\n else\n h = h - 12\n if ( h .lt. 12 ) then\n ampm = 'PM'\n else if ( h .eq. 12 ) then\n if ( n .eq. 0 .and. s .eq. 0 ) then\n ampm = 'Midnight'\n else\n ampm = 'AM'\n end if\n end if\n end if\n\n write ( *, \n & '(i2,1x,a,1x,i4,2x,i2,a1,i2.2,a1,i2.2,a1,i3.3,1x,a)' ) \n & d, month(m), y, h, ':', n, ':', s, '.', mm, ampm\n\n return\n end\n", "meta": {"hexsha": "51b71bb0844c3a008569ecf8a274e443b799adfa", "size": 77325, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/CompileTests/Fortran_tests/intrinsic_function_test.f", "max_stars_repo_name": "maurizioabba/rose", "max_stars_repo_head_hexsha": "7597292cf14da292bdb9a4ef573001b6c5b9b6c0", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/CompileTests/Fortran_tests/intrinsic_function_test.f", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/CompileTests/Fortran_tests/intrinsic_function_test.f", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 23.2626353791, "max_line_length": 80, "alphanum_fraction": 0.4732363401, "num_tokens": 24929, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8289387998695209, "lm_q2_score": 0.7931059609645724, "lm_q1q2_score": 0.6574363034513357}} {"text": "module mod_initial\n\n use iso_fortran_env, only: int32, real32\n implicit none\n private\n public populate_gaussian\n\ncontains\n\n subroutine populate_gaussian(array, mu, decay)\n implicit none\n\n real(real32), intent(in out) :: array(:)\n integer(int32), intent(in) :: mu\n real(real32), intent(in) :: decay\n\n integer(int32) :: i\n\n do concurrent(i = 1:size(array))\n array(i) = exp(-decay * (i - mu) ** 2)\n end do\n end subroutine populate_gaussian\n\nend module mod_initial\n", "meta": {"hexsha": "06caf1b5fd1c2c1fb14fa4ca48284ce3c306418a", "size": 539, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/mod_initial.f90", "max_stars_repo_name": "AJSKirk/tsunami_simulator", "max_stars_repo_head_hexsha": "a5ddd367ee2ab847fcb8e66f0203305d03e84b88", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/mod_initial.f90", "max_issues_repo_name": "AJSKirk/tsunami_simulator", "max_issues_repo_head_hexsha": "a5ddd367ee2ab847fcb8e66f0203305d03e84b88", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/mod_initial.f90", "max_forks_repo_name": "AJSKirk/tsunami_simulator", "max_forks_repo_head_hexsha": "a5ddd367ee2ab847fcb8e66f0203305d03e84b88", "max_forks_repo_licenses": ["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": 50, "alphanum_fraction": 0.6141001855, "num_tokens": 137, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388083214156, "lm_q2_score": 0.7931059511841119, "lm_q1q2_score": 0.6574363020471805}} {"text": "! { dg-do run }\r\n! Check the fix for PR16206, in which array sections would not work\r\n! in array initializers. Use of implied do loop variables for indices\r\n! and substrings, with and without implied do loops, were fixed at the\r\n! same time.\r\n!\r\n! Contributed by Paul Thomas \r\n! based on testcase from Harald Anlauf \r\n!\r\n real, parameter :: x(4,4) = reshape((/(i, i = 1, 16)/), (/4,4/))\r\n real, parameter :: y(4) = (/ x(1:2, 2), x(3:4, 4)/)\r\n real, parameter :: z(2) = x(2:3, 3) + 1\r\n real, parameter :: r(6) = (/(x(i:i +1, i), i = 1,3)/)\r\n real, parameter :: s(12) = (/((x(i, i:j-1:-1), i = 3,4), j = 2,3)/)\r\n real, parameter :: t(8) = (/(z, &\r\n real (i)**3, y(i), i = 2, 3)/) ! { dg-warning \"nonstandard\" }\r\n\r\n integer, parameter :: ii = 4\r\n\r\n character(4), parameter :: chr(4) = (/\"abcd\", \"efgh\", \"ijkl\", \"mnop\"/)\r\n character(4), parameter :: chrs = chr(ii)(2:3)//chr(2)(ii-3:ii-2) \r\n character(4), parameter :: chrt(2) = (/chr(2:2)(2:3), chr(ii-1)(3:ii)/)\r\n character(2), parameter :: chrx(2) = (/(chr(i)(i:i+1), i=2,3)/)\r\n\r\n if (any (y .ne. (/5., 6., 15., 16./))) call abort ()\r\n if (any (z .ne. (/11., 12./))) call abort ()\r\n if (any (r .ne. (/1., 2., 6., 7., 11., 12./))) call abort ()\r\n if (any (s .ne. (/11., 7., 3., 16., 12., 8., 4., &\r\n 11., 7., 16., 12., 8. /))) call abort ()\r\n\r\n if (any (t .ne. (/11., 12., 8., 6., 11., 12., 27., 15. /))) call abort ()\r\n\r\n if (chrs .ne. \"noef\") call abort ()\r\n if (any (chrt .ne. (/\"fg\", \"kl\"/))) call abort ()\r\n if (any (chrx .ne. (/\"fg\", \"kl\"/))) call abort ()\r\nend\r\n", "meta": {"hexsha": "b1db9bf59b1ff680df94d00acdf30efce2f4d227", "size": 1605, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "llvm-gcc-4.2-2.9/gcc/testsuite/gfortran.dg/array_initializer_1.f90", "max_stars_repo_name": "vidkidz/crossbridge", "max_stars_repo_head_hexsha": "ba0bf94aee0ce6cf7eb5be882382e52bc57ba396", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-04-09T02:58:13.000Z", "max_stars_repo_stars_event_max_datetime": "2016-04-09T02:58:13.000Z", "max_issues_repo_path": "llvm-gcc-4.2-2.9/gcc/testsuite/gfortran.dg/array_initializer_1.f90", "max_issues_repo_name": "vidkidz/crossbridge", "max_issues_repo_head_hexsha": "ba0bf94aee0ce6cf7eb5be882382e52bc57ba396", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "llvm-gcc-4.2-2.9/gcc/testsuite/gfortran.dg/array_initializer_1.f90", "max_forks_repo_name": "vidkidz/crossbridge", "max_forks_repo_head_hexsha": "ba0bf94aee0ce6cf7eb5be882382e52bc57ba396", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.3783783784, "max_line_length": 76, "alphanum_fraction": 0.5034267913, "num_tokens": 647, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388083214156, "lm_q2_score": 0.7931059462938815, "lm_q1q2_score": 0.6574362979934788}} {"text": " SUBROUTINE ALG14 (XDATA,YDATA,NDATA,XIN,YOUT,YPRIME,NXY,NWOT)\r\nC\r\nC THIS SPLINE ROUTINE DETERMINES Y AND/OR YPRIME LINEAR EXTRAPOLATI\r\nC XDATA AND XIN MUST BE IN ASCENDING ORDER E1 AND E2 ARE D2YDX2 LAS\r\nC D2YDX2 LAST-BUT-ONE AT ENDS OF SPECIFIED REGION OF BEAM\r\nC\r\n REAL M\r\nC\r\n DIMENSION A(65), B(65), D(65), M(65), XDATA(2), YDATA(2), XIN(1),\r\n 1YOUT(1), YPRIME(1)\r\nC\r\n IF (NDATA-2) 240,10,70\r\n10 IF (NWOT-1) 20,40,20\r\n20 DO 30 I=1,NXY\r\n30 YOUT(I)=((YDATA(2)-YDATA(1))/(XDATA(2)-XDATA(1)))*(XIN(I)-XDATA(1)\r\n 1)+YDATA(1)\r\n40 IF (NWOT) 240,240,50\r\n50 DO 60 I=1,NXY\r\n60 YPRIME(I)=(YDATA(2)-YDATA(1))/(XDATA(2)-XDATA(1))\r\n GO TO 240\r\n70 CONTINUE\r\n E1=1.0\r\n E2=1.0\r\n A(1)=1.0\r\n B(1)=-E1\r\n D(1)=0.0\r\n N=NDATA-1\r\n DO 80 I=2,N\r\n A(I)=(XDATA(I+1)-XDATA(I-1))/3.0-(XDATA(I)-XDATA(I-1))*B(I-1)/(6.0\r\n 1*A(I-1))\r\n B(I)=(XDATA(I+1)-XDATA(I))/6.0\r\n80 D(I)=(YDATA(I+1)-YDATA(I))/(XDATA(I+1)-XDATA(I))-(YDATA(I)-YDATA(I\r\n 1-1))/(XDATA(I)-XDATA(I-1))-(XDATA(I)-XDATA(I-1))*D(I-1)/6.0/A(I-1)\r\n A(NDATA)=-E2\r\n B(NDATA)=1.0\r\n D(NDATA)=0.0\r\n M(NDATA)=A(NDATA)*D(N)/(A(NDATA)*B(N)-A(N)*B(NDATA))\r\n DO 90 II=2,NDATA\r\n I=NDATA+1-II\r\n90 M(I)=(D(I)-B(I)*M(I+1))/A(I)\r\n J=1\r\n I=1\r\n100 IF (XIN(I)-XDATA(1)) 190,190,110\r\n110 IF (XIN(I)-XDATA(J+1)) 140,140,120\r\n120 IF (J+1-NDATA) 130,140,140\r\n130 J=J+1\r\n GO TO 110\r\n140 IF (XIN(I)-XDATA(NDATA)) 150,220,220\r\n150 DX=XDATA(J+1)-XDATA(J)\r\n IF (NWOT-1) 160,170,160\r\n160 YOUT(I)=M(J)/(6.0*DX)*(XDATA(J+1)-XIN(I))**3+M(J+1)/(6.0*DX)*(XIN(\r\n 1I)-XDATA(J))**3+(XDATA(J+1)-XIN(I))*(YDATA(J)/DX-M(J)/6.0*DX)+(XIN\r\n 2(I)-XDATA(J))*(YDATA(J+1)/DX-M(J+1)/6.0*DX)\r\n IF (NWOT) 170,180,170\r\n170 YPRIME(I)=(-M(J)*(XDATA(J+1)-XIN(I))**2/2.0+M(J+1)*(XIN(I)-XDATA(J\r\n 1))**2/2.0+YDATA(J+1)-YDATA(J))/DX-(M(J+1)-M(J))/6.0*DX\r\n180 I=I+1\r\n IF (I-NXY) 100,100,240\r\n190 YDASH=(YDATA(2)-YDATA(1))/(XDATA(2)-XDATA(1))-(M(1)/3.0+M(2)/6.0)*\r\n 1(XDATA(2)-XDATA(1))\r\n IF (NWOT-1) 200,210,200\r\n200 YOUT(I)=YDATA(1)-YDASH*(XDATA(1)-XIN(I))\r\n IF (NWOT) 210,180,210\r\n210 YPRIME(I)=YDASH\r\n GO TO 180\r\n220 YDASH=(YDATA(NDATA)-YDATA(N))/(XDATA(NDATA)-XDATA(N))+(M(NDATA)/3.\r\n 10+M(N)/6.0)*(XDATA(NDATA)-XDATA(N))\r\n IF (NWOT-1) 230,210,230\r\n230 YOUT(I)=YDATA(NDATA)+YDASH*(XIN(I)-XDATA(NDATA))\r\n IF (NWOT) 210,180,210\r\n240 RETURN\r\n END\r\n", "meta": {"hexsha": "30f63f8b8440c76c3c4089a8ba8d4091256deb58", "size": 2490, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "mis/alg14.f", "max_stars_repo_name": "ldallolio/NASTRAN-95", "max_stars_repo_head_hexsha": "6d2c175f5b53ebaec4ba2b5186f7926ef9d0ed47", "max_stars_repo_licenses": ["NASA-1.3"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2016-01-09T14:33:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-18T11:51:42.000Z", "max_issues_repo_path": "mis/alg14.f", "max_issues_repo_name": "gassive/NASTRAN95", "max_issues_repo_head_hexsha": "98cb3acaa7990d639360601648498834c7782056", "max_issues_repo_licenses": ["NASA-1.3"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2016-01-17T07:30:19.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-06T19:37:44.000Z", "max_forks_repo_path": "mis/alg14.f", "max_forks_repo_name": "gassive/NASTRAN95", "max_forks_repo_head_hexsha": "98cb3acaa7990d639360601648498834c7782056", "max_forks_repo_licenses": ["NASA-1.3"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-04-07T20:51:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T14:16:01.000Z", "avg_line_length": 34.1095890411, "max_line_length": 73, "alphanum_fraction": 0.5305220884, "num_tokens": 1209, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.923039160069787, "lm_q2_score": 0.7122321903471563, "lm_q1q2_score": 0.6574182027527039}} {"text": " SUBROUTINE MB03BD( JOB, DEFL, COMPQ, QIND, K, N, H, ILO, IHI, S,\n $ A, LDA1, LDA2, Q, LDQ1, LDQ2, ALPHAR, ALPHAI,\n $ BETA, SCAL, IWORK, LIWORK, DWORK, LDWORK,\n $ IWARN, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To find the eigenvalues of the generalized matrix product\nC\nC S(1) S(2) S(K)\nC A(:,:,1) * A(:,:,2) * ... * A(:,:,K)\nC\nC where A(:,:,H) is upper Hessenberg and A(:,:,i), i <> H, is upper\nC triangular, using a double-shift version of the periodic\nC QZ method. In addition, A may be reduced to periodic Schur form:\nC A(:,:,H) is upper quasi-triangular and all the other factors\nC A(:,:,I) are upper triangular. Optionally, the 2-by-2 triangular\nC matrices corresponding to 2-by-2 diagonal blocks in A(:,:,H)\nC are so reduced that their product is a 2-by-2 diagonal matrix.\nC\nC If COMPQ = 'U' or COMPQ = 'I', then the orthogonal factors are\nC computed and stored in the array Q so that for S(I) = 1,\nC\nC T\nC Q(:,:,I)(in) A(:,:,I)(in) Q(:,:,MOD(I,K)+1)(in)\nC T (1)\nC = Q(:,:,I)(out) A(:,:,I)(out) Q(:,:,MOD(I,K)+1)(out),\nC\nC and for S(I) = -1,\nC\nC T\nC Q(:,:,MOD(I,K)+1)(in) A(:,:,I)(in) Q(:,:,I)(in)\nC T (2)\nC = Q(:,:,MOD(I,K)+1)(out) A(:,:,I)(out) Q(:,:,I)(out).\nC\nC A partial generation of the orthogonal factors can be realized\nC via the array QIND.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC JOB CHARACTER*1\nC Specifies the computation to be performed, as follows:\nC = 'E': compute the eigenvalues only; A will not\nC necessarily be put into periodic Schur form;\nC = 'S': put A into periodic Schur form, and return the\nC eigenvalues in ALPHAR, ALPHAI, BETA, and SCAL;\nC = 'T': as JOB = 'S', but A is put into standardized\nC periodic Schur form, that is, the general product\nC of the 2-by-2 triangular matrices corresponding to\nC a complex eigenvalue is diagonal.\nC\nC DEFL CHARACTER*1\nC Specifies the deflation strategy to be used, as follows:\nC = 'C': apply a careful deflation strategy, that is,\nC the criteria are based on the magnitudes of\nC neighboring elements and infinite eigenvalues are\nC only deflated at the top; this is the recommended\nC option;\nC = 'A': apply a more aggressive strategy, that is,\nC elements on the subdiagonal or diagonal are set\nC to zero as soon as they become smaller in magnitude\nC than eps times the norm of the corresponding\nC factor; this option is only recommended if\nC balancing is applied beforehand and convergence\nC problems are observed.\nC\nC COMPQ CHARACTER*1\nC Specifies whether or not the orthogonal transformations\nC should be accumulated in the array Q, as follows:\nC = 'N': do not modify Q;\nC = 'U': modify (update) the array Q by the orthogonal\nC transformations that are applied to the matrices in\nC the array A to reduce them to periodic Schur form;\nC = 'I': like COMPQ = 'U', except that each matrix in the\nC array Q will be first initialized to the identity\nC matrix;\nC = 'P': use the parameters as encoded in QIND.\nC\nC QIND INTEGER array, dimension (K)\nC If COMPQ = 'P', then this array describes the generation\nC of the orthogonal factors as follows:\nC If QIND(I) > 0, then the array Q(:,:,QIND(I)) is\nC modified by the transformations corresponding to the\nC i-th orthogonal factor in (1) and (2).\nC If QIND(I) < 0, then the array Q(:,:,-QIND(I)) is\nC initialized to the identity and modified by the\nC transformations corresponding to the i-th orthogonal\nC factor in (1) and (2).\nC If QIND(I) = 0, then the transformations corresponding\nC to the i-th orthogonal factor in (1), (2) are not applied.\nC\nC Input/Output Parameters\nC\nC K (input) INTEGER\nC The number of factors. K >= 1.\nC\nC N (input) INTEGER\nC The order of each factor in the array A. N >= 0.\nC\nC H (input) INTEGER\nC Hessenberg index. The factor A(:,:,H) is on entry in upper\nC Hessenberg form. 1 <= H <= K.\nC\nC ILO (input) INTEGER\nC IHI (input) INTEGER\nC It is assumed that each factor in A is already upper\nC triangular in rows and columns 1:ILO-1 and IHI+1:N.\nC 1 <= ILO <= IHI <= N, if N > 0;\nC ILO = 1 and IHI = 0, if N = 0.\nC\nC S (input) INTEGER array, dimension (K)\nC The leading K elements of this array must contain the\nC signatures of the factors. Each entry in S must be either\nC 1 or -1.\nC\nC A (input/output) DOUBLE PRECISION array, dimension\nC (LDA1,LDA2,K)\nC On entry, the leading N-by-N-by-K part of this array\nC must contain the factors in upper Hessenberg-triangular\nC form, that is, A(:,:,H) is upper Hessenberg and the other\nC factors are upper triangular.\nC On exit, if JOB = 'S' and INFO = 0, the leading\nC N-by-N-by-K part of this array contains the factors of\nC A in periodic Schur form, that is, A(:,:,H) is upper quasi\nC triangular and the other factors are upper triangular.\nC On exit, if JOB = 'T' and INFO = 0, the leading\nC N-by-N-by-K part of this array contains the factors of\nC A as for the option JOB = 'S', but the product of the\nC triangular factors corresponding to a 2-by-2 block in\nC A(:,:,H) is diagonal.\nC On exit, if JOB = 'E', then the leading N-by-N-by-K part\nC of this array contains meaningless elements in the off-\nC diagonal blocks. Consequently, the formulas (1) and (2)\nC do not hold for the returned A and Q (if COMPQ <> 'N')\nC in this case.\nC\nC LDA1 INTEGER\nC The first leading dimension of the array A.\nC LDA1 >= MAX(1,N).\nC\nC LDA2 INTEGER\nC The second leading dimension of the array A.\nC LDA2 >= MAX(1,N).\nC\nC Q (input/output) DOUBLE PRECISION array, dimension\nC (LDQ1,LDQ2,K)\nC On entry, if COMPQ = 'U', the leading N-by-N-by-K part\nC of this array must contain the initial orthogonal factors\nC as described in (1) and (2).\nC On entry, if COMPQ = 'P', only parts of the leading\nC N-by-N-by-K part of this array must contain some\nC orthogonal factors as described by the parameters QIND.\nC If COMPQ = 'I', this array should not be set on entry.\nC On exit, if COMPQ = 'U' or COMPQ = 'I', the leading\nC N-by-N-by-K part of this array contains the modified\nC orthogonal factors as described in (1) and (2).\nC On exit, if COMPQ = 'P', only parts of the leading\nC N-by-N-by-K part contain some modified orthogonal factors\nC as described by the parameters QIND.\nC This array is not referenced if COMPQ = 'N'.\nC\nC LDQ1 INTEGER\nC The first leading dimension of the array Q. LDQ1 >= 1,\nC and, if COMPQ <> 'N', LDQ1 >= MAX(1,N).\nC\nC LDQ2 INTEGER\nC The second leading dimension of the array Q. LDQ2 >= 1,\nC and, if COMPQ <> 'N', LDQ2 >= MAX(1,N).\nC\nC ALPHAR (output) DOUBLE PRECISION array, dimension (N)\nC On exit, if INFO = 0, the leading N elements of this array\nC contain the scaled real parts of the eigenvalues of the\nC matrix product A. The i-th eigenvalue of A is given by\nC\nC (ALPHAR(I) + ALPHAI(I)*SQRT(-1))/BETA(I) * BASE**SCAL(I),\nC\nC where BASE is the machine base (often 2.0). Complex\nC conjugate eigenvalues appear in consecutive locations.\nC\nC ALPHAI (output) DOUBLE PRECISION array, dimension (N)\nC On exit, if INFO = 0, the leading N elements of this array\nC contain the scaled imaginary parts of the eigenvalues\nC of A.\nC\nC BETA (output) DOUBLE PRECISION array, dimension (N)\nC On exit, if INFO = 0, the leading N elements of this array\nC contain indicators for infinite eigenvalues. That is, if\nC BETA(I) = 0.0, then the i-th eigenvalue is infinite.\nC Otherwise BETA(I) is set to 1.0.\nC\nC SCAL (output) INTEGER array, dimension (N)\nC On exit, if INFO = 0, the leading N elements of this array\nC contain the scaling parameters for the eigenvalues of A.\nC\nC Workspace\nC\nC IWORK INTEGER array, dimension (LIWORK)\nC On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK,\nC and if IWARN > N, the nonzero absolute values in IWORK(2),\nC ..., IWORK(N+1) are indices of the possibly inaccurate\nC eigenvalues, as well as of the corresponding 1-by-1 or\nC 2-by-2 diagonal blocks of the factors in the array A.\nC The 2-by-2 blocks correspond to negative values in IWORK.\nC One negative value is stored for each such eigenvalue\nC pair. Its modulus indicates the starting index of a\nC 2-by-2 block. This is also done for any value of IWARN,\nC if a 2-by-2 block is found to have two real eigenvalues.\nC On exit, if INFO = -22, IWORK(1) returns the minimum value\nC of LIWORK.\nC\nC LIWORK INTEGER\nC The length of the array IWORK. LIWORK >= 2*K+N.\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0, DWORK(1) returns the optimal LDWORK,\nC and DWORK(2), ..., DWORK(1+K) contain the Frobenius norms\nC of the factors of the formal matrix product used by the\nC algorithm.\nC On exit, if INFO = -24, DWORK(1) returns the minimum value\nC of LDWORK.\nC\nC LDWORK INTEGER\nC The length of the array DWORK.\nC LDWORK >= K + MAX( 2*N, 8*K ).\nC\nC Warning Indicator\nC\nC IWARN INTEGER\nC = 0 : no warnings;\nC = 1,..,N-1 : A is in periodic Schur form, but the\nC algorithm was not able to reveal information\nC about the eigenvalues from the 2-by-2\nC blocks.\nC ALPHAR(i), ALPHAI(i), BETA(i) and SCAL(i),\nC can be incorrect for i = 1, ..., IWARN+1;\nC = N : some eigenvalues might be inaccurate;\nC = N+1 : some eigenvalues might be inaccurate, and\nC details can be found in IWORK.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0 : succesful exit;\nC < 0 : if INFO = -i, the i-th argument had an illegal\nC value;\nC = 1,..,N : the periodic QZ iteration did not converge.\nC A is not in periodic Schur form, but\nC ALPHAR(i), ALPHAI(i), BETA(i) and SCAL(i), for\nC i = INFO+1,...,N should be correct.\nC\nC METHOD\nC\nC A modified version of the periodic QZ algorithm is used [1], [2].\nC\nC REFERENCES\nC\nC [1] Bojanczyk, A., Golub, G. H. and Van Dooren, P.\nC The periodic Schur decomposition: algorithms and applications.\nC In F.T. Luk (editor), Advanced Signal Processing Algorithms,\nC Architectures, and Implementations III, Proc. SPIE Conference,\nC vol. 1770, pp. 31-42, 1992.\nC\nC [2] Kressner, D.\nC An efficient and reliable implementation of the periodic QZ\nC algorithm. IFAC Workshop on Periodic Control Systems (PSYCO\nC 2001), Como (Italy), August 27-28 2001. Periodic Control\nC Systems 2001 (IFAC Proceedings Volumes), Pergamon.\nC\nC NUMERICAL ASPECTS\nC\nC The implemented method is numerically backward stable.\nC 3\nC The algorithm requires 0(K N ) floating point operations.\nC\nC CONTRIBUTOR\nC\nC D. Kressner, Technical Univ. Berlin, Germany, June 2001.\nC\nC REVISIONS\nC\nC V. Sima, Research Institute for Informatics, Bucharest, Romania,\nC July 2009, SLICOT Library version of the routine PHGEQZ.\nC V. Sima, June 2010, July 2010, Nov. 2010, Sep. 2011, Oct. 2011,\nC Jan. 2013, Feb. 2013, July 2013, Sep. 2016, Nov. 2016, Apr. 2018.\nC Dec. 2018, Jan. 2019, Feb. 2019, Mar. 2019, Aug.-Sep. 2019, Dec.\nC 2019, Jan.-Apr. 2020.\nC\nC KEYWORDS\nC\nC Eigenvalues, QZ algorithm, periodic QZ algorithm, orthogonal\nC transformation.\nC\nC ******************************************************************\nC\nC .. Parameters ..\nC .. NITER is the number of consecutive iterations for a deflated ..\nC .. subproblem before switching from implicit to explicit shifts...\nC .. MCOUNT is, similarly, the maximum number of consecutive ..\nC .. iterations before switching from explicit to implicit shifts...\nC\n INTEGER MCOUNT, NITER\n PARAMETER ( MCOUNT = 1, NITER = 10 )\n DOUBLE PRECISION ZERO, ONE, TEN\n PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0, TEN = 1.0D+1 )\nC .. Scalar Arguments ..\n CHARACTER COMPQ, DEFL, JOB\n INTEGER H, IHI, ILO, INFO, IWARN, K, LDA1, LDA2, LDQ1,\n $ LDQ2, LDWORK, LIWORK, N\nC .. Array Arguments ..\n INTEGER IWORK(*), QIND(*), S(*), SCAL(*)\n DOUBLE PRECISION A(LDA1,LDA2,*), ALPHAI(*), ALPHAR(*), BETA(*),\n $ DWORK(*), Q(LDQ1,LDQ2,*)\nC .. Local Arrays ..\n DOUBLE PRECISION MACPAR(5)\nC .. Local Scalars ..\n LOGICAL ADEFL, ISINF, LCMPQ, LINIQ, LPARQ, LSCHR, LSVD\n CHARACTER SHFT\n INTEGER AIND, COUNT, COUNTE, I, IERR, IFIRST, IFRSTM,\n $ IITER, ILAST, ILASTM, IN, IO, J, J1, JDEF,\n $ JITER, JLO, L, LDEF, LM, MAXIT, NTRA, OPTDW,\n $ OPTIW, QI, SINV, TITER, ZITER\n DOUBLE PRECISION A1, A2, A3, A4, BASE, CS, CS1, CS2, LGBAS, NRM,\n $ SAFMAX, SAFMIN, SDET, SMLNUM, SN, SN1, SN2,\n $ SVMN, TEMP, TEMP2, TOL, TOLL, ULP, W1, W2\nC .. Workspace Pointers ..\n INTEGER MAPA, MAPH, MAPQ, PDW, PFREE, PNORM\nC .. External Functions ..\n LOGICAL LSAME\n DOUBLE PRECISION DLAMCH, DLANHS, DLAPY2, DLAPY3\n EXTERNAL DLAMCH, DLANHS, DLAPY2, DLAPY3, LSAME\nC .. External Subroutines ..\n EXTERNAL DLABAD, DLADIV, DLARTG, DLAS2, DLASET, DROT,\n $ MA01BD, MB03AB, MB03AF, MB03BA, MB03BB, MB03BC,\n $ MB03BF, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC ABS, DBLE, INT, LOG, MAX, MIN, MOD, SIGN, SQRT\nC\nC .. Executable Statements ..\nC\nC Decode the scalar input parameters.\nC\n LSVD = LSAME( JOB, 'T' )\n LSCHR = LSAME( JOB, 'S' ) .OR. LSVD\n LINIQ = LSAME( COMPQ, 'I' )\n LCMPQ = LSAME( COMPQ, 'U' ) .OR. LINIQ\n LPARQ = LSAME( COMPQ, 'P' )\n ADEFL = LSAME( DEFL, 'A' )\n IWARN = 0\n OPTDW = K + MAX( 2*N, 8*K )\n OPTIW = 2*K + N\nC\nC Check the scalar input parameters.\nC\n INFO = 0\n IF ( .NOT. ( LSCHR .OR. LSAME( JOB, 'E' ) ) ) THEN\n INFO = -1\n ELSE IF ( .NOT.( ADEFL .OR. LSAME( DEFL, 'C' ) ) ) THEN\n INFO = -2\n ELSE IF ( .NOT.( LCMPQ .OR. LPARQ .OR. LSAME( COMPQ, 'N' ) ) )\n $ THEN\n INFO = -3\n ELSE IF ( K.LT.1 ) THEN\n INFO = -5\n ELSE IF ( N.LT.0 ) THEN\n INFO = -6\n ELSE IF ( H.LT.1 .OR. H.GT.K ) THEN\n INFO = -7\n ELSE IF ( ILO.LT.1 ) THEN\n INFO = -8\n ELSE IF ( IHI.GT.N .OR. IHI.LT.ILO-1 ) THEN\n INFO = -9\n ELSE IF ( LDA1.LT.MAX( 1, N ) ) THEN\n INFO = -12\n ELSE IF ( LDA2.LT.MAX( 1, N ) ) THEN\n INFO = -13\n ELSE IF ( LDQ1.LT.1 .OR. ( ( LCMPQ .OR. LPARQ )\n $ .AND. LDQ1.LT.N ) ) THEN\n INFO = -15\n ELSE IF ( LDQ2.LT.1 .OR. ( ( LCMPQ .OR. LPARQ )\n $ .AND. LDQ2.LT.N ) ) THEN\n INFO = -16\n ELSE IF ( LIWORK.LT.OPTIW ) THEN\n IWORK(1) = OPTIW\n INFO = -22\n ELSE IF ( LDWORK.LT.OPTDW ) THEN\n DWORK(1) = DBLE( OPTDW )\n INFO = -24\n END IF\nC\nC Return if there were illegal values.\nC\n IF ( INFO.NE.0 ) THEN\n CALL XERBLA( 'MB03BD', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF ( N.EQ.0 ) THEN\n DWORK(1) = ONE\n IWORK(1) = 1\n RETURN\n END IF\nC\nC Compute Maps for accessing A and Q.\nC\n MAPA = 0\n MAPH = 2\n MAPQ = K\n QI = 0\n CALL MB03BA( K, H, S, SINV, IWORK(MAPA+1), IWORK(MAPQ+1) )\nC\nC Machine Constants.\nC\n IN = IHI + 1 - ILO\n SAFMIN = DLAMCH( 'SafeMinimum' )\n SAFMAX = ONE / SAFMIN\n ULP = DLAMCH( 'Precision' )\n TOLL = TEN*ULP\n CALL DLABAD( SAFMIN, SAFMAX )\n SMLNUM = SAFMIN*( IN / ULP )\n BASE = DLAMCH( 'Base' )\n LGBAS = LOG( BASE )\nC\n MACPAR(2) = DLAMCH( 'Underflow' )\n IF ( LSVD ) THEN\n MACPAR(1) = DLAMCH( 'ORmax' )\n MACPAR(3) = SAFMIN\n MACPAR(4) = DLAMCH( 'Epsilon' )\n MACPAR(5) = BASE\n END IF\n IF ( K.GE.INT( LOG( MACPAR(2) ) / LOG( ULP ) ) ) THEN\nC\nC Start Iteration with a controlled zero shift.\nC\n ZITER = -1\n ELSE\n ZITER = 0\n END IF\nC\nC Initialize IWORK (needed in case of loosing accuracy).\nC\n DO 10 I = 2*K + 1, 2*K + N\n IWORK(I) = 0\n 10 CONTINUE\nC\nC Compute norms and initialize Q.\nC\n PNORM = 0\n PFREE = K\n DO 20 I = 1, K\n AIND = IWORK(MAPA+I)\n DWORK(I) = DLANHS( 'Frobenius', IN, A(ILO,ILO,AIND), LDA1,\n $ DWORK )\n J = 0\n IF ( LINIQ ) THEN\n J = I\n ELSE IF ( LPARQ ) THEN\n J = -QIND(I)\n END IF\n IF ( J.NE.0 )\n $ CALL DLASET( 'Full', N, N, ZERO, ONE, Q(1,1,J), LDQ1 )\n 20 CONTINUE\nC\nC Set Eigenvalues IHI+1:N.\nC\n DO 30 J = IHI + 1, N\n CALL MA01BD( BASE, LGBAS, K, S, A(J,J,1), LDA1*LDA2, ALPHAR(J),\n $ BETA(J), SCAL(J) )\n ALPHAI(J) = ZERO\n 30 CONTINUE\nC\nC If IHI < ILO, skip QZ steps.\nC\n IF ( IHI.LT.ILO )\n $ GO TO 550\nC\nC MAIN PERIODIC QZ ITERATION LOOP.\nC\nC Initialize dynamic indices.\nC\nC Eigenvalues ILAST+1:N have been found.\nC Column operations modify rows IFRSTM:whatever.\nC Row operations modify columns whatever:ILASTM.\nC\nC If only eigenvalues are being computed, then\nC IFRSTM is the row of the last splitting row above row ILAST;\nC this is always at least ILO.\nC IITER counts iterations since the last eigenvalue was found,\nC to tell when to use an observed zero or exceptional shift.\nC MAXIT is the maximum number of QZ sweeps allowed.\nC\n ILAST = IHI\n IF ( LSCHR ) THEN\n IFRSTM = 1\n ILASTM = N\n ELSE\n IFRSTM = ILO\n ILASTM = IHI\n END IF\n IITER = 0\n TITER = 0\n COUNT = 0\n COUNTE = 0\n MAXIT = 120 * IN\nC\n DO 540 JITER = 1, MAXIT\nC\nC Special Case: ILAST = ILO.\nC\n IF ( ILAST.EQ.ILO )\n $ GO TO 390\nC\nC **************************************************************\nC * CHECK FOR DEFLATION *\nC **************************************************************\nC\nC Test 1: Deflation in the Hessenberg matrix.\nC\n IF ( ADEFL )\n $ TOL = MAX( SAFMIN, DWORK(PNORM+1)*ULP )\n AIND = IWORK(MAPA+1)\n JLO = ILO\n DO 40 J = ILAST, ILO + 1, -1\n IF ( .NOT.ADEFL ) THEN\n TOL = ABS( A(J-1,J-1,AIND) ) + ABS( A(J,J,AIND) )\n IF ( TOL.EQ.ZERO )\n $ TOL = DLANHS( '1', J-ILO+1, A(ILO,ILO,AIND), LDA1,\n $ DWORK )\n TOL = MAX( ULP*TOL, SMLNUM )\n END IF\n IF ( ABS( A(J,J-1,AIND) ).LE.TOL ) THEN\n A(J,J-1,AIND) = ZERO\n JLO = J\n IF ( J.EQ.ILAST )\n $ GO TO 390\n GO TO 50\n END IF\n 40 CONTINUE\nC\n 50 CONTINUE\nC\nC Test 2: Deflation in the triangular matrices with index 1.\nC\n DO 70 LDEF = 2, K\n AIND = IWORK(MAPA+LDEF)\n IF ( S(AIND).EQ.SINV ) THEN\n IF ( ADEFL )\n $ TOL = MAX( SAFMIN, DWORK(PNORM+LDEF)*ULP )\n DO 60 J = ILAST, JLO, -1\n IF ( .NOT.ADEFL ) THEN\n IF ( J.EQ.ILAST ) THEN\n TOL = ABS( A(J-1,J,AIND) )\n ELSE IF ( J.EQ.JLO ) THEN\n TOL = ABS( A(J,J+1,AIND) )\n ELSE\n TOL = ABS( A(J-1,J,AIND) )\n $ + ABS( A(J,J+1,AIND) )\n END IF\n IF ( TOL.EQ.ZERO )\n $ TOL = DLANHS( '1', J-JLO+1, A(JLO,JLO,AIND),\n $ LDA1, DWORK )\n TOL = MAX( ULP*TOL, SMLNUM )\n END IF\n IF ( ABS( A(J,J,AIND) ).LE.TOL ) THEN\n A(J,J,AIND) = ZERO\n GO TO 170\n END IF\n 60 CONTINUE\n END IF\n 70 CONTINUE\nC\nC Test 3: Deflation in the triangular matrices with index -1.\nC\n DO 90 LDEF = 2, K\n AIND = IWORK(MAPA+LDEF)\n IF ( S(AIND).NE.SINV ) THEN\n IF ( ADEFL )\n $ TOL = MAX( SAFMIN, DWORK(PNORM+LDEF)*ULP )\n DO 80 J = ILAST, JLO, -1\n IF ( .NOT.ADEFL ) THEN\n IF ( J.EQ.ILAST ) THEN\n TOL = ABS( A(J-1,J,AIND) )\n ELSE IF ( J.EQ.JLO ) THEN\n TOL = ABS( A(J,J+1,AIND) )\n ELSE\n TOL = ABS( A(J-1,J,AIND) )\n $ + ABS( A(J,J+1,AIND) )\n END IF\n IF ( TOL.EQ.ZERO )\n $ TOL = DLANHS( '1', J-JLO+1, A(JLO,JLO,AIND),\n $ LDA1, DWORK )\n TOL = MAX( ULP*TOL, SMLNUM )\n END IF\n IF ( ABS( A(J,J,AIND) ).LE.TOL ) THEN\n A(J,J,AIND) = ZERO\n GO TO 320\n END IF\n 80 CONTINUE\n END IF\n 90 CONTINUE\nC\nC Test 4: Controlled zero shift.\nC\n IF ( ZITER.GE.7 .OR. ZITER.LT.0 ) THEN\nC\nC Make Hessenberg matrix upper triangular.\nC\n AIND = IWORK(MAPA+1)\n PDW = PFREE + 1\n DO 100 J = JLO, ILAST - 1\n TEMP = A(J,J,AIND)\n CALL DLARTG( TEMP, A(J+1,J,AIND), CS, SN, A(J,J,AIND) )\n A(J+1,J,AIND) = ZERO\n CALL DROT( ILASTM-J, A(J,J+1,AIND), LDA1,\n $ A(J+1,J+1,AIND), LDA1, CS, SN )\n DWORK(PDW) = CS\n DWORK(PDW+1) = SN\n PDW = PDW + 2\n 100 CONTINUE\n IF ( LCMPQ ) THEN\n QI = IWORK(MAPQ+1)\n ELSE IF ( LPARQ ) THEN\n QI = ABS( QIND(IWORK(MAPQ+1)) )\n END IF\n IF ( QI.NE.0 ) THEN\n PDW = PFREE + 1\n DO 110 J = JLO, ILAST - 1\n CS = DWORK(PDW)\n SN = DWORK(PDW+1)\n PDW = PDW + 2\n CALL DROT( N, Q(1,J,QI), 1, Q(1,J+1,QI), 1, CS, SN )\n 110 CONTINUE\n END IF\nC\nC Propagate transformations back to A_1.\nC\n DO 150 L = K, 2, -1\n AIND = IWORK(MAPA+L)\n PDW = PFREE + 1\n IF ( ADEFL )\n $ TOL = MAX( SAFMIN, DWORK(PNORM+L)*ULP )\n IF ( S(AIND).EQ.SINV ) THEN\n DO 120 J = JLO, ILAST - 1\n CS = DWORK(PDW)\n SN = DWORK(PDW+1)\n IF ( SN.NE.ZERO ) THEN\n CALL DROT( J+2-IFRSTM, A(IFRSTM,J,AIND), 1,\n $ A(IFRSTM,J+1,AIND), 1, CS, SN )\nC\nC Check for deflation.\nC\n IF ( .NOT.ADEFL ) THEN\n TOL = ABS( A(J,J,AIND) ) +\n $ ABS( A(J+1,J+1,AIND) )\n IF ( TOL.EQ.ZERO )\n $ TOL = DLANHS( '1', J-JLO+2,\n $ A(JLO,JLO,AIND), LDA1,\n $ DWORK )\n TOL = MAX( ULP*TOL, SMLNUM )\n END IF\n IF ( ABS( A(J+1,J,AIND) ).LE.TOL ) THEN\n CS = ONE\n SN = ZERO\n A(J+1,J,AIND) = ZERO\n END IF\n END IF\n IF ( SN.NE.ZERO ) THEN\n TEMP = A(J,J,AIND)\n CALL DLARTG( TEMP, A(J+1,J,AIND), CS, SN,\n $ A(J,J,AIND) )\n A(J+1,J,AIND) = ZERO\n CALL DROT( ILASTM-J, A(J,J+1,AIND), LDA1,\n $ A(J+1,J+1,AIND), LDA1, CS, SN )\n END IF\n DWORK(PDW) = CS\n DWORK(PDW+1) = SN\n PDW = PDW + 2\n 120 CONTINUE\n ELSE\n DO 130 J = JLO, ILAST - 1\n CS = DWORK(PDW)\n SN = DWORK(PDW+1)\n IF ( SN.NE.ZERO ) THEN\n CALL DROT( ILASTM-J+1, A(J,J,AIND), LDA1,\n $ A(J+1,J,AIND), LDA1, CS, SN )\nC\nC Check for deflation.\nC\n IF ( .NOT.ADEFL ) THEN\n TOL = ABS( A(J,J,AIND) ) +\n $ ABS( A(J+1,J+1,AIND) )\n IF ( TOL.EQ.ZERO )\n $ TOL = DLANHS( '1', J-JLO+2,\n $ A(JLO,JLO,AIND), LDA1,\n $ DWORK )\n TOL = MAX( ULP*TOL, SMLNUM )\n END IF\n IF ( ABS( A(J+1,J,AIND) ).LE.TOL ) THEN\n CS = ONE\n SN = ZERO\n A(J+1,J,AIND) = ZERO\n END IF\n END IF\n IF ( SN.NE.ZERO ) THEN\n TEMP = A(J+1,J+1,AIND)\n CALL DLARTG( TEMP, -A(J+1,J,AIND), CS, SN,\n $ A(J+1,J+1,AIND) )\n A(J+1,J,AIND) = ZERO\n CALL DROT( J+1-IFRSTM, A(IFRSTM,J,AIND), 1,\n $ A(IFRSTM,J+1,AIND), 1, CS, SN )\n END IF\n DWORK(PDW) = CS\n DWORK(PDW+1) = SN\n PDW = PDW + 2\n 130 CONTINUE\n END IF\n IF ( LCMPQ ) THEN\n QI = IWORK(MAPQ+L)\n ELSE IF ( LPARQ ) THEN\n QI = ABS( QIND(IWORK(MAPQ+L)) )\n END IF\n IF ( QI.NE.0 ) THEN\n PDW = PFREE + 1\n DO 140 J = JLO, ILAST - 1\n CS = DWORK(PDW)\n SN = DWORK(PDW+1)\n PDW = PDW + 2\n IF ( SN.NE.ZERO )\n $ CALL DROT( N, Q(1,J,QI), 1, Q(1,J+1,QI), 1, CS,\n $ SN )\n 140 CONTINUE\n END IF\n 150 CONTINUE\nC\nC Apply the transformations to the right hand side of the\nC Hessenberg factor.\nC\n AIND = IWORK(MAPA+1)\n PDW = PFREE + 1\n ZITER = 0\n DO 160 J = JLO, ILAST - 1\n CS = DWORK(PDW)\n SN = DWORK(PDW+1)\n PDW = PDW + 2\n IF ( SN.NE.ZERO ) THEN\n CALL DROT( J+2-IFRSTM, A(IFRSTM,J,AIND), 1,\n $ A(IFRSTM,J+1,AIND), 1, CS, SN )\n ELSE\n ZITER = -1\n END IF\n 160 CONTINUE\nC\nC No QZ iteration.\nC\n GO TO 530\n END IF\nC\nC **************************************************************\nC * HANDLE DEFLATIONS *\nC **************************************************************\nC\nC Case I: Deflation occurs in the Hessenberg matrix. The QZ\nC iteration is only applied to the JLO:ILAST part.\nC\n IFIRST = JLO\nC\nC Go to the periodic QZ steps.\nC\n GO TO 420\nC\nC Case II: Deflation occurs in a triangular matrix with index 1.\nC\nC Do an unshifted periodic QZ step.\nC\n 170 CONTINUE\n JDEF = J\n AIND = IWORK(MAPA+1)\n PDW = PFREE + 1\n DO 180 J = JLO, JDEF - 1\n TEMP = A(J,J,AIND)\n CALL DLARTG( TEMP, A(J+1,J,AIND), CS, SN, A(J,J,AIND) )\n A(J+1,J,AIND) = ZERO\n CALL DROT( ILASTM-J, A(J,J+1,AIND), LDA1, A(J+1,J+1,AIND),\n $ LDA1, CS, SN )\n DWORK(PDW) = CS\n DWORK(PDW+1) = SN\n PDW = PDW + 2\n 180 CONTINUE\n IF ( LCMPQ ) THEN\n QI = IWORK(MAPQ+1)\n ELSE IF ( LPARQ ) THEN\n QI = ABS( QIND(IWORK(MAPQ+1)) )\n END IF\n IF ( QI.NE.0 ) THEN\n PDW = PFREE + 1\n DO 190 J = JLO, JDEF - 1\n CS = DWORK(PDW)\n SN = DWORK(PDW+1)\n PDW = PDW + 2\n CALL DROT( N, Q(1,J,QI), 1, Q(1,J+1,QI), 1, CS, SN )\n 190 CONTINUE\n END IF\nC\nC Propagate the transformations through the triangular matrices.\nC Due to the zero element on the diagonal of the LDEF-th factor,\nC the number of transformations drops by one.\nC\n DO 230 L = K, 2, -1\n AIND = IWORK(MAPA+L)\n IF ( L.LT.LDEF ) THEN\n NTRA = JDEF - 2\n ELSE\n NTRA = JDEF - 1\n END IF\n PDW = PFREE + 1\n IF ( S(AIND).EQ.SINV ) THEN\n DO 200 J = JLO, NTRA\n CS = DWORK(PDW)\n SN = DWORK(PDW+1)\n CALL DROT( J+2-IFRSTM, A(IFRSTM,J,AIND), 1,\n $ A(IFRSTM,J+1,AIND), 1, CS, SN )\n TEMP = A(J,J,AIND)\n CALL DLARTG( TEMP, A(J+1,J,AIND), CS, SN,\n $ A(J,J,AIND) )\n A(J+1,J,AIND) = ZERO\n CALL DROT( ILASTM-J, A(J,J+1,AIND), LDA1,\n $ A(J+1,J+1,AIND), LDA1, CS, SN )\n DWORK(PDW) = CS\n DWORK(PDW+1) = SN\n PDW = PDW + 2\n 200 CONTINUE\n ELSE\n DO 210 J = JLO, NTRA\n CS = DWORK(PDW)\n SN = DWORK(PDW+1)\n CALL DROT( ILASTM-J+1, A(J,J,AIND), LDA1,\n $ A(J+1,J,AIND), LDA1, CS, SN )\n TEMP = A(J+1,J+1,AIND)\n CALL DLARTG( TEMP, -A(J+1,J,AIND), CS, SN,\n $ A(J+1,J+1,AIND) )\n A(J+1,J,AIND) = ZERO\n CALL DROT( J+1-IFRSTM, A(IFRSTM,J,AIND), 1,\n $ A(IFRSTM,J+1,AIND), 1, CS, SN )\n DWORK(PDW) = CS\n DWORK(PDW+1) = SN\n PDW = PDW + 2\n 210 CONTINUE\n END IF\n IF ( LCMPQ ) THEN\n QI = IWORK(MAPQ+L)\n ELSE IF ( LPARQ ) THEN\n QI = ABS( QIND(IWORK(MAPQ+L)) )\n END IF\n IF ( QI.NE.0 ) THEN\n PDW = PFREE + 1\n DO 220 J = JLO, NTRA\n CS = DWORK(PDW)\n SN = DWORK(PDW+1)\n PDW = PDW + 2\n CALL DROT( N, Q(1,J,QI), 1, Q(1,J+1,QI), 1, CS, SN )\n 220 CONTINUE\n END IF\n 230 CONTINUE\nC\nC Apply the transformations to the right hand side of the\nC Hessenberg factor.\nC\n AIND = IWORK(MAPA+1)\n PDW = PFREE + 1\n DO 240 J = JLO, JDEF - 2\n CS = DWORK(PDW)\n SN = DWORK(PDW+1)\n PDW = PDW + 2\n CALL DROT( J+2-IFRSTM, A(IFRSTM,J,AIND), 1,\n $ A(IFRSTM,J+1,AIND), 1, CS, SN )\n 240 CONTINUE\nC\nC Do an unshifted periodic QZ step.\nC\n PDW = PFREE + 1\n DO 250 J = ILAST, JDEF + 1, -1\n TEMP = A(J,J,AIND)\n CALL DLARTG( TEMP, -A(J,J-1,AIND), CS, SN, A(J,J,AIND) )\n A(J,J-1,AIND) = ZERO\n CALL DROT( J-IFRSTM, A(IFRSTM,J-1,AIND), 1,\n $ A(IFRSTM,J,AIND), 1, CS, SN )\n DWORK(PDW) = CS\n DWORK(PDW+1) = SN\n PDW = PDW + 2\n 250 CONTINUE\n IF ( LCMPQ ) THEN\n QI = IWORK(MAPQ+2)\n ELSE IF ( LPARQ ) THEN\n QI = ABS( QIND(IWORK(MAPQ+2)) )\n END IF\n IF ( QI.NE.0 ) THEN\n PDW = PFREE + 1\n DO 260 J = ILAST, JDEF + 1, -1\n CS = DWORK(PDW)\n SN = DWORK(PDW+1)\n PDW = PDW + 2\n CALL DROT( N, Q(1,J-1,QI), 1, Q(1,J,QI), 1, CS, SN )\n 260 CONTINUE\n END IF\nC\nC Propagate the transformations through the triangular matrices.\nC\n DO 300 L = 2, K\n AIND = IWORK(MAPA+L)\n IF ( L.GT.LDEF ) THEN\n NTRA = JDEF + 2\n ELSE\n NTRA = JDEF + 1\n END IF\n PDW = PFREE + 1\n IF ( S(AIND).NE.SINV ) THEN\n DO 270 J = ILAST, NTRA, -1\n CS = DWORK(PDW)\n SN = DWORK(PDW+1)\n CALL DROT( J+1-IFRSTM, A(IFRSTM,J-1,AIND), 1,\n $ A(IFRSTM,J,AIND), 1, CS, SN )\n TEMP = A(J-1,J-1,AIND)\n CALL DLARTG( TEMP, A(J,J-1,AIND), CS, SN,\n $ A(J-1,J-1,AIND) )\n A(J,J-1,AIND) = ZERO\n CALL DROT( ILASTM-J+1, A(J-1,J,AIND), LDA1,\n $ A(J,J,AIND), LDA1, CS, SN )\n DWORK(PDW) = CS\n DWORK(PDW+1) = SN\n PDW = PDW + 2\n 270 CONTINUE\n ELSE\n DO 280 J = ILAST, NTRA, -1\n CS = DWORK(PDW)\n SN = DWORK(PDW+1)\n CALL DROT( ILASTM-J+2, A(J-1,J-1,AIND), LDA1,\n $ A(J,J-1,AIND), LDA1, CS, SN )\n TEMP = A(J,J,AIND)\n CALL DLARTG( TEMP, -A(J,J-1,AIND), CS, SN,\n $ A(J,J,AIND) )\n A(J,J-1,AIND) = ZERO\n CALL DROT( J-IFRSTM, A(IFRSTM,J-1,AIND), 1,\n $ A(IFRSTM,J,AIND), 1, CS, SN )\n DWORK(PDW) = CS\n DWORK(PDW+1) = SN\n PDW = PDW + 2\n 280 CONTINUE\n END IF\n LM = MOD( L, K ) + 1\n IF ( LCMPQ ) THEN\n QI = IWORK(MAPQ+LM)\n ELSE IF ( LPARQ ) THEN\n QI = ABS( QIND(IWORK(MAPQ+LM)) )\n END IF\n IF ( QI.NE.0 ) THEN\n PDW = PFREE + 1\n DO 290 J = ILAST, NTRA, -1\n CS = DWORK(PDW)\n SN = DWORK(PDW+1)\n PDW = PDW + 2\n CALL DROT( N, Q(1,J-1,QI), 1, Q(1,J,QI), 1, CS, SN )\n 290 CONTINUE\n END IF\n 300 CONTINUE\nC\nC Apply the transformations to the left hand side of the\nC Hessenberg factor.\nC\n AIND = IWORK(MAPA+1)\n PDW = PFREE + 1\n DO 310 J = ILAST, JDEF + 2, -1\n CS = DWORK(PDW)\n SN = DWORK(PDW+1)\n PDW = PDW + 2\n CALL DROT( ILASTM-J+2, A(J-1,J-1,AIND), LDA1, A(J,J-1,AIND),\n $ LDA1, CS, SN )\n 310 CONTINUE\nC\nC No QZ iteration.\nC\n GO TO 530\nC\nC Case III: Deflation occurs in a triangular matrix with\nC index -1.\nC\n 320 CONTINUE\n JDEF = J\n IF ( JDEF.GT.( ( ILAST - JLO + 1 )/2 ) ) THEN\nC\nC Chase the zero downwards to the last position.\nC\n DO 340 J1 = JDEF, ILAST - 1\n J = J1\n AIND = IWORK(MAPA+LDEF)\n TEMP = A(J,J+1,AIND)\n CALL DLARTG( TEMP, A(J+1,J+1,AIND), CS, SN,\n $ A(J,J+1,AIND) )\n A(J+1,J+1,AIND) = ZERO\n CALL DROT( ILASTM-J-1, A(J,J+2,AIND), LDA1,\n $ A(J+1,J+2,AIND), LDA1, CS, SN )\n LM = MOD( LDEF, K ) + 1\n IF ( LCMPQ ) THEN\n QI = IWORK(MAPQ+LM)\n ELSE IF ( LPARQ ) THEN\n QI = ABS( QIND(IWORK(MAPQ+LM)) )\n END IF\n IF ( QI.NE.0 )\n $ CALL DROT( N, Q(1,J,QI), 1, Q(1,J+1,QI), 1, CS, SN )\n DO 330 L = 1, K - 1\n AIND = IWORK(MAPA+LM)\n IF ( LM.EQ.1 ) THEN\n CALL DROT( ILASTM-J+2, A(J,J-1,AIND), LDA1,\n $ A(J+1,J-1,AIND), LDA1, CS, SN )\n TEMP = A(J+1,J,AIND)\n CALL DLARTG( TEMP, -A(J+1,J-1,AIND), CS, SN,\n $ A(J+1,J,AIND) )\n A(J+1,J-1,AIND) = ZERO\n CALL DROT( J-IFRSTM+1, A(IFRSTM,J-1,AIND), 1,\n $ A(IFRSTM,J,AIND), 1, CS, SN )\n J = J - 1\n ELSE IF ( S(AIND).EQ.SINV ) THEN\n CALL DROT( ILASTM-J+1, A(J,J,AIND), LDA1,\n $ A(J+1,J,AIND), LDA1, CS, SN )\n TEMP = A(J+1,J+1,AIND)\n CALL DLARTG( TEMP, -A(J+1,J,AIND), CS, SN,\n $ A(J+1,J+1,AIND) )\n A(J+1,J,AIND) = ZERO\n CALL DROT( J-IFRSTM+1, A(IFRSTM,J,AIND), 1,\n $ A(IFRSTM,J+1,AIND), 1, CS, SN )\n ELSE\n CALL DROT( J-IFRSTM+2, A(IFRSTM,J,AIND), 1,\n $ A(IFRSTM,J+1,AIND), 1, CS, SN )\n TEMP = A(J,J,AIND)\n CALL DLARTG( TEMP, A(J+1,J,AIND), CS, SN,\n $ A(J,J,AIND) )\n A(J+1,J,AIND) = ZERO\n CALL DROT( ILASTM-J, A(J,J+1,AIND), LDA1,\n $ A(J+1,J+1,AIND), LDA1, CS, SN )\n END IF\n LM = MOD( LM, K ) + 1\n IF ( LCMPQ ) THEN\n QI = IWORK(MAPQ+LM)\n ELSE IF ( LPARQ ) THEN\n QI = ABS( QIND(IWORK(MAPQ+LM)) )\n END IF\n IF ( QI.NE.0 )\n $ CALL DROT( N, Q(1,J,QI), 1, Q(1,J+1,QI), 1, CS,\n $ SN )\n 330 CONTINUE\n AIND = IWORK(MAPA+LDEF)\n CALL DROT( J-IFRSTM+1, A(IFRSTM,J,AIND), 1,\n $ A(IFRSTM,J+1,AIND), 1, CS, SN )\n 340 CONTINUE\nC\nC Deflate the last element in the Hessenberg matrix.\nC\n AIND = IWORK(MAPA+1)\n J = ILAST\n TEMP = A(J,J,AIND)\n CALL DLARTG( TEMP, -A(J,J-1,AIND), CS, SN, A(J,J,AIND) )\n A(J,J-1,AIND) = ZERO\n CALL DROT( J-IFRSTM, A(IFRSTM,J-1,AIND), 1,\n $ A(IFRSTM,J,AIND), 1, CS, SN )\n IF ( LCMPQ ) THEN\n QI = IWORK(MAPQ+2)\n ELSE IF ( LPARQ ) THEN\n QI = ABS( QIND(IWORK(MAPQ+2)) )\n END IF\n IF ( QI.NE.0 )\n $ CALL DROT( N, Q(1,J-1,QI), 1, Q(1,J,QI), 1, CS, SN )\n DO 350 L = 2, LDEF - 1\n AIND = IWORK(MAPA+L)\n IF ( S(AIND).NE.SINV ) THEN\n CALL DROT( J+1-IFRSTM, A(IFRSTM,J-1,AIND), 1,\n $ A(IFRSTM,J,AIND), 1, CS, SN )\n TEMP = A(J-1,J-1,AIND)\n CALL DLARTG( TEMP, A(J,J-1,AIND), CS, SN,\n $ A(J-1,J-1,AIND) )\n A(J,J-1,AIND) = ZERO\n CALL DROT( ILASTM-J+1, A(J-1,J,AIND), LDA1,\n $ A(J,J,AIND), LDA1, CS, SN )\n ELSE\n CALL DROT( ILASTM-J+2, A(J-1,J-1,AIND), LDA1,\n $ A(J,J-1,AIND), LDA1, CS, SN )\n TEMP = A(J,J,AIND)\n CALL DLARTG( TEMP, -A(J,J-1,AIND), CS, SN,\n $ A(J,J,AIND) )\n A(J,J-1,AIND) = ZERO\n CALL DROT( J-IFRSTM, A(IFRSTM,J-1,AIND), 1,\n $ A(IFRSTM,J,AIND), 1, CS, SN )\n END IF\n LM = L + 1\n IF ( LCMPQ ) THEN\n QI = IWORK(MAPQ+LM)\n ELSE IF ( LPARQ ) THEN\n QI = ABS( QIND(IWORK(MAPQ+LM)) )\n END IF\n IF ( QI.NE.0 )\n $ CALL DROT( N, Q(1,J-1,QI), 1, Q(1,J,QI), 1, CS, SN )\n 350 CONTINUE\n AIND = IWORK(MAPA+LDEF)\n CALL DROT( J+1-IFRSTM, A(IFRSTM,J-1,AIND), 1,\n $ A(IFRSTM,J,AIND), 1, CS, SN )\n ELSE\nC\nC Chase the zero upwards to the first position.\nC\n DO 370 J1 = JDEF, JLO + 1, -1\n J = J1\n AIND = IWORK(MAPA+LDEF)\n TEMP = A(J-1,J,AIND)\n CALL DLARTG( TEMP, -A(J-1,J-1,AIND), CS, SN,\n $ A(J-1,J,AIND) )\n A(J-1,J-1,AIND) = ZERO\n CALL DROT( J-IFRSTM-1, A(IFRSTM,J-1,AIND), 1,\n $ A(IFRSTM,J,AIND), 1, CS, SN )\n IF ( LCMPQ ) THEN\n QI = IWORK(MAPQ+LDEF)\n ELSE IF ( LPARQ ) THEN\n QI = ABS( QIND(IWORK(MAPQ+LDEF)) )\n END IF\n IF ( QI.NE.0 )\n $ CALL DROT( N, Q(1,J-1,QI), 1, Q(1,J,QI), 1, CS, SN )\n LM = LDEF - 1\n DO 360 L = 1, K - 1\n AIND = IWORK(MAPA+LM)\n IF ( LM.EQ.1 ) THEN\n CALL DROT( J-IFRSTM+2, A(IFRSTM,J-1,AIND), 1,\n $ A(IFRSTM,J,AIND), 1, CS, SN )\n TEMP = A(J,J-1,AIND)\n CALL DLARTG( TEMP, A(J+1,J-1,AIND), CS, SN,\n $ A(J,J-1,AIND) )\n A(J+1,J-1,AIND) = ZERO\n CALL DROT( ILASTM-J+1, A(J,J,AIND), LDA1,\n $ A(J+1,J,AIND), LDA1, CS, SN )\n J = J + 1\n ELSE IF ( S(AIND).NE.SINV ) THEN\n CALL DROT( ILASTM-J+2, A(J-1,J-1,AIND), LDA1,\n $ A(J,J-1,AIND), LDA1, CS, SN )\n TEMP = A(J,J,AIND)\n CALL DLARTG( TEMP, -A(J,J-1,AIND), CS, SN,\n $ A(J,J,AIND) )\n A(J,J-1,AIND) = ZERO\n CALL DROT( J-IFRSTM, A(IFRSTM,J-1,AIND), 1,\n $ A(IFRSTM,J,AIND), 1, CS, SN )\n ELSE\n CALL DROT( J-IFRSTM+1, A(IFRSTM,J-1,AIND), 1,\n $ A(IFRSTM,J,AIND), 1, CS, SN )\n TEMP = A(J-1,J-1,AIND)\n CALL DLARTG( TEMP, A(J,J-1,AIND), CS, SN,\n $ A(J-1,J-1,AIND) )\n A(J,J-1,AIND) = ZERO\n CALL DROT( ILASTM-J+1, A(J-1,J,AIND), LDA1,\n $ A(J,J,AIND), LDA1, CS, SN )\n END IF\n IF ( LCMPQ ) THEN\n QI = IWORK(MAPQ+LM)\n ELSE IF ( LPARQ ) THEN\n QI = ABS( QIND(IWORK(MAPQ+LM)) )\n END IF\n IF ( QI.NE.0 )\n $ CALL DROT( N, Q(1,J-1,QI), 1, Q(1,J,QI), 1, CS,\n $ SN )\n LM = LM - 1\n IF ( LM.LE.0 )\n $ LM = K\n 360 CONTINUE\n AIND = IWORK(MAPA+LDEF)\n CALL DROT( ILASTM-J+1, A(J-1,J,AIND), LDA1, A(J,J,AIND),\n $ LDA1, CS, SN )\n 370 CONTINUE\nC\nC Deflate the first element in the Hessenberg matrix.\nC\n AIND = IWORK(MAPA+1)\n J = JLO\n TEMP = A(J,J,AIND)\n CALL DLARTG( TEMP, A(J+1,J,AIND), CS, SN, A(J,J,AIND) )\n A(J+1,J,AIND) = ZERO\n CALL DROT( ILASTM-J, A(J,J+1,AIND), LDA1, A(J+1,J+1,AIND),\n $ LDA1, CS, SN )\n IF ( LCMPQ ) THEN\n QI = IWORK(MAPQ+1)\n ELSE IF ( LPARQ ) THEN\n QI = ABS( QIND(IWORK(MAPQ+1)) )\n END IF\n IF ( QI.NE.0 )\n $ CALL DROT( N, Q(1,J,QI), 1, Q(1,J+1,QI), 1, CS, SN )\n DO 380 L = K, LDEF + 1, -1\n AIND = IWORK(MAPA+L)\n IF ( S(AIND).EQ.SINV ) THEN\n CALL DROT( J+2-IFRSTM, A(IFRSTM,J,AIND), 1,\n $ A(IFRSTM,J+1,AIND), 1, CS, SN )\n TEMP = A(J,J,AIND)\n CALL DLARTG( TEMP, A(J+1,J,AIND), CS, SN,\n $ A(J,J,AIND) )\n A(J+1,J,AIND) = ZERO\n CALL DROT( ILASTM-J, A(J,J+1,AIND), LDA1,\n $ A(J+1,J+1,AIND), LDA1, CS, SN )\n ELSE\n CALL DROT( ILASTM-J+1, A(J,J,AIND), LDA1,\n $ A(J+1,J,AIND), LDA1, CS, SN )\n TEMP = A(J+1,J+1,AIND)\n CALL DLARTG( TEMP, -A(J+1,J,AIND), CS, SN,\n $ A(J+1,J+1,AIND) )\n A(J+1,J,AIND) = ZERO\n CALL DROT( J+1-IFRSTM, A(IFRSTM,J,AIND), 1,\n $ A(IFRSTM,J+1,AIND), 1, CS, SN )\n END IF\n IF ( LCMPQ ) THEN\n QI = IWORK(MAPQ+L)\n ELSE IF ( LPARQ ) THEN\n QI = ABS( QIND(IWORK(MAPQ+L)) )\n END IF\n IF ( QI.NE.0 )\n $ CALL DROT( N, Q(1,J,QI), 1, Q(1,J+1,QI), 1, CS, SN )\n 380 CONTINUE\n AIND = IWORK(MAPA+LDEF)\n CALL DROT( ILASTM-J, A(J,J+1,AIND), LDA1, A(J+1,J+1,AIND),\n $ LDA1, CS, SN )\n END IF\nC\nC No QZ iteration.\nC\n GO TO 530\nC\nC Special case: A 1x1 block splits off at the bottom.\nC\n 390 CONTINUE\n CALL MA01BD( BASE, LGBAS, K, S, A(ILAST,ILAST,1), LDA1*LDA2,\n $ ALPHAR(ILAST), BETA(ILAST), SCAL(ILAST) )\n ALPHAI(ILAST) = ZERO\nC\nC Check for possible loss of accuracy.\nC\n IF ( BETA(ILAST).NE.ZERO ) THEN\n DO 400 L = 1, K\n AIND = IWORK(MAPA+L)\n TEMP = A(ILAST,ILAST,AIND)\n IF ( TEMP.NE.ZERO ) THEN\n IF ( ABS( TEMP ).LT.DWORK(L)*TOLL ) THEN\n IWARN = N + 1\n IWORK(2*K+ILAST) = ILAST\n GO TO 410\n END IF\n END IF\n 400 CONTINUE\n END IF\nC\nC Go to next block - exit if finished.\nC\n 410 CONTINUE\n ILAST = ILAST - 1\n IF ( ILAST.LT.ILO )\n $ GO TO 550\nC\nC Reset iteration counters.\nC\n IITER = 0\n TITER = 0\n COUNT = 0\n COUNTE = 0\n IF ( ZITER.NE.-1 )\n $ ZITER = 0\n IF ( .NOT.LSCHR ) THEN\n ILASTM = ILAST\n IF ( IFRSTM.GT.ILAST )\n $ IFRSTM = ILO\n END IF\nC\nC No QZ iteration.\nC\n GO TO 530\nC\nC **************************************************************\nC * PERIODIC QZ STEP *\nC **************************************************************\nC\nC It is assumed that IFIRST < ILAST.\nC\n 420 CONTINUE\nC\n IITER = IITER + 1\n ZITER = ZITER + 1\n IF( .NOT.LSCHR )\n $ IFRSTM = IFIRST\n IF ( IFIRST+1.EQ.ILAST ) THEN\nC\nC Special case -- 2x2 block.\nC\n J = ILAST - 1\n IF ( TITER.LT.2 ) THEN\n TITER = TITER + 1\nC\nC Try to deflate the 2-by-2 problem.\nC\n PDW = PFREE + 1\n DO 430 L = 1, K\n DWORK(PDW ) = A(J,J,L)\n DWORK(PDW+1) = A(J+1,J,L)\n DWORK(PDW+2) = A(J,J+1,L)\n DWORK(PDW+3) = A(J+1,J+1,L)\n PDW = PDW + 4\n 430 CONTINUE\n IF ( SINV.LT.0 ) THEN\n I = IWORK(MAPQ+1)\n IWORK(MAPQ+1) = IWORK(MAPA+1)\n END IF\n CALL MB03BF( K, IWORK(MAPH), S, SINV, DWORK(PFREE+1),\n $ 2, 2, ULP )\n IF ( SINV.LT.0 )\n $ IWORK(MAPQ+1) = I\n I = PFREE + 4*( H - 1 )\n IF ( ABS( DWORK(I+2) ).LT.\n $ ULP*( MAX( ABS( DWORK(I+1) ), ABS( DWORK(I+3) ),\n $ ABS( DWORK(I+4) ) ) ) ) THEN\nC\nC Construct a perfect shift polynomial. This may fail,\nC so we try it twice (indicated by TITER).\nC\n CS1 = ONE\n SN1 = ONE\n DO 440 L = K, 2, -1\n AIND = IWORK(MAPA+L)\n TEMP = DWORK(PFREE+AIND*4)\n IF ( S(AIND).EQ.SINV ) THEN\n CALL DLARTG( CS1*A(J,J,AIND), SN1*TEMP, CS1,\n $ SN1, TEMP )\n ELSE\n CALL DLARTG( CS1*TEMP, SN1*A(J,J,AIND), CS1,\n $ SN1, TEMP )\n END IF\n 440 CONTINUE\n AIND = IWORK(MAPA+1)\n TEMP = DWORK(PFREE+AIND*4)\n CALL DLARTG( A(J,J,AIND)*CS1-TEMP*SN1,\n $ A(J+1,J,AIND)*CS1, CS1, SN1, TEMP )\n GO TO 510\n END IF\n END IF\nC\nC Looks like a complex block.\nC 1. Compute the product SVD of the triangular matrices\nC (optionally).\nC\n IF ( LSVD ) THEN\n CALL MB03BC( K, IWORK(MAPA+1), S, SINV, A(J,J,1), LDA1,\n $ LDA2, MACPAR, DWORK(PFREE+1),\n $ DWORK(PFREE+K+1), DWORK(PFREE+2*K+1) )\nC\nC Update factors and transformations.\nC\n AIND = IWORK(MAPA+1)\n CS2 = DWORK(PFREE+1)\n SN2 = DWORK(PFREE+K+1)\n CALL DROT( ILASTM-IFRSTM+1, A(IFRSTM,J,AIND), 1,\n $ A(IFRSTM,J+1,AIND), 1, CS2, SN2 )\n DO 450 L = 2, K\n AIND = IWORK(MAPA+L)\n IF ( LCMPQ ) THEN\n QI = IWORK(MAPQ+L)\n ELSE IF ( LPARQ ) THEN\n QI = ABS( QIND(IWORK(MAPQ+L)) )\n END IF\n IF ( QI.NE.0 )\n $ CALL DROT( N, Q(1,J,QI), 1, Q(1,J+1,QI), 1, CS2,\n $ SN2 )\n CS1 = CS2\n SN1 = SN2\n CS2 = DWORK(PFREE+L)\n SN2 = DWORK(PFREE+K+L)\n IF (S(AIND).EQ.SINV) THEN\n CALL DROT( ILASTM-J-1, A(J,J+2,AIND), LDA1,\n $ A(J+1,J+2,AIND), LDA1, CS1, SN1 )\n CALL DROT( J-IFRSTM, A(IFRSTM,J,AIND), 1,\n $ A(IFRSTM,J+1,AIND), 1, CS2, SN2 )\n ELSE\n CALL DROT( ILASTM-J-1, A(J,J+2,AIND), LDA1,\n $ A(J+1,J+2,AIND), LDA1, CS2, SN2 )\n CALL DROT( J-IFRSTM, A(IFRSTM,J,AIND), 1,\n $ A(IFRSTM,J+1,AIND), 1, CS1, SN1 )\n END IF\n 450 CONTINUE\n IF ( LCMPQ ) THEN\n QI = IWORK(MAPQ+1)\n ELSE IF ( LPARQ ) THEN\n QI = ABS( QIND(IWORK(MAPQ+1)) )\n END IF\n IF ( QI.NE.0 )\n $ CALL DROT( N, Q(1,J,QI), 1, Q(1,J+1,QI), 1, CS2, SN2 )\n AIND = IWORK(MAPA+1)\n CALL DROT( ILASTM-J+1, A(J,J,AIND), LDA1,\n $ A(J+1,J,AIND), LDA1, CS2, SN2 )\n END IF\nC\nC 2. Compute complex eigenvalues.\nC\n CALL MB03BB( BASE, LGBAS, ULP, K, IWORK(MAPA+1), S, SINV,\n $ A(J,J,1), LDA1, LDA2, ALPHAR(J), ALPHAI(J),\n $ BETA(J), SCAL(J), DWORK(PFREE+1), IERR )\n IF ( IERR.EQ.1 ) THEN\nC\nC The single shift periodic QZ did not converge, set\nC IWARN = J to indicate that the eigenvalues are not\nC assigned.\nC\n IWARN = MAX( J, IWARN )\n ELSE IF ( IERR.EQ.2 ) THEN\nC\nC Some computed eigenvalues might be inaccurate.\nC\n IF ( IWARN.EQ.0 )\n $ IWARN = N\n END IF\nC\nC Check for real eigenvalues and possible loss of accuracy.\nC Also, set zero or infinite eigenvalues where appropriate.\nC\n DO 460 L = 1, K\n AIND = IWORK(MAPA+L)\n IF ( ALPHAI(J).EQ.ZERO .AND. BETA(J).NE.ZERO ) THEN\n IF ( ABS( A(J,J,AIND) ).LT.DWORK(L)*TOLL ) THEN\n IWARN = N + 1\n IWORK(2*K+J) = -J\n GO TO 470\n END IF\n ELSE\n A1 = A(J,J,AIND)\n A3 = A(J,J+1,AIND)\n A4 = A(J+1,J+1,AIND)\n NRM = DLAPY3( A1, A3, A4 )\n IF ( L.EQ.IWORK(MAPA+1) ) THEN\n A2 = A(J+1,J,L)\n NRM = DLAPY2( NRM, A2 )\n END IF\n SDET = ( MAX( ABS( A1 ), ABS( A4 ) )/NRM )\n $ *MIN( ABS( A1 ), ABS( A4 ) )*\n $ SIGN( ONE, A1 )*SIGN( ONE, A4 )\n IF ( L.EQ.IWORK(MAPA+1) )\n $ SDET = SDET - ( MAX( ABS( A2 ), ABS( A3 ) )/NRM )\n $ *MIN( ABS( A2 ), ABS( A3 ) )*\n $ SIGN( ONE, A2 )*SIGN( ONE, A3 )\n IF ( ABS( SDET ).LT.DWORK(L)*TOLL ) THEN\nC\nC Make a more accurate singularity test using SVD.\nC\n IF ( L.EQ.IWORK(MAPA+1) ) THEN\n IF ( ABS( A1 ).GE.ABS( A4 ) ) THEN\n CALL DLARTG( A1, A2, CS, SN, TEMP )\n A1 = TEMP\n TEMP = CS*A3 + SN*A4\n A4 = CS*A4 - SN*A3\n A3 = TEMP\n ELSE\n CALL DLARTG( A4, A2, CS, SN, TEMP )\n A4 = TEMP\n TEMP = CS*A3 + SN*A1\n A1 = CS*A1 - SN*A3\n A3 = TEMP\n END IF\n END IF\n CALL DLAS2( A1, A3, A4, SVMN, TEMP )\n IF ( SVMN.LT.DWORK(L)*TOLL ) THEN\n IWARN = N + 1\n IWORK(2*K+J) = -J\n GO TO 470\n END IF\n END IF\n END IF\n 460 CONTINUE\nC\nC Go to next block and reset counters.\nC\n 470 CONTINUE\n ILAST = IFIRST - 1\n IF ( ILAST.LT.ILO )\n $ GO TO 550\n IITER = 0\n TITER = 0\n COUNT = 0\n COUNTE = 0\n IF ( ZITER.NE.-1 )\n $ ZITER = 0\n IF ( .NOT.LSCHR ) THEN\n ILASTM = ILAST\n IF ( IFRSTM.GT.ILAST )\n $ IFRSTM = ILO\n END IF\n GO TO 530\n END IF\nC\nC Now, it is assumed that ILAST-IFIRST+1 >= 3.\nC\n IF ( COUNT.LT.NITER ) THEN\nC\nC Use the normal periodic QZ step routine.\nC Note that the pointer to IWORK is increased by 1.\nC The fact that, for SINV = 1, IWORK(MAPQ+1) = IWORK(MAPA+1)\nC is used.\nC\n COUNT = COUNT + 1\n IF ( SINV.LT.0 ) THEN\n I = IWORK(MAPQ+1)\n IWORK(MAPQ+1) = IWORK(MAPA+1)\n END IF\n CALL MB03AF( 'Double', K, ILAST-IFIRST+1, IWORK(MAPH), S,\n $ SINV, A(IFIRST,IFIRST,1), LDA1, LDA2, CS1,\n $ SN1, CS2, SN2 )\n IF ( SINV.LT.0 )\n $ IWORK(MAPQ+1) = I\n ELSE IF ( COUNTE.LT.MCOUNT ) THEN\nC\nC Compute the two trailing eigenvalues for finding the shifts.\nC Deal with special case of infinite eigenvalues, if needed.\nC\n I = ILAST - 1\n IF ( SINV.LT.0 ) THEN\n AIND = IWORK(MAPA+1)\n A1 = A(I,I,AIND)\n A2 = A(I+1,I,AIND)\n A3 = A(I,I+1,AIND)\n A4 = A(I+1,I+1,AIND)\n NRM = DLANHS( 'Frobenius', 2, A(ILO,ILO,AIND), LDA1,\n $ DWORK )\n SDET = ( MAX( ABS( A1 ), ABS( A4 ) )/NRM )\n $ *MIN( ABS( A1 ), ABS( A4 ) )*\n $ SIGN( ONE, A1 )*SIGN( ONE, A4 ) -\n $ ( MAX( ABS( A2 ), ABS( A3 ) )/NRM )\n $ *MIN( ABS( A2 ), ABS( A3 ) )*\n $ SIGN( ONE, A2 )*SIGN( ONE, A3 )\n ISINF = ABS( SDET ).LT.DWORK(AIND)*TOLL\n IF ( ISINF ) THEN\n ALPHAR(I) = ONE/DWORK(PNORM+1)\n ALPHAR(ILAST) = ONE/DWORK(PNORM+1)\n SCAL(I) = 1\n SCAL(ILAST) = 1\n END IF\n IERR = 0\n ELSE\n ISINF = .FALSE.\n END IF\n IF ( .NOT.ISINF ) THEN\n CALL MB03BB( BASE, LGBAS, ULP, K, IWORK(MAPA+1), S, SINV,\n $ A(I,I,1), LDA1, LDA2, ALPHAR(I), ALPHAI(I),\n $ BETA(I), SCAL(I), DWORK(PFREE+1), IERR )\n IF ( SINV.LT.0 ) THEN\nC\nC Use the reciprocals of the eigenvalues returned above.\nC\n IF ( ALPHAI(I).EQ.ZERO ) THEN\n ALPHAR(I) = SIGN( ONE, ALPHAR(I) )/\n $ MAX( SAFMIN, ABS( ALPHAR(I) ) )\n ALPHAR(ILAST) = SIGN( ONE, ALPHAR(ILAST) )/\n $ MAX( SAFMIN, ABS( ALPHAR(ILAST) ) )\n SCAL(I) = -SCAL(I)\n SCAL(ILAST) = -SCAL(ILAST)\n ELSE\n CALL DLADIV( ONE, ZERO, ALPHAR(ILAST),\n $ -ALPHAI(ILAST), ALPHAR(I), ALPHAI(I) )\n SCAL(I) = -SCAL(I)\n END IF\n END IF\nC\n IF ( IERR.NE.0 ) THEN\nC\nC Try an exceptional transformation if MB03BB does not\nC converge on some special cases.\nC\n TEMP2 = BASE**SCAL(I)\n IF ( ALPHAI(I).NE.ZERO ) THEN\n TEMP = ( ABS( ALPHAR(I) ) + ABS( ALPHAI(I) ) )*\n $ TEMP2\n ELSE\n TEMP = MAX( ABS( ALPHAR(ILAST) )*BASE**SCAL(ILAST),\n $ ABS( ALPHAR(I) )*TEMP2 )\n END IF\n IF ( TEMP.LE.SQRT( ULP )*DWORK(PNORM+1) ) THEN\n ALPHAR(I) = DWORK(PNORM+1)\n SCAL(I) = 1\n ALPHAR(ILAST) = DWORK(PNORM+1)\n SCAL(ILAST) = 1\n IERR = 0\n END IF\n END IF\n END IF\nC\n IF ( IERR.NE.0 ) THEN\nC\nC Use the normal periodic QZ step routine.\nC\n IERR = 0\n IN = ILAST - IFIRST + 1\n IF ( SINV.LT.0 ) THEN\n J1 = IWORK(MAPQ+1)\n IWORK(MAPQ+1) = IWORK(MAPA+1)\n END IF\n CALL MB03AF( 'Double', K, IN, IWORK(MAPH), S, SINV, \n $ A(IFIRST,IFIRST,1), LDA1, LDA2, CS1, SN1,\n $ CS2, SN2 )\n IF ( SINV.LT.0 )\n $ IWORK(MAPQ+1) = J1\n COUNT = 0\n COUNTE = 0\n ELSE\nC\nC Use explict shifts.\nC\n COUNTE = COUNTE + 1\n W1 = ALPHAR(I)*BASE**SCAL(I)\nC\n IF ( ALPHAI(I).NE.ZERO ) THEN\nC\nC Use complex conjugate shifts.\nC\n SHFT = 'C'\n W2 = ALPHAI(I)*BASE**SCAL(I)\nC\n ELSE\nC\nC Two identical real shifts are tried first. If there is\nC no convergence after MCOUNT/2 consecutive iterations,\nC a single shift is applied. The eigenvalue closer to\nC the last element of the current product is used.\nC\n W2 = ALPHAR(ILAST)*BASE**SCAL(ILAST)\nC\n CALL MA01BD( BASE, LGBAS, K, S, A(ILAST,ILAST,1),\n $ LDA1*LDA2, TEMP, TEMP2, I )\n TEMP = TEMP*BASE**I\n A1 = ABS( TEMP - W1 )\n A2 = ABS( TEMP - W2 )\nC\n IF ( COUNTE.LE.MAX( 1, MCOUNT/2 ) ) THEN\n SHFT = 'D'\n IF ( A1.LT.A2 ) THEN\n W2 = W1\n ELSE\n W1 = W2\n END IF\n ELSE\n SHFT = 'S'\n IF ( A1.LT.A2 )\n $ W2 = W1\n END IF\nC\n END IF\nC\nC Compute an initial transformation using the selected\nC shifts.\nC\n CALL MB03AB( SHFT, K, ILAST-IFIRST+1, IWORK(MAPA+1), S,\n $ SINV, A(IFIRST,IFIRST,1), LDA1, LDA2, W1,\n $ W2, CS1, SN1, CS2, SN2 )\n END IF\nC\n IF ( COUNT+COUNTE.GE.NITER+MCOUNT ) THEN\nC\nC Reset the two counters.\nC\n COUNT = 0\n COUNTE = 0\n END IF\n END IF\nC\nC Do the sweeps.\nC\n IF ( K.GT.1 ) THEN\nC\nC The propagation of the initial transformation is processed\nC here separately.\nC\n IN = IFIRST + 1\n IO = ILAST - 2\n J = IFIRST\n AIND = IWORK(MAPA+1)\n CALL DROT( ILAST-IFRSTM+1, A(IFRSTM,J+1,AIND), 1,\n $ A(IFRSTM,J+2,AIND), 1, CS2, SN2 )\n CALL DROT( ILAST-IFRSTM+1, A(IFRSTM,J,AIND), 1,\n $ A(IFRSTM,J+1,AIND), 1, CS1, SN1 )\n IF ( LCMPQ ) THEN\n QI = IWORK(MAPQ+2)\n ELSE IF ( LPARQ ) THEN\n QI = ABS( QIND(IWORK(MAPQ+2)) )\n END IF\n IF ( QI.NE.0 ) THEN\n CALL DROT( N, Q(1,J+1,QI), 1, Q(1,J+2,QI), 1, CS2, SN2 )\n CALL DROT( N, Q(1,J,QI), 1, Q(1,J+1,QI), 1, CS1, SN1 )\n END IF\nC\nC Propagate information from the right to A_k.\nC\n DO 480 L = 2, K\n AIND = IWORK(MAPA+L)\n IF ( S(AIND).EQ.SINV ) THEN\n CALL DROT( ILASTM-J+1, A(J+1,J,AIND), LDA1,\n $ A(J+2,J,AIND), LDA1, CS2, SN2 )\n TEMP = A(J+2,J+2,AIND)\n CALL DLARTG( TEMP, -A(J+2,J+1,AIND), CS2, SN2,\n $ A(J+2,J+2,AIND) )\n A(J+2,J+1,AIND) = ZERO\n CALL DROT( J-IFRSTM+2, A(IFRSTM,J+1,AIND), 1,\n $ A(IFRSTM,J+2,AIND), 1, CS2, SN2 )\nC\n CALL DROT( ILASTM-J+1, A(J,J,AIND), LDA1,\n $ A(J+1,J,AIND), LDA1, CS1, SN1 )\n TEMP = A(J+1,J+1,AIND)\n CALL DLARTG( TEMP, -A(J+1,J,AIND), CS1, SN1,\n $ A(J+1,J+1,AIND) )\n A(J+1,J,AIND) = ZERO\n CALL DROT( J-IFRSTM+1, A(IFRSTM,J,AIND), 1,\n $ A(IFRSTM,J+1,AIND), 1, CS1, SN1 )\nC\n ELSE\nC\n CALL DROT( J+3-IFRSTM, A(IFRSTM,J+1,AIND), 1,\n $ A(IFRSTM,J+2,AIND), 1, CS2, SN2 )\n TEMP = A(J+1,J+1,AIND)\n CALL DLARTG( TEMP, A(J+2,J+1,AIND), CS2, SN2,\n $ A(J+1,J+1,AIND) )\n A(J+2,J+1,AIND) = ZERO\n CALL DROT( ILASTM-J-1, A(J+1,J+2,AIND), LDA1,\n $ A(J+2,J+2,AIND), LDA1, CS2, SN2 )\nC\n CALL DROT( J+2-IFRSTM, A(IFRSTM,J,AIND), 1,\n $ A(IFRSTM,J+1,AIND), 1, CS1, SN1 )\n TEMP = A(J,J,AIND)\n CALL DLARTG( TEMP, A(J+1,J,AIND), CS1, SN1,\n $ A(J,J,AIND) )\n A(J+1,J,AIND) = ZERO\n CALL DROT( ILASTM-J, A(J,J+1,AIND), LDA1,\n $ A(J+1,J+1,AIND), LDA1, CS1, SN1 )\n END IF\n IF ( LCMPQ ) THEN\n QI = IWORK(MAPQ+MOD(L,K)+1)\n ELSE IF ( LPARQ ) THEN\n QI = ABS( QIND(IWORK(MAPQ+MOD(L,K)+1)) )\n END IF\n IF ( QI.NE.0 ) THEN\n CALL DROT( N, Q(1,J+1,QI), 1, Q(1,J+2,QI), 1, CS2,\n $ SN2 )\n CALL DROT( N, Q(1,J,QI), 1, Q(1,J+1,QI), 1, CS1, SN1 )\n END IF\n 480 CONTINUE\nC\n AIND = IWORK(MAPA+1)\n CALL DROT( ILASTM-IFIRST+1, A(J+1,IFIRST,AIND), LDA1,\n $ A(J+2,IFIRST,AIND), LDA1, CS2, SN2 )\n CALL DROT( ILASTM-IFIRST+1, A(J,IFIRST,AIND), LDA1,\n $ A(J+1,IFIRST,AIND), LDA1, CS1, SN1 )\n ELSE\n IN = IFIRST - 1\n IO = ILAST - 3\n END IF\nC\n DO 500 J1 = IN, IO\n AIND = IWORK(MAPA+1)\n IF ( LCMPQ ) THEN\n QI = IWORK(MAPQ+1)\n ELSE IF ( LPARQ ) THEN\n QI = ABS( QIND(IWORK(MAPQ+1)) )\n END IF\nC\nC Create a bulge if J1 = IFIRST - 1, otherwise chase the\nC bulge.\nC\n IF ( J1.LT.IFIRST ) THEN\n J = J1 + 1\n CALL DROT( ILASTM-J+1, A(J+1,J,AIND), LDA1,\n $ A(J+2,J,AIND), LDA1, CS2, SN2 )\n CALL DROT( ILASTM-J+1, A(J,J,AIND), LDA1,\n $ A(J+1,J,AIND), LDA1, CS1, SN1 )\n ELSE\n IF ( K.EQ.1 ) THEN\n J = J + 1\n ELSE\n J = J1\n END IF\n TEMP = A(J+1,J-1,AIND)\n CALL DLARTG( TEMP, A(J+2,J-1,AIND), CS2, SN2,\n $ TEMP2 )\n TEMP = A(J,J-1,AIND)\n CALL DLARTG( TEMP, TEMP2, CS1, SN1, A(J,J-1,AIND) )\n A(J+1,J-1,AIND) = ZERO\n A(J+2,J-1,AIND) = ZERO\n CALL DROT( ILASTM-J+1, A(J+1,J,AIND), LDA1,\n $ A(J+2,J,AIND), LDA1, CS2, SN2 )\n CALL DROT( ILASTM-J+1, A(J,J,AIND), LDA1,\n $ A(J+1,J,AIND), LDA1, CS1, SN1 )\n END IF\n IF ( QI.NE.0 ) THEN\n CALL DROT( N, Q(1,J+1,QI), 1, Q(1,J+2,QI), 1, CS2, SN2 )\n CALL DROT( N, Q(1,J, QI), 1, Q(1,J+1,QI), 1, CS1, SN1 )\n END IF\nC\nC Propagate information from the right to A_1.\nC\n DO 490 L = K, 2, -1\n AIND = IWORK(MAPA+L)\n IF ( S(AIND).EQ.SINV ) THEN\n CALL DROT( J+3-IFRSTM, A(IFRSTM,J+1,AIND), 1,\n $ A(IFRSTM,J+2,AIND), 1, CS2, SN2 )\n TEMP = A(J+1,J+1,AIND)\n CALL DLARTG( TEMP, A(J+2,J+1,AIND), CS2, SN2,\n $ A(J+1,J+1,AIND) )\n A(J+2,J+1,AIND) = ZERO\n CALL DROT( ILASTM-J-1, A(J+1,J+2,AIND), LDA1,\n $ A(J+2,J+2,AIND), LDA1, CS2, SN2 )\n CALL DROT( J+2-IFRSTM, A(IFRSTM,J,AIND), 1,\n $ A(IFRSTM,J+1,AIND), 1, CS1, SN1 )\n TEMP = A(J,J,AIND)\n CALL DLARTG( TEMP, A(J+1,J,AIND), CS1, SN1,\n $ A(J,J,AIND) )\n A(J+1,J,AIND) = ZERO\n CALL DROT( ILASTM-J, A(J,J+1,AIND), LDA1,\n $ A(J+1,J+1,AIND), LDA1, CS1, SN1 )\n ELSE\n CALL DROT( ILASTM-J+1, A(J+1,J,AIND), LDA1,\n $ A(J+2,J,AIND), LDA1, CS2, SN2 )\n TEMP = A(J+2,J+2,AIND)\n CALL DLARTG( TEMP, -A(J+2,J+1,AIND), CS2, SN2,\n $ A(J+2,J+2,AIND) )\n A(J+2,J+1,AIND) = ZERO\n CALL DROT( J+2-IFRSTM, A(IFRSTM,J+1,AIND), 1,\n $ A(IFRSTM,J+2,AIND), 1, CS2, SN2 )\n CALL DROT( ILASTM-J+1, A(J,J,AIND), LDA1,\n $ A(J+1,J,AIND), LDA1, CS1, SN1 )\n TEMP = A(J+1,J+1,AIND)\n CALL DLARTG( TEMP, -A(J+1,J,AIND), CS1, SN1,\n $ A(J+1,J+1,AIND) )\n A(J+1,J,AIND) = ZERO\n CALL DROT( J+1-IFRSTM, A(IFRSTM,J,AIND), 1,\n $ A(IFRSTM,J+1,AIND), 1, CS1, SN1 )\n END IF\n IF ( LCMPQ ) THEN\n QI = IWORK(MAPQ+L)\n ELSE IF ( LPARQ ) THEN\n QI = ABS( QIND(IWORK(MAPQ+L)) )\n END IF\n IF ( QI.NE.0 ) THEN\n CALL DROT( N, Q(1,J+1,QI), 1, Q(1,J+2,QI), 1, CS2,\n $ SN2 )\n CALL DROT( N, Q(1,J,QI), 1, Q(1,J+1,QI), 1, CS1, SN1 )\n END IF\n 490 CONTINUE\n AIND = IWORK(MAPA+1)\n LM = MIN( J+3, ILASTM ) - IFRSTM + 1\n CALL DROT( LM, A(IFRSTM,J+1,AIND), 1,\n $ A(IFRSTM,J+2,AIND), 1, CS2, SN2 )\n CALL DROT( LM, A(IFRSTM,J,AIND), 1,\n $ A(IFRSTM,J+1,AIND), 1, CS1, SN1 )\n 500 CONTINUE\nC\nC To avoid IF statements, there is an extra piece of code for\nC the last step.\nC\n J = ILAST - 1\n TEMP = A(J,J-1,AIND)\n CALL DLARTG( TEMP, A(J+1,J-1,AIND), CS1, SN1, A(J,J-1,AIND) )\n A(J+1,J-1,AIND) = ZERO\nC\n 510 CONTINUE\nC\n CALL DROT( ILASTM-J+1, A(J,J,AIND), LDA1,\n $ A(J+1,J,AIND), LDA1, CS1, SN1 )\n IF ( LCMPQ ) THEN\n QI = IWORK(MAPQ+1)\n ELSE IF ( LPARQ ) THEN\n QI = ABS( QIND(IWORK(MAPQ+1)) )\n END IF\n IF ( QI.NE.0 )\n $ CALL DROT( N, Q(1,J,QI), 1, Q(1,J+1,QI), 1, CS1, SN1 )\nC\nC Propagate information from the right to A_1.\nC\n DO 520 L = K, 2, -1\n AIND = IWORK(MAPA+L)\n IF ( S(AIND).EQ.SINV ) THEN\n CALL DROT( J+2-IFRSTM, A(IFRSTM,J,AIND), 1,\n $ A(IFRSTM,J+1,AIND), 1, CS1, SN1 )\n TEMP = A(J,J,AIND)\n CALL DLARTG( TEMP, A(J+1,J,AIND), CS1, SN1,\n $ A(J,J,AIND) )\n A(J+1,J,AIND) = ZERO\n CALL DROT( ILASTM-J, A(J,J+1,AIND), LDA1,\n $ A(J+1,J+1,AIND), LDA1, CS1, SN1 )\n ELSE\n CALL DROT( ILASTM-J+1, A(J,J,AIND), LDA1,\n $ A(J+1,J,AIND), LDA1, CS1, SN1 )\n TEMP = A(J+1,J+1,AIND)\n CALL DLARTG( TEMP, -A(J+1,J,AIND), CS1, SN1,\n $ A(J+1,J+1,AIND) )\n A(J+1,J,AIND) = ZERO\n CALL DROT( J+1-IFRSTM, A(IFRSTM,J,AIND), 1,\n $ A(IFRSTM,J+1,AIND), 1, CS1, SN1 )\n END IF\n IF ( LCMPQ ) THEN\n QI = IWORK(MAPQ+L)\n ELSE IF ( LPARQ ) THEN\n QI = ABS( QIND(IWORK(MAPQ+L)) )\n END IF\n IF ( QI.NE.0 )\n $ CALL DROT( N, Q(1,J,QI), 1, Q(1,J+1,QI), 1, CS1, SN1 )\n 520 CONTINUE\n AIND = IWORK(MAPA+1)\n CALL DROT( ILASTM-IFRSTM+1, A(IFRSTM,J,AIND), 1,\n $ A(IFRSTM,J+1,AIND), 1, CS1, SN1 )\nC\nC End of iteration loop.\nC\n 530 CONTINUE\n 540 CONTINUE\nC\nC Drop through = non-convergence.\nC\n INFO = ILAST\n GO TO 580\nC\nC Successful completion of all QZ steps.\nC\n 550 CONTINUE\nC\nC Set eigenvalues 1:ILO-1.\nC\n DO 560 J = 1, ILO - 1\n CALL MA01BD( BASE, LGBAS, K, S, A(J,J,1), LDA1*LDA2, ALPHAR(J),\n $ BETA(J), SCAL(J) )\n ALPHAI(J) = ZERO\n 560 CONTINUE\nC\nC Store information about the splitted 2-by-2 blocks and possible\nC loss of accuracy.\nC\n DO 570 I = 2, N + 1\n IWORK(I) = IWORK(2*K+I-1)\n 570 CONTINUE\nC\n 580 CONTINUE\nC\n DO 590 L = K + 1, 2, -1\n DWORK(PNORM+L) = DWORK(PNORM+L-1)\n 590 CONTINUE\nC\n DWORK(1) = DBLE( OPTDW )\n IWORK(1) = OPTIW\nC\n RETURN\nC *** Last line of MB03BD ***\n END\n", "meta": {"hexsha": "9999bdebfeee56054d19a3cd6c1591ab93241a17", "size": 74462, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB03BD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB03BD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB03BD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 38.0685071575, "max_line_length": 72, "alphanum_fraction": 0.4147484623, "num_tokens": 23094, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391600697869, "lm_q2_score": 0.7122321781307374, "lm_q1q2_score": 0.6574181914764706}} {"text": " SUBROUTINE MB04YW( QRIT, UPDATU, UPDATV, M, N, L, K, SHIFT, D, E,\n $ U, LDU, V, LDV, DWORK )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To perform either one QR or QL iteration step onto the unreduced\nC bidiagonal submatrix Jk:\nC\nC |D(l) E(l) 0 ... 0 |\nC | 0 D(l+1) E(l+1) . |\nC Jk = | . . |\nC | . . |\nC | . E(k-1)|\nC | 0 ... ... D(k) |\nC\nC with k <= p and l >= 1, p = MIN(M,N), of the bidiagonal matrix J:\nC\nC |D(1) E(1) 0 ... 0 |\nC | 0 D(2) E(2) . |\nC J = | . . |.\nC | . . |\nC | . E(p-1)|\nC | 0 ... ... D(p) |\nC\nC Hereby, Jk is transformed to S' Jk T with S and T products of\nC Givens rotations. These Givens rotations S (respectively, T) are\nC postmultiplied into U (respectively, V), if UPDATU (respectively,\nC UPDATV) is .TRUE..\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC QRIT LOGICAL\nC Indicates whether a QR or QL iteration step is to be\nC taken (from larger end diagonal element towards smaller),\nC as follows:\nC = .TRUE. : QR iteration step (chase bulge from top to\nC bottom);\nC = .FALSE.: QL iteration step (chase bulge from bottom to\nC top).\nC\nC UPDATU LOGICAL\nC Indicates whether the user wishes to accumulate in a\nC matrix U the left-hand Givens rotations S, as follows:\nC = .FALSE.: Do not form U;\nC = .TRUE. : The given matrix U is updated (postmultiplied)\nC by the left-hand Givens rotations S.\nC\nC UPDATV LOGICAL\nC Indicates whether the user wishes to accumulate in a\nC matrix V the right-hand Givens rotations S, as follows:\nC = .FALSE.: Do not form V;\nC = .TRUE. : The given matrix V is updated (postmultiplied)\nC by the right-hand Givens rotations T.\nC\nC Input/Output Parameters\nC\nC M (input) INTEGER\nC The number of rows of the matrix U. M >= 0.\nC\nC N (input) INTEGER\nC The number of rows of the matrix V. N >= 0.\nC\nC L (input) INTEGER\nC The index of the first diagonal entry of the considered\nC unreduced bidiagonal submatrix Jk of J.\nC\nC K (input) INTEGER\nC The index of the last diagonal entry of the considered\nC unreduced bidiagonal submatrix Jk of J.\nC\nC SHIFT (input) DOUBLE PRECISION\nC Value of the shift used in the QR or QL iteration step.\nC\nC D (input/output) DOUBLE PRECISION array, dimension (p)\nC where p = MIN(M,N)\nC On entry, D must contain the diagonal entries of the\nC bidiagonal matrix J.\nC On exit, D contains the diagonal entries of the\nC transformed bidiagonal matrix S' J T.\nC\nC E (input/output) DOUBLE PRECISION array, dimension (p-1)\nC On entry, E must contain the superdiagonal entries of J.\nC On exit, E contains the superdiagonal entries of the\nC transformed matrix S' J T.\nC\nC U (input/output) DOUBLE PRECISION array, dimension (LDU,p)\nC On entry, if UPDATU = .TRUE., U must contain the M-by-p\nC left transformation matrix.\nC On exit, if UPDATU = .TRUE., the Givens rotations S on the\nC left have been postmultiplied into U, i.e., U * S is\nC returned.\nC U is not referenced if UPDATU = .FALSE..\nC\nC LDU INTEGER\nC The leading dimension of the array U.\nC LDU >= max(1,M) if UPDATU = .TRUE.;\nC LDU >= 1 if UPDATU = .FALSE..\nC\nC V (input/output) DOUBLE PRECISION array, dimension (LDV,p)\nC On entry, if UPDATV = .TRUE., V must contain the N-by-p\nC right transformation matrix.\nC On exit, if UPDATV = .TRUE., the Givens rotations T on the\nC right have been postmultiplied into V, i.e., V * T is\nC returned.\nC V is not referenced if UPDATV = .FALSE..\nC\nC LDV INTEGER\nC The leading dimension of the array V.\nC LDV >= max(1,N) if UPDATV = .TRUE.;\nC LDV >= 1 if UPDATV = .FALSE..\nC\nC Workspace\nC\nC DWORK DOUBLE PRECISION array, dimension (MAX(1,LDWORK))\nC LDWORK >= 4*MIN(M,N)-4, if UPDATU = UPDATV = .TRUE.;\nC LDWORK >= 2*MIN(M,N)-2, if\nC UPDATU = .TRUE. and UPDATV = .FALSE. or\nC UPDATV = .TRUE. and UPDATU = .FALSE.;\nC LDWORK >= 1, if UPDATU = UPDATV = .FALSE..\nC\nC METHOD\nC\nC QR iterations diagonalize the bidiagonal matrix by zeroing the\nC super-diagonal elements of Jk from bottom to top.\nC QL iterations diagonalize the bidiagonal matrix by zeroing the\nC super-diagonal elements of Jk from top to bottom.\nC The routine overwrites Jk with the bidiagonal matrix S' Jk T,\nC where S and T are products of Givens rotations.\nC T is essentially the orthogonal matrix that would be obtained by\nC applying one implicit symmetric shift QR (QL) step onto the matrix\nC Jk'Jk. This step factors the matrix (Jk'Jk - shift*I) into a\nC product of an orthogonal matrix T and a upper (lower) triangular\nC matrix. See [1,Sec.8.2-8.3] and [2] for more details.\nC\nC REFERENCES\nC\nC [1] Golub, G.H. and Van Loan, C.F.\nC Matrix Computations.\nC The Johns Hopkins University Press, Baltimore, Maryland, 1983.\nC\nC [2] Bowdler, H., Martin, R.S. and Wilkinson, J.H.\nC The QR and QL algorithms for symmetric matrices.\nC Numer. Math., 11, pp. 293-306, 1968.\nC\nC [3] Demmel, J. and Kahan, W.\nC Computing small singular values of bidiagonal matrices with\nC guaranteed high relative accuracy.\nC SIAM J. Sci. Statist. Comput., 11, pp. 873-912, 1990.\nC\nC NUMERICAL ASPECTS\nC\nC The algorithm is backward stable.\nC\nC CONTRIBUTOR\nC\nC Release 3.0: V. Sima, Katholieke Univ. Leuven, Belgium, June 1997.\nC Supersedes Release 2.0 routines MB04QY and MB04QZ by S. Van\nC Huffel, Katholieke University Leuven, Belgium.\nC This subroutine is based on the QR/QL step implemented in LAPACK\nC routine DBDSQR.\nC\nC REVISIONS\nC\nC -\nC\nC KEYWORDS\nC\nC Bidiagonal matrix, orthogonal transformation, singular values.\nC\nC ******************************************************************\nC\n DOUBLE PRECISION ZERO, ONE\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )\nC .. Scalar Arguments ..\n LOGICAL QRIT, UPDATU, UPDATV\n INTEGER K, L, LDU, LDV, M, N\n DOUBLE PRECISION SHIFT\nC ..\nC .. Array Arguments ..\n DOUBLE PRECISION D( * ), DWORK( * ), E( * ), U( LDU, * ),\n $ V( LDV, * )\nC ..\nC .. Local Scalars ..\n INTEGER I, IROT, NCV, NM1, NM12, NM13\n DOUBLE PRECISION COSL, COSR, CS, F, G, H, OLDCS, OLDSN, R, SINL,\n $ SINR, SN\nC ..\nC .. External Subroutines ..\n EXTERNAL DLARTG, DLASR\nC ..\nC .. Intrinsic Functions ..\n INTRINSIC ABS, MIN, SIGN\nC ..\nC .. Executable Statements ..\nC\nC For speed, no tests of the input scalar arguments are done.\nC\nC Quick return if possible.\nC\n NCV = MIN( M, N )\n IF ( NCV.LE.1 .OR. L.EQ.K )\n $ RETURN\nC\n NM1 = NCV - 1\n NM12 = NM1 + NM1\n NM13 = NM12 + NM1\n IF ( .NOT.UPDATV ) THEN\n NM12 = 0\n NM13 = NM1\n END IF\nC\nC If SHIFT = 0, do simplified QR iteration.\nC\n IF( SHIFT.EQ.ZERO ) THEN\n IF( QRIT ) THEN\nC\nC Chase bulge from top to bottom.\nC Save cosines and sines for later U and/or V updates,\nC if needed.\nC\n CS = ONE\n OLDCS = ONE\n CALL DLARTG( D( L )*CS, E( L ), CS, SN, R )\n CALL DLARTG( OLDCS*R, D( L+1 )*SN, OLDCS, OLDSN, D( L ) )\n IF ( UPDATV ) THEN\n DWORK( 1 ) = CS\n DWORK( 1+NM1 ) = SN\n END IF\n IF ( UPDATU ) THEN\n DWORK( 1+NM12 ) = OLDCS\n DWORK( 1+NM13 ) = OLDSN\n END IF\n IROT = 1\nC\n DO 110 I = L + 1, K - 1\n CALL DLARTG( D( I )*CS, E( I ), CS, SN, R )\n E( I-1 ) = OLDSN*R\n CALL DLARTG( OLDCS*R, D( I+1 )*SN, OLDCS, OLDSN, D( I ) )\n IROT = IROT + 1\n IF ( UPDATV ) THEN\n DWORK( IROT ) = CS\n DWORK( IROT+NM1 ) = SN\n END IF\n IF ( UPDATU ) THEN\n DWORK( IROT+NM12 ) = OLDCS\n DWORK( IROT+NM13 ) = OLDSN\n END IF\n 110 CONTINUE\nC\n H = D( K )*CS\n D( K ) = H*OLDCS\n E( K-1 ) = H*OLDSN\nC\nC Update U and/or V.\nC\n IF( UPDATV )\n $ CALL DLASR( 'R', 'V', 'F', N, K-L+1, DWORK( 1 ),\n $ DWORK( NCV ), V( 1, L ), LDV )\n IF( UPDATU )\n $ CALL DLASR( 'R', 'V', 'F', M, K-L+1, DWORK( NM12+1 ),\n $ DWORK( NM13+1 ), U( 1, L ), LDU )\nC\n ELSE\nC\nC Chase bulge from bottom to top.\nC Save cosines and sines for later U and/or V updates,\nC if needed.\nC\n CS = ONE\n OLDCS = ONE\n CALL DLARTG( D( K )*CS, E( K-1 ), CS, SN, R )\n CALL DLARTG( OLDCS*R, D( K-1 )*SN, OLDCS, OLDSN, D( K ) )\n IF ( UPDATV ) THEN\n DWORK( K-L ) = OLDCS\n DWORK( K-L+NM1 ) = -OLDSN\n END IF\n IF ( UPDATU ) THEN\n DWORK( K-L+NM12 ) = CS\n DWORK( K-L+NM13 ) = -SN\n END IF\n IROT = K - L\nC\n DO 120 I = K - 1, L + 1, -1\n CALL DLARTG( D( I )*CS, E( I-1 ), CS, SN, R )\n E( I ) = OLDSN*R\n CALL DLARTG( OLDCS*R, D( I-1 )*SN, OLDCS, OLDSN, D( I ) )\n IROT = IROT - 1\n IF ( UPDATV ) THEN\n DWORK( IROT ) = OLDCS\n DWORK( IROT+NM1 ) = -OLDSN\n END IF\n IF ( UPDATU ) THEN\n DWORK( IROT+NM12 ) = CS\n DWORK( IROT+NM13 ) = -SN\n END IF\n 120 CONTINUE\nC\n H = D( L )*CS\n D( L ) = H*OLDCS\n E( L ) = H*OLDSN\nC\nC Update U and/or V.\nC\n IF( UPDATV )\n $ CALL DLASR( 'R', 'V', 'B', N, K-L+1, DWORK( 1 ),\n $ DWORK( NCV ), V( 1, L ), LDV )\n IF( UPDATU )\n $ CALL DLASR( 'R', 'V', 'B', M, K-L+1, DWORK( NM12+1 ),\n $ DWORK( NM13+1 ), U( 1, L ), LDU )\n END IF\n ELSE\nC\nC Use nonzero shift.\nC\n IF( QRIT ) THEN\nC\nC Chase bulge from top to bottom.\nC Save cosines and sines for later U and/or V updates,\nC if needed.\nC\n F = ( ABS( D( L ) ) - SHIFT )*\n $ ( SIGN( ONE, D( L ) ) + SHIFT / D( L ) )\n G = E( L )\n CALL DLARTG( F, G, COSR, SINR, R )\n F = COSR*D( L ) + SINR*E( L )\n E( L ) = COSR*E( L ) - SINR*D( L )\n G = SINR*D( L+1 )\n D( L+1 ) = COSR*D( L+1 )\n CALL DLARTG( F, G, COSL, SINL, R )\n D( L ) = R\n F = COSL*E( L ) + SINL*D( L+1 )\n D( L+1 ) = COSL*D( L+1 ) - SINL*E( L )\n G = SINL*E( L+1 )\n E( L+1 ) = COSL*E( L+1 )\n IF ( UPDATV ) THEN\n DWORK( 1 ) = COSR\n DWORK( 1+NM1 ) = SINR\n END IF\n IF ( UPDATU ) THEN\n DWORK( 1+NM12 ) = COSL\n DWORK( 1+NM13 ) = SINL\n END IF\n IROT = 1\nC\n DO 130 I = L + 1, K - 2\n CALL DLARTG( F, G, COSR, SINR, R )\n E( I-1 ) = R\n F = COSR*D( I ) + SINR*E( I )\n E( I ) = COSR*E( I ) - SINR*D( I )\n G = SINR*D( I+1 )\n D( I+1 ) = COSR*D( I+1 )\n CALL DLARTG( F, G, COSL, SINL, R )\n D( I ) = R\n F = COSL*E( I ) + SINL*D( I+1 )\n D( I+1 ) = COSL*D( I+1 ) - SINL*E( I )\n G = SINL*E( I+1 )\n E( I+1 ) = COSL*E( I+1 )\n IROT = IROT + 1\n IF ( UPDATV ) THEN\n DWORK( IROT ) = COSR\n DWORK( IROT+NM1 ) = SINR\n END IF\n IF ( UPDATU ) THEN\n DWORK( IROT+NM12 ) = COSL\n DWORK( IROT+NM13 ) = SINL\n END IF\n 130 CONTINUE\nC\n IF ( L.LT.K-1 ) THEN\n CALL DLARTG( F, G, COSR, SINR, R )\n E( K-2 ) = R\n F = COSR*D( K-1 ) + SINR*E( K-1 )\n E( K-1 ) = COSR*E( K-1 ) - SINR*D( K-1 )\n G = SINR*D( K )\n D( K ) = COSR*D( K )\n CALL DLARTG( F, G, COSL, SINL, R )\n D( K-1 ) = R\n F = COSL*E( K-1 ) + SINL*D( K )\n D( K ) = COSL*D( K ) - SINL*E( K-1 )\n IROT = IROT + 1\n IF ( UPDATV ) THEN\n DWORK( IROT ) = COSR\n DWORK( IROT+NM1 ) = SINR\n END IF\n IF ( UPDATU ) THEN\n DWORK( IROT+NM12 ) = COSL\n DWORK( IROT+NM13 ) = SINL\n END IF\n END IF\n E( K-1 ) = F\nC\nC Update U and/or V.\nC\n IF( UPDATV )\n $ CALL DLASR( 'R', 'V', 'F', N, K-L+1, DWORK( 1 ),\n $ DWORK( NCV ), V( 1, L ), LDV )\n IF( UPDATU )\n $ CALL DLASR( 'R', 'V', 'F', M, K-L+1, DWORK( NM12+1 ),\n $ DWORK( NM13+1 ), U( 1, L ), LDU )\nC\n ELSE\nC\nC Chase bulge from bottom to top.\nC Save cosines and sines for later U and/or V updates,\nC if needed.\nC\n F = ( ABS( D( K ) ) - SHIFT )*\n $ ( SIGN( ONE, D( K ) ) + SHIFT / D( K ) )\n G = E( K-1 )\n IF ( L.LT.K-1 ) THEN\n CALL DLARTG( F, G, COSR, SINR, R )\n F = COSR*D( K ) + SINR*E( K-1 )\n E( K-1 ) = COSR*E( K-1 ) - SINR*D( K )\n G = SINR*D( K-1 )\n D( K-1 ) = COSR*D( K-1 )\n CALL DLARTG( F, G, COSL, SINL, R )\n D( K ) = R\n F = COSL*E( K-1 ) + SINL*D( K-1 )\n D( K-1 ) = COSL*D( K-1 ) - SINL*E( K-1 )\n G = SINL*E( K-2 )\n E( K-2 ) = COSL*E( K-2 )\n IF ( UPDATV ) THEN\n DWORK( K-L ) = COSL\n DWORK( K-L+NM1 ) = -SINL\n END IF\n IF ( UPDATU ) THEN\n DWORK( K-L+NM12 ) = COSR\n DWORK( K-L+NM13 ) = -SINR\n END IF\n IROT = K - L\n ELSE\n IROT = K - L + 1\n END IF\nC\n DO 140 I = K - 1, L + 2, -1\n CALL DLARTG( F, G, COSR, SINR, R )\n E( I ) = R\n F = COSR*D( I ) + SINR*E( I-1 )\n E( I-1 ) = COSR*E( I-1 ) - SINR*D( I )\n G = SINR*D( I-1 )\n D( I-1 ) = COSR*D( I-1 )\n CALL DLARTG( F, G, COSL, SINL, R )\n D( I ) = R\n F = COSL*E( I-1 ) + SINL*D( I-1 )\n D( I-1 ) = COSL*D( I-1 ) - SINL*E( I-1 )\n G = SINL*E( I-2 )\n E( I-2 ) = COSL*E( I-2 )\n IROT = IROT - 1\n IF ( UPDATV ) THEN\n DWORK( IROT ) = COSL\n DWORK( IROT+NM1 ) = -SINL\n END IF\n IF ( UPDATU ) THEN\n DWORK( IROT+NM12 ) = COSR\n DWORK( IROT+NM13 ) = -SINR\n END IF\n 140 CONTINUE\nC\n CALL DLARTG( F, G, COSR, SINR, R )\n E( L+1 ) = R\n F = COSR*D( L+1 ) + SINR*E( L )\n E( L ) = COSR*E( L ) - SINR*D( L+1 )\n G = SINR*D( L )\n D( L ) = COSR*D( L )\n CALL DLARTG( F, G, COSL, SINL, R )\n D( L+1 ) = R\n F = COSL*E( L ) + SINL*D( L )\n D( L ) = COSL*D( L ) - SINL*E( L )\n IROT = IROT - 1\n IF ( UPDATV ) THEN\n DWORK( IROT ) = COSL\n DWORK( IROT+NM1 ) = -SINL\n END IF\n IF ( UPDATU ) THEN\n DWORK( IROT+NM12 ) = COSR\n DWORK( IROT+NM13 ) = -SINR\n END IF\n E( L ) = F\nC\nC Update U and/or V if desired.\nC\n IF( UPDATV )\n $ CALL DLASR( 'R', 'V', 'B', N, K-L+1, DWORK( 1 ),\n $ DWORK( NCV ), V( 1, L ), LDV )\n IF( UPDATU )\n $ CALL DLASR( 'R', 'V', 'B', M, K-L+1, DWORK( NM12+1 ),\n $ DWORK( NM13+1 ), U( 1, L ), LDU )\n END IF\n END IF\nC\n RETURN\nC *** Last line of MB04YW ***\n END\n", "meta": {"hexsha": "63e03ec82c3dbcc53e71aa98ce5877dd7046b2e5", "size": 17438, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB04YW.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB04YW.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB04YW.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 34.876, "max_line_length": 72, "alphanum_fraction": 0.4346828765, "num_tokens": 5628, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9314625069680098, "lm_q2_score": 0.7057850340255386, "lm_q1q2_score": 0.6574122971739302}} {"text": "!*******************************************************************\n! *\n SUBROUTINE GRACAH1(I,J,K,L,M,N,RAC)\n! *\n! SUBROUTINE TO CALCULATE RACAH COEFFICIENTS. *\n! THE ARGUMENTS I,J,K,L,M,N SHOULD BE TWICE THEIR ACTUAL VALUE. *\n! WRITTEN BY N. S. SCOTT *\n! Modified by C. Froese Fischer, March 11, 1988 to use table *\n! look-up *\n! and *\n! G. Gaigalas, September 14, 1997 *\n! Transform to fortran 90/95 by G. Gaigalas December 2012 *\n! The last modification made by G. Gaigalas October 2017 *\n! *\n!*******************************************************************\n!\n!-----------------------------------------------\n! M o d u l e s\n!-----------------------------------------------\n USE vast_kind_param, ONLY: DOUBLE\n USE CONS_C, ONLY: ZERO, ONE, TWO\n USE FACTS_C\n IMPLICIT NONE\n!-----------------------------------------------\n! D u m m y A r g u m e n t s\n!-----------------------------------------------\n INTEGER , INTENT(IN) :: I\n INTEGER , INTENT(IN) :: J\n INTEGER , INTENT(IN) :: K\n INTEGER , INTENT(IN) :: L\n INTEGER , INTENT(IN) :: M\n INTEGER , INTENT(IN) :: N\n REAL(DOUBLE) , INTENT(OUT) :: RAC\n!-----------------------------------------------\n! L o c a l V a r i a b l e s\n!-----------------------------------------------\n INTEGER :: J1,J2,J3,J4,J5,J6,J7,NUMIN,NUMAX,ICOUNT,KK,KI\n!-----------------------------------------------\n J1 = I+J+M\n J2 = K+L+M\n J3 = I+K+N\n J4 = J+L+N\n IF (MOD(J1,2) == 0 .AND. MOD(J2,2) == 0 .AND. &\n MOD(J3,2) == 0 .AND. MOD(J4,2) == 0 ) THEN\n J1 = J1/2\n J2 = J2/2\n J3 = J3/2\n J4 = J4/2\n IF (MAX(I,J,M) <= J1 .AND. MAX(K,L,M) <= J2 .AND. &\n MAX(I,K,N) <= J3 .AND. MAX(J,L,N) <= J4 ) THEN\n J5 = (I+J+K+L)/2\n J6 = (I+L+M+N)/2\n J7 = (J+K+M+N)/2\n NUMIN = MAX(J1, J2, J3, J4) + 1\n NUMAX = MIN(J5, J6, J7) + 1\n RAC = ONE\n ICOUNT = 0\n DO KK = NUMIN+1,NUMAX\n KI = NUMAX - ICOUNT\n RAC = ONE - (RAC*(KI*(J5-KI+2)*(J6-KI+2)*(J7-KI+2)))/ &\n ((KI-1-J1)*(KI-1-J2)*(KI-1-J3)*(KI-1-J4))\n ICOUNT = ICOUNT+1\n END DO\n RAC = RAC*EXP( &\n (GAM(NUMIN+1) - GAM(NUMIN-J1) - GAM(NUMIN-J2) - &\n GAM(NUMIN-J3) - GAM(NUMIN-J4) - GAM(J5+2-NUMIN)- &\n GAM(J6+2-NUMIN)-GAM(J7+2-NUMIN)) + &\n (GAM(J1+1-I)+GAM(J1+1-J)+GAM(J1+1-M)-GAM(J1+2) + &\n GAM(J2+1-K)+GAM(J2+1-L)+GAM(J2+1-M)-GAM(J2+2) + &\n GAM(J3+1-I)+GAM(J3+1-K)+GAM(J3+1-N)-GAM(J3+2) + &\n GAM(J4+1-J)+GAM(J4+1-L)+GAM(J4+1-N)-GAM(J4+2))/TWO)\n IF (MOD(J5+NUMIN,2) == 0) RAC = -RAC\n ELSE\n RAC = ZERO\n END IF\n ELSE\n RAC = ZERO\n END IF\n RETURN\n END\n", "meta": {"hexsha": "7efcf19017e25babf1f0ab9ed7ff050549ad4391", "size": 3501, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/lib/librang90/Gracah1.f90", "max_stars_repo_name": "sylas/grasp-continuum", "max_stars_repo_head_hexsha": "f5e2fb18bb2bca4f715072190bf455fba889320f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 33, "max_stars_repo_stars_event_min_datetime": "2019-03-10T04:00:32.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T22:01:15.000Z", "max_issues_repo_path": "src/lib/librang90/Gracah1.f90", "max_issues_repo_name": "sylas/grasp-continuum", "max_issues_repo_head_hexsha": "f5e2fb18bb2bca4f715072190bf455fba889320f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 65, "max_issues_repo_issues_event_min_datetime": "2019-03-07T17:56:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-16T16:45:24.000Z", "max_forks_repo_path": "src/lib/librang90/Gracah1.f90", "max_forks_repo_name": "sylas/grasp-continuum", "max_forks_repo_head_hexsha": "f5e2fb18bb2bca4f715072190bf455fba889320f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2019-03-10T04:00:43.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-23T02:06:40.000Z", "avg_line_length": 43.2222222222, "max_line_length": 72, "alphanum_fraction": 0.3179091688, "num_tokens": 1050, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625126757597, "lm_q2_score": 0.7057850216484838, "lm_q1q2_score": 0.6574122896736122}} {"text": " subroutine compute_ddlx(ctfmp,n_alpha,n_metxx,octfmp,x,Nx,hx,myzer\n &o,phys_bdy,res)\n implicit none\n integer i\n integer Nx\n real*8 hx\n real*8 myzero\n real*8 ctfmp(Nx)\n real*8 n_alpha(Nx)\n real*8 n_metxx(Nx)\n real*8 octfmp(Nx)\n real*8 x(Nx)\n integer phys_bdy(2)\n real*8 res(Nx)\n real*8 qb\n if (phys_bdy(1) .eq. 1) then\n do i=1, 1, 1\n qb = myzero * x(i)\n res(i)=qb\n end do\n endif\n do i=2, Nx-1, 1\n qb = 0.5000000000000000D0 * (n_alpha(i - 1) - 0.1D1 * n_alpha(i + \n #1)) / hx / ctfmp(i) * octfmp(i) + (0.1250000000000000D0 / n_metxx(\n #i) * (n_alpha(i - 1) - 0.1D1 * n_alpha(i + 1)) * (-0.1D1 * n_metxx\n #(i - 1) + n_metxx(i + 1)) + n_alpha(i - 1) - 0.2D1 * n_alpha(i) + \n #n_alpha(i + 1)) / ctfmp(i) ** 2 / hx ** 2\n res(i)=qb\n end do\n if (phys_bdy(2) .eq. 1) then\n do i=Nx, Nx, 1\n qb = myzero * x(i)\n res(i)=qb\n end do\n endif\n END\n", "meta": {"hexsha": "1d22a444842f4d88b2eb516d334065fe5677b0b6", "size": 1006, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/FD/compute_ddlx.f", "max_stars_repo_name": "rmanak/bssn_spher", "max_stars_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/FD/compute_ddlx.f", "max_issues_repo_name": "rmanak/bssn_spher", "max_issues_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/FD/compute_ddlx.f", "max_forks_repo_name": "rmanak/bssn_spher", "max_forks_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.1891891892, "max_line_length": 72, "alphanum_fraction": 0.5, "num_tokens": 429, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.89181104831338, "lm_q2_score": 0.7371581684030624, "lm_q1q2_score": 0.6574057989363061}} {"text": "! **********************************************************************\nmodule Constants\nuse Types\nreal(DPT),parameter :: ZERO = 0.0_DPT\nreal(DPT),parameter :: HALF = 0.5_DPT\nreal(DPT),parameter :: ONE = 1.0_DPT\nreal(DPT),parameter :: TWO = 2.0_DPT\nreal(DPT),parameter :: THREE = 3.0_DPT\nreal(DPT),parameter :: FOUR = 4.0_DPT\ncomplex(DPT),parameter :: ZEROC = (ZERO,ZERO)\ncomplex(DPT),parameter :: ONEC = (ONE,ZERO)\ncomplex(DPT),parameter :: IU = (ZERO,ONE)\nreal(DPT),parameter :: PI = 3.141592653589793238462643383279502884197_DPT\nreal(DPT),parameter :: PISQRT = 1.7724538509055160272981674833411_DPT\nreal(DPT),parameter :: TWOPI = TWO*PI\nreal(DPT),parameter :: R2D = 180.0_DPT/PI\nreal(DPT),parameter :: VC = 2.99792458e10_DPT\nreal(DPT),parameter :: VCO8PI = VC/8.0_DPT/PI\nreal(DPT),parameter :: amr = 1836.1_DPT\nreal(DPT),parameter :: CGS_Pscale=1.0e13_DPT ! 1 MW power in CGS (erg/sec)\nreal(DPT),parameter :: CGS_Escale=10.0_DPT/3.0_DPT ! 1 kV/cm in CGS system\nreal(DPT),parameter :: CGS_Hscale=PI/2.5_DPT ! 1 A/cm in CGS system\n\nreal(DPT),parameter::EPS_length=1.0e-8_DPT ! used in detecting identical WG vectors\nend module Constants\n", "meta": {"hexsha": "5e2ec5f2da36399255d2c253b1a36caeb172ecdb", "size": 1166, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/Const.f90", "max_stars_repo_name": "temper8/FTEST", "max_stars_repo_head_hexsha": "88a6ce48a4dedec38cc05f2bd167add1e86c4767", "max_stars_repo_licenses": ["MIT"], "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/Const.f90", "max_issues_repo_name": "temper8/FTEST", "max_issues_repo_head_hexsha": "88a6ce48a4dedec38cc05f2bd167add1e86c4767", "max_issues_repo_licenses": ["MIT"], "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/Const.f90", "max_forks_repo_name": "temper8/FTEST", "max_forks_repo_head_hexsha": "88a6ce48a4dedec38cc05f2bd167add1e86c4767", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.8461538462, "max_line_length": 83, "alphanum_fraction": 0.6689536878, "num_tokens": 416, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110540642806, "lm_q2_score": 0.7371581568543044, "lm_q1q2_score": 0.6574057928763195}} {"text": " MODULE MOD_INTPL\r\n contains\r\n SUBROUTINE INTPL(Y,X,X1,X2,Y1,Y2)\r\nC**************************************\r\nC CALLED BY INPLCS, CSTABREAD\r\nC WRITTEN BY MARGIT HABERREITER\r\nC FOR LINEAR INTERPOLATION\r\nC INPUT: X1,X2,Y1,Y2,X\r\nC OUTPUT: Y\r\nC SLOPE: SLP\r\nC**************************************\r\n!\tIMPLICIT REAL*8(a-h,o-z)\r\n\tIMPLICIT NONE\r\n\tREAL*8,intent(in)::X1,X2,Y1,Y2,X\r\n\tREAL*8,intent(out)::Y\r\n\treal*8::SLP\r\n\tY=0.\r\n\tSLP=(Y2-Y1)/(X2-X1)\r\n\tY=Y1+(SLP*(X-X1))\t\r\n\r\n\tEND SUBROUTINE\r\n END MODULE\r\n", "meta": {"hexsha": "8ea6ada08742da1c1bc76874273e9b5b512b4d84", "size": 539, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/intpl.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/intpl.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/intpl.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": 23.4347826087, "max_line_length": 41, "alphanum_fraction": 0.5083487941, "num_tokens": 189, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110339361275, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6574057883379969}} {"text": "! This is the 2D mesh generator for linear, triangular elements\n! \n! This code is modified from J.N. REDDY, AN INTRODUCTION TO THE\n! FINITE ELEMENT METHOD, 2nd EDITION\n! \n! Coded by Tyler Hayes, April 3, 2007\n!\n!\n! INPUTS:\n!\n! NX = NUMBER OF DIVISIONS IN THE X-DIR\n! NY = NUMBER OF DIVISIONS IN THE Y-DIR\n! NEX1 = INTEGER = NX+1\n! NEY1 = INTEGER = NY+1\n! NEM = INTEGER = 2*NX*NY\n! NNM = INTEGER = ((IEL*NX)+1) * ((IEL*NY)+1) IEL = 1 for tri\n! DX = VECTOR OF SPACINGS IN THE X-DIR <- CAN BE VARIABLE\n! THE VECTOR SHOULD BE NX+1 IN SIZE BUT THE DX(NX+1) IS\n! SET TO ZERO AND IS A DUMMY VARIABLE\n! DY = VECTOR OF SPACINGS IN THE Y-DIR <- CAN BE VARIABLE\n! THE VECTOR SHOULD BE NY+1 IN SIZE BUT THE DY(NY+1) IS\n! SET TO ZERO AND IS A DUMMY VARIABLE\n! X0 = ORIGIN OF THE X AXIS\n! Y0 = ORIGIN OF THE Y AXIS\n!\n! OUTPUT:\n! NOD = INTEGER MATRIX OF ELEMENT NOD INDICES\n! GLXY = GLOBAL COORDINATES OF NOD\n!\n! MISC.:\n! NPE = NODES PER ELEMENT\n!----------------------------------------------------------------\n\nSUBROUTINE MESH(NOD,GLXY,NX,NY,NEX1,NEY1,NEM,NNM,DX,DY,X0,Y0)\n IMPLICIT NONE\n INTEGER :: NXX,NYY,NX2,NY2,NXX1,NYY1\n INTEGER :: K,IY,L,M,N,I,NI,NJ,IEL\n INTEGER,PARAMETER :: NPE=3\n REAL :: XC,YC\n! INPUTS\n INTEGER,INTENT(IN) :: NX,NY,NEM,NNM,NEX1,NEY1\n REAL,INTENT(IN) :: X0,Y0\n REAL,DIMENSION(NEX1),INTENT(IN) :: DX\n REAL,DIMENSION(NEY1),INTENT(IN) :: DY\n! PARAMETERS\n! OUTPUTS\n INTEGER,DIMENSION(NEM,NPE),INTENT(OUT) :: NOD\n REAL,DIMENSION(NNM,2),INTENT(OUT) :: GLXY\n\n! CREATE VARIABLES\n IEL = 1 ! FOR <= 4 NODES PER ELEMENT\n NXX = IEL*NX\n NYY = IEL*NY\n NXX1 = NXX + 1\n NYY1 = NYY + 1\n NX2 = 2*NX\n NY2 = 2*NY\n\n\n! CREATE TRIANGUALR ELEMENTS\n!----------------------------------------------------------------\n\n! INITIALIZE FIRST TWO ELEMENTS\n NOD(1,1) = 1\n NOD(1,2) = IEL+1\n NOD(1,3) = IEL*NXX1 + IEL + 1\n NOD(2,1) = 1\n NOD(2,2) = NOD(1,3)\n NOD(2,3) = IEL*NXX1 + 1\n\n! LOOP THROUGH MESH\n K=3\n DO IY=1,NY\n L=IY*NX2\n M=(IY-1)*NX2\n IF (NX > 1) THEN\n DO N=K,L,2\n DO I=1,NPE\n NOD(N,I) = NOD(N-2,I) + IEL\n NOD(N+1,I) = NOD(N-1,I) + IEL\n END DO\n END DO\n END IF\n IF (IY < NY) THEN\n DO I=1,NPE\n NOD(L+1,I) = NOD(M+1,I) + IEL*NXX1\n NOD(L+2,I) = NOD(M+2,I) + IEL*NXX1\n END DO\n END IF\n K=L+3\n END DO\n\n\n! NOW GENERATE GLOBAL COORDINATES OF THE NODES\n XC = X0\n YC = Y0\n\n DO NI=1,NEY1\n XC = X0\n I = NXX1*IEL*(NI-1)\n DO NJ = 1,NEX1\n I=I+1\n GLXY(I,1) = XC\n GLXY(I,2) = YC\n IF (NJ < NEX1) THEN\n IF (IEL == 2) THEN\n I=I+1\n XC = XC + 0.5*DX(NJ)\n GLXY(I,1) = XC\n GLXY(I,2) = YC\n END IF\n END IF\n XC = XC + DX(NJ)/IEL\n END DO\n XC = X0\n IF (IEL == 2) THEN\n YC = YC + 0.5*DY(NI)\n DO NJ = 1,NEX1\n I=I+1\n GLXY(I,1) = XC\n GLXY(I,2) = YC\n IF (NJ < NEX1) THEN\n I=I+1\n XC = XC + 0.5*DX(NJ)\n GLXY(I,1) = XC\n GLXY(I,2) = YC\n END IF\n XC = XC + 0.5*DX(NJ)\n END DO\n END IF\n YC = YC + DY(NI)/IEL\n END DO\nEND SUBROUTINE MESH\n \n", "meta": {"hexsha": "492333ade3d618c55070cd25ff82ef02bfbacd10", "size": 3321, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mesh.f90", "max_stars_repo_name": "thayes75/options", "max_stars_repo_head_hexsha": "6a15155ce345f25c885b9bb71492b164ed5781c8", "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": "mesh.f90", "max_issues_repo_name": "thayes75/options", "max_issues_repo_head_hexsha": "6a15155ce345f25c885b9bb71492b164ed5781c8", "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": "mesh.f90", "max_forks_repo_name": "thayes75/options", "max_forks_repo_head_hexsha": "6a15155ce345f25c885b9bb71492b164ed5781c8", "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.6, "max_line_length": 65, "alphanum_fraction": 0.4968383017, "num_tokens": 1307, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772482857833, "lm_q2_score": 0.7520125848754471, "lm_q1q2_score": 0.6573170908642099}} {"text": "program quadtest\n\n use quadrature_module\n\n implicit none\n\n integer :: npoints\n real*8,allocatable :: x(:)\n real*8,allocatable :: w(:)\n integer :: i\n\n npoints=1\n\n call gll_gen(x,w,npoints)\n\n do i=1,npoints+1\n \t\n \t\tprint *,x(i),w(i)\n\n\tenddo\n\nend program quadtest\n", "meta": {"hexsha": "275b53ce6716e3bf721049fb2b04e2633e459577", "size": 316, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "pretreatment_model/src/quadtest.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/quadtest.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/quadtest.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": 13.7391304348, "max_line_length": 32, "alphanum_fraction": 0.5537974684, "num_tokens": 92, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8740772417253255, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6573170810726948}} {"text": "program hip_dgemm\n use iso_c_binding\n use hipfort\n use hipfort_check\n use hipfort_hipblas\n\n implicit none\n\n integer(kind(HIPBLAS_OP_N)), parameter :: transa = HIPBLAS_OP_N, transb = HIPBLAS_OP_N;\n complex(kind=4), parameter :: alpha = 1.1d0, beta = 0.9d0;\n\n integer, parameter :: m = 512, n = 512, k = 512;\n\n complex(kind=4), allocatable, dimension(:,:) :: ha, hb, hc\n complex(kind=4), allocatable, dimension(:,:) :: hc_exact\n\n complex(kind=4), pointer, dimension(:,:) :: da, db, dc\n type(c_ptr) :: handle = c_null_ptr\n\n integer :: i,j\n double precision :: error\n double precision, parameter :: error_max = 10*epsilon(error)\n\n write(*,\"(a)\",advance=\"no\") \"-- Running test 'CGEMM' (Fortran 2008 interfaces) - \"\n\n call hipblasCheck(hipblasCreate(handle))\n\n ! C = A_MxK * B_KxN\n \n allocate(ha(m,k))\n allocate(hb(k,n))\n allocate(hc(m,n))\n allocate(hc_exact(m,n))\n\n ! Use these constant matrices so the exact answer is also a\n ! constant matrix and therefore easy to check\n ha(:,:) = 1.d0\n hb(:,:) = 2.d0\n hc(:,:) = 3.d0\n hc_exact(:,:) = alpha*k*2.d0 + beta*3.d0\n\n ! Allocate device memory\n call hipCheck(hipMalloc(da,mold=ha))\n call hipCheck(hipMalloc(db,mold=hb))\n call hipCheck(hipMalloc(dc,mold=hc))\n\n !Transfer from host to device\n call hipCheck(hipMemcpy(da, ha, hipMemcpyHostToDevice))\n call hipCheck(hipMemcpy(db, hb, hipMemcpyHostToDevice))\n call hipCheck(hipMemcpy(dc, hc, hipMemcpyHostToDevice))\n\n call hipblasCheck(hipblasCgemm(handle,transa,transb,m,n,k,alpha,da,size(da,1),db,size(db,1),beta,dc,size(dc,1)))\n\n call hipCheck(hipDeviceSynchronize())\n\n ! Transfer data back to host memory\n call hipCheck(hipMemcpy(hc, dc, hipMemcpyDeviceToHost))\n\n do j = 1,n\n do i = 1,m\n !write(*,*) \"hc(i,j)=\",hc(i,j),\",hc_exact(i,j)=\",hc_exact(i,j)\n error = abs((hc_exact(i,j) - hc(i,j))/hc_exact(i,j))\n if( error > error_max )then\n write(*,*) \"FAILED! Error bigger than max! Error = \", error\n call exit(1)\n end if\n end do\n end do\n\n call hipCheck(hipFree(da))\n call hipCheck(hipFree(db))\n call hipCheck(hipFree(dc))\n\n call hipblasCheck(hipblasDestroy(handle))\n\n deallocate(ha,hb,hc,hc_exact)\n\n write(*,*) \"PASSED!\"\n\nend program hip_dgemm\n", "meta": {"hexsha": "2c6d31e0b8bbc612d96595cedd234f4427cb3e30", "size": 2222, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "test/f2008/hipblas/cgemm.f03", "max_stars_repo_name": "twhite-cray/hipfort", "max_stars_repo_head_hexsha": "c854323b9da1dbcc6beda4206534f5a5b1d02dbe", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2020-07-28T21:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-08T01:32:29.000Z", "max_issues_repo_path": "test/f2008/hipblas/cgemm.f03", "max_issues_repo_name": "twhite-cray/hipfort", "max_issues_repo_head_hexsha": "c854323b9da1dbcc6beda4206534f5a5b1d02dbe", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 44, "max_issues_repo_issues_event_min_datetime": "2020-07-21T18:10:51.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-15T10:51:57.000Z", "max_forks_repo_path": "test/f2008/hipblas/cgemm.f03", "max_forks_repo_name": "twhite-cray/hipfort", "max_forks_repo_head_hexsha": "c854323b9da1dbcc6beda4206534f5a5b1d02dbe", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 16, "max_forks_repo_forks_event_min_datetime": "2020-07-21T16:11:58.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-18T19:18:32.000Z", "avg_line_length": 27.4320987654, "max_line_length": 114, "alphanum_fraction": 0.6665166517, "num_tokens": 719, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772482857833, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6573170762903048}} {"text": "!*==cladiv.f90 processed by SPAG 7.51RB at 20:08 on 3 Mar 2022\n!> \\brief \\b CLADIV performs complex division in real arithmetic, avoiding unnecessary overflow.\n!\n! =========== DOCUMENTATION ===========\n!\n! Online html documentation available at\n! http://www.netlib.org/lapack/explore-html/\n!\n!> \\htmlonly\n!> Download CLADIV + dependencies\n!> \n!> [TGZ]\n!> \n!> [ZIP]\n!> \n!> [TXT]\n!> \\endhtmlonly\n!\n! Definition:\n! ===========\n!\n! COMPLEX FUNCTION CLADIV( X, Y )\n!\n! .. Scalar Arguments ..\n! COMPLEX X, Y\n! ..\n!\n!\n!> \\par Purpose:\n! =============\n!>\n!> \\verbatim\n!>\n!> CLADIV := X / Y, where X and Y are complex. The computation of X / Y\n!> will not overflow on an intermediary step unless the results\n!> overflows.\n!> \\endverbatim\n!\n! Arguments:\n! ==========\n!\n!> \\param[in] X\n!> \\verbatim\n!> X is COMPLEX\n!> \\endverbatim\n!>\n!> \\param[in] Y\n!> \\verbatim\n!> Y is COMPLEX\n!> The complex scalars X and Y.\n!> \\endverbatim\n!\n! Authors:\n! ========\n!\n!> \\author Univ. of Tennessee\n!> \\author Univ. of California Berkeley\n!> \\author Univ. of Colorado Denver\n!> \\author NAG Ltd.\n!\n!> \\date December 2016\n!\n!> \\ingroup complexOTHERauxiliary\n!\n! =====================================================================\n COMPLEX FUNCTION CLADIV(X,Y)\n IMPLICIT NONE\n!*--CLADIV68\n!\n! -- LAPACK auxiliary routine (version 3.7.0) --\n! -- LAPACK is a software package provided by Univ. of Tennessee, --\n! -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n! December 2016\n!\n! .. Scalar Arguments ..\n COMPLEX X , Y\n! ..\n!\n! =====================================================================\n!\n! .. Local Scalars ..\n REAL zi , zr\n! ..\n! .. External Subroutines ..\n EXTERNAL SLADIV\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC AIMAG , CMPLX , REAL\n! ..\n! .. Executable Statements ..\n!\n CALL SLADIV(REAL(X),AIMAG(X),REAL(Y),AIMAG(Y),zr,zi)\n CLADIV = CMPLX(zr,zi)\n!\n!\n! End of CLADIV\n!\n END FUNCTION CLADIV\n", "meta": {"hexsha": "0e17c453d752e43d67d7f5b4b199d31872119c2e", "size": 2422, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/complex/cladiv.f90", "max_stars_repo_name": "urbanjost/spag_lapack", "max_stars_repo_head_hexsha": "1b082638c0ff5feb1a295a3aa4624c538d14847c", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2022-03-04T13:15:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-04T17:40:26.000Z", "max_issues_repo_path": "src/complex/cladiv.f90", "max_issues_repo_name": "urbanjost/spag_lapack", "max_issues_repo_head_hexsha": "1b082638c0ff5feb1a295a3aa4624c538d14847c", "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": "src/complex/cladiv.f90", "max_forks_repo_name": "urbanjost/spag_lapack", "max_forks_repo_head_hexsha": "1b082638c0ff5feb1a295a3aa4624c538d14847c", "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": 24.4646464646, "max_line_length": 111, "alphanum_fraction": 0.5606936416, "num_tokens": 731, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648677, "lm_q2_score": 0.7520125793176223, "lm_q1q2_score": 0.6573170761391481}} {"text": " Program dgerqf_example\n\n! DGERQF Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_interfaces, Only: dgerqf, dormrq, dtrtrs\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Real (Kind=dp), Parameter :: zero = 0.0E0_dp\n Integer, Parameter :: nb = 64, nin = 5, nout = 6\n! .. Local Scalars ..\n Integer :: i, info, lda, lwork, m, n\n! .. Local Arrays ..\n Real (Kind=dp), Allocatable :: a(:, :), b(:), tau(:), work(:), x(:)\n! .. Executable Statements ..\n Write (nout, *) 'DGERQF Example Program Results'\n Write (nout, *)\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) m, n\n lda = m\n lwork = nb*m\n Allocate (a(lda,n), b(m), tau(m), work(lwork), x(n))\n\n! Read the matrix A and the vector b from data file\n\n Read (nin, *)(a(i,1:n), i=1, m)\n Read (nin, *) b(1:m)\n\n! Compute the RQ factorization of A\n Call dgerqf(m, n, a, lda, tau, work, lwork, info)\n\n! Copy the m element vector b into elements x(n-m+1), ..., x(n) of x\n\n x(n-m+1:n) = b(1:m)\n\n! Solve R*y2 = b, storing the result in x2\n Call dtrtrs('Upper', 'No transpose', 'Non-Unit', m, 1, a(1,n-m+1), lda, &\n x(n-m+1), m, info)\n\n If (info>0) Then\n Write (nout, *) 'The upper triangular factor, R, of A is singular, '\n Write (nout, *) 'the least squares solution could not be computed'\n Else\n\n x(1:n-m) = zero\n\n! Compute the minimum-norm solution x = (Q**T)*y\n Call dormrq('Left', 'Transpose', n, 1, m, a, lda, tau, x, n, work, &\n lwork, info)\n\n! Print minimum-norm solution\n\n Write (nout, *) 'Minimum-norm solution'\n Write (nout, 100) x(1:n)\n\n End If\n\n100 Format (1X, 8F9.4)\n End Program\n", "meta": {"hexsha": "4f8a92679ddc1676887b169b74c1684200c25c65", "size": 2015, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/dgerqf_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/dgerqf_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/dgerqf_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 30.0746268657, "max_line_length": 90, "alphanum_fraction": 0.5602977667, "num_tokens": 645, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648676, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6573170761391479}} {"text": " SUBROUTINE quad3d(x1,x2,ss)\r\n REAL ss,x1,x2,h\r\n EXTERNAL h\r\nCU USES h,qgausx\r\n call qgausx(h,x1,x2,ss)\r\n return\r\n END\r\n FUNCTION f(zz)\r\n REAL f,zz,func,x,y,z\r\n COMMON /xyz/ x,y,z\r\nCU USES func\r\n z=zz\r\n f=func(x,y,z)\r\n return\r\n END\r\n FUNCTION g(yy)\r\n REAL g,yy,f,z1,z2,x,y,z\r\n EXTERNAL f\r\n COMMON /xyz/ x,y,z\r\nCU USES f,qgausz,z1,z2\r\n REAL ss\r\n y=yy\r\n call qgausz(f,z1(x,y),z2(x,y),ss)\r\n g=ss\r\n return\r\n END\r\n FUNCTION h(xx)\r\n REAL h,xx,g,y1,y2,x,y,z\r\n EXTERNAL g\r\n COMMON /xyz/ x,y,z\r\nCU USES g,qgausy,y1,y2\r\n REAL ss\r\n x=xx\r\n call qgausy(g,y1(x),y2(x),ss)\r\n h=ss\r\n return\r\n END\r\n", "meta": {"hexsha": "b7312e92ef6241266cfdd2021eefb71613341778", "size": 758, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/quad3d.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/quad3d.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/quad3d.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": 19.9473684211, "max_line_length": 40, "alphanum_fraction": 0.4722955145, "num_tokens": 277, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.874077222043951, "lm_q2_score": 0.7520125848754472, "lm_q1q2_score": 0.6573170711300218}} {"text": " function fuel(mass)\n integer mass, fuel\n fuel = 0\n\n 98 mass = mass / 3 - 2\n if (mass .lt. 1) go to 99\n fuel = fuel + mass\n go to 98\n \n 99 return\n end function\n \n program day01\n integer x, part1, part2, fuel\n part1 = 0\n part2 = 0\n\n 1 read (*,*,END=2) x\n part1 = part1 + x / 3 - 2\n part2 = part2 + fuel(x)\n goto 1\n\n 2 write(*,*) part1, part2\n stop\n end\n", "meta": {"hexsha": "358bf17752fea4d7ccdf2f7e0eb7a98657ed3f4d", "size": 500, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "day01.f", "max_stars_repo_name": "anthony-arnold/advent-2019", "max_stars_repo_head_hexsha": "583938ce1ee0c0ce719deb5c0492d00f8397062b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-09-16T04:28:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-16T04:28:15.000Z", "max_issues_repo_path": "day01.f", "max_issues_repo_name": "anthony-arnold/advent-2019", "max_issues_repo_head_hexsha": "583938ce1ee0c0ce719deb5c0492d00f8397062b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "day01.f", "max_forks_repo_name": "anthony-arnold/advent-2019", "max_forks_repo_head_hexsha": "583938ce1ee0c0ce719deb5c0492d00f8397062b", "max_forks_repo_licenses": ["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.2307692308, "max_line_length": 39, "alphanum_fraction": 0.424, "num_tokens": 161, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213853793453, "lm_q2_score": 0.731058584489497, "lm_q1q2_score": 0.6573104072796597}} {"text": "program problem77\n implicit none\n integer, parameter :: ms=100,ps=664579,limit=5000\n integer, dimension(ps) :: primes\n integer, dimension(ms) :: memo\n integer :: i,a\n\n open(33,file='./data/problem70.dat')\n read(33,*) primes\n\n ! https://oeis.org/A000607\n do i=1,ms\n memo(i)=-1\n end do\n memo(1:10)=(/ 0, 1, 1, 1, 2, 2, 3, 3, 4, 5 /)\n\n i=1\n a=1\n do while(a<=limit)\n i=i+1\n a=a000607(i)\n end do\n print *, i\n\ncontains\n\n ! https://oeis.org/A000607\n ! a(n) = (1/n)*Sum_{k=1..n} A008472(k)*a(n-k)\n recursive function a000607(n) result(r)\n implicit none\n integer, intent(in) :: n\n integer :: k,r\n\n if (n<0) then\n r=1\n return\n else if (n==0) then\n r=1\n return\n else\n if (memo(n) /= -1) then\n r=memo(n)\n return\n else\n r=0\n do k=1,n\n r=r+(a008472(k)*a000607(n-k))\n end do\n r=r/n\n if (n<=ms) memo(n)=r\n return\n end if\n end if\n \n end function a000607\n \n ! https://oeis.org/A008472\n pure function a008472(n)\n implicit none\n integer, intent(in) :: n\n integer :: p,a008472,i,rest\n\n a008472=0\n rest=n\n do i=1,n\n p=primes(i)\n if (mod(rest,p)==0) then\n a008472=a008472+p\n do while (mod(rest,p)==0)\n rest=rest/p\n end do\n end if\n\n ! Important: if the current prime is more than the square root\n ! of what is left, then what is left must be the last prime\n ! factor.\n if (p>sqrt(real(rest))) then\n if (rest>1) a008472=a008472+rest\n exit\n end if\n end do\n\n end function a008472\n\nend program problem77\n", "meta": {"hexsha": "47178f67683eae6443fe5ef286fdeb8815964ba5", "size": 1731, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "problem77.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": "problem77.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": "problem77.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": 20.1279069767, "max_line_length": 69, "alphanum_fraction": 0.5135759676, "num_tokens": 578, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213853793452, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6573104020112649}} {"text": "*DECK DVNRMS\n DOUBLE PRECISION FUNCTION DVNRMS (N, V, W)\nC***BEGIN PROLOGUE DVNRMS\nC***SUBSIDIARY\nC***PURPOSE Subsidiary to DDEBDF\nC***LIBRARY SLATEC\nC***TYPE DOUBLE PRECISION (VNWRMS-S, DVNRMS-D)\nC***AUTHOR (UNKNOWN)\nC***DESCRIPTION\nC\nC DVNRMS computes a weighted root-mean-square vector norm for the\nC integrator package DDEBDF.\nC\nC***SEE ALSO DDEBDF\nC***ROUTINES CALLED (NONE)\nC***REVISION HISTORY (YYMMDD)\nC 820301 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890831 Modified array declarations. (WRB)\nC 890911 Removed unnecessary intrinsics. (WRB)\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900328 Added TYPE section. (WRB)\nC***END PROLOGUE DVNRMS\n INTEGER I, N\n DOUBLE PRECISION SUM, V, W\n DIMENSION V(*),W(*)\nC***FIRST EXECUTABLE STATEMENT DVNRMS\n SUM = 0.0D0\n DO 10 I = 1, N\n SUM = SUM + (V(I)/W(I))**2\n 10 CONTINUE\n DVNRMS = SQRT(SUM/N)\n RETURN\nC ----------------------- END OF FUNCTION DVNRMS\nC ------------------------\n END\n", "meta": {"hexsha": "57f3bc188ad4cec26412822227d82a6d33714420", "size": 1085, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/dvnrms.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/dvnrms.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/dvnrms.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.3243243243, "max_line_length": 67, "alphanum_fraction": 0.6304147465, "num_tokens": 375, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636752, "lm_q2_score": 0.7310585844894971, "lm_q1q2_score": 0.6573103973989132}} {"text": "SUBROUTINE linear(a,b,Du,Dv,dt,modescalereal,coef,kx,ky,kz,u,v,uhat,vhat,decomp) \n\t!--------------------------------------------------------------------\n\t!\n\t!\n\t! PURPOSE\n\t!\n\t! This subroutine solves the linear equation in a splitting \n\t! method for the Brusselator equation in 3 dimensions\n\t! u_t = a + u^2v - (b+1)u + Du (u_xx + u_yy + u_zz)\n ! v_t = bu - u^2v + Dv (v_xx + v_yy + v_zz)\n\t!\n\t!\n\t! INPUT\n\t!\n\t! .. Parameters ..\n\t! a = equation parameter\n\t! b = equation parameter\n\t! Du = equation diffusion coefficient\n\t! Dv = equation diffusion coefficient\n ! modescalereal = scaling of terms after forward and backward FFT\n\t! dt\t\t\t\t= timestep\n\t! coef\t\t\t\t= (complex) timestep coefficient\n\t! .. Arrays ..\n\t! kx = Fourier wave numbers in x direction\n\t! ky = Fourier wave numbers in y direction\n\t! kz = Fourier wave numbers in z direction\t\n\t! u\t\t\t\t= u field\n\t! v\t\t\t\t= v field\n\t! uhat\t\t\t\t= storage for u field in Fourier space \n\t! vhat\t\t\t\t= storage for v field in Fourier space\n\t! .. Special Structures ..\n\t! decomp\t\t\t= contains information on domain decomposition\n\t!\t\t\t\t\tsee http://www.2decomp.org/ for more information\n\t! OUTPUT\n\t!\n\t! .. Arrays ..\n\t! u \t\t\t\t= updated u field\n\t! v \t\t\t\t= updated v field\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! k\t\t\t\t= loop counter in z direction\n\t! temp = temporary storage variable\n\t! uhattemp = temporary storage variable\n\t! vhattemp = temporary storage variable\n\t! uhatstore = temporary storage variable\n\t! vhatstore = temporary storage variable\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! 2DECOMP&FFT\t -- Domain decomposition and Fast Fourier Library\n\t!\t\t\t(http://www.2decomp.org/index.html)\n\t! MPI library\n\tUSE decomp_2d\n\tUSE decomp_2d_fft\t\n\tIMPLICIT NONE\t\t\t\t\t \n\tINCLUDE 'mpif.h'\n\t! Declare variables\n\tTYPE(DECOMP_INFO), INTENT(IN)\t\t\t\t\t\t :: decomp\n\tREAL(KIND=8), INTENT(IN) :: dt,a,b,Du,Dv,modescalereal\n\tCOMPLEX(KIND=8), INTENT(IN) :: coef\n\tCOMPLEX(kind=8), DIMENSION(decomp%zst(1):decomp%zen(1)), INTENT(IN) :: kx\n\tCOMPLEX(kind=8), DIMENSION(decomp%zst(2):decomp%zen(2)), INTENT(IN) :: ky\n\tCOMPLEX(kind=8), DIMENSION(decomp%zst(3):decomp%zen(3)), INTENT(IN) :: kz\t\n\tCOMPLEX(KIND=8), DIMENSION(decomp%xst(1):decomp%xen(1),&\n \t\t\t\t\t\t\t decomp%xst(2):decomp%xen(2),&\n \t\t\t\t\t\t\t decomp%xst(3):decomp%xen(3)),&\n \t\t\t\t\t\t\t\t\t\t\t INTENT(INOUT) :: u,v\n\tCOMPLEX(KIND=8), DIMENSION(decomp%zst(1):decomp%zen(1),&\n decomp%zst(2):decomp%zen(2),&\n decomp%zst(3):decomp%zen(3)),&\n \t\t\t\t\t\t\t\t\t\t\tINTENT(OUT) :: uhat,vhat\n\tINTEGER(kind=4)\t\t\t\t\t\t\t\t\t\t :: i,j,k\n\tCOMPLEX(kind=8) :: uhattemp,vhattemp,uhatstore,vhatstore\n\tCALL decomp_2d_fft_3d(u,uhat,DECOMP_2D_FFT_FORWARD)\n\tCALL decomp_2d_fft_3d(v,vhat,DECOMP_2D_FFT_FORWARD)\n\tIF ((decomp%zst(3).eq.1).and.(decomp%zst(2).eq.1).and.(decomp%zst(1).eq.1)) THEN\n\t uhattemp=uhat(1,1,1)\n\t vhattemp=vhat(1,1,1)\n\tEND IF\n \tDO k=decomp%zst(3),decomp%zen(3); DO j=decomp%zst(2),decomp%zen(2); DO i=decomp%zst(1),decomp%zen(1)\n \t uhatstore=uhat(i,j,k)\n \t vhatstore=vhat(i,j,k)\n \t vhat(i,j,k)=vhatstore*exp(coef*dt*Dv*(kx(i)**2+ky(j)**2+kz(k)**2)) &\n \t \t +b*uhatstore*(exp(coef*dt*Dv*(kx(i)**2+ky(j)**2+kz(k)**2)) &\n \t \t\t -exp(coef*dt*(Du*(kx(i)**2+ky(j)**2+kz(k)**2)-b-1.0d0) )) &\n \t \t /(b+1.0d0-(Du-Dv)*(kx(i)**2+ky(j)**2+kz(k)**2))\n \t uhat(i,j,k)=uhatstore*exp( coef*dt*(-b-1.0d0+Du*( kx(i)**2 + ky(j)**2 + kz(k)**2 )) ) \n \tEND DO; END DO; END DO\n\tIF ((decomp%zst(3).eq.1).and.(decomp%zst(2).eq.1).and.(decomp%zst(1).eq.1)) THEN\n\t uhat(1,1,1)=uhattemp*exp(-coef*dt*(b+1.0d0))+&\n\t (a/modescalereal)*(1.0d0-exp(-coef*dt*(b+1.0d0)))/(b+1.0d0)\n\t vhat(1,1,1)=vhattemp+b*( (exp(-(b+1)*coef*dt)-1.0d0)* &\n\t\t\t (-uhattemp+(a/modescalereal)/(b+1.0d0))/(b+1.0d0) &\n\t\t\t +(a/modescalereal)*coef*dt/(b+1.0d0))\n\tEND IF\n\t! don't forget to scale\n\tCALL decomp_2d_fft_3d(uhat,u,DECOMP_2D_FFT_BACKWARD)\n\tCALL decomp_2d_fft_3d(vhat,v,DECOMP_2D_FFT_BACKWARD)\n\tDO k=decomp%xst(3),decomp%xen(3); DO j=decomp%xst(2),decomp%xen(2); DO i=decomp%xst(1),decomp%xen(1)\n\t u(i,j,k)=u(i,j,k)*modescalereal\n\t v(i,j,k)=v(i,j,k)*modescalereal\n\tEND DO; END DO; END DO\n\tEND SUBROUTINE linear\n", "meta": {"hexsha": "89c0f7a11e5f176e92f378d2e76accecccbca5f2", "size": 4849, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Brusselator/linear.f90", "max_stars_repo_name": "openmichigan/PSNM", "max_stars_repo_head_hexsha": "1016b09635b6a29491ed52e32801fd0beaf471f0", "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": "Brusselator/linear.f90", "max_issues_repo_name": "openmichigan/PSNM", "max_issues_repo_head_hexsha": "1016b09635b6a29491ed52e32801fd0beaf471f0", "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": "Brusselator/linear.f90", "max_forks_repo_name": "openmichigan/PSNM", "max_forks_repo_head_hexsha": "1016b09635b6a29491ed52e32801fd0beaf471f0", "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": 40.4083333333, "max_line_length": 104, "alphanum_fraction": 0.5718704888, "num_tokens": 1732, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213691605412, "lm_q2_score": 0.7310585786300048, "lm_q1q2_score": 0.6573103901543691}} {"text": " Program dgeev_example\n\n! DGEEV Example Program Text\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_interfaces, Only: dgeev\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Real (Kind=dp), Parameter :: zero = 0.0_dp\n Integer, Parameter :: nb = 64, nin = 5, nout = 6\n! .. Local Scalars ..\n Complex (Kind=dp) :: eig\n Real (Kind=dp) :: alpha, beta, scale\n Integer :: i, info, j, k, lda, ldvr, lwork, n\n! .. Local Arrays ..\n Real (Kind=dp), Allocatable :: a(:, :), vr(:, :), wi(:), work(:), wr(:)\n Real (Kind=dp) :: dummy(1, 1)\n! .. Intrinsic Procedures ..\n Intrinsic :: cmplx, max, maxloc, nint, sqrt\n! .. Executable Statements ..\n Write (nout, *) 'DGEEV Example Program Results'\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n\n lda = n\n ldvr = n\n Allocate (a(lda,n), vr(ldvr,n), wi(n), wr(n))\n\n! Use routine workspace query to get optimal workspace.\n lwork = -1\n Call dgeev('No left vectors', 'Vectors (right)', n, a, lda, wr, wi, &\n dummy, 1, vr, ldvr, dummy, lwork, info)\n\n! Make sure that there is enough workspace for block size nb.\n lwork = max((nb+2)*n, nint(dummy(1,1)))\n Allocate (work(lwork))\n\n! Read the matrix A from data file\n\n Read (nin, *)(a(i,1:n), i=1, n)\n\n! Compute the eigenvalues and right eigenvectors of A\n\n Call dgeev('No left vectors', 'Vectors (right)', n, a, lda, wr, wi, &\n dummy, 1, vr, ldvr, work, lwork, info)\n\n If (info==0) Then\n\n! Print solution\n\n Do j = 1, n\n Write (nout, *)\n If (wi(j)==zero) Then\n Write (nout, 100) 'Eigenvalue(', j, ') = ', wr(j)\n Else\n eig = cmplx(wr(j), wi(j), kind=dp)\n Write (nout, 110) 'Eigenvalue(', j, ') = ', eig\n End If\n Write (nout, *)\n Write (nout, 120) 'Eigenvector(', j, ')'\n If (wi(j)==zero) Then\n! Scale by making largest element positive\n k = maxloc(vr(1:n,j), 1)\n If (vr(k,j)0.0E0_dp) Then\n! Scale by making largest element real and positive\n work(1:n) = vr(1:n, j)**2 + vr(1:n, j+1)**2\n k = maxloc(work(1:n), 1)\n scale = sqrt(work(k))\n work(1:n) = vr(1:n, j)\n alpha = vr(k, j)/scale\n beta = vr(k, j+1)/scale\n vr(1:n, j) = alpha*work(1:n) + beta*vr(1:n, j+1)\n vr(1:n, j+1) = alpha*vr(1:n, j+1) - beta*work(1:n)\n Write (nout, 140)(vr(i,j), vr(i,j+1), i=1, n)\n Else\n Write (nout, 140)(vr(i,j-1), -vr(i,j), i=1, n)\n End If\n End Do\n Else\n Write (nout, *)\n Write (nout, 150) 'Failure in DGEEV. INFO = ', info\n End If\n\n100 Format (1X, A, I2, A, 1P, E11.4)\n110 Format (1X, A, I2, A, '(', 1P, E11.4, ',', 1P, E11.4, ')')\n120 Format (1X, A, I2, A)\n130 Format (1X, 1P, E11.4)\n140 Format (1X, '(', 1P, E11.4, ',', 1P, E11.4, ')')\n150 Format (1X, A, I4)\n End Program\n", "meta": {"hexsha": "c58de974d8f1c8aa4248a68c42b384ab065dedd8", "size": 3401, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/dgeev_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/dgeev_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/dgeev_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 34.01, "max_line_length": 90, "alphanum_fraction": 0.5080858571, "num_tokens": 1148, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636752, "lm_q2_score": 0.7310585727705126, "lm_q1q2_score": 0.6573103868621237}} {"text": "!> Author: Jabir Ali Ouassou\n!> Category: Foundation\n!>\n!> This file provides a common interface to a large library of mathematical\n!> functions and subroutines. See the documentation of individual interfaces\n!> below for more information about the contents of the mathematical library.\n\nmodule math_m\n use :: basic_m\n use :: calculus_m\n use :: matrix_m\n private\n\n !------------------------------------------------------------\n ! Public interface\n !------------------------------------------------------------\n\n ! Floating-point precision\n public :: sp, dp, qp, wp\n\n ! Numerical constants\n public :: inf, eps, pi\n\n ! Basic routines\n public :: unitvector, nonzero, re, im, cx, arg\n\n ! Matrix routines\n public :: trace, diag, inverse, identity, commutator, anticommutator\n\n ! Calculus routines\n public :: mean, differentiate, integrate, interpolate, linspace\n\n !------------------------------------------------------------\n ! Interfaces for working with matrices\n !------------------------------------------------------------\n\n interface trace\n !! Public interface for functions that calculate a matrix trace.\n module procedure matrix_trace ! Trace of a matrix\n end interface\n\n interface inverse\n !! Public interface for functions that calculate a matrix inverse.\n module procedure matrix_inverse_re, & ! Inverse of a real matrix\n matrix_inverse_cx ! Inverse of a complex matrix\n end interface\n \n interface diag\n !! Public interface for functions that deal with matrix diagonals.\n module procedure matrix_diag, & ! Construct a diagonal matrix\n vector_diag ! Extract a matrix diagonal\n end interface\n\n !------------------------------------------------------------\n ! Interfaces for calculus routines\n !------------------------------------------------------------\n\n interface mean\n !! Public interface for routines that calculate the mean value.\n module procedure mean_array_re, & ! Mean of a real array\n mean_array_cx ! Mean of a complex array\n end interface\n\n interface differentiate\n !! Public interface for various differentiation routines.\n module procedure differentiate_array_re, & ! Derivative of a real array\n differentiate_array_cx ! Derivative of a complex array\n end interface\n\n interface integrate\n !! Public interface for various integration routines.\n module procedure integrate_array_re, & ! Trapezoid integration of a real array\n integrate_array_cx, & ! Trapezoid integration of a complex array\n integrate_range_re, & ! Interpolated integration of a real array\n integrate_range_cx ! Interpolated integration of a complex array\n end interface\n\n interface interpolate\n !! Public interface for various interpolation routines.\n module procedure interpolate_point_re, & ! Interpolate a scalar function from a real array to a point\n interpolate_point_cx, & ! Interpolate a scalar function from a complex array to a point\n interpolate_array_re, & ! Interpolate a scalar function from a real array to an array\n interpolate_array_cx, & ! Interpolate a scalar function from a complex array to an array\n interpolate_point_matrix_re ! Interpolate a matrix function from a real array array to a point\n end interface \n\n interface linspace\n !! Public interface for routines that initialize arrays.\n module procedure linspace_array_re ! Linearly spaced real numbers\n end interface\n\nend module\n", "meta": {"hexsha": "11d181f9af284b67234af1ded4df64a56429b769", "size": 3743, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/foundation/math.f", "max_stars_repo_name": "jabirali/NEUS", "max_stars_repo_head_hexsha": "f9e3f18a45c84272ebaafcb7b834eebf47acb9b8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-04-22T02:20:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-11T08:43:07.000Z", "max_issues_repo_path": "src/foundation/math.f", "max_issues_repo_name": "jabirali/NEUS", "max_issues_repo_head_hexsha": "f9e3f18a45c84272ebaafcb7b834eebf47acb9b8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/foundation/math.f", "max_forks_repo_name": "jabirali/NEUS", "max_forks_repo_head_hexsha": "f9e3f18a45c84272ebaafcb7b834eebf47acb9b8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-07-11T03:24:08.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-11T03:24:08.000Z", "avg_line_length": 40.247311828, "max_line_length": 118, "alphanum_fraction": 0.6128773711, "num_tokens": 706, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767906859264, "lm_q2_score": 0.7490872187162397, "lm_q1q2_score": 0.6573066486229727}} {"text": "MODULE Meltingmod\n IMPLICIT NONE\nCONTAINS\n\n SUBROUTINE model_melting(jul, &\n Tmf, &\n DKmax, &\n Kmin, &\n tavg, &\n M)\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: jul\n REAL, INTENT(IN) :: Tmf\n REAL, INTENT(IN) :: DKmax\n REAL, INTENT(IN) :: Kmin\n REAL, INTENT(IN) :: tavg\n REAL, INTENT(OUT) :: M\n REAL:: K\n !- Name: Melting -Version: 1.0, -Time step: 1\n !- Description:\n ! * Title: snow in the process of melting\n ! * Author: STICS\n ! * Reference: doi:http://dx.doi.org/10.1016/j.agrformet.2014.05.002\n ! * Institution: INRA\n ! * Abstract: It simulates snow in the process of melting\n !- inputs:\n ! * name: jul\n ! ** description : current day of year for the calculation\n ! ** inputtype : variable\n ! ** variablecategory : auxiliary\n ! ** datatype : INT\n ! ** default : 0\n ! ** min : 0\n ! ** max : 366\n ! ** unit : d\n ! ** uri : \n ! * name: Tmf\n ! ** description : threshold temperature for snow melting \n ! ** inputtype : parameter\n ! ** parametercategory : constant\n ! ** datatype : DOUBLE\n ! ** default : 0.5\n ! ** min : 0.0\n ! ** max : 1.0\n ! ** unit : degC\n ! ** uri : \n ! * name: DKmax\n ! ** description : difference between the maximum and the minimum melting rates\n ! ** inputtype : parameter\n ! ** parametercategory : constant\n ! ** datatype : DOUBLE\n ! ** default : 0.0\n ! ** min : 0.0\n ! ** max : 5000.0\n ! ** unit : mmW/degC/d\n ! ** uri : \n ! * name: Kmin\n ! ** description : minimum melting rate on 21 December\n ! ** inputtype : parameter\n ! ** parametercategory : constant\n ! ** datatype : DOUBLE\n ! ** default : 0.0\n ! ** min : 0.0\n ! ** max : 5000.0\n ! ** unit : mmW/degC/d\n ! ** uri : \n ! * name: tavg\n ! ** description : average temperature\n ! ** inputtype : variable\n ! ** variablecategory : auxiliary\n ! ** datatype : DOUBLE\n ! ** default : 0.0\n ! ** min : 0.0\n ! ** max : 100.0\n ! ** unit : degC\n ! ** uri : \n !- outputs:\n ! * name: M\n ! ** description : snow in the process of melting\n ! ** variablecategory : rate\n ! ** datatype : DOUBLE\n ! ** min : 0.0\n ! ** max : 500.0\n ! ** unit : mmW/d\n ! ** uri : \n M = 0.0\n K = DKmax / 2.0 * (-SIN((2.0 * 3.14159265 * REAL(jul) / 366.0 + (9.0 &\n / 16.0 * 3.14159265)))) + Kmin + (DKmax / 2.0)\n IF(tavg .GT. Tmf) THEN\n M = K * (tavg - Tmf)\n END IF\n END SUBROUTINE model_melting\n\nEND MODULE\n", "meta": {"hexsha": "63d4d0ff3486fd8fc578a9b734a64f6493d2c47c", "size": 4036, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/stics/STICS_SNOW/Melting.f90", "max_stars_repo_name": "Crop2ML-Catalog/STICS_SNOW", "max_stars_repo_head_hexsha": "26ed2a9a30e068d72d5589b1dc64916c1b07fa09", "max_stars_repo_licenses": ["MIT"], "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/stics/STICS_SNOW/Melting.f90", "max_issues_repo_name": "Crop2ML-Catalog/STICS_SNOW", "max_issues_repo_head_hexsha": "26ed2a9a30e068d72d5589b1dc64916c1b07fa09", "max_issues_repo_licenses": ["MIT"], "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/stics/STICS_SNOW/Melting.f90", "max_forks_repo_name": "Crop2ML-Catalog/STICS_SNOW", "max_forks_repo_head_hexsha": "26ed2a9a30e068d72d5589b1dc64916c1b07fa09", "max_forks_repo_licenses": ["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.4842105263, "max_line_length": 108, "alphanum_fraction": 0.3270564916, "num_tokens": 920, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.7490872131147275, "lm_q1q2_score": 0.657306641307636}} {"text": "! RUN: %python %S/test_folding.py %s %flang_fc1\n! Tests folding of DBLE()\nmodule ft_data\n integer nx, ny, nz\n parameter (nx=64, ny=64, nz=64, maxdim=64)\n double precision ntotal_f\n parameter (ntotal_f = dble(nx)*ny*nz)\n logical, parameter :: test_dble_1 = ntotal_f == real(nx*ny*nz, kind(0.0D0))\n logical, parameter :: test_dble_2 = kind(dble(nx)) == kind(0.0D0)\nend module ft_data\n", "meta": {"hexsha": "523fa8c520672ff59c44e07e8177f9c54c61a1c8", "size": 389, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "flang/test/Evaluate/fold-dble.f90", "max_stars_repo_name": "akashhansda/llvm-project", "max_stars_repo_head_hexsha": "32f146010968ded160f54af464673451ad574135", "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": "flang/test/Evaluate/fold-dble.f90", "max_issues_repo_name": "akashhansda/llvm-project", "max_issues_repo_head_hexsha": "32f146010968ded160f54af464673451ad574135", "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": "flang/test/Evaluate/fold-dble.f90", "max_forks_repo_name": "akashhansda/llvm-project", "max_forks_repo_head_hexsha": "32f146010968ded160f54af464673451ad574135", "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.3636363636, "max_line_length": 77, "alphanum_fraction": 0.6966580977, "num_tokens": 141, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767746654974, "lm_q2_score": 0.7490872187162397, "lm_q1q2_score": 0.6573066366222741}} {"text": "C AREBENCH.F - Gateway function to generate the benchmark examples\nC for algebraic Riccati equations using SLICOT routines\nC BB01AD, for continuous-time case, and BB02AD, for\nC discrete-time case.\nC\nC RELEASE 2.0 of SLICOT Basic Systems and Control Toolbox.\nC Based on SLICOT RELEASE 5.7. Copyright (c) 2002-2020 NICONET e.V.\nC\nC Matlab call:\nC [X,A,G,Q(,B,C)(,S)(,parval)] = arebench(dico,nr1,nr2 ...\nC (,flag,param,opt,filnam))\nC\nC Purpose:\nC To generate benchmark examples for continuous-time algebraic\nC Riccati equations (CARE)\nC\nC 0 = Q + A'X + XA - XGX,\nC\nC where A,G,Q,X are real N-by-N matrices, Q and G are symmetric and\nC may be given in factored form\nC -1 T T\nC (I) G = B R B , (II) Q = C W C ,\nC where C is P-by-N, W P-by-P, B N-by-M, and R M-by-M, where W\nC and R are symmetric,\nC\nC or\nC\nC to generate benchmark examples for the discrete-time algebraic\nC Riccati equations (DARE)\nC T T T -1 T T\nC 0 = A X A - X - (A X B + S) (R + B X B) (B X A + S ) + Q,\nC\nC where the matrices Q and R are symmetric and Q may be given in\nC factored form (II).\nC If R is nonsingular and S = 0, the DARE can be rewritten as\nC T -1\nC 0 = X - A X (I_n + G X) A - Q,\nC\nC where I_n is the N-by-N identity matrix and G is factored as in (I).\nC\nC Input parameters:\nC dico - integer option to indicate continuous- or discrete-time:\nC = 1 : continuous-time example.\nC = 2 : discrete-time example.\nC nr1 - the group of examples:\nC = 1 : parameter-free problems of fixed size.\nC = 2 : parameter-dependent problems of fixed size.\nC = 3 : parameter-free problems of scalable size.\nC = 4 : parameter-dependent problems of scalable size.\nC nr2 - the number of the example in group nr1.\nC Let NEXi be the number of examples in group i. Currently,\nC NEX1 = 6, NEX2 = 9, NEX3 = 2, NEX4 = 4, for\nC continuous-time,\nC NEX1 = 13, NEX2 = 5, NEX3 = 0, NEX4 = 1, for discrete-time.\nC 1 <= nr1 <= 4;\nC 1 <= nr2 <= NEXi , where i = nr1.\nC flag - (optional) vector containing options:\nC flag(1) = 1 : G is returned.\nC flag(1) = 0 : G is returned in factored form, i.e.,\nC B and R from (I) are returned.\nC flag(2) = 1 : Q is returned.\nC flag(2) = 0 : Q is returned in factored form, i.e.,\nC C and W from (II) are returned.\nC If dico = 1, it has size 2; if dico = 2, it has size 3:\nC flag(3) = 1 : The coefficient matrix S of the DARE\nC is returned in array S.\nC flag(3) = 0 : The coefficient matrix S of the DARE\nC is not returned.\nC param - (optional) real vector of parameter values:\nC = epsilon, if dico = 1, nr1 = 2;\nC = [q,r], if dico = 1, for 4.1 (i.e., nr1 = 4, nr2 = 1);\nC = [a,b,c,beta1,beta2,gamma1,gamma2], if dico = 1, for 4.2;\nC = [mu,delta,kappa], if dico = 1, nr1 = 4, nr2 = 3;\nC = epsilon, if dico = 2, nr1 = 2, nr2 = 2:4;\nC = [tau,D,K,r], if dico = 2, nr1 = 2, nr2 = 5;\nC = R, if dico = 2, nr1 = 2, nr2 = 1 or nr1 = 4, nr2 = 1;\nC opt - (optional) integer vector for additional\nC options/parameters:\nC if dico = 1,\nC = 1, (when nr1 = 2, nr2 = 9): generates the CARE for\nC optimal state feedback (default);\nC = 2, (when nr1 = 2, nr2 = 9): generates the\nC Kalman filter CARE.\nC = the number of vehicles, if nr1 = 3, nr2 = 1.\nC = the order of the matrix A, for 3.2, 4.1 or 4.2.\nC = the dimension of the second-order system, i.e., the\nC order of the stiffness matrix for 4.3 or 4.4.\nC if dico = 2,\nC = the order of the output matrix A, for 4.1.\nC filnam - (optional) if nr1 = nr2 = 4 and opt differs from the\nC default dimension of the second-order system (211), a\nC character string containing the name of the data file\nC to be used.\nC Output parameters:\nC X - real symmetric solution of Riccati equation (an exact\nC solution is available for the continuous-time examples\nC 1.1, 1.2, 2.1, 2.3-2.6, 3.2, and for the discrete-time\nC examples 1.1, 1.3, 1.4, 2.1, 2.3-2.5, 4.1;\nC otherwise, X is an empty array).\nC A - real n-by-n coefficient matrix.\nC G - real symmetric n-by-n matrix.\nC If flag(1) = 1, then a non-factored coefficient matrix G\nC of the ARE is returned.\nC If flag(1) = 0, then array G contains the\nC 'control weighting matrix' R from (I).\nC Q - real symmetric n-by-n matrix.\nC If flag(2) = 1, then a non-factored coefficient matrix Q\nC of the ARE is returned.\nC If flag(2) = 0, then array Q contains the\nC 'output weighting matrix' W from (II).\nC B - real n-by-m input matrix.\nC If flag(1) = 0, this array contains the coefficient\nC matrix B of the ARE.\nC C - real p-by-n output matrix.\nC If flag(2) = 0, this array contains the coefficient\nC matrix C of the ARE.\nC S - if (dico = 2, flag(3) = 1), then this array contains the\nC coefficient matrix S of the DARE.\nC parval - the values used for the problem parameters:\nC either the values given in param, or default values,\nC if param is not used.\nC\nC Contributor:\nC D. Sima, University of Bucharest, August 2001.\nC\nC Revisions:\nC V. Sima, Research Institute for Informatics, Nov. 2001, Oct. 2004,\nC Apr. 2009, Dec. 2012, May 2016, Jan. 2017.\nC\nC **********************************************************************\nC\nC\n SUBROUTINE MEXFUNCTION( NLHS, PLHS, NRHS, PRHS )\nC\nC .. Mex-file interface parameters ..\n INTEGER PLHS(*), PRHS(*)\n INTEGER*4 NLHS, NRHS\nC\nC .. Mex-file integer functions ..\n INTEGER mxCreateDoubleMatrix, mxGetPr\n INTEGER*4 mxGetM, mxGetN, mxGetString, mxIsChar,\n $ mxIsNumeric, mxIsComplex\nC\nC .. Parameters ..\nC . # of examples available , # of examples with fixed size. .\n INTEGER NEXC1, NEXC2, NEXC3, NEXC4, NEXD1, NEXD2, NEXD3,\n $ NEXD4, NMX\n PARAMETER ( NEXC1 = 6, NEXC2 = 9, NEXC3 = 2, NEXC4 = 4,\n $ NEXD1 = 13, NEXD2 = 5, NEXD3 = 0, NEXD4 = 1,\n $ NMX = 13 )\nC\nC .. Scalar parameters used by SLICOT subroutines ..\n CHARACTER DEF\n INTEGER INFO, LDA, LDB, LDC, LDG, LDQ, LDS, LDWORK, LDX,\n $ M, N, P\nC\nC .. Allocatable arrays ..\nC !Fortran 90/95 (Fixed dimensions should be used with Fortran 77.)\n DOUBLE PRECISION, ALLOCATABLE :: A(:,:), B(:,:), C(:,:),\n $ DWORK(:), G(:,:), Q(:,:), S(:,:),\n $ X(:,:)\nC\nC .. Local variables and constant dimension arrays ..\n LOGICAL BPAR(7), VEC(10)\n CHARACTER*255 CHPAR\n CHARACTER*120 TEXT\n INTEGER DICO, FLAG(3), I, IE, IP, IPAR(4), ISIZE, L,\n $ MDEFC(2,NMX), MDEFD(2,NMX), NDEFC(4,NMX),\n $ NDEFD(4,NMX), NEX(4), NEXC(4), NEXD(4), NR(2),\n $ PDEFC(2,NMX), PDEFD(2,NMX)\n DOUBLE PRECISION DPAR(7), FLAGR(3), ITMP(7), TEMP\nC\nC .. External functions ..\n LOGICAL LSAME\n EXTERNAL LSAME\nC\nC .. External subroutines ..\n EXTERNAL BB01AD, BB02AD, DLACPY\nC\nC ..Intrinsic functions..\n INTRINSIC MAX\nC\nC .. Data Statements ..\nC . default values for dimensions .\n DATA (NEXC(I), I = 1, 4) /NEXC1, NEXC2, NEXC3, NEXC4/\n DATA (NEXD(I), I = 1, 4) /NEXD1, NEXD2, NEXD3, NEXD4/\n DATA (NDEFC(1,I), I = 1, NEXC1) /2, 2, 4, 8, 9, 30/\n DATA (NDEFC(2,I), I = 1, NEXC2) /2, 2, 2, 2, 2, 3, 4, 4, 55/\n DATA (NDEFC(3,I), I = 1, NEXC3) /20, 64/\n DATA (NDEFC(4,I), I = 1, NEXC4) /21, 100, 30, 211/\n DATA (MDEFC(1,I), I = 1, NEXC1) /1, 1, 2, 2, 3, 3/\n DATA (MDEFC(2,I), I = 1, NEXC2) /1, 2, 1, 2, 1, 3, 1, 1, 2/\n DATA (PDEFC(1,I), I = 1, NEXC1) /2, 2, 4, 8, 9, 5/\n DATA (PDEFC(2,I), I = 1, NEXC2) /1, 1, 2, 2, 2, 3, 2, 1, 10/\n DATA (NDEFD(1,I), I = 1, NEXD1) /2, 2, 2, 3, 4, 4, 4, 5, 6, 9,\n $ 11, 13, 26/\n DATA (NDEFD(2,I), I = 1, NEXD2) /2, 2, 2, 3, 4/\n DATA (NDEFD(4,I), I = 1, NEXD4) /100/\n DATA (MDEFD(1,I), I = 1, NEXD1) /1, 2, 1, 2, 2, 2, 4, 2, 2, 3,\n $ 2, 2, 6/\n DATA (MDEFD(2,I), I = 1, NEXD2) /1, 2, 1, 3, 1/\n DATA (PDEFD(1,I), I = 1, NEXD1) /1, 2, 2, 3, 4, 4, 4, 5, 2, 2,\n $ 4, 4, 12/\n DATA (PDEFD(2,I), I = 1, NEXD2) /2, 2, 2, 3, 1/\nC\nC Check for proper number of arguments.\nC\n IF ( NRHS.LT.3 ) THEN\n CALL mexErrMsgTxt\n $ ( 'AREBENCH requires at least 3 input arguments' )\n ELSE IF ( NRHS.GT.6 ) THEN\n CALL mexErrMsgTxt\n $ ( 'AREBENCH requires at most 6 input arguments' )\n ELSE IF ( NLHS.GT.8 ) THEN\n CALL mexErrMsgTxt\n $ ( 'AREBENCH requires at most 8 output arguments' )\n END IF\nC\n DEF = 'D'\nC\nC Check dimensions of input parameters and read/set scalar parameters.\nC\nC dico\nC\n IF ( mxGetM( PRHS(1) ).NE.1 .OR. mxGetN( PRHS(1) ).NE.1 ) THEN\n CALL mexErrMsgTxt( 'DICO must be a scalar' )\n END IF\n IF ( mxIsNumeric( PRHS(1) ).EQ.0 .OR.\n $ mxIsComplex( PRHS(1) ).EQ.1 ) THEN\n CALL mexErrMsgTxt( 'DICO must be an integer scalar' )\n END IF\n CALL mxCopyPtrToReal8( mxGetPr( PRHS(1) ), TEMP, 1 )\n DICO = TEMP\n IF ( DICO.LT.1 .OR. DICO.GT.2 ) THEN\n CALL mexErrMsgTxt\n $ ( 'DICO has 1 or 2 the only admissible values' )\n END IF\nC\nC nr1, nr2\nC\n IF ( mxGetM( PRHS(2) ).NE.1 .OR. mxGetN( PRHS(2) ).NE.1 ) THEN\n CALL mexErrMsgTxt( 'NR1 must be a scalar' )\n END IF\n IF ( mxIsNumeric( PRHS(2) ).EQ.0 .OR.\n $ mxIsComplex( PRHS(2) ).EQ.1 ) THEN\n CALL mexErrMsgTxt( 'NR1 must be an integer scalar' )\n END IF\n CALL mxCopyPtrToReal8( mxGetPr( PRHS(2) ), TEMP, 1 )\n NR(1) = TEMP\n IF ( NR(1).LT.1 .OR. NR(1).GT.4 ) THEN\n CALL mexErrMsgTxt\n $ ( 'NR1 has 1,2,3, or 4 the only admissible values' )\n END IF\n IF ( DICO.EQ.2 .AND. NR(1).EQ.3 ) THEN\n CALL mexErrMsgTxt\n $ ( 'No available examples for this section' )\n END IF\nC\n IF ( DICO.EQ.1 ) THEN\n NEX(1) = NEXC1\n NEX(2) = NEXC2\n NEX(3) = NEXC3\n NEX(4) = NEXC4\n ELSE\n NEX(1) = NEXD1\n NEX(2) = NEXD2\n NEX(3) = NEXD3\n NEX(4) = NEXD4\n END IF\nC\n IF ( mxGetM( PRHS(3) ).NE.1 .OR. mxGetN( PRHS(3) ).NE.1 ) THEN\n CALL mexErrMsgTxt( 'NR2 must be a scalar' )\n END IF\n IF ( mxIsNumeric( PRHS(3) ).EQ.0 .OR.\n $ mxIsComplex( PRHS(3) ).EQ.1 ) THEN\n CALL mexErrMsgTxt( 'NR2 must be an integer scalar' )\n END IF\n CALL mxCopyPtrToReal8( mxGetPr( PRHS(3) ), TEMP, 1 )\n NR(2) = TEMP\n IF ( NR(2).LT.1 .OR. NR(2).GT.NEX(NR(1)) ) THEN\n WRITE( TEXT, '( \" NR2 has 1..\", I4,\n $ \" the only admisible values\" )' ) NEX(NR(1))\n CALL mexErrMsgTxt ( TEXT )\n END IF\nC\nC flag\nC\n DO 10 I = 1, 7\n BPAR(I) = .TRUE.\n 10 CONTINUE\n IP = 3\n IF ( NRHS.GT.IP ) THEN\n IP = IP + 1\n ISIZE = mxGetM( PRHS(IP) ) * mxGetN( PRHS(IP) )\n IF ( DICO.EQ.1 ) THEN\n IF ( ISIZE.NE.2 ) THEN\n CALL mexErrMsgTxt\n $ ( 'FLAG must be a vector with 2 elements' )\n END IF\n ELSE\n IF ( ISIZE.NE.3 ) THEN\n CALL mexErrMsgTxt\n $ ( 'FLAG must be a vector with 3 elements' )\n END IF\n END IF\n IF ( mxIsNumeric( PRHS(IP) ).EQ.0 .OR.\n $ mxIsComplex( PRHS(IP) ).EQ.1 ) THEN\n CALL mexErrMsgTxt( 'FLAG must be a real vector' )\n END IF\n CALL mxCopyPtrToReal8( mxGetPr( PRHS(IP) ), FLAGR, ISIZE )\n FLAG = FLAGR\nC\n IF ( DICO.EQ.1 ) THEN\n IF ( FLAG(1).EQ.0 )\n $ BPAR(1) = .FALSE.\n IF ( FLAG(2).EQ.0 )\n $ BPAR(4) = .FALSE.\n ELSE\n IF ( FLAG(1).EQ.0 )\n $ BPAR(4) = .FALSE.\n IF ( FLAG(2).EQ.0 )\n $ BPAR(1) = .FALSE.\n IF ( FLAG(3).EQ.0 )\n $ BPAR(7) = .FALSE.\n END IF\n END IF\nC\nC param\nC\n IF ( NRHS.GT.IP .AND. ( NR(1).NE.4 .OR. NR(2).NE.4 ) ) THEN\n IP = IP + 1\n IF ( mxGetM( PRHS(IP) ).NE.0 .AND. mxGetN( PRHS(IP) ).NE.0 )\n $ THEN\n L = 0\n IF ( DICO.EQ.1 ) THEN\n IF ( NR(1).EQ.2 ) THEN\n L = 1\t\n ELSE IF ( NR(1).EQ.4 ) THEN\n IF ( NR(2).EQ.1 ) THEN\n L = 2\n ELSE IF ( NR(2).EQ.2 ) THEN\n L = 7\n ELSE IF ( NR(2).EQ.3 ) THEN\n L = 3\n END IF\n END IF\n ELSE IF ( ( NR(1).EQ.2 .AND. NR(2).LE.4 ) .OR.\n $ ( NR(1).EQ.4 .AND. NR(2).EQ.1 ) ) THEN\n L = 1\t\n ELSE IF ( NR(1).EQ.2 .AND. NR(2).EQ.5 ) THEN\n L = 4\n END IF\n IF ( L.NE.0 ) THEN\n IF ( mxGetM( PRHS(IP) )*mxGetN( PRHS(IP) ).NE.L ) THEN\n WRITE( TEXT,\n $ '(''PARAM must be a vector of length '', I2)') L\n CALL mexErrMsgTxt( TEXT )\n END IF\n IF ( mxIsNumeric( PRHS(IP) ).EQ.0 .OR.\n $ mxIsComplex( PRHS(IP) ).EQ.1 ) THEN\n CALL mexErrMsgTxt( 'PARAM must be a real vector' )\n END IF\n CALL mxCopyPtrToReal8( mxGetPr( PRHS(IP) ), DPAR, L )\n ELSE\n CALL mexErrMsgTxt\n $ ( 'PARAM must not be used for this example' )\n END IF\n ELSE\n IF ( NRHS.EQ.IP )\n $ CALL mexErrMsgTxt( 'PARAM must be a real vector' )\n END IF\n END IF\nC\nC opt\nC\n IF ( NRHS.GT.IP ) THEN\n IP = IP + 1\n IF ( mxGetM( PRHS(IP) ).NE.0 .AND. mxGetN( PRHS(IP) ).NE.0 )\n $ THEN\n L = 0\n IF ( DICO.EQ.1 ) THEN\n IF ( NR(1).EQ.2 .AND. NR(2).EQ.9 ) THEN\n L = 2\n ELSE IF ( NR(1).EQ.3 .AND. NR(2).LE.2 .OR.\n $ NR(1).EQ.4 .AND. NR(2).LE.4 ) THEN\n L = 1\n END IF\n ELSE IF ( NR(1).EQ.4 .AND. NR(2).EQ.1 ) THEN\n L = 1\n END IF\n IF ( L.NE.0 ) THEN\n IF ( mxGetM( PRHS(IP) ).NE.1 .OR.\n $ mxGetN( PRHS(IP) ).NE.1 ) THEN\n CALL mexErrMsgTxt( 'OPT must be a scalar' )\n END IF\n IF ( mxIsNumeric( PRHS(IP) ).EQ.0 .OR.\n $ mxIsComplex( PRHS(IP) ).EQ.1 ) THEN\n CALL mexErrMsgTxt( 'OPT must be an integer scalar' )\n END IF\n CALL mxCopyPtrToReal8( mxGetPr( PRHS(IP) ), TEMP, 1 )\n IPAR(1) = TEMP\n IF ( L.EQ.2 .AND. IPAR(1).NE.1 .AND. IPAR(1).NE.2 ) THEN\n CALL mexErrMsgTxt\n $ ( 'OPT has 1 and 2 the only admissible values' )\n END IF\n IF ( NR(1).EQ.4 .AND. NR(2).EQ.4 .AND.\n $ IPAR(1).NE.NDEFC(4,4) ) THEN\nC\nC Specify the file name; if it is '', the default name\nC is used.\nC\n IF ( NRHS.GT.IP ) THEN\n IP = IP + 1\n IF ( mxIsChar( PRHS(IP) ).NE.1 )\n $ CALL mexErrMsgTxt( 'File name must be a string' )\n L = mxGetN( PRHS(IP) )\n IF ( L.EQ.0 ) THEN\n CALL mexPrintf( 'Default file name is used' )\n WRITE (CHPAR(1:11), '(A,I1,A,I1,A)') 'BB01',\n $ NR(1), '0', NR(2) , '.dat'\n IPAR(4) = 11\n ELSE\n IE = mxGetString( PRHS(IP), CHPAR, L )\n IF ( IE.NE.0 )\n $ CALL mexErrMsgTxt\n $ ( 'File name must be a string' )\n IPAR(4) = L\n END IF\n ELSE\n WRITE (CHPAR(1:11), '(A,I1,A,I1,A)') 'BB01',\n $ NR(1), '0', NR(2) , '.dat'\n IPAR(4) = 11\n END IF\n END IF\n ELSE\n CALL mexErrMsgTxt\n $ ( 'OPT must not be used for this example' )\n END IF\n ELSE\n CALL mexErrMsgTxt( 'OPT must be an integer scalar' )\n END IF\n END IF\nC\n IF ( IP.GT.4 )\n $ DEF = 'N'\nC\nC Determine array dimensions.\nC\n IF ( DICO.EQ.1 ) THEN\n N = NDEFC( NR(1), NR(2) )\n IF ( NR(1).LE.2 ) THEN\n M = MDEFC( NR(1), NR(2) )\n P = PDEFC( NR(1), NR(2) )\n ELSE\n IF ( NR(1).EQ.3 ) THEN\n IF ( NR(2).EQ.1 ) THEN\n IF ( LSAME( DEF, 'D' ) ) THEN\n M = N\n P = N - 1\n N = 2*N - 1\n ELSE\n M = IPAR(1)\n P = IPAR(1) - 1\n N = 2*IPAR(1) - 1\n END IF\n ELSE IF ( NR(2).EQ.2 ) THEN\n IF ( LSAME( DEF, 'N' ) )\n $ N = IPAR(1)\n M = N\n P = N\n END IF\n ELSE IF ( NR(1).EQ.4 ) THEN\n IF ( NR(2).LE.2 ) THEN\n IF ( LSAME( DEF, 'N' ) )\n $ N = IPAR(1)\n M = 1\n P = 1\n ELSE IF ( NR(2).EQ.3 ) THEN\n IF ( LSAME( DEF, 'D' ) ) THEN\n N = 2*N\n M = 2\n P = N\n ELSE\n N = 2*IPAR(1)\n M = 2\n P = N\n END IF\n ELSE IF ( NR(2).EQ.4 ) THEN\n IF ( LSAME( DEF, 'D' ) ) THEN\n M = N\n P = N\n N = 2*N - 1\n ELSE\n N = 2*IPAR(1) - 1\n M = IPAR(1)\n P = IPAR(1)\n END IF\n END IF\n END IF\n END IF\n ELSE\n N = NDEFD( NR(1), NR(2) )\n IF ( NR(1).LE.2 ) THEN\n M = MDEFD( NR(1), NR(2) )\n P = PDEFD( NR(1), NR(2) )\n ELSE IF ( NR(1).EQ.4 ) THEN\n IF ( NR(2).EQ.1 ) THEN\n IF ( LSAME( DEF, 'D' ) ) THEN\n N = 100\n ELSE\n N = IPAR(1)\n END IF\n M = 1\n P = N\n END IF\n END IF\n END IF\nC\nC Determine the lengths of working arrays.\nC\n LDA = N\n LDG = LDA\n LDQ = LDA\n LDB = LDA\n LDC = P\n LDX = LDA\nC\n IF ( DICO.EQ.1 ) THEN\n LDWORK = N*MAX( 4, N )\n ELSE\n LDS = LDA\n IF ( .NOT.BPAR(4) ) LDG = M\n IF ( .NOT.BPAR(1) ) LDQ = P\n LDWORK = N*N\n END IF\nC\nC Allocate variable dimension local arrays.\nC !Fortran 90/95\nC\n ALLOCATE( A(LDA,N), B(LDB,M), C(LDC,N), G(LDG,N), Q(LDQ,N),\n $ X(LDX,N), DWORK(LDWORK) )\n IF ( DICO.EQ.2 )\n $ ALLOCATE( S(LDS,M) )\nC\nC Do the actual computations.\nC\n IF ( DICO.EQ.1 ) THEN\n CALL BB01AD( DEF, NR, DPAR, IPAR, BPAR, CHPAR, VEC, N, M, P,\n $ A, LDA, B, LDB, C, LDC, G, LDG, Q, LDQ, X, LDX,\n $ DWORK, LDWORK, INFO )\n ELSE\n CALL BB02AD( DEF, NR, DPAR, IPAR, BPAR, CHPAR, VEC, N, M, P,\n $ A, LDA, B, LDB, C, LDC, Q, LDQ, G, LDG, S, LDS,\n $ X, LDX, DWORK, LDWORK, INFO )\n END IF\nC\nC Copy output to MATLAB workspace.\nC\n IF ( INFO.EQ.0 ) THEN\n CALL mexPrintf( CHPAR )\n IF ( NLHS.GE.1 ) THEN\n IF ( ( DICO.EQ.1 .AND. VEC(9) ) .OR.\n $ ( DICO.EQ.2 .AND. VEC(10) ) ) THEN\n PLHS(1) = mxCreateDoubleMatrix( N, N, 0 )\n CALL mxCopyReal8ToPtr( X, mxGetPr( PLHS(1) ), N*N )\n ELSE\n PLHS(1) = mxCreateDoubleMatrix( 0, 0, 0 )\n END IF\n END IF\n IF ( NLHS.GE.2 ) THEN\n PLHS(2) = mxCreateDoubleMatrix( N, N, 0 )\n CALL mxCopyReal8ToPtr( A, mxGetPr( PLHS(2) ), N*N )\n END IF\n IF ( NLHS.GE.3 ) THEN\n IF ( FLAG(1).EQ.1 ) THEN\n PLHS(3) = mxCreateDoubleMatrix( N, N, 0 )\n CALL mxCopyReal8ToPtr( G, mxGetPr( PLHS(3) ), N*N )\n ELSE\n IF ( M.LT.LDG )\n $ CALL DLACPY( 'Full', M, M, G, LDG, G, M )\n PLHS(3) = mxCreateDoubleMatrix( M, M, 0 )\n CALL mxCopyReal8ToPtr( G, mxGetPr( PLHS(3) ), M*M )\n END IF\n END IF\n IF ( NLHS.GE.4 ) THEN\n IF ( FLAG(2).EQ.1 ) THEN\n PLHS(4) = mxCreateDoubleMatrix( N, N, 0 )\n CALL mxCopyReal8ToPtr( Q, mxGetPr( PLHS(4) ), N*N )\n ELSE\n IF ( P.LT.LDQ )\n $ CALL DLACPY( 'Full', P, P, Q, LDQ, Q, P )\n PLHS(4) = mxCreateDoubleMatrix( P, P, 0 )\n CALL mxCopyReal8ToPtr( Q, mxGetPr( PLHS(4) ), P*P )\n END IF\n END IF\n IP = 5\n IF ( ( NLHS.GE.IP ) .AND. ( FLAG(1).EQ.0 ) ) THEN\n PLHS(IP) = mxCreateDoubleMatrix( N, M, 0 )\n CALL mxCopyReal8ToPtr( B, mxGetPr( PLHS(IP) ), N*M )\n IP = IP + 1\n END IF\n IF ( ( NLHS.GE.IP ) .AND. ( FLAG(2).EQ.0 ) ) THEN\n PLHS(IP) = mxCreateDoubleMatrix( P, N, 0 )\n CALL mxCopyReal8ToPtr( C, mxGetPr( PLHS(IP) ), N*P )\n IP = IP + 1\n END IF\n IF ( NLHS.GE.IP .AND. DICO.EQ.2 .AND. BPAR(7) ) THEN\n PLHS(IP) = mxCreateDoubleMatrix( N, M, 0 )\n CALL mxCopyReal8ToPtr( S, mxGetPr( PLHS(IP) ), N*M )\n IP = IP + 1\n END IF\n IF ( NLHS.GE.IP ) THEN\n IF ( DICO.EQ.1 ) THEN\n PLHS(IP) = mxCreateDoubleMatrix( 7, 1, 0 )\n CALL mxCopyReal8ToPtr( DPAR, mxGetPr( PLHS(IP) ), 7 )\n ELSE\n PLHS(IP) = mxCreateDoubleMatrix( 4, 1, 0 )\n CALL mxCopyReal8ToPtr( DPAR, mxGetPr( PLHS(IP) ), 4 )\n END IF\n END IF\n END IF\nC\nC Deallocate local arrays.\nC !Fortran 90/95\nC\n DEALLOCATE( A, B, C, G, Q, X, DWORK )\n IF ( DICO.EQ.2 )\n $ DEALLOCATE( S )\nC\nC Error and warning handling.\nC\n IF ( INFO.NE.0 ) THEN\n IF ( DICO.EQ.1 ) THEN\n WRITE( TEXT,'( \" INFO = \", I4, \" ON EXIT FROM BB01AD\" )' )\n $ INFO\n ELSE\n WRITE( TEXT,'( \" INFO = \", I4, \" ON EXIT FROM BB02AD\" )' )\n $ INFO\n END IF\n CALL mexErrMsgTxt( TEXT )\n END IF\nC\n RETURN\nC\nC *** Last line of AREBENCH ***\n END\n", "meta": {"hexsha": "a4323158a101d3fb5e12aea82a558747406081fc", "size": 23816, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "mex_src/arebench.f", "max_stars_repo_name": "SLICOT/SLICOT-ModelReduction", "max_stars_repo_head_hexsha": "a162d60dcd1f9d2a090b15944c887d472dba9901", "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": "mex_src/arebench.f", "max_issues_repo_name": "SLICOT/SLICOT-ModelReduction", "max_issues_repo_head_hexsha": "a162d60dcd1f9d2a090b15944c887d472dba9901", "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": "mex_src/arebench.f", "max_forks_repo_name": "SLICOT/SLICOT-ModelReduction", "max_forks_repo_head_hexsha": "a162d60dcd1f9d2a090b15944c887d472dba9901", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-27T09:49:32.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-27T09:49:32.000Z", "avg_line_length": 36.8098918083, "max_line_length": 72, "alphanum_fraction": 0.4510413168, "num_tokens": 8027, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681195338728, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6573022618187094}} {"text": "! =============================================================================\n! Test Jacobi diagonalisation\n!\n! This unit test checks the eigenvalue solver.\n! =============================================================================\nprogram test_jacobi_1\n use unit_test\n use constants, only : zero\n use jacobi\n implicit none\n\n double precision :: error\n integer :: n, k, sk\n logical :: valid\n double precision :: V(3, 3)\n double precision :: B(3, 3), D(3)\n double precision :: Q(3, 3), EV(3) ! reference\n integer, allocatable :: seed(:)\n\n call random_seed(size=sk)\n allocate(seed(1:sk))\n seed(:) = 42\n call random_seed(put=seed)\n\n\n error = zero\n\n n = 1\n do while (n <= 100000)\n\n call create_symmetric_matrix\n\n if (valid) then\n n = n + 1\n\n call jacobi_diagonalise(B, D, V)\n\n ! check eigenvalues\n error = max(error, dabs(EV(1) - D(1)) &\n + dabs(EV(2) - D(2)) &\n + dabs(EV(3) - D(3)))\n\n ! check eigenvectors\n do k = 1, 3\n if (Q(1, k) / V(1, k) < zero) then\n ! opposite sign\n Q(:, k) = - Q(:, k)\n endif\n error = max(error, sum(dabs(Q(:, k) - V(:, k))))\n enddo\n endif\n enddo\n\n call print_result_dp('Test Jacobi 1', error, atol=dble(1.0e-9))\n\n contains\n\n subroutine create_symmetric_matrix\n integer :: i, j\n double precision :: rndm(3, 3), val\n double precision :: tmp\n\n ! random eigenvalue\n do j = 1, 3\n call random_number(tmp)\n EV(j) = 2.0d0 * tmp\n enddo\n\n ! sort\n if (EV(1) < EV(2)) then\n tmp = EV(1)\n EV(1) = EV(2)\n EV(2) = tmp\n endif\n\n if (EV(2) < EV(3)) then\n tmp = EV(2)\n EV(2) = EV(3)\n EV(3) = tmp\n endif\n\n if (EV(1) < EV(2)) then\n tmp = EV(1)\n EV(1) = EV(2)\n EV(2) = tmp\n endif\n\n\n ! Create orthogonal vectors using Gram-Schmidt orthogonalization\n ! (https://de.wikipedia.org/wiki/Gram-Schmidtsches_Orthogonalisierungsverfahren)\n do i = 1, 3\n do j = 1, 3\n call random_number(val)\n rndm(i, j) = 10.0d0 * val\n enddo\n enddo\n\n Q = 0.0d0\n\n do j = 1, 3\n Q(:, j) = rndm(:, j)\n do i = 1, j - 1\n Q(:, j) = Q(:, j) &\n - Q(:, i) * dot_product(Q(:, i), rndm(:, j)) &\n / dot_product(Q(:, i), Q(:, i))\n enddo\n Q(:, j) = Q(:, j) / norm2(Q(:, j))\n enddo\n\n ! Check orthogonalization error:\n val = dabs(dot_product(Q(:, 1), Q(:, 2))) &\n + dabs(dot_product(Q(:, 1), Q(:, 3))) &\n + dabs(dot_product(Q(:, 2), Q(:, 3)))\n\n valid = (val < 1.0e-13)\n if (.not. valid) then\n return\n endif\n\n ! Create symmetric B matrix\n B = 0.0d0\n do i = 1, 3\n do j = 1, 3\n do k = 1, 3\n B(i, j) = B(i, j) + Q(i, k) * EV(k) * Q(j, k)\n enddo\n enddo\n enddo\n end subroutine create_symmetric_matrix\n\nend program test_jacobi_1\n", "meta": {"hexsha": "12ab2f86ebaa943ef1d444c7c8a267e1f56eafbd", "size": 3717, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "unit-tests/3d/test_jacobi_1.f90", "max_stars_repo_name": "matt-frey/epic", "max_stars_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2021-11-11T10:50:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T00:11:41.000Z", "max_issues_repo_path": "unit-tests/3d/test_jacobi_1.f90", "max_issues_repo_name": "matt-frey/epic", "max_issues_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 47, "max_issues_repo_issues_event_min_datetime": "2021-11-12T17:09:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-24T16:50:58.000Z", "max_forks_repo_path": "unit-tests/3d/test_jacobi_1.f90", "max_forks_repo_name": "matt-frey/epic", "max_forks_repo_head_hexsha": "954ebc44f2c041eee98bd14e22a85540a0c6c4bb", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.1590909091, "max_line_length": 92, "alphanum_fraction": 0.3761097659, "num_tokens": 985, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.766293653760418, "lm_q1q2_score": 0.6573022552520165}} {"text": "! BSD 3-Clause License\n!\n! Copyright (c) 2020, Fabio Durastante\n! All rights reserved.\n!\n! Redistribution and use in source and binary forms, with or without\n! modification, are permitted provided that the following conditions are met:\n!\n! 1. Redistributions of source code must retain the above copyright notice, this\n! list of conditions and the following disclaimer.\n!\n! 2. Redistributions in binary form must reproduce the above copyright notice,\n! this list of conditions and the following disclaimer in the documentation\n! and/or other materials provided with the distribution.\n!\n! 3. Neither the name of the copyright holder nor the names of its\n! contributors may be used to endorse or promote products derived from\n! this software without specific prior written permission.\n!\n! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n! DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\n! FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n! DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n! SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\n! OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n! OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\nsubmodule (psfun_utils_mod) psfun_z_utils_mod\n !! Complex variants of the utils functions\n use psb_base_mod\n implicit none\n\n complex, parameter :: iunit = cmplx(0.0_psb_dpk_,1.0_psb_dpk_)\n\ncontains\n\n recursive module subroutine z_ellipj(u,L,sn,cn,dn,flag)\n !! Returns the values of the Jacobi elliptic functions evaluated at double\n !! argument u and parameter \\(M = \\exp(-2 \\pi L)\\), \\(0 < L < \\infty\\).\n !! For \\(M = K^2\\), and \\(K\\) the elliptic modulus.\n !\n complex(psb_dpk_), intent(in) :: u\n real(psb_dpk_), intent(in) :: L\n complex(psb_dpk_), intent(out) :: sn,cn,dn\n logical, optional, intent(in) :: flag\n\n real(psb_dpk_) :: m,K(2),kappa,mu\n complex(psb_dpk_) :: ucp, sinu, cosu, v, sn1, cn1, dn1, denom, snh, cnh, dnh\n logical :: flag_, high\n real(psb_dpk_), parameter :: coeffs(7) = (/0.0,1.0,2.0,5.0,14.0,42.0,132.0/)\n\n ucp = u\n\n if( present(flag) ) then\n flag_ = flag\n else\n flag_ = .true.\n end if\n\n if(flag_) then\n K = ellipkkp(L)\n high = (aimag(ucp) > K(2)/2.0_psb_dpk_ )\n if (high) then\n ucp = iunit*K(2) - ucp\n end if\n m = exp(-2.0_psb_dpk_*DPI*L)\n else\n ! In case of recursive call we have already transformed L into m\n high = .false.\n m = L\n endif\n\n if (m < 4.0_psb_dpk_*EPSILON(m) ) then\n sinu = sin(u);\n cosu = cos(u);\n sn = sinu + m/4.0_psb_dpk_*( sinu*cosu-u)*cosu;\n cn = cosu + m/4.0_psb_dpk_*(-sinu*cosu+u)*sinu;\n dn = 1 + m/4.0_psb_dpk_*( cosu**2 -sinu**2-1.0_psb_dpk_);\n else\n if( m > 1e-3) then\n kappa = (1.0_psb_dpk_-sqrt(1.0_psb_dpk_-m))/(1.0_psb_dpk_+sqrt(1.0_psb_dpk_-m))\n else\n kappa = horner( coeffs , m/4.0_psb_dpk_ )\n end if\n mu = kappa**2\n v = u/(1.0_psb_dpk_ + kappa)\n call z_ellipj(v,mu,sn1,cn1,dn1,.false.)\n denom = (1.0_psb_dpk_ + kappa*sn1**2)\n sn = (1+kappa)*sn1/denom\n cn = cn1*dn1/denom\n dn = (1-kappa*sn1**2)/denom\n end if\n\n if(high) then\n snh = sn\n cnh = cn\n dnh = dn\n sn = -1.0_psb_dpk_/(sqrt(m)*snh)\n cn = iunit*dnh/(sqrt(m)*snh)\n dn = iunit*cnh/snh\n endif\n\n return\n\n end subroutine\n\nend submodule\n", "meta": {"hexsha": "b402c8e3da1484669bf7ed44de6f214f336a91d1", "size": 3815, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "docs/html/src/psfun_z_utils_mod.f90", "max_stars_repo_name": "Cirdans-Home/psfun", "max_stars_repo_head_hexsha": "1583d2715b0cadf6cd673b3f522b9699746cef3f", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2021-07-02T02:16:55.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-23T11:45:58.000Z", "max_issues_repo_path": "docs/html/src/psfun_z_utils_mod.f90", "max_issues_repo_name": "Cirdans-Home/psfun", "max_issues_repo_head_hexsha": "1583d2715b0cadf6cd673b3f522b9699746cef3f", "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": "docs/html/src/psfun_z_utils_mod.f90", "max_forks_repo_name": "Cirdans-Home/psfun", "max_forks_repo_head_hexsha": "1583d2715b0cadf6cd673b3f522b9699746cef3f", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.6818181818, "max_line_length": 87, "alphanum_fraction": 0.6563564875, "num_tokens": 1197, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619883, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6573022470901005}} {"text": "!\r\n! The Laboratory of Algorithms\r\n!\r\n! The MIT License\r\n!\r\n! Copyright 2011-2015 Andrey Pudov.\r\n!\r\n! Permission is hereby granted, free of charge, to any person obtaining a copy\r\n! of this software and associated documentation files (the 'Software'), to deal\r\n! in the Software without restriction, including without limitation the rights\r\n! to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n! copies of the Software, and to permit persons to whom the Software is\r\n! furnished to do so, subject to the following conditions:\r\n!\r\n! The above copyright notice and this permission notice shall be included in\r\n! all copies or substantial portions of the Software.\r\n!\r\n! THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r\n! THE SOFTWARE.\r\n!\r\n\r\nmodule MFibonacci\r\n\r\n implicit none\r\n private\r\n\r\n type, public :: TFibonacci\r\n contains\r\n procedure, nopass :: fibonacci => fibonacciRecursive\r\n\r\n procedure, nopass :: fibonacciRecursive\r\n procedure, nopass :: fibonacciIterate\r\n end type\r\ncontains\r\n recursive function fibonacciRecursive(position) result(fibonacci)\r\n integer, intent(in) :: position\r\n integer :: fibonacci\r\n\r\n if (position <= 2) then\r\n fibonacci = 1\r\n return\r\n end if\r\n\r\n fibonacci = fibonacciRecursive(position - 1) + fibonacciRecursive(position - 2)\r\n end function\r\n\r\n function fibonacciIterate(position) result(fibonacci)\r\n integer, intent(in) :: position\r\n integer :: fibonacci\r\n\r\n integer, dimension(10), save :: buffer\r\n integer, save :: index = 3\r\n buffer(1) = 1\r\n buffer(2) = 1\r\n\r\n if (buffer(position) == 0) then\r\n do index = index, position\r\n buffer(index) = buffer(index - 1) + buffer(index - 2)\r\n end do\r\n end if\r\n\r\n fibonacci = buffer(position)\r\n end function\r\nend module\r\n", "meta": {"hexsha": "94b055e23e9cbd210b9242a672eae85c6d282004", "size": 2351, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Math/Fibonacci.f", "max_stars_repo_name": "andreypudov/Algorithms", "max_stars_repo_head_hexsha": "9693efa0abed30a38fcb9c3f7eebbd5b92b734f5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2016-02-15T14:45:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-01T22:42:32.000Z", "max_issues_repo_path": "Math/Fibonacci.f", "max_issues_repo_name": "jlokimlin/Algorithms", "max_issues_repo_head_hexsha": "d981990394d940fd999334b0b65b118567670d1a", "max_issues_repo_licenses": ["MIT"], "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/Fibonacci.f", "max_forks_repo_name": "jlokimlin/Algorithms", "max_forks_repo_head_hexsha": "d981990394d940fd999334b0b65b118567670d1a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2016-02-24T15:47:02.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-01T10:45:03.000Z", "avg_line_length": 33.5857142857, "max_line_length": 88, "alphanum_fraction": 0.6631220757, "num_tokens": 507, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619885, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.6573022470901004}} {"text": "! This program calculates permutations for passwords with varying lengths & complexities\n! This is designed to show the security of length over complexity\n!\n! Author: Josh McIntyre\n!\n\n! Define data parameters in a module\nMODULE pass_data\n\n ! Constant declarations for character spaces and lengths\n INTEGER, PARAMETER::ASIZE = 7\n\n ! numerical (10), lowercase, upper lower, upper lower numerical (62), various amounts of symbols\n REAL, DIMENSION(ASIZE), PARAMETER::COMPLEXITIES = (/ 10, 26, 52, 62, 72, 82, 92 /)\n REAL, PARAMETER::LENGTH_SAMPLE = 8\n \n ! Lengths of the password in characters\n REAL, DIMENSION(ASIZE), PARAMETER::LENGTHS = (/ 8, 9, 10, 12, 14, 16, 20 /)\n REAL, PARAMETER::COMPLEXITY_SAMPLE = 62\n\n ! Password cracking constants\n ! 180 billion (giga) hashes per second - professional 25 GPU cluster, MD5 algorithm\n ! 7.652 billion (giga) hashes per second - consumer laptop with Nvidia GeForce 1050 Ti GPU\n REAL, PARAMETER::HASHPOWER_PRO = 180000000000.0\n REAL, PARAMETER::HASHPOWER_LAPTOP = 7652000000.0\n REAL, PARAMETER::SECONDS_PER_MINUTE = 60.0\n REAL, PARAMETER::SECONDS_PER_HOUR = 3600.0\n REAL, PARAMETER::SECONDS_PER_DAY = 86400.0\n REAL, PARAMETER::SECONDS_PER_YEAR = 31557600.0\n \n ! Output constants\n INTEGER, PARAMETER::HSIZE = 100\n\n CHARACTER(HSIZE), PARAMETER::COMPLEXITIES_LABEL = \"Combinations for constant length 8, variable complexity\"\n CHARACTER(HSIZE), PARAMETER::COMPLEXITIES_HEADER = \"Complexity Combinations Crack Time\"\n\n CHARACTER(HSIZE), PARAMETER::CRACKTIME_LABEL_PRO = \"Cracking w/ 180 GH/s, MD5 - 25 GPU professional cluster\"\n CHARACTER(HSIZE), PARAMETER::CRACKTIME_LABEL_LAPTOP = \"Cracking w/ 7.652 GH/s, MD5 - NVidia GeForce 1050 Ti consumer laptop\"\n\n CHARACTER(HSIZE), PARAMETER::LENGTHS_LABEL = \"Combinations for constant complexity 62, variable length\"\n CHARACTER(HSIZE), PARAMETER::LENGTHS_HEADER = \"Length Combinations Crack Time\"\n\nEND MODULE\n\n! This is the main entry point for the program\nPROGRAM passperms\n\n ! Data declarations for command line args\n USE pass_data\n\n IMPLICIT NONE\n CHARACTER(15)::flag, flag2\n \n ! Data declarations for calculations and results\n REAL(8), DIMENSION(ASIZE)::results, times\n CHARACTER(HSIZE)::cracktime_label\n\n ! Calculate and output just the permutations with no guess time specified\n ! Otherwise, calculate and output the crack time matrix\n IF (IARGC() == 1 .OR. IARGC() == 2) THEN\n\n ! Fetch arguments\n CALL getarg(1, flag)\n CALL getarg(2, flag2)\n IF (flag == \"-h\" .OR. flag == \"--help\") THEN\n CALL output_help()\n ELSE IF (flag == \"-c\" .OR. flag == \"--complexities\") THEN\n CALL calc_complexities(results)\n IF (flag2 == \"-f\" .OR. flag2 == \"--fast\") THEN\n CALL calc_times(results, HASHPOWER_LAPTOP, times)\n cracktime_label = CRACKTIME_LABEL_PRO\n ELSE\n ! Default to consumer laptop cracking time\n CALL calc_times(results, HASHPOWER_PRO, times)\n cracktime_label = CRACKTIME_LABEL_LAPTOP\n END IF\n CALL output_results(COMPLEXITIES_LABEL, cracktime_label, COMPLEXITIES_HEADER, COMPLEXITIES, results, times)\n ELSE IF (flag == \"-l\" .OR. flag == \"--lengths\") THEN\n CALL calc_lengths(results)\n IF (flag2 == \"-f\" .OR. flag2 == \"--fast\") THEN\n CALL calc_times(results, HASHPOWER_LAPTOP, times)\n cracktime_label = CRACKTIME_LABEL_PRO\n ELSE\n ! Default to consumer laptop cracking time\n CALL calc_times(results, HASHPOWER_PRO, times)\n cracktime_label = CRACKTIME_LABEL_LAPTOP\n END IF\n CALL output_results(LENGTHS_LABEL, cracktime_label, LENGTHS_HEADER, LENGTHS, results, times)\n END IF\n ELSE\n CALL output_help()\n END IF\n\nEND PROGRAM\n\n! This subroutine calculates the results array for the given complexity (character space)\n! It will calculate an entry for each complexity space to the sample-length power\nSUBROUTINE calc_complexities(results)\n\n ! Declare function params and returns, and data\n USE pass_data\n\n IMPLICIT none\n REAL(8), DIMENSION(ASIZE), INTENT(OUT)::results\n\n ! Can just use array per-element shorthand here\n results = COMPLEXITIES ** LENGTH_SAMPLE\n\n RETURN\nEND SUBROUTINE calc_complexities\n\n! This subroutine calculates the results array for the given lengths\n! It will calculate an entry for one sample-complexity to the length power\nSUBROUTINE calc_lengths(results)\n\n ! Declare function params and returns, and data\n USE pass_data\n\n IMPLICIT none\n REAL(8), DIMENSION(ASIZE), INTENT(OUT)::results\n\n INTEGER::i\n\n ! Loop on each element and exponentiate; array shorthand does not work in reverse\n DO i = 1, ASIZE, 1\n results(i) = COMPLEXITY_SAMPLE ** LENGTHS(i)\n END DO\n\n RETURN\nEND SUBROUTINE calc_lengths\n\n! This subroutine will calculate cracking times for a given result set and hashing power\nSUBROUTINE calc_times(results, hash, times)\n\n ! Declare function params and returns, and data\n USE pass_data\n\n IMPLICIT none\n REAL(8), DIMENSION(ASIZE), INTENT(IN)::results\n REAL, INTENT(IN)::hash\n REAL(8), DIMENSION(ASIZE), INTENT(OUT)::times\n\n REAL::optime\n\n ! Calculate the time per one operation, based on Gigahashes per second\n optime = 1.0 / hash\n\n ! Calculate times per element\n times = results * optime\n\n RETURN\nEND SUBROUTINE calc_times\n\n! This subroutine outputs the results of the calculations\nSUBROUTINE output_results(label, cracktime_label, header, bases, results, times)\n\n ! Declare function params and returns, and data\n USE pass_data\n\n IMPLICIT none\n CHARACTER(HSIZE), INTENT(IN)::label, cracktime_label, header\n REAL, DIMENSION(ASIZE), INTENT(IN)::bases\n REAL(8), DIMENSION(ASIZE), INTENT(IN)::results, times\n \n INTEGER::i\n\n WRITE(*, *) label\n WRITE(*, *) cracktime_label\n WRITE(*, *) header\n\n DO i = 1, ASIZE, 1\n \n IF (times(i) .LE. SECONDS_PER_MINUTE) THEN\n WRITE(*, 100) bases(i), results(i), times(i)\n 100 FORMAT(3x, F3.0, 5x, ES20.0, F20.5, \" seconds\")\n ELSE IF (times(i) .LE. SECONDS_PER_HOUR) THEN\n WRITE(*, 200) bases(i), results(i), times(i) / SECONDS_PER_MINUTE\n 200 FORMAT(3x, F3.0, 5x, ES20.0, F20.5, \" minutes\")\n ELSE IF (times(i) .LE. SECONDS_PER_DAY) THEN\n WRITE(*, 300) bases(i), results(i), times(i) / SECONDS_PER_HOUR\n 300 FORMAT(3x, F3.0, 5x, ES20.0, F20.5, \" hours\")\n ELSE IF (times(i) .LE. SECONDS_PER_YEAR) THEN\n WRITE(*, 400) bases(i), results(i), times(i) / SECONDS_PER_DAY\n 400 FORMAT(3x, F3.0, 5x, ES20.0, F20.5, \" days\")\n ELSE IF (times(i) .LE. SECONDS_PER_YEAR * 10000) THEN\n WRITE(*, 500) bases(i), results(i), times(i) / SECONDS_PER_YEAR\n 500 FORMAT(3x, F3.0, 5x, ES20.0, F20.5, \" years\")\n ELSE\n WRITE(*, 600) bases(i), results(i), times(i) / SECONDS_PER_YEAR\n 600 FORMAT(3x, F3.0, 5x, ES20.0, ES20.5, \" years\")\n END IF\n \n END DO\n\n RETURN\nEND SUBROUTINE output_results\n\n! This subroutine prints a help message\nSUBROUTINE output_help()\n WRITE(*, *) \"Usage: ./passperms [-p/--perms] [-h/--help] \"\n WRITE(*, *) \"-c/--complexities - Show the number of possible permutations for a constant length and variable complexities\"\n WRITE(*, *) \"-l/--lengths - Show the number of possible permutations for a constant complexity and variable lengths\"\n WRITE(*, *) \"-f/--fast - Show professional grade crack times (180 GH/s, MD5) 25 GPU cluster\"\n WRITE(*, *) \"-r/--regular - Show consumer grade crack times (7.652 GH/s, MD5) Nvidia GeForce 1050 Ti\"\n WRITE(*, *) \"-h/--help - Show this help message\"\n \n STOP\nEND SUBROUTINE output_help", "meta": {"hexsha": "643f596794012e56aac9817a8c06632c07619647", "size": 7977, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/passperms.f90", "max_stars_repo_name": "chaintuts/passperms", "max_stars_repo_head_hexsha": "4e83fb1f84fb0769a4c6194059dd465543bbb864", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/passperms.f90", "max_issues_repo_name": "chaintuts/passperms", "max_issues_repo_head_hexsha": "4e83fb1f84fb0769a4c6194059dd465543bbb864", "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/passperms.f90", "max_forks_repo_name": "chaintuts/passperms", "max_forks_repo_head_hexsha": "4e83fb1f84fb0769a4c6194059dd465543bbb864", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-12-31T21:20:43.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-31T21:20:43.000Z", "avg_line_length": 38.3509615385, "max_line_length": 128, "alphanum_fraction": 0.6617776106, "num_tokens": 2151, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680904463334, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6573022349510078}} {"text": "! RUN: bbc %s -o - | FileCheck %s\n\n! Test real add on real kinds.\n\n! CHECK-LABEL: real2\nREAL(2) FUNCTION real2(x0, x1)\n REAL(2) :: x0\n REAL(2) :: x1\n ! CHECK-DAG: %[[v1:.+]] = fir.load %arg0 : !fir.ref\n ! CHECK-DAG: %[[v2:.+]] = fir.load %arg1 : !fir.ref\n ! CHECK: %[[v3:.+]] = arith.addf %[[v1]], %[[v2]] : f16\n real2 = x0 + x1\n ! CHECK: return %{{.*}} : f16\nEND FUNCTION real2\n\n! CHECK-LABEL: real3\nREAL(3) FUNCTION real3(x0, x1)\n REAL(3) :: x0\n REAL(3) :: x1\n ! CHECK-DAG: %[[v1:.+]] = fir.load %arg0 : !fir.ref\n ! CHECK-DAG: %[[v2:.+]] = fir.load %arg1 : !fir.ref\n ! CHECK: %[[v3:.+]] = arith.addf %[[v1]], %[[v2]] : bf16\n real3 = x0 + x1\n ! CHECK: return %{{.*}} : bf16\nEND FUNCTION real3\n\n! CHECK-LABEL: real4\nREAL(4) FUNCTION real4(x0, x1)\n REAL(4) :: x0\n REAL(4) :: x1\n ! CHECK-DAG: %[[v1:.+]] = fir.load %arg0 : !fir.ref\n ! CHECK-DAG: %[[v2:.+]] = fir.load %arg1 : !fir.ref\n ! CHECK: %[[v3:.+]] = arith.addf %[[v1]], %[[v2]] : f32\n real4 = x0 + x1\n ! CHECK: return %{{.*}} : f32\nEND FUNCTION real4\n\n! CHECK-LABEL: defreal\nREAL FUNCTION defreal(x0, x1)\n REAL :: x0\n REAL :: x1\n ! CHECK-DAG: %[[v1:.+]] = fir.load %arg0 : !fir.ref\n ! CHECK-DAG: %[[v2:.+]] = fir.load %arg1 : !fir.ref\n ! CHECK: %[[v3:.+]] = arith.addf %[[v1]], %[[v2]] : f32\n defreal = x0 + x1\n ! CHECK: return %{{.*}} : f32\nEND FUNCTION defreal\n\n! CHECK-LABEL: real8\nREAL(8) FUNCTION real8(x0, x1)\n REAL(8) :: x0\n REAL(8) :: x1\n ! CHECK-DAG: %[[v1:.+]] = fir.load %arg0 : !fir.ref\n ! CHECK-DAG: %[[v2:.+]] = fir.load %arg1 : !fir.ref\n ! CHECK: %[[v3:.+]] = arith.addf %[[v1]], %[[v2]] : f64\n real8 = x0 + x1\n ! CHECK: return %{{.*}} : f64\nEND FUNCTION real8\n\n! CHECK-LABEL: doubleprec\nDOUBLE PRECISION FUNCTION doubleprec(x0, x1)\n DOUBLE PRECISION :: x0\n DOUBLE PRECISION :: x1\n ! CHECK-DAG: %[[v1:.+]] = fir.load %arg0 : !fir.ref\n ! CHECK-DAG: %[[v2:.+]] = fir.load %arg1 : !fir.ref\n ! CHECK: %[[v3:.+]] = arith.addf %[[v1]], %[[v2]] : f64\n doubleprec = x0 + x1\n ! CHECK: return %{{.*}} : f64\nEND FUNCTION doubleprec\n\n! CHECK-LABEL: real10\nREAL(10) FUNCTION real10(x0, x1)\n REAL(10) :: x0\n REAL(10) :: x1\n ! CHECK-DAG: %[[v1:.+]] = fir.load %arg0 : !fir.ref\n ! CHECK-DAG: %[[v2:.+]] = fir.load %arg1 : !fir.ref\n ! CHECK: %[[v3:.+]] = arith.addf %[[v1]], %[[v2]] : f80\n real10 = x0 + x1\n ! CHECK: return %{{.*}} : f80\nEND FUNCTION real10\n\n! CHECK-LABEL: real16\nREAL(16) FUNCTION real16(x0, x1)\n REAL(16) :: x0\n REAL(16) :: x1\n ! CHECK-DAG: %[[v1:.+]] = fir.load %arg0 : !fir.ref\n ! CHECK-DAG: %[[v2:.+]] = fir.load %arg1 : !fir.ref\n ! CHECK: %[[v3:.+]] = arith.addf %[[v1]], %[[v2]] : f128\n real16 = x0 + x1\n ! CHECK: return %{{.*}} : f128\nEND FUNCTION real16\n\n! CHECK-LABEL: real16b\nREAL(16) FUNCTION real16b(x0, x1)\n REAL(16) :: x0\n REAL(16) :: x1\n ! CHECK-DAG: %[[v0:.+]] = arith.constant 4.0{{.*}} : f128\n ! CHECK-DAG: %[[v1:.+]] = fir.load %arg0 : !fir.ref\n ! CHECK-DAG: %[[v2:.+]] = fir.load %arg1 : !fir.ref\n ! CHECK: %[[v3:.+]] = arith.addf %[[v1]], %[[v2]] : f128\n ! CHECK: %[[v4:.+]] = arith.subf %[[v3]], %[[v0]] : f128\n real16b = x0 + x1 - 4.0_16\n ! CHECK: return %{{.*}} : f128\nEND FUNCTION real16b\n", "meta": {"hexsha": "67de090bddd35bd5102e3fb1fb5394021efa5ed8", "size": 3247, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "flang/test/Lower/real-operations-1.f90", "max_stars_repo_name": "lxbndr/llvm-project", "max_stars_repo_head_hexsha": "2b715b15f5f4c6dd60f05d1b62f9c404e8b56e34", "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": "flang/test/Lower/real-operations-1.f90", "max_issues_repo_name": "lxbndr/llvm-project", "max_issues_repo_head_hexsha": "2b715b15f5f4c6dd60f05d1b62f9c404e8b56e34", "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": "flang/test/Lower/real-operations-1.f90", "max_forks_repo_name": "lxbndr/llvm-project", "max_forks_repo_head_hexsha": "2b715b15f5f4c6dd60f05d1b62f9c404e8b56e34", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.9238095238, "max_line_length": 59, "alphanum_fraction": 0.5380351093, "num_tokens": 1423, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339716830605, "lm_q2_score": 0.7826624688140726, "lm_q1q2_score": 0.6572282634245107}} {"text": "!*******************************************************************************\n! Copyright(C) 2005-2013 Intel Corporation. All Rights Reserved.\n! \n! The source code, information and material (\"Material\") contained herein is\n! owned by Intel Corporation or its suppliers or licensors, and title to such\n! Material remains with Intel Corporation or its suppliers or licensors. The\n! Material contains proprietary information of Intel or its suppliers and\n! licensors. The Material is protected by worldwide copyright laws and treaty\n! provisions. No part of the Material may be used, copied, reproduced,\n! modified, published, uploaded, posted, transmitted, distributed or disclosed\n! in any way without Intel's prior express written permission. No license\n! under any patent, copyright or other intellectual property rights in the\n! Material is granted to or conferred upon you, either expressly, by\n! implication, inducement, estoppel or otherwise. Any license under such\n! intellectual property rights must be express and approved by Intel in\n! writing.\n! \n! *Third Party trademarks are the property of their respective owners.\n! \n! Unless otherwise agreed by Intel in writing, you may not remove or alter\n! this notice or any other notice embedded in Materials by Intel or Intel's\n! suppliers or licensors in any way.\n!\n!*******************************************************************************\n! Content : Intel MKL Extended Eigensolvers FORTRAN 77 example\n!\n!*******************************************************************************\n!\n! Example program for using Intel MKL Extended Eigensolvers (sparse format).\n! \n! The following routines are used in the example:\n! DGEMM DFEAST_SCSREV DFEAST_SCSRGV FEASTINIT.\n!\n! Consider the matrix A \n!\n! | 5 2 1 1 0 0 0 0 0 0 0 |\n! | 2 6 3 1 1 0 0 0 0 0 0 |\n! | 1 3 6 3 1 1 0 0 0 0 0 |\n! | 1 1 3 6 3 1 1 0 0 0 0 |\n! | 0 1 1 3 6 3 1 1 0 0 0 |\n! A = | 0 0 1 1 3 6 3 1 1 0 0 |,\n! | 0 0 0 1 1 3 6 3 1 1 0 |\n! | 0 0 0 0 1 1 3 6 3 1 1 |\n! | 0 0 0 0 0 1 1 3 6 3 1 | \n! | 0 0 0 0 0 0 1 1 3 6 2 |\n! | 0 0 0 0 0 0 0 1 1 2 5 |\n\n!\n! stored as a compessed sparse row matrix (DOUBLE PRECISION).\n! B is a unit matrix:\n!\n! | 1 0 0 0 0 0 0 0 0 0 0 |\n! | 0 1 0 0 0 0 0 0 0 0 0 |\n! | 0 0 1 0 0 0 0 0 0 0 0 |\n! | 0 0 0 1 0 0 0 0 0 0 0 |\n! | 0 0 0 0 1 0 0 0 0 0 0 |\n! B = | 0 0 0 0 0 1 0 0 0 0 0 |.\n! | 0 0 0 0 0 0 1 0 0 0 0 |\n! | 0 0 0 0 0 0 0 1 0 0 0 |\n! | 0 0 0 0 0 0 0 0 1 0 0 | \n! | 0 0 0 0 0 0 0 0 0 1 0 |\n! | 0 0 0 0 0 0 0 0 0 0 1 |\n!\n!\n! In what follows the symbol ' represents a transpose operation.\n!\n! The test performs the following operations :\n!\n!\n! 1. The code calls FEASTINIT to define the default values for the input\n! FEAST parameters.\n!\n! 2. The code solves the standard eigenvalue problem Ax=ex using \n! DFEAST_SCSREV.\n!\n! 3. The code computes the residual R(i) = | E(i) - Eig(i) | where Eig(i) \n! are the expected eigenvalues and E(i) are eigenvalues computed \n! with the help of DFEAST_SCSREV().\n!\n! 4. The code computes the maximum absolute value of the matrix Y=(X')*X-I \n! where X is the matrix of eigenvectors computed with the help of \n! DFEAST_SCSREV. DGEMM (BLAS Level 3 Routine) is called to compute (X')*X.\n!\n! 5. The code solves the generalized eigenvalue problem Ax=eBx using\n! DFEAST_SCSRGV.\n!\n! 6. The code computes the residual R(i) = | E(i) - Eig(i) | where Eig(i) \n! are the expected eigenvalues and E(i) are eigenvalues computed \n! with the help of DFEAST_SCSRGV().\n!\n! 7. The code computes the maximum absolute value of the matrix Y=(X')*X-I \n! where X is the matrix of eigenvectors computed with the help of \n! DFEAST_SCSREV. DGEMM (BLAS Level 3 Routine) is called to compute (X')*X. \n!\n!*******************************************************************************\n program dexample_sparse\n implicit none\n!!!!!!!!!!!!!!!!! Matrix declaration variables !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n character*1 UPLO\n parameter (UPLO='F')\n integer n\n parameter (n=11)\n real*8 val(65), valb(n)\n integer rows(n+1), cols(65), rowsb(n+1), colsb(n)\n!!!!!!!!!!!!!!!!! Declaration of FEAST variables !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!!!!!!!!!!!!!!!! E - eigenvalues, X - eigenvectors, res - residual !!!!!!!!!!!!\n integer fpm(128)\n real*8 Emin,Emax\n real*8 epsout\n integer loop\n integer L\n parameter (L=8) \n integer M0,M,info\n real*8 E(n)\n real*8 X(n,n)\n real*8 res(n)\n!!!!!!!!!!!!!!!!! Declaration of local variables !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!!!!!!!!!!!!!!!! Eig - exact eigenvalues, R=|E-Eig|, Y=(X')*X-I !!!!!!!!!!!!!!!\n real*8 Eig(n)\n real*8 R(n)\n real*8 Y(n,n)\n integer i,j\n integer ldx, ldy\n real*8 one, zero, smax, eigabs\n!!!!!!!!!!!!!!!!! Exact eigenvalues in range (3.0, 7.0) !!!!!!!!!!!!!!!!!!!!!!\n Eig=0.0d0\n Eig(1)=3.17157287525381d0\n Eig(2)=4.0d0\n Eig(3)=4.0d0\n Eig(4)=4.1292484841890931d0\n Eig(5)=4.4066499006731521d0\n Eig(6)=6.0d0\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!!!!!!!!!!!!!!!! Initialize input matrices A and B !!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n do i=1, 65\n val(i)=1.0d0\n enddo\n do i=1,6\n val(7*(i+1)-2)=6.0d0\n val(7*(i+1)-1)=3.0d0\n val(7*(i+1)+4)=3.0d0\n enddo\n val(1)=5.0d0\n val(2)=2.0d0\n val(5)=2.0d0\n val(6)=6.0d0\n val(7)=3.0d0\n val(11)=3.0d0\n val(54)=6.0d0\n val(55)=3.0d0\n val(59)=3.0d0\n val(60)=6.0d0\n val(61)=2.0d0\n val(64)=2.0d0\n val(65)=5.0d0\n\n rows(1)=1\n rows(2)=5\n rows(3)=10\n rows(4)=16\n rows(5)=23\n rows(6)=30\n rows(7)=37\n rows(8)=44\n rows(9)=51\n rows(10)=57\n rows(11)=62\n rows(12)=66\n\n do i=1,5\n do j=2,8\n cols(7*(i+1)+j)=i-1+j-1\n enddo\n enddo\n\n do j=1,4\n do i=1,2\n cols(5*i+j-1)=j\n cols(48+5*i+j-1)=j+7\n enddo\n cols(j)=j\n cols(61+j)=j+7\n enddo\n\n cols(9)=5\n cols(14)=5\n cols(15)=6\n cols(51)=6\n cols(52)=7\n cols(57)=7\n write(*,*)rows\n write(*,*)\n write(*,*)cols\n write(*,*)\n write(*,*)val\n\n do i=1,n\n valb(i)=1.0d0\n colsb(i)=i\n rowsb(i)=i\n enddo\n rowsb(n+1)=n+1\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!!!!!!!!!!! Print matrix dimension !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n print *,'Sparse matrix size',n\n\n!!! Search interval [Emin,Emax] including M eigenpairs !!!!!!!!!!!!!!!!!!!!!!!!!\n Emin=3.0\n Emax=7.0 \n M0=L\n M=M0\n print *,'Search interval ', Emin,' ', Emax\n ldx=n\n ldy=n\n one=1.0d0\n zero=0.0d0\n\n!\n! Task 1. Call FEASTINIT to define the default values for the input\n! FEAST parameters.\n!\n call feastinit(fpm)\n fpm(1)=1\n print *, ' Testing dfeast_scsrev '\n!\n! Task 2. Solve the standard eigenvalue problem Ax=ex.\n! \n call dfeast_scsrev(UPLO,N,val,rows,cols,fpm,epsout,loop,\n $ Emin,Emax,M0,E,X,M,res,info)\n print *,' FEAST OUTPUT INFO ',info\n if(info.ne.0) stop 1\n!\n! Task 3. Compute the residual R(i) = | E(i) - Eig(i) | where Eig(i)\n! are the expected eigenvalues and E(i) are eigenvalues computed\n! with the help of SFEAST_SCSREV().\n!\n print *, 'Number of eigenvalues found ', M\n print *, ' Computed | Expected '\n print *, ' Eigenvalues | Eigenvalues '\n eigabs=0.0d0\n do i=1,M\n R(i)=dabs(E(i)-Eig(i))\n eigabs=max(eigabs, R(i))\n print *, E(i), Eig(i)\n enddo\n print *, ' Max value of '\n print *, ' | computed eigenvalue -expected eigenvalues | ', eigabs\n!\n! Task 4. Compute the maximum absolute value of the matrix\n! Y=(X')*X-I where X is the matrix of eigenvectors computed with\n! the help of DFEAST_SCSREV.\n! Call DGEMM (BLAS Level 3 Routine) to compute (X')*X.\n!\n Y=zero\n call dgemm('T','N',M,M,n,one,X,ldx,X,ldx,zero,Y,ldy)\n!\n! Compute Y=Y-I\n!\n do i=1,M\n Y(i,i)=Y(i,i)-one\n enddo\n print *,'*************************************************'\n print *,'************** REPORT ***************************'\n print *,'*************************************************'\n print *,'# Search interval [Emin,Emax]',Emin,Emax\n print *,'# mode found/subspace',M,M0\n print *,'# iterations',loop\n print *,'Relative error on the trace',epsout\n print *,'Eigenvalues/Residuals'\n do i=1,M\n print *,i,E(i),' | ', res(i)\n enddo\n smax=zero\n do i=1,M\n do j=1,M\n smax=max(smax, abs(Y(i, j)))\n enddo\n enddo\n print *, ' Max absolute value of the matrix '\n print *, ' (transposed of X)*X-I ', smax\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!!!!!!!!!!!!!!!! GENERALIZED EIGENVALUE PROBLEM !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n M0=L\n M=M0\n Y=zero\n E=zero\n X=zero\n res=zero\n epsout=zero\n print *, ' Testing dfeast_scsrgv'\n!\n! Task 5. Solve the generalized eigenvalue problem Ax=eBx.\n!\n call dfeast_scsrgv(UPLO,N,val,rows,cols,valb,rowsb,colsb,\n $ fpm,epsout,loop,Emin,Emax,M0,E,X,M,res,info)\n print *,' FEAST OUTPUT INFO ',info\n if(info.ne.0) stop 1\n!\n! Task 6. Compute the residual R(i) = | E(i) - Eig(i) | where Eig(i)\n! are the expected eigenvalues and E(i) are eigenvalues computed\n! with the help of DFEAST_SCSRGV().\n!\n print *, 'Number of eigenvalues found ', M\n print *, ' Computed | Expected '\n print *, ' Eigenvalues | Eigenvalues '\n eigabs=zero\n do i=1,M\n R(i)=dabs(E(i)-Eig(i))\n eigabs=max(eigabs, R(i))\n print *, E(i), Eig(i)\n enddo\n print *, ' Max | computed eigenvalue -expected eigenvalues | ',\n & eigabs\n!\n! Task 7. Compute the maximum absolute value of the matrix\n! Y=(X')*X-I where X is the matrix of eigenvectors computed with\n! the help of DFEAST_SCSREV.\n! Call DGEMM (BLAS Level 3 Routine) to compute (X')*X.\n!\n Y=zero\n call dgemm('T','N',M,M,n,one,X,ldx,X,ldx,zero,Y,ldy)\n!\n! Compute Y=Y-I\n!\n do i=1,M\n Y(i,i)=Y(i,i) - one \n enddo\n print *,'*************************************************'\n print *,'************** REPORT ***************************'\n print *,'*************************************************'\n print *,'# Search interval [Emin,Emax]',Emin,Emax\n print *,'# mode found/subspace',M,M0\n print *,'# iterations',loop\n print *,'Relative error on the trace',epsout\n print *,'Eigenvalues/Residuals'\n do i=1,M\n print *,i,E(i),' | ', res(i)\n enddo\n smax=zero\n do i=1,M\n do j=1,M\n smax=max(smax, abs(Y(i, j)))\n enddo\n enddo\n print *, ' Max absolute value of the matrix '\n print *, ' (transposed of X)*X-I ', smax\n stop 0\n end program dexample_sparse\n", "meta": {"hexsha": "d87ca91b29ef6072dab8497f820f54f83aa9ec7e", "size": 12611, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "eigen/dexample_sparse_f.f", "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": "eigen/dexample_sparse_f.f", "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": "eigen/dexample_sparse_f.f", "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": 35.6242937853, "max_line_length": 85, "alphanum_fraction": 0.4555546745, "num_tokens": 4110, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339596505965, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.6572282625211019}} {"text": "c=======================================================================\nc\nc subroutine TESTLINEARCST \nc\nc This function tests if w(n) verifies the lower/upper bounds and\nc general linear constraints for a specified precision EPS=1.E-10\nc\nc C*w <= b (general linear constraints) \nc Cinf(i) <= w(i) <= Csup(i) (lower/upper bounds)\nc\nc if the constraints are verified then info = 0\nc else info = -115\nc-----------------------------------------------------------------------\n SUBROUTINE testlinearcst ( n, w, neq, nin, ccst, bcst, cinf, csup,\n & dwork, info )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : portfolio size integer\nc w : point (n) double \nc neq : number equality constraints integer\nc nin : number inequality constraints integer\nc ccst : matrix of constraints (nasset*(neq+nin)) double\nc bcst : vector initial of constraints (neq+nin) double\nc cinf : lower bound (n) double\nc csup : upper bound (n) double\nc\nc WORKSPACE \nc dwork : n double\nc\nc OUTPUT \nc info : diagnostic argument integer\nc \nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\nc\nc arguments i/o\n INTEGER n, info, neq, nin\n DOUBLE PRECISION w(*), cinf(*), csup(*), ccst(n,*), bcst(*)\nc\nc workspaces\n DOUBLE PRECISION dwork(*)\nc\nc local variables\n INTEGER i, m, pdy\n DOUBLE PRECISION a, b, EPS\n PARAMETER (EPS = 1.E-10)\nc\nc external subroutines\n EXTERNAL PMTV\nc\nc-----------------------------------------------------------------------\nc\nc\nc initializations\n info = 0 ! diagnostic argument\n m = neq + nin ! number of general linear constraints\nc\nc pointers for double precision work space : dwork\nc -------------------------------------------------\n pdy = 1\nc\nc Total size of dwork array = n\nc\nc-----------------------------------------------------------------------\nc\nc test: cinf <= w <= csup\n DO i = 1,n\n IF ((w(i).LT.cinf(i)-EPS).OR.(w(i).GT.csup(i)+EPS)) THEN\n info = -115\n RETURN\n ENDIF\n ENDDO\nc\nc no test todo if m=0\n IF (m .EQ. 0) THEN\n RETURN\n ENDIF\nc\nc PMTV : matrix vector product, pdy(m) <- C'(n,m)*w(n) \n CALL PMTV ( n, m, ccst, w, dwork(pdy) ) \nc\nc test: C*w <= b\n DO i = 1,m \n a = dwork(pdy+i-1)\n b = bcst(i)\n IF (a .GT. b+EPS) THEN\n info = -115\n RETURN\n ENDIF\n ENDDO\n RETURN\n END\n", "meta": {"hexsha": "60040294416906601b2c3c1e6fe2a14fdd65108d", "size": 3006, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/optim_portfolio/testlinearcst.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/optim_portfolio/testlinearcst.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/optim_portfolio/testlinearcst.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": 31.6421052632, "max_line_length": 73, "alphanum_fraction": 0.4041916168, "num_tokens": 729, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972818382005, "lm_q2_score": 0.7549149868676284, "lm_q1q2_score": 0.6572269355858781}} {"text": " PROGRAM PRIMES2\nC\nC PROGRAM TO PRINT THE FIRST N PRIMES\nC\n READ(*,*)N\n I=1\n J=0\n 10 I=I+1\n IS = SQRT(FLOAT(I))\n DO 20 K=2,IS\n IF (I/K*K .EQ.I) GOTO 10\n 20 CONTINUE\n WRITE(*,*)I\n J=J+1\n IF (J.LT.N) GOTO 10\n END\n", "meta": {"hexsha": "8585991508f76e9bed7685fd2c6a6e8af786729f", "size": 274, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/UOW/CSCI337/examples/primes_2.f", "max_stars_repo_name": "felx/detritus", "max_stars_repo_head_hexsha": "b64d28b47381ea1e8c6b5282910365dc4292d57f", "max_stars_repo_licenses": ["MIT"], "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/UOW/CSCI337/examples/primes_2.f", "max_issues_repo_name": "felx/detritus", "max_issues_repo_head_hexsha": "b64d28b47381ea1e8c6b5282910365dc4292d57f", "max_issues_repo_licenses": ["MIT"], "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/UOW/CSCI337/examples/primes_2.f", "max_forks_repo_name": "felx/detritus", "max_forks_repo_head_hexsha": "b64d28b47381ea1e8c6b5282910365dc4292d57f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-07-03T09:22:08.000Z", "max_forks_repo_forks_event_max_datetime": "2018-07-03T09:22:08.000Z", "avg_line_length": 16.1176470588, "max_line_length": 41, "alphanum_fraction": 0.4671532847, "num_tokens": 119, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8705972751232809, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6572269305166846}} {"text": "program speed\n use interpreter\n implicit none\n\n integer, parameter :: N=10000000\n character(200) :: s, v, e\n real(8) :: x, y, r, t\n integer :: i, ff, c1, c2, cr, cm\n\n r = 0.0d0\n \n call system_clock(c1, cr, cm)\n do i = 1, N\n x = 500.0d0 - dble(i)/1000.0d0\n y = 100.0d0 - dble(i)/5000.0d0\n r = r + f(x, y)\n end do\n call system_clock(c2)\n\n write(*, *) \"Compiled code time= \", dble(c2-c1)/dble(cr)\n write(*, *) \"Compiled code result= \", r\n\n s = '0.5d0 - 0.5d0*cos(x-2.0d0*y) '\n v = 'x y'\n call s_createfn(s, v, ff, e)\n r = 0.0d0\n \n call system_clock(c1)\n do i = 1, N\n x = 500.0d0 - dble(i)/1000.0d0\n y = 100.0d0 - dble(i)/5000.0d0\n call s_evaluatefn(ff, (/ x, y /), t, e)\n r = r + t\n end do\n call system_clock(c2)\n \n write(*,*) \"Parsed code time= \", dble(c2-c1)/dble(cr)\n write(*,*) \"Parsed code result= \", r\n\ncontains\n\n function f(x,y)\n real(8) :: f, x, y\n\n f = 0.5d0 - 0.5d0*cos(x-2.0d0*y)\n end function f\nend program speed\n", "meta": {"hexsha": "931753a6f47d92bd1ba2c29c18c62a2acec604c3", "size": 987, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "speed.f90", "max_stars_repo_name": "sdm900/fortran_parser", "max_stars_repo_head_hexsha": "d079d5046d4300c9c95734553543d941b949f7eb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "speed.f90", "max_issues_repo_name": "sdm900/fortran_parser", "max_issues_repo_head_hexsha": "d079d5046d4300c9c95734553543d941b949f7eb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "speed.f90", "max_forks_repo_name": "sdm900/fortran_parser", "max_forks_repo_head_hexsha": "d079d5046d4300c9c95734553543d941b949f7eb", "max_forks_repo_licenses": ["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.5625, "max_line_length": 58, "alphanum_fraction": 0.5501519757, "num_tokens": 435, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232808, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6572269257162315}} {"text": "module evaluate\nuse config, only: ptol\nuse compare\nuse math\nimplicit none\n\nprivate\npublic :: basis_funs, ders_basis_funs\npublic :: decasteljau1, decasteljau2, bezier_curve_points, bezier_surface_points\npublic :: curve_point, curve_points, rat_curve_derivs, curve_derivs_alg1\npublic :: surface_point, surface_points, rat_surface_derivs, surface_derivs_alg1\npublic :: find_span, find_span_mult, find_mult_knots, find_mult\npublic :: check_param\n\ncontains\n\nsubroutine decasteljau1(cpw, n, u, pnt)\n !> Compute a point on a Bezier curve using deCasteljau algorithm.\n !> n - Number of control points - 1.\n !> cpw - Control points.\n !> u - Parameter (0. <= u <= 1.).\n !> pnt - Point on Bezier curve.\n \n !f2py inent(in) cpw, n, u\n !f2py intent(out) pnt\n !f2py depend(n) cpw\n \n ! Input\n integer, intent(in) :: n\n double precision, intent(in) :: u\n double precision, intent(in) :: cpw(0:n, 0:3)\n \n ! Output\n double precision, intent(out) :: pnt(0:3)\n \n ! Working\n integer :: i, k\n double precision :: u_\n double precision :: temp(0:n, 0:3)\n \n u_ = check_bounds(u, 0.0d0, 1.0d0)\n temp = cpw\n do k = 1, n\n do i = 0, n - k\n temp(i, :) = (1.0d0 - u_) * temp(i, :) + u_ * temp(i + 1, :)\n end do\n end do\n pnt = temp(0, :)\n \nend subroutine decasteljau1\n\nsubroutine decasteljau2(cpw, n, m, u, v, pnt)\n !> Compute a point on a Bezier surface using deCasteljau algorithm.\n !> cpw - Control points.\n !> n - Number of control points - 1 in u-direction.\n !> m - Number of control points - 1 in v-direction.\n !> u - Parameter in u-direction (0. <= u <= 1.).\n !> v - Parameter in v-direction (0. <= v <= 1.).\n !> pnt - Point on Bezier surface.\n \n !f2py intent(in) cpw, n, m, u, v\n !f2py intent(out) pnt\n !f2py depend(n, m) cpw\n \n ! Input\n integer, intent(in) :: n, m\n double precision, intent(in) :: u, v\n double precision, intent(in) :: cpw(0:n, 0:m, 0:3)\n \n ! Output\n double precision, intent(out) :: pnt(0:3)\n \n ! Working\n integer :: i, j, k\n double precision :: temp1(0:min(n, m), 0:3)\n double precision :: temp2(0:max(n, m), 0:3)\n \n temp1(:, :) = 0.0d0\n temp2(:, :) = 0.0d0\n if (n .le. m) then\n do j = 0, m\n temp1 = cpw(0:n, j, :)\n call decasteljau1(temp1, n, u, pnt)\n temp2(j, :) = pnt\n end do\n call decasteljau1(temp2, m, v, pnt)\n else\n do i = 0, n\n temp1 = cpw(i, 0:m, :)\n call decasteljau1(temp1, m, v, pnt)\n temp2(i, :) = pnt\n end do\n call decasteljau1(temp2, n, u, pnt)\n end if\n \nend subroutine decasteljau2\n\nsubroutine find_span(n, p, u, uk, mid)\n !> Determine the knot span index.\n !> n - Number of control points - 1.\n !> p - Degree.\n !> u - Parameter .\n !> uk - Knot vector.\n !> mid - Knot span.\n \n !f2py inent(in) n, p, u, uk\n !f2py intent(out) mid\n !f2py depend(n, p) uk\n \n ! Input\n integer, intent(in) :: n, p\n double precision, intent(in) :: u\n double precision, intent(in) :: uk(0:n + p + 1)\n \n ! Output\n integer, intent(out) :: mid\n \n ! Working\n integer :: low, high\n \n ! Special case\n if (GreaterThanEq(u, uk(n + 1), ptol)) then\n mid = n\n return\n end if\n if (LessThanEq(u, uk(p), ptol)) then\n mid = p\n return\n end if\n \n low = p\n high = n + 1\n mid = (low + high) / 2\n do while ((LessThan(u, uk(mid), ptol)) .or. (GreaterThanEq(u, uk(mid + 1), ptol)))\n if (LessThan(u, uk(mid), ptol)) then\n high = mid\n else\n low = mid\n end if\n mid = (low + high) / 2\n end do\n \nend subroutine find_span\n\nsubroutine basis_funs(i, u, p, uk, m, bf)\n !> Compute the non-vanishing basis functions.\n !> i - Knot span index.\n !> u - Parameter.\n !> p - Degree.\n !> uk - Knot vector.\n !> m - Size of knot vector - 1.\n !> bf - Non-vanishing basis functions.\n \n !f2py intent(in) i, u, p, uk, m\n !f2py intent(out) bf\n !f2py depend(m) uk\n !f2py depend(p) bf\n \n ! Input\n integer, intent(in) :: i, p, m\n double precision, intent(in) :: u\n double precision, intent(in) :: uk(0:m)\n \n ! Output\n double precision, intent(out) :: bf(0:p)\n \n ! Working\n integer :: j, r\n double precision :: temp, saved, u_\n double precision :: left(0:p), right(0:p)\n \n bf(:) = 0.0d0\n left(:) = 0.0d0\n right(:) = 0.0d0\n \n u_ = check_bounds(u, uk(0), uk(m))\n bf(0) = 1.0d0\n do j = 1, p\n left(j) = u_ - uk(i + 1 - j)\n right(j) = uk(i + j) - u_\n saved = 0.0d0\n do r = 0, j - 1\n temp = bf(r) / (right(r + 1) + left(j - r))\n bf(r) = saved + right(r + 1) * temp\n saved = left(j - r) * temp\n end do\n bf(j) = saved\n end do\n \nend subroutine basis_funs\n\nsubroutine ders_basis_funs(i, u, p, n, uk, m, ders)\n !> Compute nonzero basis functions and their derivatives.\n !> i - Knot span index.\n !> u - Parameter.\n !> p - Degree.\n !> n - Number of derivatives to compute (n <= p).\n !> uk - Knot vector.\n !> m - Size of knot vector - 1.\n !> ders - Basis functions and derivatives ders(k, j) where k is\n !> the k-th derivative.\n \n !f2py intent(in) i, u, p, n, uk, m\n !f2py intent(out) ders\n !f2py depend(m) uk\n !f2py depend(n, p) ders\n \n ! Input\n integer, intent(in) :: i, p, n, m\n double precision, intent(in) :: u\n double precision, intent(in) :: uk(0:m)\n \n ! Output\n double precision, intent(out) :: ders(0:n, 0:p)\n \n ! Working\n integer :: j, k, r, j1, j2, rk, pk, s1, s2\n double precision :: saved, temp, d, u_\n double precision :: left(0:p), right(0:p)\n double precision :: ndu(0:p, 0:p), a(0:1, 0:p)\n \n ders(:, :) = 0.0d0\n left(:) = 0.0d0\n right(:) = 0.0d0\n ndu(:, :) = 0.0d0\n a(:, :) = 0.0d0\n \n u_ = check_bounds(u, uk(0), uk(m))\n ndu(0, 0) = 1.0d0\n do j = 1, p\n left(j) = u_ - uk(i + 1 - j)\n right(j) = uk(i + j) - u_\n saved = 0.d0\n do r = 0, j - 1\n ndu(j, r) = right(r + 1) + left(j - r)\n temp = ndu(r, j - 1) / ndu(j, r)\n ndu(r, j) = saved + right(r + 1) * temp\n saved = left(j - r) * temp\n end do\n ndu(j, j) = saved\n end do\n do j = 0, p\n ders(0, j) = ndu(j, p)\n end do\n do r = 0, p\n s1 = 0\n s2 = 1\n a(0, 0) = 1.d0\n do k = 1, n\n d = 0.d0\n rk = r - k\n pk = p - k\n if (r .ge. k) then\n a(s2, 0) = a(s1, 0) / ndu(pk + 1, rk)\n d = a(s2, 0) * ndu(rk, pk)\n end if\n if (rk .ge. -1) then\n j1 = 1\n else\n j1 = -rk\n end if\n if (r - 1 .le. pk) then\n j2 = k - 1\n else\n j2 = p - r\n end if\n do j = j1, j2\n a(s2, j) = (a(s1, j) - a(s1, j - 1)) / ndu(pk + 1, rk + j)\n d = d + a(s2, j) * ndu(rk + j, pk)\n end do\n if (r .le. pk) then\n a(s2, k) = -a(s1, k - 1) / ndu(pk + 1, r)\n d = d + a(s2, k) * ndu(r, pk)\n end if\n ders(k, r) = d\n j = s1\n s1 = s2\n s2 = j\n end do\n end do\n r = p\n do k = 1, n\n do j = 0, p\n ders(k, j) = ders(k, j) * r\n end do\n r = r * (p - k)\n end do\nend subroutine ders_basis_funs\n\nsubroutine curve_point(n, p, uk, cpw, u, pnt)\n !> Compute curve point.\n !> n - Number of control points - 1.\n !> p - Degree.\n !> uk - Knot vector.\n !> cpw - Control points.\n !> u - Parameter.\n !> pnt - Point on curve.\n \n !f2py intent(in) n, p, uk, cpw, u\n !f2py intent(out) pnt\n !f2py depend(n, p) uk\n !f2py depend(n) cpw\n \n ! Input\n integer, intent(in) :: n, p\n double precision, intent(in) :: u\n double precision, intent(in) :: uk(0:n + p + 1)\n double precision, intent(in) :: cpw(0:n, 0:3)\n \n ! Output\n double precision, intent(out) :: pnt(0:2)\n \n ! Working\n integer :: i, span, m\n double precision :: bf(0:p), temp(0:3)\n \n m = n + p + 1\n call find_span(n, p, u, uk, span)\n call basis_funs(span, u, p, uk, m, bf)\n temp(:) = 0.0d0\n do i = 0, p\n temp = temp + bf(i) * cpw(span - p + i, :)\n end do\n pnt = temp(0:2) / temp(3)\n \nend subroutine curve_point\n\nsubroutine curve_derivs_alg1(n, p, uk, cpw, u, d, ck)\n !> Compute curve derivatives.\n !> n - Number of control points - 1.\n !> p - Degree.\n !> uk - Knot vector.\n !> cpw - Control points.\n !> u - Parameter.\n !> d - Maximum derivative to compute.\n !> ck - Curve derivatives ck(k, :) where k is the k-th derivative and\n !> 0 <= k <= d.\n \n !f2py intent(in) n, p, uk, cpw, u, d\n !f2py intent(out) ck\n !f2py depend(n, p) uk\n !f2py depend(n) cpw\n !f2py depend(d) ck\n \n ! Input\n integer, intent(in) :: n, p, d\n double precision, intent(in) :: u\n double precision, intent(in) :: uk(0:n + p + 1)\n double precision, intent(in) :: cpw(0:n, 0:3)\n \n ! Output\n double precision, intent(out) :: ck(0:d, 0:3)\n \n ! Working\n integer :: du, k, span, j, m\n double precision :: nders(0:min(d, p), 0:p)\n \n ck(:, :) = 0.0d0\n du = min(d, p)\n m = n + p + 1\n call find_span(n, p, u, uk, span)\n call ders_basis_funs(span, u, p, du, uk, m, nders)\n do k = 0, du\n do j = 0, p\n ck(k, :) = ck(k, :) + nders(k, j) * cpw(span - p + j, :)\n end do\n end do\n \nend subroutine curve_derivs_alg1\n\nsubroutine rat_curve_derivs(n, p, uk, cpw, u, d, ck)\n !> Compute rational curve derivative.\n !> n - Number of control points - 1.\n !> p - Degree.\n !> uk - Knot vector.\n !> cpw - Control points.\n !> u - Parameter.\n !> d - Maximum derivative to compute.\n !> ck - Curve derivatives ck(k, :) where k is the k-th derivative and\n !> 0 <= k <= d.\n\n !f2py intent(in) n, p, uk, cpw, u, d\n !f2py intent(out) ck\n !f2py depend(n, p) uk\n !f2py depend(n) cpw\n !f2py depend(d) ck\n\n ! Input\n integer, intent(in) :: n, p, d\n double precision, intent(in) :: u\n double precision, intent(in) :: uk(0:n + p + 1)\n double precision, intent(in) :: cpw(0:n, 0:3)\n \n ! Output\n double precision, intent(out) :: ck(0:d, 0:2)\n \n integer :: i, k\n double precision :: bc\n double precision :: cders(0:d, 0:3), aders(0:d, 0:2), wders(0:d)\n double precision :: v(0:2)\n \n cders(:, :) = 0.0d0\n aders(:, :) = 0.0d0\n wders(:) = 0.0d0\n \n call curve_derivs_alg1(n, p, uk, cpw, u, d, cders)\n aders = cders(:, 0:2)\n wders = cders(:, 3)\n ck(:, :) = 0.0d0\n do k = 0, d\n v = aders(k, :)\n do i = 1, k\n bc = binomial(k, i)\n v = v - bc * wders(i) * ck(k - i, :)\n end do\n ck(k, :) = v / wders(0)\n end do\n \nend subroutine rat_curve_derivs\n\nsubroutine surface_point(n, p, uk, m, q, vk, cpw, u, v, pnt)\n !> Compute surface point.\n !> n - Number of control points - 1 in u-direction.\n !> p - Degree in u-direction.\n !> uk - Knot vector in u-direction.\n !> m - Number of control points - 1 in v-direction.\n !> q - Degree in v-direction.\n !> vk - Knot vector in v-direction.\n !> cpw - Control points.\n !> u - Parameter in u-direction.\n !> v - Parameter in v-direction.\n !> pnt - Point on surface.\n \n !f2py intent(in) n, p, uk, m, q, vk, cpw, u, v\n !f2py intent(out) pnt\n !f2py depend(n, p) uk\n !f2py depend(m, q) vk\n !f2py depend(n, m) cpw\n\n ! Input\n integer, intent(in) :: n, p, m, q\n double precision, intent(in) :: u, v\n double precision, intent(in) :: uk(0:n + p + 1), vk(0:m + q + 1)\n double precision, intent(in) :: cpw(0:n, 0:m, 0:3)\n \n ! Output\n double precision, intent(out) :: pnt(0:2)\n \n ! Working\n integer :: uspan, vspan, uind, vind, l, k, r, s\n double precision :: nu(0:p), nv(0:q)\n double precision :: temp1(0:3), temp2(0:3)\n \n call find_span(n, p, u, uk, uspan)\n r = n + p + 1\n call basis_funs(uspan, u, p, uk, r, nu)\n call find_span(m, q, v, vk, vspan)\n s = m + q + 1\n call basis_funs(vspan, v, q, vk, s, nv)\n uind = uspan - p\n temp2(:) = 0.0d0\n do l = 0, q\n temp1(:) = 0.0d0\n vind = vspan - q + l\n do k = 0, p\n temp1 = temp1 + nu(k) * cpw(uind + k, vind, :)\n end do\n temp2 = temp2 + nv(l) * temp1\n end do\n pnt = temp2(0:2) / temp2(3)\n \nend subroutine surface_point\n\nsubroutine surface_derivs_alg1(n, p, uk, m, q, vk, cpw, u, v, d, skl)\n !> Compute surface derivatives.\n !> n - Number of control points - 1 in u-direction.\n !> p - Degree in u-direction.\n !> uk - Knot vector in u-direction.\n !> m - Number of control points - 1 in v-direction.\n !> q - Degree in v-direction.\n !> vk - Knot vector in v-direction.\n !> cpw - Control points.\n !> u - Parameter in u-direction.\n !> v - Parameter in v-direction.\n !> d - Maximum derivative to compute.\n !> skl - Surface derivatives skl(k, l) with respect to u k times\n !> and v l times and 0 <= k, l <= d.\n\n !f2py intent(in) n, p, uk, m, q, vk, cpw, u, v, d\n !f2py intent(out) skl\n !f2py depend(n, p) uk\n !f2py depend(m, q) vk\n !f2py depend(n, m) cpw\n !f2py depend(d) skl\n \n ! Input\n integer, intent(in) :: n, p, m, q, d\n double precision, intent(in) :: u, v\n double precision, intent(in) :: uk(0:n + p + 1), vk(0:m + q + 1)\n double precision, intent(in) :: cpw(0:n, 0:m, 0:3)\n \n ! Output\n double precision, intent(out) :: skl(0:d, 0:d, 0:3)\n \n ! Working\n integer :: du, dv, uspan, vspan, k, s, r, dd, l\n double precision :: temp(0:q, 0:3)\n double precision, allocatable :: nu(:, :), nv(:, :)\n \n du = min(d, p)\n dv = min(d, q)\n allocate(nu(0:du, 0:p), nv(0:dv, 0:q))\n \n call find_span(n, p, u, uk, uspan)\n r = n + p + 1\n call ders_basis_funs(uspan, u, p, du, uk, r, nu)\n call find_span(m, q, v, vk, vspan)\n s = m + q + 1\n call ders_basis_funs(vspan, v, q, dv, vk, s, nv)\n\n skl(:, :, :) = 0.0d0\n temp(:, :) = 0.0d0\n do k = 0, du\n do s = 0, q\n temp(s, :) = 0.0d0\n do r = 0, p\n temp(s, :) = temp(s, :) + nu(k, r) * cpw(uspan - p + r, &\n vspan - q + s, :)\n end do\n end do\n dd = min(d - k, dv)\n do l = 0, dd\n do s = 0, q\n skl(k, l, :) = skl(k, l, :) + nv(l, s) * temp(s, :)\n end do\n end do\n end do\n \nend subroutine surface_derivs_alg1\n\nsubroutine rat_surface_derivs(n, p, uk, m, q, vk, cpw, u, v, d, skl)\n !> Compute rational surface derivatives.\n !> n - Number of control points - 1 in u-direction.\n !> p - Degree in u-direction.\n !> uk - Knot vector in u-direction.\n !> m - Number of control points - 1 in v-direction.\n !> q - Degree in v-direction.\n !> vk - Knot vector in v-direction.\n !> cpw - Control points.\n !> u - Parameter in u-direction.\n !> v - Parameter in v-direction.\n !> d - Maximum derivative to compute.\n !> skl - Surface derivatives skl(k, l) with respect to u k times\n !> and v l times and 0 <= k, l <= d.\n\n !f2py intent(in) n, p, uk, m, q, vk, cpw, u, v, d\n !f2py intent(out) skl\n !f2py depend(n, p) uk\n !f2py depend(m, q) vk\n !f2py depend(n, m) cpw\n !f2py depend(d) skl\n\n ! Input\n integer, intent(in) :: n, p, m, q, d\n double precision, intent(in) :: u, v\n double precision, intent(in) :: uk(0:n + p + 1), vk(0:m + q + 1)\n double precision, intent(in) :: cpw(0:n, 0:m, 0:3)\n \n ! Output\n double precision, intent(out) :: skl(0:d, 0:d, 0:2)\n \n ! Working\n integer :: k, l, i, j\n double precision :: bc\n double precision :: v1(0:2), v2(0:2)\n double precision :: sders(0:d, 0:d, 0:3)\n double precision :: aders(0:d, 0:d, 0:2)\n double precision :: wders(0:d, 0:d)\n \n skl(:, : ,:) = 0.0d0\n sders(:, :, :) = 0.0d0\n aders(:, :, :) = 0.0d0\n wders(:, :) = 0.0d0\n \n call surface_derivs_alg1(n, p, uk, m, q, vk, cpw, u, v, d, sders)\n do i = 0, d\n do j = 0, d\n aders(i, j, :) = sders(i, j, 0:2)\n wders(i, j) = sders(i, j, 3)\n end do\n end do\n\n do k = 0, d\n do l = 0, d - k\n v1 = aders(k, l, :)\n do j = 1, l\n bc = binomial(l, j)\n v1 = v1 - bc * wders(0, j) * skl(k, l - j, :)\n end do\n do i = 1, k\n bc = binomial(k, i)\n v1 = v1 - bc * wders(i, 0) * skl(k - i, l, :)\n v2(:) = 0.0d0\n do j = 1, l\n bc = binomial(l, j)\n v2 = v2 + bc * wders(i, j) * skl(k - i, l - j, :)\n end do\n bc = binomial(k, i)\n v1 = v1 - bc * v2\n end do\n skl(k, l, :) = v1 / wders(0, 0)\n end do\n end do\n \nend subroutine rat_surface_derivs\n\nsubroutine find_span_mult(n, p, u, uk, span, s)\n !> Determine the knot span index and multiplicity.\n !> n - Number of control points - 1.\n !> p - Degree.\n !> u - Parameter.\n !> uk - Knot vector.\n !> span - Knot span index.\n !> s - Multiplicity of knot.\n \n !f2py intent(in) n, p, u, uk\n !f2py intent(out) span, s\n !f2py depend(n, p) uk\n\n ! Input\n integer, intent(in) :: n, p\n double precision, intent(in) :: u\n double precision, intent(in) :: uk(0:n + p + 1)\n \n ! Output\n integer, intent(out) :: span, s\n \n ! Working\n integer :: i, first, last, step\n\n call find_span(n, p, u, uk, span)\n \n if ((GreaterThan(u, uk(span), ptol)) .and. (LessThan(u, uk(span + 1), ptol))) then\n s = 0\n return\n end if\n \n if ((GreaterThan(u, uk(span), ptol)) .and. (LessThanEq(u, uk(span + 1), ptol))) then\n first = span + 1\n last = n + p + 1\n step = 1\n else\n first = span\n last = 0\n step = -1\n end if\n \n s = 0\n do i = first, last, step\n ! if (u .eq. uk(i)) then\n if (EqualTo(u, uk(i), ptol)) then\n s = s + 1\n else\n return\n end if\n end do\n \nend subroutine find_span_mult\n\nfunction find_mult(n, p, uk, u) result(mult)\n !> Determine the multiplicity of the parameter.\n !> n - Number of control points - 1.\n !> p - Degree.\n !> uk - Knot vector.\n !> u - Parameter.\n !> mult - Multiplicity of parameter.\n \n ! Input\n integer, intent(in) :: n, p\n double precision, intent(in) :: u\n double precision, intent(in) :: uk(0: n + p + 1)\n \n ! Output\n integer :: mult\n \n ! Working\n integer :: k\n \n call find_span_mult(n, p, u, uk, k, mult)\n \nend function find_mult\n\nsubroutine find_mult_knots(n, p, uk, nu, um, uq)\n !> Find the multiplicities and the unique knots of the knot vector.\n !> n - Number of control points - 1.\n !> p - Degree.\n !> uk - Knot vector.\n !> nu - Number of unique knots.\n !> um - Multiplicity of each unique knot.\n !> uq - Unique knot vector.\n \n !f2py intent(in) n, p, uk\n !f2py intent(out) nu, um, uq\n !f2py depend(n, p) uk, um, uq\n \n ! Input\n integer, intent(in) :: n, p\n double precision, intent(in) :: uk(0:n + p + 1)\n \n ! Output\n integer, intent(out) :: nu\n integer, intent(out) :: um(0:n + p + 1)\n double precision, intent(out) :: uq(0:n + p + 1)\n \n ! Working\n integer :: i, m, mult\n \n um(:) = 0\n uq(:) = 0.0d0\n \n i = 0\n m = n + p + 1\n nu = 0\n do while (i .le. m)\n uq(nu) = uk(i)\n mult = 0\n ! do while ((i .le. m) .and. (dabs(uk(i) .eq. uq(nu))))\n do while ((i .le. m) .and. (EqualTo(uk(i), uq(nu), ptol)))\n i = i + 1\n mult = mult + 1\n if ( i .gt. m) then\n exit\n end if\n end do\n um(nu) = mult\n nu = nu + 1\n end do\n \nend subroutine find_mult_knots\n\nsubroutine check_param(n, p, uk, u, is_closed)\n !> Check that the parameter is within the knot vector or is within\n !> tolerance of a unique knot value.\n !> n - Number of control points - 1.\n !> p - Degree.\n !> uk - Knot vector.\n !> u - Parameter.\n !> Option to specify a closed knot vector.\n \n ! Input\n integer, intent(in) :: n, p\n double precision, intent(in) :: uk(0:n + p + 1)\n \n ! In/Out\n double precision, intent(inout) :: u\n \n ! Optional\n logical, intent(in), optional :: is_closed\n \n ! Working\n logical :: is_closed_\n integer :: k\n \n if (present(is_closed)) then\n is_closed_ = is_closed\n else\n is_closed_ = .false.\n end if\n \n if (is_closed_) then\n if (u .gt. uk(n + 1)) then\n u = u - uk(n + 1) + uk(p)\n elseif (u .lt. uk(p)) then\n u = uk(n + 1) + u - uk(p)\n end if\n end if\n \n call find_span(n, p, u, uk, k)\n \n if (LessThanEq(u, uk(k), ptol)) then\n u = uk(k)\n return\n end if\n \n if (GreaterThanEq(u, uk(k + 1), ptol)) then\n u = uk(k + 1)\n return\n end if\n \nend subroutine check_param\n\nsubroutine bezier_curve_points(n, cpw, nu, arr_u, pnts)\n !> Compute Bezier curve points.\n !> n - Number of control points - 1.\n !> cpw - Control points.\n !> nu - Number of parameters.\n !> arr_u - Parameters.\n !> pnts - Points on curve.\n \n !f2py intent(in) n, cpw, nu, arr_u\n !f2py intent(out) pnts\n !f2py depend(n) cpw\n !f2py depend(nu) arr_u\n !f2py depend(nu) pnts\n \n ! Input\n integer, intent(in) :: n, nu\n double precision, intent(in) :: arr_u(nu)\n double precision, intent(in) :: cpw(0:n, 0:3)\n \n ! Output\n double precision, intent(out) :: pnts(nu, 3)\n \n ! Working\n integer :: i\n double precision :: pi(4)\n \n pnts(:, :) = 0.0d0\n do i = 1, nu\n call decasteljau1(cpw, n, arr_u(i), pi)\n pnts(i, :) = pi(1:3) / pi(4)\n end do\n\nend subroutine bezier_curve_points\n\nsubroutine curve_points(n, p, uk, cpw, nu, arr_u, pnts)\n !> Compute curve points.\n !> n - Number of control points - 1.\n !> p - Degree.\n !> uk - Knot vector.\n !> cpw - Control points.\n !> nu - Number of parameters.\n !> arr_u - Parameters.\n !> pnts - Points on curve.\n \n !f2py intent(in) n, p, uk, cpw, nu, arr_u\n !f2py intent(out) pnts\n !f2py depend(n, p) uk\n !f2py depend(n) cpw\n !f2py depend(nu) arr_u\n !f2py depend(nu) pnts\n \n ! Input\n integer, intent(in) :: n, p, nu\n double precision, intent(in) :: arr_u(nu)\n double precision, intent(in) :: uk(0:n + p + 1)\n double precision, intent(in) :: cpw(0:n, 0:3)\n \n ! Output\n double precision, intent(out) :: pnts(nu, 3)\n \n ! Working\n integer :: i\n double precision :: pi(3)\n \n pnts(:, :) = 0.0d0\n do i = 1, nu\n call curve_point(n, p, uk, cpw, arr_u(i), pi)\n pnts(i, :) = pi\n end do\n\nend subroutine curve_points\n\nsubroutine bezier_surface_points(n, m, cpw, np, arr_u, arr_v, pnts)\n !> Compute points on a Bezier surface.\n !> n - Number of control points - 1 in u-direction.\n !> m - Number of control points - 1 in v-direction.\n !> cpw - Control points.\n !> np - Number of parameters.\n !> arr_u - Parameters in u-direction.\n !> arr_v - Parameters in v-direction.\n !> pnts - Points on Bezier surface.\n \n !f2py intent(in) cpw, n, m, arr_u, arr_v, np\n !f2py intent(out) pnts\n !f2py depend(n, m) cpw\n !f2py depend(np) arr_u, arr_v, pnts\n \n ! Input\n integer, intent(in) :: n, m, np\n double precision, intent(in) :: arr_u(np), arr_v(np)\n double precision, intent(in) :: cpw(0:n, 0:m, 0:3)\n \n ! Output\n double precision, intent(out) :: pnts(np, 3)\n \n ! Working\n integer :: i\n double precision :: pi(4)\n \n pnts(:, :) = 0.0d0\n do i = 1, np\n call decasteljau2(cpw, n, m, arr_u(i), arr_v(i), pi)\n pnts(i, :) = pi(1:3) / pi(4)\n end do\n\nend subroutine bezier_surface_points\n\nsubroutine surface_points(n, p, uk, m, q, vk, cpw, np, arr_u, arr_v, pnts)\n !> Compute surface points.\n !> n - Number of control points - 1 in u-direction.\n !> p - Degree in u-direction.\n !> uk - Knot vector in u-direction.\n !> m - Number of control points - 1 in v-direction.\n !> q - Degree in v-direction.\n !> vk - Knot vector in v-direction.\n !> cpw - Control points.\n !> np - Number of parameters.\n !> arr_u - Parameters in u-direction.\n !> arr_v - Parameters in v-direction.\n !> pnt - Points on surface.\n \n !f2py intent(in) n, p, uk, m, q, vk, cpw, np, arr_u, arr_v\n !f2py intent(out) pnts\n !f2py depend(n, p) uk\n !f2py depend(m, q) vk\n !f2py depend(n, m) cpw\n !f2py depend(np) arr_u, arr_v, pnts\n\n ! Input\n integer, intent(in) :: n, p, m, q, np\n double precision, intent(in) :: arr_u(np), arr_v(np)\n double precision, intent(in) :: uk(0:n + p + 1), vk(0:m + q + 1)\n double precision, intent(in) :: cpw(0:n, 0:m, 0:3)\n \n ! Output\n double precision, intent(out) :: pnts(np, 3)\n \n ! Working\n integer :: i\n double precision :: pi(3)\n \n pnts(:, :) = 0.0d0\n do i = 1, np\n call surface_point(n, p, uk, m, q, vk, cpw, arr_u(i), arr_v(i), pi)\n pnts(i, :) = pi\n end do\n\nend subroutine surface_points\n\nend module evaluate", "meta": {"hexsha": "6fecdb15597e21af76d504b5ad3209d3dc27793b", "size": 25735, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/geometry/evaluate.f90", "max_stars_repo_name": "trelau/pyNURBS", "max_stars_repo_head_hexsha": "5dfd082fe368c1140ce485dc64b049b32c267d1f", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-04-16T20:30:19.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-03T07:40:47.000Z", "max_issues_repo_path": "src/geometry/evaluate.f90", "max_issues_repo_name": "trelau/pyNURBS", "max_issues_repo_head_hexsha": "5dfd082fe368c1140ce485dc64b049b32c267d1f", "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/geometry/evaluate.f90", "max_forks_repo_name": "trelau/pyNURBS", "max_forks_repo_head_hexsha": "5dfd082fe368c1140ce485dc64b049b32c267d1f", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-09-23T14:28:12.000Z", "max_forks_repo_forks_event_max_datetime": "2018-09-23T14:28:12.000Z", "avg_line_length": 27.348565356, "max_line_length": 88, "alphanum_fraction": 0.5106664076, "num_tokens": 9032, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.870597268408361, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.657226925447491}} {"text": "*DECK PCHDF\n REAL FUNCTION PCHDF (K, X, S, IERR)\nC***BEGIN PROLOGUE PCHDF\nC***SUBSIDIARY\nC***PURPOSE Computes divided differences for PCHCE and PCHSP\nC***LIBRARY SLATEC (PCHIP)\nC***TYPE SINGLE PRECISION (PCHDF-S, DPCHDF-D)\nC***AUTHOR Fritsch, F. N., (LLNL)\nC***DESCRIPTION\nC\nC PCHDF: PCHIP Finite Difference Formula\nC\nC Uses a divided difference formulation to compute a K-point approx-\nC imation to the derivative at X(K) based on the data in X and S.\nC\nC Called by PCHCE and PCHSP to compute 3- and 4-point boundary\nC derivative approximations.\nC\nC ----------------------------------------------------------------------\nC\nC On input:\nC K is the order of the desired derivative approximation.\nC K must be at least 3 (error return if not).\nC X contains the K values of the independent variable.\nC X need not be ordered, but the values **MUST** be\nC distinct. (Not checked here.)\nC S contains the associated slope values:\nC S(I) = (F(I+1)-F(I))/(X(I+1)-X(I)), I=1(1)K-1.\nC (Note that S need only be of length K-1.)\nC\nC On return:\nC S will be destroyed.\nC IERR will be set to -1 if K.LT.2 .\nC PCHDF will be set to the desired derivative approximation if\nC IERR=0 or to zero if IERR=-1.\nC\nC ----------------------------------------------------------------------\nC\nC***SEE ALSO PCHCE, PCHSP\nC***REFERENCES Carl de Boor, A Practical Guide to Splines, Springer-\nC Verlag, New York, 1978, pp. 10-16.\nC***ROUTINES CALLED XERMSG\nC***REVISION HISTORY (YYMMDD)\nC 820503 DATE WRITTEN\nC 820805 Converted to SLATEC library version.\nC 870813 Minor cosmetic changes.\nC 890411 Added SAVE statements (Vers. 3.2).\nC 890411 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\nC 900328 Added TYPE section. (WRB)\nC 910408 Updated AUTHOR and DATE WRITTEN sections in prologue. (WRB)\nC 920429 Revised format and order of references. (WRB,FNF)\nC 930503 Improved purpose. (FNF)\nC***END PROLOGUE PCHDF\nC\nC**End\nC\nC DECLARE ARGUMENTS.\nC\n INTEGER K, IERR\n REAL X(K), S(K)\nC\nC DECLARE LOCAL VARIABLES.\nC\n INTEGER I, J\n REAL VALUE, ZERO\n SAVE ZERO\n DATA ZERO /0./\nC\nC CHECK FOR LEGAL VALUE OF K.\nC\nC***FIRST EXECUTABLE STATEMENT PCHDF\n IF (K .LT. 3) GO TO 5001\nC\nC COMPUTE COEFFICIENTS OF INTERPOLATING POLYNOMIAL.\nC\n DO 10 J = 2, K-1\n DO 9 I = 1, K-J\n S(I) = (S(I+1)-S(I))/(X(I+J)-X(I))\n 9 CONTINUE\n 10 CONTINUE\nC\nC EVALUATE DERIVATIVE AT X(K).\nC\n VALUE = S(1)\n DO 20 I = 2, K-1\n VALUE = S(I) + VALUE*(X(K)-X(I))\n 20 CONTINUE\nC\nC NORMAL RETURN.\nC\n IERR = 0\n PCHDF = VALUE\n RETURN\nC\nC ERROR RETURN.\nC\n 5001 CONTINUE\nC K.LT.3 RETURN.\n IERR = -1\n CALL XERMSG ('SLATEC', 'PCHDF', 'K LESS THAN THREE', IERR, 1)\n PCHDF = ZERO\n RETURN\nC------------- LAST LINE OF PCHDF FOLLOWS ------------------------------\n END\n", "meta": {"hexsha": "e40a900352446e801118e64e14c8394c3dde15fa", "size": 3186, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/pchdf.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/pchdf.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/pchdf.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.7757009346, "max_line_length": 72, "alphanum_fraction": 0.580351538, "num_tokens": 1036, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934406, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6572269251787497}} {"text": "!!## MODULE: FUNCTION xyPLANE\nMODULE FUN_xyPLANE\n!!### PURPOSE\n!! Create a plane with three different interfaces.\n\n\n!!### USAGE\n!! Three different versions are provided:\n!\n! Pn = xyPLANE_C( C )\n!\n!! where is a rank 1 array of coefficients, which define\n!! the plane by equation $ ax + by + c = 0 $.\n!\n! Pn = xyPLANE_P2( P2 )\n!\n!! where is a rank 2 array of 2 points , .\n!\n! Pn = xyPLANE_PV( P , V )\n!\n!\n!! where

is a point and is a vector in the direction of the\n!! plane normal.\n\n\n!!### METHOD\n!! Uses the Hessian normal form for a plane.\n\n\n!!### EXTERNAL KINDS\nUSE KND_IntrinsicTypes,ONLY: KIND_Rsp,KIND_Rdp !!((01-A-KND_IntrinsicTypes.f90))\n\n\n!!### EXTERNAL PARAMETERS\nUSE PAR_Constants_Rsp,ONLY: c_0_Rsp => c_0 !!((02-A-PAR_Constants_Rsp.f90))\nUSE PAR_Constants_Rdp,ONLY: c_0_Rdp => c_0 !!((02-A-PAR_Constants_Rdp.f90))\n\n\n!!### EXTERNAL PROCEDURES\nUSE FUN_xyCROSS ,ONLY: xyCROSS_VV !!((03-A-FUN_xyCROSS.f90))\nUSE FUN_xyPERPCCW,ONLY: xyPERPCCW_V !!((03-A-FUN_xyPERPCCW.f90))\nUSE FUN_xyDOT ,ONLY: xyDOT_VV !!((03-A-FUN_xyDOT.f90))\nUSE FUN_xyNORM ,ONLY: xyNORM_V !!((03-A-FUN_xyNORM.f90))\nUSE FUN_xyVECTOR ,ONLY: xyVECTOR_PP !!((03-A-FUN_xyVECTOR.f90))\n\n\n!!### DEFAULT IMPLICIT\nIMPLICIT NONE\n\n\n!!### DEFAULT ACCESS\nPRIVATE\n\n\n!!### PROCEDURE OVERLOADING\nINTERFACE xyPLANE_P2\n MODULE PROCEDURE xyPLANE_P2_Rsp\n MODULE PROCEDURE xyPLANE_P2_Rdp\nEND INTERFACE\n\nINTERFACE xyPLANE_PV\n MODULE PROCEDURE xyPLANE_PV_Rsp\n MODULE PROCEDURE xyPLANE_PV_Rdp\nEND INTERFACE\n\nINTERFACE xyPLANE_C\n MODULE PROCEDURE xyPLANE_PAR_Rsp\n MODULE PROCEDURE xyPLANE_PAR_Rdp\nEND INTERFACE\n\n\n!!### PUBLIC ACCESS LIST\nPUBLIC :: xyPLANE_P2\nPUBLIC :: xyPLANE_PV\nPUBLIC :: xyPLANE_C\n\n\n!!## MODULE PROcEDURES\nCONTAINS\n\n\nPURE FUNCTION xyPLANE_PV_Rsp( P , V ) RESULT(Pn)\n!!#### LOCAL KINDS\nUSE KND_IntrinsicTypes,ONLY: KIND_R=>KIND_Rsp !!((01-A-KND_IntrinsicTypes.f90))\n!!#### LOCAL PARAMETERS\nREAL(KIND_R),PARAMETER :: c_0 = c_0_Rsp\nINCLUDE \"05-B-FUN_xyPLANE_PV.f90.hdr\"\n!!--begin--\nINCLUDE \"05-B-FUN_xyPLANE_PV.f90.bdy\"\n!!--end--\nEND FUNCTION\n\nPURE FUNCTION xyPLANE_PV_Rdp( P , V ) RESULT(Pn)\n!!#### LOCAL KINDS\nUSE KND_IntrinsicTypes,ONLY: KIND_R=>KIND_Rdp !!((01-A-KND_IntrinsicTypes.f90))\n!!#### LOCAL PARAMETERS\nREAL(KIND_R),PARAMETER :: c_0 = c_0_Rdp\nINCLUDE \"05-B-FUN_xyPLANE_PV.f90.hdr\"\n!!--begin--\nINCLUDE \"05-B-FUN_xyPLANE_PV.f90.bdy\"\n!!--end--\nEND FUNCTION\n\nPURE FUNCTION xyPLANE_PAR_Rsp( C ) RESULT(Pn)\n!!#### LOCAL KINDS\nUSE KND_IntrinsicTypes,ONLY: KIND_R=>KIND_Rsp !!((01-A-KND_IntrinsicTypes.f90))\nINCLUDE \"05-B-FUN_xyPLANE_C.f90.hdr\"\n!!--begin--\nINCLUDE \"05-B-FUN_xyPLANE_C.f90.bdy\"\n!!--end--\nEND FUNCTION\n\nPURE FUNCTION xyPLANE_PAR_Rdp( C ) RESULT(Pn)\n!!#### LOCAL KINDS\nUSE KND_IntrinsicTypes,ONLY: KIND_R=>KIND_Rdp !!((01-A-KND_IntrinsicTypes.f90))\nINCLUDE \"05-B-FUN_xyPLANE_C.f90.hdr\"\n!!--begin--\nINCLUDE \"05-B-FUN_xyPLANE_C.f90.bdy\"\n!!--end--\nEND FUNCTION\n\n\nPURE FUNCTION xyPLANE_P2_Rsp( P2 ) RESULT(Pn)\n!!#### LOCAL KINDS\nUSE KND_IntrinsicTypes,ONLY: KIND_R=>KIND_Rsp !!((01-A-KND_IntrinsicTypes.f90))\nINCLUDE \"05-B-FUN_xyPLANE_P2.f90.hdr\"\n!!--begin--\nINCLUDE \"05-B-FUN_xyPLANE_P2.f90.bdy\"\n!!--end--\nEND FUNCTION\n\nPURE FUNCTION xyPLANE_P2_Rdp( P2 ) RESULT(Pn)\n!!#### LOCAL KINDS\nUSE KND_IntrinsicTypes,ONLY: KIND_R=>KIND_Rdp !!((01-A-KND_IntrinsicTypes.f90))\nINCLUDE \"05-B-FUN_xyPLANE_P2.f90.hdr\"\n!!--begin--\nINCLUDE \"05-B-FUN_xyPLANE_P2.f90.bdy\"\n!!--end--\nEND FUNCTION\n\n\n\n\n\nEND MODULE\n", "meta": {"hexsha": "927918ba34e1fc85bb5fab60f326b94c8df84196", "size": 3542, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/05-B-FUN_xyPLANE.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/05-B-FUN_xyPLANE.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/05-B-FUN_xyPLANE.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": 24.2602739726, "max_line_length": 80, "alphanum_fraction": 0.696499153, "num_tokens": 1225, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972684083608, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6572269206470379}} {"text": "C NCLFORTSTART\n SUBROUTINE KRONSQM (n,n2,A,B,C)\n IMPLICIT NONE\nc ! input\n INTEGER n, n2 \n DOUBLE PRECISION A(n,n), B(n,n)\nc ! output\n DOUBLE PRECISION C(n2,n2)\nC NCLEND\nc computes the Kronecker product of square matrices A and B (dim=d), \nc puts into C (dim=n^2)\n INTEGER i, j, k, l, row, col\n \n DO i=1,n\n DO k=1,n\n row=n*(i-1)+k\n DO j=1,n\n DO l=1,n\n col=n*(j-1)+l\n C(row,col)=A(i,j)*B(k,l)\n END DO\n END DO\n END DO\n END DO\n \n RETURN\n END \n", "meta": {"hexsha": "d6cd8838d1f35e5d4181dd07c9a531ddece15c87", "size": 750, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ni/src/lib/nfpfort/kron_square.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "ni/src/lib/nfpfort/kron_square.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "ni/src/lib/nfpfort/kron_square.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 26.7857142857, "max_line_length": 69, "alphanum_fraction": 0.3733333333, "num_tokens": 200, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972549785201, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6572269201095555}} {"text": "module nrutils_modules\n integer(kind=4) :: iseed\ncontains\n ! Calculation of integrals...\n SUBROUTINE qromb(func,a,b,ss)\n implicit none\n INTEGER JMAX,JMAXP,K,KM\n REAL*8 a,b,func,ss,EPS\n EXTERNAL func\n PARAMETER (EPS=1.e-6, JMAX=30, JMAXP=JMAX+1, K=5, KM=K-1)\n INTEGER j\n REAL*8 dss,h(JMAXP),s(JMAXP)\n h(1)=1.\n do 11 j=1,JMAX\n call trapzd(func,a,b,s(j),j)\n if (j.ge.K) then\n call polint(h(j-KM),s(j-KM),K,0.d0,ss,dss)\n if (abs(dss).le.EPS*abs(ss)) return\n endif\n s(j+1)=s(j)\n h(j+1)=0.25*h(j)\n11 continue\n pause 'too many steps in qromb'\n END SUBROUTINE qromb\n\n SUBROUTINE qromo(func,a,b,ss,choose)\n implicit none \n INTEGER JMAX,JMAXP,K,KM\n REAL*8 a,b,func,ss,EPS\n EXTERNAL func,choose\n PARAMETER (EPS=1.e-6, JMAX=20, JMAXP=JMAX+1, K=5, KM=K-1)\n INTEGER j\n REAL*8 dss,h(JMAXP),s(JMAXP)\n h(1)=1.\n do 11 j=1,JMAX\n call choose(func,a,b,s(j),j)\n if (j.ge.K) then\n call polint(h(j-KM),s(j-KM),K,0.d0,ss,dss)\n if (abs(dss).le.EPS*abs(ss)) return\n endif\n s(j+1)=s(j)\n h(j+1)=h(j)/9.\n11 continue\n pause 'too many steps in qromo'\n END SUBROUTINE qromo\n \n SUBROUTINE qqromb(func,a,b,c,ss)\n implicit none\n INTEGER JMAX,JMAXP,K,KM\n REAL*8 a,b,c,func,ss,EPS\n EXTERNAL func\n PARAMETER (EPS=1.d-6, JMAX=30, JMAXP=JMAX+1, K=5, KM=K-1)\n INTEGER j\n REAL*8 dss,h(JMAXP),s(JMAXP)\n \n h(1)=1.\n do 11 j=1,JMAX\n call trapzd3(func,a,b,c,s(j),j)\n if (j.ge.K) then\n call polint(h(j-KM),s(j-KM),K,0.d0,ss,dss)\n if (abs(dss).le.EPS*abs(ss)) return\n endif\n s(j+1)=s(j)\n h(j+1)=0.25*h(j)\n11 continue\n pause 'too many steps in qromb'\n END SUBROUTINE qqromb\n \n SUBROUTINE mqromb(func,a,b,xp,yp,np,ss)\n implicit none\n integer np\n real*8 xp(np),yp(np)\n INTEGER JMAX,JMAXP,K,KM\n REAL*8 a,b,func,ss,EPS\n EXTERNAL func\n PARAMETER (EPS=1.d-6, JMAX=30, JMAXP=JMAX+1, K=5, KM=K-1)\n INTEGER j\n REAL*8 dss,h(JMAXP),s(JMAXP)\n \n h(1)=1.\n do 11 j=1,JMAX\n call trapzd2(func,a,b,xp,yp,np,s(j),j)\n if (j.ge.K) then\n call polint(h(j-KM),s(j-KM),K,0.d0,ss,dss)\n if (abs(dss).le.EPS*abs(ss)) return\n endif\n s(j+1)=s(j)\n h(j+1)=0.25*h(j)\n11 continue\n pause 'too many steps in qromb'\n END SUBROUTINE mqromb\n\n SUBROUTINE polint(xa,ya,n,x,y,dy)\n implicit none\n INTEGER n,NMAX\n REAL*8 dy,x,y,xa(n),ya(n)\n PARAMETER (NMAX=10)\n INTEGER i,m,ns\n REAL*8 den,dif,dift,ho,hp,w,c(NMAX),d(NMAX)\n ns=1\n dif=abs(x-xa(1))\n do 11 i=1,n\n dift=abs(x-xa(i))\n if (dift.lt.dif) then\n ns=i\n dif=dift\n endif\n c(i)=ya(i)\n d(i)=ya(i)\n11 continue\n y=ya(ns)\n ns=ns-1\n do 13 m=1,n-1\n do 12 i=1,n-m\n ho=xa(i)-x\n hp=xa(i+m)-x\n w=c(i+1)-d(i)\n den=ho-hp\n if(den.eq.0.)pause 'failure in polint'\n den=w/den\n d(i)=hp*den\n c(i)=ho*den\n12 continue\n if (2*ns.lt.n-m)then\n dy=c(ns+1)\n else\n dy=d(ns)\n ns=ns-1\n endif\n y=y+dy\n13 continue\n return\n END SUBROUTINE polint\n\n SUBROUTINE trapzd(func,a,b,s,n)\n implicit none\n INTEGER n\n REAL*8 a,b,s,func\n EXTERNAL func\n INTEGER it,j\n REAL*8 del,sum,tnm,x\n if (n.eq.1) then\n s=0.5*(b-a)*(func(a)+func(b))\n else\n it=2**(n-2)\n tnm=it\n del=(b-a)/tnm\n x=a+0.5*del\n sum=0.\n do 11 j=1,it\n sum=sum+func(x)\n x=x+del\n11 continue\n s=0.5*(s+(b-a)*sum/tnm)\n endif\n return\n END SUBROUTINE trapzd\n\n SUBROUTINE trapzd2(func,a,b,xp,yp,np,s,n)\n implicit none\n integer np\n real*8 xp(np),yp(np)\n INTEGER n\n REAL*8 a,b,s,func\n EXTERNAL func\n INTEGER it,j\n REAL*8 del,sum,tnm,x\n if (n.eq.1) then\n s=0.5*(b-a)*(func(a,xp,yp,np)+func(b,xp,yp,np))\n else\n it=2**(n-2)\n tnm=it\n del=(b-a)/tnm\n x=a+0.5*del\n sum=0.\n do 11 j=1,it\n sum=sum+func(x,xp,yp,np)\n x=x+del\n11 continue\n s=0.5*(s+(b-a)*sum/tnm)\n endif\n return\n END SUBROUTINE trapzd2\n\n SUBROUTINE trapzd3(func,a,b,c,s,n)\n implicit none\n INTEGER n\n REAL*8 a,b,c,s,func\n EXTERNAL func\n INTEGER it,j\n REAL*8 del,sum,tnm,x\n if (n.eq.1) then\n s=0.5*(b-a)*(func(a,c)+func(b,c))\n else\n it=2**(n-2)\n tnm=it\n del=(b-a)/tnm\n x=a+0.5*del\n sum=0.\n do 11 j=1,it\n sum=sum+func(x,c)\n x=x+del\n11 continue\n s=0.5*(s+(b-a)*sum/tnm)\n endif\n return\n END SUBROUTINE trapzd3\n \n SUBROUTINE midpnt(func,a,b,s,n)\n implicit none\n INTEGER n\n REAL*8 a,b,s,func\n EXTERNAL func\n INTEGER it,j\n REAL*8 ddel,del,sum,tnm,x\n if (n.eq.1) then\n s=(b-a)*func(0.5*(a+b))\n else\n it=3**(n-2)\n tnm=it\n del=(b-a)/(3.*tnm)\n ddel=del+del\n x=a+0.5*del\n sum=0.\n do 11 j=1,it\n sum=sum+func(x)\n x=x+ddel\n sum=sum+func(x)\n x=x+del\n11 continue\n s=(s+(b-a)*sum/tnm)/3.\n endif\n return\n END SUBROUTINE midpnt\n\n ! Calculation of Bessel functions...\n \n REAL*8 FUNCTION bessj0(x)\n implicit none\n REAL*8 x\n REAL*8 ax,xx,z\n REAL*8 p1,p2,p3,p4,p5,q1,q2,q3,q4,q5,r1,r2,r3,r4,r5,r6,&\n & s1,s2,s3,s4,s5,s6,y\n SAVE p1,p2,p3,p4,p5,q1,q2,q3,q4,q5,r1,r2,r3,r4,r5,r6,s1,s2,s3,s4,&\n & s5,s6\n DATA p1,p2,p3,p4,p5/1.d0,-.1098628627d-2,.2734510407d-4,&\n & -.2073370639d-5,.2093887211d-6/, q1,q2,q3,q4,q5/-.1562499995d-1,&\n & .1430488765d-3,-.6911147651d-5,.7621095161d-6,-.934945152d-7/\n DATA r1,r2,r3,r4,r5,r6/57568490574.d0,-13362590354.d0,&\n & 651619640.7d0,-11214424.18d0,77392.33017d0,-184.9052456d0/,s1,s2,&\n & s3,s4,s5,s6/57568490411.d0,1029532985.d0,9494680.718d0,&\n & 59272.64853d0,267.8532712d0,1.d0/\n if(abs(x).lt.8.)then\n y=x**2\n bessj0=(r1+y*(r2+y*(r3+y*(r4+y*(r5+y*r6)))))/(s1+y*(s2+y*(s3+y*&\n & (s4+y*(s5+y*s6)))))\n else\n ax=abs(x)\n z=8./ax\n y=z**2\n xx=ax-.785398164\n bessj0=sqrt(.636619772/ax)*(cos(xx)*(p1+y*(p2+y*(p3+y*(p4+y*&\n & p5))))-z*sin(xx)*(q1+y*(q2+y*(q3+y*(q4+y*q5)))))\n endif\n return\n END FUNCTION bessj0\n\n REAL*8 FUNCTION bessi0(x)\n implicit none\n REAL*8 x\n REAL*8 ax\n REAL*8 p1,p2,p3,p4,p5,p6,p7,q1,q2,q3,q4,q5,q6,q7,q8,q9,y\n SAVE p1,p2,p3,p4,p5,p6,p7,q1,q2,q3,q4,q5,q6,q7,q8,q9\n DATA p1,p2,p3,p4,p5,p6,p7/1.0d0,3.5156229d0,3.0899424d0,&\n & 1.2067492d0,0.2659732d0,0.360768d-1,0.45813d-2/\n DATA q1,q2,q3,q4,q5,q6,q7,q8,q9/0.39894228d0,0.1328592d-1,&\n & 0.225319d-2,-0.157565d-2,0.916281d-2,-0.2057706d-1,0.2635537d-1,&\n & -0.1647633d-1,0.392377d-2/\n if (abs(x).lt.3.75) then\n y=(x/3.75)**2\n bessi0=p1+y*(p2+y*(p3+y*(p4+y*(p5+y*(p6+y*p7)))))\n else\n ax=abs(x)\n y=3.75/ax\n bessi0=(exp(ax)/sqrt(ax))*(q1+y*(q2+y*(q3+y*(q4+y*(q5+y*(q6+y*&\n & (q7+y*(q8+y*q9))))))))\n endif\n return\n END FUNCTION bessi0\n\n REAL*8 FUNCTION bessk0(x)\n implicit none\n REAL*8 x\n REAL*8 p1,p2,p3,p4,p5,p6,p7,q1,q2,q3,q4,q5,q6,q7,y\n SAVE p1,p2,p3,p4,p5,p6,p7,q1,q2,q3,q4,q5,q6,q7\n DATA p1,p2,p3,p4,p5,p6,p7/-0.57721566d0,0.42278420d0,0.23069756d0,&\n & 0.3488590d-1,0.262698d-2,0.10750d-3,0.74d-5/\n DATA q1,q2,q3,q4,q5,q6,q7/1.25331414d0,-0.7832358d-1,0.2189568d-1,&\n & -0.1062446d-1,0.587872d-2,-0.251540d-2,0.53208d-3/\n if (x.le.2.0) then\n y=x*x/4.0\n bessk0=(-log(x/2.0)*bessi0(x))+(p1+y*(p2+y*(p3+y*(p4+y*(p5+y*&\n & (p6+y*p7))))))\n else\n y=(2.0/x)\n bessk0=(exp(-x)/sqrt(x))*(q1+y*(q2+y*(q3+y*(q4+y*(q5+y*(q6+y*&\n & q7))))))\n endif\n return\n END FUNCTION bessk0\n\n REAL*8 FUNCTION bessi1(x)\n implicit none\n REAL*8 x\n REAL*8 ax\n REAL*8 p1,p2,p3,p4,p5,p6,p7,q1,q2,q3,q4,q5,q6,q7,q8,q9,y\n SAVE p1,p2,p3,p4,p5,p6,p7,q1,q2,q3,q4,q5,q6,q7,q8,q9\n DATA p1,p2,p3,p4,p5,p6,p7/0.5d0,0.87890594d0,0.51498869d0,&\n & 0.15084934d0,0.2658733d-1,0.301532d-2,0.32411d-3/\n DATA q1,q2,q3,q4,q5,q6,q7,q8,q9/0.39894228d0,-0.3988024d-1,&\n & -0.362018d-2,0.163801d-2,-0.1031555d-1,0.2282967d-1,-0.2895312d-1,&\n & 0.1787654d-1,-0.420059d-2/\n if (abs(x).lt.3.75) then\n y=(x/3.75)**2\n bessi1=x*(p1+y*(p2+y*(p3+y*(p4+y*(p5+y*(p6+y*p7))))))\n else\n ax=abs(x)\n y=3.75/ax\n bessi1=(exp(ax)/sqrt(ax))*(q1+y*(q2+y*(q3+y*(q4+y*(q5+y*(q6+y*&\n &(q7+y*(q8+y*q9))))))))\n if(x.lt.0.)bessi1=-bessi1\n endif\n return\n END FUNCTION bessi1\n\n REAL*8 FUNCTION bessk1(x)\n implicit none\n REAL*8 x\n REAL*8 p1,p2,p3,p4,p5,p6,p7,q1,q2,q3,q4,q5,q6,q7,y\n SAVE p1,p2,p3,p4,p5,p6,p7,q1,q2,q3,q4,q5,q6,q7\n DATA p1,p2,p3,p4,p5,p6,p7/1.0d0,0.15443144d0,-0.67278579d0,&\n & -0.18156897d0,-0.1919402d-1,-0.110404d-2,-0.4686d-4/\n DATA q1,q2,q3,q4,q5,q6,q7/1.25331414d0,0.23498619d0,-0.3655620d-1,&\n & 0.1504268d-1,-0.780353d-2,0.325614d-2,-0.68245d-3/\n if (x.le.2.0) then\n y=x*x/4.0\n bessk1=(log(x/2.0)*bessi1(x))+(1.0/x)*(p1+y*(p2+y*(p3+y*(p4+y*&\n & (p5+y*(p6+y*p7))))))\n else\n y=2.0/x\n bessk1=(exp(-x)/sqrt(x))*(q1+y*(q2+y*(q3+y*(q4+y*(q5+y*(q6+y*&\n & q7))))))\n endif\n return\n END FUNCTION bessk1\n\n ! Generate random numbers...\n\n REAL*8 FUNCTION ran3(idum)\n implicit none\n INTEGER idum\n INTEGER MBIG,MSEED,MZ\n REAL*8 FAC\n PARAMETER (MBIG=1000000000,MSEED=161803398,MZ=0,FAC=1./MBIG)\n INTEGER i,iff,ii,inext,inextp,k\n INTEGER mj,mk,ma(55)\n SAVE iff,inext,inextp,ma\n DATA iff /0/\n if(idum.lt.0.or.iff.eq.0)then\n iff=1\n mj=MSEED-iabs(idum)\n mj=mod(mj,MBIG)\n ma(55)=mj\n mk=1\n do 11 i=1,54\n ii=mod(21*i,55)\n ma(ii)=mk\n mk=mj-mk\n if(mk.lt.MZ)mk=mk+MBIG\n mj=ma(ii)\n11 continue\n do 13 k=1,4\n do 12 i=1,55\n ma(i)=ma(i)-ma(1+mod(i+30,55))\n if(ma(i).lt.MZ)ma(i)=ma(i)+MBIG\n12 continue\n13 continue\n inext=0\n inextp=31\n idum=1\n endif\n inext=inext+1\n if(inext.eq.56)inext=1\n inextp=inextp+1\n if(inextp.eq.56)inextp=1\n mj=ma(inext)-ma(inextp)\n if(mj.lt.MZ)mj=mj+MBIG\n ma(inext)=mj\n ran3=mj*FAC\n return\n END FUNCTION ran3\n\n ! Solve ODE\n \n SUBROUTINE odeint(ystart,nvar,x1,x2,eps,h1,hmin,nok,nbad,derivs,&\n & rkqs,xx,yy,n)\n use structure\n implicit none\n \n INTEGER nbad,nok,nvar,MAXSTP,KMAXX,NMAX\n PARAMETER (MAXSTP=1000,NMAX=2,KMAXX=2000)\n \n REAL*8 eps,h1,hmin,x1,x2,ystart(nvar),TINY\n parameter(TINY=1.d-30)\n EXTERNAL derivs,rkqs\n \n INTEGER i,kmax,kount,nstp\n REAL*8 dxsav,h,hdid,hnext,x,xsav,dydx(NMAX),xp(KMAXX),y(NMAX),&\n & yp(NMAX,KMAXX),yscal(NMAX)\n COMMON /path/ kmax,kount,dxsav,xp,yp\n \n integer n\n real*8 xx(*),yy(*)\n \n real*8 phiz,fintrp\n external phiz,fintrp\n real*8 sum\n \n kmax=KMAXX\n \n x=x1\n h=sign(h1,x2-x1)\n nok=0\n nbad=0\n kount=0\n \n do i=1,nvar\n y(i)=ystart(i)\n end do\n \n if (kmax.gt.0) xsav=x-2.*dxsav\n \n do 16 nstp=1,MAXSTP\n call derivs(x,y,dydx)\n \n do i=1,nvar\n yscal(i)=abs(y(i))+abs(h*dydx(i))+TINY\n end do\n \n if(kmax.gt.0)then\n \n if(abs(x-xsav).gt.abs(dxsav)) then\n \n if(kount.lt.kmax-1)then\n kount=kount+1\n xp(kount)=x\n do i=1,nvar\n yp(i,kount)=y(i)\n end do\n xsav=x\n endif ! if(kount.lt.kmax-1) then\n \n endif ! if(abs(x-xsav).gt.abs(dxsav)) then\n endif ! if(kmax.gt.0) then\n \n if((x+h-x2)*(x+h-x1).gt.0.) h=x2-x\n \n call rkqs(y,dydx,nvar,x,h,eps,yscal,hdid,hnext,derivs)\n \n if(hdid.eq.h)then\n nok=nok+1\n else\n nbad=nbad+1\n endif\n \n if((x-x2)*(x2-x1).ge.0.)then\n do 14 i=1,nvar\n ystart(i)=y(i)\n14 continue\n if(kmax.ne.0)then\n kount=kount+1\n xp(kount)=x\n do 15 i=1,nvar\n yp(i,kount)=y(i)\n15 continue\n endif\n\n n=kount\n do i=1,n\n xx(i)=xp(i)\n yy(i)=yp(1,i)\n end do\n \n return\n endif\n if(abs(hnext).lt.hmin) pause 'stepsize smaller than minimum in odeint'\n h=hnext\n16 continue\n pause 'too many steps in odeint'\n return\n END SUBROUTINE odeint\n \n SUBROUTINE rkqs(y,dydx,n,x,htry,eps,yscal,hdid,hnext,derivs)\n! implicit none\n INTEGER n,NMAX\n REAL*8 eps,hdid,hnext,htry,x,dydx(n),y(n),yscal(n)\n PARAMETER (NMAX=50)\n INTEGER i\n external derivs\n REAL*8 errmax,h,xnew,yerr(NMAX),ytemp(NMAX),SAFETY,PGROW,PSHRNK,&\n & ERRCON\n PARAMETER (SAFETY=0.9,PGROW=-.2,PSHRNK=-.25,ERRCON=1.89e-4)\n h=htry\n1 call rkck(y,dydx,n,x,h,ytemp,yerr,derivs)\n errmax=0.\n do 11 i=1,n\n errmax=max(errmax,abs(yerr(i)/yscal(i)))\n11 continue\n\n errmax=errmax/eps\n if(errmax.gt.1.)then\n h=SAFETY*h*(errmax**PSHRNK)\n if(h.lt.0.1*h)then\n h=.1*h\n endif\n xnew=x+h\n if(xnew.eq.x)pause 'stepsize underflow in rkqs'\n goto 1\n else\n if(errmax.gt.ERRCON)then\n hnext=SAFETY*h*(errmax**PGROW)\n else\n hnext=5.*h\n endif\n hdid=h\n x=x+h\n do 12 i=1,n\n y(i)=ytemp(i)\n12 continue\n return\n endif\n END SUBROUTINE rkqs\n\n SUBROUTINE rkck(y,dydx,n,x,h,yout,yerr,derivs)\n! implicit none\n INTEGER n,NMAX\n REAL*8 h,x,dydx(n),y(n),yerr(n),yout(n)\n PARAMETER (NMAX=50)\n external derivs\n INTEGER i\n REAL*8 ak2(NMAX),ak3(NMAX),ak4(NMAX),ak5(NMAX),ak6(NMAX),&\n & ytemp(NMAX),A2,A3,A4,A5,A6,B21,B31,B32,B41,B42,B43,B51,B52,B53,&\n & B54,B61,B62,B63,B64,B65,C1,C3,C4,C6,DC1,DC3,DC4,DC5,DC6\n PARAMETER (A2=.2,A3=.3,A4=.6,A5=1.,A6=.875,B21=.2,B31=3./40.,&\n & B32=9./40.,B41=.3,B42=-.9,B43=1.2,B51=-11./54.,B52=2.5,&\n & B53=-70./27.,B54=35./27.,B61=1631./55296.,B62=175./512.,&\n & B63=575./13824.,B64=44275./110592.,B65=253./4096.,C1=37./378.,&\n & C3=250./621.,C4=125./594.,C6=512./1771.,DC1=C1-2825./27648.,&\n & DC3=C3-18575./48384.,DC4=C4-13525./55296.,DC5=-277./14336.,&\n & DC6=C6-.25)\n do 11 i=1,n\n ytemp(i)=y(i)+B21*h*dydx(i)\n11 continue\n call derivs(x+A2*h,ytemp,ak2)\n do 12 i=1,n\n ytemp(i)=y(i)+h*(B31*dydx(i)+B32*ak2(i))\n12 continue\n call derivs(x+A3*h,ytemp,ak3)\n do 13 i=1,n\n ytemp(i)=y(i)+h*(B41*dydx(i)+B42*ak2(i)+B43*ak3(i))\n13 continue\n call derivs(x+A4*h,ytemp,ak4)\n do 14 i=1,n\n ytemp(i)=y(i)+h*(B51*dydx(i)+B52*ak2(i)+B53*ak3(i)+B54*ak4(i))\n14 continue\n call derivs(x+A5*h,ytemp,ak5)\n do 15 i=1,n\n ytemp(i)=y(i)+h*(B61*dydx(i)+B62*ak2(i)+B63*ak3(i)+B64*ak4(i)+&\n & B65*ak5(i))\n15 continue\n call derivs(x+A6*h,ytemp,ak6)\n do 16 i=1,n\n yout(i)=y(i)+h*(C1*dydx(i)+C3*ak3(i)+C4*ak4(i)+C6*ak6(i))\n16 continue\n do 17 i=1,n\n yerr(i)=h*(DC1*dydx(i)+DC3*ak3(i)+DC4*ak4(i)+DC5*ak5(i)+DC6*ak6(i))\n17 continue\n return\n END SUBROUTINE rkck\n \n ! Sorting routine\n \n SUBROUTINE indexx(n,arr,indx)\n implicit none\n INTEGER n,indx(n),M,NSTACK\n REAL arr(n)\n PARAMETER (M=7,NSTACK=50)\n INTEGER i,indxt,ir,itemp,j,jstack,k,l,istack(NSTACK)\n REAL a\n do 11 j=1,n\n indx(j)=j\n11 continue\n jstack=0\n l=1\n ir=n\n1 if(ir-l.lt.M)then\n do 13 j=l+1,ir\n indxt=indx(j)\n a=arr(indxt)\n do 12 i=j-1,1,-1\n if(arr(indx(i)).le.a)goto 2\n indx(i+1)=indx(i)\n12 continue\n i=0\n2 indx(i+1)=indxt\n13 continue\n if(jstack.eq.0)return\n ir=istack(jstack)\n l=istack(jstack-1)\n jstack=jstack-2\n else\n k=(l+ir)/2\n itemp=indx(k)\n indx(k)=indx(l+1)\n indx(l+1)=itemp\n if(arr(indx(l+1)).gt.arr(indx(ir)))then\n itemp=indx(l+1)\n indx(l+1)=indx(ir)\n indx(ir)=itemp\n endif\n if(arr(indx(l)).gt.arr(indx(ir)))then\n itemp=indx(l)\n indx(l)=indx(ir)\n indx(ir)=itemp\n endif\n if(arr(indx(l+1)).gt.arr(indx(l)))then\n itemp=indx(l+1)\n indx(l+1)=indx(l)\n indx(l)=itemp\n endif\n i=l+1\n j=ir\n indxt=indx(l)\n a=arr(indxt)\n3 continue\n i=i+1\n if(arr(indx(i)).lt.a)goto 3\n4 continue\n j=j-1\n if(arr(indx(j)).gt.a)goto 4\n if(j.lt.i)goto 5\n itemp=indx(i)\n indx(i)=indx(j)\n indx(j)=itemp\n goto 3\n5 indx(l)=indx(j)\n indx(j)=indxt\n jstack=jstack+2\n if(jstack.gt.NSTACK)pause 'NSTACK too small in indexx'\n if(ir-i+1.ge.j-l)then\n istack(jstack)=ir\n istack(jstack-1)=i\n ir=j-1\n else\n istack(jstack)=j-1\n istack(jstack-1)=l\n l=i\n endif\n endif\n goto 1\n END SUBROUTINE indexx\n \nend module nrutils_modules\n", "meta": {"hexsha": "62111bd282ff5fe04890a2b24a38ffc74c222d5e", "size": 17736, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "nrutils_modules.f90", "max_stars_repo_name": "doctorcbpower/projected_profiles", "max_stars_repo_head_hexsha": "7ea682bfca748d385253d55d059c7e8abec466f1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "nrutils_modules.f90", "max_issues_repo_name": "doctorcbpower/projected_profiles", "max_issues_repo_head_hexsha": "7ea682bfca748d385253d55d059c7e8abec466f1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "nrutils_modules.f90", "max_forks_repo_name": "doctorcbpower/projected_profiles", "max_forks_repo_head_hexsha": "7ea682bfca748d385253d55d059c7e8abec466f1", "max_forks_repo_licenses": ["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.3145400593, "max_line_length": 78, "alphanum_fraction": 0.5184370771, "num_tokens": 7256, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934406, "lm_q2_score": 0.754914975839675, "lm_q1q2_score": 0.657226910777391}} {"text": "program time_independent\n! Compile as ```gfortran time_independent.f90 -o time_independent finite_difference.o -llapack```\n! After compiling ```gfortran -c finite_difference.f90 -llapack```\nuse finite_diff\nimplicit none\n\ninterface\n function potential_V(N_grid,x_pos,election)\n implicit none\n integer :: N_grid\n real*8 :: x_pos(1:N_grid)\n character*2 :: election\n real*8 :: potential_V(1:N_grid)\n end function\nend interface\n\ninteger :: NN, ii, n_eigen, INFO, N_grid\nreal*8, parameter :: x_0 = -10, x_n = 10\nreal*8 :: dx\nreal*8, allocatable :: energies(:), psi_states(:,:), V_pot(:), x_pos(:)\ncharacter*42 :: energy_file, states_file\ncharacter*2 :: election\n\nwrite(*,*) \"Currently enabled potential choices:\"\nwrite(*,'(A,/,A,/,A,/,A)') \" - 'ho': harmonic oscillator\",\" - 'qs': V=5 step at x = 0\",&\n\" - 'qb': V = 5 barrier when x in (-5,5)\", \" - 'qw': V = -5 well when x in (-5,5)\"\nwrite(*,*) \"Any option not listed leads to the (-10,10) quantum box.\"\nwrite(*,*) \"Enter the potential type, grid size and the number of desired energy levels\"\nread(*,*) election, NN, n_eigen\n\nif (NN.le.n_eigen) stop \"The grid size must be higher than the number of energy levels\"\n\n! The grid size determines the increment value\ndx = (x_n-x_0)/NN\n\nif (dx.ge.1) stop \"Grid size too small. Minumum should be 20 (advised 400 and above).\"\n\n! Since we assume x_0=x_n=0, we reduce the problem to a (NN-1)x(NN-1) matrix\nN_grid = NN - 1\n\n! Compute the potential energy array\nallocate(V_pot(1:N_grid))\nallocate(x_pos(1:N_grid))\nx_pos = (/(ii*dx + x_0, ii = 1,N_grid)/)\nV_pot = potential_V(N_grid,x_pos,election)\n\n! Calling single particle routine for diagonal potentials and vanishing boundaries\ncall finite_diff_1D(x_0,x_n,NN,n_eigen,energies,psi_states,V_pot,INFO)\n\n! Validate there are no routine errors\nif (INFO.ne.0) then\n write(*,'(A,I4)') \"Unsuccessful calculation. Status = \",INFO\nstop \"Not storing results. Exiting program...\"\nend if\n\nwrite(energy_file,'(A,A,A,I0,A)') \"energies_\",election,\"_\",NN,\".dat\"\nwrite(states_file,'(A,A,A,I0,A)') \"psi_states_\",election,\"_\",NN,\".dat\"\nopen(15, file = energy_file)\nopen(16, file = states_file)\ndo ii = 1, n_eigen\n write(15,*) energies(ii)\n write(16,*) psi_states(:,ii)! Storing as row vectors\nend do\nclose(16)\nclose(15)\n\nend program time_independent\n\n\n\n! Catallogue of potentials\nfunction potential_V(N_grid,x_pos,election)\nimplicit none\ninteger :: N_grid, ii\nreal*8 :: x_pos(1:N_grid)\ncharacter*2 :: election\nreal*8 :: potential_V(1:N_grid)\n select case (election)\n case ('ho')\n ! Harmonic oscillator potential\n potential_V = x_pos**2/2\n case ('qs')\n ! Step potential\n do ii = 1, N_grid\n if (x_pos(ii).lt.0) then\n potential_V(ii) = 0\n else\n potential_V(ii) = 1\n end if\n end do\n case ('qb','qw')\n ! Barrier potential\n do ii = 1, N_grid\n if ((x_pos(ii).lt.-5).or.(x_pos(ii).gt.5)) then\n potential_V(ii) = 0\n else\n potential_V(ii) = 1\n end if\n end do\n ! Potential well\n if (election.eq.'we') then\n potential_V = -potential_V\n end if\n case default\n potential_V = (/(0,ii = 1,N_grid)/)\n election = 'bx'\n end select\nend function\n", "meta": {"hexsha": "c0788ae8324eabd6c13863794dc36d1c1a083f78", "size": 3345, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "week_4/time_independent.f90", "max_stars_repo_name": "eigen-carmona/quantum-computation-unipd", "max_stars_repo_head_hexsha": "f53b40bd83cb85119ce4b494e10e01b256917659", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2022-01-11T19:41:07.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-05T19:22:24.000Z", "max_issues_repo_path": "week_4/time_independent.f90", "max_issues_repo_name": "eigen-carmona/quantum-computation-unipd", "max_issues_repo_head_hexsha": "f53b40bd83cb85119ce4b494e10e01b256917659", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "week_4/time_independent.f90", "max_forks_repo_name": "eigen-carmona/quantum-computation-unipd", "max_forks_repo_head_hexsha": "f53b40bd83cb85119ce4b494e10e01b256917659", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.6880733945, "max_line_length": 97, "alphanum_fraction": 0.6364723468, "num_tokens": 995, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972549785201, "lm_q2_score": 0.7549149758396752, "lm_q1q2_score": 0.6572269057081971}} {"text": "!======================== primitive_to_conserved_1D ==========================80\n!>\n!! Converts from the primitive state to the conserved state.\n!<\n!=============================================================================80\npure function primitive_to_conserved_1D(qp)\n\n use set_precision, only : dp\n use set_constants, only : half\n use fluid_constants, only : xgm1\n\n implicit none\n\n real(dp), dimension(3), intent(in) :: qp\n real(dp), dimension(3) :: primitive_to_conserved_1D\n\n primitive_to_conserved_1D(1) = qp(1)\n primitive_to_conserved_1D(2) = qp(1)*qp(2)\n primitive_to_conserved_1D(3) = qp(3)*xgm1 + half*qp(1)*qp(2)*qp(2)\n\nend function primitive_to_conserved_1D\n", "meta": {"hexsha": "27f889eb584207ba42776e122ede489c73f1ce33", "size": 698, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran_pFUnit/src/functions/primitive_to_conserved_1D.f90", "max_stars_repo_name": "cwj5/UnitTesting", "max_stars_repo_head_hexsha": "9298a863509cb7d913abc3fe2d0e91062fcefca6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-02T17:30:39.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-02T17:30:39.000Z", "max_issues_repo_path": "fortran_pFUnit/src/functions/primitive_to_conserved_1D.f90", "max_issues_repo_name": "cwj5/UnitTesting", "max_issues_repo_head_hexsha": "9298a863509cb7d913abc3fe2d0e91062fcefca6", "max_issues_repo_licenses": ["MIT"], "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_pFUnit/src/functions/primitive_to_conserved_1D.f90", "max_forks_repo_name": "cwj5/UnitTesting", "max_forks_repo_head_hexsha": "9298a863509cb7d913abc3fe2d0e91062fcefca6", "max_forks_repo_licenses": ["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.7272727273, "max_line_length": 80, "alphanum_fraction": 0.5873925501, "num_tokens": 194, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.746138993030751, "lm_q1q2_score": 0.6571970494962615}} {"text": "!=====================================================================!\n! Run gradient-based descent algorithms to solve linear algebra\n!=====================================================================!\n\nprogram test\n\n implicit none\n\n call check_conjugate\n\nend program test\n\n!---------------------------------------------------------------------!\n! \n!---------------------------------------------------------------------!\n\nsubroutine check_conjugate\n\n use linear_algebra\n\n implicit none\n\n dirichlet : block\n\n integer, parameter :: npts = 64\n real(8), parameter :: max_tol = 1.0d-8\n integer, parameter :: max_it = 100000\n real(8) :: x(npts,3), b(npts), A(npts,npts), P(npts, npts)\n integer :: iter, flag, i, j\n real(8) :: tol\n\n ! Solve using LU factorization\n call assemble_system_dirichlet(0.0d0, 1.0d0, npts, A, b, x(:,1), P)\n x(:,1) = solve(A,b)\n\n ! solve using CG\n call assemble_system_dirichlet(0.0d0, 1.0d0, npts, A, b, x(:,2), P) \n call dcg(A, b, max_it, max_tol, x(:,2), iter, tol, flag)\n print *, 'cg', tol, iter\n\n ! Solve using preconditioned CG\n call assemble_system_dirichlet(0.0d0, 1.0d0, npts, A, b, x(:,3), P) \n call dpcg(A, P, b, max_it, max_tol, x(:,3), iter, tol, flag)\n print *, 'pcg', tol, iter \n\n open(11, file='dirichlet.dat')\n do i = 1, npts\n ! x, exact, xcg, xpcg\n write(11, *) dble(i)/dble(npts+1), x(i,1), x(i,2), x(i,3)\n end do\n close(11)\n\n end block dirichlet\n\n mixed : block\n\n integer, parameter :: npts = 256\n real(8), parameter :: max_tol = 1.0d-8\n integer, parameter :: max_it = 100000\n real(8) :: x(npts+1,3), b(npts+1), A(npts+1,npts+1), P(npts+1, npts+1)\n integer :: iter, flag, i, j\n real(8) :: tol\n\n ! Solve using LU factorization\n call assemble_system_mixed(0.0d0, 1.0d0, npts, A, b, x(:,1), P)\n x(:,1) = solve(A,b)\n\n ! Solve using CG\n call assemble_system_mixed(0.0d0, 1.0d0, npts, A, b, x(:,2), P) \n call dcg(A, b, max_it, max_tol, x(:,2), iter, tol, flag)\n print *, 'cg', tol, iter\n\n ! Solve using preconditioned CG\n call assemble_system_mixed(0.0d0, 1.0d0, npts, A, b, x(:,3), P) \n call dpcg(A, P, b, max_it, max_tol, x(:,3), iter, tol, flag)\n print *, 'pcg', tol, iter\n\n open(11, file='mixed.dat')\n do i = 1, npts + 1\n write(11, *) dble(i)/dble(npts+1), x(i,1), x(i,2), x(i,3)\n end do\n close(11)\n\n end block mixed\n\nend subroutine check_conjugate\n\n!---------------------------------------------------------------------!\n! Assemble -U_xx = 2x - 0.5, U(0) = 1; U(1)= 0, x in [0,1]\n!---------------------------------------------------------------------!\n\nsubroutine assemble_system_dirichlet(a, b, npts, V, rhs, u, P)\n\n use linear_algebra, only : inv\n\n implicit none\n \n real(8), intent(in) :: a, b ! bounds of the domain\n integer, intent(in) :: npts ! number of interior points\n real(8), intent(out) :: V(npts,npts) ! banded matrix\n real(8), intent(out) :: rhs(npts)\n real(8), intent(out) :: u(npts)\n real(8), intent(out) :: P(npts,npts)\n real(8) :: S(npts,npts), D(npts, npts)\n \n real(8), parameter :: PI = 3.141592653589793d0\n real(8) :: h, alpha\n integer :: M, N\n integer :: i, j, k\n \n ! h = width / num_interior_pts + 1\n h = (b-a)/dble(npts+1)\n V = 0.0d0\n\n ! Size of the linear system = unknowns (interior nodes)\n M = npts ! nrows\n N = npts ! ncols\n \n ! Set the inner block\n rows: do i = 1, M\n cols: do j = 1, N\n if (j .eq. i-1) then\n ! lower triangle\n V(j,i) = -1.0d0\n else if (j .eq. i+1) then \n ! upper triangle\n V(j,i) = -1.0d0\n else if (j .eq. i) then \n ! diagonal\n V(j,i) = 2.0d0\n else\n ! skip\n end if\n end do cols\n end do rows\n \n ! Assemble the RHS\n do i = 1, M\n rhs(i) = h*h*(2.0d0*dble(i)*h - 0.5d0)\n end do\n rhs(1) = rhs(1) + 1.0d0\n rhs(M) = rhs(M)\n\n ! Initial solution profile use sin function as a first guess\n do i = 1, M\n u(i) = sin(dble(i)*h*PI)\n end do\n\n ! Find the sine transform matrix\n alpha = sqrt(2.0d0/dble(npts+1))\n do j = 1, M\n do k = 1, N\n S(k,j) = alpha*sin(PI*dble(j*k)/dble(npts+1))\n end do\n end do\n\n ! Find the diagonal matrix\n D = matmul(S, matmul(V, S))\n\n ! Invert the digonal matrix easily\n do j = 1, M\n D(j,j) = 1.0d0/D(j,j)\n end do\n \n ! Define the preconditioner\n p = matmul(S, matmul(D, S))\n\nend subroutine assemble_system_dirichlet\n\n!---------------------------------------------------------------------!\n! Assemble -U_xx = 2x - 0.5, U(0) = U_x(1)= 0, x in [0,1]\n!---------------------------------------------------------------------!\n\nsubroutine assemble_system_mixed(a, b, npts, V, rhs, u, P)\n\n use linear_algebra, only : inv\n\n implicit none\n \n real(8), intent(in) :: a, b ! bounds of the domain\n integer, intent(in) :: npts ! number of interior points\n real(8), intent(out) :: V(npts+1,npts+1) ! banded matrix\n real(8), intent(out) :: rhs(npts+1)\n real(8), intent(out) :: u(npts+1)\n real(8), intent(out) :: P(npts+1,npts+1)\n real(8) :: S(npts+1, npts+1), D(npts+1, npts+1)\n real(8), parameter :: PI = 3.141592653589793d0\n real(8) :: h, alpha\n integer :: M, N\n integer :: i, j, k\n \n ! h = width / num_interior_pts + 1\n h = (b-a)/dble(npts+1)\n V = 0.0d0\n\n ! Size of the linear system = unknowns\n M = npts + 1 ! nrows\n N = npts + 1 ! ncols\n \n ! Set the inner block\n rows: do i = 1, M\n cols: do j = 1, npts\n if (j .eq. i-1) then\n ! lower triangle\n V(j,i) = -1.0d0\n else if (j .eq. i+1) then \n ! upper triangle\n V(j,i) = -1.0d0\n else if (j .eq. i) then \n ! diagonal\n V(j,i) = 2.0d0\n else\n ! skip\n end if\n end do cols\n end do rows\n V(M,M) = 1.0d0\n V(M,N-1) = -1.0d0\n\n ! Assemble the RHS\n do i = 1, M\n rhs(i) = h*h*(2.0d0*dble(i)*h - 0.5d0)\n end do\n rhs(1) = rhs(1) + 1.0d0\n rhs(M) = rhs(M)/2.0d0\n\n ! Initial solution profile use sin function as a first guess\n do i = 1, M\n u(i) = sin(dble(i)*h*PI)\n end do\n ! Find the sine transform matrix\n alpha = sqrt(2.0d0/dble(npts+1))\n do j = 1, M\n do k = 1, N\n S(k,j) = alpha*sin(PI*dble(j*k)/dble(npts+1))\n end do\n end do\n\n ! Find the diagonal matrix\n D = matmul(S, matmul(V, S))\n\n ! Invert the digonal matrix easily\n do j = 1, M\n D(j,j) = 1.0d0/D(j,j)\n end do\n \n ! Define the preconditioner\n p = matmul(S, matmul(D, S))\n\nend subroutine assemble_system_mixed\n", "meta": {"hexsha": "4c7593e1b080dc5317e9614ff6f4b0660f207d7e", "size": 6620, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/conjugate-gradient/test.f90", "max_stars_repo_name": "komahanb/math6644-iterative-methods", "max_stars_repo_head_hexsha": "59dfd0fd8bbcb16d5f5b6d96d2565f87541803c9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-03-19T16:36:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-14T21:29:38.000Z", "max_issues_repo_path": "test/conjugate-gradient/test.f90", "max_issues_repo_name": "komahanb/math6644-iterative-methods", "max_issues_repo_head_hexsha": "59dfd0fd8bbcb16d5f5b6d96d2565f87541803c9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/conjugate-gradient/test.f90", "max_forks_repo_name": "komahanb/math6644-iterative-methods", "max_forks_repo_head_hexsha": "59dfd0fd8bbcb16d5f5b6d96d2565f87541803c9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-23T02:14:36.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-23T02:14:36.000Z", "avg_line_length": 26.374501992, "max_line_length": 74, "alphanum_fraction": 0.5054380665, "num_tokens": 2355, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6571970451295498}} {"text": "program tsunami\n\n ! Tsunami simulator.\n !\n ! Solves the non-linear 2-d shallow water equation system:\n !\n ! du/dt + u du/dx + v du/dy + g dh/dx = 0\n ! dv/dt + u dv/dx + v dv/dy + g dh/dy = 0\n ! dh/dt + d(hu)/dx + d(hv)/dy = 0\n !\n ! This version is parallelized and uses derived types.\n\n use iso_fortran_env, only: int32, real32, event_type, team_type\n use mod_field, only: Field, diffx, diffy\n\n implicit none\n\n integer(int32) :: n\n integer(int32) :: time_step_count[*]\n\n integer(int32), parameter :: im = 201 ! grid size in x\n integer(int32), parameter :: jm = 201 ! grid size in y\n integer(int32), parameter :: num_time_steps = 1000 ! number of time steps\n\n real(real32), parameter :: dt = 0.02 ! time step [s]\n real(real32), parameter :: dx = 1 ! grid spacing in x [m]\n real(real32), parameter :: dy = 1 ! grid spacing in y [m]\n real(real32), parameter :: g = 9.8 ! gravitational acceleration [m/s^2]\n\n integer(int32), parameter :: ic = im / 2 + 1, jc = jm / 2 + 1\n real(real32), parameter :: decay = 0.02\n\n type(Field) :: h, hm, u, v\n\n type(team_type) :: new_team\n integer(int32) :: team_num\n\n type(event_type) :: time_step_event[*]\n\n real(real32) :: hmin, hmax, hmean\n\n team_num = 1\n if (this_image() == 1) team_num = 2\n form team(team_num, new_team)\n\n change team(new_team)\n\n if (team_num == 1) then\n\n u = Field('u', [im, jm])\n v = Field('v', [im, jm])\n h = Field('h', [im, jm])\n hm = Field('h_mean', [im, jm])\n\n ! initialize a gaussian blob in the center\n call h % init_gaussian(decay, ic, jc)\n\n hm = 10.\n\n call h % write(0)\n\n time_loop: do n = 1, num_time_steps\n\n ! compute u at next time step\n u = u - (u * diffx(u) / dx + v * diffy(u) / dy &\n + g * diffx(h) / dx) * dt\n\n ! compute v at next time step\n v = v - (u * diffx(v) / dx + v * diffy(v) / dy &\n + g * diffy(h) / dy) * dt\n\n ! compute h at next time step\n h = h - (diffx(u * (hm + h)) / dx &\n + diffy(v * (hm + h)) / dy) * dt\n\n hmin = minval(h % data)\n call co_min(hmin, 1)\n\n hmax = maxval(h % data)\n call co_max(hmax, 1)\n\n hmean = sum(h % data(h % lb(1):h % ub(1),h % lb(2):h % ub(2))) &\n / size(h % data(h % lb(1):h % ub(1),h % lb(2):h % ub(2)))\n call co_sum(hmean, 1)\n hmean = hmean / num_images()\n\n if (this_image() == 1) then\n event post(time_step_event[1, team_number=2]) ! not implemented as of gcc-9.2.0 and OpenCoarrays-2.8.0\n print '(a, i5, 3(f10.6))', 'step, min(h), max(h), mean(h):', &\n n, hmin, hmax, hmean\n end if\n\n call h % write(n)\n\n end do time_loop\n\n else if (team_num == 2) then\n\n n = 0\n do\n call event_query(time_step_event, time_step_count)\n if (time_step_count > n) then\n n = time_step_count\n print *, 'tsunami logger: step ', n, 'of', num_time_steps, 'done'\n end if\n if (n == num_time_steps) exit\n end do\n\n end if\n\n end team\n\nend program tsunami\n", "meta": {"hexsha": "ff11c7b6a4ecd1d2b3ee3078b375337bc2d24228", "size": 3018, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/ch12/tsunami.f90", "max_stars_repo_name": "AAGAN/tsunami", "max_stars_repo_head_hexsha": "82635516dcb7f85eb6434ffdb98a9ddc4c1403ad", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 103, "max_stars_repo_stars_event_min_datetime": "2018-03-29T23:39:31.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T12:24:25.000Z", "max_issues_repo_path": "src/ch12/tsunami.f90", "max_issues_repo_name": "AAGAN/tsunami", "max_issues_repo_head_hexsha": "82635516dcb7f85eb6434ffdb98a9ddc4c1403ad", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2018-04-06T14:33:04.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T19:50:12.000Z", "max_forks_repo_path": "src/ch12/tsunami.f90", "max_forks_repo_name": "AAGAN/tsunami", "max_forks_repo_head_hexsha": "82635516dcb7f85eb6434ffdb98a9ddc4c1403ad", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 32, "max_forks_repo_forks_event_min_datetime": "2018-04-01T19:54:12.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-27T14:06:03.000Z", "avg_line_length": 26.4736842105, "max_line_length": 110, "alphanum_fraction": 0.5593108019, "num_tokens": 1028, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778825, "lm_q2_score": 0.7461389817407016, "lm_q1q2_score": 0.6571970348826026}} {"text": "real, dimension(1000) :: a = (/ (1.0/(i*i), i=1, 1000) /)\nreal :: result\n\nresult = sum(a);\n", "meta": {"hexsha": "5ce510dcad2d382a6097285a9e741420ba7de776", "size": 91, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Sum-of-a-series/Fortran/sum-of-a-series-1.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Sum-of-a-series/Fortran/sum-of-a-series-1.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Sum-of-a-series/Fortran/sum-of-a-series-1.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 18.2, "max_line_length": 57, "alphanum_fraction": 0.5274725275, "num_tokens": 38, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.944176852582231, "lm_q2_score": 0.6959583313396339, "lm_q1q2_score": 0.6571077468126371}} {"text": " SUBROUTINE ATXPXA(A,U,C,N,NA,NU,NC,EPS,FAIL)\nC \nC PURPOSE:\nC Solve the real matrix equation A'X + XA = C, where A and C are\nC constant matrices of dimension n x n with C=C'. The matrix A\nC is transformed into upper Schur form and the transformed system\nC is solved by back substitution. The option is provided to input\nC the Schur form directly and bypass the Schur decomposition.\nC REFERENCES:\nC Bartels, R.H.; and Stewart, G.W.: Algorithm 432 - Solution of\nC the Matrix Equation AX + XB = C. Commun. ACM, vol. 15, no. 9,\nC Sept. 1972, pp. 820-826.\nC \nC Subroutines employed by ATXPXA: BCKMLT, HSHLDR, SCHUR, SYMSLV\nC Subroutines employing ATXPXA: BARSTW\nC \n IMPLICIT REAL*8 (A-H,O-Z)\n REAL*8\n 1A(NA,1),U(NU,1),C(NC,1),EPS\n INTEGER\n 1N,NA,NU,NC,FAIL,N1,NM1,I,J,K\n N1 = N+1\n NM1 = N-1\nC \nC IF REQUIRED, REDUCE A TO LOWER REAL SCHUR FORM.\nC \n IF(EPS .LT. 0.) GO TO 15\n CALL HSHLDR(A,N,NA)\n CALL BCKMLT(A,U,N,NA,NU)\n DO 10 I=1,NM1\n A(I+1,I) = A(I,N1)\n 10 CONTINUE\n CALL SCHUR(A,U,N,NA,NU,EPS,FAIL)\n IF(FAIL .NE. 0) RETURN\nC \nC TRANSFORM C.\nC \n 15 DO 20 I=1,N\n C(I,I)=C(I,I)/2.\n 20 CONTINUE\n DO 40 I=1,N\n DO 30 J=1,N\n A(N1,J) = 0.\n DO 30 K=I,N\n A(N1,J) = A(N1,J) + C(I,K)*U(K,J)\n 30 CONTINUE\n DO 40 J=1,N\n C(I,J) = A(N1,J)\n 40 CONTINUE\n DO 60 J=1,N\n DO 50 I=1,N\n A(I,N1) = 0.\n DO 50 K=1,N\n A(I,N1) = A(I,N1) + U(K,I)*C(K,J)\n 50 CONTINUE\n DO 60 I=1,N\n C(I,J) = A(I,N1)\n 60 CONTINUE\n DO 70 I=1,N\n DO 70 J=I,N\n C(I,J) = C(I,J) + C(J,I)\n C(J,I) = C(I,J)\n 70 CONTINUE\nC \nC SOLVE THE TRANSFORMED SYSTEM.\nC \n CALL SYMSLV(A,C,N,NA,NC)\nC \nC TRANSFORM C BACK TO THE SOLUTION.\nC \n DO 80 I=1,N\n C(I,I) = C(I,I)/2.\n 80 CONTINUE\n DO 100 I=1,N\n DO 90 J=1,N\n A(N1,J) = 0.\n DO 90 K=I,N\n A(N1,J) = A(N1,J) + C(I,K)*U(J,K)\n 90 CONTINUE\n DO 100 J=1,N\n C(I,J) = A(N1,J)\n 100 CONTINUE\n DO 120 J=1,N\n DO 110 I=1,N\n A(I,N1) = 0.\n DO 110 K=1,N\n A(I,N1) = A(I,N1) + U(I,K)*C(K,J)\n 110 CONTINUE\n DO 120 I=1,N\n C(I,J) = A(I,N1)\n 120 CONTINUE\n DO 130 I=1,N\n DO 130 J=I,N\n C(I,J) = C(I,J) + C(J,I)\n C(J,I) = C(I,J)\n 130 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "71397a3654c4def20717cd48d982b14b64a2fd8b", "size": 2498, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "gsc-13067/iac/diriac2/oracls/atxpxa.for", "max_stars_repo_name": "SteveDoyle2/nasa-cosmic", "max_stars_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_stars_repo_licenses": ["BSD-Source-Code"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2015-03-14T07:26:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-16T12:23:17.000Z", "max_issues_repo_path": "gsc-13067/iac/diriac2/oracls/atxpxa.for", "max_issues_repo_name": "SteveDoyle2/nasa-cosmic", "max_issues_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_issues_repo_licenses": ["BSD-Source-Code"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gsc-13067/iac/diriac2/oracls/atxpxa.for", "max_forks_repo_name": "SteveDoyle2/nasa-cosmic", "max_forks_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_forks_repo_licenses": ["BSD-Source-Code"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2016-02-12T22:18:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-08T17:46:54.000Z", "avg_line_length": 25.2323232323, "max_line_length": 71, "alphanum_fraction": 0.4995996797, "num_tokens": 991, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768604361741, "lm_q2_score": 0.6959583187272711, "lm_q1q2_score": 0.657107740370353}} {"text": "Real Function fkaon(p, pmax)\n Save\n fmax = 0.148\n If (pmax==0.) pmax = 0.000001\n fkaon = (1.-p/pmax)*(p/pmax)**2\n If (fkaon>fmax) fkaon = fmax\n fkaon = fkaon/fmax\n Return\nEnd Function fkaon\n", "meta": {"hexsha": "66879d690fb9de08cee98fc35fccdaae2015f5f4", "size": 197, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fkaon.f90", "max_stars_repo_name": "xiaohaijin/AMPT", "max_stars_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-12-24T19:37:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-14T12:58:59.000Z", "max_issues_repo_path": "src/fkaon.f90", "max_issues_repo_name": "xiaohaijin/AMPT", "max_issues_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_issues_repo_licenses": ["MIT"], "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/fkaon.f90", "max_forks_repo_name": "xiaohaijin/AMPT", "max_forks_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_forks_repo_licenses": ["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.7, "max_line_length": 33, "alphanum_fraction": 0.6345177665, "num_tokens": 93, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480248488136, "lm_q2_score": 0.7154240079185319, "lm_q1q2_score": 0.6571028205673913}} {"text": "!>-----------------------------------------------------------------------------------------------\n!!\n!> @brief Solution of linear algebraic equations\n!!\n!> @author Christopher Kebschull\n!> @author Vitali Braun\n!> @author Eduard Gamper\n!> @author Volker Schaus\n!! @version 1.0\n!!\n!> @date

    \n!!
  • VB: 26.07.2013 (initial design)
  • \n!!
  • ChK: 10.07.2015 (assimilated into libslam)
  • \n!!
  • VB: 31.01.2016 (fixed issue, where routines would checkOut upon an error)
  • \n!!
  • VB: 08.02.2016 (introduced Cholesky decomposition for matrix inversion)
  • \n!!
  • VS: 16.08.2018 (Adding additional functions linear_comb1, linear_comb2)
  • \n!!
  • ChK: 13.10.2019 (Enforcing camel case and adding copyright)
  • \n!!
\n!!\n!! @details This module contains functions, parameters and routines for the solution of\n!! linear algebraic equations.\n!!\n!! @anchor linAlgebra\n!!\n!> @copyright Institute of Space Systems / TU Braunschweig\n!!\n!!------------------------------------------------------------------------------------------------\nmodule slam_linAlgebra\n\n use slam_types\n use slam_math, only: outerproduct, eps20, identity_matrix\n use slam_error_handling\n\n implicit none\n\n private\n\n integer, parameter :: INVERT_CHOLESKY = 1 ! matrix inversion via Cholesky decomposition (only for positive definite matrices)\n integer, parameter :: INVERT_LU_DECOMP = 2 ! matrix inversion via LU decomposition\n\n public :: cholesky_decomposition\n public :: invert_matrix\n public :: forward_substitution\n public :: back_substitution\n public :: inverse2\n public :: linear_comb1\n public :: linear_comb2\n public :: add_vec\n public :: sub_vec\n\ncontains\n\n! -------------------------------------------------------------------------------------\n!\n!> @brief Matrix inversion via different methods\n!!\n!> @author Vitali Braun\n!!\n!> @date
    \n!!
  • 15.01.2016 (Re-implementation with new methods)
  • \n!!
\n!!\n!> @param[in] A input matrix A\n!> @param[in] method inversion method (either CHOLESKY or LU_DECOMP)\n!> @param[out] A_inv inverted matrix\n!!\n!! @anchor invert_matrix\n!!\n!> @copyright Institute of Space Systems / TU Braunschweig\n! -------------------------------------------------------------------------------------\n subroutine invert_matrix(A, A_inv, method)\n\n real(dp), dimension(:,:), intent(in) :: A\n real(dp), dimension(size(A,1),size(A,1)), intent(out) :: A_inv\n character(len=*), intent(in) :: method\n\n character(len=*), parameter :: csubid = 'invert_matrix'\n real(dp), dimension(size(A,1),size(A,1)) :: A_loc ! local copy of matrix A\n real(dp), dimension(size(A,1),size(A,1)) :: A_chol ! Cholesky decomposition of matrix A\n real(dp), dimension(size(A,1),size(A,1)) :: A_chol_inv ! Inverse of (lower triangular) Cholesky decomposition of matrix A\n real(dp), dimension(size(A,1),size(A,1)) :: id_matrix ! identity matrix\n real(dp), dimension(size(A,1)) :: b_temp ! temporary vector\n integer, dimension(size(A,1)) :: idx ! row interchange index vector for LU decomposition\n integer :: n,i,k\n integer :: invMethod ! inversion method to be used\n real(dp) :: d\n\n real(dp), dimension(6,6) :: tempMat\n\n if(isControlled()) then\n if(hasToReturn()) return\n call checkIn(csubid)\n end if\n\n if(size(a,1) == size(a,2)) then\n n = size(a,1)\n else\n call setError(E_MATRIX_MATCHING, FATAL) ! Matrix is not invertible\n return\n end if\n\n ! check method to be used\n if(index(method, 'CHOLESKY') /= 0) then\n invMethod = INVERT_CHOLESKY\n else if(index(method, 'LU_DECOMP') /= 0) then\n invMethod = INVERT_LU_DECOMP\n else\n call setError(E_UNKNOWN_PARAMETER, FATAL, (/method/))\n return\n end if\n\n !** create local copy of matrix A\n A_loc = A\n !** set up identity matrix\n call identity_matrix(id_matrix)\n\n select case(invMethod)\n case(INVERT_CHOLESKY)\n ! compute Cholesky decomposition, which will result in a lower triangular matrix\n call cholesky_decomposition(A,A_chol)\n if(hasFailed()) return\n\n ! now perform forward substitution column-wise\n call identity_matrix(id_matrix)\n do i=1,n\n b_temp = id_matrix(:,i)\n call forward_substitution(A_chol, b_temp)\n A_chol_inv(:,i) = b_temp\n end do\n\n ! the inverse is now simply: A^{-1} = (A_chol_inv^T)*A_chol_inv\n A_inv = matmul(transpose(A_chol_inv), A_chol_inv)\n\n case(INVERT_LU_DECOMP)\n !** perform LU decomposition of matrix A\n call LU_decomposition(A_loc, idx, d)\n\n call identity_matrix(A_inv)\n !** now find inverse by columns using LU back_substitution\n do i=1,n\n call lu_back_substitution(A_loc, idx, A_inv(:,i))\n end do\n\n end select\n\n if(isControlled()) then\n call checkOut(csubid)\n end if\n\n return\n\n end subroutine invert_matrix\n\n ! -------------------------------------------------------------------------------------\n !\n !> @brief Back substitution\n !!\n !> @param[in] a input matrix A\n !! @param[inout] b output matrix B\n !!\n !! @anchor back_substitution\n !!\n ! -------------------------------------------------------------------------------------\n subroutine back_substitution(a,b)\n\n real(dp), dimension(:,:), intent(in) :: a\n real(dp), dimension(:), intent(inout) :: b\n\n integer :: i,j\n real(dp), dimension(size(b)) :: x\n\n do i=size(a,1),1,-1\n x(i) = b(i)\n do j=i+1,size(a,1)\n x(i) = x(i) - a(i,j)*x(j)\n end do\n x(i) = x(i)/a(i,i)\n end do\n\n b = x\n return\n\n end subroutine back_substitution\n\n ! -------------------------------------------------------------------------------------\n !\n !> @brief Forward substitution\n !!\n !> @param[in] a input matrix A\n !! @param[inout] b output matrix B\n !!\n !! @anchor forward_substitution\n !!\n ! -------------------------------------------------------------------------------------\n subroutine forward_substitution(a,b)\n\n real(dp), dimension(:,:), intent(in) :: a\n real(dp), dimension(:), intent(inout) :: b\n\n integer :: i,j\n real(dp), dimension(size(b)) :: x\n\n do i=1,size(a,1)\n x(i) = b(i)\n do j=1,i-1\n x(i) = x(i) - a(i,j)*x(j)\n end do\n x(i) = x(i)/a(i,i)\n end do\n\n b = x\n return\n\n end subroutine\n\n\n!>-----------------------------------------------------------------------------------------------\n!!\n!> @brief Back substitution based on LU decomposed matrix A\n!!\n!> @author Vitali Braun (based on Numerical Recipes in Fortran 90, Vol.2)\n!!\n!> @date
    \n!!
  • 26.07.2013 (initial design)
  • \n!!
\n!!\n!! @details Solves the set of N linear equations A \u00b7X = B. Here the N \u00d7 N matrix A is input,\n!! not as the original matrix A, but rather as its LU decomposition, determined by\n!! the routine \"LU_decomposition\". \"idx\" is input as the permutation vector of\n!! length N returned by \"LU_decomposition\". \"b\" is input as the right-hand-side\n!! vector B,also of length N, and returns with the solution vector X. \"a\" and \"idx\"\n!! are not modified by this routine and can be left in place for successive calls\n!! with different right-hand sides b. This routine takes into account the possibility\n!! that b will begin with many zero elements, so it is efficient for use in matrix inversion.\n!!\n!> @param[in] A input matrix A in LU decomposition form (NxN)\n!!\n!> @param[in] idx array containing the row interchanges\n!> @param[out] b right hand side of vector B, returns solution vector X.\n!!\n!!\n!! @see lu_decomposition\n!! @anchor lu_back_substitution\n!!------------------------------------------------------------------------------------------------\n subroutine lu_back_substitution(a,idx,b)\n\n real(dp), dimension(:,:), intent(in) :: a\n integer, dimension(:), intent(in) :: idx\n real(dp), dimension(:), intent(inout) :: b\n\n character(len=*), parameter :: csubid = 'lu_back_substitution'\n integer :: i,n,ii,ll\n real(dp) :: summ\n\n if(isControlled()) then\n if(hasToReturn()) return\n call checkIn(csubid)\n end if\n\n if(size(a,1) == size(a,2) .and. size(a,2) == size(idx)) then\n n = size(a,1)\n else\n call setError(E_MATRIX_MATCHING, FATAL) ! There is a row of zeros.\n if(isControlled()) then\n call checkOut(csubid)\n end if\n return\n end if\n\n ii=0\n\n do i=1,n\n ll = idx(i)\n summ = b(ll)\n b(ll) = b(i)\n\n if (ii /= 0) then\n summ = summ - dot_product(a(i,ii:i-1),b(ii:i-1))\n else if (summ /= 0.0) then\n ii=i\n end if\n\n b(i) = summ\n\n end do\n\n do i=n,1,-1\n b(i) = (b(i) - dot_product(a(i,i+1:n),b(i+1:n)))/a(i,i)\n end do\n\n if(isControlled()) then\n call checkOut(csubid)\n end if\n return\n\n end subroutine lu_back_substitution\n\n!>--------------------------------------------------------------------------------------\n!!\n!> @brief LU decomposition\n!!\n!> @author Vitali Braun (based on Numerical Recipes in Fortran 90, Vol.2)\n!!\n!> @date
    \n!!
  • 26.07.2013 (initial design)
  • \n!!
\n!!\n!! @details Given an N \u00d7 N input matrix A, this routine replaces it by the LU decomposition of\n!! a rowwise permutation of itself. \"idx\" is an output vector of length N that records\n!! the row permutation effected by the partial pivoting. \"d\" is output as +-1 depending\n!! on whether the number of row interchanges was even or odd, respectively. This\n!! routine is used in combination with \"back substitution\" to solve linear equations or\n!! invert a matrix.\n!!\n!> @param[in] A input matrix A (NxN)\n!!\n!> @param[out] idx array containing the row interchanges\n!> @param[out] d indicates whether the number of row interchanges was even (+1) or odd (-1)\n!!\n!! @anchor lu_decomposition\n!!--------------------------------------------------------------------------------------\n subroutine lu_decomposition(A,idx,d)\n\n\n real(dp), dimension(:,:), intent(inout) :: a\n integer, dimension(:), intent(out) :: idx\n real(dp), intent(out) :: d\n\n character(len=*), parameter :: csubid = 'LU_decomposition'\n integer, dimension(1) :: itemp\n real(dp), dimension(size(a,1)) :: swap\n integer :: j,n,imax\n real(dp), dimension(size(a,1)) :: vv ! stores the implicit scaling of each row.\n\n if(isControlled()) then\n if(hasToReturn()) return\n call checkIn(csubid)\n end if\n\n if(size(a,1) == size(a,2) .and. size(a,2) == size(idx)) then\n n = size(a,1)\n else\n call setError(E_MATRIX_MATCHING, FATAL) ! There is a row of zeros.\n if(isControlled()) then\n call checkOut(csubid)\n end if\n return\n end if\n\n d = 1.0 ! No row interchanges yet.\n vv = maxval(abs(a),dim=2) ! Loop over rows to get the implicit scaling\n\n if (any(vv == 0.d0)) then\n call setError(E_SINGULAR_MATRIX, FATAL) ! There is a row of zeros.\n if(isControlled()) then\n call checkOut(csubid)\n end if\n return\n end if\n\n vv=1.d0/vv ! Save the scaling.\n\n do j=1,n\n itemp = maxloc(vv(j:n)*abs(a(j:n,j)))\n imax = (j-1) + itemp(1)\n\n if (j /= imax) then ! Do we need to interchange rows?\n swap = a(imax,:)\n a(imax,:) = a(j,:)\n a(j,:) = swap\n d = -d ! ...and change the parity of d.\n vv(imax) = vv(j) ! also interchange the scale factor.\n end if\n\n idx(j)=imax\n\n if (a(j,j) == 0.d0) a(j,j)=eps20\n !If the pivot element is zero the matrix is singular (at least to the precision of the al-\n !gorithm). For some applications on singular matrices, it is desirable to substitute eps20\n !for zero.\n\n a(j+1:n,j) = a(j+1:n,j)/a(j,j) ! Divide by the pivot element.\n a(j+1:n,j+1:n) = a(j+1:n,j+1:n) - outerproduct(a(j+1:n,j),a(j,j+1:n)) ! Reduce remaining submatrix.\n\n end do\n\n if(isControlled()) then\n call checkOut(csubid)\n end if\n\n end subroutine lu_decomposition\n\n!>-------------------------------------------------------------------------------------\n!!\n!> @brief Cholesky decomposition\n!!\n!> @author Vitali Braun (based on Numerical Recipes in Fortran 90, Vol.2)\n!!\n!> @date
    \n!!
  • 13.03.2014 (initial design)
  • \n!!
\n!!\n!! @details Given an N \u00d7 N positive-definite symmetric matrix A, this routine constructs its\n!! cholesky decomposition A = LL*. On input, only the upper triangle of A need to\n!! be given. The Cholesky factor L is returned in lower triangular form.\n!!\n!> @param[in] A input matrix A (NxN)\n!> @param[out] L cholesky decomposition of A in lower triangular form (NxN)\n!!\n!! @anchor cholesky_decomposition\n!!-------------------------------------------------------------------------------------\n subroutine cholesky_decomposition(a,l)\n\n implicit none\n\n real(dp), dimension(:,:), intent(in) :: a\n real(dp), dimension(:,:), intent(out) :: l\n\n character(len=*), parameter :: csubid = 'cholesky_decomposition'\n\n integer :: i,j,n\n real(dp), dimension(size(a,1), size(a,2)) :: aloc\n real(dp) :: summ\n\n if(isControlled()) then\n if(hasToReturn()) return\n call checkIn(csubid)\n end if\n\n aloc = a\n l = 0.d0\n n = size(a,1)\n\n do i = 1,n\n\n summ = aloc(i,i)-dot_product(aloc(i,1:i-1),aloc(i,1:i-1))\n\n if (summ <= 0.0) then\n call setError(E_MATRIX_NOT_POSITIVE_DEFINITE, FATAL)\n return\n end if\n\n l(i,i) = sqrt(summ)\n aloc(i+1:n,i) = (aloc(i,i+1:n)-matmul(aloc(i+1:n,1:i-1),aloc(i,1:i-1)))/l(i,i)\n\n end do\n\n do i=1,size(l,1)\n l(i,i+1:size(l,1)) = 0.d0\n forall(j = 1:i-1) l(i,j) = aloc(i,j)\n end do\n\n if(isControlled()) then\n call checkOut(csubid)\n end if\n return\n\n end subroutine cholesky_decomposition\n\n !>-------------------------------------------------------------------------------------\n !!\n !> @brief Calculation of inverse\n !!\n !! @author Eduard Gamper (EG), based on\n !! Alex G (http://ww2.odu.edu/~agodunov/computing/programs/book2/Ch06/Inverse.f90, accessed 03.02.2015) \n !!\n !> @date
    \n !!
  • 01.12.2009 (initial design)
  • \n !!
  • 22.11.2017 EG: Input corrected. Now, original matrix won't be destroyed.
  • \n !!
  • 22.11.2017 EG: Changed in code values to double (d0).
  • \n !!
\n !!\n !> @details Subroutine calculates the inverse of a nxn matrix. Based on Doolittle LU\n !! factorization for Ax=b\n !!\n !> @param[in] original_matrix original matrix (NxN)\n !> @param[in] n dimension of original matrix\n !> @param[out] c inverse of original matrix (NxN)\n !!\n !> @anchor inverse2\n !>-------------------------------------------------------------------------------------\n subroutine inverse2(original_matrix,c,n)\n implicit none\n\n integer, intent(in) :: n\n real(dp), dimension(n,n), intent(in) :: original_matrix\n real(dp), dimension(n,n), intent(out) :: c\n\n real(dp), dimension(n,n) :: a\n real(dp), dimension(n,n) :: L\n real(dp), dimension(n,n) :: U\n real(dp), dimension(n) :: b\n real(dp), dimension(n) :: d\n real(dp), dimension(n) :: x\n real(dp) :: coeff\n integer :: i\n integer :: j\n integer :: k\n\n ! Copy original matrix to working matrix \"a\"\n a = original_matrix\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 c(i,k) = x(i)\n end do\n b(k)=0.d0\n end do\n\n end subroutine inverse2\n\n !---------------------------------------------------------------------------\n !!\n !> @anchor linear_comb1\n !!\n !> @brief linear combination of one vector with a scalar\n !!\n !> @author Volker Schaus (VS)\n !!\n !> @details this subroutine calculates the linear combination of a vector\r\n !! multiplied by a constants.\n !> @date
    \n !!
  • VS: 16.08.2018 initial implementation based on Vallado
  • \n !!
\n !!\n !---------------------------------------------------------------------------\r\n function linear_comb1(a, vec) result (out_vec)\r\n\r\n real(dp), intent(in) :: a\n real(dp), dimension(3), intent(in) :: vec\n real(dp), dimension(3) :: out_vec\r\n integer i\r\n\r\n do i= 1, 3\r\n out_vec(i)= a * vec(i)\r\n end do\n\r\n return\r\n end function linear_comb1\n\n !---------------------------------------------------------------------------\n !!\n !> @anchor linear_comb2\n !!\n !> @brief linear combination of two vectors\n !!\n !> @author Volker Schaus (VS)\n !!\n !> @details this subroutine calculates the linear combination of two vectors\r\n !! multiplied by two different constants\n !!\n !> @date
    \n !!
  • VS: 15.08.2018 initial implementation based on Vallado
  • \n !!
\n !!\n !---------------------------------------------------------------------------\r\n function linear_comb2 (a1, a2, vec1, vec2) result (out_vec)\r\n\r\n real(dp) :: a1\n real(dp) :: a2\n real(dp), dimension(3), intent(in) :: vec1\n real(dp), dimension(3), intent(in) :: vec2\n real(dp), dimension(3) :: out_vec\n\r\n integer i\r\n\r\n do i= 1, 3\r\n out_vec(i)= a1*vec1(i) + a2*vec2(i)\r\n end do\n\r\n return\r\n end function linear_comb2\n\n !---------------------------------------------------------------------------\n !!\n !> @anchor add_vec\n !!\n !> @brief adds two vectors\n !!\n !> @param[in] real(dp), dimension (3) vec1\n !> @param[in] real(dp), dimension (3) vec2\n !> @param[out] real(dp), dimension (3) out_vec\n !!\n !> @author Volker Schaus (VS)\n !!\n !> @details this subroutine adds two vectors\r\n !!\n !> @date
    \n !!
  • VS: 17.08.2018 initial implementation based on Vallado
  • \n !!
\n !!\n !---------------------------------------------------------------------------\r\n function add_vec (vec1,vec2) result (out_vec)\r\n\r\n real(dp), dimension(3), intent(in) :: vec1\r\n real(dp), dimension(3), intent(in) :: vec2\n real(dp), dimension(3) :: out_vec\n integer i\r\n\r\n do i = 1,3\r\n out_vec(i) = vec1(i) + vec2(i)\r\n end do\r\n\r\n end function add_vec\r\n\r\n !---------------------------------------------------------------------------\n !!\n !> @anchor sub_vec\n !!\n !> @brief subtracts two vectors\n !!\n !> @param[in] real(dp), dimension (3) vec1\n !> @param[in] real(dp), dimension (3) vec2\n !> @param[out] real(dp), dimension (3) out_vec\n !!\n !> @author Volker Schaus (VS)\n !!\n !> @details this subroutine subtracts two vectors\r\n !!\n !> @date
    \n !!
  • VS: 20.08.2018 initial implementation based on Vallado
  • \n !!
\n !!\n !---------------------------------------------------------------------------\n function sub_vec(Vec1, Vec2) result(out_vec)\r\n\r\n real(dp), dimension(3), intent(in) :: vec1\n real(dp), dimension(3), intent(in) :: vec2\n real(dp), dimension(3) :: out_vec\n\r\n integer i\r\n\r\n do i=1, 3\r\n out_vec(i) = vec1(i) - vec2(i)\r\n end do\r\n\r\n end function sub_vec\n\nend module slam_linAlgebra\n", "meta": {"hexsha": "15b0a40e555c431ddc904105f2feffcb04096302", "size": 21602, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/math/slam_linAlgebra.f90", "max_stars_repo_name": "Space-Systems/libslam", "max_stars_repo_head_hexsha": "9a7bd64475fb48050abf33050764c192fc650876", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-03-30T08:42:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-05T10:58:24.000Z", "max_issues_repo_path": "src/math/slam_linAlgebra.f90", "max_issues_repo_name": "Space-Systems/libslam", "max_issues_repo_head_hexsha": "9a7bd64475fb48050abf33050764c192fc650876", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-06-18T13:53:57.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-12T17:41:40.000Z", "max_forks_repo_path": "src/math/slam_linAlgebra.f90", "max_forks_repo_name": "Space-Systems/libslam", "max_forks_repo_head_hexsha": "9a7bd64475fb48050abf33050764c192fc650876", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-06-17T19:50:12.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-05T10:58:27.000Z", "avg_line_length": 31.3072463768, "max_line_length": 146, "alphanum_fraction": 0.504444033, "num_tokens": 5819, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480252950991, "lm_q2_score": 0.7154239897159438, "lm_q1q2_score": 0.6571028070415073}} {"text": " SUBROUTINE newt(x,n,check)\r\n INTEGER n,nn,NP,MAXITS\r\n LOGICAL check\r\n REAL x(n),fvec,TOLF,TOLMIN,TOLX,STPMX\r\n PARAMETER (NP=40,MAXITS=200,TOLF=1.e-4,TOLMIN=1.e-6,TOLX=1.e-7,\r\n *STPMX=100.)\r\n COMMON /newtv/ fvec(NP),nn\r\n SAVE /newtv/\r\nCU USES fdjac,fmin,lnsrch,lubksb,ludcmp\r\n INTEGER i,its,j,indx(NP)\r\n REAL d,den,f,fold,stpmax,sum,temp,test,fjac(NP,NP),g(NP),p(NP),\r\n *xold(NP),fmin\r\n EXTERNAL fmin\r\n nn=n\r\n f=fmin(x)\r\n test=0.\r\n do 11 i=1,n\r\n if(abs(fvec(i)).gt.test)test=abs(fvec(i))\r\n11 continue\r\n if(test.lt..01*TOLF)then\r\n check=.false.\r\n return\r\n endif\r\n sum=0.\r\n do 12 i=1,n\r\n sum=sum+x(i)**2\r\n12 continue\r\n stpmax=STPMX*max(sqrt(sum),float(n))\r\n do 21 its=1,MAXITS\r\n call fdjac(n,x,fvec,NP,fjac)\r\n do 14 i=1,n\r\n sum=0.\r\n do 13 j=1,n\r\n sum=sum+fjac(j,i)*fvec(j)\r\n13 continue\r\n g(i)=sum\r\n14 continue\r\n do 15 i=1,n\r\n xold(i)=x(i)\r\n15 continue\r\n fold=f\r\n do 16 i=1,n\r\n p(i)=-fvec(i)\r\n16 continue\r\n call ludcmp(fjac,n,NP,indx,d)\r\n call lubksb(fjac,n,NP,indx,p)\r\n call lnsrch(n,xold,fold,g,p,x,f,stpmax,check,fmin)\r\n test=0.\r\n do 17 i=1,n\r\n if(abs(fvec(i)).gt.test)test=abs(fvec(i))\r\n17 continue\r\n if(test.lt.TOLF)then\r\n check=.false.\r\n return\r\n endif\r\n if(check)then\r\n test=0.\r\n den=max(f,.5*n)\r\n do 18 i=1,n\r\n temp=abs(g(i))*max(abs(x(i)),1.)/den\r\n if(temp.gt.test)test=temp\r\n18 continue\r\n if(test.lt.TOLMIN)then\r\n check=.true.\r\n else\r\n check=.false.\r\n endif\r\n return\r\n endif\r\n test=0.\r\n do 19 i=1,n\r\n temp=(abs(x(i)-xold(i)))/max(abs(x(i)),1.)\r\n if(temp.gt.test)test=temp\r\n19 continue\r\n if(test.lt.TOLX)return\r\n21 continue\r\n pause 'MAXITS exceeded in newt'\r\n END\r\n", "meta": {"hexsha": "1f703da8c2178a926005285b5b7146585294cb5f", "size": 2095, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/newt.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/newt.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/newt.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": 26.5189873418, "max_line_length": 70, "alphanum_fraction": 0.4825775656, "num_tokens": 679, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802484881361, "lm_q2_score": 0.7154239897159438, "lm_q1q2_score": 0.6571028038486738}} {"text": "!*******************************************************************************\n!>\n! Kepler propagation routines.\n\n module kepler_module\n\n use numbers_module\n use kind_module, only: wp\n use iso_fortran_env, only: error_unit\n\n implicit none\n\n private\n\n public :: kepler_shepperd\n public :: kepler_goodyear_stienon_klumpp\n public :: kepler_classical\n\n contains\n!*******************************************************************************\n\n!*******************************************************************************\n!>\n! Classical Kepler propagator for elliptical and hyperbolic orbits.\n! Uses Lagrange formulations from Battin & Newton's method.\n!\n!### See also\n! * Dario Izzo: pykep/src/core_functions/propagate_lagrangian.h\n\n subroutine kepler_classical(x0, dt, mu, xf)\n\n use newton_module, only: newton\n\n implicit none\n\n real(wp),dimension(6),intent(in) :: x0 !! initial position,velocity vector\n real(wp),intent(in) :: dt !! propagation time\n real(wp),intent(in) :: mu !! central body gravitational parameter\n real(wp),dimension(6),intent(out) :: xf !! final position,velocity vector\n\n real(wp),dimension(3) :: r0 !! initial position vector\n real(wp),dimension(3) :: v0 !! initial velocity vector\n real(wp) :: de !! eccentric anomaly difference\n real(wp) :: dh !! hyperbolic anomaly difference\n integer :: iflag !! newton status flag\n real(wp) :: r,rmag,vmag,energy,a,sqrta,f,&\n g,ft,gt,sigma0,dm,dn,xs,fx,b,p,x,z,term\n\n real(wp),parameter :: parabolic_tol = 1.0e-12_wp !! zero tol for parabolic orbits (energy)\n real(wp),parameter :: ftol = 1.0e-12_wp !! function tol for root finding\n real(wp),parameter :: xtol = 1.0e-12_wp !! indep variable tol for root finding\n integer,parameter :: max_iter = 1000 !! maximum number of iterations in newton\n\n ! check trivial case:\n if (dt==zero) then\n xf = x0\n return\n end if\n\n r0 = x0(1:3)\n v0 = x0(4:6)\n rmag = norm2(r0)\n vmag = norm2(v0)\n energy = (vmag * vmag / two - mu / rmag)\n sigma0 = dot_product(r0,v0) / sqrt(mu)\n\n ! if not parabolic, then compute semimajor axis\n if (abs(energy) > parabolic_tol) then\n a = -mu / two / energy\n end if\n\n if (energy < -parabolic_tol) then ! elliptical case\n\n sqrta = sqrt(a)\n dm = sqrt(mu / a**3) * dt\n de = dm\n\n call newton(de,kepde_,d_kepde_,ftol,xtol,max_iter,xs,fx,iflag)\n if (iflag<0) then\n write(error_unit,'(A)') 'Error in kepler_classical [elliptical]: newton did not converge'\n write(*,*) xs,fx,iflag\n end if\n\n de = xs\n r = a + (rmag - a) * cos(de) + sigma0 * sqrta * sin(de) ! eqn 4.42\n\n ! lagrange coefficients (Battin eqn 4.41)\n f = one - a / rmag * (one - cos(de))\n g = a * sigma0 / sqrt(mu) * (one - cos(de)) + rmag * sqrt(a / mu) * sin(de)\n ft = -sqrt(mu * a) / (r * rmag) * sin(de)\n gt = one - a / r * (one - cos(de))\n\n else if (energy > parabolic_tol) then ! hyperbolic case\n\n sqrta = sqrt(-a)\n dn = sqrt(-mu / a**3) * dt\n dh = sign(one,dt) ! todo: need a better initial guess\n\n call newton(dh,kepdh_,d_kepdh_,ftol,xtol,max_iter,xs,fx,iflag)\n if (iflag<0) then\n write(error_unit,'(A)') 'Error in kepler_classical [hyperbola]: newton did not converge'\n write(*,*) xs,fx,iflag\n end if\n\n dh = xs\n r = a + (rmag - a) * cosh(dh) + sigma0 * sqrta * sinh(dh)\n\n ! lagrange coefficients (Battin eqn 4.62)\n f = one - a / rmag * (one - cosh(dh))\n g = a * sigma0 / sqrt(mu) * (one - cosh(dh)) + rmag * sqrt(-a / mu) * sinh(dh)\n ft = -sqrt(-mu * a) / (r * rmag) * sinh(dh)\n gt = one - a / r * (one - cosh(dh))\n\n else ! parbolic case\n\n ! See Battin Section 4.2\n\n p = two * rmag - sigma0**2\n B = one / p**1.5_wp * ( sigma0 * (rmag + p) + three * sqrt(mu) * dt )\n term = B + sqrt(one+B*B)\n z = (term)**(one/three) - (term)**(-one/three) ! Battin eqn 4.12 where z = tan(f/2)\n x = sqrt(p) * z - sigma0\n r = rmag + sigma0 * x + one/two * x**2\n\n f = one - x**2 / two / rmag\n g = x / two / sqrt(mu) * ( two * rmag + sigma0 * x )\n ft = - sqrt(mu) * x / rmag / r\n gt = one - x**2 / two / r\n\n end if\n\n ! results:\n xf(1:3) = f * r0 + g * v0\n xf(4:6) = ft * r0 + gt * v0\n\n contains\n\n ! function wrappers for newtons method:\n\n subroutine kepde_(x,f)\n implicit none\n real(wp),intent(in) :: x !! de\n real(wp),intent(out) :: f\n f = kepde(x, dm, sigma0, sqrta, a, rmag)\n end subroutine kepde_\n\n subroutine d_kepde_(x,f)\n implicit none\n real(wp),intent(in) :: x !! de\n real(wp),intent(out) :: f\n f = d_kepde(x, sigma0, sqrta, a, rmag)\n end subroutine d_kepde_\n\n subroutine kepdh_(x,f)\n implicit none\n real(wp),intent(in) :: x !! dh\n real(wp),intent(out) :: f\n f = kepdh(x, dn, sigma0, sqrta, a, rmag)\n end subroutine kepdh_\n\n subroutine d_kepdh_(x,f)\n implicit none\n real(wp),intent(in) :: x !! dh\n real(wp),intent(out) :: f\n f = d_kepdh(x, sigma0, sqrta, a, rmag)\n end subroutine d_kepdh_\n\n end subroutine kepler_classical\n!*******************************************************************************\n\n!*******************************************************************************\n!>\n! Elliptic Kepler's equation\n\n pure function kepe(e, m, ecc)\n\n implicit none\n\n real(wp),intent(in) :: e !! eccentric anomaly\n real(wp),intent(in) :: m !! mean anomaly\n real(wp),intent(in) :: ecc !! eccentricity\n real(wp) :: kepe\n\n kepe = e - ecc * sin(e) - m\n\n end function kepe\n!*******************************************************************************\n\n!*******************************************************************************\n!>\n! Derivative of [[kepe]] w.r.t. `e`\n\n pure function d_kepe(e, ecc)\n\n implicit none\n\n real(wp),intent(in) :: e !! eccentric anomaly\n real(wp),intent(in) :: ecc !! eccentricity\n real(wp) :: d_kepe\n\n d_kepe = one - ecc * cos(e)\n\n end function d_kepe\n!*******************************************************************************\n\n!*******************************************************************************\n!>\n! Elliptic Kepler's equation written in terms of the\n! eccentric anomaly difference. See Battin, eqn 4.43.\n\n pure function kepde(de, dm, sigma0, sqrta, a, r)\n\n implicit none\n\n real(wp),intent(in) :: de !! eccentric anomaly difference\n real(wp),intent(in) :: dm !! mean anomaly difference\n real(wp),intent(in) :: sigma0\n real(wp),intent(in) :: sqrta\n real(wp),intent(in) :: a\n real(wp),intent(in) :: r\n real(wp) :: kepde\n\n kepde = -dm + de + sigma0 / sqrta * (one - cos(de)) - &\n (one - r / a) * sin(de)\n\n end function kepde\n!*******************************************************************************\n\n!*******************************************************************************\n!>\n! Derivative of [[kepde]] w.r.t `de`.\n\n pure function d_kepde(de, sigma0, sqrta, a, r)\n\n implicit none\n\n real(wp),intent(in) :: de !! eccentric anomaly difference\n real(wp),intent(in) :: sigma0\n real(wp),intent(in) :: sqrta\n real(wp),intent(in) :: a\n real(wp),intent(in) :: r\n real(wp) :: d_kepde\n\n d_kepde = one + sigma0 / sqrta * sin(de) - (one - r / a) * cos(de)\n\n end function d_kepde\n!*******************************************************************************\n\n!*******************************************************************************\n!>\n! Battin, eqn. 4.64.\n\n pure function kepdh(dh, dn, sigma0, sqrta, a, r)\n\n implicit none\n\n real(wp),intent(in) :: dh !! hyperbolic anomaly difference\n real(wp),intent(in) :: dn\n real(wp),intent(in) :: sigma0\n real(wp),intent(in) :: sqrta\n real(wp),intent(in) :: a\n real(wp),intent(in) :: r\n real(wp) :: kepdh\n\n kepdh = -dn - dh + sigma0 / sqrta * (cosh(dh) - one) + &\n (one - r / a) * sinh(dh)\n\n end function kepdh\n!*******************************************************************************\n\n!*******************************************************************************\n!>\n! Derivative of [[kepdh]] w.r.t `dh`.\n\n pure function d_kepdh(dh, sigma0, sqrta, a, r)\n\n implicit none\n\n real(wp),intent(in) :: dh !! hyperbolic anomaly difference\n real(wp),intent(in) :: sigma0\n real(wp),intent(in) :: sqrta\n real(wp),intent(in) :: a\n real(wp),intent(in) :: r\n real(wp) :: d_kepdh\n\n d_kepdh = -one + sigma0 / sqrta * sinh(dh) + (one - r / a) * cosh(dh)\n\n end function d_kepdh\n!*******************************************************************************\n\n!*******************************************************************************\n!>\n! Barker time of flight equation\n\n pure function barker(r1, r2, mu)\n\n implicit none\n\n real(wp),dimension(3),intent(in) :: r1\n real(wp),dimension(3),intent(in) :: r2\n real(wp),intent(in) :: mu\n real(wp) :: barker\n\n real(wp) :: x, r1mag, r2mag, r21mag, sigma, r1pr2mag\n real(wp),dimension(3) :: r21\n\n r1mag = norm2(r1)\n r2mag = norm2(r2)\n r21 = r2 - r1\n r21mag = norm2(r21)\n x = r1(1) * r2(2) - r1(2) * r2(1)\n sigma = sign(one,x)\n r1pr2mag = r1mag + r2mag\n\n barker = (r1pr2mag + r21mag)**1.5_wp - &\n sigma * (r1pr2mag - r21mag)**1.5_wp / (six * sqrt(mu))\n\n end function barker\n!*******************************************************************************\n\n!*******************************************************************************\n!>\n!\n pure function kepds(ds, dt, r0, vr0, alpha, mu)\n\n implicit none\n\n real(wp),intent(in) :: ds !! universal anomaly difference\n real(wp),intent(in) :: dt\n real(wp),intent(in) :: r0\n real(wp),intent(in) :: vr0\n real(wp),intent(in) :: alpha\n real(wp),intent(in) :: mu\n real(wp) :: kepds\n\n real(wp) :: c,s,ads2,ds2\n\n ds2 = ds * ds\n ads2 = alpha * ds2\n s = stumpff_s(ads2)\n c = stumpff_c(ads2)\n\n kepds = -sqrt(mu) * dt + r0 * vr0 * ds2 * c / sqrt(mu) + &\n (one - alpha * r0) * ds2 * ds * s + r0 * ds\n\n end function kepds\n!*******************************************************************************\n\n!*******************************************************************************\n!>\n!\n pure function d_kepds(ds, r0, vr0, alpha, mu)\n\n implicit none\n\n real(wp),intent(in) :: ds\n real(wp),intent(in) :: r0\n real(wp),intent(in) :: vr0\n real(wp),intent(in) :: alpha\n real(wp),intent(in) :: mu\n real(wp) :: d_kepds\n\n real(wp) :: c,s,ads2,ds2\n\n ds2 = ds * ds\n ads2 = alpha * ds2\n s = stumpff_s(ads2)\n c = stumpff_c(ads2)\n\n d_kepds = r0 * vr0 / sqrt(mu) * ds * (one - ads2 * s) + &\n (one - alpha * r0) * ds2 * c + r0\n\n end function d_kepds\n!*******************************************************************************\n\n!*******************************************************************************\n!>\n! Stumpff function S(z)\n\n pure function stumpff_s(z) result(s)\n\n implicit none\n\n real(wp),intent(in) :: z\n real(wp) :: s\n\n if (z > zero) then\n s = (sqrt(z) - sin(sqrt(z))) / sqrt(z)**3\n else if (z < zero) then\n s = (sinh(sqrt(-z)) - sqrt(-z)) / (-z)**(three/two)\n else\n s = one/six\n end if\n\n end function stumpff_s\n!*******************************************************************************\n\n!*******************************************************************************\n!>\n! Stumpff function C(z)\n\n pure function stumpff_c(z) result(c)\n\n implicit none\n\n real(wp),intent(in) :: z\n real(wp) :: c\n\n if (z > zero) then\n c = (one - cos(sqrt(z))) / z\n else if (z < zero) then\n c = (cosh(sqrt(-z)) - one) / (-z)\n else\n c = 0.5_wp\n end if\n\n end function stumpff_c\n!*******************************************************************************\n\n!*******************************************************************************\n!>\n! Kepler propagation using Shepperd's method.\n!\n!### Reference\n! * S.W. Shepperd, \"Universal Keplerian State Transition Matrix\".\n! Celestial Mechanics 35(1985) p. 129-144.\n! * Rody P.S. Oldenhuis, `progress_orbitM` Matlab function (BSD license).\n! http://www.mathworks.com/matlabcentral/fileexchange/26349-kepler-state-transition-matrix-mex\n! * C.D. Eagle, Orbital Mechanics with MATLAB, `twobody2.m` Matlab function (BSD license).\n! http://www.mathworks.com/matlabcentral/fileexchange/48723-matlab-functions-for-two-body-orbit-propagation\n\n subroutine kepler_shepperd(mu,rv1,dt,rv2,istat)\n\n implicit none\n\n real(wp),intent(in) :: mu !! gravitational parameter\n real(wp),dimension(6),intent(in) :: rv1 !! initial position,velocity vector\n real(wp),intent(in) :: dt !! time step\n real(wp),dimension(6),intent(out) :: rv2 !! final position,velocity vector\n integer,intent(out),optional :: istat !! status flag (if not present, warnings are printed):\n !! Linear combination of :\n !!\n !! `0` : all is well\n !! `-10` : failed to converge in time loop\n !! `-100` : failed to converge in `g` loop\n\n ! note: some of these could also be (optional) input:\n real(wp),parameter :: min_dt = epsilon(one) !! time step considered as zero (sec)\n integer,parameter :: max_iter = 1000 !! max iterations for time\n integer,parameter :: max_iter_g = 1000 !! max iterations for g\n real(wp),parameter :: ttol = 1.0e-8_wp !! tolerance for time (sec)\n real(wp),parameter :: gtol = 1.0e-12_wp !! tolerance for g\n real(wp),parameter :: zero_tol = epsilon(one) !! tolerance for beta=0 (parabola)\n logical,parameter :: use_halley = .true. !! use the Halley update\n !! rather than the original Newton\n\n real(wp),dimension(3) :: r1 !! initial position vector\n real(wp),dimension(3) :: v1 !! initial velocity vector\n real(wp) :: r1mag,nu0,beta,p,deltau,u,t,deltat,bu,q,&\n a,b,gprev,u0w2,u1w2,uu,u0,u1,u2,u3,r,&\n ff,f,gg,g,umin,umax,du,abs_beta\n integer :: n,iter,k,d,l,iterg\n\n if (present(istat)) istat = 0\n\n if (abs(dt) <= min_dt) then\n\n rv2 = rv1\n\n else\n\n r1 = rv1(1:3)\n v1 = rv1(4:6)\n r1mag = norm2(r1)\n nu0 = dot_product(r1,v1)\n beta = two*mu/r1mag - dot_product(v1,v1)\n abs_beta = abs(beta)\n\n if (abs_beta>zero_tol) then\n umax = one/sqrt(abs_beta)\n else\n umax = huge(one)\n end if\n umin = -umax\n\n if (beta > zero) then\n p = twopi*mu*beta**(-three/two)\n n = floor((dt + p/two - two*nu0/beta)/p)\n deltau = twopi*n*beta**(-five/two)\n else\n deltau = zero\n end if\n\n u = zero\n t = zero\n iter = 0\n deltat = dt-t\n do while (abs(deltat) > ttol)\n iter = iter + 1\n bu = beta*u*u\n q = min(0.5_wp,bu/(one+bu)) ! avoid q > 0.5 due to numerical issues\n a = one\n b = one\n g = one\n n = 0\n k = -9\n d = 15\n l = 3\n gprev = huge(one)\n iterg = 0\n do while (abs(g-gprev) > gtol)\n iterg = iterg + 1\n k = -k\n l = l + 2\n d = d + 4*l\n n = n + (1+k)*l\n a = d/(d - n*a*q)\n b = (a-one)*b\n gprev = g\n g = g + b\n if (iterg==max_iter_g) then\n if (present(istat)) then\n istat = istat - 100\n else\n write(*,*) 'Warning: kepler_shepperd failed to converge in g iteration'\n end if\n exit\n end if\n end do\n\n u0w2 = one - two*q\n u1w2 = two*(one-q)*u\n uu = 16.0_wp/15.0_wp*u1w2**5*g + deltau\n u0 = two*u0w2**2-one\n u1 = two*u0w2*u1w2\n u2 = two*u1w2**2\n u3 = beta*uu + u1*u2/three\n r = r1mag*u0 + nu0*u1 + mu*u2\n t = r1mag*u1 + nu0*u2 + mu*u3\n deltat = dt - t\n\n if (use_halley) then\n ! Halley version from Oldenhuis routine\n du = deltat/((one-q)*(four*r + deltat*beta*u))\n else\n ! original Newton\n du = deltat/four/(one-q)/r\n end if\n\n ! this logic is from the Eagle routine\n if (duumax) u = (umin + umax)/two\n end if\n\n if (iter==max_iter) then\n if (abs(deltat) > ttol) then\n ! it still hasn't converged\n if (present(istat)) then\n istat = istat - 10\n else\n write(*,*) 'Warning: kepler_shepperd failed to converge in time iteration'\n end if\n exit\n end if\n end if\n\n end do\n\n ff = one - mu/r1mag*u2\n f = -mu*u1/r/r1mag\n gg = r1mag*u1 + nu0*u2\n g = one - mu/r*u2\n\n rv2 = [r1*ff + v1*gg, r1*f + v1*g]\n\n end if\n\n end subroutine kepler_shepperd\n!*******************************************************************************\n\n!*******************************************************************************\n!>\n! Kepler propagator based on the Goodyear code with\n! modifications by Stienon and Klumpp.\n!\n!### See also\n! * W. H. Goodyear, \"Completely General Closed-Form Solution for Coordinates\n! and Partial Derivatives of the Two-Body Problem\", Astronomical Journal,\n! Vol. 70, No. 3, April 1965.\n! [pdf](http://adsabs.harvard.edu/full/1965AJ.....70..189G)\n! * W. H. Goodyear, \"A General Method for the Computation of Cartesian\n! Coordinates and Partial Derivatives of the Two-Body Problem\",\n! NASA CR-522, Sep 1, 1966.\n! [pdf](https://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/19660027556.pdf)\n! * A. Klumpp, \"Performance Comparision of Lambert and Kepler Algorithms\",\n! JPL Interoffice Memorandum, 314.1-0426-ARK, Jan 2, 1991.\n! (See the `KEPGSK` Fortran 77 routine)\n\n subroutine kepler_goodyear_stienon_klumpp(rv0,tau,mu,accy,rvf)\n\n implicit none\n\n real(wp),dimension(6),intent(in) :: rv0 !! state vector at reference\n !! time T0 [km,km/s]\n real(wp),intent(in) :: tau !! Time interval T-T0 [sec]\n real(wp),intent(in) :: mu !! Central body gravitational\n !! constant [km^3/s^2]\n real(wp),intent(in) :: accy !! Fractional accuracy required\n !! [0->0.1]\n real(wp),dimension(6),intent(out) :: rvf !! state vector at solution time\n !! T [km,km/s]\n\n real(wp),parameter :: onethird = 1.0_wp / 3.0_wp !! 0.333333 in original code\n\n integer :: iloop !! loop counter defining number of iterations\n real(wp) :: r !! radius at solution time `T`\n real(wp) :: r0 !! radius at solution time `T0`\n integer :: i !! index\n integer :: j !! index\n integer :: m !! counter for normalizing lambda\n real(wp) :: psi !! independent variable in Kepler's equation\n real(wp) :: psin !! lower limit to `psi`\n real(wp) :: psip !! upper limit to `psi`\n real(wp) :: dlim !! tau/periapsis distance = abs(limit to `psi`)\n real(wp) :: dtau !! Kepler's equation residual\n real(wp) :: dtaun !! lower limit to `dtau`\n real(wp) :: dtaup !! upper limit to `dtau`\n real(wp) :: accrcy !! accuracy = midval(zero, `accy`, 0.1)\n real(wp) :: sig0 !! dot product: `r` with `v`\n real(wp) :: alpha !! twice the energy per unit mass\n real(wp) :: h2 !! square of angular momentum per unit mass\n real(wp) :: a !! reduced argument of `s_0`, `s_1`, etc.\n real(wp) :: ap !! actual argument of `s_0`, `s_1`, etc.\n real(wp) :: c0 !! c(n) is the nth Goodyear polynomial `s_n`\n !! divided by its leading term, so that\n !!\n !! * `c0 = s_0 = cosh(z)`\n !! * `c1 = s_1/psi = sinh(z)/z`\n !! * `c(n+2) = (n+1)(n+2)[c(n)-1]/z^2`\n !!\n !! where `z = psi*sqrt(alpha)`. `ap=norm2(z)`\n real(wp) :: c1\n real(wp) :: c2\n real(wp) :: c3\n real(wp) :: c4\n real(wp) :: c5x3\n real(wp) :: s1 !! `s_n` is the nth Goodyear\n !! polynomial, given by\n !! `s_n = psi^n sim{z^(2k)/(2k)!} k >=0 `\n real(wp) :: s2\n real(wp) :: s3\n real(wp) :: g !! the G-function\n real(wp) :: gdm1 !! time derivative of the G-function minus one\n real(wp) :: fm1 !! the F-function minus one\n real(wp) :: fd !! time derivative of the F-function\n real(wp),dimension(4) :: c !! terms in F(psi)\n\n accrcy = min(max(zero, accy), 0.1_wp)\n\n r0 = dot_product(rv0(1:3), rv0(1:3)) ! r dot r\n sig0 = dot_product(rv0(1:3), rv0(4:6)) ! r dot v\n alpha = dot_product(rv0(4:6), rv0(4:6)) ! v dot v\n h2 = max(r0*alpha - sig0*sig0, zero)\n r0 = sqrt(r0)\n alpha = alpha - two*mu/r0\n\n !compute initial limits for phi and dtau:\n c0 = sqrt(max(mu*mu + h2*alpha, zero)) ! gm * eccentricity\n dlim = div(1.1_wp * tau * (c0 + mu), h2) ! tau/periapsis distance = max(a).\n ! Arbitrary factor 1.1 ensures\n ! psin <= psi <= psip\n ! when converged, despite\n ! numerical imprecision.\n\n if (tau < zero) then\n psin = dlim\n psip = zero\n dtaun = psin\n dtaup = -tau\n else\n psin = zero\n psip = dlim\n dtaun = -tau\n dtaup = psip\n end if\n\n !compute initial value of psi:\n psi = tau/r0\n\n if (alpha >= zero) then\n c2 = one\n if (tau < zero) c2 = -one\n c3 = abs(tau)\n if (alpha > zero) then\n c0 = h2*sqrt(h2)/(mu + c0)**2\n if (c3 > c0) then\n c1 = sqrt(alpha)\n psi = log(two*alpha*c1*c3/(r0*alpha + c2*c1*sig0 + mu))\n psi = max(psi,one)*c2/c1\n end if\n else !parabola\n c0 = r0*sqrt(six*r0/mu)\n if (c3 > c0) psi = c2*(six*c3/mu)**onethird\n end if\n end if\n\n ! begin loop for solving Kepler's equation:\n\n m = 0\n iloop = 0\n\n do\n iloop = iloop + 1\n\n ! begin series summation:\n\n !compute argument a in reduced series obtained by factoring out psi's:\n a = alpha*psi*psi\n if (abs(a)>one) then\n !save a in ap and mod a if a exceeds unity in magnitude\n ap = a\n do\n m = m + 1\n a = a*0.25_wp\n if (abs(a)<=one) exit\n end do\n end if\n\n !sum series c5x3=3*s5/psi**5 and c4=s4/psi**4\n c4 = one\n c5x3 = one\n do i=9,3,-1\n j = 2*i\n c5x3 = one + a*c5x3/(j*(j+1))\n c4 = one + a*c4 /(j*(j-1))\n end do\n\n c5x3 = c5x3/40.0_wp\n c4 = c4 /24.0_wp\n\n !compute series c3=s3/psi**3,c2=s2/psi**2,c1=s1/psi,c0=rv0\n c3 = (0.5_wp + a*c5x3)/ three\n c2 = 0.5_wp + a*c4\n c1 = one + a*c3\n c0 = one + a*c2\n if (m>0) then\n\n !demod series c0 and c1 if necessary with double angle formulas:\n do\n c1 = c1*c0\n c0 = two*c0*c0 - one\n m = m - 1\n if (m<=0) exit\n end do\n\n !compute c2,c3,c4,c5x3 from c0,c1,ap if demod required:\n c2 = (c0 - one)/ap\n c3 = (c1 - one)/ap\n c4 = (c2 - 0.5_wp)/ap\n c5x3 = (three*c3 - 0.5_wp)/ap\n\n end if\n\n !compute series s1,s2,s3 from c1,c2,c3:\n s1 = c1*psi\n s2 = c2*psi*psi\n s3 = c3*psi*psi*psi\n\n ! compute slope r and residuals for kepler's equation:\n\n c(1) = r0*s1\n c(2) = sig0*s2\n c(3) = mu*s3\n c(4) = tau\n g = c(4) - c(3)\n dtau = c(1) + c(2) - g\n r = abs(r0*c0 + (sig0*s1 + mu*s2))\n\n ! compute next psi:\n do\n\n !method = 0\n if (dtau < zero) then\n psin = psi\n dtaun = dtau\n psi = psi - dtau/r\n if (psi < psip) exit ! < (not <=) to avoid false convergence\n else\n psip = psi\n dtaup = dtau\n psi = psi - dtau/r\n if (psi > psin) exit ! > (not >=) to avoid false convergence\n end if\n\n !reset psi within bounds psin and psip:\n\n !try incrementing bound with dtau nearest zero by the ratio 4*dtau/tau\n !--method = 1\n if (abs(dtaun) < abs(dtaup)) psi = psin*(one-div(four*dtaun,tau))\n if (abs(dtaup) < abs(dtaun)) psi = psip*(one-div(four*dtaup,tau))\n if (psi_in(psi)) exit\n\n !try doubling bound closest to zero:\n !--method = 2\n if (tau > zero) psi = psin + psin\n if (tau < zero) psi = psip + psip\n if (psi_in(psi)) exit\n\n !try interpolating between bounds:\n !--method = 3\n psi = psin + (psip - psin) * div(-dtaun, dtaup - dtaun)\n if (psi_in(psi)) exit\n\n !try halving between bounds:\n !--method = 4\n psi = psin + (psip - psin) * 0.5_wp\n exit\n\n end do\n\n ! test for convergence\n i = 1\n do j=2,4\n if (abs(c(j)) > abs(c(i))) i = j\n end do\n\n if (abs(dtau)>abs(c(i))*accrcy .and. &\n psip-psin>abs(psi)*accrcy .and. &\n psi/=psin .and. psi/=psip ) then\n cycle\n else\n exit\n end if\n\n end do\n\n !compute remaining three of four functions: g, gdm1, fm1, fd\n gdm1 = -mu*s2/r\n fm1 = -mu*s2/r0\n fd = -mu*s1/r0/r\n\n ! compute state at time T = T0 + TAU\n rvf(1:3) = rv0(1:3) + fm1*rv0(1:3) + g*rv0(4:6) ! terminal positions\n rvf(4:6) = rv0(4:6) + fd*rv0(1:3) + gdm1*rv0(4:6) ! terminal velocities\n\n contains\n!*******************************************************************************\n\n !***************************************************************************\n !>\n ! Returns a nonoverflowing quotient\n\n pure function div(num,den)\n\n implicit none\n\n real(wp) :: div\n real(wp),intent(in) :: num\n real(wp),intent(in) :: den\n\n real(wp),parameter :: fsmall = 1.0e-38_wp !! small number above underflow limit\n real(wp),parameter :: flarge = 1.0e+38_wp !! large number below underflow limit\n\n div = num / ( sign(one,den) * max(abs(den),abs(num)/flarge, fsmall) )\n\n end function div\n !***************************************************************************\n\n !***************************************************************************\n !>\n ! Returns true if `phi` is within and not on bounds\n\n pure function psi_in(psi)\n\n implicit none\n\n logical :: psi_in\n real(wp),intent(in) :: psi\n\n ! > & < (not >= & <=) to avoid false convergence\n psi_in = (psi > psin .and. psi < psip)\n\n end function psi_in\n !***************************************************************************\n\n end subroutine kepler_goodyear_stienon_klumpp\n!*******************************************************************************\n\n!*******************************************************************************\n end module kepler_module\n!*******************************************************************************\n", "meta": {"hexsha": "e5ea77f913202be30c9ff06c656957251ad7b46f", "size": 29362, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/kepler_module.f90", "max_stars_repo_name": "jacobwilliams/Fortran-Astrodynamics-Toolk", "max_stars_repo_head_hexsha": "f8e18642dc8d78473d233b8fa6078fdbf7a1d6fc", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 122, "max_stars_repo_stars_event_min_datetime": "2015-01-29T05:40:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:20:21.000Z", "max_issues_repo_path": "src/kepler_module.f90", "max_issues_repo_name": "gandymagic/Fortran-Astrodynamics-Toolkit", "max_issues_repo_head_hexsha": "7f176fabc8c36cc1981349b02eeb6d8112f2bfbc", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 25, "max_issues_repo_issues_event_min_datetime": "2015-06-10T02:16:59.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T04:28:55.000Z", "max_forks_repo_path": "src/kepler_module.f90", "max_forks_repo_name": "gandymagic/Fortran-Astrodynamics-Toolkit", "max_forks_repo_head_hexsha": "7f176fabc8c36cc1981349b02eeb6d8112f2bfbc", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 43, "max_forks_repo_forks_event_min_datetime": "2015-02-12T13:24:23.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-30T04:30:49.000Z", "avg_line_length": 32.6971046771, "max_line_length": 110, "alphanum_fraction": 0.44707445, "num_tokens": 8331, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802350995703, "lm_q2_score": 0.7154239957834733, "lm_q1q2_score": 0.6571027998430785}} {"text": "* Eigen2x2.f\n* diagonalization of a Hermitian 2-by-2 matrix\n* this file is part of FormCalc\n* last modified 15 Jun 04 th\n\n\n\tsubroutine Eigen2x2(m, msq, U, M11, M22, M12, *)\n\timplicit none\n\tdouble precision m(*), msq(*)\n\tdouble complex U(2,*)\n\tdouble precision M11, M22\n\tdouble complex M12\n\n\tdouble precision m1, m2, delta, tau\n\tdouble complex s\n\n\tcall Jacobi(delta, s, tau, M11 - M22, M12, abs(M12))\n\n\tm1 = M11 + delta\n\tm2 = M22 - delta\n\n\tif( m1 .gt. m2 ) then\n\t msq(1) = m2\n\t msq(2) = m1\n\t U(1,1) = -dconjg(s)\n\t U(2,2) = s\n\t U(1,2) = 1 - tau\n\t U(2,1) = U(1,2)\n\telse\n\t msq(1) = m1\n\t msq(2) = m2\n\t U(1,1) = 1 - tau\n\t U(2,2) = U(1,1)\n\t U(1,2) = s\n\t U(2,1) = -dconjg(s)\n\tendif\n\n\tif( msq(1) .lt. 0 ) then\n\t print *, \"Negative mass-squares.\"\n\t return 1\n\tendif\n\tm(1) = sqrt(msq(1))\n\tm(2) = sqrt(msq(2))\n\tend\n\n", "meta": {"hexsha": "f3d6aeceffdc46b25a396dc8bd175a0948300a8a", "size": 817, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Externals/micromegas_4.3.5/CPVMSSM/lib/nngg12/util/diag/Eigen2x2.f", "max_stars_repo_name": "yuanfangtardis/vscode_project", "max_stars_repo_head_hexsha": "2d78a85413cc85789cc4fee8ec991eb2a0563ef8", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Externals/micromegas_4.3.5/CPVMSSM/lib/nngg12/util/diag/Eigen2x2.f", "max_issues_repo_name": "yuanfangtardis/vscode_project", "max_issues_repo_head_hexsha": "2d78a85413cc85789cc4fee8ec991eb2a0563ef8", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Externals/micromegas_4.3.5/CPVMSSM/lib/nngg12/util/diag/Eigen2x2.f", "max_forks_repo_name": "yuanfangtardis/vscode_project", "max_forks_repo_head_hexsha": "2d78a85413cc85789cc4fee8ec991eb2a0563ef8", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-15T12:22:30.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-15T12:22:30.000Z", "avg_line_length": 17.7608695652, "max_line_length": 53, "alphanum_fraction": 0.5777233782, "num_tokens": 364, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802350995703, "lm_q2_score": 0.7154239836484143, "lm_q1q2_score": 0.6571027886972667}} {"text": "!********************************************************************************\n!* This file is adapted from part of python_finite_volume_solver\n!* (https://github.com/bwvdnbro/python_finite_volume_solver), and is part of \n!* BAFFLE (https://github.com/ATHannington/BAFFLE)\n!*\n!* BAFFLE:\n!* Copyright (C) 2017 Andrew Hannington (ath4@st-andrews.ac.uk)\n!*\n!* python_finite_volume_solver:\n!* Copyright (C) 2017 Kenneth Wood (kw25@st-andrews.ac.uk)\n!* Bert Vandenbroucke (bert.vandenbroucke@gmail.com)\n!*\n!* python_finite_volume_solver and BAFFLE are free software: you can redistribute \n!* them and/or modify them under the terms of the GNU Affero General Public License\n!* as published by the Free Software Foundation, either version 3 of the License, or\n!* (at your option) any later version.\n!*\n!* python_finite_volume_solver and BAFFLE are distributed in the hope that they will \n!* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of\n!* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n!* GNU Affero General Public License for more details.\n!*\n!* You should have received a copy of the GNU Affero General Public License\n!* along with python_finite_volume_solver and BAFFLE. If not, see\n!* .\n!********************************************************************************\n\n!********************************************************************************\n!* @file riemann.f90\n!*\n!* @brief Standalone Riemann solver library: Fortran 90 version.\n!*\n!* This Riemann solver is the original exact Riemann solver as it is presented in\n!* Toro, E., Riemann Solvers and Numerical Methods for Fluid Dynamics, 3rd\n!* edition (Springer, 2009), chapter 4.\n!*\n!* It was carefully copied (by hand) from that book to actual Fortran 77 code by\n!* Kenneth Wood, and slightly modified to be used as a Riemann solver routine in\n!* a 1-3D finite volume code. It was then adapted to Fortran 90, and combined with\n!* Bert Vandenbroucke's python riemann solver, by Andrew Hannington.\n!*\n!* Additional changes (including this documentation) were made by Bert\n!* Vandenbroucke to make the Python, C++ and Fortran version of the Riemann\n!* solver more homogeneous. Subsequent changes (including edits to this documentation)\n!* were made by Andrew Hannington, including adding vacuum capability from Bert\n!* Vandenbroucke's own python Riemann solver.\n!*\n!* @author Andrew Hannington (ath4@st-andrews.ac.uk)\n!* @author Kenneth Wood (kw25@st-andrews.ac.uk)\n!* @author Bert Vandenbroucke (bv7@st-andrews.ac.uk)\n!********************************************************************************\n\n!********************************************************************************\n!* @brief Solve the Riemann problem with the given left and right state.\n!*\n!* @pCRam d1 Left state density.\n!* @pCRam u1 Left state fluid velocity.\n!* @pCRam p1 Left state pressure.\n!* @pCRam d2 Right state density.\n!* @pCRam u2 Right state fluid velocity.\n!* @pCRam p2 Right state pressure.\n!* @pCRam gg Adiabatic index of the gas.\n!* @pCRam ds VCRiable to store the resulting density in.\n!* @pCRam us VCRiable to store the resulting fluid velocity in.\n!* @pCRam ps VCRiable to store the resulting pressure in.\n!* @pCRam uflag Flag vCRiable used to signal if the solution was sampled from the\n!* left state (-1) or the right state (1). A vacuum state (0) is currently not\n!* supported by this version of the Riemann solver.\n!* @pCRam x_over_t Point (in velocity space) where we want to sample the\n!* solution. In a finite volume scheme you usually want to set this value to 0.\n!********************************************************************************\nmodule gamma_module\n\tREAL*8 :: G1, G2, G3, G4, G5, G6, G7, G8\nend module gamma_module\n\nsubroutine initialise_gammas\n\tUSE CONSTANTS\n\tuse gamma_module\n \timplicit none\n\n G1 = (gam - 1.0d0)/(2.0d0*gam)\n G2 = (gam + 1.0d0)/(2.0d0*gam)\n G3 = 2.0d0*gam/(gam - 1.0d0)\n G4 = 2.0d0/(gam - 1.0d0)\n G5 = 2.0d0/(gam + 1.0d0)\n G6 = (gam - 1.0d0)/(gam + 1.0d0)\n G7 = (gam - 1.0d0)/2.0d0\n G8 = gam - 1.0d0\n\nend subroutine initialise_gammas\n!********************************************************************************\n!********************************************************************************\n!********************************************************************************\n!********************************************************************************\n\nsubroutine riemann(d1, u1, p1, d2, u2, p2, gg, ds,us, ps, uflag, x_over_t,i,j,k,xyz,time)\n\n\tUSE CONSTANTS\n\tuse gamma_module\n \timplicit none\n\n\tInteger,intent(in) :: i,j,k\n\tReal*8, intent(in) :: time\n\tCharacter(len=1),intent(in) :: xyz\t\t\t\t\t!ChCRacter passed in from cells to Riemann that tells this subroutine whether we CRe looking at x, y, or z direction.\n\n! DeclCRation of vCRiables:\n integer uflag\n Real*8 :: AGAMMA, DL, UL, PL, CL, DR, UR, PR, CR, &\n DIAPH, DOMLEN, DS, DX, PM, MPA, PS, S, &\n TIMEOUT, UM, US, XPOS\n\n real*8 gg, d1, u1, p1, d2, u2, p2\n real*8 x_over_t\n\n COMMON /STATES/ DL, UL, PL, CL, DR, UR, PR, CR\n\n! Compute gamma related constants\n\n AGAMMA = gg\n DL = d1\n UL = u1\n PL = p1\n DR = d2\n UR = u2\n PR = p2\n\n MPA=1.0d0 ! Not sure about this????\n\n! Compute sound speeds\n\n\tIf (IsoBool .eqv. .FALSE.) then\n\t\tCL = DSQRT(AGAMMA*PL/DL)\n\t\tCR = DSQRT(AGAMMA*PR/DR)\n\telse if (IsoBool .eqv. .TRUE.) then\n\t\tCL = DSQRT(PL/DL)\n\t\tCR = DSQRT(PR/DR)\n\tENDIF\n\n! The pressure positivity condition is tested for\n\n IF(G4*(CL+CR).LE.(UR-UL))THEN\n!\t\tPrint*,\n!\t\tPrint*,\"***!*!*!*!*!***\"\n!\t\tPrint*, \"Vacuum generated by data [@RIEMANN SOLVER].\"\n!\t\tPrint*,\"Whilst solving in \",xyz,\" direction.\"\n!\t\tPrint*,\"i=\",i,\"j=\",j,\"k=\",k\n!\t\tPrint*,\"Time=\",time\n!\t\tPrint*,\n!\t\tPrint*,\"Attempting to Solve!\"\n\t\tcall solve_vacuum(dL, uL, PL, CL, dR, uR, PR, CR, x_over_t, ds, us, Ps, uflag)\n\t!\t solve_vacuum(rhoL, uL, PL, CL, rhoR, uR, PR, CR, x_over_t, rhosol, usol, Psol, flag)\n\n\telse\n\n! Exact solution for pressure and velocity in star region is found\n\t\tCALL STCRPU(PM, UM, MPA)\n\n\n\n\t if(pm.ne.pm) then\n\t\tPrint*,\"NAN DETECTED! [@RIEMANN SOLVER]. PROGRAM WILL ABORT!\"\n\t\tPrint*,\"Whilst solving in \",xyz,\" direction.\"\n\t\tPrint*,\"i=\",i,\"j=\",j,\"k=\",k\n\t\tPrint*,\"Time=\",time\n\t\tprint*,\"PM=\",pm,\"PL=\",pl,\"DL=\",dl,\"uL=\",ul,\"PR=\",pr,\"DR=\",dr,\"uR=\",ur\n\t\tstop\n\t endif\n\t if(UM .gt.x_over_t) then\n\t\tuflag=-1 ! \"left state\"\n\t else\n\t\tuflag=1 ! \"right state\n\t endif\n\n\n\t CALL SAMPLE(PM, UM, x_over_t, DS, US, PS)\n\n\tendif\n\n RETURN\n END\n\n!********************************************************************************\n!* @brief Get the pressure and velocity in the middle state.\n!*\n!* @pCRam p VCRiable to store the resulting pressure in.\n!* @pCRam u VCRiable to store the resulting fluid velocity in.\n!* @pCRam mpa Mach number? Not used.\n!********************************************************************************\n SUBROUTINE STCRPU(P, U, MPA)\n\n\tUSE CONSTANTS\n\tuse gamma_module\n \timplicit none\n\n! Purpose: to compute the solution for pressure and velocity in stCR region\n\n INTEGER I, NRITER\n\n REAL*8 DL, UL, PL, CL, DR, UR, PR, CR, &\n CHANGE, FL, FLD, FR, FRD, P, POLD, PSTCRT, &\n TOLPRE, U, UDIFF, MPA\n\n COMMON/STATES/ DL, UL, PL, CL, DR, UR, PR, CR\n DATA TOLPRE, NRITER/1.0d-09, 20/\n\n! Guessed value PSTCRT is computed\n\n CALL GUESSP(PSTCRT)\n\n POLD = PSTCRT\n UDIFF = UR - UL\n! WRITE(6,*)'Iteration number Change '\n\n DO 10 I = 1, NRITER\n\n CALL PREFUN(FL, FLD, POLD, DL, PL, CL)\n CALL PREFUN(FR, FRD, POLD, DR, PR, CR)\n P = POLD - (FL + FR + UDIFF)/(FLD + FRD)\n\n CHANGE = 2.0d0*DABS((P - POLD)/(P + POLD))\n! WRITE(6, 30)I, CHANGE\n IF(CHANGE.LE.TOLPRE)GOTO 20\n IF(P.LT.0.0)P = TOLPRE\n POLD = P\n\n 10 CONTINUE\n\n! WRITE(6,*)'Divergence in Newton-Raphson iteration'\n\n 20 CONTINUE\n\n! Compute velocity in stCR region\n\n U = 0.5d0*(UL + UR + FR - FL)\n\n! WRITE(6,*)'Pressure\tVelocity'\n! WRITE(6,40)P/MPA, U\n\n 30 FORMAT(5X, I5,15X, F12.7)\n 40 FORMAT(2(F14.6, 5X))\n\n RETURN\n END\n\n!********************************************************************************\n!* @brief Get an initial guess for the pressure in the middle state, as a\n!* stCRting point for the Newton-Raphson iteration.\n!*\n!* @pCRam pm VCRiable to store the resulting pressure guess in.\n!********************************************************************************\n SUBROUTINE GUESSP(PM)\n\n! Purpose: to provide a guess value for pressure PM in the StCR Region.\n! The choice is made according to adaptive Riemann solver using the PVRS,\n! TRRS, and TSRS approximate Riemann solvers\n\n\tUSE CONSTANTS\n\tuse gamma_module\n \timplicit none\n\n REAL*8 DL, UL, PL, CL, DR, UR, PR, CR, &\n AGAMMA, &\n CUP, GEL, GER, PM, PMAX, PMIN, PPV, PQ, &\n PTL, PTR, QMAX, QUSER, UM\n\n\n COMMON /STATES/ DL, UL, PL, CL, DR, UR, PR, CR\n\n QUSER = 2.0d0\n\n! Compute guess pressure for PVRS Riemann solver\n\n CUP = 0.25d0*(DL + DR)*(CL + CR)\n PPV = 0.5d0*(PL + PR) + 0.5d0*(UL - UR)*CUP\n PPV = AMAX1(0.0d0, PPV)\n PMIN = AMIN1(PL, PR)\n PMAX = AMAX1(PL, PR)\n QMAX = PMAX/PMIN\n\n IF(QMAX.LE.QUSER.AND. &\n (PMIN.LE.PPV.AND.PPV.LE.PMAX))THEN\n\n! Select PVRS Riemann solver\n\n PM = PPV\n\n ELSE\n IF(PPV.LT.PMIN)THEN\n\n! Select Two-RCRefaction Riemann solver\n\n PQ = (PL/PR)**G1\n UM = (PQ*UL/CL + UR/CR + &\n G4*(PQ - 1.0d0))/(PQ/CL + 1.0d0/CR)\n PTL = 1.0d0 + G7*(UL - UM)/CL\n PTR = 1.0d0 + G7*(UM - UR)/CR\n PM = 0.5d0*(PL*PTL**G3 + PR*PTR**G3)\n ELSE\n\n! Select Two=Shock Riemann solver with PVRS as estimate\n\n GEL = DSQRT((G5/DL)/(G6*PL + PPV))\n GER = DSQRT((G5/DR)/(G6*PR + PPV))\n PM = (GEL*PL + GER*PR - (UR - UL))/(GEL + GER)\n ENDIF\n ENDIF\n\n RETURN\n END\n\n!********************************************************************************\n!* @brief Evaluate the pressure functions for the given pressure guess and the\n!* given left or right state vCRiables.\n!*\n!* @pCRam f VCRiable to store the pressure function value in.\n!* @pCRam fd VCRiable to store the value of the derivative of the presure\n!* function in.\n!* @pCRam p Current pressure guess.\n!* @pCRam dk Left or right state density.\n!* @pCRam pk Left or right state pressure.\n!* @pCRam ck Left or right state sound speed.\n!********************************************************************************\n SUBROUTINE PREFUN(F, FD, P, DK, PK, CK)\n\n! Purpose: to evaluate the pressure functions FL and FR in the exact Riemann\n! solverPM\n\n\tUSE CONSTANTS\n\tuse gamma_module\n \timplicit none\n\n REAL*8 AK, BK, CK, DK, F, FD, P, PK, PRAT, QRT, &\n AGAMMA\n\n COMMON /GAMMAS/ AGAMMA\n\n IF(P.LE.PK) THEN\n\n! RCRefaction wave\n\n PRAT = P/PK\n F = G4*CK*(PRAT**G1 - 1.0d0)\n FD = (1.0d0/(DK*CK))*PRAT**(-G2)\n\n ELSE\n\n! Shock wave\n AK = G5/DK\n BK = G6*PK\n QRT = DSQRT(AK/(BK + P))\n F = (P - PK)*QRT\n FD = (1.0d0 - 0.5d0*(P - PK)/(BK + P))*QRT\n\n ENDIF\n\n RETURN\n END\n\n!********************************************************************************\n!* @brief Sample the Riemann solution with the given middle state pressure and\n!* fluid velocity at the given point in velocity space.\n!*\n!* @pCRam pm Middle state pressure.\n!* @pCRam um Middle state fluid velocity.\n!* @pCRam s Sampling point in velocity space.\n!* @pCRam d VCRiable to store the resulting density in.\n!* @pCRam u VCRiable to store the resulting fluid velocity in.\n!* @pCRam p VCRiable to store the resulting pressure in.\n!********************************************************************************\n SUBROUTINE SAMPLE(PM, UM, S, D, U, P)\n\n! Purpose to sample the solution throughout the wave pattern. Pressure PM\n! and velocity UM in the StCR Region CRe known. Sampling is performed in\n! terms of the 'speed' S = X/T. Sampled values CRe D, U, P\n\n! Input vCRiables: PM, UM, S, /GAMMAS. /STATES/\n! Output vCRiables: D, U, P\n\tUSE CONSTANTS\n\tuse gamma_module\n \timplicit none\n\n REAL*8 DL, UL, PL, CL, DR, UR, PR, CR, &\n AGAMMA, &\n C, CML, CMR, D, P, PM, PML, PMR, S, &\n SHL, SHR, SL, SR, STL, STR, U, UM\n\n COMMON /GAMMAS/ AGAMMA\n COMMON /STATES/ DL, UL, PL, CL, DR, UR, PR, CR\n\n IF(S.LE.UM)THEN\n\n! Sampling point lies to the left of the contact discontinuity\n\n IF(PM.LE.PL)THEN\n\n! Left rCRefaction\n\n SHL = UL - CL\n\n IF(S.LE.SHL)THEN\n\n! Sampled point is left data state\n\n D = DL\n U = UL\n P = PL\n ELSE\n CML = CL*(PM/PL)**G1\n STL = UM - CML\n\n IF(S.GT.STL)THEN\n\n! Sampled point is StCR Left state\n\n D = DL*(PM/PL)**(1.0d0/AGAMMA)\n U = UM\n P = PM\n ELSE\n\n! Sampled point is inside left fan\n\n U = G5*(CL + G7*UL + S)\n C = G5*(CL + G7*(UL - S))\n D = DL*(C/CL)**G4\n P = PL*(C/CL)**G3\n ENDIF\n ENDIF\n! ENDIF\n ELSE\n\n! Left shock\n\n PML = PM/PL\n SL = UL - CL*DSQRT(G2*PML + G1)\n\n IF(S.LE.SL)THEN\n\n! Sampled point is left data state\n\n D = DL\n U = UL\n P = PL\n\n ELSE\n\n! Sampled point is StCR Left state\n\n D = DL*(PML+G6)/(PML*G6 + 1.0d0)\n U = UM\n P = PM\n ENDIF\n ENDIF\n ELSE\n\n! Sampling point lies to the right of the contact discontinuity\n\n IF(PM.GT.PR)THEN\n\n! Right shock\n\n PMR = PM/PR\n SR = UR + CR*DSQRT(G2*PMR + G1)\n\n IF(S.GE.SR)THEN\n\n! Sampled point is right data state\n\n D = DR\n U = UR\n P = PR\n ELSE\n\n! Sampled point is StCR Right state\n\n D = DR*(PMR + G6)/(PMR*G6 + 1.0d0)\n U = UM\n P = PM\n ENDIF\n ELSE\n\n\n! Right rCRefaction\n\n SHR = UR + CR\n\n IF(S.GE.SHR)THEN\n\n! Sampled point is right data state\n\n D = DR\n U = UR\n P = PR\n ELSE\n CMR = CR*(PM/PR)**G1\n STR = UM + CMR\n\n IF(S.LE.STR)THEN\n\n! Sampled point is StCR Right state\n\n D = DR*(PM/PR)**(1.0d0/AGAMMA)\n U = UM\n P = PM\n ELSE\n\n! Sampled point is inside left fan\n\n U=G5*(-CR + G7*UR + S)\n C = G5*(CR - G7*(UR-S))\n D = DR*(C/CR)**G4\n P = PR*(C/CR)**G3\n ENDIF\n ENDIF\n ENDIF\n ENDIF\n\n RETURN\nEND\n\n! ##############################################################################\n ! @brief Vacuum Riemann solver.\n!\n ! This solver is called when one or both states have a zero density, or when\n ! the vacuum generation condition is satisfied (meaning vacuum is generated\n ! in the middle state, although strictly speaking there is no \"middle\"\n ! state if vacuum is involved).\n!\n ! @pCRam rhoL Density of the left state.\n ! @pCRam uL Velocity of the left state.\n ! @pCRam PL Pressure of the left state.\n ! @pCRam CL Soundspeed of the left state.\n ! @pCRam rhoR Density of the right state.\n ! @pCRam uR Velocity of the right state.\n ! @pCRam PR Pressure of the right state.\n ! @pCRam CR Soundspeed of the right state.\n ! @pCRam x_over_t Point in velocity space where we want to sample the solution.\n ! @return Density, velocity and pressure solution, and a flag indicating\n ! wether the left state (-1), the right state (1), or a vacuum state (0) was\n ! sampled.\n! ##############################################################################\nsubroutine solve_vacuum(rhoL, uL, PL, CL, rhoR, uR, PR, CR, x_over_t, rhosol, usol, Psol, flag)\n\n\tUSE CONSTANTS\n\tuse gamma_module\n \timplicit none\n\n\t\tReal*8,intent(in) :: rhoL,uL,PL,CL\n\t\tReal*8,intent(in) :: rhoR,uR,PR,CR\n\t\tReal*8,intent(in) :: x_over_t \n\t \tReal*8,intent(out) :: rhosol, usol, Psol\n\t\tInteger,intent(out) :: flag\n\t\tReal*8 :: SR,SL,Base\n\n! if both states are vacuum, the solution is also vacuum\n\tIf ((rhoL == 0.d0) .and. (rhoR == 0.d0)) then\n \t\tRhoSol= 0.d0\n\t\tuSol= 0.d0\n\t\tPSol= 0.d0\n\t\tflag=0\n\n\telse if (rhoR == 0.d0) then \n\t\t! vacuum right state\n\t\tcall sample_right_vacuum(rhoL, uL, PL, CL, x_over_t, rhosol, usol, Psol, flag)\n\telse if (rhoL == 0.d0) then\n\t\t! vacuum left state\n\t\tcall sample_left_vacuum(rhoR, uR, PR, CR, x_over_t, rhosol, usol, Psol, flag)\n\telse\n\t\t! vacuum \"middle\" state\n\t\tcall sample_vacuum_generation(rhoL, uL, PL, CL, rhoR, uR, PR, CR, x_over_t, rhosol, usol, Psol, flag)\n\tendif\n\nend subroutine solve_vacuum\n\n! ##############################################################################\n! ! @brief Sample the vacuum Riemann problem if the right state is a vacuum.\n ! @pCRam rhoL Density of the left state.\n ! @pCRam uL Velocity of the left state.\n ! @pCRam PL Pressure of the left state.\n ! @pCRam CL Soundspeed of the left state.\n ! @pCRam x_over_t Point in velocity space where we want to sample the solution.\n ! @return Density, velocity and pressure solution, and a flag indicating\n ! wether the left state (-1), the right state (1), or a vacuum state (0) was\n ! sampled.\n ! ##############################################################################\nsubroutine sample_right_vacuum(rhoL, uL, PL, CL, x_over_t, rhosol, usol, Psol, flag)\n\tUSE CONSTANTS\n\tuse gamma_module\n \timplicit none\n\n\t\tReal*8,intent(in) :: rhoL,uL,PL,CL,x_over_t \n\t \tReal*8,intent(out) :: rhosol, usol, Psol\n\t\tInteger,intent(out) :: flag\n\t\tReal*8 :: SL,Base\n\n\tIf ((uL - CL).lt.x_over_t) then\n\n\t! vacuum regime\n\t!get the vacuum rCRefaction wave speed\n\t\tSL = uL + G4 * CL\n\n \t\tIf (SL .gt. x_over_t) then\n\t! rCRefaction wave regime\n\t! vCRiable used twice below\n\t\t\tbase = G5 + G6* (uL - x_over_t) / CL\n\n\t\t\trhosol = rhoL * base**G4\n\t\t\tusol = G5 * (CL + (G7 * uL) + x_over_t)\n\t\t\tPsol = PL * base**G3\n\t\t\tflag = -1\n \t\telse\n\t\t\t! vacuum\n\t\t\trhosol = 0.d0\n\t\t\tusol = 0.d0\n\t\t\tPsol = 0.d0\n\t\t\tflag = 0\n\t\tendif\n\telse\n\t\t! left state regime\n \t\trhosol = rhoL\n \t\tusol = uL\n \t\tPsol = PL\n \t\tflag = -1\n\tendif\n\nend subroutine sample_right_vacuum\n!##############################################################################\n ! @brief Sample the vacuum Riemann problem if the left state is a vacuum.\n!\n ! @pCRam rhoR Density of the right state.\n ! @pCRam uR Velocity of the right state.\n ! @pCRam PR Pressure of the right state.\n ! @pCRam CR Soundspeed of the right state.\n ! @pCRam x_over_t Point in velocity space where we want to sample the solution.\n ! @return Density, velocity and pressure solution, and a flag indicating\n ! wether the left state (-1), the right state (1), or a vacuum state (0) was\n ! sampled.\n! ##############################################################################\nsubroutine sample_left_vacuum(rhoR, uR, PR, CR, x_over_t, rhosol, usol, Psol, flag)\n\tUSE CONSTANTS\n\tuse gamma_module\n \timplicit none\n\n\t\tReal*8,intent(in) :: rhoR,uR,PR,CR,x_over_t \n\t \tReal*8,intent(out) :: rhosol, usol, Psol\n\t\tInteger,intent(out) :: flag\n\t\tReal*8 :: SR,Base\n\n\tIf (x_over_t .lt. (uR + CR)) then\n\t! vacuum regime\n\t! get the vacuum rarefaction wave speed\n\t\tSR = uR - G4 * CR\n\n\t\tif (SR .lt. x_over_t) then\n\t\t! rarefaction wave regime\n\t\t\t! vCRiable used twice below\n\t\t\tbase = G5 - G6* (uR - x_over_t) / CR\n\t\t\trhosol = rhoR * base**G4\n\t\t\tusol = G5 * (-1.d0*CR + G4 * uR + x_over_t)\n\t\t\tPsol = PR * base**G3\n\t\t\tflag = 1\n\t\telse\n\t\t! vacuum\n\t\t\trhosol = 0.d0\n\t\t\tusol = 0.d0\n\t\t\tPsol = 0.d0\n\t\t\tflag = 0\n\t\tendif\n\n\telse\n\t! right state regime\n\t rhosol = rhoR\n\t usol = uR\n\t Psol = PR\n\t flag = 1\n\tendif\n\nend subroutine sample_left_vacuum\n\n! ##############################################################################\n ! @brief Sample the vacuum Riemann problem in the case vacuum is generated in\n ! between the left and right state.\n!\n ! @pCRam rhoL Density of the left state.\n ! @pCRam uL Velocity of the left state.\n ! @pCRam PL Pressure of the left state.\n ! @pCRam CL Soundspeed of the left state.\n ! @pCRam rhoR Density of the right state.\n ! @pCRam uR Velocity of the right state.\n ! @pCRam PR Pressure of the right state.\n ! @pCRam CR Soundspeed of the right state.\n ! @pCRam x_over_t Point in velocity space where we want to sample the solution.\n ! @return Density, velocity and pressure solution, and a flag indicating\n ! wether the left state (-1), the right state (1), or a vacuum state (0) was\n ! sampled.\n! ##############################################################################\nsubroutine sample_vacuum_generation(rhoL, uL, PL, CL, rhoR, uR, PR, CR, x_over_t, rhosol, usol, Psol, flag)\n\n\tUSE CONSTANTS\n\tuse gamma_module\n \timplicit none\n\n\t\tReal*8,intent(in) :: rhoL,uL,PL,CL\n\t\tReal*8,intent(in) :: rhoR,uR,PR,CR\n\t\tReal*8,intent(in) :: x_over_t \n\t \tReal*8,intent(out) :: rhosol, usol, Psol\n\t\tInteger,intent(out) :: flag\n\t\tReal*8 :: SR,SL,Base\n\n! get the speeds of the left and right rCRefaction waves\n SR = uR - G4 * CR\n SL = uL + G4 * CL\n\n\tIf ((SR .gt. x_over_t) .and. (SL .lt. x_over_t)) then\n\t\t! vacuum\n\t rhosol = 0.d0\n\t usol = 0.d0\n\t Psol = 0.d0\n\t flag = 0\n\n\telse if (SL .lt. x_over_t) then\n\t! right state\n\t\tIf (x_over_t .lt. (uR + CR)) then\n\t\t! right rCRefaction wave regime\n\t\t! vCRiable used twice below\n\t\t\tbase = G5 - G6* (uR - x_over_t) / CR\n\t\t\trhosol = rhoR * base**G4\n\t\t\tusol = G5 * (-1.d0*CR + G4 * uR + x_over_t)\n\t\t\tPsol = PR * base**G3\n \t\telse\n\t\t! right state regime\n\t\t\trhosol = rhoR\n\t\t\tusol = uR\n\t\t\tPsol = PR\n\t\t\tflag = 1\n\t\tendif\n\telse\n\t! left state\n\t\tIf (x_over_t .gt. (uL - CL)) then\n\t\t! left rCRefaction wave regime\n\t\t! vCRiable used twice below\n\t\t\tbase = G5 + G6* (uL - x_over_t) / CL\n\t\t\trhosol = rhoL * base**G4\n\t\t\tusol = G5 * (CL + G4 * uL + x_over_t)\n\t\t\tPsol = PL * base**G3\n \telse\n\t\t\t! left state regime\n\t\t\trhosol = rhoL\n\t\t\tusol = uL\n\t\t\tPsol = PL\n\t\t\tflag = -1\n\t\tendif\n\tendif\n\nEND subroutine sample_vacuum_generation\n", "meta": {"hexsha": "3ac580aa973f8544f6dc1ad946af327f2c30320e", "size": 22692, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Riemann_Solver/riemann.f90", "max_stars_repo_name": "ATHannington/BAFFLE", "max_stars_repo_head_hexsha": "99f3198fa4763402c8572bc146240f59c17263ab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Riemann_Solver/riemann.f90", "max_issues_repo_name": "ATHannington/BAFFLE", "max_issues_repo_head_hexsha": "99f3198fa4763402c8572bc146240f59c17263ab", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Riemann_Solver/riemann.f90", "max_forks_repo_name": "ATHannington/BAFFLE", "max_forks_repo_head_hexsha": "99f3198fa4763402c8572bc146240f59c17263ab", "max_forks_repo_licenses": ["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.0556291391, "max_line_length": 157, "alphanum_fraction": 0.5453023092, "num_tokens": 6932, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430520409024, "lm_q2_score": 0.7905303186696747, "lm_q1q2_score": 0.6570437817899807}} {"text": "!*********************************************************\n!>\n! Sorting Routines\n\nmodule sorting\n implicit none\n\n private\n integer, parameter :: dp = kind(0.d0)\n\n public :: swap\n public :: qsort\n\n interface swap\n module procedure swap_i, swap_r, swap_d, swap_Cr, swap_Cd\n end interface\n\n interface qsort\n module procedure qsort_i, qsort_r, qsort_d\n end interface\n\ncontains\n\n subroutine swap_i(a,b,condition)\n implicit none\n integer :: a, b, aDum, bDum\n logical :: ifSwap\n logical, optional :: condition\n if(present(condition)) then\n ifSwap = condition\n else\n ifSwap = .true.\n end if\n if(ifSwap) then\n aDum = a; bDum = b\n a = bDum; b = aDum\n end if\n end subroutine\n\n subroutine swap_r(a,b,condition)\n implicit none\n real :: a, b, aDum, bDum\n logical :: ifSwap\n logical, optional :: condition\n if(present(condition)) then\n ifSwap = condition\n else\n ifSwap = .true.\n end if\n if(ifSwap) then\n aDum = a; bDum = b\n a = bDum; b = aDum\n end if\n end subroutine\n\n subroutine swap_d(a,b,condition)\n implicit none\n real(dp) :: a, b, aDum, bDum\n logical :: ifSwap\n logical, optional :: condition\n if(present(condition)) then\n ifSwap = condition\n else\n ifSwap = .true.\n end if\n if(ifSwap) then\n aDum = a; bDum = b\n a = bDum; b = aDum\n end if\n end subroutine\n\n subroutine swap_Cr(a,b,condition)\n implicit none\n complex :: a, b, aDum, bDum\n logical :: ifSwap\n logical, optional :: condition\n if(present(condition)) then\n ifSwap = condition\n else\n ifSwap = .true.\n end if\n if(ifSwap) then\n aDum = a; bDum = b\n a = bDum; b = aDum\n end if\n end subroutine\n\n subroutine swap_Cd(a,b,condition)\n implicit none\n complex(dp) :: a, b, aDum, bDum\n logical :: ifSwap\n logical, optional :: condition\n if(present(condition)) then\n ifSwap = condition\n else\n ifSwap = .true.\n end if\n if(ifSwap) then\n aDum = a; bDum = b\n a = bDum; b = aDum\n end if\n end subroutine\n\n subroutine qsort_i(array)\n implicit none\n integer :: k, n, left, right, marker\n integer :: pivot, array(:)\n n = size(array,1)\n if(n>1) then\n k = (n/2)\n pivot = array(k)\n left = 0\n right = n+1\n do while(left1) then\n k = (n/2)\n pivot = array(k)\n left = 0\n right = n+1\n do while(left1) then\n k = (n/2)\n pivot = array(k)\n left = 0\n right = n+1\n do while(left c_1 , c_0_Rsp => c_0 !!((02-A-PAR_Constants_Rsp.f90))\nUSE PAR_Constants_Rdp,ONLY: c_1_Rdp => c_1 , c_0_Rdp => c_0 !!((02-A-PAR_Constants_Rdp.f90))\n\n!!### EXTERNAL PROCEDURES\nUSE FUN_xyDIRECTION ,ONLY: xyDIRECTION_PP !!((04-B-FUN_xyDIRECTION.f90))\nUSE FUN_xyANGLE ,ONLY: xyANGLE_UU !!((05-B-FUN_xyANGLE.f90))\nUSE FUN_xyROTATE ,ONLY: xyROTATE_Px !!((05-B-FUN_xyROTATE.f90))\nUSE FUN_xyTRANSLATE ,ONLY: xyTRANSLATE_Px !!((05-B-FUN_xyTRANSLATE.f90))\nUSE FUN_xyCOUNTERCLOCKWISE,ONLY: xyCOUNTERCLOCKWISE_Cn !!((06-B-FUN_xyCOUNTERCLOCKWISE.f90))\n\n!!### DEFAULT IMPLICIT\nIMPLICIT NONE\n\n!!### DEFAULT ACCESS\nPRIVATE\n\n!!### PROCEDURE OVERLOADING\nINTERFACE xyCONVEXHULL_Px\n MODULE PROCEDURE xyCONVEXHULL_Px_Rsp\n MODULE PROCEDURE xyCONVEXHULL_Px_Rdp\nENDINTERFACE\n\n!!### PUBLIC ACCESS LIST\nPUBLIC :: xyCONVEXHULL_Px\n\n\n!!### MODULE PROCEDURES\nCONTAINS\n\n\n!!### PURE FUNCTION: xyCONVEXHULL_Px_Rsp\nPURE FUNCTION xyCONVEXHULL_Px_Rsp( N , Px ) RESULT(order_cvh)\n!!#### LOCAL KINDS\nINTEGER ,PARAMETER :: KIND_R = KIND_Rsp\n!!#### LOCAL PARAMETERS\nREAL(KIND_R),PARAMETER :: c_1 = c_1_Rsp\nREAL(KIND_R),PARAMETER :: c_0 = c_0_Rsp\nINCLUDE \"07-B-FUN_xyCONVEXHULL_Px.f90.hdr\"\n!!--begin--\nINCLUDE \"07-B-FUN_xyCONVEXHULL_Px.f90.bdy\"\n!!--end--\nEND FUNCTION\n\n\n!!### PURE FUNCTION: xyCONVEXHULL_Px_Rdp\nPURE FUNCTION xyCONVEXHULL_Px_Rdp( N , Px ) RESULT(order_cvh)\n!!#### LOCAL KINDS\nINTEGER ,PARAMETER :: KIND_R = KIND_Rdp\n!!#### LOCAL PARAMETERS\nREAL(KIND_R),PARAMETER :: c_1 = c_1_Rdp\nREAL(KIND_R),PARAMETER :: c_0 = c_0_Rdp\nINCLUDE \"07-B-FUN_xyCONVEXHULL_Px.f90.hdr\"\n!!--begin--\nINCLUDE \"07-B-FUN_xyCONVEXHULL_Px.f90.bdy\"\n!!--end--\nEND FUNCTION\n\n\nEND MODULE\n", "meta": {"hexsha": "3ad27392175309fca1d0923db2b9657fbe0d619b", "size": 2661, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/07-B-FUN_xyCONVEXHULL.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/07-B-FUN_xyCONVEXHULL.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/07-B-FUN_xyCONVEXHULL.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": 29.2417582418, "max_line_length": 97, "alphanum_fraction": 0.6711762495, "num_tokens": 888, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357735451834, "lm_q2_score": 0.757794360334681, "lm_q1q2_score": 0.6570348194009575}} {"text": "program main\n use forlab, only: empty, disp, operator(.x.)\n implicit none\n real, dimension(:, :), allocatable :: x_sp, y_sp\n real(8), dimension(:, :), allocatable :: x_dp, y_dp\n real(16), dimension(:, :), allocatable :: x_qp, y_qp\n\n x_sp = empty(2, 2); x_dp = empty(2, 2); x_qp = empty(2, 2)\n y_sp = empty(2, 2); y_dp = empty(2, 2); y_qp = empty(2, 2)\n\n x_sp = 1.; x_dp = 1.; x_qp = 1.\n y_sp = 2.; y_dp = 2.; y_qp = 2.\n\n call disp('----------------------------')\n call disp(x_sp .x. y_sp, 'x .x. y SP\u2728:')\n call disp(x_dp .x. y_dp, 'x .x. y DP\u2728:')\n call disp(x_qp .x. y_qp, 'x .x. y QP\u2728:')\n \n \nend program", "meta": {"hexsha": "9f62ab52646fb6f5eb6be48a5a8decf23dd01a4b", "size": 649, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/operator_x.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": "example/operator_x.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": "example/operator_x.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": 32.45, "max_line_length": 62, "alphanum_fraction": 0.5130970724, "num_tokens": 247, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357529306639, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.657034818007395}} {"text": "MODULE m_eigen\n\n ! Dependencies =============================================================\n USE mpi ! Message passing interface (MPI) module\n ! ==========================================================================\n\n IMPLICIT NONE\n\n CONTAINS \n\n SUBROUTINE s_eigs(Amat,Eigs,EVec,N)\n\n REAL(KIND(0d0)), TARGET, DIMENSION(:,:), INTENT(IN) :: Amat\n REAL(KIND(0d0)), TARGET, DIMENSION(:), INTENT(OUT) :: EVec, Eigs\n INTEGER, INTENT(IN) :: N\n\n REAL(KIND(0d0)), ALLOCATABLE, DIMENSION(:,:) :: VR, A\n REAL(KIND(0d0)), ALLOCATABLE, DIMENSION(:) :: WR, WI, Work\n REAL(KIND(0d0)) :: DUMMY(1,1), Eigmax\n\n INTEGER :: NB2, NMAX, LDA, LDVR, LWORK, INFO,LWKOPT\n INTEGER :: i, j\n INTEGER, PARAMETER :: LWMAX = 1000\n\n EXTERNAL DGEEV\n INTRINSIC DCMPLX\n\n Nb2=64\n LDA=N\n LDVR=N\n LWORK=LWMAX\n\n ALLOCATE( VR(LDVR,N), A(N,N) )\n ALLOCATE( WORK(LWORK), WR(N), WI(N) )\n\n A = Amat\n\n PRINT*, 'N', N\n\n CALL DGEEV('N','V',N,A,LDA,WR,WI,DUMMY,1,VR,LDVR,WORK,LWORK,INFO)\n LWKOPT = WORK(1)\n\n IF (INFO/=0) THEN\n PRINT*, 'Failure in DGEEV. INFO = ', INFO\n END IF\n\n EVec(1:N) = VR(1,N:1:-1)\n Eigs = WR(N:1:-1)\n\n\n ! ELSE\n ! EigMax = 0d0\n ! DO j = 1,N\n ! IF( WR(j) > EigMax ) THEN\n ! EigMax = WR(j)\n ! ! EVec(:) = VR(j,:)\n ! EVec(:) = VR(:,j)\n ! END IF\n ! END DO\n ! END IF\n\n ! PRINT*, 'eigenvectors'\n ! PRINT*, VR(1,:)\n ! PRINT*, VR(2,:)\n ! PRINT*, VR(3,:)\n\n\n ! print*, 'in eigs'\n ! print*, 'max eig', Eigmax\n ! print*, 'max loc', MAXLOC(WR(:),DIM=1)\n ! print*, 'real eigs: ', WR(:)\n ! print*, 'eigvec associated with largeest eigenvalue', EVec(1:N)\n\n END SUBROUTINE s_eigs\n\nEND MODULE m_eigen\n", "meta": {"hexsha": "88b54c68042ce3f64aba9db7be4c9a7403ef2811", "size": 2195, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/simulation_code/m_eigen.f90", "max_stars_repo_name": "ComputationalFlowPhysics/MFC-Caltech", "max_stars_repo_head_hexsha": "daf9f317b30961b7d7842b0b8cfb0fc0c20e355e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2019-07-25T08:37:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-26T11:30:31.000Z", "max_issues_repo_path": "src/simulation_code/m_eigen.f90", "max_issues_repo_name": "zhangzhg0508/MFC", "max_issues_repo_head_hexsha": "1bace9206474f8eb4557ba33c6ed680222e78c80", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-09-10T01:01:50.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-10T03:04:08.000Z", "max_forks_repo_path": "src/simulation_code/m_eigen.f90", "max_forks_repo_name": "zhangzhg0508/MFC", "max_forks_repo_head_hexsha": "1bace9206474f8eb4557ba33c6ed680222e78c80", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 21, "max_forks_repo_forks_event_min_datetime": "2019-07-25T07:57:26.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-02T03:05:53.000Z", "avg_line_length": 28.5064935065, "max_line_length": 80, "alphanum_fraction": 0.393166287, "num_tokens": 626, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392939666335, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6569897266610909}} {"text": "module compute\n use misc, only : meanval\n\n implicit none\n\n private\n\n integer :: opt_lwork = -1\n\n public :: compute_inertia_tensor, correct_positions\n\ncontains\n ! This routine shall be used with positions between 0 and 1. If an halo is close\n ! to the border of the box, it may have positions ~0 and others ~1. This problem\n ! is solved by the routine and the position are changed\n subroutine compute_inertia_tensor(mass, pos, I_t)\n real(kind=8), intent(in), dimension(:) :: mass\n real(kind=8), intent(inout), dimension(:, :) :: pos\n\n real(kind=8), intent(out), dimension(3, 3) :: I_t\n\n real(kind=8), dimension(size(pos, 1)) :: tmp_mean\n real(kind=8), dimension(size(pos, 1), size(pos, 2)) :: corr_pos\n real(kind=8) :: mtot, tmp\n\n integer :: i, j\n integer :: ndim, nparts\n\n ndim = size(pos, 1)\n nparts = size(pos, 2)\n\n mtot = sum(mass)\n\n call meanval(pos, tmp_mean, ndim, nparts)\n do i = 1, ndim\n corr_pos(i, :) = pos(i, :) - tmp_mean(i)\n end do\n\n I_t = 0d0\n\n !-------------------------------------\n ! Compute the tensor\n !-------------------------------------\n do i = 1, ndim\n do j = i, ndim\n tmp = sum(mass(:)*corr_pos(i, :)*corr_pos(j, :)) / mtot\n I_t(i, j) = tmp + I_t(i, j)\n I_t(j, i) = tmp + I_t(i, j)\n end do\n end do\n\n\n ! call dsytrd('U', 3, I_t, 3, I_t_diag, E, tau, worpart, opt_lwork, info)\n ! if (info == 0) then\n ! opt_lwork = int(work(1))\n ! end if\n\n end subroutine compute_inertia_tensor\n\n subroutine correct_positions (pos)\n real(kind=8), intent(inout), dimension(:, :) :: pos\n\n real(kind=8), dimension(size(pos, 1)) :: span\n integer :: ndim, nparts, part, dim\n\n ndim = size(pos, 1)\n nparts = size(pos, 2)\n\n span = maxval(pos, 2) - minval(pos, 2)\n\n !-------------------------------------\n ! If the particles have a separation > 0.5\n ! then shift 'em\n !-------------------------------------\n do dim = 1, 3\n if (span(dim) > 0.5) then\n do part = 1, nparts\n if (pos(dim, part) > 0.5) then\n pos(dim, part) = pos(dim, part) - 1d0\n end if\n end do\n end if\n end do\n end subroutine correct_positions\n\nend module compute\n", "meta": {"hexsha": "527561da324302662e06390b140c8f55b26eb7a2", "size": 2267, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tools/compute.f90", "max_stars_repo_name": "cphyc/cosmo_z17to0", "max_stars_repo_head_hexsha": "20fb1bbdfff79b3575b70be6413d1f3bb5466165", "max_stars_repo_licenses": ["CC-BY-4.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": "tools/compute.f90", "max_issues_repo_name": "cphyc/cosmo_z17to0", "max_issues_repo_head_hexsha": "20fb1bbdfff79b3575b70be6413d1f3bb5466165", "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": "tools/compute.f90", "max_forks_repo_name": "cphyc/cosmo_z17to0", "max_forks_repo_head_hexsha": "20fb1bbdfff79b3575b70be6413d1f3bb5466165", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.0574712644, "max_line_length": 82, "alphanum_fraction": 0.5359505955, "num_tokens": 698, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460332, "lm_q2_score": 0.743168019989179, "lm_q1q2_score": 0.6569897226078555}} {"text": " !***************************************************************************************************\n \tmodule evolve_routines\n !***************************************************************************************************\n \timplicit none\n \t\n \t!the target string:\n \tcharacter(len=*),parameter :: targ = 'METHINKS IT IS LIKE A WEASEL'\n \t\n \tcontains\n !***************************************************************************************************\n \t\n !********************************************************************\n \tpure elemental function fitness(member) result(n)\n !********************************************************************\n ! The fitness function. The lower the value, the better the match.\n ! It is zero if they are identical.\n !********************************************************************\n \t\n \timplicit none\n \tinteger :: n\n \tcharacter(len=*),intent(in) :: member\n \t\n \tinteger :: i\n \t\n \tn=0\n \tdo i=1,len(targ)\n \t\tn = n + abs( ichar(targ(i:i)) - ichar(member(i:i)) )\n \tend do\n \t\n !********************************************************************\n \tend function fitness\n !********************************************************************\n \t\n !********************************************************************\n \tpure elemental subroutine mutate(member,factor)\n !********************************************************************\n ! mutate a member of the population.\n !********************************************************************\n \t\n \timplicit none\n \tcharacter(len=*),intent(inout) :: member !population member\n \treal,intent(in) :: factor !mutation factor\n \t\n \tinteger,parameter :: n_chars = 27\t!number of characters in set\n \tcharacter(len=n_chars),parameter :: chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ '\n \t\n \treal :: rnd_val\n \tinteger :: i,j,n\n \t\n \tn = len(member)\n \t\t\n \tdo i=1,n\n \t\trnd_val = rand()\n \t\tif (rnd_val<=factor) then !mutate this element\t\t\t\n \t\t\trnd_val = rand()\n \t\t\tj = int(rnd_val*n_chars)+1 !an integer between 1 and n_chars\n \t\t\tmember(i:i) = chars(j:j)\n \t\tend if\n \tend do\n \t\n !********************************************************************\n\tend subroutine mutate\n !********************************************************************\n\n !***************************************************************************************************\n \tend module evolve_routines\n !***************************************************************************************************\n\n !***************************************************************************************************\n \tprogram evolve\n !***************************************************************************************************\n ! The main program\n !***************************************************************************************************\n \tuse evolve_routines\n \t\n \timplicit none\n \t\n \t!Tuning parameters:\n \tinteger,parameter :: seed = 12345 !random number generator seed\n \tinteger,parameter :: max_iter = 10000 !maximum number of iterations\n \tinteger,parameter :: population_size = 200 !size of the population\n \treal,parameter :: factor = 0.04 ![0,1] mutation factor\n \tinteger,parameter :: iprint = 5 !print every iprint iterations\n \t\n \t!local variables:\n \tinteger :: i,iter\n \tinteger,dimension(1) :: i_best\n \tcharacter(len=len(targ)),dimension(population_size) :: population\n \t\n \t!initialize random number generator:\n \tcall srand(seed)\n \t\n \t!create initial population:\n \t! [the first element of the population will hold the best member]\n \tpopulation(1) = 'PACQXJB CQPWEYKSVDCIOUPKUOJY' !initial guess\n \titer=0\n \t\t\n \twrite(*,'(A10,A30,A10)') 'iter','best','fitness'\n \twrite(*,'(I10,A30,I10)') iter,population(1),fitness(population(1))\n \t\t\n \tdo\n \t\n \t\titer = iter + 1 !iteration counter\n \t\t\n \t\t!write the iteration:\n \t\tif (mod(iter,iprint)==0) write(*,'(I10,A30,I10)') iter,population(1),fitness(population(1))\n\t\t\n \t\t!check exit conditions:\n \t\tif ( iter>max_iter .or. fitness(population(1))==0 ) exit\n \t\n \t\t!copy best member and mutate:\n \t\tpopulation = population(1)\t\n \t\tdo i=2,population_size\n \t\t\tcall mutate(population(i),factor)\t\n \t\tend do\n \t\n \t\t!select the new best population member:\n \t\t! [the best has the lowest value]\n \t\ti_best = minloc(fitness(population))\n \t\tpopulation(1) = population(i_best(1))\n \t\t \t\n \tend do\n \t\n \t!write the last iteration:\n \tif (mod(iter,iprint)/=0) write(*,'(I10,A30,I10)') iter,population(1),fitness(population(1))\n \t \t\n \tif (iter>max_iter) then\n \t\twrite(*,*) 'No solution found.'\n \telse\n \t\twrite(*,*) 'Solution found.'\n \tend if\n \t\n !***************************************************************************************************\n \tend program evolve\n !***************************************************************************************************\n", "meta": {"hexsha": "e16722f6522f2ec0a85255076e529fba4218df33", "size": 4815, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Evolutionary-algorithm/Fortran/evolutionary-algorithm-1.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Evolutionary-algorithm/Fortran/evolutionary-algorithm-1.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Evolutionary-algorithm/Fortran/evolutionary-algorithm-1.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 35.4044117647, "max_line_length": 101, "alphanum_fraction": 0.4205607477, "num_tokens": 1002, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392848011833, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6569897198496214}} {"text": "c function pbinom.f\nc\nc source\nc Bevington, page 31.\nc\nc purpose\nc evaluate binomial probability coefficient\nc\nc usage\nc result = pbinom (nobs, ntotal, prob)\nc\nc description of parameters\nc nobs - number of items observed\nc ntotal - total number of items\nc prob - probability of observing each item\nc\nc subroutines and function subprograms required\nc factor (n)\nc calculates n factorial for integers\nc\n function pbinom (nobs,ntotal,prob)\n1 notobs=ntotal-nobs\n2 pbinom=factor(ntotal)/(factor(nobs)*factor(notobs))*\n * (prob**nobs)*(1.-prob)**notobs\n return\n end\n", "meta": {"hexsha": "325f6f70f4bbb98f3af03f286ac67ed58b747e60", "size": 617, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iraf.v2161/math/bevington/pbinom.f", "max_stars_repo_name": "ysBach/irafdocgen", "max_stars_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:19:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T16:48:42.000Z", "max_issues_repo_path": "math/bevington/pbinom.f", "max_issues_repo_name": "kirxkirx/iraf", "max_issues_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-30T13:48:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-02T19:40:25.000Z", "max_forks_repo_path": "math/bevington/pbinom.f", "max_forks_repo_name": "kirxkirx/iraf", "max_forks_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.8518518519, "max_line_length": 58, "alphanum_fraction": 0.698541329, "num_tokens": 188, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8840392939666335, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6569897166036428}} {"text": "submodule (interpolation) interpolation2d\n\nimplicit none (type, external)\n\ncontains\n\nmodule procedure interp2\n\n!! A 2D BILINEAR INTERPOLATION FUNCTION. THIS VERSION ASSUMES\n!! THAT THE LIST OF OUTPUT POINTS IS A 'FLAT LIST' RATHER THAN\n!! DESCRIPTIVE OF A 2D MESHGRID.\n\n\nreal(wp) :: fx1ix2prev, fx1ix2next !function estimates at x1i point vs. at x2 interfaces\nreal(wp) :: slope\n\ninteger :: lx1,lx2,lxi,ix1,ix2,ixi\ninteger :: ix10,ix1fin,ix20,ix2fin\n\n\n\nlx1=size(x1,1)\nlx2=size(x2,1)\nlxi=size(x1i,1) !only one size since this a flat list of grid points\n\n\ndo ixi=1,lxi\n !find the x1 'bin' for this point; i.e. find ix1 s.t. xi(ix1i) is between x(ix1-1) and x(ix1)\n ix10=1\n ix1=lx1/2\n ix1fin=lx1\n if (x1i(ixi)>=x1(1) .and. x1i(ixi)<=x1(lx1)) then !in bounds\n do while(.not.(x1i(ixi)>=x1(ix1-1) .and. x1i(ixi)<=x1(ix1))) !keep going until we are in the interval we want\n if (x1i(ixi)>=x1(ix10) .and. x1i(ixi)<=x1(ix1)) then !left half (correct guess)\n ix1fin=ix1\n else !wrong take the \"right\" half (har har)\n ix10=ix1\n end if\n ix1=(ix1fin+ix10)/2\n if (ix10==ix1) then\n ix1=lx1\n end if\n end do\n else if (x1i(ixi)=x2(1) .and. x2i(ixi)<=x2(lx2)) then !in bounds\n do while(.not.(x2i(ixi)>=x2(ix2-1) .and. x2i(ixi)<=x2(ix2))) !keep going until we are in the interval we want\n if (x2i(ixi)>=x2(ix20) .and. x2i(ixi)<=x2(ix2)) then !left half (correct guess)\n ix2fin=ix2\n else !wrong take the \"right\" half (har har)\n ix20=ix2\n end if\n ix2=(ix2fin+ix20)/2\n if (ix20==ix2) then\n ix2=lx2\n end if\n end do\n else if (x2i(ixi)1 .and. ix1<=lx1 .and. ix2>1 .and. ix2<=lx2) then !interpolation\n !first the \"prev\" x2 value\n slope=(f(ix1,ix2-1)-f(ix1-1,ix2-1))/(x1(ix1)-x1(ix1-1))\n fx1ix2prev=f(ix1-1,ix2-1)+slope*(x1i(ixi)-x1(ix1-1))\n\n !now the \"next\" x2 value\n slope=(f(ix1,ix2)-f(ix1-1,ix2))/(x1(ix1)-x1(ix1-1))\n fx1ix2next=f(ix1-1,ix2)+slope*(x1i(ixi)-x1(ix1-1))\n\n !finally an interpolation in x2 to finish things off\n slope=(fx1ix2next-fx1ix2prev)/(x2(ix2)-x2(ix2-1))\n interp2(ixi)=fx1ix2prev+slope*(x2i(ixi)-x2(ix2-1))\n else\n interp2(ixi)=0\n end if\nend do\n\n\n!THERE IS SOME ISSUE WITH POINTS OUTSIDE INTERPOLANT DOMAIN - THIS IS A WORKAROUND UNTIL I CAN PIN DOWN THE EXACT PROBLEM\ndo ixi=1,lxi\nif(x1i(ixi)x1(lx1) .or. x2i(ixi)x2(lx2)) then\n interp2(ixi)=0\nend if\nend do\n\nend procedure interp2\n\n\nmodule procedure interp2_plaid\n\n!! A 2D BILINEAR INTERPOLATION FUNCTION. THIS VERSION ASSUMES\n!! A PLAID INTERPRETATION OF THE OUTPUT POINTS (I.E. THAT THEY\n!! FORM A 2D MESHGRID RATHER THAN A FLAT LIST OF POINTS.\n!!\n!! MZ - this may not be used at all anymore, but kept\n!! for potential future use???\n\nreal(wp) :: fx1ix2prev, fx1ix2next !function estimates at x1i point vs. at x2 interfaces\nreal(wp) :: slope\n\ninteger :: lx1,lx2,lx1i,lx2i,ix1,ix2,ix1i,ix2i\nreal(wp), dimension(1:size(x1i)) :: slicex1i\nreal(wp), dimension(1:size(x2i)) :: slicex2i\n\n\nlx1=size(x1,1)\nlx2=size(x2,1)\nlx1i=size(x1i,1)\nlx2i=size(x2i,1)\n\n\ndo ix2i=1,lx2i\n do ix1i=1,lx1i\n !find the x1 'bin' for this point; i.e. find ix1 s.t. xi(ix1i) is between x(ix1-1) and x(ix1)\n ix1=1\n do while(x1i(ix1i)>x1(ix1) .and. ix1<=lx1)\n ix1=ix1+1\n end do\n\n\n !find the x2 'bin' for this point; i.e. find ix2 s.t. x2i(ix2i) is between x2(ix2-1) and x2(ix2)\n ix2=1\n do while(x2i(ix2i)>x2(ix2) .and. ix2<=lx2)\n ix2=ix2+1\n end do\n\n\n !execute interpolations in x1 for fixed values of x2 at this point\n if (ix1>1 .and. ix1<=lx1 .and. ix2>1 .and. ix2<=lx2) then !interpolation\n !first the \"prev\" x2 value\n slope=(f(ix1,ix2-1)-f(ix1-1,ix2-1))/(x1(ix1)-x1(ix1-1))\n fx1ix2prev=f(ix1-1,ix2-1)+slope*(x1i(ix1i)-x1(ix1-1))\n\n !now the \"next\" x2 value\n slope=(f(ix1,ix2)-f(ix1-1,ix2))/(x1(ix1)-x1(ix1-1))\n fx1ix2next=f(ix1-1,ix2)+slope*(x1i(ix1i)-x1(ix1-1))\n\n !finally an interpolation in x2 to finish things off\n slope=(fx1ix2next-fx1ix2prev)/(x2(ix2)-x2(ix2-1))\n interp2_plaid(ix1i,ix2i)=fx1ix2prev+slope*(x2i(ix2i)-x2(ix2-1))\n else\n interp2_plaid(ix1i,ix2i)=0\n end if\n end do\nend do\n\nend procedure interp2_plaid\n\nend submodule interpolation2d", "meta": {"hexsha": "50ecf8b90df711ec16cf8798fd8e2299b8b61dd7", "size": 4629, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/numerical/interpolation/interp2d.f90", "max_stars_repo_name": "scottaiton/gemini3d", "max_stars_repo_head_hexsha": "21f59aabb4d842d587dbeba428ba7353905e063e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2020-09-17T05:08:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-24T18:22:06.000Z", "max_issues_repo_path": "src/numerical/interpolation/interp2d.f90", "max_issues_repo_name": "scottaiton/gemini3d", "max_issues_repo_head_hexsha": "21f59aabb4d842d587dbeba428ba7353905e063e", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 52, "max_issues_repo_issues_event_min_datetime": "2020-07-23T13:55:59.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-19T13:59:43.000Z", "max_forks_repo_path": "src/numerical/interpolation/interp2d.f90", "max_forks_repo_name": "scottaiton/gemini3d", "max_forks_repo_head_hexsha": "21f59aabb4d842d587dbeba428ba7353905e063e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2020-08-20T12:07:06.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-14T13:03:04.000Z", "avg_line_length": 28.3987730061, "max_line_length": 121, "alphanum_fraction": 0.6431194642, "num_tokens": 1936, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392725805823, "lm_q2_score": 0.743168019989179, "lm_q1q2_score": 0.6569897157963855}} {"text": "module advection_schemes\n\n implicit none\n\n contains\n\n ! ---------------------------------------------------------------------------\n !> Use a first-order centered advection scheme to calculate the advctive\n !! thickness tendency\n\n subroutine h_advec_1_centered(dhdt_advec, h, u, v, dx, dy, &\n xlow, xhigh, ylow, yhigh, layers, OL)\n implicit none\n\n ! dhdt is evaluated at the centre of the grid box\n double precision, intent(out) :: dhdt_advec(xlow-OL:xhigh+OL, ylow-OL:yhigh+OL, layers)\n double precision, intent(in) :: h(xlow-OL:xhigh+OL, ylow-OL:yhigh+OL, layers)\n double precision, intent(in) :: u(xlow-OL:xhigh+OL, ylow-OL:yhigh+OL, layers)\n double precision, intent(in) :: v(xlow-OL:xhigh+OL, ylow-OL:yhigh+OL, layers)\n double precision, intent(in) :: dx, dy\n integer, intent(in) :: xlow, xhigh, ylow, yhigh, layers, OL\n\n integer i, j, k\n\n dhdt_advec = 0d0\n\n do k = 1, layers\n do j = ylow-OL+1, yhigh+OL-1\n do i = xlow-OL+1, xhigh+OL-1\n dhdt_advec(i,j,k) = & \n - ((h(i,j,k)+h(i+1,j,k))*u(i+1,j,k) &\n - (h(i-1,j,k)+h(i,j,k))*u(i,j,k))/(dx*2d0) & ! d(hu)/dx\n - ((h(i,j,k)+h(i,j+1,k))*v(i,j+1,k) &\n - (h(i,j-1,k)+h(i,j,k))*v(i,j,k))/(dy*2d0) ! d(hv)/dy\n end do\n end do\n end do\n\n return\n end subroutine h_advec_1_centered\n\n ! ---------------------------------------------------------------------------\n !> Use a first-order upwind advection scheme to calculate the advctive\n !! thickness tendency\n\n subroutine h_advec_1_upwind(dhdt_advec, h, u, v, dx, dy, &\n xlow, xhigh, ylow, yhigh, layers, OL)\n implicit none\n\n ! dhdt is evaluated at the centre of the grid box\n double precision, intent(out) :: dhdt_advec(xlow-OL:xhigh+OL, ylow-OL:yhigh+OL, layers)\n double precision, intent(in) :: h(xlow-OL:xhigh+OL, ylow-OL:yhigh+OL, layers)\n double precision, intent(in) :: u(xlow-OL:xhigh+OL, ylow-OL:yhigh+OL, layers)\n double precision, intent(in) :: v(xlow-OL:xhigh+OL, ylow-OL:yhigh+OL, layers)\n double precision, intent(in) :: dx, dy\n integer, intent(in) :: xlow, xhigh, ylow, yhigh, layers, OL\n\n integer i, j, k\n\n dhdt_advec = 0d0\n\n do k = 1, layers\n do j = ylow-OL+1, yhigh+OL-1\n do i = xlow-OL+1, xhigh+OL-1\n dhdt_advec(i,j,k) = &\n ! d(hu)/dx\n ! u(i+1,j,k) point\n - ( h(i+1,j,k)*(u(i+1,j,k) - abs(u(i+1,j,k)))/2d0 & ! u < 0\n + h(i,j,k)*(u(i+1,j,k) + abs(u(i+1,j,k)))/2d0 & ! u > 0\n ! u(i,j,k) point\n - (h(i,j,k)*(u(i,j,k) - abs(u(i,j,k)))/2d0 & ! u < 0\n + h(i-1,j,k)*(u(i,j,k) + abs(u(i,j,k)))/2d0) & ! u > 0\n )/dx &\n\n ! d(hv)/dx\n ! v(i,j+1,k) point\n - ( h(i,j+1,k)*(v(i,j+1,k) - abs(v(i,j+1,k)))/2d0 & ! v < 0\n + h(i,j,k)*(v(i,j+1,k) + abs(v(i,j+1,k)))/2d0 & ! v > 0\n ! v(i,j,k) point\n - ( h(i,j,k)*(v(i,j,k) - abs(v(i,j,k)))/2d0 & ! v < 0\n + h(i,j-1,k)*(v(i,j,k) + abs(v(i,j,k)))/2d0) & ! v > 0\n )/dy\n end do\n end do\n end do\n\n return\n end subroutine h_advec_1_upwind\n\nend module advection_schemes\n", "meta": {"hexsha": "65e9415c02c7d56fcfd1bcb15a82361824b0889f", "size": 3319, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/advection_schemes.f90", "max_stars_repo_name": "edoddridge/aronnax", "max_stars_repo_head_hexsha": "7c33836fe8d6c8ea4283f2357325d12ff655bc10", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2017-05-03T17:21:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-17T21:01:06.000Z", "max_issues_repo_path": "src/advection_schemes.f90", "max_issues_repo_name": "edoddridge/aronnax", "max_issues_repo_head_hexsha": "7c33836fe8d6c8ea4283f2357325d12ff655bc10", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 172, "max_issues_repo_issues_event_min_datetime": "2017-03-26T16:00:03.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-18T23:34:08.000Z", "max_forks_repo_path": "src/advection_schemes.f90", "max_forks_repo_name": "edoddridge/aronnax", "max_forks_repo_head_hexsha": "7c33836fe8d6c8ea4283f2357325d12ff655bc10", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2017-08-19T12:41:16.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-18T08:32:48.000Z", "avg_line_length": 36.4725274725, "max_line_length": 91, "alphanum_fraction": 0.4902078939, "num_tokens": 1169, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563336, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6569897120626633}} {"text": "!> @brief A test for the calculation of the cumulative distribution function\nprogram test_cdf\n use fplus_statistic\n use fplus_strings\n use fplus_array_tools\n implicit none\n \n ! some example data array\n real (kind=8), dimension(:), allocatable :: a\n integer :: i\n real (kind=8) :: b, c\n a = (/9,8,7,6,5,4,3,1,2,1,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,2,2,2,4,4,5,7,8,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,8,8,8,8/)\n\n do i = 1, 9\n b = cumulative_distribution_function(a, real(i,8))\n c = invers_cumulative_distribution_function(a, b)\n write(*, \"(A,I1,A,F4.2,A,F4.2,A,I1)\") \"cdf(\", i, \") = \", b, \" => cdf^-1(\", b, \") = \", int(c) \n end do\n \nend program", "meta": {"hexsha": "bf535d386f58918ea1c31507aa5da05d275cf5c9", "size": 797, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "testsrc/test-cdf.f90", "max_stars_repo_name": "r5r3/fpluslib", "max_stars_repo_head_hexsha": "50de656159a39702dbeb1158dbefc02e58a3fb68", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2016-08-26T20:41:13.000Z", "max_stars_repo_stars_event_max_datetime": "2019-02-17T19:34:07.000Z", "max_issues_repo_path": "testsrc/test-cdf.f90", "max_issues_repo_name": "r5r3/fpluslib", "max_issues_repo_head_hexsha": "50de656159a39702dbeb1158dbefc02e58a3fb68", "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": "testsrc/test-cdf.f90", "max_forks_repo_name": "r5r3/fpluslib", "max_forks_repo_head_hexsha": "50de656159a39702dbeb1158dbefc02e58a3fb68", "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": 39.85, "max_line_length": 211, "alphanum_fraction": 0.5621079046, "num_tokens": 380, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392939666335, "lm_q2_score": 0.743167997235783, "lm_q1q2_score": 0.6569897115749186}} {"text": "C$Procedure DIAGS2 ( Diagonalize symmetric 2x2 matrix )\n \n SUBROUTINE DIAGS2 ( SYMMAT, DIAG, ROTATE )\n \nC$ Abstract\nC\nC Diagonalize a symmetric 2x2 matrix.\nC\nC$ Disclaimer\nC\nC THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE\nC CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.\nC GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE\nC ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE\nC PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED \"AS-IS\"\nC TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY\nC WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A\nC PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC\nC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE\nC SOFTWARE AND RELATED MATERIALS, HOWEVER USED.\nC\nC IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA\nC BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT\nC LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,\nC INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,\nC REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE\nC REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.\nC\nC RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF\nC THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY\nC CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE\nC ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.\nC\nC$ Required_Reading\nC\nC ROTATION\nC\nC$ Keywords\nC\nC ELLIPSE\nC MATRIX\nC ROTATION\nC TRANSFORMATION\nC\nC$ Declarations\n \n DOUBLE PRECISION SYMMAT ( 2, 2 )\n DOUBLE PRECISION DIAG ( 2, 2 )\n DOUBLE PRECISION ROTATE ( 2, 2 )\n \nC$ Brief_I/O\nC\nC Variable I/O Description\nC -------- --- --------------------------------------------------\nC\nC SYMMAT I A symmetric 2x2 matrix.\nC DIAG O A diagonal matrix similar to SYMMAT.\nC ROTATE O A rotation used as the similarity transformation.\nC\nC$ Detailed_Input\nC\nC SYMMAT A symmetric 2x2 matrix. That is, SYMMAT has the\nC form\nC\nC +- -+\nC | A B |\nC | |.\nC | B C |\nC +- -+\nC\nC This routine uses only the upper-triangular\nC elements of SYMMAT, that is, the elements\nC\nC SYMMAT(1,1)\nC SYMMAT(1,2)\nC SYMMAT(2,2)\nC\nC to determine the outputs DIAG and ROTATE.\nC\nC$ Detailed_Output\nC\nC DIAG,\nC ROTATE are, respectively, a diagonal matrix and a 2x2\nC rotation matrix that satisfy the equation\nC\nC T\nC DIAG = ROTATE * SYMMAT * ROTATE.\nC\nC In other words, DIAG is similar to SYMMAT, and\nC ROTATE is a change-of-basis matrix that\nC diagonalizes SYMMAT. DIAGS2 chooses ROTATE so\nC that its angle of rotation has the smallest\nC possible magnitude. If there are two rotations\nC that meet these criteria (they will be inverses of\nC one another), either rotation may be chosen.\nC\nC$ Parameters\nC\nC None.\nC\nC$ Files\nC\nC None.\nC\nC$ Exceptions\nC\nC 1) The matrix element SYMMAT(2,1) is not used in this routine's\nC computations, so the condition\nC\nC SYMMAT(1,2) .NE. SYMMAT(2,1)\nC\nC has no effect on this routine's outputs.\nC\nC$ Particulars\nC\nC The capability of diagonalizing a 2x2 symmetric matrix is\nC especially useful in a number of geometric applications\nC involving quadratic curves such as ellipses. Such curves are\nC described by expressions of the form\nC\nC 2 2\nC A x + B xy + C y + D x + E y + F = 0.\nC\nC Diagonalization of the matrix\nC\nC +- -+\nC | A B/2 |\nC | |\nC | B/2 C |\nC +- -+\nC\nC allows us to perform a coordinate transformation (a rotation,\nC specifically) such that the equation of the curve becomes\nC\nC 2 2\nC P u + Q v + R u + S v + T = 0\nC\nC in the transformed coordinates. This form is much easier to\nC handle. If the quadratic curve in question is an ellipse,\nC we can easily find its center, semi-major axis, and semi-minor\nC axis from the second equation.\nC\nC Ellipses turn up frequently in navigation geometry problems;\nC for example, the limb and terminator (if we treat the Sun as a\nC point source) of a body modelled as a tri-axial ellipsoid are\nC ellipses.\nC\nC A mathematical note: because SYMMAT is symmetric, we can ALWAYS\nC find an orthogonal similarity transformation that diagonalizes\nC SYMMAT, and we can choose the similarity transformation to be a\nC rotation matrix. By `orthogonal' we mean that if the ROTATE is\nC the matrix in question, then\nC\nC T T\nC ROTATE ROTATE = ROTATE ROTATE = I.\nC\nC The reasons this routine handles only the 2x2 case are: first,\nC the 2x2 case is much simpler than the general case, in which\nC iterative diagonalization methods must be used, and second, the\nC 2x2 case is adequate for solving problems involving ellipses in\nC 3 dimensional space. Finally, this routine can be used to\nC support a routine that solves the general-dimension\nC diagonalization problem for symmetric matrices.\nC\nC Another feature of the routine that might provoke curiosity is\nC its insistence on choosing the diagonalization matrix that\nC rotates the original basis vectors by the smallest amount. The\nC rotation angle of ROTATE is of no concern for most applications,\nC but can be important if this routine is used as part of an\nC iterative diagonalization method for higher-dimensional matrices.\nC In that case, it is most undesirable to interchange diagonal\nC matrix elements willy-nilly; the matrix to be diagonalized could\nC get ever closer to being diagonal without converging. Choosing\nC the smallest rotation angle precludes this possibility.\nC\nC$ Examples\nC\nC 1) A case that can be verified by hand computation:\nC Suppose SYMMAT is\nC\nC +- -+\nC | 1.0D0 4.0D0 |\nC | |\nC | 4.0D0 -5.0D0 |\nC +- -+\nC\nC Then SYMMAT is similar to the diagonal matrix\nC\nC +- -+\nC | 3.0D0 0.0D0 |\nC | |\nC | 0.0D0 -7.0D0 |\nC +- -+\nC\nC so\nC\nC DIAG(1,1) = 3.D0\nC DIAG(2,1) = 0.D0\nC DIAG(1,2) = 0.D0\nC DIAG(2,2) = -7.D0\nC\nC and ROTATE is\nC\nC +- -+\nC | 0.894427191 -0.447213595 |\nC | |\nC | 0.447213595 0.894427191 |\nC +- -+\nC\nC which is an approximation to\nC\nC +- -+\nC | 0.4 * 5**(1/2) -0.2 * 5**(1/2) |\nC | |\nC | 0.2 * 5**(1/2) 0.4 * 5**(1/2) |\nC +- -+\nC\nC\nC 2) Suppose we want to find the semi-axes of the ellipse defined\nC by\nC 2 2\nC 27 x + 10 xy + 3 y = 1.\nC\nC We can write the above equation as the matrix equation\nC\nC +- -+ +- -+ +- -+\nC | x y | | 27 5 | | x | = 1;\nC +- -+ | | | |\nC | 5 3 | | y |\nC +- -+ +- -+\nC\nC let SYMMAT be the symmetric matrix on the left. The code\nC fragment\nC\nC SYMMAT(1,1) = 27.D0\nC SYMMAT(2,1) = 5.D0\nC SYMMAT(1,2) = 5.D0\nC SYMMAT(2,2) = 3.D0\nC\nC CALL DIAGS2 ( SYMMAT, DIAG, ROTATE )\nC\nC will return DIAG, an array containing the eigenvalues of\nC SYMMAT, and ROTATE, the coordinate transformation required\nC to diagonalize SYMMAT. In this case,\nC\nC DIAG(1,1) = 28.D0\nC DIAG(2,1) = 0.D0\nC DIAG(1,2) = 0.D0\nC DIAG(2,2) = 2.D0 \nC\nC and\nC\nC ROTATE(1,1) = 0.980580676D0\nC ROTATE(2,1) = 0.196116135D0\nC ROTATE(1,2) = -0.196116135D0\nC ROTATE(2,2) = 0.980580676D0\nC\nC The columns of ROTATE give the ellipse's axes, after scaling\nC them by\nC\nC 1 1\nC ---------------- and ---------------\nC ____________ ____________\nC \\/ DIAG(1,1) \\/ DIAG(2,2)\nC\nC respectively.\nC\nC If SMAJOR and SMINOR are semi-major and semi-minor axes,\nC we can find them as shown below. For brevity, we omit the\nC check for zero or negative eigenvalues. Negative or zero\nC eigenvalues will occur only as a result of round-off error;\nC mathematically, the eigenvalues of the matrix SYMMAT are\nC guaranteed to be positive, since they are the reciprocals of\nC the squares of the lengths of the ellipse's semi-axes.\nC\nC DO I = 1, 2\nC SMAJOR(I) = ROTATE(I,1) / DSQRT( DIAG(1,1) )\nC SMINOR(I) = ROTATE(I,2) / DSQRT( DIAG(2,2) )\nC END DO\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Literature_References\nC\nC [1] Calculus, Vol. II. Tom Apostol. John Wiley & Sons, 1969.\nC See Chapter 5, `Eigenvalues of Operators Acting on Euclidean\nC Spaces'.\nC\nC$ Author_and_Institution\nC\nC N.J. Bachman (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 1.2.0, 06-SEP-2005 (NJB)\nC\nC Updated to remove non-standard use of duplicate arguments\nC in VHATG and SWAPD calls.\nC\nC- SPICELIB Version 1.1.0, 24-JAN-2002 (EDW)\nC\nC Edited incorrect examples in the header. The example \nC outputs did not correspond to the actual function\nC of the routine.\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, 04-NOV-1990 (NJB)\nC\nC-&\n \nC$ Index_Entries\nC\nC diagonalize symmetric 2x2_matrix\nC\nC-&\n \nC$ Revisions\nC\nC- SPICELIB Version 1.2.0, 06-SEP-2005 (NJB)\nC\nC Updated to remove non-standard use of duplicate arguments\nC in VHATG and SWAPD calls.\nC\nC-& \n \n \nC\nC SPICELIB functions\nC\n LOGICAL RETURN\n \nC\nC Local variables\nC\n DOUBLE PRECISION A\n DOUBLE PRECISION B\n DOUBLE PRECISION C\n DOUBLE PRECISION EIGVEC ( 2 )\n DOUBLE PRECISION IDENT ( 2, 2 )\n DOUBLE PRECISION ROOT1 ( 2 )\n DOUBLE PRECISION ROOT2 ( 2 )\n DOUBLE PRECISION SCALE\n DOUBLE PRECISION TMPD\n DOUBLE PRECISION TMPV ( 2 )\n\nC\nC Saved variables\nC\n SAVE IDENT\n \nC\nC Initial values\nC\n DATA IDENT / 1.D0, 0.D0,\n . 0.D0, 1.D0 /\n \n \n \nC\nC Standard SPICE error handling.\nC\n IF ( RETURN () ) THEN\n RETURN\n ELSE\n CALL CHKIN ( 'DIAGS2' )\n END IF\n \nC\nC We check for the case of a diagonal input matrix, since\nC eigenvector determination is simplified by ruling out this\nC case.\n \n IF ( SYMMAT(1,2) .EQ. 0.D0 ) THEN\n \n CALL MOVED ( IDENT, 4, ROTATE )\n CALL MOVED ( SYMMAT, 4, DIAG )\nC\nC Explicity zero out the (2,1) entry of DIAG, since DIAG is\nC guaranteed to be diagonal.\nC\n DIAG(2,1) = 0.D0\n \n CALL CHKOUT ( 'DIAGS2' )\n RETURN\n \n END IF\n \nC\nC Getting here means there's some actual work to do. We start out\nC by scaling our matrix, in order to reduce the chance of overflow.\nC We divide everything by the largest magnitude of any element of\nC SYMMAT. We're guaranteed that SCALE is non-zero, since the 0\nC matrix is diagonal.\nC\n SCALE = MAX ( DABS( SYMMAT(1,1) ),\n . DABS( SYMMAT(1,2) ),\n . DABS( SYMMAT(2,2) ) )\n \n A = SYMMAT(1,1) / SCALE\n B = SYMMAT(1,2) / SCALE\n C = SYMMAT(2,2) / SCALE\n \nC\nC Compute the eigenvalues of the scaled version of SYMMAT. The\nC eigenvalues are roots of the equation\nC\nC DET ( (1 / SCALE) * SYMMAT - x * IDENTITY ) = 0,\nC\nC or equivalently,\nC\nC 2 2\nC x - ( A + C ) x + ( AC - B ) = 0.\nC\nC\n CALL RQUAD ( 1.D0, -(A + C), A*C - B**2, ROOT1, ROOT2 )\n \nC\nC ROOT1 is the root corresponding to the positive discriminant term;\nC this is guaranteed by RQUAD.\nC\n DIAG(1,1) = ROOT1(1)\n DIAG(2,1) = 0.D0\n DIAG(1,2) = 0.D0\n DIAG(2,2) = ROOT2(1)\n \nC\nC Our next job is to find an eigenvector corresponding to the\nC eigenvalue of smaller magnitude. We can unitize it and choose\nC an orthogonal unit vector so as to create the desired rotation\nC matrix.\nC\nC If our original matrix is\nC\nC +- -+\nC | A B |\nC | |,\nC | B C |\nC +- -+\nC\nC then the matrix\nC\nC +- -+\nC | A - DIAG(x,x) B |\nC | |\nC | B C - DIAG(x,x) |\nC +- -+\nC\nC maps to zero all elements of the eigenspace corresponding to\nC DIAG(x,x), where x is either 1 or 2.\nC\nC So\nC\nC +- -+ +- -+\nC | B | | DIAG(x,x) - C |\nC | | and | |\nC | DIAG(x,x) - A | | B |\nC +- -+ +- -+\nC\nC are candidates for eigenvectors for DIAG(x,x). To minimize\nC loss of accuracy in our eigenvector due to subtraction of\nC nearly equal quantities, we choose the vector in which the\nC term involving the eigenvalue has the larger magnitude. The\nC rigorous justification of this choice would literally take\nC pages of explanation, and we are not going to go through it\nC here. In most cases, either choice is satisfactory, and in\nC the case where cancellation is a problem, our choice is\nC preferable.\nC\nC Note that there is nothing to be gained as far as accuracy is\nC concerned by working with one eigenvalue as opposed to the\nC other: the magnitudes of the quantities DIAG(x,x) - A and\nC DIAG(x,x) - C would be interchanged by taking x = '2' instead\nC of x = '1'.\nC\n \n IF ( DABS( DIAG(1,1) - A ) .GE. DABS( DIAG(1,1) - C ) ) THEN\nC\nC In this case, the second eigenvector component EIGVEC(2)\nC should be larger than |B|; we explain why in detail below.\nC We use the MAX function below to guard against reversal of the\nC inequality due to round-off error.\nC\n EIGVEC(1) = B\n EIGVEC(2) = MAX ( DIAG(1,1) - A, ABS(B) )\n \nC\nC Recall that DIAG(1,1) is an eigenvalue of the scaled version\nC of SYMMAT\nC\nC +- -+\nC | A B |\nC | |.\nC | B C |\nC +- -+\nC\nC DIAG(1,1) is the positive-discriminant root of this matrix's\nC characteristic equation. EIGVEC's y-component\nC\nC DIAG(1,1) - A\nC\nC is positive and of magnitude at least as large as that of B,\nC since it is the larger of\nC ______________________\nC / 2\nC C - A / ( A - C ) 2\nC DIAG(1,1) - A = ----- + \\ / ---------- + B\nC 2 \\/ 4\nC\nC and\nC ______________________\nC / 2\nC A - C / ( A - C ) 2\nC DIAG(1,1) - C = ----- + \\ / ---------- + B\nC 2 \\/ 4\nC\nC Equality between these expressions can occur only when A is\nC equal to C, in which case both expressions are equal (except\nC for round-off error) to |B|.\nC\n \nC\nC So the argument of EIGVEC is in the interval [pi/4, 3*pi/4].\nC The second eigenvector is EIGVEC, and the first\nC eigenvector is found by rotating EIGVEC by -pi/2. Since\nC DIAG(1,1) is the eigenvalue for the SECOND eigenvector, we\nC must swap the eigenvalues.\nC\n \nC\nC Unitize the eigenvector.\nC\n CALL VHATG ( EIGVEC, 2, TMPV )\n CALL MOVED ( TMPV, 2, EIGVEC )\n \n ROTATE(1,1) = EIGVEC(2)\n ROTATE(2,1) = -EIGVEC(1)\n ROTATE(1,2) = EIGVEC(1)\n ROTATE(2,2) = EIGVEC(2)\n \nC\nC Swap DIAG(1,1) and DIAG(2,2).\nC\n TMPD = DIAG(2,2)\n DIAG(2,2) = DIAG(1,1)\n DIAG(1,1) = TMPD \n \n ELSE\n \n EIGVEC(1) = MAX ( DIAG(1,1) - C, ABS(B) )\n EIGVEC(2) = B\n \nC\nC The x-component of EIGVEC is positive and has magnitude\nC greater than or equal to that of the y-component of EIGVEC.\nC The argument of EIGVEC is in [-pi/4, pi/4], and the second\nC eigenvector is found by rotating EIGVEC by pi/2.\nC\n \nC\nC Unitize the eigenvector.\nC\n CALL VHATG ( EIGVEC, 2, TMPV )\n CALL MOVED ( TMPV, 2, EIGVEC )\n \n ROTATE(1,1) = EIGVEC(1)\n ROTATE(2,1) = EIGVEC(2)\n ROTATE(1,2) = -EIGVEC(2)\n ROTATE(2,2) = EIGVEC(1)\n \n END IF\n \nC\nC We must scale the eigenvalues.\nC\n DIAG(1,1) = DIAG(1,1) * SCALE\n DIAG(2,2) = DIAG(2,2) * SCALE\n \n CALL CHKOUT ( 'DIAGS2' )\n RETURN\n END\n", "meta": {"hexsha": "13d969605a014c31ed78e7f508590a9a1bfadae9", "size": 18742, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/diags2.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/diags2.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/diags2.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": 31.9284497445, "max_line_length": 72, "alphanum_fraction": 0.5250240102, "num_tokens": 5485, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357326, "lm_q2_score": 0.7431680086124812, "lm_q1q2_score": 0.6569897080094278}} {"text": "subroutine eval_surface(u, v, tu, tv, ku, kv, coef, nctlu, nctlv, ndim, &\n n, m, val)\n\n !***DESCRIPTION\n !\n ! Written by Gaetan Kenway\n !\n ! Abstract eval_surface evaluates (possibly) many points on the surface\n !\n ! Description of Arguments\n ! Input\n ! u - Real, u coordinate, size(m, n)\n ! v - Real, v coordinate, size(m, n)\n ! tu - Real, Knot vector in u. size(nctlu+ku)\n ! tv - Real, Knot vector in v. size(nctlv+kv)\n ! ku - Integer, order of B-spline in u\n ! kv - Integer, order of B-spline in v\n ! coef - Real, Array of B-spline coefficients Size (ndim, nctlv, nctlu)\n ! nctlu - Integer, Number of control points in u\n ! nctlv - Integer, Number of control points in v\n ! ndim - Integer, Spatial Dimension\n !\n ! Ouput \n ! val - Real, Evaluated point(s), size (ndim, m, n)\n\n use precision\n implicit none\n\n ! Input\n integer , intent(in) :: ku, kv, nctlu, nctlv, ndim, n, m\n real(kind=realType), intent(in) :: u(m, n), v(m, n)\n real(kind=realType), intent(in) :: tu(nctlu+ku), tv(nctlv+kv)\n real(kind=realType), intent(in) :: coef(ndim, nctlv, nctlu)\n\n ! Output\n real(kind=realType), intent(out):: val(ndim, m, n)\n\n ! Working\n integer :: idim, istartu, istartv, i, j, ii, jj\n integer :: ileftu, ileftv\n real(kind=realType) :: basisu(ku), basisv(kv)\n\n val(:, :, :) = 0.0\n do ii=1, n\n do jj = 1, m\n ! U\n call findSpan(u(jj,ii), ku, tu, nctlu, ileftu)\n call basis(tu, nctlu, ku, u(jj, ii), ileftu, basisu)\n istartu = ileftu-ku\n\n ! V\n call findSpan(v(jj,ii), kv, tv, nctlv, ileftv)\n call basis(tv, nctlv, kv, v(jj, ii), ileftv, basisv)\n istartv = ileftv-kv\n\n do i=1, ku\n do j=1, kv\n do idim=1, ndim\n val(idim, jj, ii) = val(idim, jj, ii) + basisu(i)*basisv(j)*coef(idim, istartv+j, istartu+i)\n end do\n end do\n end do\n end do\n end do\n\nend subroutine eval_surface\n\nsubroutine eval_surface_deriv(u, v, tu, tv, ku, kv, coef, nctlu, nctlv, &\n ndim, val)\n\n !***DESCRIPTION\n !\n ! Written by Gaetan Kenway\n !\n ! Abstract eval_surface_deriv evaluates the derivative of a\n ! point on the surface\n !\n ! Description of Arguments\n ! Input\n ! u - Real, u coordinate\n ! v - Real, v coordinate\n ! tu - Real, Knot vector in u. size(nctlu+ku)\n ! tv - Real, Knot vector in v. size(nctlv+kv)\n ! ku - Integer, order of B-spline in u\n ! kv - Integer, order of B-spline in v\n ! coef - Real, Array of B-spline coefficients Size (ndim, nctlv, nctlu)\n ! nctlu - Integer, Number of control points in u\n ! nctlv - Integer, Number of control points in v\n ! ndim - Integer, Spatial Dimension\n !\n ! Ouput \n ! val - Real, Evaluated derivatives, size (ndim, 2)\n \n use precision\n implicit none\n \n ! Input\n integer , intent(in) :: ku, kv, nctlu, nctlv, ndim\n real(kind=realType), intent(in) :: u, v\n real(kind=realType), intent(in) :: tu(nctlu+ku), tv(nctlv+kv)\n real(kind=realType), intent(in) :: coef(ndim, nctlv, nctlu)\n\n ! Output\n real(kind=realType), intent(out) :: val(ndim, 2)\n\n ! Working\n integer :: idim\n real(kind=realType) :: b2val\n\n do idim=1, ndim\n val(idim, 1) = b2val(v, u, 0, 1, tv, tu, nctlv, nctlu, kv, ku, coef(idim, :, :))\n val(idim, 2) = b2val(v, u, 1, 0, tv, tu, nctlv, nctlu, kv, ku, coef(idim, :, :))\n end do\n\nend subroutine eval_surface_deriv\n\nsubroutine eval_surface_deriv2(u, v, tu, tv, ku, kv, coef, nctlu, nctlv, ndim, val)\n\n\n !***DESCRIPTION\n !\n ! Written by Gaetan Kenway\n !\n ! Abstract eval_surface_deriv2 evaluates the second derivative\n ! of a point on the surface\n !\n ! Description of Arguments\n ! Input\n ! u - Real, u coordinate\n ! v - Real, v coordinate\n ! tu - Real, Knot vector in u. size(nctlu+ku)\n ! tv - Real, Knot vector in v. size(nctlv+kv)\n ! ku - Integer, order of B-spline in u\n ! kv - Integer, order of B-spline in v\n ! coef - Real, Array of B-spline coefficients Size (ndim, nctlv, nctlu)\n ! nctlu - Integer, Number of control points in u\n ! nctlv - Integer, Number of control points in v\n ! ndim - Integer, Spatial Dimension\n !\n ! Ouput \n ! val - Real, Evaluated second derivatives, size (ndim, 2, 2)\n\n use precision\n implicit none\n\n ! Input\n integer , intent(in) :: ku, kv, nctlu, nctlv, ndim\n real(kind=realType), intent(in) :: u, v\n real(kind=realType), intent(in) :: tu(nctlu+ku), tv(nctlv+kv)\n real(kind=realType), intent(in) :: coef(ndim, nctlv, nctlu)\n\n ! Output\n real(kind=realType), intent(out) :: val(ndim, 2, 2)\n\n ! Working\n integer :: idim\n real(kind=realType) :: b2val\n\n do idim=1, ndim\n val(idim, 1, 1) = b2val(v, u, 0, 2, tv, tu, nctlv, nctlu, kv, ku, coef(idim, :, :))\n val(idim, 1, 2) = b2val(v, u, 1, 1, tv, tu, nctlv, nctlu, kv, ku, coef(idim, :, :))\n val(idim, 2, 1) = val(idim, 1, 2)\n val(idim, 2, 2) = b2val(v, u, 2, 0, tv, tu, nctlv, nctlu, kv, ku, coef(idim, :, :))\n end do\n\nend subroutine eval_surface_deriv2\n", "meta": {"hexsha": "28629e5f04e5da9ae254a745b9e0e09de399307e", "size": 5462, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/eval_surface.f90", "max_stars_repo_name": "eirikurj/pyspline", "max_stars_repo_head_hexsha": "91dd6d432deac3b1647508bf4fca985e704da77c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2019-04-18T00:49:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-20T14:40:08.000Z", "max_issues_repo_path": "src/eval_surface.f90", "max_issues_repo_name": "eirikurj/pyspline", "max_issues_repo_head_hexsha": "91dd6d432deac3b1647508bf4fca985e704da77c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 23, "max_issues_repo_issues_event_min_datetime": "2019-10-17T20:39:11.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T15:27:42.000Z", "max_forks_repo_path": "src/eval_surface.f90", "max_forks_repo_name": "eirikurj/pyspline", "max_forks_repo_head_hexsha": "91dd6d432deac3b1647508bf4fca985e704da77c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2019-05-29T16:56:15.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-08T13:51:24.000Z", "avg_line_length": 32.7065868263, "max_line_length": 109, "alphanum_fraction": 0.5549249359, "num_tokens": 1896, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357327, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6569897080094278}} {"text": "!\n! CalculiX - A 3-dimensional finite element program\n! Copyright (C) 1998-2015 Guido Dhondt\n!\n! This program is free software; you can redistribute it and/or\n! modify it under the terms of the GNU General Public License as\n! published by the Free Software Foundation(version 2);\n! \n!\n! This program is distributed in the hope that it will be useful,\n! but WITHOUT ANY WARRANTY; without even the implied warranty of \n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \n! GNU General Public License for more details.\n!\n! You should have received a copy of the GNU General Public License\n! along with this program; if not, write to the Free Software\n! Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n!\n subroutine shape6w(xi,et,ze,xl,xsj,shp,iflag)\n!\n! shape functions and derivatives for a 6-node linear\n! isoparametric wedge element. 0<=xi,et<=1,xi+et<=1,-1<=ze<=1.\n!\n! iflag=1: calculate only the value of the shape functions\n! iflag=2: calculate the value of the shape functions and\n! the Jacobian determinant\n! iflag=3: calculate the value of the shape functions, the\n! value of their derivatives w.r.t. the global\n! coordinates and the Jacobian determinant\n!\n!\n! Copyright (c) 2003 WB\n!\n! Written January 2003 on the basis of the Guido's shape function files\n!\n implicit none\n!\n integer i,j,k,iflag\n!\n real*8 shp(4,6),xs(3,3),xsi(3,3),xl(3,6),sh(3)\n!\n real*8 xi,et,ze,xsj,a\n!\n intent(in) xi,et,ze,xl,iflag\n!\n intent(out) shp,xsj\n!\n! shape functions and their glocal derivatives\n!\n a=1.d0-xi-et\n!\n! shape functions\n!\n shp(4, 1)=0.5d0*a *(1.d0-ze)\n shp(4, 2)=0.5d0*xi*(1.d0-ze)\n shp(4, 3)=0.5d0*et*(1.d0-ze)\n shp(4, 4)=0.5d0*a *(1.d0+ze)\n shp(4, 5)=0.5d0*xi*(1.d0+ze) \n shp(4, 6)=0.5d0*et*(1.d0+ze) \n!\n if(iflag.eq.1) return\n!\n! local derivatives of the shape functions: xi-derivative\n!\n shp(1, 1)=-0.5d0*(1.d0-ze)\n shp(1, 2)= 0.5d0*(1.d0-ze)\n shp(1, 3)= 0.d0\n shp(1, 4)=-0.5d0*(1.d0+ze)\n shp(1, 5)= 0.5d0*(1.d0+ze)\n shp(1, 6)= 0.d0\n!\n! local derivatives of the shape functions: eta-derivative\n!\n shp(2, 1)=-0.5d0*(1.d0-ze)\n shp(2, 2)= 0.d0\n shp(2, 3)= 0.5d0*(1.d0-ze)\n shp(2, 4)=-0.5d0*(1.d0+ze)\n shp(2, 5)= 0.d0\n shp(2, 6)= 0.5d0*(1.d0+ze)\n\n!\n! local derivatives of the shape functions: zeta-derivative\n!\n shp(3, 1)=-0.5d0*a\n shp(3, 2)=-0.5d0*xi\n shp(3, 3)=-0.5d0*et\n shp(3, 4)= 0.5d0*a\n shp(3, 5)= 0.5d0*xi\n shp(3, 6)= 0.5d0*et\n!\n!\n! computation of the local derivative of the global coordinates\n! (xs)\n!\n do i=1,3\n do j=1,3\n xs(i,j)=0.d0\n do k=1,6\n xs(i,j)=xs(i,j)+xl(i,k)*shp(j,k)\n enddo\n enddo\n enddo\n!\n! computation of the jacobian determinant\n!\n xsj=xs(1,1)*(xs(2,2)*xs(3,3)-xs(2,3)*xs(3,2))\n & -xs(1,2)*(xs(2,1)*xs(3,3)-xs(2,3)*xs(3,1))\n & +xs(1,3)*(xs(2,1)*xs(3,2)-xs(2,2)*xs(3,1))\n!\n if(iflag.eq.2) return\n!\n! computation of the global derivative of the local coordinates\n! (xsi) (inversion of xs)\n!\n xsi(1,1)=(xs(2,2)*xs(3,3)-xs(3,2)*xs(2,3))/xsj\n xsi(1,2)=(xs(1,3)*xs(3,2)-xs(1,2)*xs(3,3))/xsj\n xsi(1,3)=(xs(1,2)*xs(2,3)-xs(2,2)*xs(1,3))/xsj\n xsi(2,1)=(xs(2,3)*xs(3,1)-xs(2,1)*xs(3,3))/xsj\n xsi(2,2)=(xs(1,1)*xs(3,3)-xs(3,1)*xs(1,3))/xsj\n xsi(2,3)=(xs(1,3)*xs(2,1)-xs(1,1)*xs(2,3))/xsj\n xsi(3,1)=(xs(2,1)*xs(3,2)-xs(3,1)*xs(2,2))/xsj\n xsi(3,2)=(xs(1,2)*xs(3,1)-xs(1,1)*xs(3,2))/xsj\n xsi(3,3)=(xs(1,1)*xs(2,2)-xs(2,1)*xs(1,2))/xsj\n!\n! computation of the global derivatives of the shape functions\n!\n do k=1,6\n do j=1,3\n sh(j)=shp(1,k)*xsi(1,j)+shp(2,k)*xsi(2,j)+shp(3,k)*xsi(3,j)\n enddo\n do j=1,3\n shp(j,k)=sh(j)\n enddo\n enddo\n!\n return\n end\n", "meta": {"hexsha": "dcb9761d8f68f8543bd7640758481cf94b955252", "size": 4007, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ccx_prool/CalculiX/ccx_2.9/src/shape6w.f", "max_stars_repo_name": "alleindrach/calculix-desktop", "max_stars_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ccx_prool/CalculiX/ccx_2.9/src/shape6w.f", "max_issues_repo_name": "alleindrach/calculix-desktop", "max_issues_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2017-09-21T17:03:55.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-25T16:08:31.000Z", "max_forks_repo_path": "ccx_prool/CalculiX/ccx_2.9/src/shape6w.f", "max_forks_repo_name": "alleindrach/calculix-desktop", "max_forks_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-08-29T18:41:28.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-29T18:41:28.000Z", "avg_line_length": 29.0362318841, "max_line_length": 74, "alphanum_fraction": 0.5582730222, "num_tokens": 1661, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460333, "lm_q2_score": 0.7431680029241322, "lm_q1q2_score": 0.6569897075216838}} {"text": " ! Generated by TAPENADE (INRIA, Tropics team)\n ! Tapenade 3.10 (r5363) - 9 Sep 2014 09:53\n !\n ! Differentiation of getmag in forward (tangent) mode (with options noISIZE i4 dr8 r8):\n ! variations of useful results: mag\n ! with respect to varying inputs: v\n SUBROUTINE GETMAG_D(v, vb, mag, magb)\n USE CONSTANTS\n IMPLICIT NONE\n ! Subroutine Variables\n REAL(kind=realtype), DIMENSION(3), INTENT(IN) :: v\n REAL(kind=realtype), DIMENSION(3), INTENT(IN) :: vb\n REAL(kind=realtype), INTENT(OUT) :: mag\n REAL(kind=realtype), INTENT(OUT) :: magb\n INTRINSIC SQRT\n REAL(kind=realtype) :: arg1\n REAL(kind=realtype) :: arg1b\n arg1b = 2*v(1)*vb(1) + 2*v(2)*vb(2) + 2*v(3)*vb(3)\n arg1 = v(1)**2 + v(2)**2 + v(3)**2 + 1e-30\n IF (arg1 .EQ. 0.0_8) THEN\n magb = 0.0_8\n ELSE\n magb = arg1b/(2.0*SQRT(arg1))\n END IF\n mag = SQRT(arg1)\n END SUBROUTINE GETMAG_D\n", "meta": {"hexsha": "61b2ce3deeaa13ee36771bb81868d3484964c2f1", "size": 910, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/warp/outputForward/getmag_d.f90", "max_stars_repo_name": "marcomangano/idwarp", "max_stars_repo_head_hexsha": "3e0d4837a9b926b1cd227654365ca4adfbc08cbe", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2019-04-18T00:49:56.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-27T10:06:49.000Z", "max_issues_repo_path": "src/warp/outputForward/getmag_d.f90", "max_issues_repo_name": "marcomangano/idwarp", "max_issues_repo_head_hexsha": "3e0d4837a9b926b1cd227654365ca4adfbc08cbe", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 39, "max_issues_repo_issues_event_min_datetime": "2019-07-12T07:46:12.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T14:34:53.000Z", "max_forks_repo_path": "src/warp/outputForward/getmag_d.f90", "max_forks_repo_name": "marcomangano/idwarp", "max_forks_repo_head_hexsha": "3e0d4837a9b926b1cd227654365ca4adfbc08cbe", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 27, "max_forks_repo_forks_event_min_datetime": "2019-05-19T18:07:19.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-19T05:39:05.000Z", "avg_line_length": 33.7037037037, "max_line_length": 91, "alphanum_fraction": 0.6186813187, "num_tokens": 365, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789468908171, "lm_q2_score": 0.7341195385342971, "lm_q1q2_score": 0.6568824320002153}} {"text": "program test\n implicit none\n integer :: i, j, n\n\n do i = 1, 5\n write(*, \"(a, i0, a)\", advance = \"no\") \"Degree \", i, \": \"\n do j = 1, 10\n n = multifactorial(j, i)\n write(*, \"(i0, 1x)\", advance = \"no\") n\n end do\n write(*,*)\n end do\n\ncontains\n\nfunction multifactorial (range, degree)\n integer :: multifactorial, range, degree\n integer :: k\n\n multifactorial = product((/(k, k=range, 1, -degree)/))\n\nend function multifactorial\nend program test\n", "meta": {"hexsha": "bd06f8f068760d7b8da888e3c762c0f9fd840046", "size": 468, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Multifactorial/Fortran/multifactorial.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/Multifactorial/Fortran/multifactorial.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/Multifactorial/Fortran/multifactorial.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 19.5, "max_line_length": 61, "alphanum_fraction": 0.5876068376, "num_tokens": 160, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969136, "lm_q2_score": 0.7341195327172401, "lm_q1q2_score": 0.6568824226758402}} {"text": "program mtx_multi_loop_test\n\n !Undergraduate Student: Arturo Burgos\n !Professor: Jo\u00e3o Rodrigo Andrade\n !Federal University of Uberl\u00e2ndia - UFU, Fluid Mechanics Laboratory\n !MFLab, Block 5P, Uberl\u00e2ndia, MG, Brazil\n\n\n implicit none !To avoid variable definition problems, checking if they are correctly defined\n real, DIMENSION(5000,5000) :: mtx1, mtx2, mtx3\n DOUBLE PRECISION :: start, finish\n \n call random_number(mtx1)\n call random_number(mtx2)\n\n\n call cpu_time(start)\n\n mtx3 = matmul(mtx1,mtx2)\n\n call cpu_time(finish)\n\n\n\n write(*,'(A/)') \n print '(\"Elapsed time is: \",f8.5,\" seconds\")', finish - start\n !print '(\"Elapsed time is: \",f6.5,\" seconds\")', finish - start\n\nend program mtx_multi_loop_test", "meta": {"hexsha": "8b4564a709a0e24fef348d77e328ff5f36bf6397", "size": 749, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Matrix Multiplication/Fortran/mtx_multi_vec.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": "Matrix Multiplication/Fortran/mtx_multi_vec.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": "Matrix Multiplication/Fortran/mtx_multi_vec.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": 25.8275862069, "max_line_length": 96, "alphanum_fraction": 0.6889185581, "num_tokens": 212, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789457685656, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.6568824133514652}} {"text": " function quad(x,y,u)\nc-------------------------------------------------------------------\nc quad does a simple quadratic interpolation by lagranges \nc formula \nc \nc arguments- \nc \nc x-array of abscissa values (length at least 3)\nc y-corresponding ordinate values \nc (quad fits a parabola through the three given point of x and y) \nc u-abscissa value to evaluate y value at \nc---------------------------------------------------------------------- \n dimension x(3),y(3) \n dx31=x(3)-x(1)\n dx32=x(3)-x(2)\n dx21=x(2)-x(1)\n dux3=u-x(3) \n dux2=u-x(2) \n dux1=u-x(1) \n quad = ((dux2*dux3)/(dx21*dx31)) * y(1) \n 1 - ((dux1*dux3)/(dx21*dx32)) * y(2) \n 2 + ((dux1*dux2)/(dx31*dx32)) * y(3) \n return\n end \n\nc $Id$ \n", "meta": {"hexsha": "7fadf47968f82941eeba65259021972b21e6d5d1", "size": 799, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "lib/location/libglp/quad.f", "max_stars_repo_name": "jreyes1108/antelope_contrib", "max_stars_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_stars_repo_licenses": ["BSD-2-Clause", "MIT"], "max_stars_count": 30, "max_stars_repo_stars_event_min_datetime": "2015-02-20T21:44:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-27T02:53:14.000Z", "max_issues_repo_path": "lib/location/libglp/quad.f", "max_issues_repo_name": "jreyes1108/antelope_contrib", "max_issues_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_issues_repo_licenses": ["BSD-2-Clause", "MIT"], "max_issues_count": 14, "max_issues_repo_issues_event_min_datetime": "2015-07-07T19:17:24.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-19T19:18:53.000Z", "max_forks_repo_path": "lib/location/libglp/quad.f", "max_forks_repo_name": "jreyes1108/antelope_contrib", "max_forks_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_forks_repo_licenses": ["BSD-2-Clause", "MIT"], "max_forks_count": 46, "max_forks_repo_forks_event_min_datetime": "2015-02-06T16:22:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T11:46:37.000Z", "avg_line_length": 29.5925925926, "max_line_length": 72, "alphanum_fraction": 0.4568210263, "num_tokens": 249, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894604912848, "lm_q2_score": 0.7341195152660687, "lm_q1q2_score": 0.6568824050010491}} {"text": "! Demonstrate a do loop\r\nprogram loop\r\nimplicit none\r\ninteger :: i,ssq\r\nssq = 0\r\ndo i=1,5\r\n ssq = ssq + i**2\r\nend do\r\nprint*,\"sum of squares is \",ssq ! 1 + 4 + 9 + 16 + 25 = 55\r\nend program loop", "meta": {"hexsha": "04078bc1e183bb65076eb3d8d3b5432da602ab2c", "size": 196, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "loop.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": "loop.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": "loop.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": 19.6, "max_line_length": 59, "alphanum_fraction": 0.6071428571, "num_tokens": 79, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8080672320414787, "lm_q2_score": 0.8128673110375458, "lm_q1q2_score": 0.6568514380471093}} {"text": "c comment section\nc\nc fm031\nc\nc this routine tests arithmetic assignment statements of the\nc form\nc integer variable = arithmetic expression\nc where the arithmetic expression is formed with the arithmetic\nc operator -, integer constants and integer variables. some of the\nc tests use parentheses to group elements in an arithmetic\nc expression.\nc\nc there are tests where the arithmetic expression contains\nc (1) integer constant-integer constant-integer variable\nc integer constant-integer variable-integer constant\nc integer variable-integer constant-integer constant\nc (2) same as (1) but with parentheses to group elements\nc in arithmetic expression.\nc (3) integer variable - integer variable\nc\nc references\nc american national standard programming language fortran,\nc x3.9-1978\nc\nc section 4.3, integer type\nc section 4.3.1, integer constant\nc section 6.1, arithmetic expressions\nc section 10.1, arithmetic assignment statement\nc\nc **********************************************************\nc\nc a compiler validation system for the fortran language\nc based on specifications as defined in american national standard\nc programming language fortran x3.9-1978, has been developed by the\nc federal cobol compiler testing service. the fortran compiler\nc validation system (fcvs) consists of audit routines, their related\nc data, and an executive system. each audit routine is a fortran\nc program, subprogram or function which includes tests of specific\nc language elements and supporting procedures indicating the result\nc of executing these tests.\nc\nc this particular program/subprogram/function contains features\nc found only in the subset as defined in x3.9-1978.\nc\nc suggestions and comments should be forwarded to -\nc\nc department of the navy\nc federal cobol compiler testing service\nc washington, d.c. 20376\nc\nc **********************************************************\nc\nc\nc\nc initialization section\nc\nc initialize constants\nc **************\nc i01 contains the logical unit number for the card reader.\n i01 = 5\nc i02 contains the logical unit number for the printer.\n i02 = 6\nc system environment section\nc\ncx010 this card is replaced by contents of fexec x-010 control card.\nc the cx010 card is for overriding the program default i01 = 5\nc (unit number for card reader).\ncx011 this card is replaced by contents of fexec x-011 control card.\nc the cx011 card is for systems which require additional\nc fortran statements for files associated with cx010 above.\nc\ncx020 this card is replaced by contents of fexec x-020 control card.\nc the cx020 card is for overriding the program default i02 = 6\nc (unit number for printer).\ncx021 this card is replaced by contents of fexec x-021 control card.\nc the cx021 card is for systems which require additional\nc fortran statements for files associated with cx020 above.\nc\n ivpass=0\n ivfail=0\n ivdele=0\n iczero=0\nc\nc write page headers\n write (i02,90000)\n write (i02,90001)\n write (i02,90002)\n write (i02, 90002)\n write (i02,90003)\n write (i02,90002)\n write (i02,90004)\n write (i02,90002)\n write (i02,90011)\n write (i02,90002)\n write (i02,90002)\n write (i02,90005)\n write (i02,90006)\n write (i02,90002)\nc\nc test section\nc\nc test 300 through test 309 contain 2 integer constants, an integer\nc variable and operator - in an arithmetic expression.\nc\n 3001 continue\n ivtnum = 300\nc\nc **** test 300 ****\nc\n if (iczero) 33000, 3000, 33000\n 3000 continue\n ivon01 = 9\n ivcomp =ivon01 -3 -4\n go to 43000\n33000 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 43000, 3011, 43000\n43000 if (ivcomp-2) 23000,13000,23000\n13000 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 3011\n23000 ivfail = ivfail + 1\n ivcorr =2\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 3011 continue\n ivtnum = 301\nc\nc **** test 301 ****\nc\n if (iczero) 33010, 3010, 33010\n 3010 continue\n ivon02 =3\n ivcomp =9-ivon02-4\n go to 43010\n33010 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 43010, 3021, 43010\n43010 if (ivcomp-2) 23010,13010,23010\n13010 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 3021\n23010 ivfail = ivfail + 1\n ivcorr =2\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 3021 continue\n ivtnum = 302\nc\nc **** test 302 ****\nc\n if (iczero) 33020, 3020, 33020\n 3020 continue\n ivon03 = 4\n ivcomp = 9-3-ivon03\n go to 43020\n33020 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 43020, 3031, 43020\n43020 if (ivcomp-2) 23020,13020,23020\n13020 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 3031\n23020 ivfail = ivfail + 1\n ivcorr =2\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 3031 continue\n ivtnum = 303\nc\nc **** test 303 ****\nc\n if (iczero) 33030, 3030, 33030\n 3030 continue\n ivon01 = 57\n ivcomp = ivon01 -25-22\n go to 43030\n33030 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 43030, 3041, 43030\n43030 if (ivcomp-10) 23030,13030,23030\n13030 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 3041\n23030 ivfail = ivfail + 1\n ivcorr = 10\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 3041 continue\n ivtnum = 304\nc\nc **** test 304 ****\nc\n if (iczero) 33040, 3040, 33040\n 3040 continue\n ivon02 =683\n ivcomp = 101-ivon02-156\n go to 43040\n33040 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 43040, 3051, 43040\n43040 if (ivcomp+738) 23040,13040,23040\n13040 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 3051\n23040 ivfail = ivfail + 1\n ivcorr = -738\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 3051 continue\n ivtnum = 305\nc\nc **** test 305 ****\nc\n if (iczero) 33050, 3050, 33050\n 3050 continue\n ivon03 = 1289\n ivcomp = 8542-1122-ivon03\n go to 43050\n33050 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 43050, 3061, 43050\n43050 if (ivcomp-6131) 23050,13050,23050\n13050 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 3061\n23050 ivfail = ivfail + 1\n ivcorr = 6131\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 3061 continue\n ivtnum = 306\nc\nc **** test 306 ****\nc\n if (iczero) 33060, 3060, 33060\n 3060 continue\n ivon03 = 11111\n ivcomp = 32333-11111-ivon03\n go to 43060\n33060 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 43060, 3071, 43060\n43060 if (ivcomp-10111) 23060,13060,23060\n13060 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 3071\n23060 ivfail = ivfail + 1\n ivcorr =10111\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 3071 continue\n ivtnum = 307\nc\nc **** test 307 ****\nc\n if (iczero) 33070, 3070, 33070\n 3070 continue\n ivon01 = -3\n ivcomp = ivon01-2-4\n go to 43070\n33070 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 43070, 3081, 43070\n43070 if (ivcomp +9) 23070,13070,23070\n13070 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 3081\n23070 ivfail = ivfail + 1\n ivcorr =-9\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 3081 continue\n ivtnum = 308\nc\nc **** test 308 ****\nc\n if (iczero) 33080, 3080, 33080\n 3080 continue\n ivon02 =-9\n ivcomp =1-ivon02-4\n go to 43080\n33080 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 43080, 3091, 43080\n43080 if (ivcomp-6) 23080,13080,23080\n13080 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 3091\n23080 ivfail = ivfail + 1\n ivcorr = 6\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 3091 continue\n ivtnum = 309\nc\nc **** test 309 ****\nc\n if (iczero) 33090, 3090, 33090\n 3090 continue\n ivon03 = -8542\n ivcomp = 100-3-ivon03\n go to 43090\n33090 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 43090, 3101, 43090\n43090 if (ivcomp-8639) 23090,13090,23090\n13090 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 3101\n23090 ivfail = ivfail + 1\n ivcorr = 8639\n write (i02,80004) ivtnum, ivcomp ,ivcorr\nc\nc test 310 through test 319 contain 2 integer constants, an integer\nc variable and operator - in an arithmetic expression. parentheses\nc are used to group elements in the arithmetic expression.\nc\n 3101 continue\n ivtnum = 310\nc\nc **** test 310 ****\nc\n if (iczero) 33100, 3100, 33100\n 3100 continue\n ivon01 =9\n ivcomp = ivon01-(3-4)\n go to 43100\n33100 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 43100, 3111, 43100\n43100 if (ivcomp-10) 23100,13100,23100\n13100 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 3111\n23100 ivfail = ivfail + 1\n ivcorr=10\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 3111 continue\n ivtnum = 311\nc\nc **** test 311 ****\nc\n if (iczero) 33110, 3110, 33110\n 3110 continue\n ivon01=9\n ivcomp=(ivon01-3)-4\n go to 43110\n33110 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 43110, 3121, 43110\n43110 if (ivcomp-2) 23110,13110,23110\n13110 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 3121\n23110 ivfail = ivfail + 1\n ivcorr =2\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 3121 continue\n ivtnum = 312\nc\nc **** test 312 ****\nc\n if (iczero) 33120, 3120, 33120\n 3120 continue\n ivon02 = 3\n ivcomp = 9-(ivon02-4)\n go to 43120\n33120 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 43120, 3131, 43120\n43120 if (ivcomp-10) 23120,13120,23120\n13120 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 3131\n23120 ivfail = ivfail + 1\n ivcorr = 10\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 3131 continue\n ivtnum = 313\nc\nc **** test 313 ****\nc\n if (iczero) 33130, 3130, 33130\n 3130 continue\n ivon02 = 3\n ivcomp = (9-ivon02) -4\n go to 43130\n33130 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 43130, 3141, 43130\n43130 if (ivcomp-2) 23130,13130,23130\n13130 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 3141\n23130 ivfail = ivfail + 1\n ivcorr = 2\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 3141 continue\n ivtnum = 314\nc\nc **** test 314 ****\nc\n if (iczero) 33140, 3140, 33140\n 3140 continue\n ivon03 = 4\n ivcomp = 9 -(3-ivon03)\n go to 43140\n33140 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 43140, 3151, 43140\n43140 if (ivcomp-10) 23140,13140,23140\n13140 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 3151\n23140 ivfail = ivfail + 1\n ivcorr = 10\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 3151 continue\n ivtnum = 315\nc\nc **** test 315 ****\nc\n if (iczero) 33150, 3150, 33150\n 3150 continue\n ivon03 = 4\n ivcomp = (9-3)-ivon03\n go to 43150\n33150 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 43150, 3161, 43150\n43150 if (ivcomp-2) 23150,13150,23150\n13150 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 3161\n23150 ivfail = ivfail + 1\n ivcorr = 2\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 3161 continue\n ivtnum = 316\nc\nc **** test 316 ****\nc\n if (iczero) 33160, 3160, 33160\n 3160 continue\n ivon01 = -9\n ivcomp = (ivon01-3)-4\n go to 43160\n33160 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 43160, 3171, 43160\n43160 if (ivcomp +16) 23160,13160,23160\n13160 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 3171\n23160 ivfail = ivfail + 1\n ivcorr = -16\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 3171 continue\n ivtnum = 317\nc\nc **** test 317 ****\nc\n if (iczero) 33170, 3170, 33170\n 3170 continue\n ivon02 = -3\n ivcomp = 9-(ivon02-4)\n go to 43170\n33170 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 43170, 3181, 43170\n43170 if (ivcomp-16) 23170,13170,23170\n13170 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 3181\n23170 ivfail = ivfail + 1\n ivcorr = 16\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 3181 continue\n ivtnum = 318\nc\nc **** test 318 ****\nc\n if (iczero) 33180, 3180, 33180\n 3180 continue\n ivon03 = +4\n ivcomp = 9 - (3 - ivon03)\n go to 43180\n33180 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 43180, 3191, 43180\n43180 if (ivcomp - 10) 23180,13180,23180\n13180 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 3191\n23180 ivfail = ivfail + 1\n ivcorr= 10\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 3191 continue\n ivtnum = 319\nc\nc **** test 319 ****\nc\n if (iczero) 33190, 3190, 33190\n 3190 continue\n ivon02 = 11111\n ivcomp = (32333-ivon02) -11111\n go to 43190\n33190 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 43190, 3201, 43190\n43190 if (ivcomp - 10111) 23190,13190,23190\n13190 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 3201\n23190 ivfail = ivfail + 1\n ivcorr = 10111\n write (i02,80004) ivtnum, ivcomp ,ivcorr\nc\nc test 320 through test 329 contain 2 integer variables and\nc operator - in an arithmetic expression. the integer variables\nc contain positive and negative values.\nc\n 3201 continue\n ivtnum = 320\nc\nc **** test 320 ****\nc\n if (iczero) 33200, 3200, 33200\n 3200 continue\n ivon01 = 3\n ivon02 = 2\n ivcomp = ivon01 - ivon02\n go to 43200\n33200 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 43200, 3211, 43200\n43200 if (ivcomp - 1) 23200,13200,23200\n13200 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 3211\n23200 ivfail = ivfail + 1\n ivcorr = 1\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 3211 continue\n ivtnum = 321\nc\nc **** test 321 ****\nc\n if (iczero) 33210, 3210, 33210\n 3210 continue\n ivon01 =2\n ivon02 =3\n ivcomp = ivon01 - ivon02\n go to 43210\n33210 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 43210, 3221, 43210\n43210 if (ivcomp +1) 23210,13210,23210\n13210 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 3221\n23210 ivfail = ivfail + 1\n ivcorr = -1\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 3221 continue\n ivtnum = 322\nc\nc **** test 322 ****\nc\n if (iczero) 33220, 3220, 33220\n 3220 continue\n ivon01 = -2\n ivon02 = 3\n ivcomp = ivon01 - ivon02\n go to 43220\n33220 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 43220, 3231, 43220\n43220 if (ivcomp +5) 23220,13220,23220\n13220 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 3231\n23220 ivfail = ivfail + 1\n ivcorr =-5\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 3231 continue\n ivtnum = 323\nc\nc **** test 323 ****\nc\n if (iczero) 33230, 3230, 33230\n 3230 continue\n ivon01 = -2\n ivon02 = -3\n ivcomp = ivon01 - ivon02\n go to 43230\n33230 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 43230, 3241, 43230\n43230 if (ivcomp -1) 23230,13230,23230\n13230 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 3241\n23230 ivfail = ivfail + 1\n ivcorr = 1\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 3241 continue\n ivtnum = 324\nc\nc **** test 324 ****\nc\n if (iczero) 33240, 3240, 33240\n 3240 continue\n ivon01 = 51\n ivon02 = 52\n ivcomp = ivon01 - ivon02\n go to 43240\n33240 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 43240, 3251, 43240\n43240 if (ivcomp + 1) 23240,13240,23240\n13240 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 3251\n23240 ivfail = ivfail + 1\n ivcorr = -1\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 3251 continue\n ivtnum = 325\nc\nc **** test 325 ****\nc\n if (iczero) 33250, 3250, 33250\n 3250 continue\n ivon01 = 676\n ivon02 =-189\n ivcomp = ivon01 - ivon02\n go to 43250\n33250 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 43250, 3261, 43250\n43250 if (ivcomp - 865) 23250,13250,23250\n13250 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 3261\n23250 ivfail = ivfail + 1\n ivcorr = 865\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 3261 continue\n ivtnum = 326\nc\nc **** test 326 ****\nc\n if (iczero) 33260, 3260, 33260\n 3260 continue\n ivon01 = 1358\n ivon02 = -8001\n ivcomp = ivon01 - ivon02\n go to 43260\n33260 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 43260, 3271, 43260\n43260 if (ivcomp - 9359) 23260,13260,23260\n13260 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 3271\n23260 ivfail = ivfail + 1\n ivcorr = 9359\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 3271 continue\n ivtnum = 327\nc\nc **** test 327 ****\nc\n if (iczero) 33270, 3270, 33270\n 3270 continue\n ivon01 =-16383\n ivon02 = 16383\n ivcomp = ivon01 - ivon02\n go to 43270\n33270 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 43270, 3281, 43270\n43270 if (ivcomp + 32766) 23270,13270,23270\n13270 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 3281\n23270 ivfail = ivfail + 1\n ivcorr = -32766\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 3281 continue\n ivtnum = 328\nc\nc **** test 328 ****\nc\n if (iczero) 33280, 3280, 33280\n 3280 continue\n ivon01 = 9876\n ivon02 = 189\n ivcomp = ivon01 - ivon02\n go to 43280\n33280 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 43280, 3291, 43280\n43280 if (ivcomp - 9687) 23280,13280,23280\n13280 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 3291\n23280 ivfail = ivfail + 1\n ivcorr = 9687\n write (i02,80004) ivtnum, ivcomp ,ivcorr\n 3291 continue\n ivtnum = 329\nc\nc **** test 329 ****\nc\n if (iczero) 33290, 3290, 33290\n 3290 continue\n ivon01 = 11112\n ivon02 = 11112\n ivcomp = ivon01 - ivon02\n go to 43290\n33290 ivdele = ivdele + 1\n write (i02,80003) ivtnum\n if (iczero) 43290, 3301, 43290\n43290 if (ivcomp) 23290,13290,23290\n13290 ivpass = ivpass + 1\n write (i02,80001) ivtnum\n go to 3301\n23290 ivfail = ivfail + 1\n ivcorr = 0\n write (i02,80004) ivtnum, ivcomp ,ivcorr\nc\nc **** end of tests ****\n 3301 continue\nc\nc write page footings and run summaries\n99999 continue\n write (i02,90002)\n write (i02,90006)\n write (i02,90002)\n write (i02,90002)\n write (i02,90007)\n write (i02,90002)\n write (i02,90008) ivfail\n write (i02,90009) ivpass\n write (i02,90010) ivdele\nc\nc\nc terminate routine execution\n stop\nc\nc format statements for page headers\n90000 format (1h1)\n90002 format (1h )\n90001 format (1h ,10x,34hfortran compiler validation system)\n90003 format (1h ,21x,11hversion 1.0)\n90004 format (1h ,10x,38hfor official use only - copyright 1978)\n90005 format (1h ,5x,4htest,5x,9hpass/fail, 5x,8hcomputed,8x,7hcorrect)\n90006 format (1h ,5x,46h----------------------------------------------)\n90011 format (1h ,18x,17hsubset level test)\nc\nc format statements for run summaries\n90008 format (1h ,15x,i5,19h errors encountered)\n90009 format (1h ,15x,i5,13h tests passed)\n90010 format (1h ,15x,i5,14h tests deleted)\nc\nc format statements for test results\n80001 format (1h ,4x,i5,7x,4hpass)\n80002 format (1h ,4x,i5,7x,4hfail)\n80003 format (1h ,4x,i5,7x,7hdeleted)\n80004 format (1h ,4x,i5,7x,4hfail,10x,i6,9x,i6)\n80005 format (1h ,4x,i5,7x,4hfail,4x,e12.5,3x,e12.5)\nc\n90007 format (1h ,20x,20hend of program fm031)\n end\n", "meta": {"hexsha": "39b335a507830c6e47b9b508771f4b80a526e1fb", "size": 20166, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "usr.bin/f77/tests/tests/fm031.f", "max_stars_repo_name": "weiss/original-bsd", "max_stars_repo_head_hexsha": "b44636d7febc9dcf553118bd320571864188351d", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 114, "max_stars_repo_stars_event_min_datetime": "2015-01-18T22:55:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-17T10:45:02.000Z", "max_issues_repo_path": "usr.bin/f77/tests/tests/fm031.f", "max_issues_repo_name": "JamesLinus/original-bsd", "max_issues_repo_head_hexsha": "b44636d7febc9dcf553118bd320571864188351d", "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": "usr.bin/f77/tests/tests/fm031.f", "max_forks_repo_name": "JamesLinus/original-bsd", "max_forks_repo_head_hexsha": "b44636d7febc9dcf553118bd320571864188351d", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 29, "max_forks_repo_forks_event_min_datetime": "2015-11-03T22:05:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-08T15:36:37.000Z", "avg_line_length": 26.2236671001, "max_line_length": 72, "alphanum_fraction": 0.618565903, "num_tokens": 7860, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080672135527632, "lm_q2_score": 0.8128673223709252, "lm_q1q2_score": 0.6568514321763692}} {"text": "! { dg-do run }\n! { dg-options \"-ffree-form -std=legacy\" }\n!\n! Test DEC-style PARAMETER statements without parentheses in free form.\n!\n\nsubroutine sub1(t, x, y)\n implicit real(8) (A-H,O-Z)\n parameter (pi_1 = 3.141592654d0, f_1 = 3.d08)\n parameter pi_2 = 3.141592654d0, f_2 = 3.d08 ! legacy PARAMETER\n ! Note that if the parameter statements above are matched\n ! incorrectly as assignments, the below specification\n ! statements will be considered out-of-order and we see\n ! 'unexpected specification statement'. A PARAMETER\n ! statement should still be a specification statement.\n\n real(8), intent(in) :: t\n real(8), intent(out) :: x, y\n\n real(8), volatile :: two\n two = 2.0d0\n x = two * pi_1 * f_1 * t\n y = two * pi_2 * f_2 * t\n return\nend subroutine\n\nsubroutine sub2(t, x, y, z)\n implicit none\n real(8) :: pi_1, pi_2, f_1, f_2\n parameter (pi_1 = 3.141592654d0, f_1 = 3.d08)\n parameter pi_2 = 3.141592654d0, f_2 = 3.d08 ! legacy PARAMETER\n real(8), parameter :: pi_3 = 3.141592654d0, f_3 = 3.d08\n ! Ditto sub1\n\n real(8), intent(in) :: t\n real(8), intent(out) :: x, y, z\n\n real(8), volatile :: two\n two = 2.0d0\n x = two * pi_1 * f_1 * t\n y = two * pi_2 * f_2 * t\n z = two * pi_3 * f_3 * t\nend subroutine\n\nimplicit none\nreal(8) :: x1, x2, y1, y2, z2\nreal(8), volatile :: t\nt = 1.5e-6\n\ncall sub1(t, x1, y1)\ncall sub2(t, x2, y2, z2)\n\nwrite(*,'(4D18.5)') t, x1, y1\nwrite(*,'(4D18.5)') t, x2, y2, z2\n\nif (x1 .ne. x2 .or. y1 .ne. y2 &\n .or. x1 .ne. y1 .or. x2 .ne. y2 &\n .or. y2 .ne. z2) then\n STOP 1\nendif\n\nend\n", "meta": {"hexsha": "4586ff514ffae7b5d3fa0a17f9565ee33e85cb0c", "size": 1569, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/dec_parameter_2.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/dec_parameter_2.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/dec_parameter_2.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.9047619048, "max_line_length": 76, "alphanum_fraction": 0.6150414277, "num_tokens": 641, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080671950640465, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.6568514116526163}} {"text": "PROGRAM Test_SPCtoIFG\n\n USE Type_Kinds , ONLY: fp=>fp_kind\n USE Binary_File_Utility , ONLY: Open_Binary_File\n USE Message_Handler , ONLY: SUCCESS\n USE Fundamental_Constants, ONLY: PI\n USE FFT_Spectral_Utility , ONLY: SPCtoIFG\n IMPLICIT NONE\n ! Parameters\n CHARACTER(*), PARAMETER :: FILENAME='test_spc.bin'\n ! Variables\n REAL(fp), DIMENSION(:), ALLOCATABLE :: f\n REAL(fp), DIMENSION(:), ALLOCATABLE :: rSpc, iSpc\n COMPLEX(fp), DIMENSION(:), ALLOCATABLE :: spc\n REAL(fp), DIMENSION(:), ALLOCATABLE :: x\n COMPLEX(fp), DIMENSION(:), ALLOCATABLE :: ifg\n INTEGER :: fileId\n INTEGER :: n, n2\n INTEGER :: i, j, errStatus, ioStatus, allocStatus\n \n ! Read the spectral data\n WRITE(*,'(/5x,\"Reading input test spectrum...\")' )\n errStatus = Open_Binary_File( FILENAME, &\n fileId )\n IF ( errStatus /= SUCCESS ) THEN\n WRITE(*,*) 'Error opening test spectrum file.'\n STOP\n END IF\n READ(fileId) n ! The number of SPC points\n n2 = 2*(n-1) ! The number of IFG points\n ALLOCATE(f(n), rSpc(n), iSpc(n), spc(n), x(n2), ifg(n2), STAT=allocStatus)\n IF ( allocStatus /= 0 ) THEN\n WRITE(*,*) 'Error allocating arrays. STAT=',allocStatus\n STOP\n END IF\n READ(fileId)f ! Frequency data\n READ(fileId)rSpc ! Real part of SPC\n READ(fileId)iSpc ! Imaginary part of SPC\n CLOSE(fileId)\n\n ! Make the spectrum complex\n spc = CMPLX(rSpc,iSpc,fp)\n\n ! Call the routine\n WRITE(*,'(5x,\"Calling SPCtoIFG......\")' )\n errStatus=SPCtoIFG(f, Spc, x, ifg)\n IF ( errStatus /= SUCCESS ) THEN\n WRITE(*,*) 'Error in SPCtoIFG call'\n STOP\n END IF\n\n ! Output the SPC and IFG to a file\n WRITE(*,'(5x,\"Writing output file......\")' )\n errStatus = Open_Binary_File( 'Test_SPCtoIFG.bin', &\n fileId, &\n For_Output=1 )\n IF ( errStatus /= SUCCESS ) THEN\n WRITE(*,*) 'Error opening output results file.'\n STOP\n END IF\n ! The SPC data\n WRITE(fileId) n ! The number of SPC points\n WRITE(fileId) f ! Frequency data\n WRITE(fileId) rSpc ! Real part of SPC\n WRITE(fileId) iSpc ! Imaginary part of SPC\n ! The IFG data\n WRITE(fileId) n2 ! The number of IFG points\n WRITE(fileId) x ! Optical delay data\n WRITE(fileId) REAL(ifg,fp) ! Real part of IFG\n WRITE(fileId) AIMAG(ifg) ! Imaginary part of IFG\n CLOSE(fileId)\n \nEND PROGRAM Test_SPCtoIFG\n", "meta": {"hexsha": "3ea6da3acfc1c923a6763fadf16ed0c5f782660f", "size": 2446, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/Utility/FFT_Utility/Test_SPCtoIFG/Test_SPCtoIFG.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/Test_SPCtoIFG/Test_SPCtoIFG.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/Test_SPCtoIFG/Test_SPCtoIFG.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": 33.0540540541, "max_line_length": 76, "alphanum_fraction": 0.6177432543, "num_tokens": 773, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677737461006, "lm_q2_score": 0.7745833841649232, "lm_q1q2_score": 0.6568217478510505}} {"text": "\\ .( Loading Bubble Sort benchmark...) cr\n\n\\ A classical benchmark of an O(n**2) algorithm; Bubble sort\n\\\n\\ Part of the programs gathered by John Hennessy for the MIPS\n\\ RISC project at Stanford. Translated to forth by Marty Fraeman\n\\ Johns Hopkins University/Applied Physics Laboratory.\n\n\\ MM forth2c doesn't have it !\n: mybounds over + swap ;\n\n\\ 1 cells constant cell\n\nvariable seed ( -- addr)\n\n: initiate-seed ( -- ) 74755 seed ! ;\n: random ( -- n ) seed @ 1309 * 13849 + 65535 and dup seed ! ;\n\n6000 constant elements ( -- int)\n\nalign create thelist elements cells allot\n\n: initiate-list ( -- )\n thelist elements cells + thelist do random i ! 1 cells +loop\n;\n\n: dump-list ( -- )\n thelist elements cells + thelist do i @ . 1 cells +loop cr\n;\n\n: verify-list ( -- )\n thelist elements 1- cells mybounds do\n i 2@ > abort\" bubble-sort: not sorted\"\n 1 cells +loop\n;\n\n: bubble ( -- )\n\\ .\" bubbling...\" cr\n 1 elements 1 do\n thelist elements i - cells mybounds do\n i 2@ > if i 2@ swap i 2! then\n 1 cells +loop\n loop\n;\n\n: bubble-sort ( -- )\n initiate-seed\n initiate-list\n bubble\n verify-list\n;\n\n: bubble-with-flag ( -- )\n 1 elements 1 do\n -1 thelist elements i - cells mybounds do\n i 2@ > if i 2@ swap i 2! drop 0 then\n 1 cells +loop\n if leave then\n loop\n;\n\n: bubble-sort-with-flag ( -- )\n initiate-seed\n initiate-list\n bubble-with-flag\n verify-list\n;\n\n: main\t( -- )\n\t5 0 do bubble-sort loop\n\\\tbubble-sort-with-flag\n;\n\n\n", "meta": {"hexsha": "040778f7e06b22c98cd8e7d31d6f24a4476e659d", "size": 1461, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "bench/bubble-sort.f", "max_stars_repo_name": "amckewan/mcforth", "max_stars_repo_head_hexsha": "9c13abf10958fea1f5b10125206a8a485fa95001", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-01-31T14:43:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-31T14:43:13.000Z", "max_issues_repo_path": "bench/bubble-sort.f", "max_issues_repo_name": "amckewan/mcforth", "max_issues_repo_head_hexsha": "9c13abf10958fea1f5b10125206a8a485fa95001", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "bench/bubble-sort.f", "max_forks_repo_name": "amckewan/mcforth", "max_forks_repo_head_hexsha": "9c13abf10958fea1f5b10125206a8a485fa95001", "max_forks_repo_licenses": ["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.48, "max_line_length": 64, "alphanum_fraction": 0.643394935, "num_tokens": 444, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321983146848, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.6567775425342046}} {"text": "program Combsort_Demo\n implicit none\n\n integer, parameter :: num = 20\n real :: array(num)\n\n call random_seed\n call random_number(array)\n write(*,*) \"Unsorted array:-\"\n write(*,*) array\n write(*,*)\n call combsort(array)\n write(*,*) \"Sorted array:-\"\n write(*,*) array\n\ncontains\n\n subroutine combsort(a)\n\n real, intent(in out) :: a(:)\n real :: temp\n integer :: i, gap\n logical :: swapped = .true.\n\n gap = size(a)\n do while (gap > 1 .or. swapped)\n gap = gap / 1.3\n if (gap < 1) gap = 1\n swapped = .false.\n do i = 1, size(a)-gap\n if (a(i) > a(i+gap)) then\n temp = a(i)\n a(i) = a(i+gap)\n a(i+gap) = temp;\n swapped = .true.\n end if\n end do\n end do\n\n end subroutine combsort\n\nend program Combsort_Demo\n", "meta": {"hexsha": "143d8d82fba3dcada0e219f90e46a58938f84b6a", "size": 803, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Sorting-algorithms-Comb-sort/Fortran/sorting-algorithms-comb-sort.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Sorting-algorithms-Comb-sort/Fortran/sorting-algorithms-comb-sort.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Sorting-algorithms-Comb-sort/Fortran/sorting-algorithms-comb-sort.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.6744186047, "max_line_length": 35, "alphanum_fraction": 0.5392278954, "num_tokens": 257, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.6567775331170166}} {"text": "program t\n integer :: a(10,10)\n integer :: n =10,i,j\n\n do i = 1,n,1\n do j = 1,n,1\n a(i,j) = i * j + 3\n end do\n end do\n i = 10\n j = 10\n call dummy(a,n,i,j)\nend program t\n\nsubroutine dummy(vin, n,i,j)\n integer,intent(inout) :: vin(10,10),n,i,j\n \n IF (n == 10) THEN\n do i = 1,n,1\n do j = 1,n,1\n print *,vin(j,i)\n end do\n end do\n END IF\n call printOthers(n,i,j)\nend subroutine dummy\n\nsubroutine printOthers(n,i,j)\n integer,intent(in) :: n,i,j\n \n PRINT *, n,i,j\nend subroutine printOthers\n", "meta": {"hexsha": "06d959de0e0ab1bf92e9e11a5e3895b9fe9f3819", "size": 536, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/output_tests/subroutines1.f90", "max_stars_repo_name": "clementval/fc", "max_stars_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/output_tests/subroutines1.f90", "max_issues_repo_name": "clementval/fc", "max_issues_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/output_tests/subroutines1.f90", "max_forks_repo_name": "clementval/fc", "max_forks_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.2424242424, "max_line_length": 43, "alphanum_fraction": 0.5503731343, "num_tokens": 207, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321796478256, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.6567775309329206}} {"text": "c { dg-do run }\n program foo\n complex(kind=8) z0, z1, z2\n\n z0 = dcmplx(0.,.5)\n z1 = 1./z0\n if (z1 .ne. dcmplx(0.,-2)) call abort\n\n z0 = 10.*z0\n if (z0 .ne. dcmplx(0.,5.)) call abort\n\n z2 = cmplx(1.,2.)\n z1 = z0/z2\n if (z1 .ne. dcmplx(2.,1.)) call abort\n\n z1 = z0*z2\n if (z1 .ne. dcmplx(-10.,5.)) call abort\n end\n\n", "meta": {"hexsha": "f25e7c570bd95aec737a93611ec93a1875e185be", "size": 383, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/g77/dcomplex.f", "max_stars_repo_name": "maurizioabba/rose", "max_stars_repo_head_hexsha": "7597292cf14da292bdb9a4ef573001b6c5b9b6c0", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/g77/dcomplex.f", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/g77/dcomplex.f", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 19.15, "max_line_length": 45, "alphanum_fraction": 0.454308094, "num_tokens": 171, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.815232480373843, "lm_q2_score": 0.8056321819811829, "lm_q1q2_score": 0.656777521985511}} {"text": "c\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc . .\nc . copyright (c) 1998 by UCAR .\nc . .\nc . University Corporation for Atmospheric Research .\nc . .\nc . all rights reserved .\nc . .\nc . .\nc . SPHEREPACK .\nc . .\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc\nc\nc ... file shsec.f\nc\nc this file contains code and documentation for subroutines\nc shsec and shseci\nc\nc ... files which must be loaded with shsec.f\nc\nc sphcom.f, hrfft.f\nc\nc subroutine shsec(nlat,nlon,isym,nt,g,idg,jdg,a,b,mdab,ndab,\nc + wshsec,lshsec,work,lwork,ierror)\nc\nc subroutine shsec performs the spherical harmonic synthesis\nc on the arrays a and b and stores the result in the array g.\nc the synthesis is performed on an equally spaced grid. the\nc associated legendre functions are recomputed rather than stored\nc as they are in subroutine shses. the synthesis is described\nc below at output parameter g.\nc\nc required files from spherepack2\nc\nc sphcom.f, hrfft.f\nc\nc\nc input parameters\nc\nc nlat the number of colatitudes on the full sphere including the\nc poles. for example, nlat = 37 for a five degree grid.\nc nlat determines the grid increment in colatitude as\nc pi/(nlat-1). if nlat is odd the equator is located at\nc grid point i=(nlat+1)/2. if nlat is even the equator is\nc located half way between points i=nlat/2 and i=nlat/2+1.\nc nlat must be at least 3. note: on the half sphere, the\nc number of grid points in the colatitudinal direction is\nc nlat/2 if nlat is even or (nlat+1)/2 if nlat is odd.\nc\nc nlon the number of distinct londitude points. nlon determines\nc the grid increment in longitude as 2*pi/nlon. for example\nc nlon = 72 for a five degree grid. nlon must be greater\nc than or equal to 4. the efficiency of the computation is\nc improved when nlon is a product of small prime numbers.\nc\nc isym = 0 no symmetries exist about the equator. the synthesis\nc is performed on the entire sphere. i.e. on the\nc array g(i,j) for i=1,...,nlat and j=1,...,nlon.\nc (see description of g below)\nc\nc = 1 g is antisymmetric about the equator. the synthesis\nc is performed on the northern hemisphere only. i.e.\nc if nlat is odd the synthesis is performed on the\nc array g(i,j) for i=1,...,(nlat+1)/2 and j=1,...,nlon.\nc if nlat is even the synthesis is performed on the\nc array g(i,j) for i=1,...,nlat/2 and j=1,...,nlon.\nc\nc\nc = 2 g is symmetric about the equator. the synthesis is\nc performed on the northern hemisphere only. i.e.\nc if nlat is odd the synthesis is performed on the\nc array g(i,j) for i=1,...,(nlat+1)/2 and j=1,...,nlon.\nc if nlat is even the synthesis is performed on the\nc array g(i,j) for i=1,...,nlat/2 and j=1,...,nlon.\nc\nc nt the number of syntheses. in the program that calls shsec,\nc the arrays g,a and b can be three dimensional in which\nc case multiple syntheses will be performed. the third\nc index is the synthesis index which assumes the values\nc k=1,...,nt. for a single synthesis set nt=1. the\nc discription of the remaining parameters is simplified\nc by assuming that nt=1 or that the arrays g,a and b\nc have only two dimensions.\nc\nc idg the first dimension of the array g as it appears in the\nc program that calls shsec. if isym equals zero then idg\nc must be at least nlat. if isym is nonzero then idg\nc must be at least nlat/2 if nlat is even or at least\nc (nlat+1)/2 if nlat is odd.\nc\nc jdg the second dimension of the array g as it appears in the\nc program that calls shsec. jdg must be at least nlon.\nc\nc a,b two or three dimensional arrays (see the input parameter\nc nt) that contain the coefficients in the spherical harmonic\nc expansion of g(i,j) given below at the definition of the\nc output parameter g. a(m,n) and b(m,n) are defined for\nc indices m=1,...,mmax and n=m,...,nlat where mmax is the\nc maximum (plus one) longitudinal wave number given by\nc mmax = min0(nlat,(nlon+2)/2) if nlon is even or\nc mmax = min0(nlat,(nlon+1)/2) if nlon is odd.\nc\nc mdab the first dimension of the arrays a and b as it appears\nc in the program that calls shsec. mdab must be at least\nc min0(nlat,(nlon+2)/2) if nlon is even or at least\nc min0(nlat,(nlon+1)/2) if nlon is odd.\nc\nc ndab the second dimension of the arrays a and b as it appears\nc in the program that calls shsec. ndab must be at least nlat\nc\nc wshsec an array which must be initialized by subroutine shseci.\nc once initialized, wshsec can be used repeatedly by shsec\nc as long as nlon and nlat remain unchanged. wshsec must\nc not be altered between calls of shsec.\nc\nc lshsec the dimension of the array wshsec as it appears in the\nc program that calls shsec. define\nc\nc l1 = min0(nlat,(nlon+2)/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc and\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc then lshsec must be at least\nc\nc 2*nlat*l2+3*((l1-2)*(nlat+nlat-l1-1))/2+nlon+15\nc\nc\nc work a work array that does not have to be saved.\nc\nc lwork the dimension of the array work as it appears in the\nc program that calls shsec. define\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc if isym is zero then lwork must be at least\nc\nc nlat*(nt*nlon+max0(3*l2,nlon))\nc\nc if isym is not zero then lwork must be at least\nc\nc l2*(nt*nlon+max0(3*nlat,nlon))\nc\nc **************************************************************\nc\nc output parameters\nc\nc g a two or three dimensional array (see input parameter\nc nt) that contains the spherical harmonic synthesis of\nc the arrays a and b at the colatitude point theta(i) =\nc (i-1)*pi/(nlat-1) and longitude point phi(j) =\nc (j-1)*2*pi/nlon. the index ranges are defined above at\nc at the input parameter isym. for isym=0, g(i,j) is\nc given by the the equations listed below. symmetric\nc versions are used when isym is greater than zero.\nc\nc the normalized associated legendre functions are given by\nc\nc pbar(m,n,theta) = sqrt((2*n+1)*factorial(n-m)/(2*factorial(n+m)))\nc *sin(theta)**m/(2**n*factorial(n)) times the\nc (n+m)th derivative of (x**2-1)**n with respect\nc to x=cos(theta)\nc\nc define the maximum (plus one) longitudinal wave number\nc as mmax = min0(nlat,(nlon+2)/2) if nlon is even or\nc mmax = min0(nlat,(nlon+1)/2) if nlon is odd.\nc\nc then g(i,j) = the sum from n=0 to n=nlat-1 of\nc\nc .5*pbar(0,n,theta(i))*a(1,n+1)\nc\nc plus the sum from m=1 to m=mmax-1 of\nc\nc the sum from n=m to n=nlat-1 of\nc\nc pbar(m,n,theta(i))*(a(m+1,n+1)*cos(m*phi(j))\nc -b(m+1,n+1)*sin(m*phi(j)))\nc\nc\nc ierror = 0 no errors\nc = 1 error in the specification of nlat\nc = 2 error in the specification of nlon\nc = 3 error in the specification of isym\nc = 4 error in the specification of nt\nc = 5 error in the specification of idg\nc = 6 error in the specification of jdg\nc = 7 error in the specification of mdab\nc = 8 error in the specification of ndab\nc = 9 error in the specification of lshsec\nc = 10 error in the specification of lwork\nc\nc\nc ****************************************************************\nc subroutine shseci(nlat,nlon,wshsec,lshsec,dwork,ldwork,ierror)\nc\nc subroutine shseci initializes the array wshsec which can then\nc be used repeatedly by subroutine shsec.\nc\nc input parameters\nc\nc nlat the number of colatitudes on the full sphere including the\nc poles. for example, nlat = 37 for a five degree grid.\nc nlat determines the grid increment in colatitude as\nc pi/(nlat-1). if nlat is odd the equator is located at\nc grid point i=(nlat+1)/2. if nlat is even the equator is\nc located half way between points i=nlat/2 and i=nlat/2+1.\nc nlat must be at least 3. note: on the half sphere, the\nc number of grid points in the colatitudinal direction is\nc nlat/2 if nlat is even or (nlat+1)/2 if nlat is odd.\nc\nc nlon the number of distinct londitude points. nlon determines\nc the grid increment in longitude as 2*pi/nlon. for example\nc nlon = 72 for a five degree grid. nlon must be greater\nc than or equal to 4. the efficiency of the computation is\nc improved when nlon is a product of small prime numbers.\nc\nc lshsec the dimension of the array wshsec as it appears in the\nc program that calls shseci. the array wshsec is an output\nc parameter which is described below. define\nc\nc l1 = min0(nlat,(nlon+2)/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc and\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc then lshsec must be at least\nc\nc 2*nlat*l2+3*((l1-2)*(nlat+nlat-l1-1))/2+nlon+15\nc\nc dwork a double precision work array that does not have to be\nc saved.\nc\nc ldwork the dimension of array dwork as it appears in the program\nc that calls shseci. ldwork must be at least nlat+1.\nc\nc output parameters\nc\nc wshsec an array which is initialized for use by subroutine shsec.\nc once initialized, wshsec can be used repeatedly by shsec\nc as long as nlon and nlat remain unchanged. wshsec must\nc not be altered between calls of shsec.\nc\nc ierror = 0 no errors\nc = 1 error in the specification of nlat\nc = 2 error in the specification of nlon\nc = 3 error in the specification of lshsec\nc = 4 error in the specification of ldwork\nc\nc\nc ****************************************************************\n subroutine shsec(nlat,nlon,isym,nt,g,idg,jdg,a,b,mdab,ndab,\n 1 wshsec,lshsec,work,lwork,ierror)\n dimension g(idg,jdg,1),a(mdab,ndab,1),b(mdab,ndab,1),wshsec(1),\n 1 work(1)\n ierror = 1\n if(nlat.lt.3) return\n ierror = 2\n if(nlon.lt.4) return\n ierror = 3\n if(isym.lt.0 .or. isym.gt.2) return\n ierror = 4\n if(nt .lt. 0) return\n ierror = 5\n if((isym.eq.0 .and. idg.lt.nlat) .or.\n 1 (isym.ne.0 .and. idg.lt.(nlat+1)/2)) return\n ierror = 6\n if(jdg .lt. nlon) return\n ierror = 7\n mmax = min0(nlat,nlon/2+1)\n if(mdab .lt. mmax) return\n ierror = 8\n if(ndab .lt. nlat) return\n ierror = 9\n imid = (nlat+1)/2\n lzz1 = 2*nlat*imid\n labc = 3*((mmax-2)*(nlat+nlat-mmax-1))/2\n if(lshsec .lt. lzz1+labc+nlon+15) return\n ierror = 10\n ls = nlat\n if(isym .gt. 0) ls = imid\n nln = nt*ls*nlon\n if(lwork .lt. nln+max0(ls*nlon,3*nlat*imid)) return\n ierror = 0\n ist = 0\n if(isym .eq. 0) ist = imid\n iw1 = lzz1+labc+1\n call shsec1(nlat,isym,nt,g,idg,jdg,a,b,mdab,ndab,imid,ls,nlon,\n 1 work,work(ist+1),work(nln+1),work(nln+1),wshsec,wshsec(iw1))\n return\n end\n subroutine shsec1(nlat,isym,nt,g,idgs,jdgs,a,b,mdab,ndab,imid,\n 1 idg,jdg,ge,go,work,pb,walin,whrfft)\nc\nc whrfft must have at least nlon+15 locations\nc walin must have 3*l*imid + 3*((l-3)*l+2)/2 locations\nc zb must have 3*l*imid locations\nc\n dimension g(idgs,jdgs,1),a(mdab,ndab,1),b(mdab,ndab,1),\n 1 ge(idg,jdg,1),go(idg,jdg,1),pb(imid,nlat,3),walin(1),\n 3 whrfft(1),work(1)\n ls = idg\n nlon = jdg\n mmax = min0(nlat,nlon/2+1)\n mdo = mmax\n if(mdo+mdo-1 .gt. nlon) mdo = mmax-1\n nlp1 = nlat+1\n modl = mod(nlat,2)\n imm1 = imid\n if(modl .ne. 0) imm1 = imid-1\n do 80 k=1,nt\n do 80 j=1,nlon\n do 80 i=1,ls\n ge(i,j,k)=0.\n 80 continue\n if(isym .eq. 1) go to 125\n call alin (2,nlat,nlon,0,pb,i3,walin)\n do 100 k=1,nt\n do 100 np1=1,nlat,2\n do 100 i=1,imid\n ge(i,1,k)=ge(i,1,k)+a(1,np1,k)*pb(i,np1,i3)\n 100 continue\n ndo = nlat\n if(mod(nlat,2) .eq. 0) ndo = nlat-1\n do 110 mp1=2,mdo\n m = mp1-1\n call alin (2,nlat,nlon,m,pb,i3,walin)\n do 110 np1=mp1,ndo,2\n do 110 k=1,nt\n do 110 i=1,imid\n ge(i,2*mp1-2,k) = ge(i,2*mp1-2,k)+a(mp1,np1,k)*pb(i,np1,i3)\n ge(i,2*mp1-1,k) = ge(i,2*mp1-1,k)+b(mp1,np1,k)*pb(i,np1,i3)\n 110 continue\n if(mdo .eq. mmax .or. mmax .gt. ndo) go to 122\n call alin (2,nlat,nlon,mdo,pb,i3,walin)\n do 120 np1=mmax,ndo,2\n do 120 k=1,nt\n do 120 i=1,imid\n ge(i,2*mmax-2,k) = ge(i,2*mmax-2,k)+a(mmax,np1,k)*pb(i,np1,i3)\n 120 continue\n 122 if(isym .eq. 2) go to 155\n 125 call alin(1,nlat,nlon,0,pb,i3,walin)\n do 140 k=1,nt\n do 140 np1=2,nlat,2\n do 140 i=1,imm1\n go(i,1,k)=go(i,1,k)+a(1,np1,k)*pb(i,np1,i3)\n 140 continue\n ndo = nlat\n if(mod(nlat,2) .ne. 0) ndo = nlat-1\n do 150 mp1=2,mdo\n mp2 = mp1+1\n m = mp1-1\n call alin(1,nlat,nlon,m,pb,i3,walin)\n do 150 np1=mp2,ndo,2\n do 150 k=1,nt\n do 150 i=1,imm1\n go(i,2*mp1-2,k) = go(i,2*mp1-2,k)+a(mp1,np1,k)*pb(i,np1,i3)\n go(i,2*mp1-1,k) = go(i,2*mp1-1,k)+b(mp1,np1,k)*pb(i,np1,i3)\n 150 continue\n mp2 = mmax+1\n if(mdo .eq. mmax .or. mp2 .gt. ndo) go to 155\n call alin(1,nlat,nlon,mdo,pb,i3,walin)\n do 152 np1=mp2,ndo,2\n do 152 k=1,nt\n do 152 i=1,imm1\n go(i,2*mmax-2,k) = go(i,2*mmax-2,k)+a(mmax,np1,k)*pb(i,np1,i3)\n 152 continue\n 155 do 160 k=1,nt\n if(mod(nlon,2) .ne. 0) go to 157\n do 156 i=1,ls\n ge(i,nlon,k) = 2.*ge(i,nlon,k)\n 156 continue\n 157 call hrfftb(ls,nlon,ge(1,1,k),ls,whrfft,work)\n 160 continue\n if(isym .ne. 0) go to 180\n do 170 k=1,nt\n do 170 j=1,nlon\n do 175 i=1,imm1\n g(i,j,k) = .5*(ge(i,j,k)+go(i,j,k))\n g(nlp1-i,j,k) = .5*(ge(i,j,k)-go(i,j,k))\n 175 continue\n if(modl .eq. 0) go to 170\n g(imid,j,k) = .5*ge(imid,j,k)\n 170 continue\n return\n 180 do 185 k=1,nt\n do 185 i=1,imid\n do 185 j=1,nlon\n g(i,j,k) = .5*ge(i,j,k)\n 185 continue\n return\n end\nc subroutine shseci(nlat,nlon,wshsec,lshsec,dwork,ldwork,ierror)\nc\nc subroutine shseci initializes the array wshsec which can then\nc be used repeatedly by subroutine shsec.\nc\nc input parameters\nc\nc nlat the number of colatitudes on the full sphere including the\nc poles. for example, nlat = 37 for a five degree grid.\nc nlat determines the grid increment in colatitude as\nc pi/(nlat-1). if nlat is odd the equator is located at\nc grid point i=(nlat+1)/2. if nlat is even the equator is\nc located half way between points i=nlat/2 and i=nlat/2+1.\nc nlat must be at least 3. note: on the half sphere, the\nc number of grid points in the colatitudinal direction is\nc nlat/2 if nlat is even or (nlat+1)/2 if nlat is odd.\nc\nc nlon the number of distinct londitude points. nlon determines\nc the grid increment in longitude as 2*pi/nlon. for example\nc nlon = 72 for a five degree grid. nlon must be greater\nc than or equal to 4. the efficiency of the computation is\nc improved when nlon is a product of small prime numbers.\nc\nc lshsec the dimension of the array wshsec as it appears in the\nc program that calls shseci. the array wshsec is an output\nc parameter which is described below. define\nc\nc l1 = min0(nlat,(nlon+2)/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc and\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc then lshsec must be at least\nc\nc 2*nlat*l2+3*((l1-2)*(nlat+nlat-l1-1))/2+nlon+15\nc\nc dwork a double precision work array that does not have to be\nc saved.\nc\nc ldwork the dimension of array dwork as it appears in the program\nc that calls shseci. ldwork must be at least nlat+1.\nc\nc output parameters\nc\nc wshsec an array which is initialized for use by subroutine shsec.\nc once initialized, wshsec can be used repeatedly by shsec\nc as long as nlon and nlat remain unchanged. wshsec must\nc not be altered between calls of shsec.\nc\nc ierror = 0 no errors\nc = 1 error in the specification of nlat\nc = 2 error in the specification of nlon\nc = 3 error in the specification of lshsec\nc = 4 error in the specification of ldwork\nc\nc\nc ****************************************************************\n subroutine shseci(nlat,nlon,wshsec,lshsec,dwork,ldwork,ierror)\n dimension wshsec(*)\n double precision dwork(ldwork)\n ierror = 1\n if(nlat.lt.3) return\n ierror = 2\n if(nlon.lt.4) return\n ierror = 3\n imid = (nlat+1)/2\n mmax = min0(nlat,nlon/2+1)\n lzz1 = 2*nlat*imid\n labc = 3*((mmax-2)*(nlat+nlat-mmax-1))/2\n if(lshsec .lt. lzz1+labc+nlon+15) return\n ierror = 4\n if(ldwork .lt. nlat+1) return\n ierror = 0\n call alinit(nlat,nlon,wshsec,dwork)\n iw1 = lzz1+labc+1\n call hrffti(nlon,wshsec(iw1))\n return\n end\n", "meta": {"hexsha": "7e88618deda1641bc3e2df9ac685e75fc0bd153c", "size": 18915, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/shsec.f", "max_stars_repo_name": "jprules321/colas", "max_stars_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-09-09T20:54:58.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-28T02:56:41.000Z", "max_issues_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/shsec.f", "max_issues_repo_name": "jprules321/colas", "max_issues_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/shsec.f", "max_forks_repo_name": "jprules321/colas", "max_forks_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-05-10T14:22:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-02T00:26:31.000Z", "avg_line_length": 39.2427385892, "max_line_length": 72, "alphanum_fraction": 0.5648955855, "num_tokens": 6093, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037241905732, "lm_q2_score": 0.7090191399336402, "lm_q1q2_score": 0.656767069842928}} {"text": "C/MEMBR ADD NAME=IWAMAX,SSI=0\nc Copyright INRIA\n integer function iwamax(n,xr,xi,incx)\nc!but\nc\nc la fonction iwamax determine l'indice de la composante\nc de plus grande norme l1 d'un vecteur complexe dont les\nc parties reelles des composantes sont rangees dans le\nc vecteur double precision xr et les parties imaginaires\nc dans le vecteur xi.\nc\nc!liste d'appel\nc\nc integer function iwamax(n,xr,xi,incx)\nc\nc n: taille du vecteur\nc\nc xr, xi: vecteurs double precision qui contiennent,\nc respectivement, les parties reelles et imaginaires\nc des composantes du vecteur a traiter.\nc\nc incx: increment entre deux elements consecitifs des\nc vecteurs xr ou xi.\nc\nc!auteur\nc\nc cleve moler.- mathlab.\nc\nc!\n double precision xr(*),xi(*),s,p\nc index of norminf(x)\n k = 0\n if (n .le. 0) go to 20\n k = 1\n s = 0.0d+0\n ix = 1\n do 10 i = 1, n\n p = abs(xr(ix)) + abs(xi(ix))\n if (p .gt. s) k = i\n if (p .gt. s) s = p\n ix = ix + incx\n 10 continue\n 20 iwamax = k\n return\n end\n", "meta": {"hexsha": "62926f277ffedf150563729f7a57dc032e74433c", "size": 1103, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/calelm/iwamax.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/iwamax.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/iwamax.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": 23.9782608696, "max_line_length": 60, "alphanum_fraction": 0.6192203083, "num_tokens": 376, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916240341031, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.6567394070222758}} {"text": "!\n! miscset.f90\n! \n! Alex 9/13/2014\n!\n! Miscellaneous setup for the Discontinuous Galerkin Velocity Library code. \n! constains subroutines for generating grids, meshes, etc. in the velocity space \n! also subroutines for set up various complementary arrays and variables. \n!!!!!!!!!!!!!!!!!!!!!!!\n\nmodule DGV_miscset\n\nuse nrtype ! contains kind parameters (DP), (DP), (I4B) etc. \nimplicit none\n\ncontains\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! SetDGblzmGnodes\n! \n! This subroutine sets up the notes used in various integrations and \n! also used as ordinates/nodal values \n!\n! This subroutine uses parameters set by SetDGVParams\n!\n! This subroutine sets arrays used in other programs -- must be run before \n! SetDGVblzmmesh\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\nsubroutine SetGDVGnodes\nuse DGV_commvar, only: g_nds_all, g_wts_all, g_max_order, moments_u_gauss_nodes, moments_u_gauss_weights, &\n moments_u_gauss_order\nuse gaussian_mod\nuse gaussquad, only: gauss_rule\n\ninteger (I4B) :: loc_alloc_stat, info ! local variable to keep the allocation status\nreal (DP), dimension (:), allocatable :: ugn, ugw ! scratch arrays to create gauss nodes... \ninteger (I4B) :: i ! local counter\n\n!!!\n!!! Prepare the Gaussian nodes and weights in u variables !!!!!!!!!!!!!!!!!!!!!!\n! first we need to allocate the arrays to store gauss nodes and weights: \n!\n allocate (g_nds_all(1:g_max_order, 1:g_max_order), stat=loc_alloc_stat) \n !\n if (loc_alloc_stat >0) then \n print *, \"SetDGblzmGnodes: Allocation error for variable (g_nds_all)\"\n end if \n !\n allocate (g_wts_all(1:g_max_order, 1:g_max_order), stat=loc_alloc_stat) \n !\n if (loc_alloc_stat >0) then \n print *, \"SetDGblzmGnodes: Allocation error for variable (g_wts_all)\"\n end if \n !\n!!! reset the arrays to zeros:\ng_nds_all=0\ng_wts_all=0\n!!! \ng_nds_all(1,1)=0.0_DP\ng_wts_all(1,1)=2.0_DP\ndo i=2,g_max_order \n ! will need two scrap arrays... \n allocate (ugn(1:i), stat=loc_alloc_stat) \n !\n if (loc_alloc_stat >0) then \n print *, \"SetDGblzmGnodes: Allocation error for variable (ugn), i=\", i\n end if \n allocate (ugw(1:i), stat=loc_alloc_stat) \n !\n if (loc_alloc_stat >0) then \n print *, \"SetDGblzmGnodes: Allocation error for variable (ugw), i=\", i\n end if \ncall GauLeg(Real(-1,DP),Real(1,DP),ugn,ugw)\ng_nds_all(1:i,i)=ugn\ng_wts_all(1:i,i)=ugw\ndeallocate(ugn,ugw)\nend do \n ! We set the variables of moments_u_gauss_nodes, moments_u_gauss_weights\n \n allocate (moments_u_gauss_nodes(1:moments_u_gauss_order), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"SetDGblzmGnodes: Allocation error for variable (moments_u_gauss_nodes)\"\n end if \n !\n allocate (moments_u_gauss_weights(1:moments_u_gauss_order), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"SetDGblzmGnodes: Allocation error for variable (moments_u_gauss_nodes)\"\n end if \n if (moments_u_gauss_order == 1) then \n moments_u_gauss_nodes(:)= (/ 0.0_DP /)\n moments_u_gauss_weights(:)= (/ 2.0_DP /) \n else \n call GauLeg(Real(-1,DP),Real(1,DP),moments_u_gauss_nodes,moments_u_gauss_weights) ! the number of nodes/presition of the quadrature depends on the size of gnodes,gweights\n end if \n\nend subroutine SetGDVGnodes\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! SetDGVblzmmesh \n!\n! This subroutine sets up the meshes. Do not detouch from the main program \n! \n! This subroutine is highly dependent on the main program. It is created mainly \n! to organize the main program. \n! \n! The subroutine can not be called before the parameters \n! su,sv,sw,Mu,Mv,Mw, mesh_u_uniform, \n! moments_u_gauss_order are selected !!!!! \n! CALL this SUBROUTINE before other subroutines use varaibles su,Mu,svMv,sw,Mw.\n!\n! DO not call before arrays \n! moments_u_gauss_order,moments_u_gauss_nodes,moments_u_gauss_weights are selected! \n! \n! Most of the varaibles are looked up in the common_varaibles_module\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine SetDGVblzmmesh \nuse DGV_commvar, only: Mu, Mv, Mw, u_L, u_R, &\n v_L, v_R, w_L, w_R, grids_cap_u, grids_cap_v, grids_cap_w, grids_u, grids_v, grids_w, & \n mesh_u_uniform, u_nonuniform_mesh_type,&\n moments_u_gauss_nodes, mesh_v_uniform, mesh_w_uniform, & \n v_nonuniform_mesh_type,w_nonuniform_mesh_type\n\nintrinsic Min, Max, MinVal\n \ninteger (I4B) :: loc_alloc_stat ! to keep allocation status\ninteger (I4B) :: i,j ! local counter \ninteger (I4B) :: sml,smr ! parameters for umesh with small cells around zero sml -- levels of refinment and smr -- ratio of refinement\ninteger (I4B) :: mxgo,mugo ! local variables to keep the order of the gauss integration for the moments\nreal (DP) :: du ! local temp variables to store 1/3 smallest distance between nodes.\n \n ! we will setup the level zero meshes in u ( grids_u/_v/_w and grids_cap_u/_v/_w ) \n ! first the mesh in u\n allocate (grids_u(1:Mu+1), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"SetDGVblzmmesh: Allocation error for variable (grids_u)\"\n stop\n end if\n !\n allocate (grids_cap_u(1:1), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"SetDGVblzmmesh: Allocation error for variable (grids_cap_u)\"\n stop\n end if\n ! \n call OldCreateUmesh(grids_u,grids_cap_u,mesh_u_uniform,u_nonuniform_mesh_type,u_L,u_R)\n ! then mesh in v \n allocate (grids_v(1:Mv+1), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"SetDGVblzmmesh: Allocation error for variable (grids_v)\"\n stop\n end if\n !\n allocate (grids_cap_v(1:1), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"SetDGVblzmmesh: Allocation error for variable (grids_cap_v)\"\n stop\n end if\n ! \n call OldCreateUmesh(grids_v,grids_cap_v,mesh_v_uniform, v_nonuniform_mesh_type,v_L,v_R)\n ! now the mesh in w\n allocate (grids_w(1:Mw+1), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"SetDGVblzmmesh: Allocation error for variable (grids_w)\"\n stop\n end if\n !\n allocate (grids_cap_w(1:1), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"SetDGVblzmmesh: Allocation error for variable (grids_cap_w)\"\n stop\n end if\n ! \n call OldCreateUmesh(grids_w,grids_cap_w,mesh_w_uniform,w_nonuniform_mesh_type,w_L,w_R)\n !\n end subroutine SetDGVblzmmesh\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! SetDGVblzmmeshII\n!\n! This subroutine sets up the secondary meshes. Do not detouch from the main program \n! \n! This is a copy of the above subroutine, with the only change that it works with secondary mehses. \n! This is accomplished by re-naming variable in the USE commvar, only: statement. \n! \n! The suffix II in the name suggests that the subroutine works with the secondary mesh\n!\n! This subroutine is highly dependent on the common variables and preparatory subrouines. It is created mainly \n! to organize the main program. \n! \n! The subroutine can not be called before the parameters \n! suII,svII,swII,MuII,MvII,MwII, mesh_u_uniform, \n! moments_u_gauss_order are selected !!!!! \n! CALL this SUBROUTINE before other subroutines use varaibles suII,MuII,svII, MvII,swII,MwII.\n!\n! DO not call before arrays \n! moments_u_gauss_order,moments_u_gauss_nodes,moments_u_gauss_weights are selected! \n! \n! Most of the varaibles are looked up in the common varaibles module (DGV_commvar)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine SetDGVblzmmeshII \nuse DGV_commvar, only: Mu=>MuII, Mv=>MvII, Mw=>MwII, &\n u_L, u_R, v_L, v_R, w_L, w_R, &\n grids_cap_u=>grids_cap_uII, grids_cap_v=>grids_cap_vII, grids_cap_w=>grids_cap_wII, &\n grids_u=>grids_uII, grids_v=>grids_vII, grids_w=>grids_wII, & \n mesh_u_uniform, u_nonuniform_mesh_type,&\n moments_u_gauss_nodes, mesh_v_uniform, mesh_w_uniform, & \n v_nonuniform_mesh_type,w_nonuniform_mesh_type\n\nintrinsic Min, Max, MinVal\n \ninteger (I4B) :: loc_alloc_stat ! to keep allocation status\ninteger (I4B) :: i,j ! local counter \ninteger (I4B) :: sml,smr ! parameters for umesh with small cells around zero sml -- levels of refinment and smr -- ratio of refinement\ninteger (I4B) :: mxgo,mugo ! local variables to keep the order of the gauss integration for the moments\nreal (DP) :: du ! local temp variables to store 1/3 smallest distance between nodes.\n \n ! we will setup the level zero meshes in u ( grids_u/_v/_w and grids_cap_u/_v/_w ) \n ! first the mesh in u\n allocate (grids_u(1:Mu+1), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"SetDGVblzmmeshII: Allocation error for variable (grids_uII)\"\n stop\n end if\n !\n allocate (grids_cap_u(1:1), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"SetDGVblzmmeshII: Allocation error for variable (grids_cap_uII)\"\n stop\n end if\n ! \n call OldCreateUmesh(grids_u,grids_cap_u,mesh_u_uniform,u_nonuniform_mesh_type,u_L,u_R)\n ! then mesh in v \n allocate (grids_v(1:Mv+1), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"SetDGVblzmmeshII: Allocation error for variable (grids_vII)\"\n stop\n end if\n !\n allocate (grids_cap_v(1:1), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"SetDGVblzmmeshII: Allocation error for variable (grids_cap_vII)\"\n stop\n end if\n ! \n call OldCreateUmesh(grids_v,grids_cap_v,mesh_v_uniform, v_nonuniform_mesh_type,v_L,v_R)\n ! now the mesh in w\n allocate (grids_w(1:Mw+1), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"SetDGVblzmmeshII: Allocation error for variable (grids_wII)\"\n stop\n end if\n !\n allocate (grids_cap_w(1:1), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"SetDGVblzmmeshII: Allocation error for variable (grids_cap_wII)\"\n stop\n end if\n ! \n call OldCreateUmesh(grids_w,grids_cap_w,mesh_w_uniform,w_nonuniform_mesh_type,w_L,w_R)\n !\n end subroutine SetDGVblzmmeshII\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1\n!\n! Subroutine OldCreateUmesh \n! This subroutine is used to generate 1D meshes in the velocity variables \n! \n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\nsubroutine OldCreateUmesh(ugrid,ugrid_cap,mesh_u_uniform,u_nonuniform_mesh_type,u_L,u_R) \n!\nreal (DP), dimension (:), intent (out) :: ugrid\ninteger (I4B), dimension (:), intent (out) :: ugrid_cap\nlogical, intent(in) :: mesh_u_uniform\ninteger (I4B), intent (in) :: u_nonuniform_mesh_type\nreal (DP), intent (out) :: u_L, u_R\n! local variables: \ninteger (I4B) :: M ! number of cells in the grid\ninteger (I4B) :: i,j ! local counters\n!!!!!!!!!!!!!!!!!!!!!!!\ninteger (I4B) :: smr, sml ! refinement parameters for mesh of type 3\nreal (DP) :: du \n!!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1\nM=size(ugrid,1)-1\nugrid_cap(1) = M+1\n! \nif (mesh_u_uniform) then \n ugrid = (/ (u_L + (u_R-u_L)/Real(M,DP)*i, i=0,M) /) \n else\n select case (u_nonuniform_mesh_type)\n case (1) ! Unsupported \n print *, \"OldCreateUmesh: Unsupported type of mesh in velocity variable (u_nonuniform_mesh_type=1)\"\n stop\n case (2) ! This mesh is to be used with diffusive boundary conditions\n ! and will include the velocity of the wall, u_{w}=0 as a mesh point\n ! Only Static wall is implemented at this time! \n ! \n ! first, let us check that u_wall =0 is in the velocity interval \n if ((u_L > 0.0_DP) .or. (u_R < 0.0_DP)) then \n u_L = min (0.0_DP,u_L)\n u_R = max (0.0_DP,u_R)\n end if \n ! now we start to fill in the mesh:\n i=-M\n j=1\n ugrid(1)=u_L\n do while ( u_R - (u_R-u_L)/Real(M,DP)*i > (u_R-u_L)/Real(M,DP)/2 - 0.00000000001_DP ) \n if (i*(u_R-u_L)/Real(M,DP)-u_L > (u_R-u_L)/Real(M,DP)/2) then \n j=j+1\n ugrid(j)=i*(u_R-u_L)/Real(M,DP)\n end if \n i=i+1\n end do \n ugrid(M+1)=u_R\n ! now we have filled in the mesh:\n case (3) ! This mesh is to be used with diffusive boundary conditions\n ! and will include the velocity of the wall, u_{w}=0 as a mesh point\n ! also it will surround $u=0$ with small cells. The sizes of the sell are obtained \n ! by refining the size of biggest cells $smr^{sml}$ times. Here $smr$ -- is the \n ! refinement factor and $sml$ is the total level of reinements. \n ! Only Static wall is implemented at this time! \n ! \n ! First we set values for $smr$ and $sml$ \n smr=10\n sml=2\n if (2*sml > M-2) then\n print *, \"SetDGVblzmmesh: selected number of refinements 'sml' of mesh is too large for the given M\"\n stop\n end if\n ! now we need to evaluate the size of the largest cell. \n du=(u_R-u_L)/((M-2*sml) + 2.0_DP/Real(smr,DP)* &\n (1.0_DP/(Real(smr,DP)**sml)-1.0_DP)/(1.0_DP/Real(smr,DP)-1.0_DP))\n ! now we start to fill in the mesh:\n j=1\n ugrid(1) = u_L\n do while (ugrid(j) < - du*(1.0_DP/(Real(smr,DP)**sml) - 1.0_DP)/(1.0_DP/Real(smr,DP)-1.0_DP)/Real(smr,DP) - 0.00000000001_DP ) \n j=j+1\n ugrid(j)=ugrid(j-1)+du\n end do\n ! Now we fill in the small cells\n do i=1,sml\n j=j+1\n ugrid(j) = ugrid(j-1) + du/(Real(smr,DP)**i)\n end do \n ugrid(j)=0.0_DP ! Just to have it exact --- otherwise it is not zero, but 10^-13\n do i=sml,1,-1\n j=j+1\n ugrid(j) = ugrid(j-1) + du/(Real(smr,DP)**i)\n end do \n ! now the rest of the cells.\n do while (ugrid(j) < u_R - du - 0.00000000001_DP)\n j = j+1\n ugrid(j) = ugrid(j-1)+du\n end do\n ugrid(M+1) = u_R\n case default \n print *, \"SetDGVblzmmesh: Unknown type of mesh\"\n stop\n end select\n end if \nend subroutine OldCreateUmesh\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! Set3DCellsR_DGV\n!\n! This subroutine creates a 3D velocity mesh. \n!\n! The subroutine looks up the grids arrays and creates 3D cells from the grids arrays. \n! If more than one grid is defined, grids are treated as non-related. Their ierarchy is ignored -- actually it is \n! not known from the grids array rigth away and needs to be discovered by a painful process. So we just do not do it. \n! instead, we would like to use this subroutine to create zero level mesh and we will hope that we only have one grid at this point.\n! \n! Later, another subroutine may be called to create embedded grids. \n!\n! Depends on the main program (other subroutines must be exectured, first) \n! and the DGV_commvar. Before calling make sure su,sv,sw have been initialized!\n! Also make sure that 1D grids in velocity have been allocated and initialized. \n! \n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\nsubroutine Set3DCellsR_DGV\n\nuse DGV_commvar, only: grids_cap_u,grids_cap_v,grids_cap_w,grids_u,grids_v,grids_w,su,sv,sw\n!\ninteger (I4B) :: iu,iv,iw, ig ! some local counters\n\ninteger (I4B) :: mm,mx,igu,igv,igw ! local scrap counters, \n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! creating cells from whaterwer is already in the grids -- refinement will be applied later \n!\n\n! we assume that at least one grid of level zero is defined...\nif (size(grids_u,1) < 1) then \n print *, \"Set3DCellsR_DGV: Error, there seem to be no 1D grids_u/_v/_w defined.\"\n stop \nend if \nmm=(grids_cap_u(1)-1)*(grids_cap_v(1)-1)*(grids_cap_w(1)-1)\nif (mm < 1) then \n print *, \"Set3DCellsR_DGV: Error, at least one of the 1D grids_u/_v/_w defined.\"\n stop \nend if \n! create the cells arrays... \ncall AllocCellsArrsDGV(mm)\n! now we will need to populate the cells: \ncall FillCellsArrsDGV(1,mm, grids_u(1:grids_cap_u(1)),grids_v(1:grids_cap_v(1)),grids_w(1:grids_cap_w(1)),1,su,sv,sw)\n! set some counters in case we have more stuff to process...\nmx = mm ! this will accumulate the total number of the recorded cells ...\nigu=grids_cap_u(1)\nigv=grids_cap_v(1)\nigw=grids_cap_w(1)\n! now if there is more grids... we needs to continue to create cells... \ndo ig=2,size(grids_cap_u,1) ! all grids_u/_v/_w arrays are of the same length \n ! for each grid create cells... \n mm=(grids_cap_u(ig)-1)*(grids_cap_v(ig)-1)*(grids_cap_w(ig)-1) !! this is how many new cells will be on this grid\n ! extend the cells arrays to fit more cells ...\n call ExtendCellsArrsDGV(mx+mm)\n ! now we will need to populate the cells: \n call FillCellsArrsDGV(mx+1,mx+mm,grids_u(igu+1:igu+grids_cap_u(ig)),grids_v(igv+1:igv+grids_cap_v(ig)), & \n grids_w(igw+1:igw+grids_cap_w(ig)),ig,su,sv,sw)\n ! set some counters in case we have more stuff to process...\n mx = mx+mm ! this will accumulate the total number of the recorded cells ...\n igu=igu+grids_cap_u(ig)\n igv=igv+grids_cap_v(ig)\n igw=igw+grids_cap_w(ig)\n !\nend do \n\nend subroutine Set3DCellsR_DGV\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!! AllocCellsArrsDGV\n!! This is a \"macro\" subrouting to save some space in another subroutine. \n!! given the sizes, it allocates the arrays and returns emply arrays\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\nsubroutine AllocCellsArrsDGV(M)\nuse DGV_commvar, only: cells_pgrid, cells_cgrid, cells_lu, cells_lv, cells_lw, & \n cells_ru, cells_rv, cells_rw, cells_refu, cells_refv, & \n cells_refw, cells_gow, cells_gou, cells_gov\n\ninteger (I4B), intent (in) :: M ! The size of the arrays... \n!\ninteger (I4B) :: loc_alloc_stat\n!!!!!!!!!!!!!!\n!\nallocate (cells_pgrid(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"AllocCellsArrsDGV: Allocation error for variable (cells_pgrid)\"\n stop\n end if\nallocate (cells_cgrid(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"AllocCellsArrsDGV: Allocation error for variable (cells_cgrid)\"\n stop\n end if\nallocate (cells_lu(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"AllocCellsArrsDGV: Allocation error for variable (cells_lu)\"\n stop\n end if\nallocate (cells_lv(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"AllocCellsArrsDGV: Allocation error for variable (cells_lv)\"\n stop\n end if\nallocate (cells_lw(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"AllocCellsArrsDGV: Allocation error for variable (cells_lw)\"\n stop\n end if\nallocate (cells_ru(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"AllocCellsArrsDGV: Allocation error for variable (cells_ru)\"\n stop\n end if\nallocate (cells_rv(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"AllocCellsArrsDGV: Allocation error for variable (cells_rv)\"\n stop\n end if\nallocate (cells_rw(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"AllocCellsArrsDGV: Allocation error for variable (cells_rw)\"\n stop\n end if\nallocate (cells_refu(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"AllocCellsArrsDGV: Allocation error for variable (cells_refu)\"\n stop\n end if\nallocate (cells_refv(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"AllocCellsArrsDGV: Allocation error for variable (cells_refv)\"\n stop\n end if\nallocate (cells_refw(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"AllocCellsArrsDGV: Allocation error for variable (cells_refw)\"\n stop\n end if\nallocate (cells_gou(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"AllocCellsArrsDGV: Allocation error for variable (cells_gou)\"\n stop\n end if\nallocate (cells_gov(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"AllocCellsArrsDGV: Allocation error for variable (cells_gov)\"\n stop\n end if\nallocate (cells_gow(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"AllocCellsArrsDGV: Allocation error for variable (cells_gow)\"\n stop\n end if\nend subroutine AllocCellsArrsDGV\n\nsubroutine ExtendCellsArrsDGV(M)\nuse DGV_commvar, only: cells_pgrid, cells_cgrid, cells_lu, cells_lv, cells_lw, & \n cells_ru, cells_rv, cells_rw, cells_refu, cells_refv, & \n cells_refw, cells_gow, cells_gou, cells_gov\n\ninteger (I4B), intent (in) :: M ! The new size of the cells arrays... \n!\ninteger (I4B) :: loc_alloc_stat\ninteger (I4B) :: Md ! a crap variable to keed the old size \n!!!!!!!!!!!!!!\nreal (DP), dimension(:), allocatable ::cpg,ccg,clu,clv,clw,cru,crv,crw,&\n crefu,crefv,crefw,cgou,cgov,cgow \n\nMd=size(cells_pgrid, 1)\nif (Md>M) then \n print *, \"ExtendCellsArrsDGV: new size for arrays cells is smaller then the old one... \"\n stop\nend if\n!!!!\n!!!! \nallocate (cpg(1:Md),ccg(1:Md),clu(1:Md),clv(1:Md),clw(1:Md),cru(1:Md),crv(1:Md),crw(1:Md), stat=loc_alloc_stat)\n!\nif (loc_alloc_stat >0) then \n print *, \"ExtendCellsArrsDGV: Allocation error for variables cpg,ccg,clu,clv,clw,cru,crv,crw\"\n stop\n end if\nallocate (crefu(1:Md),crefv(1:Md),crefw(1:Md),cgou(1:Md),cgov(1:Md),cgow(1:Md),stat=loc_alloc_stat)\n!\nif (loc_alloc_stat >0) then \n print *, \"ExtendCellsArrsDGV: Allocation error for variables cells_refw, cells_gow, cells_gou, cells_gov\"\n stop\n end if\n! save the cells arrays in the temp arrays... \ncpg=cells_pgrid\nccg=cells_cgrid\nclu=cells_lu \nclv=cells_lv \nclw=cells_lw\ncru=cells_ru\ncrv=cells_rv\ncrw=cells_rw\ncrefu=cells_refu\ncrefv=cells_refv\ncrefw=cells_refw \ncgow=cells_gow\ncgou=cells_gou \ncgov=cells_gov\n! deallocate the old cells arrays... \ndeallocate (cells_pgrid, cells_cgrid, cells_lu, cells_lv, cells_lw, & \n cells_ru, cells_rv, cells_rw, cells_refu, cells_refv, & \n cells_refw, cells_gow, cells_gou, cells_gov)\n! now we allocate with the new size M \nallocate (cells_pgrid(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"ExtendCellsArrsDGV: Allocation error for variable (cells_pgrid)\"\n stop\n end if\nallocate (cells_cgrid(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"ExtendCellsArrsDGV: Allocation error for variable (cells_cgrid)\"\n stop\n end if\nallocate (cells_lu(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"ExtendCellsArrsDGV: Allocation error for variable (cells_lu)\"\n stop\n end if\nallocate (cells_lv(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"ExtendCellsArrsDGV: Allocation error for variable (cells_lv)\"\n stop\n end if\nallocate (cells_lw(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"ExtendCellsArrsDGV: Allocation error for variable (cells_lw)\"\n stop\n end if\nallocate (cells_ru(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"ExtendCellsArrsDGV: Allocation error for variable (cells_ru)\"\n stop\n end if\nallocate (cells_rv(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"ExtendCellsArrsDGV: Allocation error for variable (cells_rv)\"\n stop\n end if\nallocate (cells_rw(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"ExtendCellsArrsDGV: Allocation error for variable (cells_rw)\"\n stop\n end if\nallocate (cells_refu(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"ExtendCellsArrsDGV: Allocation error for variable (cells_refu)\"\n stop\n end if\nallocate (cells_refv(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"ExtendCellsArrsDGV Allocation error for variable (cells_refv)\"\n stop\n end if\nallocate (cells_refw(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"ExtendCellsArrsDGV: Allocation error for variable (cells_refw)\"\n stop\n end if\nallocate (cells_gou(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"ExtendCellsArrsDGV: Allocation error for variable (cells_gou)\"\n stop\n end if\nallocate (cells_gov(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"ExtendCellsArrsDGV: Allocation error for variable (cells_gov)\"\n stop\n end if\nallocate (cells_gow(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"ExtendCellsArrsDGV: Allocation error for variable (cells_gow)\"\n stop\n end if\n!! and the inverse assignment:\ncells_pgrid(1:Md)=cpg\ncells_cgrid(1:Md)=ccg\ncells_lu(1:Md)=clu\ncells_lv(1:Md)=clv\ncells_lw(1:Md)=clw\ncells_ru(1:Md)=cru\ncells_rv(1:Md)=crv\ncells_rw(1:Md)=crw\ncells_refu(1:Md)=crefu\ncells_refv(1:Md)=crefv\ncells_refw(1:Md)=crefw\ncells_gow(1:Md)=cgow\ncells_gou(1:Md)=cgou\ncells_gov(1:Md)=cgov\n!! the rest will be filled outside. \ndeallocate(cpg,ccg,clu,clv,clw,cru,crv,crw,crefu,crefv,crefw,cgou,cgov,cgow)\n \nend subroutine ExtendCellsArrsDGV\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! Set3DCellsR_DGVII\n!\n! This subroutine creates a 3D velocity mesh. \n!\n! This is a copy of the above subroutine, with the only change that it works with secondary mehses. \n! This is accomplished by re-naming variable in the USE commvar, only: statement. \n!\n! The suffix II in the name suggests that the subroutine works with the secondary mesh\n!\n! The subroutine looks up the grids arrays and creates 3D cells from the grids arrays. \n! If more than one grid is defined, grids are treated as non-related. Their ierarchy is ignored -- actually it is \n! not known from the grids array rigth away and needs to be discovered by a painful process. So we just do not do it. \n! instead, we would like to use this subroutine to create zero level mesh and we will hope that we only have one grid at this point.\n! \n! Later, another subroutine may be called to create embedded grids. \n!\n! Depends on the main program (other subroutines must be exectured, first) \n! and the D4GV_commvar. Before calling make sure suII,svII,swII have been initialized!\n! Also make sure that secondary 1D grids in velocity have been allocated and initialized. \n! \n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\nsubroutine Set3DCellsR_DGVII\n\nuse DGV_commvar, only: grids_cap_u=>grids_cap_uII, grids_cap_v=>grids_cap_vII, &\n grids_cap_w=>grids_cap_wII, & \n grids_u=>grids_uII, grids_v=>grids_vII, grids_w=>grids_wII, &\n su=>suII, sv=>svII, sw=>swII\n!\ninteger (I4B) :: iu,iv,iw, ig ! some local counters\n\ninteger (I4B) :: mm,mx,igu,igv,igw ! local scrap counters, \n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! creating cells from whaterwer is already in the grids -- refinement will be applied later \n!\n\n! we assume that at least one grid of level zero is defined...\nif (size(grids_u,1) < 1) then \n print *, \"Set3DCellsR_DGVII: Error, there seem to be no 1D grids_u/_v/_w defined.\"\n stop \nend if \nmm=(grids_cap_u(1)-1)*(grids_cap_v(1)-1)*(grids_cap_w(1)-1)\nif (mm < 1) then \n print *, \"Set3DCellsR_DGVII: Error, at least one of the 1D grids_u/_v/_w defined.\"\n stop \nend if \n! create the cells arrays... \ncall AllocCellsArrsDGVII(mm)\n! now we will need to populate the cells: \ncall FillCellsArrsDGVII(1,mm, grids_u(1:grids_cap_u(1)),grids_v(1:grids_cap_v(1)),grids_w(1:grids_cap_w(1)),1,su,sv,sw)\n! set some counters in case we have more stuff to process...\nmx = mm ! this will accumulate the total number of the recorded cells ...\nigu=grids_cap_u(1)\nigv=grids_cap_v(1)\nigw=grids_cap_w(1)\n! now if there is more grids... we needs to continue to create cells... \ndo ig=2,size(grids_cap_u,1) ! all grids_u/_v/_w arrays are of the same length \n ! for each grid create cells... \n mm=(grids_cap_u(ig)-1)*(grids_cap_v(ig)-1)*(grids_cap_w(ig)-1) !! this is how many new cells will be on this grid\n ! extend the cells arrays to fit more cells ...\n call ExtendCellsArrsDGVII(mx+mm)\n ! now we will need to populate the cells: \n call FillCellsArrsDGVII(mx+1,mx+mm,grids_u(igu+1:igu+grids_cap_u(ig)),grids_v(igv+1:igv+grids_cap_v(ig)), & \n grids_w(igw+1:igw+grids_cap_w(ig)),ig,su,sv,sw)\n ! set some counters in case we have more stuff to process...\n mx = mx+mm ! this will accumulate the total number of the recorded cells ...\n igu=igu+grids_cap_u(ig)\n igv=igv+grids_cap_v(ig)\n igw=igw+grids_cap_w(ig)\n !\nend do \n\nend subroutine Set3DCellsR_DGVII\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!! AllocCellsArrsDGVII\n!!\n!! This is a copy of the above subroutine, with the only change that it works with secondary mehses. \n!! This is accomplished by re-naming variable in the USE commvar, only: statement. \n!!\n!!\n!! The suffix II in the name suggests that the subroutine works with the secondary mesh\n!!\n!! This is a \"macro\" subrouting to save some space in another subroutine. \n!! given the sizes, it allocates the arrays and returns emply arrays\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\nsubroutine AllocCellsArrsDGVII(M)\n\nuse DGV_commvar, only: cells_pgridII, cells_cgridII, &\n cells_luII, cells_lvII, cells_lwII, & \n cells_ruII, cells_rvII, cells_rwII, &\n cells_refuII, cells_refvII, cells_refwII, &\n cells_gowII, cells_gouII, cells_govII\n\ninteger (I4B), intent (in) :: M ! The size of the arrays... \n!\ninteger (I4B) :: loc_alloc_stat\n!!!!!!!!!!!!!!\n!\nallocate (cells_pgridII(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"AllocCellsArrsDGVII: Allocation error for variable (cells_pgridIIII)\"\n stop\n end if\nallocate (cells_cgridII(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"AllocCellsArrsDGVII: Allocation error for variable (cells_cgridIIII)\"\n stop\n end if\nallocate (cells_luII(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"AllocCellsArrsDGVII: Allocation error for variable (cells_luIIII)\"\n stop\n end if\nallocate (cells_lvII(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"AllocCellsArrsDGVII: Allocation error for variable (cells_lvIIII)\"\n stop\n end if\nallocate (cells_lwII(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"AllocCellsArrsDGVII: Allocation error for variable (cells_lwIIII)\"\n stop\n end if\nallocate (cells_ruII(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"AllocCellsArrsDGVII: Allocation error for variable (cells_ruIIII)\"\n stop\n end if\nallocate (cells_rvII(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"AllocCellsArrsDGVII: Allocation error for variable (cells_rvIIII)\"\n stop\n end if\nallocate (cells_rwII(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"AllocCellsArrsDGVII: Allocation error for variable (cells_rwIIII)\"\n stop\n end if\nallocate (cells_refuII(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"AllocCellsArrsDGVII: Allocation error for variable (cells_refuIIII)\"\n stop\n end if\nallocate (cells_refvII(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"AllocCellsArrsDGVII: Allocation error for variable (cells_refvIIII)\"\n stop\n end if\nallocate (cells_refwII(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"AllocCellsArrsDGVII: Allocation error for variable (cells_refwIIII)\"\n stop\n end if\nallocate (cells_gouII(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"AllocCellsArrsDGVII: Allocation error for variable (cells_gouIIII)\"\n stop\n end if\nallocate (cells_govII(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"AllocCellsArrsDGVII: Allocation error for variable (cells_govIIII)\"\n stop\n end if\nallocate (cells_gowII(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"AllocCellsArrsDGVII: Allocation error for variable (cells_gowIIII)\"\n stop\n end if\nend subroutine AllocCellsArrsDGVII\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!! ExtendCellsArrsDGVII\n!! This is a \"macro\" subroutine to save some space in another subroutine. \n!! given the sizes, this subroutine extends the cells arrays\n!!\n!! This is a copy of an above subroutine, with the only change that it works with secondary mehses. \n!! This is accomplished by re-naming variable in the USE commvar, only: statement. \n!!\n!!\n!! The suffix II in the name suggests that the subroutine works with the secondary mesh\n!!\n!!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\nsubroutine ExtendCellsArrsDGVII(M)\n\nuse DGV_commvar, only: cells_pgrid => cells_pgridII, cells_cgrid => cells_cgridII, &\n cells_lu => cells_luII, cells_lv => cells_lvII, cells_lw => cells_lwII, &\n cells_ru => cells_ruII, cells_rv => cells_rvII, cells_rw => cells_rwII, &\n cells_refu => cells_refuII, cells_refv => cells_refvII, cells_refw => cells_refwII, &\n cells_gou=>cells_gouII, cells_gov=>cells_govII, cells_gow=>cells_gowII \n\ninteger (I4B), intent (in) :: M ! The new size of the cells arrays... \n!\ninteger (I4B) :: loc_alloc_stat\ninteger (I4B) :: Md ! a crap variable to keed the old size \n!!!!!!!!!!!!!!\nreal (DP), dimension(:), allocatable ::cpg,ccg,clu,clv,clw,cru,crv,crw,&\n crefu,crefv,crefw,cgou,cgov,cgow \n\nMd=size(cells_pgrid, 1)\nif (Md>M) then \n print *, \"ExtendCellsArrsDGVII: new size for arrays cells is smaller then the old one... \"\n stop\nend if\n!!!!\n!!!! \nallocate (cpg(1:Md),ccg(1:Md),clu(1:Md),clv(1:Md),clw(1:Md),cru(1:Md),crv(1:Md),crw(1:Md), stat=loc_alloc_stat)\n!\nif (loc_alloc_stat >0) then \n print *, \"ExtendCellsArrsDGVII: Allocation error for variables cpg,ccg,clu,clv,clw,cru,crv,crw\"\n stop\n end if\nallocate (crefu(1:Md),crefv(1:Md),crefw(1:Md),cgou(1:Md),cgov(1:Md),cgow(1:Md),stat=loc_alloc_stat)\n!\nif (loc_alloc_stat >0) then \n print *, \"ExtendCellsArrsDGVII: Allocation error for variables crefu, crefv, crefw, cgou, cgov, cgow\"\n stop\n end if\n! save the cells arrays in the temp arrays... \ncpg=cells_pgrid\nccg=cells_cgrid\nclu=cells_lu \nclv=cells_lv \nclw=cells_lw\ncru=cells_ru\ncrv=cells_rv\ncrw=cells_rw\ncrefu=cells_refu\ncrefv=cells_refv\ncrefw=cells_refw \ncgow=cells_gow\ncgou=cells_gou \ncgov=cells_gov\n! deallocate the old cells arrays... \ndeallocate (cells_pgrid, cells_cgrid, cells_lu, cells_lv, cells_lw, & \n cells_ru, cells_rv, cells_rw, cells_refu, cells_refv, & \n cells_refw, cells_gow, cells_gou, cells_gov)\n! now we allocate with the new size M \nallocate (cells_pgrid(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"ExtendCellsArrsDGVII: Allocation error for variable (cells_pgridII)\"\n stop\n end if\nallocate (cells_cgrid(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"ExtendCellsArrsDGVII: Allocation error for variable (cells_cgridII)\"\n stop\n end if\nallocate (cells_lu(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"ExtendCellsArrsDGVII: Allocation error for variable (cells_luII)\"\n stop\n end if\nallocate (cells_lv(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"ExtendCellsArrsDGVII: Allocation error for variable (cells_lvII)\"\n stop\n end if\nallocate (cells_lw(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"ExtendCellsArrsDGVII: Allocation error for variable (cells_lwII)\"\n stop\n end if\nallocate (cells_ru(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"ExtendCellsArrsDGVII: Allocation error for variable (cells_ruII)\"\n stop\n end if\nallocate (cells_rv(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"ExtendCellsArrsDGVII: Allocation error for variable (cells_rvII)\"\n stop\n end if\nallocate (cells_rw(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"ExtendCellsArrsDGVII: Allocation error for variable (cells_rwII)\"\n stop\n end if\nallocate (cells_refu(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"ExtendCellsArrsDGVII: Allocation error for variable (cells_refuII)\"\n stop\n end if\nallocate (cells_refv(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"ExtendCellsArrsDGVII: Allocation error for variable (cells_refvII)\"\n stop\n end if\nallocate (cells_refw(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"ExtendCellsArrsDGVII: Allocation error for variable (cells_refwII)\"\n stop\n end if\nallocate (cells_gou(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"ExtendCellsArrsDGVII: Allocation error for variable (cells_gouII)\"\n stop\n end if\nallocate (cells_gov(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"ExtendCellsArrsDGVII: Allocation error for variable (cells_govII)\"\n stop\n end if\nallocate (cells_gow(1:M), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"ExtendCellsArrsDGVII: Allocation error for variable (cells_gowII)\"\n stop\n end if\n!! and the inverse assignment:\ncells_pgrid(1:Md)=cpg\ncells_cgrid(1:Md)=ccg\ncells_lu(1:Md)=clu\ncells_lv(1:Md)=clv\ncells_lw(1:Md)=clw\ncells_ru(1:Md)=cru\ncells_rv(1:Md)=crv\ncells_rw(1:Md)=crw\ncells_refu(1:Md)=crefu\ncells_refv(1:Md)=crefv\ncells_refw(1:Md)=crefw\ncells_gow(1:Md)=cgow\ncells_gou(1:Md)=cgou\ncells_gov(1:Md)=cgov\n!! the rest will be filled outside. \ndeallocate(cpg,ccg,clu,clv,clw,cru,crv,crw,crefu,crefv,crefw,cgou,cgov,cgow)\n \nend subroutine ExtendCellsArrsDGVII \n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! this subroutine deallocates the cells arrays \n!\n\nsubroutine DeAllocCellsArrsDGV\nuse DGV_commvar, only: cells_pgrid, cells_cgrid, cells_lu, cells_lv, cells_lw, & \n cells_ru, cells_rv, cells_rw, cells_refu, cells_refv, & \n cells_refw, cells_gow, cells_gou, cells_gov\n\ndeallocate(cells_pgrid, cells_cgrid, cells_lu, cells_lv, cells_lw, & \n cells_ru, cells_rv, cells_rw, cells_refu, cells_refv, & \n cells_refw, cells_gow, cells_gou, cells_gov)\n\nend subroutine DeAllocCellsArrsDGV\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! this subroutine deallocates the cells arrays \n!\n\nsubroutine DeAllocCellsArrsDGVII\nuse DGV_commvar, only: cells_pgridII, cells_cgridII, cells_luII, cells_lvII, cells_lwII, & \n cells_ruII, cells_rvII, cells_rwII, cells_refuII, cells_refvII, & \n cells_refwII, cells_gowII, cells_gouII, cells_govII\n\ndeallocate(cells_pgridII, cells_cgridII, cells_luII, cells_lvII, cells_lwII, & \n cells_ruII, cells_rvII, cells_rwII, cells_refuII, cells_refvII, & \n cells_refwII, cells_gowII, cells_gouII, cells_govII)\n\nend subroutine DeAllocCellsArrsDGVII\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! FillCellsArrsDGV\n! \n! This subroutine populates the certain portion of the cells_arrays.\n! \n! Expects to have cells_arrays to exists and to be of a proper size\n! \n! cells_cgrid = number of the grid. If the cell is not refined then the value is -1, if the cell is refined than \n! cells_cgrid gives the number of the grid. \n\nsubroutine FillCellsArrsDGV(ibeg,iend,umesh,vmesh,wmesh,pgrid,gou,gov,gow)\n\nuse DGV_commvar, only: cells_pgrid, cells_cgrid, cells_lu, cells_lv, cells_lw, & \n cells_ru, cells_rv, cells_rw, cells_refu, cells_refv, & \n cells_refw, cells_gow, cells_gou, cells_gov\n\ninteger (I4B), intent(in) :: ibeg,iend ! beginning and end of the range to fill the cells array\nreal (DP), dimension (0:), intent (in) :: umesh,vmesh,wmesh ! 1D meshes to be used\ninteger (I4B), intent (in) :: pgrid ! the number of the parent grid --- grid where these cells belong. \ninteger (I4B), intent (in) :: gou,gov,gow ! the max order of gauss lagrange basis to be assigned to the cells -- all cells in this range will be assigned the same order in all \n! \ninteger (I4B) :: iu,iv,iw,mm ! local counters\n! first some elementary checks\nif ((size(cells_pgrid,1)< ibeg) .or. (size(cells_pgrid,1)< iend)) then \n print *, \"FillCellsArrsDGV: supplied range does not work for the cells arrays. \"\n stop\nend if\nif ((ibeg > iend) .or. (iend-ibeg + 1 /= (size(vmesh,1)-1)*(size(wmesh,1)-1)*(size(umesh,1)-1))) then \n print *, \"FillCellsArrsDGV: supplied range does not work: ibeg>iend or iend-ibeg + 1 /= size(vmesh)*size(wmesh)*size(umesh). \"\n stop\nend if \n! ok, let us populate the cells\n! some properties will be the same for the entire range: \ncells_pgrid(ibeg:iend) = pgrid\ncells_cgrid(ibeg:iend) = -1\ncells_refu(ibeg:iend) = 1\ncells_refv(ibeg:iend) = 1\ncells_refw(ibeg:iend) = 1\ncells_gou(ibeg:iend) = gou\ncells_gov(ibeg:iend) = gov\ncells_gow(ibeg:iend) = gow\n! some properties will be different: \nmm=ibeg\ndo iu=0,size(umesh,1)-2\ndo iv=0,size(vmesh,1)-2\ndo iw=0,size(wmesh,1)-2\n cells_lu(mm) = umesh(iu)\n cells_lv(mm) = vmesh(iv)\n cells_lw(mm) = wmesh(iw)\n cells_ru(mm) = umesh(iu+1)\n cells_rv(mm) = vmesh(iv+1)\n cells_rw(mm) = wmesh(iw+1)\n mm=mm+1\nend do \nend do \nend do \nend subroutine FillCellsArrsDGV\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! FillCellsArrsDGVII\n! \n! This subroutine populates the certain portion of the cells_arrays.\n! \n! \n! This is a copy of the above subroutine, with the only change that it works with secondary mehses. \n! This is accomplished by re-naming variable in the USE commvar, only: statement. \n!\n!\n! The suffix II in the name suggests that the subroutine works with the secondary mesh\n!\n! Expects to have cells_arraysII to exists and to be of a proper size\n! \n! cells_cgridII = number of the grid. If the cell is not refined then the value is -1, if the cell is refined than \n! cells_cgrid gives the number of the grid. \n!!!!!!!!!!!!!!!!!!!!!\n\nsubroutine FillCellsArrsDGVII(ibeg,iend,umesh,vmesh,wmesh,pgrid,gou,gov,gow)\n\nuse DGV_commvar, only: cells_pgrid=>cells_pgridII, cells_cgrid=>cells_cgridII, &\n cells_lu=>cells_luII, cells_lv=>cells_lvII, cells_lw=>cells_lwII, & \n cells_ru=>cells_ruII, cells_rv=>cells_rvII, cells_rw=>cells_rwII, &\n cells_refu=>cells_refuII, cells_refv=>cells_refvII, cells_refw=>cells_refwII, & \n cells_gow=>cells_gowII, cells_gou=>cells_gouII, cells_gov=>cells_govII\n\ninteger (I4B), intent(in) :: ibeg,iend ! beginning and end of the range to fill the cells array\nreal (DP), dimension (0:), intent (in) :: umesh,vmesh,wmesh ! 1D meshes to be used\ninteger (I4B), intent (in) :: pgrid ! the number of the parent grid --- grid where these cells belong. \ninteger (I4B), intent (in) :: gou,gov,gow ! the max order of gauss lagrange basis to be assigned to the cells -- all cells in this range will be assigned the same order in all \n! \ninteger (I4B) :: iu,iv,iw,mm ! local counters\n! first some elementary checks\nif ((size(cells_pgrid,1)< ibeg) .or. (size(cells_pgrid,1)< iend)) then \n print *, \"FillCellsArrsDGVII: supplied range does not work for the cells arrays. \"\n stop\nend if\nif ((ibeg > iend) .or. (iend-ibeg + 1 /= (size(vmesh,1)-1)*(size(wmesh,1)-1)*(size(umesh,1)-1))) then \n print *, \"FillCellsArrsDGVII: supplied range does not work: ibeg>iend or iend-ibeg + 1 .neqv. size(vmesh)*size(wmesh)*size(umesh). \"\n stop\nend if \n! ok, let us populate the cells\n! some properties will be the same for the entire range: \ncells_pgrid(ibeg:iend) = pgrid\ncells_cgrid(ibeg:iend) = -1\ncells_refu(ibeg:iend) = 1\ncells_refv(ibeg:iend) = 1\ncells_refw(ibeg:iend) = 1\ncells_gou(ibeg:iend) = gou\ncells_gov(ibeg:iend) = gov\ncells_gow(ibeg:iend) = gow\n! some properties will be different: \nmm=ibeg\ndo iu=0,size(umesh,1)-2\ndo iv=0,size(vmesh,1)-2\ndo iw=0,size(wmesh,1)-2\n cells_lu(mm) = umesh(iu)\n cells_lv(mm) = vmesh(iv)\n cells_lw(mm) = wmesh(iw)\n cells_ru(mm) = umesh(iu+1)\n cells_rv(mm) = vmesh(iv+1)\n cells_rw(mm) = wmesh(iw+1)\n mm=mm+1\nend do \nend do \nend do \nend subroutine FillCellsArrsDGVII\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1\n!! CellsRefineDGV\n!! \n!! This subrotine refines cells that are on the supplied list\n!!\n!! Depends on the main program. The cells arrays must be set up before calling this subroutine\n!!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\nsubroutine CellsRefineDGV(reflist,refu,refv,refw)\n\nuse DGV_commvar, only: cells_pgrid, cells_cgrid, cells_lu, cells_lv, cells_lw, & \n cells_ru, cells_rv, cells_rw, cells_refu, cells_refv, & \n cells_refw, cells_gow, cells_gou, cells_gov, grids_cap_u, &\n grids_cap_v,grids_cap_w,grids_u,grids_v,grids_w\n\ninteger (I4B), dimension (:), intent (in) :: reflist !list of cells to refine at this step\ninteger (I4B), intent(in) :: refu,refv,refw ! refinement factors in dimension u, v, and w\n!!!!!!!!\n!! IMPORTANT: \n!!\ninteger (I4B) :: go_inc=0 !! THIS IS A PARAMETER: the refined cells will have orders of the parent + go_inc\n!!\n!!!!!!!! \ninteger (I4B) :: i,ic,mm ! local counters \ninteger (I4B) :: isc ! the number of the cell that is being refined\ninteger (I4B) :: cgrid ! a scrap number to keep the number of the new grid\ninteger (I4B) :: gou,gov,gow ! the scrap variables to keep the gauss order of the basis\ninteger (I4B) :: loc_alloc_stat ! local variable to keep the allocation status\n\nreal (DP), dimension (:), allocatable :: dumu,dumv,dumw \n! a quick check for errors: \nif ((refu*refv*refw < 1 ) .or. (size(reflist,1)<1)) then \n print *,\"CellsRefineDGV: error in incoming parameters, refu*refv*refw < 1 or size(reflist,1)<1\"\nend if \n! also, we need to have a shorthand for how many cells we will add\nmm=(refu)*(refv)*(refw)\n!\ndo i=1,size(reflist,1)\n isc = reflist(i)\n ! We need to construnct the new refined grids\n allocate (dumu(1:refu+1),dumv(1:refv+1),dumw(1:refw+1), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"CellsRefineDGV: Allocation error for variable (dumu),(dumv),or (dumw)\"\n stop\n end if\n !\n dumu = (/ (cells_lu(isc) + (cells_ru(isc) - cells_lu(isc))/Real(refu,DP)*i, i=0,refu) /)\n dumv = (/ (cells_lv(isc) + (cells_rv(isc) - cells_lv(isc))/Real(refv,DP)*i, i=0,refv) /)\n dumw = (/ (cells_lw(isc) + (cells_rw(isc) - cells_lw(isc))/Real(refw,DP)*i, i=0,refw) /)\n ! Now we need to extend the grids arrays to include the new grids... \n call ExtendGridsDGV(dumu,dumv,dumw,cgrid)\n ! Now we mark the cell with number (isc) to have a child grid...\n cells_cgrid(isc) = cgrid\n cells_refu(isc)= refu\n cells_refv(isc)= refv\n cells_refw(isc)= refw\n ! We also want to know what is the order of the Lagrange basis on that cell: \n gou=cells_gou(isc)\n gov=cells_gov(isc)\n gow=cells_gow(isc)\n ! we need to know how long was cells before we added new: \n ic=size(cells_lu,1)\n ! Now we need to extend the cells arrays to include the new cells... \n call ExtendCellsArrsDGV(ic+mm)\n ! now we need to populate the new cells\n call FillCellsArrsDGV(ic+1,ic+mm,dumu,dumv,dumw,cgrid,gou+go_inc,gov+go_inc,gow+go_inc)\n ! ready to do the next cell \nend do \n\n\nend subroutine CellsRefineDGV\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! ExtendGridsDGV\n!\n! This subroutine extends the grids_cap_u/_v/_w and the grids_u/_v/_w arrays\n! Depends on the main program. \n!\n! dumu,dumv,dumw -- these are the new grids that need to be added to the old grids... \n! \n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\nsubroutine ExtendGridsDGV(dumu,dumv,dumw,cgrid)\n\nuse DGV_commvar, only: grids_cap_u, grids_cap_v, grids_cap_w, grids_u, grids_v, grids_w\n\nreal (DP), dimension (:), intent (in) :: dumu,dumv,dumw ! the new velocity values that will be added to grids\ninteger (I4B), intent (out) :: cgrid ! the number of the child grid that will be created \n!\ninteger (I4B) :: iu,iv,iw ! some scrap variables... \ninteger (I4B) :: loc_alloc_stat ! local variable to keep the allocation status\n\nreal (DP), dimension (:), allocatable :: tmp_u,tmp_v,tmp_w ! temporary arrays to keep the old grids\n\n! a quick check for errors\nif ((size(dumu,1)< 3 ) .or. (size(dumv,1)< 3) .or. (size(dumw,1)< 3 )) then \n print *,\"ExtendGridsDGV: error in incoming parameters, at least one of the arrays does not require a refinement < 1\"\nend if \n! create the dump arrays to save current grids_cap_u/v/w:\niu=size(grids_cap_u,1)\nallocate (tmp_u(1:iu),tmp_v(1:iu),tmp_w(1:iu), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"ExtendGridsDGV: Allocation error 1 for variable (tmp_u),(tmp_v),or (tmp_w)\"\n stop\n end if\n! save the old grids_cap arrays\ntmp_u=grids_cap_u\ntmp_v=grids_cap_v\ntmp_w=grids_cap_w\n! deallocate the grids_cap \ndeallocate (grids_cap_u,grids_cap_v,grids_cap_w)\n! allocate them 1 cell longer... \nallocate (grids_cap_u(1:iu+1),grids_cap_v(1:iu+1),grids_cap_w(1:iu+1), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"ExtendGridsDGV: Allocation error for variable (grids_cap_u/_v/_w)\"\n stop\n end if\n! restore the old grids_cap arrays\ngrids_cap_u(1:iu)=tmp_u\ngrids_cap_v(1:iu)=tmp_v\ngrids_cap_w(1:iu)=tmp_w\n! record the new cells\ngrids_cap_u(iu+1)=size(dumu,1)\ngrids_cap_v(iu+1)=size(dumv,1)\ngrids_cap_w(iu+1)=size(dumw,1)\n! done with grids_cap arrays\ncgrid = iu+1 ! this will be passed out as the number of the new created grid\ndeallocate(tmp_u,tmp_v,tmp_w)\n! now we extend the grids_u/_v/_w arrays... \niu=size(grids_u,1)\niv=size(grids_v,1)\niw=size(grids_w,1)\nallocate (tmp_u(1:iu),tmp_v(1:iv),tmp_w(1:iw), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"ExtendGridsDGV: Allocation error 2 for variable (tmp_u),(tmp_v),or (tmp_w)\"\n stop\n end if\n! save the old grids_u/_v/_w arrays\ntmp_u=grids_u\ntmp_v=grids_v\ntmp_w=grids_w\n! deallocate the grids_cap \ndeallocate(grids_u,grids_v,grids_w)\n! allocate them again but longer... \nallocate (grids_u(1:iu+size(dumu,1)),grids_v(1:iv+size(dumv,1)),grids_w(1:iw+size(dumw,1)), stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"ExtendGridsDGV: Allocation error for variable (grids_cap_u/_v/_w)\"\n stop\n end if\n! restore the old grids_cap arrays\ngrids_u(1:iu)=tmp_u\ngrids_v(1:iv)=tmp_v\ngrids_w(1:iw)=tmp_w\n! record the new cells\ngrids_u(iu+1:iu+size(dumu,1)) = dumu\ngrids_v(iv+1:iv+size(dumv,1)) = dumv\ngrids_w(iw+1:iw+size(dumw,1)) = dumw\n! done with grids_cap arrays\ndeallocate(tmp_u,tmp_v,tmp_w)\nend subroutine ExtendGridsDGV\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! subroutine SetNodesDGV \n!\n! This subroutine sets all nodes in velocity that will ever be used. \n!\n! nodes_cells contains the # of the cell where this node belongs\n! nodex_x/_y/_z contains the coordinates of the nodes.\n! nodes_weights contains the product of the weights of gauss quadrature for each node so that the \n! functions can be evaluated on the nodes and multiplied by the weigth and summed. \n!\n! grids_cap_u -- stores the grid capasity \n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\nsubroutine SetNodesDGV\n\nuse DGV_commvar, only: nodes_pcell, nodes_u, nodes_v, nodes_w, nodes_gwts,&\n\t\t\t\t cells_pgrid, cells_cgrid, cells_lu, cells_lv, cells_lw, & \n cells_ru, cells_rv, cells_rw, cells_refu, cells_refv, & \n cells_refw, cells_gow, cells_gou, cells_gov, grids_cap_u, &\n grids_cap_v,grids_cap_w,grids_u,grids_v,grids_w,g_nds_all, &\n g_wts_all, nodes_ui, nodes_vi, nodes_wi, &\n\t\t\t\t nodes_ut, nodes_vt, nodes_wt\n \nintrinsic SUM \n\ninteger (I4B) :: ic,im,jm,iu,iv,iw ! some scrap variables... \nreal (DP) :: ru,qu,rv,qv,rw,qw ! some scrap variables ...\n\ninteger (I4B) :: loc_alloc_stat ! local variable to keep the allocation status\n\nim=0\ndo ic=1,size(cells_pgrid,1)\n if (cells_cgrid(ic) == -1) then \n im=im+cells_gou(ic)*cells_gov(ic)*cells_gow(ic)\n end if\nend do \n!\n! We now allocating the nodes arrays\nallocate (nodes_pcell(1:im),nodes_ui(1:im),nodes_vi(1:im),nodes_wi(1:im),stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"SetNodesArDGV: Allocation error for variable (nodes_pcell,nodes_ui/_vi/_wi)\"\n stop\n end if\n\nallocate (nodes_ut(1:im),nodes_vt(1:im),nodes_wt(1:im),stat=loc_alloc_stat)\n\tif (loc_alloc_stat >0) then\n\tprint *, \"SetNodesArDGV: Allocation error for variables (nodes_ut, nodes_vt, nodes_wt)\"\n\tstop\n\tend if\n\nallocate (nodes_u(1:im),nodes_v(1:im),nodes_w(1:im),nodes_gwts(1:im),stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"SetNodesArDGV: Allocation error for variables (nodes_u/_v/_w/_gwts)\"\n stop\n end if\n! Now we will populate them. \njm=1\ndo ic=1,size(cells_pgrid,1)\nif (cells_cgrid(ic) == -1) then \n do iu=1,cells_gou(ic)\n ru=g_nds_all(iu,cells_gou(ic))*(cells_ru(ic)-cells_lu(ic))/2.0_DP + (cells_ru(ic)+cells_lu(ic))/2.0_DP\n qu=g_wts_all(iu,cells_gou(ic))\n do iv=1,cells_gov(ic)\n rv=g_nds_all(iv,cells_gov(ic))*(cells_rv(ic)-cells_lv(ic))/2.0_DP + (cells_rv(ic)+cells_lv(ic))/2.0_DP\n qv=g_wts_all(iv,cells_gov(ic))\n do iw=1,cells_gow(ic)\n rw=g_nds_all(iw,cells_gow(ic))*(cells_rw(ic)-cells_lw(ic))/2.0_DP + (cells_rw(ic)+cells_lw(ic))/2.0_DP\n qw=g_wts_all(iw,cells_gow(ic))\n! ready to fill the nodes! \nnodes_pcell(jm) = ic \nnodes_u(jm)= ru \nnodes_v(jm)= rv\nnodes_w(jm)= rw\nnodes_gwts(jm)=qu*qv*qw*(cells_ru(ic)-cells_lu(ic))*(cells_rv(ic)-cells_lv(ic))*(cells_rw(ic)-cells_lw(ic))/8.0_DP\nnodes_ui(jm)=iu\nnodes_vi(jm)=iv\nnodes_wi(jm)=iw\njm=jm+1\n end do \n end do \n end do \nend if \nend do \n!\nif (jm-1 /= im) then \n print *, \"SetNodesArDGV: Error, jm-1 .neqv. im. Nodes arrays may be populated wrong.\"\n stop\n end if\n\nend subroutine SetNodesDGV\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! subroutine SetNodesDGVII \n!\n! This subroutine sets all nodes in velocity in secondary grid that will ever be used. \n!\n! This is a copy of the above subroutine, with the only change that it works with secondary mehses. \n! This is accomplished by re-naming variable in the USE commvar, only: statement. \n!\n!\n! The suffix II in the name suggests that the subroutine works with the secondary mesh\n!\n! nodes_cellsII contains the # of the cell where this node belongs\n! nodex_x/_y/_zII contains the coordinates of the nodes.\n! nodes_weightsII contains the product of the weights of gauss quadrature for each node so that the \n! functions can be evaluated on the nodes and multiplied by the weigth and summed. \n!\n! grids_cap_uII -- stores the grid capasity \n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\nsubroutine SetNodesDGVII\n\nuse DGV_commvar, only: nodes_pcell=>nodes_pcellII, &\n nodes_u=>nodes_uII, nodes_v=>nodes_vII, nodes_w=>nodes_wII, &\n nodes_gwts=>nodes_gwtsII, cells_pgrid=>cells_pgridII, cells_cgrid=>cells_cgridII, &\n cells_lu=>cells_luII, cells_lv=>cells_lvII, cells_lw=>cells_lwII, & \n cells_ru=>cells_ruII, cells_rv=>cells_rvII, cells_rw=>cells_rwII, & \n cells_refu=>cells_refuII, cells_refv=>cells_refvII, cells_refw=>cells_refwII, &\n cells_gow=>cells_gowII, cells_gou=>cells_gouII, cells_gov=>cells_govII, &\n grids_cap_u=>grids_cap_uII, grids_cap_v=>grids_cap_vII, grids_cap_w=>grids_cap_wII, &\n grids_u=>grids_uII, grids_v=>grids_vII, grids_w=>grids_wII,&\n g_nds_all, g_wts_all, &\n nodes_ui=>nodes_uiII, nodes_vi=>nodes_viII, nodes_wi=>nodes_wiII, &\n\t\t\t\t nodes_ut=>nodes_utII, nodes_vt=>nodes_vtII, nodes_wt=>nodes_wtII\n \nintrinsic SUM \n\ninteger (I4B) :: ic,im,jm,iu,iv,iw ! some scrap variables... \nreal (DP) :: ru,qu,rv,qv,rw,qw ! some scrap variables ...\n\ninteger (I4B) :: loc_alloc_stat ! local variable to keep the allocation status\n\nim=0\ndo ic=1,size(cells_pgrid,1)\n if (cells_cgrid(ic) == -1) then \n im=im+cells_gou(ic)*cells_gov(ic)*cells_gow(ic)\n end if\nend do \n!\n! We now allocating the nodes arrays\nallocate (nodes_pcell(1:im),nodes_ui(1:im),nodes_vi(1:im),nodes_wi(1:im),stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"SetNodesArDGVII: Allocation error for variable (nodes_pcell,nodes_ui/_vi/_wiII)\"\n stop\n end if\n\nallocate (nodes_ut(1:im),nodes_vt(1:im),nodes_wt(1:im),stat=loc_alloc_stat)\n\tif (loc_alloc_stat >0) then\n\tprint *, \"SetNodesArDGVII: Allocation error for variables (nodes_utII, nodes_vtII, nodes_wtII)\"\n\tstop\n\tend if\n\nallocate (nodes_u(1:im),nodes_v(1:im),nodes_w(1:im),nodes_gwts(1:im),stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"SetNodesArDGVII: Allocation error for variables (nodes_u/_v/_w/_gwtsII)\"\n stop\n end if\n! Now we will populate them. \njm=1\ndo ic=1,size(cells_pgrid,1)\nif (cells_cgrid(ic) == -1) then \n do iu=1,cells_gou(ic)\n ru=g_nds_all(iu,cells_gou(ic))*(cells_ru(ic)-cells_lu(ic))/2.0_DP + (cells_ru(ic)+cells_lu(ic))/2.0_DP\n qu=g_wts_all(iu,cells_gou(ic))\n do iv=1,cells_gov(ic)\n rv=g_nds_all(iv,cells_gov(ic))*(cells_rv(ic)-cells_lv(ic))/2.0_DP + (cells_rv(ic)+cells_lv(ic))/2.0_DP\n qv=g_wts_all(iv,cells_gov(ic))\n do iw=1,cells_gow(ic)\n rw=g_nds_all(iw,cells_gow(ic))*(cells_rw(ic)-cells_lw(ic))/2.0_DP + (cells_rw(ic)+cells_lw(ic))/2.0_DP\n qw=g_wts_all(iw,cells_gow(ic))\n! ready to fill the nodes! \nnodes_pcell(jm) = ic \nnodes_u(jm)= ru \nnodes_v(jm)= rv\nnodes_w(jm)= rw\nnodes_gwts(jm)=qu*qv*qw*(cells_ru(ic)-cells_lu(ic))*(cells_rv(ic)-cells_lv(ic))*(cells_rw(ic)-cells_lw(ic))/8.0_DP\nnodes_ui(jm)=iu\nnodes_vi(jm)=iv\nnodes_wi(jm)=iw\njm=jm+1\n end do \n end do \n end do \nend if \nend do \n!\nif (jm-1 .ne. im) then \n print *, \"SetNodesArDGVII: Error, jm-1 /= im. Nodes arrays may be populated wrong.\"\n stop\n end if\n\nend subroutine SetNodesDGVII\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! SetCellsUGIAshiftArrays\n!\n!\n! This subroutine is setting up the arrays cells_gui, _gvi, _gwi that \n! store the relative integer adress of the cell on the grid. \n!\n! Only wil work if there is only one grid in the mesh.\n!\n! Also this subroutine sets up an arrays that gives the adress shift for different nodes to \n! read staff from the A-Array.\n!\n! Note that all these arrays can be created in other places of the algorithm, but we did nto think about them \n! earlier. So we put them here.\n!\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine SetCellsUGINdsSftArrs(ccell)\n\nuse DGV_commvar, only: nodes_pcell, nodes_ui, nodes_vi, nodes_wi, cells_ugi, cells_vgi, cells_wgi, &\n cells_pgrid, grids_cap_u, grids_cap_v, grids_cap_w, nodes_Ashift, nodes_phican,&\n cells_gou,cells_gov,cells_gow,nodes_dui,nodes_dvi,nodes_dwi,A_capphi\n!!!!!!!!!!\ninteger (I4B), intent(in) :: ccell ! the number of the canonical cell -- a cell in the middle of the domain for which A is computed \n!!!!!!!!!!\ninteger (I4B) :: i,Ashift,phishift,cshift ! scrap variable...\ninteger (I4B) :: iphi ! the number of the basis function. Recall that each node generates a basis function. \ninteger (I4B) :: phicell ! the number of the cell where phi belongs\ninteger (I4B) :: gou,gov,gow ! scrap variables to keep the number of nodes in a cell and the shift in nodes to the canonical cell\ninteger (I4B) :: pgcu,pgcv,pgcw ! scrap variables to keep the number of cells on the grid in each dimension\ninteger (I4B) :: ccell_ugi,ccell_vgi,ccell_wgi ! scrap variables to keep the integer address of the canonical cell on the grid\ninteger :: loc_alloc_stat ! scrap variable to keep the allocation status\n!!!!!!!!!!!!!!!!!!!!\nif (ccell < 0) then ! a quick check for garbage in data: \n print *,\"EvalCollisionPeriodicA_DGV: Error. The provided value of (ccell) is negative or invalid. Stop.\"\nend if \n!!!!\nif (size(grids_cap_u,1) /= 1) then \n print *, \"SetCellsUGIAshiftArrays: Error. The number of grids must be 1. Stop\"\n stop\nend if \n!!! First, we need to calculate some useful constants:\ngou=cells_gou(ccell)\ngov=cells_gov(ccell)\ngow=cells_gow(ccell)\ncshift=(ccell-1)*gou*gov*gow ! this will be the number of the node right before the first node in canonical cell\n! first we find the number of cells in each dimension\npgcu=grids_cap_u(cells_pgrid(ccell))-1\npgcv=grids_cap_v(cells_pgrid(ccell))-1\npgcw=grids_cap_w(cells_pgrid(ccell))-1\n! now we will calculate the relative integer address of all cells on the grid.\n! first, we create a space where to store this information: \ni=size(cells_pgrid,1)\nallocate (cells_ugi(1:i),cells_vgi(1:i),cells_wgi(1:i),stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"SetCellsUGIAshiftArrays: Allocation error for variable (cells_ugi/_vgi/_wgi)\"\n stop\n end if\n! Nex we will calculate the adresses\n! IMPORTANT! Notice that this algorithm uses the convention that when enumerating cells the outside loop is in x, the \n! middle loop is in y and the innermost is in z. \n\ndo phicell = 1,pgcu*pgcv*pgcw ! loop in all cells\n!\nccell_ugi=1\nccell_vgi=1\nccell_wgi=1\ni=1\ndo while (i0) then \n print *, \"SetCellsUGIAshiftArrays: Allocation error for variable (nodes_Ashift,nodes_dui/dvi/dwi)\"\n stop\n end if\n! next we populate the nodes_dui/_dvi/dwi -arrays... \n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\ndo iphi=1,size(nodes_vi,1)\n phicell = nodes_pcell(iphi)\n if (cells_pgrid(phicell) /= cells_pgrid(ccell)) then \n print *, \"SetCellsUGIAshiftArrays: Error. The parent cell of phi belongs to a different grid than the canonical cell. Stop\"\n stop\n end if \n ! next we record the shifts in integer index in from the cell containting phi to the canonical\n nodes_dui(iphi)=cells_ugi(phicell) - cells_ugi(ccell)\n nodes_dvi(iphi)=cells_vgi(phicell) - cells_vgi(ccell)\n nodes_dwi(iphi)=cells_wgi(phicell) - cells_wgi(ccell)\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n ! Now we need to calculate the nodes_Ashift number and the nodes_phican number \n ! First we calculate the number of the node on the canonical cell that corresponds to the node with number iphi \n phishift = cshift + (nodes_ui(iphi)-1)*gov*gow + (nodes_vi(iphi)-1)*gow + nodes_wi(iphi) ! this is the number of the node\n nodes_phican(iphi) = phishift ! we will record this number. \n ! Now we will calculate the Ashift number\n !! ATTENTION: when no A file present, the next line generates an access violation code! Program crashes\n Ashift = sum(A_capphi(1:phishift-1))\n nodes_Ashift(iphi)=Ashift\n !!!!! all done\nend do \nend subroutine SetCellsUGINdsSftArrs\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! SetCellsUGIAshiftArraysII\n!\n!\n! This subroutine is setting up the arrays cells_guiII, _gviII, _gwiII that \n! store the relative integer adress of the cell on the grid. \n!\n! This is a copy of the above subroutine, with the only change that it works with secondary mehses. \n! This is accomplished by re-naming variable in the USE commvar, only: statement. \n!\n!\n! The suffix II in the name suggests that the subroutine works with the secondary mesh\n!\n!\n! Only wil work if there is only one grid in the mesh.\n!\n! Also this subroutine sets up an arrays that gives the adress shift for different nodes to \n! read staff from the A-Array.\n!\n! Note that all these arrays can be created in other places of the algorithm, but we did nto think about them \n! earlier. So we put them here.\n!\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine SetCellsUGINdsSftArrsII(ccell)\n\nuse DGV_commvar, only: nodes_pcell=>nodes_pcellII, &\n nodes_ui=>nodes_uiII, nodes_vi=>nodes_viII, nodes_wi=>nodes_wiII, & \n cells_ugi=>cells_ugiII, cells_vgi=>cells_vgiII, cells_wgi=>cells_wgiII, &\n cells_pgrid=>cells_pgridII, & \n grids_cap_u=>grids_cap_uII, grids_cap_v=>grids_cap_vII, grids_cap_w=>grids_cap_wII, &\n nodes_Ashift=>nodes_AshiftII, nodes_phican=>nodes_phicanII, A_capphi=>A_capphiII, &\n cells_gou=>cells_gouII, cells_gov=>cells_govII, cells_gow=>cells_gowII, &\n nodes_dui=>nodes_duiII, nodes_dvi=>nodes_dviII, nodes_dwi=>nodes_dwiII\n!!!!!!!!!!\ninteger (I4B), intent(in) :: ccell ! the number of the canonical cell -- a cell in the middle of the domain for which A is computed \n!!!!!!!!!!\ninteger (I4B) :: i,Ashift,phishift,cshift ! scrap variable...\ninteger (I4B) :: iphi ! the number of the basis function. Recall that each node generates a basis function. \ninteger (I4B) :: phicell ! the number of the cell where phi belongs\ninteger (I4B) :: gou,gov,gow ! scrap variables to keep the number of nodes in a cell and the shift in nodes to the canonical cell\ninteger (I4B) :: pgcu,pgcv,pgcw ! scrap variables to keep the number of cells on the grid in each dimension\ninteger (I4B) :: ccell_ugi,ccell_vgi,ccell_wgi ! scrap variables to keep the integer address of the canonical cell on the grid\ninteger :: loc_alloc_stat ! scrap variable to keep the allocation status\n!!!!!!!!!!!!!!!!!!!!\nif (ccell < 0) then ! a quick check for garbage in data: \n print *,\"EvalCollisionPeriodicA_DGVII: Error. The provided value of (ccell) is negative or invalid. Stop.\"\nend if \n!!!!\nif (size(grids_cap_u,1) /= 1) then \n print *, \"SetCellsUGIAshiftArraysII: Error. The number of grids must be 1. Stop\"\n stop\nend if \n!!! First, we need to calculate some useful constants:\ngou=cells_gou(ccell)\ngov=cells_gov(ccell)\ngow=cells_gow(ccell)\ncshift=(ccell-1)*gou*gov*gow ! this will be the number of the node right before the first node in canonical cell\n! first we find the number of cells in each dimension\npgcu=grids_cap_u(cells_pgrid(ccell))-1\npgcv=grids_cap_v(cells_pgrid(ccell))-1\npgcw=grids_cap_w(cells_pgrid(ccell))-1\n! now we will calculate the relative integer address of all cells on the grid.\n! first, we create a space where to store this information: \ni=size(cells_pgrid,1)\nallocate (cells_ugi(1:i),cells_vgi(1:i),cells_wgi(1:i),stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"SetCellsUGIAshiftArraysII: Allocation error for variable (cells_ugi/_vgi/_wgiII)\"\n stop\n end if\n! Nex we will calculate the adresses\n! IMPORTANT! Notice that this algorithm uses the convention that when enumerating cells the outside loop is in x, the \n! middle loop is in y and the innermost is in z. \n\ndo phicell = 1,pgcu*pgcv*pgcw ! loop in all cells\n!\nccell_ugi=1\nccell_vgi=1\nccell_wgi=1\ni=1\ndo while (i0) then \n print *, \"SetCellsUGIAshiftArraysII: Allocation error for variable (nodes_Ashift,nodes_dui/dvi/dwiII)\"\n stop\n end if\n! next we populate the nodes_dui/_dvi/dwi -arrays... \n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\ndo iphi=1,size(nodes_vi,1)\n phicell = nodes_pcell(iphi)\n if (cells_pgrid(phicell) /= cells_pgrid(ccell)) then \n print *, \"SetCellsUGIAshiftArraysII: Error. The parent cell of phi belongs to a different grid than the canonical cell. Stop\"\n stop\n end if \n ! next we record the shifts in integer index in from the cell containting phi to the canonical\n nodes_dui(iphi)=cells_ugi(phicell) - cells_ugi(ccell)\n nodes_dvi(iphi)=cells_vgi(phicell) - cells_vgi(ccell)\n nodes_dwi(iphi)=cells_wgi(phicell) - cells_wgi(ccell)\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n ! Now we need to calculate the nodes_Ashift number and the nodes_phican number \n ! First we calculate the number of the node on the canonical cell that corresponds to the node with number iphi \n phishift = cshift + (nodes_ui(iphi)-1)*gov*gow + (nodes_vi(iphi)-1)*gow + nodes_wi(iphi) ! this is the number of the node\n nodes_phican(iphi) = phishift ! we will record this number. \n ! Now we will calculate the Ashift number\n Ashift = sum(A_capphi(1:phishift-1))\n nodes_Ashift(iphi)=Ashift\n !!!!! all done\nend do \nend subroutine SetCellsUGINdsSftArrsII\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! SetCellsUGI_DGV\n!\n!\n! This subroutine is setting up the arrays cells_gui, _gvi, _gwi that \n! store the relative integer adress of the cell on the grid. \n!\n! Only will work if there is only one grid in the mesh.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine SetCellsUGI_DGV(ccell)\n\nuse DGV_commvar, only: nodes_pcell, nodes_ui, nodes_vi, nodes_wi, cells_ugi, cells_vgi, cells_wgi, &\n cells_pgrid, grids_cap_u, grids_cap_v, grids_cap_w, nodes_phican,&\n cells_gou,cells_gov,cells_gow,nodes_dui,nodes_dvi,nodes_dwi\n!!!!!!!!!!\ninteger (I4B), intent(in) :: ccell ! the number of the canonical cell -- a cell in the middle of the domain for which A is computed \n!!!!!!!!!!\ninteger (I4B) :: i,phishift,cshift ! scrap variable...\ninteger (I4B) :: iphi ! the number of the basis function. Recall that each node generates a basis function. \ninteger (I4B) :: phicell ! the number of the cell where phi belongs\ninteger (I4B) :: gou,gov,gow ! scrap variables to keep the number of nodes in a cell and the shift in nodes to the canonical cell\ninteger (I4B) :: pgcu,pgcv,pgcw ! scrap variables to keep the number of cells on the grid in each dimension\ninteger (I4B) :: ccell_ugi,ccell_vgi,ccell_wgi ! scrap variables to keep the integer address of the canonical cell on the grid\ninteger :: loc_alloc_stat ! scrap variable to keep the allocation status\n!!!!!!!!!!!!!!!!!!!!\nif (ccell < 0) then ! a quick check for garbage in data: \n print *,\"SetCellsUGI_DGV: Error. The provided value of (ccell) is negative or invalid. Stop.\"\nend if \n!!!!\nif (size(grids_cap_u,1) /= 1) then \n print *, \"SetCellsUGI_DGV: Error. The number of grids must be 1. Stop\"\n stop\nend if \n!!! First, we need to calculate some useful constants:\ngou=cells_gou(ccell)\ngov=cells_gov(ccell)\ngow=cells_gow(ccell)\ncshift=(ccell-1)*gou*gov*gow ! this will be the number of the node right before the first node in canonical cell\n! first we find the number of cells in each dimension\npgcu=grids_cap_u(cells_pgrid(ccell))-1\npgcv=grids_cap_v(cells_pgrid(ccell))-1\npgcw=grids_cap_w(cells_pgrid(ccell))-1\n! now we will calculate the relative integer address of all cells on the grid.\n! first, we create a space where to store this information: \ni=size(cells_pgrid,1)\nallocate (cells_ugi(1:i),cells_vgi(1:i),cells_wgi(1:i),stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"SetCellsUGI_DGV: Allocation error for variable (cells_ugi/_vgi/_wgi)\"\n stop\n end if\n! Nex we will calculate the adresses\n! IMPORTANT! Notice that this algorithm uses the convention that when enumerating cells the outside loop is in x, the \n! middle loop is in y and the innermost is in z. \n\ndo phicell = 1,pgcu*pgcv*pgcw ! loop in all cells\n!\nccell_ugi=1\nccell_vgi=1\nccell_wgi=1\ni=1\ndo while (i0) then \n print *, \"SetCellsUGI_DGV: Allocation error for variable (nodes_dui/dvi/dwi)\"\n stop\n end if\n! next we populate the nodes_dui/_dvi/dwi -arrays... \n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\ndo iphi=1,size(nodes_vi,1)\n phicell = nodes_pcell(iphi)\n if (cells_pgrid(phicell) /= cells_pgrid(ccell)) then \n print *, \"SetCellsUGI_DGV: Error. The parent cell of phi belongs to a different grid than the canonical cell. Stop\"\n stop\n end if \n ! next we record the shifts in integer index in from the cell containting phi to the canonical\n nodes_dui(iphi)=cells_ugi(phicell) - cells_ugi(ccell)\n nodes_dvi(iphi)=cells_vgi(phicell) - cells_vgi(ccell)\n nodes_dwi(iphi)=cells_wgi(phicell) - cells_wgi(ccell)\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n ! Now we need to calculate the nodes_Ashift number and the nodes_phican number \n ! First we calculate the number of the node on the canonical cell that corresponds to the node with number iphi \n phishift = cshift + (nodes_ui(iphi)-1)*gov*gow + (nodes_vi(iphi)-1)*gow + nodes_wi(iphi) ! this is the number of the node\n nodes_phican(iphi) = phishift ! we will record this number. \n !!!!! all done\nend do \nend subroutine SetCellsUGI_DGV\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! SetAshift_DGV\n!\n!\n! This subroutine is setting up the arrays nodes_Ashift \n!\n! Only will work if there is only one grid in the mesh.\n!\n! Also this subroutine sets up an arrays that gives the adress shift for different nodes to \n! read staff from the A-Array.\n!\n! Note that all these arrays can be created in other places of the algorithm, but we did nto think about them \n! earlier. So we put them here.\n!\n! ATTENTION: This subroutine depends on arrays cells_gui,_gvi,_gwi and the nodes_dui/_dvi/_dwi\n! Make sure SetCellsUGI_DGV is called before this subroutine is called \n! \n!\n!\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine SetAshift_DGV(ccell)\n\nuse DGV_commvar, only: nodes_pcell, cells_pgrid, nodes_Ashift, nodes_phican, A_capphi\n!!!!!!!!!!\ninteger (I4B), intent(in) :: ccell ! the number of the canonical cell -- a cell in the middle of the domain for which A is computed \n!!!!!!!!!!\ninteger (I4B) :: i,Ashift,phishift ! scrap variable...\ninteger (I4B) :: iphi ! the number of the basis function. Recall that each node generates a basis function. \ninteger (I4B) :: phicell ! the number of the cell where phi belongs\ninteger :: loc_alloc_stat ! scrap variable to keep the allocation status\n!!!!!!!!!!!!!!!!!!!!\nif (ccell < 0) then ! a quick check for garbage in data: \n print *,\"SetAshift_DGV: Error. The provided value of (ccell) is negative or invalid. Stop.\"\nend if \n!!!!\n! first, we create a space where to store Ashift information: \ni=size(nodes_pcell,1)\nallocate (nodes_Ashift(1:i),stat=loc_alloc_stat)\n !\n if (loc_alloc_stat >0) then \n print *, \"SetAshift_DGV: Allocation error for variable (nodes_Ashift)\"\n stop\n end if\n! next we populate the Ashift array \n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\ndo iphi=1,size(nodes_pcell,1)\n phicell = nodes_pcell(iphi)\n if (cells_pgrid(phicell) /= cells_pgrid(ccell)) then \n print *, \"SetAshift_DGV: Error. The parent cell of phi belongs to a different grid than the canonical cell. Stop\"\n stop\n end if \n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n ! Now we need to calculate the nodes_Ashift number \n !! ATTENTION: when no A file present, the next line generates an access violation code! Program crashes\n phishift = nodes_phican(iphi)\n Ashift = sum(A_capphi(1:phishift-1))\n nodes_Ashift(iphi) = Ashift\n !!!!! all done\nend do \nend subroutine SetAshift_DGV\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! SetAkorshiftAllNets_DGV\n!\n!\n! This subroutine is setting up the array nodes_AkorshiftAllNets \n!\n! Only will work if there is only one grid in the mesh.\n!\n! Also this subroutine sets up an arrays that gives the adress shift for different nodes to \n! read staff from the A-Array.\n!\n! Note that all these arrays can be created in other places of the algorithm, but we did nto think about them \n! earlier. So we put them here.\n!\n! ATTENTION: This subroutine depends on arrays cells_gui,_gvi,_gwi and the nodes_dui/_dvi/_dwi\n! Make sure SetCellsUGI_DGV is called before this subroutine is called \n! \n!\n!\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine SetAkorshiftAllNets_DGV(ccell)\n\nuse DGV_commvar, only: nodes_phican,nodes_AkorshiftAllNets,AkorAllNets_capphi,numKornets\n!!!!!!!!!!\ninteger (I4B), intent(in) :: ccell ! the number of the canonical cell -- a cell in the middle of the domain for which A is computed \n!!!!!!!!!!\ninteger (I4B) :: i,mm,AKorshift,phican ! scrap variables...\ninteger (I4B) :: iphi ! the number of the basis function. Recall that each node generates a basis function. \ninteger :: loc_alloc_stat ! scrap variable to keep the allocation status\n!!!!!!!!!!!!!!!!!!!!\nif (ccell < 0) then ! a quick check for garbage in data: \n print *,\"SetAkorshiftAllNets_DGV: Error. The provided value of (ccell) is negative or invalid. Stop.\"\nend if \n!!!!\nmm = size(nodes_phican,1)\n!!!!\ndo i=1,numKornets\n allocate (nodes_AkorshiftAllNets(i)%p(1:mm), stat=loc_alloc_stat) !\n !\n if (loc_alloc_stat >0) then \n print *, \"SetAkorshiftAllNets_DGV: Allocation error for variable nodes_AkorshiftAllNets(i)%p(1:mm), netnum=\", i\n stop\n end if\n !! Now that the shift array is allocated, we need to populate it\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n do iphi=1,mm\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n ! Now we need to calculate the nodes_AKorshift number \n !! ATTENTION: when no Akor file present, the next line generates an access violation code! Program crashes\n phican = nodes_phican(iphi)\n AKorshift = sum(AkorAllNets_capphi(i)%p(1:phican-1))\n nodes_AkorshiftAllNets(i)%p(iphi) = AKorshift\n !!!!! all done\n end do \nend do \nend subroutine SetAkorshiftAllNets_DGV\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! Subrouine InitDGV0D\n!\n! This is a conglomerate subrouine that \n! performes initialization of the \n! parameters, contants and the variables \n! of the DGV Library\n!\n! \n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine InitDGV0D\n\nuse DGV_readwrite\n\nuse DGV_commvar, only: Mv,Mu,Mw,su,sv,sw,nodes_u,&\n MvII,MuII,MwII,suII,svII,swII, & \n Mu_list,Mv_list,Mw_list,su_list,sv_list,sw_list,&\n min_sens,Trad,fm,fmA,run_mode,Cco,&\n\t\t\t\t Order_nu,Order,SecondaryVelGridInUse,&\n\t\t\t\t MoRatesArry0DAllocated,MoRatesArry0D,&\n\t\t\t\t NuNextUpdateTime0D,NuLastDens0D,NuLastTemp0D,numchnksII,&\n A_capphiII,nodes_pcellII\n\n\nuse DGV_dgvtools_mod\n\n!!!!!!!!!!!!!! Variables\ninteger (I4B) :: loc_alloc_stat ! to keep allocation status\ninteger (I4B) :: i,canonical_cell\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! the next group of commands will initiate the key variables of the \n! DGV library. Change this commands if you need \n! different functionality of the library -- say if it is \n! desired to have a different initial velocity grid \n! or additional DGV variables need to be intitialized. \n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! First we read parameters from the DGV library parameter file.\n! the file name \"DGVparametes.dat\" is currently reserved for the DGV parameters. \n! However, this name can be changes\n! by default, the file should be located in the same directory where the executable is started\n!\ncall SetDGVParams(\"DGVparameters.dat\",0)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nMv=Mv_list(1)\nMu=Mu_list(1)\nMw=Mw_list(1)\nsu=su_list(1)\nsv=sv_list(1)\nsw=sw_list(1)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\ncall SetGDVGnodes ! set some supplementary arrays to be used in building meshes\ncall SetDGVblzmmesh ! sets one-dimensional grids in u,v, and w\n! newt we build the velocity discretization \ncall Set3DCellsR_DGV ! We create initial the velocity cells\ncall SetNodesDGV ! this will populate velocity cells with the \n! nodal - DG velocity nodes (see the description of the nodal-DG approach)\n\n!!!!!!\n! If you need to refine the velocity cells the following subroutines can be used: \n! in the next two lines the cell number 14 isdivived in 8 cubcells and in the next line\n! the cell number 41 in the new mech is divided into 27 cubcells\n!!! call CellsRefineDGV((/ 14 /),2,2,2) ! \n!!! call CellsRefineDGV((/ 27 + 14 /),3,3,3)\n\n!!!!!!!!!!!!!!!!!!!!!!!!\n! if one wants to record the cells, gridds and nodes information, use the following commands\n! the parameters for the files names are taken from the DGV library parameter file\n! the grids, cells, and nodes can be used in Matlab graphing subroutines. \n! they are usually not used in restart. \n!\n!!!!!!!!!!!!!!!!!!!!!!!!!\ncall WriteGridsDGV\ncall WriteCellsDGV\ncall WriteNodesDGV\n!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! Additional subroutines: \n! call WriteI1DGV(0.0_DP,0.0_DP,0.0_DP) ! this one will print the number of velocity nodes that \n ! is contained in the cell that has the given velocity point\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!! CREATING NEW OPERATORS A and Akor\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! This is a call that usually is commented. \n! the next subroutines are an OpenMP subroutines\n! that are included in this library and will create a \n! new instance of Operator A or Akor. Specifically, \n! Operators A and Akor depends on the collision model and \n! the DG discretization. Note that subrouitnes creating the operator \n! A and Akor use the primary mesh. (In contrast, when we use pre-computed Operators A and Akor, \n! we can use eithr primary or secondary meshes) Once the (primary) DG discretization is set, \n! on can compute the Operators A or Akor. To do that, uncomment the corresponding line below\n! Be aware that pre-comupting A and Akor is a very slow process and \n! usually should not be attempted on one processor for \n! meshes exceeding 33^3 velocity notes. \n! \n! call SetA_DGV ! call evaluation of A on Gauss nodes\n! call SetAKorobov_DGV ! call evaluation of A on Korobov nodes\n!!!!!!!!!!!!!!!!!\n! For lagre meshes, one should use MPI versio of the \n! subroutine SetA_DGV . \n!\n! TO BE ADDED LATER... \n!\n! \n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \n! Once the Operator A arrays are computed, \n! we need to save then on the hard drive in the \n! directory specified in the DGV parameter file\n! To save Operator A on thehard Drive use the \n! the following subroutine \n!!!!!!!\n! call WriteAarraysDGV ! write A on Gauss nodes on hard drive \n! call WriteAKorArraysDGV ! write A on Korobov nodes on hard drive \n!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!! uncomment the stop directive here is only computing A or Akor arrays....\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! stop \n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!! END CREATING NEW OPERATORS A and Akor\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!! READ pre-computed operators A and Akor\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!!! This will read Operator A arrays using the name specified in the DGV parameter file\ncall ReadAarraysDGV \n!!!! This will read Operator A arrays is they are broken into a number of chunks\n!! call ReadAarraysChnksDGV(25) ! use 9 if the A-array is divided into 9 chunks numbered 0-8. So, \n ! this parameter is the number of chunks, not the number of the last \n ! chunk. Example: to read chunks _ch000 to _ch008 use value 9 here\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!! Sometimes, it is beneficial to truncate A based on |u-u_1| \n!!! Uncomment if desired to truncate based |u-u_1|. Any value of A that corresponds to \n!!! |u-u_1|> then the provided number is truncated\ncall TruncAarrsRadius_DGV (3.0_DP)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!!!! For FFB algorithm, it is benefitial to truncate the kernel \n!!!!! to reduce aliasing. Use the following subroutine to truncate based on distance from the origin.\n!!!!! Comment: need to be replace with the distance from the center of the canonical cell.\n!call TruncAarrsRadiusFromOrigin_DGV(2.0_DP) \n\n!!!! This will read a collection of Akor arrays that correspond to several Korobov nets.\n!!!! Comment if not using Korobov Quadrature evaluation of the collision integral \n! call ReadAKorArraysAllNets_DGV \n!!!!!!! Random number will be used later in the code for Korobov integration \ncall RANDOM_SEED ! prepare the random number generator -- refresh the seed vector\n!!!!!!!!!\n\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!! END READ pre-computed operators A and Akor\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! Once the A and Akor arrays are in the memory, they are still can not be used untill a few additional arrays are \n! set up. The next subroutines set up those arrays.\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! UNCOMMENT IF USING EITHER A or AKOR ON THE PRIMARY MESH\n! This subroutine will set arrays nodes_dui, _dvi, dwi, and nodes_phican\ncall SetCellsUGI_DGV(FindCellContainsPoint_DGV(0.0_DP,0.0_DP,0.0_DP))\n! UNCOMMENT IF USING A ON PRIMARY MESH\n! This subroutine sets up arrays Ashift\ncall SetAshift_DGV(FindCellContainsPoint_DGV(0.0_DP,0.0_DP,0.0_DP))\n! UNCOMMENT IF USING Akor on primary mesh (integrating Boltzmann collision operator using Korobov quadratures)\n! This subroutine sets up arrays AkorAllNets_shift\n! call SetAkorshiftAllNets_DGV(FindCellContainsPoint_DGV(0.0_DP,0.0_DP,0.0_DP))\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! The following few lines set up necessary variables to work with the Boltzmann collision integral. \n! We note that in this code, the Botlzmann collision integral is using secondary mesh. This means that\n! the unknown solution will have to be mapped between the primary and secondary meshes. The secondary mesh, \n! in principle can be the same as primary -- then no interpolation is needed. However, in general, secondary mesh is coarser a\n! and is use to evaluate the full Boltzmann Collision integral (it might be that the task is just too expensive on the primary mesh\n!\n! Because the collisio operator will use secondary mesh we check the flag SecondaryVelGridInUse whether \n! the secondary mesh is in use. If it is, we create the mesh and then may read the operator A\n!\n!!! DEBUG --- uncomment to run Pure Boltzmann on primary grid\nSecondaryVelGridInUse=.false.\n!!! END DEBUG\nif (SecondaryVelGridInUse) then \n! We create variables of the secondary mesh\n! A quick check of we have paparameters of the secondary mesh defined: \n if ((size(Mu_list,1)<2) .or. (size(Mv_list,1)<2) .or.(size(Mw_list,1)<2) .or. &\n (size(su_list,1)<2) .or. (size(sv_list,1)<2) .or. (size(sw_list,1)<2) ) then \n ! Error -- secondary mesh requested, but at least one parameter is missing for it \n print *, \"InitDGV0D: Secondary velocity meshhas been requested, but at least one parameter is missing for secondary mesh.\" \n stop\n ! \n end if\n ! set up the parameters of the secondary nodal-DG discretization. Secondary and primary discretizations use the same \n ! boundaries in the velocity space\n MvII=Mv_list(2)\n MuII=Mu_list(2)\n MwII=Mw_list(2)\n suII=su_list(2)\n svII=sv_list(2)\n swII=sw_list(2)\n ! ready to create secondary meshes \n ! NOTE: the suffix II in the name indicates that the subroutine works with the second mesh \n call SetDGVblzmmeshII ! sets one-dimensional grids in u,v, and w \n ! newt we build the velocity discretization \n call Set3DCellsR_DGVII ! We create initial velocity cells\n call SetNodesDGVII ! this will populate velocity cells with the \n ! nodal - DG velocity nodes (see the description of the nodal-DG approach)\n\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n ! Initializing a PRE-COMPUTED Operator A\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n ! Note that Pre-computed Operator A wil be used for evaluating collision integral and estimating relaxation rates. \n ! These rates will be used in the velocity dependent BGK model. For this model evaluatin will be done using secondary grid. \n ! Therefore one needs to indicate that secondary velocoity grid is used.\n ! For that the flag SecondaryVelGridInUse needs to be set true in the DGVparameters file.\n ! \n ! It may happen that the secondary grid is the same as the primary, but in general we \n ! will expect that the solution is interpolated between the grids\n !!!!!!!!!!!!!!! \n\n ! The evaluation of the Boltzmann collision operator in the method of \n ! Alekseenko-Josyula requires the \n ! knowledge of pre-computed Operator A. \n ! There has been a library of instances of \n ! Operator A computed for different parameters of DG discretizations\n ! The pre-computed operator is loaded using the next batch of commands:\n !\n !!!!!!!!!!!!!!!!!!!!!!!! \n !!!! This will read Operator A arrays using the name specified in the DGV parameter file\n call ReadAarraysDGVII \n !!!! This will read Operator A arrays is they are broken into a number of chunks\n !! call ReadAarraysChnksDGVII(numchnksII) ! use 9 if the A-array is divided into 9 chunks numbered 0-8. So, \n ! this parameter is the number of chunks, not the number of the last \n ! chunk. Example: to read chunks _ch000 to _ch008 use value 9 here\n !!!!!!!!!!!!!!!!!!!!!!!!\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n ! Once the Operator A is loaded into the memory, it can be \n ! truncated somwhat by using two means of truncation:\n ! Truncation using the entry treshhold and truncation to distance between the \n ! velocity nodes. In the first method, all entried of operator A that\n ! fall below the truncation threshold by the absolute value (min_sens) are eliminated\n ! The following subroutine is sued to cut values based on the minimum value:\n !!!!!\n !call TruncAarrsTrhls_DGVII ( 200.0_DP ) !DGVblzmPl.f90\n !!!!!!\n ! Another way to truncate is to eliminate all values of operator \n ! A(v_1,v_2,\\phi) that correspond to v_1 and v_2 separated by more than \n ! certain distance. Specifically if \\| v_1 - v_2 \\| 0) then\n canonical_cell=nodes_pcellII(i)\n exit\n end if\n end do\n \n call SetCellsUGINdsSftArrsII(canonical_cell) ! miscset.f90\n !\n ! Another preparatory call. This one sets up array (nodes_primcellII) used for projecting the primary solution on the secondary mesh\n call prepare_sDGVpMap_DGV ! this subroutine nodes_primcellII\n \n ! the next variable keeps linearized Botlzmann operator in it -- \n ! fmAis uses a lot of memory (su*Mu*sv*Mv*sw*Mw)^2*doublereal\n ! unless linearized Boltzmann is used on a single node, do not uncomment it\n !!!!!!!!!! \n !! allocate (fmA(1:size(nodes_u,1),1:size(nodes_u,1)), stat=loc_alloc_stat)\n !! ! check if the allocation was successful \n !! if (loc_alloc_stat >0) then \n !! print *, \"InitDGV0D: Allocation error for variables (fmA)\"\n !! end if \n !!!!!!!!!!! \n\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nend if \n! End of the section dedicated to secondary mesh and end of preparatory work for\n! Using full Botlzmann collision operator. \n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n!!! Allocate arrays for gaussian nodes and weights to inegration in the first variable\nallocate (fm(1:size(nodes_u,1)), stat=loc_alloc_stat) ! local Maxwellian and array to keep the velocity dependent collision frequency\n! check if the allocation was successful \nif (loc_alloc_stat >0) then \n print *, \"InitDGV0D: Allocation error for variables (fm)\"\nend if \n!\n!!!! DIAGNOSTIC for Prakash can remove later... !!!! \n! allocate the arrays used for preserving the coefficients of the velocity dependent collision frequency\nallocate (Cco(Order_nu), stat=loc_alloc_stat)\nif (loc_alloc_stat >0) then\n print *, \"InitDGV0D: Allocation error for (Cco)\"\nend if\nCco=0 ! reset the coefficients to zero\n!!!!!!!!!!!!!!!!!!!!!!! END Diagnostic for prakash. Can remove later... \n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! next we check if the storage for the moments rates that are used in the velocity dependent collision frequency has been created yet\nif (.not. MoRatesArry0DAllocated) then \n ! we need to create the array for storing the coefficients of the velocity dependent collision frequency: \n allocate (MoRatesArry0D(1:Order), stat=loc_alloc_stat)\n if (loc_alloc_stat >0) then \n print *, \"InitDGV0D: Error allocation arrays to store coefficient of the VDCF (MoRatesArry0D)\"\n stop\n end if \n MoRatesArry0DAllocated = .true.\n! Also, we will set up the other arrays to make sure that the coefficients are updated:\nMoRatesArry0D = 0 ! reset the array\nNuNextUpdateTime0D = - 100000.0 ! these bogus values will set off the criteria for update\nNuLastDens0D = -100000.0 \nNuLastTemp0D = -100000.0 \n! \nend if \n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!!!!!!!!!!!!!!!!!!!!!! \n!! INITIALIZE THE RUN_MODE to ZERO -- in the beginning the regime is strongly non-linear\n run_mode=0\n!!!!!!!!!!!!!!!!!!!!!!!\n\nend subroutine InitDGV0D\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! Subrouine InitDGV1D(nspatialcells)\n!\n! This is copy of the above subroutine, except it creates some arrays to \n! support multiple spatial cells. \n!\n! ATTENTION: you will need to knwo the total number of the spatial cells that the discretization will have \n! before you call this subroutine.\n!\n! This is a conglomerate subrouine that \n! performes initialization of the \n! parameters, contants and the variables \n! of the DGV Library\n!\n! \n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine InitDGV1D(nspatcells)\n\nuse DGV_readwrite\n\nuse DGV_commvar, only: Mv,Mu,Mw,su,sv,sw,nodes_u,&\n MvII,MuII,MwII,suII,svII,swII, & \n Mu_list,Mv_list,Mw_list,su_list,sv_list,sw_list,&\n min_sens,Trad,fm,fmA,run_mode,Cco1D,&\n\t\t\t\t Order_nu,Order,SecondaryVelGridInUse,&\n\t\t\t\t MoRatesArry1DAllocated,MoRatesArry1D,&\n\t\t\t\t NuNextUpdateTime1D,NuLastDens1D,NuLastTemp1D,Nu1DUpdateArrysAllocated,&\n\t\t\t\t TotNumSpatCells,MoRatesReliable1D,run_mode_1D\n\n\nuse DGV_dgvtools_mod\n\n\n!!!!!!!!!!!!!! Variables\ninteger (I4B), intent (in) :: nspatcells ! the total number of the spatial cells --- arrays will be created to store information for each spatial cell. \n ! these arrays support velocity depemdent collision frequency model \n\ninteger (I4B) :: loc_alloc_stat ! to keep allocation status\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! the next group of commands will initiate the key variables of the \n! DGV library. Change this commands if you need \n! different functionality of the library -- say if it is \n! desired to have a different initial velocity grid \n! or additional DGV variables need to be intitialized. \n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! First we read parameters from the DGV library parameter file.\n! the file name \"DGVparametes.dat\" is currently reserved for the DGV parameters. \n! However, this name can be changes\n! by default, the file should be located in the same directory where the executable is started\n!\ncall SetDGVParams(\"DGVparameters.dat\",0)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nMv=Mv_list(1)\nMu=Mu_list(1)\nMw=Mw_list(1)\nsu=su_list(1)\nsv=sv_list(1)\nsw=sw_list(1)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\ncall SetGDVGnodes ! set some supplementary arrays to be used in building meshes\ncall SetDGVblzmmesh ! sets one-dimensional grids in u,v, and w\n! newt we build the velocity discretization \ncall Set3DCellsR_DGV ! We create initial the velocity cells\ncall SetNodesDGV ! this will populate velocity cells with the \n! nodal - DG velocity nodes (see the description of the nodal-DG approach)\n\n!!!!!!\n! If you need to refine the velocity cells the following subroutines can be used: \n! in the next two lines the cell number 14 isdivived in 8 cubcells and in the next line\n! the cell number 41 in the new mech is divided into 27 cubcells\n!!! call CellsRefineDGV((/ 14 /),2,2,2) ! \n!!! call CellsRefineDGV((/ 27 + 14 /),3,3,3)\n\n!!!!!!!!!!!!!!!!!!!!!!!!\n! if one wants to record the cells, gridds and nodes information, use the following commands\n! the parameters for the files names are taken from the DGV library parameter file\n! the grids, cells, and nodes can be used in Matlab graphing subroutines. \n! they are usually not used in restart. \n!\n!!!!!!!!!!!!!!!!!!!!!!!!!\ncall WriteGridsDGV\ncall WriteCellsDGV\ncall WriteNodesDGV\n!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! Additional subroutines: \n! call WriteI1DGV(0.0_DP,0.0_DP,0.0_DP) ! this one will print the number of velocity nodes that \n ! is contained in the cell that has the given velocity point\n! call InitWriteDet ! velocity dependent collision frequency. These subroutines only create an empty file. \n ! later calls of related subroutines will save some diagnostic data in the created \n ! files. These files make problems in many clusters becuase of the \n ! writing protection. If the file is not deleted, it can not be overwritten by \n ! a new instance of the running software -- we commented the use of the subroutines for now\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!! CREATING NEW OPERATORS A and Akor\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! This is a call that usually is commented. \n! the next subroutines are an OpenMP subroutines\n! that are included in this library and will create a \n! new instance of Operator A or Akor. Specifically, \n! Operators A and Akor depends on the collision model and \n! the DG discretization. Note that subrouitnes creating the operator \n! A and Akor use the primary mesh. (In contrast, when we use pre-computed Operators A and Akor, \n! we can use eithr primary or secondary meshes) Once the (primary) DG discretization is set, \n! on can compute the Operators A or Akor. To do that, uncomment the corresponding line below\n! Be aware that pre-comupting A and Akor is a very slow process and \n! usually should not be attempted on one processor for \n! meshes exceeding 33^3 velocity notes. \n! \n! call SetA_DGV ! dgvtools_mod.f90\n! call SetAKorobov_DGV\n!!!!!!!!!!!!!!!!!\n! For lagre meshes, one should use MPI versio of the \n! subroutine SetA_DGV . \n!\n! TO BE ADDED LATER... \n!\n! \n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \n! Once the Operator A arrays are computed, \n! we need to save then on the hard drive in the \n! directory specified in the DGV parameter file\n! To save Operator A on thehard Drive use the \n! the following subroutine \n!!!!!!!\n! call WriteAarraysDGV\n! call WriteAKorArraysDGV\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!! READ pre-computed operators A and Akor\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!!! This will read Operator A arrays using the name specified in the DGV parameter file\n!! call ReadAarraysDGV \n!!!! This will read Operator A arrays is they are broken into a number of chunks\n!! call ReadAarraysChnksDGV(25) ! use 9 if the A-array is divided into 9 chunks numbered 0-8. So, \n ! this parameter is the number of chunks, not the number of the last \n ! chunk. Example: to read chunks _ch000 to _ch008 use value 9 here\n!!!!!!!!!!!!!!!!!!!!!!!!\n!!!! This will read a collection of Akor arrays that correspond to several Korobov nets.\n!!!! Comment if not using Korobov Quadrature evaluation of the collision integral \n !call ReadAKorArraysAllNets_DGV \n!!!!!!! Random number will be used later in the code for Korobov integration \ncall RANDOM_SEED ! prepare the random number generator -- refresh the seed vector\n!!!!!!!!!\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!! END READ pre-computed operators A and Akor\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! Once the A and Akor arrays are in the memory, they are still can not be used untill a few additional arrays are \n! set up. The next subroutines set up those arrays.\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! UNCOMMENT IF USING EITHER A or AKOR ON THE PRIMARY MESH\n! This subroutine will set arrays nodes_dui, _dvi, dwi, and nodes_phican\ncall SetCellsUGI_DGV(FindCellContainsPoint_DGV(0.0_DP,0.0_DP,0.0_DP))\n! UNCOMMENT IF USING A ON PRIMARY MESH\n! This subroutine sets up arrays Ashift\n! call SetAshift_DGV(FindCellContainsPoint_DGVII(0.0_DP,0.0_DP,0.0_DP))\n! UNCOMMENT IF USING Akor on primary mesh (integrating Boltzmann collision operator using Korobov quadratures)\n! This subroutine sets up arrays AkorAllNets_shift\n !call SetAkorshiftAllNets_DGV(FindCellContainsPoint_DGV(0.0_DP,0.0_DP,0.0_DP))\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! The following few lines set up necessary variables to work with the Boltzmann collision integral. \n! We note that in this code, the Botlzmann collision integral is using secondary mesh. This means that\n! the unknown solution will have to be mapped between the primary and secondary meshes. The secondary mesh, \n! in principle can be the same as primary -- then no interpolation is needed. However, in general, secondary mesh is coarser a\n! and is use to evaluate the full Boltzmann Collision integral (it might be that the task is just too expensive on the primary mesh\n!\n! Because the collisio operator will use secondary mesh we check the flag SecondaryVelGridInUse whether \n! the secondary mesh is in use. If it is, we create the mesh and then may read the operator A\n!\nif (SecondaryVelGridInUse) then \n! We create variables of the secondary mesh\n! A quick check of we have paparameters of the secondary mesh defined: \n if ((size(Mu_list,1)<2) .or. (size(Mv_list,1)<2) .or.(size(Mw_list,1)<2) .or. &\n (size(su_list,1)<2) .or. (size(sv_list,1)<2) .or. (size(sw_list,1)<2) ) then \n ! Error -- secondary mesh requested, but at least one parameter is missing for it \n print *, \"InitDGV0D: Secondary velocity meshhas been requested, but at least one parameter is missing for secondary mesh.\" \n stop\n ! \n end if\n ! set up the parameters of the secondary nodal-DG discretization. Secondary and primary discretizations use the same \n ! boundaries in the velocity space\n MvII=Mv_list(2)\n MuII=Mu_list(2)\n MwII=Mw_list(2)\n suII=su_list(2)\n svII=sv_list(2)\n swII=sw_list(2)\n ! ready to create secondary meshes \n ! NOTE: the suffix II in the name indicates that the subroutine works with the second mesh \n call SetDGVblzmmeshII ! sets one-dimensional grids in u,v, and w \n ! newt we build the velocity discretization \n call Set3DCellsR_DGVII ! We create initial velocity cells\n call SetNodesDGVII ! this will populate velocity cells with the \n ! nodal - DG velocity nodes (see the description of the nodal-DG approach)\n\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n ! Initializing a PRE-COMPUTED Operator A\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n ! Note that Pre-computed Operator A wil be used for evaluating collision integral and estimating relaxation rates. \n ! These rates will be used in the velocity dependent BGK model. For this model evaluatin will be done using secondary grid. \n ! Therefore one needs to indicate that secondary velocoity grid is used.\n ! For that the flag SecondaryVelGridInUse needs to be set true in the DGVparameters file.\n ! \n ! It may happen that the secondary grid is the same as the primary, but in general we \n ! will expect that the solution is interpolated between the grids\n !!!!!!!!!!!!!!! \n\n ! The evaluation of the Boltzmann collision operator in the method of \n ! Alekseenko-Josyula requires the \n ! knowledge of pre-computed Operator A. \n ! There has been a library of instances of \n ! Operator A computed for different parameters of DG discretizations\n ! The pre-computed operator is loaded using the next batch of commands:\n !\n !!!!!!!!!!!!!!!!!!!!!!!! \n !!!! This will read Operator A arrays using the name specified in the DGV parameter file\n call ReadAarraysDGVII \n !!!! This will read Operator A arrays is they are broken into a number of chunks\n !! call ReadAarraysChnksDGVII(25) ! use 9 if nine chunks are in A-arrays, so it is always the number of chunks\n !!!!!!!!!!!!!!!!!!!!!!!!\n\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n ! Once the Operator A is loaded into the memory, it can be \n ! truncated somwhat by using two means of truncation:\n ! Truncation using the entry treshhold and truncation to distance between the \n ! velocity nodes. In the first method, all entried of operator A that\n ! fall below the truncation threshold by the absolute value (min_sens) are eliminated\n ! The following subroutine is sued to cut values based on the minimum value:\n !!!!!\n ! call TruncAarrsTrhls_DGVII ( min_sens ) !DGVblzmPl.f90\n !!!!!!\n ! Another way to truncate is to eliminate all values of operator \n ! A(v_1,v_2,\\phi) that correspond to v_1 and v_2 separated by more than \n ! certain distance. Specifically if \\| v_1 - v_2 \\|0) then \n !! print *, \"InitDGV0D: Allocation error for variables (fmA)\"\n !! end if \n !!!!!!!!!!! \n\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nend if \n! End of the section dedicated to secondary mesh and end of preparatory work for\n! Using full Botlzmann collision operator. \n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n!!! Allocate arrays for gaussian nodes and weights to inegration in the first variable\nallocate (fm(1:size(nodes_u,1)), stat=loc_alloc_stat) ! local Maxwellian and array to keep the velocity dependent collision frequency\n! check if the allocation was successful \nif (loc_alloc_stat >0) then \n print *, \"InitDGV1D: Allocation error for variables (fm)\"\nend if \n\nTotNumSpatCells=nspatcells ! record the total number of cells for future checks\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!! Atention: this array may be used in the BGK model with velocity dependent collision frequency. \n!! However, currently, the version of the subrouine does not make use if this array: therefore its allocation is commented. \n!\n! allocate the arrays used for preserving the coeeficients of the velocity dependent collision frequency\n!allocate (Cco1D(Order_nu,nspatcells), stat=loc_alloc_stat)\n!if (loc_alloc_stat >0) then\n! print *, \"InitDGV1D: Allocation error for (Cco1D)\"\n!end if\n!Cco1D=0 ! reset the coefficients to zero\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! next we check if the storage for the moments rates that are used in the velocity dependent collision frequency has been created yet\nif (.not. MoRatesArry1DAllocated) then \n ! we need to create the array for storing the coefficients of the velocity dependent collision frequency: \n allocate (MoRatesArry1D(1:Order,nspatcells), stat=loc_alloc_stat)\n if (loc_alloc_stat >0) then \n print *, \"InitDGV1D: Error allocation arrays to store coefficient of the VDCF (MoRatesArry0D)\"\n stop\n end if \n MoRatesArry1DAllocated = .true.\n! Also, we will set up the other arrays to make sure that the coefficients are updated:\nMoRatesArry1D = 0 ! reset the array\nend if \n! Allocate arrays that will keep the flag is the relaxation rates are reliable in the spatial cell: \nallocate (MoRatesReliable1D(nspatcells), stat=loc_alloc_stat)\nif (loc_alloc_stat >0) then\n print *, \"InitDGV1D: Allocation error for (MoRatesReliable1D)\"\nend if\nMoRatesReliable1D=.false. ! reset the coefficients to false\n!\n! Allocate arrays that will keep the run_mode for ech spatial cell: \nallocate (run_mode_1D(nspatcells), stat=loc_alloc_stat)\nif (loc_alloc_stat >0) then\n print *, \"InitDGV1D: Allocation error for (run_mode_1D)\"\nend if\nrun_mode_1D = 0 ! reset the coefficients to mode=0 = full Boltzmann!\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! next we check if the storage has been created for information about the last update of the relaxation rates\nif (.not. Nu1DUpdateArrysAllocated) then \n ! we need to create the array for storing the coefficients of the velocity dependent collision frequency: \n allocate (NuNextUpdateTime1D(nspatcells),NuLastDens1D(nspatcells),NuLastTemp1D(nspatcells), stat=loc_alloc_stat)\n if (loc_alloc_stat >0) then \n print *, \"InitDGV1D: Error allocation arrays to store information about last rates apdate: (NuNextUpdateTime1D),\" // &\n \"(NuLastDens1D),(NuLastTemp1D)\" \n stop\n end if \nNu1DUpdateArrysAllocated = .true.\n! Also, we will initialize the arrays to make sure that the coefficients are updated:\nNuNextUpdateTime1D = - 100000.0 ! these bogus values will set off the criteria for update\nNuLastDens1D = -100000.0 \nNuLastTemp1D = -100000.0 \nend if \n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n!!!!!!!!!!!!!!!!!!!!!!! THIS VARIABLE SHOULD NOT BE USED --- CHECK AND REMOVE LATER>\n!! INITIALIZE THE RUN_MODE to ZERO -- in the beginning the regime is strongly non-linear\n run_mode=0\n!!!!!!!!!!!!!!!!!!!!!!!\n\nend subroutine InitDGV1D\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! prepare_sDGVpMap_DGV\n!\n! This subrouine sets some supplementary arrays that will be used to project the solution from the primary to the secondary meshes\n! \n! In particular, this subroutine sets the array nodesII_primcell -- this array identifies the cell on the primary node that This subroutine sets an inmatrix for converting the solutions from the primary velocity mesh to the secondary velocity mesh \n! In the case when the both meshes are uniform. \n!\n! ATTENTION! do not call before both primary and secondary meshes are set up! \nsubroutine prepare_sDGVpMap_DGV\n\nuse DGV_commvar, only: nodes_uII,nodes_vII,nodes_wII,nodes_primcellII\n\nuse DGV_dgvtools_mod\n\n!!!!!\ninteger (I4B):: i ! \ninteger :: loc_alloc_stat ! to keep allocation status\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! First, we need to allocate the nodes_primcellII array\nallocate (nodes_primcellII(size(nodes_uII,1)), stat=loc_alloc_stat)\nif (loc_alloc_stat >0) then\n print *, \"prepare_sDGVpMap_DGV: Allocation error for (nodes_primcellII)\"\nend if\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! now we will now go over the secondary mesh and find out where the secondary nodes falls on the primary mesh.\n! the number of the cell is recoded into the array nodes_primcellII\ndo i=1,size(nodes_uII,1)\n nodes_primcellII(i) = FindCellContainsPoint_DGV(nodes_uII(i),nodes_vII(i),nodes_wII(i))\nend do \n! all done \nend subroutine prepare_sDGVpMap_DGV\n\nend module DGV_miscset\n", "meta": {"hexsha": "afd39c0f9f4527cc7ad3a6d7d265bf324b63736e", "size": 113661, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "DGV0D3V/DGV_miscsetup.f90", "max_stars_repo_name": "alexmalekseenko/DGV0D3V", "max_stars_repo_head_hexsha": "2136be5a4af6c2c83e7cf543460845447c510359", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "DGV0D3V/DGV_miscsetup.f90", "max_issues_repo_name": "alexmalekseenko/DGV0D3V", "max_issues_repo_head_hexsha": "2136be5a4af6c2c83e7cf543460845447c510359", "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": "DGV0D3V/DGV_miscsetup.f90", "max_forks_repo_name": "alexmalekseenko/DGV0D3V", "max_forks_repo_head_hexsha": "2136be5a4af6c2c83e7cf543460845447c510359", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.3196168854, "max_line_length": 249, "alphanum_fraction": 0.6789488039, "num_tokens": 33242, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.6567394016747792}} {"text": " subroutine mstat(a,n,xmax,xmin,xrms,xmean)\n implicit real*8 (a-h,o-z)\n dimension a(n)\n xmax=-1d36\n xmin= 1d36\n xmean=0d0\n xrms=0d0\n do 10 i=1,n\n xmax=max(xmax,a(i))\n xmin=min(xmin,a(i))\n 10 continue\n do 20 i=1,n\n xmean=xmean+a(i)\n xrms=xrms+a(i)*a(i)\n 20 continue\n if(n.ne.0) then\n xrms=sqrt(xrms/n)\n xmean=xmean/n\n else\n xmax=0d0\n xmin=0d0\n endif\n return\n end\n", "meta": {"hexsha": "10c5904b2f9408fe0ede599e8a1d6bcc010531b2", "size": 492, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/mstat.f", "max_stars_repo_name": "noboruatkek/SAD", "max_stars_repo_head_hexsha": "3881a190af8903537774c57b56963ffc94cfc039", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2019-04-01T15:54:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-09T16:47:20.000Z", "max_issues_repo_path": "src/mstat.f", "max_issues_repo_name": "noboruatkek/SAD", "max_issues_repo_head_hexsha": "3881a190af8903537774c57b56963ffc94cfc039", "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/mstat.f", "max_forks_repo_name": "noboruatkek/SAD", "max_forks_repo_head_hexsha": "3881a190af8903537774c57b56963ffc94cfc039", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2017-03-15T08:52:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-19T08:06:40.000Z", "avg_line_length": 19.68, "max_line_length": 48, "alphanum_fraction": 0.493902439, "num_tokens": 176, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.7606506418255928, "lm_q1q2_score": 0.6567393876208849}} {"text": "C---------------------------------------------------------------------------\nC KING_MODEL : Set of subroutines to calculate King's model\nC Version of November 14th 1986\nC---------------------------------------------------------------------------\n SUBROUTINE KING(NPTS)\nC---------------------------------------------------------------------------\nC Solves the differential equations for King's model to obtain\nC the relative values of density (RHO) and potential (PHI).\nC Input :\nC NPTS = on entry : max number of points for the model\nC W0 = Potential in the center (linked with the concentration)\nC Output :\nC NPTS = on exit : effective number of points up to the tidal radius\nC RAD = radii for the model\nC PHI = potential\nC DPHI = derivate of the potential\nC RTIDAL\nC NINDEX = index incremented after each call in subroutine \"OUT\"\nC\nC\nC--------------------------------------------------------------------------\n PARAMETER (IDIM=10000)\n IMPLICIT DOUBLE PRECISION (A-H,O-Z)\n LOGICAL FOUND\n DIMENSION RHO(IDIM),PHI(IDIM),RAD(IDIM),\n + Y(2),W(2,10),DPHI(IDIM)\nC\n\tCOMMON /KING/RHO,PHI,RAD,NINDEX,DPHI\n\tCOMMON /KING3/ W0,RTIDAL,RHO0\n\tCOMMON/CONSTANT/PI,PIROOT\nC Subroutines called by NAG Routine D02BBF...\n\tEXTERNAL FCN,OUT\nC evaluate some numbers required in lower subroutines and used\nC to evaluate the relative density at a given potential\nC from an analytic expression. Passed around in /king2/\nC\n\tPI=3.14159265358979323846\n\tPIROOT=DSQRT(PI)\n\tW0ROOT=DSQRT(W0)\n\tERF0=S15AEF(W0ROOT,IFAIL)\n\tRHO0=0.75D0*PIROOT*DEXP(W0)*ERF0\n\tRHO0=RHO0 - 1.5D0*W0ROOT - W0**1.5D0\nC\n TOL=1.0E-4\n NEQS=2\n IRELAB=0\n IFAIL=0\n REND=RAD(NPTS)\n NINDEX=2 ! increment index, first increment filled later\n ! by initial conditions R=0, W=W0, PHI=1\n\tRSTART=1.0D-3 !starting conditions a bit away from R=0\nC\t\t ! if not error due to division by 0 in FCN\t\n TOL=1.0D-4\n Y(1)=W0-1.5D0*RSTART*RSTART ! initial conditions for NAG/D02BBF\n Y(2)=-3.0D0*RSTART\nC\nC NAG routine D02BBF solves Poisson's equation. The relative densities\nC are evaluated as required in the subroutine FCN\nC Subroutine OUT fills the relevant arrays.\nC At the end of it all, arrays containing the potential and the\nC corresponding radius are filled, (except element 1, see RHORAD)\nC They are RAD and PHI\nC\n CALL D02BBF(RSTART,REND,NEQS,Y,TOL,IRELAB,FCN,OUT,\n + W,IFAIL)\nC (Resolution of the system of 2 ordinary equations\nC dy1/dR = y2\nC dy2/dR = 9 Rho(y1)/Rho0 - 2 y2 / R\nC\nC Calling FCN and OUT )\nC\nC now evaluate the relative density corresponding to each radius\nC element. We now have three arrays, RADIUS, POTENTIAL and\nC DENSITY (relative to the central value).\nC Also the tidal radius is found here and NPTS is set to its effective\nC value\nC\n\tCALL RHORAD(NPTS)\n\tPRINT *,' MODEL CALCULATED WITH',NPTS,' POINTS'\n\tRETURN\n\tEND\n \nC--------------------------------------------------------------------\n SUBROUTINE FCN(R,Y,F)\nC---------------------------------------------------------------------\nC subroutine to evaluate the values of the two first order\nC differential equations used to solve poissons equation\nC The relative density is evaluated here using the analytic\nC expression of Hills and Day Ap Lett 17,87, 1976\nC Y(1) = W\nC Y(2) = W1\nC F(1)=DY(1)/D(R) = W1\nC F(2)=DY(2)/D(R) = -9*RHO/RHO0 -2/R * W1\nc---------------------------------------------------------------------\n\tIMPLICIT REAL*8 (A-H,O-Z)\n REAL*8 T,Y(2),F(2),RELRHO\nC----------------------------------------------------------------------\nC\nC trap potential going negative. if it does i.e. we have\nC reached the tidal radius then set the relative density to\nC zero else the analytic function will bomb whilst trying to\nC find the square root of the potential.\nC\nC\n IF(Y(1).GT.0.0D0) THEN\n CALL RHOEVAL(RELRHO,Y(1)) !find relative density at W=Y(1)\n ELSE\n RELRHO=0.0D0\n END IF\n ! the values of the de's\n F(1)=Y(2)\n F(2)=-9.0D0*RELRHO - (2.0D0*Y(2))/R\n RETURN\n END\nC--------------------------------------------------------------------------\n SUBROUTINE OUT(R,Y)\nC--------------------------------------------------------------------\nC Stores the potential and its derivate corresponding to the radii R\nC--------------------------------------------------------------------\n\tPARAMETER (IDIM=10000)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n\tDIMENSION DPHI(IDIM)\n\tDIMENSION Y(2),RHO(IDIM),PHI(IDIM),RAD(IDIM)\n\tCOMMON /KING/RHO,PHI,RAD,NINDEX,DPHI\n \n\tPHI(NINDEX)=Y(1)\n\tDPHI(NINDEX)=Y(2)\n\tNINDEX=NINDEX+1\n\tR=RAD(NINDEX)\n \n\tRETURN\n\tEND\nC--------------------------------------------------------------------\n SUBROUTINE RHORAD(NPTS)\nC----------------------------------------------------------------------\nC subroutine to evaluate the relative density at each of the radius\nC increments and fill the array RHO.\nC Also finds tidal radius rtidal via a parabolic interpolation\nC-----------------------------------------------------------------------\n PARAMETER (IDIM=10000)\n IMPLICIT DOUBLE PRECISION (A-H,O-Z)\n REAL*8 PHI(IDIM),RHO(IDIM),RAD(IDIM)\n REAL*8 RTIDAL,DPHI(IDIM)\n CHARACTER*80 OUTPUT\n LOGICAL*4 FOUND_TIDAL\n\tCOMMON /KING3/ W0,RTIDAL,RHO0\n\tCOMMON /KING/RHO,PHI,RAD,NINDEX,DPHI\nc----------------------------------------------------------------------\n FOUND_TIDAL=.FALSE.\nC\nC fill element 1 of arrays with conditions at R=0\nC\n PHI(1)=W0\n RHO(1)=1.0D0\n \n DO J=2,NINDEX-1 !NINDEX is incremented in OUT after last call\n IF(PHI(J).GT.0.0D0) THEN\n CALL RHOEVAL(RELRHO,PHI(J)) !find RELDENS at W=PHI(J)\n RHO(J)=RELRHO\n ELSE\n CALL FIND_TIDAL(J,RTIDAL)\n FOUND_TIDAL=.TRUE.\n GOTO 100\n END IF\n END DO\n 100 NPTS=J-1\n IF(.NOT.FOUND_TIDAL) THEN\n PRINT *,' '\n PRINT *,'YOU HAVE NOT INTEGRATED FAR ENOUGH TO REACH'\n PRINT *,'THE TIDAL RADIUS (IN THE MODEL)'\n WRITE (6,33) RHO(J-1)\n 33 FORMAT ('FINAL RELATIVE DENSITY VALUE = ',F20.10)\n ELSE\n PRINT *,' '\n WRITE (6,44) RTIDAL\n44\tFORMAT ('THE TIDAL RADIUS = ',F20.10)\n END IF\n RETURN\n END\nC\nC--------------------------------------------------------------------\n \n SUBROUTINE RHOEVAL(RELRHO,POT)\nC--------------------------------------------------------------------\nC subroutine to evaluate the relative density at a given\nC potential pot. Uses Hills and Day's analytic expression\nC--------------------------------------------------------------------\n PARAMETER (IDIM=10000)\n IMPLICIT DOUBLE PRECISION (A-H,O-Z)\n\tREAL*8 RHO(IDIM),RAD(IDIM),DPHI(IDIM),PHI(IDIM)\n INTEGER*4 IFAIL\n\tCOMMON/CONSTANT/PI,PIROOT\n\tCOMMON/KING3/ W0,RTIDAL,RHO0\n\tCOMMON/KING/RHO,PHI,RAD,NINDEX,DPHI\nC----------------------------------------------------------------------\n POTROOT=DSQRT(POT)\n IFAIL=0\n ERF=S15AEF(POTROOT,IFAIL)\n RHO1=0.75D0*PIROOT*DEXP(POT)*ERF\n RHO1=RHO1 - 1.5D0*POTROOT - POT**1.5D0\n RELRHO=RHO1/RHO0 !THE RELATIVE DENSITY AT THE VALUE W=POT\n RETURN\n END\nC---------------------------------------------------------------------\n SUBROUTINE FIND_TIDAL(INDEX,RTIDAL)\nC---------------------------------------------------------------------\nC subroutine to evaluate the tidal radius position\nC uses parabolic interpolation of last three useful points. The\nC last point is the first point at which the potential becomes\nC negative.\nC---------------------------------------------------------------------\n\tPARAMETER (IDIM=10000)\n\tIMPLICIT REAL*8 (A-H,O-Z)\n\tREAL*8 RAD(IDIM),PHI(IDIM),DPHI(IDIM),RHO(IDIM)\n\tINTEGER*4 INDEX\n\tCOMMON /KING/RHO,PHI,RAD,NINDEX,DPHI\nC-----------------------------------------------------------------------\n \nC\nC index is the index of the arrays at which the potential becomes\nC negative. Set up interpolation coefficients\nC\n W1=PHI(INDEX-2)\n W2=PHI(INDEX-1)\n W3=PHI(INDEX)\n R1=RAD(INDEX-2)\n R2=RAD(INDEX-1)\n R3=RAD(INDEX)\n \n COEF1=W2*W3/( (W1-W2)*(W1-W3) )\n COEF2=W1*W3/( (W2-W1)*(W2-W3) )\n COEF3=W1*W2/( (W3-W1)*(W3-W2) )\n \n \nC\nC evaluate tidal radius\nC\n RTIDAL=R1*COEF1 + R2*COEF2 + R3*COEF3\n RETURN\n END\nC**********************************************************************\nC\tFONCTION DERF DE CALCUL DE LA FONCTION D'ERREUR\nC**********************************************************************\n\tDOUBLE PRECISION FUNCTION DERF(X)\n\tREAL*8 X,P,T,EER\n\tDOUBLE PRECISION A(5)\n\tDATA A/.254829592D0,-.284496736D0,1.421413741D0,\n\t1\t-1.453152027D0,1.061405429D0/\n\tDATA P/0.3275911D0/\n\tT=1D0/(1D0+P*X)\n\tEER=DEXP(-1D0*X*X)\n\tEER=EER*((((A(5)*T+A(4))*T+A(3))*T+A(2))*T+A(1))*T\n\tDERF=1D0-EER\n\tEND\nC--------------------------------------------------------------------\n SUBROUTINE MASS_KING(RADMAX,XMU1,NPTS)\nC--------------------------------------------------------------------\nC Subroutine to evaluate the integrated mass MU1 up to a given\nC radius RADMAX.\nC--------------------------------------------------------------------\n\tPARAMETER (IDIM=10000)\n\tIMPLICIT DOUBLE PRECISION (A-H,O-Z)\n\tREAL*8 RHO(IDIM),RAD(IDIM),DPHI(IDIM),PHI(IDIM)\n\tREAL*8 SPLINE1(IDIM),K1(IDIM)\n\tREAL*8 YY(IDIM)\n\tCOMMON/CONSTANT/PI,PIROOT\n\tCOMMON/KING3/W0,RTIDAL,RHO0\n\tCOMMON/KING/RHO,PHI,RAD,NINDEX,DPHI\n\tCOMMON/SPLINE1/NCAP71,K1,SPLINE1\n \n\tIF(RADMAX.GT.RTIDAL)THEN\n\tRADMAX=RTIDAL\n\tPRINT *,' RADMAX GREATER THAN RTIDAL, SO I SET IT TO RTIDAL'\n\tENDIF\n \nC Fills the arrays for further interpolation up to RTIDAL:\n\tRAD(NPTS+1)=RTIDAL\n\tRHO(NPTS+1)=0.D0\n\tNPOINT=NPTS+1\n \nC Interpolation of the input points with a cubic-spline :\n\tCALL SPLINE_INTER(RAD,RHO,NPOINT,SPLINE1,NCAP71,K1)\n \nC Integration from RADMIN to RADMAX\n\tRADMIN=RAD(1)\n\tPRINT *,' RADMIN =',RADMIN\n\tSUM=XMASS_KING1(RADMIN,RADMAX)\n\tPRINT *,' RHO0 :',RHO0\n\tXMU1=4.D0*PI*SUM/RHO0\n \n\tRETURN\n\tEND\nC---------------------------------------------------------------------------\nC Function XMASS_KING1\nC--------------------------------------------------------------------------\n\tDOUBLE PRECISION FUNCTION XMASS_KING1(XLOW,XHIGH)\n\tIMPLICIT REAL*8(A-H,O-Z)\n\tREAL*8 W(4000)\n\tINTEGER*4 IW(502)\n\tEXTERNAL FUN_KING1\n \nC Absolute and relative accuracy :\n EPSABS=0.000001\n EPSREL=0.0001\n \nC Size of the work areas W(real) and IW(integer)\n LW=4000\n LIW=502\n \nC Calling a rather sophisticated integration routine D01AKF :\n IFAIL=1\n CALL D01AKF(FUN_KING1,XLOW,XHIGH,EPSABS,EPSREL,SUM,\n\t1\tABSERR,W,LW,IW,LIW,IFAIL)\n \n IF(IFAIL.NE.0) THEN\n PRINT *,' WARNING : FAILURE IN D01AKF, IFAIL =',IFAIL\n END IF\n \n\tXMASS_KING1=SUM\n \n\tRETURN\n\tEND\nC---------------------------------------------------------------------------\nC Function FUN_KING1\nC Called by D0AKF\nC Generates the value to be integrated at the point X\nC---------------------------------------------------------------------------\n\tDOUBLE PRECISION FUNCTION FUN_KING1(X)\n\tPARAMETER (IDIM=10000)\n\tIMPLICIT REAL*8(A-H,O-Z)\n\tREAL*8 SPLINE1(IDIM),K1(IDIM)\n\tCOMMON/SPLINE1/NCAP71,K1,SPLINE1\n\tIFAIL=1\n\tCALL E02BBF(NCAP71,K1,SPLINE1,X,RHOX,IFAIL)\n \n\tIF(IFAIL.NE.0)THEN\n\tPRINT 20,IFAIL\n20\tFORMAT(' **** WARNING ! **** IN E02BBF IFAIL =',I3,\n\t1\t/,' (MASS INTEGRATION)')\n\tPRINT *,' X=',X\n\tRHOX=0.\n\tENDIF\n \nC Integral of RHO*(RAD**2):\n\tFUN_KING1=RHOX*X*X\n \n\tRETURN\n\tEND\n", "meta": {"hexsha": "eaedbd319288590ce27aac52da10cd84d7b17fc0", "size": 11586, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "jlpsub/king_model.for", "max_stars_repo_name": "jlprieur/shell_galaxies", "max_stars_repo_head_hexsha": "1dde87ef33b3c33b3a892e9ad0d642ae02ac6d9e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "jlpsub/king_model.for", "max_issues_repo_name": "jlprieur/shell_galaxies", "max_issues_repo_head_hexsha": "1dde87ef33b3c33b3a892e9ad0d642ae02ac6d9e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "jlpsub/king_model.for", "max_forks_repo_name": "jlprieur/shell_galaxies", "max_forks_repo_head_hexsha": "1dde87ef33b3c33b3a892e9ad0d642ae02ac6d9e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.1977077364, "max_line_length": 76, "alphanum_fraction": 0.5355601588, "num_tokens": 3440, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391595913457, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.656739385632288}} {"text": "program gmresvsgauss\r\n USE GMRES\r\n USE M_SOLVER\r\n USE IFPORT\r\n implicit none\r\n\r\n\r\n COMPLEX, DIMENSION(:,:), ALLOCATABLE :: random_matrix, gauss_matrix, gmres_matrix\r\n COMPLEX, DIMENSION(:), ALLOCATABLE :: random_sol, gmres_sol\r\n\r\n integer:: arg_count, num_iterations,i, n,j,iter\r\n character(200) :: arg\r\n real:: cpu_time_begin, cpu_time_end, total_cpu_gauss, total_cpu_gmres\r\n DOUBLE PRECISION :: WALL_START_TIME, WALL_STOP_TIME, total_wall_gauss, total_wall_gmres\r\n complex :: ONE, ZERO\r\n\r\n n = 2000\r\n ONE = CMPLX(1., 0.)\r\n ZERO = CMPLX(0., 0.)\r\n\r\n arg_count = command_argument_count()\r\n\r\n num_iterations = 1\r\n\r\n if(arg_count >=1 ) then\r\n call get_command_argument(1, arg)\r\n read(arg,*) num_iterations\r\n\r\n end if\r\n\r\n !CALL RANDOM_SEED()\r\n total_cpu_gmres = 0\r\n total_cpu_gauss = 0\r\n total_wall_gmres = 0\r\n total_wall_gauss = 0\r\n\r\n do iter=1,num_iterations\r\n\r\n write(*,*) 'Iteration ', iter\r\n write(*,*) 'Generates ', n , ' x ', n, ' matrix'\r\n ALLOCATE(random_matrix(n,n))\r\n ALLOCATE(random_sol(n))\r\n ALLOCATE(gauss_matrix(n,n+1), gmres_matrix(n,n), gmres_sol(n))\r\n\r\n\r\n random_matrix = cmplx(0.,0.)\r\n do i=1,n\r\n random_matrix(i,i) = (4.0e0, 0.0e0)\r\n end do\r\n do i = 1,n-1\r\n random_matrix(i,i+1) = (-2.0e0, 1.0e0)\r\n random_matrix(i+1,i) = (-1.0e0, 1.0e0)\r\n enddo\r\n\r\n gmres_sol = ONE\r\n\r\n call cgemv('N',n,n,ONE,random_matrix,n,gmres_sol,1,ZERO,random_sol,1)\r\n\r\n do i=1,n\r\n do j=1,n\r\n gauss_matrix(i, j) = random_matrix(i,j)\r\n gmres_matrix(i, j) = random_matrix(i,j)\r\n end do\r\n gauss_matrix(i, n+1) = random_sol(i)\r\n gmres_sol(i) = random_sol(i)\r\n end do\r\n\r\n write(*,*) 'Solving with gmres started'\r\n\r\n CALL CPU_TIME ( cpu_time_begin )\r\n WALL_START_TIME = DCLOCK()\r\n\r\n CALL compute_gmres(gmres_matrix, gmres_sol, n)\r\n\r\n WALL_STOP_TIME = DCLOCK()\r\n CALL CPU_TIME ( cpu_time_end )\r\n\r\n write(*, *) 'GMRES completed with following statistics:'\r\n write(*,*) 'cpu time(s) ' , cpu_time_end - cpu_time_begin\r\n write(*,*) 'wall elapsed time(s) ', WALL_STOP_TIME-WALL_START_TIME\r\n write(*,*)\r\n total_cpu_gmres = total_cpu_gmres + cpu_time_end - cpu_time_begin\r\n total_wall_gmres = total_wall_gmres + WALL_STOP_TIME-WALL_START_TIME\r\n\r\n write(*,*) 'Solving with gauss started'\r\n CALL CPU_TIME ( cpu_time_begin )\r\n WALL_START_TIME = DCLOCK()\r\n\r\n CALL compute_gauss(gauss_matrix, n)\r\n\r\n WALL_STOP_TIME = DCLOCK()\r\n CALL CPU_TIME ( cpu_time_end )\r\n\r\n write(*, *) 'GAUSS completed with following statistics:'\r\n write(*,*) 'cpu time(s) ' , cpu_time_end - cpu_time_begin\r\n write(*,*) 'wall elapsed time(s) ', WALL_STOP_TIME-WALL_START_TIME\r\n write(*,*)\r\n total_cpu_gauss = total_cpu_gauss + cpu_time_end - cpu_time_begin\r\n total_wall_gauss = total_wall_gauss + WALL_STOP_TIME-WALL_START_TIME\r\n\r\n DEALLOCATE(random_matrix)\r\n DEALLOCATE(random_sol)\r\n DEALLOCATE(gauss_matrix, gmres_matrix, gmres_sol)\r\n\r\n\r\n end do\r\n\r\n if (num_iterations >= 1) then\r\n\r\n total_cpu_gauss = total_cpu_gauss/real(num_iterations)\r\n total_cpu_gmres = total_cpu_gmres/real(num_iterations)\r\n total_wall_gauss = total_wall_gauss/ dble(num_iterations)\r\n total_wall_gmres = total_wall_gmres/ dble(num_iterations)\r\n\r\n write(*,*) '---------- Average Summary -------------'\r\n write(*, *) 'GMRES completed with following statistics:'\r\n write(*,*) 'avg cpu time(s) ' , total_cpu_gmres\r\n write(*,*) 'avg wall elapsed time(s) ', total_wall_gmres\r\n write(*,*)\r\n write(*, *) 'GAUSS completed with following statistics:'\r\n write(*,*) 'avg cpu time(s) ' , total_cpu_gauss\r\n write(*,*) 'avg wall elapsed time(s) ', total_wall_gauss\r\n write(*,*)\r\n\r\n\r\n end if\r\n\r\n\r\n\r\n\r\ncontains\r\n subroutine compute_gmres(A, b, N)\r\n\r\n COMPLEX,DIMENSION(:,:):: A\r\n COMPLEX, DIMENSION(:):: b\r\n INTEGER::N\r\n integer :: lwork\r\n integer :: revcom, colx, coly, colz, nbscal\r\n integer :: irc(5), icntl(8), info(3)\r\n TYPE(GMRESVAR):: gmres_env\r\n integer :: matvec, precondLeft, precondRight, dotProd\r\n parameter (matvec=1, precondLeft=2, precondRight=3, dotProd=4)\r\n complex, dimension(:), allocatable :: work\r\n real :: cntl(5), rinfo(2)\r\n complex :: ONE, ZZERO\r\n INTEGER:: restartParam, maxIterations\r\n real:: TOL_GMRES\r\n\r\n restartParam = 20\r\n maxIterations = 100\r\n TOL_GMRES = 5.E-07\r\n\r\n lwork = (restartParam+10)**2 + (restartParam+10)*(N+5) + 5*N + 1\r\n ALLOCATE(work(lwork))\r\n ONE = CMPLX(1., 0.)\r\n ZZERO = CMPLX(0., 0.)\r\n\r\n\r\n !******************************************************\r\n !* Initialize the control parameters to default value\r\n !******************************************************\r\n\r\n call init_cgmres(icntl,cntl, gmres_env)\r\n\r\n !************************\r\n !c Tune some parameters\r\n !************************\r\n\r\n ! Save the convergence history on standard output\r\n !icntl(3) = 30\r\n icntl(2) = 0\r\n ! Maximum number of iterations\r\n icntl(7) = maxIterations\r\n\r\n ! Tolerance\r\n cntl(1) = TOL_GMRES\r\n\r\n ! preconditioner location\r\n icntl(4) = 0\r\n ! orthogonalization scheme\r\n icntl(5)=0\r\n ! initial guess\r\n icntl(6) = 0\r\n ! residual calculation strategy at restart\r\n icntl(8) = 1\r\n !* Initialise the right hand side\r\n\r\n work = CMPLX(0., 0.)\r\n\r\n work(1:N) = ONE/2.0\r\n\r\n DO I=1,N\r\n\r\n work(N+I) = b(i)\r\n\r\n END DO\r\n\r\n DO\r\n\r\n call drive_cgmres(N,N,restartParam,lwork,work, &\r\n irc,icntl,cntl,info,rinfo, gmres_env)\r\n revcom = irc(1)\r\n colx = irc(2)\r\n coly = irc(3)\r\n colz = irc(4)\r\n nbscal = irc(5)\r\n\r\n if (revcom == matvec) then\r\n ! perform the matrix vector product\r\n ! work(colz) <-- A * work(colx)\r\n call cgemv('N',N,N,ONE,A,N,work(colx),1, &\r\n ZZERO,work(colz),1)\r\n\r\n else if (revcom == precondLeft) then\r\n ! perform the left preconditioning\r\n ! work(colz) <-- M^{-1} * work(colx)\r\n call ccopy(N,work(colx),1,work(colz),1)\r\n call ctrsm('L','L','N','N',N,1,ONE,A,N,work(colz),N)\r\n\r\n else if (revcom == precondRight) then\r\n ! perform the right preconditioning\r\n call ccopy(N,work(colx),1,work(colz),1)\r\n call ctrsm('L','U','N','N',N,1,ONE,A,N,work(colz),N)\r\n\r\n else if (revcom == dotProd) then\r\n ! perform the scalar product\r\n ! work(colz) <-- work(colx) work(coly)\r\n\r\n call cgemv('C',N,nbscal,ONE,work(colx),N, &\r\n work(coly),1,ZZERO,work(colz),1)\r\n\r\n ELSE\r\n exit\r\n endif\r\n\r\n END DO\r\n\r\n end subroutine compute_gmres\r\n\r\n subroutine compute_gauss(A, N)\r\n integer:: n\r\n COMPLEX,DIMENSION(:,:):: A\r\n CALL GAUSSZ(A,N,N,N)\r\n end subroutine compute_gauss\r\n\r\n\r\n\r\n\r\n\r\nend program gmresvsgauss\r\n", "meta": {"hexsha": "2c66a83cbd2655b37cf16b6d34484e672ee9821a", "size": 7610, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/NemohImproved/Nemoh/Verification/gmresVSgauss/gmresvsgauss.f90", "max_stars_repo_name": "NREL/OpenWARP", "max_stars_repo_head_hexsha": "ca49c4cbde17e0cead69bd9e55a81d5c0fafe4df", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2015-06-22T07:35:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-23T05:10:09.000Z", "max_issues_repo_path": "source/NemohImproved/Nemoh/Verification/gmresVSgauss/gmresvsgauss.f90", "max_issues_repo_name": "rhydar/Test", "max_issues_repo_head_hexsha": "32dd54af2c3657d0c49177395d5b1c1f7bd8e127", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2015-07-30T20:01:35.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-28T17:29:18.000Z", "max_forks_repo_path": "source/NemohImproved/Nemoh/Verification/gmresVSgauss/gmresvsgauss.f90", "max_forks_repo_name": "rhydar/Test", "max_forks_repo_head_hexsha": "32dd54af2c3657d0c49177395d5b1c1f7bd8e127", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2016-04-01T07:45:27.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-06T08:33:33.000Z", "avg_line_length": 30.3187250996, "max_line_length": 92, "alphanum_fraction": 0.5333771353, "num_tokens": 2083, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127678225575, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6567274339146942}} {"text": "!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 1998 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Spherepack *\n! * *\n! * A Package of Fortran Subroutines and Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams and Paul Swarztrauber *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\n! This file contains code and documentation for subroutines\n! vhses and vhsesi\n!\nsubmodule(vector_synthesis_routines) vector_synthesis_regular_grid_saved\n\ncontains\n\n ! Purpose:\n !\n ! subroutine vhses(nlat, nlon, ityp, nt, v, w, idvw, jdvw, br, bi, cr, ci, &\n ! mdab, ndab, wvhses, ierror)\n !\n ! subroutine vhses performs the vector spherical harmonic synthesis\n ! of the arrays br, bi, cr, and ci and stores the result in the\n ! arrays v and w. v(i, j) and w(i, j) are the colatitudinal\n ! (measured from the north pole) and east longitudinal components\n ! respectively, located at colatitude theta(i) = (i-1)*pi/(nlat-1)\n ! and longitude phi(j) = (j-1)*2*pi/nlon. the spectral\n ! representation of (v, w) is given below at output parameters v, w.\n !\n ! input parameters\n !\n ! nlat the number of colatitudes on the full sphere including the\n ! poles. for example, nlat = 37 for a five degree grid.\n ! nlat determines the grid increment in colatitude as\n ! pi/(nlat-1). if nlat is odd the equator is located at\n ! grid point i=(nlat + 1)/2. if nlat is even the equator is\n ! located half way between points i=nlat/2 and i=nlat/2+1.\n ! nlat must be at least 3. note: on the half sphere, the\n ! number of grid points in the colatitudinal direction is\n ! nlat/2 if nlat is even or (nlat + 1)/2 if nlat is odd.\n !\n ! nlon the number of distinct londitude points. nlon determines\n ! the grid increment in longitude as 2*pi/nlon. for example\n ! nlon = 72 for a five degree grid. nlon must be greater\n ! than zero. the axisymmetric case corresponds to nlon=1.\n ! the efficiency of the computation is improved when nlon\n ! is a product of small prime numbers.\n !\n ! ityp = 0 no symmetries exist about the equator. the synthesis\n ! is performed on the entire sphere. i.e. on the\n ! arrays v(i, j), w(i, j) for i=1, ..., nlat and\n ! j=1, ..., nlon.\n !\n ! = 1 no symmetries exist about the equator. the synthesis\n ! is performed on the entire sphere. i.e. on the\n ! arrays v(i, j), w(i, j) for i=1, ..., nlat and\n ! j=1, ..., nlon. the curl of (v, w) is zero. that is, \n ! (d/dtheta (sin(theta) w) - dv/dphi)/sin(theta) = 0.\n ! the coefficients cr and ci are zero.\n !\n ! = 2 no symmetries exist about the equator. the synthesis\n ! is performed on the entire sphere. i.e. on the\n ! arrays v(i, j), w(i, j) for i=1, ..., nlat and\n ! j=1, ..., nlon. the divergence of (v, w) is zero. i.e., \n ! (d/dtheta (sin(theta) v) + dw/dphi)/sin(theta) = 0.\n ! the coefficients br and bi are zero.\n !\n ! = 3 v is symmetric and w is antisymmetric about the\n ! equator. the synthesis is performed on the northern\n ! hemisphere only. i.e., if nlat is odd the synthesis\n ! is performed on the arrays v(i, j), w(i, j) for\n ! i=1, ..., (nlat + 1)/2 and j=1, ..., nlon. if nlat is\n ! even the synthesis is performed on the the arrays\n ! v(i, j), w(i, j) for i=1, ..., nlat/2 and j=1, ..., nlon.\n !\n ! = 4 v is symmetric and w is antisymmetric about the\n ! equator. the synthesis is performed on the northern\n ! hemisphere only. i.e., if nlat is odd the synthesis\n ! is performed on the arrays v(i, j), w(i, j) for\n ! i=1, ..., (nlat + 1)/2 and j=1, ..., nlon. if nlat is\n ! even the synthesis is performed on the the arrays\n ! v(i, j), w(i, j) for i=1, ..., nlat/2 and j=1, ..., nlon.\n ! the curl of (v, w) is zero. that is, \n ! (d/dtheta (sin(theta) w) - dv/dphi)/sin(theta) = 0.\n ! the coefficients cr and ci are zero.\n !\n ! = 5 v is symmetric and w is antisymmetric about the\n ! equator. the synthesis is performed on the northern\n ! hemisphere only. i.e., if nlat is odd the synthesis\n ! is performed on the arrays v(i, j), w(i, j) for\n ! i=1, ..., (nlat + 1)/2 and j=1, ..., nlon. if nlat is\n ! even the synthesis is performed on the the arrays\n ! v(i, j), w(i, j) for i=1, ..., nlat/2 and j=1, ..., nlon.\n ! the divergence of (v, w) is zero. i.e., \n ! (d/dtheta (sin(theta) v) + dw/dphi)/sin(theta) = 0.\n ! the coefficients br and bi are zero.\n !\n ! = 6 v is antisymmetric and w is symmetric about the\n ! equator. the synthesis is performed on the northern\n ! hemisphere only. i.e., if nlat is odd the synthesis\n ! is performed on the arrays v(i, j), w(i, j) for\n ! i=1, ..., (nlat + 1)/2 and j=1, ..., nlon. if nlat is\n ! even the synthesis is performed on the the arrays\n ! v(i, j), w(i, j) for i=1, ..., nlat/2 and j=1, ..., nlon.\n !\n ! = 7 v is antisymmetric and w is symmetric about the\n ! equator. the synthesis is performed on the northern\n ! hemisphere only. i.e., if nlat is odd the synthesis\n ! is performed on the arrays v(i, j), w(i, j) for\n ! i=1, ..., (nlat + 1)/2 and j=1, ..., nlon. if nlat is\n ! even the synthesis is performed on the the arrays\n ! v(i, j), w(i, j) for i=1, ..., nlat/2 and j=1, ..., nlon.\n ! the curl of (v, w) is zero. that is, \n ! (d/dtheta (sin(theta) w) - dv/dphi)/sin(theta) = 0.\n ! the coefficients cr and ci are zero.\n !\n ! = 8 v is antisymmetric and w is symmetric about the\n ! equator. the synthesis is performed on the northern\n ! hemisphere only. i.e., if nlat is odd the synthesis\n ! is performed on the arrays v(i, j), w(i, j) for\n ! i=1, ..., (nlat + 1)/2 and j=1, ..., nlon. if nlat is\n ! even the synthesis is performed on the the arrays\n ! v(i, j), w(i, j) for i=1, ..., nlat/2 and j=1, ..., nlon.\n ! the divergence of (v, w) is zero. i.e., \n ! (d/dtheta (sin(theta) v) + dw/dphi)/sin(theta) = 0.\n ! the coefficients br and bi are zero.\n !\n !\n ! nt the number of syntheses. in the program that calls vhses, \n ! the arrays v, w, br, bi, cr, and ci can be three dimensional\n ! in which case multiple syntheses will be performed.\n ! the third index is the synthesis index which assumes the\n ! values k=1, ..., nt. for a single synthesis set nt=1. the\n ! discription of the remaining parameters is simplified\n ! by assuming that nt=1 or that all the arrays are two\n ! dimensional.\n !\n ! idvw the first dimension of the arrays v, w as it appears in\n ! the program that calls vhaes. if ityp <= 2 then idvw\n ! must be at least nlat. if ityp > 2 and nlat is\n ! even then idvw must be at least nlat/2. if ityp > 2\n ! and nlat is odd then idvw must be at least (nlat + 1)/2.\n !\n ! jdvw the second dimension of the arrays v, w as it appears in\n ! the program that calls vhses. jdvw must be at least nlon.\n !\n ! br, bi two or three dimensional arrays (see input parameter nt)\n ! cr, ci that contain the vector spherical harmonic coefficients\n ! in the spectral representation of v(i, j) and w(i, j) given\n ! below at the discription of output parameters v and w.\n !\n ! mdab the first dimension of the arrays br, bi, cr, and ci as it\n ! appears in the program that calls vhses. mdab must be at\n ! least min(nlat, nlon/2) if nlon is even or at least\n ! min(nlat, (nlon + 1)/2) if nlon is odd.\n !\n ! ndab the second dimension of the arrays br, bi, cr, and ci as it\n ! appears in the program that calls vhses. ndab must be at\n ! least nlat.\n !\n ! wvhses an array which must be initialized by subroutine vhsesi.\n ! once initialized, wvhses can be used repeatedly by vhses\n ! as long as nlon and nlat remain unchanged. wvhses must\n ! not be altered between calls of vhses.\n !\n ! lvhses the dimension of the array wvhses as it appears in the\n ! program that calls vhses. define\n !\n ! l1 = min(nlat, nlon/2) if nlon is even or\n ! l1 = min(nlat, (nlon + 1)/2) if nlon is odd\n !\n ! and\n !\n ! l2 = nlat/2 if nlat is even or\n ! l2 = (nlat + 1)/2 if nlat is odd\n !\n ! then lvhses must be at least\n !\n ! l1*l2*(2*nlat-l1+1)+nlon+15\n !\n ! output parameters\n !\n ! v, w two or three dimensional arrays (see input parameter nt)\n ! in which the synthesis is stored. v is the colatitudinal\n ! component and w is the east longitudinal component.\n ! v(i, j), w(i, j) contain the components at colatitude\n ! theta(i) = (i-1)*pi/(nlat-1) and longitude phi(j) =\n ! (j-1)*2*pi/nlon. the index ranges are defined above at\n ! the input parameter ityp. v and w are computed from the\n ! formulas given below\n !\n !\n ! define\n !\n ! 1. theta is colatitude and phi is east longitude\n !\n ! 2. the normalized associated legendre funnctions\n !\n ! pbar(m, n, theta) = sqrt((2*n+1)*factorial(n-m)\n ! /(2*factorial(n+m)))*sin(theta)**m/(2**n*\n ! factorial(n)) times the (n+m)th derivative\n ! of (x**2-1)**n with respect to x=cos(theta)\n !\n ! 3. vbar(m, n, theta) = the derivative of pbar(m, n, theta) with\n ! respect to theta divided by the square\n ! root of n(n+1).\n !\n ! vbar(m, n, theta) is more easily computed in the form\n !\n ! vbar(m, n, theta) = (sqrt((n+m)*(n-m+1))*pbar(m-1, n, theta)\n ! -sqrt((n-m)*(n+m+1))*pbar(m+1, n, theta))/(2*sqrt(n*(n+1)))\n !\n ! 4. wbar(m, n, theta) = m/(sin(theta))*pbar(m, n, theta) divided\n ! by the square root of n(n+1).\n !\n ! wbar(m, n, theta) is more easily computed in the form\n !\n ! wbar(m, n, theta) = sqrt((2n+1)/(2n-1))*(sqrt((n+m)*(n+m-1))\n ! *pbar(m-1, n-1, theta)+sqrt((n-m)*(n-m-1))*pbar(m+1, n-1, theta))\n ! /(2*sqrt(n*(n+1)))\n !\n !\n ! the colatitudnal dependence of the normalized surface vector\n ! spherical harmonics are defined by\n !\n ! 5. bbar(m, n, theta) = (vbar(m, n, theta), i*wbar(m, n, theta))\n !\n ! 6. cbar(m, n, theta) = (i*wbar(m, n, theta), -vbar(m, n, theta))\n !\n !\n ! the coordinate to index mappings\n !\n ! 7. theta(i) = (i-1)*pi/(nlat-1) and phi(j) = (j-1)*2*pi/nlon\n !\n !\n ! the maximum (plus one) longitudinal wave number\n !\n ! 8. mmax = min(nlat, nlon/2) if nlon is even or\n ! mmax = min(nlat, (nlon + 1)/2) if nlon is odd.\n !\n ! if we further define the output vector as\n !\n ! 9. h(i, j) = (v(i, j), w(i, j))\n !\n ! and the complex coefficients\n !\n ! 10. b(m, n) = cmplx(br(m+1, n+1), bi(m+1, n+1))\n !\n ! 11. c(m, n) = cmplx(cr(m+1, n+1), ci(m+1, n+1))\n !\n !\n ! then for i=1, ..., nlat and j=1, ..., nlon\n !\n ! the expansion for real h(i, j) takes the form\n !\n ! h(i, j) = the sum from n=1 to n=nlat-1 of the real part of\n !\n ! 0.5*(b(0, n)*bbar(0, n, theta(i))+c(0, n)*cbar(0, n, theta(i)))\n !\n ! plus the sum from m=1 to m=mmax-1 of the sum from n=m to\n ! n=nlat-1 of the real part of\n !\n ! b(m, n)*bbar(m, n, theta(i))*exp(i*m*phi(j))\n ! +c(m, n)*cbar(m, n, theta(i))*exp(i*m*phi(j))\n !\n ! *************************************************************\n !\n ! in terms of real variables this expansion takes the form\n !\n ! for i=1, ..., nlat and j=1, ..., nlon\n !\n ! v(i, j) = the sum from n=1 to n=nlat-1 of\n !\n ! 0.5*br(1, n+1)*vbar(0, n, theta(i))\n !\n ! plus the sum from m=1 to m=mmax-1 of the sum from n=m to\n ! n=nlat-1 of the real part of\n !\n ! (br(m+1, n+1)*vbar(m, n, theta(i))-ci(m+1, n+1)*wbar(m, n, theta(i)))\n ! *cos(m*phi(j))\n ! -(bi(m+1, n+1)*vbar(m, n, theta(i))+cr(m+1, n+1)*wbar(m, n, theta(i)))\n ! *sin(m*phi(j))\n !\n ! and for i=1, ..., nlat and j=1, ..., nlon\n !\n ! w(i, j) = the sum from n=1 to n=nlat-1 of\n !\n ! -0.5*cr(1, n+1)*vbar(0, n, theta(i))\n !\n ! plus the sum from m=1 to m=mmax-1 of the sum from n=m to\n ! n=nlat-1 of the real part of\n !\n ! -(cr(m+1, n+1)*vbar(m, n, theta(i))+bi(m+1, n+1)*wbar(m, n, theta(i)))\n ! *cos(m*phi(j))\n ! +(ci(m+1, n+1)*vbar(m, n, theta(i))-br(m+1, n+1)*wbar(m, n, theta(i)))\n ! *sin(m*phi(j))\n !\n !\n ! br(m+1, nlat), bi(m+1, nlat), cr(m+1, nlat), and ci(m+1, nlat) are\n ! assumed zero for m even.\n !\n !\n ! ierror = 0 no errors\n ! = 1 error in the specification of nlat\n ! = 2 error in the specification of nlon\n ! = 3 error in the specification of ityp\n ! = 4 error in the specification of nt\n ! = 5 error in the specification of idvw\n ! = 6 error in the specification of jdvw\n ! = 7 error in the specification of mdab\n ! = 8 error in the specification of ndab\n ! = 9 error in the specification of lvhses\n !\n module subroutine vhses(nlat, nlon, ityp, nt, v, w, idvw, jdvw, br, bi, cr, ci, &\n mdab, ndab, wvhses, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n integer(ip), intent(in) :: ityp\n integer(ip), intent(in) :: nt\n real(wp), intent(out) :: v(idvw, jdvw, nt)\n real(wp), intent(out) :: w(idvw, jdvw, nt)\n integer(ip), intent(in) :: idvw\n integer(ip), intent(in) :: jdvw\n real(wp), intent(in) :: br(mdab, ndab, nt)\n real(wp), intent(in) :: bi(mdab, ndab, nt)\n real(wp), intent(in) :: cr(mdab, ndab, nt)\n real(wp), intent(in) :: ci(mdab, ndab, nt)\n integer(ip), intent(in) :: mdab\n integer(ip), intent(in) :: ndab\n real(wp), intent(in) :: wvhses(:)\n integer(ip), intent(out) :: ierror\n\n ! Local variables\n integer(ip) :: idv, idz, imid, ist, lnl, lzimn, mmax\n integer(ip) :: lwork, workspace_indices(6)\n integer(ip) :: required_wavetable_size\n type(VectorSynthesisUtility) :: util\n\n required_wavetable_size = util%get_lvhsgc(nlat, nlon)\n\n call util%check_vector_transform_inputs(ityp, idvw, jdvw, &\n mdab, ndab, nlat, nlon, nt, required_wavetable_size, &\n wvhses, ierror)\n\n ! Check error flag\n if (ierror /= 0) return\n\n imid = (nlat + 1)/2\n mmax = min(nlat, (nlon + 1)/2)\n idz = (mmax*(2*nlat-mmax+1))/2\n lzimn = idz*imid\n\n select case (ityp)\n case (0:2)\n idv = nlat\n ist = imid\n case default\n idv = imid\n ist = 0\n end select\n\n ! Set required workspace size\n lnl = nt * idv * nlon\n lwork = (2 * lnl) + (idv * nlon)\n\n block\n real(wp) :: work(lwork)\n\n ! Set workspace indices\n workspace_indices = get_vhses_workspace_indices(ist, lnl, lzimn)\n\n associate (&\n iw1 => workspace_indices(1), &\n iw2 => workspace_indices(2), &\n iw3 => workspace_indices(3), &\n iw4 => workspace_indices(4), &\n jw1 => workspace_indices(5), &\n jw2 => workspace_indices(6) &\n )\n call vhses_lower_utility_routine(nlat, nlon, ityp, nt, imid, idvw, &\n jdvw, v, w, mdab, ndab, br, bi, cr, ci, idv, work, work(iw1:), &\n work(iw2:), work(iw3:), work(iw4:), idz, wvhses, wvhses(jw1:), &\n wvhses(jw2:))\n end associate\n end block\n\n end subroutine vhses\n\n ! Purpose:\n !\n ! subroutine vhsesi(nlat, nlon, wvhses, ierror)\n !\n ! subroutine vhsesi initializes the array wvhses which can then be\n ! used repeatedly by subroutine vhses until nlat or nlon is changed.\n !\n ! input parameters\n !\n ! nlat the number of colatitudes on the full sphere including the\n ! poles. for example, nlat = 37 for a five degree grid.\n ! nlat determines the grid increment in colatitude as\n ! pi/(nlat-1). if nlat is odd the equator is located at\n ! grid point i=(nlat + 1)/2. if nlat is even the equator is\n ! located half way between points i=nlat/2 and i=nlat/2+1.\n ! nlat must be at least 3. note: on the half sphere, the\n ! number of grid points in the colatitudinal direction is\n ! nlat/2 if nlat is even or (nlat + 1)/2 if nlat is odd.\n !\n ! nlon the number of distinct londitude points. nlon determines\n ! the grid increment in longitude as 2*pi/nlon. for example\n ! nlon = 72 for a five degree grid. nlon must be greater\n ! than zero. the axisymmetric case corresponds to nlon=1.\n ! the efficiency of the computation is improved when nlon\n ! is a product of small prime numbers.\n !\n ! lvhses the dimension of the array wvhses as it appears in the\n ! program that calls vhses. define\n !\n ! l1 = min(nlat, nlon/2) if nlon is even or\n ! l1 = min(nlat, (nlon + 1)/2) if nlon is odd\n !\n ! and\n !\n ! l2 = nlat/2 if nlat is even or\n ! l2 = (nlat + 1)/2 if nlat is odd\n !\n ! then lvhses must be at least\n !\n ! l1*l2*(2*nlat-l1+1)+nlon+15\n !\n ! output parameters\n !\n ! wvhses an array which is initialized for use by subroutine vhses.\n ! once initialized, wvhses can be used repeatedly by vhses\n ! as long as nlat or nlon remain unchanged. wvhses must not\n ! be altered between calls of vhses.\n !\n !\n ! ierror = 0 no errors\n ! = 1 error in the specification of nlat\n ! = 2 error in the specification of nlon\n ! = 3 error in the specification of lvhses\n !\n module subroutine vhsesi(nlat, nlon, wvhses, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n real(wp), intent(out) :: wvhses(:)\n integer(ip), intent(out) :: ierror\n\n ! Local variables\n integer(ip) :: imid, labc, lzimn, mmax\n integer(ip) :: lwork, ldwork\n integer(ip) :: workspace_indices(4)\n type(SpherepackUtility) :: util\n\n associate (lvhses => size(wvhses))\n\n mmax = min(nlat, (nlon + 1)/2)\n imid = (nlat + 1)/2\n lzimn = (imid*mmax*(2*nlat-mmax+1))/2\n labc = 3*(max(mmax-2, 0)*(2*nlat-mmax-1))/2\n\n ! Check calling arguments\n if (nlat < 3) then\n ierror = 1\n else if (nlon < 1) then\n ierror = 2\n else if (lvhses < 2*lzimn+nlon+15) then\n ierror = 3\n else\n ierror = 0\n end if\n\n ! Check error flag\n if (ierror /= 0) return\n\n ! Set required workspace sizes\n lwork = (5 * nlat * imid) + labc\n ldwork = 2 * (nlat + 1)\n\n block\n real(wp) :: work(lwork), dwork(ldwork)\n\n ! Set workspace indices\n workspace_indices = get_vhsesi_workspace_indices(nlat, imid, mmax, lzimn)\n\n associate (&\n iw1 => workspace_indices(1), &\n idz => workspace_indices(2), &\n jw1 => workspace_indices(3), &\n jw2 => workspace_indices(4) &\n )\n call vhsesi_lower_utility_routine(nlat, nlon, imid, wvhses, &\n wvhses(jw1:), idz, work, work(iw1:), dwork)\n\n call util%hfft%initialize(nlon, wvhses(jw2:))\n end associate\n end block\n end associate\n\n end subroutine vhsesi\n\n pure function get_vhses_workspace_indices(ist, lnl, lzimn) &\n result (return_value)\n\n ! Dummy arguments\n integer(ip), intent(in) :: ist\n integer(ip), intent(in) :: lnl\n integer(ip), intent(in) :: lzimn\n integer(ip) :: return_value(6)\n\n associate (i => return_value)\n i(1) = ist+1\n i(2) = lnl+1\n i(3) = i(2)+ist\n i(4) = i(2)+lnl\n i(5) = lzimn+1\n i(6) = i(5)+lzimn\n end associate\n\n end function get_vhses_workspace_indices\n\n subroutine vhses_lower_utility_routine(nlat, nlon, ityp, nt, imid, idvw, jdvw, v, w, mdab, &\n ndab, br, bi, cr, ci, idv, ve, vo, we, wo, work, idz, vb, wb, wrfft)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n integer(ip), intent(in) :: ityp\n integer(ip), intent(in) :: nt\n integer(ip), intent(in) :: imid\n integer(ip), intent(in) :: idvw\n integer(ip), intent(in) :: jdvw\n real(wp), intent(out) :: v(idvw, jdvw, nt)\n real(wp), intent(out) :: w(idvw, jdvw, nt)\n integer(ip), intent(in) :: mdab\n integer(ip), intent(in) :: ndab\n real(wp), intent(in) :: br(mdab, ndab, nt)\n real(wp), intent(in) :: bi(mdab, ndab, nt)\n real(wp), intent(in) :: cr(mdab, ndab, nt)\n real(wp), intent(in) :: ci(mdab, ndab, nt)\n integer(ip), intent(in) :: idv\n real(wp), intent(out) :: ve(idv, nlon, nt)\n real(wp), intent(out) :: vo(idv, nlon, nt)\n real(wp), intent(out) :: we(idv, nlon, nt)\n real(wp), intent(out) :: wo(idv, nlon, nt)\n real(wp), intent(out) :: work(*)\n integer(ip), intent(in) :: idz\n real(wp), intent(in) :: vb(imid, *)\n real(wp), intent(in) :: wb(imid, *)\n real(wp), intent(in) :: wrfft(*)\n\n ! Local variables\n integer(ip) :: i, imm1, j, k, m, mb, mmax, mn\n integer(ip) :: mp1, mp2, odd_stride, even_stride, np1\n type(VectorSynthesisUtility) :: util\n\n call util%synthesis_setup(even_stride, imid, imm1, mmax, nlat, &\n odd_stride, ve, vo, we, wo)\n\n vector_symmetry_cases: select case (ityp)\n case (0)\n\n ! case ityp=0 no symmetries\n\n ! case m = 0\n do k=1, nt\n do np1=2, even_stride, 2\n ve(:imid, 1, k) = ve(:imid, 1, k) + br(1, np1, k) * vb(:imid, np1)\n we(:imid, 1, k) = we(:imid, 1, k) - cr(1, np1, k) * vb(:imid, np1)\n end do\n end do\n\n do k=1, nt\n do np1=3, odd_stride, 2\n vo(:imm1, 1, k) = vo(:imm1, 1, k) + br(1, np1, k) * vb(:imm1, np1)\n wo(:imm1, 1, k) = wo(:imm1, 1, k) - cr(1, np1, k) * vb(:imm1, np1)\n end do\n end do\n\n ! case m = 1 through nlat-1\n if (2 <= mmax) then\n do mp1=2, mmax\n m = mp1-1\n mb = m * (nlat-1) - (m * (m - 1))/2\n mp2 = mp1+1\n if (mp1 <= odd_stride) then\n do k=1, nt\n do np1=mp1, odd_stride, 2\n mn = mb+np1\n\n vo(:imm1, 2*mp1-2, k) = vo(:imm1, 2*mp1-2, k) + br(mp1, np1, k) * vb(:imm1, mn)\n ve(:imm1, 2*mp1-2, k) = ve(:imm1, 2*mp1-2, k) - ci(mp1, np1, k) * wb(:imm1, mn)\n vo(:imm1, 2*mp1-1, k) = vo(:imm1, 2*mp1-1, k) + bi(mp1, np1, k) * vb(:imm1, mn)\n ve(:imm1, 2*mp1-1, k) = ve(:imm1, 2*mp1-1, k) + cr(mp1, np1, k) * wb(:imm1, mn)\n wo(:imm1, 2*mp1-2, k) = wo(:imm1, 2*mp1-2, k) - cr(mp1, np1, k) * vb(:imm1, mn)\n we(:imm1, 2*mp1-2, k) = we(:imm1, 2*mp1-2, k) - bi(mp1, np1, k) * wb(:imm1, mn)\n wo(:imm1, 2*mp1-1, k) = wo(:imm1, 2*mp1-1, k) - ci(mp1, np1, k) * vb(:imm1, mn)\n we(:imm1, 2*mp1-1, k) = we(:imm1, 2*mp1-1, k) + br(mp1, np1, k) * wb(:imm1, mn)\n\n if (mod(nlat, 2) /= 0) then\n ve(imid, 2*mp1-2, k) = ve(imid, 2*mp1-2, k) &\n -ci(mp1, np1, k)*wb(imid, mn)\n ve(imid, 2*mp1-1, k) = ve(imid, 2*mp1-1, k) &\n +cr(mp1, np1, k)*wb(imid, mn)\n we(imid, 2*mp1-2, k) = we(imid, 2*mp1-2, k) &\n -bi(mp1, np1, k)*wb(imid, mn)\n we(imid, 2*mp1-1, k) = we(imid, 2*mp1-1, k) &\n +br(mp1, np1, k)*wb(imid, mn)\n end if\n end do\n end do\n end if\n\n if (mp2 <= even_stride) then\n do k=1, nt\n do np1=mp2, even_stride, 2\n mn = mb+np1\n ve(:imm1, 2*mp1-2, k) = ve(:imm1, 2*mp1-2, k) + br(mp1, np1, k) * vb(:imm1, mn)\n vo(:imm1, 2*mp1-2, k) = vo(:imm1, 2*mp1-2, k) - ci(mp1, np1, k) * wb(:imm1, mn)\n ve(:imm1, 2*mp1-1, k) = ve(:imm1, 2*mp1-1, k) + bi(mp1, np1, k) * vb(:imm1, mn)\n vo(:imm1, 2*mp1-1, k) = vo(:imm1, 2*mp1-1, k) + cr(mp1, np1, k) * wb(:imm1, mn)\n we(:imm1, 2*mp1-2, k) = we(:imm1, 2*mp1-2, k) - cr(mp1, np1, k) * vb(:imm1, mn)\n wo(:imm1, 2*mp1-2, k) = wo(:imm1, 2*mp1-2, k) - bi(mp1, np1, k) * wb(:imm1, mn)\n we(:imm1, 2*mp1-1, k) = we(:imm1, 2*mp1-1, k) - ci(mp1, np1, k) * vb(:imm1, mn)\n wo(:imm1, 2*mp1-1, k) = wo(:imm1, 2*mp1-1, k) + br(mp1, np1, k) * wb(:imm1, mn)\n if (mod(nlat, 2) /= 0) then\n ve(imid, 2*mp1-2, k) = ve(imid, 2*mp1-2, k) &\n + br(mp1, np1, k) * vb(imid, mn)\n ve(imid, 2*mp1-1, k) = ve(imid, 2*mp1-1, k) &\n + bi(mp1, np1, k) * vb(imid, mn)\n we(imid, 2*mp1-2, k) = we(imid, 2*mp1-2, k) &\n - cr(mp1, np1, k) * vb(imid, mn)\n we(imid, 2*mp1-1, k) = we(imid, 2*mp1-1, k) &\n - ci(mp1, np1, k) * vb(imid, mn)\n end if\n end do\n end do\n end if\n end do\n end if\n case (1)\n\n ! case ityp=1 no symmetries, cr and ci equal zero\n\n ! case m = 0\n do k=1, nt\n do np1=2, even_stride, 2\n do i=1, imid\n ve(i, 1, k)=ve(i, 1, k)+br(1, np1, k)*vb(i, np1)\n end do\n end do\n end do\n do k=1, nt\n do np1=3, odd_stride, 2\n do i=1, imm1\n vo(i, 1, k)=vo(i, 1, k)+br(1, np1, k)*vb(i, np1)\n end do\n end do\n end do\n\n ! case m = 1 through nlat-1\n if (2 <= mmax) then\n do mp1=2, mmax\n m = mp1-1\n mb = m*(nlat-1)-(m*(m-1))/2\n mp2 = mp1+1\n if (mp1 <= odd_stride) then\n do k=1, nt\n do np1=mp1, odd_stride, 2\n mn = mb+np1\n do i=1, imm1\n vo(i, 2*mp1-2, k) = vo(i, 2*mp1-2, k)+br(mp1, np1, k)*vb(i, mn)\n vo(i, 2*mp1-1, k) = vo(i, 2*mp1-1, k)+bi(mp1, np1, k)*vb(i, mn)\n we(i, 2*mp1-2, k) = we(i, 2*mp1-2, k)-bi(mp1, np1, k)*wb(i, mn)\n we(i, 2*mp1-1, k) = we(i, 2*mp1-1, k)+br(mp1, np1, k)*wb(i, mn)\n end do\n if (mod(nlat, 2) /= 0) then\n we(imid, 2*mp1-2, k) = we(imid, 2*mp1-2, k) &\n -bi(mp1, np1, k)*wb(imid, mn)\n we(imid, 2*mp1-1, k) = we(imid, 2*mp1-1, k) &\n +br(mp1, np1, k)*wb(imid, mn)\n end if\n end do\n end do\n end if\n\n if (mp2 <= even_stride) then\n do k=1, nt\n do np1=mp2, even_stride, 2\n mn = mb+np1\n do i=1, imm1\n ve(i, 2*mp1-2, k) = ve(i, 2*mp1-2, k)+br(mp1, np1, k)*vb(i, mn)\n ve(i, 2*mp1-1, k) = ve(i, 2*mp1-1, k)+bi(mp1, np1, k)*vb(i, mn)\n wo(i, 2*mp1-2, k) = wo(i, 2*mp1-2, k)-bi(mp1, np1, k)*wb(i, mn)\n wo(i, 2*mp1-1, k) = wo(i, 2*mp1-1, k)+br(mp1, np1, k)*wb(i, mn)\n end do\n if (mod(nlat, 2) /= 0) then\n ve(imid, 2*mp1-2, k) = ve(imid, 2*mp1-2, k) &\n +br(mp1, np1, k)*vb(imid, mn)\n ve(imid, 2*mp1-1, k) = ve(imid, 2*mp1-1, k) &\n +bi(mp1, np1, k)*vb(imid, mn)\n end if\n end do\n end do\n end if\n end do\n end if\n case (2)\n\n ! case ityp=2 no symmetries, br and bi are equal to zero\n\n ! case m = 0\n do k=1, nt\n do np1=2, even_stride, 2\n do i=1, imid\n we(i, 1, k)=we(i, 1, k)-cr(1, np1, k)*vb(i, np1)\n end do\n end do\n end do\n\n do k=1, nt\n do np1=3, odd_stride, 2\n do i=1, imm1\n wo(i, 1, k)=wo(i, 1, k)-cr(1, np1, k)*vb(i, np1)\n end do\n end do\n end do\n\n ! case m = 1 through nlat-1\n if (2 <= mmax) then\n do mp1=2, mmax\n m = mp1-1\n mb = m*(nlat-1)-(m*(m-1))/2\n mp2 = mp1+1\n if (mp1 <= odd_stride) then\n do k=1, nt\n do np1=mp1, odd_stride, 2\n mn = mb+np1\n do i=1, imm1\n ve(i, 2*mp1-2, k) = ve(i, 2*mp1-2, k)-ci(mp1, np1, k)*wb(i, mn)\n ve(i, 2*mp1-1, k) = ve(i, 2*mp1-1, k)+cr(mp1, np1, k)*wb(i, mn)\n wo(i, 2*mp1-2, k) = wo(i, 2*mp1-2, k)-cr(mp1, np1, k)*vb(i, mn)\n wo(i, 2*mp1-1, k) = wo(i, 2*mp1-1, k)-ci(mp1, np1, k)*vb(i, mn)\n end do\n\n if (mod(nlat, 2) /= 0) then\n ve(imid, 2*mp1-2, k) = ve(imid, 2*mp1-2, k) &\n -ci(mp1, np1, k)*wb(imid, mn)\n ve(imid, 2*mp1-1, k) = ve(imid, 2*mp1-1, k) &\n +cr(mp1, np1, k)*wb(imid, mn)\n end if\n end do\n end do\n end if\n\n if (mp2 <= even_stride) then\n do k=1, nt\n do np1=mp2, even_stride, 2\n mn = mb+np1\n do i=1, imm1\n vo(i, 2*mp1-2, k) = vo(i, 2*mp1-2, k)-ci(mp1, np1, k)*wb(i, mn)\n vo(i, 2*mp1-1, k) = vo(i, 2*mp1-1, k)+cr(mp1, np1, k)*wb(i, mn)\n we(i, 2*mp1-2, k) = we(i, 2*mp1-2, k)-cr(mp1, np1, k)*vb(i, mn)\n we(i, 2*mp1-1, k) = we(i, 2*mp1-1, k)-ci(mp1, np1, k)*vb(i, mn)\n end do\n if (mod(nlat, 2) /= 0) then\n we(imid, 2*mp1-2, k) = we(imid, 2*mp1-2, k) &\n -cr(mp1, np1, k)*vb(imid, mn)\n we(imid, 2*mp1-1, k) = we(imid, 2*mp1-1, k) &\n -ci(mp1, np1, k)*vb(imid, mn)\n end if\n end do\n end do\n end if\n end do\n end if\n case (3)\n !\n ! case ityp=3 v even, w odd\n !\n ! case m = 0\n !\n do k=1, nt\n do np1=2, even_stride, 2\n do i=1, imid\n ve(i, 1, k)=ve(i, 1, k)+br(1, np1, k)*vb(i, np1)\n end do\n end do\n end do\n\n do k=1, nt\n do np1=3, odd_stride, 2\n do i=1, imm1\n wo(i, 1, k)=wo(i, 1, k)-cr(1, np1, k)*vb(i, np1)\n end do\n end do\n end do\n !\n ! case m = 1 through nlat-1\n !\n if (2 <= mmax) then\n do mp1=2, mmax\n m = mp1-1\n mb = m*(nlat-1)-(m*(m-1))/2\n mp2 = mp1+1\n if (mp1 <= odd_stride) then\n do k=1, nt\n do np1=mp1, odd_stride, 2\n mn = mb+np1\n do i=1, imm1\n ve(i, 2*mp1-2, k) = ve(i, 2*mp1-2, k)-ci(mp1, np1, k)*wb(i, mn)\n ve(i, 2*mp1-1, k) = ve(i, 2*mp1-1, k)+cr(mp1, np1, k)*wb(i, mn)\n wo(i, 2*mp1-2, k) = wo(i, 2*mp1-2, k)-cr(mp1, np1, k)*vb(i, mn)\n wo(i, 2*mp1-1, k) = wo(i, 2*mp1-1, k)-ci(mp1, np1, k)*vb(i, mn)\n end do\n if (mod(nlat, 2) /= 0) then\n ve(imid, 2*mp1-2, k) = ve(imid, 2*mp1-2, k) &\n -ci(mp1, np1, k) * wb(imid, mn)\n ve(imid, 2*mp1-1, k) = ve(imid, 2*mp1-1, k) &\n +cr(mp1, np1, k) * wb(imid, mn)\n end if\n end do\n end do\n end if\n\n if (mp2 <= even_stride) then\n do k=1, nt\n do np1=mp2, even_stride, 2\n mn = mb+np1\n do i=1, imm1\n ve(i, 2*mp1-2, k) = ve(i, 2*mp1-2, k)+br(mp1, np1, k)*vb(i, mn)\n ve(i, 2*mp1-1, k) = ve(i, 2*mp1-1, k)+bi(mp1, np1, k)*vb(i, mn)\n wo(i, 2*mp1-2, k) = wo(i, 2*mp1-2, k)-bi(mp1, np1, k)*wb(i, mn)\n wo(i, 2*mp1-1, k) = wo(i, 2*mp1-1, k)+br(mp1, np1, k)*wb(i, mn)\n end do\n if (mod(nlat, 2) /= 0) then\n ve(imid, 2*mp1-2, k) = ve(imid, 2*mp1-2, k) &\n + br(mp1, np1, k) * vb(imid, mn)\n ve(imid, 2*mp1-1, k) = ve(imid, 2*mp1-1, k) &\n + bi(mp1, np1, k) * vb(imid, mn)\n end if\n end do\n end do\n end if\n end do\n end if\n case (4)\n !\n ! case ityp=4 v even, w odd, and both cr and ci equal zero\n !\n ! case m = 0\n !\n do k=1, nt\n do np1=2, even_stride, 2\n ve(:imid, 1, k) = ve(:imid, 1, k) &\n + br(1, np1, k) * vb(:imid, np1)\n end do\n end do\n !\n ! case m = 1 through nlat-1\n !\n if (2 <= mmax) then\n do mp1=2, mmax\n m = mp1-1\n mb = m*(nlat-1)-(m*(m-1))/2\n mp2 = mp1+1\n if (mp2 <= even_stride) then\n do k=1, nt\n do np1=mp2, even_stride, 2\n mn = mb+np1\n do i=1, imm1\n ve(i, 2*mp1-2, k) = ve(i, 2*mp1-2, k)+br(mp1, np1, k)*vb(i, mn)\n ve(i, 2*mp1-1, k) = ve(i, 2*mp1-1, k)+bi(mp1, np1, k)*vb(i, mn)\n wo(i, 2*mp1-2, k) = wo(i, 2*mp1-2, k)-bi(mp1, np1, k)*wb(i, mn)\n wo(i, 2*mp1-1, k) = wo(i, 2*mp1-1, k)+br(mp1, np1, k)*wb(i, mn)\n end do\n if (mod(nlat, 2) /= 0) then\n ve(imid, 2*mp1-2, k) = ve(imid, 2*mp1-2, k) &\n +br(mp1, np1, k)*vb(imid, mn)\n ve(imid, 2*mp1-1, k) = ve(imid, 2*mp1-1, k) &\n +bi(mp1, np1, k)*vb(imid, mn)\n end if\n end do\n end do\n end if\n end do\n end if\n case (5)\n !\n ! case ityp=5 v even, w odd, br and bi equal zero\n !\n ! case m = 0\n !\n do k=1, nt\n do np1=3, odd_stride, 2\n do i=1, imm1\n wo(i, 1, k)=wo(i, 1, k)-cr(1, np1, k)*vb(i, np1)\n end do\n end do\n end do\n !\n ! case m = 1 through nlat-1\n !\n if (2 <= mmax) then\n do mp1=2, mmax\n m = mp1-1\n mb = m*(nlat-1)-(m*(m-1))/2\n mp2 = mp1+1\n\n if (mp1 <= odd_stride) then\n do k=1, nt\n do np1=mp1, odd_stride, 2\n mn = mb+np1\n do i=1, imm1\n ve(i, 2*mp1-2, k) = ve(i, 2*mp1-2, k)-ci(mp1, np1, k)*wb(i, mn)\n ve(i, 2*mp1-1, k) = ve(i, 2*mp1-1, k)+cr(mp1, np1, k)*wb(i, mn)\n wo(i, 2*mp1-2, k) = wo(i, 2*mp1-2, k)-cr(mp1, np1, k)*vb(i, mn)\n wo(i, 2*mp1-1, k) = wo(i, 2*mp1-1, k)-ci(mp1, np1, k)*vb(i, mn)\n end do\n if (mod(nlat, 2) /= 0) then\n ve(imid, 2*mp1-2, k) = ve(imid, 2*mp1-2, k) &\n -ci(mp1, np1, k)*wb(imid, mn)\n ve(imid, 2*mp1-1, k) = ve(imid, 2*mp1-1, k) &\n +cr(mp1, np1, k)*wb(imid, mn)\n end if\n end do\n end do\n end if\n end do\n end if\n case (6)\n !\n ! case ityp=6 v odd , w even\n !\n ! case m = 0\n !\n do k=1, nt\n do np1=2, even_stride, 2\n do i=1, imid\n we(i, 1, k)=we(i, 1, k)-cr(1, np1, k)*vb(i, np1)\n end do\n end do\n end do\n\n do k=1, nt\n do np1=3, odd_stride, 2\n do i=1, imm1\n vo(i, 1, k)=vo(i, 1, k)+br(1, np1, k)*vb(i, np1)\n end do\n end do\n end do\n !\n ! case m = 1 through nlat-1\n !\n if (2 <= mmax) then\n do mp1=2, mmax\n m = mp1-1\n mb = m*(nlat-1)-(m*(m-1))/2\n mp2 = mp1+1\n if (mp1 <= odd_stride) then\n do k=1, nt\n do np1=mp1, odd_stride, 2\n mn = mb+np1\n do i=1, imm1\n vo(i, 2*mp1-2, k) = vo(i, 2*mp1-2, k)+br(mp1, np1, k)*vb(i, mn)\n vo(i, 2*mp1-1, k) = vo(i, 2*mp1-1, k)+bi(mp1, np1, k)*vb(i, mn)\n we(i, 2*mp1-2, k) = we(i, 2*mp1-2, k)-bi(mp1, np1, k)*wb(i, mn)\n we(i, 2*mp1-1, k) = we(i, 2*mp1-1, k)+br(mp1, np1, k)*wb(i, mn)\n end do\n if (mod(nlat, 2) /= 0) then\n we(imid, 2*mp1-2, k) = we(imid, 2*mp1-2, k) &\n -bi(mp1, np1, k)*wb(imid, mn)\n we(imid, 2*mp1-1, k) = we(imid, 2*mp1-1, k) &\n +br(mp1, np1, k)*wb(imid, mn)\n end if\n end do\n end do\n end if\n\n if (mp2 <= even_stride) then\n do k=1, nt\n do np1=mp2, even_stride, 2\n mn = mb+np1\n do i=1, imm1\n vo(i, 2*mp1-2, k) = vo(i, 2*mp1-2, k)-ci(mp1, np1, k)*wb(i, mn)\n vo(i, 2*mp1-1, k) = vo(i, 2*mp1-1, k)+cr(mp1, np1, k)*wb(i, mn)\n we(i, 2*mp1-2, k) = we(i, 2*mp1-2, k)-cr(mp1, np1, k)*vb(i, mn)\n we(i, 2*mp1-1, k) = we(i, 2*mp1-1, k)-ci(mp1, np1, k)*vb(i, mn)\n end do\n if (mod(nlat, 2) /= 0) then\n we(imid, 2*mp1-2, k) = we(imid, 2*mp1-2, k) &\n -cr(mp1, np1, k)*vb(imid, mn)\n we(imid, 2*mp1-1, k) = we(imid, 2*mp1-1, k) &\n -ci(mp1, np1, k)*vb(imid, mn)\n end if\n end do\n end do\n end if\n end do\n end if\n case (7)\n !\n ! case ityp=7 v odd, w even cr and ci equal zero\n !\n ! case m = 0\n !\n do k=1, nt\n do np1=3, odd_stride, 2\n do i=1, imm1\n vo(i, 1, k)=vo(i, 1, k)+br(1, np1, k)*vb(i, np1)\n end do\n end do\n end do\n !\n ! case m = 1 through nlat-1\n !\n if (2 <= mmax) then\n do mp1=2, mmax\n m = mp1-1\n mb = m*(nlat-1)-(m*(m-1))/2\n mp2 = mp1+1\n if (mp1 <= odd_stride) then\n do k=1, nt\n do np1=mp1, odd_stride, 2\n mn = mb+np1\n do i=1, imm1\n vo(i, 2*mp1-2, k) = vo(i, 2*mp1-2, k)+br(mp1, np1, k)*vb(i, mn)\n vo(i, 2*mp1-1, k) = vo(i, 2*mp1-1, k)+bi(mp1, np1, k)*vb(i, mn)\n we(i, 2*mp1-2, k) = we(i, 2*mp1-2, k)-bi(mp1, np1, k)*wb(i, mn)\n we(i, 2*mp1-1, k) = we(i, 2*mp1-1, k)+br(mp1, np1, k)*wb(i, mn)\n end do\n if (mod(nlat, 2) /= 0) then\n we(imid, 2*mp1-2, k) = we(imid, 2*mp1-2, k) &\n -bi(mp1, np1, k)*wb(imid, mn)\n we(imid, 2*mp1-1, k) = we(imid, 2*mp1-1, k) &\n +br(mp1, np1, k)*wb(imid, mn)\n end if\n end do\n end do\n end if\n end do\n end if\n case (8)\n !\n ! case ityp=8 v odd, w even br and bi equal zero\n !\n ! case m = 0\n !\n do k=1, nt\n do np1=2, even_stride, 2\n do i=1, imid\n we(i, 1, k)=we(i, 1, k)-cr(1, np1, k)*vb(i, np1)\n end do\n end do\n end do\n !\n ! case m = 1 through nlat-1\n !\n if (2 <= mmax) then\n do mp1=2, mmax\n m = mp1-1\n mb = m*(nlat-1)-(m*(m-1))/2\n mp2 = mp1+1\n if (mp2 <= even_stride) then\n do k=1, nt\n do np1=mp2, even_stride, 2\n mn = mb+np1\n do i=1, imm1\n vo(i, 2*mp1-2, k) = vo(i, 2*mp1-2, k)-ci(mp1, np1, k)*wb(i, mn)\n vo(i, 2*mp1-1, k) = vo(i, 2*mp1-1, k)+cr(mp1, np1, k)*wb(i, mn)\n we(i, 2*mp1-2, k) = we(i, 2*mp1-2, k)-cr(mp1, np1, k)*vb(i, mn)\n we(i, 2*mp1-1, k) = we(i, 2*mp1-1, k)-ci(mp1, np1, k)*vb(i, mn)\n end do\n if (mod(nlat, 2) /= 0) then\n we(imid, 2*mp1-2, k) = we(imid, 2*mp1-2, k) &\n -cr(mp1, np1, k)*vb(imid, mn)\n we(imid, 2*mp1-1, k) = we(imid, 2*mp1-1, k) &\n -ci(mp1, np1, k)*vb(imid, mn)\n end if\n end do\n end do\n end if\n end do\n end if\n end select vector_symmetry_cases\n\n call util%assemble_transform(idvw, jdvw, idv, imid, &\n imm1, ityp, nlat, nlon, nt, v, ve, vo, w, we, wo, wrfft)\n\n end subroutine vhses_lower_utility_routine\n\n\n pure function get_vhsesi_workspace_indices(nlat, imid, mmax, lzimn) &\n result (return_value)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: imid\n integer(ip), intent(in) :: mmax\n integer(ip), intent(in) :: lzimn\n integer(ip) :: return_value(4)\n\n associate (i => return_value)\n i(1) = 3*nlat*imid+1\n i(2) = (mmax*(2*nlat-mmax+1))/2\n i(3) = lzimn+1\n i(4) = 2*lzimn+1\n end associate\n\n end function get_vhsesi_workspace_indices\n\n subroutine vhsesi_lower_utility_routine(nlat, nlon, imid, vb, wb, idz, vin, wzvin, dwork)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n integer(ip), intent(in) :: imid\n real(wp), intent(out) :: vb(imid, *)\n real(wp), intent(out) :: wb(imid, *)\n integer(ip), intent(in) :: idz\n real(wp), intent(out) :: vin(imid, nlat, 3)\n real(wp), intent(out) :: wzvin(*)\n real(wp), intent(out) :: dwork(*)\n\n ! Local variables\n integer(ip) :: i3, m, mmax, mn, mp1, np1\n type(SpherepackUtility) :: util\n\n\n mmax = min(nlat, (nlon + 1)/2)\n\n call util%initialize_polar_components_for_regular_grids(nlat, nlon, wzvin, dwork)\n\n do mp1=1, mmax\n m = mp1-1\n call util%compute_polar_component(0, nlat, nlon, m, vin, i3, wzvin)\n do np1=mp1, nlat\n mn = m*(nlat-1)-(m*(m-1))/2+np1\n vb(1:imid, mn) = vin(1:imid, np1, i3)\n end do\n end do\n\n call util%initialize_azimuthal_components_for_regular_grids(nlat, nlon, wzvin, dwork)\n\n do mp1=1, mmax\n m = mp1-1\n call util%compute_azimuthal_component(0, nlat, nlon, m, vin, i3, wzvin)\n do np1=mp1, nlat\n mn = m*(nlat-1)-(m*(m-1))/2+np1\n wb(1:imid, mn) = vin(1:imid, np1, i3)\n end do\n end do\n\n end subroutine vhsesi_lower_utility_routine\n\nend submodule vector_synthesis_regular_grid_saved\n", "meta": {"hexsha": "180e34878b191e22ea8f3e697dd1b7056377f2a8", "size": 55602, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/vector_synthesis_regular_grid_saved.f90", "max_stars_repo_name": "jlokimlin/spherepack4.1", "max_stars_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-06-28T14:01:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T21:59:28.000Z", "max_issues_repo_path": "src/vector_synthesis_regular_grid_saved.f90", "max_issues_repo_name": "jlokimlin/spherepack4.1", "max_issues_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2016-05-07T23:00:35.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-22T23:52:30.000Z", "max_forks_repo_path": "src/vector_synthesis_regular_grid_saved.f90", "max_forks_repo_name": "jlokimlin/spherepack4.1", "max_forks_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-06-28T14:03:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T12:53:54.000Z", "avg_line_length": 47.0008453085, "max_line_length": 115, "alphanum_fraction": 0.3705981799, "num_tokens": 15979, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127678225575, "lm_q2_score": 0.7690802370707281, "lm_q1q2_score": 0.6567274339146942}} {"text": " REAL*8 FUNCTION XINTERP(X,X1,X2,Y1,Y2,LUERR,IERR)\nC\nC\nC THIS FUNCTION PERFORMS A LINEAR INTERPOLATION/EXTRAPOLATION\nC TO FIND THE VALUE Y OF A FUNCTION GIVEN THE VALUE X AND TWO POINTS\nC ON THE LINE, (X1,Y1) AND (X2,Y2).\nC\nC VARIABLE DIM TYPE I/O DESCRIPTION\nC -------- --- ---- --- -----------\nC X 1 R*8 I KNOWN VALUE FOR WHICH CORRESPONDING\nC INTERPOLATED VALUE IS DESIRED.\nC\nC X1 1 R*8 I X-VALUE FOR THE FIRST KNOWN POINT\nC\nC X2 1 R*8 I X-VALUE FOR THE SECOND KNOWN POINT\nC X1 AND X2 MUST BE DIFFERENT VALUES.\nC\nC Y1 1 R*8 I Y-VALUE FOR THE FIRST KNOWN POINT\nC\nC Y2 1 R*8 I Y-VALUE FOR THE SECOND KNOWN POINT\nC\nC LUERR 1 I*4 I FORTRAN UNIT NUMBER TO WHICH ERROR MESSAGES\nC CAN BE WRITTEN.\nC\nC IERR 1 I*4 O ERROR RETURN FLAG.\nC = 0, NO ERROR.\nC = 1, ERROR. ONLY ERROR IS X1=X2.\nC IF AN ERROR OCCURS, \nC THEN XINTERP = (Y1+Y2)/2 IS SET.\nC\nC XINTERP 1 R*8 O THIS IS THE FUNCTION VALUE THAT IS RETURNED.\nC\nC-----------------------------------------------------------------------\nC\nC CODED BY MARY S. WALKER. 12/83.\nC MODIFIED.....\nC\nC-----------------------------------------------------------------------\nC\n IMPLICIT REAL*8 (A-H,O-Z)\n INTEGER NERR/0/, MAXERR/6/\nC\nC\n IF (X1.EQ.X2) THEN\n IERR = 1\n XINTERP = (Y1+Y2)/2.D0\n CALL MESAGE(1,NERR,MAXERR,1,3,0,LUERR,\n * 'ERROR IN XINTERP. X1=X2. INTERPOLATION VALUE = (Y1+Y2)/2.')\n ELSE\n IERR = 0\n GRAD = ( Y2 - Y1 ) / ( X2 - X1 )\n DIFF = ( X - X1 ) * GRAD\n XINTERP = DIFF + Y1\n END IF\nC\n RETURN\n END\n", "meta": {"hexsha": "209e4b5b362a0ac118b640098ea5ddf0c0d5db14", "size": 1876, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "gsc-13083/xinterp.for", "max_stars_repo_name": "SteveDoyle2/nasa-cosmic", "max_stars_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_stars_repo_licenses": ["BSD-Source-Code"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2015-03-14T07:26:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-16T12:23:17.000Z", "max_issues_repo_path": "gsc-13083/xinterp.for", "max_issues_repo_name": "SteveDoyle2/nasa-cosmic", "max_issues_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_issues_repo_licenses": ["BSD-Source-Code"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gsc-13083/xinterp.for", "max_forks_repo_name": "SteveDoyle2/nasa-cosmic", "max_forks_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_forks_repo_licenses": ["BSD-Source-Code"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2016-02-12T22:18:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-08T17:46:54.000Z", "avg_line_length": 32.3448275862, "max_line_length": 72, "alphanum_fraction": 0.4664179104, "num_tokens": 603, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517044, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.6567274269973771}} {"text": "!! ------------------------------------------------------------------------- !!\n!>\n!! Common parameters used in llw2d and tdac\n!<\n!! --\nmodule m_params\n\n implicit none\n public\n\n integer, parameter, public :: DP = selected_real_kind(13)\n integer, parameter, public :: STDERR = 0\n integer, parameter, public :: STDOUT = 6\n real(DP), parameter :: g0 = 9.80665_DP !< Gravity Constant\n\n !! finite differnce method parametrs\n integer, parameter :: nx = 200 !< grid number (NS)\n integer, parameter :: ny = 200 !< grid number (EW)\n integer, parameter :: no = 36 !< Number of stations\n real(DP), parameter :: dx = 2000._DP !< grid width of x-direction (m)\n real(DP), parameter :: dy = 2000._DP !< grid width of y-direction (m)\n real(DP), parameter :: dt = 1.0_DP !< time step width (sec)\n\nend module m_params\n!! ------------------------------------------------------------------------- !!\n", "meta": {"hexsha": "747af5e93087f2aa26b1bbfabe71a3c9c3b8cc6e", "size": 947, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/m_params.f90", "max_stars_repo_name": "Team-RADDISH/tdac", "max_stars_repo_head_hexsha": "14f98abbb83a00df203d069e84b78eb3ca4a758e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-10-30T08:43:02.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-22T08:52:57.000Z", "max_issues_repo_path": "src/m_params.f90", "max_issues_repo_name": "Team-RADDISH/tdac", "max_issues_repo_head_hexsha": "14f98abbb83a00df203d069e84b78eb3ca4a758e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/m_params.f90", "max_forks_repo_name": "Team-RADDISH/tdac", "max_forks_repo_head_hexsha": "14f98abbb83a00df203d069e84b78eb3ca4a758e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-07-17T00:12:36.000Z", "max_forks_repo_forks_event_max_datetime": "2018-12-08T14:09:28.000Z", "avg_line_length": 36.4230769231, "max_line_length": 79, "alphanum_fraction": 0.51531151, "num_tokens": 249, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127380808499, "lm_q2_score": 0.7690802264851919, "lm_q1q2_score": 0.6567274020018103}} {"text": " SUBROUTINE LDP (G,MDG,M,N,H,X,XNORM,W,INDEX,MODE) \nC\nC Algorithm LDP: LEAST DISTANCE PROGRAMMING\nC\nC The original version of this code was developed by\nC Charles L. Lawson and Richard J. Hanson at Jet Propulsion Laboratory\nC 1974 MAR 1, and published in the book\nC \"SOLVING LEAST SQUARES PROBLEMS\", Prentice-HalL, 1974.\nC Revised FEB 1995 to accompany reprinting of the book by SIAM.\nC ------------------------------------------------------------------\n integer I, IW, IWDUAL, IY, IZ, J, JF, M, MDG, MODE, N, NP1\nC integer INDEX(M) \nC double precision G(MDG,N), H(M), X(N), W(*) \n integer INDEX(*) \n double precision G(MDG,*), H(*), X(*), W(*)\n double precision DIFF, FAC, ONE, RNORM, XNORM, ZERO\n parameter(ONE = 1.0d0, ZERO = 0.0d0)\nC ------------------------------------------------------------------\n IF (N.LE.0) GO TO 120 \n DO 10 J=1,N \n 10 X(J)=ZERO \n XNORM=ZERO\n IF (M.LE.0) GO TO 110 \nC \nC THE DECLARED DIMENSION OF W() MUST BE AT LEAST (N+1)*(M+2)+2*M. \nC \nC FIRST (N+1)*M LOCS OF W() = MATRIX E FOR PROBLEM NNLS.\nC NEXT N+1 LOCS OF W() = VECTOR F FOR PROBLEM NNLS.\nC NEXT N+1 LOCS OF W() = VECTOR Z FOR PROBLEM NNLS.\nC NEXT M LOCS OF W() = VECTOR Y FOR PROBLEM NNLS.\nC NEXT M LOCS OF W() = VECTOR WDUAL FOR PROBLEM NNLS. \nC COPY G**T INTO FIRST N ROWS AND M COLUMNS OF E. \nC COPY H**T INTO ROW N+1 OF E. \nC \n IW=0 \n DO 30 J=1,M \n DO 20 I=1,N \n IW=IW+1 \n 20 W(IW)=G(J,I) \n IW=IW+1 \n 30 W(IW)=H(J) \n JF=IW+1 \nC STORE N ZEROS FOLLOWED BY A ONE INTO F.\n DO 40 I=1,N \n IW=IW+1 \n 40 W(IW)=ZERO \n W(IW+1)=ONE \nC \n NP1=N+1 \n IZ=IW+2 \n IY=IZ+NP1 \n IWDUAL=IY+M \nC \n CALL NNLS (W,NP1,NP1,M,W(JF),W(IY),RNORM,W(IWDUAL),W(IZ),INDEX, \n * MODE) \nC USE THE FOLLOWING RETURN IF UNSUCCESSFUL IN NNLS.\n IF (MODE.NE.1) RETURN \n IF (RNORM) 130,130,50 \n 50 FAC=ONE \n IW=IY-1 \n DO 60 I=1,M \n IW=IW+1 \nC HERE WE ARE USING THE SOLUTION VECTOR Y.\n 60 FAC=FAC-H(I)*W(IW)\nC \n IF (DIFF(ONE+FAC,ONE)) 130,130,70 \n 70 FAC=ONE/FAC \n DO 90 J=1,N \n IW=IY-1 \n DO 80 I=1,M \n IW=IW+1 \nC HERE WE ARE USING THE SOLUTION VECTOR Y.\n 80 X(J)=X(J)+G(I,J)*W(IW)\n 90 X(J)=X(J)*FAC \n DO 100 J=1,N \n 100 XNORM=XNORM+X(J)**2 \n XNORM=sqrt(XNORM) \nC SUCCESSFUL RETURN.\n 110 MODE=1\n RETURN\nC ERROR RETURN. N .LE. 0. \n 120 MODE=2\n RETURN\nC RETURNING WITH CONSTRAINTS NOT COMPATIBLE.\n 130 MODE=4\n RETURN\n END \n", "meta": {"hexsha": "cfc566cd885cd999e17cf24f99fbc5bf5ad52cb0", "size": 3005, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "lawson-hanson/fortran/ldp.f", "max_stars_repo_name": "jhu-cisst/cisstNetlib", "max_stars_repo_head_hexsha": "19932915dc3e24bddeff7078b270f862e86e3f9e", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-10-19T03:12:28.000Z", "max_stars_repo_stars_event_max_datetime": "2017-10-19T03:12:28.000Z", "max_issues_repo_path": "lawson-hanson/fortran/ldp.f", "max_issues_repo_name": "jhu-cisst/cisstNetlib", "max_issues_repo_head_hexsha": "19932915dc3e24bddeff7078b270f862e86e3f9e", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2015-08-07T23:07:38.000Z", "max_issues_repo_issues_event_max_datetime": "2015-09-28T14:48:54.000Z", "max_forks_repo_path": "lawson-hanson/fortran/ldp.f", "max_forks_repo_name": "jhu-cisst/cisstNetlib", "max_forks_repo_head_hexsha": "19932915dc3e24bddeff7078b270f862e86e3f9e", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.1477272727, "max_line_length": 72, "alphanum_fraction": 0.4635607321, "num_tokens": 991, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898178450964, "lm_q2_score": 0.7248702880639791, "lm_q1q2_score": 0.656725100244407}} {"text": "!\n! CalculiX - A 3-dimensional finite element program\n! Copyright (C) 1998-2019 Guido Dhondt\n! \n! This program is free software; you can redistribute it and/or\n! modify it under the terms of the GNU General Public License as\n! published by the Free Software Foundation(version 2);\n! \n! \n! This program is distributed in the hope that it will be useful,\n! but WITHOUT ANY WARRANTY; without even the implied warranty of \n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \n! GNU General Public License for more details.\n! \n! You should have received a copy of the GNU General Public License\n! along with this program; if not, write to the Free Software\n! Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n! \n! This subroutines enables to calculate the reynolds number correction after:\n! \"Discharge coeffcients for incompressible non-cavitating flowthrough long orifices\"\n! A. Lichtarowicz, R.K duggins and E. Markland\n! Journal Mechanical Engineering Science , vol 7, No. 2, 1965\n!\n! author: Yannick Muller\n!\n subroutine cd_lichtarowicz(cd,cdu,reynolds,amod,bdh) \n!\n implicit none\n!\n real*8 cdu,reynolds,amod,bdh,eps,A1,cd_diff,cd0,cd\n!\n cd0=cdu\n cd_diff=1.d0\n!\n do\n! \n if(cd_diff.lt.1.d-3) exit\n!\n cd=cd0\n A1=20/(reynolds*dsqrt(1.d0-Amod**2))*(1.d0+2.25d0*bdh)\n eps=(0.005d0*bdh)/(1.d0+7.5d0*(log10(0.00015d0*reynolds*\n & dsqrt(1.d0-Amod**2)/cd))**2)\n \n cd=((-1/cdu+eps)+dsqrt((1/cdu-eps)**2.d0+4.d0*A1))/(2*A1)\n!\n cd_diff=dabs(cd-cd0)\n!\n cd0=cd\n!\n enddo\n! \n return\n end\n", "meta": {"hexsha": "fcdc0a1532a0a7990932407c51a8ad9f84634425", "size": 1724, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ccx_prool/CalculiX/ccx_2.16/src/cd_lichtarowicz.f", "max_stars_repo_name": "alleindrach/calculix-desktop", "max_stars_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ccx_prool/CalculiX/ccx_2.16/src/cd_lichtarowicz.f", "max_issues_repo_name": "alleindrach/calculix-desktop", "max_issues_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ccx_prool/CalculiX/ccx_2.16/src/cd_lichtarowicz.f", "max_forks_repo_name": "alleindrach/calculix-desktop", "max_forks_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.9259259259, "max_line_length": 89, "alphanum_fraction": 0.6281902552, "num_tokens": 530, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989822921759, "lm_q2_score": 0.724870282120402, "lm_q1q2_score": 0.6567250985395086}} {"text": "program Guess_a_number_Player\n implicit none\n\n integer, parameter :: limit = 100\n integer :: guess, mx = limit, mn = 1\n real :: rnum\n character(1) :: score\n\n write(*, \"(a, i0, a)\") \"Think of a number between 1 and \", limit, &\n \" and I will try to guess it.\"\n write(*, \"(a)\") \"You score my guess by entering: h if my guess is higher than that number\"\n write(*, \"(a)\") \" l if my guess is lower than that number\"\n write(*, \"(a/)\") \" c if my guess is the same as that number\"\n\n call random_seed\n call random_number(rnum)\n guess = rnum * limit + 1\n do\n write(*, \"(a, i0, a,)\", advance='no') \"My quess is: \", guess, \" Score(h, l or c)?: \"\n read*, score\n select case(score)\n case(\"l\", \"L\")\n mn = guess\n guess = (mx-guess+1) / 2 + mn\n\n case(\"h\", \"H\")\n mx = guess\n guess = mx - (guess-mn+1) / 2\n\n case(\"c\", \"C\")\n write(*, \"(a)\") \"I solved it!\"\n exit\n\n case default\n write(*, \"(a)\") \"I did not understand that\"\n end select\n end do\nend program\n", "meta": {"hexsha": "84385b75aea4b79e789a44bed05cebdaa27f3870", "size": 1118, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Guess-the-number-With-feedback--player-/Fortran/guess-the-number-with-feedback--player-.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/Guess-the-number-With-feedback--player-/Fortran/guess-the-number-with-feedback--player-.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/Guess-the-number-With-feedback--player-/Fortran/guess-the-number-with-feedback--player-.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.6666666667, "max_line_length": 93, "alphanum_fraction": 0.5089445438, "num_tokens": 333, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989815306765, "lm_q2_score": 0.7248702761768248, "lm_q1q2_score": 0.6567250876348052}} {"text": "\n logical function pvGramsing(G,n)\nc--- JC: added comparison to onshellcutoff for each element of the\nc--- matrix passed in; if the element is smaller, set to zero\n implicit none\n include 'TRonshellcutoff.f'\n include 'TRscale.f'\n integer nmax,n,j,k\n double complex G(n,n)\n double precision preci,wmax,wmin\n parameter(nmax=4,preci=1d-7)\nc--- Regular PV reduction fails checks at the C4 level at approx.\nc--- 10^-5 level of precision; lower tensors correspond to\nc--- much smaller values of preci. \n double precision Ga(nmax,nmax),V(nmax,nmax),w(nmax)\nC--- logical function which return true if the\nC--- Gram matrix is singular\n if (n .gt. nmax) then\n write(6,*) 'Error in pvGramsing, n .gt. nmax'\n stop\n endif\n\n do j=1,n\n do k=1,n\n Ga(j,k)=dble(G(j,k))\nc--- the next line improves convergence in pvdsvdcmp\n if (abs(Ga(j,k)/musq) .lt. onshellcutoff) Ga(j,k)=0d0\n enddo\n enddo\n \n call pvdsvdcmp(Ga,n,n,nmax,nmax,w,v)\n\n wmax=0d0\n do j=1,n\n if (w(j) .gt. wmax)wmax=w(j)\n enddo\n\n wmin=preci*wmax\n pvGramsing=.false.\n\n do j=1,n\nc write(6,*) 'wj ',w(j)/wmax\n if (w(j) .lt. wmin) then\n pvGramsing=.true.\n return\n endif\n enddo\n\n end\n", "meta": {"hexsha": "8329d4860e8c00d0ca3cff14d7b820fe4ebb83a0", "size": 1333, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "MCFM-JHUGen/TensorReduction/pv/pvGramsing.f", "max_stars_repo_name": "tmartini/JHUGen", "max_stars_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-06-08T13:09:28.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-04T19:59:36.000Z", "max_issues_repo_path": "MCFM-JHUGen/TensorReduction/pv/pvGramsing.f", "max_issues_repo_name": "tmartini/JHUGen", "max_issues_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 64, "max_issues_repo_issues_event_min_datetime": "2015-06-24T15:08:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-25T04:59:32.000Z", "max_forks_repo_path": "MCFM-JHUGen/TensorReduction/pv/pvGramsing.f", "max_forks_repo_name": "tmartini/JHUGen", "max_forks_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2015-05-04T22:15:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-06T10:04:40.000Z", "avg_line_length": 26.66, "max_line_length": 66, "alphanum_fraction": 0.5881470368, "num_tokens": 421, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898203834277, "lm_q2_score": 0.7248702702332476, "lm_q1q2_score": 0.6567250859299066}} {"text": "subroutine CilmPlusRhoH(cilm, gridin, lmax, nmax, mass, d, rho, gridtype, w, &\n zero, plx, n, dref, exitstatus)\n!------------------------------------------------------------------------------\n!\n! This routine will compute the potential coefficients associated\n! with the input gridded relief using the method of Wieczorek and\n! Phillips (1998). The input grid must contain the degree-0 term\n! and the computed coefficients will be referenced to the corresonding\n! degree-0 radius. Note that the array plx is optional, and should not\n! be precomputed when memory is an issue (i.e., lmax>360). In contrast\n! to CilmPlus, takes into account lateral variations in density by\n! inputing both a relief grid (GRIDIN) and density grid (RHO).\n!\n! Calling Parameters\n!\n! IN\n! gridin Input grid to be transformed to spherical harmonics.\n! lmax Maximum spherical harmonic degree to compute. For\n! gridtype 3 and 4, this must be less than or equal\n! to N/2 - 1.\n! nmax Order of expansion.\n! mass Mass of planet.\n! rho Input grid of the density with same dimensions as\n! GRIDIN.\n! gridtype 1 = Gauss-Legendre quadrature grid corresponding\n! to LMAX.\n! 2 = N by N Driscoll and Healy grid corresponding\n! to LMAX.\n! 3 = N by 2N Driscoll and Healy grid corresponding\n! to LMAX.\n! (4 = 2D Cartesian using MakeGrid2D is not implemented).\n!\n! OUT\n! cilm Output spherical harmonic coefficients with\n! dimensions (2, lmax+1, lmax+1).\n! d The radius that the coefficients are referenced\n! to. This parameter corresponds to the degree zero term\n! of the data.\n!\n! OPTIONAL\n! w Gauss-Legendre points used in the integrations of\n! dimension lmax+1.\n! zero Array of dimension lmax+1 that contains the latitudinal\n! gridpoints used in the Gauss-Legendre quadrature\n! integration scheme. Only needed when PLX is not\n! included (determined from a call to SHGLQ).\n! plx Input array of Associated Legendre Polnomials computed\n! at the Gauss points (determined from a call to\n! SHGLQ). If this is not included, then the optional\n! array zero MUST be inlcuded.\n! N Number of latitude points in the Driscoll and Healy\n! grid. Required for Gridtype 2 and 3.\n! dref The reference radius used to be used when calculating\n! the spherical harmonic coefficients. If not specified,\n! this will be set equal to the mean radius of GRIDIN.\n!\n! OPTIONAL (OUT)\n! exitstatus If present, instead of executing a STOP when an error\n! is encountered, the variable exitstatus will be\n! returned describing the error.\n! 0 = No errors;\n! 1 = Improper dimensions of input array;\n! 2 = Improper bounds for input variable;\n! 3 = Error allocating memory;\n! 4 = File IO error.\n!\n! All units assumed to be SI.\n!\n! Copyright (c) 2005-2019, SHTOOLS\n! All rights reserved.\n!\n!------------------------------------------------------------------------------\n use SHTOOLS, only: SHExpandGLQ, SHExpandDH\n use ftypes\n\n implicit none\n\n real(dp), intent(in) :: gridin(:,:), mass, rho(:,:)\n real(dp), intent(in), optional :: w(:), zero(:), plx(:,:), dref\n real(dp), intent(out) :: cilm(:,:,:), d\n integer(int32), intent(in) :: lmax, nmax, gridtype\n integer(int32), intent(in), optional :: n\n integer(int32), intent(out), optional :: exitstatus\n real(dp) :: prod, pi, scalef\n real(dp), allocatable :: cilmn(:,:,:), grid(:,:)\n integer(int32) :: j, l, k, nlat, nlong, astat(2), lmax_dh\n\n if (present(exitstatus)) exitstatus = 0\n\n pi = acos(-1.0_dp)\n\n if (size(cilm(:,1,1)) < 2 .or. size(cilm(1,:,1)) < lmax+1 .or. &\n size(cilm(1,1,:)) < lmax+1) then\n print*, \"Error --- CilmPlusRhoH\"\n print*, \"CILM must be dimensioned as (2, LMAX+1, LMAX+1) where \" // &\n \"LMAX is \", lmax\n print*, \"Input dimension is \", size(cilm(:,1,1)), size(cilm(1,:,1)), &\n size(cilm(1,1,:))\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n end if\n\n if (gridtype == 4) then\n print*, \"Error --- CilmPlusRhoH\"\n print*, \"GRIDTYPE 4 (Cartesian obtained from MakeGrid2D) is \" // &\n \"not allowed.\"\n if (present(exitstatus)) then\n exitstatus = 2\n return\n else\n stop\n end if\n\n else if (gridtype == 1) then\n if (present(n)) then\n print*, \"Error --- CilmPlusRhoH\"\n print*, \"N can not be present when using GLQ grids.\"\n if (present(exitstatus)) then\n exitstatus = 5\n return\n else\n stop\n end if\n\n end if\n\n if (present(w) .and. present(zero) .and. present(plx)) then\n print*, \"Error --- CilmPlusRhoH\"\n print*, \"For GLQ grids, either W and ZERO or W and PLX \" // &\n \"must be present, but not all three.\"\n if (present(exitstatus)) then\n exitstatus = 5\n return\n else\n stop\n end if\n\n else if (present(w) .and. present(zero)) then\n if (size(w) < lmax + 1) then\n print*, \"Error --- CilmPlusRhoH\"\n print*, \"W must be dimensioned as (LMAX+1) where LMAX is \", lmax\n print*, \"Input dimension is \", size(w)\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n end if\n\n if (size(zero) < lmax + 1) then\n print*, \"Error --- CilmPlusRhoH\"\n print*, \"ZERO must be dimensioned as (LMAX+1) \" // &\n \"where LMAX is \", lmax\n print*, \"Input dimension is \", size(zero)\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n end if\n\n else if (present(plx) .and. present(w)) then\n if (size(w) < lmax + 1) then\n print*, \"Error --- CilmPlusRhoH\"\n print*, \"W must be dimensioned as (LMAX+1) where LMAX is \", lmax\n print*, \"Input dimension is \", size(w)\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n end if\n\n if (size(plx(:,1)) < lmax+1 .or. &\n size(plx(1,:)) < (lmax+1)*(lmax+2)/2) then\n print*, \"Error --- CilmPlusRhoH\"\n print*, \"PLX must be dimensioned as (LMAX+1, \" // &\n \"(LMAX+1)*(LMAX+2)/2) where LMAX is \", lmax\n print*, \"Input dimension is \", size(plx(:,1)), size(plx(1,:))\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n end if\n\n else\n print*, \"Error --- CilmPlusRhoH\"\n print*, \"For GLQ grids, either W and ZERO or W and \" // &\n \"PLX must be present\"\n if (present(exitstatus)) then\n exitstatus = 5\n return\n else\n stop\n end if\n\n end if\n\n else if (gridtype == 2) then\n if (present(w) .or. present(zero) .or. present(plx)) then\n print*, \"Error --- CilmPlusRhoH\"\n print*, \"W, ZERO and PLX can not be present for \" // &\n \"Driscoll-Healy grids.\"\n if (present(exitstatus)) then\n exitstatus = 5\n return\n else\n stop\n end if\n\n else if (.not. present(N)) then\n print*, \"Error --- CilmPlusRhoH\"\n print*, \"N must be present when GRIDTYPE is 2 or 3.\"\n if (present(exitstatus)) then\n exitstatus = 5\n return\n else\n stop\n end if\n\n end if\n\n else if (gridtype == 3) then\n if (present(w) .or. present(zero) .or. present(plx)) then\n print*, \"Error --- CilmPlusRhoH\"\n print*, \"W, ZERO and PLX can not be present for \" // &\n \"Driscoll-Healy grids.\"\n if (present(exitstatus)) then\n exitstatus = 5\n return\n else\n stop\n end if\n\n else if (.not. present(N)) then\n print*, \"Error --- CilmPlusRhoH\"\n print*, \"N must be present when GRIDTYPE is 2 or 3.\"\n if (present(exitstatus)) then\n exitstatus = 5\n return\n else\n stop\n end if\n\n end if\n\n else\n print*, \"Error --- CilmPlusRhoH\"\n print*, \"GRIDTYPE must be 2 (GLQ), 3 (NxN) or 4 (Nx2N)\"\n print*, \"Input value is \", gridtype\n if (present(exitstatus)) then\n exitstatus = 2\n return\n else\n stop\n end if\n\n end if\n\n if (gridtype == 1) then\n nlat = lmax + 1\n nlong = 2 * lmax + 1\n\n else if (gridtype == 2) then\n nlat = N\n nlong = N\n lmax_dh = N / 2 - 1\n\n if (lmax > lmax_dh) then\n print*, \"Error --- CilmPlusRhoH\"\n print*, \"For Driscoll-Healy grids, LMAX must be less \" // &\n \"than or equal to N/2 -1, where N is \", N\n print*, \"Input value of LMAX is \", lmax\n if (present(exitstatus)) then\n exitstatus = 2\n return\n else\n stop\n end if\n\n end if\n\n else if (gridtype == 3) then\n nlat = N\n nlong = 2 * N\n lmax_dh = N/2 - 1\n\n if (lmax > lmax_dh) then\n print*, \"Error --- CilmPlusRhoH\"\n print*, \"For Driscoll-Healy grids, LMAX must be less \" // &\n \"than or equal to N/2 -1, where N is \", N\n print*, \"Input value of LMAX is \", lmax\n if (present(exitstatus)) then\n exitstatus = 2\n return\n else\n stop\n end if\n\n end if\n\n end if\n\n if (size(gridin(1,:)) < nlong .or. size(gridin(:,1)) < nlat .or. &\n size(rho(1,:)) < nlong .or. size(rho(:,1)) < nlat) then\n print*, \"Error --- CilmPlusRhoH\"\n if (gridtype == 2) then\n print*, \"GRIDIN and RHO must be dimensioned as \" // &\n \"(LMAX+1, 2*LMAX+1) where LMAX is \", lmax\n print*, \"Input dimension of GRIDIN is \", size(gridin(1,:)), &\n size(gridin(:,1))\n print*, \"Input dimension of RHO is \", size(rho(1,:)), size(rho(:,1))\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n else if (gridtype == 3) then \n print*, \"GRIDIN and RHO must be dimensioned as \" // &\n \"(N, N) where N is \", n\n print*, \"Input dimension of GRIDIN is \", size(gridin(1,:)), &\n size(gridin(:,1))\n print*, \"Input dimension of RHO is \", size(rho(1,:)), size(rho(:,1))\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n else if (gridtype == 4) then \n print*, \"GRIDIN and RHO must be dimensioned as \" // &\n \"(N, 2N) where N is \", n\n print*, \"Input dimension of GRIDIN is \", size(gridin(1,:)), &\n size(gridin(:,1))\n print*, \"Input dimension of RHO is \", size(gridin(1,:)), &\n size(gridin(:,1))\n if (present(exitstatus)) then\n exitstatus = 2\n return\n else\n stop\n end if\n\n end if\n\n end if\n\n allocate (cilmn(2, lmax+1, lmax+1), stat=astat(1))\n allocate (grid(nlat, nlong), stat=astat(2))\n if (astat(1) /= 0 .or. astat(2) /= 0) then\n print*, \"Error --- CilmPlusRhoH\"\n print*, \"Problem allocating arrays CILMN and GRID\", astat(1), astat(2)\n if (present(exitstatus)) then\n exitstatus = 3\n return\n else\n stop\n end if\n\n end if\n\n !--------------------------------------------------------------------------\n !\n ! Do the expansion.\n !\n !--------------------------------------------------------------------------\n grid(1:nlat, 1:nlong) = gridin(1:nlat,1:nlong)\n cilm = 0.0_dp\n cilmn = 0.0_dp\n\n ! Determine reference radius, if necessary\n if (present(dref)) then\n d = dref\n\n else\n select case (gridtype)\n case (1)\n if (present(plx)) then\n if (present(exitstatus)) then\n call SHExpandGLQ(cilmn(1:2,1:lmax+1,1:lmax+1), lmax, &\n grid(1:nlat,1:nlong), w, plx = plx, &\n norm = 1, csphase = 1, lmax_calc = 0, &\n exitstatus = exitstatus)\n if (exitstatus /= 0) return\n else\n call SHExpandGLQ(cilmn(1:2,1:lmax+1,1:lmax+1), lmax, &\n grid(1:nlat,1:nlong), w, plx = plx, &\n norm = 1, csphase = 1, lmax_calc = 0)\n end if\n else\n if (present(exitstatus)) then\n call SHExpandGLQ(cilmn(1:2,1:lmax+1,1:lmax+1), lmax, &\n grid(1:nlat,1:nlong), w, zero=zero, &\n norm = 1, csphase = 1, lmax_calc = 0, &\n exitstatus = exitstatus)\n if (exitstatus /= 0) return\n else\n call SHExpandGLQ(cilmn(1:2,1:lmax+1,1:lmax+1), lmax, &\n grid(1:nlat,1:nlong), w, zero=zero, &\n norm = 1, csphase = 1, lmax_calc = 0)\n end if\n end if\n\n case (2)\n if (present(exitstatus)) then\n call SHExpandDH(grid(1:nlat,1:nlong), n, &\n cilmn(1:2,1:lmax+1,1:lmax+1), lmax_dh, &\n norm = 1, sampling = 1, csphase = 1, &\n lmax_calc = 0, exitstatus = exitstatus)\n if (exitstatus /= 0) return\n else\n call SHExpandDH(grid(1:nlat,1:nlong), n, &\n cilmn(1:2,1:lmax+1,1:lmax+1), lmax_dh, &\n norm = 1, sampling = 1, csphase = 1, &\n lmax_calc = 0)\n end if\n\n case (3)\n if (present(exitstatus)) then\n call SHExpandDH(grid(1:nlat,1:nlong), n, &\n cilmn(1:2,1:lmax+1,1:lmax+1), lmax_dh, &\n norm = 1, sampling = 2, csphase = 1, &\n lmax_calc = 0, exitstatus = exitstatus)\n if (exitstatus /= 0) return\n else\n call SHExpandDH(grid(1:nlat,1:nlong), n, &\n cilmn(1:2,1:lmax+1,1:lmax+1), lmax_dh, &\n norm = 1, sampling = 2, csphase = 1, &\n lmax_calc = 0)\n end if\n\n end select\n\n d = cilmn(1,1,1) ! use mean radius of relief for reference sphere\n\n end if\n\n ! Do k = 1 terms first\n grid(1:nlat, 1:nlong) = (gridin(1:nlat,1:nlong)-d) &\n * rho(1:nlat,1:nlong) / d\n\n select case (gridtype)\n case (1)\n if (present(plx)) then\n if (present(exitstatus)) then\n call SHExpandGLQ(cilmn(1:2,1:lmax+1,1:lmax+1), lmax, &\n grid(1:nlat,1:nlong), w, plx = plx, &\n norm = 1, csphase = 1, &\n exitstatus = exitstatus)\n if (exitstatus /= 0) return\n else\n call SHExpandGLQ(cilmn(1:2,1:lmax+1,1:lmax+1), lmax, &\n grid(1:nlat,1:nlong), w, plx = plx, &\n norm = 1, csphase = 1)\n end if\n else\n if (present(exitstatus)) then\n call SHExpandGLQ(cilmn(1:2,1:lmax+1,1:lmax+1), lmax, &\n grid(1:nlat,1:nlong), w, zero=zero, &\n norm = 1, csphase = 1, &\n exitstatus = exitstatus)\n if (exitstatus /= 0) return\n else\n call SHExpandGLQ(cilmn(1:2,1:lmax+1,1:lmax+1), lmax, &\n grid(1:nlat,1:nlong), w, zero=zero, &\n norm = 1, csphase = 1)\n end if\n end if\n\n case (2)\n if (present(exitstatus)) then\n call SHExpandDH(grid(1:nlat,1:nlong), n, &\n cilmn(1:2,1:lmax+1,1:lmax+1), lmax_dh, &\n norm = 1, sampling = 1, csphase = 1, &\n lmax_calc = lmax, exitstatus = exitstatus)\n if (exitstatus /= 0) return\n else\n call SHExpandDH(grid(1:nlat,1:nlong), n, &\n cilmn(1:2,1:lmax+1,1:lmax+1), lmax_dh, &\n norm = 1, sampling = 1, csphase = 1, &\n lmax_calc = lmax)\n end if\n\n case (3)\n if (present(exitstatus)) then\n call SHExpandDH(grid(1:nlat,1:nlong), n, &\n cilmn(1:2,1:lmax+1,1:lmax+1), lmax_dh, &\n norm = 1, sampling = 2, csphase = 1, &\n lmax_calc = lmax, exitstatus = exitstatus)\n if (exitstatus /= 0) return\n else\n call SHExpandDH(grid(1:nlat,1:nlong), n, &\n cilmn(1:2,1:lmax+1,1:lmax+1), lmax_dh, &\n norm = 1, sampling = 2, csphase = 1, &\n lmax_calc = lmax)\n end if\n\n end select\n\n do l = 0, lmax\n cilm(1:2,l+1,1:l+1) = 4.0_dp * pi * (d**3) * cilmn(1:2,l+1,1:l+1) &\n / mass / dble(2*l+1)\n end do\n\n scalef = maxval(abs(gridin(1:nlat,1:nlong) - d))\n\n do k = 2, nmax\n grid(1:nlat,1:nlong) = rho(1:nlat,1:nlong) &\n * ((gridin(1:nlat,1:nlong) - d) / scalef)**k\n select case (gridtype)\n case (1)\n if (present(plx)) then\n if (present(exitstatus)) then\n call SHExpandGLQ(cilmn(1:2,1:lmax+1,1:lmax+1), lmax, &\n grid(1:nlat,1:nlong), w, plx=plx, &\n norm = 1, csphase = 1, &\n exitstatus = exitstatus)\n if (exitstatus /= 0) return\n else\n call SHExpandGLQ(cilmn(1:2,1:lmax+1,1:lmax+1), lmax, &\n grid(1:nlat,1:nlong), w, plx=plx, &\n norm = 1, csphase = 1)\n end if\n else\n if (present(exitstatus)) then\n call SHExpandGLQ(cilmn(1:2,1:lmax+1,1:lmax+1), lmax, &\n grid(1:nlat,1:nlong), w, zero=zero, &\n norm = 1, csphase = 1, &\n exitstatus = exitstatus)\n if (exitstatus /= 0) return\n else\n call SHExpandGLQ(cilmn(1:2,1:lmax+1,1:lmax+1), lmax, &\n grid(1:nlat,1:nlong), w, zero=zero, &\n norm = 1, csphase = 1)\n end if\n end if\n\n case(2)\n if (present(exitstatus)) then\n call SHExpandDH(grid(1:nlat,1:nlong), n, &\n cilmn(1:2,1:lmax+1,1:lmax+1), lmax_dh, &\n norm = 1, sampling = 1, csphase = 1, &\n lmax_calc = lmax, exitstatus = exitstatus)\n if (exitstatus /= 0) return\n else\n call SHExpandDH(grid(1:nlat,1:nlong), n, &\n cilmn(1:2,1:lmax+1,1:lmax+1), lmax_dh, &\n norm = 1, sampling = 1, csphase = 1, &\n lmax_calc = lmax)\n end if\n\n case(3)\n if (present(exitstatus)) then\n call SHExpandDH(grid(1:nlat,1:nlong), n, &\n cilmn(1:2,1:lmax+1,1:lmax+1), lmax_dh, &\n norm = 1, sampling = 2, csphase = 1, &\n lmax_calc = lmax, exitstatus = exitstatus)\n if (exitstatus /= 0) return\n else\n call SHExpandDH(grid(1:nlat,1:nlong), n, &\n cilmn(1:2,1:lmax+1,1:lmax+1), lmax_dh, &\n norm = 1, sampling = 2, csphase = 1, &\n lmax_calc = lmax)\n end if\n\n end select\n\n do l = 0, lmax\n prod = 4.0_dp * pi * (d**3) / mass * (scalef / d)**k\n\n do j = 1, k\n prod = prod * dble(l+4-j)\n end do\n\n prod = prod / (dble(2*l+1) * dble(l+3) * dble(fact(k)))\n\n cilm(1:2,l+1,1:l+1) = cilm(1:2,l+1,1:l+1) &\n + cilmn(1:2,l+1,1:l+1) * prod\n end do\n\n end do\n\n deallocate(cilmn)\n deallocate(grid)\n\n\n CONTAINS\n\n function fact(i)\n !----------------------------------------------------------------------\n !\n ! This function computes the factorial of an integer.\n !\n !----------------------------------------------------------------------\n implicit none\n integer(int32) :: i, j\n real(dp) :: fact\n\n if (i == 0) then\n fact = 1.0_dp\n else if (i < 0) then\n print*, \"Argument to FACT must be positive\"\n if (present(exitstatus)) then\n exitstatus = 2\n return\n else\n stop\n end if\n\n else\n fact = 1.0_dp\n\n do j = 1, i\n fact = fact * j\n end do\n\n end if\n\n end function fact\n\nend subroutine CilmPlusRhoH\n", "meta": {"hexsha": "f6149392e72eba025602d22e7bf9d2de7e1533b1", "size": 24420, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/CilmPlusRhoH.f95", "max_stars_repo_name": "mjc87/SHTOOLS", "max_stars_repo_head_hexsha": "8d83c42d1313d5624c4db8c2e57300c5d819834e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 251, "max_stars_repo_stars_event_min_datetime": "2015-01-27T12:58:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T17:19:36.000Z", "max_issues_repo_path": "src/CilmPlusRhoH.f95", "max_issues_repo_name": "mjc87/SHTOOLS", "max_issues_repo_head_hexsha": "8d83c42d1313d5624c4db8c2e57300c5d819834e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 193, "max_issues_repo_issues_event_min_datetime": "2015-03-11T06:21:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T14:05:45.000Z", "max_forks_repo_path": "src/CilmPlusRhoH.f95", "max_forks_repo_name": "mreineck/SHTOOLS", "max_forks_repo_head_hexsha": "fec33f203ee0b47008fd69d4080304d6ebd272e7", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 100, "max_forks_repo_forks_event_min_datetime": "2015-04-03T07:11:05.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-23T23:46:33.000Z", "avg_line_length": 38.2159624413, "max_line_length": 80, "alphanum_fraction": 0.4158886159, "num_tokens": 6155, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.7217432182679956, "lm_q1q2_score": 0.6567192143890538}} {"text": " subroutine dinverse(a,n,d)\r\nc********************************************\r\nc Finds inverse of A from cholesky decomposition A=LL'\r\nc Input: A & d from DCHOLSL\r\nc Output: A - inverse of covariance matrix\r\nc============================================\r\n integer n,i,j\r\n real*8 a(n,n),d(n),sum\r\n intent(in) d,n\r\nc********************************************\r\nc Lower diagonal inverse of L in a\r\n do i=1,n\r\n a(i,i)=1.d0/d(i)\r\n do j=i+1,n\r\n sum=0.d0\r\n do k=i,j-1\r\n sum=sum-a(j,k)*a(k,i)\r\n enddo\r\n a(j,i)=sum/d(j)\r\n enddo\r\n enddo\r\nc------\r\nc Inverse of LL'\r\n do i=1,n\r\n do j=i+1,n\r\n sum=0.d0\r\n do k=j,n\r\n sum=sum+a(k,i)*a(k,j)\r\n enddo\r\n a(i,j)=sum\r\n enddo\r\nc------\r\nc Diagonal\r\n sum=0.d0\r\n do k=i,n\r\n sum=sum+a(k,i)*a(k,i)\r\n enddo\r\n a(i,i)=sum\r\n enddo\r\nc------\r\n do i=1,n\r\n do j=i+1,n\r\n a(j,i)=a(i,j)\r\n enddo\r\n enddo\r\nc----------\r\n return\r\n end\r\n", "meta": {"hexsha": "4c453c7fcfb2075c43f7a89a8e48665e28c47e7a", "size": 1060, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "dinverse.for", "max_stars_repo_name": "emammendes/bispectrum", "max_stars_repo_head_hexsha": "03d46999d478911615dc01c7d9108870eadc9ab6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2015-09-29T05:27:08.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-09T09:09:36.000Z", "max_issues_repo_path": "dinverse.for", "max_issues_repo_name": "emammendes/bispectrum", "max_issues_repo_head_hexsha": "03d46999d478911615dc01c7d9108870eadc9ab6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "dinverse.for", "max_forks_repo_name": "emammendes/bispectrum", "max_forks_repo_head_hexsha": "03d46999d478911615dc01c7d9108870eadc9ab6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.6326530612, "max_line_length": 56, "alphanum_fraction": 0.3735849057, "num_tokens": 322, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380482, "lm_q2_score": 0.721743200312399, "lm_q1q2_score": 0.6567191945245743}} {"text": "c ##########################################################\nc # 2d LP solver based on Simplex algorithm #\nc # for directional limiting of cutcells #\nc # This solver is based on the allineq form of Simplex #\nc ##########################################################\n\n\n subroutine Simplex_allineq(row_A,A, b, c,\n & x0,W,output_debug,x,LP_success,my_iters)\n\n\n\nc :::::::::::::::::::::: Simplex_allineq :::::::::::::::::::::::::\nc\nc INPUT:\nc * row_A: no of rows of matrix A || row_A = number of constraints\nc * A: constraint matrix of LP: A(row_A,2)\nc * b: RHS of LP \nc * c: vector in objective in LP\nc * x0: admissible starting point for LP\nc * W: working set for Simplex method\nc * output_debug: logical whether we should output or not\nc \nc OUTPUT:\nc * x: solution of LP\nc * LP_success: was the Simplex algorithm successful?\nc * my_iters: number of iterations needed\nc\nc :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\n\nc ::::::::::::::::::::::::::::\nc Declare variables\nc ::::::::::::::::::::::::::::\n\n implicit none ! force yourself to properly declare all var\n\nc Input\n integer row_A\n double precision A(row_A,2), b(row_A), c(2) \n double precision x0(2) \n integer W(2)\n logical output_debug\n integer my_fort\n\nc Output\n double precision x(2)\n logical LP_success\n integer my_iters ! number of iterations needed\n\nc Local variables: Optimization variables\nc double precision matr_B(row_A,row_A), B_trans(row_A,row_A) ! columns of A corresponding to index_B\nc double precision matr_N(row_A,2) ! columns of A corresponding to index_N\nc double precision x_B(row_A), c_B(row_A) ! components of x,c in set B\nc double precision x_N(2), c_N(2) ! components of x,c in set N\nc double precision pi_vec(row_A) ! vector pi of Lagrange multipliers\nc double precision s_N(2) ! Lagrange multiplier s for set N\n\nc Local variables: other stuff\n integer i,j,k, shift_int, index_min_alpha\n double precision A_k(2,2)\n double precision det, lambda(2),min_lambda\n double precision e_q(2),p_k(2)\n double precision gamma,alpha,test\n integer min_index_W,size_D_k\nc integer ind_perm(row_A) ! permutation array coming back from solving matrix\nc integer INFO ! was subroutine of LAPACK successful?\nc double precision product, max_step_dir, min_comp ! help variables\nc integer index_N_to_B ! index in set N chosen to go to set B\nc integer index_B_to_N ! index in set B chosen to go to set N (ie limits step length)\nc double precision rhs_for_dgesv(row_A) ! help vector\nc double precision step_dir(row_A) ! help vector\nc integer min_comp_index_B, min_index_s_N\nc double precision test_admiss(row_A),max_admiss ! test whether B*x_B-b = 0\n\n\n\n 902 format (2(E12.2))\n 901 format (A,'\\t',F6.3)\n 908 format (A,'\\t',8(F6.3,'\\t'))\n 910 format (A,'\\t',10(F6.3,'\\t'))\n 912 format (A,'\\t',12(F6.3,'\\t'))\n 918 format (A,'\\t',8(E12.3,'\\t'))\n\nc ::::::::::::::::::::::::::::\nc Print given data\nc ::::::::::::::::::::::::::::\n\n if (output_debug) then\n write(*,*) \"###\"\n write(*,*) \"Subroutine Simplex_allineq\"\n write(*,*) \"###\"\n endif\n\n if (output_debug) then\n write (*,*) \"%%%%%%%\"\n write (*,*) \"Given data for LP\"\n write (*,*) \"%%%%%%%\"\n write(*,*) \"number of constraints\", row_A\n write(*,*) \"matrix A\"\n do 10 i = 1, row_A\n write(*,902) (A(i,j),j=1,2)\n 10 continue\nc\n if (row_A .EQ. 10) then\n write(*,910) \"b\",b\n elseif (row_A .EQ. 12) then\n write(*,912) \"b\",b\n endif\n write(*,*) \"x0:\", x0(1), x0(2)\n write(*,*) \"W:\", W\n write(*,*) \"c:\", c(1), c(2)\n endif ! end of if (output_debug) \n\n\nc #########################\nc Beginning of loop\nc #########################\n\n\n do 555 k = 1, 20\n \n if (output_debug) then\n write(*,*) \"%%%%%%%%\"\n write(*,*) \"Start iteration \",k\n write(*,*) \"%%%%%%%%\"\n write(*,*) \"x:\", x0(1), x0(2)\n write(*,*) \"W:\", W\n write(*,*) \"---\"\n endif\n \n\nc Step 1 of Algorithm -----------------------------\nc solve for Lagrange multiplier lambda: A_k^T lambda = c\n A_k(1,1) = A(W(1),1)\n A_k(1,2) = A(W(1),2)\n A_k(2,1) = A(W(2),1)\n A_k(2,2) = A(W(2),2)\n det = A_k(1,1)*A_k(2,2)-A_k(1,2)*A_k(2,1)\n ! added mjb for robustness\n if (det .eq. 0.0) then\n LP_Success = .false.\n return\n endif \n lambda(1) = (1.0d0/det)*(A_k(2,2)*c(1)-A_k(2,1)*c(2))\n lambda(2) = (1.0d0/det)*(-A_k(1,2)*c(1)+A_k(1,1)*c(2))\n if (output_debug) then\n write(*,*) \"lambda\", lambda\n endif\n\n\n\nc Step 2 of Algorithm --------------------------------\nc Test whether lambda >= 0\n min_lambda = min(lambda(1),lambda(2))\n if (min_lambda .GT. -1.E-12) then\nc write(*,*) \"\\n ###################### \\n\"\nc write(*,*) \"Have found the optimal x\\n\"\n x(1) = x0(1)\n x(2) = x0(2)\nc\nc if ((x(1) > 1.00005) .AND. (x(2) > 1.00005)) then\nc write(*,*) \"both slope > 1\", x(1), x(2)\nc endif\n LP_success = .TRUE.\nc write(*,*) \"LP_success\", LP_success\nc write(25,*) \"No-steps\", k-1\nc write(25,*) \"x\", x\n my_iters = k-1\n return\n endif\n\n\n\n\nc Step 3 of Algorithm -----------------------------------\nc select q with (lambda)_q < 0 as index to leave the working set\nc have 2 choices\nc our choice for now: go with the most negative one\n if (lambda(1).GE.lambda(2)) then\n min_index_W = 2\n else\n min_index_W = 1\n endif\n if (output_debug) then\n write(*,*) \"Index which leaves W\",W(min_index_W)\n endif\nc or go with the first negative index\nc if (lambda(1) < -1.E-12)\nc min_index_W = 1\nc else\nc min_index_W = 2\nc endif\n\n\nc Step 4 of Algorithm ---------------------------------\nc Calculate step direction by solving A_k p_k = e_q\n if (min_index_W .EQ. 1) then\n e_q = (/ 1.0d0, 0.0d0 /)\n else\n e_q = (/ 0.0d0, 1.0d0 /)\n endif\n p_k(1) = (1.0d0/det)*(A_k(2,2)*e_q(1)-A_k(1,2)*e_q(2))\n p_k(2) = (1.0d0/det)*(-A_k(2,1)*e_q(1)+A_k(1,1)*e_q(2))\n if (output_debug) then\n write(*,*) \"p_k\", p_k\n endif\n\n\n\nc Step 5 of Algorithm ----------------------------------\nc Calculate step length\n size_D_k = 0\n alpha = 100000000.0d0\n index_min_alpha = row_A + 10\n do 20 i=1,row_A\n test = A(i,1)*p_k(1) + A(i,2)*p_k(2)\n if (test .LT. -1.E-12) then\n gamma = -(A(i,1)*x0(1) + A(i,2)*x0(2) - b(i))/test\n if (gamma .LT. (alpha-1.E-12)) then\nc Make sure that you don't take an index in W which is already there\nc Contribution for indices in W should be 0 -- but by numerical error it\nc could happen that the error is bigger than the tested 1.E-12\n if ((i .ne. W(1)) .AND. (i .ne. W(2))) then\n size_D_k = size_D_k + 1\n alpha = gamma\n index_min_alpha = i\n endif\n endif\n endif\n 20 continue\n if (size_D_k .EQ. 0) then\n write(*,*) \"\\n LP unbounded !!!!!!!!!!!!\\n\"\n LP_success = .FALSE.\n return\n endif\n if (index_min_alpha .GT. row_A) then\n write(*,*) \"\\n Problem with index_min_alpha\\n\"\n LP_success = .FALSE.\n return\n endif\n if (output_debug) then\n write(*,*) \"Index which enters W\",index_min_alpha\n endif\n ! update x0\n x0(1) = x0(1) + alpha*p_k(1)\n x0(2) = x0(2) + alpha*p_k(2)\n if (output_debug) then\n write(*,*) \"new iterate x0\", x0\n endif\n\n\nc Step 6 of Algorithm ----------------------------------\nc Update working set\nc get rid of the index in position \"min_index_W\" and put\nc index_min_alpha there\n W(min_index_W) = index_min_alpha\n\n\n\nc write(*,*) \"After \",k,\" steps:\", \"Phi_x, Phi_y =\",x0(1),x0(2)\n\n\n 555 continue ! end of main loop\n\nc #########################\nc End of loop\nc #########################\n\n\n x(1) = x0(1)\n x(2) = x0(2)\n\n my_iters = k-1\n\n\n return\n end\n\n", "meta": {"hexsha": "53812688e935d3fedc57a3d5496ec309451eec26", "size": 9009, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/2d/fixed2_Simplex_allineq.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/fixed2_Simplex_allineq.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/fixed2_Simplex_allineq.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": 32.2903225806, "max_line_length": 105, "alphanum_fraction": 0.4770784771, "num_tokens": 2604, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582554941719, "lm_q2_score": 0.7057850216484838, "lm_q1q2_score": 0.6567034999969646}} {"text": " PROGRAM LA_SGELSS_EXAMPLE\n\n! -- LAPACK95 EXAMPLE DRIVER ROUTINE (VERSION 1.0) --\n! UNI-C, DENMARK\n! DECEMBER, 1999\n!\n! .. \"Use Statements\" ..\n USE LA_PRECISION, ONLY: WP => SP\n USE F95_LAPACK, ONLY: LA_GELSS, LA_LANGE\n! .. \"Implicit Statement\" ..\n IMPLICIT NONE\n! .. \"Local Scalars\" .\n REAL(WP) :: R1, R2, R3\n INTEGER :: RANK, I, J, INFO, M, N, NRHS\n! .. \"Local Arrays\" ..\n REAL(WP), ALLOCATABLE :: A(:,:), AA(:,:), B(:,:), BB(:,:), S(:)\n! .. \"Executable Statements\" ..\n WRITE (*,*) 'LA_GELSS Example Program Results'\n M=6; N = 4; NRHS = 3\n WRITE(*,'(5H N = , I4, 9H; NRHS = , I4)') N, NRHS\n ALLOCATE( A(M,N), AA(M,N), B(M,NRHS), BB(M,NRHS), S(N) )\n\n OPEN(UNIT=21,FILE='gelss.ma',STATUS='UNKNOWN')\n DO I=1,M \n DO J=1,N\n READ(21,*) A(I,J)\n ENDDO\n ENDDO\n CLOSE(21)\n\n OPEN(UNIT=22,FILE='gelss.mb',STATUS='UNKNOWN')\n DO I=1,M \n DO J=1,NRHS\n READ(22,*) B(I,J)\n ENDDO\n ENDDO\n CLOSE(22)\n \n WRITE(*,*)'Matrix A :'\n DO I=1,M;\n WRITE(*,\"(24(F9.5))\") A(I,:);\n ENDDO\n \n WRITE(*,*)'Matrix B :'\n DO I=1,M; \n WRITE(*,\"(3(F9.5))\") B(I,:); \n ENDDO\n \n WRITE(*,*) 'CALL LA_GELSS( A, B, RANK, S, 0.00001_WP, INFO )'\n CALL LA_GELSS( A, B, RANK, S, 0.00001_WP, INFO=INFO )\n \n WRITE(*,*) ' A on exit : '\n DO I=1,M; \n WRITE(*,\"(4(E14.6))\") A(I,:); \n ENDDO\n \n WRITE(*,*) ' B on exit : '\n DO I=1,M; \n WRITE(*,\"(3(E14.6))\") B(I,:); \n ENDDO\n \n WRITE(*,*) ' S on exit : '\n DO I=1,N; \n WRITE(*,\"(E14.6)\") S(I); \n ENDDO\n \n WRITE(*,*) 'RANK = ', RANK\n WRITE(*,*)'INFO = ',INFO\n \n R1=LA_LANGE(B(N+1:M,1),NORM='F')\n R2=LA_LANGE(B(N+1:M,2),NORM='F')\n R3=LA_LANGE(B(N+1:M,3),NORM='F')\n WRITE(*,*)'The residual r = ',R1,R2,R3\n \n END PROGRAM LA_SGELSS_EXAMPLE\n", "meta": {"hexsha": "d3eed5abd58dbee4d7b91223e70a1bf3453206c0", "size": 1986, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "EXAMPLES1/la_gelss_example.f90", "max_stars_repo_name": "MattBurn/LAPACK95", "max_stars_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-12-29T15:07:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T10:09:22.000Z", "max_issues_repo_path": "EXAMPLES1/la_gelss_example.f90", "max_issues_repo_name": "MattBurn/LAPACK95", "max_issues_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-12-30T15:38:47.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-31T06:45:11.000Z", "max_forks_repo_path": "EXAMPLES1/la_gelss_example.f90", "max_forks_repo_name": "MattBurn/LAPACK95", "max_forks_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-12-29T15:34:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-15T07:12:40.000Z", "avg_line_length": 26.1315789474, "max_line_length": 69, "alphanum_fraction": 0.4531722054, "num_tokens": 758, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818986, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6566860985676302}} {"text": "SUBROUTINE RK3(NEQ,X0,XE,N,Y0,YN,N1,WORK)\n!*********************************************************************\n! SUBROUTINE RK NUMERICALLY INTEGRATES A SYSTEM OF NEQ *\n! FIRST ORDER ORDINARY DIFFERENTIAL EQUATIONS OF THE FORM *\n! DY(I)/DX = F(X, Y(1),..., Y(NEQ)), *\n! BY THE CLASSICAL RUNGE-KUTTA FORMULA. *\n! *\n! PARAMETERS *\n! === INPUT === *\n! (1) NEQ: NUMBER OF EQUATIONS TO BE INTEGRATED *\n! (2) FUNC: SUBROUTINE FUNC(X,Y,F) TO EVALUATE DERIVATIVES *\n! F(I)=DY(I)/DX *\n! (3) X0: INITIAL VALUE OF INDEPENDENT VARIABLE *\n! (4) XE: OUTPUT POINT AT WHICH THE SOLUTION IS DESIRED *\n! (5) N: NUMBER OF DIVISIONS *\n! THE INTERVAL (X0, XE) IS DIVIDED INTO N SUBINTERVALS *\n! WITH THE LENGTH (XE-X0)/N AND IN EACH SUBINTERVAL *\n! THE CLASSICAL RUNGE-KUTTA FORMULA IS USED. *\n! (6) Y0(I) (I=1,..,NEQ): INITIAL VALUE AT X0 *\n! === OUTPUT === *\n! (7) YN(I) (I=1,..,NEQ): APPROXIMATE SOLUTION AT XE *\n! === OTHER === *\n! (8) WORK(): TWO-DIMENTIONAL ARRAY (SIZE=(NEQ,2)) TO BE *\n! USED INSIDE RK *\n! COPYRIGHT: M. SUGIHARA, NOVEMBER 15, 1989, V. 1 *\n! modified: Kensuke Konishi 2018 in Paris 2020 in Taiwan\n!*********************************************************************\n use parameters\n implicit none\n !EXTERNAL FUNC\n INTEGER:: NEQ,N,I,J,N1\n double precision:: X0,XE\n complex(dp):: Y0(NEQ),YN(NEQ),WORK(N1,2)\n double precision:: H\n H = (XE - X0) / DBLE(N)\n do I = 1,N\n CALL RKSTEP(NEQ,X0,H,Y0,YN,WORK(1,1),WORK(1,2))\n X0 = X0 + H\n Y0(1:neq) = YN(1:neq)\n enddo\n X0 = XE\n RETURN\n END\n\nSUBROUTINE RKSTEP(NEQ,X,H,Y0,YN,AK,W)\n use parameters\n implicit none\n\n INTEGER,intent(in):: NEQ\n double precision:: X,H\n complex(dp):: Y0(NEQ),YN(NEQ),AK(NEQ),W(NEQ)\n\n integer:: i\n double precision:: A2,A3,B2,B3,C1,C2,C3,C4\n PARAMETER(A2 = 0.5D0, A3 = A2)\n PARAMETER(B2 = 0.5D0, B3 = B2)\n PARAMETER(C1 = 1.D0/6.D0, C2 = 1.D0/3.D0, C3 = C2, C4 = C1)\n !EXTERNAL FUNC\n CALL eqmotion1(X,Y0,AK)\n\n YN(1:NEQ) = Y0(1:NEQ) + DCMPLX( H * C1 ) * AK(1:NEQ)\n\n W(1:NEQ) = Y0(1:NEQ) + DCMPLX( H * B2 ) * AK(1:NEQ)\n\n CALL eqmotion1(X + A2 * H,W,AK)\n\n YN(1:NEQ) = YN(1:NEQ) + DCMPLX( H * C2 ) * AK(1:NEQ)\n\n W(1:NEQ) = Y0(1:NEQ) + DCMPLX( H * B3 ) * AK(1:NEQ)\n\n CALL eqmotion1(X + A3 * H,W,AK)\n YN(1:NEQ) = YN(1:NEQ) + DCMPLX( H * C3 ) * AK(1:NEQ)\n\n W(1:NEQ) = Y0(1:NEQ) + DCMPLX( H ) * AK(1:NEQ)\n CALL eqmotion1(X + H,W,AK)\n\n YN(1:NEQ) = YN(1:NEQ) + DCMPLX( H * C4 ) * AK(1:NEQ)\n\n RETURN\n END\n", "meta": {"hexsha": "fea6e447bd77964b630a25f9e3fc538231d4d7cd", "size": 3195, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "dsmpy/src_f90/tipsv/rk3.f90", "max_stars_repo_name": "seismobassoon/dsmpy", "max_stars_repo_head_hexsha": "4290269ff0998549a2eec25ed090417f8cf1bad7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "dsmpy/src_f90/tipsv/rk3.f90", "max_issues_repo_name": "seismobassoon/dsmpy", "max_issues_repo_head_hexsha": "4290269ff0998549a2eec25ed090417f8cf1bad7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "dsmpy/src_f90/tipsv/rk3.f90", "max_forks_repo_name": "seismobassoon/dsmpy", "max_forks_repo_head_hexsha": "4290269ff0998549a2eec25ed090417f8cf1bad7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.4444444444, "max_line_length": 70, "alphanum_fraction": 0.4303599374, "num_tokens": 1069, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.656686094822646}} {"text": "module inv\n implicit none\n\n integer, parameter :: DP=8\n\ncontains\n\n!\n\nsubroutine invert(Da,Df,Dx,ndim,ipar)\n \n !\n \n ! This subroutine performs the direct inversion of a NxN system.\n ! \n ! If the parameter ipar=0, then only factorization of matrix A is performed. \n ! For ipar=1, the vector x is calculated using the factorized matrix A. \n ! For ipar=2, LAPACK routine DGESV is used to solve the dense linear system Ax=f. \n ! In addition, for NDIM=2,3,4 explicit formulas are employed to replace the\n ! more expensive LAPACK routine.\n ! \n\n !\n\n\n !\n\n real(DP), dimension(ndim), intent(IN) :: Df\n integer, intent(IN) :: ndim,ipar\n\n !\n\n\n !\n \n real(DP), dimension(ndim,ndim), intent(INOUT) :: Da\n\n !\n\n\n !\n \n real(DP), dimension(ndim), intent(OUT) :: Dx\n \n !\n\n!\n\n\n ! local variables\n real(DP), dimension(ndim,ndim) :: Db\n real(DP), dimension(ndim) :: Dpiv\n integer, dimension(ndim) :: Kindx,Kindy\n \n real(DP) :: dpivot,daux\n integer :: idim1,idim2,idim3,ix,iy,indx,indy,info\n \n select case (ipar)\n case (0)\n ! Perform factorization of matrix Da\n \n ! Initialization\n Kindx=0; Kindy=0\n \n do idim1=1,ndim\n \n ! Determine pivotal element\n dpivot=0\n \n do iy=1,ndim\n if (Kindy(iy) /= 0) cycle\n \n do ix=1,ndim\n if (Kindx(ix) /= 0) cycle\n \n if (abs(Da(ix,iy)) .le. abs(dpivot)) cycle\n dpivot=Da(ix,iy); indx=ix; indy=iy\n end do\n end do\n \n ! Return if pivotal element is zero\n if (abs(dpivot) .le. 0._DP) return\n \n Kindx(indx)=indy; Kindy(indy)=indx; Da(indx,indy)=1._DP/dpivot\n \n do idim2=1,ndim\n if (idim2 == indy) cycle \n Da(1:indx-1, idim2)=Da(1:indx-1, idim2)-Da(1:indx-1, indy)*Da(indx,idim2)/dpivot\n Da(indx+1:ndim,idim2)=Da(indx+1:ndim,idim2)-Da(indx+1:ndim,indy)*Da(indx,idim2)/dpivot\n end do\n \n do ix=1,ndim\n if (ix /= indx) Da(ix,indy)=Da(ix,indy)/dpivot\n end do\n \n do iy=1,ndim\n if (iy /= indy) Da(indx,iy)=-Da(indx,iy)/dpivot\n end do\n end do\n \n do ix=1,ndim\n if (Kindx(ix) == ix) cycle\n \n do iy=1,ndim\n if (Kindx(iy) == ix) exit\n end do\n \n do idim1=1,ndim\n daux=Da(ix,idim1); Da(ix,idim1)=Da(iy,idim1); Da(iy,idim1)=daux\n end do\n \n Kindx(iy)=Kindx(ix); Kindx(ix)=ix\n end do\n \n do ix=1,ndim\n if (Kindy(ix) == ix) cycle\n \n do iy=1,ndim\n if (Kindy(iy) == ix) exit\n end do\n \n do idim1=1,ndim\n daux=Da(idim1,ix); Da(idim1,ix)=Da(idim1,iy); Da(idim1,iy)=daux\n end do\n \n Kindy(iy)=Kindy(ix); Kindy(ix)=ix\n end do\n \n\n case (1) \n ! Perform inversion of Da to solve the Da * Dx = Df\n do idim1=1,ndim\n Dx(idim1)=0\n do idim2=1,ndim\n Dx(idim1)=Dx(idim1)+Da(idim1,idim2)*Df(idim2)\n end do\n end do\n\n case (2)\n ! Solve the dense linear system Ax=f calling LAPACK routine\n \n select case(ndim)\n case (2)\n ! Explicit formula for 2x2 system\n Db(1,1)= Da(2,2)\n Db(2,1)=-Da(2,1)\n Db(1,2)=-Da(1,2)\n Db(2,2)= Da(1,1)\n daux=Da(1,1)*Da(2,2)-Da(1,2)*Da(2,1)\n Dx=matmul(Db,Df)/daux\n \n case (3)\n ! Explicit formula for 3x3 system\n Db(1,1)=Da(2,2)*Da(3,3)-Da(2,3)*Da(3,2)\n Db(2,1)=Da(2,3)*Da(3,1)-Da(2,1)*Da(3,3)\n Db(3,1)=Da(2,1)*Da(3,2)-Da(2,2)*Da(3,1)\n Db(1,2)=Da(1,3)*Da(3,2)-Da(1,2)*Da(3,3)\n Db(2,2)=Da(1,1)*Da(3,3)-Da(1,3)*Da(3,1)\n Db(3,2)=Da(1,2)*Da(3,1)-Da(1,1)*Da(3,2)\n Db(1,3)=Da(1,2)*Da(2,3)-Da(1,3)*Da(2,2)\n Db(2,3)=Da(1,3)*Da(2,1)-Da(1,1)*Da(2,3)\n Db(3,3)=Da(1,1)*Da(2,2)-Da(1,2)*Da(2,1)\n daux=Da(1,1)*Da(2,2)*Da(3,3)+Da(2,1)*Da(3,2)*Da(1,3)+ &\n Da(3,1)*Da(1,2)*Da(2,3)-Da(1,1)*Da(3,2)*Da(2,3)- &\n Da(3,1)*Da(2,2)*Da(1,3)-Da(2,1)*Da(1,2)*Da(3,3)\n Dx=matmul(Db,Df)/daux\n\n case (4)\n ! Explicit formula for 4x4 system\n Db(1,1)=Da(2,2)*Da(3,3)*Da(4,4)+Da(2,3)*Da(3,4)*Da(4,2)+Da(2,4)*Da(3,2)*Da(4,3)- &\n Da(2,2)*Da(3,4)*Da(4,3)-Da(2,3)*Da(3,2)*Da(4,4)-Da(2,4)*Da(3,3)*Da(4,2)\n Db(2,1)=Da(2,1)*Da(3,4)*Da(4,3)+Da(2,3)*Da(3,1)*Da(4,4)+Da(2,4)*Da(3,3)*Da(4,1)- &\n Da(2,1)*Da(3,3)*Da(4,4)-Da(2,3)*Da(3,4)*Da(4,1)-Da(2,4)*Da(3,1)*Da(4,3)\n Db(3,1)=Da(2,1)*Da(3,2)*Da(4,4)+Da(2,2)*Da(3,4)*Da(4,1)+Da(2,4)*Da(3,1)*Da(4,2)- &\n Da(2,1)*Da(3,4)*Da(4,2)-Da(2,2)*Da(3,1)*Da(4,4)-Da(2,4)*Da(3,2)*Da(4,1)\n Db(4,1)=Da(2,1)*Da(3,3)*Da(4,2)+Da(2,2)*Da(3,1)*Da(4,3)+Da(2,3)*Da(3,2)*Da(4,1)- &\n Da(2,1)*Da(3,2)*Da(4,3)-Da(2,2)*Da(3,3)*Da(4,1)-Da(2,3)*Da(3,1)*Da(4,2)\n Db(1,2)=Da(1,2)*Da(3,4)*Da(4,3)+Da(1,3)*Da(3,2)*Da(4,4)+Da(1,4)*Da(3,3)*Da(4,2)- &\n Da(1,2)*Da(3,3)*Da(4,4)-Da(1,3)*Da(3,4)*Da(4,2)-Da(1,4)*Da(3,2)*Da(4,3)\n Db(2,2)=Da(1,1)*Da(3,3)*Da(4,4)+Da(1,3)*Da(3,4)*Da(4,1)+Da(1,4)*Da(3,1)*Da(4,3)- &\n Da(1,1)*Da(3,4)*Da(4,3)-Da(1,3)*Da(3,1)*Da(4,4)-Da(1,4)*Da(3,3)*Da(4,1)\n Db(3,2)=Da(1,1)*Da(3,4)*Da(4,2)+Da(1,2)*Da(3,1)*Da(4,4)+Da(1,4)*Da(3,2)*Da(4,1)- &\n Da(1,1)*Da(3,2)*Da(4,4)-Da(1,2)*Da(3,4)*Da(4,1)-Da(1,4)*Da(3,1)*Da(4,2)\n Db(4,2)=Da(1,1)*Da(3,2)*Da(4,3)+Da(1,2)*Da(3,3)*Da(4,1)+Da(1,3)*Da(3,1)*Da(4,2)- &\n Da(1,1)*Da(3,3)*Da(4,2)-Da(1,2)*Da(3,1)*Da(4,3)-Da(1,3)*Da(3,2)*Da(4,1)\n Db(1,3)=Da(1,2)*Da(2,3)*Da(4,4)+Da(1,3)*Da(2,4)*Da(4,2)+Da(1,4)*Da(2,2)*Da(4,3)- &\n Da(1,2)*Da(2,4)*Da(4,3)-Da(1,3)*Da(2,2)*Da(4,4)-Da(1,4)*Da(2,3)*Da(4,2)\n Db(2,3)=Da(1,1)*Da(2,4)*Da(4,3)+Da(1,3)*Da(2,1)*Da(4,4)+Da(1,4)*Da(2,3)*Da(4,1)- &\n Da(1,1)*Da(2,3)*Da(4,4)-Da(1,3)*Da(2,4)*Da(4,1)-Da(1,4)*Da(2,1)*Da(4,3)\n Db(3,3)=Da(1,1)*Da(2,2)*Da(4,4)+Da(1,2)*Da(2,4)*Da(4,1)+Da(1,4)*Da(2,1)*Da(4,2)- &\n Da(1,1)*Da(2,4)*Da(4,2)-Da(1,2)*Da(2,1)*Da(4,4)-Da(1,4)*Da(2,2)*Da(4,1)\n Db(4,3)=Da(1,1)*Da(2,3)*Da(4,2)+Da(1,2)*Da(2,1)*Da(4,3)+Da(1,3)*Da(2,2)*Da(4,1)- &\n Da(1,1)*Da(2,2)*Da(4,3)-Da(1,2)*Da(2,3)*Da(4,1)-Da(1,3)*Da(2,1)*Da(4,2)\n Db(1,4)=Da(1,2)*Da(2,4)*Da(3,3)+Da(1,3)*Da(2,2)*Da(3,4)+Da(1,4)*Da(2,3)*Da(3,2)- &\n Da(1,2)*Da(2,3)*Da(3,4)-Da(1,3)*Da(2,4)*Da(3,2)-Da(1,4)*Da(2,2)*Da(3,3)\n Db(2,4)=Da(1,1)*Da(2,3)*Da(3,4)+Da(1,3)*Da(2,4)*Da(3,1)+Da(1,4)*Da(2,1)*Da(3,3)- &\n Da(1,1)*Da(2,4)*Da(3,3)-Da(1,3)*Da(2,1)*Da(3,4)-Da(1,4)*Da(2,3)*Da(3,1)\n Db(3,4)=Da(1,1)*Da(2,4)*Da(3,2)+Da(1,2)*Da(2,1)*Da(3,4)+Da(1,4)*Da(2,2)*Da(3,1)- &\n Da(1,1)*Da(2,2)*Da(3,4)-Da(1,2)*Da(2,4)*Da(3,1)-Da(1,4)*Da(2,1)*Da(3,2)\n Db(4,4)=Da(1,1)*Da(2,2)*Da(3,3)+Da(1,2)*Da(2,3)*Da(3,1)+Da(1,3)*Da(2,1)*Da(3,2)- &\n Da(1,1)*Da(2,3)*Da(3,2)-Da(1,2)*Da(2,1)*Da(3,3)-Da(1,3)*Da(2,2)*Da(3,1)\n daux=Da(1,1)*Da(2,2)*Da(3,3)*Da(4,4)+Da(1,1)*Da(2,3)*Da(3,4)*Da(4,2)+Da(1,1)*Da(2,4)*Da(3,2)*Da(4,3)+ &\n Da(1,2)*Da(2,1)*Da(3,4)*Da(4,3)+Da(1,2)*Da(2,3)*Da(3,1)*Da(4,4)+Da(1,2)*Da(2,4)*Da(3,3)*Da(4,1)+ &\n Da(1,3)*Da(2,1)*Da(3,2)*Da(4,4)+Da(1,3)*Da(2,2)*Da(3,4)*Da(4,1)+Da(1,3)*Da(2,4)*Da(3,1)*Da(4,2)+ &\n Da(1,4)*Da(2,1)*Da(3,3)*Da(4,2)+Da(1,4)*Da(2,2)*Da(3,1)*Da(4,3)+Da(1,4)*Da(2,3)*Da(3,2)*Da(4,1)- &\n Da(1,1)*Da(2,2)*Da(3,4)*Da(4,3)-Da(1,1)*Da(2,3)*Da(3,2)*Da(4,4)-Da(1,1)*Da(2,4)*Da(3,3)*Da(4,2)- &\n Da(1,2)*Da(2,1)*Da(3,3)*Da(4,4)-Da(1,2)*Da(2,3)*Da(3,4)*Da(4,1)-Da(1,2)*Da(2,4)*Da(3,1)*Da(4,3)- &\n Da(1,3)*Da(2,1)*Da(3,4)*Da(4,2)-Da(1,3)*Da(2,2)*Da(3,1)*Da(4,4)-Da(1,3)*Da(2,4)*Da(3,2)*Da(4,1)- &\n Da(1,4)*Da(2,1)*Da(3,2)*Da(4,3)-Da(1,4)*Da(2,2)*Da(3,3)*Da(4,1)-Da(1,4)*Da(2,3)*Da(3,1)*Da(4,2)\n Dx=matmul(Db,Df)/daux\n \n case DEFAULT\n ! Use LAPACK routine for general NxN system, where N>4\n Dpiv=0; Dx=Df\n call DGESV(ndim,1,Da,ndim,Dpiv,Dx,ndim,info)\n\n end select\n end select\nend subroutine invert\n\nend module inv\n", "meta": {"hexsha": "96af97cf675c3322fc59e7e5a2d64046dba71def", "size": 8294, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "incoming/invert/invert.f90", "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": "incoming/invert/invert.f90", "max_issues_repo_name": "tudo-math-ls3/FeatFlow2", "max_issues_repo_head_hexsha": "56159aff28f161aca513bc7c5e2014a2d11ff1b3", "max_issues_repo_licenses": ["Intel", "Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "incoming/invert/invert.f90", "max_forks_repo_name": "tudo-math-ls3/FeatFlow2", "max_forks_repo_head_hexsha": "56159aff28f161aca513bc7c5e2014a2d11ff1b3", "max_forks_repo_licenses": ["Intel", "Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.3603603604, "max_line_length": 111, "alphanum_fraction": 0.4798649626, "num_tokens": 4210, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523148, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6566860897376581}} {"text": "C ******************** CFLPECNUMBER ****************************************\nC to calculate the CFL number CFL = Deltat * sup(surface/volume) * sup(dF/du)\nC where F is the function of the advection equation u_t + div(F(u))=0\nC In this case F is a linear function F(u)= v*u\nC and to calculate the Peclet number Pec = CFL/gamma where gamma is the\nC diffusion number gamma=Deltat*sup(|D|/volume)\nC supdiffus is equal to sup (|D|/volume) \nC **********************************************************************\nC \n subroutine cflpecnumber(NTETRA,DELTATADV,VOLUR,SURFAR,\n 1 VX,VY,VZ,SUPDIFFUS,cflinp,CFLNUMB,PECNUMB,\n 2 CFLTETRA,NADV,nadvfl,DELTAT)\n\n implicit none\nC\n integer ntetra\n integer j, cfltetra, nadv,nadvfl\n real*8 deltat,deltatadv\n real*8 volur(ntetra),surfar(ntetra)\n real*8 vx(ntetra),vy(ntetra),vz(ntetra)\n real*8 cflinp,cflnumb,pecnumb,supdiffus\n real*8 supcfl,supcflt\n \n cfltetra=1\n supcfl= surfar(1)*volur(1)*\n 1 dsqrt(vx(1)**2+vy(1)**2+vz(1)**2)\nc write(999,*)surfar(1),volur(1)\n do j=2,ntetra\n supcflt= surfar(j)*volur(j)*\n 1 dsqrt(vx(j)**2+vy(j)**2+vz(j)**2)\n if (supcflt.gt.supcfl) then\n supcfl=supcflt\n cfltetra=j\n end if \nc write(999,*)surfar(j),volur(j)\n end do\n if (nadvfl.eq.1) then\n deltatadv=deltat/float(nadv)\n cflnumb=deltatadv*supcfl\n else if(nadvfl.eq.0) then\n deltatadv= cflinp/supcfl\n nadv=max(int(deltat/deltatadv)+1,2)\n deltatadv= deltat/nadv\n cflnumb=deltatadv*supcfl\n else\n write(6,*) 'wrong value for nadvfl ',nadvfl\n stop\n end if\n if (supdiffus.eq.0.0d0) then\n pecnumb=1.e+20\n else\n pecnumb=cflnumb/(supdiffus*deltatadv)\n end if\n \n return \n end\n \n", "meta": {"hexsha": "2e9d11c26822ffa9cb34c72529274dc9dc02a65e", "size": 1934, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "examples/weil_exemple_withDA/my_cathy_prj/src/cflpecnumber.f", "max_stars_repo_name": "BenjMy/pycathy_wrapper", "max_stars_repo_head_hexsha": "8639713acbb5bc5c5cd293b94bdafe017d03f199", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "examples/weil_exemple_withDA/my_cathy_prj/src/cflpecnumber.f", "max_issues_repo_name": "BenjMy/pycathy_wrapper", "max_issues_repo_head_hexsha": "8639713acbb5bc5c5cd293b94bdafe017d03f199", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2021-10-14T13:07:46.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-02T03:32:05.000Z", "max_forks_repo_path": "examples/weil_exemple_withDA/my_cathy_prj/src/cflpecnumber.f", "max_forks_repo_name": "BenjMy/pycathy_wrapper", "max_forks_repo_head_hexsha": "8639713acbb5bc5c5cd293b94bdafe017d03f199", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.3448275862, "max_line_length": 79, "alphanum_fraction": 0.544467425, "num_tokens": 657, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6566860890676561}} {"text": "! Program to compare timings between bml wrapper to dgemms\n! and dgemms standalone.\n\nprogram main\n\n use bml\n\n implicit none\n integer, parameter :: dp = kind(1.0d0)\n character(20) :: bml_type\n integer :: hdim, i, j, mdim\n real(8) :: mls, mlsI\n real(dp) :: alpha, beta, numthresh\n real(dp), allocatable :: aux(:,:), diff(:,:), h(:,:), trace(:)\n real(dp), allocatable :: x2(:,:)\n type(bml_matrix_t) :: hmat_bml, x2_bml\n\n write(*,*)''\n write(*,*)'Example BML 4: Construct a random matrix;'\n write(*,*)'multiply the matrix by itself and compare times to dgemm'\n write(*,*)''\n\n hdim = 4000\n mdim = 4000\n bml_type = \"dense\"\n numthresh = 0.0_dp\n alpha = 1.0_dp\n beta = 0.0_dp\n\n allocate(h(hdim,hdim))\n allocate(aux(hdim,hdim))\n allocate(diff(hdim,hdim))\n allocate(x2(hdim,hdim))\n\n H=0.0_dp\n\n call bml_random_matrix(bml_type, bml_element_real, dp, hdim, mdim, hmat_bml)\n call bml_export_to_dense(hmat_bml,H)\n call bml_copy_new(hmat_bml,x2_bml)\n\n !With BML wrapper to dgemm\n mlsI = mls()\n call bml_multiply_x2(hmat_bml, x2_bml, numthresh, trace)\n write(*,*)\"Time for x2 bml dense=\", mls()-mlsI\n\n call bml_export_to_dense(x2_bml,x2)\n\n !With dgemm\n mlsI = mls()\n call MMult(alpha,h,h,beta,aux,'N','N',hdim)\n write(*,*)\"Time for x2 dgemm=\", mls()-mlsI\n\n !Fnorm to see the difference\n diff = aux - x2\n call bml_import_from_dense(bml_type,diff,hmat_bml,numthresh,mdim)\n\n write(*,*)\"Fnorm difference=\", bml_fnorm(hmat_bml)\n\nend program main\n\n\nsubroutine MMult(alpha,a,b,beta,c,ta,tb,hdim)\n implicit none\n integer, parameter :: dp = kind(1.0d0)\n character(1), intent(in) :: ta, tb\n integer, intent(in) :: hdim\n real(dp), intent(inout) :: a(hdim, hdim), alpha, b(hdim,hdim), beta\n real(dp), intent(inout) :: c(hdim, hdim)\n\n call dgemm(ta, tb, hdim, hdim, hdim, alpha, &\n a, hdim, b, hdim, beta, c, hdim)\n\nend subroutine MMult\n\nfunction mls()\n integer, parameter :: dp = kind(1.0d0)\n real(dp) :: mls\n integer :: timevector(8)\n\n mls = 0.0_dp\n call date_and_time(values=timevector)\n mls=timevector(5)*60.0_dp*60.0_dp*1000.0_dp + timevector(6)*60.0_dp*1000.0_dp &\n + timevector(7)*1000.0_dp + timevector(8)\n\nend function mls\n", "meta": {"hexsha": "721c80081443fc6eb6c3dde2d8255e5badff9c58", "size": 2261, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/example3/main.f90", "max_stars_repo_name": "mikiec84/bml", "max_stars_repo_head_hexsha": "b26c6902dd79785edc2008ff4d054ea288037469", "max_stars_repo_licenses": ["Unlicense", "BSD-3-Clause"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2017-11-10T02:20:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T07:10:53.000Z", "max_issues_repo_path": "examples/example3/main.f90", "max_issues_repo_name": "mikiec84/bml", "max_issues_repo_head_hexsha": "b26c6902dd79785edc2008ff4d054ea288037469", "max_issues_repo_licenses": ["Unlicense", "BSD-3-Clause"], "max_issues_count": 408, "max_issues_repo_issues_event_min_datetime": "2017-07-27T05:01:47.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-23T23:03:02.000Z", "max_forks_repo_path": "examples/example3/main.f90", "max_forks_repo_name": "mikiec84/bml", "max_forks_repo_head_hexsha": "b26c6902dd79785edc2008ff4d054ea288037469", "max_forks_repo_licenses": ["Unlicense", "BSD-3-Clause"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2017-06-21T20:38:32.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T07:10:51.000Z", "avg_line_length": 26.2906976744, "max_line_length": 81, "alphanum_fraction": 0.6395400265, "num_tokens": 818, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045817875224, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6566860802376837}} {"text": "program P1407\n implicit none\n integer(8) :: a, b\n integer(8) :: sum\n integer :: shift = 0\n read *, a, b\n a = a - 1\n sum = b - a\n a = rshift(a, 1)\n b = rshift(b, 1)\n do while (b > 0)\n sum = sum + lshift(b - a, shift)\n a = rshift(a, 1)\n b = rshift(b, 1)\n shift = shift + 1\n end do\n write (*, '(I0)') sum\nend program P1407\n", "meta": {"hexsha": "f52be67ab27585909be3f3f930b8161ea8e7aebf", "size": 384, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "P1407.f95", "max_stars_repo_name": "daily-boj/kiwiyou", "max_stars_repo_head_hexsha": "ceca96ddfee95708871af67d1682048e0bed0257", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-04-08T09:04:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-16T07:30:24.000Z", "max_issues_repo_path": "P1407.f95", "max_issues_repo_name": "daily-boj/kiwiyou", "max_issues_repo_head_hexsha": "ceca96ddfee95708871af67d1682048e0bed0257", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "P1407.f95", "max_forks_repo_name": "daily-boj/kiwiyou", "max_forks_repo_head_hexsha": "ceca96ddfee95708871af67d1682048e0bed0257", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-04-16T05:32:06.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-28T13:40:56.000Z", "avg_line_length": 20.2105263158, "max_line_length": 40, "alphanum_fraction": 0.4609375, "num_tokens": 148, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744939732856, "lm_q2_score": 0.8031738010682209, "lm_q1q2_score": 0.656654413980951}} {"text": "module module1\nimplicit none\n\ncontains\n\nfunction myadd(a, b)\nreal(8) myadd\nreal(8) a, b\nmyadd=a + b\nend function myadd\n\nsubroutine mytrig(x, sinx, cosx, tanx)\nreal(8) x\nreal(8) sinx, cosx, tanx\nsinx = sin(x)\ncosx = cos(x)\ntanx = tan(x)\nend subroutine mytrig\n\nend module module1", "meta": {"hexsha": "a9cdc5c5c2f5a70bf745c3ad12ae00e2cf57138a", "size": 277, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "cnd/cnd.modelimpl/test/unit/data/org/netbeans/modules/cnd/modelimpl/trace/FortranFileModelTest/bug212602.f", "max_stars_repo_name": "leginee/netbeans", "max_stars_repo_head_hexsha": "814ad30e2d0a094f4aa3813bcbb5323a95a0b1d6", "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": "cnd/cnd.modelimpl/test/unit/data/org/netbeans/modules/cnd/modelimpl/trace/FortranFileModelTest/bug212602.f", "max_issues_repo_name": "leginee/netbeans", "max_issues_repo_head_hexsha": "814ad30e2d0a094f4aa3813bcbb5323a95a0b1d6", "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": "cnd/cnd.modelimpl/test/unit/data/org/netbeans/modules/cnd/modelimpl/trace/FortranFileModelTest/bug212602.f", "max_forks_repo_name": "leginee/netbeans", "max_forks_repo_head_hexsha": "814ad30e2d0a094f4aa3813bcbb5323a95a0b1d6", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 13.85, "max_line_length": 38, "alphanum_fraction": 0.7184115523, "num_tokens": 105, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8031738057795402, "lm_q2_score": 0.8175744673038222, "lm_q1q2_score": 0.6566543964125912}} {"text": "! 2017 / 09 /10 version 1.1 \n! -----------------------------------------------------------------------------\n! The ELEMENTAL attribute allows for declaring procedures that operate element\n! by element(rank insensitive code) and can be applied to arrays of any dimensions(up to 16D so far). \n! CAUTION :\n! In a simplified model, we leave off implicit none, private, public\n! -----------------------------------------------------------------------------\nmodule mod1\n contains\n\n elemental function contract(a,b) result(c)\n integer, intent(in) :: a, b\n integer :: c\n c = a - b\n end function \n\n elemental subroutine elesub1(a, b, c)\n integer, intent(in) :: a, b\n integer, intent(out) :: c\n c = a - b\n end subroutine elesub1\n\n subroutine elesub2(a, b, c)\n integer, intent(in) :: a, b\n integer, intent(out) :: c\n c = a - b\n end subroutine elesub2\nend module mod1\n\n\nprogram prog1\n use mod1\n integer :: i, j, k, ia(3), ib(3), ic(3)\n i = 0\n j = -1\n ia = [1, 2, 3]\n ib = [4, 5, 6]\n\n write (*,*) contract(i, j)\n write (*,*) contract(i, ia)\n write (*,*) contract(ib, i)\n write (*,*) contract(ia, ib)\n\n call elesub1(i, j, k)\n write(*,*) k\n call elesub1(ia, j, ic)\n write(*,*) ic\n call elesub1(ia, ib, ic)\n write(*,*) ic\n\n ! call elesub2(ia, j, ic)\n ! 1\n ! Error: Rank mismatch in argument \u2018a\u2019 at (1) (scalar and rank-1)\n\n !write(*,*) ic\nend program prog1\n", "meta": {"hexsha": "2e877c9535d001f5fc235c2cf1eea0b4babe973e", "size": 1516, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "modern_fotran/NewAttribute/elemental_procedure.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/NewAttribute/elemental_procedure.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/NewAttribute/elemental_procedure.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": 26.5964912281, "max_line_length": 102, "alphanum_fraction": 0.4986807388, "num_tokens": 437, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936435, "lm_q2_score": 0.8031737940012417, "lm_q1q2_score": 0.6566543939230265}} {"text": "! 5.14\u0431 \u0432 \u0443\u0447\u0435\u0431\u043d\u0438\u043a\u0435\n! \u041d\u0430\u0439\u0442\u0438 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435\n\nprogram ex_5_14b\n implicit none\n integer :: arrayLength, Out = 0, In = 0, i = 0 \n integer, allocatable :: X(:), Indexes(:), NegativeIndexes(:)\n logical, allocatable :: mask(:)\n character(*), parameter :: output_file = \"output.txt\", &\n input_file = \"../data/input.txt\"\n\n open (file=input_file, newunit=In)\n read(In, *) arrayLength\n allocate(X(arrayLength))\n read(In, *) X(:)\n close (In)\n\n Indexes = [(i, i = 1, arrayLength)]\n mask = X < 0\n\n NegativeIndexes = pack(Indexes, mask)\n\n open (file=output_file, newunit=Out)\n write(Out,*) 'Negative indexes'\n write(Out,*) NegativeIndexes\n close (Out)\n\nend program ex_5_14b\n", "meta": {"hexsha": "9ecffd157b6313e89c56b7869a771bc82dc65413", "size": 799, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ex_5_14b/src/ex_5_14b.f90", "max_stars_repo_name": "taxnuke/algorithm-exercises", "max_stars_repo_head_hexsha": "5dae749093489d0e66a74bd8bc3b2040496449bf", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-06-01T06:06:44.000Z", "max_stars_repo_stars_event_max_datetime": "2017-06-01T09:16:17.000Z", "max_issues_repo_path": "ex_5_14b/src/ex_5_14b.f90", "max_issues_repo_name": "taxnuke/algorithm-exercises", "max_issues_repo_head_hexsha": "5dae749093489d0e66a74bd8bc3b2040496449bf", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ex_5_14b/src/ex_5_14b.f90", "max_forks_repo_name": "taxnuke/algorithm-exercises", "max_forks_repo_head_hexsha": "5dae749093489d0e66a74bd8bc3b2040496449bf", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.5517241379, "max_line_length": 67, "alphanum_fraction": 0.5744680851, "num_tokens": 233, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737775116229, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.6566543768714995}} {"text": "C LAST UPDATE 07/08/95\nC+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\nC\n REAL FUNCTION VGTINT(A1,A3,A4)\n IMPLICIT NONE\nC\nC Purpose: Y(X;A) is a Voigtian. The amplitude. centre and widths of \nC the Voigtian are stored in consecutive locations of A: \nC A(1) = H, A(2) = E, A(3) = G, A(4) = P\nC This function returns the integrated area under the curve.\nC\nC-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-\nC Parameters:\nC\n DOUBLE PRECISION TINY,FACTOR\n PARAMETER(TINY=1.0D-10,FACTOR=1.66510922231D0)\nC\nC Arguments:\nC\n DOUBLE PRECISION A1,A3,A4\nC\nC Local variables:\nC\n INTEGER I\n DOUBLE PRECISION PI,PMA,PMA2,RM,RN,RA,RB,RC,SUM,W,P\n DOUBLE PRECISION ALPHA(4),BETA(4),GAMMA(4),DELTA(4)\nC\nC Common block:\nC\n DOUBLE PRECISION VCOM\n COMMON /VGTCOM/ VCOM\n SAVE /VGTCOM/\nC\nC Data:\nC\n DATA PI /3.1415926536D0/\n DATA ALPHA /-1.2150D0,-1.3509D0,-1.2150D0,-1.3509D0/,\n & BETA / 1.2359D0, 0.3786D0,-1.2359D0,-0.3786D0/,\n & GAMMA /-0.3085D0, 0.5906D0,-0.3085D0, 0.5906D0/,\n & DELTA / 0.0210D0,-1.1858D0,-0.0210D0, 1.1858D0/\nC\nC-----------------------------------------------------------------------\n IF(A3.LT.TINY)A3 = TINY\n W = A3/FACTOR\n P = A4/2.0D0\n SUM = 0.0D0\n RC = 1.0D0\n DO 10 I=1,4\n PMA = P - ALPHA(I)\n PMA2 = PMA*PMA\n RB = -BETA(I)\n RM = DELTA(I)\n RN = GAMMA(I)*PMA + DELTA(I)*RB\n RA = PMA2 + RB*RB\n SUM = SUM + (RN*RC-RM*RB)/(RC*SQRT(RA*RC-RB*RB))\n 10 CONTINUE\n SUM = SUM*PI*A1*W/VCOM\n VGTINT = SNGL(SUM)\nC\n RETURN\n END\n \n", "meta": {"hexsha": "95bb555f1fcd09303ddc9e3459493b3eb92c8ebd", "size": 1707, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "software/guifix/VGTINT.f", "max_stars_repo_name": "scattering-central/CCP13", "max_stars_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "software/guifix/VGTINT.f", "max_issues_repo_name": "scattering-central/CCP13", "max_issues_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "software/guifix/VGTINT.f", "max_forks_repo_name": "scattering-central/CCP13", "max_forks_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-09-05T15:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-15T11:13:45.000Z", "avg_line_length": 27.0952380952, "max_line_length": 72, "alphanum_fraction": 0.4932630346, "num_tokens": 645, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.921921834855049, "lm_q2_score": 0.7122321781307374, "lm_q1q2_score": 0.6566223965050975}} {"text": "program test_diffusion1d\n!! Need program statement for FORD\n!! Solve a time-dependent heat equation in 1D. See GEMINI-docs repo for\n!! a description of the specific problem solved here\n\nuse phys_consts, only : wp,pi\nuse PDEparabolic, only : backEuler1D,TRBDF21D\nuse h5fortran, only : hdf5_file\n\nimplicit none (type, external)\n\ntype(hdf5_file) :: h5f\ninteger, parameter :: npts=256,lt=20*5\n\ncharacter(:), allocatable :: outfile\ncharacter(1024) :: argv\n\ncharacter(4) :: ic\n\nreal(wp), dimension(npts) :: v1,dx1i\nreal(wp), dimension(-1:npts+2) :: x1,TsEuler,TsBDF2,Tstrue\nreal(wp), dimension(npts) :: lambda,A,B,C,D,E\nreal(wp), dimension(npts+1) :: x1i\nreal(wp), dimension(0:npts+2) :: dx1\ninteger :: lx1,it,ix1,ierr\nreal(wp) :: t=0,dt\nreal(wp) :: Tsminx1,Tsmaxx1\n\nreal(wp), dimension(npts) :: errorEuler,errorBDF2\nreal(wp), dimension(npts,3) :: abc\nreal(wp), dimension(npts) :: y\n\n!! create a grid for the calculation\nx1=[ (real(ix1-1,wp)/real(npts-1,wp), ix1=-1,npts+2) ]\nlx1=npts !exclude ghost cells in count\ndx1=x1(0:lx1+2)-x1(-1:lx1+1)\nx1i(1:lx1+1)=0.5*(x1(0:lx1)+x1(1:lx1+1))\ndx1i=x1i(2:lx1+1)-x1i(1:lx1)\n\ncall get_command_argument(1, argv, status=ierr)\nif(ierr/=0) error stop 'please specify input filename'\noutfile = trim(argv)\n\n!! write the time, space length and spatial grid to a file\n! open(newunit=u,file=outfile,status='replace')\n! write(u,*) lt\n! write(u,*) lx1\n! call writearray(u,x1)\ncall h5f%open(outfile, action='w')\ncall h5f%write('/lt', lt, ierr)\ncall h5f%write('/lx1', lx1, ierr)\ncall h5f%write('/x1', x1, ierr)\n\n!! initial conditions\nTsEuler(-1:lx1+2)=sin(2*pi*x1(-1:lx1+2))+sin(8*pi*x1(-1:lx1+2))\nTsBDF2=TsEuler\nlambda(:)=1 !thermal conductivity\n\n\n!! typical diffusion time, make our time step a fraction of this\ndt=0.05/8**2/pi**2/maxval(lambda)\n\n\n!! time iterations\ndo it=1,lt\n write(ic, '(I4.4)') it\n !boundary values\n Tsminx1=0.0\n Tsmaxx1=0.0\n\n !solve using two different numerical schemes\n A(:)=0\n B(:)=0\n C(:)=1\n D(:)=lambda(:)\n E(:)=0.0\n TsEuler(1:lx1)=backEuler1D(TsEuler(1:lx1),A,B,C,D,E,Tsminx1,Tsmaxx1,dt,dx1,dx1i,coeffs=abc,rhs=y)\n TsBDF2(1:lx1)=TRBDF21D(TsBDF2(1:lx1),A,B,C,D,E,Tsminx1,Tsmaxx1,dt,dx1,dx1i)\n t=t+dt\n\n !compute analytical solution to compare\n Tstrue(1:lx1) = exp(-4 *pi**2*lambda*t)*sin(2 *pi*x1(1:lx1))+exp(-64 *pi**2*lambda*t)*sin(8 *pi*x1(1:lx1))\n\n !! output\n ! write(u,*) t\n ! call writearray(u,TsEuler(1:lx1))\n ! call writearray(u,TsBDF2(1:lx1))\n ! call writearray(u,Tstrue(1:lx1))\n call h5f%write('/t'//ic, t, ierr)\n call h5f%write('/TsEuler'//ic, TsEuler(1:lx1), ierr)\n call h5f%write('/TsBDF2'//ic, TsBDF2(1:lx1), ierr)\n call h5f%write('/TsTrue'//ic, Tstrue(1:lx1), ierr)\n call h5f%write('/coeffs'//ic,abc,ierr)\n call h5f%write('/rhs'//ic,y,ierr)\n\n !check the validity of the numerical solutions at this time step\n errorEuler(1:lx1)=TsEuler(1:lx1)-Tstrue(1:lx1)\n errorBDF2(1:lx1)=TsBDF2(1:lx1)-Tstrue(1:lx1)\n if (mod(it,5) == 0) then\n print*, 'At time step: ',it,' max error: ',maxval(abs(errorEuler)),maxval(abs(errorBDF2))\n end if\n if (maxval(abs(errorEuler)) > 0.05_wp) then !more that 5% error at a point means something really bad happened...\n print*, 'Time step: ',it,dt\n error stop 'Excessive error (large max diff) in backward Euler solution, check time step maybe???'\n end if\n if (maxval(abs(errorBDF2)) > 0.05_wp) then\n print*, 'Time step: ',it,dt\n error stop 'Excessive error (large max diff) in TRBDF2 solution, check time step maybe???'\n end if\nend do\n\n! close(u)\ncall h5f%close()\n\ncontains\n\n! subroutine writearray(u,array)\n! integer, intent(in) :: u\n! real(wp), dimension(:), intent(in) :: array\n\n! integer :: k\n\n! do k=1,size(array)\n! write(u,*) array(k)\n! end do\n! end subroutine writearray\n\n!\n! subroutine write2Darray(u,array)\n! integer, intent(in) :: u\n! real(wp), dimension(:,:), intent(in) :: array\n!\n! integer :: k1,k2\n!\n! do k1=1,size(array,1)\n! write(u,'(f8.0)') (array(k1,k2), k2=1,size(array,2))\n! end do\n! end subroutine write2Darray\n!\n\nend program\n", "meta": {"hexsha": "7dc6a6cdd174fc29489be558494966b21ca4f87e", "size": 4022, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/numerical/diffusion/test_diffusion1D.f90", "max_stars_repo_name": "scottaiton/gemini3d", "max_stars_repo_head_hexsha": "21f59aabb4d842d587dbeba428ba7353905e063e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2020-09-17T05:08:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-24T18:22:06.000Z", "max_issues_repo_path": "src/numerical/diffusion/test_diffusion1D.f90", "max_issues_repo_name": "scottaiton/gemini3d", "max_issues_repo_head_hexsha": "21f59aabb4d842d587dbeba428ba7353905e063e", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 52, "max_issues_repo_issues_event_min_datetime": "2020-07-23T13:55:59.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-19T13:59:43.000Z", "max_forks_repo_path": "src/numerical/diffusion/test_diffusion1D.f90", "max_forks_repo_name": "scottaiton/gemini3d", "max_forks_repo_head_hexsha": "21f59aabb4d842d587dbeba428ba7353905e063e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2020-08-20T12:07:06.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-14T13:03:04.000Z", "avg_line_length": 28.323943662, "max_line_length": 118, "alphanum_fraction": 0.6688214818, "num_tokens": 1562, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256551882382, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6566180342985876}} {"text": "module precision\n !\n !*Brief Description:* Defines the precision of real parameters.\n !\n !*LICENSE:*\n !\n !\n !\n !*Full Description:*\n ! Defines the precision of real, via a parameter 'dp'.\n implicit none\n \n !Module parameters\n integer, parameter :: dp=kind(0.d0) ! for double precision \n\n real(dp),parameter :: zero_tol = 1.0e-12_dp\n real(dp),parameter :: loose_tol = 1.0e-6_dp\n\n !Module types\n\n !Module variables\n\n !Interfaces\n private\n public dp\n public zero_tol\n public loose_tol\n \nend module precision\n", "meta": {"hexsha": "87ce67dfbc62f6291046cbc86172609907caef89", "size": 529, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/lib/precision.f90", "max_stars_repo_name": "marziaghababaie/lungsim", "max_stars_repo_head_hexsha": "08a21f06f82d6121e0e8a664fc454d8930ce0d94", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-10-18T12:06:55.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-18T12:06:55.000Z", "max_issues_repo_path": "src/lib/precision.f90", "max_issues_repo_name": "marziaghababaie/lungsim", "max_issues_repo_head_hexsha": "08a21f06f82d6121e0e8a664fc454d8930ce0d94", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 75, "max_issues_repo_issues_event_min_datetime": "2016-06-14T22:57:29.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-16T05:01:48.000Z", "max_forks_repo_path": "src/lib/precision.f90", "max_forks_repo_name": "marziaghababaie/lungsim", "max_forks_repo_head_hexsha": "08a21f06f82d6121e0e8a664fc454d8930ce0d94", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 29, "max_forks_repo_forks_event_min_datetime": "2016-06-01T23:16:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T02:31:28.000Z", "avg_line_length": 17.6333333333, "max_line_length": 65, "alphanum_fraction": 0.6786389414, "num_tokens": 151, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7799929002541068, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.6566180312033145}} {"text": "!> @ingroup insertion_sort_gen\n!> \n!> @brief \n!> Run an insertion sort on a vector of double precision values. \n!>\n!> @details \n!> Run the specified on a vector of double precision values to sort them in the specified order.The vector of intergers map is permuted in the same way that the vector vec is permuted to be sorted. It is important that map be at least as long as vec.\n!>\n!> @param vec\n!> The vector double precision values to be sorted.\n!>\n!> @param map\n!> Vector of intergers which is permuted in the same way that vec is permuted. If map is a vector of values 1 to N, where N is the length of vec, than, map is the map from vec's original value to vec's final value after the sort.\n!> \n!> @param ord\n!> A logical function which describes the ordering used. The function must take two double precision arguments and return true if and only if the first argument must proceed the second argument in the order.\n!>\n!> @warning\n!> The argument types and counts of ord are not checked within this subroutine.\n!> \n!> @warning\n!> The length of map is not checked within this subroutine. If the length of vec is larger than the length of map, than this subroutine may attempt to access elements outside of map.\n!> \n!> @author Arin R. Bratt\n!> @date 11/07/2014\nsubroutine insertion_sort_gen_map_dble(vec,map,ord)\n ! Arguments\n double precision, intent(inout) :: vec(:)\n integer, intent(inout) :: map(:)\n procedure(logical) :: ord\n \n ! Variables\n double precision :: double_precision_value\n double precision :: swap_value\n integer :: i\n integer :: j\n \n \n ! Sort to the first element\n if (ord(vec(size(vec,1)),vec(1))) then\n double_precision_value = vec(1)\n else\n double_precision_value = vec(size(vec,1))\n vec(size(vec,1)) = vec(1)\n end if\n \n do i = size(vec,1) - 1,2,-1\n if (ord(double_precision_value,vec(i))) then\n ! Swap double precision values double_precision_value and vec(i).\n swap_value = double_precision_value\n double_precision_value = vec(i)\n vec(i) = swap_value\n end if\n end do\n\n ! Run regualr insertion sort\n do j = 3,size(vec,1)\n swap_value = vec(j)\n i = j - 1\n if (ord(vec(i),swap_value)) then\n vec(j) = vec(i)\n i = i - 1\n do\n if (.not. ord(vec(i),swap_value)) exit\n vec(i + 1) = vec(i)\n i = i - 1\n end do\n vec(i + 1) = swap_value\n end if\n end do\nend subroutine insertion_sort_gen_map_dble\n\n\n", "meta": {"hexsha": "ee686dbb643ceec652e53759524f372cc498cb14", "size": 2461, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/insertion_sort_gen_map_dble.f90", "max_stars_repo_name": "arinrb/bsort", "max_stars_repo_head_hexsha": "17cc0e2cbe52af808bae860d53dd4e4d691f4674", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-11-08T18:36:23.000Z", "max_stars_repo_stars_event_max_datetime": "2015-11-08T18:36:23.000Z", "max_issues_repo_path": "src/insertion_sort_gen_map_dble.f90", "max_issues_repo_name": "arinrb/bsort", "max_issues_repo_head_hexsha": "17cc0e2cbe52af808bae860d53dd4e4d691f4674", "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/insertion_sort_gen_map_dble.f90", "max_forks_repo_name": "arinrb/bsort", "max_forks_repo_head_hexsha": "17cc0e2cbe52af808bae860d53dd4e4d691f4674", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.2567567568, "max_line_length": 250, "alphanum_fraction": 0.6741162129, "num_tokens": 670, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799929002541068, "lm_q2_score": 0.8418256472515683, "lm_q1q2_score": 0.6566180281080414}} {"text": "*----------------------------------------------------------------------*\n integer function ipermfac(ilist,len,ordered)\n*----------------------------------------------------------------------*\n* obtain number of equivalent permutations of list ilist\n* i.e. for each n-tuple of equivalent elements on ilist, we\n* get a factor of n!\n* if ordered==.true., the list is in ordered sequence and\n* equivalent entries come subsequently\n* ... intended for small lists ...\n*----------------------------------------------------------------------*\n \n implicit none\n\n include 'stdunit.h'\n\n integer, parameter ::\n & ntest = 00\n\n logical, intent(in) ::\n & ordered\n integer, intent(in) ::\n & len, ilist(len)\n\n logical ::\n & succ\n integer ::\n & idx, ihlp, iscr(len), ilast, nn\n integer, external ::\n & ifac\n\n ! copy to scratch (do not change input)\n iscr(1:len) = ilist(1:len)\n ! bubble-sort (len is small, remember?) into ordered list\n ! OK, I am ashamed -- I will use insertion sort next time ....\n if (.not.ordered) then\n succ = .false.\n do while (.not.succ)\n succ = .true.\n do idx = 1, len-1\n if (iscr(idx).gt.iscr(idx+1)) then\n succ = .false.\n ihlp = iscr(idx)\n iscr(idx) = iscr(idx+1)\n iscr(idx+1) = ihlp\n end if\n end do\n end do\n end if\n\n ilast = iscr(1)\n nn = 1\n ipermfac = 1\n do idx = 2, len\n if (iscr(idx).eq.ilast) then\n nn = nn+1\n else\n ilast = iscr(idx)\n if (nn.gt.1) ipermfac = ipermfac*ifac(nn)\n nn = 1\n end if\n end do\n if (nn.gt.1) ipermfac = ipermfac*ifac(nn)\n\n if (ntest.ge.100) then\n write(lulog,*) '-------------------'\n write(lulog,*) ' ipermfac speaking'\n write(lulog,*) '-------------------'\n write(lulog,*) ' list: ',ilist(1:len)\n if (.not.ordered) \n & write(lulog,*) ' list(reo): ',iscr(1:len)\n write(lulog,*) ' ipermfac = ',ipermfac\n end if \n\n return\n end\n", "meta": {"hexsha": "06b88e18a06d0cb2ecb327519cb099d84808426a", "size": 2201, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "formula/ipermfac.f", "max_stars_repo_name": "ak-ustutt/GeCCo-public", "max_stars_repo_head_hexsha": "8d43a6c9323aeba7eb54625b95553bfd4b2418c6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "formula/ipermfac.f", "max_issues_repo_name": "ak-ustutt/GeCCo-public", "max_issues_repo_head_hexsha": "8d43a6c9323aeba7eb54625b95553bfd4b2418c6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "formula/ipermfac.f", "max_forks_repo_name": "ak-ustutt/GeCCo-public", "max_forks_repo_head_hexsha": "8d43a6c9323aeba7eb54625b95553bfd4b2418c6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.9605263158, "max_line_length": 72, "alphanum_fraction": 0.4434348024, "num_tokens": 587, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256393148982, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.6566180262227572}} {"text": " SUBROUTINE SB02MD( DICO, HINV, UPLO, SCAL, SORT, N, A, LDA, G,\r\n $ LDG, Q, LDQ, RCOND, WR, WI, S, LDS, U, LDU,\r\n $ IWORK, DWORK, LDWORK, BWORK, INFO )\r\nC\r\nC SLICOT RELEASE 5.5.\r\nC\r\nC Copyright (c) 2002-2012 NICONET e.V.\r\nC\r\nC PURPOSE\r\nC\r\nC To solve for X either the continuous-time algebraic Riccati\r\nC equation\r\nC -1\r\nC Q + A'*X + X*A - X*B*R B'*X = 0 (1)\r\nC\r\nC or the discrete-time algebraic Riccati equation\r\nC -1\r\nC X = A'*X*A - A'*X*B*(R + B'*X*B) B'*X*A + Q (2)\r\nC\r\nC where A, B, Q and R are N-by-N, N-by-M, N-by-N and M-by-M matrices\r\nC respectively, with Q symmetric and R symmetric nonsingular; X is\r\nC an N-by-N symmetric matrix.\r\nC -1\r\nC The matrix G = B*R B' must be provided on input, instead of B and\r\nC R, that is, for instance, the continuous-time equation\r\nC\r\nC Q + A'*X + X*A - X*G*X = 0 (3)\r\nC\r\nC is solved, where G is an N-by-N symmetric matrix. SLICOT Library\r\nC routine SB02MT should be used to compute G, given B and R. SB02MT\r\nC also enables to solve Riccati equations corresponding to optimal\r\nC problems with coupling terms.\r\nC\r\nC The routine also returns the computed values of the closed-loop\r\nC spectrum of the optimal system, i.e., the stable eigenvalues\r\nC lambda(1),...,lambda(N) of the corresponding Hamiltonian or\r\nC symplectic matrix associated to the optimal problem.\r\nC\r\nC ARGUMENTS\r\nC\r\nC Mode Parameters\r\nC\r\nC DICO CHARACTER*1\r\nC Specifies the type of Riccati equation to be solved as\r\nC follows:\r\nC = 'C': Equation (3), continuous-time case;\r\nC = 'D': Equation (2), discrete-time case.\r\nC\r\nC HINV CHARACTER*1\r\nC If DICO = 'D', specifies which symplectic matrix is to be\r\nC constructed, as follows:\r\nC = 'D': The matrix H in (5) (see METHOD) is constructed;\r\nC = 'I': The inverse of the matrix H in (5) is constructed.\r\nC HINV is not used if DICO = 'C'.\r\nC\r\nC UPLO CHARACTER*1\r\nC Specifies which triangle of the matrices G and Q is\r\nC stored, as follows:\r\nC = 'U': Upper triangle is stored;\r\nC = 'L': Lower triangle is stored.\r\nC\r\nC SCAL CHARACTER*1\r\nC Specifies whether or not a scaling strategy should be\r\nC used, as follows:\r\nC = 'G': General scaling should be used;\r\nC = 'N': No scaling should be used.\r\nC\r\nC SORT CHARACTER*1\r\nC Specifies which eigenvalues should be obtained in the top\r\nC of the Schur form, as follows:\r\nC = 'S': Stable eigenvalues come first;\r\nC = 'U': Unstable eigenvalues come first.\r\nC\r\nC Input/Output Parameters\r\nC\r\nC N (input) INTEGER\r\nC The order of the matrices A, Q, G and X. N >= 0.\r\nC\r\nC A (input/output) DOUBLE PRECISION array, dimension (LDA,N)\r\nC On entry, the leading N-by-N part of this array must\r\nC contain the coefficient matrix A of the equation.\r\nC On exit, if DICO = 'D', and INFO = 0 or INFO > 1, the\r\nC -1\r\nC leading N-by-N part of this array contains the matrix A .\r\nC Otherwise, the array A is unchanged on exit.\r\nC\r\nC LDA INTEGER\r\nC The leading dimension of array A. LDA >= MAX(1,N).\r\nC\r\nC G (input) DOUBLE PRECISION array, dimension (LDG,N)\r\nC The leading N-by-N upper triangular part (if UPLO = 'U')\r\nC or lower triangular part (if UPLO = 'L') of this array\r\nC must contain the upper triangular part or lower triangular\r\nC part, respectively, of the symmetric matrix G. The stricly\r\nC lower triangular part (if UPLO = 'U') or stricly upper\r\nC triangular part (if UPLO = 'L') is not referenced.\r\nC\r\nC LDG INTEGER\r\nC The leading dimension of array G. LDG >= MAX(1,N).\r\nC\r\nC Q (input/output) DOUBLE PRECISION array, dimension (LDQ,N)\r\nC On entry, the leading N-by-N upper triangular part (if\r\nC UPLO = 'U') or lower triangular part (if UPLO = 'L') of\r\nC this array must contain the upper triangular part or lower\r\nC triangular part, respectively, of the symmetric matrix Q.\r\nC The stricly lower triangular part (if UPLO = 'U') or\r\nC stricly upper triangular part (if UPLO = 'L') is not used.\r\nC On exit, if INFO = 0, the leading N-by-N part of this\r\nC array contains the solution matrix X of the problem.\r\nC\r\nC LDQ INTEGER\r\nC The leading dimension of array N. LDQ >= MAX(1,N).\r\nC\r\nC RCOND (output) DOUBLE PRECISION\r\nC An estimate of the reciprocal of the condition number (in\r\nC the 1-norm) of the N-th order system of algebraic\r\nC equations from which the solution matrix X is obtained.\r\nC\r\nC WR (output) DOUBLE PRECISION array, dimension (2*N)\r\nC WI (output) DOUBLE PRECISION array, dimension (2*N)\r\nC If INFO = 0 or INFO = 5, these arrays contain the real and\r\nC imaginary parts, respectively, of the eigenvalues of the\r\nC 2N-by-2N matrix S, ordered as specified by SORT (except\r\nC for the case HINV = 'D', when the order is opposite to\r\nC that specified by SORT). The leading N elements of these\r\nC arrays contain the closed-loop spectrum of the system\r\nC -1\r\nC matrix A - B*R *B'*X, if DICO = 'C', or of the matrix\r\nC -1\r\nC A - B*(R + B'*X*B) B'*X*A, if DICO = 'D'. Specifically,\r\nC lambda(k) = WR(k) + j*WI(k), for k = 1,2,...,N.\r\nC\r\nC S (output) DOUBLE PRECISION array, dimension (LDS,2*N)\r\nC If INFO = 0 or INFO = 5, the leading 2N-by-2N part of this\r\nC array contains the ordered real Schur form S of the\r\nC Hamiltonian or symplectic matrix H. That is,\r\nC\r\nC (S S )\r\nC ( 11 12)\r\nC S = ( ),\r\nC (0 S )\r\nC ( 22)\r\nC\r\nC where S , S and S are N-by-N matrices.\r\nC 11 12 22\r\nC\r\nC LDS INTEGER\r\nC The leading dimension of array S. LDS >= MAX(1,2*N).\r\nC\r\nC U (output) DOUBLE PRECISION array, dimension (LDU,2*N)\r\nC If INFO = 0 or INFO = 5, the leading 2N-by-2N part of this\r\nC array contains the transformation matrix U which reduces\r\nC the Hamiltonian or symplectic matrix H to the ordered real\r\nC Schur form S. That is,\r\nC\r\nC (U U )\r\nC ( 11 12)\r\nC U = ( ),\r\nC (U U )\r\nC ( 21 22)\r\nC\r\nC where U , U , U and U are N-by-N matrices.\r\nC 11 12 21 22\r\nC\r\nC LDU INTEGER\r\nC The leading dimension of array U. LDU >= MAX(1,2*N).\r\nC\r\nC Workspace\r\nC\r\nC IWORK INTEGER array, dimension (2*N)\r\nC\r\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\r\nC On exit, if INFO = 0, DWORK(1) returns the optimal value\r\nC of LDWORK and DWORK(2) returns the scaling factor used\r\nC (set to 1 if SCAL = 'N'), also set if INFO = 5;\r\nC if DICO = 'D', DWORK(3) returns the reciprocal condition\r\nC number of the given matrix A.\r\nC\r\nC LDWORK INTEGER\r\nC The length of the array DWORK.\r\nC LDWORK >= MAX(2,6*N) if DICO = 'C';\r\nC LDWORK >= MAX(3,6*N) if DICO = 'D'.\r\nC For optimum performance LDWORK should be larger.\r\nC\r\nC BWORK LOGICAL array, dimension (2*N)\r\nC\r\nC Error Indicator\r\nC\r\nC INFO INTEGER\r\nC = 0: successful exit;\r\nC < 0: if INFO = -i, the i-th argument had an illegal\r\nC value;\r\nC = 1: if matrix A is (numerically) singular in discrete-\r\nC time case;\r\nC = 2: if the Hamiltonian or symplectic matrix H cannot be\r\nC reduced to real Schur form;\r\nC = 3: if the real Schur form of the Hamiltonian or\r\nC symplectic matrix H cannot be appropriately ordered;\r\nC = 4: if the Hamiltonian or symplectic matrix H has less\r\nC than N stable eigenvalues;\r\nC = 5: if the N-th order system of linear algebraic\r\nC equations, from which the solution matrix X would\r\nC be obtained, is singular to working precision.\r\nC\r\nC METHOD\r\nC\r\nC The method used is the Schur vector approach proposed by Laub.\r\nC It is assumed that [A,B] is a stabilizable pair (where for (3) B\r\nC is any matrix such that B*B' = G with rank(B) = rank(G)), and\r\nC [E,A] is a detectable pair, where E is any matrix such that\r\nC E*E' = Q with rank(E) = rank(Q). Under these assumptions, any of\r\nC the algebraic Riccati equations (1)-(3) is known to have a unique\r\nC non-negative definite solution. See [2].\r\nC Now consider the 2N-by-2N Hamiltonian or symplectic matrix\r\nC\r\nC ( A -G )\r\nC H = ( ), (4)\r\nC (-Q -A'),\r\nC\r\nC for continuous-time equation, and\r\nC -1 -1\r\nC ( A A *G )\r\nC H = ( -1 -1 ), (5)\r\nC (Q*A A' + Q*A *G)\r\nC -1\r\nC for discrete-time equation, respectively, where G = B*R *B'.\r\nC The assumptions guarantee that H in (4) has no pure imaginary\r\nC eigenvalues, and H in (5) has no eigenvalues on the unit circle.\r\nC If Y is an N-by-N matrix then there exists an orthogonal matrix U\r\nC such that U'*Y*U is an upper quasi-triangular matrix. Moreover, U\r\nC can be chosen so that the 2-by-2 and 1-by-1 diagonal blocks\r\nC (corresponding to the complex conjugate eigenvalues and real\r\nC eigenvalues respectively) appear in any desired order. This is the\r\nC ordered real Schur form. Thus, we can find an orthogonal\r\nC similarity transformation U which puts (4) or (5) in ordered real\r\nC Schur form\r\nC\r\nC U'*H*U = S = (S(1,1) S(1,2))\r\nC ( 0 S(2,2))\r\nC\r\nC where S(i,j) is an N-by-N matrix and the eigenvalues of S(1,1)\r\nC have negative real parts in case of (4), or moduli greater than\r\nC one in case of (5). If U is conformably partitioned into four\r\nC N-by-N blocks\r\nC\r\nC U = (U(1,1) U(1,2))\r\nC (U(2,1) U(2,2))\r\nC\r\nC with respect to the assumptions we then have\r\nC (a) U(1,1) is invertible and X = U(2,1)*inv(U(1,1)) solves (1),\r\nC (2), or (3) with X = X' and non-negative definite;\r\nC (b) the eigenvalues of S(1,1) (if DICO = 'C') or S(2,2) (if\r\nC DICO = 'D') are equal to the eigenvalues of optimal system\r\nC (the 'closed-loop' spectrum).\r\nC\r\nC [A,B] is stabilizable if there exists a matrix F such that (A-BF)\r\nC is stable. [E,A] is detectable if [A',E'] is stabilizable.\r\nC\r\nC REFERENCES\r\nC\r\nC [1] Laub, A.J.\r\nC A Schur Method for Solving Algebraic Riccati equations.\r\nC IEEE Trans. Auto. Contr., AC-24, pp. 913-921, 1979.\r\nC\r\nC [2] Wonham, W.M.\r\nC On a matrix Riccati equation of stochastic control.\r\nC SIAM J. Contr., 6, pp. 681-697, 1968.\r\nC\r\nC [3] Sima, V.\r\nC Algorithms for Linear-Quadratic Optimization.\r\nC Pure and Applied Mathematics: A Series of Monographs and\r\nC Textbooks, vol. 200, Marcel Dekker, Inc., New York, 1996.\r\nC\r\nC NUMERICAL ASPECTS\r\nC 3\r\nC The algorithm requires 0(N ) operations.\r\nC\r\nC FURTHER COMMENTS\r\nC\r\nC To obtain a stabilizing solution of the algebraic Riccati\r\nC equation for DICO = 'D', set SORT = 'U', if HINV = 'D', or set\r\nC SORT = 'S', if HINV = 'I'.\r\nC\r\nC The routine can also compute the anti-stabilizing solutions of\r\nC the algebraic Riccati equations, by specifying\r\nC SORT = 'U' if DICO = 'D' and HINV = 'I', or DICO = 'C', or\r\nC SORT = 'S' if DICO = 'D' and HINV = 'D'.\r\nC\r\nC Usually, the combinations HINV = 'D' and SORT = 'U', or HINV = 'I'\r\nC and SORT = 'U', will be faster then the other combinations [3].\r\nC\r\nC CONTRIBUTOR\r\nC\r\nC Release 3.0: V. Sima, Katholieke Univ. Leuven, Belgium, Aug. 1997.\r\nC Supersedes Release 2.0 routine SB02AD by Control Systems Research\r\nC Group, Kingston Polytechnic, United Kingdom, March 1982.\r\nC\r\nC REVISIONS\r\nC\r\nC V. Sima, Research Institute for Informatics, Bucharest, Dec. 2002.\r\nC\r\nC KEYWORDS\r\nC\r\nC Algebraic Riccati equation, closed loop system, continuous-time\r\nC system, discrete-time system, optimal regulator, Schur form.\r\nC\r\nC ******************************************************************\r\nC\r\nC .. Parameters ..\r\n DOUBLE PRECISION ZERO, HALF, ONE\r\n PARAMETER ( ZERO = 0.0D0, HALF = 0.5D0, ONE = 1.0D0 )\r\nC .. Scalar Arguments ..\r\n CHARACTER DICO, HINV, SCAL, SORT, UPLO\r\n INTEGER INFO, LDA, LDG, LDQ, LDS, LDU, LDWORK, N\r\n DOUBLE PRECISION RCOND\r\nC .. Array Arguments ..\r\n LOGICAL BWORK(*)\r\n INTEGER IWORK(*)\r\n DOUBLE PRECISION A(LDA,*), DWORK(*), G(LDG,*), Q(LDQ,*),\r\n $ S(LDS,*), U(LDU,*), WR(*), WI(*)\r\nC .. Local Scalars ..\r\n LOGICAL DISCR, LHINV, LSCAL, LSORT, LUPLO\r\n INTEGER I, IERR, ISCL, N2, NP1, NROT\r\n DOUBLE PRECISION GNORM, QNORM, RCONDA, UNORM, WRKOPT\r\nC .. External Functions ..\r\n LOGICAL LSAME, SB02MR, SB02MS, SB02MV, SB02MW\r\n DOUBLE PRECISION DLAMCH, DLANGE, DLANSY\r\n EXTERNAL DLAMCH, DLANGE, DLANSY, LSAME, SB02MR, SB02MS,\r\n $ SB02MV, SB02MW\r\nC .. External Subroutines ..\r\n EXTERNAL DAXPY, DCOPY, DGECON, DGEES, DGETRF, DGETRS,\r\n $ DLACPY, DLASCL, DLASET, DSCAL, DSWAP, SB02MU,\r\n $ XERBLA\r\nC .. Intrinsic Functions ..\r\n INTRINSIC INT, MAX\r\nC .. Executable Statements ..\r\nC\r\n INFO = 0\r\n N2 = N + N\r\n NP1 = N + 1\r\n DISCR = LSAME( DICO, 'D' )\r\n LSCAL = LSAME( SCAL, 'G' )\r\n LSORT = LSAME( SORT, 'S' )\r\n LUPLO = LSAME( UPLO, 'U' )\r\n IF ( DISCR ) LHINV = LSAME( HINV, 'D' )\r\nC\r\nC Test the input scalar arguments.\r\nC\r\n IF( .NOT.DISCR .AND. .NOT.LSAME( DICO, 'C' ) ) THEN\r\n INFO = -1\r\n ELSE IF( DISCR ) THEN\r\n IF( .NOT.LHINV .AND. .NOT.LSAME( HINV, 'I' ) )\r\n $ INFO = -2\r\n END IF\r\n IF( .NOT.LUPLO .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN\r\n INFO = -3\r\n ELSE IF( .NOT.LSCAL .AND. .NOT.LSAME( SCAL, 'N' ) ) THEN\r\n INFO = -4\r\n ELSE IF( .NOT.LSORT .AND. .NOT.LSAME( SORT, 'U' ) ) THEN\r\n INFO = -5\r\n ELSE IF( N.LT.0 ) THEN\r\n INFO = -6\r\n ELSE IF( LDA.LT.MAX( 1, N ) ) THEN\r\n INFO = -8\r\n ELSE IF( LDG.LT.MAX( 1, N ) ) THEN\r\n INFO = -10\r\n ELSE IF( LDQ.LT.MAX( 1, N ) ) THEN\r\n INFO = -12\r\n ELSE IF( LDS.LT.MAX( 1, N2 ) ) THEN\r\n INFO = -17\r\n ELSE IF( LDU.LT.MAX( 1, N2 ) ) THEN\r\n INFO = -19\r\n ELSE IF( ( .NOT.DISCR .AND. LDWORK.LT.MAX( 2, 6*N ) ) .OR.\r\n $ ( DISCR .AND. LDWORK.LT.MAX( 3, 6*N ) ) ) THEN\r\n INFO = -22\r\n END IF\r\nC\r\n IF ( INFO.NE.0 ) THEN\r\nC\r\nC Error return.\r\nC\r\n CALL XERBLA( 'SB02MD', -INFO )\r\n RETURN\r\n END IF\r\nC\r\nC Quick return if possible.\r\nC\r\n IF ( N.EQ.0 ) THEN\r\n RCOND = ONE\r\n DWORK(1) = ONE\r\n DWORK(2) = ONE\r\n IF ( DISCR ) DWORK(3) = ONE\r\n RETURN\r\n END IF\r\nC\r\n IF ( LSCAL ) THEN\r\nC\r\nC Compute the norms of the matrices Q and G.\r\nC\r\n QNORM = DLANSY( '1-norm', UPLO, N, Q, LDQ, DWORK )\r\n GNORM = DLANSY( '1-norm', UPLO, N, G, LDG, DWORK )\r\n END IF\r\nC\r\nC Initialise the Hamiltonian or symplectic matrix associated with\r\nC the problem.\r\nC Workspace: need 1 if DICO = 'C';\r\nC max(2,4*N) if DICO = 'D';\r\nC prefer larger if DICO = 'D'.\r\nC\r\n CALL SB02MU( DICO, HINV, UPLO, N, A, LDA, G, LDG, Q, LDQ, S, LDS,\r\n $ IWORK, DWORK, LDWORK, INFO )\r\n IF ( INFO.NE.0 ) THEN\r\n INFO = 1\r\n RETURN\r\n END IF\r\nC\r\n WRKOPT = DWORK(1)\r\n IF ( DISCR ) RCONDA = DWORK(2)\r\nC\r\n ISCL = 0\r\n IF ( LSCAL ) THEN\r\nC\r\nC Scale the Hamiltonian or symplectic matrix.\r\nC\r\n IF( QNORM.GT.GNORM .AND. GNORM.GT.ZERO ) THEN\r\n CALL DLASCL( 'G', 0, 0, QNORM, GNORM, N, N, S(NP1,1), N2,\r\n $ IERR )\r\n CALL DLASCL( 'G', 0, 0, GNORM, QNORM, N, N, S(1,NP1), N2,\r\n $ IERR )\r\n ISCL = 1\r\n END IF\r\n END IF\r\nC\r\nC Find the ordered Schur factorization of S, S = U*H*U'.\r\nC Workspace: need 6*N;\r\nC prefer larger.\r\nC\r\n IF ( .NOT.DISCR ) THEN\r\n IF ( LSORT ) THEN\r\n CALL DGEES( 'Vectors', 'Sorted', SB02MV, N2, S, LDS, NROT,\r\n $ WR, WI, U, LDU, DWORK, LDWORK, BWORK, INFO )\r\n ELSE\r\n CALL DGEES( 'Vectors', 'Sorted', SB02MR, N2, S, LDS, NROT,\r\n $ WR, WI, U, LDU, DWORK, LDWORK, BWORK, INFO )\r\n END IF\r\n ELSE\r\n IF ( LSORT ) THEN\r\n CALL DGEES( 'Vectors', 'Sorted', SB02MW, N2, S, LDS, NROT,\r\n $ WR, WI, U, LDU, DWORK, LDWORK, BWORK, INFO )\r\n ELSE\r\n CALL DGEES( 'Vectors', 'Sorted', SB02MS, N2, S, LDS, NROT,\r\n $ WR, WI, U, LDU, DWORK, LDWORK, BWORK, INFO )\r\n END IF\r\n IF ( LHINV ) THEN\r\n CALL DSWAP( N, WR, 1, WR(NP1), 1 )\r\n CALL DSWAP( N, WI, 1, WI(NP1), 1 )\r\n END IF\r\n END IF\r\n IF ( INFO.GT.N2 ) THEN\r\n INFO = 3\r\n ELSE IF ( INFO.GT.0 ) THEN\r\n INFO = 2\r\n ELSE IF ( NROT.NE.N ) THEN\r\n INFO = 4\r\n END IF\r\n IF ( INFO.NE.0 )\r\n $ RETURN\r\nC\r\n WRKOPT = MAX( WRKOPT, DWORK(1) )\r\nC\r\nC Check if U(1,1) is singular. Use the (2,1) block of S as a\r\nC workspace for factoring U(1,1).\r\nC\r\n UNORM = DLANGE( '1-norm', N, N, U, LDU, DWORK )\r\nC\r\n CALL DLACPY( 'Full', N, N, U, LDU, S(NP1,1), LDS )\r\n CALL DGETRF( N, N, S(NP1,1), LDS, IWORK, INFO )\r\nC\r\n IF ( INFO.GT.0 ) THEN\r\nC\r\nC Singular matrix. Set INFO and RCOND for error return.\r\nC\r\n INFO = 5\r\n RCOND = ZERO\r\n GO TO 100\r\n END IF\r\nC\r\nC Estimate the reciprocal condition of U(1,1).\r\nC Workspace: 6*N.\r\nC\r\n CALL DGECON( '1-norm', N, S(NP1,1), LDS, UNORM, RCOND,\r\n $ DWORK, IWORK(NP1), INFO )\r\nC\r\n IF ( RCOND.LT.DLAMCH( 'Epsilon' ) ) THEN\r\nC\r\nC Nearly singular matrix. Set INFO for error return.\r\nC\r\n INFO = 5\r\n RETURN\r\n END IF\r\nC\r\nC Transpose U(2,1) in Q and compute the solution.\r\nC\r\n DO 60 I = 1, N\r\n CALL DCOPY( N, U(NP1,I), 1, Q(I,1), LDQ )\r\n 60 CONTINUE\r\nC\r\n CALL DGETRS( 'Transpose', N, N, S(NP1,1), LDS, IWORK, Q, LDQ,\r\n $ INFO )\r\nC\r\nC Set S(2,1) to zero.\r\nC\r\n CALL DLASET( 'Full', N, N, ZERO, ZERO, S(NP1,1), LDS )\r\nC\r\nC Make sure the solution matrix X is symmetric.\r\nC\r\n DO 80 I = 1, N - 1\r\n CALL DAXPY( N-I, ONE, Q(I,I+1), LDQ, Q(I+1,I), 1 )\r\n CALL DSCAL( N-I, HALF, Q(I+1,I), 1 )\r\n CALL DCOPY( N-I, Q(I+1,I), 1, Q(I,I+1), LDQ )\r\n 80 CONTINUE\r\nC\r\n IF( LSCAL ) THEN\r\nC\r\nC Undo scaling for the solution matrix.\r\nC\r\n IF( ISCL.EQ.1 )\r\n $ CALL DLASCL( 'G', 0, 0, GNORM, QNORM, N, N, Q, LDQ, IERR )\r\n END IF\r\nC\r\nC Set the optimal workspace, the scaling factor, and reciprocal\r\nC condition number (if any).\r\nC\r\n DWORK(1) = WRKOPT\r\n 100 CONTINUE\r\n IF( ISCL.EQ.1 ) THEN\r\n DWORK(2) = QNORM / GNORM\r\n ELSE\r\n DWORK(2) = ONE\r\n END IF\r\n IF ( DISCR ) DWORK(3) = RCONDA\r\nC\r\n RETURN\r\nC *** Last line of SB02MD ***\r\n END\r\n", "meta": {"hexsha": "013ff30bc2665d55d66c3c7ce2c79a278991a195", "size": 20796, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "External/SLICOT/SB02MD.f", "max_stars_repo_name": "bgin/MissileSimulation", "max_stars_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2016-08-28T23:20:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-15T14:43:58.000Z", "max_issues_repo_path": "External/SLICOT/SB02MD.f", "max_issues_repo_name": "bgin/MissileSimulation", "max_issues_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-06-02T21:29:51.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-05T05:59:31.000Z", "max_forks_repo_path": "External/SLICOT/SB02MD.f", "max_forks_repo_name": "bgin/MissileSimulation", "max_forks_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-07-04T22:38:22.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-04T22:38:22.000Z", "avg_line_length": 38.0879120879, "max_line_length": 73, "alphanum_fraction": 0.5188016926, "num_tokens": 6284, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9390248191350351, "lm_q2_score": 0.6992544273261175, "lm_q1q2_score": 0.6566172621492801}} {"text": "\n\n subroutine tok_fraction(ft_tok,irho)\nc--\nc This calculates the fraction passing and the fraction trapped\nc for a tokamak using the Lin-Liu Miller approximation with Houlberg\nc weighting factors. (Phys. Plas. 2, 1966 (1995).\nc--\nC-----------------------------------------------\nC M o d u l e s\nC-----------------------------------------------\n use parambs\n use vmec0\n implicit none\nC-----------------------------------------------\nC D u m m y A r g u m e n t s\nC-----------------------------------------------\n integer irho\n real(rprec) ft_tok\nC-----------------------------------------------\nC L o c a l P a r a m e t e r s\nC-----------------------------------------------\n real(rprec), parameter :: one = 1\nC-----------------------------------------------\nC L o c a l V a r i a b l e s\nC-----------------------------------------------\n integer i\n real(rprec) fub, flb, bavg, b2av, sum_gsqrt_tok\n real(rprec) bmax\nC-----------------------------------------------\n\n real(rprec), dimension(:), allocatable ::\n 1 bfield_tok, gsqrt_tok, b2obm_tok, one_b2\n allocate(bfield_tok(nthetah), gsqrt_tok(nthetah),\n 1 b2obm_tok(nthetah), one_b2(nthetah), stat = i)\n if(i .ne. 0) stop 'allocation error of tokamak fields'\n\n\nc make symetric copies of field quantites--average over zeta to extract\nc symmetric component.\n\n do i =1,nthetah\n bfield_tok(i) = sum(bfield(i,:nzetah))/nzetah\n enddo\n\nc renormalize to max tok field equivalent\n\n bmax = maxval(bfield_tok)\n bfield_tok = bfield_tok/bmax\n where(bfield_tok .gt. one) bfield_tok = one\n\nc calculate 1/b**2, b**2\n\n one_b2 = one/bfield_tok**2\n b2obm_tok = bfield_tok**2\n\nc jacobian only includes 1/b**2 component and is normalized to bmax tok\nc integrate over jacobian to obtain normalization for averages\n sum_gsqrt_tok= sum(one_b2)\n\n\nc find average b, b**2\n\n bavg = sum(bfield_tok*one_b2)/sum_gsqrt_tok\n b2av = sum(b2obm_tok*one_b2)/sum_gsqrt_tok\n\nc find upper bound\n\n fub = one-(one-sqrt(one-bavg)*(one+0.5_dp*bavg))*b2av/bavg**2\n\nc find lower bound\n\n\nc minus <1/b**2>\n\n flb = - sum(one/b2obm_tok**2)/sum_gsqrt_tok\n\nc plus \n\n flb = flb + sum(sqrt(one-bfield_tok)\n 1 /b2obm_tok**2)/sum_gsqrt_tok\n\nc plus /2\n\n flb = flb + 0.5_dp*sum(sqrt(one-bfield_tok)\n 1 /bfield_tok/b2obm_tok)/sum_gsqrt_tok\n\nc 1+(previous stuff)*\n\n\n flb = one + flb*b2av\n\nc finally combine upper and lower limits with Houlberg factors\n ft_tok = 0.25_dp*flb + 0.75_dp*fub\n\n deallocate(bfield_tok, gsqrt_tok, b2obm_tok, one_b2)\n\n return\n end subroutine tok_fraction\n", "meta": {"hexsha": "414b020f83eac687f91ba9a7d1810290e01a8584", "size": 2737, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "BOOTSJ/Sources/tok_fraction.f", "max_stars_repo_name": "joseluisvelasco/STELLOPT", "max_stars_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2020-05-08T01:47:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T10:35:28.000Z", "max_issues_repo_path": "BOOTSJ/Sources/tok_fraction.f", "max_issues_repo_name": "joseluisvelasco/STELLOPT", "max_issues_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 77, "max_issues_repo_issues_event_min_datetime": "2020-05-08T07:18:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:20:33.000Z", "max_forks_repo_path": "BOOTSJ/Sources/tok_fraction.f", "max_forks_repo_name": "joseluisvelasco/STELLOPT", "max_forks_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-02-10T13:47:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T12:53:43.000Z", "avg_line_length": 27.37, "max_line_length": 72, "alphanum_fraction": 0.5495067592, "num_tokens": 827, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248157222395, "lm_q2_score": 0.6992544273261175, "lm_q1q2_score": 0.6566172597628677}} {"text": "\tFUNCTION XPADC(F)\nC\nC\tTHIS FUNCTION RETURNS THE GAIN OF THE DC CHANNEL OF THE WIND X PREAMP\nC\tNOT TESTED YET\nC\n\tCOMPLEX CGAIN,Y1,Z1,Y2,Z2\n\tDATA R1,C1,R2,CINP /5.E8,22.E-12,5.E8,4.51E-12/\n\tDATA R3,C3 /2.2E+03,1.E-9/\n\tDATA TWOPI /6.2831853/\nC\n\tW = TWOPI*F\n\tCGAIN = 1.\nC\tDIVISION OF SIGNAL BEFORE FOLLOWER\n\tY1 = CMPLX(1./R1,W*C1)\n\tY2 = CMPLX(1./R2,W*CINP)\n\tZ1 = 1./Y1\n\tZ2 = 1./Y2\n\tCGAIN = CGAIN*Z2/(Z1+Z2)\nC\tEFFECT OF OUTPUT RC\n\tWC3 = 1./(W*C3)\n\tCGAIN = CGAIN*CMPLX(0.,WC3)/CMPLX(R3,WC3)\n\tXPADC = CABS(CGAIN)\n\tRETURN\n\tEND\n", "meta": {"hexsha": "054465e5fe2484476a56c267fb9ee8e5805512f1", "size": 520, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/padcgn_4.for", "max_stars_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_stars_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/padcgn_4.for", "max_issues_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_issues_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/padcgn_4.for", "max_forks_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_forks_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.8, "max_line_length": 71, "alphanum_fraction": 0.6634615385, "num_tokens": 260, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248208414329, "lm_q2_score": 0.6992544147913993, "lm_q1q2_score": 0.6566172515720747}} {"text": "! =========================================================================\nelemental function gsw_pt_from_entropy (sa, entropy)\n! =========================================================================\n!\n! Calculates potential temperature with reference pressure p_ref = 0 dbar \n! and with entropy as an input variable. \n!\n! SA = Absolute Salinity [ g/kg ]\n! entropy = specific entropy [ deg C ]\n!\n! pt = potential temperature [ deg C ]\n! with reference sea pressure (p_ref) = 0 dbar.\n! Note. The reference sea pressure of the output, pt, is zero dbar.\n!--------------------------------------------------------------------------\n\nuse gsw_mod_teos10_constants, only : gsw_cp0, gsw_sso, gsw_t0\n\nuse gsw_mod_toolbox, only : gsw_entropy_from_pt, gsw_gibbs_pt0_pt0\n\nuse gsw_mod_kinds\n\nimplicit none\n\nreal (r8), intent(in) :: sa, entropy\n\nreal (r8) :: gsw_pt_from_entropy\n\ninteger :: number_of_iterations\nreal (r8) :: c, dentropy, dentropy_dt, ent_sa, part1, part2, pt, ptm\nreal (r8) :: pt_old\n\n! Find the initial value of pt\npart1 = 1.0_r8 - sa/gsw_sso\npart2 = 1.0_r8 - 0.05_r8*part1\nent_sa = (gsw_cp0/gsw_t0)*part1*(1.0_r8 - 1.01_r8*part1)\nc = (entropy - ent_sa)*(part2/gsw_cp0)\npt = gsw_t0*(exp(c) - 1.0_r8)\ndentropy_dt = gsw_cp0/((gsw_t0 + pt)*part2)\n\ndo number_of_iterations = 1, 2\n pt_old = pt\n dentropy = gsw_entropy_from_pt(sa,pt_old) - entropy\n pt = pt_old - dentropy/dentropy_dt\n ptm = 0.5_r8*(pt + pt_old)\n dentropy_dt = -gsw_gibbs_pt0_pt0(sa,ptm)\n pt = pt_old - dentropy/dentropy_dt\nend do\n \n! Maximum error of 2.2x10^-6 degrees C for one iteration.\n! Maximum error is 1.4x10^-14 degrees C for two iterations \n! (two iterations is the default, \"for Number_of_iterations = 1:2\"). \n\ngsw_pt_from_entropy = pt\n\nreturn\nend function\n\n!--------------------------------------------------------------------------\n", "meta": {"hexsha": "33b865c872e635d08b51007479bebc8699cc8cd0", "size": 1962, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "MOM6-interface/MOM6/pkg/GSW-Fortran/toolbox/gsw_pt_from_entropy.f90", "max_stars_repo_name": "minsukji/ci-debug", "max_stars_repo_head_hexsha": "3e8bbbe6652b702b61d2896612f6aa8e4aa6c803", "max_stars_repo_licenses": ["Apache-2.0", "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": "MOM6-interface/MOM6/pkg/GSW-Fortran/toolbox/gsw_pt_from_entropy.f90", "max_issues_repo_name": "minsukji/ci-debug", "max_issues_repo_head_hexsha": "3e8bbbe6652b702b61d2896612f6aa8e4aa6c803", "max_issues_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-05-21T20:21:16.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-06T17:52:34.000Z", "max_forks_repo_path": "MOM6-interface/MOM6/pkg/GSW-Fortran/toolbox/gsw_pt_from_entropy.f90", "max_forks_repo_name": "minsukji/ci-debug", "max_forks_repo_head_hexsha": "3e8bbbe6652b702b61d2896612f6aa8e4aa6c803", "max_forks_repo_licenses": ["Apache-2.0", "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": 33.2542372881, "max_line_length": 75, "alphanum_fraction": 0.5606523955, "num_tokens": 554, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248157222395, "lm_q2_score": 0.6992544085240401, "lm_q1q2_score": 0.6566172421072504}} {"text": " SUBROUTINE airy(x,ai,bi,aip,bip)\n REAL ai,aip,bi,bip,x\nCU USES bessik,bessjy\n REAL absx,ri,rip,rj,rjp,rk,rkp,rootx,ry,ryp,z,PI,THIRD,TWOTHR,\n *ONOVRT\n PARAMETER (PI=3.1415927,THIRD=1./3.,TWOTHR=2.*THIRD,\n *ONOVRT=.57735027)\n absx=abs(x)\n rootx=sqrt(absx)\n z=TWOTHR*absx*rootx\n if(x.gt.0.)then\n call bessik(z,THIRD,ri,rk,rip,rkp)\n ai=rootx*ONOVRT*rk/PI\n bi=rootx*(rk/PI+2.*ONOVRT*ri)\n call bessik(z,TWOTHR,ri,rk,rip,rkp)\n aip=-x*ONOVRT*rk/PI\n bip=x*(rk/PI+2.*ONOVRT*ri)\n else if(x.lt.0.)then\n call bessjy(z,THIRD,rj,ry,rjp,ryp)\n ai=.5*rootx*(rj-ONOVRT*ry)\n bi=-.5*rootx*(ry+ONOVRT*rj)\n call bessjy(z,TWOTHR,rj,ry,rjp,ryp)\n aip=.5*absx*(ONOVRT*ry+rj)\n bip=.5*absx*(ONOVRT*rj-ry)\n else\n ai=.35502805\n bi=ai/ONOVRT\n aip=-.25881940\n bip=-aip/ONOVRT\n endif\n return\n END\n", "meta": {"hexsha": "bd159098fa4eaab0be6f998a9689b6ed5d6df7e6", "size": 953, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/airy_2.for", "max_stars_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_stars_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/airy_2.for", "max_issues_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_issues_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/airy_2.for", "max_forks_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_forks_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.8787878788, "max_line_length": 68, "alphanum_fraction": 0.5571878279, "num_tokens": 404, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741268224333, "lm_q2_score": 0.6893056231680122, "lm_q1q2_score": 0.6566147021030625}} {"text": " SUBROUTINE TEST8(L,N,M,A,B,C)\n INTEGER L,N,M\n REAL A(L,M), B(M,N), C(L,M)\n\n DO 10 I = 1, L \n DO 20 J = 1, N\n C(I,J) = 0.0\n DO 30 K = 1, M \n C(I,J) = C(I,J) + A(I,K) * B(K,J)\n 30 CONTINUE\n 20 CONTINUE\n 10 CONTINUE\n END\n", "meta": {"hexsha": "7d2726dafae4c4cfa2313805020de473f754e63d", "size": 303, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "packages/PIPS/validation/Ricedg/test8.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/Ricedg/test8.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/Ricedg/test8.f", "max_forks_repo_name": "DVSR1966/par4all", "max_forks_repo_head_hexsha": "86b33ca9da736e832b568c5637a2381f360f1996", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2015-03-26T08:05:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T02:01:51.000Z", "avg_line_length": 21.6428571429, "max_line_length": 48, "alphanum_fraction": 0.3795379538, "num_tokens": 118, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246035907933, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.6566024554157562}} {"text": "!*==zrotg.f90 processed by SPAG 7.51RB at 20:37 on 3 Mar 2022\n!> \\brief \\b ZROTG\n!\n! =========== DOCUMENTATION ===========\n!\n! Online html documentation available at\n! http://www.netlib.org/lapack/explore-html/\n!\n! Definition:\n! ===========\n!\n! SUBROUTINE ZROTG(CA,CB,C,S)\n!\n! .. Scalar Arguments ..\n! COMPLEX*16 CA,CB,S\n! DOUBLE PRECISION C\n! ..\n!\n!\n!> \\par Purpose:\n! =============\n!>\n!> \\verbatim\n!>\n!> ZROTG determines a double complex Givens rotation.\n!> \\endverbatim\n!\n! Arguments:\n! ==========\n!\n!> \\param[in,out] CA\n!> \\verbatim\n!> CA is COMPLEX*16\n!> \\endverbatim\n!>\n!> \\param[in] CB\n!> \\verbatim\n!> CB is COMPLEX*16\n!> \\endverbatim\n!>\n!> \\param[out] C\n!> \\verbatim\n!> C is DOUBLE PRECISION\n!> \\endverbatim\n!>\n!> \\param[out] S\n!> \\verbatim\n!> S is COMPLEX*16\n!> \\endverbatim\n!\n! Authors:\n! ========\n!\n!> \\author Univ. of Tennessee\n!> \\author Univ. of California Berkeley\n!> \\author Univ. of Colorado Denver\n!> \\author NAG Ltd.\n!\n!> \\date November 2017\n!\n!> \\ingroup complex16_blas_level1\n!\n! =====================================================================\n SUBROUTINE ZROTG(Ca,Cb,C,S)\n IMPLICIT NONE\n!*--ZROTG66\n!\n! -- Reference BLAS level1 routine (version 3.8.0) --\n! -- Reference BLAS is a software package provided by Univ. of Tennessee, --\n! -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n! November 2017\n!\n! .. Scalar Arguments ..\n COMPLEX*16 Ca , Cb , S\n DOUBLE PRECISION C\n! ..\n!\n! =====================================================================\n!\n! .. Local Scalars ..\n COMPLEX*16 alpha\n DOUBLE PRECISION norm , scale\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC CDABS , DCMPLX , DCONJG , DSQRT\n! ..\n IF ( CDABS(Ca)==0.0D0 ) THEN\n C = 0.0D0\n S = (1.0D0,0.0D0)\n Ca = Cb\n ELSE\n scale = CDABS(Ca) + CDABS(Cb)\n norm = scale*DSQRT((CDABS(Ca/DCMPLX(scale,0.0D0))) &\n & **2+(CDABS(Cb/DCMPLX(scale,0.0D0)))**2)\n alpha = Ca/CDABS(Ca)\n C = CDABS(Ca)/norm\n S = alpha*DCONJG(Cb)/norm\n Ca = alpha*norm\n ENDIF\n END SUBROUTINE ZROTG\n", "meta": {"hexsha": "ac34b8fd3478d2d1a25fb00c5f4d691e01037e47", "size": 2252, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/blas/zrotg.f90", "max_stars_repo_name": "urbanjost/spag_lapack", "max_stars_repo_head_hexsha": "1b082638c0ff5feb1a295a3aa4624c538d14847c", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2022-03-04T13:15:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-04T17:40:26.000Z", "max_issues_repo_path": "src/blas/zrotg.f90", "max_issues_repo_name": "urbanjost/spag_lapack", "max_issues_repo_head_hexsha": "1b082638c0ff5feb1a295a3aa4624c538d14847c", "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": "src/blas/zrotg.f90", "max_forks_repo_name": "urbanjost/spag_lapack", "max_forks_repo_head_hexsha": "1b082638c0ff5feb1a295a3aa4624c538d14847c", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.297029703, "max_line_length": 80, "alphanum_fraction": 0.5062166963, "num_tokens": 729, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245953120233, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.6566024405930125}} {"text": "program array_init_test\n implicit none\n integer, parameter :: m = 4, n = 5, p = m*n/2\n integer :: i, j\n integer, dimension(m, n) :: a = reshape( [ (i, i = 1, m*n) ], [m, n])\n real, dimension(m, n) :: b\n integer, dimension(p) :: c\n character(len=10) :: fmt_str\n\n print '(A)', '# initialized at declaration'\n write (fmt_str, '(A, I1, A)') '(', n, 'I3)'\n do i = 1, size(a, 1)\n print fmt_str, a(i, :)\n end do\n\n print '(A)', '# initialized in program'\n b = reshape([ ((1.0/(i*n + j), i = 1, m), j=1, n) ], [m, n])\n write (fmt_str, '(A, I1, A)') '(', n, 'F7.3)'\n do i = 1, size(b, 1)\n print fmt_str, b(i, :)\n end do\n\n print '(A)', '# transposed and reshaped'\n c = reshape(transpose(a(2:3, :)), [p])\n write (fmt_str, '(A, I2, A)') '(', p, 'I3)'\n print fmt_str, c(:)\n \nend program array_init_test\n", "meta": {"hexsha": "c75af31647667f305cff1ca80a7a93870b3bc6c5", "size": 866, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran/Matrices/array_init_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/array_init_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/array_init_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": 29.8620689655, "max_line_length": 73, "alphanum_fraction": 0.5011547344, "num_tokens": 320, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.833324587033253, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.6566024382197325}} {"text": "! Program to generate a lattice of spin-1/2 particles and study its\n! Ferromagnetic properties \n\nprogram ising_3d\n implicit none\n\n integer:: i,j,k,L,p,a,b,c,d,f,g,niter,time,mm,nn,oo,N\n real*8:: r,E,M,mag,Ei,Ef,dE,u,h\n\n real*8:: T, J_ising=1.0 !assigning value to relevant parameters: k_B, J_ising\n\n integer, dimension(:,:,:), allocatable :: spin\n integer:: seed\n ! character(len=30):: charac_a, charac_b ! charac_b stores the name dump_pos\n\n seed=44859\n ! charac_b = \"store_config\"\n\n print*, \"Welcome to this program! This program simulates a 3D ising model with all spins iniitally in the random state\"\n print*, \"Enter the value of KbT in units of J_ising\"\n read*, T\n print*, \"Enter the number of lattice points in one dimension for (LxLxL)\"\n read*,L\n print*, \"Enter the number of iterations\"\n read*, niter\n\n allocate(spin(L,L,L))\n E=0.0d0 ! Instantaneous Energy of the lattice\n M=0.0d0 ! Instantaneous magnetization of the lattice \n N = L*L*L ! Total number of spins in lattice\n\n ! Initialize your lattice\n open(unit=71, file=\"initial_ising_3D.dat\")\n p=0\n do i=1,L\n do j=1,L\n do k=1,L\n call RANDOM_NUMBER(r)\n ! spin(k,j,i) = -1\n if (r < 0.5) then \n spin(i,j,k) = -1\n else\n spin(i,j,k)=1\n end if\n ! Write down this configuration \n !write(71, fmt=\"(5g10.8)\") float(i), float(j), float(p), float(spin(j,i))\n write(71,*) float(i), float(j), float(k), float(p), float(spin(i,j,k))\n end do\n end do\n end do\n\n close(71)\n\n ! Calculate Initial magnetization and energy \n do i=1,L\n do j=1,L \n do k=1,L\n a=i+1; b=i-1; c=j+1; d=j-1; f=k+1; g=k-1 !identifying the 4 neighbors of spin(j,i) \n\n ! Setting PBCs (Periodic Boundary conditions) \n if (i==L)a=1\n if (i==1)b=L\n if (j==L)c=1\n if (j==1)d=L\n if (k==L)f=1\n if (k==1)g=L\n\n E=E-J_ising*float((spin(i,j,k))*(spin(a,j,k)+spin(b,j,k)+spin(i,c,k)+spin(i,d,k)+spin(i,j,f)+spin(i,j,g)))\n M=M+spin(i,j,k)\n end do\n end do\n end do\n\n ! Calculate instantaneous magnetization per spin \n mag = M/float(N)\n E=E*0.5d0\n print*, \"Initial energy E, E per spin is: \",E, E/float(N)\n print*, \"Initial magentization M, M per spin is: \", M,M/float(N)\n\n ! INITIALIZATION COMPLETE\n ! -----------------------------\n ! EVOLVE TO REACH EQUILIBRIUM \n\n open(unit=10, file=\"ising_3d_T_L20_random.dat\")\n do time=i,niter ! loop over number of MCS\n do mm=1,L\n do nn=1,L\n do oo=1,L\n call random_number(r); i=int(r*float(L))+1 !choosing a lattice site\n call random_number(r); j=int(r*float(L))+1\n call random_number(r); k=int(r*float(L))+1\n\n a=i+1;b=i-1;c=j+1;d=j-1;f=k+1;g=k-1 !identify the neighbors of spin(j,i) \n\n if(i==L)a=1; if(i==1)b=L; if(j==L)c=1; if(j==1)d=L; if(k==L)f=1; if(k==1)g=L !PBC\n ! BEFORE TRAIL FLIP\n Ei = -J_ising*float((spin(i,j,k))*(spin(a,j,k)+spin(b,j,k)+spin(i,c,k)+spin(i,d,k)+spin(i,j,f)+spin(i,j,g)))\n\n spin(i,j,k) =-spin(i,j,k) !TRIAL FLIP\n\n ! AFTER TRAIL FLIP\n Ef = -J_ising*float((spin(i,j,k))*(spin(a,j,k)+spin(b,j,k)+spin(i,c,k)+spin(i,d,k)+spin(i,j,f)+spin(i,j,g)))\n dE = Ef-Ei\n\n if(dE <=0.0) then\n E=E+dE\n M=M+(2.0*float(spin(i,j,k)))\n else\n u=exp(-dE/(T))\n call random_number(h)\n if (h 0 ) then\n do i=1,n\n if( eival8(i) < abs(eival8(n))*sqrt(epsilon(eival8)) ) then\n nrank_eff = nrank_eff - 1\n eival8(i) = 0._r_double\n eivec8(:,i) = 0._r_double\n end if\n end do\n else\n print *,'!!! ERROR (mtx_eigen): All Eigenvalues are below 0'\n call stop2(2)\n end if\n\n if( nrank_eff= 0.\nC\nC NB (input) INTEGER\nC The number of system inputs, i.e. the number of columns in\nC the transfer function matrix G(z). NB >= 0.\nC\nC N (input) INTEGER\nC The number of Markov parameters M(k) to be computed.\nC N >= 0.\nC\nC IORD (input) INTEGER array, dimension (NC*NB)\nC This array must contain the order r of the elements of the\nC transfer function matrix G(z), stored row by row.\nC For example, the order of the (i,j)-th element of G(z) is\nC given by IORD((i-1)xNB+j).\nC\nC AR (input) DOUBLE PRECISION array, dimension (NA), where\nC NA = IORD(1) + IORD(2) + ... + IORD(NC*NB).\nC The leading NA elements of this array must contain the\nC denominator coefficients AR(1),...,AR(r) in equation (1)\nC of the (i,j)-th element of the transfer function matrix\nC G(z), stored row by row, i.e. in the order\nC (1,1),(1,2),...,(1,NB), (2,1),(2,2),...,(2,NB), ...,\nC (NC,1),(NC,2),...,(NC,NB). The coefficients must be given\nC in decreasing order of powers of z; the coefficient of the\nC highest order term is assumed to be equal to 1.\nC\nC MA (input) DOUBLE PRECISION array, dimension (NA)\nC The leading NA elements of this array must contain the\nC numerator coefficients MA(1),...,MA(r) in equation (1)\nC of the (i,j)-th element of the transfer function matrix\nC G(z), stored row by row, i.e. in the order\nC (1,1),(1,2),...,(1,NB), (2,1),(2,2),...,(2,NB), ...,\nC (NC,1),(NC,2),...,(NC,NB). The coefficients must be given\nC in decreasing order of powers of z.\nC\nC H (output) DOUBLE PRECISION array, dimension (LDH,N*NB)\nC The leading NC-by-N*NB part of this array contains the\nC multivariable Markov parameter sequence M(k), where each\nC parameter M(k) is an NC-by-NB matrix and k = 1,2,...,N.\nC The Markov parameters are stored such that H(i,(k-1)xNB+j)\nC contains the (i,j)-th element of M(k) for i = 1,2,...,NC\nC and j = 1,2,...,NB.\nC\nC LDH INTEGER\nC The leading dimension of array H. LDH >= MAX(1,NC).\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value.\nC\nC METHOD\nC\nC The (i,j)-th element of G(z), defining the particular I/O transfer\nC between output i and input j, has the following form:\nC\nC -1 -2 -r\nC MA(1)z + MA(2)z + ... + MA(r)z\nC G (z) = ----------------------------------------. (1)\nC ij -1 -2 -r\nC 1 + AR(1)z + AR(2)z + ... + AR(r)z\nC\nC The (i,j)-th element of G(z) is defined by its order r, its r\nC moving average coefficients (= numerator) MA(1),...,MA(r) and its\nC r autoregressive coefficients (= denominator) AR(1),...,AR(r). The\nC coefficient of the constant term in the denominator is assumed to\nC be equal to 1.\nC\nC The relationship between the (i,j)-th element of the Markov\nC parameters M(1),M(2),...,M(N) and the corresponding element of the\nC transfer function matrix G(z) is given by:\nC\nC -1 -2 -k\nC G (z) = M (0) + M (1)z + M (2)z + ... + M (k)z + ...(2)\nC ij ij ij ij ij\nC\nC Equating (1) and (2), we find that the relationship between the\nC (i,j)-th element of the Markov parameters M(k) and the ARMA\nC parameters AR(1),...,AR(r) and MA(1),...,MA(r) of the (i,j)-th\nC element of the transfer function matrix G(z) is as follows:\nC\nC M (1) = MA(1),\nC ij\nC k-1\nC M (k) = MA(k) - SUM AR(p) x M (k-p) for 1 < k <= r and\nC ij p=1 ij\nC r\nC M (k+r) = - SUM AR(p) x M (k+r-p) for k > 0.\nC ij p=1 ij\nC\nC From these expressions the Markov parameters M(k) are computed\nC element by element.\nC\nC REFERENCES\nC\nC [1] Luenberger, D.G.\nC Introduction to Dynamic Systems: Theory, Models and\nC Applications.\nC John Wiley & Sons, New York, 1979.\nC\nC NUMERICAL ASPECTS\nC\nC The computation of the (i,j)-th element of M(k) requires:\nC (k-1) multiplications and k additions if k <= r;\nC r multiplications and r additions if k > r.\nC\nC CONTRIBUTOR\nC\nC Release 3.0: V. Sima, Katholieke Univ. Leuven, Belgium, Dec. 1996.\nC Supersedes Release 2.0 routine TF01ED by S. Van Huffel, Katholieke\nC Univ. Leuven, Belgium.\nC\nC REVISIONS\nC\nC -\nC\nC KEYWORDS\nC\nC Markov parameters, multivariable system, transfer function,\nC transfer matrix.\nC\nC ******************************************************************\nC\nC .. Scalar Arguments ..\n INTEGER INFO, LDH, N, NB, NC\nC .. Array Arguments ..\n INTEGER IORD(*)\n DOUBLE PRECISION AR(*), H(LDH,*), MA(*)\nC .. Local Scalars ..\n INTEGER I, J, JJ, JK, K, KI, LDHNB, NL, NORD\nC .. External Functions ..\n DOUBLE PRECISION DDOT\n EXTERNAL DDOT\nC .. External Subroutines ..\n EXTERNAL XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC MAX\nC .. Executable Statements ..\nC\n INFO = 0\nC\nC Test the input scalar arguments.\nC\n IF( NC.LT.0 ) THEN\n INFO = -1\n ELSE IF( NB.LT.0 ) THEN\n INFO = -2\n ELSE IF( N.LT.0 ) THEN\n INFO = -3\n ELSE IF( LDH.LT.MAX( 1, NC ) ) THEN\n INFO = -8\n END IF\nC\n IF ( INFO.NE.0 ) THEN\nC\nC Error return.\nC\n CALL XERBLA( 'TF01QD', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF ( MAX( NC, NB, N ).EQ.0 )\n $ RETURN\nC\n LDHNB = LDH*NB\n NL = 1\n K = 1\nC\n DO 60 I = 1, NC\nC\n DO 50 J = 1, NB\n NORD = IORD(K)\n H(I,J) = MA(NL)\n JK = J\nC\n DO 20 KI = 1, NORD - 1\n JK = JK + NB\n H(I,JK) = MA(NL+KI) - DDOT( KI, AR(NL), 1, H(I,J),\n $ -LDHNB )\n 20 CONTINUE\nC\n DO 40 JJ = J, J + (N - NORD - 1)*NB, NB\n JK = JK + NB\n H(I,JK) = -DDOT( NORD, AR(NL), 1, H(I,JJ), -LDHNB )\n 40 CONTINUE\nC\n NL = NL + NORD\n K = K + 1\n 50 CONTINUE\nC\n 60 CONTINUE\nC\n RETURN\nC *** Last line of TF01QD ***\n END\n", "meta": {"hexsha": "7bdcf6704e4addacec739c67354c75f632f54557", "size": 7328, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/TF01QD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/TF01QD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/TF01QD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 33.6146788991, "max_line_length": 72, "alphanum_fraction": 0.5055949782, "num_tokens": 2256, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9136765281148512, "lm_q2_score": 0.7185943805178138, "lm_q1q2_score": 0.6565628187143584}} {"text": " program DRDSVA\nc>> 1996-06-27 DRDSVA Krogh Special code for C conversion.\nc>> 1996-05-28 DRDSVA Krogh Removed implicit statement.\nc>> 1994-10-19 DRDSVA Krogh Changes to use M77CON\nc>> 1989-03-07 DRDSVA CLL\nc Demo driver for DSVA, Singular Value Analysis.\nc\nc Mar 1987, C. L. Lawson & S. Y. Chiu, JPL. This sample problem\nc taken from the book, Solving Least Squares Problems,\nc Prentice-Hall, 1974, by C. L. Lawson and R. J. Hanson.\nc ------------------------------------------------------------------\nc--D replaces \"?\": DR?SVA, ?SVA\nc ------------------------------------------------------------------\n integer I, J, KPVEC(4), M, MDATA, MMAX, N, NMAX, NMAX2\n parameter(MMAX = 15, NMAX = 5, NMAX2 = NMAX*2)\n double precision A(MMAX,NMAX), B(MMAX), SING(NMAX)\n double precision D(NMAX), WORK(NMAX2)\n character*6 NAMES(NMAX)\nc\n data ((A(I,J),J=1,5),I=1,15) /\n *-.13405547D0,-.20162827D0,-.16930778D0,-.18971990D0,-.17387234D0,\n *-.10379475D0,-.15766336D0,-.13346256D0,-.14848550D0,-.13597690D0,\n *-.08779597D0,-.12883867D0,-.10683007D0,-.12011796D0,-.10932972D0,\n * .02058554D0, .00335331D0,-.01641270D0, .00078606D0, .00271659D0,\n *-.03248093D0,-.01876799D0, .00410639D0,-.01405894D0,-.01384391D0,\n * .05967662D0, .06667714D0, .04352153D0, .05740438D0, .05024962D0,\n * .06712457D0, .07352437D0, .04489770D0, .06471862D0, .05876455D0,\n * .08687186D0, .09368296D0, .05672327D0, .08141043D0, .07302320D0,\n * .02149662D0, .06222662D0, .07213486D0, .06200069D0, .05570931D0,\n * .06687407D0, .10344506D0, .09153849D0, .09508223D0, .08393667D0,\n * .15879069D0, .18088339D0, .11540692D0, .16160727D0, .14796479D0,\n * .17642887D0, .20361830D0, .13057860D0, .18385729D0, .17005549D0,\n * .11414080D0, .17259611D0, .14816471D0, .16007466D0, .14374096D0,\n * .07846038D0, .14669563D0, .14365800D0, .14003842D0, .12571177D0,\n * .10803175D0, .16994623D0, .14971519D0, .15885312D0, .14301547D0 /\nc\n data (B(I),I=1,15) /\n *-.4361D0, -.3437D0, -.2657D0, -.0392D0, .0193D0, .0747D0,\n * .0935D0, .1079D0, .1930D0, .2058D0, .2606D0, .3142D0,\n * .3529D0, .3615D0, .3647D0 /\nc\n data NAMES /'Earth ', 'Water ', 'Air ', 'Fire ', 'Time '/\n data KPVEC / 1, 111111, -1, 76/\nc ------------------------------------------------------------------\nc\n M = MMAX\n N = NMAX\n MDATA = M\n print '('' DRDSVA.. Demonstrate Singular Value Analysis''/\n * '' Listing of input matrix, A, and vector, B, follows..'')'\nc++ Code for ~.C. is active\n print '(/(5F12.7,F13.4))',\n * ((A(I,J),J=1,N),B(I),I=1,M)\nc++ Code for .C. is inactive\nc%% for (i = 1; i <= m; i++){\nc%% printf( \"\\n\" );\nc%% for (j = 1; j <= n; j++)\nc%% printf( \"%12.7f\", a[j - 1][i - 1] );\nc%% printf( \"%13.4f\", B[i] );}\nc%% fprintf( stdout, \" \\n\\n\\n \\n\" );\nc++ End\n print '(1X///1X)'\nc\n call DSVA(A, MMAX, M, N, MDATA, B, SING, KPVEC, NAMES, 1, D, WORK)\nc\n stop\n end\n", "meta": {"hexsha": "c9aead9200892d818490dd45fa85d97f6e73cf68", "size": 3039, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drdsva.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drdsva.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drdsva.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": 44.6911764706, "max_line_length": 72, "alphanum_fraction": 0.5607107601, "num_tokens": 1283, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933447152497, "lm_q2_score": 0.8006920116079209, "lm_q1q2_score": 0.6564820514839997}} {"text": "C * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC * *\nC * copyright (c) 1999 by UCAR *\nC * *\nC * UNIVERSITY CORPORATION for ATMOSPHERIC RESEARCH *\nC * *\nC * all rights reserved *\nC * *\nC * FISHPACK version 4.1 *\nC * *\nC * A PACKAGE OF FORTRAN SUBPROGRAMS FOR THE SOLUTION OF *\nC * *\nC * SEPARABLE ELLIPTIC PARTIAL DIFFERENTIAL EQUATIONS *\nC * *\nC * BY *\nC * *\nC * JOHN ADAMS, PAUL SWARZTRAUBER AND ROLAND SWEET *\nC * *\nC * OF *\nC * *\nC * THE NATIONAL CENTER FOR ATMOSPHERIC RESEARCH *\nC * *\nC * BOULDER, COLORADO (80307) U.S.A. *\nC * *\nC * WHICH IS SPONSORED BY *\nC * *\nC * THE NATIONAL SCIENCE FOUNDATION *\nC * *\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC\nC\nC PROGRAM TO ILLUSTRATE THE USE OF SUBROUTINE HWSPLR TO SOLVE\nC THE EQUATION\nC\nC (1/R)(D/DR)(R*(DU/DR)) + (1/R**2)(D/DTHETA)(DU/DTHETA) = 16*R**2\nC\nC ON THE QUARTER-DISK 0 .LT. R .LT. 1, 0 .LT. THETA .LT. PI/2 WITH\nC WITH THE BOUNDARY CONDITIONS\nC\nC U(1,THETA) = 1 - COS(4*THETA), 0 .LE. THETA .LE. 1\nC\nC AND\nC\nC (DU/DTHETA)(R,0) = (DU/DTHETA)(R,PI/2) = 0, 0 .LE. R .LE. 1.\nC\nC (NOTE THAT THE SOLUTION U IS UNSPECIFIED AT R = 0.)\nC THE R-INTERVAL WILL BE DIVIDED INTO 50 PANELS AND THE\nC THETA-INTERVAL WILL BE DIVIDED INTO 48 PANELS.\nC\n DIMENSION F(100,50) ,BDC(51) ,BDD(51) ,W(1114) ,\n 1 R(51) ,THETA(49)\nC\nC FROM DIMENSION STATEMENT WE GET VALUE OF IDIMF. ALSO NOTE THAT W\nC IS DIMENSIONED 4*(N+1) + (13 + INT(LOG2(N+1)))*(M+1) .\nC\n IDIMF = 100\n A = 0.\n B = 1.\n M = 50\n MBDCND = 5\n C = 0.\n PI = PIMACH(DUM)\n D = PI/2.\n N = 48\n NBDCND = 3\n ELMBDA = 0.\nC\nC AUXILIARY QUANTITIES.\nC\n MP1 = M+1\n NP1 = N+1\nC\nC GENERATE AND STORE GRID POINTS FOR THE PURPOSE OF COMPUTING\nC BOUNDARY DATA AND THE RIGHT SIDE OF THE POISSON EQUATION.\nC\n DO 101 I=1,MP1\n R(I) = FLOAT(I-1)/50.\n 101 CONTINUE\n DO 102 J=1,NP1\n THETA(J) = FLOAT(J-1)*PI/96.\n 102 CONTINUE\nC\nC GENERATE BOUNDARY DATA.\nC\n DO 103 I=1,MP1\n BDC(I) = 0.\n BDD(I) = 0.\n 103 CONTINUE\nC\nC BDA AND BDB ARE DUMMY VARIABLES.\nC\n DO 104 J=1,NP1\n F(MP1,J) = 1.-COS(4.*THETA(J))\n 104 CONTINUE\nC\nC GENERATE RIGHT SIDE OF EQUATION.\nC\n DO 106 I=1,M\n DO 105 J=1,NP1\n F(I,J) = 16.*R(I)**2\n 105 CONTINUE\n 106 CONTINUE\n CALL HWSPLR (A,B,M,MBDCND,BDA,BDB,C,D,N,NBDCND,BDC,BDD,ELMBDA,F,\n 1 IDIMF,PERTRB,IERROR,W)\nC\nC COMPUTE DISCRETIZATION ERROR. THE EXACT SOLUTION IS\nC U(R,THETA) = R**4*(1 - COS(4*THETA))\nC\n ERR = 0.\n DO 108 I=1,MP1\n DO 107 J=1,NP1\n Z = ABS(F(I,J)-R(I)**4*(1.-COS(4.*THETA(J))))\n IF (Z .GT. ERR) ERR = Z\n 107 CONTINUE\n 108 CONTINUE\n PRINT 1001 , IERROR,ERR,W(1)\n STOP\nC\n 1001 FORMAT (1H1,20X,25HSUBROUTINE HWSPLR EXAMPLE///\n 1 10X,46HTHE OUTPUT FROM THE NCAR CONTROL DATA 7600 WAS//\n 2 32X,10HIERROR = 0/\n 3 18X,34HDISCRETIZATION ERROR = 6.19134E-04/\n 4 12X,32HREQUIRED LENGTH OF W ARRAY = 882//\n 5 10X,32HTHE OUTPUT FROM YOUR COMPUTER IS//\n 6 32X,8HIERROR =,I2/18X,22HDISCRETIZATION ERROR =,E12.5/\n 7 12X,28HREQUIRED LENGTH OF W ARRAY =,F4.0)\nC\n END\n", "meta": {"hexsha": "47c961731088384aa0e3c1b2e5e526c89ee83af8", "size": 4760, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/test/thwsplr.f", "max_stars_repo_name": "ipelupessy/omuse", "max_stars_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2020-03-25T10:02:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-18T00:28:35.000Z", "max_issues_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/test/thwsplr.f", "max_issues_repo_name": "ipelupessy/omuse", "max_issues_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 45, "max_issues_repo_issues_event_min_datetime": "2020-03-03T16:07:16.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-14T09:01:07.000Z", "max_forks_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/test/thwsplr.f", "max_forks_repo_name": "ipelupessy/omuse", "max_forks_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-03-03T13:28:50.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-26T09:20:02.000Z", "avg_line_length": 36.8992248062, "max_line_length": 71, "alphanum_fraction": 0.3831932773, "num_tokens": 1445, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099167, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6563393202568701}} {"text": "module lcg\n ! Linear congruential random number generator\n use global_variables\n implicit none\n\n private :: Iterate_lcg \n public :: Init_lcg, Rand_lcg\n\n ! parameters from \"Numerical Recipies\"\n integer(DP), parameter, private :: M = 4294967296_DP\n integer(DP), parameter, private :: A = 1664525_DP\n integer(DP), parameter, private :: C = 1013904223_DP\n integer(DP), private, save :: rand_val = 0_DP\n\n interface Rand_lcg\n module procedure Rand_lcg1, Rand_lcgN, Rand_lcgNN\n end interface Rand_lcg\n\ncontains\n\n subroutine Init_lcg(seed)\n implicit none\n integer, intent(in) :: seed\n if (seed < 0 .or. seed > m) then\n write(*,*) 'Error: bad lcg seed'\n else\n rand_val = seed\n end if\n end subroutine Init_lcg\n \n subroutine Iterate_lcg()\n implicit none\n rand_val = mod((A*rand_val+C), M)\n end subroutine Iterate_lcg\n \n function Rand_lcg1() result(r)\n implicit none\n real(DP) :: r\n call Iterate_lcg()\n r = abs(real(rand_val,kind=DP) / real(M,kind=DP))\n end function Rand_lcg1\n\n function Rand_lcgN(n) result(r)\n implicit none\n integer, intent(in) :: n\n real(DP), dimension(n) :: r\n integer :: i\n do i = 1, n\n call Iterate_lcg()\n r(n) = abs(real(rand_val, kind=DP) / real(M, kind=DP))\n end do\n end function Rand_lcgN\n\n function Rand_lcgNN(n,nn) result(r)\n implicit none\n integer, intent(in) :: n,nn\n real(DP), dimension(n,nn) :: r\n integer :: i,j\n do i = 1, n\n do j = 1, nn\n call Iterate_lcg()\n r(i,j) = abs(real(rand_val, kind=DP) / real(M, kind=DP))\n end do\n end do\n end function Rand_lcgNN\n\nend module lcg\n", "meta": {"hexsha": "293fd3a89633f9ba8c079ab189963094a364fcd9", "size": 1647, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/lcg.f90", "max_stars_repo_name": "tukiains/dimred-fortran", "max_stars_repo_head_hexsha": "4c3165dd60ee05607aa973b1addc246e358e4f25", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-05-16T06:59:23.000Z", "max_stars_repo_stars_event_max_datetime": "2018-05-16T06:59:23.000Z", "max_issues_repo_path": "src/lcg.f90", "max_issues_repo_name": "tukiains/dimred-fortran", "max_issues_repo_head_hexsha": "4c3165dd60ee05607aa973b1addc246e358e4f25", "max_issues_repo_licenses": ["MIT"], "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/lcg.f90", "max_forks_repo_name": "tukiains/dimred-fortran", "max_forks_repo_head_hexsha": "4c3165dd60ee05607aa973b1addc246e358e4f25", "max_forks_repo_licenses": ["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.2205882353, "max_line_length": 66, "alphanum_fraction": 0.6399514268, "num_tokens": 514, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190939, "lm_q2_score": 0.7634837689358857, "lm_q1q2_score": 0.6563393147667936}} {"text": " SUBROUTINE svdsolveuv(m, n, mp, np, wcut, file, a, b, x)\n USE stel_kinds\n IMPLICIT NONE\nC-----------------------------------------------\nC D u m m y A r g u m e n t s\nC-----------------------------------------------\n INTEGER m, n, mp, np\n REAL(rprec) wcut\n CHARACTER file*(*)\n REAL(rprec), DIMENSION(mp,np) :: a\n REAL(rprec), DIMENSION(n) :: x\n REAL(rprec), DIMENSION(m) :: b\nC-----------------------------------------------\nC L o c a l P a r a m e t e r s\nC-----------------------------------------------\n REAL(rprec) :: zero = 0\nC-----------------------------------------------\nC L o c a l V a r i a b l e s\nC-----------------------------------------------\n INTEGER :: n1, nonzero, nlast, istat, i, j, iunit\n REAL(rprec), ALLOCATABLE :: u(:,:), w(:), v(:,:)\n REAL(rprec) :: wmax, wcuta, udotb\nC-----------------------------------------------\n\nc Solves Matrix equation A X = B for X using SVD method\nc Allows supression of weights, storage and recall of answers\nc Uses svd routines from numerical recipes\nc Prashant Valanju (Sept 1998) pvalanju@mail.utexas.edu\n\nc Almost same as SvdSolveB except this one stores U, W, V\nc rather than basis vectors.\nc Use this one when you want to change both B and weights for fixed A\n\nc Inputs:\nc A(M,N) - Matrix with physical dimensions (Mp,Np)\nc B(N) - R.H.S. of A X = B\nc M - Number of rows of A to use\nc N - Number of columns of A to use\nc Mp,NP - Storage dimensions of A(Mp,Np)\nc Wcut - Cutoff parameter\nc If Wcut = 0, writes answers into \"file\", all weights are kept\nc If Wcut < 0, reads previous answers from \"file\",\nc and uses -Wcut for weights to keep\nc If 0 < Wcut < 1 : Cuts off weights with w(i)/wmax < wcut\nc Use this to cut off small weights, does calculation\nc If Wcut = integer > 1, keeps Wcut weights, does calculation\nc Use this to cut off fixed number of weights\nc Output:\nc X(N) - Solution of A X = B\nc\n n1 = n\n\nc ALLOCATE local arrays\n ALLOCATE (u(mp,np), w(np), v(np,np), stat=istat)\n IF (istat .eq. 0) THEN !have enough memory\n iunit = 41\n\n x(:n1) = zero !zero answer from previous CALL\n wcuta = ABS(wcut)\nc...............................\nc If Wcut < 0 use precalculated weights to get answer fast\nc use wcuta = ABS(wcut) for everything\nc If any error happens while reading \"file\", do full svd calculation\n IF (wcut .lt. 0) THEN !Read file from previous calculation\n CALL safe_open(iunit, istat, file, 'old', 'formatted')\n IF (istat .ne. 0) GOTO 98\n READ (iunit, *, err=98)\n READ (iunit, *, err=98)\n READ (iunit, *, err=98) m, n, nonzero\n DO i = 1, n !Read exactly the same way they were written\n READ (iunit, *, err=98) w(i) !READ i-th weight\n DO j = 1, n\n READ (iunit, *, err=98) v(j,i)\n END DO\n DO j = 1, m\n READ (iunit, *, err=98) u(j,i)\n END DO\n END DO\n CLOSE(unit=iunit)\n\n GOTO 99 !Use U, w, V matrices to calculate X\n ENDIF !End of precalculated branch Wcut < 0\n 98 CONTINUE\nc.......................................\nc If Wcut .ge. 0, do full svd calculation\nc Initialize all to zero to wipe out effects of old call\n DO j = 1, n\n w(j) = zero !Zero all weights\n u(:m,j) = a(:m,j) !Because U will be changed by svdcmp\n v(:n,j) = zero\n END DO\n\n CALL svdcmp (u, m, n, mp, np, w, v) !Do SVD decomposition\n\nc Sort weights and matrices with DECREASING weights\nc Permute weight w(i) AND column vectors U(*,i), V(*,i) at the same time\n CALL sortsvd (m, n, mp, np, w, u, v)\n\nc Find the number of nonzero weights (already dcreasing ordered)\n DO nonzero = n, 1, -1\nc !Found first nonzero weight, get out\n IF (w(nonzero) .ne. 0) EXIT\n END DO\n IF (nonzero .le. 0) GOTO 999\n\nc............................................\nc Decide how many weights to keep\n 99 CONTINUE\n IF (wcuta .gt. 1) THEN\n nlast = wcuta\n ELSE !cutoff small weights\n wMAX = w(1) !weights are already ordered\n nlast = 0\n DO i = 1, nonzero\n IF (w(i) .gt. wmax*wcuta) THEN\n nlast = nlast + 1 !accept this weight\n ELSE\n GOTO 96\n END IF\n END DO\n END IF\n\nc Find solution X and basis vectors (put into columns of V)\nc This is the NR SVBKSB routine\n 96 CONTINUE\n IF (nlast.le.0 .or. nlast.gt.nonzero) nlast = nonzero\n DO i = 1, nlast !Calc i-th coeff (U.b/w) for noNonzero w(i)\nc First calculate i-th coeff (U(i)*b/w(i)) in the SUM in eq 14.3.17 (NR)\nc !Dot product of i-th column of U with B\nc !summed over all plasma points\n udotb = SUM(u(:m,i)*b(:m))\nc !=(Ui.b/wi) in eq 14.3.17, saves many divisions\n udotb = udotb/w(i)\nc Now run DOwn the i-th column of the vector V(j,i)\nc !j-th entry (row) of vectors in eq 14.3.17\nc !add it to the j-th entry of X\n x(:n) = x(:n) + udotb*v(:n,i)\nc !This did the svdbksb, faster than NR\n END DO !and also calculated the basis vectors\n\nc............................................\nc Write ALL weights and U, V into SVD file (IF Wcut=0)\n IF (wcut .eq. 0) THEN\n CALL safe_open(iunit, istat, file, 'unknown', 'formatted')\n WRITE (iunit, *) 'Max w = ', w(1), ', Min w = ', w(nonzero)\n WRITE (iunit, *) 'Ratio = ', w(1)/w(nonzero)\n WRITE (iunit, *) m, n, nonzero\n DO i = 1, n\n WRITE (iunit, *) w(i) !WRITE i-th weight\n DO j = 1, n\n WRITE (iunit, *) v(j,i)\n END DO\n DO j = 1, m\n WRITE (iunit, *) u(j,i)\n END DO\n END DO\n CLOSE(unit=iunit)\n END IF\nc................................................\n END IF\n 999 CONTINUE\n\n DEALLOCATE (u, w, v, stat=istat)\n\n END SUBROUTINE svdsolveuv\n", "meta": {"hexsha": "e264823fe7b99e80954c68306ab4429ff2372082", "size": 6834, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Sources/SVDpack/svdsolveuv.f", "max_stars_repo_name": "ORNL-Fusion/libstell", "max_stars_repo_head_hexsha": "92ac5c339b31e29d9d734c20eae3e7571de8f490", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-10-19T06:24:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-08T21:10:12.000Z", "max_issues_repo_path": "Sources/SVDpack/svdsolveuv.f", "max_issues_repo_name": "ORNL-Fusion/libstell", "max_issues_repo_head_hexsha": "92ac5c339b31e29d9d734c20eae3e7571de8f490", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-09-21T14:00:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-03T00:48:39.000Z", "max_forks_repo_path": "Sources/SVDpack/svdsolveuv.f", "max_forks_repo_name": "ORNL-Fusion/LIBSTELL", "max_forks_repo_head_hexsha": "ba938c678d776b84d7bb260ea541a9b45deb37e2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.1686746988, "max_line_length": 79, "alphanum_fraction": 0.4591747147, "num_tokens": 1866, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.7371581741774411, "lm_q1q2_score": 0.6562876662088329}} {"text": "module type_reference_element\n#include \n use mod_kinds, only: rk, ik\n use mod_constants, only: NFACES, ZERO, ONE, XI_DIR, ETA_DIR, ZETA_DIR\n use mod_gauss_legendre, only: quadrature_nodes, quadrature_weights\n use mod_nodes_uniform, only: uniform_nodes, uniform_weights\n use mod_polynomial, only: polynomial_val, dpolynomial_val, ddpolynomial_val\n use mod_inv, only: inv\n use ieee_arithmetic, only: ieee_is_nan\n implicit none\n\n\n\n\n !> A reference element data type.\n !!\n !! Contains references nodes/weights, interpolators, and projectors.\n !!\n !!\n !! \n !!\n !! nodes_r(.'s) for P1 element nodes_r(.'s) for P2 element\n !! .-----------. .-----.-----.\n !! / /| / / /|\n !! / / | .-----.-----. |\n !! / / | / / /| .\n !! .-----------. | .-----.-----. |/|\n !! | | | | | | . |\n !! | | . | | |/| .\n !! | | / .-----.-----. |/\n !! | | / | | | .\n !! | |/ | | |/\n !! .-----------. .-----.-----.\n !!\n !!\n !! \n !! Example of quadrature interpolation nodes(x's) on faces. Note,\n !! the interpolation nodes are independent of the element reference \n !! nodes, self%nodes_r.\n !!\n !! .-----------. .-----.-----.\n !! / x x /| / x / x /|\n !! / / | .-----.-----. |\n !! / x x / x| / x / x /|x.\n !! .-----------. | .-----.-----. |/|\n !! | |x x| | | |x.x|\n !! | x x | . | x | x |/| .\n !! | |x / .-----.-----.x|/\n !! | x x | / | x | x | .\n !! | |/ | | |/\n !! .-----------. .-----.-----.\n !! \n !!\n !! The interpolator matrices compute the interpolation of polynomial\n !! quantities at the interpolation nodes(x's).\n !!\n !! values_{at inodes} = matmul(val_e, modes)\n !!\n !! The nodes_to_modes projector matrix, acts on values at the reference\n !! nodes(nodes_r, .'s). When the nodes_to_modes projector matrix,\n !! acting on values located at nodes_r, computes modal coefficients\n !! representing the original quantity as a polynomial expansion on \n !! the reference element.\n !!\n !! modes = matmul(nodes_to_modes, values_{at nodes_r})\n !!\n !!\n !!\n !! @author Nathan A. Wukie (AFRL)\n !! @date 6/26/2017\n !!\n !---------------------------------------------------------------------\n type, public :: reference_element_t\n\n ! Reference element type/nodes\n integer(ik) :: element_type\n real(rk), allocatable :: nodes_r(:,:) ! Nodes defining the parametric reference element.\n real(rk), allocatable :: nodes_to_modes(:,:) ! linear projector. Takes values at 'nodes_r' and computes modal coefficients\n ! NOTE: nterms of the nodes_to_mdoes projector does not correspond to\n ! the number of terms in the interpolator matrices. The number of\n ! terms in the projector is equal to the number of reference\n ! nodes.\n\n ! Interpolator settings\n character(:), allocatable :: polynomial ! polynomial type being interpolated\n character(:), allocatable :: node_set ! node set defined for the interpolators\n integer(ik) :: level\n integer(ik) :: nterms_rule\n\n ! Interpolation nodes/weights\n real(rk), allocatable :: nodes_ie(:,:) ! nodes_3d(nnodes, 3). xi = nodes(:,1), eta = nodes(:,2), zeta = nodes(:,3)\n real(rk), allocatable :: iweights_e(:) ! weights_3d(nnodes)\n real(rk), allocatable :: nodes_if(:,:,:) ! nodes_2d(nnodes, 3, nfaces). xi = nodes(:,1,iface), eta = nodes(:,2,iface), zeta = nodes(:,3,iface)\n real(rk), allocatable :: iweights_f(:) ! weights_2d(nnodes)\n\n\n ! Interpolators\n real(rk), allocatable :: val_e(:,:) ! element interpolator, expansion value to elem nodes\n real(rk), allocatable :: ddxi_e(:,:) ! element interpolator, expansion ddxi to elem nodes\n real(rk), allocatable :: ddeta_e(:,:) ! element interpolator, expansion ddeta to elem nodes\n real(rk), allocatable :: ddzeta_e(:,:) ! element interpolator, expansion ddzeta to elem nodes\n\n real(rk), allocatable :: dd_dxidxi_e(:,:) ! element interpolator\n real(rk), allocatable :: dd_dxideta_e(:,:) ! element interpolator\n real(rk), allocatable :: dd_dxidzeta_e(:,:) ! element interpolator\n real(rk), allocatable :: dd_detadeta_e(:,:) ! element interpolator\n real(rk), allocatable :: dd_detadzeta_e(:,:) ! element interpolator\n real(rk), allocatable :: dd_dzetadzeta_e(:,:) ! element interpolator\n\n real(rk), allocatable :: val_f(:,:,:) ! face interpolator, expansion value to face nodes\n real(rk), allocatable :: ddxi_f(:,:,:) ! face interpolator, expansion ddxi to face nodes\n real(rk), allocatable :: ddeta_f(:,:,:) ! face interpolator, expansion ddeta to face nodes\n real(rk), allocatable :: ddzeta_f(:,:,:) ! face interpolator, expansion ddzeta to face nodes\n\n real(rk), allocatable :: dd_dxidxi_f(:,:,:) ! face interpolator, dxidxi\n real(rk), allocatable :: dd_dxideta_f(:,:,:) ! face interpolator, dxideta\n real(rk), allocatable :: dd_dxidzeta_f(:,:,:) ! face interpolator, dxidzeta\n real(rk), allocatable :: dd_detadeta_f(:,:,:) ! face interpolator, detadeta\n real(rk), allocatable :: dd_detadzeta_f(:,:,:) ! face interpolator, detadzeta\n real(rk), allocatable :: dd_dzetadzeta_f(:,:,:) ! face interpolator, dzetadzeta\n\n logical :: element_initialized = .false.\n logical :: nodes_initialized = .false.\n logical :: weights_initialized = .false.\n logical :: interpolation_initialized = .false.\n contains\n\n ! Initialize\n procedure :: init_element\n procedure :: init_interpolator\n procedure, private :: init_interpolator_nodes\n procedure, private :: init_interpolator_matrices\n\n ! Produce \n generic :: nodes => nodes_element, nodes_face\n procedure, private :: nodes_element\n procedure, private :: nodes_face\n\n generic :: weights => weights_element, weights_face\n procedure, private :: weights_element\n procedure, private :: weights_face\n\n generic :: interpolator => interpolate_element, interpolate_face\n procedure, private :: interpolate_element\n procedure, private :: interpolate_face\n \n ! Query\n procedure :: nnodes_r ! number of nodes in the reference node set\n procedure :: nnodes_ie ! Number of interpolation nodes in the element set\n procedure :: nnodes_if ! Number of interpolation nodes in the face set\n\n procedure :: nterms_r ! number of terms in the reference node data\n procedure :: nterms_i ! number of terms in the interpolator node data\n\n end type reference_element_t\n !********************************************************************\n\n\n\n\n\n\ncontains\n\n\n\n\n !> Initialize the reference element.\n !!\n !! @author Nathan A. Wukie (AFRL)\n !! @date 6/29/2017\n !!\n !-------------------------------------------------------------------\n subroutine init_element(self,element_type)\n class(reference_element_t), intent(inout) :: self\n integer(ik), intent(in) :: element_type\n\n real(rk), allocatable :: temp(:,:)\n integer(ik) :: nnodes, iterm, inode, ierr\n\n !\n ! Set element type, initialize reference nodes.\n !\n self%element_type = element_type\n self%nodes_r = uniform_nodes(element_type,dim=3)\n\n\n\n !\n ! Compute nodes-to-modes projection matrix\n !\n !\n ! Compute the values of each mapping term at each mesh point\n !\n nnodes = self%nnodes_r()\n if (allocated(temp)) deallocate(temp)\n allocate(temp(nnodes,nnodes), stat=ierr)\n if (ierr /= 0) call AllocationError\n\n do iterm = 1,nnodes\n do inode = 1,nnodes\n temp(inode,iterm) = polynomial_val(3,nnodes,iterm,[self%nodes_r(inode,1),self%nodes_r(inode,2),self%nodes_r(inode,3)])\n end do\n end do\n ! Invert matrix so that it can multiply a vector of\n ! element points to compute the mode amplitudes of the x,y mappings\n self%nodes_to_modes = inv(temp)\n\n\n self%element_initialized = .true.\n\n\n end subroutine init_element\n !*******************************************************************\n\n\n\n !> Initialize interpolation nodes.\n !!\n !! @param[in] polynomial String indicating the polynomial basis\n !! @param[in] nterms Number of terms in the polynomial expansion being interpolated from\n !! @param[in] node_set String indicating the node set being interpolated to\n !! @param[in] level Integer indicator for the level of resolution in the interpolation node set\n !! @param[in] nterms_rule Number of terms used as a rule to construct the node set resolution\n !!\n !! In the case where we want an interpolation from the mesh coordinate expansion\n !! to the quadrature nodes, we could use the number of terms in the mesh\n !! expansion for 'nterms' and the number of terms in the solution expansion\n !! for 'nterms_rule'. In this way, the quadrature node set used to interpolate\n !! the mesh coordinate expansion will coincide with the interpolation set\n !! for the solution expansion.\n !!\n !! @author Nathan A. Wukie (AFRL)\n !! @date 6/28/2017\n !!\n !-------------------------------------------------------------------\n subroutine init_interpolator(self,polynomial,nterms,node_set,level,nterms_rule)\n class(reference_element_t), intent(inout) :: self\n character(*), intent(in) :: polynomial\n integer(ik), intent(in) :: nterms\n character(*), intent(in) :: node_set\n integer(ik), intent(in) :: level\n integer(ik), intent(in) :: nterms_rule\n\n character(:), allocatable :: user_msg\n\n call self%init_interpolator_nodes(node_set,level,nterms_rule)\n\n call self%init_interpolator_matrices(polynomial,nterms)\n\n self%interpolation_initialized = .true.\n\n end subroutine init_interpolator\n !*******************************************************************\n\n\n\n\n\n\n\n !> Initialize the interpolation node set.\n !!\n !! nodes_ie\n !! iweights_e (maybe)\n !! nodes_if\n !! iweights_f (maybe)\n !!\n !! @author Nathan A. Wukie (AFRL)\n !! @date 6/29/2017\n !!\n !-----------------------------------------------------------------------\n subroutine init_interpolator_nodes(self,node_set,level,nterms_rule)\n class(reference_element_t), intent(inout) :: self\n character(*), intent(in) :: node_set\n integer(ik), intent(in) :: level\n integer(ik), intent(in) :: nterms_rule\n\n integer(ik) :: iface, ierr\n real(rk), allocatable :: nodes_3d(:,:), nodes_2d(:,:)\n real(rk), allocatable :: weights_3d(:), weights_2d(:)\n\n\n\n !\n ! Reset node/weight initialization flags\n !\n self%nodes_initialized = .false.\n self%weights_initialized = .false.\n\n self%node_set = trim(node_set)\n self%level = level\n self%nterms_rule = nterms_rule\n\n\n !\n ! Generate 3D/2D node sets\n !\n select case(trim(node_set))\n case('Uniform')\n nodes_3d = uniform_nodes(level,dim=3)\n nodes_2d = uniform_nodes(level,dim=2)\n weights_3d = uniform_weights(level,dim=3)\n weights_2d = uniform_weights(level,dim=2)\n\n\n case('Quadrature')\n nodes_3d = quadrature_nodes( nterms=nterms_rule, level=level,dim=3)\n nodes_2d = quadrature_nodes( nterms=nterms_rule, level=level,dim=2)\n weights_3d = quadrature_weights(nterms=nterms_rule, level=level,dim=3)\n weights_2d = quadrature_weights(nterms=nterms_rule, level=level,dim=2)\n\n self%weights_initialized = .true.\n case default\n call chidg_signal_one(FATAL,\"reference_element%init_nodes: requested node set not implemented.\", trim(node_set))\n end select\n\n\n !\n ! Set nodes (if provided)\n !\n if (allocated(nodes_3d) .and. allocated(nodes_2d)) then\n ! Set 3D element nodes\n self%nodes_ie = nodes_3d\n\n ! Set 2D face nodes\n if (allocated(self%nodes_if)) deallocate(self%nodes_if)\n allocate(self%nodes_if(size(nodes_2d,1),3,NFACES), stat=ierr)\n if (ierr /= 0) call AllocationError\n\n iface = 1\n self%nodes_if(:,1,iface) = -ONE\n self%nodes_if(:,2,iface) = nodes_2d(:,1)\n self%nodes_if(:,3,iface) = nodes_2d(:,2)\n\n iface = 2\n self%nodes_if(:,1,iface) = ONE\n self%nodes_if(:,2,iface) = nodes_2d(:,1)\n self%nodes_if(:,3,iface) = nodes_2d(:,2)\n\n iface = 3\n self%nodes_if(:,1,iface) = nodes_2d(:,1)\n self%nodes_if(:,2,iface) = -ONE\n self%nodes_if(:,3,iface) = nodes_2d(:,2)\n\n iface = 4\n self%nodes_if(:,1,iface) = nodes_2d(:,1)\n self%nodes_if(:,2,iface) = ONE\n self%nodes_if(:,3,iface) = nodes_2d(:,2)\n\n iface = 5\n self%nodes_if(:,1,iface) = nodes_2d(:,1)\n self%nodes_if(:,2,iface) = nodes_2d(:,2)\n self%nodes_if(:,3,iface) = -ONE\n\n iface = 6\n self%nodes_if(:,1,iface) = nodes_2d(:,1)\n self%nodes_if(:,2,iface) = nodes_2d(:,2)\n self%nodes_if(:,3,iface) = ONE\n\n\n self%nodes_initialized = .true.\n\n\n end if !nodes\n\n\n\n !\n ! Set weights (if provided)\n !\n if (allocated(self%iweights_e)) deallocate(self%iweights_e)\n if (allocated(self%iweights_f)) deallocate(self%iweights_f)\n if (allocated(weights_3d) .and. allocated(weights_2d)) then\n ! Set 3D element weights\n self%iweights_e = weights_3d\n\n ! Set 2D element weights\n self%iweights_f = weights_2d\n\n self%weights_initialized = .true.\n end if\n\n\n end subroutine init_interpolator_nodes\n !***********************************************************************\n\n\n\n\n\n\n\n\n\n\n !> Initialize polynomial interpolation matrices to compute polynomial\n !! quantities at the interpolation node locations.\n !!\n !!\n !! @author Nathan A. Wukie (AFRL)\n !! @date 6/29/2017\n !!\n !-----------------------------------------------------------------------\n subroutine init_interpolator_matrices(self,polynomial,nterms)\n class(reference_element_t), intent(inout) :: self\n character(*), intent(in) :: polynomial\n integer(ik), intent(in) :: nterms\n\n integer(ik) :: iterm, inode, iface, spacedim, ierr, nnodes\n real(rk) :: xi, eta, zeta\n real(rk), allocatable :: temp(:,:)\n\n\n !\n ! Store polynomial\n !\n self%polynomial = trim(polynomial)\n spacedim = 3\n\n\n !\n ! Compute element interpolators\n !\n if (allocated(self%val_e)) deallocate(self%val_e, &\n self%ddxi_e, &\n self%ddeta_e, &\n self%ddzeta_e, &\n self%dd_dxidxi_e, &\n self%dd_dxideta_e, &\n self%dd_dxidzeta_e, &\n self%dd_detadeta_e, &\n self%dd_detadzeta_e, &\n self%dd_dzetadzeta_e)\n allocate(self%val_e( self%nnodes_ie(), nterms), &\n self%ddxi_e( self%nnodes_ie(), nterms), &\n self%ddeta_e( self%nnodes_ie(), nterms), &\n self%ddzeta_e( self%nnodes_ie(), nterms), &\n self%dd_dxidxi_e( self%nnodes_ie(), nterms), &\n self%dd_dxideta_e( self%nnodes_ie(), nterms), &\n self%dd_dxidzeta_e( self%nnodes_ie(), nterms), &\n self%dd_detadeta_e( self%nnodes_ie(), nterms), &\n self%dd_detadzeta_e( self%nnodes_ie(), nterms), &\n self%dd_dzetadzeta_e(self%nnodes_ie(), nterms), stat=ierr)\n if (ierr /= 0) call AllocationError\n\n do iterm = 1,nterms\n do inode = 1,self%nnodes_ie()\n xi = self%nodes_ie(inode,1)\n eta = self%nodes_ie(inode,2)\n zeta = self%nodes_ie(inode,3)\n\n ! Value\n self%val_e( inode,iterm) = polynomial_val(spacedim,nterms,iterm,[xi,eta,zeta])\n\n ! First derivatives\n self%ddxi_e( inode,iterm) = dpolynomial_val(spacedim,nterms,iterm,[xi,eta,zeta],XI_DIR)\n self%ddeta_e( inode,iterm) = dpolynomial_val(spacedim,nterms,iterm,[xi,eta,zeta],ETA_DIR)\n self%ddzeta_e(inode,iterm) = dpolynomial_val(spacedim,nterms,iterm,[xi,eta,zeta],ZETA_DIR)\n\n ! Second/mixed derivatives\n self%dd_dxidxi_e( inode,iterm) = ddpolynomial_val(spacedim,nterms,iterm,[xi,eta,zeta],XI_DIR,XI_DIR )\n self%dd_dxideta_e( inode,iterm) = ddpolynomial_val(spacedim,nterms,iterm,[xi,eta,zeta],XI_DIR,ETA_DIR )\n self%dd_dxidzeta_e( inode,iterm) = ddpolynomial_val(spacedim,nterms,iterm,[xi,eta,zeta],XI_DIR,ZETA_DIR)\n\n self%dd_detadeta_e( inode,iterm) = ddpolynomial_val(spacedim,nterms,iterm,[xi,eta,zeta],ETA_DIR,ETA_DIR )\n self%dd_detadzeta_e( inode,iterm) = ddpolynomial_val(spacedim,nterms,iterm,[xi,eta,zeta],ETA_DIR,ZETA_DIR)\n\n self%dd_dzetadzeta_e(inode,iterm) = ddpolynomial_val(spacedim,nterms,iterm,[xi,eta,zeta],ZETA_DIR,ZETA_DIR)\n end do\n end do\n\n\n\n !\n ! Compute face interpolators\n !\n if (allocated(self%val_f)) deallocate(self%val_f, &\n self%ddxi_f, &\n self%ddeta_f, &\n self%ddzeta_f, &\n self%dd_dxidxi_f, &\n self%dd_dxideta_f, &\n self%dd_dxidzeta_f, &\n self%dd_detadeta_f, &\n self%dd_detadzeta_f, &\n self%dd_dzetadzeta_f)\n\n allocate(self%val_f( self%nnodes_if(), nterms, NFACES), &\n self%ddxi_f( self%nnodes_if(), nterms, NFACES), &\n self%ddeta_f( self%nnodes_if(), nterms, NFACES), &\n self%ddzeta_f( self%nnodes_if(), nterms, NFACES), &\n self%dd_dxidxi_f( self%nnodes_if(), nterms, NFACES), &\n self%dd_dxideta_f( self%nnodes_if(), nterms, NFACES), &\n self%dd_dxidzeta_f( self%nnodes_if(), nterms, NFACES), &\n self%dd_detadeta_f( self%nnodes_if(), nterms, NFACES), &\n self%dd_detadzeta_f( self%nnodes_if(), nterms, NFACES), &\n self%dd_dzetadzeta_f(self%nnodes_if(), nterms, NFACES), stat=ierr)\n if (ierr /= 0) call AllocationError\n\n do iface = 1,NFACES\n do iterm = 1,nterms\n do inode = 1,self%nnodes_if()\n xi = self%nodes_if(inode,1,iface)\n eta = self%nodes_if(inode,2,iface)\n zeta = self%nodes_if(inode,3,iface)\n\n ! Value\n self%val_f( inode,iterm,iface) = polynomial_val(spacedim,nterms,iterm,[xi,eta,zeta])\n\n ! First-derivatives\n self%ddxi_f( inode,iterm,iface) = dpolynomial_val(spacedim,nterms,iterm,[xi,eta,zeta],XI_DIR)\n self%ddeta_f( inode,iterm,iface) = dpolynomial_val(spacedim,nterms,iterm,[xi,eta,zeta],ETA_DIR)\n self%ddzeta_f(inode,iterm,iface) = dpolynomial_val(spacedim,nterms,iterm,[xi,eta,zeta],ZETA_DIR)\n\n ! Second/midxed-derivatives\n self%dd_dxidxi_f( inode,iterm,iface) = ddpolynomial_val(spacedim,nterms,iterm,[xi,eta,zeta],XI_DIR,XI_DIR)\n self%dd_dxideta_f( inode,iterm,iface) = ddpolynomial_val(spacedim,nterms,iterm,[xi,eta,zeta],XI_DIR,ETA_DIR)\n self%dd_dxidzeta_f( inode,iterm,iface) = ddpolynomial_val(spacedim,nterms,iterm,[xi,eta,zeta],XI_DIR,ZETA_DIR)\n self%dd_detadeta_f( inode,iterm,iface) = ddpolynomial_val(spacedim,nterms,iterm,[xi,eta,zeta],ETA_DIR,ETA_DIR)\n self%dd_detadzeta_f( inode,iterm,iface) = ddpolynomial_val(spacedim,nterms,iterm,[xi,eta,zeta],ETA_DIR,ZETA_DIR)\n self%dd_dzetadzeta_f( inode,iterm,iface) = ddpolynomial_val(spacedim,nterms,iterm,[xi,eta,zeta],ZETA_DIR,ZETA_DIR)\n\n end do\n end do\n end do\n\n\n end subroutine init_interpolator_matrices\n !***********************************************************************\n\n\n\n\n\n\n\n\n\n\n\n\n !>\n !!\n !!\n !!\n !!\n !-------------------------------------------------------------------\n function nodes_element(self) result(nodes_)\n class(reference_element_t), intent(in) :: self\n\n real(rk), allocatable :: nodes_(:,:)\n character(:), allocatable :: user_msg\n\n user_msg = \"reference_element_t: tried to return element nodes without being &\n initialized. Make sure init_nodes is getting called.\"\n if (.not. self%nodes_initialized) call chidg_signal(FATAL,user_msg)\n\n nodes_ = self%nodes_ie\n\n end function nodes_element\n !*******************************************************************\n\n\n !>\n !!\n !!\n !!\n !!\n !-------------------------------------------------------------------\n function nodes_face(self,iface) result(nodes_)\n class(reference_element_t), intent(in) :: self\n integer(ik), intent(in) :: iface\n\n real(rk), allocatable :: nodes_(:,:)\n character(:), allocatable :: user_msg\n\n user_msg = \"reference_element_t: tried to return face nodes without being &\n initialized. Make sure init_nodes is getting called.\"\n if (.not. self%nodes_initialized) call chidg_signal(FATAL,user_msg)\n\n nodes_ = self%nodes_if(:,:,iface)\n\n end function nodes_face\n !*******************************************************************\n\n\n\n\n !>\n !!\n !!\n !!\n !!\n !-------------------------------------------------------------------\n function weights_element(self) result(weights_)\n class(reference_element_t), intent(in) :: self\n\n real(rk), allocatable :: weights_(:)\n character(:), allocatable :: user_msg\n\n user_msg = \"reference_element_t: tried to return element weights without being &\n initialized. Make sure init_nodes is getting called.\"\n if (.not. self%weights_initialized) call chidg_signal(FATAL,user_msg)\n\n weights_ = self%iweights_e\n\n end function weights_element\n !*******************************************************************\n\n\n\n\n !>\n !!\n !! NOTE: we don't actually use the 'iface' argument in the call.\n !! it is just there to be consistent with the other calls and it\n !! also helps differentiate this routine from the weights_element\n !! routine for the generic interface.\n !!\n !! @author Nathan A. Wukie (AFRL)\n !!\n !!\n !-------------------------------------------------------------------\n function weights_face(self,iface) result(weights_)\n class(reference_element_t), intent(in) :: self\n integer(ik), intent(in) :: iface\n\n real(rk), allocatable :: weights_(:)\n character(:), allocatable :: user_msg\n\n user_msg = \"reference_element_t: tried to return face weights without being &\n initialized. Make sure init_nodes is getting called.\"\n if (.not. self%weights_initialized) call chidg_signal(FATAL,user_msg)\n\n weights_ = self%iweights_f\n\n end function weights_face\n !*******************************************************************\n\n\n\n\n\n\n\n\n !> Return an interpolator for the element volume node set.\n !!\n !! @author Nathan A. Wukie (AFRL)\n !! @date 6/28/2017\n !!\n !-------------------------------------------------------------------\n function interpolate_element(self,selector) result(interpolator_) \n class(reference_element_t), intent(in) :: self\n character(*), intent(in) :: selector\n\n real(rk), allocatable :: interpolator_(:,:)\n\n\n select case(trim(selector))\n case('Value')\n interpolator_ = self%val_e\n case('ddxi')\n interpolator_ = self%ddxi_e\n case('ddeta')\n interpolator_ = self%ddeta_e\n case('ddzeta')\n interpolator_ = self%ddzeta_e\n case('dxidxi')\n interpolator_ = self%dd_dxidxi_e\n case('dxideta')\n interpolator_ = self%dd_dxideta_e\n case('dxidzeta')\n interpolator_ = self%dd_dxidzeta_e\n case('detadeta')\n interpolator_ = self%dd_detadeta_e\n case('detadzeta')\n interpolator_ = self%dd_detadzeta_e\n case('dzetadzeta')\n interpolator_ = self%dd_dzetadzeta_e\n case default\n call chidg_signal_one(FATAL,\"reference_element%interpolate: Invalid selector for element interpolator.\", trim(selector))\n end select\n \n end function interpolate_element\n !*******************************************************************\n\n\n\n !> Return an interpolator for the face node set.\n !!\n !! @author Nathan A. Wukie (AFRL)\n !! @date 6/28/2017\n !!\n !-------------------------------------------------------------------\n function interpolate_face(self,selector,iface) result(interpolator_) \n class(reference_element_t), intent(in) :: self\n character(*), intent(in) :: selector\n integer(ik), intent(in) :: iface\n\n real(rk), allocatable :: interpolator_(:,:)\n\n\n select case(trim(selector))\n case('Value')\n interpolator_ = self%val_f(:,:,iface)\n case('ddxi')\n interpolator_ = self%ddxi_f(:,:,iface)\n case('ddeta')\n interpolator_ = self%ddeta_f(:,:,iface)\n case('ddzeta')\n interpolator_ = self%ddzeta_f(:,:,iface)\n case('dxidxi')\n interpolator_ = self%dd_dxidxi_f(:,:,iface)\n case('dxideta')\n interpolator_ = self%dd_dxideta_f(:,:,iface)\n case('dxidzeta')\n interpolator_ = self%dd_dxidzeta_f(:,:,iface)\n case('detadeta')\n interpolator_ = self%dd_detadeta_f(:,:,iface)\n case('detadzeta')\n interpolator_ = self%dd_detadzeta_f(:,:,iface)\n case('dzetadzeta')\n interpolator_ = self%dd_dzetadzeta_f(:,:,iface)\n case default\n call chidg_signal_one(FATAL,\"reference_element%interpolate: Invalid selector for face interpolator.\", trim(selector))\n end select\n \n end function interpolate_face\n !*******************************************************************\n\n\n\n\n\n !> Return number of nodes in the reference node set.\n !!\n !! @author Nathan A. Wukie (AFRL)\n !! @date 6/30/2017\n !!\n !-------------------------------------------------------------------\n pure function nnodes_r(self) result(nnodes)\n class(reference_element_t), intent(in) :: self\n\n integer(ik) :: nnodes\n\n !if (.not. self%element_initialized) call chidg_signal(FATAL,\"reference_element%nnodes_r: reference element has not been initialized.\")\n\n nnodes = size(self%nodes_r,1)\n\n end function nnodes_r\n !*******************************************************************\n\n\n\n\n !> Return number of nodes in the element interpolation node set.\n !!\n !! @author Nathan A. Wukie (AFRL)\n !! @date 6/30/2017\n !!\n !-------------------------------------------------------------------\n pure function nnodes_ie(self) result(nnodes)\n class(reference_element_t), intent(in) :: self\n\n integer(ik) :: nnodes\n\n !if (.not. self%interpolation_initialized) call chidg_signal(FATAL,\"reference_element%nnodes_i: interpolation has not been initialized.\")\n\n !nnodes = size(self%val_e,1)\n nnodes = size(self%nodes_ie,1)\n\n end function nnodes_ie\n !*******************************************************************\n\n\n !> Return number of nodes in the face interpolation node set.\n !!\n !! @author Nathan A. Wukie (AFRL)\n !! @date 6/30/2017\n !!\n !-------------------------------------------------------------------\n pure function nnodes_if(self) result(nnodes)\n class(reference_element_t), intent(in) :: self\n\n integer(ik) :: nnodes\n\n !if (.not. self%interpolation_initialized) call chidg_signal(FATAL,\"reference_element%nnodes_i: interpolation has not been initialized.\")\n\n !nnodes = size(self%val_f,1)\n nnodes = size(self%nodes_if,1)\n\n end function nnodes_if\n !*******************************************************************\n\n\n\n\n\n\n\n !> Return number of terms in the linear projector.\n !!\n !! NOTE: the number of terms in the linear projector matrix should\n !! equal the number of nodes defined for the reference element.\n !!\n !! @author Nathan A. Wukie (AFRL)\n !! @date 6/30/2017\n !!\n !-------------------------------------------------------------------\n function nterms_r(self) result(nterms)\n class(reference_element_t), intent(in) :: self\n\n integer(ik) :: nterms\n\n if (.not. self%element_initialized) call chidg_signal(FATAL,\"reference_element%nterms_r: reference element has not been initialized.\")\n\n nterms = size(self%nodes_to_modes,1)\n\n end function nterms_r\n !*******************************************************************\n\n\n\n\n !> Return number of terms the interpolators are contstructed for.\n !!\n !!\n !! @author Nathan A. Wukie (AFRL)\n !! @date 6/30/2017\n !!\n !-------------------------------------------------------------------\n function nterms_i(self) result(nterms)\n class(reference_element_t), intent(in) :: self\n\n integer(ik) :: nterms\n\n if (.not. self%interpolation_initialized) call chidg_signal(FATAL,\"reference_element%nterms_i: reference element interpolators have not been initialized.\")\n\n nterms = size(self%val_e,2)\n\n end function nterms_i\n !*******************************************************************\n\n\nend module type_reference_element\n", "meta": {"hexsha": "783aab03a57be7ed12687b04b0e1d16c652ad554", "size": 33170, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/grid/type_reference_element.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/grid/type_reference_element.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/grid/type_reference_element.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": 39.1155660377, "max_line_length": 163, "alphanum_fraction": 0.5036177269, "num_tokens": 7986, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942348544447, "lm_q2_score": 0.7371581626286833, "lm_q1q2_score": 0.6562876623642119}} {"text": "c............................................................rinvgj\n SUBROUTINE rinvgj(ainv,a,arraydim,n)\nC ********************************************************************\nC * *\nC * AINV = A**(-1) *\nC * *\nC * invert A using the GAUSS-JORDAN - algorithm *\nC * the 1- matrix is not set up and use is made of its structure *\nC * *\nC * REAL*8 VERSION *\nC * *\nC ********************************************************************\n\n IMPLICIT NONE\nc scan columns\nC .. Scalar Arguments ..\n INTEGER arraydim,n\nC ..\nC .. Array Arguments ..\n REAL a(arraydim,arraydim),ainv(arraydim,arraydim)\nC ..\nC .. Local Scalars ..\n REAL t,t1\n INTEGER icol,l,ll\nC ..\n DO 60 icol = 1,n\nc make A(ICOL,ICOL) = 1\n t1 = 1.0/a(icol,icol)\n DO 10 l = (icol+1),n\n a(icol,l) = a(icol,l)*t1\n 10 CONTINUE\n DO 20 l = 1, (icol-1)\n ainv(icol,l) = ainv(icol,l)*t1\n 20 CONTINUE\n ainv(icol,icol) = t1\nc make A(LL,ICOL) = 0 for LL<>ICOL\n DO 50 ll = 1,n\n IF (ll.NE.icol) THEN\n t = a(ll,icol)\n DO 30 l = (icol+1),n\n a(ll,l) = a(ll,l) - a(icol,l)*t\n 30 CONTINUE\n DO 40 l = 1, (icol-1)\n ainv(ll,l) = ainv(ll,l) - ainv(icol,l)*t\n 40 CONTINUE\n ainv(ll,icol) = -t1*t\n END IF\n 50 CONTINUE\n 60 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "bd3c1c7551bb046a437d3d9c925bac6f3e437b81", "size": 1993, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "core/rinvgj.f", "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": "core/rinvgj.f", "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": "core/rinvgj.f", "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": 38.3269230769, "max_line_length": 72, "alphanum_fraction": 0.3025589563, "num_tokens": 474, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.737158174177441, "lm_q1q2_score": 0.656287661917385}} {"text": "! initialize.f90\n! author: sunder\n\n!-----------------------------------------------------------------------\n! Allocate memory, initialize various data and also the initial\n! condition\n!-----------------------------------------------------------------------\n\nsubroutine initialize\n use ader_weno\n implicit none\n \n integer :: i, j, p, m, alpha, q, center, L, iGP\n double precision, dimension(0:N) :: phi_p, phi_m, phi\n double precision, dimension(N+1,N+1) :: MS, FRm\n double precision, dimension(nVar) :: q0\n double precision, dimension(N+1) :: phi_xi, phi_i\n double precision :: xiL, xiR, shift, xp, total\n \n ! Initialize basic stuff \n \n dx = (xR - xL)/REAL(IMAX)\n dt = CFL*dx \n time = 0.0d0\n timestep = 0\n nDOF = N+1\n \n if (mod(N,2) .eq. 0) then\n nStencils = 3 \n else\n nStencils = 4\n end if\n \n nGhostCells = 2*(N+1) -1\n \n ! Allocate required memory \n \n allocate( x(1-nGhostCells:IMAX+nGhostCells) )\n allocate( uh(nVar, 1-nGhostCells:IMAX+nGhostCells) )\n allocate( duh(nVar, IMAX) )\n allocate( qbnd(nVar, 2, 0:IMAX+1) ) ! 2 corresponds to 2 faces per cell\n allocate( Fbnd(nVar, 2, 0:IMAX+1) )\n allocate( F(nVar, IMAX+1) )\n \n ! Initialize the grid \n \n do i = 1-nGhostCells, IMAX+nGhostCells\n x(i) = xL + (REAL(i)-0.5)*dx\n end do\n \n ! Basis functions \n \n xiL = 0.0d0\n xiR = 1.0d0\n \n allocate( xGP(N+1) )\n allocate( wGP(N+1) )\n allocate( phiL(N+1) )\n allocate( phiR(N+1) )\n \n call gauleg(xiL, xiR, xGP, wGP, N+1)\n \n ! Find the basis function values at the left and the right end of the unit cell \n \n do i = 1, N+1\n call lagrange_basis_values(i, xiL, phi)\n phiL(i) = phi(0)\n call lagrange_basis_values(i, xiR, phi)\n phiR(i) = phi(0)\n end do\n \n ! WENO Related data \n \n allocate (lin_wt(nStencils)) ! Calculate linear weights\n\n lin_wt(1) = lambda_s\n lin_wt(2) = lambda_s\n lin_wt(3) = lambda\n\n if (nStencils .eq. 4) then\n lin_wt(4) = lambda\n end if\n\n total = sum(lin_wt)\n\n lin_wt = lin_wt/total\n\n allocate( OS_M(N+1, N+1) ) ! Initialize the oscillation indicator matrix\n \n OS_M = 0.0d0\n \n do p = 1, N+1\n do m = 1, N+1\n do q = 1, N+1\n call lagrange_basis_values(p, xGP(q), phi_p)\n call lagrange_basis_values(m, xGP(q), phi_m)\n do alpha = 1, N\n OS_M(p,m) = OS_M(p,m) + wGP(q)*phi_p(alpha)*phi_m(alpha)\n end do\n end do\n end do\n end do\n \n allocate( iMCL(N+1, N+1) ) ! Initialize center left stencil coefficient matrix\n allocate( iML(N+1, N+1) ) ! Initialize left-sided coefficient matrix\n allocate( iMCR(N+1, N+1) ) ! Initialize center right-sided coefficient matrix\n allocate( iMR(N+1, N+1) ) ! Initialize right-sided coefficient matrix\n \n ! Centered left side stencil \n \n MS = 0.0d0\n L = floor(real(N/2)) + 1\n \n do i = 1, N+1\n center = i - 1 - L\n do j = 1, N+1\n do q = 1, N+1\n shift = xGP(q) + DBLE(center)\n call lagrange_basis_values(j, shift, phi)\n MS(i,j) = MS(i,j) + wGP(q)*phi(0)\n end do\n end do\n end do\n \n call MatrixInverse(N+1,MS,iMCL)\n \n ! Centered right side stencil (Use this stencil for odd-ordered schemes)\n \n MS = 0.0d0\n L = floor(real(N/2))\n \n do i = 1, N+1\n center = i - 1 - L\n do j = 1, N+1\n do q = 1, N+1\n shift = xGP(q) + DBLE(center)\n call lagrange_basis_values(j, shift, phi)\n MS(i,j) = MS(i,j) + wGP(q)*phi(0)\n end do\n end do\n end do\n \n call MatrixInverse(N+1,MS,iMCR)\n \n ! Left sided stencil \n \n MS = 0.0d0\n L = N \n \n do i = 1, N+1\n center = i - 1 - L\n do j = 1, N+1\n do q = 1, N+1\n shift = xGP(q) + dble(center)\n call lagrange_basis_values(j, shift, phi)\n MS(i,j) = MS(i,j) + wGP(q)*phi(0)\n end do\n end do\n end do\n \n call MatrixInverse(N+1,MS,iML)\n \n ! Right sided stencil \n \n MS = 0.0d0\n L = 0\n \n do i = 1, N+1\n center = i - 1 - L\n do j = 1, N+1\n do q = 1, N+1\n shift = xGP(q) + DBLE(center)\n call lagrange_basis_values(j, shift, phi)\n MS(i,j) = MS(i,j) + wGP(q)*phi(0)\n end do\n end do\n end do\n \n call MatrixInverse(N+1,MS,iMR)\n \n ! ADER related data \n \n allocate( Kxi(N+1, N+1) ) ! Element stiffness matrix\n allocate( K1(N+1, N+1) ) ! Element stiffness matrix\n allocate( iK1(N+1, N+1) ) ! Element stiffness matrix\n allocate( F0(N+1) ) ! Time flux matrix\n \n Kxi = 0.0d0\n \n DO iGP = 1, N+1\n call BaseFunc1D(phi_i,phi_xi,xGP(iGP))\n DO i = 1, N+1\n DO j = 1, N+1\n Kxi(i,j) = Kxi(i,j) + wGP(iGP)*phi_xi(i)*phi_i(j)\n end do\n end do\n end do\n \n do i = 1, N+1\n do j = 1, N+1\n FRm(i,j) = phiR(i)*phiR(j) ! Left contribution to the right flux matrix (m = left of the interface)\n end do\n end do\n \n ! The time flux matrices for the ADER-DG predictor method are given by the principle of upwinding in time (causality principle)\n K1 = FRm - Kxi ! upwinding in time = information comes from smaller times\n F0 = phiL ! upwinding in time = information comes from smaller times\n call MatrixInverse(N+1,K1,iK1)\n \n \n ! Initialize the solution \n \n do i = 1, IMAX\n uh(:,i) = 0.0\n do q = 1, N+1\n xp = x(i) - 0.5d0*dx + dx*xGP(q)\n call initial_field(q0, xp)\n uh(:,i) = uh(:,i) + wGP(q)*q0\n end do\n end do\n \nend subroutine initialize\n", "meta": {"hexsha": "a566901389e4d83dbd21b037592df83ca017ed79", "size": 5931, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ADER-WENO-1D-LINEAR-CONVECTION/initialize.f90", "max_stars_repo_name": "dasikasunder/ADER-WENO", "max_stars_repo_head_hexsha": "8d40b341be7610ac89a144077a9f759a0154909a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-12-19T07:50:53.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-19T07:50:53.000Z", "max_issues_repo_path": "ADER-WENO-1D-LINEAR-CONVECTION/initialize.f90", "max_issues_repo_name": "dasikasunder/ADER-WENO", "max_issues_repo_head_hexsha": "8d40b341be7610ac89a144077a9f759a0154909a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ADER-WENO-1D-LINEAR-CONVECTION/initialize.f90", "max_forks_repo_name": "dasikasunder/ADER-WENO", "max_forks_repo_head_hexsha": "8d40b341be7610ac89a144077a9f759a0154909a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.5964125561, "max_line_length": 131, "alphanum_fraction": 0.5066599224, "num_tokens": 1929, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.890294223211224, "lm_q2_score": 0.7371581684030621, "lm_q1q2_score": 0.6562876589222129}} {"text": "!/home/zq822358/programming/ppvi/PVItoolbox\n\nmodule pv_inversion\n\nimplicit none\n\ncontains\n\n subroutine balnc(fco, aps, ac, h, s, qe, tha, pe, part, thrs, maxx, maxxt, &\n omegs, omegh, nx, ny, nl)\n ! Calculates geopotential height and streamfunction by inverting an\n ! input pv field using the charney (1955) balance equation.\n\n !f2py integer, intent(hide) :: nx, ny, nl\n !f2py real, intent(in) :: fco(nx,ny)\n !f2py real, intent(in) :: aps(nx,ny)\n !f2py real, intent(in) :: ac(ny,5)\n !f2py real, intent(inout) :: h(nx,ny,nl)\n !f2py real, intent(inout) :: s(nx,ny,nl)\n !f2py real, intent(inout) :: qe(nx,ny,nl)\n !f2py real, intent(inout) :: tha(nx,ny,2)\n !f2py real, intent(in) :: pe(nl)\n !f2py real, intent(in) :: part\n !f2py real, intent(in) :: thrs\n !f2py integer, intent(in) :: maxx\n !f2py integer, intent(in) :: maxxt\n !f2py real, intent(in) :: omegs\n !f2py real, intent(in) :: omegh\n\n !-Input variables-------------------------------------------------------------\n ! Grid dimensions\n integer, intent(in) :: nx, ny, nl\n\n ! coriolis parameter\n real, intent(in) :: fco(nx,ny)\n\n ! ap ! cos(latitude)\n real, intent(in) :: aps(nx,ny)\n \n ! a ! coefficients for 2-d laplacian operator\n real, intent(in) :: ac(ny,5)\n\n ! hz ! geopotential height\n real, intent(inout) :: h(nx,ny,nl)\n\n ! si ! streamfunction\n real, intent(inout) :: s(nx,ny,nl)\n\n ! q ! pv (/0.01 pvu)\n real, intent(inout) :: qe(nx,ny,nl)\n\n ! tha(i,j,m)= boundary theta\n ! m=1 is lower boundary (midway between k=1 and k=2)\n ! m=2 is upper boundary (midway between k=nl-1 and k=nl)\n real, intent(inout) :: tha(nx,ny,2)\n\n ! pi ! exner function\n real, intent(in) :: pe(nl)\n\n ! prt ! relaxation parameter\n real, intent(in) :: part\n\n ! thr ! threshold parameter\n real, intent(in) :: thrs\n\n ! max ! maximum iterations\n real, intent(in) :: maxx\n\n ! maxt ! maximum cycles\n real, intent(in) :: maxxt\n\n ! omegas ! relaxation parameter for 2-d poisson equation\n real, intent(in) :: omegs\n\n ! omegah ! relaxation parameter for 3-d poisson equation\n real, intent(in) :: omegh\n\n !-Local variables-------------------------------------------------------------\n real :: mi,zm,rh(ny,nx,nl),zpl(ny,nx),zpp(ny),rs,gpts, &\n & stb(ny,nx,nl),asi(ny,nx,nl),bb(nl),bh(nl),bl(nl), &\n & vor,old(ny,nx,nl),dpi2(nl),nlco(ny,nx),coef(ny,nl), &\n & dh(ny,nx,nl),znl,rhs(ny,nx,nl),delh(ny,nx,nl), &\n & dsi(ny,nx,nl),vozro(nl),spzro(nl),maxhz(nl), &\n & minvor(nl),maxvor(nl), &\n & betas,dhmax,rha,rhst,sxx,sxy,syy, &\n & zhl,zhp,zmrs,zl,zsl,zsp,zp\n\n integer :: i,J,K,igtz,ihm,iitot,iltz,insq, &\n & itc,itc1,itcm,itcold,itct,jhm,khm\n\n logical :: it,icon\n\n!-----------------------------------------------------------------------!\n! start of subroutine !\n!-----------------------------------------------------------------------!\n mi=9999.90\n gpts=float(ny*nx*(nl-2))\n\n iltz=0\n igtz=0\n insq=0\n itct=0\n itc1=0\n itc=0\n iitot=0\n itcold=0\n\n do k=1,nl\n vozro(k)=0.\n minvor(k)=100000.\n maxvor(k)=-100000.\n end do\n\n do i=2,ny-1\n zpp(i)=1./16.\n do j=2,nx-1\n zpl(i,j)=1./(16.*aps(i,j)*aps(i,j))\n nlco(i,j)=2./( aps(i,j)*aps(i,j) )\n end do\n end do\n\n do k=1,nl\n bb(k)=0.\n bh(k)=0.\n bl(k)=0.\n end do\n\n do k=2,nl-1\n bb(k)=-2./( (pe(k+1)-pe(k))*(pe(k)-pe(k-1)) )\n bh(k)=2./( (pe(k+1)-pe(k))*(pe(k+1)-pe(k-1)) )\n bl(k)=2./( (pe(k)-pe(k-1))*(pe(k+1)-pe(k-1)) )\n dpi2(k)=(pe(k+1) - pe(k-1))/2.\n do i=1,ny\n coef(i,k)=ac(i,3)/bb(k)\n end do\n end do\n\n do k=1,nl\n maxhz(k)=0\n end do\n\n do k=1,nl\n do j=1,nx\n do i=1,ny\n old(i,j,k)=h(i,j,k)\n if (h(i,j,k)>maxhz(k)) then\n maxhz(k)=h(i,j,k)\n end if\n end do\n end do\n end do\n!-----------------------------------------------------------------------!\n\n 900 continue\n if (iitot == 0) go to 700\n itcm=0\n itc1=0\n do k=1,nl\n spzro(k)=0.\n end do\n\n do k=2,nl-1\n do j=2,nx-1\n do i=2,ny-1\n old(i,j,k)=s(i,j,k)\n if (k == 2) then\n old(i,j,1)=s(i,j,1)\n else if (k == nl-1) then\n old(i,j,nl)=s(i,j,nl)\n end if\n delh(i,j,k)= ac(i,1)*h(i-1,j,k) + ac(i,2)*h(i,j-1,k) + &\n & ac(i,3)*h(i,j,k) + ac(i,4)*h(i,j+1,k) + &\n & ac(i,5)*h(i+1,j,k)\n\n stb(i,j,k)=bl(k)*h(i,j,k-1) + bh(k)*h(i,j,k+1) + &\n & bb(k)*h(i,j,k)\n\n if (stb(i,j,k) <= 0.0001) then\n stb(i,j,k)=0.0001\n \n! modify boundary theta (k=2) or pv if static stability\n! becomes too small. theta becomes smaller; pv becomes larger\n! by a small amount (0.2 nondimensionally, which works out to\n! be perhaps a tenth of a degree K.\n \n if (k == 2) then\n tha(i,j,1)=tha(i,j,1)-0.2\n end if\n qe(i,j,k)=qe(i,j,k) + 0.2/(pe(k)-pe(k+1))\n spzro(k)=spzro(k) + 1\n end if\n sxx=s(i,j+1,k) + s(i,j-1,k) - 2.*s(i,j,k)\n syy=s(i-1,j,k) + s(i+1,j,k) - 2.*s(i,j,k)\n sxy=( s(i-1,j+1,k) - s(i-1,j-1,k) - &\n & s(i+1,j+1,k) + s(i+1,j-1,k) )/4.\n betas=0.25*((fco(i-1,j)-fco(i+1,j))* &\n & (s(i-1,j,k)-s(i+1,j,k)) + & \n & (fco(i,j+1)-fco(i,j-1))* &\n & (s(i,j+1,k)-s(i,j-1,k)) )\n zhp=h(i-1,j,k+1)-h(i+1,j,k+1)-h(i-1,j,k-1)+h(i+1,j,k-1)\n zhl=h(i,j+1,k+1)-h(i,j-1,k+1)-h(i,j+1,k-1)+h(i,j-1,k-1)\n zsp=s(i-1,j,k+1)-s(i+1,j,k+1)-s(i-1,j,k-1)+s(i+1,j,k-1)\n zsl=s(i,j+1,k+1)-s(i,j-1,k+1)-s(i,j+1,k-1)+s(i,j-1,k-1)\n zl=zpl(i,j)*zhl*zsl/(dpi2(k)*dpi2(k))\n zp=zpp(i)*zhp*zsp/(dpi2(k)*dpi2(k))\n znl=nlco(i,j)*( sxx*syy - sxy*sxy ) + betas\n rhst = qe(i,j,k) - fco(i,j)*stb(i,j,k) + delh(i,j,k) - &\n & znl + zl + zp\n rhs(i,j,k)=rhst/(fco(i,j) + stb(i,j,k))\n\n end do\n end do\n end do\n\n 23 format(f6.0,' neg stabilities.')\n do k=1,nl\n spzro(k)=0.\n end do\n\n!*************iteration for psi **********************\n do k=2,nl-1\n itc=0\n 800 continue\n it=.true.\n do j=2,nx-1\n do i=2,ny-1\n rs = ac(i,1)*s(i-1,j,k) + ac(i,2)*s(i,j-1,k) + &\n & ac(i,3)*s(i,j,k) + ac(i,4)*s(i,j+1,k) + &\n & ac(i,5)*s(i+1,j,k) - rhs(i,j,k)\n dsi(i,j,k)=-omegs*rs/ac(i,3)\n s(i,j,k) = s(i,j,k) + dsi(i,j,k)\n!*******check accuracy criterion *******************************\n if (abs(dsi(i,j,k)) > thrs) then\n it=.false.\n end if\n end do\n end do\n \n itc=itc+1\n if (it) then\n icon=.true.\n if (itc > itcm) itcm=itc\n if (itc == 1) itc1=itc1 + 1\n else\n if (itc < maxx) then\n go to 800\n else\n icon=.true.\n end if\n end if\n end do\n\n if (iitot > 0) then\n itct=itct + itcm\n do k=1,nl\n do j=2,nx-1\n do i=2,ny-1\n s(i,j,k)=part*s(i,j,k) + (1.-part)*old(i,j,k)\n old(i,j,k)=h(i,j,k)\n end do\n end do\n end do\n end if\n\n!*************calculate the rhs of bal-pv eQuation (phi,h) ************\n\n 700 continue\n do k=2,nl-1\n do j=2,nx-1\n do i=2,ny-1\n vor = ac(i,1)*s(i-1,j,k) + ac(i,2)*s(i,j-1,k) + &\n & ac(i,3)*s(i,j,k) + ac(i,4)*s(i,j+1,k) + &\n & ac(i,5)*s(i+1,j,k)\n if (vor <= minvor(k)) then\n minvor(k)=vor\n end if\n if (vor >= maxvor(k)) then\n maxvor(k)=vor\n end if\n if (vor <= 0.0001-fco(i,j)) then\n vor = (0.0001 - fco(i,j))\n! increase pv where absolute vorticity is too small. similar to\n! case where stratification is too small.\n qe(i,j,k)=qe(i,j,k) + 0.01\n vozro(k)=vozro(k) + 1\n end if\n asi(i,j,k)=fco(i,j) + vor\n sxx=s(i,j+1,k)+s(i,j-1,k)-2.*s(i,j,k)\n syy=s(i-1,j,k)+s(i+1,j,k)-2.*s(i,j,k)\n sxy=( s(i-1,j+1,k) - s(i-1,j-1,k) - &\n & s(i+1,j+1,k) + s(i+1,j-1,k) )/4.\n zhp=h(i-1,j,k+1)-h(i+1,j,k+1)-h(i-1,j,k-1)+h(i+1,j,k-1)\n zhl=h(i,j+1,k+1)-h(i,j-1,k+1)-h(i,j+1,k-1)+h(i,j-1,k-1)\n zsp=s(i-1,j,k+1)-s(i+1,j,k+1)-s(i-1,j,k-1)+s(i+1,j,k-1)\n zsl=s(i,j+1,k+1)-s(i,j-1,k+1)-s(i,j+1,k-1)+s(i,j-1,k-1)\n zl=zpl(i,j)*zhl*zsl/(dpi2(k)*dpi2(k))\n zp=zpp(i)*zhp*zsp/(dpi2(k)*dpi2(k))\n betas=0.25*( &\n & ( fco(i-1,j) - fco(i+1,j) )* &\n & ( s(i-1,j,k) - s(i+1,j,k) ) + & \n & ( fco(i,j+1) - fco(i,j-1) )* &\n & ( s(i,j+1,k) - s(i,j-1,k) ) )\n rha=fco(i,j)*vor + nlco(i,j)*(sxx*syy - sxy*sxy) + betas\n rh(i,j,k)=rha + qe(i,j,k) + zl + zp\n \n end do\n end do\n end do\n\n 24 format(i11,2f11.3,f6.0,' neg abs vorticities in phi eQ.')\n do k=1,nl\n vozro(k)=0.\n end do\n\n!*************solve for h at each level *****************\n\n itc=0\n 701 it=.true.\n zmrs=0.\n do k=2,nl-1\n do j=2,nx-1\n do i=2,ny-1\n if (k == 2) then\n rs = ac(i,1)*h(i-1,j,k) + &\n & ac(i,2)*h(i,j-1,k) + &\n & (ac(i,3) + asi(i,j,k)*(bb(k)+bl(k)) )*h(i,j,k) + &\n & ac(i,4)*h(i,j+1,k) + & \n & ac(i,5)*h(i+1,j,k) + &\n & asi(i,j,k)*(bh(k)*h(i,j,k+1) + &\n & tha(i,j,1)/dpi2(k)) - rh(i,j,k)\n zm = h(i,j,k)\n h(i,j,k) = zm - omegh*rs/(ac(i,3) + &\n & asi(i,j,k)*(bb(k)+bl(k)))\n \n else if (k == nl-1) then\n rs = ac(i,1)*h(i-1,j,k) + & \n & ac(i,2)*h(i,j-1,k) + &\n & (ac(i,3) + asi(i,j,k)*(bb(k)+bh(k)) )*h(i,j,k) + &\n & ac(i,4)*h(i,j+1,k) + &\n & ac(i,5)*h(i+1,j,k) + &\n & asi(i,j,k)*(bl(k)*h(i,j,k-1) - &\n & tha(i,j,2)/dpi2(k)) - rh(i,j,k)\n zm = h(i,j,k)\n h(i,j,k) = zm - omegh*rs/(ac(i,3) + &\n & asi(i,j,k)*(bb(k)+bh(k)))\n \n else\n rs = ac(i,1)*h(i-1,j,k) + &\n & ac(i,2)*h(i,j-1,k) + &\n & (ac(i,3) + asi(i,j,k)*bb(k) )*h(i,j,k) + &\n & ac(i,4)*h(i,j+1,k) + &\n & ac(i,5)*h(i+1,j,k) + &\n & asi(i,j,k)*( bh(k)*h(i,j,k+1) + &\n & bl(k)*h(i,j,k-1) ) - &\n & rh(i,j,k)\n zm = h(i,j,k)\n h(i,j,k) = zm - omegh*rs/(ac(i,3) + &\n & asi(i,j,k)*bb(k))\n end if\n dh(i,j,k)=h(i,j,k) - zm\n zmrs=zmrs + abs(dh(i,j,k))\n if (abs(dh(i,j,k)) > thrs) then\n it=.false.\n end if\n\n end do\n end do\n end do\n\n if (amod(float(itc),5.) == 0) then\n dhmax=thrs/10.\n zmrs=zmrs/gpts\n do k=2,nl-1\n do j=2,nx-1\n do i=2,ny-1\n if (abs(dh(i,j,k)) > dhmax) then\n dhmax=abs(dh(i,j,k))\n ihm=i\n jhm=j\n khm=k\n end if\n end do\n end do\n end do\n\n 716 format(2e9.2,3i5,f8.3)\n end if\n zmrs=0.\n\n itc=itc+1\n if (it) then\n itct=itct + itc\n do j=1,nx\n do i=1,ny\n h(i,j,1) = h(i,j,2) + tha(i,j,1)*(pe(2)-pe(1))\n s(i,j,1) = s(i,j,2) + tha(i,j,1)*(pe(2)-pe(1))\n h(i,j,nl) = h(i,j,nl-1) - tha(i,j,2)*(pe(nl)-pe(nl-1))\n s(i,j,nl) = s(i,j,nl-1) - tha(i,j,2)*(pe(nl)-pe(nl-1))\n end do\n end do\n \n if (iitot > 0) then\n do k=1,nl\n do j=2,nx-1\n do i=2,ny-1\n h(i,j,k)=part*h(i,j,k) + (1.-part)*old(i,j,k)\n end do\n end do\n end do\n end if\n if ( (itc > itcold+10).and.(iitot > 30) ) then\n print*,'started diverging'\n go to 901\n end if\n itcold=itc\n if ((itc == 1).and.(itc1 == nl-2)) then\n print*,'total convergence.'\n else\n iitot=iitot + 1\n 22 format(i4,' total iteration(s).')\n if (iitot > maxxt) then\n print*,'too many total iterations.'\n go to 901\n else\n go to 900\n end if\n end if\n else\n if (itc < maxx) then\n go to 701\n else\n print*,'too many iterations for hght.'\n icon=.false.\n go to 901\n end if\n end if\n!*******************************************************\n 901 return\n end subroutine balnc\n\nend module pv_inversion\n", "meta": {"hexsha": "2bc764b1fa861eb53ae4aefd6d8489ab47aaf621", "size": 14588, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "myscripts/fortran/pvi.f90", "max_stars_repo_name": "LSaffin/scripts", "max_stars_repo_head_hexsha": "100fc442229ea11f8766a6d78b4db8790c607326", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-03-16T13:54:28.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-16T13:54:28.000Z", "max_issues_repo_path": "myscripts/fortran/pvi.f90", "max_issues_repo_name": "LSaffin/scripts", "max_issues_repo_head_hexsha": "100fc442229ea11f8766a6d78b4db8790c607326", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "myscripts/fortran/pvi.f90", "max_forks_repo_name": "LSaffin/scripts", "max_forks_repo_head_hexsha": "100fc442229ea11f8766a6d78b4db8790c607326", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-01-16T04:54:53.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-16T04:54:53.000Z", "avg_line_length": 33.0045248869, "max_line_length": 81, "alphanum_fraction": 0.3613243762, "num_tokens": 4999, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.7371581568543044, "lm_q1q2_score": 0.656287655077592}} {"text": " \nC \nC FFTPACKAGE FOR PSEUDOSPECTRAL ADVECTION CALCULATIONS 05/04/84 \nC \nC PURPOSE THIS PACKAGE CONSISTS OF PROGRAMS WHICH PERFORM FAST FOURIER \nC TRANSFORMS FOR BOTH COMPLEX AND REAL PERIODIC SEQUENCES AND \nC CERTIAN OTHER SYMMETRIC SEQUENCES THAT ARE LISTED BELOW. \nC \nC RFFTI INITIALIZE RFFTF AND RFFTB \nC RFFTF FORWARD TRANSFORM OF A REAL PERIODIC SEQUENCE \nC RFFTB BACKWARD TRANSFORM OF A REAL COEFFICIENT ARRAY \nC \nC ******************************************************************\nC \nC SUBROUTINE RFFTI(N,WSAVE) \nC \nC ******************************************************************\nC \nC SUBROUTINE RFFTI INITIALIZES THE ARRAY WSAVE WHICH IS USED IN \nC BOTH RFFTF AND RFFTB. THE PRIME FACTORIZATION OF N TOGETHER WITH \nC A TABULATION OF THE TRIGONOMETRIC FUNCTIONS ARE COMPUTED AND \nC STORED IN WSAVE. \nC \nC INPUT PARAMETER \nC \nC N THE LENGTH OF THE SEQUENCE TO BE TRANSFORMED. \nC \nC OUTPUT PARAMETER \nC \nC WSAVE A WORK ARRAY WHICH MUST BE DIMENSIONED AT LEAST 2*N+15. \nC THE SAME WORK ARRAY CAN BE USED FOR BOTH RFFTF AND RFFTB \nC AS LONG AS N REMAINS UNCHANGED. DIFFERENT WSAVE ARRAYS \nC ARE REQUIRED FOR DIFFERENT VALUES OF N. THE CONTENTS OF \nC WSAVE MUST NOT BE CHANGED BETWEEN CALLS OF RFFTF OR RFFTB.\nC \nC ******************************************************************\nC \nC SUBROUTINE RFFTF(N,R,WSAVE) \nC \nC ******************************************************************\nC \nC SUBROUTINE RFFTF COMPUTES THE FOURIER COEFFICIENTS OF A REAL \nC PERODIC SEQUENCE (FOURIER ANALYSIS). THE TRANSFORM IS DEFINED \nC BELOW AT OUTPUT PARAMETER R. \nC \nC INPUT PARAMETERS \nC \nC N THE LENGTH OF THE ARRAY R TO BE TRANSFORMED. THE METHOD \nC IS MOST EFFICIENT WHEN N IS A PRODUCT OF SMALL PRIMES. \nC N MAY CHANGE SO LONG AS DIFFERENT WORK ARRAYS ARE PROVIDED\nC \nC R A REAL ARRAY OF LENGTH N WHICH CONTAINS THE SEQUENCE \nC TO BE TRANSFORMED \nC \nC WSAVE A WORK ARRAY WHICH MUST BE DIMENSIONED AT LEAST 2*N+15. \nC IN THE PROGRAM THAT CALLS RFFTF. THE WSAVE ARRAY MUST BE \nC INITIALIZED BY CALLING SUBROUTINE RFFTI(N,WSAVE) AND A \nC DIFFERENT WSAVE ARRAY MUST BE USED FOR EACH DIFFERENT \nC VALUE OF N. THIS INITIALIZATION DOES NOT HAVE TO BE \nC REPEATED SO LONG AS N REMAINS UNCHANGED THUS SUBSEQUENT \nC TRANSFORMS CAN BE OBTAINED FASTER THAN THE FIRST. \nC THE SAME WSAVE ARRAY CAN BE USED BY RFFTF AND RFFTB. \nC \nC \nC OUTPUT PARAMETERS \nC \nC R R(1) = THE SUM FROM I=1 TO I=N OF R(I) \nC \nC IF N IS EVEN SET L =N/2 , IF N IS ODD SET L = (N+1)/2 \nC \nC THEN FOR K = 2,...,L \nC \nC R(2*K-2) = THE SUM FROM I = 1 TO I = N OF \nC \nC R(I)*COS((K-1)*(I-1)*2*PI/N) \nC \nC R(2*K-1) = THE SUM FROM I = 1 TO I = N OF \nC \nC -R(I)*SIN((K-1)*(I-1)*2*PI/N) \nC \nC IF N IS EVEN \nC \nC R(N) = THE SUM FROM I = 1 TO I = N OF \nC \nC (-1)**(I-1)*R(I) \nC \nC ***** NOTE \nC THIS TRANSFORM IS UNNORMALIZED SINCE A CALL OF RFFTF \nC FOLLOWED BY A CALL OF RFFTB WILL MULTIPLY THE INPUT \nC SEQUENCE BY N. \nC \nC WSAVE CONTAINS RESULTS WHICH MUST NOT BE DESTROYED BETWEEN \nC CALLS OF RFFTF OR RFFTB. \nC \nC \nC ******************************************************************\nC \nC SUBROUTINE RFFTB(N,R,WSAVE) \nC \nC ******************************************************************\nC \nC SUBROUTINE RFFTB COMPUTES THE REAL PERODIC SEQUENCE FROM ITS \nC FOURIER COEFFICIENTS (FOURIER SYNTHESIS). THE TRANSFORM IS DEFINED\nC BELOW AT OUTPUT PARAMETER R. \nC \nC INPUT PARAMETERS \nC \nC N THE LENGTH OF THE ARRAY R TO BE TRANSFORMED. THE METHOD \nC IS MOST EFFICIENT WHEN N IS A PRODUCT OF SMALL PRIMES. \nC N MAY CHANGE SO LONG AS DIFFERENT WORK ARRAYS ARE PROVIDED\nC \nC R A REAL ARRAY OF LENGTH N WHICH CONTAINS THE SEQUENCE \nC TO BE TRANSFORMED \nC \nC WSAVE A WORK ARRAY WHICH MUST BE DIMENSIONED AT LEAST 2*N+15. \nC IN THE PROGRAM THAT CALLS RFFTB. THE WSAVE ARRAY MUST BE \nC INITIALIZED BY CALLING SUBROUTINE RFFTI(N,WSAVE) AND A \nC DIFFERENT WSAVE ARRAY MUST BE USED FOR EACH DIFFERENT \nC VALUE OF N. THIS INITIALIZATION DOES NOT HAVE TO BE \nC REPEATED SO LONG AS N REMAINS UNCHANGED THUS SUBSEQUENT \nC TRANSFORMS CAN BE OBTAINED FASTER THAN THE FIRST. \nC THE SAME WSAVE ARRAY CAN BE USED BY RFFTF AND RFFTB. \nC \nC \nC OUTPUT PARAMETERS \nC \nC R FOR N EVEN AND FOR I = 1,...,N \nC \nC R(I) = R(1)+(-1)**(I-1)*R(N) \nC \nC PLUS THE SUM FROM K=2 TO K=N/2 OF \nC \nC 2.*R(2*K-2)*COS((K-1)*(I-1)*2*PI/N) \nC \nC -2.*R(2*K-1)*SIN((K-1)*(I-1)*2*PI/N) \nC \nC FOR N ODD AND FOR I = 1,...,N \nC \nC R(I) = R(1) PLUS THE SUM FROM K=2 TO K=(N+1)/2 OF \nC \nC 2.*R(2*K-2)*COS((K-1)*(I-1)*2*PI/N) \nC \nC -2.*R(2*K-1)*SIN((K-1)*(I-1)*2*PI/N) \nC \nC ***** NOTE \nC THIS TRANSFORM IS UNNORMALIZED SINCE A CALL OF RFFTF \nC FOLLOWED BY A CALL OF RFFTB WILL MULTIPLY THE INPUT \nC SEQUENCE BY N. \nC \nC WSAVE CONTAINS RESULTS WHICH MUST NOT BE DESTROYED BETWEEN \nC CALLS OF RFFTB OR RFFTF. \n SUBROUTINE RFFTI (N,WSAVE) \n DIMENSION WSAVE(*) \nCX30127 CALL SBINX (127) \nCY30127 CALL SBINY (127) \n IF (N .EQ. 1) THEN \nCX40128 CALL SBOUTX (128) \nCY40128 CALL SBOUTY (128) \n RETURN \n ENDIF \nc CALL RFFTI1 (N,WSAVE(N+1),WSAVE(2*N+1)) \nCX40128 CALL SBOUTX (128) \nCY40128 CALL SBOUTY (128) \n RETURN \n END \n", "meta": {"hexsha": "3684f53d614458a603db8776972666514c706eff", "size": 12046, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "packages/PIPS/validation/Syntax/comments2.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/Syntax/comments2.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/Syntax/comments2.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": 72.5662650602, "max_line_length": 73, "alphanum_fraction": 0.274032874, "num_tokens": 1896, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942290328345, "lm_q2_score": 0.7371581568543044, "lm_q1q2_score": 0.6562876529318682}} {"text": "C NCLFORTSTART\n SUBROUTINE DWGTVOLRMSE(T,Q,WGTZ,WGTY,WGTX,MX,NY,KZ,TMSG,QMSG,\n + IFLAG,RMSE)\n IMPLICIT NONE\n INTEGER MX,NY,KZ,IFLAG\n DOUBLE PRECISION T(MX,NY,KZ),Q(MX,NY,KZ)\n DOUBLE PRECISION WGTX(MX),WGTY(NY),WGTZ(KZ)\n DOUBLE PRECISION TMSG,QMSG\n DOUBLE PRECISION RMSE\nC NCLEND\n\nC NCL: rmsqTQ = wgtVolRmse (T,Q,wgtz,wgty,wgtx,flag)\nC compute the weighted root-mean-square-difference [rmse]\nc . This could have been programmed more efficiently.\n\n INTEGER NL,ML,KL,KMSG\n DOUBLE PRECISION SUMD,SUMW,WGTXY,SUMTQ,SUMWZ,VARTQ\n\nC Nomenclature:\nC INPUT:\nC t - 3D array\nC q - 3D array\nC wgtz - 1D array of length \"kz\"\nC wgty - 1D array of length \"ny\"\nC wgtx - 1D array of length \"mx\"\nC mx - 1st [fastest varying] dimension of \"t\" [eg, longitude]\nC ny - 2nd dimension of \"t\" [eg, latitude ]\nC kz - 3rd [slowest varying] dimension of \"t\" [eg, latitude ]\nc tmsg - msg value\nc qmsg - msg value\nC iflag - flag\nC =0 compute rmse ignoring msg values\nC =1 if any msg data is encountered return as msg\n\nC OUTPUT:\nC rmse - volume root-mean-square-difference [weighted]\n\n SUMD = 0.0D0\n SUMW = 0.0D0\n RMSE = TMSG\n KMSG = 0\n\n DO NL = 1,NY\n DO ML = 1,MX\n SUMTQ = 0\n SUMWZ = 0.0D0\nc sum wgted vertical differences\nc at each lat/lon point\n DO KL = 1,KZ\n IF (T(ML,NL,KL).NE.TMSG .AND.\n + Q(ML,NL,KL).NE.QMSG) THEN\n SUMTQ = SUMTQ + WGTZ(KL)*\n + (T(ML,NL,KL)-Q(ML,NL,KL))**2\n SUMWZ = SUMWZ + WGTZ(KL)\n ELSE\n KMSG = KMSG + 1\n END IF\n END DO\nc return if user desired\n IF (IFLAG.EQ.1 .AND. KMSG.NE.0) RETURN\nc wgt vertical mean square difference\nc by areal wgts x/lon and y/lat\n IF (SUMWZ.GT.0.0D0) THEN\n VARTQ = (SUMTQ/SUMWZ)\n WGTXY = WGTX(ML)*WGTY(NL)\n SUMD = SUMD + WGTXY*VARTQ\n SUMW = SUMW + WGTXY\n END IF\n\n END DO\n END DO\nc compute wgted rmse\n IF (SUMW.GT.0.0D0) THEN\n RMSE = SQRT(SUMD/SUMW)\n END IF\n\n RETURN\n END\n\nC NCLFORTSTART\n SUBROUTINE DWGTVOLRMSECCM(T,Q,DPT,DPQ,WGTY,WGTX,MX,NY,KZ,TMSG,\n + QMSG,IFLAG,RMSE)\n IMPLICIT NONE\n INTEGER MX,NY,KZ,IFLAG\n DOUBLE PRECISION T(MX,NY,KZ),Q(MX,NY,KZ)\n DOUBLE PRECISION WGTX(MX),WGTY(NY)\n DOUBLE PRECISION DPT(MX,NY,KZ),DPQ(MX,NY,KZ)\n DOUBLE PRECISION TMSG,QMSG\n DOUBLE PRECISION RMSE\nC NCLEND\n\nC NCL: rmsqTQ = wgtVolRmse_ccm (T,Q,dpT,dpQ,wgty,wgtx,flag)\nC compute the weighted root-mean-square-difference [rmse]\nc . This could have been programmed more efficiently.\n\n INTEGER NL,ML,KL,KMSG\n DOUBLE PRECISION SUMD,SUMW,WGTXY,SUMTQ,SUMDP,WGTDP,VARTQ\n\nC Nomenclature:\nC INPUT:\nC t - 3D array\nC q - 3D array\nC dpt - 3D array same size as \"t\" and \"q\"\nC dpq - 3D array same size as \"t\" and \"q\"\nC wgty - 1D array of length \"ny\"\nC wgtx - 1D array of length \"mx\"\nC mx - 1st [faster varying] dimension of \"t\" [eg, longitude]\nC ny - 2nd [slower varying] dimension of \"t\" [eg, latitude ]\nC kz - 3rd [slower varying] dimension of \"t\" [eg, latitude ]\nc tmsg - msg value\nc qmsg - msg value\nC iflag - flag\nC =0 compute rmse ignoring msg values\nC =1 if any msg data is encountered return as msg\n\nC OUTPUT:\nC rmse - volume root-mean-square-difference [weighted]\nC Dave Williamson suggested the use of the mean \"dp\"\n\n SUMD = 0.0D0\n SUMW = 0.0D0\n RMSE = TMSG\n KMSG = 0\n\n DO NL = 1,NY\n DO ML = 1,MX\n SUMTQ = 0.0D0\n SUMDP = 0.0D0\nc sum wgted vertical differences\nc at each lat/lon point\n DO KL = 1,KZ\n IF (T(ML,NL,KL).NE.TMSG .AND.\n + Q(ML,NL,KL).NE.QMSG) THEN\n WGTDP = 0.5D0* (DPT(ML,NL,KL)+DPQ(ML,NL,KL))\n SUMTQ = SUMTQ + WGTDP*(T(ML,NL,KL)-Q(ML,NL,KL))**2\n SUMDP = SUMDP + WGTDP\n ELSE\n KMSG = KMSG + 1\n END IF\n END DO\nc return if user desired\n IF (IFLAG.EQ.1 .AND. KMSG.NE.0) RETURN\nc wgt vertical mean square difference\nc by areal wgts x/lon and y/lat\n IF (SUMDP.GT.0.0D0) THEN\n VARTQ = SUMTQ/SUMDP\n WGTXY = WGTX(ML)*WGTY(NL)\n SUMD = SUMD + WGTXY*VARTQ\n SUMW = SUMW + WGTXY\n END IF\n\n END DO\n END DO\nc compute wgted rmse\n IF (SUMW.GT.0.0D0) THEN\n RMSE = SQRT(SUMD/SUMW)\n END IF\n\n RETURN\n END\n", "meta": {"hexsha": "ebc5ab691611df1912103bec0fb9cbc07f8c6bf3", "size": 5241, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ni/src/lib/nfpfort/volRmse.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "ni/src/lib/nfpfort/volRmse.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "ni/src/lib/nfpfort/volRmse.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 32.5527950311, "max_line_length": 72, "alphanum_fraction": 0.5042930738, "num_tokens": 1698, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942173896131, "lm_q2_score": 0.7371581568543043, "lm_q1q2_score": 0.6562876443489725}} {"text": "! \n! Written by Leandro Mart\u00ednez, 2009-2011.\n! Copyright (c) 2009-2018, Leandro Mart\u00ednez, Jose Mario Martinez,\n! Ernesto G. Birgin.\n! \n! Subroutine eulerrmat: Computes the rotation matrix from the\n! Euler angles\n! \n! Note that:\n! In this routine, beta is a rotation about the y-axis\n! gama is a rotation about the z-axis\n! teta is a rotation about the x-axis\n\nsubroutine eulerrmat(beta,gama,teta,v1,v2,v3)\n\n implicit none\n double precision :: beta, gama, teta\n double precision :: cb, sb, cg, sg, ct, st\n double precision :: v1(3), v2(3), v3(3)\n\n cb = dcos(beta) \n sb = dsin(beta) \n cg = dcos(gama) \n sg = dsin(gama) \n ct = dcos(teta) \n st = dsin(teta)\n\n v1(1)=-sb * sg * ct + cb * cg \n v1(2)=-sb * cg * ct - cb * sg \n v1(3)= sb * st \n\n v2(1)= cb * sg * ct + sb * cg \n v2(2)= cb * cg * ct - sb * sg \n v2(3)=-cb * st \n\n v3(1)= sg * st \n v3(2)= cg * st \n v3(3)= ct \n\n return\nend subroutine eulerrmat\n\n!\n! Subroutine compcart: Compute cartesian coordinates using\n! the center of mass, the canonical coordinates\n! and the rotation matrix\n! \n\nsubroutine compcart(icart,xbar,ybar,zbar,&\n xcoor,ycoor,zcoor,v1,v2,v3)\n\n use compute_data, only : xcart\n implicit none\n integer :: icart\n double precision :: xbar, ybar, zbar\n double precision :: xcoor, ycoor, zcoor\n double precision :: v1(3), v2(3), v3(3)\n\n xcart(icart,1) = xbar + xcoor*v1(1) + ycoor*v2(1) + zcoor*v3(1) \n xcart(icart,2) = ybar + xcoor*v1(2) + ycoor*v2(2) + zcoor*v3(2) \n xcart(icart,3) = zbar + xcoor*v1(3) + ycoor*v2(3) + zcoor*v3(3) \n\n return\nend subroutine compcart\n\n!\n! Subroutine eulerfixed: This routine was added because it defines \n! the rotation in the \"human\" way, an is thus used\n! to set the position of the fixed molecules. \n! That means: beta is a counterclockwise rotation around x axis.\n! gama is a counterclockwise rotation around y axis.\n! teta is a counterclockwise rotation around z axis.\n! The other routine should better do this as well, but then we need to change\n! all the derivative calculations, just for the sake of human interpretation\n! of the rotation which, in that case, is not really important. Maybe some day.\n! \n\nsubroutine eulerfixed(beta,gama,teta,v1,v2,v3)\n\n implicit none\n double precision :: beta, gama, teta\n double precision :: c1, s1, c2, s2, c3, s3\n double precision :: v1(3), v2(3), v3(3)\n\n c1 = dcos(beta) \n s1 = dsin(beta) \n c2 = dcos(gama) \n s2 = dsin(gama) \n c3 = dcos(teta) \n s3 = dsin(teta)\n\n v1(1) = c2*c3\n v1(2) = c1*s3 + c3*s1*s2\n v1(3) = s1*s3 - c1*c3*s2\n\n v2(1) = -c2*s3\n v2(2) = c1*c3 - s1*s2*s3\n v2(3) = c1*s2*s3 + c3*s1\n\n v3(1) = s2\n v3(2) = -c2*s1\n v3(3) = c1*c2 \n\n return\nend subroutine eulerfixed\n\n", "meta": {"hexsha": "5007ff371401fa144350ab51611faf4818be554f", "size": 2909, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "polartocart.f90", "max_stars_repo_name": "donshen/packmol", "max_stars_repo_head_hexsha": "b62e8abaf22106d2c6287a594fa8dff6afb11326", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 47, "max_stars_repo_stars_event_min_datetime": "2020-04-12T17:47:15.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T07:37:53.000Z", "max_issues_repo_path": "polartocart.f90", "max_issues_repo_name": "donshen/packmol", "max_issues_repo_head_hexsha": "b62e8abaf22106d2c6287a594fa8dff6afb11326", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2020-05-24T16:29:44.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-10T17:24:17.000Z", "max_forks_repo_path": "polartocart.f90", "max_forks_repo_name": "donshen/packmol", "max_forks_repo_head_hexsha": "b62e8abaf22106d2c6287a594fa8dff6afb11326", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2017-09-07T19:30:15.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-27T19:16:17.000Z", "avg_line_length": 27.1869158879, "max_line_length": 83, "alphanum_fraction": 0.6002062564, "num_tokens": 1039, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942144788076, "lm_q2_score": 0.7371581568543043, "lm_q1q2_score": 0.6562876422032485}} {"text": "! File flaplace90_arrays.f90\n! Author: Ramon Crehuet\nsubroutine timestep(u,n,m,dx,dy,error)\nimplicit none\nreal (kind=8), dimension(0:n-1,0:m-1), intent(inout):: u\n\nreal (kind=8), intent(in) :: dx,dy\nreal (kind=8), intent(out) :: error\ninteger, intent(in) :: n,m\nreal (kind=8), dimension(0:n-1,0:m-1) :: diff\nreal (kind=8) :: dx2,dy2,dnr_inv\n\n!f2py intent(in) :: dx,dy\n!f2py intent(in,out) :: u\n!f2py intent(out) :: error\n!f2py intent(hide) :: n,m\n\ndx2 = dx*dx\ndy2 = dy*dy\ndnr_inv = 0.5d0 / (dx2+dy2)\n\ndiff=u\n\nu(1:n-2, 1:m-2) = ((u(0:n-3, 1:m-2) + u(2:n-1, 1:m-2))*dy2 + &\n (u(1:n-2,0:m-3) + u(1:n-2, 2:m-1))*dx2)*dnr_inv\n\nerror=sqrt(sum((u-diff)**2))\n\nend subroutine\n", "meta": {"hexsha": "821789655639ef3671ea455260b0b6895b559cea", "size": 691, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "doc/perfpy/src/flaplace90_arrays.f90", "max_stars_repo_name": "srossross/Clyther", "max_stars_repo_head_hexsha": "3540952ef2da2dbbc55bc71bee9b34c43a058edb", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2015-02-02T21:47:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-28T04:18:47.000Z", "max_issues_repo_path": "doc/perfpy/src/flaplace90_arrays.f90", "max_issues_repo_name": "srossross/Clyther", "max_issues_repo_head_hexsha": "3540952ef2da2dbbc55bc71bee9b34c43a058edb", "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": "doc/perfpy/src/flaplace90_arrays.f90", "max_forks_repo_name": "srossross/Clyther", "max_forks_repo_head_hexsha": "3540952ef2da2dbbc55bc71bee9b34c43a058edb", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-03-21T17:54:33.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-06T22:22:17.000Z", "avg_line_length": 23.0333333333, "max_line_length": 72, "alphanum_fraction": 0.5962373372, "num_tokens": 303, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953030553434, "lm_q2_score": 0.7310585844894971, "lm_q1q2_score": 0.6562678575545094}} {"text": "SUBROUTINE distriblay(nlay,bszlyd,bszlyt,layval,insertval,begind,endd)\n!\nIMPLICIT NONE\n!\n! Subroutine arguments\n!\nREAL :: begind,endd,insertval\nINTEGER :: nlay\nREAL,DIMENSION(nlay) :: bszlyd,bszlyt,layval\n!\n! Local variables\n!\nREAL :: depth,interval_thick,prevdepth,thick\nREAL :: intersect\nINTEGER :: lay\n!\n! the following subroutine arguments are not used: bszlyt jcaii 8/08/08\n!\n! + + + purpose + + +\n! distributes a quantity of material over an underground interval\n! adding material in each layer in proportion to the fraction of\n! the interval that is each soil layer.\n \n! note: insertval and layval need the same units\n \n! + + + argument declarations + + +\n \n! + + + argument definitions + + +\n! nlay - number of layers in soil input array\n! bszlyd - depth to bottom of soil layers (mm)\n! bszlyt - thickness of soil layers (mm)\n! layval - the layer bins that will be supplemented by added material\n! insertval - the quantity of material to be distributed into layval\n! begind - uppper depth of soil interval (mm)\n! endd - lower depth of soil interval (mm)\n \n! + + + local variables + + +\n \n! + + + local definitions + + +\n! lay - layer index\n! depth - depth to bottom of present soil layer (mm)\n! prevdepth - previous cumulative depth in soil (mm)\n! thick - thickness of soil slice (intersection of soil interval\n! and soil layer) (mm)\n! interval_thick - thickness of soil interval over which quantity\n! of material is being inserted. (mm)\n \n! + + + functions called + + +\n \n! + + + end specifications + + +\n \n ! interval thickness is used repeatedly, calculate here\ninterval_thick = endd - begind\n ! start at soil surface\ndepth = 0.0\nDO lay = 1,nlay\n ! set depth of layer upper boundary\n prevdepth = depth\n ! set depth of layer lower boundary\n depth = bszlyd(lay)\n IF (interval_thick.GT.0.0) THEN\n ! find thickness of intersection between layer and interval\n thick = intersect(prevdepth,depth,begind,endd)\n ! put proportional amount in this layer\n IF (thick.GT.0.0) layval(lay) = layval(lay) &\n & + insertval*thick/interval_thick\n ! zero interval thickness\n ELSE IF ((endd.LE.depth).AND.(endd.GT.prevdepth)) THEN\n ! interval in this layer, put all in this layer\n layval(lay) = layval(lay) + insertval\n END IF\nEND DO\n! \nEND SUBROUTINE distriblay\n", "meta": {"hexsha": "687f11814ea10bc991bd6541048de81deb5ae8ad", "size": 2559, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Project Documents/Source Code Original/Distriblay.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/Distriblay.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/Distriblay.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": 34.12, "max_line_length": 81, "alphanum_fraction": 0.6357952325, "num_tokens": 683, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953030553434, "lm_q2_score": 0.7310585844894971, "lm_q1q2_score": 0.6562678575545094}} {"text": "!---------------------------------------------------------------------!\n! OWNER: Ithaca Combustion Enterprise, LLC !\n! COPYRIGHT: \u00a9 2012, Ithaca Combustion Enterprise, LLC !\n! LICENSE: BSD 3-Clause License (The complete text of the license can !\n! be found in the `LICENSE-ICE.txt' file included in the ISAT-CK7 !\n! source directory.) !\n!---------------------------------------------------------------------!\n\nsubroutine ell_eig2chol( n, u, lam, g )\n\n! The n x n matrix A has the eigendecomposition A = u * lam^2 * u^T\n! and the Cholesky decomposition A = G * G^T. Given u and lam, this\n! routine returns G in packed format.\n\n! Method:\n! A = u * lam^2 * u^T = B * B^T, where B = u * lam\n! B = G * Q ( LQ factorization)\n\nimplicit none\ninteger, parameter :: k_dp = kind(1.d0)\ninteger, intent(in) :: n\nreal(k_dp), intent(in) :: u(n,n), lam(n)\nreal(k_dp), intent(out) :: g((n*(n+1))/2)\n\nreal(k_dp) :: B(n,n)\ninteger :: j\n\n! form B\ndo j = 1, n ! B = u * lam\n B(:,j) = u(:,j) * lam(j)\nend do\n\ncall ell_bbt2chol( n, B, g )\n\nreturn\nend subroutine ell_eig2chol\n", "meta": {"hexsha": "2d24f8f0afc230c35e1428aa53a102eb9757455d", "size": 1179, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/isat/ell_lib/ell_eig2chol.f90", "max_stars_repo_name": "xuhan425/isat_ffd", "max_stars_repo_head_hexsha": "3a5449f7e49b686c33fe0e97ca90ea8d92fc2f00", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-04-10T20:16:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-15T11:09:44.000Z", "max_issues_repo_path": "src/isat/ell_lib/ell_eig2chol.f90", "max_issues_repo_name": "xuhan425/isat_ffd", "max_issues_repo_head_hexsha": "3a5449f7e49b686c33fe0e97ca90ea8d92fc2f00", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-06-07T14:10:25.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-07T14:10:25.000Z", "max_forks_repo_path": "src/isat/ell_lib/ell_eig2chol.f90", "max_forks_repo_name": "xuhan425/isat_ffd", "max_forks_repo_head_hexsha": "3a5449f7e49b686c33fe0e97ca90ea8d92fc2f00", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-06-07T03:44:12.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-05T05:54:10.000Z", "avg_line_length": 31.8648648649, "max_line_length": 71, "alphanum_fraction": 0.4961832061, "num_tokens": 346, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.7310585786300048, "lm_q1q2_score": 0.6562678442908441}} {"text": "Module Md_numerical_recipes\r\n\r\nUse Md_Types_Numeriques\r\nUse Md_Constantes\r\n\r\nImplicit None\r\n\r\nContains\r\n\r\n!######################################################################\r\nSubroutine mnewt(neqt,nspec,nat,pilag,dlnn,abun,mu,b0,abuntot, &\r\n ntrial,x,n,tolx,tolf,code)\r\n\r\n! From Fortran Numerical Recipes, Chap. 9.6\r\n! ...real variables changed to Real(8) ::\r\n! ...included call to mprove and save of fvec and fjac\r\n! USES lubksb,ludcmp,usrfun\r\n! Given an initial guess x for a root in n dimensions, take ntrial Newton-Raphson steps to\r\n! improve the root. Stop if the root converges in either summed absolute variable increments\r\n! tolx or summed absolute function values tolf.\r\n\r\nImplicit None\r\nInteger, intent(in) :: neqt\r\nInteger, intent(in) :: nspec\r\nInteger, intent(in) :: nat(:,:)\r\nReal(8), intent(inout) :: pilag(:)\r\nReal(8), intent(inout) :: dlnn\r\nReal(8), intent(in) :: abun(:)\r\nReal(8), intent(in) :: mu(:)\r\nReal(8), intent(in) :: b0(:)\r\nReal(8), intent(in) :: abuntot\r\n\r\nInteger, intent(in) :: n, ntrial\r\nReal(8), intent(in) :: tolf,tolx\r\nReal(8), intent(inout) :: x(n)\r\nInteger, intent(inout) :: code ! 0 : OK, 1 : error\r\n\r\nInteger, parameter :: NP = 500\t\t ! Up to NP variables.\r\nInteger :: i, j, k, indx(NP)\r\nReal(8) :: d, errf, errx, fjac(NP,NP), fvec(NP), p(NP)\r\nReal(8) :: fvec_save(NP), fjac_save(NP,NP)\r\n\r\n\r\nIf (n > NP) then\r\n Write(*,*)' E- Too large size in mnewt'\r\n Stop\r\nEnd if\r\n\r\nDo k=1, ntrial\r\n Call usrfun(neqt,pilag,dlnn,nspec,nat,abun,mu,b0,abuntot, &\r\n x,n,NP,fvec,fjac) ! User Subroutine supplies function values at x in fvec\r\n Do i = 1, n\t\t\t! *** save fvec and fjac\r\n fvec_save(i) = -fvec(i)\r\n Do j = 1, n\r\n fjac_save(i,j) = fjac(i,j)\r\n End do\r\n End do\r\n errf = 0.0d0\t\t\t! and Jacobian matrix in fjac.\r\n Do i = 1, n\t\t ! Check function convergence.\r\n errf = errf + dabs(fvec(i))\r\n End do\r\n If (errf <= tolf) Return\r\n Do i = 1, n\t\t ! Right-hand side of linear equations.\r\n p(i) = -fvec(i)\r\n End do\r\n Call ludcmp(fjac,n,NP,indx,d,code) ! Solve linear equations using LU decomposition.\r\n If (code == 1) Return\r\n Call lubksb(fjac,n,NP,indx,p)\r\n Call mprove(fjac_save,fjac,n,NP,indx,fvec_save,p)\r\n errx = 0.0d0\t\t\t! Check root convergence.\r\n Do i = 1, n\t\t ! Update solution.\r\n errx = errx + dabs(p(i))\r\n x(i) = x(i) + p(i)\r\n End do\r\n If (errx <= tolx) Return\r\nEnd do\r\n\r\n\r\nEnd Subroutine mnewt\r\n\r\n!######################################################################\r\n\r\nSubroutine ludcmp(a,n,np,indx,d,code)\r\n! From Fortran Numerical Recipes, Chap. 2.3\r\n! ...real variables changed to Real(8) ::\r\n! Given a matrix a(1:n,1:n), with physical dimension np by np, this routine replaces it by\r\n! the LU decomposition of a rowwise permutation of itself. a and n are input. a is output,\r\n! arranged as in equation (2.3.14) above; indx(1:n) is an output vector that records the\r\n! row permutation effected by the partial pivoting; d is output as +-1 depending on whether\r\n! the number of row interchanges was even or odd, respectively. This routine is used in\r\n! combination with lubksb to solve linear equations or invert a matrix.\r\n! the code variable has been added for when the code crashes at the end of the profiles at this stage\r\n\r\nImplicit None\r\nInteger, intent(in) :: n, np\r\nInteger, intent(out) :: indx(n)\r\nReal(8), intent(inout) :: a(np,np)\r\nReal(8), intent(out) :: d\r\nInteger, intent(inout) :: code ! 0: OK, 1: error\r\n\r\nInteger, parameter :: NMAX = 500 !Largest expected n\r\nInteger :: i, imax, j, k\r\nReal(8) :: aamax, dum, sum, vv(NMAX) ! vv stores the implicit scaling of each row.\r\n\r\nimax = 0 ! ad hoc initialization\r\nd = 1.0d0 ! No row interchanges yet.\r\nDo i = 1, n ! Loop over rows to get the implicit scaling\r\n aamax = 0.0d0 ! information.\r\n Do j = 1, n\r\n If (dabs(a(i,j)) > aamax) aamax = dabs(a(i,j))\r\n End do\r\n !If (aamax == 0.0d0) pause 'singular matrix in ludcmp' ! No nonzero largest element.\r\n !If (aamax == 0.0d0) Stop 'singular matrix in ludcmp' ! No nonzero largest element.\r\n If (aamax == 0.0d0) then\r\n code = 1\r\n Return\r\n End if\r\n vv(i) = 1.0d0 / aamax ! Save the scaling.\r\nEnd do\r\nDo j = 1, n ! This is the loop over columns of Crout's method.\r\n Do i = 1, j-1 ! This is equation (2.3.12) except for i = j.\r\n sum = a(i,j)\r\n Do k = 1, i-1\r\n sum = sum - a(i,k)*a(k,j)\r\n End do\r\n a(i,j) = sum\r\n End do\r\n aamax = 0.0d0 ! Initialize for the search for largest pivot element.\r\n Do i = j, n ! This is i = j of equation (2.3.12) and i = j+1: ::N\r\n sum = a(i,j) ! of equation (2.3.13).\r\n Do k = 1, j-1\r\n sum = sum-a(i,k) * a(k,j)\r\n End do\r\n a(i,j) = sum\r\n dum = vv(i) * dabs(sum) ! Figure of merit for the pivot.\r\n If (dum >= aamax) then ! Is it better than the best so far?\r\n imax = i\r\n aamax = dum\r\n End if\r\n End do\r\n If (j /= imax)then ! Do we need to interchange rows?\r\n Do k = 1, n ! Yes, do so...\r\n dum = a(imax,k)\r\n a(imax,k) = a(j,k)\r\n a(j,k) = dum\r\n End do\r\n d = -d ! ...and change the parity of d.\r\n vv(imax) = vv(j) ! Also interchange the scale factor.\r\n End if\r\n indx(j) = imax\r\n If (a(j,j) == 0.) a(j,j) = eps_dp\r\n !If the pivot element is zero the matrix is singular (at least to the precision of the algorithm).\r\n !For some applications on singular matrices, it is desirable to substitute eps\r\n !for zero.\r\n \r\n If(j /= n)then ! Now, Finally, divide by the pivot element.\r\n dum = 1.0d0 / a(j,j)\r\n Do i = j+1, n\r\n a(i,j) = a(i,j) * dum\r\n End do\r\n End if\r\nEnd do ! Go back for the next column in the reduction.\r\n\r\nEnd Subroutine ludcmp\r\n\r\n!######################################################################\r\n\r\nSubroutine lubksb(a,n,np,indx,b)\r\n! From Fortran Numerical Recipes, Chap. 2.3\r\n! ...real variables changed to Real(8) ::\r\n! Solves the set of n linear equations A . X = B. Here a is input, not as the matrix A but\r\n! rather as its LU decomposition, determined by the routine ludcmp. indx is input as the\r\n! permutation vector returned by ludcmp. b(1:n) is input as the right-hand side vector B,\r\n! and returns with the solution vector X. a, n, np, and indx are not modified by this routine\r\n! and can be left in place for successive calls with different right-hand sides b. This routine\r\n! takes into account the possibility that b will begin with many zero elements, so it is efficient\r\n! for use in matrix inversion.\r\n\r\nImplicit None\r\nInteger, intent(in) :: n, np, indx(n)\r\nReal(8), intent(in) :: a(np,np)\r\nReal(8), intent(inout) :: b(n)\r\nInteger :: i, ii, j, ll\r\nReal(8) :: sum\r\n\r\nii = 0 ! When ii is set to a positive value, it will become the index\r\nDo i = 1, n ! of the first nonvanishing element of b. We now do\r\n ll = indx(i)\t\t ! the forward substitution, equation (2.3.6). The only new\r\n sum = b(ll)\t\t ! wrinkle is to unscramble the permutation as we go.\r\n b(ll) = b(i)\r\n If (ii /= 0) then\r\n Do j = ii, i-1\r\n sum = sum - a(i,j)*b(j)\r\n End do\r\n Else if (sum /=0.) then\r\n ii = i\t\t ! A nonzero element was encountered, so from now on we will\r\n End if\t\t ! have to do the sums in the loop above.\r\n b(i) = sum\r\nEnd do\r\nDo i = n, 1, -1 ! Now we do the backsubstitution, equation (2.3.7).\r\n sum = b(i)\r\n Do j = i+1, n\r\n sum = sum - a(i,j)*b(j)\r\n End do\r\n b(i) = sum / a(i,i)\t ! Store a component of the solution vector X.\r\nEnd do\r\n\r\nEnd Subroutine lubksb\r\n\r\n!######################################################################\r\n\r\nSubroutine mprove(a,alud,n,np,indx,b,x)\r\n! From Fortran Numerical Recipes, Chap. 2.5\r\n! ...real variables changed to Real(8) ::\r\n! USES lubksb\r\n! Improves a solution vector x(1:n) of the linear set of equations A . X = B. The matrix\r\n! a(1:n,1:n), and the vectors b(1:n) and x(1:n) are input, as is the dimension n. Also\r\n! input is alud, the LU decomposition of a as returned by ludcmp, and the vector indx also\r\n! returned by that routine. On output, only x(1:n) is modified, to an improved set of values.\r\n\r\nImplicit None\r\nInteger, intent(in) :: n, np, indx(n)\r\nReal(8), intent(in) :: a(np,np), alud(np,np), b(n)\r\nReal(8), intent(inout) :: x(n)\r\n\r\nInteger, parameter :: NMAX = 500\t ! Maximum anticipated value of n.\r\nInteger :: i, j\r\nReal(8) :: r(NMAX)\r\nReal(8) :: sdp\r\n\r\nDo i=1,n\t\t ! Calculate the right-hand side, accumulating the residual\r\n sdp = -b(i) ! in double precision\r\n Do j = 1, n\r\n sdp = sdp + a(i,j)*x(j)\r\n End do\r\n r(i) = sdp\r\nEnd do\r\nCall lubksb(alud,n,np,indx,r) ! Solve for the error term,\r\nDo i = 1, n ! and subtract it from the old solution.\r\n x(i) = x(i) - r(i)\r\nEnd do\r\n\r\nEnd subroutine mprove\r\n\r\n!######################################################################\r\nSubroutine usrfun(neqt,pilag,dlnn,nspec,nat,abun,mu,b0,abuntot, &\r\n x,n,NP,fvec,fjac)\r\n\r\nImplicit None\r\nInteger, intent(in) :: neqt\r\nInteger, intent(in) :: nspec\r\nInteger, intent(in) :: nat(:,:)\r\nReal(8), intent(inout) :: pilag(:)\r\nReal(8), intent(inout) :: dlnn\r\nReal(8), intent(in) :: abun(:)\r\nReal(8), intent(in) :: mu(:)\r\nReal(8), intent(in) :: b0(:)\r\nReal(8), intent(in) :: abuntot\r\n\r\n! user subroutine for mnewt\r\n! it evaluates the functions F_i(x_j)=0 and the jacobian\r\nInteger, intent(in) :: NP, n\r\nReal(8), intent(in) :: x(NP)\r\nReal(8), intent(out) :: fvec(NP),fjac(NP,NP)\r\n\r\nInteger :: i,j,k\r\nReal(8) :: s1,s2,s3\r\n\r\nIf(n /= neqt)then\r\n Write(*,*)' E- Error in mnewt usrfun'\r\n Stop\r\nEnd if\r\n\r\n! get current values of pi lagrange multipliers\r\nDo i = 1, neqt-1\r\n pilag(i) = x(i)\r\nEnd do\r\ndlnn = x(neqt)\r\n\r\n! evaluate functions f_i(x_j)\r\nDo i = 1, neqt-1\r\n s1 = 0.0d0\r\n s2 = 0.0d0\r\n s3 = 0.0d0\r\n Do j = 1, nspec\r\n Do k = 1, neqt-1\r\n s1 = s1+ nat(j,i)*nat(j,k)*abun(j)*pilag(k)\r\n End do\r\n s2 = s2 + nat(j,i)*abun(j)\r\n s3 = s3 + nat(j,i)*abun(j)*mu(j)\r\n End do\r\n fvec(i) = s1 + s2*dlnn - b0(i) + s2 - s3\r\nEnd do\r\ns1 = 0.0d0\r\ns2 = 0.0d0\r\ns3 = 0.0d0\r\nDo j = 1, nspec\r\n Do k = 1, neqt-1\r\n s1 = s1 + nat(j,k)*abun(j)*pilag(k)\r\n End do\r\n s2 = s2 + abun(j)\r\n s3 = s3 + abun(j)*mu(j)\r\nEnd do\r\nfvec(neqt) = s1 + (s2-abuntot)*dlnn - abuntot + s2 - s3\r\n\r\n! evaluate derivatives of functions d[f_i(x_j)]/dx_j\r\nDo i = 1, neqt-1\r\n Do k = 1, neqt-1\r\n fjac(i,k) = 0.0d0\r\n Do j = 1, nspec\r\n fjac(i,k) = fjac(i,k) + nat(j,i)*nat(j,k)*abun(j)\r\n End do\r\n End do\r\n fjac(i,neqt) = 0.0d0\r\n Do j = 1, nspec\r\n fjac(i,neqt) = fjac(i,neqt) + nat(j,i)*abun(j)\r\n End do\r\nEnd do\r\nDo k = 1, neqt-1\r\n fjac(neqt,k) = 0.0d0\r\n Do j = 1, nspec\r\n fjac(neqt,k) = fjac(neqt,k) + nat(j,k)*abun(j)\r\n End do\r\nEnd do\r\nfjac(neqt,neqt) = 0.0d0\r\nDo j = 1, nspec\r\n fjac(neqt,neqt) = fjac(neqt,neqt) + abun(j)\r\nEnd do\r\nfjac(neqt,neqt) = fjac(neqt,neqt) - abuntot\r\n\r\nEnd Subroutine usrfun\r\n\r\n!######################################################################\r\n\r\n\r\nEnd Module Md_numerical_recipes\r\n", "meta": {"hexsha": "b924fe6f7304007cb9df2cda66606adcfa0590b5", "size": 11748, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/ACE/Md_numerical_recipes.f90", "max_stars_repo_name": "rychallener/TauREx3_public", "max_stars_repo_head_hexsha": "eb0eeeeca8f47e5e7d64d8d70b43a3af370b7677", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 18, "max_stars_repo_stars_event_min_datetime": "2019-07-22T01:35:24.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-10T11:25:42.000Z", "max_issues_repo_path": "src/ACE/Md_numerical_recipes.f90", "max_issues_repo_name": "rychallener/TauREx3_public", "max_issues_repo_head_hexsha": "eb0eeeeca8f47e5e7d64d8d70b43a3af370b7677", "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/ACE/Md_numerical_recipes.f90", "max_forks_repo_name": "rychallener/TauREx3_public", "max_forks_repo_head_hexsha": "eb0eeeeca8f47e5e7d64d8d70b43a3af370b7677", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2017-10-19T15:14:06.000Z", "max_forks_repo_forks_event_max_datetime": "2017-10-19T15:14:06.000Z", "avg_line_length": 34.8605341246, "max_line_length": 112, "alphanum_fraction": 0.5436670072, "num_tokens": 3703, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952811593496, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6562678362872167}} {"text": "module geq_sphax_base\n use, intrinsic :: iso_fortran_env, dp=>real64\n implicit none\n real(dp) :: asp_ratio ! rpolar / requatorial\n real(dp) :: surf_r_eq\n real(dp) :: surf_bl_a\n interface\n function pot_generic(pos) result(pot)\n import dp\n real(dp), dimension(0:3) :: pos\n real(dp), dimension(1:5) :: pot\n ! Index convention:\n ! pot: {1: V, 2: W, 3: X, 4: Y, 5: Z}\n end function\n function dpot_generic(pos) result(dpot)\n import dp\n real(dp), dimension(0:3) :: pos\n real(dp), dimension(1:5,1:2) :: dpot\n ! Index convention:\n ! dpot, first index:\n ! {1: V, 2: W, 3: X, 4: Y, 5: Z}\n ! dpot, second index: (variable w.r.t. which we differentiate)\n ! {1: r, 2: th}\n end function\n end interface\n procedure(pot_generic), pointer :: selected_pot_func => null()\n procedure(dpot_generic), pointer :: selected_dpot_func => null()\n save\ncontains\n function get_metric(pos) result(metric)\n real(dp), dimension(0:3,0:3) :: metric\n real(dp), dimension(0:3) :: pos\n real(dp), dimension(1:5) :: pot\n pot = selected_pot_func(pos)\n include \"sphax-metric.f90\"\n end function\n function geqrhs(pos, vel)\n real(dp), dimension(0:3) :: geqrhs\n real(dp), dimension(0:3) :: pos\n real(dp), dimension(0:3) :: vel\n real(dp), dimension(1:5) :: pot\n real(dp), dimension(1:5,1:2) :: dpot\n pot = selected_pot_func(pos)\n dpot = selected_dpot_func(pos)\n include \"sphax-geq.f90\"\n end function\n function surface_sph(pos,padding)\n real(dp) :: padding\n real(dp), dimension(0:3) :: pos\n logical :: surface_sph\n if (pos(1)/surf_r_eq - sin(pos(2))**2 - asp_ratio*cos(pos(2))**2 < padding) then\n surface_sph = .true.\n else\n surface_sph = .false.\n end if\n end function\n function surface_bl(pos,padding)\n real(dp) :: padding\n real(dp), dimension(0:3) :: pos\n logical :: surface_bl\n real(dp) :: r_sph, th_sph\n associate( r_bl => pos(1), th_bl => pos(2), a=> surf_bl_a )\n r_sph = sqrt( r_bl**2 + a**2*sin(th_bl)**2 )\n th_sph = acos( r_bl/r_sph * cos(th_bl) )\n if (r_sph/surf_r_eq - sin(th_sph)**2 - asp_ratio*cos(th_sph)**2 < padding ) then\n surface_bl = .true.\n else\n surface_bl = .false.\n end if\n end associate\n end function\nend module\n", "meta": {"hexsha": "533a4c0eef0d9d6587e64b02523ab09724a6d6f3", "size": 2319, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "symbolic/geq-sphax-base.f90", "max_stars_repo_name": "gandreoliva/ujti", "max_stars_repo_head_hexsha": "269c4a36fa0939acddae698b351e20590c5715db", "max_stars_repo_licenses": ["FSFAP"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "symbolic/geq-sphax-base.f90", "max_issues_repo_name": "gandreoliva/ujti", "max_issues_repo_head_hexsha": "269c4a36fa0939acddae698b351e20590c5715db", "max_issues_repo_licenses": ["FSFAP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "symbolic/geq-sphax-base.f90", "max_forks_repo_name": "gandreoliva/ujti", "max_forks_repo_head_hexsha": "269c4a36fa0939acddae698b351e20590c5715db", "max_forks_repo_licenses": ["FSFAP"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.7671232877, "max_line_length": 86, "alphanum_fraction": 0.6080206986, "num_tokens": 765, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952811593495, "lm_q2_score": 0.7310585727705126, "lm_q1q2_score": 0.656267831027178}} {"text": "program main\nuse shoelace_implementation\nimplicit none\n\tinteger :: perm(4, 24) = reshape( &\n\t\t(/ &\n\t\t\t1, 2, 3, 4, &\n\t\t\t1, 2, 4, 3, &\n\t\t\t1, 3, 2, 4, &\n\t\t\t1, 3, 4, 2, &\n\t\t\t1, 4, 2, 3, &\n\t\t\t1, 4, 3, 2, &\n\t\t\t2, 1, 3, 4, &\n\t\t\t2, 1, 4, 3, &\n\t\t\t2, 3, 1, 4, &\n\t\t\t2, 3, 4, 1, &\n\t\t\t2, 4, 1, 3, &\n\t\t\t2, 4, 3, 1, &\n\t\t\t3, 1, 2, 4, &\n\t\t\t3, 1, 4, 2, &\n\t\t\t3, 2, 1, 4, &\n\t\t\t3, 2, 4, 1, &\n\t\t\t3, 4, 1, 2, &\n\t\t\t3, 4, 2, 1, &\n\t\t\t4, 1, 2, 3, &\n\t\t\t4, 1, 3, 2, &\n\t\t\t4, 2, 1, 3, &\n\t\t\t4, 2, 3, 1, &\n\t\t\t4, 3, 1, 2, &\n\t\t\t4, 3, 2, 1 &\n\t\t/), (/ 4, 24 /) &\n\t)\n\t\n\tinteger :: row\n\treal :: temp(2, 4)\n\t\t\n\tread (*, *) &\n\t\ttemp(1, 1), temp(2, 1), &\n\t\ttemp(1, 2), temp(2, 2), &\n\t\ttemp(1, 3), temp(2, 3), &\n\t\ttemp(1, 4), temp(2, 4)\n\t\n\tdo row = 1, 24\n\t\twrite (*, *) &\n\t\t\tintersect( &\n\t\t\t\ttemp(1, perm(1, row)), temp(2, perm(1, row)), &\n\t\t\t\ttemp(1, perm(2, row)), temp(2, perm(2, row)), &\n\t\t\t\ttemp(1, perm(3, row)), temp(2, perm(3, row)), &\n\t\t\t\ttemp(1, perm(4, row)), temp(2, perm(4, row))), &\n\t\t\tshoelace( &\n\t\t\t\ttemp(1, perm(1, row)), temp(2, perm(1, row)), &\n\t\t\t\ttemp(1, perm(2, row)), temp(2, perm(2, row)), &\n\t\t\t\ttemp(1, perm(3, row)), temp(2, perm(3, row)), &\n\t\t\t\ttemp(1, perm(4, row)), temp(2, perm(4, row)))\n\tend do\t\nend program main\n\n", "meta": {"hexsha": "e42b44035e24983d6eb1ddca7615a118e478b2fa", "size": 1202, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "shoelace.f95", "max_stars_repo_name": "bachvaroff/shoelace", "max_stars_repo_head_hexsha": "910e5310112728bae37390fceab3122ce57700d1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "shoelace.f95", "max_issues_repo_name": "bachvaroff/shoelace", "max_issues_repo_head_hexsha": "910e5310112728bae37390fceab3122ce57700d1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "shoelace.f95", "max_forks_repo_name": "bachvaroff/shoelace", "max_forks_repo_head_hexsha": "910e5310112728bae37390fceab3122ce57700d1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.0877192982, "max_line_length": 52, "alphanum_fraction": 0.4143094842, "num_tokens": 675, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219503, "lm_q2_score": 0.7981867873410141, "lm_q1q2_score": 0.6562605006780172}} {"text": "program test\n logical :: flag1, flag2\n integer :: a = (2*3) * 2\n integer :: b = 2 * 3 * 2\n flag1 = a == b .and. b == 12\n if (flag1) a = 10\n PRINT *,a\nend program test\n", "meta": {"hexsha": "bc17c35ff59f2607702ca7277c66f6a532a0725a", "size": 197, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/stmts/ifstmt/if_stmt1.f90", "max_stars_repo_name": "clementval/fc", "max_stars_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/stmts/ifstmt/if_stmt1.f90", "max_issues_repo_name": "clementval/fc", "max_issues_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/stmts/ifstmt/if_stmt1.f90", "max_forks_repo_name": "clementval/fc", "max_forks_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "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": 21.8888888889, "max_line_length": 34, "alphanum_fraction": 0.4720812183, "num_tokens": 75, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.822189121808099, "lm_q2_score": 0.798186775339273, "lm_q1q2_score": 0.6562604838550352}} {"text": "C PROGRAM No. 11: QUADRATIC STRENGTH DOUBLET POTENTIAL\nC ----------------------------------------------------\nC THIS PROGRAM FINDS THE PRESSURE DISTRIBUTION ON AN ARBITRARY AIRFOIL\nC BY REPRESENTING THE SURFACE AS A FINITE NUMBER OF DOUBLET PANELS WITH\nC QUADRATIC STRENGTH (DIRICHLET B.C., PROGRAM BY STEVEN YON, 1989).\n REAL EP(400,2),EPT(400,2),PT1(400,2),PT2(400,2)\n REAL CO(400,2),A(400,400),B(400,400,3),G(400)\n REAL DL(400),U1(400),A1(400),B1(400),TH(400)\n\n OPEN(8,FILE='CPQD.DAT',STATUS='NEW')\n OPEN(9,FILE='AFOIL2.DAT',STATUS='OLD')\n\n WRITE(6,*) 'ENTER NUMBER OF PANELS'\n READ(5,*) M\n N=M+1\n WRITE(6,*) 'ENTER ANGLE OF ATTACK IN DEGREES'\n READ(5,*) ALPHA\n AL=ALPHA/57.2958\n\nC READ IN THE PANEL END POINTS\n DO I=1,M+1\n READ(9,*) EPT(I,1), EPT(I,2)\n END DO\n\nC CONVERT PANELING TO CLOCKWISE\n DO I=1,M+1\n EP(I,1)=EPT(N-I+1,1)\n EP(I,2)=EPT(N-I+1,2)\n END DO\n\nC ESTABLISH COORDINATES OF PANEL END POINTS\n DO I=1,M\n PT1(I,1)=EP(I,1)\n PT2(I,1)=EP(I+1,1)\n PT1(I,2)=EP(I,2)\n PT2(I,2)=EP(I+1,2)\n END DO\n\nC FIND PANEL ANGLES TH(J)\n DO I=1,M\n DZ=PT2(I,2)-PT1(I,2)\n DX=PT2(I,1)-PT1(I,1)\n TH(I)=ATAN2(DZ,DX)\n END DO\n\nC ESTABLISH COLLOCATION POINTS\n DO I=1,M\n CO(I,1)=(PT2(I,1)-PT1(I,1))/2+PT1(I,1)\n CO(I,2)=(PT2(I,2)-PT1(I,2))/2+PT1(I,2)\n END DO\n\nC ESTABLISH LOCATION OF ADDITIONAL COLLOCATION POINT\n WRITE(6,*) 'ENTER X COORD. OF INTERNAL POINT'\n READ(5,*) XX\n CO(M+1,1)=XX\n CO(M+1,2)=0.0\n\nC ESTABLISH INFLUENCE COEFFICIENTS\n DO I=1,M+1\n DO J=1,M\nC CONVERT COLLOCATION POINT TO LOCAL PANEL COORDS.\n XT=CO(I,1)-PT1(J,1)\n ZT=CO(I,2)-PT1(J,2)\n X2T=PT2(J,1)-PT1(J,1)\n Z2T=PT2(J,2)-PT1(J,2)\n\n X=XT*COS(TH(J))+ZT*SIN(TH(J))\n Z=-XT*SIN(TH(J))+ZT*COS(TH(J))\n X2=X2T*COS(TH(J))+Z2T*SIN(TH(J))\n Z2=0\n\nC SAVE PANEL LENGTHS FOR LATER USE\n IF(I.EQ.1) THEN\n DL(J)=X2\n END IF\n\nC FIND TH1, TH2, AND R1, R2\n R1=SQRT(X**2+Z**2)\n R2=SQRT((X-X2)**2+Z**2)\n TH1=ATAN2(Z,X)\n TH2=ATAN2(Z,X-X2)\n\nC COMPUTE THE INFLUENCE COEFFICIENTS IN\nC THE 'B' MATRIX (UNREDUCED).\n IF(I.EQ.J) THEN\n B(I,J,1)=0.5\n B(I,J,2)=0.5*X\n B(I,J,3)=0.5*X**2\n ELSE\n B(I,J,1)=-0.15916*(TH2-TH1)\n B(I,J,2)=-0.15916*(X*(TH2-TH1)+Z*LOG(R2/R1))\n B(I,J,3)=0.15916*((X**2-Z**2)*(TH1-TH2)\n * -2*X*Z*LOG(R2/R1)-Z*X2)\n END IF\n END DO\n END DO\n\nC ADD DOUBLET GRADIENT CONDITION\n B(M+2,1,1)=0\n B(M+2,1,2)=1\n B(M+2,1,3)=0\n B(M+2,M,1)=0\n B(M+2,M,2)=1\n B(M+2,M,3)=2*DL(M)\n\nC ADD KUTTA CONDITION\n B(M+3,1,1)=-1\n B(M+3,1,2)=0\n B(M+3,1,3)=0\n B(M+3,M,1)=1\n B(M+3,M,2)=DL(M)\n B(M+3,M,3)=(DL(M))**2\n\nC BACK SUBSTITUTE THE 'B' MATRIX WITH THE\nC REGRESSION FORMULA TO GET THE COMPONENTS\nC OF THE 'A' MATRIX.\n DO I=1,M+3\n DO J=M-1,1,-1\n B(I,J,1)=B(I,J,1)+B(I,J+1,1)\n B(I,J,2)=B(I,J,2)+B(I,J+1,1)*DL(J)+B(I,J+1,2)\n B(I,J,3)=B(I,J,3)+B(I,J+1,1)\n * *(DL(J))**2+2*B(I,J+1,2)*DL(J)\n END DO\n A(I,1)=B(I,1,1)\n A(I,2)=B(I,1,2)\n DO J=1,M\n A(I,J+2)=B(I,J,3)\n END DO\n END DO\n\nC ADD INFLUENCE OF WAKE AS A(I,M+3)\nC AND RHS AS A(I,M+4)\n DO I=1,M+1\n XW=CO(I,1)-PT2(M,1)\n ZW=CO(I,2)-PT2(M,2)\n DTHW=-ATAN(ZW/XW)\n A(I,M+3)=-0.15916*DTHW\n A(I,M+4)=(CO(I,1)*COS(AL)+CO(I,2)*SIN(AL))\n END DO\n\nC COMPLETE KUTTA COND. BY ADDING WAKE COEFF AND RHS\nC TO ROWS M+2 AND M+3\n A(M+2,M+3)=0\n A(M+2,M+4)=0\n A(M+3,M+3)=-1\n A(M+3,M+4)=0\n N=M+4\n\nC SOLVE FOR THE SOLUTION VECTOR OF DOUBLET STRENGTHS\n CALL MATRX(A,N,G)\n\nC CONVERT DOUBLET STRENGTHS, LINEAR CORRECTION\nC AND QUADRATIC CORRECTION INTO TANGENTIAL\nC VELOCITIES ALONG THE AIRFOIL SURFACE AND CP'S\nC ON EACH OF THE PANELS.\n\n 200 CONTINUE\n\nC FORWARD SUBSTITUTE USING THE SOLUTION VECTOR TO\nC GET THE DOUBLET STRENGTH PARAMETERS\nC FOR EACH PANEL.\n U1(1)=G(1)\n A1(1)=G(2)\n DO I=3,M+2\n B1(I-2)=G(I)\n END DO\n\n DO I=1,M-1\n U1(I+1)=U1(I)+A1(I)*DL(I)+B1(I)*(DL(I))**2\n A1(I+1)=A1(I)+2*B1(I)*DL(I)\n END DO\n\nC THE DERIVATIVE OF THE DOUBLET STRENGTH IS THE\nC SURFACE SPEED ALONG EACH PANEL.\n DO I=1,M\n VEL=A1(I)+B1(I)*DL(I)\n CP=1-VEL**2\n WRITE(8,*) CO(I,1),' ,',CP\n END DO\n\n WRITE(6,*) ' '\n WRITE(6,*) 'LIFT COEFFICIENT=', G(M+3)\n\n STOP\n END\n", "meta": {"hexsha": "5952460e706647107dce8fcacb492abe2f1c64a5", "size": 4981, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/f77/PHIQD.f", "max_stars_repo_name": "Budhyant/KatzPlotkinPy", "max_stars_repo_head_hexsha": "60f96e17dd1c4fa53b0ae5e878d455151007c334", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2020-07-21T10:19:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-09T12:54:25.000Z", "max_issues_repo_path": "tests/f77/PHIQD.f", "max_issues_repo_name": "AlwinW/KatzPlotkinPy", "max_issues_repo_head_hexsha": "60f96e17dd1c4fa53b0ae5e878d455151007c334", "max_issues_repo_licenses": ["MIT"], "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/f77/PHIQD.f", "max_forks_repo_name": "AlwinW/KatzPlotkinPy", "max_forks_repo_head_hexsha": "60f96e17dd1c4fa53b0ae5e878d455151007c334", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-07-23T22:18:24.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-25T11:33:45.000Z", "avg_line_length": 26.7795698925, "max_line_length": 78, "alphanum_fraction": 0.47922104, "num_tokens": 1994, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072386, "lm_q2_score": 0.7154239957834733, "lm_q1q2_score": 0.6562603372984258}} {"text": " SUBROUTINE lcasy6(deriv,x,jacin,j0,t3,ang,locax)\r\n !***********************************************************************\r\n !\r\n !****this routine sets up the local cartesyan system for element\r\n !\r\n !***********************************************************************\r\n IMPLICIT NONE\r\n\r\n ! routine parameters\r\n\r\n REAL (kind=8), INTENT(IN) :: deriv(:,:),x(:,:),ang\r\n REAL (kind=8), INTENT(OUT) :: t3(:),j0,jacin(:,:)\r\n INTEGER(kind=4), INTENT(IN) :: locax\r\n\r\n ! local variables\r\n\r\n REAL (kind=8) t1(3),t2(3),ta(3),gcova(3,2),lt\r\n\r\n INTERFACE\r\n INCLUDE 'vecpro.h'\r\n INCLUDE 'vecuni.h'\r\n END INTERFACE\r\n ! evaluates the local cartesian system\r\n\r\n ! convective base\r\n gcova = MATMUL(x,deriv)\r\n ! t3 normal to the plane\r\n CALL vecpro(gcova(:,1),gcova(:,2),t3)\r\n ! normalizes t3 & j0 = |t3| (jacobian)\r\n CALL vecuni(3,t3,j0)\r\n SELECT CASE(locax)\r\n CASE (1)\r\n lt = (t3(2)*t3(2)+t3(3)*t3(3)) !component in th Y-Z plane\r\n IF( lt < 1.0d-5) THEN !If t3 is almost orthogonal to Y-Z plane\r\n t2 = (/ -t3(3), 0d0, t3(1) /) !choose t2 orthogonal to global Y direction\r\n CALL vecuni(3,t2,lt)\r\n CALL vecpro(t2,t3,t1)\r\n ELSE ! SELECT local y=t1 in the global YZ plane\r\n t1 = (/ 0d0, -t3(3), t3(2) /)\r\n t2 = (/ lt, -t3(2)*t3(1), -t3(3)*t3(1) /)\r\n CALL vecuni(3,t1,lt) ! normalizes t1 & t2\r\n CALL vecuni(3,t2,lt)\r\n END IF\r\n CASE (2)\r\n lt = (t3(3)*t3(3)+t3(1)*t3(1)) !component in th Z-X plane\r\n IF( lt < 1.0d-5) THEN !If t3 is almost orthogonal to Z-Y plane\r\n t2 = (/ t3(2), -t3(1), 0d0 /) !choose t2 orthogonal to global Z direction\r\n CALL vecuni(3,t2,lt)\r\n CALL vecpro(t2,t3,t1)\r\n ELSE ! SELECT local z=t1 in the global ZX plane\r\n t1 = (/ t3(3), 0d0, -t3(1) /)\r\n t2 = (/ -t3(1)*t3(2), lt, -t3(3)*t3(2) /)\r\n CALL vecuni(3,t1,lt) ! normalizes t1 & t2\r\n CALL vecuni(3,t2,lt)\r\n END IF\r\n CASE (3)\r\n lt = (t3(1)*t3(1)+t3(2)*t3(2)) !component in th X-Y plane\r\n IF( lt < 1.0d-5) THEN !If t3 is almost orthogonal to X-Y plane\r\n t2 = (/ 0d0, t3(3), -t3(2) /) !choose t2 orthogonal to global X direction\r\n CALL vecuni(3,t2,lt)\r\n CALL vecpro(t2,t3,t1)\r\n ELSE ! SELECT local x=t1 in the global xy plane\r\n t1 = (/ -t3(2), t3(1) , 0d0 /)\r\n t2 = (/ -t3(1)*t3(3), -t3(2)*t3(3), lt /)\r\n CALL vecuni(3,t1,lt) ! normalizes t1 & t2\r\n CALL vecuni(3,t2,lt)\r\n END IF\r\n END SELECT\r\n ta = t1\r\n t1 = COS(ang)*t1 + SIN(ang)*t2\r\n t2 = -SIN(ang)*ta + COS(ang)*t2\r\n ! evaluates inverse of jacobian matrix (transpose)\r\n jacin(1,1) = DOT_PRODUCT(gcova(:,2),t2)/j0 ! phi^xita . t_x\r\n jacin(2,1) = -DOT_PRODUCT(gcova(:,2),t1)/j0 ! phi^xita . t_y\r\n jacin(1,2) = -DOT_PRODUCT(gcova(:,1),t2)/j0 ! phi^eta . t_x\r\n jacin(2,2) = DOT_PRODUCT(gcova(:,1),t1)/j0 ! phi^eta . t_y\r\n\r\n RETURN\r\n END SUBROUTINE lcasy6\r\n", "meta": {"hexsha": "5041fe37c9c3a4c490abaa6325d4cee0a098156f", "size": 2973, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/shelq/lcasy6.f90", "max_stars_repo_name": "jerebenitez/IFE-simpact-openfoam", "max_stars_repo_head_hexsha": "2dbcbf3195b22fca1c80ad0da6b3822b6cad5cdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/shelq/lcasy6.f90", "max_issues_repo_name": "jerebenitez/IFE-simpact-openfoam", "max_issues_repo_head_hexsha": "2dbcbf3195b22fca1c80ad0da6b3822b6cad5cdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/shelq/lcasy6.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": 37.1625, "max_line_length": 79, "alphanum_fraction": 0.5132862429, "num_tokens": 1117, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026550642019, "lm_q2_score": 0.7154239897159438, "lm_q1q2_score": 0.6562603252630596}} {"text": "! The tsunami example from _Modern Fortran_.\nprogram tsunami\n\n implicit none\n\n integer, parameter :: nx = 100 ! grid dimension\n integer, parameter :: nt = 100 ! number of time steps\n real, parameter :: dt = 1.0 ! time step [s]\n real, parameter :: dx = 1.0 ! grid spacing [m]\n real, parameter :: c = 1.0 ! phase speed of wave [m s-1]\n integer, parameter :: icenter = 25 ! node of wave center\n real, parameter :: decay = 0.02 ! decay factor of wave shape\n\n integer :: i, n\n real :: h(nx) ! wave height [m]\n real :: dh(nx) ! change in wave height [m]\n\n do i = 1, nx\n h(i) = exp(-decay * (i - icenter)**2)\n end do\n\n print *, 0, h\n\n time_loop: do n = 1, nt\n\n dh(1) = h(1) - h(nx)\n\n do i = 2, nx\n dh(i) = h(i) - h(i-1)\n end do\n\n do i = 1, nx\n h(i) = h(i) - c * dh(i) / dx * dt\n end do\n\n print *, n, h\n\n end do time_loop\n\nend program tsunami\n", "meta": {"hexsha": "98b187a7e121dd3f054168dd845011ac20254c6f", "size": 997, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tsunami/1/tsunami.f90", "max_stars_repo_name": "mdpiper/fortran-examples", "max_stars_repo_head_hexsha": "2fb36f07d2cf60172db1215d0128ed11cbf535de", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tsunami/1/tsunami.f90", "max_issues_repo_name": "mdpiper/fortran-examples", "max_issues_repo_head_hexsha": "2fb36f07d2cf60172db1215d0128ed11cbf535de", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tsunami/1/tsunami.f90", "max_forks_repo_name": "mdpiper/fortran-examples", "max_forks_repo_head_hexsha": "2fb36f07d2cf60172db1215d0128ed11cbf535de", "max_forks_repo_licenses": ["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.3170731707, "max_line_length": 69, "alphanum_fraction": 0.5035105316, "num_tokens": 318, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026505426832, "lm_q2_score": 0.7154239897159439, "lm_q1q2_score": 0.6562603220282567}} {"text": " SUBROUTINE ga_niche(myid)\nc#######################################################################\nc\nc Implement \"niching\" through Goldberg''s multidimensional phenotypic\nc sharing scheme with a triangular sharing FUNCTION. To find the\nc multidimensional distance from the best individual, normalize ALL\nc PARAMETER differences.\nc\n USE ga_mod\n USE mpi_params, ONLY: master\n IMPLICIT NONE\n REAL(rprec) :: alpha, del, del2, sigshar, SUMshar, share\n INTEGER :: nniche, jj, ii, j, k, myid\n SAVE\nc\nc Variable definitions:\nc\nc alpha = power law exponent for sharing function; typically = 1.0\nc del = normalized multidimensional distance between ii and ALL\nc other members of the population\nc (equals the square root of del2)\nc del2 = sum of the squares of the normalized multidimensional\nc distance between member ii and all other members of\nc the population\nc nniche = number of niched parameters\nc sigshar = normalized distance to be compared with del; in some sense,\nc 1/sigshar can be viewed as the number of regions over which\nc the sharing function should focus, e.g. with sigshar=0.1,\nc the sharing function will try to clump in ten distinct\nc regions of the phase space. a value of sigshar on the\nc order of 0.1 seems to work best.\nc share = sharing function between individual ii and j\nc sumshar = sum of the sharing functions for individual ii\nc\n alpha=1\n sigshar=0.1_dp\n nniche=0\n DO 33 jj=1,nparam\n nniche=nniche+nichflg(jj)\n 33 CONTINUE\n IF (nniche.eq.0) THEN\n IF (myid .eq. master) THEN\n WRITE(6,1900)\n WRITE(iunit_ga_out,1900)\n CLOSE(iunit_ga_out)\n END IF\n STOP\n END IF\n DO 34 ii=1,npopsiz\n SUMshar=0\n DO 35 j=1,npopsiz\n del2=0\n DO 36 k=1,nparam\n IF (nichflg(k).ne.0) THEN\n del2=del2+((parent(k,j)-parent(k,ii))/pardel(k))**2\n END IF\n 36 CONTINUE\n del=SQRT(del2)/nniche\n IF (del.lt.sigshar) THEN\nc share=1.0-((del/sigshar)**alpha)\n share=1-(del/sigshar)\n ELSE\n share=0\n END IF\n SUMshar=sumshar+share/npopsiz\n 35 CONTINUE\n IF (sumshar.ne.0.0_dp) fitness(ii)=fitness(ii)/sumshar\n 34 CONTINUE\n\n 1900 FORMAT(1x,'ERROR: iniche=1 and ALL values in nichflg array = 0'/\n 1 1x,' Do you want to niche or not?')\n\n END SUBROUTINE ga_niche\n", "meta": {"hexsha": "93b9a739ba2d0a7ccdc31adcb4aa5f0d9972eece", "size": 2624, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "LIBSTELL/Sources/Optimization/ga_niche.f", "max_stars_repo_name": "jonathanschilling/VMEC_8_00", "max_stars_repo_head_hexsha": "25519df38bf81bcb673dd9374bda11988de2d940", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2020-05-08T01:47:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T10:35:28.000Z", "max_issues_repo_path": "LIBSTELL/Sources/Optimization/ga_niche.f", "max_issues_repo_name": "jonathanschilling/VMEC_8_00", "max_issues_repo_head_hexsha": "25519df38bf81bcb673dd9374bda11988de2d940", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 77, "max_issues_repo_issues_event_min_datetime": "2020-05-08T07:18:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:20:33.000Z", "max_forks_repo_path": "LIBSTELL/Sources/Optimization/ga_niche.f", "max_forks_repo_name": "jonathanschilling/VMEC_8_00", "max_forks_repo_head_hexsha": "25519df38bf81bcb673dd9374bda11988de2d940", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-02-10T13:47:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T12:53:43.000Z", "avg_line_length": 35.4594594595, "max_line_length": 72, "alphanum_fraction": 0.5929878049, "num_tokens": 738, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026482819238, "lm_q2_score": 0.7154239897159439, "lm_q1q2_score": 0.6562603204108551}} {"text": "subroutine GLQGridCoord(latglq, longlq, lmax, nlat, nlong, extend, exitstatus)\n!------------------------------------------------------------------------------\n!\n! Given a maximum spherical harmonic degree lmax, this routine\n! will determine the latitude and longitude coordinates associated with\n! grids that are used in the Gauss-Legendre quadratue spherical harmonic\n! expansion routines. The coordinates are output in DEGREES.\n!\n! Calling Parameters\n! IN\n! lmax Maximum spherical harmonic degree of the expansion.\n!\n! OUT\n! latglq Array of latitude points used in Gauss-Legendre\n! grids, in degrees.\n! longlq Array of longitude points used in Gauss-Legendre\n! grids, in degrees.\n! nlat Number of latitude points.\n! nlong Number of longitude points.\n!\n! OPTIONAL (IN)\n! extend If 1, return a grid that contains an additional column\n! for 360 E longitude.\n!\n! OPTIONAL (OUT)\n! exitstatus If present, instead of executing a STOP when an error\n! is encountered, the variable exitstatus will be\n! returned describing the error.\n! 0 = No errors;\n! 1 = Improper dimensions of input array;\n! 2 = Improper bounds for input variable;\n! 3 = Error allocating memory;\n! 4 = File IO error.\n!\n! Copyright (c) 2005-2019, SHTOOLS\n! All rights reserved.\n!\n!------------------------------------------------------------------------------\n use SHTOOLS, only: PreGLQ\n use ftypes\n\n implicit none\n\n integer, intent(in) :: lmax\n integer, intent(out) :: nlat, nlong\n real(dp), intent(out) :: latglq(:), longlq(:)\n integer, intent(in), optional :: extend\n integer, intent(out), optional :: exitstatus\n real(dp) :: pi, upper, lower, zero(lmax+1), w(lmax+1)\n integer :: i, nlong_out\n\n if (present(exitstatus)) exitstatus = 0\n\n nlat = lmax + 1\n nlong = 2 * lmax + 1\n\n if (present(extend)) then\n if (extend == 0) then\n nlong_out = nlong\n else if (extend == 1) then\n nlong_out = nlong + 1\n else\n print*, \"Error --- GLQGridCoord\"\n print*, \"Optional parameter EXTEND must be 0 or 1.\"\n print*, \"Input value is \", extend\n if (present(exitstatus)) then\n exitstatus = 2\n return\n else\n stop\n end if\n end if\n else\n nlong_out = nlong\n end if\n\n if (size(latglq) < nlat) then\n print*, \"Error --- GLQGridCoord\"\n print*, \"LATGLQ must be dimensioned as (LMAX+1) where LMAX is \", lmax\n print*, \"Input array is dimensioned as \", size(latglq)\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n else if (size(longlq) < nlong_out) then\n print*, \"Error --- GLQGridCoord\"\n print*, \"LONGLQ must be dimensioned as \", nlong_out\n print*, \"Input array is dimensioned as \", size(longlq)\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n end if\n\n pi = acos(-1.0_dp)\n\n upper = 1.0_dp\n lower = -1.0_dp\n\n if (present(exitstatus)) then\n call PreGLQ(lower, upper, nlat, zero, w, exitstatus = exitstatus)\n if (exitstatus /= 0) return\n else\n call PreGLQ(lower, upper, nlat, zero, w)\n end if\n\n do i = 1, nlong_out\n longlq(i) = 360.0_dp * dble(i-1) / dble(nlong)\n end do\n\n do i = 1, nlat\n latglq(i) = asin(zero(i)) * 180.0_dp / pi\n end do\n\nend subroutine GLQGridCoord\n", "meta": {"hexsha": "7253ff1d007c8cc13707db83de96fb3d4e9c9753", "size": 3859, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/GLQGridCoord.f95", "max_stars_repo_name": "megies/SHTOOLS", "max_stars_repo_head_hexsha": "740455a28eafb6bb23a449cdec43724e86d99c4f", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/GLQGridCoord.f95", "max_issues_repo_name": "megies/SHTOOLS", "max_issues_repo_head_hexsha": "740455a28eafb6bb23a449cdec43724e86d99c4f", "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/GLQGridCoord.f95", "max_forks_repo_name": "megies/SHTOOLS", "max_forks_repo_head_hexsha": "740455a28eafb6bb23a449cdec43724e86d99c4f", "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.631147541, "max_line_length": 79, "alphanum_fraction": 0.5301891682, "num_tokens": 994, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835371034369, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.6561123866797788}} {"text": " program demo_aimag\n use, intrinsic :: iso_fortran_env, only : real_kinds, &\n & real32, real64, real128\n implicit none\n complex(kind=real32) z4\n complex(kind=real64) z8\n z4 = cmplx(1.e0, 2.e0)\n z8 = cmplx(3.e0_real64, 4.e0_real64,kind=real64)\n print *, aimag(z4), aimag(z8)\n ! an elemental function can be passed an array\n print *\n print *, [z4,z4/2.0,z4+z4,z4**3]\n print *\n print *, aimag([z4,z4/2.0,z4+z4,z4**3])\n end program demo_aimag\n", "meta": {"hexsha": "a97b95cb34fcb571fbab643c49d01ce96d427181", "size": 613, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/demo_aimag.f90", "max_stars_repo_name": "urbanjost/fortran-intrinsic-manpages", "max_stars_repo_head_hexsha": "672e0545bcbef3dd6c8169c8f6b8424dbb3f0880", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-06-30T07:29:39.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-10T07:36:25.000Z", "max_issues_repo_path": "example/demo_aimag.f90", "max_issues_repo_name": "urbanjost/fortran-intrinsic-manpages", "max_issues_repo_head_hexsha": "672e0545bcbef3dd6c8169c8f6b8424dbb3f0880", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-10-07T21:29:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-07T00:19:52.000Z", "max_forks_repo_path": "example/demo_aimag.f90", "max_forks_repo_name": "urbanjost/fortran-intrinsic-manpages", "max_forks_repo_head_hexsha": "672e0545bcbef3dd6c8169c8f6b8424dbb3f0880", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-10-08T00:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-08T00:41:17.000Z", "avg_line_length": 38.3125, "max_line_length": 66, "alphanum_fraction": 0.4959216966, "num_tokens": 183, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835289107307, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.6561123844439821}} {"text": "! Generated by TAPENADE (INRIA, Ecuador team)\n! Tapenade 3.16 (master) - 9 Oct 2020 17:47\n!\nMODULE MOD_VARIANCE_D\n USE MOD_MEAN_D, ONLY : mean_d\n USE MOD_MATH_D, ONLY : divide_d, subtract_d\n IMPLICIT NONE\n PUBLIC :: variance_d\n PRIVATE \n\nCONTAINS\n! Differentiation of variance in forward (tangent) mode (with options i4 dr8 r8):\n! variations of useful results: b\n! with respect to varying inputs: a\n! RW status of diff variables: a:in b:out\n SUBROUTINE VARIANCE_D(a, ad, b, bd)\n IMPLICIT NONE\n real(8), DIMENSION(:), INTENT(INOUT) :: a\n real(8), DIMENSION(:), INTENT(INOUT) :: ad\n real(8), INTENT(INOUT) :: b\n real(8), INTENT(INOUT) :: bd\n real(8) :: meanval\n real(8) :: meanvald\n real(8) :: temp1\n real(8) :: temp1d\n real(8) :: temp2\n real(8) :: temp2d\n real(8) :: n\n INTEGER*8 :: i\n INTRINSIC SIZE\n INTRINSIC REAL\n INTRINSIC INT\n meanval = 0.0\n CALL MEAN_D(a, ad, meanval, meanvald)\n n = REAL(SIZE(a), 8)\n b = 0.0\n bd = 0.0_8\n DO i=1,INT(n)\n CALL SUBTRACT_D(a(i), ad(i), meanval, meanvald, temp1, temp1d)\n temp1d = 2*temp1*temp1d\n temp1 = temp1**2\n CALL DIVIDE_D(temp1, temp1d, n, temp2, temp2d)\n bd = bd + temp2d\n b = b + temp2\n END DO\n END SUBROUTINE VARIANCE_D\n\nEND MODULE MOD_VARIANCE_D\n", "meta": {"hexsha": "5dd9f55abf6380f78159640db4800a60bd13fd9e", "size": 1321, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/adjoint/forward/mod_variance_d.f90", "max_stars_repo_name": "bernardopacini/f90wrapTemplate", "max_stars_repo_head_hexsha": "801d3ab0a4394a5256f419dbae67457a110f1fb1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2022-02-10T20:54:27.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T22:40:21.000Z", "max_issues_repo_path": "src/adjoint/forward/mod_variance_d.f90", "max_issues_repo_name": "bernardopacini/f90wrapTemplate", "max_issues_repo_head_hexsha": "801d3ab0a4394a5256f419dbae67457a110f1fb1", "max_issues_repo_licenses": ["MIT"], "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/adjoint/forward/mod_variance_d.f90", "max_forks_repo_name": "bernardopacini/f90wrapTemplate", "max_forks_repo_head_hexsha": "801d3ab0a4394a5256f419dbae67457a110f1fb1", "max_forks_repo_licenses": ["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.9591836735, "max_line_length": 82, "alphanum_fraction": 0.61998486, "num_tokens": 495, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711908591638, "lm_q2_score": 0.7718434925908525, "lm_q1q2_score": 0.6560447325543431}} {"text": " SUBROUTINE GETGAUHER (vm,sg,veltemp,Nvhist,Nvmax,dvhist,\n & hh,Nhermmax,gam,ingam)\nC\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC\nC Calculate the first Nhermmax Gauss-Hermite moments from the histogram\nC veltemp with spacing dvhist, using the values vm and sg for the weighting\nC function. The results are returned in hh.\nC\nC If ingam=1, then gam is taken as input.\nC If ingam=0, then gam is returned on output such that h0=1.\nC\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC\n IMPLICIT REAL*8 (a-h,o-z)\n IMPLICIT INTEGER*4 (i-n)\nC\n PARAMETER (pi = 3.14159265358979323846D0)\nC\n DIMENSION veltemp(-Nvmax:Nvmax),hh(0:Nhermmax)\nC\nCCCCCCCCCCCCCCCCCCCC\nC\nC Initialize\nC\n \n DO l=0,Nhermmax\n hh(l) = 0.0D0\n END DO\nC\nC Loop over the velocities\nC\n DO i=-Nvhist,Nvhist\nC\n vel = dvhist * DBLE(i)\n w = (vel-vm)/sg\nC\nC Loop over the Gauss-Hermite moments\nC\n DO l=0,Nhermmax\n hh(l) = hh(l) + (veltemp(i)*SDGAUSS(w)*H_POL(l,w))\n END DO\nC\n END DO\nC\nC Normalize properly. The factor dvhist arises through the stepsize of the\nC Euler integration. The value of gamma is determined by the constraint\nC that h0=1.\nC\n IF (ingam.EQ.0) THEN\n gam = hh(0) * 2.0D0 * SQRT(pi) * dvhist\n END IF\nC\n DO l=0,Nhermmax\n hh(l) = hh(l) * 2.0D0 * SQRT(pi) * dvhist / gam\n END DO\nC\n END\n\n\n SUBROUTINE GETGAUSSWEIGHTMOM\n & (vm,sg,veltemp,Nvhist,Nvmax,dvhist,gw,Nmommax)\nC\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC\nC Calculate the first Nmommax Gaussian weighted moments from the histogram\nC veltemp with spacing dvhist, using the values vm and sg for the weighting\nC function. The results are returned in hh.\nC\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC\n IMPLICIT REAL*8 (a-h,o-z)\nC\n PARAMETER (pi = 3.14159265358979323846D0)\nC\n DIMENSION veltemp(-Nvmax:Nvmax),gw(0:Nmommax)\nC\nCCCCCCCCCCCCCCCCCCCC\nC\nC Initialize\nC\n DO l=0,Nmommax\n gw(l) = 0.0D0\n END DO\nC\nC Loop over the velocities\nC\n DO i=-Nvhist,Nvhist\nC\n vel = dvhist * DBLE(i)\n w = (vel-vm)/sg\nC\nC Loop over the moments\nC\n DO l=0,Nmommax\n gw(l) = gw(l) + (veltemp(i)*SDGAUSS(w)*(vel**l))\n END DO\nC\n END DO\nC\nC Normalize properly\nC\n DO l=0,Nmommax\n gw(l) = gw(l) * dvhist\n END DO\nC\n END\n\n\n SUBROUTINE GETTRUEMOM (veltemp,Nvhist,Nvmax,dvhist,\n & allmom,Nmommax)\nC\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC\nC Calculate the first Nmommax moments from the histogram\nC veltemp with spacing dvhist. The results are returned in allmom.\nC\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC\n IMPLICIT REAL*8 (a-h,o-z)\n IMPLICIT INTEGER*4 (i-n)\nC\n DIMENSION veltemp(-Nvmax:Nvmax),allmom(0:Nmommax)\nC\nCCCCCCCCCCCCCCCCCCCC\nC\nC Initialize\nC\n DO l=0,Nmommax\n allmom(l) = 0.0D0\n END DO\nC\nC Loop over the velocities\nC\n DO i=-Nvhist,Nvhist\nC\n vel = dvhist * DBLE(i)\nC\nC Loop over the moments\nC\n DO l=0,Nmommax\n allmom(l) = allmom(l) + (veltemp(i)*(vel**l))\n END DO\nC\n END DO\nC\nC Normalize properly\nC\n DO l=0,Nmommax\n allmom(l) = allmom(l) * dvhist\n END DO\nC\n END\n\n\n SUBROUTINE GAUSSFIT (veltemp,Nvhist,Nvmax,dvhist,\n & gam,vm,sg,h12,NMC)\nC\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC\nC Calculate the normalization gam, mean vm and dispersion sg of\nC the best-fitting Gaussian to the histogram veltemp with spacing dvhist.\nC\nC A good initial guess is sought using a random number scheme, by drawing\nC NMC (vm,sg) points.\nC\nC The program uses an amoeba scheme which should be very robust.\nC\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC\n IMPLICIT REAL*8 (a-h,o-z)\n IMPLICIT INTEGER*4 (i-n) \nC\n PARAMETER (eps = 1.0D-10 ,\n & Nhistmax = 10000 )\nC\n DIMENSION veltemp(-Nvmax:Nvmax),vvtemp(-Nhistmax:Nhistmax),\n & allmom(0:2)\nC\nC Starting simpleces for routine AMOEBA, and the function values\nC in the starting simplices.\nC\n DIMENSION P(3,2),Y(3),help(2)\nC\n COMMON /vpcur/ vvtemp,dvhistt,gamma,Nvhistt\n COMMON /truesigcur/ sg0\nC\n EXTERNAL CHI2H_2D\nC\nCCCCCCCCCCCCCCCCCCCC\nC\nC Store the velocity profile in a common block\nC\n Nvhistt = Nvhist\n dvhistt = dvhist\n DO i=-Nhistmax,Nhistmax\n IF (ABS(i).LE.Nvhist) THEN\n vvtemp(i) = veltemp(i)\n ELSE\n vvtemp(i) = 0.0D0\n END IF\n END DO\nC\nCCCCCCCCCCCCCCCCCCCC\nC\nC Get the lowest order true moments\nC\n CALL GETTRUEMOM (veltemp,Nvhist,Nvmax,dvhist,allmom,2)\nC\nC Initialize the estimates for the mean and dispersion of the best\nC Gaussian fit.\nC\n vm0 = allmom(1)/allmom(0)\n sg0 = SQRT((allmom(2)/allmom(0))-(vm0*vm0))\nC\nCCCCCCCCCCCCCCCCCCCC\nC\nC Draw a certain number of random points in (vm,sg). Remember\nC the one with the lowest CHI2H_2D.\nC\n Ndraw = NMC\n idum = -100\n vm = vm0\n sg = sg0\n help(1) = vm\n help(2) = sg\n chi2min = CHI2H_2D(help)\nC\n51 DO i=1,Ndraw\n help(1) = vm0 + (2.0D0 * sg0 * ((2.0D0*randraw(idum))-1.0D0))\n help(2) = 2.0D0 * sg0 * randraw(idum)\n chi2cur = CHI2H_2D(help)\n IF (chi2cur.LT.chi2min) THEN\n vm = help(1)\n sg = help(2)\n chi2min = chi2cur\n END IF\n END DO\nC\nCCCCCCCCCCCCCCCCCCCC\nC\nC Initialize the starting simplex fits\nC\n epsmal = 0.2D0\n pl1 = 1.0D0 + epsmal\n xmn1 = 1.0D0 - epsmal\nC\n P(1,1) = vm + (epsmal*sg)\n P(1,2) = pl1 * sg\n P(2,1) = vm - (epsmal*sg)\n P(2,2) = xmn1 * sg\n P(3,1) = vm + (epsmal*sg)\n P(3,2) = xmn1 * sg\nC\nC Initialize\nC\n DO i=1,3\n DO j=1,2\n help(j) = P(i,j)\n END DO\n Y(i) = CHI2H_2D(help)\n END DO\nC\n CALL AMOEBA(P,Y,3,2,2,eps,CHI2H_2D,iter)\nC\n vm = (P(1,1)+P(2,1)+P(3,1)) / 3.0D0\n sg = (ABS(P(1,2))+ABS(P(2,2))+ABS(P(3,2))) / 3.0D0\nC\n help(1) = vm\n help(2) = sg\n h12 = CHI2H_2D(help) - 1.0D0\n gam = gamma\nC\nC Start from the beginning if the found minimum does not satisfy\nC h1=h2=0 to high enough accuracy.\nC\n IF ((h12.GT.100.0D0*eps).AND.(Ndraw.LE.3000)) THEN\n Ndraw = Ndraw*5\n chi2min = h12 + 1.0D0\n WRITE (*,*) 'Redraw', Ndraw\n GOTO 51\n END IF\nC\n END\n\n\n\n\n REAL*8 FUNCTION CHI2H_2D (y)\nC\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC\nC Calculates the chih^2 = (h1^2) + (h2^2) for a Gaussian\nC with parameters Vgau = y(1), sig = |y(2)|,\nC for the VP in the common block /vpcur/\nC\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC\n IMPLICIT REAL*8 (a-h,o-z)\n IMPLICIT INTEGER*4 (i-n) \nC\n PARAMETER (Nhistmax = 10000)\nC\n DIMENSION y(2),harr(0:10)\nC\n DIMENSION veltemp(-Nhistmax:Nhistmax)\n COMMON /vpcur/ veltemp,dvhist,gam,Nvhist\n COMMON /truesigcur/ sg0\nC\nCCCCCCCCCCCCCCCCCCCC\nC\nC Note: it may be necessary to avoid values of gamma and sigma too\nC close to zero.\nC\n vm = y(1)\n sg = MAX(0.1D0*sg0,ABS(y(2)))\nC\n CALL GETGAUHER (vm,sg,veltemp,Nvhist,Nhistmax,dvhist,\n & harr,2,gam,0)\nC\n CHI2H_2D = 1.0D0 + SQRT(MAX(0.0D0,\n & (harr(1)**2.0D0)+(harr(2)**2.0D0) ))\nC\n END\n\n\n SUBROUTINE GAUSSFITfix (veltemp,Nvhist,Nvmax,dvhist,\n & vm,sg,h12,NMC)\nC\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC\nC Calculate the normalization mean vm and dispersion sg of\nC the best-fitting NORMALIZED Gaussian to the histogram veltemp with\nC spacing dvhist.\nC\nC A good initial guess is sought using a random number scheme, by drawing\nC NMC (vm,sg) points.\nC\nC The program uses an amoeba scheme which should be very robust.\nC\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC\n IMPLICIT REAL*8 (a-h,o-z)\n IMPLICIT INTEGER*4 (i-n) \nC\n PARAMETER (eps = 1.0D-10 ,\n & Nhistmax = 10000 )\nC\n DIMENSION veltemp(-Nvmax:Nvmax),vvtemp(-Nhistmax:Nhistmax),\n & allmom(0:2)\nC\nC Starting simpleces for routine AMOEBA, and the function values\nC in the starting simplices.\nC\n DIMENSION P(3,2),Y(3),help(2)\nC\n COMMON /vpcur_FIX/ vvtemp,dvhistt,Nvhistt\n COMMON /truesigcur_FIX/ sg0\nC\n EXTERNAL CHI2H_2D_FIX\nC\nCCCCCCCCCCCCCCCCCCCC\nC\nC Store the velocity profile in a common block\nC\n Nvhistt = Nvhist\n dvhistt = dvhist\n DO i=-Nhistmax,Nhistmax\n IF (ABS(i).LE.Nvhist) THEN\n vvtemp(i) = veltemp(i)\n ELSE\n vvtemp(i) = 0.0D0\n END IF\n END DO\nC\nCCCCCCCCCCCCCCCCCCCC\nC\nC Get the lowest order true moments\nC\n CALL GETTRUEMOM (veltemp,Nvhist,Nvmax,dvhist,allmom,2)\nC\nC Initialize the estimates for the mean and dispersion of the best\nC Gaussian fit.\nC\n vm0 = allmom(1)/allmom(0)\n sg0 = SQRT((allmom(2)/allmom(0))-(vm0*vm0))\nC\nCCCCCCCCCCCCCCCCCCCC\nC\nC Draw a certain number of random points in (vm,sg). Remember\nC the one with the lowest CHI2H_2D.\nC\n Ndraw = NMC\n idum = -100\n vm = vm0\n sg = sg0\n help(1) = vm\n help(2) = sg\n chi2min = CHI2H_2D_FIX(help)\nC\n51 DO i=1,Ndraw\n help(1) = vm0 + (2.0D0 * sg0 * ((2.0D0*randraw(idum))-1.0D0))\n help(2) = 2.0D0 * sg0 * randraw(idum)\n chi2cur = CHI2H_2D_FIX(help)\n IF (chi2cur.LT.chi2min) THEN\n vm = help(1)\n sg = help(2)\n chi2min = chi2cur\n END IF\n END DO\nC\nCCCCCCCCCCCCCCCCCCCC\nC\nC Initialize the starting simplex fits\nC\n epsmal = 0.2D0\n pl1 = 1.0D0 + epsmal\n xmn1 = 1.0D0 - epsmal\nC\n P(1,1) = vm + (epsmal*sg)\n P(1,2) = pl1 * sg\n P(2,1) = vm - (epsmal*sg)\n P(2,2) = xmn1 * sg\n P(3,1) = vm + (epsmal*sg)\n P(3,2) = xmn1 * sg\nC\nC Initialize\nC\n DO i=1,3\n DO j=1,2\n help(j) = P(i,j)\n END DO\n Y(i) = CHI2H_2D_FIX(help)\n END DO\nC\n CALL AMOEBA(P,Y,3,2,2,eps,CHI2H_2D_FIX,iter)\nC\n vm = (P(1,1)+P(2,1)+P(3,1)) / 3.0D0\n sg = (ABS(P(1,2))+ABS(P(2,2))+ABS(P(3,2))) / 3.0D0\nC\n help(1) = vm\n help(2) = sg\n h12 = CHI2H_2D_FIX(help) - 1.0D0\nC\nC Start from the beginning if the found minimum does not satisfy\nC h12 = 0 to high enough accuracy.\nC\n IF ((h12.GT.100.0D0*eps).AND.(Ndraw.LE.3000)) THEN\n Ndraw = Ndraw*5\n chi2min = h12 + 1.0D0\n WRITE (*,*) 'Redraw', Ndraw\n GOTO 51\n END IF\nC\n END\n\n\n REAL*8 FUNCTION CHI2H_2D_FIX (y)\nC\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC\nC Calculates the chih^2 = (h1^2) + ((h0-SQRT(2)*h2)^2) for a Gaussian\nC with parameters Vgau = y(1), sig = |y(2)|,\nC for the VP in the common block /vpcur_FIX/\nC\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC\n IMPLICIT REAL*8 (a-h,o-z)\n IMPLICIT INTEGER*4 (i-n) \nC\n PARAMETER (Nhistmax = 10000)\nC\n DIMENSION y(2),harr(0:10)\nC\n DIMENSION veltemp(-Nhistmax:Nhistmax)\n COMMON /vpcur_FIX/ veltemp,dvhist,Nvhist\n COMMON /truesigcur_FIX/ sg0\nC\nCCCCCCCCCCCCCCCCCCCC\nC\n vm = y(1)\n sg = MAX(0.1D0*sg0,ABS(y(2)))\nC\n CALL GETGAUHER (vm,sg,veltemp,Nvhist,Nhistmax,dvhist,\n & harr,2,1.0D0,1)\nC\n CHI2H_2D_FIX = 1.0D0 + SQRT(MAX(0.0D0,\n & (harr(1)**2.0D0) +\n & ((1.0D0-harr(0)+(SQRT(2.0D0)*harr(2)))**2.0D0) ))\nC\n END\n\n\n REAL*8 FUNCTION SDGAUSS (x)\nC\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC\nC Returns the standard Gaussian as function of x\nC\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC\n IMPLICIT REAL*8 (a-h,o-z)\n IMPLICIT INTEGER*4 (i-n) \n PARAMETER (pi=3.14159265358979D0)\n SDGAUSS = (1.0D0/SQRT(2.0D0*pi)) * EXPP(-0.5D0*x*x)\n END\n\n\n REAL*8 FUNCTION EXPP(x)\nC\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC\nC Modified exponential function that will not underflow\nC\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC\n IMPLICIT REAL*8 (a-h,o-z)\n IF (x.GE.-500D0) THEN\n EXPP = EXP(x)\n ELSE\n EXPP = 0.0D0\n END IF\n END\n\n\n REAL*8 FUNCTION HE_POL (ll,x)\nC\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC\nC Returns the value of the Hermite polynomial He_l(x) as defined\nC in Appendix A of van der Marel & Franx.\nC\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC\n IMPLICIT REAL*8 (a-h,o-z)\n IMPLICIT INTEGER*4 (i-n)\nC\n LOGICAL firstc\n DATA firstc/.TRUE./\nC\n DIMENSION pfac(0:20,0:20)\n SAVE firstc,pfac\nC\nCCCCCCCCCCCCCCCCCCCC\nC\n IF (firstc) THEN\n DO l=0,20\n dl = DBLE(l)\n DO j=l,0,-1\n IF (2*((j+l)/2).EQ.j+l) THEN\n dj = DBLE(j)\n pfacln = (0.5D0*gammaln(dl+1.0D0)) -\n & gammaln(dj+1.0D0) - gammaln(dl-dj+1.0D0) +\n & gammaln(0.5D0*(dl-dj+1.0D0)) -\n & gammaln(0.5D0) + (0.5D0*(dl-dj)*LOG(2.0D0))\n pfac(l,j) = ((-1.0D0)**((l-j)/2)) * EXPP(pfacln)\n ELSE\n pfac(l,j) = 0.0D0\n END IF\n END DO\n END DO\n firstc = .FALSE.\n END IF\nC\nCCCCCCCCCCCCCCCCCCCC\nC\n HE_POL = 0.0D0\n DO j=ll,0,-1\n HE_POL = pfac(ll,j) + (x*HE_POL)\n END DO\nC\n END\n\n\n REAL*8 FUNCTION H_POL (l,x)\nC\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC\nC Returns the value of the Hermite polynomial H_l(x) as defined\nC in Appendix A of van der Marel & Franx.\nC\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC\n IMPLICIT REAL*8 (a-h,o-z)\n IMPLICIT INTEGER*4 (i-n) \n H_POL = HE_POL(l,x*SQRT(2.0D0))\n END\n\n\n REAL*8 FUNCTION gammaln(x)\nC\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC\nC The logarithm of the gamma function\nC\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC\n IMPLICIT REAL*8 (a-h,o-z)\n PARAMETER (pi=3.14159265358979D0)\n IF (x.GE.1.0D0) THEN\n gammaln = gammln(x)\n ELSE IF (x.GE.0.0D0) THEN\n z = 1.0D0 - x\n gammaln = (LOG((pi*z)/SIN(pi*z))) - gammln(2.0D0-x)\n ELSE\n PAUSE 'x < 0 in gammaln'\n END IF\n END\n\n\n REAL*8 FUNCTION gammln(x)\nC\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC\nC From Numerical recipes. Modified to be double precision\nC\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC\n IMPLICIT REAL*8 (a-h,o-z)\n INTEGER j\n DIMENSION cof(6)\n SAVE cof,stp\n DATA cof,stp/76.18009172947146d0,-86.50532032941677d0,\n *24.01409824083091d0,-1.231739572450155d0,.1208650973866179d-2,\n *-.5395239384953d-5,2.5066282746310005d0/\n y=x\n tmp=x+5.5d0\n tmp=(x+0.5d0)*log(tmp)-tmp\n ser=1.000000000190015d0\n do 11 j=1,6\n y=y+1.d0\n ser=ser+cof(j)/y\n11 continue\n gammln=tmp+log(stp*ser/x)\n return\n END\n\n\n SUBROUTINE amoeba(p,y,mp,np,ndim,ftol,funk,iter)\nC\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC\nC From Numerical Recipes. Modified to be double precision\nC\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC\n IMPLICIT REAL*8 (a-h,o-z)\n INTEGER*4 iter,mp,ndim,np,NMAX,ITMAX\n REAL*8 ftol,p(mp,np),y(mp),funk\n PARAMETER (NMAX=20,ITMAX=1000)\n EXTERNAL funk\nCU USES amotry,funk\n INTEGER*4 i,ihi,ilo,inhi,j,m,n\n REAL*8 rtol,sum,swap,ysave,ytry,psum(NMAX),amotry\n iter=0\n1 do 12 n=1,ndim\n sum=0.0D0\n do 11 m=1,ndim+1\n sum=sum+p(m,n)\n11 continue\n psum(n)=sum\n12 continue\n2 ilo=1\n if (y(1).gt.y(2)) then\n ihi=1\n inhi=2\n else\n ihi=2\n inhi=1\n endif\n do 13 i=1,ndim+1\n if(y(i).le.y(ilo)) ilo=i\n if(y(i).gt.y(ihi)) then\n inhi=ihi\n ihi=i\n else if(y(i).gt.y(inhi)) then\n if(i.ne.ihi) inhi=i\n endif\n13 continue\n rtol=2.0D0*abs(y(ihi)-y(ilo))/(abs(y(ihi))+abs(y(ilo)))\n if (rtol.lt.ftol) then\n swap=y(1)\n y(1)=y(ilo)\n y(ilo)=swap\n do 14 n=1,ndim\n swap=p(1,n)\n p(1,n)=p(ilo,n)\n p(ilo,n)=swap\n14 continue\n return\n endif\nC\nC Possibility to write intermediate results\nC\nC WRITE (*,'(I5,3F20.12)') iter,(p(ilo,j),j=1,2),y(ilo)\nC\n if (iter.ge.ITMAX) then\n write (*,*) 'ITMAX exceeded in amoeba'\n return\n endif\n iter=iter+2\n ytry=amotry(p,y,psum,mp,np,ndim,funk,ihi,-1.0D0)\n if (ytry.le.y(ilo)) then\n ytry=amotry(p,y,psum,mp,np,ndim,funk,ihi,2.0D0)\n else if (ytry.ge.y(inhi)) then\n ysave=y(ihi)\n ytry=amotry(p,y,psum,mp,np,ndim,funk,ihi,0.5D0)\n if (ytry.ge.ysave) then\n do 16 i=1,ndim+1\n if(i.ne.ilo)then\n do 15 j=1,ndim\n psum(j)=0.5D0*(p(i,j)+p(ilo,j))\n p(i,j)=psum(j)\n15 continue\n y(i)=funk(psum)\n endif\n16 continue\n iter=iter+ndim\n goto 1\n endif\n else\n iter=iter-1\n endif\n goto 2\n END\n\n\n REAL*8 FUNCTION amotry(p,y,psum,mp,np,ndim,funk,ihi,fac)\nC\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC\nC From Numerical Recipes. Modified to be double precision\nC\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC\n IMPLICIT REAL*8 (a-h,o-z)\n INTEGER*4 ihi,mp,ndim,np,NMAX\n REAL*8 fac,p(mp,np),psum(np),y(mp),funk\n PARAMETER (NMAX=20)\n EXTERNAL funk\nCU USES funk\n INTEGER j\n REAL*8 fac1,fac2,ytry,ptry(NMAX)\n fac1=(1.0D0-fac)/ndim\n fac2=fac1-fac\n do 11 j=1,ndim\n ptry(j)=psum(j)*fac1-p(ihi,j)*fac2\n11 continue\n ytry=funk(ptry)\n if (ytry.lt.y(ihi)) then\n y(ihi)=ytry\n do 12 j=1,ndim\n psum(j)=psum(j)-p(ihi,j)+ptry(j)\n p(ihi,j)=ptry(j)\n12 continue\n endif\n amotry=ytry\n return\n END\n\n\n FUNCTION randraw(idum)\nC\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC\nC Function to compute a sequence of pseudo-random numbers in the\nC interval (0,1). 'Minimal' random number generator of Park and Miller\nC with Bays-Durham shuffle and added safeguards. idum must be negative\nC and must not be alterated on successive calls. (See Numerical\nC Recipes for more details, 2nd. Edition, it corresponds to ran). It\nC is not useful for a number of calls > 10^8.\nC\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC\nC Declaration of local variables.\nC\n INTEGER*4 idum, ia,im,iq,ir,ntab,ndiv\n REAL*8 randraw,am,epsran,rnmx\n PARAMETER (ia=16807,im=2147483647,am=1./im,iq=127773,ir=2836,\n & ntab=32,ndiv=1+(im-1)/ntab,epsran=1.2e-7,\n & rnmx=1.0-epsran)\n INTEGER j,k,iv(ntab),iy\nC\n SAVE iv,iy\n DATA iv /ntab*0/, iy /0/\nC\n IF (idum.LE.0.or.iy.EQ.0) THEN\n idum=max(-idum, 1)\n DO j=ntab+8, 1, -1\n k=idum/iq\n idum=ia*(idum-k*iq)-ir*k\n IF (idum.LT.0) idum=idum+im\n IF (j.LE.ntab) iv(j)=idum\n END DO\n iy=iv(1)\n END IF\n k=idum/iq\n idum=ia*(idum-k*iq)-ir*k\n IF (idum.LT.0) idum=idum+im\n j=1+iy/ndiv\n iy=iv(j)\n iv(j)=idum\n randraw=MIN(am*iy,rnmx)\nC\n RETURN\n END\n", "meta": {"hexsha": "7a73bf03db5db221e8b4f10680cf489139b36a72", "size": 19886, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "legacy_fortran/sub/gausherm.f", "max_stars_repo_name": "dynamics-of-stellar-systems/dynamite_release", "max_stars_repo_head_hexsha": "a921d8a1bde98f48daeea78213fb17b3edb223bb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-10-14T12:22:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-31T15:32:59.000Z", "max_issues_repo_path": "legacy_fortran/sub/gausherm.f", "max_issues_repo_name": "dynamics-of-stellar-systems/dynamite_release", "max_issues_repo_head_hexsha": "a921d8a1bde98f48daeea78213fb17b3edb223bb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2022-02-25T16:05:40.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T15:15:16.000Z", "max_forks_repo_path": "legacy_fortran/sub/gausherm.f", "max_forks_repo_name": "dynamics-of-stellar-systems/dynamite", "max_forks_repo_head_hexsha": "5ccf936e4b1cd907db8dd7070d4ad204ed913337", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-11-04T04:36:40.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-01T01:07:38.000Z", "avg_line_length": 24.6418835192, "max_line_length": 75, "alphanum_fraction": 0.6217942271, "num_tokens": 7287, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711794579723, "lm_q2_score": 0.7718434978390746, "lm_q1q2_score": 0.6560447282152451}} {"text": "program test9\n#if (_DP==0)\n use iso_fortran_env,only:int32,int64,wp=>real32\n#else\n use iso_fortran_env,only:int32,int64,wp=>real64\n#endif\n use modsparse\n implicit none\n integer(kind=int32)::i\n integer(kind=int32)::nrow\n integer(kind=int32)::row\n integer(kind=int32)::col\n integer(kind=int32)::iunit, istat\n real(kind=wp)::val\n real(kind=wp),allocatable::x(:),y(:),y1(:)\n real(kind=wp),allocatable::xa(:,:),ya(:,:),ya1(:,:)\n logical::lup=.false.\n type(coosparse)::coo\n type(crssparse)::crs\n\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \n open(newunit=iunit,file='crsinput.ascii',status='old',action='read')\n read(iunit,*) nrow\n\n coo=coosparse(nrow)\n\n do\n read(iunit,*,iostat=istat) row,col,val\n if(istat.ne.0)exit\n call coo%add(row,col,val)\n end do\n close(iunit)\n\n\n allocate(x(coo%getdim(2)),y(coo%getdim(1)),y1(coo%getdim(1)))\n allocate(xa(coo%getdim(2),3),ya(coo%getdim(1),3),ya1(coo%getdim(1),3))\n\n x(:) = [(i,i=1,size(x,1))]\n xa = 3\n xa(:,1) = [(i,i=1,size(x,1))]\n\n call coo%printstats()\n call coo%print()\n call coo%printsquare()\n !call coo%print(lint=.false.)\n\n crs=coo\n call crs%printstats()\n call crs%print()\n call crs%printsquare()\n\n call coo%mult(1._wp,'n',x,2.5_wp,y)\n call crs%mult(1._wp,'n',x,2.5_wp,y1)\n print*,'sum ',sum(abs(y-y1))\n\n call coo%mult(1._wp,'n',xa,2.5_wp,ya)\n call crs%mult(1._wp,'n',xa,2.5_wp,ya1)\n print*,'sum ',sum(abs(ya-ya1))\n\n deallocate(x,xa,y,ya,y1,ya1)\n \n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \n open(newunit=iunit,file='crsinput.ascii',status='old',action='read')\n read(iunit,*) nrow\n\n coo=coosparse(nrow,lupper=.true.)\n\n do\n read(iunit,*,iostat=istat) row,col,val\n if(istat.ne.0)exit\n call coo%add(row,col,val)\n end do\n close(iunit)\n\n\n allocate(x(coo%getdim(2)),y(coo%getdim(1)))\n allocate(xa(coo%getdim(2),3),ya(coo%getdim(1),3))\n\n x(:) = [(i,i=1,size(x,1))]\n xa = 3\n xa(:,1) = [(i,i=1,size(x,1))]\n\n call coo%printstats()\n call coo%print()\n call coo%printsquare()\n !call coo%print(lint=.false.)\n\n crs=coo\n call crs%sort()\n call crs%printstats()\n call crs%print()\n call crs%printsquare()\n\n y=1.7\n y1=y\n call coo%mult(1._wp,'n',x,2.5_wp,y)\n call crs%mult(1._wp,'n',x,2.5_wp,y1)\n print*,'sum ',sum(abs(y-y1))\n\n ya=1.7\n ya1=ya\n call coo%mult(1._wp,'n',xa,2.5_wp,ya)\n call crs%mult(1._wp,'n',xa,2.5_wp,ya1)\n print*,'sum ',sum(abs(ya-ya1))\n\n\n deallocate(x,xa,y,ya,y1,ya1)\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \n open(newunit=iunit,file='crsinput.ascii',status='old',action='read')\n read(iunit,*) nrow\n\n coo=coosparse(nrow,lupper=.true.)\n\n call coo%setsymmetric()\n\n do\n read(iunit,*,iostat=istat) row,col,val\n if(istat.ne.0)exit\n call coo%add(row,col,val)\n end do\n close(iunit)\n\n\n allocate(x(coo%getdim(2)),y(coo%getdim(1)))\n allocate(xa(coo%getdim(2),3),ya(coo%getdim(1),3))\n\n x(:) = [(i,i=1,size(x,1))]\n xa = 3\n xa(:,1) = [(i,i=1,size(x,1))]\n\n call coo%printstats()\n call coo%print()\n call coo%printsquare()\n !call coo%print(lint=.false.)\n\n crs=coo\n call crs%sort()\n call crs%printstats()\n call crs%print()\n call crs%printsquare()\n\n y=1.7\n y1=y\n call coo%mult(1._wp,'n',x,2.5_wp,y)\n call crs%mult(1._wp,'n',x,2.5_wp,y1)\n print*,'sum ',sum(abs(y-y1))\n\n ya=1.7\n ya1=ya\n call coo%mult(1._wp,'n',xa,2.5_wp,ya)\n call crs%mult(1._wp,'n',xa,2.5_wp,ya1)\n print*,'sum ',sum(abs(ya-ya1))\n\nend program\n", "meta": {"hexsha": "a3db82bee3e31a67fa15dd0fa17a12cee8c28b42", "size": 3339, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/test9.f90", "max_stars_repo_name": "jvdp1/libsparse", "max_stars_repo_head_hexsha": "eaf5ec8e45bce873154aff24c2143b8f00df63a8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2019-08-03T14:17:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-14T04:31:16.000Z", "max_issues_repo_path": "examples/test9.f90", "max_issues_repo_name": "jvdp1/libsparse", "max_issues_repo_head_hexsha": "eaf5ec8e45bce873154aff24c2143b8f00df63a8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-09-06T21:38:44.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-08T16:02:40.000Z", "max_forks_repo_path": "examples/test9.f90", "max_forks_repo_name": "jvdp1/libsparse", "max_forks_repo_head_hexsha": "eaf5ec8e45bce873154aff24c2143b8f00df63a8", "max_forks_repo_licenses": ["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.5419354839, "max_line_length": 76, "alphanum_fraction": 0.6067684936, "num_tokens": 1304, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84997116805678, "lm_q2_score": 0.7718434978390746, "lm_q1q2_score": 0.656044719415309}} {"text": " SUBROUTINE TB01TY( MODE, IOFF, JOFF, NROW, NCOL, SIZE, X, LDX,\n $ BVECT )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC Balances the rows (MODE .EQ. 0) or columns (MODE .NE. 0) of the\nC (NROW x NCOL) block of the matrix X with offset (IOFF,JOFF), i.e.\nC with first (top left) element (IOFF + 1,JOFF + 1). Each non-\nC zero row (column) is balanced in the sense that it is multiplied\nC by that integer power of the base of the machine floating-point\nC representation for which the sum of the absolute values of its\nC entries (i.e. its 1-norm) satisfies\nC\nC (SIZE / BASE) .LT. ABSSUM .LE. SIZE\nC\nC for SIZE as input. (Note that this form of scaling does not\nC introduce any rounding errors.) The vector BVECT then contains\nC the appropriate scale factors in rows (IOFF + 1)...(IOFF + NROW)\nC (columns (JOFF + 1)...(JOFF + NCOL) ). In particular, if the\nC I-th row (J-th column) of the block is 'numerically' non-zero\nC with 1-norm given by BASE**(-EXPT) for some real EXPT, then the\nC desired scale factor (returned as element IOFF + I (JOFF + J) of\nC BVECT) is BASE**IEXPT, where IEXPT is the largest integer .LE.\nC EXPT: this integer is precisely the truncation INT(EXPT) except\nC for negative non-integer EXPT, in which case this value is too\nC high by 1 and so must be adjusted accordingly. Finally, note\nC that the element of BVECT corresponding to a 'numerically' zero\nC row (column) is simply set equal to 1.0.\nC\nC For efficiency, no tests of the input scalar parameters are\nC performed.\nC\nC REVISIONS\nC\nC -\nC\nC ******************************************************************\nC\n DOUBLE PRECISION ONE\n PARAMETER ( ONE = 1.0D0 )\nC .. Scalar Arguments ..\n INTEGER IOFF, JOFF, LDX, MODE, NCOL, NROW\n DOUBLE PRECISION SIZE\nC .. Array Arguments ..\n DOUBLE PRECISION BVECT(*), X(LDX,*)\nC .. Local Scalars ..\n DOUBLE PRECISION ABSSUM, DIV, EPS, EXPT, SCALE, TEST\n INTEGER BASE, I, IEXPT, J\nC .. External Functions ..\n DOUBLE PRECISION DASUM, DLAMCH\n EXTERNAL DASUM, DLAMCH\nC .. External Subroutines ..\n EXTERNAL DSCAL\nC .. Intrinsic Functions ..\n INTRINSIC ABS, DBLE, INT, LOG\nC .. Executable Statements ..\nC\n BASE = DLAMCH( 'Base' )\n EPS = DLAMCH( 'Epsilon' )\nC\n DIV = ONE/LOG( DBLE( BASE ) )\n IF ( MODE.NE.0 ) THEN\nC\nC Balance one column at a time using its column-sum norm.\nC\n DO 10 J = JOFF + 1, JOFF + NCOL\n ABSSUM = DASUM( NROW, X(IOFF+1,J), 1 )/ABS( SIZE )\n TEST = ABSSUM/DBLE( NROW )\n IF ( TEST.GT.EPS ) THEN\nC\nC Non-zero column: calculate (and apply) correct scale\nC factor.\nC\n EXPT = -DIV*LOG( ABSSUM )\n IEXPT = INT( EXPT )\n IF ( ( IEXPT.LT.0 ) .AND. ( DBLE( IEXPT ).NE.EXPT ) )\n $ IEXPT = IEXPT - 1\n SCALE = DBLE( BASE )**IEXPT\n BVECT(J) = SCALE\n CALL DSCAL( NROW, SCALE, X(IOFF+1,J), 1 )\n ELSE\nC\nC 'Numerically' zero column: do not rescale.\nC\n BVECT(J) = ONE\n END IF\n 10 CONTINUE\nC\n ELSE\nC\nC Balance one row at a time using its row-sum norm.\nC\n DO 20 I = IOFF + 1, IOFF + NROW\n ABSSUM = DASUM( NCOL, X(I,JOFF+1), LDX )/ABS( SIZE )\n TEST = ABSSUM/DBLE( NCOL )\n IF ( TEST.GT.EPS ) THEN\nC\nC Non-zero row: calculate (and apply) correct scale factor.\nC\n EXPT = -DIV*LOG( ABSSUM )\n IEXPT = INT( EXPT )\n IF ( ( IEXPT.LT.0 ) .AND. ( DBLE( IEXPT ).NE.EXPT ) )\n $ IEXPT = IEXPT - 1\nC\n SCALE = DBLE( BASE )**IEXPT\n BVECT(I) = SCALE\n CALL DSCAL( NCOL, SCALE, X(I,JOFF+1), LDX )\n ELSE\nC\nC 'Numerically' zero row: do not rescale.\nC\n BVECT(I) = ONE\n END IF\n 20 CONTINUE\nC\n END IF\nC\n RETURN\nC *** Last line of TB01TY ***\n END\n", "meta": {"hexsha": "0ae8f4af7353377b94b183319cd902f3702bce51", "size": 4234, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/TB01TY.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/TB01TY.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/TB01TY.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 33.872, "max_line_length": 72, "alphanum_fraction": 0.5488899386, "num_tokens": 1327, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8757869948899665, "lm_q2_score": 0.7490872075132153, "lm_q1q2_score": 0.6560408343785156}} {"text": "\nprogram main \n \n implicit none \n \n complex(kind(1d0)), allocatable :: poly(:),roots(:),coeffs(:,:),allroots(:,:)\n integer, allocatable :: iterations(:) \n double precision, allocatable :: res(:,:)\n double precision :: time\n \n integer :: ii,jj,kk,ll,mm,N,zero,flag\n integer :: clock_start,clock_end,clock_rate \n \n open (unit=8, file='poly.txt', status='unknown')\n open (unit=9, file='roots.txt', status='unknown')\n open (unit=10, file='errors.txt', status='unknown')\n\n\n \tN = 10\n\n\tallocate(poly(N+1),roots(N),coeffs(N,3),allroots(N,2),iterations(N),res(N,6))\n\n\tcall cnormalpoly(N,poly(2:N+1))\n\tpoly(1) = complex(1d0,0d0)\n\n\tdo kk=1,N+1\n\t\twrite(8,*) dble(poly(kk)),dimag(poly(kk))\n\tend do\n\n\tCALL SYSTEM_CLOCK(COUNT_RATE=clock_rate) \n\tCALL SYSTEM_CLOCK(COUNT=clock_start)\n\n\tcall ZAVW2(0,N,1,POLY,COEFFS,ROOTS,ITERATIONS,FLAG)\n\tcall RESCHECK(0,N,1,1,POLY(2:N+1)/poly(1),COEFFS,ROOTS,ALLROOTS,RES)\t\n\n\tCALL SYSTEM_CLOCK(COUNT=clock_end) \n\ttime = dble(clock_end - clock_start)/dble(clock_rate) \n\twrite (*,*) \"Run time =\", time\n\n\tdo kk=1,N\n\t\twrite(10,*) res(kk,:)\n\t\twrite(9,*) dble(allroots(kk,2)),dimag(allroots(kk,2))\n\tend do\n\n \tdeallocate(poly,roots,coeffs,allroots,iterations,res)\n\n close(8)\n close(9)\n close(10)\n\n\nend program main\n", "meta": {"hexsha": "862baaac80eb02f2610863663f879835197868f1", "size": 1252, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "avw2/complex_companion.f90", "max_stars_repo_name": "jaurentz/amvw", "max_stars_repo_head_hexsha": "3b155bd2c0372d21564bdbe2bbd6106298c7cacf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-01-08T05:47:42.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-15T18:30:11.000Z", "max_issues_repo_path": "avw2/complex_companion.f90", "max_issues_repo_name": "jaurentz/amvw", "max_issues_repo_head_hexsha": "3b155bd2c0372d21564bdbe2bbd6106298c7cacf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2016-02-25T13:45:53.000Z", "max_issues_repo_issues_event_max_datetime": "2016-02-25T13:45:53.000Z", "max_forks_repo_path": "avw2/complex_companion.f90", "max_forks_repo_name": "jaurentz/avw", "max_forks_repo_head_hexsha": "3b155bd2c0372d21564bdbe2bbd6106298c7cacf", "max_forks_repo_licenses": ["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.6226415094, "max_line_length": 79, "alphanum_fraction": 0.6677316294, "num_tokens": 435, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319862, "lm_q2_score": 0.749087201911703, "lm_q1q2_score": 0.6560408319013394}} {"text": "cc Copyright (C) 2009: Zydrunas Gimbutas and Hong Xiao\ncc Contact: Zydrunas Gimbutas \ncc Hong Xiao \ncc \ncc This software is being released under a modified FreeBSD license\ncc (see COPYING in home directory). \nccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\nc\nc \nc Interpolation and quadratures for smooth functions on a tetrahedron\nc\nc All quadratures are accurate to quad precision\nc All weights are positive and inside the standard tetrahedron\nc\nc (-1,-1/Sqrt[3],-1/Sqrt[6]), (0,2/Sqrt[3],-1/Sqrt[6]), \nc (1,-1/Sqrt[3],-1/Sqrt[6]), and (0,0,3/Sqrt[6])\nc\nc Input:\nc\nc n - the interpoation order (must not exceed 10)\nc\nc Output:\nc\nc fort.11 - quadrature nodes and weights\nc fort.12 - quadrature nodes in gnuplot compatible format\nc fort.14 - standard tetrahedron as constructed \nc in gnuplot compatible format\nc \nc in gnuplot:\nc\nc splot 'fort.14' w l, 'fort.12'\nc\nc\nc\n implicit real *8 (a-h,o-z)\n dimension rnodes(3,1000),weights(1000)\n dimension rints(1000),z(3),pols(1000)\n dimension work(100000),vert(3,4)\nc\nc\n call prini(6,13)\nc\nc SET ALL PARAMETERS\nc\n PRINT *, 'ENTER mmax (1..10)'\n READ *, mmax\nc\n call prinf('mmax=*',mmax,1)\nc\nc\n\nc\nc ... retrieve the quadrature rule \nc\n call tetraintq(mmax,rnodes,weights,numnodes)\nc\n call prinf('nummodes=*',numnodes,1)\n call prin2('rnodes=*',rnodes,3*numnodes) \n call prin2('weights=*',weights,numnodes) \nc\n d=0\n do i=1,numnodes\n d=d+weights(i)\n enddo\nc\n call prin2('sum of weights=*',d,1)\nc \nc ... plot the standard tetrahedron\nc\n\n vert(1,1)=-1\n vert(2,1)=-1/sqrt(3.0d0)\n vert(3,1)=-1/sqrt(6.0d0)\nc\n vert(1,2)=0\n vert(2,2)=2/sqrt(3.0d0)\n vert(3,2)=-1/sqrt(6.0d0)\nc \n vert(1,3)=1\n vert(2,3)=-1/sqrt(3.0d0)\n vert(3,3)=-1/sqrt(6.0d0)\nc\n vert(1,4)=0\n vert(2,4)=0\n vert(3,4)=3/sqrt(6.0d0)\nc\n\nc\n write(14,*) vert(1,1),vert(2,1),vert(3,1)\n write(14,*) vert(1,2),vert(2,2),vert(3,2)\n write(14,*) vert(1,3),vert(2,3),vert(3,3)\n write(14,*) vert(1,1),vert(2,1),vert(3,1)\n write(14,*)\nc\n write(14,*) vert(1,1),vert(2,1),vert(3,1)\n write(14,*) vert(1,4),vert(2,4),vert(3,4)\n write(14,*)\n write(14,*) vert(1,2),vert(2,2),vert(3,2)\n write(14,*) vert(1,4),vert(2,4),vert(3,4)\n write(14,*)\n write(14,*) vert(1,3),vert(2,3),vert(3,3)\n write(14,*) vert(1,4),vert(2,4),vert(3,4)\n write(14,*)\nc\nc\nc ... dump the nodes into a file\nc \n write(11,*) numnodes\n do i=1,numnodes\n write(11,1020) rnodes(1,i),rnodes(2,i),rnodes(3,i),weights(i)\n write(12,*) rnodes(1,i),rnodes(2,i),rnodes(3,i)\n enddo\n 1010 format(i2)\n 1020 format(4(e21.15,2x))\nc\n\nc\nc construct the matrix of values of the orthogonal polynomials\nc at the user-provided nodes \nc\n npols=(mmax+1)*(mmax+2)*(mmax+3)/6\nc\nc adjust to somewhat arbitrary scaling in ortho3eva.f\nc \n scale = 2.0d0 * sqrt(2.0d0) / 3.0d0\nc\n d=0\n do i=1,numnodes\n d=d+weights(i)\n enddo\n\n do i=1,numnodes\n weights(i)=weights(i)/d * scale\n enddo\n\nc\n do 1200 j=1,npols\n rints(j)=0\n 1200 continue\nc\nc\n do 2400 i=1,numnodes\nc\n z(1)=rnodes(1,i)\n z(2)=rnodes(2,i)\n z(3)=rnodes(3,i)\nc \n call symeval(itype,mmax,z(1),z(2),z(3),pols,dersx,dersy,dersz)\nc\n do 2200 j=1,npols\nc\n rints(j)=rints(j)+weights(i)*pols(j)\n\n 2200 continue\n\n 2400 continue\nc\nc\n call prin2('rints=*',rints,npols)\nc\n vol = 2.0d0 * sqrt(2.0d0) / 3.0d0\nc\n d=0\n d=(rints(1)-sqrt(vol))**2\n do i=2,npols\n d=d+rints(i)**2\n enddo\nc\n d=sqrt(d)/npols\nc\n call prin2('error=*',d,1)\nc\n stop\n end\nc\nc\nc\nc\nc\n subroutine symeval(itype,mmax,x,y,z,polsout,dersx,dersy,dersz)\n implicit real *8 (a-h,o-z)\n dimension z1(3),polsout(1),dersx(1),dersy(1),dersz(1)\nc\n dimension polsout1(10 000),\n $ dersx1(10 000),dersy1(10 000),dersz1(10 000)\n dimension work(100 000)\nc\n dimension v(4 000 000), v0(4 000 000), rnorms(10000)\n data ifinit/0/\nc\n save\nc\nc evaluate all polynomials \nc\n z1(1)=x\n z1(2)=y\n z1(3)=z\nc\n npols7=(mmax+1)*(mmax+2)*(mmax+3)/6\nc\n scale=1\nc\n if(itype .eq. 1)\n 1 call ortho3eva4\n 2 (mmax,z1,polsout1,dersx1,dersy1,dersz1,work)\nc\n if(itype .eq. 0)\n 1 call ortho3eva(mmax,z1,polsout1,work)\nc \n if(itype .eq. 0) goto 4400\nc \n do 4200 i=1,npols7\nc\n polsout(i)=polsout1(i) *scale\n dersx(i)=dersx1(i) *scale\n dersy(i)=dersy1(i) *scale\n dersz(i)=dersz1(i) *scale\nc\n 4200 continue\n return\nc\n return\nc\n 4400 continue\nc\n do 4600 i=1,npols7\nc\n polsout(i)=polsout1(i) *scale\nc\n 4600 continue\n return\nc\n return\nc\nc\nc\n entry symevalget(mmax,ncolsout)\nc\n npolsout=(mmax+1)*(mmax+2)*(mmax+3)/6\n npols7=npolsout\nc\n return\n end \nc\nc\nc\nc\nc\n", "meta": {"hexsha": "6fcd27c79a5da9d6cbbd054ec879408f400bb993", "size": 5413, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tetraintq_dr.f", "max_stars_repo_name": "zgimbutas/triasymq", "max_stars_repo_head_hexsha": "940a83c2f3cbbc0295fb87f0a4d411b9435c6678", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-12-16T15:55:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T00:06:27.000Z", "max_issues_repo_path": "tetraintq_dr.f", "max_issues_repo_name": "zgimbutas/triasymq", "max_issues_repo_head_hexsha": "940a83c2f3cbbc0295fb87f0a4d411b9435c6678", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tetraintq_dr.f", "max_forks_repo_name": "zgimbutas/triasymq", "max_forks_repo_head_hexsha": "940a83c2f3cbbc0295fb87f0a4d411b9435c6678", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.7389558233, "max_line_length": 75, "alphanum_fraction": 0.5507112507, "num_tokens": 2093, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869786798663, "lm_q2_score": 0.7490872131147276, "lm_q1q2_score": 0.6560408271414684}} {"text": "! { dg-do run }\n! Check the fix for PR28947, in which the mechanism for dealing\n! with matmul (a, transpose (b)) would cause wrong results for\n! a having a rank == 1.\n!\n! Contributed by Harald Anlauf \n! \nprogram gfcbug40\n implicit none\n\n real :: h(3,3), mat(2,3)\n\n h(:,:) = - HUGE (1.0)/4 ! Preset unused elements suitably...\n\n h(3,:) = 0\n h(3,3) = 1\n mat(:,:) = 1\n h(3,:) = h(3,:) + matmul (matmul (h(3,:), transpose (mat)), mat)\n\n if (any (h(3,:) .ne. (/2.0, 2.0, 3.0/))) STOP 1\n\nend program gfcbug40\n", "meta": {"hexsha": "164099d9fbe50147e1c2ceab321d83a3f89b07ca", "size": 535, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/matmul_4.f90", "max_stars_repo_name": "brugger1/testsuite", "max_stars_repo_head_hexsha": "9b504db668cdeaf7c561f15b76c95d05bfdd1517", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2019-02-12T18:20:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-09T19:46:19.000Z", "max_issues_repo_path": "validation_tests/llvm/f18/gfortran.dg/matmul_4.f90", "max_issues_repo_name": "brugger1/testsuite", "max_issues_repo_head_hexsha": "9b504db668cdeaf7c561f15b76c95d05bfdd1517", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 24, "max_issues_repo_issues_event_min_datetime": "2020-08-31T22:05:07.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T18:30:03.000Z", "max_forks_repo_path": "validation_tests/llvm/f18/gfortran.dg/matmul_4.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": 23.2608695652, "max_line_length": 68, "alphanum_fraction": 0.5775700935, "num_tokens": 208, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869851639066, "lm_q2_score": 0.749087201911703, "lm_q1q2_score": 0.6560408221871169}} {"text": "! calculate bulk's energy band using wannier TB method\n subroutine ek_bulk_polar\n\n use mpi\n use para\n\n implicit none\n\n integer :: ik, i, j\n integer :: nkx, nky\n\t integer :: knv3\n integer :: ierr\n integer :: nktheta\n integer :: nkr\n real(Dp) :: k(3)\n real(dp) :: kx\n real(dp) :: ky\n real(dp) :: kz\n real(dp) :: ktheta\n real(dp) :: kr\n real(Dp) :: W(Num_wann)\n real(dp) :: krmax\n real(dp), allocatable :: kxy(:,:)\n real(dp), allocatable :: krtheta(:,:)\n \n ! Hamiltonian of bulk system\n complex(Dp) :: Hamk_bulk(Num_wann,Num_wann) \n\n ! eigen value of H\n\t real(dp), allocatable :: eigv(:,:)\n\t real(dp), allocatable :: eigv_mpi(:,:)\n\n nktheta= 50\n nkr= Nk\n knv3= nktheta*nkr\n allocate( kxy(2, knv3))\n allocate( krtheta(2, knv3))\n allocate( eigv (4, knv3))\n allocate( eigv_mpi(4, knv3))\n kxy = 0d0\n krtheta = 0d0\n\t eigv = 0d0\n\t eigv_mpi= 0d0\n\n krmax= 0.2d0\n kz= 0d0\n ik =0\n\n do i= 1, nktheta\n ktheta= 2d0*pi*(i-1)/nktheta\n do j= 1, nkr\n kr= krmax*(j-1)/nkr\n ik =ik +1\n kxy(1, ik)= kr*cos(ktheta)\n kxy(2, ik)= kr*sin(ktheta)\n krtheta(1, ik)= ktheta\n krtheta(2, ik)= kr\n enddo\n enddo\n\n do ik= 1+cpuid, knv3, num_cpu\n\t if (cpuid==0) print * , ik\n\n k(1:2) = kxy(:, ik)\n k(3)= kz\n\n ! calculation bulk hamiltonian\n Hamk_bulk= 0d0\n call ham_bulk(k, Hamk_bulk)\n\n !> diagonalization by call zheev in lapack\n W= 0d0\n call eigensystem_c( 'N', 'U', Num_wann ,Hamk_bulk, W)\n\n eigv(:, ik)= W(55:58)\n\n enddo\n\n call mpi_allreduce(eigv,eigv_mpi,size(eigv),&\n mpi_dp,mpi_sum,mpi_cmw,ierr)\n\n if (cpuid==0)then\n open(unit=14, file='bulkek_polar.dat')\n do ik=1, knv3\n write(14, '(1000f19.9)')krtheta(:, ik), eigv_mpi(:, ik)\n enddo\n close(14)\n endif\n\n return\n end subroutine ek_bulk_polar\n", "meta": {"hexsha": "ef497d8e00fa875d0ec6cef4c704e0d28cc372e0", "size": 2049, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "soc_sym/ek_bulk_polar.f90", "max_stars_repo_name": "dlnguyen/wannier_tools", "max_stars_repo_head_hexsha": "cc6748e3718ee2a89934a187490c37f9f520aeff", "max_stars_repo_licenses": ["OLDAP-2.3"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-14T12:07:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-14T12:07:24.000Z", "max_issues_repo_path": "soc_sym/ek_bulk_polar.f90", "max_issues_repo_name": "jtsun/wannier_tools", "max_issues_repo_head_hexsha": "f3512e986c6546af6b823ee6b8a4b9118c53a9fa", "max_issues_repo_licenses": ["OLDAP-2.3"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "soc_sym/ek_bulk_polar.f90", "max_forks_repo_name": "jtsun/wannier_tools", "max_forks_repo_head_hexsha": "f3512e986c6546af6b823ee6b8a4b9118c53a9fa", "max_forks_repo_licenses": ["OLDAP-2.3"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.2717391304, "max_line_length": 66, "alphanum_fraction": 0.523670083, "num_tokens": 724, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473813156294, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6560161994357857}} {"text": " SUBROUTINE DCHKBD( NSIZES, MVAL, NVAL, NTYPES, DOTYPE, NRHS,\n $ ISEED, THRESH, A, LDA, BD, BE, S1, S2, X, LDX,\n $ Y, Z, Q, LDQ, PT, LDPT, U, VT, WORK, LWORK,\n $ IWORK, NOUT, INFO )\n*\n* -- LAPACK test routine (version 3.1) --\n* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..\n* November 2006\n*\n* .. Scalar Arguments ..\n INTEGER INFO, LDA, LDPT, LDQ, LDX, LWORK, NOUT, NRHS,\n $ NSIZES, NTYPES\n DOUBLE PRECISION THRESH\n* ..\n* .. Array Arguments ..\n LOGICAL DOTYPE( * )\n INTEGER ISEED( 4 ), IWORK( * ), MVAL( * ), NVAL( * )\n DOUBLE PRECISION A( LDA, * ), BD( * ), BE( * ), PT( LDPT, * ),\n $ Q( LDQ, * ), S1( * ), S2( * ), U( LDPT, * ),\n $ VT( LDPT, * ), WORK( * ), X( LDX, * ),\n $ Y( LDX, * ), Z( LDX, * )\n* ..\n*\n* Purpose\n* =======\n*\n* DCHKBD checks the singular value decomposition (SVD) routines.\n*\n* DGEBRD reduces a real general m by n matrix A to upper or lower\n* bidiagonal form B by an orthogonal transformation: Q' * A * P = B\n* (or A = Q * B * P'). The matrix B is upper bidiagonal if m >= n\n* and lower bidiagonal if m < n.\n*\n* DORGBR generates the orthogonal matrices Q and P' from DGEBRD.\n* Note that Q and P are not necessarily square.\n*\n* DBDSQR computes the singular value decomposition of the bidiagonal\n* matrix B as B = U S V'. It is called three times to compute\n* 1) B = U S1 V', where S1 is the diagonal matrix of singular\n* values and the columns of the matrices U and V are the left\n* and right singular vectors, respectively, of B.\n* 2) Same as 1), but the singular values are stored in S2 and the\n* singular vectors are not computed.\n* 3) A = (UQ) S (P'V'), the SVD of the original matrix A.\n* In addition, DBDSQR has an option to apply the left orthogonal matrix\n* U to a matrix X, useful in least squares applications.\n*\n* DBDSDC computes the singular value decomposition of the bidiagonal\n* matrix B as B = U S V' using divide-and-conquer. It is called twice\n* to compute\n* 1) B = U S1 V', where S1 is the diagonal matrix of singular\n* values and the columns of the matrices U and V are the left\n* and right singular vectors, respectively, of B.\n* 2) Same as 1), but the singular values are stored in S2 and the\n* singular vectors are not computed.\n*\n* For each pair of matrix dimensions (M,N) and each selected matrix\n* type, an M by N matrix A and an M by NRHS matrix X are generated.\n* The problem dimensions are as follows\n* A: M x N\n* Q: M x min(M,N) (but M x M if NRHS > 0)\n* P: min(M,N) x N\n* B: min(M,N) x min(M,N)\n* U, V: min(M,N) x min(M,N)\n* S1, S2 diagonal, order min(M,N)\n* X: M x NRHS\n*\n* For each generated matrix, 14 tests are performed:\n*\n* Test DGEBRD and DORGBR\n*\n* (1) | A - Q B PT | / ( |A| max(M,N) ulp ), PT = P'\n*\n* (2) | I - Q' Q | / ( M ulp )\n*\n* (3) | I - PT PT' | / ( N ulp )\n*\n* Test DBDSQR on bidiagonal matrix B\n*\n* (4) | B - U S1 VT | / ( |B| min(M,N) ulp ), VT = V'\n*\n* (5) | Y - U Z | / ( |Y| max(min(M,N),k) ulp ), where Y = Q' X\n* and Z = U' Y.\n* (6) | I - U' U | / ( min(M,N) ulp )\n*\n* (7) | I - VT VT' | / ( min(M,N) ulp )\n*\n* (8) S1 contains min(M,N) nonnegative values in decreasing order.\n* (Return 0 if true, 1/ULP if false.)\n*\n* (9) | S1 - S2 | / ( |S1| ulp ), where S2 is computed without\n* computing U and V.\n*\n* (10) 0 if the true singular values of B are within THRESH of\n* those in S1. 2*THRESH if they are not. (Tested using\n* DSVDCH)\n*\n* Test DBDSQR on matrix A\n*\n* (11) | A - (QU) S (VT PT) | / ( |A| max(M,N) ulp )\n*\n* (12) | X - (QU) Z | / ( |X| max(M,k) ulp )\n*\n* (13) | I - (QU)'(QU) | / ( M ulp )\n*\n* (14) | I - (VT PT) (PT'VT') | / ( N ulp )\n*\n* Test DBDSDC on bidiagonal matrix B\n*\n* (15) | B - U S1 VT | / ( |B| min(M,N) ulp ), VT = V'\n*\n* (16) | I - U' U | / ( min(M,N) ulp )\n*\n* (17) | I - VT VT' | / ( min(M,N) ulp )\n*\n* (18) S1 contains min(M,N) nonnegative values in decreasing order.\n* (Return 0 if true, 1/ULP if false.)\n*\n* (19) | S1 - S2 | / ( |S1| ulp ), where S2 is computed without\n* computing U and V.\n* The possible matrix types are\n*\n* (1) The zero matrix.\n* (2) The identity matrix.\n*\n* (3) A diagonal matrix with evenly spaced entries\n* 1, ..., ULP and random signs.\n* (ULP = (first number larger than 1) - 1 )\n* (4) A diagonal matrix with geometrically spaced entries\n* 1, ..., ULP and random signs.\n* (5) A diagonal matrix with \"clustered\" entries 1, ULP, ..., ULP\n* and random signs.\n*\n* (6) Same as (3), but multiplied by SQRT( overflow threshold )\n* (7) Same as (3), but multiplied by SQRT( underflow threshold )\n*\n* (8) A matrix of the form U D V, where U and V are orthogonal and\n* D has evenly spaced entries 1, ..., ULP with random signs\n* on the diagonal.\n*\n* (9) A matrix of the form U D V, where U and V are orthogonal and\n* D has geometrically spaced entries 1, ..., ULP with random\n* signs on the diagonal.\n*\n* (10) A matrix of the form U D V, where U and V are orthogonal and\n* D has \"clustered\" entries 1, ULP,..., ULP with random\n* signs on the diagonal.\n*\n* (11) Same as (8), but multiplied by SQRT( overflow threshold )\n* (12) Same as (8), but multiplied by SQRT( underflow threshold )\n*\n* (13) Rectangular matrix with random entries chosen from (-1,1).\n* (14) Same as (13), but multiplied by SQRT( overflow threshold )\n* (15) Same as (13), but multiplied by SQRT( underflow threshold )\n*\n* Special case:\n* (16) A bidiagonal matrix with random entries chosen from a\n* logarithmic distribution on [ulp^2,ulp^(-2)] (I.e., each\n* entry is e^x, where x is chosen uniformly on\n* [ 2 log(ulp), -2 log(ulp) ] .) For *this* type:\n* (a) DGEBRD is not called to reduce it to bidiagonal form.\n* (b) the bidiagonal is min(M,N) x min(M,N); if M= THRESH. To have\n* every test ratio printed, use THRESH = 0. Note that the\n* expected value of the test ratios is O(1), so THRESH should\n* be a reasonably small multiple of 1, e.g., 10 or 100.\n*\n* A (workspace) DOUBLE PRECISION array, dimension (LDA,NMAX)\n* where NMAX is the maximum value of N in NVAL.\n*\n* LDA (input) INTEGER\n* The leading dimension of the array A. LDA >= max(1,MMAX),\n* where MMAX is the maximum value of M in MVAL.\n*\n* BD (workspace) DOUBLE PRECISION array, dimension\n* (max(min(MVAL(j),NVAL(j))))\n*\n* BE (workspace) DOUBLE PRECISION array, dimension\n* (max(min(MVAL(j),NVAL(j))))\n*\n* S1 (workspace) DOUBLE PRECISION array, dimension\n* (max(min(MVAL(j),NVAL(j))))\n*\n* S2 (workspace) DOUBLE PRECISION array, dimension\n* (max(min(MVAL(j),NVAL(j))))\n*\n* X (workspace) DOUBLE PRECISION array, dimension (LDX,NRHS)\n*\n* LDX (input) INTEGER\n* The leading dimension of the arrays X, Y, and Z.\n* LDX >= max(1,MMAX)\n*\n* Y (workspace) DOUBLE PRECISION array, dimension (LDX,NRHS)\n*\n* Z (workspace) DOUBLE PRECISION array, dimension (LDX,NRHS)\n*\n* Q (workspace) DOUBLE PRECISION array, dimension (LDQ,MMAX)\n*\n* LDQ (input) INTEGER\n* The leading dimension of the array Q. LDQ >= max(1,MMAX).\n*\n* PT (workspace) DOUBLE PRECISION array, dimension (LDPT,NMAX)\n*\n* LDPT (input) INTEGER\n* The leading dimension of the arrays PT, U, and V.\n* LDPT >= max(1, max(min(MVAL(j),NVAL(j)))).\n*\n* U (workspace) DOUBLE PRECISION array, dimension\n* (LDPT,max(min(MVAL(j),NVAL(j))))\n*\n* V (workspace) DOUBLE PRECISION array, dimension\n* (LDPT,max(min(MVAL(j),NVAL(j))))\n*\n* WORK (workspace) DOUBLE PRECISION array, dimension (LWORK)\n*\n* LWORK (input) INTEGER\n* The number of entries in WORK. This must be at least\n* 3(M+N) and M(M + max(M,N,k) + 1) + N*min(M,N) for all\n* pairs (M,N)=(MM(j),NN(j))\n*\n* IWORK (workspace) INTEGER array, dimension at least 8*min(M,N)\n*\n* NOUT (input) INTEGER\n* The FORTRAN unit number for printing out error messages\n* (e.g., if a routine returns IINFO not equal to 0.)\n*\n* INFO (output) INTEGER\n* If 0, then everything ran OK.\n* -1: NSIZES < 0\n* -2: Some MM(j) < 0\n* -3: Some NN(j) < 0\n* -4: NTYPES < 0\n* -6: NRHS < 0\n* -8: THRESH < 0\n* -11: LDA < 1 or LDA < MMAX, where MMAX is max( MM(j) ).\n* -17: LDB < 1 or LDB < MMAX.\n* -21: LDQ < 1 or LDQ < MMAX.\n* -23: LDPT< 1 or LDPT< MNMAX.\n* -27: LWORK too small.\n* If DLATMR, SLATMS, DGEBRD, DORGBR, or DBDSQR,\n* returns an error code, the\n* absolute value of it is returned.\n*\n*-----------------------------------------------------------------------\n*\n* Some Local Variables and Parameters:\n* ---- ----- --------- --- ----------\n*\n* ZERO, ONE Real 0 and 1.\n* MAXTYP The number of types defined.\n* NTEST The number of tests performed, or which can\n* be performed so far, for the current matrix.\n* MMAX Largest value in NN.\n* NMAX Largest value in NN.\n* MNMIN min(MM(j), NN(j)) (the dimension of the bidiagonal\n* matrix.)\n* MNMAX The maximum value of MNMIN for j=1,...,NSIZES.\n* NFAIL The number of tests which have exceeded THRESH\n* COND, IMODE Values to be passed to the matrix generators.\n* ANORM Norm of A; passed to matrix generators.\n*\n* OVFL, UNFL Overflow and underflow thresholds.\n* RTOVFL, RTUNFL Square roots of the previous 2 values.\n* ULP, ULPINV Finest relative precision and its inverse.\n*\n* The following four arrays decode JTYPE:\n* KTYPE(j) The general type (1-10) for type \"j\".\n* KMODE(j) The MODE value to be passed to the matrix\n* generator for type \"j\".\n* KMAGN(j) The order of magnitude ( O(1),\n* O(overflow^(1/2) ), O(underflow^(1/2) )\n*\n* ======================================================================\n*\n* .. Parameters ..\n DOUBLE PRECISION ZERO, ONE, TWO, HALF\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0, TWO = 2.0D0,\n $ HALF = 0.5D0 )\n INTEGER MAXTYP\n PARAMETER ( MAXTYP = 16 )\n* ..\n* .. Local Scalars ..\n LOGICAL BADMM, BADNN, BIDIAG\n CHARACTER UPLO\n CHARACTER*3 PATH\n INTEGER I, IINFO, IMODE, ITYPE, J, JCOL, JSIZE, JTYPE,\n $ LOG2UI, M, MINWRK, MMAX, MNMAX, MNMIN, MQ,\n $ MTYPES, N, NFAIL, NMAX, NTEST\n DOUBLE PRECISION AMNINV, ANORM, COND, OVFL, RTOVFL, RTUNFL,\n $ TEMP1, TEMP2, ULP, ULPINV, UNFL\n* ..\n* .. Local Arrays ..\n INTEGER IDUM( 1 ), IOLDSD( 4 ), KMAGN( MAXTYP ),\n $ KMODE( MAXTYP ), KTYPE( MAXTYP )\n DOUBLE PRECISION DUM( 1 ), DUMMA( 1 ), RESULT( 19 )\n* ..\n* .. External Functions ..\n DOUBLE PRECISION DLAMCH, DLARND\n EXTERNAL DLAMCH, DLARND\n* ..\n* .. External Subroutines ..\n EXTERNAL ALASUM, DBDSDC, DBDSQR, DBDT01, DBDT02, DBDT03,\n $ DCOPY, DGEBRD, DGEMM, DLABAD, DLACPY, DLAHD2,\n $ DLASET, DLATMR, DLATMS, DORGBR, DORT01, XERBLA\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC ABS, EXP, INT, LOG, MAX, MIN, SQRT\n* ..\n* .. Scalars in Common ..\n LOGICAL LERR, OK\n CHARACTER*6 SRNAMT\n INTEGER INFOT, NUNIT\n* ..\n* .. Common blocks ..\n COMMON / INFOC / INFOT, NUNIT, OK, LERR\n COMMON / SRNAMC / SRNAMT\n* ..\n* .. Data statements ..\n DATA KTYPE / 1, 2, 5*4, 5*6, 3*9, 10 /\n DATA KMAGN / 2*1, 3*1, 2, 3, 3*1, 2, 3, 1, 2, 3, 0 /\n DATA KMODE / 2*0, 4, 3, 1, 4, 4, 4, 3, 1, 4, 4, 0,\n $ 0, 0, 0 /\n* ..\n* .. Executable Statements ..\n*\n* Check for errors\n*\n INFO = 0\n*\n BADMM = .FALSE.\n BADNN = .FALSE.\n MMAX = 1\n NMAX = 1\n MNMAX = 1\n MINWRK = 1\n DO 10 J = 1, NSIZES\n MMAX = MAX( MMAX, MVAL( J ) )\n IF( MVAL( J ).LT.0 )\n $ BADMM = .TRUE.\n NMAX = MAX( NMAX, NVAL( J ) )\n IF( NVAL( J ).LT.0 )\n $ BADNN = .TRUE.\n MNMAX = MAX( MNMAX, MIN( MVAL( J ), NVAL( J ) ) )\n MINWRK = MAX( MINWRK, 3*( MVAL( J )+NVAL( J ) ),\n $ MVAL( J )*( MVAL( J )+MAX( MVAL( J ), NVAL( J ),\n $ NRHS )+1 )+NVAL( J )*MIN( NVAL( J ), MVAL( J ) ) )\n 10 CONTINUE\n*\n* Check for errors\n*\n IF( NSIZES.LT.0 ) THEN\n INFO = -1\n ELSE IF( BADMM ) THEN\n INFO = -2\n ELSE IF( BADNN ) THEN\n INFO = -3\n ELSE IF( NTYPES.LT.0 ) THEN\n INFO = -4\n ELSE IF( NRHS.LT.0 ) THEN\n INFO = -6\n ELSE IF( LDA.LT.MMAX ) THEN\n INFO = -11\n ELSE IF( LDX.LT.MMAX ) THEN\n INFO = -17\n ELSE IF( LDQ.LT.MMAX ) THEN\n INFO = -21\n ELSE IF( LDPT.LT.MNMAX ) THEN\n INFO = -23\n ELSE IF( MINWRK.GT.LWORK ) THEN\n INFO = -27\n END IF\n*\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'DCHKBD', -INFO )\n RETURN\n END IF\n*\n* Initialize constants\n*\n PATH( 1: 1 ) = 'Double precision'\n PATH( 2: 3 ) = 'BD'\n NFAIL = 0\n NTEST = 0\n UNFL = DLAMCH( 'Safe minimum' )\n OVFL = DLAMCH( 'Overflow' )\n CALL DLABAD( UNFL, OVFL )\n ULP = DLAMCH( 'Precision' )\n ULPINV = ONE / ULP\n LOG2UI = INT( LOG( ULPINV ) / LOG( TWO ) )\n RTUNFL = SQRT( UNFL )\n RTOVFL = SQRT( OVFL )\n INFOT = 0\n*\n* Loop over sizes, types\n*\n DO 200 JSIZE = 1, NSIZES\n M = MVAL( JSIZE )\n N = NVAL( JSIZE )\n MNMIN = MIN( M, N )\n AMNINV = ONE / MAX( M, N, 1 )\n*\n IF( NSIZES.NE.1 ) THEN\n MTYPES = MIN( MAXTYP, NTYPES )\n ELSE\n MTYPES = MIN( MAXTYP+1, NTYPES )\n END IF\n*\n DO 190 JTYPE = 1, MTYPES\n IF( .NOT.DOTYPE( JTYPE ) )\n $ GO TO 190\n*\n DO 20 J = 1, 4\n IOLDSD( J ) = ISEED( J )\n 20 CONTINUE\n*\n DO 30 J = 1, 14\n RESULT( J ) = -ONE\n 30 CONTINUE\n*\n UPLO = ' '\n*\n* Compute \"A\"\n*\n* Control parameters:\n*\n* KMAGN KMODE KTYPE\n* =1 O(1) clustered 1 zero\n* =2 large clustered 2 identity\n* =3 small exponential (none)\n* =4 arithmetic diagonal, (w/ eigenvalues)\n* =5 random symmetric, w/ eigenvalues\n* =6 nonsymmetric, w/ singular values\n* =7 random diagonal\n* =8 random symmetric\n* =9 random nonsymmetric\n* =10 random bidiagonal (log. distrib.)\n*\n IF( MTYPES.GT.MAXTYP )\n $ GO TO 100\n*\n ITYPE = KTYPE( JTYPE )\n IMODE = KMODE( JTYPE )\n*\n* Compute norm\n*\n GO TO ( 40, 50, 60 )KMAGN( JTYPE )\n*\n 40 CONTINUE\n ANORM = ONE\n GO TO 70\n*\n 50 CONTINUE\n ANORM = ( RTOVFL*ULP )*AMNINV\n GO TO 70\n*\n 60 CONTINUE\n ANORM = RTUNFL*MAX( M, N )*ULPINV\n GO TO 70\n*\n 70 CONTINUE\n*\n CALL DLASET( 'Full', LDA, N, ZERO, ZERO, A, LDA )\n IINFO = 0\n COND = ULPINV\n*\n BIDIAG = .FALSE.\n IF( ITYPE.EQ.1 ) THEN\n*\n* Zero matrix\n*\n IINFO = 0\n*\n ELSE IF( ITYPE.EQ.2 ) THEN\n*\n* Identity\n*\n DO 80 JCOL = 1, MNMIN\n A( JCOL, JCOL ) = ANORM\n 80 CONTINUE\n*\n ELSE IF( ITYPE.EQ.4 ) THEN\n*\n* Diagonal Matrix, [Eigen]values Specified\n*\n CALL DLATMS( MNMIN, MNMIN, 'S', ISEED, 'N', WORK, IMODE,\n $ COND, ANORM, 0, 0, 'N', A, LDA,\n $ WORK( MNMIN+1 ), IINFO )\n*\n ELSE IF( ITYPE.EQ.5 ) THEN\n*\n* Symmetric, eigenvalues specified\n*\n CALL DLATMS( MNMIN, MNMIN, 'S', ISEED, 'S', WORK, IMODE,\n $ COND, ANORM, M, N, 'N', A, LDA,\n $ WORK( MNMIN+1 ), IINFO )\n*\n ELSE IF( ITYPE.EQ.6 ) THEN\n*\n* Nonsymmetric, singular values specified\n*\n CALL DLATMS( M, N, 'S', ISEED, 'N', WORK, IMODE, COND,\n $ ANORM, M, N, 'N', A, LDA, WORK( MNMIN+1 ),\n $ IINFO )\n*\n ELSE IF( ITYPE.EQ.7 ) THEN\n*\n* Diagonal, random entries\n*\n CALL DLATMR( MNMIN, MNMIN, 'S', ISEED, 'N', WORK, 6, ONE,\n $ ONE, 'T', 'N', WORK( MNMIN+1 ), 1, ONE,\n $ WORK( 2*MNMIN+1 ), 1, ONE, 'N', IWORK, 0, 0,\n $ ZERO, ANORM, 'NO', A, LDA, IWORK, IINFO )\n*\n ELSE IF( ITYPE.EQ.8 ) THEN\n*\n* Symmetric, random entries\n*\n CALL DLATMR( MNMIN, MNMIN, 'S', ISEED, 'S', WORK, 6, ONE,\n $ ONE, 'T', 'N', WORK( MNMIN+1 ), 1, ONE,\n $ WORK( M+MNMIN+1 ), 1, ONE, 'N', IWORK, M, N,\n $ ZERO, ANORM, 'NO', A, LDA, IWORK, IINFO )\n*\n ELSE IF( ITYPE.EQ.9 ) THEN\n*\n* Nonsymmetric, random entries\n*\n CALL DLATMR( M, N, 'S', ISEED, 'N', WORK, 6, ONE, ONE,\n $ 'T', 'N', WORK( MNMIN+1 ), 1, ONE,\n $ WORK( M+MNMIN+1 ), 1, ONE, 'N', IWORK, M, N,\n $ ZERO, ANORM, 'NO', A, LDA, IWORK, IINFO )\n*\n ELSE IF( ITYPE.EQ.10 ) THEN\n*\n* Bidiagonal, random entries\n*\n TEMP1 = -TWO*LOG( ULP )\n DO 90 J = 1, MNMIN\n BD( J ) = EXP( TEMP1*DLARND( 2, ISEED ) )\n IF( J.LT.MNMIN )\n $ BE( J ) = EXP( TEMP1*DLARND( 2, ISEED ) )\n 90 CONTINUE\n*\n IINFO = 0\n BIDIAG = .TRUE.\n IF( M.GE.N ) THEN\n UPLO = 'U'\n ELSE\n UPLO = 'L'\n END IF\n ELSE\n IINFO = 1\n END IF\n*\n IF( IINFO.EQ.0 ) THEN\n*\n* Generate Right-Hand Side\n*\n IF( BIDIAG ) THEN\n CALL DLATMR( MNMIN, NRHS, 'S', ISEED, 'N', WORK, 6,\n $ ONE, ONE, 'T', 'N', WORK( MNMIN+1 ), 1,\n $ ONE, WORK( 2*MNMIN+1 ), 1, ONE, 'N',\n $ IWORK, MNMIN, NRHS, ZERO, ONE, 'NO', Y,\n $ LDX, IWORK, IINFO )\n ELSE\n CALL DLATMR( M, NRHS, 'S', ISEED, 'N', WORK, 6, ONE,\n $ ONE, 'T', 'N', WORK( M+1 ), 1, ONE,\n $ WORK( 2*M+1 ), 1, ONE, 'N', IWORK, M,\n $ NRHS, ZERO, ONE, 'NO', X, LDX, IWORK,\n $ IINFO )\n END IF\n END IF\n*\n* Error Exit\n*\n IF( IINFO.NE.0 ) THEN\n WRITE( NOUT, FMT = 9998 )'Generator', IINFO, M, N,\n $ JTYPE, IOLDSD\n INFO = ABS( IINFO )\n RETURN\n END IF\n*\n 100 CONTINUE\n*\n* Call DGEBRD and DORGBR to compute B, Q, and P, do tests.\n*\n IF( .NOT.BIDIAG ) THEN\n*\n* Compute transformations to reduce A to bidiagonal form:\n* B := Q' * A * P.\n*\n CALL DLACPY( ' ', M, N, A, LDA, Q, LDQ )\n CALL DGEBRD( M, N, Q, LDQ, BD, BE, WORK, WORK( MNMIN+1 ),\n $ WORK( 2*MNMIN+1 ), LWORK-2*MNMIN, IINFO )\n*\n* Check error code from DGEBRD.\n*\n IF( IINFO.NE.0 ) THEN\n WRITE( NOUT, FMT = 9998 )'DGEBRD', IINFO, M, N,\n $ JTYPE, IOLDSD\n INFO = ABS( IINFO )\n RETURN\n END IF\n*\n CALL DLACPY( ' ', M, N, Q, LDQ, PT, LDPT )\n IF( M.GE.N ) THEN\n UPLO = 'U'\n ELSE\n UPLO = 'L'\n END IF\n*\n* Generate Q\n*\n MQ = M\n IF( NRHS.LE.0 )\n $ MQ = MNMIN\n CALL DORGBR( 'Q', M, MQ, N, Q, LDQ, WORK,\n $ WORK( 2*MNMIN+1 ), LWORK-2*MNMIN, IINFO )\n*\n* Check error code from DORGBR.\n*\n IF( IINFO.NE.0 ) THEN\n WRITE( NOUT, FMT = 9998 )'DORGBR(Q)', IINFO, M, N,\n $ JTYPE, IOLDSD\n INFO = ABS( IINFO )\n RETURN\n END IF\n*\n* Generate P'\n*\n CALL DORGBR( 'P', MNMIN, N, M, PT, LDPT, WORK( MNMIN+1 ),\n $ WORK( 2*MNMIN+1 ), LWORK-2*MNMIN, IINFO )\n*\n* Check error code from DORGBR.\n*\n IF( IINFO.NE.0 ) THEN\n WRITE( NOUT, FMT = 9998 )'DORGBR(P)', IINFO, M, N,\n $ JTYPE, IOLDSD\n INFO = ABS( IINFO )\n RETURN\n END IF\n*\n* Apply Q' to an M by NRHS matrix X: Y := Q' * X.\n*\n CALL DGEMM( 'Transpose', 'No transpose', M, NRHS, M, ONE,\n $ Q, LDQ, X, LDX, ZERO, Y, LDX )\n*\n* Test 1: Check the decomposition A := Q * B * PT\n* 2: Check the orthogonality of Q\n* 3: Check the orthogonality of PT\n*\n CALL DBDT01( M, N, 1, A, LDA, Q, LDQ, BD, BE, PT, LDPT,\n $ WORK, RESULT( 1 ) )\n CALL DORT01( 'Columns', M, MQ, Q, LDQ, WORK, LWORK,\n $ RESULT( 2 ) )\n CALL DORT01( 'Rows', MNMIN, N, PT, LDPT, WORK, LWORK,\n $ RESULT( 3 ) )\n END IF\n*\n* Use DBDSQR to form the SVD of the bidiagonal matrix B:\n* B := U * S1 * VT, and compute Z = U' * Y.\n*\n CALL DCOPY( MNMIN, BD, 1, S1, 1 )\n IF( MNMIN.GT.0 )\n $ CALL DCOPY( MNMIN-1, BE, 1, WORK, 1 )\n CALL DLACPY( ' ', M, NRHS, Y, LDX, Z, LDX )\n CALL DLASET( 'Full', MNMIN, MNMIN, ZERO, ONE, U, LDPT )\n CALL DLASET( 'Full', MNMIN, MNMIN, ZERO, ONE, VT, LDPT )\n*\n CALL DBDSQR( UPLO, MNMIN, MNMIN, MNMIN, NRHS, S1, WORK, VT,\n $ LDPT, U, LDPT, Z, LDX, WORK( MNMIN+1 ), IINFO )\n*\n* Check error code from DBDSQR.\n*\n IF( IINFO.NE.0 ) THEN\n WRITE( NOUT, FMT = 9998 )'DBDSQR(vects)', IINFO, M, N,\n $ JTYPE, IOLDSD\n INFO = ABS( IINFO )\n IF( IINFO.LT.0 ) THEN\n RETURN\n ELSE\n RESULT( 4 ) = ULPINV\n GO TO 170\n END IF\n END IF\n*\n* Use DBDSQR to compute only the singular values of the\n* bidiagonal matrix B; U, VT, and Z should not be modified.\n*\n CALL DCOPY( MNMIN, BD, 1, S2, 1 )\n IF( MNMIN.GT.0 )\n $ CALL DCOPY( MNMIN-1, BE, 1, WORK, 1 )\n*\n CALL DBDSQR( UPLO, MNMIN, 0, 0, 0, S2, WORK, VT, LDPT, U,\n $ LDPT, Z, LDX, WORK( MNMIN+1 ), IINFO )\n*\n* Check error code from DBDSQR.\n*\n IF( IINFO.NE.0 ) THEN\n WRITE( NOUT, FMT = 9998 )'DBDSQR(values)', IINFO, M, N,\n $ JTYPE, IOLDSD\n INFO = ABS( IINFO )\n IF( IINFO.LT.0 ) THEN\n RETURN\n ELSE\n RESULT( 9 ) = ULPINV\n GO TO 170\n END IF\n END IF\n*\n* Test 4: Check the decomposition B := U * S1 * VT\n* 5: Check the computation Z := U' * Y\n* 6: Check the orthogonality of U\n* 7: Check the orthogonality of VT\n*\n CALL DBDT03( UPLO, MNMIN, 1, BD, BE, U, LDPT, S1, VT, LDPT,\n $ WORK, RESULT( 4 ) )\n CALL DBDT02( MNMIN, NRHS, Y, LDX, Z, LDX, U, LDPT, WORK,\n $ RESULT( 5 ) )\n CALL DORT01( 'Columns', MNMIN, MNMIN, U, LDPT, WORK, LWORK,\n $ RESULT( 6 ) )\n CALL DORT01( 'Rows', MNMIN, MNMIN, VT, LDPT, WORK, LWORK,\n $ RESULT( 7 ) )\n*\n* Test 8: Check that the singular values are sorted in\n* non-increasing order and are non-negative\n*\n RESULT( 8 ) = ZERO\n DO 110 I = 1, MNMIN - 1\n IF( S1( I ).LT.S1( I+1 ) )\n $ RESULT( 8 ) = ULPINV\n IF( S1( I ).LT.ZERO )\n $ RESULT( 8 ) = ULPINV\n 110 CONTINUE\n IF( MNMIN.GE.1 ) THEN\n IF( S1( MNMIN ).LT.ZERO )\n $ RESULT( 8 ) = ULPINV\n END IF\n*\n* Test 9: Compare DBDSQR with and without singular vectors\n*\n TEMP2 = ZERO\n*\n DO 120 J = 1, MNMIN\n TEMP1 = ABS( S1( J )-S2( J ) ) /\n $ MAX( SQRT( UNFL )*MAX( S1( 1 ), ONE ),\n $ ULP*MAX( ABS( S1( J ) ), ABS( S2( J ) ) ) )\n TEMP2 = MAX( TEMP1, TEMP2 )\n 120 CONTINUE\n*\n RESULT( 9 ) = TEMP2\n*\n* Test 10: Sturm sequence test of singular values\n* Go up by factors of two until it succeeds\n*\n TEMP1 = THRESH*( HALF-ULP )\n*\n DO 130 J = 0, LOG2UI\n* CALL DSVDCH( MNMIN, BD, BE, S1, TEMP1, IINFO )\n IF( IINFO.EQ.0 )\n $ GO TO 140\n TEMP1 = TEMP1*TWO\n 130 CONTINUE\n*\n 140 CONTINUE\n RESULT( 10 ) = TEMP1\n*\n* Use DBDSQR to form the decomposition A := (QU) S (VT PT)\n* from the bidiagonal form A := Q B PT.\n*\n IF( .NOT.BIDIAG ) THEN\n CALL DCOPY( MNMIN, BD, 1, S2, 1 )\n IF( MNMIN.GT.0 )\n $ CALL DCOPY( MNMIN-1, BE, 1, WORK, 1 )\n*\n CALL DBDSQR( UPLO, MNMIN, N, M, NRHS, S2, WORK, PT, LDPT,\n $ Q, LDQ, Y, LDX, WORK( MNMIN+1 ), IINFO )\n*\n* Test 11: Check the decomposition A := Q*U * S2 * VT*PT\n* 12: Check the computation Z := U' * Q' * X\n* 13: Check the orthogonality of Q*U\n* 14: Check the orthogonality of VT*PT\n*\n CALL DBDT01( M, N, 0, A, LDA, Q, LDQ, S2, DUMMA, PT,\n $ LDPT, WORK, RESULT( 11 ) )\n CALL DBDT02( M, NRHS, X, LDX, Y, LDX, Q, LDQ, WORK,\n $ RESULT( 12 ) )\n CALL DORT01( 'Columns', M, MQ, Q, LDQ, WORK, LWORK,\n $ RESULT( 13 ) )\n CALL DORT01( 'Rows', MNMIN, N, PT, LDPT, WORK, LWORK,\n $ RESULT( 14 ) )\n END IF\n*\n* Use DBDSDC to form the SVD of the bidiagonal matrix B:\n* B := U * S1 * VT\n*\n CALL DCOPY( MNMIN, BD, 1, S1, 1 )\n IF( MNMIN.GT.0 )\n $ CALL DCOPY( MNMIN-1, BE, 1, WORK, 1 )\n CALL DLASET( 'Full', MNMIN, MNMIN, ZERO, ONE, U, LDPT )\n CALL DLASET( 'Full', MNMIN, MNMIN, ZERO, ONE, VT, LDPT )\n*\n CALL DBDSDC( UPLO, 'I', MNMIN, S1, WORK, U, LDPT, VT, LDPT,\n $ DUM, IDUM, WORK( MNMIN+1 ), IWORK, IINFO )\n*\n* Check error code from DBDSDC.\n*\n IF( IINFO.NE.0 ) THEN\n WRITE( NOUT, FMT = 9998 )'DBDSDC(vects)', IINFO, M, N,\n $ JTYPE, IOLDSD\n INFO = ABS( IINFO )\n IF( IINFO.LT.0 ) THEN\n RETURN\n ELSE\n RESULT( 15 ) = ULPINV\n GO TO 170\n END IF\n END IF\n*\n* Use DBDSDC to compute only the singular values of the\n* bidiagonal matrix B; U and VT should not be modified.\n*\n CALL DCOPY( MNMIN, BD, 1, S2, 1 )\n IF( MNMIN.GT.0 )\n $ CALL DCOPY( MNMIN-1, BE, 1, WORK, 1 )\n*\n CALL DBDSDC( UPLO, 'N', MNMIN, S2, WORK, DUM, 1, DUM, 1,\n $ DUM, IDUM, WORK( MNMIN+1 ), IWORK, IINFO )\n*\n* Check error code from DBDSDC.\n*\n IF( IINFO.NE.0 ) THEN\n WRITE( NOUT, FMT = 9998 )'DBDSDC(values)', IINFO, M, N,\n $ JTYPE, IOLDSD\n INFO = ABS( IINFO )\n IF( IINFO.LT.0 ) THEN\n RETURN\n ELSE\n RESULT( 18 ) = ULPINV\n GO TO 170\n END IF\n END IF\n*\n* Test 15: Check the decomposition B := U * S1 * VT\n* 16: Check the orthogonality of U\n* 17: Check the orthogonality of VT\n*\n CALL DBDT03( UPLO, MNMIN, 1, BD, BE, U, LDPT, S1, VT, LDPT,\n $ WORK, RESULT( 15 ) )\n CALL DORT01( 'Columns', MNMIN, MNMIN, U, LDPT, WORK, LWORK,\n $ RESULT( 16 ) )\n CALL DORT01( 'Rows', MNMIN, MNMIN, VT, LDPT, WORK, LWORK,\n $ RESULT( 17 ) )\n*\n* Test 18: Check that the singular values are sorted in\n* non-increasing order and are non-negative\n*\n RESULT( 18 ) = ZERO\n DO 150 I = 1, MNMIN - 1\n IF( S1( I ).LT.S1( I+1 ) )\n $ RESULT( 18 ) = ULPINV\n IF( S1( I ).LT.ZERO )\n $ RESULT( 18 ) = ULPINV\n 150 CONTINUE\n IF( MNMIN.GE.1 ) THEN\n IF( S1( MNMIN ).LT.ZERO )\n $ RESULT( 18 ) = ULPINV\n END IF\n*\n* Test 19: Compare DBDSQR with and without singular vectors\n*\n TEMP2 = ZERO\n*\n DO 160 J = 1, MNMIN\n TEMP1 = ABS( S1( J )-S2( J ) ) /\n $ MAX( SQRT( UNFL )*MAX( S1( 1 ), ONE ),\n $ ULP*MAX( ABS( S1( 1 ) ), ABS( S2( 1 ) ) ) )\n TEMP2 = MAX( TEMP1, TEMP2 )\n 160 CONTINUE\n*\n RESULT( 19 ) = TEMP2\n*\n* End of Loop -- Check for RESULT(j) > THRESH\n*\n 170 CONTINUE\n DO 180 J = 1, 19\n IF( RESULT( J ).GE.THRESH ) THEN\n IF( NFAIL.EQ.0 )\n $ CALL DLAHD2( NOUT, PATH )\n WRITE( NOUT, FMT = 9999 )M, N, JTYPE, IOLDSD, J,\n $ RESULT( J )\n NFAIL = NFAIL + 1\n END IF\n 180 CONTINUE\n IF( .NOT.BIDIAG ) THEN\n NTEST = NTEST + 19\n ELSE\n NTEST = NTEST + 5\n END IF\n*\n 190 CONTINUE\n 200 CONTINUE\n*\n* Summary\n*\n CALL ALASUM( PATH, NOUT, NFAIL, NTEST, 0 )\n*\n RETURN\n*\n* End of DCHKBD\n*\n 9999 FORMAT( ' M=', I5, ', N=', I5, ', type ', I2, ', seed=',\n $ 4( I4, ',' ), ' test(', I2, ')=', G11.4 )\n 9998 FORMAT( ' DCHKBD: ', A, ' returned INFO=', I6, '.', / 9X, 'M=',\n $ I6, ', N=', I6, ', JTYPE=', I6, ', ISEED=(', 3( I5, ',' ),\n $ I5, ')' )\n*\n END\n", "meta": {"hexsha": "685d7ad65d4922c69bf98c65407b4c59e7291f1f", "size": 34284, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "TESTING/EIG/dchkbd.f", "max_stars_repo_name": "nashmit/lapack-release", "max_stars_repo_head_hexsha": "fd9237f4f4cd45f10a8be62b35e63a702c93328f", "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": "TESTING/EIG/dchkbd.f", "max_issues_repo_name": "nashmit/lapack-release", "max_issues_repo_head_hexsha": "fd9237f4f4cd45f10a8be62b35e63a702c93328f", "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": "TESTING/EIG/dchkbd.f", "max_forks_repo_name": "nashmit/lapack-release", "max_forks_repo_head_hexsha": "fd9237f4f4cd45f10a8be62b35e63a702c93328f", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.3808049536, "max_line_length": 72, "alphanum_fraction": 0.4649399137, "num_tokens": 10852, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473713594992, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6560161967970046}} {"text": "module constants\n implicit none\n\n public:: me, c, eps0, el\n\n real,parameter:: c = 2.99792458e8\n real,parameter:: me = 9.10938356e-31\n real,parameter:: eps0 = 8.85418782e-12\n real,parameter:: el = 1.60217662e-19\n real,parameter:: pi = acos(-1.0)\nend module constants\n", "meta": {"hexsha": "d03dea2cafe3d9382640196e2c4cb5c5e4cf4273", "size": 280, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "constants.f90", "max_stars_repo_name": "gjwilkie/nlfp", "max_stars_repo_head_hexsha": "9e566c4566d0657ea50686d79c3ad353a6c82975", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "constants.f90", "max_issues_repo_name": "gjwilkie/nlfp", "max_issues_repo_head_hexsha": "9e566c4566d0657ea50686d79c3ad353a6c82975", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "constants.f90", "max_forks_repo_name": "gjwilkie/nlfp", "max_forks_repo_head_hexsha": "9e566c4566d0657ea50686d79c3ad353a6c82975", "max_forks_repo_licenses": ["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.3333333333, "max_line_length": 41, "alphanum_fraction": 0.675, "num_tokens": 104, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6560161944443623}} {"text": " real function gcum(x)\nC%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nC %\nC Copyright (C) 1996, The Board of Trustees of the Leland Stanford %\nC Junior University. All rights reserved. %\nC %\nC The programs in GSLIB are distributed in the hope that they will be %\nC useful, but WITHOUT ANY WARRANTY. No author or distributor accepts %\nC responsibility to anyone for the consequences of using them or for %\nC whether they serve any particular purpose or work at all, unless he %\nC says so in writing. Everyone is granted permission to copy, modify %\nC and redistribute the programs in GSLIB, but only under the condition %\nC that this notice and the above copyright notice remain intact. %\nC %\nC%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nc-----------------------------------------------------------------------\nc\nc Evaluate the standard normal cdf given a normal deviate x. gcum is\nc the area under a unit normal curve to the left of x. The results are\nc accurate only to about 5 decimal places.\nc\nc\nc-----------------------------------------------------------------------\n z = x\n if(z.lt.0.) z = -z\n t = 1./(1.+ 0.2316419*z)\n gcum = t*(0.31938153 + t*(-0.356563782 + t*(1.781477937 +\n + t*(-1.821255978 + t*1.330274429))))\n e2 = 0.\nc\nc 6 standard deviations out gets treated as infinity:\nc\n if(z.le.6.) e2 = exp(-z*z/2.)*0.3989422803\n gcum = 1.0- e2 * gcum\n if(x.ge.0.) return\n gcum = 1.0 - gcum\n return\n end\n", "meta": {"hexsha": "2995459db9b42306a8f1110869cf95888260beb8", "size": 1797, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "visim/visim_src/gslib/gcum.f", "max_stars_repo_name": "fcecinati/QUICS_UOB", "max_stars_repo_head_hexsha": "88cc8534a304520f5b25f84f4516712befaf13b3", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-06T01:43:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-06T01:43:12.000Z", "max_issues_repo_path": "visim/visim_src/gslib/gcum.f", "max_issues_repo_name": "fcecinati/QUICS_UOB", "max_issues_repo_head_hexsha": "88cc8534a304520f5b25f84f4516712befaf13b3", "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": "visim/visim_src/gslib/gcum.f", "max_forks_repo_name": "fcecinati/QUICS_UOB", "max_forks_repo_head_hexsha": "88cc8534a304520f5b25f84f4516712befaf13b3", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-10-07T17:56:00.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-19T23:43:04.000Z", "avg_line_length": 46.0769230769, "max_line_length": 72, "alphanum_fraction": 0.469671675, "num_tokens": 399, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473614033683, "lm_q2_score": 0.7520125848754472, "lm_q1q2_score": 0.656016194158223}} {"text": " SUBROUTINE MB02WD( FORM, F, N, IPAR, LIPAR, DPAR, LDPAR, ITMAX,\n $ A, LDA, B, INCB, X, INCX, TOL, DWORK, LDWORK,\n $ IWARN, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To solve the system of linear equations Ax = b, with A symmetric,\nC positive definite, or, in the implicit form, f(A, x) = b, where\nC y = f(A, x) is a symmetric positive definite linear mapping\nC from x to y, using the conjugate gradient (CG) algorithm without\nC preconditioning.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC FORM CHARACTER*1\nC Specifies the form of the system of equations, as\nC follows:\nC = 'U' : Ax = b, the upper triagular part of A is used;\nC = 'L' : Ax = b, the lower triagular part of A is used;\nC = 'F' : the implicit, function form, f(A, x) = b.\nC\nC Function Parameters\nC\nC F EXTERNAL\nC If FORM = 'F', then F is a subroutine which calculates the\nC value of f(A, x), for given A and x.\nC If FORM <> 'F', then F is not called.\nC\nC F must have the following interface:\nC\nC SUBROUTINE F( N, IPAR, LIPAR, DPAR, LDPAR, A, LDA, X,\nC $ INCX, DWORK, LDWORK, INFO )\nC\nC where\nC\nC N (input) INTEGER\nC The dimension of the vector x. N >= 0.\nC\nC IPAR (input) INTEGER array, dimension (LIPAR)\nC The integer parameters describing the structure of\nC the matrix A.\nC\nC LIPAR (input) INTEGER\nC The length of the array IPAR. LIPAR >= 0.\nC\nC DPAR (input) DOUBLE PRECISION array, dimension (LDPAR)\nC The real parameters needed for solving the\nC problem.\nC\nC LDPAR (input) INTEGER\nC The length of the array DPAR. LDPAR >= 0.\nC\nC A (input) DOUBLE PRECISION array, dimension\nC (LDA, NC), where NC is the number of columns.\nC The leading NR-by-NC part of this array must\nC contain the (compressed) representation of the\nC matrix A, where NR is the number of rows of A\nC (function of IPAR entries).\nC\nC LDA (input) INTEGER\nC The leading dimension of the array A.\nC LDA >= MAX(1,NR).\nC\nC X (input/output) DOUBLE PRECISION array, dimension\nC (1+(N-1)*INCX)\nC On entry, this incremented array must contain the\nC vector x.\nC On exit, this incremented array contains the value\nC of the function f, y = f(A, x).\nC\nC INCX (input) INTEGER\nC The increment for the elements of X. INCX > 0.\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC The workspace array for subroutine F.\nC\nC LDWORK (input) INTEGER\nC The size of the array DWORK (as large as needed\nC in the subroutine F).\nC\nC INFO INTEGER\nC Error indicator, set to a negative value if an\nC input scalar argument is erroneous, and to\nC positive values for other possible errors in the\nC subroutine F. The LAPACK Library routine XERBLA\nC should be used in conjunction with negative INFO.\nC INFO must be zero if the subroutine finished\nC successfully.\nC\nC Parameters marked with \"(input)\" must not be changed.\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The dimension of the vector x. N >= 0.\nC If FORM = 'U' or FORM = 'L', N is also the number of rows\nC and columns of the matrix A.\nC\nC IPAR (input) INTEGER array, dimension (LIPAR)\nC If FORM = 'F', the integer parameters describing the\nC structure of the matrix A.\nC This parameter is ignored if FORM = 'U' or FORM = 'L'.\nC\nC LIPAR (input) INTEGER\nC The length of the array IPAR. LIPAR >= 0.\nC\nC DPAR (input) DOUBLE PRECISION array, dimension (LDPAR)\nC If FORM = 'F', the real parameters needed for solving\nC the problem.\nC This parameter is ignored if FORM = 'U' or FORM = 'L'.\nC\nC LDPAR (input) INTEGER\nC The length of the array DPAR. LDPAR >= 0.\nC\nC ITMAX (input) INTEGER\nC The maximal number of iterations to do. ITMAX >= 0.\nC\nC A (input) DOUBLE PRECISION array,\nC dimension (LDA, NC), if FORM = 'F',\nC dimension (LDA, N), otherwise.\nC If FORM = 'F', the leading NR-by-NC part of this array\nC must contain the (compressed) representation of the\nC matrix A, where NR and NC are the number of rows and\nC columns, respectively, of the matrix A. The array A is\nC not referenced by this routine itself, except in the\nC calls to the routine F.\nC If FORM <> 'F', the leading N-by-N part of this array\nC must contain the matrix A, assumed to be symmetric;\nC only the triangular part specified by FORM is referenced.\nC\nC LDA (input) INTEGER\nC The leading dimension of array A.\nC LDA >= MAX(1,NR), if FORM = 'F';\nC LDA >= MAX(1,N), if FORM = 'U' or FORM = 'L'.\nC\nC B (input) DOUBLE PRECISION array, dimension (1+(N-1)*INCB)\nC The incremented vector b.\nC\nC INCB (input) INTEGER\nC The increment for the elements of B. INCB > 0.\nC\nC X (input/output) DOUBLE PRECISION array, dimension\nC (1+(N-1)*INCX)\nC On entry, this incremented array must contain an initial\nC approximation of the solution. If an approximation is not\nC known, setting all elements of x to zero is recommended.\nC On exit, this incremented array contains the computed\nC solution x of the system of linear equations.\nC\nC INCX (input) INTEGER\nC The increment for the elements of X. INCX > 0.\nC\nC Tolerances\nC\nC TOL DOUBLE PRECISION\nC If TOL > 0, absolute tolerance for the iterative process.\nC The algorithm will stop if || Ax - b ||_2 <= TOL. Since\nC it is advisable to use a relative tolerance, say TOLER,\nC TOL should be chosen as TOLER*|| b ||_2.\nC If TOL <= 0, a default relative tolerance,\nC TOLDEF = N*EPS*|| b ||_2, is used, where EPS is the\nC machine precision (see LAPACK Library routine DLAMCH).\nC\nC Workspace\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0, DWORK(1) returns the number of\nC iterations performed and DWORK(2) returns the remaining\nC residual, || Ax - b ||_2.\nC\nC LDWORK INTEGER\nC The length of the array DWORK.\nC LDWORK >= MAX(2,3*N + DWORK(F)), if FORM = 'F',\nC where DWORK(F) is the workspace needed by F;\nC LDWORK >= MAX(2,3*N), if FORM = 'U' or FORM = 'L'.\nC\nC Warning Indicator\nC\nC IWARN INTEGER\nC = 0: no warning;\nC = 1: the algorithm finished after ITMAX > 0 iterations,\nC without achieving the desired precision TOL;\nC = 2: ITMAX is zero; in this case, DWORK(2) is not set.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value;\nC > 0: if INFO = i, then F returned with INFO = i.\nC\nC METHOD\nC\nC The following CG iteration is used for solving Ax = b:\nC\nC Start: q(0) = r(0) = Ax - b\nC\nC < q(k), r(k) >\nC ALPHA(k) = - ----------------\nC < q(k), Aq(k) >\nC x(k+1) = x(k) - ALPHA(k) * q(k)\nC r(k+1) = r(k) - ALPHA(k) * Aq(k)\nC < r(k+1), r(k+1) >\nC BETA(k) = --------------------\nC < r(k) , r(k) >\nC q(k+1) = r(k+1) + BETA(k) * q(k)\nC\nC where <.,.> denotes the scalar product.\nC\nC REFERENCES\nC\nC [1] Golub, G.H. and van Loan, C.F.\nC Matrix Computations. Third Edition.\nC M. D. Johns Hopkins University Press, Baltimore, pp. 520-528,\nC 1996.\nC\nC [2] Luenberger, G.\nC Introduction to Linear and Nonlinear Programming.\nC Addison-Wesley, Reading, MA, p.187, York, 1973.\nC\nC NUMERICAL ASPECTS\nC\nC Since the residuals are orthogonal in the scalar product\nC = y'Ax, the algorithm is theoretically finite. But rounding\nC errors cause a loss of orthogonality, so a finite termination\nC cannot be guaranteed. However, one can prove [2] that\nC\nC || x-x_k ||_A := sqrt( (x-x_k)' * A * (x-x_k) )\nC\nC sqrt( kappa_2(A) ) - 1\nC <= 2 || x-x_0 ||_A * ------------------------ ,\nC sqrt( kappa_2(A) ) + 1\nC\nC where kappa_2 is the condition number.\nC\nC The approximate number of floating point operations is\nC (k*(N**2 + 15*N) + N**2 + 3*N)/2, if FORM <> 'F',\nC k*(f + 7*N) + f, if FORM = 'F',\nC where k is the number of CG iterations performed, and f is the\nC number of floating point operations required by the subroutine F.\nC\nC CONTRIBUTORS\nC\nC A. Riedel, R. Schneider, Chemnitz University of Technology,\nC Oct. 2000, during a stay at University of Twente, NL.\nC\nC REVISIONS\nC\nC V. Sima, Research Institute for Informatics, Bucharest, Mar. 2001,\nC March, 2002.\nC\nC KEYWORDS\nC\nC Conjugate gradients, convergence, linear system of equations,\nC matrix operations.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, ONE\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )\nC .. Scalar Arguments ..\n CHARACTER FORM\n INTEGER INCB, INCX, INFO, ITMAX, IWARN, LDA, LDPAR,\n $ LDWORK, LIPAR, N\n DOUBLE PRECISION TOL\nC .. Array Arguments ..\n DOUBLE PRECISION A(LDA,*), B(*), DPAR(*), DWORK(*), X(*)\n INTEGER IPAR(*)\nC .. Local Scalars ..\n DOUBLE PRECISION ALPHA, BETA, RES, RESOLD, TOLDEF\n INTEGER AQ, DWLEFT, K, R\n LOGICAL MAT\nC .. External Functions ..\n DOUBLE PRECISION DDOT, DLAMCH, DNRM2\n LOGICAL LSAME\n EXTERNAL DDOT, DLAMCH, DNRM2, LSAME\nC .. External Subroutines ..\n EXTERNAL DAXPY, DCOPY, DSCAL, DSYMV, F, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC MAX\nC ..\nC .. Executable Statements ..\nC\nC Decode the scalar input parameters.\nC\n MAT = LSAME( FORM, 'U' ) .OR. LSAME( FORM, 'L' )\nC\nC Check the scalar input parameters.\nC\n IWARN = 0\n INFO = 0\n IF( .NOT.( MAT .OR. LSAME( FORM, 'F' ) ) ) THEN\n INFO = -1\n ELSEIF ( N.LT.0 ) THEN\n INFO = -3\n ELSEIF ( .NOT. MAT .AND. LIPAR.LT.0 ) THEN\n INFO = -5\n ELSEIF ( .NOT. MAT .AND. LDPAR.LT.0 ) THEN\n INFO = -7\n ELSEIF ( ITMAX.LT.0 ) THEN\n INFO = -8\n ELSEIF ( LDA.LT.1 .OR. ( MAT .AND. LDA.LT.N ) ) THEN\n INFO = -10\n ELSEIF ( INCB.LE.0 ) THEN\n INFO = -12\n ELSEIF ( INCX.LE.0 ) THEN\n INFO = -14\n ELSEIF ( LDWORK.LT.MAX( 2, 3*N ) ) THEN\n INFO = -17\n ENDIF\nC\nC Return if there are illegal arguments.\nC\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'MB02WD', -INFO )\n RETURN\n ENDIF\nC\nC Quick return if possible.\nC\n IF ( N.EQ.0 ) THEN\n DWORK(1) = ZERO\n DWORK(2) = ZERO\n RETURN\n ENDIF\nC\n IF ( ITMAX.EQ.0 ) THEN\n DWORK(1) = ZERO\n IWARN = 2\n RETURN\n ENDIF\nC\nC Set default tolerance, if needed.\nC\n TOLDEF = TOL\n IF ( TOLDEF.LE.ZERO )\n $ TOLDEF = DBLE( N )*DLAMCH( 'Epsilon' )*DNRM2( N, B, INCB )\nC\nC Initialize local variables.\nC\n K = 0\nC\nC Vector q is stored in DWORK(1), A*q or f(A, q) in DWORK(AQ),\nC and r in DWORK(R). The workspace for F starts in DWORK(DWLEFT).\nC\n AQ = N + 1\n R = N + AQ\n DWLEFT = N + R\nC\nC Prepare the first iteration, initialize r and q.\nC\n IF ( MAT ) THEN\n CALL DCOPY( N, B, INCB, DWORK(R), 1 )\n CALL DSYMV( FORM, N, ONE, A, LDA, X, INCX, -ONE, DWORK(R), 1 )\n ELSE\n CALL DCOPY( N, X, INCX, DWORK(R), 1 )\n CALL F( N, IPAR, LIPAR, DPAR, LDPAR, A, LDA, DWORK(R), 1,\n $ DWORK(DWLEFT), LDWORK-DWLEFT+1, INFO )\n IF ( INFO.NE.0 )\n $ RETURN\n CALL DAXPY( N, -ONE, B, INCB, DWORK(R), 1 )\n ENDIF\n CALL DCOPY( N, DWORK(R), 1, DWORK, 1 )\nC\n RES = DNRM2( N, DWORK(R), 1 )\nC\nC Do nothing if x is already the solution.\nC\n IF ( RES.LE.TOLDEF ) GOTO 20\nC\nC Begin of the iteration loop.\nC\nC WHILE ( RES.GT.TOLDEF .AND. K.LE.ITMAX ) DO\n 10 CONTINUE\nC\nC Calculate A*q or f(A, q).\nC\n IF ( MAT ) THEN\n CALL DSYMV( FORM, N, ONE, A, LDA, DWORK, 1, ZERO, DWORK(AQ),\n $ 1 )\n ELSE\n CALL DCOPY( N, DWORK, 1, DWORK(AQ), 1 )\n CALL F( N, IPAR, LIPAR, DPAR, LDPAR, A, LDA, DWORK(AQ), 1,\n $ DWORK(DWLEFT), LDWORK-DWLEFT+1, INFO )\n IF ( INFO.NE.0 )\n $ RETURN\n ENDIF\nC\nC Calculate ALPHA(k).\nC\n ALPHA = DDOT( N, DWORK, 1, DWORK(R), 1 ) /\n $ DDOT( N, DWORK, 1, DWORK(AQ), 1 )\nC\nC x(k+1) = x(k) - ALPHA(k)*q(k).\nC\n CALL DAXPY( N, -ALPHA, DWORK, 1, X, INCX )\nC\nC r(k+1) = r(k) - ALPHA(k)*(A*q(k)).\nC\n CALL DAXPY( N, -ALPHA, DWORK(AQ), 1, DWORK(R), 1 )\nC\nC Save RES and calculate a new RES.\nC\n RESOLD = RES\n RES = DNRM2( N, DWORK(R), 1 )\nC\nC Exit if tolerance is reached.\nC\n IF ( RES.LE.TOLDEF ) GOTO 20\nC\nC Calculate BETA(k).\nC\n BETA = ( RES/RESOLD )**2\nC\nC q(k+1) = r(k+1) + BETA(k)*q(k).\nC\n CALL DSCAL( N, BETA, DWORK, 1 )\n CALL DAXPY( N, ONE, DWORK(R), 1, DWORK, 1 )\nC\nC End of the iteration loop.\nC\n K = K + 1\n IF ( K.LT.ITMAX ) GOTO 10\nC END WHILE 10\nC\nC Tolerance was not reached!\nC\n IWARN = 1\nC\n 20 CONTINUE\nC\n DWORK(1) = K\n DWORK(2) = RES\nC\nC *** Last line of MB02WD ***\n END\n", "meta": {"hexsha": "30d3d507cffcf0cb909ad04dd48d38b3e2b249da", "size": 14956, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB02WD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB02WD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB02WD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 33.608988764, "max_line_length": 72, "alphanum_fraction": 0.5237362931, "num_tokens": 4451, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.925229959153748, "lm_q2_score": 0.709019146082187, "lm_q1q2_score": 0.6560057555688471}} {"text": " SUBROUTINE TTEST(DATA1,N1,DATA2,N2,T,PROB)\n DIMENSION DATA1(N1),DATA2(N2)\n CALL AVEVAR(DATA1,N1,AVE1,VAR1)\n CALL AVEVAR(DATA2,N2,AVE2,VAR2)\n DF=N1+N2-2\n VAR=((N1-1)*VAR1+(N2-1)*VAR2)/DF\n T=(AVE1-AVE2)/SQRT(VAR*(1./N1+1./N2))\n PROB=BETAI(0.5*DF,0.5,DF/(DF+T**2))\n RETURN\n END\n", "meta": {"hexsha": "4302f720f0c326850ad5b9016825425cb6c0f0c0", "size": 326, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "Math3/NumRec/source/ttest.for", "max_stars_repo_name": "domijin/MM3", "max_stars_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Math3/NumRec/source/ttest.for", "max_issues_repo_name": "domijin/MM3", "max_issues_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Math3/NumRec/source/ttest.for", "max_forks_repo_name": "domijin/MM3", "max_forks_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.6363636364, "max_line_length": 48, "alphanum_fraction": 0.5674846626, "num_tokens": 150, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9252299570920387, "lm_q2_score": 0.7090191399336402, "lm_q1q2_score": 0.6560057484182361}} {"text": "! ----------------------------------------------------------------------\r\n! SUBROUTINE: R3\r\n! ----------------------------------------------------------------------\r\n! Purpose:\r\n! Calculate rotation matrix about the z-axis (towards earth centre)\r\n! for given radians PSI\r\n! ----------------------------------------------------------------------\r\n! Author :\tJohn Donovan, Geoscience Australia\r\n! Created:\t26 March 2020\r\n! ----------------------------------------------------------------------\r\n*\r\n* ( + cos(PSI) + sin(PSI) 0 )\r\n* ( )\r\n* ( - sin(PSI) + cos(PSI) 0 )\r\n* ( )\r\n* ( 0 0 1 )\r\n*\r\n\r\n SUBROUTINE R3 ( PSI, R )\r\n IMPLICIT NONE\r\n\r\n DOUBLE PRECISION PSI, R(3,3)\r\n\r\n DOUBLE PRECISION S, C, A11, A12, A13, A21, A22, A23\r\n\r\n* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\r\n\r\n S = SIN(PSI)\r\n C = COS(PSI)\r\n\r\n\r\n A11 = C\r\n A12 = S\r\n A13 = 0.0d0\r\n A21 = - S\r\n A22 = C\r\n A23 = 0.0d0\r\n\r\n\r\n R(1,1) = A11\r\n R(1,2) = A12\r\n R(1,3) = A13\r\n R(2,1) = A21\r\n R(2,2) = A22\r\n R(2,3) = A23\r\n\r\n END\r\n", "meta": {"hexsha": "dff82ff58937569d776ccbb196e69b26244e72e4", "size": 1262, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/R3.for", "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/R3.for", "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/R3.for", "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": 26.2916666667, "max_line_length": 73, "alphanum_fraction": 0.2702060222, "num_tokens": 370, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.925229948845201, "lm_q2_score": 0.7090191399336402, "lm_q1q2_score": 0.6560057425710704}} {"text": "module HeatingMod\n implicit none\n private\n public :: crheat\n \n real, parameter :: sece = 35\n\ncontains\n\n function crheat_f1(x) result(f1)\n real :: x,f1\n f1=.9971*(1-(1-x**.2663)**1.3163)\n end function\n \n function crheat_f2(e) result(f2)\n real :: e,f2\n f2=2*e-13.6\n end function \n \n function crheat_f3(x) result(f3)\n real :: x,logx,f3\n logx=log10(x)\n f3=-.265*(-2.37+logx)*(4.69+logx)*(15.62+7.21*logx+logx**2)\n end function\n \n function crheat(x)\n real :: crheat,x,xe\n xe=x \n if(x.lt.5.e-5) xe=5.e-5\n if(x.gt.1) xe=1\n crheat=crheat_f1(xe)+1./(crheat_f2(sece)/crheat_f3(xe)+1./(1-crheat_f1(xe))) \n crheat=crheat*sece\n end function\n \nend module \n\n!program test\n!use heatingMod\n!real xe\n\n!10 read*, xe\n! if(xe.eq.0) stop\n! print*, crheat(xe)\n! goto 10\n \n!end program \n", "meta": {"hexsha": "b7b28e399817bd05d287597dca3107e5960b63e1", "size": 786, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/amuse/community/fi/src/heating.f90", "max_stars_repo_name": "rknop/amuse", "max_stars_repo_head_hexsha": "85d5bdcc29cfc87dc69d91c264101fafd6658aec", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 131, "max_stars_repo_stars_event_min_datetime": "2015-06-04T09:06:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-01T12:11:29.000Z", "max_issues_repo_path": "src/amuse/community/fi/src/heating.f90", "max_issues_repo_name": "rknop/amuse", "max_issues_repo_head_hexsha": "85d5bdcc29cfc87dc69d91c264101fafd6658aec", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 690, "max_issues_repo_issues_event_min_datetime": "2015-10-17T12:18:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:15:58.000Z", "max_forks_repo_path": "src/amuse/community/fi/src/heating.f90", "max_forks_repo_name": "rieder/amuse", "max_forks_repo_head_hexsha": "3ac3b6b8f922643657279ddee5c8ab3fc0440d5e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 102, "max_forks_repo_forks_event_min_datetime": "2015-01-22T10:00:29.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-09T13:29:43.000Z", "avg_line_length": 16.7234042553, "max_line_length": 79, "alphanum_fraction": 0.6386768448, "num_tokens": 316, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299529686201, "lm_q2_score": 0.7090191214879991, "lm_q1q2_score": 0.6560057284281937}} {"text": "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! This test computes a 3D FFT using 2DECOMP&FFT and P3DFFT separately,\n! crosschecks the result and compares the performance of the libraries.\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\nprogram p3dfft_test\n\n use p3dfft\n use decomp_2d\n use decomp_2d_fft\n use MPI\n \n implicit none\n \n integer, parameter :: wp=KIND(0.0d0)\n integer, parameter :: nx=128, ny=128, nz=128\n ! use 0*0 for auto-tuning, particularly good for large core count\n integer, parameter :: p_row=0, p_col=0 \n integer, parameter :: ntest = 10\n \n real(wp), dimension(:,:,:), allocatable :: BEG,FIN\n complex(wp), dimension(:,:,:), allocatable :: AEND,AEND2\n \n real(wp) :: cdiff, ccdiff\n double precision :: rtime1, rtime2\n integer :: ierr, ndims(2), nsize, proc_id\n integer :: dims(2), dummy_coords(2)\n logical :: dummy_periods(2)\n integer :: istart(3), iend(3), isize(3)\n integer :: fstart(3), fend(3), fsize(3)\n integer :: i, m, x, y, z, imin\n \n call MPI_INIT (ierr)\n \n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n ! 2DECOMP&FFT\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n call decomp_2d_init(nx,ny,nz,p_row,p_col)\n call MPI_CART_GET(DECOMP_2D_COMM_CART_X, 2, &\n dims, dummy_periods, dummy_coords, ierr)\n \n if (nrank == 0) then\n print *,' '\n print *,'----------------------------------------------'\n print *,'2DECOMP&FFT result'\n endif\n \n call decomp_2d_fft_init\n \n allocate (BEG(xstart(1):xend(1),xstart(2):xend(2),xstart(3):xend(3)))\n allocate (FIN(xstart(1):xend(1),xstart(2):xend(2),xstart(3):xend(3)))\n call decomp_2d_fft_get_size(istart,iend,isize)\n allocate(AEND(istart(1):iend(1),istart(2):iend(2),istart(3):iend(3)))\n allocate(AEND2(istart(1):iend(1),istart(2):iend(2),istart(3):iend(3)))\n \n do z=xstart(3),xend(3)\n do y=xstart(2),xend(2)\n do x=xstart(1),xend(1)\n BEG(x,y,z) = real(x,wp)/real(nx,wp)*real(y,wp) &\n /real(ny,wp)*real(z,wp)/real(nz,wp)\n FIN(x,y,z) = BEG(x,y,z) ! keep a copy\n end do\n end do\n end do\n \n rtime1 = 0.0D0\n do m = 1, ntest\n \n BEG = FIN ! Note if OVERWRITE flag used BEG may be overwritten.\n ! So here restore exact input from the copy.\n \n call MPI_Barrier(MPI_COMM_WORLD,ierr)\n rtime1 = rtime1 - MPI_WTIME()\n call decomp_2d_fft_3d(BEG,AEND)\n rtime1 = rtime1 + MPI_WTIME()\n \n ! keep a copy of the result for comparison with P3DFFT\n if (m==1) AEND2=AEND\n \n if (nrank==0 .AND. m==1) then\n imin = min(isize(1),min(isize(2),isize(3)))\n write(*,*) 'Result of forward transform:'\n write(*,*) (AEND(i,i,i),i=1,min(10,imin))\n end if\n \n AEND = AEND / real(nx,wp) / real(ny,wp) / real(nz,wp)\n \n call MPI_Barrier(MPI_COMM_WORLD,ierr)\n rtime1 = rtime1 - MPI_WTIME()\n call decomp_2d_fft_3d(AEND,BEG)\n rtime1 = rtime1 + MPI_WTIME()\n \n end do\n \n cdiff = 0.0_wp\n ccdiff = 0.0_wp\n do z=xstart(3),xend(3)\n do y=xstart(2),xend(2)\n do x=xstart(1),xend(1)\n if (cdiff < abs(BEG(x,y,z)-FIN(x,y,z))) then\n cdiff = abs(BEG(x,y,z)-FIN(x,y,z))\n end if\n end do\n end do\n end do\n call MPI_Reduce(cdiff,ccdiff,1,real_type,MPI_MAX,0, &\n MPI_COMM_WORLD,ierr)\n if (nrank == 0) then\n write(*,*) 'after backward transform'\n write (*,*) ' max diff =',ccdiff\n end if\n \n cdiff = 0.0_wp\n ccdiff = 0.0_wp\n do z=xstart(3),xend(3)\n do y=xstart(2),xend(2)\n do x=xstart(1),xend(1)\n cdiff = cdiff + (BEG(x,y,z)-FIN(x,y,z))**2\n end do\n end do\n end do\n call MPI_Reduce(cdiff,ccdiff,1,real_type,MPI_SUM,0, &\n MPI_COMM_WORLD,ierr)\n ccdiff = sqrt(ccdiff/real(nx,wp)/real(ny,wp)/real(nz,wp))\n if (nrank == 0) then\n write (*,*) 'aver diff =',ccdiff\n end if\n \n call MPI_Reduce(rtime1,rtime2,1,MPI_REAL8,MPI_MAX,0, &\n MPI_COMM_WORLD,ierr)\n if (nrank==0) then\n write(*,*)'cpu time per forward+backward transforms', &\n rtime2/dble(ntest)\n end if\n \n ! save some information for P3DFFT\n proc_id = nrank\n ndims(1) = dims(1)\n ndims(2) = dims(2)\n \n call decomp_2d_fft_finalize\n call decomp_2d_finalize\n \n deallocate(BEG, FIN, AEND)\n \n\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n ! P3DFFT\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n call MPI_COMM_SIZE(MPI_COMM_WORLD,nsize,ierr)\n call MPI_COMM_RANK(MPI_COMM_WORLD,proc_id,ierr)\n \n if (ndims(1)*ndims(2) /= nsize) then\n call MPI_ABORT(MPI_COMM_WORLD,-1,ierr)\n end if\n \n if (proc_id == 0) then\n print *,' '\n print *,'----------------------------------------------'\n print *,'P3DFFT result'\n endif\n \n call p3dfft_setup(ndims,nx,ny,nz,.true.)\n call p3dfft_get_dims(istart,iend,isize,1)\n call p3dfft_get_dims(fstart,fend,fsize,2)\n \n allocate (BEG(istart(1):iend(1),istart(2):iend(2),istart(3):iend(3)))\n allocate (AEND(fstart(1):fend(1),fstart(2):fend(2),fstart(3):fend(3)))\n allocate (FIN(istart(1):iend(1),istart(2):iend(2),istart(3):iend(3)))\n \n do z=istart(3),iend(3)\n do y=istart(2),iend(2)\n do x=istart(1),iend(1)\n BEG(x,y,z) = real(x,wp)/real(nx,wp)*real(y,wp) &\n /real(ny,wp)*real(z,wp)/real(nz,wp)\n end do\n end do\n end do\n !\n ! transform from physical space to wavenumber space\n ! (XgYiZj to XiYjZg)\n ! then transform back to physical space\n ! (XiYjZg to XgYiZj)\n !\n rtime1 = 0.0D0 \n do m=1, ntest\n \n call MPI_Barrier(MPI_COMM_WORLD,ierr)\n \n ! Forward transform\n rtime1 = rtime1 - MPI_wtime()\n ! The third parameter introduce in version 2.5.1 of P3DFFT\n ! API not compatible with earlier versions\n call p3dfft_ftran_r2c(BEG,AEND,'fft')\n rtime1 = rtime1 + MPI_wtime()\n \n ! check against 2DECOMP&FFT\n if (m==1) then\n cdiff = 0.0_wp\n do z=fstart(3),fend(3)\n do y=fstart(2),fend(2)\n do x=fstart(1),fend(1)\n cdiff = cdiff + &\n (real(AEND(x,y,z),wp)-real(AEND2(x,y,z),wp))**2 &\n +(aimag(AEND(x,y,z))-aimag(AEND2(x,y,z)))**2\n end do\n end do\n end do\n call MPI_Reduce(cdiff,ccdiff,1,mpireal,MPI_SUM,0, &\n MPI_COMM_WORLD,ierr)\n ccdiff = sqrt(ccdiff/real(nx/2+1,wp)/real(ny,wp)/real(nz,wp))\n if (proc_id==0) then\n write(*,*) ' '\n write(*,*) '==== Crosscheck (2DECOMP&FFT vs. P3DFFT) ===='\n write(*,*) 'aver diff = ', ccdiff\n write(*,*) ' '\n end if\n end if\n \n if (proc_id==0 .AND. m==1) then\n imin = min(fsize(1),min(fsize(2),fsize(3)))\n write(*,*) 'Result of forward transform:'\n write(*,*) (AEND(i,i,i),i=1,min(10,imin))\n end if\n \n AEND = AEND / real(nx,wp) / real(ny,wp) / real(nz,wp)\n \n call MPI_Barrier(MPI_COMM_WORLD,ierr)\n \n ! Backward transform\n rtime1 = rtime1 - MPI_wtime()\n call p3dfft_btran_c2r(AEND,FIN,'tff') \n rtime1 = rtime1 + MPI_wtime()\n \n end do\n \n cdiff = 0.0_wp\n ccdiff = 0.0_wp\n do z=istart(3),iend(3)\n do y=istart(2),iend(2)\n do x=istart(1),iend(1)\n if (cdiff < abs(BEG(x,y,z)-FIN(x,y,z))) then\n cdiff = abs(BEG(x,y,z)-FIN(x,y,z))\n end if\n end do\n end do\n end do\n call MPI_Reduce(cdiff,ccdiff,1,mpireal,MPI_MAX,0, &\n MPI_COMM_WORLD,ierr)\n if (proc_id == 0) then\n write(*,*) 'after backward transform'\n write (*,*) ' max diff =',ccdiff\n end if\n \n cdiff = 0.0_wp\n ccdiff = 0.0_wp\n do z=istart(3),iend(3)\n do y=istart(2),iend(2)\n do x=istart(1),iend(1)\n cdiff = cdiff + (BEG(x,y,z)-FIN(x,y,z))**2\n end do\n end do\n end do\n call MPI_Reduce(cdiff,ccdiff,1,mpireal,MPI_SUM,0, &\n MPI_COMM_WORLD,ierr)\n ccdiff = sqrt(ccdiff/real(nx,wp)/real(ny,wp)/real(nz,wp))\n if (proc_id == 0) then\n write (*,*) 'aver diff =',ccdiff\n end if\n \n call MPI_Reduce(rtime1,rtime2,1,mpi_real8,MPI_MAX,0, &\n MPI_COMM_WORLD,ierr)\n \n if (proc_id == 0) then\n write(*,*)'cpu time per forward+backward transforms', &\n rtime2/dble(ntest)\n end if\n \n call p3dfft_clean\n deallocate(BEG, FIN, AEND, AEND2)\n \n \n call MPI_FINALIZE (ierr)\n \nend program p3dfft_test\n", "meta": {"hexsha": "b9291ace524f746806f19afb55519658719426ee", "size": 8443, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/p3dfft/p3dfft.f90", "max_stars_repo_name": "BenMql/2decomp_emptyFourierFourier", "max_stars_repo_head_hexsha": "a7655268d78937f7b65043871af3d23736c55845", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2018-02-13T11:00:08.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-06T01:13:04.000Z", "max_issues_repo_path": "libs/2decomp_fft/examples/p3dfft/p3dfft.f90", "max_issues_repo_name": "GeZhouyang/ICLS-release", "max_issues_repo_head_hexsha": "940c7937cff412566b3ce9f058d961de06b4ad7f", "max_issues_repo_licenses": ["AFL-3.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-02-03T10:45:50.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-04T11:49:27.000Z", "max_forks_repo_path": "examples/p3dfft/p3dfft.f90", "max_forks_repo_name": "BenMql/2decomp_emptyFourierFourier", "max_forks_repo_head_hexsha": "a7655268d78937f7b65043871af3d23736c55845", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-02-17T12:47:17.000Z", "max_forks_repo_forks_event_max_datetime": "2020-01-30T11:01:14.000Z", "avg_line_length": 29.3159722222, "max_line_length": 73, "alphanum_fraction": 0.5480279521, "num_tokens": 2983, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619306896956, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.6559898193392953}} {"text": "! Check that parameters are correct intercepted.\n! Constants with comma separations are commonly\n! used, for instance Pi = 3._dp\nsubroutine foo_single(x)\n implicit none\n integer, parameter :: rp = selected_real_kind(6)\n real(rp), intent(inout) :: x\n dimension x(3)\n real(rp), parameter :: three = 3._rp\n x(1) = x(1) + x(2) + x(3) * three\n return\nend subroutine\n\nsubroutine foo_double(x)\n implicit none\n integer, parameter :: rp = selected_real_kind(15)\n real(rp), intent(inout) :: x\n dimension x(3)\n real(rp), parameter :: three = 3._rp\n x(1) = x(1) + x(2) + x(3) * three\n return\nend subroutine\n\n", "meta": {"hexsha": "02ac9dd993b39dbb69a233ed1f0d031f15f84639", "size": 610, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "crabageprediction/venv/Lib/site-packages/numpy/f2py/tests/src/parameter/constant_real.f90", "max_stars_repo_name": "13rianlucero/CrabAgePrediction", "max_stars_repo_head_hexsha": "92bc7fbe1040f49e820473e33cc3902a5a7177c7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 20453, "max_stars_repo_stars_event_min_datetime": "2015-01-02T09:00:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:35:56.000Z", "max_issues_repo_path": "venv/lib/python3.7/site-packages/numpy/f2py/tests/src/parameter/constant_real.f90", "max_issues_repo_name": "John1001Song/Big-Data-Robo-Adviser", "max_issues_repo_head_hexsha": "9444dce96954c546333d5aecc92a06c3bfd19aa5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 14862, "max_issues_repo_issues_event_min_datetime": "2015-01-01T01:28:34.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T23:48:52.000Z", "max_forks_repo_path": "venv/lib/python3.7/site-packages/numpy/f2py/tests/src/parameter/constant_real.f90", "max_forks_repo_name": "John1001Song/Big-Data-Robo-Adviser", "max_forks_repo_head_hexsha": "9444dce96954c546333d5aecc92a06c3bfd19aa5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 9362, "max_forks_repo_forks_event_min_datetime": "2015-01-01T15:49:43.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T21:26:51.000Z", "avg_line_length": 25.4166666667, "max_line_length": 51, "alphanum_fraction": 0.6754098361, "num_tokens": 193, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619350028204, "lm_q2_score": 0.7956581024858785, "lm_q1q2_score": 0.6559898187761798}} {"text": "module date_mod\r\nimplicit none\r\ninterface operator (+)\r\n module procedure add\r\nend interface\r\ninterface operator (>)\r\n module procedure greater\r\nend interface\r\ntype :: ym\r\n integer :: year,month\r\nend type ym\r\ncontains\r\n!\r\nelemental function str(date) result(text)\r\ntype(ym), intent(in) :: date\r\ncharacter (len=7) :: text\r\nwrite (text,\"(i4.4,'-',i2.2)\") date%year,date%month\r\nend function str\r\n!\r\nelemental function add(date,n) result(new_date)\r\ntype(ym), intent(in) :: date\r\ninteger , intent(in) :: n\r\ntype(ym) :: new_date\r\nnew_date = int_to_ym(int(date) + n)\r\nend function add\r\n!\r\nelemental function int(date) result(idate)\r\ntype(ym), intent(in) :: date\r\ninteger :: idate\r\nidate = date%year*12 + date%month\r\nend function int\r\n!\r\nelemental function int_to_ym(idate) result(date)\r\ninteger, intent(in) :: idate\r\ntype(ym) :: date\r\ndate%year = idate/12\r\ndate%month = idate - date%year*12\r\nif (date%month == 0) then\r\n date%month = 12\r\n date%year = date%year - 1\r\nend if\r\nend function int_to_ym\r\n!\r\nelemental function greater(date_1,date_2) result(tf)\r\ntype(ym), intent(in) :: date_1,date_2\r\nlogical :: tf\r\ntf = int(date_1) > int(date_2)\r\nend function greater\r\nend module date_mod\r\n\r\nprogram xdate\r\nuse date_mod, only: ym, str, operator(+), operator(>)\r\nimplicit none\r\ntype(ym), allocatable :: dates(:)\r\ndates = [ym(2021,11),ym(2021,12),ym(2022,1)] ! set array of type(ym)\r\nwrite (*,\"(a10,':',*(1x,a))\") \"dates\",str(dates) \r\nwrite (*,\"(a10,':',*(i8))\") \"months\",dates%month\r\nwrite (*,\"(a10,':',*(1x,a))\") \"dates+1\",str(dates+1) ! user-defined + operator\r\nwrite (*,*) \"dates > dates(2)\",dates > dates(2) ! user-defined > operator\r\n! output:\r\n! dates: 2021-11 2021-12 2022-01\r\n! months: 11 12 1\r\n! dates+1: 2021-12 2022-01 2022-02\r\n! dates > dates(2) F F T\r\nend program xdate\r\n", "meta": {"hexsha": "b2deb5b305533c7474f9409823af1014c82c599f", "size": 1859, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "date.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": "date.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": "date.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": 28.1666666667, "max_line_length": 79, "alphanum_fraction": 0.6347498655, "num_tokens": 600, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619263765706, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.655989805920302}} {"text": "MODULE circle_class\r\n!\r\n! This module implements a circle class. \r\n!\r\n! Record of revisions:\r\n! Date Programmer Description of change\r\n! ==== ========== =====================\r\n! 12/29/06 S. J. Chapman Original code\r\n!\r\nUSE shape_class ! USE parent class\r\nIMPLICIT NONE\r\n\r\n! Type definition\r\nTYPE,PUBLIC,EXTENDS(shape) :: circle \r\n\r\n ! Additional instance variables. \r\n REAL :: r = 0 ! Radius\r\n\r\nCONTAINS\r\n\r\n ! Bound procedures\r\n PROCEDURE,PUBLIC :: initialize => initialize_sub\r\n PROCEDURE,PUBLIC :: area => get_area_fn\r\n PROCEDURE,PUBLIC :: perimeter => get_perimeter_fn\r\n PROCEDURE,PUBLIC :: to_string => to_string_fn\r\n\r\nEND TYPE circle\r\n\r\n! Declare constant PI\r\nREAL,PARAMETER :: PI = 3.141593\r\n\r\n! Restrict access to the actual procedure names\r\nPRIVATE :: initialize_sub, get_area_fn, get_perimeter_fn\r\nPRIVATE :: to_string_fn\r\n\r\n! Now add methods\r\nCONTAINS\r\n\r\n SUBROUTINE initialize_sub(this,r)\r\n ! \r\n ! Initialize the circle object.\r\n !\r\n IMPLICIT NONE\r\n \r\n ! Declare calling arguments\r\n CLASS(circle) :: this ! Circle object\r\n REAL,INTENT(IN) :: r ! Radius\r\n \r\n ! Initialize the circle\r\n this%r = r\r\n\r\n END SUBROUTINE initialize_sub\r\n\r\n\r\n REAL FUNCTION get_area_fn(this)\r\n ! \r\n ! Return the area of this object.\r\n !\r\n IMPLICIT NONE\r\n \r\n ! Declare calling arguments\r\n CLASS(circle) :: this ! Circle object\r\n \r\n ! Calculate area\r\n get_area_fn = PI * this%r**2\r\n\r\n END FUNCTION get_area_fn\r\n\r\n\r\n REAL FUNCTION get_perimeter_fn(this)\r\n ! \r\n ! Return the perimeter of this object.\r\n !\r\n IMPLICIT NONE\r\n \r\n ! Declare calling arguments\r\n CLASS(circle) :: this ! Circle object\r\n \r\n ! Calculate perimeter\r\n get_perimeter_fn = 2.0 * PI * this%r\r\n\r\n END FUNCTION get_perimeter_fn\r\n\r\n\r\n CHARACTER(len=50) FUNCTION to_string_fn(this)\r\n ! \r\n ! Return the a character description of this object.\r\n !\r\n IMPLICIT NONE\r\n \r\n ! Declare calling arguments\r\n CLASS(circle) :: this ! Circle object\r\n \r\n ! Return description\r\n WRITE (to_string_fn,'(A,F6.2)') 'Circle of radius ', &\r\n this%r \r\n\r\n END FUNCTION to_string_fn\r\n\r\nEND MODULE circle_class\r\n", "meta": {"hexsha": "e47fdb70aab4cf26ee6217d777275f3c26945d45", "size": 2303, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap16/shape/circle_class.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/chap16/shape/circle_class.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/chap16/shape/circle_class.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": 22.801980198, "max_line_length": 60, "alphanum_fraction": 0.6022579244, "num_tokens": 551, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619263765707, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.6559898039228579}} {"text": "program diff_and_diss\nuse constants \nimplicit none\ninteger, parameter :: dp = selected_real_kind(15,307)\n! program to calculate ratediff and ratediss\nreal (dp) :: deltag,eta,ratediff,ratediss,temp,k\n! read eta (in Pa*s=pascal*second) deltag (of reaction) and temperature (in K)\nread(*,*) eta,deltag,temp\nif(deltag>0) then\n ratediff=8*boltz*temp/3/eta*avog*1d3\nelse\n ratediff=boltz*temp/planck*exp(deltag/r/temp)*ratm*temp\nendif\nk=exp(-deltag/r/temp)/ratm/temp\nratediss=ratediff*k\n! rate\nprint*, ratediff\nprint*, ratediss\n\nend program diff_and_diss\n\n", "meta": {"hexsha": "a7e2d81c91106a5a5d7aa020e6d7a3f28e2e8574", "size": 553, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/diff_and_diss.f90", "max_stars_repo_name": "emartineznunez/AutoMeKin2020", "max_stars_repo_head_hexsha": "0b336d89ed292805a8980c09c58cac58e207db6b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-01-27T17:41:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-22T08:31:19.000Z", "max_issues_repo_path": "src/diff_and_diss.f90", "max_issues_repo_name": "emartineznunez/AutoMeKin2020", "max_issues_repo_head_hexsha": "0b336d89ed292805a8980c09c58cac58e207db6b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-01-28T21:26:05.000Z", "max_issues_repo_issues_event_max_datetime": "2020-01-28T21:26:05.000Z", "max_forks_repo_path": "src/diff_and_diss.f90", "max_forks_repo_name": "emartineznunez/AutoMeKin2020", "max_forks_repo_head_hexsha": "0b336d89ed292805a8980c09c58cac58e207db6b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-01-30T02:52:05.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-02T16:46:59.000Z", "avg_line_length": 25.1363636364, "max_line_length": 78, "alphanum_fraction": 0.7613019892, "num_tokens": 188, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240211961401, "lm_q2_score": 0.6992544335934766, "lm_q1q2_score": 0.6559873810819417}} {"text": "cc Copyright (C) 2018-2021: Leslie Greengard, Zydrunas Gimbutas, \ncc Manas Rachh, Travis Askham\ncc Contact: greengard@cims.nyu.edu\ncc \ncc This program is free software; you can redistribute it and/or modify \ncc it under the terms of the GNU General Public License as published by \ncc the Free Software Foundation; either version 2 of the License, or \ncc (at your option) any later version. This program is distributed in \ncc the hope that it will be useful, but WITHOUT ANY WARRANTY; without \ncc even the implied warranty of MERCHANTABILITY or FITNESS FOR A \ncc PARTICULAR PURPOSE. See the GNU General Public License for more \ncc details. You should have received a copy of the GNU General Public \ncc License along with this program; \ncc if not, see .\nccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\nc\nc $Date$\nc $Revision$\n subroutine mbhfmm2d(nd,eps,beta,ns,sources,ifcharge,charge,\n 1 ifdipole,dipstr,dipvec,ifquadpole,quadstr,quadvec,ifoctpole,\n 2 octstr,octvec,iper,ifpgh,pot,grad,hess,nt,targ,ifpghtarg,\n 3 pottarg,gradtarg,hesstarg,ier)\nc----------------------------------------------\nc FMM for the modified biharmonic Green's\nc function\nc \nc G(x,y) = (S_beta(r) - S_0(r))/beta^2\nc\nc where S_beta(r) = K_0(beta r)/(2*pi) is the fundamental solution\nc of the Yukawa equation and S_0(r) = log(r)/(2*pi) is the\nc fundamental solution of the Laplace equation, with\nc r = sqrt( (x(1)-y(1))**2 + (x(2)-y(2))**2 )\nc\nc The expansions represent the sum\nc\nc u(x) = sum_j charge(j)*G(x,y(j))\nc + dipstr(j)*(G_{y1}(x,y(j))*dipvec(1,j) + G_{y2}*dipvec(2,j))\nc + quadstr(j)*(G_{y1y1}(x,y(j))*quadvec(1,j)\nc + G_{y1y2}*quadvec(2,j) + G_{y2y2}*quadvec(2,j))\nc + octstr(j)*(G_{y1y1y1}(x,y(j))*octvec(1,j)\nc + G_{y1y1y2}*octvec(2,j) + G_{y1y2y2}*octvec(2,j)\nc + G_{y1y2y2}*octvec(2,j))\nc\nc INPUT PARAMETERS:\nc \nc nd : number of expansions\nc eps : FMM precision requested\nc zk : Helmholtz parameter\nc ns : number of sources\nc sources(2,ns) : source locations\nc ifcharge : flag for including charge interactions\nc charge interactions included if ifcharge =1\nc not included otherwise\nc charge(nd,ns) : charge strengths\nc ifdipole : flag for including dipole interactions\nc dipole interactions included if ifdipole =1\nc not included otherwise\nc dipstr(nd,ns) : dipole strengths\nc dipvec(nd,2,ns) : dipole orientation vectors\nc ifquadpole : flag for including quadrupole interactions\nc quadrupole interactions included if ifquadpole =1\nc not included otherwise\nc quadstr(nd,ns) : quadrupole strengths\nc quadvec(nd,3,ns) : quadrupole orientation vectors\nc ifoctpole : flag for including octopole interactions\nc octopole interactions included if ifoctpole =1\nc not included otherwise\nc octstr(nd,ns) : octopole strengths\nc octvec(nd,4,ns) : octopole orientation vectors\nc iper : flag for periodic implmentations. Currently unused\nc ifpgh : flag for computing pot/grad/hess\nc ifpgh = 1, only potential is computed\nc ifpgh = 2, potential and gradient are computed\nc ifpgh = 3, potential, gradient, and hessian \nc are computed\nc nt : number of targets\nc targ(2,nt) : target locations\nc ifpghtarg : flag for computing pottarg/gradtarg/hesstarg\nc ifpghtarg = 1, only potential is computed at targets\nc ifpghtarg = 2, potential and gradient are \nc computed at targets\nc ifpghtarg = 3, potential, gradient, and hessian are \nc computed at targets\nc\nc OUTPUT PARAMETERS\nc pot(nd,*) : potential at the source locations\nc grad(nd,2,*) : gradients at the source locations\nc hess(nd,3,*) : hessian at the source locations\nc pottarg(nd,*) : potential at the target locations\nc gradtarg(nd,2,*): gradient at the target locations\nc hesstarg(nd,3,*): hessian at the target locations\nc ier : error code\nc\n\n\n implicit none\nc\ncc calling sequence variables\nc \n integer nd, ifcharge, ifdipole, ifquadpole, ifoctpole\n integer iper\n real *8 eps\n real *8 beta\n integer ns,nt,ier\n real *8 sources(2,ns),targ(2,nt)\n real *8 dipvec(nd,2,*)\n real *8 charge(nd,*),dipstr(nd,*)\n real *8 quadvec(nd,3,*),quadstr(nd,*)\n real *8 octvec(nd,4,*),octstr(nd,*) \n\n real *8 pot(nd,*),grad(nd,2,*),hess(nd,3,*)\n real *8 pottarg(nd,*),gradtarg(nd,2,*),hesstarg(nd,3,*)\n\nc\ncc Tree variables\nc\n integer, allocatable :: itree(:)\n integer iptr(8)\n integer nlmin,nlmax,ifunif\n real *8, allocatable :: tcenters(:,:),boxsize(:)\n integer nexpc,ntj\n real *8 expc(2)\n real *8 scj\n integer idivflag,nlevels,nboxes,ndiv\n integer ltree\n\n real *8, allocatable :: radsrc(:)\n real *8 radexp\n\nc\ncc sorted arrays\nc\n integer, allocatable :: isrc(:),isrcse(:,:)\n integer, allocatable :: itarg(:),itargse(:,:)\n real *8, allocatable :: sourcesort(:,:)\n real *8, allocatable :: targsort(:,:)\n \n complex *16, allocatable :: mbhmps(:,:,:), ymps(:,:,:)\n complex *16, allocatable :: mbhmpssort(:,:,:), ympssort(:,:,:) \n\n real *8, allocatable :: potsort(:,:),gradsort(:,:,:),\n 1 hesssort(:,:,:)\n real *8, allocatable :: pottargsort(:,:),gradtargsort(:,:,:),\n 1 hesstargsort(:,:,:)\n\nc\ncc additional fmm variables\n\n integer lmptot, ldc\n real *8, allocatable :: rscales(:)\n integer, allocatable :: nterms(:),iaddr(:,:)\n real *8, allocatable :: rmlexp(:),carray(:,:)\n\nc\ncc temporary variables\nc\n integer i,ilev,lmptmp,nmax,idim,j,l\n integer ifpgh,ifpghtarg,ifprint,iert\n integer ntermsmps,ndtmp,nterms1\n real *8 time1,time2,pi,done\n real *8 omp_get_wtime\n complex *16 zk, eye\n data eye /(0.0d0,1.0d0)/\n\n done = 1\n pi = atan(done)*4.0d0\n\n zk = beta*eye\n\n nexpc = 0\n\n nlevels = 0\n nboxes = 0\n idivflag =0\n ndiv = 20\n ltree = 0\n nlmin = 0\n nlmax = 51\n ifunif = 0\n iper = 0\n\n ifprint = 1\n\nc\ncc call the tree memory management\nc code to determine number of boxes,\nc number of levels and length of tree\nc\n\n \n call pts_tree_mem(sources,ns,targ,nt,idivflag,ndiv,nlmin,nlmax,\n 1 ifunif,iper,nlevels,nboxes,ltree)\n\n\n allocate(itree(ltree))\n allocate(boxsize(0:nlevels))\n allocate(tcenters(2,nboxes))\n\nc\nc call the tree code\nc\n\n call pts_tree_build(sources,ns,targ,nt,idivflag,ndiv,nlmin,nlmax,\n 1 ifunif,iper,nlevels,nboxes,ltree,itree,iptr,tcenters,boxsize)\n\n allocate(isrc(ns),isrcse(2,nboxes))\n allocate(itarg(nt),itargse(2,nboxes))\n\n call pts_tree_sort(ns,sources,itree,ltree,nboxes,nlevels,iptr,\n 1 tcenters,isrc,isrcse)\n\n call pts_tree_sort(nt,targ,itree,ltree,nboxes,nlevels,iptr,\n 1 tcenters,itarg,itargse)\n allocate(sourcesort(2,ns))\n allocate(targsort(2,nt))\n\n ntermsmps=0\n if (ifdipole .eq. 1) ntermsmps = 1\n if (ifquadpole .eq. 1) ntermsmps = 2\n if (ifoctpole .eq. 1) ntermsmps = 3\n\n call prinf('ntermsmp *',ntermsmps,1)\n\n allocate(mbhmps(nd,0:ntermsmps,ns),\n 1 ymps(nd,0:ntermsmps,ns))\n\n allocate(mbhmpssort(nd,0:ntermsmps,ns),\n 1 ympssort(nd,0:ntermsmps,ns))\n\n do i = 1,ns\n do j = 0,ntermsmps\n do l = 1,nd\n mbhmps(l,j,i)=0\n ymps(l,j,i)=0\n enddo\n enddo\n enddo\n \n call mbh2dconvtomp_vec(nd,beta,ns,ifcharge,charge,\n 1 ifdipole,dipstr,dipvec,ifquadpole,quadstr,quadvec,\n 2 ifoctpole,octstr,octvec,ntermsmps,mbhmps,ymps)\n\n \n\n if(ifpgh.eq.1) then\n allocate(potsort(nd,ns),gradsort(nd,2,1),hesssort(nd,3,1))\n else if(ifpgh.eq.2) then\n allocate(potsort(nd,ns),gradsort(nd,2,ns),hesssort(nd,3,1))\n else if(ifpgh.eq.3) then\n allocate(potsort(nd,ns),gradsort(nd,2,ns),hesssort(nd,3,ns))\n else\n allocate(potsort(nd,1),gradsort(nd,2,1),hesssort(nd,3,1))\n endif\n\n \n if(ifpghtarg.eq.1) then\n allocate(pottargsort(nd,nt),gradtargsort(nd,2,1),\n 1 hesstargsort(nd,3,1))\n else if(ifpghtarg.eq.2) then\n allocate(pottargsort(nd,nt),gradtargsort(nd,2,nt),\n 1 hesstargsort(nd,3,1))\n else if(ifpghtarg.eq.3) then\n allocate(pottargsort(nd,nt),gradtargsort(nd,2,nt),\n 1 hesstargsort(nd,3,nt))\n else\n allocate(pottargsort(nd,1),gradtargsort(nd,2,1),\n 1 hesstargsort(nd,3,1))\n endif\n \nc\ncc initialize potentials,hessians,gradients\nc\n\n\n if(ifpgh.eq.1) then\n do i=1,ns\n do idim=1,nd\n potsort(idim,i) = 0\n enddo\n enddo\n endif\n\n if(ifpgh.eq.2) then\n do i=1,ns\n do idim=1,nd\n potsort(idim,i) = 0\n gradsort(idim,1,i) = 0\n gradsort(idim,2,i) = 0\n enddo\n enddo\n endif\n\n if(ifpgh.eq.3) then\n do i=1,ns\n do idim=1,nd\n potsort(idim,i) = 0\n gradsort(idim,1,i) = 0\n gradsort(idim,2,i) = 0\n hesssort(idim,1,i) = 0\n hesssort(idim,2,i) = 0\n hesssort(idim,3,i) = 0\n enddo\n enddo\n endif\n\n\n if(ifpghtarg.eq.1) then\n do i=1,nt\n do idim=1,nd\n pottarg(idim,i) = 0\n pottargsort(idim,i) = 0\n enddo\n enddo\n endif\n\n if(ifpghtarg.eq.2) then\n do i=1,nt\n do idim=1,nd\n pottargsort(idim,i) = 0\n gradtargsort(idim,1,i) = 0\n gradtargsort(idim,2,i) = 0\n enddo\n enddo\n endif\n\n if(ifpghtarg.eq.3) then\n do i=1,nt\n do idim=1,nd\n pottargsort(idim,i) = 0\n gradtargsort(idim,1,i) = 0\n gradtargsort(idim,2,i) = 0\n hesstargsort(idim,1,i) = 0\n hesstargsort(idim,2,i) = 0\n hesstargsort(idim,3,i) = 0\n enddo\n enddo\n endif\n\n\nc\ncc compute scaling factor for multipole/local expansions\nc and lengths of multipole and local expansions\nc\n allocate(rscales(0:nlevels),nterms(0:nlevels))\n\n nmax = 0\n ier = 0\n do i=0,nlevels\n rscales(i) = min(abs(zk*boxsize(i)/(2.0d0*pi)),1.0d0)\n call l2dterms(eps,nterms1,ier)\n nterms(i) = nterms1\n if(nterms(i).gt.nmax) nmax = nterms(i)\n enddo\n\n if(ifprint.eq.1) call prinf('nmax=*',nmax,1)\n if(ifprint.eq.1) call prinf('nterms=*',nterms,nlevels+1)\n\n ldc = nmax+5\n allocate(carray(0:ldc,0:ldc))\n call mbh2d_init_carray(carray,ldc)\n\n \nc \nc Multipole and local expansions will be held in workspace\nc in locations pointed to by array iaddr(4,nboxes).\nc\nc ... allocate iaddr and temporary arrays\nc\n\n allocate(iaddr(4,nboxes))\n\n\nc reorder sources\nc\n call dreorderf(2,ns,sources,sourcesort,isrc)\n ndtmp = nd*2*(ntermsmps+1)\n call dreorderf(ndtmp,ns,mbhmps,mbhmpssort,isrc)\n call dreorderf(ndtmp,ns,ymps,ympssort,isrc) \n\nc\ncc reorder targets\nc\n call dreorderf(2,nt,targ,targsort,itarg)\n\n\n\nc\nc\nc allocate memory need by multipole, local expansions at all\nc levels\nc irmlexp is pointer for workspace need by various fmm routines,\nc\n call mbh2dmpalloc(nd,itree(iptr(1)),iaddr,nlevels,lmptot,\n 1 nterms)\n if(ifprint .eq. 1) call prinf(' lmptot is *',lmptot,1)\n\n ier = 0\n allocate(rmlexp(lmptot),stat=iert)\n if(iert.ne.0) then\n print *, \"Cannot allocate mpole expansion workspace\"\n print *, \"lmptot=\", lmptot\n ier = 4\n return\n endif\n\n\n\nc\ncc call the main fmm routine\nc\n\nc Memory allocation is complete. \nc Call main fmm routine\nc\n call cpu_time(time1)\nC$ time1=omp_get_wtime()\n call mbhfmm2dmain(nd,eps,\n $ beta,ns,sourcesort,\n $ ntermsmps,mbhmpssort,ympssort,\n $ nt,targsort,\n $ iaddr,rmlexp,carray,ldc,\n $ itree,ltree,iptr,ndiv,nlevels,\n $ nboxes,iper,boxsize,rscales,tcenters,itree(iptr(1)),\n $ isrcse,itargse,nterms,\n $ ifpgh,potsort,gradsort,hesssort,\n $ ifpghtarg,pottargsort,gradtargsort,\n $ hesstargsort,ier)\n call cpu_time(time2)\nC$ time2=omp_get_wtime()\n if( ifprint .eq. 1 ) call prin2('time in fmm main=*',\n 1 time2-time1,1)\n if(ier.ne.0) return\n\n\nc\ncc resort the output arrays in input order\nc\n\n if(ifpgh.eq.1) then\n call dreorderi(nd,ns,potsort,pot,isrc)\n endif\n\n if(ifpgh.eq.2) then\n call dreorderi(nd,ns,potsort,pot,isrc)\n call dreorderi(2*nd,ns,gradsort,grad,isrc)\n endif\n\n if(ifpgh.eq.3) then\n call dreorderi(nd,ns,potsort,pot,isrc)\n call dreorderi(2*nd,ns,gradsort,grad,isrc)\n call dreorderi(3*nd,ns,hesssort,hess,isrc)\n endif\n\ncc call prini(6,13)\ncc call prin2('eps = *', eps, 1)\nc call prin2('after mbhfmm2dmain, potsort = *', potsort,\nc 1 2*nt)\ncc stop\n \n if(ifpghtarg.eq.1) then\n call dreorderi(nd,nt,pottargsort,pottarg,itarg)\n endif\n\n if(ifpghtarg.eq.2) then\n call dreorderi(nd,nt,pottargsort,pottarg,itarg)\n call dreorderi(2*nd,nt,gradtargsort,gradtarg,itarg)\n endif\n\n if(ifpghtarg.eq.3) then\n call dreorderi(nd,nt,pottargsort,pottarg,itarg)\n call dreorderi(2*nd,nt,gradtargsort,gradtarg,itarg)\n call dreorderi(3*nd,nt,hesstargsort,hesstarg,itarg)\n endif\n\n\n return\n end\n\n subroutine mbhfmm2dmain(nd,eps,\n $ beta,nsource,source,\n $ ntermsmps,mbhmps,ymps,\n $ ntarget,target,\n $ iaddr,rmlexp,carray,ldc,\n $ itree,ltree,iptr,ndiv,nlevels, \n $ nboxes,iper,boxsize,rscales,centers,laddr,\n $ isrcse,itargse,nterms,\n $ ifpgh,pot,grad,hess,\n $ ifpghtarg,pottarg,gradtarg,hesstarg,\n $ ier)\nc 2D FMM for the modified biharmonic Green's\nc function\nc \nc G(x,y) = (S_beta(r) - S_0(r))/beta^2\nc\nc where S_beta(r) = K_0(beta r)/(2*pi) is the fundamental solution\nc of the Yukawa equation and S_0(r) = log(r)/(2*pi) is the\nc fundamental solution of the Laplace equation, with\nc r = sqrt( (x(1)-y(1))**2 + (x(2)-y(2))**2 )\nc\nc This FMM takes charges to be multipolar expansions\nc of a given length.\nc\nc All the source/target related quantities\nc are assumed to be tree-sorted\nc\nc-----------------------------------------------------------------------\nc INPUT PARAMETERS:\nc\nc nd: number of charge densities\nc\nc eps: FMM precision requested\nc\nc beta: real *8, modified biharmonic parameter\nc\nc nsource: integer: number of sources\nc source: real *8 (2,ns): source locations\nc ntermsmps: integer: order of multipolar sources\nc mbhmps: complex *16(nd,0:ntermsmps,nsource): difference function\nc type expansion at each source\nc ymps: complex *16(nd,0:ntermsmps,nsource): Yukawa (modified\nc bessel K) type expansion at each source\nc ntarget: integer: number of targets\nc target: real *8 (2,ntarget): target locations\nc iaddr: (4,nboxes): pointer in rmlexp where multipole\nc and local expansions for each\nc box is stored\nc iaddr(1,ibox) is the\nc starting index in rmlexp for the \nc difference typ multipole expansion of ibox\nc iaddr(2,ibox) is the\nc starting index in rmlexp for the \nc Yukawa (Bessel K) multipole expansion of ibox\nc iaddr(3,ibox) is the\nc starting index in rmlexp for the \nc difference type local expansion of ibox\nc and iaddr(4,ibox) is the\nc starting index in rmlexp\nc for the Laplace (power series)\nc local expansion of ibox\nc\nc itree in: integer (ltree)\nc This array contains all the information\nc about the tree\nc Refer to pts_tree2d.f \nc\nc ltree in: integer\nc length of tree\nc\nc iptr in: integer(8)\nc iptr is a collection of pointers \nc which points to where different elements \nc of the tree are stored in the itree array\nc\nc ndiv in: integer\nc Max number of chunks per box\nc\nc nlevels in: integer\nc number of levels in the tree\nc\nc \nc nboxes in: integer\nc number of boxes in the tree\nc\nc boxsize in: real*8 (0:nlevels)\nc boxsize(i) is the size of the box from end to end\nc at level i\nc \nc iper in: integer\nc flag for periodic implementation. Currently unused\nc\nc centers in: real *8(2,nboxes)\nc array containing the centers of all the boxes\nc\nc isrcse in: integer(2,nboxes)\nc starting and ending location of sources in ibox\nc in sorted list of sources\nc\nc itargse in: integer(2,nboxes)\nc starting and ending location of targets in ibox\nc in sorted list of sources\nc\nc nterms: (0:nlevels) length of multipole and local expansions\nc at various levels\nc ntj in: integer\nc order of the output expansions\nc\nc ifpgh in: integer\nc flag for evaluating potential/gradients/hessians \nc at sources.\nc ifpgh = 1, only potentials will be evaluated\nc ifpgh = 2, potentials/gradients will be evaluated\nc ifpgh = 3, potentials/gradients/hessians will be evaluated\nc\nc ifpghtarg in: integer\nc flag for evaluating potential/gradients/hessians \nc at targets.\nc ifpghtarg = 1, only potentials will be evaluated\nc ifpghtarg = 2, potentials/gradients will be evaluated\nc ifpghtarg = 3, potentials/gradients/hessians will be evaluated\nc\nc\nc OUTPUT\nc\nc pot: potential at the source locations\nc grad: gradient at the source locations\nc hess: gradient at the source locations\nc \nc pottarg: potential at the target locations\nc gradtarg: gradient at the target locations\nc hesstarg: gradient at the target locations\nc------------------------------------------------------------------\n\n implicit none\n\n integer nd\n\n real *8 zi, beta\n\n integer nsource,ntarget,ier\n integer ndiv,nlevels,ntermsmps\n\n integer ifpgh,ifpghtarg\n real *8 eps\n integer iper\n\n real *8 source(2,nsource)\n\n complex *16 :: mbhmps(nd,0:ntermsmps,nsource)\n complex *16 :: ymps(nd,0:ntermsmps,nsource) \n \n real *8 target(2,ntarget)\n\n real *8 pot(nd,*)\n real *8 grad(nd,2,*)\n real *8 hess(nd,3,*)\n\n real *8 pottarg(nd,*)\n real *8 gradtarg(nd,2,*)\n real *8 hesstarg(nd,3,*)\n\n integer iaddr(4,nboxes),lmptmp\n real *8 rmlexp(*)\n \n real *8 timeinfo(10)\n real *8 timelev(0:200)\n real *8 centers(2,*)\n\n integer laddr(2,0:nlevels)\n integer nterms(0:nlevels)\n integer iptr(8),ltree\n integer isrcse(2,nboxes),itargse(2,nboxes)\n integer itree(*)\n integer nboxes, ldc\n real *8 rscales(0:nlevels),boxsize(0:nlevels)\n real *8 carray(0:ldc,0:ldc)\n\n real *8 zkiupbound,thresh\n\n integer nterms_eval(4,0:200)\n\nc temp variables\n integer i,j,k,l,idim\n integer ibox,jbox,ilev,npts\n integer nchild,nlist1,nlist2,nlist3,nlist4\n integer mnlist1,mnlist2,mnlist3,mnlist4\n integer, allocatable :: list1(:,:),list2(:,:),list3(:,:)\n integer, allocatable :: list4(:,:)\n integer, allocatable :: nlist1s(:),nlist2s(:),nlist3s(:)\n integer, allocatable :: nlist4s(:)\n\n\n integer istart,iend,istarts,iends\n integer isstart,isend,jsstart,jsend\n integer jstart,jend\n integer istarte,iende,istartt,iendt\n\n integer ifprint\n\n integer ifhesstarg,nn\n real *8 d,time1,time2,omp_get_wtime\n real *8 tt1,tt2\n real *8 pottmp,gradtmp(2),hesstmp(3)\n \n double precision dlam, pi, boxlam\n \nc ifprint is an internal information printing flag. \nc Suppressed if ifprint=0.\nc Prints timing breakdown and other things if ifprint=1.\nc Prints timing breakdown, list information, and other things if ifprint=2.\nc \n ifprint=1\n\n pi = 4*atan(1.0d0)\nc \nc c\nc upper limit for zk along imaginary axis\n zkiupbound = 40.0d0\n zi = beta\n\n do i=0,nlevels\n timelev(i) = 0\n enddo\n\nc\nc compute list info\nc \n call computemnlists(nlevels,nboxes,itree,ltree,iptr,centers,\n 1 boxsize,iper,mnlist1,mnlist2,mnlist3,mnlist4)\n allocate(nlist1s(nboxes),list1(mnlist1,nboxes))\n allocate(nlist2s(nboxes),list2(mnlist2,nboxes))\n allocate(nlist3s(nboxes),list3(mnlist3,nboxes))\n allocate(nlist4s(nboxes),list4(mnlist4,nboxes))\n \n call computelists(nlevels,nboxes,itree,ltree,iptr,centers,\n 1 boxsize,iper,mnlist1,nlist1s,list1,mnlist2,nlist2s,list2,\n 2 mnlist3,nlist3s,list3,mnlist4,nlist4s,list4)\n\n\nc \n do i=1,10\n timeinfo(i)=0\n enddo\nc\nc ... set all multipole and local expansions to zero\nc\n do ilev = 0,nlevels\nC$OMP PARALLEL DO DEFAULT (SHARED)\nC$OMP$PRIVATE(ibox)\n do ibox = laddr(1,ilev),laddr(2,ilev)\n call mbh2dmpzero(nd,rmlexp(iaddr(1,ibox)),nterms(ilev))\n call mbh2dmpzero(nd,rmlexp(iaddr(2,ibox)),nterms(ilev))\n call mbh2dmpzero(nd,rmlexp(iaddr(3,ibox)),nterms(ilev))\n call mbh2dmpzero(nd,rmlexp(iaddr(4,ibox)),nterms(ilev))\n enddo\nC$OMP END PARALLEL DO \n enddo\n \nc\n if(ifprint .ge. 1) \n $ call prinf('=== STEP 1 (form mp) ====*',i,0)\n call cpu_time(time1)\nC$ time1=omp_get_wtime()\nc\nc ... step 1, locate all charges, assign them to boxes, and\nc form multipole expansions\n\n do ilev = 2,nlevels\n if(zi*boxsize(ilev).lt.zkiupbound) then\nC \n\nC$OMP PARALLEL DO DEFAULT (SHARED)\nC$OMP$PRIVATE(ibox,nchild,istart,iend,npts)\nC$OMP$SCHEDULE(DYNAMIC)\n do ibox=laddr(1,ilev),laddr(2,ilev)\n nchild = itree(iptr(4)+ibox-1)\n istart = isrcse(1,ibox)\n iend = isrcse(2,ibox)\n npts = iend-istart+1\nc Check if current box is a leaf box \n if(nchild.eq.0.and.npts.gt.0) then\n call mbh2dformmpmp_vec(nd,beta,rscales(ilev),\n 1 source(1,istart),npts,mbhmps(1,0,istart),\n 1 ymps(1,0,istart),ntermsmps,centers(1,ibox),\n 1 nterms(ilev),rmlexp(iaddr(1,ibox)),\n 1 rmlexp(iaddr(2,ibox)))\n endif\n enddo\nC$OMP END PARALLEL DO \n \n endif\n enddo\n\n call cpu_time(time2)\nC$ time2=omp_get_wtime()\n timeinfo(1)=time2-time1\n\n if(ifprint.ge.1)\n $ call prinf('=== STEP 2 (form lo) ====*',i,0)\n call cpu_time(time1)\nC$ time1=omp_get_wtime()\n do ilev = 2,nlevels\n if(zi*boxsize(ilev).lt.zkiupbound) then\nC$OMP PARALLEL DO DEFAULT(SHARED)\nC$OMP$PRIVATE(ibox,jbox,nlist4,istart,iend,npts,i)\nC$OMP$SCHEDULE(DYNAMIC)\n do ibox = laddr(1,ilev),laddr(2,ilev)\n npts = 0\n\n if(ifpghtarg.gt.0) then\n istart = itargse(1,ibox)\n iend = itargse(2,ibox)\n npts = npts + iend-istart+1\n endif\n\n if(ifpgh.gt.0) then\n istart = isrcse(1,ibox)\n iend = isrcse(2,ibox)\n npts = npts + iend-istart+1\n endif\n\n if(npts.gt.0) then\n \n do i=1,nlist4s(ibox)\n jbox = list4(i,ibox)\n istart = isrcse(1,jbox)\n iend = isrcse(2,jbox)\n npts = iend-istart+1\n \n call mbh2dformtamp_vec(nd,beta,rscales(ilev),\n 1 source(1,istart),npts,mbhmps(1,0,istart),\n 2 ymps(1,0,istart),ntermsmps,centers(1,ibox),\n 3 nterms(ilev),rmlexp(iaddr(3,ibox)),\n 4 rmlexp(iaddr(4,ibox)))\n\n enddo\n endif\n enddo\nC$OMP END PARALLEL DO \n\n endif\n enddo\n call cpu_time(time2)\nC$ time2=omp_get_wtime()\n timeinfo(2)=time2-time1\n\n if(ifprint .ge. 1)\n $ call prinf('=== STEP 3 (merge mp) ====*',i,0)\n call cpu_time(time1)\nC$ time1=omp_get_wtime()\nc\n do ilev=nlevels-1,1,-1\n\n if(zi*boxsize(ilev).lt.zkiupbound) then\n\n\nC$OMP PARALLEL DO DEFAULT(SHARED)\nC$OMP$PRIVATE(ibox,jbox,i,nchild,istart,iend,npts)\nC$OMP$SCHEDULE(DYNAMIC)\n do ibox = laddr(1,ilev),laddr(2,ilev)\n nchild = itree(iptr(4)+ibox-1)\n do i=1,nchild\n jbox = itree(iptr(5)+4*(ibox-1)+i-1)\n istart = isrcse(1,jbox)\n iend = isrcse(2,jbox)\n npts = iend-istart+1\n if(npts.gt.0) then\n call mbh2dmpmp_vec(nd,beta,rscales(ilev+1),\n 1 centers(1,jbox),rmlexp(iaddr(1,jbox)),\n 2 rmlexp(iaddr(2,jbox)),nterms(ilev+1),\n 3 rscales(ilev),centers(1,ibox),\n 4 rmlexp(iaddr(1,ibox)),rmlexp(iaddr(2,ibox)),\n 5 nterms(ilev))\n endif\n enddo\n enddo\nC$OMP END PARALLEL DO \n endif\n enddo\n call cpu_time(time2)\nC$ time2=omp_get_wtime()\n timeinfo(3)=time2-time1\n\n if(ifprint.ge.1)\n $ call prinf('=== Step 4 (mp to loc) ===*',i,0)\nc ... step 3, convert multipole expansions into local\nc expansions\n\n call cpu_time(time1)\nC$ time1=omp_get_wtime()\n do ilev = 2,nlevels\n\n tt1 = second()\n\n if(zi*boxsize(ilev).lt.zkiupbound) then\nC$OMP PARALLEL DO DEFAULT(SHARED)\nC$OMP$PRIVATE(ibox,jbox,istart,iend,npts,i,nlist2)\nC$OMP$SCHEDULE(DYNAMIC)\n do ibox = laddr(1,ilev),laddr(2,ilev)\n\n npts = 0\n\n if(ifpghtarg.gt.0) then\n istart = itargse(1,ibox)\n iend = itargse(2,ibox)\n npts = npts + iend-istart+1\n endif\n\n if(ifpgh.gt.0) then\n istart = isrcse(1,ibox)\n iend = isrcse(2,ibox)\n npts = npts + iend-istart+1\n endif\n\n if(npts.gt.0) then\n do i=1,nlist2s(ibox)\n jbox = list2(i,ibox) \n\n call mbh2dmploc_vec(nd,beta,rscales(ilev),\n 1 centers(1,jbox),rmlexp(iaddr(1,jbox)),\n 2 rmlexp(iaddr(2,jbox)),nterms(ilev),\n 3 rscales(ilev),centers(1,ibox),\n 4 rmlexp(iaddr(3,ibox)),\n 5 rmlexp(iaddr(4,ibox)),nterms(ilev))\n \n enddo\n endif\n enddo\nC$OMP END PARALLEL DO \n endif\n\n tt2 = second()\n timelev(ilev) = tt2-tt1\n\n enddo\n call cpu_time(time2)\nC$ time2=omp_get_wtime()\n timeinfo(4) = time2-time1\n\n if(ifprint.ge.1)\n $ call prinf('=== Step 5 (split loc) ===*',i,0)\n\n call cpu_time(time1)\nC$ time1=omp_get_wtime()\n do ilev = 1,nlevels-1\n if(zi*boxsize(ilev).lt.zkiupbound) then\nC$OMP PARALLEL DO DEFAULT(SHARED)\nC$OMP$PRIVATE(ibox,jbox,i,nchild,istart,iend,npts)\nC$OMP$SCHEDULE(DYNAMIC)\n do ibox = laddr(1,ilev),laddr(2,ilev)\n nchild = itree(iptr(4)+ibox-1)\n \n npts = 0\n\n if(ifpghtarg.gt.0) then\n istart = itargse(1,ibox)\n iend = itargse(2,ibox)\n npts = npts + iend-istart+1\n endif\n\n if(ifpgh.gt.0) then\n istart = isrcse(1,ibox)\n iend = isrcse(2,ibox)\n npts = npts + iend-istart+1\n endif\n\n if(npts.gt.0) then\n do i=1,nchild\n jbox = itree(iptr(5)+4*(ibox-1)+i-1)\n\n call mbh2dlocloc_vec(nd,beta,rscales(ilev),\n 1 centers(1,ibox),rmlexp(iaddr(3,ibox)),\n 2 rmlexp(iaddr(4,ibox)),nterms(ilev),\n 3 rscales(ilev+1),centers(1,jbox),\n 4 rmlexp(iaddr(3,jbox)),rmlexp(iaddr(4,jbox)),\n 5 nterms(ilev+1),carray,ldc)\n \n enddo\n endif\n enddo\nC$OMP END PARALLEL DO \n endif\n enddo\n call cpu_time(time2)\nC$ time2=omp_get_wtime()\n timeinfo(5) = time2-time1\n\n call cpu_time(time1)\nC$ time1=omp_get_wtime()\n if(ifprint.ge.1)\n $ call prinf('=== Step 6 (mp eval) ===*',i,0)\n\ncc call prinf('ifpgh=*',ifpgh,1)\ncc call prinf('ifpghtarg=*',ifpghtarg,1)\ncc call prinf('laddr=*',laddr,2*(nlevels+1))\n do ilev=1,nlevels-1\n if(zi*boxsize(ilev+1).lt.zkiupbound) then\nC$OMP PARALLEL DO DEFAULT(SHARED)\nC$OMP$PRIVATE(ibox,istart,iend,npts,j,i)\nC$OMP$PRIVATE(jbox)\nC$OMP$SCHEDULE(DYNAMIC)\n do ibox=laddr(1,ilev),laddr(2,ilev)\n\nc evalute multipole expansion at all targets\n istart = itargse(1,ibox)\n iend = itargse(2,ibox)\n npts = iend-istart+1\n\n if(ifpghtarg.eq.1) then\n do i=1,nlist3s(ibox)\n jbox = list3(i,ibox)\n \n call mbh2dmpevalp_vec(nd,beta,rscales(ilev+1),\n 1 centers(1,jbox),rmlexp(iaddr(1,jbox)),\n 1 rmlexp(iaddr(2,jbox)),\n 2 nterms(ilev+1),target(1,istart),npts,\n 3 pottarg(1,istart))\n enddo\n endif\n if(ifpghtarg.eq.2) then\n do i=1,nlist3s(ibox)\n jbox = list3(i,ibox)\n call mbh2dmpevalg_vec(nd,beta,rscales(ilev+1),\n 1 centers(1,jbox),rmlexp(iaddr(1,jbox)),\n 1 rmlexp(iaddr(2,jbox)),\n 2 nterms(ilev+1),target(1,istart),npts,\n 3 pottarg(1,istart),\n 4 gradtarg(1,1,istart))\n enddo\n endif\n if(ifpghtarg.eq.3) then\n do i=1,nlist3s(ibox)\n jbox = list3(i,ibox)\n\n call mbh2dmpevalh_vec(nd,beta,rscales(ilev+1),\n 1 centers(1,jbox),rmlexp(iaddr(1,jbox)),\n 1 rmlexp(iaddr(2,jbox)),\n 2 nterms(ilev+1),target(1,istart),npts,\n 3 pottarg(1,istart),\n 3 gradtarg(1,1,istart),hesstarg(1,1,istart))\n enddo\n endif\n\n\nc evalute multipole expansion at all sources\n istart = isrcse(1,ibox)\n iend = isrcse(2,ibox)\n npts = iend-istart+1\n \n\n if(ifpgh.eq.1) then\n do i=1,nlist3s(ibox)\n jbox = list3(i,ibox)\n call mbh2dmpevalp_vec(nd,beta,rscales(ilev+1),\n 1 centers(1,jbox),rmlexp(iaddr(1,jbox)),\n 1 rmlexp(iaddr(2,jbox)),\n 2 nterms(ilev+1),source(1,istart),npts,\n 3 pot(1,istart))\n enddo\n endif\n if(ifpgh.eq.2) then\n do i=1,nlist3s(ibox)\n jbox = list3(i,ibox)\n call mbh2dmpevalg_vec(nd,beta,rscales(ilev+1),\n 1 centers(1,jbox),rmlexp(iaddr(1,jbox)),\n 1 rmlexp(iaddr(2,jbox)),\n 2 nterms(ilev+1),source(1,istart),npts,\n 3 pot(1,istart),grad(1,1,istart))\n enddo\n endif\n if(ifpgh.eq.3) then\n do i=1,nlist3s(ibox)\n jbox = list3(i,ibox)\n call mbh2dmpevalh_vec(nd,beta,rscales(ilev+1),\n 1 centers(1,jbox),rmlexp(iaddr(1,jbox)),\n 1 rmlexp(iaddr(2,jbox)),\n 2 nterms(ilev+1),source(1,istart),npts,\n 3 pot(1,istart),grad(1,1,istart),hess(1,1,istart))\n enddo\n endif\n\n enddo\nC$OMP END PARALLEL DO \n endif\n enddo\n\n 1000 continue \n\n\n call cpu_time(time2)\nC$ time2=omp_get_wtime()\n timeinfo(6) = time2-time1\n\n\n if(ifprint.ge.1)\n $ call prinf('=== step 7 (eval lo) ===*',i,0)\n\nc ... step 7, evaluate all local expansions\n call cpu_time(time1)\nC$ time1=omp_get_wtime()\n do ilev = 0,nlevels\n if(zi*boxsize(ilev).lt.zkiupbound) then\nC$OMP PARALLEL DO DEFAULT(SHARED)\nC$OMP$PRIVATE(ibox,istart,iend,i,npts)\nC$OMP$SCHEDULE(DYNAMIC)\n do ibox = laddr(1,ilev),laddr(2,ilev)\n nchild = itree(iptr(4)+ibox-1)\n if(nchild.eq.0) then\nc c evaluate local expansion\nc at targets\n istart = itargse(1,ibox)\n iend = itargse(2,ibox)\n npts = iend-istart + 1\n if(ifpghtarg.eq.1) then\n call mbh2dtaevalp_vec(nd,beta,rscales(ilev),\n 1 centers(1,ibox),rmlexp(iaddr(3,ibox)),\n 1 rmlexp(iaddr(4,ibox)),\n 2 nterms(ilev),target(1,istart),npts,\n 3 pottarg(1,istart))\n endif\n if(ifpghtarg.eq.2) then\n call mbh2dtaevalg_vec(nd,beta,rscales(ilev),\n 1 centers(1,ibox),rmlexp(iaddr(3,ibox)),\n 2 rmlexp(iaddr(4,ibox)),\n 2 nterms(ilev),target(1,istart),npts,\n 3 pottarg(1,istart),gradtarg(1,1,istart))\n endif\n if(ifpghtarg.eq.3) then\n call mbh2dtaevalh_vec(nd,beta,rscales(ilev),\n 1 centers(1,ibox),rmlexp(iaddr(3,ibox)),\n 2 rmlexp(iaddr(4,ibox)),\n 2 nterms(ilev),target(1,istart),npts,\n 3 pottarg(1,istart),gradtarg(1,1,istart),\n 4 hesstarg(1,1,istart))\n endif\n\nc\ncc evaluate local expansion at sources\n\n istart = isrcse(1,ibox)\n iend = isrcse(2,ibox)\n npts = iend-istart+1\n if(ifpgh.eq.1) then\n call mbh2dtaevalp_vec(nd,beta,rscales(ilev),\n 1 centers(1,ibox),rmlexp(iaddr(3,ibox)),\n 1 rmlexp(iaddr(4,ibox)),\n 2 nterms(ilev),source(1,istart),npts,\n 3 pot(1,istart))\n endif\n if(ifpgh.eq.2) then\n call mbh2dtaevalg_vec(nd,beta,rscales(ilev),\n 1 centers(1,ibox),rmlexp(iaddr(3,ibox)),\n 1 rmlexp(iaddr(4,ibox)),\n 2 nterms(ilev),source(1,istart),npts,\n 3 pot(1,istart),grad(1,1,istart))\n endif\n if(ifpgh.eq.3) then\n call mbh2dtaevalh_vec(nd,beta,rscales(ilev),\n 1 centers(1,ibox),rmlexp(iaddr(3,ibox)),\n 1 rmlexp(iaddr(4,ibox)),\n 2 nterms(ilev),source(1,istart),npts,\n 3 pot(1,istart),grad(1,1,istart),hess(1,1,istart))\n endif\n endif\n enddo\nC$OMP END PARALLEL DO \n endif\n enddo\n\n call cpu_time(time2)\nC$ time2 = omp_get_wtime() \n timeinfo(7) = time2 - time1\n\n if(ifprint .ge. 1)\n $ call prinf('=== STEP 8 (direct) =====*',i,0)\n\nc\ncc set threshold for ignoring interactions with \nc |r| < thresh\nc\n thresh = boxsize(0)*1.0d-16\n call prin2('thresh=*',thresh,1)\nc\ncc\n call cpu_time(time1)\nC$ time1=omp_get_wtime() \n do ilev = 0,nlevels\nC$OMP PARALLEL DO DEFAULT(SHARED)\nC$OMP$PRIVATE(ibox,jbox,istartt,iendt,i,jstart,jend,istarte,iende)\nC$OMP$PRIVATE(nlist1,istarts,iends)\nC$OMP$SCHEDULE(DYNAMIC) \n do ibox = laddr(1,ilev),laddr(2,ilev)\n\n istartt = itargse(1,ibox)\n iendt = itargse(2,ibox)\n\n istarts = isrcse(1,ibox)\n iends = isrcse(2,ibox)\n\n do i =1,nlist1s(ibox)\n jbox = list1(i,ibox) \n\n jstart = isrcse(1,jbox)\n jend = isrcse(2,jbox)\n\n call mbhfmm2dmps_direct_vec(nd,jstart,jend,istartt,\n 1 iendt,beta,source,mbhmps,ymps,ntermsmps,\n 2 target,ifpghtarg,pottarg,\n 3 gradtarg,hesstarg,thresh)\n \n call mbhfmm2dmps_direct_vec(nd,jstart,jend,istarts,\n 1 iends,beta,source,mbhmps,ymps,ntermsmps,\n 2 source,ifpgh,pot,\n 3 grad,hess,thresh)\n \n enddo \n enddo\nC$OMP END PARALLEL DO \n enddo\n\n call cpu_time(time2)\nC$ time2=omp_get_wtime() \n timeinfo(8) = time2-time1\n if(ifprint.ge.1) call prin2('timeinfo=*',timeinfo,8)\n d = 0\n do i = 1,8\n d = d + timeinfo(i)\n enddo\n\n if(ifprint.ge.1) call prin2('sum(timeinfo)=*',d,1)\n if(ifprint.ge.1) call prin2('timlev=*',timelev,nlevels+1)\n\n return\n end\nc\nc------------------------------------------------------------------ \n subroutine mbhfmm2dmps_direct_vec(nd,istart,iend,jstart,jend,\n $ beta,source,mbhmps,ymps,ntermsmps,\n $ targ,ifpgh,pot,grad,hess,thresh)\nc--------------------------------------------------------------------\nc This subroutine adds the contribuition due to multipolar sources\nc istart to iend in the source array at the expansion centers\nc jstart to jend in the target array to the computed velocities\nc and gradients. Note that contributions for sources\nc within thresh of the targets are not added to the potential\nc \nc\nc INPUT arguments\nc-------------------------------------------------------------------\nc nd in: integer\nc number of charge densities\nc\nc istart in:Integer\nc Starting index in source array whose expansions\nc we wish to add\nc\nc iend in:Integer\nc Last index in source array whose expansions\nc we wish to add\nc\nc jstart in: Integer\nc First index in target array at which we\nc wish to update the potential and gradients\nc \nc jend in:Integer\nc Last index in target array at which we wish\nc to update the potential and gradients\nc\nc beta in: real *8\nc modified biharmonic parameter\nc\nc source in: real *8(2,ns)\nc Source locations\nc \nc mbhmps in: complex *16 (nd,0:ntermsmps,ns)\nc difference kernel type expansion at each source \nc\nc ymps in: complex *16 (nd,0:ntermsmps,ns)\nc Yukawa (Bessel K) type expansion at each source \nc\nc ntermsmps in: integer, order of the multipolar charges at\nc each source\nc \nc targ in: real *8(2,nt)\nc target locations\nc\nc ifpgh in: Integer\nc Flag for computing the potential/gradient/hessian.\nc ifpgh = 1, only potential is computed\nc ifpgh = 2, potential/gradient are computed\nc ifpgh = 3, potential/gradient/hessian are computed\nc\nc thresh in: real *8\nc threshold for computing interactions\nc if |r| < threshold, then interactions are\nc not included\nc\nc\nc------------------------------------------------------------\nc OUTPUT\nc\nc Updated velocity and gradients at the targets\nc pot : potential at the targets\nc grad: gradient at the targets\nc hess: Hessian at the targets\nc------------------------------------------------------- \n implicit none\nc\n integer istart,iend,jstart,jend,ns,j,i\n integer ifcharge,ifdipole\n\n integer nd,ntermsmps\n\n real *8 beta\n\n real *8 source(2,*)\n complex *16 mbhmps(nd,0:ntermsmps,*),ymps(nd,0:ntermsmps,*)\n\n integer ifpgh\n real *8 targ(2,*),thresh\n \nc\n real *8 pot(nd,*)\n real *8 grad(nd,2,*)\n real *8 hess(nd,3,*)\n\n integer nt\n\nc\n ns = iend - istart + 1\n nt = jend - jstart + 1\n \n if(ifpgh.eq.1) then\n call mbh2d_directmpsp_vec(nd,beta,source(1,istart),ns,\n 1 mbhmps(1,0,istart),ymps(1,0,istart),ntermsmps,\n 1 targ(1,jstart),nt,pot(1,jstart),thresh)\n endif\n\n if(ifpgh.eq.2) then\n call mbh2d_directmpsg_vec(nd,beta,source(1,istart),ns,\n 1 mbhmps(1,0,istart),ymps(1,0,istart),ntermsmps,\n 1 targ(1,jstart),nt, pot(1,jstart),grad(1,1,jstart),\n 1 thresh)\n endif\n if(ifpgh.eq.3) then\n call mbh2d_directmpsh_vec(nd,beta,source(1,istart),ns,\n 1 mbhmps(1,0,istart),ymps(1,0,istart),ntermsmps,\n 1 targ(1,jstart),nt,pot(1,jstart),grad(1,1,jstart),\n 1 hess(1,1,jstart),thresh)\n endif\n\nc\n return\n end\nc------------------------------------------------------------------ \n subroutine mbh2dmpalloc(nd,laddr,iaddr,nlevels,lmptot,\n 1 nterms)\nc This subroutine determines the size of the array\nc to be allocated for the multipole expansions\nc iaddr(1,i) points to the starting location of the multipole\nc expansion of box i and iaddr(2,i) points to the local\nc expansion of box i\nc \nc Input arguments\nc nd in: integer\nc number of expansions\nc\nc laddr in: Integer(2,0:nlevels)\nc indexing array providing access to boxes at each\nc level\nc\nc nlevels in: Integer\nc Total numner of levels\nc \nc nterms in: Integer(0:nlevels)\nc Number of terms requried in expansions at each\nc level\nc\nc------------------------------------------------------------------\nc Output arguments\nc iaddr out: Integer(4,nboxes)\nc Points to the multipole and local expansions in box i\nc iaddr(1,ibox) - difference type multipole exp\nc iaddr(2,ibox) - Yukawa (Bessel K) type multipole exp\nc iaddr(3,ibox) - difference type local exp\nc iaddr(4,ibox) - Laplace (power series) type multipole exp\nc \nc lmptot out: Integer\nc Total length of expansions array required\nc------------------------------------------------------------------\n\n implicit none\n integer nlevels,nterms(0:nlevels),nd,nsig,nt1,nt2,next235\n integer iaddr(4,*), lmptot, laddr(2,0:nlevels)\n integer ibox,i,iptr,istart,nn,itmp\n real *8 ddn\nc\n istart = 1\n do i = 0,nlevels\n\n nn = (nterms(i)+1)*2*nd\nC$OMP PARALLEL DO DEFAULT(SHARED)\nC$OMP$PRIVATE(ibox,itmp)\n do ibox = laddr(1,i),laddr(2,i)\nc Allocate memory for the multipole expansion \nc\n itmp = ibox - laddr(1,i)\n iaddr(1,ibox) = istart + itmp*nn*2\n iaddr(2,ibox) = istart + itmp*nn*2 + nn\n enddo\nC$OMP END PARALLEL DO \n istart = istart + (laddr(2,i)-laddr(1,i)+1)*nn*2\n enddo\nc\nc Allocate memory for the local expansion\nc\n do i=0,nlevels\n nn = (nterms(i)+1)*2*nd\nC$OMP PARALLEL DO DEFAULT(SHARED)\nC$OMP$PRIVATE(ibox,itmp)\n do ibox = laddr(1,i),laddr(2,i)\n itmp = ibox - laddr(1,i)\n iaddr(3,ibox) = istart + itmp*nn*2\n iaddr(4,ibox) = istart + itmp*nn*2 + nn \n enddo\nC$OMP END PARALLEL DO \n istart = istart + (laddr(2,i)-laddr(1,i)+1)*nn*2\n enddo\n lmptot = istart\n\n return\n end\nc---------------------------------------------------------------- \nc\nC***********************************************************************\n subroutine mbh2dmpzero(nd,mpole,nterms)\n implicit none\nC***********************************************************************\nc\nc This subroutine sets a multipole expansion of the given\nc order to zero.\nc-----------------------------------------------------------------------\nc INPUT:\nc\nc nd : number of expansions\nc nterms : order of multipole expansions\nC---------------------------------------------------------------------\nc OUTPUT:\nc\nc mpole : coeffs for the expansion set to zero.\nC---------------------------------------------------------------------\n integer n,nterms,nd,idim\n complex *16 mpole(nd,nterms+1)\nc\n do n=1,(nterms+1)\n do idim=1,nd\n mpole(idim,n)=0.0d0\n enddo\n enddo\n return\n end\nc\nc\n", "meta": {"hexsha": "57cb85897158f2f793c93508e54202b1f79b5b20", "size": 45640, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/modified-biharmonic/mbhfmm2d.f", "max_stars_repo_name": "flatironinstitute/fmm2d", "max_stars_repo_head_hexsha": "b1ccc42510fb8edab53c8753b74e2bb7ba56663b", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2020-12-22T16:01:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-01T05:47:18.000Z", "max_issues_repo_path": "src/modified-biharmonic/mbhfmm2d.f", "max_issues_repo_name": "flatironinstitute/fmm2d", "max_issues_repo_head_hexsha": "b1ccc42510fb8edab53c8753b74e2bb7ba56663b", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-12-15T16:25:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-21T21:03:32.000Z", "max_forks_repo_path": "src/modified-biharmonic/mbhfmm2d.f", "max_forks_repo_name": "flatironinstitute/fmm2d", "max_forks_repo_head_hexsha": "b1ccc42510fb8edab53c8753b74e2bb7ba56663b", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2020-12-23T04:45:28.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-15T18:09:44.000Z", "avg_line_length": 31.6285516286, "max_line_length": 79, "alphanum_fraction": 0.5441279579, "num_tokens": 14148, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240090865197, "lm_q2_score": 0.6992544273261175, "lm_q1q2_score": 0.6559873667346758}} {"text": "module type_rbf_interpolation_matrix\n#include \n use mod_kinds, only: ik, rk\n use mod_inv, only: inv\n implicit none\n\n\n type, public :: rbf_interpolation_matrix_t\n \n ! We assume the form \n ! |A 0||cb| = |sb|\n ! |B C||ce| |se|\n !\n ! where A and B are base and C is lower triangular.\n !\n ! We then can solve the system via\n !\n ! 1. Solve the dense system, A*cb = sb to obtain\n ! cb = Ainv*sb\n ! 2. Solve the lower triangular system, C*ce = se-B*cb, via forward substitution to obtain\n ! ce = Cinv*(se-B*cb)\n ! \n\n\n real(rk), allocatable :: A(:,:)\n real(rk), allocatable :: Ainv(:,:)\n real(rk), allocatable :: B(:,:)\n real(rk), allocatable :: C(:,:)\n\n logical :: is_initialized = .false.\n logical :: is_filled = .false.\n\n contains\n\n procedure :: init \n procedure :: solve\n\n end type rbf_interpolation_matrix_t\n\ncontains\n\n subroutine init(self, nnodes_base, nnodes_explicit) \n class(rbf_interpolation_matrix_t), intent(inout) :: self\n integer(ik), intent(in) :: nnodes_base\n integer(ik), intent(in), optional :: nnodes_explicit\n\n allocate(self%A(nnodes_base, nnodes_base))\n if (present(nnodes_explicit)) then\n if (nnodes_explicit>0) then\n allocate(self%B(nnodes_explicit, nnodes_base))\n allocate(self%C(nnodes_explicit, nnodes_explicit))\n end if\n end if\n\n end subroutine\n\n\n\n function solve(self, source_val) result(rbf_coeff)\n class(rbf_interpolation_matrix_t), intent(inout) :: self\n real(rk), intent(in) :: source_val(:)\n\n real(rk), allocatable :: rbf_coeff(:)\n real(rk), allocatable :: rbf_coeff_base(:), rbf_coeff_explicit(:), temp(:), rhs(:)\n real(rk), allocatable :: source_val_base(:)\n real(rk), allocatable :: source_val_explicit(:) \n\n integer(ik) :: inode_sol, inode_term, nnodes_base, nnodes_explicit\n\n if (.not. self%is_filled) call chidg_signal(FATAL, 'rbf_interpolation_matrix%solve : matrix is not filled')\n\n nnodes_base = size(self%A,1)\n ! Invert the base block\n if (.not. allocated(self%Ainv)) then\n\n self%Ainv = inv(self%A)\n\n end if\n\n ! Solve for the basely coupled RBF coefficients\n allocate(rbf_coeff_base(nnodes_base), source_val_base(nnodes_base))\n source_val_base = source_val(1:nnodes_base)\n rbf_coeff_base = matmul(self%Ainv, source_val_base)\n !rbf_coeff_base = solve_dense(self%A, source_val_base)\n \n\n\n\n\n ! Now, check if we have explicit RBF nodes, and solve if so\n if ((allocated(self%C))) then\n nnodes_explicit = size(self%C,1)\n allocate(rbf_coeff_explicit(nnodes_explicit), source_val_explicit(nnodes_explicit))\n \n temp = matmul(self%B, rbf_coeff_base)\n\n source_val_explicit = source_val(nnodes_base+1:nnodes_base+nnodes_explicit)\n rhs = source_val_explicit-temp\n\n\n rbf_coeff_explicit(1) = rhs(1)/self%C(1,1)\n do inode_sol = 2, size(source_val_explicit,1)\n\n rbf_coeff_explicit(inode_sol) = rhs(inode_sol)\n do inode_term = 1, (inode_sol-1)\n rbf_coeff_explicit(inode_sol) = rbf_coeff_explicit(inode_sol) -&\n self%C(inode_sol,inode_term)*rbf_coeff_explicit(inode_term)\n\n end do\n\n rbf_coeff_explicit(inode_sol) = rbf_coeff_explicit(inode_sol)/self%C(inode_sol, inode_sol)\n\n end do\n\n \n allocate(rbf_coeff(nnodes_base+nnodes_explicit))\n rbf_coeff(1:nnodes_base) = rbf_coeff_base\n rbf_coeff(nnodes_base+1:(nnodes_base+nnodes_explicit)) = rbf_coeff_explicit\n else\n rbf_coeff = rbf_coeff_base\n\n end if\n\n end function solve\n\n\nend module type_rbf_interpolation_matrix\n", "meta": {"hexsha": "8a9785a48f4a7782f9ae95215fdb1d68458085c8", "size": 4335, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/grid/radial_basis_functions/type_rbf_interpolation_matrix.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/grid/radial_basis_functions/type_rbf_interpolation_matrix.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/grid/radial_basis_functions/type_rbf_interpolation_matrix.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": 33.8671875, "max_line_length": 115, "alphanum_fraction": 0.5628604383, "num_tokens": 1043, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.929440403812707, "lm_q2_score": 0.7057850340255386, "lm_q1q2_score": 0.6559851270296617}} {"text": " SUBROUTINE MB03QG( DICO, STDOM, JOBU, JOBV, N, NLOW, NSUP, ALPHA,\n $ A, LDA, E, LDE, U, LDU, V, LDV, NDIM, DWORK,\n $ LDWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To reorder the diagonal blocks of a principal subpencil of an\nC upper quasi-triangular matrix pencil A-lambda*E together with\nC their generalized eigenvalues, by constructing orthogonal\nC similarity transformations UT and VT.\nC After reordering, the leading block of the selected subpencil of\nC A-lambda*E has generalized eigenvalues in a suitably defined\nC domain of interest, usually related to stability/instability in a\nC continuous- or discrete-time sense.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC DICO CHARACTER*1\nC Specifies the type of the spectrum separation to be\nC performed, as follows:\nC = 'C': continuous-time sense;\nC = 'D': discrete-time sense.\nC\nC STDOM CHARACTER*1\nC Specifies whether the domain of interest is of stability\nC type (left part of complex plane or inside of a circle)\nC or of instability type (right part of complex plane or\nC outside of a circle), as follows:\nC = 'S': stability type domain;\nC = 'U': instability type domain.\nC\nC JOBU CHARACTER*1\nC Indicates how the performed orthogonal transformations UT\nC are accumulated, as follows:\nC = 'I': U is initialized to the unit matrix and the matrix\nC UT is returned in U;\nC = 'U': the given matrix U is updated and the matrix U*UT\nC is returned in U.\nC\nC JOBV CHARACTER*1\nC Indicates how the performed orthogonal transformations VT\nC are accumulated, as follows:\nC = 'I': V is initialized to the unit matrix and the matrix\nC VT is returned in V;\nC = 'U': the given matrix V is updated and the matrix V*VT\nC is returned in V.\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The order of the matrices A, E, U, and V. N >= 0.\nC\nC NLOW, (input) INTEGER\nC NSUP (input) INTEGER\nC NLOW and NSUP specify the boundary indices for the rows\nC and columns of the principal subpencil of A - lambda*E\nC whose diagonal blocks are to be reordered.\nC 0 <= NLOW <= NSUP <= N.\nC\nC ALPHA (input) DOUBLE PRECISION\nC The boundary of the domain of interest for the eigenvalues\nC of A. If DICO = 'C', ALPHA is the boundary value for the\nC real parts of the generalized eigenvalues, while for\nC DICO = 'D', ALPHA >= 0 represents the boundary value for\nC the moduli of the generalized eigenvalues.\nC\nC A (input/output) DOUBLE PRECISION array, dimension (LDA,N)\nC On entry, the leading N-by-N part of this array must\nC contain a matrix in a real Schur form whose 1-by-1 and\nC 2-by-2 diagonal blocks between positions NLOW and NSUP\nC are to be reordered.\nC On exit, the leading N-by-N part of this array contains\nC a real Schur matrix UT' * A * VT, with the elements below\nC the first subdiagonal set to zero.\nC The leading NDIM-by-NDIM part of the principal subpencil\nC B - lambda*C, defined with B := A(NLOW:NSUP,NLOW:NSUP),\nC C := E(NLOW:NSUP,NLOW:NSUP), has generalized eigenvalues\nC in the domain of interest and the trailing part of this\nC subpencil has generalized eigenvalues outside the domain\nC of interest.\nC The domain of interest for eig(B,C), the generalized\nC eigenvalues of the pair (B,C), is defined by the\nC parameters ALPHA, DICO and STDOM as follows:\nC For DICO = 'C':\nC Real(eig(B,C)) < ALPHA if STDOM = 'S';\nC Real(eig(B,C)) > ALPHA if STDOM = 'U'.\nC For DICO = 'D':\nC Abs(eig(B,C)) < ALPHA if STDOM = 'S';\nC Abs(eig(B,C)) > ALPHA if STDOM = 'U'.\nC\nC LDA INTEGER\nC The leading dimension of the array A. LDA >= MAX(1,N).\nC\nC E (input/output) DOUBLE PRECISION array, dimension (LDE,N)\nC On entry, the leading N-by-N part of this array must\nC contain a matrix in an upper triangular form.\nC On exit, the leading N-by-N part of this array contains an\nC upper triangular matrix UT' * E * VT, with the elements\nC below the diagonal set to zero.\nC The leading NDIM-by-NDIM part of the principal subpencil\nC B - lambda*C, defined with B := A(NLOW:NSUP,NLOW:NSUP)\nC C := E(NLOW:NSUP,NLOW:NSUP) has generalized eigenvalues\nC in the domain of interest and the trailing part of this\nC subpencil has generalized eigenvalues outside the domain\nC of interest (see description of A).\nC\nC LDE INTEGER\nC The leading dimension of the array E. LDE >= MAX(1,N).\nC\nC U (input/output) DOUBLE PRECISION array, dimension (LDU,N)\nC On entry with JOBU = 'U', the leading N-by-N part of this\nC array must contain a transformation matrix (e.g., from a\nC previous call to this routine).\nC On exit, if JOBU = 'U', the leading N-by-N part of this\nC array contains the product of the input matrix U and the\nC orthogonal matrix UT used to reorder the diagonal blocks\nC of A - lambda*E.\nC On exit, if JOBU = 'I', the leading N-by-N part of this\nC array contains the matrix UT of the performed orthogonal\nC transformations.\nC Array U need not be set on entry if JOBU = 'I'.\nC\nC LDU INTEGER\nC The leading dimension of the array U. LDU >= MAX(1,N).\nC\nC V (input/output) DOUBLE PRECISION array, dimension (LDV,N)\nC On entry with JOBV = 'U', the leading N-by-N part of this\nC array must contain a transformation matrix (e.g., from a\nC previous call to this routine).\nC On exit, if JOBV = 'U', the leading N-by-N part of this\nC array contains the product of the input matrix V and the\nC orthogonal matrix VT used to reorder the diagonal blocks\nC of A - lambda*E.\nC On exit, if JOBV = 'I', the leading N-by-N part of this\nC array contains the matrix VT of the performed orthogonal\nC transformations.\nC Array V need not be set on entry if JOBV = 'I'.\nC\nC LDV INTEGER\nC The leading dimension of the array V. LDV >= MAX(1,N).\nC\nC NDIM (output) INTEGER\nC The number of generalized eigenvalues of the selected\nC principal subpencil lying inside the domain of interest.\nC If NLOW = 1, NDIM is also the dimension of the deflating\nC subspace corresponding to the generalized eigenvalues of\nC the leading NDIM-by-NDIM subpencil. In this case, if U and\nC V are the orthogonal transformation matrices used to\nC compute and reorder the generalized real Schur form of the\nC pair (A,E), then the first NDIM columns of V form an\nC orthonormal basis for the above deflating subspace.\nC\nC Workspace\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0, DWORK(1) returns the optimal value\nC of LDWORK.\nC\nC LDWORK INTEGER\nC The length of the array DWORK. LDWORK >= 1, and if N > 1,\nC LDWORK >= 4*N + 16.\nC\nC If LDWORK = -1, then a workspace query is assumed; the\nC routine only calculates the optimal size of the DWORK\nC array, returns this value as the first entry of the DWORK\nC array, and no error message related to LDWORK is issued by\nC XERBLA.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value;\nC = 1: A(NLOW,NLOW-1) is nonzero, i.e., A(NLOW,NLOW) is not\nC the leading element of a 1-by-1 or 2-by-2 diagonal\nC block of A, or A(NSUP+1,NSUP) is nonzero, i.e.,\nC A(NSUP,NSUP) is not the bottom element of a 1-by-1\nC or 2-by-2 diagonal block of A;\nC = 2: two adjacent blocks are too close to swap (the\nC problem is very ill-conditioned).\nC\nC METHOD\nC\nC Given an upper quasi-triangular matrix pencil A - lambda*E with\nC 1-by-1 or 2-by-2 diagonal blocks, the routine reorders its\nC diagonal blocks along with its eigenvalues by performing an\nC orthogonal equivalence transformation UT'*(A - lambda*E)* VT.\nC The column transformations UT and VT are also performed on the\nC given (initial) transformations U and V (resulted from a\nC possible previous step or initialized as identity matrices).\nC After reordering, the generalized eigenvalues inside the region\nC specified by the parameters ALPHA, DICO and STDOM appear at the\nC top of the selected diagonal subpencil between positions NLOW and\nC NSUP. In other words, lambda(A(Select,Select),E(Select,Select))\nC are ordered such that lambda(A(Inside,Inside),E(Inside,Inside))\nC are inside, and lambda(A(Outside,Outside),E(Outside,Outside)) are\nC outside the domain of interest, where Select = NLOW:NSUP,\nC Inside = NLOW:NLOW+NDIM-1, and Outside = NLOW+NDIM:NSUP.\nC If NLOW = 1, the first NDIM columns of V*VT span the corresponding\nC right deflating subspace of (A,E).\nC\nC REFERENCES\nC\nC [1] Stewart, G.W.\nC HQR3 and EXCHQZ: FORTRAN subroutines for calculating and\nC ordering the eigenvalues of a real upper Hessenberg matrix.\nC ACM TOMS, 2, pp. 275-280, 1976.\nC\nC NUMERICAL ASPECTS\nC 3\nC The algorithm requires less than 4*N operations.\nC\nC CONTRIBUTOR\nC\nC A. Varga, German Aerospace Center, DLR Oberpfaffenhofen,\nC October 2002. Based on the RASP/BIMASC routine GSEOR1.\nC\nC REVISIONS\nC\nC V. Sima, Dec. 2016.\nC\nC KEYWORDS\nC\nC Eigenvalues, invariant subspace, orthogonal transformation, real\nC Schur form, equivalence transformation.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ONE, ZERO\n PARAMETER ( ONE = 1.0D0, ZERO = 0.0D0 )\nC .. Scalar Arguments ..\n CHARACTER DICO, JOBU, JOBV, STDOM\n INTEGER INFO, LDA, LDE, LDU, LDV, LDWORK, N, NDIM, NLOW,\n $ NSUP\n DOUBLE PRECISION ALPHA\nC .. Array Arguments ..\n DOUBLE PRECISION A(LDA,*), DWORK(*), E(LDE,*), U(LDU,*), V(LDV,*)\nC .. Local Scalars ..\n LOGICAL DISCR, LQUERY, LSTDOM\n INTEGER IB, L, LM1, MINWRK, NUP\n DOUBLE PRECISION ALPHAI(2), ALPHAR(2), BETA(2)\n DOUBLE PRECISION TLAMBD, TOLE, X\nC .. External Functions ..\n LOGICAL LSAME\n DOUBLE PRECISION DLAMCH, DLANTR, DLAPY2\n EXTERNAL DLAMCH, DLANTR, DLAPY2, LSAME\nC .. External Subroutines ..\n EXTERNAL DLASET, DTGEXC, MB03QW, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC ABS, MAX\nC .. Executable Statements ..\nC\n INFO = 0\n DISCR = LSAME( DICO, 'D' )\n LSTDOM = LSAME( STDOM, 'S' )\nC\nC Check input scalar arguments.\nC\n IF( .NOT. ( LSAME( DICO, 'C' ) .OR. DISCR ) ) THEN\n INFO = -1\n ELSE IF( .NOT. ( LSTDOM .OR. LSAME( STDOM, 'U' ) ) ) THEN\n INFO = -2\n ELSE IF( .NOT. ( LSAME( JOBU, 'I' ) .OR.\n $ LSAME( JOBU, 'U' ) ) ) THEN\n INFO = -3\n ELSE IF( .NOT. ( LSAME( JOBV, 'I' ) .OR.\n $ LSAME( JOBV, 'U' ) ) ) THEN\n INFO = -4\n ELSE IF( N.LT.0 ) THEN\n INFO = -5\n ELSE IF( NLOW.LT.0 ) THEN\n INFO = -6\n ELSE IF( NSUP.LT.NLOW .OR. N.LT.NSUP ) THEN\n INFO = -7\n ELSE IF( DISCR .AND. ALPHA.LT.ZERO ) THEN\n INFO = -8\n ELSE IF( LDA.LT.MAX( 1, N ) ) THEN\n INFO = -10\n ELSE IF( LDE.LT.MAX( 1, N ) ) THEN\n INFO = -12\n ELSE IF( LDU.LT.MAX( 1, N ) ) THEN\n INFO = -14\n ELSE IF( LDV.LT.MAX( 1, N ) ) THEN\n INFO = -16\n ELSE\n LQUERY = LDWORK.EQ.-1\n IF( N.LE.1 ) THEN\n MINWRK = 1\n ELSE\n MINWRK = 4*N + 16\n END IF\n IF( LDWORK.LT.MINWRK .AND. .NOT.LQUERY ) THEN\n INFO = -19\n END IF\n END IF\nC\n IF( INFO.NE.0 ) THEN\nC\nC Error return.\nC\n CALL XERBLA( 'MB03QG', -INFO )\n RETURN\n ELSE IF( LQUERY ) THEN\n DWORK(1) = MINWRK\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n NDIM = 0\n IF( NSUP.EQ.0 )\n $ RETURN\nC\n IF( NLOW.GT.1 ) THEN\n IF( A(NLOW,NLOW-1).NE.ZERO )\n $ INFO = 1\n END IF\n IF( NSUP.LT.N ) THEN\n IF( A(NSUP+1,NSUP).NE.ZERO )\n $ INFO = 1\n END IF\n IF( INFO.NE.0 )\n $ RETURN\nC\nC Initialize U with an identity matrix if necessary.\nC\n IF( LSAME( JOBU, 'I' ) )\n $ CALL DLASET( 'Full', N, N, ZERO, ONE, U, LDU )\nC\nC Initialize V with an identity matrix if necessary.\nC\n IF( LSAME( JOBV, 'I' ) )\n $ CALL DLASET( 'Full', N, N, ZERO, ONE, V, LDV )\nC\nC Compute zero tolerance for the diagonal elements of matrix E.\nC\n TOLE = DLAMCH( 'Epsilon' ) *\n $ DLANTR( '1', 'Upper', 'Non-unit', N, N, E, LDE, DWORK )\nC\n L = NSUP\n NUP = NSUP\nC\nC NUP is the minimal value such that the subpencil\nC A(i,j)-lambda*E(i,j), with NUP+1 <= i,j <= NSUP contains no\nC generalized eigenvalues inside the domain of interest.\nC L is such that all generalized eigenvalues of the subpencil\nC A(i,j)-lambda*E(i,j) with L <= i,j <= NUP lie inside the\nC domain of interest.\nC\nC WHILE( L >= NLOW ) DO\nC\n 10 CONTINUE\n IF( L.GE.NLOW ) THEN\n IB = 1\n IF( L.GT.NLOW ) THEN\n LM1 = L - 1\n IF( A(L,LM1).NE.ZERO ) THEN\n CALL MB03QW( N, LM1, A, LDA, E, LDE, U, LDU, V, LDV,\n $ ALPHAR, ALPHAI, BETA, INFO )\n IF( A(L,LM1).NE.ZERO )\n $ IB = 2\n END IF\n END IF\n IF( DISCR ) THEN\n IF( IB.EQ.1 ) THEN\n TLAMBD = ABS( A(L,L) )\n X = ABS( E(L,L) )\n ELSE\n TLAMBD = DLAPY2( ALPHAR(1), ALPHAI(1) )\n X = ABS( BETA(1) )\n END IF\n ELSE\n IF( IB.EQ.1 ) THEN\n X = E(L,L)\n IF( X.LT.ZERO ) THEN\n TLAMBD = -A(L,L)\n X = -X\n ELSE\n TLAMBD = A(L,L)\n END IF\n ELSE\n TLAMBD = ALPHAR(1)\n X = BETA(1)\n IF( X.LT.ZERO ) THEN\n TLAMBD = -TLAMBD\n X = -X\n END IF\n END IF\n END IF\n IF(( LSTDOM .AND. TLAMBD.LT.ALPHA*X .AND. X.GT.TOLE ) .OR.\n $ ( .NOT.LSTDOM .AND. TLAMBD.GT.ALPHA*X ) )\n $ THEN\n NDIM = NDIM + IB\n L = L - IB\n ELSE\n IF( NDIM.NE.0 ) THEN\n CALL DTGEXC( .TRUE., .TRUE., N, A, LDA, E, LDE, U, LDU,\n $ V, LDV, L, NUP, DWORK, LDWORK, INFO )\n IF( INFO.NE.0 ) THEN\n INFO = 2\n RETURN\n END IF\n NUP = NUP - 1\n L = L - 1\n ELSE\n NUP = NUP - IB\n L = L - IB\n END IF\n END IF\n GO TO 10\n END IF\nC\nC END WHILE 10\nC\n DWORK(1) = MINWRK\n RETURN\nC *** Last line of MB03QG ***\n END\n", "meta": {"hexsha": "d204058f34cca6c19d64f3ed6d0f8f95230f5294", "size": 16296, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB03QG.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB03QG.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB03QG.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 38.1639344262, "max_line_length": 72, "alphanum_fraction": 0.5516691213, "num_tokens": 4617, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403959948494, "lm_q2_score": 0.7057850340255386, "lm_q1q2_score": 0.6559851215119349}} {"text": "module geomagnetic\n\n!> transformations and data relevant to converting geographic to geomagnetic coordinates\n\nuse phys_consts, only: wp,Re,pi\nimplicit none (type, external)\n\n\n! magnetic pole location in geographic coordinates\nreal(wp), parameter :: thetan=11*pi/180\nreal(wp), parameter :: phin=289*pi/180\n\nprivate\npublic :: geomag2geog, geog2geomag, r2alt, alt2r\n\ncontains\n\n!> convert geomagnetic coordinates to geographic\nelemental subroutine geog2geomag(glon,glat,phi,theta)\n real(wp), intent(in) :: glon,glat\n real(wp), intent(out) :: phi,theta\n real(wp) :: glonwrap\n real(wp) :: thetag\n real(wp) :: phig\n real(wp) :: argtmp,alpha\n\n glonwrap=mod(glon,360._wp)\n thetag = pi/2 - glat*pi/180\n phig = glonwrap*pi/180\n\n theta = acos(cos(thetag)*cos(thetan)+sin(thetag)*sin(thetan)*cos(phig-phin))\n argtmp = (cos(thetag)-cos(theta)*cos(thetan))/(sin(theta)*sin(thetan))\n alpha = acos( max(min(argtmp,1._wp),-1._wp) )\n\n if (phin>phig .and. phin-phig>pi .or. phin convert geographic coordinates to geomagnetic; do not use at the magnetic pole!!!\n\nelemental subroutine geomag2geog(phi,theta,glon,glat)\n real(wp), intent(in) :: phi,theta\n real(wp), intent(out) :: glon,glat\n real(wp) :: thetag2p,thetag2\n real(wp) :: beta\n real(wp) :: phig2,phiwrap\n real(wp) :: argtmp\n\n phiwrap=mod(phi,2*pi)\n thetag2p=acos(cos(theta)*cos(thetan)-sin(theta)*sin(thetan)*cos(phiwrap))\n argtmp=(cos(theta)-cos(thetag2p)*cos(thetan))/(sin(thetag2p)*sin(thetan))\n beta=acos( max(min(argtmp,1._wp),-1._wp) )\n\n if (phiwrap>pi) then\n phig2=phin-beta\n else\n phig2=phin+beta\n end if\n phig2=mod(phig2,2*pi)\n thetag2=pi/2-thetag2p\n\n glon=phig2*180._wp/pi\n glat=thetag2*180._wp/pi\nend subroutine geomag2geog\n\n\n!> convert geocentric distance into altitude (assume spherical Earth but could use other model)\nelemental function r2alt(r) result(alt)\n real(wp), intent(in) :: r\n real(wp) :: alt\n\n alt=r-Re\nend function r2alt\n\n\n!> convert altitude to geocentric distance\nelemental function alt2r(alt) result(r)\n real(wp), intent(in) :: alt\n real(wp) :: r\n\n r=alt+Re\nend function alt2r\n\nend module geomagnetic\n", "meta": {"hexsha": "f4c3db9089e921e72f467ae00d734fad90ea5af8", "size": 2222, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/numerical/coord/geomagnetic.f90", "max_stars_repo_name": "scottaiton/gemini3d", "max_stars_repo_head_hexsha": "21f59aabb4d842d587dbeba428ba7353905e063e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2020-09-17T05:08:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-24T18:22:06.000Z", "max_issues_repo_path": "src/numerical/coord/geomagnetic.f90", "max_issues_repo_name": "scottaiton/gemini3d", "max_issues_repo_head_hexsha": "21f59aabb4d842d587dbeba428ba7353905e063e", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 52, "max_issues_repo_issues_event_min_datetime": "2020-07-23T13:55:59.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-19T13:59:43.000Z", "max_forks_repo_path": "src/numerical/coord/geomagnetic.f90", "max_forks_repo_name": "scottaiton/gemini3d", "max_forks_repo_head_hexsha": "21f59aabb4d842d587dbeba428ba7353905e063e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 11, "max_forks_repo_forks_event_min_datetime": "2020-08-20T12:07:06.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-14T13:03:04.000Z", "avg_line_length": 24.9662921348, "max_line_length": 95, "alphanum_fraction": 0.7088208821, "num_tokens": 753, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404018582427, "lm_q2_score": 0.7057850278370112, "lm_q1q2_score": 0.6559851198983627}} {"text": "module kernel_operators_mod\n\nuse constants_mod\n\ncontains\n\nsubroutine kernel_operators_lagrangeProlongationMatrixDGFV(N, dgnodes, fvnodes, matM, matP)\n\n use lagrange_mod, only: lagrange_polynomial\n\n integer, intent(in) :: N\n real(dp), intent(in) :: dgnodes(N)\n real(dp), intent(in) :: fvnodes(N)\n real(dp), intent(out) :: matM(N,N,N)\n real(dp), intent(out) :: matP(N,N,N)\n\n integer :: i,j,k\n\n do k = 1,N\n do j = 1,N\n do i = 1,N\n matM(i,j,k) = lagrange_polynomial(N, dgnodes, i, -1.0_dp)*lagrange_polynomial(N, dgnodes, j, fvnodes(k))\n matP(i,j,k) = lagrange_polynomial(N, dgnodes, i, 1.0_dp)*lagrange_polynomial(N, dgnodes, j, fvnodes(k))\n end do\n end do\n end do\n\nend subroutine\n\nsubroutine kernel_operators_DiffMatrix(N, dgnodes, mat)\n\n use utils_mod, only: krondelta\n use interpol_mod, only: DiffMatrix\n\n integer, intent(in) :: N\n real(dp), intent(in) :: dgnodes(N_NODES)\n real(dp), intent(out) :: mat(N_NODES,N_NODES)\n\n real(dp) :: DiffMat(N_NODES,N_NODES)\n\n real(dp) :: p,q\n integer :: i,j\n\n DiffMat = 0.0\n call DiffMatrix(N-1, dgnodes(1:N), DiffMat(1:N,1:N))\n\n p = real(N,dp)\n q = real(N,dp)\n\n mat = 0.0\n do j = 1,N_NODES; do i = 1,N_NODES\n mat(i,j) = krondelta(ceiling(i/p),ceiling(j/q)) * DiffMat(i-floor((i-1)/p)*N, j-floor((j-1)/q)*N)\n end do; end do\n\n !! correct element length\n mat = real(N_NODES,dp)/real(N,dp)*mat\n\nend subroutine\n\n# if 0\nsubroutine kernel_operators_StrongDGDiffMatrix(N, dgnodes, dgweights, mat)\n\n use utils_mod, only: krondelta\n use interpol_mod, only: DiffMatrix\n\n integer, intent(in) :: N\n real(dp), intent(in) :: dgnodes(N_NODES)\n real(dp), intent(in) :: dgweights(N_NODES)\n real(dp), intent(out) :: mat(N_NODES,N_NODES)\n\n real(dp) :: MassMat(N_NODES,N_NODES)\n real(dp) :: DiffMat(N_NODES,N_NODES)\n\n real(dp) :: p,q\n integer :: i,j\n\n DiffMat = 0.0\n call DiffMatrix(N-1, dgnodes(1:N), DiffMat(1:N,1:N))\n\n p = real(N,dp)\n q = real(N,dp)\n\n mat = 0.0\n do j = 1,N_NODES; do i = 1,N_NODES\n mat(i,j) = krondelta(ceiling(i/p),ceiling(j/q)) * DiffMat(i-floor((i-1)/p)*N, j-floor((j-1)/q)*N)\n end do; end do\n\n !! correct element length\n mat = real(N_NODES,dp)/real(N,dp)*mat\n\nend subroutine\n# endif\n\nsubroutine kernel_operators_WeakDGDiffMatrix(N, dgnodes, dgweights, mat)\n\n use utils_mod, only: krondelta\n use interpol_mod, only: DiffMatrix\n\n integer, intent(in) :: N\n real(dp), intent(in) :: dgnodes(N)\n real(dp), intent(in) :: dgweights(N)\n real(dp), intent(out) :: mat(N_NODES,N_NODES)\n\n real(dp) :: temp(N,N)\n real(dp) :: DiffMat(N,N)\n\n real(dp) :: p,q\n integer :: i,j\n\n DiffMat = 0.0\n call DiffMatrix(N-1, dgnodes, DiffMat)\n\n temp = 0.0\n forall (j = 1:N, i = 1:N) temp(i,j) = -2 * dgweights(j)/dgweights(i) * DiffMat(j,i)\n\n p = real(N,dp)\n q = real(N,dp)\n\n mat = 0.0\n do j = 1,N_NODES; do i = 1,N_NODES\n mat(i,j) = krondelta(ceiling(i/p),ceiling(j/q)) * temp(i-floor((i-1)/p)*N, j-floor((j-1)/q)*N)\n end do; end do\n\n !! correct element length\n !mat = real(N_NODES,dp)/real(N,dp)*mat\n mat = -mat/real(N,dp)\n\n# if 0\n write (*,*) 'nodes', qq, dgnodes\n write (*,*) 'weights', qq, dgweights\n\n write (*,*) qq, 'Riffdmat'\n do i = 1,N_NODES\n write (*,1001) diffrmat(i,:)\n end do\n write (*,*)\n\n\n write (*,*) qq, 'xDiffrMat'\n do i = 1,N_NODES\n write (*,1001) xDiffrMat(i,:,qq)\n end do\n write (*,*)\n\n1001 format(PP_N_NODES(f12.3))\n# endif\n\nend subroutine\n\nsubroutine kernel_operators_WeakDGDiffMatrixV(N, dgnodes, dgweights, mat)\n\n use utils_mod, only: krondelta\n use interpol_mod, only: DiffMatrix\n\n integer, intent(in) :: N\n real(dp), intent(in) :: dgnodes(N)\n real(dp), intent(in) :: dgweights(N)\n real(dp), intent(out) :: mat(N,N)\n\n real(dp) :: temp(N,N)\n real(dp) :: DiffMat(N,N)\n\n real(dp) :: p,q\n integer :: i,j\n\n DiffMat = 0.0\n call DiffMatrix(N-1, dgnodes, DiffMat)\n\n temp = 0.0\n forall (j = 1:N, i = 1:N) temp(i,j) = -2 * dgweights(j)/dgweights(i) * DiffMat(j,i)\n\n mat = temp\n\nend subroutine\n\nsubroutine kernel_operators_AverageMatrix(N, mat)\n\n use utils_mod, only: krondelta\n\n integer, intent(in) :: N\n real(dp), intent(out) :: mat(N_NODES,N_NODES)\n\n real(dp) :: p,q\n integer :: i,j\n\n p = real(N,dp)\n q = real(N,dp)\n\n mat = 0.0\n do j = 1,N_NODES; do i = 1,N_NODES\n mat(i,j) = 1/real(N,dp) * krondelta(ceiling(i/p),ceiling(j/q))\n end do; end do\n\n# if 0\n write (*,*) 'AvgMat', qq\n do i = 1,N_NODES\n write (*,1001) AvgMat(i,:,qq)\n end do\n write (*,*)\n\n1001 format(12(f7.2))\n1002 format(24(f12.3))\n# endif\n\nend subroutine\n\n!! --------------------------------------------------------------------- !!\n!! Modal space operators\n\nsubroutine kernel_operators_ModalTrafoMatrix(N, dgnodes, toModal, toNodal)\n\n use utils_mod, only: krondelta\n use interpol_mod, only: mkVanderMondeMatrix\n\n integer, intent(in) :: N\n real(dp), intent(in) :: dgnodes(N)\n\n real(dp), intent(out) :: toModal(N_NODES,N_NODES)\n real(dp), intent(out) :: toNodal(N_NODES,N_NODES)\n\n real(dp) :: toNodal_(N,N)\n real(dp) :: toModal_(N,N)\n\n real(dp) :: p,q\n integer :: i,j\n \n p = real(N,dp)\n q = real(N,dp)\n\n toNodal_ = 0.0\n toModal_ = 0.0\n call mkVanderMondeMatrix(n, dgnodes, toNodal_, toModal_)\n\n toNodal = 0\n toModal = 0\n do j = 1,N_NODES; do i = 1,N_NODES\n toNodal(i,j) = krondelta(ceiling(i/p),ceiling(j/q)) * toNodal_(i-floor((i-1)/p)*N, j-floor((j-1)/q)*N)\n toModal(i,j) = krondelta(ceiling(i/p),ceiling(j/q)) * toModal_(i-floor((i-1)/p)*N, j-floor((j-1)/q)*N)\n end do; end do\nend subroutine\n\nsubroutine kernel_operators_ModalTrafoMatrix2(N, dgnodes, toModal, toNodal)\n\n use interpol_mod, only: mkVanderMondeMatrix\n\n integer, intent(in) :: N\n real(dp), intent(in) :: dgnodes(N)\n real(dp), intent(out) :: toModal(N,N)\n real(dp), intent(out) :: toNodal(N,N)\n\n toNodal = 0.0\n toModal = 0.0\n call mkVanderMondeMatrix(n, dgnodes, toNodal, toModal)\n\nend subroutine\n\n!! --------------------------------------------------------------------- !!\n!! trafo operators: DG <-> FV\n\nsubroutine kernel_operators_dg2fvMatrix(N, M, dgnodes, dgweights, mat)\n\n use utils_mod, only: krondelta\n use subcellfv_mod, only: subcellfv_vanderMondeMatrix\n\n integer, intent(in) :: N,M\n real(dp), intent(in) :: dgnodes(N)\n real(dp), intent(in) :: dgweights(N)\n real(dp), intent(out) :: mat(M,M)\n\n real(dp) :: temp(N,N)\n\n real(dp) :: p,q\n integer :: i,j\n \n temp = 0.0\n call subcellfv_vanderMondeMatrix(N, N, dgnodes, dgweights, temp)\n \n p = real(N,dp)\n q = real(N,dp)\n\n mat = 0.0\n do j = 1,M; do i = 1,M\n mat(i,j) = krondelta(ceiling(i/p),ceiling(j/q)) * temp(i-floor((i-1)/p)*N, j-floor((j-1)/q)*N)\n end do; end do\n\nend subroutine\n\nsubroutine kernel_operators_dg2fvMatrixV(N, M, dgnodes, dgweights, mat)\n\n use utils_mod, only: krondelta\n use subcellfv_mod, only: subcellfv_vanderMondeMatrix\n\n integer, intent(in) :: N,M\n real(dp), intent(in) :: dgnodes(N)\n real(dp), intent(in) :: dgweights(N)\n real(dp), intent(out) :: mat(M,N)\n\n real(dp) :: p,q\n integer :: i,j\n \n mat = 0.0\n call subcellfv_vanderMondeMatrix(N, M, dgnodes, dgweights, mat)\n \nend subroutine\n\nsubroutine kernel_operators_refineMatrix(N, dgnodes, dgweights, mat)\n\n use utils_mod, only: krondelta\n use subcellfv_mod, only: subcellfv_vanderMondeMatrix\n\n integer, intent(in) :: N\n real(dp), intent(in) :: dgnodes(N)\n real(dp), intent(in) :: dgweights(N)\n real(dp), intent(out) :: mat(2*N_NODES,N_NODES)\n\n real(dp) :: temp(2*N,N)\n\n real(dp) :: p,q\n integer :: i,j\n \n temp = 0.0\n call subcellfv_vanderMondeMatrix(N, 2*N, dgnodes, dgweights, temp)\n \n p = real(2*N,dp)\n q = real(N,dp)\n\n mat = 0.0\n do j = 1,N_NODES; do i = 1,2*N_NODES\n mat(i,j) = krondelta(ceiling(i/p),ceiling(j/q)) * temp(i-floor((i-1)/p)*2*N, j-floor((j-1)/q)*N)\n end do; end do\n\nend subroutine\n\nsubroutine kernel_operators_coarsenMatrix(N, dgnodes, dgweights, mat)\n\n use utils_mod, only: krondelta\n use subcellfv_mod, only: subcellfv_vanderMondeMatrix\n\n integer, intent(in) :: N\n real(dp), intent(in) :: dgnodes(N)\n real(dp), intent(in) :: dgweights(N)\n real(dp), intent(out) :: mat(N_NODES/2,N_NODES)\n\n real(dp) :: temp(N/2,N)\n\n real(dp) :: p,q\n integer :: i,j\n \n temp = 0.0\n call subcellfv_vanderMondeMatrix(N, N/2, dgnodes, dgweights, temp)\n \n p = real(N/2,dp)\n q = real(N,dp)\n\n mat = 0.0\n do j = 1,N_NODES; do i = 1,N_NODES/2\n mat(i,j) = krondelta(ceiling(i/p),ceiling(j/q)) * temp(i-floor((i-1)/p)*N/2, j-floor((j-1)/q)*N)\n end do; end do\n\nend subroutine\n\nsubroutine kernel_operators_overMatrix(N, M, nodesA, nodesB, mat)\n\n use lagrange_mod, only: lagrange_VanderMondeMatrix\n\n integer, intent(in) :: N, M\n real(dp), intent(in) :: nodesA(N)\n real(dp), intent(in) :: nodesB(M)\n real(dp), intent(out) :: mat(M,N)\n\n call lagrange_VanderMondeMatrix(N, M, nodesA, nodesB, mat)\n \nend subroutine\n\nsubroutine kernel_operators_revoMatrix(N, M, dgnodes, dgweights, mat)\n\n use utils_mod, only: krondelta\n use subcellfv_mod, only: subcellfv_vanderMondeMatrix\n\n integer, intent(in) :: N, M\n real(dp), intent(in) :: dgnodes(N)\n real(dp), intent(in) :: dgweights(N)\n real(dp), intent(out) :: mat(M,N)\n\n real(dp) :: temp(M,N)\n\n real(dp) :: p,q\n integer :: i,j\n \n call subcellfv_vanderMondeMatrix(N, M, dgnodes, dgweights, mat)\n \n !p = real(dp)(M)\n !q = real(dp)(N)\n\n !mat = 0.0\n !do j = 1,N; do i = 1,M\n ! mat(i,j) = krondelta(ceiling(i/p),ceiling(j/q)) * temp(i-floor((i-1)/p)*M, j-floor((j-1)/q)*N)\n !end do; end do\n\nend subroutine\n\nsubroutine kernel_operators_interpolateBoundaryFVMatrix(N, dgnodes, fvnodes, mat)\n\n use utils_mod, only: krondelta\n use lagrange_mod, only: lagrange_polynomial\n\n integer, intent(in) :: N\n real(dp), intent(in) :: dgnodes(N)\n real(dp), intent(in) :: fvnodes(N)\n real(dp), intent(out) :: mat(N_NODES,N_NODES)\n\n real(dp) :: temp(N,N)\n\n real(dp) :: p,q\n integer :: i,j\n\n temp = 0.0\n do j = 1,N; do i = 1,N\n temp(i,j) = lagrange_polynomial(n, dgnodes, i, fvnodes(j))\n end do; end do\n\n p = real(N,dp)\n q = real(N,dp)\n\n mat = 0.0\n do j = 1,N_NODES; do i = 1,N_NODES\n mat(i,j) = krondelta(ceiling(i/p),ceiling(j/q)) * temp(i-floor((i-1)/p)*n, j-floor((j-1)/q)*n)\n end do; end do\n\n# if 0\n write (*,*) qq, 'dg2fvMat'\n do i = 1,N_NODES\n write (*,1001) dg2fvMat(i,:,qq)\n end do\n write (*,*)\n\n write (*,*) qq, 'fv2dgMat'\n do i = 1,N_NODES\n write (*,1001) fv2dgMat(i,:,qq)\n end do\n write (*,*)\n1001 format(PP_N_NODES(f12.3))\n1002 format(24(f12.3))\n# endif\n\nend subroutine\n\nsubroutine kernel_operators_interpolateBoundaryFVMatrix3(N, dgnodes, mat)\n\n use utils_mod, only: krondelta\n use utils_mod, only: eyeproduct\n use lagrange_mod, only: lagrange_polynomial\n use interpol_mod, only: EquidistAndInterfaceNodes_3times\n\n integer, intent(in) :: N\n real(dp), intent(in) :: dgnodes(N)\n real(dp), intent(out) :: mat(3*N_NODES,N_NODES)\n\n real(dp) :: temp(3*N,N)\n real(dp) :: itfnodes(3*N)\n real(dp) :: itfweights(3*N)\n\n integer :: i,j\n\n call EquidistAndInterfaceNodes_3times(3*N, itfnodes, itfweights)\n\n do i = 1,3*N; do j = 1,N\n temp(i,j) = lagrange_polynomial(n, dgnodes, j, itfnodes(i))\n end do; end do\n\n mat = eyeproduct(N_NODES/N,temp)\n\n# if 0\n write (*,*) 'lagriptlMat3',N\n do i = 1,3*N_NODES\n write (*,'(8(ES12.4))') mat(i,:)\n end do\n write (*,*)\n# endif\n\nend subroutine\n\nsubroutine kernel_operators_interpolateBoundaryDGMatrix(N, nodes, MatM, MatP)\n\n use utils_mod, only: krondelta\n use lagrange_mod, only: lagrange_polynomial\n use interpol_mod, only: InterfaceNodes\n\n integer, intent(in) :: N\n real(dp), intent(in) :: nodes(N)\n real(dp), intent(out) :: matM(N_NODES-1,N_NODES)\n real(dp), intent(out) :: matP(N_NODES-1,N_NODES)\n\n real(dp) :: tempM(N,N)\n real(dp) :: tempP(N,N)\n\n real(dp) :: p,q\n integer :: i,j\n\n real(dp), dimension(N) :: xL,xC,xR\n\n call InterfaceNodes(N,xL,xC,xR)\n\n tempM = 0.0\n tempP = 0.0\n !do i = 1,N; do j = 1,N\n do j = 1,N\n tempM(1,j) = lagrange_polynomial(N, nodes, j, -1.0_dp)\n tempP(N,j) = lagrange_polynomial(N, nodes, j, 1.0_dp)\n\n !tempM(i,j) = lagrange_polynomial(N, nodes, j, xL(i))\n !tempP(i,j) = lagrange_polynomial(N, nodes, j, xR(i))\n end do\n\n p = real(N,dp)\n q = real(N,dp)\n\n matM = 0.0\n matP = 0.0\n\n do i = 2,N_NODES; do j = 1,N_NODES\n matM(i-1,j) = krondelta(ceiling(i/p),ceiling(j/q)) * tempM(i-floor((i-1)/p)*n, j-floor((j-1)/q)*n)\n end do; end do\n\n do i = 1,N_NODES-1; do j = 1,N_NODES\n matP(i,j) = krondelta(ceiling(i/p),ceiling(j/q)) * tempP(i-floor((i-1)/p)*n, j-floor((j-1)/q)*n)\n end do; end do\n\n# if 1\n write (*,*) 'lagritplMatM', N\n do i = 1,N_NODES-1\n write (*,'(8(ES12.4))') matM(i,:)\n end do\n write (*,*)\n\n write (*,*) 'lagritplMatP', N\n do i = 1,N_NODES-1\n write (*,'(8(ES12.4))') matP(i,:)\n end do\n write (*,*)\n# endif\n\nend subroutine\n\nsubroutine kernel_operators_interpolateBoundaryDGMatrixV(N, nodes, MatM, MatP)\n\n use utils_mod, only: krondelta\n use lagrange_mod, only: lagrange_polynomial\n\n integer, intent(in) :: N\n real(dp), intent(in) :: nodes(N)\n real(dp), intent(out) :: matM(N_NODES-1,N_NODES)\n real(dp), intent(out) :: matP(N_NODES-1,N_NODES)\n\n real(dp) :: tempM(N,N)\n real(dp) :: tempP(N,N)\n\n real(dp) :: p,q\n integer :: i,j\n\n tempM = 0.0\n tempP = 0.0\n do j = 1,N\n tempM(1,j) = lagrange_polynomial(N, nodes, j, -1.0_dp)\n tempP(N,j) = lagrange_polynomial(N, nodes, j, 1.0_dp)\n end do\n\n p = real(N,dp)\n q = real(N,dp)\n\n matM = 0.0\n matP = 0.0\n\n do i = 2,N_NODES-1; do j = 1,N_NODES\n matM(i-1,j) = krondelta(ceiling(i/p),ceiling(j/q)) * tempM(i-floor((i-1)/p)*n, j-floor((j-1)/q)*n)\n end do; end do\n\n do i = 1,N_NODES-1; do j = 1,N_NODES\n matP(i,j) = krondelta(ceiling(i/p),ceiling(j/q)) * tempP(i-floor((i-1)/p)*n, j-floor((j-1)/q)*n)\n end do; end do\n\n# if 1\n write (*,*) 'lagritplMatM', N\n do i = 1,N_NODES-1\n write (*,'(8(ES12.4))') matM(i,:)\n end do\n write (*,*)\n\n write (*,*) 'lagritplMatP', N\n do i = 1,N_NODES-1\n write (*,'(8(ES12.4))') matP(i,:)\n end do\n write (*,*)\n# endif\n\nend subroutine\n\nsubroutine kernel_operators_interpolateBackMatrix(N, nodes, weights, MatM, MatP)\n\n use lagrange_mod, only: lagrange_polynomial\n\n integer, intent(in) :: N\n real(dp), intent(in) :: nodes(N)\n real(dp), intent(in) :: weights(N)\n real(dp), intent(out) :: matM(N_NODES,N_NODES)\n real(dp), intent(out) :: matP(N_NODES,N_NODES)\n\n real(dp) :: lagrVecM(N)\n real(dp) :: lagrVecP(N)\n\n real(dp) :: tempM(N,N)\n real(dp) :: tempP(N,N)\n\n real(dp) :: p,q\n integer :: i,j\n\n do i = 1,N\n LagrVecM(i) = lagrange_polynomial(n, nodes, i, -1.0_dp)\n lagrVecP(i) = lagrange_polynomial(n, nodes, i, 1.0_dp)\n end do\n\n tempM = spread(2./weights*lagrVecM,2,N)\n tempP = spread(2./weights*lagrVecP,2,N)\n\n p = real(N,dp)\n q = real(N,dp)\n \n matM = 0.0_dp\n matP = 0.0_dp\n do j = 1,N_NODES; do i = 1,N_NODES\n matM(i,j) = tempM(i-floor((i-1)/p)*N, j-floor((j-1)/q)*N)\n matP(i,j) = tempP(i-floor((i-1)/p)*N, j-floor((j-1)/q)*N)\n end do; end do\n\n matM = real(N_NODES,dp)/real(N,dp)*matM\n matP = real(N_NODES,dp)/real(N,dp)*matP\n\n# if 0\n write (*,*) 'xmLagrM'\n do i = 1,N_NODES\n write (*,1001) xmLagrM(i,:,qq)\n end do\n write (*,*)\n\n write (*,*) 'xmLagrP'\n do i = 1,N_NODES\n write (*,1001) xmLagrP(i,:,qq)\n end do\n write (*,*)\n\n1001 format(PP_N_NODES(f12.3))\n1002 format(24(f12.3))\n# endif\nend subroutine\n\nsubroutine kernel_operators_surfaceMatrix(N, nodes, weights, surfMat)\n\n use lagrange_mod, only: lagrange_polynomial\n\n integer, intent(in) :: N\n real(dp), intent(in) :: nodes(N)\n real(dp), intent(in) :: weights(N)\n\n real(dp), intent(out) :: surfMat(N_NODES,N_NODES)\n\n real(dp) :: matM(N_NODES,N_NODES)\n real(dp) :: matP(N_NODES,N_NODES)\n\n real(dp) :: lagrM(N_NODES)\n real(dp) :: lagrP(N_NODES)\n\n integer :: i,j\n\n do i = 1,N_NODES\n lagrM(i) = 2.0_dp/REAL(N,dp)/weights(i)*lagrange_polynomial(N, nodes, i, -1.0_dp)\n lagrP(i) = 2.0_dp/REAL(N,dp)/weights(i)*lagrange_polynomial(N, nodes, i, 1.0_dp)\n end do\n\n matM = 0.0_dp\n matP = 0.0_dp\n\n matM(:,1 ) = lagrM\n matP(:,N_NODES) = lagrP\n\n surfMat = matM - matP\n \nend subroutine\n\nsubroutine kernel_operators_surfaceMatrix_ext(N,M, nodes, weights, surfMat)\n\n use utils_mod, only: krondelta\n use share_mod, only: rt => runtime\n use lagrange_mod, only: lagrange_polynomial\n\n integer, intent(in) :: N,M\n real(dp), intent(in) :: nodes(N)\n real(dp), intent(in) :: weights(N)\n\n real(dp), intent(out) :: surfMat(M,M+1)\n\n real(dp) :: matM(M,M+1)\n real(dp) :: matP(M,M+1)\n\n real(dp) :: lagrM(M)\n real(dp) :: lagrP(M)\n\n integer :: i,j\n\n do i = 1,M\n !lagrM(i) = REAL(N_NODES,dp)/REAL(N,dp)*2./weights(mod(i-1,N)+1)*lagrange_polynomial(N, nodes, mod(i-1,N)+1, -1.0_dp)\n !lagrP(i) = REAL(N_NODES,dp)/REAL(N,dp)*2./weights(mod(i-1,N)+1)*lagrange_polynomial(N, nodes, mod(i-1,N)+1, 1.0_dp)\n !lagrM(i) = 2.0_dp/REAL(N,dp)/weights(mod(i-1,N)+1)*lagrange_polynomial(N, nodes, mod(i-1,N)+1, -1.0_dp)\n !lagrP(i) = 2.0_dp/REAL(N,dp)/weights(mod(i-1,N)+1)*lagrange_polynomial(N, nodes, mod(i-1,N)+1, 1.0_dp)\n\n lagrM(i) = 2.0_dp/weights(mod(i-1,N)+1)*lagrange_polynomial(N, nodes, mod(i-1,N)+1, -1.0_dp)\n lagrP(i) = 2.0_dp/weights(mod(i-1,N)+1)*lagrange_polynomial(N, nodes, mod(i-1,N)+1, 1.0_dp)\n end do\n\n matM = 0.0_dp\n matP = 0.0_dp\n\n do j = 1,M+1; do i = 1,M\n matM(i,j) = lagrM(i) * krondelta(0 + 1 + N * ((i-1)/N), j)\n matP(i,j) = lagrP(i) * krondelta(N + 1 + N * ((i-1)/N), j)\n end do; end do\n\n surfMat = matM - matP\n \n# if 0\n if (rt%mpi%isroot) then\n !write (*,*) 'matM', N\n !do i = 1,N_NODES\n ! write (*,'(9(ES12.4))') matM(i,:)\n !end do\n !write (*,*)\n !write (*,*) 'matP', N\n !do i = 1,N_NODES\n ! write (*,'(9(ES12.4))') matP(i,:)\n !end do\n !write (*,*)\n\n write (*,*) 'surfMat', N\n do i = 1,N_NODES\n write (*,'(9(ES12.4))') surfMat(i,:)\n end do\n write (*,*)\n end if\n# endif\n\nend subroutine\n\nsubroutine kernel_operators_surfaceMatrix_split(N, nodes, weights, surfMatM, surfMatP)\n\n use utils_mod, only: krondelta\n use share_mod, only: rt => runtime\n use lagrange_mod, only: lagrange_polynomial\n\n integer, intent(in) :: N\n real(dp), intent(in) :: nodes(N)\n real(dp), intent(in) :: weights(N)\n\n real(dp), intent(out) :: surfMatM(N_NODES,N_NODES+1)\n real(dp), intent(out) :: surfMatP(N_NODES,N_NODES+1)\n\n real(dp) :: matM(N_NODES,N_NODES+1)\n real(dp) :: matP(N_NODES,N_NODES+1)\n\n real(dp) :: lagrM(N_NODES)\n real(dp) :: lagrP(N_NODES)\n\n integer :: i,j\n\n do i = 1,N_NODES\n !lagrM(i) = REAL(N_NODES,dp)/REAL(N,dp)*2./weights(mod(i-1,N)+1)*lagrange_polynomial(N, nodes, mod(i-1,N)+1, -1.0_dp)\n !lagrP(i) = REAL(N_NODES,dp)/REAL(N,dp)*2./weights(mod(i-1,N)+1)*lagrange_polynomial(N, nodes, mod(i-1,N)+1, 1.0_dp)\n lagrM(i) = 2.0_dp/REAL(N,dp)/weights(mod(i-1,N)+1)*lagrange_polynomial(N, nodes, mod(i-1,N)+1, -1.0_dp)\n lagrP(i) = 2.0_dp/REAL(N,dp)/weights(mod(i-1,N)+1)*lagrange_polynomial(N, nodes, mod(i-1,N)+1, 1.0_dp)\n end do\n\n matM = 0.0_dp\n matP = 0.0_dp\n\n do j = 1,N_NODES+1; do i = 1,N_NODES\n matM(i,j) = lagrM(i) * krondelta(0 + 1 + N * ((i-1)/N), j)\n matP(i,j) = lagrP(i) * krondelta(N + 1 + N * ((i-1)/N), j)\n end do; end do\n\n surfMatM = matM\n surfMatP = -matP\n \nend subroutine\n\n!! FV difference operator\nsubroutine kernel_operators_FVDifferenceMatrix(mat)\n\n use utils_mod, only: krondelta\n\n real(dp), intent(out) :: mat(1:N_NODES,0:N_NODES)\n\n integer :: i,j\n\n mat = 0.0\n do j = 0,N_NODES; do i = 1,N_NODES\n mat(i,j) = krondelta(i-1,j) - krondelta(i,j)\n end do; end do\n\n mat = N_NODES * mat\n\nend subroutine\n\n!! FV surface operator\nsubroutine kernel_operators_FVProlongBackMatrix(mat)\n\n use utils_mod, only: krondelta\n\n real(dp), intent(out) :: mat(N_NODES,2*N_NODES,2)\n\n integer :: i,j\n\n mat = 0.0\n\n do j = 1,2*N_NODES; do i = 1,N_NODES\n mat(i,j,1) = krondelta(i,j)\n mat(i,j,2) = 0.5*(krondelta(i*2-1,j) + krondelta(i*2,j))\n end do; end do\n\n# if 0\n write (*,*) 'prolongBack'\n do i = 1,N_NODES\n write (*,1002) prolongBack(i,:,0,2)\n end do\n write (*,*)\n\n1001 format(PP_N_NODES(f8.3))\n1002 format(16(f6.2))\n# endif\n\nend subroutine\n\n!! FV surface operator\nsubroutine kernel_operators_FVProlongBackMatrixN(N,mat)\n\n use utils_mod, only: krondelta\n\n integer, intent(in) :: N\n real(dp), intent(out) :: mat(N,2*N)\n\n integer :: i,j\n\n mat = 0.0\n do j = 1,2*N; do i = 1,N\n mat(i,j) = 0.5*(krondelta(i*2-1,j) + krondelta(i*2,j))\n end do; end do\n\nend subroutine\n\n!! FV simpson rule operator\nsubroutine kernel_operators_SimpsonRuleMatrixN(N,mat)\n\n integer, intent(in) :: N\n real(dp), intent(out) :: mat(N,3*N)\n\n integer :: i,j\n\n real(dp), parameter :: coeffs(3) = (/1.0_dp,4.0_dp,1.0_dp/) / 6.0_dp\n !real(dp), parameter :: coeffs(3) = (/0.0_dp,1.0_dp,0.0_dp/)\n\n mat = 0.0\n do i = 1,N; do j = (i-1)*3 + 2,i*3,3\n mat(i,j-1) = coeffs(1)\n mat(i,j+0) = coeffs(2)\n mat(i,j+1) = coeffs(3)\n end do; end do\n\nend subroutine\n\npure subroutine kernel_operators_InterfaceNodes(N,xs,xL,xC,xR,x3)\n\n implicit none\n\n integer,intent(in) :: N\n real(dp), intent(in) :: xs(3)\n real(dp),intent(out) :: xL(N),xC(N),xR(N),x3(3*N)\n\n integer :: i\n\n do i = 1,N\n xL(i) = -1.0_dp + 2.0_dp*(real(i,dp)-0.5_dp)/real(N,dp) + xs(1)/real(N,dp)\n xC(i) = -1.0_dp + 2.0_dp*(real(i,dp)-0.5_dp)/real(N,dp) + xs(2)/real(N,dp)\n xR(i) = -1.0_dp + 2.0_dp*(real(i,dp)-0.5_dp)/real(N,dp) + xs(3)/real(N,dp)\n end do\n\n do i = 1,N\n x3(3*(i-1)+1) = xL(i)\n x3(3*(i-1)+2) = xC(i)\n x3(3*(i-1)+3) = xR(i)\n end do\n\nend subroutine\n\nsubroutine kernel_operators_faceMatrix(N,L, M,P, xnodes, ynodes, mat)\n\n !! asuming nodes are within [-0.5,0.5]\n\n use utils_mod, only: krondelta\n use lagrange_mod, only: lagrange_polynomial\n\n integer, intent(in) :: N,L, M,P\n real(dp), intent(in) :: xnodes(L)\n real(dp), intent(in) :: ynodes(P)\n real(dp), intent(out) :: mat(M,N)\n\n real(dp) :: xbd(-1:1,N/L) !! left,center,right\n real(dp) :: ybd(-1:1,M/P) !! left,center,right\n\n real(dp) :: xxnodes(N)\n real(dp) :: yynodes(M)\n\n real(dp) :: dx, dxx, dy, prefac, ofsL, ofsR\n integer :: i,j, ii,jj,iii\n\n integer :: Nx,Ny\n\n real(dp), parameter :: tol = 1e-9\n\n Nx = N/L\n Ny = M/P\n\n dx = 1.0_dp/real(Nx,dp)\n dy = 1.0_dp/real(Ny,dp)\n\n !! compute boundaries of input sub-elements\n do i = 1,Nx\n xbd(-1,i) = -0.5_dp + (i-1.0_dp)*dx\n xbd( 0,i) = -0.5_dp + (i-0.5_dp)*dx\n xbd( 1,i) = -0.5_dp + (i )*dx\n end do\n\n !! compute boundaries of output sub-elements\n do i = 1,Ny\n ybd(-1,i) = -0.5_dp + (i-1.0_dp)*dy\n ybd( 0,i) = -0.5_dp + (i-0.5_dp)*dy\n ybd( 1,i) = -0.5_dp + (i )*dy\n end do\n\n !! compute destination nodes\n do i = 1,Ny\n do ii = 1,P\n yynodes((i-1)*P+ii) = ybd(0,i) + dy*ynodes(ii)\n end do\n end do\n\n !! compute interpolation matrix\n mat = 0.0_dp\n do iii = 1,Ny\n do ii= 1,P\n i = (iii-1)*P+ii\n\n if (ii == 1) then\n ofsL = tol\n ofsR = 0.0_dp\n\n else if (ii == P) then\n ofsL = 0.0_dp\n ofsR = -tol\n end if\n\n do j = 1,Nx\n\n if (abs(ybd( 1,iii) - yynodes(i)) > tol .and. abs(xbd(1,j) - yynodes(i)) <= tol) then\n do jj = 1,L\n mat(i,(j-1)*L + jj) = 0.5*lagrange_polynomial(L, xnodes, jj, 0.5_dp)\n end do\n\n cycle\n endif\n\n if (abs(ybd(-1,iii) - yynodes(i)) > tol .and. abs(xbd(-1,j) - yynodes(i)) <= tol) then\n do jj = 1,L\n mat(i,(j-1)*L + jj) = 0.5*lagrange_polynomial(L, xnodes, jj, -0.5_dp)\n end do\n\n cycle\n endif\n\n if (xbd(-1,j) < yynodes(i) + ofsL .and. yynodes(i) + ofsR < xbd(1,j)) then\n \n dxx = abs(xbd(-1,j) - yynodes(i))/dx\n do jj = 1,L\n mat(i,(j-1)*L + jj) = lagrange_polynomial(L, xnodes, jj, -0.5_dp + dxx)\n end do\n\n exit\n end if\n\n end do\n end do\n end do\n\n# if 0\n write (*,*) N,L,M,P,'faceMat'\n do i = 1,M\n write (*,'(99(ES12.4))') Mat(i,:)\n end do\n write (*,*)\n# endif\n\nend subroutine\n\nsubroutine kernel_operators_interpolationMatrix(N,M,Q, xs,ws, ys,vs, mat)\n\n use lagrange_mod, only: lagrange_polynomial\n\n integer, intent(in) :: N,M,Q !! # of xs-nodes, ys-nodes, sub-elements\n real(dp), intent(in) :: xs(N),ws(N) !! nodes, weights of source element\n real(dp), intent(in) :: ys(M),vs(M) !! nodes, weights of target sub-elements\n real(dp), intent(out) :: mat(M,N,Q)\n\n real(dp) :: xL,xR !! left,right boundaries\n real(dp) :: mu(Q) !! center nodes of sub-elements\n real(dp) :: xi(N,Q) !! scaled quadrature nodes of 'xs' around center nodes 'mu'\n\n integer :: i,j,k\n\n !! works for reference elements of arbitrary size\n xL = -0.5*sum(vs)\n xR = -xL\n \n !! make body-centered linear space\n forall (k = 1:Q)\n mu(k) = xL + (k-0.5)*abs(xR-xL)/Q\n end forall\n\n !! interpolation nodes within each sub-element of master element\n forall (k = 1:Q, i = 1:M)\n xi(i,k) = mu(k) + ys(i)/Q\n end forall\n\n !! interpolation matrices\n forall (k = 1:Q, j = 1:N, i = 1:M)\n mat(i,j,k) = lagrange_polynomial(N,xs,j,xi(i,k))\n end forall\n\n# if 0\n do k = 1,Q\n write (*,*) 'interpolationMat',N,M,Q,k\n do i = 1,M\n write (*,'(99(ES12.4))') mat(i,:,k)\n end do\n write (*,*)\n end do\n# endif\n\nend subroutine\n\nsubroutine kernel_operators_projectionMatrix(N,M,Q, xs,ws, ys,vs, mat)\n\n use lagrange_mod, only: lagrange_polynomial\n\n integer, intent(in) :: N,M,Q !! # of xs-nodes, ys-nodes, sub-elements\n real(dp), intent(in) :: xs(N),ws(N) !! nodes, weights of sub-elements\n real(dp), intent(in) :: ys(M),vs(M) !! nodes, weights of target element\n real(dp), intent(out) :: mat(M,N,Q)\n\n real(dp) :: xL,xR !! left,right boundaries\n real(dp) :: mu(Q) !! center nodes of sub-elements\n real(dp) :: xi(N,Q) !! scaled quadrature nodes of 'xs' around center nodes 'mu'\n\n integer :: i,j,k\n\n !! works for reference elements of arbitrary size\n xL = -0.5*sum(vs)\n xR = -xL\n \n !! make body-centered linear space\n forall (k = 1:Q)\n mu(k) = xL + (k-0.5)*abs(xR-xL)/Q\n end forall\n\n !! interpolation nodes within each sub-element of master element\n forall (k = 1:Q, j = 1:N)\n xi(j,k) = mu(k) + xs(j)/Q\n end forall\n\n !! projection matrices\n forall (k = 1:Q, j = 1:N, i = 1:M)\n mat(i,j,k) = lagrange_polynomial(M,ys,i,xi(j,k))*ws(j)/vs(i)/Q\n end forall\n\n# if 0\n do k = 1,Q\n write (*,*) 'projectionMat',N,M,Q,k\n do i = 1,M\n write (*,'(99(ES12.4))') mat(i,:,k)\n end do\n write (*,*)\n end do\n# endif\n\nend subroutine\n\nend module\n", "meta": {"hexsha": "2f2bd39ed957c54b484d7c02dab824fb37cfc921", "size": 28470, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/kernel/dgsem/weakform/2d/kernel_operators_mod.f90", "max_stars_repo_name": "jmark/nemo", "max_stars_repo_head_hexsha": "cf8a6a8bed5c54626f5e300c701b9c278fd5e0cd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source/kernel/dgsem/weakform/2d/kernel_operators_mod.f90", "max_issues_repo_name": "jmark/nemo", "max_issues_repo_head_hexsha": "cf8a6a8bed5c54626f5e300c701b9c278fd5e0cd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/kernel/dgsem/weakform/2d/kernel_operators_mod.f90", "max_forks_repo_name": "jmark/nemo", "max_forks_repo_head_hexsha": "cf8a6a8bed5c54626f5e300c701b9c278fd5e0cd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.8114233908, "max_line_length": 125, "alphanum_fraction": 0.5617843344, "num_tokens": 10149, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467770088162, "lm_q2_score": 0.7461389986757758, "lm_q1q2_score": 0.6559656958863936}} {"text": "************************************************************************\n* Computes the norms RESU, RESDIV\n*\n* This routine computes the \"U-residual\" RESU and the \"divergence\n* residual\" RESDIV.\n*\n* In:\n* U1,\n* U2,\n* P - Velocity/pressure vector of the solution of \n* the linearised system A * (U1,U2,P) = (F1,F2,FP)\n* D1,\n* D2,\n* DP - Defect vector (D1,D2,DP) = (F1,F2,FP) - A*(U1,U2,P)\n* F1,\n* F2,\n* FP - RHS vector of the system A * (U1,U2,P) = (F1,F2,FP)\n* NU - length of the velocity vectors\n* NP - length of the pressure vectors\n* \n* Out:\n* RESU - Norm of the velocity residual:\n* || (D1,D2) ||_E\n* RESU = -----------------------------\n* max ( ||F1||_E , ||F2||_E )\n*\n* RESDIV - Norm of the pressure residual\n* || P ||_E\n* RESDIV = ----------------\n* || (U1,U2) ||_E\n************************************************************************\n\n SUBROUTINE RESDFK(U1,U2,P,D1,D2,DP,F1,F2,FP,NU,NP,RESU,RESDIV)\n \n IMPLICIT NONE\n \nC parameters \n\n INTEGER NU,NP\n DOUBLE PRECISION U1(*),U2(*),P(*),D1(*),D2(*),DP(*),F1(*),F2(*),\n * FP(*)\n DOUBLE PRECISION RESU, RESDIV\n\nC local variables\n \n DOUBLE PRECISION RESF, RESF1, RESF2, RESU1, RESU2\n DOUBLE PRECISION DNORMU, DNRMU1, DNRMU2\n\nC-----------------------------------------------------------------------\nC Compute the relative l2-norms RESU,RESDIV\nC-----------------------------------------------------------------------\n\nC RESF := max ( ||F1||_E , ||F2||_E )\n\n CALL LL21 (F1,NU,RESF1)\n CALL LL21 (F2,NU,RESF2)\n RESF=MAX(RESF1,RESF2)\n IF (ABS(RESF).LT.1D-8) RESF=1D0\n\nC || (D1,D2) ||_E\nC RESU = -----------------------------\nC max ( ||F1||_E , ||F2||_E )\n\n CALL LL21 (D1,NU,RESU1)\n CALL LL21 (D2,NU,RESU2)\n RESU=SQRT(RESU1*RESU1+RESU2*RESU2)/RESF\n\nC DNORMU = || (U1,U2) ||_l2 \n\n CALL LL21 (U1,NU,DNRMU1)\n CALL LL21 (U2,NU,DNRMU2)\n DNORMU=SQRT(DNRMU1*DNRMU1+DNRMU2*DNRMU2)\n IF (ABS(DNORMU).LT.1D-8) DNORMU=1D0\n\nC || P ||_E\nC RESDIV = ----------------\nC || (U1,U2) ||_E\n\n CALL LL21 (DP,NP,RESDIV)\n RESDIV=RESDIV/DNORMU\nC\n END\n\n************************************************************************\n* Defect-RHS and matrix construction routine 4\n*\n* Extended calling convention\n*\n* Build the linear part of the defect vector for the nonlinear \n* iteration. Combinate Stokes- and Mass-matrix to build the\n* linear part of the nonlinear system matrix.\n*\n* This routine is called in NSDEF2 to assemble mass-/system\n* matrices for the nonlinear iteration. It has the same duty as\n* XMADF2 but uses a different calling convention. \n*\n* The shortcut nodal property array is used to decide on which\n* DOF's are boundary and which not!\n*\n* In:\n* TRIA - array [1..SZTRIA] of integer\n* Triangulation structure on current level\n* MATPAR - array [1..SZN2VI] of integer\n* TNS2DMatrixParams structure containing all information about\n* system-/mass-/Laplace matrices on the current level\n* DU - array [1..2*NEQA+NEQB] of double\n* This is the the X-,Y- and pressure-component of the current \n* solution vector u^n of the equation.\n* Must correspond to MATPAR.\n* DD - array [1..2*NEQA+NEQB] of double\n* Vector that contains the current RHS-vector of the linear \n* system for velocity and pressure. This will be overwritten\n* by the resulting defect vector, if IDEF=1.\n* Must correspond to MATPAR.\n* THSTEP - double. Theta-scheme identifier.\n* =0: Forward Euler, =1: Backward Euler, =0.5: Crank Nicolson\n* For Fractional-Step theta scheme this is set to different\n* values, depending on the current step in the scheme.\n* For stationary simulations this parameter must be set\n* to 1 to include the full Laplacian matrix into the\n* system matrix:\n* [alpha*M + THETA*KST1 ] \n* IALPHA - Whether the simulation is stationary or not.\n* As this routine generally builds\n* [alpha*M + Theta_1*nu*k*L ] u\n* (the linear part of S(u)), this parameter decides whether\n* ALPHA=0 or ALPHA=1, so whether the mass \n* matrix is added or not. \n* IDEF - Whether to update the defect vector according to\n* DEF := DEF - [ ALPHA*M*I - THSTEP*(-nu*Laplace(u^n)) ] u \n* = 0: don't update defect vector\n* <>0: update defect vector\n* IPRECA - Defines how to set up the system matrix.\n* = 0,\n* = 1: Copy a precalculated Stokes matrix KST to KA\n* and add mass matrix if desired\n* = 2,\n* = 3: Read precalculated Stokes matrix for level ILEV from\n* disc and add mass matrix if desired\n* = 4: Clear the System matrix. In a stationary simulation\n* (IALPHA=1) with lumped mass matrix (IMASS=0), \n* add the mass matrix to the system matrix.\n* INEUM - Whether there are Neumann boundary components in our\n* problem or not.\n* ILEV - Current level. Only used if IPRECA=3 to read the correct\n* matrix into the memory - otherwise ignored.\n*\n* Out:\n* - The system matrix (identified by MATPAR(ILEV).LA1) is filled with \n* a linear approximation to the nonlinear system matrix\n* - DD - Will receive the defect vector, calculated\n* with the RHS, the solution and the linear part of the\n* nonlinear system matrix:\n* DD = DD - [alpha*M*u-THSTEP*{-nu*Laplace(u)}]*u\n************************************************************************\n\n SUBROUTINE XMADF4(TRIA,MATPAR,DU,DD,IDEF,IPRECA,\n * INEUM,THSTEP,IALPHA,ILEV)\n \n************************************************************************\n\n IMPLICIT NONE\n\nC main COMMON blocks\n\n INCLUDE 'cmem.inc'\n INCLUDE 'cout.inc'\n INCLUDE 'cerr.inc'\n \n INCLUDE 'cbasicmg.inc'\n \n INCLUDE 'stria.inc'\n INCLUDE 'slinsol.inc'\n INCLUDE 'slinsol2dns.inc'\n INCLUDE 'smat2dns.inc'\n\nC parameters\n\n INTEGER TRIA(SZTRIA),MATPAR(SZN2MI)\n INTEGER INEUM,IALPHA,IDEF,IPRECA,ILEV\n DOUBLE PRECISION DU(*),DD(*),THSTEP\n\nC local variables\n\n INTEGER KM1,KST1,KA1,KCOLA,KLDA,KB1,KB2,KCOLB,KLDB\n INTEGER NA,KSCNPR,NBDMT,NU\n INTEGER INU, INUA\n\nC constants for filenames\n\n CHARACTER CFILST*12,CFILM*12,CFILE*12\n DIMENSION CFILST(NNLEV),CFILM(NNLEV)\n DATA CFILST/'ns/ST1 ','ns/ST2 ','ns/ST3 ',\n * 'ns/ST4 ','ns/ST5 ','ns/ST6 ',\n * 'ns/ST7 ','ns/ST8 ','ns/ST9 '/\n DATA CFILM /'ns/MA1 ','ns/MA2 ','ns/MA3 ',\n * 'ns/MA4 ','ns/MA5 ','ns/MA6 ',\n * 'ns/MA7 ','ns/MA8 ','ns/MA9 '/\n SAVE CFILST,CFILM,CFILE\n\nC At first transfer the starting addresses of the matrices\nC to local variables for faster access.\nC\nC We assume here, that we only have one system and one pressure\nC matrix structure.\n\n KM1 = L(MATPAR(OLM))\n KA1 = L(MATPAR(OLA1))\n KCOLA = L(MATPAR(OLCLA1))\n KLDA = L(MATPAR(OLLDA1))\n KB1 = L(MATPAR(OLB1))\n KB2 = L(MATPAR(OLB2))\n KCOLB = L(MATPAR(OLCLB1))\n KLDB = L(MATPAR(OLLDB1))\n NA = MATPAR(ONA1)\n\nC Use the shortcut nodal property array to decide which points are\nC on the boundary, which are Neumann boundary,...\n \n NBDMT = TRIA(OTRIUD)\n KSCNPR = L(TRIA(OTRIUD+1))\n \nC We known the number of velocity equations by the size of A\n\n NU = MATPAR(ONEQA)\n\nC Standard matrix assembling branch:\n\n IF ((IPRECA.EQ.0).OR.(IPRECA.EQ.1)) THEN\n\nC We have a Stokes matrix\n\n KST1 = L(MATPAR(OLST))\n\nC Decide whether or not to include the mass matrix (for\nC instationary simulation) into the system matrix:\n\n IF (IALPHA.EQ.1) THEN\n\nC We have to build the linear part of the nonlinear system \nC matrix with the help of the Stokes- and mass-matrices:\nC\nC KA1 = [ M*I + THSTEP * N(u) ]\nC = [ M*I + THSTEP * (-nu * Laplace(.)) + u * grad(.) ]\nC ^^^ ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^\nC ->KM1 ->KST1 -> ignored here\nC\nC Check if we have a real or a lumped mass matrix.\n\n IF (MATPAR(OIMALMP).EQ.1) THEN\n\nC We have a real mass matrix in the structure of the \nC system matrix.\nC Now check the Theta-parameter. If it's 0, we can skip the \nC linear combination with the Stokes-matrix. Otherwise\nC simply add the matrices:\nC\nC KM1 + THSTEP*KST1\n\n IF (THSTEP.NE.0D0) THEN\n CALL LLC1(DWORK(KST1),DWORK(KA1),NA,THSTEP,0D0)\n CALL LLC1(DWORK(KM1 ),DWORK(KA1),NA,1D0,1D0)\n ELSE\n CALL LCP1(DWORK(KM1),DWORK(KA1),NA)\n ENDIF\n \n ELSE\n \nC Using lumped mass matrices we have only to tackle\nC the diagonal when adding it to the system matrix.\nC Again add the matrices:\nC\nC KM1 + THSTEP*KST1\n\n IF (THSTEP.NE.0D0) THEN\n CALL LLC1(DWORK(KST1),DWORK(KA1),NA,THSTEP,0D0)\n DO INU=1,NU\n INUA=KWORK(KLDA+INU-1)-1\n DWORK(KA1+INUA)=DWORK(KA1+INUA)+DWORK(KM1+INU-1)\n END DO\n ELSE\n CALL LCL1(DWORK(KA1),NA)\n DO INU=1,NU\n INUA=KWORK(KLDA+INU-1)-1\n DWORK(KA1+INUA)=DWORK(KM1+INU-1)\n END DO\n ENDIF\n ENDIF\n ELSE\n \nC The case of a stationary simulation is much easier. \nC Remember, we have to solve a system of the form\nC\nC S(u_h)u_h + k B p_h = g_h, B^T u_h = 0\nC\nC where\nC\nC S(u) = [alpha*M + Theta_1*nu*k*L + Theta_2*k*K(u)] u\nC \nC is the matrix whose linear parts we are building here.\nC In the stationary approach, there is alpha=0, so adding\nC the mass matrix can be dropped completely!\nC\nC Therefore we only have to build\nC\nC KA1 = [ THSTEP * (-nu * Laplace(.)) + u * grad(.) ]\nC ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^\nC ->KST1 -> ignored here\nC\nC what can simply be done by copying KST1 to KA1 with the \nC correct scaling factor.\n \n CALL LLC1(DWORK(KST1),DWORK(KA1),NA,THSTEP,0D0)\n \n ENDIF\n\nC Multiply the solution vector with the built matrix, and \nC subtract it from the RHS-vector (the current setting of KDx)\nC to build the defect vector. \nC\nC DEF := DEF - [ ALPHA*M*I - THSTEP*(-nu*Laplace(u^n)) ] u\n\n IF (IDEF.NE.0) THEN\n CALL LAX17 (DWORK(KA1),KWORK(KCOLA),KWORK(KLDA),NU,\n * DU(1),DD(1),-1D0,1D0)\n CALL LAX17 (DWORK(KA1),KWORK(KCOLA),KWORK(KLDA),NU,\n * DU(1+NU),DD(1+NU),-1D0,1D0)\n ENDIF\n\n ENDIF\n\nC=======================================================================\n\nC Check if the matrices are so big that they have to be read in\nC from a file. The duty of this branch is the same as above.\n\n IF ((IPRECA.EQ.2).OR.(IPRECA.EQ.3)) THEN\n\nC Read data about level ILEV into memory.\n\n IF (IALPHA.EQ.1) THEN\n IF (THSTEP.NE.0D0) THEN\n CALL OF0 (59,CFILST(ILEV),0)\n CFILE='STMAT '\n CALL ORA1 (DWORK(KA1),CFILE,59,0)\n REWIND(59)\n CLOSE (59)\n IF (IER.NE.0) RETURN\n CALL LLC1(DWORK(KA1),DWORK(KA1),NA,THSTEP,0D0)\n ELSE\n CALL LCL1(DWORK(KA1),NA)\n ENDIF\n\n IF (MATPAR(OIMALMP).EQ.1) THEN\n CALL OF0 (59,CFILM(ILEV),0)\n CFILE='MASMAT'\n CALL ORALC1 (DWORK(KA1),1D0,CFILE,59,0)\n REWIND(59)\n CLOSE (59)\n IF (IER.NE.0) RETURN\n ELSE\n IF (THSTEP.NE.0D0) THEN\n DO INU=1,NU\n INUA=KWORK(KLDA+INU-1)-1\n DWORK(KA1+INUA)=DWORK(KA1+INUA)+DWORK(KM1+INU-1)\n END DO\n ELSE\n DO INU=1,NU\n INUA=KWORK(KLDA+INU-1)-1\n DWORK(KA1+INUA)=DWORK(KM1+INU-1)\n END DO\n ENDIF\n ENDIF\n ELSE\n CALL OF0 (59,CFILST(ILEV),0)\n CFILE='STMAT '\n CALL ORA1 (DWORK(KA1),CFILE,59,0)\n REWIND(59)\n CLOSE (59)\n IF (IER.NE.0) RETURN\n CALL LLC1(DWORK(KA1),DWORK(KA1),NA,THSTEP,0D0)\n ENDIF\n\n IF (IDEF.NE.0) THEN\n CALL LAX17 (DWORK(KA1),KWORK(KCOLA),KWORK(KLDA),NU,\n * DU(1),DD(1),-1D0,1D0)\n CALL LAX17 (DWORK(KA1),KWORK(KCOLA),KWORK(KLDA),NU,\n * DU(1+NU),DD(1+NU),-1D0,1D0)\n ENDIF\n\n ENDIF\n\nC=======================================================================\n\nC In this branch we don't rely on any precalculated information\nC in KST1. If we have a lumped mass matrix, we can build a part of\nC the RHS-vector and of KA1 - otherwise simply clear KA1 as is\nC will be calculated later by the caller.\n\n IF (IPRECA.EQ.4) THEN\n\n IF (IALPHA.EQ.1) THEN\n \n IF (MATPAR(OIMALMP).EQ.0) THEN\n \n IF (IDEF.NE.0) THEN\n \nC Treat both components separately instead of \nC simultaneously in one loop. That is a little faster\nC as the compiler can unroll it...\n \n DO INU=1,NU\n DD(INU)= DD(INU)-DWORK(KM1+INU-1)*DU(INU)\n END DO\n \n DO INU=1,NU\n DD(NU+INU)= DD(NU+INU)-DWORK(KM1+INU-1)*DU(NU+INU)\n END DO\n \n ENDIF ! (IDEF.NE.0)\n\n CALL LCL1(DWORK(KA1),NA)\n\n DO INU=1,NU\n INUA=KWORK(KLDA+INU-1)-1\n DWORK(KA1+INUA)=DWORK(KM1+INU-1)\n END DO\n \n ELSE\n \n CALL LCL1(DWORK(KA1),NA)\n \n ENDIF ! (IMASS.EQ.0)\n \n ELSE\n \n CALL LCL1(DWORK(KA1),NA)\n \n ENDIF ! (IALPHA.EQ.1)\n\n ENDIF ! (IPRECA.EQ.4)\n\nC That's it for the velocity part of the system matrix\nC\nC=======================================================================\nC\nC Now turn over to handle the pressure part. Up to now we\nC constructed the defect vector KD1/KD2 only using the velocity\nC part - but of course that's not enough. Also the pressure-part\nC has to be included into the defect calculation.\nC\nC So now update the defect vector by\nC\nC KD1 = KD1 - KB1*KP\nC\nC to get the correct defect for the velocity. Remember, the\nC whole thing we are calculating here is:\nC\nC (def1) (d1) [ KST1 KB1 ] ( u1 ) \nC (def2) = (d2) - [ KST1 KB2 ] ( u2 ) \nC (defp) (dp) [ KB1^T KB2^T 0 ] ( p ) \nC\nC Standard handling: IPRECB<>2\n\nC IF (IPRECB.NE.2) THEN\n \nC Subtract KB1*p from KD1 to get the correct defect for U\n \n CALL LAX19 (DWORK(KB1),KWORK(KCOLB),KWORK(KLDB),NU,\n * DU(1+2*NU),DD(1),-1D0,1D0)\n \nC Subtract KB2*p from KD2 to get the correct defect for V\n \n CALL LAX19 (DWORK(KB2),KWORK(KCOLB),KWORK(KLDB),NU,\n * DU(1+2*NU),DD(1+NU),-1D0,1D0)\n \n\nC ELSE\nC\nC Special treatment: IPRECB=2=elementwise application.\nC Might not be implemented completely...\nC \nC CALL BMUL1 (KWORK(L(LVERT)),KWORK(L(LMID)),KWORK(L(LADJ)),\nC * DWORK(L(LCORVG)),DU(1+2*NU),DD(1),DD(1+NU)\nC * NEL,NVT,NMT,-1D0,1D0)\nC \nC ENDIF\n\nC=======================================================================\n\nC Implement Dirichlet-values into the defect.\nC On all Dirichlet-nodes, the defect must be exactly 0.\n\n IF (IDEF.NE.0) CALL BDRY0 (DD(1),DD(1+NU),KWORK(KSCNPR),NBDMT)\n\nC=======================================================================\n\nC Finally calculate the defect vector of the pressure by subtracting\nC the velocity components (multiplied with KB) from KDP.\nC\nC KDP = KDP - KB1^T KU1 - KB2^T KU2\n\nC IF (IPRECB.NE.2) THEN\n\n CALL LTX19 (DWORK(KB1),KWORK(KCOLB),KWORK(KLDB),NU,\n * MATPAR(ONEQB),DU(1),DD(1+2*NU),-1D0,1D0)\n CALL LTX19 (DWORK(KB2),KWORK(KCOLB),KWORK(KLDB),NU,\n * MATPAR(ONEQB),DU(1+NU),DD(1+2*NU),-1D0,1D0)\n\nC ELSE\n\nC Special treatment: IPRECB=2=elementwise application.\nC Might not be implemented completely...\n\nC WRITE(6,*) 'BTMUL ???'\nC CALL BTMUL1(KWORK(L(LVERT)),KWORK(L(LMID)),KWORK(L(LADJ)),\nC * DWORK(L(LCORVG)),DU(1),DU(1+NU),DD(1+2*NU),\nC * NEL,NVT,NMT,-1D0)\nC ENDIF\n\n99998 END\n\n************************************************************************\n* Matrix construction routine 6\n*\n* Extended calling convention\n*\n* Combinate Stokes- and Mass-matrix to build the\n* linear part of the nonlinear system matrix.\n*\n* This routine is called in NGSTP2 to assemble mass-/system\n* matrices for the nonlinear iteration on all lower levels than NLMAX.\n*\n* It's basically the same routine as XMADF3, except for that it uses\n* a different calling convention.\n*\n* In:\n* MATPAR - array [1..SZN2VI] of integer\n* TNS2DMatrixParams structure containing all information about\n* system-/mass-/Laplace matrices on the current level\n* IPRECA - Defines how to set up the system matrix.\n* = 0,\n* = 1: Copy a precalculated Stokes matrix KST to KA\n* and add mass matrix if desired\n* = 2,\n* = 3: Read precalculated Stokes matrix for level ILEV from\n* disc and add mass matrix if desired\n* = 4: Clear the System matrix. In a stationary simulation\n* (IALPHA=1) with lumped mass matrix (IMASS=0), \n* add the mass matrix to the system matrix.\n* THSTEP - double. Theta-scheme identifier.\n* =0: Forward Euler, =1: Backward Euler, =0.5: Crank Nicolson\n* For Fractional-Step theta scheme this is set to different\n* values, depending on the current step in the scheme.\n* For stationary simulations this parameter must be set\n* to 1 to include the full Laplacian matrix into the\n* system matrix:\n* [alpha*M + THETA*KST1 ] \n* IALPHA - Whether the simulation is stationary or not.\n* As this routine generally builds\n* [alpha*M + Theta_1*nu*k*L ] u\n* (the linear part of S(u)), this parameter decides whether\n* ALPHA=0 or ALPHA=1, so whether the mass \n* matrix is added or not. \n* ILEV - Current level. Only used if IPRECA=3 to read the correct\n* matrix into the memory - otherwise ignored.\n*\n* Out:\n* - The system matrix (identified by MATPAR(ILEV).LA1) is filled with \n* a linear approximation to the nonlinear system matrix\n************************************************************************\n\n SUBROUTINE XMADF5(MATPAR,IPRECA,THSTEP,IALPHA,ILEV)\n \n IMPLICIT NONE\n\nC main COMMON blocks\n\n INCLUDE 'cmem.inc'\n INCLUDE 'cout.inc'\n INCLUDE 'cerr.inc'\n \n INCLUDE 'cbasicmg.inc'\n \n INCLUDE 'stria.inc'\n INCLUDE 'slinsol.inc'\n INCLUDE 'slinsol2dns.inc'\n INCLUDE 'smat2dns.inc'\n\nC parameters\n\n INTEGER MATPAR(SZN2MI)\n INTEGER IALPHA,IPRECA,ILEV\n DOUBLE PRECISION THSTEP\n\nC local variables\n\n INTEGER KM1,KST1,KA1,KCOLA,KLDA,NA,NU\n INTEGER INU, INUA\n\nC constants\n\n CHARACTER CFILST*12,CFILM*12,CFILE*12\n DIMENSION CFILST(NNLEV),CFILM(NNLEV)\n DATA CFILST/'ns/ST1 ','ns/ST2 ','ns/ST3 ',\n * 'ns/ST4 ','ns/ST5 ','ns/ST6 ',\n * 'ns/ST7 ','ns/ST8 ','ns/ST9 '/\n DATA CFILM /'ns/MA1 ','ns/MA2 ','ns/MA3 ',\n * 'ns/MA4 ','ns/MA5 ','ns/MA6 ',\n * 'ns/MA7 ','ns/MA8 ','ns/MA9 '/\n SAVE CFILST, CFILM, CFILE\n\nC At first transfer the starting addresses of the matrices\nC to local variables for faster access.\nC\nC We assume here, that we only have one system and one pressure\nC matrix structure.\n\n KM1 = L(MATPAR(OLM))\n KA1 = L(MATPAR(OLA1))\n KCOLA = L(MATPAR(OLCLA1))\n KLDA = L(MATPAR(OLLDA1))\n NA = MATPAR(ONA1)\n NU = MATPAR(ONEQA)\n \nC Standard matrix assembling branch:\n\n IF ((IPRECA.EQ.0).OR.(IPRECA.EQ.1)) THEN\n\nC We have a Stokes matrix\n\n KST1 = L(MATPAR(OLST))\n\nC Decide whether or not to include the mass matrix (for\nC instationary simulation) into the system matrix:\n\n IF (IALPHA.EQ.1) THEN\n\nC We have to build the linear part of the nonlinear system \nC matrix with the help of the Stokes- and mass-matrices:\nC\nC KA1 = [ M*I + THSTEP * N(u) ]\nC = [ M*I + THSTEP * (-nu * Laplace(.)) + u * grad(.) ]\nC ^^^ ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^\nC ->KM1 ->KST1 -> ignored here\nC\nC Check if we have a real or a lumped mass matrix.\n\n IF (MATPAR(OIMALMP).EQ.1) THEN\n\nC We have a real mass matrix in the structure of the \nC system matrix.\nC Now check the Theta-parameter. If it's 0, we can skip the \nC linear combination with the Stokes-matrix. Otherwise\nC simply add the matrices:\nC\nC KM1 + THSTEP*KST1\n\n IF (THSTEP.NE.0D0) THEN\n CALL LLC1(DWORK(KST1),DWORK(KA1),NA,THSTEP,0D0)\n CALL LLC1(DWORK(KM1),DWORK(KA1),NA,1D0,1D0)\n ELSE\n CALL LCP1(DWORK(KM1),DWORK(KA1),NA)\n ENDIF\n ELSE\n\nC Using lumped mass matrices we have only to tackle\nC the diagonal when adding it to the system matrix.\nC Again add the matrices:\nC\nC KM1 + THSTEP*KST1\n\n IF (THSTEP.NE.0D0) THEN\n CALL LLC1(DWORK(KST1),DWORK(KA1),NA,THSTEP,0D0)\n DO INU=1,NU\n INUA=KWORK(KLDA+INU-1)-1\n DWORK(KA1+INUA)=DWORK(KA1+INUA)+DWORK(KM1+INU-1)\n END DO\n ELSE\n CALL LCL1(DWORK(KA1),NA)\n DO INU=1,NU\n INUA=KWORK(KLDA+INU-1)-1\n DWORK(KA1+INUA)=DWORK(KM1+INU-1)\n END DO\n ENDIF\n ENDIF\n ELSE\n \nC The case of a stationary simulation is much easier. \nC Remember, we have to solve a system of the form\nC\nC S(u_h)u_h + k B p_h = g_h, B^T u_h = 0\nC\nC where\nC\nC S(u) = [alpha*M + Theta_1*nu*k*L + Theta_2*k*K(u)] u\nC \nC is the matrix whose linear parts we are building here.\nC In the stationary approach, there is alpha=0, so adding\nC the mass matrix can be dropped completely!\nC\nC Therefore we only have to build\nC\nC KA1 = [ THSTEP * (-nu * Laplace(.)) + u * grad(.) ]\nC ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^\nC ->KST1 -> ignored here\nC\nC what can simply be done by copying KST1 to KA1 with the \nC correct scaling factor.\n\n CALL LLC1(DWORK(KST1),DWORK(KA1),NA,THSTEP,0D0)\n \n ENDIF\n\n ENDIF\n\nC=======================================================================\n\nC Check if the matrices are so big that they have to be read in\nC from a file. The duty of this branch is the same as above.\n\n IF ((IPRECA.EQ.2).OR.(IPRECA.EQ.3)) THEN\n\n IF (THSTEP.NE.0D0) THEN\n CALL OF0 (59,CFILST(ILEV),0)\n CFILE='STMAT '\n CALL ORA1 (DWORK(KA1),CFILE,59,0)\n REWIND(59)\n CLOSE (59)\n IF (IER.NE.0) RETURN\n CALL LLC1(DWORK(KA1),DWORK(KA1),NA,THSTEP,0D0)\n ELSE\n CALL LCL1(DWORK(KA1),NA)\n ENDIF\n\n IF (MATPAR(OIMALMP).EQ.1) THEN\n CALL OF0 (59,CFILM(ILEV),0)\n CFILE='MASMAT'\n CALL ORALC1 (DWORK(KA1),1D0,CFILE,59,0)\n REWIND(59)\n CLOSE (59)\n IF (IER.NE.0) RETURN\n ELSE\n IF (THSTEP.NE.0D0) THEN\n DO INU=1,NU\n INUA=KWORK(KLDA+INU-1)-1\n DWORK(KA1+INUA)=DWORK(KA1+INUA)+DWORK(KM1+INU-1)\n END DO\n ELSE\n DO INU=1,NU\n INUA=KWORK(KLDA+INU-1)-1\n DWORK(KA1+INUA)=DWORK(KM1+INU-1)\n END DO\n ENDIF\n ENDIF\n\n ENDIF\nC=======================================================================\n\nC In this branch we don't rely on any precalculated information\nC in KST1. If we have a lumped mass matrix, we can build a part of\nC the RHS-vector and of KA1 - otherwise simply clear KA1 as is\nC will be calculated later by the caller.\n\n IF (IPRECA.EQ.4) THEN\n\n IF (MATPAR(OIMALMP).EQ.0) THEN\n CALL LCL1(DWORK(KA1),NA)\n DO INU=1,NU\n INUA=KWORK(KLDA+INU-1)-1\n DWORK(KA1+INUA)=DWORK(KM1+INU-1)\n END DO\n ELSE\n CALL LCL1(DWORK(KA1),NA)\n ENDIF\n\n ENDIF\n\nC=======================================================================\n\n99998 END\n", "meta": {"hexsha": "697f39ee5ff2b940e90c49ea35b93d3adc778251", "size": 26074, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "area51/cc2d_movbc_structured_2/src/stationary/dfkt2.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/stationary/dfkt2.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/stationary/dfkt2.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": 33.3427109974, "max_line_length": 73, "alphanum_fraction": 0.5133466288, "num_tokens": 7769, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467801752451, "lm_q2_score": 0.746138993030751, "lm_q1q2_score": 0.6559656932861844}} {"text": "!> @file sparse_matrix.f90\n!! @brief Sparse matrix module\n!! @author Innocent Souopgui\n!! @details\n!! The sparse matrix module provide the sparse matrix data structure\n!! and some basic operation\n!!\n!! For a complete sparse matrix toolbox,\n!! http://people.sc.fsu.edu/~jburkardt/f_src/sparsekit/sparsekit.html\n!! Most subroutines in this module are borrowed from sparsekit\n!<\n\n!> @brief Module sparse matrix data structures and some basic subroutines\n!!\n!<\nmodule sparse_matrix\n use general_constant\n use debug_tools\nimplicit none\n\n !> @brief user defined type for compressed sparse row matrix\n !! Let @a A be the matrix to store\n !! The @a val vector stores the values of the nonzero elements of\n !! the matrix @a A as they are traversed in a row-wise fashion\n !! The @a col_ind vector stores the column indexes of the elements\n !! in the @a val vector. If @a val[k] = @a A[i,j], then col_ind[k] = j\n !! The @a row_ptr vector stores the locations in the @a val vector that\n !! start a row. If @a val[k] = @a A[i,j],\n !! then row_ptr[i] <= k < row_ptr[i+1].\n !! By convention, row_ptr[nrow+1] = nnz+1, where nnz is the number\n !! of nonzeros in the matrix @a A\n !!\n !! @details http://web.eecs.utk.edu/~dongarra/etemplates/node373.html\n !<\n type CSR_matrix\n integer :: nrow = 0 !< Number of rows of the matrix\n integer :: ncol = 0 !< Number of columns of the matrix\n integer :: nnz = 0 !< Number of nonzero elements of the matrix\n integer, dimension(:), pointer :: col_ind => null()\n integer, dimension(:), pointer :: row_ptr => null()\n real(dp), dimension(:), pointer :: val => null()\n !> \\brief indicates if the structure as been initialized\n logical :: initialized = .false.\n end type CSR_matrix\n\ncontains\n\n !> @brief create a CSR matrix from a full matrix and a mask\n !! @param [in] A full matrix to compress\n !! @param [in] M mask matrix indicating masked entries of @a A\n !! @param [in, out] B csr matrix\n !! @details\n !! @a A and @a M must have the same shape\n !<\n subroutine full2csr(A, M, B)\n real(dp), dimension(:,:), intent(in) :: A\n integer, dimension(:,:), intent(in) :: M\n type(CSR_matrix), intent(inout) :: B\n !local variables\n integer :: nrow, ncol, nnz, i, j, pos\n\n if( sum( abs( shape(A)-shape(M) ) )/=0 )then\n call debug(shape(A), 'Shape of the input matrix')\n call debug(shape(M), 'Shape of the input mask ')\n call stop_program('in to_csr, input matrix and mask have different shapes')\n end if\n nrow = size(A,1)\n ncol = size(A,2)\n nnz = count( M == UNMASKED )\n call set_csr(B, nrow, ncol, nnz)\n if(nnz>0)then\n pos = 1!position in the val vector\n do i = 1, nrow\n B%row_ptr(i) = pos\n do j = 1, ncol\n if(M(i,j)==UNMASKED)then\n B%val(pos) = A(i,j)\n B%col_ind(pos) = j\n pos = pos+1\n end if\n end do\n end do\n B%row_ptr(nrow+1) = nnz+1\n end if\n end subroutine full2csr\n\n !> @brief convert a CSR matrix to a full matrix\n !! @param [in] A csr matrix to expand\n !! @param [out] B full matrix (output)\n !! @param [out] M (optional) mask matrix indicating masked entries of @a B\n !! @details\n !! @a A and @a M must have the same shape that corresponds\n !! to the shape of the CSR matrix\n !<\n subroutine csr2full(A,B,M)\n type(CSR_matrix), intent(inout) :: A\n real(dp), dimension(:,:), intent(in out) :: B\n integer, dimension(:,:), optional, intent(in out) :: M\n\n !local variables\n integer :: nrow, ncol, nnz, i, j, k\n\n nrow = A%nrow\n ncol = A%ncol\n if( sum( abs( shape(B)-[nrow,ncol] ) )/=0 )then\n call debug([A%nrow,A%ncol], 'Shape of the CSR matrix')\n call debug(shape(B), 'Shape of the full matrix ')\n call stop_program('In to_csr, shapes of matrices differ')\n end if\n\n if( present(M) )then\n if( sum( abs( shape(M)-[nrow,ncol] ) )/=0 )then\n call debug([A%nrow,A%ncol], 'Shape of the CSR matrix')\n call debug(shape(M), 'Shape of the mask matrix ')\n call stop_program('In to_csr, shapes of matrices differ')\n end if\n\n M = MASKED !suppose all masked\n do i = 1, A%nrow\n do k = A%row_ptr(i), A%row_ptr(i+1)-1\n M(i, A%col_ind(k) ) = UNMASKED\n end do\n end do\n end if\n\n B = 0.0_dp\n do i = 1, A%nrow\n do k = A%row_ptr(i), A%row_ptr(i+1)-1\n B(i, A%col_ind(k) ) = A%val(k)\n end do\n end do\n end subroutine csr2full\n\n\n !> @brief create a CSR matrix from a full matrix and a mask\n !! @param [in, out] A sparse matrix data structure\n !! @param [in] nrow number of row of the matrix\n !! @param [in] ncol number of column of the matrix\n !! @param [in] nnz number of nonzero entry of the matrix\n !<\n subroutine new_csr(A, nrow, ncol, nnz)\n type(CSR_matrix), intent(inout) :: A\n integer, intent(in) :: nrow, ncol, nnz\n\n call set_csr(A, nrow, ncol, nnz)\n end subroutine new_csr\n\n !> @brief Allocates state dynamic space for the csr matrix\n !! @param [in, out] A sparse matrix data structure\n !! @param [in] nrow number of row of the matrix\n !! @param [in] ncol number of column of the matrix\n !! @param [in] nnz number of nonzero entry of the matrix\n !! @details\n !! This routine is used to allocate space compressed sparse matrices.\n !<\n subroutine set_csr(A, nrow, ncol, nnz)\n type(CSR_matrix), intent(inout) :: A\n integer, intent(in) :: nrow, ncol, nnz\n !local variables\n logical :: ll_allocate, ll_reset\n\n ll_allocate = .false.\n ll_reset = .false.\n\n if( (nnz/=0).and.( (nrow==0).or.(ncol==0) ) )then\n call debug( (/nrow, ncol, nnz/), \"nrow ncol, nnz =\", tag=dALLWAYS )\n call stop_program(\"In set_csr: if nnz is nonzero, nrow and ncol must all be nonzero\")\n end if\n\n if( (nrow==0).eqv.(ncol==0) )then !all zero or nonzero\n if( (nrow==0).and.(ncol==0) )then ! all zero\n ll_reset = .true.\n else !both nonzero\n if(A%initialized)then\n !if current size different from required size\n if( (A%nrow /= nrow).or.(A%ncol /= ncol).or.(A%nnz /= nnz) )then\n ll_reset = .true.\n ll_allocate = .true.\n end if\n else !not initialized\n ll_allocate = .true.\n end if\n end if\n else\n call debug( (/nrow, ncol/), \"nrow ncol =\", tag=dALLWAYS )\n call stop_program(\"In set_csr: nrow ncol should all be zero or nonzero\")\n end if\n\n if(ll_reset)call reset_csr(A) !free space if necessary\n\n if( ll_allocate )then\n A%nrow = nrow\n A%ncol = ncol\n A%nnz = nnz\n allocate( A%val(A%nnz), A%col_ind(A%nnz), A%row_ptr(A%nrow+1))\n end if\n\n if( nnz>0 )then !all nonzero\n A%val = 0.0_cp\n A%col_ind = 0\n A%row_ptr = A%nnz+1\n A%initialized = .true.\n end if\n\n !call debug_state( td_state, tag=dALLWAYS )\n end subroutine set_csr\n\n !> @brief Reset crs data structure, free dynamically allocated memory\n !! @param [in, out] A sparse matrix data structure\n !<\n subroutine reset_csr(A)\n type(CSR_matrix), intent(inout) :: A\n\n if(A%initialized) then\n deallocate( A%val, A%col_ind, A%row_ptr )\n end if\n nullify(A%val, A%col_ind, A%row_ptr)\n\n A%nrow = 0\n A%ncol = 0\n A%nnz = 0\n\n A%initialized = .false.\n end subroutine reset_csr\n\n !> @brief transpose a CSR matrix\n !! @param [in] A sparse matrix data structure to transpose\n !! @param [in] B sparse matrix data structure for the transposed matrix\n !! @details\n !! this is not an in-place operation.\n !! Developper notes\n !! this subroutine exploits some properties of operations on CSR\n !! matrix to limit the number of variables. For example, the row_ptr\n !! of the transposed matrix is used for three different purposes:\n !! - count the number of nonzero of each row of the transposed\n !! - mark the position in the data array of the next avaible position\n !! for each row of the transpose\n !! - its actual role of row_ptr\n !! Something to keep in mind (reason why I implemented this function):\n !! in fortran (pgf90 14.6) the code\n !! y = matmul( transpose(A), x)\n !! and the code\n !! B = transpose(A); y = matmul(B,x)\n !! do not produce the same results.\n !<\n subroutine csr_transpose(A, B)\n type(CSR_matrix), intent(in) :: A\n type(CSR_matrix), intent(inout) :: B\n !local variables\n integer :: i, j, k, q, l\n\n call new_csr(B, A%ncol, A%nrow, A%nnz)\n\n ! Step 1\n ! counting the number of nonzeros in each row of the transpose\n B%row_ptr(1:B%nrow) = 0\n do i = 1, A%nrow\n do k = A%row_ptr(i), A%row_ptr(i+1)-1\n j = A%col_ind(k)\n B%row_ptr(j) = B%row_ptr(j) + 1\n end do\n end do\n ! At this point, it is mandatory that sum (B%row_ptr(1:B%nrow))=B%nnz\n if( sum(B%row_ptr(1:B%nrow))/=B%nnz )call stop_program(\"In csr_transpose, step 1 went wrong\")\n\n ! Step 2\n ! Compute the location in the data vector of the first element\n ! of each row of the transpose\n do i = B%nrow, 1, -1\n B%row_ptr(i) = B%row_ptr(i+1) - B%row_ptr(i)\n end do\n ! At this point, it is mandatory that B%row_ptr(1)=1\n if(B%row_ptr(1)/=1)call stop_program(\"In csr_transpose, step 2 went wrong\")\n\n ! Step 3\n ! Actual copy\n do i = 1,A%nrow\n do k = A%row_ptr(i), A%row_ptr(i+1)-1\n q = A%col_ind(k)\n l = B%row_ptr(q) ! next index for the q row\n B%col_ind(l) = i ! colums of B are rows of A\n B%val(l) = A%val(k)\n B%row_ptr(q) = B%row_ptr(q) + 1\n end do\n end do\n ! At this point B%row_ptr contains pointer to the begining of the next row\n\n ! Step 4, re-shift B%row_ptr to actual row pointers\n do i = B%nrow, 1, -1\n B%row_ptr(i+1) = B%row_ptr(i)\n end do\n B%row_ptr(1)=1\n ! At this point, it is mandatory that B%row_ptr(B%nrow+1)=B%nnz+1\n if(B%row_ptr(B%nrow+1)/=B%nnz+1)call stop_program(\"In csr_transpose, step 4 went wrong\")\n end subroutine csr_transpose\n\n !> @brief multiply a CSR matrix A by a vector.\n !! @param[in] A matrix under the CSR form\n !! @param[in] x input vector, must be of size A%ncol\n !! @param[out] y outut vector, must be of size A%nrow\n !! @param[in] trans logical transpose flag\n !! @details\n !! There is no check of the dimensions\n !! if trans flag is present and set to .true. then\n !! y = A^t x, the transpose is used\n !! otherwise\n !! y = Ax\n !<\n subroutine CSR_matvec(A, x, y, trans)\n type(CSR_matrix), intent(in) :: A\n real(dp), dimension(:), intent(in) :: x\n real(dp), dimension(:), intent(in out) :: y\n logical, optional :: trans\n !local variables\n integer :: i, k\n real(dp) :: t\n logical :: ll_trans\n\n if( present(trans) )then\n ll_trans = trans\n else\n ll_trans = .false.\n end if\n\n if(ll_trans) then\n !apply the transposed matrix\n y = 0.0_dp\n do i = 1, A%nrow\n do k = A%row_ptr(i), A%row_ptr(i+1)-1\n y( A%col_ind(k) ) = y( A%col_ind(k) ) + x( i )*A%val(k)\n end do\n end do\n else\n do i = 1, A%nrow\n !\n ! Compute the inner product of row i with vector X.\n !\n t = 0.0_dp\n do k = A%row_ptr(i), A%row_ptr(i+1)-1\n t = t + A%val(k) * x( A%col_ind(k) )\n end do\n y(i) = t\n\n end do\n end if\n end subroutine CSR_matvec\n\nend module sparse_matrix", "meta": {"hexsha": "6b83c841bcc59faeb72588c85dc5c6f7b62d2a72", "size": 12674, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tools/sparse_matrix.f90", "max_stars_repo_name": "souopgui/da-toolbox", "max_stars_repo_head_hexsha": "f274cdec4db272cc10bb142fdff095e40e4a702a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2015-04-25T03:30:32.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-04T00:41:31.000Z", "max_issues_repo_path": "src/tools/sparse_matrix.f90", "max_issues_repo_name": "souopgui/da-toolbox", "max_issues_repo_head_hexsha": "f274cdec4db272cc10bb142fdff095e40e4a702a", "max_issues_repo_licenses": ["MIT"], "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/sparse_matrix.f90", "max_forks_repo_name": "souopgui/da-toolbox", "max_forks_repo_head_hexsha": "f274cdec4db272cc10bb142fdff095e40e4a702a", "max_forks_repo_licenses": ["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.4195402299, "max_line_length": 101, "alphanum_fraction": 0.5477355215, "num_tokens": 3637, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146761176671, "lm_q2_score": 0.7461389873857264, "lm_q1q2_score": 0.6559656741478024}} {"text": " subroutine inv(ndim,Amat)\n\n\n implicit none\n\n integer,parameter :: dp=8\n\n integer :: i\n integer :: info\n\n integer,intent(in):: ndim\n\n! IPIV : INTEGER. Array, DIMENSION at least max(1, n). The pivot indices that define\n! the permutation matrix P; row i of the matrix was interchanged with\n! row ipiv(i). Corresponds to the single precision factorization (if info=\n! 0 and iter \u2265 0) or the double precision factorization (if info= 0 and\n! iter < 0).\n integer,allocatable :: ipiv(:)\n\n\n complex(dp),parameter :: zone=(1.0d0,0.0d0)\n\n\n\n! Amat :\n! Overwritten by the factors L and U from the factorization of A = P*L*U;\n! the unit diagonal elements of L are not stored.\n! If iterative refinement has been successfully used (info= 0 and iter\u2265\n! 0), then A is unchanged.\n! If double precision factorization has been used (info= 0 and iter <\n! 0), then the array A contains the factors L and U from the factorization\n! A = P*L*U; the unit diagonal elements of L are not stored.\n complex(dp),intent(inout):: Amat(ndim,ndim)\n\n! Bmat :\n! Overwritten by the solution matrix X for dgesv, sgesv,zgesv,zgesv.\n complex(dp),allocatable :: Bmat(:,:)\n\n\n allocate(ipiv(ndim))\n allocate(Bmat(ndim,ndim))\n\n ipiv=0\n\n ! unit matrix\n Bmat= (0d0, 0d0)\n do i=1,ndim\n Bmat(i,i)= zone\n enddo\n\n call zgesv(ndim,ndim,Amat,ndim,ipiv,Bmat,ndim,info)\n\n if(info.ne.0)print *,'something wrong with zgesv'\n\n Amat=Bmat\n \n return\n end subroutine inv \n\n !> get the inverse of a real matrix\n subroutine inv_r(ndim,Amat)\n\n implicit none\n\n integer,parameter :: dp=8\n\n integer :: i\n integer :: info\n\n integer,intent(in):: ndim\n\n! IPIV : INTEGER. Array, DIMENSION at least max(1, n). The pivot indices that define\n! the permutation matrix P; row i of the matrix was interchanged with\n! row ipiv(i). Corresponds to the single precision factorization (if info=\n! 0 and iter \u2265 0) or the double precision factorization (if info= 0 and\n! iter < 0).\n integer,allocatable :: ipiv(:)\n\n\n! Amat :\n! Overwritten by the factors L and U from the factorization of A = P*L*U;\n! the unit diagonal elements of L are not stored.\n! If iterative refinement has been successfully used (info= 0 and iter\u2265\n! 0), then A is unchanged.\n! If double precision factorization has been used (info= 0 and iter <\n! 0), then the array A contains the factors L and U from the factorization\n! A = P*L*U; the unit diagonal elements of L are not stored.\n real(dp),intent(inout):: Amat(ndim,ndim)\n\n! Bmat :\n! Overwritten by the solution matrix X for dgesv, sgesv,zgesv,zgesv.\n real(dp),allocatable :: Bmat(:,:)\n\n\n allocate(ipiv(ndim))\n allocate(Bmat(ndim,ndim))\n\n ipiv=0\n\n ! unit matrix\n Bmat= 0d0 \n do i=1,ndim\n Bmat(i,i)= 1d0\n enddo\n\n call dgesv(ndim,ndim,Amat,ndim,ipiv,Bmat,ndim,info)\n\n if(info.ne.0)print *,'something wrong with dgesv'\n\n Amat=Bmat\n \n return\n end subroutine inv_r\n", "meta": {"hexsha": "aa0d8426a5cf27b74e1829650a1317c38e9f7212", "size": 3124, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "stable/inverse.f90", "max_stars_repo_name": "dlnguyen/wannier_tools", "max_stars_repo_head_hexsha": "cc6748e3718ee2a89934a187490c37f9f520aeff", "max_stars_repo_licenses": ["OLDAP-2.3"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-14T12:07:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-14T12:07:24.000Z", "max_issues_repo_path": "stable/inverse.f90", "max_issues_repo_name": "jtsun/wannier_tools", "max_issues_repo_head_hexsha": "f3512e986c6546af6b823ee6b8a4b9118c53a9fa", "max_issues_repo_licenses": ["OLDAP-2.3"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "stable/inverse.f90", "max_forks_repo_name": "jtsun/wannier_tools", "max_forks_repo_head_hexsha": "f3512e986c6546af6b823ee6b8a4b9118c53a9fa", "max_forks_repo_licenses": ["OLDAP-2.3"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.4035087719, "max_line_length": 89, "alphanum_fraction": 0.6376440461, "num_tokens": 937, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951182587158, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.6559595669756819}} {"text": "! PR rtl-optimization/49472\n! { dg-do compile }\n! { dg-options \"-O -fcompare-debug -ffast-math\" }\nsubroutine pr49472\n integer, parameter :: n = 3\n real(8) :: a, b, c, d, e (n+1)\n integer :: i\n do i=2, (n+1)\n b = 1. / ((i - 1.5d0) * 1.)\n c = b * a\n d = -b * c / (1. + b * b) ** 1.5d0\n e(i) = d\n end do\n call dummy (e)\nend subroutine\n", "meta": {"hexsha": "1baf82e8b113e604067e54d20cd4aa22dfc4e200", "size": 350, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/pr49472.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/pr49472.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/pr49472.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": 21.875, "max_line_length": 49, "alphanum_fraction": 0.5085714286, "num_tokens": 157, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951104066293, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.655959556518665}} {"text": "program main\n implicit none\n integer :: n\n print \"(a)\", \"Numbers n is \"\n read *, n\n if (is_even(n)) then\n print \"(a)\", \"n is even\"\n else\n print \"(a)\", \"n is odd\"\n end if\ncontains\n recursive function is_even(n) result(even)\n logical :: even\n integer, intent(in) :: n\n if (n > 0) then\n even = is_odd(n - 1)\n else if (n == 0) then\n even = .true.\n end if\n end function is_even\n\n recursive function is_odd(n) result(odd)\n logical :: odd\n integer, intent(in) :: n\n if (n > 0) then\n odd = is_even(n - 1)\n else if (n == 0) then\n odd = .false.\n end if\n end function is_odd\nend program main", "meta": {"hexsha": "9798ba232c21b9a0e68e080c8046a7fe0a8d291e", "size": 765, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Lecture_04/recursive_even_odd/even_odd.f90", "max_stars_repo_name": "avsukhorukov/TdP2021-22", "max_stars_repo_head_hexsha": "dd3adf2ece93bcd685912614b848c5dddbcdf6de", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Lecture_04/recursive_even_odd/even_odd.f90", "max_issues_repo_name": "avsukhorukov/TdP2021-22", "max_issues_repo_head_hexsha": "dd3adf2ece93bcd685912614b848c5dddbcdf6de", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Lecture_04/recursive_even_odd/even_odd.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.6774193548, "max_line_length": 46, "alphanum_fraction": 0.4810457516, "num_tokens": 214, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951025545426, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.6559595504152389}} {"text": " program demo_scale\n implicit none\n real :: x = 178.1387e-4\n integer :: i = 5\n print *, scale(x,i), x*radix(x)**i\n end program demo_scale\n", "meta": {"hexsha": "c8cc9b987286e06a3eaa9e2da4eb9d5a082b1b38", "size": 159, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/scale.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/scale.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/scale.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": 22.7142857143, "max_line_length": 41, "alphanum_fraction": 0.5786163522, "num_tokens": 52, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8438951025545426, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.6559595417080564}} {"text": " SUBROUTINE proma2(a,b,c,n1,n2,n3)\r\n!********************************************************************\r\n!\r\n!***this routine evaluates a matrix product\r\n! t\r\n! a(i,j) = b(i,k) * c(j,k) a = b * c\r\n!\r\n!********************************************************************\r\n IMPLICIT NONE\r\n\r\n INTEGER (kind=4),INTENT(IN) :: n1,n2,n3\r\n REAL (kind=8),INTENT(IN) :: b(1:n1,1:n3), c(1:n2,1:n3)\r\n REAL (kind=8),INTENT(OUT) :: a(1:n1,1:n2)\r\n\r\n a(1:n1,1:n2) = MATMUL(b(1:n1,1:n3),TRANSPOSE(c(1:n2,1:n3)))\r\n RETURN\r\n\r\n END SUBROUTINE proma2\r\n", "meta": {"hexsha": "6b8017f22482df3ed453d4f0f6ff87e76a5fb8dd", "size": 632, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/auxil/proma2.f90", "max_stars_repo_name": "jerebenitez/IFE-simpact-openfoam", "max_stars_repo_head_hexsha": "2dbcbf3195b22fca1c80ad0da6b3822b6cad5cdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/auxil/proma2.f90", "max_issues_repo_name": "jerebenitez/IFE-simpact-openfoam", "max_issues_repo_head_hexsha": "2dbcbf3195b22fca1c80ad0da6b3822b6cad5cdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/auxil/proma2.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": 33.2631578947, "max_line_length": 70, "alphanum_fraction": 0.3591772152, "num_tokens": 191, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267830311354, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6558903595021932}} {"text": "! DART software - Copyright UCAR. This open source software is provided\n! by UCAR, \"as is\", without charge, subject to all terms of use at\n! http://www.image.ucar.edu/DAReS/DART/DART_download\n!\n! $Id$\n\nprogram sys_sim4\n\n! Work done during last week of January 2002 (28 Jan init) to investigate\n! impacts of sampling error from small ensembles on update for a single \n! variable that is exactly observed; applicable to observation variable \n! priors. Small sample estimates of variance have approximately normal\n! (or is it exactly normal) error distributions. BUT, when one computes\n! the updated variance there is a bias. Of course, one must also account\n! for the increased uncertainty in the estimate of the mean resulting from\n! errors in the computation of the variance.\n\nuse random_seq_mod, only : random_seq_type, init_random_seq, random_gaussian, &\n twod_gaussians, random_uniform\n\nimplicit none\n\n! version controlled file description for error handling, do not edit\ncharacter(len=256), parameter :: source = &\n \"$URL$\"\ncharacter(len=32 ), parameter :: revision = \"$Revision$\"\ncharacter(len=128), parameter :: revdate = \"$Date$\"\n\ntype (random_seq_type) :: r\ndouble precision, allocatable :: rnum(:), var_hist(:)\ndouble precision :: sample_mean, sample_sigma_y_p\ndouble precision :: c(2, 2), sum_err_var, sigma_y_p, sigma_y_o, sigma_x_p\ndouble precision :: y_truth, y_o, sample_correl, reg_coef, sample_reg_coef\ndouble precision :: sigma_y_u, y_u, sigma_x_u, x_u, sample_x_u, x_error\ndouble precision :: x_error_var, total_err_var, mean(2), correl, est_err_var\ndouble precision :: temp_sum, pe_2_sum, xx, s_xx, s_xx_2, xx_mean, xx_var\ndouble precision, allocatable :: x_mean(:), x_var(:)\ndouble precision :: sum_sample_mean, sum_sample_sigma, sum_y_u, sum_sigma_y_u, sum_y_u_2\ndouble precision :: sum_err, sum_err_2, inf_sigma_y_u, var_mean, var_var\ninteger :: n, i, j, n_samples, index\n\n! Initialize repeatable random sequence\ncall init_random_seq(r) \n\n! Initialize error accumulation for averaging\nsum_err_var = 0.0\nmean = 0.0; temp_sum = 0.0; pe_2_sum = 0.0; \n\n! For now have a set of free parameters that may be too large\nwrite(*, *) 'Input prior variance of observation variable'\nread(*, *) sigma_y_p\nwrite(*, *) 'Input variance of observing instrument'\nread(*, *) sigma_y_o\nwrite(*, *) 'Input ensemble size'\nread(*, *) n\n\n! Allocate storage for computing sample variance \nallocate(rnum(n))\n\nwrite(*, *) 'Input number of samples for statistics'\nread(*, *) n_samples\nallocate(var_hist(n_samples))\n\nsum_sample_mean = 0.0\nsum_sample_sigma = 0.0\nsum_y_u = 0.0; sum_y_u_2 = 0.0\nsum_sigma_y_u = 0.0\nsum_err = 0.0; sum_err_2 = 0.0\n\n! Loop through the number of samples\ndo i = 1, n_samples\n\n! Produce a sample of an observation yo by getting truth from prior\n! and adding on sample from observatoinal error distribution\n y_truth = random_gaussian(r, dble(0.0), sqrt(sigma_y_p))\n y_o = y_truth + random_gaussian(r, dble(0.0), sqrt(sigma_y_o))\n\n! Compute the sample variance for this ensemble size\n do j = 1, n\n rnum(j) = random_gaussian(r, dble(0.0), sqrt(sigma_y_p))\n end do\n\n! Compute the sample variance\n call sample_mean_var(rnum, n, sample_mean, sample_sigma_y_p)\n sum_sample_mean = sum_sample_mean + sample_mean\n sum_sample_sigma = sum_sample_sigma + sample_sigma_y_p\n var_hist(i) = sample_sigma_y_p\n\n! write(*, *) 'sample mean and variance ', real(sample_mean), real(sample_sigma_y_p)\n\n! Compute the updated covariance and mean for y given this observation\n sigma_y_u = (1.0 / (1.0 / sample_sigma_y_p + 1.0 / sigma_y_o))\n y_u = sigma_y_u * (0.0 + y_o / sigma_y_o)\n\n sum_y_u = sum_y_u + y_u\n sum_y_u_2 = sum_y_u_2 + y_u**2\n sum_sigma_y_u = sum_sigma_y_u + sigma_y_u\n sum_err = sum_err + y_u - y_truth\n sum_err_2 = sum_err_2 + (y_u - y_truth) ** 2\n \n\nend do\n\nwrite(*, *)'mean sample mean and var ', real(sum_sample_mean / n_samples), real(sum_sample_sigma / n_samples)\nwrite(*, *) 'mean update mean and var ', real(sum_y_u / n_samples), real(sum_sigma_y_u / n_samples)\nwrite(*, *) 'mean err ', real(sum_err / n_samples), real(sum_err_2 / n_samples)\n\n! Correct updated error variance is computed here\ninf_sigma_y_u = 1.0 / (1.0 / sigma_y_p + 1.0 / sigma_y_o)\nwrite(*, *) 'infinite sample updated error variance ', real(inf_sigma_y_u)\nwrite(*, *) '---------------------------------'\n\n! Output some ratios of the spread measure\nwrite(*, *) 'ratio of predicted var to correct ', real((sum_sigma_y_u / n_samples) / inf_sigma_y_u), &\n real(inf_sigma_y_u / (sum_sigma_y_u / n_samples))\nwrite(*, *) 'ratio of actual var to correct ', real((sum_err_2 / n_samples) / inf_sigma_y_u)\n\n! Compute variance of original sampled variance\ncall sample_mean_var(var_hist, n_samples, var_mean, var_var)\nwrite(*, *) '-----------------------------------'\nwrite(*, *) 'original sample mean and var of var ', real(var_mean), real(var_var)\nwrite(*, *) 'predicted var of var is ', 2.0 * sigma_y_p**4 / (n - 1.0)\n\n\nif(1 == 1) stop\n\n! Output the expected value of the mean x\nwrite(*, *) 'Expected updated mean is ', sum(x_mean) / n_samples\n\n! Now compute the expected value of the updated variance by doing sampling\n! The distribution is a sum of Gaussians with means and variance given\n! by x_mean and x_var; each is equally likely. So, do a sample, randomly\n! select a 'kernel', then randomly select a value from it.\ns_xx = 0.0\ns_xx_2 = 0.0\ndo i = 1, 10 * n_samples\n index = random_uniform(r) * n_samples + 1\n if(index < 1 .or. index > n_samples) then\n write(*, *) 'bad index ', i, index\n stop\n end if\n if(i / 500000 * 500000 == i) then\n write(*, *) 'mean, var ', i, index, real(x_mean(index)), real(x_var(index))\n endif\n xx = random_gaussian(r, x_mean(index), sqrt(x_var(index)))\n s_xx = s_xx + xx\n s_xx_2 = s_xx_2 + xx**2\nend do\n\nxx_mean = s_xx / (10.0 * n_samples)\nwrite(*, *) 'Sampled mean is ', xx_mean\nwrite(*, *) 'Expected mean is ', x_u\nxx_var = (s_xx_2 - (10.0 * n_samples) * xx_mean**2) / &\n (10.0 * n_samples - 1.0)\nwrite(*, *) 'Sampled variance is ', xx_var\nwrite(*, *) 'Expected raw var is ', sigma_x_u\nwrite(*, *) 'Mean variance is ', s_xx_2 / (10.0 * n_samples)\n\n\n\nif(1 == 1) stop\n\n! Output the mean total_err_var\nwrite(*, *) '----------'\nwrite(*, *) 'Large N Mean total_err_var is ', sigma_x_u\nwrite(*, *) 'Expected sample x variance is ', sum_err_var / n_samples\nwrite(*, *) '----------'\n\n! Using sample for product of correlation and y_0_2\nwrite(*, *) 'Expected error variance is ', &\n (temp_sum / n_samples )*(sigma_x_p / sigma_y_p) * (sigma_y_u / sigma_y_o)**2\n\n! Estimate using sample only for correlation\nwrite(*, *) 'Expected error variance, only sample correl ', &\n sigma_x_p * sigma_y_p * (pe_2_sum / n_samples) / (sigma_y_p + sigma_y_o)\n\nest_err_var = ((1.0 - correl**2)**2 / (n - 1.)) * sigma_x_p * sigma_y_p / &\n (sigma_y_p + sigma_y_o)\nwrite(*, *) 'Estimated correl expected variance is ', est_err_var\nwrite(*, *) '----------'\n\nwrite(*, *) 'pe_2_mean ', pe_2_sum / n_samples\nwrite(*, *) 'expected value of pe_2_mean ', (1.0 - correl**2)**2 / (n - 1.)\n\nwrite(*, *) '----------'\nwrite(*, *) 'net improvement ', (sigma_x_p - sum_err_var / n_samples) / &\n (sigma_x_p - sigma_x_u)\nwrite(*, *) 'Computed net improvement ', 1. - (pe_2_sum / n_samples) / correl**2\n\nend program sys_sim4\n\n!-----------------------------------------------------\n \nsubroutine comp_correl(ens, n, correl)\n \nimplicit none\n \ninteger, intent(in) :: n\ndouble precision, intent(in) :: ens(2, n)\ndouble precision, intent(out) :: correl\ndouble precision :: sum_x, sum_y, sum_xy, sum_x2, sum_y2\n\n\nsum_x = sum(ens(2, :))\nsum_y = sum(ens(1, :))\nsum_xy = sum(ens(2, :) * ens(1, :))\nsum_x2 = sum(ens(2, :) * ens(2, :))\n \n! Computation of correlation \nsum_y2 = sum(ens(1, :) * ens(1, :))\n\ncorrel = (n * sum_xy - sum_x * sum_y) / &\n sqrt((n * sum_x2 - sum_x**2) * (n * sum_y2 - sum_y**2))\n \nend subroutine comp_correl\n\n!----------------------------------------------------------------\n\nsubroutine sample_mean_var(x, n, mean, var)\n\nimplicit none\n\ninteger, intent(in) :: n\ndouble precision, intent(in) :: x(n)\ndouble precision, intent(out) :: mean, var\n\ndouble precision :: sx, s_x2\n\nsx = sum(x)\ns_x2 = sum(x * x)\nmean = sx / n\nvar = (s_x2 - sx**2 / n) / (n - 1)\n\nend subroutine sample_mean_var\n\n", "meta": {"hexsha": "2c43250812be2bc8d8103dbdef2cca0d3eddf6d1", "size": 8298, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "assimilation_code/programs/system_simulation/sys_sim4.f90", "max_stars_repo_name": "hkershaw-brown/feature-preprocess", "max_stars_repo_head_hexsha": "fe2bd77b38c63fa0566c83ebc4d2fac1623aef66", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-07-05T03:43:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-05T11:39:49.000Z", "max_issues_repo_path": "assimilation_code/programs/system_simulation/sys_sim4.f90", "max_issues_repo_name": "hkershaw-brown/feature-preprocess", "max_issues_repo_head_hexsha": "fe2bd77b38c63fa0566c83ebc4d2fac1623aef66", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-03-31T04:16:45.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-31T04:16:45.000Z", "max_forks_repo_path": "assimilation_code/programs/system_simulation/sys_sim4.f90", "max_forks_repo_name": "hkershaw-brown/feature-preprocess", "max_forks_repo_head_hexsha": "fe2bd77b38c63fa0566c83ebc4d2fac1623aef66", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-20T23:36:16.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-20T23:36:16.000Z", "avg_line_length": 35.1610169492, "max_line_length": 109, "alphanum_fraction": 0.6744998795, "num_tokens": 2459, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267626522813, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6558903393272005}} {"text": " subroutine far(y,c,s,r,in,r2,sig,n,p,po,pv,ier,io)\r\nc********************************************\r\nc Multi level iterative AR fit which loops back to discard lags\r\nc whose coefficients have prob value of abs(t) statistics < pv\r\nc Input: y - n observations, p - order in, pv - two sided p-value\r\nc Output: c - po AR coefficients, s - standard errors of c coeff's\r\nc r(1),...,r(n) - residuals\r\nc r2 - R square, sig - standard deviation of residuals\r\nc in - array of lag values for significant lags, po - order out\r\nc Version 3-12-2005\r\nc ier = 1: A is not positive definite, ier = 2: p < 1, ier = 3: p > n/2\r\nc============================================\r\n allocatable::a,b,d,w\r\n integer p,pi,po\r\n integer in(p)\r\n real y(n),r(n),s(p),pv\r\n real*8 c(p),a(:),b(:),w(:),d(:),sy,ssy\r\n intent(in) y,n,p,pv\r\n intent(out) c,s,r,in,po\r\nc****************************\r\nc Trap p\r\n if(p<1) then\r\n write(io,*) 'p in AR(p) ',p,' < 1'\r\n ier=2\r\n return\r\n elseif(p>n/2) then\r\n write(io,*) 'p in AR(p) ',p,' > n/2 ',n/2,' n = ',n\r\n ier=3\r\n return\r\n endif\r\nc-------\r\n allocate(a(0:p*p-1),b(0:p),d(0:p),w(0:p),stat=ibad)\r\n if(ibad/=0) then\r\n write(io,*) 'Unable to allocate work space for arrays in far'\r\n return\r\n endif\r\nc Covariances in a\r\n call cr(y,a,b,w,sy,ssy,n,p,io)\r\n do k=1,p\r\n c(k)=0.d0\r\n in(k)=k\r\n enddo\r\n pi=p\r\n po=p-1\r\n dowhile(po>0)\r\nc Iteration on ols\r\n call ar(y,c,s,r,a,b,d,w,n,p,sy,ssy,r2,sig,pv,ier,in,pi,po,io)\r\n if(poprb) then\r\n po=po+1\r\n in(po)=in(k)\r\n endif\r\n enddo\r\nc-------\r\n if(po0) then\r\nc Reduce down the covariance matrix\r\n call reduce(a,b,w,ssy,p,po,in,io)\r\n endif\r\nc-------\r\n return\r\n end\r\nc\r\nc===========================================\r\nc\r\n subroutine cr(y,a,b,w,sy,ssy,n,p,io)\r\nc********************************************\r\nc Covariances of y in a & variances in b,w\r\nc sy - Mean of y, ssy - Sum of squares of y\r\nc============================================\r\n integer p,t\r\n real y(n)\r\n real*8 a(p*p),b(p),w(p),sy,ssy,ac\r\n intent(in) y,n,p\r\n intent(out) a,b,w,sy,ssy\r\nc********************************************\r\nc Compute mean\r\n sy=0.d0\r\n do t=1,n\r\n sy=sy+dble(y(t))\r\n enddo\r\n sy=sy/dfloat(n)\r\nc-------\r\nc Compute sums\r\n ssy=(dble(y(n))-sy)*(dble(y(n))-sy)\r\n do k=1,p\r\n ac=0.d0\r\nc Compute covariances\r\n do t=1,n-k\r\n ac=ac+(dble(y(t))-sy)*(dble(y(t+k))-sy)\r\n if(k==1) then\r\n ssy=ssy+(dble(y(t))-sy)*(dble(y(t))-sy)\r\n endif\r\n enddo\r\n b(k)=ac\r\n w(k)=ac\r\n enddo\r\nc-------\r\nc Put in upper triangle of matrix a\r\n a(p*p)=ssy\r\n do j=1,p-1\r\n do k=j+1,p\r\n a((k-1)*p+j)=b(k-j)\r\n enddo\r\n a((j-1)*p+j)=ssy\r\n enddo\r\nc-------\r\n return\r\n end\r\nc\r\nc===========================================\r\nc\r\n subroutine reduce(a,b,w,ssy,p,po,in,io)\r\nc********************************************\r\nc Rearrange a & b for reduced least squares fit\r\nc============================================\r\n integer p,po\r\n integer in(p)\r\n real*8 a(p*p),b(p),w(p),ssy\r\n intent(in) w,ssy,in,p,po\r\n intent(out) a,b\r\nc********************************************\r\n do k1=1,po\r\n b(k1)=w(in(k1))\r\n a((k1-1)*po+k1)=ssy\r\n if(po>0) then\r\n do k2=k1+1,po\r\n a((k2-1)*po+k1)=w(in(k2)-in(k1))\r\n enddo\r\n endif\r\n enddo\r\nc-------\r\n return\r\n end\r\n", "meta": {"hexsha": "6e84e4b82c7e9520299901bac1d3da969e01785d", "size": 5778, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "far.for", "max_stars_repo_name": "emammendes/bispectrum", "max_stars_repo_head_hexsha": "03d46999d478911615dc01c7d9108870eadc9ab6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2015-09-29T05:27:08.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-09T09:09:36.000Z", "max_issues_repo_path": "far.for", "max_issues_repo_name": "emammendes/bispectrum", "max_issues_repo_head_hexsha": "03d46999d478911615dc01c7d9108870eadc9ab6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "far.for", "max_forks_repo_name": "emammendes/bispectrum", "max_forks_repo_head_hexsha": "03d46999d478911615dc01c7d9108870eadc9ab6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.7788461538, "max_line_length": 74, "alphanum_fraction": 0.4440983039, "num_tokens": 1901, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.7662936430859598, "lm_q1q2_score": 0.6558332933488384}} {"text": "program c\n use utilities\n use percolation\n\n implicit none\n\n integer :: i,j,k, fileunit\n integer, parameter :: L = 1024, num_probabilities = 50, num_samples = 50\n real(kind=dp), dimension(:), allocatable :: probabilities, spanning_densities\n real(kind=dp), dimension(:), allocatable :: estimated_densities\n character(len=:), allocatable :: fmtstring, filename\n real(kind=dp) :: beta, const\n\n probabilities = linspace(pc + 0.000001d0, 1.02d0*pc, num_probabilities)\n\n spanning_densities = [ (spanning_density(probabilities(i), L, num_samples), &\n i = 1, num_probabilities) ]\n\n call linfit(log10(probabilities - pc), log10(spanning_densities), beta, const)\n\n estimated_densities = (probabilities - pc)**beta * 10**const\n\n fmtstring = \"(f0.6,x,f0.6,x,f0.6)\"\n filename = \"tmp/c_P.dat\"\n open(newunit=fileunit, file=filename, status=\"replace\")\n\n do i=1, num_probabilities\n write(unit=fileunit, fmt=fmtstring) probabilities(i), spanning_densities(i), &\n estimated_densities(i)\n end do\n close(unit=fileunit)\n\n open(newunit=fileunit, file=\"tmp/c_beta.dat\", status=\"replace\")\n write(unit=fileunit, fmt=\"(f0.3)\") beta\n close(unit=fileunit)\n\nend program c\n", "meta": {"hexsha": "c1e00eb28e61145b1aa9ffdc48a4aae19e2d529d", "size": 1285, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/c.f90", "max_stars_repo_name": "anjohan/fys4460-3", "max_stars_repo_head_hexsha": "8dd9dabbfd55ab82f9fcb9bc0b90ce6188d9a99c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-06-28T17:49:29.000Z", "max_stars_repo_stars_event_max_datetime": "2018-06-28T17:49:29.000Z", "max_issues_repo_path": "src/c.f90", "max_issues_repo_name": "anjohan/fys4460-3", "max_issues_repo_head_hexsha": "8dd9dabbfd55ab82f9fcb9bc0b90ce6188d9a99c", "max_issues_repo_licenses": ["MIT"], "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/c.f90", "max_forks_repo_name": "anjohan/fys4460-3", "max_forks_repo_head_hexsha": "8dd9dabbfd55ab82f9fcb9bc0b90ce6188d9a99c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-06-28T17:51:37.000Z", "max_forks_repo_forks_event_max_datetime": "2018-06-28T17:51:37.000Z", "avg_line_length": 33.8157894737, "max_line_length": 86, "alphanum_fraction": 0.6513618677, "num_tokens": 347, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6558332933488383}} {"text": "program functiontests\n use prep\n use detgen\n use projection\n use gramschmidt, only: prtmtx, mgs, mult, orth\n\n implicit none\n\n\n integer(i16b) :: det(2)\n integer:: i, j, n, m, k\n real(rk), allocatable ::z, A(:, :), Q(:, :), R(:, :)\n !Lz_det Szt2_det tested, correct.\n !det(1) = 0\n !det(2) = 0\n !do i = 1, 10\n ! det(1) = det(1) + 1\n ! do j = 1, 10\n ! det(2) = det(2) + 1\n ! write(*, '(2b16, 2I8)') det(1:2), Lz_det(det), Szt2_det(det)\n ! enddo\n !enddo\n ! n = 2\n ! m = 8\n ! allocate(A(n, n), Q(n, n), R(n, n))\n ! A(1, :) = (/-1., 1./)\n ! A(2, :) = (/2., -2./)\n\n !A(1, :) = (/1., 2., 3., 4./)\n !A(2, :) = (/5.,6.,7.,8./)\n !A(3, :) = (/0.,9.,10.,11./)\n !A(4, :) = (/0.,0.,12.,13./)\n ! call orth(A, Q, R, m, n)\n\n\n\n\n\nend program functiontests\n\n \n", "meta": {"hexsha": "fb35ccfeaabb2b2bbbe98794a15d86b497c6b4b0", "size": 909, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "functiontests.f90", "max_stars_repo_name": "MingtongH/csfcal", "max_stars_repo_head_hexsha": "712b6d098426a0c84731575288b033736096ebd9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "functiontests.f90", "max_issues_repo_name": "MingtongH/csfcal", "max_issues_repo_head_hexsha": "712b6d098426a0c84731575288b033736096ebd9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "functiontests.f90", "max_forks_repo_name": "MingtongH/csfcal", "max_forks_repo_head_hexsha": "712b6d098426a0c84731575288b033736096ebd9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.6428571429, "max_line_length": 75, "alphanum_fraction": 0.3861386139, "num_tokens": 376, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511322604133, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6558332866469493}} {"text": "C NCLFORTSTART\n subroutine gamfitd3 (datarr, n, dmsg, pcrit, invscale\n + ,alpha , scale, shape, pzero,ier)\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\nc based upon: www.unicam.it/matinf/pasef/docs/CDIIIsem/home/pidieffe/spi.pdf\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\nc Estimate incomplete gamma parameters.\nc\nc Input:\nc\tdatarr - data array\nc\tn - size of datarr\nc\tdmsg - missing data\nc\tpcrit - scalar (int,float,double) specifying % non missing data\nc\tinvscale - if invscale=1, then return (1/beta)\nc\nc Output:\nc\talpha (???), beta (scale), eta (shape) - gamma parameters\nc\tpzero - probability of zero.\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\n implicit none\nc INPUT\n integer n, invscale, ier\n double precision datarr(n), dmsg, pcrit\nc OUTPUT\n double precision shape, scale, alpha, pzero\nc NCLEND\nc LOCAL \n integer i, nact, nmsg\n double precision sum, sumlog, av, pobs, pc\n double precision beta, eta\nc double precision s, kappa\n\n shape = dmsg\n scale = dmsg\n alpha = dmsg\n\n beta = scale\n eta = shape\n pzero = dmsg\n\n ier = 0\n if (n .le. 0) then\n ier = 1\nc c c write(*, *) 'Error in gamfit - empty data array'\n return\n end if\n\n sum = 0.0d0\n sumlog = 0.0d0\n pzero = 0.0d0\n nact = 0\n nmsg = 0\n\nc\tcompute sums and counts\n\n do i = 1, n\n if (datarr(i) .ne. dmsg) then\n if (datarr(i) .gt. 0.0d0) then\n sum = sum + datarr(i)\n sumlog = sumlog + log(datarr(i))\n nact = nact + 1\n else\n pzero = pzero + 1.0d0\n end if\n else\n nmsg = nmsg+1\n end if\n end do\nc pobs id the total # of non-missing obs\n pobs = nact + pzero \n pc = 100d0*pobs/n\n if (pc.lt.pcrit) then\n ier = 2\nc c c write(*, *) 'too few observations'\n return\n end if\n\n pzero = pzero/pobs\n if (nact .gt. 0) av = sum / nact\n\nc\tBogus data array but do something reasonable\n if (nact .eq. 1) then\n alpha = 0.0d0\n eta = 1.0d0\n beta = av\n return\n end if\n\nc\tThey were all zeroes.\n if (pzero .eq. 1) then\n alpha = 0.0d0\n eta = 1.0d0\n beta = av\n return\n end if\n\nc\tUse MLE (Maximum Liklihood Estimate)\nc A Note on the Gamma Distribution\nc Thom (1958): Monthly Weather Review, pp 117-122.\nc eqn 22 for gamma; just above eqn 21 \"A\" => alpha\n\n\n alpha = log(av)-(sumlog/nact)\n eta = (1.0d0+sqrt(1.0d0+4.0d0*alpha/3.0d0))/(4.0d0*alpha)\n beta = av/eta\n\nc ------------\nc http://en.wikipedia.org/wiki/Gamma_distribution#Maximum_likelihood_estimation\nc alpha is \"s\" at the above url\nc eta (shape) is approximately \"kappa\" at the above url\nc The numbers for eta and kappa are very similar\n\nc c c s = alpha\nc c c kappa = (3-s+sqrt((s-3)**2 + 24*s))/(12*s)\nc ------------\n\n if (invscale.eq.1 .and. beta.gt.0.0d0) then\n beta = 1.0d0/beta\n end if\n\n shape = eta \n scale = beta\n\n return\n end\n", "meta": {"hexsha": "83189c4caa615e4ed01587cdeb315fa4e425de68", "size": 3493, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ni/src/lib/nfpfort/gamfitd3.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "ni/src/lib/nfpfort/gamfitd3.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "ni/src/lib/nfpfort/gamfitd3.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 27.7222222222, "max_line_length": 79, "alphanum_fraction": 0.5422273118, "num_tokens": 1077, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511396138365, "lm_q2_score": 0.7662936377487304, "lm_q1q2_score": 0.6558332831460834}} {"text": "c***************************************************************************\nc\t\t\tOBL_ACC.F\nc*************************************************************************\nc OBL_ACC returns the BARYCENTRIC x,y,z components of the acc. on NBOD\nc particles due to the oblateness of mass(1) using \nc the values of J2RP2 and J4RP4 passed into the routine.\nc (J2RP2 for example is the product of \nc J_2 times the square of the central body's radius)\nc Here we return the net acc. produced\nc only by the J2 and J4 terms (i.e. including\nc neither the monopole nor higher order terms).\nc\t\nc\nc Input:\nc nbod ==> number of massive bodies (incl. central one)\nc mass(*) ==> masses of particles (real*8 array)\nc j2rp2 ==> scaled value of j2 moment (real*8 scalar)\nc j4rp4 ==> scaled value of j4 moment (real*8 scalar)\nc (real*8 vectors)\nc xh(*),yh(*),zh(*) ==> HELIO. positions of particles\nc irh(*) ==> 1./ magnitude of radius vector (real*8 vector)\nc (passed in to save calcs.)\nc Output:\nc aoblx(*),aobly(*),aoblz(*) ==> BARY. components of accel \nc (real*8 vectors) \nc\nc Remarks: aoblx(1) (for example) contains x-component of\nc bary. acc. of central body\nc Authors: Martin Duncan \nc Date: 3/4/94\nc Last revision: \n\n subroutine obl_acc(nbod,mass,j2rp2,j4rp4,xh,yh,zh,irh,\n & aoblx,aobly,aoblz)\n\n\n include '../swift.inc'\n\nc... Inputs Only: \n integer nbod\n real*8 j2rp2,j4rp4\n real*8 mass(NPLMAX)\n real*8 xh(NPLMAX),yh(NPLMAX),zh(NPLMAX),irh(NPLMAX)\n\nc... Output\n real*8 aoblx(NPLMAX),aobly(NPLMAX),aoblz(NPLMAX)\n\nc... Internals\n integer n\n real*8 rinv2,t0,t1,t2,t3\n real*8 fac1,fac2\n\nc----\nc... executable code\n\nc First get the bary acc. of each \"planet\" due to central oblate \"sun\"\n\n\tdo n =2,nbod\n\nc Note that here we assume we know inverse of radius rather than calc. it\nc from (x,y,z) to save the sqrt.\n\t rinv2= irh(n)**2\n\t t0 = -mass(1)*rinv2*rinv2*irh(n)\n\t t1 = 1.5d0 *j2rp2\n\t t2 = zh(n)*zh(n)*rinv2\n\t t3 = 1.875d0 *j4rp4*rinv2\n\n\t fac1 = t0*(t1 - t3 - (5.d0*t1 - (14.d0 - 21.d0*t2)*t3)*t2)\n\t fac2 = 2.d0*t0*(t1 - (2.d0 - (14.d0*t2/3.d0))*t3)\n \n aoblx(n) = fac1*xh(n)\n aobly(n) = fac1*yh(n)\n aoblz(n) = (fac1 + fac2)*zh(n)\n\n\tenddo\n\nc Now compute the bary. acc. of Sun due to all the planets\n\n\taoblx(1) = 0.d0\n\taobly(1) = 0.d0\n\taoblz(1) = 0.d0\n\tdo n=2,nbod\n\t aoblx(1) = aoblx(1) - mass(n)*aoblx(n)/mass(1)\n\t aobly(1) = aobly(1) - mass(n)*aobly(n)/mass(1)\n\t aoblz(1) = aoblz(1) - mass(n)*aoblz(n)/mass(1)\n\tenddo\n\n return\t\n end ! obl_acc.f\nc____________________________________________________________________________\n", "meta": {"hexsha": "a703fb2054e441fe697dd7537c9daa24f7034e05", "size": 2923, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/swift_j/obl/obl_acc.f", "max_stars_repo_name": "Simske/exostriker", "max_stars_repo_head_hexsha": "587b0af4c9cadb46637a4ac61a5392a596e966b1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 69, "max_stars_repo_stars_event_min_datetime": "2020-01-06T13:31:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T11:23:14.000Z", "max_issues_repo_path": "exostriker/source/swift_j/obl/obl_acc.f", "max_issues_repo_name": "sai-33/Exostriker", "max_issues_repo_head_hexsha": "f59fa51c6bdce3a2ed51d6621fe42bfcd8c2846f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 67, "max_issues_repo_issues_event_min_datetime": "2019-11-30T14:45:05.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-14T20:26:06.000Z", "max_forks_repo_path": "exostriker/source/swift_j/obl/obl_acc.f", "max_forks_repo_name": "sai-33/Exostriker", "max_forks_repo_head_hexsha": "f59fa51c6bdce3a2ed51d6621fe42bfcd8c2846f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2020-01-06T13:44:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T11:23:17.000Z", "avg_line_length": 32.1208791209, "max_line_length": 77, "alphanum_fraction": 0.5470407116, "num_tokens": 964, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896824119662, "lm_q2_score": 0.712232184238947, "lm_q1q2_score": 0.655816046728961}} {"text": " SUBROUTINE CALEBI \nC \nC CHANGE RECORD \nC ** CALEBI CALCULATES THE EXTERNAL BUOYANCY INTEGRALS \nC \n USE GLOBAL \n\tIMPLICIT NONE\n\tINTEGER::K,L,LLCM\n\tREAL::DBK,DZCBK\n\n REAL*4 DZCB(KCM)\n REAL*4 BK(KCM)\n\n PARAMETER(LLCM=200)\n! REAL*4 BI1T(LLCM)\n! REAL*4 BI2T(LLCM)\n! REAL*4 BET(LLCM)\n\n DO L=2,LA\n\n BI1(L)=0.\n BI2(L)=0.\n BE(L)=0.\n \n DO K=1,KC\n DZCB(K)=DZC(K)*B(L,K)\n ENDDO\n\n DBK=0. \n DO K=KC,1,-1\n DBK=DBK+DZCB(K) !DZC(K)*B(L,K)\n BK(K)=DBK-0.5*DZCB(K) !DZC(K)*B(L,K)\n ENDDO\n\n !Z(0)=0.\n !Z(K)=Z(K-1)+DZC(K)\n DO K=1,KC\n BE(L) =BE(L)+DZCB(K) !DZC(K)*B(L,K)\n DZCBK =DZC(K)*BK(K)\n BI1(L)=BI1(L)+DZCBK \n BI2(L)=BI2(L)+(DZCBK+0.5*(Z(K)+Z(K-1))*DZCB(K)) \n ENDDO\n\n ENDDO\n RETURN \n END \n\n", "meta": {"hexsha": "8218d9eab14d26206ccc362ea1c190d4a0cdfebd", "size": 912, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "EFDC_src/CALEBI.f", "max_stars_repo_name": "T-Carlotto/SW2D-EFDC", "max_stars_repo_head_hexsha": "7b01a41a308cb79db569a0e6291fe40797f3ef28", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 32, "max_stars_repo_stars_event_min_datetime": "2018-03-31T22:19:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-14T01:35:23.000Z", "max_issues_repo_path": "EFDC_src/CALEBI.f", "max_issues_repo_name": "T-Carlotto/SW2D-EFDC", "max_issues_repo_head_hexsha": "7b01a41a308cb79db569a0e6291fe40797f3ef28", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-04-02T06:13:13.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-10T07:15:07.000Z", "max_forks_repo_path": "EFDC_src/CALEBI.f", "max_forks_repo_name": "T-Carlotto/SW2D-EFDC", "max_forks_repo_head_hexsha": "7b01a41a308cb79db569a0e6291fe40797f3ef28", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2018-06-27T02:55:23.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-09T07:51:23.000Z", "avg_line_length": 19.0, "max_line_length": 58, "alphanum_fraction": 0.4385964912, "num_tokens": 383, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896737173119, "lm_q2_score": 0.7122321903471563, "lm_q1q2_score": 0.6558160461607245}} {"text": " REAL*8 FUNCTION TSTEP(F,FDOT,F2DOT,F3DOT,ETA)\n*\n*\n* General time-step criterion.\n* ----------------------------\n*\n IMPLICIT REAL*8 (A-H,O-Z)\n REAL*8 F(3),FDOT(3),F2DOT(3),F3DOT(3)\n*\n* Obtain new integration step using composite expression.\n* STEP = (ETA*(F*F2DOT + FDOT**2)/(FDOT*F3DOT + F2DOT**2))**0.5.\n*\n F2 = F(1)**2 + F(2)**2 + F(3)**2\n FDOT2 = FDOT(1)**2 + FDOT(2)**2 + FDOT(3)**2\n F2DOT2 = F2DOT(1)**2 + F2DOT(2)**2 + F2DOT(3)**2\n F3DOT2 = F3DOT(1)**2 + F3DOT(2)**2 + F3DOT(3)**2\n*\n TSTEP = (SQRT(F2*F2DOT2) + FDOT2)/(SQRT(FDOT2*F3DOT2) + F2DOT2)\n TSTEP = SQRT(ETA*TSTEP)\n*\n RETURN\n*\n END\n", "meta": {"hexsha": "d8e9ab3fcfb75f6c3d428916f5d24fa13e66d599", "size": 678, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/amuse/community/nbody6xx/src/tstep.f", "max_stars_repo_name": "rknop/amuse", "max_stars_repo_head_hexsha": "85d5bdcc29cfc87dc69d91c264101fafd6658aec", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 131, "max_stars_repo_stars_event_min_datetime": "2015-06-04T09:06:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-01T12:11:29.000Z", "max_issues_repo_path": "src/amuse/community/nbody6xx/src/tstep.f", "max_issues_repo_name": "rknop/amuse", "max_issues_repo_head_hexsha": "85d5bdcc29cfc87dc69d91c264101fafd6658aec", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 690, "max_issues_repo_issues_event_min_datetime": "2015-10-17T12:18:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:15:58.000Z", "max_forks_repo_path": "src/amuse/community/nbody6xx/src/tstep.f", "max_forks_repo_name": "rieder/amuse", "max_forks_repo_head_hexsha": "3ac3b6b8f922643657279ddee5c8ab3fc0440d5e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 102, "max_forks_repo_forks_event_min_datetime": "2015-01-22T10:00:29.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-09T13:29:43.000Z", "avg_line_length": 28.25, "max_line_length": 70, "alphanum_fraction": 0.5029498525, "num_tokens": 286, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896671963207, "lm_q2_score": 0.7122321781307374, "lm_q1q2_score": 0.6558160302675122}} {"text": " subroutine strap (x, y, n, sum)\n\nc Trapeziodal integration of y(x), result in sum\nc SINGLE PRECISION\nc modified by ala to handle cases for E i) cycle\n Am(i,j) = Am(i,j) + sum( &\n (phi_dx(:, :, ax, ay)*phi_dx(:, :, bx, by) &\n +phi_dy(:, :, ax, ay)*phi_dy(:, :, bx, by)) &\n * jac_det * wtq) / 2\n Am(i,j) = Am(i,j) + sum(fq * &\n phi_v(:, :, ax, ay)*phi_v(:, :, bx, by) &\n * jac_det * wtq)\n Bm(i,j) = Bm(i,j) + sum((phi_v(:, :, ax, ay)*phi_v(:, :, bx, by) &\n * jac_det * wtq))\n end do\n end do\n end do\n end do\nend do\ndo j = 1, size(Am, 2)\n do i = 1, j-1\n Am(i, j) = Am(j, i)\n Bm(i, j) = Bm(j, i)\n end do\nend do\nend subroutine\n\nend module\n\n\n\n\nprogram laplace2d_eig\n\nuse types, only: dp\nuse fe_mesh, only: cartesian_mesh_2d, cartesian_mesh_3d, &\n define_connect_tensor_2d, c2fullc_2d, fe2quad_2d\nuse laplace_assembly, only: assemble_2d\nuse feutils, only: get_parent_nodes, get_parent_quad_pts_wts, phih, dphih\nuse linalg, only: eigh\nuse constants, only: pi\nimplicit none\n\ninteger :: Nn, Ne\n! nodes(:, i) are the (x,y) coordinates of the i-th mesh node\nreal(dp), allocatable :: nodes(:, :)\ninteger, allocatable :: elems(:, :) ! elems(:, i) are nodes of the i-th element\ninteger :: Nq, p, Nb\nreal(dp), allocatable :: xin(:), xiq(:), wtq(:), A(:, :), B(:, :), c(:, :), &\n lam(:), wtq2(:, :), phihq(:, :), dphihq(:, :)\ninteger, allocatable :: ib(:, :, :), in(:, :, :)\nreal(dp) :: rmax\ninteger :: i, j, Nex, Ney\n\nNex = 1\nNey = 1\np = 3\nNq = 4\nrmax = pi/2\n\ncall cartesian_mesh_2d(Nex, Ney, [-rmax, -rmax], [rmax, rmax], nodes, elems)\nNn = size(nodes, 2)\nNe = size(elems, 2)\n\nprint *, \"Number of nodes:\", Nn\nprint *, \"Number of elements:\", Ne\n\nallocate(xin(p+1))\ncall get_parent_nodes(2, p, xin)\nallocate(xiq(Nq), wtq(Nq), wtq2(Nq, Nq))\ncall get_parent_quad_pts_wts(1, Nq, xiq, wtq)\nforall(i=1:Nq, j=1:Nq) wtq2(i, j) = wtq(i)*wtq(j)\nallocate(phihq(size(xiq), size(xin)))\nallocate(dphihq(size(xiq), size(xin)))\n! Tabulate parent basis at quadrature points\nforall(i=1:size(xiq), j=1:size(xin)) phihq(i, j) = phih(xin, j, xiq(i))\nforall(i=1:size(xiq), j=1:size(xin)) dphihq(i, j) = dphih(xin, j, xiq(i))\n\ncall define_connect_tensor_2d(Nex, Ney, p, 1, in)\ncall define_connect_tensor_2d(Nex, Ney, p, 2, ib)\nNb = maxval(ib)\nprint *, \"p =\", p\nprint *, \"DOFs =\", Nb\nallocate(A(Nb, Nb), B(Nb, Nb), c(Nb, Nb), lam(Nb))\n\ncall assemble_2d(xin, nodes, elems, ib, xiq, wtq2, phihq, dphihq, A, B)\ncall eigh(A, B, lam, c)\nprint *, \"Eigenvalues:\"\ndo i = 1, min(Nb, 20)\n print *, i, lam(i)\nend do\nend program\n", "meta": {"hexsha": "8b81a7e7c928da81399d5fde27c1d0d91c8c0dec", "size": 4583, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/fem/laplace2d_eig.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/tests/fem/laplace2d_eig.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/tests/fem/laplace2d_eig.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": 28.4658385093, "max_line_length": 79, "alphanum_fraction": 0.5555313114, "num_tokens": 1769, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543488, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6557958837445339}} {"text": " subroutine boost(q,pboost,qprime)\n implicit real*8 (a-h,o-z)\n\nc this subroutine performs the boost according to the vector pboost of \nc the fourvector q to the fourvector qprime. The vector q and the \nc resulting qprime might also have the same name in the call \nc Let's call rmboost the mass of pboost. With this transformation\nc if q= (rmboost,0,0,0), qprime=pboost \n \n\n dimension q(0:3), pboost(0:3), qprime (0:3)\n\n rmboost=pboost(0)**2-pboost(1)**2-pboost(2)**2-pboost(3)**2\n rmboost=sqrt(max(rmboost,0.d0))\n aux=(q(0)*pboost(0)+q(1)*pboost(1)+q(2)*pboost(2)+q(3)*pboost(3))\n & /rmboost\n aaux=(aux+q(0))/(pboost(0)+rmboost)\n qprime(0)=aux\n qprime(1)=q(1)+aaux*pboost(1)\n qprime(2)=q(2)+aaux*pboost(2)\n qprime(3)=q(3)+aaux*pboost(3)\n\n return\n end\n\n subroutine boostinv(q,pboost,qprime)\n implicit real*8 (a-h,o-z)\n\nc this subroutine performs the inverse boost according to the vector \nc pboost ( which corresponds to the boost according to pboost(0), \nc -pboost(i) ) of the fourvector q to the fourvector qprime. \nc The vector q and the resulting qprime might also have the same \nc name in the call \nc Let's call rmboost the mass of pboost. With this transformation\nc if q=pboost, qprime= (rmboost,0,0,0), \n\n dimension q(0:3), pboost(0:3), qprime (0:3)\n\n rmboost=pboost(0)**2-pboost(1)**2-pboost(2)**2-pboost(3)**2\n rmboost=sqrt(max(rmboost,0.d0))\n aux=(q(0)*pboost(0)-q(1)*pboost(1)-q(2)*pboost(2)-q(3)*pboost(3))\n & /rmboost\n aaux=(aux+q(0))/(pboost(0)+rmboost)\n qprime(0)=aux\n qprime(1)=q(1)-aaux*pboost(1)\n qprime(2)=q(2)-aaux*pboost(2)\n qprime(3)=q(3)-aaux*pboost(3)\n\n return\n end\n\n\n\n\n subroutine rot(p,q,pp)\n\n* the subroutine performs a rotation such that the 3-vector p goes into\n* the 3-vector pp. The rotation is such that the vector q', of the same\n* lenght as q but along the z axis, becomes q after the rotation\n \n implicit real*8 (a-h,o-z)\n\n dimension pp(3), p(3), q(3) \n\n\n qmod=sqrt(q(1)**2+q(2)**2+q(3)**2)\n if (qmod.eq.0.d0) then\n print*, ' ERROR in subroutine rot '\n print*, ' spatial q components are 0.d0 ! '\n stop\n endif\n\n cth=q(3)/qmod\n sth=1.d0-cth**2\n if (sth.eq.0.d0) then\n pp(1)=p(1)\n pp(2)=p(2)\n pp(3)=p(3)\n return\n endif\n sth=sqrt(sth)\n\n qmodt=sqrt(q(1)**2+q(2)**2)\n if (qmodt.eq.0.d0) then\n pp(1)=p(1)\n pp(2)=p(2)\n pp(3)=p(3)\n return\n endif\n \n cfi=q(1)/qmodt\n sfi=q(2)/qmodt\n\nc avoid possible problems if p and pp are the same vector:\n \n p1=p(1)\n p2=p(2)\n p3=p(3)\n\nc perform the rotation\n\n pp(1)=cth*cfi*p1-sfi*p2+sth*cfi*p3\n pp(2)=cth*sfi*p1+cfi*p2+sth*sfi*p3\n pp(3)=-sth *p1 +cth* p3\n\n\n return\n end\n\n subroutine rotinv(p,q,pp)\n* the subroutine performs a rotation such that the 3-vector p goes into\n* the 3-vector pp. The rotation is such that the vector q goes to the z axis.\n* It performs first a rotation around z which brings the vectot in the xz-plane and\n* then a rotaion around y which brings the vector along the z axis\n \n implicit real*8 (a-h,o-z)\n dimension pp(3), p(3), q(3) \n\n qmodt=q(1)**2+q(2)**2\n qmod=qmodt+q(3)**2\n qmodt=sqrt(qmodt)\n qmod=sqrt(qmod)\n\n if (qmod.eq.0.d0) then\n print*, ' ERROR in subroutine rot '\n print*, ' spatial q components are 0.d0 ! '\n stop\n endif\n\n cth=q(3)/qmod\n sth=1.d0-cth**2\n if (sth.eq.0.d0) then\n pp(1)=p(1)\n pp(2)=p(2)\n pp(3)=p(3)\n return\n endif\n sth=sqrt(sth)\n\n if (qmodt.eq.0.d0) then\n pp(1)=p(1)\n pp(2)=p(2)\n pp(3)=p(3)\n return\n endif\n \n cfi=q(1)/qmodt\n sfi=q(2)/qmodt\n\nc avoid possible problems if p and pp are the same vector: \n p1=p(1)\n p2=p(2)\n p3=p(3)\n\nc perform the rotation\n pp(1)=cth*cfi*p1+cth*sfi*p2-sth*p3\n pp(2)=-sfi*p1 +cfi*p2\n pp(3)=+sth*cfi*p1+sth*sfi*p2+cth* p3\n\n return\n end\n\n\n \n*****************************************************************************\n* Auxiliary subroutine\n* INPUT:\n* pbst : intermediate particle momentum\n* shat : the corresponding mass (assumed positive)\n* pmod : the absolute value of the 3-momentum of the two\n* daughter particles in the decay CM\n* xm1sq,xm2sq : the squared masses of the daughter particles\n* x1,x2 : two random numbers uniformly distributed in [0,1]\n* OUTPUT:\n* p1,p2 : the momenta of the two daughters in the frame in\n* which the intermediate particle has momentum pbst \n* p1 + p2 = pbst\n*\n* If pbst=(sqrt(shat),0,0,0) the boost reduces to the identity\n* Ezio May 2 2007\n* A rotation of the generated momentum has been added in such a way to assume as\n* z-axis the boost momentum\n* \n*****************************************************************************\n SUBROUTINE TWOBODY(pbst,shat,pmod,xm1sq,xm2sq,x1,x2,p1,p2)\n IMPLICIT NONE\n REAL*8 pbst(0:3),shat,pmod,xm1sq,xm2sq,x1,x2,p1(0:3),p2(0:3)\n* Local variables\n REAL*8 app,costh,sinth,ph,rmboost,aapp,pi,twopi\n INTEGER i\n PARAMETER (pi=3.141592653589793238462643d0,twopi=2.d0*pi)\n \n costh=min(x1*2.d0-1.d0,1.d0)\n costh=max(costh,-1.d0)\n sinth=sqrt(1.d0-costh*costh)\n ph=x2*twopi\n* p1\n p1(0)=sqrt(pmod*pmod+xm1sq)\n p1(1)=pmod*sinth*cos(ph)\n p1(2)=pmod*sinth*sin(ph)\n p1(3)=pmod*costh\n* rotate in such a way that angles are relative to the direction of pbst\n call rot(p1(1),pbst(1),p1(1))\n* boost back\n rmboost=sqrt(shat)\n app=(p1(0)*pbst(0)+p1(1)*pbst(1)+p1(2)*pbst(2)+p1(3)*pbst(3))\n & /rmboost\n aapp=(app+p1(0))/(pbst(0)+rmboost)\n p1(0)=app\n p1(1)=p1(1)+aapp*pbst(1)\n p1(2)=p1(2)+aapp*pbst(2)\n p1(3)=p1(3)+aapp*pbst(3)\n DO i=0,3\n p2(i)=pbst(i)-p1(i)\n ENDDO\n \n RETURN\n END\n \n\n\n*****************************************************************************\n* Auxiliary subroutine. Defines extrema for flat+Breit-Wigner+flat mapping\n* of resonances. Checks for position of estrsup,estrinf with respect to\n* spm1lo,spm1hi\n* INPUT:\n* estrsup,estrinf: upper and lower limit for the generated mass\n* spm1lo,spm1hi : lower and upper limit of the Breit-Wigner region\n* rmx1,gamx1 : mass and width of the resonance\n* OUTPUT:\n* alfa1,alfa2 : separation points in [0,1] between the three regions\n* Can also be 0 or 1. Some care necessary in this cases\n* auxalfa2,xf1_min,xf1_max,xw1_min,xw1_max,xf2_min,xf2_max\n* : auxiliary quantities used for generating the mass\n* and computing the jacobian\n*****************************************************************************\n SUBROUTINE PHSP_INI(estrsup,estrinf,spm1lo,spm1hi,\n & rmx1,gamx1,\n & alfa1,alfa2,auxalfa2,\n & xf1_min,xf1_max,xw1_min,xw1_max,xf2_min,xf2_max)\n \n IMPLICIT REAL*8(a-h,o-z)\n \n IF(estrsup.LE.spm1lo)THEN ! only flat1\n alfa2=1.d0\n alfa1=1.d0\n auxalfa2=alfa2\n xf1_max=estrsup\n xf1_min=estrinf\n ELSEIF(estrsup.LE.spm1hi)THEN ! flat1 + W/Z ?\n alfa2=1.d0\n auxalfa2=alfa2\n IF((estrinf.GE.spm1lo))THEN ! W/Z only\n alfa1=0.d0\n xw1_max=atan((estrsup**2-rmx1**2)/(gamx1*rmx1))\n xw1_min=atan((estrinf**2-rmx1**2)/(gamx1*rmx1))\n ELSE ! flat1 + W/Z !\n xw1_min=atan((spm1lo**2-rmx1**2)/(gamx1*rmx1))\n xw1_max=atan((estrsup**2-rmx1**2)/(gamx1*rmx1))\n\n rkappa2low=(xw1_max-xw1_min)*\n & ((spm1lo**2-rmx1**2)**2+(gamx1*rmx1)**2)\n & /(gamx1*rmx1)\n xf1_max=spm1lo\n xf1_min=estrinf\n rkappa1=(xf1_max-xf1_min)*2.d0*spm1lo\n* If rkappa2low=0 then estrsup is numerically indistinguishable from spm1lo\n IF(rkappa2low.LE.0.d0)THEN \n alfa1=1.d0\n auxalfa2=alfa2\n xf1_max=estrsup\n xf1_min=estrinf\n\t RETURN\n\t ENDIF\n rkappa=rkappa1/rkappa2low\n alfa1=rkappa/(rkappa+1.d0)\n ENDIF\n ELSE ! estrsup.GT.spm1hi: flat1 + W/Z + flat2 ?\n IF(estrinf.GE.spm1hi)THEN ! only flat2\n alfa1=0.d0\n alfa2=0.d0\n auxalfa2=alfa2\n xf2_max=estrsup\n xf2_min=estrinf\n ELSEIF((estrinf.GE.spm1lo))THEN ! W/Z + flat2 \n alfa1=0.d0\n xf2_max=estrsup\n xf2_min=spm1hi\n rkappa3=(xf2_max-xf2_min)*2.d0*spm1hi\n xw1_max=atan((spm1hi**2-rmx1**2)/(gamx1*rmx1))\n xw1_min=atan((estrinf**2-rmx1**2)/(gamx1*rmx1))\n rkappa2high=(xw1_max-xw1_min)*\n & ((spm1hi**2-rmx1**2)**2+(gamx1*rmx1)**2)\n & /(gamx1*rmx1)\n rk2=rkappa2high/rkappa3\nc alfa2=rk2/(rk2+1.d0)\n alfa2=0.5d0\n auxalfa2=alfa2\n ELSE ! flat + W/Z + flat\n xf2_max=estrsup\n xf2_min=spm1hi\n rkappa3=(xf2_max-xf2_min)*2.d0*spm1hi\n xw1_min=atan((spm1lo**2-rmx1**2)/(gamx1*rmx1))\n xw1_max=atan((spm1hi**2-rmx1**2)/(gamx1*rmx1))\n rkappa2high=(xw1_max-xw1_min)*\n & ((spm1hi**2-rmx1**2)**2+(gamx1*rmx1)**2)\n & /(gamx1*rmx1)\n rkappa2low=(xw1_max-xw1_min)*\n & ((spm1lo**2-rmx1**2)**2+(gamx1*rmx1)**2)\n & /(gamx1*rmx1)\n rk2=rkappa2high/rkappa3\nc auxalfa2=rk2/(rk2+1.d0)\n auxalfa2=0.5d0\nc auxalfa2=8.d0/9.d0\n xf1_min=estrinf\n xf1_max=spm1lo\n rkappa1=(xf1_max-xf1_min)*2.d0*spm1lo\n rk1=rkappa1/rkappa2low*auxalfa2\nc alfa1=rk1/(rk1+1.d0)\n alfa1=1.d0/3.d0\nc alfa1=1.d0/10.d0\n alfa2=auxalfa2*(1.d0-alfa1)+alfa1\n ENDIF\n ENDIF\n \n RETURN\n END\n\n*****************************************************************************\n* Auxiliary subroutine. Defines extrema for flat+Breit-Wigner+flat\n* +Breit-Wigner+flat mapping\n* of resonances. Checks for position of estrsup,estrinf with respect to\n* spm1lo,spm1hi\n* INPUT:\n* estrsup,estrinf: upper and lower limit for the generated mass\n* spm1lo,spm1hi : lower and upper limit of first Breit-Wigner region\n* rmx1,gamx1 : mass and width of first resonance\n* spm2lo,spm2hi : lower and upper limit of second Breit-Wigner region\n* rmx2,gamx2 : mass and width of second resonance\n* OUTPUT:\n* alfa1,alfa2,alfa3,alfa4: separation points in [0,1] between the five regions\n* Can also be 0 or 1. Some care necessary in this cases\n* auxalfa2,xf1_min,xf1_max,xw1_min,xw1_max,xf2_min,xf2_max,xw2_min,xw2_max,\n* xf3_min,xf3_max,auxalfa3,auxalfa4\n* : auxiliary quantities used for generating the mass\n* and computing the jacobian\n*****************************************************************************\n SUBROUTINE PHSP_INI5(estrsup,estrinf,\n & spm1lo,spm1hi,rmx1,gamx1,\n & spm2lo,spm2hi,rmx2,gamx2,\n & alfa1,alfa2,auxalfa2,\n & alfa3,auxalfa3,alfa4,auxalfa4,\n & xf1_min,xf1_max,xw1_min,xw1_max,xf2_min,xf2_max,\n & xw2_min,xw2_max,xf3_min,xf3_max)\n \n IMPLICIT REAL*8(a-h,o-z)\n \n IF(estrsup.LE.spm1lo)THEN ! only flat1\n alfa1=1.d0\n alfa2=1.d0\n alfa3=1.d0\n alfa4=1.d0\n auxalfa4=alfa4\n auxalfa3=alfa3\n auxalfa2=alfa2\n xf1_max=estrsup\n xf1_min=estrinf\n ELSEIF(estrsup.LE.spm1hi)THEN ! flat1 + res1 ?\n alfa2=1.d0\n alfa3=1.d0\n alfa4=1.d0\n auxalfa4=alfa4\n auxalfa3=alfa3\n auxalfa2=alfa2\n IF((estrinf.GE.spm1lo))THEN ! res1 only\n alfa1=0.d0\n xw1_max=atan((estrsup**2-rmx1**2)/(gamx1*rmx1))\n xw1_min=atan((estrinf**2-rmx1**2)/(gamx1*rmx1))\n ELSE ! flat1 + res1 !\n xw1_min=atan((spm1lo**2-rmx1**2)/(gamx1*rmx1))\n xw1_max=atan((estrsup**2-rmx1**2)/(gamx1*rmx1))\n rkappa2low=(xw1_max-xw1_min)*\n & ((spm1lo**2-rmx1**2)**2+(gamx1*rmx1)**2)\n & /(gamx1*rmx1)\n xf1_max=spm1lo\n xf1_min=estrinf\n rkappa1=(xf1_max-xf1_min)*2.d0*spm1lo\n* If rkappa2low=0 then estrsup is numerically indistinguishable from spm1lo\n IF(rkappa2low.LE.0.d0)THEN \n alfa1=1.d0\n xf1_max=estrsup\n xf1_min=estrinf\n RETURN\n ENDIF\n rk1=rkappa1/rkappa2low\n alfa1=rk1/(rk1+1.d0)\n ENDIF\n ELSEIF(estrsup.LE.spm2lo)THEN ! estrsup.GT.spm1hi: flat1 + res1 + flat2 ?\n alfa3=1.d0\n alfa4=1.d0\n auxalfa4=alfa4\n auxalfa3=alfa3\n IF(estrinf.GE.spm1hi)THEN ! only flat2\n alfa1=0.d0\n alfa2=0.d0\n auxalfa2=alfa2\n xf2_max=estrsup\n xf2_min=estrinf\n ELSEIF((estrinf.GE.spm1lo))THEN ! res1 + flat2 \n alfa1=0.d0\n xf2_max=estrsup\n xf2_min=spm1hi\n rkappa3low=(xf2_max-xf2_min)*2.d0*spm1hi\n xw1_max=atan((spm1hi**2-rmx1**2)/(gamx1*rmx1))\n xw1_min=atan((estrinf**2-rmx1**2)/(gamx1*rmx1))\n rkappa2high=(xw1_max-xw1_min)*\n & ((spm1hi**2-rmx1**2)**2+(gamx1*rmx1)**2)\n & /(gamx1*rmx1)\n rk2=rkappa2high/rkappa3low\n alfa2=rk2/(rk2+1.d0)\n auxalfa2=alfa2\n ELSE ! flat1 + res1 + flat2\n xf2_max=estrsup\n xf2_min=spm1hi\n rkappa3low=(xf2_max-xf2_min)*2.d0*spm1hi\n xw1_min=atan((spm1lo**2-rmx1**2)/(gamx1*rmx1))\n xw1_max=atan((spm1hi**2-rmx1**2)/(gamx1*rmx1))\n rkappa2low=(xw1_max-xw1_min)*\n & ((spm1lo**2-rmx1**2)**2+(gamx1*rmx1)**2)\n & /(gamx1*rmx1)\n rkappa2high=(xw1_max-xw1_min)*\n & ((spm1hi**2-rmx1**2)**2+(gamx1*rmx1)**2)\n & /(gamx1*rmx1)\n rk2=rkappa2high/rkappa3low\nccc auxalfa2=rk2/(rk2+1.d0)\n auxalfa2=0.5d0\n xf1_min=estrinf\n xf1_max=spm1lo\n rkappa1=(xf1_max-xf1_min)*2.d0*spm1lo\n rk1=rkappa1/rkappa2low*auxalfa2\nCCC alfa1=rk1/(rk1+1.d0)\n alfa1=1.d0/3.d0\n alfa2=auxalfa2*(1.d0-alfa1)+alfa1\n ENDIF\n ELSEIF(estrsup.LE.spm2hi)THEN \n ! estrsup.GT.spm2lo: flat1 + res1 + flat2 + res2?\n alfa4=1.d0\n auxalfa4=alfa4\n IF(estrinf.GE.spm2lo)THEN ! only res2\n alfa1=0.d0\n alfa2=0.d0\n alfa3=0.d0\n auxalfa3=alfa3\n auxalfa2=alfa2\n xw2_max=atan((estrsup**2-rmx2**2)/(gamx2*rmx2))\n xw2_min=atan((estrinf**2-rmx2**2)/(gamx2*rmx2))\n ELSEIF(estrinf.GE.spm1hi)THEN ! flat2 + res2\n alfa1=0.d0\n alfa2=0.d0\n auxalfa2=alfa2\n xw2_min=atan((spm2lo**2-rmx2**2)/(gamx2*rmx2))\n xw2_max=atan((estrsup**2-rmx2**2)/(gamx2*rmx2))\n rkappa4low=(xw2_max-xw2_min)*\n & ((spm2lo**2-rmx2**2)**2+(gamx2*rmx2)**2)\n & /(gamx2*rmx2)\n* If rkappa4low=0 then estrsup is numerically indistinguishable from spm2lo\n IF(rkappa4low.LE.0.d0)THEN \n alfa3=1.d0\n auxalfa3=alfa3\n xf2_max=estrsup\n xf2_min=estrinf\n RETURN\n ENDIF\n xf2_max=spm2lo\n xf2_min=estrinf\n rkappa3high=(xf2_max-xf2_min)*2.d0*spm2lo\n rk3=rkappa3high/rkappa4low\n alfa3=rk3/(rk3+1.d0)\n auxalfa3=alfa3\n ELSEIF(estrinf.GE.spm1lo)THEN ! res1 + flat2 + res2\n alfa1=0.d0\n xw2_min=atan((spm2lo**2-rmx2**2)/(gamx2*rmx2))\n xw2_max=atan((estrsup**2-rmx2**2)/(gamx2*rmx2))\n rkappa4low=(xw2_max-xw2_min)*\n & ((spm2lo**2-rmx2**2)**2+(gamx2*rmx2)**2)\n & /(gamx2*rmx2)\n* If rkappa4low=0 then estrsup is numerically indistinguishable from spm2lo\n IF(rkappa4low.LE.0.d0)THEN \n auxalfa3=1.d0\n xf2_max=estrsup\n ELSE\n xf2_max=spm2lo\n rkappa3high=(xf2_max-xf2_min)*2.d0*spm2lo\n rk3=rkappa3high/rkappa4low\nccc auxalfa3=rk3/(rk3+1.d0)\n auxalfa3=0.5d0\n ENDIF\n xf2_min=spm1hi\n rkappa3low=(xf2_max-xf2_min)*2.d0*spm1hi\n xw1_max=atan((spm1hi**2-rmx1**2)/(gamx1*rmx1))\n xw1_min=atan((estrinf**2-rmx1**2)/(gamx1*rmx1))\n rkappa2high=(xw1_max-xw1_min)*\n & ((spm1hi**2-rmx1**2)**2+(gamx1*rmx1)**2)\n & /(gamx1*rmx1)\n rk2=rkappa2high/rkappa3low*auxalfa3\nccc alfa2=rk2/(rk2+1.d0)\n alfa2=1.d0/3.d0\n auxalfa2=alfa2\n alfa3=auxalfa3*(1.d0-alfa2)+alfa2\n IF(rkappa4low.LE.0.d0) alfa3=1.d0 \n ELSE ! flat1 + res1 + flat2 + res2\n xw2_min=atan((spm2lo**2-rmx2**2)/(gamx2*rmx2))\n xw2_max=atan((estrsup**2-rmx2**2)/(gamx2*rmx2))\n rkappa4low=(xw2_max-xw2_min)*\n & ((spm2lo**2-rmx2**2)**2+(gamx2*rmx2)**2)\n & /(gamx2*rmx2)\n* If rkappa4low=0 then estrsup is numerically indistinguishable from spm2lo\n IF(rkappa4low.LE.0.d0)THEN \n auxalfa3=1.d0\n xf2_max=estrsup\n ELSE\n xf2_max=spm2lo\n rkappa3high=(xf2_max-xf2_min)*2.d0*spm2lo\n rk3=rkappa3high/rkappa4low\nccc auxalfa3=rk3/(rk3+1.d0)\n auxalfa3=0.5d0\n ENDIF\n xf2_min=spm1hi\n rkappa3low=(xf2_max-xf2_min)*2.d0*spm1hi\n xw1_max=atan((spm1hi**2-rmx1**2)/(gamx1*rmx1))\n xw1_min=atan((spm1lo**2-rmx1**2)/(gamx1*rmx1))\n rkappa2low=(xw1_max-xw1_min)*\n & ((spm1lo**2-rmx1**2)**2+(gamx1*rmx1)**2)\n & /(gamx1*rmx1)\n rkappa2high=(xw1_max-xw1_min)*\n & ((spm1hi**2-rmx1**2)**2+(gamx1*rmx1)**2)\n & /(gamx1*rmx1)\n rk2=rkappa2high/rkappa3low*auxalfa3\nccc auxalfa2=rk2/(rk2+1.d0)\n auxalfa2=1.d0/3.d0\n xf1_max=spm1lo\n xf1_min=estrinf\n rkappa1=(xf1_max-xf1_min)*2.d0*spm1lo\n rk1=rkappa1/rkappa2low*auxalfa2\nccc alfa1=rk1/(rk1+1.d0)\n alfa1=1.d0/4.d0\n alfa2=auxalfa2*(1.d0-alfa1)+alfa1\n alfa3=auxalfa3*(1.d0-auxalfa2)*(1.d0-alfa1)+alfa2\n IF(rkappa4low.LE.0.d0) alfa3=1.d0 \n ENDIF\n ELSE ! estrsup.GT.spm2hi: flat1 + res1 + flat2 + res2 + flat3?\n IF(estrinf.GE.spm2hi)THEN ! only flat3\n alfa1=0.d0\n alfa2=0.d0\n alfa3=0.d0\n alfa4=0.d0\n auxalfa4=alfa4\n auxalfa3=alfa3\n auxalfa2=alfa2\n xf3_max=estrsup\n xf3_min=estrinf\n ELSEIF(estrinf.GE.spm2lo)THEN ! res2 + flat3\n alfa1=0.d0\n alfa2=0.d0\n alfa3=0.d0\n auxalfa3=alfa3\n auxalfa2=alfa2\n xf3_max=estrsup\n xf3_min=spm2hi\n rkappa5=(xf3_max-xf3_min)*2.d0*spm2hi\n xw2_min=atan((estrinf**2-rmx2**2)/(gamx2*rmx2))\n xw2_max=atan((spm2hi**2-rmx2**2)/(gamx2*rmx2))\n rkappa4high=(xw2_max-xw2_min)*\n & ((spm2hi**2-rmx2**2)**2+(gamx2*rmx2)**2)\n & /(gamx2*rmx2)\n rk4=rkappa4high/rkappa5\nccc alfa4=rk4/(rk4+1.d0)\n alfa4=0.5d0\n auxalfa4=alfa4\n ELSEIF(estrinf.GE.spm1hi)THEN ! flat2 + res2 + flat3\n alfa1=0.d0\n alfa2=0.d0\n auxalfa2=alfa2\n xf3_max=estrsup\n xf3_min=spm2hi\n rkappa5=(xf3_max-xf3_min)*2.d0*spm2hi\n xw2_min=atan((spm2lo**2-rmx2**2)/(gamx2*rmx2))\n xw2_max=atan((spm2hi**2-rmx2**2)/(gamx2*rmx2))\n rkappa4high=(xw2_max-xw2_min)*\n & ((spm2hi**2-rmx2**2)**2+(gamx2*rmx2)**2)\n & /(gamx2*rmx2)\n rkappa4low=(xw2_max-xw2_min)*\n & ((spm2lo**2-rmx2**2)**2+(gamx2*rmx2)**2)\n & /(gamx2*rmx2)\n rk4=rkappa4high/rkappa5\nccc auxalfa4=rk4/(rk4+1.d0)\n auxalfa4=0.5d0\n xf2_max=spm2lo\n xf2_min=estrinf\n rkappa3high=(xf2_max-xf2_min)*2.d0*spm2lo\n rk3=rkappa3high/rkappa4low*auxalfa4\nccc alfa3=rk3/(rk3+1.d0)\n alfa3=1.d0/3.d0\n auxalfa3=alfa3\n alfa4=auxalfa4*(1.d0-alfa3)+alfa3\n ELSEIF(estrinf.GE.spm1lo)THEN ! res1 + flat2 + res2 + flat3\n alfa1=0.d0\n xf3_max=estrsup\n xf3_min=spm2hi\n rkappa5=(xf3_max-xf3_min)*2.d0*spm2hi\n xw2_min=atan((spm2lo**2-rmx2**2)/(gamx2*rmx2))\n xw2_max=atan((spm2hi**2-rmx2**2)/(gamx2*rmx2))\n rkappa4high=(xw2_max-xw2_min)*\n & ((spm2hi**2-rmx2**2)**2+(gamx2*rmx2)**2)\n & /(gamx2*rmx2)\n rkappa4low=(xw2_max-xw2_min)*\n & ((spm2lo**2-rmx2**2)**2+(gamx2*rmx2)**2)\n & /(gamx2*rmx2)\n rk4=rkappa4high/rkappa5\nccc auxalfa4=rk4/(rk4+1.d0)\n auxalfa4=0.5d0\n xf2_max=spm2lo\n xf2_min=spm1hi\n rkappa3high=(xf2_max-xf2_min)*2.d0*spm2lo\n rkappa3low=(xf2_max-xf2_min)*2.d0*spm1hi\n rk3=rkappa3high/rkappa4low*auxalfa4\nccc auxalfa3=rk3/(rk3+1.d0)\n auxalfa3=1.d0/3.d0\n xw1_max=atan((spm1hi**2-rmx1**2)/(gamx1*rmx1))\n xw1_min=atan((estrinf**2-rmx1**2)/(gamx1*rmx1))\n rkappa2high=(xw1_max-xw1_min)*\n & ((spm1hi**2-rmx1**2)**2+(gamx1*rmx1)**2)\n & /(gamx1*rmx1)\n rk2=rkappa2high/rkappa3low*auxalfa3\nccc alfa2=rk2/(rk2+1.d0)\n alfa2=1.d0/4.d0\n auxalfa2=alfa2\n alfa3=auxalfa3*(1.d0-alfa2)+alfa2\n alfa4=auxalfa4*(1.d0-auxalfa3)*(1.d0-alfa2)+alfa3\n ELSE ! estrinf.GT.spm1lo: flat1 + res1 + flat2 + res2+ flat3\n xf3_max=estrsup\n xf3_min=spm2hi\n rkappa5=(xf3_max-xf3_min)*2.d0*spm2hi\n xw2_min=atan((spm2lo**2-rmx2**2)/(gamx2*rmx2))\n xw2_max=atan((spm2hi**2-rmx2**2)/(gamx2*rmx2))\n rkappa4high=(xw2_max-xw2_min)*\n & ((spm2hi**2-rmx2**2)**2+(gamx2*rmx2)**2)\n & /(gamx2*rmx2)\n rkappa4low=(xw2_max-xw2_min)*\n & ((spm2lo**2-rmx2**2)**2+(gamx2*rmx2)**2)\n & /(gamx2*rmx2)\n rk4=rkappa4high/rkappa5\nccc auxalfa4=rk4/(rk4+1.d0)\n auxalfa4=0.5d0\n xf2_max=spm2lo\n xf2_min=spm1hi\n rkappa3high=(xf2_max-xf2_min)*2.d0*spm2lo\n rkappa3low=(xf2_max-xf2_min)*2.d0*spm1hi\n rk3=rkappa3high/rkappa4low*auxalfa4\nccc auxalfa3=rk3/(rk3+1.d0)\n auxalfa3=1.d0/3.d0\n xw1_max=atan((spm1hi**2-rmx1**2)/(gamx1*rmx1))\n xw1_min=atan((spm1lo**2-rmx1**2)/(gamx1*rmx1))\n rkappa2high=(xw1_max-xw1_min)*\n & ((spm1hi**2-rmx1**2)**2+(gamx1*rmx1)**2)\n & /(gamx1*rmx1)\n rkappa2low=(xw1_max-xw1_min)*\n & ((spm1lo**2-rmx1**2)**2+(gamx1*rmx1)**2)\n & /(gamx1*rmx1)\n rk2=rkappa2high/rkappa3low*auxalfa3\nccc auxalfa2=rk2/(rk2+1.d0)\n auxalfa2=1.d0/4.d0\n xf1_max=spm1lo\n xf1_min=estrinf\n rkappa1=(xf1_max-xf1_min)*2.d0*spm1lo\n rk1=rkappa1/rkappa2low*auxalfa2\nccc alfa1=rk1/(rk1+1.d0)\n alfa1=1.d0/5.d0\n alfa2=auxalfa2*(1.d0-alfa1)+alfa1\n alfa3=auxalfa3*(1.d0-auxalfa2)*(1.d0-alfa1)+alfa2\n alfa4=auxalfa4*(1.d0-auxalfa3)*(1.d0-auxalfa2)*(1.d0-alfa1)\n & +alfa3\n ENDIF\n ENDIF\n \n RETURN\n END\n\n \n \n*****************************************************************************\n* Auxiliary subroutine. Defines extrema for flat+t**alfa mapping of t-channel\n* Propagator. Checks for position of t_sup,t_inf with respect to spt1\n* INPUT:\n* t_sup,t_inf : upper and lower limit for t\n* spt1 : separation point between flat and mapped regions\n* exp1 : exponent of the mapping\n* OUTPUT:\n* alfa : separation points in [0,1] between flat and mapped regions\n* Can also be 0 or 1. Some care necessary in this cases\n* xt1_min,xt1_max,xt2_min,xt2_max\n* : auxiliary quantities used for generating t\n* and computing the jacobian\n*****************************************************************************\n* a --> c, b --> d\n\n SUBROUTINE T_INI(t_inf,t_sup,spt1,exp1,\n & alfa,xt1_min,xt1_max,xt2_min,xt2_max)\n IMPLICIT REAL*8(a-h,o-z)\n\n IF(t_sup.LE.spt1)THEN ! only flat\n alfa=1.d0\n xt1_min=t_inf\n xt1_max=t_sup\n ELSE ! flat + mapped?\n IF(t_inf.GE.spt1)THEN ! only mapped\n alfa=0.d0\n IF(exp1.eq.0.d0)THEN\n xt2_min=t_inf\n xt2_max=t_sup \n ELSEIF(exp1.ne.1.d0)THEN \n xt2_min=(-t_sup)**(1.d0-exp1)\n xt2_max=(-t_inf)**(1.d0-exp1)\n ELSE\n xt2_min=log((-t_sup))\n\t xt2_max=log((-t_inf))\n ENDIF\n\tELSE ! flat + mapped!\n xt1_min=t_inf\n xt1_max=spt1\n rkappa1=(xt1_max-xt1_min)\n IF(exp1.eq.0.d0)THEN\n xt2_min=spt1\n xt2_max=t_sup \n rkappa2=(xt2_max-xt2_min)\n ELSEIF(exp1.ne.1.d0)THEN \n xt2_min=(-t_sup)**(1.d0-exp1)\n xt2_max=(-spt1)**(1.d0-exp1)\n\t rkappa2=(xt2_max-xt2_min)/(1.d0-exp1)*(-spt1)**exp1\n ELSE\n xt2_min=log((-t_sup))\n\t xt2_max=log((-spt1))\n\t rkappa2=(xt2_max-xt2_min)*(-spt1)\n ENDIF\n rkappa=rkappa1/rkappa2\n alfa=rkappa/(rkappa+1.d0)\n\tENDIF\n ENDIF \n\t\n RETURN\n END\n \n\n*****************************************************************************\n* Auxiliary subroutine. Defines extrema for flat+flat mapping\n* of shat. Checks for position of estrsup,estrinf with respect to\n* spm1lo,spm1hi\n* INPUT:\n* estrsup,estrinf: upper and lower limit for the generated mass\n* spm1 : separation point of the two regions region\n* OUTPUT:\n* alfa1 : separation point in [0,1] between the two regions\n* Can also be 0 or 1. Some care necessary in this cases.\n* At present set to 2/3.\n* xf1_min,xf1_max,xf2_min,xf2_max\n* : auxiliary quantities used for generating the mass\n* and computing the jacobian\n*****************************************************************************\n SUBROUTINE PHSP_INI2(estrsup,estrinf,spm1,\n & alfa1,\n & xf1_min,xf1_max,xf2_min,xf2_max)\n \n IMPLICIT REAL*8(a-h,o-z)\n \n IF(estrsup.LE.spm1)THEN ! only flat1\n alfa1=1.d0\n xf1_max=estrsup\n xf1_min=estrinf\n ELSE ! estrsup.GT.spm1: flat1 + flat2 ?\n IF(estrinf.GE.spm1)THEN ! only flat2\n alfa1=0.d0\n xf2_max=estrsup\n xf2_min=estrinf\n ELSE ! flat1 + flat2\n xf2_max=estrsup\n xf2_min=spm1\n rkappa2=(xf2_max-xf2_min)*2.d0*spm1\n xf1_min=estrinf\n xf1_max=spm1\n rkappa1=(xf1_max-xf1_min)*2.d0*spm1\n rk1=rkappa1/rkappa2\nc alfa1=rk1/(rk1+1.d0)\n alfa1=0.85d0\n ENDIF\n ENDIF\n \n RETURN\n END\n\n \n*****************************************************************************\n* Auxiliary subroutine\n* INPUT:\n* pbst : intermediate particle momentum\n* shat : the corresponding mass (assumed positive)\n* pmod : the absolute value of the 3-momentum of the two\n* daughter particles in the decay CM\n* xm1sq,xm2sq : the squared masses of the daughter particles\n* x1,x2 : two random numbers uniformly distributed in [0,1]\n* OUTPUT:\n* p1,p2 : the momenta of the two daughters in the frame in\n* which the intermediate particle has momentum pbst \n* p1 + p2 = pbst\n*\n* If pbst=(sqrt(shat),0,0,0) the boost reduces to the identity\n* Ezio May 7 2007\n* A rotation of the generated momentum has been added in such a way to assume as\n* z-axis the direction of a massless particle along the z-axis in the overall\n* center of mass\n* \n*****************************************************************************\n SUBROUTINE TWOBODY_Z(pbst,shat,pmod,xm1sq,xm2sq,x1,x2,p1,p2)\n IMPLICIT NONE\n REAL*8 pbst(0:3),shat,pmod,xm1sq,xm2sq,x1,x2,p1(0:3),p2(0:3)\n* Local variables\n REAL*8 app,costh,sinth,ph,rmboost,aapp,pi,twopi\n REAL*8 pz(0:3)\n INTEGER i\n PARAMETER (pi=3.141592653589793238462643d0,twopi=2.d0*pi)\n \n costh=min(x1*2.d0-1.d0,1.d0)\n costh=max(costh,-1.d0)\n sinth=sqrt(1.d0-costh*costh)\n ph=x2*twopi\n* p1\n p1(0)=sqrt(pmod*pmod+xm1sq)\n p1(1)=pmod*sinth*cos(ph)\n p1(2)=pmod*sinth*sin(ph)\n p1(3)=pmod*costh\n* pz\n pz(0)=1.d0\n pz(1)=0.d0 \n pz(2)=0.d0 \n pz(3)=1.d0\n* boost to pbst center of mass\n call boostinv(pz,pbst,pz) \n* rotate in such a way that angles are relative to the direction of pz (bbosted)\n call rot(p1(1),pz(1),p1(1))\n* boost back\n rmboost=sqrt(shat)\n app=(p1(0)*pbst(0)+p1(1)*pbst(1)+p1(2)*pbst(2)+p1(3)*pbst(3))\n & /rmboost\n aapp=(app+p1(0))/(pbst(0)+rmboost)\n p1(0)=app\n p1(1)=p1(1)+aapp*pbst(1)\n p1(2)=p1(2)+aapp*pbst(2)\n p1(3)=p1(3)+aapp*pbst(3)\n DO i=0,3\n p2(i)=pbst(i)-p1(i)\n ENDDO\n \n RETURN\n END\n\n*****************************************************************************\n* Auxiliary subroutine. Determines the invariant mass squared of a branching.\n* The mass is supposed to resonate at two different masses rmx1 and rmx2.\n* INPUT:\n* xvar: a random number in [0,1]\n* rmx1,gamx1 : mass and width of first resonance\n* rmx2,gamx2 : mass and width of second resonance\n* iregion : index for filling the iphsp_fxn COMMON\n* \n* alfa1,alfa2,alfa3,alfa4: separation points in [0,1] between the five regions\n* Can also be 0 or 1. Some care necessary in this cases\n* auxalfa2,xf1_min,xf1_max,xw1_min,xw1_max,xf2_min,xf2_max,xw2_min,xw2_max,\n* xf3_min,xf3_max,auxalfa3,auxalfa4\n* : auxiliary quantities used for generating the mass\n* and computing the jacobian\n* OUTPUT:\n* svar: the generated invariant mass squared\n* xjacvar: the jacobian\n*****************************************************************************\n SUBROUTINE PHSP_5(xvar,\n & rmx1,gamx1,rmx2,gamx2,\n & alfa1,alfa2,auxalfa2,\n & alfa3,auxalfa3,alfa4,auxalfa4,\n & xf1_min,xf1_max,xw1_min,xw1_max,xf2_min,xf2_max,\n & xw2_min,xw2_max,xf3_min,xf3_max,\n & iregion,\n & svar,xjacvar)\n \n IMPLICIT REAL*8(a-h,o-z)\nc giuseppe 29/09/2007\n INTEGER maxnresonant\n PARAMETER (maxnresonant=4)\n INTEGER isresonant(maxnresonant),imapregion(maxnresonant)\n COMMON /iphsp_fxn/ isresonant,imapregion \n PARAMETER (pi=3.141592653589793238462643d0,twopi=2.d0*pi,\n & fourpi=4.d0*pi)\n\n* Compute the invariant mass squared and the corresponding jacobian\n\n xjacvar=1.d0\n\n IF(xvar.LE.alfa1.AND.alfa1.GT.0.d0)THEN\n vegas_x=xvar/alfa1\n evar=(xf1_max-xf1_min)*vegas_x+xf1_min\n svar=evar*evar\n xjacvar=xjacvar*(xf1_max-xf1_min)*2.d0*evar/alfa1\n ELSEIF(xvar.LE.alfa2.AND.alfa2.GT.0.d0)THEN\n vegas_x=(xvar-alfa1)/(1.d0-alfa1)/auxalfa2\n x_max=xw1_max\n x_min=xw1_min\n svar=(gamx1*rmx1*tan((x_max-x_min)*vegas_x+x_min)+rmx1**2)\n IF(svar.LE.0.d0)THEN\n xjacvar=0.d0\n RETURN\n ENDIF\n xjacvar=xjacvar*(x_max-x_min)*((svar-rmx1**2)**2+\n & (gamx1*rmx1)**2)/(gamx1*rmx1)/(1.d0-alfa1)/auxalfa2\nc giuseppe 29/09/2007\n isresonant(iregion)=1\n imapregion(iregion)=2\nc end giuseppe 29/09/2007\n ELSEIF(xvar.LE.alfa3.AND.alfa3.GT.0.d0)THEN\n vegas_x=(xvar-alfa2)/(1.d0-alfa1)/(1.d0-auxalfa2)/auxalfa3\n evar=(xf2_max-xf2_min)*vegas_x+xf2_min\n svar=evar*evar\n xjacvar=xjacvar*(xf2_max-xf2_min)*2.d0*evar\n & /(1.d0-alfa1)/(1.d0-auxalfa2)/auxalfa3\n ELSEIF(xvar.LE.alfa4.AND.alfa4.GT.0.d0)THEN\n vegas_x=(xvar-alfa3)/(1.d0-alfa1)/(1.d0-auxalfa2)\n & /(1.d0-auxalfa3)/auxalfa4\n x_max=xw2_max\n x_min=xw2_min\n svar=(gamx2*rmx2*tan((x_max-x_min)*vegas_x+x_min)+rmx2**2)\n IF(svar.LE.0.d0)THEN\n xjacvar=0.d0\n RETURN\n ENDIF\n xjacvar=xjacvar*(x_max-x_min)*((svar-rmx2**2)**2+\n & (gamx2*rmx2)**2)/(gamx2*rmx2)/(1.d0-alfa1)\n & /(1.d0-auxalfa2)/(1.d0-auxalfa3)/auxalfa4\nc giuseppe 29/09/2007\n isresonant(iregion)=1\n imapregion(iregion)=4\nc end giuseppe 29/09/2007\n ELSE\n vegas_x=(xvar-alfa4)/(1.d0-alfa1)/(1.d0-auxalfa2)\n & /(1.d0-auxalfa3)/(1.d0-auxalfa4)\n evar=(xf3_max-xf3_min)*vegas_x+xf3_min\n svar=evar*evar\n xjacvar=xjacvar*(xf3_max-xf3_min)*2.d0*evar\n & /(1.d0-alfa1)/(1.d0-auxalfa2)\n & /(1.d0-auxalfa3)/(1.d0-auxalfa4)\n ENDIF \n xjacvar=xjacvar/twopi\n \n RETURN\n END\n\n\n\n \n", "meta": {"hexsha": "405256369f6c92c095c785359c12eff4606c1e4d", "size": 34115, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "phantom_1_7/util.f", "max_stars_repo_name": "valsdav/vbscan-school", "max_stars_repo_head_hexsha": "ef18677f797860dadf662042e11291074ece140b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "phantom_1_7/util.f", "max_issues_repo_name": "valsdav/vbscan-school", "max_issues_repo_head_hexsha": "ef18677f797860dadf662042e11291074ece140b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "phantom_1_7/util.f", "max_forks_repo_name": "valsdav/vbscan-school", "max_forks_repo_head_hexsha": "ef18677f797860dadf662042e11291074ece140b", "max_forks_repo_licenses": ["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.3157349896, "max_line_length": 83, "alphanum_fraction": 0.5383555621, "num_tokens": 12286, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093946927837, "lm_q2_score": 0.7341195385342971, "lm_q1q2_score": 0.6557958806002187}} {"text": "c\nc\nc ###################################################\nc ## COPYRIGHT (C) 1990 by Jay William Ponder ##\nc ## All Rights Reserved ##\nc ###################################################\nc\nc ############################################################\nc ## ##\nc ## subroutine invert -- gauss-jordan matrix inversion ##\nc ## ##\nc ############################################################\nc\nc\nc \"invert\" inverts a matrix using the Gauss-Jordan method\nc\nc variables and parameters:\nc\nc n dimension of the matrix to be inverted\nc a matrix to invert; contains inverse on exit\nc\nc\n subroutine invert (n,a)\n implicit none\n include 'iounit.i'\n integer i,j,k,n\n integer icol,irow\n integer, allocatable :: ipivot(:)\n integer, allocatable :: indxc(:)\n integer, allocatable :: indxr(:)\n real*8 big,temp\n real*8 pivot\n real*8 a(n,*)\nc\nc\nc perform dynamic allocation of some local arrays\nc\n allocate (ipivot(n))\n allocate (indxc(n))\n allocate (indxr(n))\nc\nc perform matrix inversion via the Gauss-Jordan algorithm\nc\n do i = 1, n\n ipivot(i) = 0\n end do\n do i = 1, n\n big = 0.0d0\n do j = 1, n\n if (ipivot(j) .ne. 1) then\n do k = 1, n\n if (ipivot(k) .eq. 0) then\n if (abs(a(j,k)) .ge. big) then\n big = abs(a(j,k))\n irow = j\n icol = k\n end if\n else if (ipivot(k) .gt. 1) then\n write (iout,10)\n 10 format (/,' INVERT -- Cannot Invert',\n & ' a Singular Matrix')\n call fatal\n end if\n end do\n end if\n end do\n ipivot(icol) = ipivot(icol) + 1\n if (irow .ne. icol) then\n do j = 1, n\n temp = a(irow,j)\n a(irow,j) = a(icol,j)\n a(icol,j) = temp\n end do\n end if\n indxr(i) = irow\n indxc(i) = icol\n if (a(icol,icol) .eq. 0.0d0) then\n write (iout,20)\n 20 format (/,' INVERT -- Cannot Invert a Singular Matrix')\n call fatal\n end if\n pivot = a(icol,icol)\n a(icol,icol) = 1.0d0\n do j = 1, n\n a(icol,j) = a(icol,j) / pivot\n end do\n do j = 1, n\n if (j .ne. icol) then\n temp = a(j,icol)\n a(j,icol) = 0.0d0\n do k = 1, n\n a(j,k) = a(j,k) - a(icol,k)*temp\n end do\n end if\n end do\n end do\n do i = n, 1, -1\n if (indxr(i) .ne. indxc(i)) then\n do k = 1, n\n temp = a(k,indxr(i))\n a(k,indxr(i)) = a(k,indxc(i))\n a(k,indxc(i)) = temp\n end do\n end if\n end do\nc\nc perform deallocation of some local arrays\nc\n deallocate (ipivot)\n deallocate (indxc)\n deallocate (indxr)\n return\n end\n", "meta": {"hexsha": "150f4fdbb9bfa88a329bcdbbfe36d711f4441b58", "size": 3295, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "HCsbLib/HCsbLib/HTLib2.Bioinfo/External.Tinker/src/tinker-6.2.06/invert.f", "max_stars_repo_name": "htna/HCsbLib", "max_stars_repo_head_hexsha": "dae7f4e3e5e2fbc3b6e619f2ea037f661a8ae097", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-01-21T23:45:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-03T16:34:24.000Z", "max_issues_repo_path": "HCsbLib/HCsbLib/HTLib2.Bioinfo/External.Tinker/src/tinker-6.2.06/invert.f", "max_issues_repo_name": "htna/HCsbLib", "max_issues_repo_head_hexsha": "dae7f4e3e5e2fbc3b6e619f2ea037f661a8ae097", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HCsbLib/HCsbLib/HTLib2.Bioinfo/External.Tinker/src/tinker-6.2.06/invert.f", "max_forks_repo_name": "htna/HCsbLib", "max_forks_repo_head_hexsha": "dae7f4e3e5e2fbc3b6e619f2ea037f661a8ae097", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-03-05T00:26:38.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-08T23:25:29.000Z", "avg_line_length": 28.9035087719, "max_line_length": 69, "alphanum_fraction": 0.3869499241, "num_tokens": 886, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093975331751, "lm_q2_score": 0.734119526900183, "lm_q1q2_score": 0.655795872292542}} {"text": "program newton\n implicit none\n character(len=32) :: arg\n integer :: iter = 100\n real :: fx, number,x\n call getarg(1, arg)\n read (arg, '(f10.0)') number\n !do 20 i=1, 2, 1\n !20 continue\n fx = number /2 \n !fx = number\n\n do while (iter >= 0)\n fx = (fx + (number / fx))/2\n !fx = fx - ( (fx*fx) / (fx * 2) )\n\n iter = iter - 1\n end do\nprint '(\"A raiz \u00e9: \"(f0.2))' , fx\nend program newton", "meta": {"hexsha": "696bbb648723bbb37130f78121f8809472774547", "size": 438, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "newton.f95", "max_stars_repo_name": "jonfrs/senac-cn-ado04", "max_stars_repo_head_hexsha": "eebe9452eb075d22141deabc7c99718f55f775b4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "newton.f95", "max_issues_repo_name": "jonfrs/senac-cn-ado04", "max_issues_repo_head_hexsha": "eebe9452eb075d22141deabc7c99718f55f775b4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "newton.f95", "max_forks_repo_name": "jonfrs/senac-cn-ado04", "max_forks_repo_head_hexsha": "eebe9452eb075d22141deabc7c99718f55f775b4", "max_forks_repo_licenses": ["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.9, "max_line_length": 41, "alphanum_fraction": 0.49543379, "num_tokens": 168, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543488, "lm_q2_score": 0.7341195152660687, "lm_q1q2_score": 0.6557958681552383}} {"text": " INCLUDE 'VICMAIN_FOR'\n\n SUBROUTINE MAIN44\n DOUBLE PRECISION X(2,2), QR(5,3)\n INTEGER I, M, N, IP, J, IFAIL, IPIV(2)\n DOUBLE PRECISION A(3,2) ! Presets: / 1.1,1.2,1.0, 0.9,1.0,1.0 /\n DOUBLE PRECISION B(3,2) ! Presets: / 2.2,2.3,2.1, 4.4,4.6,4.2 /\n CHARACTER*132 TBUF\n\n DATA A / 1.1,1.2,1.0, 0.9,1.0,1.0/\n DATA B / 2.2,2.3,2.1, 4.4,4.6,4.2 /\n \nC 1.1 0.9 2.2\nC 1.2 1.0 2.3\nC 1.0 1.0 2.1\n\n M = 3\n N = 2\n IP = 2\n IFAIL = 1\n\n\n! Call DLLSQ to calculat the least squares solution for test values\n CALL DLLSQ(A,B,M,N,IP,X,IPIV,1.D-15,IFAIL,QR)\n\n! If a failure was detected then print contents of array and terminate\n IF (IFAIL.EQ.0) GO TO 20\n WRITE (TBUF,99996) IFAIL\n99996 FORMAT ('ERROR IN DLLSQ IFAIL = ', I2)\n CALL XVMESSAGE (TBUF, ' ') \n RETURN\n\n! DLLSQ was successful ... print results of least squares computatin \n 20 WRITE (TBUF,90010)\n90010 FORMAT ('SOLUTIONS')\n CALL XVMESSAGE (TBUF, ' ') \n\n DO 40 J = 1, IP\n DO 40 I = 1, N\n WRITE (TBUF,99920) X(I,J)\n99920 FORMAT (F7.4)\n CALL XVMESSAGE (TBUF, ' ') \n40 END DO\n\nC Test DLLSQ error processing \n WRITE (TBUF, 90100)\n90100 FORMAT ('TEST ERROR HANDLING. SHOULD GET IER=1')\n CALL XVMESSAGE (TBUF, ' ') \n \nC Set first 24 (6*4) bytes of memory occupied by matrix A to zero\n CALL ZIA(A,6)\n\n CALL DLLSQ(A,B,M,N,IP,X,IPIV,1.D-15,IFAIL,QR)\n WRITE (TBUF,99996) IFAIL\n CALL XVMESSAGE (TBUF, ' ') \n\n! Initiate Call to the C bridge for DLLSQ and the DLLSQ bridge test driver\n CALL tzdllsq\n\n RETURN\n END\n", "meta": {"hexsha": "db764e82dc899cb2a404bf97392c0d3c189dfe47", "size": 1626, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "vos/p2/sub/dllsq/test/tdllsq.f", "max_stars_repo_name": "NASA-AMMOS/VICAR", "max_stars_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2020-10-21T05:56:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T10:02:01.000Z", "max_issues_repo_path": "vos/p2/sub/dllsq/test/tdllsq.f", "max_issues_repo_name": "NASA-AMMOS/VICAR", "max_issues_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "vos/p2/sub/dllsq/test/tdllsq.f", "max_forks_repo_name": "NASA-AMMOS/VICAR", "max_forks_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-03-09T01:51:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-23T00:23:24.000Z", "avg_line_length": 26.2258064516, "max_line_length": 74, "alphanum_fraction": 0.581795818, "num_tokens": 649, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278788223265, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6557921744680819}} {"text": "program problem50\n use euler\n implicit none\n integer, parameter :: limit=1000000\n integer*8, dimension(limit/10) :: primes,sums\n integer*8 :: i,j,sum,count\n integer*8 :: best_prime,best_gap,gap,prime\n\n count=0\n do i=2,limit\n if (is_prime(int8(i))) then\n count=count+1\n primes(count)=i\n end if\n end do\n\n sum=0\n do i=1,count\n sum=sum+primes(i)\n sums(i)=sum\n end do\n\n best_gap=21\n do i=count,1,-1 ! index of end of sequence\n do j=1,i-1 ! length of the gap\n gap=i-j+1\n if (gap= 0.\r\nC\r\nC S (input) INTEGER array, dimension (K)\r\nC The signature array. Each entry of S must be 1 or -1.\r\nC\r\nC A (input) COMPLEX*16 array, dimension (K)\r\nC Vector of real scalars.\r\nC\r\nC INCA (input) INTEGER\r\nC Increment for the array A. incA <> 0.\r\nC\r\nC ALPHA (output) COMPLEX*16\r\nC ALPHA is a real scalar with 1.0 <= ABS(ALPHA) < BASE such\r\nC that\r\nC\r\nC ALPHA / BETA * BASE**(SCAL)\r\nC\r\nC is the general product of A. \r\nC\r\nC BETA (output) COMPLEX*16\r\nC BETA is either 0.0 or 1.0.\r\nC See also the description of ALPHA.\r\nC\r\nC SCAL (output) INTEGER\r\nC Scaling factor, see ALPHA.\r\nC\r\nC CONTRIBUTOR\r\nC\r\nC D. Kressner, Technical Univ. Berlin, Germany, Dec. 2002.\r\nC\r\nC ******************************************************************\r\nC\r\nC .. Parameters ..\r\n DOUBLE PRECISION ONE, ZERO\r\n PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 )\r\n COMPLEX*16 CONE, CZERO\r\n PARAMETER ( CONE = ( 1.0D+0, 0.0D+0 ),\r\n $ CZERO = ( 0.0D+0, 0.0D+0 ) )\r\nC .. Array Arguments ..\r\n INTEGER S(*)\r\n COMPLEX*16 A(*)\r\nC .. Scalar Arguments ..\r\n INTEGER INCA, K, SCAL\r\n DOUBLE PRECISION BASE\r\n COMPLEX*16 ALPHA, BETA\r\nC .. Local Scalars ..\r\n INTEGER I, INDA\r\nC .. Intrinsic Functions ..\r\n INTRINSIC ABS, DCMPLX\r\nC\r\nC .. Executable Statements ..\r\nC\r\n ALPHA = CONE\r\n BETA = CONE\r\n SCAL = 0\r\n INDA = 1\r\n DO 50 I = 1, K\r\n IF ( S(I).EQ.1 ) THEN\r\n ALPHA = ALPHA * A(INDA)\r\n ELSE\r\n IF ( A(INDA).EQ.CZERO ) THEN\r\n BETA = CZERO\r\n ELSE\r\n ALPHA = ALPHA / A(INDA)\r\n END IF\r\n END IF\r\n IF ( ABS( ALPHA ).EQ.ZERO ) THEN\r\n SCAL = 0\r\n ALPHA = CZERO\r\n ELSE\r\n 10 IF ( ABS( ALPHA ).GE.ONE ) GO TO 20\r\n ALPHA = DCMPLX( BASE, ZERO )*ALPHA\r\n SCAL = SCAL - 1\r\n GO TO 10\r\n 20 CONTINUE\r\n 30 IF ( ABS( ALPHA ).LT.BASE ) GO TO 40\r\n ALPHA = ALPHA / DCMPLX( BASE, ZERO )\r\n SCAL = SCAL + 1\r\n GO TO 30\r\n 40 CONTINUE\r\n END IF\r\n INDA = INDA + INCA\r\n 50 CONTINUE\r\nC\r\n RETURN\r\nC\r\nC *** Last line of ZLAPR1 ***\r\n END\r\n", "meta": {"hexsha": "9b3c2d298419f660b322e1957eb2ebe843ea9728", "size": 2927, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "pqzschur/zlapr1.f", "max_stars_repo_name": "iwoodsawyer/dpre", "max_stars_repo_head_hexsha": "515076c0b6b7c6643378427553b4c302dc29ed3b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-17T13:13:08.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-17T13:13:08.000Z", "max_issues_repo_path": "pqzschur/zlapr1.f", "max_issues_repo_name": "iwoodsawyer/dpre", "max_issues_repo_head_hexsha": "515076c0b6b7c6643378427553b4c302dc29ed3b", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-12-25T15:47:07.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-03T21:11:59.000Z", "max_forks_repo_path": "pqzschur/zlapr1.f", "max_forks_repo_name": "iwoodsawyer/dpre", "max_forks_repo_head_hexsha": "515076c0b6b7c6643378427553b4c302dc29ed3b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.8761904762, "max_line_length": 73, "alphanum_fraction": 0.4598565084, "num_tokens": 878, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278540866547, "lm_q2_score": 0.7431680199891789, "lm_q1q2_score": 0.6557921611048793}} {"text": "program Five_weekends\n implicit none\n\n integer :: m, year, nfives = 0, not5 = 0\n logical :: no5weekend\n\n type month\n integer :: n\n character(3) :: name\n end type month\n\n type(month) :: month31(7)\n\n month31(1) = month(13, \"Jan\")\n month31(2) = month(3, \"Mar\")\n month31(3) = month(5, \"May\")\n month31(4) = month(7, \"Jul\")\n month31(5) = month(8, \"Aug\")\n month31(6) = month(10, \"Oct\")\n month31(7) = month(12, \"Dec\")\n\n do year = 1900, 2100\n no5weekend = .true.\n do m = 1, size(month31)\n if(month31(m)%n == 13) then\n if(Day_of_week(1, month31(m)%n, year-1) == 6) then\n write(*, \"(a3, i5)\") month31(m)%name, year\n nfives = nfives + 1\n no5weekend = .false.\n end if\n else\n if(Day_of_week(1, month31(m)%n, year) == 6) then\n write(*,\"(a3, i5)\") month31(m)%name, year\n nfives = nfives + 1\n no5weekend = .false.\n end if\n end if\n end do\n if(no5weekend) not5 = not5 + 1\n end do\n\n write(*, \"(a, i0)\") \"Number of months with five weekends between 1900 and 2100 = \", nfives\n write(*, \"(a, i0)\") \"Number of years between 1900 and 2100 with no five weekend months = \", not5\n\ncontains\n\nfunction Day_of_week(d, m, y)\n integer :: Day_of_week\n integer, intent(in) :: d, m, y\n integer :: j, k\n\n j = y / 100\n k = mod(y, 100)\n Day_of_week = mod(d + (m+1)*26/10 + k + k/4 + j/4 + 5*j, 7)\n\nend function Day_of_week\nend program Five_weekends\n", "meta": {"hexsha": "8fbab98d3c49268c4a3f9affceb616bababcb5ca", "size": 1452, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Five-weekends/Fortran/five-weekends.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/Five-weekends/Fortran/five-weekends.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/Five-weekends/Fortran/five-weekends.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 25.0344827586, "max_line_length": 98, "alphanum_fraction": 0.5688705234, "num_tokens": 542, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705731, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6557921506418969}} {"text": "c***************************************************************************\nc\t\t\tOBL_ACC_TP.F\nc*************************************************************************\nc OBL_ACC returns the BARYCENTRIC x,y,z components of the acc. on NTP\nc test particles due to the oblateness of mass(1) using \nc the values of J2RP2 and J4RP4 passed into the routine.\nc (J2RP2 for example is the product of \nc J_2 times the square of the central body's radius)\nc Here we return the net acc. produced\nc only by the J2 and J4 terms (i.e. including\nc neither the monopole nor higher order terms).\nc\t\nc\nc Input:\nc ntp ==> number of massive bodies (incl. central one)\nc istat ==> status of the test paricles\nc (integer array)\nc istat(i) = 0 ==> active: = 1 not\nc NOTE: it is really a 2d array but \nc we only use the 1st row\nc msun ==> mass of the central particle (real*8 scalar)\nc j2rp2 ==> scaled value of j2 moment (real*8 scalar)\nc j4rp4 ==> scaled value of j4 moment (real*8 scalar)\nc xht(*),yht(*),zht(*) ==> HELIO. positions of particles\nc irht(*) ==> 1./ magnitude of radius vector (real*8 vector)\nc (passed in to save calcs.)\nc Output:\nc aoblxt(*),aoblyt(*),aoblzt(*) ==> BARY. components of accel \nc (real*8 vectors) \nc\nc Remarks: Based on Martin's OBL_ACC.F\nc Authors: Hal Levison\nc Date: 3/4/94\nc Last revision: \n\n subroutine obl_acc_tp(ntp,istat,msun,j2rp2,j4rp4,xht,yht,zht,\n & irht,aoblxt,aoblyt,aoblzt)\n\n include '../swift.inc'\n\nc... Inputs Only: \n integer ntp,istat(ntp)\n real*8 msun,j2rp2,j4rp4\n real*8 xht(ntp),yht(ntp),zht(ntp),irht(NPLMAX)\n\nc... Output\n real*8 aoblxt(ntp),aoblyt(ntp),aoblzt(ntp)\n\nc... Internals\n integer n\n real*8 rinv2,t0,t1,t2,t3\n real*8 fac1,fac2\n\nc----\nc... executable code\n\nc First get the bary acc. of each tp due to central oblate \"sun\"\n\n do n =1,ntp\n\n rinv2= irht(n)**2\n t0 = -msun*rinv2*rinv2*irht(n)\n t1 = 1.5d0 *j2rp2\n t2 = zht(n)*zht(n)*rinv2\n t3 = 1.875d0 *j4rp4*rinv2\n \n fac1 = t0*(t1 - t3 - (5.d0*t1 - (14.d0 - 21.d0*t2)*t3)*t2)\n fac2 = 2.d0*t0*(t1 - (2.d0 - (14.d0*t2/3.d0))*t3)\n \n aoblxt(n) = fac1*xht(n)\n aoblyt(n) = fac1*yht(n)\n aoblzt(n) = (fac1 + fac2)*zht(n)\n \n enddo\n \n return\t\n end ! obl_acc_tp.f\nc____________________________________________________________________________\n", "meta": {"hexsha": "4ffce9cb93e9a54bd7d14dfd33287d91e84e0c53", "size": 2793, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/swift_j/obl/obl_acc_tp.f", "max_stars_repo_name": "Simske/exostriker", "max_stars_repo_head_hexsha": "587b0af4c9cadb46637a4ac61a5392a596e966b1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 69, "max_stars_repo_stars_event_min_datetime": "2020-01-06T13:31:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T11:23:14.000Z", "max_issues_repo_path": "exostriker/source/swift_j/obl/obl_acc_tp.f", "max_issues_repo_name": "sai-33/Exostriker", "max_issues_repo_head_hexsha": "f59fa51c6bdce3a2ed51d6621fe42bfcd8c2846f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 67, "max_issues_repo_issues_event_min_datetime": "2019-11-30T14:45:05.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-14T20:26:06.000Z", "max_forks_repo_path": "exostriker/source/swift_j/obl/obl_acc_tp.f", "max_forks_repo_name": "sai-33/Exostriker", "max_forks_repo_head_hexsha": "f59fa51c6bdce3a2ed51d6621fe42bfcd8c2846f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2020-01-06T13:44:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T11:23:17.000Z", "avg_line_length": 35.3544303797, "max_line_length": 77, "alphanum_fraction": 0.5130683852, "num_tokens": 841, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308147331957, "lm_q2_score": 0.7025300698514778, "lm_q1q2_score": 0.6557632154760338}} {"text": " SUBROUTINE MB04ZD( COMPU, N, A, LDA, QG, LDQG, U, LDU, DWORK, INFO\n $ )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To transform a Hamiltonian matrix\nC\nC ( A G )\nC H = ( T ) (1)\nC ( Q -A )\nC\nC into a square-reduced Hamiltonian matrix\nC\nC ( A' G' )\nC H' = ( T ) (2)\nC ( Q' -A' )\nC T\nC by an orthogonal symplectic similarity transformation H' = U H U,\nC where\nC ( U1 U2 )\nC U = ( ). (3)\nC ( -U2 U1 )\nC T\nC The square-reduced Hamiltonian matrix satisfies Q'A' - A' Q' = 0,\nC and\nC\nC 2 T 2 ( A'' G'' )\nC H' := (U H U) = ( T ).\nC ( 0 A'' )\nC\nC In addition, A'' is upper Hessenberg and G'' is skew symmetric.\nC The square roots of the eigenvalues of A'' = A'*A' + G'*Q' are the\nC eigenvalues of H.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC COMPU CHARACTER*1\nC Indicates whether the orthogonal symplectic similarity\nC transformation matrix U in (3) is returned or\nC accumulated into an orthogonal symplectic matrix, or if\nC the transformation matrix is not required, as follows:\nC = 'N': U is not required;\nC = 'I' or 'F': on entry, U need not be set;\nC on exit, U contains the orthogonal\nC symplectic matrix U from (3);\nC = 'V' or 'A': the orthogonal symplectic similarity\nC transformations are accumulated into U;\nC on input, U must contain an orthogonal\nC symplectic matrix S;\nC on exit, U contains S*U with U from (3).\nC See the description of U below for details.\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The order of the matrices A, G, and Q. N >= 0.\nC\nC A (input/output) DOUBLE PRECISION array, dimension (LDA,N)\nC On input, the leading N-by-N part of this array must\nC contain the upper left block A of the Hamiltonian matrix H\nC in (1).\nC On output, the leading N-by-N part of this array contains\nC the upper left block A' of the square-reduced Hamiltonian\nC matrix H' in (2).\nC\nC LDA INTEGER\nC The leading dimension of the array A. LDA >= MAX(1,N).\nC\nC QG (input/output) DOUBLE PRECISION array, dimension\nC (LDQG,N+1)\nC On input, the leading N-by-N lower triangular part of this\nC array must contain the lower triangle of the lower left\nC symmetric block Q of the Hamiltonian matrix H in (1), and\nC the N-by-N upper triangular part of the submatrix in the\nC columns 2 to N+1 of this array must contain the upper\nC triangle of the upper right symmetric block G of H in (1).\nC So, if i >= j, then Q(i,j) = Q(j,i) is stored in QG(i,j)\nC and G(i,j) = G(j,i) is stored in QG(j,i+1).\nC On output, the leading N-by-N lower triangular part of\nC this array contains the lower triangle of the lower left\nC symmetric block Q', and the N-by-N upper triangular part\nC of the submatrix in the columns 2 to N+1 of this array\nC contains the upper triangle of the upper right symmetric\nC block G' of the square-reduced Hamiltonian matrix H'\nC in (2).\nC\nC LDQG INTEGER\nC The leading dimension of the array QG. LDQG >= MAX(1,N).\nC\nC U (input/output) DOUBLE PRECISION array, dimension (LDU,2*N)\nC If COMPU = 'N', then this array is not referenced.\nC If COMPU = 'I' or 'F', then the input contents of this\nC array are not specified. On output, the leading\nC N-by-(2*N) part of this array contains the first N rows\nC of the orthogonal symplectic matrix U in (3).\nC If COMPU = 'V' or 'A', then, on input, the leading\nC N-by-(2*N) part of this array must contain the first N\nC rows of an orthogonal symplectic matrix S. On output, the\nC leading N-by-(2*N) part of this array contains the first N\nC rows of the product S*U where U is the orthogonal\nC symplectic matrix from (3).\nC The storage scheme implied by (3) is used for orthogonal\nC symplectic matrices, i.e., only the first N rows are\nC stored, as they contain all relevant information.\nC\nC LDU INTEGER\nC The leading dimension of the array U.\nC LDU >= MAX(1,N), if COMPU <> 'N';\nC LDU >= 1, if COMPU = 'N'.\nC\nC Workspace\nC\nC DWORK DOUBLE PRECISION array, dimension (2*N)\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, then the i-th argument had an illegal\nC value.\nC\nC METHOD\nC\nC The Hamiltonian matrix H is transformed into a square-reduced\nC Hamiltonian matrix H' using the implicit version of Van Loan's\nC method as proposed in [1,2,3].\nC\nC REFERENCES\nC\nC [1] Van Loan, C. F.\nC A Symplectic Method for Approximating All the Eigenvalues of\nC a Hamiltonian Matrix.\nC Linear Algebra and its Applications, 61, pp. 233-251, 1984.\nC\nC [2] Byers, R.\nC Hamiltonian and Symplectic Algorithms for the Algebraic\nC Riccati Equation.\nC Ph. D. Thesis, Cornell University, Ithaca, NY, January 1983.\nC\nC [3] Benner, P., Byers, R., and Barth, E.\nC Fortran 77 Subroutines for Computing the Eigenvalues of\nC Hamiltonian Matrices. I: The Square-Reduced Method.\nC ACM Trans. Math. Software, 26, 1, pp. 49-77, 2000.\nC\nC NUMERICAL ASPECTS\nC\nC This algorithm requires approximately 20*N**3 flops for\nC transforming H into square-reduced form. If the transformations\nC are required, this adds another 8*N**3 flops. The method is\nC strongly backward stable in the sense that if H' and U are the\nC computed square-reduced Hamiltonian and computed orthogonal\nC symplectic similarity transformation, then there is an orthogonal\nC symplectic matrix T and a Hamiltonian matrix M such that\nC\nC H T = T M\nC\nC || T - U || <= c1 * eps\nC\nC || H' - M || <= c2 * eps * || H ||\nC\nC where c1, c2 are modest constants depending on the dimension N and\nC eps is the machine precision.\nC\nC Eigenvalues computed by explicitly forming the upper Hessenberg\nC matrix A'' = A'A' + G'Q', with A', G', and Q' as in (2), and\nC applying the Hessenberg QR iteration to A'' are exactly\nC eigenvalues of a perturbed Hamiltonian matrix H + E, where\nC\nC || E || <= c3 * sqrt(eps) * || H ||,\nC\nC and c3 is a modest constant depending on the dimension N and eps\nC is the machine precision. Moreover, if the norm of H and an\nC eigenvalue lambda are of roughly the same magnitude, the computed\nC eigenvalue is essentially as accurate as the computed eigenvalue\nC from traditional methods. See [1] or [2].\nC\nC CONTRIBUTOR\nC\nC P. Benner, Universitaet Bremen, Germany,\nC R. Byers, University of Kansas, Lawrence, USA, and\nC E. Barth, Kalamazoo College, Kalamazoo, USA,\nC Aug. 1998, routine DHASRD.\nC V. Sima, Research Institute for Informatics, Bucharest, Romania,\nC Oct. 1998, SLICOT Library version.\nC\nC REVISIONS\nC\nC May 2001, A. Varga, German Aeropsce Center, DLR Oberpfaffenhofen.\nC May 2009, V. Sima, Research Institute for Informatics, Bucharest.\nC\nC KEYWORDS\nC\nC Orthogonal transformation, (square-reduced) Hamiltonian matrix,\nC symplectic similarity transformation.\nC\nC ******************************************************************\nC\nC .. Parameters ..\nC\n DOUBLE PRECISION ZERO, ONE, TWO\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0, TWO = 2.0D0 )\nC\nC .. Scalar Arguments ..\n INTEGER INFO, LDA, LDQG, LDU, N\n CHARACTER COMPU\nC ..\nC .. Array Arguments ..\n DOUBLE PRECISION A(LDA,*), DWORK(*), QG(LDQG,*), U(LDU,*)\nC ..\nC .. Local Scalars ..\n DOUBLE PRECISION COSINE, SINE, TAU, TEMP, X, Y\n INTEGER J\n LOGICAL ACCUM, FORGET, FORM\nC ..\nC .. Local Arrays ..\n DOUBLE PRECISION DUMMY(1), T(2,2)\nC ..\nC .. External Functions ..\n DOUBLE PRECISION DDOT\n LOGICAL LSAME\n EXTERNAL DDOT, LSAME\nC ..\nC .. External Subroutines ..\n EXTERNAL DAXPY, DCOPY, DGEMV, DLARFG, DLARFX, DLARTG,\n $ DROT, DSYMV, DSYR2, XERBLA\nC ..\nC .. Intrinsic Functions ..\n INTRINSIC MAX\nC ..\nC .. Executable Statements ..\nC\n INFO = 0\n ACCUM = LSAME( COMPU, 'A' ) .OR. LSAME( COMPU, 'V' )\n FORM = LSAME( COMPU, 'F' ) .OR. LSAME( COMPU, 'I' )\n FORGET = LSAME( COMPU, 'N' )\nC\n IF ( .NOT.ACCUM .AND. .NOT.FORM .AND. .NOT.FORGET ) THEN\n INFO = -1\n ELSE IF( N.LT.0 ) THEN\n INFO = -2\n ELSE IF( LDA.LT.MAX( 1, N ) ) THEN\n INFO = -4\n ELSE IF( LDQG.LT.MAX( 1, N ) ) THEN\n INFO = -6\n ELSE IF( LDU.LT.1 .OR. ( .NOT.FORGET .AND. LDU.LT.MAX( 1, N ) ) )\n $ THEN\n INFO = -8\n END IF\nC\n IF ( INFO.NE.0 ) THEN\n CALL XERBLA( 'MB04ZD', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF( N.EQ.0 )\n $ RETURN\nC\nC Transform to square-reduced form.\nC\n DO 10 J = 1, N - 1\nC T\nC DWORK <- (Q*A - A *Q)(J+1:N,J).\nC\n CALL DCOPY( J-1, QG(J,1), LDQG, DWORK(N+1), 1 )\n CALL DCOPY( N-J+1, QG(J,J), 1, DWORK(N+J), 1 )\n CALL DGEMV( 'Transpose', N, N-J, -ONE, A(1,J+1), LDA,\n $ DWORK(N+1), 1, ZERO, DWORK(J+1), 1 )\n CALL DGEMV( 'NoTranspose', N-J, J, ONE, QG(J+1,1), LDQG,\n $ A(1,J), 1, ONE, DWORK(J+1), 1 )\n CALL DSYMV( 'Lower', N-J, ONE, QG(J+1,J+1), LDQG, A(J+1,J), 1,\n $ ONE, DWORK(J+1), 1 )\nC\nC Symplectic reflection to zero (H*H)((N+J+2):2N,J).\nC\n CALL DLARFG( N-J, DWORK(J+1), DWORK(J+2), 1, TAU )\n Y = DWORK(J+1)\n DWORK(J+1) = ONE\nC\n CALL DLARFX( 'Left', N-J, N, DWORK(J+1), TAU, A(J+1,1), LDA,\n $ DWORK(N+1) )\n CALL DLARFX( 'Right', N, N-J, DWORK(J+1), TAU, A(1,J+1), LDA,\n $ DWORK(N+1) )\nC\n CALL DLARFX( 'Left', N-J, J, DWORK(J+1), TAU, QG(J+1,1), LDQG,\n $ DWORK(N+1) )\n CALL DSYMV( 'Lower', N-J, TAU, QG(J+1,J+1), LDQG, DWORK(J+1),\n $ 1, ZERO, DWORK(N+J+1), 1 )\n CALL DAXPY( N-J, -TAU*DDOT( N-J, DWORK(N+J+1), 1, DWORK(J+1),\n $ 1 )/TWO, DWORK(J+1), 1, DWORK(N+J+1), 1 )\n CALL DSYR2( 'Lower', N-J, -ONE, DWORK(J+1), 1, DWORK(N+J+1), 1,\n $ QG(J+1,J+1), LDQG )\nC\n CALL DLARFX( 'Right', J, N-J, DWORK(J+1), TAU, QG(1,J+2), LDQG,\n $ DWORK(N+1) )\n CALL DSYMV( 'Upper', N-J, TAU, QG(J+1,J+2), LDQG, DWORK(J+1),\n $ 1, ZERO, DWORK(N+J+1), 1 )\n CALL DAXPY( N-J, -TAU*DDOT( N-J, DWORK(N+J+1), 1, DWORK(J+1),\n $ 1 )/TWO, DWORK(J+1), 1, DWORK(N+J+1), 1 )\n CALL DSYR2( 'Upper', N-J, -ONE, DWORK(J+1), 1, DWORK(N+J+1), 1,\n $ QG(J+1,J+2), LDQG )\nC\n IF ( FORM ) THEN\nC\nC Save reflection.\nC\n CALL DCOPY( N-J, DWORK(J+1), 1, U(J+1,J), 1 )\n U(J+1,J) = TAU\nC\n ELSE IF ( ACCUM ) THEN\nC\nC Accumulate reflection.\nC\n CALL DLARFX( 'Right', N, N-J, DWORK(J+1), TAU, U(1,J+1),\n $ LDU, DWORK(N+1) )\n CALL DLARFX( 'Right', N, N-J, DWORK(J+1), TAU, U(1,N+J+1),\n $ LDU, DWORK(N+1) )\n END IF\nC\nC (X,Y) := ((J+1,J),(N+J+1,J)) component of H*H.\nC\n X = DDOT( J, QG(1,J+2), 1, QG(J,1), LDQG ) +\n $ DDOT( N-J, QG(J+1,J+2), LDQG, QG(J+1,J), 1 ) +\n $ DDOT( N, A(J+1,1), LDA, A(1,J), 1 )\nC\nC Symplectic rotation to zero (H*H)(N+J+1,J).\nC\n CALL DLARTG( X, Y, COSINE, SINE, TEMP )\nC\n CALL DROT( J, A(J+1,1), LDA, QG(J+1,1), LDQG, COSINE, SINE )\n CALL DROT( J, A(1,J+1), 1, QG(1,J+2), 1, COSINE, SINE )\n IF( J.LT.N-1 ) THEN\n CALL DROT( N-J-1, A(J+1,J+2), LDA, QG(J+2,J+1), 1,\n $ COSINE, SINE )\n CALL DROT( N-J-1, A(J+2,J+1), 1, QG(J+1,J+3), LDQG,\n $ COSINE, SINE )\n END IF\nC\n T(1,1) = A(J+1,J+1)\n T(1,2) = QG(J+1,J+2)\n T(2,1) = QG(J+1,J+1)\n T(2,2) = -T(1,1)\n CALL DROT( 2, T(1,1), 1, T(1,2), 1, COSINE, SINE )\n CALL DROT( 2, T(1,1), 2, T(2,1), 2, COSINE, SINE )\n A(J+1,J+1) = T(1,1)\n QG(J+1,J+2) = T(1,2)\n QG(J+1,J+1) = T(2,1)\nC\n IF ( FORM ) THEN\nC\nC Save rotation.\nC\n U(J,J) = COSINE\n U(J,N+J) = SINE\nC\n ELSE IF ( ACCUM ) THEN\nC\nC Accumulate rotation.\nC\n CALL DROT( N, U(1,J+1), 1, U(1,N+J+1), 1, COSINE, SINE )\n END IF\nC\nC DWORK := (A*A + G*Q)(J+1:N,J).\nC\n CALL DGEMV( 'NoTranspose', N-J, N, ONE, A(J+1,1), LDA, A(1,J),\n $ 1, ZERO, DWORK(J+1), 1 )\n CALL DGEMV( 'Transpose', J, N-J, ONE, QG(1,J+2), LDQG, QG(J,1),\n $ LDQG, ONE, DWORK(J+1), 1 )\n CALL DSYMV( 'Upper', N-J, ONE, QG(J+1,J+2), LDQG, QG(J+1,J), 1,\n $ ONE, DWORK(J+1), 1 )\nC\nC Symplectic reflection to zero (H*H)(J+2:N,J).\nC\n CALL DLARFG( N-J, DWORK(J+1), DWORK(J+2), 1, TAU )\n DWORK(J+1) = ONE\nC\n CALL DLARFX( 'Left', N-J, N, DWORK(J+1), TAU, A(J+1,1), LDA,\n $ DWORK(N+1) )\n CALL DLARFX( 'Right', N, N-J, DWORK(J+1), TAU, A(1,J+1), LDA,\n $ DWORK(N+1) )\nC\n CALL DLARFX( 'Left', N-J, J, DWORK(J+1), TAU, QG(J+1,1), LDQG,\n $ DWORK(N+1) )\n CALL DSYMV( 'Lower', N-J, TAU, QG(J+1,J+1), LDQG, DWORK(J+1),\n $ 1, ZERO, DWORK(N+J+1), 1 )\n CALL DAXPY( N-J, -TAU*DDOT( N-J, DWORK(N+J+1), 1, DWORK(J+1),\n $ 1 )/TWO, DWORK(J+1), 1, DWORK(N+J+1), 1 )\n CALL DSYR2( 'Lower', N-J, -ONE, DWORK(J+1), 1, DWORK(N+J+1), 1,\n $ QG(J+1,J+1), LDQG )\nC\n CALL DLARFX( 'Right', J, N-J, DWORK(J+1), TAU, QG(1,J+2), LDQG,\n $ DWORK(N+1) )\n CALL DSYMV( 'Upper', N-J, TAU, QG(J+1,J+2), LDQG, DWORK(J+1),\n $ 1, ZERO, DWORK(N+J+1), 1 )\n CALL DAXPY( N-J, -TAU*DDOT( N-J, DWORK(N+J+1), 1, DWORK(J+1),\n $ 1 )/TWO, DWORK(J+1), 1, DWORK(N+J+1), 1 )\n CALL DSYR2( 'Upper', N-J, -ONE, DWORK(J+1), 1, DWORK(N+J+1), 1,\n $ QG(J+1,J+2), LDQG )\nC\n IF ( FORM ) THEN\nC\nC Save reflection.\nC\n CALL DCOPY( N-J, DWORK(J+1), 1, U(J+1,N+J), 1 )\n U(J+1,N+J) = TAU\nC\n ELSE IF ( ACCUM ) THEN\nC\nC Accumulate reflection.\nC\n CALL DLARFX( 'Right', N, N-J, DWORK(J+1), TAU, U(1,J+1),\n $ LDU, DWORK(N+1) )\n CALL DLARFX( 'Right', N, N-J, DWORK(J+1), TAU, U(1,N+J+1),\n $ LDU, DWORK(N+1) )\n END IF\nC\n 10 CONTINUE\nC\n IF ( FORM ) THEN\n DUMMY(1) = ZERO\nC\nC Form S by accumulating transformations.\nC\n DO 20 J = N - 1, 1, -1\nC\nC Initialize (J+1)st column of S.\nC\n CALL DCOPY( N, DUMMY, 0, U(1,J+1), 1 )\n U(J+1,J+1) = ONE\n CALL DCOPY( N, DUMMY, 0, U(1,N+J+1), 1 )\nC\nC Second reflection.\nC\n TAU = U(J+1,N+J)\n U(J+1,N+J) = ONE\n CALL DLARFX( 'Left', N-J, N-J, U(J+1,N+J), TAU,\n $ U(J+1,J+1), LDU, DWORK(N+1) )\n CALL DLARFX( 'Left', N-J, N-J, U(J+1,N+J), TAU,\n $ U(J+1,N+J+1), LDU, DWORK(N+1) )\nC\nC Rotation.\nC\n CALL DROT( N-J, U(J+1,J+1), LDU, U(J+1,N+J+1), LDU,\n $ U(J,J), U(J,N+J) )\nC\nC First reflection.\nC\n TAU = U(J+1,J)\n U(J+1,J) = ONE\n CALL DLARFX( 'Left', N-J, N-J, U(J+1,J), TAU, U(J+1,J+1),\n $ LDU, DWORK(N+1) )\n CALL DLARFX( 'Left', N-J, N-J, U(J+1,J), TAU,\n $ U(J+1,N+J+1), LDU, DWORK(N+1) )\n 20 CONTINUE\nC\nC The first column is the first column of identity.\nC\n CALL DCOPY( N, DUMMY, 0, U, 1 )\n U(1,1) = ONE\n CALL DCOPY( N, DUMMY, 0, U(1,N+1), 1 )\n END IF\nC\n RETURN\nC *** Last line of MB04ZD ***\n END\n", "meta": {"hexsha": "11484d01a799f95b9ea5c08bf1b96fa2bac9f775", "size": 17341, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB04ZD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB04ZD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB04ZD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 36.6617336152, "max_line_length": 72, "alphanum_fraction": 0.4935701517, "num_tokens": 5934, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9334308147331957, "lm_q2_score": 0.7025300636233416, "lm_q1q2_score": 0.6557632096624996}} {"text": "! *********************************************************************\r\n! * *\r\n! * subroutine dcvit3 *\r\n! * *\r\n! *********************************************************************\r\n! Double Precision Version 2.0\r\n! Written by Gordon A. Fenton, TUNS, Aug. 2, 1993\r\n!\r\n! PURPOSE computes the initial k1*k2*k3 x k1*k2*k3 covariance matrix (and a\r\n! 27x27 submatrix) between local averages. Used by LAS3G.\r\n! \r\n!\r\n! This routine forms the covariance matrix R0 between local averages arranged\r\n! on a k1 x k2 x k3 grid using a user provided variance function \"dvarfn\" that\r\n! returns the variance of a local average (note that this is the point\r\n! variance sigma^2 times the traditionally \"variance\" function, as defined\r\n! by Vanmarcke in \"Random Fields\", MIT Press, 1984). The grid and element\r\n! numbering schemes appear as follows (for k1 = k2 = 5, k3 = 1 plane shown)\r\n!\r\n! | Dx |\r\n! --- --------------------------\r\n! Dy | 21 | 22 | 23 | 24 | 25 |\r\n! --- --------------------------\r\n! | 16 | 17 | 18 | 19 | 20 |\r\n! -------------------------- ----------------\r\n! | 11 | 12 | 13 | 14 | 15 | | 7 | 8 | 9 |\r\n! -------------------------- ----------------\r\n! | 6 | 7 | 8 | 9 | 10 | | 4 | 5 | 6 |\r\n! -------------------------- ----------------\r\n! | 1 | 2 | 3 | 4 | 5 | | 1 | 2 | 3 |\r\n! -------------------------- ----------------\r\n!\r\n! R0 Array R Array\r\n!\r\n! with the k1 x k2 array numbering on the left and a basic 3 x 3 subarray\r\n! shown on the right. In the depth direction (not shown), the numbering\r\n! continues; ie the element immediately behind element 1 on the left is\r\n! element number 26, etc. If we call Z_i the local average of a random process\r\n! over the i'th cell, then for E[Z] = 0, the elements of R0 are defined by\r\n!\r\n! R0(i,j) = E[Z_i*Z_j]\r\n!\r\n! Note that the elements of R are simply extracted directly from the\r\n! appropriate elements of R0 (for example, R(1,5) = R0(1,7)) if k1, k2 and k3\r\n! are greater than 2. Note also that since both R0 and R are symmetric, ONLY\r\n! THE UPPER TRIANGULAR VALUES are stored herein. Finally note that\r\n! the random process is assumed to be quadrant symmetric (that is the\r\n! covariance function is even in each individual lag component) to reduce\r\n! the total number of covariance calculations.\r\n!\r\n! Arguments to this routine are as follows;\r\n!\r\n! dvarfn external double precision function which returns the\r\n! variance of a local average of size X x Y x Z. This function\r\n! is referenced using the call \"V = dvarfn(X,Y,Z)\" (other\r\n! parameters to the function must be passed via common blocks).\r\n!\r\n! R0 double precision array of size at least k1*k2*k3 x k1*k2*k3\r\n! which on output will contain the covariance matrix between\r\n! the local average elements shown above on the left. Note\r\n! that since R0 is symmetric, only the upper triangular values\r\n! are actually stored (compatible with DCHOL2). (output)\r\n!\r\n! iq leading dimension of the array R0 as specified in the calling\r\n! routine. (input)\r\n!\r\n! R double precision array of size at least 27 x 27 which on output\r\n! will contain the covariance matrix between the local average\r\n! elements shown above on the right. Note that since R is\r\n! symmetric, only the upper triangular values are actually\r\n! stored (compatible with DSIFA). (output)\r\n!\r\n! ir leading dimension of the array R as specified in the calling\r\n! routine. (input)\r\n!\r\n! k1 number of local average cells in the x direction\r\n! (horizontally). (input)\r\n!\r\n! k2 number of local average cells in the y direction\r\n! (vertically). (input)\r\n!\r\n! k3 number of local average cells in the z direction\r\n! (depth). (input)\r\n!\r\n! Dx x-dimension of the local average cells. (input)\r\n!\r\n! Dy y-dimension of the local average cells. (input)\r\n!\r\n! Dz z-dimension of the local average cells. (input)\r\n!\r\n! Required:\r\n! 1) from libGAFsim:\tDCVAA3\r\n!----------------------------------------------------------------------------\r\n subroutine dcvit3( dvarfn, R0, iq, R, ir, k1, k2, k3, Dx, Dy, Dz )\r\n implicit real*8 (a-h,o-z)\r\n dimension R0(iq,*), R(ir,*)\r\n external dvarfn\r\n!\t\t\t\t\tfirst form the essential elements of R0\r\n ii = 0\r\n do 30 k = 1, k3\r\n tz = dble(k-1)\r\n do 20 j = 1, k2\r\n ty = dble(j-1)\r\n do 10 i = 1, k1\r\n ii = ii + 1\r\n tx = dble(i-1)\r\n R0(1,ii) = dcvaa3( dvarfn, Dx, Dy, Dz, tx, ty, tz )\r\n 10 continue\r\n 20 continue\r\n 30 continue\r\n!\t\t\t\t\tnow distribute into the upper triangle\r\n kk = k1*k2*k3\r\n k12 = k1*k2\r\n do 50 n = 2, kk\r\n n3 = (n-1)/k12\r\n n2 = (n - k12*n3 - 1)/k1\r\n do 40 m = 2, n\r\n m3 = (m-1)/k12\r\n m2 = (m - k12*m3 - 1)/k1\r\n i3 = m3 - n3\r\n i2 = m2 - n2\r\n i1 = (m-n) - k1*i2 - k12*i3\r\n k = 1 + iabs(i1) + k1*iabs(i2) + k12*iabs(i3)\r\n R0(m,n) = R0(1,k)\r\n 40 continue\r\n 50 continue\r\n!\t\t\t\t\tform R (27 x 27)\r\n\r\n if( k1 .lt. 3 .or. k2 .lt. 3 .or. k3 .lt. 3 ) then\r\n!\t\t\t\t\t\tfind essential elements of R\r\n ii = 0\r\n do 80 k = 1, 3\r\n tz = dble(k-1)\r\n do 70 j = 1, 3\r\n ty = dble(j-1)\r\n do 60 i = 1, 3\r\n tx = dble(i-1)\r\n ii = ii + 1\r\n R(1,ii) = dcvaa3( dvarfn, Dx, Dy, Dz, tx, ty, tz )\r\n 60 continue\r\n 70 continue\r\n 80 continue\r\n!\t\t\t\t\t\tand distribute into upper tri.\r\n do 100 n = 2, 27\r\n n3 = (n-1)/9\r\n n2 = (n - 9*n3 - 1)/3\r\n do 90 m = 2, n\r\n m3 = (m-1)/9\r\n m2 = (m - 9*m3 - 1)/3\r\n i3 = m3 - n3\r\n i2 = m2 - n2\r\n i1 = (m-n) - 3*i2 - 9*i3\r\n k = 1 + iabs(i1) + 3*iabs(i2) + 9*iabs(i3)\r\n R(m,n) = R(1,k)\r\n 90 continue\r\n 100 continue\r\n else\r\n!\t\t\t\t\t\tor extract R from R0\r\n do 120 n = 1, 27\r\n n3 = (n-1)/9\r\n n2 = (n - 9*n3 - 1)/3\r\n do 110 m = 1, n\r\n m3 = (m-1)/9\r\n m2 = (m - 9*m3 - 1)/3\r\n i3 = m3 - n3\r\n i2 = m2 - n2\r\n i1 = (m-n) - 3*i2 - 9*i3\r\n k = 1 + iabs(i1) + k1*iabs(i2) + k12*iabs(i3)\r\n R(m,n) = R0(1,k)\r\n 110 continue\r\n 120 continue\r\n endif\r\n\r\n return\r\n end\r\n\r\n", "meta": {"hexsha": "3c73f6739f3f5c86f236c48db7c6beb57208fa45", "size": 7156, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/libs/gaf95/dcvit3.f95", "max_stars_repo_name": "leemargetts/PoreFEM", "max_stars_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/libs/gaf95/dcvit3.f95", "max_issues_repo_name": "leemargetts/PoreFEM", "max_issues_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/libs/gaf95/dcvit3.f95", "max_forks_repo_name": "leemargetts/PoreFEM", "max_forks_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.4293785311, "max_line_length": 80, "alphanum_fraction": 0.4540245947, "num_tokens": 2068, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294982, "lm_q2_score": 0.7025300636233416, "lm_q1q2_score": 0.6557632070605407}} {"text": " subroutine mann(q0, ichan, slp, chnn, ishp, bw, s, y)\n\n implicit none\nc\nc + + + PURPOSE + + +\nc SR Mann solves depth y from Manning's equation.\nc\nc Called from: SR WSHCHR\nc Author(s): L. Wang\nc Reference in User Guide:\nc\nc Version:\nc Date recoded:\nc Recoded by:\nc\nc + + + KEYWORDS + + +\nc\nc + + + PARAMETERS + + +\nc\nc + + + ARGUMENT DECLARATIONS + + +\n real q0, slp, chnn, y, bw, s\n integer ichan, ishp\nc\nc + + + ARGUMENT DEFINITIONS + + +\nc\nc bw - channel width\nc chnn - Manning's roughness coefficient n\nc q0 - known discharge\nc s - inverse slope of the channel banks\nc slp - channel slope\nc y - depth of water flow\nc ichan - channel number\nc ishp - shape of the channel\nc\nc + + + COMMON BLOCKS + + +\nc\nc + + + LOCAL VARIABLES + + +\nc\n real area, rh, ay, ry, qi, dy, q0x, yx, eps, ap\n integer i, ichanx\nc\nc\nc + + + LOCAL DEFINITIONS + + +\nc\nc area - cross-sectional area of channel water flow\nc ay - derivative, AY = dA / dY\nc qi - calculated discharge\nc rh - hydraulic radius\nc ry - derivative, RY = dR / dY\nc ichanx - channel number\nc\nc + + + SAVES + + +\n save ichanx, q0x, yx\nc\nc + + + SUBROUTINES CALLED + + +\nc\nc + + + DATA INITIALIZATIONS + + +\nc\nc + + + END SPECIFICATIONS + + +\nc\nc\n eps = 1.e-6\n if(ichan /= ichanx .or. abs(q0 - q0x) > eps)then\nc--------------------------------------------------\n\t if(ishp == 1) then\nc\nc Triangular-shape channel\nc Calculate y explicitly.\nc\n y = 2.**0.25*(1.+s*s)**0.125*(chnn*q0)**0.375/\n 1 (slp**0.1875*s**0.625)\nc\nc--------------------------------------------------\n\t elseif(ishp == 2) then\nc\nc Rectangular-shape channel\nc Calculate y iteratively using Newton's method.\nc\nc First guess of y assuming bw >> y.\nc y = (chnn*q0/(sqrt(slp)*bw))**0.6\n y = 1.\nc\n\t i = 0\n400 i = i + 1\n\t area = bw * y\n\t rh = area / (bw + 2. * y)\n\t ay = bw ! ay = dA / dy\n\t ry = (bw / (bw + 2. * y))**2 ! ry = dR / dy\n qi = sqrt(slp) / chnn * area * rh ** (2./3.)\n\t dy = (q0/qi-1.) / (ay/area + 2./3.*ry/rh)\n\t y = y + dy\n\t if(y > 1) dy = dy / y\n if(abs(dy) > eps .and. i < 20) goto 400\nc--------------------------------------------------\nc--------------------------------------------------\n\t elseif(ishp == 3) then\nc\nc Parabolic-shape channel\nc Calculate y iteratively using Newton's method.\nc s = parabolic focal height\nc\n y = 1.\nc\n\t i = 0\n300 i = i + 1\n bw = 4. * sqrt(y * s) ! top width\n\t area = 2. * bw * y / 3.\n\t ap = 2.*sqrt(y*(s+y))+2.*s*log(sqrt(1.+y/s)+sqrt(y/s)) ! wetted perimeter\n\t rh = area / ap ! hydraulic radius\n\t ay = bw ! ay = dA / dy\n\t ry = bw/ap - 2.*area/(ap*ap)*sqrt(1.+s/y) ! ry = dR / dy\n qi = sqrt(slp) / chnn * area * rh ** (2./3.)\n\t dy = (q0/qi-1.) / (ay/area + 2./3.*ry/rh)\n\t y = y + dy\n\t if(y > 1) dy = dy / y\n if(abs(dy) > eps .and. i < 20) goto 300\nc--------------------------------------------------\nc--------------------------------------------------\n\t elseif(ishp >= 4) then\nc\nc Tropezoidal-shape channel\nc Calculate y iteratively using Newton's method.\nc\n y = 1.\nc\n\t i = 0\n200 i = i + 1\n\t area = (bw + s * y) * y\n\t rh = area / (bw + 2. * y * sqrt(1. + s * s))\n\t ay = bw + 2. * s * y\n\t ry = (bw*bw + 2.*bw*s*y + 2.*s*y*y*sqrt(1.+s*s))\n 1 / (bw + 2. * y * sqrt(1. + s * s))**2\n qi = sqrt(slp) / chnn * area * rh ** (2./3.)\n\t dy = (q0/qi-1.) / (ay/area + 2./3.*ry/rh)\n\t y = y + dy\n\t if(y > 1) dy = dy / y\n if(abs(dy) > eps .and. i < 20) goto 200\nc--------------------------------------------------\nc--------------------------------------------------\n\t endif\nc--------------------------------------------------\n\t ichanx = ichan\n\t q0x = q0\n\t yx = y\n\telse\n\t y = yx\n\tendif\nc\n return\n\tend\n", "meta": {"hexsha": "ee37d124bbe55670b49b5c1eb3c196015493a41d", "size": 4241, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/wepp2012-src/mann.for", "max_stars_repo_name": "jarad/dep", "max_stars_repo_head_hexsha": "fe73982f4c70039e1a31b9e8e2d9aac31502f803", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-11-26T17:49:19.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-26T17:49:19.000Z", "max_issues_repo_path": "src/wepp2012-src/mann.for", "max_issues_repo_name": "jarad/dep", "max_issues_repo_head_hexsha": "fe73982f4c70039e1a31b9e8e2d9aac31502f803", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 54, "max_issues_repo_issues_event_min_datetime": "2018-12-12T18:02:31.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T19:14:25.000Z", "max_forks_repo_path": "src/wepp2012-src/mann.for", "max_forks_repo_name": "akrherz/idep", "max_forks_repo_head_hexsha": "7189a26fbcec3d8c3cc7d7015107b8fb6c5f6a45", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-03-02T22:59:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-09T15:49:00.000Z", "avg_line_length": 28.0860927152, "max_line_length": 80, "alphanum_fraction": 0.4149964631, "num_tokens": 1396, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308091776495, "lm_q2_score": 0.7025300636233416, "lm_q1q2_score": 0.6557632057595614}} {"text": "program sobol_index_test\n\n use mo_kind, only: dp,i4, i8\n use mo_ansi_colors, only: color, c_red, c_green\n use mo_sobol, only: sobol\n use mo_model, only: getrange, model\n use mo_sobol_index, only: sobol_index\n\n implicit none\n\n integer(i4), parameter :: npara = 3 ! number of parameter\n integer(i4), parameter :: nsets = 1000 ! number of parametersets \n integer(i4), parameter :: nx = 100 ! number of variable values\n integer(i8) :: skip = 30000_i8 ! used for generating parameter sets \n ! ! via sobol sequences\n\n ! Samples and Model Output\n real(dp), dimension(npara,2) :: ParaRange ! array: Parameter ranges (Min, Max)\n real(dp), dimension(nx) :: x ! array: variable values\n\n ! Sobol index\n real(dp), dimension(2*npara) :: sample_sobol ! sobol sequence\n real(dp), dimension(npara) :: sample_a ! parameter sample A\n real(dp), dimension(npara) :: sample_b ! parameter sample B\n real(dp), dimension(npara) :: sample_ci ! parameter sample Ci\n real(dp), dimension(nsets,nx) :: ya, yb ! model output A and B, \n ! ! i.e. time series with nx time points\n real(dp), dimension(nsets,npara,nx) :: yc ! model output C(i), i=1,npara, \n ! ! i.e. time series with nx time points\n real(dp), dimension(npara,nx) :: si ! Sobol index (main effect) per time point and param.\n ! ! based on ya, yb, and yc\n real(dp), dimension(npara,nx) :: sti ! Sobol index (total effect) per time point and param.\n ! ! based on ya, yb, and yc\n real(dp), dimension(npara,2) :: smean ! Mean SI and STI\n real(dp), dimension(npara,2) :: wmean ! Variance weighted mean SI and STI\n\n integer(i8) :: seed\n\n ! Dummy variables\n integer(i4) :: set, para, i\n logical :: isgood = .true.\n\n ParaRange = GetRange()\n\n ! ------------------------------------------------------------------\n ! variable values, e.g. time points\n ! ------------------------------------------------------------------\n do i=1,nx\n x(i) = real(i-1,dp) * 1.0_dp + 50.0_dp\n end do\n\n ! ------------------------------------------------------------------\n ! Generating model outputs for parameter sets A, B, and C(i)\n ! ------------------------------------------------------------------\n seed = 0_i8\n call sobol(int(2*npara,i8), seed, sample_sobol)\n do set = 1,nsets\n ! sobol sequence\n call sobol(int(2*npara,i8), skip, sample_sobol)\n sample_a = sample_sobol(1:npara)\n sample_b = sample_sobol(npara+1:2*npara)\n ! scaling\n sample_a = ParaRange(:,1) + sample_a * (ParaRange(:,2) - ParaRange(:,1)) \n sample_b = ParaRange(:,1) + sample_b * (ParaRange(:,2) - ParaRange(:,1)) \n\n ya(set,:) = model(sample_a,x)\n yb(set,:) = model(sample_b,x)\n \n do para=1,npara\n sample_ci = sample_b\n sample_ci(para) = sample_a(para)\n yc(set,para,:) = model(sample_ci,x)\n end do\n end do\n\n ! ------------------------------------------------------------------\n ! Calculate Sobol index: Main Effect (Si) and Total Effect (STi)\n ! ------------------------------------------------------------------\n call sobol_index(ya, yb, yc, si, sti, method=6, smean=smean, wmean=wmean)\n \n ! ------------------------------------------------------------------\n ! Printing and checking\n ! ------------------------------------------------------------------\n write(*,'(A40)') '----------------------------------------'\n write(*,'(A24,F5.1,A8)') ' Sobol index (x = ',x(3),') '\n write(*,'(A40)') '----------------------------------------'\n write(*,'(A40)') 'para SI STI '\n do para=1,npara\n write(*,'(I4,A2,F7.4,A4,F7.4)') para, ' ', si(para,3),' ', sti(para,3)\n end do\n write(*,'(A40)') '----------------------------------------'\n write(*,*) ' '\n\n if (nint(si(1,3)*10000._dp) .ne. 3226_i4) isgood = .false.\n if (nint(si(2,3)*10000._dp) .ne. 1404_i4) isgood = .false.\n if (nint(si(3,3)*10000._dp) .ne. - 58_i4) isgood = .false.\n if (nint(sti(1,3)*10000._dp) .ne. 7826_i4) isgood = .false.\n if (nint(sti(2,3)*10000._dp) .ne. 1490_i4) isgood = .false.\n if (nint(sti(3,3)*10000._dp) .ne. 5348_i4) isgood = .false.\n\n write(*,'(A40)') '----------------------------------------'\n write(*,'(A40)') ' Mean Sobol index '\n write(*,'(A40)') '----------------------------------------'\n write(*,'(A40)') 'para SI STI '\n do para=1,npara\n write(*,'(I4,A2,F7.4,A4,F7.4)') para, ' ', smean(para,1),' ', smean(para,2)\n end do\n write(*,'(A40)') '----------------------------------------'\n write(*,*) ' '\n\n if (nint(smean(1,1)*10000._dp) .ne. 2417_i4) isgood = .false.\n if (nint(smean(2,1)*10000._dp) .ne. 3689_i4) isgood = .false.\n if (nint(smean(3,1)*10000._dp) .ne. 13_i4) isgood = .false.\n if (nint(smean(1,2)*10000._dp) .ne. 5784_i4) isgood = .false.\n if (nint(smean(2,2)*10000._dp) .ne. 3820_i4) isgood = .false.\n if (nint(smean(3,2)*10000._dp) .ne. 3980_i4) isgood = .false.\n\n write(*,'(A40)') '----------------------------------------'\n write(*,'(A40)') ' Var. weighted mean Sobol index '\n write(*,'(A40)') '----------------------------------------'\n write(*,'(A40)') 'para SI STI '\n do para=1,npara\n write(*,'(I4,A2,F7.4,A4,F7.4)') para, ' ', wmean(para,1),' ', wmean(para,2)\n end do\n write(*,'(A40)') '----------------------------------------'\n write(*,*) ' '\n\n if (nint(wmean(1,1)*10000._dp) .ne. 2319_i4) isgood = .false.\n if (nint(wmean(2,1)*10000._dp) .ne. 3963_i4) isgood = .false.\n if (nint(wmean(3,1)*10000._dp) .ne. 20_i4) isgood = .false.\n if (nint(wmean(1,2)*10000._dp) .ne. 5535_i4) isgood = .false.\n if (nint(wmean(2,2)*10000._dp) .ne. 4102_i4) isgood = .false.\n if (nint(wmean(3,2)*10000._dp) .ne. 3813_i4) isgood = .false.\n\n if (isgood) then\n write(*,*) 'mo_sobol_index ', color('o.k.', c_green)\n else\n write(*,*) 'mo_sobol_index ', color('failed', c_red)\n end if\n\nend program sobol_index_test\n", "meta": {"hexsha": "450e728ea89aca04f579e32245c8f3dda6fa53d0", "size": 7128, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/test_mo_sobol_index/main.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_sobol_index/main.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_sobol_index/main.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": 50.1971830986, "max_line_length": 130, "alphanum_fraction": 0.4191919192, "num_tokens": 2059, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008906, "lm_q2_score": 0.7248702702332475, "lm_q1q2_score": 0.6557542778452344}} {"text": " SUBROUTINE SB01BX( REIG, N, XR, XI, WR, WI, S, P )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To choose a real eigenvalue or a pair of complex conjugate\nC eigenvalues at \"minimal\" distance to a given real or complex\nC value.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC REIG LOGICAL\nC Specifies the type of eigenvalues as follows:\nC = .TRUE., a real eigenvalue is to be selected;\nC = .FALSE., a pair of complex eigenvalues is to be\nC selected.\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The number of eigenvalues contained in the arrays WR\nC and WI. N >= 1.\nC\nC XR,XI (input) DOUBLE PRECISION\nC If REIG = .TRUE., XR must contain the real value and XI\nC is assumed zero and therefore not referenced.\nC If REIG = .FALSE., XR must contain the real part and XI\nC the imaginary part, respectively, of the complex value.\nC\nC WR,WI (input/output) DOUBLE PRECISION array, dimension (N)\nC On entry, if REIG = .TRUE., WR must contain the real\nC eigenvalues from which an eigenvalue at minimal distance\nC to XR is to be selected. In this case, WI is considered\nC zero and therefore not referenced.\nC On entry, if REIG = .FALSE., WR and WI must contain the\nC real and imaginary parts, respectively, of the eigenvalues\nC from which a pair of complex conjugate eigenvalues at\nC minimal \"distance\" to XR + jXI is to be selected.\nC The eigenvalues of each pair of complex conjugate\nC eigenvalues must appear consecutively.\nC On exit, the elements of these arrays are reordered such\nC that the selected eigenvalue(s) is (are) found in the\nC last element(s) of these arrays.\nC\nC S,P (output) DOUBLE PRECISION\nC If REIG = .TRUE., S (and also P) contains the value of\nC the selected real eigenvalue.\nC If REIG = .FALSE., S and P contain the sum and product,\nC respectively, of the selected complex conjugate pair of\nC eigenvalues.\nC\nC FURTHER COMMENTS\nC\nC For efficiency reasons, |x| + |y| is used for a complex number\nC x + jy, instead of its modulus.\nC\nC CONTRIBUTOR\nC\nC A. Varga, German Aerospace Center, DLR Oberpfaffenhofen.\nC February 1999. Based on the RASP routine PMDIST.\nC\nC REVISIONS\nC\nC March 30, 1999, V. Sima, Research Institute for Informatics,\nC Bucharest.\nC Feb. 15, 2004, V. Sima, Research Institute for Informatics,\nC Bucharest.\nC\nC ******************************************************************\nC\nC .. Scalar Arguments ..\n LOGICAL REIG\n INTEGER N\n DOUBLE PRECISION P, S, XI ,XR\nC .. Array Arguments ..\n DOUBLE PRECISION WI(*), WR(*)\nC .. Local Scalars ..\n INTEGER I, J, K\n DOUBLE PRECISION X, Y\nC .. Intrinsic Functions ..\n INTRINSIC ABS\nC .. Executable Statements ..\nC\n J = 1\n IF( REIG ) THEN\n Y = ABS( WR(1)-XR )\n DO 10 I = 2, N\n X = ABS( WR(I)-XR )\n IF( X .LT. Y ) THEN\n Y = X\n J = I\n END IF\n 10 CONTINUE\n S = WR(J)\n K = N - J\n IF( K .GT. 0 ) THEN\n DO 20 I = J, J + K - 1\n WR(I) = WR(I+1)\n 20 CONTINUE\n WR(N) = S\n END IF\n P = S\n ELSE\n Y = ABS( WR(1)-XR ) + ABS( WI(1)-XI )\n DO 30 I = 3, N, 2\n X = ABS( WR(I)-XR ) + ABS( WI(I)-XI )\n IF( X .LT. Y ) THEN\n Y = X\n J = I\n END IF\n 30 CONTINUE\n X = WR(J)\n Y = WI(J)\n K = N - J - 1\n IF( K .GT. 0 ) THEN\n DO 40 I = J, J + K - 1\n WR(I) = WR(I+2)\n WI(I) = WI(I+2)\n 40 CONTINUE\n WR(N-1) = X\n WI(N-1) = Y\n WR(N) = X\n WI(N) = -Y\n END IF\n S = X + X\n P = X * X + Y * Y\n END IF\nC\n RETURN\nC *** End of SB01BX ***\n END\n", "meta": {"hexsha": "a67a022db62b1941255343efbf663be1d94b44f4", "size": 4287, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/SB01BX.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/SB01BX.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/SB01BX.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 31.2919708029, "max_line_length": 72, "alphanum_fraction": 0.5145789596, "num_tokens": 1215, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361652391385, "lm_q2_score": 0.7185944046238981, "lm_q1q2_score": 0.6556715229173314}} {"text": "\tSUBROUTINE VC_PONZ ( z, zt, zb, tt, tb, rlnpt, rlnpb,\n +\t\t\t nxy, p, iret ) \nC************************************************************************\nC* VC_PONZ\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This subroutine computes pressure on a height surface given\t\t*\nC* pressure, temperature and height on bounding surfaces.\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* VC_PONZ ( Z, ZT, ZB, TT, TB, RLNPT, RLNPB, NXY, P, IRET )\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tZ\t\tREAL\t\tHeight coordinate value\t\t*\nC*\tZT(*)\t\tREAL\t\tTop height\t\t\t*\nC*\tZB(*)\t\tREAL\t\tBottom height\t\t\t*\nC*\tTT(*)\t\tREAL\t\tTop temperature\t\t\t*\nC*\tTB(*)\t\tREAL\t\tBottom temperature\t\t*\nC*\tRLNPT(*)\tREAL\t\tTop ln (p)\t\t\t*\nC*\tRLNPB(*)\tREAL\t\tBottom ln (p)\t\t\t*\nC*\tNXY\t\tINTEGER\t\tNumber of points\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tP (NXY)\tREAL\t\tOutput pressure values\t\t*\nC*\tIRET\t\tINTEGER\t\tReturn code\t\t\t*\nC*\t\t\t\t\t 0 = normal return\t\t*\nC*\t\t\t\t\t +1 = all missing\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* K. Brill/NMC 07/92\t\t\t\t\t\t*\nC************************************************************************\n\tINCLUDE\t\t'GEMPRM.PRM'\n\tREAL\t\tzt (*), zb (*), tt (*), tb (*), rlnpt (*),\n +\t\t\trlnpb (*), p (*)\nC*\n\tPARAMETER\t( govr = 2. * GRAVTY / RDGAS )\n\tLOGICAL\t\tbetwen\nC*\n\tINCLUDE\t\t'ERMISS.FNC'\nC*\n\tBETWEN ( rlev, rlo, rhi ) = \n + ( ( rlev .ge. rlo .and. rlev .le. rhi ) .or.\n + ( rlev .le. rlo .and. rlev .ge. rhi ) )\nC-----------------------------------------------------------------------\n\tiret = 0\nC*\n\ticnt = 0\n\tDO i = 1, nxy\n\t IF ( .not. BETWEN ( z, zb (i), zt (i) ) .or.\n +\t\t ERMISS ( zt (i) ) .or. ERMISS ( zb (i) ) .or.\n +\t\t ERMISS ( tt (i) ) .or. ERMISS ( tb (i) ) .or.\n +\t\t ERMISS ( rlnpt (i) ) .or. ERMISS ( rlnpb (i) ) .or.\n +\t\t ( zb (i) .gt. zt (i) ) .or.\n +\t\t ( rlnpt (i) .eq. rlnpb (i) ) ) THEN\n\t\tp (i) = RMISSD\n\t\ticnt = icnt + 1\n\t ELSE\n\t\tgama = ( tt (i) - tb (i) ) / ( rlnpt (i) - rlnpb (i) )\n\t\tdzt = zt (i) - z\n\t\tIF ( gama .eq. 0.0 ) THEN\n\t\t pln = rlnpt (i) + .5 * govr * dzt / tt (i)\n\t\tELSE\n\t\t sq = tt (i) * tt (i) + govr * gama * dzt\n\t\t sq = ( SQRT ( sq ) - tt (i) ) / gama\n\t\t pln = rlnpt (i) + sq\n\t\tEND IF\n\t\tp (i) = EXP ( pln )\n\t END IF\n\tEND DO\nC*\n\tIF ( icnt .eq. nxy ) iret = +1\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "3643a4f1007c6ffc931f7e4c77d6d453239b8fc0", "size": 2224, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/programs/gd/gdvint/vcponz.f", "max_stars_repo_name": "oxelson/gempak", "max_stars_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2015-06-03T15:26:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T22:36:03.000Z", "max_issues_repo_path": "gempak/source/programs/gd/gdvint/vcponz.f", "max_issues_repo_name": "oxelson/gempak", "max_issues_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 60, "max_issues_repo_issues_event_min_datetime": "2015-05-11T21:36:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T16:22:42.000Z", "max_forks_repo_path": "gempak/source/programs/gd/gdvint/vcponz.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.4657534247, "max_line_length": 73, "alphanum_fraction": 0.434352518, "num_tokens": 914, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147439, "lm_q2_score": 0.7185944046238981, "lm_q1q2_score": 0.6556715160731548}} {"text": "! { dg-do run }\n! { dg-options \"-ffrontend-optimize -fdump-tree-original\" }\n! PR 57071 - Check that 2**k is transformed into ishift(1,k).\nprogram main\n implicit none\n integer :: i,m,v\n integer, parameter :: n=30\n integer, dimension(-n:n) :: a,b,c,d,e\n m = n\n\n v = 2\n ! Test scalar expressions.\n do i=-n,n\n if (2**i /= v**i) STOP 1\n end do\n\n ! Test array constructors\n b = [(2**i,i=-m,m)]\n c = [(v**i,i=-m,m)]\n if (any(b /= c)) STOP 2\n\n ! Test array expressions\n a = [(i,i=-m,m)]\n d = 2**a\n e = v**a\n if (any(d /= e)) STOP 3\nend program main\n! { dg-final { scan-tree-dump-times \"_gfortran_pow_i4_i4\" 3 \"original\" } }\n", "meta": {"hexsha": "d3e9ab86af70783e2eeb0901b117ab386b19c35f", "size": 638, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/power_4.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/power_4.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/power_4.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": 22.0, "max_line_length": 74, "alphanum_fraction": 0.5768025078, "num_tokens": 241, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118026095992, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.6556700566280346}} {"text": "! demo rotating a 2-D array 90 degrees clockwise\nuse rotflip, only: rot90, flipud, fliplr\n\nimplicit none\n\ninteger, parameter :: N=3\ninteger :: i, iarr(N,N), Barr(0:2, 0:2)\nreal :: rarr(N,N)\n\niarr = reshape( &\n [0, 1, 2, &\n 3, 4, 5, &\n 6, 7, 8], &\n shape(iarr), order=[2,1])\n\nrarr = iarr\n\n\ncall printarr(iarr,'before rot90')\n\ncall rot90(iarr, 0)\ncall printarr(iarr, 'rot90(0)')\n\ncall rot90(iarr, 1)\ncall printarr(iarr, 'rot90(1)')\ncall rot90(iarr, -1)\n\ncall rot90(iarr, 2)\ncall printarr(iarr, 'rot90(2)')\ncall rot90(iarr, -2)\n\ncall rot90(iarr, 3)\ncall printarr(iarr, 'rot90(3)')\ncall rot90(iarr, -3)\n\ncall flipud(iarr)\ncall printarr(iarr, 'flipud()')\ncall flipud(iarr)\n\ncall fliplr(iarr)\ncall printarr(iarr, 'fliplr()')\ncall fliplr(iarr)\n\n! -- test non-default bounds\nBarr = iarr\nif (lbound(Barr,1) /= 0) error stop 'lbound should be 0'\n\ncall rot90(Barr)\nif (lbound(Barr,1) /= 0) error stop 'lbound should be 0'\n\n! -- Fortran polymorphic type\nrarr = iarr\ncall rot90(rarr)\n\ncontains\n\n\nsubroutine printarr(arr, msg)\n\ninteger, intent(in) :: arr(:,:)\ncharacter(*), intent(in), optional :: msg\ncharacter(5) :: frmt\n\nwrite(frmt,'(A1,I1,A3)') '(',size(arr,1),'I1)'\n\nif(present(msg)) print *,msg\ndo i = 1, size(arr,1)\n print frmt, arr(i,:)\nenddo\n\n\nend subroutine printarr\nend program\n", "meta": {"hexsha": "703cb549b4b838f24575dde7e02778a0b23369b9", "size": 1284, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "array/test_rot90.f90", "max_stars_repo_name": "plasmasimulation/fortran2018-examples", "max_stars_repo_head_hexsha": "0a7d336e0fc8508b2d6c0e30eff0c3325c57f735", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-04-28T02:10:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-28T02:10:26.000Z", "max_issues_repo_path": "array/test_rot90.f90", "max_issues_repo_name": "plasmasimulation/fortran2018-examples", "max_issues_repo_head_hexsha": "0a7d336e0fc8508b2d6c0e30eff0c3325c57f735", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "array/test_rot90.f90", "max_forks_repo_name": "plasmasimulation/fortran2018-examples", "max_forks_repo_head_hexsha": "0a7d336e0fc8508b2d6c0e30eff0c3325c57f735", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.3513513514, "max_line_length": 56, "alphanum_fraction": 0.6588785047, "num_tokens": 482, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.793105941403651, "lm_q2_score": 0.8267117962054048, "lm_q1q2_score": 0.6556700373989909}} {"text": "MODULE movmod\nCONTAINS\n SUBROUTINE shape_function(phi,j,k,s)\n ! Returns the Hermite interpolating polynomials on [0,1] and their \n ! derivatives up to order 6\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: j, k\n REAL(kind=8), INTENT(IN) :: s\n REAL(kind=8), INTENT(OUT) :: phi\n\n if (j == 0) then\n if (k == 0) then\n phi = (1.0d0) - &\n (462.0d0)*(s**6.0d0) + &\n (1980.0d0)*(s**7.0d0) - &\n (3465.0d0)*(s**8.0d0) + &\n (3080.0d0)*(s**9.0d0) - &\n (1386.0d0)*(s**10.0d0) + &\n (252.0d0)*(s**11.0d0)\n else if (k == 1) then\n phi = -(2772.0d0)*(s**5.0d0) + &\n (13860.0d0)*(s**6.0d0) - &\n (27720.0d0)*(s**7.0d0) + &\n (27720.0d0)*(s**8.0d0) - &\n (13860.0d0)*(s**9.0d0) + &\n (2772.0d0)*(s**10.0d0)\n else if (k == 2) then\n phi = -(13860.0d0)*(s**4.0d0) + &\n (83160.0d0)*(s**5.0d0) - &\n (194040.0d0)*(s**6.0d0) + &\n (221760.0d0)*(s**7.0d0) - &\n (124740.0d0)*(s**8.0d0) + &\n (27720.0d0)*(s**9.0d0)\n else if (k == 3) then\n phi = -(55440.0d0)*(s**3.0d0) + &\n (415800.0d0)*(s**4.0d0) - &\n (1164240.0d0)*(s**5.0d0) + &\n (1552320.0d0)*(s**6.0d0) - &\n (997920.0d0)*(s**7.0d0) + &\n (249480.0d0)*(s**8.0d0)\n else if (k == 4) then\n phi = -(166320.0d0)*(s**2.0d0) + &\n (1663200.0d0)*(s**3.0d0) - &\n (5821200.0d0)*(s**4.0d0) + &\n (9313920.0d0)*(s**5.0d0) - &\n (6985440.0d0)*(s**6.0d0) + &\n (1995840.0d0)*(s**7.0d0)\n else if (k == 5) then\n phi = -(332640.0d0)*s + &\n (4989600.0d0)*(s**2.0d0) - &\n (23284800.0d0)*(s**3.0d0) + &\n (46569600.0d0)*(s**4.0d0) - &\n (41912640.0d0)*(s**5.0d0) + &\n (13970880.0d0)*(s**6.0d0)\n else if (k == 6) then\n phi = -(332640.0d0) + &\n (9979200.0d0)*s - &\n (69854400.0d0)*(s**2.0d0) + &\n (186278400.0d0)*(s**3.0d0) - &\n (209563200.0d0)*(s**4.0d0) + &\n (83825280.0d0)*(s**5.0d0)\n end if\n else if (j == 1) then\n if (k == 0) then\n phi = s - &\n (252.0d0)*(s**6.0d0) + &\n (1050.0d0)*(s**7.0d0) - &\n (1800.0d0)*(s**8.0d0) + &\n (1575.0d0)*(s**9.0d0) - &\n (700.0d0)*(s**10.0d0) + &\n (126.0d0)*(s**11.0d0)\n else if (k == 1) then\n phi = (1.0d0) - &\n (1512.0d0)*(s**5.0d0) + &\n (7350.0d0)*(s**6.0d0) - &\n (14400.0d0)*(s**7.0d0) + &\n (14175.0d0)*(s**8.0d0) - &\n (7000.0d0)*(s**9.0d0) + &\n (1386.0d0)*(s**10.0d0)\n else if (k == 2) then\n phi = -(7560.0d0)*(s**4.0d0) + &\n (44100.0d0)*(s**5.0d0) - &\n (100800.0d0)*(s**6.0d0) + &\n (113400.0d0)*(s**7.0d0) - &\n (63000.0d0)*(s**8.0d0) + &\n (13860.0d0)*(s**9.0d0)\n else if (k == 3) then\n phi = -(30240.0d0)*(s**3.0d0) + &\n (220500.0d0)*(s**4.0d0) - &\n (604800.0d0)*(s**5.0d0) + &\n (793800.0d0)*(s**6.0d0) - &\n (504000.0d0)*(s**7.0d0) + &\n (124740.0d0)*(s**8.0d0)\n else if (k == 4) then\n phi = -(90720.0d0)*(s**2.0d0) + &\n (882000.0d0)*(s**3.0d0) - &\n (3024000.0d0)*(s**4.0d0) + &\n (4762800.0d0)*(s**5.0d0) - &\n (3528000.0d0)*(s**6.0d0) + &\n (997920.0d0)*(s**7.0d0)\n else if (k == 5) then\n phi = -(181440.0d0)*s + &\n (2646000.0d0)*(s**2.0d0) - &\n (12096000.0d0)*(s**3.0d0) + &\n (23814000.0d0)*(s**4.0d0) - &\n (21168000.0d0)*(s**5.0d0) + &\n (6985440.0d0)*(s**6.0d0)\n else if (k == 6) then\n phi = -(181440.0d0) + &\n (5292000.0d0)*s - &\n (36288000.0d0)*(s**2.0d0) + &\n (95256000.0d0)*(s**3.0d0) - &\n (105840000.0d0)*(s**4.0d0) + &\n (41912640.0d0)*(s**5.0d0)\n end if\n else if (j == 2) then\n if (k == 0) then\n phi = (1.0d0/2.0d0)*(s**2.0d0) - &\n (63.0d0)*(s**6.0d0) + &\n (252.0d0)*(s**7.0d0) - &\n (420.0d0)*(s**8.0d0) + &\n (360.0d0)*(s**9.0d0) - &\n (315.0d0/2.0d0)*(s**10.0d0) + &\n (28.0d0)*(s**11.0d0)\n else if (k == 1) then\n phi = s - &\n (378.0d0)*(s**5.0d0) + &\n (1764.0d0)*(s**6.0d0) - &\n (3360.0d0)*(s**7.0d0) + &\n (3240.0d0)*(s**8.0d0) - &\n (1575.0d0)*(s**9.0d0) + &\n (308.0d0)*(s**10.0d0)\n else if (k == 2) then\n phi = (1.0d0) - &\n (1890.0d0)*(s**4.0d0) + &\n (10584.0d0)*(s**5.0d0) - &\n (23520.0d0)*(s**6.0d0) + &\n (25920.0d0)*(s**7.0d0) - &\n (14175.0d0)*(s**8.0d0) + &\n (3080.0d0)*(s**9.0d0)\n else if (k == 3) then\n phi = -(7560.0d0)*(s**3.0d0) + &\n (52920.0d0)*(s**4.0d0) - &\n (141120.0d0)*(s**5.0d0) + &\n (181440.0d0)*(s**6.0d0) - &\n (113400.0d0)*(s**7.0d0) + &\n (27720.0d0)*(s**8.0d0)\n else if (k == 4) then\n phi = -(22680.0d0)*(s**2.0d0) + &\n (211680.0d0)*(s**3.0d0) - &\n (705600.0d0)*(s**4.0d0) + &\n (1088640.0d0)*(s**5.0d0) - &\n (793800.0d0)*(s**6.0d0) + &\n (221760.0d0)*(s**7.0d0)\n else if (k == 5) then\n phi = -(45360.0d0)*s + &\n (635040.0d0)*(s**2.0d0) - &\n (2822400.0d0)*(s**3.0d0) + &\n (5443200.0d0)*(s**4.0d0) - &\n (4762800.0d0)*(s**5.0d0) + &\n (1552320.0d0)*(s**6.0d0)\n else if (k == 6) then\n phi = -(45360.0d0) + &\n (1270080.0d0)*s - &\n (8467200.0d0)*(s**2.0d0) + &\n (21772800.0d0)*(s**3.0d0) - &\n (23814000.0d0)*(s**4.0d0) + &\n (9313920.0d0)*(s**5.0d0)\n end if\n else if (j == 3) then\n if (k == 0) then\n phi = (1.0d0/6.0d0)*(s**3.0d0) - &\n (28.0d0/3.0d0)*(s**6.0d0) + &\n (35.0d0)*(s**7.0d0) - &\n (56.0d0)*(s**8.0d0) + &\n (140.0d0/3.0d0)*(s**9.0d0) - &\n (20.0d0)*(s**10.0d0) + &\n (7.0d0/2.0d0)*(s**11.0d0)\n else if (k == 1) then\n phi = (1.0d0/2.0d0)*(s**2.0d0) - &\n (56.0d0)*(s**5.0d0) + &\n (245.0d0)*(s**6.0d0) - &\n (448.0d0)*(s**7.0d0) + &\n (420.0d0)*(s**8.0d0) - &\n (200.0d0)*(s**9.0d0) + &\n (77.0d0/2.0d0)*(s**10.0d0)\n else if (k == 2) then\n phi = s - &\n (280.0d0)*(s**4.0d0) + &\n (1470.0d0)*(s**5.0d0) - &\n (3136.0d0)*(s**6.0d0) + &\n (3360.0d0)*(s**7.0d0) - &\n (1800.0d0)*(s**8.0d0) + &\n (385.0d0)*(s**9.0d0)\n else if (k == 3) then\n phi = (1.0d0) - &\n (1120.0d0)*(s**3.0d0) + &\n (7350.0d0)*(s**4.0d0) - &\n (18816.0d0)*(s**5.0d0) + &\n (23520.0d0)*(s**6.0d0) - &\n (14400.0d0)*(s**7.0d0) + &\n (3465.0d0)*(s**8.0d0)\n else if (k == 4) then\n phi = -(3360.0d0)*(s**2.0d0) + &\n (29400.0d0)*(s**3.0d0) - &\n (94080.0d0)*(s**4.0d0) + &\n (141120.0d0)*(s**5.0d0) - &\n (100800.0d0)*(s**6.0d0) + &\n (27720.0d0)*(s**7.0d0)\n else if (k == 5) then\n phi = -(6720.0d0)*s + &\n (88200.0d0)*(s**2.0d0) - &\n (376320.0d0)*(s**3.0d0) + &\n (705600.0d0)*(s**4.0d0) - &\n (604800.0d0)*(s**5.0d0) + &\n (194040.0d0)*(s**6.0d0)\n else if (k == 6) then\n phi = -(6720.0d0) + &\n (176400.0d0)*s - &\n (1128960.0d0)*(s**2.0d0) + &\n (2822400.0d0)*(s**3.0d0) - &\n (3024000.0d0)*(s**4.0d0) + &\n (1164240.0d0)*(s**5.0d0)\n end if\n else if (j == 4) then\n if (k == 0) then\n phi = (1.0d0/24.0d0)*(s**4.0d0) - &\n (7.0d0/8.0d0)*(s**6.0d0) + &\n (35.0d0/12.0d0)*(s**7.0d0) - &\n (35.0d0/8.0d0)*(s**8.0d0) + &\n (7.0d0/2.0d0)*(s**9.0d0) - &\n (35.0d0/24.0d0)*(s**10.0d0) + &\n (1.0d0/4.0d0)*(s**11.0d0)\n else if (k == 1) then\n phi = (1.0d0/6.0d0)*(s**3.0d0) - &\n (21.0d0/4.0d0)*(s**5.0d0) + &\n (245.0d0/12.0d0)*(s**6.0d0) - &\n (35.0d0)*(s**7.0d0) + &\n (63.0d0/2.0d0)*(s**8.0d0) - &\n (175.0d0/12.0d0)*(s**9.0d0) + &\n (11.0d0/4.0d0)*(s**10.0d0)\n else if (k == 2) then\n phi = (1.0d0/2.0d0)*(s**2.0d0) - &\n (105.0d0/4.0d0)*(s**4.0d0) + &\n (245.0d0/2.0d0)*(s**5.0d0) - &\n (245.0d0)*(s**6.0d0) + &\n (252.0d0)*(s**7.0d0) - &\n (525.0d0/4.0d0)*(s**8.0d0) + &\n (55.0d0/2.0d0)*(s**9.0d0)\n else if (k == 3) then\n phi = s - &\n (105.0d0)*(s**3.0d0) + &\n (1225.0d0/2.0d0)*(s**4.0d0) - &\n (1470.0d0)*(s**5.0d0) + &\n (1764.0d0)*(s**6.0d0) - &\n (1050.0d0)*(s**7.0d0) + &\n (495.0d0/2.0d0)*(s**8.0d0)\n else if (k == 4) then\n phi = (1.0d0) - &\n (315.0d0)*(s**2.0d0) + &\n (2450.0d0)*(s**3.0d0) - &\n (7350.0d0)*(s**4.0d0) + &\n (10584.0d0)*(s**5.0d0) - &\n (7350.0d0)*(s**6.0d0) + &\n (1980.0d0)*(s**7.0d0)\n else if (k == 5) then\n phi = -(630.0d0)*s + &\n (7350.0d0)*(s**2.0d0) - &\n (29400.0d0)*(s**3.0d0) + &\n (52920.0d0)*(s**4.0d0) - &\n (44100.0d0)*(s**5.0d0) + &\n (13860.0d0)*(s**6.0d0)\n else if (k == 6) then\n phi = -(630.0d0) + &\n (14700.0d0)*s - &\n (88200.0d0)*(s**2.0d0) + &\n (211680.0d0)*(s**3.0d0) - &\n (220500.0d0)*(s**4.0d0) + &\n (83160.0d0)*(s**5.0d0)\n end if\n else if (j == 5) then\n if (k == 0) then\n phi = (1.0d0/120.0d0)*(s**5.0d0) - &\n (1.0d0/20.0d0)*(s**6.0d0) + &\n (1.0d0/8.0d0)*(s**7.0d0) - &\n (1.0d0/6.0d0)*(s**8.0d0) + &\n (1.0d0/8.0d0)*(s**9.0d0) - &\n (1.0d0/20.0d0)*(s**10.0d0) + &\n (1.0d0/120.0d0)*(s**11.0d0)\n else if (k == 1) then\n phi = (1.0d0/24.0d0)*(s**4.0d0) - &\n (3.0d0/10.0d0)*(s**5.0d0) + &\n (7.0d0/8.0d0)*(s**6.0d0) - &\n (4.0d0/3.0d0)*(s**7.0d0) + &\n (9.0d0/8.0d0)*(s**8.0d0) - &\n (1.0d0/2.0d0)*(s**9.0d0) + &\n (11.0d0/120.0d0)*(s**10.0d0)\n else if (k == 2) then\n phi = (1.0d0/6.0d0)*(s**3.0d0) - &\n (3.0d0/2.0d0)*(s**4.0d0) + &\n (21.0d0/4.0d0)*(s**5.0d0) - &\n (28.0d0/3.0d0)*(s**6.0d0) + &\n (9.0d0)*(s**7.0d0) - &\n (9.0d0/2.0d0)*(s**8.0d0) + &\n (11.0d0/12.0d0)*(s**9.0d0)\n else if (k == 3) then\n phi = (1.0d0/2.0d0)*(s**2.0d0) - &\n (6.0d0)*(s**3.0d0) + &\n (105.0d0/4.0d0)*(s**4.0d0) - &\n (56.0d0)*(s**5.0d0) + &\n (63.0d0)*(s**6.0d0) - &\n (36.0d0)*(s**7.0d0) + &\n (33.0d0/4.0d0)*(s**8.0d0)\n else if (k == 4) then\n phi = s - &\n (18.0d0)*(s**2.0d0) + &\n (105.0d0)*(s**3.0d0) - &\n (280.0d0)*(s**4.0d0) + &\n (378.0d0)*(s**5.0d0) - &\n (252.0d0)*(s**6.0d0) + &\n (66.0d0)*(s**7.0d0)\n else if (k == 5) then\n phi = (1.0d0) - &\n (36.0d0)*s + &\n (315.0d0)*(s**2.0d0) - &\n (1120.0d0)*(s**3.0d0) + &\n (1890.0d0)*(s**4.0d0) - &\n (1512.0d0)*(s**5.0d0) + &\n (462.0d0)*(s**6.0d0)\n else if (k == 6) then\n phi = -(36.0d0) + &\n (630.0d0)*s - &\n (3360.0d0)*(s**2.0d0) + &\n (7560.0d0)*(s**3.0d0) - &\n (7560.0d0)*(s**4.0d0) + &\n (2772.0d0)*(s**5.0d0)\n end if\n else if (j == 6) then\n if (k == 0) then\n phi = (462.0d0)*(s**6.0d0) - &\n (1980.0d0)*(s**7.0d0) + &\n (3465.0d0)*(s**8.0d0) - &\n (3080.0d0)*(s**9.0d0) + &\n (1386.0d0)*(s**10.0d0) - &\n (252.0d0)*(s**11.0d0)\n else if (k == 1) then\n phi = (2772.0d0)*(s**5.0d0) - &\n (13860.0d0)*(s**6.0d0) + &\n (27720.0d0)*(s**7.0d0) - &\n (27720.0d0)*(s**8.0d0) + &\n (13860.0d0)*(s**9.0d0) - &\n (2772.0d0)*(s**10.0d0)\n else if (k == 2) then\n phi = (13860.0d0)*(s**4.0d0) - &\n (83160.0d0)*(s**5.0d0) + &\n (194040.0d0)*(s**6.0d0) - &\n (221760.0d0)*(s**7.0d0) + &\n (124740.0d0)*(s**8.0d0) - &\n (27720.0d0)*(s**9.0d0)\n else if (k == 3) then\n phi = (55440.0d0)*(s**3.0d0) - &\n (415800.0d0)*(s**4.0d0) + &\n (1164240.0d0)*(s**5.0d0) - &\n (1552320.0d0)*(s**6.0d0) + &\n (997920.0d0)*(s**7.0d0) - &\n (249480.0d0)*(s**8.0d0)\n else if (k == 4) then\n phi = (166320.0d0)*(s**2.0d0) - &\n (1663200.0d0)*(s**3.0d0) + &\n (5821200.0d0)*(s**4.0d0) - &\n (9313920.0d0)*(s**5.0d0) + &\n (6985440.0d0)*(s**6.0d0) - &\n (1995840.0d0)*(s**7.0d0)\n else if (k == 5) then\n phi = (332640.0d0)*s - &\n (4989600.0d0)*(s**2.0d0) + &\n (23284800.0d0)*(s**3.0d0) - &\n (46569600.0d0)*(s**4.0d0) + &\n (41912640.0d0)*(s**5.0d0) - &\n (13970880.0d0)*(s**6.0d0)\n else if (k == 6) then\n phi = (332640.0d0) - &\n (9979200.0d0)*s + &\n (69854400.0d0)*(s**2.0d0) - &\n (186278400.0d0)*(s**3.0d0) + &\n (209563200.0d0)*(s**4.0d0) - &\n (83825280.0d0)*(s**5.0d0)\n end if\n else if (j == 7) then\n if (k == 0) then\n phi = -(210.0d0)*(s**6.0d0) + &\n (930.0d0)*(s**7.0d0) - &\n (1665.0d0)*(s**8.0d0) + &\n (1505.0d0)*(s**9.0d0) - &\n (686.0d0)*(s**10.0d0) + &\n (126.0d0)*(s**11.0d0)\n else if (k == 1) then\n phi = -(1260.0d0)*(s**5.0d0) + &\n (6510.0d0)*(s**6.0d0) - &\n (13320.0d0)*(s**7.0d0) + &\n (13545.0d0)*(s**8.0d0) - &\n (6860.0d0)*(s**9.0d0) + &\n (1386.0d0)*(s**10.0d0)\n else if (k == 2) then\n phi = -(6300.0d0)*(s**4.0d0) + &\n (39060.0d0)*(s**5.0d0) - &\n (93240.0d0)*(s**6.0d0) + &\n (108360.0d0)*(s**7.0d0) - &\n (61740.0d0)*(s**8.0d0) + &\n (13860.0d0)*(s**9.0d0)\n else if (k == 3) then\n phi = -(25200.0d0)*(s**3.0d0) + &\n (195300.0d0)*(s**4.0d0) - &\n (559440.0d0)*(s**5.0d0) + &\n (758520.0d0)*(s**6.0d0) - &\n (493920.0d0)*(s**7.0d0) + &\n (124740.0d0)*(s**8.0d0)\n else if (k == 4) then\n phi = -(75600.0d0)*(s**2.0d0) + &\n (781200.0d0)*(s**3.0d0) - &\n (2797200.0d0)*(s**4.0d0) + &\n (4551120.0d0)*(s**5.0d0) - &\n (3457440.0d0)*(s**6.0d0) + &\n (997920.0d0)*(s**7.0d0)\n else if (k == 5) then\n phi = -(151200.0d0)*s + &\n (2343600.0d0)*(s**2.0d0) - &\n (11188800.0d0)*(s**3.0d0) + &\n (22755600.0d0)*(s**4.0d0) - &\n (20744640.0d0)*(s**5.0d0) + &\n (6985440.0d0)*(s**6.0d0)\n else if (k == 6) then\n phi = -(151200.0d0) + &\n (4687200.0d0)*s - &\n (33566400.0d0)*(s**2.0d0) + &\n (91022400.0d0)*(s**3.0d0) - &\n (103723200.0d0)*(s**4.0d0) + &\n (41912640.0d0)*(s**5.0d0)\n end if\n else if (j == 8) then\n if (k == 0) then\n phi = (42.0d0)*(s**6.0d0) - &\n (192.0d0)*(s**7.0d0) + &\n (705.0d0/2.0d0)*(s**8.0d0) - &\n (325.0d0)*(s**9.0d0) + &\n (301.0d0/2.0d0)*(s**10.0d0) - &\n (28.0d0)*(s**11.0d0)\n else if (k == 1) then\n phi = (252.0d0)*(s**5.0d0) - &\n (1344.0d0)*(s**6.0d0) + &\n (2820.0d0)*(s**7.0d0) - &\n (2925.0d0)*(s**8.0d0) + &\n (1505.0d0)*(s**9.0d0) - &\n (308.0d0)*(s**10.0d0)\n else if (k == 2) then\n phi = (1260.0d0)*(s**4.0d0) - &\n (8064.0d0)*(s**5.0d0) + &\n (19740.0d0)*(s**6.0d0) - &\n (23400.0d0)*(s**7.0d0) + &\n (13545.0d0)*(s**8.0d0) - &\n (3080.0d0)*(s**9.0d0)\n else if (k == 3) then\n phi = (5040.0d0)*(s**3.0d0) - &\n (40320.0d0)*(s**4.0d0) + &\n (118440.0d0)*(s**5.0d0) - &\n (163800.0d0)*(s**6.0d0) + &\n (108360.0d0)*(s**7.0d0) - &\n (27720.0d0)*(s**8.0d0)\n else if (k == 4) then\n phi = (15120.0d0)*(s**2.0d0) - &\n (161280.0d0)*(s**3.0d0) + &\n (592200.0d0)*(s**4.0d0) - &\n (982800.0d0)*(s**5.0d0) + &\n (758520.0d0)*(s**6.0d0) - &\n (221760.0d0)*(s**7.0d0)\n else if (k == 5) then\n phi = (30240.0d0)*s - &\n (483840.0d0)*(s**2.0d0) + &\n (2368800.0d0)*(s**3.0d0) - &\n (4914000.0d0)*(s**4.0d0) + &\n (4551120.0d0)*(s**5.0d0) - &\n (1552320.0d0)*(s**6.0d0)\n else if (k == 6) then\n phi = (30240.0d0) - &\n (967680.0d0)*s + &\n (7106400.0d0)*(s**2.0d0) - &\n (19656000.0d0)*(s**3.0d0) + &\n (22755600.0d0)*(s**4.0d0) - &\n (9313920.0d0)*(s**5.0d0)\n end if\n else if (j == 9) then\n if (k == 0) then\n phi = -(14.0d0/3.0d0)*(s**6.0d0) + &\n (22.0d0)*(s**7.0d0) - &\n (83.0d0/2.0d0)*(s**8.0d0) + &\n (235.0d0/6.0d0)*(s**9.0d0) - &\n (37.0d0/2.0d0)*(s**10.0d0) + &\n (7.0d0/2.0d0)*(s**11.0d0)\n else if (k == 1) then\n phi = -(28.0d0)*(s**5.0d0) + &\n (154.0d0)*(s**6.0d0) - &\n (332.0d0)*(s**7.0d0) + &\n (705.0d0/2.0d0)*(s**8.0d0) - &\n (185.0d0)*(s**9.0d0) + &\n (77.0d0/2.0d0)*(s**10.0d0)\n else if (k == 2) then\n phi = -(140.0d0)*(s**4.0d0) + &\n (924.0d0)*(s**5.0d0) - &\n (2324.0d0)*(s**6.0d0) + &\n (2820.0d0)*(s**7.0d0) - &\n (1665.0d0)*(s**8.0d0) + &\n (385.0d0)*(s**9.0d0)\n else if (k == 3) then\n phi = -(560.0d0)*(s**3.0d0) + &\n (4620.0d0)*(s**4.0d0) - &\n (13944.0d0)*(s**5.0d0) + &\n (19740.0d0)*(s**6.0d0) - &\n (13320.0d0)*(s**7.0d0) + &\n (3465.0d0)*(s**8.0d0)\n else if (k == 4) then\n phi = -(1680.0d0)*(s**2.0d0) + &\n (18480.0d0)*(s**3.0d0) - &\n (69720.0d0)*(s**4.0d0) + &\n (118440.0d0)*(s**5.0d0) - &\n (93240.0d0)*(s**6.0d0) + &\n (27720.0d0)*(s**7.0d0)\n else if (k == 5) then\n phi = -(3360.0d0)*s + &\n (55440.0d0)*(s**2.0d0) - &\n (278880.0d0)*(s**3.0d0) + &\n (592200.0d0)*(s**4.0d0) - &\n (559440.0d0)*(s**5.0d0) + &\n (194040.0d0)*(s**6.0d0)\n else if (k == 6) then\n phi = -(3360.0d0) + &\n (110880.0d0)*s - &\n (836640.0d0)*(s**2.0d0) + &\n (2368800.0d0)*(s**3.0d0) - &\n (2797200.0d0)*(s**4.0d0) + &\n (1164240.0d0)*(s**5.0d0)\n end if\n else if (j == 10) then\n if (k == 0) then\n phi = (7.0d0/24.0d0)*(s**6.0d0) - &\n (17.0d0/12.0d0)*(s**7.0d0) + &\n (11.0d0/4.0d0)*(s**8.0d0) - &\n (8.0d0/3.0d0)*(s**9.0d0) + &\n (31.0d0/24.0d0)*(s**10.0d0) - &\n (1.0d0/4.0d0)*(s**11.0d0)\n else if (k == 1) then\n phi = (7.0d0/4.0d0)*(s**5.0d0) - &\n (119.0d0/12.0d0)*(s**6.0d0) + &\n (22.0d0)*(s**7.0d0) - &\n (24.0d0)*(s**8.0d0) + &\n (155.0d0/12.0d0)*(s**9.0d0) - &\n (11.0d0/4.0d0)*(s**10.0d0)\n else if (k == 2) then\n phi = (35.0d0/4.0d0)*(s**4.0d0) - &\n (119.0d0/2.0d0)*(s**5.0d0) + &\n (154.0d0)*(s**6.0d0) - &\n (192.0d0)*(s**7.0d0) + &\n (465.0d0/4.0d0)*(s**8.0d0) - &\n (55.0d0/2.0d0)*(s**9.0d0)\n else if (k == 3) then\n phi = (35.0d0)*(s**3.0d0) - &\n (595.0d0/2.0d0)*(s**4.0d0) + &\n (924.0d0)*(s**5.0d0) - &\n (1344.0d0)*(s**6.0d0) + &\n (930.0d0)*(s**7.0d0) - &\n (495.0d0/2.0d0)*(s**8.0d0)\n else if (k == 4) then\n phi = (105.0d0)*(s**2.0d0) - &\n (1190.0d0)*(s**3.0d0) + &\n (4620.0d0)*(s**4.0d0) - &\n (8064.0d0)*(s**5.0d0) + &\n (6510.0d0)*(s**6.0d0) - &\n (1980.0d0)*(s**7.0d0)\n else if (k == 5) then\n phi = (210.0d0)*s - &\n (3570.0d0)*(s**2.0d0) + &\n (18480.0d0)*(s**3.0d0) - &\n (40320.0d0)*(s**4.0d0) + &\n (39060.0d0)*(s**5.0d0) - &\n (13860.0d0)*(s**6.0d0)\n else if (k == 6) then\n phi = (210.0d0) - &\n (7140.0d0)*s + &\n (55440.0d0)*(s**2.0d0) - &\n (161280.0d0)*(s**3.0d0) + &\n (195300.0d0)*(s**4.0d0) - &\n (83160.0d0)*(s**5.0d0)\n end if\n else if (j == 11) then\n if (k == 0) then\n phi = -(1.0d0/120.0d0)*(s**6.0d0) + &\n (1.0d0/24.0d0)*(s**7.0d0) - &\n (1.0d0/12.0d0)*(s**8.0d0) + &\n (1.0d0/12.0d0)*(s**9.0d0) - &\n (1.0d0/24.0d0)*(s**10.0d0) + &\n (1.0d0/120.0d0)*(s**11.0d0)\n else if (k == 1) then\n phi = -(1.0d0/20.0d0)*(s**5.0d0) + &\n (7.0d0/24.0d0)*(s**6.0d0) - &\n (2.0d0/3.0d0)*(s**7.0d0) + &\n (3.0d0/4.0d0)*(s**8.0d0) - &\n (5.0d0/12.0d0)*(s**9.0d0) + &\n (11.0d0/120.0d0)*(s**10.0d0)\n else if (k == 2) then\n phi = -(1.0d0/4.0d0)*(s**4.0d0) + &\n (7.0d0/4.0d0)*(s**5.0d0) - &\n (14.0d0/3.0d0)*(s**6.0d0) + &\n (6.0d0)*(s**7.0d0) - &\n (15.0d0/4.0d0)*(s**8.0d0) + &\n (11.0d0/12.0d0)*(s**9.0d0)\n else if (k == 3) then\n phi = -(s**3.0d0) + &\n (35.0d0/4.0d0)*(s**4.0d0) - &\n (28.0d0)*(s**5.0d0) + &\n (42.0d0)*(s**6.0d0) - &\n (30.0d0)*(s**7.0d0) + &\n (33.0d0/4.0d0)*(s**8.0d0)\n else if (k == 4) then\n phi = -(3.0d0)*(s**2.0d0) + &\n (35.0d0)*(s**3.0d0) - &\n (140.0d0)*(s**4.0d0) + &\n (252.0d0)*(s**5.0d0) - &\n (210.0d0)*(s**6.0d0) + &\n (66.0d0)*(s**7.0d0)\n else if (k == 5) then\n phi = -(6.0d0)*s + &\n (105.0d0)*(s**2.0d0) - &\n (560.0d0)*(s**3.0d0) + &\n (1260.0d0)*(s**4.0d0) - &\n (1260.0d0)*(s**5.0d0) + &\n (462.0d0)*(s**6.0d0)\n else if (k == 6) then\n phi = -(6.0d0) + &\n (210.0d0)*s - &\n (1680.0d0)*(s**2.0d0) + &\n (5040.0d0)*(s**3.0d0) - &\n (6300.0d0)*(s**4.0d0) + &\n (2772.0d0)*(s**5.0d0)\n end if\n end if\n\n\n END SUBROUTINE shape_function\n\n SUBROUTINE derivatives(neq,i,x,y,yprime,u,ux,uxx,uxxx,&\n uxxxx,uxxxxx,uxxxxxx,utau,rpar)\n ! return value of u and its spatio-termporal derivatives\n ! at a point x_i < x < x_i+1\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: i, neq, x\n REAL(kind=8), DIMENSION(neq), INTENT(IN) :: y, yprime\n REAL(kind=8), INTENT(OUT) :: u, ux, uxx, uxxx, uxxxx,&\n uxxxxx, uxxxxxx, utau\n REAL(kind=8), DIMENSION(4+7*12*13), INTENT(IN) :: rpar\n REAL(kind=8), PARAMETER :: sone = 0.03376524289842475d0,&\n stwo = 0.16939530676686765d0,&\n sthree = 0.3806904069584014d0,&\n sfour = 0.6193095930415986d0,&\n sfive = 0.8306046932331324d0,&\n ssix = 0.9662347571015759d0,&\n pone = 0.0d0, ptwo = 0.0848880518607158d0,&\n pthree = 0.265575603264643d0, pfour = 0.5d0,&\n pfive = 0.7344243967353573d0,&\n psix = 0.9151119481392833d0, pseven = 1.0d0\n REAL(kind=8), DIMENSION(13), PARAMETER :: points = &\n [sone, stwo, sthree, sfour, sfive, ssix, pone, ptwo, &\n pthree, pfour, pfive, psix, pseven]\n REAL(kind=8) :: h, htau\n\n h = y(7*(i+1)) - y(7*i)\n htau = yprime(7*(i+1)) - yprime(7*i)\n\n ! rpar set up so that rpar(4+1) = phi(0,0,sone), rpar(4+14) = \n ! phi(0,1,sone), rpar(4+92) = phi(1,0,sone). Use x now to contain\n ! an integer where 1 to 6 correspond to s's and 7 to 13 \n ! correspond to p's\n\n u = y(7*(i-1)+1)*rpar(4+x) + &\n y(7*(i-1)+2)*rpar(4+91+x)*h +&\n y(7*(i-1)+3)*rpar(4+2*91+x)*(h**2.0d0) +&\n y(7*(i-1)+4)*rpar(4+3*91+x)*(h**3.0d0) +&\n y(7*(i-1)+5)*rpar(4+4*91+x)*(h**4.0d0) +&\n y(7*(i-1)+6)*rpar(4+5*91+x)*(h**5.0d0) +&\n y(7*i+1)*rpar(4+6*91+x) + &\n y(7*i+2)*rpar(4+7*91+x)*h +&\n y(7*i+3)*rpar(4+8*91+x)*(h**2.0d0) +&\n y(7*i+4)*rpar(4+9*91+x)*(h**3.0d0) +&\n y(7*i+5)*rpar(4+10*91+x)*(h**4.0d0) +&\n y(7*i+6)*rpar(4+11*91+x)*(h**5.0d0)\n\n ux = (y(7*(i-1)+1)*rpar(4+13+x) + &\n y(7*(i-1)+2)*rpar(4+91+13+x)*h +&\n y(7*(i-1)+3)*rpar(4+2*91+13+x)*(h**2.0d0) +&\n y(7*(i-1)+4)*rpar(4+3*91+13+x)*(h**3.0d0) +&\n y(7*(i-1)+5)*rpar(4+4*91+13+x)*(h**4.0d0) +&\n y(7*(i-1)+6)*rpar(4+5*91+13+x)*(h**5.0d0) +&\n y(7*i+1)*rpar(4+6*91+13+x) + &\n y(7*i+2)*rpar(4+7*91+13+x)*h +&\n y(7*i+3)*rpar(4+8*91+13+x)*(h**2.0d0) +&\n y(7*i+4)*rpar(4+9*91+13+x)*(h**3.0d0) +&\n y(7*i+5)*rpar(4+10*91+13+x)*(h**4.0d0) +&\n y(7*i+6)*rpar(4+11*91+13+x)*(h**5.0d0))/h\n\n uxx = (y(7*(i-1)+1)*rpar(4+2*13+x) + &\n y(7*(i-1)+2)*rpar(4+91+2*13+x)*h +&\n y(7*(i-1)+3)*rpar(4+2*91+2*13+x)*(h**2.0d0) +&\n y(7*(i-1)+4)*rpar(4+3*91+2*13+x)*(h**3.0d0) +&\n y(7*(i-1)+5)*rpar(4+4*91+2*13+x)*(h**4.0d0) +&\n y(7*(i-1)+6)*rpar(4+5*91+2*13+x)*(h**5.0d0) +&\n y(7*i+1)*rpar(4+6*91+2*13+x) + &\n y(7*i+2)*rpar(4+7*91+2*13+x)*h +&\n y(7*i+3)*rpar(4+8*91+2*13+x)*(h**2.0d0) +&\n y(7*i+4)*rpar(4+9*91+2*13+x)*(h**3.0d0) +&\n y(7*i+5)*rpar(4+10*91+2*13+x)*(h**4.0d0) +&\n y(7*i+6)*rpar(4+11*91+2*13+x)*(h**5.0d0))/(h**2.0d0)\n\n uxxx = (y(7*(i-1)+1)*rpar(4+3*13+x) + &\n y(7*(i-1)+2)*rpar(4+91+3*13+x)*h +&\n y(7*(i-1)+3)*rpar(4+2*91+3*13+x)*(h**2.0d0) +&\n y(7*(i-1)+4)*rpar(4+3*91+3*13+x)*(h**3.0d0) +&\n y(7*(i-1)+5)*rpar(4+4*91+3*13+x)*(h**4.0d0) +&\n y(7*(i-1)+6)*rpar(4+5*91+3*13+x)*(h**5.0d0) +&\n y(7*i+1)*rpar(4+6*91+3*13+x) + &\n y(7*i+2)*rpar(4+7*91+3*13+x)*h +&\n y(7*i+3)*rpar(4+8*91+3*13+x)*(h**2.0d0) +&\n y(7*i+4)*rpar(4+9*91+3*13+x)*(h**3.0d0) +&\n y(7*i+5)*rpar(4+10*91+3*13+x)*(h**4.0d0) +&\n y(7*i+6)*rpar(4+11*91+3*13+x)*(h**5.0d0))/(h**3.0d0) \n\n uxxxx = (y(7*(i-1)+1)*rpar(4+4*13+x) + &\n y(7*(i-1)+2)*rpar(4+91+4*13+x)*h +&\n y(7*(i-1)+3)*rpar(4+2*91+4*13+x)*(h**2.0d0) +&\n y(7*(i-1)+4)*rpar(4+3*91+4*13+x)*(h**3.0d0) +&\n y(7*(i-1)+5)*rpar(4+4*91+4*13+x)*(h**4.0d0) +&\n y(7*(i-1)+6)*rpar(4+5*91+4*13+x)*(h**5.0d0) +&\n y(7*i+1)*rpar(4+6*91+4*13+x) + &\n y(7*i+2)*rpar(4+7*91+4*13+x)*h +&\n y(7*i+3)*rpar(4+8*91+4*13+x)*(h**2.0d0) +&\n y(7*i+4)*rpar(4+9*91+4*13+x)*(h**3.0d0) +&\n y(7*i+5)*rpar(4+10*91+4*13+x)*(h**4.0d0) +&\n y(7*i+6)*rpar(4+11*91+4*13+x)*(h**5.0d0))/(h**4.0d0)\n\n uxxxxx = (y(7*(i-1)+1)*rpar(4+5*13+x) + &\n y(7*(i-1)+2)*rpar(4+91+5*13+x)*h +&\n y(7*(i-1)+3)*rpar(4+2*91+5*13+x)*(h**2.0d0) +&\n y(7*(i-1)+4)*rpar(4+3*91+5*13+x)*(h**3.0d0) +&\n y(7*(i-1)+5)*rpar(4+4*91+5*13+x)*(h**4.0d0) +&\n y(7*(i-1)+6)*rpar(4+5*91+5*13+x)*(h**5.0d0) +&\n y(7*i+1)*rpar(4+6*91+5*13+x) + &\n y(7*i+2)*rpar(4+7*91+5*13+x)*h +&\n y(7*i+3)*rpar(4+8*91+5*13+x)*(h**2.0d0) +&\n y(7*i+4)*rpar(4+9*91+5*13+x)*(h**3.0d0) +&\n y(7*i+5)*rpar(4+10*91+5*13+x)*(h**4.0d0) +&\n y(7*i+6)*rpar(4+11*91+5*13+x)*(h**5.0d0))/(h**5.0d0)\n\n uxxxxxx = (y(7*(i-1)+1)*rpar(4+6*13+x) + &\n y(7*(i-1)+2)*rpar(4+91+6*13+x)*h +&\n y(7*(i-1)+3)*rpar(4+2*91+6*13+x)*(h**2.0d0) +&\n y(7*(i-1)+4)*rpar(4+3*91+6*13+x)*(h**3.0d0) +&\n y(7*(i-1)+5)*rpar(4+4*91+6*13+x)*(h**4.0d0) +&\n y(7*(i-1)+6)*rpar(4+5*91+6*13+x)*(h**5.0d0) +&\n y(7*i+1)*rpar(4+6*91+6*13+x) + &\n y(7*i+2)*rpar(4+7*91+6*13+x)*h +&\n y(7*i+3)*rpar(4+8*91+6*13+x)*(h**2.0d0) +&\n y(7*i+4)*rpar(4+9*91+6*13+x)*(h**3.0d0) +&\n y(7*i+5)*rpar(4+10*91+6*13+x)*(h**4.0d0) +&\n y(7*i+6)*rpar(4+11*91+6*13+x)*(h**5.0d0))/(h**6.0d0)\n\n utau = yprime(7*(i-1)+1)*rpar(4+x) + &\n (yprime(7*(i-1)+2)*h)*rpar(4+91+x) + &\n (yprime(7*(i-1)+3)*(h**2.0d0))*rpar(4+2*91+x) + &\n (yprime(7*(i-1)+4)*(h**3.0d0))*rpar(4+3*91+x) +&\n (yprime(7*(i-1)+5)*(h**4.0d0))*rpar(4+4*91+x) +&\n (yprime(7*(i-1)+6)*(h**5.0d0))*rpar(4+5*91+x) +&\n yprime(7*i+1)*rpar(4+6*91+x) + &\n (yprime(7*i+2)*h)*rpar(4+7*91+x) +&\n (yprime(7*i+3)*(h**2.0d0))*rpar(4+8*91+x) +&\n (yprime(7*i+4)*(h**3.0d0))*rpar(4+9*91+x) +&\n (yprime(7*i+5)*(h**4.0d0))*rpar(4+10*91+x) +&\n (yprime(7*i+6)*(h**5.0d0))*rpar(4+11*91+x) -&\n ux*(yprime(7*i)+points(x)*htau)\n\n END SUBROUTINE derivatives\n\n SUBROUTINE residual_pde(neq,tau,y,yprime,delta,ires,rpar,ipar)\n ! Fill the entries of the residual corresponding to the solution and\n ! its derivatives with the collocation equation (non conservative)\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: neq\n INTEGER :: npts, ii, jj, kk, ll, timetrans, cons, x\n REAL(kind=8) :: u, ux, uxx, uxxx, uxxxx, uxxxxx, uxxxxxx, &\n utau, vx, xtau, p, g\n INTEGER, INTENT(INOUT) :: ires\n INTEGER, DIMENSION(*), INTENT(IN) :: ipar\n REAL(kind=8) :: h, htau, sund, big\n REAL(kind=8), INTENT(IN) :: tau\n REAL(kind=8), DIMENSION(neq), INTENT(IN) :: y, yprime\n REAL(kind=8), DIMENSION(4+7*12*13), INTENT(IN) :: rpar\n REAL(kind=8), DIMENSION(neq), INTENT(INOUT) :: delta\n REAL(kind=8), DIMENSION(:), ALLOCATABLE :: fmntr, fsmooth, prmtr\n REAL(kind=8), PARAMETER :: sone = 0.03376524289842475d0,&\n stwo = 0.16939530676686765d0,&\n sthree = 0.3806904069584014d0,&\n sfour = 0.6193095930415986d0,&\n sfive = 0.8306046932331324d0,&\n ssix = 0.9662347571015759d0\n REAL(kind=8), DIMENSION(6), PARAMETER :: points = &\n [sone, stwo, sthree, sfour, sfive, ssix]\n\n timetrans = ipar(6)\n cons = ipar(7)\n npts = ipar(4)\n p = rpar(1)\n\n ALLOCATE (fmntr(neq),fsmooth(neq),prmtr(neq))\n call monitor(neq,y,yprime,fmntr,prmtr,rpar,ipar)\n big = 0.0d0\n do kk = 1,npts\n if (fmntr(7*kk) > big) then\n big = fmntr(7*kk)\n end if\n end do\n if (timetrans==1) then\n sund = 1.0d0/big\n elseif (timetrans==0) then\n sund = 1.0d0\n end if\n if (cons == 0) then\n do ii = 1,npts-1\n h = y(7*(ii+1))-y(7*ii)\n htau = yprime(7*(ii+1)) - yprime(7*ii)\n do jj = 1,6\n call derivatives(neq,ii,jj,y,yprime,u,ux,&\n uxx,uxxx,uxxxx,uxxxxx,uxxxxxx,utau,rpar)\n call def_pde(g,u,ux,uxx,uxxx,uxxxx,uxxxxx,&\n uxxxxxx,rpar,ipar)\n! one of these plus the two following lines should be uncommented \n! to attempt to stabilize the problem\n ! call upwinder(neq,ii,jj,y,yprime,u,vx,rpar)\n ! call lower_order(neq,ii,jj,y,yprime,vx)\n xtau = yprime(7*ii) + points(jj)*htau\n utau = utau + (ux - vx)*xtau\n if (jj < 4) then\n delta(7*(ii-1)+3+jj) = utau - sund*g\n else\n delta(7*ii+jj-3) = utau - sund*g\n end if\n end do\n end do\n else if (cons == 1) then\n do ii = 1,npts-1\n h = y(7*(ii+1))-y(7*ii)\n do jj = 1,6\n call derivatives(neq,ii,jj,y,yprime,u,ux,&\n uxx,uxxx,uxxxx,uxxxxx,uxxxxxx,utau,rpar)\n call def_pde(g,u,ux,uxx,uxxx,uxxxx,uxxxxx,&\n uxxxxxx,rpar,ipar)\n if (jj < 4) then\n delta(7*(ii-1)+3+jj) = h*utau/sund\n else\n delta(7*ii+jj-3) = h*utau/sund\n end if\n end do\n do ll = 1,7\n if (ll == 1) then\n x = 7\n call derivatives(neq,ii,x,y,yprime,u,ux,&\n uxx,uxxx,uxxxx,uxxxxx,uxxxxxx,utau,rpar)\n call def_pde(g,u,ux,uxx,uxxx,uxxxx,uxxxxx,&\n uxxxxxx,rpar,ipar)\n delta(7*(ii-1)+4) = delta(7*(ii-1)+4) +&\n 0.128882066524507657D2*g\n delta(7*(ii-1)+5) = delta(7*(ii-1)+5) -&\n 0.732825716500196678D0*g\n delta(7*(ii-1)+6) = delta(7*(ii-1)+6) + &\n 0.164922049039696650D0*g\n delta(7*ii+1) = delta(7*ii+1) - &\n 0.623170625543232604D-1*g\n delta(7*ii+2) = delta(7*ii+2) + &\n 0.304799806699240471D-1*g\n delta(7*ii+3) = delta(7*ii+3) - &\n 0.157386303787899057D-1*g\n else if (ll == 2) then\n x = 8\n call derivatives(neq,ii,x,y,yprime,u,ux,&\n uxx,uxxx,uxxxx,uxxxxx,uxxxxxx,utau,rpar)\n call def_pde(g,u,ux,uxx,uxxx,uxxxx,uxxxxx,&\n uxxxxxx,rpar,ipar)\n delta(7*(ii-1)+4) = delta(7*(ii-1)+4) -&\n 0.135555128881389990D2*g\n delta(7*(ii-1)+5) = delta(7*(ii-1)+5) +&\n 0.709951339386726676D1*g\n delta(7*(ii-1)+6) = delta(7*(ii-1)+6) - &\n 0.658616272480538112D0*g\n delta(7*ii+1) = delta(7*ii+1) + &\n 0.201775206853726796D0*g\n delta(7*ii+2) = delta(7*ii+2) - &\n 0.911735577624964294D-1*g\n delta(7*ii+3) = delta(7*ii+3) + &\n 0.456091312690583006D-1*g\n else if (ll == 3) then\n x = 9\n call derivatives(neq,ii,x,y,yprime,u,ux,&\n uxx,uxxx,uxxxx,uxxxxx,uxxxxxx,utau,rpar)\n call def_pde(g,u,ux,uxx,uxxx,uxxxx,uxxxxx,&\n uxxxxxx,rpar,ipar)\n delta(7*(ii-1)+4) = delta(7*(ii-1)+4) +&\n 0.823360561753947895D0*g\n delta(7*(ii-1)+5) = delta(7*(ii-1)+5) -&\n 0.684470480798240999D1*g\n delta(7*(ii-1)+6) = delta(7*(ii-1)+6) + &\n 0.543104912697367581D1*g\n delta(7*ii+1) = delta(7*ii+1) - &\n 0.575165066473151465D0*g\n delta(7*ii+2) = delta(7*ii+2) + &\n 0.198328593004358011D0*g\n delta(7*ii+3) = delta(7*ii+3) - &\n 0.901243497969793084D-1*g\n else if (ll == 4) then\n x = 10\n call derivatives(neq,ii,x,y,yprime,u,ux,&\n uxx,uxxx,uxxxx,uxxxxx,uxxxxxx,utau,rpar)\n call def_pde(g,u,ux,uxx,uxxx,uxxxx,uxxxxx,&\n uxxxxxx,rpar,ipar)\n delta(7*(ii-1)+4) = delta(7*(ii-1)+4) - &\n 0.216308174972419803D0*g\n delta(7*(ii-1)+5) = delta(7*(ii-1)+5) + &\n 0.615652146527092881D0*g\n delta(7*(ii-1)+6) = delta(7*(ii-1)+6) - &\n 0.537306182570658031D1*g\n delta(7*ii+1) = delta(7*ii+1) + &\n 0.537306182570662916D1*g\n delta(7*ii+2) = delta(7*ii+2) - &\n 0.615652146527116750D0*g\n delta(7*ii+3) = delta(7*ii+3) + &\n 0.216308174972481171D0*g\n else if (ll == 5) then\n x = 11\n call derivatives(neq,ii,x,y,yprime,u,ux,&\n uxx,uxxx,uxxxx,uxxxxx,uxxxxxx,utau,rpar)\n call def_pde(g,u,ux,uxx,uxxx,uxxxx,uxxxxx,&\n uxxxxxx,rpar,ipar)\n delta(7*(ii-1)+4) = delta(7*(ii-1)+4) + &\n 0.901243497969332896D-1*g\n delta(7*(ii-1)+5) = delta(7*(ii-1)+5) - &\n 0.198328593004349574D0*g\n delta(7*(ii-1)+6) = delta(7*(ii-1)+6) + &\n 0.575165066473167785D0*g\n delta(7*ii+1) = delta(7*ii+1) - &\n 0.543104912697373088D1*g\n delta(7*ii+2) = delta(7*ii+2) + &\n 0.684470480798244640D1*g\n delta(7*ii+3) = delta(7*ii+3) - &\n 0.823360561754134634D0*g\n else if (ll == 6) then\n x = 12\n call derivatives(neq,ii,x,y,yprime,u,ux,&\n uxx,uxxx,uxxxx,uxxxxx,uxxxxxx,utau,rpar)\n call def_pde(g,u,ux,uxx,uxxx,uxxxx,uxxxxx,&\n uxxxxxx,rpar,ipar)\n delta(7*(ii-1)+4) = delta(7*(ii-1)+4) - &\n 0.456091312689924505D-1*g\n delta(7*(ii-1)+5) = delta(7*(ii-1)+5) + &\n 0.911735577625287091D-1*g\n delta(7*(ii-1)+6) = delta(7*(ii-1)+6) - &\n 0.201775206853745059D0*g\n delta(7*ii+1) = delta(7*ii+1) + &\n 0.658616272480554432D0*g\n delta(7*ii+2) = delta(7*ii+2) - &\n 0.709951339386726943D1*g\n delta(7*ii+3) = delta(7*ii+3) + &\n 0.135555128881391269D2*g\n else if (ll == 7) then\n x = 13\n call derivatives(neq,ii,x,y,yprime,u,ux,&\n uxx,uxxx,uxxxx,uxxxxx,uxxxxxx,utau,rpar)\n call def_pde(g,u,ux,uxx,uxxx,uxxxx,uxxxxx,&\n uxxxxxx,rpar,ipar)\n delta(7*(ii-1)+4) = delta(7*(ii-1)+4) + &\n 0.157386303787635622D-1*g\n delta(7*(ii-1)+5) = delta(7*(ii-1)+5) - &\n 0.304799806699315723D-1*g\n delta(7*(ii-1)+6) = delta(7*(ii-1)+6) + &\n 0.623170625543236212D-1*g\n delta(7*ii+1) = delta(7*ii+1) - &\n 0.164922049039704727D0*g\n delta(7*ii+2) = delta(7*ii+2) + &\n 0.732825716500154489D0*g\n delta(7*ii+3) = delta(7*ii+3) - &\n 0.128882066524507621D2*g\n end if\n end do\n end do\n end if\n ! Left Boundary Conditions\n x = 7\n call derivatives(neq,1,x,y,yprime,u,ux,uxx,uxxx,uxxxx,uxxxxx,&\n uxxxxxx,utau,rpar)\n delta(1) = ux\n delta(2) = uxxx\n delta(3) = uxxxxx\n\n ! Right Boundary Conditions\n x = 13 \n call derivatives(neq,npts-1,x,y,yprime,u,ux,uxx,uxxx,uxxxx,&\n uxxxxx,uxxxxxx,utau,rpar)\n delta(7*npts-3) = ux\n delta(7*npts-2) = uxxx\n delta(7*npts-1) = uxxxxx\n ! last entry contains ode for time transformation dt/dtau = g(u)\n delta(neq) = yprime(neq) - sund\n DEALLOCATE(fmntr)\n END SUBROUTINE residual_pde\n\n SUBROUTINE residual_mesheq(neq,tau,y,yprime,delta,ires,rpar,ipar)\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: neq\n INTEGER :: npts, j, kk, timetrans\n REAL(kind=8) :: epsilon, h, sund, big, p\n INTEGER, INTENT(INOUT) :: ires\n INTEGER, DIMENSION(*), INTENT(IN) :: ipar\n REAL(kind=8), INTENT(IN) :: tau\n REAL(kind=8), DIMENSION(neq), INTENT(IN) :: y, yprime\n REAL(kind=8), DIMENSION(4+7*12*13), INTENT(IN) :: rpar\n REAL(kind=8), DIMENSION(neq), INTENT(INOUT) :: delta\n REAL(kind=8), DIMENSION(:), ALLOCATABLE :: fmntr, fsmooth, prmtr\n npts = ipar(4)\n h = rpar(2)\n p = rpar(1)\n epsilon = 1.0d-3\n ALLOCATE (fmntr(neq),fsmooth(neq),prmtr(neq))\n call monitor(neq,y,yprime,fmntr,prmtr,rpar,ipar)\n call smooth_monitor(neq,fmntr,fsmooth,rpar,ipar)\n big = 0.0d0\n do kk = 1,npts\n if (fmntr(7*kk) > big) then\n big = fmntr(7*kk)\n end if\n end do\n if (timetrans==1) then\n sund = 1.0d0/big\n elseif (timetrans==0) then\n sund = 1.0d0\n end if\n ! Fix left mesh point location by setting RHS of MEQ to zero\n delta(7) = yprime(7)/(h**2.0d0)\n do j = 2,npts-1\n delta(7*j) = (yprime(7*(j-1)) - 2.0d0*yprime(7*j) + &\n yprime(7*(j+1)))/(h**2.0d0) + &\n sund*((((fsmooth(7*(j+1)) + &\n fsmooth(7*j))*(y(7*(j+1)) - y(7*j))) - &\n (((fsmooth(7*j) + &\n fsmooth(7*(j-1)))*(y(7*j) - &\n y(7*(j-1))))))/(epsilon*(h**2.0d0)))\n end do\n ! Likewise right mesh point\n delta(7*npts) = yprime(7*npts)/(h**2.0d0)\n DEALLOCATE(fmntr,fsmooth,prmtr)\n END SUBROUTINE residual_mesheq\n\n SUBROUTINE monitor(neq,y,yprime,fmntr,prmtr,rpar,ipar)\n ! Calculates Monitor Function evaluated at mesh points (might be\n ! advantageous in future to figure out how to take weighted average\n ! over Gauss points)\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: neq\n INTEGER :: npts, i, j, k, job, x\n REAL(kind=8) :: u, ux, uxx, uxxx, uxxxx, uxxxxx, uxxxxxx,&\n utau, p, add, weight, h, M, dummy, monalpha\n REAL(kind=8), PARAMETER :: wone = 0.08566224618958468d0,&\n wtwo = 0.18038078652407022d0,&\n wthree = 0.2339569672863451d0,&\n wfour = 0.23395696728634524d0,&\n wfive = 0.1803807865240697d0,&\n wsix = 0.08566224618958512d0\n INTEGER, DIMENSION(*), INTENT(IN) :: ipar\n REAL(kind=8), DIMENSION(neq), INTENT(IN) :: y, yprime\n REAL(kind=8), DIMENSION(4+7*12*13), INTENT(IN) :: rpar\n REAL(kind=8), DIMENSION(neq), INTENT(INOUT) :: fmntr, prmtr\n npts = ipar(4)\n p = rpar(1)\n monalpha = rpar(1097)\n add = 0.0d0\n dummy = 0.0d0\n do i = 1,npts-1\n h = y(7*(i+1)) - y(7*i)\n fmntr(7*i) = 0.0d0\n do j = 1,6\n if (j == 1) then\n x = 1\n weight = wone\n call derivatives(neq,i,x,y,yprime,u,ux,&\n uxx,uxxx,uxxxx,uxxxxx,uxxxxxx,utau,rpar)\n call def_monitor(M,dummy,u,ux,uxx,rpar,ipar)\n fmntr(7*i) = fmntr(7*i) + (1.0d0/6.0d0)*M\n add = add + h*weight*M\n else if (j == 2) then\n x = 2\n weight = wtwo\n call derivatives(neq,i,x,y,yprime,u,ux,&\n uxx,uxxx,uxxxx,uxxxxx,uxxxxxx,utau,rpar)\n call def_monitor(M,dummy,u,ux,uxx,rpar,ipar)\n fmntr(7*i) = fmntr(7*i) + (1.0d0/6.0d0)*M\n add = add + h*weight*M\n else if (j == 3) then\n x = 3\n weight = wthree\n call derivatives(neq,i,x,y,yprime,u,ux,&\n uxx,uxxx,uxxxx,uxxxxx,uxxxxxx,utau,rpar)\n call def_monitor(M,dummy,u,ux,uxx,rpar,ipar)\n fmntr(7*i) = fmntr(7*i) + (1.0d0/6.0d0)*M\n add = add + h*weight*M\n else if (j == 4) then\n x = 4\n weight = wfour\n call derivatives(neq,i,x,y,yprime,u,ux,&\n uxx,uxxx,uxxxx,uxxxxx,uxxxxxx,utau,rpar)\n call def_monitor(M,dummy,u,ux,uxx,rpar,ipar)\n fmntr(7*i) = fmntr(7*i) + (1.0d0/6.0d0)*M\n add = add + h*weight*M\n else if (j == 5) then\n x = 5\n weight = wfive\n call derivatives(neq,i,x,y,yprime,u,ux,&\n uxx,uxxx,uxxxx,uxxxxx,uxxxxxx,utau,rpar)\n call def_monitor(M,dummy,u,ux,uxx,rpar,ipar)\n fmntr(7*i) = fmntr(7*i) + (1.0d0/6.0d0)*M\n add = add + h*weight*M\n else if (j == 6) then\n x = 6\n weight = wsix\n call derivatives(neq,i,x,y,yprime,u,ux,&\n uxx,uxxx,uxxxx,uxxxxx,uxxxxxx,utau,rpar)\n call def_monitor(M,dummy,u,ux,uxx,rpar,ipar)\n fmntr(7*i) = fmntr(7*i) + (1.0d0/6.0d0)*M\n add = add + h*weight*M\n end if\n end do\n end do\n fmntr(7*npts) = fmntr(7*(npts-1))\n prmtr = fmntr\n do k = 1,npts\n fmntr(7*k) = fmntr(7*k) + monalpha*add\n end do\n END SUBROUTINE monitor\n\n SUBROUTINE smooth_monitor(neq,fmntr,fsmooth,rpar,ipar)\n ! smooths the monitor function to reduce stiffness\n IMPLICIT NONE\n INTEGER :: npts, j, l, p\n INTEGER, INTENT(IN) :: neq\n INTEGER, DIMENSION(7) :: ipar\n REAL(kind=8) :: gamma, qgamma, divisor\n REAL(kind=8), DIMENSION(4) :: rpar\n REAL(kind=8), DIMENSION(*) :: fsmooth, fmntr\n npts = ipar(4)\n ! smoothing parameter\n gamma = 3.0d0\n qgamma = gamma/(1.0d0+gamma)\n ! smoothing index (currently only 1 and 2 are supported)\n p = 1\n do j = p,npts-p\n fsmooth(7*j) = 0.0d0\n divisor = 0.0d0\n do l = -p,p\n fsmooth(7*j) = fsmooth(7*j) + (fmntr(7*(j+l))**2.0d0)*(qgamma**(dble(abs(l))))\n divisor = divisor + (qgamma**(dble(abs(l))))\n end do\n fsmooth(7*j) = sqrt(fsmooth(7*j)/divisor)\n end do\n fsmooth(7) = sqrt(fmntr(7)**2.0d0 + fmntr(14)**2.0d0)\n fsmooth(7*npts) = sqrt(fmntr(7*(npts-1))**2.0d0 + &\n fmntr(7*npts)**2.0d0) \n if (p == 2) then\n fsmooth(14) = sqrt(((fmntr(7)**2.0d0)*qgamma + &\n (fmntr(14)**2.0d0) + &\n (fmntr(21)**2.0d0/qgamma))/(2.0d0*qgamma)) \n fsmooth(7*(npts-1)) = sqrt(((fmntr(7*(npts-2))**2.0d0)*qgamma + (fmntr(7*(npts-1))**2.0d0) + &\n (fmntr(7*npts))**2.0d0/qgamma)/(2.0d0*qgamma))\n end if\n END SUBROUTINE smooth_monitor\n\n SUBROUTINE def_ic(x,u0)\n IMPLICIT NONE\n REAL(kind=8), INTENT(IN) :: x\n REAL(kind=8), INTENT(OUT) :: u0\n REAL(kind=8), PARAMETER :: pi = 4.0d0*datan(1.0d0)\n\n u0 = (8.0d0/(dsqrt(2.0d0*pi)))*dexp(-x**2.0/2.0)\n END SUBROUTINE def_ic\n\n SUBROUTINE def_pde(g,u,ux,uxx,uxxx,uxxxx,uxxxxx,uxxxxxx,rpar,ipar)\n IMPLICIT NONE\n REAL(kind=8), INTENT(OUT) :: g\n REAL(kind=8), INTENT(IN) :: u, ux, uxx, uxxx, uxxxx, uxxxxx, uxxxxxx\n INTEGER, DIMENSION(*), INTENT(IN) :: ipar\n REAL(kind=8), DIMENSION(*), INTENT(IN) :: rpar\n REAL(kind=8) :: p, delta\n INTEGER :: cons\n\n p = rpar(1)\n delta = 1.0d-3 ! Regularizing parameter\n cons = ipar(7)\n\n if (cons == 0) then\n g = ux*uxxxxx + u*uxxxxxx - 30*(u**4.0d0)*(ux**2.0d0) - 6*(u**5.0d0)*uxx\n elseif (cons == 1) then\n g = u*uxxxxx - 6.0d0*(u**5.0d0)*ux\n endif\n END SUBROUTINE def_pde\n\n SUBROUTINE def_monitor(M,x,u,ux,uxx,rpar,ipar)\n IMPLICIT NONE\n REAL(kind=8), INTENT(OUT) :: M\n REAL(kind=8), INTENT(IN) :: x, u, ux, uxx\n INTEGER, DIMENSION(*), INTENT(IN) :: ipar\n REAL(kind=8), DIMENSION(*), INTENT(IN) :: rpar\n REAL(kind=8) :: p, nu, delta\n\n p = rpar(1)\n M = u**7.0d0 + abs((x**2.0d0)*uxx)**7.0d0\n END SUBROUTINE def_monitor\n\n\n SUBROUTINE solution_output(neq,y,yprime,rpar,ipar,mesh,soln)\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: neq\n INTEGER, DIMENSION(*), INTENT(IN) :: ipar\n INTEGER :: i, j, npts, x\n REAL(kind=8), DIMENSION(neq), INTENT(IN) :: y, yprime\n REAL(kind=8), DIMENSION(4+7*12*13), INTENT(IN) :: rpar\n REAL(kind=8), DIMENSION(neq-6), INTENT(OUT) :: mesh,&\n soln\n REAL(kind=8) :: u, ux, uxx, uxxx, uxxxx, uxxxxx,&\n uxxxxxx, utau, h, coord\n REAL(kind=8), PARAMETER :: sone = 0.03376524289842475d0,&\n stwo = 0.16939530676686765d0,&\n sthree = 0.3806904069584014d0,&\n sfour = 0.6193095930415986d0,&\n sfive = 0.8306046932331324d0,&\n ssix = 0.9662347571015759d0\n\n npts = ipar(4)\n do i = 1, npts-1\n h = y(7*(i+1)) - y(7*i)\n mesh(7*i-6) = y(7*i)\n soln(7*i-6) = y(7*i-6)\n do j = 1,6\n if (j == 1) then\n x = 1\n coord = y(7*i) + sone*h\n mesh(7*i-5) = coord\n call derivatives(neq,i,x,y,yprime,u,ux,uxx,uxxx,&\n uxxxx,uxxxxx,uxxxxxx,utau,rpar)\n soln(7*i-5) = u\n else if (j == 2) then\n x = 2\n coord = y(7*i) + stwo*h\n mesh(7*i-4) = coord\n call derivatives(neq,i,x,y,yprime,u,ux,uxx,uxxx,&\n uxxxx,uxxxxx,uxxxxxx,utau,rpar)\n soln(7*i-4) = u\n else if (j == 3) then\n x = 3\n coord = y(7*i) + sthree*h\n mesh(7*i-3) = coord\n call derivatives(neq,i,x,y,yprime,u,ux,uxx,uxxx,&\n uxxxx,uxxxxx,uxxxxxx,utau,rpar)\n soln(7*i-3) = u\n else if (j == 4) then\n x = 4\n coord = y(7*i) + sfour*h\n mesh(7*i-2) = coord\n call derivatives(neq,i,x,y,yprime,u,ux,uxx,uxxx,&\n uxxxx,uxxxxx,uxxxxxx,utau,rpar)\n soln(7*i-2) = u\n else if (j == 5) then\n x = 5\n coord = y(7*i) + sfive*h\n mesh(7*i-1) = coord\n call derivatives(neq,i,x,y,yprime,u,ux,uxx,uxxx,&\n uxxxx,uxxxxx,uxxxxxx,utau,rpar)\n soln(7*i-1) = u\n else if (j == 6) then\n x = 6\n coord = y(7*i) + ssix*h\n mesh(7*i) = coord\n call derivatives(neq,i,x,y,yprime,u,ux,uxx,uxxx,&\n uxxxx,uxxxxx,uxxxxxx,utau,rpar)\n soln(7*i) = u\n end if\n end do\n end do\n\n mesh(neq-7) = y(7*npts)\n mesh(neq-6) = y(7*npts)\n soln(neq-7) = y(7*npts-6)\n soln(neq-6) = y(neq)\n END SUBROUTINE solution_output\n\n SUBROUTINE residual_ic(neq,tau,y,yprime,delta,ires,rpar,ipar)\n ! set up the dummy problem for generating an equidistributed mesh for \n ! the initial conditions defined in def_ic\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: neq\n INTEGER, INTENT(INOUT) :: ires\n INTEGER, DIMENSION(*), INTENT(IN) :: ipar\n INTEGER :: i, j, npts\n REAL(kind=8), INTENT(IN) :: tau\n REAL(kind=8), DIMENSION(*), INTENT(IN) :: rpar\n REAL(kind=8), DIMENSION(neq), INTENT(IN) :: y, yprime\n REAL(kind=8), DIMENSION(neq), INTENT(INOUT) :: delta\n REAL(kind=8) :: u0\n REAL(kind=8) :: u, ux, uxx, uxxx, uxxxx, uxxxxx, uxxxxxx, utau, x, h\n REAL(kind=8), PARAMETER :: sone = 0.03376524289842475d0,&\n stwo = 0.16939530676686765d0,&\n sthree = 0.3806904069584014d0,&\n sfour = 0.6193095930415986d0,&\n sfive = 0.8306046932331324d0,&\n ssix = 0.9662347571015759d0\n REAL(kind=8), DIMENSION(6), PARAMETER :: points = &\n [sone, stwo, sthree, sfour, sfive, ssix]\n\n npts = ipar(4)\n\n ! put dummy equation in relevant res entries\n do i = 1,npts-1\n h = y(7*(i+1))-y(7*i)\n do j = 1,6\n\n x = y(7*i) + points(j)*h\n call derivatives(neq,i,j,y,yprime,u,ux,uxx,uxxx,uxxxx,uxxxxx,uxxxxxx,utau,rpar)\n call def_ic(x,u0)\n delta(7*i+j-4+floor((dble(j-1))/3.0d0)) = utau-u0\n\n end do\n end do\n\n ! Fill in the two gaps on the left\n x = y(7)\n call derivatives(neq,1,7,y,yprime,u,ux,uxx,uxxx,uxxxx,uxxxxx,uxxxxxx,utau,rpar)\n call def_ic(x,u0)\n delta(1) = ux\n delta(2) = uxxx\n delta(3) = uxxxxx\n\n ! And the right\n x = y(7*npts)\n call derivatives(neq,npts-1,13,y,yprime,u,ux,uxx,uxxx,uxxxx,uxxxxx,uxxxxxx,utau,rpar)\n call def_ic(x,u0)\n delta(7*(npts-1)+4) = ux\n delta(7*(npts-1)+5) = uxxx\n delta(7*(npts-1)+6) = uxxxxx\n\n ! no time transformation in last entry\n delta(neq) = yprime(neq) - 1.0d0\n END SUBROUTINE residual_ic\n\nEND MODULE movmod\n", "meta": {"hexsha": "3f26380bc09abd4a9f1a6673c99e4cbd8eb115b3", "size": 53075, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "movmod.f90", "max_stars_repo_name": "BenedictBoyle/Movcol6", "max_stars_repo_head_hexsha": "8cb45cca16b197a2ff4563680a42be7ce9a1c8fd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-10-28T07:44:17.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-25T09:19:42.000Z", "max_issues_repo_path": "movmod.f90", "max_issues_repo_name": "BenedictBoyle/Movcol6", "max_issues_repo_head_hexsha": "8cb45cca16b197a2ff4563680a42be7ce9a1c8fd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "movmod.f90", "max_forks_repo_name": "BenedictBoyle/Movcol6", "max_forks_repo_head_hexsha": "8cb45cca16b197a2ff4563680a42be7ce9a1c8fd", "max_forks_repo_licenses": ["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.9112903226, "max_line_length": 101, "alphanum_fraction": 0.4205558172, "num_tokens": 22892, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9653811611608241, "lm_q2_score": 0.6791787056691698, "lm_q1q2_score": 0.6556663275146087}} {"text": "module arrCallback\ncontains\n elemental function cube( x )\n implicit none\n real :: cube\n real, intent(in) :: x\n cube = x * x * x\n end function cube\nend module arrCallback\n", "meta": {"hexsha": "77112c2b2b2f8699faec73b3fce79d4311548615", "size": 204, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Apply-a-callback-to-an-array/Fortran/apply-a-callback-to-an-array-1.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Apply-a-callback-to-an-array/Fortran/apply-a-callback-to-an-array-1.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Apply-a-callback-to-an-array/Fortran/apply-a-callback-to-an-array-1.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 20.4, "max_line_length": 32, "alphanum_fraction": 0.5980392157, "num_tokens": 50, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6556619396681481}} {"text": "PROGRAM LA_DSYEVR_ET_EXAMPLE\n!\n! -- LAPACK95 interface driver routine (version 3.0) --\n! UNI-C, Denmark; Univ. of Tennessee, USA; NAG Ltd., UK\n! September, 2000\n!\n! .. USE STATEMENTS\n USE LA_PRECISION, ONLY: WP => DP\n USE F95_LAPACK, ONLY: LA_SYEVR\n! .. IMPLICIT STATEMENT ..\n IMPLICIT NONE\n! .. PARAMETERS ..\n CHARACTER(LEN=*), PARAMETER :: FMT = '(8(1X,F10.3))'\n INTEGER, PARAMETER :: NIN=5, NOUT=6\n! .. LOCAL SCALARS ..\n INTEGER :: I, J, INFO, M, N\n CHARACTER(LEN = 1) :: UPLO\n REAL(WP) :: VL, VU\n INTEGER :: IL, IU\n! .. LOCAL ARRAYS ..\n REAL(WP), ALLOCATABLE :: AA(:,:), W(:)\n REAL(WP), ALLOCATABLE :: Z(:,:)\n REAL(WP), ALLOCATABLE :: A(:,:)\n INTEGER, ALLOCATABLE :: ISUPPZ(:)\n! .. EXECUTABLE STATEMENTS ..\n WRITE(NOUT,*) 'DSYEVR ET_Example Program Results.'\n READ(NIN,*) ! SKIP HEADING IN DATA FILE\n READ(NIN,*) N\n ALLOCATE ( A(N,N), AA(N,N), W(N) )\n ALLOCATE (Z(N,N), ISUPPZ(N))\n DO I = 1, N\n READ(NIN,*) (AA(I, J), J = 1, N)\n ENDDO\n A=AA\n WRITE(NOUT,*) 'The matrix A:'\n DO I = 1, N\n WRITE(NOUT,FMT) A(I,:)\n ENDDO\n!\n WRITE(NOUT,*) '---------------------------------------------------------'\n WRITE(NOUT,*)\n WRITE ( NOUT, * )'Details of LA_DSYEVR LAPACK Subroutine Results.'\n WRITE(NOUT,*)\n!\n WRITE(NOUT,*)\n WRITE(NOUT,*) 'CALL LA_SYEVR(A, W, INFO=INFO)'\n WRITE(NOUT,*) 'ON ENTRY: A'\n WRITE(NOUT,*) ' A - the original matrix (upper triangular)'\n WRITE(NOUT,*) 'ON EXIT: A, W'\n WRITE(NOUT,*) ' A - destroyed matrix A'\n WRITE(NOUT,*) ' W - the eigenvalues in ascending order'\n A=AA\n W=0\n CALL LA_SYEVR(A,W,INFO=INFO)\n WRITE(NOUT,*) 'The eigenvalues computed by LA_SYEVR:'\n WRITE(NOUT,FMT) W(:)\n WRITE(NOUT,*) 'INFO = ',INFO\n! \n WRITE(NOUT,*)\n WRITE(NOUT,*) \"CALL LA_SYEVR(A, W)\"\n WRITE(NOUT,*) 'ON ENTRY: A'\n WRITE(NOUT,*) ' A - the original matrix (upper triangular)'\n WRITE(NOUT,*) 'ON EXIT: A, W'\n WRITE(NOUT,*) ' A - orthonormal eigenvectors of the matrix A'\n WRITE(NOUT,*) ' W - the eigenvalues in ascending order'\n A=AA\n W=0\n CALL LA_SYEVR(A,W)\n WRITE(NOUT,*) 'The eigenvalues computed by LA_SYEVR:'\n WRITE(NOUT,FMT) W(:)\n WRITE(NOUT,*) 'The orthonormal eigenvectors computed by LA_SYEVR:'\n DO I = 1, N\n WRITE(NOUT,FMT) A(I,:)\n END DO\n! \n WRITE(NOUT,*)\n WRITE(NOUT,*) \"CALL LA_SYEVR(A, W, ABSTOL=0.01_WP)\"\n WRITE(NOUT,*) 'ON ENTRY: A'\n WRITE(NOUT,*) ' A - the original matrix (upper triangular)'\n WRITE(NOUT,*) ' ABSTOL - the absolute error tolerance for the eigenvalues'\n WRITE(NOUT,*) 'ON EXIT: A, W'\n WRITE(NOUT,*) ' A - orthonormal eigenvectors of the matrix A'\n WRITE(NOUT,*) ' W - the eigenvalues in ascending order'\n A=AA\n W=0\n CALL LA_SYEVR(A,W, ABSTOL=0.01_WP)\n WRITE(NOUT,*) 'The eigenvalues computed by LA_SYEVR:'\n WRITE(NOUT,FMT) W(:)\n WRITE(NOUT,*) 'The orthonormal eigenvectors computed by LA_SYEVR:'\n DO I = 1, N\n WRITE(NOUT,FMT) A(I,:)\n END DO\n! \n WRITE(NOUT,*)\n WRITE(NOUT,*) \"CALL LA_SYEVR(A, W, UPLO='L')\"\n WRITE(NOUT,*) 'ON ENTRY: A'\n WRITE(NOUT,*) ' A - the original matrix (lower triangular)'\n WRITE(NOUT,*) 'ON EXIT: A, W'\n WRITE(NOUT,*) ' A - orthonormal eigenvectors of the matrix A'\n WRITE(NOUT,*) ' W - the eigenvalues in ascending order'\n A=AA\n W=0\n UPLO = 'L'\n CALL LA_SYEVR(A, W, UPLO='L')\n WRITE(NOUT,*) 'The eigenvalues computed by LA_SYEVR:'\n WRITE(NOUT,FMT) W(:)\n WRITE(NOUT,*) 'The orthonormal eigenvectors computed by LA_SYEVR:'\n DO I = 1, N\n WRITE(NOUT,FMT) A(I,:)\n END DO\n! \n WRITE(NOUT,*)\n WRITE(NOUT,*) \"CALL LA_SYEVR(A, W, UPLO='L')\"\n WRITE(NOUT,*) 'ON ENTRY: A'\n WRITE(NOUT,*) ' A - the original matrix (lower triangular)'\n WRITE(NOUT,*) 'ON EXIT: A, W'\n WRITE(NOUT,*) ' A - destroyed matrix A'\n WRITE(NOUT,*) ' W - the eigenvalues in ascending order'\n A=AA\n W=0\n UPLO = 'L'\n CALL LA_SYEVR(A,W,UPLO=UPLO)\n WRITE(NOUT,*) 'The eigenvalues computed by LA_SYEVR:'\n WRITE(NOUT,FMT) W(:)\n! \n WRITE(NOUT,*)\n WRITE(NOUT,*) \"CALL LA_SYEVR(A, W, INFO=INFO)\"\n WRITE(NOUT,*) 'ON ENTRY: A'\n WRITE(NOUT,*) ' A - the original matrix (upper triangular)'\n WRITE(NOUT,*) 'ON EXIT: A, W'\n WRITE(NOUT,*) ' A - orthonormal eigenvectors of the matrix A'\n WRITE(NOUT,*) ' W - the eigenvalues in ascending order'\n A=AA\n W=0\n CALL LA_SYEVR(A,W,INFO=INFO)\n WRITE(NOUT,*) 'The eigenvalues computed by LA_SYEVR:'\n WRITE(NOUT,FMT) W(:)\n WRITE(NOUT,*) 'The orthonormal eigenvectors computed by LA_SYEVR:'\n DO I = 1, N\n WRITE(NOUT,FMT) A(I,:)\n END DO\n WRITE(NOUT,*) 'INFO = ',INFO\n! \n WRITE(NOUT,*)\n WRITE(NOUT,*) \"CALL LA_SYEVR(A, W, IL=2, IU=3)\"\n WRITE(NOUT,*) 'ON ENTRY: A'\n WRITE(NOUT,*) ' A - the original matrix (upper triangular)'\n WRITE(NOUT,*) ' IL,IU - the indices of the smallest and largest'\n WRITE(NOUT,*) ' eigenvalues to be returned'\n WRITE(NOUT,*) 'ON EXIT: A, W'\n WRITE(NOUT,*) ' A - orthonormal eigenvectors of the matrix A'\n WRITE(NOUT,*) ' W - the eigenvalues in ascending order'\n A=AA\n W=0\n CALL LA_SYEVR(A,W,IL=2,IU=3)\n WRITE(NOUT,*) 'The eigenvalues computed by LA_SYEVR:'\n WRITE(NOUT,FMT) W(:)\n WRITE(NOUT,*) 'The orthonormal eigenvectors computed by LA_SYEVR:'\n DO I = 1, N\n WRITE(NOUT,FMT) A(I,:)\n END DO\n! \n WRITE(NOUT,*)\n WRITE(NOUT,*) \"CALL LA_SYEVR(A, W, IL=2)\"\n WRITE(NOUT,*) 'ON ENTRY: A'\n WRITE(NOUT,*) ' A - the original matrix (upper triangular)'\n WRITE(NOUT,*) ' IL,IU - the indices of the smallest and largest'\n WRITE(NOUT,*) ' eigenvalues to be returned (IU = N is assumed).'\n WRITE(NOUT,*) 'ON EXIT: A, W'\n WRITE(NOUT,*) ' A - orthonormal eigenvectors of the matrix A'\n WRITE(NOUT,*) ' W - the eigenvalues in ascending order'\n A=AA\n W=0\n CALL LA_SYEVR(A,W,IL=2)\n WRITE(NOUT,*) 'The eigenvalues computed by LA_SYEVR:'\n WRITE(NOUT,FMT) W(:)\n WRITE(NOUT,*) 'The orthonormal eigenvectors computed by LA_SYEVR:'\n DO I = 1, N\n WRITE(NOUT,FMT) A(I,:)\n END DO\n! \n WRITE(NOUT,*)\n WRITE(NOUT,*) \"CALL LA_SYEVR(A, W, VL=0.1_WP, VU=4.0_WP, M=M)\"\n WRITE(NOUT,*) 'ON ENTRY: A'\n WRITE(NOUT,*) ' A - the original matrix (upper triangular)'\n WRITE(NOUT,*) ' VL,VU - the lower and upper bounds of the interval'\n WRITE(NOUT,*) ' to be searched for eigenvalues'\n WRITE(NOUT,*) 'ON EXIT: A, W'\n WRITE(NOUT,*) ' A - destroyed matrix A'\n WRITE(NOUT,*) ' W - the eigenvalues in ascending order'\n WRITE(NOUT,*) ' M - the total number of eigenvalues found'\n A=AA\n W=0\n CALL LA_SYEVR(A,W,VL=0.1_WP,VU=4.0_WP,M=M)\n WRITE(NOUT,*) 'The total number of eigenvalues found = ',M\n WRITE(NOUT,*) 'The eigenvalues computed by LA_SYEVR:'\n WRITE(NOUT,FMT) W(:M)\n! \n WRITE(NOUT,*)\n WRITE(NOUT,*) \"CALL LA_SYEVR(A, W, VU=4.0_WP, M=M)\"\n WRITE(NOUT,*) 'ON ENTRY: A'\n WRITE(NOUT,*) ' A - the original matrix (upper triangular)'\n WRITE(NOUT,*) ' VL,VU - the lower and upper bounds of the interval'\n WRITE(NOUT,*) ' to be searched for eigenvalues (VL = -infinity'\n WRITE(NOUT,*) ' is assumed)'\n WRITE(NOUT,*) 'ON EXIT: A, W'\n WRITE(NOUT,*) ' A - destroyed matrix A'\n WRITE(NOUT,*) ' W - the eigenvalues in ascending order'\n WRITE(NOUT,*) ' M - the total number of eigenvalues found'\n A=AA\n W=0\n CALL LA_SYEVR(A,W,VU=4.0_WP,M=M)\n WRITE(NOUT,*) 'The total number of eigenvalues found = ',M\n WRITE(NOUT,*) 'The eigenvalues computed by LA_SYEVR:'\n WRITE(NOUT,FMT) W(:M)\n! STARTING THE ERROR TESTS:\n! ERROR 1\n WRITE(NOUT,*)\n WRITE(NOUT,*) \"CALL LA_SYEVR(A(:,1:N-1), W, VL=0.1_WP, VU=4.0_WP, M=M, INFO=INFO)\"\n A=AA; W=0\n CALL LA_SYEVR(A(:,1:N-1),W,VL=0.1_WP,VU=4.0_WP,M=M, INFO=INFO)\n WRITE(NOUT,*) 'INFO = ', INFO\n! ERROR 2\n WRITE(NOUT,*)\n WRITE(NOUT,*) \"CALL LA_SYEVR(A, W(1:N-1), VL=0.1_WP, VU=4.0_WP, M=M, INFO=INFO)\"\n A=AA; W=0\n CALL LA_SYEVR(A,W(1:N-1),VL=0.1_WP,VU=4.0_WP,M=M, INFO=INFO)\n WRITE(NOUT,*) 'INFO = ', INFO\n! ERROR 3\n UPLO = 'T'; VL = 1; VU = 10\n WRITE(NOUT,*)\n WRITE(NOUT,*) \"CALL LA_SYEVR(A, W, 'T', VL=VL, VU=VU, M=M, INFO=INFO)\"\n A=AA; W=0\n CALL LA_SYEVR(A, W, JOBZ='T', VL=VL, VU=VU, M=M, INFO=INFO)\n WRITE(NOUT,*) 'INFO = ', INFO\n! ERROR 4\n UPLO = 'U'; VL = 1; VU = 10\n WRITE(NOUT,*)\n WRITE(NOUT,*) \"CALL LA_SYEVR(A, W, 'V', UPLO='U', VL=VL, VU=VU, M=M, INFO=INFO)\"\n A=AA; W=0\n CALL LA_SYEVR(A, W, 'V', UPLO='U', VL=VL, VU=VU, M=M, INFO=INFO)\n WRITE(NOUT,*) 'INFO = ', INFO\n! ERROR 4\n UPLO = 'U'; VL = 1; VU = 10\n WRITE(NOUT,*)\n WRITE(NOUT,*) \"CALL LA_SYEVR(A, W, 'U', VL=VL, VU=VU, M=M, INFO=INFO)\"\n A=AA; W=0\n CALL LA_SYEVR(A, W, 'U', VL=VL, VU=VU, M=M, INFO=INFO)\n WRITE(NOUT,*) 'INFO = ', INFO\n! ERROR 5\n UPLO = 'U'; VL = 1; VU = 10\n WRITE(NOUT,*)\n WRITE(NOUT,*) \"CALL LA_SYEVR(A, W, JOBZ='V', UPLO='U', VL=VL, VU=VU, M=M, ISUPPZ=ISUPPZ(1:N-1), INFO=INFO)\"\n A=AA; W=0\n CALL LA_SYEVR(A, W, JOBZ='V', UPLO='U', VL=VL, VU=VU, M=M, ISUPPZ=ISUPPZ(1:N-1), INFO=INFO)\n WRITE(NOUT,*) 'INFO = ', INFO\n! ERROR 5\n UPLO = 'U'; VL = 1; VU = 10\n WRITE(NOUT,*)\n WRITE(NOUT,*) \"CALL LA_SYEVR(A, W, 'U', VL=VL, VU=VU, M=M, ISUPPZ=ISUPPZ, INFO=INFO)\"\n A=AA; W=0\n CALL LA_SYEVR(A, W, 'U', VL=VL, VU=VU, M=M, ISUPPZ=ISUPPZ, INFO=INFO)\n WRITE(NOUT,*) 'INFO = ', INFO \n! ERROR 6\n UPLO = 'U'; VL = 10; VU = 1\n WRITE(NOUT,*)\n WRITE(NOUT,*) \"CALL LA_SYEVR(A, W, 'U', VL=VL, VU=VU, M=M, INFO=INFO)\"\n A=AA; W=0\n CALL LA_SYEVR(A, W, 'N', VL=VL, VU=VU, M=M, INFO=INFO)\n WRITE(NOUT,*) 'INFO = ', INFO \n! ERROR 7\n UPLO = 'U'; VL = 1; VU = 10; IL=1; IU=N\n WRITE(NOUT,*)\n WRITE(NOUT,*) \"CALL LA_SYEVR(A, W, 'V', VL=VL, VU=VU, IL=IL, IU=IU, M=M, INFO=INFO)\"\n A=AA; W=0\n CALL LA_SYEVR(A, W, 'V', VL=VL, VU=VU, IL=IL, IU=IU, M=M, INFO=INFO)\n WRITE(NOUT,*) 'INFO = ', INFO \n! ERROR 8\n UPLO = 'U'; IL=-1; IU=N\n WRITE(NOUT,*)\n WRITE(NOUT,*) \"CALL LA_SYEVR(A, W, 'N', IL=-1, IU=IU, M=M, INFO=INFO)\"\n A=AA; W=0\n CALL LA_SYEVR(A, W, 'N', IL=IL, IU=IU, M=M, INFO=INFO)\n WRITE(NOUT,*) 'INFO = ', INFO\n! ERROR 8\n UPLO = 'U'; IL=N; IU=N-1\n WRITE(NOUT,*)\n WRITE(NOUT,*) \"CALL LA_SYEVR(A, W, '0', IL=N, IU=N-1, M=M, INFO=INFO)\"\n A=AA; W=0\n CALL LA_SYEVR(A, W, '0', IL=IL, IU=IU, M=M, INFO=INFO)\n WRITE(NOUT,*) 'INFO = ', INFO \n! ERROR 9\n UPLO = 'U'; IL=1; IU=N+1\n WRITE(NOUT,*)\n WRITE(NOUT,*) \"CALL LA_SYEVR(A, W, UPLO='N', IL=1, IU=N+1, M=M, INFO=INFO)\"\n A=AA; W=0\n CALL LA_SYEVR(A, W, UPLO='N', IL=IL, IU=IU, M=M, INFO=INFO)\n WRITE(NOUT,*) 'INFO = ', INFO \n \nEND PROGRAM LA_DSYEVR_ET_EXAMPLE\n", "meta": {"hexsha": "13beed283610baa3b2b7960ac56e283bd8b26e6e", "size": 10622, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "EXAMPLES2/dsyevret.f90", "max_stars_repo_name": "MattBurn/LAPACK95", "max_stars_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-12-29T15:07:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T10:09:22.000Z", "max_issues_repo_path": "EXAMPLES2/dsyevret.f90", "max_issues_repo_name": "MattBurn/LAPACK95", "max_issues_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-12-30T15:38:47.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-31T06:45:11.000Z", "max_forks_repo_path": "EXAMPLES2/dsyevret.f90", "max_forks_repo_name": "MattBurn/LAPACK95", "max_forks_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-12-29T15:34:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-15T07:12:40.000Z", "avg_line_length": 35.2890365449, "max_line_length": 110, "alphanum_fraction": 0.5827527773, "num_tokens": 4133, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.757794360334681, "lm_q1q2_score": 0.6556619302026316}} {"text": " PROGRAM LA_SGELS_EXAMPLE\n\n! -- LAPACK95 EXAMPLE DRIVER ROUTINE (VERSION 1.0) --\n! UNI-C, DENMARK\n! DECEMBER, 1999\n!\n! .. \"Use Statements\" ..\n USE LA_PRECISION, ONLY: WP => SP\n USE F95_LAPACK, ONLY: LA_GELS\n! .. \"Implicit Statement\" ..\n IMPLICIT NONE\n! .. \"Local Scalars\" ..\n INTEGER :: I, J, INFO, M, N, NRHS\n! .. \"Local Arrays\" ..\n REAL(WP), ALLOCATABLE :: A(:,:), AA(:,:), B(:,:), BB(:,:)\n! .. \"Executable Statements\" ..\n WRITE (*,*) 'LA_GELS Example Program Results'\n M=6; N = 4; NRHS = 3\n WRITE(*,'(5H N = , I4, 9H; NRHS = , I4)') N, NRHS\n ALLOCATE( A(M,N), AA(M,N), B(M,NRHS), BB(M,NRHS) )\n\n OPEN(UNIT=21,FILE='gels.ma',STATUS='UNKNOWN')\n DO J=1,N\n DO I=1,M \n READ(21,'(F2.0)') A(I,J)\n ENDDO\n ENDDO\n CLOSE(21)\n\n WRITE(*,*)'Matrix A :'\n DO I=1,M;\n WRITE(*,\"(24(F9.5))\") A(I,:);\n ENDDO\n \n AA=A\n \n OPEN(UNIT=22,FILE='gels.mb',STATUS='UNKNOWN')\n DO J=1,NRHS\n DO I=1,M \n READ(22,'(F3.0)') B(I,J)\n ENDDO\n ENDDO\n CLOSE(22)\n \n BB=B\n WRITE(*,*)'Matrix B :'\n DO I=1,M; \n WRITE(*,\"(3(F9.5))\") B(I,:); \n ENDDO\n \n WRITE(*,*) 'CALL LA_GELS( A, B )'\n CALL LA_GELS( A, B )\n \n WRITE(*,*) 'The matrix B on exit :'\n DO I=1,M; \n WRITE(*,\"(3(E13.6))\") B(I,:); \n ENDDO\n WRITE(*,*)\n WRITE(*,*)' * EXAMPLE 2 * '\n \n WRITE(*,*)'Matrix A :'\n DO I=1,M;\n WRITE(*,\"(24(F9.5))\") AA(I,:);\n ENDDO \n\n WRITE(*,*)'Matrix B(:,1) :'\n WRITE(*,\"(F9.5)\") BB(:,1); \n \n WRITE(*,*) \"CALL LA_GELS( A, B(:,1), 'T', INFO )\"\n CALL LA_GELS( A, B(:,1), 'T', INFO )\n\n WRITE(*,*) 'The matrix B on exit :' \n WRITE(*,\"(E13.6)\") B(:,1); \n \n WRITE(*,*) 'INFO = ', INFO\n\n END PROGRAM LA_SGELS_EXAMPLE\n", "meta": {"hexsha": "5ed5cc07121f9923dce6917f87632f9fc129ef98", "size": 1920, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "EXAMPLES1/la_gels_example.f90", "max_stars_repo_name": "MattBurn/LAPACK95", "max_stars_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-12-29T15:07:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T10:09:22.000Z", "max_issues_repo_path": "EXAMPLES1/la_gels_example.f90", "max_issues_repo_name": "MattBurn/LAPACK95", "max_issues_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-12-30T15:38:47.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-31T06:45:11.000Z", "max_forks_repo_path": "EXAMPLES1/la_gels_example.f90", "max_forks_repo_name": "MattBurn/LAPACK95", "max_forks_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-12-29T15:34:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-15T07:12:40.000Z", "avg_line_length": 24.6153846154, "max_line_length": 63, "alphanum_fraction": 0.4348958333, "num_tokens": 699, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199795472731, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6555737338592353}} {"text": " program circ\n\n implicit real*8 (a-h,o-z)\n\n pi = 3.1415926535897932385d+0\n\n write(*,\"('Enter Nx ==> ',$)\")\n read(*,*) nx\n write(*,\"('Enter Radius ==> ',$)\")\n read(*,*) r\n \n dth = -2.0 * pi / float(nx-1)\n\n thmin = 2.0 * pi\n\n write(10,*) nx\n\n do i = 1, nx\n\n th = thmin + float(i-1) * dth\n\n x = r * cos(th)\n y = r * sin(th)\n\n write(10,10) x, y\n 10 format(2(1pe20.13,1x))\n\n end do\n\n stop\n end\n\n", "meta": {"hexsha": "21be2ec51f9e2837300829e0666cba154829555c", "size": 504, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "mesh/circ.f", "max_stars_repo_name": "sscollis/lns3d", "max_stars_repo_head_hexsha": "f87b06abbb188cce9248092075f71dcce4570493", "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": "mesh/circ.f", "max_issues_repo_name": "sscollis/lns3d", "max_issues_repo_head_hexsha": "f87b06abbb188cce9248092075f71dcce4570493", "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": "mesh/circ.f", "max_forks_repo_name": "sscollis/lns3d", "max_forks_repo_head_hexsha": "f87b06abbb188cce9248092075f71dcce4570493", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-02-20T09:24:25.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-20T09:24:25.000Z", "avg_line_length": 15.2727272727, "max_line_length": 40, "alphanum_fraction": 0.4007936508, "num_tokens": 183, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6555737211691584}} {"text": "program smoothbump_generator\n implicit none\n\n\n integer(kind=4) :: npt_x, npt_y, npt_z, &\n nelem_quartic_x, nelem_quartic_y, nelem_quartic_z, &\n ierr, ncoords, i, j, k, n, &\n ipt_x, ipt_y, ipt_z\n real(kind=8), allocatable :: coord(:,:,:,:)\n real(kind=8) :: x,y,z,alpha\n character(len=100) :: buffer\n\n\n\n !\n ! Get grid dimensions from user-input arguments\n !\n print*, 'Enter number of elements in each coordinate direction: nelem_x, nelem_y, nelem_z'\n read(*,*) nelem_quartic_x, nelem_quartic_y, nelem_quartic_z\n\n\n\n !\n ! Define number of quartic elements in each direction\n !\n !nelem_quartic_x = 6\n !nelem_quartic_y = 2\n !nelem_quartic_z = 2\n\n !\n ! Compute number of points in each direction\n !\n npt_x = nelem_quartic_x*4 + 1\n npt_y = nelem_quartic_y*4 + 1\n npt_z = nelem_quartic_z*4 + 1 \n\n\n !\n ! Allocate coordinate array\n !\n ncoords = 3\n allocate(coord(npt_x,npt_y,npt_z,ncoords),stat=ierr)\n if (ierr /= 0) stop \"Allocation Error\"\n\n\n !\n ! Create gridfile name\n !\n write(buffer,'( \"smoothbump_\",I0.0,\"x\",I0.0,\"x\",I0.0,\".x\")') nelem_quartic_x, nelem_quartic_y, nelem_quartic_z\n\n\n\n !\n ! Generate coordinates\n !\n do ipt_z = 1,npt_z\n \n do ipt_y = 1,npt_y\n\n\n\n\n do ipt_x = 1,npt_x\n\n x = -1.5_8 + real(ipt_x-1,kind=8)*(3._8 / real(npt_x-1,kind=8))\n alpha = 0.0625_8 * exp(-25._8 * (x**2._8))\n y = alpha + real(ipt_y-1,kind=8)*(0.8_8 - alpha)/real(npt_y-1,kind=8)\n z = 0._8 + real(ipt_z-1,kind=8)*(1._8 / real(npt_z-1,kind=8))\n\n\n coord(ipt_x,ipt_y,ipt_z,1) = x\n coord(ipt_x,ipt_y,ipt_z,2) = y\n coord(ipt_x,ipt_y,ipt_z,3) = z\n\n end do\n\n end do\n\n end do\n\n\n\n\n\n\n\n\n !\n ! Write coordinates to file\n !\n open(unit=7, file=trim(buffer), form='unformatted')\n\n write(7) 1\n write(7) npt_x, npt_y, npt_z\n write(7) (((( coord(i,j,k,n), i=1,npt_x), j=1,npt_y), k=1,npt_z), n=1,ncoords)\n\n close(7)\n\n\n\n\n\n\nend program\n", "meta": {"hexsha": "2e341b98077bfedb8ff89b55404622ec58e4e1c2", "size": 2241, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/examples/smoothbump/smoothbump_example/smoothbump_generator.f90", "max_stars_repo_name": "nwukie/ChiDG_pysite", "max_stars_repo_head_hexsha": "9116b9c4cdf73606f1d49906f10be0a170cd2e8d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-01-21T03:53:15.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-21T03:53:15.000Z", "max_issues_repo_path": "source/examples/smoothbump/smoothbump_example/smoothbump_generator.f90", "max_issues_repo_name": "nwukie/ChiDG_pysite", "max_issues_repo_head_hexsha": "9116b9c4cdf73606f1d49906f10be0a170cd2e8d", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/examples/smoothbump/smoothbump_example/smoothbump_generator.f90", "max_forks_repo_name": "nwukie/ChiDG_pysite", "max_forks_repo_head_hexsha": "9116b9c4cdf73606f1d49906f10be0a170cd2e8d", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.3428571429, "max_line_length": 114, "alphanum_fraction": 0.5292280232, "num_tokens": 733, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199552262967, "lm_q2_score": 0.7826624688140726, "lm_q1q2_score": 0.6555737020853464}} {"text": "*DECK DGAUS8\n SUBROUTINE DGAUS8 (FUN, A, B, ERR, ANS, IERR)\nC***BEGIN PROLOGUE DGAUS8\nC***PURPOSE Integrate a real function of one variable over a finite\nC interval using an adaptive 8-point Legendre-Gauss\nC algorithm. Intended primarily for high accuracy\nC integration or integration of smooth functions.\nC***LIBRARY SLATEC\nC***CATEGORY H2A1A1\nC***TYPE DOUBLE PRECISION (GAUS8-S, DGAUS8-D)\nC***KEYWORDS ADAPTIVE QUADRATURE, AUTOMATIC INTEGRATOR,\nC GAUSS QUADRATURE, NUMERICAL INTEGRATION\nC***AUTHOR Jones, R. E., (SNLA)\nC***DESCRIPTION\nC\nC Abstract *** a DOUBLE PRECISION routine ***\nC DGAUS8 integrates real functions of one variable over finite\nC intervals using an adaptive 8-point Legendre-Gauss algorithm.\nC DGAUS8 is intended primarily for high accuracy integration\nC or integration of smooth functions.\nC\nC The maximum number of significant digits obtainable in ANS\nC is the smaller of 18 and the number of digits carried in\nC double precision arithmetic.\nC\nC Description of Arguments\nC\nC Input--* FUN, A, B, ERR are DOUBLE PRECISION *\nC FUN - name of external function to be integrated. This name\nC must be in an EXTERNAL statement in the calling program.\nC FUN must be a DOUBLE PRECISION function of one DOUBLE\nC PRECISION argument. The value of the argument to FUN\nC is the variable of integration which ranges from A to B.\nC A - lower limit of integration\nC B - upper limit of integration (may be less than A)\nC ERR - is a requested pseudorelative error tolerance. Normally\nC pick a value of ABS(ERR) so that DTOL .LT. ABS(ERR) .LE.\nC 1.0D-3 where DTOL is the larger of 1.0D-18 and the\nC double precision unit roundoff D1MACH(4). ANS will\nC normally have no more error than ABS(ERR) times the\nC integral of the absolute value of FUN(X). Usually,\nC smaller values of ERR yield more accuracy and require\nC more function evaluations.\nC\nC A negative value for ERR causes an estimate of the\nC absolute error in ANS to be returned in ERR. Note that\nC ERR must be a variable (not a constant) in this case.\nC Note also that the user must reset the value of ERR\nC before making any more calls that use the variable ERR.\nC\nC Output--* ERR,ANS are double precision *\nC ERR - will be an estimate of the absolute error in ANS if the\nC input value of ERR was negative. (ERR is unchanged if\nC the input value of ERR was non-negative.) The estimated\nC error is solely for information to the user and should\nC not be used as a correction to the computed integral.\nC ANS - computed value of integral\nC IERR- a status code\nC --Normal codes\nC 1 ANS most likely meets requested error tolerance,\nC or A=B.\nC -1 A and B are too nearly equal to allow normal\nC integration. ANS is set to zero.\nC --Abnormal code\nC 2 ANS probably does not meet requested error tolerance.\nC\nC***REFERENCES (NONE)\nC***ROUTINES CALLED D1MACH, I1MACH, XERMSG\nC***REVISION HISTORY (YYMMDD)\nC 810223 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890911 Removed unnecessary intrinsics. (WRB)\nC 890911 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\nC 900326 Removed duplicate information from DESCRIPTION section.\nC (WRB)\nC***END PROLOGUE DGAUS8\n INTEGER IERR, K, KML, KMX, L, LMN, LMX, LR, MXL, NBITS,\n 1 NIB, NLMN, NLMX\n INTEGER I1MACH\n DOUBLE PRECISION A,AA,AE,ANIB,ANS,AREA,B,C,CE,EE,EF,\n 1 EPS, ERR, EST, GL, GLR, GR, HH, SQ2, TOL, VL, VR, W1, W2, W3,\n 2 W4, X1, X2, X3, X4, X, H\n DOUBLE PRECISION D1MACH, G8, FUN\n DIMENSION AA(60), HH(60), LR(60), VL(60), GR(60)\n SAVE X1, X2, X3, X4, W1, W2, W3, W4, SQ2,\n 1 NLMN, KMX, KML\n DATA X1, X2, X3, X4/\n 1 1.83434642495649805D-01, 5.25532409916328986D-01,\n 2 7.96666477413626740D-01, 9.60289856497536232D-01/\n DATA W1, W2, W3, W4/\n 1 3.62683783378361983D-01, 3.13706645877887287D-01,\n 2 2.22381034453374471D-01, 1.01228536290376259D-01/\n DATA SQ2/1.41421356D0/\n DATA NLMN/1/,KMX/5000/,KML/6/\n G8(X,H)=H*((W1*(FUN(X-X1*H) + FUN(X+X1*H))\n 1 +W2*(FUN(X-X2*H) + FUN(X+X2*H)))\n 2 +(W3*(FUN(X-X3*H) + FUN(X+X3*H))\n 3 +W4*(FUN(X-X4*H) + FUN(X+X4*H))))\nC***FIRST EXECUTABLE STATEMENT DGAUS8\nC\nC Initialize\nC\n K = I1MACH(14)\n ANIB = D1MACH(5)*K/0.30102000D0\n NBITS = ANIB\n NLMX = MIN(60,(NBITS*5)/8)\n ANS = 0.0D0\n IERR = 1\n CE = 0.0D0\n IF (A .EQ. B) GO TO 140\n LMX = NLMX\n LMN = NLMN\n IF (B .EQ. 0.0D0) GO TO 10\n IF (SIGN(1.0D0,B)*A .LE. 0.0D0) GO TO 10\n C = ABS(1.0D0-A/B)\n IF (C .GT. 0.1D0) GO TO 10\n IF (C .LE. 0.0D0) GO TO 140\n ANIB = 0.5D0 - LOG(C)/0.69314718D0\n NIB = ANIB\n LMX = MIN(NLMX,NBITS-NIB-7)\n IF (LMX .LT. 1) GO TO 130\n LMN = MIN(LMN,LMX)\n 10 TOL = MAX(ABS(ERR),2.0D0**(5-NBITS))/2.0D0\n IF (ERR .EQ. 0.0D0) TOL = SQRT(D1MACH(4))\n EPS = TOL\n HH(1) = (B-A)/4.0D0\n AA(1) = A\n LR(1) = 1\n L = 1\n EST = G8(AA(L)+2.0D0*HH(L),2.0D0*HH(L))\n K = 8\n AREA = ABS(EST)\n EF = 0.5D0\n MXL = 0\nC\nC Compute refined estimates, estimate the error, etc.\nC\n 20 GL = G8(AA(L)+HH(L),HH(L))\n GR(L) = G8(AA(L)+3.0D0*HH(L),HH(L))\n K = K + 16\n AREA = AREA + (ABS(GL)+ABS(GR(L))-ABS(EST))\nC IF (L .LT .LMN) GO TO 11\n GLR = GL + GR(L)\n EE = ABS(EST-GLR)*EF\n AE = MAX(EPS*AREA,TOL*ABS(GLR))\n IF (EE-AE) 40, 40, 50\n 30 MXL = 1\n 40 CE = CE + (EST-GLR)\n IF (LR(L)) 60, 60, 80\nC\nC Consider the left half of this level\nC\n 50 IF (K .GT. KMX) LMX = KML\n IF (L .GE. LMX) GO TO 30\n L = L + 1\n EPS = EPS*0.5D0\n EF = EF/SQ2\n HH(L) = HH(L-1)*0.5D0\n LR(L) = -1\n AA(L) = AA(L-1)\n EST = GL\n GO TO 20\nC\nC Proceed to right half at this level\nC\n 60 VL(L) = GLR\n 70 EST = GR(L-1)\n LR(L) = 1\n AA(L) = AA(L) + 4.0D0*HH(L)\n GO TO 20\nC\nC Return one level\nC\n 80 VR = GLR\n 90 IF (L .LE. 1) GO TO 120\n L = L - 1\n EPS = EPS*2.0D0\n EF = EF*SQ2\n IF (LR(L)) 100, 100, 110\n 100 VL(L) = VL(L+1) + VR\n GO TO 70\n 110 VR = VL(L+1) + VR\n GO TO 90\nC\nC Exit\nC\n 120 ANS = VR\n IF ((MXL.EQ.0) .OR. (ABS(CE).LE.2.0D0*TOL*AREA)) GO TO 140\n IERR = 2\n CALL XERMSG ('SLATEC', 'DGAUS8',\n + 'ANS is probably insufficiently accurate.', 3, 1)\n GO TO 140\n 130 IERR = -1\n CALL XERMSG ('SLATEC', 'DGAUS8',\n + 'A and B are too nearly equal to allow normal integration. $$'\n + // 'ANS is set to zero and IERR to -1.', 1, -1)\n 140 IF (ERR .LT. 0.0D0) ERR = CE\n RETURN\n END\n", "meta": {"hexsha": "ad4a1cbb3e46466cbe7b68ea1d45917cc51fd631", "size": 7271, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/dgaus8.f", "max_stars_repo_name": "fermi-lat/st_facilities", "max_stars_repo_head_hexsha": "4775ca58c2aef031d3cbffb57a0c55368cfd79f2", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/dgaus8.f", "max_issues_repo_name": "fermi-lat/st_facilities", "max_issues_repo_head_hexsha": "4775ca58c2aef031d3cbffb57a0c55368cfd79f2", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-01-09T23:51:17.000Z", "max_issues_repo_issues_event_max_datetime": "2020-01-09T23:51:17.000Z", "max_forks_repo_path": "src/dgaus8.f", "max_forks_repo_name": "fermi-lat/st_facilities", "max_forks_repo_head_hexsha": "4775ca58c2aef031d3cbffb57a0c55368cfd79f2", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-14T19:25:00.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-14T19:25:00.000Z", "avg_line_length": 35.995049505, "max_line_length": 71, "alphanum_fraction": 0.5813505708, "num_tokens": 2615, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297967961707, "lm_q2_score": 0.7279754489059775, "lm_q1q2_score": 0.6555635830759011}} {"text": " SUBROUTINE MB04YD( JOBU, JOBV, M, N, RANK, THETA, Q, E, U, LDU, V,\n $ LDV, INUL, TOL, RELTOL, DWORK, LDWORK, IWARN,\n $ INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To partially diagonalize the bidiagonal matrix\nC\nC |q(1) e(1) 0 ... 0 |\nC | 0 q(2) e(2) . |\nC J = | . . | (1)\nC | . e(MIN(M,N)-1)|\nC | 0 ... ... q(MIN(M,N)) |\nC\nC using QR or QL iterations in such a way that J is split into\nC unreduced bidiagonal submatrices whose singular values are either\nC all larger than a given bound or are all smaller than (or equal\nC to) this bound. The left- and right-hand Givens rotations\nC performed on J (corresponding to each QR or QL iteration step) may\nC be optionally accumulated in the arrays U and V.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC JOBU CHARACTER*1\nC Indicates whether the user wishes to accumulate in a\nC matrix U the left-hand Givens rotations, as follows:\nC = 'N': Do not form U;\nC = 'I': U is initialized to the M-by-MIN(M,N) submatrix of\nC the unit matrix and the left-hand Givens rotations\nC are accumulated in U;\nC = 'U': The given matrix U is updated by the left-hand\nC Givens rotations used in the calculation.\nC\nC JOBV CHARACTER*1\nC Indicates whether the user wishes to accumulate in a\nC matrix V the right-hand Givens rotations, as follows:\nC = 'N': Do not form V;\nC = 'I': V is initialized to the N-by-MIN(M,N) submatrix of\nC the unit matrix and the right-hand Givens\nC rotations are accumulated in V;\nC = 'U': The given matrix V is updated by the right-hand\nC Givens rotations used in the calculation.\nC\nC Input/Output Parameters\nC\nC M (input) INTEGER\nC The number of rows in matrix U. M >= 0.\nC\nC N (input) INTEGER\nC The number of rows in matrix V. N >= 0.\nC\nC RANK (input/output) INTEGER\nC On entry, if RANK < 0, then the rank of matrix J is\nC computed by the routine as the number of singular values\nC larger than THETA.\nC Otherwise, RANK must specify the rank of matrix J.\nC RANK <= MIN(M,N).\nC On exit, if RANK < 0 on entry, then RANK contains the\nC computed rank of J. That is, the number of singular\nC values of J larger than THETA.\nC Otherwise, the user-supplied value of RANK may be\nC changed by the routine on exit if the RANK-th and the\nC (RANK+1)-th singular values of J are considered to be\nC equal. See also the parameter TOL.\nC\nC THETA (input/output) DOUBLE PRECISION\nC On entry, if RANK < 0, then THETA must specify an upper\nC bound on the smallest singular values of J. THETA >= 0.0.\nC Otherwise, THETA must specify an initial estimate (t say)\nC for computing an upper bound such that precisely RANK\nC singular values are greater than this bound.\nC If THETA < 0.0, then t is computed by the routine.\nC On exit, if RANK >= 0 on entry, then THETA contains the\nC computed upper bound such that precisely RANK singular\nC values of J are greater than THETA + TOL.\nC Otherwise, THETA is unchanged.\nC\nC Q (input/output) DOUBLE PRECISION array, dimension\nC (MIN(M,N))\nC On entry, this array must contain the diagonal elements\nC q(1),q(2),...,q(MIN(M,N)) of the bidiagonal matrix J. That\nC is, Q(i) = J(i,i) for i = 1,2,...,MIN(M,N).\nC On exit, this array contains the leading diagonal of the\nC transformed bidiagonal matrix J.\nC\nC E (input/output) DOUBLE PRECISION array, dimension\nC (MIN(M,N)-1)\nC On entry, this array must contain the superdiagonal\nC elements e(1),e(2),...,e(MIN(M,N)-1) of the bidiagonal\nC matrix J. That is, E(k) = J(k,k+1) for k = 1,2,...,\nC MIN(M,N)-1.\nC On exit, this array contains the superdiagonal of the\nC transformed bidiagonal matrix J.\nC\nC U (input/output) DOUBLE PRECISION array, dimension (LDU,*)\nC On entry, if JOBU = 'U', the leading M-by-MIN(M,N) part\nC of this array must contain a left transformation matrix\nC applied to the original matrix of the problem, and\nC on exit, the leading M-by-MIN(M,N) part of this array\nC contains the product of the input matrix U and the\nC left-hand Givens rotations.\nC On exit, if JOBU = 'I', then the leading M-by-MIN(M,N)\nC part of this array contains the matrix of accumulated\nC left-hand Givens rotations used.\nC If JOBU = 'N', the array U is not referenced and can be\nC supplied as a dummy array (i.e. set parameter LDU = 1 and\nC declare this array to be U(1,1) in the calling program).\nC\nC LDU INTEGER\nC The leading dimension of array U. If JOBU = 'U' or\nC JOBU = 'I', LDU >= MAX(1,M); if JOBU = 'N', LDU >= 1.\nC\nC V (input/output) DOUBLE PRECISION array, dimension (LDV,*)\nC On entry, if JOBV = 'U', the leading N-by-MIN(M,N) part\nC of this array must contain a right transformation matrix\nC applied to the original matrix of the problem, and\nC on exit, the leading N-by-MIN(M,N) part of this array\nC contains the product of the input matrix V and the\nC right-hand Givens rotations.\nC On exit, if JOBV = 'I', then the leading N-by-MIN(M,N)\nC part of this array contains the matrix of accumulated\nC right-hand Givens rotations used.\nC If JOBV = 'N', the array V is not referenced and can be\nC supplied as a dummy array (i.e. set parameter LDV = 1 and\nC declare this array to be V(1,1) in the calling program).\nC\nC LDV INTEGER\nC The leading dimension of array V. If JOBV = 'U' or\nC JOBV = 'I', LDV >= MAX(1,N); if JOBV = 'N', LDV >= 1.\nC\nC INUL (input/output) LOGICAL array, dimension (MIN(M,N))\nC On entry, the leading MIN(M,N) elements of this array must\nC be set to .FALSE. unless the i-th columns of U (if JOBU =\nC 'U') and V (if JOBV = 'U') already contain a computed base\nC vector of the desired singular subspace of the original\nC matrix, in which case INUL(i) must be set to .TRUE.\nC for 1 <= i <= MIN(M,N).\nC On exit, the indices of the elements of this array with\nC value .TRUE. indicate the indices of the diagonal entries\nC of J which belong to those bidiagonal submatrices whose\nC singular values are all less than or equal to THETA.\nC\nC Tolerances\nC\nC TOL DOUBLE PRECISION\nC This parameter defines the multiplicity of singular values\nC by considering all singular values within an interval of\nC length TOL as coinciding. TOL is used in checking how many\nC singular values are less than or equal to THETA. Also in\nC computing an appropriate upper bound THETA by a bisection\nC method, TOL is used as a stopping criterion defining the\nC minimum (absolute) subinterval width. TOL is also taken\nC as an absolute tolerance for negligible elements in the\nC QR/QL iterations. If the user sets TOL to be less than or\nC equal to 0, then the tolerance is taken as\nC EPS * MAX(ABS(Q(i)), ABS(E(k))), where EPS is the\nC machine precision (see LAPACK Library routine DLAMCH),\nC i = 1,2,...,MIN(M,N) and k = 1,2,...,MIN(M,N)-1.\nC\nC RELTOL DOUBLE PRECISION\nC This parameter specifies the minimum relative width of an\nC interval. When an interval is narrower than TOL, or than\nC RELTOL times the larger (in magnitude) endpoint, then it\nC is considered to be sufficiently small and bisection has\nC converged. If the user sets RELTOL to be less than\nC BASE * EPS, where BASE is machine radix and EPS is machine\nC precision (see LAPACK Library routine DLAMCH), then the\nC tolerance is taken as BASE * EPS.\nC\nC Workspace\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC\nC LDWORK INTEGER\nC The length of the array DWORK.\nC LDWORK >= MAX(1,6*MIN(M,N)-5), if JOBU = 'I' or 'U', or\nC JOBV = 'I' or 'U';\nC LDWORK >= MAX(1,4*MIN(M,N)-3), if JOBU = 'N' and\nC JOBV = 'N'.\nC\nC Warning Indicator\nC\nC IWARN INTEGER\nC = 0: no warning;\nC = 1: if the rank of the bidiagonal matrix J (as specified\nC by the user) has been lowered because a singular\nC value of multiplicity larger than 1 was found.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value; this includes values like RANK > MIN(M,N), or\nC THETA < 0.0 and RANK < 0;\nC = 1: if the maximum number of QR/QL iteration steps\nC (30*MIN(M,N)) has been exceeded.\nC\nC METHOD\nC\nC If the upper bound THETA is not specified by the user, then it is\nC computed by the routine (using a bisection method) such that\nC precisely (MIN(M,N) - RANK) singular values of J are less than or\nC equal to THETA + TOL.\nC\nC The method used by the routine (see [1]) then proceeds as follows.\nC\nC The unreduced bidiagonal submatrices of J(j), where J(j) is the\nC transformed bidiagonal matrix after the j-th iteration step, are\nC classified into the following three classes:\nC\nC - C1 contains the bidiagonal submatrices with all singular values\nC > THETA,\nC - C2 contains the bidiagonal submatrices with all singular values\nC <= THETA and\nC - C3 contains the bidiagonal submatrices with singular values\nC > THETA and also singular values <= THETA.\nC\nC If C3 is empty, then the partial diagonalization is complete, and\nC RANK is the sum of the dimensions of the bidiagonal submatrices of\nC C1.\nC Otherwise, QR or QL iterations are performed on each bidiagonal\nC submatrix of C3, until this bidiagonal submatrix has been split\nC into two bidiagonal submatrices. These two submatrices are then\nC classified and the iterations are restarted.\nC If the upper left diagonal element of the bidiagonal submatrix is\nC larger than its lower right diagonal element, then QR iterations\nC are performed, else QL iterations are used. The shift is taken as\nC the smallest diagonal element of the bidiagonal submatrix (in\nC magnitude) unless its value exceeds THETA, in which case it is\nC taken as zero.\nC\nC REFERENCES\nC\nC [1] Van Huffel, S., Vandewalle, J. and Haegemans, A.\nC An efficient and reliable algorithm for computing the\nC singular subspace of a matrix associated with its smallest\nC singular values.\nC J. Comput. and Appl. Math., 19, pp. 313-330, 1987.\nC\nC NUMERICAL ASPECTS\nC\nC The algorithm is backward stable.\nC\nC To avoid overflow, matrix J is scaled so that its largest element\nC is no greater than overflow**(1/2) * underflow**(1/4) in absolute\nC value (and not much smaller than that, for maximal accuracy).\nC\nC CONTRIBUTOR\nC\nC Release 3.0: V. Sima, Katholieke Univ. Leuven, Belgium, June 1997.\nC Supersedes Release 2.0 routine MB04QD by S. Van Huffel, Katholieke\nC University Leuven, Belgium.\nC\nC REVISIONS\nC\nC July 10, 1997. V. Sima.\nC November 25, 1997. V. Sima: Setting INUL(K) = .TRUE. when handling\nC 2-by-2 submatrix.\nC\nC KEYWORDS\nC\nC Bidiagonal matrix, orthogonal transformation, singular values.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, ONE, TEN, HNDRD\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0, TEN = 10.0D0,\n $ HNDRD = 100.0D0 )\n DOUBLE PRECISION MEIGTH\n PARAMETER ( MEIGTH = -0.125D0 )\n INTEGER MAXITR\n PARAMETER ( MAXITR = 30 )\nC .. Scalar Arguments ..\n CHARACTER JOBU, JOBV\n INTEGER INFO, IWARN, LDU, LDV, LDWORK, M, N, RANK\n DOUBLE PRECISION RELTOL, THETA, TOL\nC .. Array Arguments ..\n LOGICAL INUL(*)\n DOUBLE PRECISION DWORK(*), E(*), Q(*), U(LDU,*), V(LDV,*)\nC .. Local Scalars ..\n LOGICAL LJOBUA, LJOBUI, LJOBVA, LJOBVI, NOC12, QRIT\n INTEGER I, I1, IASCL, INFO1, ITER, J, K, MAXIT, NUMEIG,\n $ OLDI, OLDK, P, R\n DOUBLE PRECISION COSL, COSR, EPS, PIVMIN, RMAX, RMIN, SAFEMN,\n $ SHIFT, SIGMA, SIGMN, SIGMX, SINL, SINR, SMAX,\n $ SMLNUM, THETAC, THRESH, TOLABS, TOLREL, X\nC .. External Functions ..\n LOGICAL LSAME\n INTEGER MB03ND\n DOUBLE PRECISION DLAMCH\n EXTERNAL DLAMCH, LSAME, MB03ND\nC .. External Subroutines ..\n EXTERNAL DLASET, DLASV2, DROT, DSCAL, MB02NY, MB03MD,\n $ MB04YW, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC ABS, MAX, MIN, SQRT\nC .. Executable Statements ..\nC\n P = MIN( M, N )\n INFO = 0\n IWARN = 0\n LJOBUI = LSAME( JOBU, 'I' )\n LJOBVI = LSAME( JOBV, 'I' )\n LJOBUA = LJOBUI.OR.LSAME( JOBU, 'U' )\n LJOBVA = LJOBVI.OR.LSAME( JOBV, 'U' )\nC\nC Test the input scalar arguments.\nC\n IF( .NOT.LJOBUA .AND. .NOT.LSAME( JOBU, 'N' ) ) THEN\n INFO = -1\n ELSE IF( .NOT.LJOBVA .AND. .NOT.LSAME( JOBV, 'N' ) ) THEN\n INFO = -2\n ELSE IF( M.LT.0 ) THEN\n INFO = -3\n ELSE IF( N.LT.0 ) THEN\n INFO = -4\n ELSE IF( RANK.GT.P ) THEN\n INFO = -5\n ELSE IF( RANK.LT.0 .AND. THETA.LT.ZERO ) THEN\n INFO = -6\n ELSE IF( .NOT.LJOBUA .AND. LDU.LT.1 .OR.\n $ LJOBUA .AND. LDU.LT.MAX( 1, M ) ) THEN\n INFO = -10\n ELSE IF( .NOT.LJOBVA .AND. LDV.LT.1 .OR.\n $ LJOBVA .AND. LDV.LT.MAX( 1, N ) ) THEN\n INFO = -12\n ELSE IF( ( ( LJOBUA.OR.LJOBVA ) .AND. LDWORK.LT.MAX( 1, 6*P-5 ) )\n $ .OR.(.NOT.( LJOBUA.OR.LJOBVA ) .AND. LDWORK.LT.MAX( 1, 4*P-3 ) )\n $ ) THEN\n INFO = -17\n END IF\nC\n IF ( INFO.NE.0 ) THEN\nC\nC Error return.\nC\n CALL XERBLA( 'MB04YD', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF ( P.EQ.0 ) THEN\n IF ( RANK.GE.0 )\n $ THETA = ZERO\n RANK = 0\n RETURN\n END IF\nC\nC Set tolerances and machine parameters.\nC\n TOLABS = TOL\n TOLREL = RELTOL\n SMAX = ABS( Q(P) )\nC\n DO 20 J = 1, P - 1\n SMAX = MAX( SMAX, ABS( Q(J) ), ABS( E(J) ) )\n 20 CONTINUE\nC\n SAFEMN = DLAMCH( 'Safe minimum' )\n EPS = DLAMCH( 'Epsilon' )\n IF ( TOLABS.LE.ZERO ) TOLABS = EPS*SMAX\n X = DLAMCH( 'Base' )*EPS\n IF ( TOLREL.LE.X ) TOLREL = X\n THRESH = MAX( TEN, MIN( HNDRD, EPS**MEIGTH ) )*EPS\n SMLNUM = SAFEMN / EPS\n RMIN = SQRT( SMLNUM )\n RMAX = MIN( ONE / RMIN, ONE / SQRT( SQRT( SAFEMN ) ) )\n THETAC = THETA\nC\nC Scale the matrix to allowable range, if necessary, and set PIVMIN,\nC using the squares of Q and E (saved in DWORK).\nC\n IASCL = 0\n IF( SMAX.GT.ZERO .AND. SMAX.LT.RMIN ) THEN\n IASCL = 1\n SIGMA = RMIN / SMAX\n ELSE IF( SMAX.GT.RMAX ) THEN\n IASCL = 1\n SIGMA = RMAX / SMAX\n END IF\n IF( IASCL.EQ.1 ) THEN\n CALL DSCAL( P, SIGMA, Q, 1 )\n CALL DSCAL( P-1, SIGMA, E, 1 )\n THETAC = SIGMA*THETA\n TOLABS = SIGMA*TOLABS\n END IF\nC\n PIVMIN = Q(P)**2\n DWORK(P) = PIVMIN\nC\n DO 40 J = 1, P - 1\n DWORK(J) = Q(J)**2\n DWORK(P+J) = E(J)**2\n PIVMIN = MAX( PIVMIN, DWORK(J), DWORK(P+J) )\n 40 CONTINUE\nC\n PIVMIN = MAX( PIVMIN*SAFEMN, SAFEMN )\nC\nC Initialize U and/or V to the identity matrix, if needed.\nC\n IF ( LJOBUI )\n $ CALL DLASET( 'Full', M, P, ZERO, ONE, U, LDU )\n IF ( LJOBVI )\n $ CALL DLASET( 'Full', N, P, ZERO, ONE, V, LDV )\nC\nC Estimate THETA (if not fixed by the user), and set R.\nC\n IF ( RANK.GE.0 ) THEN\n J = P - RANK\n CALL MB03MD( P, J, THETAC, Q, E, DWORK(1), DWORK(P+1), PIVMIN,\n $ TOLABS, TOLREL, IWARN, INFO1 )\n THETA = THETAC\n IF ( IASCL.EQ.1 ) THETA = THETA / SIGMA\n IF ( J.LE.0 )\n $ RETURN\n R = P - J\n ELSE\n R = P - MB03ND( P, THETAC, DWORK, DWORK(P+1), PIVMIN, INFO1 )\n END IF\nC\n RANK = P\nC\n DO 60 I = 1, P\n IF ( INUL(I) ) RANK = RANK - 1\n 60 CONTINUE\nC\nC From now on K is the smallest known index such that the elements\nC of the bidiagonal matrix J with indices larger than K belong to C1\nC or C2.\nC RANK = P - SUM(dimensions of known bidiagonal matrices of C2).\nC\n K = P\n OLDI = -1\n OLDK = -1\n ITER = 0\n MAXIT = MAXITR*P\nC WHILE ( C3 NOT EMPTY ) DO\n 80 IF ( RANK.GT.R .AND. K.GT.0 ) THEN\nC WHILE ( K.GT.0 .AND. INUL(K) ) DO\nC\nC Search for the rightmost index of a bidiagonal submatrix,\nC not yet classified.\nC\n 100 IF ( K.GT.0 ) THEN\n IF ( INUL(K) ) THEN\n K = K - 1\n GO TO 100\n END IF\n END IF\nC END WHILE 100\nC\n IF ( K.EQ.0 )\n $ RETURN\nC\n NOC12 = .TRUE.\nC WHILE ((ITER < MAXIT).AND.(No bidiagonal matrix of C1 or\nC C2 found)) DO\n 120 IF ( ( ITER.LT.MAXIT ) .AND. NOC12 ) THEN\nC\nC Search for negligible Q(I) or E(I-1) (for I > 1) and find\nC the shift.\nC\n I = K\n X = ABS( Q(I) )\n SHIFT = X\nC WHILE ABS( Q(I) ) > TOLABS .AND. ABS( E(I-1) ) > TOLABS ) DO\n 140 IF ( I.GT.1 ) THEN\n IF ( ( X.GT.TOLABS ).AND.( ABS( E(I-1) ).GT.TOLABS ) )\n $ THEN\n I = I - 1\n X = ABS( Q(I) )\n IF ( X.LT.SHIFT ) SHIFT = X\n GO TO 140\n END IF\n END IF\nC END WHILE 140\nC\nC Classify the bidiagonal submatrix (of order J) found.\nC\n J = K - I + 1\n IF ( ( X.LE.TOLABS ) .OR. ( K.EQ.I ) ) THEN\n NOC12 = .FALSE.\n ELSE\n NUMEIG = MB03ND( J, THETAC, DWORK(I), DWORK(P+I), PIVMIN,\n $ INFO1 )\n IF ( NUMEIG.GE.J .OR. NUMEIG.LE.0 ) NOC12 = .FALSE.\n END IF\n IF ( NOC12 ) THEN\n IF ( J.EQ.2 ) THEN\nC\nC Handle separately the 2-by-2 submatrix.\nC\n CALL DLASV2( Q(I), E(I), Q(K), SIGMN, SIGMX, SINR,\n $ COSR, SINL, COSL )\n Q(I) = SIGMX\n Q(K) = SIGMN\n E(I) = ZERO\n RANK = RANK - 1\n INUL(K) = .TRUE.\n NOC12 = .FALSE.\nC\nC Update U and/or V, if needed.\nC\n IF( LJOBUA )\n $ CALL DROT( M, U(1,I), 1, U(1,K), 1, COSL, SINL )\n IF( LJOBVA )\n $ CALL DROT( N, V(1,I), 1, V(1,K), 1, COSR, SINR )\n ELSE\nC\nC If working on new submatrix, choose QR or\nC QL iteration.\nC\n IF ( I.NE.OLDI .OR. K.NE.OLDK )\n $ QRIT = ABS( Q(I) ).GE.ABS( Q(K) )\n OLDI = I\n IF ( QRIT ) THEN\n IF ( ABS( E(K-1) ).LE.THRESH*ABS( Q(K) ) )\n $ E(K-1) = ZERO\n ELSE\n IF ( ABS( E(I) ).LE.THRESH*ABS( Q(I) ) )\n $ E(I) = ZERO\n END IF\nC\n CALL MB04YW( QRIT, LJOBUA, LJOBVA, M, N, I, K, SHIFT,\n $ Q, E, U, LDU, V, LDV, DWORK(2*P) )\nC\n IF ( QRIT ) THEN\n IF ( ABS( E(K-1) ).LE.TOLABS ) E(K-1) = ZERO\n ELSE\n IF ( ABS( E(I) ).LE.TOLABS ) E(I) = ZERO\n END IF\n DWORK(K) = Q(K)**2\nC\n DO 160 I1 = I, K - 1\n DWORK(I1) = Q(I1)**2\n DWORK(P+I1) = E(I1)**2\n 160 CONTINUE\nC\n ITER = ITER + 1\n END IF\n END IF\n GO TO 120\n END IF\nC END WHILE 120\nC\n IF ( ITER.GE.MAXIT ) THEN\n INFO = 1\n GO TO 200\n END IF\nC\n IF ( X.LE.TOLABS ) THEN\nC\nC Split at negligible diagonal element ABS( Q(I) ) <= TOLABS.\nC\n CALL MB02NY( LJOBUA, LJOBVA, M, N, I, K, Q, E, U, LDU, V,\n $ LDV, DWORK(2*P) )\n INUL(I) = .TRUE.\n RANK = RANK - 1\n ELSE\nC\nC A negligible superdiagonal element ABS( E(I-1) ) <= TOL\nC has been found, the corresponding bidiagonal submatrix\nC belongs to C1 or C2. Treat this bidiagonal submatrix.\nC\n IF ( J.GE.2 ) THEN\n IF ( NUMEIG.EQ.J ) THEN\nC\n DO 180 I1 = I, K\n INUL(I1) = .TRUE.\n 180 CONTINUE\nC\n RANK = RANK - J\n K = K - J\n ELSE\n K = I - 1\n END IF\n ELSE\n IF ( X.LE.( THETAC + TOLABS ) ) THEN\n INUL(I) = .TRUE.\n RANK = RANK - 1\n END IF\n K = K - 1\n END IF\n OLDK = K\n END IF\n GO TO 80\n END IF\nC END WHILE 80\nC\nC If matrix was scaled, then rescale Q and E appropriately.\nC\n 200 CONTINUE\n IF( IASCL.EQ.1 ) THEN\n CALL DSCAL( P, ONE / SIGMA, Q, 1 )\n CALL DSCAL( P-1, ONE / SIGMA, E, 1 )\n END IF\nC\n RETURN\nC *** Last line of MB04YD ***\n END\n", "meta": {"hexsha": "90f787439850f3a2b671b58f76260a816948f8c9", "size": 22921, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB04YD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB04YD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB04YD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 37.5754098361, "max_line_length": 72, "alphanum_fraction": 0.5271585009, "num_tokens": 6824, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9005297967961707, "lm_q2_score": 0.7279754489059774, "lm_q1q2_score": 0.655563583075901}} {"text": "module lambert\n\nimplicit none\n\ndouble precision, parameter :: pi = 3.1415926535897931d0\n\ntype lambertresult\n double precision, dimension(3) :: v0\n double precision, dimension(3) :: v\nend type lambertresult\n\ncontains\n\ntype(lambertresult) function lambertsolver(k, r0, r, tof, short, numiter, rtol)\n double precision, intent(in) :: k\n double precision, dimension(:), intent(in) :: r0\n double precision, dimension(:), intent(in) :: r\n double precision, intent(in) :: tof\n logical, intent(in), optional :: short\n integer, intent(in), optional :: numiter\n double precision, intent(in), optional :: rtol\n\n logical :: short_\n integer :: numiter_\n double precision :: rtol_\n\n double precision :: norm_r0, norm_r, cos_dnu\n double precision :: a, psi, psi_low, psi_up\n double precision :: y, xi, tof_new, g, gdot\n integer :: t_m, counter\n double precision, dimension(3) :: f, v, v0\n\n short_ = .true.\n if (present(short)) short_ = short\n numiter_ = 35\n if (present(numiter)) numiter_ = numiter\n rtol_ = 1e-8\n if (present(rtol)) rtol_ = rtol\n\n if (short_) then\n t_m = 1\n else\n t_m = -1\n end if\n\n norm_r0 = norm2(r0)\n norm_r = norm2(r)\n cos_dnu = dot_product(r0, r) / (norm_r0 * norm_r)\n\n a = t_m * sqrt(norm_r * norm_r0 * (1 + cos_dnu))\n\n if (a == 0d0) then\n write(*,*) \"Cannot compute orbit, phase angle is 180 degrees\"\n stop 1\n end if\n\n psi = 0d0\n psi_low = -4 * pi\n psi_up = 4 * pi\n\n counter = 0\n do while (counter < numiter_)\n y = norm_r0 + norm_r + a * (psi * c3(psi) - 1) / sqrt(c2(psi))\n if (a > 0d0 .and. y < 0d0) then\n do while (y < 0d0)\n psi_low = psi\n psi = (0.8d0 * (1d0 / c3(psi)) * &\n (1d0 - (norm_r0 + norm_r) * sqrt(c2(psi)) / a))\n y = norm_r0 + norm_r + a * (psi * c3(psi) - 1) / sqrt(c2(psi))\n end do\n end if\n xi = sqrt(y / c2(psi))\n tof_new = (xi**3 * c3(psi) + A * sqrt(y)) / sqrt(k)\n\n if (abs((tof_new - tof) / tof) < rtol_) then\n exit\n else\n counter = counter + 1\n if (tof_new <= tof) then\n psi_low = psi\n else\n psi_up = psi\n end if\n psi = (psi_up + psi_low) / 2\n end if\n end do\n\n if (counter > numiter_) then\n write(*,*) \"Maximum number of iterations reached.\"\n stop 1\n end if\n\n f = 1 - y / norm_r0\n g = a * sqrt(y / k)\n gdot = 1 - y / norm_r\n\n v0 = (r - f * r0) / g\n v = (gdot * r - r0) / g\n lambertsolver = lambertresult(v0, v)\nend function lambertsolver\n\ndouble precision function c2(psi)\n double precision, intent(in) :: psi\n\n double precision :: eps\n double precision :: delta\n integer :: k\n\n eps = 1.0\n if (psi > eps) then\n c2 = (1 - cos(sqrt(psi))) / psi\n else if (psi < -eps) then\n c2 = (cosh(sqrt(-psi)) - 1) / (-psi)\n else\n c2 = 1d0 / 2d0\n delta = (-psi) / gamma(2d0 + 2d0 + 1d0)\n k = 1\n do while (c2 + delta /= c2)\n c2 = c2 + delta\n k = k + 1\n delta = (-psi)**k / gamma(2 * k + 2d0 + 1d0)\n end do\n end if\nend function c2\n\ndouble precision function c3(psi)\n double precision, intent(in) :: psi\n\n double precision :: eps\n double precision :: delta\n integer :: k\n\n eps = 1.0\n if (psi > eps) then\n c3 = (sqrt(psi) - sin(sqrt(psi))) / (psi * sqrt(psi))\n else if (psi < -eps) then\n c3 = (sinh(sqrt(-psi)) - sqrt(-psi)) / (-psi * sqrt(-psi))\n else\n c3 = 1d0 / 6d0\n delta = (-psi) / gamma(2d0 + 3d0 + 1d0)\n k = 1\n do while (c3 + delta /= c3)\n c3 = c3 + delta\n k = k + 1\n delta = (-psi) ** k / gamma(2 * k + 3d0 + 1d0)\n end do\n end if\nend function c3\n\nsubroutine benchmark_lambert(times)\n integer, intent(in) :: times\n\n double precision, dimension(3) :: r\n double precision, dimension(3) :: r0\n double precision :: tof\n double precision, parameter :: mu = 3.986004418d5\n type(lambertresult) :: res\n\n double precision :: current, rate\n integer(kind=8) :: start, finish, irate\n double precision :: total, best, worst\n integer :: i\n\n r0 = [5000d0, 10000d0, 2100d0]\n r = [-14600d0, 2500d0, 7000d0]\n tof = 3600d0\n\n worst = -1d20\n best = 1d20\n total = 0d0\n call system_clock(count_rate=irate)\n rate = dble(irate)\n do i=1, times\n call system_clock(start)\n\n res = lambertsolver(mu, r0, r, tof)\n\n call system_clock(finish)\n current = (finish - start)/rate\n if (current < best .and. current > 0) then\n best = current\n end if\n if (current > worst) then\n worst = current\n end if\n total = total + current\n end do\n print *, total/times, best, worst\nend subroutine benchmark_lambert\n\nend module lambert\n", "meta": {"hexsha": "727405bd557eb2c674bd00dd7b80ca391ec1d404", "size": 4991, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/src/lambert.f90", "max_stars_repo_name": "helgee/icatt-2016", "max_stars_repo_head_hexsha": "0fb1012b3639a6d6c53d80cd00b43b72a67b8022", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2016-05-07T19:09:15.000Z", "max_stars_repo_stars_event_max_datetime": "2017-05-06T14:31:44.000Z", "max_issues_repo_path": "fortran/src/lambert.f90", "max_issues_repo_name": "OpenAstrodynamics/benchmarks", "max_issues_repo_head_hexsha": "0fb1012b3639a6d6c53d80cd00b43b72a67b8022", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-05-05T14:36:39.000Z", "max_issues_repo_issues_event_max_datetime": "2017-05-08T09:18:55.000Z", "max_forks_repo_path": "fortran/src/lambert.f90", "max_forks_repo_name": "OpenAstrodynamics/benchmarks", "max_forks_repo_head_hexsha": "0fb1012b3639a6d6c53d80cd00b43b72a67b8022", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-11-09T12:13:04.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-13T14:19:13.000Z", "avg_line_length": 25.9947916667, "max_line_length": 79, "alphanum_fraction": 0.5391705069, "num_tokens": 1645, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178929, "lm_q2_score": 0.7279754489059775, "lm_q1q2_score": 0.6555635753023771}} {"text": "module statistics_module\nuse system_module, only : dp, PRINT_VERBOSE, PRINT_NORMAL, print, current_verbosity, operator(//)\nimplicit none\nprivate\n\npublic :: mean, variance\n\npublic :: mean_var_decorrelated_err\ninterface mean_var_decorrelated_err\n module procedure mean_var_decorrelated_err_r1\nend interface mean_var_decorrelated_err\n\ncontains\n\nsubroutine mean_var_decorrelated_err_r1(A, m, v, decorrelated_err, decorrelation_t)\n real(dp) :: A(:)\n real(dp), optional :: m, v, decorrelated_err, decorrelation_t\n\n integer :: bin_i, bin_size, n_bins, N\n real(dp) :: A_mean, A_var, Nr, A_decorrelation_t\n real(dp), allocatable :: binned_means(:)\n real(dp) :: binned_means_var\n real(dp) :: p_d_t, pp_d_t\n logical :: found_max\n\n N = size(A)\n Nr = N\n\n A_mean = mean(A)\n if (present(m)) m = A_mean\n if (present(v) .or. present(decorrelation_t) .or. present(decorrelated_err)) A_var = variance(A, A_mean)\n if (present(v)) v = A_var\n\n found_max = .false.\n p_d_t = -HUGE(1.0_dp)\n pp_d_t = HUGE(1.0_dp)\n if (present(decorrelation_t) .or. present(decorrelated_err)) then\n bin_size = 1\n do while (bin_size <= N)\n\t n_bins = N/bin_size\n\t allocate(binned_means(n_bins))\n\t do bin_i=1, n_bins\n\t binned_means(bin_i) = mean(A((bin_i-1)*bin_size+1:(bin_i-1)*bin_size+bin_size))\n\t end do\n\t binned_means_var = variance(binned_means, mean(binned_means))\n\t deallocate(binned_means)\n\t A_decorrelation_t = binned_means_var*real(bin_size,dp)/A_var\n\t call print(\"bin_size \" // bin_size // \" decorrelation_t \" // A_decorrelation_t, PRINT_VERBOSE)\n\t if (A_decorrelation_t < p_d_t .and. p_d_t > pp_d_t) then\n\t if (.not. found_max) then\n\t if (present(decorrelation_t)) decorrelation_t = A_decorrelation_t\n\t if (present(decorrelated_err)) decorrelated_err = sqrt(binned_means_var/real(n_bins,dp))\n\t found_max = .true.\n\t endif\n\t if (current_verbosity() <= PRINT_NORMAL) exit\n\t endif\n\t pp_d_t = p_d_t\n\t p_d_t = A_decorrelation_t\n\t if (bin_size == 1) then\n\t bin_size = bin_size * 2\n\t else\n\t bin_size = bin_size * 1.5\n\t endif\n end do\n end if\n\nend subroutine mean_var_decorrelated_err_r1\n\nfunction mean(A)\n real(dp), intent(in) :: A(:)\n real(dp) :: mean\n\n mean = sum(A)/real(size(A),dp)\nend function mean\n\nfunction variance(A, A_mean)\n real(dp), intent(in) :: A(:), A_mean\n real(dp) :: variance\n\n variance = sum((A-A_mean)**2)/real(size(A),dp)\nend function variance\n\nend module statistics_module\n", "meta": {"hexsha": "f48036fdb73ab60a83255e4949c0c47fa73ebd71", "size": 2456, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/libAtoms/statistics.f95", "max_stars_repo_name": "albapa/QUIP", "max_stars_repo_head_hexsha": "ecde1e332c6bd62c238d3cd90e31dba4fb390313", "max_stars_repo_licenses": ["NRL"], "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/libAtoms/statistics.f95", "max_issues_repo_name": "albapa/QUIP", "max_issues_repo_head_hexsha": "ecde1e332c6bd62c238d3cd90e31dba4fb390313", "max_issues_repo_licenses": ["NRL"], "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/libAtoms/statistics.f95", "max_forks_repo_name": "albapa/QUIP", "max_forks_repo_head_hexsha": "ecde1e332c6bd62c238d3cd90e31dba4fb390313", "max_forks_repo_licenses": ["NRL"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.2380952381, "max_line_length": 107, "alphanum_fraction": 0.7027687296, "num_tokens": 740, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181875, "lm_q2_score": 0.7401743735019595, "lm_q1q2_score": 0.6555217212869939}} {"text": "*=======================================================================\n* File: gumbel.F\n* Author: Alex Stivala\n* Created: July 2010\n*\n* Functions to compute z-score and p-value from tableau matching score,\n* according to Gumbel distribution parameters.\n* See thesis Ch. 6 (s6.2.2) and Ortiz et al (2002), \n* Abagyan & Batalov (1997), Versetr0m & Taylor (2006),\n* Kolbeck et al (2006), Levitt & Gerstein (1998).\n*\n* This file contains double precision functions zgumbel and pvgumbel\n* \n* $Id: rdtabd.F 2969 2009-11-22 01:29:39Z astivala $\n*=======================================================================\n\n\n double precision function pvgumbel(z)\n\n implicit none\n*\n* pvgumbel - compute p-value from Gumbel distribution\n*\n* .. Scalar Arguments ..\n double precision z\n*\n*\n* Arguments\n* =========\n*\n* z (input) DOUBLE PRECISION\n* Gumbel z-score from pvgumbel to compute pvalue for\n*\n* Return value\n* ============\n* p-value computed for x according to Gumbel(a,b) distribution\n* \n*=======================================================================\n*\n\n* .. Parameters ..\n double precision pi\n parameter(pi=3.141592653589793D0)\n* Euler-Mascheroni constant\n double precision egamma\n parameter(egamma = 0.5772156649015328606d0)\n* ..\n* .. Local Scalars ..\n* ..\n* .. Local Arrays ..\n* ..\n* .. Intrinsic Functions ..\n intrinsic sqrt,exp\n* ..\n* .. External Subroutines and Functions ..\n* ..\n* .. Executable Statements ..\n* \n pvgumbel = 1.0d0-exp(-1.0d0*exp(-1.0d0*(z*pi/sqrt(6.0d0)+egamma)))\n end\n\n*=======================================================================\n\n\n\n*=======================================================================\n\n double precision function zgumbel(x)\n\n implicit none\n*\n* zgumbel - compute Z-score from Gumbel distribution\n*\n*\n* The Gumbel distribution parameters a and b are estimated by MLE\n* for structures in different folds (see thesis ch.6 (s6.2.2)\n* for query200 in ASTRAL SCOP 1.75 95% nr.\n*\n* .. Scalar Arguments ..\n double precision x\n*\n*\n* Arguments\n* =========\n*\n* x (input) DOUBLE PRECISION\n* Tableau matching score to compute z-score for\n*\n* Return value\n* ============\n* Z-score computed for x according to Gumbel(a,b) distribution\n* \n*=======================================================================\n*\n\n* .. Parameters ..\n double precision pi\n parameter(pi=3.141592653589793D0)\n* Euler-Mascheroni constant\n double precision egamma\n parameter(egamma = 0.5772156649015328606d0)\n* Gumbel distribution location parameter\n double precision a\n parameter(a = 0.4731609844614057d0)\n* Gumbel distribution scale parameter\n double precision b\n parameter(b = 0.44602089192192d0)\n* ..\n* .. Local Scalars ..\n double precision mu\n double precision sigma\n* ..\n* .. Local Arrays ..\n* ..\n* .. Intrinsic Functions ..\n intrinsic sqrt\n* ..\n* .. External Subroutines and Functions ..\n* ..\n* .. Executable Statements ..\n* \n mu = a + b * egamma\n sigma = (pi / sqrt(6.0d0)) * b\n zgumbel = (x - mu) / sigma\n end\n\n", "meta": {"hexsha": "7a0af75fe33ae501bb91809532caf54ebd974b67", "size": 3241, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/gumbel.f", "max_stars_repo_name": "stivalaa/qptabsearch", "max_stars_repo_head_hexsha": "1064672c2b929408975c07decda9478d4bb66f41", "max_stars_repo_licenses": ["MIT"], "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/gumbel.f", "max_issues_repo_name": "stivalaa/qptabsearch", "max_issues_repo_head_hexsha": "1064672c2b929408975c07decda9478d4bb66f41", "max_issues_repo_licenses": ["MIT"], "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/gumbel.f", "max_forks_repo_name": "stivalaa/qptabsearch", "max_forks_repo_head_hexsha": "1064672c2b929408975c07decda9478d4bb66f41", "max_forks_repo_licenses": ["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.5196850394, "max_line_length": 72, "alphanum_fraction": 0.5325516816, "num_tokens": 838, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.885631476836816, "lm_q2_score": 0.7401743563075447, "lm_q1q2_score": 0.6555217082933904}} {"text": "module mod_QCG\r\n implicit none\r\n integer,parameter:: ik=selected_int_kind(11)\r\n integer,parameter:: rk=selected_real_kind(11, 11)\r\n !QCG parameters\r\n integer(kind=ik),parameter:: qcg_m=11, qcg_a=11, qcg_b=1, qcg_c=5\r\n integer(kind=ik):: qcg_seed\r\n\r\ncontains\r\n subroutine seed_qcg(seed)\r\n implicit none\r\n integer(kind=ik), intent(in):: seed\r\n qcg_seed=seed\r\n end subroutine seed_qcg\r\n\r\n real(rk) function rand_qcg()\r\n implicit none\r\n qcg_seed=mod(qcg_a*qcg_seed**2+qcg_b*qcg_seed+qcg_c, qcg_m)\r\n rand_qcg=real(qcg_seed, rk)/real(qcg_m, rk)\r\n end function rand_qcg \r\nend module\r\n\r\nprogram ex2p1\r\n use mod_QCG\r\n implicit none\r\n integer(kind=ik)::i\r\n real(kind=rk)::x0, x\r\n !Set seed\r\n call seed_qcg(int(345343, ik))\r\n\r\n !First value\r\n x0=rand_qcg()\r\n print*, x0\r\n i=1\r\n do \r\n x=rand_qcg()\r\n print*,x\r\n if (x==x0) exit\r\n i=i+1\r\n end do\r\n print*, \"QCG repeat interval:\",i\r\nend program ex2p1", "meta": {"hexsha": "e46efdc3c39369ebc3050b6e3774d40d2b2d5f8c", "size": 1029, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Nico_Toikka_ex2/p01/mod_qcg.f95", "max_stars_repo_name": "toicca/basics-of-mc", "max_stars_repo_head_hexsha": "71f2fc2ac4252c359a6c6bbf46d9bac743aaec25", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Nico_Toikka_ex2/p01/mod_qcg.f95", "max_issues_repo_name": "toicca/basics-of-mc", "max_issues_repo_head_hexsha": "71f2fc2ac4252c359a6c6bbf46d9bac743aaec25", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Nico_Toikka_ex2/p01/mod_qcg.f95", "max_forks_repo_name": "toicca/basics-of-mc", "max_forks_repo_head_hexsha": "71f2fc2ac4252c359a6c6bbf46d9bac743aaec25", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.5, "max_line_length": 70, "alphanum_fraction": 0.6015549077, "num_tokens": 323, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554445, "lm_q2_score": 0.7401743505760728, "lm_q1q2_score": 0.65552170545173}} {"text": "\tFUNCTION PR_HGSF ( hgml )\nC************************************************************************\nC* PR_HGSF\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes HGFT from HGML. 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* HGFT = HGML * 5280\t \t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PR_HGSF ( HGML )\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*\tHGML\t\tREAL\t \tHeight in statute miles \t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPR_HGSF\t\tREAL\t\tHeight in feet \t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* S. Schotz \t10/89\tOriginal source\t\t\t\t*\nC* J. Whistler/SSAI\t 7/91\tChanged hght to hgml in ERMISS check\t*\nC************************************************************************\n INCLUDE 'GEMPRM.PRM'\n INCLUDE 'ERMISS.FNC'\nC------------------------------------------------------------------------\nC*\tCheck for missing values.\nC\t\n\tIF ( ERMISS ( hgml ) ) THEN\n\t PR_HGSF = RMISSD\n\t ELSE\n\t PR_HGSF = hgml * 5280.\n\tEND IF\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "bc600e36b20cce9d43d7c832dec0acfe83490dfd", "size": 1000, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/pr/prhgsf.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/prhgsf.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/prhgsf.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": 28.5714285714, "max_line_length": 73, "alphanum_fraction": 0.406, "num_tokens": 298, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181875, "lm_q2_score": 0.7401743505760728, "lm_q1q2_score": 0.6555217009831072}} {"text": " SUBROUTINE FTEST(DATA1,N1,DATA2,N2,F,PROB)\n DIMENSION DATA1(N1),DATA2(N2)\n CALL AVEVAR(DATA1,N1,AVE1,VAR1)\n CALL AVEVAR(DATA2,N2,AVE2,VAR2)\n IF(VAR1.GT.VAR2)THEN\n F=VAR1/VAR2\n DF1=N1-1\n DF2=N2-1\n ELSE\n F=VAR2/VAR1\n DF1=N2-1\n DF2=N1-1\n ENDIF\n PROB = BETAI(0.5*DF2,0.5*DF1,DF2/(DF2+DF1*F))\n * +(1.-BETAI(0.5*DF1,0.5*DF2,DF1/(DF1+DF2/F)))\n RETURN\n END\n", "meta": {"hexsha": "6f937e117c572464bc1b4950603c3c4ae533d76b", "size": 449, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "Math3/NumRec/source/ftest.for", "max_stars_repo_name": "domijin/MM3", "max_stars_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Math3/NumRec/source/ftest.for", "max_issues_repo_name": "domijin/MM3", "max_issues_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Math3/NumRec/source/ftest.for", "max_forks_repo_name": "domijin/MM3", "max_forks_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.9444444444, "max_line_length": 54, "alphanum_fraction": 0.5300668151, "num_tokens": 207, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9161096158798117, "lm_q2_score": 0.7154240079185318, "lm_q1q2_score": 0.6554068130854415}} {"text": "!{\\src2tex{textfont=tt}}\n!!****f* ABINIT/sg_fft\n!! NAME\n!! sg_fft\n!!\n!! FUNCTION\n!! Calculates the discrete fourier transform\n!! ftarr(i1,i2,i3)=exp(ris*i*2*pi*(j1*i1/n1+j2*i2/n2+j3*i3/n3)) arr(j1,j2,j3)\n!!\n!! COPYRIGHT\n!! Copyright by Stefan Goedecker, Ithaca, NY USA, July 14, 1993\n!! Copyright (C) 1998-2001 ABINIT group (DCA, XG)\n!! This file is distributed under the terms of the\n!! GNU General Public License, see ~ABINIT/Infos/copyright\n!! or http://www.gnu.org/copyleft/gpl.txt .\n!!\n!! INPUTS\n!! arr(2,nd1,nd2,nd3)=input complex array with alternating real and imaginary\n!! elements; data resides in 2*n1*n2*n3 of this array, spread out.\n!! fftcache=size of the cache (kB)\n!! nd1,nd2,nd3=memory dimension of arr and ftarr\n!! n1,n2,n3=physical dimension of the transform\n!! ris=(real(dp)) sign of exponential in transform\n!!\n!! OUTPUT\n!! ftarr(2,nd1,nd2,nd3)=working space for transform and contains output\n!!\n!! SIDE EFFECTS\n!!\n!! NOTES\n!! ndi must always be greater or equal to ni. Recommended choice for nd1\n!! and nd2 is: ni for ni=odd or ni+1 for ni=even (hence 2*(ni/2)+1);\n!! nd3 should always be n3. Note that choosing nd1 or nd2 larger than\n!! the recommended value can severely degrade efficiency of this routine.\n!! Avoiding even ndi for nd1 and nd2 avoids cache conflicts on cache machines.\n!! Each of n1,n2,n3 must be a\n!! product of the prime factors 2,3,5. If two ni s are equal\n!! it is recommended to place them behind each other.\n!! The largest any of these may be is set by parameter \"mg\" below.\n!! This fft is particularly efficient for cache architectures.\n!! Note that the meaning of fftcache has changed from the original\n!! ncache of SG (that was the maximum number of COMPLEX*16 in the cache)\n!!\n!! TODO\n!! Use latex for the equation above\n!!\n!! PARENTS\n!! ccfft\n!!\n!! SOURCE\n\n subroutine sg_fft(fftcache,nd1,nd2,nd3,n1,n2,n3,arr,ftarr,ris) \n \n use basis_defs\n implicit none \n\n!Arguments ------------------------------------\n integer :: fftcache,nd1,nd2,nd3,n1,n2,n3\n real(dp) :: ris\n real(dp) :: arr(2,nd1,nd2,nd3),ftarr(2,nd1,nd2,nd3)\n\n!Local variables-------------------------------\n!mfac sets maximum number of factors (5, 4, 3, or 2) which may be \n!contained within any n1, n2, or n3\n!mg sets the maximum 1 dimensional fft length (any one of n1, n2, or n3)\n integer, parameter :: mfac=11,mg=2048\n integer :: ic,i2,nd13,nd23,n1i,n12,n2i,n23,n3i\n integer :: aft(mfac),bef(mfac),ind(mg),now(mfac)\n real(dp) :: trig(2,mg)\n character :: message*500\n\n! *************************************************************************\n \n!Check that dimension is not exceeded\n if (n1>mg.or.n2>mg.or.n3>mg) then\n write(message, '(a,a,a,a,3i10,a,i10,a)' ) ch10,&\n& ' sg_fft : BUG -',ch10,&\n& ' one of the dimensions n1,n2,n3=',n1,n2,n3,&\n& ' exceeds allowed dimension mg=',mg,ch10\n! call wrtout(06,message,'PERS')\n! call leave_new('PERS')\n endif\n \n!transform along x direction\n call sg_ctrig(n1,trig,aft,bef,now,ris,ic,ind,mfac,mg)\n call sg_fftx(fftcache,mfac,mg,nd1,nd2,nd3,n2,n3,&\n& arr,ftarr,trig,aft,now,bef,ris,ind,ic)\n \n!transform along y direction\n if (n2/=n1)then\n call sg_ctrig(n2,trig,aft,bef,now,ris,ic,ind,mfac,mg)\n endif\n n1i=1 ; n3i=1\n call sg_ffty(fftcache,mfac,mg,nd1,nd2,nd3,n1i,n1,n3i,n3,&\n& ftarr,arr,trig,aft,now,bef,ris,ind,ic)\n \n!transform along z direction\n if (n3/=n2)then\n call sg_ctrig(n3,trig,aft,bef,now,ris,ic,ind,mfac,mg)\n endif\n\n!$OMP PARALLEL DO SHARED(aft,arr,bef,fftcache,ftarr,ind,ic)&\n!$OMP&SHARED(nd1,nd2,nd3,now,n1,n2,ris,trig)&\n!$OMP&PRIVATE(i2)\n do i2=1,n2\n call sg_fftz(fftcache,mfac,mg,nd1,nd2,nd3,n1,i2,i2,arr,ftarr,&\n& trig,aft,now,bef,ris,ind,ic)\n enddo\n!$OMP END PARALLEL DO\n\n end subroutine\n!!***\n", "meta": {"hexsha": "301151d2c5e2886c6d210d3517acf3e4545d2ca8", "size": 3707, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "benchees/goedecker/sg_fft.f90", "max_stars_repo_name": "mreineck/benchfft", "max_stars_repo_head_hexsha": "6c754dca9f53f16886a71744199a0bbce40b3e1a", "max_stars_repo_licenses": ["ImageMagick"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2019-08-11T02:13:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T01:31:41.000Z", "max_issues_repo_path": "benchees/goedecker/sg_fft.f90", "max_issues_repo_name": "mreineck/benchfft", "max_issues_repo_head_hexsha": "6c754dca9f53f16886a71744199a0bbce40b3e1a", "max_issues_repo_licenses": ["ImageMagick"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2020-12-01T18:15:43.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-21T21:39:55.000Z", "max_forks_repo_path": "benchees/goedecker/sg_fft.f90", "max_forks_repo_name": "mreineck/benchfft", "max_forks_repo_head_hexsha": "6c754dca9f53f16886a71744199a0bbce40b3e1a", "max_forks_repo_licenses": ["ImageMagick"], "max_forks_count": 9, "max_forks_repo_forks_event_min_datetime": "2020-06-02T08:44:13.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-26T11:50:36.000Z", "avg_line_length": 32.8053097345, "max_line_length": 79, "alphanum_fraction": 0.6725114648, "num_tokens": 1290, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096135894201, "lm_q2_score": 0.7154239836484143, "lm_q1q2_score": 0.6554067892127524}} {"text": "!***********************************/\n!\tName:\u5c40\u6240\u6642\u9593\u523b\u307f\u5e45\u7528\u306e\u6642\u9593\u523b\u307f\u8a08\u7b97\u30d7\u30ed\u30b0\u30e9\u30e0\n!\tAlias:UCalcTimeWidth\n!\tDescription:\n!\tType:\n!\tInput:\n!\tOutput:\n!\tNote:\n!\tAuthor:Akitaka Toyota\n!\tDate:2018.01.22\n!\tUpdate:\n!\tOther:\n!***********************************/\nsubroutine JPUCalcTimeWidth(UG,CC)\nuse StructVar_Mod\nuse LoopVar_Mod\nuse ConstantVar_Mod, Gamma => SpecificOfHeatRatio, CFL => CourantFriedrichsLewyCondition\nimplicit none\n type(UnstructuredGrid),intent(in) :: UG\n type(CellCenter), intent(inout) :: CC\n type(CalcTimeWidthWithOMP) :: CTW\n\n do iCell = 1, UG%GI%RealCells\n CTW%AbsoluteVelocity2 = dot_product(CC%ConservedQuantity(2:4,iCell,1,1),CC%ConservedQuantity(2:4,iCell,1,1))/(CC%ConservedQuantity(1,iCell,1,1)**2) !\u901f\u5ea6L2\u30ce\u30eb\u30e0\n\n if(Gamma*Gmin1*(CC%ConservedQuantity(5,iCell,1,1) / CC%ConservedQuantity(1,iCell,1,1) &\n & - 0.5d0 * CTW%AbsoluteVelocity2) < 0.0d0) then\n write(6,*) \"CalcTimeWidth, Error \"\n write(6,*) iCell\n write(6,*) CC%ConservedQuantity(1,iCell,1,1),CC%ConservedQuantity(5,iCell,1,1)\n write(6,*) CTW%AbsoluteVelocity2\n !stop\n end if\n\n CTW%LocalSoundSpeed = sqrt(Gamma*Gmin1*(CC%ConservedQuantity(5,iCell,1,1) / CC%ConservedQuantity(1,iCell,1,1) &\n & - 0.5d0 * CTW%AbsoluteVelocity2)) !\u5c40\u6240\u97f3\u901f\n\n CTW%AbsoluteVelocity = sqrt(CTW%AbsoluteVelocity2) !\u901f\u5ea6\u7d76\u5bfe\u5024\n\n CC%TmpTimeWidth(iCell,1,1,1) = CFL*UG%InscribedCircle(iCell) / (CTW%LocalSoundSpeed + CTW%AbsoluteVelocity) !\u885d\u6483\u6ce2\u304c\u901a\u904e\u3059\u308b\u901f\u5ea6(\u306e\u534a\u5206\u304f\u3089\u3044)\n end do\n\n do iCell = UG%GI%RealCells+1, UG%GI%AllCells\n CC%TmpTimeWidth(iCell,1,1,1) = CC%TmpTimeWidth(UG%VC%Cell(iCell,1),1,1,1)\n end do\n\n do iCell = 1, UG%GI%RealCells\n CC%TimeWidth(iCell,1,1) = 0.5d0*min(CC%TmpTimeWidth(iCell,1,1,1),CC%TmpTimeWidth(UG%Tri%Cell(iCell,1),1,1,1),&\n & CC%TmpTimeWidth(UG%Tri%Cell(iCell,2),1,1,1),CC%TmpTimeWidth(UG%Tri%Cell(iCell,3),1,1,1))\n end do\n\n return\nend subroutine JPUCalcTimeWidth\n", "meta": {"hexsha": "944c9803b581e6841c981d25a17a68fbcc60ea19", "size": 2045, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "flow_solver/EulerSolver2_2018/source/Routine4JobParallel/JPUnstTimeIntegral/JPUCalcTimeWidth.f90", "max_stars_repo_name": "Mayu14/2D_comp_viscos", "max_stars_repo_head_hexsha": "a62633d8684b218b52e39d47a13717a1edfa4a46", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-05-08T18:00:28.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-08T18:00:28.000Z", "max_issues_repo_path": "flow_solver/EulerSolver2_2018/source/Routine4JobParallel/JPUnstTimeIntegral/JPUCalcTimeWidth.f90", "max_issues_repo_name": "Mayu14/2D_comp_viscos", "max_issues_repo_head_hexsha": "a62633d8684b218b52e39d47a13717a1edfa4a46", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "flow_solver/EulerSolver2_2018/source/Routine4JobParallel/JPUnstTimeIntegral/JPUCalcTimeWidth.f90", "max_forks_repo_name": "Mayu14/2D_comp_viscos", "max_forks_repo_head_hexsha": "a62633d8684b218b52e39d47a13717a1edfa4a46", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-02-20T09:26:27.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-20T09:26:27.000Z", "avg_line_length": 37.8703703704, "max_line_length": 164, "alphanum_fraction": 0.6254278729, "num_tokens": 759, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107896491796, "lm_q2_score": 0.6992544210587585, "lm_q1q2_score": 0.6553487881261589}} {"text": "!**********************************************************************\n! LICENSED MATERIALS - PROPERTY OF IBM *\n! \"RESTRICTED MATERIALS OF IBM\" *\n! *\n! 5765-422 *\n! 5765-C41 *\n! (C) COPYRIGHT IBM CORP. 1995, 1997. ALL RIGHTS RESERVED. *\n! *\n! U.S. GOVERNMENT USERS RESTRICTED RIGHTS - USE, DUPLICATION *\n! OR DISCLOSURE RESTRICTED BY GSA ADP SCHEDULE CONTRACT WITH *\n! IBM CORP. *\n!**********************************************************************\n\tprogram image\n use putilities\n implicit none\n!\n! This is a simple example program showing the real to complex\n! and complex to real Fourier transforms.\n! \n! It well known that a the following correlation \n! \n! C(x,y) = FTINV(H(u,v)*G(u,v))\n!\n! where H is the 2-d Fourier transform of a target image h(x,y)\n! G is the complex conjugate of the 2-d Fourier transform of \n! a refererence image g(x,y)\n! and FTINV represents the 2d inverse Fourier transform\n! provides a measure of the similarity between the images. If the resulting\n! correlation has no peak the images have little in common. The size\n! and location of any peak in C(x,y) provides information on how similar\n! the target image is to the reference image and to any rotation or\n! scale changes of the reference image to the target image.\n!\n! Subroutines call:\n! array_create from the utilitity library\n! blacs_pinfo from the blacs library\n! pcrft2 from pessl\n! prcft2 from pessl\n!\n integer, parameter :: xsize=1024, ysize=1024\n real(long_t), pointer :: target_image(:,:), ref_image(:,:)\n real(long_t), pointer :: correlation(:,:)\n complex(long_t), pointer :: target_xform(:,:), ref_xform(:,:)\n complex(long_t), pointer :: correlation_xform(:,:)\n complex(long_t), pointer :: frow1(:),frow2(:),lrow1(:),lrow2(:)\n integer :: ip(40)\n integer :: desc(DESC_DIM) ! dummy descriptor \n integer :: iam, nprocs, status, i, j\n\n!\n! create interface block for all subroutines which follow\n!\n INTERFACE\n\n subroutine unpack(xform,frow,lrow)\n use putilities\n complex(long_t), intent(out) :: frow(:), lrow(:)\n complex(long_t), intent(in) :: xform(:,:)\n end subroutine unpack\n\n subroutine pack(xform,frow,lrow)\n use putilities\n complex(long_t), intent(in) :: frow(:), lrow(:)\n complex(long_t), intent(out) :: xform(:,:)\n end subroutine pack\n\n subroutine filter(image)\n use putilities\n implicit none\n complex(long_t), intent(inout) :: image(:,:)\n end subroutine filter\n \n\n subroutine get_target_image(image)\n use putilities\n implicit none\n real(long_t), intent(inout) :: image(:,:)\n end subroutine get_target_image\n \n\n subroutine get_ref_image(image)\n use putilities\n implicit none\n real(long_t), intent(inout) :: image(:,:)\n end subroutine get_ref_image\n \n\n END INTERFACE\n\n\n!\n! initialize system\n!\n call blacs_pinfo(iam,nprocs)\n call initutils(status,npcs=nprocs)\n!\n! check that the number of processors evenly divide ysize and xsize/2\n!\n if ( xsize .ne. 2*nprocs*(xsize/(2*nprocs)) ) then\n if( iam.eq.0) then\n write(*,*)'2*nprocs must evenly divide xsize'\n endif\n call blacs_abort(p_context(),1)\n endif\n\n if ( ysize .ne. nprocs*(ysize/nprocs) ) then\n if( iam.eq.0) then\n write(*,*)'nprocs must evenly divide ysize'\n endif\n call blacs_abort(p_context(),1)\n endif\n\n if( status .ne. 0 ) then\n if(iam.eq.0)write(*,*) 'communication initilization failure'\n call blacs_abort(p_context(),1)\n endif\n\n!\n! allocate data for images\n!\n\n call array_create(target_image,desc,xsize,ysize,CREATE_BLOCK)\n call array_create(ref_image,desc,xsize,ysize,CREATE_BLOCK)\n call array_create(correlation,desc,xsize,ysize,CREATE_BLOCK)\n call array_create(target_xform,desc,ysize,xsize/2,CREATE_BLOCK)\n call array_create(ref_xform,desc,ysize,xsize/2,CREATE_BLOCK)\n call array_create(correlation_xform,desc,ysize,xsize/2, &\n & CREATE_BLOCK)\n\n!\n! get the target image\n!\n call get_target_image(target_image)\n!\n! use default values\n!\n ip = 0\n \n!\n! call 2d Fourier real to complex transform\n!\n call pdrcft2(target_image,target_xform,xsize,ysize,1,1.d0, &\n & p_context(),ip)\n\n call filter(target_xform)\n\n!\n! get the reference image\n!\n call get_ref_image(ref_image)\n!\n! call 2d Fourier real to complex transform\n!\n call pdrcft2(ref_image,ref_xform,xsize,ysize,1,1.d0, &\n & p_context(),ip)\n\n!\n! multiply the two xforms together to get the correlation xform\n!\n\n if(iam .eq. 0 ) then\n!\n! processor 0 will have the first and last column stored in \n! packed format \n!\n allocate(frow1(ysize))\n allocate(frow2(ysize))\n allocate(lrow1(ysize))\n allocate(lrow2(ysize))\n\n!\n! unpack target transform\n!\n call unpack(target_xform,frow1,lrow1)\n call unpack(ref_xform,frow2,lrow2)\n \n do i = 1, ysize\n frow1(i) = frow1(i) * conjg(frow2(i))\n lrow1(i) = lrow1(i) * conjg(lrow2(i))\n enddo\n\n do j = 2, xsize/(2*nprocs)\n do i = 1, ysize\n correlation_xform(i,j) = target_xform(i,j) * &\n & conjg(ref_xform(i,j))\n enddo\n enddo\n\n call pack(correlation_xform,frow1,lrow1)\n deallocate(frow1)\n deallocate(frow2)\n deallocate(lrow1)\n deallocate(lrow2)\n\n else ! My processor doesn't have the messy row\n\n do j = 1, xsize/(2*nprocs)\n do i = 1, ysize\n correlation_xform(i,j) = target_xform(i,j) * &\n & conjg(ref_xform(i,j))\n enddo\n enddo\n endif\n\n!\n! correlation_xform now has the 2d transform of the image corrlation\n!\n call pdcrft2(correlation_xform,correlation,xsize,ysize, &\n & -1, 1.d0/(xsize*ysize),p_context(),ip)\n\n!\n! correlation now has the correlation array\n!\n if(iam .eq. 0) then\n write(*,*)'The 1,1 correlation element is ', correlation(1,1)\n endif\n\n!\n! clean up space\n!\n deallocate(target_image)\n deallocate(ref_image)\n deallocate(correlation)\n deallocate(target_xform)\n deallocate(ref_xform)\n deallocate(correlation_xform)\n!\n! end blacs\n!\n call exitutils(0)\n \n!\n! end program\n!\n stop\n end \n\n!\n! subroutine to unpack row 1 and row n2/2 + 1 of a complex\n! transform in packed format\n!\n subroutine unpack(xform,frow,lrow)\n use putilities\n implicit none\n complex(long_t), intent(out) :: frow(:), lrow(:)\n complex(long_t), intent(in) :: xform(:,:)\n!\n! input:\n! xform :: the transform in packed format\n! frow :: first row of transform in unpacked format\n! lrow :: last row of transform in unpacked format\n! note: This routine should be only called from the first processor\n! since only processor 0 will have the packed row of the\n! transform\n!\n!\n integer :: ysize, i, j\n\n ysize = size(xform,1)\n if( size(frow) .ne. ysize .or. size(lrow) .ne. ysize) then \n write(*,*) 'size mismatch in unpack'\n call blacs_abort(p_context(),1)\n endif\n\n!\n! unpack the first row \n! rows appear to be columns because the transformed array\n! is stored in transpose format\n!\n frow(1) = real(xform(1,1))\n frow(ysize/2+1) = imag(xform(1,1))\n frow(2:ysize/2) = xform(2:ysize/2,1)\n frow(ysize/2+2:ysize) = conjg(frow(2:ysize/2))\n\n!\n! unpack the last row \n!\n lrow(1) = real(xform(ysize/2+1,1))\n lrow(ysize/2+1) = imag(xform(ysize/2+1,1))\n lrow(2:ysize/2) = xform(ysize/2+2:ysize,1)\n lrow(ysize/2+2:ysize) = conjg(lrow(2:ysize/2))\n return\n end subroutine unpack\n\n\n!\n! subroutine to pack row 1 and row n2/2 + 1 of a complex\n! transform into packed format\n!\n subroutine pack(xform,frow,lrow)\n use putilities\n implicit none\n complex(long_t), intent(in) :: frow(:), lrow(:)\n complex(long_t), intent(out) :: xform(:,:)\n!\n! input:\n! xform :: the transform in packed format\n! frow :: first row of transform in unpacked format\n! lrow :: last row of transform in unpacked format\n! note: This routine should be only called from the first processor\n! since only processor 0 will have the packed row of the\n! transform\n!\n!\n integer :: ysize, i, j\n\n ysize = size(xform,1)\n if( size(frow) .ne. ysize .or. size(lrow) .ne. ysize) then \n write(*,*) 'size mismatch in unpack'\n call blacs_abort(p_context(),1)\n endif\n\n!\n! pack the first row \n! rows appear to be columns because the transformed array\n! is stored in transpose format\n!\n xform(1,1) = cmplx(real(frow(1)),real(frow(ysize/2+1)))\n xform(2:ysize/2,1) = frow(2:ysize/2)\n\n!\n! pack the last row \n!\n xform(ysize/2+1,1) = cmplx(real(lrow(1)),real(lrow(ysize/2+1)))\n xform(ysize/2+2:ysize,1) = lrow(2:ysize/2)\n return\n end subroutine pack\n\n subroutine get_target_image(image)\n use putilities\n implicit none\n real(long_t), intent(out) :: image(:,:)\n integer i, j\n\n!\n! get a target image\n!\n\n image = 0.d0\n\n!\n! create a horizontal bar\n!\n do j = 1, size(image,2)\n do i = size(image,1)/3, size(image,1)/2\n image(i,j) = 1.d0\n enddo\n enddo\n return\n end subroutine get_target_image\n\n subroutine get_ref_image(image)\n use putilities\n implicit none\n real(long_t), intent(out) :: image(:,:)\n integer i, j\n\n!\n! get a reference image\n!\n\n image = 0.d0\n\n!\n! create a horizontal bar\n!\n do j = 1, size(image,2)\n do i = size(image,1)/3, size(image,1)/2\n image(i,j) = 1.d0\n enddo\n enddo\n return\n end subroutine get_ref_image\n\n subroutine filter(image)\n use putilities\n implicit none\n complex(long_t), intent(inout) :: image(:,:)\n\n!\n! apply any sort of image filter\n! in this case, we have a null routine\n!\n\n return\n end subroutine filter\n\n\n\n", "meta": {"hexsha": "e697a7fa593d893d54bdfadbe0611b7353ab181c", "size": 11090, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "power_pessl/image.f", "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": "power_pessl/image.f", "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": "power_pessl/image.f", "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.4358974359, "max_line_length": 79, "alphanum_fraction": 0.5589720469, "num_tokens": 2936, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.86153820232079, "lm_q2_score": 0.760650658103136, "lm_q1q2_score": 0.6553296005763017}} {"text": "! !------------------------------------------------------------------\n! module rand_fun\n\n! implicit none \n! private\n! integer :: idum \n\n! public :: set_seed, poidev, ran1\n\n! contains \n \n! subroutine set_seed(seed)\n! implicit none \n! integer :: seed\n! idum = seed\n! end subroutine set_seed\n\n! function poidev(xm)\n! implicit none\n! double precision poidev, xm, pi\n! parameter (pi=3.141592654d0)\n! double precision alxm, em, g, oldm, sq, t, y!, gammln, ran1\n! save alxm, g, oldm, sq\n! data oldm /-1./\n\n! if (xm .lt. 12) then\n! if(xm .ne. oldm) then\n! oldm = xm\n! g = exp(-xm)\n! end if\n! em = -1.\n! t = 1.\n! 2 em = em + 1.\n! t = t * ran1()\n! if( t .gt. g) goto 2\n! else\n! if(xm .ne. oldm)then\n! oldm = xm\n! sq = sqrt(2.d0 * xm)\n! alxm = log(xm)\n! g = xm * alxm - gammln( xm + 1.)\n! end if\n! 1 y = tan(pi * ran1())\n! em = sq * y + xm\n! if(em .lt. 0.d0) goto 1\n! em = int(em)\n! t = 0.9d0*(1. + y**2.) * exp(em * alxm - gammln(em + 1.d0) - g)\n! if(ran1() .gt. t) goto 1\n! end if\n! poidev = em\n! return \n! end function poidev\n\n \n! FUNCTION gammln(xx)\n! implicit none \n! DOUBLE PRECISION gammln, xx\n! INTEGER j\n! DOUBLE PRECISION ser, stp, tmp, x, y, cof(6)\n! SAVE cof,stp\n! DATA cof, stp / 76.18009172947146d0, -86.50532032941677d0, 24.01409824083091d0, &\n! -1.231739572450155d0, 0.1208650973866179d-2, -0.5395239384953d-5, 2.5066282746310005d0/\n! x = xx\n! y = x\n! tmp = x + 5.5d0\n! tmp = (x + 0.5d0) * log(tmp) - tmp\n! ser = 1.000000000190015d0\n! do 11 j = 1, 6\n! y = y + 1.d0\n! ser = ser +cof(j) / y\n! 11 continue\n! gammln = real(tmp + log(stp * ser / x))\n! return\n! END function gammln\n\n! FUNCTION ran1()\n! implicit none \n! INTEGER IA,IM,IQ,IR,NTAB,NDIV\n! DOUBLE PRECISION ran1,AM,EPS,RNMX\n! PARAMETER (IA=16807,IM=2147483647,AM=1./IM,IQ=127773,IR=2836,&\n! NTAB=32,NDIV=1+(IM-1)/NTAB,EPS=1.2e-7,RNMX=1.-EPS)\n! INTEGER j,k,iv(NTAB),iy\n! SAVE iv,iy\n! DATA iv /NTAB*0/, iy /0/\n! if (idum.le.0.or.iy.eq.0) then\n! idum=max(-idum,1)\n! do 11 j=NTAB+8,1,-1\n! k=idum/IQ\n! idum=IA*(idum-k*IQ)-IR*k\n! if (idum.lt.0) idum=idum+IM\n! if (j.le.NTAB) iv(j)=idum\n! 11 continue\n! iy=iv(1)\n! endif\n! k=idum/IQ\n! idum=IA*(idum-k*IQ)-IR*k\n! if (idum.lt.0) idum=idum+IM\n! j=1+iy/NDIV\n! iy=iv(j)\n! iv(j)=idum\n! ran1=min(AM*iy,RNMX)\n! return\n! END function ran1\n\n! end module rand_fun\n! !----------------------------------------------------------------\n\n\n\n\n\n! !------------------------------------------------------------------\n! module rand_fun_real\n\n! implicit none \n! private\n! integer :: idum \n\n! public :: set_seed_real, poidev_real, ran1_real\n\n! contains \n \n! subroutine set_seed_real(seed)\n! implicit none \n! integer :: seed\n! idum = seed\n! end subroutine set_seed_real\n \n! function poidev_real(xm)\n! implicit none\n! real poidev_real, xm, pi\n! parameter (pi=3.141592654)\n! real alxm, em, g, oldm, sq, t, y!, gammln, ran1\n! save alxm, g, oldm, sq\n! data oldm /-1./\n\n! if (xm .lt. 12) then\n! if(xm .ne. oldm) then\n! oldm = xm\n! g = exp(-xm)\n! end if\n! em = -1.\n! t = 1.\n! 2 em = em + 1.\n! t = t * ran1_real()\n! if( t .gt. g) goto 2\n! else\n! if(xm .ne. oldm)then\n! oldm = xm\n! sq = sqrt(2. * xm)\n! alxm = log(xm)\n! g = xm * alxm - gammln_real( xm + 1.)\n! end if\n! 1 y = tan(pi * ran1_real())\n! em = sq * y + xm\n! if(em .lt. 0.) goto 1\n! em = int(em)\n! t = 0.9*(1. + y**2.) * exp(em * alxm - gammln_real(em + 1.) - g)\n! if(ran1_real() .gt. t) goto 1\n! end if\n! poidev_real = em\n! return\n! end function poidev_real\n\n \n! FUNCTION gammln_real(xx)\n! implicit none \n! REAL gammln_real, xx\n! INTEGER j\n! DOUBLE PRECISION ser, stp, tmp, x, y, cof(6)\n! SAVE cof,stp\n! DATA cof, stp / 76.18009172947146d0, -86.50532032941677d0, 24.01409824083091d0, &\n! -1.231739572450155d0, 0.1208650973866179d-2, -0.5395239384953d-5, 2.5066282746310005d0/\n! x = xx\n! y = x\n! tmp = x + 5.5d0\n! tmp = (x + 0.5d0) * log(tmp) - tmp\n! ser = 1.000000000190015d0\n! do 11 j = 1, 6\n! y = y + 1.d0\n! ser = ser +cof(j) / y\n! 11 continue\n! gammln_real = real(tmp + log(stp * ser / x))\n! return\n! END function gammln_real\n\n! FUNCTION ran1_real()\n! implicit none \n! INTEGER IA,IM,IQ,IR,NTAB,NDIV\n! REAL ran1_real,AM,EPS,RNMX\n! PARAMETER (IA=16807,IM=2147483647,AM=1./IM,IQ=127773,IR=2836,&\n! NTAB=32,NDIV=1+(IM-1)/NTAB,EPS=1.2e-7,RNMX=1.-EPS)\n! INTEGER j,k,iv(NTAB),iy\n! SAVE iv,iy\n! DATA iv /NTAB*0/, iy /0/\n! if (idum.le.0.or.iy.eq.0) then\n! idum=max(-idum,1)\n! do 11 j=NTAB+8,1,-1\n! k=idum/IQ\n! idum=IA*(idum-k*IQ)-IR*k\n! if (idum.lt.0) idum=idum+IM\n! if (j.le.NTAB) iv(j)=idum\n! 11 continue\n! iy=iv(1)\n! endif\n! k=idum/IQ\n! idum=IA*(idum-k*IQ)-IR*k\n! if (idum.lt.0) idum=idum+IM\n! j=1+iy/NDIV\n! iy=iv(j)\n! iv(j)=idum\n! ran1_real=min(AM*iy,RNMX)\n! return\n! END function ran1_real\n\n! end module rand_fun_real\n! !----------------------------------------------------------------\n\n\n! module rand\n! implicit none \n\n! public :: funUniformSingle, funPoissonSingle\n\n! contains \n\n! !START Function definitions\n! !Uniform function -- returns a standard uniform random variable\n! function funUniformSingle() result(randUni)\n! implicit none\n! real randUni\n! call random_seed\n! call random_number(randUni) \n! end function funUniformSingle\n\n! !Poisson function -- returns a single Poisson random variable\n! function funPoissonSingle(lambda) result(randPoisson)\n! implicit none\n! real, intent(in) :: lambda !input\n! real :: exp_lambda !constant for terminating loop\n! real :: randUni !uniform variable \n! real :: prodUni !product of uniform variables\n! integer :: randPoisson !Poisson variable\n\n! !declare functions\n! real funUniformSingle\n \n! exp_lambda= exp(-lambda) !calculate constant\n\n! !initialize variables\n! randPoisson = -1\n! prodUni = 1\n! do while (prodUni > exp_lambda) \n! randUni = funUniformSingle() !generate uniform variable\n! prodUni = prodUni * randUni !update product\n! randPoisson = randPoisson + 1 !increase Poisson variable\n! end do\n! end function funPoissonSingle\n! !END Function definitions\n! end module rand\n", "meta": {"hexsha": "77918d6ebd48a1b84f93cab11c3e57ab6178d799", "size": 7627, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mod_random.f90", "max_stars_repo_name": "mgullik/data_analysis", "max_stars_repo_head_hexsha": "b91ae014bfa280ba7e7fa3a48600b18eeb74eafe", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "mod_random.f90", "max_issues_repo_name": "mgullik/data_analysis", "max_issues_repo_head_hexsha": "b91ae014bfa280ba7e7fa3a48600b18eeb74eafe", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "mod_random.f90", "max_forks_repo_name": "mgullik/data_analysis", "max_forks_repo_head_hexsha": "b91ae014bfa280ba7e7fa3a48600b18eeb74eafe", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.2222222222, "max_line_length": 102, "alphanum_fraction": 0.473449587, "num_tokens": 2556, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381952105442, "lm_q2_score": 0.760650658103136, "lm_q1q2_score": 0.6553295951678886}} {"text": "\n! From:\n!\n! http://icl.cs.utk.edu/lapack-for-windows/lapack/\n!\n\nprogram main\n\n\tinteger, parameter :: n=2, lda=2, nrhs=1, ldb=2\n\n\tdouble precision :: a(lda,n), b(ldb,nrhs)\n\n\tinteger :: ipiv(n), info, i, j\n\n\ta(1,1) = 1\n\ta(1,2) = 2\n\ta(2,1) = 3\n\ta(2,2) = 4\n\n\tb(1,1) = 5\n\tb(2,1) = 6\n\n\tprint *, \"Hello world\"\n\n\t! Solve linear system a*x = b, for x\n\tcall dgesv(n, nrhs, a, lda, ipiv, b, ldb, info)\n\n\tprint *, \"info = \", info\n\tprint *, \"a (factored) = \", a\n\n\t! Expected output: x = -4.0 4.5\n\tprint *, \"x = \", b\n\n\tprint *, \"done main\"\n\nend program main\n\n", "meta": {"hexsha": "e1f17be2f2fc38ead656fc6631db643c6eb2734c", "size": 551, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "main.f90", "max_stars_repo_name": "JeffIrwin/lapack-hello-world", "max_stars_repo_head_hexsha": "a5fe6b0399418fe30389f424359aeddf4f4fb687", "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": "main.f90", "max_issues_repo_name": "JeffIrwin/lapack-hello-world", "max_issues_repo_head_hexsha": "a5fe6b0399418fe30389f424359aeddf4f4fb687", "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": "main.f90", "max_forks_repo_name": "JeffIrwin/lapack-hello-world", "max_forks_repo_head_hexsha": "a5fe6b0399418fe30389f424359aeddf4f4fb687", "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": 14.5, "max_line_length": 54, "alphanum_fraction": 0.5499092559, "num_tokens": 232, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.86153820232079, "lm_q2_score": 0.7606506418255928, "lm_q1q2_score": 0.6553295865525764}} {"text": " program demo_tan\n use, intrinsic :: iso_fortran_env, only : real_kinds, &\n & real32, real64, real128\n implicit none\n real(kind=real64) :: x = 0.165_real64\n write(*,*)x, tan(x)\n end program demo_tan\n", "meta": {"hexsha": "d1904ac7f9e83b8f6ba14bc1c566f042ef5d18b0", "size": 225, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/tan.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/tan.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/tan.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": 28.125, "max_line_length": 59, "alphanum_fraction": 0.6266666667, "num_tokens": 73, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381952105441, "lm_q2_score": 0.7606506418255928, "lm_q1q2_score": 0.6553295811441633}} {"text": "function our_noise(ips)\r\n\r\nUSE DFPORT\r\n\r\ncommon/histo/istep,xconv(2000),xdir1,xdir2,dxdir\r\ncommon/noise_1/a_rand(2),xmid(2)\r\n\r\nour_noise=0\r\n\r\nx = RAND()\r\ndo ii=1,istep-1\r\n\tx1=xdir1+dxdir*(ii-1)\r\n\tx2=xdir1+dxdir*ii\r\n\tif(x.lt.x1.or.x.ge.x2) cycle\r\n\ty1=xconv(ii)\r\n\ty2=xconv(ii+1)\r\n\ty=y1+((y2-y1)/(x2-x1))*(x-x1)\r\n\t!write(*,*)' y=',y\r\n\tgoto 16\r\nend do\r\n\r\nwrite(*,*)' x=',x,' istep=',istep,' dxdir=',dxdir\r\nwrite(*,*)' xconv(1)=',xconv(1),' xconv(istep)=',xconv(istep)\r\nwrite(*,*)' xdir1=',xdir1,' xdir2=',xdir2\r\nstop\r\n\r\n16 continue\r\n\r\nour_noise = xmid(ips) + y * a_rand(ips)\r\n\r\nreturn\r\nend\r\n\r\n", "meta": {"hexsha": "21d880f5c4442798fdd1d0a5305b1bfb08d94c2e", "size": 589, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "PROGRAMS/0_START/add_noise_to_real_data/subr/our_noise.f90", "max_stars_repo_name": "ilyasnsk/colima_lotos_2019", "max_stars_repo_head_hexsha": "d3ff4f32034e49a32560f170e980b6847b6ea9c7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-10-28T06:16:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-16T02:52:23.000Z", "max_issues_repo_path": "PROGRAMS/0_START/add_noise_to_real_data/subr/our_noise.f90", "max_issues_repo_name": "ilyasnsk/colima_lotos_2019", "max_issues_repo_head_hexsha": "d3ff4f32034e49a32560f170e980b6847b6ea9c7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "PROGRAMS/0_START/add_noise_to_real_data/subr/our_noise.f90", "max_forks_repo_name": "ilyasnsk/colima_lotos_2019", "max_forks_repo_head_hexsha": "d3ff4f32034e49a32560f170e980b6847b6ea9c7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.3235294118, "max_line_length": 62, "alphanum_fraction": 0.6061120543, "num_tokens": 250, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. Yes\n2. Yes", "lm_q1_score": 0.828938825225204, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.6553012777537844}} {"text": " PROGRAM TB0101\n\n IMPLICIT NONE\n\n* DOUBLE PRECISION TABLE\n DOUBLE PRECISION DH(15), D4(15), D5(15)\n* SINGLE PRECISION TABLE\n REAL SH(15), S4(15), S5(15)\n\n* DUMMIES\n INTEGER I\n\n* DATA DECLARATION\n DATA DH / 0.5D-0, 0.2D-0, 0.1D-0, 0.5D-1, 0.2D-1, 0.1D-1,\n $ 0.5D-2, 0.2D-2, 0.1D-2, 0.5D-3, 0.2D-3, 0.1D-3,\n $ 0.5D-4, 0.2D-4, 0.1D-4 /\n DATA SH / 0.5E-0, 0.2E-0, 0.1E-0, 0.5E-1, 0.2E-1, 0.1E-1,\n $ 0.5E-2, 0.2E-2, 0.1E-2, 0.5E-3, 0.2E-3, 0.1E-3,\n $ 0.5E-4, 0.2E-4, 0.1E-4 /\n \n* FILE OF WRITTEN FILE\n OPEN (11, FILE = '01-01.txt')\n\n*----------------------------------------------------------------------\n\n* ERROR CALCULATION\n DO 10 I = 1, 15\n* SINGLE ERROR CALCULATION \n S4(I) = ( SIN(1.0E0 + SH(I)) - 2.0E0 * SIN(1.0E0)\n $ + SIN(1.0E0 - SH(I)) ) \n $ / ( SH(I) * SH(I) ) + SIN(1.0E0)\n S5(I) = ( - SIN(1.0E0 - 2.0E0 * SH(I)) \n $ + 16.0E0 * SIN(1.0E0 - SH(I))\n $ - 30.0E0 * SIN(1.0E0)\n $ + 16.0E0 * SIN(1.0E0 + SH(I))\n $ - SIN(1.0E0 + 2.0E0 * SH(I)) )\n $ / ( 12.0E0 * SH(I) * SH(I) ) + SIN(1.0E0)\n* DOUBLE ERROR CALCULATION \n D4(I) = ( DSIN(1.0D0 + DH(I)) - 2.0D0 * DSIN(1.0D0)\n $ + DSIN(1.0D0 - DH(I)) ) \n $ / ( DH(I) * DH(I) ) + DSIN(1.0D0)\n D5(I) = ( - DSIN(1.0D0 - 2.0D0 * DH(I)) \n $ + 16.0D0 * DSIN(1.0D0 - DH(I))\n $ - 30.0D0 * DSIN(1.0D0)\n $ + 16.0D0 * DSIN(1.0D0 + DH(I))\n $ - DSIN(1.0D0 + 2.0D0 * DH(I)) )\n $ / ( 12.0D0 * DH(I) * DH(I) ) + DSIN(1.0D0)\n\n 10 CONTINUE\n\n* DOUBLE ERROR TABLE\n\n WRITE (11,*)\n WRITE (11,35) '2nd Derivate Single Precision Error Table'\n WRITE (11,*)\n\n WRITE (11,15) '----------' , '---------------', '---------------' \n WRITE (11,15) ' h ' , ' 4-Point', ' 5-Point'\n WRITE (11,15) '----------' , '---------------', '---------------' \n\n DO 20 I = 1, 15\n WRITE (11,25) SH(I), S4(I), S5(I)\n 20 CONTINUE\n \n WRITE (11,15) '----------' , '---------------', '---------------' \n\n* DOUBLE ERROR TABLE\n\n WRITE (11,*)\n WRITE (11,35) '2nd Derivate Double Precision Error Table'\n WRITE (11,*)\n\n WRITE (11,15) '----------' , '---------------', '---------------' \n WRITE (11,15) ' h ' , ' 4-Point', ' 5-Point'\n WRITE (11,15) '----------' , '---------------', '---------------' \n\n DO 30 I = 1, 15\n WRITE (11,25) DH(I), D4(I), D5(I)\n 30 CONTINUE\n \n WRITE (11,15) '----------' , '---------------', '---------------' \n\n* FORMAT\n 15 FORMAT (10A, 2(15A))\n 25 FORMAT (F10.5, 2(3X, F12.8))\n 35 FORMAT (50A)\n\n END PROGRAM TB0101\n", "meta": {"hexsha": "ae1565e7376e88668bbef54f301384d303183b4a", "size": 2851, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "Exercise/Chapter-01/01-01/01-01.for", "max_stars_repo_name": "ajz34/Comp-Phys-Koonin", "max_stars_repo_head_hexsha": "9fc371bdb44b7030025d254eda040a55bfa3b7cd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-10-29T12:21:38.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-31T17:03:43.000Z", "max_issues_repo_path": "Exercise/Chapter-01/01-01/01-01.for", "max_issues_repo_name": "ajz34/Comp-Phys-Koonin", "max_issues_repo_head_hexsha": "9fc371bdb44b7030025d254eda040a55bfa3b7cd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Exercise/Chapter-01/01-01/01-01.for", "max_forks_repo_name": "ajz34/Comp-Phys-Koonin", "max_forks_repo_head_hexsha": "9fc371bdb44b7030025d254eda040a55bfa3b7cd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.0337078652, "max_line_length": 72, "alphanum_fraction": 0.370045598, "num_tokens": 1197, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7905303186696747, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.6553012653110982}} {"text": "!---------------------------------------------------------------------------------------------------\n!\n!\tfilename = main.f90\n!\tauthors = Edison Salazar\n!\t\t Pedro Guarderas\n!\tdate = 01/08/2013\n!\n!---------------------------------------------------------------------------------------------------\n\n!---------------------------------------------------------------------------------------------------\n!\n! Main program\n!\n!---------------------------------------------------------------------------------------------------\nprogram principal\n\n use atomic\n use consts\n use coupling\n use grid\n use linear\n use plotting\n use quad\n\n!---------------------------------------------------------------------------------------------------\n!\n! Atomic parameters\n!\n! m : Total number of bases\n! n : Number of orbitals by type\n! l : Second Quantic numbers for every type of orbital \n! c : Coefficients for the bases\n! nc : Principal quantic number for all the base orbitals\n! e : Coefficients for the base orbitals\n! ne : Quantity of electrons for every orbital\n! d : Quantity of coefficients for kind of orbital, starting in the second component\n!\n!---------------------------------------------------------------------------------------------------\n\n character( len = 100 ) :: infile\n integer :: n, m, Nr\n integer, allocatable :: d(:)\n double precision, allocatable :: l(:), c(:), nc(:), e(:), ne(:)\n double precision, allocatable :: DFT(:,:), T(:,:), y(:), p(:), r(:)\n double precision, dimension(3) :: Ct, W, J\n double precision :: Tapp\n\n!---------------------------------------------------------------------------------------------------\n! Reading parameters\n write(*,*) \"Reading file with parameters\"\n call getarg( 1, infile )\n\n open( unit = 10, file = infile )\n\n read( 10, * ) n\n read( 10, * ) m\n\n allocate( l(n), c(m), nc(m), e(m), ne(n), d(n+1), y(m) )\n \n read( 10, * ) l\n read( 10, * ) c\n read( 10, * ) nc\n read( 10, * ) e\n read( 10, * ) ne\n read( 10, * ) d\n\n! Paramaters for homogeneous approximation\n Ct = (/ 3.26422D0, -0.02631D0, 0.000498D0 /)\n W = (/ 5.0D0/3.0D0, 4.0D0/3.0D0, 11.0D0/9.0D0 /)\n J = (/ 1.0D0, 2.0D0, 3.0D0 /)\n \n!---------------------------------------------------------------------------------------------------\n! Grid generations\n Nr = 1000\n write(*,*) \"Building radial mesh with size: \", Nr\n allocate( r(Nr), p(Nr) )\n call grid_adap_exp( r, Nr, 5.0D0, 5.0D0 )\n !call grid_unif( r, Nr, 0.0D0, 5.0D0 )\n \n!---------------------------------------------------------------------------------------------------\n write(*,*) \"DFT computations\"\n\n allocate( T(m,m), DFT(m,m) )\n\t\n write(*,*) \"Building DFT matrices\"\n call buildKS( DFT, T, nc, e, ne, l, d, n, m )\n \n write(*,*) \"Computing exact kinetic energy\"\n open( unit = 14, file = 'results.data' )\n call MatMulVec( y, T, c, m, m )\n write(14,*) \"Exact integral of the kinetic energy T: \", scalar( y, c, m )\n \n write(*,*) \"Computing exact density\"\n call MatMulVec( y, DFT, c, m, m )\n write(14,*) \"Exact integral of density: \", scalar( y, c, m )\n \n \n write(*,*) \"Computing radial density\"\n call radialDFT( p, r, Nr, c, nc, e, ne, d, n, m )\n \n write(*,*) \"Computing Kinectic Energy approximation\"\n call HomogeneousApprox( Tapp, Ct, W, J, p, r, Nr, 3 )\n write(14,*) \"Kinectic Energy approximation: \", Tapp\n close( unit = 14 )\n\n!---------------------------------------------------------------------------------------------------\n write(*,*) \"Writing results in *.data files\"\n \n write(*,*) \"Writing kinetic energy\"\n open( unit = 15, file = \"kinetic.data\" )\n call WriteMatrix( 15, T, m, m )\n close( unit = 15 )\n \n write(*,*) \"Writing density matrix\"\n open( unit = 16, file = \"density.data\" )\n call WriteMatrix( 16, DFT, m, m )\n close( unit = 16 )\n \n write(*,*) \"Writing radial grid\"\n open( unit = 17, file = \"radial_grid.data\" )\n call WriteVector( 17, r, Nr )\n close( unit = 17 )\n \n write(*,*) \"Writing radial density\"\n open( unit = 18, file = \"radial_density.data\" )\n call WriteVector( 18, p, Nr )\n close( unit = 18 )\n \n \n!---------------------------------------------------------------------------------------------------\n write(*,*) \"Plotting\"\n call contour( T, m, m, 0.0, real(m), 10, 0.0, real(m), 10, -446.843, 220.607, 10, 1 )\n call contour( DFT, m, m, 0.0, real(m), 10, 0.0, real(m), 10, 0.0, 3.0, 10, 1 )\n\n\n!---------------------------------------------------------------------------------------------------\n deallocate( l, c, nc, e, ne, d )\n deallocate( T, DFT, y )\n deallocate( r, p )\n \n stop\n\nend program principal\n", "meta": {"hexsha": "6b1befd64fc3cc7447cb37297c646193a77540f5", "size": 4582, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/main.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": "test/main.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": "test/main.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": 31.8194444444, "max_line_length": 100, "alphanum_fraction": 0.4386730685, "num_tokens": 1297, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088064979618, "lm_q2_score": 0.7057850278370112, "lm_q1q2_score": 0.6552570353382904}} {"text": "module problem_data\n\n use mfe_constants, only: wp\n private\n \n public :: c_of_u, u_of_c\n \n real(kind=wp), parameter, public :: D0 = 7.3e-8, D1 = 1.17e-7, ni = 7.12e18\n\n real(kind=wp), save, public :: mu, t_scale, u_scale, u_shift, c_min, c_max\n \n contains\n\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n !!\n !! C_OF_U -- Compute c(u).\n !!\n !! Using a Newton iteration, this routine inverts the function\n !!\n !!\tU(C) = (C/MU + log(C/MU) - U_SHIFT) / U_SCALE.\n !!\n !! This is done by writing\n !!\n !!\tU_SCALE * U + U_SHIFT = (C/MU) + log(C/MU)\n !!\n !! and then inverting the function y = x + log(x).\n !!\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n \n function c_of_u (u) result (c)\n \n real(kind=wp), dimension(:), intent(in) :: u\n real(kind=wp), dimension(size(u)) :: c, y\n \n integer :: k\n integer, parameter :: NITR = 4\n\n y = u_scale * u + u_shift\n \n where (y < 1.0_wp)\n c = exp(y - 1.0_wp)\n elsewhere\n c = y\n end where\n \n y = y + 1.0_wp\n \n do k = 1, NITR\n c = c * (y - log(c)) / (1.0_wp + c)\n end do\n \n c = mu * c\n \n end function c_of_u\n \n function u_of_c (c) result (u)\n \n real(kind=wp), dimension(:), intent(in) :: c\n real(kind=wp), dimension(size(c)) :: u\n \n u = ((c/mu) + log(c/mu) - u_shift) / u_scale\n \n end function u_of_c\n\nend module problem_data\n\nmodule problem_init\n\n use mfe_constants, only: wp\n use problem_data\n use common_io\n private\n \n public :: read_problem_data\n \n contains\n \n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n !!\n !! READ_PROBLEM_DATA\n !!\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n \n subroutine read_problem_data ()\n\n call read_tagged_data (mu, \"Transformation parameter MU\")\n call read_tagged_data (c_min, \"Minimum concentration (for transf)\")\n call read_tagged_data (c_max, \"Maximum concentration (for transf)\")\n\n c_min = c_min / (2.0_wp * ni)\n c_max = c_max / (2.0_wp * ni)\n\n end subroutine read_problem_data\n\nend module problem_init\n\nmodule problem_pde\n\n use mfe_constants, only: wp\n use problem_data\n use local_arrays\n use local_laplacian\n private\n \n public :: pde_rhs\n \n contains\n \n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n !!\n !! PDE_RHS --\n !! \n !! RHS inner products for Kent Smith's arsenic diffusion problem,\n !! using the transformation\n !!\n !! USCF*U(x,T) + GAMMA = C(x,t)/MU + log(C(x,t)/MU)\n !!\n !! where C(x,t) is the scaled concentration of arsenic, USCF is\n !! the scaling factor for U and the scaled time T = t/TSCF. The\n !! equation for U is\n !!\n !! dU/dT = TSCF*A(C)*Lapl(U) + (TSCF*USCF)*B(C)*|Grad(U)|**2\n !!\n !! where\n !!\n !! A(C) = N(C)*(D0 + D1*N(C))/sqrt(1 + C**2)\n !!\n !! C*A'(C) A(C)\n !! B(C) = ---------- + -------------\n !! (1 + C/MU) (1 + C/MU)**2\n !!\n !! N(C) = C + sqrt(1 + C**2)\n !!\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n subroutine pde_rhs (t)\n\n real(kind=wp), intent(in) :: t\n\n real(kind=wp) :: fac\n real(kind=wp), dimension(2,nelt) :: visc\n real(kind=wp), dimension(nelt) :: b_phi_1, b_phi_2\n \n ! 3pt gaussian quadrature parameters\n real(kind=wp), parameter :: w1 = 0.2464717596168727_wp, &\n w2 = 0.2222222222222222_wp, &\n w3 = 0.03130601816090511_wp, &\n c1 = 0.8872983346207417_wp, &\n c2 = 0.1127016653792583_wp\n \n fac = u_scale * t_scale\n\n b_phi_1 = w1 * b_of_u (c1 * u(1,:) % u + c2 * u(2,:) % u) + &\n w2 * b_of_u (0.5_wp * (u(1,:) % u + u(2,:) % u)) + &\n w3 * b_of_u (c2 * u(1,:) % u + c1 * u(2,:) % u)\n\n b_phi_2 = w3 * b_of_u (c1 * u(1,:) % u + c2 * u(2,:) % u) + &\n w2 * b_of_u (0.5_wp * (u(1,:) % u + u(2,:) % u)) + &\n w1 * b_of_u (c2 * u(1,:) % u + c1 * u(2,:) % u)\n\n r(1,:) % x = ((fac * dx * dudx**2) * b_phi_1) * n % x\n r(1,:) % u = ((fac * dx * dudx**2) * b_phi_1) * n % u\n\n r(2,:) % x = ((fac * dx * dudx**2) * b_phi_2) * n % x\n r(2,:) % u = ((fac * dx * dudx**2) * b_phi_2) * n % u\n\n visc(1,:) = t_scale * a_of_u (u(1,:) % u)\n visc(2,:) = t_scale * a_of_u (u(2,:) % u)\n\n call laplacian (coef=visc)\n\n end subroutine pde_rhs\n \n function a_of_u (u) result (a)\n \n real(kind=wp), dimension(:), intent(in) :: u\n real(kind=wp), dimension(size(u)) :: a\n \n real(kind=wp), dimension(size(u)) :: c, r\n \n c = c_of_u (u)\n r = sqrt(1.0_wp + c**2)\n a = (c + r) * (D0 + D1 * (c + r)) / r\n \n end function a_of_u\n \n function b_of_u (u) result (b)\n \n real(kind=wp), dimension(:), intent(in) :: u\n real(kind=wp), dimension(size(u)) :: b\n \n real(kind=wp), dimension(size(u)) :: c, r\n \n c = c_of_u (u)\n r = sqrt(1.0_wp + c**2)\n b = ( (c + r) * (D0 + D1 * (c + r)) / (1.0_wp + c/mu) + &\n (D0 + D1 * (c + r)**2 * (2.0_wp * r - c)) / (1.0_wp + c**2) ) &\n / (r * (1.0_wp + c/mu))\n \n end function b_of_u\n\nend module problem_pde\n", "meta": {"hexsha": "58ea4215a5731c98e20ab17550b8b5e5bdc3d48f", "size": 5506, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "nldiff/att.f90", "max_stars_repo_name": "mfeproject/mfe1", "max_stars_repo_head_hexsha": "e07b27a5287ced55b19eb2e804a9b7a80e1a8791", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "nldiff/att.f90", "max_issues_repo_name": "mfeproject/mfe1", "max_issues_repo_head_hexsha": "e07b27a5287ced55b19eb2e804a9b7a80e1a8791", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "nldiff/att.f90", "max_forks_repo_name": "mfeproject/mfe1", "max_forks_repo_head_hexsha": "e07b27a5287ced55b19eb2e804a9b7a80e1a8791", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.1231527094, "max_line_length": 80, "alphanum_fraction": 0.4406102434, "num_tokens": 1824, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088064979618, "lm_q2_score": 0.7057850278370112, "lm_q1q2_score": 0.6552570353382904}} {"text": "! $UWHPSC/codes/mpi/matrix1norm1.f90\n!\n! Compute 1-norm of a matrix using mpi.\n! Process 0 is the master that sets things up and then sends a column\n! to each worker (Processes 1, 2, ..., num_procs - 1).\n!\n! This version assumes there are at least as many workers as columns.\n\nprogram matrix1norm1\n\n use mpi\n\n implicit none\n\n integer :: i,j,jj,nrows,ncols,proc_num, num_procs,ierr,nerr\n integer, dimension(MPI_STATUS_SIZE) :: status\n real(kind=8) :: colnorm\n real(kind=8), allocatable, dimension(:,:) :: a\n real(kind=8), allocatable, dimension(:) :: anorm, colvect\n\n call MPI_INIT(ierr)\n call MPI_COMM_SIZE(MPI_COMM_WORLD, num_procs, ierr)\n call MPI_COMM_RANK(MPI_COMM_WORLD, proc_num, ierr)\n\n nerr = 0\n if (proc_num==0) then\n print *, \"Input nrows, ncols\"\n read *, nrows, ncols\n if (ncols > num_procs-1) then\n print *, \"*** Error, this version requires ncols < num_procs = \",&\n num_procs\n nerr = 1\n endif\n allocate(a(nrows,ncols)) ! only master process 0 needs the matrix\n a = 1.d0 ! initialize to all 1's for this test\n allocate(anorm(ncols)) ! to hold norm of each column in MPI_RECV\n endif\n\n ! if nerr == 1 then all processes must stop:\n call MPI_BCAST(nerr, 1, MPI_DOUBLE_PRECISION, 0, MPI_COMM_WORLD, ierr)\n\n if (nerr == 1) then\n ! Note that error message already printed by Process 0\n ! All processes must execute the MPI_FINALIZE \n ! (Could also just have \"go to 99\" here.)\n call MPI_FINALIZE(ierr)\n stop\n endif\n \n call MPI_BCAST(nrows, 1, MPI_DOUBLE_PRECISION, 0, MPI_COMM_WORLD, ierr)\n call MPI_BCAST(ncols, 1, MPI_DOUBLE_PRECISION, 0, MPI_COMM_WORLD, ierr)\n\n if (proc_num > 0) then\n allocate(colvect(nrows)) ! to hold a column vector sent from master\n endif \n\n\n \n ! -----------------------------------------\n ! code for Master (Processor 0):\n ! -----------------------------------------\n\n if (proc_num == 0) then\n\n do j=1,ncols\n call MPI_SEND(a(1,j), nrows, MPI_DOUBLE_PRECISION,&\n j, j, MPI_COMM_WORLD, ierr)\n enddo\n\n do j=1,ncols\n call MPI_RECV(colnorm, 1, MPI_DOUBLE_PRECISION, &\n MPI_ANY_SOURCE, MPI_ANY_TAG, &\n MPI_COMM_WORLD, status, ierr)\n jj = status(MPI_TAG)\n anorm(jj) = colnorm\n enddo\n\n print *, \"Finished filling anorm with values... \"\n print *, anorm\n print *, \"1-norm of matrix a = \", maxval(anorm)\n endif\n\n\n ! -----------------------------------------\n ! code for Workers (Processors 1, 2, ...):\n ! -----------------------------------------\n if (proc_num /= 0) then\n\n if (proc_num > ncols) go to 99 ! no work expected\n\n call MPI_RECV(colvect, nrows, MPI_DOUBLE_PRECISION,&\n 0, MPI_ANY_TAG, &\n MPI_COMM_WORLD, status, ierr)\n\n j = status(MPI_TAG) ! this is the column number\n ! (should agree with proc_num)\n\n colnorm = sum(abs(colvect))\n\n call MPI_SEND(colnorm, 1, MPI_DOUBLE_PRECISION, &\n 0, j, MPI_COMM_WORLD, ierr)\n\n endif\n\n99 continue ! might jump to here if finished early\n call MPI_FINALIZE(ierr)\n\nend program matrix1norm1\n\n\n \n", "meta": {"hexsha": "6a64adc83b172a97bce074a60aebebfdabdadd4e", "size": 3401, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/codes/mpi/matrix1norm1.f90", "max_stars_repo_name": "philipwangdk/HPC", "max_stars_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "uwhpsc/codes/mpi/matrix1norm1.f90", "max_issues_repo_name": "philipwangdk/HPC", "max_issues_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "uwhpsc/codes/mpi/matrix1norm1.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": 30.3660714286, "max_line_length": 78, "alphanum_fraction": 0.5633637166, "num_tokens": 880, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833945721304, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.6552529692157187}} {"text": "! this mod is used to find the x in Ax=b\n! you should make sure that A is a stmmetrical matrix\nMODULE cgm_mod\n IMPLICIT NONE\n PRIVATE\n PUBLIC:: CGM\nCONTAINS\n SUBROUTINE CGM(A,b,x)\n INTEGER(8)::n,i,ii\n REAL(8),PARAMETER ::delta = 1.0E-5\n REAL(8)::alpha,oldnorm,beta\n REAL(8),DIMENSION(:,:),INTENT(IN):: A\n REAL(8),DIMENSION(:,:),INTENT(IN):: b\n REAL(8),DIMENSION(:,:),INTENT(INOUT)::x\n REAL(8),ALLOCATABLE::r(:,:)\n REAL(8),ALLOCATABLE::d(:,:)\n REAL(8),ALLOCATABLE::r1(:)\n REAL(8)::rtr(1,1),dtad(1,1)\n \n\n n=size(A,1)\n ALLOCATE(r(n,1))\n ALLOCATE(d(n,1))\n ALLOCATE(r1(n))\n\n !step 0:\n r=b-MATMUL(A,x)\n d=r\n r1(1:n)=r(1:n,1)\n DO i=0,n-1\n rtr=MATMUL(transpose(r),r)\n dtad=MATMUL(transpose(d),MATMUL(A,d))\n alpha=rtr(1,1)/dtad(1,1)\n x=x+alpha*d\n oldnorm=NORM2(r1)\n r=b-MATMUL(A,x)\n r1(1:n)=r(1:n,1)\n IF(NORM2(r1)<=delta .OR. i+1==n) EXIT\n beta=NORM2(r1)*NORM2(r1)/(oldnorm*oldnorm)\n d=r+beta*d\n END DO\n DEALLOCATE(r)\n DEALLOCATE(d)\n DEALLOCATE(r1)\n END SUBROUTINE CGM\nEND MODULE", "meta": {"hexsha": "c1ddc5442113b3744e17eb55ed37c329f721e1dd", "size": 1263, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "CGM/src/cgm_mod.f90", "max_stars_repo_name": "Huang-Yihan/jisuanfangfa", "max_stars_repo_head_hexsha": "1e48104988b01f66da216f639fd0654a6b1ff6c4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "CGM/src/cgm_mod.f90", "max_issues_repo_name": "Huang-Yihan/jisuanfangfa", "max_issues_repo_head_hexsha": "1e48104988b01f66da216f639fd0654a6b1ff6c4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "CGM/src/cgm_mod.f90", "max_forks_repo_name": "Huang-Yihan/jisuanfangfa", "max_forks_repo_head_hexsha": "1e48104988b01f66da216f639fd0654a6b1ff6c4", "max_forks_repo_licenses": ["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.4565217391, "max_line_length": 54, "alphanum_fraction": 0.5003958828, "num_tokens": 447, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418262465169, "lm_q2_score": 0.7090191337850933, "lm_q1q2_score": 0.6552342371398796}} {"text": " SUBROUTINE AF (F,N,A,B,C,C1,C2,C3,T1,T3,T5,JUMP)\r\nC\r\nC THIS AREA INTEGRATION ROUTINE IS USED IN TRIM6, TRPLT1 AND TRSHL\r\nC IT COMPUTES THE F FUNCTION, AND CONSTANTS C1, C2, C3\r\nC\r\nC FAC ARE THE FACTORIALS 1 THRU 36\r\nC B IS DISTANCE OF GRID POINT 1\r\nC A IS DISTANCE OF GRID POINT 3\r\nC C IS DISTANCE OF GRID POINT 5\r\nC T1 IS ASSOCIATIVE VARIABLE AT GRID POINT 1\r\nC T3 IS ASSOCIATIVE VARIABLE AT GRID POINT 3\r\nC T5 IS ASSOCIATIVE VARIABLE AT GRID POINT 5\r\nC N IS DIMENSION OF AREA FUNCTION F\r\nC\r\nC\r\nC\r\n REAL F(N,N)\r\n DOUBLE PRECISION FAC(20), TEMP\r\n DATA FAC / 1.D0,1.D0, 2.D0,6.D0, 2.4D1, 1.2D2, 7.2D2, 5.04D3,\r\n 1 4.032D4, 3.6288D5, 3.6288D6, 3.99168D7,\r\n 2 4.790016D8, 6.227021D9, 8.7178291D10, 1.307674D12,\r\n 3 2.092279D13, 3.556874D14, 6.402374D15, 1.216451D17/\r\nC\r\n IF (JUMP .GT. 0) GO TO 30\r\n IF (N .GT. 18) STOP 'IN AF'\r\n DO 10 I=1,N\r\n DO 10 J=1,N\r\n 10 F(I,J)=0.0\r\n DO 20 I=1,N\r\n I1=I\r\n DO 15 J=1,I\r\n TEMP = DBLE(C**J) * FAC(I1) / FAC(I+2)\r\n TEMP = DBLE(A**I1-(-B)**I1) * TEMP * FAC(J)\r\n F(I1,J) = SNGL(TEMP)\r\n I1=I1-1\r\n 15 CONTINUE\r\n 20 CONTINUE\r\n IF (JUMP .LT. 0) RETURN\r\nC\r\n 30 AB=A-B\r\n IF (A .EQ. B .AND. A .NE. 0.0) AB=A+B\r\n IF (AB .EQ. 0.0) CALL MESAGE (-37,0,0)\r\n C1=(T1*A-T3*B)/AB\r\n C2=(T3-T1)/AB\r\n C3=(T5-C1)/C\r\n RETURN\r\n END\r\n", "meta": {"hexsha": "a084a9eb8191a9b516f99ad459cca0604d6fbe5c", "size": 1501, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "mis/af.f", "max_stars_repo_name": "ldallolio/NASTRAN-95", "max_stars_repo_head_hexsha": "6d2c175f5b53ebaec4ba2b5186f7926ef9d0ed47", "max_stars_repo_licenses": ["NASA-1.3"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2016-01-09T14:33:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-18T11:51:42.000Z", "max_issues_repo_path": "mis/af.f", "max_issues_repo_name": "gassive/NASTRAN95", "max_issues_repo_head_hexsha": "98cb3acaa7990d639360601648498834c7782056", "max_issues_repo_licenses": ["NASA-1.3"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2016-01-17T07:30:19.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-06T19:37:44.000Z", "max_forks_repo_path": "mis/af.f", "max_forks_repo_name": "gassive/NASTRAN95", "max_forks_repo_head_hexsha": "98cb3acaa7990d639360601648498834c7782056", "max_forks_repo_licenses": ["NASA-1.3"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-04-07T20:51:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T14:16:01.000Z", "avg_line_length": 31.2708333333, "max_line_length": 73, "alphanum_fraction": 0.525649567, "num_tokens": 657, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418283357702, "lm_q2_score": 0.7090191276365462, "lm_q1q2_score": 0.6552342329390706}} {"text": "5.\n5.+3.\n(5.+3.)*2.\n5.+3.*2.\n5.-3.\n4.**3.\n", "meta": {"hexsha": "bafe7139b0b41bd4a34f0e194073eb2487fcd244", "size": 42, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/expr4.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/expr4.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": "tests/expr4.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": 6.0, "max_line_length": 10, "alphanum_fraction": 0.3095238095, "num_tokens": 29, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528094861981, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.6552200732019068}} {"text": "module lr_lib\n use ort_lib\n implicit none\n\n interface lr\n module procedure lr_d2\n end interface\n\n contains\n subroutine lr_d2(a,u,b,tol,maxr,err)\n implicit none\n double precision,intent(in) :: a(:,:)\n double precision,pointer :: u(:,:),b(:,:)\n double precision,intent(in),optional :: tol\n integer,intent(in),optional :: maxr\n double precision,intent(out),optional :: err\n character(len=*),parameter :: subnam='lr_d2'\n double precision,allocatable :: x(:,:),y(:,:),z(:,:),g(:,:),v(:)\n integer,allocatable :: q(:)\n integer :: m,n,mn,i,j,jj,ij(2),rmax,r,info\n double precision :: er,nrm,nr1,er1,zz,xx\n logical :: done\n double precision,external :: dnrm2\n integer,external :: idamax\n\n m=size(a,1); n=size(a,2); mn=min(m,n)\n if(present(maxr))then;if(maxr.ge.0)then;rmax=min(maxr,mn);else;rmax=mn;endif; else;rmax=mn;end if\n\n allocate(x(m,rmax),y(n,rmax),z(m,n),v(n),q(n), stat=info)\n if(info.ne.0)then;write(*,*)subnam,': not enough memory!';stop;endif\n \n call dcopy(m*n,a,1,z,1)\n nrm=dnrm2(m*n,a,1); er=nrm; nr1=-1.d0\n r=0; done=(r.ge.rmax)\n \n do while(.not.done)\n! ij=maxloc(abs(z)); i=ij(1); j=ij(2)\n!...OMP parallel do shared(z,q,v,m,n)\n do jj=1,n\n q(jj)=idamax(m,z(1,jj),1); v(jj)=abs(z(q(jj),jj))\n end do\n!...OMP END parallel do\n j=maxloc(v,1); i=q(j); zz=z(i,j); er1=dabs(zz)\n if(r.eq.0)nr1=er1\n r=r+1\n call dcopy(m,z(1,j),1,x(1,r),1); xx=dnrm2(m,x(1,r),1); call dscal(m,1.d0/xx,x(1,r),1)\n call dcopy(n,z(i,1),m,y(1,r),1); call dscal(n,xx/zz,y(1,r),1)\n call dger(m,n,-1.d0,x(1,r),1,y(1,r),1,z,m)\n er=dnrm2(m*n,z,1)\n done=r.eq.rmax\n if(present(tol))done=done.or.er.le.tol*nrm\n\n !write(*,'(i3,a,2i6,a,2e10.3)')r,' @ ',i,j,' er ',er/nrm,er1/nr1\n end do\n \n allocate(u(m,r),b(r,n),g(r,r), stat=info)\n if(info.ne.0)then;write(*,*)subnam,': not enough memory!';stop;endif\n \n call ort0(x(:,1:r),out=u,mat=g)\n call dgemm('n','t',r,n,r,1.d0,g,r,y,n,0.d0,b,r)\n!- \n! call dcopy(m*n,a,1,z,1)\n! call dgemm('n','n',m,n,r,-1.d0,u,m,b,r,1.d0,z,m)\n! er=dnrm2(m*n,z,1)\n! write(*,*) 'truerr : ',er/nrm\n!- \n deallocate(x,y,z,v,q,g)\n if(present(err))err=er/nrm\n end subroutine\nend module\n", "meta": {"hexsha": "0d2addc70c6e25aa7377c19eb6cc98f1ea0c3661", "size": 2135, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lr.f90", "max_stars_repo_name": "dimpase/tt-fort", "max_stars_repo_head_hexsha": "2feceda8df2f7c6c84a473759a9c502c3c5a3ded", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2017-12-07T12:51:46.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-02T11:27:41.000Z", "max_issues_repo_path": "lr.f90", "max_issues_repo_name": "dimpase/tt-fort", "max_issues_repo_head_hexsha": "2feceda8df2f7c6c84a473759a9c502c3c5a3ded", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-06-18T09:31:01.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-21T13:15:30.000Z", "max_forks_repo_path": "lr.f90", "max_forks_repo_name": "dimpase/tt-fort", "max_forks_repo_head_hexsha": "2feceda8df2f7c6c84a473759a9c502c3c5a3ded", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2015-03-30T10:53:25.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-21T03:58:11.000Z", "avg_line_length": 30.0704225352, "max_line_length": 99, "alphanum_fraction": 0.6056206089, "num_tokens": 874, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528170040852, "lm_q2_score": 0.7690802317779601, "lm_q1q2_score": 0.655220069965388}} {"text": " program main\n\nc*********************************************************************72\nc\ncc MAIN is the main program for BROWNIAN_MOTION_SIMULATION_PRB.\nc\nc Discussion:\nc\nc BROWNIAN_MOTION_SIMULATION_PRB tests the BROWNIAN_MOTION_SIMULATION library.\nc\nc Licensing:\nc\nc This code is distributed under the GNU LGPL license.\nc\nc Modified:\nc\nc 30 September 2012\nc\nc Author:\nc\nc John Burkardt\nc\n implicit none\n\n integer k\n parameter ( k = 40 )\n integer m_max\n parameter ( m_max = 3 )\n integer n\n parameter ( n = 1001 )\n\n double precision d\n double precision dsq(k,n)\n character * ( 80 ) header\n integer m\n integer seed\n double precision t\n double precision x(m_max,n)\n\n call timestamp ( )\n write ( *, '(a)' ) ''\n write ( *, '(a)' ) 'BROWNIAN_MOTION_SIMULATION_PRB'\n write ( *, '(a)' ) ' FORTRAN77 version'\n write ( *, '(a)' ) \n & ' Test the BROWNIAN_MOTION_SIMULATION library.'\nc\nc Compute the path of a particle undergoing Brownian motion.\nc\n do m = 1, 2\n\n d = 10.0D+00\n t = 1.0D+00\n seed = 123456789\n call brownian_motion_simulation ( m, n, d, t, seed, x )\n if ( m .eq. 1 ) then\n header = 'motion_1d'\n else if ( m .eq. 2 ) then\n header = 'motion_2d'\n end if\n call brownian_motion_display ( m, n, x, header )\n\n end do\nc\nc Estimate the average displacement of the particle from the origin\nc as a function of time.\nc\n do m = 1, 3\n\n d = 10.0D+00\n t = 1.0D+00\n seed = 123456789\n\n call brownian_displacement_simulation ( k, n, m, d, t, seed, \n & dsq )\n if ( m .eq. 1 ) then\n header = 'displacement_1d'\n else if ( m .eq. 2 ) then\n header = 'displacement_2d'\n else if ( m .eq. 3 ) then\n header = 'displacement_3d'\n end if\n call brownian_displacement_display ( k, n, d, t, dsq, header )\n\n end do\nc\nc Terminate.\nc\n write ( *, '(a)' ) ''\n write ( *, '(a)' ) 'BROWNIAN_MOTION_SIMULATION_PRB'\n write ( *, '(a)' ) ' Normal end of execution.'\n write ( *, '(a)' ) ''\n call timestamp ( );\n\n return\n end\n", "meta": {"hexsha": "ceed8aba19213507840d79f831b2ae7930ae1b3b", "size": 2238, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "brownian_motion_simulation_prb.f", "max_stars_repo_name": "FortranSoftwares/BROWNIAN_MOTION_SIMULATION", "max_stars_repo_head_hexsha": "68c6b0b72b08827607dbd15cfbe4106aaf335419", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-07-27T13:58:09.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-29T12:52:00.000Z", "max_issues_repo_path": "brownian_motion_simulation_prb.f", "max_issues_repo_name": "FortranSoftwares/BROWNIAN_MOTION_SIMULATION", "max_issues_repo_head_hexsha": "68c6b0b72b08827607dbd15cfbe4106aaf335419", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "brownian_motion_simulation_prb.f", "max_forks_repo_name": "FortranSoftwares/BROWNIAN_MOTION_SIMULATION", "max_forks_repo_head_hexsha": "68c6b0b72b08827607dbd15cfbe4106aaf335419", "max_forks_repo_licenses": ["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.3125, "max_line_length": 81, "alphanum_fraction": 0.5442359249, "num_tokens": 680, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7690802264851919, "lm_q2_score": 0.8519528038477824, "lm_q1q2_score": 0.6552200553379468}} {"text": "\tSUBROUTINE FITSLOPE(X,Y,N,SLOPE,SUMSQ)\nC\n\tDIMENSION X(1),Y(1),WT(2048)\nC\n\tSUMSQ = 0.\n\tSXX = 0.\n\tSXY = 0.\n\tSYY = 0.\t\n\tDO J = 1,N\n\t WT(J) = 1.\n\t SXX =SXX + WT(J)*X(J)**2\n\t SXY =SXY + WT(J)*X(J)*Y(J)\n\t SYY =SYY + WT(J)*Y(J)**2\n\tENDDO\nC\tSLOPE IS Y/X\n\tSLOPE = SXY/SXX\n\tSUMSQ = SXX*SLOPE**2 - 2.*SLOPE*SXY + SYY\n\tRETURN\n\tEND\n\n", "meta": {"hexsha": "8f4571009ea4d566322aee3a4b2254baf4e730ee", "size": 325, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/fitslope_1.for", "max_stars_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_stars_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/fitslope_1.for", "max_issues_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_issues_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/fitslope_1.for", "max_forks_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_forks_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.4761904762, "max_line_length": 42, "alphanum_fraction": 0.5446153846, "num_tokens": 177, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8962513786759492, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6552122589900217}} {"text": "\nc======================================================================= \n subroutine ptdensityu(ngrid,nrec,y,\n & ab,murand,sigmarand,jfr,m0,s0,tau,\n & mcmcvec,nsave,tune1,tune2,tune3,\n & acrate,f,thetasave,cpo,\n & cpar,mu,sigma,\n & grid,seed,whicho,whichn)\nc======================================================================= \nc\nc Subroutine `ptdensityu' to run a Markov chain for univariate \nc density estimation using a Mixture of Polya Tree prior. The\nc Polya Tree is centered in a N(mu,sigma2) distribution.\nc\nc Copyright: Alejandro Jara, 2006-2010.\nc\nc Version 3.0: \nc\nc Last modification: 25-01-2009.\nc \nc Changes and Bug fixes: \nc\nc Version 2.0 to Version 3.0:\nc - Centering parameters can be fixed.\nc - Proper prior can be used on the centering parameters.\nc\nc Version 1.0 to Version 2.0:\nc - Uses vectors to keep the observations in each partition.\nc\nc This program is free software; you can redistribute it and/or modify\nc it under the terms of the GNU General Public License as published by\nc the Free Software Foundation; either version 2 of the License, or (at\nc your option) any later version.\nc\nc This program is distributed in the hope that it will be useful, but\nc WITHOUT ANY WARRANTY; without even the implied warranty of\nc MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nc General Public License for more details.\nc\nc You should have received a copy of the GNU General Public License\nc along with this program; if not, write to the Free Software\nc Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\nc\nc The author's contact information:\nc\nc Alejandro Jara\nc Department of Statistics\nc Facultad de Matematicas\nc Pontificia Universidad Catolica de Chile\nc Casilla 306, Correo 22 \nc Santiago\nc Chile\nc Voice: +56-2-3544506 URL : http://www.mat.puc.cl/~ajara\nc Fax : +56-2-3547729 Email: atjara@uc.cl\nc\nc---- Data -------------------------------------------------------------\nc\nc ngrid : integer giving the size of the grid where\nc the density estimate is evaluated.\nc nrec : integer giving the number of observations.\nc y : real vector giving the response variables,\nc y(nrec).\nc\nc-----------------------------------------------------------------------\nc\nc---- Prior information ------------------------------------------------\nc \nc ca, cb : real giving the hyperparameters of the prior\nc distribution for the precision parameter,\nc c ~ Gamma(ca,cb). If ca<0 the precision \nc parameter is considered as a constant.\nc jfr : integer vector indicating whether Jeffery's\nc prior is used for the centering parameters.\nc m0 : real giving the mean of the normal prior\nc for the centering mean.\nc s0 : real giving the variance of the normal prior\nc for the centering mean.\nc tau : real vector giving the hyperparameters of\nc inverse gamma prior for the centering variance.\nc\nc-----------------------------------------------------------------------\nc\nc---- MCMC parameters --------------------------------------------------\nc\nc nburn : integer giving the number of burn-in scans.\nc ndisplay : integer giving the number of saved scans to be\nc displayed on screen.\nc nskip : integer giving the thinning interval.\nc nsave : integer giving the number of scans to be saved.\nc tune1 : real giving the tuning parameter for MH of\nc mean baseline.\nc tune2 : real giving the tuning parameter for MH of\nc variance baseline.\nc tune3 : real giving the tuning parameter for MH of\nc precision parameter.\nc \nc-----------------------------------------------------------------------\nc\nc---- Output ----------------------------------------------------------- \nc\nc acrate : real vector giving the MH acceptance rate,\nc acrate(3). \nc f : real vector giving the density estimate at the\nc grid, f(ngrid).\nc thetasave : real vector containing the mcmc sample for the\nc parameters, betsave(nsave,3). \nc cpo : real giving the cpo, cpo(nrec).\nc\nc-----------------------------------------------------------------------\nc\nc---- Current value of the parameters ----------------------------------\nc\nc cpar : real giving the current value of the precision\nc parameter of the Polya Tree.\nc mu : real giving the current value of the \nc baseline mean.\nc sigma : real giving the he current value of the\nc baseline standard deviation.\nc\nc-----------------------------------------------------------------------\nc\nc---- Working space ----------------------------------------------------\nc\nc cdfnorm : cdf of a normal distribution.\nc cparc : real giving the value of the candidate\nc for the precision parameter.\nc dispcount : index. \nc dlnrm : density of a log-normal distribution.\nc dnrm : density of a normal distribution.\nc grid : real vector giving the grid where the density\nc estimate is evaluated, grid(ngrid) .\nc i : index.\nc invcdfnorm : quantile function for a normal distribution.\nc isave : index. \nc iscan : index. \nc j : index. \nc je2 : index.\nc k : index. \nc k1 : index.\nc k2 : index.\nc logcgkn : real working variable.\nc logcgko : real working variable.\nc loglikn : real working variable.\nc logliko : real working variable.\nc logpriorn : real working variable.\nc logprioro : real working variable.\nc muc : real giving the value of the candidate\nc for the baseline mean. \nc nscan : index.\nc parti : index.\nc pprn : index.\nc quan : real working variable.\nc ratio : real working variable.\nc rbeta : real beta random number generator.\nc rtlnorm : real truncated log normal random number generator.\nc rnorm : real normal random number generator.\nc runif : real uniform random number generator.\nc s : real giving the sample variance. \nc sec : cpu time working variable.\nc sec0 : cpu time working variable.\nc sec00 : cpu time working variable.\nc sec1 : cpu time working variable.\nc seed1 : seed for random number generation.\nc seed2 : seed for random number generation.\nc sigmac : real giving the value of the candidate\nc for the baseline standard deviation. \nc sigma2 : real giving the current value of\nc the baseline variance. \nc sigma2c : real giving the value of the candidate\nc for the baseline variance. \nc skipcount : index. \nc sprint : integer function to print on screen.\nc tmp1 : real used to accumulate quantities. \nc tmp2 : real used to accumulate quantities.\nc whicho : integer vector giving the observation in each\nc partition, whicho(nrec).\nc whichn : integer vector giving the observation in each\nc partition, whichn(nrec).\nc ybar : real giving the sample mean.\nc\nc=======================================================================\n implicit none \n\nc+++++Data\n integer ngrid,nrec\n real*8 y(nrec)\n\nc+++++Prior information\n real*8 ab(2),ca,cb\n integer murand,sigmarand,jfr(2)\n real*8 m0,s0\n real*8 tau(2)\n\nc+++++MCMC parameters\n integer mcmcvec(3),nburn,nskip,nsave,ndisplay\n real*8 tune1,tune2,tune3\n\nc+++++Stored output\n real*8 acrate(3),f(ngrid)\n real*8 thetasave(nsave,3)\n real*8 cpo(nrec)\n\nc+++++Current values of the parameters\n real*8 cpar,mu,sigma\n\nc+++++Working space - CPU time\n real*8 sec00,sec0,sec1,sec\n\nc+++++Working space - Density\n real*8 grid(ngrid)\n \nc+++++Working space - Distributions\n real*8 dnrm,dlnrm\n real*8 invcdfnorm\n\nc+++++Working space - General\n integer countero,countern\n integer i,j,je2,k,k1,k2,l\n integer nint,ok,parti,pprn,sprint\n integer whicho(nrec),whichn(nrec)\n real*8 prob\n real*8 quan\n real*8 s,tmp1,tmp2,ybar\n\nc+++++Working space - MCMC scans\n integer dispcount,isave,iscan,nscan,skipcount\n\nc+++++Working space - MH steps\n real*8 cparc\n real*8 logcgkn,logcgko\n real*8 loglikn,logliko\n real*8 logpriorn,logprioro\n real*8 muc,sigma2,sigmac,sigma2c\n real*8 ratio\n\nc+++++Working space - Random number generator\n integer seed(2),seed1,seed2\n real*8 rnorm,rtlnorm\n real runif\n\nc++++ initialize variables\n nburn=mcmcvec(1)\n nskip=mcmcvec(2)\n ndisplay=mcmcvec(3)\n \n ca=ab(1)\n cb=ab(2)\n \n sigma2=sigma**2\n \nc++++ set random number generator\n\n seed1=seed(1)\n seed2=seed(2)\n\n call setall(seed1,seed2)\n\nc+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\nc++++ start the MCMC algorithm\nc+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n isave=0\n skipcount=0\n dispcount=0\n nscan=nburn+(nskip+1)*(nsave)\n \n call cpu_time(sec0)\n sec00=0.d0\n \n ybar=0.d0\n s=0.d0\n do i=1,nrec\n ybar=ybar+y(i) \n end do\n ybar=ybar/dble(nrec)\n \n do i=1,nrec\n s=s+(y(i)-ybar)**2 \n end do\n s=s/dble(nrec)\n\n\nc+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\nc++++ First computation of loglikelihood (to reduce CPU time)\nc+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n logliko=0.d0\n\n do i=1,nrec\n\nc+++++++ check if the user has requested an interrupt\n call rchkusr()\n\nc+++++++ first observation\n if(i.eq.1)then\n\n logliko=dnrm(y(1),mu, sigma, 1)\n\nc+++++++ following observations\n else\n\n nint=2\n prob=1.d0/dble(nint)\n quan=invcdfnorm(prob,mu,sigma,1,0)\n\n countero=0\n \n if(y(i).le.quan) then\n parti=1 \n do l=1,i-1\n if(y(l).le.quan)then\n countero=countero+1\n whicho(countero)=l\n end if \n end do\n else\n parti=2\n do l=1,i-1\n if(y(l).gt.quan)then\n countero=countero+1\n whicho(countero)=l\n end if \n end do\n end if \n\n logliko=logliko+\n & log(2.d0*cpar+dble(2*countero))-\n & log(2.d0*cpar+dble(i-1))\n\n if(countero.eq.0) go to 1\n\n ok=1\n j=2\n do while(ok.eq.1)\n nint=2**j\n je2=j**2\n prob=1.d0/dble(nint)\n \n k1=2*(parti-1)+1\n k2=2*(parti-1)+2\n quan=invcdfnorm(dble(k1)*prob,mu,sigma,1,0)\n \n if(y(i).le.quan)then\n parti=k1\n k=k1\n else\n parti=k2\n k=k2\n end if \n\n countern=0\n \n if(k.eq.1)then\n do l=1,countero\n if(y(whicho(l)).le.quan)then\n countern=countern+1\n whichn(countern)=whicho(l)\n end if \n end do\n else if(k.eq.nint)then\n quan=invcdfnorm(dble(k-1)*prob,mu,sigma,1,0) \n do l=1,countero\n if(y(whicho(l)).gt.quan)then\n countern=countern+1\n whichn(countern)=whicho(l)\n end if \n end do\n else\n tmp1=invcdfnorm(dble(k-1)*prob,mu,sigma,1,0)\n tmp2=invcdfnorm(dble(k )*prob,mu,sigma,1,0)\n\n if(tmp1.ge.tmp2)then\n call rexit(\"Error in the limits\")\n end if \n \n do l=1,countero\n if(y(whicho(l)).gt.tmp1.and.\n & y(whicho(l)).le.tmp2)then\n countern=countern+1\n whichn(countern)=whicho(l)\n end if \n end do\n end if\n \n logliko=logliko+\n & log(2.d0*cpar*dble(je2)+dble(2*countern))-\n & log(2.d0*cpar*dble(je2)+dble( countero))\n\n if(countern.eq.0)then\n ok=0\n else \n countero=countern\n do l=1,countern\n whicho(l)=whichn(l)\n end do\n j=j+1\n end if \n end do\n\n1 continue\n \n logliko=logliko+dnrm(y(i),mu,sigma,1)\n \n end if\n end do\n\n\nc+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\nc++++ Scanning the posterior distribution\nc+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n do iscan=1,nscan\n \nc+++++++ check if the user has requested an interrupt\n call rchkusr()\n \nc++++++++++++++++++++++++++++++++++++++++++++++++++++++++\nc+++++++ Updating mu using a MH step +++\nc++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n \n if(murand.eq.1)then\n muc=rnorm(mu,tune1*sigma/sqrt(dble(nrec)))\n\n loglikn=0.d0\n\n do i=1,nrec\n\nc+++++++++++++ check if the user has requested an interrupt\n call rchkusr()\n\nc+++++++++++++ first observation\n if(i.eq.1)then\n\n loglikn=dnrm(y(1),muc,sigma ,1)\n\nc+++++++++++++ following observations\n else\n\n nint=2\n prob=1.d0/dble(nint)\n quan=invcdfnorm(prob,muc,sigma,1,0)\n\n countero=0\n \n if(y(i).le.quan) then\n parti=1 \n do l=1,i-1\n if(y(l).le.quan)then\n countero=countero+1\n whicho(countero)=l\n end if \n end do\n else\n parti=2 \n do l=1,i-1\n if(y(l).gt.quan)then\n countero=countero+1\n whicho(countero)=l\n end if \n end do\n end if \n\n loglikn=loglikn+\n & log(2.d0*cpar+dble(2*countero))-\n & log(2.d0*cpar+dble(i-1))\n\n if(countero.eq.0) go to 2\n\n ok=1\n j=2\n do while(ok.eq.1)\n nint=2**j\n je2=j**2\n prob=1.d0/dble(nint)\n\n k1=2*(parti-1)+1\n k2=2*(parti-1)+2\n quan=invcdfnorm(dble(k1)*prob,muc,sigma,1,0)\n \n if(y(i).le.quan)then\n parti=k1\n k=k1\n else\n parti=k2\n k=k2\n end if \n \n countern=0\n \n if(k.eq.1)then\n do l=1,countero\n if(y(whicho(l)).le.quan)then\n countern=countern+1\n whichn(countern)=whicho(l)\n end if \n end do\n else if(k.eq.nint)then\n quan=invcdfnorm(dble(k-1)*prob,muc,sigma,1,0) \n do l=1,countero\n if(y(whicho(l)).gt.quan)then\n countern=countern+1\n whichn(countern)=whicho(l)\n end if \n end do\n else\n tmp1=invcdfnorm(dble(k-1)*prob,muc,sigma,1,0)\n tmp2=invcdfnorm(dble(k )*prob,muc,sigma,1,0)\n\n if(tmp1.ge.tmp2)then\n call rexit(\"Error in the limits\")\n end if \n \n do l=1,countero\n if(y(whicho(l)).gt.tmp1.and.\n & y(whicho(l)).le.tmp2)then\n countern=countern+1\n whichn(countern)=whicho(l)\n end if \n end do\n end if\n \n loglikn=loglikn+\n & log(2.d0*cpar*dble(je2)+dble(2*countern))-\n & log(2.d0*cpar*dble(je2)+dble( countero))\n\n if(countern.eq.0)then\n ok=0\n else \n countero=countern\n do l=1,countern\n whicho(l)=whichn(l)\n end do\n j=j+1\n end if \n end do\n\n2 continue\n \n loglikn=loglikn+dnrm(y(i),muc,sigma,1)\n\n end if \n end do \n\nc++++++++++ acceptance step\n\n logpriorn=0.d0\n logprioro=0.d0\n\n if(jfr(1).eq.0)then\n logprioro=dnrm(mu, m0,sqrt(s0),1)\n logpriorn=dnrm(muc,m0,sqrt(s0),1)\n end if\n\n ratio=loglikn-logliko+logpriorn-logprioro\n\n if(log(dble(runif())).lt.ratio)then\n mu=muc\n logliko=loglikn\n acrate(1)=acrate(1)+1.d0\n end if\n\n end if\n\nc++++++++++++++++++++++++++++++++++++++++++++++++++++++++\nc+++++++ Updating sigma using a MH step +++\nc++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n if(sigmarand.eq.1)then\n\n loglikn=0.d0\n\n sigma2c=rtlnorm(log(sigma2),tune2*0.1d0,0,0,.true.,.true.)\n sigmac=sqrt(sigma2c)\n\n logcgkn=dlnrm(sigma2 ,log(sigma2c),tune2*0.1d0,1) \n logcgko=dlnrm(sigma2c,log(sigma2 ),tune2*0.1d0,1) \n\n\n do i=1,nrec\n \nc+++++++++++++ check if the user has requested an interrupt\n call rchkusr()\n\nc+++++++++++++ first observation\n if(i.eq.1)then\n\n loglikn=dnrm(y(1),mu,sigmac ,1)\n\nc+++++++++++++ following observations\n else\n\n nint=2\n prob=1.d0/dble(nint)\n quan=invcdfnorm(prob,mu,sigmac,1,0)\n\n countero=0\n \n if(y(i).le.quan) then\n parti=1\n do l=1,i-1\n if(y(l).le.quan)then\n countero=countero+1\n whicho(countero)=l\n end if \n end do\n else \n parti=2\n do l=1,i-1\n if(y(l).gt.quan)then\n countero=countero+1\n whicho(countero)=l\n end if \n end do\n end if \n\n loglikn=loglikn+\n & log(2.d0*cpar+dble(2*countero))-\n & log(2.d0*cpar+dble(i-1))\n\n if(countero.eq.0) go to 3\n\n ok=1\n j=2\n do while(ok.eq.1)\n nint=2**j\n je2=j**2\n prob=1.d0/dble(nint)\n\n k1=2*(parti-1)+1\n k2=2*(parti-1)+2\n quan=invcdfnorm(dble(k1)*prob,mu,sigmac,1,0)\n \n if(y(i).le.quan)then\n parti=k1\n k=k1\n else\n parti=k2\n k=k2\n end if \n \n countern=0\n \n if(k.eq.1)then\n do l=1,countero\n if(y(whicho(l)).le.quan)then\n countern=countern+1\n whichn(countern)=whicho(l)\n end if \n end do\n else if(k.eq.nint)then\n quan=invcdfnorm(dble(k-1)*prob,mu,sigmac,1,0) \n do l=1,countero\n if(y(whicho(l)).gt.quan)then\n countern=countern+1\n whichn(countern)=whicho(l)\n end if \n end do\n else\n tmp1=invcdfnorm(dble(k-1)*prob,mu,sigmac,1,0)\n tmp2=invcdfnorm(dble(k )*prob,mu,sigmac,1,0)\n\n if(tmp1.ge.tmp2)then\n call rexit(\"Error in the limits\")\n end if \n \n do l=1,countero\n if(y(whicho(l)).gt.tmp1.and.\n & y(whicho(l)).le.tmp2)then\n countern=countern+1\n whichn(countern)=whicho(l)\n end if \n end do\n end if\n \n loglikn=loglikn+\n & log(2.d0*cpar*dble(je2)+dble(2*countern))-\n & log(2.d0*cpar*dble(je2)+dble( countero))\n\n if(countern.eq.0)then\n ok=0\n else \n countero=countern\n do l=1,countern\n whicho(l)=whichn(l)\n end do\n j=j+1\n end if \n end do\n \n3 continue\n \n loglikn=loglikn+dnrm(y(i),mu,sigmac,1)\n\n end if\n end do \n\nc++++++++++ acceptance step\n\n logpriorn=-log(sigma2c)\n logprioro=-log(sigma2)\n\n if(jfr(2).eq.0)then\n logpriorn=-(0.5d0*tau(1)+1.d0)*log(sigma2c)-\n & 0.5d0*tau(2)/sigma2c\n\n logprioro=-(0.5d0*tau(1)+1.d0)*log(sigma2)-\n & 0.5d0*tau(2)/sigma2\n end if\n\n ratio=loglikn-logliko+logcgkn-logcgko+\n & logpriorn-logprioro \n\n\n if(log(dble(runif())).lt.ratio)then\n sigma=sigmac\n sigma2=sigma2c\n logliko=loglikn\n acrate(2)=acrate(2)+1.d0\n end if\n\n end if\n\nc++++++++++++++++++++++++++++++++++++++++++++++++++++++++\nc+++++++ MH to update the c parameter +++\nc++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n if(ca.gt.0.d0)then\n\nc++++++++++ sample candidates\n\n cparc=rtlnorm(log(cpar),tune3*0.2,0,0,.true.,.true.)\n logcgkn=dlnrm(cpar ,log(cparc),tune3*0.2,1) \n logcgko=dlnrm(cparc,log(cpar ),tune3*0.2,1) \n\nc++++++++++ evaluate log-prior for candidate value of the parameters\n\n call dgamma2(cparc,ca,cb,logpriorn) \n\nc++++++++++ evaluate log-prior for current value of parameters\n\n call dgamma2(cpar ,ca,cb,logprioro)\n\nc++++++++++ evaluate log-likelihood\n\n do i=1,nrec\n\nc+++++++++++++ check if the user has requested an interrupt\n call rchkusr()\n\nc++++++++++ first observation\n if(i.eq.1)then\n\n loglikn=dnrm(y(1),mu,sigma ,1)\n\nc++++++++++ following observations\n else\n\n nint=2\n prob=1.d0/dble(nint)\n quan=invcdfnorm(prob,mu,sigma,1,0)\n\n countero=0\n \n if(y(i).le.quan) then\n parti=1 \n do l=1,i-1\n if(y(l).le.quan)then\n countero=countero+1\n whicho(countero)=l\n end if \n end do\n else\n parti=2\n do l=1,i-1\n if(y(l).gt.quan)then\n countero=countero+1\n whicho(countero)=l\n end if \n end do\n end if \n\n loglikn=loglikn+\n & log(2.d0*cparc+dble(2*countero))-\n & log(2.d0*cparc+dble(i-1))\n\n if(countero.eq.0) go to 4\n\n ok=1\n j=2\n do while(ok.eq.1)\n nint=2**j\n je2=j**2\n prob=1.d0/dble(nint)\n\n k1=2*(parti-1)+1\n k2=2*(parti-1)+2\n quan=invcdfnorm(dble(k1)*prob,mu,sigma,1,0)\n \n if(y(i).le.quan)then\n parti=k1\n k=k1\n else\n parti=k2\n k=k2\n end if \n \n countern=0\n \n if(k.eq.1)then\n do l=1,countero\n if(y(whicho(l)).le.quan)then\n countern=countern+1\n whichn(countern)=whicho(l)\n end if \n end do\n else if(k.eq.nint)then\n quan=invcdfnorm(dble(k-1)*prob,mu,sigma,1,0) \n do l=1,countero\n if(y(whicho(l)).gt.quan)then\n countern=countern+1\n whichn(countern)=whicho(l)\n end if \n end do\n else\n tmp1=invcdfnorm(dble(k-1)*prob,mu,sigma,1,0)\n tmp2=invcdfnorm(dble(k )*prob,mu,sigma,1,0)\n\n if(tmp1.ge.tmp2)then\n call rexit(\"Error in the limits\")\n end if \n \n do l=1,countero\n if(y(whicho(l)).gt.tmp1.and.\n & y(whicho(l)).le.tmp2)then\n countern=countern+1\n whichn(countern)=whicho(l)\n end if \n end do\n end if\n \n loglikn=loglikn+\n & log(2.d0*cparc*dble(je2)+dble(2*countern))-\n & log(2.d0*cparc*dble(je2)+dble( countero))\n\n if(countern.eq.0)then\n ok=0\n else \n countero=countern\n do l=1,countern\n whicho(l)=whichn(l)\n end do\n j=j+1\n end if \n end do\n\n4 continue\n \n loglikn=loglikn+dnrm(y(i),mu,sigma,1)\n\n end if\n end do \n\nc++++++++++ acceptance step\n ratio=loglikn+logpriorn-logliko-logprioro+\n & logcgkn-logcgko\n\n if(log(dble(runif())).lt.ratio)then\n cpar=cparc\n acrate(3)=acrate(3)+1.d0\n logliko=loglikn\n end if \n \n end if \n\nc++++++++++++++++++++++++++++++++++++++++++++++++++++++++\nc+++++++ Save samples +++\nc++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n if(iscan.gt.nburn)then\n skipcount=skipcount+1\n if(skipcount.gt.nskip)then\n isave=isave+1\n dispcount=dispcount+1\n \nc+++++++++++++ mu\n thetasave(isave,1)=mu\n\nc+++++++++++++ sigma\n thetasave(isave,2)=sigma\n\nc+++++++++++++ c parameter\n thetasave(isave,3)=cpar\n\nc+++++++++++++ cpo\n\n do i=1,nrec\n\nc++++++++++++++++ check if the user has requested an interrupt\n call rchkusr()\n\n loglikn=0.d0 \n \n nint=2\n tmp1=1.d0/dble(nint)\n quan=invcdfnorm(tmp1,mu,sigma,1,0)\n \n countero=0\n \n if(y(i).le.quan)then\n parti=1\n do l=1,nrec\n if(y(l).le.quan.and.l.ne.i)then\n countero=countero+1\n whicho(countero)=l\n end if \n end do\n else \n parti=2\n do l=1,nrec\n if(y(l).gt.quan.and.l.ne.i)then\n countero=countero+1\n whicho(countero)=l\n end if \n end do\n end if \n \n loglikn=loglikn+\n & log(2.d0*cpar+dble(2*countero))-\n & log(2.d0*cpar+dble(nrec-1))\n\n if(countero.eq.0) go to 5\n\n ok=1\n j=2\n do while(ok.eq.1)\n nint=2**j\n je2=j**2\n prob=1.d0/dble(nint)\n\n k1=2*(parti-1)+1\n k2=2*(parti-1)+2\n quan=invcdfnorm(dble(k1)*prob,mu,sigma,1,0)\n \n if(y(i).le.quan)then\n parti=k1\n k=k1\n else\n parti=k2\n k=k2\n end if \n\n countern=0\n \n if(k.eq.1)then\n do l=1,countero\n if(y(whicho(l)).le.quan.and.\n & whicho(l).ne.i)then\n countern=countern+1\n whichn(countern)=whicho(l)\n end if \n end do\n else if(k.eq.nint)then\n quan=invcdfnorm(dble(k-1)*prob,mu,sigma,1,0) \n do l=1,countero\n if(y(whicho(l)).gt.quan.and.\n & whicho(l).ne.i)then\n countern=countern+1\n whichn(countern)=whicho(l)\n end if \n end do\n else\n tmp1=invcdfnorm(dble(k-1)*prob,mu,sigma,1,0)\n tmp2=invcdfnorm(dble(k )*prob,mu,sigma,1,0)\n\n if(tmp1.ge.tmp2)then\n call rexit(\"Error in the limits\")\n end if \n \n do l=1,countero\n if(whicho(l).ne.i)then\n if(y(whicho(l)).gt.tmp1.and.\n & y(whicho(l)).le.tmp2)then\n countern=countern+1\n whichn(countern)=whicho(l)\n end if\n end if\n end do\n end if\n \n loglikn=loglikn+\n & log(2.d0*cpar*dble(je2)+dble(2*countern))-\n & log(2.d0*cpar*dble(je2)+dble( countero))\n\n if(countern.eq.0)then\n ok=0\n else \n countero=countern\n do l=1,countern\n whicho(l)=whichn(l)\n end do\n j=j+1\n end if \n end do\n\n5 continue\n \n loglikn=loglikn+dnrm(grid(i),mu,sigma,1)\n\n cpo(i)=cpo(i)+1.d0/exp(loglikn)\n end do\n\nc+++++++++++++ density \n\n do i=1,ngrid\n \nc++++++++++++++++ check if the user has requested an interrupt\n call rchkusr()\n\n loglikn=0.d0 \n \n nint=2\n tmp1=1.d0/dble(nint)\n quan=invcdfnorm(tmp1,mu,sigma,1,0)\n \n countero=0\n \n if(grid(i).le.quan)then\n parti=1\n do l=1,nrec\n if(y(l).le.quan)then\n countero=countero+1\n whicho(countero)=l\n end if \n end do\n else\n parti=2\n do l=1,nrec\n if(y(l).gt.quan)then\n countero=countero+1\n whicho(countero)=l\n end if \n end do\n end if \n \n loglikn=loglikn+\n & log(2.d0*cpar+dble(2*countero))-\n & log(2.d0*cpar+dble( nrec))\n\n if(countero.eq.0) go to 6\n\n ok=1\n j=2\n do while(ok.eq.1)\n nint=2**j\n je2=j**2\n prob=1.d0/dble(nint)\n\n k1=2*(parti-1)+1\n k2=2*(parti-1)+2\n quan=invcdfnorm(dble(k1)*prob,mu,sigma,1,0)\n \n if(grid(i).le.quan)then\n parti=k1\n k=k1\n else\n parti=k2\n k=k2\n end if \n\n countern=0\n \n if(k.eq.1)then\n do l=1,countero\n if(y(whicho(l)).le.quan)then\n countern=countern+1\n whichn(countern)=whicho(l)\n end if \n end do\n else if(k.eq.nint)then\n quan=invcdfnorm(dble(k-1)*prob,mu,sigma,1,0) \n do l=1,countero\n if(y(whicho(l)).gt.quan)then\n countern=countern+1\n whichn(countern)=whicho(l)\n end if \n end do\n else\n tmp1=invcdfnorm(dble(k-1)*prob,mu,sigma,1,0)\n tmp2=invcdfnorm(dble(k )*prob,mu,sigma,1,0)\n\n if(tmp1.ge.tmp2)then\n call rexit(\"Error in the limits\")\n end if \n \n do l=1,countero\n if(y(whicho(l)).gt.tmp1.and.\n & y(whicho(l)).le.tmp2)then\n countern=countern+1\n whichn(countern)=whicho(l)\n end if \n end do\n end if\n \n loglikn=loglikn+\n & log(2.d0*cpar*dble(je2)+dble(2*countern))-\n & log(2.d0*cpar*dble(je2)+dble( countero))\n\n if(countern.eq.0)then\n ok=0\n else \n countero=countern\n do l=1,countern\n whicho(l)=whichn(l)\n end do\n j=j+1\n end if \n end do\n\n6 continue\n \n loglikn=loglikn+dnrm(grid(i),mu,sigma,1)\n \n f(i)=f(i)+exp(loglikn)\n\n end do\n\nc+++++++++++++ print\n skipcount = 0\n if(dispcount.ge.ndisplay)then\n call cpu_time(sec1)\n sec00=sec00+(sec1-sec0)\n sec=sec00\n sec0=sec1\n pprn=sprint(isave,nsave,sec)\n dispcount=0\n end if \n end if \n end if\n end do\n\n do i=1,3 \n acrate(i)=acrate(i)/dble(nscan) \n end do \n \n do i=1,nrec\n cpo(i)=dble(nsave)/cpo(i)\n end do\n\n do i=1,ngrid\n f(i)=f(i)/dble(nsave)\n end do\n\n\n return\n end\n\n", "meta": {"hexsha": "d33d4bdc15969cf50e76e30d5f205dd04c0ce870", "size": 38458, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "DPpackage-modified/src/PTudensity.f", "max_stars_repo_name": "kdevick/densitymediation", "max_stars_repo_head_hexsha": "12bd192f922dae5c8adb8b5573ba8718ea08e9ee", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-16T03:35:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-16T03:35:49.000Z", "max_issues_repo_path": "DPpackage-modified/src/PTudensity.f", "max_issues_repo_name": "kdevick/densitymediation", "max_issues_repo_head_hexsha": "12bd192f922dae5c8adb8b5573ba8718ea08e9ee", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "DPpackage-modified/src/PTudensity.f", "max_forks_repo_name": "kdevick/densitymediation", "max_forks_repo_head_hexsha": "12bd192f922dae5c8adb8b5573ba8718ea08e9ee", "max_forks_repo_licenses": ["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.296969697, "max_line_length": 94, "alphanum_fraction": 0.37695668, "num_tokens": 8787, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513759047848, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6552122569641382}} {"text": "subroutine gausshermite(x,n,par,npar,ghfun)\n\n!replicates APOGEE's gausshermite.pro\n\nuse share, only: dp\n\n!Input/output\nreal(dp), intent(in)\t:: x(n) ! abscissae\nreal(dp), intent(in) :: par(npar) ! height, center, sigma,H0, H1, H2, H3, H4\ninteger, intent(in) \t:: n,npar ! size of x and par\nreal(dp), intent(out)\t:: ghfun(n) ! Hermite function\n\n!locals\ninteger, parameter\t\t:: nherm=5\nreal(dp), parameter\t\t:: pi=3.1415926535897932384626433832795_dp\nreal(dp), parameter\t\t:: sqr2=sqrt(2._dp),sqr3=sqrt(3._dp)\nreal(dp), parameter\t\t:: sqr24=sqrt(24._dp),sqrpi=sqrt(pi)\ninteger\t\t\t\t\t:: i\nreal(dp)\t\t\t\t:: hpar(nherm)\nreal(dp)\t\t\t\t:: hh(nherm),w(n)\n\nhpar(1:nherm)=0.0_dp\nif (npar > 3)\thpar(1:npar-3)=par(4:npar)\n\nw(1:n) = (x(1:n) - par(2))/par(3)\n\nhh(1) = hpar(1) - hpar(3)/sqr2 + hpar(5)*3._dp/sqr24\nhh(2) = hpar(2) - hpar(4)*3._dp/sqrt(6._dp)\nhh(3) = hpar(3)/sqr2 - hpar(5)*(6._dp/sqr24)\nhh(4) = hpar(4)/sqrt(6._dp)\nhh(5) = hpar(5)/sqr24\n\nghfun(1:n)=0.0_dp\ndo i=1,nherm\n\tghfun(1:n)= ghfun(1:n) + hh(i)*w(1:n)**(i-1)\nenddo\nghfun(1:n)=ghfun(1:n)*exp(-0.5_dp*w(1:n)**2)*par(1)/sqrt(2._dp*pi)\n\nend subroutine gausshermite\n", "meta": {"hexsha": "26be513b7cf868b051548b1fbf27db64186f4687", "size": 1122, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ferre/src/gausshermite.f90", "max_stars_repo_name": "dnidever/apogee", "max_stars_repo_head_hexsha": "83ad7496a0b4193df9e2c01b06dc36cb879ea6c1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2019-04-11T13:35:24.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-14T06:12:51.000Z", "max_issues_repo_path": "ferre/src/gausshermite.f90", "max_issues_repo_name": "dnidever/apogee", "max_issues_repo_head_hexsha": "83ad7496a0b4193df9e2c01b06dc36cb879ea6c1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ferre/src/gausshermite.f90", "max_forks_repo_name": "dnidever/apogee", "max_forks_repo_head_hexsha": "83ad7496a0b4193df9e2c01b06dc36cb879ea6c1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2018-09-20T22:07:43.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-15T07:13:38.000Z", "avg_line_length": 28.05, "max_line_length": 80, "alphanum_fraction": 0.632798574, "num_tokens": 517, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853654, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6551558035749906}} {"text": "C++*****************************************************************\nC Set of routines for FFT computation (without NAG)\nC Contains:\nC FFT_2D_FOURN, FFT_2D_FOURN_DBLE, FFT_1D, FOURN2, FOURN1, RECENTRE\nC\nC Warning: this version divides by NX*NY the inverse FFT\nC\nC JLP\nC Version 21-03-96\nC--******************************************************************\nC********************************************************************\nC FFT 2D_FOURN routine\nC Input:\nC TR, TI: real part and imaginary part (input/output) of the image\nC\nC KOD=1, or 2 direct\nC KOD=-1, or -2 inverse\nC KOD=-2, or 2: power spectrum, and phase\nC********************************************************************\n SUBROUTINE FFT_2D_FOURN(TR,TI,NX,NY,IDIM,KOD)\n REAL*4 TR(IDIM,*),TI(IDIM,*)\n REAL PI\n INTEGER NX,NY,KOD,ISIGN\n PI=3.14159265358979323846\n \nC Check the size (should be a power of 2 : NX=2**M and NY=NX)\nC M = ln(NX)/ln(2)\n M=0\n NF=1\n1 M=M+1\n NF=NF+NF\n IF(NF.LT.NX) GOTO 1\nC PRINT *,'M,NX,NF',M,NX,NF\n \n IF((NF.NE.NX).OR.(NX.NE.NY))THEN\n WRITE(6,11) NX,NY\n11 FORMAT(' FFT_2D/Fatal error: Wrong size for the input image',/,\n 1 ' (should be square and power of two)',/,' NX, NY :',I5,1X,I5)\n STOP\n ENDIF\n \nC Flag for direct or inverse FFT:\n IF(KOD.LT.0) THEN\n ISIGN = -1\n ELSE\n ISIGN = 1\n ENDIF\n\nC Actual FFT now:\n CALL FOURN2(TR,TI,NX,NY,IDIM,ISIGN)\n\nC Check the value of KOD:\n IF(IABS(KOD).EQ.2)THEN\nC Power and phase spectrum:\n DO 60 J=1,NY\n DO 60 I=1,NX\n AR=TR(I,J)\n AI=TI(I,J)\n TR(I,J)=SQRT(AR*AR+AI*AI)\n IF(AR.NE.0.) THEN\n TI(I,J)=ATAN(AI/AR)\n IF(ACOS(AI/AR).LT.0.)TI(I,J)=TI(I,J)+PI\n ELSE\n IF(AI.GE.0.)THEN\n TI(I,J)=PI/2.\n ELSE\n TI(I,J)=3.*PI/2.\n ENDIF\n ENDIF\n IF(TI(I,J).LT.0.)TI(I,J)=TI(I,J)+2.*PI\n60 CONTINUE\n ENDIF\n\n RETURN\n END\nC********************************************************************\nC FFT 2D routine for double precision arrays\nC (NB:it is faster in FFT_NAG) \nC\nC Input:\nC TR, TI: real part and imaginary part (input/output) of the image\nC KOD: flag for direct(=1) or inverse(=-1) FFT:\nC\nC********************************************************************\n SUBROUTINE FFT_2D_FOURN_DBLE(TR,TI,NX,NY,IDIM,KOD)\n INTEGER*4 NX,NY,KOD,M,NF\n REAL*8 TR(IDIM,*),TI(IDIM,*)\n \nC Check the size (should be a power of 2 : NX=2**M and NY=NX)\nC M = ln(NX)/ln(2)\n M=0\n NF=1\n1 M=M+1\n NF=NF+NF\n IF(NF.LT.NX) GOTO 1\nC PRINT *,'M,NX,NF',M,NX,NF\n \n IF((NF.NE.NX).OR.(NX.NE.NY))THEN\n WRITE(6,11) NX,NY\n11 FORMAT(' FFT_2D_DOUBLE/Fatal error: Wrong size',\n 1 ' for the input image',/,\n 1 ' (should be square and power of two)',/,' NX, NY :',I5,1X,I5)\n STOP\n ENDIF\n \nC Actual FFT now:\n CALL FOURN2_R8(TR,TI,NX,NY,NX,KOD)\n\n RETURN\n END\n \nC******************************************************************\nC FOURN2 routine\nC Input:\nC TR, TI: real part and imaginary part (input/output) of the image\nC\nC ISIGN=1 direct\nC ISIGN=-1 inverse \nC********************************************************************\n SUBROUTINE FOURN2(TR,TI,NX,NY,IDIM,ISIGN)\n REAL*4 TR(IDIM,*),TI(IDIM,*)\n REAL DATA(1024*1024*2)\n INTEGER NN(2),ISIGN\n\nC Check size:\n IF(NX.GT.1024.OR.NY.GT.1024)THEN\n WRITE(6,*) ' FOURN2/Fatal error: maximum size',\n 1 ' allowed is (1024 x 1024)'\n STOP\n ENDIF\n\nC Rearranging the data for FOURN1\nC (real and complex value ordered in a standard fortran array...)\n K=1\n DO J=1,NY\n DO I=1,NX\n DATA(K)=TR(I,J)\n DATA(K+1)=TI(I,J)\n K = K+2\n END DO\n END DO\n\nC Actual FFT:\n NN(1)=NX\n NN(2)=NY\n CALL FOURN1(DATA,NN,2,ISIGN)\n\nC Rearranging the data\n K=1\n DO J=1,NY\n DO I=1,NX\n TR(I,J)=DATA(K)\n TI(I,J)=DATA(K+1)\n K = K+2\n END DO\n END DO\n\n RETURN\n END\nC******************************************************************\nC FOURN2_R8 routine\nC Input:\nC TR, TI: real part and imaginary part (input/output) of the image\nC\nC ISIGN=1 direct\nC ISIGN=-1 inverse \nC********************************************************************\n SUBROUTINE FOURN2_R8(TR,TI,NX,NY,IDIM,ISIGN)\n INTEGER*4 I,J,NX,NY,IDIM,NN(2),ISIGN\n REAL*8 TR(IDIM,*),TI(IDIM,*)\n REAL*4 DATA(1024*1024*2)\n\nC Check size:\n IF(NX.GT.512.OR.NY.GT.512)THEN\n WRITE(6,*) ' FOURN2_R8/Fatal error: maximum size',\n 1 ' allowed is 1024x1024'\n STOP\n ENDIF\n\nC Rearranging the data for FOURN1\nC (real and complex value ordered in a standard fortran array...)\n K=1\n DO J=1,NY\n DO I=1,NX\n DATA(K)=TR(I,J)\n DATA(K+1)=TI(I,J)\n K = K+2\n END DO\n END DO\n\nC Actual FFT:\n NN(1)=NX\n NN(2)=NY\n CALL FOURN1(DATA,NN,2,ISIGN)\n\nC Rearranging the data\n K=1\n DO J=1,NY\n DO I=1,NX\n TR(I,J)=DATA(K)\n TI(I,J)=DATA(K+1)\n K = K+2\n END DO\n END DO\n\n RETURN\n END\nC********************************************************************\nC FFT 1D routine\nC Input:\nC TR, TI: real part and imaginary part (input/output) of the image\nC\nC********************************************************************\n SUBROUTINE FFT_1D_FOURN(RE,IM,NX,NY,IDIM,KOD)\n INTEGER NX,NY,IDIM,NF,M,I,J,KOD\n REAL RE(IDIM,*),IM(IDIM,*)\n REAL TR(512),TI(512),XNORM\n\nC Check the size (should be a power of 2 : NY=2**M)\nC M = ln(NY)/ln(2)\n M=0\n NF=1\n1 M=M+1\n NF=NF+NF\n IF(NF.LT.NY) GOTO 1\n PRINT *,'FFT1D/M,NY,NF',M,NY,NF\n IF(NF.NE.NY.OR.NY.GT.512)THEN\n WRITE(6,8)\n8 FORMAT('FFT_1D_FOURN/ Fatal error: NY not a power of two',\n 1 ' or larger than 512')\n ENDIF\n XNORM=SQRT(REAL(NY))\nC Main loop on all the columns:\n DO I=1,NX\nC Transfer to temporary array:\n DO J=1,NY\n TR(J)=RE(I,J)\n TI(J)=IM(I,J)\n END DO\n CALL FFT_1D_MONODIM(TR,TI,NY,M)\nC Transfer from temporary array and normalization:\n DO J=1,NY\n RE(I,J)=TR(J)/XNORM\n IM(I,J)=TI(J)/XNORM\n END DO\n END DO\n RETURN\n END\nC********************************************************************\n SUBROUTINE FFT_1D_MONODIM(TR,TI,NX,M)\n REAL TR(512),TI(512)\n INTEGER NX,NS2,NM1,I,J,K\n INTEGER M,L1,LE\n REAL AR,AI,PI,ANG,CST\n REAL BR,BI,UA,UI,UR,WR,WI\n PI=3.14159265358979323846\n \nC Sorting the input array:\n NS2=NX/2\n NM1=NX-1\n J=1\n DO 10 I=1,NM1\nC Swap I and J:\n IF(I.LT.J) THEN\n AR=TR(J)\n AI=TI(J)\n TR(J)=TR(I)\n TI(J)=TI(I)\n TR(I)=AR\n TI(I)=AI\n ENDIF\n K=NS2\n6 IF(K.GE.J) GOTO7\n J=J-K\n K=K/2\n GOTO 6\n7 J=J+K\n10 CONTINUE\nC\nC Computing the FFT:\n LE=1\n ANG=PI\n CST=0.5\n DO 40 K=1,M\n L1=LE\n LE=LE*2\n UR=1.0\n UI=0.0\n WR=COS(ANG)\n WI=SIN(ANG)\n ANG=CST*ANG\nC\n DO 30 J=1,L1\n DO 20 I=J,NX,LE\n BR=TR(I)\n BI=TI(I)\n IP=I+L1\n AR=TR(IP)*UR-TI(IP)*UI\n AI=TR(IP)*UI-TI(IP)*UR\n TR(IP)=BR-AR\n TI(IP)=BI-AI\n TR(I)=BR+AR\n TI(I)=BI+AI\n20 CONTINUE\n UA=UR*WR-UI*WI\n UI=UR*WI+UI*WR\n UR=UA\n30 CONTINUE\n40 CONTINUE\n \nC PRINT *,'M',M\nC PRINT *,'L1,NM1,NX,CST,NS2',L1,NM1,NX,CST,NS2\n RETURN\n END\nC**********************************************************************\nC++*******************************************************************\nC FOURN1\nC From \"Numerical Recipees\" p 451\nC\nC Replaces DATA by its NDIM-dimensional disccrete Fourier transform, if\nC SIGN is input as 1.\nC NN is an integer array of length NDIM, containing the lengths of each\nC dimension (number of complex values), which MUST all be powers of 2.\nC DATA is a real array of length twice the product of these lengths, in\nC which the data are stored as in a multidimensional complex Fortran array.\nC\nC If ISIGN is input as -1, DATA is replaced by its inverse transform\nC\nC Warning: This routine divides by NX*NY the inverse transform.\nC\nC JLP\nC Version 03-08-2008\nC--*********************************************************************\n subroutine FOURN1(data,nn,ndim,isign)\n \nC Double precision for trigonometric recurrences:\n real*8 wr,wi,wpr,wpi,wtemp,theta\n \n integer*4 ndim,isign,ntot,nprev,n,i1,i2,i3,i2rev,i3rev\n integer*4 ibit,ifp1,ifp2,ip1,ip2,k1,k2,idim,nrem\n integer*4 nn(*)\n real*4 data(*),tempr,tempi\n \nC Compute total number of complex values:\n ntot=1\n do 11 idim=1,ndim\n ntot=ntot*nn(idim)\n11 continue\n \n nprev=1\n \nC Main loop over the dimensions:\n do 18 idim=1,ndim\n n=nn(idim)\n nrem=ntot/(n*nprev)\n ip1=2*nprev\n ip2=ip1*n\n ip3=ip2*nrem\n i2rev=1\n \nC This is the bit reversal routine\nC (to set up the book keeping for the next step):\n do 14 i2=1,ip2,ip1\n if(i2.lt.i2rev)then\n do 13 i1=i2,i2+ip1-2,2\n do 12 i3=i1,ip3,ip2\n i3rev=i2rev+i3-i2\nC Swap real array (i3 <-> i3rev) and imaginary array (i3+1 <-> i3rev+1)\n tempr=data(i3)\n tempi=data(i3+1)\n data(i3)=data(i3rev)\n data(i3+1)=data(i3rev+1)\n data(i3rev)=tempr\n data(i3rev+1)=tempi\n12 continue\n13 continue\n endif\n ibit=ip2/2\n1 if((ibit.ge.ip1).and.(i2rev.gt.ibit))then\n i2rev=i2rev-ibit\n ibit=ibit/2\n go to 1\n endif\n i2rev=i2rev+ibit\n14 continue\n \nC Here begins the Danielson-Lanczos section of the routine:\nC (i.e. iterative processing of the data)\n ifp1=ip1\n2 if(ifp1.lt.ip2)then\n ifp2=2*ifp1\nC Initialize for the trig. recurrence:\nC JLP2008: there was a minus sign here, which is wrong according\nC to Num. recipees in C p 524\nC (This caused a central symmetry of the transform until August 2008...)\n theta=6.28318530717959*float(isign)/(ifp2/ip1)\n wpr=-2.d0*dsin(0.5d0*theta)**2\n wpi=dsin(theta)\n wr=1.d0\n wi=0.d0\n do 17 i3=1,ifp1,ip1\n do 16 i1=i3,i3+ip1-2,2\n do 15 i2=i1,ip3,ifp2\n k1=i2\n k2=k1+ifp1\nC Danielson-Lanczos formula:\n tempr=sngl(wr)*data(k2)-sngl(wi)*data(k2+1)\n tempi=sngl(wr)*data(k2+1)+sngl(wi)*data(k2)\n data(k2)=data(k1)-tempr\n data(k2+1)=data(k1+1)-tempi\n data(k1)=data(k1)+tempr\n data(k1+1)=data(k1+1)+tempi\n15 continue\n16 continue\n \nC Trigonometric recurrence:\n wtemp=wr\n wr=wr*wpr-wi*wpi+wr\n wi=wi*wpr+wtemp*wpi+wi\n17 continue\n ifp1=ifp2\n go to 2\n endif\n nprev=n*nprev\n18 continue\n\nC Divides inverse transform by the total size of the array:\n if(isign.le.0)then\n stot=float(ntot)\n do 46 k=1,2*ntot\n data(k)=data(k)/stot\n46 continue\n endif\n\n return\n end\nC*********************************************************************\n SUBROUTINE RECENTRE(INPUT,OUTPUT,NX,NY,IDIM)\n REAL*4 INPUT(IDIM,*),OUTPUT(IDIM,*)\n INTEGER*4 NX,NY,NNX,NNY\n \n NNX=2*(NX/2)\n NNY=2*(NY/2)\n \n IF((NX.NE.NNX).OR.(NY.NE.NNY))THEN\n PRINT *,' RECENTRE/Fatal error: NX or NY not even numbers'\n PRINT *,' NX, NY =',NX,NY\n STOP\n ENDIF\n \nC Uses a buffer to allow for the same array in input and output:\n DO J=1,NY/2\n DO I=1,NX/2\n X1=INPUT(I,J)\n X2=INPUT(I+NX/2,J+NY/2)\n X3=INPUT(I+NX/2,J)\n X4=INPUT(I,J+NY/2)\nC\n OUTPUT(I+NX/2,J+NY/2)=X1\n OUTPUT(I,J)=X2\n OUTPUT(I,J+NY/2)=X3\n OUTPUT(I+NX/2,J)=X4\n END DO\n END DO\n RETURN\n END\n", "meta": {"hexsha": "953b1f6a33f2f267e217050c09ef51fccf980d08", "size": 12762, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "jlp_numeric/fft_num/fft_fourn.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/fft_fourn.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/fft_fourn.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": 27.3276231263, "max_line_length": 75, "alphanum_fraction": 0.4746121298, "num_tokens": 4066, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995482, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6551558000190092}} {"text": "!---------------------------------------------------------------------------!\r\n! \t NS2D: two-dimensional Navier-Stokes solver in periodic domain\r\n!---------------------------------------------------------------------------!\r\n! \t Domain: (x,y) in periodic [0,2pi] \r\n!-----------------------------------------------------------------!\r\n! \t\t two-dimensional navier-stokes solver \r\n! vorticity-stream function formulation\r\n!\t\t 4th-order Arakawa scheme (or compact scheme) for nonlinear term\r\n!\t 4th order compact Pade scheme for spatial derivaties (linear terms)\r\n!\t\t 3rd order Runge-Kutta for temporal discritization\r\n! periodic boundary conditions only\r\n! \r\n!\r\n!\t\t needs: input.txt ==> header file (options for the solver)\r\n! and/or initial.dat ==> initial condition for vorticity field\r\n! and/or final.dat ==> saved condition\r\n!\r\n! results: fort.500\t==> vorticity field (fort.200 is normalized)\r\n!\t\t\t\t fort.600\t==> energy spectrum (all frequencies)\r\n!\t\t\t\t fort.700 ==> energy spectrum (angle avaraged)\r\n!\t\t\t\t fort.300\t==> mid line vorticity values (along y)\r\n!\t\t\t\t fort.400\t==> mid line vorticity values (along x) \r\n!\t\t\t\t fort.800\t==> 2nd order structure function\r\n! fort.100000 ==> filtered dns data\r\n! \r\n!\r\n!---------------------------------------------------------------------------!\r\n!Case: Decaying turbulence problem\r\n!---------------------------------------------------------------------------!\r\n!Omer San, Oklahoma State University, cfdlab.osu@gmail.com \r\n!Updated: June 07, 2016\r\n!---------------------------------------------------------------------------!\r\n\r\nprogram ns2d\r\nimplicit none\r\ninteger::nd,nt,nf,ion,ifil,ich,isc,isgs,idyn,ivis,NA,ipr\r\ninteger::nx,ny\r\ninteger::fw,ifile,ikolmog,idt,isolver\r\ninteger::i,j,n\r\ndouble precision::re,dt,kappa2,sma,csd,delta,del,betaAD,afil\r\ndouble precision::pi,lx,ly,dx,dy,rate,en0,enf0,Afor,kfor,nu\r\ndouble precision::time,cpuinit,cpufinal,cfl,en,ew,cpuh,delc\r\ndouble precision::Akolmog,kkolmog,cflc,dta,dtv,neuc,lambda,Rec\r\ndouble precision,dimension(:,:),allocatable::w,wf\r\n\r\ncommon /solver/ isolver\r\ncommon /forcing/ Akolmog,kkolmog,ikolmog\r\ncommon /kolmog/ Afor,kfor,nu\r\ncommon /LESmodels/ isgs\r\ncommon /filtering/ ifil\r\ncommon /dyncoeff/ csd\r\ncommon /ADmodel/ betaAD,NA\r\ncommon /smaconstant/ sma,del\r\ncommon /clarkconstant/ delc\r\ncommon /dynconstant/ kappa2\r\ncommon /Padefilter/ afil\r\ncommon /viskernel/ ivis\r\ncommon /dynmodel/ idyn\r\ncommon /adaptive/ cflc,dta,dtv\r\n\r\n! read input file:\r\nopen(7,file='input.txt')\r\nread(7,*)nd\r\nread(7,*)nt\r\nread(7,*)re\r\nread(7,*)dt\r\nread(7,*)idt\r\nread(7,*)cflc\r\nread(7,*)neuc\r\nread(7,*)nf\r\nread(7,*)isolver\r\nread(7,*)ipr\r\nread(7,*)kfor\r\nread(7,*)Afor\r\nread(7,*)lambda\r\nread(7,*)ion\r\nread(7,*)ifil\r\nread(7,*)afil\r\nread(7,*)isgs\r\nread(7,*)idyn\r\nread(7,*)ivis\r\nread(7,*)kappa2\r\nread(7,*)sma\r\nread(7,*)delta\r\nread(7,*)NA\r\nread(7,*)betaAD\r\nread(7,*)isc\r\nread(7,*)ich\r\nclose(7)\r\nif (ich.ne.19) then\r\nwrite(*,*)'check input.txt file..'\r\nstop\r\nend if\r\n\r\nif (ivis.eq.2) then !correction to kappa for leith\r\n kappa2 = dsqrt(kappa2)**3\r\nend if\r\n\r\nif(ipr.eq.5) then !if Kolmogorov flow (forcing)\r\nRec = dsqrt(2.0d0)\r\nikolmog = 1\r\nAkolmog = Afor\r\nkkolmog = kfor\r\nnu = dsqrt(Afor/(lambda*Rec*(kfor**4)))\r\nre = 1.0d0/nu !recompute Re\r\nelse\r\nikolmog = 0\r\nAkolmog = 0.0d0\r\nkkolmog = 0.0d0\r\nnu = 1.0d0/re\r\nend if\r\n\r\n! some parameters\r\nnx=nd\r\nny=nd\r\n\r\npi=4.0d0*datan(1.0d0)\r\nlx=2.0d0*pi\r\nly=2.0d0*pi\r\n\r\n\r\ndx=lx/dfloat(nx)\r\ndy=ly/dfloat(ny)\r\n\r\ndtv = neuc*nu/(dx**2)\r\n\r\n!filter length scale\r\ndel=dsqrt(dx*delta*dy*delta)\r\ndelc=del\r\n\r\nifile=0\r\ntime=0.0d0\r\ncsd = 0.0d0\r\n\r\n\r\n! allocate the vorticity array:\r\nallocate(w(-2:nx+2,-2:ny+2))\r\nallocate(wf(-2:nx+2,-2:ny+2))\r\n\r\n! initial conditions:\r\ncall ic(nx,ny,dx,dy,ion,ipr,time,w)\r\n\r\n!open(77,file='spec-time.plt')\r\n!write(77,*)'variables =\"k\",\"E(k)\"'\r\n\r\n\r\n! open(5,file='initial.plt')\r\n! write(5,*) 'variables =\"x\",\"y\",\"w\"'\r\n! write(5,51)'zone f=point i=',nx+1,',j=',ny+1,',t=\"time',time,'\"'\r\n! do j=0,ny\r\n! do i=0,nx\r\n! write(5,52) dfloat(i)*dx,dfloat(j)*dy,w(i,j)\r\n! end do\r\n! end do\r\n! close(5)\r\n\r\n\r\n\r\n! ! write initial voryicity field in tecplot format:\r\ncall outw(ifile,nx,ny,dx,dy,time,w)\r\n! call spec(ifile,nx,ny,time,w)\r\n! call line(ifile,nx,ny,dx,dy,time,w)\r\n! call strfun(ifile,nx,ny,time,w)\r\n\r\n\r\n! compute history:\r\ncall history(nx,ny,dx,dy,dt,w,cfl,en,ew)\r\nen0=en\r\n\r\n!adaptive time stepping\r\nif(idt.eq.1) then\r\ndt = dta\r\nend if\r\n\r\n\r\n!check for initial cfl number\r\n111 continue\r\nif (cfl.ge.cflc) then\r\ndt = 0.5d0*dt\r\ncfl= 0.5d0*cfl\r\nnt = nt*2\r\ngoto 111\r\nend if\r\n\r\nopen(66,file=\"cfl.txt\")\r\nwrite(66,*)'idt= ',idt\r\nwrite(66,*)'time step= ',dt\r\nwrite(66,*)'dtv = ',dtv\r\nwrite(66,*)'CFL = ',cfl\r\nwrite(66,*)'nu = ',nu\r\nwrite(66,*)'1/nu = ',1.0d0/nu\r\nclose(66)\r\n\r\n\r\nopen(11,file='history_rate.plt')\r\nwrite(11,*) 'variables =\"t\",\"e\"'\r\n\r\nopen(12,file='history_rate_filtered.plt')\r\nwrite(12,*) 'variables =\"t\",\"e\"'\r\n \r\n\r\n! write historty file:\r\nopen(9,file='history.plt')\r\nwrite(9,*) 'variables =\"t\",\"E\",\"Q\",\"cfl\",\"max_w\",\"min_w\"'\r\nwrite(9,19) time,en,ew,cfl,maxval(w),minval(w)\r\nif(isc.eq.1) write(*,18) time,en,cfl\r\n\r\n! write historty file for dynamic coefficient:\r\nif(isgs.eq.9) then\r\n\tif (ivis.eq.1) then\r\n\topen(99,file='history_dyn.plt')\r\n\twrite(99,*) 'variables =\"t\",\"c\"'\r\n else\r\n\topen(99,file='history_dyn.plt')\r\n\twrite(99,*) 'variables =\"t\",\"c\"'\r\n end if\r\nend if\r\n\r\n\r\n!Filtered DNS data\r\nif (isgs.eq.0) then\r\n! compute filtered history\r\ncall filter(nx,ny,w,wf)\r\ncall history(nx,ny,dx,dy,dt,wf,cfl,en,ew)\r\nenf0=en\r\n\r\n! write filtered historty file\r\nopen(8,file='history_filtered.plt')\r\nwrite(8,*) 'variables =\"t\",\"E\",\"Q\",\"cfl\",\"max_w\",\"min_w\"'\r\nwrite(8,19) time,en,ew,cfl,maxval(wf),minval(wf)\r\n\r\n\t! call outw(100000+ifile,nx,ny,dx,dy,time,wf)\r\n\t! call spec(100000+ifile,nx,ny,time,wf)\r\n ! call line(100000+ifile,nx,ny,dx,dy,time,wf)\r\n\t! call strfun(100000+ifile,nx,ny,time,wf)\r\n\r\nend if\r\n\r\ncall cpu_time(cpuinit)\r\n\r\nif (nt.le.nf) nf=nt\r\nfw= max(1,nt/nf) !writing frequency\r\n\r\n\r\n!=====================================\r\n!time integration is starting...\r\n!=====================================\r\ndo n=1,nt\r\n\r\n\ttime=time+dt\r\n\r\n\t!tvd 3rd-order rk scheme (3-stage)\r\n\tcall rk3tvd(nx,ny,dx,dy,dt,re,w)\r\n\r\n\t\r\n\t! write on the log file\r\n\tcall history(nx,ny,dx,dy,dt,w,cfl,en,ew)\r\n\twrite(9,19) time,en,ew,cfl,maxval(w),minval(w)\r\n \r\n\tif(isc.eq.1) write(*,18) time,en,cfl\r\n\t\r\n\tif(isgs.eq.9) then\r\n\t\tif (ivis.eq.1) then\r\n\t\twrite(99,*) time,dsqrt(csd/(dx*dy))\r\n \telse\r\n\t\twrite(99,*) time,(csd/(del**3))**(1.0d0/3.0d0)\r\n \tend if\r\n\tend if\r\n\r\n\t!adaptive time stepping\r\n\tif(idt.eq.1) then\r\n\tdt = dta\r\n\tend if\r\n\r\n\t!compute dissipation rate\r\n rate = -(en-en0)/dt\r\n en0=en\r\n write(11,*)time-dt*0.5d0, rate\r\n \r\n\tif (isgs.eq.0) then\t\r\n\tcall filter(nx,ny,w,wf)\r\n\tcall history(nx,ny,dx,dy,dt,wf,cfl,en,ew)\r\n\twrite(8,19) time,en,ew,cfl,maxval(wf),minval(wf)\r\n !compute dissipation rate\r\n rate = -(en-enf0)/dt\r\n enf0=en\r\n write(12,*)time-dt*0.5d0, rate\r\n\tend if\r\n\r\n\r\n\r\n\t!writing vorticity field:\r\n\tif (mod(n,fw).eq.0) then\r\n\tifile=ifile+1\r\n\r\n\tcall outw(ifile,nx,ny,dx,dy,time,w)\r\n\t! call spec(ifile,nx,ny,time,w)\r\n ! call line(ifile,nx,ny,dx,dy,time,w)\r\n\t! call strfun(ifile,nx,ny,time,w)\t\r\n\t\r\n\t! if (isgs.eq.0) then\t\r\n\t! call filter(nx,ny,w,wf)\r\n\t! call outw(100000+ifile,nx,ny,dx,dy,time,wf)\r\n\t! call spec(100000+ifile,nx,ny,time,wf)\r\n ! call line(100000+ifile,nx,ny,dx,dy,time,wf)\r\n\t! call strfun(100000+ifile,nx,ny,time,wf)\r\n\t! end if\r\n\t\t\r\n\tend if\r\n\t\r\n\r\n\tcall cpu_time(cpufinal)\r\n\tcpuh=(cpufinal-cpuinit)/60./60.\r\n\tif(cpuh.ge.503.0d0) goto 44\r\n\r\nend do\r\n\r\n44 continue\r\n\r\nif (isgs.eq.0) close(8)\r\nif (isgs.eq.9) close(99)\r\nclose(9)\r\nclose(11)\r\nclose(12)\r\n!close(77)\r\n\r\ncall cpu_time(cpufinal)\r\n\r\nopen(66,file=\"cpu.txt\")\r\nwrite(66,*)'cpu time = ',(cpufinal-cpuinit), ' second'\r\nwrite(66,*)'cpu time = ',(cpufinal-cpuinit)/60./60., ' hrs'\r\nwrite(66,*)'Max time = ',time\r\nwrite(66,*)'Number of time = ',n\r\nwrite(66,*)'Time step = ',dt\r\nclose(66)\r\n\r\ncall saved(nx,ny,time,w)\r\n\r\n\r\n! open(5,file='final.plt')\r\n! write(5,*) 'variables =\"x\",\"y\",\"w\"'\r\n! write(5,51)'zone f=point i=',nx+1,',j=',ny+1,',t=\"time',time,'\"'\r\n! do j=0,ny\r\n! do i=0,nx\r\n! write(5,52) dfloat(i)*dx,dfloat(j)*dy,w(i,j)\r\n! end do\r\n! end do\r\n! close(5)\r\n\r\n51 format(a16,i8,a4,i8,a10,f10.4,a3)\r\n52 format(3es16.6)\r\n19 format(6es16.6)\r\n18 format(3es18.8)\r\n\r\n\r\n!Exact solution for TGV problem\r\nif (ipr.eq.1) call tgvnorm(nx,ny,dx,dy,time,re,w)\r\n\r\n\r\nend \r\n\r\n!---------------------------------------------------------------------------!\r\n!Compute 2D vorticity field from the energy spectrum\r\n!Periodic, equidistant grid\r\n!---------------------------------------------------------------------------!\r\nsubroutine spec2field2d(nx,ny,dx,dy,w)\r\nimplicit none\r\ninteger::nx,ny,ni,nj,ii,jj\r\ndouble precision ::w(-2:nx+2,-2:ny+2)\r\ndouble precision ::ran,pi,kk,E4,dx,dy\r\ndouble precision,parameter:: tiny=1.0d-10\r\ndouble precision,allocatable ::data1d(:),phase2d(:,:,:),ksi(:,:),eta(:,:)\r\ndouble precision,allocatable ::kx(:),ky(:),ww(:,:)\r\ninteger::i,j,k,isign,ndim,nn(2),seed\r\n\r\nseed = 19\r\n\r\n!expand it to dns grid\r\n\r\nni = nx\r\nnj = ny\r\n\r\nnx = 2048\r\nny = 2048\r\n\r\nif (ni.ge.2048) nx=ni\r\nif (nj.ge.2048) ny=nj\r\n\r\nii = nx/ni\r\njj = ny/nj\r\n\r\nndim =2\r\nnn(1)=nx\r\nnn(2)=ny\r\n\r\nallocate(kx(0:nx-1),ky(0:ny-1))\r\nallocate(ksi(0:nx/2,0:ny/2),eta(0:nx/2,0:ny/2))\r\nallocate(data1d(2*nx*ny))\r\nallocate(phase2d(2,0:nx-1,0:ny-1))\r\nallocate(ww(0:nx,0:ny))\r\n\r\n!Set seed for the random number generator between [0,1]\r\nCALL RANDOM_SEED(seed)\r\n\r\npi = 4.0d0*datan(1.0d0)\r\n\r\n\r\n!Wave numbers \r\ndo i=0,nx/2-1\r\nkx(i) = dfloat(i)\r\nkx(i+nx/2) = dfloat(i-nx/2)\r\nend do\r\nkx(0) = tiny\r\n\r\ndo j=0,ny/2-1\r\nky(j) = dfloat(j)\r\nky(j+ny/2) = dfloat(j-ny/2)\r\nend do\r\nky(0) = tiny\r\n\r\n!Random numbers in the first quadrant\r\ndo j=0,ny/2\r\ndo i=0,nx/2\r\nCALL RANDOM_NUMBER(ran)\r\nksi(i,j) =2.0d0*pi*ran\r\nend do\r\nend do\r\n\r\ndo j=0,ny/2\r\ndo i=0,nx/2\r\nCALL RANDOM_NUMBER(ran)\r\neta(i,j) =2.0d0*pi*ran\r\nend do\r\nend do\r\n\r\n!Random phase\r\ndo j=0,ny-1\r\ndo i=0,nx-1\r\nphase2d(1,i,j) = 0.0d0\r\nphase2d(2,i,j) = 0.0d0\r\nend do\r\nend do\r\n \r\ndo j=1,ny/2-1\r\ndo i=1,nx/2-1\r\n!I.st\r\nphase2d(1,i,j) = dcos(ksi(i,j)+eta(i,j)) \r\nphase2d(2,i,j) = dsin(ksi(i,j)+eta(i,j)) \r\n!II.nd\r\nphase2d(1,nx-i,j) = dcos(-ksi(i,j)+eta(i,j)) \r\nphase2d(2,nx-i,j) = dsin(-ksi(i,j)+eta(i,j)) \r\n!IV.th\r\nphase2d(1,i,ny-j) = dcos(ksi(i,j)-eta(i,j)) \r\nphase2d(2,i,ny-j) = dsin(ksi(i,j)-eta(i,j)) \r\n!III.rd\r\nphase2d(1,nx-i,ny-j) = dcos(-ksi(i,j)-eta(i,j)) \r\nphase2d(2,nx-i,ny-j) = dsin(-ksi(i,j)-eta(i,j)) \r\nend do\r\nend do\r\n\r\n\r\n!vorticity amplitudes in Fourier space \r\nk=1\r\ndo j=0,ny-1\r\ndo i=0,nx-1 \r\n kk = dsqrt(kx(i)*kx(i) + ky(j)*ky(j))\r\n data1d(k) = dsqrt(kk*E4(kk)/pi)*phase2d(1,i,j)\r\n\tdata1d(k+1) = dsqrt(kk*E4(kk)/pi)*phase2d(2,i,j) \r\nk = k + 2\r\nend do\r\nend do\r\n\r\n!find the velocity in physical space\r\n!forward fourier transform\r\nisign= 1\r\ncall fourn(data1d,nn,ndim,isign)\r\n\r\n\r\nk=1\r\ndo j=0,ny-1\r\ndo i=0,nx-1\r\nww(i,j)=data1d(k)\r\nk=k+2\r\nend do\r\nend do\r\n\r\n\r\n! periodicity\r\ndo j=0,ny-1\r\nww(nx,j)=ww(0,j)\r\nend do\r\ndo i=0,nx\r\nww(i,ny)=ww(i,0)\r\nend do\r\n\r\n!back to the local grid\r\nnx = ni\r\nny = nj\r\ndo j=0,ny\r\ndo i=0,nx\r\nw(i,j)=ww(i*ii,j*jj)\r\nend do\r\nend do\r\n\r\nopen(5,file='initial-w.plt')\r\nwrite(5,*) 'variables =\"x\",\"y\",\"w\"'\r\nwrite(5,51)'zone f=point i=',nx+1,',j=',ny+1,',t=\"time',0.0,'\"'\r\ndo j=0,ny\r\ndo i=0,nx\r\nwrite(5,52) dfloat(i)*dx,dfloat(j)*dy,w(i,j)\r\nend do\r\nend do\r\nclose(5)\r\n\r\n\r\ndeallocate(data1d,phase2d,ksi,eta,ww)\r\n\r\n!write input files:\r\n!write files when dns starts\r\nif(nx.eq.2048) then\r\nopen(3,file='i2048.dat')\r\nwrite(3,*) nx,ny\r\nwrite(3,*)((w(i,j), i=0,nx), j=0,ny)\r\nclose(3)\r\n\r\nopen(3,file='i1024.dat')\r\nwrite(3,*) nx/2,ny/2\r\nwrite(3,*)((w(i*2,j*2), i=0,nx/2), j=0,ny/2)\r\nclose(3)\r\n\r\nopen(3,file='i512.dat')\r\nwrite(3,*) nx/4,ny/4\r\nwrite(3,*)((w(i*4,j*4), i=0,nx/4), j=0,ny/4)\r\nclose(3)\r\n\r\nopen(3,file='i256.dat')\r\nwrite(3,*) nx/8,ny/8\r\nwrite(3,*)((w(i*8,j*8), i=0,nx/8), j=0,ny/8)\r\nclose(3)\r\n\r\nopen(3,file='i128.dat')\r\nwrite(3,*) nx/16,ny/16\r\nwrite(3,*)((w(i*16,j*16), i=0,nx/16), j=0,ny/16)\r\nclose(3)\r\n\r\nopen(3,file='i64.dat')\r\nwrite(3,*) nx/32,ny/32\r\nwrite(3,*)((w(i*32,j*32), i=0,nx/32), j=0,ny/32)\r\nclose(3)\r\nend if\r\n\r\n51 format(a16,i8,a4,i8,a10,f10.4,a3)\r\n52 format(3es16.6)\r\nreturn\r\nend\r\n\r\n\r\n!---------------------------------------------------------------------------!\r\n!Given energy spectrum\r\n!---------------------------------------------------------------------------!\r\ndouble precision function E4(kr)\r\nimplicit none\r\ndouble precision:: kr,pi,c,k0\r\nk0 = 10.0d0\r\npi = 4.0d0*datan(1.0d0)\r\nc = 4.0d0/(3.0d0*dsqrt(pi)*(k0**5))\r\n!c = 1.0d0/(4.0d0*pi*(k0**6))\r\n!c = 1.0d0/(2.0d0*pi*(k0**6))\r\nE4 = c*(kr**4)*dexp(-(kr/k0)**2)\r\nend\r\n\r\n\r\n!-------------------------------------------------------------------------!\r\n!initial conditions\r\n!-------------------------------------------------------------------------!\r\nsubroutine tgvnorm(nx,ny,dx,dy,time,re,w)\r\nimplicit none\r\ninteger :: nx,ny,i,j,nq\r\ndouble precision::time,re,xx,yy,sum,dx,dy\r\ndouble precision, dimension (-2:nx+2,-2:ny+2) :: w\r\ndouble precision,dimension(:,:),allocatable:: we\r\n\r\n! exact solution for tgv\r\nallocate(we(-2:nx+2,-2:ny+2))\r\nnq = 4 !number of arrays\r\ndo j=0,ny\r\ndo i=0,nx\r\n xx=dfloat(i)*dx\r\n\tyy=dfloat(j)*dy\r\nwe(i,j) = 2.0d0*dfloat(nq) &\r\n *dcos(dfloat(nq)*xx) &\r\n *dcos(dfloat(nq)*yy) &\r\n *dexp(-2.0d0*dfloat(nq)*dfloat(nq)*time/re)\r\nend do\r\nend do\r\n\r\n! l2 avaraged norm\r\nsum = 0.0d0\r\ndo j=0,ny\r\ndo i=0,nx\r\nsum = sum + (w(i,j)-we(i,j))**2\r\nend do\r\nend do\r\nsum = dsqrt(sum/(dfloat(nx+1)*dfloat(ny+1)))\r\n\r\nopen(17,file='tgv.txt')\r\nwrite(17,*)\"Time: \", time\r\nwrite(17,*)\"Resolution: \", nx\r\nwrite(17,*)\"L2 norm: \", sum\r\nclose(17)\r\n\r\nreturn\r\nend\r\n\r\n\r\n!-------------------------------------------------------------------------!\r\n!initial conditions\r\n!-------------------------------------------------------------------------!\r\nsubroutine ic(nx,ny,dx,dy,ion,ipr,time,w)\r\nimplicit none\r\ninteger :: nx,ny,nxi,nyi,i,j,ion,ipr,nq\r\ndouble precision::time,dx,dy,pi,sigma,xc1,xc2,yc1,yc2,xx,yy,delta\r\ndouble precision::Afor,kfor,nu,noiseamp\r\ndouble precision, dimension (-2:nx+2,-2:ny+2) :: w\r\n\r\ncommon /kolmog/ Afor,kfor,nu\r\n\r\n\r\npi =4.0d0*datan(1.0d0)\r\n\r\nif (ipr.eq.1) then\r\n!Taylor Green Vortex\r\n nq = 4 !number of arrays\r\n \r\n\tdo j=0,ny\r\n\tdo i=0,nx\r\n xx=dfloat(i)*dx\r\n\tyy=dfloat(j)*dy\r\n \r\n\tw(i,j) = 2.0d0*dfloat(nq)*dcos(dfloat(nq)*xx) &\r\n\t\t\t\t\t\t\t *dcos(dfloat(nq)*yy)\r\n\tend do\r\n\tend do\r\n \r\nelse if (ipr.eq.2) then\r\n!Two-gaussian vortex (vortex merging)\r\n\tsigma=1.0d0*pi\r\n\txc1 =pi-pi/4.0d0\r\n\tyc1 =pi\r\n\txc2 =pi+pi/4.0d0\r\n\tyc2 =pi\r\n\r\n\tdo j=0,ny\r\n\tdo i=0,nx\r\n\t\r\n\txx=dfloat(i)*dx\r\n\tyy=dfloat(j)*dy\r\n\t\r\n\tw(i,j) = dexp(-sigma*((xx-xc1)**2 + (yy-yc1)**2)) &\r\n\t +dexp(-sigma*((xx-xc2)**2 + (yy-yc2)**2)) \r\n\tend do\r\n\tend do\r\n \r\nelse if (ipr.eq.3) then\r\n!Double shear layer problem\r\n\r\n\tdelta = 0.05d0\t\t\t\t!perturbation amplitude\r\n\tsigma = 30.0d0/(2.0d0*pi)\t!thickness parameter\r\n\r\n\tdo j=0,ny\r\n\tdo i=0,nx\r\n\r\n\txx=dfloat(i)*dx\r\n\tyy=dfloat(j)*dy\r\n\t\r\n\tif (yy.le.pi) then\r\n\tw(i,j) = delta*dcos(xx) - sigma/(dcosh(sigma*(yy-pi/2.0d0)))**2\r\n\telse\r\n\tw(i,j) = delta*dcos(xx) + sigma/(dcosh(sigma*(3.0d0*pi/2.0d0-yy)))**2\r\n\tend if\r\n\t\r\n\tend do\r\n\tend do\r\n \r\nelse if (ipr.eq.4) then\r\n \r\nif (ion.eq.1) then \r\n\topen(3,file='i2048.dat')\r\n\tread(3,*)nxi,nyi\r\n\t\tif(nxi.ne.nx.or.nyi.ne.ny) then\r\n\t\twrite(*,*)'check initial file..'\r\n\t\tstop\r\n\t\tend if\r\n\tread(3,*)((w(i,j), i=0,nx), j=0,ny)\r\n\tclose(3)\r\n\r\nelse if (ion.eq.2) then\r\n\topen(3,file='i1024.dat')\r\n\tread(3,*)nxi,nyi\r\n\t\tif(nxi.ne.nx.or.nyi.ne.ny) then\r\n\t\twrite(*,*)'check initial file..'\r\n\t\tstop\r\n\t\tend if\r\n\tread(3,*)((w(i,j), i=0,nx), j=0,ny)\r\n\tclose(3)\r\n \r\nelse if (ion.eq.3) then\r\n\r\n\topen(3,file='i512.dat')\r\n\tread(3,*)nxi,nyi\r\n\t\tif(nxi.ne.nx.or.nyi.ne.ny) then\r\n\t\twrite(*,*)'check initial file..'\r\n\t\tstop\r\n\t\tend if\r\n\tread(3,*)((w(i,j), i=0,nx), j=0,ny)\r\n\tclose(3)\r\n\r\nelse if (ion.eq.4) then\r\n\r\n\topen(3,file='i256.dat')\r\n\tread(3,*)nxi,nyi\r\n\t\tif(nxi.ne.nx.or.nyi.ne.ny) then\r\n\t\twrite(*,*)'check initial file..'\r\n\t\tstop\r\n\t\tend if\r\n\tread(3,*)((w(i,j), i=0,nx), j=0,ny)\r\n\tclose(3)\r\n\r\n\r\nelse if (ion.eq.5) then\r\n\r\n\topen(3,file='i128.dat')\r\n\tread(3,*)nxi,nyi\r\n\t\tif(nxi.ne.nx.or.nyi.ne.ny) then\r\n\t\twrite(*,*)'check initial file..'\r\n\t\tstop\r\n\t\tend if\r\n\tread(3,*)((w(i,j), i=0,nx), j=0,ny)\r\n\tclose(3)\r\n\r\n\r\nelse if (ion.eq.6) then\r\n\r\n\topen(3,file='i64.dat')\r\n\tread(3,*)nxi,nyi\r\n\t\tif(nxi.ne.nx.or.nyi.ne.ny) then\r\n\t\twrite(*,*)'check initial file..'\r\n\t\tstop\r\n\t\tend if\r\n\tread(3,*)((w(i,j), i=0,nx), j=0,ny)\r\n\tclose(3)\r\n\r\nelse\r\n\r\n\tcall spec2field2d(nx,ny,dx,dy,w)\r\n \r\nend if\r\n\r\nelse if (ipr.eq.5) then !Kolmogorov flow\r\n\r\n!add noise to trigger instability\r\n\tnoiseamp=0.05d0\r\n\tdo j=0,ny\r\n\tdo i=0,nx\r\n\txx=dfloat(i)*dx\r\n\tyy=dfloat(j)*dy\t\r\n\tw(i,j) = (Afor/(nu*kfor**2))*(dsin(kfor*yy) + noiseamp*dsin(kfor*xx)*dsin(kfor*yy))\t\r\n\tend do\r\n\tend do\r\n \r\nelse\r\n! from 'final.dat' file\r\n\topen(3,file='final.dat')\r\n\tread(3,*)time\r\n\tread(3,*)nxi,nyi\r\n\t\tif(nxi.ne.nx.or.nyi.ne.ny) then\r\n\t\twrite(*,*)'check final.dat file..'\r\n\t\tstop\r\n\t\tend if\r\n\tread(3,*)((w(i,j), i=0,nx), j=0,ny)\r\n\tclose(3)\r\n\r\nend if\r\n\r\n\r\n!extend for periodic b.c.\r\ncall bc(nx,ny,w)\r\n\r\nreturn\r\nend\r\n\r\n\r\n!-------------------------------------------------------------------------!\r\n!periodic boundary conditions\r\n!-------------------------------------------------------------------------!\r\nsubroutine bc(nx,ny,u)\r\nimplicit none\r\ninteger :: nx,ny,i,j\r\ndouble precision, dimension (-2:nx+2,-2:ny+2) :: u\r\n\r\n!extend for periodic b.c.\r\ndo i=0,nx\r\nu(i,-2) = u(i,ny-2)\r\nu(i,-1) = u(i,ny-1)\r\nu(i,ny+1)= u(i,1)\r\nu(i,ny+2)= u(i,2)\r\nend do\r\ndo j=-2,ny+2\r\nu(-2,j) = u(nx-2,j)\r\nu(-1,j) = u(nx-1,j)\r\nu(nx+1,j)= u(1,j)\r\nu(nx+2,j)= u(2,j)\r\nend do\r\n\r\nreturn\r\nend\r\n\r\n\r\n\r\n!------------------------------------------------------------------!\r\n!Approximate deconvolution method for 2D data\r\n!\r\n!NA: order of van Cittert approximation\r\n!\r\n!compute unfiltered quantity u from the filtered variable uf\r\n!by repeated filtering (van Cittert series)\r\n!also known iterative inverse filtering\r\n!\r\n!filtering operation in physical space by discrete filters\r\n!------------------------------------------------------------------!\r\nsubroutine adm(nx,ny,uf,u)\r\nimplicit none\r\ninteger::nx,ny,NA,i,j,k\r\ndouble precision::betaAD\r\ndouble precision,dimension(-2:nx+2,-2:ny+2):: u,uf\r\ndouble precision, dimension (:,:), allocatable :: ug\r\n\r\ncommon /ADModel/ betaAD,NA\r\n\r\nallocate(ug(-2:nx+2,-2:ny+2))\r\n\r\n!initial guess\r\n!k=0 \r\ndo j=0,ny\r\ndo i=0,nx\r\nu(i,j) = uf(i,j)\r\nend do\r\nend do\r\n\r\n!k>0 \r\ndo k = 1, NA \r\n !compute filtered value of guess\r\n call filter(nx,ny,u,ug) \r\n\tdo j=0,ny\r\n\tdo i=0,nx\r\n\t\tu(i,j) = u(i,j) + betaAD*(uf(i,j) - ug(i,j))\r\n\tend do\r\n end do\r\nend do\r\n\r\ndeallocate(ug)\r\n\r\n!extend for periodic b.c.\r\ncall bc(nx,ny,u)\r\n\r\nreturn\r\nend\r\n\r\n\r\n!-----------------------------------------------------------------!\r\n!Pade Filter in 2D (fourth order)\r\n!-----------------------------------------------------------------!\r\nsubroutine pade4filter2d(nx,ny,w,wf)\r\nimplicit none\r\ninteger::nx,ny,i,j\r\ndouble precision::w(-2:nx+2,-2:ny+2),wf(-2:nx+2,-2:ny+2)\r\ndouble precision, dimension (:), allocatable:: a,b\r\ndouble precision, dimension(:,:),allocatable::g\r\n\r\n\r\nallocate(g(-2:nx+2,-2:ny+2))\r\n\r\n! filter in x direction (periodic)\r\nallocate(a(0:nx),b(0:nx))\r\ndo j=0,ny\r\n\tdo i=0,nx\r\n\ta(i) = w(i,j)\r\n\tend do\r\n\t\tcall filterPade4p(nx,a,b)\r\n\tdo i=0,nx\r\n\tg(i,j) = b(i)\r\n\tend do\r\nend do\r\ndeallocate(a,b)\r\n\r\n\r\n! filter in y direction (wall)\r\nallocate(a(0:ny),b(0:ny))\r\ndo i=0,nx\r\n\tdo j=0,ny\r\n\ta(j) = g(i,j)\r\n\tend do\r\n\t\tcall filterPade4p(ny,a,b)\r\n\tdo j=0,ny\r\n\twf(i,j) = b(j)\r\n\tend do\r\nend do\r\ndeallocate(a,b)\r\n\r\ndeallocate(g)\r\n\r\n\r\nreturn\r\nend\r\n\r\n!---------------------------------------------------------------------------!\r\n!Compute filtered variable for a given grid data\r\n!Pade forth-order: -0.5 < afil < 0.5\r\n!Periodic\r\n!---------------------------------------------------------------------------!\r\nsubroutine filterPade4p(n,u,uf)\r\nimplicit none\r\ninteger::n,i\r\ndouble precision ::afil\r\ndouble precision ::u(0:n),uf(0:n)\r\ndouble precision ::alpha,beta\r\ndouble precision, dimension (0:n-1):: a,b,c,r,x \r\n\r\ncommon /Padefilter/ afil\r\n\r\ndo i=0,n-1\r\na(i) = afil\r\nb(i) = 1.0d0\r\nc(i) = afil\r\nend do\r\n\r\ndo i=2,n-2\r\nr(i) = (0.625d0 + 0.75d0*afil)*u(i) &\r\n +(0.5d0 + afil)*0.5d0*(u(i-1)+u(i+1)) &\r\n +(-0.125d0 + 0.25d0*afil)*0.5d0*(u(i-2)+u(i+2))\r\nend do\r\n\r\nr(1) = (0.625d0 + 0.75d0*afil)*u(1) &\r\n +(0.5d0 + afil)*0.5d0*(u(0)+u(2)) &\r\n +(-0.125d0 + 0.25d0*afil)*0.5d0*(u(n-1)+u(3))\r\n\r\nr(0) = (0.625d0 + 0.75d0*afil)*u(0) &\r\n +(0.5d0 + afil)*0.5d0*(u(n-1)+u(1)) &\r\n +(-0.125d0 + 0.25d0*afil)*0.5d0*(u(n-2)+u(2))\r\n\r\nr(n-1) = (0.625d0 + 0.75d0*afil)*u(n-1) &\r\n +(0.5d0 + afil)*0.5d0*(u(n-2)+u(n)) &\r\n +(-0.125d0 + 0.25d0*afil)*0.5d0*(u(n-3)+u(1)) \r\n \r\n \r\nalpha = afil\r\nbeta = afil\r\n\r\ncall ctdms(a,b,c,alpha,beta,r,x,0,n-1) \r\n\r\ndo i=0,n-1\r\nuf(i)=x(i)\r\nend do\r\nuf(n)=uf(0)\r\n\r\nreturn \r\nend\r\n\r\n\r\n\r\n\r\n!-----------------------------------------------------------------!\r\n!Filter\r\n!-----------------------------------------------------------------!\r\nsubroutine filter(nx,ny,w,wf)\r\nimplicit none\r\ninteger ::nx,ny,ifil,i,j\r\ndouble precision::w(-2:nx+2,-2:ny+2),wf(-2:nx+2,-2:ny+2),dd\r\n\r\ncommon /filtering/ ifil\r\n\r\ncall bc(nx,ny,w)\r\n\r\nif (ifil.eq.1) then !trapezoidal filter\r\ndd=1.0d0/16.0d0\r\n\r\ndo j=0,ny\r\ndo i=0,nx\r\nwf(i,j) = dd*(4.0d0*w(i,j) &\r\n + 2.0d0*(w(i+1,j) + w(i-1,j) + w(i,j+1) + w(i,j-1)) &\r\n\t + w(i+1,j+1) + w(i-1,j-1) + w(i+1,j-1) + w(i-1,j+1))\r\nend do\r\nend do\r\n\r\nelse\r\ncall pade4filter2d(nx,ny,w,wf)\r\nend if\r\n\r\ncall bc(nx,ny,wf)\r\n\r\nreturn\r\nend \r\n\r\n\r\n\r\n!-----------------------------------------------------------------!\r\n! tvd 3rd-order rk scheme\r\n!-----------------------------------------------------------------!\r\nsubroutine rk3tvd(nx,ny,dx,dy,dt,re,w)\r\nimplicit none\r\ninteger ::nx,ny,i,j,ips\r\ndouble precision::dx,dy,dt,re,w(-2:nx+2,-2:ny+2),oneth,twoth\r\ndouble precision, dimension (:,:), allocatable :: s,f,w1,w2\r\n\r\ncommon /ellp/ ips\r\n\r\nallocate(w1(-2:nx+2,-2:ny+2),w2(-2:nx+2,-2:ny+2))\r\nallocate(s(-2:nx+2,-2:ny+2),f(-2:nx+2,-2:ny+2))\r\n\r\noneth = 1.0d0/3.0d0\r\ntwoth = 2.0d0/3.0d0\r\n\r\n!poisson solver\r\ncall fps4(nx,ny,dx,dy,-w,s)\r\n\r\ncall rhs(nx,ny,dx,dy,re,w,s,f)\r\n\r\ndo j=0,ny\r\ndo i=0,nx\r\nw1(i,j) = w(i,j) + dt*f(i,j)\r\nend do\r\nend do\r\ncall bc(nx,ny,w1)\r\n\r\n\r\n!poisson solver\r\ncall fps4(nx,ny,dx,dy,-w1,s)\r\n\r\ncall rhs(nx,ny,dx,dy,re,w1,s,f)\r\n\r\ndo j=0,ny\r\ndo i=0,nx\r\nw2(i,j) = 0.75d0*w(i,j) + 0.25d0*w1(i,j) + 0.25d0*dt*f(i,j)\r\nend do\r\nend do\r\ncall bc(nx,ny,w2)\r\n\r\n!poisson solver\r\ncall fps4(nx,ny,dx,dy,-w2,s)\r\n\r\ncall rhs(nx,ny,dx,dy,re,w2,s,f)\r\n\r\ndo j=0,ny\r\ndo i=0,nx\r\nw(i,j) = oneth*w(i,j) + twoth*w2(i,j) + twoth*dt*f(i,j)\r\nend do\r\nend do\r\n\r\ncall bc(nx,ny,w)\r\n\r\ndeallocate(s,f,w1,w2)\r\n\r\nreturn\r\nend\r\n\r\n\r\n!-------------------------------------------------------------------------!\r\n! evaluation of rhs terms \r\n! both convertive and viscous terms are treated explicitly\r\n!-------------------------------------------------------------------------!\r\nsubroutine rhs(nx,ny,dx,dy,re,w,s,f)\r\nimplicit none\r\ninteger :: i,j,nx,ny,isgs,ikolmog\r\ndouble precision :: dx,dy,re,Akolmog,kkolmog,yy\r\ndouble precision, dimension (-2:nx+2,-2:ny+2) :: w,s\r\ndouble precision, dimension (-2:nx+2,-2:ny+2) :: f\r\ndouble precision, dimension (:,:), allocatable :: lp,jc,vt,r\r\n\r\ncommon /LESmodels/ isgs\r\ncommon /forcing/ Akolmog,kkolmog,ikolmog\r\n\r\n\r\ncall bc(nx,ny,w)\r\ncall bc(nx,ny,s)\r\n\r\n!------------------------------!\r\n! viscous terms:\r\n!------------------------------!\r\nallocate(lp(-2:nx+2,-2:ny+2))\r\ncall laplacian(nx,ny,dx,dy,w,lp)\r\n\r\n!------------------------------!\r\n! convective terms:\r\n!------------------------------!\r\nallocate(jc(-2:nx+2,-2:ny+2))\r\ncall jacobian(nx,ny,dx,dy,w,s,jc)\r\n\r\n!------------------------------!\r\n!compute rhs\r\n!------------------------------!\r\ndo j=0,ny\r\ndo i=0,nx\r\nf(i,j)=lp(i,j)/re - jc(i,j)\r\nend do\r\nend do\r\n\r\n!------------------------------!\r\n!Add forcing\r\n!------------------------------!\r\nif(ikolmog.eq.1) then\r\ndo j=0,ny\r\nyy = dfloat(j)*dy\r\ndo i=0,nx\r\nf(i,j)=f(i,j) + Akolmog*dsin(kkolmog*yy)\r\nend do\r\nend do\r\nend if\r\n\r\n\r\n!------------------------------!\r\n!SGS terms:\r\n!------------------------------!\r\nif(isgs.ne.0) then\r\n \r\nif(isgs.eq.1) then\r\n \tallocate(vt(-2:nx+2,-2:ny+2))\r\n\tcall smagor(nx,ny,dx,dy,s,vt)\r\n \r\n do j=0,ny\r\n\tdo i=0,nx\r\n\tf(i,j)=f(i,j) + vt(i,j)*lp(i,j)\r\n\tend do\r\n\tend do\r\n \r\n\tdeallocate(vt)\r\n\r\nelse if(isgs.eq.2) then\r\n \tallocate(vt(-2:nx+2,-2:ny+2))\r\n\tcall leith(nx,ny,dx,dy,s,vt)\r\n \r\n do j=0,ny\r\n\tdo i=0,nx\r\n\tf(i,j)=f(i,j) + vt(i,j)*lp(i,j)\r\n\tend do\r\n\tend do\r\n \r\n\tdeallocate(vt)\r\n \r\nelse if(isgs.eq.3) then\r\n allocate(r(-2:nx+2,-2:ny+2))\r\n \tcall ss(nx,ny,dx,dy,w,s,jc,r)\r\n do j=0,ny\r\n\tdo i=0,nx\r\n\tf(i,j)=f(i,j) + r(i,j)\r\n\tend do\r\n\tend do\r\n \tdeallocate(r) \r\n \r\nelse if(isgs.eq.4) then\r\n \r\n allocate(r(-2:nx+2,-2:ny+2))\r\n \tcall layton(nx,ny,jc,r)\r\n do j=0,ny\r\n\tdo i=0,nx\r\n\tf(i,j)=f(i,j) + r(i,j)\r\n\tend do\r\n\tend do\r\n \tdeallocate(r) \r\n \r\nelse if(isgs.eq.5) then\r\n \r\n allocate(r(-2:nx+2,-2:ny+2))\r\n \tcall adles(nx,ny,dx,dy,w,s,jc,r)\r\n do j=0,ny\r\n\tdo i=0,nx\r\n\tf(i,j)=f(i,j) + r(i,j)\r\n\tend do\r\n\tend do\r\n \tdeallocate(r) \r\n\r\nelse if(isgs.eq.6) then !not sure it is correct\r\n \r\n \tallocate(r(-2:nx+2,-2:ny+2))\r\n\tcall grad(nx,ny,dx,dy,s,r)\r\n \r\n do j=0,ny\r\n\tdo i=0,nx\r\n\tf(i,j)=f(i,j) + r(i,j)\r\n\tend do\r\n\tend do\r\n \r\n\tdeallocate(vt)\r\n\r\n\r\nelse if(isgs.eq.9) then \r\n \r\n allocate(vt(-2:nx+2,-2:ny+2))\r\n\tcall dyneddy(nx,ny,dx,dy,w,s,lp,jc,vt)\r\n \r\n do j=0,ny\r\n\tdo i=0,nx\r\n\tf(i,j)=f(i,j) + vt(i,j)*lp(i,j)\r\n\tend do\r\n\tend do\r\n \r\n\tdeallocate(vt)\r\n \r\n\t\r\nend if\r\n\r\n \r\nend if\r\n\r\n\r\ndeallocate(lp,jc)\r\n\r\nreturn\r\nend\r\n\r\n\r\n!-------------------------------------------------------------------------!\r\n! compute AS-LES\r\n!-------------------------------------------------------------------------!\r\nsubroutine adles(nx,ny,dx,dy,w,s,jc,r)\r\nimplicit none\r\ninteger :: i,j,nx,ny\r\ndouble precision :: dx,dy, afil, random_val\r\ndouble precision, dimension (-2:nx+2,-2:ny+2) :: w,s\r\ndouble precision, dimension (-2:nx+2,-2:ny+2) :: jc,r\r\ndouble precision, dimension (:,:), allocatable :: ja,jaf\r\ndouble precision, dimension (:,:), allocatable :: sa,wa\r\n\r\ncommon /Padefilter/ afil\r\n\r\nrandom_val = rand(1)\r\n\r\nif (random_val > 0.5d0) then\r\nafil = 0.1\r\nelse\r\nafil = 0.0\r\nend if\r\n\r\n!AD process\r\nallocate(sa(-2:nx+2,-2:ny+2))\r\nallocate(wa(-2:nx+2,-2:ny+2))\r\n\t\r\ncall adm(nx,ny,s,sa)\r\ncall adm(nx,ny,w,wa)\r\n\r\n\r\n\t!compute jacobian of ad variables\r\n\tallocate(ja(-2:nx+2,-2:ny+2))\r\n\tcall jacobian(nx,ny,dx,dy,wa,sa,ja)\r\n\r\n\t!compute filtered jacobian\r\n\tallocate(jaf(-2:nx+2,-2:ny+2))\r\n\tcall filter(nx,ny,ja,jaf)\r\n\r\n\t!compute scale similarity\r\n\tdo j=0,ny\r\n\tdo i=0,nx \r\n\t\tr(i,j) = jc(i,j)-jaf(i,j)\r\n\tend do\r\n\tend do\r\n\r\ndeallocate(wa,sa,ja,jaf)\r\n\r\nreturn\r\nend\r\n\r\n\r\n!-------------------------------------------------------------------------!\r\n! compute scale similarity\r\n!-------------------------------------------------------------------------!\r\nsubroutine ss(nx,ny,dx,dy,w,s,jc,r)\r\nimplicit none\r\ninteger :: i,j,nx,ny\r\ndouble precision :: dx,dy\r\ndouble precision, dimension (-2:nx+2,-2:ny+2) :: w,s\r\ndouble precision, dimension (-2:nx+2,-2:ny+2) :: jc,r\r\ndouble precision, dimension (:,:), allocatable :: wf,sf,fjc,jcf\r\n\r\n\r\n\t!compute jacobian of filtered variables\r\n\tallocate(wf(-2:nx+2,-2:ny+2))\r\n\tallocate(sf(-2:nx+2,-2:ny+2))\r\n\tallocate(fjc(-2:nx+2,-2:ny+2))\r\n\tcall filter(nx,ny,w,wf)\r\n\tcall filter(nx,ny,s,sf)\r\n\r\n\tcall jacobian(nx,ny,dx,dy,wf,sf,fjc)\r\n\r\n\t!compute filtered jacobian\r\n\tallocate(jcf(-2:nx+2,-2:ny+2))\r\n\tcall filter(nx,ny,jc,jcf)\r\n\r\n\t!compute scale similarity\r\n\tdo j=0,ny\r\n\tdo i=0,nx \r\n\t\tr(i,j) = fjc(i,j)-jcf(i,j)\r\n\tend do\r\n\tend do\r\n\r\ndeallocate(wf,sf,fjc,jcf)\r\n\r\nreturn\r\nend\r\n\r\n!-------------------------------------------------------------------------!\r\n! compute scale similarity (layton)\r\n!-------------------------------------------------------------------------!\r\nsubroutine layton(nx,ny,jc,r)\r\nimplicit none\r\ninteger :: i,j,nx,ny\r\ndouble precision, dimension (-2:nx+2,-2:ny+2) :: jc,r\r\ndouble precision, dimension (:,:), allocatable :: jcf\r\n\r\n\r\n\t!compute filtered jacobian\r\n\tallocate(jcf(-2:nx+2,-2:ny+2))\r\n\tcall filter(nx,ny,jc,jcf)\r\n\r\n\t!compute scale similarity\r\n\tdo j=0,ny\r\n\tdo i=0,nx \r\n\t\tr(i,j) = jc(i,j)-jcf(i,j)\r\n\tend do\r\n\tend do\r\n\r\ndeallocate(jcf)\r\n\r\n\r\nreturn\r\nend\r\n\r\n!-----------------------------------------------------------------!\r\n!Compute clarks gradient model \r\n!i.e., see Legras's paper \r\n!-----------------------------------------------------------------!\r\nsubroutine grad(nx,ny,dx,dy,s,r)\r\nimplicit none\r\ninteger ::nx,ny,i,j\r\ndouble precision::dx,dy,delc,temp\r\ndouble precision::s(-2:nx+2,-2:ny+2),r(-2:nx+2,-2:ny+2)\r\ndouble precision, dimension (:), allocatable :: a,b \r\ndouble precision, dimension (:,:), allocatable :: d,e,f,g,h\r\n\r\ncommon /clarkconstant/ delc\r\n\r\n\r\nallocate(d(0:nx,0:ny))\r\nallocate(e(0:nx,0:ny))\r\nallocate(f(0:nx,0:ny))\r\nallocate(g(0:nx,0:ny))\r\nallocate(h(0:nx,0:ny))\r\n\r\n! compute strain\r\n\r\n! sx\r\nallocate(a(0:nx),b(0:nx))\r\ndo j=0,ny\r\n\tdo i=0,nx\r\n\ta(i) = s(i,j)\r\n\tend do\r\n\t\tcall c4dp(a,b,dx,nx) \r\n\tdo i=0,nx\r\n\te(i,j) = b(i)\r\n\tend do\r\nend do\r\ndeallocate(a,b)\r\n\r\n! s_xy\r\nallocate(a(0:ny),b(0:ny))\r\ndo i=0,nx\r\n\tdo j=0,ny\r\n\ta(j) = e(i,j)\r\n\tend do\r\n\t\tcall c4dp(a,b,dy,ny)\r\n\tdo j=0,ny\r\n\tf(i,j) = b(j)\r\n\tend do\r\nend do\r\ndeallocate(a,b)\r\n\r\n\r\n! s_xy_xx\r\nallocate(a(0:nx),b(0:nx))\r\ndo j=0,ny\r\n\tdo i=0,nx\r\n\ta(i) = f(i,j)\r\n\tend do\r\n\t\tcall c4ddp(a,b,dx,nx)\r\n\tdo i=0,nx\r\n\te(i,j) = b(i)\r\n\tend do\r\nend do\r\ndeallocate(a,b)\r\n\r\n! s_xy_yy\r\nallocate(a(0:ny),b(0:ny))\r\ndo i=0,nx\r\n\tdo j=0,ny\r\n\ta(j) = f(i,j)\r\n\tend do\r\n\t\tcall c4ddp(a,b,dy,ny)\r\n\tdo j=0,ny\r\n\tg(i,j) = e(i,j) + b(j)\r\n\tend do\r\nend do\r\ndeallocate(a,b)\r\n\r\n\r\n! sxx\r\nallocate(a(0:nx),b(0:nx))\r\ndo j=0,ny\r\n\tdo i=0,nx\r\n\ta(i) = s(i,j)\r\n\tend do\r\n\t\tcall c4ddp(a,b,dx,nx)\r\n\tdo i=0,nx\r\n\te(i,j) = b(i)\r\n\tend do\r\nend do\r\ndeallocate(a,b)\r\n\r\n! sxx_xx\r\nallocate(a(0:nx),b(0:nx))\r\ndo j=0,ny\r\n\tdo i=0,nx\r\n\ta(i) = e(i,j)\r\n\tend do\r\n\t\tcall c4ddp(a,b,dx,nx)\r\n\tdo i=0,nx\r\n\th(i,j) = b(i)\r\n\tend do\r\nend do\r\ndeallocate(a,b)\r\n\r\n\r\n! syy\r\nallocate(a(0:ny),b(0:ny))\r\ndo i=0,nx\r\n\tdo j=0,ny\r\n\ta(j) = s(i,j)\r\n\tend do\r\n\t\tcall c4ddp(a,b,dy,ny)\r\n\tdo j=0,ny\r\n\td(i,j) = b(j)\r\n\tend do\r\nend do\r\ndeallocate(a,b)\r\n\r\n! syy_yy\r\nallocate(a(0:ny),b(0:ny))\r\ndo i=0,nx\r\n\tdo j=0,ny\r\n\ta(j) = d(i,j)\r\n\tend do\r\n\t\tcall c4ddp(a,b,dy,ny)\r\n\tdo j=0,ny\r\n\th(i,j) = b(j) - h(i,j)\r\n\tend do\r\nend do\r\ndeallocate(a,b)\r\n\r\n\r\ntemp = -delc*delc/12.0d0\r\n!gradiant model\r\ndo j=0,ny\r\ndo i=0,nx\r\nr(i,j) = temp*(g(i,j)*(e(i,j)-d(i,j)) + f(i,j)*h(i,j))\r\nend do\r\nend do\r\n\r\n\r\ndeallocate(d,e,f,g,h)\r\n\r\n\r\nreturn\r\nend \r\n\r\n \r\n!-------------------------------------------------------------------------!\r\n! compute eddy viscosity\r\n!-------------------------------------------------------------------------!\r\nsubroutine smagor(nx,ny,dx,dy,s,vt)\r\nimplicit none\r\ninteger :: i,j,nx,ny\r\ndouble precision :: dx,dy,sma,del,csd\r\ndouble precision, dimension (-2:nx+2,-2:ny+2) :: s\r\ndouble precision, dimension (-2:nx+2,-2:ny+2) :: vt\r\ndouble precision, dimension (:,:), allocatable :: st\r\n\r\ncommon /smaconstant/ sma,del\r\ncommon /smag/ csd\r\n\r\n\tallocate(st(-2:nx+2,-2:ny+2))\r\n\tcall strain(nx,ny,dx,dy,s,st)\r\n\r\n\tcsd = sma*sma*del*del\r\n\r\n\tdo j=0,ny\r\n\tdo i=0,nx\r\n\tvt(i,j)=csd*st(i,j)\r\n\tend do\r\n\tend do\r\n\t\r\n\tdeallocate(st)\r\n\r\nreturn\r\nend\r\n\r\n!-------------------------------------------------------------------------!\r\n! compute eddy viscosity\r\n!-------------------------------------------------------------------------!\r\nsubroutine leith(nx,ny,dx,dy,w,vt)\r\nimplicit none\r\ninteger :: i,j,nx,ny\r\ndouble precision :: dx,dy,sma,del,csd\r\ndouble precision, dimension (-2:nx+2,-2:ny+2) :: w\r\ndouble precision, dimension (-2:nx+2,-2:ny+2) :: vt\r\ndouble precision, dimension (:,:), allocatable :: st\r\n\r\ncommon /smaconstant/ sma,del\r\ncommon /smag/ csd\r\n\r\n\tallocate(st(-2:nx+2,-2:ny+2))\r\n\tcall vortgrad(nx,ny,dx,dy,w,st)\r\n\r\n\tcsd = sma*sma*sma*del*del*del\r\n\r\n\tdo j=0,ny\r\n\tdo i=0,nx\r\n\tvt(i,j)=csd*st(i,j)\r\n\tend do\r\n\tend do\r\n\t\r\n\tdeallocate(st)\r\n\r\nreturn\r\nend\r\n\r\n\r\n!-------------------------------------------------------------------------!\r\n! compute eddy viscosity\r\n!-------------------------------------------------------------------------!\r\nsubroutine dyneddy(nx,ny,dx,dy,w,s,lp,jc,vt)\r\nimplicit none\r\ninteger :: nx,ny,idyn\r\ndouble precision :: dx,dy\r\ndouble precision, dimension (-2:nx+2,-2:ny+2) :: w,s\r\ndouble precision, dimension (-2:nx+2,-2:ny+2) :: lp,jc,vt\r\n\r\ncommon /dynmodel/ idyn\r\n\r\nif(idyn.eq.1) then\r\n\tcall dyn_classic(nx,ny,dx,dy,w,s,lp,jc,vt)\r\nelse if(idyn.eq.2) then\r\n\tcall dyn_ba(nx,ny,dx,dy,w,s,lp,jc,vt)\r\nelse if(idyn.eq.3) then\r\n\tcall dyn_ly(nx,ny,dx,dy,w,s,lp,jc,vt)\r\nelse if(idyn.eq.4) then\r\n\tcall dyn_ad(nx,ny,dx,dy,w,s,lp,jc,vt)\r\nelse if(idyn.eq.5) then\r\n\tcall dyn_gr(nx,ny,dx,dy,w,s,lp,vt)\r\nend if\r\n\r\n \r\nreturn\r\nend\r\n\r\n!-------------------------------------------------------------------------!\r\n! compute eddy viscosity (dynamic gradient)\r\n!-------------------------------------------------------------------------!\r\nsubroutine dyn_gr(nx,ny,dx,dy,w,s,lp,vt)\r\nimplicit none\r\ninteger :: i,j,nx,ny,ivis\r\ndouble precision :: dx,dy,dd,nn,csd\r\ndouble precision, dimension (-2:nx+2,-2:ny+2) :: w,s\r\ndouble precision, dimension (-2:nx+2,-2:ny+2) :: lp,vt\r\ndouble precision, dimension (:,:), allocatable :: l,m,st\r\n\r\ncommon /viskernel/ ivis\r\ncommon /dyncoeff/ csd\r\n\r\nallocate(l(-2:nx+2,-2:ny+2))\r\nallocate(m(-2:nx+2,-2:ny+2))\r\n\r\n!compute L\r\ncall grad(nx,ny,dx,dy,s,l)\r\n\r\n!compute M\r\n\t!compute strain\r\n\tallocate(st(-2:nx+2,-2:ny+2))\r\n if (ivis.eq.1) then\r\n\tcall strain(nx,ny,dx,dy,s,st)\r\n else \r\n call vortgrad(nx,ny,dx,dy,w,st)\r\n end if\r\n\r\n \tdo j=0,ny\r\n\tdo i=0,nx\r\n\tm(i,j)=st(i,j)*lp(i,j)\r\n\tend do\r\n\tend do \r\n\r\n\tnn = 0.0d0\r\n\tdd = 0.0d0\r\n\t!compute (cs*delta)^2 =csd\r\n\tdo j=0,ny\r\n\tdo i=0,nx \r\n\tnn = nn + l(i,j)*m(i,j)\r\n\tdd = dd + m(i,j)*m(i,j)\r\n\tend do\r\n\tend do\r\n\t\r\n\t!compute csd\r\n\tcsd = dabs(nn/dd)\r\n\r\n\t!eddy vicosity model\r\n\tdo j=0,ny\r\n\tdo i=0,nx \r\n\t\tvt(i,j) = csd*st(i,j)\r\n\tend do\r\n\tend do\r\n\r\ndeallocate(l,m,st)\r\n\r\nreturn\r\nend\r\n\r\n\r\n!-------------------------------------------------------------------------!\r\n! compute eddy viscosity (dynamic layton)\r\n!-------------------------------------------------------------------------!\r\nsubroutine dyn_ad(nx,ny,dx,dy,w,s,lp,jc,vt)\r\nimplicit none\r\ninteger :: i,j,nx,ny,ivis\r\ndouble precision :: dx,dy,dd,nn,csd\r\ndouble precision, dimension (-2:nx+2,-2:ny+2) :: w,s\r\ndouble precision, dimension (-2:nx+2,-2:ny+2) :: lp,jc,vt\r\ndouble precision, dimension (:,:), allocatable :: l,m,st\r\n\r\ncommon /viskernel/ ivis\r\ncommon /dyncoeff/ csd\r\n\r\nallocate(l(-2:nx+2,-2:ny+2))\r\nallocate(m(-2:nx+2,-2:ny+2))\r\n\r\n!compute L\r\ncall adles(nx,ny,dx,dy,w,s,jc,l)\r\n\r\n!compute M\r\n\t!compute strain\r\n\tallocate(st(-2:nx+2,-2:ny+2))\r\n if (ivis.eq.1) then\r\n\tcall strain(nx,ny,dx,dy,s,st)\r\n else \r\n call vortgrad(nx,ny,dx,dy,w,st)\r\n end if\r\n\r\n \tdo j=0,ny\r\n\tdo i=0,nx\r\n\tm(i,j)=st(i,j)*lp(i,j)\r\n\tend do\r\n\tend do \r\n\r\n\tnn = 0.0d0\r\n\tdd = 0.0d0\r\n\t!compute (cs*delta)^2 =csd\r\n\tdo j=0,ny\r\n\tdo i=0,nx \r\n\tnn = nn + l(i,j)*m(i,j)\r\n\tdd = dd + m(i,j)*m(i,j)\r\n\tend do\r\n\tend do\r\n\t\r\n\t!compute csd\r\n\tcsd = dabs(nn/dd)\r\n\r\n\t!eddy vicosity model\r\n\tdo j=0,ny\r\n\tdo i=0,nx \r\n\t\tvt(i,j) = csd*st(i,j)\r\n\tend do\r\n\tend do\r\n\r\ndeallocate(l,m,st)\r\n\r\nreturn\r\nend\r\n\r\n\r\n!-------------------------------------------------------------------------!\r\n! compute eddy viscosity (dynamic layton)\r\n!-------------------------------------------------------------------------!\r\nsubroutine dyn_ly(nx,ny,dx,dy,w,s,lp,jc,vt)\r\nimplicit none\r\ninteger :: i,j,nx,ny,ivis\r\ndouble precision :: dx,dy,dd,nn,csd\r\ndouble precision, dimension (-2:nx+2,-2:ny+2) :: w,s\r\ndouble precision, dimension (-2:nx+2,-2:ny+2) :: lp,jc,vt\r\ndouble precision, dimension (:,:), allocatable :: l,m,st\r\n\r\ncommon /viskernel/ ivis\r\ncommon /dyncoeff/ csd\r\n\r\nallocate(l(-2:nx+2,-2:ny+2))\r\nallocate(m(-2:nx+2,-2:ny+2))\r\n\r\n!compute L\r\ncall layton(nx,ny,jc,l)\r\n\r\n!compute M\r\n\t!compute strain\r\n\tallocate(st(-2:nx+2,-2:ny+2))\r\n if (ivis.eq.1) then\r\n\tcall strain(nx,ny,dx,dy,s,st)\r\n else \r\n call vortgrad(nx,ny,dx,dy,w,st)\r\n end if\r\n\r\n \tdo j=0,ny\r\n\tdo i=0,nx\r\n\tm(i,j)=st(i,j)*lp(i,j)\r\n\tend do\r\n\tend do \r\n\r\n\tnn = 0.0d0\r\n\tdd = 0.0d0\r\n\t!compute (cs*delta)^2 =csd\r\n\tdo j=0,ny\r\n\tdo i=0,nx \r\n\tnn = nn + l(i,j)*m(i,j)\r\n\tdd = dd + m(i,j)*m(i,j)\r\n\tend do\r\n\tend do\r\n\t\r\n\t!compute csd\r\n\tcsd = dabs(nn/dd)\r\n\r\n\t!eddy vicosity model\r\n\tdo j=0,ny\r\n\tdo i=0,nx \r\n\t\tvt(i,j) = csd*st(i,j)\r\n\tend do\r\n\tend do\r\n\r\ndeallocate(l,m,st)\r\n\r\nreturn\r\nend\r\n\r\n!-------------------------------------------------------------------------!\r\n! compute eddy viscosity (dynamic bardina)\r\n!-------------------------------------------------------------------------!\r\nsubroutine dyn_ba(nx,ny,dx,dy,w,s,lp,jc,vt)\r\nimplicit none\r\ninteger :: i,j,nx,ny,ivis\r\ndouble precision :: dx,dy,dd,nn,csd\r\ndouble precision, dimension (-2:nx+2,-2:ny+2) :: w,s\r\ndouble precision, dimension (-2:nx+2,-2:ny+2) :: lp,jc,vt\r\ndouble precision, dimension (:,:), allocatable :: l,m,st\r\n\r\ncommon /viskernel/ ivis\r\ncommon /dyncoeff/ csd\r\n\r\nallocate(l(-2:nx+2,-2:ny+2))\r\nallocate(m(-2:nx+2,-2:ny+2))\r\n\r\n!compute L\r\ncall ss(nx,ny,dx,dy,w,s,jc,l)\r\n\r\n!compute M\r\n\t!compute strain\r\n\tallocate(st(-2:nx+2,-2:ny+2))\r\n if (ivis.eq.1) then\r\n\tcall strain(nx,ny,dx,dy,s,st)\r\n else \r\n call vortgrad(nx,ny,dx,dy,w,st)\r\n end if\r\n\r\n \tdo j=0,ny\r\n\tdo i=0,nx\r\n\tm(i,j)=st(i,j)*lp(i,j)\r\n\tend do\r\n\tend do \r\n\r\n\tnn = 0.0d0\r\n\tdd = 0.0d0\r\n\t!compute (cs*delta)^2 =csd\r\n\tdo j=0,ny\r\n\tdo i=0,nx \r\n\tnn = nn + l(i,j)*m(i,j)\r\n\tdd = dd + m(i,j)*m(i,j)\r\n\tend do\r\n\tend do\r\n\t\r\n\t!compute csd\r\n\tcsd = dabs(nn/dd)\r\n\r\n\t!eddy vicosity model\r\n\tdo j=0,ny\r\n\tdo i=0,nx \r\n\t\tvt(i,j) = csd*st(i,j)\r\n\tend do\r\n\tend do\r\n\r\ndeallocate(l,m,st)\r\n\r\nreturn\r\nend\r\n\r\n\r\n!-------------------------------------------------------------------------!\r\n! compute eddy viscosity (dynamic classic)\r\n!-------------------------------------------------------------------------!\r\nsubroutine dyn_classic(nx,ny,dx,dy,w,s,lp,jc,vt)\r\nimplicit none\r\ninteger :: i,j,nx,ny,ivis\r\ndouble precision :: dx,dy,kappa2,dd,nn,csd\r\ndouble precision, dimension (-2:nx+2,-2:ny+2) :: w,s\r\ndouble precision, dimension (-2:nx+2,-2:ny+2) :: lp,jc,vt\r\ndouble precision, dimension (:,:), allocatable :: wf,sf,fjc,jcf,st,lwf\r\n\r\ncommon /viskernel/ ivis\r\ncommon /dynconstant/ kappa2\r\ncommon /dyncoeff/ csd\r\n\r\n\r\n\t!compute jacobian of filtered variables\r\n\tallocate(wf(-2:nx+2,-2:ny+2))\r\n\tallocate(sf(-2:nx+2,-2:ny+2))\r\n\tallocate(fjc(-2:nx+2,-2:ny+2))\r\n\tcall filter(nx,ny,w,wf)\r\n\tcall filter(nx,ny,s,sf)\r\n\r\n\tcall jacobian(nx,ny,dx,dy,wf,sf,fjc)\r\n\r\n\t!compute filtered jacobian\r\n\tallocate(jcf(-2:nx+2,-2:ny+2))\r\n\tcall filter(nx,ny,jc,jcf)\r\n\r\n\t!compute laplacian of wf \r\n\tallocate(lwf(-2:nx+2,-2:ny+2))\r\n\tcall laplacian(nx,ny,dx,dy,wf,lwf)\r\n\r\n\t!compute strain\r\n\tallocate(st(-2:nx+2,-2:ny+2))\r\n if (ivis.eq.1) then\r\n\tcall strain(nx,ny,dx,dy,s,st)\r\n else \r\n call vortgrad(nx,ny,dx,dy,w,st)\r\n end if\r\n\t\r\n\t!get filtered st ==> sf\r\n call filter(nx,ny,st,sf)\r\n\r\n\r\n\t!compute |S|L on test filter ==> lwf\r\n\tdo j=0,ny\r\n\tdo i=0,nx\r\n\tlwf(i,j)=sf(i,j)*lwf(i,j)\r\n\tend do\r\n\tend do\r\n\r\n\r\n\t!compute |S|L ==> wf on grid filter\r\n\tdo j=0,ny\r\n\tdo i=0,nx\r\n\twf(i,j)=st(i,j)*lp(i,j)\r\n\tend do\r\n\tend do\r\n\r\n\t!compute filtered |S|L on grid filter\r\n\tcall filter(nx,ny,wf,sf)\r\n\r\n\tnn = 0.0d0\r\n\tdd = 0.0d0\r\n\t!compute (cs*delta)^2 =csd\r\n\tdo j=0,ny\r\n\tdo i=0,nx \r\n\tnn = nn + (fjc(i,j) - jcf(i,j))*(kappa2*lwf(i,j) - sf(i,j))\r\n\tdd = dd + (kappa2*lwf(i,j) - sf(i,j))*(kappa2*lwf(i,j) - sf(i,j))\r\n\tend do\r\n\tend do\r\n\t\r\n\t!compute csd\r\n\tcsd = dabs(nn/dd)\r\n\r\n\r\n\t!limiters\r\n\t!remove negative ones, backscatter\r\n\t!if(csd.le.0.0d0) csd=0.0d0\r\n\t!limit by smagorisnky constant of 1\r\n\t!if(csd.ge.(dx*dy)) csd = dx*dy\r\n\r\n\r\n\t!eddy vicosity model\r\n\tdo j=0,ny\r\n\tdo i=0,nx \r\n\t\tvt(i,j) = csd*st(i,j)\r\n\tend do\r\n\tend do\r\n\r\ndeallocate(wf,sf,fjc,jcf,st,lwf)\r\n\r\n\r\n\r\nreturn\r\nend\r\n\r\n!-----------------------------------------------------------------!\r\n!Compute vorticity gradient from stream function\r\n!-----------------------------------------------------------------!\r\nsubroutine vortgrad(nx,ny,dx,dy,w,st)\r\nimplicit none\r\ninteger ::nx,ny,i,j\r\ndouble precision::w(-2:nx+2,-2:ny+2),st(-2:nx+2,-2:ny+2),dx,dy\r\ndouble precision, dimension (:), allocatable :: a,b \r\ndouble precision, dimension (:,:), allocatable :: e,f\r\n\r\nallocate(e(0:nx,0:ny))\r\nallocate(f(0:nx,0:ny))\r\n\r\n\r\n! compute strain\r\n\r\n! wx\r\nallocate(a(0:nx),b(0:nx))\r\ndo j=0,ny\r\n\tdo i=0,nx\r\n\ta(i) = w(i,j)\r\n\tend do\r\n\t\tcall c4dp(a,b,dx,nx)\r\n\tdo i=0,nx\r\n\te(i,j) = b(i)\r\n\tend do\r\nend do\r\ndeallocate(a,b)\r\n\r\n! wy\r\nallocate(a(0:ny),b(0:ny))\r\ndo i=0,nx\r\n\tdo j=0,ny\r\n\ta(j) = w(i,j)\r\n\tend do\r\n\t\tcall c4dp(a,b,dy,ny)\r\n\tdo j=0,ny\r\n\tf(i,j) = b(j)\r\n\tend do\r\nend do\r\ndeallocate(a,b)\r\n\r\n\r\n!strain\r\ndo j=0,ny\r\ndo i=0,nx\r\nst(i,j) = dsqrt(f(i,j)*f(i,j) + e(i,j)*e(i,j))\r\nend do\r\nend do\r\n\r\n\r\ndeallocate(e,f)\r\n\r\n\r\nreturn\r\nend \r\n\r\n!-----------------------------------------------------------------!\r\n!Compute strain from stream function\r\n!-----------------------------------------------------------------!\r\nsubroutine strain(nx,ny,dx,dy,s,st)\r\nimplicit none\r\ninteger ::nx,ny,i,j\r\ndouble precision::s(-2:nx+2,-2:ny+2),st(-2:nx+2,-2:ny+2),dx,dy\r\ndouble precision, dimension (:), allocatable :: a,b \r\ndouble precision, dimension (:,:), allocatable :: e,f\r\n\r\nallocate(e(0:nx,0:ny))\r\nallocate(f(0:nx,0:ny))\r\n\r\n\r\n! compute strain\r\n\r\n! sx\r\nallocate(a(0:nx),b(0:nx))\r\ndo j=0,ny\r\n\tdo i=0,nx\r\n\ta(i) = s(i,j)\r\n\tend do\r\n\t\tcall c4dp(a,b,dx,nx)\r\n\tdo i=0,nx\r\n\te(i,j) = b(i)\r\n\tend do\r\nend do\r\ndeallocate(a,b)\r\n\r\n! sx_y\r\nallocate(a(0:ny),b(0:ny))\r\ndo i=0,nx\r\n\tdo j=0,ny\r\n\ta(j) = e(i,j)\r\n\tend do\r\n\t\tcall c4dp(a,b,dy,ny)\r\n\tdo j=0,ny\r\n\tf(i,j) = b(j)\r\n\tend do\r\nend do\r\ndeallocate(a,b)\r\n\r\n\r\n\r\n! sxx\r\nallocate(a(0:nx),b(0:nx))\r\ndo j=0,ny\r\n\tdo i=0,nx\r\n\ta(i) = s(i,j)\r\n\tend do\r\n\t\tcall c4ddp(a,b,dx,nx)\r\n\tdo i=0,nx\r\n\te(i,j) = b(i)\r\n\tend do\r\nend do\r\ndeallocate(a,b)\r\n\r\n! syy\r\nallocate(a(0:ny),b(0:ny))\r\ndo i=0,nx\r\n\tdo j=0,ny\r\n\ta(j) = s(i,j)\r\n\tend do\r\n\t\tcall c4ddp(a,b,dy,ny)\r\n\tdo j=0,ny\r\n\te(i,j) = e(i,j) - b(j)\r\n\tend do\r\nend do\r\ndeallocate(a,b)\r\n\r\n\r\n!strain\r\ndo j=0,ny\r\ndo i=0,nx\r\nst(i,j) = dsqrt(4.0d0*f(i,j)*f(i,j) + e(i,j)*e(i,j))\r\nend do\r\nend do\r\n\r\n\r\ndeallocate(e,f)\r\n\r\n\r\nreturn\r\nend \r\n\r\n!-------------------------------------------------------------------------!\r\n! compute laplacian\r\n! Modified second order - Romit \r\n!-------------------------------------------------------------------------!\r\nsubroutine laplacian(nx,ny,dx,dy,u,lp)\r\nimplicit none\r\ninteger :: i,j,nx,ny\r\ndouble precision :: dx,dy, d2wdy2, d2wdx2\r\ndouble precision, dimension (-2:nx+2,-2:ny+2) :: u,lp\r\ndouble precision, dimension (:), allocatable :: a,b \r\n\r\n\r\n\r\ndo j = 0,ny\r\n\tdo i = 0,nx\r\n\t\td2wdy2 = (u(i, j+1) + u(i, j-1) - 2.0 * u(i, j)) / (dy * dy)\r\n\t\td2wdx2 = (u(i+1, j) + u(i-1, j) - 2.0 * u(i, j)) / (dx * dx)\r\n\r\n\t\tlp(i,j) = d2wdx2 + d2wdy2\r\n\r\n\tend do\r\nend do\r\n\r\n\r\n\r\n! uxx\r\n! allocate(a(0:nx),b(0:nx))\r\n! do j=0,ny\r\n! \tdo i=0,nx\r\n! \ta(i) = u(i,j)\r\n! \tend do\r\n! \t\tcall c4ddp(a,b,dx,nx)\r\n! \tdo i=0,nx\r\n! \tlp(i,j) = b(i)\r\n! \tend do\r\n! end do\r\n! deallocate(a,b)\r\n\r\n! ! uyy\r\n! allocate(a(0:ny),b(0:ny))\r\n! do i=0,nx\r\n! \tdo j=0,ny\r\n! \ta(j) = u(i,j)\r\n! \tend do\r\n! \t\tcall c4ddp(a,b,dy,ny)\r\n! \tdo j=0,ny\r\n! \tlp(i,j) = lp(i,j) + b(j)\r\n! \tend do\r\n! end do\r\n! deallocate(a,b)\r\n\r\n\r\nreturn\r\nend\r\n\r\n!-------------------------------------------------------------------------!\r\n! compute jacobian \r\n!-------------------------------------------------------------------------!\r\nsubroutine jacobian(nx,ny,dx,dy,w,s,jc)\r\nimplicit none\r\ninteger :: nx,ny,isolver\r\ndouble precision :: dx,dy\r\ndouble precision, dimension (0:nx,0:ny) :: w,s,jc\r\n\r\ncommon /solver/ isolver\r\n\r\nif (isolver.eq.1) then\r\ncall jacobian_compact(nx,ny,dx,dy,w,s,jc)\r\nelse\r\ncall jacobian_arakawa(nx,ny,dx,dy,w,s,jc)\r\nend if\r\n\r\n\r\nreturn\r\nend\r\n\r\n!-------------------------------------------------------------------------!\r\n! compute jacobian (compact)\r\n!-------------------------------------------------------------------------!\r\nsubroutine jacobian_compact(nx,ny,dx,dy,w,s,jc)\r\nimplicit none\r\ninteger :: i,j,nx,ny\r\ndouble precision :: dx,dy\r\ndouble precision, dimension (-2:nx+2,-2:ny+2) :: w,s,jc\r\ndouble precision, dimension (:), allocatable :: a,b \r\ndouble precision, dimension (:,:), allocatable :: e\r\n\r\n! jacobian (convective term):\r\nallocate(e(0:nx,0:ny))\r\n\r\n! sy\r\nallocate(a(0:ny),b(0:ny))\r\ndo i=0,nx\r\n\tdo j=0,ny\r\n\ta(j) = s(i,j)\r\n\tend do\r\n\t\tcall c4dp(a,b,dy,ny) \r\n\tdo j=0,ny\r\n\te(i,j) = b(j)\r\n\tend do\r\nend do\r\ndeallocate(a,b)\r\n\r\n! wx\r\nallocate(a(0:nx),b(0:nx))\r\ndo j=0,ny\r\n\tdo i=0,nx\r\n\ta(i) = w(i,j)\r\n\tend do\r\n\t\tcall c4dp(a,b,dx,nx)\r\n\tdo i=0,nx\r\n\tjc(i,j) = e(i,j)*b(i)\r\n\tend do\r\nend do\r\ndeallocate(a,b)\r\n\r\n\r\n\r\n! sx\r\nallocate(a(0:nx),b(0:nx))\r\ndo j=0,ny\r\n\tdo i=0,nx\r\n\ta(i) = s(i,j)\r\n\tend do\r\n\t\tcall c4dp(a,b,dx,nx)\r\n\tdo i=0,nx\r\n\te(i,j) = b(i)\r\n\tend do\r\nend do\r\ndeallocate(a,b)\r\n\r\n! wy\r\nallocate(a(0:ny),b(0:ny))\r\ndo i=0,nx\r\n\tdo j=0,ny\r\n\ta(j) = w(i,j)\r\n\tend do\r\n\t\tcall c4dp(a,b,dy,ny)\r\n\tdo j=0,ny\r\n\tjc(i,j) = jc(i,j) - e(i,j)*b(j)\r\n\tend do\r\nend do\r\ndeallocate(a,b)\r\ndeallocate(e)\r\n\r\ncall bc(nx,ny,jc)\r\n\r\nreturn\r\nend\r\n\r\n\r\n!-------------------------------------------------------------------------!\r\n! compute jacobian by second order Arakawa scheme (conservative)\r\n! Modified Romit Maulik\r\n!-------------------------------------------------------------------------!\r\nsubroutine jacobian_arakawa(nx,ny,dx,dy,w,s,jc)\r\nimplicit none\r\ninteger :: i,j,nx,ny\r\ndouble precision :: dx,dy,j1,j2,j3,j11,j22,j33,g,e,z,h\r\ndouble precision, dimension (-2:nx+2,-2:ny+2) :: w,s\r\ndouble precision, dimension (-2:nx+2,-2:ny+2) :: jc\r\n\r\ng = 1.0d0/(4.0d0*dx*dy)\r\ne = 1.0d0/(8.0d0*dx*dy)\r\nz = 2.0d0/3.0d0\r\nh = 1.0d0/3.0d0\r\n\r\ncall bc(nx,ny,w)\r\ncall bc(nx,ny,s)\r\n\r\n! do j=0,ny\r\n! do i=0,nx\r\n\r\n! j1 = g*((w(i+1,j)-w(i-1,j))*(s(i,j+1)-s(i,j-1)) &\r\n! -(w(i,j+1)-w(i,j-1))*(s(i+1,j)-s(i-1,j)) )\r\n\r\n! j2 = g*(w(i+1,j)*(s(i+1,j+1)-s(i+1,j-1)) &\r\n! -w(i-1,j)*(s(i-1,j+1)-s(i-1,j-1)) &\r\n! \t -w(i,j+1)*(s(i+1,j+1)-s(i-1,j+1)) &\r\n! \t +w(i,j-1)*(s(i+1,j-1)-s(i-1,j-1)) )\r\n\r\n! j3 = g*(w(i+1,j+1)*(s(i,j+1)-s(i+1,j)) &\r\n! -w(i-1,j-1)*(s(i-1,j)-s(i,j-1)) &\r\n! \t -w(i-1,j+1)*(s(i,j+1)-s(i-1,j)) &\r\n! \t +w(i+1,j-1)*(s(i+1,j)-s(i,j-1)) )\r\n\r\n\r\n! j11= e*((w(i+1,j+1)-w(i-1,j-1))*(s(i-1,j+1)-s(i+1,j-1)) &\r\n! -(w(i-1,j+1)-w(i+1,j-1))*(s(i+1,j+1)-s(i-1,j-1)) )\r\n\r\n! j22= e*(w(i+1,j+1)*(s(i,j+2)-s(i+2,j)) &\r\n! -w(i-1,j-1)*(s(i-2,j)-s(i,j-2)) &\r\n! \t -w(i-1,j+1)*(s(i,j+2)-s(i-2,j)) &\r\n! \t +w(i+1,j-1)*(s(i+2,j)-s(i,j-2)) )\r\n\r\n\r\n! j33= e*(w(i+2,j)*(s(i+1,j+1)-s(i+1,j-1)) &\r\n! -w(i-2,j)*(s(i-1,j+1)-s(i-1,j-1)) &\r\n! \t -w(i,j+2)*(s(i+1,j+1)-s(i-1,j+1)) &\r\n! \t +w(i,j-2)*(s(i+1,j-1)-s(i-1,j-1)) )\r\n\r\n\r\n! jc(i,j) = (j1+j2+j3)*z - (j11+j22+j33)*h\r\n\r\n! end do\r\n! end do\r\n\r\ndo j = 0,ny\r\ndo i = 0,nx\r\n\r\n\r\nj1 = 1.0/(4.0*dx*dy) * ((w(i+1,j)-w(i-1,j)) * (s(i,j+1) - s(i,j-1)) &\r\n\t\t\t- (w(i,j+1)-w(i,j-1)) * (s(i+1,j) - s(i-1,j)))\r\n\r\nj2 = 1.0 / (4.0 * dx * dy) * (w(i+1, j) * (s(i+1, j+1) - s(i+1, j-1)) &\r\n - w(i-1, j) * (s(i-1, j+1) - s(i-1, j-1)) &\r\n - w(i, j+1) * (s(i+1, j+1) - s(i-1, j+1)) &\r\n + w(i, j-1) * (s(i+1, j-1) - s(i-1, j-1)) &\r\n )\r\n\r\nj3 = 1.0 / (4.0 * dx * dy) * (w(i+1, j+1) * (s(i, j+1) - s(i+1, j)) &\r\n - w(i-1, j-1) * (s(i-1, j) - s(i, j-1)) &\r\n - w(i-1, j+1) * (s(i, j+1) - s(i-1, j)) &\r\n + w(i+1, j-1) * (s(i+1, j) - s(i, j-1)) &\r\n )\r\n\r\njc(i, j) = (j1 + j2 + j3)/3.0\r\n\r\nend do\r\nend do\r\n\r\ncall bc(nx,ny,jc)\r\n\r\nreturn\r\nend\r\n\r\n\r\n!-----------------------------------------------------------------!\r\n! computes integral values\r\n!-----------------------------------------------------------------!\r\nsubroutine history(nx,ny,dx,dy,dt,w,cfl,en,ew)\r\nimplicit none\r\ninteger ::nx,ny,i,j\r\ndouble precision::dx,dy,dt,cfl,en,ew,w(-2:nx+2,-2:ny+2)\r\ndouble precision,dimension(:),allocatable :: a,b \r\ndouble precision,dimension(:,:),allocatable:: s,u,v,g \r\ndouble precision::umax,umin,vmax,vmin,area,pi,cflc,dta,dtv\r\n\r\ncommon /adaptive/ cflc,dta,dtv\r\n\r\npi = 4.0d0*datan(1.0d0)\r\narea = (2.0d0*pi)**2\r\n\r\n\r\n!compute stream function\r\nallocate(s(-2:nx+2,-2:ny+2))\r\ncall fps4(nx,ny,dx,dy,-w,s)\r\n\r\nallocate(u(0:nx,0:ny),v(0:nx,0:ny))\r\n\r\n! u = sy\r\nallocate(a(0:ny),b(0:ny))\r\ndo i=0,nx\r\n\tdo j=0,ny\r\n\ta(j) = s(i,j)\r\n\tend do\r\n\t\tcall c4dp(a,b,dy,ny)\r\n\tdo j=0,ny\r\n\tu(i,j) = b(j)\r\n\tend do\r\nend do\r\ndeallocate(a,b)\r\n\r\n! v=-sx\r\nallocate(a(0:nx),b(0:nx))\r\ndo j=0,ny\r\n\tdo i=0,nx\r\n\ta(i) = s(i,j)\r\n\tend do\r\n\t\tcall c4dp(a,b,dx,nx)\r\n\tdo i=0,nx\r\n\tv(i,j) =-b(i)\r\n\tend do\r\nend do\r\ndeallocate(a,b)\r\n\r\numax = maxval(u)\r\numin = minval(u)\r\nvmax = maxval(v)\r\nvmin = minval(v)\r\n\r\numax = max(dabs(umax),dabs(umin))\r\nvmax = max(dabs(vmax),dabs(vmin))\r\n\r\ncfl = max(umax*dt/dx, vmax*dt/dy)\r\n\r\ndta = min(cflc*dx/umax,cflc*dy/vmax,dtv)\r\n\r\n\r\n!compute total energy\r\nallocate(g(0:nx,0:ny))\r\ndo i=0,nx\r\ndo j=0,ny\r\ng(i,j)=0.5d0*(u(i,j)**2 + v(i,j)**2)\r\nend do\r\nend do\r\ncall simp2D(nx,ny,dx,dy,g,en)\r\ndeallocate(g)\r\nen = en/area\r\n\r\n\r\n!compute total enstrophy\r\nallocate(g(0:nx,0:ny))\r\ndo i=0,nx\r\ndo j=0,ny\r\ng(i,j)=0.5d0*(w(i,j)**2)\r\nend do\r\nend do\r\ncall simp2D(nx,ny,dx,dy,g,ew)\r\ndeallocate(g)\r\new = ew/area\r\n\r\ndeallocate(u,v,s)\r\n\r\nreturn\r\nend \r\n\r\n\r\n!-----------------------------------------------------------------!\r\nsubroutine saved(nx,ny,time,w)\r\nimplicit none\r\ninteger ::nx,ny,i,j\r\ndouble precision::time,w(-2:nx+2,-2:ny+2)\r\n\r\n\topen(3,file='final.dat')\r\n\twrite(3,*)time\r\n\twrite(3,*)nx,ny\r\n\twrite(3,*)((w(i,j), i=0,nx), j=0,ny)\r\n\tclose(3)\r\n\r\nreturn\r\nend \r\n\r\n!-----------------------------------------------------------------!\r\nsubroutine outw(i1,nx,ny,dx,dy,time,w)\r\nimplicit none\r\ninteger ::nx,ny,i1,i,j\r\ndouble precision::dx,dy,time,w(-2:nx+2,-2:ny+2),wmax\r\n\r\nopen(50000+i1)\r\nwrite(50000+i1,*) 'variables =\"x\",\"y\",\"w\"'\r\nwrite(50000+i1,51)'zone f=point i=',nx+1,',j=',ny+1,',t=\"time',time,'\"'\r\ndo j=0,ny\r\ndo i=0,nx\r\nwrite(50000+i1,52) dfloat(i)*dx,dfloat(j)*dy,w(i,j)\r\nend do\r\nend do\r\nclose(50000+i1)\r\n\r\n! wmax = maxval(w)\r\n! open(20000+i1)\r\n! write(20000+i1,*) 'variables =\"x\",\"y\",\"w\"'\r\n! write(20000+i1,51)'zone f=point i=',nx+1,',j=',ny+1,',t=\"time',time,'\"'\r\n! do j=0,ny\r\n! do i=0,nx\r\n! write(20000+i1,52) dfloat(i)*dx,dfloat(j)*dy,w(i,j)/wmax\r\n! end do\r\n! end do\r\n! close(20000+i1)\r\n\r\n\r\n51 format(a16,i8,a4,i8,a10,f10.4,a3)\r\n52 format(3e16.6)\r\nreturn\r\nend \r\n\r\n\r\n!-----------------------------------------------------------------!\r\nsubroutine spec(i2,nx,ny,time,w)\r\nimplicit none\r\ninteger ::nx,ny,i2\r\ndouble precision::w(-2:nx+2,-2:ny+2)\r\ndouble precision::time,pi\r\ninteger::i,j,k,n,ic\r\ndouble precision::kx(0:nx-1),ky(0:ny-1),kk\r\ndouble precision,parameter:: tiny=1.0d-10\r\ndouble precision,dimension(:),allocatable:: data1d,en\r\ndouble precision,dimension(:,:),allocatable::es\r\ninteger,parameter::ndim=2\r\ninteger::nn(ndim),isign\r\n\r\nallocate(data1d(2*nx*ny))\r\n\r\npi = 4.0d0*datan(1.0d0)\r\n\r\nnn(1)= nx\r\nnn(2)= ny\r\n\r\n!finding fourier coefficients of w \r\n!invese fourier transform\r\n!find the vorticity in Fourier space\r\nk=1\r\ndo j=0,ny-1 \r\ndo i=0,nx-1 \r\n\tdata1d(k) = w(i,j)\r\n\tdata1d(k+1) = 0.0d0 \r\nk = k + 2\r\nend do\r\nend do\r\n!normalize\r\ndo k=1,2*nx*ny\r\ndata1d(k)=data1d(k)/dfloat(nx*ny)\r\nend do\r\n!inverse fourier transform\r\nisign= -1\r\ncall fourn(data1d,nn,ndim,isign)\r\n\r\n\r\n!Wave numbers \r\ndo i=0,nx/2-1\r\nkx(i) = dfloat(i)\r\nkx(i+nx/2) = dfloat(i-nx/2)\r\nend do\r\nkx(0) = tiny\r\n\r\ndo j=0,ny/2-1\r\nky(j) = dfloat(j)\r\nky(j+ny/2) = dfloat(j-ny/2)\r\nend do\r\nky(0) = tiny\r\n\r\n!Energy spectrum (for all wavenumbers)\r\nallocate(es(0:nx-1,0:ny-1))\r\nk=1\r\ndo j=0,ny-1\r\ndo i=0,nx-1 \r\nkk = dsqrt(kx(i)*kx(i) + ky(j)*ky(j))\r\nes(i,j) = pi*(data1d(k)*data1d(k) + data1d(k+1)*data1d(k+1))/kk\r\nk = k + 2\r\nend do\r\nend do\r\n\r\nopen(600+i2)\r\nwrite(600+i2,*)'variables =\"k\",\"E(k)\"'\r\nwrite(600+i2,54)'zone f=point i=',(nx-1)*(ny-1),',t=\"time',time,'\"'\r\ndo j=1,ny-1\r\ndo i=1,nx-1\r\nkk = dsqrt(kx(i)*kx(i) + ky(j)*ky(j))\r\nwrite(600+i2,103) kk,es(i,j)\r\nend do\r\nend do\r\nclose(600+i2)\r\n\r\n\r\n!Plot angle avaraged energy spectrum\r\nn = nint(0.5d0*dsqrt(dfloat(nx*nx + ny*ny)))-1\r\nallocate(en(n))\r\n\r\ndo k=1,n\r\nen(k) = 0.0d0\r\nic = 0\r\ndo j=1,ny-1\r\ndo i=1,nx-1\r\nkk = dsqrt(kx(i)*kx(i) + ky(j)*ky(j))\r\n if(kk.ge.(dfloat(k)-0.5d0).and.kk.le.(dfloat(k)+0.5d0)) then\r\n ic = ic + 1\r\n en(k) = en(k) + es(i,j)\r\n end if\r\nend do\r\nend do\r\nen(k) = en(k) / dfloat(ic)\r\nend do\r\n\r\nopen(700+i2)\r\nwrite(700+i2,*)'variables =\"k\",\"E(k)\"'\r\nwrite(700+i2,54)'zone f=point i=',n,',t=\"time',time,'\"'\r\n!write(77,54)'zone f=point i=',n,',t=\"time',time,'\"'\r\ndo k=1,n\r\nwrite(700+i2,103)dfloat(k),en(k)\r\n!write(77,103)dfloat(k),en(k)\r\nend do\r\nclose(700+i2)\r\n\r\n\r\ndeallocate(data1d,es,en)\r\n\r\n103 format(2e16.6)\r\n54 format(a16,i8,a10,f10.4,a3)\r\nreturn\r\nend \r\n\r\n\r\n\r\n!-----------------------------------------------------------------!\r\nsubroutine line(i3,nx,ny,dx,dy,time,w)\r\nimplicit none\r\ninteger ::nx,ny,i3,i,j\r\ndouble precision::dx,dy,time,w(-2:nx+2,-2:ny+2)\r\n\r\nopen(300+i3)\r\nwrite(300+i3,*) 'variables =\"y\",\"w\"'\r\nwrite(300+i3,54)'zone f=point i=',ny+1,',t=\"time',time,'\"'\r\ndo j=0,ny\r\nwrite(300+i3,55) dfloat(j)*dy,w(nx/2,j)\r\nend do\r\nclose(300+i3)\r\n\r\nopen(400+i3)\r\nwrite(400+i3,*) 'variables =\"x\",\"w\"'\r\nwrite(400+i3,54)'zone f=point i=',nx+1,',t=\"time',time,'\"'\r\ndo i=0,nx\r\nwrite(400+i3,55) dfloat(i)*dx,w(i,ny/2)\r\nend do\r\nclose(400+i3)\r\n\r\n\r\n54 format(a16,i8,a10,f10.4,a3)\r\n55 format(2e16.6)\r\nreturn\r\nend \r\n\r\n!-----------------------------------------------------------------!\r\n!Compute structure functions\r\n!-----------------------------------------------------------------!\r\nsubroutine strfun(i4,nx,ny,time,w)\r\nimplicit none\r\ninteger::nx,ny,ic,p,i4,i,j\r\ndouble precision::time\r\ndouble precision::w(-2:nx+2,-2:ny+2),dw2(nx/2)\r\n\r\ndo p=1,nx/2\r\n\r\n\tic=0\r\n\tdw2(p)=0.0d0\t\t\r\n\t!computing x directional vorticity difference\r\n\tdo j=0,ny\r\n\tdo i=0,nx-p\t\r\n\t\tic=ic+1\t\t\r\n\t\tdw2(p)=dw2(p) + (w(i+p,j)-w(i,j))**2\r\n\tend do\r\n\tend do\r\n\r\n\t!computing y directional vorticity difference\r\n\tdo i=0,nx\r\n\tdo j=0,ny-p\t\r\n\t\tic = ic+1\t\t\r\n\t\tdw2(p)=dw2(p) + (w(i,j+p)-w(i,j))**2\r\n\tend do\r\n\tend do \r\n\r\n\t!normalizing (ensamble averaging)\r\n\tdw2(p)=dw2(p)/dfloat(ic)\r\n\r\nend do\r\n\r\n\r\n!writing\r\nopen(800+i4)\r\nwrite(800+i4,*) 'variables =\"r\",\"SF2\"'\r\nwrite(800+i4,54)'zone f=point i=',nx/2,',t=\"time',time,'\"'\r\ndo i=1,nx/2\r\nwrite(800+i4,*)i,dw2(i)\r\nend do\r\nclose(800+i4)\r\n\r\n54 format(a16,i8,a10,f10.4,a3)\r\nreturn\r\nend \r\n\r\n\r\n\r\n!-----------------------------------------------------------------!\r\n! fft routine from numerical recipes\r\n! ndim: dimension of the transform (i.e.; 2 for 2d problems)\r\n! nn : number of points in each direction\r\n! data: one-dimensional array including real and imaginary part \r\n!-----------------------------------------------------------------!\r\nsubroutine fourn(data,nn,ndim,isign)\r\nimplicit none\r\ninteger:: ndim,isign\r\ninteger:: nn(ndim)\r\nreal*8:: data(*)\r\nreal*8:: wr,wi,wpr,wpi,wtemp,theta,tempr,tempi\r\ninteger::ntot,n,nrem,nprev,idim,ip1,ip2,ip3,i1,i2,i3\r\ninteger::i2rev,i3rev,ibit,ifp1,ifp2,k1,k2\r\n\r\n ntot=1\r\n do 11 idim=1,ndim\r\n ntot=ntot*nn(idim)\r\n11 continue\r\n nprev=1\r\n do 18 idim=1,ndim\r\n n=nn(idim)\r\n nrem=ntot/(n*nprev)\r\n ip1=2*nprev\r\n ip2=ip1*n\r\n ip3=ip2*nrem\r\n i2rev=1\r\n do 14 i2=1,ip2,ip1\r\n if(i2.lt.i2rev)then\r\n do 13 i1=i2,i2+ip1-2,2\r\n do 12 i3=i1,ip3,ip2\r\n i3rev=i2rev+i3-i2\r\n tempr=data(i3)\r\n tempi=data(i3+1)\r\n data(i3)=data(i3rev)\r\n data(i3+1)=data(i3rev+1)\r\n data(i3rev)=tempr\r\n data(i3rev+1)=tempi\r\n12 continue\r\n13 continue\r\n endif\r\n ibit=ip2/2\r\n1 if ((ibit.ge.ip1).and.(i2rev.gt.ibit)) then\r\n i2rev=i2rev-ibit\r\n ibit=ibit/2\r\n go to 1\r\n endif\r\n i2rev=i2rev+ibit\r\n14 continue\r\n ifp1=ip1\r\n2 if(ifp1.lt.ip2)then\r\n ifp2=2*ifp1\r\n theta=isign*6.28318530717959d0/(ifp2/ip1)\r\n wpr=-2.d0*dsin(0.5d0*theta)**2\r\n wpi=dsin(theta)\r\n wr=1.d0\r\n wi=0.d0\r\n do 17 i3=1,ifp1,ip1\r\n do 16 i1=i3,i3+ip1-2,2\r\n do 15 i2=i1,ip3,ifp2\r\n k1=i2\r\n k2=k1+ifp1\r\n tempr=sngl(wr)*data(k2)-sngl(wi)*data(k2+1)\r\n tempi=sngl(wr)*data(k2+1)+sngl(wi)*data(k2)\r\n data(k2)=data(k1)-tempr\r\n data(k2+1)=data(k1+1)-tempi\r\n data(k1)=data(k1)+tempr\r\n data(k1+1)=data(k1+1)+tempi\r\n15 continue\r\n16 continue\r\n wtemp=wr\r\n wr=wr*wpr-wi*wpi+wr\r\n wi=wi*wpr+wtemp*wpi+wi\r\n17 continue\r\n ifp1=ifp2\r\n go to 2\r\n endif\r\n nprev=n*nprev\r\n18 continue\r\n\r\nreturn\r\nend\r\n\r\n\r\n!---------------------------------------------------------------------------!\r\n!Spectral accurate Poisson solver\r\n!Periodic, equidistant grid\r\n!Taken from MAE5093 - Github\r\n!Matches with GS\r\n!---------------------------------------------------------------------------!\r\nsubroutine fps4(nx,ny,dx,dy,f_org,u_org)\r\nimplicit none\r\ninteger,intent(in)::nx,ny\r\ndouble precision,intent(in) ::dx,dy\r\ndouble precision,intent(in)::f_org(-2:nx+2,-2:ny+2)\r\ndouble precision,intent(inout):: u_org(-2:nx+2,-2:ny+2)\r\ndouble precision ::pi,Lx,Ly,den\r\ndouble precision ::kx(0:nx-1),ky(0:ny-1) \r\ndouble precision ::data1d(2*nx*ny) \r\ninteger::i,j,k,isign,ndim,nn(2)\r\n\r\n!2d data\r\nndim =2\r\nnn(1)=nx\r\nnn(2)=ny\r\n\r\n!1.Find the f coefficient in Fourier space\r\n!assign 1d data array\r\nk=1\r\ndo j=0,ny-1 \r\ndo i=0,nx-1 \r\n data1d(k) = f_org(i,j)\r\n data1d(k+1) = 0.0d0 \r\nk = k + 2\r\nend do\r\nend do\r\n\r\n!normalize\r\ndo k=1,2*nx*ny\r\ndata1d(k)=data1d(k)/dfloat(nx*ny)\r\nend do\r\n!inverse fourier transform\r\nisign= -1\r\ncall fourn(data1d,nn,ndim,isign)\r\n\r\n!2.Solve for u coeeficient in Fourier space\r\n!coefficients\r\nLx = dfloat(nx)*dx\r\nLy = dfloat(ny)*dy\r\n\r\n!wave numbers (scaled)\r\npi = 4.0d0*datan(1.0d0)\r\ndo i=0,nx/2-1\r\nkx(i) = (2.0d0*pi/Lx)*dfloat(i)\r\nkx(i+nx/2) = (2.0d0*pi/Lx)*dfloat(i-nx/2)\r\nend do\r\ndo j=0,ny/2-1\r\nky(j) = (2.0d0*pi/Ly)*dfloat(j)\r\nky(j+ny/2) = (2.0d0*pi/Ly)*dfloat(j-ny/2)\r\nend do\r\nkx(0) = 1.0d-6 !to eleminate zero division\r\nky(0) = 1.0d-6 !to eleminate zero division\r\ndata1d(1) = 0.0d0\r\ndata1d(2) = 0.0d0\r\n\r\n!Fourier coefficients for u\r\nk=1\r\ndo j=0,ny-1\r\ndo i=0,nx-1 \r\n den = -(kx(i)*kx(i))-(ky(j)*ky(j))\r\n data1d(k) = data1d(k)/den\r\n data1d(k+1) = data1d(k+1)/den\r\nk = k + 2\r\nend do\r\nend do\r\n\r\n!3. Find u values on physical space\r\n!forward fourier transform\r\nisign= 1\r\ncall fourn(data1d,nn,ndim,isign)\r\n\r\n!assign 2d array\r\nk=1\r\ndo j=0,ny-1\r\ndo i=0,nx-1\r\nu_org(i,j)=data1d(k)\r\nk=k+2\r\nend do\r\nend do\r\n\r\n\r\n! periodicity\r\ndo i=0,nx-1\r\nu_org(i,ny)=u_org(i,0)\r\nend do\r\ndo j=0,ny-1\r\nu_org(nx,j)=u_org(0,j)\r\nend do\r\nu_org(nx,ny)=u_org(0,0)\r\n\r\n!extend for periodic b.c.\r\ncall bc(nx,ny,u_org)\r\n\r\nreturn\r\nend\r\n\r\n! !-----------------------------------------------------------------------------------------!\r\n! !fast Poisson solver in 2D periodic domain (forth-order)\r\n! !-----------------------------------------------------------------------------------------!\r\n! subroutine fps4(nx,ny,dx,dy,f,u)\r\n! implicit none\r\n! integer::nx,ny\r\n! real*8 ::f(-2:nx+2,-2:ny+2),u(-2:nx+2,-2:ny+2)\r\n! real*8 ::dx,dy\r\n! real*8 ::data1d(2*nx*ny)\r\n! integer,parameter::ndim=2\r\n! integer::nn(ndim),isign\r\n! real*8 ::pi,hx,hy,ra,aa,bb,cc,dd,ee,nom,den\r\n! integer::i,j,k\r\n! real*8,parameter:: eps=1.0d-10\r\n\r\n! nn(1)= nx\r\n! nn(2)= ny\r\n\r\n! pi = 4.0d0*datan(1.0d0)\r\n! ra = dx/dy\r\n! hx = 2.0d0*pi/dfloat(nx)\r\n! hy = 2.0d0*pi/dfloat(ny)\r\n! aa =-10.0d0*(1.0d0 + ra*ra )\r\n! bb = 5.0d0-ra*ra\r\n! cc = 5.0d0*ra*ra -1.0d0\r\n! dd = 0.5d0*(1.0d0 +ra*ra)\r\n! ee = (dx*dx)/2.0d0\r\n\r\n! !step-1\r\n! !finding fourier coefficients of f \r\n! !invese fourier transform\r\n! k=1\r\n! do j=0,ny-1\r\n! do i=0,nx-1\r\n! data1d(k) =f(i,j)\r\n! data1d(k+1)=0.0d0\r\n! k=k+2\r\n! end do\r\n! end do\r\n\r\n! isign=-1\r\n! call fourn(data1d,nn,ndim,isign)\r\n\r\n! do j=1,2*nx*ny\r\n! data1d(j)=data1d(j)/dfloat(nx*ny)\r\n! end do\r\n\r\n! !step-2\r\n! !find fourier coefficients of u\r\n! !algebraic equation\r\n! k=1\r\n! do j=0,ny-1\r\n! do i=0,nx-1\r\n! nom = data1d(k)*ee*(8.0d0 + 2.0d0*dcos(hx*dfloat(i)) + 2.0d0*dcos(hy*dfloat(j)))\r\n! den = aa + 2.0d0*bb*dcos(hx*dfloat(i)) + 2.0d0*cc*dcos(hy*dfloat(j)) + 4.0d0*dd*dcos(hx*dfloat(i))*dcos(hy*dfloat(j)) + eps\r\n! data1d(k)=nom/den\r\n! data1d(k+1)=nom/den\r\n! k=k+2\r\n! end do \r\n! end do\r\n\r\n\r\n! !step-3\r\n! !find the u\r\n! !forward fourier transform\r\n! isign= 1\r\n! call fourn(data1d,nn,ndim,isign)\r\n\r\n! k=1\r\n! do j=0,ny-1\r\n! do i=0,nx-1\r\n! u(i,j)=data1d(k)\r\n! k=k+2\r\n! end do\r\n! end do\r\n\r\n! ! periodicity\r\n! do i=0,nx-1\r\n! u(i,ny)=u(i,0)\r\n! end do\r\n! do j=0,ny-1\r\n! u(nx,j)=u(0,j)\r\n! end do\r\n! u(nx,ny)=u(0,0)\r\n\r\n! !extend for periodic b.c.\r\n! call bc(nx,ny,u)\r\n \r\n! return\r\n! end\r\n\r\n\r\n\r\n!------------------------------------------------------------------!\r\n! compact interpolations for derivarives\r\n!------------------------------------------------------------------!\r\n\r\n!------------------------------------------------------------------!\r\n! c4dp: 4th-order compact scheme for first-degree derivative(up)\r\n! periodic boundary conditions (0=n), h=grid spacing\r\n! tested\r\n!------------------------------------------------------------------!\r\nsubroutine c4dp(u,up,h,n)\r\nimplicit none\r\ninteger :: n,i\r\ndouble precision :: h,alpha,beta\r\ndouble precision , dimension (0:n) :: u,up\r\ndouble precision , dimension (0:n-1):: a,b,c,r,x \r\n\r\ndo i=0,n-1\r\na(i) = 1.0d0/4.0d0\r\nb(i) = 1.0d0\r\nc(i) = 1.0d0/4.0d0\r\nend do\r\n\r\ndo i=1,n-1\r\nr(i) = 3.0d0/2.0d0*(u(i+1)-u(i-1))/(2.0d0*h) \r\nend do\r\nr(0) = 3.0d0/2.0d0*(u(1)-u(n-1))/(2.0d0*h) \r\n \r\nalpha = 1.0d0/4.0d0\r\nbeta = 1.0d0/4.0d0\r\n\r\ncall ctdms(a,b,c,alpha,beta,r,x,0,n-1) \r\n\r\ndo i=0,n-1\r\nup(i)=x(i)\r\nend do\r\nup(n)=up(0)\r\n\r\nreturn\r\nend\r\n\r\n!------------------------------------------------------------------!\r\n! c6dp: 6th-order compact scheme for first-degree derivative(up)\r\n! periodic boundary conditions (0=n), h=grid spacing\r\n! tested\r\n!------------------------------------------------------------------!\r\nsubroutine c6dp(u,up,h,n)\r\nimplicit none\r\ninteger :: n,i\r\ndouble precision :: h,alpha,beta\r\ndouble precision , dimension (0:n) :: u,up\r\ndouble precision , dimension (0:n-1):: a,b,c,r,x \r\n\r\ndo i=0,n-1\r\na(i) = 1.0d0/3.0d0\r\nb(i) = 1.0d0\r\nc(i) = 1.0d0/3.0d0\r\nend do\r\n\r\ndo i=2,n-2\r\nr(i) = 14.0d0/9.0d0*(u(i+1)-u(i-1))/(2.0d0*h) &\r\n + 1.0d0/9.0d0*(u(i+2)-u(i-2))/(4.0d0*h)\r\nend do\r\nr(1) = 14.0d0/9.0d0*(u(2)-u(0))/(2.0d0*h) &\r\n + 1.0d0/9.0d0*(u(3)-u(n-1))/(4.0d0*h) \r\n\r\nr(n-1) = 14.0d0/9.0d0*(u(n)-u(n-2))/(2.0d0*h) &\r\n + 1.0d0/9.0d0*(u(1)-u(n-3))/(4.0d0*h)\r\n\r\nr(0) = 14.0d0/9.0d0*(u(1)-u(n-1))/(2.0d0*h) &\r\n + 1.0d0/9.0d0*(u(2)-u(n-2))/(4.0d0*h)\r\n \r\nalpha = 1.0d0/3.0d0\r\nbeta = 1.0d0/3.0d0\r\n\r\ncall ctdms(a,b,c,alpha,beta,r,x,0,n-1) \r\n\r\ndo i=0,n-1\r\nup(i)=x(i)\r\nend do\r\nup(n)=up(0)\r\n\r\nreturn\r\nend\r\n\r\n!------------------------------------------------------------------!\r\n! c4ddp: 4th-order compact scheme for second-degree derivative(upp)\r\n! periodic boundary conditions (0=n), h=grid spacing\r\n! tested\r\n!------------------------------------------------------------------!\r\nsubroutine c4ddp(u,upp,h,n)\r\nimplicit none\r\ninteger :: n,i\r\ndouble precision :: h,alpha,beta\r\ndouble precision , dimension (0:n) :: u,upp\r\ndouble precision , dimension (0:n-1):: a,b,c,r,x \r\n\r\ndo i=0,n-1\r\na(i) = 1.0d0/10.0d0\r\nb(i) = 1.0d0\r\nc(i) = 1.0d0/10.0d0\r\nend do\r\n\r\ndo i=1,n-1\r\nr(i) = 6.0d0/5.0d0*(u(i-1)-2.0d0*u(i)+u(i+1))/(h*h) \r\nend do\r\nr(0) = 6.0d0/5.0d0*(u(n-1)-2.0d0*u(0)+u(1))/(h*h) \r\n \r\nalpha = 1.0d0/10.0d0\r\nbeta = 1.0d0/10.0d0\r\n\r\ncall ctdms(a,b,c,alpha,beta,r,x,0,n-1) \r\n\r\ndo i=0,n-1\r\nupp(i)=x(i)\r\nend do\r\nupp(n)=upp(0)\r\n\r\nreturn\r\nend\r\n\r\n!------------------------------------------------------------------!\r\n! c6ddp: 6th-order compact scheme for second-degree derivative(upp)\r\n! periodic boundary conditions (0=n), h=grid spacing\r\n! tested\r\n!------------------------------------------------------------------!\r\nsubroutine c6ddp(u,upp,h,n)\r\nimplicit none\r\ninteger :: n,i\r\ndouble precision :: h,alpha,beta\r\ndouble precision , dimension (0:n) :: u,upp\r\ndouble precision , dimension (0:n-1):: a,b,c,r,x \r\n\r\n\r\ndo i=0,n-1\r\na(i) = 2.0d0/11.0d0\r\nb(i) = 1.0d0\r\nc(i) = 2.0d0/11.0d0\r\nend do\r\n\r\ndo i=2,n-2\r\nr(i) = 12.0d0/11.0d0*(u(i-1)-2.0d0*u(i)+u(i+1))/(h*h) &\r\n + 3.0d0/11.0d0*(u(i-2)-2.0d0*u(i)+u(i+2))/(4.0d0*h*h) \r\nend do\r\nr(1) = 12.0d0/11.0d0*(u(0)-2.0d0*u(1)+u(2))/(h*h) &\r\n + 3.0d0/11.0d0*(u(n-1)-2.0d0*u(1)+u(3))/(4.0d0*h*h) \r\n\r\nr(n-1) = 12.0d0/11.0d0*(u(n-2)-2.0d0*u(n-1)+u(n))/(h*h) &\r\n + 3.0d0/11.0d0*(u(n-3)-2.0d0*u(n-1)+u(1))/(4.0d0*h*h) \r\n\r\nr(0) = 12.0d0/11.0d0*(u(n-1)-2.0d0*u(0)+u(1))/(h*h) &\r\n + 3.0d0/11.0d0*(u(n-2)-2.0d0*u(0)+u(2))/(4.0d0*h*h) \r\n \r\nalpha = 2.0d0/11.0d0\r\nbeta = 2.0d0/11.0d0\r\n\r\ncall ctdms(a,b,c,alpha,beta,r,x,0,n-1) \r\n\r\ndo i=0,n-1\r\nupp(i)=x(i)\r\nend do\r\nupp(n)=upp(0)\r\n\r\nreturn\r\nend\r\n\r\n!----------------------------------------------------!\r\n! solution tridiagonal systems (regular tri-diagonal)\r\n! a:subdiagonal, b: diagonal, c:superdiagonal\r\n! r:rhs, u:results\r\n! s: starting index\r\n! e: ending index\r\n!----------------------------------------------------!\r\nsubroutine tdms(a,b,c,r,u,s,e)\r\nimplicit none \r\ninteger::s,e\r\ndouble precision ::a(s:e),b(s:e),c(s:e),r(s:e),u(s:e) \r\ninteger::j \r\ndouble precision ::bet,gam(s:e) \r\nbet=b(s) \r\nu(s)=r(s)/bet \r\ndo j=s+1,e \r\ngam(j)=c(j-1)/bet \r\nbet=b(j)-a(j)*gam(j) \r\nu(j)=(r(j)-a(j)*u(j-1))/bet \r\nend do \r\ndo j=e-1,s,-1 \r\nu(j)=u(j)-gam(j+1)*u(j+1) \r\nend do \r\nreturn \r\nend \r\n\r\n\r\n!-------------------------------------------------------------------!\r\n! solution of cyclic tridiagonal systems (periodic tridiagonal)\r\n! n:matrix size (starting from 1)\r\n! a:subdiagonal, b: diagonal, c:superdiagonal\r\n! r:rhs, x:results\r\n! alpha:sub entry (first value in e-th eq.)\r\n! beta: super entry (last value in s-th eq.)\r\n!-------------------------------------------------------------------!\r\nsubroutine ctdms(a,b,c,alpha,beta,r,x,s,e) \r\nimplicit none\r\ninteger:: s,e\r\ndouble precision :: alpha,beta,a(s:e),b(s:e),c(s:e),r(s:e),x(s:e) \r\ninteger:: i \r\ndouble precision :: fact,gamma,bb(s:e),u(s:e),z(s:e)\r\nif((e-s).le.2) then\r\nwrite(*,*) ' matrix too small in cyclic' \r\nstop\r\nend if \r\ngamma=-b(s) \r\nbb(s)=b(s)-gamma \r\nbb(e)=b(e)-alpha*beta/gamma \r\ndo i=s+1,e-1 \r\nbb(i)=b(i) \r\nend do \r\ncall tdms(a,bb,c,r,x,s,e) \t \r\nu(s)=gamma \r\nu(e)=alpha \r\ndo i=s+1,e-1 \r\nu(i)=0.0d0 \r\nend do \r\ncall tdms(a,bb,c,u,z,s,e) \r\nfact=(x(s)+beta*x(e)/gamma)/(1.0d0+z(s)+beta*z(e)/gamma) \r\ndo i=s,e \r\nx(i)=x(i)-fact*z(i) \r\nend do \r\nreturn \r\nend\r\n\r\n\r\n!----------------------------------------------------------!\r\n!Simpson's 1/3 rule for numerical integration of g(i,j)\r\n!for equally distributed mesh with interval dx and dy\r\n!n should be power of 2\r\n!dual integration\r\n!----------------------------------------------------------!\r\nsubroutine simp2D(nx,ny,dx,dy,g,s)\r\nimplicit none\r\ninteger::nx,ny,i,j,nh\r\nreal*8 ::dx,dy,g(0:nx,0:ny),s,ds,th\r\nreal*8,allocatable::sy(:)\r\n\r\nallocate(sy(0:ny))\r\n\r\n\tnh = int(nx/2)\r\n\tth = 1.0d0/3.0d0*dx\r\n \r\ndo j=0,ny\r\n\tsy(j) = 0.0d0\r\n\tdo i=0,nh-1\r\n\tds = th*(g(2*i,j)+4.0d0*g(2*i+1,j)+g(2*i+2,j))\r\n\tsy(j) = sy(j) + ds\r\n\tend do\r\nend do\r\n\r\n\tnh = int(ny/2)\t\r\n\tth = 1.0d0/3.0d0*dy\r\n \r\n\ts = 0.0d0\r\n\tdo j=0,nh-1\r\n\tds = th*(sy(2*j)+4.0d0*sy(2*j+1)+sy(2*j+2))\r\n\ts = s + ds\r\n\tend do\r\n\r\ndeallocate(sy)\r\nreturn\r\nend\r\n", "meta": {"hexsha": "2833f026c6110c42de6c50cebd58e3b3a60ae19b", "size": 67631, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Misc_Fortran_C/NS2D/ns2d.f90", "max_stars_repo_name": "Romit-Maulik/Tutorials-Demos-Practice", "max_stars_repo_head_hexsha": "a58ddc819f24a16f7059e63d7f201fc2cd23e03a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2020-09-02T14:46:07.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-29T15:27:05.000Z", "max_issues_repo_path": "Misc_Fortran_C/NS2D/ns2d.f90", "max_issues_repo_name": "omersan/Practice", "max_issues_repo_head_hexsha": "77eecdc2a202e6b333123cfd92e7db6dc0eea021", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 18, "max_issues_repo_issues_event_min_datetime": "2020-11-13T18:49:33.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-12T00:54:43.000Z", "max_forks_repo_path": "Misc_Fortran_C/NS2D/ns2d.f90", "max_forks_repo_name": "omersan/Practice", "max_forks_repo_head_hexsha": "77eecdc2a202e6b333123cfd92e7db6dc0eea021", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-09-25T23:57:00.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-18T08:15:34.000Z", "avg_line_length": 21.3145288371, "max_line_length": 126, "alphanum_fraction": 0.517795094, "num_tokens": 25582, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587817066391, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6551557956750031}} {"text": "PROGRAM two_var_func\nIMPLICIT NONE\n REAL:: x, y ! User inputs for f(x,y)\n REAL :: result ! The output of f(x,y)\n WRITE(*, *) \"Enter real number values for the variables x and y.\"\n READ(*, *) x, y\n\n IF ((x .GE. 0) .AND. (y .GE. 0)) THEN\n result = x + y\n WRITE(*, *) \"f(x,y) = x + y\"\n ELSE IF ((x .GE. 0) .AND. (y .LT. 0)) THEN\n result = x + y**2\n WRITE(*, *) \"f(x,y) = x + y^2\"\n ELSE IF ((x .LT. 0) .AND. (y .GE. 0)) THEN\n result = x**2 + y\n WRITE(*, *) \"f(x,y) = x^2 + y\"\n ELSE IF ((x .LT. 0) .AND. (y .LT. 0)) THEN\n result = x**2 + y**2\n WRITE(*, *) \"f(x,y) = x^2 + y^2\"\n END IF\n\n WRITE(*, *) \"x = \", x, \" y = \", y\n WRITE(*, *) \"f(x,y) = \", result\n \nEND PROGRAM two_var_func\n", "meta": {"hexsha": "e6f7c2914d9efe0d36b4d73f411c0de108e09e91", "size": 712, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap3/two_var_func.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/two_var_func.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/two_var_func.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.3846153846, "max_line_length": 67, "alphanum_fraction": 0.4761235955, "num_tokens": 301, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587846530937, "lm_q2_score": 0.7371581568543044, "lm_q1q2_score": 0.6551557875829461}} {"text": "!\n! file hstcrt.f90\n!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 2005 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Fishpack *\n! * *\n! * A Package of Fortran *\n! * *\n! * Subroutines and Example Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams, Paul Swarztrauber and Roland Sweet *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\n! SUBROUTINE hstcrt (a, b, m, mbdcnd, bda, bdb, c, d, n, nbdcnd, bdc, bdd,\n! elmbda, f, idimf, pertrb, ierror)\n!\n! DIMENSION OF bda(n), bdb(n), bdc(m), bdd(m), f(idimf, n)\n! ARGUMENTS\n!\n! LATEST REVISION May 2016\n!\n! PURPOSE Solves the standard five-point finite\n! difference approximation to the helmholtz\n! equation\n! (d/dx)(du/dx) + (d/dy)(du/dy) + lambda*u\n! = f(x, y)\n! on a staggered grid in cartesian coordinates.\n!\n! USAGE call hstcrt (a, b, m, mbdcnd, bda, bdb, c, d\n! n, nbdcnd, bdc, bdd, elmbda,\n! f, idimf, pertrb, ierror)\n!\n! ARGUMENTS\n! ON INPUT\n!\n! a, b\n! the range of x, i.e. a <= x <= b.\n! a must be less than b.\n!\n! m\n! the number of grid points in the\n! interval (a, b). the grid points\n! in the x-direction are given by\n! x(i) = a + (i-0.5)dx for i=1, 2, ..., m\n! where dx =(b-a)/m. m must be greater\n! than 2.\n!\n! mbdcnd\n! indicates the type of boundary conditions\n! at x = a and x = b.\n!\n! = 0 if the solution is periodic in x,\n! u(m+i, j) = u(i, j).\n!\n! = 1 if the solution is specified at\n! x = a and x = b.\n!\n! = 2 if the solution is specified at\n! x = a and the derivative\n! of the solution with respect to x\n! is specified at x = b.\n!\n! = 3 if the derivative of the solution\n! with respect to x is specified\n! at x = a and x = b.\n!\n! = 4 if the derivative of the solution\n! with respect to x is specified\n! at x = a and the solution is\n! specified at x = b.\n!\n! bda\n! a one-dimensional array of length n\n! that specifies the boundary values\n! (if any) of the solution at x = a.\n!\n! when mbdcnd = 1 or 2,\n! bda(j) = u(a, y(j)) , j=1, 2, ..., n.\n!\n! when mbdcnd = 3 or 4,\n! bda(j) = (d/dx)u(a, y(j)) , j=1, 2, ..., n.\n!\n! bdb\n! a one-dimensional array of length n\n! that specifies the boundary values\n! of the solution at x = b.\n!\n! when mbdcnd = 1 or 4\n! bdb(j) = u(b, y(j)) , j=1, 2, ..., n.\n!\n! when mbdcnd = 2 or 3\n! bdb(j) = (d/dx)u(b, y(j)) , j=1, 2, ..., n.\n!\n! c, d\n! the range of y, i.e. c <= y <= d.\n! c must be less than d.\n!\n!\n! n\n! the number of unknowns in the interval\n! (c, d). the unknowns in the y-direction\n! are given by y(j) = c + (j-0.5)dy,\n! j=1, 2, ..., n, where dy = (d-c)/n.\n! n must be greater than 2.\n!\n! nbdcnd\n! indicates the type of boundary conditions\n! at y = c and y = d.\n!\n!\n! = 0 if the solution is periodic in y, i.e.\n! u(i, j) = u(i, n+j).\n!\n! = 1 if the solution is specified at y = c\n! and y = d.\n!\n! = 2 if the solution is specified at y = c\n! and the derivative of the solution\n! with respect to y is specified at\n! y = d.\n!\n! = 3 if the derivative of the solution\n! with respect to y is specified at\n! y = c and y = d.\n!\n! = 4 if the derivative of the solution\n! with respect to y is specified at\n! y = c and the solution is specified\n! at y = d.\n!\n! bdc\n! a one dimensional array of length m that\n! specifies the boundary values of the\n! solution at y = c.\n!\n! when nbdcnd = 1 or 2,\n! bdc(i) = u(x(i), c) , i=1, 2, ..., m.\n!\n! when nbdcnd = 3 or 4,\n! bdc(i) = (d/dy)u(x(i), c), i=1, 2, ..., m.\n!\n! when nbdcnd = 0, bdc is a dummy variable.\n!\n! bdd\n! a one-dimensional array of length m that\n! specifies the boundary values of the\n! solution at y = d.\n!\n! when nbdcnd = 1 or 4,\n! bdd(i) = u(x(i), d) , i=1, 2, ..., m.\n!\n! when nbdcnd = 2 or 3,\n! bdd(i) = (d/dy)u(x(i), d) , i=1, 2, ..., m.\n!\n! when nbdcnd = 0, bdd is a dummy variable.\n!\n! elmbda\n! the constant lambda in the helmholtz\n! equation. if lambda is greater than 0,\n! a solution may not exist. however,\n! hstcrt will attempt to find a solution.\n!\n! f\n! a two-dimensional array that specifies\n! the values of the right side of the\n! helmholtz equation. for i=1, 2, ..., m\n! and j=1, 2, ..., n\n!\n! f(i, j) = f(x(i), y(j)) .\n!\n! f must be dimensioned at least m x n.\n!\n! idimf\n! the row (or first) dimension of the array\n! f as it appears in the program calling\n! hstcrt. this parameter is used to specify\n! the variable dimension of f.\n! idimf must be at least m.\n!\n!\n! ON OUTPUT f\n! contains the solution u(i, j) of the finite\n! difference approximation for the grid point\n! (x(i), y(j)) for i=1, 2, ..., m, j=1, 2, ..., n.\n!\n! pertrb\n! If a combination of periodic or derivative\n! boundary conditions is specified for a\n! poisson equation (lambda = 0), a solution\n! may not exist. pertrb is a constant,\n! calculated and subtracted from f, which\n! ensures that a solution exists. hstcrt\n! then computes this solution, which is a\n! least squares solution to the original\n! approximation. this solution plus any\n! constant is also a solution; hence, the\n! solution is not unique. the value of\n! pertrb should be small compared to the\n! right side f. otherwise, a solution is\n! obtained to an essentially different problem.\n! this comparison should always be made to\n! insure that a meaningful solution has been\n! obtained.\n!\n! ierror\n! an error flag that indicates invalid input\n! parameters. except to numbers 0 and 6,\n! a solution is not attempted.\n!\n! = 0 no error\n!\n! = 1 a >= b\n!\n! = 2 mbdcnd < 0 or mbdcnd > 4\n!\n! = 3 c >= d\n!\n! = 4 n <= 2\n!\n! = 5 nbdcnd < 0 or nbdcnd > 4\n!\n! = 6 lambda > 0\n!\n! = 7 idimf < m\n!\n! = 8 m <= 2\n!\n! Since this is the only means of indicating\n! a possibly incorrect call to hstcrt, the\n! user should test ierror after the call.\n!\n! = 20 If the dynamic allocation of real and\n! complex workspace required for solution\n! fails (for example if n, m are too large\n! for your computer)\n!\n!\n! I/O None\n!\n! PRECISION 64-bit double precision\n!\n! REQUIRED LIBRARY type_FishpackWorkspace.f90, genbun.f90, type_CyclicReductionUtility.f9090, poistg.f90\n! FILES\n!\n! LANGUAGE Fortran\n!\n! HISTORY * Written by Roland Sweet at NCAR in 1977.\n! released on NCAR's public software libraries\n! in January 1980.\n! * Revised in June 2004 by John Adams using\n! Fortran 90 dynamically allocated workspace.\n!\n! PORTABILITY Fortran 2008\n!\n! ALGORITHM This subroutine defines the finite-difference\n! equations, incorporates boundary data, adjusts\n! the right side when the system is singular\n! and calls either poistg or genbun which solves\n! the linear system of equations.\n!\n! TIMING For large m and n, the operation count\n! is roughly proportional to m*n*log2(n).\n!\n! ACCURACY The solution process employed results in a\n! loss of no more than four significant digits\n! for n and m as large as 64. more detailed\n! information about accuracy can be found in\n! the documentation for package poistg which\n! solves the finite difference equations.\n!\n! REFERENCES U. Schumann and R. Sweet, \"A direct method\n! for the solution of Poisson's equation with\n! boundary conditions on a staggered grid of\n! arbitrary size, \" J. Comp. Phys. 20(1976), \n! PP. 171-182.\n!\nsubmodule(staggered_helmholtz_solvers) staggered_cartesian_solver\n\ncontains\n\n module subroutine hstcrt(a, b, m, mbdcnd, bda, bdb, c, d, n, nbdcnd, bdc, &\n bdd, elmbda, f, idimf, pertrb, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: m\n integer(ip), intent(in) :: mbdcnd\n integer(ip), intent(in) :: n\n integer(ip), intent(in) :: nbdcnd\n integer(ip), intent(in) :: idimf\n integer(ip), intent(out) :: ierror\n real(wp), intent(in) :: a\n real(wp), intent(in) :: b\n real(wp), intent(in) :: c\n real(wp), intent(in) :: d\n real(wp), intent(in) :: elmbda\n real(wp), intent(out) :: pertrb\n real(wp), intent(in) :: bda(:)\n real(wp), intent(in) :: bdb(:)\n real(wp), intent(in) :: bdc(:)\n real(wp), intent(in) :: bdd(:)\n real(wp), intent(inout) :: f(:,:)\n\n ! Local variables\n type(FishpackWorkspace) :: workspace\n\n ! Check input arguments\n call hstcrt_check_input_arguments(a, b, m, mbdcnd, c, d, n, nbdcnd, idimf, ierror)\n\n ! Check error flag\n if (ierror /= 0) return\n\n ! Allocate memory\n call workspace%initialize_staggered_workspace(n, m)\n\n ! Solve system\n associate( rew => workspace%real_workspace )\n call hstcrt_lower_routine(a, b, m, mbdcnd, bda, bdb, &\n c, d, n, nbdcnd, bdc, bdd, &\n elmbda, f, idimf, pertrb, ierror, rew)\n end associate\n\n ! Release memory\n call workspace%destroy()\n\n end subroutine hstcrt\n\n pure subroutine hstcrt_check_input_arguments(a, b, m, mbdcnd, c, d, n, nbdcnd, idimf, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: m\n integer(ip), intent(in) :: mbdcnd\n integer(ip), intent(in) :: n\n integer(ip), intent(in) :: nbdcnd\n integer(ip), intent(in) :: idimf\n integer(ip), intent(out) :: ierror\n real(wp), intent(in) :: a\n real(wp), intent(in) :: b\n real(wp), intent(in) :: c\n real(wp), intent(in) :: d\n\n if (ZERO <= (a-b)) then\n ierror = 1\n return\n else if (mbdcnd < 0 .or. mbdcnd > 4) then\n ierror = 2\n return\n else if (ZERO <= (c-d)) then\n ierror = 3\n return\n else if(3 > n) then\n ierror = 4\n return\n else if (nbdcnd < 0 .or. nbdcnd > 4) then\n ierror = 5\n return\n else if (idimf < m) then\n ierror = 7\n return\n else if (3 > m) then\n ierror = 8\n return\n else\n ierror = 0\n end if\n\n end subroutine hstcrt_check_input_arguments\n\n subroutine hstcrt_lower_routine(a, b, m, mbdcnd, bda, bdb, c, d, n, nbdcnd, bdc, &\n bdd, elmbda, f, idimf, pertrb, ierror, w)\n\n ! Dummy arguments\n integer(ip), intent(in) :: m\n integer(ip), intent(in) :: mbdcnd\n integer(ip), intent(in) :: n\n integer(ip), intent(in) :: nbdcnd\n integer(ip), intent(in) :: idimf\n integer(ip), intent(out) :: ierror\n real(wp), intent(in) :: a\n real(wp), intent(in) :: b\n real(wp), intent(in) :: c\n real(wp), intent(in) :: d\n real(wp), intent(in) :: elmbda\n real(wp), intent(out) :: pertrb\n real(wp), intent(in) :: bda(:)\n real(wp), intent(in) :: bdb(:)\n real(wp), intent(in) :: bdc(:)\n real(wp), intent(in) :: bdd(:)\n real(wp), intent(inout) :: f(:,:)\n real(wp), intent(inout) :: w(:)\n\n ! Local variables\n integer(ip) :: nperod, mperod, np, mp\n integer(ip) :: id2, id3, id4, local_error_flag\n real(wp) :: dx, twdelx, delxsq, dy\n real(wp) :: twdely, dy2, twdysq, s, two_s\n type(CenteredCyclicReductionUtility) :: centered_util\n type(StaggeredCyclicReductionUtility) :: staggered_util\n\n nperod = nbdcnd\n\n if (mbdcnd > 0) then\n mperod = 1\n else\n mperod = 0\n end if\n\n dx = (b - a)/m\n twdelx = ONE/dx\n delxsq = TWO/dx**2\n dy = (d - c)/n\n twdely = ONE/dy\n dy2 = dy**2\n twdysq = TWO/dy2\n np = nbdcnd + 1\n mp = mbdcnd + 1\n !\n ! define the a, b, c coefficients in w-array.\n !\n id2 = m\n id3 = id2 + m\n id4 = id3 + m\n s = (dy/dx)**2\n two_s = TWO*s\n w(:m) = s\n w(id2+1:m+id2) = (-two_s) + elmbda*dy2\n w(id3+1:m+id3) = s\n !\n ! Set boundary data for x-boundaries.\n !\n if (mp /= 1) then\n select case (mp)\n case (2:3)\n f(1, :n) = f(1, :n) - bda(:n)*delxsq\n w(id2+1) = w(id2+1) - w(1)\n case (4:5)\n f(1, :n) = f(1, :n) + bda(:n)*twdelx\n w(id2+1) = w(id2+1) + w(1)\n end select\n\n select case (mp)\n case (2, 5)\n f(m, :n) = f(m, :n) - bdb(:n)*delxsq\n w(id3) = w(id3) - w(1)\n case (3:4)\n f(m, :n) = f(m, :n) - bdb(:n)*twdelx\n w(id3) = w(id3) + w(1)\n end select\n end if\n\n if (np /= 1) then\n select case (np)\n case (2:3)\n f(:m, 1) = f(:m, 1) - bdc(:m)*twdysq\n case (4:5)\n f(:m, 1) = f(:m, 1) + bdc(:m)*twdely\n end select\n\n select case (np)\n case (2, 5)\n f(:m, n) = f(:m, n) - bdd(:m)*twdysq\n case (3:4)\n f(:m, n) = f(:m, n) - bdd(:m)*twdely\n end select\n end if\n\n f(:m, :n) = f(:m, :n)*dy2\n\n if (mperod /= 0) then\n w(1) = ZERO\n w(id4) = ZERO\n end if\n\n pertrb = ZERO\n\n if (elmbda >= ZERO) then\n if (elmbda /= ZERO) then\n ierror = 6\n return\n else\n select case (mp)\n case (1, 4)\n select case (np)\n case (1, 4)\n !\n ! For singular problems must adjust data to\n ! insure that a solution will exist.\n !\n s = sum(f(:m, 1:n))\n\n pertrb = s/(m*n)\n f(:m, :n) = f(:m, :n) - pertrb\n pertrb = pertrb/dy2\n end select\n end select\n end if\n end if\n\n associate( &\n iw1 => 1, &\n iw2 => id2 + 1, &\n iw3 => id3 + 1, &\n iw4 => id4 + 1 &\n )\n select case (nperod)\n case (0)\n\n ! Solve system with call to genbun_lower_routine\n call centered_util%genbun_lower_routine(nperod, n, mperod, m, w(iw1:), w(iw2:), w(iw3:), &\n idimf, f, local_error_flag, w(iw4:))\n\n ! Check error flag\n if (local_error_flag /= 0) then\n error stop 'fishpack library: genbun_lower_routine call failed in hstcrt_lower_routine'\n end if\n\n case default\n\n ! Solve system with call to poistg_lower_routine\n call staggered_util%poistg_lower_routine(nperod, n, mperod, m, w(iw1:), w(iw2:), w(iw3:), &\n idimf, f, local_error_flag, w(iw4:))\n\n ! Check error flag\n if (local_error_flag /= 0) then\n error stop 'fishpack library: poistg_lower_routine call failed in hstcrt_lower_routine'\n end if\n end select\n end associate\n\n end subroutine hstcrt_lower_routine\n\nend submodule staggered_cartesian_solver\n", "meta": {"hexsha": "feac741a93acdca9669fb824c1cf9addcc4995c4", "size": 21865, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/staggered_cartesian_solver.f90", "max_stars_repo_name": "jlokimlin/fishpack", "max_stars_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2018-03-12T11:31:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-27T07:58:23.000Z", "max_issues_repo_path": "src/staggered_cartesian_solver.f90", "max_issues_repo_name": "jlokimlin/fishpack", "max_issues_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2016-05-07T22:42:47.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-15T17:44:58.000Z", "max_forks_repo_path": "src/staggered_cartesian_solver.f90", "max_forks_repo_name": "jlokimlin/modern_fishpack", "max_forks_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-01-26T20:49:05.000Z", "max_forks_repo_forks_event_max_datetime": "2017-01-27T16:44:58.000Z", "avg_line_length": 39.4675090253, "max_line_length": 111, "alphanum_fraction": 0.3773153442, "num_tokens": 5250, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587817066392, "lm_q2_score": 0.7371581568543044, "lm_q1q2_score": 0.6551557854109432}} {"text": "\r\n! --------------------------------------------------------------- TprFrctn\r\n subroutine tprfrctn (frctnFRONT,frctnBACK,Z,NZ)\r\n\r\nc Apply cosine tapers to first frctnfront*nz points of beginning\r\n* and last frctnback*nz points of time series array Z.\r\nc Written by Chuck Mueller, USGS.\r\nc Modified by D. M. Boore on 8/31/88 to eliminate the use of ZNULL;\r\nc see FBCTPR_CSM for the original version.\r\n\r\n* Dates: 2/13/90 - if ifront or iback is zero, do not apply a taper.\r\n* 12/12/00 - specify taper in terms of fraction of number of\r\n* points rather than percent of number (copied from\r\n* fbctpr.for)\r\n! 09/29/12 - Small change to trap for frctn = 0.0\r\n\r\n real Z(*)\r\n\r\n PI = 4.0*ATAN(1.0)\r\n LZ = NZ*frctnFRONT\r\n\r\n if (lz >= 1) then\r\n\r\n SF = PI/LZ\r\n do I=1,LZ\r\n F = 0.5*(1.0-COS(SF*(I-1)))\r\n Z(I) = Z(I)*F\r\n end do\r\n \r\n end if\r\n\r\n LZ = NZ*frctnback\r\n\r\n if (lz >= 1) then\r\n \r\n SF = PI/LZ\r\n do I=NZ,NZ-LZ+1,-1\r\n F = 0.5*(1.0-COS(SF*(NZ-I)))\r\n Z(I) = Z(I)*F\r\n end do\r\n\r\n end if\r\n \r\n return\r\n end\r\n! --------------------------------------------------------------- TprFrctn\r\n\r\n", "meta": {"hexsha": "f0d7f74d97fa4bf1f3a17b046a37c4af1671dc60", "size": 1277, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "bbp/src/usgs/fas/tprfrctn.for", "max_stars_repo_name": "ZhangHCFJEA/bbp", "max_stars_repo_head_hexsha": "33bd999cf8d719c49f9a904872c62f02eb5850d1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2017-10-31T09:16:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T23:44:29.000Z", "max_issues_repo_path": "bbp/src/usgs/fas/tprfrctn.for", "max_issues_repo_name": "ZhangHCFJEA/bbp", "max_issues_repo_head_hexsha": "33bd999cf8d719c49f9a904872c62f02eb5850d1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 37, "max_issues_repo_issues_event_min_datetime": "2017-05-23T15:15:35.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-05T09:13:18.000Z", "max_forks_repo_path": "bbp/src/usgs/fas/tprfrctn.for", "max_forks_repo_name": "ZhangHCFJEA/bbp", "max_forks_repo_head_hexsha": "33bd999cf8d719c49f9a904872c62f02eb5850d1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2017-09-21T17:43:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-29T06:34:30.000Z", "avg_line_length": 26.6041666667, "max_line_length": 75, "alphanum_fraction": 0.4620203602, "num_tokens": 393, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012747599251, "lm_q2_score": 0.6926419894793246, "lm_q1q2_score": 0.655101676601796}} {"text": "C$Procedure DROTAT ( Derivative of a rotation matrix )\n \n SUBROUTINE DROTAT ( ANGLE, IAXIS, DMOUT )\n \nC$ Abstract\nC\nC Calculate the derivative with respect to the angle of rotation\nC of a 3x3 coordinate system rotation matrix generated by a\nC rotation of a specified angle about a specified axis.\nC\nC$ Disclaimer\nC\nC THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE\nC CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.\nC GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE\nC ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE\nC PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED \"AS-IS\"\nC TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY\nC WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A\nC PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC\nC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE\nC SOFTWARE AND RELATED MATERIALS, HOWEVER USED.\nC\nC IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA\nC BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT\nC LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,\nC INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,\nC REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE\nC REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.\nC\nC RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF\nC THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY\nC CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE\nC ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.\nC\nC$ Required_Reading\nC\nC ROTATION\nC\nC$ Keywords\nC\nC MATRIX\nC ROTATION\nC DERIVATIVE\nC\nC$ Declarations\n \n DOUBLE PRECISION ANGLE\n INTEGER IAXIS\n DOUBLE PRECISION DMOUT ( 3,3 )\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC ANGLE I Angle of rotation (radians).\nC IAXIS I Coordinate axis number (X=1, Y=2, Z=3).\nC DMOUT O Derivative of rotation matrix [ANGLE] w.r.t. angle\nC IAXIS\nC$ Detailed_Input\nC\nC ANGLE The angle given in radians, through which the rotation\nC is performed.\nC\nC IAXIS The coordinate axis number of the rotation. The X, Y,\nC and Z axes have indices 1, 2 and 3 respectively.\nC\nC Together ANGLE and IAXIS define the coordinate system\nC rotation [ANGLE] .\nC IAXIS\nC\nC$ Detailed_Output\nC\nC DMOUT Derivative of rotation matrix with respect to the\nC angle of rotation. That is, DMOUT is the derivative\nC with respect to ANGLE of the matrix [ANGLE] .\nC IAXIS\nC\nC (The rotation matrix being differentiated describes\nC the rotation of the COORDINATE system through ANGLE\nC radians about the axis whose index is IAXIS.)\nC\nC$ Parameters\nC\nC None.\nC\nC$ Particulars\nC\nC A coordinate system rotation by ANGLE radians rotation about\nC the first, i.e. x-axis, [ANGLE] is described by\nC 1\nC\nC | 1 0 0 |\nC | 0 cos(ANGLE) sin(ANGLE) |\nC | 0 -sin(ANGLE) cos(ANGLE) |\nC\nC A coordinate system rotation by ANGLE radians rotation about the\nC second, i.e. y-axis, [ANGLE] is described by\nC 2\nC\nC | cos(ANGLE) 0 -sin(ANGLE) |\nC | 0 1 0 |\nC | sin(ANGLE) 0 cos(ANGLE) |\nC\nC A coordinate system rotation by ANGLE radians rotation about\nC the third, i.e. z-axis, [ANGLE] is described by\nC 3\nC\nC | cos(ANGLE) sin(ANGLE) 0 |\nC | -sin(ANGLE) cos(ANGLE) 0 |\nC | 0 0 1 |\nC\nC The derivatives of these matrices are:\nC\nC about the x-axis\nC\nC | 0 0 0 |\nC | 0 -sin(ANGLE) cos(ANGLE) |\nC | 0 -cos(ANGLE) -sin(ANGLE) |\nC\nC about the y-axis\nC\nC | -sin(ANGLE) 0 -cos(ANGLE) |\nC | 0 0 0 |\nC | cos(ANGLE) 0 -sin(ANGLE) |\nC\nC about the z-axis\nC\nC | -sin(ANGLE) cos(ANGLE) 0 |\nC | -cos(ANGLE) -sin(ANGLE) 0 |\nC | 0 0 0 |\nC\nC$ Examples\nC\nC If ROTATE is called from a FORTRAN program as follows:\nC\nC CALL DROTAT (PI()/4, 3, DMOUT)\nC\nC then DMOUT will be\nC\nC |-SQRT(2)/2 SQRT(2)/2 0 |\nC |-SQRT(2)/2 -SQRT(2)/2 0 |\nC | 0 0 0 |\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Exceptions\nC\nC 1) If the axis index is not in the range 1 to 3 the error\nC 'SPICE(BADAXIS)' will be signalled.\nC\nC$ Files\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC W.L. Taber (JPL)\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)\nC\nC Comment section for permuted index source lines was added\nC following the header.\nC\nC- SPICELIB Version 1.0.0, 5-NOV-1990 (WLT)\nC\nC-&\n \nC$ Index_Entries\nC\nC derivative of a rotation matrix\nC\nC-&\n \n \n DOUBLE PRECISION S\n DOUBLE PRECISION C\n \n INTEGER I1\n INTEGER I2\n INTEGER I3\n INTEGER INDEXS ( 5 )\n SAVE INDEXS\n \n DATA INDEXS / 1, 2, 3, 1, 2 /\n \n \n \nC\nC First make sure the input axis is reasonable.\nC\n IF ( ( IAXIS .GT. 3 )\n . .OR. ( IAXIS .LT. 1 ) ) THEN\n \n CALL CHKIN ( 'DROTAT' )\n CALL SETMSG ( 'The input axis is out of range. Its value ' //\n . 'is #.')\n CALL ERRINT ( '#', IAXIS )\n CALL SIGERR ( 'SPICE(BADAXIS)' )\n CALL CHKOUT ( 'DROTAT' )\n RETURN\n \n END IF\n \nC\nC Get the sine and cosine of ANGLE\nC\n S = DSIN(ANGLE)\n C = DCOS(ANGLE)\n \nC\nC Get indices for axes. The first index is for the axis of rotation.\nC The next two axes follow in right hand order (XYZ).\nC\n I1 = INDEXS( IAXIS )\n I2 = INDEXS( IAXIS + 1 )\n I3 = INDEXS( IAXIS + 2 )\n \nC\nC Construct the rotation matrix\nC\n DMOUT(I1,I1) = 0.D0\n DMOUT(I2,I1) = 0.D0\n DMOUT(I3,I1) = 0.D0\n DMOUT(I1,I2) = 0.D0\n DMOUT(I2,I2) = -S\n DMOUT(I3,I2) = -C\n DMOUT(I1,I3) = 0.D0\n DMOUT(I2,I3) = C\n DMOUT(I3,I3) = -S\nC\n RETURN\n END\n \n \n \n", "meta": {"hexsha": "2f1569effec25200a401091e16d4b5fbea749a3c", "size": 6871, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/drotat.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/drotat.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/drotat.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.0448979592, "max_line_length": 72, "alphanum_fraction": 0.5495561054, "num_tokens": 2076, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425377849806, "lm_q2_score": 0.7122321903471563, "lm_q1q2_score": 0.6549990190230143}} {"text": "c=======================================================================\nc\nc subroutine ALLOCSRRFR \nc\nc Sharpe Ratio (SR) maximisation strategy with a risk-free asset\nc\nc Max[ Sharpe Ratio ]\nc s.t. \nc C*w <= b (linear constraints) \nc Cinf <= w <= Csup (lower/upper bounds risky assets)\nc Cinfrfr <= wrfr <= Csuprfr (lower/upper bounds risk-free asset)\nc\nc where, Sharpe Ratio := (rho'*w - rfr)/sqrt(w'Qw)\nc\nc w : risky assets weights\nc wrfr : risk-free asset weights \nc Q : covariance matrix\nc rho : assets performance \nc rfr : risk-free rate\nc\nc-----------------------------------------------------------------------\n SUBROUTINE allocsrrfr (n, cov, rho, rfr,\n & neq, nin, ccst, bcst, \n & cinf, csup, cinfrfr, csuprfr,\n & iwork, dwork, wopt, wrf, info )\nc-----------------------------------------------------------------------\nc\nc INPUT \nc n : number of assets integer\nc cov : covariance matrix (n*n) double\nc rho : expected returns (n) double\nc rfr : risk-free rate double\nc neq : number equality constraints integer\nc nin : number inequality constraints integer\nc ccst : matrix of constraints (n*(neq+nin)) double\nc bcst : vector initial of constraints (neq+nin) double\nc cinf : lower bound (n) double\nc csup : upper bound (n) double\nc cinfrfr : risk-free asset lower bound double\nc csuprfr : risk-free asset upper bound double\nc\nc WORKSPACE \nc iwork : 7*n + 2*nin + neq + 7 integer \nc dwork : n*(5*n+2*neq+3*nin+35)+4*neq+9*nin+27 double\nc\nc OUTPUT \nc wopt : optimal portfolio (n) double\nc wrf : optimal risk-free asset double\nc info : diagnostic arguments integer\nc\nc CALL \nc TESTSDP : matrix SDP test\nc OPSR : computing optimization for ALLOCSR\nc\nc-----------------------------------------------------------------------\nc\n IMPLICIT NONE\nc\nc arguments i/o\n INTEGER n, info, neq, nin\n DOUBLE PRECISION rfr, cinfrfr, csuprfr, wrf \n DOUBLE PRECISION cov(*), rho(*), cinf(*), csup(*), \n & ccst(n,*), bcst(*), wopt(*)\nc\nc workspaces\n INTEGER iwork(*)\n DOUBLE PRECISION dwork(*)\nc\nc local variables\n INTEGER p, i, j, neqtot, nintot, ncst, ntot\n INTEGER piwo, pdwo, pdcov, pdrho, pdlagr, pdc, pdb, pdx, \n & pdcinf, pdcsup\n DOUBLE PRECISION coef, mu, t, sum, rhomax, ZERO, EPS, NEPS, INF, \n & NINF\n PARAMETER (ZERO = 0.0, EPS = 1.E-12, NEPS = -1.E-12)\n PARAMETER (INF = 1.E+12, NINF = -1.E+12)\nc\nc external subroutines\n EXTERNAL testsdp, opmv, qp, YMCPIR, CTSR, IMX, IVX\nc\nc-----------------------------------------------------------------------\nc\nc initializations \n info = 0 ! diagnostic argument\n p = n + 1 ! problem size\n CALL IVX ( n, wopt, ZERO )\n wrf = 0.0\nc\nc pointers for integer work space : iwork\nc ---------------------------------------\n piwo = 1\nc piwo : pointer for workspaces of TESTSDP, OPMV, QP\nc\nc Total size of iwork array = 7*n + 2*nin + neq + 7 \nc\nc pointers for double precision work space : dwork\nc ------------------------------------------------- \nc pdwo = 1\nc pdwo : pointer for workspaces of TESTSDP, OPMV, QP\nc n*( 2*n + neq + nin + 12 ) + 2*neq + 4*nin + 7 \nc pdwo + n*( 2*n + neq + nin + 12 ) + 2*neq + 4*nin + 7 \n pdcov = 1\nc pdcov : pointer for temporary cov. matrix (n+1)*(n+1)\n pdrho = pdcov + ( p*p )\nc pdrho : pointer for temporary rho. verctor (p)\n pdc = pdrho + ( p )\nc pdc : pointer for constraint matrix p*(2*n + nin + 2) \n pdb = pdc + ( p*(2*n + nin + 2) )\nc pdb : pointer for constraint vector (2*n + nin + 2)\n pdcinf= pdb + ( 2*n + nin + 2 )\nc pdcinf: pointer for lower bounds (p)\n pdcsup= pdcinf + ( p )\nc pdcsup: pointer for upper bounds (p)\n pdlagr= pdcsup + ( p )\nc pdlagr : pointer for Lagrange multipliers (p + 2 + 2*n + nin)\n pdx = pdlagr + ( p + 2 + 2*n + nin )\nc pdx : pointer for quadratic optimal points ( p )\n pdwo = pdx + p\nc needs \nc Testsdp needs n*(2*n+7)\nc Quapro needs p*p + 6*p + 2*neq\nc OPMV needs 2*n*(neq+nin+n+9)+4*neq+6*nin+2*n+15\nc so 2*n*(neq+nin+n+9)+4*neq+6*nin+2*n+15\n\nc Total size of dwork array = n*(2*neq+2*nin+2*n+18)+4*neq+6*nin+2*n+15 + n*(3*n+15+nin) + 12 +3*nin\nc = n*( 6*n + 2*neq + 3*nin + 35 ) + 4*neq + 9*nin + 27 \nc\nc-----------------------------------------------------------------------\nc\nc case cinfrfr = 100%\n IF ((cinfrfr .GT. 1-EPS).AND.(csuprfr .GT. 1-EPS)) THEN\n wrf = 1.0\n RETURN\n ENDIF\n wrf = cinfrfr\n coef = 1.0/(1.0 - cinfrfr)\nc\nc covariance matrix SDP test\n CALL testsdp (n, cov, iwork(piwo), dwork(pdwo), info)\n IF (info .NE. 0) THEN\n info = -108\n RETURN\n ENDIF\nc\nc general linear constraints\n ncst = neq + nin\n neqtot = neq + 1\n ntot = ncst + 1\n DO i = 1,n\n dwork(pdc + i - 1) = 1.0\n ENDDO\n dwork(pdb) = coef*1.0\nc case ncst = 0 (neq=0, nin=0)\n IF (ncst .NE. 0) THEN\n DO i = 1,n\n DO j = 1,ncst\n dwork(pdc + n + n*(j-1) + i - 1) = ccst(i,j)\n ENDDO\n ENDDO \n DO j = 1,ncst\n dwork(pdb + j) = coef*bcst(j)\n ENDDO\n ENDIF\nc\nc tests constraints compatibility\nc mu = -1.E+8\n DO i = 1,n\n dwork(pdcinf + i - 1) = coef*cinf(i)\n dwork(pdcsup + i - 1) = coef*csup(i)\n ENDDO\nc\nc test if max. returns < rfr\n CALL EVMAX ( n, rho, rhomax )\n IF (rhomax .LT. rfr) THEN\n CALL IVX ( n, wopt, ZERO )\n wrf = 1.0\n info = 0\n IF (wrf .GT. (csuprfr+1.E-8)) THEN\n info = -113\n ENDIF\n RETURN\n ENDIF \nc\nc test constraints\n mu = rfr + 1.E-10\n CALL opmv ( n, cov, rho, mu,\n & neqtot, nin, dwork(pdc), dwork(pdb),\n & dwork(pdcinf), dwork(pdcsup),\n & iwork(piwo), dwork(pdwo), wopt, info )\n IF (info .LT. 0) THEN\n info = -100\n RETURN\n ENDIF\nc\nc construction of the quadratic part\nc Q = | cov 0 | \nc | 0 ... 0 |\n CALL IMX ( p, p, dwork(pdcov), ZERO )\n DO i = 1,n\n iwork(piwo + i - 1) = i\n ENDDO\n CALL YMCPIR ( n, cov, p, iwork(piwo), dwork(pdcov), info )\n dwork(pdcov + p*p - 1) = 1.E-12\nc\nc initialize linear part to 0\n CALL IVX ( p, dwork(pdrho), ZERO )\nc\nc construction of the constraints matrix and vector\n IF ((neq+nin) .GT. 0) THEN\n DO i = 1, (neq+nin)\n dwork(pdwo + i - 1) = coef*bcst(i)\n ENDDO\n ENDIF\n CALL CTSR ( n, rho, rfr, neq, nin, ccst, dwork(pdwo),\n & dwork(pdcinf), dwork(pdcsup),\n & neqtot, nintot, dwork(pdc), dwork(pdb))\nc\nc initialize lower/upper bounds\n CALL IVX ( p, dwork(pdcinf), ZERO )\n CALL IVX ( p, dwork(pdcsup), INF )\n dwork(pdcsup + p - 1) = n*INF\nc\nc quadratic solver\n CALL qp ( p, dwork(pdcov), dwork(pdrho),\n & neqtot, nintot, dwork(pdc), dwork(pdb),\n & dwork(pdcinf), dwork(pdcsup),\n & iwork(piwo), dwork(pdwo),\n & dwork(pdlagr), dwork(pdx), info)\n IF (info .NE. 0) THEN\n CALL IVX ( n, wopt, ZERO )\n RETURN\n ENDIF\nc\nc re-scale weights\n t = dwork(pdx + p - 1)\nc\nc if |t| < EPS then (no solution) \nc return min. vol. solution \n IF (ABS(t) .LT. 100*EPS) THEN\nc info = -113\n DO i = 1,n\n wopt(i) = (1.0 - wrf)*wopt(i)\n ENDDO \n RETURN\n ENDIF\n sum = 0.0\n DO i = 1,n\n wopt(i) = dwork(pdx + i - 1)/t\n sum = sum + wopt(i)\n ENDDO\n DO i = 1,n\n wopt(i) = wopt(i)/sum\n ENDDO\nc\nc re-scale result \n DO i = 1,n\n wopt(i) = (1.0 - wrf)*wopt(i)\n ENDDO\n RETURN\n END\n", "meta": {"hexsha": "3786fbc241413a0860383c55fb1a2af68d53de50", "size": 8747, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/optim_portfolio/allocsrrfr.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/optim_portfolio/allocsrrfr.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/optim_portfolio/allocsrrfr.f", "max_forks_repo_name": "alpgodev/numx", "max_forks_repo_head_hexsha": "d2d3a0713020e1b83b65d3a661c3801ea256aff9", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.5134099617, "max_line_length": 104, "alphanum_fraction": 0.4564993712, "num_tokens": 2864, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425311777929, "lm_q2_score": 0.7122321903471563, "lm_q1q2_score": 0.6549990143171625}} {"text": "C PROGRAM No. 12: INFLUENCE COEFF. OF A RECTILINEAR SOURCE/DOUBLET PANEL\nC -----------------------------------------------------------------\nC THIS PROGRAM CALCULATES THE INFLUENCE OF A RECTILINEAR PANEL AT AN\nC ARBITRARY POINT. (PROGRAM BY LINDSEY BROWNE, 1988).\n DIMENSION X(5),Y(5),Z(5)\n\n PI=3.14159\n TWOPI=2.0*PI\n EPS=1.E-06\n PNDS=1.0\n\nC INPUT DOUBLET AND SOURCE STRENGTHS\n DUB=1.0/(4.0*PI)\n SIG=1.0/(4.0*PI)\n\n OPEN(2,FILE='INDIV',STATUS='UNKNOWN')\n\nC SQUARE/FLAT PANEL\nC INPUT COORDINATES\n X(1)=-.5\n X(2)=.5\n X(3)=.5\n X(4)=-.5\n Y(1)=-.5\n Y(2)=-.5\n Y(3)=.5\n Y(4)=.5\n\n DO 5 I=1,4\n Z(I)=0.0\n 5 CONTINUE\n\n X(5)=X(1)\n Y(5)=Y(1)\n Z(5)=Z(1)\n\nC MID-POINT AT (0,0,0)\n PXO=0.0\n PYO=0.0\n PZO=0.0\n\n 100 CONTINUE\n\n RJ31 = 0.0\n CJK1 = 0.0\n VXS = 0.0\n VYS = 0.0\n VZS = 0.0\n VXD = 0.0\n VYD = 0.0\n VZD = 0.0\n VX = 0.0\n VY = 0.0\n VZ = 0.0\n\nC INPUT POINT OF INTEREST\n WRITE(*,*) 'ENTER POINT OF INTEREST (X,Y,Z):'\n READ(*,*) PXI, PYI, PZI\n\n PX=PXI-PXO\n PY=PYI-PYO\n PZ=PZI-PZO\n RDIST=SQRT(PX*PX+PY*PY+PZ*PZ)\n\n PNLX=.25*(X(1)+X(2)+X(3)+X(4))\n PNLY=.25*(Y(1)+Y(2)+Y(3)+Y(4))\n PNLZ=.25*(Z(1)+Z(2)+Z(3)+Z(4))\n PNX=PX-PNLX\n PNY=PY-PNLY\n PNZ=PZ-PNLZ\n PNS=SQRT(PNX*PNX+PNY*PNY+PNZ*PNZ)\n\n D1X=X(3)-X(1)\n D1Y=Y(3)-Y(1)\n D1Z=Z(3)-Z(1)\n D2X=X(4)-X(2)\n D2Y=Y(4)-Y(2)\n D2Z=Z(4)-Z(2)\n\n CRX=D1Y*D2Z-D2Y*D1Z\n CRY=D2X*D1Z-D1X*D2Z\n CRZ=D1X*D2Y-D2X*D1Y\n CRSQ=SQRT(CRX*CRX+CRY*CRY+CRZ*CRZ)\n\n AREA=CRSQ/2.\n CNX=CRX/CRSQ\n CNY=CRY/CRSQ\n CNZ=CRZ/CRSQ\n PNN=CNX*PNX+CNY*PNY+CNZ*PNZ\n\n TCMX=(X(3)+X(4))/2. - PNLX\n TCMY=(Y(3)+Y(4))/2. - PNLY\n TCMZ=(Z(3)+Z(4))/2. - PNLZ\n TMS=SQRT(TCMX*TCMX+TCMY*TCMY+TCMZ*TCMZ)\n\n CMX=((X(3)+X(4))/2. - PNLX)/TMS\n CMY=((Y(3)+Y(4))/2. - PNLY)/TMS\n CMZ=((Z(3)+Z(4))/2. - PNLZ)/TMS\n CLX=CMY*CNZ-CNY*CMZ\n CLY=CNX*CMZ-CMX*CNZ\n CLZ=CMX*CNY-CNX*CMY\n\n DO 20 J=1,4\n K=J+1\n AX=PX-X(J)\n AY=PY-Y(J)\n AZ=PZ-Z(J)\n BX=PX-X(K)\n BY=PY-Y(K)\n BZ=PZ-Z(K)\n SX=X(K)-X(J)\n SY=Y(K)-Y(J)\n SZ=Z(K)-Z(J)\n\n A=SQRT(AX*AX + AY*AY + AZ*AZ)\n B=SQRT(BX*BX + BY*BY + BZ*BZ)\n S=SQRT(SX*SX + SY*SY + SZ*SZ)\n\nC SOURCE CONTRIBUTION\n SM=SX*CMX+SY*CMY+SZ*CMZ\n SL=SX*CLX+SY*CLY+SZ*CLZ\n AM=AX*CMX+AY*CMY+AZ*CMZ\n AL=AX*CLX+AY*CLY+AZ*CLZ\n BM=BX*CMX+BY*CMY+BZ*CMZ\n ALL=AM*SL-AL*SM\n\n IF((A+B-S).GT.0.0.AND.S.GT.0.0)THEN\n RJ3=ALOG((A+B+S)/(A+B-S))/S\n ELSE\n RJ3=0.0\n ENDIF\n\n PA=PNZ*PNZ*SL + ALL*AM\n PB=PA - ALL*SM\n RNUM=SM*PNZ*(B*PA - A*PB)\n DNOM=PA*PB + PNZ*PNZ*A*B*SM*SM\n\n IF(ABS(PNZ).LT.EPS)THEN\n DE=0.0\n ELSE\n IF(RNUM.NE.0)THEN\n DE=ATAN2(RNUM,DNOM)\n ELSE\n DE=0.0\n ENDIF\n ENDIF\n\n RJ31 = RJ31 - SIG*ALL*RJ3\n CJK1 = CJK1 - DUB*DE\n VXS=VXS+SIG*(RJ3*(SM*CLX-SL*CMX)+DE*CNX)\n VYS=VYS+SIG*(RJ3*(SM*CLY-SL*CMY)+DE*CNY)\n VZS=VZS+SIG*(RJ3*(SM*CLZ-SL*CMZ)+DE*CNZ)\n\nC DOUBLET CONTRIBUTION\n AVBX=AY*BZ - AZ*BY\n AVBY=AZ*BX - AX*BZ\n AVBZ=AX*BY - AY*BX\n ADB=AX*BX + AY*BY + AZ*BZ\n VMOD=(A+B)/(A*B*(A*B + ADB))\n\n VXD=VXD + DUB*VMOD*AVBX\n VYD=VYD + DUB*VMOD*AVBY\n VZD=VZD + DUB*VMOD*AVBZ\n 20 CONTINUE\n\nC LIMITING CASES\n DTT=TWOPI\n IF(RDIST.GT.0.0) PNDS=PNZ**2/RDIST\n\n IF(PNDS.LT.EPS.AND.RDIST.GT.EPS)THEN\n DTT=PNZ*AREA/SQRT(RDIST)/RDIST\n ENDIF\n\n IF(ABS(DTT).LT.ABS(CJK1))CJK1=DTT\n IF(RDIST.LT.EPS*EPS)CJK1=-TWOPI\n\nC TOTAL\n CJK = CJK1\n BJK = RJ31 - PNZ*CJK1\n VX=VXD+VXS\n VY=VYD+VYS\n VZ=VZD+VZS\n\n TVS=SQRT(VXS*VXS+VYS*VYS+VZS*VZS)\n TVD=SQRT(VXD*VXD+VYD*VYD+VZD*VZD)\n TV=SQRT(VX*VX+VY*VY+VZ*VZ)\n\n WRITE(*,*)'AREA OF PANEL=',AREA\n WRITE(*,*)'SOURCE (POTENTIAL)=',BJK\n WRITE(*,*)'SOURCE (VELOCITY):'\n WRITE(*,*)'VXS=',VXS\n WRITE(*,*)'VYS=',VYS\n WRITE(*,*)'VZS=',VZS\n WRITE(*,*)'TVS=',TVS\n WRITE(*,*)'DOUBLET (POTENTIAL):', CJK\n WRITE(*,*)'DOUBLET (VELOCITY):'\n WRITE(*,*)'VXD=',VXD\n WRITE(*,*)'VYD=',VYD\n WRITE(*,*)'VZD=',VZD\n WRITE(*,*)'TVD=',TVD\n WRITE(*,*)'TOTAL VELOCITY:'\n WRITE(*,*)'VX=',VX\n WRITE(*,*)'VY=',VY\n WRITE(*,*)'VZ=',VZ\n WRITE(*,*)'TV=',TV\n\n WRITE(*,*)'DO YOU WANT ANOTHER TRY? 1:YES, 2:NO'\n READ(*,*) NTRY\n IF(NTRY.EQ.1)GO TO 100\n\n STOP\n END\n", "meta": {"hexsha": "85f14f0e3f9f7a914e922fd7014842f932d9ce09", "size": 4868, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/f77/DUB3DC.f", "max_stars_repo_name": "Budhyant/KatzPlotkinPy", "max_stars_repo_head_hexsha": "60f96e17dd1c4fa53b0ae5e878d455151007c334", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2020-07-21T10:19:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-09T12:54:25.000Z", "max_issues_repo_path": "tests/f77/DUB3DC.f", "max_issues_repo_name": "AlwinW/KatzPlotkinPy", "max_issues_repo_head_hexsha": "60f96e17dd1c4fa53b0ae5e878d455151007c334", "max_issues_repo_licenses": ["MIT"], "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/f77/DUB3DC.f", "max_forks_repo_name": "AlwinW/KatzPlotkinPy", "max_forks_repo_head_hexsha": "60f96e17dd1c4fa53b0ae5e878d455151007c334", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-07-23T22:18:24.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-25T11:33:45.000Z", "avg_line_length": 22.8544600939, "max_line_length": 76, "alphanum_fraction": 0.4599424815, "num_tokens": 2266, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425311777929, "lm_q2_score": 0.712232184238947, "lm_q1q2_score": 0.6549990086997933}} {"text": "program main\n use nrtype\n use distributions\n\n implicit none\n integer :: i, ac, nbr_samples ! i = counter, ac = autocorrelation, number of samples.\n real(dp) :: accept ! accept = acceptance criterion.\n real(dp) :: direction, distance\n real(dp) :: current_sample(2) ! current sample, could or could not be rejected.\n real(dp) :: r(2), x(2), y(2) ! values of r, x and y.\n\n real(dp) :: ZBQLUAB, ZBQLEXP, ZBQLU01\n external ZBQLINI, ZBQLUAB, ZBQLEXP, ZBQLU01\n\n call ZBQLINI(0)\n\n current_sample = 0.!1d-8\n\n i = 0\n ac = 5\n nbr_samples = 1e6\n open(unit = 1, file = 'data.dat')\n\n collect_samples: do while (i < ac * nbr_samples)\n ! Direction and distance.\n direction = ZBQLUAB(0.,tau)\n distance = -DLOG(ZBQLU01(0.0D0))*2.!ZBQLEXP(2.)\n\n ! Current point.\n x(1) = current_sample(1)\n y(1) = current_sample(2)\n\n ! Next point.\n x(2) = x(1) + distance*cos(direction)\n y(2) = y(1) + distance*sin(direction)\n\n ! Check whether it fits the distribution.\n ! Min( f(X_2)/f(X_1), 1 )\n r = sqrt(x**2. + y**2.)\n accept = min( radial_sine_dist(r(2)) / radial_sine_dist(r(1)), 1.)\n acceptance: if (accept > ZBQLU01(0.)) then\n current_sample(1) = x(2)\n current_sample(2) = y(2)\n i = i + 1\n take_sample: if (mod(i, ac) == 0) then\n write(1,*) current_sample\n end if take_sample\n end if acceptance\n end do collect_samples\n close (1, status='keep')\n\n call system( \"gnuplot plot_met_hast.plt\" )\n !call system( \"\" )\n\nend program main\n", "meta": {"hexsha": "49293c85ded2a0edbaf03610b009a400331f3dc7", "size": 1523, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "prob_stats/not_generalised/main_met_hast.f08", "max_stars_repo_name": "dcelisgarza/applied_math", "max_stars_repo_head_hexsha": "a8a6e49ce225392bafffb02b51c22299ffb9d20e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2015-09-30T19:22:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T23:33:04.000Z", "max_issues_repo_path": "prob_stats/not_generalised/main_met_hast.f08", "max_issues_repo_name": "dcelisgarza/applied_math", "max_issues_repo_head_hexsha": "a8a6e49ce225392bafffb02b51c22299ffb9d20e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "prob_stats/not_generalised/main_met_hast.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": 27.1964285714, "max_line_length": 90, "alphanum_fraction": 0.6119500985, "num_tokens": 532, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.839733983715524, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6549865411056414}} {"text": " subroutine cwrpjt(noutpt)\nc\nc This subroutine calculates and writes tables of the higher-order\nc electrostatic term functions J(x) and J'(x). These functions may\nc be computed from two different approximate formulations. The\nc first is one given by Pitzer (1975, eq. 47). The second is given\nc by Harvie (1981). Almost all modern application of the Pitzer\nc equations for aqueous electrolyte thermodynamics uses the more\nc recent Harvie formulation. These formulations are all\nc approximate in nature.\nc\nc It is important to note that the tabulation in Table II of\nc Pitzer (1975) is not for the formulation represented by\nc eq. 47. Therefore, the results given here for the eq. 47\nc approximation will not precisely match the results given in\nc that table. Pitzer (1975) does not provide such a table for\nc the eq. 47 formulation.\nc\nc References\nc\nc Harvie, C. E. 1981. Theoretical Investigations in Geochemistry\nc and Atom Surface Scattering. Ph.D. dissertation, University\nc of California, San Diego (Available as #8203026 from\nc University Microfilms International, Ann Arbor, Michigan).\nc\nc Pitzer, K.S. 1975. Thermodynamics of electrolytes. V. Effects\nc of higher-order electrostatic terms. Journal of Solution\nc Chemistry, v. 4, p. 249-265.\nc\nc This subroutine is called by:\nc\nc EQ6/eq6.f\nc EQ3NR/eq3nr.f\nc\nc-----------------------------------------------------------------------\nc\nc Principal input:\nc\nc noutpt = unit number of the output file\nc\nc Principal output:\nc\nc None returned\nc\nc-----------------------------------------------------------------------\nc\n implicit none\nc\nc-----------------------------------------------------------------------\nc\nc Calling sequence variable declarations.\nc\n integer noutpt\nc\nc-----------------------------------------------------------------------\nc\nc Local variable declarations.\nc\n integer ktable,n\nc\n logical qpit75\nc\n real(8) dhj0,d2hj0,hj0,hj1,hj2,x\nc\nc-----------------------------------------------------------------------\nc\n write (noutpt,1000)\n 1000 format(/1x,\"Tables of J(x) and J'(x) (used with Pitzer's\",\n $ ' equations)')\nc\nc Tables using the Pitzer (1975) table format.\nc\n write (noutpt,1010)\n 1010 format(//3x,'Tables in the format of Pitzer (1975, Table II)',\n $ /3x,'(Note: that table was for a different approximation than',\n $ /3x,'than Pitzer, 1975, eq. 47, so results for eq. 47 will',\n $ /3x,'not precisely match those in Table II)')\nc\n ktable = 1\n qpit75 = .true.\n 100 continue\nc\n if (qpit75) then\n write (noutpt,1020)\n 1020 format(//5x,'Pitzer (1975, eq. 47) formulation')\n else\n write (noutpt,1030)\n 1030 format(//5x,'Harvie (1981, Appendix B) formulation')\n endif\nc\n write (noutpt,1040)\n 1040 format(/7x,\"x J(x) J'(x)\",/)\nc\n x = 0.\n do n = 1,10\n x = x + 0.01\n if (.not.qpit75) then\n call ghj0(dhj0,d2hj0,hj0,hj1,hj2,x)\n else\n call gpj0(dhj0,d2hj0,hj0,x)\n endif\n write (noutpt,1050) x,hj0,dhj0\n 1050 format(1x,f9.3,3x,f13.8,3x,f7.4)\n enddo\nc\nc x should now be 0.1\nc\n do n = 1,5\n x = x + 0.02\n if (.not.qpit75) then\n call ghj0(dhj0,d2hj0,hj0,hj1,hj2,x)\n else\n call gpj0(dhj0,d2hj0,hj0,x)\n endif\n write (noutpt,1050) x,hj0,dhj0\n enddo\nc\nc x should now be 0.2\nc\n do n = 1,10\n x = x + 0.04\n if (.not.qpit75) then\n call ghj0(dhj0,d2hj0,hj0,hj1,hj2,x)\n else\n call gpj0(dhj0,d2hj0,hj0,x)\n endif\n write (noutpt,1050) x,hj0,dhj0\n enddo\nc\nc x should now be 0.6\nc\n do n = 1,7\n x = x + 0.2\n if (.not.qpit75) then\n call ghj0(dhj0,d2hj0,hj0,hj1,hj2,x)\n else\n call gpj0(dhj0,d2hj0,hj0,x)\n endif\n write (noutpt,1050) x,hj0,dhj0\n enddo\nc\nc x should now be 2.0\nc\n do n = 1,8\n x = x + 1.0\n if (.not.qpit75) then\n call ghj0(dhj0,d2hj0,hj0,hj1,hj2,x)\n else\n call gpj0(dhj0,d2hj0,hj0,x)\n endif\n write (noutpt,1050) x,hj0,dhj0\n enddo\nc\nc x should now be 10.0\nc\n x = x + 2.0\n if (.not.qpit75) then\n call ghj0(dhj0,d2hj0,hj0,hj1,hj2,x)\n else\n call gpj0(dhj0,d2hj0,hj0,x)\n endif\n write (noutpt,1050) x,hj0,dhj0\nc\nc x should now be 12.0\nc\n do n = 1,7\n x = x + 4.0\n if (.not.qpit75) then\n call ghj0(dhj0,d2hj0,hj0,hj1,hj2,x)\n else\n call gpj0(dhj0,d2hj0,hj0,x)\n endif\n write (noutpt,1050) x,hj0,dhj0\n enddo\nc\nc x should now be 40.0\nc\n do n = 1,6\n x = x + 10.0\n if (.not.qpit75) then\n call ghj0(dhj0,d2hj0,hj0,hj1,hj2,x)\n else\n call gpj0(dhj0,d2hj0,hj0,x)\n endif\n write (noutpt,1050) x,hj0,dhj0\n enddo\nc\nc x should now be 100.0\nc\n x = x + 100.0\n if (.not.qpit75) then\n call ghj0(dhj0,d2hj0,hj0,hj1,hj2,x)\n else\n call gpj0(dhj0,d2hj0,hj0,x)\n endif\n write (noutpt,1050) x,hj0,dhj0\nc\nc x should now be 200.0\nc\n do n = 1,4\n x = x + 200.0\n if (.not.qpit75) then\n call ghj0(dhj0,d2hj0,hj0,hj1,hj2,x)\n else\n call gpj0(dhj0,d2hj0,hj0,x)\n endif\n write (noutpt,1050) x,hj0,dhj0\n enddo\nc\nc x should now be 1000.0\nc\n x = x + 1000.0\n if (.not.qpit75) then\n call ghj0(dhj0,d2hj0,hj0,hj1,hj2,x)\n else\n call gpj0(dhj0,d2hj0,hj0,x)\n endif\n write (noutpt,1050) x,hj0,dhj0\nc\nc x should now be 2000.0\nc\n do n = 1,4\n x = x + 2000.0\n if (.not.qpit75) then\n call ghj0(dhj0,d2hj0,hj0,hj1,hj2,x)\n else\n call gpj0(dhj0,d2hj0,hj0,x)\n endif\n write (noutpt,1050) x,hj0,dhj0\n enddo\nc\nc x should now be 10000.0\nc\n if (ktable .le. 1) then\n qpit75 = .false.\n ktable = ktable + 1\n go to 100\n endif\nc\nc* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nc\nc Tables using the Harvie (1981) table format (extended).\nc\n write (noutpt,1060)\n 1060 format(//3x,'Tables in the format of Harvie (1981, Appendix B)',\n $ /3x,'(extended format)')\nc\n ktable = 1\n qpit75 = .true.\n 120 continue\nc\n if (qpit75) then\n write (noutpt,1020)\n else\n write (noutpt,1030)\n endif\nc\n write (noutpt,1040)\nc\n x = 0.\n do n = 1,10\n x = x + 0.001\n if (.not.qpit75) then\n call ghj0(dhj0,d2hj0,hj0,hj1,hj2,x)\n else\n call gpj0(dhj0,d2hj0,hj0,x)\n endif\n write (noutpt,1070) x,hj0,dhj0\n 1070 format(1x,f9.3,3x,f12.7,4x,f10.7)\n enddo\nc\nc x should now be 0.01\nc\n do n = 1,9\n x = x + 0.01\n if (.not.qpit75) then\n call ghj0(dhj0,d2hj0,hj0,hj1,hj2,x)\n else\n call gpj0(dhj0,d2hj0,hj0,x)\n endif\n write (noutpt,1070) x,hj0,dhj0\n enddo\nc\nc x should now be 0.1\nc\n do n = 1,9\n x = x + 0.1\n if (.not.qpit75) then\n call ghj0(dhj0,d2hj0,hj0,hj1,hj2,x)\n else\n call gpj0(dhj0,d2hj0,hj0,x)\n endif\n write (noutpt,1070) x,hj0,dhj0\n enddo\nc\nc x should now be 1.0\nc\n do n = 1,9\n x = x + 1.0\n if (.not.qpit75) then\n call ghj0(dhj0,d2hj0,hj0,hj1,hj2,x)\n else\n call gpj0(dhj0,d2hj0,hj0,x)\n endif\n write (noutpt,1070) x,hj0,dhj0\n enddo\nc\nc x should now be 10.0\nc\n do n = 1,9\n x = x + 10.0\n if (.not.qpit75) then\n call ghj0(dhj0,d2hj0,hj0,hj1,hj2,x)\n else\n call gpj0(dhj0,d2hj0,hj0,x)\n endif\n write (noutpt,1070) x,hj0,dhj0\n enddo\nc\nc x should now be 100.0\nc\n do n = 1,9\n x = x + 100.0\n if (.not.qpit75) then\n call ghj0(dhj0,d2hj0,hj0,hj1,hj2,x)\n else\n call gpj0(dhj0,d2hj0,hj0,x)\n endif\n write (noutpt,1070) x,hj0,dhj0\n enddo\nc\nc x should now be 1000.0\nc\n do n = 1,9\n x = x + 1000.0\n if (.not.qpit75) then\n call ghj0(dhj0,d2hj0,hj0,hj1,hj2,x)\n else\n call gpj0(dhj0,d2hj0,hj0,x)\n endif\n write (noutpt,1070) x,hj0,dhj0\n enddo\nc\nc x should now be 10000.0\nc\n if (ktable .le. 1) then\n qpit75 = .false.\n ktable = ktable + 1\n go to 120\n endif\nc\nc* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nc\n write (noutpt,2000)\n 2000 format(/' - - - - - - - - - - - - - - - - - - - - - - - - ',\n $ '- - - - - - ',/)\n end\n", "meta": {"hexsha": "10d5e40c4e197c12968fac5f00299bb8d0ab1f9a", "size": 8837, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/eqlibg/src/cwrpjt.f", "max_stars_repo_name": "39alpha/eq3_6", "max_stars_repo_head_hexsha": "4ff7eec3d34634f1470ae5f67d8e294694216b6e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/eqlibg/src/cwrpjt.f", "max_issues_repo_name": "39alpha/eq3_6", "max_issues_repo_head_hexsha": "4ff7eec3d34634f1470ae5f67d8e294694216b6e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-11-30T15:48:52.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-02T18:16:22.000Z", "max_forks_repo_path": "src/eqlibg/src/cwrpjt.f", "max_forks_repo_name": "39alpha/eq3_6", "max_forks_repo_head_hexsha": "4ff7eec3d34634f1470ae5f67d8e294694216b6e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.6843575419, "max_line_length": 72, "alphanum_fraction": 0.5189543963, "num_tokens": 3409, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339756938818, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6549865391433825}} {"text": "subroutine SHAdmitCorr(G, T, lmax, admit, corr, admit_error)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n!\tThis subroutine will compute the admittance and correlation between the two input\n!\tspherical harmonic coefficients. The optional \"error\" on the admittance estimates \n!\tassumes that the two fields are perfectly correlated, which may not necessarily true\n!\tfor certain models (such as Forsyth's loading model). \n!\t\n!\tAssuming that the two input fields are related by \n!\n!\tG = Z T + N\n!\n!\twhere N is noise, the admittance is calcalated as \n!\n!\t\tZ = < G T > / < T T >,\n!\n!\tthe correlation is \n!\n!\t\tcorrelation = < G T > / sqrt(< G G >) / sqrt(< T T >).\n!\n!\tAssuming that the two fields are perfectly correlated, and that the lack of coherence is\n!\ta result of noise, the uncertainty on the admittance can be calculaed from\n!\n!\t\tsigma^2 = ( < G G > / < T T > ) ( 1 - gamma^2) / (2 l).\n!\n!\t< > signifies an average of over all m. Since only ratios \n!\tare being used, < > is implemented only as sums over all m (i.e., by the cross \n!\tspectra of the fields). Note that the correlation can possess values between -1 and 1, \n!\tin contrast to the \"coherence\" (or coherence-squared; the terminology is ambiguous) \n!\twhich only possesses values between 0 and 1.\n!\n!\tNote that in order for the magnitude of the admittance to be correct, the \n!\tinput coefficients must be multiplied by all constants. For instance, in the \n!\tcase of gravity-topography admittances, the potential coefficients must first be \n!\tmultiplied by GM (l+1) (R/r)**(l+2) where R is the refernce radius of the coefficients,\n!\tand r is the radius at which the field is evaluated.\n!\n!\tCalling Parameters\n!\t\tIN\n!\t\t\tG\t\tFirst input spherical harmonic coefficients.\n!\t\t\tT\t\tSecond input spherical harmonic coefficients.\n!\t\t\tlmax\t\tMaximum spherical harmonic degree of the input fields.\n!\t\tOUT\n!\t\t\tadmit\t\tG/T admittance spectra (length lmax+1).\n!\t\t\tcorr\t\tG/T correlation spectra (length lmax+1).\n!\t\tOPTIONAL\n!\t\t\tadmit_error\tG/T addittance error spectra (length lmax+1)\n!\t\t\t\t\tassuming that the two fields perfectly correlated in \n!\t\t\t\t\tthe abscence of noise.\n!\n!\tDependencies: SHPowerSpectrum, SHCrossPowerSpectrum\n!\n!\tWritten by Mark Wieczorek (June 2004)\n!\n!\tCopyright (c) 2005-2006, Mark A. Wieczorek\n!\tAll rights reserved.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\tuse SHTOOLS, only: SHPowerSpectrum, SHCrossPowerSpectrum\n\n\timplicit none\n\t\n\treal*8, intent(in) ::\tG(:,:,:), T(:,:,:)\n\tinteger, intent(in) ::\tlmax\n\treal*8, intent(out) ::\tadmit(:), corr(:)\n\treal*8, intent(out), optional ::\tadmit_error(:)\n\treal*8 ::\tgt(lmax+1), gg(lmax+1), tt(lmax+1)\n\tinteger ::\tl, l1\n\t\n\tif (size(G(:,1,1)) < 2 .or. size(G(1,:,1)) < lmax+1 .or. size(G(1,1,:)) < lmax+1) then\n\t\tprint*, \"Error --- SHAdmitCorr\"\n\t\tprint*, \"G must be dimensioned as (2, LMAX+1, LMAX+1) where LMAX is \", lmax\n\t\tprint*, \"Input dimension is \", size(G(:,1,1)), size(G(1,:,1)), size(G(1,1,:))\n\t\tstop\n\telseif (size(T(:,1,1)) < 2 .or. size(T(1,:,1)) < lmax+1 .or. size(T(1,1,:)) < lmax+1) then\n\t\tprint*, \"Error --- SHAdmitCorr\"\n\t\tprint*, \"T must be dimensioned as (2, LMAX+1, LMAX+1) where LMAX is \", lmax\n\t\tprint*, \"Input dimension is \", size(T(:,1,1)), size(T(1,:,1)), size(T(1,1,:))\n\t\tstop\n\telseif (size(admit) < lmax+1) then\n\t\tprint*, \"Error --- SHAdmitCorr\"\n\t\tprint*, \"ADMIT must be dimensioned as (LMAX+1) where LMAX is \", lmax\n\t\tprint*, \"Input dimension is \", size(admit)\n\t\tstop\n\telseif (size(corr) < lmax+1) then\n\t\tprint*, \"Error --- SHAdmitCorr\"\n\t\tprint*, \"CORR must be dimensioned as (LMAX+1) where LMAX is \", lmax\n\t\tprint*, \"Input dimension is \", size(corr)\n\t\tstop\n\tendif\n\t\n\tif (present(admit_error)) then\n\t\tif (size(admit_error) < lmax+1) then\n\t\t\tprint*, \"Error --- SHAdmitCorr\"\n\t\t\tprint*, \"ADMIT_ERROR must be dimensioned as (LMAX+1) where LMAX is \", lmax\n\t\t\tprint*, \"Input dimension is \", size(admit_error)\n\t\t\tstop\n\t\tendif\n\tendif\n\t\n\tadmit = 0.0d0\n\tcorr = 0.0d0\n\n\tcall SHCrossPowerSpectrum(G, T, lmax, gt) ! < G T > \n\n\tcall SHPowerSpectrum(G, lmax, gg) ! < G G >\n\t\n\tcall SHPowerSpectrum(T, lmax, tt) ! < T T >\n\t\n\tadmit(1:lmax+1) = gt(1:lmax+1) / tt(1:lmax+1)\n\t\n\tcorr(1:lmax+1) = gt(1:lmax+1) / sqrt( tt(1:lmax+1) * gg(1:lmax+1) )\n\t\n\tif (present(admit_error)) then\n\t\tadmit_error = 0.0d0\n\t\tdo l = 1, lmax\n\t\t\tl1 = l+1\n\t\t\tadmit_error(l1) = gg(l1)*(1.0d0 - corr(l1)**2) / ( tt(l1) * dble(2*l) )\n\t\tenddo\n\t\tadmit_error(1:lmax+1) = sqrt(admit_error(1:lmax+1))\n\tendif\n\t\nend subroutine SHAdmitCorr\n\n", "meta": {"hexsha": "2385613ac9c5b1a68c36c5c90355eb986c07a4fb", "size": 4532, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "spherical_splines/SHTOOLS/src/SHAdmitCorr.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/SHAdmitCorr.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/SHAdmitCorr.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": 36.256, "max_line_length": 98, "alphanum_fraction": 0.6376875552, "num_tokens": 1484, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722394, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.6549865371811233}} {"text": "!**\n!* Module that provides a function to interpolate points on a given grid\n!**\nmodule interpolation\n use kinds, only: dp\n implicit none\n private\n public :: interpolate_ordered\n\n contains\n ! **\n ! * Interpolates the exogenous points on the given grid. Note: both input arrays of points are expected to be ordered.\n ! *\n ! * Input:\n ! * - grid: array of interpolation points, i.e. the grid on which the points are interpolated\n ! * - points: array of points that are interpolated on the given grid\n ! *\n ! * Return value: a vector mapping each given exogenous point to the corresponding RIGHT interpolating point on the grid\n ! **\n function interpolate_ordered(grid,points) result(map)\n real(dp), dimension(:), intent(in) :: grid,points\n integer, dimension(size(points)) :: map\n\n integer :: i,j,i_min,i_max,len_grid,len_points\n len_grid = size(grid)\n len_points = size(points)\n\n do i=1,len_points\n if (points(i) > grid(1)) exit\n end do\n i_min = i\n do i=len_points,1,-1\n if (points(i) < grid(len_grid)) exit\n end do\n i_max = i\n\n map(1:i_min-1)=1\n map(i_max+1:len_points)=len_grid\n\n j=2\n do i=i_min,i_max\n do while(points(i) > grid(j))\n j = j + 1\n end do\n map(i)=j\n end do\n end function\nend module interpolation\n\n\n\n\n", "meta": {"hexsha": "306571275337bd462d71f612268d4ee083654c03", "size": 1635, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "interpolation.f90", "max_stars_repo_name": "carlozanella/ncegm", "max_stars_repo_head_hexsha": "29c6846946bcdc8d527a4ff7a0bfb3ddee0c8bf8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-03-14T23:31:35.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-14T23:31:35.000Z", "max_issues_repo_path": "interpolation.f90", "max_issues_repo_name": "carlozanella/ncegm", "max_issues_repo_head_hexsha": "29c6846946bcdc8d527a4ff7a0bfb3ddee0c8bf8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "interpolation.f90", "max_forks_repo_name": "carlozanella/ncegm", "max_forks_repo_head_hexsha": "29c6846946bcdc8d527a4ff7a0bfb3ddee0c8bf8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.8490566038, "max_line_length": 128, "alphanum_fraction": 0.525382263, "num_tokens": 364, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339837155239, "lm_q2_score": 0.7799928900257126, "lm_q1q2_score": 0.6549865368110761}} {"text": "! Factorial, calculated in a 1D ring topology.\n!\n! 1) Rank 0 reads in a number, which must be 1.\n! 2) Each rank multiplies this number by my_rank + 1 and sends it to the next\n! neighbor.\n! 3) The last rank does the same and sends this number to rank 0, where it is\n! received and printed out.\n!\n! Compile and run:\n!\n! $ mpifort -O0 -Wall -Wextra -Wpedantic -fcheck=all -fbacktrace ring_factorial.f90\n! $ mpirun -np 6 --oversubscribe ./a.out\n! 720\nprogram ring_factorial\n use mpi_f08\n implicit none\n type(MPI_Comm) :: comm\n type(MPI_Status) :: status\n integer :: my_rank, n_ranks, prev, next, f\n\n call MPI_Init()\n comm = MPI_COMM_WORLD\n call MPI_Comm_rank(comm, my_rank)\n call MPI_Comm_size(comm, n_ranks)\n\n ! Create a 1D ring topology.\n prev = get_rank(my_rank - 1, n_ranks)\n next = get_rank(my_rank + 1, n_ranks)\n\n ! Read in the number `f` at rank 0. Other ranks are waiting to receive.\n if (my_rank == 0) then\n read *, f\n else\n call MPI_Recv(f, 1, MPI_INTEGER, prev, 0, comm, status)\n end if\n\n ! All ranks multiply the number.\n f = f * (my_rank + 1)\n\n ! Send the result to the next rank in the ring.\n call MPI_Send(f, 1, MPI_INTEGER, next, 0, comm)\n\n ! Now rank 0 receives the result and prints it out.\n if (my_rank == 0) then\n call MPI_Recv(f, 1, MPI_INTEGER, prev, 0, comm, status)\n print \"(i0)\", f\n end if\n\n ! Another, shorter solution is possible:\n !if (my_rank == 0) then\n ! read *, f\n ! f = f * (my_rank + 1)\n ! call MPI_Send(f, 1, MPI_INTEGER, next, 0, comm)\n ! call MPI_Recv(f, 1, MPI_INTEGER, prev, 0, comm, status)\n ! print \"(i0)\", f\n !else\n ! call MPI_Recv(f, 1, MPI_INTEGER, prev, 0, comm, status)\n ! f = f * (my_rank + 1)\n ! call MPI_Send(f, 1, MPI_INTEGER, next, 0, comm)\n !end if\n\n call MPI_Finalize()\n\ncontains\n\n ! Use the modulo division to find the corresponding rank in a 1D ring\n ! topology of `n` processes.\n integer function get_rank(rnk, n)\n integer, intent(in) :: rnk, n\n get_rank = modulo(rnk, n)\n return\n end function get_rank\n\nend program ring_factorial\n", "meta": {"hexsha": "876af8d4c0777cd191db6b518d6d2f83b13d6bf1", "size": 2191, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Lecture_11/ring_factorial/ring_factorial.f90", "max_stars_repo_name": "avsukhorukov/TdP2021-22", "max_stars_repo_head_hexsha": "dd3adf2ece93bcd685912614b848c5dddbcdf6de", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Lecture_11/ring_factorial/ring_factorial.f90", "max_issues_repo_name": "avsukhorukov/TdP2021-22", "max_issues_repo_head_hexsha": "dd3adf2ece93bcd685912614b848c5dddbcdf6de", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Lecture_11/ring_factorial/ring_factorial.f90", "max_forks_repo_name": "avsukhorukov/TdP2021-22", "max_forks_repo_head_hexsha": "dd3adf2ece93bcd685912614b848c5dddbcdf6de", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.2133333333, "max_line_length": 85, "alphanum_fraction": 0.6234596075, "num_tokens": 697, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7799928900257126, "lm_q2_score": 0.8397339716830605, "lm_q1q2_score": 0.6549865274258403}} {"text": "submodule(euler_interface_m) euler_prob_0009_m\n implicit none\n\ncontains\n\n module character(len=20) function euler0009()\n write (euler0009, \"(i20)\") answer(1000)\n end function euler0009\n\n integer function answer(n)\n integer, intent(in) :: n\n integer :: i, j, k\n\n answer = 0\n outer: do i = 1, n\n inner: do j = i + 1, n\n k = n - i - j\n if (i**2 + j**2 == k**2) then\n answer = i*j*k\n return\n end if\n end do inner\n end do outer\n end function answer\n\nend submodule euler_prob_0009_m\n", "meta": {"hexsha": "56da0f3ddb183ddb9ef60b09d8db52ee93ee6d58", "size": 639, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/euler/prob_0009_m.f90", "max_stars_repo_name": "han190/PE-Fortran", "max_stars_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-02-09T07:07:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-31T07:45:48.000Z", "max_issues_repo_path": "src/euler/prob_0009_m.f90", "max_issues_repo_name": "han190/PE-Fortran", "max_issues_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-14T00:48:58.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-14T00:48:58.000Z", "max_forks_repo_path": "src/euler/prob_0009_m.f90", "max_forks_repo_name": "han190/PE-Fortran", "max_forks_repo_head_hexsha": "da64e7c2e3ee10d1ae0f4b30a2ff243a406f8b55", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-04T21:29:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T21:29:45.000Z", "avg_line_length": 23.6666666667, "max_line_length": 49, "alphanum_fraction": 0.5086071987, "num_tokens": 174, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339596505965, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6549865266297339}} {"text": "! Demonstrate the ** exponentiation operator, which is elemental\r\nprogram main\r\nimplicit none\r\ninteger :: i\r\nprint*,1.2**2 ! 1.44000006\r\nprint*,[1.0,1.1,1.2,1.3]**2 ! 1.00000000 1.21000004 1.44000006 1.68999982\r\nprint*,2**[0,1,2,3] ! 1 2 4 8\r\nprint*,2**[(i,i=0,3)] ! 1 2 4 8\r\nend program main", "meta": {"hexsha": "e61f46486337292a6dc5818ef949880dc67fb097", "size": 306, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "power.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": "power.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": "power.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": 34.0, "max_line_length": 74, "alphanum_fraction": 0.6274509804, "num_tokens": 133, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789178257654, "lm_q2_score": 0.8080672158638528, "lm_q1q2_score": 0.6549214426438146}} {"text": "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!Module importantEqs saves the important variables/equations to be used by both the\n! program and the subroutine\nModule importantEqs\n\n!The functions are added into the module for use in the subroutines\nContains\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!Function to be solved, the equation for the valve for the tank with\n!\nFunction func(t, F1, tau)\nDouble Precision, intent (in):: t, F1\nDouble Precision:: func, F1spec, tau\n!tau = 2.00\n!F1spec is a function of time F1(t=0) = 5kg/s]\nIf (t>=10.0) then\nF1spec = 4.00\nelse\nF1spec = 5.00 - 0.10*t\nEnd if\n\n!Sets the value of the function\nfunc = 1/tau*(F1spec - F1)\nEnd Function\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!Function2 to be solved, the equation for the energy of the system for a tank with two\n! inlets with flow of F1 (kg/s) and F2 (kg/s) at temperatures of T1 (\u02daC) and T2 (\u02daC)\n! and one outlet flow (F1+F2) at temperature Temp (\u02daC) and an accumulation term M (kg)\nFunction func2(t, F1, Temp)\nDouble Precision, intent (in):: t, F1, Temp\nDouble Precision:: func2, M, F2, T1, T2\nM = 100.00\nT1 = 25.00\nT2 = 75.00\nF2 = 5.00\n!Sets the value of the function\nfunc2 = 1/M*(F1*T1 + F2*T2 - (F1+F2)*Temp)\nEnd Function\n\nEnd Module\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!Program Proj4 utilizes different subroutines to solve for the equation for the\n! temperature of the outlet stream of a tank and produces graphs of the results\nProgram Proj4_2\nUse importantEqs\n! t0 \t: the starting value of time (seconds)\n! tf \t: the final value of time (seconds)\n! Temp0 : the starting value of temperature (\u02daC)\n! steps : the number of steps to divide the interval\n! intX\t: array for x values from the Integration Method\n! intY\t: array for y values from the Integration Method\n! rkX\t: array for x values from the Runge-Kutta Method\n! rkY\t: array for y values from the Runge-Kutta Method\nDouble Precision:: t0 = 0.0, tf = 75.0, flow0 = 5.0, Temp0 = 50.0\nInteger, parameter::steps = 50\nDouble Precision:: intX2(0:steps), intY2(0:steps), intZ2(0:steps), rkX2(0:steps), rkY2(0:steps), rkZ2(0:steps)\nDouble Precision:: intX4(0:steps), intY4(0:steps), intZ4(0:steps), rkX4(0:steps), rkY4(0:steps), rkZ4(0:steps)\nDouble Precision:: intX6(0:steps), intY6(0:steps), intZ6(0:steps), rkX6(0:steps), rkY6(0:steps), rkZ6(0:steps)\nDouble Precision::tau2 = 2.00, tau4 = 4.00, tau6 = 6.00\nCharacter(len = 1)::name2 = '2', name4 = '4', name6 = '6'\n\n!Uses the variables from the module to solve func for both methods\nCall IntegrationMethod(t0, tf, flow0, Temp0, steps, intX2, intY2, intZ2, tau2, name2)\nCall RungeKuttaMethod(t0, tf, flow0, Temp0, steps, rkX2, rkY2, rkZ2, tau2, name2)\nCall Combined_Data(steps, intX2, intZ2, rkZ2, name2)\nCall Combined_Data(steps, intX2, intY2, rkY2, name2//'F')\n\n\n!Uses the variables from the module to solve func for both methods\nCall IntegrationMethod(t0, tf, flow0, Temp0, steps, intX4, intY4, intZ4, tau4, name4)\nCall RungeKuttaMethod(t0, tf, flow0, Temp0, steps, rkX4, rkY4, rkZ4, tau4, name4)\nCall Combined_Data(steps, intX4, intZ4, rkZ4, name4)\nCall Combined_Data(steps, intX4, intY4, rkY4, name4//'F')\n\n!Uses the variables from the module to solve func for both methods\nCall IntegrationMethod(t0, tf, flow0, Temp0, steps, intX6, intY6, intZ6, tau6, name6)\nCall RungeKuttaMethod(t0, tf, flow0, Temp0, steps, rkX6, rkY6, rkZ6, tau6, name6)\nCall Combined_Data(steps, intX6, intZ6, rkZ6, name6)\nCall Combined_Data(steps, intX6, intY6, rkY6, name6//'F')\n\nCall run_gnuplot('/Users/DanielK/Desktop/Fortran/IntRKMethod_Part2All.txt')\nCall run_gnuplot('/Users/DanielK/Desktop/Fortran/IntRKMethod_Part2AllF.txt')\n\n\nEnd Program\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!Subroutine IntegrationMethod utilizes the numerical integration method to calculate\n! the area under the curve for the given function in the module\nSubroutine IntegrationMethod(startX, finalX, startY, startZ, numSteps, xint, yint, zint, tauin, namein)\nUse importantEqs\nDouble Precision, intent(in):: startX, finalX, startY, startZ, tauin\nInteger, intent(in)::numSteps\nCharacter(len = 1), intent(in)::namein\nDouble Precision:: stepSize, k1, k2, k3, k4, F1calc\nDouble Precision, intent(out):: xint(0:numSteps), yint(0:numSteps), zint(0:numSteps)\nInteger::err\n\n!Calculates the steps size and sets the initial values based on the input data\nstepSize = (finalX - startX)/numSteps\nxint(0) = startX\nyint(0) = startY\nzint(0) = startZ\n\n!Do loop runs the interative calculation of the Integration Method\nDo i = 0, numSteps - 1\n\txint(i+1) = xint(i) + stepSize\n!\tPrint *, 'xint', xint(i), 'yint', yint(i)\n\tyint(i+1) = yint(i) + stepSize*func(xint(i), yint(i), tauin)\n!\tPrint*, '\t\tstepSize*func', stepSize*func(xint(i), yint(i))\n\tzint(i+1) = zint(i) + stepSize*func2(xint(i), yint(i), zint(i))\nEnd Do\n\nerr = 0\n\n!The write_xy_data subroutine writes the data in the arrays to the specified data file\nCall write_xy_data('/Users/DanielK/Desktop/Fortran/IntMethod_'//namein//'.dat', numSteps, xint, zint, err)\nCall write_xy_data('/Users/DanielK/Desktop/Fortran/IntMethod_'//namein//'F.dat', numSteps, xint, yint, err)\n\n!The write_xy_plot subroutine can write the script to produce a graph of the data\n!Call write_xy_plot('/Users/DanielK/Desktop/Fortran/IntMethod.txt', 'IntMethod.dat', err)\n\n!The run_gnuplot subroutine uses the given script to create a graph of the data\n!Call run_gnuplot('/Users/DanielK/Desktop/Fortran/IntMethod_2.txt')\n\nif(err /= 0) then\nPrint*, 'Fatal Error: Unable to plot IntMethod_'//namein//'.dat'\nEnd if\n\nEnd Subroutine\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!Subroutine utilizes RungeKuttaMethod utilizes the Runge-Kutta Method to calculate the\n! area under the curve for the given function in the module, more detail is given at:\n! https://math.stackexchange.com/questions/721076/help-with-using-the-runge-kutta-4th-order-method-on-a-system-of-2-first-order-od\nSubroutine RungeKuttaMethod(startX, finalX, startY, startZ, numSteps, xrk, yrk, zrk, tauin, namein)\nUse importantEqs\nDouble Precision, intent(in):: startX, finalX, startY, startZ, tauin\nInteger, intent(in)::numSteps\nCharacter(len = 1), intent(in)::namein\nDouble Precision:: stepSize, k1, k2, k3, k4, k1z, k2z, k3z, k4z\nDouble Precision, intent(out):: xrk(0:numSteps), yrk(0:numSteps), zrk(0:numSteps)\nInteger::err\n\n!Calculates the steps size and sets the initial values based on the input data\nstepSize = (finalX - startX)/numSteps\nxrk(0) = startX\nyrk(0) = startY\nzrk(0) = startZ\n\n!Do loop runs the interative calculation of the RK Method\nDo i = 0, numSteps - 1\n\txrk(i+1) = xrk(i) + stepSize\n!\tPrint *, 'xrk', xrk(i), 'yrk', yrk(i)\n\tk1 = stepSize*func(xrk(i), yrk(i), tauin)\n\tk2 = stepSize*func((xrk(i)+stepSize/2), (yrk(i)+k1/2), tauin)\n\tk3 = stepSize*func((xrk(i)+stepSize/2), (yrk(i)+k2/2), tauin)\n\tk4 = stepSize*func((xrk(i)+stepSize), (yrk(i)+k3), tauin)\n!\tPrint *, '\t\tk1', k1, '\tk2', k2, '\tk3', k3, '\tk4', k4\n\tyrk(i+1) = yrk(i) + (k1 + 2.00*k2 + 2.00*k3 + k4)/6.00\n!\tPrint*, '\t\t1/6(...)', (k1 + 2.00*k2 + 2.00*k3 + k4)/6.00\n\tk1z = stepSize*func2(xrk(i), yrk(i), zrk(i))\n\tk2z = stepSize*func2((xrk(i)+stepSize/2), (yrk(i)+k1/2), (zrk(i)+k1z/2))\n\tk3z = stepSize*func2((xrk(i)+stepSize/2), (yrk(i)+k2/2), (zrk(i)+k2z/2))\n\tk4z = stepSize*func2((xrk(i)+stepSize), (yrk(i)+k3), (zrk(i)+k3z))\n!\tPrint *, '\t\tk1', k1, '\tk2', k2, '\tk3', k3, '\tk4', k4\n zrk(i+1) = zrk(i) + (k1z + 2.00*k2z + 2.00*k3z + k4z)/6.00\n!\tPrint*, '\t\t1/6(...)', (k1 + 2.00*k2 + 2.00*k3 + k4)/6.00\n\nEnd Do\n\nerr = 0\n\n!The write_xy_data subroutine writes the data in the arrays to the specified data file\nCall write_xy_data('/Users/DanielK/Desktop/Fortran/RKMethod_'//namein//'.dat', numSteps, xrk, zrk, err)\nCall write_xy_data('/Users/DanielK/Desktop/Fortran/RKMethod_'//namein//'F.dat', numSteps, xrk, yrk, err)\n\n!The write_xy_plot subroutine can write the script to produce a graph of the data\n!Call write_xy_plot('/Users/DanielK/Desktop/Fortran/RKMethod.txt', 'RKMethod.dat', err)\n\n!The run_gnuplot subroutine uses the given script to create a graph of the data\n!Call run_gnuplot('/Users/DanielK/Desktop/Fortran/RKMethod_2.txt')\n\nif(err /= 0) then\n\tPrint*, '/Users/DanielK/Desktop/Fortran/RKMethod_'//namein//'.dat'\nEnd if\n\nEnd Subroutine\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!Subroutine IntegrationMethod utilizes the numerical integration method to calculate\n! the area under the curve for the given function in the module\nSubroutine Combined_Data(numSteps, xint, yint, yrk, namein)\nUse importantEqs\nInteger, intent(in)::numSteps\nCharacter(len = *), intent(in)::namein\nDouble Precision, intent(in):: xint(0:numSteps), yint(0:numSteps), yrk(0:numSteps)\nDouble Precision::allpts(0:2, 0:numSteps)\nInteger::err\n\n!Do loops inputs all the data from both solutions into a single array\nDo i = 0, numSteps\n\tallpts(i,0) = xint(i)\n\tallpts(i,1) = yint(i)\n\tallpts(i,2) = yrk(i)\n!\tPrint*, 'allpts(0,i)', allpts(0,i), 'allpts(1,i)', allpts(1,i), 'allpts(2,i)', allpts(2,i)\nEnd Do\n\n!The write_xyy_data subroutine writes the data in the arrays to the specified data file\n!Call write_xyy_data ( '/Users/DanielK/Desktop/Fortran/IntRKMethod_'//namein//'.dat', 0, 2, numSteps, allpts, err )\n\n!The write_xyy_plot subroutine can write the script to produce a graph of the data\n!Call write_xyy_plots ( '/Users/DanielK/Desktop/Fortran/IntRKMethod.txt', &\n!'/Users/DanielK/Desktop/Fortran/IntRKMethod.dat', numSteps, err )\n\n!The run_gnuplot subroutine uses the given script to create a graph of the data\nCall run_gnuplot('/Users/DanielK/Desktop/Fortran/IntRKMethod_'//namein//'.txt')\n\nif(err /= 0) then\n\tPrint*, 'Fatal Error: Unable to plot IntRKMethod_'//namein//'.dat'\nEnd if\n\nEnd Subroutine\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!The following subroutines are modified from those provided at the link below:\n! http://people.sc.fsu.edu/~jburkardt/f_src/gnufor/gnufor.html\nsubroutine write_xy_data ( data_filename, n, x, y, ierror )\n\n!*****************************************************************************80\n!\n!! WRITE_XY_DATA writes X(1:N), Y(1:N) data to a file.\n!Note: Editied to write X(0:N), Y(0:N)\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 23 February 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, character ( len = * ) DATA_FILENAME, the name of the data file.\n!\n! Input, integer ( kind = 4 ) N, the number of data items.\n!\n! Input, real ( kind = 8 ) X(N), Y(N), the X and Y data\n!\n! Output, integer ( kind = 4 ) IERROR, nonzero if an error occurred.\n!\n\nimplicit none\n\ninteger ( kind = 4 ) n\n\ncharacter ( len = * ) data_filename\ninteger ( kind = 4 ) file_unit\ninteger ( kind = 4 ) i\ninteger ( kind = 4 ) ierror \ninteger ( kind = 4 ) ios\nreal ( kind = 8 ) x(0:n)\nreal ( kind = 8 ) y(0:n)\n\nierror = 0\n\ncall get_unit ( file_unit )\n\nif ( file_unit == 0 ) then\nierror = 1\nwrite ( *, '(a)' ) ' '\nwrite ( *, '(a)' ) 'WRITE_XY_DATA - Fatal error!'\nwrite ( *, '(a)' ) ' Could not get a free FORTRAN unit.'\nreturn\nend if\n\nopen ( unit = file_unit, file = data_filename, status = 'replace', &\niostat = ios )\n\nif ( ios /= 0 ) then\nierror = 2\nwrite ( *, '(a)' ) ' '\nwrite ( *, '(a)' ) 'WRITE_XY_DATA - Fatal error!'\nwrite ( *, '(a)' ) ' Could not open the output file.'\nreturn\nend if\n\n!Edited to start at i=0\ndo i = 0, n\nwrite ( file_unit, * ) x(i), y(i)\nend do\n\nclose ( unit = file_unit )\n\nwrite ( *, '(a)' ) ' '\nwrite ( *, '(a)' ) 'WRITE_XY_DATA:'\nwrite ( *, '(a)' ) ' Wrote the GNUPLOT XY data file \"' // &\ntrim ( data_filename ) // '\"'\n\nreturn\nend\nsubroutine write_xy_plot ( command_filename, data_filename, ierror )\n\n!*****************************************************************************80\n!\n!! WRITE_XY_PLOT writes GNUPLOT commands to plot X(1:N), Y(1:N) data.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 23 June 2011\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, character ( len = * ) COMMAND_FILENAME, the name of the\n! command file.\n!\n! Input, character ( len = * ) DATA_FILENAME, the name of the data file.\n!\n! Output, integer ( kind = 4 ) IERROR, nonzero if an error occurred.\n!\nimplicit none\n\ncharacter ( len = * ) command_filename\ncharacter ( len = * ) data_filename\ninteger ( kind = 4 ) file_unit\ninteger ( kind = 4 ) i\ninteger ( kind = 4 ) ierror\ninteger ( kind = 4 ) ios\n!\n! Write the data file.\n!\nierror = 0\n\ncall get_unit ( file_unit )\n\nif ( file_unit == 0 ) then\nierror = 1\nwrite ( *, '(a)' ) ' '\nwrite ( *, '(a)' ) 'WRITE_XY_PLOT - Fatal error!'\nwrite ( *, '(a)' ) ' Could not get a free FORTRAN unit.'\nreturn\nend if\n\nopen ( unit = file_unit, file = command_filename, status = 'replace', &\niostat = ios )\n\nif ( ios /= 0 ) then\nierror = 2\nwrite ( *, '(a)' ) ' '\nwrite ( *, '(a)' ) 'WRITE_XY_PLOT - Fatal error!'\nwrite ( *, '(a)' ) ' Could not open the output file.'\nreturn\nend if\n\nwrite ( file_unit, '(a)' ) 'set title \"GNUFOR plot\"'\nwrite ( file_unit, '(a)' ) 'set xlabel \"x\"'\nwrite ( file_unit, '(a)' ) 'set ylabel \"y\"'\nwrite ( file_unit, '(a,i2,a)' ) 'plot \"' // trim ( data_filename ) // &\n'\" using 1:2 with lines'\nwrite ( file_unit, '(a)' ) 'pause -1'\nwrite ( file_unit, '(a)' ) 'q'\n\nclose ( unit = file_unit )\n\nwrite ( *, '(a)' ) ' '\nwrite ( *, '(a)' ) 'WRITE_XY_PLOT:'\nwrite ( *, '(a)' ) ' Wrote the GNUPLOT XY plot command file \"' // &\ntrim ( command_filename ) // '\"'\n\nreturn\nend\n\nsubroutine run_gnuplot ( command_filename )\n\n!*****************************************************************************80\n!\n!! RUN_GNUPLOT runs GNUPLOT with a given command file.\n!\n! Discussion:\n!\n! The GNUPLOT program must be available. To check whether\n! this is so, try typing\n!\n! which gnuplot\n!\n! If the response is\n!\n! gnuplot: command not found\n!\n! then you're going to have to make GNUPLOT available.\n!\n! You may need to set the environment variable GNUTERM:\n!\n! setenv GNUTERM x11\n!\n! so that GNUPLOT automatically displays to your X window terminal.\n!\n!\n! This routine expects that there is a text file containing the appropriate\n! commands to GNUPLOT to display your picture. There are a number of\n! routines in this package that will do this for simple plotting tasks.\n! Most of them require that you also set up a file of data to be plotted.\n!\n! Once this routine invokes GNUPLOT, a graphics window should open\n! up, and the FORTRAN program will pause. Hitting RETURN should advance\n! to the next picture, or terminate the window at the end, allowing the\n! FORTRAN routine to proceed.\n!\n!\n! You can look at the data and command files created by the routines.\n! Moreover, you can easily modify the command file to change the options\n! used in GNUPLOT, and then run GNUPLOT interactively, as in:\n!\n! gnuplot commands\n!\n! In particular, if you want a PostScript version of your graphics files,\n! insert the command \"set term postscript\" at the beginning of the command\n! file and run gnuplot as follows:\n!\n! gnuplot commands > mypicture.ps\n!\n! You will also have to hit RETURN once for each plot that is made.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 February 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, character ( len = * ) COMMAND_FILENAME, the name of the\n! command file.\n!\nimplicit none\n\ncharacter ( len = 255 ) command\ncharacter ( len = * ) command_filename\ninteger ( kind = 4 ) status\ninteger ( kind = 4 ) system\n\ncall timestamp ( )\nwrite ( *, '(a)' ) ' '\nwrite ( *, '(a)' ) 'GNUFOR:'\nwrite ( *, '(a)' ) ' GNUPLOT / FORTRAN90 command interface.'\n!\n! Issue a command to the system that will start GNUPLOT, using\n! the file we just wrote as input.\n!\n! The \"&\" will run GNUPLOT in the background, so the FORTRAN program\n! can continue execution independently, and the PERSIST switch tells\n! GNUPLOT that if there are multiple plots, they should each go in\n! a separate window.\n!\n! Thanks to Morag Am-Shallem for suggesting these improvements.\n! 17 October 2007\n!\nwrite ( command, * ) 'gnuplot ' // command_filename\n\nwrite ( *, '(a)' ) ' '\nwrite ( *, '(a)' ) 'GNUFOR:'\nwrite ( *, '(a)' ) ' Issuing the command:\"' // trim ( command ) // '\".'\nwrite ( *, '(a)' ) ' '\nwrite ( *, '(a)' ) ' Press RETURN to proceed.'\n\nstatus = system ( trim ( command ) )\n\nif ( status /= 0 ) then\nwrite ( *, '(a)' ) ' '\nwrite ( *, '(a)' ) 'GNUFOR - Fatal error!'\nwrite ( *, '(a)' ) ' An error code was returned when the GNUPLOT command'\nwrite ( *, '(a)' ) ' was issued. Perhaps GNUPLOT is not in your path.'\nwrite ( *, '(a)' ) ' Type \"which gnuplot\" to check this.'\nstop\nend if\n!\n! Terminate.\n!\nwrite ( *, '(a)' ) ' '\nwrite ( *, '(a)' ) 'GNUFOR:'\nwrite ( *, '(a)' ) ' Normal end of execution.'\n\nwrite ( *, '(a)' ) ' '\ncall timestamp ( )\n\nreturn\nend\n\nsubroutine get_unit ( iunit )\n\n!*****************************************************************************80\n!\n!! GET_UNIT returns a free FORTRAN unit number.\n!\n! Discussion:\n!\n! A \"free\" FORTRAN unit number is an integer between 1 and 99 which\n! is not currently associated with an I/O device. A free FORTRAN unit\n! number is needed in order to open a file with the OPEN command.\n!\n! If IUNIT = 0, then no free FORTRAN unit could be found, although\n! all 99 units were checked (except for units 5, 6 and 9, which\n! are commonly reserved for console I/O).\n!\n! Otherwise, IUNIT is an integer between 1 and 99, representing a\n! free FORTRAN unit. Note that GET_UNIT assumes that units 5 and 6\n! are special, and will never return those values.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 18 September 2005\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Output, integer ( kind = 4 ) IUNIT, the free unit number.\n!\nimplicit none\n\ninteger ( kind = 4 ) i\ninteger ( kind = 4 ) ios\ninteger ( kind = 4 ) iunit\nlogical lopen\n\niunit = 0\n\ndo i = 1, 99\n\nif ( i /= 5 .and. i /= 6 .and. i /= 9 ) then\n\ninquire ( unit = i, opened = lopen, iostat = ios )\n\nif ( ios == 0 ) then\nif ( .not. lopen ) then\niunit = i\nreturn\nend if\nend if\n\nend if\n\nend do\n\nreturn\nend\n\nsubroutine timestamp ( )\n\n!*****************************************************************************80\n!\n!! TIMESTAMP prints the current YMDHMS date as a time stamp.\n!\n! Example:\n!\n! 31 May 2001 9:45:54.872 AM\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 18 May 2013\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! None\n!\nimplicit none\n\ncharacter ( len = 8 ) ampm\ninteger ( kind = 4 ) d\ninteger ( kind = 4 ) h\ninteger ( kind = 4 ) m\ninteger ( kind = 4 ) mm\ncharacter ( len = 9 ), parameter, dimension(12) :: month = (/ &\n'January ', 'February ', 'March ', 'April ', &\n'May ', 'June ', 'July ', 'August ', &\n'September', 'October ', 'November ', 'December ' /)\ninteger ( kind = 4 ) n\ninteger ( kind = 4 ) s\ninteger ( kind = 4 ) values(8)\ninteger ( kind = 4 ) y\n\ncall date_and_time ( values = values )\n\ny = values(1)\nm = values(2)\nd = values(3)\nh = values(5)\nn = values(6)\ns = values(7)\nmm = values(8)\n\nif ( h < 12 ) then\nampm = 'AM'\nelse if ( h == 12 ) then\nif ( n == 0 .and. s == 0 ) then\nampm = 'Noon'\nelse\nampm = 'PM'\nend if\nelse\nh = h - 12\nif ( h < 12 ) then\nampm = 'PM'\nelse if ( h == 12 ) then\nif ( n == 0 .and. s == 0 ) then\nampm = 'Midnight'\nelse\nampm = 'AM'\nend if\nend if\nend if\n\nwrite ( *, '(i2,1x,a,1x,i4,2x,i2,a1,i2.2,a1,i2.2,a1,i3.3,1x,a)' ) &\nd, trim ( month(m) ), y, h, ':', n, ':', s, '.', mm, trim ( ampm )\n\nreturn\nend\n\nsubroutine write_xyy_data ( data_filename, lda, nrow, ncol, x, ierror )\n\n!*****************************************************************************80\n!\n!! WRITE_XYY_DATA writes a table of data to a file, for plotting by GNUPLOT.\n!\n! Discussion:\n!\n! The first column of data is assumed to be the independent variable, X.\n! Separate plots are made of X versus all the other columns of data.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 21 February 2001\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, character ( len = * ) DATA_FILENAME, the name of the data file.\n!\n! Input, integer ( kind = 4 ) LDA, the leading dimension of X.\n!\n! Input, integer ( kind = 4 ) NROW, NCOL, the dimensions of X.\n!\n! Input, real ( kind = 8 ) X(LDA,NCOL), the NROW by NCOL data to be written.\n!\n! Output, integer ( kind = 4 ) IERROR, nonzero if an error occurred.\n!\nimplicit none\n\ninteger ( kind = 4 ) lda\ninteger ( kind = 4 ) ncol\n\ncharacter ( len = * ) data_filename\ninteger ( kind = 4 ) file_unit\ninteger ( kind = 4 ) i\ninteger ( kind = 4 ) ierror\ninteger ( kind = 4 ) ios\ninteger ( kind = 4 ) nrow\nreal ( kind = 8 ) x(0:lda,0:ncol)\n!Note:Now starts from 0\nierror = 0\n\ncall get_unit ( file_unit )\n\nif ( file_unit == 0 ) then\nierror = 1\nwrite ( *, '(a)' ) ' '\nwrite ( *, '(a)' ) 'WRITE_XYY_DATA - Fatal error!'\nwrite ( *, '(a)' ) ' Could not get a free FORTRAN unit.'\nreturn\nend if\n\nopen ( unit = file_unit, file = data_filename, status = 'replace', &\niostat = ios )\n\nif ( ios /= 0 ) then\nierror = 2\nwrite ( *, '(a)' ) ' '\nwrite ( *, '(a)' ) 'WRITE_XYY_DATA - Fatal error!'\nwrite ( *, '(a)' ) ' Could not open the output file.'\nreturn\nend if\n\n!Note: Changed i from starting at 1 to starting at 0\ndo i = 0, nrow\n!Note: Changed from starting at 1 to starting at 0 for x(i,0:ncol)\nwrite ( file_unit, * ) x(i,0:ncol)\nend do\n\nclose ( unit = file_unit )\n\nwrite ( *, '(a)' ) ' '\nwrite ( *, '(a)' ) 'WRITE_XYY_DATA:'\nwrite ( *, '(a)' ) ' Wrote the GNUPLOT XYY data file \"' // &\ntrim ( data_filename ) // '\"'\n\nreturn\nend\n\nsubroutine write_xyy_plots ( command_filename, data_filename, &\nncol, ierror )\n\n!*****************************************************************************80\n!\n!! WRITE_XYY_PLOTS writes GNUPLOT commands to make multiple (X,Y) plots.\n!\n! Discussion:\n!\n! The first column of data is assumed to be the independent variable, X.\n! Separate plots are made of X versus all the other columns of data.\n!\n! Licensing:\n!\n! This code is distributed under the GNU LGPL license.\n!\n! Modified:\n!\n! 24 June 2011\n!\n! Author:\n!\n! John Burkardt\n!\n! Parameters:\n!\n! Input, character ( len = * ) COMMAND_FILENAME, the name of the\n! command file.\n!\n! Input, character ( len = * ) DATA_FILENAME, the name of the data file.\n!\n! Input, integer ( kind = 4 ) NCOL, the number of columns of data.\n!\n! Output, integer ( kind = 4 ) IERROR, nonzero if an error occurred.\n!\nimplicit none\n\ncharacter ( len = * ) command_filename\ncharacter ( len = * ) data_filename\ninteger ( kind = 4 ) file_unit\ninteger ( kind = 4 ) i\ninteger ( kind = 4 ) ierror\ninteger ( kind = 4 ) ios\ninteger ( kind = 4 ) ncol\n!\n! Write the data file.\n!\nierror = 0\n\ncall get_unit ( file_unit )\n\nif ( file_unit == 0 ) then\nierror = 1\nwrite ( *, '(a)' ) ' '\nwrite ( *, '(a)' ) 'WRITE_XYY_PLOTS - Fatal error!'\nwrite ( *, '(a)' ) ' Could not get a free FORTRAN unit.'\nreturn\nend if\n\nopen ( unit = file_unit, file = command_filename, status = 'replace', &\niostat = ios )\n\nif ( ios /= 0 ) then\nierror = 2\nwrite ( *, '(a)' ) ' '\nwrite ( *, '(a)' ) 'WRITE_XYY_PLOTS - Fatal error!'\nwrite ( *, '(a)' ) ' Could not open the output file.'\nreturn\nend if\n\nwrite ( file_unit, '(a)' ) 'set title \"GNUFOR plot\"'\nwrite ( file_unit, '(a)' ) 'set xlabel \"x\"'\nwrite ( file_unit, '(a)' ) 'set ylabel \"y\"'\ndo i = 2, ncol\nwrite ( file_unit, '(a,i2,a)' ) 'plot \"' // trim ( data_filename ) // &\n'\" using ', i, ' with lines'\nwrite ( file_unit, '(a)' ) 'pause -1'\nend do\nwrite ( file_unit, '(a)' ) 'q'\n\nclose ( unit = file_unit )\n\nwrite ( *, '(a)' ) ' '\nwrite ( *, '(a)' ) 'WRITE_XYY_PLOTS:'\nwrite ( *, '(a)' ) ' Wrote the GNUPLOT XYY plots command file \"' // &\ntrim ( command_filename ) // '\"'\n\nreturn\nend\n", "meta": {"hexsha": "95c5af63606ab6ddcb74df677faa6970d09219c6", "size": 24225, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Proj4_2.f90", "max_stars_repo_name": "dtkrizak/numerical-methods", "max_stars_repo_head_hexsha": "876cb72efda71dff2f46de895fe0477f5d855bea", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Proj4_2.f90", "max_issues_repo_name": "dtkrizak/numerical-methods", "max_issues_repo_head_hexsha": "876cb72efda71dff2f46de895fe0477f5d855bea", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Proj4_2.f90", "max_forks_repo_name": "dtkrizak/numerical-methods", "max_forks_repo_head_hexsha": "876cb72efda71dff2f46de895fe0477f5d855bea", "max_forks_repo_licenses": ["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.1516245487, "max_line_length": 130, "alphanum_fraction": 0.6274509804, "num_tokens": 7643, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789178257654, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.6549214407707252}} {"text": " Program dgbtrf_example\n\n! DGBTRF Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_example_aux, Only: nagf_file_print_matrix_real_band\n Use lapack_interfaces, Only: dgbtrf\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nin = 5, nout = 6\n! .. Local Scalars ..\n Integer :: i, ifail, info, j, k, kl, ku, ldab, m, n\n! .. Local Arrays ..\n Real (Kind=dp), Allocatable :: ab(:, :)\n Integer, Allocatable :: ipiv(:)\n! .. Intrinsic Procedures ..\n Intrinsic :: max, min\n! .. Executable Statements ..\n Write (nout, *) 'DGBTRF Example Program Results'\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) m, n, kl, ku\n ldab = 2*kl + ku + 1\n Allocate (ab(ldab,n), ipiv(n))\n\n! Read A from data file\n\n k = kl + ku + 1\n Read (nin, *)((ab(k+i-j,j),j=max(i-kl,1),min(i+ku,n)), i=1, m)\n\n! Factorize A\n Call dgbtrf(m, n, kl, ku, ab, ldab, ipiv, info)\n\n! Print details of factorization\n\n Write (nout, *)\n Flush (nout)\n\n! ifail: behaviour on error exit\n! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft\n ifail = 0\n Call nagf_file_print_matrix_real_band(m, n, kl, kl+ku, ab, ldab, &\n 'Details of factorization', ifail)\n\n! Print pivot indices\n\n Write (nout, *)\n Write (nout, *) 'IPIV'\n Write (nout, 100) ipiv(1:min(m,n))\n\n If (info/=0) Then\n Write (nout, *) 'The factor U is singular'\n End If\n\n100 Format ((3X,7I11))\n End Program\n", "meta": {"hexsha": "588b3aae0e4fd4276d9cb36314954cc511d58c17", "size": 1798, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/dgbtrf_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/dgbtrf_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/dgbtrf_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 28.5396825397, "max_line_length": 90, "alphanum_fraction": 0.5789766407, "num_tokens": 558, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8080671950640465, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.6549214202373502}} {"text": "C PRIME.F 1 \nC COPYRIGHT (C) 2020 HUGH COLEMAN 2 \nC 3 \nC THIS FILE IS PART OF HUGHCOLEMAN/FORTRAN, AN ATTEMPT TO 4 \nC INVESTIGATE THE FORTRAN PROGRAMMING LANGUAGE AND LEARN ABOUT THE 5 \nC EARLY DAYS OF COMPUTING. IT IS RELEASED UNDER THE MIT LICENSE (SEE6 \nC LICENSE.) 7 \n 8 \n 10 FORMAT ( 1I5 ) 9 \n 11 FORMAT ( 1I5, 9H IS PRIME ) 10 \n 12 FORMAT ( 1I5, 13H IS NOT PRIME ) 11 \n 12 \nC READ AN 5 DIGIT INTEGER FROM THE CARD READER. EXIT THE PROGRAM IF 13 \nC THE QUERIED INTEGER IS -1. THEN, CONSIDER THE PRIMALITY EDGE-CASES14 \nC SUCH AS 1 (NOT PRIME) AND 2 (PRIME.) 15 \n 20 READ 10, N 16 \n IF (N+1) 9999, 9999, 21 17 \n 21 IF (N-1) 9999, 120, 22 18 \n 22 IF (N-2) 9999, 110, 30 19 \n 20 \nC FIRST, CHECK IF N IS EVEN. THIS QUICKLY ELIMINATES A LARGE PORTION21 \nC OF THE SEARCH SPACE. 22 \n 30 IF (XMODF(N, 2)) 9999, 120, 40 23 \n 24 \nC THEN, LOOP OVER ODD INTEGERS FROM 3 TO SQRT(N) AND CONSIDER EACH 25 \nC ONE AS A POTENTIAL FACTOR. 26 \n 40 IFAC = 3 27 \n 41 IF (N - IFAC**2) 110, 42, 42 28 \nC IF IFAC DIVIDES N THEN N IS NOT PRIME. 29 \n 42 IF (XMODF(N, IFAC)) 9999, 120, 43 30 \nC OTHERWISE, IFAC DOES NOT DIVIDE N AND WE CONSIDER THE NEXT 31 \nC LARGEST POSSIBLE FACTOR. 32 \n 43 IFAC = IFAC + 2 33 \n GOTO 41 34 \n 35 \n 110 PRINT 11, N 36 \n GOTO 20 37 \n 120 PRINT 12, N 38 \n GOTO 20 39 \n 40 \n 9999 STOP 41 \n", "meta": {"hexsha": "b3a8fae65db181757c172fabac6e9dfd1bac96c8", "size": 3321, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/prime/prog.f", "max_stars_repo_name": "hughcoleman/retrocomputing", "max_stars_repo_head_hexsha": "9742bdf5bb93b2972848192ff1c4ee1f35ae4e26", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/prime/prog.f", "max_issues_repo_name": "hughcoleman/retrocomputing", "max_issues_repo_head_hexsha": "9742bdf5bb93b2972848192ff1c4ee1f35ae4e26", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/prime/prog.f", "max_forks_repo_name": "hughcoleman/retrocomputing", "max_forks_repo_head_hexsha": "9742bdf5bb93b2972848192ff1c4ee1f35ae4e26", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 79.0714285714, "max_line_length": 80, "alphanum_fraction": 0.2655826558, "num_tokens": 629, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681195338728, "lm_q2_score": 0.7634837527911057, "lm_q1q2_score": 0.6548920229262909}} {"text": "program sqrt_02\nreal, parameter :: x = 30\nprint*, sqrt(x)\nend program\n", "meta": {"hexsha": "dadd836b14650bb6bc3d4ebace0a99e3d5fa672b", "size": 70, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "integration_tests/sqrt_02.f90", "max_stars_repo_name": "Thirumalai-Shaktivel/lfortran", "max_stars_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 316, "max_stars_repo_stars_event_min_datetime": "2019-03-24T16:23:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:28:33.000Z", "max_issues_repo_path": "integration_tests/sqrt_02.f90", "max_issues_repo_name": "Thirumalai-Shaktivel/lfortran", "max_issues_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-07-29T04:58:03.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-04T16:40:06.000Z", "max_forks_repo_path": "integration_tests/sqrt_02.f90", "max_forks_repo_name": "Thirumalai-Shaktivel/lfortran", "max_forks_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2019-03-28T19:40:07.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T07:28:55.000Z", "avg_line_length": 14.0, "max_line_length": 25, "alphanum_fraction": 0.7142857143, "num_tokens": 22, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430562234878, "lm_q2_score": 0.7879312031126512, "lm_q1q2_score": 0.6548835482488986}} {"text": "C ALGORITHM 660, COLLECTED ALGORITHMS FROM ACM.\nC THIS WORK PUBLISHED IN TRANSACTIONS ON MATHEMATICAL SOFTWARE,\nC VOL. 14, NO. 2, P.149.\nC\nC\t\t\t QS2TEST\nC\nC THIS PROGRAM TESTS THE SCATTERED DATA INTERPOLATION\nC PACKAGE QSHEP2D BY PRINTING THE MAXIMUM ERRORS ASSOCIATED\nC WITH INTERPOLATED VALUES AND GRADIENTS ON A 10 BY 10\nC UNIFORM GRID IN THE UNIT SQUARE. THE DATA SET CONSISTS\nC OF 36 NODES WITH DATA VALUES TAKEN FROM A QUADRATIC FUNC-\nC TION FOR WHICH THE METHOD IS EXACT. THE RATIO OF MAXIMUM\nC INTERPOLATION ERROR RELATIVE TO THE MACHINE PRECISION IS\nC ALSO PRINTED. THIS SHOULD BE O(1). THE INTERPOLATED\nC VALUES FROM QS2VAL AND QS2GRD ARE COMPARED FOR AGREEMENT.\nC\n INTEGER LCELL(3,3), LNEXT(36)\n REAL X(36), Y(36), F(36), RSQ(36), A(5,36), P(10)\nC\nC QSHEP2 PARAMETERS AND LOGICAL UNIT FOR OUTPUT\nC\n DATA N/36/, NQ/13/, NW/19/, NR/3/, LOUT/6/\nC\nC QUADRATIC TEST FUNCTION AND PARTIAL DERIVATIVES\nC\n FQ(XX,YY) = ((XX + 2.*YY)/3.)**2\n FX(XX,YY) = 2.*(XX + 2.*YY)/9.\n FY(XX,YY) = 4.*(XX + 2.*YY)/9.\nC\nC GENERATE A 6 BY 6 GRID OF NODES IN THE UNIT SQUARE WITH\nC THE NATURAL ORDERING.\nC\n K = 0\n DO 1 J = 1,6\n\tYK = FLOAT(6-J)/5.\n\tDO 1 I = 1,6\n\t K = K + 1\n\t X(K) = FLOAT(I-1)/5.\n 1\t Y(K) = YK\nC\nC COMPUTE THE DATA VALUES.\nC\n DO 2 K = 1,N\n 2\tF(K) = FQ(X(K),Y(K))\nC\nC COMPUTE PARAMETERS DEFINING THE INTERPOLANT Q.\nC\n CALL QSHEP2 (N,X,Y,F,NQ,NW,NR, LCELL,LNEXT,XMIN,YMIN,\n . DX,DY,RMAX,RSQ,A,IER)\n IF (IER .NE. 0) GO TO 6\nC\nC GENERATE A 10 BY 10 UNIFORM GRID OF INTERPOLATION POINTS\nC (P(I),P(J)) IN THE UNIT SQUARE. THE FOUR CORNERS COIN-\nC CIDE WITH NODES.\nC\n DO 3 I = 1,10\n 3\tP(I) = FLOAT(I-1)/9.\nC\nC COMPUTE THE MACHINE PRECISION EPS.\nC\n EPS = 1.\n 4 EPS = EPS/2.\n EP1 = EPS + 1.\n IF (STORE(EP1) .GT. 1.) GO TO 4\n EPS = EPS*2.\nC\nC COMPUTE INTERPOLATION ERRORS AND TEST FOR AGREEMENT IN THE\nC Q VALUES RETURNED BY QS2VAL AND QS2GRD.\nC\n EQ = 0.\n EQX = 0.\n EQY = 0.\n DO 5 J = 1,10\n\tPY = P(J)\n\tDO 5 I = 1,10\n\t PX = P(I)\n\t Q1 = QS2VAL (PX,PY,N,X,Y,F,NR,LCELL,LNEXT,XMIN,\n . YMIN,DX,DY,RMAX,RSQ,A)\n\t CALL QS2GRD (PX,PY,N,X,Y,F,NR,LCELL,LNEXT,XMIN,\n . YMIN,DX,DY,RMAX,RSQ,A, Q,QX,QY,IER)\n\t IF (IER .NE. 0) GO TO 7\n\t IF (ABS(Q1-Q) .GT. 3.*ABS(Q)*EPS) GO TO 8\n\t EQ = AMAX1(EQ,ABS(FQ(PX,PY)-Q))\n\t EQX = AMAX1(EQX,ABS(FX(PX,PY)-QX))\n 5\t EQY = AMAX1(EQY,ABS(FY(PX,PY)-QY))\nC\nC PRINT ERRORS AND THE RATIO EQ/EPS.\nC\n RQ = EQ/EPS\n WRITE (LOUT,100)\n WRITE (LOUT,110) EQ, RQ\n WRITE (LOUT,120) EQX\n WRITE (LOUT,130) EQY\n STOP\n 100 FORMAT (///1H ,31HMAXIMUM ABSOLUTE ERRORS IN THE ,\n . 25HINTERPOLANT Q AND PARTIAL/\n . 1H ,31HDERIVATIVES QX AND QY RELATIVE ,\n . 24HTO MACHINE PRECISION EPS//\n . 1H ,10X,8HFUNCTION,3X,9HMAX ERROR,3X,\n . 13HMAX ERROR/EPS/)\n 110 FORMAT (1H ,13X,1HQ,7X,E9.3,7X,F4.2)\n 120 FORMAT (1H ,13X,2HQX,6X,E9.3)\n 130 FORMAT (1H ,13X,2HQY,6X,E9.3)\nC\nC ERROR IN QSHEP2\nC\n 6 WRITE (LOUT,200) IER\n STOP\n 200 FORMAT (///1H ,28H*** ERROR IN QSHEP2 -- IER =,I2,\n . 4H ***)\nC\nC ERROR IN QS2GRD\nC\n 7 WRITE (LOUT,210) IER\n STOP\n 210 FORMAT (///1H ,28H*** ERROR IN QS2GRD -- IER =,I2,\n . 4H ***)\nC\nC VALUES RETURNED BY QS2VAL AND QS2GRD DIFFER BY A RELATIVE\nC AMOUNT GREATER THAN 3*EPS.\nC\n 8 WRITE (LOUT,220) Q1, Q\n STOP\n 220 FORMAT (///1H ,33H*** ERROR -- INTERPOLATED VALUES ,\n . 37HQ1 (QS2VAL) AND Q2 (QS2GRD) DIFFER --//\n . 1H ,5X,5HQ1 = ,E21.14,5X,5HQ2 = ,E21.14)\n END\n FUNCTION STORE (X)\n REAL X\nC\nC***********************************************************\nC\nC\t\t\t\t\t\tROBERT RENKA\nC\t\t\t\t NORTH TEXAS STATE UNIV.\nC\t\t\t\t\t (817) 565-2767\nC\nC THIS FUNCTION FORCES ITS ARGMENT X TO BE STORED IN MAIN\nC MEMORY. THIS IS USEFUL FOR COMPUTING MACHINE DEPENDENT\nC PARAMETERS (SUCH AS THE MACHINE PRECISION) WHERE IT IS\nC NECESSARY TO AVOID COMPUTATION IN HIGH PRECISION REG-\nC ISTERS.\nC\nC INPUT PARAMETER -\nC\nC\tX - VALUE TO BE STORED.\nC\nC X IS NOT ALTERED BY THIS FUNCTION.\nC\nC OUTPUT PARAMETER -\nC\nC\tSTORE - VALUE OF X AFTER IT HAS BEEN STORED AND\nC\t\t(POSSIBLY) TRUNCATED OR ROUNDED TO THE\nC\t\tMACHINE WORD LENGTH.\nC\nC MODULES REQUIRED BY STORE - NONE\nC\nC***********************************************************\nC\n COMMON/STCOM/Y\n Y = X\n STORE = Y\n RETURN\n END\n SUBROUTINE QSHEP2 (N,X,Y,F,NQ,NW,NR, LCELL,LNEXT,XMIN,\n . YMIN,DX,DY,RMAX,RSQ,A,IER)\n INTEGER N, NQ, NW, NR, LCELL(NR,NR), LNEXT(N), IER\n REAL X(N), Y(N), F(N), XMIN, YMIN, DX, DY, RMAX,\n . RSQ(N), A(5,N)\nC\nC***********************************************************\nC\nC\t\t\t\t\t\tROBERT RENKA\nC\t\t\t\t\tUNIV. OF NORTH TEXAS\nC\t\t\t\t\t (817) 565-2767\nC\t\t\t\t\t\t 01/08/90\nC\nC THIS SUBROUTINE COMPUTES A SET OF PARAMETERS A AND RSQ\nC DEFINING A SMOOTH (ONCE CONTINUOUSLY DIFFERENTIABLE) BI-\nC VARIATE FUNCTION Q(X,Y) WHICH INTERPOLATES DATA VALUES F\nC AT SCATTERED NODES (X,Y). THE INTERPOLANT Q MAY BE EVAL-\nC UATED AT AN ARBITRARY POINT BY FUNCTION QS2VAL, AND ITS\nC FIRST DERIVATIVES ARE COMPUTED BY SUBROUTINE QS2GRD.\nC THE INTERPOLATION SCHEME IS A MODIFIED QUADRATIC SHEPARD\nC METHOD --\nC\nC Q = (W(1)*Q(1)+W(2)*Q(2)+..+W(N)*Q(N))/(W(1)+W(2)+..+W(N))\nC\nC FOR BIVARIATE FUNCTIONS W(K) AND Q(K). THE NODAL FUNC-\nC TIONS ARE GIVEN BY\nC\nC Q(K)(X,Y) = A(1,K)*(X-X(K))**2 + A(2,K)*(X-X(K))*(Y-Y(K))\nC\t + A(3,K)*(Y-Y(K))**2 + A(4,K)*(X-X(K))\nC\t + A(5,K)*(Y-Y(K))\t + F(K) .\nC\nC THUS, Q(K) IS A QUADRATIC FUNCTION WHICH INTERPOLATES THE\nC DATA VALUE AT NODE K. ITS COEFFICIENTS A(,K) ARE OBTAINED\nC BY A WEIGHTED LEAST SQUARES FIT TO THE CLOSEST NQ DATA\nC POINTS WITH WEIGHTS SIMILAR TO W(K). NOTE THAT THE RADIUS\nC OF INFLUENCE FOR THE LEAST SQUARES FIT IS FIXED FOR EACH\nC K, BUT VARIES WITH K.\nC THE WEIGHTS ARE TAKEN TO BE\nC\nC W(K)(X,Y) = ( (R(K)-D(K))+ / R(K)*D(K) )**2\nC\nC WHERE (R(K)-D(K))+ = 0 IF R(K) .LE. D(K) AND D(K)(X,Y) IS\nC THE EUCLIDEAN DISTANCE BETWEEN (X,Y) AND (X(K),Y(K)). THE\nC RADIUS OF INFLUENCE R(K) VARIES WITH K AND IS CHOSEN SO\nC THAT NW NODES ARE WITHIN THE RADIUS. NOTE THAT W(K) IS\nC NOT DEFINED AT NODE (X(K),Y(K)), BUT Q(X,Y) HAS LIMIT F(K)\nC AS (X,Y) APPROACHES (X(K),Y(K)).\nC\nC ON INPUT --\nC\nC\tN = NUMBER OF NODES AND ASSOCIATED DATA VALUES.\nC\t N .GE. 6.\nC\nC\tX,Y = ARRAYS OF LENGTH N CONTAINING THE CARTESIAN\nC\t COORDINATES OF THE NODES.\nC\nC\tF = ARRAY OF LENGTH N CONTAINING THE DATA VALUES\nC\t IN ONE-TO-ONE CORRESPONDENCE WITH THE NODES.\nC\nC\tNQ = NUMBER OF DATA POINTS TO BE USED IN THE LEAST\nC\t SQUARES FIT FOR COEFFICIENTS DEFINING THE NODAL\nC\t FUNCTIONS Q(K). A HIGHLY RECOMMENDED VALUE IS\nC\t NQ = 13. 5 .LE. NQ .LE. MIN(40,N-1).\nC\nC\tNW = NUMBER OF NODES WITHIN (AND DEFINING) THE RADII\nC\t OF INFLUENCE R(K) WHICH ENTER INTO THE WEIGHTS\nC\t W(K). FOR N SUFFICIENTLY LARGE, A RECOMMENDED\nC\t VALUE IS NW = 19. 1 .LE. NW .LE. MIN(40,N-1).\nC\nC\tNR = NUMBER OF ROWS AND COLUMNS IN THE CELL GRID DE-\nC\t FINED IN SUBROUTINE STORE2. A RECTANGLE CON-\nC\t TAINING THE NODES IS PARTITIONED INTO CELLS IN\nC\t ORDER TO INCREASE SEARCH EFFICIENCY. NR =\nC\t SQRT(N/3) IS RECOMMENDED. NR .GE. 1.\nC\nC THE ABOVE PARAMETERS ARE NOT ALTERED BY THIS ROUTINE.\nC\nC\tLCELL = ARRAY OF LENGTH .GE. NR**2.\nC\nC\tLNEXT = ARRAY OF LENGTH .GE. N.\nC\nC\tRSQ = ARRAY OF LENGTH .GE. N.\nC\nC\tA = ARRAY OF LENGTH .GE. 5N.\nC\nC ON OUTPUT --\nC\nC\tLCELL = NR BY NR ARRAY OF NODAL INDICES ASSOCIATED\nC\t\tWITH CELLS. REFER TO STORE2.\nC\nC\tLNEXT = ARRAY OF LENGTH N CONTAINING NEXT-NODE INDI-\nC\t\tCES. REFER TO STORE2.\nC\nC\tXMIN,YMIN,DX,DY = MINIMUM NODAL COORDINATES AND CELL\nC\t\t\t DIMENSIONS. REFER TO STORE2.\nC\nC\tRMAX = SQUARE ROOT OF THE LARGEST ELEMENT IN RSQ --\nC\t MAXIMUM RADIUS R(K).\nC\nC\tRSQ = ARRAY CONTAINING THE SQUARES OF THE RADII R(K)\nC\t WHICH ENTER INTO THE WEIGHTS W(K).\nC\nC\tA = 5 BY N ARRAY CONTAINING THE COEFFICIENTS FOR\nC\t QUADRATIC NODAL FUNCTION Q(K) IN COLUMN K.\nC\nC NOTE THAT THE ABOVE OUTPUT PARAMETERS ARE NOT DEFINED\nC UNLESS IER = 0.\nC\nC\tIER = ERROR INDICATOR --\nC\t IER = 0 IF NO ERRORS WERE ENCOUNTERED.\nC\t IER = 1 IF N, NQ, NW, OR NR IS OUT OF RANGE.\nC\t IER = 2 IF DUPLICATE NODES WERE ENCOUNTERED.\nC\t IER = 3 IF ALL NODES ARE COLLINEAR.\nC\nC MODULES REQUIRED BY QSHEP2 -- GETNP2, GIVENS, ROTATE,\nC\t\t\t\t SETUP2, STORE2\nC\nC INTRINSIC FUNCTIONS CALLED BY QSHEP2 -- ABS, AMIN1, FLOAT,\nC\t\t\t\t\t MAX0, MIN0, SQRT\nC\nC***********************************************************\nC\n INTEGER I, IB, IERR, IP1, IRM1, IROW, J, JP1, K, LMAX,\n . LNP, NEQ, NN, NNQ, NNR, NNW, NP, NPTS(40),\n . NQWMAX\n REAL AV, AVSQ, B(6,6), C, DDX, DDY, DMIN, DTOL, FK,\n . RQ, RS, RSMX, RSOLD, RTOL, RWS, S, SF, SUM, T,\n . XK, XMN, YK, YMN\nC\n DATA RTOL/1.E-5/, DTOL/.01/, SF/1./\nC\nC LOCAL PARAMETERS --\nC\nC AV =\t ROOT-MEAN-SQUARE DISTANCE BETWEEN K AND THE\nC\t\t NODES IN THE LEAST SQUARES SYSTEM (UNLESS\nC\t\t ADDITIONAL NODES ARE INTRODUCED FOR STABIL-\nC\t\t ITY). THE FIRST 3 COLUMNS OF THE MATRIX\nC\t\t ARE SCALED BY 1/AVSQ, THE LAST 2 BY 1/AV\nC AVSQ = AV*AV\nC B =\t TRANSPOSE OF THE AUGMENTED REGRESSION MATRIX\nC C =\t FIRST COMPONENT OF THE PLANE ROTATION USED TO\nC\t\t ZERO THE LOWER TRIANGLE OF B**T -- COMPUTED\nC\t\t BY SUBROUTINE GIVENS\nC DDX,DDY = LOCAL VARIABLES FOR DX AND DY\nC DMIN = MINIMUM OF THE MAGNITUDES OF THE DIAGONAL\nC\t\t ELEMENTS OF THE REGRESSION MATRIX AFTER\nC\t\t ZEROS ARE INTRODUCED BELOW THE DIAGONAL\nC DTOL = TOLERANCE FOR DETECTING AN ILL-CONDITIONED\nC\t\t SYSTEM. THE SYSTEM IS ACCEPTED WHEN DMIN\nC\t\t .GE. DTOL\nC FK =\t DATA VALUE AT NODE K -- F(K)\nC I =\t INDEX FOR A, B, AND NPTS\nC IB =\t DO-LOOP INDEX FOR BACK SOLVE\nC IERR = ERROR FLAG FOR THE CALL TO STORE2\nC IP1 = I+1\nC IRM1 = IROW-1\nC IROW = ROW INDEX FOR B\nC J =\t INDEX FOR A AND B\nC JP1 = J+1\nC K =\t NODAL FUNCTION INDEX AND COLUMN INDEX FOR A\nC LMAX = MAXIMUM NUMBER OF NPTS ELEMENTS (MUST BE CON-\nC\t\t SISTENT WITH THE DIMENSION STATEMENT ABOVE)\nC LNP = CURRENT LENGTH OF NPTS\nC NEQ = NUMBER OF EQUATIONS IN THE LEAST SQUARES FIT\nC NN,NNQ,NNR = LOCAL COPIES OF N, NQ, AND NR\nC NNW = LOCAL COPY OF NW\nC NP =\t NPTS ELEMENT\nC NPTS = ARRAY CONTAINING THE INDICES OF A SEQUENCE OF\nC\t\t NODES TO BE USED IN THE LEAST SQUARES FIT\nC\t\t OR TO COMPUTE RSQ. THE NODES ARE ORDERED\nC\t\t BY DISTANCE FROM K AND THE LAST ELEMENT\nC\t\t (USUALLY INDEXED BY LNP) IS USED ONLY TO\nC\t\t DETERMINE RQ, OR RSQ(K) IF NW .GT. NQ\nC NQWMAX = MAX(NQ,NW)\nC RQ =\t RADIUS OF INFLUENCE WHICH ENTERS INTO THE\nC\t\t WEIGHTS FOR Q(K) (SEE SUBROUTINE SETUP2)\nC RS =\t SQUARED DISTANCE BETWEEN K AND NPTS(LNP) --\nC\t\t USED TO COMPUTE RQ AND RSQ(K)\nC RSMX = MAXIMUM RSQ ELEMENT ENCOUNTERED\nC RSOLD = SQUARED DISTANCE BETWEEN K AND NPTS(LNP-1) --\nC\t\t USED TO COMPUTE A RELATIVE CHANGE IN RS\nC\t\t BETWEEN SUCCEEDING NPTS ELEMENTS\nC RTOL = TOLERANCE FOR DETECTING A SUFFICIENTLY LARGE\nC\t\t RELATIVE CHANGE IN RS. IF THE CHANGE IS\nC\t\t NOT GREATER THAN RTOL, THE NODES ARE\nC\t\t TREATED AS BEING THE SAME DISTANCE FROM K\nC RWS = CURRENT VALUE OF RSQ(K)\nC S =\t SECOND COMPONENT OF THE PLANE GIVENS ROTATION\nC SF =\t MARQUARDT STABILIZATION FACTOR USED TO DAMP\nC\t\t OUT THE FIRST 3 SOLUTION COMPONENTS (SECOND\nC\t\t PARTIALS OF THE QUADRATIC) WHEN THE SYSTEM\nC\t\t IS ILL-CONDITIONED. AS SF INCREASES, THE\nC\t\t FITTING FUNCTION APPROACHES A LINEAR\nC SUM = SUM OF SQUARED EUCLIDEAN DISTANCES BETWEEN\nC\t\t NODE K AND THE NODES USED IN THE LEAST\nC\t\t SQUARES FIT (UNLESS ADDITIONAL NODES ARE\nC\t\t ADDED FOR STABILITY)\nC T =\t TEMPORARY VARIABLE FOR ACCUMULATING A SCALAR\nC\t\t PRODUCT IN THE BACK SOLVE\nC XK,YK = COORDINATES OF NODE K -- X(K), Y(K)\nC XMN,YMN = LOCAL VARIABLES FOR XMIN AND YMIN\nC\n NN = N\n NNQ = NQ\n NNW = NW\n NNR = NR\n NQWMAX = MAX0(NNQ,NNW)\n LMAX = MIN0(40,NN-1)\n IF (5 .GT. NNQ .OR. 1 .GT. NNW .OR. NQWMAX .GT.\n . LMAX .OR. NNR .LT. 1) GO TO 20\nC\nC CREATE THE CELL DATA STRUCTURE, AND INITIALIZE RSMX.\nC\n CALL STORE2 (NN,X,Y,NNR, LCELL,LNEXT,XMN,YMN,DDX,DDY,\n . IERR)\n IF (IERR .NE. 0) GO TO 22\n RSMX = 0.\nC\nC OUTER LOOP ON NODE K\nC\n DO 18 K = 1,NN\n\tXK = X(K)\n\tYK = Y(K)\n\tFK = F(K)\nC\nC MARK NODE K TO EXCLUDE IT FROM THE SEARCH FOR NEAREST\nC NEIGHBORS.\nC\n\tLNEXT(K) = -LNEXT(K)\nC\nC INITIALIZE FOR LOOP ON NPTS.\nC\n\tRS = 0.\n\tSUM = 0.\n\tRWS = 0.\n\tRQ = 0.\n\tLNP = 0\nC\nC COMPUTE NPTS, LNP, RWS, NEQ, RQ, AND AVSQ.\nC\n 1\tSUM = SUM + RS\n\t IF (LNP .EQ. LMAX) GO TO 3\n\t LNP = LNP + 1\n\t RSOLD = RS\n\t CALL GETNP2 (XK,YK,X,Y,NNR,LCELL,LNEXT,XMN,YMN,\n . DDX,DDY, NP,RS)\n\t IF (RS .EQ. 0.) GO TO 21\n\t NPTS(LNP) = NP\n\t IF ( (RS-RSOLD)/RS .LT. RTOL ) GO TO 1\n\t IF (RWS .EQ. 0. .AND. LNP .GT. NNW) RWS = RS\n\t IF (RQ .NE. 0. .OR. LNP .LE. NNQ) GO TO 2\nC\nC RQ = 0 (NOT YET COMPUTED) AND LNP .GT. NQ. RQ =\nC SQRT(RS) IS SUFFICIENTLY LARGE TO (STRICTLY) INCLUDE\nC NQ NODES. THE LEAST SQUARES FIT WILL INCLUDE NEQ =\nC LNP - 1 EQUATIONS FOR 5 .LE. NQ .LE. NEQ .LT. LMAX\nC .LE. N-1.\nC\n\t NEQ = LNP - 1\n\t RQ = SQRT(RS)\n\t AVSQ = SUM/FLOAT(NEQ)\nC\nC BOTTOM OF LOOP -- TEST FOR TERMINATION.\nC\n 2\t IF (LNP .GT. NQWMAX) GO TO 4\n\t GO TO 1\nC\nC ALL LMAX NODES ARE INCLUDED IN NPTS. RWS AND/OR RQ**2 IS\nC (ARBITRARILY) TAKEN TO BE 10 PERCENT LARGER THAN THE\nC DISTANCE RS TO THE LAST NODE INCLUDED.\nC\n 3\tIF (RWS .EQ. 0.) RWS = 1.1*RS\n\tIF (RQ .NE. 0.) GO TO 4\n\t NEQ = LMAX\n\t RQ = SQRT(1.1*RS)\n\t AVSQ = SUM/FLOAT(NEQ)\nC\nC STORE RSQ(K), UPDATE RSMX IF NECESSARY, AND COMPUTE AV.\nC\n 4\tRSQ(K) = RWS\n\tIF (RWS .GT. RSMX) RSMX = RWS\n\tAV = SQRT(AVSQ)\nC\nC SET UP THE AUGMENTED REGRESSION MATRIX (TRANSPOSED) AS THE\nC COLUMNS OF B, AND ZERO OUT THE LOWER TRIANGLE (UPPER\nC TRIANGLE OF B) WITH GIVENS ROTATIONS -- QR DECOMPOSITION\nC WITH ORTHOGONAL MATRIX Q NOT STORED.\nC\n\tI = 0\n 5\t I = I + 1\n\t NP = NPTS(I)\n\t IROW = MIN0(I,6)\n\t CALL SETUP2 (XK,YK,FK,X(NP),Y(NP),F(NP),AV,AVSQ,\n . RQ, B(1,IROW))\n\t IF (I .EQ. 1) GO TO 5\n\t IRM1 = IROW-1\n\t DO 6 J = 1,IRM1\n\t JP1 = J + 1\n\t CALL GIVENS (B(J,J),B(J,IROW),C,S)\n 6\t CALL ROTATE (6-J,C,S,B(JP1,J),B(JP1,IROW))\n\t IF (I .LT. NEQ) GO TO 5\nC\nC TEST THE SYSTEM FOR ILL-CONDITIONING.\nC\n\tDMIN = AMIN1( ABS(B(1,1)),ABS(B(2,2)),ABS(B(3,3)),\n . ABS(B(4,4)),ABS(B(5,5)) )\n\tIF (DMIN*RQ .GE. DTOL) GO TO 13\n\tIF (NEQ .EQ. LMAX) GO TO 10\nC\nC INCREASE RQ AND ADD ANOTHER EQUATION TO THE SYSTEM TO\nC IMPROVE THE CONDITIONING. THE NUMBER OF NPTS ELEMENTS\nC IS ALSO INCREASED IF NECESSARY.\nC\n 7\tRSOLD = RS\n\tNEQ = NEQ + 1\n\tIF (NEQ .EQ. LMAX) GO TO 9\n\tIF (NEQ .EQ. LNP) GO TO 8\nC\nC NEQ .LT. LNP\nC\n\tNP = NPTS(NEQ+1)\n\tRS = (X(NP)-XK)**2 + (Y(NP)-YK)**2\n\tIF ( (RS-RSOLD)/RS .LT. RTOL ) GO TO 7\n\tRQ = SQRT(RS)\n\tGO TO 5\nC\nC ADD AN ELEMENT TO NPTS.\nC\n 8\tLNP = LNP + 1\n\tCALL GETNP2 (XK,YK,X,Y,NNR,LCELL,LNEXT,XMN,YMN,\n . DDX,DDY, NP,RS)\n\tIF (NP .EQ. 0) GO TO 21\n\tNPTS(LNP) = NP\n\tIF ( (RS-RSOLD)/RS .LT. RTOL ) GO TO 7\n\tRQ = SQRT(RS)\n\tGO TO 5\nC\n 9\tRQ = SQRT(1.1*RS)\n\tGO TO 5\nC\nC STABILIZE THE SYSTEM BY DAMPING SECOND PARTIALS -- ADD\nC MULTIPLES OF THE FIRST THREE UNIT VECTORS TO THE FIRST\nC THREE EQUATIONS.\nC\n 10\tDO 12 I = 1,3\n\t B(I,6) = SF\n\t IP1 = I + 1\n\t DO 11 J = IP1,6\n 11\t B(J,6) = 0.\n\t DO 12 J = I,5\n\t JP1 = J + 1\n\t CALL GIVENS (B(J,J),B(J,6),C,S)\n 12\t CALL ROTATE (6-J,C,S,B(JP1,J),B(JP1,6))\nC\nC TEST THE STABILIZED SYSTEM FOR ILL-CONDITIONING.\nC\n\tDMIN = AMIN1( ABS(B(1,1)),ABS(B(2,2)),ABS(B(3,3)),\n . ABS(B(4,4)),ABS(B(5,5)) )\n\tIF (DMIN*RQ .LT. DTOL) GO TO 22\nC\nC SOLVE THE 5 BY 5 TRIANGULAR SYSTEM FOR THE COEFFICIENTS\nC\n 13\tDO 15 IB = 1,5\n\t I = 6-IB\n\t T = 0.\n\t IF (I .EQ. 5) GO TO 15\n\t IP1 = I + 1\n\t DO 14 J = IP1,5\n 14\t T = T + B(J,I)*A(J,K)\n 15\t A(I,K) = (B(6,I)-T)/B(I,I)\nC\nC SCALE THE COEFFICIENTS TO ADJUST FOR THE COLUMN SCALING.\nC\n\tDO 16 I = 1,3\n 16\t A(I,K) = A(I,K)/AVSQ\n\tA(4,K) = A(4,K)/AV\n\tA(5,K) = A(5,K)/AV\nC\nC UNMARK K AND THE ELEMENTS OF NPTS.\nC\n\tLNEXT(K) = -LNEXT(K)\n\tDO 17 I = 1,LNP\n\t NP = NPTS(I)\n 17\t LNEXT(NP) = -LNEXT(NP)\n 18\tCONTINUE\nC\nC NO ERRORS ENCOUNTERED.\nC\n XMIN = XMN\n YMIN = YMN\n DX = DDX\n DY = DDY\n RMAX = SQRT(RSMX)\n IER = 0\n RETURN\nC\nC N, NQ, NW, OR NR IS OUT OF RANGE.\nC\n 20 IER = 1\n RETURN\nC\nC DUPLICATE NODES WERE ENCOUNTERED BY GETNP2.\nC\n 21 IER = 2\n RETURN\nC\nC NO UNIQUE SOLUTION DUE TO COLLINEAR NODES.\nC\n 22 XMIN = XMN\n YMIN = YMN\n DX = DDX\n DY = DDY\n IER = 3\n RETURN\n END\n FUNCTION QS2VAL (PX,PY,N,X,Y,F,NR,LCELL,LNEXT,XMIN,\n . YMIN,DX,DY,RMAX,RSQ,A)\n INTEGER N, NR, LCELL(NR,NR), LNEXT(N)\n REAL PX, PY, X(N), Y(N), F(N), XMIN, YMIN, DX, DY,\n . RMAX, RSQ(N), A(5,N)\nC\nC***********************************************************\nC\nC\t\t\t\t\t\tROBERT RENKA\nC\t\t\t\t\tUNIV. OF NORTH TEXAS\nC\t\t\t\t\t (817) 565-2767\nC\t\t\t\t\t\t 10/28/87\nC\nC THIS FUNCTION RETURNS THE VALUE Q(PX,PY) WHERE Q IS THE\nC WEIGHTED SUM OF QUADRATIC NODAL FUNCTIONS DEFINED IN SUB-\nC ROUTINE QSHEP2. QS2GRD MAY BE CALLED TO COMPUTE A GRADI-\nC ENT OF Q ALONG WITH THE VALUE, AND/OR TO TEST FOR ERRORS.\nC\nC ON INPUT --\nC\nC\tPX,PY = CARTESIAN COORDINATES OF THE POINT P AT\nC\t\tWHICH Q IS TO BE EVALUATED.\nC\nC\tN = NUMBER OF NODES AND DATA VALUES DEFINING Q.\nC\t N .GE. 6.\nC\nC\tX,Y,F = ARRAYS OF LENGTH N CONTAINING THE NODES AND\nC\t\tDATA VALUES INTERPOLATED BY Q.\nC\nC\tNR = NUMBER OF ROWS AND COLUMNS IN THE CELL GRID.\nC\t REFER TO STORE2. NR .GE. 1.\nC\nC\tLCELL = NR BY NR ARRAY OF NODAL INDICES ASSOCIATED\nC\t\tWITH CELLS. REFER TO STORE2.\nC\nC\tLNEXT = ARRAY OF LENGTH N CONTAINING NEXT-NODE INDI-\nC\t\tCES. REFER TO STORE2.\nC\nC\tXMIN,YMIN,DX,DY = MINIMUM NODAL COORDINATES AND CELL\nC\t\t\t DIMENSIONS. DX AND DY MUST BE\nC\t\t\t POSITIVE. REFER TO STORE2.\nC\nC\tRMAX = SQUARE ROOT OF THE LARGEST ELEMENT IN RSQ --\nC\t MAXIMUM RADIUS.\nC\nC\tRSQ = ARRAY OF LENGTH N CONTAINING THE SQUARED RADII\nC\t WHICH ENTER INTO THE WEIGHTS DEFINING Q.\nC\nC\tA = 5 BY N ARRAY CONTAINING THE COEFFICIENTS FOR THE\nC\t NODAL FUNCTIONS DEFINING Q.\nC\nC INPUT PARAMETERS ARE NOT ALTERED BY THIS FUNCTION. THE\nC PARAMETERS OTHER THAN PX AND PY SHOULD BE INPUT UNALTERED\nC FROM THEIR VALUES ON OUTPUT FROM QSHEP2. THIS FUNCTION\nC SHOULD NOT BE CALLED IF A NONZERO ERROR FLAG WAS RETURNED\nC BY QSHEP2.\nC\nC ON OUTPUT --\nC\nC\tQS2VAL = FUNCTION VALUE Q(PX,PY) UNLESS N, NR, DX,\nC\t\t DY, OR RMAX IS INVALID, IN WHICH CASE NO\nC\t\t VALUE IS RETURNED.\nC\nC MODULES REQUIRED BY QS2VAL -- NONE\nC\nC INTRINSIC FUNCTIONS CALLED BY QS2VAL -- IFIX, SQRT\nC\nC***********************************************************\nC\n XP = PX\n YP = PY\n QS2VAL = -9999.99\n IF (N .LT. 6 .OR. NR .LT. 1 .OR. DX .LE. 0. .OR.\n . DY .LE. 0. .OR. RMAX .LT. 0.) RETURN\nC\nC SET IMIN, IMAX, JMIN, AND JMAX TO CELL INDICES DEFINING\nC THE RANGE OF THE SEARCH FOR NODES WHOSE RADII INCLUDE\nC P. THE CELLS WHICH MUST BE SEARCHED ARE THOSE INTER-\nC SECTED BY (OR CONTAINED IN) A CIRCLE OF RADIUS RMAX\nC CENTERED AT P.\nC\n IMIN = IFIX((XP-XMIN-RMAX)/DX) + 1\n IMAX = IFIX((XP-XMIN+RMAX)/DX) + 1\n IF (IMIN .LT. 1) IMIN = 1\n IF (IMAX .GT. NR) IMAX = NR\n JMIN = IFIX((YP-YMIN-RMAX)/DY) + 1\n JMAX = IFIX((YP-YMIN+RMAX)/DY) + 1\n IF (JMIN .LT. 1) JMIN = 1\n IF (JMAX .GT. NR) JMAX = NR\nC\nC THE FOLLOWING IS A TEST FOR NO CELLS WITHIN THE CIRCLE\nC OF RADIUS RMAX.\nC\n IF (IMIN .GT. IMAX .OR. JMIN .GT. JMAX) GO TO 5\nC\nC ACCUMULATE WEIGHT VALUES IN SW AND WEIGHTED NODAL FUNCTION\nC VALUES IN SWQ. THE WEIGHTS ARE W(K) = ((R-D)+/(R*D))**2\nC FOR R**2 = RSQ(K) AND D = DISTANCE BETWEEN P AND NODE K.\nC\n SW = 0.\n SWQ = 0.\nC\nC OUTER LOOP ON CELLS (I,J).\nC\n DO 3 J = JMIN,JMAX\n\tDO 3 I = IMIN,IMAX\n\t K = LCELL(I,J)\n\t IF (K .EQ. 0) GO TO 3\nC\nC INNER LOOP ON NODES K.\nC\n 1\t DELX = XP - X(K)\n\t DELY = YP - Y(K)\n\t DXSQ = DELX*DELX\n\t DYSQ = DELY*DELY\n\t DS = DXSQ + DYSQ\n\t RS = RSQ(K)\n\t IF (DS .GE. RS) GO TO 2\n\t IF (DS .EQ. 0.) GO TO 4\n\t RDS = RS*DS\n\t RD = SQRT(RDS)\n\t W = (RS+DS-RD-RD)/RDS\n\t SW = SW + W\n\t SWQ = SWQ + W*(A(1,K)*DXSQ + A(2,K)*DELX*DELY +\n . A(3,K)*DYSQ + A(4,K)*DELX +\n . A(5,K)*DELY + F(K))\nC\nC BOTTOM OF LOOP ON NODES IN CELL (I,J).\nC\n 2\t KP = K\n\t K = LNEXT(KP)\n\t IF (K .NE. KP) GO TO 1\n 3\t CONTINUE\nC\nC SW = 0 IFF P IS NOT WITHIN THE RADIUS R(K) FOR ANY NODE K.\nC\n IF (SW .EQ. 0.) GO TO 5\n QS2VAL = SWQ/SW\n RETURN\nC\nC (PX,PY) = (X(K),Y(K))\nC\n 4 QS2VAL = F(K)\n RETURN\nC\nC ALL WEIGHTS ARE 0 AT P.\nC\n 5 QS2VAL = 0.\n RETURN\n END\n SUBROUTINE QS2GRD (PX,PY,N,X,Y,F,NR,LCELL,LNEXT,XMIN,\n . YMIN,DX,DY,RMAX,RSQ,A, Q,QX,QY,IER)\n INTEGER N, NR, LCELL(NR,NR), LNEXT(N), IER\n REAL PX, PY, X(N), Y(N), F(N), XMIN, YMIN, DX, DY,\n . RMAX, RSQ(N), A(5,N), Q, QX, QY\nC\nC***********************************************************\nC\nC\t\t\t\t\t\tROBERT RENKA\nC\t\t\t\t\tUNIV. OF NORTH TEXAS\nC\t\t\t\t\t (817) 565-2767\nC\t\t\t\t\t\t 10/28/87\nC\nC THIS SUBROUTINE COMPUTES THE VALUE AND GRADIENT AT\nC (PX,PY) OF THE INTERPOLATORY FUNCTION Q DEFINED IN SUB-\nC ROUTINE QSHEP2. Q(X,Y) IS A WEIGHTED SUM OF QUADRATIC\nC NODAL FUNCTIONS.\nC\nC ON INPUT --\nC\nC\tPX,PY = CARTESIAN COORDINATES OF THE POINT AT WHICH\nC\t\tQ AND ITS PARTIALS ARE TO BE EVALUATED.\nC\nC\tN = NUMBER OF NODES AND DATA VALUES DEFINING Q.\nC\t N .GE. 6.\nC\nC\tX,Y,F = ARRAYS OF LENGTH N CONTAINING THE NODES AND\nC\t\tDATA VALUES INTERPOLATED BY Q.\nC\nC\tNR = NUMBER OF ROWS AND COLUMNS IN THE CELL GRID.\nC\t REFER TO STORE2. NR .GE. 1.\nC\nC\tLCELL = NR BY NR ARRAY OF NODAL INDICES ASSOCIATED\nC\t\tWITH CELLS. REFER TO STORE2.\nC\nC\tLNEXT = ARRAY OF LENGTH N CONTAINING NEXT-NODE INDI-\nC\t\tCES. REFER TO STORE2.\nC\nC\tXMIN,YMIN,DX,DY = MINIMUM NODAL COORDINATES AND CELL\nC\t\t\t DIMENSIONS. DX AND DY MUST BE\nC\t\t\t POSITIVE. REFER TO STORE2.\nC\nC\tRMAX = SQUARE ROOT OF THE LARGEST ELEMENT IN RSQ --\nC\t MAXIMUM RADIUS.\nC\nC\tRSQ = ARRAY OF LENGTH N CONTAINING THE SQUARED RADII\nC\t WHICH ENTER INTO THE WEIGHTS DEFINING Q.\nC\nC\tA = 5 BY N ARRAY CONTAINING THE COEFFICIENTS FOR THE\nC\t NODAL FUNCTIONS DEFINING Q.\nC\nC INPUT PARAMETERS ARE NOT ALTERED BY THIS SUBROUTINE.\nC THE PARAMETERS OTHER THAN PX AND PY SHOULD BE INPUT UNAL-\nC TERED FROM THEIR VALUES ON OUTPUT FROM QSHEP2. THIS SUB-\nC ROUTINE SHOULD NOT BE CALLED IF A NONZERO ERROR FLAG WAS\nC RETURNED BY QSHEP2.\nC\nC ON OUTPUT --\nC\nC\tQ = VALUE OF Q AT (PX,PY) UNLESS IER .EQ. 1, IN\nC\t WHICH CASE NO VALUES ARE RETURNED.\nC\nC\tQX,QY = FIRST PARTIAL DERIVATIVES OF Q AT (PX,PY)\nC\t\tUNLESS IER .EQ. 1.\nC\nC\tIER = ERROR INDICATOR\nC\t IER = 0 IF NO ERRORS WERE ENCOUNTERED.\nC\t IER = 1 IF N, NR, DX, DY OR RMAX IS INVALID.\nC\t IER = 2 IF NO ERRORS WERE ENCOUNTERED BUT\nC\t\t (PX,PY) IS NOT WITHIN THE RADIUS R(K)\nC\t\t FOR ANY NODE K (AND THUS Q=QX=QY=0).\nC\nC MODULES REQUIRED BY QS2GRD -- NONE\nC\nC INTRINSIC FUNCTIONS CALLED BY QS2GRD -- IFIX, SQRT\nC\nC***********************************************************\nC\n XP = PX\n YP = PY\n IF (N .LT. 6 .OR. NR .LT. 1 .OR. DX .LE. 0. .OR.\n . DY .LE. 0. .OR. RMAX .LT. 0.) GO TO 5\nC\nC SET IMIN, IMAX, JMIN, AND JMAX TO CELL INDICES DEFINING\nC THE RANGE OF THE SEARCH FOR NODES WHOSE RADII INCLUDE\nC P. THE CELLS WHICH MUST BE SEARCHED ARE THOSE INTER-\nC SECTED BY (OR CONTAINED IN) A CIRCLE OF RADIUS RMAX\nC CENTERED AT P.\nC\n IMIN = IFIX((XP-XMIN-RMAX)/DX) + 1\n IMAX = IFIX((XP-XMIN+RMAX)/DX) + 1\n IF (IMIN .LT. 1) IMIN = 1\n IF (IMAX .GT. NR) IMAX = NR\n JMIN = IFIX((YP-YMIN-RMAX)/DY) + 1\n JMAX = IFIX((YP-YMIN+RMAX)/DY) + 1\n IF (JMIN .LT. 1) JMIN = 1\n IF (JMAX .GT. NR) JMAX = NR\nC\nC THE FOLLOWING IS A TEST FOR NO CELLS WITHIN THE CIRCLE\nC OF RADIUS RMAX.\nC\n IF (IMIN .GT. IMAX .OR. JMIN .GT. JMAX) GO TO 6\nC\nC Q = SWQ/SW = SUM(W(K)*Q(K))/SUM(W(K)) WHERE THE SUM IS\nC FROM K = 1 TO N, Q(K) IS THE QUADRATIC NODAL FUNCTION,\nC AND W(K) = ((R-D)+/(R*D))**2 FOR RADIUS R(K) AND DIST-\nC ANCE D(K). THUS\nC\nC\t QX = (SWQX*SW - SWQ*SWX)/SW**2 AND\nC\t QY = (SWQY*SW - SWQ*SWY)/SW**2\nC\nC WHERE SWQX AND SWX ARE PARTIAL DERIVATIVES WITH RESPECT\nC TO X OF SWQ AND SW, RESPECTIVELY. SWQY AND SWY ARE DE-\nC FINED SIMILARLY.\nC\n SW = 0.\n SWX = 0.\n SWY = 0.\n SWQ = 0.\n SWQX = 0.\n SWQY = 0.\nC\nC OUTER LOOP ON CELLS (I,J).\nC\n DO 3 J = JMIN,JMAX\n\tDO 3 I = IMIN,IMAX\n\t K = LCELL(I,J)\n\t IF (K .EQ. 0) GO TO 3\nC\nC INNER LOOP ON NODES K.\nC\n 1\t DELX = XP - X(K)\n\t DELY = YP - Y(K)\n\t DXSQ = DELX*DELX\n\t DYSQ = DELY*DELY\n\t DS = DXSQ + DYSQ\n\t RS = RSQ(K)\n\t IF (DS .GE. RS) GO TO 2\n\t IF (DS .EQ. 0.) GO TO 4\n\t RDS = RS*DS\n\t RD = SQRT(RDS)\n\t W = (RS+DS-RD-RD)/RDS\n\t T = 2.*(RD-RS)/(DS*RDS)\n\t WX = DELX*T\n\t WY = DELY*T\n\t QKX = 2.*A(1,K)*DELX + A(2,K)*DELY\n\t QKY = A(2,K)*DELX + 2.*A(3,K)*DELY\n\t QK = (QKX*DELX + QKY*DELY)/2.\n\t QKX = QKX + A(4,K)\n\t QKY = QKY + A(5,K)\n\t QK = QK + A(4,K)*DELX + A(5,K)*DELY + F(K)\n\t SW = SW + W\n\t SWX = SWX + WX\n\t SWY = SWY + WY\n\t SWQ = SWQ + W*QK\n\t SWQX = SWQX + WX*QK + W*QKX\n\t SWQY = SWQY + WY*QK + W*QKY\nC\nC BOTTOM OF LOOP ON NODES IN CELL (I,J).\nC\n 2\t KP = K\n\t K = LNEXT(KP)\n\t IF (K .NE. KP) GO TO 1\n 3\t CONTINUE\nC\nC SW = 0 IFF P IS NOT WITHIN THE RADIUS R(K) FOR ANY NODE K.\nC\n IF (SW .EQ. 0.) GO TO 6\n Q = SWQ/SW\n SWS = SW*SW\n QX = (SWQX*SW - SWQ*SWX)/SWS\n QY = (SWQY*SW - SWQ*SWY)/SWS\n IER = 0\n RETURN\nC\nC (PX,PY) = (X(K),Y(K))\nC\n 4 Q = F(K)\n QX = A(4,K)\n QY = A(5,K)\n IER = 0\n RETURN\nC\nC INVALID INPUT PARAMETER.\nC\n 5 IER = 1\n RETURN\nC\nC NO CELLS CONTAIN A POINT WITHIN RMAX OF P, OR\nC SW = 0 AND THUS DS .GE. RSQ(K) FOR ALL K.\nC\n 6 Q = 0.\n QX = 0.\n QY = 0.\n IER = 2\n RETURN\n END\n SUBROUTINE GETNP2 (PX,PY,X,Y,NR,LCELL,LNEXT,XMIN,YMIN,\n . DX,DY, NP,DSQ)\n INTEGER NR, LCELL(NR,NR), LNEXT(1), NP\n REAL PX, PY, X(1), Y(1), XMIN, YMIN, DX, DY, DSQ\nC\nC***********************************************************\nC\nC\t\t\t\t\t\tROBERT RENKA\nC\t\t\t\t\tUNIV. OF NORTH TEXAS\nC\t\t\t\t\t (817) 565-2767\nC\nC GIVEN A SET OF N NODES AND THE DATA STRUCTURE DEFINED IN\nC SUBROUTINE STORE2, THIS SUBROUTINE USES THE CELL METHOD TO\nC FIND THE CLOSEST UNMARKED NODE NP TO A SPECIFIED POINT P.\nC NP IS THEN MARKED BY SETTING LNEXT(NP) TO -LNEXT(NP). (A\nC NODE IS MARKED IF AND ONLY IF THE CORRESPONDING LNEXT ELE-\nC MENT IS NEGATIVE. THE ABSOLUTE VALUES OF LNEXT ELEMENTS,\nC HOWEVER, MUST BE PRESERVED.)\tTHUS, THE CLOSEST M NODES TO\nC P MAY BE DETERMINED BY A SEQUENCE OF M CALLS TO THIS ROU-\nC TINE. NOTE THAT IF THE NEAREST NEIGHBOR TO NODE K IS TO\nC BE DETERMINED (PX = X(K) AND PY = Y(K)), THEN K SHOULD BE\nC MARKED BEFORE THE CALL TO THIS ROUTINE.\nC THE SEARCH IS BEGUN IN THE CELL CONTAINING (OR CLOSEST\nC TO) P AND PROCEEDS OUTWARD IN RECTANGULAR LAYERS UNTIL ALL\nC CELLS WHICH CONTAIN POINTS WITHIN DISTANCE R OF P HAVE\nC BEEN SEARCHED, WHERE R IS THE DISTANCE FROM P TO THE FIRST\nC UNMARKED NODE ENCOUNTERED (INFINITE IF NO UNMARKED NODES\nC ARE PRESENT).\nC\nC ON INPUT --\nC\nC\tPX,PY = CARTESIAN COORDINATES OF THE POINT P WHOSE\nC\t\tNEAREST UNMARKED NEIGHBOR IS TO BE FOUND.\nC\nC\tX,Y = ARRAYS OF LENGTH N, FOR N .GE. 2, CONTAINING\nC\t THE CARTESIAN COORDINATES OF THE NODES.\nC\nC\tNR = NUMBER OF ROWS AND COLUMNS IN THE CELL GRID.\nC\t NR .GE. 1.\nC\nC\tLCELL = NR BY NR ARRAY OF NODAL INDICES ASSOCIATED\nC\t\tWITH CELLS.\nC\nC\tLNEXT = ARRAY OF LENGTH N CONTAINING NEXT-NODE INDI-\nC\t\tCES (OR THEIR NEGATIVES).\nC\nC\tXMIN,YMIN,DX,DY = MINIMUM NODAL COORDINATES AND CELL\nC\t\t\t DIMENSIONS. DX AND DY MUST BE\nC\t\t\t POSITIVE.\nC\nC INPUT PARAMETERS OTHER THAN LNEXT ARE NOT ALTERED BY\nC THIS ROUTINE. WITH THE EXCEPTION OF (PX,PY) AND THE SIGNS\nC OF LNEXT ELEMENTS, THESE PARAMETERS SHOULD BE UNALTERED\nC FROM THEIR VALUES ON OUTPUT FROM SUBROUTINE STORE2.\nC\nC ON OUTPUT --\nC\nC\tNP = INDEX (FOR X AND Y) OF THE NEAREST UNMARKED\nC\t NODE TO P, OR 0 IF ALL NODES ARE MARKED OR NR\nC\t .LT. 1 OR DX .LE. 0 OR DY .LE. 0. LNEXT(NP)\nC\t .LT. 0 IF NP .NE. 0.\nC\nC\tDSQ = SQUARED EUCLIDEAN DISTANCE BETWEEN P AND NODE\nC\t NP, OR 0 IF NP = 0.\nC\nC MODULES REQUIRED BY GETNP2 -- NONE\nC\nC INTRINSIC FUNCTIONS CALLED BY GETNP2 -- IABS, IFIX, SQRT\nC\nC***********************************************************\nC\n LOGICAL FIRST\n XP = PX\n YP = PY\nC\nC TEST FOR INVALID INPUT PARAMETERS.\nC\n IF (NR .LT. 1 .OR. DX .LE. 0. .OR. DY .LE. 0.)\n . GO TO 9\nC\nC INITIALIZE PARAMETERS --\nC\nC FIRST = TRUE IFF THE FIRST UNMARKED NODE HAS YET TO BE\nC\t ENCOUNTERED,\nC IMIN,IMAX,JMIN,JMAX = CELL INDICES DEFINING THE RANGE OF\nC\t\t\t THE SEARCH,\nC DELX,DELY = PX-XMIN AND PY-YMIN,\nC I0,J0 = CELL CONTAINING OR CLOSEST TO P,\nC I1,I2,J1,J2 = CELL INDICES OF THE LAYER WHOSE INTERSEC-\nC\t\t TION WITH THE RANGE DEFINED BY IMIN,...,\nC\t\t JMAX IS CURRENTLY BEING SEARCHED.\nC\n FIRST = .TRUE.\n IMIN = 1\n IMAX = NR\n JMIN = 1\n JMAX = NR\n DELX = XP - XMIN\n DELY = YP - YMIN\n I0 = IFIX(DELX/DX) + 1\n IF (I0 .LT. 1) I0 = 1\n IF (I0 .GT. NR) I0 = NR\n J0 = IFIX(DELY/DY) + 1\n IF (J0 .LT. 1) J0 = 1\n IF (J0 .GT. NR) J0 = NR\n I1 = I0\n I2 = I0\n J1 = J0\n J2 = J0\nC\nC OUTER LOOP ON LAYERS, INNER LOOP ON LAYER CELLS, EXCLUDING\nC THOSE OUTSIDE THE RANGE (IMIN,IMAX) X (JMIN,JMAX).\nC\n 1 DO 6 J = J1,J2\n\tIF (J .GT. JMAX) GO TO 7\n\tIF (J .LT. JMIN) GO TO 6\n\tDO 5 I = I1,I2\n\t IF (I .GT. IMAX) GO TO 6\n\t IF (I .LT. IMIN) GO TO 5\n\t IF (J .NE. J1 .AND. J .NE. J2 .AND. I .NE. I1\n . .AND. I .NE. I2) GO TO 5\nC\nC SEARCH CELL (I,J) FOR UNMARKED NODES L.\nC\n\t L = LCELL(I,J)\n\t IF (L .EQ. 0) GO TO 5\nC\nC LOOP ON NODES IN CELL (I,J).\nC\n 2\t LN = LNEXT(L)\n\t IF (LN .LT. 0) GO TO 4\nC\nC NODE L IS NOT MARKED.\nC\n\t RSQ = (X(L)-XP)**2 + (Y(L)-YP)**2\n\t IF (.NOT. FIRST) GO TO 3\nC\nC NODE L IS THE FIRST UNMARKED NEIGHBOR OF P ENCOUNTERED.\nC INITIALIZE LMIN TO THE CURRENT CANDIDATE FOR NP, AND\nC RSMIN TO THE SQUARED DISTANCE FROM P TO LMIN. IMIN,\nC IMAX, JMIN, AND JMAX ARE UPDATED TO DEFINE THE SMAL-\nC LEST RECTANGLE CONTAINING A CIRCLE OF RADIUS R =\nC SQRT(RSMIN) CENTERED AT P, AND CONTAINED IN (1,NR) X\nC (1,NR) (EXCEPT THAT, IF P IS OUTSIDE THE RECTANGLE\nC DEFINED BY THE NODES, IT IS POSSIBLE THAT IMIN .GT.\nC NR, IMAX .LT. 1, JMIN .GT. NR, OR JMAX .LT. 1). FIRST\nC IS RESET TO FALSE.\nC\n\t LMIN = L\n\t RSMIN = RSQ\n\t R = SQRT(RSMIN)\n\t IMIN = IFIX((DELX-R)/DX) + 1\n\t IF (IMIN .LT. 1) IMIN = 1\n\t IMAX = IFIX((DELX+R)/DX) + 1\n\t IF (IMAX .GT. NR) IMAX = NR\n\t JMIN = IFIX((DELY-R)/DY) + 1\n\t IF (JMIN .LT. 1) JMIN = 1\n\t JMAX = IFIX((DELY+R)/DY) + 1\n\t IF (JMAX .GT. NR) JMAX = NR\n\t FIRST = .FALSE.\n\t GO TO 4\nC\nC TEST FOR NODE L CLOSER THAN LMIN TO P.\nC\n 3\t IF (RSQ .GE. RSMIN) GO TO 4\nC\nC UPDATE LMIN AND RSMIN.\nC\n\t LMIN = L\n\t RSMIN = RSQ\nC\nC TEST FOR TERMINATION OF LOOP ON NODES IN CELL (I,J).\nC\n 4\t IF (IABS(LN) .EQ. L) GO TO 5\n\t L = IABS(LN)\n\t GO TO 2\n 5\t CONTINUE\n 6\tCONTINUE\nC\nC TEST FOR TERMINATION OF LOOP ON CELL LAYERS.\nC\n 7 IF (I1 .LE. IMIN .AND. I2 .GE. IMAX .AND.\n . J1 .LE. JMIN .AND. J2 .GE. JMAX) GO TO 8\n I1 = I1 - 1\n I2 = I2 + 1\n J1 = J1 - 1\n J2 = J2 + 1\n GO TO 1\nC\nC UNLESS NO UNMARKED NODES WERE ENCOUNTERED, LMIN IS THE\nC CLOSEST UNMARKED NODE TO P.\nC\n 8 IF (FIRST) GO TO 9\n NP = LMIN\n DSQ = RSMIN\n LNEXT(LMIN) = -LNEXT(LMIN)\n RETURN\nC\nC ERROR -- NR, DX, OR DY IS INVALID OR ALL NODES ARE MARKED.\nC\n 9 NP = 0\n DSQ = 0.\n RETURN\n END\n SUBROUTINE GIVENS ( A,B, C,S)\n REAL A, B, C, S\nC\nC***********************************************************\nC\nC\t\t\t\t\t\tROBERT RENKA\nC\t\t\t\t\tUNIV. OF NORTH TEXAS\nC\t\t\t\t\t (817) 565-2767\nC\nC THIS ROUTINE CONSTRUCTS THE GIVENS PLANE ROTATION --\nC ( C S)\nC G = ( ) WHERE C*C + S*S = 1 -- WHICH ZEROS THE SECOND\nC (-S C)\nC ENTRY OF THE 2-VECTOR (A B)-TRANSPOSE. A CALL TO GIVENS\nC IS NORMALLY FOLLOWED BY A CALL TO ROTATE WHICH APPLIES\nC THE TRANSFORMATION TO A 2 BY N MATRIX. THIS ROUTINE WAS\nC TAKEN FROM LINPACK.\nC\nC ON INPUT --\nC\nC\tA,B = COMPONENTS OF THE 2-VECTOR TO BE ROTATED.\nC\nC ON OUTPUT --\nC\nC\tA = VALUE OVERWRITTEN BY R = +/-SQRT(A*A + B*B)\nC\nC\tB = VALUE OVERWRITTEN BY A VALUE Z WHICH ALLOWS C\nC\t AND S TO BE RECOVERED AS FOLLOWS --\nC\t C = SQRT(1-Z*Z), S=Z IF ABS(Z) .LE. 1.\nC\t C = 1/Z, S = SQRT(1-C*C) IF ABS(Z) .GT. 1.\nC\nC\tC = +/-(A/R)\nC\nC\tS = +/-(B/R)\nC\nC MODULES REQUIRED BY GIVENS -- NONE\nC\nC INTRINSIC FUNCTIONS CALLED BY GIVENS - ABS, SQRT\nC\nC***********************************************************\nC\n REAL AA, BB, R, U, V\nC\nC LOCAL PARAMETERS --\nC\nC AA,BB = LOCAL COPIES OF A AND B\nC R =\t C*A + S*B = +/-SQRT(A*A+B*B)\nC U,V = VARIABLES USED TO SCALE A AND B FOR COMPUTING R\nC\n AA = A\n BB = B\n IF (ABS(AA) .LE. ABS(BB)) GO TO 1\nC\nC ABS(A) .GT. ABS(B)\nC\n U = AA + AA\n V = BB/U\n R = SQRT(.25 + V*V) * U\n C = AA/R\n S = V * (C + C)\nC\nC NOTE THAT R HAS THE SIGN OF A, C .GT. 0, AND S HAS\nC SIGN(A)*SIGN(B).\nC\n B = S\n A = R\n RETURN\nC\nC ABS(A) .LE. ABS(B)\nC\n 1 IF (BB .EQ. 0.) GO TO 2\n U = BB + BB\n V = AA/U\nC\nC STORE R IN A.\nC\n A = SQRT(.25 + V*V) * U\n S = BB/A\n C = V * (S + S)\nC\nC NOTE THAT R HAS THE SIGN OF B, S .GT. 0, AND C HAS\nC SIGN(A)*SIGN(B).\nC\n B = 1.\n IF (C .NE. 0.) B = 1./C\n RETURN\nC\nC A = B = 0.\nC\n 2 C = 1.\n S = 0.\n RETURN\n END\n SUBROUTINE ROTATE (N,C,S, X,Y )\n INTEGER N\n REAL C, S, X(N), Y(N)\nC\nC***********************************************************\nC\nC\t\t\t\t\t\tROBERT RENKA\nC\t\t\t\t\tUNIV. OF NORTH TEXAS\nC\t\t\t\t\t (817) 565-2767\nC\nC\t\t\t\t\t ( C S)\nC THIS ROUTINE APPLIES THE GIVENS ROTATION (\t ) TO THE\nC\t\t\t\t\t (-S C)\nC\t\t(X(1) ... X(N))\nC 2 BY N MATRIX (\t ).\nC\t\t(Y(1) ... Y(N))\nC\nC ON INPUT --\nC\nC\tN = NUMBER OF COLUMNS TO BE ROTATED.\nC\nC\tC,S = ELEMENTS OF THE GIVENS ROTATION. THESE MAY BE\nC\t DETERMINED BY SUBROUTINE GIVENS.\nC\nC\tX,Y = ARRAYS OF LENGTH .GE. N CONTAINING THE VECTORS\nC\t TO BE ROTATED.\nC\nC PARAMETERS N, C, AND S ARE NOT ALTERED BY THIS ROUTINE.\nC\nC ON OUTPUT --\nC\nC\tX,Y = ROTATED VECTORS.\nC\nC MODULES REQUIRED BY ROTATE -- NONE\nC\nC***********************************************************\nC\n INTEGER I\n REAL XI, YI\nC\nC LOCAL PARAMETERS --\nC\nC I =\t DO-LOOP INDEX\nC XI,YI = X(I), Y(I)\nC\n IF (N .LE. 0 .OR. (C .EQ. 1. .AND. S .EQ. 0.)) RETURN\n DO 1 I = 1,N\n\tXI = X(I)\n\tYI = Y(I)\n\tX(I) = C*XI + S*YI\n\tY(I) = -S*XI + C*YI\n 1\tCONTINUE\n RETURN\n END\n SUBROUTINE SETUP2 (XK,YK,FK,XI,YI,FI,S1,S2,R, ROW)\n REAL XK, YK, FK, XI, YI, FI, S1, S2, R, ROW(6)\nC\nC***********************************************************\nC\nC\t\t\t\t\t\tROBERT RENKA\nC\t\t\t\t\tUNIV. OF NORTH TEXAS\nC\t\t\t\t\t (817) 565-2767\nC\nC THIS ROUTINE SETS UP THE I-TH ROW OF AN AUGMENTED RE-\nC GRESSION MATRIX FOR A WEIGHTED LEAST-SQUARES FIT OF A\nC QUADRATIC FUNCTION Q(X,Y) TO A SET OF DATA VALUES F, WHERE\nC Q(XK,YK) = FK. THE FIRST 3 COLUMNS (QUADRATIC TERMS) ARE\nC SCALED BY 1/S2 AND THE FOURTH AND FIFTH COLUMNS (LINEAR\nC TERMS) ARE SCALED BY 1/S1. THE WEIGHT IS (R-D)/(R*D) IF\nC R .GT. D AND 0 IF R .LE. D, WHERE D IS THE DISTANCE\nC BETWEEN NODES I AND K.\nC\nC ON INPUT --\nC\nC\tXK,YK,FK = COORDINATES AND DATA VALUE AT NODE K --\nC\t\t INTERPOLATED BY Q.\nC\nC\tXI,YI,FI = COORDINATES AND DATA VALUE AT NODE I.\nC\nC\tS1,S2 = RECIPROCALS OF THE SCALE FACTORS.\nC\nC\tR = RADIUS OF INFLUENCE ABOUT NODE K DEFINING THE\nC\t WEIGHT.\nC\nC\tROW = ARRAY OF LENGTH 6.\nC\nC INPUT PARAMETERS ARE NOT ALTERED BY THIS ROUTINE.\nC\nC ON OUTPUT --\nC\nC\tROW = VECTOR CONTAINING A ROW OF THE AUGMENTED\nC\t REGRESSION MATRIX.\nC\nC MODULES REQUIRED BY SETUP2 -- NONE\nC\nC INTRINSIC FUNCTION CALLED BY SETUP2 -- SQRT\nC\nC***********************************************************\nC\n INTEGER I\n REAL DX, DY, DXSQ, DYSQ, D, W, W1, W2\nC\nC LOCAL PARAMETERS -\nC\nC I =\t DO-LOOP INDEX\nC DX =\t XI - XK\nC DY =\t YI - YK\nC DXSQ = DX*DX\nC DYSQ = DY*DY\nC D =\t DISTANCE BETWEEN NODES K AND I\nC W =\t WEIGHT ASSOCIATED WITH THE ROW\nC W1 =\t W/S1\nC W2 =\t W/S2\nC\n DX = XI - XK\n DY = YI - YK\n DXSQ = DX*DX\n DYSQ = DY*DY\n D = SQRT(DXSQ + DYSQ)\n IF (D .LE. 0. .OR. D .GE. R) GO TO 1\n W = (R-D)/R/D\n W1 = W/S1\n W2 = W/S2\n ROW(1) = DXSQ*W2\n ROW(2) = DX*DY*W2\n ROW(3) = DYSQ*W2\n ROW(4) = DX*W1\n ROW(5) = DY*W1\n ROW(6) = (FI - FK)*W\n RETURN\nC\nC NODES K AND I COINCIDE OR NODE I IS OUTSIDE OF THE RADIUS\nC OF INFLUENCE. SET ROW TO THE ZERO VECTOR.\nC\n 1 DO 2 I = 1,6\n 2\tROW(I) = 0.\n RETURN\n END\n SUBROUTINE STORE2 (N,X,Y,NR, LCELL,LNEXT,XMIN,YMIN,DX,\n . DY,IER)\n INTEGER N, NR, LCELL(NR,NR), LNEXT(N), IER\n REAL X(N), Y(N), XMIN, YMIN, DX, DY\nC\nC***********************************************************\nC\nC\t\t\t\t\t\tROBERT RENKA\nC\t\t\t\t\tUNIV. OF NORTH TEXAS\nC\t\t\t\t\t (817) 565-2767\nC\nC GIVEN A SET OF N ARBITRARILY DISTRIBUTED NODES IN THE\nC PLANE, THIS SUBROUTINE CREATES A DATA STRUCTURE FOR A\nC CELL-BASED METHOD OF SOLVING CLOSEST-POINT PROBLEMS. THE\nC SMALLEST RECTANGLE CONTAINING THE NODES IS PARTITIONED\nC INTO AN NR BY NR UNIFORM GRID OF CELLS, AND NODES ARE AS-\nC SOCIATED WITH CELLS. IN PARTICULAR, THE DATA STRUCTURE\nC STORES THE INDICES OF THE NODES CONTAINED IN EACH CELL.\nC FOR A UNIFORM RANDOM DISTRIBUTION OF NODES, THE NEAREST\nC NODE TO AN ARBITRARY POINT CAN BE DETERMINED IN CONSTANT\nC EXPECTED TIME.\nC\nC ON INPUT --\nC\nC\tN = NUMBER OF NODES. N .GE. 2.\nC\nC\tX,Y = ARRAYS OF LENGTH N CONTAINING THE CARTESIAN\nC\t COORDINATES OF THE NODES.\nC\nC\tNR = NUMBER OF ROWS AND COLUMNS IN THE GRID. THE\nC\t CELL DENSITY (AVERAGE NUMBER OF NODES PER CELL)\nC\t IS D = N/(NR**2). A RECOMMENDED VALUE, BASED\nC\t ON EMPIRICAL EVIDENCE, IS D = 3 -- NR =\nC\t SQRT(N/3). NR .GE. 1.\nC\nC THE ABOVE PARAMETERS ARE NOT ALTERED BY THIS ROUTINE.\nC\nC\tLCELL = ARRAY OF LENGTH .GE. NR**2.\nC\nC\tLNEXT = ARRAY OF LENGTH .GE. N.\nC\nC ON OUTPUT --\nC\nC\tLCELL = NR BY NR CELL ARRAY SUCH THAT LCELL(I,J)\nC\t\tCONTAINS THE INDEX (FOR X AND Y) OF THE\nC\t\tFIRST NODE (NODE WITH SMALLEST INDEX) IN\nC\t\tCELL (I,J), OR LCELL(I,J) = 0 IF NO NODES\nC\t\tARE CONTAINED IN THE CELL. THE UPPER RIGHT\nC\t\tCORNER OF CELL (I,J) HAS COORDINATES (XMIN+\nC\t\tI*DX,YMIN+J*DY). LCELL IS NOT DEFINED IF\nC\t\tIER .NE. 0.\nC\nC\tLNEXT = ARRAY OF NEXT-NODE INDICES SUCH THAT\nC\t\tLNEXT(K) CONTAINS THE INDEX OF THE NEXT NODE\nC\t\tIN THE CELL WHICH CONTAINS NODE K, OR\nC\t\tLNEXT(K) = K IF K IS THE LAST NODE IN THE\nC\t\tCELL FOR K = 1,...,N. (THE NODES CONTAINED\nC\t\tIN A CELL ARE ORDERED BY THEIR INDICES.)\nC\t\tIF, FOR EXAMPLE, CELL (I,J) CONTAINS NODES\nC\t\t2, 3, AND 5 (AND NO OTHERS), THEN LCELL(I,J)\nC\t\t= 2, LNEXT(2) = 3, LNEXT(3) = 5, AND\nC\t\tLNEXT(5) = 5. LNEXT IS NOT DEFINED IF\nC\t\tIER .NE. 0.\nC\nC\tXMIN,YMIN = CARTESIAN COORDINATES OF THE LOWER LEFT\nC\t\t CORNER OF THE RECTANGLE DEFINED BY THE\nC\t\t NODES (SMALLEST NODAL COORDINATES) UN-\nC\t\t LESS IER = 1. THE UPPER RIGHT CORNER IS\nC\t\t (XMAX,YMAX) FOR XMAX = XMIN + NR*DX AND\nC\t\t YMAX = YMIN + NR*DY.\nC\nC\tDX,DY = DIMENSIONS OF THE CELLS UNLESS IER = 1. DX\nC\t\t= (XMAX-XMIN)/NR AND DY = (YMAX-YMIN)/NR\nC\t\tWHERE XMIN, XMAX, YMIN, AND YMAX ARE THE\nC\t\tEXTREMA OF X AND Y.\nC\nC\tIER = ERROR INDICATOR --\nC\t IER = 0 IF NO ERRORS WERE ENCOUNTERED.\nC\t IER = 1 IF N .LT. 2 OR NR .LT. 1.\nC\t IER = 2 IF DX = 0 OR DY = 0.\nC\nC MODULES REQUIRED BY STORE2 -- NONE\nC\nC INTRINSIC FUNCTIONS CALLED BY STORE2 -- FLOAT, IFIX\nC\nC***********************************************************\nC\n NN = N\n NNR = NR\n IF (NN .LT. 2 .OR. NNR .LT. 1) GO TO 4\nC\nC COMPUTE THE DIMENSIONS OF THE RECTANGLE CONTAINING THE\nC NODES.\nC\n XMN = X(1)\n XMX = XMN\n YMN = Y(1)\n YMX = YMN\n DO 1 K = 2,NN\n\tIF (X(K) .LT. XMN) XMN = X(K)\n\tIF (X(K) .GT. XMX) XMX = X(K)\n\tIF (Y(K) .LT. YMN) YMN = Y(K)\n 1\tIF (Y(K) .GT. YMX) YMX = Y(K)\n XMIN = XMN\n YMIN = YMN\nC\nC COMPUTE CELL DIMENSIONS AND TEST FOR ZERO AREA.\nC\n DELX = (XMX-XMN)/FLOAT(NNR)\n DELY = (YMX-YMN)/FLOAT(NNR)\n DX = DELX\n DY = DELY\n IF (DELX .EQ. 0. .OR. DELY .EQ. 0.) GO TO 5\nC\nC INITIALIZE LCELL.\nC\n DO 2 J = 1,NNR\n\tDO 2 I = 1,NNR\n 2\t LCELL(I,J) = 0\nC\nC LOOP ON NODES, STORING INDICES IN LCELL AND LNEXT.\nC\n NP1 = NN + 1\n DO 3 K = 1,NN\n\tKB = NP1 - K\n\tI = IFIX((X(KB)-XMN)/DELX) + 1\n\tIF (I .GT. NNR) I = NNR\n\tJ = IFIX((Y(KB)-YMN)/DELY) + 1\n\tIF (J .GT. NNR) J = NNR\n\tL = LCELL(I,J)\n\tLNEXT(KB) = L\n\tIF (L .EQ. 0) LNEXT(KB) = KB\n 3\tLCELL(I,J) = KB\nC\nC NO ERRORS ENCOUNTERED\nC\n IER = 0\n RETURN\nC\nC INVALID INPUT PARAMETER\nC\n 4 IER = 1\n RETURN\nC\nC DX = 0 OR DY = 0\nC\n 5 IER = 2\n RETURN\n END\n", "meta": {"hexsha": "d6250c1ddbdb8a0af23e54bbe0a9e7b4183864f9", "size": 41282, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "smrf/spatial/sheppard.f90", "max_stars_repo_name": "scotthavens/smrf", "max_stars_repo_head_hexsha": "a492d01a5eef994e00728c1cbed9f693879bbade", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2017-10-26T20:15:53.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-07T02:16:14.000Z", "max_issues_repo_path": "smrf/spatial/sheppard.f90", "max_issues_repo_name": "scotthavens/smrf", "max_issues_repo_head_hexsha": "a492d01a5eef994e00728c1cbed9f693879bbade", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 187, "max_issues_repo_issues_event_min_datetime": "2017-09-19T20:56:47.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-15T15:50:32.000Z", "max_forks_repo_path": "smrf/spatial/sheppard.f90", "max_forks_repo_name": "UofU-Cryosphere/smrf", "max_forks_repo_head_hexsha": "a6f13080e7fc99be5e238f4542ae7ea8974fda15", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2019-09-30T21:01:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-27T22:07:49.000Z", "avg_line_length": 27.3390728477, "max_line_length": 68, "alphanum_fraction": 0.5903541495, "num_tokens": 16410, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430520409023, "lm_q2_score": 0.787931190663057, "lm_q1q2_score": 0.6548835346059153}} {"text": "program test\n integer :: a(10, 10), b(10,10), c(10, 10)\n integer:: i = 1,j =1\n \n do while (i <= 10)\n j = 1\n do while (j <= 10)\n a(j,i) = i\n b(j,i) = j\n j = j + 1\n end do\n i = i + 1\n end do\n \n i = 1\n do while (i <= 10)\n j = 1\n do while (j <= 10)\n c(j,i) = a(j,i) + b(j,i)\n j = j + 1\n end do\n i = i + 1\n end do\n \n print *, c\nend program test\n", "meta": {"hexsha": "4a8b8348d0deed4ce7bd4a31be18b1bdfefe25b4", "size": 399, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/output_tests/2d_array_sum.f90", "max_stars_repo_name": "clementval/fc", "max_stars_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/output_tests/2d_array_sum.f90", "max_issues_repo_name": "clementval/fc", "max_issues_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/output_tests/2d_array_sum.f90", "max_forks_repo_name": "clementval/fc", "max_forks_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "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": 14.7777777778, "max_line_length": 43, "alphanum_fraction": 0.3984962406, "num_tokens": 179, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428946, "lm_q2_score": 0.8311430436757312, "lm_q1q2_score": 0.6548835321536934}} {"text": " SUBROUTINE DE01PD( CONV, WGHT, N, A, B, W, INFO )\r\nC\r\nC SLICOT RELEASE 5.5.\r\nC\r\nC Copyright (c) 2002-2012 NICONET e.V.\r\nC\r\nC PURPOSE\r\nC\r\nC To compute the convolution or deconvolution of two real signals\r\nC A and B using the Hartley transform.\r\nC\r\nC ARGUMENTS\r\nC\r\nC Mode Parameters\r\nC\r\nC CONV CHARACTER*1\r\nC Indicates whether convolution or deconvolution is to be\r\nC performed as follows:\r\nC = 'C': Convolution;\r\nC = 'D': Deconvolution.\r\nC\r\nC WGHT CHARACTER*1\r\nC Indicates whether the precomputed weights are available\r\nC or not, as follows:\r\nC = 'A': available;\r\nC = 'N': not available.\r\nC Note that if N > 1 and WGHT = 'N' on entry, then WGHT is\r\nC set to 'A' on exit.\r\nC\r\nC Input/Output Parameters\r\nC\r\nC N (input) INTEGER\r\nC The number of samples. N must be a power of 2. N >= 0.\r\nC\r\nC A (input/output) DOUBLE PRECISION array, dimension (N)\r\nC On entry, this array must contain the first signal.\r\nC On exit, this array contains the convolution (if\r\nC CONV = 'C') or deconvolution (if CONV = 'D') of the two\r\nC signals.\r\nC\r\nC B (input) DOUBLE PRECISION array, dimension (N)\r\nC On entry, this array must contain the second signal.\r\nC NOTE that this array is overwritten.\r\nC\r\nC W (input/output) DOUBLE PRECISION array,\r\nC dimension (N - LOG2(N))\r\nC On entry with WGHT = 'A', this array must contain the long\r\nC weight vector computed by a previous call of this routine\r\nC or of the SLICOT Library routine DG01OD.f, with the same\r\nC value of N. If WGHT = 'N', the contents of this array on\r\nC entry is ignored.\r\nC On exit, this array contains the long weight vector.\r\nC\r\nC Error Indicator\r\nC\r\nC INFO INTEGER\r\nC = 0: successful exit;\r\nC < 0: if INFO = -i, the i-th argument had an illegal\r\nC value.\r\nC\r\nC METHOD\r\nC\r\nC This routine computes the convolution or deconvolution of two\r\nC real signals A and B using three scrambled Hartley transforms\r\nC (SLICOT Library routine DG01OD).\r\nC\r\nC REFERENCES\r\nC\r\nC [1] Van Loan, Charles.\r\nC Computational frameworks for the fast Fourier transform.\r\nC SIAM, 1992.\r\nC\r\nC NUMERICAL ASPECTS\r\nC\r\nC The algorithm requires O(N log(N)) floating point operations.\r\nC\r\nC CONTRIBUTOR\r\nC\r\nC D. Kressner, Technical Univ. Berlin, Germany, April 2001.\r\nC\r\nC REVISIONS\r\nC\r\nC V. Sima, Research Institute for Informatics, Bucharest, Apr. 2000.\r\nC\r\nC KEYWORDS\r\nC\r\nC Convolution, deconvolution, digital signal processing,\r\nC fast Hartley transform, real signals.\r\nC\r\nC ******************************************************************\r\nC\r\nC .. Parameters ..\r\n DOUBLE PRECISION HALF, TWO\r\n PARAMETER ( HALF = 0.5D0, TWO = 2.0D0 )\r\nC .. Scalar Arguments ..\r\n CHARACTER CONV, WGHT\r\n INTEGER INFO, N\r\nC .. Array Arguments ..\r\n DOUBLE PRECISION A(*), B(*), W(*)\r\nC .. Local Scalars ..\r\n LOGICAL LCONV, LWGHT\r\n INTEGER J, L, LEN, M, P1, R1\r\n DOUBLE PRECISION T1, T2, T3\r\nC .. External Functions ..\r\n LOGICAL LSAME\r\n EXTERNAL LSAME\r\nC .. External Subroutines ..\r\n EXTERNAL DG01OD, DLADIV, DSCAL, XERBLA\r\nC .. Intrinsic Functions ..\r\n INTRINSIC DBLE, MOD\r\nC .. Executable Statements ..\r\nC\r\n INFO = 0\r\n LCONV = LSAME( CONV, 'C' )\r\n LWGHT = LSAME( WGHT, 'A' )\r\nC\r\nC Test the input scalar arguments.\r\nC\r\n IF( .NOT.LCONV .AND. .NOT.LSAME( CONV, 'D' ) ) THEN\r\n INFO = -1\r\n ELSE IF( .NOT.LWGHT .AND. .NOT.LSAME( WGHT, 'N' ) ) THEN\r\n INFO = -2\r\n ELSE\r\n M = 0\r\n J = 0\r\n IF( N.GE.1 ) THEN\r\n J = N\r\nC WHILE ( MOD( J, 2 ).EQ.0 ) DO\r\n 10 CONTINUE\r\n IF ( MOD( J, 2 ).EQ.0 ) THEN\r\n J = J/2\r\n M = M + 1\r\n GO TO 10\r\n END IF\r\nC END WHILE 10\r\n IF ( J.NE.1 ) INFO = -3\r\n ELSE IF ( N.LT.0 ) THEN\r\n INFO = -3\r\n END IF\r\n END IF\r\nC\r\n IF ( INFO.NE.0 ) THEN\r\nC\r\nC Error return.\r\nC\r\n CALL XERBLA( 'DE01PD', -INFO )\r\n RETURN\r\n END IF\r\nC\r\nC Quick return if possible.\r\nC\r\n IF ( N.LE.0 ) THEN\r\n RETURN\r\n ELSE IF ( N.EQ.1 ) THEN\r\n IF ( LCONV ) THEN\r\n A(1) = A(1)*B(1)\r\n ELSE\r\n A(1) = A(1)/B(1)\r\n END IF\r\n RETURN\r\n END IF\r\nC\r\nC Scrambled Hartley transforms of A and B.\r\nC\r\n CALL DG01OD( 'OutputScrambled', WGHT, N, A, W, INFO )\r\n CALL DG01OD( 'OutputScrambled', WGHT, N, B, W, INFO )\r\nC\r\nC Something similar to a Hadamard product/quotient.\r\nC\r\n LEN = 1\r\n IF( LCONV ) THEN\r\n A(1) = TWO*A(1)*B(1)\r\n A(2) = TWO*A(2)*B(2)\r\nC\r\n DO 30 L = 1, M - 1\r\n LEN = 2*LEN\r\n R1 = 2*LEN\r\nC\r\n DO 20 P1 = LEN + 1, LEN + LEN/2\r\n T1 = B(P1) + B(R1)\r\n T2 = B(P1) - B(R1)\r\n T3 = T2*A(P1)\r\n A(P1) = T1*A(P1) + T2*A(R1)\r\n A(R1) = T1*A(R1) - T3\r\n R1 = R1 - 1\r\n 20 CONTINUE\r\nC\r\n 30 CONTINUE\r\nC\r\n ELSE\r\nC\r\n A(1) = HALF*A(1)/B(1)\r\n A(2) = HALF*A(2)/B(2)\r\nC\r\n DO 50 L = 1, M - 1\r\n LEN = 2*LEN\r\n R1 = 2*LEN\r\nC\r\n DO 40 P1 = LEN + 1, LEN + LEN/2\r\n CALL DLADIV( A(P1), A(R1), B(P1)+B(R1), B(R1)-B(P1), T1,\r\n $ T2 )\r\n A(P1) = T1\r\n A(R1) = T2\r\n R1 = R1 - 1\r\n 40 CONTINUE\r\nC\r\n 50 CONTINUE\r\nC\r\n END IF\r\nC\r\nC Transposed Hartley transform of A.\r\nC\r\n CALL DG01OD( 'InputScrambled', WGHT, N, A, W, INFO )\r\n IF ( LCONV ) THEN\r\n CALL DSCAL( N, HALF/DBLE( N ), A, 1 )\r\n ELSE\r\n CALL DSCAL( N, TWO/DBLE( N ), A, 1 )\r\n END IF\r\nC\r\n RETURN\r\nC *** Last line of DE01PD ***\r\n END\r\n", "meta": {"hexsha": "f22f7861fce9d46052219bc65e206e8427017c42", "size": 6348, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "External/SLICOT/DE01PD.f", "max_stars_repo_name": "bgin/MissileSimulation", "max_stars_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2016-08-28T23:20:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-15T14:43:58.000Z", "max_issues_repo_path": "External/SLICOT/DE01PD.f", "max_issues_repo_name": "bgin/MissileSimulation", "max_issues_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-06-02T21:29:51.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-05T05:59:31.000Z", "max_forks_repo_path": "External/SLICOT/DE01PD.f", "max_forks_repo_name": "bgin/MissileSimulation", "max_forks_repo_head_hexsha": "90adcbf1c049daafb939f3fe9f9dfe792f26d5df", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-07-04T22:38:22.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-04T22:38:22.000Z", "avg_line_length": 28.466367713, "max_line_length": 73, "alphanum_fraction": 0.486294896, "num_tokens": 1942, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312226373181, "lm_q2_score": 0.7217432182679956, "lm_q1q2_score": 0.6548464462364798}} {"text": " subroutine csroot(xr,xi,yr,yi)\n double precision xr,xi,yr,yi\nc\nc (yr,yi) = complex dsqrt(xr,xi) \nc branch chosen so that yr .ge. 0.0 and sign(yi) .eq. sign(xi)\nc\n double precision s,tr,ti,pythag\n tr = xr\n ti = xi\n s = dsqrt(0.5d0*(pythag(tr,ti) + dabs(tr)))\n if (tr .ge. 0.0d0) yr = s\n if (ti .lt. 0.0d0) s = -s\n if (tr .le. 0.0d0) yi = s\n if (tr .lt. 0.0d0) yr = 0.5d0*(ti/yi)\n if (tr .gt. 0.0d0) yi = 0.5d0*(ti/yr)\n return\n end\n", "meta": {"hexsha": "fd04b307685082c2c329ef092829c4bae3cf8b5a", "size": 504, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "eispack/csroot.f", "max_stars_repo_name": "mmoeller86/kingmatrix", "max_stars_repo_head_hexsha": "9bfe6688ba904a414bac5db5ce59405803e563c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "eispack/csroot.f", "max_issues_repo_name": "mmoeller86/kingmatrix", "max_issues_repo_head_hexsha": "9bfe6688ba904a414bac5db5ce59405803e563c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "eispack/csroot.f", "max_forks_repo_name": "mmoeller86/kingmatrix", "max_forks_repo_head_hexsha": "9bfe6688ba904a414bac5db5ce59405803e563c0", "max_forks_repo_licenses": ["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.0, "max_line_length": 66, "alphanum_fraction": 0.5138888889, "num_tokens": 229, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122313857379, "lm_q2_score": 0.7217432062975979, "lm_q1q2_score": 0.6548464389933706}} {"text": "module supercell\n use linalg, only: determinant_3x3_real, frobnorm_3x3_real, matinv3x3\n\n contains\n\n !> Compute deviation from the target metric, given that cell is normed\n pure function get_deviation(cell, target_metric, norm) result(deviation)\n real*8, dimension(3,3), intent(in) :: cell\n real*8, dimension(3,3), intent(in) :: target_metric\n logical, optional, intent(in) :: norm\n logical :: nrm\n real*8 :: ncell(3,3)\n\n nrm = .true.\n if (present(norm)) nrm = norm\n\n ! Normalize the input lattice\n if (nrm) then\n ncell = cell * (determinant_3x3_real(cell) / determinant_3x3_real(target_metric))**(-1./3.)\n else\n ncell = cell\n end if\n\n deviation = frobnorm_3x3_real(ncell - target_metric)\n\n end function\n\n !> Find optimal supercell matrix to realize supercell lattice of given\n !> metric, e.g., cubic.\n function find_optimal_cell(cell, target_metric, target_size, lower_limit, &\n upper_limit, verbose) result(smatrix)\n real*8, intent(in) :: cell(3,3) \n real*8, intent(in) :: target_metric(3,3)\n real*8, intent(in) :: target_size\n integer, intent(in) :: lower_limit, upper_limit\n logical, intent(in) :: verbose\n integer :: smatrix(3,3)\n optional :: lower_limit, upper_limit, verbose\n integer :: llim, ulim \n logical :: vrbs, found\n integer :: i1, i2, i3, i4, i5, i6, i7, i8, i9, nn\n integer :: initial_P(3,3), P(3,3), dP(3,3)\n real*8 :: norm, score, best_score, ideal_P(3,3), ccell(3,3)\n \n ! options and defaults\n llim = -2\n ulim = 2\n vrbs = .false.\n if(present(lower_limit)) llim = lower_limit\n if(present(upper_limit)) ulim = upper_limit\n if(present(verbose)) vrbs = verbose\n\n ! initialize matrices and values\n smatrix = -1\n score = 1.e7\n best_score = 1.e6\n ccell = cell\n found = .false.\n P = 0\n\n if (vrbs) then\n write(*,*) 'Settings:'\n write (*,\"(A,/,3(F7.2))\") 'Input cell: ', cell\n write (*,\"(A,/,3(F7.2))\") 'Target metric:', target_metric\n write (*,\"(A,(F7.2))\") 'Target size: ', target_size\n write (*,\"(A,2(I3))\") 'Limits: ', llim, ulim\n end if\n\n ! Normalize the input lattice\n norm = (target_size * determinant_3x3_real(cell) / determinant_3x3_real(target_metric))**(-1./3.)\n ccell = norm * cell\n\n if (vrbs) write(*,\"(A,(F7.3))\") 'Normalization factor: ', norm\n if (vrbs) write (*,\"(A,/,3(F7.2))\") 'Normed cell: ', ccell\n\n ! Approximate the perfect smatrix\n ideal_P = matmul(target_metric, matinv3x3(ccell))\n initial_P = nint(ideal_P)\n if (vrbs) write (*,\"(A,/,3(F7.3))\") 'Ideal P: ' , ideal_P \n if (vrbs) write (*,\"(A,/,3(I7))\") 'Initial P: ' , initial_P\n\n !> Expand brute force\n do i1=llim, ulim\n do i2=llim, ulim\n do i3=llim, ulim\n do i4=llim, ulim\n do i5=llim, ulim\n do i6=llim, ulim\n do i7=llim, ulim\n do i8=llim, ulim\n do i9=llim, ulim\n dP(1,1:3) = (/ i1, i2, i3 /) \n dP(2,1:3) = (/ i4, i5, i6 /) \n dP(3,1:3) = (/ i7, i8, i9 /)\n P = initial_P + dP\n nn = nint(determinant_3x3_real(real(P, 8)))\n ! Allow up to 20% increase in size from target shape\n if ((nn < target_size ) .or. (nn > 1.2*target_size)) cycle\n score = get_deviation(matmul(ccell, P), target_metric)\n ! Save the result if it was a good one\n if (score < best_score) then\n found = .true.\n best_score = score\n smatrix = P\n end if\n end do\n end do\n end do\n end do\n end do\n end do\n end do\n end do\n end do\n\n if (vrbs) then\n write (*,\"(A,/,(F7.3))\") 'Best score: ' , best_score\n write (*,\"(A,/,3(I7))\") 'P: ' , smatrix\n write (*,\"(A,/,F7.3,I5)\") 'N_target, N:' , target_size, nint(determinant_3x3_real(real(smatrix, 8)))\n end if\n\n if (.not. found) write(*,*) 'No supercell matrix found.'\n\n end function\nend module\n", "meta": {"hexsha": "0f734e9ddac3f5fbbdf33a3e88f326b382a04cff", "size": 4391, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "c_bindings/cffi/supercell.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/supercell.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/supercell.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.8492063492, "max_line_length": 109, "alphanum_fraction": 0.5240264177, "num_tokens": 1389, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480666, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6548464335704774}} {"text": "C----------------------------------------------------------------\nC Set of subroutines used by PATCH1 and PATCH_GRI\nC Version of 20/07/87\nC\nC Warning : if you have error messages like \"FLOATING UNDERFLOW\"\nC don't worry and compile your program with\nC\t the option FORTRAN/CHECK=(NOUNDERFLOW)\nC\nC Contains : NEQSOL,REJECT, and POLY\nC------------------------------------------------------------------\n SUBROUTINE NEQSOL(X,Y,Z,NDIM,NPTS,NTERMS,NOTO,IOOR,D,SE,\n 1 RDOE,SDOR)\nC **************************************************************\nC\nC SUBROUTINE NEQSOL(X,Y,Z,NDIM,NPTS,NTERMS,NOTO,IOOR,D,SE,RDOE,SDOR)\nC\nC THIS SUBROUTINE COMPUTES THE COEFFICIENTS, D, WHICH DEFINE THAT LINEAR\nC FUNCTION, Y, OF LINEARLY INDEPENDENT FUNCTIONS WHICH BEST FITS, IN THE\nC LEAST SQUARES SENSE, A GIVEN SET OF DATA. OR EQUIVALENTLY, IT FINDS\nC THE SOLUTION TO THE SYSTEM OF NORMAL EQUATIONS WHICH IS CALLED THE\nC NORMAL EQUATIONS SOLUTION.\nC\nC WRITTEN AND DOCUMENTED BY:\nC\nC JONES, W B, OBITTS, D L, GALLET, R M, AND DE VAUCOULEURS, G,\nC 'ASTRONOMICAL SURFACE PHOTOMETRY BY NUMERICAL MAPPING\nC TECHNIQUES', PUBLICATION OF THE ASTRONOMY DEPARTMENT, UNIV.\nC OF TEXAS, AUSTIN, SERIES II, VOL. I, NO. 8, FEB. 1967\nC\nC MODIFIED BY W D PENCE, UNIV. OF SUSSEX, SEPT. 1980\nC\nC X(NPTS,2) = COORDINATES OF POINTS: X(I,1) = X COORD. (R*4)\nC X(I,2) = Y COORD. (R*4)\nC Y(NPTS) = VALUE OF POINT AT X(NPTS,1),X(NPTS,2) (R*4)\nC Z = SCRATCH ARRAY (DOUBLE PRECISION, R*8)\nC NDIM = FIRST DIMENSION OF X, Y AND Z (I*4)\nC NPTS = NO. OF POINTS IN LEAST SQUARES FIT (I*4)\nC NTERMS = NO. OF COEFS TO BE SOLVED FOR (I*4)\nC NOTO = NO. OF TOTAL ORTHOGONALIZATIONS TO PERFORM (I*4)\nC IOOR = POSITIVE INTEGER IF OPTIONAL OUTPUT IS REQUIRED\nC D(NTERMS) = COEFFICIENTS OF THE POLYNOMIAL (DOUBLE PRECISION, R*8)\nC Maximum: NTERMS=30\nC SE(K) = RMS OF FIT USING ONLY THE FIRST K COEFFICIENTS (R*8)\nC RDOE(NTERMS) = INDICATES THE STATISTICAL SIGNIFICANCE OF EACH TERM (R*8)\nC SDOR = STANDARD DEVIATION OF RESIDUALS (R*4)\nC VALMINI = SMALLEST VALUE TOLERABLE TO AVOID \"FLOATING UNDERFLOW\"\nC (Be carefull if you increase this value, the fit is bad...)\nC\nC ***************************************************************\n \n IMPLICIT REAL*8 (A-H,O-Z)\n REAL*4 X(NDIM,2),Y(NDIM),SDOR\n REAL*8 Z(NDIM),D(30),SUM\n REAL*8 A(30),AKJ(30,30),AA(30),CE(30),DT(30),DYGC(30)\n REAL*8 GGSQT(30),GG(30,30),Q(30,30,2),RDOE(30),REE(30)\n REAL*8 RREE(30),RYG(30),SD(30),SE(30),S(30,30),YGC(30),YG(30)\n DOUBLE PRECISION POLY\n EXTERNAL POLY\n \n IF(NTERMS.GT.30)THEN\n WRITE(6,*)'NEQSOL/Fatal error: too many terms: NTERMS=',NTERMS\n STOP\n ENDIF\nC Smallest value to avoid floating underflow (in computing products of\nC such values ...)\nC Tried 0.1d-15 too large\nC 0.1d-30 too large (where I use it ...)\nC@\tVALMINI=0.1D-30\n \n GO TO (1,9)NOTO\nC COMPUTE THE SQUARE OF THE NORM OF THE VECTOR OF THE DEPENDENT VARIABLE,\nC COMPUTE THE MEAN OF THE DEPENDENT VARIABLE, YBAR.\n1 FLNPTS=NPTS\n YY=Y(1)*Y(1)\n YBAR=Y(1)\n DO 2 I=2,NPTS\n YY=YY+Y(I)*Y(I)\n2 YBAR=YBAR+Y(I)\nC COMPUTE THE MATRIX OF INNER PRODUCTS OF THE NORMALIZED FITTING FUNCTIONS\n YBAR=YBAR/FLNPTS\n IX=0\n JY=-1\n DO 8 J=1,NTERMS\n IF (IX .NE. 0)THEN\n IX=IX-1\n JY=JY+1\n ELSE\n IX=JY+1\n JY=0\n END IF\n T=0.\n SUM=0.\n DO 4 I=1,NPTS\n GK=1.\n IF (IX .NE. 0) GK=X(I,1)**IX\n IF (JY .NE. 0) GK=GK*X(I,2)**JY\n Z(I)=GK\n T=T+GK*GK\n4 SUM=SUM+Y(I)*GK\n GGSQT(J)=DSQRT(T)\n YG(J)=SUM/GGSQT(J)\n GG(J,J)=1.0\n IF (J-1)8,8,5\n5 KUL=J-1\n IXX=0\n JYY=-1\n DO 7 K=1,KUL\n IF (IXX .NE. 0)THEN\n IXX=IXX-1\n JYY=JYY+1\n ELSE\n IXX=JYY+1\n JYY=0\n END IF\n T=0.\n DO 6 I=1,NPTS\n GK=1.\n IF (IXX .NE. 0) GK=X(I,1)**IXX\n IF (JYY .NE. 0) GK=GK*X(I,2)**JYY\n6 T=T+Z(I)*GK\n GG(J,K)=T/(GGSQT(J)*GGSQT(K))\n7 GG(K,J)=GG(J,K)\n8 CONTINUE\nC COMPUTE THE MATRIX OF COEFFICIENTS, Q, DEFINING THE ORTHOGONAL FUNCTIONS\nC IN TERMS OF THE FITTING FUNCTIONS.\n9 Q(1,1,NOTO)=1.\n S(1,1)=1.\n AA(1)=1.\n GO TO (10,12)NOTO\n10 DO 11 K=2,NTERMS\n AKJ(K,1)=-GG(K,1)\n11 CONTINUE\n GO TO 15\n12 DO 14 K=2,NTERMS\n SUM=0.\n DO 13 J=1,K\n13 SUM=SUM+Q(K,J,1)*GG(J,1)\n14 AKJ(K,1)=-SUM\n15 DO 32 K=2,NTERMS\n Q(K,K,NOTO)=1.\n S(K,K)=1.\n JUL=K-1\n DO 19 J=1,JUL\n GO TO (16,17)NOTO\n16 T=AKJ(K,J)\n GO TO 19\n17 T=0.\n DO 18 L=J,JUL\n18 T=T+AKJ(K,L)*S(L,J)\n19 S(K,J)=T\n DO 23 J=1,JUL\n SUM=0.\n DO 20 L=J,JUL\n20 SUM=SUM+S(K,L)*Q(L,J,1)\n GO TO (21,22)NOTO\n21 Q(K,J,1)=SUM\n GO TO 23\n22 Q(K,J,2)=SUM+Q(K,J,1)\n23 CONTINUE\n SUM=0.\n DO 25 J=1,K\n T=0.\n DO 24 L=1,K\nC COMPUTE THE VECTOR OF THE SQUARE OF THE NORM OF THE ORTHOGONAL FUNCTIONS\n24 T=T+Q(K,L,NOTO)*GG(L,J)\n \nC To avoid floating underflow :\nC\t IF(ABS(T).LT.VALMINI)T=0.\n \n SUM=SUM+Q(K,J,NOTO)*T\n25 CONTINUE\n AA(K)=SUM\n IF (K-NTERMS)26,32,32\n26 KPO=K+1\n DO 31 J=KPO,NTERMS\n SUM=0.\n DO 30 L=1,K\n GO TO (27,28)NOTO\n27 T=GG(J,L)\n GO TO 30\n28 T=0.\n DO 29 M=1,J\n29 T=T+Q(J,M,1)*GG(M,L)\n30 SUM=SUM+Q(K,L,NOTO)*T\n31 AKJ(J,K)=-SUM/AA(K)\n32 CONTINUE\n \nC COMPUTE THE LEAST SQUARES COEFFICIENTS, A, FOR THE SOLUTION IN TERMS OF\nC THE ORTHOGONAL FUNCTIONS.\n DO 34 K=1,NTERMS\n SUM=0.\n DO 33 J=1,K\n33 SUM=SUM+Q(K,J,NOTO)*YG(J)\n A(K)=SUM/AA(K)\nC PRINT *,'JLP2006/ AA(',K,')=',A(K),' SUM=',SUM\n34 CONTINUE\n \nC COMPUTE THE LEAST SQUARES COEFFICIENTS,D, FOR THE SOLUTION IN TERMS OF\nC THE FITTING FUNCTIONS.\n DO 36 K=1,NTERMS\n SUM=0.\n DO 35 J=K,NTERMS\n35 SUM=SUM+Q(J,K,NOTO)*A(J)\n D(K)=SUM/GGSQT(K)\n36 DT(K)=SUM\nC COMPUTE THE STANDARD DEVIATION OF THE RESIDUALS, SDOR.\n SDOR=0.\n DO 38 I=1,NPTS\n SUM=POLY(X(I,1),X(I,2),D)\nC IF(I.LE.5)PRINT *,'Y,X(I,1),X(I,2),SUM',Y(I),X(I,1),\nC 1 X(I,2),SUM\n T=Y(I)-SUM\n SDOR=SDOR+T*T\n38 CONTINUE\n SDOR=DSQRT(SDOR/(FLNPTS-NTERMS))\n IF (IOOR)99,99,39\nC COMPUTE THE OPTIONAL OUTPUT ONLY IF (IOOR) IS POSITIVE.\n39 DO 42 K=1,NTERMS\nC COMPUTE THE CHECK FOR THE CONSISTENCY OF THE COEFFICIENTS D.\n40 Z(K+200)=YG(K)\n SUM=0.\n DO 41 J=1,NTERMS\n SUM=SUM+DT(J)*GG(K,J)\n41 CONTINUE\n YGC(K)=SUM\n DYGC(K)=SUM-YG(K)\n RYG(K)=DYGC(K)/YG(K)\n42 CONTINUE\nC Compute the orthonormal coefficients, the sum of the squares of residuals,\nC the estimates of the standard deviation of the residuals, and the\nC term significance ratio.\n SD(1)=A(1)\n CE(1)=YY-A(1)*A(1)*AA(1)\n DEN=NPTS-1\n SE(1)=DSQRT(CE(1)/DEN)\n RDOE(1)=SD(1)/SE(1)\n DO 50 K=2,NTERMS\n IF (AA(K)) 43,44,45\n43 SD(K)=-DSQRT(-AA(K))*A(K)\n GO TO 46\n44 SD(K)=0.\n GO TO 46\n45 SD(K)=DSQRT(AA(K))*A(K)\n46 CE(K)=CE(K-1)-A(K)*A(K)*AA(K)\n DEN=NPTS-K\n IF (CE(K))47,48,49\n47 SE(K)=-DSQRT(-CE(K)/DEN)\n GO TO 50\n48 SE(K)=1.0E-33\n GO TO 50\n49 SE(K)=DSQRT(CE(K)/DEN)\n50 RDOE(K)=SD(K)/SE(K)\nC COMPUTE THE ESTIMATE OF THE ERROR DUE TO ROUNDING AND THE RELATIVE ERROR\nC IN THE LEAST SQUARES COEFFICIENTS,A.\n DO 60 K=1,NTERMS\n KMO=K-1\n KPO=K+1\n T=0.\nC\n IF (KMO)55,55,51\n51 DO 54 J=1,KMO\n SUM=0.\n DO 53 L=1,J\n T1=0.\n DO 52 M=1,K\n T1=T1+Q(K,M,NOTO)*GG(L,M)\n52 CONTINUE\n SUM=SUM+Q(J,L,NOTO)*T1\n53 CONTINUE\n T=T+A(J)*SUM\n54 CONTINUE\nC\n IF(K-NTERMS)55,59,59\n55 DO 58 J=KPO,NTERMS\n SUM=0.\n DO 57 L=1,J\n T1=0.\n DO 56 M=1,K\n T1=T1+Q(K,M,NOTO)*GG(L,M)\n56 CONTINUE\n SUM=SUM+Q(J,L,NOTO)*T1\n57 CONTINUE\n T=T+A(J)*SUM\n58 CONTINUE\nC\n59 REE(K)=-T/AA(K)\n60 RREE(K)=REE(K)/A(K)\n \n99 CONTINUE\n RETURN\n END\nC-------------------------------------------------------------------------\n SUBROUTINE REJECT(X,Y,NDIM,D,NN,KK,TT,M,J)\nC*****************************************************************\nC\nC SUBROUTINE REJECT(X,Y,NDIM,D,N,K,TT,M,J)\nC\nC WRITTEN BY JONES ET AL., 1967\nC MODIFIED BY W D PENCE, 1980\nC\nC REJECT ANY POINT WHOSE RESIDUAL IS GREATER THAN BETA*SIGMA\nC FROM THE POLYNOMIAL DEFINED BY THE COEFFICIENTS D.\nC\nC X = INDEPENDENT VARIABLE (R*4)\nC Y = THE DEPENDENT VARIABLE (R*4)\nC NDIM = FIRST DIMENSION OF X AND Y (I*4)\nC D(30) = ARRAY CONTAINING THE POLYNOMIAL COEFFICIENTS (R*8)\nC N = NUMBER OF VALUES TO BE TESTED\nC K = THE NUMBER OF TERMS IN THE POLYNOMIAL\nC TT = THE TEST VALUE USED TO SPECIFY THE REJECTION LEVEL\nC M = THE MODIFIED NUMBER OF VALUES AFTER REJECTION\nC J = AN INDICATOR WHICH IS ZERO ONLY ON THE LAST CALL\nC ( THIS PREVENTS ANY POINTS FROM BEING REJECTED)\nC\nC***********************************************************\n REAL*4 X(NDIM,2),Y(NDIM)\n INTEGER*4 INDXP(21),INDXN(21)\n INTEGER*4 KK,M,J,NN\n DOUBLE PRECISION D(30),S\n DOUBLE PRECISION POLY\n EXTERNAL POLY\nC\n N=NN\n T=TT\n AVR=0.\n DO 9 M=1,21\n INDXN(M)=0\n INDXP(M)=0\n9 CONTINUE\n U=0.\n V=0.\n NPOS=0\n NNEG=0\n M=1\n DO 23 I=1,N\n X(M,1)=X(I,1)\n X(M,2)=X(I,2)\n Y(M)=Y(I)\n S=POLY(X(I,1),X(I,2),D)\nC\nC R=RESIDUAL FROM POLYNOMIAL FIT\nC\n R=Y(I)-S\nC IF(I.LE.3)PRINT *,'Y,X(I,1),X(I,2),S',Y(I),X(I,1),X(I,2),S\n AVR=AVR+R\n IF (R)11,15,12\n11 NNEG=NNEG+1\n S=-R\n GO TO 13\n12 NPOS=NPOS+1\n S=R\nC\nC DO NOT INCREMENT COUNTER M IF RESIDUAL IS GREATER THAN T LIMIT\nC\n13 IF (S-T)15,15,14\n14 IF (J)15,15,16\n15 M=M+1\n16 U=U+R*R\n V=V+R*R*R\n IF (R)17,22,20\n17 IF (R+.2)18,19,19\n18 INDXN(21)=INDXN(21)+1\n GO TO 23\n19 JJ=1.-100.*R\n INDXN(JJ)=INDXN(JJ)+1\n GO TO 23\n20 IF (R-0.2)22,22,21\n21 INDXP(21)=INDXP(21)+1\n GO TO 23\n22 JJ=1.+100.*R\n INDXP(JJ)=INDXP(JJ)+1\n23 CONTINUE\n M=M-1\nC\n RETURN\n END\nC-----------------------------------------------------------------------\n DOUBLE PRECISION FUNCTION POLY(Z1,Z2,D)\nC\nC **********************************************************************\nC\nC FUNCTION POLY(X,Y,D)\nC\nC EVALUATES THE POLYNOMIAL DEFINED BY THE COEFFICIENTS D, AT\nC THE NORMALIZED COORDINATE (X,Y).\nC\nC Z1 = NORMALIZED X COORDINATE (R*4)\nC 2 = NORMALIZED Y COORDINATE (R*4)\nC D(30) = ARRAY CONTAINING THE COEFFICIENTS OF THE POLYNOMIAL (R*8)\nC\nC WRITTEN BY W D PENCE, NOV. 1980\nC\nC **********************************************************************\nC\n IMPLICIT REAL*8 (A-H,O-Y)\n REAL*4 Z1,Z2\n REAL*8 X,D(30)\n REAL*8 YLAST,Y1,Y2,Y3,Y4,Y5,Y6\n REAL*8 C0,C1,C2,C3,C4,C5,C6,C7\n DATA YLAST/-2./\n SAVE YLAST\nC\nC FIRST, CALC 1-D POLYNOMIAL IN X FOR GIVEN Y VALUE, IF\nC NOT ALREADY DONE\nC\n X=Z1\n Y1=Z2\nC\n IF (Y1 .NE. YLAST)THEN\n Y2=Y1*Y1\n Y3=Y2*Y1\n Y4=Y3*Y1\n Y5=Y4*Y1\n Y6=Y5*Y1\nC\n C0=D(1)+D(3)*Y1+D(6)*Y2+D(10)*Y3+D(15)*Y4+D(21)*Y5+D(28)*Y6\n C1= D(2) +D(5)*Y1+D(9) *Y2+D(14)*Y3+D(20)*Y4+D(27)*Y5\n C2= D(4) +D(8) *Y1+D(13)*Y2+D(19)*Y3+D(26)*Y4\n C3= D(7) +D(12)*Y1+D(18)*Y2+D(25)*Y3\n C4= D(11) +D(17)*Y1+D(24)*Y2\n C5= D(16) +D(23)*Y1\n C6=D(22)+D(30)*Y1\n C7=D(29)\n \n END IF\nC\nC EVALUATE POLYNOMIAL IN X\nC\n POLY=((((((C7*X+C6)*X+C5)*X+C4)*X+C3)*X+C2)*X+C1)*X+C0\nC IF(I.LE.5) PRINT *,' Z1,Z2,POLY',Z1,Z2,POLY\nC\n YLAST=Y1\n RETURN\n END\n", "meta": {"hexsha": "5993f5739095503d420e9ec38eac791a15290f9d", "size": 12216, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "source/archived_programs/patch_set.for", "max_stars_repo_name": "jlprieur/shell_galaxies", "max_stars_repo_head_hexsha": "1dde87ef33b3c33b3a892e9ad0d642ae02ac6d9e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source/archived_programs/patch_set.for", "max_issues_repo_name": "jlprieur/shell_galaxies", "max_issues_repo_head_hexsha": "1dde87ef33b3c33b3a892e9ad0d642ae02ac6d9e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "source/archived_programs/patch_set.for", "max_forks_repo_name": "jlprieur/shell_galaxies", "max_forks_repo_head_hexsha": "1dde87ef33b3c33b3a892e9ad0d642ae02ac6d9e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.0827586207, "max_line_length": 78, "alphanum_fraction": 0.5160445318, "num_tokens": 4744, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122238669025, "lm_q2_score": 0.7217432062975979, "lm_q1q2_score": 0.6548464335667021}} {"text": "MODULE Fisher_Test\r\nIMPLICIT NONE\r\n\r\nCONTAINS\r\n\r\n\r\nSUBROUTINE fisher (x, m, y, n, total, possib, p, ifault)\r\n\r\n! ALGORITHM AS 304.1 APPL.STATIST. (1996), VOL.45, NO.3\r\n\r\n! Fisher's non-parametric randomization test for two small\r\n! independent random samples\r\n\r\nIMPLICIT NONE\r\nINTEGER, INTENT(IN OUT) :: m, n\r\nINTEGER, INTENT(OUT) :: ifault, total, possib\r\nREAL, INTENT(IN OUT) :: x(*), y(*)\r\nREAL, INTENT(OUT) :: p\r\n\r\nINTEGER, PARAMETER :: maxsam = 14, maxsiz = 3432\r\n\r\n! Important : set MAXSIZ >= COMB(MAXSAM, MAXSAM / 2)\r\n\r\nINTEGER :: k, size1, size2, ws3(maxsam)\r\nREAL :: sumx, sumy, ws1(maxsiz), ws2(maxsiz)\r\n\r\n! mean(summ, count) = summ / REAL(count)\r\n\r\nIF (comb(maxsam, maxsam/2) > maxsiz) THEN\r\n ifault = 1\r\nELSE IF (m > maxsam .OR. n > maxsam) THEN\r\n ifault = 2\r\nELSE\r\n ifault = 0\r\n sumx = SUM( x(1:m) )\r\n sumy = SUM( y(1:n) )\r\n IF (mean(sumx, m) > mean(sumy, n)) THEN\r\n CALL exchng(x, m, y, n, sumx, sumy)\r\n END IF\r\n total = 0\r\n IF (m == n) THEN\r\n DO k = 1, (m-1)/2\r\n CALL ktrade(x, m, ws1, size1, ws3, k)\r\n CALL ktrade(y, n, ws2, size2, ws3, k)\r\n total = total + trades(ws1, size1, ws2, size2)\r\n CALL cmplmt(ws1, size1, sumx)\r\n CALL cmplmt(ws2, size2, sumy)\r\n total = total + trades(ws1, size1, ws2, size2)\r\n END DO\r\n IF (MOD(m, 2) == 0) THEN\r\n CALL ktrade(x, m, ws1, size1, ws3, k)\r\n CALL ktrade(y, n, ws2, size2, ws3, k)\r\n total = total + trades(ws1, size1, ws2, size2)\r\n END IF\r\n ELSE\r\n DO k = 1, MIN(m, n)\r\n CALL ktrade(x, m, ws1, size1, ws3, k)\r\n CALL ktrade(y, n, ws2, size2, ws3, k)\r\n total = total + trades(ws1, size1, ws2, size2)\r\n END DO\r\n END IF\r\n possib = comb(m+n, m)\r\n p = REAL(total + 1) / REAL(possib)\r\nEND IF\r\n\r\nRETURN\r\nEND SUBROUTINE fisher\r\n\r\n\r\n\r\nFUNCTION mean(summ, count) RESULT(fn_val)\r\nIMPLICIT NONE\r\n\r\nREAL, INTENT(IN) :: summ\r\nINTEGER, INTENT(IN) :: count\r\nREAL :: fn_val\r\n\r\nfn_val = summ / REAL(count)\r\n\r\nRETURN\r\nEND FUNCTION mean\r\n\r\n\r\nSUBROUTINE exchng (x, m, y, n, sx, sy)\r\n\r\n! ALGORITHM AS 304.2 APPL.STATIST. (1996), VOL.45, NO.3\r\n\r\n! Exchanges the sample data. Assumes both X and Y have been\r\n! previously dimensioned to at least max(M, N) elements\r\n\r\nIMPLICIT NONE\r\nINTEGER, INTENT(IN OUT) :: m, n\r\nREAL, INTENT(IN OUT) :: x(*), y(*), sx, sy\r\n\r\nINTEGER :: c, k\r\nREAL :: temp\r\n\r\ntemp = sx\r\nsx = sy\r\nsy = temp\r\n\r\nc = MIN(m, n)\r\nDO k = 1, c\r\n temp = x(k)\r\n x(k) = y(k)\r\n y(k) = temp\r\nEND DO\r\nIF (m > n) THEN\r\n DO k = c+1, m\r\n y(k) = x(k)\r\n END DO\r\n n = m\r\n m = c\r\nELSE IF (m < n) THEN\r\n DO k = c+1, n\r\n x(k) = y(k)\r\n END DO\r\n m = n\r\n n = c\r\nEND IF\r\n\r\nRETURN\r\nEND SUBROUTINE exchng\r\n\r\n\r\n\r\nSUBROUTINE ktrade (w, k, wprime, kprime, ws, r)\r\n\r\n! ALGORITHM AS 304.3 APPL.STATIST. (1996), VOL.45, NO.3\r\n\r\n! Generates and sorts the sums of the R-combinations of the elements of W.\r\n\r\nINTEGER, INTENT(IN) :: k, r\r\nINTEGER, INTENT(IN OUT) :: ws(*)\r\nINTEGER, INTENT(OUT) :: kprime\r\nREAL, INTENT(IN OUT) :: w(*)\r\nREAL, INTENT(OUT) :: wprime(*)\r\n\r\nkprime = comb(k, r)\r\nIF (r <= k - r .OR. r == k) THEN\r\n CALL gener(w, k, wprime, kprime, ws, r)\r\n CALL sort(wprime, kprime)\r\nELSE\r\n CALL gener(w, k, wprime, kprime, ws, k - r)\r\n CALL sort(wprime, kprime)\r\n CALL cmplmt(wprime, kprime, SUM( w(1:k) ))\r\nEND IF\r\n\r\nRETURN\r\nEND SUBROUTINE ktrade\r\n\r\n\r\n\r\nFUNCTION trades (xprime, mprime, yprime, nprime) RESULT(fn_val)\r\n\r\n! ALGORITHM AS 304.4 APPL.STATIST. (1996), VOL.45, NO.3\r\n\r\n! Returns the number of 1-for-1 trades that refutes the null hypothesis.\r\n! Assumes that XPRIME has the smaller mean and\r\n! that both arrays are sorted in ascending order.\r\n\r\nINTEGER, INTENT(IN) :: mprime, nprime\r\nREAL, INTENT(IN) :: xprime(*), yprime(*)\r\nINTEGER :: fn_val\r\n\r\nINTEGER :: i, j\r\n\r\nfn_val = 0\r\ni = 1\r\nj = 1\r\n10 IF (j > nprime) GO TO 40\r\n20 IF (xprime(i) >= yprime(j)) GO TO 30\r\ni = i + 1\r\nIF (i <= mprime) GO TO 20\r\n30 fn_val = fn_val + (mprime - i + 1)\r\nj = j + 1\r\nIF (i <= mprime) GO TO 10\r\n\r\n40 RETURN\r\nEND FUNCTION trades\r\n\r\n\r\n\r\nSUBROUTINE cmplmt (wprime, kprime, sum)\r\n\r\n! ALGORITHM AS 304.5 APPL.STATIST. (1996), VOL.45, NO.3\r\n\r\n! Reverse and complement the data in WPRIME\r\n\r\nIMPLICIT NONE\r\nINTEGER, INTENT(IN) :: kprime\r\nREAL, INTENT(IN) :: sum\r\nREAL, INTENT(IN OUT) :: wprime(*)\r\n\r\nINTEGER :: i, j\r\nREAL :: temp\r\n\r\nj = kprime\r\nDO i = 1, kprime / 2 + MOD(kprime, 2)\r\n temp = wprime(i)\r\n wprime(i) = REAL(DBLE(sum) - DBLE(wprime(j)))\r\n wprime(j) = REAL(DBLE(sum) - DBLE(temp))\r\n j = j - 1\r\nEND DO\r\n\r\nRETURN\r\nEND SUBROUTINE cmplmt\r\n\r\n\r\n\r\nSUBROUTINE gener (w, n, wprime, nprime, INDEX, r)\r\n\r\n! ALGORITHM AS 304.6 APPL.STATIST. (1996), VOL.45, NO.3\r\n\r\n! Computes an array of sums of the various R-combinations of\r\n! the elements of W\r\n\r\nIMPLICIT NONE\r\nINTEGER, INTENT(IN) :: n, nprime, r\r\nINTEGER, INTENT(IN OUT) :: INDEX(r)\r\nREAL, INTENT(IN) :: w(n)\r\nREAL, INTENT(OUT) :: wprime(nprime)\r\nINTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(14, 60)\r\n\r\nINTEGER :: i, j\r\nREAL (dp) :: sum\r\nLOGICAL :: init\r\n\r\ninit = .true.\r\n\r\nDO i = 1, nprime\r\n CALL next(INDEX, r, n, init)\r\n sum = 0.0D0\r\n DO j = 1, r\r\n sum = sum + DBLE(w(INDEX(j)))\r\n END DO\r\n wprime(i) = REAL(sum)\r\nEND DO\r\n\r\nRETURN\r\nEND SUBROUTINE gener\r\n\r\n\r\n\r\nSUBROUTINE next (rcombo, r, n, init)\r\n\r\n! ALGORITHM AS 304.7 APPL.STATIST. (1996), VOL.45, NO.3\r\n\r\n! Accepts some R-combination of the first N integers and then\r\n! computes the next R-combination in the lexicographic\r\n! ordering of the N! / (R! * (N - R)!) such R-combinations.\r\n! Returns the first R-combination if the initialization\r\n! indicator is .true. and then resets the indicator.\r\n\r\nIMPLICIT NONE\r\nINTEGER, INTENT(IN) :: r, n\r\nINTEGER, INTENT(IN OUT) :: rcombo(r)\r\nLOGICAL, INTENT(IN OUT) :: init\r\n\r\nINTEGER :: i, j, d\r\n\r\nIF (init) THEN\r\n DO i = 1, r\r\n rcombo(i) = i\r\n END DO\r\n init = .false.\r\nELSE\r\n d = n - r\r\n j = r\r\n \r\n! The counter J is not prevented from going out of bounds\r\n! which will happen if there is no next R-combination\r\n \r\n 20 IF (rcombo(j) < d + j) GO TO 30\r\n j = j - 1\r\n GO TO 20\r\n\r\n 30 rcombo(j) = rcombo(j) + 1\r\n DO i = j + 1, r\r\n rcombo(i) = rcombo(i - 1) + 1\r\n END DO\r\nEND IF\r\n\r\nRETURN\r\nEND SUBROUTINE next\r\n\r\n\r\n\r\n! General purpose subroutines\r\n\r\nSUBROUTINE sort (x, n)\r\n\r\n! ALGORITHM AS 304.8 APPL.STATIST. (1996), VOL.45, NO.3\r\n\r\n! Sorts the N values stored in array X in ascending order\r\n\r\nIMPLICIT NONE\r\nINTEGER, INTENT(IN) :: n\r\nREAL, INTENT(IN OUT) :: x(n)\r\n\r\nINTEGER :: i, j, incr\r\nREAL :: temp\r\n\r\nincr = 1\r\n\r\n! Loop : calculate the increment\r\n\r\n10 incr = 3 * incr + 1\r\nIF (incr <= n) GO TO 10\r\n\r\n! Loop : Shell-Metzner sort\r\n\r\n20 incr = incr / 3\r\ni = incr + 1\r\n30 IF (i > n) GO TO 60\r\ntemp = x(i)\r\nj = i\r\n40 IF (x(j - incr) < temp) GO TO 50\r\nx(j) = x(j - incr)\r\nj = j - incr\r\nIF (j > incr) GO TO 40\r\n50 x(j) = temp\r\ni = i + 1\r\nGO TO 30\r\n60 IF (incr > 1) GO TO 20\r\n\r\nRETURN\r\nEND SUBROUTINE sort\r\n\r\n\r\n\r\nFUNCTION comb (n, k) RESULT(fn_val)\r\n\r\n! ALGORITHM AS 304.9 APPL.STATIST. (1996), VOL.45, NO.3\r\n\r\n! Returns the number of combinations of N things taken K at a\r\n! time or 0 if the parameters are incompatible\r\n\r\nIMPLICIT NONE\r\nINTEGER, INTENT(IN) :: n, k\r\nINTEGER :: fn_val\r\n\r\nINTEGER :: m, i\r\nREAL :: numer, denom\r\n\r\nIF (k < 0 .OR. k > n) THEN\r\n fn_val = 0\r\nELSE\r\n m = n - k\r\n numer = 1.0\r\n DO i = n, 1 + MAX(k, m), -1\r\n numer = numer * REAL(i)\r\n END DO\r\n denom = fact(MIN(k, m))\r\n fn_val = nint(numer / denom)\r\nEND IF\r\n\r\nRETURN\r\nEND FUNCTION comb\r\n\r\n\r\n\r\nFUNCTION fact (n) RESULT(fn_val)\r\n\r\n! ALGORITHM AS 304.10 APPL.STATIST. (1996), VOL.45, NO.3\r\n\r\n! Returns the factorial of N or 0.0 if the parameter is negative.\r\n\r\nIMPLICIT NONE\r\nINTEGER, INTENT(IN) :: n\r\nREAL :: fn_val\r\n\r\nINTEGER :: i\r\n\r\nIF (n < 0) THEN\r\n fn_val = 0.0\r\nELSE\r\n fn_val = 1.0\r\n DO i = 2, n\r\n fn_val = fn_val * REAL(i)\r\n END DO\r\nEND IF\r\n\r\nRETURN\r\nEND FUNCTION fact\r\n\r\nEND MODULE Fisher_Test\r\n", "meta": {"hexsha": "9914ec10c1095c9406783bfad30cf9d29f50ee5b", "size": 8150, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/as304.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/as304.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/as304.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": 21.0051546392, "max_line_length": 77, "alphanum_fraction": 0.574601227, "num_tokens": 2863, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122213606241, "lm_q2_score": 0.7217431943271999, "lm_q1q2_score": 0.6548464208969244}} {"text": " INTEGER FUNCTION ICMAX1( N, CX, INCX )\n*\n* -- LAPACK auxiliary routine (version 3.1) --\n* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..\n* November 2006\n*\n* .. Scalar Arguments ..\n INTEGER INCX, N\n* ..\n* .. Array Arguments ..\n COMPLEX CX( * )\n* ..\n*\n* Purpose\n* =======\n*\n* ICMAX1 finds the index of the element whose real part has maximum\n* absolute value.\n*\n* Based on ICAMAX from Level 1 BLAS.\n* The change is to use the 'genuine' absolute value.\n*\n* Contributed by Nick Higham for use with CLACON.\n*\n* Arguments\n* =========\n*\n* N (input) INTEGER\n* The number of elements in the vector CX.\n*\n* CX (input) COMPLEX array, dimension (N)\n* The vector whose elements will be summed.\n*\n* INCX (input) INTEGER\n* The spacing between successive values of CX. INCX >= 1.\n*\n* =====================================================================\n*\n* .. Local Scalars ..\n INTEGER I, IX\n REAL SMAX\n COMPLEX ZDUM\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC ABS\n* ..\n* .. Statement Functions ..\n REAL CABS1\n* ..\n* .. Statement Function definitions ..\n*\n* NEXT LINE IS THE ONLY MODIFICATION.\n CABS1( ZDUM ) = ABS( ZDUM )\n* ..\n* .. Executable Statements ..\n*\n ICMAX1 = 0\n IF( N.LT.1 )\n $ RETURN\n ICMAX1 = 1\n IF( N.EQ.1 )\n $ RETURN\n IF( INCX.EQ.1 )\n $ GO TO 30\n*\n* CODE FOR INCREMENT NOT EQUAL TO 1\n*\n IX = 1\n SMAX = CABS1( CX( 1 ) )\n IX = IX + INCX\n DO 20 I = 2, N\n IF( CABS1( CX( IX ) ).LE.SMAX )\n $ GO TO 10\n ICMAX1 = I\n SMAX = CABS1( CX( IX ) )\n 10 CONTINUE\n IX = IX + INCX\n 20 CONTINUE\n RETURN\n*\n* CODE FOR INCREMENT EQUAL TO 1\n*\n 30 CONTINUE\n SMAX = CABS1( CX( 1 ) )\n DO 40 I = 2, N\n IF( CABS1( CX( I ) ).LE.SMAX )\n $ GO TO 40\n ICMAX1 = I\n SMAX = CABS1( CX( I ) )\n 40 CONTINUE\n RETURN\n*\n* End of ICMAX1\n*\n END\n", "meta": {"hexsha": "ef36a0e9017af291c8e14b9789bd69e37213a96a", "size": 2157, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "external_src/oomph_flapack/icmax1.f", "max_stars_repo_name": "pkeuchel/oomph-lib", "max_stars_repo_head_hexsha": "37c1c61425d6b9ea1c2ddceef63a68a228af6fa4", "max_stars_repo_licenses": ["RSA-MD"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-11-16T12:25:09.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-29T08:53:25.000Z", "max_issues_repo_path": "external_src/oomph_flapack/icmax1.f", "max_issues_repo_name": "pkeuchel/oomph-lib", "max_issues_repo_head_hexsha": "37c1c61425d6b9ea1c2ddceef63a68a228af6fa4", "max_issues_repo_licenses": ["RSA-MD"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-05-05T22:41:37.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-10T14:14:17.000Z", "max_forks_repo_path": "external_src/oomph_flapack/icmax1.f", "max_forks_repo_name": "pkeuchel/oomph-lib", "max_forks_repo_head_hexsha": "37c1c61425d6b9ea1c2ddceef63a68a228af6fa4", "max_forks_repo_licenses": ["RSA-MD"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-01-31T14:09:20.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-07T07:20:51.000Z", "avg_line_length": 22.46875, "max_line_length": 71, "alphanum_fraction": 0.4751970329, "num_tokens": 666, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324983301568, "lm_q2_score": 0.8031738010682209, "lm_q1q2_score": 0.654773384438174}} {"text": " !standard fortran interface\n\n !my function descriptions will be here,\n !other lapack cheats show only different interfaces.\n\n subroutine assert_eqi( a, b )\n\n integer a, b\n\n if ( a /= b) then\n write(*,*) 'assert_eqi failed'\n write(*,*) 'a', a\n write(*,*) 'b', b\n stop 1\n endif\n\n end\n\n subroutine assert_eqr( x, y, err )\n\n real x, y, err\n\n if ( abs( x - y ) >= err ) then\n write(*,*) 'assert_eqr failed'\n write(*,*) 'y', x\n write(*,*) 'x', y\n write(*,*) 'err', err\n stop 1\n endif\n\n end\n\n !euclidean distance |x-y|_2\n function dist2( n, x, y )\n\n integer n\n real x(n), y(n)\n\n call saxpy( 2, -1.0, x, 1, y, 1 )\n dist2 = snrm2( n, y, 1 )\n return\n\n end\n\n !assert |x-y|_2 <= err\n subroutine assert_eqvr2( n, x, y, err )\n\n integer n\n real x(n), y(n), err\n real dist2\n\n if ( dist2( n, x, y ) >= err ) then\n write(*,*) 'assert_eq_vr_norm2 failed'\n write(*,*) 'x', x\n write(*,*) 'y', y\n write(*,*) 'err', err\n stop 1\n endif\n\n end\n\n program main\n\n integer n, nrhs, lda, ldb, info, pivots(2)\n real a2x2(2,2), b2(2), c2(2), x2(2), x4(4), y2(2), err\n\n err = 10e-6\n\n !#blas\n\n !#common arguments\n\n !most commands start with the array dimension as argument\n\n !ex:\n\n x4(1) = 1.0\n x4(2) = 1.0\n x4(3) = 1.0\n x4(4) = 1.0\n call assert_eqr( snrm2(4, x4, 1), 2.0, err )\n ! ^ \n ! array length\n\n !#indx\n\n !argument present on lots of the level 1 ops.\n\n !takes every nth value only.\n\n !array must be indx times larger\n\n !TODO make this work\n\n x4(1) = 1.0\n x4(2) = 1.0\n x4(3) = 1.0\n x4(4) = 1.0\n !call assert_eqr( snrm2(4, x4, 2), sqrt(2.0), err )\n ! ^ \n ! indx \n\n !#nrm2\n\n !euclidean norm 2\n\n x2(1) = 1.0\n x2(2) = -2.0\n call assert_eqr( snrm2(2, x2, 1), sqrt(5.0), err )\n\n !#axpy\n\n !y = \\alpha * x + y\n\n !x\n x2(1) = 1.0\n x2(2) = -2.0\n\n !y\n y2(1) = 3.0\n y2(2) = -4.0\n\n call saxpy(2, 2.0, x2, 1, y2, 1)\n ! 1 2 3 \n !1: \\alpha\n !2: incx\n !3: incy\n call assert_eqr( y2(1), 5.0, err )\n call assert_eqr( y2(2), -8.0, err )\n\n !#scal\n\n !x = \\alpha x\n\n x2(1) = 1.0\n x2(2) = -2.0\n call sscal( 2, 2.0, x2, 1 )\n\n y2(1) = 2.0\n y2(2) = -4.0\n call assert_eqvr2( 2, x2, y2, err )\n\n !#i.amax\n\n !index of largest absolute value in array\n\n x4(1) = 1.0\n x4(2) = -1.0\n x4(3) = -2.0\n x4(4) = 0.0\n call assert_eqi( isamax(4, x4, 1), 3 )\n\n !#lapack\n\n !#gesv\n\n !solve general linear system\n\n n = 2\n nrhs = 1 !number of columns of b: if many solves several eqs with same A\n a2x2(1,1) = 1.0\n a2x2(1,2) = 2.0\n a2x2(2,1) = 3.0\n a2x2(2,2) = 4.0\n lda = 2 !max N,1. Leading Dimenstion A\n b2(1) = 5.0\n b2(2) = 11.0\n ldb = 2 !max 1,N\n\n !result returned inside of b itself:\n !return status returned on `info`:\n !pivots returned on `pivots`:\n call sgesv( n, nrhs, a2x2, lda, pivots, b2, ldb, info )\n\n c2(1) = 1.0\n c2(2) = 2.0\n call assert_eqi( info, 0 )\n call assert_eqvr2( 2, b2, c2, err );\n\n !#\n\n stop\n end\n", "meta": {"hexsha": "1f8aeaae373361490b570beb5103253e6db5d780", "size": 4156, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "awesome/c_cpp/cpp-cheat/lapack/main.f", "max_stars_repo_name": "liujiamingustc/phd", "max_stars_repo_head_hexsha": "4f815a738abad43531d02ac66f5bd0d9a1def52a", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-01-06T03:01:18.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T03:02:55.000Z", "max_issues_repo_path": "awesome/c_cpp/cpp-cheat/lapack/main.f", "max_issues_repo_name": "liujiamingustc/phd", "max_issues_repo_head_hexsha": "4f815a738abad43531d02ac66f5bd0d9a1def52a", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "awesome/c_cpp/cpp-cheat/lapack/main.f", "max_forks_repo_name": "liujiamingustc/phd", "max_forks_repo_head_hexsha": "4f815a738abad43531d02ac66f5bd0d9a1def52a", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.5869565217, "max_line_length": 93, "alphanum_fraction": 0.3780076997, "num_tokens": 1395, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8152324803738429, "lm_q2_score": 0.8031738057795403, "lm_q1q2_score": 0.6547733738569538}} {"text": "program test_math_is_close\n\n call test_math_is_close_real\n call test_math_is_close_complex\n print *, \"All tests in `test_math_is_close` passed.\"\n\ncontains\n\n subroutine test_math_is_close_real\n use forlab_math, only: is_close\n use stdlib_error, only: check\n\n call check(is_close(2.5, 2.5, rel_tol=1.0e-5), msg=\"is_close(2.5, 2.5, rel_tol=1.0e-5) failed.\")\n call check(all(is_close([2.5, 3.2], [2.5, 10.0], rel_tol=1.0e-5)), &\n msg=\"all(is_close([2.5, 3.2], [2.5, 10.0], rel_tol=1.0e-5)) failed (expected).\", warn=.true.)\n call check(all(is_close(reshape([2.5, 3.2, 2.2, 1.0], [2, 2]), reshape([2.5, 3.2001, 2.25, 1.1], [2, 2]), &\n abs_tol=1.0e-5, rel_tol=0.1)), &\n msg=\"all(is_close(reshape([2.5, 3.2, 2.2, 1.0],[2,2]), reshape([2.5, 3.2001, 2.25, 1.1],[2,2]), &\n &rel_tol=1.0e-5, abs_tol=0.1)) failed.\")\n\n !> Tests for zeros\n call check(is_close(0.0, -0.0), msg=\"is_close(0.0, -0.0) failed.\")\n\n end subroutine test_math_is_close_real\n\n subroutine test_math_is_close_complex\n use forlab_math, only: is_close\n use stdlib_error, only: check\n\n call check(is_close((2.5,1.2), (2.5,1.2), rel_tol=1.0e-5), &\n msg=\"is_close((2.5,1.2), (2.5,1.2), rel_tol=1.0e-5) failed.\")\n call check(all(is_close([(2.5,1.2), (3.2,1.2)], [(2.5,1.2), (10.0,1.2)], rel_tol=1.0e-5)), &\n msg=\"all(is_close([(2.5,1.2), (3.2,1.2)], [(2.5,1.2), (10.0,1.2)], rel_tol=1.0e-5)) failed (expected).\", &\n warn=.true.)\n call check(all(is_close(reshape([(2.5,1.2009), (3.2,1.199999)], [1, 2]), reshape([(2.4,1.2009), (3.15,1.199999)], [1, 2]), &\n abs_tol=1.0e-5, rel_tol=0.1)), &\n msg=\"all(is_close(reshape([(2.5,1.2009), (3.2,1.199999)], [1, 2]), &\n &reshape([(2.4,1.2009), (3.15,1.199999)], [1, 2]), &\n &rel_tol=1.0e-5, abs_tol=0.1)) failed.\")\n\n !> Tests for zeros\n call check(is_close((0.0, -0.0), (-0.0, 0.0)), msg=\"is_close((0.0, -0.0), (-0.0, 0.0)) failed.\")\n\n end subroutine test_math_is_close_complex\n\nend program test_math_is_close", "meta": {"hexsha": "f0a412e707755883dc7f1d352ff7e8e76b81b08a", "size": 2217, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/math/test_math_is_close.f90", "max_stars_repo_name": "zoziha/forlab_z", "max_stars_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2021-08-31T15:23:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T02:44:46.000Z", "max_issues_repo_path": "test/math/test_math_is_close.f90", "max_issues_repo_name": "zoziha/forlab_z", "max_issues_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-08-22T11:47:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-31T00:57:16.000Z", "max_forks_repo_path": "test/math/test_math_is_close.f90", "max_forks_repo_name": "zoziha/forlab_z", "max_forks_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-07-16T03:16:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-31T13:09:42.000Z", "avg_line_length": 48.1956521739, "max_line_length": 132, "alphanum_fraction": 0.5417230492, "num_tokens": 864, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232480373843, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.6547733642549024}} {"text": "subroutine getConstants(n, k, q, Voc, V0, AT, Isat)\r\n\r\n implicit none\r\n\r\n !Output\r\n double precision, intent(out) :: n, k, q, Voc, V0, AT, Isat\r\n\r\n n = 1.35\r\n k = 1.38065e-23\r\n q = 1.60218e-19\r\n Voc = 2.68/3.0\r\n V0 = -0.6\r\n AT = 2.66e-3\r\n Isat = 2.809e-12\r\n\r\nend subroutine getConstants\r\n\r\n\r\n\r\n\r\nsubroutine computeVcurve(nT, nA, nI, T, A, I, V)\r\n\r\n implicit none\r\n\r\n !Fortran-python interface directives\r\n !f2py intent(in) nT, nA, nI, T, A, I\r\n !f2py intent(out) V\r\n !f2py depend(nT) T\r\n !f2py depend(nA) A\r\n !f2py depend(nI) I\r\n !f2py depend(nT,nA,nI) V\r\n\r\n !Input\r\n integer, intent(in) :: nT, nA, nI\r\n double precision, intent(in) :: T(nT), A(nA), I(nI)\r\n\r\n !Output\r\n double precision, intent(out) :: V(nT,nA,nI)\r\n\r\n !Working\r\n double precision n, k, q, Voc, V0, AT, Isat\r\n double precision Isc, Vt\r\n double precision arg, den\r\n integer iT, iA, iI\r\n\r\n call getConstants(n, k, q, Voc, V0, AT, Isat)\r\n\r\n do iI=1,nI\r\n do iA=1,nA\r\n do iT=1,nT\r\n Isc = 0.453*A(iA)/AT\r\n Vt = n*k*T(iT)/q\r\n arg = (Isc + Isat - I(iI)) / Isat\r\n den = I(iI) - Isc - V0*Isat/Vt\r\n if (I(iI) .le. Isc) then\r\n V(iT,iA,iI) = Vt*log(arg)\r\n else\r\n V(iT,iA,iI) = V0**2*Isat/Vt/den + V0\r\n end if\r\n end do\r\n end do\r\n end do\r\n\r\n\r\nend subroutine computeVcurve\r\n", "meta": {"hexsha": "87d4e2f003a10aeb9c5d763252ff0d899bc13563", "size": 1377, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "CADRE/data/Power/power.f90", "max_stars_repo_name": "robfalck/CADRE", "max_stars_repo_head_hexsha": "f1fb419aade62fe830d56d958f35f1e153f04363", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2015-05-13T23:44:26.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-30T07:23:30.000Z", "max_issues_repo_path": "CADRE/data/Power/power.f90", "max_issues_repo_name": "robfalck/CADRE", "max_issues_repo_head_hexsha": "f1fb419aade62fe830d56d958f35f1e153f04363", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2018-07-24T20:10:52.000Z", "max_issues_repo_issues_event_max_datetime": "2018-09-07T17:16:51.000Z", "max_forks_repo_path": "CADRE/data/Power/power.f90", "max_forks_repo_name": "robfalck/CADRE", "max_forks_repo_head_hexsha": "f1fb419aade62fe830d56d958f35f1e153f04363", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2015-07-21T17:41:42.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-31T09:49:09.000Z", "avg_line_length": 20.8636363636, "max_line_length": 63, "alphanum_fraction": 0.5294117647, "num_tokens": 551, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942119105696, "lm_q2_score": 0.7248702880639791, "lm_q1q2_score": 0.6547711355941396}} {"text": "C**************************************************************************\nC FFTPACK: Available at http://www.scd.ucar.edu/softlib/mathlib.html\nC\nC ***NOTE (C.T.) *** this is a subset of FFTPACK, which only includes\nC the routines for the complex FFT (forward & inverse).\nC\nC Modified: November 1999 by Arjan van Dijk to include IMPLICIT NONE and\nC to convert all routines to DOUBLE precision.\nC**************************************************************************\n\n\n\n\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC * *\nC * FFTPACK *\nC * *\nC * A package of Fortran subprograms for calculating *\nC * fast Fourier transforms for both complex and real *\nC * periodic sequences and certain other symmetric *\nC * sequences that are listed below *\nC * (Version 4.1 November 1988) *\nC * by *\nC * Paul Swarztrauber *\nC * of *\nC * The National Center for Atmospheric Research *\nC * Boulder, Colorado (80307) U.S.A. *\nC * which is sponsored by *\nC * the National Science Foundation *\nC * *\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC\nC Any source code available through this distribution interface at NCAR\nC is free of charge, but there is no guarantee.\nC\nC FFTPACK breaks the FORTRAN 77 ANSI Standard\nC by passing REAL arrays to subroutines and using the arrays within\nC the subroutines as DOUBLE PRECISION or other types. This infraction\nC may cause data alignment problems when the source code is compiled\nC and loaded in an executable.\n\n\n\n\nC****************************************************************************\nC SUBROUTINE CFFTI(N,WSAVE)\nC\nC SUBROUTINE CFFTI INITIALIZES THE ARRAY WSAVE WHICH IS USED IN\nC BOTH CFFTF AND CFFTB. THE PRIME FACTORIZATION OF N TOGETHER WITH\nC A TABULATION OF THE TRIGONOMETRIC FUNCTIONS ARE COMPUTED AND\nC STORED IN WSAVE.\nC\nC INPUT PARAMETER\nC\nC N THE LENGTH OF THE SEQUENCE TO BE TRANSFORMED\nC\nC OUTPUT PARAMETER\nC\nC WSAVE A WORK ARRAY WHICH MUST BE DIMENSIONED AT LEAST 4*N+15\nC THE SAME WORK ARRAY CAN BE USED FOR BOTH CFFTF AND CFFTB\nC AS LONG AS N REMAINS UNCHANGED. DIFFERENT WSAVE ARRAYS\nC ARE REQUIRED FOR DIFFERENT VALUES OF N. THE CONTENTS OF\nC WSAVE MUST NOT BE CHANGED BETWEEN CALLS OF CFFTF OR CFFTB.\nC\n SUBROUTINE CFFTI (N,WSAVE)\n IMPLICIT NONE\n INTEGER N,IW1,IW2\n DOUBLE PRECISION WSAVE\n DIMENSION WSAVE(*)\nC\n IF (N .EQ. 1) RETURN\n IW1 = N+N+1\n IW2 = IW1+N+N\n CALL CFFTI1 (N,WSAVE(IW1),WSAVE(IW2))\n RETURN\n END\n\nC****************************************************************************\nC SUBROUTINE CFFTF(N,C,WSAVE)\nC\nC SUBROUTINE CFFTF COMPUTES THE FORWARD COMPLEX DISCRETE FOURIER\nC TRANSFORM (THE FOURIER ANALYSIS). EQUIVALENTLY , CFFTF COMPUTES\nC THE FOURIER COEFFICIENTS OF A COMPLEX PERIODIC SEQUENCE.\nC THE TRANSFORM IS DEFINED BELOW AT OUTPUT PARAMETER C.\nC\nC THE TRANSFORM IS NOT NORMALIZED. TO OBTAIN A NORMALIZED TRANSFORM\nC THE OUTPUT MUST BE DIVIDED BY N. OTHERWISE A CALL OF CFFTF\nC FOLLOWED BY A CALL OF CFFTB WILL MULTIPLY THE SEQUENCE BY N.\nC\nC THE ARRAY WSAVE WHICH IS USED BY SUBROUTINE CFFTF MUST BE\nC INITIALIZED BY CALLING SUBROUTINE CFFTI(N,WSAVE).\nC\nC INPUT PARAMETERS\nC\nC\nC N THE LENGTH OF THE COMPLEX SEQUENCE C. THE METHOD IS\nC MORE EFFICIENT WHEN N IS THE PRODUCT OF SMALL PRIMES. N\nC\nC C A COMPLEX ARRAY OF LENGTH N WHICH CONTAINS THE SEQUENCE\nC\nC WSAVE A REAL WORK ARRAY WHICH MUST BE DIMENSIONED AT LEAST 4N+15\nC IN THE PROGRAM THAT CALLS CFFTF. THE WSAVE ARRAY MUST BE\nC INITIALIZED BY CALLING SUBROUTINE CFFTI(N,WSAVE) AND A\nC DIFFERENT WSAVE ARRAY MUST BE USED FOR EACH DIFFERENT\nC VALUE OF N. THIS INITIALIZATION DOES NOT HAVE TO BE\nC REPEATED SO LONG AS N REMAINS UNCHANGED THUS SUBSEQUENT\nC TRANSFORMS CAN BE OBTAINED FASTER THAN THE FIRST.\nC THE SAME WSAVE ARRAY CAN BE USED BY CFFTF AND CFFTB.\nC\nC OUTPUT PARAMETERS\nC\nC C FOR J=1,...,N\nC\nC C(J)=THE SUM FROM K=1,...,N OF\nC\nC C(K)*EXP(-I*(J-1)*(K-1)*2*PI/N)\nC\nC WHERE I=SQRT(-1)\nC\nC WSAVE CONTAINS INITIALIZATION CALCULATIONS WHICH MUST NOT BE\nC DESTROYED BETWEEN CALLS OF SUBROUTINE CFFTF OR CFFTB\nC\n SUBROUTINE CFFTF (N,C,WSAVE)\n IMPLICIT NONE\n INTEGER N,IW1,IW2\n DOUBLE PRECISION C,WSAVE\n DIMENSION C(*) ,WSAVE(*)\nC\n IF (N .EQ. 1) RETURN\n IW1 = N+N+1\n IW2 = IW1+N+N\n CALL CFFTF1 (N,C,WSAVE,WSAVE(IW1),WSAVE(IW2))\n RETURN\n END\n\nC****************************************************************************\nC SUBROUTINE CFFTB(N,C,WSAVE)\nC\nC SUBROUTINE CFFTB COMPUTES THE BACKWARD COMPLEX DISCRETE FOURIER\nC TRANSFORM (THE FOURIER SYNTHESIS). EQUIVALENTLY , CFFTB COMPUTES\nC A COMPLEX PERIODIC SEQUENCE FROM ITS FOURIER COEFFICIENTS.\nC THE TRANSFORM IS DEFINED BELOW AT OUTPUT PARAMETER C.\nC\nC A CALL OF CFFTF FOLLOWED BY A CALL OF CFFTB WILL MULTIPLY THE\nC SEQUENCE BY N.\nC\nC THE ARRAY WSAVE WHICH IS USED BY SUBROUTINE CFFTB MUST BE\nC INITIALIZED BY CALLING SUBROUTINE CFFTI(N,WSAVE).\nC\nC INPUT PARAMETERS\nC\nC\nC N THE LENGTH OF THE COMPLEX SEQUENCE C. THE METHOD IS\nC MORE EFFICIENT WHEN N IS THE PRODUCT OF SMALL PRIMES.\nC\nC C A COMPLEX ARRAY OF LENGTH N WHICH CONTAINS THE SEQUENCE\nC\nC WSAVE A REAL WORK ARRAY WHICH MUST BE DIMENSIONED AT LEAST 4N+15\nC IN THE PROGRAM THAT CALLS CFFTB. THE WSAVE ARRAY MUST BE\nC INITIALIZED BY CALLING SUBROUTINE CFFTI(N,WSAVE) AND A\nC DIFFERENT WSAVE ARRAY MUST BE USED FOR EACH DIFFERENT\nC VALUE OF N. THIS INITIALIZATION DOES NOT HAVE TO BE\nC REPEATED SO LONG AS N REMAINS UNCHANGED THUS SUBSEQUENT\nC TRANSFORMS CAN BE OBTAINED FASTER THAN THE FIRST.\nC THE SAME WSAVE ARRAY CAN BE USED BY CFFTF AND CFFTB.\nC\nC OUTPUT PARAMETERS\nC\nC C FOR J=1,...,N\nC\nC C(J)=THE SUM FROM K=1,...,N OF\nC\nC C(K)*EXP(I*(J-1)*(K-1)*2*PI/N)\nC\nC WHERE I=SQRT(-1)\nC\nC WSAVE CONTAINS INITIALIZATION CALCULATIONS WHICH MUST NOT BE\nC DESTROYED BETWEEN CALLS OF SUBROUTINE CFFTF OR CFFTB\nC\n SUBROUTINE CFFTB (N,C,WSAVE)\n IMPLICIT NONE\n INTEGER N,IW1,IW2\n DOUBLE PRECISION C,WSAVE\n DIMENSION C(*) ,WSAVE(*)\nC\n IF (N .EQ. 1) RETURN\n IW1 = N+N+1\n IW2 = IW1+N+N\n CALL CFFTB1 (N,C,WSAVE,WSAVE(IW1),WSAVE(IW2))\n RETURN\n END\n\nC****************************************************************************\n SUBROUTINE CFFTI1 (N,WA,WIFAC)\n IMPLICIT NONE\n INTEGER N,NTRYH,NL,NF,J,NTRY,NQ,NR,IB,I,L1,K1,IP,LD,L2,\n & IDO,IDOT,IPM,I1,II\n DOUBLE PRECISION WA,TPI,ARGH,FI,ARGLD,ARG,WIFAC\n DIMENSION WA(*) ,WIFAC(*) ,NTRYH(4)\n DATA NTRYH(1),NTRYH(2),NTRYH(3),NTRYH(4)/3,4,2,5/\n NL = N\n NF = 0\n J = 0\n 101 J = J+1\n IF (J-4) 102,102,103\n 102 NTRY = NTRYH(J)\n GO TO 104\n 103 NTRY = NTRY+2\n 104 NQ = NL/NTRY\n NR = NL-NTRY*NQ\n IF (NR) 101,105,101\n 105 NF = NF+1\n WIFAC(NF+2) = DBLE(NTRY)\n NL = NQ\n IF (NTRY .NE. 2) GO TO 107\n IF (NF .EQ. 1) GO TO 107\n DO 106 I=2,NF\n IB = NF-I+2\n WIFAC(IB+2) = WIFAC(IB+1)\n 106 CONTINUE\n WIFAC(3) = 2.D0\n 107 IF (NL .NE. 1) GO TO 104\n WIFAC(1) = DBLE(N)\n WIFAC(2) = DBLE(NF)\n TPI = 2.D0*(4.D0*ATAN(1.D0))\n ARGH = TPI/DBLE(N)\n I = 2\n L1 = 1\n DO 110 K1=1,NF\n IP = NINT(WIFAC(K1+2))\n LD = 0\n L2 = L1*IP\n IDO = N/L2\n IDOT = IDO+IDO+2\n IPM = IP-1\n DO 109 J=1,IPM\n I1 = I\n WA(I-1) = 1.D0\n WA(I) = 0.D0\n LD = LD+L1\n FI = 0.D0\n ARGLD = DBLE(LD)*ARGH\n DO 108 II=4,IDOT,2\n I = I+2\n FI = FI+1.D0\n ARG = FI*ARGLD\n WA(I-1) = COS(ARG)\n WA(I) = SIN(ARG)\n 108 CONTINUE\n IF (IP .LE. 5) GO TO 109\n WA(I1-1) = WA(I-1)\n WA(I1) = WA(I)\n 109 CONTINUE\n L1 = L2\n 110 CONTINUE\n RETURN\n END\n\nC****************************************************************************\n SUBROUTINE CFFTF1 (N,C,CH,WA,WIFAC)\n IMPLICIT NONE\n INTEGER N,NF,NA,L1,IW,K1,IP,L2,IDO,IDOT,IDL1,IX2,IX3,IX4,N2,\n & I,NAC\n DOUBLE PRECISION C,CH,WA,WIFAC\n DIMENSION CH(*) ,C(*) ,WA(*) ,WIFAC(*)\n NF = NINT(WIFAC(2))\n NA = 0\n L1 = 1\n IW = 1\n DO 116 K1=1,NF\n IP = NINT(WIFAC(K1+2))\n L2 = IP*L1\n IDO = N/L2\n IDOT = IDO+IDO\n IDL1 = IDOT*L1\n IF (IP .NE. 4) GO TO 103\n IX2 = IW+IDOT\n IX3 = IX2+IDOT\n IF (NA .NE. 0) GO TO 101\n CALL PASSF4 (IDOT,L1,C,CH,WA(IW),WA(IX2),WA(IX3))\n GO TO 102\n 101 CALL PASSF4 (IDOT,L1,CH,C,WA(IW),WA(IX2),WA(IX3))\n 102 NA = 1-NA\n GO TO 115\n 103 IF (IP .NE. 2) GO TO 106\n IF (NA .NE. 0) GO TO 104\n CALL PASSF2 (IDOT,L1,C,CH,WA(IW))\n GO TO 105\n 104 CALL PASSF2 (IDOT,L1,CH,C,WA(IW))\n 105 NA = 1-NA\n GO TO 115\n 106 IF (IP .NE. 3) GO TO 109\n IX2 = IW+IDOT\n IF (NA .NE. 0) GO TO 107\n CALL PASSF3 (IDOT,L1,C,CH,WA(IW),WA(IX2))\n GO TO 108\n 107 CALL PASSF3 (IDOT,L1,CH,C,WA(IW),WA(IX2))\n 108 NA = 1-NA\n GO TO 115\n 109 IF (IP .NE. 5) GO TO 112\n IX2 = IW+IDOT\n IX3 = IX2+IDOT\n IX4 = IX3+IDOT\n IF (NA .NE. 0) GO TO 110\n CALL PASSF5 (IDOT,L1,C,CH,WA(IW),WA(IX2),WA(IX3),WA(IX4))\n GO TO 111\n 110 CALL PASSF5 (IDOT,L1,CH,C,WA(IW),WA(IX2),WA(IX3),WA(IX4))\n 111 NA = 1-NA\n GO TO 115\n 112 IF (NA .NE. 0) GO TO 113\n CALL PASSF (NAC,IDOT,IP,L1,IDL1,C,C,C,CH,CH,WA(IW))\n GO TO 114\n 113 CALL PASSF (NAC,IDOT,IP,L1,IDL1,CH,CH,CH,C,C,WA(IW))\n 114 IF (NAC .NE. 0) NA = 1-NA\n 115 L1 = L2\n IW = IW+(IP-1)*IDOT\n 116 CONTINUE\n IF (NA .EQ. 0) RETURN\n N2 = N+N\n DO 117 I=1,N2\n C(I) = CH(I)\n 117 CONTINUE\n RETURN\n END\n\nC****************************************************************************\n SUBROUTINE CFFTB1 (N,C,CH,WA,WIFAC)\n IMPLICIT NONE\n INTEGER N,NF,NA,L1,IW,K1,IP,L2,IDO,IDOT,IDL1,IX2,IX3,IX4,N2,\n & I,NAC\n DOUBLE PRECISION C,CH,WA,WIFAC\n DIMENSION CH(*) ,C(*) ,WA(*) ,WIFAC(*)\n NF = NINT(WIFAC(2))\n NA = 0\n L1 = 1\n IW = 1\n DO 116 K1=1,NF\n IP = NINT(WIFAC(K1+2))\n L2 = IP*L1\n IDO = N/L2\n IDOT = IDO+IDO\n IDL1 = IDOT*L1\n IF (IP .NE. 4) GO TO 103\n IX2 = IW+IDOT\n IX3 = IX2+IDOT\n IF (NA .NE. 0) GO TO 101\n CALL PASSB4 (IDOT,L1,C,CH,WA(IW),WA(IX2),WA(IX3))\n GO TO 102\n 101 CALL PASSB4 (IDOT,L1,CH,C,WA(IW),WA(IX2),WA(IX3))\n 102 NA = 1-NA\n GO TO 115\n 103 IF (IP .NE. 2) GO TO 106\n IF (NA .NE. 0) GO TO 104\n CALL PASSB2 (IDOT,L1,C,CH,WA(IW))\n GO TO 105\n 104 CALL PASSB2 (IDOT,L1,CH,C,WA(IW))\n 105 NA = 1-NA\n GO TO 115\n 106 IF (IP .NE. 3) GO TO 109\n IX2 = IW+IDOT\n IF (NA .NE. 0) GO TO 107\n CALL PASSB3 (IDOT,L1,C,CH,WA(IW),WA(IX2))\n GO TO 108\n 107 CALL PASSB3 (IDOT,L1,CH,C,WA(IW),WA(IX2))\n 108 NA = 1-NA\n GO TO 115\n 109 IF (IP .NE. 5) GO TO 112\n IX2 = IW+IDOT\n IX3 = IX2+IDOT\n IX4 = IX3+IDOT\n IF (NA .NE. 0) GO TO 110\n CALL PASSB5 (IDOT,L1,C,CH,WA(IW),WA(IX2),WA(IX3),WA(IX4))\n GO TO 111\n 110 CALL PASSB5 (IDOT,L1,CH,C,WA(IW),WA(IX2),WA(IX3),WA(IX4))\n 111 NA = 1-NA\n GO TO 115\n 112 IF (NA .NE. 0) GO TO 113\n CALL PASSB (NAC,IDOT,IP,L1,IDL1,C,C,C,CH,CH,WA(IW))\n GO TO 114\n 113 CALL PASSB (NAC,IDOT,IP,L1,IDL1,CH,CH,CH,C,C,WA(IW))\n 114 IF (NAC .NE. 0) NA = 1-NA\n 115 L1 = L2\n IW = IW+(IP-1)*IDOT\n 116 CONTINUE\n IF (NA .EQ. 0) RETURN\n N2 = N+N\n DO 117 I=1,N2\n C(I) = CH(I)\n 117 CONTINUE\n RETURN\n END\n\nC****************************************************************************\n SUBROUTINE PASSB (NAC,IDO,IP,L1,IDL1,CC,C1,C2,CH,CH2,WA)\n IMPLICIT NONE\n INTEGER NAC,IDO,IP,L1,IDL1,IDOT,IPP2,IPPH,IDP,J,K,I,IDL,LC,L,\n & IK,IDLJ,JC,INC,IDIJ,IDJ\n DOUBLE PRECISION CC,C1,C2,CH,CH2,WA,WAR,WAI\n DIMENSION CH(IDO,L1,IP) ,CC(IDO,IP,L1) ,\n 1 C1(IDO,L1,IP) ,WA(*) ,C2(IDL1,IP),\n 2 CH2(IDL1,IP)\n IDOT = IDO/2\n IPP2 = IP+2\n IPPH = (IP+1)/2\n IDP = IP*IDO\nC\n IF (IDO .LT. L1) GO TO 106\n DO 103 J=2,IPPH\n JC = IPP2-J\n DO 102 K=1,L1\n DO 101 I=1,IDO\n CH(I,K,J) = CC(I,J,K)+CC(I,JC,K)\n CH(I,K,JC) = CC(I,J,K)-CC(I,JC,K)\n 101 CONTINUE\n 102 CONTINUE\n 103 CONTINUE\n DO 105 K=1,L1\n DO 104 I=1,IDO\n CH(I,K,1) = CC(I,1,K)\n 104 CONTINUE\n 105 CONTINUE\n GO TO 112\n 106 DO 109 J=2,IPPH\n JC = IPP2-J\n DO 108 I=1,IDO\n DO 107 K=1,L1\n CH(I,K,J) = CC(I,J,K)+CC(I,JC,K)\n CH(I,K,JC) = CC(I,J,K)-CC(I,JC,K)\n 107 CONTINUE\n 108 CONTINUE\n 109 CONTINUE\n DO 111 I=1,IDO\n DO 110 K=1,L1\n CH(I,K,1) = CC(I,1,K)\n 110 CONTINUE\n 111 CONTINUE\n 112 IDL = 2-IDO\n INC = 0\n DO 116 L=2,IPPH\n LC = IPP2-L\n IDL = IDL+IDO\n DO 113 IK=1,IDL1\n C2(IK,L) = CH2(IK,1)+WA(IDL-1)*CH2(IK,2)\n C2(IK,LC) = WA(IDL)*CH2(IK,IP)\n 113 CONTINUE\n IDLJ = IDL\n INC = INC+IDO\n DO 115 J=3,IPPH\n JC = IPP2-J\n IDLJ = IDLJ+INC\n IF (IDLJ .GT. IDP) IDLJ = IDLJ-IDP\n WAR = WA(IDLJ-1)\n WAI = WA(IDLJ)\n DO 114 IK=1,IDL1\n C2(IK,L) = C2(IK,L)+WAR*CH2(IK,J)\n C2(IK,LC) = C2(IK,LC)+WAI*CH2(IK,JC)\n 114 CONTINUE\n 115 CONTINUE\n 116 CONTINUE\n DO 118 J=2,IPPH\n DO 117 IK=1,IDL1\n CH2(IK,1) = CH2(IK,1)+CH2(IK,J)\n 117 CONTINUE\n 118 CONTINUE\n DO 120 J=2,IPPH\n JC = IPP2-J\n DO 119 IK=2,IDL1,2\n CH2(IK-1,J) = C2(IK-1,J)-C2(IK,JC)\n CH2(IK-1,JC) = C2(IK-1,J)+C2(IK,JC)\n CH2(IK,J) = C2(IK,J)+C2(IK-1,JC)\n CH2(IK,JC) = C2(IK,J)-C2(IK-1,JC)\n 119 CONTINUE\n 120 CONTINUE\n NAC = 1\n IF (IDO .EQ. 2) RETURN\n NAC = 0\n DO 121 IK=1,IDL1\n C2(IK,1) = CH2(IK,1)\n 121 CONTINUE\n DO 123 J=2,IP\n DO 122 K=1,L1\n C1(1,K,J) = CH(1,K,J)\n C1(2,K,J) = CH(2,K,J)\n 122 CONTINUE\n 123 CONTINUE\n IF (IDOT .GT. L1) GO TO 127\n IDIJ = 0\n DO 126 J=2,IP\n IDIJ = IDIJ+2\n DO 125 I=4,IDO,2\n IDIJ = IDIJ+2\n DO 124 K=1,L1\n C1(I-1,K,J) = WA(IDIJ-1)*CH(I-1,K,J)-WA(IDIJ)*CH(I,K,J)\n C1(I,K,J) = WA(IDIJ-1)*CH(I,K,J)+WA(IDIJ)*CH(I-1,K,J)\n 124 CONTINUE\n 125 CONTINUE\n 126 CONTINUE\n RETURN\n 127 IDJ = 2-IDO\n DO 130 J=2,IP\n IDJ = IDJ+IDO\n DO 129 K=1,L1\n IDIJ = IDJ\n DO 128 I=4,IDO,2\n IDIJ = IDIJ+2\n C1(I-1,K,J) = WA(IDIJ-1)*CH(I-1,K,J)-WA(IDIJ)*CH(I,K,J)\n C1(I,K,J) = WA(IDIJ-1)*CH(I,K,J)+WA(IDIJ)*CH(I-1,K,J)\n 128 CONTINUE\n 129 CONTINUE\n 130 CONTINUE\n RETURN\n END\n\nC****************************************************************************\n SUBROUTINE PASSB2 (IDO,L1,CC,CH,WA1)\n IMPLICIT NONE\n INTEGER IDO,L1,K,I\n DOUBLE PRECISION CC,CH,WA1,TR2,TI2\n DIMENSION CC(IDO,2,L1) ,CH(IDO,L1,2) ,\n 1 WA1(1)\n IF (IDO .GT. 2) GO TO 102\n DO 101 K=1,L1\n CH(1,K,1) = CC(1,1,K)+CC(1,2,K)\n CH(1,K,2) = CC(1,1,K)-CC(1,2,K)\n CH(2,K,1) = CC(2,1,K)+CC(2,2,K)\n CH(2,K,2) = CC(2,1,K)-CC(2,2,K)\n 101 CONTINUE\n RETURN\n 102 DO 104 K=1,L1\n DO 103 I=2,IDO,2\n CH(I-1,K,1) = CC(I-1,1,K)+CC(I-1,2,K)\n TR2 = CC(I-1,1,K)-CC(I-1,2,K)\n CH(I,K,1) = CC(I,1,K)+CC(I,2,K)\n TI2 = CC(I,1,K)-CC(I,2,K)\n CH(I,K,2) = WA1(I-1)*TI2+WA1(I)*TR2\n CH(I-1,K,2) = WA1(I-1)*TR2-WA1(I)*TI2\n 103 CONTINUE\n 104 CONTINUE\n RETURN\n END\n\nC****************************************************************************\n SUBROUTINE PASSB3 (IDO,L1,CC,CH,WA1,WA2)\n IMPLICIT NONE\n INTEGER IDO,L1,K,I\n DOUBLE PRECISION CC,CH,WA1,WA2,TAUR,TAUI,TR2,CR2,TI2,CI2,CR3,CI3,\n & DR2,DR3,DI2,DI3\n DIMENSION CC(IDO,3,L1) ,CH(IDO,L1,3) ,\n 1 WA1(*) ,WA2(*)\n DATA TAUR,TAUI /-.5D0,.866025403784439D0/\n IF (IDO .NE. 2) GO TO 102\n DO 101 K=1,L1\n TR2 = CC(1,2,K)+CC(1,3,K)\n CR2 = CC(1,1,K)+TAUR*TR2\n CH(1,K,1) = CC(1,1,K)+TR2\n TI2 = CC(2,2,K)+CC(2,3,K)\n CI2 = CC(2,1,K)+TAUR*TI2\n CH(2,K,1) = CC(2,1,K)+TI2\n CR3 = TAUI*(CC(1,2,K)-CC(1,3,K))\n CI3 = TAUI*(CC(2,2,K)-CC(2,3,K))\n CH(1,K,2) = CR2-CI3\n CH(1,K,3) = CR2+CI3\n CH(2,K,2) = CI2+CR3\n CH(2,K,3) = CI2-CR3\n 101 CONTINUE\n RETURN\n 102 DO 104 K=1,L1\n DO 103 I=2,IDO,2\n TR2 = CC(I-1,2,K)+CC(I-1,3,K)\n CR2 = CC(I-1,1,K)+TAUR*TR2\n CH(I-1,K,1) = CC(I-1,1,K)+TR2\n TI2 = CC(I,2,K)+CC(I,3,K)\n CI2 = CC(I,1,K)+TAUR*TI2\n CH(I,K,1) = CC(I,1,K)+TI2\n CR3 = TAUI*(CC(I-1,2,K)-CC(I-1,3,K))\n CI3 = TAUI*(CC(I,2,K)-CC(I,3,K))\n DR2 = CR2-CI3\n DR3 = CR2+CI3\n DI2 = CI2+CR3\n DI3 = CI2-CR3\n CH(I,K,2) = WA1(I-1)*DI2+WA1(I)*DR2\n CH(I-1,K,2) = WA1(I-1)*DR2-WA1(I)*DI2\n CH(I,K,3) = WA2(I-1)*DI3+WA2(I)*DR3\n CH(I-1,K,3) = WA2(I-1)*DR3-WA2(I)*DI3\n 103 CONTINUE\n 104 CONTINUE\n RETURN\n END\n\nC****************************************************************************\n SUBROUTINE PASSB4 (IDO,L1,CC,CH,WA1,WA2,WA3)\n IMPLICIT NONE\n INTEGER IDO,L1,K,I\n DOUBLE PRECISION CC,CH,WA1,WA2,WA3,TI1,TI2,TI3,TI4,TR1,TR2,TR3,\n & TR4,CR3,CR2,CI3,CR4,CI4,CI2\n DIMENSION CC(IDO,4,L1) ,CH(IDO,L1,4) ,\n 1 WA1(*) ,WA2(*) ,WA3(*)\n IF (IDO .NE. 2) GO TO 102\n DO 101 K=1,L1\n TI1 = CC(2,1,K)-CC(2,3,K)\n TI2 = CC(2,1,K)+CC(2,3,K)\n TR4 = CC(2,4,K)-CC(2,2,K)\n TI3 = CC(2,2,K)+CC(2,4,K)\n TR1 = CC(1,1,K)-CC(1,3,K)\n TR2 = CC(1,1,K)+CC(1,3,K)\n TI4 = CC(1,2,K)-CC(1,4,K)\n TR3 = CC(1,2,K)+CC(1,4,K)\n CH(1,K,1) = TR2+TR3\n CH(1,K,3) = TR2-TR3\n CH(2,K,1) = TI2+TI3\n CH(2,K,3) = TI2-TI3\n CH(1,K,2) = TR1+TR4\n CH(1,K,4) = TR1-TR4\n CH(2,K,2) = TI1+TI4\n CH(2,K,4) = TI1-TI4\n 101 CONTINUE\n RETURN\n 102 DO 104 K=1,L1\n DO 103 I=2,IDO,2\n TI1 = CC(I,1,K)-CC(I,3,K)\n TI2 = CC(I,1,K)+CC(I,3,K)\n TI3 = CC(I,2,K)+CC(I,4,K)\n TR4 = CC(I,4,K)-CC(I,2,K)\n TR1 = CC(I-1,1,K)-CC(I-1,3,K)\n TR2 = CC(I-1,1,K)+CC(I-1,3,K)\n TI4 = CC(I-1,2,K)-CC(I-1,4,K)\n TR3 = CC(I-1,2,K)+CC(I-1,4,K)\n CH(I-1,K,1) = TR2+TR3\n CR3 = TR2-TR3\n CH(I,K,1) = TI2+TI3\n CI3 = TI2-TI3\n CR2 = TR1+TR4\n CR4 = TR1-TR4\n CI2 = TI1+TI4\n CI4 = TI1-TI4\n CH(I-1,K,2) = WA1(I-1)*CR2-WA1(I)*CI2\n CH(I,K,2) = WA1(I-1)*CI2+WA1(I)*CR2\n CH(I-1,K,3) = WA2(I-1)*CR3-WA2(I)*CI3\n CH(I,K,3) = WA2(I-1)*CI3+WA2(I)*CR3\n CH(I-1,K,4) = WA3(I-1)*CR4-WA3(I)*CI4\n CH(I,K,4) = WA3(I-1)*CI4+WA3(I)*CR4\n 103 CONTINUE\n 104 CONTINUE\n RETURN\n END\n\nC****************************************************************************\n SUBROUTINE PASSB5 (IDO,L1,CC,CH,WA1,WA2,WA3,WA4)\n IMPLICIT NONE\n INTEGER IDO,L1,K,I\n DOUBLE PRECISION CC,CH,WA1,WA2,WA3,WA4,TR11,TI11,TR12,TI12,\n & TI2,TI3,TI4,TI5,TR2,TR3,TR4,TR5,CR2,CI2,CR3,CI3,CR4,CI4,CR5,CI5,\n & DR3,DI3,DR4,DI4,DR5,DI5,DR2,DI2\n DIMENSION CC(IDO,5,L1) ,CH(IDO,L1,5) ,\n 1 WA1(*) ,WA2(*) ,WA3(*) ,WA4(*)\n DATA TR11,TI11,TR12,TI12 /.309016994374947D0,.951056516295154D0,\n 1-.809016994374947D0,.587785252292473D0/\n IF (IDO .NE. 2) GO TO 102\n DO 101 K=1,L1\n TI5 = CC(2,2,K)-CC(2,5,K)\n TI2 = CC(2,2,K)+CC(2,5,K)\n TI4 = CC(2,3,K)-CC(2,4,K)\n TI3 = CC(2,3,K)+CC(2,4,K)\n TR5 = CC(1,2,K)-CC(1,5,K)\n TR2 = CC(1,2,K)+CC(1,5,K)\n TR4 = CC(1,3,K)-CC(1,4,K)\n TR3 = CC(1,3,K)+CC(1,4,K)\n CH(1,K,1) = CC(1,1,K)+TR2+TR3\n CH(2,K,1) = CC(2,1,K)+TI2+TI3\n CR2 = CC(1,1,K)+TR11*TR2+TR12*TR3\n CI2 = CC(2,1,K)+TR11*TI2+TR12*TI3\n CR3 = CC(1,1,K)+TR12*TR2+TR11*TR3\n CI3 = CC(2,1,K)+TR12*TI2+TR11*TI3\n CR5 = TI11*TR5+TI12*TR4\n CI5 = TI11*TI5+TI12*TI4\n CR4 = TI12*TR5-TI11*TR4\n CI4 = TI12*TI5-TI11*TI4\n CH(1,K,2) = CR2-CI5\n CH(1,K,5) = CR2+CI5\n CH(2,K,2) = CI2+CR5\n CH(2,K,3) = CI3+CR4\n CH(1,K,3) = CR3-CI4\n CH(1,K,4) = CR3+CI4\n CH(2,K,4) = CI3-CR4\n CH(2,K,5) = CI2-CR5\n 101 CONTINUE\n RETURN\n 102 DO 104 K=1,L1\n DO 103 I=2,IDO,2\n TI5 = CC(I,2,K)-CC(I,5,K)\n TI2 = CC(I,2,K)+CC(I,5,K)\n TI4 = CC(I,3,K)-CC(I,4,K)\n TI3 = CC(I,3,K)+CC(I,4,K)\n TR5 = CC(I-1,2,K)-CC(I-1,5,K)\n TR2 = CC(I-1,2,K)+CC(I-1,5,K)\n TR4 = CC(I-1,3,K)-CC(I-1,4,K)\n TR3 = CC(I-1,3,K)+CC(I-1,4,K)\n CH(I-1,K,1) = CC(I-1,1,K)+TR2+TR3\n CH(I,K,1) = CC(I,1,K)+TI2+TI3\n CR2 = CC(I-1,1,K)+TR11*TR2+TR12*TR3\n CI2 = CC(I,1,K)+TR11*TI2+TR12*TI3\n CR3 = CC(I-1,1,K)+TR12*TR2+TR11*TR3\n CI3 = CC(I,1,K)+TR12*TI2+TR11*TI3\n CR5 = TI11*TR5+TI12*TR4\n CI5 = TI11*TI5+TI12*TI4\n CR4 = TI12*TR5-TI11*TR4\n CI4 = TI12*TI5-TI11*TI4\n DR3 = CR3-CI4\n DR4 = CR3+CI4\n DI3 = CI3+CR4\n DI4 = CI3-CR4\n DR5 = CR2+CI5\n DR2 = CR2-CI5\n DI5 = CI2-CR5\n DI2 = CI2+CR5\n CH(I-1,K,2) = WA1(I-1)*DR2-WA1(I)*DI2\n CH(I,K,2) = WA1(I-1)*DI2+WA1(I)*DR2\n CH(I-1,K,3) = WA2(I-1)*DR3-WA2(I)*DI3\n CH(I,K,3) = WA2(I-1)*DI3+WA2(I)*DR3\n CH(I-1,K,4) = WA3(I-1)*DR4-WA3(I)*DI4\n CH(I,K,4) = WA3(I-1)*DI4+WA3(I)*DR4\n CH(I-1,K,5) = WA4(I-1)*DR5-WA4(I)*DI5\n CH(I,K,5) = WA4(I-1)*DI5+WA4(I)*DR5\n 103 CONTINUE\n 104 CONTINUE\n RETURN\n END\n\nC****************************************************************************\n SUBROUTINE PASSF (NAC,IDO,IP,L1,IDL1,CC,C1,C2,CH,CH2,WA)\n IMPLICIT NONE\n INTEGER NAC,IDO,IP,L1,IDL1,IDOT,IPP2,IPPH,IDP,J,JC,K,I,IDL,\n & INC,L,LC,IK,IDLJ,IDIJ,IDJ\n DOUBLE PRECISION CC,C1,C2,CH,CH2,WA,WAR,WAI\n DIMENSION CH(IDO,L1,IP) ,CC(IDO,IP,L1) ,\n 1 C1(IDO,L1,IP) ,WA(*) ,C2(IDL1,IP),\n 2 CH2(IDL1,IP)\n IDOT = IDO/2\n IPP2 = IP+2\n IPPH = (IP+1)/2\n IDP = IP*IDO\nC\n IF (IDO .LT. L1) GO TO 106\n DO 103 J=2,IPPH\n JC = IPP2-J\n DO 102 K=1,L1\n DO 101 I=1,IDO\n CH(I,K,J) = CC(I,J,K)+CC(I,JC,K)\n CH(I,K,JC) = CC(I,J,K)-CC(I,JC,K)\n 101 CONTINUE\n 102 CONTINUE\n 103 CONTINUE\n DO 105 K=1,L1\n DO 104 I=1,IDO\n CH(I,K,1) = CC(I,1,K)\n 104 CONTINUE\n 105 CONTINUE\n GO TO 112\n 106 DO 109 J=2,IPPH\n JC = IPP2-J\n DO 108 I=1,IDO\n DO 107 K=1,L1\n CH(I,K,J) = CC(I,J,K)+CC(I,JC,K)\n CH(I,K,JC) = CC(I,J,K)-CC(I,JC,K)\n 107 CONTINUE\n 108 CONTINUE\n 109 CONTINUE\n DO 111 I=1,IDO\n DO 110 K=1,L1\n CH(I,K,1) = CC(I,1,K)\n 110 CONTINUE\n 111 CONTINUE\n 112 IDL = 2-IDO\n INC = 0\n DO 116 L=2,IPPH\n LC = IPP2-L\n IDL = IDL+IDO\n DO 113 IK=1,IDL1\n C2(IK,L) = CH2(IK,1)+WA(IDL-1)*CH2(IK,2)\n C2(IK,LC) = -WA(IDL)*CH2(IK,IP)\n 113 CONTINUE\n IDLJ = IDL\n INC = INC+IDO\n DO 115 J=3,IPPH\n JC = IPP2-J\n IDLJ = IDLJ+INC\n IF (IDLJ .GT. IDP) IDLJ = IDLJ-IDP\n WAR = WA(IDLJ-1)\n WAI = WA(IDLJ)\n DO 114 IK=1,IDL1\n C2(IK,L) = C2(IK,L)+WAR*CH2(IK,J)\n C2(IK,LC) = C2(IK,LC)-WAI*CH2(IK,JC)\n 114 CONTINUE\n 115 CONTINUE\n 116 CONTINUE\n DO 118 J=2,IPPH\n DO 117 IK=1,IDL1\n CH2(IK,1) = CH2(IK,1)+CH2(IK,J)\n 117 CONTINUE\n 118 CONTINUE\n DO 120 J=2,IPPH\n JC = IPP2-J\n DO 119 IK=2,IDL1,2\n CH2(IK-1,J) = C2(IK-1,J)-C2(IK,JC)\n CH2(IK-1,JC) = C2(IK-1,J)+C2(IK,JC)\n CH2(IK,J) = C2(IK,J)+C2(IK-1,JC)\n CH2(IK,JC) = C2(IK,J)-C2(IK-1,JC)\n 119 CONTINUE\n 120 CONTINUE\n NAC = 1\n IF (IDO .EQ. 2) RETURN\n NAC = 0\n DO 121 IK=1,IDL1\n C2(IK,1) = CH2(IK,1)\n 121 CONTINUE\n DO 123 J=2,IP\n DO 122 K=1,L1\n C1(1,K,J) = CH(1,K,J)\n C1(2,K,J) = CH(2,K,J)\n 122 CONTINUE\n 123 CONTINUE\n IF (IDOT .GT. L1) GO TO 127\n IDIJ = 0\n DO 126 J=2,IP\n IDIJ = IDIJ+2\n DO 125 I=4,IDO,2\n IDIJ = IDIJ+2\n DO 124 K=1,L1\n C1(I-1,K,J) = WA(IDIJ-1)*CH(I-1,K,J)+WA(IDIJ)*CH(I,K,J)\n C1(I,K,J) = WA(IDIJ-1)*CH(I,K,J)-WA(IDIJ)*CH(I-1,K,J)\n 124 CONTINUE\n 125 CONTINUE\n 126 CONTINUE\n RETURN\n 127 IDJ = 2-IDO\n DO 130 J=2,IP\n IDJ = IDJ+IDO\n DO 129 K=1,L1\n IDIJ = IDJ\n DO 128 I=4,IDO,2\n IDIJ = IDIJ+2\n C1(I-1,K,J) = WA(IDIJ-1)*CH(I-1,K,J)+WA(IDIJ)*CH(I,K,J)\n C1(I,K,J) = WA(IDIJ-1)*CH(I,K,J)-WA(IDIJ)*CH(I-1,K,J)\n 128 CONTINUE\n 129 CONTINUE\n 130 CONTINUE\n RETURN\n END\n\nC****************************************************************************\n SUBROUTINE PASSF2 (IDO,L1,CC,CH,WA1)\n IMPLICIT NONE\n INTEGER IDO,L1,K,I\n DOUBLE PRECISION CC,CH,WA1,TR2,TI2\n DIMENSION CC(IDO,2,L1) ,CH(IDO,L1,2) ,\n 1 WA1(*)\n IF (IDO .GT. 2) GO TO 102\n DO 101 K=1,L1\n CH(1,K,1) = CC(1,1,K)+CC(1,2,K)\n CH(1,K,2) = CC(1,1,K)-CC(1,2,K)\n CH(2,K,1) = CC(2,1,K)+CC(2,2,K)\n CH(2,K,2) = CC(2,1,K)-CC(2,2,K)\n 101 CONTINUE\n RETURN\n 102 DO 104 K=1,L1\n DO 103 I=2,IDO,2\n CH(I-1,K,1) = CC(I-1,1,K)+CC(I-1,2,K)\n TR2 = CC(I-1,1,K)-CC(I-1,2,K)\n CH(I,K,1) = CC(I,1,K)+CC(I,2,K)\n TI2 = CC(I,1,K)-CC(I,2,K)\n CH(I,K,2) = WA1(I-1)*TI2-WA1(I)*TR2\n CH(I-1,K,2) = WA1(I-1)*TR2+WA1(I)*TI2\n 103 CONTINUE\n 104 CONTINUE\n RETURN\n END\n\nC****************************************************************************\n SUBROUTINE PASSF3 (IDO,L1,CC,CH,WA1,WA2)\n IMPLICIT NONE\n INTEGER IDO,L1,K,I\n DOUBLE PRECISION CC,CH,WA1,WA2,TAUR,TAUI,TR2,CR2,TI2,CI2,CR3,CI3,\n & DR2,DR3,DI2,DI3\n DIMENSION CC(IDO,3,L1) ,CH(IDO,L1,3) ,\n 1 WA1(*) ,WA2(*)\n DATA TAUR,TAUI /-.5D0,-.866025403784439D0/\n IF (IDO .NE. 2) GO TO 102\n DO 101 K=1,L1\n TR2 = CC(1,2,K)+CC(1,3,K)\n CR2 = CC(1,1,K)+TAUR*TR2\n CH(1,K,1) = CC(1,1,K)+TR2\n TI2 = CC(2,2,K)+CC(2,3,K)\n CI2 = CC(2,1,K)+TAUR*TI2\n CH(2,K,1) = CC(2,1,K)+TI2\n CR3 = TAUI*(CC(1,2,K)-CC(1,3,K))\n CI3 = TAUI*(CC(2,2,K)-CC(2,3,K))\n CH(1,K,2) = CR2-CI3\n CH(1,K,3) = CR2+CI3\n CH(2,K,2) = CI2+CR3\n CH(2,K,3) = CI2-CR3\n 101 CONTINUE\n RETURN\n 102 DO 104 K=1,L1\n DO 103 I=2,IDO,2\n TR2 = CC(I-1,2,K)+CC(I-1,3,K)\n CR2 = CC(I-1,1,K)+TAUR*TR2\n CH(I-1,K,1) = CC(I-1,1,K)+TR2\n TI2 = CC(I,2,K)+CC(I,3,K)\n CI2 = CC(I,1,K)+TAUR*TI2\n CH(I,K,1) = CC(I,1,K)+TI2\n CR3 = TAUI*(CC(I-1,2,K)-CC(I-1,3,K))\n CI3 = TAUI*(CC(I,2,K)-CC(I,3,K))\n DR2 = CR2-CI3\n DR3 = CR2+CI3\n DI2 = CI2+CR3\n DI3 = CI2-CR3\n CH(I,K,2) = WA1(I-1)*DI2-WA1(I)*DR2\n CH(I-1,K,2) = WA1(I-1)*DR2+WA1(I)*DI2\n CH(I,K,3) = WA2(I-1)*DI3-WA2(I)*DR3\n CH(I-1,K,3) = WA2(I-1)*DR3+WA2(I)*DI3\n 103 CONTINUE\n 104 CONTINUE\n RETURN\n END\n\nC****************************************************************************\n SUBROUTINE PASSF4 (IDO,L1,CC,CH,WA1,WA2,WA3)\n IMPLICIT NONE\n INTEGER IDO,L1,K,I\n DOUBLE PRECISION CC,CH,WA1,WA2,WA3,TI1,TI2,TI3,TI4,TR1,TR2,TR3,\n & TR4,CR2,CR3,CR4,CI2,CI3,CI4\n DIMENSION CC(IDO,4,L1) ,CH(IDO,L1,4) ,\n 1 WA1(*) ,WA2(*) ,WA3(*)\n IF (IDO .NE. 2) GO TO 102\n DO 101 K=1,L1\n TI1 = CC(2,1,K)-CC(2,3,K)\n TI2 = CC(2,1,K)+CC(2,3,K)\n TR4 = CC(2,2,K)-CC(2,4,K)\n TI3 = CC(2,2,K)+CC(2,4,K)\n TR1 = CC(1,1,K)-CC(1,3,K)\n TR2 = CC(1,1,K)+CC(1,3,K)\n TI4 = CC(1,4,K)-CC(1,2,K)\n TR3 = CC(1,2,K)+CC(1,4,K)\n CH(1,K,1) = TR2+TR3\n CH(1,K,3) = TR2-TR3\n CH(2,K,1) = TI2+TI3\n CH(2,K,3) = TI2-TI3\n CH(1,K,2) = TR1+TR4\n CH(1,K,4) = TR1-TR4\n CH(2,K,2) = TI1+TI4\n CH(2,K,4) = TI1-TI4\n 101 CONTINUE\n RETURN\n 102 DO 104 K=1,L1\n DO 103 I=2,IDO,2\n TI1 = CC(I,1,K)-CC(I,3,K)\n TI2 = CC(I,1,K)+CC(I,3,K)\n TI3 = CC(I,2,K)+CC(I,4,K)\n TR4 = CC(I,2,K)-CC(I,4,K)\n TR1 = CC(I-1,1,K)-CC(I-1,3,K)\n TR2 = CC(I-1,1,K)+CC(I-1,3,K)\n TI4 = CC(I-1,4,K)-CC(I-1,2,K)\n TR3 = CC(I-1,2,K)+CC(I-1,4,K)\n CH(I-1,K,1) = TR2+TR3\n CR3 = TR2-TR3\n CH(I,K,1) = TI2+TI3\n CI3 = TI2-TI3\n CR2 = TR1+TR4\n CR4 = TR1-TR4\n CI2 = TI1+TI4\n CI4 = TI1-TI4\n CH(I-1,K,2) = WA1(I-1)*CR2+WA1(I)*CI2\n CH(I,K,2) = WA1(I-1)*CI2-WA1(I)*CR2\n CH(I-1,K,3) = WA2(I-1)*CR3+WA2(I)*CI3\n CH(I,K,3) = WA2(I-1)*CI3-WA2(I)*CR3\n CH(I-1,K,4) = WA3(I-1)*CR4+WA3(I)*CI4\n CH(I,K,4) = WA3(I-1)*CI4-WA3(I)*CR4\n 103 CONTINUE\n 104 CONTINUE\n RETURN\n END\n\nC****************************************************************************\n SUBROUTINE PASSF5 (IDO,L1,CC,CH,WA1,WA2,WA3,WA4)\n IMPLICIT NONE\n INTEGER IDO,L1,K,I\n DOUBLE PRECISION CC,CH,WA1,WA2,WA3,WA4,TR11,TI11,TR12,TI12,\n & TI2,TI3,TI4,TI5,TR2,TR3,TR4,TR5,CI2,CI3,CI4,CI5,CR2,CR3,CR4,\n & CR5,DI2,DI3,DI4,DI5,DR2,DR3,DR4,DR5\n DIMENSION CC(IDO,5,L1) ,CH(IDO,L1,5) ,\n 1 WA1(*) ,WA2(*) ,WA3(*) ,WA4(*)\n DATA TR11,TI11,TR12,TI12 /.309016994374947D0,-.951056516295154D0,\n 1-.809016994374947D0,-.587785252292473D0/\n IF (IDO .NE. 2) GO TO 102\n DO 101 K=1,L1\n TI5 = CC(2,2,K)-CC(2,5,K)\n TI2 = CC(2,2,K)+CC(2,5,K)\n TI4 = CC(2,3,K)-CC(2,4,K)\n TI3 = CC(2,3,K)+CC(2,4,K)\n TR5 = CC(1,2,K)-CC(1,5,K)\n TR2 = CC(1,2,K)+CC(1,5,K)\n TR4 = CC(1,3,K)-CC(1,4,K)\n TR3 = CC(1,3,K)+CC(1,4,K)\n CH(1,K,1) = CC(1,1,K)+TR2+TR3\n CH(2,K,1) = CC(2,1,K)+TI2+TI3\n CR2 = CC(1,1,K)+TR11*TR2+TR12*TR3\n CI2 = CC(2,1,K)+TR11*TI2+TR12*TI3\n CR3 = CC(1,1,K)+TR12*TR2+TR11*TR3\n CI3 = CC(2,1,K)+TR12*TI2+TR11*TI3\n CR5 = TI11*TR5+TI12*TR4\n CI5 = TI11*TI5+TI12*TI4\n CR4 = TI12*TR5-TI11*TR4\n CI4 = TI12*TI5-TI11*TI4\n CH(1,K,2) = CR2-CI5\n CH(1,K,5) = CR2+CI5\n CH(2,K,2) = CI2+CR5\n CH(2,K,3) = CI3+CR4\n CH(1,K,3) = CR3-CI4\n CH(1,K,4) = CR3+CI4\n CH(2,K,4) = CI3-CR4\n CH(2,K,5) = CI2-CR5\n 101 CONTINUE\n RETURN\n 102 DO 104 K=1,L1\n DO 103 I=2,IDO,2\n TI5 = CC(I,2,K)-CC(I,5,K)\n TI2 = CC(I,2,K)+CC(I,5,K)\n TI4 = CC(I,3,K)-CC(I,4,K)\n TI3 = CC(I,3,K)+CC(I,4,K)\n TR5 = CC(I-1,2,K)-CC(I-1,5,K)\n TR2 = CC(I-1,2,K)+CC(I-1,5,K)\n TR4 = CC(I-1,3,K)-CC(I-1,4,K)\n TR3 = CC(I-1,3,K)+CC(I-1,4,K)\n CH(I-1,K,1) = CC(I-1,1,K)+TR2+TR3\n CH(I,K,1) = CC(I,1,K)+TI2+TI3\n CR2 = CC(I-1,1,K)+TR11*TR2+TR12*TR3\n CI2 = CC(I,1,K)+TR11*TI2+TR12*TI3\n CR3 = CC(I-1,1,K)+TR12*TR2+TR11*TR3\n CI3 = CC(I,1,K)+TR12*TI2+TR11*TI3\n CR5 = TI11*TR5+TI12*TR4\n CI5 = TI11*TI5+TI12*TI4\n CR4 = TI12*TR5-TI11*TR4\n CI4 = TI12*TI5-TI11*TI4\n DR3 = CR3-CI4\n DR4 = CR3+CI4\n DI3 = CI3+CR4\n DI4 = CI3-CR4\n DR5 = CR2+CI5\n DR2 = CR2-CI5\n DI5 = CI2-CR5\n DI2 = CI2+CR5\n CH(I-1,K,2) = WA1(I-1)*DR2+WA1(I)*DI2\n CH(I,K,2) = WA1(I-1)*DI2-WA1(I)*DR2\n CH(I-1,K,3) = WA2(I-1)*DR3+WA2(I)*DI3\n CH(I,K,3) = WA2(I-1)*DI3-WA2(I)*DR3\n CH(I-1,K,4) = WA3(I-1)*DR4+WA3(I)*DI4\n CH(I,K,4) = WA3(I-1)*DI4-WA3(I)*DR4\n CH(I-1,K,5) = WA4(I-1)*DR5+WA4(I)*DI5\n CH(I,K,5) = WA4(I-1)*DI5-WA4(I)*DR5\n 103 CONTINUE\n 104 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "aa20ced5985745dc1317d8b02812608616003a10", "size": 34800, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "wave_fortran/cfftpack.f", "max_stars_repo_name": "danielrios12/wavelet---torrence-e-compo", "max_stars_repo_head_hexsha": "d1d92343c43f5a251cc4e4c3e845a6ce1b21fe39", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 148, "max_stars_repo_stars_event_min_datetime": "2018-03-10T15:11:53.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T18:09:14.000Z", "max_issues_repo_path": "wave_fortran/cfftpack.f", "max_issues_repo_name": "danielrios12/wavelet---torrence-e-compo", "max_issues_repo_head_hexsha": "d1d92343c43f5a251cc4e4c3e845a6ce1b21fe39", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-04-20T15:07:55.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-29T13:49:45.000Z", "max_forks_repo_path": "wave_fortran/cfftpack.f", "max_forks_repo_name": "danielrios12/wavelet---torrence-e-compo", "max_forks_repo_head_hexsha": "d1d92343c43f5a251cc4e4c3e845a6ce1b21fe39", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 122, "max_forks_repo_forks_event_min_datetime": "2018-02-26T16:54:16.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-28T18:09:15.000Z", "avg_line_length": 32.7067669173, "max_line_length": 77, "alphanum_fraction": 0.4575574713, "num_tokens": 14124, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941988938413, "lm_q2_score": 0.7248702880639791, "lm_q1q2_score": 0.6547711261587}} {"text": "!------------------------------------------------------------------------\n! fortfp ----------------------------------------------------------------\n! Fortran module that reads weights and biases -----------------------\n! and performs a forward propagation ---------------------------------\n!------------------------------------------------------------------------\n\nmodule fortfp\n \n implicit none\n \n ! activation function type\n type :: af\n procedure(ndarray), pointer, nopass :: f\n end type af\n\n ! array of function pointers for activation functions\n type (af), dimension(:), allocatable :: activfuncs\n \n ! layer type\n type :: layer\n \n real(8), dimension (:,:), pointer :: w, wd \t\t! matrix of weights\n real(8), dimension (:), pointer :: b, bd \t\t! array of biases\n real(8), dimension (:), pointer :: y \t\t! array of outputs\n procedure(ndarray), public, nopass, pointer :: af => null()\t! activation function\n \n end type layer\n\n ! making pointers for working with input and output vectors\n real(8), dimension (:), pointer :: xp => null(), yp => null()\n \n ! neural network type: array of layers\n type :: nn\n \n type(layer), dimension (:), allocatable :: layers\n \n contains \n \n ! initialize neural network\n procedure, public :: init\n \n ! perform forward propagation\n procedure, public :: query\n\n end type nn\n \n ! dynamic arrays type\n type :: dyn_arr\n\n real(8), dimension(:), allocatable :: v\n real(8), dimension(:,:), allocatable :: m\n\n end type dyn_arr\n \n ! interface for activation functions\n abstract interface\n\n function ndarray(n)\n \n import af\n real(8), dimension (:), intent(in) :: n\n real(8), dimension (size(n)) :: ndarray\n\n end function ndarray\n\n end interface\n\n private :: readwb, init, query\n\ncontains\n\n !=====================================================================\n ! initialization of neural network\n subroutine init(this, layers, activ_func)\n \n class (nn), intent(inout) :: this\n\n ! array containing structure of layers, e.g., [100, 20, 30, 10]\n ! 100 input neurons; 20 neurons in first hidden layer;\n ! 30 neurons in second hidden layer; 10 neurons in output layer\n integer, dimension (:), intent(in) :: layers\n integer :: i, nin, nout, nl\n\n ! list of activation functions passed in\n type (af), dimension(0:), intent(in) :: activ_func\n real(8) :: sd\n type (dyn_arr) :: wb\n\n ! check if number of activation functions match number of layers\n if (size(activ_func) /= size(layers)) then\n print *, \"The number of layers and activation functions do not match\"\n stop\n endif\n \n ! number of layers and neurons\n nl = size(layers)\n nin = layers(1)\n nout = layers(nl)\n \n ! layers' numbers begin from 0\n allocate (this%layers(0:nl-1))\n\n ! loop over layers\n do i=1,nl-1\n \n ! allocate weights\n allocate (this%layers(i)%w(layers(i+1),layers(i)))\n allocate (this%layers(i)%wd(layers(i+1),layers(i)))\n\n ! allocate biases\n allocate (this%layers(i)%b(layers(i+1)))\n allocate (this%layers(i)%bd(layers(i+1)))\n\n ! set to 0\n this%layers(i)%wd = 0.d0\n this%layers(i)%bd = 0.d0\n\n ! allocate outputs\n allocate (this%layers(i)%y(layers(i+1)))\n\n ! read weights and biases\n call readwb(i, shape(this%layers(i)%w), wb)\n call readwb(i, shape(this%layers(i)%b), wb)\n this%layers(i)%w = wb%m\n this%layers(i)%b = wb%v\n\n deallocate (wb%v,wb%m)\n\n ! assign activation functions\n this%layers(i)%af => activ_func(i)%f\n\n enddo\n\n ! manually create layer 0\n allocate (this%layers(0)%y(nin))\n\n ! no weights in layer 0\n allocate (this%layers(0)%w(0,0), this%layers(0)%wd(0,0)) \n allocate (this%layers(0)%b(0), this%layers(0)%bd(0))\n\n ! activation function for layer 0 (very likely null)\n this%layers(0)%af => activ_func(0)%f\n\n end subroutine init\n \n !=====================================================================\n ! given input x, performs forward propagation with results in this%y\n subroutine query(this, x)\n\n class(nn), intent(inout) :: this\n real(8), dimension(:), intent(in) :: x\n integer :: i, n, lm, ln\n integer :: j, k\n real(8) :: sum_j\n \n ! number of weight matrices\n ! layer 0 does not have it, so the number is 1 unit less\n n = size(this%layers) - 1\n \n ! copy x into y(0)\n this%layers(0)%y = x\n\n ! if activation function for inputs is used (very likely null)\n if (associated(this%layers(0)%af)) &\n this%layers(0)%y = this%layers(0)%af (this%layers(0)%y)\n\n ! loop over layers\n do i=1,n\n\n xp => this%layers(i-1)%y\n yp => this%layers(i)%y\n\n lm = ubound(this%layers(i)%w, 1)\n ln = ubound(this%layers(i)%w, 2)\n yp = this%layers(i)%b\n\n ! matrix-vector multiplication: lapack library\n !call dgemv(\"N\", lm, ln, 1.d0, this%layers(i)%w, lm, xp, 1, 1.d0, yp, 1) \n\n ! uncomment this staff if there is no access to lapack\n do k=1,lm\n sum_j = 0.d0\n do j=1,ln\n sum_j = sum_j + this%layers(i)%w(k,j)*xp(j)\n enddo\n yp(k) = sum_j + this%layers(i)%b(k)\n enddo\n \n ! apply activation\n yp = this%layers(i)%af(yp)\n \n enddo\n\n end subroutine query\n\n ! =====================================================================\n ! read weights and biases from file\n subroutine readwb(n_skip, frm, arr)\n\n integer, intent(in) :: n_skip\n type (dyn_arr), intent(inout) :: arr\n real(8), dimension(:), allocatable :: nd\n integer, dimension(:), intent(in) :: frm\n integer(4) :: samples, n, nm, osize\n integer(4) :: i, lm, ln, j, k, nsum\n\n ! nm = 2 for weights; nm = 1 for biases\n nm = size(frm)\n \n ! allocate arrays for weights and open file\n if (nm == 2) then\n samples = int(frm(1))*int(frm(2))\n osize = samples\t! recording original size\n ! in case both dimensions are odd\n if (mod(samples, 2) == 1) samples = samples + 1\n allocate (arr%m(frm(1), frm(2)))\n open (1111, file = 'wb/w_0', status = 'old')\n ! allocate arrays for biases\n else\n samples=int(frm(1))\n osize = samples \t! recording original size\n ! in case dimension is odd\n if (mod(samples,2) == 1) samples = samples + 1\n allocate (arr%v(frm(1)))\n open (1111, file = 'wb/b_0', status = 'old')\n endif\n \n ! array for values\n allocate (nd(samples))\n nd = 0\n\n ! skip necessary lines\n if (n_skip > 1) then\n rewind (1111)\n do i=1,n_skip-1\n read (1111,*)\n end do\n end if\n ! read values from file\n read (1111,*) nd\n close (1111)\n\n ! weights\n if (nm == 2) then\n ln = size(arr%m, dim=2)\n lm = size(arr%m, dim=1)\n nsum = 1\n do j=1,lm\n do k=1,ln\n arr%m(j,k) = nd(nsum)\n nsum = nsum + 1\n enddo\n enddo\n ! biases\n else\n arr%v = nd(1:osize)\n endif\n\n end subroutine readwb\n !=====================================================================\n\n !---------------------------------------------------------------------\n ! ACTIVATION FUNCTIONS -----------------------------------------------\n ! all inputs and outputs are multidimensional ---------------------\n ! so even a scalar must be with dimension (1) ---------------------\n !---------------------------------------------------------------------\n \n !===================================================================== \n pure function sigmoid(x)\n \n ! sigmoid\n real(8), dimension (:), intent(in) :: x\n real(8), dimension (size(x)) :: sigmoid\n \n sigmoid = exp(-x)\n sigmoid = 1.d0 + sigmoid\n sigmoid = 1.d0 / sigmoid\n \n end function sigmoid\n\n ! =====================================================================\n pure function htan (x)\n \n ! hyperbolic tan\n real(8), dimension (:), intent(in) :: x\n real(8), dimension (size(x)) :: htan\n htan = tanh(x)\n\n end function htan\n\n ! =====================================================================\n pure function smax (y)\n \n ! softmax\n real(8), dimension(:), intent(in) :: y\n real(8), dimension (size(y)) :: smax\n real(8) :: sum_smax, l1, l2\n l1 = 1.d-9\n l2 = 0.999999999d0\n smax = exp(y)\n sum_smax = sum(smax)\n smax = smax / sum_smax\n where (smax > l2) smax = l2\n where (smax < l1) smax = l1\n\n end function smax\n\n ! =====================================================================\n pure function lrelu(x)\n\n ! leaky relu\n real(8), dimension (:), intent(in) :: x\n real(8), dimension (size(x)) :: lrelu\n lrelu = x\n where (x < 0.d0) lrelu = 0.01d0*x\n\n end function lrelu\n\n ! =====================================================================\n pure function relu(x)\n \n ! relu\n real(8), dimension (:), intent(in) :: x\n real(8), dimension (size(x)) :: relu\n\n relu = x\n where ( x < 0.d0 ) relu = 0.d0\n\n end function relu\n ! =====================================================================\n\n pure function no_activation(x)\n \n ! no activation\n real(8), dimension (:), intent(in) :: x\n real(8), dimension (size(x)) :: no_activation\n\n no_activation = x\n\n end function no_activation\n ! =====================================================================\n\nend module fortfp\n", "meta": {"hexsha": "356239aefb37b1790791d93d71c09c7f8d9e82da", "size": 9982, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortfp.f90", "max_stars_repo_name": "aiskhak/FortNN_Forward_Propagation", "max_stars_repo_head_hexsha": "0728e031459b72b788c9ac2cea5079f58a0724ca", "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": "fortfp.f90", "max_issues_repo_name": "aiskhak/FortNN_Forward_Propagation", "max_issues_repo_head_hexsha": "0728e031459b72b788c9ac2cea5079f58a0724ca", "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": "fortfp.f90", "max_forks_repo_name": "aiskhak/FortNN_Forward_Propagation", "max_forks_repo_head_hexsha": "0728e031459b72b788c9ac2cea5079f58a0724ca", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.0174418605, "max_line_length": 87, "alphanum_fraction": 0.4738529353, "num_tokens": 2517, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942067038784, "lm_q2_score": 0.7248702761768248, "lm_q1q2_score": 0.6547711210823661}} {"text": " real function intrpl(x1,y1,x2,y2,x)\r\nc\r\nc + + + PURPOSE + + +\r\nc\r\nc Function INTRPL interpolates between columnar table entries.\r\nc\r\nc Called from: SR TABLE\r\nc Author(s): Ascough II, R. van der Zweep, V. Lopes\r\nc Reference in User Guide:\r\nc\r\nc Version:\r\nc Date recoded:\r\nc Recoded by: Jim Ascough II\r\nc\r\nc + + + KEYWORDS + + +\r\nc\r\nc + + + PARAMETERS + + +\r\nc\r\nc + + + ARGUMENT DECLARATIONS + + +\r\nc\r\n real x1, y1, x2, y2, x\r\nc\r\nc + + + ARGUMENT DEFINITIONS + + +\r\nc\r\nc x1 -\r\nc y1 -\r\nc x2 -\r\nc y2 -\r\nc x -\r\nc\r\nc + + + COMMON BLOCKS + + +\r\nc\r\nc + + + LOCAL VARIABLES + + +\r\nc\r\nc + + + LOCAL DEFINITIONS + + +\r\nc\r\nc + + + SAVES + + +\r\nc\r\nc + + + SUBROUTINES CALLED + + +\r\nc\r\nc + + + DATA INITIALIZATIONS + + +\r\nc\r\nc + + + END SPECIFICATIONS + + +\r\nc\r\nc\r\ncd Modified by S. Dun, May 24, 2005\r\ncd intrpl = ((y2-y1)*(x-x1)/(x2-x1)) + y1\r\n if(x2 .eq. x1) then\r\n intrpl = (y2-y1)/2\r\n else\r\n intrpl = ((y2-y1)*(x-x1)/(x2-x1)) + y1\r\n endif\r\ncd End modifying\r\n return\r\n end\r\n", "meta": {"hexsha": "17be122a898a670352c1139a788be2915950454b", "size": 1122, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/wepp2010.1/intrpl.for", "max_stars_repo_name": "jarad/dep", "max_stars_repo_head_hexsha": "fe73982f4c70039e1a31b9e8e2d9aac31502f803", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-11-26T17:49:19.000Z", "max_stars_repo_stars_event_max_datetime": "2019-11-26T17:49:19.000Z", "max_issues_repo_path": "src/wepp2010.1/intrpl.for", "max_issues_repo_name": "jarad/dep", "max_issues_repo_head_hexsha": "fe73982f4c70039e1a31b9e8e2d9aac31502f803", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 54, "max_issues_repo_issues_event_min_datetime": "2018-12-12T18:02:31.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T19:14:25.000Z", "max_forks_repo_path": "src/wepp2010.1/intrpl.for", "max_forks_repo_name": "akrherz/idep", "max_forks_repo_head_hexsha": "7189a26fbcec3d8c3cc7d7015107b8fb6c5f6a45", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-03-02T22:59:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-09T15:49:00.000Z", "avg_line_length": 20.0357142857, "max_line_length": 67, "alphanum_fraction": 0.4803921569, "num_tokens": 406, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942067038785, "lm_q2_score": 0.7248702702332476, "lm_q1q2_score": 0.6547711157135674}} {"text": " double precision function DLNREL (X)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc>> 1994-10-20 DLNREL Krogh Changes to use M77CON\nc>> 1990-11-27 DLNREL WV Snyder Initial Code.\nc\nc Compute LOG(1+X).\nc\nc This procedure uses approximation 2707 from Hart, et. al. when\nc 1/sqrt(2) < 1+x < sqrt(2), and otherwise uses the Fortran\nc intrinsic logarithm routine.\nc\nc--D replaces \"?\": ?LNREL\n double precision X\n double precision P0, P1, P2, P3, P4, Q0, Q1, Q2, Q3, Z, ZSQ\n double precision BOT, TOP\n parameter (P0 = +0.75040 94990 77712 22174 55611 007 D+2 )\n parameter (P1 = -0.13456 69115 05043 02353 18253 537 D+3 )\n parameter (P2 = +0.74137 19213 24860 25127 79336 47 D+2 )\n parameter (P3 = -0.12772 49755 01233 08199 84385 D+2 )\n parameter (P4 = +0.33271 08381 08768 69381 44 D00 )\n parameter (Q0 = +0.37520 47495 38856 11087 27775 374 D+2 )\n parameter (Q1 = -0.79790 28073 71500 48794 39951 583 D+2 )\n parameter (Q2 = +0.56161 26132 11825 72920 58560 36 D+2 )\n parameter (Q3 = -0.14508 68091 85808 26853 62325 D+2 )\nc parameter (Q4 = +1.0 D00 )\n parameter (BOT = .70710 67811 86547 52440 D0 - 1.0D0 )\n parameter (TOP = 1.4142 13562 37309 50488 D0 - 1.0D0 )\nc\n if (x .lt. bot .or. x .gt. top) then\n dlnrel = log(x+1.0d0)\n else\n z = x / (x+2.0d0)\n zsq = z*z\n dlnrel = z * ((((p4*zsq+p3)*zsq+p2)*zsq+p1)*zsq+p0)/\n 1 (((( zsq+q3)*zsq+q2)*zsq+q1)*zsq+q0)\n end if\n return\n end\n", "meta": {"hexsha": "b0c8da5816bd4c9584405a642ed324fa17563bd4", "size": 1702, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/dlnrel.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/dlnrel.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/dlnrel.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 41.512195122, "max_line_length": 70, "alphanum_fraction": 0.5963572268, "num_tokens": 666, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797124237604, "lm_q2_score": 0.7185943985973773, "lm_q1q2_score": 0.6547686374632833}} {"text": "c***********************************************************************\nc\t COORD_J2H.F\nc***********************************************************************\n* PURPOSE: Converts from Jacobi to Helio coords.\n* ARGUMENTS: Input is \n* nbod ==> number of bodies (must be less than NBMAX)\n* (integer)\n*\t mass(*) ==> masses (real array)\n*\t\t xj(*),yj(*),zj(*) ==> Jacobi particle coords\n* (real array)\n*\t\t vxj(*),vyj(*),vzj(*) ==> Jacobi particle velocities\n* (real array)\n* Returned are\n* xh(*),yh(*),zh(*) ==> Helio particle positions\n* (real array)\n* vxh(*),vyh(*),vzh(*) ==> Helio particle velocities\n* (real array)\n* \n* ALGORITHM: See my notes on Nov 21. \n*\n* Authors: Martin Duncan\n* WRITTEN: Jan 27/93\n* REVISIONS: 2/17/95 HFL\n\n\tsubroutine coord_j2h(nbod,mass,xj,yj,zj,vxj,vyj,vzj,\n & xh,yh,zh,vxh,vyh,vzh)\n\n\n include '../swift.inc'\n\nc... Inputs: \n\tinteger nbod\n\treal*8 mass(NPLMAX)\n\treal*8 xj(NPLMAX),yj(NPLMAX),zj(NPLMAX)\n\treal*8 vxj(NPLMAX),vyj(NPLMAX),vzj(NPLMAX)\n\nc... Outputs:\n\treal*8 xh(NPLMAX),yh(NPLMAX),zh(NPLMAX)\n\treal*8 vxh(NPLMAX),vyh(NPLMAX),vzh(NPLMAX)\n\nc... Internals:\n\tinteger n\n\treal*8 sumx,sumy,sumz,sumvx,sumvy,sumvz\n\treal*8 eta(NPLMAX)\n\nc----\nc... Executable code \n\nc First calc. the array eta(*) then convert to jacobi coords\n\n\teta(1) = mass(1)\n\tdo n = 2,nbod\n\t eta(n) = eta(n-1) + mass(n)\n enddo\n\n xh(1) = 0.d0\n yh(1) = 0.d0\n\tzh(1) = 0.d0\n\tvxh(1) = 0.d0\n\tvyh(1) = 0.d0\n\tvzh(1) = 0.d0\n\n xh(2) = xj(2) \n yh(2) = yj(2)\n\tzh(2) = zj(2)\n\tvxh(2) = vxj(2)\n\tvyh(2) = vyj(2)\n\tvzh(2) = vzj(2)\n\n\tsumx = mass(2)*xj(2)/eta(2)\n\tsumy = mass(2)*yj(2)/eta(2)\n\tsumz = mass(2)*zj(2)/eta(2)\n\tsumvx = mass(2)*vxj(2)/eta(2)\n\tsumvy = mass(2)*vyj(2)/eta(2)\n\tsumvz = mass(2)*vzj(2)/eta(2)\n\n\tdo n=3,nbod \n\t xh(n) = xj(n) + sumx\n\t yh(n) = yj(n) + sumy\n\t zh(n) = zj(n) + sumz\n\t vxh(n) = vxj(n) + sumvx\n\t vyh(n) = vyj(n) + sumvy\n\t vzh(n) = vzj(n) + sumvz\n\n\t if(n.lt.nbod) then\n sumx = sumx + mass(n)*xj(n)/eta(n)\n sumy = sumy + mass(n)*yj(n)/eta(n)\n sumz = sumz + mass(n)*zj(n)/eta(n)\n sumvx = sumvx + mass(n)*vxj(n)/eta(n)\n sumvy = sumvy + mass(n)*vyj(n)/eta(n)\n sumvz = sumvz + mass(n)*vzj(n)/eta(n)\n endif\n\n\tenddo\n\n\n123\treturn\n\tend ! coord_j2h\n\nc--------------------------------------------------------------------------\n\n", "meta": {"hexsha": "9b9dd8638e75ece15c36c0d69f0c165cb2126d4c", "size": 2717, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/swift_j/coord/coord_j2h.f", "max_stars_repo_name": "Simske/exostriker", "max_stars_repo_head_hexsha": "587b0af4c9cadb46637a4ac61a5392a596e966b1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 69, "max_stars_repo_stars_event_min_datetime": "2020-01-06T13:31:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T11:23:14.000Z", "max_issues_repo_path": "exostriker/source/swift_j/coord/coord_j2h.f", "max_issues_repo_name": "sai-33/Exostriker", "max_issues_repo_head_hexsha": "f59fa51c6bdce3a2ed51d6621fe42bfcd8c2846f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 67, "max_issues_repo_issues_event_min_datetime": "2019-11-30T14:45:05.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-14T20:26:06.000Z", "max_forks_repo_path": "exostriker/source/swift_j/coord/coord_j2h.f", "max_forks_repo_name": "sai-33/Exostriker", "max_forks_repo_head_hexsha": "f59fa51c6bdce3a2ed51d6621fe42bfcd8c2846f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2020-01-06T13:44:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T11:23:17.000Z", "avg_line_length": 26.637254902, "max_line_length": 75, "alphanum_fraction": 0.4427677586, "num_tokens": 949, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797148356994, "lm_q2_score": 0.7185943925708561, "lm_q1q2_score": 0.6547686337052453}} {"text": "PROGRAM F050\n\n ! Copyright 2021 Melwyn Francis Carlo\n ! FILE REFERENCE: http://www.naturalnumbers.org/primes.html\n\n IMPLICIT NONE\n\n INTEGER :: PRIME_NUM\n CHARACTER (LEN=50), PARAMETER :: FILENAME = \"problems/003/PrimeNumbers_Upto_1000000\"\n\n INTEGER, DIMENSION(80000) :: PRIMES_NUMS = 0;\n\n INTEGER :: N = 1\n INTEGER :: COUNT_VAL = 23\n INTEGER :: I_START = 0\n INTEGER :: RESULTANT_PRIME = 0\n\n LOGICAL :: PRIME_FOUND = .FALSE.\n\n INTEGER :: I, I_BY_10, J, K, SUM_VAL\n\n OPEN (2, FILE = FILENAME, STATUS = 'OLD')\n\n DO\n READ(2, *, END=10) PRIME_NUM\n IF (PRIME_NUM > 1000000) EXIT\n IF (I_START == 0) THEN\n IF (PRIME_NUM > 100000) I_START = N - 1\n END IF\n PRIMES_NUMS(N) = PRIME_NUM\n N = N + 1\n END DO\n\n 10 CLOSE(2)\n\n DO WHILE (COUNT_VAL < 1000)\n\n I = I_START\n PRIME_FOUND = .FALSE.\n\n DO WHILE (I < N)\n\n I_BY_10 = INT(I / 10)\n\n DO J = 1, I_BY_10\n\n SUM_VAL = 0\n\n DO K = J, (J + COUNT_VAL - 1)\n SUM_VAL = SUM_VAL + PRIMES_NUMS(K)\n END DO\n\n IF (SUM_VAL > PRIMES_NUMS(I)) EXIT\n\n IF (SUM_VAL == PRIMES_NUMS(I)) THEN\n RESULTANT_PRIME = PRIMES_NUMS(I)\n PRIME_FOUND = .TRUE.\n COUNT_VAL = COUNT_VAL + 1\n EXIT\n END IF\n\n END DO\n\n IF (PRIME_FOUND) EXIT\n\n I = I + 1\n\n END DO\n\n COUNT_VAL = COUNT_VAL + 1\n\n END DO\n\n PRINT ('(I0)'), RESULTANT_PRIME\n\nEND PROGRAM F050\n", "meta": {"hexsha": "853c4afc9f2f89cafef531bdbb1e6ab159859408", "size": 1678, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "problems/050/050.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/050/050.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/050/050.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": 21.7922077922, "max_line_length": 88, "alphanum_fraction": 0.489272944, "num_tokens": 496, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772417253255, "lm_q2_score": 0.7490872187162396, "lm_q1q2_score": 0.6547600899471864}} {"text": "C LAST UPDATE 18/02/94\nC+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\nC\n REAL FUNCTION FUNC(X)\n IMPLICIT NONE\nC\nC Purpose: Evaluates the square of the residual for circle fitting\nC given X(1) = XC, X(2) = YC, X(3) = R \nC\nC Calls 0:\nC Called by: FRPRMN, F1DIM \nC\nC-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-\nC FIX include file:\nC\n INCLUDE 'FIXPAR.COM'\nC \nC Arguments:\nC\n REAL X(3)\nC\nC Common block:\nC\n REAL XD(MAXPTS),YD(MAXPTS)\n INTEGER NDAT \n COMMON /CIRDAT/ XD,YD,NDAT \nC\nC Local variables:\nC\n INTEGER I\nC\nC-----------------------------------------------------------------------\n FUNC = 0.0\n DO 10 I=1,NDAT \n FUNC = FUNC + (SQRT((X(1)-XD(I))**2+(X(2)-YD(I))**2) - X(3))**2\n 10 CONTINUE\n RETURN\nC\n END \n\n\n\n\n\nC LAST UPDATE 18/02/94\nC+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\nC\n SUBROUTINE DFUNC(X,D)\n IMPLICIT NONE\nC\nC Purpose: Evaluates the gradient of the square of the residual for \nC circle fitting given X(1) = XC, X(2) = YC, X(3) = R,\nC returning partial derivatives in array D. \nC \nC\nC Calls 0:\nC Called by: FRPRMN, DF1DIM \nC\nC-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-\nC FIX include file:\nC\n INCLUDE 'FIXPAR.COM'\nC \nC Arguments:\nC\n REAL X(3),D(3)\nC\nC Common block:\nC\n REAL XD(MAXPTS),YD(MAXPTS)\n INTEGER NDAT \n COMMON /CIRDAT/ XD,YD,NDAT \nC\nC Local variables:\nC\n INTEGER I\n REAL DD \nC\nC-----------------------------------------------------------------------\n DO 10 I=1,3\n D(I) = 0.0\n 10 CONTINUE \n DO 20 I=1,NDAT \n DD = SQRT((X(1)-XD(I))**2+(X(2)-YD(I))**2)\n D(1) = D(1) + (X(1)-XD(I))*(1.0-X(3)/DD)\n D(2) = D(2) + (X(2)-YD(I))*(1.0-X(3)/DD)\n D(3) = D(3) + X(3) - DD \n 20 CONTINUE\n DO 30 I=1,3\n D(I) = 2.0*D(I)\n 30 CONTINUE \n RETURN\nC\n END \n\n", "meta": {"hexsha": "b68808cb45179433faf16f5a76cb2f0f6be787e2", "size": 2041, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "software/guifix/CIRFIT.f", "max_stars_repo_name": "scattering-central/CCP13", "max_stars_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "software/guifix/CIRFIT.f", "max_issues_repo_name": "scattering-central/CCP13", "max_issues_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "software/guifix/CIRFIT.f", "max_forks_repo_name": "scattering-central/CCP13", "max_forks_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-09-05T15:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-15T11:13:45.000Z", "avg_line_length": 21.2604166667, "max_line_length": 72, "alphanum_fraction": 0.4105830475, "num_tokens": 648, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772417253255, "lm_q2_score": 0.7490872187162396, "lm_q1q2_score": 0.6547600899471864}} {"text": "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC BenchIT - Performance Measurement for Scientific Applications\nC Contact: developer@benchit.org\nC\nC $Id: matmul_f_core.f 1 2009-09-11 12:26:19Z william $\nC $URL: svn+ssh://william@rupert.zih.tu-dresden.de/svn-base/benchit-root/BenchITv6/kernel/numerical/matmul/F77/0/0/double/matmul_f_core.f $\nC For license details see COPYING in the package base directory\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC Kernel: Matrix Multiply (F77)\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n\n\tSUBROUTINE multaijk( a, b, c, n)\n\tINTEGER*4 n,i,j,k\n\tdouble precision a(n,n), b(n,n), c(n,n)\n\tdo 100 i=1,n\n\tdo 100 j=1,n\n\tdo 100 k=1,n\n\t c(i,j)=c(i,j)+a(i,k)*b(k,j)\n 100\tCONTINUE\n\tRETURN\n\tEND\nc\n\tSUBROUTINE multaikj( a, b, c, n)\n\tINTEGER*4 n,i,j,k\n\tdouble precision a(n,n), b(n,n), c(n,n)\n\tdo 100 i=1,n\n\tdo 100 k=1,n\n\tdo 100 j=1,n\n\t c(i,j)=c(i,j)+a(i,k)*b(k,j)\n 100\tCONTINUE\n\tRETURN\n\tEND\nc\n\tSUBROUTINE multajik( a, b, c, n)\n\tINTEGER*4 n,i,j,k\n\tdouble precision a(n,n), b(n,n), c(n,n)\n\tdo 100 j=1,n\n\tdo 100 i=1,n\n\tdo 100 k=1,n\n\t c(i,j)=c(i,j)+a(i,k)*b(k,j)\n 100\tCONTINUE\n\tRETURN\n\tEND\nc\n\tSUBROUTINE multajki( a, b, c, n)\n\tINTEGER*4 n,i,j,k\n\tdouble precision a(n,n), b(n,n), c(n,n)\n\tdo 100 j=1,n\n\tdo 100 k=1,n\n\tdo 100 i=1,n\n\t c(i,j)=c(i,j)+a(i,k)*b(k,j)\n 100\tCONTINUE\n\tRETURN\n\tEND\nc\n\tSUBROUTINE multakij( a, b, c, n)\n\tINTEGER*4 n,i,j,k\n\tdouble precision a(n,n), b(n,n), c(n,n)\n\tdo 100 k=1,n\n\tdo 100 i=1,n\n\tdo 100 j=1,n\n\t c(i,j)=c(i,j)+a(i,k)*b(k,j)\n 100\tCONTINUE\n\tRETURN\n\tEND\nc\n\tSUBROUTINE multakji( a, b, c, n)\n\tINTEGER*4 n,i,j,k\n\tdouble precision a(n,n), b(n,n), c(n,n)\n\tdo 100 k=1,n\n\tdo 100 j=1,n\n\tdo 100 i=1,n\n\t c(i,j)=c(i,j)+a(i,k)*b(k,j)\n 100\tCONTINUE\n\tRETURN\n\tEND\n\n", "meta": {"hexsha": "8288462a52baf0ffa9b7bafd9d4d426a71653cec", "size": 1783, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "kernel/numerical/matmul/F77/0/0/double/matmul_f_core.f", "max_stars_repo_name": "Arka2009/x86_64-ubench-ecolab", "max_stars_repo_head_hexsha": "38461e73617c92449f85a84176cd108fb82434b2", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "kernel/numerical/matmul/F77/0/0/double/matmul_f_core.f", "max_issues_repo_name": "Arka2009/x86_64-ubench-ecolab", "max_issues_repo_head_hexsha": "38461e73617c92449f85a84176cd108fb82434b2", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "kernel/numerical/matmul/F77/0/0/double/matmul_f_core.f", "max_forks_repo_name": "Arka2009/x86_64-ubench-ecolab", "max_forks_repo_head_hexsha": "38461e73617c92449f85a84176cd108fb82434b2", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.858974359, "max_line_length": 139, "alphanum_fraction": 0.6763881099, "num_tokens": 736, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772482857833, "lm_q2_score": 0.7490872075132152, "lm_q1q2_score": 0.6547600850692327}} {"text": "\nc---------------------------------------------------------------------\nc---------------------------------------------------------------------\n subroutine l2norm (v, sum, nx, nxmax, ny, nz)\nc---------------------------------------------------------------------\nc---------------------------------------------------------------------\n\nc---------------------------------------------------------------------\nc to compute the l2-norm of vector v.\nc---------------------------------------------------------------------\n\n implicit none\n\nc---------------------------------------------------------------------\nc input parameters\nc---------------------------------------------------------------------\n integer nx, nxmax, ny, nz\n double precision v(5,nxmax,ny,nz), sum(5)\n\nc---------------------------------------------------------------------\nc local variables\nc---------------------------------------------------------------------\n integer i, j, k, m\n\n\n do m = 1, 5\n sum(m) = 0.0d+00\n end do\n\n do k = 2, nz-1\n do j = 2, ny-1\n do i = 2, nx-1\n do m = 1, 5\n sum(m) = sum(m) + v(m,i,j,k) * v(m,i,j,k)\n end do\n end do\n end do\n end do\n\n do m = 1, 5\n sum(m) = dsqrt ( sum(m) / ( dble(nx-2)*(ny-2)*(nz-2) ) )\n end do\n\n return\n end\n", "meta": {"hexsha": "4af519c6b8ede38c43c1b5cc6526d79e8d545690", "size": 1383, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Benchmarks/LU-MZ/NPB3.3-MZ-SER/LU-MZ/l2norm.f", "max_stars_repo_name": "jcm300/NAS-Parallel-Benchmarks-Profilling", "max_stars_repo_head_hexsha": "a94e52f9a1cb30b2f4668e08d90ca637ebee264c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Benchmarks/LU-MZ/NPB3.3-MZ-SER/LU-MZ/l2norm.f", "max_issues_repo_name": "jcm300/NAS-Parallel-Benchmarks-Profilling", "max_issues_repo_head_hexsha": "a94e52f9a1cb30b2f4668e08d90ca637ebee264c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Benchmarks/LU-MZ/NPB3.3-MZ-SER/LU-MZ/l2norm.f", "max_forks_repo_name": "jcm300/NAS-Parallel-Benchmarks-Profilling", "max_forks_repo_head_hexsha": "a94e52f9a1cb30b2f4668e08d90ca637ebee264c", "max_forks_repo_licenses": ["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.0652173913, "max_line_length": 70, "alphanum_fraction": 0.2161966739, "num_tokens": 273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044094, "lm_q2_score": 0.7490872075132152, "lm_q1q2_score": 0.6547600703261672}} {"text": " SUBROUTINE TRANEM (MCSID, NGRID, R, ICOMP, U, RC)\r\nC*****\r\nC COMPUTES A STRESS TRANSFORMATION MATRIX U FOR TRIANGLES AND QUADS.\r\nC INPUTS\r\nC MCSID ID OF COORDINATE SYSTEM REFERENCED ON MAT1,2 DATA CARD.\r\nC NGRID 3 FOR TRIANGLES, 4 FOR QUADS.\r\nC R ARRAY OF BASIC LOCATIONS OF ELEMENT GRID PTS (3,NGRID).\r\nC OUTPUTS\r\nC ICOMP 1 (IF MAT X-AXIS IS USED) OR 2 (IF Y-AXIS IS USED).\r\nC U ARRAY (3X3) FOR TRANSFORMATION, STORED BY ROW.\r\nC RC BASIC LOCATION COORDINATES OF ELEMENT CENTER.\r\nC REQUIREMENTS\r\nC SUBROUTINE PRETRS MUST SET UP FOR TRANSS. SEE P.M. PAGE 3.4-66\r\nC*****\r\n INTEGER ECPT(4),SUBNAM(2)\r\nC\r\n REAL RC(3)\r\n REAL R(9)\r\n REAL U(9)\r\n REAL RCENT(4)\r\nC\r\n EQUIVALENCE (RCENT(1), ECPT(1))\r\nC\r\n DATA SUBNAM /4HTRAN,2HEM/\r\nC\r\nC-----------------------------------------------------------------------\r\nC\r\n IF(NGRID .NE.3 .AND. NGRID.NE.4 ) CALL MESAGE(-61,0,SUBNAM)\r\nC*****\r\nC FIND THE UNIT NORMAL OF THE ELEMENT\r\nC*****\r\n I = 3*(NGRID-3)\r\n VN1 = (R(8)-R(2))*(R(I+9)-R(6))-(R(9)-R(3))*(R(I+8)-R(5))\r\n VN2 = (R(9)-R(3))*(R(I+7)-R(4))-(R(7)-R(1))*(R(I+9)-R(6))\r\n VN3 = (R(7)-R(1))*(R(I+8)-R(5))-(R(8)-R(2))*(R(I+7)-R(4))\r\n TEMP = SQRT(VN1**2+VN2**2+VN3**2)\r\n IF(TEMP .LE. 0.0) CALL MESAGE(-61,0,SUBNAM)\r\n VN1 = VN1 / TEMP\r\n VN2 = VN2 / TEMP\r\n VN3 = VN3 / TEMP\r\nC*****\r\nC GET THE UNIT VECTORS OF MCSID AT ELEM CENTER. PUT IN U TEMPORARILY\r\nC*****\r\n GRDS = NGRID\r\n DO 20 IC=1,3\r\n SUM = 0.0\r\n DO 10 IG=1,NGRID\r\n K = 3*IG + IC-3\r\n SUM = SUM +R(K)\r\n 10 CONTINUE\r\n RCENT(IC+1) = SUM / GRDS\r\n RC(IC) = RCENT(IC+1)\r\n 20 CONTINUE\r\n ECPT(1) = MCSID\r\n CALL TRANSS(ECPT,U)\r\nC*****\r\nC SELECT FIRST OR SECOND VECTOR TO PROJECT FOR ELEM-MAT X-AXIS\r\nC*****\r\n VNDOTM=VN1*U(1)+VN2*U(4)+VN3*U(7)\r\n IF( VNDOTM**2 .GT. 0.4) GO TO 30\r\n ICOMP = 1\r\n VM1 = U(1)\r\n VM2 = U(4)\r\n VM3 = U(7)\r\n GO TO 40\r\n 30 CONTINUE\r\n ICOMP = 2\r\n VM1 = U(2)\r\n VM2 = U(5)\r\n VM3 = U(8)\r\n VNDOTM = VN1*VM1+VN2*VM2+VN3*VM3\r\n 40 CONTINUE\r\nC*****\r\nC FIND COSINE AND SINE OF ANGLE\r\nC*****\r\n VE1 = R(4) - R(1)\r\n VE2 = R(5) - R(2)\r\n VE3 = R(6) - R(3)\r\n C = VE1*(VM1-VNDOTM*VN1)\r\n * + VE2*(VM2-VNDOTM*VN2)\r\n * + VE3*(VM3-VNDOTM*VN3)\r\n S = VE1*(VM2*VN3-VM3*VN2)\r\n * + VE2*(VM3*VN1-VM1*VN3)\r\n * + VE3*(VM1*VN2-VM2*VN1)\r\n TEMP = SQRT(C*C+S*S)\r\n IF(TEMP .LE. 0.0) CALL MESAGE(-61,0,SUBNAM)\r\n C = C/TEMP\r\n S = S/TEMP\r\nC*****\r\nC FILL IN THE U MATRIX, ROW STORED.\r\nC*****\r\n U(1) = C*C\r\n U(4) = S*S\r\n U(7) = -C*S\r\n U(2) = U(4)\r\n U(5) = U(1)\r\n U(8) = -U(7)\r\n U(3) = 2.0*U(8)\r\n U(6) = -U(3)\r\n U(9) = U(1)-U(4)\r\nC\r\n RETURN\r\nC\r\n END\r\n", "meta": {"hexsha": "e4c93493185b347ec74045513f365c89f128d904", "size": 2895, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "mis/tranem.f", "max_stars_repo_name": "ldallolio/NASTRAN-95", "max_stars_repo_head_hexsha": "6d2c175f5b53ebaec4ba2b5186f7926ef9d0ed47", "max_stars_repo_licenses": ["NASA-1.3"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2016-01-09T14:33:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-18T11:51:42.000Z", "max_issues_repo_path": "mis/tranem.f", "max_issues_repo_name": "gassive/NASTRAN95", "max_issues_repo_head_hexsha": "98cb3acaa7990d639360601648498834c7782056", "max_issues_repo_licenses": ["NASA-1.3"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2016-01-17T07:30:19.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-06T19:37:44.000Z", "max_forks_repo_path": "mis/tranem.f", "max_forks_repo_name": "gassive/NASTRAN95", "max_forks_repo_head_hexsha": "98cb3acaa7990d639360601648498834c7782056", "max_forks_repo_licenses": ["NASA-1.3"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-04-07T20:51:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T14:16:01.000Z", "avg_line_length": 27.5714285714, "max_line_length": 73, "alphanum_fraction": 0.4711571675, "num_tokens": 1188, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897542390751, "lm_q2_score": 0.6959583376458153, "lm_q1q2_score": 0.6547504734344418}} {"text": "*DECK RPQR79\n SUBROUTINE RPQR79 (NDEG, COEFF, ROOT, IERR, WORK)\nC***BEGIN PROLOGUE RPQR79\nC***PURPOSE Find the zeros of a polynomial with real coefficients.\nC***LIBRARY SLATEC\nC***CATEGORY F1A1A\nC***TYPE SINGLE PRECISION (RPQR79-S, CPQR79-C)\nC***KEYWORDS COMPLEX POLYNOMIAL, POLYNOMIAL ROOTS, POLYNOMIAL ZEROS\nC***AUTHOR Vandevender, W. H., (SNLA)\nC***DESCRIPTION\nC\nC Abstract\nC This routine computes all zeros of a polynomial of degree NDEG\nC with real coefficients by computing the eigenvalues of the\nC companion matrix.\nC\nC Description of Parameters\nC The user must dimension all arrays appearing in the call list\nC COEFF(NDEG+1), ROOT(NDEG), WORK(NDEG*(NDEG+2))\nC\nC --Input--\nC NDEG degree of polynomial\nC\nC COEFF REAL coefficients in descending order. i.e.,\nC P(Z)= COEFF(1)*(Z**NDEG) + COEFF(NDEG)*Z + COEFF(NDEG+1)\nC\nC WORK REAL work array of dimension at least NDEG*(NDEG+2)\nC\nC --Output--\nC ROOT COMPLEX vector of roots\nC\nC IERR Output Error Code\nC - Normal Code\nC 0 means the roots were computed.\nC - Abnormal Codes\nC 1 more than 30 QR iterations on some eigenvalue of the\nC companion matrix\nC 2 COEFF(1)=0.0\nC 3 NDEG is invalid (less than or equal to 0)\nC\nC***REFERENCES (NONE)\nC***ROUTINES CALLED HQR, XERMSG\nC***REVISION HISTORY (YYMMDD)\nC 800601 DATE WRITTEN\nC 890505 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\nC 911010 Code reworked and simplified. (RWC and WRB)\nC***END PROLOGUE RPQR79\n REAL COEFF(*), WORK(*), SCALE\n COMPLEX ROOT(*)\n INTEGER NDEG, IERR, K, KH, KWR, KWI, KCOL\nC***FIRST EXECUTABLE STATEMENT RPQR79\n IERR = 0\n IF (ABS(COEFF(1)) .EQ. 0.0) THEN\n IERR = 2\n CALL XERMSG ('SLATEC', 'RPQR79',\n + 'LEADING COEFFICIENT IS ZERO.', 2, 1)\n RETURN\n ENDIF\nC\n IF (NDEG .LE. 0) THEN\n IERR = 3\n CALL XERMSG ('SLATEC', 'RPQR79', 'DEGREE INVALID.', 3, 1)\n RETURN\n ENDIF\nC\n IF (NDEG .EQ. 1) THEN\n ROOT(1) = CMPLX(-COEFF(2)/COEFF(1),0.0)\n RETURN\n ENDIF\nC\n SCALE = 1.0E0/COEFF(1)\n KH = 1\n KWR = KH+NDEG*NDEG\n KWI = KWR+NDEG\n KWEND = KWI+NDEG-1\nC\n DO 10 K=1,KWEND\n WORK(K) = 0.0E0\n 10 CONTINUE\nC\n DO 20 K=1,NDEG\n KCOL = (K-1)*NDEG+1\n WORK(KCOL) = -COEFF(K+1)*SCALE\n IF (K .NE. NDEG) WORK(KCOL+K) = 1.0E0\n 20 CONTINUE\nC\n CALL HQR (NDEG,NDEG,1,NDEG,WORK(KH),WORK(KWR),WORK(KWI),IERR)\nC\n IF (IERR .NE. 0) THEN\n IERR = 1\n CALL XERMSG ('SLATEC', 'CPQR79',\n + 'NO CONVERGENCE IN 30 QR ITERATIONS.', 1, 1)\n RETURN\n ENDIF\nC\n DO 30 K=1,NDEG\n KM1 = K-1\n ROOT(K) = CMPLX(WORK(KWR+KM1),WORK(KWI+KM1))\n 30 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "aab212c6643873eb77ce470abb484b3dcd2f8ccb", "size": 3013, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/rpqr79.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/rpqr79.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/rpqr79.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.9711538462, "max_line_length": 71, "alphanum_fraction": 0.5907733156, "num_tokens": 1111, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476793890012, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6547196563543236}} {"text": "module dg2d_problem\n\n\n use fsystem\n use storage\n\n implicit none\n\n real(dp), parameter :: g = 1.0_dp\n\n\n\ncontains\n\n\n ! This function returns the Roe mean values\n function calculateQroe(Ql, Qr) result(Qroe)\n\n ! The left and right Q values\n ! The solution components q1 = h, q2 = uh, q3 = vh\n real(DP), dimension(3), intent(IN)\t\t:: Ql, Qr\n\n ! The computed Roe values\n real(DP), dimension(3)\t\t\t\t\t:: Qroe\n\n ! temp variables\n real(DP)\t\t:: whl, whr, denom, hl, hr\n\n ! Choose kind of mean value\n integer, parameter :: mvk = 0\n\n\n select case (mvk)\n\n case (0) ! Roe-meanvalues\n\n ! Set the height variables\n hl=Ql(1)\n hr=Qr(1)\n\n denom = sqrt(hl)+sqrt(hr)\n whl = 1.0_DP/sqrt(hl)\n whr = 1.0_DP/sqrt(hr)\n\n Qroe(1) = sqrt(hl*hr)\n Qroe(2) = Qroe(1)*(whl*Ql(2)+whr*Qr(2))/denom\n Qroe(3) = Qroe(1)*(whl*Ql(3)+whr*Qr(3))/denom\n\n case (1) ! Artihmetic mean\n\n Qroe = 0.5_dp*(Ql+Qr)\n\n case (2) ! Roe-meanvalues\n\n ! Set the height variables\n hl=Ql(1)\n hr=Qr(1)\n\n denom = sqrt(hl)+sqrt(hr)\n whl = 1.0_DP/sqrt(hl)\n whr = 1.0_DP/sqrt(hr)\n\n Qroe(1) = 0.5_dp*(hl+hr)\n Qroe(2) = Qroe(1)*(whl*Ql(2)+whr*Qr(2))/denom\n Qroe(3) = Qroe(1)*(whl*Ql(3)+whr*Qr(3))/denom\n\n end select\n\n end function calculateQroe\n\n\n\n ! This routine builds the jacobi matrix DF of the flux in direction d\n ! d=1: x-direction, d=2: y-direction\n function buildJacobi(Q,d) result(J)\n\n ! The jacobi matrix in direction d\n real(DP), dimension(3,3)\t:: J\n\n ! The solution components q1 = h, q2 = uh, q3 = vh\n real(DP), dimension(3), intent(IN)\t\t:: q\n\n integer, intent(IN) :: d\n\n ! primitive variables\n real(DP) :: h, u, v, c\n\n ! Calculate primitive variables\n h=Q(1)\n ! if (hSR) then\n ! write(*,*) 'Warning**************'\n ! end if\n ! if (SL>SS) then\n ! write(*,*) 'Warning'\n ! end if\n ! if (SS>SR) then\n ! write(*,*) 'Warning'\n ! end if\n !\n ! FX = Euler_buildFlux(Qa+Qi,1)\n !\n ! if (SL.ge.0.0_dp) then\n ! FX = Euler_buildFlux(Qi,1)\n ! elseif ((SL<0.0_dp).and.(SS.ge.0.0_dp)) then\n ! FX = Euler_buildFlux(Qi,1) + SL*( rhoi*(SL-ui)/min((SL-SS),-SYS_EPSREAL_DP)*(/ 1.0_dp, SS, vi, Ei/rhoi+(SS-ui)*(SS+pi/(rhoi*(SL-ui))) /) -Qi)\n ! elseif ((SS<0.0_dp).and.(SR>0.0_dp)) then\n ! FX = Euler_buildFlux(Qa,1) + SR*( rhoa*(SR-ua)/max((SR-SS),SYS_EPSREAL_DP)*(/ 1.0_dp, SS, va, Ea/rhoa+(SS-ua)*(SS+pa/(rhoa*(SR-ua))) /) -Qa)\n ! elseif (SR.le.0.0_dp) then\n ! FX = Euler_buildFlux(Qa,1)\n ! end if\n\n\n\n\n\n\n ! !!! Type 2 !!!\n !\n !\n ! ps = 0.5_dp*(pi+pa)+0.5_dp*(ui-ua)*0.5_dp*(rhoi+rhoa)*0.5_dp*(ci+ca)\n ! us = 0.5_dp*(ui+ua)+0.5_dp*(pi-pa)/(0.5_dp*(rhoi+rhoa)*0.5_dp*(ci+ca))\n !\n ! if (ps>pi) then\n ! ql = sqrt(max(1.0_dp+(gamma+1.0_dp)/(2.0_dp*gamma)*(ps/pi-1.0_dp),0.0_dp))\n ! else\n ! ql = 1.0_dp\n ! end if\n !\n ! if (ps>pa) then\n ! qr = sqrt(max(1.0_dp+(gamma+1.0_dp)/(2.0_dp*gamma)*(ps/pa-1.0_dp),0.0_dp))\n ! else\n ! qr = 1.0_dp\n ! end if\n !\n !\n !\n !\n ! ! Compute estimate wave speeds\n ! SL = ui-ci*ql\n ! SR = ua+ca*qr\n ! SS = us\n !\n !! SS = max(SS,SL)\n !! SS = min(SS,SR)\n !\n !\n !\n ! if (SL.ge.0.0_dp) then\n ! FX = Euler_buildFlux(Qi,1)\n ! elseif ((SL<0.0_dp).and.(SS.ge.0.0_dp)) then\n ! FX = Euler_buildFlux(Qi,1) + SL*( rhoi*(SL-ui)/min((SL-SS),-SYS_EPSREAL_DP)*(/ 1.0_dp, SS, vi, Ei/rhoi+(SS-ui)*(SS+pi/(rhoi*(SL-ui))) /) -Qi)\n ! elseif ((SS<0.0_dp).and.(SR>0.0_dp)) then\n ! FX = Euler_buildFlux(Qa,1) + SR*( rhoa*(SR-ua)/max((SR-SS),SYS_EPSREAL_DP)*(/ 1.0_dp, SS, va, Ea/rhoa+(SS-ua)*(SS+pa/(rhoa*(SR-ua))) /) -Qa)\n ! elseif (SR.le.0.0_dp) then\n ! FX = Euler_buildFlux(Qa,1)\n ! else\n ! FX = 0.5_dp*Euler_buildFlux(0.5_dp*(Qi+Qa),1)\n ! end if\n !\n !\n ! if(SL>SR) then\n ! write(*,*) 'Warning**************'\n ! end if\n ! if (SL>SS) then\n ! write(*,*) 'Warning'\n ! end if\n ! if (SS>SR) then\n ! write(*,*) 'Warning'\n ! end if\n\n\n\n ! Type 3\n SL = min(ui - ci,ua-ca)\n SR = max(ua + ca,ui+ci)\n SS = ( rhoa*ua*(SR-ua)-rhoi*ui*(SL-ui)+pi-pa )/(rhoa*(SR-ua)-rhoi*(SL-ui))\n\n ps = rhoi*(SL-ui)*(SS-ui)+pi\n\n\n FX = 0.5_dp*(Euler_buildFlux(Qi,1)+Euler_buildFlux(Qa,1) -ui*Qi+(/ 0.0_dp,ps-pi,0.0_dp,ps*SS-pi*ui /) &\n -ua*Qa+(/ 0.0_dp,ps-pa,0.0_dp,ps*SS-pa*ua /) )\n\n\n\n\n\n\n ! Rotate back\n Flux(1) = FX(1)\n Flux(2) = a*FX(2)-b*FX(3)\n Flux(3) = b*FX(2)+a*FX(3)\n Flux(4) = FX(4)\n\n\n\n end function Euler_buildFlux_HLLC2D\n\n\n\n\n\n\n\n\n !*****************************************************************************\n !* -- Roe's Flux Function ---\n !*\n !* P. L. Roe, Approximate Riemann Solvers, Parameter Vectors and Difference\n !* Schemes, Journal of Computational Physics, 43, pp. 357-372.\n !*\n !* Katate Masatsuka, February 2009. http://www.cfdbooks.com\n !*****************************************************************************\n function Roe(uL, uR, nx, ny)\n real(dp) :: uL(4), uR(4) ! Input: conservative variables rho*[1, u, v, E]\n real(dp) :: nx, ny ! Input: face normal vector, [nx, ny] (Left-to-Right)\n real(dp) :: Roe(4) ! Output: Roe flux function (upwind)\n !Local constants\n real(dp) :: gamma ! Ratio of specific heat.\n real(dp) :: zero, fifth, half, one, two ! Numbers\n !Local variables\n real(dp) :: tx, ty ! Tangent vector (perpendicular to the face normal)\n real(dp) :: vxL, vxR, vyL, vyR ! Velocity components.\n real(dp) :: rhoL, rhoR, pL, pR ! Primitive variables.\n real(dp) :: vnL, vnR, vtL, vtR ! Normal and tangent velocities\n real(dp) :: aL, aR, HL, HR ! Speeds of sound.\n real(dp) :: RT,rho,vx,vy,H,a,vn, vt ! Roe-averages\n real(dp) :: drho,dvx,dvy,dvn,dvt,dpp,dV(4) ! Wave strenghs\n real(dp) :: ws(4),dws(4), Rv(4,4) ! Wave speeds and right-eigevectors\n real(dp) :: fL(4), fR(4), diss(4) ! Fluxes ad dissipation term\n integer :: i, j\n\n !Constants.\n gamma = 1.4_dp\n zero = 0.0_dp\n fifth = 0.2_dp\n half = 0.5_dp\n one = 1.0_dp\n two = 2.0_dp\n\n !Tangent vector (Do you like it? Actually, Roe flux can be implemented\n ! without any tangent vector. See \"I do like CFD, VOL.1\" for details.)\n tx = -ny\n ty = nx\n\n !Primitive and other variables.\n ! Left state\n rhoL = uL(1)\n vxL = uL(2)/uL(1)\n vyL = uL(3)/uL(1)\n vnL = vxL*nx+vyL*ny\n vtL = vxL*tx+vyL*ty\n pL = (gamma-one)*( uL(4) - half*rhoL*(vxL*vxL+vyL*vyL) )\n aL = sqrt(gamma*pL/rhoL)\n HL = ( uL(4) + pL ) / rhoL\n ! Right state\n rhoR = uR(1)\n vxR = uR(2)/uR(1)\n vyR = uR(3)/uR(1)\n vnR = vxR*nx+vyR*ny\n vtR = vxR*tx+vyR*ty\n pR = (gamma-one)*( uR(4) - half*rhoR*(vxR*vxR+vyR*vyR) )\n aR = sqrt(gamma*pR/rhoR)\n HR = ( uR(4) + pR ) / rhoR\n\n !First compute the Roe Averages\n RT = sqrt(rhoR/rhoL)\n rho = RT*rhoL\n vx = (vxL+RT*vxR)/(one+RT)\n vy = (vyL+RT*vyR)/(one+RT)\n H = ( HL+RT* HR)/(one+RT)\n a = sqrt( (gamma-one)*(H-half*(vx*vx+vy*vy)) )\n vn = vx*nx+vy*ny\n vt = vx*tx+vy*ty\n\n !Wave Strengths\n drho = rhoR - rhoL\n dpp = pR - pL\n dvn = vnR - vnL\n dvt = vtR - vtL\n\n dV(1) = (dpp - rho*a*dvn )/(two*a*a)\n dV(2) = rho*dvt/a\n dV(3) = drho - dpp/(a*a)\n dV(4) = (dpp + rho*a*dvn )/(two*a*a)\n\n !Wave Speed\n ws(1) = abs(vn-a)\n ws(2) = abs(vn)\n ws(3) = abs(vn)\n ws(4) = abs(vn+a)\n\n !Harten's Entropy Fix JCP(1983), 49, pp357-393:\n ! only for the nonlinear fields.\n dws(1) = fifth\n if ( ws(1) < dws(1) ) ws(1) = half * ( ws(1)*ws(1)/dws(1)+dws(1) )\n dws(4) = fifth\n if ( ws(4) < dws(4) ) ws(4) = half * ( ws(4)*ws(4)/dws(4)+dws(4) )\n\n !Right Eigenvectors\n Rv(1,1) = one\n Rv(2,1) = vx - a*nx\n Rv(3,1) = vy - a*ny\n Rv(4,1) = H - vn*a\n\n Rv(1,2) = zero\n Rv(2,2) = a*tx\n Rv(3,2) = a*ty\n Rv(4,2) = vt*a\n\n Rv(1,3) = one\n Rv(2,3) = vx\n Rv(3,3) = vy\n Rv(4,3) = half*(vx*vx+vy*vy)\n\n Rv(1,4) = one\n Rv(2,4) = vx + a*nx\n Rv(3,4) = vy + a*ny\n Rv(4,4) = H + vn*a\n\n !Dissipation Term\n diss = zero\n do i=1,4\n do j=1,4\n diss(i) = diss(i) + ws(j)*dV(j)*Rv(i,j)\n end do\n end do\n\n !Compute the flux.\n fL(1) = rhoL*vnL\n fL(2) = rhoL*vnL * vxL + pL*nx\n fL(3) = rhoL*vnL * vyL + pL*ny\n fL(4) = rhoL*vnL * HL\n\n fR(1) = rhoR*vnR\n fR(2) = rhoR*vnR * vxR + pR*nx\n fR(3) = rhoR*vnR * vyR + pR*ny\n fR(4) = rhoR*vnR * HR\n\n Roe = half * (fL + fR - diss)\n\n end function Roe\n \n \n \n function DRoe(uL, uR, nx, ny, h)\n real(dp) :: uL(4), uR(4) ! Input: conservative variables rho*[1, u, v, E]\n real(dp) :: nx, ny ! Input: face normal vector, [nx, ny]\n real(dp) :: h ! Input: infinitesimal constant\n real(dp), dimension(4,8) :: DRoe ! Output: Approximate differential of Roe flux function\n \n real(dp), dimension(4) :: F, U\n integer :: i\n \n F = Roe(uL, uR, nx, ny)\n \n ! First order approx\n do i = 1,4\n U = uL\n U(i) = U(i) + h\n DRoe(:,i) = (Roe(U, uR, nx, ny) - F)/h\n end do\n \n do i = 1,4\n U = uR\n U(i) = U(i) + h\n DRoe(:,i+4) = (Roe(uL, U, nx, ny) - F)/h\n end do\n\n! ! Second order approx\n! do i = 1,4\n! U = uL\n! U(i) = U(i) + h\n! DRoe(:,i) = Roe(U, uR, nx, ny)\n! U = uL\n! U(i) = U(i) - h\n! DRoe(:,i) = 0.5_dp*(DRoe(:,i)-Roe(U, uR, nx, ny))/h\n! end do\n! \n! do i = 1,4\n! U = uR\n! U(i) = U(i) + h\n! DRoe(:,i+4) = Roe(uL, U, nx, ny)\n! U = uR\n! U(i) = U(i) - h\n! DRoe(:,i+4) = 0.5_dp*(DRoe(:,i+4)-Roe(uL, U, nx, ny))/h\n! end do\n \n end function Droe\n\n\n !*****************************************************************************\n !* -- Rotated-Roe-HLL Flux Function ---\n !*\n !* H. Nishikawa and K. Kitamura, Very Simple, Carbuncle-Free, Boundary-Layer\n !* Resolving, Rotated-Hybrid Riemann Solvers,\n !* Journal of Computational Physics, 227, pp. 2560-2581, 2008.\n !*\n !* The most robust Riemann solver known to the author (in terms of nonlinear\n !* instability such as carbuncle).\n !*\n !* NB: At a boundary face, need to switch to a geometric normal vector:\n !* (nx2,ny2)=(nx, ny), (nx1,ny1)=(-ny,nx).\n !* This is not implemented here. It requires information on whether\n !* the geometric normal, (nx,ny), is on a boundary face or not.\n !* It shouldn't be difficult for you to implement it.\n !*\n !* Katate Masatsuka, February 2010. http://www.cfdbooks.com\n !*****************************************************************************\n function Rotated_RHLL(uL, uR, nx, ny)\n real(dp) :: uL(4), uR(4) ! Input: conservative variables rho*[1, u, v, E]\n real(dp) :: nx, ny ! Input: face normal vector, [nx, ny] (Left-to-Right)\n real(dp) :: Rotated_RHLL(4) ! Output: Rotated_RHLL flux function.\n !Local constants\n real(dp) :: gamma ! Ratio of specific heat.\n real(dp) :: zero, fifth, half, one, two ! Numbers\n real(dp) :: eps !\n !Local variables\n real(dp) :: nx1, ny1, nx2, ny2 ! Rotated normals, n1 and n2\n real(dp) :: tx, ty ! Tangent vector (taken as n1)\n real(dp) :: alpha1, alpha2 ! Projections of the new normals\n real(dp) :: vxL, vxR, vyL, vyR ! Velocity components.\n real(dp) :: rhoL, rhoR, pL, pR ! Primitive variables.\n real(dp) :: vnL, vnR, vtL, vtR ! Normal and tagent velocities\n real(dp) :: aL, aR, HL, HR ! Speeds of sound and total enthalpy\n real(dp) :: RT,rho,vx,vy,H,a ! Roe-averages\n real(dp) :: vn, vt ! Normal and tagent velocities(Roe-average)\n real(dp) :: drho,dvx,dvy,dvn,dvt,dpp,dV(4) ! Wave strenghs\n real(dp) :: abs_dq ! Magnitude of the velocity difference\n real(dp) :: abs_ws(4),ws(4),dws(4), Rv(4,4)! Wave speeds and right-eigevectors\n real(dp) :: SRp,SLm ! Wave speeds for the HLL part\n real(dp) :: fL(4), fR(4), diss(4) ! Fluxes ad dissipation term\n real(dp) :: temp\n integer :: i, j\n\n !Constants.\n gamma = 1.4_dp\n zero = 0.0_dp\n fifth = 0.2_dp\n half = 0.5_dp\n one = 1.0_dp\n two = 2.0_dp\n eps = 1.0e-12_dp ! 1.0e-12 in the original paper (double precision)\n\n !Primitive and other variables.\n ! Left state\n rhoL = uL(1)\n vxL = uL(2)/uL(1)\n vyL = uL(3)/uL(1)\n pL = (gamma-one)*( uL(4) - half*rhoL*(vxL*vxL+vyL*vyL) )\n pL = max(0.0_dp,pL)\n aL = sqrt(gamma*pL/rhoL)\n HL = ( uL(4) + pL ) / rhoL\n ! Right state\n rhoR = uR(1)\n vxR = uR(2)/uR(1)\n vyR = uR(3)/uR(1)\n pR = (gamma-one)*( uR(4) - half*rhoR*(vxR*vxR+vyR*vyR) )\n pR = max(0.0_dp,pR)\n aR = sqrt(gamma*pR/rhoR)\n HR = ( uR(4) + pR ) / rhoR\n\n vnL = vxL*nx + vyL*ny\n vnR = vxR*nx + vyR*ny\n\n !Compute the flux.\n fL(1) = rhoL*vnL\n fL(2) = rhoL*vnL * vxL + pL*nx\n fL(3) = rhoL*vnL * vyL + pL*ny\n fL(4) = rhoL*vnL * HL\n\n fR(1) = rhoR*vnR\n fR(2) = rhoR*vnR * vxR + pR*nx\n fR(3) = rhoR*vnR * vyR + pR*ny\n fR(4) = rhoR*vnR * HR\n\n !Define n1 and n2, and compute alpha1 and alpha2: (4.2) in the original paper.\n !(NB: n1 and n2 may need to be frozen at some point during\n ! a steady calculation to fully make it converge. For time-accurate\n ! calculation, this is fine.)\n ! NB: For a boundary face, set (nx2,ny2)=(nx,ny), (nx1,ny1)=(-ny,nx).\n\n abs_dq = sqrt( (vxR-vxL)**2+(vyR-vyL)**2 )\n if ( abs_dq > eps) then\n nx1 = (vxR-vxL)/abs_dq\n ny1 = (vyR-vyL)/abs_dq\n else\n nx1 = -ny\n ny1 = nx\n endif\n alpha1 = nx * nx1 + ny * ny1\n ! To make alpha1 always positive.\n temp = sign(one,alpha1)\n nx1 = temp * nx1\n ny1 = temp * ny1\n alpha1 = temp * alpha1\n\n ! Take n2 as perpendicular to n1.\n nx2 = -ny1\n ny2 = nx1\n alpha2 = nx * nx2 + ny * ny2\n ! To make alpha2 always positive.\n temp = sign(one,alpha2)\n nx2 = temp * nx2\n ny2 = temp * ny2\n alpha2 = temp * alpha2\n\n !Now we are going to compute the Roe flux with n2 as the normal\n !and n1 as the tagent vector, with modified wave speeds (5.12)\n\n !Compute the Roe Averages\n RT = sqrt(rhoR/rhoL)\n rho = RT*rhoL\n vx = (vxL+RT*vxR)/(one+RT)\n vy = (vyL+RT*vyR)/(one+RT)\n H = ( HL+RT* HR)/(one+RT)\n a = sqrt( max(0.0_dp,(gamma-one)*(H-half*(vx*vx+vy*vy))) )\n vn = vx*nx2+vy*ny2\n vt = vx*nx1+vy*ny1\n\n !Wave Strengths (remember that n2 is the normal and n1 is the tangent.)\n vnL = vxL*nx2 + vyL*ny2\n vnR = vxR*nx2 + vyR*ny2\n vtL = vxL*nx1 + vyL*ny1\n vtR = vxR*nx1 + vyR*ny1\n\n drho = rhoR - rhoL\n dpp = pR - pL\n dvn = vnR - vnL\n dvt = vtR - vtL\n\n a = max(a,1.0e-12)\n\n dV(1) = (dpp - rho*a*dvn )/(two*a*a)\n dV(2) = rho*dvt/a\n dV(3) = drho - dpp/(a*a)\n dV(4) = (dpp + rho*a*dvn )/(two*a*a)\n\n !Wave Speeds for Roe flux part.\n ws(1) = vn-a\n ws(2) = vn\n ws(3) = vn\n ws(4) = vn+a\n abs_ws = abs(ws)\n\n !Harten's Entropy Fix JCP(1983), 49, pp357-393:\n !only for the nonlinear fields.\n dws(1) = fifth\n if (abs_ws(1)\n!\n! See the file LICENCE for licence details.\n!===============================================================================\nmodule statistical\n!===============================================================================\n! Contains statistical functions\n! Andy Nowacki, University of Bristol\n!\n! 2011-06-13 + First iteration. Includes F-distribution, Beta- (B), regularized\n! Beta- (I) and incomplete Beta-functions\n! 2011-06-17 + Added functions from Alan Miller's website to compute percentage\n! values for the chi2 distribution.\n! 2011-08-09 + Added circular statistical functions.\n\n! Declare public functions\n! public f_dist\n\n! Declare some internal constants\n! ** size constants\n integer, parameter, private :: i4 = selected_int_kind(9) ; ! long int\n integer, parameter, private :: r4 = selected_real_kind(6,37) ; ! SP\n integer, parameter, private :: r8 = selected_real_kind(15,307) ; ! DP\n integer, parameter, private :: c4 = r4\n integer, parameter, private :: c8 = r8\n\n! ** precision selector\n integer, parameter, private :: rs = r8\n integer, parameter, private :: cs = c8\n\n! ** maths constants and other useful things\n real(rs), parameter, private :: pi = 3.141592653589793238462643_rs\n\n! ** IO units\n integer, parameter, private :: lu_stdout = 5\n integer, parameter, private :: lu_stdin = 6\n integer, parameter, private :: lu_stderr = 0\n\ncontains\n\n!===============================================================================\nfunction fact12(n)\n!===============================================================================\n! Gives true integer value for n!, n <= 12\n implicit none\n integer,intent(in) :: n\n integer :: fact12,i\n\n if (n < 0) then\n write(lu_stderr,'(a)') 'statistical: fact: error: n must be >= 0.'\n stop\n else if (n == 0) then\n fact12 = 1\n return\n else if (n > 12) then\n write(lu_stderr,'(a)') 'statistical: fact: error: n cannot be larger than 12 for 4-byte integer calculations.'\n stop\n endif\n fact12 = 1\n do i=1,n\n fact12 = i*fact12\n enddo\n return\nend function fact12\n!-------------------------------------------------------------------------------\n\n!===============================================================================\nfunction fact(n)\n!===============================================================================\n! Gives approximate value of n! up to n<170\n! fact(n) \u2248 exp{n.ln(n) - n + ln(n(1 + 4n(1 + 2n)))/6 + ln(pi)/2}\n! Approximation given by Ramanujan (1988)\n! Good to within ~1e-5 of integer value up to n=12.\n implicit none\n integer,intent(in) :: n\n real(rs) :: fact,rn\n\n if (n == 0) then\n fact = 1._rs\n return\n else if (n < 0) then\n write(lu_stderr,'(a)') 'statistical: fact: error: n must be >= 0.'\n stop\n else if (n > 0 .and. n <= 12) then\n fact = real(fact12(n))\n return\n else if (n > 170) then\n write(lu_stderr,'(a)') 'statistical: fact: error: cannot represent n! in double precision for n > 170.'\n stop\n endif\n\n rn = real(n)\n fact = exp(n*log(rn) - rn + log(rn*(1._rs + 4._rs*rn*(1._rs + 2._rs*rn)))/6._rs &\n + log(pi)/2._rs)\n return\nend function fact\n!-------------------------------------------------------------------------------\n\n!===============================================================================\nfunction stat_poisson_pmf(lambda, k)\n!===============================================================================\n! Return the probability mass function for the Poisson distribution with mean\n! lambda at integer point k\n implicit none\n real(rs), intent(in) :: lambda\n integer, intent(in) :: k\n real(rs) :: stat_poisson_pmf\n stat_poisson_pmf = lambda**k*exp(-lambda)/fact(k)\nend function stat_poisson_pmf\n!-------------------------------------------------------------------------------\n\n!===============================================================================\nfunction beta_func(p,q)\n!===============================================================================\n! Returns the Beta function B(p,q) = Gamma(p)*Gamma(q) / Gamma(p+q)\n implicit none\n real(rs),intent(in) :: p,q\n real(rs) :: beta_func,rp,rq\n\n rp = real(p) ; rq = real(q)\n beta_func = gamma(rp) * gamma(rq) / gamma(rp + rq)\n return\nend function beta_func\n!-------------------------------------------------------------------------------\n\n!===============================================================================\nfunction incomp_beta_func(z,a,b)\n!===============================================================================\n! Returns the incomplete Beta function B(z;a,b) = \u222b_0^z(u^(a-1)*(1-u)^(b-1))du\n implicit none\n real(rs),intent(in) :: z,a,b\n real(rs) :: incomp_beta_func,ra,rb,rn\n real(rs) :: u,du ! Dummy variable of integration\n integer :: n\n\n ra = real(a)\n rb = real(b)\n if (z <= 0. .or. z > 1.) then\n write(lu_stderr,'(a)') 'statistical: incomp_beta_func: error: z must be in range [0,1].'\n stop\n endif\n du = 0.000001_rs\n u = 0._rs\n incomp_beta_func = 0._rs\n do while (u <= z)\n incomp_beta_func = incomp_beta_func + (u**(a-1._rs))*((1._rs-u)**(b-1._rs))*du\n u = u + du\n enddo\n incomp_beta_func = incomp_beta_func / beta_func(a,b)\n return\nend function incomp_beta_func\n!-------------------------------------------------------------------------------\n\n!===============================================================================\nfunction reg_beta_func(z,a,b)\n!===============================================================================\n! Returns the regularised Beta function B(a,b) = B(z;a,b)/B(a,b)\n implicit none\n real(rs),intent(in) :: z,a,b\n real(rs) :: reg_beta_func\n\n reg_beta_func = incomp_beta_func(z,a,b) / beta_func(a,b)\n return\nend function reg_beta_func\n!-------------------------------------------------------------------------------\n\n!===============================================================================\nfunction pochhammer(x,n)\n!===============================================================================\n! Give the Pochhhammer symbol p(x)_n == gamma(x+n)/gamma(x)\n implicit none\n real(rs),intent(in) :: x\n integer,intent(in) :: n\n real(rs) :: pochhammer,rn\n\n rn = real(n)\n pochhammer = gamma(x+rn)/gamma(x)\n return\nend function pochhammer\n!-------------------------------------------------------------------------------\n\n!===============================================================================\nfunction f_dist(n,m,x)\n!===============================================================================\n! Returns the value of the f distribution f(n,m,x)\n implicit none\n integer :: m,n\n real(rs) :: x\n real(rs) :: f_dist\n real(rs) :: rn,rm,half,one\n\n if (x <= 0.) then\n write(lu_stderr,'(a)') 'statistical: f_dist: error: x must be > 0.'\n stop\n endif\n\n! Convert input integers into real values and set value of half\n rn = real(n)\n rm = real(m)\n half = 0.5_rs\n one = 1.0_rs\n\n f_dist = gamma(half*(rn+rm)) * rn**(half*rn) * rm**(half*rm) * x**(half*rn - one) / &\n (gamma(half*rn) * gamma(half*rm) * (rm+rn*x)**(half*(rn + rm)))\n return\nend function f_dist\n!-------------------------------------------------------------------------------\n\n!===============================================================================\nfunction f_dist_cum(n,m,x)\n!===============================================================================\n! Returns the value of the cumulative F distribution F(n,m,x)\n implicit none\n integer,intent(in) :: m,n\n real(rs),intent(in) :: x\n real(rs) :: f_dist_cum,u,du\n real(rs) :: rm,rn\n! Convert input integers into real values\n rm = real(m)\n rn = real(n)\n\n! f_dist_cum = reg_beta_func(rn*x/(rm+rn*x), rn*0.5_rs, rm*0.5_rs)\n f_dist_cum = 0._rs\n du = 0.0001_rs\n u = 0._rs + du\n do while (u <= x)\n f_dist_cum = f_dist_cum + f_dist(n,m,u)*du\n u = u + du\n enddo\n return\nend function f_dist_cum\n!-------------------------------------------------------------------------------\n\n!===============================================================================\n!===============================================================================\n! The following functions are taken from Alan Miller's page at:\n! http://jblevins.org/mirror/amiller/\n! All are transcriptions into Fortran of algorithms plublished in the Royal Statistical\n! Society's Applied Statitstics journal.\n\n!===============================================================================\nfunction ppchi2(p, v, g) RESULT(fn_val)\n!===============================================================================\n! N.B. Argument IFAULT has been removed.\n! This version by Alan Miller\n! amiller @ bigpond.net.au\n! Latest revision - 27 October 2000\n! Algorithm AS 91 Appl. Statist. (1975) Vol.24, P.35\n!\n! To evaluate the percentage points of the chi-squared\n! probability distribution function.\n!\n! p must lie in the range 0.000002 to 0.999998,\n! v must be positive,\n! g must be supplied and should be equal to ln(gamma(v/2.0))\n!\n! Incorporates the suggested changes in AS R85 (vol.40(1), pp.233-5, 1991)\n! which should eliminate the need for the limited range for p above,\n! though these limits have not been removed from the routine.\n!\n! If IFAULT = 4 is returned, the result is probably as accurate as\n! the machine will allow.\n!\n! Auxiliary routines required: PPND = AS 111 (or AS 241) and GAMMAD = AS 239.\n\n IMPLICIT NONE\n INTEGER, PARAMETER :: dp = rs\n\n REAL (dp), INTENT(IN) :: p\n REAL (dp), INTENT(IN) :: v\n REAL (dp), INTENT(IN) :: g\n REAL (dp) :: fn_val\n\n! AJN: don't need interface as we're in a module.\n! INTERFACE\n! FUNCTION gammad(x, p) RESULT(fn_val)\n! IMPLICIT NONE\n! INTEGER, PARAMETER :: dp = rs\n! REAL (dp), INTENT(IN) :: x, p\n! REAL (dp) :: fn_val\n! END FUNCTION gammad\n!\n! SUBROUTINE ppnd16 (p, normal_dev, ifault)\n! IMPLICIT NONE\n! INTEGER, PARAMETER :: dp = rs\n! REAL (dp), INTENT(IN) :: p\n! INTEGER, INTENT(OUT) :: ifault\n! REAL (dp), INTENT(OUT) :: normal_dev\n! END SUBROUTINE ppnd16\n! END INTERFACE\n\n! Local variables\n\n REAL (dp) :: a, b, c, p1, p2, q, s1, s2, s3, s4, s5, s6, t, x, xx\n INTEGER :: i, if1\n\n INTEGER, PARAMETER :: maxit = 20\n REAL (dp), PARAMETER :: aa = 0.6931471806_dp, e = 0.5e-06_dp, &\n pmin = 0.000002_dp, pmax = 0.999998_dp, &\n zero = 0.0_dp, half = 0.5_dp, one = 1.0_dp, &\n two = 2.0_dp, three = 3.0_dp, six = 6.0_dp, &\n c1 = 0.01_dp, c2 = 0.222222_dp, c3 = 0.32_dp, &\n c4 = 0.4_dp, c5 = 1.24_dp, c6 = 2.2_dp, &\n c7 = 4.67_dp, c8 = 6.66_dp, c9 = 6.73_dp, &\n c10 = 13.32_dp, c11 = 60.0_dp, c12 = 70.0_dp, &\n c13 = 84.0_dp, c14 = 105.0_dp, c15 = 120.0_dp, &\n c16 = 127.0_dp, c17 = 140.0_dp, c18 = 175.0_dp, &\n c19 = 210.0_dp, c20 = 252.0_dp, c21 = 264.0_dp, &\n c22 = 294.0_dp, c23 = 346.0_dp, c24 = 420.0_dp, &\n c25 = 462.0_dp, c26 = 606.0_dp, c27 = 672.0_dp, &\n c28 = 707.0_dp, c29 = 735.0_dp, c30 = 889.0_dp, &\n c31 = 932.0_dp, c32 = 966.0_dp, c33 = 1141.0_dp, &\n c34 = 1182.0_dp, c35 = 1278.0_dp, c36 = 1740.0_dp, &\n c37 = 2520.0_dp, c38 = 5040.0_dp\n\n! Test arguments and initialise\n fn_val = -one\n IF (p < pmin .OR. p > pmax) THEN\n WRITE(lu_stderr,'(a)') 'statistical: PPCHI2: error: p must be between 0.000002 & 0.999998'\n stop !RETURN\n END IF\n IF (v <= zero) THEN\n WRITE(lu_stderr,'(a)') 'statistical: PPCHI2: error: Number of deg. of freedom <= 0'\n stop !RETURN\n END IF\n\n xx = half * v\n c = xx - one\n\n! Starting approximation for small chi-squared\n IF (v < -c5 * LOG(p)) THEN\n fn_val = (p * xx * EXP(g + xx * aa)) ** (one/xx)\n IF (fn_val < e) GO TO 6\n GO TO 4\n END IF\n\n! Starting approximation for v less than or equal to 0.32\n IF (v > c3) GO TO 3\n fn_val = c4\n a = LOG(one-p)\n\n 2 q = fn_val\n p1 = one + fn_val * (c7+fn_val)\n p2 = fn_val * (c9 + fn_val * (c8 + fn_val))\n t = -half + (c7 + two * fn_val) / p1 - (c9 + fn_val * (c10 + three * fn_val)) / p2\n fn_val = fn_val - (one - EXP(a + g + half * fn_val + c * aa) * p2 / p1) / t\n IF (ABS(q / fn_val - one) > c1) GO TO 2\n GO TO 4\n\n! Call to algorithm AS 241 - note that p has been tested above.\n 3 CALL ppnd16(p, x, if1)\n\n! Starting approximation using Wilson and Hilferty estimate\n p1 = c2 / v\n fn_val = v * (x * SQRT(p1) + one - p1) ** 3\n\n! Starting approximation for p tending to 1\n IF (fn_val > c6 * v + six) fn_val = -two * (LOG(one-p) - c * LOG(half * fn_val) + g)\n\n! Call to algorithm AS 239 and calculation of seven term Taylor series\n 4 DO i = 1, maxit\n q = fn_val\n p1 = half * fn_val\n p2 = p - gammad(p1, xx)\n\n t = p2 * EXP(xx * aa + g + p1 - c * LOG(fn_val))\n b = t / fn_val\n a = half * t - b * c\n s1 = (c19 + a * (c17 + a * (c14 + a * (c13 + a * (c12 + c11 * a))))) / c24\n s2 = (c24 + a * (c29 + a * (c32 + a * (c33 + c35 * a)))) / c37\n s3 = (c19 + a * (c25 + a * (c28 + c31 * a))) / c37\n s4 = (c20 + a * (c27 + c34 * a) + c * (c22 + a * (c30 + c36 * a))) / c38\n s5 = (c13 + c21 * a + c * (c18 + c26 * a)) / c37\n s6 = (c15 + c * (c23 + c16 * c)) / c38\n fn_val = fn_val + t * (one + half * t * s1 - b * c * (s1 - b * &\n (s2 - b * (s3 - b * (s4 - b * (s5 - b * s6))))))\n IF (ABS(q / fn_val - one) > e) RETURN\n END DO\n\n WRITE(lu_stderr,'(a)') 'statistical: PPCHI2: error: Max. number of iterations exceeded'\n stop\n\n 6 RETURN\nEND FUNCTION ppchi2\n!-------------------------------------------------------------------------------\n\n!===============================================================================\nfunction gammad(x, p) RESULT(fn_val)\n!===============================================================================\n! ALGORITHM AS239 APPL. STATIST. (1988) VOL. 37, NO. 3\n\n! Computation of the Incomplete Gamma Integral\n\n! Auxiliary functions required: ALOGAM = logarithm of the gamma\n! function, and ALNORM = algorithm AS66\n\n! ELF90-compatible version by Alan Miller\n! Latest revision - 27 October 2000\n\n! N.B. Argument IFAULT has been removed\n! AJN: Remove need for alogam by using log_gamma, intrinsic in Fortran 2008 and\n! implemented in most recent compilers.\n\n IMPLICIT NONE\n INTEGER, PARAMETER :: dp = rs\n REAL (dp), INTENT(IN) :: x, p\n REAL (dp) :: fn_val\n\n ! Local variables\n REAL (dp) :: pn1, pn2, pn3, pn4, pn5, pn6, arg, c, rn, a, b, an\n REAL (dp), PARAMETER :: zero = 0.d0, one = 1.d0, two = 2.d0, &\n oflo = 1.d+37, three = 3.d0, nine = 9.d0, &\n tol = 1.d-14, xbig = 1.d+8, plimit = 1000.d0, &\n elimit = -88.d0\n! EXTERNAL alogam, alnorm\n\n fn_val = zero\n\n! Check that we have valid values for X and P\n IF (p <= zero .OR. x < zero) THEN\n WRITE(lu_stderr,'(a)') 'statistical: gammad(AS239): error: Either p <= 0 or x < 0'\n stop !RETURN\n END IF\n IF (x == zero) RETURN\n\n! Use a normal approximation if P > PLIMIT\n IF (p > plimit) THEN\n pn1 = three * SQRT(p) * ((x / p) ** (one / three) + one /(nine * p) - one)\n fn_val = alnorm(pn1, .false.)\n RETURN\n END IF\n\n! If X is extremely large compared to P then set fn_val = 1\n IF (x > xbig) THEN\n fn_val = one\n RETURN\n END IF\n\n IF (x <= one .OR. x < p) THEN\n\n! Use Pearson's series expansion.\n! (Note that P is not large enough to force overflow in ALOGAM).\n! No need to test IFAULT on exit since P > 0.\n! arg = p * LOG(x) - x - alogam(p + one, ifault)\n arg = p * LOG(x) - x - log_gamma(p + one)\n c = one\n fn_val = one\n a = p\n 40 a = a + one\n c = c * x / a\n fn_val = fn_val + c\n IF (c > tol) GO TO 40\n arg = arg + LOG(fn_val)\n fn_val = zero\n IF (arg >= elimit) fn_val = EXP(arg)\n\n ELSE\n\n! Use a continued fraction expansion\n! arg = p * LOG(x) - x - alogam(p, ifault)\n arg = p * LOG(x) - x - log_gamma(p)\n a = one - p\n b = a + x + one\n c = zero\n pn1 = one\n pn2 = x\n pn3 = x + one\n pn4 = x * b\n fn_val = pn3 / pn4\n 60 a = a + one\n b = b + two\n c = c + one\n an = a * c\n pn5 = b * pn3 - an * pn1\n pn6 = b * pn4 - an * pn2\n IF (ABS(pn6) > zero) THEN\n rn = pn5 / pn6\n IF (ABS(fn_val - rn) <= MIN(tol, tol * rn)) GO TO 80\n fn_val = rn\n END IF\n\n pn1 = pn3\n pn2 = pn4\n pn3 = pn5\n pn4 = pn6\n IF (ABS(pn5) >= oflo) THEN\n\n! Re-scale terms in continued fraction if terms are large\n pn1 = pn1 / oflo\n pn2 = pn2 / oflo\n pn3 = pn3 / oflo\n pn4 = pn4 / oflo\n END IF\n GO TO 60\n 80 arg = arg + LOG(fn_val)\n fn_val = one\n IF (arg >= elimit) fn_val = one - EXP(arg)\n END IF\n\n RETURN\nEND FUNCTION gammad\n!-------------------------------------------------------------------------------\n\n!===============================================================================\nsubroutine ppnd16 (p, normal_dev, ifault)\n!===============================================================================\n! ALGORITHM AS241 APPL. STATIST. (1988) VOL. 37, NO. 3\n\n! Produces the normal deviate Z corresponding to a given lower\n! tail area of P; Z is accurate to about 1 part in 10**16.\n\n! The hash sums below are the sums of the mantissas of the\n! coefficients. They are included for use in checking\n! transcription.\n\n! This ELF90-compatible version by Alan Miller - 20 August 1996\n! N.B. The original algorithm is as a function; this is a subroutine\n\n IMPLICIT NONE\n\n INTEGER, PARAMETER :: dp = rs\n REAL (dp), INTENT(IN) :: p\n INTEGER, INTENT(OUT) :: ifault\n REAL (dp), INTENT(OUT) :: normal_dev\n\n! Local variables\n REAL (dp) :: zero = 0.d0, one = 1.d0, half = 0.5d0, &\n split1 = 0.425d0, split2 = 5.d0, const1 = 0.180625d0, &\n const2 = 1.6d0, q, r\n\n! Coefficients for P close to 0.5\n REAL (dp) :: a0 = 3.3871328727963666080D0, &\n a1 = 1.3314166789178437745D+2, &\n a2 = 1.9715909503065514427D+3, &\n a3 = 1.3731693765509461125D+4, &\n a4 = 4.5921953931549871457D+4, &\n a5 = 6.7265770927008700853D+4, &\n a6 = 3.3430575583588128105D+4, &\n a7 = 2.5090809287301226727D+3, &\n b1 = 4.2313330701600911252D+1, &\n b2 = 6.8718700749205790830D+2, &\n b3 = 5.3941960214247511077D+3, &\n b4 = 2.1213794301586595867D+4, &\n b5 = 3.9307895800092710610D+4, &\n b6 = 2.8729085735721942674D+4, &\n b7 = 5.2264952788528545610D+3\n! HASH SUM AB 55.8831928806149014439\n\n! Coefficients for P not close to 0, 0.5 or 1.\n REAL (dp) :: c0 = 1.42343711074968357734D0, &\n c1 = 4.63033784615654529590D0, &\n c2 = 5.76949722146069140550D0, &\n c3 = 3.64784832476320460504D0, &\n c4 = 1.27045825245236838258D0, &\n c5 = 2.41780725177450611770D-1, &\n c6 = 2.27238449892691845833D-2, &\n c7 = 7.74545014278341407640D-4, &\n d1 = 2.05319162663775882187D0, &\n d2 = 1.67638483018380384940D0, &\n d3 = 6.89767334985100004550D-1, &\n d4 = 1.48103976427480074590D-1, &\n d5 = 1.51986665636164571966D-2, &\n d6 = 5.47593808499534494600D-4, &\n d7 = 1.05075007164441684324D-9\n! HASH SUM CD 49.33206503301610289036\n\n! Coefficients for P near 0 or 1.\n REAL (dp) :: e0 = 6.65790464350110377720D0, &\n e1 = 5.46378491116411436990D0, &\n e2 = 1.78482653991729133580D0, &\n e3 = 2.96560571828504891230D-1, &\n e4 = 2.65321895265761230930D-2, &\n e5 = 1.24266094738807843860D-3, &\n e6 = 2.71155556874348757815D-5, &\n e7 = 2.01033439929228813265D-7, &\n f1 = 5.99832206555887937690D-1, &\n f2 = 1.36929880922735805310D-1, &\n f3 = 1.48753612908506148525D-2, &\n f4 = 7.86869131145613259100D-4, &\n f5 = 1.84631831751005468180D-5, &\n f6 = 1.42151175831644588870D-7, &\n f7 = 2.04426310338993978564D-15\n! HASH SUM EF 47.52583317549289671629\n\n ifault = 0\n q = p - half\n IF (ABS(q) <= split1) THEN\n r = const1 - q * q\n normal_dev = q * (((((((a7*r + a6)*r + a5)*r + a4)*r + a3)*r + a2)*r + a1)*r + a0) / &\n (((((((b7*r + b6)*r + b5)*r + b4)*r + b3)*r + b2)*r + b1)*r + one)\n RETURN\n ELSE\n IF (q < zero) THEN\n r = p\n ELSE\n r = one - p\n END IF\n IF (r <= zero) THEN\n ifault = 1\n normal_dev = zero\n RETURN\n END IF\n r = SQRT(-LOG(r))\n IF (r <= split2) THEN\n r = r - const2\n normal_dev = (((((((c7*r + c6)*r + c5)*r + c4)*r + c3)*r + c2)*r + c1)*r + c0) / &\n (((((((d7*r + d6)*r + d5)*r + d4)*r + d3)*r + d2)*r + d1)*r + one)\n ELSE\n r = r - split2\n normal_dev = (((((((e7*r + e6)*r + e5)*r + e4)*r + e3)*r + e2)*r + e1)*r + e0) / &\n (((((((f7*r + f6)*r + f5)*r + f4)*r + f3)*r + f2)*r + f1)*r + one)\n END IF\n IF (q < zero) normal_dev = - normal_dev\n RETURN\n END IF\nEND SUBROUTINE ppnd16\n!-------------------------------------------------------------------------------\n\n!===============================================================================\nfunction alnorm( x, upper ) RESULT( fn_val )\n!===============================================================================\n! Algorithm AS66 Applied Statistics (1973) vol.22, no.3\n\n! Evaluates the tail area of the standardised normal curve\n! from x to infinity if upper is .true. or\n! from minus infinity to x if upper is .false.\n\n! ELF90-compatible version by Alan Miller\n! Latest revision - 29 November 2001\n\n IMPLICIT NONE\n INTEGER, PARAMETER :: dp = rs\n REAL(DP), INTENT(IN) :: x\n LOGICAL, INTENT(IN) :: upper\n REAL(DP) :: fn_val\n\n! Local variables\n REAL(DP), PARAMETER :: zero=0.0_DP, one=1.0_DP, half=0.5_DP, con=1.28_DP\n REAL(DP) :: z, y\n LOGICAL :: up\n\n! Machine dependent constants\n REAL(DP), PARAMETER :: ltone = 7.0_DP, utzero = 18.66_DP\n REAL(DP), PARAMETER :: p = 0.398942280444_DP, q = 0.39990348504_DP, &\n r = 0.398942280385_DP, a1 = 5.75885480458_DP, &\n a2 = 2.62433121679_DP, a3 = 5.92885724438_DP, &\n b1 = -29.8213557807_DP, b2 = 48.6959930692_DP, &\n c1 = -3.8052E-8_DP, c2 = 3.98064794E-4_DP, &\n c3 = -0.151679116635_DP, c4 = 4.8385912808_DP, &\n c5 = 0.742380924027_DP, c6 = 3.99019417011_DP, &\n d1 = 1.00000615302_DP, d2 = 1.98615381364_DP, &\n d3 = 5.29330324926_DP, d4 = -15.1508972451_DP, &\n d5 = 30.789933034_DP\n\n up = upper\n z = x\n IF( z < zero ) THEN\n up = .NOT. up\n z = -z\n END IF\n IF( z <= ltone .OR. (up .AND. z <= utzero) ) THEN\n y = half*z*z\n IF( z > con ) THEN\n fn_val = r*EXP( -y )/(z+c1+d1/(z+c2+d2/(z+c3+d3/(z+c4+d4/(z+c5+d5/(z+c6))))))\n ELSE\n fn_val = half - z*(p-q*y/(y+a1+b1/(y+a2+b2/(y+a3))))\n END IF\n ELSE\n fn_val = zero\n END IF\n\n IF( .NOT. up ) fn_val = one - fn_val\n RETURN\nEND FUNCTION alnorm\n!-------------------------------------------------------------------------------\n\n\n!===============================================================================\n!-------------------------------------------------------------------------------\n! Circular statistical functions\n!-------------------------------------------------------------------------------\n!===============================================================================\n\n!===============================================================================\nfunction circ_mean(angle,degrees)\n!===============================================================================\n! Returns the circular mean of a set of angles. Input is a column vector\n! of arbitrary length. Default is for input in degrees.\n implicit none\n real(rs),intent(in) :: angle(:)\n real(rs) :: circ_mean\n logical,intent(in),optional :: degrees\n logical :: radians\n\n radians = .false.\n if (present(degrees)) radians = .not.degrees\n\n if (radians) then\n circ_mean = atan2(sum( sin( angle(1:size(angle)) ) ), &\n sum( cos( angle(1:size(angle)) ) ) )\n else\n circ_mean = atan2(sum( sin( angle(1:size(angle))*pi/180._rs ) ), &\n sum( cos( angle(1:size(angle))*pi/180._rs ) ) )\n circ_mean = circ_mean*180._rs/pi\n endif\n\n return\nend function circ_mean\n!-------------------------------------------------------------------------------\n\n!===============================================================================\nsubroutine circ_mean_bootstrap(angle,mu,mu1,mu2,B,degrees)\n!===============================================================================\n! Calculate a sample mean using a bootstrap technique. Assumes a symmetric\n! distribution. See Fisher, Statistical analysis of circular data, \u00a74.4\n! Optionally specify number of bootstrap samples to take.\n implicit none\n real(rs),intent(in) :: angle(:)\n real(rs),intent(out) :: mu\n real(rs),intent(out),optional :: mu1,mu2\n integer,intent(in),optional :: B\n logical,intent(in),optional :: degrees\n logical :: degrees_in\n\n degrees_in = .true.\n if (present(degrees)) degrees_in = degrees\n\n if (size(angle) <= 9) then ! For small N, calculate all n**n samples\n call circ_mean_bootstrap_smallN(angle,mu,mu1,mu2,degrees=degrees_in)\n else\n write(lu_stderr,'(a)') 'statistical: circ_mean_bootstrap: only implemented for n<=9 at the moment.'\n stop\n endif\n\n return\nend subroutine circ_mean_bootstrap\n!-------------------------------------------------------------------------------\n\n!===============================================================================\nsubroutine circ_mean_bootstrap_smallN(angle,mu,mu1,mu2,degrees,force)\n!===============================================================================\n! For a small sample, calculate the bootstrap mean and confidence interval\n! by taking all possible subsamples of the data (= n**n).\n! If n==9, then n**n real*4s takes up ~1.5 GB. Use this routine with care on\n! lesser or shared machines! Hence a warning is displayed, unless the force=.true.\n! option is employed on the command line.\n implicit none\n real(rs),intent(in) :: angle(:)\n real(rs),intent(out) :: mu,mu1,mu2\n logical,intent(in),optional :: degrees,force\n logical :: force_in\n real(rs) :: conversion\n real(r4) :: Csum,Ssum\n real(r4),allocatable :: mean(:) ! Use single preision for storage of bootstrap samples\n real(rs),allocatable :: rangle(:)\n integer :: n,i,i1,i2,i3,i4,i5,i6,i7,i8,i9\n\n! We're potentially allocating <=1.5 GB of memory, so make sure we know what\n! we're doing.\n force_in = .false.\n if (present(force)) force_in = force\n if (.not.force_in) then\n if (size(angle) >= 8) then\n write(*,'(a,f0.0,a)') 'circ_mean_bootstrap_smallN is about to allocate ',&\n 8.*size(angle)**size(angle)/(1024.**2),' MB of memory.'\n write(*,'(a)') 'Hit return to continue, or ^C to abort.'\n read(*,*)\n endif\n endif\n\n! Check we're only testing with small sample size\n n = size(angle)\n if (n > 9 .or. n == 1) then\n write(lu_stderr,'(a)') &\n 'statistical: circ_mean_bootstrap_smallN: number of samples too large for small N subroutine, or n is 1.'\n stop\n endif\n\n! Allocate memory for all n**n sample means: here we go!\n allocate(mean(n**n))\n\n! Convert angles into radians if necesary\n allocate(rangle(n))\n conversion = pi/180._rs\n if (present(degrees)) then\n if (.not.degrees) conversion = 1._rs\n endif\n rangle = conversion*angle\n\n! Calculate sample mean for all possible bootstrap samples\n i = 1\n if (n == 2) then\n do i1=1,n\n do i2=1,n\n Csum = cos(rangle(i1)) + cos(rangle(i2))\n Ssum = sin(rangle(i1)) + sin(rangle(i2))\n mean(i) = atan2(Ssum,Csum)\n i = i + 1\n enddo\n enddo\n\n else if (n == 3) then\n do i1=1,n\n do i2=1,n\n do i3=1,n\n Csum = cos(rangle(i1)) + cos(rangle(i2)) + cos(rangle(i3))\n Ssum = sin(rangle(i1)) + sin(rangle(i2)) + sin(rangle(i3))\n mean(i) = atan2(Ssum,Csum)\n i = i + 1\n enddo\n enddo\n enddo\n\n else if (n == 4) then\n do i1=1,n\n write(*,'(a,i0,a)') 'Executing ',i1,' of 8 passes.'\n do i2=1,n\n do i3=1,n\n do i4=1,n\n Csum = cos(rangle(i1)) + cos(rangle(i2)) + cos(rangle(i3)) + &\n cos(rangle(i4))\n Ssum = sin(rangle(i1)) + sin(rangle(i2)) + sin(rangle(i3)) + &\n sin(rangle(i4))\n mean(i) = atan2(Ssum,Csum)\n i = i + 1\n enddo\n enddo\n enddo\n enddo\n\n\n else if (n == 5) then\n do i1=1,n\n write(*,'(a,i0,a)') 'Executing ',i1,' of 8 passes.'\n do i2=1,n\n do i3=1,n\n do i4=1,n\n do i5=1,n\n Csum = cos(rangle(i1)) + cos(rangle(i2)) + cos(rangle(i3)) + &\n cos(rangle(i4)) + cos(rangle(i5))\n Ssum = sin(rangle(i1)) + sin(rangle(i2)) + sin(rangle(i3)) + &\n sin(rangle(i4)) + sin(rangle(i5))\n mean(i) = atan2(Ssum,Csum)\n i = i + 1\n enddo\n enddo\n enddo\n enddo\n enddo\n\n else if (n == 6) then\n do i1=1,n\n write(*,'(a,i0,a)') 'Executing ',i1,' of 8 passes.'\n do i2=1,n\n do i3=1,n\n do i4=1,n\n do i5=1,n\n do i6=1,n\n Csum = cos(rangle(i1)) + cos(rangle(i2)) + cos(rangle(i3)) + &\n cos(rangle(i4)) + cos(rangle(i5)) + cos(rangle(i6))\n Ssum = sin(rangle(i1)) + sin(rangle(i2)) + sin(rangle(i3)) + &\n sin(rangle(i4)) + sin(rangle(i5)) + sin(rangle(i6))\n mean(i) = atan2(Ssum,Csum)\n i = i + 1\n enddo\n enddo\n enddo\n enddo\n enddo\n enddo\n\n else if (n == 7) then\n do i1=1,n\n write(*,'(a,i0,a)') 'Executing ',i1,' of 8 passes.'\n do i2=1,n\n do i3=1,n\n do i4=1,n\n do i5=1,n\n do i6=1,n\n do i7=1,n\n Csum = cos(rangle(i1)) + cos(rangle(i2)) + cos(rangle(i3)) + &\n cos(rangle(i4)) + cos(rangle(i5)) + cos(rangle(i6)) + &\n cos(rangle(i7))\n Ssum = sin(rangle(i1)) + sin(rangle(i2)) + sin(rangle(i3)) + &\n sin(rangle(i4)) + sin(rangle(i5)) + sin(rangle(i6)) + &\n sin(rangle(i7))\n mean(i) = atan2(Ssum,Csum)\n i = i + 1\n enddo\n enddo\n enddo\n enddo\n enddo\n enddo\n enddo\n\n else if (n == 8) then\n do i1=1,n\n write(*,'(a,i0,a)') 'Executing ',i1,' of 8 passes.'\n do i2=1,n\n do i3=1,n\n do i4=1,n\n do i5=1,n\n do i6=1,n\n do i7=1,n\n do i8=1,n\n Csum = cos(rangle(i1)) + cos(rangle(i2)) + cos(rangle(i3)) + &\n cos(rangle(i4)) + cos(rangle(i5)) + cos(rangle(i6)) + &\n cos(rangle(i7)) + cos(rangle(i8))\n Ssum = sin(rangle(i1)) + sin(rangle(i2)) + sin(rangle(i3)) + &\n sin(rangle(i4)) + sin(rangle(i5)) + sin(rangle(i6)) + &\n sin(rangle(i7)) + sin(rangle(i8))\n mean(i) = atan2(Ssum,Csum)\n i = i + 1\n enddo\n enddo\n enddo\n enddo\n enddo\n enddo\n enddo\n enddo\n\n else if (n == 9) then\n do i1=1,n\n write(*,'(a,i0,a)') 'Executing ',i1,' of 9 passes.'\n do i2=1,n\n do i3=1,n\n do i4=1,n\n do i5=1,n\n do i6=1,n\n do i7=1,n\n do i8=1,n\n do i9=1,n\n Csum = cos(rangle(i1)) + cos(rangle(i2)) + cos(rangle(i3)) + &\n cos(rangle(i4)) + cos(rangle(i5)) + cos(rangle(i6)) + &\n cos(rangle(i7)) + cos(rangle(i8)) + cos(rangle(i9))\n Ssum = sin(rangle(i1)) + sin(rangle(i2)) + sin(rangle(i3)) + &\n sin(rangle(i4)) + sin(rangle(i5)) + sin(rangle(i6)) + &\n sin(rangle(i7)) + sin(rangle(i8)) + sin(rangle(i9))\n mean(i) = atan2(Ssum,Csum)\n i = i + 1\n enddo\n enddo\n enddo\n enddo\n enddo\n enddo\n enddo\n enddo\n enddo\n endif\n\n mu = sum(mean)/(conversion*n**n)\n\n return\nend subroutine circ_mean_bootstrap_smallN\n!-------------------------------------------------------------------------------\n\n!===============================================================================\nfunction circ_res_length(angle,degrees)\n!===============================================================================\n! Returns the resultant length of the angles. Input is a column vector of\n! arbitrary length. Default is for input in degrees.\n implicit none\n real(rs),intent(in) :: angle(:)\n real(rs) :: circ_res_length\n logical,intent(in),optional :: degrees\n logical :: radians\n\n radians = .false.\n if (present(degrees)) radians = .not.degrees\n\n if (radians) then\n circ_res_length = sqrt((sum(sin(angle(1:size(angle)))))**2 + &\n (sum(cos(angle(1:size(angle)))))**2) / real(size(angle))\n else\n circ_res_length = sqrt((sum( sin(angle(1:size(angle))*pi/180._rs)) )**2 + &\n (sum( cos(angle(1:size(angle))*pi/180._rs)) )**2) / real(size(angle))\n endif\n\n return\nend function circ_res_length\n!-------------------------------------------------------------------------------\n\n!===============================================================================\nfunction circ_sd(angle,degrees)\n!===============================================================================\n! Returns the circular standard deviation. Input is a column vector of\n! arbitrary length. Default is for input in degrees.\n implicit none\n real(rs),intent(in) :: angle(:)\n real(rs) :: circ_sd\n logical,intent(in),optional :: degrees\n logical :: degrees_in\n\n degrees_in = .true.\n if (present(degrees)) degrees_in = degrees\n\n circ_sd = sqrt(-2._rs*log(circ_res_length(angle,degrees=degrees_in)))\n\n return\nend function circ_sd\n!===============================================================================\n\n!===============================================================================\nfunction circ_variance(angle,degrees)\n!===============================================================================\n! Returns the circular variance of a set of angles. Input is a column vector\n! of arbitrary length. Default is for input in degrees.\n implicit none\n real(rs),intent(in) :: angle(:)\n real(rs) :: circ_variance,mean\n logical,intent(in),optional :: degrees\n logical :: radians\n\n radians = .false.\n if (present(degrees)) radians = .not.degrees\n\n if (radians) then\n mean = circ_mean(angle,degrees=.false.)\n circ_variance = 1._rs - sum(cos(angle - mean))/real(size(angle))\n else\n mean = circ_mean(angle,degrees=.true.) * pi/180._rs\n circ_variance = 1._rs - sum(cos(angle*pi/180._rs - mean))/real(size(angle))\n endif\n\n return\nend function circ_variance\n!-------------------------------------------------------------------------------\n\n!===============================================================================\nfunction circ_uncent_trig_moment(angle,p,degrees)\n!===============================================================================\n! Returns the uncentered pth trigonometric moment. Input is a column vector of\n! arbitrary length. Default is for input in degrees.\n implicit none\n real(rs),intent(in) :: angle(:)\n integer,intent(in) :: p\n complex(cs) :: circ_uncent_trig_moment\n real(rs) :: Cp,Sp\n integer :: n\n logical,intent(in),optional :: degrees\n real(rs) :: conversion\n\n! Check for valid p\n if (p < 1) then\n write(lu_stderr,'(a)') 'statistical: circ_uncent_trig_moment: p must be > 0.'\n stop\n endif\n\n! Convert from degrees to radians unless otherwise\n conversion = pi/180._rs\n if (present(degrees)) then\n if (.not.degrees) conversion = 1._rs\n endif\n\n n = size(angle)\n Cp = sum(cos(real(p)*angle(1:n)*conversion))/real(n)\n Sp = sum(sin(real(p)*angle(1:n)*conversion))/real(n)\n\n circ_uncent_trig_moment = cmplx(Cp, Sp)\n\n return\nend function circ_uncent_trig_moment\n!-------------------------------------------------------------------------------\n\n!===============================================================================\nfunction circ_cent_trig_moment(angle,p,degrees)\n!===============================================================================\n! Returns the centered pth trigonometric moment. Input is a column vector of\n! arbitrary length. Default is for input in degrees.\n implicit none\n real(rs),intent(in) :: angle(:)\n integer, intent(in) :: p\n complex(cs) :: circ_cent_trig_moment\n real(rs) :: Cp,Sp,mean,conversion\n integer :: n\n logical,intent(in),optional :: degrees\n\n! Check for valid p\n if (p < 1) then\n write(lu_stderr,'(a)') 'statistical: circ_cent_trig_moment: P must be > 0.'\n stop\n endif\n\n! Convert from degrees to radians unless otherwise desired\n conversion = pi/180._rs\n if (present(degrees)) then; if (.not.degrees) conversion = 1._rs; endif\n\n n = size(angle)\n mean = circ_mean(angle,degrees=degrees)\n Cp = sum(cos(real(p)*conversion*(angle(1:n) - mean)))/real(n)\n Sp = sum(sin(real(p)*conversion*(angle(1:n) - mean)))/real(n)\n\n circ_cent_trig_moment = cmplx(Cp, Sp)\n\n return\nend function circ_cent_trig_moment\n!-------------------------------------------------------------------------------\n\n!===============================================================================\nfunction circ_dispers(angle,degrees)\n!===============================================================================\n! Returns the circular dispersion of a set of angles. Input is a column vector\n! of arbitrary length. Default is for input in degrees.\n implicit none\n real(rs),intent(in) :: angle(:)\n real(rs) :: circ_dispers\n real(rs) :: mean,rho2,R,conversion\n integer :: n\n logical,intent(in),optional :: degrees\n\n! By default, convert from degrees to radians for calculations\n conversion = pi/180._rs\n if (present(degrees)) then\n if (.not.degrees) conversion = 1._rs\n endif\n\n mean = circ_mean(angle,degrees=degrees)\n n = size(angle)\n R = sum(cos(conversion*(angle(1:n) - mean)))/real(n)\n rho2 = sum(cos(2._rs*conversion*(angle(1:n) - mean)))/real(n)\n circ_dispers = (1._rs - rho2)/(2._rs*R**2)\n\n return\nend function circ_dispers\n!-------------------------------------------------------------------------------\n\n!===============================================================================\nfunction circ_correl(a,b,degrees)\n!===============================================================================\n! Returns the circular correlation between two sets of angles. Input is two\n! column vectors of arbitrary (but the same) length. Default is for input\n! in dgerees.\n implicit none\n real(rs),intent(in) :: a(:), b(:)\n real(rs) :: circ_correl, amean, bmean\n logical,intent(in),optional :: degrees\n logical :: radians\n\n! Check arrays are same length\n if (size(a) /= size(b)) then\n write(0,'(a)') 'Error: statistical: circ_correl: Input arrays are not same length.'\n stop\n endif\n\n radians = .false.\n if (present(degrees)) radians = .not.degrees\n\n if (radians) then\n amean = circ_mean(a,degrees=.false.)\n bmean = circ_mean(a,degrees=.false.)\n circ_correl = sum( sin(a - amean) * sin(b - bmean) )/ &\n sqrt( sum( sin(a-amean)*sin(a-amean)*sin(b-bmean)*sin(b-bmean) ) )\n else\n amean = circ_mean(a,degrees=.true.) * pi/180._rs\n bmean = circ_mean(b,degrees=.true.) * pi/180._rs\n circ_correl = sum( sin(a*pi/180._rs - amean) * sin(b*pi/180._rs - bmean) )/ &\n sqrt( sum( sin(a*pi/180._rs-amean)*sin(a*pi/180._rs-amean) * &\n sin(b*pi/180._rs-bmean)*sin(b*pi/180._rs-bmean) ) )\n endif\n\n return\nend function circ_correl\n!-------------------------------------------------------------------------------\n\n!===============================================================================\nfunction circ_von_mieses(theta,mu,kappa,degrees)\n!===============================================================================\n! Returns the value of the von Mieses distribution for given mean and 'pointiness'\n implicit none\n\n real(rs),intent(in) :: theta,mu,kappa\n real(rs) :: circ_von_mieses,conversion\n logical,intent(in),optional :: degrees\n\n conversion = pi/180._rs\n if (present(degrees)) then; if (.not.degrees) conversion = 1._rs; endif\n\n circ_von_mieses = exp(kappa*cos(conversion*(theta - mu)))/(2._rs*pi*BessI0(kappa))\n\n return\n\n contains\n function BessI0(x)\n ! Evaluates the modified Bessel function of the first kind at x.\n ! Polynomial approximation taken from Abramowitz & Stegun, 1964, Handbook\n ! of mathematical functions. See also Numerical Recipes \u00a76.6\n implicit none\n real(rs),intent(in) :: x\n real(rs) :: BessI0\n real(r8) :: t\n\n if (abs(x) < 3.75_r8) then\n t = abs(x/3.75_r8)\n BessI0 = 1._r8 + &\n 3.5156229_r8*t**2 + 3.0899424_r8*t**4 + 1.2067492_r8*t**6 + &\n 0.2659732_r8*t**8 + 0.0360768_r8*t**10 + 0.0045813_r8*t**12\n else\n t = abs(3.75_r8/x)\n BessI0 = (exp(abs(x))/sqrt(abs(x)))*(0.39894228_rs + &\n 0.01328592_r8*t + 0.00225319_r8*t**2 - 0.00157565_r8*t**3 + &\n 0.00916281_r8*t**4 - 0.02057706_r8*t**5 + 0.02635537_r8*t**6 - &\n 0.01647633_r8*t**7 + 0.00392377_r8*t**8)\n endif\n return\n end function BessI0\n\nend function circ_von_mieses\n!-------------------------------------------------------------------------------\n\n!===============================================================================\nfunction circ_test_random_orient(theta,theta0,alpha,degrees) result(pass)\n!===============================================================================\n! Test whether a set of orientations (i.e., 180-degrees ambiguous), theta_i,\n! point in a certain direction, theta0, statistically differently from random,\n! using the V-test as modified by Rayleigh\n! (test 95 in: 100 Statistical Tests. G.K. Kanji, SAGE Publications.).\n implicit none\n real(rs), intent(in) :: theta(:), theta0\n real(rs), intent(in), optional :: alpha\n logical, optional, intent(in) :: degrees\n real(rs) :: conversion, alpha_in\n real(rs) :: r, mean, V\n logical :: radians, pass\n integer :: n\n\n n = size(theta)\n if (n < 5) then\n write(0,'(a)') 'statistical: circ_test_random_orient: Error: Cannot ' // &\n 'calculate significance for samples < 5'\n stop\n endif\n\n radians = .false.\n alpha_in = 0.05_rs\n if (present(alpha)) alpha_in = alpha\n\n if (present(degrees)) radians = .not.degrees\n conversion = pi/180._rs\n if (radians) conversion = 1._rs\n\n mean = circ_mean(2._rs*theta, degrees=.not.radians)\n r = circ_res_length(2._rs*theta, degrees=.not.radians)\n V = 2._rs*sqrt(2._rs*size(theta))*r*cos(conversion*mean - 2._rs*conversion*theta0)\n\n ! Lookup values in table and decide on significance\n pass = .false.\n if (V > v_test_table()) pass = .true.\n\n contains\n function v_test_table() result(value)\n integer :: i\n real(rs) :: value\n integer, parameter, dimension(33) :: table_n = &\n (/ 5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26, &\n 27,28,29,30,40,50,60,70,100,500,1000 /)\n real(rs), parameter, dimension(6) :: table_alpha = &\n (/ 0.1, 0.05, 0.01, 0.005, 0.001, 0.0001 /)\n real(rs), parameter :: table(33,6) = transpose(reshape( (/ &\n 1.3051_rs, 1.6524_rs, 2.2505_rs, 2.4459_rs, 2.7938_rs, 3.0825_rs, &\n 1.3009_rs, 1.6509_rs, 2.2640_rs, 2.4695_rs, 2.8502_rs, 3.2114_rs, &\n 1.2980_rs, 1.6499_rs, 2.2734_rs, 2.4858_rs, 2.8886_rs, 3.2970_rs, &\n 1.2958_rs, 1.6492_rs, 2.2803_rs, 2.4978_rs, 2.9164_rs, 3.3578_rs, &\n 1.2942_rs, 1.6484_rs, 2.2856_rs, 2.5070_rs, 2.9375_rs, 3.4034_rs, &\n 1.2929_rs, 1.6482_rs, 2.2899_rs, 2.5143_rs, 2.9540_rs, 3.4387_rs, &\n 1.2918_rs, 1.6479_rs, 2.2933_rs, 2.5201_rs, 2.9672_rs, 3.4669_rs, &\n 1.2909_rs, 1.6476_rs, 2.2961_rs, 2.5250_rs, 2.9782_rs, 3.4899_rs, &\n 1.2902_rs, 1.6474_rs, 2.2985_rs, 2.5290_rs, 2.9873_rs, 3.5091_rs, &\n 1.2895_rs, 1.6472_rs, 2.3006_rs, 2.5325_rs, 2.9950_rs, 3.5253_rs, &\n 1.2890_rs, 1.6470_rs, 2.3023_rs, 2.5355_rs, 3.0017_rs, 3.5392_rs, &\n 1.2885_rs, 1.6469_rs, 2.3039_rs, 2.5381_rs, 3.0075_rs, 3.5512_rs, &\n 1.2881_rs, 1.6467_rs, 2.3052_rs, 2.5404_rs, 3.0126_rs, 3.5617_rs, &\n 1.2877_rs, 1.6466_rs, 2.3064_rs, 2.5424_rs, 3.0171_rs, 3.5710_rs, &\n 1.2874_rs, 1.6465_rs, 2.3075_rs, 2.5442_rs, 3.0211_rs, 3.5792_rs, &\n 1.2871_rs, 1.6464_rs, 2.3085_rs, 2.5458_rs, 3.0247_rs, 3.5866_rs, &\n 1.2868_rs, 1.6464_rs, 2.3093_rs, 2.5473_rs, 3.0279_rs, 3.5932_rs, &\n 1.2866_rs, 1.6463_rs, 2.3101_rs, 2.5486_rs, 3.0308_rs, 3.5992_rs, &\n 1.2864_rs, 1.6462_rs, 2.3108_rs, 2.5498_rs, 3.0335_rs, 3.6047_rs, &\n 1.2862_rs, 1.6462_rs, 2.3115_rs, 2.5509_rs, 3.0359_rs, 3.6096_rs, &\n 1.2860_rs, 1.6461_rs, 2.3121_rs, 2.5519_rs, 3.0382_rs, 3.6142_rs, &\n 1.2858_rs, 1.6461_rs, 2.3127_rs, 2.5529_rs, 3.0402_rs, 3.6184_rs, &\n 1.2856_rs, 1.6460_rs, 2.3132_rs, 2.5538_rs, 3.0421_rs, 3.6223_rs, &\n 1.2855_rs, 1.6460_rs, 2.3136_rs, 2.5546_rs, 3.0439_rs, 3.6258_rs, &\n 1.2853_rs, 1.6459_rs, 2.3141_rs, 2.5553_rs, 3.0455_rs, 3.6292_rs, &\n 1.2852_rs, 1.6459_rs, 2.3145_rs, 2.5560_rs, 3.0471_rs, 3.6323_rs, &\n 1.2843_rs, 1.6456_rs, 2.3175_rs, 2.5610_rs, 3.0580_rs, 3.6545_rs, &\n 1.2837_rs, 1.6455_rs, 2.3193_rs, 2.5640_rs, 3.0646_rs, 3.6677_rs, &\n 1.2834_rs, 1.6454_rs, 2.3205_rs, 2.5660_rs, 3.0689_rs, 3.6764_rs, &\n 1.2831_rs, 1.6453_rs, 2.3213_rs, 2.5674_rs, 3.0720_rs, 3.6826_rs, &\n 1.2826_rs, 1.6452_rs, 2.3228_rs, 2.5699_rs, 3.0775_rs, 3.6936_rs, &\n 1.2818_rs, 1.6449_rs, 2.3256_rs, 2.5747_rs, 3.0877_rs, 3.7140_rs, &\n 1.2817_rs, 1.6449_rs, 2.3260_rs, 2.5752_rs, 3.0890_rs, 3.7165_rs /), (/6,33/)))\n ! The function just checks that the value you asked for alpha\n ! is near to one of those we offer--if not, you get an error\n do i = 1, size(table_alpha)\n if (abs(table_alpha(i) - alpha_in)/table_alpha(i) < 0.1_rs) then\n value = table(minloc(abs(n-table_n),1), i)\n return\n endif\n enddo\n write(0,'(a,f0.6,a)') 'statistical: circ_test_random_orient: v_test_table: ' &\n //'Error: Cannot find a value for alpha near that requested (',alpha_in,')'\n stop\n end function v_test_table\nend function circ_test_random_orient\n!-------------------------------------------------------------------------------\n\n\n!===============================================================================\n!-------------------------------------------------------------------------------\n! Spherical statistical functions\n!-------------------------------------------------------------------------------\n!===============================================================================\n\n!===============================================================================\nfunction sph_mean(x, y, z) result(mean)\n!===============================================================================\n! Compute the mean direction for a set of vectors representing the x, y and z\n! directions of points on the unit sphere. Each input value is normalised to\n! the unit sphere even if it isn't on input.\n! Output is a three-vector giving the direction as (x,y,z)\n real(rs), intent(in), dimension(:) :: x, y, z\n real(rs) :: mean(3)\n if (size(x) /= size(y) .or. size(y) /= size(z) .or. size(z) /= size(x)) then\n write(0,'(a)') 'statistical: sph_mean: Input arrays must be same length'\n stop\n endif\n mean = (/sum(x), sum(y), sum(z)/)/sph_resultant(x, y, z)\nend function sph_mean\n!-------------------------------------------------------------------------------\n\n!===============================================================================\nfunction sph_resultant(x, y, z) result(resultant)\n!===============================================================================\n! Compute the spherical resultant\n real(rs), intent(in), dimension(:) :: x, y, z\n real(rs) :: resultant(3)\n if (size(x) /= size(y) .or. size(y) /= size(z) .or. size(z) /= size(x)) then\n write(0,'(a)') 'statistical: sph_resultant: Input arrays must be same length'\n stop\n endif\n resultant = sqrt(sum(x)**2 + sum(y)**2 + sum(z)**2)\nend function sph_resultant\n!-------------------------------------------------------------------------------\n\n!===============================================================================\nfunction sph_mean_resultant(x, y, z) result(mean_resultant)\n!===============================================================================\n real(rs), intent(in), dimension(:) :: x, y, z\n real(rs) :: mean_resultant(3)\n mean_resultant = sph_resultant(x, y, z)/size(x)\nend function sph_mean_resultant\n!-------------------------------------------------------------------------------\n\n\n!===============================================================================\n!-------------------------------------------------------------------------------\n! Linear statistical functions\n!-------------------------------------------------------------------------------\n!===============================================================================\n\n!===============================================================================\nfunction stat_mean(x)\n!===============================================================================\n! Compute the mean\n real(rs), intent(in), dimension(:) :: x\n real(rs) :: stat_mean\n stat_mean = sum(x)/size(x)\nend function stat_mean\n!-------------------------------------------------------------------------------\n\n!===============================================================================\nfunction stat_variance(x)\n!===============================================================================\n! Compute the variance\n real(rs), intent(in), dimension(:) :: x\n real(rs) :: stat_variance\n stat_variance = sum((x - stat_mean(x))**2)/(size(x) - 1)\nend function stat_variance\n!-------------------------------------------------------------------------------\n\n!===============================================================================\nfunction stat_sd(x)\n!===============================================================================\n! Compute the standard deviation\n real(rs), intent(in), dimension(:) :: x\n real(rs) :: stat_sd\n stat_sd = sqrt(stat_variance(x))\nend function stat_sd\n!-------------------------------------------------------------------------------\n\n!===============================================================================\nfunction stat_covariance(x, y)\n!===============================================================================\n! Compute the covariance between two arrays of the same length\n real(rs), intent(in), dimension(:) :: x, y\n real(rs) :: stat_covariance\n if (size(x) /= size(y)) then\n write(0,'(a)') 'statistical: stat_covariance: Input arrays must be same length'\n stop\n endif\n stat_covariance = sum((x - stat_mean(x))*(y - stat_mean(y)))/size(x)\nend function stat_covariance\n!-------------------------------------------------------------------------------\n!_______________________________________________________________________________\nend module statistical\n", "meta": {"hexsha": "b0c07ef895d026e94d1432544ef47a050fd62f42", "size": 54190, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "statistical.f90", "max_stars_repo_name": "JackWalpole/seismo-fortran-fork", "max_stars_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2015-06-23T05:28:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T03:46:07.000Z", "max_issues_repo_path": "statistical.f90", "max_issues_repo_name": "JackWalpole/seismo-fortran-fork", "max_issues_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2017-05-17T11:02:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-28T09:36:24.000Z", "max_forks_repo_path": "statistical.f90", "max_forks_repo_name": "JackWalpole/seismo-fortran-fork", "max_forks_repo_head_hexsha": "18ba57302ba2dbd39028e6ff55deb448d02bd919", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-04-15T02:55:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-20T12:20:51.000Z", "avg_line_length": 38.3510261854, "max_line_length": 116, "alphanum_fraction": 0.4731869349, "num_tokens": 15552, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.7461389986757758, "lm_q1q2_score": 0.6547196515729372}} {"text": "module special_functions\n! Special functions\nuse types, only: dp\nuse constants, only: i_, pi\nuse utils, only: stop_error, str\nimplicit none\nprivate\npublic wigner3j, getgaunt, getgauntr, Fm, Inu_asympt_sum, Inu_series, &\n Knu_asympt_sum, Inu_formula, Knu_formula, Inu_formula2, Knu_formula2\n\ncontains\n\nreal(dp) function fact(n) result(r)\ninteger, intent(in) :: n\nr = gamma(n+1.0_dp)\nend function\n\nreal(dp) function wigner3j(j1, j2, j3, m1, m2, m3) result(r)\n! Calculates wigner3j symbols.\ninteger, intent(in) :: j1, j2, j3 ! angular momentum quantum numbers\ninteger, intent(in) :: m1, m2, m3 ! magnetic quantum numbers\ninteger :: k, k1, k2, l1, l2, l3, n1, n2, sgn\nif ((abs(m1) > j1) .or. (abs(m2) > j2) .or. (abs(m3) > j3)) then\n print *, \"Arguments:\"\n print *, j1, j2, j3\n print *, m1, m2, m3\n call stop_error(\"wigner3j: invalid arguments\")\nend if\nif ((j1 == 0) .and. (j2 == 0) .and. (j3 == 0)) then\n r = 1\n return\nend if\n\nl1 = j2 - j1 + j3\nl2 = j1 - j2 + j3\nl3 = j1 + j2 - j3\nif ((m1 + m2 + m3 /= 0) .or. (l1 < 0) .or. (l2 < 0) .or. (l3 < 0)) then\n r = 0\n return\nend if\nn1 = j1 - m1\nn2 = j2 + m2\nk1 = max(0, j2-j3-m1, j1-j3+m2)\nk2 = min(l3, n1, n2)\nif (mod(k1 + j1 + j2 + m3, 2) /= 0) then\n sgn = -1\nelse\n sgn = 1\nend if\nr = 0\ndo k = k1, k2\n r = r + sgn * fr(l1, l1-n2+k) * fr(l2, l2-n1+k) * fr(l3, l3-k) / &\n (fact(k) * fact(n1-k) * fact(n2-k))\n sgn = -sgn\nend do\nr = r * sqrt(fr(j1+m1, l1) * fr(j2+m2, l2) * fr(j3+m3, l3) * &\n fr(j3-m3, 1+j1+j2+j3) * fact(j1-m1) * fact(j2-m2))\nend function\n\nreal(dp) function fr(a, b) result(r)\n! Returns a!/b!, for a,b >= 0\ninteger, intent(in) :: a, b\ninteger :: i\nif (a < 0 .or. b < 0) call stop_error(\"fr(a,b): must satisfy a, b >= 0\")\nr = 1\nif (a < b) then\n do i = a + 1, b\n r = r / i\n end do\nelse if (a > b) then\n do i = b + 1, a\n r = r * i\n end do\nend if\nend function\n\nsubroutine getgaunt(Lmax, ck)\n! Calculates the Gaunt c^k(l1, m1, l2, m2) coefficients\n! It returns an array of coefficients for all combinations of k, l1, m1, l2, m2:\n! ck(k, l1, m1, l2, m2) = c^k(l1, m1, l2, m2)\n! Indices out of bounds mean that the coefficient is zero.\ninteger, intent(in) :: Lmax ! max(l1, l2)\nreal(dp), allocatable, intent(out) :: ck(:, :, :, :, :) ! ck(k, l1, m1, l2, m2)\ninteger :: k, l1, m1, l2, m2\nallocate(ck(0:2*Lmax, 0:Lmax, -Lmax:Lmax, 0:Lmax, -Lmax:Lmax))\nck = 0\ndo l1 = 0, Lmax\n do l2 = 0, Lmax\n do m1 = -l1, l1\n do m2 = -l2, l2\n do k = abs(l1-l2), l1+l2, 2\n if (abs(m1-m2) > k) cycle\n ck(k, l1, m1, l2, m2) = (-1)**(-m1) * &\n sqrt(1._dp*(2*l1+1)*(2*l2+1)) * &\n wigner3j(l1, k, l2, 0, 0, 0) * &\n wigner3j(l1, k, l2, -m1, m1-m2, m2)\n end do\n end do\n end do\n end do\nend do\nend subroutine\n\nsubroutine getgauntr(Lmax, gr)\ninteger, intent(in) :: Lmax ! max(l1, l2)\n! gr(i, j, k, l, m, n) = _R\nreal(dp), allocatable, intent(out) :: gr(:, :, :, :, :, :)\nreal(dp), allocatable :: ck(:, :, :, :, :)\ninteger :: l1, m1, l2, m2, l3, m3\ninteger :: Lmax2\nLmax2 = 4*Lmax\nallocate(ck(0:2*Lmax2, 0:Lmax2, -Lmax2:Lmax2, 0:Lmax2, -Lmax2:Lmax2))\ncall getgaunt(Lmax2, ck)\nallocate(gr(0:Lmax, -Lmax:Lmax, 0:2*Lmax, -2*Lmax:2*Lmax, 0:Lmax, -Lmax:Lmax))\ngr = 0\ndo l1 = 0, Lmax\n do l2 = 0, 2*Lmax\n do l3 = 0, Lmax\n do m1 = -l1, l1\n do m2 = -l2, l2\n do m3 = -l3, l3\n gr(l1, m1, l2, m2, l3, m3) = &\n gauntr(l1, m1, l2, m2, l3, m3, ck, Lmax2)\n end do\n end do\n end do\n end do\n end do\nend do\nend subroutine\n\nreal(dp) recursive function gauntr(l1, m1, l2, m2, l3, m3, ck, Lmax) result(r)\ninteger, intent(in) :: l1, m1, l2, m2, l3, m3, Lmax\nreal(dp), intent(in) :: ck(0:, 0:, -Lmax:, 0:, -Lmax:)\nif (m1 /= 0 .and. m2 /= 0 .and. m3 /= 0) then\n ! Case A\n r = 2*ck(l2, l1, m2+m3, l3, m3) &\n * real(U(m1, m2+m3) * U(m2, m2) * U(m3, m3), dp) &\n + 2*ck(l2, l1, m2-m3, l3, -m3) &\n * real(U(m1, m2-m3) * U(m2, m2) * U(m3, -m3), dp)\nelse if (m1 /= 0 .and. m2 /= 0 .and. m3 == 0) then\n ! Case B\n r = 2*ck(l2, l1, m2, l3, 0) * real(U(m1, m2) * U(m2, m2), dp)\nelse if (m1 /= 0 .and. m2 == 0 .and. m3 /= 0) then\n ! Convert to case B\n r = gauntr(l1, m1, l3, m3, l2, m2, ck, Lmax)\nelse if (m1 == 0 .and. m2 /= 0 .and. m3 /= 0) then\n ! Convert to case B\n r = gauntr(l3, m3, l2, m2, l1, m1, ck, Lmax)\nelse if (m2 == 0 .and. m3 == 0) then\n ! Case C\n r = ck(l2, l1, 0, l3, 0) * delta(m1, 0)\nelse if (m1 == 0 .and. m3 == 0) then\n ! Convert to case C\n r = gauntr(l2, m2, l1, m1, l3, m3, ck, Lmax)\nelse if (m1 == 0 .and. m2 == 0) then\n ! Convert to case C\n r = gauntr(l3, m3, l1, m1, l2, m2, ck, Lmax)\nelse\n r = 0 ! silence gfortran warning\n call stop_error(\"Internal error.\")\nend if\n\ncontains\n\ninteger function delta(a, b) result(r)\ninteger, intent(in) :: a, b\nif (a == b) then\n r = 1\nelse\n r = 0\nend if\nend function\n\ncomplex(dp) function U(mu, m) result(r)\ninteger, intent(in) :: mu, m\nif (mu > 0) then\n r = (delta(mu, m) + (-1)**m * delta(mu, -m))/sqrt(2._dp)\nelse if (mu == 0) then\n r = delta(0, m)\nelse\n r = (delta(mu, -m) - (-1)**m * delta(mu, m))/(i_ * sqrt(2._dp))\nend if\nend function\n\nend function\n\n\nsubroutine Fm(maxm, t, F)\n! Calculates F_m(t) for m=0,1,..,maxm, where\n!\n! F_m(t) = \\int_0^1 u^(2m) e^(-tu^2) du\n!\n! And assigns the result to the array F(m) = F_m(t).\n!\n! Conditions on max, t: 0 <= maxm <= 500, t >= 0.\n!\n! This routine is tested for absolute accuracy 1e-15 and relative accuracy\n! 1e-12 for all maxm = 0..500 and all values \"t\" from the interval\n! 0 <= t <= 2e8.\n!\n! The algorithm is based on [1], all equations are references from there. The\n! idea is to use series expansion for F_maxm(t) and then the recursive relation\n! (24) downwards to calculate F_m(t) for m < maxm. For t >= maxm + 0.5, the\n! series would take too many iterations to converge and also the downwards\n! relation (24) becomes inaccurate, so we calculate F_0(t) directly and use\n! (24) upwards.\n!\n! [1] I. Shavitt: Methods in Computational Physics (Academic Press Inc., New\n! York, 1963), vol. 2\ninteger, intent(in) :: maxm\nreal(dp), intent(in) :: t\n! The array F(0:maxm) will be equal to F(m) = F_m(t) for m = 0..maxm\nreal(dp), intent(out) :: F(0:)\n\nreal(dp) :: s, term\ninteger :: m\nif (maxm < 0 .or. maxm > 500) &\n call stop_error(\"Fm: only works for 0 <= m <= 500\")\nif (t < 0) call stop_error(\"Fm: only works for t >= 0\")\nif (ubound(F, 1) /= maxm) call stop_error(\"Fm: invalid bounds on F\")\n\nif (t < maxm + 0.5_dp) then\n ! Series expansion for F_m(t), between equations (24) and (25).\n ! Since (2*t)/(2*maxm+1) < 1, this will converge fast:\n term = 1._dp / (2*maxm + 1)\n s = term\n m = 1\n do while (term/s > epsilon(1._dp))\n term = term * (2*t) / (2*maxm + 2 * m + 1)\n ! \"s\" will only change if term/s > machine eps\n s = s + term\n m = m + 1\n end do\n F(maxm) = s * exp(-t)\n ! Eq. (24) downwards, for t < maxm+0.5, this converges well:\n do m = maxm-1, 0, -1\n F(m) = (2*t*F(m + 1) + exp(-t)) / (2*m + 1)\n end do\nelse\n ! Eq. for F_0(t) on page 7:\n F(0) = 0.5_dp * sqrt(pi/t) * erf(sqrt(t))\n ! Eq. (24) upwards, for t >= maxm+0.5, this converges well:\n do m = 0, maxm-1\n F(m + 1) = ((2*m + 1)*F(m) - exp(-t)) / (2*t)\n end do\nendif\nend subroutine\n\n\nreal(dp) function Knu_asympt_sum(nu, x) result(s)\n! If nu = k + 1/2 for k = 0, 1, 2, ..., then the series terminates (the result\n! is a polynomial) and this function returns an exact result for all \"x\".\nreal(dp), intent(in) :: nu, x\nreal(dp) :: term, max_term\ninteger :: k\nterm = 1\ns = term\nmax_term = abs(term)\nk = 1\ndo while (term/s > epsilon(1._dp))\n term = term * (4*nu**2-(2*k-1)**2)/(8*k*x)\n if (abs(term) > max_term) max_term = abs(term)\n if (max_term > 1e100_dp) then\n call stop_error(\"Knu asymptotic series does not converge.\")\n end if\n s = s + term\n k = k + 1\nend do\n\nif (max_term / abs(s) > 10) then\n call stop_error(\"Knu asymptotic series lost too many significant digits.\")\nend if\nend function\n\nreal(dp) function Inu_asympt_sum(nu, x) result(s)\n! If nu = k + 1/2 for k = 0, 1, 2, ..., then the series terminates (the result\n! is a polynomial), however, unlike Knu_asympt_sum(), this polynomial is only\n! valid asymptotically. The exact result contains functions sinh(x) and\n! cosh(x). As such, sinh(x)/exp(x) = cosh(x)/exp(x) = 1/2 for\n! x > -log(epsilon(1._dp))/2. Then this function returns exact result for the\n! given floating point precision for all x satisfying the inequality.\nreal(dp), intent(in) :: nu, x\nreal(dp) :: term, max_term\ninteger :: k\nterm = 1\ns = term\nmax_term = abs(term)\nk = 1\ndo while (term/s > epsilon(1._dp))\n term = - term * (4*nu**2-(2*k-1)**2)/(8*k*x)\n if (abs(term) > max_term) max_term = abs(term)\n if (max_term > 1e100_dp) then\n call stop_error(\"Inu asymptotic series does not converge.\")\n end if\n s = s + term\n k = k + 1\nend do\n\nif (max_term / abs(s) > 10) then\n call stop_error(\"Inu asymptotic series lost too many significant digits.\")\nend if\nend function\n\nreal(dp) function hyp0f1(a, x) result(s)\nreal(dp), intent(in) :: a, x\nreal(dp) :: term, max_term\ninteger :: k\nterm = 1\ns = term\nmax_term = abs(term)\nk = 1\ndo while (term/s > epsilon(1._dp))\n term = term * x/(k*(a+k-1))\n if (abs(term) > max_term) max_term = abs(term)\n if (max_term > 1e100_dp) then\n call stop_error(\"hyp0f1: series does not converge.\")\n end if\n s = s + term\n k = k + 1\nend do\n\nif (max_term / abs(s) > 10) then\n call stop_error(\"hyp0f1: series lost too many significant digits.\")\nend if\nend function\n\n\nreal(dp) function Inu_series(nu, x) result(r)\n! Returns the modified Bessel function of the first kind using the series\n! expansion around x=0.\nreal(dp), intent(in) :: nu, x\nr = (x/2)**nu / gamma(nu+1) * hyp0f1(nu+1, x**2/4)\nend function\n\nsubroutine Knu_formula(maxk, x, K)\n! Returns K(k) = K_{k+1/2}(x) / exp(-x) for k=-1,0,1,...,maxk.\ninteger, intent(in) :: maxk\nreal(dp), intent(in) :: x\nreal(dp), intent(out) :: K(-1:)\ninteger :: l\nK(-1) = sqrt(pi/(2*x))\nK(0) = K(-1)\ndo l = 0, maxk-1\n ! K_{nu+1} = K_{nu-1} + 2*nu*K_nu/x\n K(l + 1) = K(l-1) + (2*l + 1)*K(l)/x\nend do\nend subroutine\n\nsubroutine Inu_formula(maxk, x, I)\n! Returns I(k) = I_{k+1/2}(x) / exp(x) for k=-1,0,1,...,maxk.\ninteger, intent(in) :: maxk\nreal(dp), intent(in) :: x\nreal(dp), intent(out) :: I(-1:)\ninteger :: l\nI(-1) = (1+exp(-2*x)) / sqrt(2*pi*x)\n! I(0) = (1-exp(-2*x)) / sqrt(2*pi*x)\nif (x > -log(epsilon(1._dp))/2) then\n ! (1-exp(-2*x)) = 1 in floating point precission\n I(0) = 1 / sqrt(2*pi*x)\nelse\n ! (1-exp(-2*x)) = 2*sinh(x)/exp(x) to avoid cancellation\n I(0) = sqrt(2/(pi*x)) * sinh(x)/exp(x)\nend if\ndo l = 0, maxk-1\n ! I_{nu+1} = I_{nu-1} - 2*nu*I_nu/x\n I(l + 1) = I(l-1) - (2*l + 1)*I(l)/x\nend do\nend subroutine\n\nreal(dp) function Inu_formula2(k, x) result(r)\ninteger, intent(in) :: k\nreal(dp), intent(in) :: x\nselect case (k)\n case (0)\n ! r = sinh(x) / exp(x)\n if (x < 20) then\n r = sinh(x) / exp(x)\n else\n r = 1._dp / 2\n end if\n case (1)\n ! r = -sinh(x)/x + cosh(x)\n ! r = r * sqrt(2/(pi*x)) / exp(x)\n if (x < 0.55_dp) then\n r = x**2/3 + x**4/30 + x**6/840 + x**8/45360 + x**10/3991680 + &\n x**12/518918400 + x**14/93405312e3_dp\n r = r / exp(x)\n else if (x < 2) then\n r = (-1.0118340437504393201742626606e-13_dp + &\n x*(1.816670640113517482116741309e-12_dp + &\n x*(0.333333333318047257036705475493_dp + &\n x*(0.0283477684328350973136495456416_dp + &\n x*(0.0236972901524850660936691284628_dp + &\n x*(0.0018095002919993302530473889535_dp + &\n x*(0.000376379638016770111327098946609_dp + &\n (0.0000200246480593843172713997406232_dp + &\n 1.01338637272678665804111511983e-6_dp*x)*x)))))))/ &\n (1 + x*(1.08504330505794283765963608202_dp + &\n x*(0.556135176398351735247605123725_dp + &\n x*(0.177204358493610809522295217793_dp + &\n x*(0.0387591827785532218461461492913_dp + &\n x*(0.00603331772767809320892209353842_dp + &\n x*(0.000663930390602843320578606798458_dp + &\n (0.0000484437498700383824299885362686_dp + &\n 1.88315077527785406856560709781e-6_dp*x)*x)))))))\n else if (x < 20) then\n r = (-sinh(x)/x + cosh(x)) / exp(x)\n else\n r = (-1/x + 1) / 2\n end if\n case (2)\n ! r = (3/x**2 + 1)*sinh(x) - 3/x*cosh(x)\n ! r = r * sqrt(2/(pi*x)) / exp(x)\n if (x < 0.4_dp) then\n r = x**3/15 + x**5/210 + x**7/7560 + x**9/498960 + &\n x**11/51891840 + x**13/7783776e3_dp\n r = r / exp(x)\n else if (x < 3.5_dp) then\n r = (2.53492679940778614368716713944e-12_dp + &\n x*(-4.54239143359406142775391525584e-11_dp + &\n x*(3.74155600551604503226833667911e-10_dp + &\n x*(0.0666666647818812413079530441494_dp + &\n x*(0.00828258168209346350068333077357_dp + &\n x*(0.00316314651226673854191486006661_dp + &\n x*(0.000312916425508586674670599989463_dp + &\n (0.0000347881775004914918533122949261_dp + &\n 1.78379773794153349607916665442e-6_dp*x)*x)))))))/ &\n (1. + x*(1.12423862743404991052489502731_dp + &\n x*(0.600257501089318988530867089925_dp + &\n x*(0.20062393658095786500607161529_dp + &\n x*(0.0464529738128345227818430451247_dp + &\n x*(0.00775200781581904134897323422714_dp + &\n x*(0.000932283869002308809130049094732_dp + &\n (0.0000765450448110628850893821308195_dp + &\n 3.64978189893775492541031628736e-6_dp*x)*x)))))))\n else if (x < 8) then\n r = (-0.0500329770733375148059871692299_dp + &\n x*(0.225443974816227263854027844348_dp + &\n x*(-0.490706738714676572173733908052_dp + &\n x*(0.754739228306267786750520915722_dp + &\n x*(-0.0229222956512753039643375612586_dp + &\n x*(0.0417199171935382735527783646423_dp + &\n x*(0.00129242688582393560040014185308_dp + &\n (0.000436655909016956929989211236885_dp + &\n 0.0000544588062620298286123134699247_dp*x)*x)))))))/ &\n (1 + x*(11.1481461018360358000411784178_dp + &\n x*(2.95111664564331863128521306942_dp + &\n x*(2.07069035717497213861002964422_dp + &\n x*(0.212130624675779325122087859297_dp + &\n x*(0.0985267048591193186479900210954_dp + &\n x*(0.00581026870781213052737501655128_dp + &\n (0.00120128946303470807826705767304_dp + &\n 0.000108903528444754760503502120599_dp*x)*x)))))))\n else if (x < 20) then\n r = ((3/x**2 + 1)*sinh(x) - 3/x*cosh(x)) / exp(x)\n else\n r = (3/x**2 - 3/x + 1) / 2\n end if\n case (3)\n ! r = -(15/x**3 + 6/x)*sinh(x) + (15/x**2 + 1)*cosh(x)\n ! r = r / exp(x)\n if (x < 0.4_dp) then\n r = x**4/105 + x**6/1890 + x**8/83160 + x**10/6486480 + &\n x**12/778377600 + x**14/132324192e3_dp\n r = r / exp(x)\n else if (x < 3) then\n r = (-3.70655078828583097759525479916e-13_dp + &\n x*(7.15112302218910770115285755762e-12_dp + &\n x*(-6.36681926888695741582309642988e-11_dp + &\n x*(3.47928680854080370346525732791e-10_dp + &\n x*(0.00952380821395522376879618243177_dp + &\n x*(0.00113757240229334056047517957181_dp + &\n x*(0.000297467643525496580117283299361_dp + &\n (0.0000243340659637433371695954961197_dp + &\n 1.81721245776908511864649367981e-6_dp*x)*x)))))))/ &\n (1 + x*(1.11944472257087316750869453522_dp + &\n x*(0.595124068593635706143579962619_dp + &\n x*(0.197986316667328417652509149837_dp + &\n x*(0.0456127952595471262482188760838_dp + &\n x*(0.00757090880409778905789353557549_dp + &\n x*(0.000905726554901565254770825575224_dp + &\n (0.0000739095656995355486962496918923_dp + &\n 3.54519707102049776194411547746e-6_dp*x)*x)))))))\n else if (x < 8.5_dp) then\n r = (0.00117649571172537032041386386937_dp + &\n x*(-0.00530534669296740084953876529485_dp + &\n x*(0.0113989437968364216304855248904_dp + &\n x*(-0.0155143209720413375494757271933_dp + &\n x*(0.0245092943569822333734792982989_dp + &\n x*(-0.00194266321525633715561142461716_dp + &\n x*(0.00125839658564675731614612557048_dp + &\n (-0.0000560593512807954817946224257333_dp + &\n 0.0000154307073445195296381347198964_dp*x)*x)))))))/ &\n (1 + x*(1.93920721196223643040357762209_dp + &\n x*(0.871960706430017695531414950855_dp + &\n x*(0.294335907964445235622348955601_dp + &\n x*(0.076510324944994462960832902772_dp + &\n x*(0.0103358291871056058873144950985_dp + &\n x*(0.00249717323564249173430366673788_dp + &\n (0.0000729070672630135675918235119142_dp + &\n 0.0000308632011694791287440146822781_dp*x)*x)))))))\n else if (x < 20) then\n r = (-(15/x**3 + 6/x)*sinh(x) + (15/x**2 + 1)*cosh(x)) / exp(x)\n else\n r = (-15/x**3 + 15/x**2 - 6/x + 1)/2\n end if\n case (4)\n ! r = (105/x**4 + 45/x**2 + 1)*sinh(x) - (105/x**3 + 10/x)*cosh(x)\n ! r = r / exp(x)\n if (x < 0.2_dp) then\n r = x**5/945 + x**7/20790 + x**9/1081080 + x**11/97297200 + &\n x**13/132324192e2_dp\n r = r / exp(x)\n else if (x < 1.7_dp) then\n r = (8.24833340467311342180121686171e-18_dp + &\n x*(-2.9977388208095462038421382427e-16_dp + &\n x*(4.98591599598783667120520966419e-15_dp + &\n x*(-5.04172127797261339201651796769e-14_dp + &\n x*(3.47424275623446932695212209666e-13_dp + &\n x*(0.00105820105646713443251629043736_dp + &\n x*(0.0000979757728258499019673125884795_dp + &\n (0.0000182024072642408317859820498652_dp + &\n 1.0631472458547091790087783848e-6_dp*x)*x))))))) / &\n (1 + x*(1.09258709917337245791086210753_dp + &\n x*(0.564333846348740813775052159905_dp + &\n x*(0.181503092836557003863165983269_dp + &\n x*(0.040177538019272720474585552471_dp + &\n x*(0.00635509731709913059075978583153_dp + &\n x*(0.000715397138065847382814527384553_dp + &\n (0.0000540407967369787069953788458276_dp + &\n 2.26320060646140077482435126776e-6_dp*x)*x)))))))\n else if (x < 4) then\n r = (-1.79380868029518008655845945341e-7_dp + &\n x*(1.42021959889593932447404701528e-6_dp + &\n x*(-5.3621673060507414018999203431e-6_dp + &\n x*(0.0000128612071905009120973461141937_dp + &\n x*(-0.0000220283666472339963720124703845_dp + &\n x*(0.00108692026226442881323459546524_dp + &\n x*(-0.000108914780493366312610770062505_dp + &\n (0.0000213026860907556990203197490202_dp - &\n 2.40044294668610963152692356425e-6_dp*x)*x))))))) / &\n (1 + x*(0.92511576565864173804826819565_dp + &\n x*(0.376185570863101848786874779376_dp + &\n x*(0.0979599622990753625780606726782_dp + &\n x*(0.0139543384283183184757129378369_dp + &\n x*(0.00167710554949622675142353677903_dp + &\n x*(-0.0000841270733243543647065400772874_dp + &\n (-4.04735930419963375054951672688e-6_dp - &\n 4.82907242383463140296057166244e-6_dp*x)*x)))))))\n else if (x < 10) then\n ! Produced by:\n ! FortranForm[HornerForm[MiniMaxApproximation[((105/x^4 + 45/x^2 +\n ! 1)*Sinh[x]-(105/x^3 + 10/x)*Cosh[x])/Exp[x], {x, {4, 10}, 8, 8},\n ! WorkingPrecision->30][[2, 1]]]]\n r = (0.000395502959013236968661582656143_dp + &\n x*(-0.001434648369704841686633794071_dp + &\n x*(0.00248783474583503473135143644434_dp + &\n x*(-0.00274477921388295929464613063609_dp + &\n x*(0.00216275018107657273725589740499_dp + &\n x*(-0.000236779926184242197820134964535_dp + &\n x*(0.0000882030507076791807159699814428_dp + &\n (-4.62078105288798755556136693122e-6_dp + &\n 8.23671374777791529292655504214e-7_dp*x)*x))))))) / &\n (1 + x*(0.504839286873735708062045336271_dp + &\n x*(0.176683950009401712892997268723_dp + &\n x*(0.0438594911840609324095487447279_dp + &\n x*(0.00829753062428409331123592322788_dp + &\n x*(0.00111693697900468156881720995034_dp + &\n x*(0.000174719963536517752971223459247_dp + &\n (7.22885338737473776714257581233e-6_dp + &\n 1.64737453771748367647332279826e-6_dp*x)*x)))))))\n else if (x < 20) then\n r = (1.49435717183021678294278540018_dp + &\n x*(-1.9954827594990599398954087063_dp + &\n x*(1.19185825369343226912112655137_dp + &\n x*(-0.40866680980235804096143699423_dp + &\n x*(0.0852839860059780325406440673318_dp + &\n (-0.00980617919194154929317057489645_dp + &\n 0.000550291361244287676343295379476_dp*x)*x)))))/&\n (1 + x*(0.420439518058743727857466136746_dp + &\n x*(0.144024726914933127664739439568_dp + &\n x*(0.035261250406130055921113600336_dp + &\n x*(0.0349770458351085078647522073879_dp + &\n (-0.00860653991097136433951965579037_dp + &\n 0.00110058277850687516223459976889_dp*x)*x)))))\n else\n r = (105/x**4 - 105/x**3 + 45/x**2 - 10/x + 1)/2\n end if\n case default\n r = -1 ! For compiler warning \"fix\"\n call stop_error(\"k = \" // str(k) // \" not implemented.\")\nend select\nr = r * sqrt(2/(pi*x))\nend function\n\nreal(dp) function Knu_formula2(k, x) result(r)\ninteger, intent(in) :: k\nreal(dp), intent(in) :: x\nselect case (k)\n case (0)\n r = 1\n case (1)\n r = 1/x + 1\n case (2)\n r = 3/x**2 + 3/x + 1\n case (3)\n r = 15/x**3 + 15/x**2 + 6/x + 1\n case (4)\n r = 105/x**4 + 105/x**3 + 45/x**2 + 10/x + 1\n case default\n r = 0 ! silence gfortran warning\n call stop_error(\"k = \" // str(k) // \" not implemented.\")\nend select\nr = r * sqrt(pi/(2*x))\nend function\n\nend module\n", "meta": {"hexsha": "8d017ccd2fb09a7c355fc371974c9475c4e14e8b", "size": 23700, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/special_functions.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/special_functions.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/special_functions.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": 38.2875605816, "max_line_length": 80, "alphanum_fraction": 0.5501687764, "num_tokens": 8656, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767810736693, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6547196467915505}} {"text": "!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright (c) 1998 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Spherepack *\n! * *\n! * A Package of Fortran Subroutines and Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams and Paul Swarztrauber *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\nsubmodule(scalar_laplacian_routines) invert_scalar_laplacian_gaussian_grid\n\ncontains\n ! subroutine islapgc(nlat, nlon, isym, nt, xlmbda, sf, ids, jds, a, b,\n ! mdab, ndab, wshsgc, pertrb, ierror)\n !\n ! islapgc inverts the laplace or helmholz operator on a Gaussian\n ! grid using o(n**2) storage. given the\n ! spherical harmonic coefficients a(m, n) and b(m, n) of the right\n ! hand side slap(i, j), islapgc computes a solution sf(i, j) to\n ! the following helmhotz equation :\n !\n ! 2 2\n ! [d(sf(i, j))/dlambda /sint + d(sint*d(sf(i, j))/dtheta)/dtheta]/sint\n !\n ! - xlmbda * sf(i, j) = slap(i, j)\n !\n ! where sf(i, j) is computed at the Gaussian colatitude point theta(i)\n ! (see nlat as an input argument) and longitude\n !\n ! lambda(j) = (j-1)*2*pi/nlon\n !\n ! for i=1, ..., nlat and j=1, ..., nlon.\n !\n !\n ! input parameters\n !\n ! nlat the number of points in the gaussian colatitude grid on the\n ! full sphere. these lie in the interval (0, pi) and are computed\n ! in radians in theta(1) <...< theta(nlat) by subroutine compute_gaussian_latitudes_and_weights.\n ! if nlat is odd the equator will be included as the grid point\n ! theta((nlat + 1)/2). if nlat is even the equator will be\n ! excluded as a grid point and will lie half way between\n ! theta(nlat/2) and theta(nlat/2+1). nlat must be at least 3.\n ! note: on the half sphere, the number of grid points in the\n ! colatitudinal direction is nlat/2 if nlat is even or\n ! (nlat + 1)/2 if nlat is odd.\n !\n ! nlon the number of distinct longitude points. nlon determines\n ! the grid increment in longitude as 2*pi/nlon. for example\n ! nlon = 72 for a five degree grid. nlon must be greater\n ! than zero. the axisymmetric case corresponds to nlon=1.\n ! the efficiency of the computation is improved when nlon\n ! is a product of small prime numbers.\n !\n ! isym this parameter should have the same value input to subroutine\n ! shagc to compute the coefficients a and b for the scalar field\n ! slap. isym is set as follows:\n !\n ! = 0 no symmetries exist in slap about the equator. scalar\n ! synthesis is used to compute sf on the entire sphere.\n ! i.e., in the array sf(i, j) for i=1, ..., nlat and\n ! j=1, ..., nlon.\n !\n ! = 1 sf and slap are antisymmetric about the equator. the\n ! synthesis used to compute sf is performed on the\n ! northern hemisphere only. if nlat is odd, sf(i, j) is\n ! computed for i=1, ..., (nlat + 1)/2 and j=1, ..., nlon. if\n ! nlat is even, sf(i, j) is computed for i=1, ..., nlat/2\n ! and j=1, ..., nlon.\n !\n !\n ! = 2 sf and slap are symmetric about the equator. the\n ! synthesis used to compute sf is performed on the\n ! northern hemisphere only. if nlat is odd, sf(i, j) is\n ! computed for i=1, ..., (nlat + 1)/2 and j=1, ..., nlon. if\n ! nlat is even, sf(i, j) is computed for i=1, ..., nlat/2\n ! and j=1, ..., nlon.\n !\n !\n ! nt the number of solutions. in the program that calls islapgc\n ! the arrays sf, a, and b can be three dimensional in which\n ! case multiple solutions are computed. the third index\n ! is the solution index with values k=1, ..., nt.\n ! for a single solution set nt=1. the description of the\n ! remaining parameters is simplified by assuming that nt=1\n ! and sf, a, b are two dimensional.\n !\n ! xlmbda a one dimensional array with nt elements. if xlmbda is\n ! is identically zero islapgc solves poisson's equation.\n ! if xlmbda > 0.0 islapgc solves the helmholtz equation.\n ! if xlmbda < 0.0 the nonfatal error flag ierror=-1 is\n ! returned. negative xlambda could result in a division\n ! by zero.\n !\n ! ids the first dimension of the array sf as it appears in the\n ! program that calls islapgc. if isym = 0 then ids must be at\n ! least nlat. if isym > 0 and nlat is even then ids must be\n ! at least nlat/2. if isym > 0 and nlat is odd then ids must\n ! be at least (nlat + 1)/2.\n !\n ! jds the second dimension of the array sf as it appears in the\n ! program that calls islapgc. jds must be at least nlon.\n !\n !\n ! a, b two or three dimensional arrays (see input parameter nt)\n ! that contain scalar spherical harmonic coefficients\n ! of the scalar field slap. a, b must be computed by shagc\n ! prior to calling islapgc.\n !\n !\n ! mdab the first dimension of the arrays a and b as it appears\n ! in the program that calls islapgc. mdab must be at\n ! least min(nlat, (nlon+2)/2) if nlon is even or at least\n ! min(nlat, (nlon + 1)/2) if nlon is odd.\n !\n ! ndab the second dimension of the arrays a and b as it appears\n ! in the program that calls islapgc. ndbc must be at least\n ! least nlat.\n !\n ! mdab, ndab should have the same values input to shagc to\n ! compute the coefficients a and b.\n !\n ! wshsgc an array which must be initialized by subroutine shsgci\n ! once initialized, wshsgc can be used repeatedly by islapgc\n ! as long as nlon and nlat remain unchanged. wshsgc must\n ! not be altered between calls of islapgc.\n !\n !\n ! lshsgc the dimension of the array wshsgc as it appears in the\n ! program that calls islapgc. let\n !\n ! l1 = min(nlat, (nlon+2)/2) if nlon is even or\n ! l1 = min(nlat, (nlon + 1)/2) if nlon is odd\n !\n ! and\n !\n ! l2 = nlat/2 if nlat is even or\n ! l2 = (nlat + 1)/2 if nlat is odd\n !\n ! then lshsgc must be at least\n !\n ! nlat*(2*l2+3*l1-2)+3*l1*(1-l1)/2+nlon+15\n !\n ! output parameters\n !\n !\n ! sf a two or three dimensional arrays (see input parameter nt) that\n ! inverts the scalar laplacian in slap. sf(i, j) is given at\n ! the colatitude\n !\n ! theta(i) = (i-1)*pi/(nlat-1)\n !\n ! and longitude\n !\n ! lambda(j) = (j-1)*2*pi/nlon\n !\n ! for i=1, ..., nlat and j=1, ..., nlon.\n !\n ! pertrb a one dimensional array with nt elements (see input\n ! parameter nt). in the discription that follows we assume\n ! that nt=1. if xlmbda > 0.0 then pertrb=0.0 is always\n ! returned because the helmholtz operator is invertible.\n ! if xlmbda = 0.0 then a solution exists only if a(1, 1)\n ! is zero. islapgc sets a(1, 1) to zero. the resulting\n ! solution sf(i, j) solves poisson's equation with\n ! pertrb = a(1, 1)/(2.*sqrt(2.)) subtracted from the\n ! right side slap(i, j).\n !\n ! ierror a parameter which flags errors in input parameters as follows:\n !\n ! =-1 xlmbda is input negative (nonfatal error)\n ! = 0 no errors detected\n ! = 1 error in the specification of nlat\n ! = 2 error in the specification of nlon\n ! = 3 error in the specification of isym\n ! = 4 error in the specification of nt\n ! = 5 error in the specification of ids\n ! = 6 error in the specification of jds\n ! = 7 error in the specification of mdab\n ! = 8 error in the specification of ndab\n ! = 9 error in the specification of lshsgc\n !\n module subroutine islapgc(nlat, nlon, isym, nt, xlmbda, sf, ids, jds, a, b, &\n mdab, ndab, wshsgc, pertrb, ierror)\n\n ! Dummy arguments\n integer(ip), intent(in) :: nlat\n integer(ip), intent(in) :: nlon\n integer(ip), intent(in) :: isym\n integer(ip), intent(in) :: nt\n real(wp), intent(in) :: xlmbda(:)\n real(wp), intent(out) :: sf(ids, jds, nt)\n integer(ip), intent(in) :: ids\n integer(ip), intent(in) :: jds\n real(wp), intent(in) :: a(mdab, ndab, nt)\n real(wp), intent(in) :: b(mdab, ndab, nt)\n integer(ip), intent(in) :: mdab\n integer(ip), intent(in) :: ndab\n real(wp), intent(in) :: wshsgc(:)\n real(wp), intent(out) :: pertrb(:)\n integer(ip), intent(out) :: ierror\n\n ! Local variables\n integer(ip) :: required_wavetable_size\n type(ScalarSynthesisUtility) :: util\n\n ! Check input arguments\n required_wavetable_size = util%get_lshsgc(nlat, nlon)\n\n call util%check_scalar_transform_inputs(isym, ids, jds, &\n mdab, ndab, nlat, nlon, nt, required_wavetable_size, &\n wshsgc, ierror)\n\n ! Check sign of xlmbda\n if (any(xlmbda < ZERO)) then\n ierror = -1\n end if\n\n ! Check error flag\n if (ierror /= 0) return\n\n call invert_scalar_laplacian_lower_utility_routine(nlat, nlon, isym, &\n nt, xlmbda, pertrb, sf, a, b, wshsgc, shsgc, ierror)\n\n end subroutine islapgc\n\nend submodule invert_scalar_laplacian_gaussian_grid\n", "meta": {"hexsha": "1afd9217b7d390906e22adfc4071389064441e11", "size": 12105, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/invert_scalar_laplacian_gaussian_grid.f90", "max_stars_repo_name": "jlokimlin/spherepack4.1", "max_stars_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-06-28T14:01:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T21:59:28.000Z", "max_issues_repo_path": "src/invert_scalar_laplacian_gaussian_grid.f90", "max_issues_repo_name": "jlokimlin/spherepack4.1", "max_issues_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2016-05-07T23:00:35.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-22T23:52:30.000Z", "max_forks_repo_path": "src/invert_scalar_laplacian_gaussian_grid.f90", "max_forks_repo_name": "jlokimlin/spherepack4.1", "max_forks_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-06-28T14:03:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T12:53:54.000Z", "avg_line_length": 48.42, "max_line_length": 111, "alphanum_fraction": 0.4701363073, "num_tokens": 3133, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.746138993030751, "lm_q1q2_score": 0.654719646619559}} {"text": " INTEGER FUNCTION ignnbn(n,p)\nC**********************************************************************\nC\nC INTEGER FUNCTION IGNNBN( N, P )\nC\nC GENerate Negative BiNomial random deviate\nC\nC\nC Function\nC\nC\nC Generates a single random deviate from a negative binomial\nC distribution.\nC\nC\nC Arguments\nC\nC\nC N --> Required number of events.\nC INTEGER N\nC JJV (N > 0)\nC\nC P --> The probability of an event during a Bernoulli trial.\nC DOUBLE PRECISION P\nC JJV (0.0 < P < 1.0)\nC\nC\nC\nC Method\nC\nC\nC Algorithm from page 480 of\nC\nC Devroye, Luc\nC\nC Non-Uniform Random Variate Generation. Springer-Verlag,\nC New York, 1986.\nC\nC**********************************************************************\nC ..\nC .. Scalar Arguments ..\n DOUBLE PRECISION p\n INTEGER n\nC ..\nC .. Local Scalars ..\n DOUBLE PRECISION y,a,r\nC ..\nC .. External Functions ..\nC JJV changed to call SGAMMA directly\nC DOUBLE PRECISION gengam\n DOUBLE PRECISION sgamma\n INTEGER ignpoi\nC EXTERNAL gengam,ignpoi\n EXTERNAL sgamma,ignpoi\nC ..\nC .. Intrinsic Functions ..\n INTRINSIC real\nC ..\nC .. Executable Statements ..\nC Check Arguments\nC JJV changed argumnet checker to abort if N <= 0\nC See Rand,c \nC Generate Y, a random gamma (n,(1-p)/p) variable\nC JJV Note: the above parametrization is consistent with Devroye,\nC JJV but gamma (p/(1-p),n) is the equivalent in our code\n 10 r = dble(n)\n a = p/ (1.0-p)\nC y = gengam(a,r)\n y = sgamma(r)/a\n\nC Generate a random Poisson(y) variable\n ignnbn = ignpoi(y)\n RETURN\n\n END\n", "meta": {"hexsha": "6720b6f086bc5c07db29aec5b1dac6de982bde75", "size": 1873, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/rnd/ignnbn.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/ignnbn.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/ignnbn.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.6447368421, "max_line_length": 71, "alphanum_fraction": 0.507741591, "num_tokens": 492, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232809, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6547000975737247}} {"text": "! =====================================================================\n! subroutine VAHO \n!\n! This subroutine constructs a polar simple harmonic oscillator\n! potential. It may be used to generate an inital wavefuction that is\n! correctly aligned with the potential minimum of the simple harmonic\n! oscillator ring.\n! ---------------------------------------------------------------------\n subroutine VAHO(nRP,nR,nP,r0,p0,kR,kP,R,P,V)\n implicit none\n\n integer :: nRP\n integer :: nR\n integer :: nP\n double precision :: pi\n double precision :: r0\n double precision :: p0\n double precision :: kR\n double precision :: kP\n double precision :: R(nR)\n double precision :: P(nP)\n double precision :: V(nRP)\n\n integer :: i\n integer :: j\n integer :: k\n\n pi = 3.14159265358979323846d0\n\n k = 0\n do j = 1, nP\n do i = 1, nR\n k = k + 1\n if (P(j).le.(1.5*pi)) then\n V(k) = 0.5d0*(kR*(R(i)-r0))**2+0.5d0*(kP*r0*(P(j)-p0))**2\n else\n V(k) = 0.5d0*(kR*(R(i)-r0))**2+0.5d0*(kP*r0*(P(j)-p0- 2.0d0*pi))**2\n endif\n enddo\n enddo\n\n return\n end\n! =====================================================================\n", "meta": {"hexsha": "98b6970a92dcf667517bbc03326ff82a16ba90b6", "size": 1287, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/vaho.f", "max_stars_repo_name": "mkandes/itpprp", "max_stars_repo_head_hexsha": "d30f4fc0b05822a34fef187688ab12245cbbf93a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source/vaho.f", "max_issues_repo_name": "mkandes/itpprp", "max_issues_repo_head_hexsha": "d30f4fc0b05822a34fef187688ab12245cbbf93a", "max_issues_repo_licenses": ["MIT"], "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/vaho.f", "max_forks_repo_name": "mkandes/itpprp", "max_forks_repo_head_hexsha": "d30f4fc0b05822a34fef187688ab12245cbbf93a", "max_forks_repo_licenses": ["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.6, "max_line_length": 82, "alphanum_fraction": 0.4452214452, "num_tokens": 357, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972684083609, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6547000973626478}} {"text": "program main\n implicit none\n integer*4 :: nd, Ns, Nt\n\n nd = 1\n Ns = 1000\n Nt = 1000\n call test(nd, Ns, Nt)\nend\n\nsubroutine test(nd, Ns, Nt)\n use iso_c_binding\n implicit none\n include 'kernels.f90'\n integer*4 :: i, nd, Ns, Nt\n real*8 :: Xs(Ns*3), Xt(Nt*3), thresh\n complex*16 :: zk, Vs(Ns*nd), Vt(Nt*nd), Vt_ref(Nt*nd)\n double precision :: omp_get_wtime, tt\n real*4 :: rand\n\n zk = (1.0,1.0)\n thresh = 1.0e-12\n\n call srand(0)\n do i=1, Ns*3\n Xs(i) = rand(0)\n enddo\n do i=1, Ns\n Vs(i) = rand(0)\n enddo\n do i=1, Nt*3\n Xt(i) = rand(0)\n enddo\n do i=1, Nt\n Vt(i) = (0,0)\n Vt_ref(i) = (0,0)\n enddo\n\n tt = -omp_get_wtime()\n do i=1,100\n call helm3d_d(nd, zk, Xs, Vs, ns, Xt, nt, Vt_ref, thresh)\n enddo\n tt = tt + omp_get_wtime()\n print*, \"Unvectorized : \", tt\n\n tt = -omp_get_wtime()\n do i=1,100\n call helm3d_vec_d(nd, zk, Xs, Vs, ns, Xt, nt, Vt, thresh)\n enddo\n tt = tt + omp_get_wtime()\n print*, \"Vectorized : \", tt\n\n print*, \"Maximum relative error : \", maxval(abs(Vt_ref - Vt)) / maxval(abs(Vt_ref));\nendsubroutine\n\n", "meta": {"hexsha": "cbc5398b8ecbd30e8e7ff5c9bbb70ec4272ccc0a", "size": 1066, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "vec-kernels/src/test-fortran.f90", "max_stars_repo_name": "ejyoo921/FMM3D", "max_stars_repo_head_hexsha": "6aeb4031340c1aeca0754f0fd2b7ef8e754a449e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 71, "max_stars_repo_stars_event_min_datetime": "2019-06-03T21:22:37.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-03T01:15:45.000Z", "max_issues_repo_path": "vec-kernels/src/test-fortran.f90", "max_issues_repo_name": "ejyoo921/FMM3D", "max_issues_repo_head_hexsha": "6aeb4031340c1aeca0754f0fd2b7ef8e754a449e", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 14, "max_issues_repo_issues_event_min_datetime": "2019-08-22T19:58:36.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-08T19:01:06.000Z", "max_forks_repo_path": "vec-kernels/src/test-fortran.f90", "max_forks_repo_name": "ejyoo921/FMM3D", "max_forks_repo_head_hexsha": "6aeb4031340c1aeca0754f0fd2b7ef8e754a449e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2019-09-13T21:30:35.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-26T12:34:42.000Z", "avg_line_length": 19.0357142857, "max_line_length": 86, "alphanum_fraction": 0.5844277674, "num_tokens": 469, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232808, "lm_q2_score": 0.752012562644147, "lm_q1q2_score": 0.6547000878964698}} {"text": "subroutine downhill(n,func,xstart,fstart,stepi,epsf,itmin,iter)\n!\n! n dimension of the problem\n! func function\n! xstart starting values\n! fstart conrespoding function value\n! stepi relative stepsize for initial simplex\n! epsf epsilon for termination\n! itmin termination is tested if itmin < it\n! iter maximum number of iterations\n!\n\n use NumType\n implicit none\n integer :: n, iter, itmin\n real(dp), external :: func\n real(dp) :: xstart(1:n), fstart, stepi, epsf\n real(dp), parameter :: alph=1._dp, gamm=2._dp, &\n rho=0.5_dp, sig=0.5_dp\n real(dp) :: xi(1:n,1:n+1), x(1:n,1:n+1), &\n fi(1:n+1), f(1:n+1), &\n x0(1:n), xr(1:n), xe(1:n), xc(1:n), &\n fxr, fxe, fxc, deltaf\n integer :: i, ii, it\n \n xi(1:n,1) = xstart(1:n); fi(1) = fstart\n do i = 2, n+1\n xi(1:n,i)=xi(1:n,1)\n xi(i-1,i)=xi(i-1,i)*(1+stepi)\n fi(i)=func(xi(1:n,i))\n end do\n \n do it = 1, iter \n\n do i = 1, n+1 ! ordering\n ii = minloc(fi(1:n+1),dim=1)\n x(1:n,i) = xi(1:n,ii); f(i) = fi(ii)\n fi(ii) = huge(0._dp)\n end do\n xi(1:n,1:n+1) = x(1:n,1:n+1)\n fi(1:n+1) = f(1:n+1)\n\n x0(1:n) = sum(x(1:n,1:n),dim=2)/n ! central\n\n\n if ( itmin < it ) then ! condition for exit\n deltaf = (f(n)-f(1))\n !write(777,*) it,deltaf\n if(deltaf < epsf ) then\n exit\n end if\n end if\n \n xr(1:n) = x0(1:n)+alph*(x0(1:n)-x(1:n,n+1))\n fxr = func(xr)\n if( fxr < f(n) .and. & ! reflection\n f(1) <= fxr ) then \n xi(1:n,n+1) = xr(1:n); fi(n+1) = fxr\n cycle\n \n else if ( fxr < f(1) ) then ! expansion\n xe(1:n) = x0(1:n)+gamm*(x0(1:n)-x(1:n,n+1))\n fxe = func(xe)\n if( fxe < fxr ) then\n xi(1:n,n+1) = xe(1:n); fi(n+1) = fxe\n cycle\n else\n xi(1:n,n+1) = xr(1:n); fi(n+1) = fxr\n cycle\n end if\n\n else if ( fxr >= f(n) ) then ! contraction\n xc(1:n) = x(1:n,n+1)+rho*(x0(1:n)-x(1:n,n+1))\n fxc = func(xc)\n if( fxc <= f(n+1) ) then\n xi(1:n,n+1) = xc(1:n); fi(n+1) = fxc\n cycle\n else ! reduction\n do i = 2, n+1\n xi(1:n,i) = x(1:n,1)+sig*(x(1:n,i)-x(1:n,1))\n fi(i) = func(xi(1:n,i))\n end do\n cycle\n end if\n \n end if\n \n end do\n \n xstart(1:n)=xi(1:n,1); fstart = fi(1)\n\nend subroutine downhill\n\n\n", "meta": {"hexsha": "9ac27b5952d0c6814171430bc743c9de280ea4de", "size": 2849, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "gaussian_fit_fortran/downhill-pe.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/downhill-pe.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/downhill-pe.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": 29.9894736842, "max_line_length": 64, "alphanum_fraction": 0.404001404, "num_tokens": 976, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972549785201, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6547000872632386}} {"text": " subroutine compute_c5(n_A,n_Athth,n_Axx,n_B,n_K,n_rho,x,Nx,myzero,\n &phys_bdy,res)\n implicit none\n integer i\n integer Nx\n real*8 myzero\n real*8 n_A(Nx)\n real*8 n_Athth(Nx)\n real*8 n_Axx(Nx)\n real*8 n_B(Nx)\n real*8 n_K(Nx)\n real*8 n_rho(Nx)\n real*8 x(Nx)\n integer phys_bdy(2)\n real*8 res(Nx)\n real*8 qb\n if (phys_bdy(1) .eq. 1) then\n do i=1, 1, 1\n qb = myzero * x(i)\n res(i)=qb\n end do\n endif\n do i=2, Nx-1, 1\n qb = -0.8333333333333333D-1 * n_K(i) ** 2 + 0.2500000000000000D0 *\n # n_rho(i) + 0.1250000000000000D0 / n_A(i) ** 2 * n_Axx(i) ** 2 + 0\n #.2500000000000000D0 / n_B(i) ** 2 * n_Athth(i) ** 2\n res(i)=qb\n end do\n if (phys_bdy(2) .eq. 1) then\n do i=Nx, Nx, 1\n qb = myzero * x(i)\n res(i)=qb\n end do\n endif\n END\n", "meta": {"hexsha": "67575892ef8e642b15db043add7cb18c91405140", "size": 889, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/FD/compute_c5.f", "max_stars_repo_name": "rmanak/bssn_spher", "max_stars_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/FD/compute_c5.f", "max_issues_repo_name": "rmanak/bssn_spher", "max_issues_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/FD/compute_c5.f", "max_forks_repo_name": "rmanak/bssn_spher", "max_forks_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.6944444444, "max_line_length": 72, "alphanum_fraction": 0.5106861642, "num_tokens": 372, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110540642805, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.654695914281739}} {"text": "C$Procedure ROTMAT ( Rotate a matrix )\n \n SUBROUTINE ROTMAT ( M1, ANGLE, IAXIS, MOUT )\n \nC$ Abstract\nC\nC ROTMAT applies a rotation of ANGLE radians about axis IAXIS to a\nC matrix. This rotation is thought of as rotating the coordinate\nC system.\nC\nC$ Disclaimer\nC\nC THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE\nC CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.\nC GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE\nC ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE\nC PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED \"AS-IS\"\nC TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY\nC WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A\nC PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC\nC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE\nC SOFTWARE AND RELATED MATERIALS, HOWEVER USED.\nC\nC IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA\nC BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT\nC LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,\nC INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,\nC REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE\nC REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.\nC\nC RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF\nC THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY\nC CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE\nC ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.\nC\nC$ Required_Reading\nC\nC None.\nC\nC$ Keywords\nC\nC MATRIX\nC ROTATION\nC\nC$ Declarations\n \n DOUBLE PRECISION M1 ( 3,3 )\n DOUBLE PRECISION ANGLE\n INTEGER IAXIS\n DOUBLE PRECISION MOUT ( 3,3 )\n \nC$ Brief_I/O\nC\nC VARIABLE I/O DESCRIPTION\nC -------- --- --------------------------------------------------\nC M1 I Matrix to be rotated.\nC ANGLE I Angle of rotation (radians).\nC IAXIS I Axis of rotation (X=1, Y=2, Z=3).\nC MOUT O Resulting rotated matrix [ANGLE] * M1\nC IAXIS\nC\nC$ Detailed_Input\nC\nC M1 This is a matrix to which a rotation is to be applied.\nC In matrix algebra, the components of the matrix are\nC relevant in one particular coordinate system. Applying\nC ROTMAT changes the components of M1 so that they are\nC relevant to a rotated coordinate system.\nC\nC ANGLE The angle in radians through which the original\nC coordinate system is to be rotated.\nC\nC IAXIS An index for the axis of the original coordinate system\nC about which the rotation by ANGLE is to be performed.\nC IAXIS = 1,2 or 3 designates the x-, y- or z-axis,\nC respectively.\nC\nC$ Detailed_Output\nC\nC MOUT The matrix resulting from the application of the\nC specified rotation to the input matrix M1. If\nC [ANGLE] denotes the rotation matrix by ANGLE\nC IAXIS\nC radians about IAXIS, (refer to the routine ROTATE) then\nC MOUT is given by the following matrix equation:\nC\nC MOUT = [ANGLE] * M1\nC IAXIS\nC\nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC Error free.\nC\nC 1) If the axis index is not in the range 1 to 3 it will be\nC treated the same as that integer 1, 2, or 3 that is congruent\nC to it mod 3.\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC None.\nC\nC$ Examples\nC\nC Suppose that to rotate a set of inertial axes to body fixed\nC axes, one must first roll the coordinate axes about the x-axis by\nC angle R to get x', y', z'. From this one must pitch about the y'\nC axis by angle P to get x'', y'', z''. And finally yaw the x'',\nC y'', z'' about the z'' axis by angle Y to obtain the\nC transformation to bodyfixed coordinates. If ID is the identity\nC matrix, then the following code fragment generates the\nC transformation from inertial to body fixed.\nC\nC CALL ROTMAT ( ID, R, 1, M1 )\nC CALL ROTMAT ( M1, P, 2, M2 )\nC CALL ROTMAT ( M2, Y, 3, TIBF )\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC W.M. Owen (JPL)\nC W.L. Taber (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.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 rotate a matrix\nC\nC-&\n \n \nC$ Revisions\nC\nC- Beta Version 1.1.0, 3-JAN-1989 (WLT)\nC\nC Upgrade the routine to work with negative axis indexes. Also take\nC care of the funky way the indices (other than the input) were\nC obtained via the MOD function. It works but isn't as clear\nC (or fast) as just reading the axes from data.\nC\nC-&\n \n \n \n DOUBLE PRECISION S\n DOUBLE PRECISION C\n \n INTEGER TEMP\n INTEGER I1\n INTEGER I2\n INTEGER I3\n INTEGER I\n \n DOUBLE PRECISION PRODM (3,3)\n \n INTEGER INDEXS (5)\n SAVE INDEXS\n \n DATA INDEXS / 3, 1, 2, 3, 1 /\nC\nC Get the sine and cosine of ANGLE\nC\n S = DSIN(ANGLE)\n C = DCOS(ANGLE)\nC\nC Get indices for axes. The first index is for the axis of rotation.\nC The next two axes follow in right hand order (XYZ). First get the\nC non-negative value of IAXIS mod 3 .\nC\n TEMP = MOD ( MOD(IAXIS,3) + 3, 3 )\n \n I1 = INDEXS( TEMP + 1 )\n I2 = INDEXS( TEMP + 2 )\n I3 = INDEXS( TEMP + 3 )\nC\nC Calculate the output matrix column by column\nC\n DO I=1,3\n PRODM(I1,I) = M1(I1,I)\n PRODM(I2,I) = C*M1(I2,I) + S*M1(I3,I)\n PRODM(I3,I) = -S*M1(I2,I) + C*M1(I3,I)\n END DO\nC\nC Move the buffered matrix into MOUT.\nC\n CALL MOVED (PRODM, 9, MOUT)\nC\n RETURN\n END\n", "meta": {"hexsha": "b07574092be198d8b3df2f69b7d33b360a7e7b07", "size": 6434, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/rotmat.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/rotmat.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/rotmat.f", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 29.3789954338, "max_line_length": 72, "alphanum_fraction": 0.6122163506, "num_tokens": 1878, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379297, "lm_q2_score": 0.7341195385342971, "lm_q1q2_score": 0.654695913136682}} {"text": "program test_stats_var\n use forlab_io, only: disp\n use forlab_stats, only: var,randn,rng,mean,std\n real, allocatable :: x(:)\n call rng()\n allocate(X(5))\n x = randn(mean=0.0, std=1.0, ndim=5)\n call disp(x,'randn(n)')\n call disp(mean(x),'mean(randn(n)):')\n call disp(var(x),'var(randn(n)):')\n call disp(std(x), 'std(randn(n)):')\n if(allocated(X)) deallocate(X)\n allocate(X(4)) !!\\FIXME:\n x = randn(mean=10.0, std=1.0, ndim=4)\n call disp(X,'call randn(X,10.,1.0)')\nend program test_stats_var", "meta": {"hexsha": "3ac81a8a4e17e7386f35c43f0a127e85985f80ea", "size": 531, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/stats/test_stats_var.f90", "max_stars_repo_name": "zoziha/forlab_z", "max_stars_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2021-08-31T15:23:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-13T02:44:46.000Z", "max_issues_repo_path": "test/stats/test_stats_var.f90", "max_issues_repo_name": "zoziha/forlab_z", "max_issues_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-08-22T11:47:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-31T00:57:16.000Z", "max_forks_repo_path": "test/stats/test_stats_var.f90", "max_forks_repo_name": "zoziha/forlab_z", "max_forks_repo_head_hexsha": "354846b03f4dcccffc17ae5aed09000a5d64227c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-07-16T03:16:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-31T13:09:42.000Z", "avg_line_length": 33.1875, "max_line_length": 50, "alphanum_fraction": 0.604519774, "num_tokens": 184, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8918110569397306, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.6546959112049473}} {"text": " program ssvd\nc\nc This example program is intended to illustrate the \nc the use of ARPACK to compute the Singular Value Decomposition.\nc \nc This code shows how to use ARPACK to find a few of the\nc largest singular values(sigma) and corresponding right singular \nc vectors (v) for the the matrix A by solving the symmetric problem:\nc \nc (A'*A)*v = sigma*v\nc \nc where A is an m by n real matrix.\nc\nc This code may be easily modified to estimate the 2-norm\nc condition number largest(sigma)/smallest(sigma) by setting\nc which = 'BE' below. This will ask for a few of the smallest\nc and a few of the largest singular values simultaneously.\nc The condition number could then be estimated by taking\nc the ratio of the largest and smallest singular values.\nc\nc This formulation is appropriate when m .ge. n.\nc Reverse the roles of A and A' in the case that m .le. n.\nc\nc The main points illustrated here are \nc\nc 1) How to declare sufficient memory to find NEV \nc largest singular values of A . \nc\nc 2) Illustration of the reverse communication interface \nc needed to utilize the top level ARPACK routine SSAUPD \nc that computes the quantities needed to construct\nc the desired singular values and vectors(if requested).\nc\nc 3) How to extract the desired singular values and vectors\nc using the ARPACK routine SSEUPD.\nc\nc 4) How to construct the left singular vectors U from the \nc right singular vectors V to obtain the decomposition\nc\nc A*V = U*S\nc\nc where S = diag(sigma_1, sigma_2, ..., sigma_k).\nc\nc The only thing that must be supplied in order to use this\nc routine on your problem is to change the array dimensions \nc appropriately, to specify WHICH singular values you want to \nc compute and to supply a the matrix-vector products \nc\nc w <- Ax\nc y <- A'w\nc\nc in place of the calls to AV( ) and ATV( ) respectively below. \nc\nc Further documentation is available in the header of DSAUPD\nc which may be found in the SRC directory.\nc\nc This codes implements\nc\nc\\Example-1\nc ... Suppose we want to solve A'A*v = sigma*v in regular mode,\nc where A is derived from the simplest finite difference \nc discretization of the 2-dimensional kernel K(s,t)dt where\nc\nc K(s,t) = s(t-1) if 0 .le. s .le. t .le. 1,\nc t(s-1) if 0 .le. t .lt. s .le. 1. \nc\nc See subroutines AV and ATV for details.\nc ... OP = A'*A and B = I.\nc ... Assume \"call av (n,x,y)\" computes y = A*x\nc ... Assume \"call atv (n,y,w)\" computes w = A'*y\nc ... Assume exact shifts are used\nc ...\nc\nc\\BeginLib\nc\nc\\Routines called:\nc ssaupd ARPACK reverse communication interface routine.\nc sseupd ARPACK routine that returns Ritz values and (optionally)\nc Ritz vectors.\nc snrm2 Level 1 BLAS that computes the norm of a vector.\nc saxpy Level 1 BLAS that computes y <- alpha*x+y.\nc sscal Level 1 BLAS thst computes x <- x*alpha.\nc scopy Level 1 BLAS thst computes y <- x.\nc\nc\\Author\nc Richard Lehoucq\nc Danny Sorensen\nc Chao Yang\nc Dept. of Computational &\nc Applied Mathematics\nc Rice University\nc Houston, Texas\nc\nc\\SCCS Information: @(#)\nc FILE: svd.F SID: 2.4 DATE OF SID: 10/17/00 RELEASE: 2\nc\nc\\Remarks\nc 1. None\nc\nc\\EndLib\nc\nc-----------------------------------------------------------------------\nc\nc %------------------------------------------------------%\nc | Storage Declarations: |\nc | |\nc | It is assumed that A is M by N with M .ge. N. |\nc | |\nc | The maximum dimensions for all arrays are |\nc | set here to accommodate a problem size of |\nc | M .le. MAXM and N .le. MAXN |\nc | |\nc | The NEV right singular vectors will be computed in |\nc | the N by NCV array V. |\nc | |\nc | The NEV left singular vectors will be computed in |\nc | the M by NEV array U. |\nc | |\nc | NEV is the number of singular values requested. |\nc | See specifications for ARPACK usage below. |\nc | |\nc | NCV is the largest number of basis vectors that will |\nc | be used in the Implicitly Restarted Arnoldi |\nc | Process. Work per major iteration is |\nc | proportional to N*NCV*NCV. |\nc | |\nc | You must set: |\nc | |\nc | MAXM: Maximum number of rows of the A allowed. |\nc | MAXN: Maximum number of columns of the A allowed. |\nc | MAXNEV: Maximum NEV allowed |\nc | MAXNCV: Maximum NCV allowed |\nc %------------------------------------------------------%\nc\n integer maxm, maxn, maxnev, maxncv, ldv, ldu\n parameter (maxm = 500, maxn=250, maxnev=10, maxncv=25, \n & ldu = maxm, ldv=maxn )\nc\nc %--------------%\nc | Local Arrays |\nc %--------------%\nc\n Real\n & v(ldv,maxncv), u(ldu, maxnev), \n & workl(maxncv*(maxncv+8)), workd(3*maxn), \n & s(maxncv,2), resid(maxn), ax(maxm)\n logical select(maxncv)\n integer iparam(11), ipntr(11)\nc\nc %---------------%\nc | Local Scalars |\nc %---------------%\nc\n character bmat*1, which*2\n integer ido, m, n, nev, ncv, lworkl, info, ierr,\n & j, ishfts, maxitr, mode1, nconv\n logical rvec\n Real \n & tol, sigma, temp\nc\nc %------------%\nc | Parameters |\nc %------------%\nc\n Real\n & one, zero\n parameter (one = 1.0E+0, zero = 0.0E+0)\nc \nc %-----------------------------%\nc | BLAS & LAPACK routines used |\nc %-----------------------------%\nc\n Real \n & snrm2\n external snrm2, saxpy, scopy, sscal\nc\nc %-----------------------%\nc | Executable Statements |\nc %-----------------------%\nc\nc %-------------------------------------------------%\nc | The following include statement and assignments |\nc | initiate trace output from the internal |\nc | actions of ARPACK. See debug.doc in the |\nc | DOCUMENTS directory for usage. Initially, the |\nc | most useful information will be a breakdown of |\nc | time spent in the various stages of computation |\nc | given by setting msaupd = 1. |\nc %-------------------------------------------------%\nc\n include 'debug.h'\n ndigit = -3\n logfil = 6\n msgets = 0\n msaitr = 0 \n msapps = 0\n msaupd = 1\n msaup2 = 0\n mseigt = 0\n mseupd = 0\nc\nc %-------------------------------------------------%\nc | The following sets dimensions for this problem. |\nc %-------------------------------------------------%\nc\n m = 500\n n = 100\nc\nc %------------------------------------------------%\nc | Specifications for ARPACK usage are set | \nc | below: |\nc | |\nc | 1) NEV = 4 asks for 4 singular values to be | \nc | computed. | \nc | |\nc | 2) NCV = 20 sets the length of the Arnoldi |\nc | factorization |\nc | |\nc | 3) This is a standard problem |\nc | (indicated by bmat = 'I') |\nc | |\nc | 4) Ask for the NEV singular values of |\nc | largest magnitude |\nc | (indicated by which = 'LM') |\nc | See documentation in SSAUPD for the |\nc | other options SM, BE. | \nc | |\nc | Note: NEV and NCV must satisfy the following |\nc | conditions: |\nc | NEV <= MAXNEV, |\nc | NEV + 1 <= NCV <= MAXNCV |\nc %------------------------------------------------%\nc\n nev = 4\n ncv = 10 \n bmat = 'I'\n which = 'LM'\nc\n if ( n .gt. maxn ) then\n print *, ' ERROR with _SVD: N is greater than MAXN '\n go to 9000\n else if ( m .gt. maxm ) then\n print *, ' ERROR with _SVD: M is greater than MAXM '\n go to 9000\n else if ( nev .gt. maxnev ) then\n print *, ' ERROR with _SVD: NEV is greater than MAXNEV '\n go to 9000\n else if ( ncv .gt. maxncv ) then\n print *, ' ERROR with _SVD: NCV is greater than MAXNCV '\n go to 9000\n end if\nc\nc %-----------------------------------------------------%\nc | Specification of stopping rules and initial |\nc | conditions before calling SSAUPD |\nc | |\nc | abs(sigmaC - sigmaT) < TOL*abs(sigmaC) |\nc | computed true |\nc | |\nc | If TOL .le. 0, then TOL <- macheps |\nc | (machine precision) is used. |\nc | |\nc | IDO is the REVERSE COMMUNICATION parameter |\nc | used to specify actions to be taken on return |\nc | from SSAUPD. (See usage below.) |\nc | |\nc | It MUST initially be set to 0 before the first |\nc | call to SSAUPD. | \nc | |\nc | INFO on entry specifies starting vector information |\nc | and on return indicates error codes |\nc | |\nc | Initially, setting INFO=0 indicates that a | \nc | random starting vector is requested to |\nc | start the ARNOLDI iteration. Setting INFO to |\nc | a nonzero value on the initial call is used |\nc | if you want to specify your own starting |\nc | vector (This vector must be placed in RESID.) | \nc | |\nc | The work array WORKL is used in SSAUPD as | \nc | workspace. Its dimension LWORKL is set as |\nc | illustrated below. |\nc %-----------------------------------------------------%\nc\n lworkl = ncv*(ncv+8)\n tol = zero \n info = 0\n ido = 0\nc\nc %---------------------------------------------------%\nc | Specification of Algorithm Mode: |\nc | |\nc | This program uses the exact shift strategy |\nc | (indicated by setting IPARAM(1) = 1.) |\nc | IPARAM(3) specifies the maximum number of Arnoldi |\nc | iterations allowed. Mode 1 of SSAUPD is used |\nc | (IPARAM(7) = 1). All these options can be changed |\nc | by the user. For details see the documentation in |\nc | SSAUPD. |\nc %---------------------------------------------------%\nc\n ishfts = 1\n maxitr = n\n mode1 = 1\nc\n iparam(1) = ishfts\nc \n iparam(3) = maxitr\nc \n iparam(7) = mode1\nc\nc %------------------------------------------------%\nc | M A I N L O O P (Reverse communication loop) |\nc %------------------------------------------------%\nc\n 10 continue\nc\nc %---------------------------------------------%\nc | Repeatedly call the routine SSAUPD and take | \nc | actions indicated by parameter IDO until |\nc | either convergence is indicated or maxitr |\nc | has been exceeded. |\nc %---------------------------------------------%\nc\n call ssaupd ( ido, bmat, n, which, nev, tol, resid, \n & ncv, v, ldv, iparam, ipntr, workd, workl,\n & lworkl, info )\nc\n if (ido .eq. -1 .or. ido .eq. 1) then\nc\nc %---------------------------------------%\nc | Perform matrix vector multiplications |\nc | w <--- A*x (av()) |\nc | y <--- A'*w (atv()) |\nc | The user should supply his/her own |\nc | matrix vector multiplication routines |\nc | here that takes workd(ipntr(1)) as |\nc | the input, and returns the result in |\nc | workd(ipntr(2)). |\nc %---------------------------------------%\nc\n call av (m, n, workd(ipntr(1)), ax) \n call atv (m, n, ax, workd(ipntr(2)))\nc\nc %-----------------------------------------%\nc | L O O P B A C K to call SSAUPD again. |\nc %-----------------------------------------%\nc\n go to 10\nc\n end if \nc\nc %----------------------------------------%\nc | Either we have convergence or there is |\nc | an error. |\nc %----------------------------------------%\nc\n if ( info .lt. 0 ) then\nc\nc %--------------------------%\nc | Error message. Check the |\nc | documentation in SSAUPD. |\nc %--------------------------%\nc\n print *, ' '\n print *, ' Error with _saupd, info = ', info\n print *, ' Check documentation in _saupd '\n print *, ' '\nc\n else \nc\nc %--------------------------------------------%\nc | No fatal errors occurred. |\nc | Post-Process using SSEUPD. |\nc | |\nc | Computed singular values may be extracted. | \nc | |\nc | Singular vectors may also be computed now |\nc | if desired. (indicated by rvec = .true.) | \nc | |\nc | The routine SSEUPD now called to do this |\nc | post processing | \nc %--------------------------------------------%\nc \n rvec = .true.\nc\n call sseupd ( rvec, 'All', select, s, v, ldv, sigma, \n & bmat, n, which, nev, tol, resid, ncv, v, ldv, \n & iparam, ipntr, workd, workl, lworkl, ierr )\nc\nc %-----------------------------------------------%\nc | Singular values are returned in the first |\nc | column of the two dimensional array S |\nc | and the corresponding right singular vectors | \nc | are returned in the first NEV columns of the |\nc | two dimensional array V as requested here. |\nc %-----------------------------------------------%\nc\n if ( ierr .ne. 0) then\nc\nc %------------------------------------%\nc | Error condition: |\nc | Check the documentation of SSEUPD. |\nc %------------------------------------%\nc\n print *, ' '\n print *, ' Error with _seupd, info = ', ierr\n print *, ' Check the documentation of _seupd. '\n print *, ' '\nc\n else\nc\n nconv = iparam(5)\n do 20 j=1, nconv\nc\n s(j,1) = sqrt(s(j,1))\nc\nc %-----------------------------%\nc | Compute the left singular |\nc | vectors from the formula |\nc | |\nc | u = Av/sigma |\nc | |\nc | u should have norm 1 so |\nc | divide by norm(Av) instead. |\nc %-----------------------------%\nc\n call av(m, n, v(1,j), ax)\n call scopy(m, ax, 1, u(1,j), 1)\n temp = one/snrm2(m, u(1,j), 1)\n call sscal(m, temp, u(1,j), 1)\nc\nc %---------------------------%\nc | |\nc | Compute the residual norm |\nc | |\nc | || A*v - sigma*u || |\nc | |\nc | for the NCONV accurately |\nc | computed singular values |\nc | and vectors. (iparam(5) |\nc | indicates how many are |\nc | accurate to the requested |\nc | tolerance). |\nc | Store the result in 2nd |\nc | column of array S. |\nc %---------------------------%\nc\n call saxpy(m, -s(j,1), u(1,j), 1, ax, 1)\n s(j,2) = snrm2(m, ax, 1)\nc\n 20 continue\nc\nc %-------------------------------%\nc | Display computed residuals |\nc %-------------------------------%\nc\n call smout(6, nconv, 2, s, maxncv, -6,\n & 'Singular values and direct residuals')\n end if\nc\nc %------------------------------------------%\nc | Print additional convergence information |\nc %------------------------------------------%\nc\n if ( info .eq. 1) then\n print *, ' '\n print *, ' Maximum number of iterations reached.'\n print *, ' '\n else if ( info .eq. 3) then\n print *, ' ' \n print *, ' No shifts could be applied during implicit',\n & ' Arnoldi update, try increasing NCV.'\n print *, ' '\n end if \nc\n print *, ' '\n print *, ' _SVD '\n print *, ' ==== '\n print *, ' '\n print *, ' Size of the matrix is ', n\n print *, ' The number of Ritz values requested is ', nev\n print *, ' The number of Arnoldi vectors generated',\n & ' (NCV) is ', ncv\n print *, ' What portion of the spectrum: ', which\n print *, ' The number of converged Ritz values is ', \n & nconv \n print *, ' The number of Implicit Arnoldi update',\n & ' iterations taken is ', iparam(3)\n print *, ' The number of OP*x is ', iparam(9)\n print *, ' The convergence criterion is ', tol\n print *, ' '\nc\n end if\nc\nc %-------------------------%\nc | Done with program ssvd. |\nc %-------------------------%\nc\n 9000 continue\nc\n end\nc \nc ------------------------------------------------------------------\nc matrix vector subroutines\nc\nc The matrix A is derived from the simplest finite difference \nc discretization of the integral operator \nc\nc f(s) = integral(K(s,t)x(t)dt).\nc \nc Thus, the matrix A is a discretization of the 2-dimensional kernel \nc K(s,t)dt, where\nc\nc K(s,t) = s(t-1) if 0 .le. s .le. t .le. 1,\nc t(s-1) if 0 .le. t .lt. s .le. 1.\nc\nc Thus A is an m by n matrix with entries\nc\nc A(i,j) = k*(si)*(tj - 1) if i .le. j,\nc k*(tj)*(si - 1) if i .gt. j\nc\nc where si = i/(m+1) and tj = j/(n+1) and k = 1/(n+1).\nc \nc-------------------------------------------------------------------\nc\n subroutine av (m, n, x, w)\nc\nc computes w <- A*x\nc\n integer m, n, i, j\n Real\n & x(n), w(m), one, zero, h, k, s, t\n parameter ( one = 1.0E+0, zero = 0.0E+0 ) \nc\n h = one / real(m+1)\n k = one / real(n+1)\n do 5 i = 1,m\n w(i) = zero\n 5 continue\n t = zero\nc \n do 30 j = 1,n\n t = t+k\n s = zero\n do 10 i = 1,j\n s = s+h\n w(i) = w(i) + k*s*(t-one)*x(j)\n 10 continue \n do 20 i = j+1,m\n s = s+h\n w(i) = w(i) + k*t*(s-one)*x(j) \n 20 continue\n 30 continue \nc\n return\n end\nc\nc-------------------------------------------------------------------\nc\n subroutine atv (m, n, w, y)\nc\nc computes y <- A'*w\nc\n integer m, n, i, j\n Real\n & w(m), y(n), one, zero, h, k, s, t\n parameter ( one = 1.0E+0, zero = 0.0E+0 )\nc\n h = one / real(m+1)\n k = one / real(n+1)\n do 5 i = 1,n\n y(i) = zero\n 5 continue\n t = zero\nc\n do 30 j = 1,n\n t = t+k\n s = zero\n do 10 i = 1,j\n s = s+h\n y(j) = y(j) + k*s*(t-one)*w(i)\n 10 continue\n do 20 i = j+1,m\n s = s+h\n y(j) = y(j) + k*t*(s-one)*w(i)\n 20 continue\n 30 continue\nc\n return\n end \nc\n\n\n", "meta": {"hexsha": "cf30f07d558540f752633bc9110e497090e66ba9", "size": 21820, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "roms_Sep2018/roms/Lib/ARPACK/EXAMPLES/SVD/ssvd.f", "max_stars_repo_name": "JamiePringle/ROMScode-PringleBBLpaper", "max_stars_repo_head_hexsha": "87166b65c0d926ea04e5f17ea96d16e694bac1ea", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 63, "max_stars_repo_stars_event_min_datetime": "2018-06-21T14:11:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T11:24:36.000Z", "max_issues_repo_path": "roms_Sep2018/roms/Lib/ARPACK/EXAMPLES/SVD/ssvd.f", "max_issues_repo_name": "JamiePringle/ROMScode-PringleBBLpaper", "max_issues_repo_head_hexsha": "87166b65c0d926ea04e5f17ea96d16e694bac1ea", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 105, "max_issues_repo_issues_event_min_datetime": "2019-07-08T19:27:23.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-22T02:12:16.000Z", "max_forks_repo_path": "roms_Sep2018/roms/Lib/ARPACK/EXAMPLES/SVD/ssvd.f", "max_forks_repo_name": "JamiePringle/ROMScode-PringleBBLpaper", "max_forks_repo_head_hexsha": "87166b65c0d926ea04e5f17ea96d16e694bac1ea", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2018-08-23T15:59:44.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-20T06:47:22.000Z", "avg_line_length": 36.6722689076, "max_line_length": 73, "alphanum_fraction": 0.3994500458, "num_tokens": 5394, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.89181104831338, "lm_q2_score": 0.7341195327172402, "lm_q1q2_score": 0.6546959100598906}} {"text": "*DECK DCHFIE\n DOUBLE PRECISION FUNCTION DCHFIE (X1, X2, F1, F2, D1, D2, A, B)\nC***BEGIN PROLOGUE DCHFIE\nC***SUBSIDIARY\nC***PURPOSE Evaluates integral of a single cubic for DPCHIA\nC***LIBRARY SLATEC (PCHIP)\nC***TYPE DOUBLE PRECISION (CHFIE-S, DCHFIE-D)\nC***AUTHOR Fritsch, F. N., (LLNL)\nC***DESCRIPTION\nC\nC DCHFIE: Cubic Hermite Function Integral Evaluator.\nC\nC Called by DPCHIA to evaluate the integral of a single cubic (in\nC Hermite form) over an arbitrary interval (A,B).\nC\nC ----------------------------------------------------------------------\nC\nC Calling sequence:\nC\nC DOUBLE PRECISION X1, X2, F1, F2, D1, D2, A, B\nC DOUBLE PRECISION VALUE, DCHFIE\nC\nC VALUE = DCHFIE (X1, X2, F1, F2, D1, D2, A, B)\nC\nC Parameters:\nC\nC VALUE -- (output) value of the requested integral.\nC\nC X1,X2 -- (input) endpoints if interval of definition of cubic.\nC\nC F1,F2 -- (input) function values at the ends of the interval.\nC\nC D1,D2 -- (input) derivative values at the ends of the interval.\nC\nC A,B -- (input) endpoints of interval of integration.\nC\nC***SEE ALSO DPCHIA\nC***ROUTINES CALLED (NONE)\nC***REVISION HISTORY (YYMMDD)\nC 820730 DATE WRITTEN\nC 820805 Converted to SLATEC library version.\nC 870707 Corrected subroutine name from DCHIV to DCHFIV.\nC 870813 Minor cosmetic changes.\nC 890411 1. Added SAVE statements (Vers. 3.2).\nC 2. Added SIX to DOUBLE PRECISION declaration.\nC 890411 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\nC 900328 Added TYPE section. (WRB)\nC 910408 Updated AUTHOR section in prologue. (WRB)\nC 930503 Corrected to set VALUE=0 when IERR.ne.0. (FNF)\nC 930504 Eliminated IERR and changed name DCHFIV to DCHFIE. (FNF)\nC***END PROLOGUE DCHFIE\nC\nC Programming notes:\nC 1. There is no error return from this routine because zero is\nC indeed the mathematically correct answer when X1.EQ.X2 .\nC**End\nC\nC DECLARE ARGUMENTS.\nC\n DOUBLE PRECISION X1, X2, F1, F2, D1, D2, A, B\nC\nC DECLARE LOCAL VARIABLES.\nC\n DOUBLE PRECISION DTERM, FOUR, FTERM, H, HALF, PHIA1, PHIA2,\n * PHIB1, PHIB2, PSIA1, PSIA2, PSIB1, PSIB2, SIX, TA1, TA2,\n * TB1, TB2, THREE, TWO, UA1, UA2, UB1, UB2\n SAVE HALF, TWO, THREE, FOUR, SIX\nC\nC INITIALIZE.\nC\n DATA HALF/.5D0/, TWO/2.D0/, THREE/3.D0/, FOUR/4.D0/, SIX/6.D0/\nC\nC VALIDITY CHECK INPUT.\nC\nC***FIRST EXECUTABLE STATEMENT DCHFIE\n IF (X1 .EQ. X2) THEN\n DCHFIE = 0\n ELSE\n H = X2 - X1\n TA1 = (A - X1) / H\n TA2 = (X2 - A) / H\n TB1 = (B - X1) / H\n TB2 = (X2 - B) / H\nC\n UA1 = TA1**3\n PHIA1 = UA1 * (TWO - TA1)\n PSIA1 = UA1 * (THREE*TA1 - FOUR)\n UA2 = TA2**3\n PHIA2 = UA2 * (TWO - TA2)\n PSIA2 = -UA2 * (THREE*TA2 - FOUR)\nC\n UB1 = TB1**3\n PHIB1 = UB1 * (TWO - TB1)\n PSIB1 = UB1 * (THREE*TB1 - FOUR)\n UB2 = TB2**3\n PHIB2 = UB2 * (TWO - TB2)\n PSIB2 = -UB2 * (THREE*TB2 - FOUR)\nC\n FTERM = F1*(PHIA2 - PHIB2) + F2*(PHIB1 - PHIA1)\n DTERM = ( D1*(PSIA2 - PSIB2) + D2*(PSIB1 - PSIA1) )*(H/SIX)\nC\n DCHFIE = (HALF*H) * (FTERM + DTERM)\n ENDIF\nC\n RETURN\nC------------- LAST LINE OF DCHFIE FOLLOWS -----------------------------\n END\n", "meta": {"hexsha": "8d141b4cfa753e07cfe05341fea7fd03c3845c26", "size": 3429, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/dchfie.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/dchfie.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/dchfie.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.1727272727, "max_line_length": 72, "alphanum_fraction": 0.58909303, "num_tokens": 1278, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110540642805, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.6546959090940232}} {"text": "c\nc\nc ###################################################\nc ## COPYRIGHT (C) 1991 by Jay William Ponder ##\nc ## All Rights Reserved ##\nc ###################################################\nc\nc #############################################################\nc ## ##\nc ## subroutine orthog -- Gram-Schmidt orthogonalization ##\nc ## ##\nc #############################################################\nc\nc\nc \"orthog\" performs an orthogonalization of an input matrix\nc via the modified Gram-Schmidt algorithm\nc\nc variables and parameters:\nc\nc m first dimension of the matrix to orthogonalize\nc n second dimension of the matrix to orthogonalize\nc a matrix to orthogonalize; contains result on exit\nc\nc\n subroutine orthog (m,n,a)\n implicit none\n integer i,j,k\n integer m,n\n real*8 rkk,rkj\n real*8 a(m,*)\nc\nc\nc compute the modified Gram-Schmidt orthogonalization\nc\n do k = 1, n\n rkk = 0.0d0\n do i = 1, m\n rkk = rkk + a(i,k)**2\n end do\n rkk = sqrt(rkk)\n do i = 1, m\n a(i,k) = a(i,k) / rkk\n end do\n do j = k+1, n\n rkj = 0.0d0\n do i = 1, m\n rkj = rkj + a(i,k)*a(i,j)\n end do\n do i = 1, m\n a(i,j) = a(i,j) - a(i,k)*rkj\n end do\n end do\n end do\n return\n end\n", "meta": {"hexsha": "f4a77bda16e864fb0e3d4297fe4728f875f82023", "size": 1583, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "HCsbLib/HCsbLib/HTLib2.Bioinfo/External.Tinker/src/tinker-6.2.06/orthog.f", "max_stars_repo_name": "htna/HCsbLib", "max_stars_repo_head_hexsha": "dae7f4e3e5e2fbc3b6e619f2ea037f661a8ae097", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-01-21T23:45:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-03T16:34:24.000Z", "max_issues_repo_path": "HCsbLib/HCsbLib/HTLib2.Bioinfo/External.Tinker/src/tinker-6.2.06/orthog.f", "max_issues_repo_name": "htna/HCsbLib", "max_issues_repo_head_hexsha": "dae7f4e3e5e2fbc3b6e619f2ea037f661a8ae097", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HCsbLib/HCsbLib/HTLib2.Bioinfo/External.Tinker/src/tinker-6.2.06/orthog.f", "max_forks_repo_name": "htna/HCsbLib", "max_forks_repo_head_hexsha": "dae7f4e3e5e2fbc3b6e619f2ea037f661a8ae097", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-03-05T00:26:38.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-08T23:25:29.000Z", "avg_line_length": 28.2678571429, "max_line_length": 67, "alphanum_fraction": 0.3796588756, "num_tokens": 400, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110569397306, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6546959060172314}} {"text": "MODULE numerical_utilities\nuse num_types\nimplicit none\nprivate\npublic equal\n! Overloaded procedure for comparing real types\n INTERFACE equal\n MODULE PROCEDURE equal_scalar , &\n equal_rank1, &\n equal_rank2, &\n equal_rank3, &\n equal_rank1_rank0, &\n equal_rank2_rank0, &\n equal_rank2_real_int, &\n equal_rank1_real_int, &\n equal_scalar_real_int, &\n equal_scalar_int_int\n\n END INTERFACE\n\nCONTAINS\n !!This function takes two real entities and compares them\n !! to see if they are equal within some tolerance. This prevents\n !! failed comparisons due to numbers that are \"equal\" but differ due\n !! to small differences arising from finite precision.\n !!The first array to be\n !!compared.\n !!The second array to be\n !!compared.\n !!The relative tolerance for their comparison\n !! which is multiplied to the larger of a and b.\n !!The optional absolute\n !!tolerance for their comparison. Is added to the relative tolerance.\n !!Default value is 5E-4\n function equal_rank1(a, b, rtolerance, atolerance_)\n logical :: equal_rank1\n real(dp) :: a(:), b(:), rtolerance\n real(dp) :: atolerance\n real(dp), OPTIONAL :: atolerance_\n if(present(atolerance_)) then; atolerance = atolerance_; else; atolerance = 5E-4_dp; endif\n\n equal_rank1 = .false.\n if(all(abs(a-b) == 0.0)) then\n equal_rank1 = .true. !This line was added so that if a user did\n !request a comparison with a tolerance of zero it would return the\n !correct result, or if the values are actually zero. We added this\n !line instead of making the following one <= so that the codes\n !original functionality would be unaltered.\n else if(all(abs(a - b) < atolerance + rtolerance * max(maxval(abs(a)),maxval(abs(b))))) then\n equal_rank1 = .true.\n end if\n end function equal_rank1\n\n !!This function takes two real entities and compares them\n !! to see if they are equal within some tolerance. This prevents\n !! failed comparisons due to numbers that are \"equal\" but differ due\n !! to small differences arising from finite precision.\n !!The first array to be\n !!compared.\n !!The second array to be\n !!compared.\n !!The relative tolerance for their comparison\n !! which is multiplied to the larger of a and b.\n !!The optional absolute\n !!tolerance for their comparison. Is added to the relative tolerance.\n !!Default value is 5E-4\n function equal_rank2(a, b, rtolerance, atolerance_)\n logical :: equal_rank2\n real(dp) :: a(:,:), b(:,:), rtolerance\n real(dp) :: atolerance\n real(dp), OPTIONAL :: atolerance_\n if(present(atolerance_)) then; atolerance = atolerance_; else; atolerance = 5E-4_dp; endif\n\n equal_rank2 = .false.\n if(all(abs(a-b) == 0.0)) then\n equal_rank2 = .true. !This line was added so that if a user did\n !request a comparison with a tolerance of zero it would return the\n !correct result, or if the values are actually zero. We added this\n !line instead of making the following one <= so that the codes\n !original functionallity would be unaltered.\n else if(all(abs(a - b) < atolerance + rtolerance * max(maxval(abs(a)),maxval(abs(b))))) then\n equal_rank2 = .true.\n end if\n end function equal_rank2\n\n !!This function takes two real entities and compares them\n !! to see if they are equal within some tolerance. This prevents\n !! failed comparisons due to numbers that are \"equal\" but differ due\n !! to small differences arising from finite precision.\n !!The first array to be\n !!compared.\n !!The second array to be\n !!compared.\n !!The relative tolerance for their comparison\n !! which is multiplied to the larger of a and b.\n !!The optional absolute\n !!tolerance for their comparison. Is added to the relative tolerance.\n !!Default value is 5E-4\n function equal_rank3(a, b, rtolerance, atolerance_)\n logical :: equal_rank3\n real(dp) :: a(:,:,:), b(:,:,:), rtolerance\n real(dp) :: atolerance\n real(dp), OPTIONAL :: atolerance_\n if(present(atolerance_)) then; atolerance = atolerance_; else; atolerance = 5E-4_dp; endif\n\n equal_rank3 = .false.\n if(all(abs(a-b) == 0.0)) then\n equal_rank3 = .true. !This line was added so that if a user did\n !request a comparison with a tolerance of zero it would return the\n !correct result, or if the values are actually zero. We added this\n !line instead of making the following one <= so that the codes\n !original functionallity would be unaltered.\n else if(all(abs(a - b) < atolerance + rtolerance * max(maxval(abs(a)),maxval(abs(b))))) then\n equal_rank3 = .true.\n end if\n end function equal_rank3\n\n !!This function takes two real entities and compares them\n !! to see if they are equal within some tolerance. This prevents\n !! failed comparisons due to numbers that are \"equal\" but differ due\n !! to small differences arising from finite precision.\n !!The first real scalar to be\n !!compared.\n !!The second real scalar to be\n !!compared.\n !!The relative tolerance for their comparison\n !! which is multiplied to the larger of a and b.\n !!The optional absolute\n !!tolerance for their comparison. Is added to the relative tolerance.\n !!Default value is 5E-4\n function equal_scalar(a, b, rtolerance, atolerance_)\n logical :: equal_scalar\n real(dp) :: a, b, rtolerance\n real(dp) :: atolerance\n real(dp), OPTIONAL :: atolerance_\n if(present(atolerance_)) then; atolerance = atolerance_; else; atolerance = 5E-4_dp; endif\n\n equal_scalar = .false.\n if(abs(a-b) == 0.0) then\n equal_scalar = .true. !This line was added so that if a user did\n !request a comparison with a tolerance of zero it would return the\n !correct result, or if the values are actually zero. We added this\n !line instead of making the following one <= so that the codes\n !original functionallity would be unaltered.\n else if(abs(a - b) < atolerance + rtolerance * max(abs(a),abs(b))) then\n equal_scalar = .true.\n end if\n end function equal_scalar\n\n !!This function takes two real entities and compares them\n !! to see if they are equal within some tolerance. This prevents\n !! failed comparisons due to numbers that are \"equal\" but differ due\n !! to small differences arising from finite precision.\n !!The first integer to be\n !!compared.\n !!The second real to be\n !!compared.\n !!The relative tolerance for their comparison\n !! which is multiplied to the larger of a and b.\n !!The optional absolute\n !!tolerance for their comparison. Is added to the relative tolerance.\n !!Default value is 5E-4\n function equal_scalar_real_int(a, b, rtolerance, atolerance_)\n logical :: equal_scalar_real_int\n integer :: b\n real(dp) :: a, rtolerance\n real(dp) :: atolerance\n real(dp), OPTIONAL :: atolerance_\n if(present(atolerance_)) then; atolerance = atolerance_; else; atolerance = 5E-4_dp; endif\n\n equal_scalar_real_int = .false.\n if(abs(a-b) == 0.0) then\n equal_scalar_real_int = .true. !This line was added so that if a user did\n !request a comparison with a tolerance of zero it would return the\n !correct result, or if the values are actually zero. We added this\n !line instead of making the following one <= so that the codes\n !original functionallity would be unaltered.\n else if(abs(a - b) < atolerance + rtolerance * max(abs(a),abs(real(b,dp)))) then\n equal_scalar_real_int = .true.\n end if\n end function equal_scalar_real_int\n\n !!This function takes two real entities and compares them\n !! to see if they are equal within some tolerance. This prevents\n !! failed comparisons due to numbers that are \"equal\" but differ due\n !! to small differences arising from finite precision.\n !!The first integer to be\n !!compared.\n !!The second integer to be\n !!compared.\n !!The relative tolerance for their comparison\n !! which is multiplied to the larger of a and b.\n !!The optional absolute\n !!tolerance for their comparison. Is added to the relative tolerance.\n !!Default value is 5E-4\n function equal_scalar_int_int(a, b, rtolerance, atolerance_)\n logical :: equal_scalar_int_int\n real(dp) :: rtolerance, atolerance\n real(dp), OPTIONAL :: atolerance_\n integer :: a, b\n if(present(atolerance_)) then; atolerance = atolerance_; else; atolerance = 5E-4_dp; endif\n\n equal_scalar_int_int = .false.\n if(abs(a-b) == 0) then\n equal_scalar_int_int = .true. !This line was added so that if a user did\n !request a comparison with a tolerance of zero it would return the\n !correct result, or if the values are actually zero. We added this\n !line instead of making the following one <= so that the codes\n !original functionallity would be unaltered.\n else if(abs(a - b) < atolerance + rtolerance * max(abs(real(a,dp)),abs(real(b,dp)))) then\n equal_scalar_int_int = .true.\n end if\n end function equal_scalar_int_int\n\n !!This function takes two real entities and compares them\n !! to see if they are equal within some tolerance. This prevents\n !! failed comparisons due to numbers that are \"equal\" but differ due\n !! to small differences arising from finite precision.\n !!The first 1D array to be\n !!compared.\n !!The second real scalar to be\n !!compared.\n !!The relative tolerance for their comparison\n !! which is multiplied to the larger of a and b.\n !!The optional absolute\n !!tolerance for their comparison. Is added to the relative tolerance.\n !!Default value is 5E-4\n function equal_rank1_rank0(a, b, rtolerance, atolerance_)\n logical :: equal_rank1_rank0\n real(dp) :: a(:), b, rtolerance, atolerance\n real(dp), OPTIONAL :: atolerance_\n if(present(atolerance_)) then; atolerance = atolerance_; else; atolerance = 5E-4_dp; endif\n\n equal_rank1_rank0 = .false.\n if(all(abs(a-b) == 0.0)) then\n equal_rank1_rank0 = .true. !This line was added so that if a user did\n !request a comparison with a tolerance of zero it would return the\n !correct result, or if the values are actually zero. We added this\n !line instead of making the following one <= so that the codes\n !original functionallity would be unaltered.\n else if(all(abs(a - b) < atolerance + rtolerance * max(maxval(abs(a)),abs(b)))) then\n equal_rank1_rank0 = .true.\n end if\n end function equal_rank1_rank0\n\n !!This function takes two real entities and compares them\n !! to see if they are equal within some tolerance. This prevents\n !! failed comparisons due to numbers that are \"equal\" but differ due\n !! to small differences arising from finite precision.\n !!The first 2D array to be\n !!compared.\n !!The second real scalar to be\n !!compared.\n !!The relative tolerance for their comparison\n !! which is multiplied to the larger of a and b.\n !!The optional absolute\n !!tolerance for their comparison. Is added to the relative tolerance.\n !!Default value is 5E-4\n function equal_rank2_rank0(a, b, rtolerance, atolerance_)\n logical :: equal_rank2_rank0\n real(dp) :: a(:,:), b, rtolerance, atolerance\n real(dp), OPTIONAL :: atolerance_\n if(present(atolerance_)) then; atolerance = atolerance_; else; atolerance = 5E-4_dp; endif\n\n equal_rank2_rank0 = .false.\n if(all(abs(a-b) == 0.0)) then\n equal_rank2_rank0 = .true. !This line was added so that if a user did\n !request a comparison with a tolerance of zero it would return the\n !correct result, or if the values are actually zero. We added this\n !line instead of making the following one <= so that the codes\n !original functionallity would be unaltered.\n else if(all(abs(a - b) < atolerance + rtolerance * max(maxval(abs(a)),abs(b)))) then\n equal_rank2_rank0 = .true.\n end if\n end function equal_rank2_rank0\n\n !!This function takes two real entities and compares them\n !! to see if they are equal within some tolerance. This prevents\n !! failed comparisons due to numbers that are \"equal\" but differ due\n !! to small differences arising from finite precision.\n !!The first real 2D array to be\n !!compared.\n !!The second integer 2D array to be\n !!compared.\n !!The relative tolerance for their comparison\n !! which is multiplied to the larger of a and b.\n !!The optional absolute\n !!tolerance for their comparison. Is added to the relative tolerance.\n !!Default value is 5E-4\n function equal_rank2_real_int(a, b, rtolerance, atolerance_)\n logical :: equal_rank2_real_int\n real(dp) :: a(:,:), rtolerance, atolerance\n real(dp), OPTIONAL :: atolerance_\n integer :: b(:,:)\n if(present(atolerance_)) then; atolerance = atolerance_; else; atolerance = 5E-4_dp; endif\n\n\n equal_rank2_real_int = .false.\n if(all(abs(a-b) == 0.0)) then\n equal_rank2_real_int = .true. !This line was added so that if a user did\n !request a comparison with a tolerance of zero it would return the\n !correct result, or if the values are actually zero. We added this\n !line instead of making the following one <= so that the codes\n !original functionallity would be unaltered.\n else if(all(abs(a - b) < atolerance + rtolerance * max(maxval(abs(a)),maxval(abs(real(b,dp)))))) then\n equal_rank2_real_int = .true.\n end if\n end function equal_rank2_real_int\n\n !!This function takes two real entities and compares them\n !! to see if they are equal within some tolerance. This prevents\n !! failed comparisons due to numbers that are \"equal\" but differ due\n !! to small differences arising from finite precision.\n !!The first 1D real array to be\n !!compared.\n !!The second 1D integer array to be\n !!compared.\n !!The relative tolerance for their comparison\n !! which is multiplied to the larger of a and b.\n !!The optional absolute\n !!tolerance for their comparison. Is added to the relative tolerance.\n !!Default value is 5E-4\n function equal_rank1_real_int(a, b, rtolerance, atolerance_)\n logical :: equal_rank1_real_int\n real(dp) :: a(:), rtolerance, atolerance\n real(dp), OPTIONAL :: atolerance_\n integer :: b(:)\n if(present(atolerance_)) then; atolerance = atolerance_; else; atolerance = 5E-4_dp; endif\n\n equal_rank1_real_int = .false.\n if(all(abs(a-b) == 0.0)) then\n equal_rank1_real_int = .true. !This line was added so that if a user did\n !request a comparison with a tolerance of zero it would return the\n !correct result, or if the values are actually zero. We added this\n !line instead of making the following one <= so that the codes\n !original functionallity would be unaltered.\n else if(all(abs(a - b) < atolerance + rtolerance * max(maxval(abs(a)),maxval(abs(real(b,dp)))))) then\n equal_rank1_real_int = .true.\n end if\n end function equal_rank1_real_int\n\n\nEND MODULE numerical_utilities\n", "meta": {"hexsha": "da0bdfb60650c7d93a9157a3c876d4acbe00472f", "size": 17122, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/numerical_utilities.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/numerical_utilities.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/numerical_utilities.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": 49.773255814, "max_line_length": 105, "alphanum_fraction": 0.7057002687, "num_tokens": 4382, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744939732856, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.6546253584420568}} {"text": "PROGRAM F004\n\n ! Copyright 2021 Melwyn Francis Carlo\n\n IMPLICIT NONE\n\n INTEGER :: I, J, N\n LOGICAL :: IS_PALINDROME\n\n DO I = 999, 900, -1\n DO J = 999, 900, -1\n N = I * J\n IF (IS_PALINDROME(N)) THEN\n GOTO 10\n END IF\n END DO\n END DO\n\n 10 CONTINUE\n\n PRINT ('(I0)'), N\n\nEND PROGRAM F004\n\n\nLOGICAL FUNCTION IS_PALINDROME (N_VAL)\n\n IMPLICIT NONE\n\n INTEGER, INTENT(IN) :: N_VAL\n INTEGER :: I, N_LEN_BY_2\n CHARACTER (LEN=10) :: N_STR\n CHARACTER (LEN=5) :: N_STR_SPLIT_1, N_STR_SPLIT_2\n\n WRITE (N_STR, '(I0)') N_VAL\n N_LEN_BY_2 = INT(CEILING(LEN_TRIM(N_STR) / 2.0))\n N_STR_SPLIT_1 = N_STR(1:3)\n N_STR_SPLIT_2 = N_STR(N_LEN_BY_2+1:)\n FORALL (I=1:N_LEN_BY_2) N_STR_SPLIT_2(I:I) &\n = N_STR_SPLIT_2(N_LEN_BY_2-I+1:N_LEN_BY_2-I+1)\n IF (N_STR_SPLIT_1 == N_STR_SPLIT_2) THEN\n IS_PALINDROME = .TRUE.\n ELSE\n IS_PALINDROME = .FALSE.\n END IF\n\nEND FUNCTION IS_PALINDROME\n", "meta": {"hexsha": "9c49111d341a89f83384f48aeb33053615ee602d", "size": 1000, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "problems/004/004.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/004/004.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/004/004.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.8333333333, "max_line_length": 55, "alphanum_fraction": 0.592, "num_tokens": 361, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006919925839875, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.6546253346497962}} {"text": "\nprogram main\n\n implicit none\n\n integer :: i\n\n i = 1\n\n do\n if(evenly_divis(i)) then\n exit\n end if\n\n i = i + 1\n end do\n\n print *, i\n\n\ncontains\n\n function evenly_divis (a)\n integer :: a, i\n logical :: evenly_divis\n\n evenly_divis = .true.\n\n do i = 1, 20, 1\n\n if(mod(a, i) /= 0) then\n evenly_divis = .false.\n exit\n end if\n\n end do\n\n return\n\n end function evenly_divis\n\n\nend program main\n", "meta": {"hexsha": "4edc08148aa091ec6516190787d4e02026da62d6", "size": 705, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "fortran/small_mult.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/small_mult.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/small_mult.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": 16.0227272727, "max_line_length": 54, "alphanum_fraction": 0.3446808511, "num_tokens": 148, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8175744673038222, "lm_q2_score": 0.8006919949619793, "lm_q1q2_score": 0.654625331255475}} {"text": "program descriptive_statistics\n use, intrinsic :: iso_fortran_env, only : error_unit, input_unit, output_unit\n use :: stats_mod\n implicit none\n type(descriptive_stats_t) :: stats\n real, dimension(3) :: data_values = [ 3.5, 5.7, 7.3 ]\n integer :: i\n\n do i = 1, size(data_values)\n call stats%add_data(data_values(i))\n end do\n print '(A, I0)', 'n = ', stats%get_nr_values()\n print '(A, F10.3)', 'mean = ', stats%get_mean()\n print '(A, F10.3)', 'stddev = ', stats%get_stddev()\n\n call stats%add_data(data_values)\n print '(A, I0)', 'n = ', stats%get_nr_values()\n print '(A, F10.3)', 'mean = ', stats%get_mean()\n print '(A, F10.3)', 'stddev = ', stats%get_stddev()\n\nend program descriptive_statistics\n", "meta": {"hexsha": "54473031aa3a33d0cd9db236f9d36beb236b6465", "size": 760, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source_code/statistics_oo/overloading/descriptive_statistics.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/statistics_oo/overloading/descriptive_statistics.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/statistics_oo/overloading/descriptive_statistics.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": 34.5454545455, "max_line_length": 81, "alphanum_fraction": 0.6118421053, "num_tokens": 237, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6545802200936199}} {"text": " SUBROUTINE terint(ng,xg,yg, n,x,y, c1,c2)\n IMPLICIT NONE\n\n* SUBROUTINE to TERminate and INTerpolate a 1D input data array.\n* INPUTS:\n* working grid:\n\n INTEGER ng, ig\n REAL xg(ng)\n\n* data array to be gridded:\n\n INTEGER n, i\n REAL x(n), y(n)\n\n* multipliers for 4 y-values to be added:\n\n INTEGER c1, c2\n\n* OUTPUT:\n* gridded y-values, with proper termination at both ends\n\n REAL yg(ng)\n\n* INTERNAL:\n* input terminator points to be added:\n\n REAL xt1, yt1\n REAL xt2, yt2\n REAL xt3, yt3\n REAL xt4, yt4\n\n* delta for adding points at beginning or end of data grids\n\n REAL deltax\n PARAMETER (deltax = 1.E-5)\n\n* error flag:\n\n INTEGER ierr\n\n* extended array:\n\n INTEGER n1, k1\n REAL x1(n+4), y1(n+4)\n\n* check for valid input values of c1, c2:\n\n ierr = 0\n if(c1 .ne. 0 .and. c1 .ne. 1) ierr = 1\n if(c2 .ne. 0 .and. c2 .ne. 1) ierr = 1\n IF (ierr .NE. 0) THEN\n WRITE(*,*) ierr, 'entering terint.f'\n STOP\n ENDIF\n\n* assign x-coordinate to 4 new points\n\n xt1 = -1.e36\n xt2 = x(1)*(1.-deltax)\n xt3 = x(n)*(1.+deltax)\n xt4 = 1.e36\n\n* terminator multipliers c1,c2 = e.g., = 1.,0.\n* there are really only two practical options: constant or zero\n\n yt1 = float(c1) * y(1)\n yt2 = float(c1) * y(1)\n\n yt3 = float(c2) * y(n)\n yt4 = float(c2) * y(n)\n\n* transcribe input x,y array to avoid modifying it\n\n n1 = n\n do i = 1, n\n x1(i) = x(i)\n y1(i) = y(i)\n enddo\n\n* extended data array, with up to 4 terminator points:\n* note that n1 gets incremented by 1 for each call to ADDPNT \n\n k1 = n1 + 4\n call addpnt(x1,y1,k1,n1, xt1,yt1)\n call addpnt(x1,y1,k1,n1, xt2,yt2)\n call addpnt(x1,y1,k1,n1, xt3,yt3)\n call addpnt(x1,y1,k1,n1, xt4,yt4)\n\n* point to grid interpolation:\n\n CALL inter2(ng,xg,yg, n1,x1,y1,ierr)\n IF (ierr .NE. 0) THEN\n WRITE(*,*) ierr, 'exiting terint.f'\n STOP\n ENDIF\n\n RETURN\n END\n", "meta": {"hexsha": "422366509de053fb820a5b53f495e0fcc247082d", "size": 2031, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "V5.4/terint.f", "max_stars_repo_name": "SeregaOsipov/TUV", "max_stars_repo_head_hexsha": "fdf9945d6a1e38805c7e687fc55b6888bf426b2e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-02-27T11:21:59.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-26T10:04:41.000Z", "max_issues_repo_path": "V5.4/terint.f", "max_issues_repo_name": "SeregaOsipov/TUV", "max_issues_repo_head_hexsha": "fdf9945d6a1e38805c7e687fc55b6888bf426b2e", "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": "V5.4/terint.f", "max_forks_repo_name": "SeregaOsipov/TUV", "max_forks_repo_head_hexsha": "fdf9945d6a1e38805c7e687fc55b6888bf426b2e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-02-27T11:51:33.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-27T11:51:33.000Z", "avg_line_length": 20.31, "max_line_length": 66, "alphanum_fraction": 0.5657311669, "num_tokens": 720, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359876, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6545802200936199}} {"text": "*DECK ZAIRY\n SUBROUTINE ZAIRY (ZR, ZI, ID, KODE, AIR, AII, NZ, IERR)\nC***BEGIN PROLOGUE ZAIRY\nC***PURPOSE Compute the Airy function Ai(z) or its derivative dAi/dz\nC for complex argument z. A scaling option is available\nC to help avoid underflow and overflow.\nC***LIBRARY SLATEC\nC***CATEGORY C10D\nC***TYPE COMPLEX (CAIRY-C, ZAIRY-C)\nC***KEYWORDS AIRY FUNCTION, BESSEL FUNCTION OF ORDER ONE THIRD,\nC BESSEL FUNCTION OF ORDER TWO THIRDS\nC***AUTHOR Amos, D. E., (SNL)\nC***DESCRIPTION\nC\nC ***A DOUBLE PRECISION ROUTINE***\nC On KODE=1, ZAIRY computes the complex Airy function Ai(z)\nC or its derivative dAi/dz on ID=0 or ID=1 respectively. On\nC KODE=2, a scaling option exp(zeta)*Ai(z) or exp(zeta)*dAi/dz\nC is provided to remove the exponential decay in -pi/31 and from power series when abs(z)<=1.\nC\nC In most complex variable computation, one must evaluate ele-\nC mentary functions. When the magnitude of Z is large, losses\nC of significance by argument reduction occur. Consequently, if\nC the magnitude of ZETA=(2/3)*Z**(3/2) exceeds U1=SQRT(0.5/UR),\nC then losses exceeding half precision are likely and an error\nC flag IERR=3 is triggered where UR=MAX(D1MACH(4),1.0D-18) is\nC double precision unit roundoff limited to 18 digits precision.\nC Also, if the magnitude of ZETA is larger than U2=0.5/UR, then\nC all significance is lost and IERR=4. In order to use the INT\nC function, ZETA must be further restricted not to exceed\nC U3=I1MACH(9)=LARGEST INTEGER. Thus, the magnitude of ZETA\nC must be restricted by MIN(U2,U3). In IEEE arithmetic, U1,U2,\nC and U3 are approximately 2.0E+3, 4.2E+6, 2.1E+9 in single\nC precision and 4.7E+7, 2.3E+15, 2.1E+9 in double precision.\nC This makes U2 limiting is single precision and U3 limiting\nC in double precision. This means that the magnitude of Z\nC cannot exceed approximately 3.4E+4 in single precision and\nC 2.1E+6 in double precision. This also means that one can\nC expect to retain, in the worst cases on 32-bit machines,\nC no digits in single precision and only 6 digits in double\nC precision.\nC\nC The approximate relative error in the magnitude of a complex\nC Bessel function can be expressed as P*10**S where P=MAX(UNIT\nC ROUNDOFF,1.0E-18) is the nominal precision and 10**S repre-\nC sents the increase in error due to argument reduction in the\nC elementary functions. Here, S=MAX(1,ABS(LOG10(ABS(Z))),\nC ABS(LOG10(FNU))) approximately (i.e., S=MAX(1,ABS(EXPONENT OF\nC ABS(Z),ABS(EXPONENT OF FNU)) ). However, the phase angle may\nC have only absolute accuracy. This is most likely to occur\nC when one component (in magnitude) is larger than the other by\nC several orders of magnitude. If one component is 10**K larger\nC than the other, then one can expect only MAX(ABS(LOG10(P))-K,\nC 0) significant digits; or, stated another way, when K exceeds\nC the exponent of P, no significant digits remain in the smaller\nC component. However, the phase angle retains absolute accuracy\nC because, in complex arithmetic with precision P, the smaller\nC component will not (as a rule) decrease below P times the\nC magnitude of the larger component. In these extreme cases,\nC the principal phase angle is on the order of +P, -P, PI/2-P,\nC or -PI/2+P.\nC\nC***REFERENCES 1. M. Abramowitz and I. A. Stegun, Handbook of Mathe-\nC matical Functions, National Bureau of Standards\nC Applied Mathematics Series 55, U. S. Department\nC of Commerce, Tenth Printing (1972) or later.\nC 2. D. E. Amos, Computation of Bessel Functions of\nC Complex Argument and Large Order, Report SAND83-0643,\nC Sandia National Laboratories, Albuquerque, NM, May\nC 1983.\nC 3. D. E. Amos, A Subroutine Package for Bessel Functions\nC of a Complex Argument and Nonnegative Order, Report\nC SAND85-1018, Sandia National Laboratory, Albuquerque,\nC NM, May 1985.\nC 4. D. E. Amos, A portable package for Bessel functions\nC of a complex argument and nonnegative order, ACM\nC Transactions on Mathematical Software, 12 (September\nC 1986), pp. 265-273.\nC\nC***ROUTINES CALLED D1MACH, I1MACH, ZABS, ZACAI, ZBKNU, ZEXP, ZSQRT\nC***REVISION HISTORY (YYMMDD)\nC 830501 DATE WRITTEN\nC 890801 REVISION DATE from Version 3.2\nC 910415 Prologue converted to Version 4.0 format. (BAB)\nC 920128 Category corrected. (WRB)\nC 920811 Prologue revised. (DWL)\nC 930122 Added ZEXP and ZSQRT to EXTERNAL statement. (RWC)\nC***END PROLOGUE ZAIRY\nC COMPLEX AI,CONE,CSQ,CY,S1,S2,TRM1,TRM2,Z,ZTA,Z3\n DOUBLE PRECISION AA, AD, AII, AIR, AK, ALIM, ATRM, AZ, AZ3, BK,\n * CC, CK, COEF, CONEI, CONER, CSQI, CSQR, CYI, CYR, C1, C2, DIG,\n * DK, D1, D2, ELIM, FID, FNU, PTR, RL, R1M5, SFAC, STI, STR,\n * S1I, S1R, S2I, S2R, TOL, TRM1I, TRM1R, TRM2I, TRM2R, TTH, ZEROI,\n * ZEROR, ZI, ZR, ZTAI, ZTAR, Z3I, Z3R, D1MACH, ZABS, ALAZ, BB\n INTEGER ID, IERR, IFLAG, K, KODE, K1, K2, MR, NN, NZ, I1MACH\n DIMENSION CYR(1), CYI(1)\n EXTERNAL ZABS, ZEXP, ZSQRT\n DATA TTH, C1, C2, COEF /6.66666666666666667D-01,\n * 3.55028053887817240D-01,2.58819403792806799D-01,\n * 1.83776298473930683D-01/\n DATA ZEROR, ZEROI, CONER, CONEI /0.0D0,0.0D0,1.0D0,0.0D0/\nC***FIRST EXECUTABLE STATEMENT ZAIRY\n IERR = 0\n NZ=0\n IF (ID.LT.0 .OR. ID.GT.1) IERR=1\n IF (KODE.LT.1 .OR. KODE.GT.2) IERR=1\n IF (IERR.NE.0) RETURN\n AZ = ZABS(ZR,ZI)\n TOL = MAX(D1MACH(4),1.0D-18)\n FID = ID\n IF (AZ.GT.1.0D0) GO TO 70\nC-----------------------------------------------------------------------\nC POWER SERIES FOR ABS(Z).LE.1.\nC-----------------------------------------------------------------------\n S1R = CONER\n S1I = CONEI\n S2R = CONER\n S2I = CONEI\n IF (AZ.LT.TOL) GO TO 170\n AA = AZ*AZ\n IF (AA.LT.TOL/AZ) GO TO 40\n TRM1R = CONER\n TRM1I = CONEI\n TRM2R = CONER\n TRM2I = CONEI\n ATRM = 1.0D0\n STR = ZR*ZR - ZI*ZI\n STI = ZR*ZI + ZI*ZR\n Z3R = STR*ZR - STI*ZI\n Z3I = STR*ZI + STI*ZR\n AZ3 = AZ*AA\n AK = 2.0D0 + FID\n BK = 3.0D0 - FID - FID\n CK = 4.0D0 - FID\n DK = 3.0D0 + FID + FID\n D1 = AK*DK\n D2 = BK*CK\n AD = MIN(D1,D2)\n AK = 24.0D0 + 9.0D0*FID\n BK = 30.0D0 - 9.0D0*FID\n DO 30 K=1,25\n STR = (TRM1R*Z3R-TRM1I*Z3I)/D1\n TRM1I = (TRM1R*Z3I+TRM1I*Z3R)/D1\n TRM1R = STR\n S1R = S1R + TRM1R\n S1I = S1I + TRM1I\n STR = (TRM2R*Z3R-TRM2I*Z3I)/D2\n TRM2I = (TRM2R*Z3I+TRM2I*Z3R)/D2\n TRM2R = STR\n S2R = S2R + TRM2R\n S2I = S2I + TRM2I\n ATRM = ATRM*AZ3/AD\n D1 = D1 + AK\n D2 = D2 + BK\n AD = MIN(D1,D2)\n IF (ATRM.LT.TOL*AD) GO TO 40\n AK = AK + 18.0D0\n BK = BK + 18.0D0\n 30 CONTINUE\n 40 CONTINUE\n IF (ID.EQ.1) GO TO 50\n AIR = S1R*C1 - C2*(ZR*S2R-ZI*S2I)\n AII = S1I*C1 - C2*(ZR*S2I+ZI*S2R)\n IF (KODE.EQ.1) RETURN\n CALL ZSQRT(ZR, ZI, STR, STI)\n ZTAR = TTH*(ZR*STR-ZI*STI)\n ZTAI = TTH*(ZR*STI+ZI*STR)\n CALL ZEXP(ZTAR, ZTAI, STR, STI)\n PTR = AIR*STR - AII*STI\n AII = AIR*STI + AII*STR\n AIR = PTR\n RETURN\n 50 CONTINUE\n AIR = -S2R*C2\n AII = -S2I*C2\n IF (AZ.LE.TOL) GO TO 60\n STR = ZR*S1R - ZI*S1I\n STI = ZR*S1I + ZI*S1R\n CC = C1/(1.0D0+FID)\n AIR = AIR + CC*(STR*ZR-STI*ZI)\n AII = AII + CC*(STR*ZI+STI*ZR)\n 60 CONTINUE\n IF (KODE.EQ.1) RETURN\n CALL ZSQRT(ZR, ZI, STR, STI)\n ZTAR = TTH*(ZR*STR-ZI*STI)\n ZTAI = TTH*(ZR*STI+ZI*STR)\n CALL ZEXP(ZTAR, ZTAI, STR, STI)\n PTR = STR*AIR - STI*AII\n AII = STR*AII + STI*AIR\n AIR = PTR\n RETURN\nC-----------------------------------------------------------------------\nC CASE FOR ABS(Z).GT.1.0\nC-----------------------------------------------------------------------\n 70 CONTINUE\n FNU = (1.0D0+FID)/3.0D0\nC-----------------------------------------------------------------------\nC SET PARAMETERS RELATED TO MACHINE CONSTANTS.\nC TOL IS THE APPROXIMATE UNIT ROUNDOFF LIMITED TO 1.0D-18.\nC ELIM IS THE APPROXIMATE EXPONENTIAL OVER- AND UNDERFLOW LIMIT.\nC EXP(-ELIM).LT.EXP(-ALIM)=EXP(-ELIM)/TOL AND\nC EXP(ELIM).GT.EXP(ALIM)=EXP(ELIM)*TOL ARE INTERVALS NEAR\nC UNDERFLOW AND OVERFLOW LIMITS WHERE SCALED ARITHMETIC IS DONE.\nC RL IS THE LOWER BOUNDARY OF THE ASYMPTOTIC EXPANSION FOR LARGE Z.\nC DIG = NUMBER OF BASE 10 DIGITS IN TOL = 10**(-DIG).\nC-----------------------------------------------------------------------\n K1 = I1MACH(15)\n K2 = I1MACH(16)\n R1M5 = D1MACH(5)\n K = MIN(ABS(K1),ABS(K2))\n ELIM = 2.303D0*(K*R1M5-3.0D0)\n K1 = I1MACH(14) - 1\n AA = R1M5*K1\n DIG = MIN(AA,18.0D0)\n AA = AA*2.303D0\n ALIM = ELIM + MAX(-AA,-41.45D0)\n RL = 1.2D0*DIG + 3.0D0\n ALAZ = LOG(AZ)\nC-----------------------------------------------------------------------\nC TEST FOR PROPER RANGE\nC-----------------------------------------------------------------------\n AA=0.5D0/TOL\n BB=I1MACH(9)*0.5D0\n AA=MIN(AA,BB)\n AA=AA**TTH\n IF (AZ.GT.AA) GO TO 260\n AA=SQRT(AA)\n IF (AZ.GT.AA) IERR=3\n CALL ZSQRT(ZR, ZI, CSQR, CSQI)\n ZTAR = TTH*(ZR*CSQR-ZI*CSQI)\n ZTAI = TTH*(ZR*CSQI+ZI*CSQR)\nC-----------------------------------------------------------------------\nC RE(ZTA).LE.0 WHEN RE(Z).LT.0, ESPECIALLY WHEN IM(Z) IS SMALL\nC-----------------------------------------------------------------------\n IFLAG = 0\n SFAC = 1.0D0\n AK = ZTAI\n IF (ZR.GE.0.0D0) GO TO 80\n BK = ZTAR\n CK = -ABS(BK)\n ZTAR = CK\n ZTAI = AK\n 80 CONTINUE\n IF (ZI.NE.0.0D0) GO TO 90\n IF (ZR.GT.0.0D0) GO TO 90\n ZTAR = 0.0D0\n ZTAI = AK\n 90 CONTINUE\n AA = ZTAR\n IF (AA.GE.0.0D0 .AND. ZR.GT.0.0D0) GO TO 110\n IF (KODE.EQ.2) GO TO 100\nC-----------------------------------------------------------------------\nC OVERFLOW TEST\nC-----------------------------------------------------------------------\n IF (AA.GT.(-ALIM)) GO TO 100\n AA = -AA + 0.25D0*ALAZ\n IFLAG = 1\n SFAC = TOL\n IF (AA.GT.ELIM) GO TO 270\n 100 CONTINUE\nC-----------------------------------------------------------------------\nC CBKNU AND CACON RETURN EXP(ZTA)*K(FNU,ZTA) ON KODE=2\nC-----------------------------------------------------------------------\n MR = 1\n IF (ZI.LT.0.0D0) MR = -1\n CALL ZACAI(ZTAR, ZTAI, FNU, KODE, MR, 1, CYR, CYI, NN, RL, TOL,\n * ELIM, ALIM)\n IF (NN.LT.0) GO TO 280\n NZ = NZ + NN\n GO TO 130\n 110 CONTINUE\n IF (KODE.EQ.2) GO TO 120\nC-----------------------------------------------------------------------\nC UNDERFLOW TEST\nC-----------------------------------------------------------------------\n IF (AA.LT.ALIM) GO TO 120\n AA = -AA - 0.25D0*ALAZ\n IFLAG = 2\n SFAC = 1.0D0/TOL\n IF (AA.LT.(-ELIM)) GO TO 210\n 120 CONTINUE\n CALL ZBKNU(ZTAR, ZTAI, FNU, KODE, 1, CYR, CYI, NZ, TOL, ELIM,\n * ALIM)\n 130 CONTINUE\n S1R = CYR(1)*COEF\n S1I = CYI(1)*COEF\n IF (IFLAG.NE.0) GO TO 150\n IF (ID.EQ.1) GO TO 140\n AIR = CSQR*S1R - CSQI*S1I\n AII = CSQR*S1I + CSQI*S1R\n RETURN\n 140 CONTINUE\n AIR = -(ZR*S1R-ZI*S1I)\n AII = -(ZR*S1I+ZI*S1R)\n RETURN\n 150 CONTINUE\n S1R = S1R*SFAC\n S1I = S1I*SFAC\n IF (ID.EQ.1) GO TO 160\n STR = S1R*CSQR - S1I*CSQI\n S1I = S1R*CSQI + S1I*CSQR\n S1R = STR\n AIR = S1R/SFAC\n AII = S1I/SFAC\n RETURN\n 160 CONTINUE\n STR = -(S1R*ZR-S1I*ZI)\n S1I = -(S1R*ZI+S1I*ZR)\n S1R = STR\n AIR = S1R/SFAC\n AII = S1I/SFAC\n RETURN\n 170 CONTINUE\n AA = 1.0D+3*D1MACH(1)\n S1R = ZEROR\n S1I = ZEROI\n IF (ID.EQ.1) GO TO 190\n IF (AZ.LE.AA) GO TO 180\n S1R = C2*ZR\n S1I = C2*ZI\n 180 CONTINUE\n AIR = C1 - S1R\n AII = -S1I\n RETURN\n 190 CONTINUE\n AIR = -C2\n AII = 0.0D0\n AA = SQRT(AA)\n IF (AZ.LE.AA) GO TO 200\n S1R = 0.5D0*(ZR*ZR-ZI*ZI)\n S1I = ZR*ZI\n 200 CONTINUE\n AIR = AIR + C1*S1R\n AII = AII + C1*S1I\n RETURN\n 210 CONTINUE\n NZ = 1\n AIR = ZEROR\n AII = ZEROI\n RETURN\n 270 CONTINUE\n NZ = 0\n IERR=2\n RETURN\n 280 CONTINUE\n IF(NN.EQ.(-1)) GO TO 270\n NZ=0\n IERR=5\n RETURN\n 260 CONTINUE\n IERR=4\n NZ=0\n RETURN\n END\n", "meta": {"hexsha": "20f562f16abb549a5692161bd550b614ac976908", "size": 15229, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "COMPDIRS/debug.BIN.mac/bessel/zairy.f", "max_stars_repo_name": "danhax/V1-temp", "max_stars_repo_head_hexsha": "efbcba25dbd8550e62f1a83ce8c2328a30659466", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2016-02-08T05:46:15.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-23T12:27:36.000Z", "max_issues_repo_path": "COMPDIRS/debug.BIN.mac/bessel/zairy.f", "max_issues_repo_name": "danhax/V1-temp", "max_issues_repo_head_hexsha": "efbcba25dbd8550e62f1a83ce8c2328a30659466", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 18, "max_issues_repo_issues_event_min_datetime": "2015-12-21T19:20:36.000Z", "max_issues_repo_issues_event_max_datetime": "2020-11-20T06:22:29.000Z", "max_forks_repo_path": "COMPDIRS/debug.BIN.mac/bessel/zairy.f", "max_forks_repo_name": "danhax/V1-temp", "max_forks_repo_head_hexsha": "efbcba25dbd8550e62f1a83ce8c2328a30659466", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2016-03-04T17:35:46.000Z", "max_forks_repo_forks_event_max_datetime": "2018-03-02T03:11:23.000Z", "avg_line_length": 37.6024691358, "max_line_length": 72, "alphanum_fraction": 0.5180904853, "num_tokens": 5321, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.743167997235783, "lm_q1q2_score": 0.6545802050627761}} {"text": "!-------------------------------------------------------------------------------\n!\n!+ Program mkvlayer\n!\n!-------------------------------------------------------------------------------\nprogram prg_mkvlayer\n !-----------------------------------------------------------------------------\n !\n !++ Description:\n ! This program makes grid systems based on the icosahedral grid\n ! configuration.\n !\n !++ Current Corresponding Author : H.Tomita\n !\n !++ History:\n ! Version Date Comment\n ! -----------------------------------------------------------------------\n ! 0.00 04-02-17 Imported from igdc-4.34\n ! -----------------------------------------------------------------------\n !\n !-----------------------------------------------------------------------------\n !\n !++ Used modules ( shared )\n !\n !=============================================================================\n integer, parameter :: kdum=1\n integer, parameter :: fid=11\n integer :: num_of_layer = 10\n real(8) :: ztop = 1.0D+4\n character(256) :: outfname = 'outfile'\n character(256) :: infname = 'infile'\n character(16) :: layer_type = 'POWER'\n real(8) :: fact = 1.0D0\n\n namelist / mkvlayer_cnf / &\n num_of_layer, & !--- number of layers\n ztop, & !--- height of model top\n outfname, & !--- output file name\n layer_type, & !--- type of layer\n fact, & !--- factor if layer_type='POWER'\n infname !--- input file name if layer_type='GIVEN'\n\n real(8),allocatable :: z_c(:)\n real(8),allocatable :: z_h(:)\n\n integer :: kmin\n integer :: kmax\n integer :: kall\n\n open(fid,file='mkvlayer.cnf',status='old',form='formatted')\n read(fid,nml=mkvlayer_cnf)\n close(fid)\n\n\n select case(trim(layer_type))\n case('POWER')\n call mk_layer_powerfunc(fact)\n case('GIVEN')\n call mk_layer_given(infname)\n end select\n !\n call output_layer(outfname)\n\n !=============================================================================\ncontains\n !-----------------------------------------------------------------------------\n subroutine mk_layer_powerfunc( fact )\n implicit none\n real(8) :: a\n integer :: k\n real(8),intent(in) :: fact\n\n kmin=kdum+1\n kmax=kdum+num_of_layer\n kall=kdum+num_of_layer+kdum\n allocate(z_c(kall))\n allocate(z_h(kall))\n !\n a = ztop/(dble(num_of_layer)**fact)\n !\n do k = kmin, kmax+1\n z_h(k) = a * (dble(k-kmin)**fact)\n enddo\n !\n z_h(kmin-1) = z_h(kmin) - ( z_h(kmin+1) - z_h(kmin) )\n !\n do k= kmin-1, kmax\n z_c(k) = z_h(k) + ( z_h(k+1) - z_h(k) )*0.5D0\n enddo\n z_c(kmax+1) = z_h(kmax+1) + ( z_h(kmax+1) - z_h(kmax) )*0.5D0\n !\n end subroutine mk_layer_powerfunc\n\n subroutine mk_layer_given( infname )\n implicit none\n character(len=*), intent(in) :: infname\n integer,parameter :: fid=10\n integer :: k\n !\n open(fid,file=trim(infname),status='old',form='formatted')\n read(fid,*) num_of_layer\n !\n kmin=kdum+1\n kmax=kdum+num_of_layer\n kall=kdum+num_of_layer+kdum\n allocate(z_c(kall))\n allocate(z_h(kall))\n !\n do k = kmin, kmax+1\n read(fid,*) z_h(k)\n enddo\n !\n z_h(kmin-1) = z_h(kmin) - ( z_h(kmin+1) - z_h(kmin) )\n !\n do k= kmin-1, kmax\n z_c(k) = z_h(k) + ( z_h(k+1) - z_h(k) )*0.5D0\n enddo\n z_c(kmax+1) = z_h(kmax+1) + ( z_h(kmax+1) - z_h(kmax) )*0.5D0\n !\n close(fid)\n !\n end subroutine mk_layer_given\n\n !-----------------------------------------------------------------------------\n subroutine output_layer( outfname )\n implicit none\n\n character(len=*), intent(in) :: outfname\n\n character(len=128) :: fname_all\n character(len=128) :: fname_def\n integer :: kall, kmin, kmax\n\n integer :: fid = 10\n integer :: k\n !---------------------------------------------------------------------------\n\n open( unit = fid, &\n file = trim(outfname), &\n form = 'unformatted' )\n write(fid) num_of_layer\n write(fid) z_c\n write(fid) z_h\n close(fid)\n\n kmin = kdum + 1\n kmax = kdum + num_of_layer\n kall = kdum + num_of_layer + kdum\n\n if ( kall > 100 ) then\n write(fname_all,'(A5,I3.3,A4)') 'ZSALL', kall, '.txt'\n write(fname_def,'(A5,I3.3,A4)') 'ZSDEF', num_of_layer, '.txt'\n else\n write(fname_all,'(A5,I2.2,A4)') 'ZSALL', kall, '.txt'\n write(fname_def,'(A5,I2.2,A4)') 'ZSDEF', num_of_layer, '.txt'\n endif\n\n open( unit = fid, &\n file = trim(fname_all), &\n form = 'formatted' )\n write(fid,'(I4)') kall\n do k = 1, kall\n write(fid,'(f12.3)') z_c(k)\n enddo\n close(fid)\n\n open( unit = fid, &\n file = trim(fname_def), &\n form = 'formatted' )\n write(fid,'(I4)') num_of_layer\n do k = kmin, kmax\n write(fid,'(f12.3)') z_c(k)\n enddo\n close(fid)\n\n return\n end subroutine output_layer\n\nend program prg_mkvlayer\n!-------------------------------------------------------------------------------\n", "meta": {"hexsha": "1d6eb054354672200467ffbafd79d3efd6c31ec0", "size": 5155, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/framework/mkvlayer/mkvlayer.f90", "max_stars_repo_name": "hisashiyashiro/nicamdc", "max_stars_repo_head_hexsha": "90ac760804a2e81fd4453a33351787e448433ce7", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2016-06-30T02:14:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-13T22:24:47.000Z", "max_issues_repo_path": "test/framework/mkvlayer/mkvlayer.f90", "max_issues_repo_name": "nicamdc-dev/nicamdc", "max_issues_repo_head_hexsha": "90ac760804a2e81fd4453a33351787e448433ce7", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/framework/mkvlayer/mkvlayer.f90", "max_forks_repo_name": "nicamdc-dev/nicamdc", "max_forks_repo_head_hexsha": "90ac760804a2e81fd4453a33351787e448433ce7", "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": 28.4806629834, "max_line_length": 80, "alphanum_fraction": 0.4490785645, "num_tokens": 1462, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970748488296, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.654580203096822}} {"text": "! ::: -----------------------------------------------------------\n! ::: This routine will tag high error cells based on the Laplacian.\n! :::\n! ::: INPUTS/OUTPUTS:\n! :::\n! ::: tag <= integer tag array\n! ::: lo,hi => index extent of tag array\n! ::: set => integer value to tag cell for refinement\n! ::: clear => integer value to untag cell\n! ::: var => array of data\n! ::: nd => number of components in var array (should be 1)\n! ::: domlo,hi => index extent of problem domain\n! ::: delta => cell spacing\n! ::: xlo => physical location of lower left hand\n! ::: corner of tag array\n! ::: problo => phys loc of lower left corner of prob domain\n! ::: time => problem evolution time\n! ::: level => refinement level of this array\n! ::: -----------------------------------------------------------\n subroutine tag_laplac_error(tag,tagl1,tagl2,tagl3,tagh1,tagh2,tagh3, &\n set,clear, &\n var,varl1,varl2,varl3,varh1,varh2,varh3, &\n lo,hi,nd,domlo,domhi, &\n delta,xlo,problo,time,level)\n use probdata_module\n use amrex_fort_module, only : rt => amrex_real\n implicit none\n\n integer :: set, clear, nd, level\n integer :: tagl1,tagl2,tagl3,tagh1,tagh2,tagh3\n integer :: varl1,varl2,varl3,varh1,varh2,varh3\n integer :: lo(3), hi(3), domlo(3), domhi(3)\n integer :: tag(tagl1:tagh1,tagl2:tagh2,tagl3:tagh3)\n real(rt) :: var(varl1:varh1,varl2:varh2,varl3:varh3)\n real(rt) :: delta(3), xlo(3), problo(3), time\n integer :: i,j,k\n\n real(rt) :: delu(lo(1)-1:hi(1)+1,lo(2)-1:hi(2)+1,lo(3)-1:hi(3)+1,3)\n real(rt) :: delua(lo(1)-1:hi(1)+1,lo(2)-1:hi(2)+1,lo(3)-1:hi(3)+1,3)\n real(rt) :: delu2(9), delu3(9), delu4(9)\n real(rt) :: num, denom, error\n\n ! This value is taken from FLASH\n real(rt), parameter :: ctore=0.8\n real(rt), parameter:: epsil=0.02\n\n ! adapted from ref_marking.f90 in FLASH2.5\n\n ! d/dx\n do k=lo(3)-1,hi(3)+1\n do j=lo(2)-1,hi(2)+1\n do i=lo(1)-1,hi(1)+1\n delu(i,j,k,1) = var(i+1,j,k) - var(i-1,j,k) \n delua(i,j,k,1) = abs(var(i+1,j,k)) + abs(var(i-1,j,k))\n end do\n end do\n end do\n\n ! d/dy\n do k=lo(3)-1,hi(3)+1\n do j=lo(2)-1,hi(2)+1\n do i=lo(1)-1,hi(1)+1\n delu(i,j,k,2) = var(i,j+1,k) - var(i,j-1,k) \n delua(i,j,k,2) = abs(var(i,j+1,k)) + abs(var(i,j-1,k))\n end do\n end do\n end do\n\n ! d/dz\n do k=lo(3)-1,hi(3)+1\n do j=lo(2)-1,hi(2)+1\n do i=lo(1)-1,hi(1)+1\n delu(i,j,k,3) = var(i,j,k+1) - var(i,j,k-1)\n delua(i,j,k,3) = abs(var(i,j,k+1)) + abs(var(i,j,k-1))\n end do\n end do\n end do\n\n do k = lo(3),hi(3)\n do j = lo(2),hi(2)\n do i = lo(1),hi(1)\n \n\n ! d/dxdx\n delu2(1) = delu(i+1,j,k,1) - delu(i-1,j,k,1)\n delu3(1) = abs(delu(i+1,j,k,1)) + abs(delu(i-1,j,k,1))\n delu4(1) = delua(i+1,j,k,1) + delua(i-1,j,k,1)\n\n ! d/dydx\n delu2(2) = delu(i,j+1,k,1) - delu(i,j-1,k,1)\n delu3(2) = abs(delu(i,j+1,k,1)) + abs(delu(i,j-1,k,1))\n delu4(2) = delua(i,j+1,k,1) + delua(i,j-1,k,1)\n\n ! d/dxdy\n delu2(3) = delu(i+1,j,k,2) - delu(i-1,j,k,2)\n delu3(3) = abs(delu(i+1,j,k,2)) + abs(delu(i-1,j,k,2))\n delu4(3) = delua(i+1,j,k,2) + delua(i-1,j,k,2)\n \n ! d/dydy \n delu2(4) = delu(i,j+1,k,2) - delu(i,j-1,k,2)\n delu3(4) = abs(delu(i,j+1,k,2)) + abs(delu(i,j-1,k,2))\n delu4(4) = delua(i,j+1,k,2) + delua(i,j-1,k,2)\n \n ! d/dzdx \n delu2(5) = delu(i,j,k+1,1) - delu(i,j,k-1,1)\n delu3(5) = abs(delu(i,j,k+1,1)) + abs(delu(i,j,k-1,1))\n delu4(5) = delua(i,j,k+1,1) + delua(i,j,k-1,1)\n \n ! d/dzdy \n delu2(6) = delu(i,j,k+1,2) - delu(i,j,k-1,2)\n delu3(6) = abs(delu(i,j,k+1,2)) + abs(delu(i,j,k-1,2))\n delu4(6) = delua(i,j,k+1,2) + delua(i,j,k-1,2)\n \n ! d/dxdz \n delu2(7) = delu(i+1,j,k,3) - delu(i-1,j,k,3)\n delu3(7) = abs(delu(i+1,j,k,3)) + abs(delu(i-1,j,k,3))\n delu4(7) = delua(i+1,j,k,3) + delua(i-1,j,k,3)\n \n ! d/dydz \n delu2(8) = delu(i,j+1,k,3) - delu(i,j-1,k,3)\n delu3(8) = abs(delu(i,j+1,k,3)) + abs(delu(i,j-1,k,3))\n delu4(8) = delua(i,j+1,k,3) + delua(i,j-1,k,3)\n \n ! d/dzdz \n delu2(9) = delu(i,j,k+1,3) - delu(i,j,k-1,3)\n delu3(9) = abs(delu(i,j,k+1,3)) + abs(delu(i,j,k-1,3))\n delu4(9) = delua(i,j,k+1,3) + delua(i,j,k-1,3)\n\n ! compute the error\n num = delu2(1)**2 + delu2(2)**2 + delu2(3)**2 + delu2(4)**2 &\n +delu2(5)**2 + delu2(6)**2 + delu2(7)**2 + delu2(8)**2 &\n +delu2(9)**2\n\n denom = (delu3(1) + (epsil*delu4(1)+1.d-99))**2 + &\n (delu3(2) + (epsil*delu4(2)+1.d-99))**2 + &\n (delu3(3) + (epsil*delu4(3)+1.d-99))**2 + &\n (delu3(4) + (epsil*delu4(4)+1.d-99))**2 + &\n (delu3(5) + (epsil*delu4(5)+1.d-99))**2 + &\n (delu3(6) + (epsil*delu4(6)+1.d-99))**2 + &\n (delu3(7) + (epsil*delu4(7)+1.d-99))**2 + &\n (delu3(8) + (epsil*delu4(8)+1.d-99))**2 + &\n (delu3(9) + (epsil*delu4(9)+1.d-99))**2\n\n error = sqrt(num/denom)\n\n if (error .gt. ctore) tag(i,j,k)=set\n\n end do\n end do\n end do\n\n end subroutine tag_laplac_error\n\n! ::: -----------------------------------------------------------\n! ::: This routine will tag high error cells based on the density\n! ::: \n! ::: INPUTS/OUTPUTS:\n! ::: \n! ::: tag <= integer tag array\n! ::: lo,hi => index extent of tag array\n! ::: set => integer value to tag cell for refinement\n! ::: clear => integer value to untag cell\n! ::: den => density array\n! ::: nd => number of components in den array (should be 1)\n! ::: domlo,hi => index extent of problem domain\n! ::: delta => cell spacing\n! ::: xlo => physical location of lower left hand\n! ::: corner of tag array\n! ::: problo => phys loc of lower left corner of prob domain\n! ::: time => problem evolution time\n! ::: level => refinement level of this array\n! ::: -----------------------------------------------------------\n subroutine tag_denerror(tag,tagl1,tagl2,tagl3,tagh1,tagh2,tagh3, &\n set,clear, &\n den,denl1,denl2,denl3,denh1,denh2,denh3, &\n lo,hi,nd,domlo,domhi, &\n delta,xlo,problo,time,level)\n use probdata_module\n implicit none\n\n integer :: set, clear, nd, level\n integer :: tagl1,tagl2,tagl3,tagh1,tagh2,tagh3\n integer :: denl1,denl2,denl3,denh1,denh2,denh3\n integer :: lo(3), hi(3), domlo(3), domhi(3)\n integer :: tag(tagl1:tagh1,tagl2:tagh2,tagl3:tagh3)\n real(rt) :: den(denl1:denh1,denl2:denh2,denl3:denh3,nd)\n real(rt) :: delta(3), xlo(3), problo(3), time\n\n integer :: i,j,k\n real(rt) :: ax,ay,az\n\n! Tag on regions of high density\n if (level .lt. max_denerr_lev) then\n do k = lo(3), hi(3)\n do j = lo(2), hi(2)\n do i = lo(1), hi(1)\n if (den(i,j,k,1) .ge. denerr) then\n tag(i,j,k) = set\n endif\n enddo\n enddo\n enddo\n endif\n\n! Tag on regions of high density gradient\n if (level .lt. max_dengrad_lev) then\n do k = lo(3), hi(3)\n do j = lo(2), hi(2)\n do i = lo(1), hi(1)\n ax = ABS(den(i+1,j,k,1) - den(i,j,k,1))\n ay = ABS(den(i,j+1,k,1) - den(i,j,k,1))\n az = ABS(den(i,j,k+1,1) - den(i,j,k,1))\n ax = MAX(ax,ABS(den(i,j,k,1) - den(i-1,j,k,1)))\n ay = MAX(ay,ABS(den(i,j,k,1) - den(i,j-1,k,1)))\n az = MAX(az,ABS(den(i,j,k,1) - den(i,j,k-1,1)))\n if ( MAX(ax,ay,az) .ge. dengrad) then\n tag(i,j,k) = set\n endif\n enddo\n enddo\n enddo\n endif\n\n end subroutine tag_denerror\n\n! ::: -----------------------------------------------------------\n! ::: This routine will tag high error cells based on the temperature\n! ::: \n! ::: INPUTS/OUTPUTS:\n! ::: \n! ::: tag <= integer tag array\n! ::: lo,hi => index extent of tag array\n! ::: set => integer value to tag cell for refinement\n! ::: clear => integer value to untag cell\n! ::: temp => temperature array\n! ::: np => number of components in temp array (should be 1)\n! ::: domlo,hi => index extent of problem domain\n! ::: delta => cell spacing\n! ::: xlo => physical location of lower left hand\n! ::: corner of tag array\n! ::: problo => phys loc of lower left corner of prob domain\n! ::: time => problem evolution time\n! ::: level => refinement level of this array\n! ::: -----------------------------------------------------------\n\n subroutine tag_temperror(tag,tagl1,tagl2,tagl3,tagh1,tagh2,tagh3, &\n set,clear, &\n temp,templ1,templ2,templ3,temph1, &\n temph2,temph3, &\n lo,hi,np,domlo,domhi, &\n delta,xlo,problo,time,level)\n\n use probdata_module\n implicit none\n\n integer :: set, clear, np, level\n integer :: tagl1,tagl2,tagl3,tagh1,tagh2,tagh3\n integer :: templ1,templ2,templ3,temph1,temph2,temph3\n integer :: lo(3), hi(3), domlo(3), domhi(3)\n integer :: tag(tagl1:tagh1,tagl2:tagh2,tagl3:tagh3)\n real(rt) :: temp(templ1:temph1,templ2:temph2, &\n templ3:temph3,np)\n real(rt) :: delta(3), xlo(3), problo(3), time\n\n integer :: i,j,k\n real(rt) :: ax,ay,az\n\n! Tag on regions of high temperature\n if (level .lt. max_temperr_lev) then\n do k = lo(3), hi(3)\n do j = lo(2), hi(2)\n do i = lo(1), hi(1)\n if (temp(i,j,k,1) .ge. temperr) then\n tag(i,j,k) = set\n endif\n enddo\n enddo\n enddo\n endif\n\n! Tag on regions of high temperature gradient\n if (level .lt. max_tempgrad_lev) then\n do k = lo(3), hi(3)\n do j = lo(2), hi(2)\n do i = lo(1), hi(1)\n ax = ABS(temp(i+1,j,k,1) - temp(i,j,k,1))\n ay = ABS(temp(i,j+1,k,1) - temp(i,j,k,1))\n az = ABS(temp(i,j,k+1,1) - temp(i,j,k,1))\n ax = MAX(ax,ABS(temp(i,j,k,1) - temp(i-1,j,k,1)))\n ay = MAX(ay,ABS(temp(i,j,k,1) - temp(i,j-1,k,1)))\n az = MAX(az,ABS(temp(i,j,k,1) - temp(i,j,k-1,1)))\n if ( MAX(ax,ay,az) .ge. tempgrad) then\n tag(i,j,k) = set\n endif\n enddo\n enddo\n enddo\n endif\n\n end subroutine tag_temperror\n\n! ::: -----------------------------------------------------------\n! ::: This routine will tag high error cells based on the pressure\n! ::: \n! ::: INPUTS/OUTPUTS:\n! ::: \n! ::: tag <= integer tag array\n! ::: lo,hi => index extent of tag array\n! ::: set => integer value to tag cell for refinement\n! ::: clear => integer value to untag cell\n! ::: press => pressure array\n! ::: np => number of components in press array (should be 1)\n! ::: domlo,hi => index extent of problem domain\n! ::: delta => cell spacing\n! ::: xlo => physical location of lower left hand\n! ::: corner of tag array\n! ::: problo => phys loc of lower left corner of prob domain\n! ::: time => problem evolution time\n! ::: level => refinement level of this array\n! ::: -----------------------------------------------------------\n subroutine tag_presserror(tag,tagl1,tagl2,tagl3,tagh1,tagh2,tagh3, &\n set,clear, &\n press,pressl1,pressl2,pressl3,pressh1, &\n pressh2,pressh3, &\n lo,hi,np,domlo,domhi, &\n delta,xlo,problo,time,level)\n\n use probdata_module\n implicit none\n\n integer :: set, clear, np, level\n integer :: tagl1,tagl2,tagl3,tagh1,tagh2,tagh3\n integer :: pressl1,pressl2,pressl3,pressh1,pressh2,pressh3\n integer :: lo(3), hi(3), domlo(3), domhi(3)\n integer :: tag(tagl1:tagh1,tagl2:tagh2,tagl3:tagh3)\n real(rt) :: press(pressl1:pressh1,pressl2:pressh2, &\n pressl3:pressh3,np)\n real(rt) :: delta(3), xlo(3), problo(3), time\n\n integer :: i,j,k\n real(rt) :: ax,ay,az\n\n! Tag on regions of high pressure\n if (level .lt. max_presserr_lev) then\n do k = lo(3), hi(3)\n do j = lo(2), hi(2)\n do i = lo(1), hi(1)\n if (press(i,j,k,1) .ge. presserr) then\n tag(i,j,k) = set\n endif\n enddo\n enddo\n enddo\n endif\n\n! Tag on regions of high pressure gradient\n if (level .lt. max_pressgrad_lev) then\n do k = lo(3), hi(3)\n do j = lo(2), hi(2)\n do i = lo(1), hi(1)\n ax = ABS(press(i+1,j,k,1) - press(i,j,k,1))\n ay = ABS(press(i,j+1,k,1) - press(i,j,k,1))\n az = ABS(press(i,j,k+1,1) - press(i,j,k,1))\n ax = MAX(ax,ABS(press(i,j,k,1) - press(i-1,j,k,1)))\n ay = MAX(ay,ABS(press(i,j,k,1) - press(i,j-1,k,1)))\n az = MAX(az,ABS(press(i,j,k,1) - press(i,j,k-1,1)))\n if ( MAX(ax,ay,az) .ge. pressgrad) then\n tag(i,j,k) = set\n endif\n enddo\n enddo\n enddo\n endif\n\n end subroutine tag_presserror\n\n! ::: -----------------------------------------------------------\n! ::: This routine will tag high error cells based on the velocity\n! ::: \n! ::: INPUTS/OUTPUTS:\n! ::: \n! ::: tag <= integer tag array\n! ::: lo,hi => index extent of tag array\n! ::: set => integer value to tag cell for refinement\n! ::: clear => integer value to untag cell\n! ::: vel => velocity array\n! ::: nv => number of components in vel array (should be 3)\n! ::: domlo,hi => index extent of problem domain\n! ::: delta => cell spacing\n! ::: xlo => physical location of lower left hand\n! ::: corner of tag array\n! ::: problo => phys loc of lower left corner of prob domain\n! ::: time => problem evolution time\n! ::: level => refinement level of this array\n! ::: -----------------------------------------------------------\n subroutine tag_velerror(tag,tagl1,tagl2,tagl3,tagh1,tagh2,tagh3, &\n set,clear, &\n vel,vell1,vell2,vell3,velh1,velh2,velh3, &\n lo,hi,nv,domlo,domhi, &\n delta,xlo,problo,time,level)\n\n use probdata_module\n implicit none\n\n integer :: set, clear, nv, level\n integer :: tagl1,tagl2,tagl3,tagh1,tagh2,tagh3\n integer :: vell1,vell2,vell3,velh1,velh2,velh3\n integer :: lo(3), hi(3), domlo(3), domhi(3)\n integer :: tag(tagl1:tagh1,tagl2:tagh2,tagl3:tagh3)\n real(rt) :: vel(vell1:velh1,vell2:velh2,vell3:velh3,nv)\n real(rt) :: delta(3), xlo(3), problo(3), time\n\n integer :: i,j,k\n real(rt) :: ax,ay,az\n\n! Tag on regions of high velocity gradient\n if (level .lt. max_velgrad_lev) then\n do k = lo(3), hi(3)\n do j = lo(2), hi(2)\n do i = lo(1), hi(1)\n ax = ABS(vel(i+1,j,k,1) - vel(i,j,k,1))\n ay = ABS(vel(i,j+1,k,1) - vel(i,j,k,1))\n az = ABS(vel(i,j,k+1,1) - vel(i,j,k,1))\n ax = MAX(ax,ABS(vel(i,j,k,1) - vel(i-1,j,k,1)))\n ay = MAX(ay,ABS(vel(i,j,k,1) - vel(i,j-1,k,1)))\n az = MAX(az,ABS(vel(i,j,k,1) - vel(i,j,k-1,1)))\n if ( MAX(ax,ay,az) .ge. velgrad) then\n tag(i,j,k) = set\n endif\n enddo\n enddo\n enddo\n endif\n\n end subroutine tag_velerror\n\n! ::: -----------------------------------------------------------\n! ::: This routine will tag high error cells based on overdensity\n! :::\n! ::: INPUTS/OUTPUTS:\n! :::\n! ::: tag <= integer tag array\n! ::: lo,hi => index extent of tag array\n! ::: set => integer value to tag cell for refinement\n! ::: clear => integer value to untag cell\n! ::: den => density array\n! ::: nc => number of components in density array\n! ::: domlo,hi => index extent of problem domain\n! ::: delta => cell spacing\n! ::: xlo => physical location of lower left hand\n! ::: corner of tag array\n! ::: problo => phys loc of lower left corner of prob domain\n! ::: time => problem evolution time\n! ::: level => refinement level of this array\n! ::: -----------------------------------------------------------\n subroutine tag_overdensity(tag,tagl1,tagl2,tagl3,tagh1,tagh2,tagh3, &\n set,clear, &\n den,denl1,denl2,denl3,denh1,denh2,denh3, &\n lo,hi,nc,domlo,domhi,delta,level,avg_den)\n\n use probdata_module\n implicit none\n\n integer :: set, clear, nc, level\n integer :: tagl1,tagl2,tagl3,tagh1,tagh2,tagh3\n integer :: denl1,denl2,denl3,denh1,denh2,denh3\n integer :: lo(3), hi(3), domlo(3), domhi(3)\n integer :: tag(tagl1:tagh1,tagl2:tagh2,tagl3:tagh3)\n real(rt) :: den(denl1:denh1,denl2:denh2,denl3:denh3,nc)\n real(rt) :: delta(3), avg_den\n\n integer :: i,j,k\n real(rt) :: over_den\n\n over_den = 1.1d0 * avg_den\n\n! Tag on regions of overdensity\n do k = lo(3), hi(3)\n do j = lo(2), hi(2)\n do i = lo(1), hi(1)\n if ( den(i,j,k,1) .gt. over_den ) then\n tag(i,j,k) = set\n endif\n enddo\n enddo\n enddo\n\n end subroutine tag_overdensity\n\n! ::: -----------------------------------------------------------\n! ::: This routine will tag high error cells based on the number of particles.\n! :::\n! ::: INPUTS/OUTPUTS:\n! :::\n! ::: tag <= integer tag array\n! ::: lo,hi => index extent of tag array\n! ::: set => integer value to tag cell for refinement\n! ::: clear => integer value to untag cell\n! ::: var => array of data\n! ::: nd => number of components in var array (should be 1)\n! ::: domlo,hi => index extent of problem domain\n! ::: delta => cell spacing\n! ::: xlo => physical location of lower left hand\n! ::: corner of tag array\n! ::: problo => phys loc of lower left corner of prob domain\n! ::: time => problem evolution time\n! ::: level => refinement level of this array\n! ::: -----------------------------------------------------------\n subroutine tag_part_cnt_err(tag,tagl1,tagl2,tagl3,tagh1,tagh2,tagh3, &\n set,clear, &\n var,varl1,varl2,varl3,varh1,varh2,varh3, &\n lo,hi,nd,domlo,domhi, &\n delta,xlo,problo,time,level)\n use probdata_module\n implicit none\n\n integer :: set, clear, nd, level\n integer :: tagl1,tagl2,tagl3,tagh1,tagh2,tagh3\n integer :: varl1,varl2,varl3,varh1,varh2,varh3\n integer :: lo(3), hi(3), domlo(3), domhi(3)\n integer :: tag(tagl1:tagh1,tagl2:tagh2,tagl3:tagh3)\n real(rt) :: var(varl1:varh1,varl2:varh2,varl3:varh3,nd)\n real(rt) :: delta(3), xlo(3), problo(3), time\n\n integer :: ilo,jlo,klo,ihi,jhi,khi\n integer :: i,j,k\n\n do k = lo(3),hi(3)\n do j = lo(2),hi(2)\n do i = lo(1),hi(1)\n if (var(i,j,k,1) .gt. max_num_part) then\n tag(i,j,k) = set\n end if\n end do\n end do\n end do\n\n end subroutine tag_part_cnt_err\n\n! ::: -----------------------------------------------------------\n! ::: This routine will tag a specific region.\n! :::\n! ::: INPUTS/OUTPUTS:\n! :::\n! ::: tag <= integer tag array\n! ::: lo,hi => index extent of tag array\n! ::: set => integer value to tag cell for refinement\n! ::: clear => integer value to untag cell\n! ::: var => array of data\n! ::: nd => number of components in var array (should be 1)\n! ::: domlo,hi => index extent of problem domain\n! ::: delta => cell spacing\n! ::: xlo => physical location of lower left hand\n! ::: corner of tag array\n! ::: problo => phys loc of lower left corner of prob domain\n! ::: time => problem evolution time\n! ::: level => refinement level of this array\n! ::: -----------------------------------------------------------\n subroutine tag_region(tag,tagl1,tagl2,tagl3,tagh1,tagh2,tagh3, &\n set,lo,hi,domlo,domhi, &\n delta,xlo,problo,level)\n\n use probdata_module\n implicit none\n\n integer :: set,level\n integer :: tagl1,tagl2,tagl3,tagh1,tagh2,tagh3\n integer :: lo(3), hi(3), domlo(3), domhi(3)\n integer :: tag(tagl1:tagh1,tagl2:tagh2,tagl3:tagh3)\n real(rt) :: delta(3), xlo(3), problo(3), time\n\n integer :: ilo,jlo,klo,ihi,jhi,khi\n integer :: i,j,k\n\n if (level .eq. 0) then\n ilo = (domhi(1)+1)*1/4\n ihi = (domhi(1)+1)*3/4 - 1\n jlo = (domhi(2)+1)*1/4\n jhi = (domhi(2)+1)*3/4 - 1\n klo = (domhi(3)+1)*1/4\n khi = (domhi(3)+1)*3/4 - 1\n do k = lo(3),hi(3)\n do j = lo(2),hi(2)\n do i = lo(1),hi(1)\n if (i.ge.ilo .and. i.le.ihi .and. &\n j.ge.jlo .and. j.le.jhi .and. &\n k.ge.klo .and. k.le.khi) then\n tag(i,j,k) = set\n end if\n end do\n end do\n end do\n else\n ilo = (domhi(1)+1)*3/8\n ihi = (domhi(1)+1)*5/8 - 1\n jlo = (domhi(2)+1)*3/8\n jhi = (domhi(2)+1)*5/8 - 1\n klo = (domhi(3)+1)*3/8\n khi = (domhi(3)+1)*5/8 - 1\n do k = lo(3),hi(3)\n do j = lo(2),hi(2)\n do i = lo(1),hi(1)\n if (i.ge.ilo .and. i.le.ihi .and. &\n j.ge.jlo .and. j.le.jhi .and. &\n k.ge.klo .and. k.le.khi) then\n tag(i,j,k) = set\n end if\n end do\n end do\n end do\n endif\n\n end subroutine tag_region\n", "meta": {"hexsha": "bf61a9886c00f4e9c10cfe58821fd8fb427bd786", "size": 24116, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Source/Tagging/Tagging_3d.f90", "max_stars_repo_name": "Gosenca/axionyx_1.0", "max_stars_repo_head_hexsha": "7e2a723e00e6287717d6d81b23db32bcf6c3521a", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-02-18T09:13:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T21:27:46.000Z", "max_issues_repo_path": "Source/Tagging/Tagging_3d.f90", "max_issues_repo_name": "Gosenca/axionyx_1.0", "max_issues_repo_head_hexsha": "7e2a723e00e6287717d6d81b23db32bcf6c3521a", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-10-12T08:54:31.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-12T08:54:31.000Z", "max_forks_repo_path": "Source/Tagging/Tagging_3d.f90", "max_forks_repo_name": "Gosenca/axionyx_1.0", "max_forks_repo_head_hexsha": "7e2a723e00e6287717d6d81b23db32bcf6c3521a", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-09-04T10:26:25.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T23:51:51.000Z", "avg_line_length": 39.2768729642, "max_line_length": 78, "alphanum_fraction": 0.4450986897, "num_tokens": 7584, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009503523291, "lm_q2_score": 0.7154240079185319, "lm_q1q2_score": 0.654542104749537}} {"text": "module fcn_scalar_adv_diff_bl_solution\n#include \n use mod_kinds, only: rk,ik\n use mod_constants, only: ZERO, ONE, TWO, THREE, FIVE\n use type_point, only: point_t\n use type_point_ad, only: point_ad_t\n use type_function, only: function_t\n use DNAD_D\n implicit none\n\n\n\n\n\n !> scalar_adv_diff_bl_solution function.\n !!\n !! Three 1D scalar_adv_diff_bl_solution functions are computed; one for each dimension. They are multiplied\n !! together to create a 3D version of the function.\n !!\n !! \\f$ f_x(t,\\vec{x}) = a e^{- \\frac{(x-b_x)^2}{2c^2} } \\\\\n !! f_y(t,\\vec{x}) = a e^{- \\frac{(y-b_y)^2}{2c^2} } \\\\\n !! f_z(t,\\vec{x}) = a e^{- \\frac{(z-b_z)^2}{2c^2} } \\\\\n !! f(t,\\vec{x}) = f_x * f_y * f_z \\f$\n !!\n !! Function parameters:\n !!\n !! \\f$ a - \\text{Amplitude of the distribution} \\\\\n !! b_i - \\text{Offset in coordinate 'i'} \\\\\n !! c - \\text{Width of the distribution} \\f$\n !!\n !! @author Nathan A. Wukie\n !! @date 2/1/2016\n !!\n !-------------------------------------------------------------------------------------\n type, extends(function_t), public :: scalar_adv_diff_bl_solution_f\n\n\n contains\n\n procedure :: init\n procedure :: compute\n\n end type scalar_adv_diff_bl_solution_f\n !*************************************************************************************\n\n\n\ncontains\n\n\n\n !>\n !!\n !! @author Nathan A. Wukie\n !! @date 2/2/2016\n !!\n !-------------------------------------------------------------------------\n subroutine init(self)\n class(scalar_adv_diff_bl_solution_f), intent(inout) :: self\n\n !\n ! Set function name\n !\n call self%set_name(\"scalar_adv_diff_bl_solution\")\n\n\n !\n ! Set function options to default settings\n !\n call self%add_option('mu',0.05_rk)\n call self%add_option('cx',1._rk)\n\n\n end subroutine init\n !*************************************************************************\n\n\n\n\n\n\n\n !>\n !!\n !! @author Nathan A. Wukie\n !! @date 2/2/2016\n !!\n !----------------------------------------------------------------------------------\n impure elemental function compute(self,time,coord) result(val)\n class(scalar_adv_diff_bl_solution_f), intent(inout) :: self\n real(rk), intent(in) :: time\n type(point_ad_t), intent(in) :: coord\n\n type(AD_D) :: val\n\n \n integer(ik) :: fcn_dim\n type(AD_D) :: x, y, z\n real(rk) :: mu, cx \n\n !\n ! Get inputs and function parameters\n !\n x = coord%c1_\n y = coord%c2_\n z = coord%c3_\n\n mu = self%get_option_value('mu')\n cx = self%get_option_value('cx')\n\n\n\n val = (ONE-exp((x-ONE)*(cx/mu)))/(ONE-exp(-cx/mu))\n end function compute\n !***********************************************************************************\n\n\nend module fcn_scalar_adv_diff_bl_solution\n", "meta": {"hexsha": "cb78be506860499812d5a261792fd8cd92b47e95", "size": 3118, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/functions/scalar_adv_diff_bl_solution/fcn_scalar_adv_diff_bl_solution.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/functions/scalar_adv_diff_bl_solution/fcn_scalar_adv_diff_bl_solution.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/functions/scalar_adv_diff_bl_solution/fcn_scalar_adv_diff_bl_solution.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": 26.2016806723, "max_line_length": 112, "alphanum_fraction": 0.4493264913, "num_tokens": 802, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900950352329, "lm_q2_score": 0.7154240018510026, "lm_q1q2_score": 0.6545420991983487}} {"text": " subroutine jacobi(a,v,n)\nc \nc***********************************************************************\nc \nc diagonalisation of real symmetric matices by jacobi method\nc \nc input parameters:\nc \nc a(n,n) is the matrix to be diagonalised\nc v(n,n) is the eigenvector matrix\nc n is the dimension of the matrices\nc \nc jacobi processes lower triangle only (upper triangle unchanged)\nc \nc variable rho sets absolute tolerance on convergence\nc variable tes is a moving tolerance that diminishes\nc on each pass until at true convergence tes1 and from power series when abs(z)<=1.\nC\nC In most complex variable computation, one must evaluate ele-\nC mentary functions. When the magnitude of Z is large, losses\nC of significance by argument reduction occur. Consequently, if\nC the magnitude of ZETA=(2/3)*Z**(3/2) exceeds U1=SQRT(0.5/UR),\nC then losses exceeding half precision are likely and an error\nC flag IERR=3 is triggered where UR=R1MACH(4)=UNIT ROUNDOFF.\nC Also, if the magnitude of ZETA is larger than U2=0.5/UR, then\nC all significance is lost and IERR=4. In order to use the INT\nC function, ZETA must be further restricted not to exceed\nC U3=I1MACH(9)=LARGEST INTEGER. Thus, the magnitude of ZETA\nC must be restricted by MIN(U2,U3). In IEEE arithmetic, U1,U2,\nC and U3 are approximately 2.0E+3, 4.2E+6, 2.1E+9 in single\nC precision and 4.7E+7, 2.3E+15, 2.1E+9 in double precision.\nC This makes U2 limiting is single precision and U3 limiting\nC in double precision. This means that the magnitude of Z\nC cannot exceed approximately 3.4E+4 in single precision and\nC 2.1E+6 in double precision. This also means that one can\nC expect to retain, in the worst cases on 32-bit machines,\nC no digits in single precision and only 6 digits in double\nC precision.\nC\nC The approximate relative error in the magnitude of a complex\nC Bessel function can be expressed as P*10**S where P=MAX(UNIT\nC ROUNDOFF,1.0E-18) is the nominal precision and 10**S repre-\nC sents the increase in error due to argument reduction in the\nC elementary functions. Here, S=MAX(1,ABS(LOG10(ABS(Z))),\nC ABS(LOG10(FNU))) approximately (i.e., S=MAX(1,ABS(EXPONENT OF\nC ABS(Z),ABS(EXPONENT OF FNU)) ). However, the phase angle may\nC have only absolute accuracy. This is most likely to occur\nC when one component (in magnitude) is larger than the other by\nC several orders of magnitude. If one component is 10**K larger\nC than the other, then one can expect only MAX(ABS(LOG10(P))-K,\nC 0) significant digits; or, stated another way, when K exceeds\nC the exponent of P, no significant digits remain in the smaller\nC component. However, the phase angle retains absolute accuracy\nC because, in complex arithmetic with precision P, the smaller\nC component will not (as a rule) decrease below P times the\nC magnitude of the larger component. In these extreme cases,\nC the principal phase angle is on the order of +P, -P, PI/2-P,\nC or -PI/2+P.\nC\nC***REFERENCES 1. M. Abramowitz and I. A. Stegun, Handbook of Mathe-\nC matical Functions, National Bureau of Standards\nC Applied Mathematics Series 55, U. S. Department\nC of Commerce, Tenth Printing (1972) or later.\nC 2. D. E. Amos, Computation of Bessel Functions of\nC Complex Argument and Large Order, Report SAND83-0643,\nC Sandia National Laboratories, Albuquerque, NM, May\nC 1983.\nC 3. D. E. Amos, A Subroutine Package for Bessel Functions\nC of a Complex Argument and Nonnegative Order, Report\nC SAND85-1018, Sandia National Laboratory, Albuquerque,\nC NM, May 1985.\nC 4. D. E. Amos, A portable package for Bessel functions\nC of a complex argument and nonnegative order, ACM\nC Transactions on Mathematical Software, 12 (September\nC 1986), pp. 265-273.\nC\nC***ROUTINES CALLED CBINU, I1MACH, R1MACH\nC***REVISION HISTORY (YYMMDD)\nC 830501 DATE WRITTEN\nC 890801 REVISION DATE from Version 3.2\nC 910415 Prologue converted to Version 4.0 format. (BAB)\nC 920128 Category corrected. (WRB)\nC 920811 Prologue revised. (DWL)\nC***END PROLOGUE CBIRY\n COMPLEX BI, CONE, CSQ, CY, S1, S2, TRM1, TRM2, Z, ZTA, Z3\n REAL AA, AD, AK, ALIM, ATRM, AZ, AZ3, BB, BK, CK, COEF, C1, C2,\n * DIG, DK, D1, D2, ELIM, FID, FMR, FNU, FNUL, PI, RL, R1M5, SFAC,\n * TOL, TTH, ZI, ZR, Z3I, Z3R, R1MACH\n INTEGER ID, IERR, K, KODE, K1, K2, NZ, I1MACH\n DIMENSION CY(2)\n DATA TTH, C1, C2, COEF, PI /6.66666666666666667E-01,\n * 6.14926627446000736E-01,4.48288357353826359E-01,\n * 5.77350269189625765E-01,3.14159265358979324E+00/\n DATA CONE / (1.0E0,0.0E0) /\nC***FIRST EXECUTABLE STATEMENT CBIRY\n IERR = 0\n NZ=0\n IF (ID.LT.0 .OR. ID.GT.1) IERR=1\n IF (KODE.LT.1 .OR. KODE.GT.2) IERR=1\n IF (IERR.NE.0) RETURN\n AZ = ABS(Z)\n TOL = MAX(R1MACH(4),1.0E-18)\n FID = ID\n IF (AZ.GT.1.0E0) GO TO 60\nC-----------------------------------------------------------------------\nC POWER SERIES FOR ABS(Z).LE.1.\nC-----------------------------------------------------------------------\n S1 = CONE\n S2 = CONE\n IF (AZ.LT.TOL) GO TO 110\n AA = AZ*AZ\n IF (AA.LT.TOL/AZ) GO TO 40\n TRM1 = CONE\n TRM2 = CONE\n ATRM = 1.0E0\n Z3 = Z*Z*Z\n AZ3 = AZ*AA\n AK = 2.0E0 + FID\n BK = 3.0E0 - FID - FID\n CK = 4.0E0 - FID\n DK = 3.0E0 + FID + FID\n D1 = AK*DK\n D2 = BK*CK\n AD = MIN(D1,D2)\n AK = 24.0E0 + 9.0E0*FID\n BK = 30.0E0 - 9.0E0*FID\n Z3R = REAL(Z3)\n Z3I = AIMAG(Z3)\n DO 30 K=1,25\n TRM1 = TRM1*CMPLX(Z3R/D1,Z3I/D1)\n S1 = S1 + TRM1\n TRM2 = TRM2*CMPLX(Z3R/D2,Z3I/D2)\n S2 = S2 + TRM2\n ATRM = ATRM*AZ3/AD\n D1 = D1 + AK\n D2 = D2 + BK\n AD = MIN(D1,D2)\n IF (ATRM.LT.TOL*AD) GO TO 40\n AK = AK + 18.0E0\n BK = BK + 18.0E0\n 30 CONTINUE\n 40 CONTINUE\n IF (ID.EQ.1) GO TO 50\n BI = S1*CMPLX(C1,0.0E0) + Z*S2*CMPLX(C2,0.0E0)\n IF (KODE.EQ.1) RETURN\n ZTA = Z*CSQRT(Z)*CMPLX(TTH,0.0E0)\n AA = REAL(ZTA)\n AA = -ABS(AA)\n BI = BI*CMPLX(EXP(AA),0.0E0)\n RETURN\n 50 CONTINUE\n BI = S2*CMPLX(C2,0.0E0)\n IF (AZ.GT.TOL) BI = BI + Z*Z*S1*CMPLX(C1/(1.0E0+FID),0.0E0)\n IF (KODE.EQ.1) RETURN\n ZTA = Z*CSQRT(Z)*CMPLX(TTH,0.0E0)\n AA = REAL(ZTA)\n AA = -ABS(AA)\n BI = BI*CMPLX(EXP(AA),0.0E0)\n RETURN\nC-----------------------------------------------------------------------\nC CASE FOR ABS(Z).GT.1.0\nC-----------------------------------------------------------------------\n 60 CONTINUE\n FNU = (1.0E0+FID)/3.0E0\nC-----------------------------------------------------------------------\nC SET PARAMETERS RELATED TO MACHINE CONSTANTS.\nC TOL IS THE APPROXIMATE UNIT ROUNDOFF LIMITED TO 1.0E-18.\nC ELIM IS THE APPROXIMATE EXPONENTIAL OVER- AND UNDERFLOW LIMIT.\nC EXP(-ELIM).LT.EXP(-ALIM)=EXP(-ELIM)/TOL AND\nC EXP(ELIM).GT.EXP(ALIM)=EXP(ELIM)*TOL ARE INTERVALS NEAR\nC UNDERFLOW AND OVERFLOW LIMITS WHERE SCALED ARITHMETIC IS DONE.\nC RL IS THE LOWER BOUNDARY OF THE ASYMPTOTIC EXPANSION FOR LARGE Z.\nC DIG = NUMBER OF BASE 10 DIGITS IN TOL = 10**(-DIG).\nC FNUL IS THE LOWER BOUNDARY OF THE ASYMPTOTIC SERIES FOR LARGE FNU.\nC-----------------------------------------------------------------------\n K1 = I1MACH(12)\n K2 = I1MACH(13)\n R1M5 = R1MACH(5)\n K = MIN(ABS(K1),ABS(K2))\n ELIM = 2.303E0*(K*R1M5-3.0E0)\n K1 = I1MACH(11) - 1\n AA = R1M5*K1\n DIG = MIN(AA,18.0E0)\n AA = AA*2.303E0\n ALIM = ELIM + MAX(-AA,-41.45E0)\n RL = 1.2E0*DIG + 3.0E0\n FNUL = 10.0E0 + 6.0E0*(DIG-3.0E0)\nC-----------------------------------------------------------------------\nC TEST FOR RANGE\nC-----------------------------------------------------------------------\n AA=0.5E0/TOL\n BB=I1MACH(9)*0.5E0\n AA=MIN(AA,BB)\n AA=AA**TTH\n IF (AZ.GT.AA) GO TO 190\n AA=SQRT(AA)\n IF (AZ.GT.AA) IERR=3\n CSQ=CSQRT(Z)\n ZTA=Z*CSQ*CMPLX(TTH,0.0E0)\nC-----------------------------------------------------------------------\nC RE(ZTA).LE.0 WHEN RE(Z).LT.0, ESPECIALLY WHEN IM(Z) IS SMALL\nC-----------------------------------------------------------------------\n SFAC = 1.0E0\n ZI = AIMAG(Z)\n ZR = REAL(Z)\n AK = AIMAG(ZTA)\n IF (ZR.GE.0.0E0) GO TO 70\n BK = REAL(ZTA)\n CK = -ABS(BK)\n ZTA = CMPLX(CK,AK)\n 70 CONTINUE\n IF (ZI.EQ.0.0E0 .AND. ZR.LE.0.0E0) ZTA = CMPLX(0.0E0,AK)\n AA = REAL(ZTA)\n IF (KODE.EQ.2) GO TO 80\nC-----------------------------------------------------------------------\nC OVERFLOW TEST\nC-----------------------------------------------------------------------\n BB = ABS(AA)\n IF (BB.LT.ALIM) GO TO 80\n BB = BB + 0.25E0*ALOG(AZ)\n SFAC = TOL\n IF (BB.GT.ELIM) GO TO 170\n 80 CONTINUE\n FMR = 0.0E0\n IF (AA.GE.0.0E0 .AND. ZR.GT.0.0E0) GO TO 90\n FMR = PI\n IF (ZI.LT.0.0E0) FMR = -PI\n ZTA = -ZTA\n 90 CONTINUE\nC-----------------------------------------------------------------------\nC AA=FACTOR FOR ANALYTIC CONTINUATION OF I(FNU,ZTA)\nC KODE=2 RETURNS EXP(-ABS(XZTA))*I(FNU,ZTA) FROM CBINU\nC-----------------------------------------------------------------------\n CALL CBINU(ZTA, FNU, KODE, 1, CY, NZ, RL, FNUL, TOL, ELIM, ALIM)\n IF (NZ.LT.0) GO TO 180\n AA = FMR*FNU\n Z3 = CMPLX(SFAC,0.0E0)\n S1 = CY(1)*CMPLX(COS(AA),SIN(AA))*Z3\n FNU = (2.0E0-FID)/3.0E0\n CALL CBINU(ZTA, FNU, KODE, 2, CY, NZ, RL, FNUL, TOL, ELIM, ALIM)\n CY(1) = CY(1)*Z3\n CY(2) = CY(2)*Z3\nC-----------------------------------------------------------------------\nC BACKWARD RECUR ONE STEP FOR ORDERS -1/3 OR -2/3\nC-----------------------------------------------------------------------\n S2 = CY(1)*CMPLX(FNU+FNU,0.0E0)/ZTA + CY(2)\n AA = FMR*(FNU-1.0E0)\n S1 = (S1+S2*CMPLX(COS(AA),SIN(AA)))*CMPLX(COEF,0.0E0)\n IF (ID.EQ.1) GO TO 100\n S1 = CSQ*S1\n BI = S1*CMPLX(1.0E0/SFAC,0.0E0)\n RETURN\n 100 CONTINUE\n S1 = Z*S1\n BI = S1*CMPLX(1.0E0/SFAC,0.0E0)\n RETURN\n 110 CONTINUE\n AA = C1*(1.0E0-FID) + FID*C2\n BI = CMPLX(AA,0.0E0)\n RETURN\n 170 CONTINUE\n NZ=0\n IERR=2\n RETURN\n 180 CONTINUE\n IF(NZ.EQ.(-1)) GO TO 170\n NZ=0\n IERR=5\n RETURN\n 190 CONTINUE\n IERR=4\n NZ=0\n RETURN\n END\n", "meta": {"hexsha": "7ab03bb9a65a2a2a8a75454aaab93678d53fe37f", "size": 13007, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/cbiry.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/cbiry.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-03-30T12:46:26.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:29:11.000Z", "max_forks_repo_path": "slatec/src/cbiry.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.646875, "max_line_length": 72, "alphanum_fraction": 0.5181825171, "num_tokens": 4376, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.867035752930664, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6545382888182312}} {"text": "! .................................................\r\n! ____ _ _ ____ _____ _ \r\n! | _ \\| | |_| | _ \\| ___| |_| \r\n! | |_) | |___ _ | |_) | |___ _ \r\n! | _ /| _ | | | | _ /|___ | | | \r\n! | | | | | | | | | | ___| | | | \r\n! |_| |_| |_| |_| |_| |_____| |_| \r\n! .................................................\r\n! PhiPsi: a general-purpose computational \r\n! mechanics program written in Fortran.\r\n! Website: http://phipsi.top \r\n! Author: Shi Fang from Huaiyin Institute of \r\n! Technology, HuaiAn, JiangSu, China \r\n! Contact me: shifang@hyit.edu.cn \r\n! ------------------------------------------------ \r\n! Please cite the following papers: \r\n! (1)Shi F, Wang X L, Liu C, Liu H, Wu H A. An \r\n! XFEM-based method with reduction technique \r\n! for modeling hydraulic fracture propagation \r\n! in formations containing frictional natural \r\n! fractures. Engineering Fracture Mechanics, \r\n! 2017, 173: 64-90. \r\n! (2)Shi F, Wang X L, Liu C, Liu H, Wu H A. A \r\n! coupled extended finite element approach \r\n! for modeling hydraulic fracturing in \r\n! consideration of proppant. Journal of \r\n! Natural Gas Science and Engineering, 2016, \r\n! 33: 885-897. \r\n! (3)Shi F, Wang X L, Liu C, Liu H, Wu H A. An \r\n! XFEM-based numerical model to calculate \r\n! conductivity of propped fracture considering \r\n! proppant transport, embedment and crushing. \r\n! Journal of Petroleum Science and Engineering, \r\n! 2018, 167: 615-626.. \r\n \r\n subroutine Tool_Cal_Intersection(A,B,C,D,X,Y,Yes_Cross)\r\nC get intersection point of two line segments\r\n\r\nc A: Coordinates of point A of line segment AB;\r\nc B: Coordinates of point B of line segment AB;\r\nc C: Coordinates of point C of line segment CD;\r\nc D: Coordinates of point D of line segment CD.\r\n\r\n use Global_Elem_Area\r\n \r\n implicit none\r\n double precision,intent(in)::A(2),B(2),C(2),D(2)\r\n double precision,intent(out)::X,Y\r\n logical,intent(out)::Yes_Cross\r\n \r\n double precision L_AB,L_CD,tem,k2,k1,b1,b2\r\n double precision L_AX,L_BX,L_CX,L_DX\r\n logical Yes_in_AB,Yes_in_CD\r\n double precision minX_AB,maxX_AB,minY_AB,maxY_AB,\r\n & minX_CD,maxX_CD,minY_CD,maxY_CD\r\n \r\nc The length of AB.\r\n L_AB = sqrt((A(1)-B(1))**2+(A(2)-B(2))**2)\r\nc The length of CD.\r\n L_CD = sqrt((C(1)-D(1))**2+(C(2)-D(2))**2)\r\n \r\n if (A(1).eq.B(1)) then\r\n X=A(1)\r\n tem = D(1)-C(1)\r\n k2=(D(2)-C(2))/tem\r\n b2=C(2)-k2*C(1) \r\n Y=k2*X+b2;\r\n end if\r\n\r\n if (C(1).eq.D(1)) then\r\n X=C(1)\r\n tem =B(1)-A(1)\r\n k1=(B(2)-A(2))/tem\r\n b1=A(2)-k1*A(1)\r\n Y=k1*X+b1\r\n end if\r\n\r\n if ((A(1).ne.B(1)) .and. (C(1).ne.D(1))) then\r\n k1=(B(2)-A(2))/(B(1)-A(1))\r\n k2=(D(2)-C(2))/(D(1)-C(1))\r\n b1=A(2)-k1*A(1)\r\n b2=C(2)-k2*C(1)\r\n if (k1.eq.k2) then\r\n X=1.0D9\r\n Y=1.0D9\r\n else\r\n X=(b2-b1)/(k1-k2)\r\n Y=k1*X+b1\r\n end if\r\n end if\r\n\r\n minX_AB = min(A(1),B(1))\r\n maxX_AB = max(A(1),B(1))\r\n minY_AB = min(A(2),B(2))\r\n maxY_AB = max(A(2),B(2))\r\n minX_CD = min(C(1),D(1))\r\n maxX_CD = max(C(1),D(1))\r\n minY_CD = min(C(2),D(2))\r\n maxY_CD = max(C(2),D(2))\r\n\r\n Yes_Cross = .False.\r\n Yes_in_AB = .False.\r\n Yes_in_CD = .False.\r\n\r\nc Check if (X,Y) is in AB.\r\nc The length of AX.\r\n L_AX = sqrt((A(1)-X)**2+(A(2)-Y)**2)\r\nc The length of BX.\r\n L_BX = sqrt((B(1)-X)**2+(B(2)-Y)**2)\r\n if (((L_AX + L_BX)-L_AB) .le. 1.0D-6*sqrt(Ave_Elem_Area)) then\r\n Yes_in_AB = .True.\r\n end if\r\n\r\n\r\nc Check if (X,Y) is in CD.\r\nc The length of CX.\r\n L_CX = sqrt((C(1)-X)**2+(C(2)-Y)**2)\r\nc The length of DX.\r\n L_DX = sqrt((D(1)-X)**2+(D(2)-Y)**2)\r\n if (((L_CX + L_DX) - L_CD) .le. 1.0D-6*sqrt(Ave_Elem_Area)) then\r\n Yes_in_CD = .True.\r\n end if\r\n\r\nc if (X,Y) is in both AB and CD, then YesCross = 1.\r\n if ((Yes_in_AB .eqv..True.).and.(Yes_in_CD.eqv..True.)) then \r\n Yes_Cross = .True.\r\n else\r\n Yes_Cross = .False.\r\n end if\r\n \r\n return \r\n end SUBROUTINE Tool_Cal_Intersection \r\n", "meta": {"hexsha": "8cdcb7d5199854fe017600c80effbda7677ca590", "size": 4807, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Tool_Cal_Intersection.f", "max_stars_repo_name": "PhiPsi-Software/PhiPsi_XFEM_Fortran_Codes_Early_Version", "max_stars_repo_head_hexsha": "1eae63a8f0dc968b9d5220397879645a83e5d083", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-04-15T11:56:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-14T11:49:59.000Z", "max_issues_repo_path": "Tool_Cal_Intersection.f", "max_issues_repo_name": "PhiPsi-Software/PhiPsi_XFEM_Fortran_Codes_Early_Version", "max_issues_repo_head_hexsha": "1eae63a8f0dc968b9d5220397879645a83e5d083", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Tool_Cal_Intersection.f", "max_forks_repo_name": "PhiPsi-Software/PhiPsi_XFEM_Fortran_Codes_Early_Version", "max_forks_repo_head_hexsha": "1eae63a8f0dc968b9d5220397879645a83e5d083", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2019-01-20T00:55:09.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T00:30:28.000Z", "avg_line_length": 36.1428571429, "max_line_length": 71, "alphanum_fraction": 0.4464322862, "num_tokens": 1473, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699435, "lm_q2_score": 0.7279754489059774, "lm_q1q2_score": 0.6545382882390478}} {"text": "c subroutine lfim (init,theta,l,n,nm,pb,id,wlfim)\nc\nc dimension of theta(l), pb(id,nm+1), wlfim(4*l*(nm+1))\nc arguments\nc\nc purpose given n and l, routine lfim calculates\nc the normalized associated legendre functions\nc pbar(n,m,theta) for m=0,...,n and theta(i)\nc for i=1,...,l where\nc\nc pbar(m,n,theta) = sqrt((2*n+1)*factorial(n-m)\nc /(2*factorial(n+m)))*sin(theta)**m/(2**n*\nc factorial(n)) times the (n+m)th derivative of\nc (x**2-1)**n with respect to x=cos(theta)\nc\nc usage call lfim (init,theta,l,n,nm,pb,id,wlfim)\nc\nc arguments\nc on input init\nc = 0\nc initialization only - using parameters\nc l, nm and array theta, subroutine lfim\nc initializes array wlfim for subsequent\nc use in the computation of the associated\nc legendre functions pb. initialization\nc does not have to be repeated unless\nc l, nm, or array theta are changed.\nc = 1\nc subroutine lfim uses the array wlfim that\nc was computed with init = 0 to compute pb.\nc\nc theta\nc an array that contains the colatitudes\nc at which the associated legendre functions\nc will be computed. the colatitudes must be\nc specified in radians.\nc\nc l\nc the length of the theta array. lfim is\nc vectorized with vector length l.\nc\nc n\nc nonnegative integer, less than nm, specifying\nc degree of pbar(n,m,theta). subroutine lfim\nc must be called starting with n=0. n must be\nc incremented by one in subsequent calls and\nc must not exceed nm.\nc\nc nm\nc the maximum value of n and m\nc\nc id\nc the first dimension of the two dimensional\nc array pb as it appears in the program that\nc calls lfim. (see output parameter pb)\nc\nc wlfim\nc an array with length 4*l*(nm+1) which\nc must be initialized by calling lfim\nc with init=0 (see parameter init) it\nc must not be altered between calls to\nc lfim.\nc\nc\nc on output pb\nc a two dimensional array with first\nc dimension id in the program that calls\nc lfim. the second dimension of pb must\nc be at least nm+1. starting with n=0\nc lfim is called repeatedly with n being\nc increased by one between calls. on each\nc call, subroutine lfim computes\nc = pbar(m,n,theta(i)) for m=0,...,n and\nc i=1,...l.\nc\nc wlfim\nc array containing values which must not\nc be altered unless l, nm or the array theta\nc are changed in which case lfim must be\nc called with init=0 to reinitialize the\nc wlfim array.\nc\nc special conditions n must be increased by one between calls\nc of lfim in which n is not zero.\nc\nc precision single\nc\nc\nc algorithm routine lfim calculates pbar(n,m,theta) using\nc a four term recurrence relation. (unpublished\nc notes by paul n. swarztrauber)\nc\n subroutine lfim (init,theta,l,n,nm,pb,id,wlfim)\n dimension pb(1) ,wlfim(1)\nc\nc total length of wlfim is 4*l*(nm+1)\nc\n lnx = l*(nm+1)\n iw1 = lnx+1\n iw2 = iw1+lnx\n iw3 = iw2+lnx\n call lfim1(init,theta,l,n,nm,id,pb,wlfim,wlfim(iw1),\n 1 wlfim(iw2),wlfim(iw3),wlfim(iw2))\n return\n end\n subroutine lfim1(init,theta,l,n,nm,id,p3,phz,ph1,p1,p2,cp)\n dimension p1(l,1) ,p2(l,1) ,p3(id,1) ,phz(l,1) ,\n 1 ph1(l,1) ,cp(1) ,theta(1)\n nmp1 = nm+1\n if(init .ne. 0) go to 5\n ssqrt2 = 1./sqrt(2.)\n do 10 i=1,l\n phz(i,1) = ssqrt2\n 10 continue\n do 15 np1=2,nmp1\n nh = np1-1\n call alfk(nh,0,cp)\n do 16 i=1,l\n call lfpt(nh,0,theta(i),cp,phz(i,np1))\n 16 continue\n call alfk(nh,1,cp)\n do 17 i=1,l\n call lfpt(nh,1,theta(i),cp,ph1(i,np1))\n 17 continue\n 15 continue\n return\n 5 if(n .gt. 2) go to 60\n if(n-1)25,30,35\n 25 do 45 i=1,l\n p3(i,1)=phz(i,1)\n 45 continue\n return\n 30 do 50 i=1,l\n p3(i,1) = phz(i,2)\n p3(i,2) = ph1(i,2)\n 50 continue\n return\n 35 sq5s6 = sqrt(5./6.)\n sq1s6 = sqrt(1./6.)\n do 55 i=1,l\n p3(i,1) = phz(i,3)\n p3(i,2) = ph1(i,3)\n p3(i,3) = sq5s6*phz(i,1)-sq1s6*p3(i,1)\n p1(i,1) = phz(i,2)\n p1(i,2) = ph1(i,2)\n p2(i,1) = phz(i,3)\n p2(i,2) = ph1(i,3)\n p2(i,3) = p3(i,3)\n 55 continue\n return\n 60 nm1 = n-1\n np1 = n+1\n fn = float(n)\n tn = fn+fn\n cn = (tn+1.)/(tn-3.)\n do 65 i=1,l\n p3(i,1) = phz(i,np1)\n p3(i,2) = ph1(i,np1)\n 65 continue\n if(nm1 .lt. 3) go to 71\n do 70 mp1=3,nm1\n m = mp1-1\n fm = float(m)\n fnpm = fn+fm\n fnmm = fn-fm\n temp = fnpm*(fnpm-1.)\n cc = sqrt(cn*(fnpm-3.)*(fnpm-2.)/temp)\n dd = sqrt(cn*fnmm*(fnmm-1.)/temp)\n ee = sqrt((fnmm+1.)*(fnmm+2.)/temp)\n do 70 i=1,l\n p3(i,mp1) = cc*p1(i,mp1-2)+dd*p1(i,mp1)-ee*p3(i,mp1-2)\n 70 continue\n 71 fnpm = fn+fn-1.\n temp = fnpm*(fnpm-1.)\n cc = sqrt(cn*(fnpm-3.)*(fnpm-2.)/temp)\n ee = sqrt(6./temp)\n do 75 i=1,l\n p3(i,n) = cc*p1(i,n-2)-ee*p3(i,n-2)\n 75 continue\n fnpm = fn+fn\n temp = fnpm*(fnpm-1.)\n cc = sqrt(cn*(fnpm-3.)*(fnpm-2.)/temp)\n ee = sqrt(2./temp)\n do 80 i=1,l\n p3(i,n+1) = cc*p1(i,n-1)-ee*p3(i,n-1)\n 80 continue\n do 90 mp1=1,np1\n do 90 i=1,l\n p1(i,mp1) = p2(i,mp1)\n p2(i,mp1) = p3(i,mp1)\n 90 continue\n return\n end\n", "meta": {"hexsha": "cae6b0581cbff5bfc87e289e2471e69f2c42fc0f", "size": 6744, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/lfim.f", "max_stars_repo_name": "jprules321/colas", "max_stars_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/lfim.f", "max_issues_repo_name": "jprules321/colas", "max_issues_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "wgrib2-v0.1.9.4/extensions/shfilt/spherepak/lfim.f", "max_forks_repo_name": "jprules321/colas", "max_forks_repo_head_hexsha": "2757d5c077c3306d510488a0134ac4120e2d3fa0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.7628865979, "max_line_length": 72, "alphanum_fraction": 0.4620403321, "num_tokens": 2031, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213691605412, "lm_q2_score": 0.7279754548076478, "lm_q1q2_score": 0.65453828764192}} {"text": "\n\n subroutine get_a_not_hex(xc,anot)\n\n include \"common.h\"\n\n dimension xc(npro,nenl,nsd), anot(npro,nenl,nsd)\n\n\n do i = 1, nsd\n\n anot(:,1,i) = pt125*(xc(:,1,i)+xc(:,2,i)+xc(:,3,i)+xc(:,4,i)\n & +xc(:,5,i)+xc(:,6,i)+xc(:,7,i)+xc(:,8,i))\n \n anot(:,2,i) = pt125*(-xc(:,1,i)+xc(:,2,i)+xc(:,3,i)-xc(:,4,i)\n & -xc(:,5,i)+xc(:,6,i)+xc(:,7,i)-xc(:,8,i))\n\n anot(:,3,i) = pt125*(-xc(:,1,i)-xc(:,2,i)+xc(:,3,i)+xc(:,4,i)\n & -xc(:,5,i)-xc(:,6,i)+xc(:,7,i)+xc(:,8,i))\n \n anot(:,4,i) = pt125*(-xc(:,1,i)-xc(:,2,i)-xc(:,3,i)-xc(:,4,i)\n & +xc(:,5,i)+xc(:,6,i)+xc(:,7,i)+xc(:,8,i))\n\n anot(:,5,i) = pt125*(xc(:,1,i)-xc(:,2,i)+xc(:,3,i)-xc(:,4,i)\n & +xc(:,5,i)-xc(:,6,i)+xc(:,7,i)-xc(:,8,i))\n\n anot(:,6,i) = pt125*(xc(:,1,i)+xc(:,2,i)-xc(:,3,i)-xc(:,4,i)\n & -xc(:,5,i)-xc(:,6,i)+xc(:,7,i)+xc(:,8,i))\n\n anot(:,7,i) = pt125*(xc(:,1,i)-xc(:,2,i)-xc(:,3,i)+xc(:,4,i)\n & -xc(:,5,i)+xc(:,6,i)+xc(:,7,i)-xc(:,8,i))\n\n anot(:,8,i) = pt125*(-xc(:,1,i)+xc(:,2,i)-xc(:,3,i)+xc(:,4,i)\n & +xc(:,5,i)-xc(:,6,i)+xc(:,7,i)-xc(:,8,i))\n\n enddo\n\n return\n end\n\n\n subroutine get_a_not_tet(xc,anot)\n\n include \"common.h\"\n\n dimension xc(npro,nenl,nsd), anot(npro,nenl,nsd)\n\n\n do i = 1, nsd\n\n anot(:,1,i) = xc(:,4,i)\n anot(:,2,i) = xc(:,1,i)-xc(:,4,i)\n anot(:,3,i) = xc(:,2,i)-xc(:,4,i)\n anot(:,4,i) = xc(:,3,i)-xc(:,4,i)\n \n enddo\n \n return\n end\n \n", "meta": {"hexsha": "6029751617d0de3285a6df6cacf8728ba7b1d8f4", "size": 1589, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "phSolver/common/get_a_not_hex.f", "max_stars_repo_name": "yangf4/phasta", "max_stars_repo_head_hexsha": "a096094f33b98047de0a2e28225c4d74875a88d8", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 49, "max_stars_repo_stars_event_min_datetime": "2015-04-16T13:45:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-07T01:02:49.000Z", "max_issues_repo_path": "phSolver/common/get_a_not_hex.f", "max_issues_repo_name": "yangf4/phasta", "max_issues_repo_head_hexsha": "a096094f33b98047de0a2e28225c4d74875a88d8", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 21, "max_issues_repo_issues_event_min_datetime": "2015-10-06T19:50:43.000Z", "max_issues_repo_issues_event_max_datetime": "2017-12-17T03:47:51.000Z", "max_forks_repo_path": "phSolver/common/get_a_not_hex.f", "max_forks_repo_name": "yangf4/phasta", "max_forks_repo_head_hexsha": "a096094f33b98047de0a2e28225c4d74875a88d8", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 38, "max_forks_repo_forks_event_min_datetime": "2015-04-21T12:13:40.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-12T19:38:00.000Z", "avg_line_length": 26.0491803279, "max_line_length": 70, "alphanum_fraction": 0.3763373191, "num_tokens": 634, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213691605412, "lm_q2_score": 0.7279754548076477, "lm_q1q2_score": 0.6545382876419199}} {"text": "submodule(gas_interface) gas_implementation\n use assertions_interface, only : assert, max_errmsg_len\n use kind_parameters, only : rkind\n implicit none\n\ncontains\n\n module procedure define\n real(rkind) :: c_p_, MW_\n namelist/gas_list/ c_p_, MW_\n\n block\n character(len=max_errmsg_len) error_message\n integer :: io_status, file_unit\n integer, parameter :: success = 0\n open(newunit=file_unit, file=input_file, status=\"old\", iostat=io_status, iomsg=error_message)\n call assert(io_status == success, \"gas%define: io_status == success\", diagnostic_data=error_message)\n read(file_unit, nml=gas_list)\n close(file_unit)\n end block\n\n this%c_p_ = c_p_\n this%MW_ = MW_\n end procedure\n\n module procedure T\n T = energy/(this%c_v()*mass)\n end procedure\n\n module procedure R_gas\n real(rkind), parameter :: R_universal = 8314._rkind ! 8.31446261815324_rkind\n R_gas = R_universal/this%MW_\n end procedure\n\n module procedure c_v\n c_v = this%c_p_ - this%R_gas()\n end procedure\n\n module procedure g\n g = this%c_p_/this%c_v()\n end procedure\n\n module procedure c_p\n c_p = this%c_p_\n end procedure\n\n module procedure p\n associate(M => (mass), R_gas => this%R_gas(), T => energy/(mass*this%c_v()), V => (volume))\n p = M*R_gas*T/V\n end associate\n end procedure\n\nend submodule gas_implementation\n", "meta": {"hexsha": "4c2587b868ebd9a0d4112fd10da9e31321436c4c", "size": 1366, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/rocket/gas_implementation.f90", "max_stars_repo_name": "sourceryinstitute/rocket-science", "max_stars_repo_head_hexsha": "92c79b1008db7a715770e098db0dbda6a6062d54", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-09-23T15:09:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-24T05:50:57.000Z", "max_issues_repo_path": "src/rocket/gas_implementation.f90", "max_issues_repo_name": "sourceryinstitute/rocket-science", "max_issues_repo_head_hexsha": "92c79b1008db7a715770e098db0dbda6a6062d54", "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/rocket/gas_implementation.f90", "max_forks_repo_name": "sourceryinstitute/rocket-science", "max_forks_repo_head_hexsha": "92c79b1008db7a715770e098db0dbda6a6062d54", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2021-03-04T14:17:20.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-21T17:35:44.000Z", "avg_line_length": 25.2962962963, "max_line_length": 106, "alphanum_fraction": 0.6954612006, "num_tokens": 385, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357460591568, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6545382836308273}} {"text": " subroutine evol_alphakd(n_K,n_alpha,np1_K,np1_alpha,x,Nx,ck,epsal,\n &ht,myzero,phys_bdy,res)\n implicit none\n integer i\n integer Nx\n real*8 ck\n real*8 epsal\n real*8 ht\n real*8 myzero\n real*8 n_K(Nx)\n real*8 n_alpha(Nx)\n real*8 np1_K(Nx)\n real*8 np1_alpha(Nx)\n real*8 x(Nx)\n integer phys_bdy(2)\n real*8 res(Nx)\n real*8 qb\n if (phys_bdy(1) .eq. 1) then\n do i=1, 1, 1\n qb = np1_alpha(i) - 0.1D1 * ht * ((-0.1D1 * n_alpha(i) + np1_alpha\n #(i)) / ht + epsal * (-0.1D1 * n_K(i) + np1_K(i)) / ht + 0.50000000\n #00000000D0 * epsal * ck * np1_K(i) + 0.5000000000000000D0 * epsal \n #* ck * n_K(i))\n res(i)=qb\n end do\n endif\n do i=2, Nx-1, 1\n qb = np1_alpha(i) - 0.1D1 * ht * ((-0.1D1 * n_alpha(i) + np1_alpha\n #(i)) / ht + epsal * (-0.1D1 * n_K(i) + np1_K(i)) / ht + 0.50000000\n #00000000D0 * epsal * ck * np1_K(i) + 0.5000000000000000D0 * epsal \n #* ck * n_K(i))\n res(i)=qb\n end do\n if (phys_bdy(2) .eq. 1) then\n do i=Nx, Nx, 1\n qb = -0.1D1 * myzero * x(i) + 0.1D1\n res(i)=qb\n end do\n endif\n END\n", "meta": {"hexsha": "b5e14f98603054dec0b9aceca7fd595c97fa3057", "size": 1180, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/FD/evol_alphakd.f", "max_stars_repo_name": "rmanak/bssn_spher", "max_stars_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/FD/evol_alphakd.f", "max_issues_repo_name": "rmanak/bssn_spher", "max_issues_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/FD/evol_alphakd.f", "max_forks_repo_name": "rmanak/bssn_spher", "max_forks_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.7804878049, "max_line_length": 72, "alphanum_fraction": 0.5118644068, "num_tokens": 508, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357494949105, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6545382814437145}} {"text": " SUBROUTINE MB03DZ( A, LDA, B, LDB, CO1, SI1, CO2, SI2 )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute unitary matrices Q1 and Q2 for a complex 2-by-2 regular\nC pencil aA - bB with A, B upper triangular, such that\nC Q2' (aA - bB) Q1 is still upper triangular but the eigenvalues are\nC in reversed order. The matrices Q1 and Q2 are represented by\nC\nC ( CO1 SI1 ) ( CO2 SI2 )\nC Q1 = ( ), Q2 = ( ).\nC ( -SI1' CO1 ) ( -SI2' CO2 )\nC\nC The notation M' denotes the conjugate transpose of the matrix M.\nC\nC ARGUMENTS\nC\nC Input/Output Parameters\nC\nC A (input) COMPLEX*16 array, dimension (LDA, 2)\nC On entry, the leading 2-by-2 upper triangular part of\nC this array must contain the matrix A of the pencil.\nC The (2,1) entry is not referenced.\nC\nC LDA INTEGER\nC The leading dimension of the array A. LDA >= 2.\nC\nC B (input) COMPLEX*16 array, dimension (LDB, 2)\nC On entry, the leading 2-by-2 upper triangular part of\nC this array must contain the matrix B of the pencil.\nC The (2,1) entry is not referenced.\nC\nC LDB INTEGER\nC The leading dimension of the array B. LDB >= 2.\nC\nC CO1 (output) DOUBLE PRECISION\nC The upper left element of the unitary matrix Q1.\nC\nC SI1 (output) COMPLEX*16\nC The upper right element of the unitary matrix Q1.\nC\nC CO2 (output) DOUBLE PRECISION\nC The upper left element of the unitary matrix Q2.\nC\nC SI2 (output) COMPLEX*16\nC The upper right element of the unitary matrix Q2.\nC\nC METHOD\nC\nC The algorithm uses unitary transformations as described on page 42\nC in [1].\nC\nC REFERENCES\nC\nC [1] Benner, P., Byers, R., Mehrmann, V. and Xu, H.\nC Numerical Computation of Deflating Subspaces of Embedded\nC Hamiltonian Pencils.\nC Tech. Rep. SFB393/99-15, Technical University Chemnitz,\nC Germany, June 1999.\nC\nC NUMERICAL ASPECTS\nC\nC The algorithm is numerically backward stable.\nC\nC CONTRIBUTOR\nC\nC Matthias Voigt, Fakultaet fuer Mathematik, Technische Universitaet\nC Chemnitz, January 26, 2009.\nC\nC REVISIONS\nC\nC V. Sima, Aug. 2009 (SLICOT version of the routine ZBTUEX).\nC V. Sima, Nov. 2009, Nov. 2010, Dec. 2010.\nC M. Voigt, Jan. 2012. \nC\nC KEYWORDS\nC\nC Eigenvalue exchange, matrix pencil, upper triangular matrix.\nC\nC ******************************************************************\nC\nC .. Scalar Arguments ..\n INTEGER LDA, LDB\n DOUBLE PRECISION CO1, CO2\n COMPLEX*16 SI1, SI2\nC\nC .. Array Arguments ..\n COMPLEX*16 A( LDA, * ), B( LDB, * )\nC\nC .. Local Scalars ..\n COMPLEX*16 D, G, TMP\nC\nC .. External Subroutines ..\n EXTERNAL ZLARTG\nC\nC .. Executable Statements ..\nC\nC For efficiency, the input arguments are not tested.\nC\nC Computations.\nC\n G = A( 1, 1 )*B( 2, 2 ) - A( 2, 2 )*B( 1, 1 )\n D = A( 1, 2 )*B( 2, 2 ) - A( 2, 2 )*B( 1, 2 )\n CALL ZLARTG( D, G, CO1, SI1, TMP )\n D = A( 1, 2 )*B( 1, 1 ) - A( 1, 1 )*B( 1, 2 )\n CALL ZLARTG( D, G, CO2, SI2, TMP )\nC\n RETURN\nC *** Last line of MB03DZ ***\n END\n", "meta": {"hexsha": "503477bd7b7805e666601886d44322fe25ee664d", "size": 3427, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB03DZ.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB03DZ.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB03DZ.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 29.8, "max_line_length": 72, "alphanum_fraction": 0.5716370003, "num_tokens": 1130, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8991213745668094, "lm_q2_score": 0.7279754430043072, "lm_q1q2_score": 0.6545382809649146}} {"text": "c program DRSRANUS\nc>> 1995-10-23 DRSRANUS Krogh Reduced N to work on PC in D.P.\nc>> 1994-10-19 DRSRANUS Krogh Changes to use M77CON\nc>> 1992-03-13 DRSRANUS CLL\nc\nc Driver to demonstrate use of SRANUS to generate random numbers\nc from the uniform distribution between A and A+B.\nc Program computes histogram for N numbers\nc ------------------------------------------------------------------\nc--S replaces \"?\": DR?RANUS, ?RANUS, ?STAT1, ?STAT2\nc ------------------------------------------------------------------\n integer N, NCELLS\n parameter(N = 8000, NCELLS = 10+2)\n real A, B, STATS(5), YTAB(N)\n integer IHIST(NCELLS)\n data A, B / 20.0e0, 10.0e0/\nc ------------------------------------------------------------------\n STATS(1) = 0.0e0\nc Get array of scaled random numbers.\nc\n call SRANUS(YTAB, N, A, B)\nc\nc Compute statistics and histogram.\nc\n call SSTAT1(YTAB, N, STATS, IHIST, NCELLS, A, A+B)\nc\nc Print the statistics and histogram.\nc\n write(*,'(13x,a//)') 'Uniform random numbers from SRANUS'\n call SSTAT2(STATS, IHIST, NCELLS, A, A+B)\n end\n", "meta": {"hexsha": "2479dfd8e5cf3df3b6a216055c01b0a6879725a5", "size": 1219, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drsranus.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drsranus.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drsranus.f", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 38.09375, "max_line_length": 72, "alphanum_fraction": 0.4938474159, "num_tokens": 348, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357460591569, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.654538274069198}} {"text": " SUBROUTINE MB02YD( COND, N, R, LDR, IPVT, DIAG, QTB, RANK, X, TOL,\n $ DWORK, LDWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To determine a vector x which solves the system of linear\nC equations\nC\nC A*x = b , D*x = 0 ,\nC\nC in the least squares sense, where A is an m-by-n matrix,\nC D is an n-by-n diagonal matrix, and b is an m-vector.\nC It is assumed that a QR factorization, with column pivoting, of A\nC is available, that is, A*P = Q*R, where P is a permutation matrix,\nC Q has orthogonal columns, and R is an upper triangular matrix\nC with diagonal elements of nonincreasing magnitude.\nC The routine needs the full upper triangle of R, the permutation\nC matrix P, and the first n components of Q'*b (' denotes the\nC transpose). The system A*x = b, D*x = 0, is then equivalent to\nC\nC R*z = Q'*b , P'*D*P*z = 0 , (1)\nC\nC where x = P*z. If this system does not have full rank, then a\nC least squares solution is obtained. On output, MB02YD also\nC provides an upper triangular matrix S such that\nC\nC P'*(A'*A + D*D)*P = S'*S .\nC\nC The system (1) is equivalent to S*z = c , where c contains the\nC first n components of the vector obtained by applying to\nC [ (Q'*b)' 0 ]' the transformations which triangularized\nC [ R' P'*D*P ]', getting S.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC COND CHARACTER*1\nC Specifies whether the condition of the matrix S should be\nC estimated, as follows:\nC = 'E' : use incremental condition estimation and store\nC the numerical rank of S in RANK;\nC = 'N' : do not use condition estimation, but check the\nC diagonal entries of S for zero values;\nC = 'U' : use the rank already stored in RANK.\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The order of the matrix R. N >= 0.\nC\nC R (input/output) DOUBLE PRECISION array, dimension (LDR, N)\nC On entry, the leading N-by-N upper triangular part of this\nC array must contain the upper triangular matrix R.\nC On exit, the full upper triangle is unaltered, and the\nC strict lower triangle contains the strict upper triangle\nC (transposed) of the upper triangular matrix S.\nC\nC LDR INTEGER\nC The leading dimension of array R. LDR >= MAX(1,N).\nC\nC IPVT (input) INTEGER array, dimension (N)\nC This array must define the permutation matrix P such that\nC A*P = Q*R. Column j of P is column IPVT(j) of the identity\nC matrix.\nC\nC DIAG (input) DOUBLE PRECISION array, dimension (N)\nC This array must contain the diagonal elements of the\nC matrix D.\nC\nC QTB (input) DOUBLE PRECISION array, dimension (N)\nC This array must contain the first n elements of the\nC vector Q'*b.\nC\nC RANK (input or output) INTEGER\nC On entry, if COND = 'U', this parameter must contain the\nC (numerical) rank of the matrix S.\nC On exit, if COND = 'E' or 'N', this parameter contains\nC the numerical rank of the matrix S, estimated according\nC to the value of COND.\nC\nC X (output) DOUBLE PRECISION array, dimension (N)\nC This array contains the least squares solution of the\nC system A*x = b, D*x = 0.\nC\nC Tolerances\nC\nC TOL DOUBLE PRECISION\nC If COND = 'E', the tolerance to be used for finding the\nC rank of the matrix S. If the user sets TOL > 0, then the\nC given value of TOL is used as a lower bound for the\nC reciprocal condition number; a (sub)matrix whose\nC estimated condition number is less than 1/TOL is\nC considered to be of full rank. If the user sets TOL <= 0,\nC then an implicitly computed, default tolerance, defined by\nC TOLDEF = N*EPS, is used instead, where EPS is the machine\nC precision (see LAPACK Library routine DLAMCH).\nC This parameter is not relevant if COND = 'U' or 'N'.\nC\nC Workspace\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, the first N elements of this array contain the\nC diagonal elements of the upper triangular matrix S, and\nC the next N elements contain the solution z.\nC\nC LDWORK INTEGER\nC The length of the array DWORK.\nC LDWORK >= 4*N, if COND = 'E';\nC LDWORK >= 2*N, if COND <> 'E'.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value.\nC\nC METHOD\nC\nC Standard plane rotations are used to annihilate the elements of\nC the diagonal matrix D, updating the upper triangular matrix R\nC and the first n elements of the vector Q'*b. A basic least squares\nC solution is computed.\nC\nC REFERENCES\nC\nC [1] More, J.J., Garbow, B.S, and Hillstrom, K.E.\nC User's Guide for MINPACK-1.\nC Applied Math. Division, Argonne National Laboratory, Argonne,\nC Illinois, Report ANL-80-74, 1980.\nC\nC NUMERICAL ASPECTS\nC 2\nC The algorithm requires 0(N ) operations and is backward stable.\nC\nC FURTHER COMMENTS\nC\nC This routine is a LAPACK-based modification of QRSOLV from the\nC MINPACK package [1], and with optional condition estimation.\nC The option COND = 'U' is useful when dealing with several\nC right-hand side vectors.\nC\nC CONTRIBUTORS\nC\nC V. Sima, Research Institute for Informatics, Bucharest, Dec. 2001.\nC\nC REVISIONS\nC\nC V. Sima, Research Institute for Informatics, Bucharest, Mar. 2005.\nC\nC KEYWORDS\nC\nC Linear system of equations, matrix operations, plane rotations.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, SVLMAX\n PARAMETER ( ZERO = 0.0D0, SVLMAX = 0.0D0 )\nC .. Scalar Arguments ..\n CHARACTER COND\n INTEGER INFO, LDR, LDWORK, N, RANK\n DOUBLE PRECISION TOL\nC .. Array Arguments ..\n INTEGER IPVT(*)\n DOUBLE PRECISION DIAG(*), DWORK(*), QTB(*), R(LDR,*), X(*)\nC .. Local Scalars ..\n DOUBLE PRECISION CS, QTBPJ, SN, TEMP, TOLDEF\n INTEGER I, J, K, L\n LOGICAL ECOND, NCOND, UCOND\nC .. Local Arrays ..\n DOUBLE PRECISION DUM(3)\nC .. External Functions ..\n DOUBLE PRECISION DLAMCH\n LOGICAL LSAME\n EXTERNAL DLAMCH, LSAME\nC .. External Subroutines ..\n EXTERNAL DCOPY, DLARTG, DROT, DSWAP, MB03OD, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC DBLE, MAX\nC ..\nC .. Executable Statements ..\nC\nC Check the scalar input parameters.\nC\n ECOND = LSAME( COND, 'E' )\n NCOND = LSAME( COND, 'N' )\n UCOND = LSAME( COND, 'U' )\n INFO = 0\n IF( .NOT.( ECOND .OR. NCOND .OR. UCOND ) ) THEN\n INFO = -1\n ELSEIF( N.LT.0 ) THEN\n INFO = -2\n ELSEIF ( LDR.LT.MAX( 1, N ) ) THEN\n INFO = -4\n ELSEIF ( UCOND .AND. ( RANK.LT.0 .OR. RANK.GT.N ) ) THEN\n INFO = -8\n ELSEIF ( LDWORK.LT.2*N .OR. ( ECOND .AND. LDWORK.LT.4*N ) ) THEN\n INFO = -12\n ENDIF\nC\nC Return if there are illegal arguments.\nC\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'MB02YD', -INFO )\n RETURN\n ENDIF\nC\nC Quick return if possible.\nC\n IF ( N.EQ.0 ) THEN\n IF ( .NOT.UCOND )\n $ RANK = 0\n RETURN\n END IF\nC\nC Copy R and Q'*b to preserve input and initialize S.\nC In particular, save the diagonal elements of R in X.\nC\n DO 20 J = 1, N\n X(J) = R(J,J)\n DO 10 I = J, N\n R(I,J) = R(J,I)\n 10 CONTINUE\n 20 CONTINUE\nC\n CALL DCOPY( N, QTB, 1, DWORK(N+1), 1 )\nC\nC Eliminate the diagonal matrix D using Givens rotations.\nC\n DO 50 J = 1, N\nC\nC Prepare the row of D to be eliminated, locating the\nC diagonal element using P from the QR factorization.\nC\n L = IPVT(J)\n IF ( DIAG(L).NE.ZERO ) THEN\n QTBPJ = ZERO\n DWORK(J) = DIAG(L)\nC\n DO 30 K = J + 1, N\n DWORK(K) = ZERO\n 30 CONTINUE\nC\nC The transformations to eliminate the row of D modify only\nC a single element of Q'*b beyond the first n, which is\nC initially zero.\nC\n DO 40 K = J, N\nC\nC Determine a Givens rotation which eliminates the\nC appropriate element in the current row of D.\nC\n IF ( DWORK(K).NE.ZERO ) THEN\nC\n CALL DLARTG( R(K,K), DWORK(K), CS, SN, TEMP )\nC\nC Compute the modified diagonal element of R and\nC the modified elements of (Q'*b,0).\nC Accumulate the tranformation in the row of S.\nC\n TEMP = CS*DWORK(N+K) + SN*QTBPJ\n QTBPJ = -SN*DWORK(N+K) + CS*QTBPJ\n DWORK(N+K) = TEMP\n CALL DROT( N-K+1, R(K,K), 1, DWORK(K), 1, CS, SN )\nC\n END IF\n 40 CONTINUE\nC\n END IF\nC\nC Store the diagonal element of S and, if COND <> 'E', restore\nC the corresponding diagonal element of R.\nC\n DWORK(J) = R(J,J)\n IF ( .NOT.ECOND )\n $ R(J,J) = X(J)\n 50 CONTINUE\nC\nC Solve the triangular system for z. If the system is singular,\nC then obtain a least squares solution.\nC\n IF ( ECOND ) THEN\n TOLDEF = TOL\n IF ( TOLDEF.LE.ZERO ) THEN\nC\nC Use the default tolerance in rank determination.\nC\n TOLDEF = DBLE( N )*DLAMCH( 'Epsilon' )\n END IF\nC\nC Interchange the strict upper and lower triangular parts of R.\nC\n DO 60 J = 2, N\n CALL DSWAP( J-1, R(1,J), 1, R(J,1), LDR )\n 60 CONTINUE\nC\nC Estimate the reciprocal condition number of S and set the rank.\nC Additional workspace: 2*N.\nC\n CALL MB03OD( 'No QR', N, N, R, LDR, IPVT, TOLDEF, SVLMAX,\n $ DWORK, RANK, DUM, DWORK(2*N+1), LDWORK-2*N,\n $ INFO )\n R(1,1) = X(1)\nC\nC Restore the strict upper and lower triangular parts of R.\nC\n DO 70 J = 2, N\n CALL DSWAP( J-1, R(1,J), 1, R(J,1), LDR )\n R(J,J) = X(J)\n 70 CONTINUE\nC\n ELSEIF ( NCOND ) THEN\nC\nC Determine rank(S) by checking zero diagonal entries.\nC\n RANK = N\nC\n DO 80 J = 1, N\n IF ( DWORK(J).EQ.ZERO .AND. RANK.EQ.N )\n $ RANK = J - 1\n 80 CONTINUE\nC\n END IF\nC\n DUM(1) = ZERO\n IF ( RANK.LT.N )\n $ CALL DCOPY( N-RANK, DUM, 0, DWORK(N+RANK+1), 1 )\nC\nC Solve S*z = c using back substitution.\nC\n DO 100 J = RANK, 1, -1\n TEMP = ZERO\nC\n DO 90 I = J + 1, RANK\n TEMP = TEMP + R(I,J)*DWORK(N+I)\n 90 CONTINUE\nC\n DWORK(N+J) = ( DWORK(N+J) - TEMP )/DWORK(J)\n 100 CONTINUE\nC\nC Permute the components of z back to components of x.\nC\n DO 110 J = 1, N\n L = IPVT(J)\n X(L) = DWORK(N+J)\n 110 CONTINUE\nC\n RETURN\nC\nC *** Last line of MB02YD ***\n END\n", "meta": {"hexsha": "a58b5c7f608afad085b82505c39b00203e065ee3", "size": 11565, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB02YD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB02YD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB02YD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 32.3044692737, "max_line_length": 72, "alphanum_fraction": 0.5618677043, "num_tokens": 3411, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9273633016692236, "lm_q2_score": 0.7057850216484837, "lm_q1q2_score": 0.6545191279446223}} {"text": "program modcor\n\n! calcul de la fonction de correlation des scintillations\nimplicit none\n\ninteger\t:: i, j, k, nb_int \t! nombre de pas pour le calcul de l'integrale\nreal \t:: Pi, epo, pasf, pasp, lambda, arhm, rhoi, arho\nreal\t:: coef, xj, yj, zj, resint, restot, bessj0\nreal, dimension(5)\t:: hm, Jt, rescint\nreal, dimension(5000) \t:: fk\t\n\n Pi = 4.0*atan(1.0)\n epo = -8/3.\n nb_int = 5000\n pasf = 0.02\n pasp = 7.63e-3\n lambda = 0.53e-6 \t! longueur d'onde, en metre\t\n\n coef = 0.243*4*Pi*Pi/lambda/lambda\n coef = coef*3.0e-14\t! soit un r_{0} de 0.7 m a 0.53 \\mu m\n\nopen (11, file = 'modcor.dat')\n\nhm(1)=5000; hm(2)=10000; hm(3)=15000; hm(4)=20000; hm(5)=25000\n! hm(1)=17200; hm(2)=13400; hm(3)=9600; hm(4)=4250\t! distance de la couche en m\n! Jt(1)=0.25 ; Jt(2)=0.25 ; Jt(3)=0.5; Jt(4)=1.0\t! contenu de turbulence \n \ndo i=-50,50\n\trhoi = pasp*i\t! rho en metre\n\tarho = 2*Pi*rhoi\n\trestot = 0.\n\t\n do k=1,5\n \tarhm = Pi*lambda*hm(k)\n\t\n\tdo j=1,nb_int\n\t\txj = pasf*j\n\t\tyj = arhm*xj*xj\n\t\tzj = arho*xj\n\t\tfk(j) = xj**epo*sin(yj)*sin(yj)*bessj0(zj)\n\tenddo\n\t\n\tresint = coef*pasf*( 0.5*(fk(1) + fk(nb_int)) + &\n\t\t sum( (/(fk(j), j=2,nb_int-1)/)) )\n\trescint(k) = resint\t\n\t\n\trestot = restot + rescint(k)\n enddo\n \n write (11, '(i5, 7(f10.6))') i, rhoi, rescint, restot\nenddo\n\t\nend program modcor\n\n\t\n\t\n\n\n\n", "meta": {"hexsha": "a7f00aed169ba3c7c8b1bb2884dde49039bffc86", "size": 1284, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "modcor.f90", "max_stars_repo_name": "jlprieur/sourcc", "max_stars_repo_head_hexsha": "bf00cc91d9669f6e4ed51b89df357fb27eead711", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "modcor.f90", "max_issues_repo_name": "jlprieur/sourcc", "max_issues_repo_head_hexsha": "bf00cc91d9669f6e4ed51b89df357fb27eead711", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "modcor.f90", "max_forks_repo_name": "jlprieur/sourcc", "max_forks_repo_head_hexsha": "bf00cc91d9669f6e4ed51b89df357fb27eead711", "max_forks_repo_licenses": ["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.4, "max_line_length": 79, "alphanum_fraction": 0.6074766355, "num_tokens": 600, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632956467158, "lm_q2_score": 0.7057850154599563, "lm_q1q2_score": 0.6545191179550134}} {"text": "program test_fluid\n use fluid\n implicit none\n ! Fluid solver class.\n type(FluidSlv) :: FldSlv2D, FldSlv3D\n ! Names of variables.\n character(len=:), dimension(:), allocatable :: names2D, names3D\n ! Dimensions of the simulation domains.\n integer :: whd2D(2), whd3D(3)\n ! Simulation parameters.\n real(dp) :: scale, safety\n ! Density.\n real(dp) :: rho, timestep\n ! Add in flow coordinates.\n type(Vec2D2) :: xi2D\n real(dp) :: initial_cond(3)\n ! Time\n real(dp) :: t\n ! Timers\n integer :: startvalues(8), endvalues(8), startcount, endcount\n real(4) :: countrate\n ! Counter\n integer :: i, j\n ! Arrays\n real(dp), allocatable :: u(:,:), prhs(:)\n real(dp) :: celsiz\n\n ! Initialise names.\n allocate(character(len=8) :: names2D(4))\n\n ! Test 2D.1: Initialise Fluid.\n ! Safety factor.\n safety = 1._dp\n ! Grid scale.\n scale = 1._dp\n ! 3x3 2D grid with sides of length 3 (each box is of size 1x1).\n whd2D = 3\n ! Density.\n rho = 0.1_dp\n ! Initial timestep.\n timestep = 0.005\n ! Names\n names2D(1)(:) = \"Density.\"\n names2D(2)(:) = \"Vx.\"\n names2D(3)(:) = \"Vy.\"\n call FldSlv2D % Init(names2D, whd2D, rho, timestep, scale, safety)\n\n print*, \" rho % name = \", FldSlv2D % rho % name, &\n new_line(\" \"), \" Expected rho % name = \", names2D(1)(1:len(names2D(1)))\n print*, \" u(1) % name = \", FldSlv2D % u(1) % name, &\n new_line(\" \"), \" Expected u(1) % name = \", names2D(2)(1:len(names2D(2)))\n print*, \" u(2) % name = \", FldSlv2D % u(2) % name, &\n new_line(\" \"), \" Expected u(2) % name = \", names2D(3)(1:len(names2D(3)))\n\n print*, \" Box Width = \", FldSlv2D % whd(1), &\n new_line(\" \"), \" Expected width = \", whd2D(1)\n print*, \" Box Height = \", FldSlv2D % whd(2), &\n new_line(\" \"), \" Expected height = \", whd2D(2)\n\n print*, \" Density = \", FldSlv2D % srho, &\n new_line(\" \"), \" Expected Density = \", rho\n\n print*, \" Cell size = \", FldSlv2D % celsiz, &\n new_line(\" \"), \" Expected Cell size = \", scale/minval(whd2D)\n\n print*, \" Safety factor = \", FldSlv2D % safety, &\n new_line(\" \"), \" Expected Safety factor = \", safety\n\n print*, new_line(new_line(\" \")), \" FldSlv2D % prhs = \", FldSlv2D % prhs, &\n new_line(new_line(\" \")), \" Expected FldSlv2D % prhs = \", [(real(i)*0._dp, i = 1, product(whd2D))]\n\n print*, new_line(new_line(\" \")), \" FldSlv2D % p = \", FldSlv2D % prhs, &\n new_line(new_line(\" \")), \" Expected FldSlv2D % p = \", [(real(i)*0._dp, i = 1, product(whd2D))]\n\n print*, new_line(new_line(\" \")), \" FldSlv2D % u(1) % old = \", FldSlv2D % u(1) % old, &\n new_line(new_line(\" \")), \" Expected FldSlv2D % u(1) % old = \", [(real(i)*0._dp, i = 1, (whd2D(1) + 1)*whd2D(2))]\n\n print*, new_line(new_line(\" \")), \" FldSlv2D % u(1) % new = \", FldSlv2D % u(1) % new, &\n new_line(new_line(\" \")), \" Expected FldSlv2D % u(1) % new = \", [(real(i)*0._dp, i = 1, (whd2D(1) + 1)*whd2D(2))]\n\n print*, \" Size(FldSlv2D % u(1) % old) = \", size(FldSlv2D % u(1) % old), &\n new_line(\" \"), \" Expected Size(FldSlv2D % u(1) % old) = \", (whd2D(1) + 1)*whd2D(2)\n\n print*, \" Size(FldSlv2D % u(1) % new) = \", size(FldSlv2D % u(1) % new), &\n new_line(\" \"), \" Expected Size(FldSlv2D % u(1) % new) = \", (whd2D(1) + 1)*whd2D(2)\n\n print*, \" FldSlv2D % u(1) % ost = \", FldSlv2D % u(1) % ost, &\n new_line(\" \"), \" Expected FldSlv2D % u(1) % ost = \", [0._dp, 0.5_dp]\n\n print*, \" FldSlv2D % u(1) % whd = \", FldSlv2D % u(1) % whd, &\n new_line(\" \"), \" Expected FldSlv2D % u(1) % whd = \", [whd2D(1) + 1, whd2D(2)]\n\n print*, \" FldSlv2D % u(1) % celsiz = \", FldSlv2D % u(1) % celsiz, &\n new_line(\" \"), \" Expected FldSlv2D % u(1) % celsiz = \", scale/minval(whd2D)\n\n print*, new_line(new_line(\" \")), \" FldSlv2D % u(2) % old = \", FldSlv2D % u(2) % old, &\n new_line(new_line(\" \")), \" Expected FldSlv2D % u(2) % old = \", [(real(i)*0._dp, i = 1, (whd2D(2) + 1)*whd2D(1))]\n\n print*, new_line(new_line(\" \")), \" FldSlv2D % u(2) % new = \", FldSlv2D % u(2) % new, &\n new_line(new_line(\" \")), \" Expected FldSlv2D % u(2) % new = \", [(real(i)*0._dp, i = 1, (whd2D(2) + 1)*whd2D(1))]\n\n print*, \" Size(FldSlv2D % u(2) % old) = \", size(FldSlv2D % u(2) % old), &\n new_line(\" \"), \" Expected Size(FldSlv2D % u(2) % old) = \", (whd2D(2) + 1)*whd2D(1)\n\n print*, \" Size(FldSlv2D % u(2) % new) = \", size(FldSlv2D % u(2) % new), &\n new_line(\" \"), \" Expected Size(FldSlv2D % u(2) % new) = \", (whd2D(2) + 1)*whd2D(2)\n\n print*, \" FldSlv2D % u(2) % ost = \", FldSlv2D % u(2) % ost, &\n new_line(\" \"), \" Expected FldSlv2D % u(2) % ost = \", [0.5_dp, 0._dp]\n\n print*, \" FldSlv2D % u(2) % whd = \", FldSlv2D % u(2) % whd, &\n new_line(\" \"), \" Expected FldSlv2D % u(2) % whd = \", [whd2D(1), whd2D(2) + 1]\n\n print*, \" FldSlv2D % u(2) % celsiz = \", FldSlv2D % u(2) % celsiz, &\n new_line(\" \"), \" Expected FldSlv2D % celsiz = \", scale/minval(whd2D)\n\n print*, new_line(new_line(\" \")), \" FldSlv2D % rho % new = \", FldSlv2D % rho % new, &\n new_line(new_line(\" \")), \" Expected FldSlv2D % rho % new = \", [(real(i)*0._dp, i = 1, product(whd2D))]\n\n print*, \" Size(FldSlv2D % rho % old) = \", size(FldSlv2D % rho % old), &\n new_line(\" \"), \" Expected Size(FldSlv2D % rho % old) = \", product(whd2D)\n\n print*, \" Size(FldSlv2D % rho % new) = \", size(FldSlv2D % rho % new), &\n new_line(\" \"), \" Expected Size(FldSlv2D % rho % new) = \", product(whd2D)\n\n print*, \" FldSlv2D % rho % ost = \", FldSlv2D % rho % ost, &\n new_line(\" \"), \" Expected FldSlv2D % rho % ost = \", [0.5_dp, 0.5_dp]\n\n print*, \" FldSlv2D % rho % whd = \", FldSlv2D % rho % whd, &\n new_line(\" \"), \" Expected FldSlv2D % rho % whd = \", [whd2D(1), whd2D(2)]\n\n print*, \" FldSlv2D % rho % celsiz = \", FldSlv2D % rho % celsiz, &\n new_line(\" \"), \" Expected FldSlv2D % rho % celsiz = \", scale/minval(whd2D), new_line(new_line(\" \"))\n\n xi2D % x = [0._dp, 1._dp, 0._dp, 1._dp]\n initial_cond = [1.0_dp, 2.0_dp, 3.0_dp]\n\n CALL SYSTEM_CLOCK(startcount, countrate)\n do i = 1, 1\n call FldSlv2D % AddFlow(xi2D, initial_cond)\n end do\n CALL SYSTEM_CLOCK(endcount, countrate)\n print*, \"ADDFLOW: It took me\", endcount - startcount, \"clicks (\", (endcount - startcount)/countrate*1000,\" ms)\"\n\n print*, new_line(new_line(\" \")), \"FldSlv2D % rho % old = \", new_line(\" \"), FldSlv2D % rho % old\n\n print*, new_line(new_line(\" \")), \"FldSlv2D % u(1) % old = \", new_line(\" \"), FldSlv2D % u(1) % old\n\n print*, new_line(new_line(\" \")), \"FldSlv2D % u(2) % old = \", new_line(\" \"), FldSlv2D % u(2) % old, new_line(new_line(\" \"))\n\n t = 0._dp\n CALL SYSTEM_CLOCK(startcount, countrate)\n do i = 1, 1\n call FldSlv2D % MaxTimeStep2D(t)\n end do\n CALL SYSTEM_CLOCK(endcount, countrate)\n print*, \"MAXTIMESTEP: It took me\", endcount - startcount, \"clicks (\", (endcount - startcount)/countrate*1000,\" ms)\"\n print*, new_line(new_line(\" \")), FldSlv2D % TimeStep\n\n\n CALL SYSTEM_CLOCK(startcount, countrate)\n do i = 1, 1\n call FldSlv2D % BuildRhs2D()\n end do\n CALL SYSTEM_CLOCK(endcount, countrate)\n print*, \"BUILDRHS: It took me\", endcount - startcount, \"clicks (\", (endcount - startcount)/countrate*1000,\" ms)\"\n print*, new_line(new_line(\" \")), \" FldSlv2D % prhs = \", FldSlv2D % prhs\n\n CALL SYSTEM_CLOCK(startcount, countrate)\n call FldSlv2D % GSPSlv2D(60, 1d-5)\n CALL SYSTEM_CLOCK(endcount, countrate)\n !print*, endvalues - startvalues\n print*, \"Gauss-Seidel: It took me\", endcount - startcount, \"clicks (\", (endcount - startcount)/countrate*1000,\" ms)\"\n\n call FldSlv2D % ApplyPressure2D()\n do j = 0, 2\n do i = 0, 2\n write(*,\"(A,A,I2,A,I2,A,A,F5.3,A,F5.3,A)\"), \"(Vx(i,j), Vy(i,j) = \", \"(\", i,\",\", j, \"), \", \"(\", FldSlv2D % u(1) % ReadVal(i,j)&\n ,\", \", FldSlv2D % u(2) % ReadVal(i,j), \")\"\n end do\n end do\n\n call FldSlv2D % rho % Advect2D(FluidQty2D([FldSlv2D % u]), FldSlv2D%timestep(1))\n call FldSlv2D % u(1) % Advect2D(FluidQty2D([FldSlv2D % u]), FldSlv2D%timestep(1))\n call FldSlv2D % u(2) % Advect2D(FluidQty2D([FldSlv2D % u]), FldSlv2D%timestep(1))\n !do i = 0, 8\n ! print*, FldSlv2D % rho % new(i)\n !end do\n\nend program test_fluid\n", "meta": {"hexsha": "d1fefaf79a14d1717ccb42a5848a47c5f4ff8b0c", "size": 8117, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "fluid_dynamics/fscg/matrixless/test_fluid_backup.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": "fluid_dynamics/fscg/matrixless/test_fluid_backup.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": "fluid_dynamics/fscg/matrixless/test_fluid_backup.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": 42.497382199, "max_line_length": 132, "alphanum_fraction": 0.5663422447, "num_tokens": 3349, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778258, "lm_q2_score": 0.7718435030872967, "lm_q1q2_score": 0.6544984051314234}} {"text": "SUBROUTINE lpest(n, p, x, y, maxit, a, b, sd, r, rate, it, npo, ifault)\r\n \r\n! Code converted using TO_F90 by Alan Miller\r\n! Date: 2003-12-17 Time: 15:07:09\r\n\r\n! FORMAL PARAMETERS\r\n! N INTEGER input : the number of points\r\n! P REAL input : p in the Lp norm\r\n! X REAL ARRAY (N) input : the observed values x(i)\r\n! Y REAL ARRAY (N) input : the observed values y(i)\r\n! MAXIT INTEGER input : maximum allowable number of iterations\r\n! A REAL output : the estimate of alfa\r\n! B REAL output : the estimate of beta\r\n! SD REAL output : the Lp norm\r\n! R REAL ARRAY (N) output : the signed residuals\r\n! RATE REAL output : abs(S(k+1)-S(k))/S(k+1), where S(k) is\r\n! the Lp norm of the fit on the kth iteration\r\n! IT INTEGER output : the number of iterations\r\n! NPO INTEGER output : the number of the points on the line\r\n! IFAULT INTEGER output :\r\n! IFAULT = 0 if the routine converged.\r\n! = 1 if return was due to an increase in the norm.\r\n! = 2 if the maximum iterations\r\n! specified was less than 2.\r\n! = 3 if the weighted sample variance of x is 0.\r\n! = 4 if N given less than 2.\r\n! = 5 if convergence has not be achieved within\r\n! the maximum number of iterations specified.\r\n\r\n! ALGORITHM AS 110 APPL. STATIST. (1977), VOL.26, NO.1\r\n\r\n! Lp-NORM FIT OF STRAIGHT LINE BY EXTENSION OF SCHLOSSMACHER,\r\n! particularly for 1 <= p <= 2.\r\n\r\nIMPLICIT NONE\r\nINTEGER, INTENT(IN) :: n\r\nREAL, INTENT(IN) :: p\r\nREAL, INTENT(IN) :: x(n)\r\nREAL, INTENT(IN) :: y(n)\r\nINTEGER, INTENT(IN) :: maxit\r\nREAL, INTENT(OUT) :: a\r\nREAL, INTENT(OUT) :: b\r\nREAL, INTENT(OUT) :: sd\r\nREAL, INTENT(OUT) :: r(n)\r\nREAL, INTENT(OUT) :: rate\r\nINTEGER, INTENT(OUT) :: it\r\nINTEGER, INTENT(OUT) :: npo\r\nINTEGER, INTENT(OUT) :: ifault\r\n\r\nINTEGER :: i, isw\r\nREAL :: absri, a2, b2, div, dx, dxy, eps2, &\r\n res, sd2, sw, ssx, spxy, w, xiw, xmean, wp, xi, yi, ymean\r\nREAL, PARAMETER :: eps = 1.0E-6\r\n\r\nIF(maxit < 2) GO TO 9\r\nIF(n < 2) GO TO 10\r\nifault = 0\r\nwp = p - 2.0\r\neps2 = 2.0 * eps\r\nsd = 0.0\r\nr(1:n) = 1.0\r\n\r\nDO it = 1, maxit\r\n npo = 0\r\n \r\n! CALCULATE A AND B BY LEAST SQUARES ON WEIGHTED DATA,\r\n! USING THE HERRAMAN ALGORITHM.\r\n! OMIT OBSERVATIONS WITH SMALL RESIDUALS.\r\n \r\n sw = 0.0\r\n xmean = 0.0\r\n ymean = 0.0\r\n ssx = 0.0\r\n spxy = 0.0\r\n DO i = 1, n\r\n absri = ABS(r(i))\r\n IF(absri <= eps) GO TO 2\r\n w = absri ** wp\r\n sw = sw + w\r\n div = w / sw\r\n xi = x(i) - xmean\r\n yi = y(i) - ymean\r\n xiw = xi * w\r\n dx = xi * xiw\r\n dxy = yi * xiw\r\n ssx = ssx + dx - dx * div\r\n spxy = spxy + dxy - dxy * div\r\n xmean = xmean + xi * div\r\n ymean = ymean + yi * div\r\n CYCLE\r\n 2 npo = npo + 1\r\n END DO\r\n IF(ssx < eps) GO TO 11\r\n b = spxy / ssx\r\n a = ymean - b * xmean\r\n \r\n! FORM RESIDUALS AND TEST CONVERGENCE\r\n \r\n sd2 = 0.0\r\n isw = 0\r\n DO i = 1, n\r\n res = y(i) - a - b * x(i)\r\n absri = ABS(res)\r\n IF(ABS(absri - ABS(r(i))) > eps2) isw = 1\r\n sd2 = sd2 + absri ** p\r\n r(i) = res\r\n END DO\r\n rate = ABS(sd2 - sd) / sd2\r\n IF(isw == 0) RETURN\r\n IF(it == 1) GO TO 5\r\n \r\n! TEST FOR INCREASE IN NORM\r\n \r\n IF(sd2 > sd) GO TO 7\r\n 5 sd = sd2\r\n a2 = a\r\n b2 = b\r\nEND DO\r\n! FAILED TO CONVERGE IN MAXIT ITERATIONS\r\n\r\nifault = 5\r\nRETURN\r\n\r\n! NORM INCREASED, RESTORE A, B, AND R, THEN RETURN\r\n\r\n7 ifault = 1\r\na = a2\r\nb = b2\r\nDO i = 1, n\r\n r(i) = y(i) - a - b * x(i)\r\nEND DO\r\nRETURN\r\n\r\n! MAXIT SPECIFIED LESS THAN 2\r\n\r\n9 ifault = 2\r\nRETURN\r\n\r\n! N LESS THAN 2\r\n\r\n10 ifault = 4\r\nRETURN\r\n\r\n! VARIANCE OF WEIGHTED X IS ZERO\r\n\r\n11 ifault = 3\r\nRETURN\r\nEND SUBROUTINE lpest\r\n", "meta": {"hexsha": "d5c1ee4228ef46274e4d556a9f16b878f744f493", "size": 3981, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/as110.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/as110.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/as110.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.7181208054, "max_line_length": 79, "alphanum_fraction": 0.5164531525, "num_tokens": 1379, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677660619633, "lm_q2_score": 0.7718434873426302, "lm_q1q2_score": 0.6544983977114054}} {"text": "! MD5 of template: 4487f0f616ecccd76ea2b91ab000241b\n! 3D angle related routines\n!\n! ------------------------------------------------------------------------------\n! Copyright (c) 2009-13, Thomas P. Robitaille\n!\n! All rights reserved.\n!\n! Redistribution and use in source and binary forms, with or without\n! modification, are permitted provided that the following conditions are met:\n!\n! * Redistributions of source code must retain the above copyright notice, this\n! list of conditions and the following disclaimer.\n!\n! * Redistributions in binary form must reproduce the above copyright notice,\n! this list of conditions and the following disclaimer in the documentation\n! and/or other materials provided with the distribution.\n!\n! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n! DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\n! FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n! DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n! SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\n! OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n! OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n! ------------------------------------------------------------------------------\n\nmodule type_angle3d\n\n implicit none\n save\n\n private\n\n integer,parameter :: sp = selected_real_kind(p=6,r=37)\n integer,parameter :: dp = selected_real_kind(p=15,r=307)\n\n real(dp),parameter :: pi = 3.14159265358979323846_dp\n real(dp),parameter :: deg2rad = pi / 180._dp\n real(dp),parameter :: rad2deg = 180._dp / pi\n\n public :: angle3d_sp\n type angle3d_sp\n real(sp) :: cost,sint,cosp,sinp\n end type angle3d_sp\n\n public :: angle3d_dp\n type angle3d_dp\n real(dp) :: cost,sint,cosp,sinp\n end type angle3d_dp\n\n public :: operator(.eq.)\n interface operator(.eq.)\n module procedure equal_sp\n module procedure equal_dp\n end interface operator(.eq.)\n\n public :: angle3d_deg\n interface angle3d_deg\n module procedure angle3d_deg_sp\n module procedure angle3d_deg_dp\n end interface angle3d_deg\n\n public :: display_angle\n interface display_angle\n module procedure display_angle_sp\n module procedure display_angle_dp\n end interface display_angle\n\n public :: operator(.dot.)\n interface operator(.dot.)\n module procedure dot_product_sp\n module procedure dot_product_dp\n end interface operator(.dot.)\n\n public :: rotate_angle3d\n interface rotate_angle3d\n module procedure rotate_angle3d_sp\n module procedure rotate_angle3d_dp\n end interface rotate_angle3d\n\n public :: difference_angle3d\n interface difference_angle3d\n module procedure difference_angle3d_sp\n module procedure difference_angle3d_dp\n end interface difference_angle3d\n\n public :: random_sphere_angle3d\n interface random_sphere_angle3d\n module procedure random_sphere_angle3d_sp\n module procedure random_sphere_angle3d_dp\n end interface random_sphere_angle3d\n\n public :: operator(-)\n interface operator(-)\n module procedure minus_angle_sp\n module procedure minus_angle_dp\n end interface operator(-)\n\n interface sin2cos\n module procedure sin2cos_sp\n module procedure sin2cos_dp\n end interface sin2cos\n\n interface cos2sin\n module procedure sin2cos_sp\n module procedure sin2cos_dp\n end interface cos2sin\n\ncontains\n\n\n\n logical function equal_dp(a, b) result(e)\n\n implicit none\n\n type(angle3d_dp),intent(in) :: a, b\n\n e = a%cost == b%cost .and. a%sint == b%sint .and. a%cosp == b%cosp .and. a%sinp == b%sinp\n\n end function equal_dp\n\n type(angle3d_dp) function angle3d_deg_dp(theta,phi) result(a)\n\n implicit none\n\n real(dp),intent(in) :: theta,phi\n\n a%cost = cos(theta*deg2rad)\n a%sint = sin(theta*deg2rad)\n a%cosp = cos(phi*deg2rad)\n a%sinp = sin(phi*deg2rad)\n\n end function angle3d_deg_dp\n\n\n subroutine display_angle_dp(a)\n implicit none\n type(angle3d_dp),intent(in) :: a\n print '(\"Theta = \",F8.4,\" degrees\")',atan2(a%sint,a%cost)*rad2deg\n print '(\"Phi = \",F8.4,\" degrees\")',atan2(a%sinp,a%cosp)*rad2deg\n end subroutine display_angle_dp\n\n\n real(dp) function dot_product_dp(a, b) result(p)\n\n implicit none\n\n type(angle3d_dp),intent(in) :: a, b\n\n p = a%sint*a%cosp*b%sint*b%cosp + a%sint*a%sinp*b%sint*b%sinp + a%cost * b%cost\n\n end function dot_product_dp\n\n\n subroutine rotate_angle3d_dp(a_local,a_coord,a_final)\n\n ! This subroutine is used to add a local angle, such as as\n ! photon emission angle on the surface of a star, or a photon\n ! scattering angle, to an already existing position angle.\n ! The former is given by a_local, the latter, by a_coord, and\n ! the final angle by a_angle. We solve this using spherical\n ! trigonometry. Consider a spherical triangle with corner angles\n ! (A,B,C) and side angles (a,b,c). The angle B is attached to the\n ! z axis, and the sides a and c are on the great circles passing\n ! through the z-axis. The meaning of the angles is as follows:\n\n ! a = old theta angle (initial direction angle)\n ! b = local theta angle (scattering or emission angle)\n ! c = new theta angle (final direction angle)\n\n ! A = no meaning (but useful for scattering)\n ! B = new phi - old phi\n ! C = local phi angle (scattering or emission angle)\n\n implicit none\n\n type(angle3d_dp),intent(in) :: a_local\n type(angle3d_dp),intent(in) :: a_coord\n type(angle3d_dp),intent(out) :: a_final\n\n real(dp) :: cos_a,sin_a\n real(dp) :: cos_b,sin_b\n real(dp) :: cos_c,sin_c\n\n real(dp) :: cos_big_b,sin_big_b\n real(dp) :: cos_big_c,sin_big_c\n\n real(dp) :: delta\n logical :: same_sign\n\n ! Special case - if coord%theta is 0, then final = local\n if(abs(a_coord%sint) < 1.e-10_dp) then\n if(a_coord%cost > 0._dp) then\n a_final = a_local\n a_final%cosp = + a_local%cosp * a_coord%cosp + a_local%sinp * a_coord%sinp\n a_final%sinp = + a_local%cosp * a_coord%sinp - a_local%sinp * a_coord%cosp\n else\n a_final = a_local\n a_final%cost = - a_local%cost\n a_final%cosp = + a_local%cosp * a_coord%cosp - a_local%sinp * a_coord%sinp\n a_final%sinp = + a_local%cosp * a_coord%sinp + a_local%sinp * a_coord%cosp\n end if\n return\n end if\n\n ! --- Assign spherical triangle angles values --- !\n\n ! The angles in the spherical triangle are as follows:\n\n cos_a = a_coord%cost\n sin_a = a_coord%sint\n\n cos_b = a_local%cost\n sin_b = a_local%sint\n\n if(a_local%sinp < 0._dp) then ! the angle in the triangle is then actually 2*pi - local phi\n cos_big_C = + a_local%cosp\n sin_big_C = - a_local%sinp\n else ! the angle is local phi\n cos_big_C = + a_local%cosp\n sin_big_C = + a_local%sinp\n end if\n\n ! --- Solve the spherical triangle --- !\n\n if (abs(sin_a) > abs(cos_a)) then\n same_sign = sin_a > 0._dp .eqv. sin_b > 0._dp\n delta = cos_b - cos_a\n else\n same_sign = cos_a > 0._dp .eqv. cos_b > 0._dp\n delta = sin_b - sin_a\n end if\n\n if(same_sign .and. abs(delta) < 1.e-5_dp .and. sin_big_C < 1.e-5_dp .and. cos_big_c > 0._dp) then\n if (abs(sin_a) > abs(cos_a)) then\n sin_c = sqrt(delta * delta * (1._dp + (cos_a/sin_a)**2) + sin_a * sin_b * sin_big_C * sin_big_C)\n else\n sin_c = sqrt(delta * delta * (1._dp + (sin_a/cos_a)**2) + sin_a * sin_b * sin_big_C * sin_big_C)\n end if\n cos_c = sin2cos(sin_c)\n else\n cos_c = cos_a * cos_b + sin_a * sin_b * cos_big_c\n sin_c = cos2sin(cos_c)\n end if\n\n ! Special case - if local and coord theta are the same and C = 0, return\n ! vertical vector. We can't do better than that because we are limited by\n ! numerical precision, in particular for delta (above) which will be limited\n ! in precision\n if(abs(sin_c) < 1.e-10_dp) then\n write(*,'(\" WARNING: final angle is vertical, and phi is undetermined (set to 0) [rotate_angle3d]\")')\n if(cos_c > 0._dp) then\n a_final = angle3d_deg(0._dp,0._dp)\n else\n a_final = angle3d_deg(180._dp,0._dp)\n end if\n return\n end if\n\n cos_big_b = ( cos_b - cos_a * cos_c ) / ( sin_a * sin_c )\n sin_big_b = + sin_big_c * sin_b / sin_c\n\n ! --- Find final theta and phi values --- !\n\n a_final%cost = cos_c\n a_final%sint = sin_c\n\n if(a_local%sinp < 0._dp) then ! the top angle is old phi - new phi\n a_final%cosp = + cos_big_b * a_coord%cosp + sin_big_b * a_coord%sinp\n a_final%sinp = + cos_big_b * a_coord%sinp - sin_big_b * a_coord%cosp\n else ! the top angle is new phi - old phi\n a_final%cosp = + cos_big_b * a_coord%cosp - sin_big_b * a_coord%sinp\n a_final%sinp = + cos_big_b * a_coord%sinp + sin_big_b * a_coord%cosp\n end if\n\n end subroutine rotate_angle3d_dp\n\n subroutine difference_angle3d_dp(a_coord,a_final,a_local)\n\n ! This subroutine is used to find the local angle by which\n ! a coordinate angle would have to be rotated to give the\n ! final angle specified. This is complementary to the rotate_\n ! angle3d routine.\n\n ! We solve this using spherical\n ! trigonometry. Consider a spherical triangle with corner angles\n ! (A,B,C) and side angles (a,b,c). The angle B is attached to the\n ! z axis, and the sides a and c are on the great circles passing\n ! through the z-axis. The meaning of the angles is as follows:\n\n ! a = old theta angle (initial direction angle)\n ! b = local theta angle (scattering or emission angle)\n ! c = new theta angle (final direction angle)\n\n ! A = no meaning (but useful for scattering)\n ! B = new phi - old phi\n ! C = local phi angle (scattering or emission angle)\n\n implicit none\n\n type(angle3d_dp),intent(out) :: a_local\n type(angle3d_dp),intent(in) :: a_coord\n type(angle3d_dp),intent(in) :: a_final\n\n real(dp) :: cos_a,sin_a\n real(dp) :: cos_b,sin_b\n real(dp) :: cos_c,sin_c\n\n real(dp) :: cos_big_b,sin_big_b\n real(dp) :: cos_big_c,sin_big_c\n\n real(dp) :: delta,diff\n logical :: same_sign\n\n ! Special case - if coord%theta is 0, then final = local\n if(abs(a_coord%sint) < 1.e-10_dp) then\n if(a_coord%cost > 0._dp) then\n a_local = a_final\n a_local%cosp = + a_coord%cosp * a_final%cosp + a_coord%sinp * a_final%sinp\n a_local%sinp = - a_coord%cosp * a_final%sinp + a_coord%sinp * a_final%cosp\n else\n a_local = a_final\n a_local%cost = - a_local%cost\n a_local%cosp = + a_coord%cosp * a_final%cosp + a_coord%sinp * a_final%sinp\n a_local%sinp = + a_coord%cosp * a_final%sinp - a_coord%sinp * a_final%cosp\n end if\n return\n end if\n\n ! --- Assign spherical triangle angles values --- !\n\n ! The angles in the spherical triangle are as follows:\n\n cos_a = a_coord%cost\n sin_a = a_coord%sint\n\n cos_c = a_final%cost\n sin_c = a_final%sint\n\n cos_big_B = a_coord%cosp * a_final%cosp + a_coord%sinp * a_final%sinp\n sin_big_B = a_coord%sinp * a_final%cosp - a_coord%cosp * a_final%sinp\n\n ! --- Solve the spherical triangle --- !\n\n cos_b = cos_a * cos_c + sin_a * sin_c * cos_big_B\n sin_b = cos2sin(cos_b)\n\n ! If cos_b is -1, then the angles are opposite and phi is undefined\n if(abs(cos_b + 1._dp) < 1.e-10_dp) then\n a_local = angle3d_deg(180._dp,0._dp)\n return\n end if\n\n ! If cos_b is +1, then the angles are the same and phi is undefined\n if(abs(cos_b - 1._dp) < 1.e-10_dp) then\n a_local = angle3d_deg(0._dp,0._dp)\n return\n end if\n\n same_sign = cos_a > 0._dp .eqv. cos_b > 0._dp .and. sin_a > 0._dp .eqv. sin_b > 0._dp\n if(abs(sin_a) > abs(cos_a)) then\n delta = cos_b - cos_a\n else\n delta = sin_b - sin_a\n end if\n\n if(same_sign .and. abs(delta) < 1.e-5_dp .and. sin_c < 1.e-5_dp) then\n\n if (abs(sin_a) > abs(cos_a)) then\n diff = (sin_c * sin_c - delta * delta * (1._dp + (cos_a / sin_a)**2)) / (sin_a * sin_b)\n else\n diff = (sin_c * sin_c - delta * delta * (1._dp + (sin_a / cos_a)**2)) / (sin_a * sin_b)\n end if\n\n if(diff >= 0._dp) then\n sin_big_c = sqrt(diff)\n else\n sin_big_c = 0._dp\n end if\n\n if(cos_c > 0._dp) then\n cos_big_c = sin2cos(sin_big_c)\n else\n cos_big_c = - sin2cos(sin_big_c)\n end if\n\n else\n sin_big_c = + abs(sin_big_b) * sin_c / sin_b\n cos_big_c = ( cos_c - cos_a * cos_b ) / ( sin_a * sin_b )\n end if\n\n ! If sin_big_c is zero, this can cause issues in other routines, so we\n ! make it the next floating point, which should have no effect on\n ! calculations but prevents issues.\n if(sin_big_c == 0._dp) sin_big_c = tiny(1._dp)\n\n ! --- Find final theta and phi values --- !\n\n a_local%cost = cos_b\n a_local%sint = sin_b\n\n if(sin_big_b < 0._dp) then\n\n a_local%cosp = cos_big_C\n a_local%sinp = sin_big_C\n\n else\n\n a_local%cosp = cos_big_C\n a_local%sinp = - sin_big_C\n\n end if\n\n end subroutine difference_angle3d_dp\n\n real(dp) function sin2cos_dp(x) result(y)\n implicit none\n real(dp), intent(in) :: x\n if(x * x < 1._dp) then\n y = sqrt(1._dp - x * x)\n else\n y = 0._dp\n end if\n end function sin2cos_dp\n\n subroutine random_sphere_angle3d_dp(a)\n ! Random position on a unit sphere\n use lib_random\n implicit none\n type(angle3d_dp),intent(out) :: a\n real(dp) :: phi\n call random_sphere(a%cost,phi)\n a%sint = sqrt(1._dp - a%cost * a%cost)\n a%cosp = cos(phi)\n a%sinp = sin(phi)\n end subroutine random_sphere_angle3d_dp\n\n type(angle3d_dp) function minus_angle_dp(a) result(b)\n implicit none\n type(angle3d_dp),intent(in) :: a\n b = angle3d_dp(-a%cost, a%sint, -a%cosp, -a%sinp)\n end function minus_angle_dp\n\n\n logical function equal_sp(a, b) result(e)\n\n implicit none\n\n type(angle3d_sp),intent(in) :: a, b\n\n e = a%cost == b%cost .and. a%sint == b%sint .and. a%cosp == b%cosp .and. a%sinp == b%sinp\n\n end function equal_sp\n\n type(angle3d_sp) function angle3d_deg_sp(theta,phi) result(a)\n\n implicit none\n\n real(sp),intent(in) :: theta,phi\n\n a%cost = cos(theta*deg2rad)\n a%sint = sin(theta*deg2rad)\n a%cosp = cos(phi*deg2rad)\n a%sinp = sin(phi*deg2rad)\n\n end function angle3d_deg_sp\n\n\n subroutine display_angle_sp(a)\n implicit none\n type(angle3d_sp),intent(in) :: a\n print '(\"Theta = \",F8.4,\" degrees\")',atan2(a%sint,a%cost)*rad2deg\n print '(\"Phi = \",F8.4,\" degrees\")',atan2(a%sinp,a%cosp)*rad2deg\n end subroutine display_angle_sp\n\n\n real(sp) function dot_product_sp(a, b) result(p)\n\n implicit none\n\n type(angle3d_sp),intent(in) :: a, b\n\n p = a%sint*a%cosp*b%sint*b%cosp + a%sint*a%sinp*b%sint*b%sinp + a%cost * b%cost\n\n end function dot_product_sp\n\n\n subroutine rotate_angle3d_sp(a_local,a_coord,a_final)\n\n ! This subroutine is used to add a local angle, such as as\n ! photon emission angle on the surface of a star, or a photon\n ! scattering angle, to an already existing position angle.\n ! The former is given by a_local, the latter, by a_coord, and\n ! the final angle by a_angle. We solve this using spherical\n ! trigonometry. Consider a spherical triangle with corner angles\n ! (A,B,C) and side angles (a,b,c). The angle B is attached to the\n ! z axis, and the sides a and c are on the great circles passing\n ! through the z-axis. The meaning of the angles is as follows:\n\n ! a = old theta angle (initial direction angle)\n ! b = local theta angle (scattering or emission angle)\n ! c = new theta angle (final direction angle)\n\n ! A = no meaning (but useful for scattering)\n ! B = new phi - old phi\n ! C = local phi angle (scattering or emission angle)\n\n implicit none\n\n type(angle3d_sp),intent(in) :: a_local\n type(angle3d_sp),intent(in) :: a_coord\n type(angle3d_sp),intent(out) :: a_final\n\n real(sp) :: cos_a,sin_a\n real(sp) :: cos_b,sin_b\n real(sp) :: cos_c,sin_c\n\n real(sp) :: cos_big_b,sin_big_b\n real(sp) :: cos_big_c,sin_big_c\n\n real(sp) :: delta\n logical :: same_sign\n\n ! Special case - if coord%theta is 0, then final = local\n if(abs(a_coord%sint) < 1.e-10_sp) then\n if(a_coord%cost > 0._sp) then\n a_final = a_local\n a_final%cosp = + a_local%cosp * a_coord%cosp + a_local%sinp * a_coord%sinp\n a_final%sinp = + a_local%cosp * a_coord%sinp - a_local%sinp * a_coord%cosp\n else\n a_final = a_local\n a_final%cost = - a_local%cost\n a_final%cosp = + a_local%cosp * a_coord%cosp - a_local%sinp * a_coord%sinp\n a_final%sinp = + a_local%cosp * a_coord%sinp + a_local%sinp * a_coord%cosp\n end if\n return\n end if\n\n ! --- Assign spherical triangle angles values --- !\n\n ! The angles in the spherical triangle are as follows:\n\n cos_a = a_coord%cost\n sin_a = a_coord%sint\n\n cos_b = a_local%cost\n sin_b = a_local%sint\n\n if(a_local%sinp < 0._sp) then ! the angle in the triangle is then actually 2*pi - local phi\n cos_big_C = + a_local%cosp\n sin_big_C = - a_local%sinp\n else ! the angle is local phi\n cos_big_C = + a_local%cosp\n sin_big_C = + a_local%sinp\n end if\n\n ! --- Solve the spherical triangle --- !\n\n if (abs(sin_a) > abs(cos_a)) then\n same_sign = sin_a > 0._sp .eqv. sin_b > 0._sp\n delta = cos_b - cos_a\n else\n same_sign = cos_a > 0._sp .eqv. cos_b > 0._sp\n delta = sin_b - sin_a\n end if\n\n if(same_sign .and. abs(delta) < 1.e-5_sp .and. sin_big_C < 1.e-5_sp .and. cos_big_c > 0._sp) then\n if (abs(sin_a) > abs(cos_a)) then\n sin_c = sqrt(delta * delta * (1._sp + (cos_a/sin_a)**2) + sin_a * sin_b * sin_big_C * sin_big_C)\n else\n sin_c = sqrt(delta * delta * (1._sp + (sin_a/cos_a)**2) + sin_a * sin_b * sin_big_C * sin_big_C)\n end if\n cos_c = sin2cos(sin_c)\n else\n cos_c = cos_a * cos_b + sin_a * sin_b * cos_big_c\n sin_c = cos2sin(cos_c)\n end if\n\n ! Special case - if local and coord theta are the same and C = 0, return\n ! vertical vector. We can't do better than that because we are limited by\n ! numerical precision, in particular for delta (above) which will be limited\n ! in precision\n if(abs(sin_c) < 1.e-10_sp) then\n write(*,'(\" WARNING: final angle is vertical, and phi is undetermined (set to 0) [rotate_angle3d]\")')\n if(cos_c > 0._sp) then\n a_final = angle3d_deg(0._sp,0._sp)\n else\n a_final = angle3d_deg(180._sp,0._sp)\n end if\n return\n end if\n\n cos_big_b = ( cos_b - cos_a * cos_c ) / ( sin_a * sin_c )\n sin_big_b = + sin_big_c * sin_b / sin_c\n\n ! --- Find final theta and phi values --- !\n\n a_final%cost = cos_c\n a_final%sint = sin_c\n\n if(a_local%sinp < 0._sp) then ! the top angle is old phi - new phi\n a_final%cosp = + cos_big_b * a_coord%cosp + sin_big_b * a_coord%sinp\n a_final%sinp = + cos_big_b * a_coord%sinp - sin_big_b * a_coord%cosp\n else ! the top angle is new phi - old phi\n a_final%cosp = + cos_big_b * a_coord%cosp - sin_big_b * a_coord%sinp\n a_final%sinp = + cos_big_b * a_coord%sinp + sin_big_b * a_coord%cosp\n end if\n\n end subroutine rotate_angle3d_sp\n\n subroutine difference_angle3d_sp(a_coord,a_final,a_local)\n\n ! This subroutine is used to find the local angle by which\n ! a coordinate angle would have to be rotated to give the\n ! final angle specified. This is complementary to the rotate_\n ! angle3d routine.\n\n ! We solve this using spherical\n ! trigonometry. Consider a spherical triangle with corner angles\n ! (A,B,C) and side angles (a,b,c). The angle B is attached to the\n ! z axis, and the sides a and c are on the great circles passing\n ! through the z-axis. The meaning of the angles is as follows:\n\n ! a = old theta angle (initial direction angle)\n ! b = local theta angle (scattering or emission angle)\n ! c = new theta angle (final direction angle)\n\n ! A = no meaning (but useful for scattering)\n ! B = new phi - old phi\n ! C = local phi angle (scattering or emission angle)\n\n implicit none\n\n type(angle3d_sp),intent(out) :: a_local\n type(angle3d_sp),intent(in) :: a_coord\n type(angle3d_sp),intent(in) :: a_final\n\n real(sp) :: cos_a,sin_a\n real(sp) :: cos_b,sin_b\n real(sp) :: cos_c,sin_c\n\n real(sp) :: cos_big_b,sin_big_b\n real(sp) :: cos_big_c,sin_big_c\n\n real(dp) :: delta,diff\n logical :: same_sign\n\n ! Special case - if coord%theta is 0, then final = local\n if(abs(a_coord%sint) < 1.e-10_sp) then\n if(a_coord%cost > 0._sp) then\n a_local = a_final\n a_local%cosp = + a_coord%cosp * a_final%cosp + a_coord%sinp * a_final%sinp\n a_local%sinp = - a_coord%cosp * a_final%sinp + a_coord%sinp * a_final%cosp\n else\n a_local = a_final\n a_local%cost = - a_local%cost\n a_local%cosp = + a_coord%cosp * a_final%cosp + a_coord%sinp * a_final%sinp\n a_local%sinp = + a_coord%cosp * a_final%sinp - a_coord%sinp * a_final%cosp\n end if\n return\n end if\n\n ! --- Assign spherical triangle angles values --- !\n\n ! The angles in the spherical triangle are as follows:\n\n cos_a = a_coord%cost\n sin_a = a_coord%sint\n\n cos_c = a_final%cost\n sin_c = a_final%sint\n\n cos_big_B = a_coord%cosp * a_final%cosp + a_coord%sinp * a_final%sinp\n sin_big_B = a_coord%sinp * a_final%cosp - a_coord%cosp * a_final%sinp\n\n ! --- Solve the spherical triangle --- !\n\n cos_b = cos_a * cos_c + sin_a * sin_c * cos_big_B\n sin_b = cos2sin(cos_b)\n\n ! If cos_b is -1, then the angles are opposite and phi is undefined\n if(abs(cos_b + 1._sp) < 1.e-10_sp) then\n a_local = angle3d_deg(180._sp,0._sp)\n return\n end if\n\n ! If cos_b is +1, then the angles are the same and phi is undefined\n if(abs(cos_b - 1._sp) < 1.e-10_sp) then\n a_local = angle3d_deg(0._sp,0._sp)\n return\n end if\n\n same_sign = cos_a > 0._sp .eqv. cos_b > 0._sp .and. sin_a > 0._sp .eqv. sin_b > 0._sp\n if(abs(sin_a) > abs(cos_a)) then\n delta = cos_b - cos_a\n else\n delta = sin_b - sin_a\n end if\n\n if(same_sign .and. abs(delta) < 1.e-5_sp .and. sin_c < 1.e-5_sp) then\n\n if (abs(sin_a) > abs(cos_a)) then\n diff = (sin_c * sin_c - delta * delta * (1._sp + (cos_a / sin_a)**2)) / (sin_a * sin_b)\n else\n diff = (sin_c * sin_c - delta * delta * (1._sp + (sin_a / cos_a)**2)) / (sin_a * sin_b)\n end if\n\n if(diff >= 0._sp) then\n sin_big_c = sqrt(diff)\n else\n sin_big_c = 0._sp\n end if\n\n if(cos_c > 0._sp) then\n cos_big_c = sin2cos(sin_big_c)\n else\n cos_big_c = - sin2cos(sin_big_c)\n end if\n\n else\n sin_big_c = + abs(sin_big_b) * sin_c / sin_b\n cos_big_c = ( cos_c - cos_a * cos_b ) / ( sin_a * sin_b )\n end if\n\n ! If sin_big_c is zero, this can cause issues in other routines, so we\n ! make it the next floating point, which should have no effect on\n ! calculations but prevents issues.\n if(sin_big_c == 0._sp) sin_big_c = tiny(1._sp)\n\n ! --- Find final theta and phi values --- !\n\n a_local%cost = cos_b\n a_local%sint = sin_b\n\n if(sin_big_b < 0._sp) then\n\n a_local%cosp = cos_big_C\n a_local%sinp = sin_big_C\n\n else\n\n a_local%cosp = cos_big_C\n a_local%sinp = - sin_big_C\n\n end if\n\n end subroutine difference_angle3d_sp\n\n real(sp) function sin2cos_sp(x) result(y)\n implicit none\n real(sp), intent(in) :: x\n if(x * x < 1._sp) then\n y = sqrt(1._sp - x * x)\n else\n y = 0._sp\n end if\n end function sin2cos_sp\n\n subroutine random_sphere_angle3d_sp(a)\n ! Random position on a unit sphere\n use lib_random\n implicit none\n type(angle3d_sp),intent(out) :: a\n real(sp) :: phi\n call random_sphere(a%cost,phi)\n a%sint = sqrt(1._sp - a%cost * a%cost)\n a%cosp = cos(phi)\n a%sinp = sin(phi)\n end subroutine random_sphere_angle3d_sp\n\n type(angle3d_sp) function minus_angle_sp(a) result(b)\n implicit none\n type(angle3d_sp),intent(in) :: a\n b = angle3d_sp(-a%cost, a%sint, -a%cosp, -a%sinp)\n end function minus_angle_sp\n\n\nend module type_angle3d\n", "meta": {"hexsha": "da8a9b4b79179a54a793ae7403922a8c5b46768f", "size": 24665, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "extra/Fortran/fortranlib-master/fortranlib-master/src/type_angle3d.f90", "max_stars_repo_name": "jfitz/code-stat", "max_stars_repo_head_hexsha": "dd2a13177f3ef03ab42123ef3cfcbbd062a2ae26", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 255, "max_stars_repo_stars_event_min_datetime": "2015-01-22T20:12:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-16T05:39:48.000Z", "max_issues_repo_path": "extra/Fortran/fortranlib-master/fortranlib-master/src/type_angle3d.f90", "max_issues_repo_name": "jfitz/code-stat", "max_issues_repo_head_hexsha": "dd2a13177f3ef03ab42123ef3cfcbbd062a2ae26", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2015-05-06T22:43:11.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-27T04:13:37.000Z", "max_forks_repo_path": "extra/Fortran/fortranlib-master/fortranlib-master/src/type_angle3d.f90", "max_forks_repo_name": "jfitz/code-stat", "max_forks_repo_head_hexsha": "dd2a13177f3ef03ab42123ef3cfcbbd062a2ae26", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 75, "max_forks_repo_forks_event_min_datetime": "2015-02-17T13:48:32.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T20:03:53.000Z", "avg_line_length": 31.4604591837, "max_line_length": 108, "alphanum_fraction": 0.6435029394, "num_tokens": 7382, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778258, "lm_q2_score": 0.7718434873426302, "lm_q1q2_score": 0.6544983917804539}} {"text": "PROGRAM complex\n implicit none\n real, parameter :: pi = 3.141592 ! Declaration of a constant like a #define in c++\n ! real:: a = 5.90, b = 7.2\n complex :: cpm \n ! cpm = a + (0, 1)*b ! Assigning 2 real number to a complex number\n read(*, *) cpm ! In the console give input as ------> (1.56, -8.3)\n print *, cpm, real(cpm), aimag(cpm)\n cpm = cpm*(0., 1.)\n print *, cpm\nEND", "meta": {"hexsha": "529bc2099367d26a6d0062b4da03564938762749", "size": 403, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Learning FORTRAN Concepts/3.f90", "max_stars_repo_name": "arpitkekri/Code_With_FORTRAN", "max_stars_repo_head_hexsha": "fb731e6f8d8a47cfe38896fffd74a55d17efb2e3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2021-02-21T05:24:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-27T10:25:24.000Z", "max_issues_repo_path": "Learning FORTRAN Concepts/3.f90", "max_issues_repo_name": "akhil18soni/Code_With_FORTRAN", "max_issues_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Learning FORTRAN Concepts/3.f90", "max_forks_repo_name": "akhil18soni/Code_With_FORTRAN", "max_forks_repo_head_hexsha": "92bb46ab5b340f070c229f27acb4806931879d02", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-02-27T12:14:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-19T23:30:55.000Z", "avg_line_length": 36.6363636364, "max_line_length": 86, "alphanum_fraction": 0.5583126551, "num_tokens": 142, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867873410141, "lm_q2_score": 0.819893335913536, "lm_q1q2_score": 0.6544280277551322}} {"text": "program array_op_3\nimplicit none\n\nlogical, allocatable :: a(:, :, :), b(:, :, :)\nlogical, allocatable :: c(:, :, :)\ninteger :: i, j, k, dim1 = 10, dim2 = 100, dim3 = 1\n\nallocate(a(dim1, dim2, dim3), b(dim1, dim2, dim3), c(dim1, dim2, dim3))\n\ndo i = 1, dim1\n do j = 1, dim2\n do k = 1, dim3\n a(i, j, k) = modulo2(i + j + k)\n b(i, j, k) = modulo2(i*j + j*k + k*j)\n end do\n end do\nend do\n\nc = a .and. b\ncall verify(c, 0)\n\nc = a .or. b\ncall verify(c, 1)\n\nc = a .eqv. b\ncall verify(c, 2)\n\nc = b .neqv. a\ncall verify(c, 3)\n\ncontains\n\n logical function modulo2(x) result(r)\n integer, intent(in) :: x\n r = (x - 2*(x/2) == 1)\n end function modulo2\n\n subroutine verify(c, op_code)\n implicit none\n\n logical, allocatable, intent(in) :: c(:, :, :)\n integer, intent(in) :: op_code\n\n integer :: i, j, k\n logical :: x, y\n\n do i = lbound(c, 1), ubound(c, 1)\n do j = lbound(c, 2), ubound(c, 2)\n do k = lbound(c, 3), ubound(c, 3)\n x = modulo2(i + j + k)\n y = modulo2(i*j + j*k + k*j)\n select case(op_code)\n case (0)\n if(c(i, j, k) .neqv. (x .and. y)) error stop\n case (1)\n if(c(i, j, k) .neqv. (x .or. y)) error stop\n case (2)\n if(c(i, j, k) .neqv. (x .eqv. y)) error stop\n case (3)\n if(c(i, j, k) .neqv. (x .neqv. y)) error stop\n end select\n end do\n end do\n end do\n\n end subroutine verify\n\nend program", "meta": {"hexsha": "3e1b6e622dd8d4b139d28e9d73bba3d66f1fd446", "size": 1595, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "integration_tests/arrays_op_4.f90", "max_stars_repo_name": "Thirumalai-Shaktivel/lfortran", "max_stars_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 316, "max_stars_repo_stars_event_min_datetime": "2019-03-24T16:23:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:28:33.000Z", "max_issues_repo_path": "integration_tests/arrays_op_4.f90", "max_issues_repo_name": "Thirumalai-Shaktivel/lfortran", "max_issues_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-07-29T04:58:03.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-04T16:40:06.000Z", "max_forks_repo_path": "integration_tests/arrays_op_4.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": 23.4558823529, "max_line_length": 71, "alphanum_fraction": 0.460815047, "num_tokens": 546, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333246035907933, "lm_q2_score": 0.7853085758631159, "lm_q1q2_score": 0.6544169576775815}} {"text": "SUBROUTINE kepler_k2z (kepler, GM , r,v)\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! SUBROUTINE: kepler_k2z.f90\r\n! ----------------------------------------------------------------------\r\n! Purpose:\r\n! Conversion of Keplerian elements (a,e,i,Omega,omega,E) to Position and \r\n! Velocity vectors (Cartesian coordinates) \r\n! ----------------------------------------------------------------------\r\n! Input arguments:\r\n! - kepler:\t\tKepler elements | Array with rank 6\r\n! a: \tsemi-major axis (m)\r\n! e: \teccentricity\r\n! i: \tinclination (degrees)\r\n! Omega: \tright ascension of the ascending node (degrees)\r\n! omega: \targument of perigee (degrees)\r\n! E: \teccentric anomaly (degrees)\r\n! - GM: \t\tEarth gravity constant, m^3/sec^2\r\n!\r\n! Output arguments:\r\n! - r: \t\tposition (m)\r\n! - v: \t\tvelocity (m/sec)\r\n! ----------------------------------------------------------------------\r\n! Dr. Thomas Papanikolaou, Geoscience Australia 26 April 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) :: kepler(6), GM\r\n! OUT\r\n REAL (KIND = prec_q), INTENT(OUT) :: r(3), v(3)\r\n! ----------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n! Local variables declaration\r\n! ----------------------------------------------------------------------\r\n REAL (KIND = prec_q) :: a, e, i_rad, Omega_asc_rad, omega_per_rad, E_rad\r\n REAL (KIND = prec_q) :: n\r\n REAL (KIND = prec_q) :: P(3), Q(3), W(3), Rmatrix(3,3), r_orbplane(3), v_orbplane(3) \r\n! ----------------------------------------------------------------------\r\n\t \r\n\t \r\n! ----------------------------------------------------------------------\r\n! Keplerian elements\r\n! ----------------------------------------------------------------------\r\n! semi-major axis\r\n a = kepler(1)\r\n\t \r\n! Eccentricity\r\n e = kepler(2)\r\n\t \r\n! Inclination\r\n !i_deg = kepler(3)\r\n i_rad = kepler(3) * (PI_global / 180D0)\r\n\r\n! Omega : right ascension of the ascending node (degrees)\r\n !Omega_asc_deg = kepler(4)\r\n Omega_asc_rad = kepler(4) * (PI_global / 180D0)\r\n\r\n! omega : argument of perigee (degrees)\r\n !omega_per_deg = kepler(5)\r\n omega_per_rad = kepler(5) * (PI_global / 180D0)\r\n\r\n! E : eccentric anomaly (degrees)\r\n !E_deg = kepler(6)\r\n E_rad = kepler(6) * (PI_global / 180D0)\r\n! ----------------------------------------------------------------------\r\n \r\n! ----------------------------------------------------------------------\r\n! Mean motion\r\n n = sqrt( GM / a**3 )\r\n! ----------------------------------------------------------------------\r\n \r\n\r\n! ----------------------------------------------------------------------\r\n! Rotation matrix : Rmatrix = [P Q W]\r\n\r\n!P = [cos(omega)*cos(Omega)-sin(omega)*cos(i)*sin(Omega)\r\n! cos(omega)*sin(Omega)+sin(omega)*cos(i)*cos(Omega)\r\n! sin(omega)*sin(i)];\r\n P(1) = cos(omega_per_rad) * cos(Omega_asc_rad) - sin(omega_per_rad) * cos(i_rad) * sin(Omega_asc_rad)\r\n P(2) = cos(omega_per_rad) * sin(Omega_asc_rad) + sin(omega_per_rad) * cos(i_rad) * cos(Omega_asc_rad)\r\n P(3) = sin(omega_per_rad) * sin(i_rad)\r\n\t \r\n!Q = [-sin(omega)*cos(Omega)-cos(omega)*cos(i)*sin(Omega)\r\n! -sin(omega)*sin(Omega)+cos(omega)*cos(i)*cos(Omega)\r\n! cos(omega)*sin(i)];\r\n Q(1) = -1.0D0 * sin(omega_per_rad) * cos(Omega_asc_rad) - cos(omega_per_rad) * cos(i_rad) * sin(Omega_asc_rad)\r\n Q(2) = -1.0D0 * sin(omega_per_rad) * sin(Omega_asc_rad) + cos(omega_per_rad) * cos(i_rad) * cos(Omega_asc_rad)\r\n Q(3) = cos(omega_per_rad) * sin(i_rad)\r\n\t \r\n!W = [sin(i)*sin(Omega) \r\n! -sin(i)*cos(Omega)\r\n! cos(i)];\r\n W(1) = sin(i_rad) * sin(Omega_asc_rad)\r\n W(2) = -1.0D0 * sin(i_rad) * cos(Omega_asc_rad)\r\n W(3) = cos(i_rad)\r\n\t \r\n! Rmatrix = [P Q W]\r\n Rmatrix(1,1:3) = (/ P(1), Q(1), W(1) /)\r\n Rmatrix(2,1:3) = (/ P(2), Q(2), W(2) /)\r\n Rmatrix(3,1:3) = (/ P(3), Q(3), W(3) /)\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! Coordinates in the orbital plane\r\n r_orbplane(1) = a * (cos(E_rad) - e)\r\n\t r_orbplane(2) = a * sqrt(1.0D0 - e**2) * sin(E_rad)\r\n r_orbplane(3) = 0.0D0\r\n\t \r\n! Derivatives of the coordinates in the orbital plane\r\n !dX = ( (n*a) / ( 1-e*cos(E) ) ) * [-sin(E); sqrt(1-e^2)*cos(E); 0;] ;\r\n v_orbplane(1) = ( (n * a) / (1.D0 - e * cos(E_rad)) ) * (-1.0D0 * sin(E_rad) ) \r\n\t v_orbplane(2) = ( (n * a) / (1.D0 - e * cos(E_rad)) ) * sqrt(1.0D0 - e**2) * cos(E_rad)\r\n v_orbplane(3) = 0.0D0\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! Position vector \r\n !r = R * r_orbplane\r\n CALL matrix_Rr (Rmatrix, r_orbplane , r)\t \r\n\t \r\n! Velocity vector\r\n !v = R * v_orbplane\r\n CALL matrix_Rr (Rmatrix, v_orbplane , v)\t \r\n! ----------------------------------------------------------------------\r\n\r\n\r\n\r\nend\r\n", "meta": {"hexsha": "cd4475f0270e01e3a79c43bf26fa1e5d18d0f9de", "size": 5447, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/kepler_k2z.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_k2z.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_k2z.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": 38.6312056738, "max_line_length": 117, "alphanum_fraction": 0.3994859556, "num_tokens": 1473, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9683812354689082, "lm_q2_score": 0.6757645944891559, "lm_q1q2_score": 0.6543977528975545}} {"text": " include 'ttb/ttb_library.f'\n\n subroutine hypela2(d,g,e,de,s,t,dt,ngens,m,nn,kcus,matus,ndi,\n 2 nshear,disp,dispt,coord,ffn,frotn,strechn,eigvn,ffn1,\n 3 frotn1,strechn1,eigvn1,ncrd,itel,ndeg,ndm,\n 4 nnode,jtype,lclass,ifr,ifu)\n \n ! HYPELA2 Nonlinear Viscoelasticity with\n ! Neo-Hookean Hyperelasticity\n ! ----------------------------------------------------------------\n ! Source: Shutov et.al. (2013): An explicit solution for\n ! implicit time stepping in multiplicative\n ! finite strain viscoelasticity.\n ! DOI: http://dx.doi.org/10.1016/j.cma.2013.07.004\n ! --> Lagrangian formulation, EBMSC-method (eq.41f)\n !\n ! Formulation: Total Lagrange, Large Strain\n ! (with option for Updated Lagrange with Push Forward\n ! and Jaumann-like Tangent Correction included)\n !\n ! ----------------------------------------------------------------\n ! Andreas Dutzler, Graz University of Technology\n ! 2018-04-05\n\n use Tensor\n implicit none\n \n integer :: ifr,ifu,itel,jtype,ncrd,ndeg,ndi,ndm,ngens,\n * nn,nnode,nshear\n integer, dimension(2) :: m,matus,kcus,lclass\n real(kind=8), dimension(*) :: e,de,t,dt,g,s\n real(kind=8), dimension(itel) :: strechn,strechn1\n real(kind=8), dimension(ngens,*) :: d\n real(kind=8), dimension(ncrd,*) :: coord\n real(kind=8), dimension(ndeg,*) :: disp, dispt\n real(kind=8), dimension(itel,3) :: ffn,ffn1,frotn,frotn1\n real(kind=8), dimension(itel,*) :: eigvn,eigvn1\n \n include 'concom'\n include 'creeps'\n \n ! begin user code\n type(Tensor2) :: F1\n type(Tensor2s) :: C1,invC1,C0_i,invC1_i,S1,S1_hat,S1_bar,Eye,\n * Phi,Phi_hat,invPhi\n type(Tensor4s) :: C4,C4_hat,C4_bar,I4,P4,Eye4\n real(kind=8) :: J,J_th,C10,mu,eta,kappa,tr_SC,\n * p,dpdJ,detPhi,dtime\n \n ! material parameters\n C10 = 0.5\n mu = 2.0\n eta = 10.0\n kappa = 50.0\n \n ! time increment\n dtime = timinc\n \n ! deformation gradient\n Eye = identity2(Eye)\n F1 = Eye\n F1%ab(1:itel,1:3) = ffn1(1:itel,1:3)\n \n ! volumetric ratio\n J = det(F1)\n \n ! hydrostatic stress and derivative\n p = kappa*(J-1)\n dpdJ = kappa\n \n ! right cauchy-green deformation tensor and inverse\n C1 = transpose(F1)*F1\n invC1 = inv(C1,J**2)\n \n ! PK2-stress elastic ground network\n S1_hat = 2.*C10*Eye\n C4_hat = 0.0\n \n ! inelastic deformation at beginning of the inc.\n C0_i = t(2:7)\n if (t(2) == 0.0) then\n ! if start of analysis is detected\n ! --> no inelastic deformation\n C0_i = Eye\n end if\n \n ! inelastic part of rCG (= Phi_hat)\n Phi = C0_i + mu*dtime/eta * J**(-2./3.)*C1\n Phi_hat = unimodular(Phi)\n invC1_i = inv(Phi_hat,1.d0)\n\n ! PK2-stress viscous overstress\n S1_hat = S1_hat + mu*(invC1_i)\n Eye4 = Eye.cdya.Eye\n detPhi = det(Phi)\n invPhi = inv(Phi,detPhi)\n C4_hat = C4_hat + (mu*(invC1_i.cdya.invC1_i))**\n * (detPhi**(-1./3.) * 2.*mu*dtime/eta* \n * (Eye4 - 1./3.*(Phi.dya.invPhi)))\n \n S1_bar = J**(-2./3.) * S1_hat\n C4_bar = J**(-4./3.) * C4_hat\n \n ! distortional + hydrostatic component of PK2-stress\n tr_SC = S1_bar**C1\n S1 = (S1_bar - 1./3.*tr_SC*invC1) + p*J*invC1\n \n ! material elasticity tensor\n I4 = invC1.cdya.invC1\n P4 = (Eye.cdya.Eye) - 1./3.*(invC1.dya.C1)\n C4 = P4**C4_bar**transpose(P4)\n * + 2./3. * (tr_SC*I4\n * -(S1_bar.dya.invC1)-(invC1.dya.S1_bar)\n * +tr_SC/3.*(invC1.dya.invC1))\n * +(p*J+dpdJ*J**2)*(invC1.dya.invC1)\n * -2.*p*J*I4\n \n ! (lovl==6) --> solution converged, save state variables\n if (lovl.eq.6) then\n t(2:7) = asarray( asvoigt(Phi_hat), 6)\n end if\n \n ! updated lagrange\n if (iupdat.eq.1) then\n ! cauchy stress\n S1 = piola(F1,S1)/J\n ! tangent matrix (jaumann-like co-rotated)\n C4 = piola(F1,C4)/J\n * + (S1.cdya.Eye) + (Eye.cdya.S1)\n endif\n \n ! output as array\n s(1:ngens) = asarray( asvoigt(S1), ngens )\n d(1:ngens,1:ngens) = asarray( asvoigt(C4), ngens,ngens )\n \n return\n end", "meta": {"hexsha": "74299598e54c993b05ca704973e4fd898b3e069d", "size": 4535, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "docs/examples/hypela2_nonlinear_viscoelasticity.f", "max_stars_repo_name": "pinkieli/Tensor-for-Fortran", "max_stars_repo_head_hexsha": "15372e07ad2031a83b8e3a4fe1c99bf538c4d20b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "docs/examples/hypela2_nonlinear_viscoelasticity.f", "max_issues_repo_name": "pinkieli/Tensor-for-Fortran", "max_issues_repo_head_hexsha": "15372e07ad2031a83b8e3a4fe1c99bf538c4d20b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/examples/hypela2_nonlinear_viscoelasticity.f", "max_forks_repo_name": "pinkieli/Tensor-for-Fortran", "max_forks_repo_head_hexsha": "15372e07ad2031a83b8e3a4fe1c99bf538c4d20b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-18T02:02:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-18T02:02:31.000Z", "avg_line_length": 33.102189781, "max_line_length": 72, "alphanum_fraction": 0.5177508269, "num_tokens": 1521, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625050654264, "lm_q2_score": 0.7025300698514777, "lm_q1q2_score": 0.6543804187476464}} {"text": "! =====================================================\nsubroutine rpn2(ixy,maxm,meqn,mwaves,maux,mbc,mx,ql,qr,auxl,auxr,fwave,s,amdq,apdq)\n! =====================================================\n\n! Approximate Riemann solver for the nonlinear p-system in 2d\n! with variable coefficients.\n\n! waves: 2\n! equations: 3\n\n! Conserved quantities:\n! 1 strain\n! 2 x_momentum\n! 3 y_momentum\n\n! The variable names are based on an elasticity interpretation\n\n! The jacobian matrix of the flux vector (in each direction)\n! is approximated by the linear localized problem.\n \n! There are 3 eigenvectors; however, the second eigenvalue\n! is always zero and just two waves are computed.\n\n! Solve Riemann problems along one slice of data:\n! in the x-direction if ixy=1\n! in the y-direction if ixy=2.\n\n! On input, ql contains the state vector at the left edge of each cell\n! qr contains the state vector at the right edge of each cell\n\n! f-wave approach is considered. This consists in decomposing the flux\n! difference (assuming it's continuous) using the eigenvectors of the\n! jacobian matrices of the flux vectors (in each spatial direction).\n! This is convinient for variable coefficient PDEs.\n\n! On output, fwave contains the f-waves,\n! s the speeds,\n! amdq the left-going fluctuation\n! apdq the right-going fluctuation\n\n! Note that the i'th Riemann problem has left state qr(i-1,:)\n! and right state ql(i,:)\n! From the basic clawpack routines, this routine is called with ql = qr\n\n implicit double precision (a-h,o-z)\n dimension fwave(meqn,mwaves,1-mbc:maxm+mbc)\n dimension s(mwaves,1-mbc:maxm+mbc)\n dimension ql(meqn,1-mbc:maxm+mbc)\n dimension qr(meqn,1-mbc:maxm+mbc)\n dimension apdq(meqn,1-mbc:maxm+mbc)\n dimension amdq(meqn,1-mbc:maxm+mbc)\n dimension auxl(maux,1-mbc:maxm+mbc)\n dimension auxr(maux,1-mbc:maxm+mbc)\n \n do 10 i=2-mbc,mx+mbc\n ! material properties\n pim=auxr(1,i-1)\n pi=auxl(1,i)\n Eim=auxr(2,i-1)\n Ei=auxl(2,i)\n ! solution eps, urho and vrho\n epsi=ql(1,i)\n urhoi=ql(2,i)\n vrhoi=ql(3,i)\n epsim=qr(1,i-1)\n urhoim=qr(2,i-1)\n vrhoim=qr(3,i-1)\n ! linearity of material (for cell i and for cell im)\n linearity_mati=auxl(3,i)\n linearity_matim=auxr(3,i-1)\n ! sigma\n sigmai=sigma(epsi,Ei,linearity_mati)\n sigmaim=sigma(epsim,Eim,linearity_matim)\n ! sigmap\n sigmapi=sigmap(epsi,Ei,linearity_mati)\n sigmapim=sigmap(epsim,Eim,linearity_matim)\n ! computation of components of eigenvectors\n r11=1/dsqrt(sigmapim*pim)\n r13=-1/dsqrt(sigmapi*pi)\n ! shock speeds\n s(1,i)=-dsqrt(sigmapim/pim) !lambda_1\n s(2,i)=dsqrt(sigmapi/pi) !lambda_2\n \n if(ixy == 1) then !x direction\n ! compute jump in flux\n dF1=-(urhoi/pi-urhoim/pim)\n dF2=-(sigmai-sigmaim)\n ! compute betas\n beta1=(dF1-r13*dF2)/(r11-r13)\n beta3=(-dF1+r11*dF2)/(r11-r13)\n ! compute f-waves\n fwave(1,1,i)=beta1*r11\n fwave(2,1,i)=beta1*1\n fwave(3,1,i)=beta1*0\n fwave(1,2,i)=beta3*r13\n fwave(2,2,i)=beta3*1\n fwave(3,2,i)=beta3*0\n else !y direction\n ! compute jump in flux\n dF1=-(vrhoi/pi-vrhoim/pim)\n dF3=-(sigmai-sigmaim)\n ! compute betas\n beta1=(dF1-r13*dF3)/(r11-r13)\n beta3=(-dF1+r11*dF3)/(r11-r13)\n ! compute f-waves\n fwave(1,1,i)=beta1*r11\n fwave(2,1,i)=beta1*0\n fwave(3,1,i)=beta1*1\n fwave(1,2,i)=beta3*r13\n fwave(2,2,i)=beta3*0\n fwave(3,2,i)=beta3*1\n endif\n ! computation of the fluctuations\n amdq(1,i)=fwave(1,1,i)\n amdq(2,i)=fwave(2,1,i)\n amdq(3,i)=fwave(3,1,i)\n apdq(1,i)=fwave(1,2,i)\n apdq(2,i)=fwave(2,2,i)\n apdq(3,i)=fwave(3,2,i)\n\n 10 END DO\n \n return\n end subroutine rpn2\n\n double precision function sigma(eps,E,linearity_mat)\n! Returns the flux sigma for a given\n! eps, E and depending the linearity of the material\n implicit double precision (a-h,o-z)\n beta=5\n select case (linearity_mat)\n case (1)\n sigma=E*eps\n case (2)\n sigma=dexp(E*eps)-1\n case (3)\n sigma=0.1*E*eps+beta*eps**3*E**3\n end select\n return\n END function\n\n double precision function sigmap(eps,E,linearity_mat)\n implicit double precision (a-h,o-z)\n! Returns the derivative of sigma wrt eps for a given\n! eps, E and depending the linearity of the material\n beta=5\n select case (linearity_mat)\n case (1)\n sigmap=E\n case (2)\n sigmap=E*dexp(E*eps)\n case (3)\n sigmap=0.1*E+3*beta*eps**2*E**3\n end select\n return\n END function\n", "meta": {"hexsha": "a370783456465d6f08debf1a718cb7413e941647", "size": 4922, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/rpn2_psystem.f90", "max_stars_repo_name": "ranocha/riemann", "max_stars_repo_head_hexsha": "d7b4d72d1147eee12e60a64f46a7e076b28a212d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 27, "max_stars_repo_stars_event_min_datetime": "2015-03-08T03:42:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-21T01:46:12.000Z", "max_issues_repo_path": "src/rpn2_psystem.f90", "max_issues_repo_name": "ranocha/riemann", "max_issues_repo_head_hexsha": "d7b4d72d1147eee12e60a64f46a7e076b28a212d", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 47, "max_issues_repo_issues_event_min_datetime": "2015-02-11T15:39:22.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-25T01:56:46.000Z", "max_forks_repo_path": "src/rpn2_psystem.f90", "max_forks_repo_name": "ranocha/riemann", "max_forks_repo_head_hexsha": "d7b4d72d1147eee12e60a64f46a7e076b28a212d", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 37, "max_forks_repo_forks_event_min_datetime": "2015-01-09T21:44:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-21T12:53:04.000Z", "avg_line_length": 31.3503184713, "max_line_length": 83, "alphanum_fraction": 0.59122308, "num_tokens": 1583, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625050654264, "lm_q2_score": 0.7025300573952054, "lm_q1q2_score": 0.6543804071450957}} {"text": "!##############################################################################\n! MODULE globals\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!##############################################################################\nmodule globals\n\n implicit none\n real*8, parameter :: mu = 1d0, sig2 = 0.1d0, minp = 1d0\n integer, parameter :: n = 10\n real*8 :: y(0:n), w(0:n)\n\ncontains\n\n\n function market(A)\n\n implicit none\n real*8, intent(in) :: A\n real*8 :: market\n real*8 :: Ep\n\n ! calculate expected price\n Ep = sum(w*max(3d0-2d0*A*y, minp))\n\n ! get equilibrium equation\n market = A - (0.5d0+0.5d0*Ep)\n\n end function\n\nend module globals\n", "meta": {"hexsha": "2a7a5490ecfaa09aeb251668dac7ef9c5d8b1516", "size": 922, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "complete/prog02/prog02_14/prog02_14m.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_14/prog02_14m.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_14/prog02_14m.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.641025641, "max_line_length": 79, "alphanum_fraction": 0.4772234273, "num_tokens": 246, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256393148982, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.6543509612585959}} {"text": "program intel_dgesvd\n\nuse,intrinsic:: iso_fortran_env, only: sp=>real32, dp=>real64, compiler_version, stderr=>error_unit\n\nimplicit none (type, external)\n\nexternal :: dgesvd\n\n! Intel(R) Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64,\n! Version 19.0.1.144 Build 20181018\n! 64 bits: error mag: 0.000000000000E+00 0.000000000000E+00 0.000000000000E+00\n\n\n! GCC version 7.3.0 (system Lapack)\n! 64 bits: error mag: 0.000000000000E+00 2.220446049250E-16 4.996003610813E-16\n\n! GCC version 7.3.0 (MKL 19)\n! 64 bits: error mag: 6.952923663893-310 6.941716482845-310 4.940656458412-324\n\n! pgf90 18.10-0 (system Lapack\n! 64 bits: error mag: 0.000000000000E+00 2.220446049250E-16 4.996003610813E-16\n\n! pgf90 18.10-0 (MKL 19)\n! 64 bits: error mag: 0.000000000000E+00 0.000000000000E+00 0.000000000000E+00\n\nreal(dp):: A(3,3) = reshape( &\n [ 1, 0, 1, &\n -1,-2, 0, &\n 0, 1,-1 ], &\n shape(A))\n\ninteger :: svdinfo\ninteger, parameter :: M = size(a,1), N = size(a,2), Lratio = 5\ninteger, parameter :: LWORK = LRATIO*M\nreal(dp) :: U(M,M),VT(M,M), SWORK(LRATIO*M)\n\nreal(dp) :: ss64(M, N), s64(M), e64(M), maxerr\nreal(dp), parameter :: s64ref(3) = [2.460504870018764_dp, 1.699628148275318_dp, 0.239123278256554_dp]\n\n\ncall dgesvd('A','N',M,M,A,M,SS64,U,M,VT,M, SWORK, LWORK,svdinfo)\nif (svdinfo /=0) then\n write(stderr,*) 'svd error: ',svdinfo\n error stop\nendif\n\ns64 = ss64(:,1) ! NOT DIAG!!!!\n\n!e64 = s64 - S64ref\n\nprint *,compiler_version()\nprint '(I3,A,3ES20.12)',storage_size(s64),' bits: error mag: ',e64\n\n\nmaxerr=maxval(abs(e64))\n\nif (maxerr > 1e-7_dp) error stop 'excessive singular value error'\n\nend program\n", "meta": {"hexsha": "28a36cf70c4de3e339b80a166a23e7b0bd148f75", "size": 1672, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lapack95/intel_dgesvd.f90", "max_stars_repo_name": "supershushu/fortran2018-examples", "max_stars_repo_head_hexsha": "f0dc03b80326bc7c06fa31945b6e7406a60c1fa8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-12-29T15:07:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T10:09:22.000Z", "max_issues_repo_path": "lapack95/intel_dgesvd.f90", "max_issues_repo_name": "supershushu/fortran2018-examples", "max_issues_repo_head_hexsha": "f0dc03b80326bc7c06fa31945b6e7406a60c1fa8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-12-30T15:38:47.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-31T06:45:11.000Z", "max_forks_repo_path": "lapack95/intel_dgesvd.f90", "max_forks_repo_name": "supershushu/fortran2018-examples", "max_forks_repo_head_hexsha": "f0dc03b80326bc7c06fa31945b6e7406a60c1fa8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-12-29T15:34:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-15T07:12:40.000Z", "avg_line_length": 27.8666666667, "max_line_length": 101, "alphanum_fraction": 0.6704545455, "num_tokens": 678, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256313782276, "lm_q2_score": 0.7772998611746912, "lm_q1q2_score": 0.6543509464035931}} {"text": "!\n! ludcmp.f90\n! \n!\n! Created by Xingshi on 1/30/08.\n! Copyright 2008 __MyCompanyName__. All rights reserved.\n! a the matrix put in , n=np give the dimension, d returns the determinant\n\t subroutine determinant(a,n,np,d)! LU decomposition to calculate dertiminant\n\t integer n, np\n\t real(8) d, a(np,np)\n\t integer indx(n)\n\t integer j\n\t call ludcmp(a,n,np,indx,d)\n\t do j=1,n\n\t d=d*a(j,j)\n\t end do\n\t return\n\t end\n \n\t \n\t subroutine ludcmp(a,n,np,inx,d)\n\t integer n,np,indx(n), NMAX\n\t real(8) d, a(np,np), TINY\n\t parameter (NMAX=500, TINY=1.0e-20)\n\t integer i, imax,j,k\n\t real(8) aamax, dum, summ, vv(NMAX)\n\t d=1\n\t do i=1,n\n\t aamax=0.0d0\n\t\t do j=1,n\n\t\t if (abs(a(i,j)) .gt. aamax) aamax=abs(a(i,j))\n\t\t end do\n\t\t if (aamax .eq. 0) pause 'sigular matrix in ludcmp'\n\t\t vv(i)=1.d0/aamax\n\t end do\n\t do j=1,n\n\t do i=1,j-1\n\t\t summ=a(i,j)\n\t\t\t do k=1, i-1\n\t\t\t summ=summ-a(i,k)*a(k,j)\n\t\t\t end do\n\t\t\t a(i,j)=summ\n end do\n aamax=0\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\t\t\t dum=vv(i)*abs(summ)\n\t\t\t if (dum .ge. aamax) then\n\t\t\t imax=i\n\t\t\t\taamax=dum\n\t\t\t end if\n\t end do\n\t\t \n\t\t if (j .ne. imax) then\n\t\t do k=1,n\n\t\t\t dum=a(imax,k)\n\t\t\t\t a(imax,k)=a(j,k)\n\t\t\t\t a(j,k)=dum\n\t\t\t end do\n\t\t\t d=-d\n\t\t\t vv(imax)=vv(j)\n\t\t end if\n\t\t\tindx(j)=imax\n\t\t\tif(a(j,j) .eq. 0) a(j,j)=TINY\n\t\t\tif (j .ne. n) then\n\t\t\t dum=1./a(j,j)\n\t\t\t do i= j+1, n\n\t\t\t a(i,j)=a(i,j)*dum\n\t\t\t end do\n\t\t\tend if\n\t\tend do\n return\n end\n", "meta": {"hexsha": "27a493392c1379ac22990b8e116fec9a625bec1d", "size": 1664, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "determinant.f90", "max_stars_repo_name": "biofluids/IFEM-archive", "max_stars_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-15T11:40:16.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-15T11:40:16.000Z", "max_issues_repo_path": "determinant.f90", "max_issues_repo_name": "biofluids/IFEM-archive", "max_issues_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "determinant.f90", "max_forks_repo_name": "biofluids/IFEM-archive", "max_forks_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-02-11T16:50:21.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-08T07:24:59.000Z", "avg_line_length": 21.3333333333, "max_line_length": 79, "alphanum_fraction": 0.484375, "num_tokens": 611, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256313782276, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.6543509377177629}} {"text": "#\n# Example program: FizzBuzz!\n#\nuse foreach\n\nfbz(x | x % 15 = 0): say(x, ' FizzBuzz') .\nfbz(x | x % 3 = 0): say(x, ' Fizz') .\nfbz(x | x % 5 = 0): say(x, ' Buzz') .\nfbz(x) : say(x).\n\nmain():\n foreach( [x | 1 <= x <= 100] , fbz ).", "meta": {"hexsha": "22456f76cd21d69f426133475c678e11bf26cbe3", "size": 235, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "examples/fizzbuzz/fizzbuzz.f", "max_stars_repo_name": "diegovalverde/funk", "max_stars_repo_head_hexsha": "39be1ad5ce6d5b306f23165bc0fe5882de56b2ee", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-04-05T14:24:42.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-17T20:05:09.000Z", "max_issues_repo_path": "examples/fizzbuzz/fizzbuzz.f", "max_issues_repo_name": "diegovalverde/funk", "max_issues_repo_head_hexsha": "39be1ad5ce6d5b306f23165bc0fe5882de56b2ee", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2019-01-31T15:39:34.000Z", "max_issues_repo_issues_event_max_datetime": "2019-08-16T17:34:31.000Z", "max_forks_repo_path": "examples/fizzbuzz/fizzbuzz.f", "max_forks_repo_name": "diegovalverde/funk", "max_forks_repo_head_hexsha": "39be1ad5ce6d5b306f23165bc0fe5882de56b2ee", "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": 19.5833333333, "max_line_length": 42, "alphanum_fraction": 0.4680851064, "num_tokens": 104, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8539127678225575, "lm_q2_score": 0.7662936377487305, "lm_q1q2_score": 0.6543479211748348}} {"text": "program modulo_test\n implicit none\n integer, parameter :: n=1024\n real :: array(n,n)\n integer :: i\n !$omp declare target map(alloc:array)\n\n !$omp target teams distribute parallel do simd\n do i=1,size(array)\n array(modulo(i,n),i/n)=i\n enddo\nend program modulo_test\n", "meta": {"hexsha": "1a1d8f4f521dfaa2d30dcc5c435213d071fe4c72", "size": 275, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/smoke-fails/flang-318074/flang-318074.f90", "max_stars_repo_name": "raramakr/aomp", "max_stars_repo_head_hexsha": "9a224fe01ca8eff4209b8b79aa1fa15a18da65db", "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": "test/smoke-fails/flang-318074/flang-318074.f90", "max_issues_repo_name": "raramakr/aomp", "max_issues_repo_head_hexsha": "9a224fe01ca8eff4209b8b79aa1fa15a18da65db", "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": "test/smoke-fails/flang-318074/flang-318074.f90", "max_forks_repo_name": "raramakr/aomp", "max_forks_repo_head_hexsha": "9a224fe01ca8eff4209b8b79aa1fa15a18da65db", "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": 21.1538461538, "max_line_length": 48, "alphanum_fraction": 0.6981818182, "num_tokens": 80, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517043, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6543479188944507}} {"text": "PROGRAM symmetric_eigen\r\n\r\n! Demonstration program 2 using the 'LONG' package. Calculation of the\r\n! eigenvalues & vectors of 2 large symmetric matrices using Kaiser's method.\r\n! In this version, quadruple precision is used to orthogonalize the columns\r\n! of the input matrix, but the final calculation of the eigenvalues and\r\n! normalization of the eigenvectors is in double precision.\r\n\r\n! Programmer: Alan Miller\r\n\r\n! Latest revision - 28 September 1986\r\n! Fortran 90 version - 6 December 1996\r\n! Revised - 19 June 1997\r\n\r\nUSE quadruple_precision\r\nIMPLICIT NONE\r\n\r\nTYPE (quad) :: a(44,44)\r\nREAL (dp) :: eigenv(44), trace, sume\r\nINTEGER :: i, j, nrows, ier\r\nREAL :: tstart, tend\r\nCHARACTER (LEN=1) :: ch\r\n\r\nINTERFACE\r\n SUBROUTINE qkaiser(a, dim_a, n, eigenv, trace, sume, ier)\r\n USE quadruple_precision\r\n IMPLICIT NONE\r\n INTEGER, INTENT(IN) :: dim_a, n\r\n INTEGER, INTENT(OUT) :: ier\r\n TYPE (quad), DIMENSION(:,:), INTENT(IN OUT) :: a\r\n REAL (dp), DIMENSION(:), INTENT(OUT) :: eigenv\r\n REAL (dp), INTENT(OUT) :: trace, sume\r\n END SUBROUTINE qkaiser\r\nEND INTERFACE\r\n\r\n! First example 30 x 30\r\n\r\n! ( 10 1 1 1 )\r\n! ( 1 10 0 0 1 )\r\n! ( 1 0 10 0 0 1 )\r\n! ( 1 0 0 9 0 0 1 )\r\n! ( 1 0 0 9 0 0 1 )\r\n! A = ( . . . . . . . . )\r\n! ( 1 0 0 2 0 0 1 )\r\n! ( 1 0 0 1 0 0 )\r\n! ( 1 0 0 1 0 )\r\n! ( 1 0 0 1 )\r\n\r\n! The published eigenvalues of this matrix are:-\r\n! 11.80931 0238 10.74619 4183 10.17489 2583 9.47341 06874\r\n! 9.21067 86475 8.68784 18564 8.11381 05886 8.03894 11158\r\n! 7.76156 65166 7.01635 02620 7.00395 17985 6.96372 64186\r\n! 6.00126 33582 6.00021 75223 5.99783 78494 4.99983 25857\r\n! 4.99978 24777 4.99968 95662 3.99604 97565 3.99604 82014\r\n! 3.99604 56418 2.96105 89161 2.96105 88842 2.96105 88358\r\n! 1.78932 13529 1.78932 13527 1.78932 13522 0.25380 58171\r\n! 0.25380 58171 0.25380 58170\r\n\r\nDO i = 1, 30\r\n DO j = 1, 30\r\n a(i,j)%lo = 0._dp\r\n IF (i == j) THEN\r\n a(i,i)%hi = (33-i)/3\r\n ELSE IF (ABS(i-j) == 3) THEN\r\n a(i,j)%hi = 1._dp\r\n ELSE\r\n a(i,j)%hi = 0._dp\r\n END IF\r\n END DO\r\nEND DO\r\na(1,2)%hi = 1._dp\r\na(1,3)%hi = 1._dp\r\na(2,1)%hi = 1._dp\r\na(3,1)%hi = 1._dp\r\n\r\nnrows = 30\r\nCALL time_now(tstart)\r\nCALL qkaiser(a, 44, nrows, eigenv, trace, sume, ier)\r\nIF (ier == 0) THEN\r\n WRITE(*, 900) eigenv(1:nrows)\r\n 900 FORMAT(' Eigenvalues:-', 11(/ 4F19.14))\r\n WRITE(*, *)\r\n WRITE(*, '(a, 2F19.14)') ' Trace & sum of eigenvalues = ', trace, sume\r\n WRITE(*, *) 'Trace = sum if all eigenvalues +ve'\r\nELSE\r\n WRITE(*, '(a, i4)') ' *** qkaiser error no. ', ier\r\nEND IF\r\n\r\nCALL time_now(tend)\r\nWRITE(*, '(a, f8.2, a)') ' Time taken = ', tend-tstart, 'secs.'\r\n\r\nWRITE(*, *)\r\nWRITE(*, *) 'Press RETURN to continue'\r\nREAD(*, '(a)') ch\r\nWRITE(*, '(a)') ' ' // ch\r\n\r\n! Second example 44 x 44\r\n!\r\n! ( 5 2 1 1 )\r\n! ( 2 6 3 1 1 )\r\n! ( 1 3 6 3 1 1 )\r\n! ( 1 1 3 6 3 1 1 )\r\n! ( 1 1 3 6 3 1 1 )\r\n! A = ( . . . . . . . . )\r\n! ( 1 1 3 6 3 1 )\r\n! ( 1 1 3 6 2 )\r\n! ( 1 1 2 5 )\r\n\r\n! This is a particularly difficult matrix as it has 11 eigenvalues\r\n! (nos. 15-25) very close together. Their published values are:-\r\n! 4.16250 38244 29765 4.14589 80337 50315\r\n! 4.14077 17541 12427 4.12083 46534 01856\r\n! 4.09474 53700 81830 4.07872 56924 26601\r\n! 4.05284 15893 88415 4.03456 80076 76363\r\n! 4.00521 19531 60050 4.00453 18458 00653\r\n! 4.0 (exactly)\r\n\r\nDO i = 1, 44\r\n DO j = 1, 44\r\n a(i,j)%lo = 0._dp\r\n IF (i == j) THEN\r\n a(i,i)%hi = 6._dp\r\n ELSE IF (ABS(i-j) == 1) THEN\r\n a(i,j)%hi = 3._dp\r\n ELSE IF (ABS(i-j) <= 3) THEN\r\n a(i,j)%hi = 1._dp\r\n ELSE\r\n a(i,j)%hi = 0._dp\r\n END IF\r\n END DO\r\nEND DO\r\na(1,1)%hi = 5._dp\r\na(1,2)%hi = 2._dp\r\na(2,1)%hi = 2._dp\r\na(44,44)%hi = 5._dp\r\na(44,43)%hi = 2._dp\r\na(43,44)%hi = 2._dp\r\n\r\nnrows = 44\r\nCALL time_now(tstart)\r\nCALL qkaiser(a, 44, nrows, eigenv, trace, sume, ier)\r\nIF (ier == 0) THEN\r\n WRITE(*, 900) eigenv(1:nrows)\r\n WRITE(*, *)\r\n WRITE(*, '(a, 2F19.14)') ' Trace & sum of eigenvalues = ', trace, sume\r\n WRITE(*, *) 'Trace = sum if all eigenvalues +ve'\r\nELSE\r\n WRITE(*, '(a, i4)') ' *** qkaiser error no. ', ier\r\nEND IF\r\n\r\nCALL time_now(tend)\r\nWRITE(*, '(a, f8.2, a)') ' Time taken = ', tend-tstart, 'secs.'\r\n\r\nSTOP\r\n\r\n\r\nCONTAINS\r\n\r\n\r\nSUBROUTINE time_now(seconds)\r\nREAL, INTENT(OUT) :: seconds\r\n\r\n! Local variables\r\nINTEGER :: t(8)\r\n\r\nCALL DATE_AND_TIME(values=t)\r\nseconds = 3600.*t(5) + 60.*t(6) + t(7) + 0.001*t(8)\r\n\r\nRETURN\r\nEND SUBROUTINE time_now\r\n\r\nEND PROGRAM symmetric_eigen\r\n\r\n\r\n\r\n\r\nSUBROUTINE qkaiser(a, dim_a, n, eigenv, trace, sume, ier)\r\n\r\n! Calculate the eigenvalues & vectors of a +ve definite symmetric\r\n! matrix in quadruple precision, using a method due to Kaiser.\r\n! Reference:\r\n! Kaiser, H.F. 'The JK method: a procedure for finding the eigenvalues of\r\n! a real symmetric matrix', Computer J., 15, 271-273, 1972.\r\n! N.B. Strictly the method finds the squared eigenvalues. It can be used\r\n! with any symmetric matrix - it does not need to be +ve definite, but it\r\n! does not know what signs to give to the eigenvalues.\r\n\r\n! Arguments:\r\n! A(DIM_A,*) INPUT. Contains the matrix in quadruple-precision.\r\n! OUTPUT. The columns contain the eigenvectors.\r\n! N.B. The input matrix is overwritten.\r\n! DIM_A INPUT. Second dimension of A in the calling program\r\n! N INPUT. The order or no. of columns in A.\r\n! EIGENV(N) OUTPUT. The eigenvalues (ordered).\r\n! TRACE OUTPUT. The trace of A.\r\n! SUME OUTPUT. Sum of the eigenvalues. This should equal the trace\r\n! if all the eigenvalues are >= 0.\r\n! If not, the difference is equal to twice the sum\r\n! of the negative eigenvalues.\r\n! IER OUTPUT. Error indicator\r\n! = 0 if no errors detected\r\n! = 1 if N > DIM_A\r\n! = 2 failed to converge in 12 iterations\r\n\r\n! Programmer: Alan Miller\r\n\r\n! Latest revision - 28 September 1986\r\n! Fortran 90 version - 3 December 1996\r\n! Revised - 5 August 1997\r\n\r\nUSE quadruple_precision\r\nIMPLICIT NONE\r\n\r\nINTEGER, INTENT(IN) :: dim_a, n\r\nINTEGER, INTENT(OUT) :: ier\r\nTYPE (quad), DIMENSION(:,:), INTENT(IN OUT) :: a\r\nREAL (dp), DIMENSION(:), INTENT(OUT) :: eigenv\r\nREAL (dp), INTENT(OUT) :: trace, sume\r\n\r\n! Local variables\r\n\r\nTYPE (quad) :: halfp, q, temp, sine, cosine, qone\r\nREAL (dp) :: small = 1.E-08_dp, very_small = 1.E-25_dp, ss, eps1, eps2, &\r\n xj, xk, p, absp, absq, tangent, cotan, zero = 0._dp, one = 1._dp\r\nINTEGER :: iter, nn, ncount, i, j, k\r\n\r\n! Initial checks\r\n\r\nIF (n < 1 .OR. n > dim_a) THEN\r\n ier = 1\r\n RETURN\r\nEND IF\r\nier = 0\r\nqone%hi = one\r\nqone%lo = zero\r\n\r\n! Calculate trace & tolerances.\r\n\r\nsume = zero\r\ntrace = zero\r\nss = zero\r\nDO i = 1, n\r\n trace = trace + a(i,i)%hi\r\n DO j = 1, n\r\n ss = ss + a(i,j)%hi**2\r\n END DO\r\nEND DO\r\neps1 = small * ss/n\r\neps2 = very_small * ss/n\r\n\r\n! Some initialization.\r\n\r\niter = 1\r\nnn = n*(n-1)/2\r\nncount = nn\r\n\r\n!----------------------------------------------------------------------\r\n\r\n! Main loop to orthogonalize all pairs of columns starts here.\r\n\r\n30 DO j = 1, n-1\r\n DO k = j+1, n\r\n\r\n! Calculate planar rotation in double precision.\r\n! This is fairly fast so it does not matter if we have to repeat\r\n! it in quadruple precision.\r\n\r\n halfp%hi = zero\r\n q%hi = zero\r\n DO i = 1, n\r\n xj = a(i,j)%hi\r\n xk = a(i,k)%hi\r\n halfp%hi = halfp%hi + xj*xk\r\n q%hi = q%hi + (xj + xk) * (xj - xk)\r\n END DO\r\n p = SCALE(halfp%hi, 1)\r\n absp = ABS(p)\r\n absq = ABS(q%hi)\r\n\r\n! If the cross-product in p or the difference of 2-norms in q%hi is\r\n! small, repeat the calculation in quadruple precision.\r\n\r\n IF (absp < eps1 .OR. absq < eps1) THEN\r\n halfp%hi = zero\r\n halfp%lo = zero\r\n q%hi = zero\r\n q%lo = zero\r\n DO i = 1, n\r\n halfp = halfp + a(i,j) * a(i,k)\r\n q = q + (a(i,j) + a(i,k)) * (a(i,j) - a(i,k))\r\n END DO\r\n p = SCALE(halfp%hi, 1)\r\n absp = ABS(p)\r\n absq = ABS(q%hi)\r\n END IF\r\n\r\n! Test if columns are almost orthogonal and in the correct order.\r\n\r\n IF (absp < eps2) THEN\r\n IF (q%hi >= zero) GO TO 80\r\n END IF\r\n\r\n! The trigonometric bit.\r\n\r\n IF (absp <= absq) THEN\r\n tangent = absp / absq\r\n temp = exactmul2(tangent, tangent)\r\n cosine = qone / SQRT(temp + qone)\r\n temp%hi = tangent\r\n temp%lo = zero\r\n sine = temp * cosine\r\n ELSE\r\n cotan = absq / absp\r\n temp = exactmul2(cotan, cotan)\r\n sine = qone / SQRT(temp + qone)\r\n temp%hi = cotan\r\n temp%lo = zero\r\n cosine = temp * sine\r\n END IF\r\n temp = qone + cosine\r\n temp = SCALE(temp, -1)\r\n cosine = SQRT(temp)\r\n temp = SCALE(cosine, 1)\r\n sine = sine / temp\r\n IF (q%hi < zero) THEN\r\n temp = cosine\r\n cosine = sine\r\n sine = temp\r\n END IF\r\n IF (p < zero) THEN\r\n sine = -sine\r\n END IF\r\n\r\n! Carry out the rotation in quadruple precision.\r\n\r\n WRITE(*, 900) iter, j, k, sine%hi\r\n 900 FORMAT('+', 'iter:', i3, ' columns:', 2I4, ' sine:', g13.5)\r\n DO i = 1, n\r\n q = a(i,j) * cosine + a(i,k) * sine\r\n a(i,k) = a(i,k) * cosine - a(i,j) * sine\r\n a(i,j) = q\r\n END DO\r\n CYCLE\r\n\r\n! No rotation was needed if this point is reached.\r\n! Test for convergence.\r\n\r\n 80 ncount = ncount - 1\r\n IF (ncount <= 0) GO TO 110\r\n\r\n! End of loop over pairs of columns.\r\n\r\n END DO\r\nEND DO\r\n\r\n! Increase count of iterations, then go back for more.\r\n\r\nncount = nn\r\niter = iter + 1\r\nIF (iter <= 12) GO TO 30\r\nier = 2\r\nWRITE(*, *)' *** Failed to converge ***'\r\n\r\n!----------------------------------------------------------------------\r\n\r\n! Converged, or gave up after 12 iterations.\r\n! Eigenvalues squared are the squared lengths of columns.\r\n! The columns of A contain the eigenvectors; scale to length 1.\r\n\r\n110 DO j = 1, n\r\n ss = SUM( a(1:n,j)%hi**2 )\r\n eigenv(j) = SQRT(ss)\r\n sume = sume + eigenv(j)\r\n a(1:n,j)%hi = a(1:n,j)%hi / eigenv(j)\r\n a(1:n,j)%lo = zero\r\nEND DO\r\n\r\nRETURN\r\nEND SUBROUTINE qkaiser\r\n", "meta": {"hexsha": "8cc4bd7ebe9743264ad4d01a20bd8f75bc8e19a5", "size": 10888, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/sym_eig.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/sym_eig.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/sym_eig.f90", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 28.6526315789, "max_line_length": 80, "alphanum_fraction": 0.5219507715, "num_tokens": 3778, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517043, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6543479188944507}} {"text": "SUBROUTINE svbksb_sp(u,w,v,b,x)\r\n USE nrtype\n USE nrutil, ONLY : assert_eq\r\n REAL(SP), DIMENSION(:,:), INTENT(IN) :: u,v\r\n REAL(SP), DIMENSION(:), INTENT(IN) :: w,b\r\n REAL(SP), DIMENSION(:), INTENT(OUT) :: x\r\n INTEGER(I4B) :: mdum,ndum\r\n REAL(SP), DIMENSION(size(x)) :: tmp\r\n mdum=assert_eq(size(u,1),size(b),'svbksb_sp: mdum')\r\n ndum=assert_eq((/size(u,2),size(v,1),size(v,2),size(w),size(x)/),&\r\n 'svbksb_sp: ndum')\r\n where (w /= 0.0)\r\n tmp=matmul(b,u)/w\r\nelsewhere\r\n tmp=0.0\r\nend where\r\nx=matmul(v,tmp)\r\nEND SUBROUTINE svbksb_sp\r\n\r\nSUBROUTINE svbksb_dp(u,w,v,b,x)\r\n USE nrtype\n USE nrutil, ONLY : assert_eq\r\n REAL(DP), DIMENSION(:,:), INTENT(IN) :: u,v\r\n REAL(DP), DIMENSION(:), INTENT(IN) :: w,b\r\n REAL(DP), DIMENSION(:), INTENT(OUT) :: x\r\n INTEGER(I4B) :: mdum,ndum\r\n REAL(DP), DIMENSION(size(x)) :: tmp\r\n mdum=assert_eq(size(u,1),size(b),'svbksb_dp: mdum')\r\n ndum=assert_eq((/size(u,2),size(v,1),size(v,2),size(w),size(x)/),&\r\n 'svbksb_dp: ndum')\r\n where (w /= 0.0)\r\n tmp=matmul(b,u)/w\r\nelsewhere\r\n tmp=0.0\r\nend where\r\nx=matmul(v,tmp)\r\nEND SUBROUTINE svbksb_dp\r\n", "meta": {"hexsha": "a39992a9773ac679a6dff63e1ce6356beb084a15", "size": 1096, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "inversor/database/NICOLE/numerical_recipes/svbksb.f90", "max_stars_repo_name": "aasensio/DeepLearning", "max_stars_repo_head_hexsha": "71838115ce93e0ca96c8314cff3f07de1d64c235", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "inversor/database/NICOLE/numerical_recipes/svbksb.f90", "max_issues_repo_name": "aasensio/DeepLearning", "max_issues_repo_head_hexsha": "71838115ce93e0ca96c8314cff3f07de1d64c235", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "inversor/database/NICOLE/numerical_recipes/svbksb.f90", "max_forks_repo_name": "aasensio/DeepLearning", "max_forks_repo_head_hexsha": "71838115ce93e0ca96c8314cff3f07de1d64c235", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.8421052632, "max_line_length": 69, "alphanum_fraction": 0.6149635036, "num_tokens": 440, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517043, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6543479143369226}} {"text": "!> @brief This function returns the overall index for any step within 6 nested do loops\n!>\n!> @param[in] i1 the index of the first do loop\n!>\n!> @param[in] i2 the index of the second do loop\n!>\n!> @param[in] i3 the index of the third do loop\n!>\n!> @param[in] i4 the index of the fourth do loop\n!>\n!> @param[in] i5 the index of the fifth do loop\n!>\n!> @param[in] i6 the index of the sixth do loop\n!>\n!> @param[in] n2 the end of the second do loop\n!>\n!> @param[in] n3 the end of the third do loop\n!>\n!> @param[in] n4 the end of the fourth do loop\n!>\n!> @param[in] n5 the end of the fifth do loop\n!>\n!> @param[in] n6 the end of the sixth do loop\n!>\n!> @warning This function assumes that all indexes go from 1 to n (inclusive)\n!>\n\nELEMENTAL FUNCTION func_overall_index_6loops(i1, i2, i3, i4, i5, i6, n2, n3, n4, n5, n6) RESULT(ans)\n USE ISO_FORTRAN_ENV\n\n IMPLICIT NONE\n\n ! Declare inputs/outputs ...\n INTEGER(kind = INT64), INTENT(in) :: i1\n INTEGER(kind = INT64), INTENT(in) :: i2\n INTEGER(kind = INT64), INTENT(in) :: i3\n INTEGER(kind = INT64), INTENT(in) :: i4\n INTEGER(kind = INT64), INTENT(in) :: i5\n INTEGER(kind = INT64), INTENT(in) :: i6\n INTEGER(kind = INT64), INTENT(in) :: n2\n INTEGER(kind = INT64), INTENT(in) :: n3\n INTEGER(kind = INT64), INTENT(in) :: n4\n INTEGER(kind = INT64), INTENT(in) :: n5\n INTEGER(kind = INT64), INTENT(in) :: n6\n INTEGER(kind = INT64) :: ans\n\n ans = i6 + n6 * ((i5 - 1_INT64) + n5 * ((i4 - 1_INT64) + n4 * ((i3 - 1_INT64) + n3 * ((i2 - 1_INT64) + n2 * (i1 - 1_INT64)))))\nEND FUNCTION\n", "meta": {"hexsha": "69362829d14b1ce5809741f960e3a884cd8e5fcc", "size": 2084, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "mod_safe/func_overall_index/func_overall_index_6loops.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_overall_index/func_overall_index_6loops.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_overall_index/func_overall_index_6loops.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": 42.5306122449, "max_line_length": 130, "alphanum_fraction": 0.472168906, "num_tokens": 566, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127455162773, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6543479131967301}} {"text": "module example_module\n\n use :: ral_nlls_double\n use :: ral_nlls_internal\n use :: ral_nlls_workspaces\n implicit none \n\n type, extends( params_base_type ) :: user_type\n real(wp), allocatable :: x_values(:)\n real(wp), allocatable :: y_values(:)\n integer :: iter = 0 \n integer :: m\n end type user_type\n\ncontains\n \n \nSUBROUTINE eval_F( status, n_dummy, m, X, f, params)\n\n! -------------------------------------------------------------------\n! eval_F, a subroutine for evaluating the function f at a point X\n! -------------------------------------------------------------------\n\n USE ISO_FORTRAN_ENV\n\n INTEGER, PARAMETER :: wp = KIND( 1.0D+0 )\n INTEGER, INTENT( OUT ) :: status\n INTEGER, INTENT( IN ) :: n_dummy, m\n REAL ( wp ), DIMENSION( * ),INTENT( OUT ) :: f\n REAL ( wp ), DIMENSION( * ),INTENT( IN ) :: X\n class( params_base_type ), intent(inout) :: params\n! Let's switch to an actual fitting example...\n! min 0.5 || f(m,c)||**2, where\n! f_i(m,c) = y_i - exp( m * x_i + c )\n Real (Kind=wp) :: ex\n integer :: i\n! then, let's work this into the format we need\n! X(1) = m, X(2) = c\n select type(params)\n type is(user_type)\n do i = 1,m\n ! Avoid overflow\n ex = max(-70.0_wp, min(70.0_wp, X(1) * params%x_values(i) + X(2)))\n f(i) = params%y_values(i) - exp( ex )\n end do\n end select\n\n status = 0\n \n!!$! let's use Powell's function for now....\n!!$ f(1) = X(1) + 10.0 * X(2)\n!!$ f(2) = sqrt(5.0) * (X(3) - X(4))\n!!$ f(3) = ( X(2) - 2.0 * X(3) )**2\n!!$ f(4) = sqrt(10.0) * ( X(1) - X(4) )**2\n \n! end of subroutine eval_F\n \n END SUBROUTINE eval_F\n\n SUBROUTINE eval_F_one_error( status, n_dummy, m, X, f, params)\n\n! -------------------------------------------------------------------\n! eval_F, a subroutine for evaluating the function f at a point X\n! -------------------------------------------------------------------\n\n USE ISO_FORTRAN_ENV\n\n INTEGER, PARAMETER :: wp = KIND( 1.0D+0 )\n INTEGER, INTENT( OUT ) :: status\n INTEGER, INTENT( IN ) :: n_dummy, m\n REAL ( wp ), DIMENSION( * ),INTENT( OUT ) :: f\n REAL ( wp ), DIMENSION( * ),INTENT( IN ) :: X\n class( params_base_type ), intent(inout) :: params\n Real (Kind=wp) :: ex\n integer :: i\n\n select type(params)\n type is(user_type)\n do i = 1,m\n ! Avoid overflow\n ex = max(-70.0_wp, min(70.0_wp, X(1) * params%x_values(i) + X(2)))\n f(i) = params%y_values(i) - exp( ex )\n end do\n params%iter = params%iter + 1\n \n if (params%iter == 2) then \n status = -1\n else\n status = 0\n end if\n\n end select\n \n END SUBROUTINE eval_F_one_error\n\n SUBROUTINE eval_F_allbutone_error( status, n_dummy, m, X, f, params)\n\n! -------------------------------------------------------------------\n! eval_F, a subroutine for evaluating the function f at a point X\n! -------------------------------------------------------------------\n\n USE ISO_FORTRAN_ENV\n\n INTEGER, PARAMETER :: wp = KIND( 1.0D+0 )\n INTEGER, INTENT( OUT ) :: status\n INTEGER, INTENT( IN ) :: n_dummy, m\n REAL ( wp ), DIMENSION( * ),INTENT( OUT ) :: f\n REAL ( wp ), DIMENSION( * ),INTENT( IN ) :: X\n class( params_base_type ), intent(inout) :: params\n Real (Kind=wp) :: ex\n integer :: i\n\n select type(params)\n type is(user_type)\n do i = 1,m\n ! Avoid overflow\n ex = max(-70.0_wp, min(70.0_wp, X(1) * params%x_values(i) + X(2)))\n f(i) = params%y_values(i) - exp( ex )\n end do\n params%iter = params%iter + 1\n \n if (params%iter > 1) then \n status = -1\n else\n status = 0\n end if\n\n end select\n \n END SUBROUTINE eval_F_allbutone_error\n\n\n SUBROUTINE eval_F_large( status, n_dummy, m, X, f, params)\n\n! -------------------------------------------------------------------\n! eval_F, a subroutine for evaluating the function f at a point X\n! -------------------------------------------------------------------\n\n USE ISO_FORTRAN_ENV\n\n INTEGER, PARAMETER :: wp = KIND( 1.0D+0 )\n INTEGER, INTENT( OUT ) :: status\n INTEGER, INTENT( IN ) :: n_dummy, m\n REAL ( wp ), DIMENSION( * ),INTENT( OUT ) :: f\n REAL ( wp ), DIMENSION( * ),INTENT( IN ) :: X\n class( params_base_type ), intent(inout) :: params\n Real (Kind=wp) :: ex\n integer :: i\n\n select type(params)\n type is(user_type)\n if (params%iter == 2) then\n do i = 1, m\n f(i) = 1e100_wp!exp(88.0)\n end do\n else\n do i = 1,m\n ! Avoid overflow\n ex = max(-70.0_wp, min(70.0_wp, X(1) * params%x_values(i) + X(2)))\n f(i) = params%y_values(i) - exp( ex )\n end do\n end if\n params%iter = params%iter + 1\n end select\n status = 0\n \n END SUBROUTINE eval_F_large\n\n SUBROUTINE eval_J_large( status, n_dummy, m, X, J, params)\n\n! -------------------------------------------------------------------\n! eval_J, a subroutine for evaluating the Jacobian J at a point X\n! -------------------------------------------------------------------\n\n USE ISO_FORTRAN_ENV\n\n INTEGER, PARAMETER :: wp = KIND( 1.0D+0 )\n INTEGER, INTENT( OUT ) :: status\n INTEGER, INTENT( IN ) :: n_dummy, m\n REAL ( wp ), DIMENSION( * ),INTENT( OUT ) :: J\n REAL ( wp ), DIMENSION( * ),INTENT( IN ) :: X\n class( params_base_type ), intent(inout) :: params\n integer :: i\n\n select type(params)\n type is(user_type)\n if (params%iter == 2) then\n do i = 1,2*m\n J(i) = 1e100_wp!exp(88.0)\n end do\n params%iter = params%iter + 1\n else\n do i = 1,m\n J(i) = - params%x_values(i) * exp( X(1) * params%x_values(i) + X(2) )\n J(m + i) = - exp( X(1) * params%x_values(i) + X(2) )\n end do\n end if\n end select\n \n status = 0\n \n END SUBROUTINE eval_J_large\n \n subroutine eval_F_error( status, n_dummy, m_dummy, X_dummy, f_dummy, params_dummy)\n ! a fake eval_f to flag an error \n USE ISO_FORTRAN_ENV\n\n INTEGER, PARAMETER :: wp = KIND( 1.0D+0 )\n INTEGER, INTENT( OUT ) :: status\n INTEGER, INTENT( IN ) :: n_dummy, m_dummy\n REAL ( wp ), DIMENSION( * ),INTENT( OUT ) :: f_dummy\n REAL ( wp ), DIMENSION( * ),INTENT( IN ) :: X_dummy\n class( params_base_type ), intent(inout) :: params_dummy\n\n status = -1\n \n end subroutine eval_F_error\n\n SUBROUTINE eval_J( status, n_dummy, m, X, J, params)\n\n! -------------------------------------------------------------------\n! eval_J, a subroutine for evaluating the Jacobian J at a point X\n! -------------------------------------------------------------------\n\n USE ISO_FORTRAN_ENV\n\n INTEGER, PARAMETER :: wp = KIND( 1.0D+0 )\n INTEGER, INTENT( OUT ) :: status\n INTEGER, INTENT( IN ) :: n_dummy, m\n REAL ( wp ), DIMENSION( * ),INTENT( OUT ) :: J\n REAL ( wp ), DIMENSION( * ),INTENT( IN ) :: X\n class( params_base_type ), intent(inout) :: params\n\n! Let's switch to an actual fitting example...\n! min 0.5 || f(m,c)||**2, where\n! f_i(m,c) = y_i - exp( m * x_i + c )\n\n integer :: i\n\n ! let's work this into the format we need\n ! X(1) = m, X(2) = c\n select type(params)\n type is(user_type)\n do i = 1,m\n J(i) = - params%x_values(i) * exp( X(1) * params%x_values(i) + X(2) )\n J(m + i) = - exp( X(1) * params%x_values(i) + X(2) )\n end do\n end select\n \n status = 0\n\n! end of subroutine eval_J\n\n!!$ ! initialize to zeros...\n!!$ J(1:4,1:4) = 0.0\n!!$ \n!!$ ! enter non-zeros values\n!!$ J(1,1) = 1.0\n!!$ J(1,2) = 10.0\n!!$ J(2,3) = sqrt(5.0)\n!!$ J(2,4) = -sqrt(5.0)\n!!$ J(3,2) = 2.0 * (X(2) - 2.0 * X(3))\n!!$ J(3,3) = -4.0 * (X(2) - 2.0 * X(3)) \n!!$ J(4,1) = sqrt(10.0) * 2.0 * (X(1) - X(4))\n!!$ J(4,4) = - sqrt(10.0) * 2.0 * (X(1) - X(4))\n\n END SUBROUTINE eval_J\n\n SUBROUTINE eval_J_one_error( status, n_dummy, m, X, J, params)\n\n! -------------------------------------------------------------------\n! eval_J, a subroutine for evaluating the Jacobian J at a point X\n! -------------------------------------------------------------------\n\n USE ISO_FORTRAN_ENV\n\n INTEGER, PARAMETER :: wp = KIND( 1.0D+0 )\n INTEGER, INTENT( OUT ) :: status\n INTEGER, INTENT( IN ) :: n_dummy, m\n REAL ( wp ), DIMENSION( * ),INTENT( OUT ) :: J\n REAL ( wp ), DIMENSION( * ),INTENT( IN ) :: X\n class( params_base_type ), intent(inout) :: params\n integer :: i\n\n select type(params)\n type is(user_type)\n do i = 1,m\n J(i) = - params%x_values(i) * exp( X(1) * params%x_values(i) + X(2) )\n J(m + i) = - exp( X(1) * params%x_values(i) + X(2) )\n end do\n params%iter = params%iter + 1\n if (params%iter == 2) then \n status = -1\n else\n status = 0\n end if\n end select\n \n END SUBROUTINE eval_J_one_error\n\n \n SUBROUTINE eval_J_c( status, n_dummy, m, X, J, params)\n\n! -------------------------------------------------------------------\n! eval_J, a subroutine for evaluating the Jacobian J at a point X\n! -------------------------------------------------------------------\n\n USE ISO_FORTRAN_ENV\n\n INTEGER, PARAMETER :: wp = KIND( 1.0D+0 )\n INTEGER, INTENT( OUT ) :: status\n INTEGER, INTENT( IN ) :: n_dummy, m\n REAL ( wp ), DIMENSION( * ),INTENT( OUT ) :: J\n REAL ( wp ), DIMENSION( * ),INTENT( IN ) :: X\n class( params_base_type ), intent(inout) :: params\n\n! Let's switch to an actual fitting example...\n! min 0.5 || f(m,c)||**2, where\n! f_i(m,c) = y_i - exp( m * x_i + c )\n\n integer :: i, index\n\n ! let's work this into the format we need\n ! X(1) = m, X(2) = c\n select type(params)\n type is(user_type)\n index = 0\n ! use c-based formatting\n do i = 1, m\n J(index + 1) = - params%x_values(i) * exp( X(1) * params%x_values(i) + X(2) )\n J(index + 2) = - exp( X(1) * params%x_values(i) + X(2) )\n index = index + 2\n end do\n end select\n \n status = 0\n\n! end of subroutine eval_J\n\n!!$ ! initialize to zeros...\n!!$ J(1:4,1:4) = 0.0\n!!$ \n!!$ ! enter non-zeros values\n!!$ J(1,1) = 1.0\n!!$ J(1,2) = 10.0\n!!$ J(2,3) = sqrt(5.0)\n!!$ J(2,4) = -sqrt(5.0)\n!!$ J(3,2) = 2.0 * (X(2) - 2.0 * X(3))\n!!$ J(3,3) = -4.0 * (X(2) - 2.0 * X(3)) \n!!$ J(4,1) = sqrt(10.0) * 2.0 * (X(1) - X(4))\n!!$ J(4,4) = - sqrt(10.0) * 2.0 * (X(1) - X(4))\n\n END SUBROUTINE eval_J_c\n\n\n \n subroutine eval_J_error( status, n_dummy, m_dummy, X_dummy, J_dummy, params_dummy)\n ! a fake eval_J to flag an error \n USE ISO_FORTRAN_ENV\n\n INTEGER, PARAMETER :: wp = KIND( 1.0D+0 )\n INTEGER, INTENT( OUT ) :: status\n INTEGER, INTENT( IN ) :: n_dummy, m_dummy\n REAL ( wp ), DIMENSION( * ),INTENT( OUT ) :: J_dummy\n REAL ( wp ), DIMENSION( * ),INTENT( IN ) :: X_dummy\n class( params_base_type ), intent(inout) :: params_dummy\n\n status = -1\n \n end subroutine eval_J_error\n\n SUBROUTINE eval_H( status, n_dummy, m, X, f, h, params)\n\n! -------------------------------------------------------------------\n! eval_H, a subroutine for evaluating the second derivative hessian terms\n! -------------------------------------------------------------------\n\n USE ISO_FORTRAN_ENV\n\n INTEGER, PARAMETER :: wp = KIND( 1.0D+0 )\n INTEGER, INTENT( OUT ) :: status\n INTEGER, INTENT( IN ) :: n_dummy, m\n REAL ( wp ), DIMENSION( * ),INTENT( IN ) :: f\n REAL ( wp ), DIMENSION( * ),INTENT( OUT ) :: h\n REAL ( wp ), DIMENSION( * ),INTENT( IN ) :: X\n class( params_base_type ), intent(inout) :: params\n! Let's switch to an actual fitting example...\n! min 0.5 || f(m,c)||**2, where\n! f_i(m,c) = y_i - exp( m * x_i + c )\n\n integer :: i\n\n! then, let's work this into the format we need\n! X(1) = m, X(2) = c\n select type(params)\n type is(user_type)\n ! evaluate \n ! HF = \\sum_{i=1}^m F_i H_i\n h(1:4) = 0.0\n do i = 1, m\n h(1) = &\n h(1) + f(i)* ( & \n - (params%x_values(i)**2) * exp( X(1) * params%x_values(i) + X(2) ) &\n )\n h(2) = &\n h(2) + f(i)* ( &\n - params%x_values(i) * exp( X(1) * params%x_values(i) + X(2) ) &\n )\n h(4) = &\n h(4) + f(i)* ( &\n - exp( X(1) * params%x_values(i) + X(2) ) &\n )\n end do\n h(3) = h(2)\n end select\n\n status = 0\n \n!!$! let's use Powell's function for now....\n!!$ f(1) = X(1) + 10.0 * X(2)\n!!$ f(2) = sqrt(5.0) * (X(3) - X(4))\n!!$ f(3) = ( X(2) - 2.0 * X(3) )**2\n!!$ f(4) = sqrt(10.0) * ( X(1) - X(4) )**2\n \n! end of subroutine eval_F\n \n END SUBROUTINE eval_H\n\n subroutine eval_H_error( status, n_dummy, m_dummy, X_dummy, f_dummy, h_dummy, params_dummy)\n\n! -------------------------------------------------------------------\n! a fake eval_H for flagging an error\n! -------------------------------------------------------------------\n\n USE ISO_FORTRAN_ENV\n\n INTEGER, PARAMETER :: wp = KIND( 1.0D+0 )\n INTEGER, INTENT( OUT ) :: status\n INTEGER, INTENT( IN ) :: n_dummy, m_dummy\n REAL ( wp ), DIMENSION( * ),INTENT( IN ) :: f_dummy\n REAL ( wp ), DIMENSION( * ),INTENT( OUT ) :: h_dummy\n REAL ( wp ), DIMENSION( * ),INTENT( IN ) :: X_dummy\n class( params_base_type ), intent(inout) :: params_dummy\n\n status = -1\n \n end subroutine eval_H_error\n\n SUBROUTINE eval_H_one_error( status, n_dummy, m, X, f, h, params)\n\n! -------------------------------------------------------------------\n! eval_H, a subroutine for evaluating the second derivative hessian terms\n! -------------------------------------------------------------------\n\n USE ISO_FORTRAN_ENV\n\n INTEGER, PARAMETER :: wp = KIND( 1.0D+0 )\n INTEGER, INTENT( OUT ) :: status\n INTEGER, INTENT( IN ) :: n_dummy, m\n REAL ( wp ), DIMENSION( * ),INTENT( IN ) :: f\n REAL ( wp ), DIMENSION( * ),INTENT( OUT ) :: h\n REAL ( wp ), DIMENSION( * ),INTENT( IN ) :: X\n class( params_base_type ), intent(inout) :: params\n\n integer :: i\n\n select type(params)\n type is(user_type)\n ! evaluate \n ! HF = \\sum_{i=1}^m F_i H_i\n h(1:4) = 0.0\n do i = 1, m\n h(1) = &\n h(1) + f(i)* ( & \n - (params%x_values(i)**2) * exp( X(1) * params%x_values(i) + X(2) ) &\n )\n h(2) = &\n h(2) + f(i)* ( &\n - params%x_values(i) * exp( X(1) * params%x_values(i) + X(2) ) &\n )\n h(4) = &\n h(4) + f(i)* ( &\n - exp( X(1) * params%x_values(i) + X(2) ) &\n )\n end do\n h(3) = h(2)\n\n params%iter = params%iter + 1\n\n if (params%iter == 2) then \n status = -1\n else\n status = 0\n end if\n \n end select\n\n status = 0\n \n END SUBROUTINE eval_H_one_error\n\n \n subroutine eval_HP ( status, n, m, x, y, hp, params )\n \n INTEGER, PARAMETER :: wp = KIND( 1.0D+0 )\n INTEGER, INTENT( OUT ) :: status\n INTEGER, INTENT( IN ) :: n, m \n REAL ( wp ), DIMENSION( * ),INTENT( IN ) :: x\n REAL ( wp ), DIMENSION( * ),INTENT( IN ) :: y\n REAL ( wp ), DIMENSION( * ),INTENT( OUT ) :: hp\n class( params_base_type ), intent(inout) :: params\n\n ! does nothing for now...\n\n integer :: i\n\n ! X(1) = m, X(2) = c\n select type(params)\n type is(user_type)\n\n hp(1:n*m) = 0.0\n do i = 1, m ! loop over the columns\n ! need to put H(x)*y in each row\n hp( n*(i-1) + 1 ) = &\n y(1)* (- (params%x_values(i)**2) * exp( X(1) * params%x_values(i) + X(2) ) ) + &\n y(2)* (- params%x_values(i) * exp( X(1) * params%x_values(i) + X(2) ) )\n hp( n*(i-1) + 2 ) = &\n y(1)* (- params%x_values(i) * exp( X(1) * params%x_values(i) + X(2) ) ) + &\n y(2)* (- exp( X(1) * params%x_values(i) + X(2) ) )\n end do\n \n end select\n \n status = 0\n \n end subroutine eval_HP\n\n subroutine generate_data_example(params)\n \n type ( user_type ), intent(out) :: params\n \n params%m = 67\n allocate(params%x_values(params%m))\n allocate(params%y_values(params%m))\n \n ! First, let's get the data\n ! Generated with the code\n ! randn('seed', 23497);\n ! m = 0.3;\n ! c = 0.1;\n ! x_data = [0:0.075:5];\n ! y = exp(m * x_data + c);\n ! noise = randn(size(x_data)) * 0.2;\n ! y_data = y + noise;\n ! (c.f. https://ceres-solver.googlesource.com/ceres-solver/+/master/examples/curve_fitting.cc)\n params%x_values = (/ 0.0, &\n 0.075000000000000, &\n 0.150000000000000, &\n 0.225000000000000, &\n 0.300000000000000, &\n 0.375000000000000, &\n 0.450000000000000, &\n 0.525000000000000, &\n 0.600000000000000, &\n 0.675000000000000, &\n 0.750000000000000, &\n 0.825000000000000, &\n 0.900000000000000, &\n 0.975000000000000, &\n 1.050000000000000, &\n 1.125000000000000, &\n 1.200000000000000, &\n 1.275000000000000, &\n 1.350000000000000, &\n 1.425000000000000, &\n 1.500000000000000, &\n 1.575000000000000, &\n 1.650000000000000, &\n 1.725000000000000, &\n 1.800000000000000, &\n 1.875000000000000, &\n 1.950000000000000, &\n 2.025000000000000, &\n 2.100000000000000, &\n 2.175000000000000, &\n 2.250000000000000, &\n 2.325000000000000, &\n 2.400000000000000, &\n 2.475000000000000, &\n 2.550000000000000, &\n 2.625000000000000, &\n 2.700000000000000, &\n 2.775000000000000, &\n 2.850000000000000, &\n 2.925000000000000, &\n 3.000000000000000, &\n 3.075000000000000, &\n 3.150000000000000, &\n 3.225000000000001, &\n 3.300000000000000, &\n 3.375000000000000, &\n 3.450000000000000, &\n 3.525000000000000, &\n 3.600000000000001, &\n 3.675000000000000, &\n 3.750000000000000, &\n 3.825000000000000, &\n 3.900000000000000, &\n 3.975000000000000, &\n 4.050000000000001, &\n 4.125000000000000, &\n 4.200000000000000, &\n 4.275000000000000, &\n 4.350000000000001, &\n 4.425000000000000, &\n 4.500000000000000, &\n 4.575000000000000, &\n 4.650000000000000, &\n 4.725000000000001, &\n 4.800000000000000, &\n 4.875000000000000, &\n 4.950000000000000 /)\n \n params%y_values = (/ 0.907946872110432, &\n 1.199579396036134, &\n 1.060092431384317, &\n 1.298370500472354, &\n 0.952768858414788, &\n 1.209665290655204, &\n 1.256912538155493, &\n 1.163922146095987, &\n 1.004877938808100, &\n 1.205944250961060, &\n 0.952693297695969, &\n 1.449662692280761, &\n 1.402015259144406, &\n 1.378094012325746, &\n 1.560882147577552, &\n 1.437185539058121, &\n 1.559853079888265, &\n 1.877814947316832, &\n 1.818781749024682, &\n 1.375546045112591, &\n 1.233967904388409, &\n 1.887793124397751, &\n 1.610237096463521, &\n 1.787032484792262, &\n 1.850015127982676, &\n 2.120553361509177, &\n 1.942913663511919, &\n 2.106517132599766, &\n 2.271787117356578, &\n 1.727554346001754, &\n 2.002909500898113, &\n 1.975837413903495, &\n 2.337446525801909, &\n 1.960190841677278, &\n 2.447097025572309, &\n 2.161663720225506, &\n 2.748798529374621, &\n 2.507814238594416, &\n 2.423769408403069, &\n 2.578119353028746, &\n 2.460310096221557, &\n 2.638362783992324, &\n 2.765540456237868, &\n 2.837165966564409, &\n 3.179711963042789, &\n 3.245315453091675, &\n 3.289631922410174, &\n 3.360995198615834, &\n 3.470489725998371, &\n 3.169513520153466, &\n 3.363740517933189, &\n 3.665288099084969, &\n 3.620334359722351, &\n 4.018911445550667, &\n 3.512715166706162, &\n 3.874661411575566, &\n 4.197746303653517, &\n 3.703511523106007, &\n 4.076351488309604, &\n 4.056340365649961, &\n 4.297751562451419, &\n 4.373076571153739, &\n 4.577093065941748, &\n 4.856619059058190, &\n 4.927350280596274, &\n 4.703122139742729, &\n 4.870205182453842 /)\n \n end subroutine generate_data_example\n \n subroutine reset_default_options(options)\n type( nlls_options ), intent(inout) :: options\n \n type( nlls_options ) :: default_options\n\n! options%error = default_options%error\n! options%out = default_options%out\n! options%print_level = default_options%print_level\n options%print_options = default_options%print_options\n options%print_header = default_options%print_header \n options%maxit = default_options%maxit\n options%model = default_options%model\n options%type_of_method = default_options%type_of_method\n options%nlls_method = default_options%nlls_method\n options%allow_fallback_method = default_options%allow_fallback_method\n options%lls_solver = default_options%lls_solver\n options%stop_g_absolute = default_options%stop_g_absolute\n options%stop_g_relative = default_options%stop_g_relative\n options%stop_f_absolute = default_options%stop_f_absolute\n options%stop_f_relative = default_options%stop_f_relative\n options%stop_s = default_options%stop_s \n options%relative_tr_radius = default_options%relative_tr_radius\n options%initial_radius_scale = default_options%initial_radius_scale\n options%initial_radius = default_options%initial_radius\n options%base_regularization = default_options%base_regularization\n options%regularization = default_options%regularization\n options%regularization_term = default_options%regularization_term\n options%regularization_power = default_options%regularization_power\n options%maximum_radius = default_options%maximum_radius\n options%eta_successful = default_options%eta_successful\n options%eta_success_but_reduce = default_options%eta_success_but_reduce\n options%eta_very_successful = default_options%eta_very_successful\n options%eta_too_successful = default_options%eta_too_successful\n options%radius_increase = default_options%radius_increase\n options%radius_reduce = default_options%radius_reduce\n options%radius_reduce_max = default_options%radius_reduce_max\n options%tr_update_strategy = default_options%tr_update_strategy\n options%hybrid_switch = default_options%hybrid_switch\n options%exact_second_derivatives = default_options%exact_second_derivatives\n options%subproblem_eig_fact = default_options%subproblem_eig_fact\n options%use_ews_subproblem = default_options%use_ews_subproblem\n options%scale = default_options%scale\n options%scale_max = default_options%scale_max\n options%scale_min = default_options%scale_min\n options%scale_trim_max = default_options%scale_trim_max\n options%scale_trim_min = default_options%scale_trim_min\n options%scale_require_increase = default_options%scale_require_increase\n options%setup_workspaces = default_options%setup_workspaces\n options%remove_workspaces = default_options%remove_workspaces\n options%more_sorensen_maxits = default_options%more_sorensen_maxits\n options%more_sorensen_shift = default_options%more_sorensen_shift\n options%more_sorensen_tiny = default_options%more_sorensen_tiny\n options%more_sorensen_tol = default_options%more_sorensen_tol\n options%hybrid_tol = default_options%hybrid_tol\n options%hybrid_switch_its = default_options%hybrid_switch_its\n options%reg_order = default_options%reg_order\n options%inner_method = default_options%inner_method\n options%output_progress_vectors = default_options%output_progress_vectors\n options%update_lower_order = default_options%update_lower_order\n options%fortran_jacobian = .true.\n \n end subroutine reset_default_options\n\n subroutine solve_basic(X,params,options,inform)\n \n real(wp), intent(out) :: X(:)\n type( user_type ), intent(inout) :: params\n type( nlls_options ), intent(in) :: options\n type( nlls_inform ), intent(inout) :: inform\n\n integer :: n, m\n \n n = 2 \n m = 67\n \n X(1) = 1.0\n X(2) = 2.0\n \n\n call nlls_solve(n, m, X, &\n eval_F, eval_J, eval_H, params, &\n options, inform ) \n \n end subroutine solve_basic\n\n subroutine dogleg_tests(options,fails)\n \n type( nlls_options ), intent(inout) :: options \n integer, intent(out) :: fails\n \n real(wp), allocatable :: J(:), hf(:), f(:), g(:), d(:)\n real(wp) :: Delta, normd\n type( nlls_inform ) :: inform\n type( nlls_workspace ) :: w\n type( nlls_workspace ), Target :: iw\n\n integer :: n,m\n\n fails = 0\n! Link the inner_workspace to the main workspace\n w%iw_ptr => iw\n! Self reference for inner workspace so recursive call does not fail\n iw%iw_ptr => iw\n\n options%scale = 0 \n options%print_level = 3\n \n !! dogleg \n options%nlls_method = 1\n options%model = 5\n n = 2\n m = 3\n allocate(J(m*n), hf(n*n), f(m), g(n), d(n))\n call setup_workspaces(w,n,m,options,inform) \n Delta = 10.0_wp\n \n ! first, hit the 'method not supported' error\n options%model = 27\n J = 1.0_wp\n hf = 0.0_wp\n f = 1.0_wp\n g = 1.0_wp\n call dogleg(J,f,hf,g,n,m,Delta,d,normd,options,inform,w%calculate_step_ws%dogleg_ws)\n if (inform%status .ne. NLLS_ERROR_DOGLEG_MODEL) then\n write(*,*) 'Error: unsupported model allowed in dogleg'\n fails = fails + 1\n end if\n inform%status = 0\n \n options%model = 1\n J = 0.1_wp * (/ 2.0_wp, 3.0_wp, 4.0_wp, 5.0_wp, 6.0_wp, 7.0_wp /)\n f = 1.0_wp\n hf = 0.0_wp\n g = 1.0_wp\n ! now, get ||d_gn|| <= Delta\n Delta = 6.0_wp\n call dogleg(J,f,hf,g,n,m,Delta,d,normd,options,inform,w%calculate_step_ws%dogleg_ws)\n if (inform%status .ne. 0) then\n write(*,*) 'Error: unexpected error in dogleg'\n fails = fails + 1\n end if\n\n ! now set delta so that || alpha * d_sd || >= Delta\n Delta = 0.5_wp\n call dogleg(J,f,hf,g,n,m,Delta,d,normd,options,inform,w%calculate_step_ws%dogleg_ws)\n if (inform%status .ne. 0) then\n write(*,*) 'Error: unexpected error in dogleg'\n fails = fails + 1\n end if\n\n ! now get the guys in the middle...\n Delta = 2.5_wp\n call dogleg(J,f,hf,g,n,m,Delta,d,normd,options,inform,w%calculate_step_ws%dogleg_ws)\n if (inform%status .ne. 0) then\n write(*,*) 'Error: unexpected error in dogleg'\n fails = fails + 1\n inform%status = 0\n end if\n \n call nlls_finalize(w,options)\n \n call dogleg(J,f,hf,g,n,m,Delta,d,normd,options,inform,w%calculate_step_ws%dogleg_ws)\n if (inform%status .ne. NLLS_ERROR_WORKSPACE_ERROR) then \n write(*,*) 'Error: workspace error not flagged when workspaces not setup'\n fails = fails + 1\n end if\n\n call reset_default_options(options)\n \n end subroutine dogleg_tests\n\n subroutine generate_scaling_tests(options, fails)\n type(nlls_options),intent(inout) :: options \n integer, intent(out) :: fails\n\n real(wp), allocatable :: J(:), A(:,:), scale_extra(:), scale(:)\n integer :: n,m\n type( nlls_workspace) :: w\n type( nlls_workspace), Target :: iw\n type( nlls_inform ) :: inform\n \n fails = 0\n w%iw_ptr => iw\n iw%iw_ptr => iw\n\n options%scale = 4\n options%nlls_method = 3\n n = 2\n m = 3 \n allocate(J(m*n),A(n,n),scale_extra(n),scale(n))\n call setup_workspaces(w,n,m,options,inform)\n \n J = 0.0_wp\n J(1) = 1e15\n J(4) = 1e-15\n A(1,1) = 1.0_wp\n A(2,1) = 0.0_wp\n A(1,2) = 0.0_wp\n A(2,2) = 1.0_wp\n\n scale = 1.0_wp\n scale_extra = 0.0_wp \n\n !** scale = 1 **\n options%scale= 1 \n call generate_scaling(J,A,n,m,scale,scale_extra,& \n w%calculate_step_ws%generate_scaling_ws, &\n options,inform)\n if (inform%status .ne. 0 ) then\n write(*,*) 'Error: unexpected error in generate_scaling when scale = 1'\n write(*,*) 'status = ', inform%status,' returned.'\n fails = fails + 1\n inform%status = 0 \n end if\n\n !** scale = 2 **\n options%scale = 2\n call generate_scaling(J,A,n,m,scale,scale_extra,& \n w%calculate_step_ws%generate_scaling_ws, &\n options,inform)\n if (inform%status .ne. 0 ) then\n write(*,*) 'Error: unexpected error in generate_scaling when scale = 2'\n write(*,*) 'status = ', inform%status,' returned.'\n fails = fails + 1\n inform%status = 0 \n end if\n\n !** scale = 3 **\n options%scale = 3\n call generate_scaling(J,A,n,m,scale,scale_extra,& \n w%calculate_step_ws%generate_scaling_ws, &\n options,inform)\n if (inform%status .ne. 0 ) then\n write(*,*) 'Error: unexpected error in generate_scaling when scale = 2'\n write(*,*) 'status = ', inform%status,' returned.'\n fails = fails + 1\n inform%status = 0 \n end if\n\n !** scale undefined\n options%scale = 786\n call generate_scaling(J,A,n,m,scale,scale_extra,& \n w%calculate_step_ws%generate_scaling_ws, &\n options,inform)\n if (inform%status .ne. NLLS_ERROR_BAD_SCALING ) then\n write(*,*) 'Error: expected error in generate_scaling when passing undefined scaling'\n write(*,*) 'status = ', inform%status,' returned.'\n fails = fails + 1\n inform%status = 0 \n end if\n inform%status = 0\n \n ! now, let's test the non-default modes\n ! first, set scale_require_increase to T\n options%scale = 1\n options%scale_require_increase = .true.\n call generate_scaling(J,A,n,m,scale,scale_extra,& \n w%calculate_step_ws%generate_scaling_ws, &\n options,inform)\n if (inform%status .ne. 0 ) then\n write(*,*) 'Error: unexpected error when scale_require_increase = T'\n write(*,*) 'status = ', inform%status,' returned.'\n fails = fails + 1\n inform%status = 0 \n end if\n options%scale_require_increase = .false.\n\n ! first, set scale_trim_min to T\n options%scale_trim_min = .true.\n call generate_scaling(J,A,n,m,scale,scale_extra,& \n w%calculate_step_ws%generate_scaling_ws, &\n options,inform)\n if (inform%status .ne. 0 ) then\n write(*,*) 'Error: unexpected error when scale_require_increase = T'\n write(*,*) 'status = ', inform%status,' returned.'\n fails = fails + 1\n inform%status = 0 \n end if\n options%scale_trim_min = .false.\n\n ! first, set scale_trim_max to T\n options%scale_trim_max = .false.\n call generate_scaling(J,A,n,m,scale,scale_extra,& \n w%calculate_step_ws%generate_scaling_ws, &\n options,inform)\n if (inform%status .ne. 0 ) then\n write(*,*) 'Error: unexpected error when scale_require_increase = T'\n write(*,*) 'status = ', inform%status,' returned.'\n fails = fails + 1\n inform%status = 0 \n end if\n options%scale_trim_max = .true.\n\n\n call nlls_finalize(w,options)\n call generate_scaling(J,A,n,m,scale,scale_extra,& \n w%calculate_step_ws%generate_scaling_ws, &\n options,inform)\n if (inform%status .ne. NLLS_ERROR_WORKSPACE_ERROR) then \n write(*,*) 'Error: workspace error not flagged when workspaces not setup'\n write(*,*) '(generate_scaling)'\n fails = fails + 1\n end if\n\n call reset_default_options(options)\n\n end subroutine generate_scaling_tests\n\n subroutine aint_tr_tests(options,fails)\n \n type( nlls_options), intent(inout) :: options\n integer, intent(out) :: fails\n \n REAL(wp), allocatable :: J(:), A(:,:), hf(:), f(:), v(:), X(:), d(:)\n real(wp) :: Delta, normd\n integer :: n, m\n TYPE( nlls_inform ) :: inform\n type( nlls_workspace ) :: w\n type( nlls_workspace), Target :: iw\n \n fails = 0\n w%iw_ptr => iw\n iw%iw_ptr => iw\n options%nlls_method = 2\n \n n = 2\n m = 3\n\n allocate(J(n*m), A(n,n), f(m), v(n), X(n), hf(n*n),d(n))\n \n J = [ 1.0, 1.0, 2.0, 2.0, 3.0, 4.0 ]\n A = reshape([6.0, 13.0, 13.0, 29.0],[2, 2])\n f = [2.0, 3.0, 4.0]\n v = [13.0, 29.0]\n hf = 0.0_wp\n Delta = 1.0_wp\n \n call setup_workspaces(w,n,m,options,inform) \n call aint_tr(J,A,f,X,v,hf,n,m,Delta,d,normd,options,inform,& \n w%calculate_step_ws%aint_tr_ws)\n if (inform%status .ne. 0) then \n write(*,*) 'Error: aint_tr test failed'\n fails = fails + 1\n end if\n \n call nlls_finalize(w,options)\n \n call aint_tr(J,A,f,X,v,hf,n,m,Delta,d,normd,options,inform,& \n w%calculate_step_ws%aint_tr_ws)\n if (inform%status .ne. NLLS_ERROR_WORKSPACE_ERROR) then \n write(*,*) 'Error: workspace error not flagged when workspaces not setup'\n write(*,*) '(aint_tr)'\n fails = fails + 1\n end if\n call reset_default_options(options)\n\n end subroutine aint_tr_tests\n\n subroutine more_sorensen_tests(options,fails)\n type( nlls_options), intent(inout) :: options\n integer, intent(out) :: fails\n \n \n real(wp), allocatable :: g(:), d(:), A(:,:)\n real(wp) :: Delta, normd\n type( nlls_inform ) :: status\n type( nlls_workspace ) :: work\n integer :: n,m\n type( nlls_workspace ), Target :: iw\n \n fails = 0\n work%iw_ptr => iw\n iw%iw_ptr => iw\n \n options%nlls_method = 3\n \n n = 2\n m = 3\n allocate(A(n,n), g(n), d(n))\n call setup_workspaces(work,n,m,options,status) \n Delta = 10.0_wp\n \n ! regular case...\n A(1,1) = 0.2_wp\n A(2,1) = 0.3_wp\n A(1,2) = A(2,1)\n A(2,2) = 0.4_wp\n g = 1.0_wp\n ! now, get ||d_gn|| <= Delta\n call more_sorensen(A,g,n,m,Delta,d,normd,options,status,& \n work%calculate_step_ws%more_sorensen_ws)\n if (status%status .ne. 0) then\n write(*,*) 'Error: unexpected error in more-sorensen'\n fails = fails + 1\n status%status = 0\n end if\n\n ! non spd matrix, with failure\n options%more_sorensen_shift = -1000.0_wp\n g = 1.0_wp\n ! now, get ||d_gn|| <= Delta\n call more_sorensen(A,g,n,m,Delta,d,normd,options,status,& \n work%calculate_step_ws%more_sorensen_ws)\n if (status%status .ne. NLLS_ERROR_MS_TOO_MANY_SHIFTS) then\n write(*,*) 'Error: MS too many shifts test passed, when fail expected'\n fails = fails + 1\n end if\n status%status = 0\n options%more_sorensen_shift = 1e-13\n\n ! look for nd /= Delta with a non-zero shift?\n g = 1.0_wp\n Delta = 10.0_wp\n ! now, get ||d_gn|| <= Delta\n call more_sorensen(A,g,n,m,Delta,d,normd,options,status,& \n work%calculate_step_ws%more_sorensen_ws)\n if (status%status .ne. 0) then\n write(*,*) 'Error: unexpected error in more-sorensen test with non-zero shift'\n write(*,*) 'status = ', status%status, ' returned'\n fails = fails + 1\n status%status = 0\n end if\n\n ! now look for nd = Delta with a non-zero shift?\n g = 1.0_wp\n options%more_sorensen_tiny = 0.01_wp\n Delta = 0.2055_wp\n ! now, get ||d_gn|| <= Delta\n call more_sorensen(A,g,n,m,Delta,d,normd,options,status,& \n work%calculate_step_ws%more_sorensen_ws)\n if (status%status .ne. 0) then\n write(*,*) 'Error: unexpected error in more-sorensen test with non-zero shift'\n write(*,*) 'status = ', status%status, ' returned'\n fails = fails + 1\n status%status = 0\n end if\n call reset_default_options(options)\n options%nlls_method = 3\n! options%more_sorensen_tiny = beta\n ! *todo*\n\n ! now take nd > Delta\n d = 1.0_wp\n Delta = 3.0_wp\n ! now, get ||d_gn|| <= Delta\n call more_sorensen(A,g,n,m,Delta,d,normd,options,status,& \n work%calculate_step_ws%more_sorensen_ws)\n if (status%status .ne. 0) then\n write(*,*) 'Error: unexpected error in more-sorensen test with nd > Delta'\n fails = fails + 1\n status%status = 0\n end if\n\n\n ! get to max_its...\n options%more_sorensen_maxits = 1 \n g = 1.0_wp\n Delta = 3.0_wp\n ! now, get ||d_gn|| <= Delta\n call more_sorensen(A,g,n,m,Delta,d,normd,options,status,& \n work%calculate_step_ws%more_sorensen_ws)\n if (status%status .ne. NLLS_ERROR_MS_MAXITS) then\n write(*,*) 'Error: Expected maximum iterations error in more_sorensen'\n fails = fails + 1\n end if\n status%status = 0\n options%more_sorensen_maxits = 10\n \n call nlls_finalize(work,options)\n call more_sorensen(A,g,n,m,Delta,d,normd,options,status,& \n work%calculate_step_ws%more_sorensen_ws)\n if (status%status .ne. NLLS_ERROR_WORKSPACE_ERROR) then \n write(*,*) 'Error: workspace error not flagged when workspaces not setup'\n fails = fails + 1\n end if\n\n call reset_default_options(options)\n \n end subroutine more_sorensen_tests\n\n subroutine trust_region_subproblem_tests(options,fails)\n\n type( nlls_options ), intent(inout) :: options\n integer, intent(out) :: fails\n \n real(wp), allocatable :: g(:), d(:), A(:,:)\n real(wp) :: Delta, normd\n type( nlls_inform ) :: status\n type( nlls_workspace ) :: work\n type( nlls_workspace ), Target :: iw\n integer :: n,m\n integer :: problem, method\n character (len=40) :: problem_name\n character (len=40) :: method_name\n integer :: num_successful_steps\n \n fails = 0\n work%iw_ptr => iw\n iw%iw_ptr => iw\n\n options%out = 6\n options%print_level = 0\n \n n = 4\n m = 5\n allocate(A(n,n), g(n), d(n))\n\n do problem = 1, 6\n select case (problem)\n case (1,2) ! Convex, within the tr radius\n g = 1.0_wp\n A = 0.0_wp\n A(1,1) = 1.0_wp\n A(2,2) = 2.0_wp\n A(3,3) = 3.0_wp\n A(4,4) = 4.0_wp\n\n if (problem == 1) then\n Delta = 1.0_wp ! point lies on the tr radius\n elseif (problem == 2) then \n Delta = 3.0_wp ! point lies in the tr radius\n end if\n \n write(problem_name,'(A,ES12.4)') '7.3.1.1, Delta = ',Delta\n case (3,4) ! Nonconvex\n g = 1.0_wp\n A = 0.0_wp \n A(1,1) = -2.0_wp\n A(2,2) = -1.0_wp\n A(3,3) = 0.0_wp\n A(4,4) = 1.0_wp\n if (problem == 3) then\n Delta = 1.0_wp ! point lies on the tr radius\n elseif (problem == 4) then \n Delta = 3.0_wp ! point lies in the tr radius\n end if\n \n write(problem_name,'(A,ES12.4)') '7.3.1.2, Delta = ',Delta\n case (5,6) ! hard case\n g = 1.0_wp\n g(1) = 0.0_wp\n A = 0.0_wp \n A(1,1) = -2.0_wp\n A(2,2) = -1.0_wp\n A(3,3) = 0.0_wp\n A(4,4) = 1.0_wp\n if (problem == 5) then\n Delta = 1.0_wp ! point lies on the tr radius\n elseif (problem == 6) then \n Delta = 1.5_wp ! point lies in the tr radius\n end if\n write(problem_name,'(A,ES12.4)') '7.3.1.3, Delta = ',Delta\n end select\n do method = 1,3 ! now, let's loop through the methods available...\n select case (method)\n case (1) ! more sorensen, eigenvalues\n method_name = 'more sorensen, eigenvalues'\n options%nlls_method = 3 \n options%use_ews_subproblem = .true.\n call setup_workspaces(work,n,m,options,status)\n call more_sorensen(A,g,n,m,Delta,d,normd,options,status,& \n work%calculate_step_ws%more_sorensen_ws)\n case (2) ! dltr\n method_name = 'dltr'\n options%nlls_method = 4\n num_successful_steps = 0 \n call setup_workspaces(work,n,m,options,status)\n call solve_galahad(A,g,n,m,Delta,num_successful_steps,& \n d,normd,2.0_wp,options,status,&\n work%calculate_step_ws%solve_galahad_ws )\n case (3) ! more sorensen, no eigenvalues\n method_name = 'more_sorensen, no eigenvalues'\n options%nlls_method = 3\n options%use_ews_subproblem = .false.\n call setup_workspaces(work,n,m,options,status)\n call more_sorensen(A,g,n,m,Delta,d,normd,options,status,& \n work%calculate_step_ws%more_sorensen_ws) \n end select\n if (options%print_level > 0 ) then \n write(*,*) 'method = ', method_name, ' problem = ', problem_name, 'normd = ', normd\n end if\n if ( (status%status .ne. 0)) then\n write(*,*) 'Error: unexpected error in ', method_name\n write(*,*) '(status = ',status%status,')'\n write(*,*) 'TR Book Example ',problem_name\n fails = fails + 1\n status%status = 0\n elseif ( normd - Delta > 1e-3 ) then\n write(*,*) 'Error: answer returned outside the TR Radius'\n write(*,*) 'TR Book Example ', trim(problem_name),' using method ',method_name\n write(*,*) 'Delta = ', Delta, '||d|| = ', normd\n fails = fails + 1\n status%status = 0\n end if\n end do \n end do\n\n options%out = 17\n \n end subroutine trust_region_subproblem_tests\n \n subroutine evaluate_model_tests(options,fails)\n \n type( nlls_options ), intent(inout) :: options\n integer, intent(out) :: fails\n \n real(wp), allocatable :: f(:), J(:), hf(:), X(:), Xnew(:), d(:)\n real(wp) :: md, md_gn\n integer :: m, n\n type( nlls_inform ) :: status\n type( nlls_workspace ) :: work\n type( nlls_workspace ), Target :: iw\n \n real(wp) :: one = 1.0_wp\n\n fails = 0\n work%iw_ptr => iw\n iw%iw_ptr => iw\n n = 2\n m = 4\n \n allocate(f(m), J(n*m), hf(n*n), X(n), Xnew(n), d(n))\n f = one\n J = one\n hf = one \n X = one\n Xnew = one\n \n call evaluate_model(f,J,hf,X,Xnew,d,md,md_gn,m,n,options,status,& \n work%calculate_step_ws%evaluate_model_ws)\n if (status%status .ne. NLLS_ERROR_WORKSPACE_ERROR) then \n write(*,*) 'Error: workspace error not flagged when workspaces not setup'\n fails = fails + 1\n end if\n \n \n call reset_default_options(options)\n \n end subroutine evaluate_model_tests\n\n subroutine solve_galahad_tests(options,fails)\n \n type( nlls_options ), intent(inout) :: options\n integer, intent(out) :: fails\n \n real(wp), allocatable :: g(:), d(:), A(:,:)\n real(wp) :: Delta, normd\n type( nlls_inform ) :: status\n type( nlls_workspace ) :: work\n type( nlls_workspace ), Target :: iw\n integer :: n,m, i, num_successful_steps\n character (len=5) :: testname\n \n fails = 0\n work%iw_ptr => iw\n iw%iw_ptr => iw\n\n options%nlls_method = 4\n \n n = 2\n m = 5\n \n num_successful_steps = 0 \n \n allocate(A(n,n), g(n), d(n))\n\n do i = 1,2\n options%type_of_method = i\n if (i == 1) then \n testname = 'DTRS '\n elseif (i == 2) then \n testname = 'DRQS '\n end if\n \n call setup_workspaces(work,n,m,options,status) \n \n A(1,1) = 10.0\n A(1,2) = 2.0\n A(2,1) = 2.0\n A(2,2) = 10.0\n g = [-7.4, -28.9]\n Delta = 0.02_wp\n call solve_galahad(A,g,n,m,Delta,num_successful_steps,& \n d,normd,2.0_wp,options,status,&\n work%calculate_step_ws%solve_galahad_ws )\n if ( status%status .ne. 0 ) then\n write(*,*) testname,'test failed, status = ', status%status\n fails = fails + 1\n end if\n \n if (i == 1) then\n ! check result lies within the trust region\n if ( abs(dot_product(d,d) - Delta**2) > 1e-12 ) then\n write(*,*) testname,'failed'\n write(*,*) 'Delta = ', Delta, '||d|| = ', dot_product(d,d)\n fails = fails + 1\n end if\n end if\n\n \n Delta = -100.0_wp\n call solve_galahad(A,g,n,m,Delta,num_successful_steps,& \n d,normd,2.0_wp,options,status,&\n work%calculate_step_ws%solve_galahad_ws )\n if ( status%status .ne. NLLS_ERROR_FROM_EXTERNAL ) then\n write(*,*) testname,'test failed, expected status = ', NLLS_ERROR_FROM_EXTERNAL\n write(*,*) ' but got status = ', status%status\n fails = fails + 1\n end if\n status%status = 0\n\n call nlls_finalize(work,options)\n \n end do\n\n call reset_default_options(options)\n \n end subroutine solve_galahad_tests\n\n subroutine solve_newton_tensor_tests(options,fails)\n \n type( nlls_options ), intent(inout) :: options\n integer, intent(out) :: fails\n \n real(wp), allocatable :: J(:), f(:), X(:), d(:)\n real(wp) :: Delta, md\n integer :: n, m, num_successful_steps\n type( params_base_type ) :: params\n type( nlls_inform ) :: status\n type( nlls_workspace ) :: work\n type( tenJ_type ), Target :: tenJ\n type( tenJ_type ), Pointer :: tenJ_pointer\n type( NLLS_workspace ), Target :: inner_workspace\n real(wp) :: one = 1.0_wp\n \n fails = 0\n tenJ_pointer => tenJ\n work%iw_ptr => inner_workspace\n inner_workspace%iw_ptr => inner_workspace\n \n n = 3 \n m = 5\n allocate(J(n*m),f(m),X(n),d(n))\n J = one\n f = one\n X = one\n\n num_successful_steps = 0\n \n call solve_newton_tensor(J, f, eval_H, X, n, m, Delta, num_successful_steps, & \n d, md, params, options, status, & \n work%calculate_step_ws%solve_newton_tensor_ws,&\n tenJ_pointer, inner_workspace)\n if (status%status .ne. NLLS_ERROR_WORKSPACE_ERROR) then \n write(*,*) 'Error: workspace error not flagged when workspaces not setup'\n fails = fails + 1\n end if\n \n \n call reset_default_options(options)\n \n end subroutine solve_newton_tensor_tests\n\n subroutine all_eig_symm_tests(options,fails)\n \n type( nlls_options ), intent(inout) :: options\n integer, intent(out) :: fails\n \n real(wp), allocatable :: A(:,:), ew(:), ev(:,:)\n integer :: n\n type( nlls_workspace ) :: work\n type( nlls_inform ) :: status\n \n real(wp) :: one = 1.0_wp\n\n fails = 0\n\n n = 2\n allocate(A(n,n), ew(n), ev(n,n))\n A = one\n\n call all_eig_symm(A,n,ew,ev, & \n work%calculate_step_ws%solve_galahad_ws%all_eig_symm_ws, status)\n if (status%status .ne. NLLS_ERROR_WORKSPACE_ERROR) then \n write(*,*) 'Error: workspace error not flagged when workspaces not setup'\n fails = fails + 1\n end if\n \n call reset_default_options(options)\n \n end subroutine all_eig_symm_tests\n\n subroutine solve_LLS_tests(options,fails)\n \n type( nlls_options ), intent(inout) :: options\n integer, intent(out) :: fails\n \n real(wp), allocatable :: J(:), f(:), d(:), Jd(:)\n real(wp) :: normerror\n integer :: n,m \n type( nlls_workspace ) :: work\n type( nlls_workspace ), Target :: iw\n type( nlls_inform ) :: status\n\n fails = 0\n work%iw_ptr => iw\n iw%iw_ptr => iw\n\n options%nlls_method = 1 ! dogleg\n\n n = 2\n m = 5\n\n call setup_workspaces(work,n,m,options,status) \n\n allocate(J(n*m), f(m), d(n), Jd(m))\n J = [ 1.0_wp, 2.0_wp, 3.0_wp, 4.0_wp, 5.0_wp, & \n 6.0_wp, 7.0_wp, 8.0_wp, 9.0_wp, 10.0_wp ]\n f = [ 7.0_wp, 9.0_wp, 11.0_wp, 13.0_wp, 15.0_wp ]\n\n call solve_LLS(J,f,n,m,d,status, & \n work%calculate_step_ws%dogleg_ws%solve_LLS_ws)\n if ( status%status .ne. 0 ) then \n write(*,*) 'solve_LLS test failed: wrong error message returned'\n write(*,*) 'status = ', status%status, \" (expected \",NLLS_ERROR_FROM_EXTERNAL,\")\"\n fails = fails + 1\n end if\n ! check answer\n call mult_J(J,n,m,d,Jd)\n normerror = norm2(Jd + f)\n if ( normerror > 1.0e-12_wp ) then\n ! wrong answer, as data chosen to fit\n write(*,*) 'solve_LLS test failed: wrong solution returned'\n write(*,*) '||Jd - f|| = ', normerror\n fails = fails + 1\n end if\n \n n = 100 \n m = 20\n deallocate(J,f,Jd,d)\n allocate(J(n*m), f(m), d(n)) ! f has wrong size\n \n call setup_workspaces(work,n,m,options,status) \n\n J = 1.0_wp\n f = 1.0_wp\n call solve_LLS(J,f,n,m,d,status, & \n work%calculate_step_ws%dogleg_ws%solve_LLS_ws)\n if ( status%status .ne. NLLS_ERROR_FROM_EXTERNAL ) then \n write(*,*) 'solve_LLS test failed: wrong error message returned'\n write(*,*) 'status = ', status%status, \" (expected \",NLLS_ERROR_FROM_EXTERNAL,\")\"\n fails = fails + 1\n end if\n status%status = 0\n\n call nlls_finalize(work, options)\n \n call solve_LLS(J,f,n,m,d,status, & \n work%calculate_step_ws%dogleg_ws%solve_LLS_ws)\n if (status%status .ne. NLLS_ERROR_WORKSPACE_ERROR) then \n write(*,*) 'Error: workspace error not flagged when workspaces not setup'\n fails = fails + 1\n end if\n\n \n call reset_default_options(options)\n \n end subroutine solve_LLS_tests\n\n\n subroutine findbeta_tests(options,fails)\n \n type( nlls_options ), intent(inout) :: options\n integer, intent(out) :: fails\n \n real(wp), allocatable :: a(:), b(:)\n real(wp) :: Delta, beta\n type( nlls_inform ) :: status\n integer :: n\n \n fails = 0 \n\n n = 3\n allocate(a(n), b(n))\n a = [ 1.0, 2.0, 3.0 ]\n b = [ 2.0, 1.0, 1.0 ]\n\n call findbeta(a,b,10.0_wp,beta,status)\n\n if (status%status .ne. 0) then\n write(*,*) 'error -- findbeta did not work: info /= 0'\n fails = fails + 1\n else if ( ( norm2( a + beta * b ) - 10.0_wp ) > 1e-12 ) then\n write(*,*) 'error -- findbeta did not work'\n write(*,*) '|| x + beta y|| = ', norm2( (a + beta * b)-10.0_wp)\n fails = fails + 1\n end if\n \n deallocate(a,b)\n \n n = 2\n allocate(a(n),b(n))!,z(n))\n \n a(1) = 1e25_wp\n a(2) = 0.0_wp\n b(1) = 0.0_wp\n b(2) = 1.0_wp\n Delta = 1e-8_wp\n beta = 0.0_wp\n\n call findbeta(a,b,Delta,beta,status)\n\n if (status%status .ne. NLLS_ERROR_FIND_BETA) then\n write(*,*) 'Expected an error from findbeta: info =', status%status\n write(*,*) 'beta returned = ', beta\n write(*,*) '|| x + beta y|| = ', norm2( (a + beta * b) )\n fails = fails + 1\n end if\n\n call reset_default_options(options)\n \n end subroutine findbeta_tests\n\n subroutine calculate_rho_tests(options,fails)\n \n type( nlls_options ), intent(inout) :: options\n integer, intent(out) :: fails\n \n real(wp) :: normf, normfnew, md, rho\n\n fails = 0 \n\n normf = 2.0_wp\n normfnew = 1.0_wp\n md = 1.5_wp\n call calculate_rho(normf, normfnew, md, rho,options)\n if ( abs(rho - 3.0_wp) > 1e-10) then\n write(*,*) 'Unexpected answer from calculate_rho'\n write(*,*) 'Expected 3.0, got ', rho\n fails = fails + 1\n end if\n \n ! now, let's check one is returned if alpha = beta\n normfnew = 2.0_wp\n call calculate_rho(normf, normfnew, md, rho,options)\n if (abs(rho - 1.0_wp) > 1e-10) then\n write(*,*) 'Unexpected answer from calculate_rho'\n write(*,*) 'Expected 1.0, got ', rho\n fails = fails + 1\n end if\n normfnew = 1.0_wp\n\n ! finally, check that 1 is returned if denominator = 0\n md = 2.0_wp\n call calculate_rho(normf, normfnew, md, rho,options)\n if (abs(rho - 1.0_wp) > 1e-10) then\n write(*,*) 'Unexpected answer from calculate_rho'\n write(*,*) 'Expected 1.0, got ', rho\n fails = fails + 1\n end if\n \n call reset_default_options(options)\n \n end subroutine calculate_rho_tests\n\n subroutine update_trust_region_radius_tests(options,fails)\n \n type( nlls_options ), intent(inout) :: options\n integer, intent(out) :: fails\n \n real(wp) :: rho\n type( nlls_inform ) :: status\n type( nlls_workspace ) :: work\n type( nlls_workspace ), Target :: iw\n \n fails = 0 \n work%iw_ptr => iw\n iw%iw_ptr => iw\n\n call setup_workspaces(work,2,2,options,status) \n work%Delta = 100.0_wp ! Delta\n work%tr_nu = 2.0_wp ! nu\n work%tr_p = 3 ! p\n ! rho = rho\n\n options%tr_update_strategy = 1\n ! let's go through the options\n \n options%eta_success_but_reduce = 0.25_wp\n options%eta_very_successful = 0.75_wp\n options%eta_too_successful = 2.0_wp\n\n ! check if rho reduced...\n rho = options%eta_success_but_reduce - 0.5_wp\n call update_trust_region_radius(rho,options,status,work)\n if ( work%Delta >= 100.0_wp ) then\n write(*,*) 'Unexpected answer from update_trust_region_radius'\n write(*,*) 'Delta did not decrease as expected: delta = ', work%Delta\n fails = fails + 1\n end if\n work%Delta = 100.0_wp\n \n ! check if rho stays the same...\n rho = (options%eta_success_but_reduce + options%eta_very_successful) / 2\n call update_trust_region_radius(rho,options,status,work)\n if ( abs(work%Delta - 100.0_wp) > 1e-12 ) then\n write(*,*) 'Unexpected answer from update_trust_region_radius'\n write(*,*) 'Delta did not stay the same: Delta = ', work%Delta\n fails = fails + 1\n end if\n work%Delta = 100.0_wp\n\n ! check if rho increases...\n rho = (options%eta_very_successful + options%eta_too_successful) / 2\n work%norm_S_d = 100.0_wp\n call update_trust_region_radius(rho,options,status,work)\n if ( work%Delta <= 100.0_wp ) then\n write(*,*) 'Unexpected answer from update_trust_region_radius'\n write(*,*) 'Delta did not incease: delta = ', work%Delta\n fails = fails + 1\n end if\n work%Delta = 100.0_wp\n\n \n ! check if rho stays the same because too successful...\n rho = options%eta_too_successful + 1.0_wp\n call update_trust_region_radius(rho,options,status,work)\n if ( abs(work%Delta - 100.0_wp) > 1e-12 ) then\n write(*,*) 'Unexpected answer from update_trust_region_radius'\n write(*,*) 'Delta did not stay the same: delta = ', work%Delta\n fails = fails + 1\n end if\n work%Delta = 100.0_wp\n\n ! now check for NaNs...HOW to do this in a non-compiler dependent way!?!?\n\n !! now, let's check the other option....\n options%tr_update_strategy = 2\n \n ! check if rho increases...\n rho = (options%eta_very_successful + options%eta_too_successful) / 2\n call update_trust_region_radius(rho,options,status,work)\n if ( work%Delta <= 100.0_wp ) then\n write(*,*) 'Unexpected answer from update_trust_region_radius'\n write(*,*) 'Delta did not incease: delta = ', work%Delta\n fails = fails + 1\n end if\n work%Delta = 100.0_wp\n \n ! check if rho stays the same because too successful...\n rho = options%eta_too_successful + 1.0_wp\n call update_trust_region_radius(rho,options,status,work)\n if ( abs(work%Delta - 100.0_wp) > 1e-12 ) then\n write(*,*) 'Unexpected answer from update_trust_region_radius'\n write(*,*) 'Delta did not stay the same: delta = ', work%Delta\n fails = fails + 1\n end if\n work%Delta = 100.0_wp\n\n rho = options%eta_success_but_reduce - 0.5_wp\n call update_trust_region_radius(rho,options,status,work)\n if ( work%Delta >= 100.0_wp ) then\n write(*,*) 'Unexpected answer from update_trust_region_radius'\n write(*,*) 'Delta did not decrease as expected: delta = ', work%Delta\n fails = fails + 1\n end if\n work%Delta = 100.0_wp\n\n rho = options%eta_successful - 10.0_wp\n call update_trust_region_radius(rho,options,status,work)\n if ( work%Delta >= 100.0_wp ) then\n write(*,*) 'Unexpected answer from update_trust_region_radius'\n write(*,*) 'Delta did not decrease as expected: delta = ', work%Delta\n fails = fails + 1\n end if\n work%Delta = 100.0_wp\n \n ! again...NaN test should go here!!!\n\n !Finally, check the error cases...\n \n options%tr_update_strategy = 18\n call update_trust_region_radius(rho,options,status,work)\n if ( status%status .ne. NLLS_ERROR_BAD_TR_STRATEGY ) then\n write(*,*) 'Unexpected answer from update_trust_region_radius'\n write(*,*) 'Error returned is = ', status%status, ', expected ',NLLS_ERROR_BAD_TR_STRATEGY\n fails = fails + 1\n end if\n status%status = 0\n work%Delta = 100.0_wp\n\n\n \n call reset_default_options(options)\n \n end subroutine update_trust_region_radius_tests\n\n subroutine test_convergence_tests(options,fails)\n \n type( nlls_options ), intent(inout) :: options\n integer, intent(out) :: fails\n \n real(wp) :: normF, normJf, normF0, normJF0, normd\n type( nlls_inform ) :: status\n\n fails = 0\n \n ! hit the case where f = 0 \n normF = 0.0_wp\n normJf = 0.0_wp\n normF0 = 1.0_wp\n normJF0 = 1.0_wp\n normd = 0.0_wp\n call test_convergence(normF,normJf,normF0,normJF0,normd, options, status)\n if ( status%convergence_normf .ne. 1) then\n write(*,*) 'Error in test_convergence test :: expected status%convergence_normf = 1'\n write(*,*) 'got status%convergence_normf = ', status%convergence_normf\n fails = fails + 1\n end if\n\n call reset_default_options(options)\n \n end subroutine test_convergence_tests\n\n subroutine mult_J_tests(options,fails) \n\n type( nlls_options ), intent(inout) :: options\n integer, intent(out) :: fails\n \n real(wp), allocatable :: J(:), x(:), Jx(:)\n integer :: n, m \n\n fails = 0 \n \n n = 2\n m = 4\n allocate(J(n*m), x(m), Jx(n))\n \n x = 1.0_wp\n J = [ 1.0 , 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]\n call mult_J(J,m,n,x,Jx)\n if ( norm2( Jx - [16.0, 20.0 ] ) > 1e-12) then\n write(*,*) 'error :: mult_J test failed'\n fails = fails + 1\n end if\n \n call reset_default_options(options)\n \n end subroutine mult_J_tests\n\n subroutine mult_Jt_tests(options,fails)\n \n type( nlls_options ), intent(inout) :: options\n integer, intent(out) :: fails\n \n real(wp), allocatable :: J(:), x(:), Jtx(:)\n integer :: n, m \n \n fails = 0\n\n n = 2\n m = 4\n allocate( J(n*m) ) \n allocate( x(m) ) \n allocate( Jtx(n) )\n \n x = 1.0_wp\n J = [ 1.0 , 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]\n call mult_Jt(J,n,m,x,Jtx)\n if ( norm2( Jtx - [10.0, 26.0 ] ) > 1e-12) then\n write(*,*) 'error :: mult_Jt test failed'\n fails = fails + 1\n end if\n \n call reset_default_options(options)\n \n end subroutine mult_Jt_tests\n\n\n \n\n subroutine switch_to_quasi_newton_tests(options,fails)\n \n type( nlls_options), intent(inout) :: options\n integer, intent(out) :: fails\n\n integer :: n, m\n TYPE( nlls_inform ) :: inform\n type( nlls_workspace ) :: w\n type( nlls_workspace ), Target :: iw\n\n fails = 0\n w%iw_ptr => iw\n iw%iw_ptr => iw\n\n n = 2\n m = 4\n \n options%type_of_method = 2\n options%reg_order = 0.0_wp\n call setup_workspaces(w,n,m,options,inform)\n ! switch_to_quasi_newton expect for w%hf_temp to be defined.\n ! Fill with zeros...\n w%hf_temp(1:n**2) = 0.0_wp\n call switch_to_quasi_newton(w,n,options)\n call remove_workspaces(w,options)\n\n call reset_default_options(options)\n \n end subroutine switch_to_quasi_newton_tests\n\n \n subroutine solve_spd_tests(options,fails)\n \n type( nlls_options ), intent(inout) :: options\n integer, intent(out) :: fails\n \n real(wp), allocatable :: A(:,:), b(:), LtL(:,:), x_calc(:), x_true(:)\n integer :: n\n type( nlls_inform ) :: status\n \n fails = 0\n \n n = 2\n allocate(A(n,n), b(n), LtL(n,n), x_calc(n), x_true(n))\n A = reshape([ 4.0, 1.0, 1.0, 2.0 ], shape(A))\n x_true = [1.0, 1.0]\n b = [5.0, 3.0]\n call solve_spd(A,b,LtL,x_calc,n,status)\n if (status%status .ne. 0) then\n write(*,*) 'Error: info = ', status%status, ' returned from solve_spd'\n fails = fails + 1\n else if (norm2(x_calc-x_true) > 1e-12) then\n write(*,*) 'Error: incorrect value returned from solve_spd'\n fails = fails + 1\n end if\n \n call reset_default_options(options)\n \n end subroutine solve_spd_tests\n\n subroutine solve_general_tests(options,fails)\n \n type( nlls_options ), intent(inout) :: options\n integer, intent(out) :: fails\n \n real(wp), allocatable :: A(:,:), b(:), x_calc(:), x_true(:)\n integer :: n,m\n type( nlls_inform ) :: status\n type( nlls_workspace ) :: work\n type( nlls_workspace ), Target :: iw\n \n fails = 0\n work%iw_ptr => iw\n iw%iw_ptr => iw\n \n n = 2\n m = 3\n \n allocate(A(n,n), b(n), x_calc(n), x_true(n))\n \n options%nlls_method = 2\n options%model = 2\n call setup_workspaces(work,n,m,options,status)\n\n A = reshape([4.0, 1.0, 2.0, 2.0], shape(A))\n x_true = [1.0, 1.0] \n b = [6.0, 3.0]\n\n call solve_general(A,b,x_calc,n,status,& \n work%calculate_step_ws%AINT_tr_ws%solve_general_ws)\n if (status%status .ne. 0) then\n write(*,*) 'Error: info = ', status%status, ' returned from solve_general'\n fails = fails + 1\n status%status = 0\n else if (norm2(x_true-x_calc) > 1e-12) then\n write(*,*) 'Error: incorrect value returned from solve_general'\n fails = fails + 1\n end if\n\n A = reshape( [ 0.0, 0.0, 0.0, 0.0 ],shape(A))\n b = [ 6.0, 3.0 ]\n\n call solve_general(A,b,x_calc,n,status,& \n work%calculate_step_ws%AINT_tr_ws%solve_general_ws)\n if (status%status .ne. NLLS_ERROR_FROM_EXTERNAL) then\n write(*,*) 'Error: expected error return from solve_general, got info = ', status%status\n fails = fails + 1\n end if\n\n call nlls_finalize(work,options)\n call reset_default_options(options)\n \n end subroutine solve_general_tests\n\n subroutine matmult_inner_tests(options,fails)\n \n type( nlls_options ), intent(inout) :: options\n integer, intent(out) :: fails\n \n real(wp), allocatable :: A(:,:), AtA(:,:), AtA_expected(:,:), diff(:)\n integer :: n, m, i\n\n fails = 0 \n \n\n n = 2\n m = 3\n allocate(A(m,n), AtA(n,n), AtA_expected(n,n), diff(n))\n A = reshape( [ 1.0, 2.0, 3.0, &\n 2.0, 4.0, 6.0 ],&\n shape(A))\n call matmult_inner(A,n,m,AtA)\n AtA_expected = reshape( [ 14.0, 28.0, &\n 28.0, 56.0 ] &\n , shape(AtA_expected))\n do i = 1,n\n diff(i) = norm2(AtA(:,i) - AtA_expected(:,i))\n end do\n if (norm2(diff) > 1e-10) then\n write(*,*) 'error :: matmult_inner test failed'\n fails = fails + 1\n end if\n \n call reset_default_options(options)\n \n end subroutine matmult_inner_tests\n\n \n subroutine matmult_outer_tests(options,fails)\n \n type( nlls_options ), intent(inout) :: options\n integer, intent(out) :: fails\n \n real(wp), allocatable :: A(:,:), AAt(:,:), AAt_expected(:,:), diff(:)\n integer :: n, m, i\n \n fails = 0 \n\n n = 2\n m = 3\n allocate(A(m,n), AAt(m,m), AAt_expected(m,m), diff(m))\n A = reshape( [1.0, 2.0, 3.0, &\n 2.0, 4.0, 6.0],&\n shape(A))\n call matmult_outer(A,n,m,AAt)\n AAt_expected = reshape( [ 5.0, 10.0, 15.0, &\n 10.0, 20.0, 30.0, & \n 15.0, 30.0, 45.0 ] &\n , shape(AAt_expected))\n do i = 1,m\n diff(i) = norm2(AAt(:,i) - AAt_expected(:,i))\n end do\n if (norm2(diff) > 1e-10) then\n write(*,*) 'error :: matmult_outer test failed'\n fails = fails + 1\n end if\n \n call reset_default_options(options)\n \n end subroutine matmult_outer_tests\n\n subroutine outer_product_tests(options,fails)\n \n type( nlls_options ), intent(inout) :: options\n integer, intent(out) :: fails\n \n real(wp), allocatable :: x(:), xxt(:,:), xxt_exact(:,:), diff(:)\n integer :: n, i \n \n fails = 0\n\n n = 4\n allocate(x(n), xxt(n,n), xxt_exact(n,n), diff(n))\n x = [ 1.0, 2.0, 3.0, 4.0 ]\n xxt_exact = reshape( [1.0, 2.0, 3.0, 4.0, &\n 2.0, 4.0, 6.0, 8.0, &\n 3.0, 6.0, 9.0, 12.0, & \n 4.0, 8.0, 12.0, 16.0], shape(xxt_exact))\n call outer_product(x,n,xxt)\n do i = 1, n\n diff(i) = norm2(xxt(i,:) - xxt_exact(i,:))\n end do\n if (norm2(diff) > 1e-12) then\n write(*,*) 'error :: outer_product test failed'\n fails = fails +1\n end if\n\n \n call reset_default_options(options)\n \n end subroutine outer_product_tests\n\n subroutine min_eig_symm_tests(options,fails)\n \n type( nlls_options ), intent(inout) :: options\n integer, intent(out) :: fails\n \n real(wp), allocatable :: A(:,:), ev(:)\n real(wp) :: ew\n type( nlls_inform ) :: status\n type( nlls_workspace ) :: work\n type( nlls_workspace ), Target :: iw\n integer :: n, m, i \n \n fails = 0 \n work%iw_ptr => iw\n iw%iw_ptr => iw\n \n n = 4\n m = 4\n\n allocate(ev(n), A(n,n))\n \n ! make sure min_eig_symm gets called\n do i = 1, 2\n ! Setup workspace for n = 4\n ! use this for min_eig_symm\n\n options%nlls_method = 3\n select case (i)\n case (1)\n options%subproblem_eig_fact = .TRUE.\n case (2)\n options%subproblem_eig_fact = .FALSE.\n end select\n\n ! first, remove previous workspace\n call remove_workspaces(work,options)\n call setup_workspaces(work,n,m,options,status) \n if (status%status .ne. 0) then\n write(*,*) 'Error: info = ', status%status, ' when setting up workspace'\n fails = fails +1 \n end if\n \n A = reshape( [-5.0, 1.0, 0.0, 0.0, &\n 1.0, -5.0, 0.0, 0.0, &\n 0.0, 0.0, 4.0, 2.0, & \n 0.0, 0.0, 2.0, 4.0], shape(A))\n\n call min_eig_symm(A,n,ew,ev,options,status, & \n work%calculate_step_ws%more_sorensen_ws%min_eig_symm_ws)\n\n if ( (abs( ew + 6.0 ) > 1e-12).or.(status%status .ne. 0) ) then\n write(*,*) 'error :: min_eig_symm test failed -- wrong eig found'\n fails = fails +1 \n elseif ( norm2(matmul(A,ev) - ew*ev) > 1e-12 ) then\n write(*,*) 'error :: min_eig_symm test failed -- not an eigenvector'\n fails = fails +1 \n end if\n\n call nlls_finalize(work,options)\n\n call min_eig_symm(A,n,ew,ev,options,status, & \n work%calculate_step_ws%more_sorensen_ws%min_eig_symm_ws)\n if (status%status .ne. NLLS_ERROR_WORKSPACE_ERROR) then \n write(*,*) 'Error: workspace error not flagged when workspaces not setup'\n fails = fails + 1\n end if\n \n end do\n\n call reset_default_options(options)\n \n end subroutine min_eig_symm_tests\n\n subroutine max_eig_tests(options,fails)\n \n type( nlls_options ), intent(inout) :: options\n integer, intent(out) :: fails\n \n real(wp), allocatable :: A(:,:), B(:,:), ev(:), nullevs(:,:), shapenull(:), diff(:)\n real(wp) :: ew\n type( nlls_inform ) :: status\n type( nlls_workspace ) :: work\n type( nlls_workspace ), Target :: iw\n integer :: n, m, i \n \n fails = 0 \n work%iw_ptr => iw\n iw%iw_ptr => iw\n \n n = 2\n m = 2\n\n allocate(ev(2*n), A(2*n,2*n), B(2*n,2*n),nullevs(n,2))\n \n options%nlls_method = 2\n call setup_workspaces(work,n,m,options,status)\n \n A = reshape( [ 1.0, 2.0, 3.0, 4.0, &\n 2.0, 4.0, 6.0, 8.0, &\n 3.0, 6.0, 9.0, 12.0, & \n 4.0, 8.0, 12.0,16.0 ], shape(A))\n B = 0.0_wp\n do i = 1,2*n\n B(i,i) = real(i,wp)\n end do\n !alpha = 1.0_wp\n !x = 0.0_wp\n call max_eig(A,B,2*n,ew,ev,nullevs,options,status, & \n work%calculate_step_ws%AINT_tr_ws%max_eig_ws)\n if ( status%status .ne. 0 ) then\n write(*,*) 'error :: max_eig test failed, status = ', status%status\n fails = fails + 1 \n elseif ( (abs( ew - 10.0_wp) > 1e-12) ) then\n write(*,*) 'error :: max_eig test failed, incorrect answer'\n write(*,*) 'expected 10.0, got ', ew\n fails = fails + 1\n end if\n\n A = 0.0_wp\n A(3,1) = 1.0_wp; A(4,1) = 2.0_wp; A(3,2) = 3.0_wp; A(4,2) = 4.0_wp\n A(1,3) = A(3,1); A(1,4) = A(4,1); A(2,3) = A(3,2); A(2,4) = A(4,2)\n B = A\n A(1,1) = 1.0_wp; A(2,2) = 1.0_wp\n \n deallocate(nullevs)\n call max_eig(A,B,2*n,ew,ev,nullevs,options,status, & \n work%calculate_step_ws%AINT_tr_ws%max_eig_ws)\n if (.not. allocated(nullevs)) then ! check C returned \n write(*,*) 'error :: hard case of max_eig test failed - C not returned'\n fails = fails + 1\n else\n allocate(shapenull(2))\n shapenull = shape(nullevs)\n if ((shapenull(1) .ne. 2) .or. (shapenull(2) .ne. 2*n)) then\n write(*,*) 'error :: hard case of max_eig test failed - wrong shape C returned'\n write(*,*) 'shapenull(1) = ', shapenull(1), 'shapenull(2) = ', shapenull(2)\n fails = fails + 1\n else\n allocate(diff(n))\n ! Repopulate A (was overwritten by eig routine)\n A = 0.0_wp \n A(3,1) = 1.0_wp; A(4,1) = 2.0_wp; A(3,2) = 3.0_wp; A(4,2) = 4.0_wp\n A(1,3) = A(3,1); A(1,4) = A(4,1); A(2,3) = A(3,2); A(2,4) = A(4,2)\n B = A\n A(1,1) = 1.0_wp; A(2,2) = 1.0_wp\n do i = 1, n\n diff(i) = norm2( &\n matmul( A(3:4,3:4),nullevs(1:2,i) ) &\n - ew * matmul(B(3:4,3:4),nullevs(1:2,i)) & \n )\n end do\n if (norm2(diff) > 1e-10) then\n write(*,*) 'error :: hard case of max_eig test failed - wrong vectors returned'\n write(*,*) 'diff = ', diff\n fails = fails + 1\n end if\n end if\n end if\n \n call remove_workspaces(work, options)\n\n deallocate(ev,A,B)\n \n n = 1\n m = 1\n call setup_workspaces(work, n, m, options, status)\n\n ! check the error return\n allocate(ev(2*n), A(2*n,2*n), B(2*n,2*n))\n A = 0.0_wp\n B = 0.0_wp\n A(1,2) = 1.0_wp\n A(2,1) = -1.0_wp\n B(1,1) = 1.0_wp\n B(2,2) = 1.0_wp\n\n call max_eig(A,B,2*n,ew,ev,nullevs,options,status, & \n work%calculate_step_ws%AINT_tr_ws%max_eig_ws)\n if (status%status .ne. NLLS_ERROR_AINT_EIG_IMAG) then\n write(*,*) 'error :: all complex part of max_eig test failed'\n fails = fails + 1\n end if\n status%status = 0\n\n call max_eig(A,B,2*n+1,ew,ev,nullevs, options,status, &\n work%calculate_step_ws%AINT_tr_ws%max_eig_ws)\n if ( status%status .ne. NLLS_ERROR_AINT_EIG_ODD ) then\n write(*,*) 'error :: even part of max_eig test failed'\n fails = fails + 1\n end if\n status%status = 0\n\n call nlls_finalize(work,options)\n\n ! now let's check for workspace error\n call max_eig(A,B,2*n+1,ew,ev,nullevs, options,status, &\n work%calculate_step_ws%AINT_tr_ws%max_eig_ws)\n if (status%status .ne. NLLS_ERROR_WORKSPACE_ERROR) then \n write(*,*) 'Error: workspace error not flagged when workspaces not setup'\n fails = fails + 1 \n end if\n\n \n call reset_default_options(options)\n \n end subroutine max_eig_tests\n\n subroutine shift_matrix_tests(options,fails)\n \n type( nlls_options ), intent(inout) :: options\n integer, intent(out) :: fails\n \n real(wp), allocatable :: A(:,:), AplusSigma(:,:)\n real(wp) :: sigma\n integer :: n\n \n fails = 0 \n\n n = 2\n\n allocate(A(n,n),AplusSigma(n,n))\n A = 1.0_wp\n AplusSigma = 0.0_wp\n sigma = 5.0_wp\n call shift_matrix(A,sigma,AplusSigma,n)\n if ( ( (AplusSigma(1,1)-6.0_wp) > 1e-12) .or. &\n ((AplusSigma(2,2) - 6.0_wp) > 1e-12) ) then\n write(*,*) 'Error: incorrect return from shift_matrix'\n fails = fails + 1\n elseif ( ( (AplusSigma(1,2)-1.0_wp) > 1e-12) .or. & \n ((AplusSigma(2,1) - 1.0_wp) > 1e-12) ) then\n write(*,*) 'Error: incorrect return from shift_matrix'\n fails = fails + 1\n end if\n \n call reset_default_options(options)\n \n end subroutine shift_matrix_tests\n \n \n subroutine error_message_tests(options,fails)\n \n type( nlls_options ), intent(inout) :: options\n integer, intent(out) :: fails\n \n real(wp), allocatable :: X(:)\n type( user_type ) :: params\n type( nlls_inform ) :: status\n character (len = 80) :: expected_string\n \n integer :: n, m\n \n\n fails = 0\n n = 2\n m = 67\n\n allocate(params%x_values(m))\n allocate(params%y_values(m))\n \n call generate_data_example(params)\n \n ! let's check the workspace errors \n ! first, let's do the main workspace...\n allocate(X(n))\n options%setup_workspaces = .false.\n call nlls_solve(n, m, X, &\n eval_F, eval_J, eval_H, params, &\n options, status)\n if (status%status .ne. NLLS_ERROR_WORKSPACE_ERROR) then \n write(*,*) 'Error: workspace error not flagged when workspaces not setup'\n write(*,*) 'status = ', status%status\n fails = fails + 1\n end if\n\n \n ! nlls_strerror\n status%status = NLLS_ERROR_MAXITS\n call nlls_strerror(status)\n expected_string = 'Maximum number of iterations reached'\n if (status%error_message .ne. expected_string) then \n write(*,*) 'Error: incorrect string returned from nlls_strerror when status = ', &\n status%status\n fails = fails + 1\n end if\n\n status%status = NLLS_ERROR_EVALUATION\n status%external_name = 'nlls_test'\n status%external_return = -1\n write(expected_string,'(a,a,a,i0)') & \n 'Error code from user-supplied subroutine ',trim(status%external_name), & \n ' passed error = ', status%external_return\n call nlls_strerror(status)\n if (status%error_message .ne. expected_string) then \n write(*,*) 'Error: incorrect string returned from nlls_strerror when status = ', &\n status%status\n fails = fails + 1\n end if\n\n status%status = NLLS_ERROR_UNSUPPORTED_MODEL\n call nlls_strerror(status)\n expected_string = 'Unsupported model passed in options'\n if (status%error_message .ne. expected_string) then \n write(*,*) 'Error: incorrect string returned from nlls_strerror when status = ', &\n status%status\n fails = fails + 1\n end if\n\n status%status = NLLS_ERROR_FROM_EXTERNAL\n call nlls_strerror(status)\n write(expected_string,'(a,a,a,i0)') & \n 'The external subroutine ',trim(status%external_name), & \n ' passed error = ', status%external_return\n if (status%error_message .ne. expected_string) then \n write(*,*) 'Error: incorrect string returned from nlls_strerror when status = ', &\n status%status\n fails = fails + 1\n end if\n\n status%status = NLLS_ERROR_MAXITS\n call nlls_strerror(status)\n expected_string = 'Maximum number of iterations reached'\n if (status%error_message .ne. 'Maximum number of iterations reached') then \n write(*,*) 'Error: incorrect string returned from nlls_strerror when status = ', &\n status%status\n fails = fails + 1\n end if\n \n status%status = NLLS_ERROR_UNSUPPORTED_METHOD\n call nlls_strerror(status)\n expected_string = 'Unsupported nlls_method passed in options'\n if (status%error_message .ne. expected_string) then \n write(*,*) 'Error: incorrect string returned from nlls_strerror when status = ', &\n status%status\n fails = fails + 1\n end if\n\n status%status = NLLS_ERROR_ALLOCATION\n status%bad_alloc = \"nlls_test\"\n call nlls_strerror(status)\n write(expected_string,'(a,a)') &\n 'Bad allocation of memory in ', trim(status%bad_alloc)\n if (status%error_message .ne. expected_string) then \n write(*,*) 'Error: incorrect string returned from nlls_strerror when status = ', &\n status%status\n fails = fails + 1\n end if\n\n status%status = NLLS_ERROR_MAX_TR_REDUCTIONS\n call nlls_strerror(status)\n expected_string = 'The trust region was reduced the maximum number of times'\n if (status%error_message .ne. expected_string) then \n write(*,*) 'Error: incorrect string returned from nlls_strerror when status = ', &\n status%status\n fails = fails + 1\n end if\n \n status%status = NLLS_ERROR_MAX_TR_REDUCTIONS\n call nlls_strerror(status)\n expected_string = 'The trust region was reduced the maximum number of times'\n if (status%error_message .ne. expected_string) then \n write(*,*) 'Error: incorrect string returned from nlls_strerror when status = ', &\n status%status\n fails = fails + 1\n end if\n\n\n status%status = NLLS_ERROR_X_NO_PROGRESS\n call nlls_strerror(status)\n expected_string = 'No progress made in X'\n if (status%error_message .ne. expected_string) then \n write(*,*) 'Error: incorrect string returned from nlls_strerror when status = ', &\n status%status\n fails = fails + 1\n end if\n\n\n status%status = NLLS_ERROR_N_GT_M\n call nlls_strerror(status)\n expected_string = 'The problem is overdetermined'\n if (status%error_message .ne. expected_string) then \n write(*,*) 'Error: incorrect string returned from nlls_strerror when status = ', &\n status%status\n fails = fails + 1\n end if\n\n\n status%status = NLLS_ERROR_BAD_TR_STRATEGY\n call nlls_strerror(status)\n expected_string = 'Unsupported tr_update_stategy passed in options'\n if (status%error_message .ne. expected_string) then \n write(*,*) 'Error: incorrect string returned from nlls_strerror when status = ', &\n status%status\n fails = fails + 1\n end if\n\n\n status%status = NLLS_ERROR_FIND_BETA\n call nlls_strerror(status)\n expected_string = 'Unable to find suitable scalar in findbeta subroutine'\n if (status%error_message .ne. expected_string) then \n write(*,*) 'Error: incorrect string returned from nlls_strerror when status = ', &\n status%status\n fails = fails + 1\n end if\n\n\n status%status = NLLS_ERROR_BAD_SCALING\n call nlls_strerror(status)\n expected_string = 'Unsupported value of scale passed in options'\n if (status%error_message .ne. expected_string) then \n write(*,*) 'Error: incorrect string returned from nlls_strerror when status = ', &\n status%status\n fails = fails + 1\n end if\n\n\n status%status = NLLS_ERROR_WORKSPACE_ERROR\n call nlls_strerror(status)\n expected_string = 'Error accessing pre-allocated workspace'\n if (status%error_message .ne. expected_string) then \n write(*,*) 'Error: incorrect string returned from nlls_strerror when status = ', &\n status%status\n fails = fails + 1\n end if\n\n status%status = NLLS_ERROR_UNSUPPORTED_TYPE_METHOD\n call nlls_strerror(status)\n expected_string = 'Unsupported value of type_of_method passed in options'\n if (status%error_message .ne. expected_string) then \n write(*,*) 'Error: incorrect string returned from nlls_strerror when status = ', &\n status%status\n fails = fails + 1\n end if\n\n status%status = NLLS_ERROR_DOGLEG_MODEL\n call nlls_strerror(status)\n expected_string = 'Model not supported in dogleg (nlls_method=1)'\n if (status%error_message .ne. expected_string) then \n write(*,*) 'Error: incorrect string returned from nlls_strerror when status = ', &\n status%status\n fails = fails + 1\n end if\n\n\n status%status = NLLS_ERROR_AINT_EIG_IMAG\n call nlls_strerror(status)\n expected_string = 'All eigenvalues are imaginary (nlls_method=2)'\n if (status%error_message .ne. expected_string) then \n write(*,*) 'Error: incorrect string returned from nlls_strerror when status = ', &\n status%status\n fails = fails + 1\n end if\n\n\n status%status = NLLS_ERROR_AINT_EIG_ODD\n call nlls_strerror(status)\n expected_string = 'Odd matrix sent to max_eig subroutine (nlls_method=2)'\n if (status%error_message .ne. expected_string) then \n write(*,*) 'Error: incorrect string returned from nlls_strerror when status = ', &\n status%status\n fails = fails + 1\n end if\n\n\n status%status = NLLS_ERROR_MS_MAXITS\n call nlls_strerror(status)\n expected_string = 'Maximum iterations reached in more_sorensen (nlls_method=3)'\n if (status%error_message .ne. expected_string) then \n write(*,*) 'Error: incorrect string returned from nlls_strerror when status = ', &\n status%status\n fails = fails + 1\n end if\n\n\n status%status = NLLS_ERROR_MS_TOO_MANY_SHIFTS\n call nlls_strerror(status)\n expected_string = 'Too many shifts taken in more_sorensen (nlls_method=3)'\n if (status%error_message .ne. expected_string) then \n write(*,*) 'Error: incorrect string returned from nlls_strerror when status = ', &\n status%status\n fails = fails + 1\n end if\n\n\n status%status = NLLS_ERROR_MS_NO_PROGRESS\n call nlls_strerror(status)\n expected_string = 'No progress being made in more_sorensen (nlls_method=3)'\n if (status%error_message .ne. expected_string) then \n write(*,*) 'Error: incorrect string returned from nlls_strerror when status = ', &\n status%status\n fails = fails + 1\n end if\n\n status%status = NLLS_ERROR_NO_SECOND_DERIVATIVES\n call nlls_strerror(status)\n expected_string = 'Exact second derivatives needed for tensor model'\n if (status%error_message .ne. expected_string) then \n write(*,*) 'Error: incorrect string returned from nlls_strerror when status = ', &\n status%status\n fails = fails + 1\n end if\n \n \n\n\n status%status = -2355\n call nlls_strerror(status)\n expected_string = 'Unknown error number'\n if (status%error_message .ne. expected_string) then \n write(*,*) 'Error: incorrect string returned from nlls_strerror when status = ', &\n status%status\n fails = fails + 1\n end if\n\n call reset_default_options(options)\n \n end subroutine error_message_tests\n\n subroutine print_line(unit)\n integer, intent(in) :: unit\n \n write(unit,*) \"==================================================\"\n \n end subroutine print_line\n\n \n end module example_module\n", "meta": {"hexsha": "19e6b27a2c9fcda9cff7013bf85120adc0d5e2b2", "size": 85002, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "libRALFit/test/example_module.f90", "max_stars_repo_name": "andpic/RALFit", "max_stars_repo_head_hexsha": "d8bd77217b5163f79069eaf7c5238a854f4843e3", "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": "libRALFit/test/example_module.f90", "max_issues_repo_name": "andpic/RALFit", "max_issues_repo_head_hexsha": "d8bd77217b5163f79069eaf7c5238a854f4843e3", "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": "libRALFit/test/example_module.f90", "max_forks_repo_name": "andpic/RALFit", "max_forks_repo_head_hexsha": "d8bd77217b5163f79069eaf7c5238a854f4843e3", "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.5055449331, "max_line_length": 101, "alphanum_fraction": 0.5580809863, "num_tokens": 25479, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127417985636, "lm_q2_score": 0.7662936430859598, "lm_q1q2_score": 0.6543479057903419}} {"text": " subroutine idz_enorm(n,v,enorm)\nc\nc computes the Euclidean norm of v, the square root\nc of the sum of the squares of the absolute values\nc of the entries of v.\nc\nc input:\nc n -- length of v\nc v -- vector whose Euclidean norm is to be calculated\nc\nc output:\nc enorm -- Euclidean norm of v\nc\n implicit none\n integer n,k\n real*8 enorm\n complex*16 v(n)\nc\nc\n enorm = 0\nc\n do k = 1,n\n enorm = enorm+v(k)*conjg(v(k))\n enddo ! k\nc\n enorm = sqrt(enorm)\nc\nc\n return\n end\nc\nc\nc\nc\n", "meta": {"hexsha": "984e511e54aef27116e0773c9a4833e5083659a6", "size": 604, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "contrib/python/scipy/scipy/linalg/src/id_dist/src/idz_snorm_subr_1.f", "max_stars_repo_name": "ibr11/catboost", "max_stars_repo_head_hexsha": "842a25b4fb856a61564b163b16a3f49ba35fdc14", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 6989, "max_stars_repo_stars_event_min_datetime": "2017-07-18T06:23:18.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T15:58:36.000Z", "max_issues_repo_path": "contrib/python/scipy/scipy/linalg/src/id_dist/src/idz_snorm_subr_1.f", "max_issues_repo_name": "birichie/catboost", "max_issues_repo_head_hexsha": "de75c6af12cf490700e76c22072fbdc15b35d679", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1978, "max_issues_repo_issues_event_min_datetime": "2017-07-18T09:17:58.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T14:28:43.000Z", "max_forks_repo_path": "contrib/python/scipy/scipy/linalg/src/id_dist/src/idz_snorm_subr_1.f", "max_forks_repo_name": "birichie/catboost", "max_forks_repo_head_hexsha": "de75c6af12cf490700e76c22072fbdc15b35d679", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1228, "max_forks_repo_forks_event_min_datetime": "2017-07-18T09:03:13.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T05:57:40.000Z", "avg_line_length": 17.2571428571, "max_line_length": 60, "alphanum_fraction": 0.5397350993, "num_tokens": 181, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8840392756357327, "lm_q2_score": 0.7401743735019595, "lm_q1q2_score": 0.6543432169948045}} {"text": "program demo_polyhatch\n use M_draw\n use M_draw, only : D_BLACK, D_WHITE\n use M_draw, only : D_RED, D_GREEN, D_BLUE\n use M_draw, only : D_YELLOW, D_MAGENTA, D_CYAN\n real :: N=11\n call prefsize(600*10/6,200*10/6)\n call vinit(' ')\n call page( -15.0, 15.0, -5.0, 5.0)\n call linewidth(100)\n call color(D_BLACK)\n call clear()\n call color(D_RED)\n call spirograph(-10.0, 0.0, N, 1.0, N, 5.0, 1000, 0.0, 0.0, 0)\n call polyhatch(.true.) ! turn on polygon hatching\n call hatchang(45.0)\n call hatchpitch(0.3)\n call color(D_GREEN)\n call spirograph(10.0, 0.0, N, 1.0, N, 5.0, 1000, 0.0, 0.0, 2)\n call vflush()\n key=getkey()\n call vexit()\ncontains\n subroutine spirograph(xcenter,ycenter,sunr0,planet0,offset0,radius,ilines,ang,angs,ifill)\n!\n! Make shapes for use as markers using hypocycloidal curves.\n! Huge variety of shapes can be generated using this routine.\n!===================================================================================================================================\n\n!@(#) M_drawplus::spirograph(3f): draw hypocycloidal curves\n\n real,parameter :: PI= 3.14159265358979323846264338327950288419716939937510\n real,intent(in) :: xcenter, ycenter ! center of curve\n real,intent(in) :: sunr0,planet0,offset0 ! radii of sun, planet, and planet offset\n real,intent(in) :: radius ! radius to fit the shape to (no fit if radius is 0)\n integer,intent(in) :: ilines ! number of points to sample along curve\n real,intent(in) :: ang ! angle to rotate the shape by, to orientate it.\n real,intent(in) :: angs ! angle to start sampling points at; ccw is +; 0 is East\n integer,intent(in) :: ifill ! 1 make a filled polygon, 2 make a hatched polygon\n real :: ang1\n real :: con1\n real :: con2\n real :: factor\n integer :: i10\n real :: offset\n real :: planet\n real :: r\n real :: sunr\n real :: u\n real :: xpoin\n real :: xpoin1\n real :: ypoin\n real :: ypoin1\n\n sunr=sunr0\n offset=offset0\n planet=planet0\n\n if(ilines.eq.0) return\n if(planet.eq.0.0) return\n if(sunr.eq.0.0) return\n\n if(radius.ne.0.and.sunr-planet+offset.ne.0)then\n factor=radius/(sunr-planet+offset)\n sunr=factor*sunr\n planet=factor*planet\n offset=factor*offset\n endif\n\n u=0.0+ang\n con1=PI*2.*(sunr/planet)/real(ilines)\n con2=(1.0-planet/sunr)*u\n xpoin1=(sunr-planet)*cos(planet*u/sunr)+offset*cos(con2)\n ypoin1=(sunr-planet)*sin(planet*u/sunr)-offset*sin(con2)\n\n ang1=atan2(ypoin1,xpoin1)+angs\n r=sqrt(xpoin1**2+ypoin1**2)\n xpoin1=r*cos(ang1)+xcenter\n ypoin1=r*sin(ang1)+ycenter\n\n !call push()\n\n select case(ifill)\n case(0)\n case(1)\n call polyfill(.true.)\n call makepoly()\n case(2)\n call polyhatch(.true.)\n call makepoly()\n case(3:)\n call makepoly()\n case default\n end select\n\n call move2(xpoin1,ypoin1)\n do i10=1,ilines\n u=con1*i10+ang\n con2=(1.0-planet/sunr)*u\n if(con2.ge.2**24) con2=amod(con2,PI)\n xpoin=(sunr-planet)*cos(planet*u/sunr)+offset*cos(con2)\n ypoin=(sunr-planet)*sin(planet*u/sunr)-offset*sin(con2)\n\n ang1=atan2(ypoin,xpoin)+angs\n r=sqrt(xpoin**2+ypoin**2)\n xpoin=r*cos(ang1)+xcenter\n ypoin=r*sin(ang1)+ycenter\n\n call draw2(xpoin,ypoin)\n enddo\n\n if(ifill.gt.0)then\n call closepoly()\n call polyfill(.false.)\n endif\n\n !call pop()\n\n end subroutine spirograph\nend program demo_polyhatch\n", "meta": {"hexsha": "6d655a2da514f3ecd0daeb595ad9e06f24801f00", "size": 3967, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/demo_polyhatch.f90", "max_stars_repo_name": "urbanjost/M_draw", "max_stars_repo_head_hexsha": "e82fb2dc669d324847a97f0620687b39aea6a53b", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-25T05:43:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T05:43:49.000Z", "max_issues_repo_path": "example/demo_polyhatch.f90", "max_issues_repo_name": "urbanjost/M_draw", "max_issues_repo_head_hexsha": "e82fb2dc669d324847a97f0620687b39aea6a53b", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "example/demo_polyhatch.f90", "max_forks_repo_name": "urbanjost/M_draw", "max_forks_repo_head_hexsha": "e82fb2dc669d324847a97f0620687b39aea6a53b", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-05-25T05:43:44.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-25T05:43:44.000Z", "avg_line_length": 32.7851239669, "max_line_length": 132, "alphanum_fraction": 0.540458785, "num_tokens": 1222, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392939666336, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6543432153623292}} {"text": "module matrix_invert_mod\n\nuse fms_mod, only: mpp_pe, mpp_root_pe, error_mesg, FATAL, &\n write_version_number\n\nimplicit none\n\npublic :: invert\ninteger, private :: maxmag\n\ncharacter(len=128), parameter :: version = '$Id matrix_invert.f90 $'\ncharacter(len=128), parameter :: tagname = '$Name: latest $'\nlogical :: entry_to_logfile_done = .false.\n\ncontains\n\nsubroutine invert(matrix, det)\n\nreal, intent(inout), dimension(:,:) :: matrix\nreal, intent(out) :: det\n\nreal, dimension(2*size(matrix,1)) :: dd, h\nreal, dimension(2*size(matrix,1),size(matrix,1)) :: ac, temp\nreal :: min_det=1.0e-30\ncharacter(len=24) :: chtmp\ninteger :: n, i, j, L, m, k\n\n! *******************************************************************\n!\n! **** matrix_invert (MATRIX INVERSION AND DETERMINANT)\n!\n! **** QUESTIONS: TRIVENI N. UPADHYAY, AUSTIN,TEXAS X2207,MS 2186\n!\n! **** PURPOSE:\n! THIS SUBROUTINE INVERTS n by n NONSINGULAR MATRIX AND\n! FINDS IT'S DETERMINANT.\n!\n! **** ARGUMENTS:\n! matrix : INPUT MATRIX OF DIMENSION n by n TO BE INVERTED\n! n : DIMENSION OF MATRIX\n! det : DETERMINANT OF MATRIX\n!\n! **** PROCEDURE AND LIMITATIONS :\n! THIS SUBROUTINE USES THE METHOD OF ELEMENTARY\n! TRANFORMATIONS TO FIND THE INVERSE OF A MATRIX.\n! THE INPUT MATRIX IS DESTROYED IN COMPUTATION AND THE INVERSE\n! MATRIX TAKES ITS PLACE. FOR NUMERICAL ACCURACY, ELEMENTARY\n! TRANSFORMATIONS ARE PERFORMED IN CONJUNCTION WITH THE\n! 'PIVOTAL' ELEMENT METHOD.\n! IF THE INPUT MATRIX IS SINGULAR (DETERMINANT LESS\n! THAN min_det), AN ERROR MESSAGE IS PRINTED OUT AND THE\n! PROGRAM IS TERMINATED.\n\nif(.not.entry_to_logfile_done) then\n call write_version_number(version, tagname)\n entry_to_logfile_done = .true.\nendif\n\nn = size(matrix,1)\n\n! INITIALIZE\n\ndet = 1.0\nac(1:n,:) = matrix(:,:)\ndo j=1,n\n ac(n+1:2*n,j) = 0.0\n ac(n+j, j) = 1.0\nend do\n\ndo k=1,n\n\n! FIND LARGEST ELEMENT IN THE ROW\n\n h(k:n) = ac(k,k:n)\n m = n-k+1\n L = max_mag(h(k:n),M)+k\n\n! INTERCHANGE COLUMNS IF THE LARGEST ELEMENT IS NOT THE DIAGONAL ELEMENT.\n\n if (k-L < 0) then\n do i=k,2*n\n dd(i) = ac(i,k)\n ac(i,k) = ac(i,L)\n ac(i,L) = dd(i)\n end do\n det = -det\n end if\n \n! DIVIDE THE COLUMN BY THE LARGEST ELEMENT\n \n det = det*ac(k,k)\n if (abs(det) < min_det) then\n write(chtmp,'(1pe24.16)') det\n call error_mesg('invert','DETERMINANT OF MATRIX ='//chtmp// &\n & ' THE MAGNITUDE OF THE DETERMINANT IS LESS THAN THE MINIMUM ALLOWED. &\n & THE INPUT MATRIX APPEARS TO BE SINGULAR.',FATAL)\n endif\n h(k:2*n) = ac(k:2*n,k)/ac(k,k)\n do j=1,n\n temp(k:2*n,j) = h(k:2*n)*ac(k,j)\n end do\n ac(k:2*n,:) = ac(k:2*n,:) - temp(k:2*n,:)\n ac(k:2*n,k) = h(k:2*n)\nend do\n\nmatrix(1:n,:) = ac(n+1:2*n,:)\n\nreturn\nend subroutine invert\n\nfunction max_mag(h,m) result(max)\n\ninteger, intent(in) :: m\nreal, intent(in) :: h(m)\ninteger :: max, i\nreal :: rmax\n\nmax = 0\nrmax = abs(h(1))\ndo i=1,m\n if (abs(h(i)) > rmax ) then\n rmax = abs(h(i))\n max = i-1\n endif\nend do\nreturn\nend function max_mag\n\nend module matrix_invert_mod\n", "meta": {"hexsha": "8ae9526254f6694397ac0933b17f901a3f39dad9", "size": 3124, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fms_dynamical_cores/_fortran/src/atmos_spectral/model/matrix_invert.f90", "max_stars_repo_name": "JoyMonteiro/FMSDynamicalCore", "max_stars_repo_head_hexsha": "b46a8943de28f8b16a1d36f5607f10e928ed6667", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-05-23T13:35:20.000Z", "max_stars_repo_stars_event_max_datetime": "2018-05-23T13:35:20.000Z", "max_issues_repo_path": "fms_dynamical_cores/_fortran/src/atmos_spectral/model/matrix_invert.f90", "max_issues_repo_name": "JoyMonteiro/fms_dynamical_cores", "max_issues_repo_head_hexsha": "b46a8943de28f8b16a1d36f5607f10e928ed6667", "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": "fms_dynamical_cores/_fortran/src/atmos_spectral/model/matrix_invert.f90", "max_forks_repo_name": "JoyMonteiro/fms_dynamical_cores", "max_forks_repo_head_hexsha": "b46a8943de28f8b16a1d36f5607f10e928ed6667", "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.0307692308, "max_line_length": 76, "alphanum_fraction": 0.6161971831, "num_tokens": 1027, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357327, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6543432068611126}} {"text": "#include \"eiscor.h\"\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! d_orthhess_real2complex\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! This routine converts the real Schur factorization of a real\n! orthogonal matrix to the complex Schur factorization.\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! INPUT VARIABLES:\n!\n! VEC LOGICAL\n! .TRUE.: compute schurvectors\n! .FALSE.: no schurvectors\n!\n! N INTEGER\n! dimension of matrix\n!\n! H REAL(8) array of dimension (N,N)\n! block diagonal orthogonal matrix\n!\n! M INTEGER\n! leading dimension of Z\n!\n! Z REAL(8) array of dimension (M,N)\n! if VEC = .FALSE. unused\n! if VEC = .TRUE. contains real Schur vectors \n!\n! OUTPUT VARIABLES:\n!\n! E COMPLEX(8) array of dimension (N)\n! contains eigenvalues\n!\n! V COMPLEX(8) array of dimension (M,N)\n! if VEC = .FALSE. unused\n! if VEC = .TRUE. contains complex schurvectors \n!\n! INFO INTEGER\n! INFO = 0 implies successful computation\n! INFO = -2 implies N is invalid\n! INFO = -3 implies H is invalid\n! INFO = -4 implies M is invalid\n! INFO = -5 implies Z is invalid\n!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nsubroutine d_orthhess_real2complex(VEC,N,H,M,Z,E,V,INFO)\n \n implicit none\n \n ! input variables\n logical, intent(in) :: VEC\n integer, intent(in) :: N, M\n integer, intent(inout) :: INFO\n real(8), intent(in) :: H(N,N), Z(M,N)\n complex(8), intent(inout) :: E(N), V(M,N)\n \n ! compute variables\n logical :: flg\n integer :: ii, jj, ind\n complex(8) :: block(2,2) \n\n ! initialize INFO\n INFO = 0\n \n ! check factorization\n call d_2Darray_check(N,N,H,flg)\n if (.NOT.flg) then\n INFO = -3\n ! print error message in debug mode\n if (DEBUG) then\n call u_infocode_check(__FILE__,__LINE__ &\n ,\"H is invalid\",INFO,INFO)\n end if\n return\n end if\n \n ! check M\n if (VEC.AND.(M < 1)) then\n INFO = -4\n ! print error message in debug mode\n if (DEBUG) then\n call u_infocode_check(__FILE__,__LINE__,\"M must be at least 1\",INFO,INFO)\n end if\n return\n end if\n \n ! check Z\n if (VEC) then\n call d_2Darray_check(M,N,Z,flg)\n if (.NOT.flg) then\n INFO = -5\n ! print error message in debug mode\n if (DEBUG) then\n call u_infocode_check(__FILE__,__LINE__,\"Z is invalid\",INFO,INFO)\n end if\n return\n end if\n end if \n \n ! initialize storage\n if (VEC) then\n\n ! initialize V\n do ii=1,M\n do jj=1,N\n V(ii,jj) = cmplx(Z(ii,jj),0d0,kind=8)\n end do\n end do\n\n ! initialize block\n block(1,1) = cmplx(0d0,1d0,kind=8)\n block(2,1) = cmplx(1d0,0d0,kind=8)\n block(1,2) = cmplx(-1d0,0d0,kind=8)\n block(2,2) = cmplx(0d0,-1d0,kind=8)\n block = block/sqrt(2d0)\n\n end if\n \n ! loop through eigenvalues\n ind = 1\n do while (ind.LT.N)\n\n ! single eigenvalue\n if (H(ind+1,ind).EQ.0d0) then\n\n ! store eigenvalue\n E(ind) = cmplx(H(ind,ind),0d0,kind=8)\n ind = ind + 1\n\n ! conjugate pair\n else\n\n ! store eigenvalues\n E(ind) = cmplx(H(ind,ind),H(ind+1,ind),kind=8)\n E(ind+1) = conjg(E(ind))\n\n ! update eigenvectors\n if (VEC) then\n V(:,ind:(ind+1)) = matmul(V(:,ind:(ind+1)),block)\n end if\n\n ! check to see that next rotation is identity\n if ((ind.LT.(N-1)).AND.(H(ind+1,ind+2).NE.0d0)) then\n INFO = -3\n ! print error message in debug mode\n if (DEBUG) then\n call u_infocode_check(__FILE__,__LINE__ &\n ,\"Not a valid real Schur form.\",INFO,INFO)\n end if\n return\n end if\n\n ! update ind \n ind = ind + 2\n\n end if\n \n end do\n\n ! update last eigenvalue if not conjugate pair\n if (H(N-1,N).EQ.0d0) then\n\n ! store eigenvalue\n E(N) = cmplx(H(N,N),0d0,kind=8)\n\n end if\n \nend subroutine d_orthhess_real2complex\n", "meta": {"hexsha": "9e86380e0b61132d46e9cd5ca85391c76e6af8a5", "size": 4261, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/AMVW/src/double/d_orthhess_real2complex.f90", "max_stars_repo_name": "trcameron/FPML", "max_stars_repo_head_hexsha": "f6aacfcd702f7ce74a45ffaf281e9586dceb1b7e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tests/AMVW/src/double/d_orthhess_real2complex.f90", "max_issues_repo_name": "trcameron/FPML", "max_issues_repo_head_hexsha": "f6aacfcd702f7ce74a45ffaf281e9586dceb1b7e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/AMVW/src/double/d_orthhess_real2complex.f90", "max_forks_repo_name": "trcameron/FPML", "max_forks_repo_head_hexsha": "f6aacfcd702f7ce74a45ffaf281e9586dceb1b7e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.773255814, "max_line_length": 79, "alphanum_fraction": 0.5127904248, "num_tokens": 1274, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6542733075712974}} {"text": "c program DRDHFTI\nc>> 2001-05-22 DRDHFTI Krogh Minor change for making .f90 version.\nc>> 1996-07-03 DRDHFTI Krogh Special code for C conversion.\nc>> 1994-10-19 DRDHFTI Krogh Changes to use M77CON\nc>> 1987-12-09 DRDHFTI Lawson Initial Code.\nc Demo driver for DHFTI and DCOV2\nc--D replaces \"?\": DR?HFTI, ?HFTI, ?COV2\nc\nc The sample data was computed as\nc y = 0.5 + 0.25 * sin(2*pi*x) + 0.125 * exp(-x)\nc rounded to four decimal places.\nc ------------------------------------------------------------------\nc++ Code for .C. is inactive\nc%% long int k;\nc++ End\n integer MMAX, NMAX\n double precision ZERO, ONE, TWO, FOUR\n parameter(MMAX=11, NMAX=3)\n parameter(ZERO = 0.0D0, ONE = 1.0D0, TWO = 2.0D0, FOUR = 4.0D0)\n double precision X(MMAX),Y(MMAX),A(MMAX,NMAX),C(MMAX)\n double precision WORK(NMAX), RNORM(1)\n double precision DOF, PI, STDDEV, TAU, VAR\n integer IP(NMAX), KRANK, I, IERR, J, NC, M, N\nc ------------------------------------------------------------------\n data X / 0.0D0, 0.1D0, 0.2D0, 0.3D0, 0.4D0, 0.5D0,\n * 0.6D0, 0.7D0, 0.8D0, 0.9D0, 1.0D0/\n data Y / 0.6250D0,0.7601D0,0.8401D0,0.8304D0,0.7307D0,0.5758D0,\n * 0.4217D0,0.3243D0,0.3184D0,0.4039D0,0.5460D0/\n data M, N, NC, TAU/ MMAX, NMAX, 1, 0.0D0/\nc ------------------------------------------------------------------\n PI = FOUR * atan(ONE)\n do 20 I = 1, M\n A(I,1) = ONE\n A(I,2) = sin(TWO * PI * X(I))\n A(I,3) = exp(-X(I))\n C(I) = Y(I)\n 20 continue\n\n call DHFTI (A,MMAX,M,N,C,MMAX,NC,TAU,KRANK,RNORM,WORK,IP)\n DOF = M - N\n STDDEV = RNORM(1) / sqrt(DOF)\n VAR = STDDEV**2\n print '(1x,''Rank of linear system ='',i4)', KRANK\n print '(1x,''Std. Dev. of data error ='',f10.6)', STDDEV\n print '(1x,''Solution coefficients ='',3f10.6)', (C(J),J=1,N)\n\n call DCOV2( A, MMAX, N, IP, VAR, IERR)\n print '(1x,''Error flag from DCOV2 ='',i4)', IERR\n print '('' Covariance matrix of computed coefficients:'')'\n print '(1X)'\nc++ Code for ~.C. is active\n do 30 I = 1,N\n print '(1x,3(3x,2i3,g16.8))', (I,J,A(I,J),J=I,N)\n 30 continue\nc++ Code for .C. is inactive\nc%% for (i = 0; i < n; i++){\nc%% for (j = i; j < n; j+=3){\nc%% for (k = j; k < (j < n - 3 ? j+3 : n); k++)\nc%% printf( \" %3ld%3ld%16.8g\", i+1, k+1, a[k][i] );\nc%% printf( \"\\n\" );}\nc%% }\nc++ End\n stop\n end\n", "meta": {"hexsha": "c71eeb19426b83e2e8c20bbe9fab257f963da036", "size": 2553, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/demo/drdhfti.f", "max_stars_repo_name": "jacobwilliams/math77", "max_stars_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2016-01-04T03:17:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-25T19:17:42.000Z", "max_issues_repo_path": "src/MATH77/demo/drdhfti.f", "max_issues_repo_name": "jacobwilliams/math77", "max_issues_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-01-17T02:48:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-21T16:04:58.000Z", "max_forks_repo_path": "src/MATH77/demo/drdhfti.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.2769230769, "max_line_length": 72, "alphanum_fraction": 0.4829612221, "num_tokens": 1012, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916134888613, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6542733049075891}} {"text": "C$Procedure QMINI ( Quaternion linear interpolation )\n\n SUBROUTINE QMINI ( INIT, FINAL, FRAC, QINTRP )\n IMPLICIT NONE\n\nC$ Abstract\nC\nC Interpolate between two quaternions using a constant angular\nC rate.\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 ROTATIONS\nC\nC$ Keywords\nC\nC MATH\nC QUATERNION\nC ROTATION\nC\nC$ Declarations\n \n DOUBLE PRECISION INIT ( 0 : 3 )\n DOUBLE PRECISION FINAL ( 0 : 3 )\n DOUBLE PRECISION FRAC\n DOUBLE PRECISION QINTRP ( 0 : 3 )\n\nC$ Brief_I/O\nC\nC Variable I/O Description\nC -------- --- --------------------------------------------------\nC INIT I Initial quaternion representing a rotation.\nC FINAL I Final quaternion representing a rotation.\nC FRAC I Fraction of rotation from INIT to FINAL by which\nC to interpolate.\nC QINTRP O Linearly interpolated quaternion.\nC\nC$ Detailed_Input\nC\nC INIT,\nC FINAL,\nC FRAC are, respectively, two unit quaternions between\nC which to interpolate, and an interpolation\nC fraction. See the Detailed_Output and Particulars\nC sections for details.\nC\nC$ Detailed_Output\nC\nC QINTRP is the quaternion resulting from linear\nC interpolation between INIT and FINAL by the\nC fraction FRAC. By \"linear interpolation\" we mean\nC the following:\nC\nC We view INIT and FINAL as quaternions\nC representing two values of a time-varying\nC rotation matrix R(t) that rotates at a constant\nC angular velocity (that is, the row vectors of\nC R(t) rotate with constant angular velocity).\nC We can say that\nC\nC INIT represents R(t0)\nC FINAL represents R(t1)\nC\nC Equivalently, the SPICELIB routine Q2M maps\nC INIT and FINAL to rotation matrices\nC corresponding to R(t0) and R(t1) respectively.\nC\nC \"Linear interpolation by the fraction FRAC\"\nC means that QINTRP represents the matrix\nC R(t) evaluated at time\nC\nC t = t0 + FRAC * (t1 - t0)\nC\nC and that the sign of QINTRP is such that\nC QINTRP is closer to both INIT and FINAL\nC than is -QINTRP.\nC\nC\nC$ Parameters\nC\nC None.\nC\nC$ Exceptions\nC\nC 1) If either of INIT or FINAL is not a unit quaternion, the error\nC SPICE(NOTAROTATION) is signaled.\nC\nC 2) This routine assumes that the quaternion QUOT defined by\nC \nC *\nC QUOT = FINAL * INIT\nC\nC has rotation angle THETA radians, where\nC\nC 0 < THETA < pi\nC - \nC\nC Above the * superscript denotes quaternion conjugation.\nC\nC The caller must test this condition on THETA; it is not\nC tested by this routine. A quick check may be performed by\nC verifying that\nC\nC 0 < QUOT(0)\nC \nC Note that this inequality is strict because rotations of\nC pi radians cannot be linearly interpolated so as to\nC produce a unique result.\nC\nC This routine cannot distinguish between rotations of THETA\nC radians, where THETA is in the interval [0, pi), and\nC rotations of\nC\nC THETA + 2 * k * pi\nC\nC radians, where k is any integer. These \"large\" rotations will\nC yield invalid results when interpolated. You must ensure\nC that the inputs you provide to this routine will not be\nC subject to this sort of ambiguity. If in fact you are\nC interpolating a time-dependent rotation with constant angular\nC velocity AV between times t0 and t1, you must ensure that\nC\nC || AV || * |t1 - t0| < pi.\nC\nC Here we assume that the magnitude of AV is the angular rate\nC of the rotation in units of radians per second.\nC\nC\nC 3) When FRAC is outside of the interval [0, 1], the process\nC performed is \"extrapolation\", not interpolation. Such\nC values of FRAC are permitted.\nC\nC$ Files\nC\nC None.\nC\nC$ Particulars\nC\nC In the discussion below, we assume that the conditions specified\nC in item (2) of the Exceptions section have been satisfied.\nC\nC As we've said, we view INIT and FINAL as quaternions representing\nC two values of a time-varying rotation matrix R(t) that rotates at\nC a constant angular velocity; we define R(t), t0, and t1 so that\nC\nC INIT represents R(t0)\nC FINAL represents R(t1).\nC\nC The output quaternion QINTRP represents R(t) evaluated at the\nC time\nC\nC t0 + FRAC * (t1 - t0).\nC\nC How do we evaluate R at times between t0 and t1? Since the row\nC vectors of R are presumed to rotate with constant angular\nC velocity, we will first find the rotation axis of the quotient\nC rotation Q that maps the row vectors of R from their initial to\nC final position. Since the rows of R are the columns of the\nC transpose of R, we can write:\nC\nC T T\nC R(t1) = Q * R(t0),\nC\nC Since\nC\nC T T T\nC R(t1) = ( R(t1) * R(t0) ) * R(t0)\nC\nC\nC we can find Q, as well as a rotation axis A and an angle THETA\nC in the range [0, pi] such that Q rotates vectors by THETA\nC radians about axis A.\nC\nC We'll use the notation\nC\nC [ x ]\nC N\nC\nC to indicate a coordinate system rotation of x radians about the\nC vector N. Having found A and THETA, we can write (note that\nC the sign of the rotation angle is negated because we're using\nC a coordinate system rotation)\nC\nC T (t - t0) T\nC R(t) = [ - THETA * --------- ] * R(t0)\nC (t1 - t0) A\nC\nC Thus R(t) and QINTRP are determined.\nC\nC The input argument FRAC plays the role of the quotient\nC\nC t - t0\nC -------\nC t1 - t0\nC\nC shown above.\nC\nC\nC$ Examples\nC\nC 1) Suppose we want to interpolate between quaternions\nC Q1 and Q2 that give the orientation of a spacecraft structure\nC at times t1 and t2. We wish to find an approximation of the\nC structure's orientation at the midpoint of the time interval\nC [t1, t2]. We assume that the angular velocity of the\nC structure equals the constant AV between times t1 and t2. We\nC also assume that\nC\nC || AV || * (t2 - t1) < pi.\nC\nC Then the code fragment\nC\nC CALL QMINI ( Q1, Q2, 0.5D0, QINTRP, SCLDAV )\nC\nC produces the approximation we desire.\nC\nC\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC N.J. Bachman (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.1, 28-FEB-2008 (NJB)\nC\nC The discussion of exception #2 was expanded.\nC\nC- SPICELIB Version 1.0.0, 19-JUL-2005 (NJB)\nC\nC-&\n \nC$ Index_Entries\nC\nC linear interpolation between quaternions\nC\nC-&\n\nC\nC SPICELIB functions\nC\n DOUBLE PRECISION BRCKTD\n\nC\nC Local variables\nC\n DOUBLE PRECISION ANGLE\n DOUBLE PRECISION AXIS ( 3 )\n DOUBLE PRECISION INSTAR ( 0 : 3 )\n DOUBLE PRECISION INTANG\n DOUBLE PRECISION Q ( 0 : 3 )\n DOUBLE PRECISION QSCALE ( 0 : 3 )\n DOUBLE PRECISION VMAG\n\nC\nC Use discovery check-in.\nC\nC\nC\nC Find the conjugate INSTAR of the input quaternion INIT.\nC\n INSTAR(0) = INIT(0)\n \n CALL VMINUS ( INIT(1), INSTAR(1) )\n\nC\nC Find the quotient quaternion Q that maps INIT to FINAL.\nC\n CALL QXQ ( FINAL, INSTAR, Q )\n\nC\nC Extract the rotation angle from Q. Use arccosine for \nC speed, sacrificing some accuracy.\nC\n ANGLE = 2.D0 * ACOS ( BRCKTD( Q(0), -1.D0, 1.D0 ) )\n\nC\nC Create a quaternion QSCALE from the rotation axis of the quotient \nC and the scaled rotation angle.\nC\n INTANG = FRAC * ANGLE / 2.D0\n\n QSCALE(0) = COS ( INTANG )\n\nC\nC Get the unit vector parallel to the vector part of Q. \nC UNORM does exactly what we want here, because if the vector\nC part of Q is zero, the returned \"unit\" vector will be the\nC zero vector.\nC\n CALL UNORM ( Q(1), AXIS, VMAG )\n\nC\nC Form the vector part of QSCALE.\nC\n CALL VSCL ( SIN ( INTANG ), AXIS, QSCALE(1) )\n\nC\nC Apply QSCALE to INIT to produce the interpolated quaternion we\nC seek.\nC \n CALL QXQ ( QSCALE, INIT, QINTRP )\n\n RETURN\n END\n\n\n", "meta": {"hexsha": "79562f86baf53623a2737f2c13e8ac198e55bfd8", "size": 10240, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/qmini.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/qmini.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/qmini.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": 30.0293255132, "max_line_length": 72, "alphanum_fraction": 0.61015625, "num_tokens": 2787, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737806, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6542733022438808}} {"text": "*> \\brief \\b CLAEV2 computes the eigenvalues and eigenvectors of a 2-by-2 symmetric/Hermitian matrix.\n*\n* =========== DOCUMENTATION ===========\n*\n* Online html documentation available at\n* http://www.netlib.org/lapack/explore-html/\n*\n*> \\htmlonly\n*> Download CLAEV2 + dependencies\n*> \n*> [TGZ]\n*> \n*> [ZIP]\n*> \n*> [TXT]\n*> \\endhtmlonly\n*\n* Definition:\n* ===========\n*\n* SUBROUTINE CLAEV2( A, B, C, RT1, RT2, CS1, SN1 )\n*\n* .. Scalar Arguments ..\n* REAL CS1, RT1, RT2\n* COMPLEX A, B, C, SN1\n* ..\n*\n*\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*>\n*> CLAEV2 computes the eigendecomposition of a 2-by-2 Hermitian matrix\n*> [ A B ]\n*> [ CONJG(B) C ].\n*> On return, RT1 is the eigenvalue of larger absolute value, RT2 is the\n*> eigenvalue of smaller absolute value, and (CS1,SN1) is the unit right\n*> eigenvector for RT1, giving the decomposition\n*>\n*> [ CS1 CONJG(SN1) ] [ A B ] [ CS1 -CONJG(SN1) ] = [ RT1 0 ]\n*> [-SN1 CS1 ] [ CONJG(B) C ] [ SN1 CS1 ] [ 0 RT2 ].\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in] A\n*> \\verbatim\n*> A is COMPLEX\n*> The (1,1) element of the 2-by-2 matrix.\n*> \\endverbatim\n*>\n*> \\param[in] B\n*> \\verbatim\n*> B is COMPLEX\n*> The (1,2) element and the conjugate of the (2,1) element of\n*> the 2-by-2 matrix.\n*> \\endverbatim\n*>\n*> \\param[in] C\n*> \\verbatim\n*> C is COMPLEX\n*> The (2,2) element of the 2-by-2 matrix.\n*> \\endverbatim\n*>\n*> \\param[out] RT1\n*> \\verbatim\n*> RT1 is REAL\n*> The eigenvalue of larger absolute value.\n*> \\endverbatim\n*>\n*> \\param[out] RT2\n*> \\verbatim\n*> RT2 is REAL\n*> The eigenvalue of smaller absolute value.\n*> \\endverbatim\n*>\n*> \\param[out] CS1\n*> \\verbatim\n*> CS1 is REAL\n*> \\endverbatim\n*>\n*> \\param[out] SN1\n*> \\verbatim\n*> SN1 is COMPLEX\n*> The vector (CS1, SN1) is a unit right eigenvector for RT1.\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee\n*> \\author Univ. of California Berkeley\n*> \\author Univ. of Colorado Denver\n*> \\author NAG Ltd.\n*\n*> \\date September 2012\n*\n*> \\ingroup complexOTHERauxiliary\n*\n*> \\par Further Details:\n* =====================\n*>\n*> \\verbatim\n*>\n*> RT1 is accurate to a few ulps barring over/underflow.\n*>\n*> RT2 may be inaccurate if there is massive cancellation in the\n*> determinant A*C-B*B; higher precision or correctly rounded or\n*> correctly truncated arithmetic would be needed to compute RT2\n*> accurately in all cases.\n*>\n*> CS1 and SN1 are accurate to a few ulps barring over/underflow.\n*>\n*> Overflow is possible only if RT1 is within a factor of 5 of overflow.\n*> Underflow is harmless if the input data is 0 or exceeds\n*> underflow_threshold / macheps.\n*> \\endverbatim\n*>\n* =====================================================================\n SUBROUTINE CLAEV2( A, B, C, RT1, RT2, CS1, SN1 )\n*\n* -- LAPACK auxiliary routine (version 3.4.2) --\n* -- LAPACK is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n* September 2012\n*\n* .. Scalar Arguments ..\n REAL CS1, RT1, RT2\n COMPLEX A, B, C, SN1\n* ..\n*\n* =====================================================================\n*\n* .. Parameters ..\n REAL ZERO\n PARAMETER ( ZERO = 0.0E0 )\n REAL ONE\n PARAMETER ( ONE = 1.0E0 )\n* ..\n* .. Local Scalars ..\n REAL T\n COMPLEX W\n* ..\n* .. External Subroutines ..\n EXTERNAL SLAEV2\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC ABS, CONJG, REAL\n* ..\n* .. Executable Statements ..\n*\n IF( ABS( B ).EQ.ZERO ) THEN\n W = ONE\n ELSE\n W = CONJG( B ) / ABS( B )\n END IF\n CALL SLAEV2( REAL( A ), ABS( B ), REAL( C ), RT1, RT2, CS1, T )\n SN1 = W*T\n RETURN\n*\n* End of CLAEV2\n*\n END\n", "meta": {"hexsha": "ec24f431a3fae1783775884046d0362a878e5585", "size": 4447, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "SRC/claev2.f", "max_stars_repo_name": "sydha/Lapack", "max_stars_repo_head_hexsha": "1290e6b39b73b2431976e0a9b7fb7d78aeab3ba7", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "SRC/claev2.f", "max_issues_repo_name": "sydha/Lapack", "max_issues_repo_head_hexsha": "1290e6b39b73b2431976e0a9b7fb7d78aeab3ba7", "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": "SRC/claev2.f", "max_forks_repo_name": "sydha/Lapack", "max_forks_repo_head_hexsha": "1290e6b39b73b2431976e0a9b7fb7d78aeab3ba7", "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": 26.7891566265, "max_line_length": 111, "alphanum_fraction": 0.5428378682, "num_tokens": 1357, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.863391602943619, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6542732969164639}} {"text": "! ##################################################################################################################################\n! Begin MIT license text. \n! _______________________________________________________________________________________________________\n \n! Copyright 2019 Dr William R Case, Jr (dbcase29@gmail.com) \n \n! Permission is hereby granted, free of charge, to any person obtaining a copy of this software and \n! associated documentation files (the \"Software\"), to deal in the Software without restriction, including\n! without limitation the rights 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 furnished to do so, subject to \n! the following conditions: \n \n! The above copyright notice and this permission notice shall be included in all copies or substantial \n! portions of the Software and documentation. \n \n! THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS \n! OR 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 \n! THE SOFTWARE. \n! _______________________________________________________________________________________________________\n \n! End MIT license text. \n \n SUBROUTINE ORDER_TRIA ( KORDER, SS_I, SS_J, HH_IJ )\n \n! Calculates abscissa and weight coefficients for triangular integration for the PENTA element\n \n USE PENTIUM_II_KIND, ONLY : BYTE, LONG, DOUBLE\n USE IOUNT1, ONLY : WRT_ERR, WRT_LOG, ERR, F04, F06\n USE SCONTR, ONLY : BLNK_SUB_NAM, FATAL_ERR, MAX_ORDER_TRIA\n USE TIMDAT, ONLY : TSEC\n USE SUBR_BEGEND_LEVELS, ONLY : ORDER_BEGEND\n USE CONSTANTS_1, ONLY : ZERO, SIXTH, THIRD, HALF, TWO\n \n USE ORDER_TRIA_USE_IFs\n IMPLICIT NONE\n \n CHARACTER(LEN=LEN(BLNK_SUB_NAM)):: SUBR_NAME = 'ORDER_TRIA'\n\n INTEGER(LONG), INTENT(IN) :: KORDER ! Triangular integration order to use\n INTEGER(LONG) :: I ! DO loop index\n INTEGER(LONG), PARAMETER :: SUBR_BEGEND = ORDER_BEGEND\n \n REAL(DOUBLE) ,INTENT(OUT) :: SS_I(MAX_ORDER_TRIA) ! Triangular integration abscissa's\n REAL(DOUBLE) ,INTENT(OUT) :: SS_J(MAX_ORDER_TRIA) ! Triangular integration abscissa's\n REAL(DOUBLE) ,INTENT(OUT) :: HH_IJ(MAX_ORDER_TRIA) ! Triangular integration weight coeffs\n REAL(DOUBLE) , PARAMETER :: A1 = .0597158717D0 ! Intermediate constant\n REAL(DOUBLE) , PARAMETER :: A2 = .7974269853D0 ! Intermediate constant\n REAL(DOUBLE) , PARAMETER :: B1 = .4701420641D0 ! Intermediate constant\n REAL(DOUBLE) , PARAMETER :: B2 = .1012865073D0 ! Intermediate constant\n REAL(DOUBLE) , PARAMETER :: W1 = .1125D0 ! Intermediate constant\n REAL(DOUBLE) , PARAMETER :: W2 = .0661970763D0 ! Intermediate constant\n REAL(DOUBLE) , PARAMETER :: W3 = .0629695902D0 ! Intermediate constant\n \n! **********************************************************************************************************************************\n IF (WRT_LOG >= SUBR_BEGEND) THEN\n CALL OURTIM\n WRITE(F04,9001) SUBR_NAME,TSEC\n 9001 FORMAT(1X,A,' BEGN ',F10.3)\n ENDIF\n\n! **********************************************************************************************************************************\n DO I=1,MAX_ORDER_TRIA\n SS_I(I) = ZERO\n SS_J(I) = ZERO\n HH_IJ(I) = ZERO\n ENDDO\n\n IF (KORDER == 1) THEN\n\n SS_I(1) = THIRD ; SS_J(1) = THIRD ; HH_IJ(1) = HALF\n\n ELSE IF (KORDER == 3) THEN\n\n SS_I(1) = SIXTH ; SS_J(1) = TWO*THIRD; HH_IJ(1) = SIXTH\n SS_I(2) = SIXTH ; SS_J(2) = SIXTH ; HH_IJ(2) = SIXTH\n SS_I(3) = TWO*THIRD; SS_J(3) = SIXTH ; HH_IJ(3) = SIXTH\n\n ELSE IF (KORDER == 7) THEN\n\n SS_I(1) = THIRD; SS_J(1) = THIRD; HH_IJ(1) = W1\n SS_I(2) = A1 ; SS_J(2) = B1 ; HH_IJ(2) = W2\n SS_I(3) = B1 ; SS_J(3) = A1 ; HH_IJ(3) = W2\n SS_I(4) = B1 ; SS_J(4) = B1 ; HH_IJ(4) = W2\n SS_I(5) = A2 ; SS_J(5) = B2 ; HH_IJ(5) = W3\n SS_I(6) = B2 ; SS_J(6) = A2 ; HH_IJ(6) = W3\n SS_I(7) = B2 ; SS_J(7) = B2 ; HH_IJ(7) = W3\n \n ELSE\n \n WRITE(ERR,1931) SUBR_NAME, KORDER\n WRITE(F06,1931) SUBR_NAME, KORDER\n FATAL_ERR = FATAL_ERR + 1\n CALL OUTA_HERE ( 'Y' ) ! Coding error, so quit\n \n ENDIF\n \n! **********************************************************************************************************************************\n IF (WRT_LOG >= SUBR_BEGEND) THEN\n CALL OURTIM\n WRITE(F04,9002) SUBR_NAME,TSEC\n 9002 FORMAT(1X,A,' END ',F10.3)\n ENDIF\n\n RETURN\n\n! **********************************************************************************************************************************\n 1931 FORMAT(' *ERROR 1931: PROGRAMMING ERROR IN SUBROUTINE ',A &\n ,/,14X,' TRIANGULAR INTEGRATION ORDER MUST BE EITHER 1, 3 OR 7 BUT VALUE IS ',I8)\n\n! **********************************************************************************************************************************\n \n END SUBROUTINE ORDER_TRIA\n", "meta": {"hexsha": "35808493a5f7d3d81442b9e2dac4efaf17b10627", "size": 6998, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Source/EMG/EMG7/ORDER_TRIA.f90", "max_stars_repo_name": "dr-bill-c/MYSTRAN-general-purpose-finite-element-computer-program", "max_stars_repo_head_hexsha": "307d62953924e3945b22b2fcdb7963a8be330a0c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 43, "max_stars_repo_stars_event_min_datetime": "2020-04-04T15:33:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-23T08:46:05.000Z", "max_issues_repo_path": "Source/EMG/EMG7/ORDER_TRIA.f90", "max_issues_repo_name": "dr-bill-c/MYSTRAN-general-purpose-finite-element-computer-program", "max_issues_repo_head_hexsha": "307d62953924e3945b22b2fcdb7963a8be330a0c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 15, "max_issues_repo_issues_event_min_datetime": "2020-07-06T21:15:15.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-06T19:54:09.000Z", "max_forks_repo_path": "Source/EMG/EMG7/ORDER_TRIA.f90", "max_forks_repo_name": "dr-bill-c/MYSTRAN-general-purpose-finite-element-computer-program", "max_forks_repo_head_hexsha": "307d62953924e3945b22b2fcdb7963a8be330a0c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2020-05-28T17:16:44.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-06T18:08:31.000Z", "avg_line_length": 59.811965812, "max_line_length": 132, "alphanum_fraction": 0.4339811375, "num_tokens": 1521, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.863391595913457, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6542732915890467}} {"text": "program array2\nimplicit none\nreal,dimension (10) :: x\nreal :: average,sum\ninteger ::i\nprint*, \"the numbers are\"\nsum =0.0\ndo i = 1,10\nread*, x(i)\nsum = sum + x(i)\nend do\naverage = sum /10\nprint*, \"the average is \",average\nprint*,x\n\nend program array2\n", "meta": {"hexsha": "47d2b679f464da5b43819126a76f632dec3513ca", "size": 250, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "array1/array2/array2.f90", "max_stars_repo_name": "akkiturb/Ilkay-s-Fortran-Class", "max_stars_repo_head_hexsha": "0600640574354052a5a7d87bad520b8a03650d0e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-12-18T19:31:01.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-18T19:31:01.000Z", "max_issues_repo_path": "array1/array2/array2.f90", "max_issues_repo_name": "akkiturb/Scientific-computing-in-Fortran", "max_issues_repo_head_hexsha": "0600640574354052a5a7d87bad520b8a03650d0e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "array1/array2/array2.f90", "max_forks_repo_name": "akkiturb/Scientific-computing-in-Fortran", "max_forks_repo_head_hexsha": "0600640574354052a5a7d87bad520b8a03650d0e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-02-04T19:45:56.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-10T14:22:05.000Z", "avg_line_length": 14.7058823529, "max_line_length": 33, "alphanum_fraction": 0.676, "num_tokens": 85, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8221891479496523, "lm_q2_score": 0.7956581049086031, "lm_q1q2_score": 0.6541814593340394}} {"text": "C LAST UPDATE 02/1/95\nC+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\nC\n SUBROUTINE ROOTJ(N,XMAX,ROOTS,MAXRTS,NR)\n IMPLICIT NONE\nC\nC Purpose: Calculates the first NR roots of Jn out to XMAX or the first\nC MAXRTS roots if NR > MAXRTS.\nC\nC Calls 1: RTJNK\nC Called by:\nC\nC-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-\nC\nC Arguments:\nC\n INTEGER N,MAXRTS,NR\n REAL ROOTS(MAXRTS),XMAX\nC\nC External function:\nC\n REAL RTJNK\n EXTERNAL RTJNK\nC\nC Local variables:\nC\n INTEGER I\nC-----------------------------------------------------------------------\n DO 10 I=1,MAXRTS\n ROOTS(I) = RTJNK(N,I)\n IF(ROOTS(I).GT.XMAX)THEN\n NR = I - 1\n RETURN\n ENDIF\n 10 CONTINUE\n NR = I - 1\nC\n RETURN\n END \n\n \nC LAST UPDATE 02/1/95\nC+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\nC\n REAL FUNCTION RTJNK(N,K)\n IMPLICIT NONE\nC\nC Purpose: Calculates the Kth root of Jn.\nC\nC Calls 1: RTSAFE\nC Called by:\nC\nC-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-\nC Parameters:\nC\n REAL XACC,PI\n PARAMETER(XACC=1.0E-04,PI=3.141592654)\nC\nC Arguments:\nC\n INTEGER N,K\nC\nC Local variables:\nC\n REAL K0\n INTEGER I\n REAL RTMP,X1,X2\nC\nC External functions:\nC\n REAL RTSAFE,BESSD\n EXTERNAL RTSAFE,BESSD\nC\nC Common block variables:\nC\n INTEGER NBESS\nC\nC Common blocks:\nC\n COMMON /BORDER/NBESS\nC\nC Data:\nC\n DATA K0 /2.40483/\nC-----------------------------------------------------------------------\nC\nC========Find Kth roots of zero order\nC\n RTMP = K0\n NBESS = 0\n DO 10 I=2,K\n X1 = RTMP + 0.5*PI\n X2 = X1 + PI\n RTMP = RTSAFE(BESSD,X1,X2,XACC)\n 10 CONTINUE\nC\nC========Find all the intervening Kth roots\nC\n DO 20 I=1,ABS(N)\n NBESS = I\n X1 = RTMP\n X2 = X1 + PI\n RTMP = RTSAFE(BESSD,X1,X2,XACC)\n 20 CONTINUE\n RTJNK = RTMP\nC\n RETURN\n END \n\n\n\n", "meta": {"hexsha": "0a7076ed5e344d660307dc2f2bfe9a6482cd5636", "size": 2092, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "software/sample/ROOTJ.f", "max_stars_repo_name": "scattering-central/CCP13", "max_stars_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "software/sample/ROOTJ.f", "max_issues_repo_name": "scattering-central/CCP13", "max_issues_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "software/sample/ROOTJ.f", "max_forks_repo_name": "scattering-central/CCP13", "max_forks_repo_head_hexsha": "e78440d34d0ac80d2294b131ca17dddcf7505b01", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-09-05T15:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-15T11:13:45.000Z", "avg_line_length": 18.6785714286, "max_line_length": 72, "alphanum_fraction": 0.4455066922, "num_tokens": 630, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891479496521, "lm_q2_score": 0.7956581049086031, "lm_q1q2_score": 0.6541814593340394}} {"text": "! Check that parameters are correct intercepted.\r\n! Constants with comma separations are commonly\r\n! used, for instance Pi = 3._dp\r\nsubroutine foo(x)\r\n implicit none\r\n integer, parameter :: sp = selected_real_kind(6)\r\n integer, parameter :: dp = selected_real_kind(15)\r\n integer, parameter :: ii = selected_int_kind(9)\r\n integer, parameter :: il = selected_int_kind(18)\r\n real(dp), intent(inout) :: x\r\n dimension x(3)\r\n real(sp), parameter :: three_s = 3._sp\r\n real(dp), parameter :: three_d = 3._dp\r\n integer(ii), parameter :: three_i = 3_ii\r\n integer(il), parameter :: three_l = 3_il\r\n x(1) = x(1) + x(2) * three_s * three_i + x(3) * three_d * three_l\r\n x(2) = x(2) * three_s\r\n x(3) = x(3) * three_l\r\n return\r\nend subroutine\r\n\r\n\r\nsubroutine foo_no(x)\r\n implicit none\r\n integer, parameter :: sp = selected_real_kind(6)\r\n integer, parameter :: dp = selected_real_kind(15)\r\n integer, parameter :: ii = selected_int_kind(9)\r\n integer, parameter :: il = selected_int_kind(18)\r\n real(dp), intent(inout) :: x\r\n dimension x(3)\r\n real(sp), parameter :: three_s = 3.\r\n real(dp), parameter :: three_d = 3.\r\n integer(ii), parameter :: three_i = 3\r\n integer(il), parameter :: three_l = 3\r\n x(1) = x(1) + x(2) * three_s * three_i + x(3) * three_d * three_l\r\n x(2) = x(2) * three_s\r\n x(3) = x(3) * three_l\r\n return\r\nend subroutine\r\n\r\nsubroutine foo_sum(x)\r\n implicit none\r\n integer, parameter :: sp = selected_real_kind(6)\r\n integer, parameter :: dp = selected_real_kind(15)\r\n integer, parameter :: ii = selected_int_kind(9)\r\n integer, parameter :: il = selected_int_kind(18)\r\n real(dp), intent(inout) :: x\r\n dimension x(3)\r\n real(sp), parameter :: three_s = 2._sp + 1._sp\r\n real(dp), parameter :: three_d = 1._dp + 2._dp\r\n integer(ii), parameter :: three_i = 2_ii + 1_ii\r\n integer(il), parameter :: three_l = 1_il + 2_il\r\n x(1) = x(1) + x(2) * three_s * three_i + x(3) * three_d * three_l\r\n x(2) = x(2) * three_s\r\n x(3) = x(3) * three_l\r\n return\r\nend subroutine\r\n", "meta": {"hexsha": "b16af3e8bb5c533c6ef5a051537e471565ca4337", "size": 1996, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "libs/numpy/f2py/tests/src/parameter/constant_both.f90", "max_stars_repo_name": "rocketbot-cl/recognition", "max_stars_repo_head_hexsha": "cca8a87070ccaca3a26e37345c36ab1bf836e258", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 353, "max_stars_repo_stars_event_min_datetime": "2020-12-10T10:47:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:08:29.000Z", "max_issues_repo_path": "libs/numpy/f2py/tests/src/parameter/constant_both.f90", "max_issues_repo_name": "rocketbot-cl/recognition", "max_issues_repo_head_hexsha": "cca8a87070ccaca3a26e37345c36ab1bf836e258", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 80, "max_issues_repo_issues_event_min_datetime": "2020-12-10T09:54:22.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T22:08:45.000Z", "max_forks_repo_path": "libs/numpy/f2py/tests/src/parameter/constant_both.f90", "max_forks_repo_name": "rocketbot-cl/recognition", "max_forks_repo_head_hexsha": "cca8a87070ccaca3a26e37345c36ab1bf836e258", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 63, "max_forks_repo_forks_event_min_datetime": "2020-12-10T17:10:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-28T16:27:07.000Z", "avg_line_length": 34.4137931034, "max_line_length": 68, "alphanum_fraction": 0.6422845691, "num_tokens": 643, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891392358014, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.6541814444330423}} {"text": " SUBROUTINE COSFT(Y,N,ISIGN)\n REAL*8 WR,WI,WPR,WPI,WTEMP,THETA\n DIMENSION Y(N)\n THETA=3.14159265358979D0/DBLE(N)\n WR=1.0D0\n WI=0.0D0\n WPR=-2.0D0*DSIN(0.5D0*THETA)**2\n WPI=DSIN(THETA)\n SUM=Y(1)\n M=N/2\n DO 11 J=1,M-1\n WTEMP=WR\n WR=WR*WPR-WI*WPI+WR\n WI=WI*WPR+WTEMP*WPI+WI\n Y1=0.5*(Y(J+1)+Y(N-J+1))\n Y2=(Y(J+1)-Y(N-J+1))\n Y(J+1)=Y1-WI*Y2\n Y(N-J+1)=Y1+WI*Y2\n SUM=SUM+WR*Y2\n11 CONTINUE\n CALL REALFT(Y,M,+1)\n Y(2)=SUM\n DO 12 J=4,N,2\n SUM=SUM+Y(J)\n Y(J)=SUM\n12 CONTINUE\n IF (ISIGN.EQ.-1) THEN\n EVEN=Y(1)\n ODD=Y(2)\n DO 13 I=3,N-1,2\n EVEN=EVEN+Y(I)\n ODD=ODD+Y(I+1)\n13 CONTINUE\n ENF0=2.0*(EVEN-ODD)\n SUMO=Y(1)-ENF0\n SUME=(2.0*ODD/FLOAT(N))-SUMO\n Y(1)=0.5*ENF0\n Y(2)=Y(2)-SUME\n DO 14 I=3,N-1,2\n Y(I)=Y(I)-SUMO\n Y(I+1)=Y(I+1)-SUME\n14 CONTINUE\n ENDIF\n RETURN\n END\n", "meta": {"hexsha": "5b48e202c4cddb7e2bc50767d4cfa42a98471736", "size": 1026, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "Math3/NumRec/source/cosft.for", "max_stars_repo_name": "domijin/MM3", "max_stars_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Math3/NumRec/source/cosft.for", "max_issues_repo_name": "domijin/MM3", "max_issues_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Math3/NumRec/source/cosft.for", "max_forks_repo_name": "domijin/MM3", "max_forks_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.3043478261, "max_line_length": 38, "alphanum_fraction": 0.4522417154, "num_tokens": 471, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480252950991, "lm_q2_score": 0.7122321903471563, "lm_q1q2_score": 0.6541712023498946}} {"text": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\ncc cc\ncc mncosp : cocosp test program cc\ncc cc\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\n real x(10),y(10),w(10),sx(10),s2(10),t(20),c(20),e(20),wrk(550)\n integer iwrk(450)\n logical bind(20)\n integer i,ier,is,j,j3,kwrk,lwrk,m,maxbin,maxtr,n,n4,n6\n real sq\nc the absciss values of the data points.\n data x(1),x(2),x(3),x(4),x(5),x(6),x(7),x(8),x(9),x(10)/0.25,\n * 0.5,0.75,1.25,1.75,2.25,2.75,3.25,6.25,12.25/\nc the ordinate values of the data points.\n data y(1),y(2),y(3),y(4),y(5),y(6),y(7),y(8),y(9),y(10)/17.0,\n * 15.2,13.8,12.2,11.0,10.1,9.4,8.6,6.1,3.5/\nc m denotes the number of data points.\n m = 10\nc we set up the weights of the data points.\n do 10 i=1,m\n w(i) = 1.\n 10 continue\nc we set up the dimension information.\n maxtr = 100\n maxbin = 10\n lwrk = 550\n kwrk = 450\nc we fetch the knots of the cubic spline\n n = 11\n n4 = n-4\n n6 = n-6\nc the interior knots\n t(5) = 1.6\n t(6) = 2.5\n t(7) = 6.0\nc the boundary knots\n do 20 i=1,4\n t(i) = x(1)\n t(i+7) = x(m)\n 20 continue\nc loop for the different spline approximations\n do 500 is=1,3\n go to (110,130,150),is\nc a convex spline approximation\n 110 write(6,900)\n do 120 j=1,n6\n e(j) = -1.\n 120 continue\n go to 200\nc a concave spline approximation (a straight line)\n 130 write(6,905)\n do 140 j=1,n6\n e(j) = 1.\n 140 continue\n go to 200\nc no convexity/concavity constraints\n 150 write(6,910)\n do 160 j=1,n6\n e(j) = 0.\n 160 continue\nc we determine the spline approximation.\n 200 call cocosp(m,x,y,w,n,t,e,maxtr,maxbin,c,sq,sx,\n * bind,wrk,lwrk,iwrk,kwrk,ier)\nc printing of the results.\n write(6,915) ier\n write(6,920) sq\n write(6,925) n\n write(6,930)\n write(6,935) (t(i),i=1,n)\n write(6,940)\n do 300 j=1,n6\n j3 = j+3\n if(bind(j)) write(6,945) t(j3)\n 300 continue\n write(6,950)\n write(6,955) (c(i),i=1,n4)\nc we evaluate the second order derivative of the spline.\n call splder(t,n,c,3,2,x,s2,m,wrk,ier)\n write(6,960)\n do 400 i=1,m\n write(6,965) i,x(i),y(i),sx(i),s2(i)\n 400 continue\n 500 continue\n stop\nc format statements\n 900 format(28h0convex spline approximation)\n 905 format(29h0concave spline approximation)\n 910 format(35h0unconstrained spline approximation)\n 915 format(16h error flag ier=,i2)\n 920 format(1x,28hsum of squared residuals sq=,e10.3)\n 925 format(1x,24htotal number of knots n=,i2)\n 930 format(1x,21hposition of the knots)\n 935 format(5x,8f7.2)\n 940 format(1x,24hthe knots where s''(x)=0)\n 945 format(5x,f7.2)\n 950 format(1x,21hb-spline coefficients)\n 955 format(5x,4f12.4)\n 960 format(3h0 i,6x,4hx(i),5x,4hy(i),4x,7hs(x(i)),3x,9hs''(x(i)))\n 965 format(1x,i2,5x,f5.2,5x,f4.1,5x,f5.2,5x,f5.2)\n end\n", "meta": {"hexsha": "c5d8f78f6883d45df30787ba93aba0bca32b7d8e", "size": 3273, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ApproxSpline/Resources/F77-Sources/ex/mncosp.f", "max_stars_repo_name": "modelica-3rdparty/ApproxSpline", "max_stars_repo_head_hexsha": "28420f5c1a88c9cd069defbd8c05e4a78a090675", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-07-13T17:24:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-18T16:16:02.000Z", "max_issues_repo_path": "ApproxSpline/Resources/F77-Sources/ex/mncosp.f", "max_issues_repo_name": "tbeu/ApproxSpline", "max_issues_repo_head_hexsha": "28420f5c1a88c9cd069defbd8c05e4a78a090675", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-03-28T09:08:23.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T07:35:48.000Z", "max_forks_repo_path": "ApproxSpline/Resources/F77-Sources/ex/mncosp.f", "max_forks_repo_name": "modelica-3rdparty/ApproxSpline", "max_forks_repo_head_hexsha": "28420f5c1a88c9cd069defbd8c05e4a78a090675", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-10-21T07:46:49.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T20:02:06.000Z", "avg_line_length": 32.4059405941, "max_line_length": 72, "alphanum_fraction": 0.5621753743, "num_tokens": 1243, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480237330998, "lm_q2_score": 0.7122321964553657, "lm_q1q2_score": 0.6541711968351024}} {"text": " REAL*8 FUNCTION PERIOD(GRAVMU,SCPOS,SCVEL)\n IMPLICIT REAL*8 (A-H,O-Z)\nC\nC THIS ROUTINE COMPUTES THE ORBITAL PERIOD OF A SATELLITE GIVEN THE\nC POSITION AND VELOCITY VECTOR. \nC\nC VARIABLE DIM TYPE I/O DESCRIPTION\nC -------- --- ---- --- -----------\nC\nC GRAVMU 1 R*8 I GRAVITATIONAL COEFFICIENT IN KM**3/SEC**2.\nC\nC IF ZERO OR NEGATIVE, THE EARTH CENTRAL BODY TERM\nC IS USED. THE VALUE IS OBTAINED FROM THE CONST\nC ROUTINE.\nC\nC SCPOS 3 R*8 I THE S/C POSITION VECTOR. IN KM.\nC\nC NOTE ON SCPOS AND SCVEL:\nC\nC MOTION IS ASSUMED TO BE CIRCULAR OR ELLIPTICAL\nC ABOUT THE BODY FOR WHICH GRAVMU IS GIVEN. THE\nC FUNDAMENTAL PLANE AND PRINCIPAL DIRECTION MAY\nC BE ANY CONVENIENT SYSTEM. THE ORIGIN IS THE \nC BODY ABOUT WHICH MOTION OCCURS.\nC\nC SCVEL 3 R*8 I THE S/C VELOCITY VECTOR. IN KM/SEC.\nC\nC PERIOD 1 R*8 O THE FUNCTION VALUE RETURNED. THIS IS THE ORBITAL\nC PERIOD IN SECONDS.\nC\nC***********************************************************************\nC\nC BY C PETRUZZO, 11/83\nC MODIFIED.......\nC\nC***********************************************************************\nC \n REAL*8 GRAVMU,SCPOS(3),SCVEL(3),ELEMS(6)\n REAL*8 TWOPI/ 6.283185307179586D0 /\nC\nC SOURCE OF EQUATIONS: ORBITAL FLIGHT HANDBOOK, PART 1, PAGE III-24, \nC EQN 4-1. THE HANDBOOK WAS DONE BY THE MARTIN COMPANY FOR MSFC. \nC\n VMU = GRAVMU\n IF(GRAVMU.LE.0.D0) VMU = CONST(56)\nC\n R = DSQRT( SCPOS(1)**2 + SCPOS(2)**2 + SCPOS(3)**2 )\n VSQ = SCVEL(1)**2 + SCVEL(2)**2 + SCVEL(3)**2\nC\n SMA = R / (2.D0 - (R*VSQ/VMU) )\nC\n PERIOD = TWOPI * SMA * DSQRT(SMA/VMU)\nC\n RETURN\n END\n", "meta": {"hexsha": "067559817fd046280f4b23348c6d5736a7cdbae8", "size": 1864, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "gsc-13083/period.for", "max_stars_repo_name": "SteveDoyle2/nasa-cosmic", "max_stars_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_stars_repo_licenses": ["BSD-Source-Code"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2015-03-14T07:26:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-16T12:23:17.000Z", "max_issues_repo_path": "gsc-13083/period.for", "max_issues_repo_name": "SteveDoyle2/nasa-cosmic", "max_issues_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_issues_repo_licenses": ["BSD-Source-Code"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gsc-13083/period.for", "max_forks_repo_name": "SteveDoyle2/nasa-cosmic", "max_forks_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_forks_repo_licenses": ["BSD-Source-Code"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2016-02-12T22:18:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-08T17:46:54.000Z", "avg_line_length": 33.2857142857, "max_line_length": 72, "alphanum_fraction": 0.5182403433, "num_tokens": 593, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802440252811, "lm_q2_score": 0.7122321903471563, "lm_q1q2_score": 0.6541711959927166}} {"text": "SUBROUTINE p51(input_file,output_file)\n!-------------------------------------------------------------------------\n! Program 5.1 Plane or axisymmetric strain analysis of an elastic solid\n! using 3-, 6-, 10- or 15-node right-angled triangles or\n! 4-, 8- or 9-node rectangular quadrilaterals. Mesh numbered\n! in x(r)- or y(z)- direction.\n!-------------------------------------------------------------------------\n USE main \n USE geom \n IMPLICIT NONE\n CHARACTER(len=70),INTENT(IN) :: input_file\n CHARACTER(len=70),INTENT(OUT) :: output_file\n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\n INTEGER::fixed_freedoms,i,iel,k,loaded_nodes,ndim=2,ndof,nels,neq,nip, &\n nlen,nn,nod,nodof=2,nprops=2,np_types,nr,nst=3,nxe,nye \n REAL(iwp)::det,one=1.0_iwp,penalty=1.0e20_iwp,zero=0.0_iwp\n CHARACTER(LEN=15)::argv,element,dir,type_2d\n!-----------------------dynamic arrays------------------------------------\n INTEGER,ALLOCATABLE::etype(:),g(:),g_g(:,:),g_num(:,:),kdiag(:),nf(:,:), &\n no(:),node(:),num(:),sense(:) \n REAL(iwp),ALLOCATABLE::bee(:,:),coord(:,:),dee(:,:),der(:,:),deriv(:,:), &\n eld(:),fun(:),gc(:),g_coord(:,:),jac(:,:),km(:,:),kv(:),loads(:), &\n points(:,:),prop(:,:),sigma(:),value(:),weights(:),x_coords(:), &\n y_coords(:) \n!-----------------------input and initialisation--------------------------\n\n OPEN(10,FILE=input_file) \n OPEN(11,FILE=output_file)\n READ(10,*)type_2d,element,nod,dir,nxe,nye,nip,np_types\n CALL mesh_size(element,nod,nels,nn,nxe,nye)\n !ndof: number of degrees of freedom per element\n !nodof: number of degrees of freedom per node\n ndof=nod*nodof \n IF(type_2d=='axisymmetric')nst=4\n ALLOCATE(nf(nodof,nn),points(nip,ndim),g(ndof),g_coord(ndim,nn),fun(nod),&\n coord(nod,ndim),jac(ndim,ndim),g_num(nod,nels),der(ndim,nod), &\n deriv(ndim,nod),bee(nst,ndof),km(ndof,ndof),eld(ndof),weights(nip), &\n g_g(ndof,nels),prop(nprops,np_types),num(nod),x_coords(nxe+1), &\n y_coords(nye+1),etype(nels),gc(ndim),dee(nst,nst),sigma(nst))\n READ(10,*)prop \n etype=1 \n IF(np_types>1)read(10,*)etype \n READ(10,*)x_coords,y_coords\n nf=1 \n READ(10,*)nr,(k,nf(:,k),i=1,nr) \n CALL formnf(nf) \n neq=MAXVAL(nf)\n ALLOCATE(loads(0:neq),kdiag(neq)) \n kdiag=0\n!-----------------------loop the elements to find global arrays sizes-----\n elements_1: DO iel=1,nels\n CALL geom_rect(element,iel,x_coords,y_coords,coord,num,dir)\n CALL num_to_g(num,nf,g) \n g_num(:,iel)=num\n g_coord(:,num)=TRANSPOSE(coord) \n g_g(:,iel)=g \n CALL fkdiag(kdiag,g)\n END DO elements_1\n CALL mesh(g_coord,g_num,argv,nlen,12)\n DO i=2,neq \n kdiag(i)=kdiag(i)+kdiag(i-1) \n END DO \n ALLOCATE(kv(kdiag(neq)))\n WRITE(11,'(2(A,I5))') &\n \" There are\",neq,\" equations and the skyline storage is\",kdiag(neq)\n!-----------------------element stiffness integration and assembly--------\n CALL sample(element,points,weights) \n kv=zero \n gc=one\n elements_2: DO iel=1,nels\n CALL deemat(dee,prop(1,etype(iel)),prop(2,etype(iel))) \n num=g_num(:,iel)\n coord=TRANSPOSE(g_coord(:,num)) \n g=g_g(:,iel) \n km=zero\n int_pts_1: DO i=1,nip\n CALL shape_fun(fun,points,i) \n CALL shape_der(der,points,i)\n jac=MATMUL(der,coord) \n det=determinant(jac) \n CALL invert(jac)\n deriv=MATMUL(jac,der) \n CALL beemat(bee,deriv)\n IF(type_2d=='axisymmetric')THEN\n gc=MATMUL(fun,coord) \n bee(4,1:ndof-1:2)=fun(:)/gc(1)\n END IF\n km=km+MATMUL(MATMUL(TRANSPOSE(bee),dee),bee)*det*weights(i)*gc(1)\n END DO int_pts_1\n CALL fsparv(kv,km,g,kdiag)\n END DO elements_2 \n loads=zero \n READ(10,*)loaded_nodes,(k,loads(nf(:,k)),i=1,loaded_nodes)\n READ(10,*)fixed_freedoms\n IF(fixed_freedoms/=0)THEN\n ALLOCATE(node(fixed_freedoms),sense(fixed_freedoms), &\n value(fixed_freedoms),no(fixed_freedoms))\n READ(10,*)(node(i),sense(i),value(i),i=1,fixed_freedoms)\n DO i=1,fixed_freedoms \n no(i)=nf(sense(i),node(i)) \n END DO\n kv(kdiag(no))=kv(kdiag(no))+penalty \n loads(no)=kv(kdiag(no))*value\n END IF\n!-----------------------equation solution---------------------------------\n CALL sparin(kv,kdiag) \n CALL spabac(kv,loads,kdiag) \n loads(0)=zero\n IF(type_2d=='axisymmetric')THEN\n WRITE(11,'(/A)')\" Node r-disp z-disp\" \n ELSE\n WRITE(11,'(/A)')\" Node x-disp y-disp\"\n END IF\n DO k=1,nn \n WRITE(11,'(I5,2E12.4)')k,loads(nf(:,k)) \n END DO\n!-----------------------recover stresses at nip integrating points--------\n nip=1 \n DEALLOCATE(points,weights) \n ALLOCATE(points(nip,ndim),weights(nip))\n CALL sample(element,points,weights)\n WRITE(11,'(/A,I2,A)')\" The integration point (nip=\",nip,\") stresses are:\"\n IF(type_2d=='axisymmetric')THEN\n WRITE(11,'(A,A)')\" Element r-coord z-coord\", &\n \" sig_r sig_z tau_rz sig_t\" \n ELSE \n WRITE(11,'(A,A)')\" Element x-coord y-coord\", &\n \" sig_x sig_y tau_xy\" \n END IF\n elements_3: DO iel=1,nels\n CALL deemat(dee,prop(1,etype(iel)),prop(2,etype(iel))) \n num=g_num(:,iel)\n coord=TRANSPOSE(g_coord(:,num)) \n g=g_g(:,iel) \n eld=loads(g)\n int_pts_2: DO i=1,nip\n CALL shape_fun(fun,points,i) \n CALL shape_der(der,points,i)\n gc=MATMUL(fun,coord) \n jac=MATMUL(der,coord) \n CALL invert(jac)\n deriv=MATMUL(jac,der) \n CALL beemat(bee,deriv)\n IF(type_2d=='axisymmetric')THEN\n gc=MATMUL(fun,coord) \n bee(4,1:ndof-1:2)=fun(:)/gc(1)\n END IF\n sigma=MATMUL(dee,MATMUL(bee,eld)) \n WRITE(11,'(I5,6E12.4)')iel,gc,sigma\n END DO int_pts_2\n END DO elements_3\n CALL dismsh(loads,nf,0.05_iwp,g_coord,g_num,argv,nlen,13)\n CALL vecmsh(loads,nf,0.05_iwp,0.1_iwp,g_coord,g_num,argv,nlen,14)\n\nEND SUBROUTINE p51\n", "meta": {"hexsha": "e43767afcb59d5b42d9c78c62c11aa861f52ef28", "size": 5770, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "subordinates/Static-Equilibrium-Linear-Elastic-Solids/p51.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": "subordinates/Static-Equilibrium-Linear-Elastic-Solids/p51.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": "subordinates/Static-Equilibrium-Linear-Elastic-Solids/p51.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": 36.9871794872, "max_line_length": 75, "alphanum_fraction": 0.5918544194, "num_tokens": 1950, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802395624257, "lm_q2_score": 0.7122321781307374, "lm_q1q2_score": 0.6541711815935879}} {"text": "*DECK DWUPDT\n SUBROUTINE DWUPDT (N, R, LDR, W, B, ALPHA, COS, SIN)\nC***BEGIN PROLOGUE DWUPDT\nC***SUBSIDIARY\nC***PURPOSE Subsidiary to DNLS1 and DNLS1E\nC***LIBRARY SLATEC\nC***TYPE DOUBLE PRECISION (RWUPDT-S, DWUPDT-D)\nC***AUTHOR (UNKNOWN)\nC***DESCRIPTION\nC\nC Given an N by N upper triangular matrix R, this subroutine\nC computes the QR decomposition of the matrix formed when a row\nC is added to R. If the row is specified by the vector W, then\nC DWUPDT determines an orthogonal matrix Q such that when the\nC N+1 by N matrix composed of R augmented by W is premultiplied\nC by (Q TRANSPOSE), the resulting matrix is upper trapezoidal.\nC The orthogonal matrix Q is the product of N transformations\nC\nC G(1)*G(2)* ... *G(N)\nC\nC where G(I) is a Givens rotation in the (I,N+1) plane which\nC eliminates elements in the I-th plane. DWUPDT also\nC computes the product (Q TRANSPOSE)*C where C is the\nC (N+1)-vector (b,alpha). Q itself is not accumulated, rather\nC the information to recover the G rotations is supplied.\nC\nC The subroutine statement is\nC\nC SUBROUTINE DWUPDT(N,R,LDR,W,B,ALPHA,COS,SIN)\nC\nC where\nC\nC N is a positive integer input variable set to the order of R.\nC\nC R is an N by N array. On input the upper triangular part of\nC R must contain the matrix to be updated. On output R\nC contains the updated triangular matrix.\nC\nC LDR is a positive integer input variable not less than N\nC which specifies the leading dimension of the array R.\nC\nC W is an input array of length N which must contain the row\nC vector to be added to R.\nC\nC B is an array of length N. On input B must contain the\nC first N elements of the vector C. On output B contains\nC the first N elements of the vector (Q TRANSPOSE)*C.\nC\nC ALPHA is a variable. On input ALPHA must contain the\nC (N+1)-st element of the vector C. On output ALPHA contains\nC the (N+1)-st element of the vector (Q TRANSPOSE)*C.\nC\nC COS is an output array of length N which contains the\nC cosines of the transforming Givens rotations.\nC\nC SIN is an output array of length N which contains the\nC sines of the transforming Givens rotations.\nC\nC **********\nC\nC***SEE ALSO DNLS1, DNLS1E\nC***ROUTINES CALLED (NONE)\nC***REVISION HISTORY (YYMMDD)\nC 800301 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890831 Modified array declarations. (WRB)\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900326 Removed duplicate information from DESCRIPTION section.\nC (WRB)\nC 900328 Added TYPE section. (WRB)\nC***END PROLOGUE DWUPDT\n INTEGER N,LDR\n DOUBLE PRECISION ALPHA\n DOUBLE PRECISION R(LDR,*),W(*),B(*),COS(*),SIN(*)\n INTEGER I,J,JM1\n DOUBLE PRECISION COTAN,ONE,P5,P25,ROWJ,TAN,TEMP,ZERO\n SAVE ONE, P5, P25, ZERO\n DATA ONE,P5,P25,ZERO /1.0D0,5.0D-1,2.5D-1,0.0D0/\nC***FIRST EXECUTABLE STATEMENT DWUPDT\n DO 60 J = 1, N\n ROWJ = W(J)\n JM1 = J - 1\nC\nC APPLY THE PREVIOUS TRANSFORMATIONS TO\nC R(I,J), I=1,2,...,J-1, AND TO W(J).\nC\n IF (JM1 .LT. 1) GO TO 20\n DO 10 I = 1, JM1\n TEMP = COS(I)*R(I,J) + SIN(I)*ROWJ\n ROWJ = -SIN(I)*R(I,J) + COS(I)*ROWJ\n R(I,J) = TEMP\n 10 CONTINUE\n 20 CONTINUE\nC\nC DETERMINE A GIVENS ROTATION WHICH ELIMINATES W(J).\nC\n COS(J) = ONE\n SIN(J) = ZERO\n IF (ROWJ .EQ. ZERO) GO TO 50\n IF (ABS(R(J,J)) .GE. ABS(ROWJ)) GO TO 30\n COTAN = R(J,J)/ROWJ\n SIN(J) = P5/SQRT(P25+P25*COTAN**2)\n COS(J) = SIN(J)*COTAN\n GO TO 40\n 30 CONTINUE\n TAN = ROWJ/R(J,J)\n COS(J) = P5/SQRT(P25+P25*TAN**2)\n SIN(J) = COS(J)*TAN\n 40 CONTINUE\nC\nC APPLY THE CURRENT TRANSFORMATION TO R(J,J), B(J), AND ALPHA.\nC\n R(J,J) = COS(J)*R(J,J) + SIN(J)*ROWJ\n TEMP = COS(J)*B(J) + SIN(J)*ALPHA\n ALPHA = -SIN(J)*B(J) + COS(J)*ALPHA\n B(J) = TEMP\n 50 CONTINUE\n 60 CONTINUE\n RETURN\nC\nC LAST CARD OF SUBROUTINE DWUPDT.\nC\n END\n", "meta": {"hexsha": "67e51b239926fb29888dd2e6f55d28f803e20b10", "size": 4250, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/idl/extern/sdss/idlutils/src/slatec/dwupdt.f", "max_stars_repo_name": "sfarrens/cosmostat", "max_stars_repo_head_hexsha": "a475315cda06dca346095a1e83cb6ad23979acae", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-02-09T05:03:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-26T10:20:02.000Z", "max_issues_repo_path": "src/idl/extern/sdss/idlutils/src/slatec/dwupdt.f", "max_issues_repo_name": "sfarrens/cosmostat", "max_issues_repo_head_hexsha": "a475315cda06dca346095a1e83cb6ad23979acae", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2020-04-28T17:09:50.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-01T16:24:43.000Z", "max_forks_repo_path": "src/idl/extern/sdss/idlutils/src/slatec/dwupdt.f", "max_forks_repo_name": "sfarrens/cosmostat", "max_forks_repo_head_hexsha": "a475315cda06dca346095a1e83cb6ad23979acae", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-06-22T07:53:00.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-10T19:59:53.000Z", "avg_line_length": 34.2741935484, "max_line_length": 69, "alphanum_fraction": 0.6174117647, "num_tokens": 1376, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894661025423, "lm_q2_score": 0.7310585844894971, "lm_q1q2_score": 0.6541435205050374}} {"text": " SUBROUTINE CLAGS2( UPPER, A1, A2, A3, B1, B2, B3, CSU, SNU, CSV,\n $ SNV, CSQ, SNQ )\n*\n* -- LAPACK auxiliary routine (version 3.0) --\n* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,\n* Courant Institute, Argonne National Lab, and Rice University\n* September 30, 1994 \n*\n* .. Scalar Arguments ..\n LOGICAL UPPER\n REAL A1, A3, B1, B3, CSQ, CSU, CSV\n COMPLEX A2, B2, SNQ, SNU, SNV\n* ..\n*\n* Purpose\n* =======\n*\n* CLAGS2 computes 2-by-2 unitary matrices U, V and Q, such\n* that if ( UPPER ) then\n*\n* U'*A*Q = U'*( A1 A2 )*Q = ( x 0 )\n* ( 0 A3 ) ( x x )\n* and\n* V'*B*Q = V'*( B1 B2 )*Q = ( x 0 )\n* ( 0 B3 ) ( x x )\n*\n* or if ( .NOT.UPPER ) then\n*\n* U'*A*Q = U'*( A1 0 )*Q = ( x x )\n* ( A2 A3 ) ( 0 x )\n* and\n* V'*B*Q = V'*( B1 0 )*Q = ( x x )\n* ( B2 B3 ) ( 0 x )\n* where\n*\n* U = ( CSU SNU ), V = ( CSV SNV ),\n* ( -CONJG(SNU) CSU ) ( -CONJG(SNV) CSV )\n*\n* Q = ( CSQ SNQ )\n* ( -CONJG(SNQ) CSQ )\n*\n* Z' denotes the conjugate transpose of Z.\n*\n* The rows of the transformed A and B are parallel. Moreover, if the\n* input 2-by-2 matrix A is not zero, then the transformed (1,1) entry\n* of A is not zero. If the input matrices A and B are both not zero,\n* then the transformed (2,2) element of B is not zero, except when the\n* first rows of input A and B are parallel and the second rows are\n* zero.\n*\n* Arguments\n* =========\n*\n* UPPER (input) LOGICAL\n* = .TRUE.: the input matrices A and B are upper triangular.\n* = .FALSE.: the input matrices A and B are lower triangular.\n*\n* A1 (input) REAL\n* A2 (input) COMPLEX\n* A3 (input) REAL\n* On entry, A1, A2 and A3 are elements of the input 2-by-2\n* upper (lower) triangular matrix A.\n*\n* B1 (input) REAL\n* B2 (input) COMPLEX\n* B3 (input) REAL\n* On entry, B1, B2 and B3 are elements of the input 2-by-2\n* upper (lower) triangular matrix B.\n*\n* CSU (output) REAL\n* SNU (output) COMPLEX\n* The desired unitary matrix U.\n*\n* CSV (output) REAL\n* SNV (output) COMPLEX\n* The desired unitary matrix V.\n*\n* CSQ (output) REAL\n* SNQ (output) COMPLEX\n* The desired unitary matrix Q.\n*\n* =====================================================================\n*\n* .. Parameters ..\n REAL ZERO, ONE\n PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 )\n* ..\n* .. Local Scalars ..\n REAL A, AUA11, AUA12, AUA21, AUA22, AVB11, AVB12,\n $ AVB21, AVB22, CSL, CSR, D, FB, FC, S1, S2, SNL,\n $ SNR, UA11R, UA22R, VB11R, VB22R\n COMPLEX B, C, D1, R, T, UA11, UA12, UA21, UA22, VB11,\n $ VB12, VB21, VB22\n* ..\n* .. External Subroutines ..\n EXTERNAL CLARTG, SLASV2\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC ABS, AIMAG, CMPLX, CONJG, REAL\n* ..\n* .. Statement Functions ..\n REAL ABS1\n* ..\n* .. Statement Function definitions ..\n ABS1( T ) = ABS( REAL( T ) ) + ABS( AIMAG( T ) )\n* ..\n* .. Executable Statements ..\n*\n IF( UPPER ) THEN\n*\n* Input matrices A and B are upper triangular matrices\n*\n* Form matrix C = A*adj(B) = ( a b )\n* ( 0 d )\n*\n A = A1*B3\n D = A3*B1\n B = A2*B1 - A1*B2\n FB = ABS( B )\n*\n* Transform complex 2-by-2 matrix C to real matrix by unitary\n* diagonal matrix diag(1,D1).\n*\n D1 = ONE\n IF( FB.NE.ZERO )\n $ D1 = B / FB\n*\n* The SVD of real 2 by 2 triangular C\n*\n* ( CSL -SNL )*( A B )*( CSR SNR ) = ( R 0 )\n* ( SNL CSL ) ( 0 D ) ( -SNR CSR ) ( 0 T )\n*\n CALL SLASV2( A, FB, D, S1, S2, SNR, CSR, SNL, CSL )\n*\n IF( ABS( CSL ).GE.ABS( SNL ) .OR. ABS( CSR ).GE.ABS( SNR ) )\n $ THEN\n*\n* Compute the (1,1) and (1,2) elements of U'*A and V'*B,\n* and (1,2) element of |U|'*|A| and |V|'*|B|.\n*\n UA11R = CSL*A1\n UA12 = CSL*A2 + D1*SNL*A3\n*\n VB11R = CSR*B1\n VB12 = CSR*B2 + D1*SNR*B3\n*\n AUA12 = ABS( CSL )*ABS1( A2 ) + ABS( SNL )*ABS( A3 )\n AVB12 = ABS( CSR )*ABS1( B2 ) + ABS( SNR )*ABS( B3 )\n*\n* zero (1,2) elements of U'*A and V'*B\n*\n IF( ( ABS( UA11R )+ABS1( UA12 ) ).EQ.ZERO ) THEN\n CALL CLARTG( -CMPLX( VB11R ), CONJG( VB12 ), CSQ, SNQ,\n $ R )\n ELSE IF( ( ABS( VB11R )+ABS1( VB12 ) ).EQ.ZERO ) THEN\n CALL CLARTG( -CMPLX( UA11R ), CONJG( UA12 ), CSQ, SNQ,\n $ R )\n ELSE IF( AUA12 / ( ABS( UA11R )+ABS1( UA12 ) ).LE.AVB12 /\n $ ( ABS( VB11R )+ABS1( VB12 ) ) ) THEN\n CALL CLARTG( -CMPLX( UA11R ), CONJG( UA12 ), CSQ, SNQ,\n $ R )\n ELSE\n CALL CLARTG( -CMPLX( VB11R ), CONJG( VB12 ), CSQ, SNQ,\n $ R )\n END IF\n*\n CSU = CSL\n SNU = -D1*SNL\n CSV = CSR\n SNV = -D1*SNR\n*\n ELSE\n*\n* Compute the (2,1) and (2,2) elements of U'*A and V'*B,\n* and (2,2) element of |U|'*|A| and |V|'*|B|.\n*\n UA21 = -CONJG( D1 )*SNL*A1\n UA22 = -CONJG( D1 )*SNL*A2 + CSL*A3\n*\n VB21 = -CONJG( D1 )*SNR*B1\n VB22 = -CONJG( D1 )*SNR*B2 + CSR*B3\n*\n AUA22 = ABS( SNL )*ABS1( A2 ) + ABS( CSL )*ABS( A3 )\n AVB22 = ABS( SNR )*ABS1( B2 ) + ABS( CSR )*ABS( B3 )\n*\n* zero (2,2) elements of U'*A and V'*B, and then swap.\n*\n IF( ( ABS1( UA21 )+ABS1( UA22 ) ).EQ.ZERO ) THEN\n CALL CLARTG( -CONJG( VB21 ), CONJG( VB22 ), CSQ, SNQ, R )\n ELSE IF( ( ABS1( VB21 )+ABS( VB22 ) ).EQ.ZERO ) THEN\n CALL CLARTG( -CONJG( UA21 ), CONJG( UA22 ), CSQ, SNQ, R )\n ELSE IF( AUA22 / ( ABS1( UA21 )+ABS1( UA22 ) ).LE.AVB22 /\n $ ( ABS1( VB21 )+ABS1( VB22 ) ) ) THEN\n CALL CLARTG( -CONJG( UA21 ), CONJG( UA22 ), CSQ, SNQ, R )\n ELSE\n CALL CLARTG( -CONJG( VB21 ), CONJG( VB22 ), CSQ, SNQ, R )\n END IF\n*\n CSU = SNL\n SNU = D1*CSL\n CSV = SNR\n SNV = D1*CSR\n*\n END IF\n*\n ELSE\n*\n* Input matrices A and B are lower triangular matrices\n*\n* Form matrix C = A*adj(B) = ( a 0 )\n* ( c d )\n*\n A = A1*B3\n D = A3*B1\n C = A2*B3 - A3*B2\n FC = ABS( C )\n*\n* Transform complex 2-by-2 matrix C to real matrix by unitary\n* diagonal matrix diag(d1,1).\n*\n D1 = ONE\n IF( FC.NE.ZERO )\n $ D1 = C / FC\n*\n* The SVD of real 2 by 2 triangular C\n*\n* ( CSL -SNL )*( A 0 )*( CSR SNR ) = ( R 0 )\n* ( SNL CSL ) ( C D ) ( -SNR CSR ) ( 0 T )\n*\n CALL SLASV2( A, FC, D, S1, S2, SNR, CSR, SNL, CSL )\n*\n IF( ABS( CSR ).GE.ABS( SNR ) .OR. ABS( CSL ).GE.ABS( SNL ) )\n $ THEN\n*\n* Compute the (2,1) and (2,2) elements of U'*A and V'*B,\n* and (2,1) element of |U|'*|A| and |V|'*|B|.\n*\n UA21 = -D1*SNR*A1 + CSR*A2\n UA22R = CSR*A3\n*\n VB21 = -D1*SNL*B1 + CSL*B2\n VB22R = CSL*B3\n*\n AUA21 = ABS( SNR )*ABS( A1 ) + ABS( CSR )*ABS1( A2 )\n AVB21 = ABS( SNL )*ABS( B1 ) + ABS( CSL )*ABS1( B2 )\n*\n* zero (2,1) elements of U'*A and V'*B.\n*\n IF( ( ABS1( UA21 )+ABS( UA22R ) ).EQ.ZERO ) THEN\n CALL CLARTG( CMPLX( VB22R ), VB21, CSQ, SNQ, R )\n ELSE IF( ( ABS1( VB21 )+ABS( VB22R ) ).EQ.ZERO ) THEN\n CALL CLARTG( CMPLX( UA22R ), UA21, CSQ, SNQ, R )\n ELSE IF( AUA21 / ( ABS1( UA21 )+ABS( UA22R ) ).LE.AVB21 /\n $ ( ABS1( VB21 )+ABS( VB22R ) ) ) THEN\n CALL CLARTG( CMPLX( UA22R ), UA21, CSQ, SNQ, R )\n ELSE\n CALL CLARTG( CMPLX( VB22R ), VB21, CSQ, SNQ, R )\n END IF\n*\n CSU = CSR\n SNU = -CONJG( D1 )*SNR\n CSV = CSL\n SNV = -CONJG( D1 )*SNL\n*\n ELSE\n*\n* Compute the (1,1) and (1,2) elements of U'*A and V'*B,\n* and (1,1) element of |U|'*|A| and |V|'*|B|.\n*\n UA11 = CSR*A1 + CONJG( D1 )*SNR*A2\n UA12 = CONJG( D1 )*SNR*A3\n*\n VB11 = CSL*B1 + CONJG( D1 )*SNL*B2\n VB12 = CONJG( D1 )*SNL*B3\n*\n AUA11 = ABS( CSR )*ABS( A1 ) + ABS( SNR )*ABS1( A2 )\n AVB11 = ABS( CSL )*ABS( B1 ) + ABS( SNL )*ABS1( B2 )\n*\n* zero (1,1) elements of U'*A and V'*B, and then swap.\n*\n IF( ( ABS1( UA11 )+ABS1( UA12 ) ).EQ.ZERO ) THEN\n CALL CLARTG( VB12, VB11, CSQ, SNQ, R )\n ELSE IF( ( ABS1( VB11 )+ABS1( VB12 ) ).EQ.ZERO ) THEN\n CALL CLARTG( UA12, UA11, CSQ, SNQ, R )\n ELSE IF( AUA11 / ( ABS1( UA11 )+ABS1( UA12 ) ).LE.AVB11 /\n $ ( ABS1( VB11 )+ABS1( VB12 ) ) ) THEN\n CALL CLARTG( UA12, UA11, CSQ, SNQ, R )\n ELSE\n CALL CLARTG( VB12, VB11, CSQ, SNQ, R )\n END IF\n*\n CSU = SNR\n SNU = CONJG( D1 )*CSR\n CSV = SNL\n SNV = CONJG( D1 )*CSL\n*\n END IF\n*\n END IF\n*\n RETURN\n*\n* End of CLAGS2\n*\n END\n", "meta": {"hexsha": "6d01a681155a1ca3c7c9f239977d6fcb655e9bdc", "size": 9741, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "external/lapack/clags2.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "external/lapack/clags2.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "external/lapack/clags2.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 31.8333333333, "max_line_length": 72, "alphanum_fraction": 0.4330150909, "num_tokens": 3481, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894745194281, "lm_q2_score": 0.7310585727705127, "lm_q1q2_score": 0.6541435161722502}} {"text": " integer function get_eqvfac(neqv,fix_vtx,nvtx)\n\n integer, intent(in) ::\n & nvtx,\n & neqv(nvtx)\n logical, intent(in) ::\n & fix_vtx(nvtx)\n\n integer ::\n & ieqvfac, ivtx\n\n integer, external ::\n & ifac\n\n ieqvfac = 1\n do ivtx = 1, nvtx\n if (fix_vtx(ivtx).or.neqv(ivtx).lt.0) cycle\n ieqvfac = ieqvfac*ifac(neqv(ivtx))\n end do\n \n get_eqvfac = ieqvfac\n\n return\n end\n", "meta": {"hexsha": "dbb4292850f9adcb7cfd59497597063b69a0c335", "size": 472, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "formula/get_eqvfac.f", "max_stars_repo_name": "ak-ustutt/GeCCo-public", "max_stars_repo_head_hexsha": "8d43a6c9323aeba7eb54625b95553bfd4b2418c6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "formula/get_eqvfac.f", "max_issues_repo_name": "ak-ustutt/GeCCo-public", "max_issues_repo_head_hexsha": "8d43a6c9323aeba7eb54625b95553bfd4b2418c6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "formula/get_eqvfac.f", "max_forks_repo_name": "ak-ustutt/GeCCo-public", "max_forks_repo_head_hexsha": "8d43a6c9323aeba7eb54625b95553bfd4b2418c6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 18.88, "max_line_length": 52, "alphanum_fraction": 0.5021186441, "num_tokens": 161, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8947894632969136, "lm_q2_score": 0.7310585669110203, "lm_q1q2_score": 0.6541435027249226}} {"text": " subroutine exjlnl (z, l, jl, nl)\n\nc purpose: to calculate the spherical bessel functions jl and nl\nc for l = 0 to 6 using exact analytic expression\nc\nc arguments:\nc z = argument of jl and nl\nc l = integer order of spherical bessel function\nc jl = jl bessel function (abramowitz conventions)\nc nl = nl bessel function (abramowitz yl conventions)\nc Note that this nl = abramowitz yl.\nc\nc analytic expressions from abramowitz 10.1.11 and 10.1.12\nc recurrence relation to get analytic j4,n4 eqns 10.1.19-22 ala\n\n implicit double precision (a-h, o-z)\n\n complex*16 z, jl, nl\n\n complex*16 cosz, sinz\n\nc Exact formulae unstable for very small z, so use series\nc expansion there. Limit of .3 chosen for 9 digit agreement.\n if (abs(z) .lt. 0.3) then\n call bjnser (z, l, jl, nl, 0)\n else\nc use analytic formulae\n cosz = cos(z)\n sinz = sin(z)\n\n if (l .eq. 0) then\n jl = sinz / z\n nl = -cosz / z\n\n elseif (l .eq. 1) then\n jl = sinz/z**2 - cosz/z\n nl = -cosz/z**2 - sinz/z\n\n elseif (l .eq. 2) then\n jl = ( 3/z**3 - 1/z)*sinz - 3*cosz/z**2\n nl = (-3/z**3 + 1/z)*cosz - 3*sinz/z**2\n\n elseif (l .eq. 3) then\n jl = ( 15/z**4 - 6/z**2)*sinz + (-15/z**3 + 1/z)*cosz\n nl = (-15/z**4 + 6/z**2)*cosz + (-15/z**3 + 1/z)*sinz\n\n elseif (l .eq. 4) then\n jl = ( 105/z**5 - 45/z**3 + 1/z )*sinz + \n 1 ( -105/z**4 + 10/z**2 )*cosz\n nl = (-105/z**5 + 45/z**3 - 1/z )*cosz + \n 1 ( -105/z**4 + 10/z**2 )*sinz\n\n elseif (l .eq. 5) then\n jl = ( 945/z**6 - 420/z**4 + 15/z**2 )*sinz + \n 1 ( -945/z**5 + 105/z**3 - 1/z )*cosz\n nl = (-945/z**6 + 420/z**4 - 15/z**2 )*cosz + \n 1 ( -945/z**5 + 105/z**3 - 1/z )*sinz\n\n elseif (l .eq. 6) then\n jl = ( 10395/z**7 - 4725/z**5 + 210/z**3 - 1/z )*sinz + \n 1 ( -10395/z**6 + 1155/z**4 - 21/z**2 )*cosz\n nl = (-10395/z**7 + 4725/z**5 - 210/z**3 + 1/z )*cosz + \n 1 ( -10395/z**6 + 1155/z**4 - 21/z**2 )*sinz\n\n else\n stop 'exjlnl, l out of range'\n endif\n endif\n\n return\n end\n", "meta": {"hexsha": "c6a08ec0488eab528014f7b23c551152cc505320", "size": 2385, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH/exjlnl.f", "max_stars_repo_name": "xraypy/feff85exafs", "max_stars_repo_head_hexsha": "ec8dcb07ca8ee034d0fa7431782074f0f65357a5", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2016-01-05T21:29:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:59:17.000Z", "max_issues_repo_path": "src/MATH/exjlnl.f", "max_issues_repo_name": "bruceravel/feff85exafs", "max_issues_repo_head_hexsha": "9698ce3703a73def4c1a965f276708d689ea5acb", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 17, "max_issues_repo_issues_event_min_datetime": "2015-01-04T18:37:30.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-07T12:06:12.000Z", "max_forks_repo_path": "src/MATH/exjlnl.f", "max_forks_repo_name": "bruceravel/feff85exafs", "max_forks_repo_head_hexsha": "9698ce3703a73def4c1a965f276708d689ea5acb", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2016-01-05T21:29:26.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T13:11:01.000Z", "avg_line_length": 33.125, "max_line_length": 70, "alphanum_fraction": 0.4620545073, "num_tokens": 870, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133447766224, "lm_q2_score": 0.6959583250334527, "lm_q1q2_score": 0.6541405171073282}} {"text": "MODULE Riemann_zeta\r\n\r\n! From CERNLIB, with permission.\r\n! Code converted using TO_F90 by Alan Miller\r\n! Date: 2002-02-27 Time: 16:11:48\r\n\r\n! Author: K.S. Kolbig, 7 June 1992\r\n! Revision 1.1.1.1 1996/04/01 15:02:00 mclareni\r\n! Mathlib gen/C (C315)\r\n\r\n! The Riemann Zeta function\r\n! Reference:\r\n! Cody, W.J., Hillstrom, K.E. & Thather, H.C., `Chebyshev approximations\r\n! for the Riemann zeta function', Math. Comp., vol.25 (1971), 537-547.\r\n\r\n! N.B. The value returned by the CERNLIB routine was (zeta - 1) when the\r\n! argument was > 1. This version returns the value of zeta.\r\n\r\n\r\nIMPLICIT NONE\r\nINTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(12, 60)\r\n\r\n\r\nCONTAINS\r\n\r\n\r\nFUNCTION r_zeta(x) RESULT(fn_val)\r\n\r\nREAL (dp), INTENT(IN) :: x\r\nREAL (dp) :: fn_val\r\n\r\nREAL (dp), PARAMETER :: delta = 1.0D-13, z1 = 1.0_dp, hf = z1/2, th = z1/3, &\r\n pi = 3.14159265358979324_dp, pih = pi/2, pi2 = 2*pi\r\n\r\nREAL (dp), PARAMETER :: p1(0:8) = (/ 1.28716812148244639D+10, &\r\n 1.37539693203702511D+10, 5.10665591836440610D+09, 8.56147100243331486D+08, &\r\n 7.48361812438023298D+07, 4.86010658546188251D+06, 2.73957499022140609D+05, &\r\n 4.63171084318342712D+03, 5.78758100409666066D+01 /)\r\nREAL (dp), PARAMETER :: q1(0:8) = (/ 2.57433624296484624D+10, &\r\n 5.93816564867959016D+09, 9.00633037326123344D+08, 8.04253663428328989D+07, &\r\n 5.60971175954192006D+06, 2.24743120289913752D+05, 7.57457890934153756D+03, &\r\n -2.37383578137377262D+01, 1.0_dp /)\r\n\r\nREAL (dp), PARAMETER :: p2(0:8) = (/ -6.88197293216348954D+06, &\r\n 7.48218916305315972D+06, -2.07584504810211014D+06, 3.55302557096214295D+05, &\r\n -4.06706449551854889D+04, 3.19804864027146911D+03, -1.69820937033722853D+02, &\r\n 5.61485842394289048D+00, -8.93888705926154944D-02 /)\r\nREAL (dp), PARAMETER :: q2(0:8) = (/ -1.29725624934891554D+09, &\r\n -9.48715407579907817D+08, -1.05496193474005203D+08, 4.67774488211993048D+06, &\r\n 3.12936040573813534D+06, 4.59581803839305070D+05, 3.88176109610396834D+04, &\r\n 1.92561544834491423D+03, 5.12578125000000000D+01 /)\r\n\r\nREAL (dp), PARAMETER :: p3(0:9) = (/ 1.66156480515774676D-11, &\r\n -4.68068827660654529D-09, 5.83519727319147047D-07, -4.17644012643145602D-05, &\r\n 1.85468422843597959D-03, -5.11288800220490241D-02, 8.10450231751100353D-01, &\r\n -5.69951948768478923D+00, 0.0_dp, 0.0_dp /)\r\nREAL (dp), PARAMETER :: q3(0:9) = (/ -6.99562633519191655D-10, &\r\n -1.77757961895149257D-08, -9.82231825734078036D-07, -2.84927282759096488D-05, &\r\n -5.81727909388048094D-04, -1.15848749169766586D-02, -1.28149124051978196D-01, &\r\n -1.11913057349097709D+00, -7.67928761604628813D-01, 1.0_dp /)\r\n\r\nREAL (dp), PARAMETER :: p4(0:8) = (/ 1.03144877188859712D-15, &\r\n -5.12584613964688241D-13, 1.12948794194873548D-10, -1.44234665373130952D-08, &\r\n 1.16824676984458098D-06, -6.14975167990314806D-05, 2.05594677988830328D-03, &\r\n -3.99339429394668869D-02, 3.45234976736178457D-01 /)\r\nREAL (dp), PARAMETER :: q4(0:8) = (/ 5.93959417288419050D-11, &\r\n -6.04755359079991806D-09, 3.64680208668388563D-07, -1.29456905568011812D-05, &\r\n 3.20189498470229250D-04, -5.07801557099994077D-03, 5.49628907881587266D-02, &\r\n -3.24517611155972419D-01, 1.0_dp /)\r\n\r\nREAL (dp) :: alfa, ap, aq, b0, b1, b2, f, h, t, v\r\nINTEGER :: ix, j\r\n\r\nv = x\r\nf = 1.0_dp\r\nIF (x /= 0 .AND. x < hf) THEN\r\n ix = x - delta\r\n IF (ABS(ix-x) <= delta) THEN\r\n IF (MOD(-ix,2) == 0) THEN\r\n h = 0.0_dp\r\n GO TO 70\r\n ELSE\r\n v = 1.0_dp - x\r\n f = 2 * (-z1) ** ((1-ix)/2) * dgamma(v) / pi2 ** v\r\n END IF\r\n ELSE\r\n v = 1.0_dp - x\r\n f = 2 * SIN(pih*x) * dgamma(v) / pi2 ** v\r\n END IF\r\nEND IF\r\n\r\nIF (x == 0) THEN\r\n h = -3 * hf\r\nELSE IF (x == 1) THEN\r\n fn_val = 0.0_dp\r\n WRITE(*, *) 'Riemanns ZETA(X) HAS POLE AT X = 1'\r\n RETURN\r\nELSE IF (v <= 5) THEN\r\n ap = p1(8)\r\n aq = q1(8)\r\n DO j = 7, 0, -1\r\n ap = p1(j) + v * ap\r\n aq = q1(j) + v * aq\r\n END DO\r\n h = ap / (aq*(v-1)) - 1\r\nELSE IF (v <= 11) THEN\r\n t = th * (v-8)\r\n alfa = t + t\r\n b1 = 0\r\n b2 = 0\r\n DO j = 8, 0, -1\r\n b0 = p2(j) + alfa * b1 - b2\r\n b2 = b1\r\n b1 = b0\r\n END DO\r\n h = b0 - t * b2\r\n b1 = 0\r\n b2 = 0\r\n DO j = 8, 0, -1\r\n b0 = q2(j) + alfa * b1 - b2\r\n b2 = b1\r\n b1 = b0\r\n END DO\r\n h = h / (b0 - t*b2)\r\nELSE IF (v <= 25) THEN\r\n t = 1 / v\r\n ap = p3(7)\r\n DO j = 6, 0, -1\r\n ap = p3(j) + t * ap\r\n END DO\r\n aq = q3(9)\r\n DO j = 8, 0, -1\r\n aq = q3(j) + t * aq\r\n END DO\r\n h = hf ** (v - t*ap/aq)\r\nELSE IF (v <= 55) THEN\r\n t = 1 / v\r\n ap = p4(8)\r\n aq = q4(8)\r\n DO j = 7, 0, -1\r\n ap = p4(j) + t * ap\r\n aq = q4(j) + t * aq\r\n END DO\r\n h = hf ** (v-t*ap/aq)\r\nELSE IF (v <= 90) THEN\r\n h = hf ** v + th ** v\r\nELSE\r\n h = hf ** v\r\nEND IF\r\nIF (x < 1) h = f * (1 + h)\r\n\r\n70 IF (x > 1.0_dp) THEN\r\n fn_val = 1.0_dp + h\r\nELSE\r\n fn_val = h\r\nEND IF\r\n\r\nRETURN\r\nEND FUNCTION r_zeta\r\n\r\n\r\n\r\n! $Log: gamma64.F,v $\r\n! Revision 1.1.1.1 1996/04/01 15:01:54 mclareni\r\n! Mathlib gen\r\n\r\nFUNCTION dgamma(x) RESULT(fn_val)\r\n\r\nREAL (dp), INTENT(IN) :: x\r\nREAL (dp) :: fn_val\r\n\r\nREAL (dp), PARAMETER :: c(0:15) = (/ 3.65738772508338244_dp, &\r\n 1.95754345666126827_dp, 0.33829711382616039_dp, 0.04208951276557549_dp, &\r\n 0.00428765048212909_dp, 0.00036521216929462_dp, 0.00002740064222642_dp, &\r\n 0.00000181240233365_dp, 0.00000010965775866_dp, 0.00000000598718405_dp, &\r\n 0.00000000030769081_dp, 0.00000000001431793_dp, 0.00000000000065109_dp, &\r\n 0.00000000000002596_dp, 0.00000000000000111_dp, 0.00000000000000004_dp /)\r\nREAL (dp) :: alfa, b0, b1, b2, f, h, u\r\nINTEGER :: i\r\n\r\nu = x\r\nIF (u <= 0) THEN\r\n WRITE(*, '(a, g13.5, a)') ' Argument value: ', u, ' <= 0 for routine DGAMMA'\r\n h = 0\r\n RETURN\r\nEND IF\r\n\r\nf = 1\r\nIF (u < 3) THEN\r\n DO i = 1, INT(4-u)\r\n f = f / u\r\n u = u + 1\r\n END DO\r\nELSE\r\n DO i = 1, INT(u-3)\r\n u = u - 1\r\n f = f * u\r\n END DO\r\nEND IF\r\nh = u + u - 7\r\nalfa = h + h\r\nb1 = 0\r\nb2 = 0\r\nDO i = 15, 0, -1\r\n b0 = c(i) + alfa * b1 - b2\r\n b2 = b1\r\n b1 = b0\r\nEND DO\r\n\r\nfn_val = f * (b0 - h*b2)\r\nRETURN\r\nEND FUNCTION dgamma\r\n\r\nEND MODULE Riemann_zeta\r\n\r\n\r\n\r\nPROGRAM Test_Riemann_zeta\r\nUSE Riemann_zeta\r\nIMPLICIT NONE\r\n\r\n! Output the LHS of Table 23.3 (page 811) of Abramowitz & Stegun\r\n\r\nINTEGER :: n\r\nREAL (dp) :: zeta\r\nCHARACTER (LEN=21) :: text\r\n\r\nDO n = 2, 42\r\n zeta = r_zeta( DBLE(n) )\r\n WRITE(text, '(f18.16)') zeta\r\n text = text(:7) // ' ' // text(8:12) // ' ' // text(13:17) // ' ' // text(18:18)\r\n WRITE(*, '(i3, \" \", a)') n, text\r\nEND DO\r\n\r\nSTOP\r\nEND PROGRAM Test_Riemann_zeta\r\n", "meta": {"hexsha": "ea0e70fc7ec96ceff611d394d291c6aaa8aa4ef9", "size": 6509, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/r_zeta.f90", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/amil/r_zeta.f90", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/amil/r_zeta.f90", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 27.4641350211, "max_line_length": 83, "alphanum_fraction": 0.5916423414, "num_tokens": 3028, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.939913343093499, "lm_q2_score": 0.6959583250334526, "lm_q1q2_score": 0.6541405159359445}} {"text": "module forced_interaction\n\n use core_lib, only : dp, random\n\n implicit none\n save\n\n private\n public :: forced_interaction_wr99\n public :: forced_interaction_baes16\n public :: baes16_xi\n public :: WR99, BAES16\n\n ! The optical depth at which we transition to approximating (1 - exp(-tau))\n ! by simply tau\n real(dp), parameter :: TAU_THRES = 1.e-7_dp\n real(dp) :: baes16_xi = 0.5_dp\n\n integer, parameter :: WR99=1, BAES16=2\n\ncontains\n\n subroutine forced_interaction_wr99(tau_escape, tau, weight)\n\n ! Simple forced first interaction from Wood & Reynolds, 1999, The\n ! Astrophysical Journal, 525, 799:\n !\n ! http://dx.doi.org/10.1086/307939\n !\n ! This changes the probability density function for tau from exp(-tau)\n ! defined between 0 and infinity to being a truncated decaying exponential\n ! going from 0 to tau_escape. The PDF is thus:\n !\n !\n ! PDF = exp(-tau) / (1 - exp(-tau_escape))\n !\n ! and the CDF is\n !\n ! CDF = (1 - exp(-tau)) / (1 - exp(-tau_escape))\n\n implicit none\n\n real(dp),intent(in) :: tau_escape\n real(dp),intent(out) :: tau, weight\n real(dp) :: xi, one_minus_exp\n\n call random(xi)\n\n if(tau_escape > TAU_THRES) then\n one_minus_exp = (1._dp - exp(-tau_escape))\n else\n one_minus_exp = tau_escape\n end if\n\n tau = -log(1._dp - xi * one_minus_exp)\n weight = one_minus_exp\n\n end subroutine forced_interaction_wr99\n\n subroutine forced_interaction_baes16(tau_escape, tau, weight)\n\n ! Forced first interaction with composite biasing from Baes et al. 2019,\n ! Astronomy and Astrophysics, 590, A55:\n !\n ! http://dx.doi.org/10.1086/307939\n !\n ! This changes the probability density function for tau from exp(-tau)\n ! defined between 0 and infinity to being a composite of a truncated\n ! decaying exponential and a constant. The PDF is thus:\n !\n ! PDF = (1 - xi) * exp(-tau) / (1 - exp(-tau_escape)) + xi / tau_escape\n !\n ! where eta is in the range [0:1], and the CDF is\n !\n ! CDF = (1 - xi) * (1 - exp(-tau)) / (1 - exp(-tau_escape)) + xi * tau / tau_escape\n !\n ! Note that the xi parameter here is different from the xi used to sample\n ! random numbers. For simplicity, we define:\n !\n ! alpha = (1 - xi) / (1 - exp(-tau_escape))\n ! beta = xi / tau_escape\n !\n ! so that the CDF becomes:\n !\n ! CDF = alpha * (1 - exp(-tau)) + beta * tau\n !\n ! Unfortunately, we cannot solve CDF = random number analytically for tau,\n ! so instead we solve this by searching the CDF by bisection.\n\n implicit none\n\n real(dp),intent(in) :: tau_escape\n real(dp),intent(out) :: tau, weight\n real(dp) :: alpha, beta, tau_min, tau_max, xi, xi_test, one_minus_exp\n integer :: i\n\n if(tau_escape > TAU_THRES) then\n one_minus_exp = 1._dp - exp(-tau_escape)\n else\n one_minus_exp = tau_escape\n end if\n\n ! Pre-define alpha and beta for convenience and performance\n alpha = (1._dp - baes16_xi) / one_minus_exp\n beta = baes16_xi / tau_escape\n\n ! Search tau by bisection - we know in advance it will be in the range\n ! 0 to tau_escape, so we use this as initial limits\n tau_min = 0._dp\n tau_max = tau_escape\n\n call random(xi)\n\n ! 50 iterations is enough to get a result to machine precision\n do i=1,60\n tau = 0.5_dp * (tau_min + tau_max)\n if (tau > TAU_THRES) then\n xi_test = alpha * (1._dp - exp(-tau)) + beta * tau\n else\n xi_test = alpha * tau + beta * tau\n end if\n if (xi_test > xi) then\n tau_max = tau\n else\n tau_min = tau\n end if\n end do\n\n tau = 0.5_dp * (tau_min + tau_max)\n\n weight = 1._dp / (alpha + beta * exp(tau))\n\n end subroutine forced_interaction_baes16\n\nend module forced_interaction\n", "meta": {"hexsha": "3bb6764e5327bc310cc7a68c7f2d925e61eb7e68", "size": 3801, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/main/forced_interaction.f90", "max_stars_repo_name": "christopherlovell/hyperion", "max_stars_repo_head_hexsha": "f65c253abf0bdf174a9302666bc2fec57f7ae7da", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 37, "max_stars_repo_stars_event_min_datetime": "2015-01-29T20:58:04.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-10T23:36:39.000Z", "max_issues_repo_path": "src/main/forced_interaction.f90", "max_issues_repo_name": "christopherlovell/hyperion", "max_issues_repo_head_hexsha": "f65c253abf0bdf174a9302666bc2fec57f7ae7da", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 83, "max_issues_repo_issues_event_min_datetime": "2015-01-07T11:04:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-16T16:26:33.000Z", "max_forks_repo_path": "src/main/forced_interaction.f90", "max_forks_repo_name": "christopherlovell/hyperion", "max_forks_repo_head_hexsha": "f65c253abf0bdf174a9302666bc2fec57f7ae7da", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 17, "max_forks_repo_forks_event_min_datetime": "2015-04-21T13:17:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-06T02:42:20.000Z", "avg_line_length": 27.9485294118, "max_line_length": 87, "alphanum_fraction": 0.6329913181, "num_tokens": 1120, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045966995028, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.654010115501783}} {"text": "module mod_cylindricalduct\n use mod_kinds, only: rk, ik\n use mod_constants, only: HALF, ZERO, ONE, TWO\n use type_point, only: point_t\n use type_function, only: function_t\n use mod_function, only: create_function\n use mod_gridspace, only: linspace\n use mod_rootfinding, only: bisect\n implicit none\n\n\n\ncontains\n\n\n\n !> Compute eigenvalues of cylindrical duct modes for a given azimuthal\n !! mode order 'm'.\n !!\n !! @author Nathan A. Wukie\n !! @date 4/14/2016\n !!\n !!\n !---------------------------------------------------------------------------\n function compute_cylindricalduct_eigenvalues(m,nevalues) result(evalues)\n integer(ik), intent(in) :: m\n integer(ik), intent(in) :: nevalues\n\n real(rk), dimension(nevalues) :: evalues\n real(rk), allocatable :: xvals(:)\n real(rk) :: fnew, fold, xnew, xold\n type(point_t) :: x\n integer(ik) :: ieig, ix\n class(function_t), allocatable :: efcn\n\n\n !\n ! Create eigenfunction and set 'm'\n !\n call create_function(efcn,'cylindricalduct_eigenfunction')\n call efcn%set_option('m',real(m,rk))\n\n !\n ! Initialize values\n !\n evalues = ZERO\n call x%set(ZERO,ZERO,ZERO)\n\n\n !\n ! Numerically compute each eigen value\n !\n do ieig = 1,nevalues\n\n !\n ! Eigenvalue for (0,1) is ZERO. Bisection\n ! wouldn't find this because iteration starts \n ! after 0.\n !\n if ( m == 0 ) then\n if ( ieig == 1 ) then\n evalues(ieig) = ZERO\n exit\n end if\n end if\n\n\n \n !\n ! Get discretization values to try\n !\n if (ieig == 1) then\n ! Start from the beginning of the function\n xvals = linspace(0.1_rk,100._rk,1000)\n else\n ! Start after the previous zero\n xvals = linspace(evalues(ieig-1)+0.1,100._rk,10000)\n end if\n\n\n ! \n ! Iterate through xvals and look for sign change\n !\n do ix = 1,size(xvals)\n x%c1_ = xvals(ix)\n fnew = efcn%compute(ZERO,x)\n xnew = xvals(ix)\n\n if (ix > 1) then\n ! Test for sign change\n if ( int(sign(ONE,fnew)) /= int(sign(ONE,fold)) ) then\n ! Sign changed, so start bisection to find root.\n evalues(ieig) = bisect(efcn, xold, xnew)\n exit\n else\n fold = fnew\n xold = xnew\n end if\n else\n fold = fnew\n xold = xnew\n end if\n\n end do\n\n\n\n\n end do\n\n\n\n\n\n end function compute_cylindricalduct_eigenvalues\n !***************************************************************************\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n !> Return the value of a specified cylindrical duct mode.\n !!\n !! For a specified azimuthal mode(m), and the eigenvalue of an associated \n !! radial mode(alpha), compute the value of the mode at radial location(r),\n !! bounded by the outer wall(rmax)\n !!\n !! The mode values are normalized by N such that:\n !!\n !! \\f$ \\int_0^1 N_{m \\mu}^2 J(\\alpha_{m \\mu})^2 r dr = 1 \\f$\n !!\n !! This is outlined in the document:\n !! \"Fundamentals of Duct Acoustics\" by Sjoerd W. Rienstra\n !!\n !!\n !! @author Nathan A. Wukie\n !! @date 4/14/2016\n !!\n !----------------------------------------------------------------------------\n impure elemental function compute_cylindricalduct_mode(m,alpha,r,rmax) result(val)\n integer(ik), intent(in) :: m\n real(rk), intent(in) :: alpha\n real(rk), intent(in) :: r\n real(rk), intent(in) :: rmax\n\n real(rk) :: val, normalization\n\n\n ! Compute value of mode at location 'r'\n val = bessel_jn(m,alpha*r/rmax)\n\n\n ! Compute normalization\n if ( m == 0 ) then\n normalization = sqrt(TWO)\n else\n normalization = sqrt(TWO)/(bessel_jn(m,alpha)*sqrt(ONE - (real(m,rk)**TWO)/alpha**TWO))\n end if\n\n\n ! Apply normalization \n val = val*normalization\n\n end function compute_cylindricalduct_mode\n !*****************************************************************************\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nend module mod_cylindricalduct\n", "meta": {"hexsha": "d6514f04a4fe954a7699cdbc5d98ab8980778a6d", "size": 4766, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/equations/Acoustics/DuctModes/mod_cylindricalduct.f90", "max_stars_repo_name": "wanglican/ChiDG", "max_stars_repo_head_hexsha": "d3177b87cc2f611e66e26bb51616f9385168f338", "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/equations/Acoustics/DuctModes/mod_cylindricalduct.f90", "max_issues_repo_name": "haohb/ChiDG", "max_issues_repo_head_hexsha": "d3177b87cc2f611e66e26bb51616f9385168f338", "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/equations/Acoustics/DuctModes/mod_cylindricalduct.f90", "max_forks_repo_name": "haohb/ChiDG", "max_forks_repo_head_hexsha": "d3177b87cc2f611e66e26bb51616f9385168f338", "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": 22.6952380952, "max_line_length": 99, "alphanum_fraction": 0.4588753672, "num_tokens": 1157, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045907347107, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6540101111047878}} {"text": "!! This module makes a bimodal distribution using two maxwellians \n!! one maxwellian on the left and another on the right and some sort of linear? switching in between... \n!! IN 3D in velocity space and 1D in physical space...\n\n!DIMENSIONLESS SEE NOTES FOR THE REDUCTION FORMULAS\nmodule DGV_distributions_mod\nuse nrtype ! contains kind parameters (DP), (DP), (I4B) etc. \n\nimplicit none\n interface maxwelveldist\n module procedure maxwelveldist, maxwelveldist_T_vector, maxwelveldist_u_vectors, &\n maxwelveldist_T_vector_u_vectors\n end interface\n\n interface ESBGK\n module procedure ESBGK_f0\n end interface\n \n!!!!!!!!!!!!! parameters and global variables \nreal (DP), parameter, private :: pi25DT = 3.141592653589793238462643d0\n!!!!!!!!!!\n\n\ncontains\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! maxwelveldist (T,u_0,n,u) result (y)\n! \n! This function evauates the 3D velocity dimensionless maxwellian equilibrium distribution with given temperature and average velocity\n! Temperature and average velocity can be arrays (corresponding to different points in x variable\n!\n! This function evaluates \n! f_{M}(t,x,u)=(\\pi T(t,x))^{-1/2} \\exp(-\\frac{(u-\\bar{u})^2}{2RT}) \n!\n! This is a reloadable function\n!!!!!!!!!!!!!!!!!!!!!!!\n!\n! this is the copy when T is vector and u is scalar\nfunction maxwelveldist_T_vector_u_vectors (T,u_0,v_0,w_0,n,u,v,w) result (y)\n real (DP), dimension (:), intent (in) :: T ! temperature parameter (may depend on x)\n real (DP), dimension (:), intent (in) :: n ! density parameter (may depend on x)\n real (DP), dimension (:), intent (in) :: u_0,v_0,w_0 ! average velocity (may depend on x)\n !!! T,n,u_0 must be the same size !!! \n real (DP), dimension (:), intent (in) :: u,v,w ! value of the velocity variable\n real (DP), dimension (size(T),size(u)) :: y ! value of the dencity for this values of u and T\n!!!\n real (DP), dimension (size(T)) :: beta ! local variable to keep temporary results\n integer (I4B) :: i ! local counter\n!!! \nbeta=sqrt(pi25DT*T)*(pi25DT*T)\ndo i=1,size(u)\ny(:,i) = n*exp(-((u(i)-u_0)*(u(i)-u_0)+(v(i)-v_0)*(v(i)-v_0)+&\n (w(i)-w_0)*(w(i)-w_0))/max(T,0.0000001_DP))/beta\nend do \nend function maxwelveldist_T_vector_u_vectors\n\n! this is the copy when T is vector and u is scalar\nfunction maxwelveldist_T_vector (T,u_0,v_0,w_0,n,u,v,w) result (y)\n real (DP), dimension (:), intent (in) :: T ! temperature parameter (may depend on x)\n real (DP), dimension (:), intent (in) :: n ! density parameter (may depend on x)\n real (DP), dimension (:), intent (in) :: u_0, v_0,w_0 ! average velocity (may depend on x)\n !!! T,n,u_0 must be the same size !!! \n real (DP), intent (in) :: u,v,w ! value of the velocity variable \n real (DP), dimension (size(T)) :: y ! value of the dencity for this values of u and T \n!!!\n real (DP), dimension (size(T)) :: beta ! local variable to keep temporary results \nbeta=sqrt(pi25DT*T)*(pi25DT*T)\ny = n*exp(-((u-u_0)*(u-u_0)+(v-v_0)*(v-v_0)+&\n (w-w_0)*(w-w_0))/max(T,0.0000001_DP))/beta\nend function maxwelveldist_T_vector\n\n! this is the copy when T is scalar and u is vector\nfunction maxwelveldist_u_vectors (T,u_0,v_0,w_0,n,u,v,w) result (y)\n real (DP), intent (in) :: T ! temperature parameter (scalar)\n real (DP), intent (in) :: u_0,v_0,w_0 ! average velocity (scalar)\n real (DP), intent (in) :: n ! density parameter (scalar)\n real (DP), dimension (:), intent (in) :: u,v,w ! values of the velocity variable \n real (DP), dimension (size(u)) :: y ! value of the dencity for this values of u and T \n!!!\n real (DP) :: beta ! local variable to keep temporary results \nbeta=sqrt(pi25DT*T)*(pi25DT*T)\ny = n*exp(-((u-u_0)*(u-u_0)+(v-v_0)*(v-v_0)+&\n (w-w_0)*(w-w_0))/max(T,0.0000001_DP))/beta\nend function maxwelveldist_u_vectors\n\n! this is the copy when both T and u are scalars\nfunction maxwelveldist (T,u_0,v_0,w_0,n,u,v,w) result (y)\n real (DP), intent (in) :: T ! temperature parameter (may depend on x)\n real (DP), intent (in) :: u_0,v_0,w_0 ! average velocity (scalar)\n real (DP), intent (in) :: n ! density parameter (scalar)\n real (DP), intent (in) :: u,v,w ! value of the velocity variable \n real (DP) :: y ! value of the dencity for this values of u and T \n!!!\n real (DP) :: beta ! local variable to keep temporary results \nbeta=sqrt(pi25DT*T)*(pi25DT*T)\ny = n*exp(-((u-u_0)*(u-u_0)+(v-v_0)*(v-v_0)+&\n (w-w_0)*(w-w_0))/max(T,0.0000001_DP))/beta\nend function maxwelveldist \n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! ESBGK_f0\n! \n! This function evauates the 3D ES-BGK equilibrium distribution with given temperature and average velocity.\n! Note that the parameters are dependent on time and velocity but not in the spacial variable x\n!\n! This function evaluates \n! f_0(t,u)=\\frac{n(t)}{\\sqrt{(\\pi^3 det(\\mathbb{T})}} \\exp(-c'\\mathbb{T}c) \n!\n!!!!!!!!!!!!!!!!!!!!!!!\n\nfunction ESBGK_f0 (TensorInv,Determinant,n,u_0,v_0,w_0,nodes_u,nodes_v,nodes_w) result (f0)\n! Evaluate f0 for ESBGK\nreal (DP), dimension(3,3), intent (in) :: TensorInv ! The inverse of the tensor matrix\nreal (DP), intent (in) :: u_0, v_0, w_0 ! These are the bulk velocities\nreal (DP), intent (in) :: Determinant ! This is the Determinant of the Tensor matrix\nreal (DP), intent (in) :: n ! this is the number density\nreal (DP), dimension(:), intent (in) :: nodes_u,nodes_v,nodes_w ! These are the velocity nodes\ninteger (I4B) :: Unodes ! the number of nodes in velocity space\nreal (DP), dimension(3) :: Left, c ! c-v vector\nreal (DP), parameter :: PI25DT = 3.141592653589793238462643d0\ninteger :: loc_alloc_stat\nreal (DP), dimension (:), allocatable :: Prod ! This is the component that goes into the argument of the exponent\nreal (DP), dimension (1:size(nodes_u,1)) :: f0 ! result -- the ES-BGK distribution function\n!real (DP), dimension(1:size(nodes_u,1)) :: nodes_cu, nodes_cv, nodes_cw\ninteger (I4B) :: i,j,k ! these are local counters\n\nUnodes = size(nodes_U) ! Get the number of elements of each of the nodes\n\nallocate (Prod(1:size(nodes_u,1)), stat=loc_alloc_stat)\nif (loc_alloc_stat >0) then \n print *, \"ESBGK_f0: Allocation error for variables (Prod)\"\n stop\nend if\n\n! from here, the component in the exponent's argument is computed\n\ndo i=1,Unodes\n ! c = \\vec{u} - \\vec{bar{u}}\n c(1) = nodes_u(i) - u_0\n c(2) = nodes_v(i) - v_0\n c(3) = nodes_w(i) - w_0\n\n ! used as part of the left operation (i.e. c'*TensorInv)\n Left(1) = c(1)*TensorInv(1,1) + c(2)*TensorInv(2,1) + c(3)*TensorInv(3,1)\n Left(2) = c(1)*TensorInv(1,2) + c(2)*TensorInv(2,2) + c(3)*TensorInv(3,2)\n Left(3) = c(1)*TensorInv(1,3) + c(2)*TensorInv(2,3) + c(3)*TensorInv(3,3)\n\n Prod(i) = Left(1)*c(1) + Left(2)*c(2) + Left(3)*c(3)! final computation of c'*TensorInv*c\nend do\n\nf0 = n/sqrt((PI25DT)**3*Determinant) * exp(-Prod)\n\ndeallocate (Prod)\n\nend function ESBGK_f0\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n! Shakhov_f0\n! \n! This function evauates the dimensionless 3D Shakhov equilibrium distribution function \n! with given temperature and average velocity and the \n! give Prandtl number. \n!\n!Note that the parameters are dependent on time and velocity but not in the spacial variable x\n!\n! This function evaluates \n! f_0(t,u)=f_{M}(t,u)(1+(4/5)(1-Pr)S_{a}c^{a}(c_{a}c^{a}-5/2)) where c_a=(u_a-\\bar{u}_a)/\\sqrt{T}\n! S_a=q_{a}/(nT^{3/2}), q_{a} = \\int f (u_{a}-\\bar(u)_{a})|u-\\bar{u}|^2 du\n!\n!!!!!!!!!!!!!!!!!!!!!!!\n\nfunction Shakhov_f0 (alpha,n,u_0,v_0,w_0,T,S_u,S_v,S_w,nodes_u,nodes_v,nodes_w) result (f0)\n! Evaluate f0 for Shakhov model\nreal (DP), intent (in) :: alpha ! the Prandtl number \nreal (DP), intent (in) :: T ! This is the temperature of the local maxwellian \nreal (DP), intent (in) :: n ! this is the number density \nreal (DP), intent (in) :: u_0, v_0, w_0 ! These are the bulk velocities of the local maxwellian\nreal (DP), dimension(:), intent (in) :: S_u,S_v,S_w ! These are the components of the vector S in the shakov model\n\nreal (DP), dimension(:), intent (in) :: nodes_u,nodes_v,nodes_w ! These are the velocity nodes\nreal (DP), dimension (1:size(nodes_u,1)) :: f0 ! the Shakhov distribution function -- the result\n!\n!\nreal (DP), parameter :: PI25DT = 3.141592653589793238462643d0\nreal (DP), dimension (:), allocatable :: ShCorr,c_u, c_v, c_w! This are useful arrays, \ninteger (I4B) :: i,j,k,loc_alloc_stat ! these are local counters\n\n\nallocate (ShCorr(1:size(nodes_u,1)),c_u(1:size(nodes_u,1)),c_v(1:size(nodes_u,1)),&\n c_w(1:size(nodes_u,1)), stat=loc_alloc_stat)\nif (loc_alloc_stat >0) then \n print *, \"Shakhov_f0: Allocation error for variables (ShCorr,c_u,c_v,c_w)\"\n stop\nend if\n\n! first, we compute the components of vector c:\nc_u = (nodes_u-u_0)/sqrt(T)\nc_v = (nodes_v-v_0)/sqrt(T)\nc_w = (nodes_w-w_0)/sqrt(T)\n! Next we compute the Shakhov correction term\nShCorr = (S_u*c_u+S_v*c_v+S_w*c_w)*((c_u*c_u+c_v*c_v+c_w*c_w)-5.0_DP/2.0_DP)\nShCorr = (1+4.0_DP/5.0_DP*((-1)*alpha)/(1-alpha)*ShCorr)\n!!!!!!!!\nf0 = maxwelveldist(T,u_0,v_0,w_0,n,nodes_u,nodes_v,nodes_w)*ShCorr\n\ndeallocate (ShCorr,c_u,c_v,c_w)\n\nend function Shakhov_f0\n\nend module DGV_distributions_mod", "meta": {"hexsha": "8f5b3b24a40236e06ebfaab361f8fcc7a58c5643", "size": 9280, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "DGV0D3V/DGV_distributions_mod.f90", "max_stars_repo_name": "alexmalekseenko/DGV0D3V", "max_stars_repo_head_hexsha": "2136be5a4af6c2c83e7cf543460845447c510359", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "DGV0D3V/DGV_distributions_mod.f90", "max_issues_repo_name": "alexmalekseenko/DGV0D3V", "max_issues_repo_head_hexsha": "2136be5a4af6c2c83e7cf543460845447c510359", "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": "DGV0D3V/DGV_distributions_mod.f90", "max_forks_repo_name": "alexmalekseenko/DGV0D3V", "max_forks_repo_head_hexsha": "2136be5a4af6c2c83e7cf543460845447c510359", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.981042654, "max_line_length": 134, "alphanum_fraction": 0.6490301724, "num_tokens": 3037, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.7371581568543044, "lm_q1q2_score": 0.6540101030571744}} {"text": " subroutine comppro(v,n1v,nrow,nv,x) \nc---------------------------------------------------------------\nc projects vector x onto subspace perpendicular to \nc orthonormal basis vectors stored in array v. (i.e. its orthogonal\nc complement). \nc \nc arguments- \nc v - array of containing orthonormal basis vectors defining the \nc subspace whose complement x is to be projected onto. \nc these vectors are assumed to be stored in the columns of v.\nc n1v-first dimension of v in calling program. \nc nrow-number of elements in the rows of v and x.\nc nv-number of vectors in v. (i.e. number of columns in v)\nc x-vector to be projected. it is overwritten on return by\nc the requested projection.\nc \nc author gary l. pavlis\nc geophysics program ak-50\nc university of washington\nc seattle, wa 98195 \nc \nc written january 1983 \nc---------------------------------------------------------------------\n integer n1v,nrow,nv \n real v(n1v,nv),x(nrow)\n integer j \n real scale\n do 100 j=1,nv \n scale = sdot(nrow,v(1,j),1,x,1)\n call saxpy(nrow,-scale,v(1,j),1,x,1) \n 100 continue\n return\n end \n\nc $Id$ \n", "meta": {"hexsha": "b5eae5d1f904022ea484ce4f99687226b4fc8503", "size": 1224, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "lib/location/libglp/comppro.f", "max_stars_repo_name": "jreyes1108/antelope_contrib", "max_stars_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_stars_repo_licenses": ["BSD-2-Clause", "MIT"], "max_stars_count": 30, "max_stars_repo_stars_event_min_datetime": "2015-02-20T21:44:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-27T02:53:14.000Z", "max_issues_repo_path": "lib/location/libglp/comppro.f", "max_issues_repo_name": "jreyes1108/antelope_contrib", "max_issues_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_issues_repo_licenses": ["BSD-2-Clause", "MIT"], "max_issues_count": 14, "max_issues_repo_issues_event_min_datetime": "2015-07-07T19:17:24.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-19T19:18:53.000Z", "max_forks_repo_path": "lib/location/libglp/comppro.f", "max_forks_repo_name": "jreyes1108/antelope_contrib", "max_forks_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_forks_repo_licenses": ["BSD-2-Clause", "MIT"], "max_forks_count": 46, "max_forks_repo_forks_event_min_datetime": "2015-02-06T16:22:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T11:46:37.000Z", "avg_line_length": 34.0, "max_line_length": 70, "alphanum_fraction": 0.5710784314, "num_tokens": 324, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.7371581568543043, "lm_q1q2_score": 0.6540101030571743}} {"text": "module elements\n\nimplicit none\n\ndouble precision, parameter :: pi = 3.1415926535897931d0\n\ncontains\n\npure function fromrv(r, v, mu) result(ele)\n double precision, dimension(:), intent(in) :: r\n double precision, dimension(:), intent(in) :: v\n double precision, intent(in) :: mu\n double precision, dimension(6) :: ele\n\n double precision :: r_mag, v_mag, h_mag, n_mag, xi\n double precision, dimension(3) :: h, n, k, e\n\n r_mag = norm2(r)\n v_mag = norm2(v)\n h = cross(r,v)\n h_mag = norm2(h)\n k = [0d0, 0d0, 1d0]\n n = cross(k, h)\n n_mag = norm2(n)\n xi = v_mag**2/2 - mu/r_mag\n e = ((v_mag**2 - mu/r_mag)*r - v*dot_product(r,v))/mu\n ele(2) = norm2(e)\n if (ele(2) /= 1.0) then\n ele(1) = -mu/(2*xi)\n else\n ele(1) = h_mag**2/mu\n end if\n ele(3) = acos(h(3)/h_mag)\n ele(4) = acos(n(1)/n_mag)\n ele(5) = acos(dot_product(n,e)/(ele(2)*n_mag))\n ele(6) = acos(dot_product(e,r)/(ele(2)*r_mag))\n if (n(2) < 0) then\n ele(4) = 2*pi - ele(4)\n end if\n if (e(3) < 0) then\n ele(5) = 2*pi - ele(5)\n end if\n if (dot_product(r,v) < 0) then\n ele(6) = 2*pi - ele(6)\n end if\nend function fromrv\n\npure function cross(a, b)\n double precision, dimension(:), intent(in) :: a\n double precision, dimension(:), intent(in) :: b\n double precision, dimension(3) :: cross\n\n cross(1) = a(2) * b(3) - a(3) * b(2)\n cross(2) = a(3) * b(1) - a(1) * b(3)\n cross(3) = a(1) * b(2) - a(2) * b(1)\nend function cross\n\nsubroutine benchmark_elements(times)\n integer, intent(in) :: times\n\n double precision, dimension(3) :: r\n double precision, dimension(3) :: v\n double precision, dimension(6) :: el\n double precision, parameter :: mu = 3.986004418d5\n\n double precision :: current, rate\n integer(kind=8) :: start, finish, irate\n double precision :: total, best, worst\n integer :: i\n\n r = [8.59072560d+02, -4.13720368d+03, 5.29556871d+03]\n v = [7.37289205d+00, 2.08223573d+00, 4.39999794d-01]\n\n worst = -1d20\n best = 1d20\n total = 0d0\n call system_clock(count_rate=irate)\n rate = dble(irate)\n do i=1, times\n call system_clock(start)\n\n el = fromrv(r, v, mu)\n\n call system_clock(finish)\n current = (finish - start)/rate\n if (current < best .and. current > 0) then\n best = current\n end if\n if (current > worst) then\n worst = current\n end if\n total = total + current\n end do\n print *, total/times, best, worst\nend subroutine benchmark_elements\n\nend module elements\n", "meta": {"hexsha": "55136ce35d0bd54a7ea4118729799d4550c18ca2", "size": 2587, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/src/elements.f90", "max_stars_repo_name": "helgee/icatt-2016", "max_stars_repo_head_hexsha": "0fb1012b3639a6d6c53d80cd00b43b72a67b8022", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2016-05-07T19:09:15.000Z", "max_stars_repo_stars_event_max_datetime": "2017-05-06T14:31:44.000Z", "max_issues_repo_path": "fortran/src/elements.f90", "max_issues_repo_name": "OpenAstrodynamics/benchmarks", "max_issues_repo_head_hexsha": "0fb1012b3639a6d6c53d80cd00b43b72a67b8022", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2017-05-05T14:36:39.000Z", "max_issues_repo_issues_event_max_datetime": "2017-05-08T09:18:55.000Z", "max_forks_repo_path": "fortran/src/elements.f90", "max_forks_repo_name": "OpenAstrodynamics/benchmarks", "max_forks_repo_head_hexsha": "0fb1012b3639a6d6c53d80cd00b43b72a67b8022", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-11-09T12:13:04.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-13T14:19:13.000Z", "avg_line_length": 26.3979591837, "max_line_length": 57, "alphanum_fraction": 0.577116351, "num_tokens": 896, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171067, "lm_q2_score": 0.7371581568543043, "lm_q1q2_score": 0.6540101030571742}} {"text": "module global_integral_mod\n\nuse fms_mod, only: mpp_pe, mpp_root_pe, &\n write_version_number\n\nuse press_and_geopot_mod, only: half_level_pressures\n\nuse transforms_mod, only: area_weighted_global_mean\n\nuse constants_mod, only: grav\n\nuse mpp_domains_mod, only: mpp_global_field\n\nimplicit none\nprivate\n\npublic :: mass_weighted_global_integral\n\nreal :: global_sum_of_wts\nlogical :: entry_to_logfile_done=.false.\ncharacter(len=128), parameter :: version = '$Id: global_integral.f90,v 13.0 2006/03/28 21:17:51 fms Exp $'\ncharacter(len=128), parameter :: tagname = '$Name: latest $'\n\ncontains\n\n!---------------------------------------------------------------------------------------------\n\nfunction mass_weighted_global_integral(field, surf_press)\n\n! This function returns the mass weighted vertical integral of field,\n! area averaged over the globe. The units of the result are:\n! (units of field)*(Kg/meters**2)\n\nreal :: mass_weighted_global_integral\nreal, intent(in), dimension(:,:,:) :: field\nreal, intent(in), dimension(:,:) :: surf_press\nreal, dimension(size(field,1), size(field,2), size(field,3) ) :: dp\nreal, dimension(size(field,1), size(field,2), size(field,3)+1) :: p_half\n\nreal, dimension(size(field,1), size(field,2)) :: vert_integral\n\ninteger :: k, num_levels\n\nif(.not.entry_to_logfile_done) then\n call write_version_number(version, tagname)\n entry_to_logfile_done=.true.\nendif\n\n\nnum_levels = size(field,3)\np_half= half_level_pressures(surf_press)\ndp = p_half(:,:,2:num_levels+1) - p_half(:,:,1:num_levels)\nvert_integral = 0.\ndo k=1,num_levels\n vert_integral = vert_integral + field(:,:,k)*dp(:,:,k)\nenddo\nmass_weighted_global_integral = area_weighted_global_mean(vert_integral)/grav\n\nreturn\nend function mass_weighted_global_integral\n!---------------------------------------------------------------------------------------------\nend module global_integral_mod\n", "meta": {"hexsha": "9e1193e74d676ca8fbf058a57259e0e3847dc651", "size": 1940, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fms_dynamical_cores/_fortran/src/atmos_spectral/model/global_integral.f90", "max_stars_repo_name": "JoyMonteiro/FMSDynamicalCore", "max_stars_repo_head_hexsha": "b46a8943de28f8b16a1d36f5607f10e928ed6667", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-05-23T13:35:20.000Z", "max_stars_repo_stars_event_max_datetime": "2018-05-23T13:35:20.000Z", "max_issues_repo_path": "fms_dynamical_cores/_fortran/src/atmos_spectral/model/global_integral.f90", "max_issues_repo_name": "JoyMonteiro/fms_dynamical_cores", "max_issues_repo_head_hexsha": "b46a8943de28f8b16a1d36f5607f10e928ed6667", "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": "fms_dynamical_cores/_fortran/src/atmos_spectral/model/global_integral.f90", "max_forks_repo_name": "JoyMonteiro/fms_dynamical_cores", "max_forks_repo_head_hexsha": "b46a8943de28f8b16a1d36f5607f10e928ed6667", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.7936507937, "max_line_length": 106, "alphanum_fraction": 0.6659793814, "num_tokens": 466, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637648915617, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6539037991833767}} {"text": "\tsubroutine tucspl (xa, ya, n, work, y2)\nC\nC Compute the second derivative of YA at each point in the array.\nC This is the initialization needed in preparation for interpolating\nC using cubic splines by the subroutine TUISPL. Input and output\nC are all double precision.\nC\nC This routine was copied with slight modifications from the SPLINE\nC subroutine in Numerical Recipes by Press, Flannery, Teukolsky and\nC Vetterling.\nC\nC N\t\ti: number of elements in each array\nC XA\t\ti: array of independent-variable values\nC YA\t\ti: array of dependent-variable values\nC WORK\t\tio: scratch array used for work space\nC Y2\t\to: second derivative of YA at each point\nC\nCH Phil Hodge, 14-Apr-1988 Subroutine copied from Numerical Recipes SPLINE.\nC\n\tinteger n\n\tdouble precision xa(n), ya(n), work(n), y2(n)\nC--\n\tinteger i\n\tdouble precision p, sig\n\nC These values (and y2(n) = 0) are for a \"natural\" spline.\n\ty2(1) = 0.\n\twork(1) = 0.\nC\nC This is the decomposition loop of the tridiagonal algorithm.\nC Y2 and WORK are used for temporary storage of the decomposed factors.\nC\n\tdo 10 i = 2, n-1\n\t sig = (xa(i) - xa(i-1)) / (xa(i+1) - xa(i-1))\n\t p = sig * y2(i-1) + 2.\n\t y2(i) = (sig - 1.) / p\n\t work(i) = (6. * ((ya(i+1) - ya(i)) / (xa(i+1) - xa(i))\n +\t\t\t- (ya(i) - ya(i-1)) / (xa(i) - xa(i-1))) /\n +\t\t\t(xa(i+1) - xa(i-1)) - sig * work(i-1)) / p\n 10\tcontinue\n\nC\t\t\t\t\t\"natural\" spline\n\ty2(n) = 0.\nC\nC This is the backsubstitution loop of the tridiagonal algorithm.\nC\n\tdo 20 i = n-1, 1, -1\n\t y2(i) = y2(i) * y2(i+1) + work(i)\n 20\tcontinue\n\n\treturn\n\tend\n", "meta": {"hexsha": "511211b899f620c7ce8f42f78c74772ccbb393f5", "size": 1567, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iraf.v2161/pkg/utilities/nttools/trebin/tucspl.f", "max_stars_repo_name": "ysBach/irafdocgen", "max_stars_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:19:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T16:48:42.000Z", "max_issues_repo_path": "iraf.v2161/pkg/utilities/nttools/trebin/tucspl.f", "max_issues_repo_name": "ysBach/irafdocgen", "max_issues_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-30T13:48:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-02T19:40:25.000Z", "max_forks_repo_path": "iraf.v2161/pkg/utilities/nttools/trebin/tucspl.f", "max_forks_repo_name": "ysBach/irafdocgen", "max_forks_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_forks_repo_licenses": ["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.5660377358, "max_line_length": 77, "alphanum_fraction": 0.6528398213, "num_tokens": 550, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637612961505, "lm_q2_score": 0.7606506472514406, "lm_q1q2_score": 0.6539037964485248}} {"text": "*DECK HTRIDI\n SUBROUTINE HTRIDI (NM, N, AR, AI, D, E, E2, TAU)\nC***BEGIN PROLOGUE HTRIDI\nC***PURPOSE Reduce a complex Hermitian matrix to a real symmetric\nC tridiagonal matrix using unitary similarity\nC transformations.\nC***LIBRARY SLATEC (EISPACK)\nC***CATEGORY D4C1B1\nC***TYPE SINGLE PRECISION (HTRIDI-S)\nC***KEYWORDS EIGENVALUES, EIGENVECTORS, EISPACK\nC***AUTHOR Smith, B. T., et al.\nC***DESCRIPTION\nC\nC This subroutine is a translation of a complex analogue of\nC the ALGOL procedure TRED1, NUM. MATH. 11, 181-195(1968)\nC by Martin, Reinsch, and Wilkinson.\nC HANDBOOK FOR AUTO. COMP., VOL.II-LINEAR ALGEBRA, 212-226(1971).\nC\nC This subroutine reduces a COMPLEX HERMITIAN matrix\nC to a real symmetric tridiagonal matrix using\nC unitary similarity transformations.\nC\nC On INPUT\nC\nC NM must be set to the row dimension of the two-dimensional\nC array parameters, AR and AI, as declared in the calling\nC program dimension statement. NM is an INTEGER variable.\nC\nC N is the order of the matrix A=(AR,AI). N is an INTEGER\nC variable. N must be less than or equal to NM.\nC\nC AR and AI contain the real and imaginary parts, respectively,\nC of the complex Hermitian input matrix. Only the lower\nC triangle of the matrix need be supplied. AR and AI are two-\nC dimensional REAL arrays, dimensioned AR(NM,N) and AI(NM,N).\nC\nC On OUTPUT\nC\nC AR and AI contain some information about the unitary trans-\nC formations used in the reduction in the strict lower triangle\nC of AR and the full lower triangle of AI. The rest of the\nC matrices are unaltered.\nC\nC D contains the diagonal elements of the real symmetric\nC tridiagonal matrix. D is a one-dimensional REAL array,\nC dimensioned D(N).\nC\nC E contains the subdiagonal elements of the real tridiagonal\nC matrix in its last N-1 positions. E(1) is set to zero.\nC E is a one-dimensional REAL array, dimensioned E(N).\nC\nC E2 contains the squares of the corresponding elements of E.\nC E2(1) is set to zero. E2 may coincide with E if the squares\nC are not needed. E2 is a one-dimensional REAL array,\nC dimensioned E2(N).\nC\nC TAU contains further information about the transformations.\nC TAU is a one-dimensional REAL array, dimensioned TAU(2,N).\nC\nC Calls PYTHAG(A,B) for sqrt(A**2 + B**2).\nC\nC Questions and comments should be directed to B. S. Garbow,\nC APPLIED MATHEMATICS DIVISION, ARGONNE NATIONAL LABORATORY\nC ------------------------------------------------------------------\nC\nC***REFERENCES B. T. Smith, J. M. Boyle, J. J. Dongarra, B. S. Garbow,\nC Y. Ikebe, V. C. Klema and C. B. Moler, Matrix Eigen-\nC system Routines - EISPACK Guide, Springer-Verlag,\nC 1976.\nC***ROUTINES CALLED PYTHAG\nC***REVISION HISTORY (YYMMDD)\nC 760101 DATE WRITTEN\nC 890831 Modified array declarations. (WRB)\nC 890831 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE HTRIDI\nC\n INTEGER I,J,K,L,N,II,NM,JP1\n REAL AR(NM,*),AI(NM,*),D(*),E(*),E2(*),TAU(2,*)\n REAL F,G,H,FI,GI,HH,SI,SCALE\n REAL PYTHAG\nC\nC***FIRST EXECUTABLE STATEMENT HTRIDI\n TAU(1,N) = 1.0E0\n TAU(2,N) = 0.0E0\nC\n DO 100 I = 1, N\n 100 D(I) = AR(I,I)\nC .......... FOR I=N STEP -1 UNTIL 1 DO -- ..........\n DO 300 II = 1, N\n I = N + 1 - II\n L = I - 1\n H = 0.0E0\n SCALE = 0.0E0\n IF (L .LT. 1) GO TO 130\nC .......... SCALE ROW (ALGOL TOL THEN NOT NEEDED) ..........\n DO 120 K = 1, L\n 120 SCALE = SCALE + ABS(AR(I,K)) + ABS(AI(I,K))\nC\n IF (SCALE .NE. 0.0E0) GO TO 140\n TAU(1,L) = 1.0E0\n TAU(2,L) = 0.0E0\n 130 E(I) = 0.0E0\n E2(I) = 0.0E0\n GO TO 290\nC\n 140 DO 150 K = 1, L\n AR(I,K) = AR(I,K) / SCALE\n AI(I,K) = AI(I,K) / SCALE\n H = H + AR(I,K) * AR(I,K) + AI(I,K) * AI(I,K)\n 150 CONTINUE\nC\n E2(I) = SCALE * SCALE * H\n G = SQRT(H)\n E(I) = SCALE * G\n F = PYTHAG(AR(I,L),AI(I,L))\nC .......... FORM NEXT DIAGONAL ELEMENT OF MATRIX T ..........\n IF (F .EQ. 0.0E0) GO TO 160\n TAU(1,L) = (AI(I,L) * TAU(2,I) - AR(I,L) * TAU(1,I)) / F\n SI = (AR(I,L) * TAU(2,I) + AI(I,L) * TAU(1,I)) / F\n H = H + F * G\n G = 1.0E0 + G / F\n AR(I,L) = G * AR(I,L)\n AI(I,L) = G * AI(I,L)\n IF (L .EQ. 1) GO TO 270\n GO TO 170\n 160 TAU(1,L) = -TAU(1,I)\n SI = TAU(2,I)\n AR(I,L) = G\n 170 F = 0.0E0\nC\n DO 240 J = 1, L\n G = 0.0E0\n GI = 0.0E0\nC .......... FORM ELEMENT OF A*U ..........\n DO 180 K = 1, J\n G = G + AR(J,K) * AR(I,K) + AI(J,K) * AI(I,K)\n GI = GI - AR(J,K) * AI(I,K) + AI(J,K) * AR(I,K)\n 180 CONTINUE\nC\n JP1 = J + 1\n IF (L .LT. JP1) GO TO 220\nC\n DO 200 K = JP1, L\n G = G + AR(K,J) * AR(I,K) - AI(K,J) * AI(I,K)\n GI = GI - AR(K,J) * AI(I,K) - AI(K,J) * AR(I,K)\n 200 CONTINUE\nC .......... FORM ELEMENT OF P ..........\n 220 E(J) = G / H\n TAU(2,J) = GI / H\n F = F + E(J) * AR(I,J) - TAU(2,J) * AI(I,J)\n 240 CONTINUE\nC\n HH = F / (H + H)\nC .......... FORM REDUCED A ..........\n DO 260 J = 1, L\n F = AR(I,J)\n G = E(J) - HH * F\n E(J) = G\n FI = -AI(I,J)\n GI = TAU(2,J) - HH * FI\n TAU(2,J) = -GI\nC\n DO 260 K = 1, J\n AR(J,K) = AR(J,K) - F * E(K) - G * AR(I,K)\n 1 + FI * TAU(2,K) + GI * AI(I,K)\n AI(J,K) = AI(J,K) - F * TAU(2,K) - G * AI(I,K)\n 1 - FI * E(K) - GI * AR(I,K)\n 260 CONTINUE\nC\n 270 DO 280 K = 1, L\n AR(I,K) = SCALE * AR(I,K)\n AI(I,K) = SCALE * AI(I,K)\n 280 CONTINUE\nC\n TAU(2,L) = -SI\n 290 HH = D(I)\n D(I) = AR(I,I)\n AR(I,I) = HH\n AI(I,I) = SCALE * SQRT(H)\n 300 CONTINUE\nC\n RETURN\n END\n", "meta": {"hexsha": "4145bd5f84a3674e5535dda63dd58edf4f8047f7", "size": 6387, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/htridi.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/htridi.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/htridi.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.3387096774, "max_line_length": 72, "alphanum_fraction": 0.5105683419, "num_tokens": 2191, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099167, "lm_q2_score": 0.7606506418255927, "lm_q1q2_score": 0.6539037835795644}} {"text": " SUBROUTINE area2d(x,area,vn,ntype)\r\n!---------------------------------------------------\r\n!*** calculates volume of a pyramid with a quad base (1GP scheme)\r\n!---------------------------------------------------\r\n\r\n IMPLICIT NONE\r\n\r\n INTEGER(kind=4):: ntype\r\n REAL(kind=8):: area,x(2,2),vn(2)\r\n\r\n REAL(kind=8) :: x1(2)\r\n REAL (kind=8), PARAMETER :: twopi=6.283185307179586\r\n\r\n X1(:) = X(:,2)-X(:,1)\r\n vn(1) = -x1(2)\r\n vn(2) = x1(1)\r\n CALL vecuni(2,vn,area)\r\n IF(ntype == 3) area=area*twopi*(x(1,1)+x(1,2))/2d0\r\n\r\n END SUBROUTINE area2d\r\n", "meta": {"hexsha": "83986c53a776dc5894129f000b9e7a5b5f0846e5", "size": 599, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/loads/area2d.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/loads/area2d.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/loads/area2d.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": 28.5238095238, "max_line_length": 67, "alphanum_fraction": 0.4323873122, "num_tokens": 194, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898305367525, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6538920105871425}} {"text": "c=======================================================================\nc\nc GENGAM \nc \nc Gamma distribution generator\nc\nc Generates random deviates from the Gamma distribution whose\nc density is\nc\nc (A**R)/Gamma(R) * X**(R-1) * Exp(-A*X)\nc\nc-----------------------------------------------------------------------\nc\nc----------------------------------------------------------------------- \n DOUBLE PRECISION FUNCTION gengam(a, r)\nc----------------------------------------------------------------------- \nc\nc INPUT :\nc a : location parameter of Gamma distribution (a>0) double\nc r : shape parameter of Gamma distribution (r>0) double\nc\nc Method - for details see:\nc (Case R >= 1.0)\nc Ahrens, J.H. and Dieter, U.\nc Generating Gamma Variates by a\nc Modified Rejection Technique.\nc Comm. ACM, 25,1 (Jan. 1982), 47 - 54.\nc Algorithm GD\nc\nc (Case 0.0 < R < 1.0)\nc Ahrens, J.H. and Dieter, U.\nc Computer Methods for Sampling from Gamma,\nc Beta, Poisson and Binomial Distributions.\nc Computing, 12 (1974), 223-246/\nc Adapted algorithm GS.\nc\nc----------------------------------------------------------------------\nc\nc scalar arguments\n DOUBLE PRECISION a, r\nc \nc external functions\n DOUBLE PRECISION sgamma\n EXTERNAL sgamma\nc \nc executable statements\n 10 gengam = sgamma(r)/a\nc gengam = gengam/a\n RETURN\n END\n", "meta": {"hexsha": "8e7db593ff1a05a1d61fb7955fbfbe09c860892b", "size": 1620, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/rnd/gengam.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/gengam.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/gengam.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": 31.7647058824, "max_line_length": 78, "alphanum_fraction": 0.4203703704, "num_tokens": 361, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898153067649, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6538919995950023}} {"text": "MODULE coolrates_module\n use amr_parameters,only:dp\n implicit none\n \nCONTAINS\n\n!XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nELEMENTAL FUNCTION comp_AlphaA_HII(T)\n\n! Returns case A rec. coefficient [cm3 s-1] for HII (Hui&Gnedin'97)\n! T => Temperature [K]\n!-------------------------------------------------------------------------\n implicit none \n real(dp),intent(in)::T\n real(dp)::comp_AlphaA_HII, lambda\n!-------------------------------------------------------------------------\n lambda= 315614./T ! 2.d0 * 157807.d0 / T\n comp_AlphaA_HII = 1.269d-13 * lambda**1.503 &\n / ( ( 1.d0+(lambda/0.522)**0.47 )**1.923 )\nEND FUNCTION comp_AlphaA_HII\n\n!XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nELEMENTAL FUNCTION comp_dAlphaA_dT_HII(T)\n\n! Returns Temperature derivative of the case A rec. coeff. of HII \n! T => Temperature [K]\n!-------------------------------------------------------------------------\n implicit none \n real(dp),intent(in)::T\n real(dp)::comp_dAlphaA_dT_HII, lambda, f\n!-------------------------------------------------------------------------\n lambda= 315614./T\n f= 1.d0+(lambda/0.522)**0.47\n comp_dAlphaA_dT_HII = 1.269d-13 * lambda**1.503 / f**1.923 &\n / T * ( 0.90381*(f-1.)/f - 1.503 )\nEND FUNCTION comp_dAlphaA_dT_HII\n\n!XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nELEMENTAL FUNCTION comp_AlphaA_HeII(T)\n\n! Returns case A rec. coefficient [cm3 s-1] for HeII (Hui&Gnedin'97)\n! T => Temperature [K]\n!-------------------------------------------------------------------------\n implicit none \n real(dp),intent(in)::T\n real(dp)::comp_AlphaA_HeII, lambda\n!-------------------------------------------------------------------------\n lambda= 570670./T\n comp_AlphaA_HeII = 3.d-14 * lambda**0.654\nEND FUNCTION comp_AlphaA_HeII\n\n!XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nELEMENTAL FUNCTION comp_AlphaA_HeIII(T)\n\n! Returns case A rec. coefficient [cm3 s-1] for HeIII (Hui&Gnedin'97)\n! T => Temperature [K]\n!-------------------------------------------------------------------------\n implicit none \n real(dp),intent(in)::T\n real(dp)::comp_AlphaA_HeIII, lambda\n!-------------------------------------------------------------------------\n lambda= 1263030./T\n comp_AlphaA_HeIII = 2.538d-13 * lambda**1.503 &\n / ( ( 1.d0+(lambda/0.522)**0.47 )**1.923 )\nEND FUNCTION comp_AlphaA_HeIII\n\n!XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nELEMENTAL FUNCTION comp_AlphaB_HII(T)\n\n! Returns case B rec. coefficient [cm3 s-1] for HII (Hui&Gnedin'97)\n! T => Temperature [K]\n!-------------------------------------------------------------------------\n implicit none \n real(dp),intent(in)::T\n real(dp)::comp_AlphaB_HII, lambda\n!-------------------------------------------------------------------------\n lambda = 315614./T\n comp_AlphaB_HII = &\n 2.753d-14 * lambda**1.5 / ( (1.d0+(lambda/2.74)**0.407)**2.242 )\nEND FUNCTION comp_AlphaB_HII\n\n!XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nELEMENTAL FUNCTION comp_AlphaB_HeII(T)\n\n! Returns case B rec. coefficient [cm3 s-1] for HeII (Hui&Gnedin'97)\n! T => Temperature [K]\n!-------------------------------------------------------------------------\n implicit none \n real(dp),intent(in)::T\n real(dp)::comp_AlphaB_HeII, lambda\n!-------------------------------------------------------------------------\n lambda = 570670./T\n comp_AlphaB_HeII = 1.26d-14 * lambda**0.75\nEND FUNCTION comp_AlphaB_HeII\n\n!XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nELEMENTAL FUNCTION comp_AlphaB_HeIII(T)\n\n! Returns case B rec. coefficient [cm3 s-1] for HeIII (Hui&Gnedin'97)\n! T => Temperature [K]\n!-------------------------------------------------------------------------\n implicit none \n real(dp),intent(in)::T\n real(dp)::comp_AlphaB_HeIII, lambda\n!-------------------------------------------------------------------------\n lambda= 1263030./T\n comp_AlphaB_HeIII = 5.506d-14 * lambda**1.5 &\n / ( ( 1.d0+(lambda/2.74)**0.407 )**2.242 )\nEND FUNCTION comp_AlphaB_HeIII\n\n!XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nELEMENTAL FUNCTION comp_dAlphaB_dT_HII(T)\n\n! Returns temperature derivative of the case B recombination rate\n! Gnedin 1997\n! T => Temperature [K]\n!-------------------------------------------------------------------------\n implicit none \n real(dp),intent(in)::T\n real(dp)::comp_dAlphaB_dT_HII, lambda, f\n!-------------------------------------------------------------------------\n lambda = 315614./T\n f= 1.d0+(lambda/2.74)**0.407\n comp_dAlphaB_dT_HII = 2.753d-14 * lambda**1.5 / f**2.242 &\n / T * ( 0.912494*(f-1.)/f - 1.5 )\nEND FUNCTION comp_dAlphaB_dT_HII\n\n!XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nELEMENTAL FUNCTION comp_Beta_HI(T)\n\n! Returns collisional ionization rate [cm3 s-1] of HI (Maselli&'03)\n! T => Temperature [K]\n!-------------------------------------------------------------------------\n implicit none \n real(dp),intent(in)::T\n real(dp)::comp_Beta_HI, T5\n!-------------------------------------------------------------------------\n T5 = T/1.d5\n comp_Beta_HI = &\n 5.85d-11 * sqrt(T) / (1.d0+sqrt(T5)) * exp(-157809.1d0/T)\nEND FUNCTION comp_Beta_HI\n\n!XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nELEMENTAL FUNCTION comp_dBeta_dT_HI(T)\n\n! Returns T derivative of collisional ionization rate [cm3 s-1] of HI \n! (Maselli&'03)\n! T => Temperature [K]\n!-------------------------------------------------------------------------\n implicit none \n real(dp),intent(in)::T\n real(dp)::f, T5, comp_dBeta_dT_HI\n!-------------------------------------------------------------------------\n T5 = T/1.d5\n f = 1.+sqrt(T5)\n comp_dBeta_dT_HI = 5.85d-11 * sqrt(T) / f * exp(-157809.1d0/T) &\n * (0.5/T + 157809.1d0/T**2 - .5/(sqrt(1.d5*T)*f))\nEND FUNCTION comp_dBeta_dT_HI\n\n!XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nELEMENTAL FUNCTION comp_Beta_HeI(T)\n\n! Returns collisional ionization rate [cm3 s-1] of HeI (Maselli&'03)\n! T => Temperature [K]\n!-------------------------------------------------------------------------\n implicit none \n real(dp),intent(in)::T\n real(dp)::comp_Beta_HeI, T5\n!-------------------------------------------------------------------------\n T5 = T/1.d5\n comp_Beta_HeI = &\n 2.38d-11 * sqrt(T) / (1.d0+sqrt(T5)) * exp(-285335.4d0/T)\nEND FUNCTION comp_Beta_HeI\n\n!XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nELEMENTAL FUNCTION comp_Beta_HeII(T)\n\n! Returns collisional ionization rate [cm3 s-1] of HeII (Maselli&'03)\n! T => Temperature [K]\n!-------------------------------------------------------------------------\n implicit none \n real(dp),intent(in)::T\n real(dp)::comp_Beta_HeII, T5\n!-------------------------------------------------------------------------\n T5 = T/1.d5\n comp_Beta_HeII = &\n 5.68d-12 * sqrt(T) / (1.d0+sqrt(T5)) * exp(-631515.d0/T)\nEND FUNCTION comp_Beta_HeII\n\n!XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nELEMENTAL FUNCTION comp_collExrate_HI(TK)\n\n! Gives Collisional Excitation rate coefficient for the 1->2\n! transition in hydrogen atom energies, in [cm3 s-1], according to\n! Callaway, Unnikrishnan & Oza 1987.\n! TK => Temperatue in Kelvin\n!-------------------------------------------------------------------------\n real(dp),intent(in)::TK\n real(dp)::comp_collExrate_HI\n real(dp),parameter ::kB = 1.38062d-16 ! Boltzm.const. [erg K-1]\n!-------------------------------------------------------------------------\n comp_collExrate_HI = &\n 2.41d-6/sqrt(TK) * (TK/1.d4)**0.22 * exp(-1.63d-11/(kb*TK))\nEND FUNCTION comp_collExrate_HI\n\n!XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nFUNCTION compCoolrate(T, ne, nHI, nHII, nHeI, nHeII, nHeIII, aexp, &\n dcooldT, rt_OTSA)\n\n! Compute cooling rate in a cell\n! T => Cell emperature [K]\n! xion => Cell ionization fraction\n! nH => Hydrogen number density [cm-3] \n! aexp => Cosmic expansion\n! dcooldT <= Temperature derivative of the rate\n! dcooldx <= Ionized fraction derivative of the rate\n! returns: Resulting cooling rate [erg s-1 cm-3] \n!-------------------------------------------------------------------------\n implicit none \n real(dp)::T, ne, nHI, nHII, nHeI, nHeII, nHeIII, aexp\n real(dp)::compCoolrate, dcooldT!----------------------------------------\n real(dp)::T2, sqrtT, sqrt5T, fT5, sqrtT_fT5, f, Ta\n real(dp)::laHII, laHeII, laHeIII \n real(dp)::ci_HI, ci_HeI, ci_HeII, dci_HI, dci_HeI, dci_HeII\n real(dp)::r_HII, r_HeII, r_HeIII, dr_HII, dr_HeII, dr_HeIII\n real(dp)::ce_HI, ce_HeI, ce_HeII, dce_HI, dce_HeI, dce_HeII\n real(dp)::bre, dbre, com, dcom, die, ddie\n real(dp),parameter::kb=1.3806d-16 ! Boltzmann constant [ergs K-1]\n logical::RT_OTSA\n!-------------------------------------------------------------------------\n T2 = T**2\n sqrtT = sqrt(T)\n sqrt5T = sqrt(1.d5*T)\n fT5 = 1.+sqrt(T/1.d5)\n\n ! Coll. Ionization Cooling from Cen 1992 (via Maselli et al 2003)\n sqrtT_fT5 = sqrtT/fT5\n ci_HI = 1.27d-21 * sqrtT_fT5 * exp(-157809.1/T) * ne * nHI\n ci_HeI = 9.38d-22 * sqrtT_fT5 * exp(-285335.4/T) * ne * nHeI\n ci_HeII = 4.95d-22 * sqrtT_fT5 * exp(-631515. /T) * ne * nHeII\n f = 0.5/T - 0.5/(sqrt5T+T)\n dci_HI = ci_HI * ( f + 157809.1/T2 ) !dHI\n dci_HeI = ci_HeI * ( f + 285335.4/T2 ) !dHeI\n dci_HeII= ci_HeII * ( f + 631515.0/T2 ) !dHeII\n\n ! Recombination Cooling (Hui&Gnedin'97)\n laHII = 315614./T \n laHeII = 570670./T \n laHeIII = 1263030./T\n if(.not. rt_otsa) then ! Case A\n f = 1.d0+(laHII/0.541)**0.502 \n r_HII = 1.778d-29 * laHII**1.965 / f**2.697 * T * ne * nHII\n dr_HII = r_HII/T * ( - 0.965 + 1.35389*(f-1.)/f ) !dHII\n \n r_HeII = 3.d-14 * laHeII**0.654 * kb * T * ne * nHeII\n dr_HeII = r_HeII / T * 0.346 !dHeII\n\n f = 1.d0+(laHeIII/0.541)**0.502 \n r_HeIII = 14.224d-29 * laHeIII**1.965 / f**2.697 * T * ne * nHeIII\n dr_HeIII= r_HeIII/T * ( - 0.965 + 1.35389*(f-1.)/f ) !dHeIII \n else ! Case B\n f = 1.d0+(laHII/2.25)**0.376 \n r_HII = 3.435d-30 * laHII**1.97 / f**3.72 * T * ne * nHII\n dr_HII = r_HII/T * ( - 0.97 + 1.39827*(f-1.)/f ) !dHII\n\n r_HeII = 1.26d-14 * laHeII**0.75 * kb * T * ne * nHeII\n dr_HeII = r_HeII / T * 0.25 !dHeII\n\n f = 1.d0+(laHeIII/2.25)**0.376 \n r_HeIII = 27.48d-30 * laHeIII**1.97 / f**3.72 * T * ne * nHeIII\n dr_HeIII =r_HeIII/T * ( - 0.97 + 1.39827*(f-1.)/f ) !dHeIII\n endif\n\n ! Collisional excitation cooling from Cen'92\n ce_HI = 7.5d-19 * exp(-118348./T) / fT5 * ne * nHI\n ce_HeI = 9.10d-27 * exp(-13179./T) / fT5 * T**(-0.1687) * ne * nHeI\n ce_HeII = 5.54d-17 * exp(-473638./T) / fT5 * T**(-0.397) * ne * nHeII\n\n f = 0.5/(sqrt5T+T)\n dce_HI = ce_HI * ( 118348./T2 - f) !dHI\n dce_HeI = ce_HeI * ( 13179./T2 - f - 0.1687/T) !dHeI\n dce_HeII = ce_HeII * ( 473638./T2 - f - 0.397/T) !dHeII\n\n ! Bremsstrahlung from Osterbrock & Ferland 2006\n bre = 1.42d-27 * 1.5 * sqrtT * ne * (nHII + nHeII + 4. * nHeIII)\n dbre = bre * 0.5 / T\n\n ! Compton Cooling from Haimann et al. 96, via Maselli et al.\n Ta = 2.727/aexp \n com = 1.017d-37 * Ta**4 * (T-Ta) * ne \n dcom = com / (T-Ta) \n\n ! Dielectronic recombination cooling, from Black 1981\n f = 1.24D-13*T**(-1.5d0)*exp(-470000.d0/T) * ne * nHeII\n die = f*(1.D0+0.3d0*exp(-94000.d0/T))\n ddie = die/T2*(564000.-1.5*T) - f*94000./T2\n \n ! Overall Cooling\n compCoolrate = ci_HI + r_HII + ce_HI + com &\n + ci_HeI + r_HeII + ce_HeI + die &\n + ci_HeII + r_HeIII + ce_HeII + bre\n\n dCooldT = dci_HI + dr_HII + dce_HI + dcom &\n + dci_HeI + dr_HeII + dce_HeI + ddie &\n + dci_HeII + dr_HeIII + dce_HeII + dbre\n\nEND FUNCTION compCoolrate\n\n\nEND MODULE coolrates_module\n", "meta": {"hexsha": "2f3d749c1a8af4b3f51199a2cfe4104389c73864", "size": 13072, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/amuse/community/ramses/src/rt/coolrates_module.f90", "max_stars_repo_name": "rknop/amuse", "max_stars_repo_head_hexsha": "85d5bdcc29cfc87dc69d91c264101fafd6658aec", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-02-24T16:47:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-24T16:47:48.000Z", "max_issues_repo_path": "src/amuse/community/ramses/src/rt/coolrates_module.f90", "max_issues_repo_name": "rknop/amuse", "max_issues_repo_head_hexsha": "85d5bdcc29cfc87dc69d91c264101fafd6658aec", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-06-22T13:02:14.000Z", "max_issues_repo_issues_event_max_datetime": "2018-09-06T20:08:43.000Z", "max_forks_repo_path": "src/amuse/community/ramses/src/rt/coolrates_module.f90", "max_forks_repo_name": "rknop/amuse", "max_forks_repo_head_hexsha": "85d5bdcc29cfc87dc69d91c264101fafd6658aec", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-11-19T04:41:37.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-20T02:11:17.000Z", "avg_line_length": 42.0321543408, "max_line_length": 78, "alphanum_fraction": 0.5045899633, "num_tokens": 4019, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898279984214, "lm_q2_score": 0.7217432003123989, "lm_q1q2_score": 0.6538919979100605}} {"text": "MODULE common\n!=======================================================================\n!\n! [PURPOSE:] General constants and procedures\n!\n! [ATTENTION:] This module calls 'SFMT.f90'\n!\n! [HISTORY:]\n! 07/20/2004 Takemasa MIYOSHI created\n! 01/23/2009 Takemasa MIYOSHI modified for SFMT\n!\n!=======================================================================\n IMPLICIT NONE\n PUBLIC\n!-----------------------------------------------------------------------\n! Variable size definitions\n!-----------------------------------------------------------------------\n INTEGER,PARAMETER :: r_dble=kind(0.0d0)\n INTEGER,PARAMETER :: r_sngl=kind(0.0e0)\n!#ifdef SINGLE\n! INTEGER,PARAMETER :: r_size=r_sngl\n!#else\n INTEGER,PARAMETER :: r_size=r_dble\n!#endif\n!-----------------------------------------------------------------------\n! Constants\n!-----------------------------------------------------------------------\n REAL(r_size),PARAMETER :: pi=3.1415926535d0\n REAL(r_size),PARAMETER :: gg=9.81d0\n REAL(r_size),PARAMETER :: rd=287.05d0 ! gas constant air (J/kg/K) GYL\n REAL(r_size),PARAMETER :: rv=461.50d0 ! gas constant H2O (J/kg/K) GYL\n REAL(r_size),PARAMETER :: cp=1005.7d0 ! spec heat air [p] (J/kg/K)\n REAL(r_size),PARAMETER :: hvap=2.5d6 ! heat of vaporization (J/kg)\n REAL(r_size),PARAMETER :: fvirt=rv/rd-1.0d0 ! parameter for T/Tv conversion GYL\n REAL(r_size),PARAMETER :: re=6371.3d3\n REAL(r_size),PARAMETER :: r_omega=7.292d-5\n REAL(r_size),PARAMETER :: t0c=273.15d0\n REAL(r_size),PARAMETER :: undef=-9.99d33\n REAL(r_size),PARAMETER :: deg2rad=pi/180.0d0 ! GYL\n REAL(r_size),PARAMETER :: rad2deg=180.0d0/pi ! GYL\n\nCONTAINS\n!-----------------------------------------------------------------------\n! Mean\n!-----------------------------------------------------------------------\nSUBROUTINE com_mean(ndim,var,amean)\n IMPLICIT NONE\n\n INTEGER,INTENT(IN) :: ndim\n REAL(r_size),INTENT(IN) :: var(ndim)\n REAL(r_size),INTENT(OUT) :: amean\n\n INTEGER :: i\n\n amean = 0.0d0\n DO i=1,ndim\n amean = amean + var(i)\n END DO\n amean = amean / REAL(ndim,r_size)\n\n RETURN\nEND SUBROUTINE com_mean\n!-----------------------------------------------------------------------\n! Standard deviation\n!-----------------------------------------------------------------------\nSUBROUTINE com_stdev(ndim,var,aout)\n IMPLICIT NONE\n\n INTEGER,INTENT(IN) :: ndim\n REAL(r_size),INTENT(IN) :: var(ndim)\n REAL(r_size),INTENT(OUT) :: aout\n\n REAL(r_size) :: amean\n REAL(r_size) :: dev(ndim)\n\n CALL com_mean(ndim,var,amean)\n\n dev(:) = var(:) - amean\n\n aout = SQRT( SUM(dev*dev) / REAL(ndim-1,r_size) )\n\n RETURN\nEND SUBROUTINE com_stdev\n!-----------------------------------------------------------------------\n! Covariance\n!-----------------------------------------------------------------------\nSUBROUTINE com_covar(ndim,var1,var2,cov)\n IMPLICIT NONE\n\n INTEGER,INTENT(IN) :: ndim\n REAL(r_size),INTENT(IN) :: var1(ndim)\n REAL(r_size),INTENT(IN) :: var2(ndim)\n REAL(r_size),INTENT(OUT) :: cov\n\n REAL(r_size) :: amean1,amean2\n REAL(r_size) :: dev1(ndim),dev2(ndim)\n\n CALL com_mean(ndim,var1,amean1)\n CALL com_mean(ndim,var2,amean2)\n\n dev1(:) = var1(:) - amean1\n dev2(:) = var2(:) - amean2\n\n cov = SUM( dev1*dev2 ) / REAL(ndim-1,r_size)\n\n RETURN\nEND SUBROUTINE com_covar\n!-----------------------------------------------------------------------\n! Correlation\n!-----------------------------------------------------------------------\nSUBROUTINE com_correl(ndim,var1,var2,cor)\n IMPLICIT NONE\n\n INTEGER,INTENT(IN) :: ndim\n REAL(r_size),INTENT(IN) :: var1(ndim)\n REAL(r_size),INTENT(IN) :: var2(ndim)\n REAL(r_size),INTENT(OUT) :: cor\n\n REAL(r_size) :: cov,stdev1,stdev2\n\n CALL com_stdev(ndim,var1,stdev1)\n CALL com_stdev(ndim,var2,stdev2)\n CALL com_covar(ndim,var1,var2,cov)\n\n cor = cov/stdev1/stdev2\n\n RETURN\nEND SUBROUTINE com_correl\n!-----------------------------------------------------------------------\n! Anomaly Correlation\n!-----------------------------------------------------------------------\nSUBROUTINE com_anomcorrel(ndim,var1,var2,varmean,cor)\n IMPLICIT NONE\n\n INTEGER,INTENT(IN) :: ndim\n REAL(r_size),INTENT(IN) :: var1(ndim)\n REAL(r_size),INTENT(IN) :: var2(ndim)\n REAL(r_size),INTENT(IN) :: varmean(ndim)\n REAL(r_size),INTENT(OUT) :: cor\n\n REAL(r_size) :: dev1(ndim),dev2(ndim)\n\n dev1 = var1 - varmean\n dev2 = var2 - varmean\n\n cor = SUM( dev1*dev2 ) / SQRT( SUM(dev1*dev1) * SUM(dev2*dev2) )\n\n RETURN\nEND SUBROUTINE com_anomcorrel\n!-----------------------------------------------------------------------\n! L2 Norm\n!-----------------------------------------------------------------------\nSUBROUTINE com_l2norm(ndim,var,anorm)\n IMPLICIT NONE\n\n INTEGER,INTENT(IN) :: ndim\n REAL(r_size),INTENT(IN) :: var(ndim)\n REAL(r_size),INTENT(OUT) :: anorm\n\n anorm = SQRT( SUM(var*var) )\n\n RETURN\nEND SUBROUTINE com_l2norm\n!-----------------------------------------------------------------------\n! RMS (root mean square)\n!-----------------------------------------------------------------------\nSUBROUTINE com_rms(ndim,var,rmsv)\n IMPLICIT NONE\n\n INTEGER,INTENT(IN) :: ndim\n REAL(r_size),INTENT(IN) :: var(ndim)\n REAL(r_size),INTENT(OUT) :: rmsv\n\n rmsv = SQRT( SUM(var*var) / REAL(ndim,r_size) )\n\n RETURN\nEND SUBROUTINE com_rms\n!-----------------------------------------------------------------------\n! Lanczos Filter (Low-pass) with cyclic boundary\n!-----------------------------------------------------------------------\nSUBROUTINE com_filter_lanczos(ndim,fc,var)\n IMPLICIT NONE\n\n INTEGER,INTENT(IN) :: ndim\n REAL(r_size),INTENT(IN) :: fc ! critical frequency in [0,pi]\n REAL(r_size),INTENT(INOUT) :: var(ndim)\n\n INTEGER,PARAMETER :: lresol=10\n\n REAL(r_size) :: weight(-lresol:lresol)\n REAL(r_size) :: varwk(1-lresol:ndim+lresol)\n REAL(r_size) :: rl,rlresol\n INTEGER :: i,l\n!\n! Weight\n!\n rlresol = REAL(lresol,r_size)\n DO l=-lresol,-1\n rl = REAL(l,r_size)\n weight(l) = SIN(fc*rl) * SIN(pi*rl/rlresol) &\n & * rlresol / pi / rl / pi / rl\n END DO\n DO l=1,lresol\n rl = REAL(l,r_size)\n weight(l) = SIN(fc*rl) * SIN(pi*rl/rlresol) &\n & * rlresol / pi / rl / pi / rl\n END DO\n weight(0) = fc / pi\n!\n! Cyclic boundary\n!\n DO i=0,1-lresol,-1\n varwk(i) = var(ndim+i)\n END DO\n DO i=ndim+1,ndim+lresol\n varwk(i) = var(i-ndim)\n END DO\n varwk(1:ndim) = var(1:ndim)\n!\n! Filter\n!\n var = 0.0d0\n DO i=1,ndim\n DO l=-lresol,lresol\n var(i) = var(i) + weight(l) * varwk(i+l)\n END DO\n END DO\n\n RETURN\nEND SUBROUTINE com_filter_lanczos\n!-----------------------------------------------------------------------\n! RAND (random number with uniform distribution)\n!-----------------------------------------------------------------------\nSUBROUTINE com_rand(ndim,var)\n IMPLICIT NONE\n\n INTEGER,INTENT(IN) :: ndim\n REAL(r_size),INTENT(OUT) :: var(1:ndim)\n REAL(r_dble) :: genrand_res53\n INTEGER :: idate(8)\n INTEGER :: i,iseed\n LOGICAL,SAVE :: first=.true.\n\n IF (first) THEN\n CALL DATE_AND_TIME(VALUES=idate)\n iseed = idate(8) + idate(7)*1000\n CALL init_gen_rand(iseed)\n first=.false.\n END IF\n\n DO i=1,ndim\n var(i) = genrand_res53()\n END DO\n\n RETURN\nEND SUBROUTINE com_rand\n!-----------------------------------------------------------------------\n! RANDN (random number with normal distribution)\n!-----------------------------------------------------------------------\nSUBROUTINE com_randn(ndim,var)\n IMPLICIT NONE\n\n INTEGER,INTENT(IN) :: ndim\n REAL(r_size),INTENT(OUT) :: var(1:ndim)\n REAL(r_size) :: rnd(2)\n REAL(r_dble) :: genrand_res53\n INTEGER :: idate(8)\n INTEGER :: i,iseed\n LOGICAL,SAVE :: first=.true.\n\n IF (first) THEN\n CALL DATE_AND_TIME(VALUES=idate)\n iseed = idate(8) + idate(7)*1000\n CALL init_gen_rand(iseed)\n first=.false.\n END IF\n\n IF( MOD(ndim,2)==0 ) THEN\n DO i=1,ndim/2\n rnd(1) = genrand_res53()\n rnd(2) = genrand_res53()\n var(i*2-1) = sqrt( -2.0d0 * log( rnd(1) ) ) * sin( 2.0d0*pi*rnd(2) )\n var(i*2) = sqrt( -2.0d0 * log( rnd(1) ) ) * cos( 2.0d0*pi*rnd(2) )\n END DO\n ELSE\n DO i=1,(ndim-1)/2\n rnd(1) = genrand_res53()\n rnd(2) = genrand_res53()\n var(i*2-1) = sqrt( -2.0d0 * log( rnd(1) ) ) * sin( 2.0d0*pi*rnd(2) )\n var(i*2) = sqrt( -2.0d0 * log( rnd(1) ) ) * cos( 2.0d0*pi*rnd(2) )\n END DO\n rnd(1) = genrand_res53()\n rnd(2) = genrand_res53()\n var(ndim) = sqrt( -2.0d0 * log( rnd(1) ) ) * sin( 2.0d0*pi*rnd(2) )\n END IF\n\n RETURN\nEND SUBROUTINE com_randn\n!-----------------------------------------------------------------------\n! TIMEINC\n!-----------------------------------------------------------------------\nSUBROUTINE com_timeinc_hr(iy,im,id,ih,incr)\n IMPLICIT NONE\n\n INTEGER,INTENT(INOUT) :: iy\n INTEGER,INTENT(INOUT) :: im\n INTEGER,INTENT(INOUT) :: id\n INTEGER,INTENT(INOUT) :: ih\n INTEGER,INTENT(IN) :: incr\n\n ih = ih + incr\n IF(ih>23) THEN\n ih = ih - 24\n id = id + 1\n IF(id==29.AND.im==2.AND.mod(iy,4)/=0) THEN\n id = 1\n im = 3\n ELSE IF(id==30.AND.im==2.AND.mod(iy,4)==0) THEN\n id = 1\n im = 3\n ELSE IF(id==31.AND.(im==4.OR.im==6.OR.im==9.OR.im==11)) THEN\n id = 1\n im = im + 1\n ELSE IF(id==32.AND.(im==1.OR.im==3.OR.im==5.OR.im==7.OR.im==8.OR.im==10)) THEN\n id = 1\n im = im + 1\n ELSE IF(id==32.AND.im==12) THEN\n id = 1\n im = 1\n iy = iy + 1\n END IF\n END IF\n\n RETURN\nEND SUBROUTINE com_timeinc_hr\n!-----------------------------------------------------------------------\n! TIMECONVERSION\n!-----------------------------------------------------------------------\nSUBROUTINE com_time2ymdh(itime,iy,im,id,ih)\n IMPLICIT NONE\n INTEGER(8),INTENT(IN) :: itime\n INTEGER,INTENT(OUT) :: iy\n INTEGER,INTENT(OUT) :: im\n INTEGER,INTENT(OUT) :: id\n INTEGER,INTENT(OUT) :: ih\n\n iy = INT( itime / 1000000 )\n im = INT( (itime-iy*1000000) / 10000 )\n id = INT( (itime-iy*1000000-im*10000) / 100 )\n ih = INT( itime-iy*1000000-im*10000-id*100 )\n\n RETURN\nEND SUBROUTINE com_time2ymdh\n\nSUBROUTINE com_ymdh2time(iy,im,id,ih,itime)\n IMPLICIT NONE\n INTEGER,INTENT(IN) :: iy\n INTEGER,INTENT(IN) :: im\n INTEGER,INTENT(IN) :: id\n INTEGER,INTENT(IN) :: ih\n INTEGER(8),INTENT(OUT) :: itime\n\n itime=iy*1000000+im*10000+id*100+ih\n\n RETURN\nEND SUBROUTINE com_ymdh2time\n!-----------------------------------------------------------------------\n! DISTANCE BETWEEN TWO POINTS (LONa,LATa)-(LONb,LATb)\n!-----------------------------------------------------------------------\nSUBROUTINE com_distll(ndim,alon,alat,blon,blat,dist)\n IMPLICIT NONE\n INTEGER,INTENT(IN) :: ndim\n REAL(r_size),INTENT(IN) :: alon(ndim)\n REAL(r_size),INTENT(IN) :: alat(ndim)\n REAL(r_size),INTENT(IN) :: blon(ndim)\n REAL(r_size),INTENT(IN) :: blat(ndim)\n REAL(r_size),INTENT(OUT) :: dist(ndim)\n REAL(r_size),PARAMETER :: r180=1.0d0/180.0d0\n REAL(r_size) :: lon1,lon2,lat1,lat2\n REAL(r_size) :: cosd(ndim)\n INTEGER :: i\n\n DO i=1,ndim\n lon1 = alon(i) * pi * r180\n lon2 = blon(i) * pi * r180\n lat1 = alat(i) * pi * r180\n lat2 = blat(i) * pi * r180\n\n cosd(i) = SIN(lat1)*SIN(lat2) + COS(lat1)*COS(lat2)*COS(lon2-lon1)\n cosd(i) = MIN( 1.d0,cosd(i))\n cosd(i) = MAX(-1.d0,cosd(i))\n\n dist(i) = ACOS( cosd(i) ) * re\n END DO\n\n RETURN\nEND SUBROUTINE com_distll\n!-----------------------------------------------------------------------\n! DISTANCE BETWEEN TWO POINTS (LONa,LATa)-(LONb,LATb)\n!-----------------------------------------------------------------------\nSUBROUTINE com_distll_1(alon,alat,blon,blat,dist)\n IMPLICIT NONE\n REAL(r_size),INTENT(IN) :: alon\n REAL(r_size),INTENT(IN) :: alat\n REAL(r_size),INTENT(IN) :: blon\n REAL(r_size),INTENT(IN) :: blat\n REAL(r_size),INTENT(OUT) :: dist\n REAL(r_size),PARAMETER :: r180=1.0d0/180.0d0\n REAL(r_size) :: lon1,lon2,lat1,lat2\n REAL(r_size) :: cosd\n\n lon1 = alon * pi * r180\n lon2 = blon * pi * r180\n lat1 = alat * pi * r180\n lat2 = blat * pi * r180\n\n cosd = SIN(lat1)*SIN(lat2) + COS(lat1)*COS(lat2)*COS(lon2-lon1)\n cosd = MIN( 1.d0,cosd)\n cosd = MAX(-1.d0,cosd)\n\n dist = ACOS( cosd ) * re\n\n RETURN\nEND SUBROUTINE com_distll_1\n!-----------------------------------------------------------------------\n! Cubic spline interpolation\n! [Reference:] Akima, H., 1970: J. ACM, 17, 589-602.\n!-----------------------------------------------------------------------\nSUBROUTINE com_interp_spline(ndim,x,y,n,x5,y5)\n IMPLICIT NONE\n INTEGER,INTENT(IN) :: ndim ! number of grid points\n REAL(r_size),INTENT(IN) :: x(ndim) ! coordinate\n REAL(r_size),INTENT(IN) :: y(ndim) ! variable\n INTEGER,INTENT(IN) :: n ! number of targets\n REAL(r_size),INTENT(IN) :: x5(n) ! target coordinates\n REAL(r_size),INTENT(OUT) :: y5(n) ! target values\n INTEGER :: i,j,m\n REAL(r_size) :: dydx(5),ddydx(4),t(2),dx21,dx\n REAL(r_size) :: wk\n\n TGT: DO j=1,n\n DO i=1,ndim\n IF(x5(j) == x(i)) THEN\n y5(j) = y(i)\n CYCLE TGT\n END IF\n IF(x5(j) < x(i)) EXIT\n END DO\n! i-3 i-2 i-1 i i+1 i+2\n! ---+-----+-----+---*-+-----+-----+---\n!dydx 1 2 3 4 5\n!ddydx 1 2 3 4\n!t 1 2\n IF(i==2) THEN\n DO m=3,5\n dydx(m) = (y(i-3+m)-y(i-4+m)) / (x(i-3+m)-x(i-4+m))\n END DO\n dydx(2) = 2.0d0*dydx(3) - dydx(4)\n dydx(1) = 2.0d0*dydx(2) - dydx(3)\n ELSE IF(i==3) THEN\n DO m=2,5\n dydx(m) = (y(i-3+m)-y(i-4+m)) / (x(i-3+m)-x(i-4+m))\n END DO\n dydx(1) = 2.0d0*dydx(2) - dydx(3)\n ELSE IF(i==ndim) THEN\n DO m=1,3\n dydx(m) = (y(i-3+m)-y(i-4+m)) / (x(i-3+m)-x(i-4+m))\n END DO\n dydx(4) = 2.0d0*dydx(3) - dydx(2)\n dydx(5) = 2.0d0*dydx(4) - dydx(3)\n ELSE IF(i==ndim-1) THEN\n DO m=1,4\n dydx(m) = (y(i-3+m)-y(i-4+m)) / (x(i-3+m)-x(i-4+m))\n END DO\n dydx(5) = 2.0d0*dydx(4) - dydx(3)\n ELSE\n DO m=1,5\n dydx(m) = (y(i-3+m)-y(i-4+m)) / (x(i-3+m)-x(i-4+m))\n END DO\n END IF\n DO m=1,4\n ddydx(m) = ABS(dydx(m+1) - dydx(m))\n END DO\n DO m=1,2\n wk = ddydx(m+2) + ddydx(m)\n IF(wk == 0) THEN\n t(m) = 0.0d0\n ELSE\n t(m) = (ddydx(m+2)*dydx(m+1)+ddydx(m)*dydx(m+2))/wk\n END IF\n END DO\n dx21 = x(i)-x(i-1)\n dx = x5(j) - x(i-1)\n y5(j) = y(i-1) &\n & + dx*t(1) &\n & + dx*dx*(3.0d0*dydx(3)-2.0d0*t(1)-t(2))/dx21 &\n & + dx*dx*dx*(t(1)+t(2)-2.0d0*dydx(3))/dx21/dx21\n END DO TGT\n\n RETURN\nEND SUBROUTINE com_interp_spline\n!-----------------------------------------------------------------------\n! (LON,LAT) --> (i,j) conversion\n! [ORIGINAL AUTHOR:] Masaru Kunii\n!-----------------------------------------------------------------------\nSUBROUTINE com_pos2ij(msw,nx,ny,flon,flat,num_obs,olon,olat,oi,oj)\n IMPLICIT NONE\n ! --- inout variables\n INTEGER,INTENT(IN) :: msw !MODE SWITCH: 1: fast, 2: accurate\n INTEGER,INTENT(IN) :: nx,ny !number of grid points\n REAL(r_size),INTENT(IN) :: flon(nx,ny),flat(nx,ny) !(lon,lat) at (i,j)\n INTEGER,INTENT(IN) :: num_obs !repetition number of conversion\n REAL(r_size),INTENT(IN) :: olon(num_obs),olat(num_obs) !target (lon,lat)\n REAL(r_size),INTENT(OUT) :: oi(num_obs),oj(num_obs) !target (i,j)\n ! --- local work variables\n LOGICAL,PARAMETER :: detailout = .FALSE.\n INTEGER,PARAMETER :: num_grid_ave = 4 ! fix\n INTEGER :: inum,ix,jy,ip,wk_maxp\n INTEGER :: iorder_we,iorder_sn\n INTEGER :: nxp,nyp\n REAL(r_size),PARAMETER :: miss = -32768 \n REAL(r_size),PARAMETER :: max_dist = 2.0e+6\n REAL(r_size) :: rlat_max, rlat_min, rlon_max, rlon_min \n REAL(r_size) :: dist(num_grid_ave) \n REAL(r_size) :: dist_min_x(num_obs, num_grid_ave)\n REAL(r_size) :: dist_min_y(num_obs, num_grid_ave) \n REAL(r_size) :: wk_dist, sum_dist\n REAL(r_size) :: ratio(num_grid_ave)\n IF(detailout) THEN\n WRITE(6,'(A)') '====================================================='\n WRITE(6,'(A)') ' Detailed output of SUBROUTINE com_pos2ij '\n WRITE(6,'(A)') '=====================================================' \n END IF\n ! ================================================================\n ! Check the Order of flon, flat\n ! ================================================================ \n iorder_we = 1\n iorder_sn = 1\n IF(flon(1,1) > flon(2,1)) THEN\n iorder_we = -1\n END IF\n IF(flat(1,1) > flat(1,2)) THEN\n iorder_sn = -1\n END IF\n IF(detailout) THEN \n WRITE(6,'(3X,A,I5)') 'Obs Order (WE) :',iorder_we \n WRITE(6,'(3X,A,I5)') 'Obs Order (SN) :',iorder_sn \n END IF\n ! ================================================================\n ! FAST MODE\n ! ================================================================ \n IF(msw == 1) THEN\n ! ==============================================================\n ! Surrounding 4 Grid Points Interpolation\n ! ============================================================== \n Obs_Loop_1 : DO inum=1,num_obs \n IF(detailout) WRITE(6,'(A,I5,2F15.5)') '*** START OBS ',inum,olon(inum),olat(inum) \n ! ------------------------------------------------------------\n ! Search Basic Point\n ! ------------------------------------------------------------ \n nxp = miss\n nyp = miss\n DO jy=1,ny-1\n DO ix=1,nx-1\n rlon_max = MAXVAL(flon(ix:ix+1, jy:jy+1))\n rlon_min = MINVAL(flon(ix:ix+1, jy:jy+1))\n rlat_max = MAXVAL(flat(ix:ix+1, jy:jy+1))\n rlat_min = MINVAL(flat(ix:ix+1, jy:jy+1))\n IF(rlon_min <= olon(inum) .AND. rlon_max >= olon(inum) .AND. &\n & rlat_min <= olat(inum) .AND. rlat_max >= olat(inum)) THEN\n nxp = ix\n nyp = jy\n EXIT\n END IF\n END DO\n END DO\n IF(detailout) WRITE(6,'(3X,A,2I7)') 'nxp, nyp =',nxp,nyp\n IF(nxp == miss .OR. nyp == miss) THEN\n WRITE(6,'(A)') '!!WARNING(com_pos2ij): obs position cannot be detected'\n oi(inum) = miss\n oj(inum) = miss\n CYCLE Obs_Loop_1\n END IF\n ! ------------------------------------------------------------\n ! Interpolation\n ! ------------------------------------------------------------ \n CALL com_distll_1(flon(nxp ,nyp ),flat(nxp ,nyp ),&\n & olon(inum),olat(inum),dist(1))\n CALL com_distll_1(flon(nxp+1,nyp ),flat(nxp+1,nyp ),&\n & olon(inum),olat(inum),dist(2))\n CALL com_distll_1(flon(nxp ,nyp+1),flat(nxp ,nyp+1),&\n & olon(inum),olat(inum),dist(3)) \n CALL com_distll_1(flon(nxp+1,nyp+1),flat(nxp+1,nyp+1),&\n & olon(inum),olat(inum),dist(4)) \n dist(1:4) = dist(1:4) * 1.D-3 \n IF(detailout) WRITE(6,'(3X,A,4F15.5)') 'distance :',dist(1:4) \n sum_dist = dist(1) * dist(1) * dist(2) * dist(2) * dist(3) * dist(3) &\n & + dist(2) * dist(2) * dist(3) * dist(3) * dist(4) * dist(4) &\n & + dist(3) * dist(3) * dist(4) * dist(4) * dist(1) * dist(1) &\n & + dist(4) * dist(4) * dist(1) * dist(1) * dist(2) * dist(2)\n ratio(1) = (dist(2)*dist(2)*dist(3)*dist(3)*dist(4)*dist(4))/sum_dist\n ratio(2) = (dist(3)*dist(3)*dist(4)*dist(4)*dist(1)*dist(1))/sum_dist\n ratio(3) = (dist(4)*dist(4)*dist(1)*dist(1)*dist(2)*dist(2))/sum_dist\n ratio(4) = (dist(1)*dist(1)*dist(2)*dist(2)*dist(3)*dist(3))/sum_dist\n IF(detailout) WRITE(6,'(3X,A,5F15.5)') 'ratio :',ratio(1:4),SUM(ratio(1:4))\n oi(inum) = ratio(1) * nxp + ratio(2) * (nxp+1) &\n & + ratio(3) * nxp + ratio(4) * (nxp+1)\n oj(inum) = ratio(1) * nyp + ratio(2) * nyp &\n & + ratio(3) * (nyp+1) + ratio(4) * (nyp+1) \n IF(detailout) WRITE(6,'(3X,A,2F15.5)') 'position :',oi(inum), oj(inum)\n \n END DO Obs_Loop_1\n ! ================================================================\n ! ACCURATE MODE\n ! ================================================================ \n ELSE IF(msw == 2) THEN\n ! ================================================================\n ! Nearest 4 Grid Points Interpolation\n ! ================================================================ \n Obs_Loop_2 : DO inum=1,num_obs\n IF(detailout) WRITE(6,'(A,I5,2F15.5)') '*** START OBS ',inum,olon(inum),olat(inum) \n ! ------------------------------------------------------------\n ! Search 4-Grid Points\n ! ------------------------------------------------------------ \n dist(1:num_grid_ave) = 1.D+10\n wk_maxp = num_grid_ave \n DO jy=1,ny\n DO ix=1,nx\n CALL com_distll_1(flon(ix,jy),flat(ix,jy),&\n & olon(inum) ,olat(inum) ,wk_dist)\n IF(wk_dist > max_dist) CYCLE\n IF(wk_dist < dist(wk_maxp)) THEN\n dist(wk_maxp) = wk_dist\n dist_min_x(inum, wk_maxp) = ix\n dist_min_y(inum, wk_maxp) = jy\n DO ip = 1, num_grid_ave\n IF(dist(ip) == maxval(dist(1:num_grid_ave))) THEN\n wk_maxp = ip\n EXIT\n END IF\n END DO\n END IF\n END DO\n END DO\n IF(detailout) WRITE(6,'(A,4(A,I4,A,I4,A))') ' Intp Grids : ', &\n & '(', INT(dist_min_x(inum, 1)), ',', INT(dist_min_y(inum, 1)), ') ', &\n & '(', INT(dist_min_x(inum, 2)), ',', INT(dist_min_y(inum, 2)), ') ', &\n & '(', INT(dist_min_x(inum, 3)), ',', INT(dist_min_y(inum, 3)), ') ', &\n & '(', INT(dist_min_x(inum, 4)), ',', INT(dist_min_y(inum, 4)), ') '\n ! ------------------------------------------------------------\n ! Interpolation\n ! ------------------------------------------------------------ \n dist(1:num_grid_ave) = dist(1:num_grid_ave) * 1.0D-3\n sum_dist = dist(1) * dist(1) * dist(2) * dist(2) * dist(3) * dist(3) &\n & + dist(2) * dist(2) * dist(3) * dist(3) * dist(4) * dist(4) &\n & + dist(3) * dist(3) * dist(4) * dist(4) * dist(1) * dist(1) &\n & + dist(4) * dist(4) * dist(1) * dist(1) * dist(2) * dist(2)\n ratio(1) = (dist(2)*dist(2)*dist(3)*dist(3)*dist(4)*dist(4))/sum_dist\n ratio(2) = (dist(3)*dist(3)*dist(4)*dist(4)*dist(1)*dist(1))/sum_dist\n ratio(3) = (dist(4)*dist(4)*dist(1)*dist(1)*dist(2)*dist(2))/sum_dist\n ratio(4) = (dist(1)*dist(1)*dist(2)*dist(2)*dist(3)*dist(3))/sum_dist\n IF(detailout) WRITE(6,'(2X,A,5F15.5)') 'ratio :',ratio(1:4),SUM(ratio(1:4))\n oi(inum) = SUM(ratio(1:num_grid_ave) * dist_min_x(inum, 1:num_grid_ave))\n oj(inum) = SUM(ratio(1:num_grid_ave) * dist_min_y(inum, 1:num_grid_ave))\n IF(detailout) WRITE(6,'(2X,A,2F15.5)') 'position :',oi(inum),oj(inum)\n END DO Obs_Loop_2\n END IF\n\n RETURN\nEND SUBROUTINE com_pos2ij\n!-----------------------------------------------------------------------\n! UTC to TAI93\n!-----------------------------------------------------------------------\nSUBROUTINE com_utc2tai(iy,im,id,ih,imin,sec,tai93)\n IMPLICIT NONE\n INTEGER,INTENT(IN) :: iy,im,id,ih,imin\n REAL(r_size),INTENT(IN) :: sec\n REAL(r_size),INTENT(OUT) :: tai93\n REAL(r_size),PARAMETER :: mins = 60.0d0\n REAL(r_size),PARAMETER :: hour = 60.0d0*mins\n REAL(r_size),PARAMETER :: day = 24.0d0*hour\n REAL(r_size),PARAMETER :: year = 365.0d0*day\n INTEGER,PARAMETER :: mdays(12) = (/31,28,31,30,31,30,31,31,30,31,30,31/)\n INTEGER :: days,i\n\n tai93 = REAL(iy-1993,r_size)*year + FLOOR(REAL(iy-1993)/4.0,r_size)*day\n days = id -1\n DO i=1,12\n IF(im > i) days = days + mdays(i)\n END DO\n IF(MOD(iy,4) == 0 .AND. im > 2) days = days + 1 !leap year\n tai93 = tai93 + REAL(days,r_size)*day + REAL(ih,r_size)*hour &\n & + REAL(imin,r_size)*mins + sec\n IF(iy > 1993 .OR. (iy==1993 .AND. im > 6)) tai93 = tai93 + 1.0d0 !leap second\n IF(iy > 1994 .OR. (iy==1994 .AND. im > 6)) tai93 = tai93 + 1.0d0 !leap second\n IF(iy > 1995) tai93 = tai93 + 1.0d0 !leap second\n IF(iy > 1997 .OR. (iy==1997 .AND. im > 6)) tai93 = tai93 + 1.0d0 !leap second\n IF(iy > 1998) tai93 = tai93 + 1.0d0 !leap second\n IF(iy > 2005) tai93 = tai93 + 1.0d0 !leap second\n IF(iy > 2008) tai93 = tai93 + 1.0d0 !leap second\n IF(iy > 2012 .OR. (iy==2012 .AND. im > 6)) tai93 = tai93 + 1.0d0 !leap second\n\n RETURN\nEND SUBROUTINE com_utc2tai\n!-----------------------------------------------------------------------\n! TAI93 to UTC\n!-----------------------------------------------------------------------\nSUBROUTINE com_tai2utc(tai93,iy,im,id,ih,imin,sec)\n IMPLICIT NONE\n INTEGER,PARAMETER :: n=8 ! number of leap seconds after Jan. 1, 1993\n INTEGER,PARAMETER :: leapsec(n) = (/ 15638399, 47174400, 94608001,&\n & 141868802, 189302403, 410227204,&\n & 504921605, 615254406/)\n REAL(r_size),INTENT(IN) :: tai93\n INTEGER,INTENT(OUT) :: iy,im,id,ih,imin\n REAL(r_size),INTENT(OUT) :: sec\n REAL(r_size),PARAMETER :: mins = 60.0d0\n REAL(r_size),PARAMETER :: hour = 60.0d0*mins\n REAL(r_size),PARAMETER :: day = 24.0d0*hour\n REAL(r_size),PARAMETER :: year = 365.0d0*day\n INTEGER,PARAMETER :: mdays(12) = (/31,28,31,30,31,30,31,31,30,31,30,31/)\n REAL(r_size) :: wk,tai\n INTEGER :: days,i,leap\n\n tai = tai93\n sec = 0.0d0\n DO i=1,n\n IF(FLOOR(tai93) == leapsec(i)+1) sec = 60.0d0 + tai93-FLOOR(tai93,r_size)\n IF(FLOOR(tai93) > leapsec(i)) tai = tai -1.0d0\n END DO\n iy = 1993 + FLOOR(tai /year)\n wk = tai - REAL(iy-1993,r_size)*year - FLOOR(REAL(iy-1993)/4.0,r_size)*day\n IF(wk < 0.0d0) THEN\n iy = iy -1\n wk = tai - REAL(iy-1993,r_size)*year - FLOOR(REAL(iy-1993)/4.0,r_size)*day\n END IF\n days = FLOOR(wk/day)\n wk = wk - REAL(days,r_size)*day\n im = 1\n DO i=1,12\n leap = 0\n IF(im == 2 .AND. MOD(iy,4)==0) leap=1\n IF(im == i .AND. days >= mdays(i)+leap) THEN\n im = im + 1\n days = days - mdays(i)-leap\n END IF\n END DO\n id = days +1\n\n ih = FLOOR(wk/hour)\n wk = wk - REAL(ih,r_size)*hour\n imin = FLOOR(wk/mins)\n IF(sec < 60.0d0) sec = wk - REAL(imin,r_size)*mins\n\n RETURN\nEND SUBROUTINE com_tai2utc\n!-----------------------------------------------------------------------\n! Date and time regulation\n!-----------------------------------------------------------------------\nSUBROUTINE com_datetime_reg(iy,im,id,ih,imin,isec)\n IMPLICIT NONE\n INTEGER, INTENT(INOUT) :: iy,im,id,ih,imin,isec\n INTEGER :: mdays\n\n DO WHILE(im <= 0)\n im = im + 12\n iy = iy - 1\n END DO\n DO WHILE(im > 12)\n im = im - 12\n iy = iy + 1\n END DO\n DO WHILE(isec < 0)\n isec = isec + 60\n imin = imin - 1\n END DO\n DO WHILE(isec >= 60)\n isec = isec - 60\n imin = imin + 1\n END DO\n DO WHILE(imin < 0)\n imin = imin + 60\n ih = ih - 1\n END DO\n DO WHILE(imin >= 60)\n imin = imin - 60\n ih = ih + 1\n END DO\n DO WHILE(ih < 0)\n ih = ih + 24\n id = id - 1\n END DO\n DO WHILE(ih >= 24)\n ih = ih - 24\n id = id + 1\n END DO\n DO WHILE(id <= 0)\n im = im - 1\n IF(im <= 0) THEN\n im = im + 12\n iy = iy - 1\n END IF\n CALL com_mdays(iy,im,mdays)\n id = id + mdays\n END DO\n CALL com_mdays(iy,im,mdays)\n DO WHILE(id > mdays)\n id = id - mdays\n im = im + 1\n IF(im > 12) THEN\n im = im - 12\n iy = iy + 1\n END IF\n CALL com_mdays(iy,im,mdays)\n END DO\n\n RETURN\nEND SUBROUTINE com_datetime_reg\n!-----------------------------------------------------------------------\n! Number of days of the month\n!-----------------------------------------------------------------------\nSUBROUTINE com_mdays(iy,im,mdays)\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: iy,im\n INTEGER, INTENT(OUT) :: mdays\n\n SELECT CASE(im)\n CASE(1,3,5,7,8,10,12)\n mdays = 31\n CASE(4,6,9,11)\n mdays = 30\n CASE(2)\n mdays = 28\n IF(MOD(iy,100) == 0) THEN\n IF(MOD(iy,400) == 0) THEN\n mdays = 29\n END IF\n ELSE IF(MOD(iy,4) == 0) THEN\n mdays = 29\n END IF\n CASE DEFAULT\n WRITE(6,'(A)') '[Error] com_mdays: invalid month.'\n STOP\n END SELECT\nEND SUBROUTINE com_mdays\n\n!-----------------------------------------------------------------------\n! GAMMA FUNCTION\n!-----------------------------------------------------------------------\n\n!==================================================\n! Purpose: Compute the gamma function \u00e2(x)\n! Input : x --- Argument of \u00e2(x)\n! ( x is not equal to 0,-1,-2,\u00fa\u00fa\u00fa )\n! Output: GA --- \u00e2(x)\n!==================================================\n! Proff. Jianming Jin\n! Department of Electrical and Computer Engineering\n! University of Illinois\n\nSUBROUTINE com_gamma(x,ga)\n\n IMPLICIT NONE\n REAL(r_size) :: X , GA\n REAL(r_size) :: G(26)\n REAL(r_size) :: Z , R , GR\n INTEGER :: M1, K , M\n\n !DIMENSION G(26)\n IF (X.EQ.INT(X)) THEN\n IF (X.GT.0.0D0) THEN\n GA=1.0D0\n M1=X-1\n DO 10 K=2,M1\n10 GA=GA*K\n ELSE\n GA=1.0D+300\n ENDIF\n ELSE\n IF (DABS(X).GT.1.0D0) THEN\n Z=DABS(X)\n M=INT(Z)\n R=1.0D0\n DO 15 K=1,M\n15 R=R*(Z-K)\n Z=Z-M\n ELSE\n Z=X\n ENDIF\n DATA G/1.0D0,0.5772156649015329D0, &\n -0.6558780715202538D0, -0.420026350340952D-1, &\n 0.1665386113822915D0,-.421977345555443D-1, &\n -.96219715278770D-2, .72189432466630D-2, &\n -.11651675918591D-2, -.2152416741149D-3, &\n .1280502823882D-3, -.201348547807D-4, &\n -.12504934821D-5, .11330272320D-5, &\n -.2056338417D-6, .61160950D-8, &\n .50020075D-8, -.11812746D-8, &\n .1043427D-9, .77823D-11, &\n -.36968D-11, .51D-12, &\n -.206D-13, -.54D-14, .14D-14, .1D-15/\n GR=G(26)\n DO 20 K=25,1,-1\n20 GR=GR*Z+G(K)\n GA=1.0D0/(GR*Z)\n IF (DABS(X).GT.1.0D0) THEN\n GA=GA*R\n IF (X.LT.0.0D0) GA=-PI/(X*GA*DSIN(PI*X))\n ENDIF\n ENDIF\n RETURN\nEND SUBROUTINE com_gamma\n\n!-----------------------------------------------------------------------\n! Lon , lat moving in a certain direction.\n!-----------------------------------------------------------------------\n\n!-------------------------------------------------------------------------------------\n! Compute the lat and lon reached by moving a certain distance in a certain direction\n! Formula from Map Projections - a working manual. USGS paper\n! 1395. Equations (5-5) and (5-6).\n!-------------------------------------------------------------------------------------\n! Note: This routine should be moved to the common module\n! Input azimuth in degrees with respect to North\n! Input distance in meters\n! Input and output lat lon in degrees\n\nSUBROUTINE com_ll_arc_distance(ini_lon,ini_lat,distance,azimuth,final_lon,final_lat)\nIMPLICIT NONE\nREAL(r_size), INTENT(IN) :: ini_lon,ini_lat,distance,azimuth\nREAL(r_size), INTENT(OUT) :: final_lon,final_lat\nREAL(r_size) :: cdist,sdist,sinll1,cosll1\n\n\n IF ( distance .EQ. 0d0 )THEN\n final_lon=ini_lon\n final_lat=ini_lat\n ELSE\n\n cdist = cos(distance/Re)\n sdist = sin(distance/Re)\n\n sinll1 = sin(ini_lat*deg2rad)\n cosll1 = cos(ini_lat*deg2rad)\n\n final_lat=asin(sinll1*cdist + cosll1*sdist*cos(azimuth*deg2rad))/deg2rad\n final_lon=ini_lon + (1/deg2rad)*atan2(sdist*sin(azimuth*deg2rad),cosll1*cdist - sinll1*sdist*cos(azimuth*deg2rad))\n\n ENDIF\nEND SUBROUTINE com_ll_arc_distance\n\nEND MODULE common\n", "meta": {"hexsha": "b5f54204fb0ed346556b288e5ae74c76ac603523", "size": 31568, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "data/prep/common.f90", "max_stars_repo_name": "f-tomizawa/RC_Analysis_Loren96", "max_stars_repo_head_hexsha": "f8ba9368acbaaeef6b7cdf337b4a7c21048a17e8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-06-27T09:57:17.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-04T02:56:34.000Z", "max_issues_repo_path": "data/prep/common.f90", "max_issues_repo_name": "f-tomizawa/RC_Analysis_Loren96", "max_issues_repo_head_hexsha": "f8ba9368acbaaeef6b7cdf337b4a7c21048a17e8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "data/prep/common.f90", "max_forks_repo_name": "f-tomizawa/RC_Analysis_Loren96", "max_forks_repo_head_hexsha": "f8ba9368acbaaeef6b7cdf337b4a7c21048a17e8", "max_forks_repo_licenses": ["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.1248688353, "max_line_length": 115, "alphanum_fraction": 0.4822288393, "num_tokens": 10636, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619436290698, "lm_q2_score": 0.7931059462938814, "lm_q1q2_score": 0.6538856699852261}} {"text": "! { dg-do run }\n! { dg-require-effective-target fortran_large_real }\n! { dg-require-effective-target fortran_large_int }\n!\n! PR fortran/41711\n!\n! Check reading and writing of real(10/16) BOZ,\n! which needs integer(16) support.\n!\nimplicit none\ncharacter(len=256) :: str\ninteger,parameter :: xp = selected_real_kind (precision (0.0d0)+1)\nreal(xp) :: r1,r2\ncomplex(xp) :: z1,z2\n\nr2 = 5.0_xp\nr1 = 2.0_xp\n! Real B(OZ)\nwrite(str,'(b128)') r1\nread (str,'(b128)') r2\nif(r2 /= r1) STOP 1\n! Real (B)O(Z)\nr2 = 5.0_xp\nwrite(str,'(o126)') r1\nread (str,'(o126)') r2\nif(r2 /= r1) STOP 2\n! Real (BO)Z\nr2 = 5.0_xp\nwrite(str,'(z126)') r1\nread (str,'(z126)') r2\nif(r2 /= r1) STOP 3\n\nz2 = cmplx(5.0_xp,7.0_xp)\nz1 = cmplx(2.0_xp,3.0_xp)\n! Complex B(OZ)\nwrite(str,'(2b128)') z1\nread (str,'(2b128)') z2\nif(z2 /= z1) STOP 4\n! Complex (B)O(Z)\nz2 = cmplx(5.0_xp,7.0_xp)\nwrite(str,'(2o126)') z1\nread (str,'(2o126)') z2\nif(z2 /= z1) STOP 5\n! Complex (BO)Z\nz2 = cmplx(5.0_xp,7.0_xp)\nwrite(str,'(2z126)') z1\nread (str,'(2z126)') z2\nif(z2 /= z1) STOP 6\nend\n", "meta": {"hexsha": "1045e9ffc70ef03e40f7050e80977ca4926d8e6c", "size": 1029, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/boz_15.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/boz_15.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/boz_15.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": 20.58, "max_line_length": 66, "alphanum_fraction": 0.6336248785, "num_tokens": 483, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.793105951184112, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.653885665465123}} {"text": "function add(x, y)\n real :: x\n real :: y\n real :: add\n add = x + y \nend function add\n\nprogram t\n\n real :: r\n r = add(10.55, 5.1010)\n print *, r\n\nend program t\n", "meta": {"hexsha": "5d7381b221e7d4e58d75571345a9dbb0ba03c7b7", "size": 167, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/output_tests/func_out1.f90", "max_stars_repo_name": "clementval/fc", "max_stars_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/output_tests/func_out1.f90", "max_issues_repo_name": "clementval/fc", "max_issues_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/output_tests/func_out1.f90", "max_forks_repo_name": "clementval/fc", "max_forks_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "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": 11.1333333333, "max_line_length": 24, "alphanum_fraction": 0.5508982036, "num_tokens": 65, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.793105941403651, "lm_q2_score": 0.8244619350028204, "lm_q1q2_score": 0.6538856591118876}} {"text": " subroutine ksol(nright,neq,nsb,a,r,s,ising)\r\nc-----------------------------------------------------------------------\r\nc\r\nc Solution of a System of Linear Equations\r\nc ****************************************\r\nc\r\nc\r\nc\r\nc INPUT VARIABLES:\r\nc\r\nc nright,nsb number of columns in right hand side matrix.\r\nc for KB2D: nright=1, nsb=1\r\nc neq number of equations\r\nc a() upper triangular left hand side matrix (stored \r\nc columnwise)\r\nc r() right hand side matrix (stored columnwise)\r\nc for kb2d, one column per variable\r\nc\r\nc\r\nc\r\nc OUTPUT VARIABLES:\r\nc\r\nc s() solution array, same dimension as r above.\r\nc ising singularity indicator\r\nc 0, no singularity problem\r\nc -1, neq .le. 1\r\nc k, a null pivot appeared at the kth iteration\r\nc\r\nc\r\nc\r\nc PROGRAM NOTES:\r\nc\r\nc 1. Requires the upper triangular left hand side matrix.\r\nc 2. Pivots are on the diagonal.\r\nc 3. Does not search for max. element for pivot.\r\nc 4. Several right hand side matrices possible.\r\nc 5. USE for ok and sk only, NOT for UK.\r\nc\r\nc\r\nc-----------------------------------------------------------------------\r\n implicit real*8 (a-h,o-z)\r\n real*8 a(*),r(*),s(*)\r\nc\r\nc If there is only one equation then set ising and return:\r\nc\r\n if(neq.le.1) then\r\n ising = -1\r\n return\r\n endif\r\nc\r\nc Initialize:\r\nc\r\n tol = 0.1e-06\r\n ising = 0\r\n nn = neq*(neq+1)/2\r\n nm = nsb*neq\r\n m1 = neq-1\r\n kk = 0\r\nc\r\nc Start triangulation:\r\nc\r\n do k=1,m1\r\n kk=kk+k\r\n ak=a(kk)\r\n if(abs(ak).lt.tol) then\r\n ising=k\r\n return\r\n endif\r\n km1=k-1\r\n do iv=1,nright\r\n nm1=nm*(iv-1)\r\n ii=kk+nn*(iv-1)\r\n piv=1./a(ii)\r\n lp=0\r\n do i=k,m1\r\n ll=ii\r\n ii=ii+i\r\n ap=a(ii)*piv\r\n lp=lp+1\r\n ij=ii-km1\r\n do j=i,m1\r\n ij=ij+j\r\n ll=ll+j\r\n a(ij)=a(ij)-ap*a(ll)\r\n end do\r\n do llb=k,nm,neq\r\n in=llb+lp+nm1\r\n ll1=llb+nm1\r\n r(in)=r(in)-ap*r(ll1)\r\n end do\r\n end do\r\n end do\r\n end do\r\nc\r\nc Error checking - singular matrix:\r\nc\r\n ijm=ij-nn*(nright-1)\r\n if(abs(a(ijm)).lt.tol) then\r\n ising=neq\r\n return\r\n endif\r\nc\r\nc Finished triangulation, start solving back:\r\nc\r\n do iv=1,nright\r\n nm1=nm*(iv-1)\r\n ij=ijm+nn*(iv-1)\r\n piv=1./a(ij)\r\n do llb=neq,nm,neq\r\n ll1=llb+nm1\r\n s(ll1)=r(ll1)*piv\r\n end do\r\n i=neq\r\n kk=ij\r\n do ii=1,m1\r\n kk=kk-i\r\n piv=1./a(kk)\r\n i=i-1\r\n do llb=i,nm,neq\r\n ll1=llb+nm1\r\n in=ll1\r\n ap=r(in)\r\n ij=kk\r\n do j=i,m1\r\n ij=ij+j\r\n in=in+1\r\n ap=ap-a(ij)*s(in)\r\n end do\r\n s(ll1)=ap*piv\r\n end do\r\n end do\r\n end do\r\nc\r\nc Finished solving back, return:\r\nc\r\n return\r\n end\r\n", "meta": {"hexsha": "0c2ac38544dffcfd8e3b5c56c66134d22201c5b2", "size": 3842, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/original/gslib/ksol.for", "max_stars_repo_name": "exepulveda/gslib2.0", "max_stars_repo_head_hexsha": "5c021000eb3da8703ced3ee9be145d6c0ecb2608", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-07-09T06:03:38.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T11:11:19.000Z", "max_issues_repo_path": "src/original/gslib/ksol.for", "max_issues_repo_name": "exepulveda/gslib2.0", "max_issues_repo_head_hexsha": "5c021000eb3da8703ced3ee9be145d6c0ecb2608", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/original/gslib/ksol.for", "max_forks_repo_name": "exepulveda/gslib2.0", "max_forks_repo_head_hexsha": "5c021000eb3da8703ced3ee9be145d6c0ecb2608", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.8405797101, "max_line_length": 73, "alphanum_fraction": 0.3599687663, "num_tokens": 967, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380482, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6538540777834513}} {"text": " subroutine SplineCub(x, y, d, n, type, A_d, A_sd, qdy, lll)\n*\n* PURPOSE\n* computes a cubic spline interpolation function\n* in Hermite form (ie computes the derivatives d(i) of the\n* spline in each interpolation point (x(i), y(i)))\n*\n* ARGUMENTS\n* inputs :\n* n number of interpolation points (n >= 3)\n* x, y the n interpolation points, x must be in strict increasing order\n* type type of the spline : currently \n* type = 0 correspond to a NOT_A_KNOT spline where it is\n* imposed the conditions :\n* s'''(x(2)-) = s'''(x(2)+) \n* and s'''(x(n-1)-) = s'''(x(n-1)+)\n* type = 1 correspond to a NATURAL spline with the conditions :\n* s''(x1) = 0\n* and s''(xn) = 0\n* type = 2 correspond to a CLAMPED spline (d(1) and d(n) are given)\n*\n* type = 3 correspond to a PERIODIC spline\n* outputs :\n* d the derivatives in each x(i) i = 1..n\n*\n* work arrays :\n* A_d(1..n), A_sd(1..n-1), qdy(1..n-1)\n* lll(1..n-1) (used only in the periodic case)\n*\n* NOTES\n* this routine requires (i) n >= 3 (for natural) n >=4 (for not_a_knot) \n* (ii) strict increasing abscissae x(i)\n* (iii) y(1) = y(n) in the periodic case\n* THESE CONDITIONS MUST BE TESTED IN THE CALLING CODE\n*\n* AUTHOR\n* Bruno Pincon\n*\n* July 22 2004 : correction of the case not_a_knot which worked only\n* for equidistant abscissae\n*\n implicit none\n\n integer n, type \n double precision x(n), y(n), d(n), A_d(n), A_sd(n-1), qdy(n-1), \n $ lll(n-1)\n\n include 'constinterp.h'\n integer i\n double precision r\n\n if (n .eq. 2) then\n if (type .ne. CLAMPED) then\n d(1) = (y(2) - y(1)) / (x(2) - x(1))\n d(2) = d(1)\n endif\n return\n endif\n\n if (n .eq. 3 .and. type .eq. NOT_A_KNOT) then\n call derivd(x, y, d, n, 1, FAST)\n return\n endif\n \n do i = 1, n-1\n A_sd(i) = 1.d0 / (x(i+1) - x(i))\n qdy(i) = (y(i+1) - y(i)) * A_sd(i)**2 \n enddo\n\n* compute the coef matrix and r.h.s. for rows 2..n-1 \n* (which don't relies on the type)\n do i = 2, n-1\n A_d(i) = 2.d0*( A_sd(i-1) + A_sd(i) )\n d(i) = 3.d0 * ( qdy(i-1) + qdy(i) )\n enddo\n\n* compute equ 1 and n in function of the type\n if (type .eq. NATURAL) then\n A_d(1) = 2.d0*A_sd(1)\n d(1) = 3.d0 * qdy(1)\n A_d(n) = 2.d0*A_sd(n-1)\n d(n) = 3.d0 * qdy(n-1)\n call TriDiagLDLtSolve(A_d, A_sd, d, n)\n\n else if (type .eq. NOT_A_KNOT) then\n ! s'''(x(2)-) = s'''(x(2)+)\n r = A_sd(2)/A_sd(1)\n A_d(1) = A_sd(1)/(1.d0 + r)\n d(1) = ((3.d0*r+2.d0)*qdy(1)+r*qdy(2))/(1.d0+r)**2\n ! s'''(x(n-1)-) = s'''(x(n-1)+)\n r = A_sd(n-2)/A_sd(n-1)\n A_d(n) = A_sd(n-1)/(1.d0 + r)\n d(n) = ((3.d0*r+2.d0)*qdy(n-1)+r*qdy(n-2))/(1.d0+r)**2\n call TriDiagLDLtSolve(A_d, A_sd, d, n)\n\n else if (type .eq. CLAMPED) then\n ! d(1) and d(n) are already known \n d(2) = d(2) - d(1)*A_sd(1)\n d(n-1) = d(n-1) - d(n)*A_sd(n-1)\n call TriDiagLDLtSolve(A_d(2), A_sd(2), d(2), n-2)\n\n else if (type .eq. PERIODIC) then\n A_d(1) = 2.d0*( A_sd(1) + A_sd(n-1) )\n d(1) = 3.d0 * ( qdy(1) + qdy(n-1) )\n lll(1) = A_sd(n-1)\n call dset(n-2, 0.d0, lll(2),1) ! mise a zero\n lll(n-2) = A_sd(n-2)\n call CyclicTriDiagLDLtSolve(A_d, A_sd, lll, d, n-1)\n d(n) = d(1)\n\n endif\n \n end ! subroutine SplineCub\n\n\n subroutine TriDiagLDLtSolve(d, l, b, n)\n*\n* PURPOSE\n* solve a linear system A x = b with a symetric tridiagonal positive definite\n* matrix A by using an LDL^t factorization\n* \n* PARAMETERS\n* d(1..n) : on input the diagonal of A\n* on output the diagonal of the (diagonal) matrix D\n* l(1..n-1) : on input the sub-diagonal of A\n* on output the sub-diagonal of L\n* b(1..n) : on input contains the r.h.s. b\n* on output the solution x\n* n : the dimension \n*\n* CAUTION \n* no zero pivot detection\n*\n implicit none\n integer n\n double precision d(n), l(n-1), b(n)\n\n integer i\n double precision temp \n\n do i = 2, n\n temp = l(i-1)\n l(i-1) = l(i-1) / d(i-1)\n d(i) = d(i) - temp * l(i-1)\n b(i) = b(i) - l(i-1)*b(i-1)\n enddo\n\n b(n) = b(n) / d(n)\n do i = n-1, 1, -1\n b(i) = b(i)/d(i) - l(i)*b(i+1)\n enddo\n\n end ! subroutine TriDiagLDLtSolve\n\n subroutine CyclicTriDiagLDLtSolve(d, lsd, lll, b, n)\n*\n* PURPOSE\n* solve a linear system A x = b with a symetric \"nearly\" tridiagonal \n* positive definite matrix A by using an LDL^t factorization, \n* the matrix A has the form :\n* \n* |x x x| |1 |\n* |x x x | |x 1 |\n* | x x x | | x 1 |\n* | x x x | and so the L is like | x 1 |\n* | x x x | | x 1 |\n* | x x x| | x 1 |\n* |x x x| |x x x x x x 1|\n*\n* PARAMETERS\n* d(1..n) : on input the diagonal of A\n* on output the diagonal of the (diagonal) matrix D\n* lsd(1..n-2) : on input the sub-diagonal of A (without A(n,n-1)) \n* on output the sub-diagonal of L (without L(n,n-1))\n* lll(1..n-1) : on input the last line of A (without A(n,n))\n* on output the last line of L (without L(n,n))\n* b(1..n) : on input contains the r.h.s. b\n* on output the solution x\n* n : the dimension \n*\n* CAUTION \n* no zero pivot detection\n*\n implicit none\n integer n\n double precision d(n), lsd(n-2), lll(n-1), b(n)\n \n integer i, j\n double precision temp1, temp2 \n\n* compute the LDL^t factorization\n do i = 1, n-2\n temp1 = lsd(i)\n temp2 = lll(i)\n lsd(i) = lsd(i) / d(i) ! elimination coef L(i,i-1)\n lll(i) = lll(i) / d(i) ! elimination coef L(n,i-1)\n \n d(i+1) = d(i+1) - lsd(i) * temp1 ! elimination on line i+1\n lll(i+1) = lll(i+1) - lll(i) * temp1 ! elimination on line n\n d(n) = d(n) - lll(i) * temp2 ! elimination on line n \n enddo\n temp2 = lll(n-1)\n lll(n-1) = lll(n-1) / d(n-1)\n d(n) = d(n) - lll(n-1) * temp2\n\n* solve LDL^t x = b (but use b for x and for the intermediary vectors...)\n do i = 2, n-1\n b(i) = b(i) - lsd(i-1)*b(i-1)\n enddo\n do j = 1, n-1\n b(n) = b(n) - lll(j)*b(j)\n enddo\n \n do i = 1, n\n b(i) = b(i) / d(i)\n enddo\n\n b(n-1) = b(n-1) - lll(n-1)*b(n)\n do i = n-2, 1, -1\n b(i) = b(i) - lsd(i)*b(i+1) - lll(i)*b(n)\n enddo\n\n end ! subroutine CyclicTriDiagLDLtSolve\n\n\n integer function isearch(t, x, n) \n*\n* PURPOSE\n* x(1..n) being an array (with strict increasing order and n >=2)\n* representing intervals, this routine return i such that :\n* \n* x(i) <= t <= x(i+1)\n* \n* and 0 if t is not in [x(1), x(n)] \n*\n implicit none\n integer n\n double precision t, x(n)\n\n integer i1, i2, i\n\n if ( x(1) .le. t .and. t .le. x(n)) then\n* dichotomic search\n i1 = 1\n i2 = n\n do while ( i2 - i1 .gt. 1 )\n i = (i1 + i2)/2\n if ( t .le. x(i) ) then\n i2 = i\n else\n i1 = i\n endif\n enddo\n isearch = i1\n else\n isearch = 0\n endif\n\n end\n\n subroutine EvalPWHermite(t, st, dst, d2st, d3st, m, x, y, d, n, \n $ outmode)\n*\n* PURPOSE\n* evaluation at the abscissae t(1..m) of the piecewise hermite function\n* define by x(1..n), y(1..n), d(1..n) (d being the derivatives at the\n* x(i)) together with its derivative, second derivative and third derivative\n* \n* PARAMETERS\n*\n* outmode : define what return in case t(j) not in [x(1), x(n)]\n\n implicit none\n integer m, n, outmode\n double precision t(m), st(m), dst(m), d2st(m), d3st(m), \n $ x(n), y(n), d(n)\n \n include 'constinterp.h'\n integer i, j\n integer isearch, isanan\n external isearch, isanan\n double precision tt\n double precision return_a_nan\n external return_a_nan \n logical new_call \n common /INFO_HERMITE/new_call\n\n new_call = .true.\n i = 0\n do j = 1, m\n tt = t(j)\n call fast_int_search(tt, x, n, i) ! recompute i only if necessary\n\n if ( i .ne. 0 ) then\n call EvalHermite(tt, x(i), x(i+1), y(i), y(i+1), d(i), \n $ d(i+1), st(j), dst(j), d2st(j), d3st(j), i)\n\n else ! t(j) is outside [x(1), x(n)] evaluation depend upon outmode \n\n if (outmode .eq. BY_NAN .or. isanan(tt) .eq. 1) then \n st(j) = return_a_nan()\n dst(j) = st(j)\n d2st(j) = st(j)\n d3st(j) = st(j)\n\n elseif (outmode .eq. BY_ZERO) then\n st(j) = 0.d0\n dst(j) = 0.d0\n d2st(j) = 0.d0\n d3st(j) = 0.d0\n\n elseif (outmode .eq. C0) then\n dst(j) = 0.d0\n d2st(j) = 0.d0\n d3st(j) = 0.d0\n if ( tt .lt. x(1) ) then\n st(j) = y(1)\n else\n st(j) = y(n)\n endif\n\n elseif (outmode .eq. LINEAR) then\n d2st(j) = 0.d0\n d3st(j) = 0.d0\n if ( tt .lt. x(1) ) then\n dst(j) = d(1)\n st(j) = y(1) + (tt - x(1))*d(1)\n else\n dst(j) = d(n)\n st(j) = y(n) + (tt - x(n))*d(n)\n endif\n\n else\n if (outmode .eq. NATURAL) then\n call near_interval(tt, x, n, i)\n elseif (outmode .eq. PERIODIC) then\n call coord_by_periodicity(tt, x, n, i)\n endif\n call EvalHermite(tt, x(i), x(i+1), y(i), y(i+1), d(i), \n $ d(i+1), st(j), dst(j), d2st(j), d3st(j), i)\n endif\n endif\n enddo\n \n end ! subroutine EvalPWHermite\n\n subroutine EvalHermite(t, xa, xb, ya, yb, da, db, h, dh, ddh, \n $ dddh, i)\n \n implicit none\n double precision t, xa, xb, ya, yb, da, db, h, dh, ddh, dddh\n integer i\n\n logical new_call \n common /INFO_HERMITE/new_call\n\n double precision tmxa, dx, p, c2, c3\n integer old_i\n save old_i, c2, c3\n data old_i/0/\n\n if (old_i .ne. i .or. new_call) then\n* compute the following Newton form : \n* h(t) = ya + da*(t-xa) + c2*(t-xa)^2 + c3*(t-xa)^2*(t-xb)\n dx = 1.d0/(xb - xa)\n p = (yb - ya) * dx\n c2 = (p - da) * dx\n c3 = ( (db - p) + (da - p) ) * (dx*dx)\n new_call = .false.\n endif\n old_i = i\n\n* eval h(t), h'(t), h\"(t) and h\"'(t), by a generalised Horner 's scheme\n tmxa = t - xa\n h = c2 + c3*(t - xb)\n dh = h + c3*tmxa\n ddh = 2.d0*( dh + c3*tmxa )\n dddh = 6.d0*c3\n h = da + h*tmxa\n dh = h + dh*tmxa\n h = ya + h*tmxa\n\n end ! subroutine EvalHermite\n\n subroutine fast_int_search(xx, x, nx, i)\n\n implicit none\n integer nx, i\n double precision xx, x(nx)\n\n integer isearch\n external isearch\n\n if ( i .eq. 0 ) then\n i = isearch(xx, x, nx)\n elseif ( .not. (x(i) .le. xx .and. xx .le. x(i+1))) then\n i = isearch(xx, x, nx)\n endif\n\n end\n\n subroutine coord_by_periodicity(t, x, n, i)\n*\n* PURPOSE\n* recompute t such that t in [x(1), x(n)] by periodicity :\n* and then the interval i of this new t\n*\n implicit none\n integer n, i\n double precision t, x(n)\n integer isearch\n external isearch\n\n double precision r, dx\n\n dx = x(n) - x(1)\n r = (t - x(1)) / dx\n\n if (r .ge. 0.d0) then\n t = x(1) + (r - aint(r))*dx\n else\n r = abs(r)\n t = x(n) - (r - aint(r))*dx\n endif\n\n ! some cautions in case of roundoff errors (is necessary ?)\n if (t .lt. x(1)) then\n t = x(1)\n i = 1\n else if (t .gt. x(n)) then\n t = x(n)\n i = n-1\n else\n i = isearch(t, x, n)\n endif\n\n end ! subroutine coord_by_periodicity\n\n\n subroutine near_grid_point(xx, x, nx, i)\n*\n* calcule le point de la grille le plus proche ... a detailler\n*\n implicit none\n integer i, nx\n double precision xx, x(nx)\n\n if (xx .lt. x(1)) then\n i = 1\n xx = x(1)\n else ! xx > x(nx)\n i = nx-1\n xx = x(nx)\n endif\n \n end\n\n subroutine near_interval(xx, x, nx, i)\n*\n* idem sans modifier xx\n*\n implicit none\n integer i, nx\n double precision xx, x(nx)\n\n if (xx .lt. x(1)) then\n i = 1\n else ! xx > x(nx)\n i = nx-1\n endif\n \n end\n\n subroutine proj_by_per(t, xmin, xmax)\n*\n* PURPOSE\n* recompute t such that t in [xmin, xmax] by periodicity.\n*\n implicit none\n double precision t, xmin, xmax\n double precision r, dx\n\n dx = xmax - xmin\n r = (t - xmin) / dx\n\n if (r .ge. 0.d0) then\n t = xmin + (r - aint(r))*dx\n else\n r = abs(r)\n t = xmax - (r - aint(r))*dx\n endif\n\n ! some cautions in case of roundoff errors (is necessary ?)\n if (t .lt. xmin) then\n t = xmin\n else if (t .gt. xmax) then\n t = xmax\n endif\n\n end ! subroutine proj_by_per\n\n\n subroutine proj_on_grid(xx, xmin, xmax)\n*\n implicit none\n double precision xx, xmin, xmax\n\n if (xx .lt. xmin) then\n xx = xmin\n else \n xx = xmax\n endif\n \n end\n\n double precision function return_a_nan()\n \n implicit none\n \n logical first\n double precision a, b\n save first\n data first /.true./\n \n data a /1.d0/, b /1.d0/\n save a\n\n if (first) then\n first = .false.\n a = (a - b) / (a - b)\n endif\n\n return_a_nan = a\n\n end\n\n\n subroutine BiCubicSubSpline(x, y, u, nx, ny, C, p, q, r, type)\n*\n* PURPOSE\n* compute bicubic subsplines\n*\n implicit none\n integer nx, ny, type\n double precision x(nx), y(ny), u(nx, ny), C(4,4,nx-1,ny-1),\n $ p(nx, ny), q(nx, ny), r(nx, ny)\n integer i, j\n include 'constinterp.h'\n\n if (type .eq. MONOTONE) then\n* approximation des derivees par SUBROUTINE DPCHIM(N,X,F,D,INCFD)\n ! p = du/dx\n do j = 1, ny\n call dpchim(nx, x, u(1,j), p(1,j), 1)\n enddo\n ! q = du/dy\n do i = 1, nx\n call dpchim(ny, y, u(i,1), q(i,1), nx)\n enddo\n ! r = d2 u/ dx dy approchee via dq / dx\n do j = 1, ny\n call dpchim(nx, x, q(1,j), r(1,j), 1)\n enddo\n\n elseif (type .eq. FAST .or. type .eq. FAST_PERIODIC) then\n* approximation des derivees partielles par methode simple\n\n ! p = du/dx\n do j = 1, ny\n call derivd(x, u(1,j), p(1,j), nx, 1, type)\n enddo\n ! q = du/dy\n do i = 1, nx\n call derivd(y, u(i,1), q(i,1), ny, nx, type)\n enddo\n ! r = d2 u/ dx dy approchee via dq / dx\n do j = 1, ny\n call derivd(x, q(1,j), r(1,j), nx, 1, type)\n enddo\n\n endif\n\n* calculs des coefficients dans les bases (x-x(i))^k (y-y(j))^l 0<= k,l <= 3\n* pour evaluation rapide via Horner par la suite\n call coef_bicubic(u, p, q, r, x, y, nx, ny, C)\n\n end ! subroutine BiCubicSubSpline\n\n subroutine BiCubicSpline(x, y, u, nx, ny, C, p, q, r, \n $ A_d, A_sd, d, ll, qdu, u_temp, type)\n*\n* PURPOSE\n* compute bicubic splines\n*\n implicit none\n integer nx, ny, type\n double precision x(nx), y(ny), u(nx, ny), C(4,4,nx-1,ny-1),\n $ p(nx, ny), q(nx, ny), r(nx, ny), A_d(*),\n $ A_sd(*), d(ny), ll(*), qdu(*), u_temp(ny) \n include 'constinterp.h'\n integer i, j\n\n ! compute du/dx\n do j = 1, ny\n call SplineCub(x, u(1,j), p(1,j), nx, type, A_d, A_sd, qdu, ll)\n enddo\n\n ! compute du/dy\n do i = 1, nx\n call dcopy(ny, u(i,1), nx, u_temp, 1) \n call SplineCub(y, u_temp, d, ny, type, A_d, A_sd, qdu, ll)\n call dcopy(ny, d, 1, q(i,1), nx)\n enddo\n\n ! compute ddu/dxdy\n call SplineCub(x, q(1,1), r(1,1), nx, type, A_d, A_sd, qdu, ll)\n call SplineCub(x, q(1,ny), r(1,ny), nx, type, A_d, A_sd, qdu, ll)\n\n do i = 1, nx\n call dcopy(ny, p(i,1), nx, u_temp, 1) \n d(1) = r(i,1)\n d(ny) = r(i,ny)\n call SplineCub(y, u_temp, d, ny, CLAMPED, A_d, A_sd, qdu, ll)\n call dcopy(ny-2, d(2), 1, r(i,2), nx)\n enddo\n\n* calculs des coefficients dans les bases (x-x(i))^k (y-y(j))^l 0<= k,l <= 3\n* pour evaluation rapide via Horner par la suite\n call coef_bicubic(u, p, q, r, x, y, nx, ny, C)\n\n end ! subroutine BiCubicSpline\n\n\n subroutine derivd(x, u, du, n, inc, type)\n*\n* PURPOSE\n* given functions values u(i) at points x(i), i = 1, ..., n\n* this subroutine computes approximations du(i) of the derivative\n* at the points x(i). \n*\n* METHOD\n* For i in [2,n-1], the \"centered\" formula of order 2 is used :\n* d(i) = derivative at x(i) of the interpolation polynomial\n* of the points {(x(j),u(j)), j in [i-1,i+1]}\n*\n* For i=1 and n, if type = FAST_PERIODIC (in which case u(n)=u(1)) then\n* the previus \"centered\" formula is also used else (type = FAST), d(1)\n* is the derivative at x(1) of the interpolation polynomial of\n* {(x(j),u(j)), j in [1,3]} and the same method is used for d(n)\n*\n* ARGUMENTS\n* inputs :\n* n integer : number of point (n >= 2)\n* x, u double precision : the n points, x must be in strict increasing order\n* type integer : FAST (the function is non periodic) or FAST_PERIODIC\n* (the function is periodic), in this last case u(n) must be equal to u(1))\n* inc integer : to deal easily with 2d applications, u(i) is in fact\n* u(1,i) with u declared as u(inc,*) to avoid the direct management of\n* the increment inc (the i th value given with u(1 + inc*(i-1) ...)\n* outputs :\n* d the derivatives in each x(i) i = 1..n\n*\n* NOTES\n* this routine requires (i) n >= 2\n* (ii) strict increasing abscissae x(i)\n* (iii) u(1)=u(n) if type = FAST_PERIODIC\n* ALL THESE CONDITIONS MUST BE TESTED IN THE CALLING CODE\n*\n* AUTHOR\n* Bruno Pincon\n*\n\n implicit none\n integer n, inc, type\n double precision x(n), u(inc,*), du(inc,*)\n\n include 'constinterp.h'\n double precision dx_l, du_l, dx_r, du_r, w_l, w_r\n integer i\n\n\n if (n .eq. 2) then ! special case used linear interp\n du(1,1) = (u(1,2) - u(1,1))/(x(2)-x(1))\n du(1,2) = du(1,1)\n return\n endif\n\n if (type .eq. FAST_PERIODIC) then\n\n dx_r = x(n)-x(n-1)\n du_r = (u(1,1) - u(1,n-1)) / dx_r\n do i = 1, n-1\n dx_l = dx_r\n du_l = du_r\n dx_r = x(i+1) - x(i)\n du_r = (u(1,i+1) - u(1,i))/dx_r\n w_l = dx_r/(dx_l + dx_r)\n w_r = 1.d0 - w_l\n du(1,i) = w_l*du_l + w_r*du_r\n enddo\n du(1,n) = du(1,1)\n\n else if (type .eq. FAST) then\n\n dx_l = x(2) - x(1)\n du_l = (u(1,2) - u(1,1))/dx_l\n dx_r = x(3) - x(2)\n du_r = (u(1,3) - u(1,2))/dx_r\n w_l = dx_r/(dx_l + dx_r)\n w_r = 1.d0 - w_l\n du(1,1) = (1.d0 + w_r)*du_l - w_r*du_r\n du(1,2) = w_l*du_l + w_r*du_r\n do i = 3, n-1\n dx_l = dx_r\n du_l = du_r\n dx_r = x(i+1) - x(i)\n du_r = (u(1,i+1) - u(1,i))/dx_r\n w_l = dx_r/(dx_l + dx_r)\n w_r = 1.d0 - w_l\n du(1,i) = w_l*du_l + w_r*du_r\n enddo\n du(1,n) = (1.d0 + w_l)*du_r - w_l*du_l\n \n endif\n\n end\n\n \n subroutine coef_bicubic(u, p, q, r, x, y, nx, ny, C)\n*\n* PURPOSE \n* compute for each polynomial (i,j)-patch (defined on \n* [x(i),x(i+1)]x[y(i),y(i+1)]) the following base\n* representation :\n* i,j _4_ _4_ i,j k-1 l-1\n* u (x,y) = >__ >__ C (x-x(i)) (y-y(j)) \n* k=1 l=1 k,l\n*\n* from the \"Hermite\" representation (values of u, p = du/dx,\n* q = du/dy, r = ddu/dxdy at the 4 vertices (x(i),y(j)),\n* (x(i+1),y(j)), (x(i+1),y(j+1)), (x(i),y(j+1)). \n*\n implicit none\n\n integer nx, ny\n double precision u(nx, ny), p(nx, ny), q(nx, ny), r(nx, ny),\n $ x(nx), y(ny), C(4,4,nx-1,ny-1)\n\n integer i, j\n double precision a, b, cc, d, dx, dy\n\n do j = 1, ny-1\n dy = 1.d0/(y(j+1) - y(j))\n\n do i = 1, nx-1\n dx = 1.d0/(x(i+1) - x(i))\n\n C(1,1,i,j) = u(i,j)\n C(2,1,i,j) = p(i,j)\n C(1,2,i,j) = q(i,j)\n C(2,2,i,j) = r(i,j)\n\n a = (u(i+1,j) - u(i,j))*dx\n C(3,1,i,j) = (3.d0*a -2.d0*p(i,j) - p(i+1,j))*dx\n C(4,1,i,j) = (p(i+1,j) + p(i,j) - 2.d0*a)*(dx*dx)\n\n a = (u(i,j+1) - u(i,j))*dy\n C(1,3,i,j) = (3.d0*a -2.d0*q(i,j) - q(i,j+1))*dy\n C(1,4,i,j) = (q(i,j+1) + q(i,j) - 2.d0*a)*(dy*dy)\n \n a = (q(i+1,j) - q(i,j))*dx\n C(3,2,i,j) = (3.d0*a - r(i+1,j) - 2.d0*r(i,j))*dx\n C(4,2,i,j) = (r(i+1,j) + r(i,j) - 2.d0*a)*(dx*dx)\n\n a = (p(i,j+1) - p(i,j))*dy\n C(2,3,i,j) = (3.d0*a - r(i,j+1) - 2.d0*r(i,j))*dy\n C(2,4,i,j) = (r(i,j+1) + r(i,j) - 2.d0*a)*(dy*dy)\n\n a = (u(i+1,j+1)+u(i,j)-u(i+1,j)-u(i,j+1))*(dx*dx*dy*dy)\n $ - (p(i,j+1)-p(i,j))*(dx*dy*dy)\n $ - (q(i+1,j)-q(i,j))*(dx*dx*dy)\n $ + r(i,j)*(dx*dy)\n b = (p(i+1,j+1)+p(i,j)-p(i+1,j)-p(i,j+1))*(dx*dy*dy)\n $ - (r(i+1,j)-r(i,j))*(dx*dy)\n cc = (q(i+1,j+1)+q(i,j)-q(i+1,j)-q(i,j+1))*(dx*dx*dy)\n $ - (r(i,j+1)-r(i,j))*(dx*dy)\n d = (r(i+1,j+1)+r(i,j)-r(i+1,j)-r(i,j+1))*(dx*dy)\n\n\n C(3,3,i,j) = 9.d0*a - 3.d0*b - 3.d0*cc + d\n C(3,4,i,j) =(-6.d0*a + 2.d0*b + 3.d0*cc - d)*dy\n C(4,3,i,j) =(-6.d0*a + 3.d0*b + 2.d0*cc - d)*dx\n C(4,4,i,j) =( 4.d0*a - 2.d0*b - 2.d0*cc + d)*dx*dy\n\n enddo\n enddo\n end\n\n double precision function EvalBicubic(xx, yy, xk, yk, Ck)\n\n implicit none\n double precision xx, yy, xk, yk, Ck(4,4)\n\n double precision dx, dy, u\n integer i\n\n dx = xx - xk\n dy = yy - yk\n\n u = 0.d0\n do i = 4, 1, -1\n u = Ck(i,1) + dy*(Ck(i,2) + dy*(Ck(i,3) + dy*Ck(i,4))) + u*dx\n enddo\n EvalBicubic = u\n\n end ! function EvalBicubic\n \n subroutine EvalBicubic_with_grad(xx, yy, xk, yk, Ck, \n $ u, dudx, dudy)\n\n implicit none\n double precision xx, yy, xk, yk, Ck(4,4), u, dudx, dudy\n\n double precision dx, dy\n integer i\n\n dx = xx - xk\n dy = yy - yk\n u = 0.d0\n dudx = 0.d0\n dudy = 0.d0\n do i = 4, 1, -1\n u = Ck(i,1) + dy*(Ck(i,2) + dy*(Ck(i,3) + dy*Ck(i,4))) + u*dx\n dudx = Ck(2,i)+dx*(2.d0*Ck(3,i) + dx*3.d0*Ck(4,i)) + dudx*dy\n dudy = Ck(i,2)+dy*(2.d0*Ck(i,3) + dy*3.d0*Ck(i,4)) + dudy*dx\n enddo\n\n end ! subroutine EvalBicubic_with_grad\n \n \n subroutine EvalBicubic_with_grad_and_hes(xx, yy, xk, yk, Ck, \n $ u, dudx, dudy, \n $ d2udx2, d2udxy, d2udy2)\n\n implicit none\n double precision xx, yy, xk, yk, Ck(4,4), u, dudx, dudy, d2udx2,\n $ d2udxy, d2udy2\n\n double precision dx, dy\n integer i\n\n dx = xx - xk\n dy = yy - yk\n u = 0.d0\n dudx = 0.d0\n dudy = 0.d0\n d2udx2 = 0.d0\n d2udy2 = 0.d0\n d2udxy = 0.d0\n do i = 4, 1, -1\n u = Ck(i,1) + dy*(Ck(i,2) + dy*(Ck(i,3) + dy*Ck(i,4))) + u*dx\n dudx = Ck(2,i)+dx*(2.d0*Ck(3,i) + dx*3.d0*Ck(4,i)) + dudx*dy\n dudy = Ck(i,2)+dy*(2.d0*Ck(i,3) + dy*3.d0*Ck(i,4)) + dudy*dx\n d2udx2 = 2.d0*Ck(3,i) + dx*6.d0*Ck(4,i) + d2udx2*dy\n d2udy2 = 2.d0*Ck(i,3) + dy*6.d0*Ck(i,4) + d2udy2*dx\n enddo\n d2udxy = Ck(2,2)+dy*(2.d0*Ck(2,3)+dy*3.d0*Ck(2,4))\n . + dx*(2.d0*(Ck(3,2)+dy*(2.d0*Ck(3,3)+dy*3.d0*Ck(3,4)))\n . + dx*(3.d0*(Ck(4,2)+dy*(2.d0*Ck(4,3)+dy*3.d0*Ck(4,4)))))\n end ! subroutine EvalBicubic_with_grad_and_hes\n \n \n subroutine BiCubicInterp(x, y, C, nx, ny, x_eval, y_eval, z_eval, \n $ m, outmode)\n*\n* PURPOSE\n* bicubic interpolation :\n* the grid is defined by x(1..nx), y(1..ny)\n* the known values are z(1..nx,1..ny), (z(i,j) being the value \n* at point (x(i),y(j))) \n* the interpolation is done on the points x_eval,y_eval(1..m)\n* z_eval(k) is the result of the bicubic interpolation of \n* (x_eval(k), y_eval(k)) \n*\n implicit none\n integer nx, ny, m, outmode\n double precision x(nx), y(ny), C(4,4,nx-1,ny-1), \n $ x_eval(m), y_eval(m), z_eval(m)\n \n double precision xx, yy\n integer i, j, k\n include 'constinterp.h'\n integer isanan\n double precision return_a_nan, EvalBicubic\n external isanan, return_a_nan, EvalBicubic\n\n i = 0\n j = 0\n do k = 1, m\n xx = x_eval(k)\n call fast_int_search(xx, x, nx, i) \n yy = y_eval(k)\n call fast_int_search(yy, y, ny, j) \n \n if (i .ne. 0 .and. j .ne. 0) then\n z_eval(k) = EvalBicubic(xx, yy, x(i), y(j), C(1,1,i,j))\n\n elseif (outmode .eq. BY_NAN .or. isanan(xx) .eq. 1\n $ .or. isanan(yy) .eq. 1) then\n z_eval(k) = return_a_nan()\n\n elseif (outmode .eq. BY_ZERO) then\n z_eval(k) = 0.d0\n\n elseif (outmode .eq. PERIODIC) then\n if (i .eq. 0) call coord_by_periodicity(xx, x, nx, i)\n if (j .eq. 0) call coord_by_periodicity(yy, y, ny, j)\n z_eval(k) = EvalBicubic(xx, yy, x(i), y(j), C(1,1,i,j))\n\n elseif (outmode .eq. C0) then\n if (i .eq. 0) call near_grid_point(xx, x, nx, i)\n if (j .eq. 0) call near_grid_point(yy, y, ny, j)\n z_eval(k) = EvalBicubic(xx, yy, x(i), y(j), C(1,1,i,j))\n\n elseif (outmode .eq. NATURAL) then\n if (i .eq. 0) call near_interval(xx, x, nx, i)\n if (j .eq. 0) call near_interval(yy, y, ny, j)\n z_eval(k) = EvalBicubic(xx, yy, x(i), y(j), C(1,1,i,j))\n endif\n\n enddo\n\n end\n\n subroutine BiCubicInterpWithGrad(x, y, C, nx, ny, x_eval, y_eval, \n $ z_eval, dzdx_eval, dzdy_eval,m, \n $ outmode)\n*\n* PURPOSE\n* bicubic interpolation :\n* the grid is defined by x(1..nx), y(1..ny)\n* the known values are z(1..nx,1..ny), (z(i,j) being the value \n* at point (x(i),y(j))) \n* the interpolation is done on the points x_eval,y_eval(1..m)\n* z_eval(k) is the result of the bicubic interpolation of \n* (x_eval(k), y_eval(k)) and dzdx_eval(k), dzdy_eval(k) is the gradient\n*\n implicit none\n integer nx, ny, m, outmode\n double precision x(nx), y(ny), C(4,4,nx-1,ny-1), \n $ x_eval(m), y_eval(m), z_eval(m), \n $ dzdx_eval(m), dzdy_eval(m)\n \n double precision xx, yy\n integer k, i, j\n include 'constinterp.h'\n integer isanan\n double precision return_a_nan, EvalBicubic\n external isanan, return_a_nan, EvalBicubic\n logical change_dzdx, change_dzdy\n\n i = 0\n j = 0\n do k = 1, m\n xx = x_eval(k)\n call fast_int_search(xx, x, nx, i) \n yy = y_eval(k)\n call fast_int_search(yy, y, ny, j) \n \n if (i .ne. 0 .and. j .ne. 0) then\n call Evalbicubic_with_grad(xx, yy, x(i), y(j), C(1,1,i,j),\n $ z_eval(k), \n $ dzdx_eval(k), dzdy_eval(k))\n\n elseif ( outmode .eq. BY_NAN .or. isanan(xx) .eq. 1\n $ .or. isanan(yy) .eq. 1) then\n z_eval(k) = return_a_nan()\n dzdx_eval(k) = z_eval(k)\n dzdy_eval(k) = z_eval(k)\n\n elseif (outmode .eq. BY_ZERO ) then\n z_eval(k) = 0.d0\n dzdx_eval(k) = 0.d0\n dzdy_eval(k) = 0.d0\n\n elseif (outmode .eq. PERIODIC) then\n if (i .eq. 0) call coord_by_periodicity(xx, x, nx, i)\n if (j .eq. 0) call coord_by_periodicity(yy, y, ny, j)\n call Evalbicubic_with_grad(xx, yy, x(i), y(j), C(1,1,i,j),\n $ z_eval(k), \n $ dzdx_eval(k), dzdy_eval(k))\n\n elseif (outmode .eq. C0) then\n if (i .eq. 0) then\n call near_grid_point(xx, x, nx, i)\n change_dzdx = .true.\n else\n change_dzdx = .false.\n endif\n if (j .eq. 0) then\n call near_grid_point(yy, y, ny, j)\n change_dzdy = .true.\n else\n change_dzdy = .false.\n endif\n call Evalbicubic_with_grad(xx, yy, x(i), y(j), C(1,1,i,j),\n $ z_eval(k), \n $ dzdx_eval(k), dzdy_eval(k))\n if (change_dzdx) dzdx_eval(k) = 0.d0\n if (change_dzdy) dzdy_eval(k) = 0.d0\n\n elseif (outmode .eq. NATURAL) then\n if (i .eq. 0) call near_interval(xx, x, nx, i)\n if (j .eq. 0) call near_interval(yy, y, ny, j)\n call Evalbicubic_with_grad(xx, yy, x(i), y(j), C(1,1,i,j),\n $ z_eval(k), \n $ dzdx_eval(k), dzdy_eval(k))\n\n endif\n\n enddo\n\n end\n\n subroutine BiCubicInterpWithGradAndHes(x, y, C, nx, ny, \n $ x_eval, y_eval, z_eval, \n $ dzdx_eval, dzdy_eval, \n $ d2zdx2_eval, d2zdxy_eval, d2zdy2_eval,\n $ m, outmode)\n*\n* PURPOSE\n* bicubic interpolation :\n* the grid is defined by x(1..nx), y(1..ny)\n* the known values are z(1..nx,1..ny), (z(i,j) being the value \n* at point (x(i),y(j))) \n* the interpolation is done on the points x_eval,y_eval(1..m)\n* z_eval(k) is the result of the bicubic interpolation of \n* (x_eval(k), y_eval(k)), [dzdx_eval(k), dzdy_eval(k)] is the gradient\n* and [d2zdx2(k), d2zdxy(k), d2zdy2(k)] the Hessean\n*\n implicit none\n integer nx, ny, m, outmode\n double precision x(nx), y(ny), C(4,4,nx-1,ny-1), \n $ x_eval(m), y_eval(m), z_eval(m), dzdx_eval(m), \n $ dzdy_eval(m), d2zdx2_eval(m), d2zdxy_eval(m), d2zdy2_eval(m)\n \n double precision xx, yy\n integer k, i, j\n include 'constinterp.h'\n integer isanan\n double precision return_a_nan, EvalBicubic\n external isanan, return_a_nan, EvalBicubic\n logical change_dzdx, change_dzdy\n\n i = 0\n j = 0\n do k = 1, m\n xx = x_eval(k)\n call fast_int_search(xx, x, nx, i) \n yy = y_eval(k)\n call fast_int_search(yy, y, ny, j) \n \n if (i .ne. 0 .and. j .ne. 0) then\n call Evalbicubic_with_grad_and_hes(xx, yy, x(i), y(j), \n $ C(1,1,i,j), z_eval(k), \n $ dzdx_eval(k), dzdy_eval(k),\n $ d2zdx2_eval(k), d2zdxy_eval(k), d2zdy2_eval(k))\n\n elseif ( outmode .eq. BY_NAN .or. isanan(xx) .eq. 1\n $ .or. isanan(yy) .eq. 1) then\n z_eval(k) = return_a_nan()\n dzdx_eval(k) = z_eval(k)\n dzdy_eval(k) = z_eval(k)\n d2zdx2_eval(k) = z_eval(k)\n d2zdxy_eval(k) = z_eval(k)\n d2zdy2_eval(k) = z_eval(k)\n\n elseif (outmode .eq. BY_ZERO ) then\n z_eval(k) = 0.d0\n dzdx_eval(k) = 0.d0\n dzdy_eval(k) = 0.d0\n d2zdx2_eval(k) = 0.d0\n d2zdxy_eval(k) = 0.d0\n d2zdy2_eval(k) = 0.d0\n\n elseif (outmode .eq. PERIODIC) then\n if (i .eq. 0) call coord_by_periodicity(xx, x, nx, i)\n if (j .eq. 0) call coord_by_periodicity(yy, y, ny, j)\n call Evalbicubic_with_grad_and_hes(xx, yy, x(i), y(j), \n $ C(1,1,i,j), z_eval(k), \n $ dzdx_eval(k), dzdy_eval(k),\n $ d2zdx2_eval(k), d2zdxy_eval(k), d2zdy2_eval(k))\n\n elseif (outmode .eq. C0) then\n if (i .eq. 0) then\n call near_grid_point(xx, x, nx, i)\n change_dzdx = .true.\n else\n change_dzdx = .false.\n endif\n if (j .eq. 0) then\n call near_grid_point(yy, y, ny, j)\n change_dzdy = .true.\n else\n change_dzdy = .false.\n endif\n call Evalbicubic_with_grad_and_hes(xx, yy, x(i), y(j), \n $ C(1,1,i,j), z_eval(k), \n $ dzdx_eval(k), dzdy_eval(k),\n $ d2zdx2_eval(k), d2zdxy_eval(k), d2zdy2_eval(k))\n if (change_dzdx) then\n dzdx_eval(k) = 0.d0\n d2zdx2_eval(k) = 0.d0\n d2zdxy_eval(k) = 0.d0\n endif\n if (change_dzdy) then\n dzdy_eval(k) = 0.d0\n d2zdxy_eval(k) = 0.d0\n d2zdy2_eval(k) = 0.d0\n endif\n\n elseif (outmode .eq. NATURAL) then\n if (i .eq. 0) call near_interval(xx, x, nx, i)\n if (j .eq. 0) call near_interval(yy, y, ny, j)\n call Evalbicubic_with_grad_and_hes(xx, yy, x(i), y(j), \n $ C(1,1,i,j), z_eval(k), \n $ dzdx_eval(k), dzdy_eval(k),\n $ d2zdx2_eval(k), d2zdxy_eval(k), d2zdy2_eval(k))\n endif\n\n enddo\n\n end\n\n subroutine driverdb3val(xp, yp, zp, fp, np, tx, ty, tz, \n $ nx, ny, nz, kx, ky, kz, bcoef, work, \n $ xmin, xmax, ymin, ymax, zmin, zmax, \n $ outmode)\n*\n* PURPOSE\n* driver on to db3val\n*\n implicit none\n integer np, nx, ny, nz, kx, ky, kz, outmode\n double precision xp(np), yp(np), zp(np), fp(np), \n $ tx(*), ty(*), tz(*), bcoef(*), work(*), \n $ xmin, xmax, ymin, ymax, zmin, zmax\n \n integer k\n logical flag_x, flag_y, flag_z\n double precision x, y, z\n include 'constinterp.h'\n integer isanan\n double precision return_a_nan, db3val\n external isanan, return_a_nan, db3val\n\n do k = 1, np\n x = xp(k)\n if ( xmin .le. x .and. x .le. xmax ) then\n flag_x = .true.\n else\n flag_x = .false.\n endif\n y = yp(k)\n if ( ymin .le. y .and. y .le. ymax ) then\n flag_y = .true.\n else\n flag_y = .false.\n endif\n z = zp(k)\n if ( zmin .le. z .and. z .le. zmax ) then\n flag_z = .true.\n else\n flag_z = .false.\n endif\n\n if ( flag_x .and. flag_y .and. flag_z ) then\n fp(k) = db3val(x, y, z, 0, 0, 0, tx, ty, tz, \n $ nx, ny, nz, kx, ky, kz, bcoef, work)\n\n elseif (outmode .eq. BY_NAN .or. isanan(x) .eq. 1 \n $ .or. isanan(y) .eq. 1\n $ .or. isanan(z) .eq. 1) then\n fp(k) = return_a_nan()\n\n elseif (outmode .eq. BY_ZERO) then\n fp(k) = 0.d0\n\n else\n if (outmode .eq. PERIODIC) then\n if (.not. flag_x) call proj_by_per(x, xmin, xmax)\n if (.not. flag_y) call proj_by_per(y, ymin, ymax)\n if (.not. flag_z) call proj_by_per(z, zmin, zmax)\n elseif (outmode .eq. C0) then\n if (.not. flag_x) call proj_on_grid(x, xmin, xmax)\n if (.not. flag_y) call proj_on_grid(y, ymin, ymax)\n if (.not. flag_z) call proj_on_grid(z, zmin, zmax)\n endif\n fp(k) = db3val(x, y, z, 0, 0, 0, tx, ty, tz, nx, ny, nz, \n $ kx, ky, kz, bcoef, work)\n endif\n enddo\n\n end\n\n subroutine driverdb3valwithgrad(xp, yp, zp, fp, \n $ dfpdx, dfpdy, dfpdz, np, tx, ty, tz, \n $ nx, ny, nz, kx, ky, kz, bcoef, work, \n $ xmin, xmax, ymin, ymax, zmin, zmax, \n $ outmode)\n*\n* PURPOSE\n* driver on to db3val with gradient computing\n*\n implicit none\n integer np, nx, ny, nz, kx, ky, kz, outmode\n double precision xp(np), yp(np), zp(np), fp(np),\n $ dfpdx(np), dfpdy(np), dfpdz(np), \n $ tx(*), ty(*), tz(*), bcoef(*), work(*), \n $ xmin, xmax, ymin, ymax, zmin, zmax\n \n integer k\n logical flag_x, flag_y, flag_z\n double precision x, y, z\n include 'constinterp.h'\n integer isanan\n double precision return_a_nan, db3val\n external isanan, return_a_nan, db3val\n\n do k = 1, np\n x = xp(k)\n if ( xmin .le. x .and. x .le. xmax ) then\n flag_x = .true.\n else\n flag_x = .false.\n endif\n y = yp(k)\n if ( ymin .le. y .and. y .le. ymax ) then\n flag_y = .true.\n else\n flag_y = .false.\n endif\n z = zp(k)\n if ( zmin .le. z .and. z .le. zmax ) then\n flag_z = .true.\n else\n flag_z = .false.\n endif\n\n if ( flag_x .and. flag_y .and. flag_z ) then\n fp(k) = db3val(x, y, z, 0, 0, 0, tx, ty, tz, \n $ nx, ny, nz, kx, ky, kz, bcoef, work)\n dfpdx(k) = db3val(x, y, z, 1, 0, 0, tx, ty, tz, \n $ nx, ny, nz, kx, ky, kz, bcoef, work)\n dfpdy(k) = db3val(x, y, z, 0, 1, 0, tx, ty, tz, \n $ nx, ny, nz, kx, ky, kz, bcoef, work)\n dfpdz(k) = db3val(x, y, z, 0, 0, 1, tx, ty, tz, \n $ nx, ny, nz, kx, ky, kz, bcoef, work)\n\n elseif (outmode .eq. BY_NAN .or. isanan(x) .eq. 1 \n $ .or. isanan(y) .eq. 1\n $ .or. isanan(z) .eq. 1) then\n fp(k) = return_a_nan()\n dfpdx(k) = fp(k)\n dfpdy(k) = fp(k)\n dfpdz(k) = fp(k)\n\n elseif (outmode .eq. BY_ZERO) then\n fp(k) = 0.d0\n dfpdx(k) = 0.d0\n dfpdy(k) = 0.d0\n dfpdz(k) = 0.d0\n\n elseif (outmode .eq. PERIODIC) then\n if (.not. flag_x) call proj_by_per(x, xmin, xmax)\n if (.not. flag_y) call proj_by_per(y, ymin, ymax)\n if (.not. flag_z) call proj_by_per(z, zmin, zmax)\n fp(k) = db3val(x, y, z, 0, 0, 0, tx, ty, tz, nx, ny, nz, \n $ kx, ky, kz, bcoef, work)\n dfpdx(k) = db3val(x, y, z, 1, 0, 0, tx, ty, tz, \n $ nx, ny, nz, kx, ky, kz, bcoef, work)\n dfpdy(k) = db3val(x, y, z, 0, 1, 0, tx, ty, tz, \n $ nx, ny, nz, kx, ky, kz, bcoef, work)\n dfpdz(k) = db3val(x, y, z, 0, 0, 1, tx, ty, tz, \n $ nx, ny, nz, kx, ky, kz, bcoef, work)\n\n elseif (outmode .eq. C0) then\n if (.not. flag_x) call proj_on_grid(x, xmin, xmax)\n if (.not. flag_y) call proj_on_grid(y, ymin, ymax)\n if (.not. flag_z) call proj_on_grid(z, zmin, zmax)\n fp(k) = db3val(x, y, z, 0, 0, 0, tx, ty, tz, nx, ny, nz, \n $ kx, ky, kz, bcoef, work)\n if ( flag_x ) then\n dfpdx(k) = 0.d0\n else\n dfpdx(k) = db3val(x, y, z, 1, 0, 0, tx, ty, tz, \n $ nx, ny, nz, kx, ky, kz, bcoef, work)\n endif\n if ( flag_y ) then\n dfpdy(k) = 0.d0\n else\n dfpdy(k) = db3val(x, y, z, 0, 1, 0, tx, ty, tz, \n $ nx, ny, nz, kx, ky, kz, bcoef, work)\n endif\n if ( flag_z ) then\n dfpdz(k) = 0.d0\n else\n dfpdz(k) = db3val(x, y, z, 0, 0, 1, tx, ty, tz, \n $ nx, ny, nz, kx, ky, kz, bcoef, work)\n endif\n\n endif\n enddo\n\n end\n", "meta": {"hexsha": "e030e61d186792e9d532e7edcfd0f715ff5a8f19", "size": 42516, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/calelm/somespline.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/somespline.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/somespline.f", "max_forks_repo_name": "alpgodev/numx", "max_forks_repo_head_hexsha": "d2d3a0713020e1b83b65d3a661c3801ea256aff9", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.3069908815, "max_line_length": 91, "alphanum_fraction": 0.4469376235, "num_tokens": 14460, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380481, "lm_q2_score": 0.7185943985973773, "lm_q1q2_score": 0.6538540777834513}} {"text": " SUBROUTINE BMGTNS(CSTM,NCSTM,ECPT,TA)\r\nC/// THIS ROUTINE WAS LIFTED FROM PRETRD AND TRANSD AND CONVERTED\r\nC///// TO HAVE ONE ENTRY POINT\r\nC\r\nC PRETRD SETS UP EVENTUAL CALLS TO TRANSD. FOR A MODULE TO USE TRANSD\r\nC A CALL TO PRETRD MUST BE INITIATED BY THE MODULE DRIVER ONCE AND ONLY\r\nC ONCE. CSTM IS ARRAY OF COORDINATE SYSTEM TRANSFORMATION MATRICES\r\nC AND NCSTM IS THE LENGTH OF THIS ARRAY.\r\nC\r\n DIMENSION CSTM(1)\r\nC*****\r\nC GIVEN THE ECPT ARRAY OF LENGTH 4, THE FIRST WORD BEING AN INTEGER\r\nC COORDINATE SYSTEM IDENTIFICATION NUMBER AND THE NEXT WORDS BEING THE\r\nC REAL COORDINATES OF A POINT IN BASIC COORDINATES, THIS ROUTINE\r\nC COMPUTES THE TRANSFORMATION (DIRECTION COSINE) MATRIX TA WHICH WILL\r\nC MAP A VECTOR FROM THE LOCAL SYSTEM LABELED ECPT(1) TO BASIC COORDI-\r\nC NATES. TA IS A DOUBLE PRECISION MATRIX.\r\nC*****\r\n DIMENSION ECPT(4)\r\nC\r\n DOUBLE PRECISION\r\n 1 TA(9) ,TL(9)\r\n 2, XN(3) ,X\r\n 3, Y ,Z\r\n 4, R ,KE(9)\r\n 5, XL\r\nC\r\n EQUIVALENCE (FL1,INT1) ,(FL2,INT2)\r\nC\r\n FL1 = ECPT(1)\r\n IF(INT1.EQ.0) GO TO 13\r\n DO 6 I = 1,NCSTM,14\r\n FL2 = CSTM(I)\r\n IF(INT1.NE.INT2) GO TO 6\r\n KK = I\r\n FL2 = CSTM(I + 1)\r\n GO TO (7,10,10),INT2\r\n 6 CONTINUE\r\nC\r\nC THE COORDINATE SYSTEM ID. COULD NOT BE FOUND IN THE CSTM.\r\nC\r\n CALL MESAGE (-30,25,INT1)\r\nC\r\nC THE COORDINATE SYSTEM IS RECTANGULAR.\r\nC\r\n 7 DO 8 J = 1,9\r\n K = KK + 4 + J\r\n 8 TA(J) = CSTM(K)\r\n RETURN\r\n 10 XN(1) = ECPT(2) - CSTM(KK+2)\r\n XN(2) = ECPT(3) - CSTM(KK+3)\r\n XN(3) = ECPT(4) - CSTM(KK + 4)\r\n X = CSTM(KK+5)*XN(1)+CSTM(KK+8)*XN(2)+CSTM(KK+11)*XN(3)\r\n Y = CSTM(KK+6)*XN(1)+CSTM(KK+9)*XN(2)+CSTM(KK+12)*XN(3)\r\n Z = CSTM(KK+7)*XN(1)+CSTM(KK+10)*XN(2)+CSTM(KK+13)*XN(3)\r\n R = DSQRT(X**2+Y**2)\r\n IF (R .EQ. 0.0D0) GO TO 7\r\n DO 110 J=1,9\r\n K=KK+4+J\r\n 110 KE(J)=CSTM(K)\r\n GO TO (11,11,12),INT2\r\nC\r\nC THE COORDINATE SYSTEM IS CYLINDRICAL.\r\nC\r\n 11 TL(1)=X/R\r\n TL(2)=-Y/R\r\n TL(3)=0.0D0\r\n TL(4)=-TL(2)\r\n TL(5)=TL(1)\r\n TL(6)=0.0D0\r\n TL(7)=0.0D0\r\n TL(8)=0.0D0\r\n TL(9)=1.0D0\r\n GO TO 125\r\nC\r\nC THE COORDINATE SYSTEM IS SPHERICAL.\r\nC\r\n 12 XL=DSQRT(X*X+Y*Y+Z*Z)\r\n TL(1)=X/XL\r\n TL(2)=(X*Z)/(R*XL)\r\n TL(3)=-Y/R\r\n TL(4)=Y/XL\r\n TL(5)=(Y*Z)/(R*XL)\r\n TL(6)=X/R\r\n TL(7)=Z/XL\r\n TL(8)=-R/XL\r\n TL(9)=0.0D0\r\n 125 CALL GMMATD (KE(1),3,3,0, TL(1),3,3,0, TA(1))\r\n RETURN\r\nC\r\nC THE LOCAL SYSTEM IS BASIC.\r\nC\r\n 13 DO 14 I=1,9\r\n 14 TA(I)=0.0D0\r\n TA(1)=1.0D0\r\n TA(5)=1.0D0\r\n TA(9)=1.0D0\r\n RETURN\r\n END\r\n", "meta": {"hexsha": "e855d07b8f340565c2d773d48f9a993bbe4dc055", "size": 2798, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "mis/bmgtns.f", "max_stars_repo_name": "ldallolio/NASTRAN-95", "max_stars_repo_head_hexsha": "6d2c175f5b53ebaec4ba2b5186f7926ef9d0ed47", "max_stars_repo_licenses": ["NASA-1.3"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2016-01-09T14:33:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-18T11:51:42.000Z", "max_issues_repo_path": "mis/bmgtns.f", "max_issues_repo_name": "gassive/NASTRAN95", "max_issues_repo_head_hexsha": "98cb3acaa7990d639360601648498834c7782056", "max_issues_repo_licenses": ["NASA-1.3"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2016-01-17T07:30:19.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-06T19:37:44.000Z", "max_forks_repo_path": "mis/bmgtns.f", "max_forks_repo_name": "gassive/NASTRAN95", "max_forks_repo_head_hexsha": "98cb3acaa7990d639360601648498834c7782056", "max_forks_repo_licenses": ["NASA-1.3"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-04-07T20:51:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T14:16:01.000Z", "avg_line_length": 27.98, "max_line_length": 72, "alphanum_fraction": 0.5182273052, "num_tokens": 1137, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380482, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6538540777834513}} {"text": "************************************************************************\n* *\n* gibbmain 1-09-95 *\n* *\n* This program calculates the number of iterations required in a run *\n* of MCMC. The user has to specify the precision required. This *\n* subroutine returns the number of iterations required to estimate *\n* the posterior cdf of the q-quantile of the quantity of interest (a *\n* function of the parameters) to within +-r with probability s. It *\n* also gives the number of \"burn-in\" iterations required for the *\n* conditional distribution given any starting point (of the derived *\n* two-state process) to be within epsilon of the actual equilibrium *\n* distribution. *\n* *\n* If q<=0, then gibbmain is to treat the original input series as a *\n* vector of 0-1 outcome variables. In this case no quantile needs to *\n* be found. Instead, this subroutine just needs to calculate kthin, *\n* nburn, nprec and kmind tuning parameters such that a MCMC run based *\n* on these tuning parameters should be adequate for estimating the *\n* probability of an outcome of 1 within the prescribed (by r, s, and *\n* epsilon) probability. *\n* *\n************************************************************************\n\n************************************************************************\n* *\n* Inputs: *\n* *\n* original = a double precision vector containing the original MCMC *\n* generated series of parameter estimates. This vector *\n* contains iteracnt elements. *\n* *\n* iteracnt = an integer containing the number of actual iterations *\n* provided in the sample MCMC output series, original. *\n* *\n* q,r,s = double precision numbers in which the caller specifies *\n* the required precision: the q-quantile is to be *\n* estimated to within r with probability s. *\n* *\n* epsilon = a double precision number containing the half width of *\n* the tolerance interval required for the q-quantile. *\n* *\n* work = an integer vector passed to various subroutines to *\n* hold a number of internal vectors. There must be at *\n* least (iteracnt * 2) elements in this vector. *\n* *\n************************************************************************\n\n************************************************************************\n* *\n* Outputs: *\n* *\n* nmin = an integer which will be set to the minimum number of *\n* independent Gibbs iterates required to achieve the *\n* specified accuracy for the q-quantile. *\n* *\n* kthin = an integer which will be set to the skip parameter *\n* sufficient to produce a first-order Markov chain. *\n* *\n* nburn = an integer which will be set to the number of *\n* iterations to be discarded at the beginning of the *\n* simulation, i.e. the number of burn-in iterations. *\n* *\n* nprec = an integer which will be set to the number of *\n* iterations not including the burn-in iterations which *\n* need to be obtained in order to attain the precision *\n* specified by the values of the q, r and s input *\n* parameters. *\n* *\n* kmind = an integer which will be set to the minimum skip *\n* parameter sufficient to produce an independence chain. *\n* *\n* r15 = an integer valued error return code. This variable *\n* is set to 0 if no errors were encountered. *\n* Otherwise, r15 can assume the following values: *\n* *\n* 12 = the original input vector contains something *\n* other than a 0 or 1 even though q<=0. *\n* No other possible values are currently in use. *\n* *\n************************************************************************\n\n subroutine gibbmain(original,iteracnt,q,r,s,epsilon,work,nmin,\n + kthin,nburn,nprec,kmind,r15)\n\n integer iteracnt\n double precision original(iteracnt)\n double precision q\n double precision r\n double precision s\n double precision epsilon\n integer work(iteracnt*2)\n integer nmin\n integer kthin\n integer nburn\n integer nprec\n integer kmind\n integer r15\n\n************************************************************************\n* *\n* The following variables hold various temporary values used in this *\n* subroutine. This includes any do-loop counters and similar such *\n* temporary subscripts and indices. *\n* *\n* cutpt - the q-th empirical quantile *\n* qhat - when q=0, proportion of 1's in the input data vector, *\n* when q>0, qhat is set equal to the passed value of q *\n* g2 - G2 for the test of first-order vs second-order Markov *\n* bic - the corresponding BIC value *\n* phi - \\PHI^{-1} ((s+1)/2) *\n* alpha - probability of moving from below the cutpt to above *\n* beta - probability of moving from above the cutpt to below *\n* probsum - sum of alpha + beta *\n* *\n* The first iteracnt elements of the work vector will be used to *\n* store a binary 0-1 series indicating which elements are less than *\n* or equal to the cutpt (set to 1) and which elements are less than *\n* the cutpt (set to 0). *\n* *\n* The remaining iteracnt elements of the work vector are to be used *\n* to hold thinned versions of the 0-1 series, where the amount of *\n* thinning is determined by the current value of kthin (or kmind). *\n* That is, for each proposed value of kthin (or kmind), only every *\n* kthin-th (or kmind-th) element of the 0-1 series is copied to this *\n* thinned copy of the series. *\n* *\n* ixkstart is the subscript of the first element of the thinned *\n* series. That is, ixkstart = iteracnt + 1. *\n* *\n* thincnt is the current length of the thinned series. *\n* *\n************************************************************************\n\n double precision empquant\n double precision cutpt\n double precision qhat\n double precision g2\n double precision bic\n double precision phi\n\n double precision alpha\n double precision beta\n double precision probsum\n\n double precision tmp1\n double precision tmp2\n\n real ppnd7\n\n integer ixkstart\n integer thincnt\n integer i1\n integer rc\n\n************************************************************************\n* *\n* If the q argument is a postive number, interpret it as the quantile *\n* which is to be ascertained using MCMC. It should be a positive *\n* number less than 1. Set qhat to the passed value of q (we will use *\n* qhat later when we calculate nmin). *\n* *\n************************************************************************\n\n if (q.gt.0.0d0) then\n qhat = q\n\n************************************************************************\n* *\n* Find the q-th quantile of the original MCMC series of parameter *\n* estimates. *\n* *\n************************************************************************\n\n cutpt = empquant(original,iteracnt,qhat,work)\n\n************************************************************************\n* *\n* Calculate a binary 0-1 series indicating which elements are less *\n* than or equal to the cutpt (set to 1) and which elements are *\n* greater than the cutpt (set to 0). The resulting series is stored *\n* in the work vector. *\n* *\n************************************************************************\n\n call dichot(original,iteracnt,cutpt,work)\n\n************************************************************************\n* *\n* Otherwise treat the original input series as a binary 0-1 series of *\n* outcomes whose probability needs to be estimated using MCMC. This *\n* is easily accomplished by copying the input series into the first *\n* iteracnt elements of the work vector, converting the double preci- *\n* sion input into an equivalent integer vector of 0's and 1's. For *\n* this case we will also need to set qhat equal to the proportion of *\n* 1's in the original input data vector. *\n* *\n************************************************************************\n\n else\n\n qhat = 0.0d0\n\n do 300 i1=1,iteracnt\n if (original(i1).eq.0.0d0 .or. original(i1).eq.1.0d0) then\n work(i1) = int( original(i1) )\n qhat = qhat + original(i1)\n else\n r15 = 12\n return\n end if\n 300 continue\n\n qhat = qhat / dble( iteracnt )\n\n end if\n\n************************************************************************\n* *\n* Find kthin, the degree of thinning at which the indicator series is *\n* first-order Markov. *\n* *\n************************************************************************\n\n ixkstart = iteracnt + 1\n kthin = 1\n\n 500 call thin(work,iteracnt,kthin,work(ixkstart),thincnt)\n call mctest(work(ixkstart),thincnt,g2,bic)\n if (bic.le.0.0d0) go to 600\n kthin = kthin + 1\n go to 500\n\n************************************************************************\n* *\n* Calculate both the alpha and beta transition probabilities (in the *\n* Cox & Miller parametrization) of the two state first-order Markov *\n* chain determined above. *\n* *\n************************************************************************\n\n 600 call mcest(work(ixkstart),thincnt,alpha,beta)\n kmind = kthin\n go to 750\n\n************************************************************************\n* *\n* Now compute just how big the spacing needs to be so that a thinned *\n* chain would no longer be a Markov chain, but rather would be an *\n* independence chain. This thinning parameter must be at least as *\n* large as the thinning parameter required for a first-order Markov *\n* chain. *\n* *\n************************************************************************\n\n 700 call thin(work,iteracnt,kmind,work(ixkstart),thincnt)\n 750 call indtest(work(ixkstart),thincnt,g2,bic)\n if (bic.le.0.0d0) go to 800\n kmind = kmind + 1\n go to 700\n\n************************************************************************\n* *\n* Estimate the first-order Markov chain parameters and find the *\n* burn-in and precision number of required iterations. *\n* *\n************************************************************************\n\n 800 probsum = alpha + beta\n tmp1 = dlog(probsum * epsilon / max(alpha,beta)) /\n + dlog( dabs(1.0d0 - probsum) )\n nburn = int( tmp1 + 1.0d0 ) * kthin\n\n************************************************************************\n* *\n* Note: ppnd7 is the routine that implements AS algorithm 241. *\n* It calculates the specified percentile of the Normal distribution. *\n* *\n************************************************************************\n\n phi = dble(ppnd7( ((real(s) + 1.0) / 2.0), rc ))\n tmp2 = (2.0d0 - probsum) * alpha * beta * phi**2 / (probsum**3 *\n + r**2)\n nprec = int( tmp2 + 1.0d0 ) * kthin\n nmin = int( ((1.0d0-qhat) * qhat * phi**2 / r**2) + 1.0d0 )\n\n************************************************************************\n* *\n* At this point we have calculated nmin, kthin, nburn, nprec and *\n* kmind, so we can return to the calling program. *\n* *\n************************************************************************\n\n r15 = 0\n return\n end\n\n************************************************************************\n* *\n* empquant 9-13-94 *\n* *\n* This function finds the q-th empirical quantile of the input double *\n* precsion series, data, of length iteracnt. *\n* *\n* The algorithm used by this subroutine is the one used in the SPLUS *\n* quantile function. *\n* *\n************************************************************************\n\n************************************************************************\n* *\n* Inputs: *\n* *\n* data = a double precision vector of numbers whose q-th *\n* empirical quantile is to be calculated. *\n* *\n* iteracnt = an integer containing the number of elements in the *\n* input data vector, data. There must also be this *\n* many elements in the work vector. *\n* *\n* q = a double precision number between 0.0d0 and 1.0d0, *\n* inclusive, specifying which empirical quantile is *\n* wanted. *\n* *\n* work = a double precision vector to be used as a work area *\n* for the sort subroutine called by empquant. This *\n* vector must contain at least iteracnt elements. *\n* *\n* *\n* Outputs: *\n* *\n* empquant = a double precision number corresponding to the q-th *\n* level of the sorted vector of input values. *\n* *\n************************************************************************\n\n function empquant(data,iteracnt,q,work)\n\n double precision empquant\n integer iteracnt\n double precision data(iteracnt)\n double precision q\n double precision work(*)\n\n************************************************************************\n* *\n* The following variables hold various temporary values used in this *\n* subroutine. This includes any do-loop counters and similar such *\n* temporary subscripts and indices. *\n* *\n************************************************************************\n\n double precision order\n double precision fract\n\n integer low\n integer high\n integer i1\n\n************************************************************************\n* *\n* Copy the input series of double precision numbers into the work *\n* area provided by the caller. In this way the original input will *\n* not be modified by this subroutine. *\n* *\n************************************************************************\n\n do 300 i1=1,iteracnt\n work(i1) = data(i1)\n 300 continue\n\n************************************************************************\n* *\n* Sort the input series into ascending order. *\n* *\n************************************************************************\n\n call ssort(work,work,iteracnt,int(1))\n\n************************************************************************\n* *\n* Now locate the q-th empirical quantile. This apparently longer *\n* than necessary calculation is used so as to appropriately handle *\n* the case where there are two or more identical values at the *\n* requested quantile. *\n* *\n************************************************************************\n\n order = dble(iteracnt-1) * q + 1.0d0\n fract = mod(order, 1.0d0)\n low = max(int(order), 1)\n high = min(low+1, iteracnt)\n empquant = (1.0d0 - fract) * work(low) + fract * work(high)\n\n return\n end\n\n************************************************************************\n* *\n* dichot 9-13-94 *\n* *\n* This subroutine takes a double precision vector, data, of length *\n* iteracnt and converts it into a 0-1 series in zt, depending on *\n* which elements of data are less than or greater than cutpt. *\n* *\n************************************************************************\n\n************************************************************************\n* *\n* Inputs: *\n* *\n* data = a double precision vector containing a series of *\n* numbers which are to be compared to cutpt in order to *\n* determine which elements of zt are to be set to 1 and *\n* which are to be set to 0. *\n* *\n* iteracnt = an integer containing the number of elements in the *\n* input data vector. *\n* *\n* cutpt = a double precision number indicating the boundary *\n* about which the input data vector is to be dichoto- *\n* mized, i.e. set to 1 when less than or equal to the *\n* cutpoint and to 0 when greater than the cutpoint. *\n* *\n* *\n* Outputs: *\n* *\n* zt = an integer vector containing zeros and ones depending *\n* on whether or not the corresponding elements of data *\n* were less than the cutpoint or not. *\n* *\n************************************************************************\n\n subroutine dichot(data,iteracnt,cutpt,zt)\n\n integer iteracnt\n double precision data(iteracnt)\n double precision cutpt\n integer zt(iteracnt)\n\n************************************************************************\n* *\n* The following variables hold various temporary values used in this *\n* subroutine. This includes any do-loop counters and similar such *\n* temporary subscripts and indices. *\n* *\n************************************************************************\n\n integer i1\n\n************************************************************************\n* *\n* If the entry in the input data vector is less than or equal to the *\n* cutpoint, set the corresponding element of zt to 1, otherwise set *\n* it to 0. *\n* *\n************************************************************************\n\n do 500 i1=1,iteracnt\n if (data(i1).le.cutpt) then\n zt(i1) = 1\n else\n zt(i1) = 0\n end if\n 500 continue\n\n return\n end\n\n************************************************************************\n* *\n* thin 9-13-94 *\n* *\n* This subroutine takes the integer-valued vector series of length *\n* iteracnt and outputs elements 1,1+kthin,1+2kthin,1+3kthin,... in *\n* the result vector. *\n* *\n************************************************************************\n\n************************************************************************\n* *\n* Inputs: *\n* *\n* series = an integer vector containing the sequence of numbers *\n* from which this subroutine is to select every kthin'th *\n* number to be copied to the output vector, starting *\n* with the first number. There are iteracnt elements in *\n* this vector. *\n* *\n* iteracnt = an integer containing the number of elements in the *\n* input vector of numbers to be thinned, series. If *\n* kthin can be as little as 1, the output result vector *\n* must also contain iteracnt elements. *\n* *\n* kthin = an integer specifying the interval between elements of *\n* the input data vector, series, which are to be copied *\n* to the output vector, result. If kthin is 1, then all *\n* of series is to be copied to result. If kthin is 2, *\n* then only every other element of series is to be *\n* copied to result. If kthin is 3, then every third *\n* element is copied and so forth. *\n* *\n* *\n* Outputs: *\n* *\n* result = an integer vector containing the thinned subset of the *\n* input data vector, series, starting with the first *\n* element and copying every kthin'th from there on. The *\n* number of meaningful elements in this vector will be *\n* returned as thincnt. *\n* *\n* thincnt = an integer containing the number of elements actually *\n* copied to the result vector. *\n* *\n************************************************************************\n\n subroutine thin(series,iteracnt,kthin,result,thincnt)\n\n integer iteracnt\n integer series(iteracnt)\n integer kthin\n integer result(iteracnt)\n integer thincnt\n\n************************************************************************\n* *\n* The following variables hold various temporary values used in this *\n* subroutine. This includes any do-loop counters and similar such *\n* temporary subscripts and indices. *\n* *\n************************************************************************\n\n integer from\n integer i1\n\n************************************************************************\n* *\n* The specified subset of the input data vector, series, is copied to *\n* sequential elements of the output vector, result. Stop copying *\n* when the entries in the input data vector run out. *\n* *\n************************************************************************\n\n do 300 i1=1,iteracnt\n from = (i1-1) * kthin + 1\n if (from.gt.iteracnt) go to 600\n result(i1) = series(from)\n 300 continue\n\n************************************************************************\n* *\n* Calculate how many elements have been copied to the output vector, *\n* result, and return this number as thincnt. *\n* *\n************************************************************************\n\n 600 thincnt = i1 - 1\n return\n end\n\n************************************************************************\n* *\n* mctest 12-05-94 *\n* *\n* This subroutine tests for a first-order Markov chain against a *\n* second-order Markov chain using the log-linear modeling *\n* formulation. Here the first-order model is the [12][23] model, *\n* while the 2nd-order model is the saturated model. The [12][23] *\n* model has closed form estimates - see Bishop, Feinberg and Holland. *\n* *\n************************************************************************\n\n************************************************************************\n* *\n* Inputs: *\n* *\n* data = an integer vector containing the series of 0's and 1's *\n* for which this subroutine is to determine whether a *\n* first-order Markov chain is sufficient or whether a *\n* second-order Markov chain is needed to model the data. *\n* There must be at least datacnt elements in the data *\n* vector. *\n* *\n* datacnt = an integer containing the number of elements in the *\n* data argument. *\n* *\n* *\n* Outputs: *\n* *\n* g2 = a double precision number in which this subroutine is *\n* to return the log likelihood ratio statistic for *\n* testing a second-order Markov chain against only a *\n* first-order Markov chain. Bishop, Feinberg and *\n* Holland denote this statistic as G2. *\n* *\n* bic = a double precision number in which this subroutine is *\n* to return the BIC value corresponding to the log *\n* likelihood ratio statistic, g2. *\n* *\n************************************************************************\n\n subroutine mctest(data,datacnt,g2,bic)\n\n integer datacnt\n integer data(datacnt)\n double precision g2\n double precision bic\n\n************************************************************************\n* *\n* The following variables hold various temporary values used in this *\n* subroutine. This includes any do-loop counters and similar such *\n* temporary subscripts and indices. *\n* *\n************************************************************************\n\n double precision fitted\n double precision focus\n\n integer tran(2,2,2)\n integer i1\n integer i2\n integer i3\n\n************************************************************************\n* *\n* Initialize the transition counts array to all zeroes. *\n* *\n************************************************************************\n\n do 300 i1=1,2\n do 200 i2=1,2\n do 100 i3=1,2\n tran(i1,i2,i3) = 0\n 100 continue\n 200 continue\n 300 continue\n\n************************************************************************\n* *\n* Count up the number of occurrences of each possible type of *\n* transition. Keep these counts in the transition counts array. *\n* *\n************************************************************************\n\n do 400 i1=3,datacnt\n tran( data(i1-2)+1, data(i1-1)+1, data(i1)+1 ) =\n + tran( data(i1-2)+1, data(i1-1)+1, data(i1)+1 ) + 1\n 400 continue\n\n************************************************************************\n* *\n* Compute the log likelihood ratio statistic for testing a second- *\n* order Markov chain against only a first-order Markov chain. This *\n* is Bishop, Feinberg and Holland's G2 statistic. *\n* *\n************************************************************************\n\n g2 = 0.0d0\n\n do 700 i1=1,2\n do 600 i2=1,2\n do 500 i3=1,2\n if (tran(i1,i2,i3).eq.0) go to 500\n fitted = dble( (tran(i1,i2,1) + tran(i1,i2,2)) *\n + (tran(1,i2,i3) + tran(2,i2,i3)) ) / dble( tran(1,i2,1) +\n + tran(1,i2,2) + tran(2,i2,1) + tran(2,i2,2) )\n focus = dble( tran(i1,i2,i3) )\n g2 = g2 + dlog( focus / fitted ) * focus\n 500 continue\n 600 continue\n 700 continue\n\n g2 = g2 * 2.0d0\n\n************************************************************************\n* *\n* Finally calculate the associated bic statistic and return to the *\n* caller. *\n* *\n************************************************************************\n\n bic = g2 - dlog( dble(datacnt-2) ) * 2.0d0\n return\n end\n\n************************************************************************\n* *\n* indtest 11-23-94 *\n* *\n* This subroutine tests for an independence chain against a first- *\n* order Markov chain using the log-linear modeling formulation. In *\n* our case the independence model is the [1][2][3] model, while the *\n* first-order model is the [12][23] model. Both the [1][2][3] and *\n* the [12][23] models have closed form estimates - see Bishop, *\n* Feinberg and Holland (1975). *\n* *\n************************************************************************\n\n************************************************************************\n* *\n* Inputs: *\n* *\n* data = an integer vector containing the series of 0's and 1's *\n* for which this subroutine is to determine whether an *\n* independence chain is sufficient or whether a first- *\n* order Markov chain is needed to model the data. There *\n* must be at least datacnt elements in the data vector. *\n* *\n* datacnt = an integer containing the number of elements in the *\n* data argument. *\n* *\n* *\n* Outputs: *\n* *\n* g2 = a double precision number in which this subroutine is *\n* to return the log likelihood ratio statistic for *\n* testing a first-order Markov chain against simply an *\n* independence chain. Bishop, Feinberg and Holland *\n* denote this statistic as G2. *\n* *\n* bic = a double precision number in which this subroutine is *\n* to return the BIC value corresponding to the log *\n* likelihood ratio statistic, g2. *\n* *\n************************************************************************\n\n subroutine indtest(data,datacnt,g2,bic)\n\n integer datacnt\n integer data(datacnt)\n double precision g2\n double precision bic\n\n************************************************************************\n* *\n* The following variables hold various temporary values used in this *\n* subroutine. This includes any do-loop counters and similar such *\n* temporary subscripts and indices. *\n* *\n************************************************************************\n\n double precision fitted\n double precision focus\n double precision dcm1\n\n integer tran(2,2)\n integer i1\n integer i2\n\n************************************************************************\n* *\n* Initialize the transition counts array to all zeroes. *\n* *\n************************************************************************\n\n do 300 i1=1,2\n do 200 i2=1,2\n tran(i1,i2) = 0\n 200 continue\n 300 continue\n\n************************************************************************\n* *\n* Count up the number of occurrences of each possible type of *\n* transition. Keep these counts in the transition counts array. *\n* *\n************************************************************************\n\n do 400 i1=2,datacnt\n tran( data(i1-1)+1, data(i1)+1 ) = tran( data(i1-1)+1,\n + data(i1)+1 ) + 1\n 400 continue\n\n************************************************************************\n* *\n* Compute the log likelihood ratio statistic for testing a first- *\n* order Markov chain against simply an independence chain. This is *\n* Bishop, Feinberg and Holland's G2 statistic. *\n* *\n************************************************************************\n\n dcm1 = dble( datacnt-1 )\n g2 = 0.0d0\n\n do 700 i1=1,2\n do 600 i2=1,2\n if (tran(i1,i2).eq.0) go to 600\n fitted = dble( (tran(i1,1) + tran(i1,2)) * (tran(1,i2) +\n + tran(2,i2)) ) / dcm1\n focus = dble( tran(i1,i2) )\n g2 = g2 + dlog( focus / fitted ) * focus\n 600 continue\n 700 continue\n\n g2 = g2 * 2.0d0\n\n************************************************************************\n* *\n* Finally calculate the associated bic statistic and return to the *\n* caller. Note that the first-order Markov chain model contains just *\n* one more parameter than does the independence chain model, so p=1. *\n* *\n************************************************************************\n\n bic = g2 - dlog( dcm1 )\n return\n end\n\n************************************************************************\n* *\n* mcest 12-05-94 *\n* *\n* Estimate the parameters of a first-order Markov chain (in the Cox *\n* & Miller parametrization) from a series of binary, i.e. 0-1, data *\n* passed in the data vector argument. *\n* *\n************************************************************************\n\n************************************************************************\n* *\n* Inputs: *\n* *\n* data = an integer vector containing the series of 0's and 1's *\n* from which this subroutine is to calculate empirical *\n* probabilities of a transition from a 0 to a 1 or a *\n* transition from a 1 to a 0. There must be at least *\n* datacnt elements in this vector. *\n* *\n* datacnt = an integer containing the number of elements in the *\n* data argument. *\n* *\n* *\n* Outputs: *\n* *\n* alpha = a double precision number in which this subroutine is *\n* to return the empirical probability of a 1 following *\n* a 0 in the input data vector. *\n* *\n* beta = a double precision number in which this subroutine is *\n* to return the empirical probability of a 0 following *\n* a 1 in the input data vector. *\n* *\n************************************************************************\n\n subroutine mcest(data,datacnt,alpha,beta)\n\n integer datacnt\n integer data(datacnt)\n double precision alpha\n double precision beta\n\n************************************************************************\n* *\n* The following variables hold various temporary values used in this *\n* subroutine. This includes any do-loop counters and similar such *\n* temporary subscripts and indices. *\n* *\n************************************************************************\n\n integer tran(2,2)\n integer i1\n integer i2\n\n************************************************************************\n* *\n* Initialize the transition counts array to all zeroes. *\n* *\n************************************************************************\n\n do 200 i1=1,2\n do 100 i2=1,2\n tran(i1,i2) = 0\n 100 continue\n 200 continue\n\n************************************************************************\n* *\n* Count up the number of occurrences of each possible type of *\n* transition. Keep these counts in the transition counts array. *\n* *\n************************************************************************\n\n do 400 i1=2,datacnt\n tran( data(i1-1)+1, data(i1)+1 ) = tran( data(i1-1)+1,\n + data(i1)+1 ) + 1\n 400 continue\n\n************************************************************************\n* *\n* Calculate the empirical transition probabilities between 0's and *\n* 1's in the input (returned in alpha) and between 1's and 0's in the *\n* input (returned in beta). *\n* *\n************************************************************************\n\n alpha = dble(tran(1,2)) / dble( (tran(1,1) + tran(1,2)) )\n beta = dble(tran(2,1)) / dble( (tran(2,1) + tran(2,2)) )\n\n return\n end\n\n REAL FUNCTION PPND7(P,IFAULT)\n\n* ALGORITHM AS241 APPL. STATIST. (1988) VOL. 37, NO. 3, 477-\n* 484.\n\n* Produces the normal deviate Z corresponding to a given lower\n* tail area of P; Z is accurate to about 1 part in 10**7.\n\n* The hash sums below are the sums of the mantissas of the\n* coefficients. They are included for use in checking\n* transcription.\n\n REAL ZERO, ONE, HALF, SPLIT1, SPLIT2, CONST1, CONST2, A0, A1,\n + A2, A3, B1, B2, B3, C0, C1, C2, C3, D1, D2, E0, E1, E2,\n + E3, F1, F2, P, Q, R\n PARAMETER (ZERO = 0.0, ONE = 1.0, HALF = 0.5,\n + SPLIT1 = 0.425, SPLIT2 = 5.0,\n + CONST1 = 0.180625, CONST2 = 1.6)\n INTEGER IFAULT\n\n* Coefficients for P close to 0.5\n\n PARAMETER (A0 = 3.38713 27179E+00, A1 = 5.04342 71938E+01,\n + A2 = 1.59291 13202E+02, A3 = 5.91093 74720E+01,\n + B1 = 1.78951 69469E+01, B2 = 7.87577 57664E+01,\n + B3 = 6.71875 63600E+01)\n* HASH SUM AB 32.31845 77772\n\n* Coefficients for P not close to 0, 0.5 or 1.\n\n PARAMETER (C0 = 1.42343 72777E+00, C1 = 2.75681 53900E+00,\n + C2 = 1.30672 84816E+00, C3 = 1.70238 21103E-01,\n + D1 = 7.37001 64250E-01, D2 = 1.20211 32975E-01)\n* HASH SUM CD 15.76149 29821\n\n* Coefficients for P near 0 or 1.\n\n PARAMETER (E0 = 6.65790 51150E+00, E1 = 3.08122 63860E+00,\n + E2 = 4.28682 94337E-01, E3 = 1.73372 03997E-02,\n + F1 = 2.41978 94225E-01, F2 = 1.22582 02635E-02)\n* HASH SUM EF 19.40529 10204\n\n IFAULT = 0\n Q = P - HALF\n IF (ABS(Q) .LE. SPLIT1) THEN\n R = CONST1 - Q * Q\n PPND7 = Q * (((A3 * R + A2) * R + A1) * R + A0) /\n + (((B3 * R + B2) * R + B1) * R + ONE)\n RETURN\n ELSE\n IF (Q .LT. ZERO) THEN\n R = P\n ELSE\n R = ONE - P\n END IF\n IF (R .LE. ZERO) THEN\n IFAULT = 1\n PPND7 = ZERO\n RETURN\n END IF\n R = SQRT(-LOG(R))\n IF (R .LE. SPLIT2) THEN\n R = R - CONST2\n PPND7 = (((C3 * R + C2) * R + C1) * R + C0) /\n + ((D2 * R + D1) * R + ONE)\n ELSE\n R = R - SPLIT2\n PPND7 = (((E3 * R + E2) * R + E1) * R + E0) /\n + ((F2 * R + F1) * R + ONE)\n END IF\n IF (Q .LT. ZERO) PPND7 = - PPND7\n RETURN\n END IF\n END\n\n SUBROUTINE SSORT(X,Y,N,KFLAG)\n****BEGIN PROLOGUE SSORT\n****REVISION OCTOBER 1,1980\n****CATEGORY NO. M1\n****KEYWORD(S) SORTING,SORT,SINGLETON QUICKSORT,QUICKSORT\n****DATE WRITTEN NOVEMBER,1976\n****AUTHOR JONES R.E., WISNIEWSKI J.A. (SLA)\n****PURPOSE\n* SSORT SORTS ARRAY X AND OPTIONALLY MAKES THE SAME\n* INTERCHANGES IN ARRAY Y. THE ARRAY X MAY BE SORTED IN\n* INCREASING ORDER OR DECREASING ORDER. A SLIGHTLY MODIFIED\n* QUICKSORT ALGORITHM IS USED.\n****DESCRIPTION\n* SANDIA MATHEMATICAL PROGRAM LIBRARY\n* APPLIED MATHEMATICS DIVISION 2646\n* SANDIA LABORATORIES\n* ALBUQUERQUE, NEW MEXICO 87185\n* CONTROL DATA 6600/7600 VERSION 8.1 AUGUST 1980\n*\n* WRITTEN BY RONDALL E JONES\n* MODIFIED BY JOHN A. WISNIEWSKI TO USE THE SINGLETON QUICKSORT\n* ALGORITHM. DATE 18 NOVEMBER 1976.\n*\n* ABSTRACT\n* SSORT SORTS ARRAY X AND OPTIONALLY MAKES THE SAME\n* INTERCHANGES IN ARRAY Y. THE ARRAY X MAY BE SORTED IN\n* INCREASING ORDER OR DECREASING ORDER. A SLIGHTLY MODIFIED\n* QUICKSORT ALGORITHM IS USED.\n*\n* REFERENCE\n* SINGLETON,R.C., ALGORITHM 347, AN EFFICIENT ALGORITHM FOR\n* SORTING WITH MINIMAL STORAGE, CACM,12(3),1969,185-7.\n*\n* DESCRIPTION OF PARAMETERS\n* X - ARRAY OF VALUES TO BE SORTED (USUALLY ABSCISSAS)\n* Y - ARRAY TO BE (OPTIONALLY) CARRIED ALONG\n* N - NUMBER OF VALUES IN ARRAY X TO BE SORTED\n* KFLAG - CONTROL PARAMETER\n* =2 MEANS SORT X IN INCREASING ORDER AND CARRY Y ALONG.\n* =1 MEANS SORT X IN INCREASING ORDER (IGNORING Y)\n* =-1 MEANS SORT X IN DECREASING ORDER (IGNORING Y)\n* =-2 MEANS SORT X IN DECREASING ORDER AND CARRY Y ALONG.\n*\n****REFERENCE(S)\n* SINGLETON,R.C., ALGORITHM 347, AN EFFICIENT ALGORITHM FOR\n* SORTING WITH MINIMAL STORAGE, CACM,12(3),1969,185-7.\n****END PROLOGUE\n\n INTEGER I, IJ, IL(21), IU(21), J, K, KFLAG, KK, L, M, N, NN\n DOUBLE PRECISION R, T, TT, TTY, TY, X(N), Y(N)\n\n****FIRST EXECUTABLE STATEMENT SSORT\n NN = N\n KK = IABS(KFLAG)\n*\n* ALTER ARRAY X TO GET DECREASING ORDER IF NEEDED\n*\n 15 IF (KFLAG.GE.1) GO TO 30\n DO 20 I=1,NN\n 20 X(I) = -X(I)\n 30 GO TO (100,200),KK\n*\n* SORT X ONLY\n*\n 100 CONTINUE\n M = 1\n I = 1\n J = NN\n R = .375\n 110 IF (I .EQ. J) GO TO 155\n 115 IF (R .GT. .5898437) GO TO 120\n R = R+3.90625E-2\n GO TO 125\n 120 R = R-.21875\n 125 K = I\n* SELECT A CENTRAL ELEMENT OF THE\n* ARRAY AND SAVE IT IN LOCATION T\n IJ = I + IDINT( DBLE(J-I) * R )\n T = X(IJ)\n* IF FIRST ELEMENT OF ARRAY IS GREATER\n* THAN T, INTERCHANGE WITH T\n IF (X(I) .LE. T) GO TO 130\n X(IJ) = X(I)\n X(I) = T\n T = X(IJ)\n 130 L = J\n* IF LAST ELEMENT OF ARRAY IS LESS THAN\n* T, INTERCHANGE WITH T\n IF (X(J) .GE. T) GO TO 140\n X(IJ) = X(J)\n X(J) = T\n T = X(IJ)\n* IF FIRST ELEMENT OF ARRAY IS GREATER\n* THAN T, INTERCHANGE WITH T\n IF (X(I) .LE. T) GO TO 140\n X(IJ) = X(I)\n X(I) = T\n T = X(IJ)\n GO TO 140\n 135 TT = X(L)\n X(L) = X(K)\n X(K) = TT\n* FIND AN ELEMENT IN THE SECOND HALF OF\n* THE ARRAY WHICH IS SMALLER THAN T\n 140 L = L-1\n IF (X(L) .GT. T) GO TO 140\n* FIND AN ELEMENT IN THE FIRST HALF OF\n* THE ARRAY WHICH IS GREATER THAN T\n 145 K = K+1\n IF (X(K) .LT. T) GO TO 145\n* INTERCHANGE THESE ELEMENTS\n IF (K .LE. L) GO TO 135\n* SAVE UPPER AND LOWER SUBSCRIPTS OF\n* THE ARRAY YET TO BE SORTED\n IF (L-I .LE. J-K) GO TO 150\n IL(M) = I\n IU(M) = L\n I = K\n M = M+1\n GO TO 160\n 150 IL(M) = K\n IU(M) = J\n J = L\n M = M+1\n GO TO 160\n* BEGIN AGAIN ON ANOTHER PORTION OF\n* THE UNSORTED ARRAY\n 155 M = M-1\n IF (M .EQ. 0) GO TO 300\n I = IL(M)\n J = IU(M)\n 160 IF (J-I .GE. 1) GO TO 125\n IF (I .EQ. 1) GO TO 110\n I = I-1\n 165 I = I+1\n IF (I .EQ. J) GO TO 155\n T = X(I+1)\n IF (X(I) .LE. T) GO TO 165\n K = I\n 170 X(K+1) = X(K)\n K = K-1\n IF (T .LT. X(K)) GO TO 170\n X(K+1) = T\n GO TO 165\n*\n* SORT X AND CARRY Y ALONG\n*\n 200 CONTINUE\n M = 1\n I = 1\n J = NN\n R = .375\n 210 IF (I .EQ. J) GO TO 255\n 215 IF (R .GT. .5898437) GO TO 220\n R = R+3.90625E-2\n GO TO 225\n 220 R = R-.21875\n 225 K = I\n* SELECT A CENTRAL ELEMENT OF THE\n* ARRAY AND SAVE IT IN LOCATION T\n IJ = I + IDINT( DBLE(J-I) * R )\n T = X(IJ)\n TY = Y(IJ)\n* IF FIRST ELEMENT OF ARRAY IS GREATER\n* THAN T, INTERCHANGE WITH T\n IF (X(I) .LE. T) GO TO 230\n X(IJ) = X(I)\n X(I) = T\n T = X(IJ)\n Y(IJ) = Y(I)\n Y(I) = TY\n TY = Y(IJ)\n 230 L = J\n* IF LAST ELEMENT OF ARRAY IS LESS THAN\n* T, INTERCHANGE WITH T\n IF (X(J) .GE. T) GO TO 240\n X(IJ) = X(J)\n X(J) = T\n T = X(IJ)\n Y(IJ) = Y(J)\n Y(J) = TY\n TY = Y(IJ)\n* IF FIRST ELEMENT OF ARRAY IS GREATER\n* THAN T, INTERCHANGE WITH T\n IF (X(I) .LE. T) GO TO 240\n X(IJ) = X(I)\n X(I) = T\n T = X(IJ)\n Y(IJ) = Y(I)\n Y(I) = TY\n TY = Y(IJ)\n GO TO 240\n 235 TT = X(L)\n X(L) = X(K)\n X(K) = TT\n TTY = Y(L)\n Y(L) = Y(K)\n Y(K) = TTY\n* FIND AN ELEMENT IN THE SECOND HALF OF\n* THE ARRAY WHICH IS SMALLER THAN T\n 240 L = L-1\n IF (X(L) .GT. T) GO TO 240\n* FIND AN ELEMENT IN THE FIRST HALF OF\n* THE ARRAY WHICH IS GREATER THAN T\n 245 K = K+1\n IF (X(K) .LT. T) GO TO 245\n* INTERCHANGE THESE ELEMENTS\n IF (K .LE. L) GO TO 235\n* SAVE UPPER AND LOWER SUBSCRIPTS OF\n* THE ARRAY YET TO BE SORTED\n IF (L-I .LE. J-K) GO TO 250\n IL(M) = I\n IU(M) = L\n I = K\n M = M+1\n GO TO 260\n 250 IL(M) = K\n IU(M) = J\n J = L\n M = M+1\n GO TO 260\n* BEGIN AGAIN ON ANOTHER PORTION OF\n* THE UNSORTED ARRAY\n 255 M = M-1\n IF (M .EQ. 0) GO TO 300\n I = IL(M)\n J = IU(M)\n 260 IF (J-I .GE. 1) GO TO 225\n IF (I .EQ. 1) GO TO 210\n I = I-1\n 265 I = I+1\n IF (I .EQ. J) GO TO 255\n T = X(I+1)\n TY = Y(I+1)\n IF (X(I) .LE. T) GO TO 265\n K = I\n 270 X(K+1) = X(K)\n Y(K+1) = Y(K)\n K = K-1\n IF (T .LT. X(K)) GO TO 270\n X(K+1) = T\n Y(K+1) = TY\n GO TO 265\n*\n* CLEAN UP\n*\n 300 IF (KFLAG.GE.1) RETURN\n DO 310 I=1,NN\n 310 X(I) = -X(I)\n RETURN\n END \"\n", "meta": {"hexsha": "aaa4b4939bb1e4bb177a666abcc874a27a11c22c", "size": 57925, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Rascal_functions/eAnalysis/bayes/mcmcstat/src/gibbmain.f", "max_stars_repo_name": "Gingerfridge/RasCAL_2019", "max_stars_repo_head_hexsha": "efe5c97c1ec14ee4bd71c0bcfa58ff17d04406b8", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-02-24T15:58:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-06T17:49:42.000Z", "max_issues_repo_path": "Rascal_functions/eAnalysis/bayes/mcmcstat/src/gibbmain.f", "max_issues_repo_name": "Gingerfridge/RasCAL_2019", "max_issues_repo_head_hexsha": "efe5c97c1ec14ee4bd71c0bcfa58ff17d04406b8", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2020-03-04T14:11:29.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-05T14:25:55.000Z", "max_forks_repo_path": "lib/dependencies/mcmcstat-master/src/gibbmain.f", "max_forks_repo_name": "GarciaLab/mRNADynamics", "max_forks_repo_head_hexsha": "b0b221e03b6ab0eb5df443917e06494366cd318e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-12-08T16:44:51.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-08T16:44:51.000Z", "avg_line_length": 47.1318144833, "max_line_length": 80, "alphanum_fraction": 0.3485886923, "num_tokens": 11028, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070084811306, "lm_q2_score": 0.718594386544335, "lm_q1q2_score": 0.6538540685718891}} {"text": "program main\n use matrix_module\n implicit none\n\n type(vector) :: vec1, vec2\n type(matrix) :: mat1, mat2\n real :: x\n integer :: i\n\n ! 0s, id, random\n mat1 = zeros(3,3)\n call mat1%destruct()\n mat1 = identity(3,3)\n mat2 = random(3,3)\n mat1 = mat1*mat1\n vec1 = zeros(3)\n call vec1%destruct()\n vec1 = random(3)\n vec2 = random(3)\n ! +,-,*,/,**\n mat1 = mat1+mat2\n vec1 = vec1+vec2\n mat1 = mat1-mat2\n vec1 = vec1-vec2\n vec1 = mat1*vec2\n mat1 = mat2*mat1\n mat1 = 2.0*mat1\n vec1 = 2.0*vec1\n mat1 = mat1/2.0\n vec1 = vec1/2.0\n mat2 = mat1**3\n ! norm\n x = norm(vec1,0)\n x = norm(vec1,1)\n x = norm(mat1,-1)\n x = norm(mat1,0)\n x = norm(mat1,1)\n x = norm(mat1,2)\n call vec1%destruct\n call vec2%destruct\n call mat1%destruct\n call mat2%destruct\nend program main\n", "meta": {"hexsha": "d01f641a9032ab4162c80a6219144d9bfebad281", "size": 783, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "teaching/acm-computing-seminar/resources/langs/fortran/power/main.f90", "max_stars_repo_name": "notmatthancock/notmatthancock.github.io", "max_stars_repo_head_hexsha": "abcd91cc7c2653c5243fe96ba2fd681ec03930bb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "teaching/acm-computing-seminar/resources/langs/fortran/power/main.f90", "max_issues_repo_name": "notmatthancock/notmatthancock.github.io", "max_issues_repo_head_hexsha": "abcd91cc7c2653c5243fe96ba2fd681ec03930bb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "teaching/acm-computing-seminar/resources/langs/fortran/power/main.f90", "max_forks_repo_name": "notmatthancock/notmatthancock.github.io", "max_forks_repo_head_hexsha": "abcd91cc7c2653c5243fe96ba2fd681ec03930bb", "max_forks_repo_licenses": ["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.7954545455, "max_line_length": 28, "alphanum_fraction": 0.6053639847, "num_tokens": 345, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.909907001151883, "lm_q2_score": 0.718594386544335, "lm_q1q2_score": 0.653854063305133}} {"text": "*\n* -------------------------------------------------------------\n* N I N E 1 2\n* -------------------------------------------------------------\n*\n* *\n* THIS PACKAGE DETERMINES THE VALUES OF 9j COEFFICIENT *\n* *\n* | J1/2 J2/2 J3/2 | *\n* | L1/2 L2/2 J3/2 | *\n* | K1/2 + 1 K1/2 1 | *\n* *\n* Written by G. Gaigalas, * \n* Vanderbilt University, Nashville October 1996 * \n*\n SUBROUTINE NINE12(J1,J2,J3,L1,L2,K1,A)\n IMPLICIT DOUBLEPRECISION (A-H,O-Z)\n COMMON/CONSTS/ZERO,TENTH,HALF,ONE,TWO,THREE,FOUR,SEVEN,ELEVEN,EPS\n K2=K1-2\n CALL SIXJ(J1,L1,K1,L2,J2,J3,0,S1)\n SKAI1=DBLE(J2-L2+K1)*DBLE(L2-J2+K1)*DBLE(J2+L2+K2+4)*\n :DBLE(J2+L2-K2)\n S1=S1*DSQRT(SKAI1)\n CALL SIXJ(J1,L1,K2,L2,J2,J3,0,S2)\n SKAI2=DBLE(J1-L1+K1)*DBLE(L1-J1+K1)*DBLE(J1+L1+K2+4)*\n :DBLE(J1+L1-K2)\n S2=S2*DSQRT(SKAI2)\n S=S1+S2\nC VARD=DSQRT(DBLE(8*(K2+3)*(K2+2)*(K2+1)*J3*(J3+2)*(J3+1)))\n VARD=DSQRT(DBLE(8*(K2+3))*DBLE(K2+2)*DBLE(K2+1)*DBLE(J3)*\n :DBLE(J3+2)*DBLE(J3+1))\n A=S/VARD\n IF(MOD(L1+J2+K2+J3,4).NE.0) A=-A \n RETURN\n END\n\n\n", "meta": {"hexsha": "64a9611842307a356161d4925e724aa3ce8e8a24", "size": 1500, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/lib/libang/nine12.f", "max_stars_repo_name": "mansour2014/ATSP2K_plus", "max_stars_repo_head_hexsha": "30842b9f086d1e497aeb778e2a352d1e8e520ec3", "max_stars_repo_licenses": ["BSD-4-Clause-UC"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-07-21T14:03:39.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-21T14:03:39.000Z", "max_issues_repo_path": "src/lib/libang/nine12.f", "max_issues_repo_name": "mzmansour/ATSP2K_plus", "max_issues_repo_head_hexsha": "30842b9f086d1e497aeb778e2a352d1e8e520ec3", "max_issues_repo_licenses": ["BSD-4-Clause-UC"], "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/libang/nine12.f", "max_forks_repo_name": "mzmansour/ATSP2K_plus", "max_forks_repo_head_hexsha": "30842b9f086d1e497aeb778e2a352d1e8e520ec3", "max_forks_repo_licenses": ["BSD-4-Clause-UC"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.4736842105, "max_line_length": 71, "alphanum_fraction": 0.3586666667, "num_tokens": 525, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569267, "lm_q2_score": 0.724870282120402, "lm_q1q2_score": 0.6537754914242309}} {"text": "subroutine mdim_gls(t, y, err, freqs, t_ref, coeffs, A)\n\n !implicit Real*4 (a-h,o-z)\n Real*4, intent(in) :: t(:), y(:), err(:)\n Real*4, intent(in) :: freqs(:), t_ref\n Real*4, intent(out):: coeffs(2*size(freqs)+1)\n Real*4 :: F(size(t),2*size(freqs)+1), Ft(2*size(freqs)+1, size(t)), b(2*size(freqs)+1), y_err(size(t))\n Real*4 , intent(out):: A(2*size(freqs)+1,2*size(freqs)+1)\n Real*4 :: pi=acos(-1.0)\n integer :: i, j, k, n_dim, LS_INFO, pivot(2*size(freqs)+1)\n\n n_dim = size(freqs)\n n_data = size(t)\n\n do k = 1, 2*n_dim+1\n if (k.EQ.1) then\n do j = 1,n_data\n F(j,k) = 1.0/err(j)\n enddo\n else if ((k.GT.1).AND.(k.LE.(n_dim+1))) then\n do j = 1,n_data\n F(j,k) = cos(2.0*pi*(t(j)-t_ref)*freqs(k-1))/err(j)\n enddo\n else if ((k.GT.(n_dim+1)).AND.(k.LT.(2*n_dim+2))) then\n do j = 1,n_data\n F(j,k) = sin(2.0*pi*(t(j)-t_ref)*freqs(k-(n_dim+1)))/err(j)\n enddo\n !else if (k.EQ.(2*n_dim+2)) then\n ! do j = 1,n_data\n ! F(j,k) = (t(j)-t_ref)/err(j)\n ! enddo\n endif\n enddo\n \n do i =1,n_data\n y_err(i) = y(i)/err(i)\n enddo\n !arrange linear system F_t*F*theta = F_t*y_e --> A*theta = b\n Ft = transpose(F)\n A = matmul(Ft,F)\n b = matmul(Ft,y_err)\n !solves a system of linear equations A*X = B \n call SGESV(2*n_dim+1, 1, A, 2*n_dim+1, pivot, b, 2*n_dim+1, LS_INFO)\n !fill output vector: fitting coeffs.\n do i = 1,2*n_dim+1\n coeffs(i) = b(i)\n enddo\n\nend subroutine mdim_gls\n\nsubroutine mdim_gls_multiset(times, rvs, errs, freqs, jitters, len_sets, coeffs, A)\n\n !implicit Real*4 (a-h,o-z)\n real, intent(in) :: times(:), rvs(:), errs(:)\n real, intent(in) :: freqs(:), jitters(:)\n integer, intent(in) :: len_sets(:)\n real, intent(out):: coeffs(2*size(freqs)+size(len_sets))\n real :: F(size(times),2*size(freqs)+size(len_sets)), Ft(2*size(freqs)+size(len_sets), size(times))\n real :: b(2*size(freqs)+size(len_sets)), y_err(size(times))\n real, intent(out):: A(2*size(freqs)+size(len_sets),2*size(freqs)+size(len_sets))\n real :: pi=acos(-1.0), t_ref = 0.0, errs_jitter(size(times))\n integer :: i, j, k, final, n_dim, n_sets, LS_INFO, pivot(2*size(freqs)+size(len_sets))\n integer :: init_times(size(len_sets)) \n \n !number of datasets\n n_sets = size(len_sets)\n !total length of data (list of all datasets concatenated)\n n_data = size(times)\n !num of dimensions\n n_dim = size(freqs)\n \n !init times for each set (store array index)\n ind = 1\n do i = 1, n_sets\n init_times(i) = ind\n ind = ind + len_sets(i)\n enddo\n \n !init matrix\n do k = 1, 2*n_dim + n_sets \n do j = 1, n_data\n F(j,k) = 0.0\n enddo\n enddo\n \n !fill offsets + jitters\n do k = 1, n_sets\n if (k.EQ.n_sets) then\n final = n_data\n else\n final = init_times(k+1) - 1 \n endif\n \n do j = init_times(k), final\n errs_jitter(j) = SQRT(errs(j)**2.0 + jitters(k)**2.0) !redefinition of errs variable to include jitters\n F(j,k) = 1.0/(errs_jitter(j))\n enddo\n enddo\n \n t_ref = times(1)\n !fill {cos,sin} elements\n do 11 k = n_sets, 2*n_dim + n_sets\n if ((k.GT.n_sets).AND.(k.LE.(n_dim+n_sets))) then\n do j = 1,n_data\n F(j,k) = cos(2.0*pi*(times(j)-t_ref)*freqs(k-n_sets))/errs_jitter(j)\n enddo \n \n else if ((k.GT.(n_dim+n_sets)).AND.(k.LE.(2*n_dim+n_sets))) then\n do j = 1,n_data\n F(j,k) = sin(2.0*pi*(times(j)-t_ref)*freqs(k-(n_dim+n_sets)))/errs_jitter(j)\n enddo\n \n endif \n \n11 enddo\n ! b array\n do i = 1, n_data\n y_err(i) = rvs(i)/errs_jitter(i)\n enddo\n\n !arrange linear system F_t*F*theta = F_t*y_e --> A*theta = b\n Ft = transpose(F)\n A = matmul(Ft,F)\n b = matmul(Ft,y_err)\n !call sgemm('t','n',2*n_dim+n_sets,2*n_dim+n_sets,n_data,1.0,F,n_data,F,n_data,0.0,A,2*n_dim+n_sets)\n !call sgemm('t','n',2*n_dim+n_sets,1,n_data,1.0,F,n_data,y_err,n_data,0,b,2*n_dim+n_sets)\n \n !solves a system of linear equations A*X = B \n !call SPOSV('U', 2*n_dim+n_sets, 1, A, 2*n_dim+n_sets, b, 2*n_dim+n_sets, LS_INFO)\n call SGESV(2*n_dim+n_sets, 1, A, 2*n_dim+n_sets, pivot, b, 2*n_dim+n_sets, LS_INFO)\n \n !fill output vector: fitting coeffs.\n do i = 1, 2*n_dim + n_sets \n coeffs(i) = b(i)\n enddo\n \n\nend subroutine mdim_gls_multiset\n\nsubroutine mdim_gls_multiset_trend(times, rvs, errs, freqs, jitters, len_sets, coeffs, A)\n\n !implicit Real*4 (a-h,o-z)\n real, intent(in) :: times(:), rvs(:), errs(:)\n real, intent(in) :: freqs(:), jitters(:)\n integer, intent(in) :: len_sets(:)\n real, intent(out):: coeffs(2*size(freqs)+size(len_sets)+1)\n real :: F(size(times),2*size(freqs)+size(len_sets)+1), Ft(2*size(freqs)+size(len_sets)+1, size(times))\n real :: b(2*size(freqs)+size(len_sets)+1), y_err(size(times))\n real, intent(out):: A(2*size(freqs)+size(len_sets)+1,2*size(freqs)+size(len_sets)+1)\n real :: pi=acos(-1.0), t_ref = 0.0, errs_jitter(size(times))\n integer :: i, j, k, final, n_dim, n_sets, LS_INFO, pivot(2*size(freqs)+size(len_sets)+1)\n integer :: init_times(size(len_sets)) \n \n !number of datasets\n n_sets = size(len_sets)\n !total length of data (list of all datasets concatenated)\n n_data = size(times)\n !num of dimensions\n n_dim = size(freqs)\n \n !init times for each set (store array index)\n ind = 1\n do i = 1, n_sets\n init_times(i) = ind\n ind = ind + len_sets(i)\n enddo\n \n !init matrix\n do k = 1, 2*n_dim + n_sets + 1\n do j = 1, n_data\n F(j,k) = 0.0\n enddo\n enddo\n \n !fill offsets + jitters\n do k = 1, n_sets\n if (k.EQ.n_sets) then\n final = n_data\n else\n final = init_times(k+1) - 1 \n endif\n \n do j = init_times(k), final\n errs_jitter(j) = SQRT(errs(j)**2.0 + jitters(k)**2.0) !redefinition of errs variable to include jitters\n F(j,k) = 1.0/(errs_jitter(j))\n enddo\n enddo\n \n t_ref = times(1)\n !fill {cos,sin} elements\n do 11 k = n_sets, 2*n_dim + n_sets + 1\n if ((k.GT.n_sets).AND.(k.LE.(n_dim+n_sets))) then\n do j = 1,n_data\n F(j,k) = cos(2.0*pi*(times(j)-t_ref)*freqs(k-n_sets))/errs_jitter(j)\n enddo \n \n else if ((k.GT.(n_dim+n_sets)).AND.(k.LE.(2*n_dim+n_sets))) then\n do j = 1,n_data\n F(j,k) = sin(2.0*pi*(times(j)-t_ref)*freqs(k-(n_dim+n_sets)))/errs_jitter(j)\n enddo\n \n else if (k.GT.(2*n_dim+n_sets)) then\n do j = 1,n_data\n F(j,k) = (times(j)-t_ref)/errs_jitter(j)\n enddo\n \n endif \n \n11 enddo\n ! b array\n do i = 1, n_data\n y_err(i) = rvs(i)/errs_jitter(i)\n enddo\n\n !arrange linear system F_t*F*theta = F_t*y_e --> A*theta = b\n Ft = transpose(F)\n A = matmul(Ft,F)\n b = matmul(Ft,y_err)\n !call sgemm('t','n',2*n_dim+n_sets+1,2*n_dim+n_sets+1,n_data,1.0,F,n_data,F,n_data,0.0,A,2*n_dim+n_sets+1)\n !call sgemm('t','n',2*n_dim+n_sets+1,1,n_data,1.0,F,n_data,y_err,n_data,0,b,2*n_dim+n_sets+1)\n !solves a system of linear equations A*X = B \n !call SPOSV('U', 2*n_dim+n_sets+1, 1, A, 2*n_dim+n_sets+1, b, 2*n_dim+n_sets+1, LS_INFO)\n call SGESV(2*n_dim+n_sets+1, 1, A, 2*n_dim+n_sets+1, pivot, b, 2*n_dim+n_sets+1, LS_INFO)\n \n !fill output vector: fitting coeffs.\n do i = 1, 2*n_dim + n_sets + 1\n coeffs(i) = b(i)\n enddo\n \n\nend subroutine mdim_gls_multiset_trend\n\nsubroutine model(t_p, t_ref, freqs, fitting_coeffs, y_model)\n !computes model according to fitting coefficients, frequencies\n double precision, intent(in) :: t_p, t_ref, fitting_coeffs(:), freqs(:)\n double precision, intent(out) :: y_model\n double precision :: pi=dacos(-1.0d0)\n integer :: k, n_dim\n \n n_dim = size(freqs)\n y_model = 0.0\n do k = 1,size(fitting_coeffs)\n if (k.EQ.1) then\n y_model = y_model + fitting_coeffs(k)\n else if ((k.GT.1).AND.(k.LE.(n_dim+1))) then\n y_model = y_model + &\n fitting_coeffs(k)*cos(2.0*pi*(t_p-t_ref)*freqs(k-1))\n else if ((k.GT.(n_dim+1)).AND.(k.LT.(2*n_dim+2))) then\n y_model = y_model + &\n fitting_coeffs(k)*sin(2.0*pi*(t_p-t_ref)*freqs((k-(n_dim+1))))\n !else if (k.EQ.(2*n_dim+2)) then\n ! y_model = y_model + fitting_coeffs(k)*(t_p-t_ref)\n endif\n enddo\n\nend subroutine model\n\nsubroutine model_series(t, t_ref, freqs, fitting_coeffs, n_points, y_model_s)\n !computes model according to fitting coefficients, frequencies\n double precision, intent(in) :: t(:), t_ref, fitting_coeffs(:), freqs(:)\n integer, intent(in) :: n_points\n double precision, intent(out) :: y_model_s(n_points)\n double precision :: pi=dacos(-1.0d0), y_model\n integer :: k, n_dim\n \n n_dim = size(freqs)\n\n do i = 1,n_points\n y_model = 0.0\n do k = 1,size(fitting_coeffs)\n if (k.EQ.1) then\n y_model = y_model + fitting_coeffs(k)\n else if ((k.GT.1).AND.(k.LE.(n_dim+1))) then\n y_model = y_model + &\n fitting_coeffs(k)*cos(2.0*pi*(t(i)-t_ref)*freqs(k-1))\n else if ((k.GT.(n_dim+1)).AND.(k.LT.(2*n_dim+2))) then\n y_model = y_model + &\n fitting_coeffs(k)*sin(2.0*pi*(t(i)-t_ref)*freqs((k-(n_dim+1))))\n else if (k.EQ.(2*n_dim+2)) then !if exists a linear trend slope\n y_model = y_model + fitting_coeffs(k)*(t(i)-t_ref)\n endif\n enddo\n y_model_s(i) = y_model \n enddo\n \nend subroutine model_series\n\nsubroutine model_series_multiset(times, freqs, fitting_coeffs, len_sets, y_model_s)\n !computes model according to fitting coefficients, frequencies\n double precision, intent(in) :: times(:), fitting_coeffs(:), freqs(:)\n integer, intent(in) :: len_sets(:)\n double precision, intent(out) :: y_model_s(size(times))\n double precision :: pi=dacos(-1.0d0), y_model, t_ref\n integer :: i, k, s, n_dim, n_sets, n_data, ind, init_times(size(len_sets)), end_data\n \n n_dim = size(freqs)\n n_data = size(times)\n n_sets = size(len_sets)\n \n !init times (store array index)\n ind = 1\n do i = 1, n_sets\n init_times(i) = ind\n ind = ind + len_sets(i)\n enddo\n !reference time\n t_ref = times(1)\n \n do s = 1, n_sets \n !define indexes in concatenated list of data\n if (s.EQ.n_sets) then\n end_data = n_data\n else\n end_data = init_times(s+1) - 1 \n endif\n \n do i = init_times(s), end_data \n y_model = 0.0\n do k = 1,size(fitting_coeffs)\n if (k.EQ.s) then\n y_model = y_model + fitting_coeffs(k)\n else if ((k.GT.n_sets).AND.(k.LE.(n_dim+n_sets))) then\n y_model = y_model + &\n fitting_coeffs(k)*cos(2.0*pi*(times(i)-t_ref)*freqs(k-n_sets))\n else if ((k.GT.(n_dim+n_sets)).AND.(k.LT.(2*n_dim+n_sets+1))) then\n y_model = y_model + &\n fitting_coeffs(k)*sin(2.0*pi*(times(i)-t_ref)*freqs((k-(n_dim+n_sets))))\n \n endif\n enddo\n y_model_s(i) = y_model \n enddo\n \n enddo\n \nend subroutine model_series_multiset\n\nsubroutine chi2(t, y, err, t_ref, freqs, fitting_coeffs, chi2_out)\n! computes chi2 between data and model\n double precision, intent(in) :: t(:), y(:), err(:), t_ref\n double precision, intent(in) :: freqs(:), fitting_coeffs(:)\n double precision, intent(out) :: chi2_out\n double precision :: y_model\n double precision :: pi=dacos(-1.0d0)\n integer :: i, k, n_dim\n \n n_dim = size(freqs)\n chi2_out = 0.0\n do 97 i = 1, size(t)\n y_model = 0.0\n !call model(t(i), t_ref, freqs, fitting_coeffs, y_model)\n do k = 1,size(fitting_coeffs)\n if (k.EQ.1) then\n y_model = y_model + fitting_coeffs(k)\n else if ((k.GT.1).AND.(k.LE.(n_dim+1))) then\n y_model = y_model + &\n fitting_coeffs(k)*cos(2.0*pi*(t(i)-t_ref)*freqs(k-1))\n else if ((k.GT.(n_dim+1)).AND.(k.LT.(2*n_dim+2))) then\n y_model = y_model + &\n fitting_coeffs(k)*sin(2.0*pi*(t(i)-t_ref)*freqs((k-(n_dim+1))))\n !else if (k.EQ.(2*n_dim+2)) then\n ! y_model = y_model + fitting_coeffs(k)*(t(i)-t_ref)\n endif\n enddo\n chi2_out = chi2_out + (1.0/(err(i)*err(i)))*(y(i) - y_model)**2.0\n97 continue\n\nend subroutine chi2\n\nsubroutine chi2_0(y, err, chi2_0_out)\n! computes chi2 respect to the mean\n double precision, intent(in) :: y(:), err(:)\n double precision, intent(out) :: chi2_0_out\n double precision :: mean_y\n integer :: i\n\n chi2_0_out = 0.0\n mean_y = 0.0\n do 96 j = 1,size(y)\n mean_y = mean_y + y(j)\n96 continue\n mean_y = mean_y/size(y)\n\n do 97 i = 1,size(y)\n chi2_0_out = chi2_0_out + &\n (1.0/(err(i)*err(i)))*(y(i) - mean_y)**2.0\n97 continue\n\nend subroutine chi2_0\n\nsubroutine residuals(t, y, t_ref, freqs, fitting_coeffs, residuals_out)\n! computes chi2 between data and model\n double precision, intent(in) :: t(:), y(:), t_ref\n double precision, intent(in) :: freqs(:), fitting_coeffs(:)\n double precision, intent(out) :: residuals_out(size(t))\n double precision :: y_model\n double precision :: pi=dacos(-1.0d0)\n integer :: i, k, n_dim\n \n n_dim = size(freqs)\n do 97 i = 1, size(t)\n !call model(time_p, t_ref, periods, fitting_coeffs, y_model)\n y_model = 0.0\n do k = 1,size(fitting_coeffs)\n if (k.EQ.1) then\n y_model = y_model + fitting_coeffs(k)\n else if ((k.GT.1).AND.(k.LE.(n_dim+1))) then\n y_model = y_model + &\n fitting_coeffs(k)*cos(2.0*pi*(t(i)-t_ref)*freqs(k-1))\n else if ((k.GT.(n_dim+1)).AND.(k.LT.(2*n_dim+2))) then\n y_model = y_model + &\n fitting_coeffs(k)*sin(2.0*pi*(t(i)-t_ref)*freqs((k-(n_dim+1)))) \n !else if (k.EQ.(2*n_dim+2)) then\n ! y_model = y_model + fitting_coeffs(k)*(t(i)-t_ref)\n endif\n enddo\n residuals_out(i) = y(i) - y_model\n97 continue\n\nend subroutine residuals\n", "meta": {"hexsha": "9ac060f42aae7e72255c938eae19e0a1a248865b", "size": 14809, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/mMGLS.f95", "max_stars_repo_name": "rosich/mgls", "max_stars_repo_head_hexsha": "64c924f59adba2dddf44bb70a84868173f0b7120", "max_stars_repo_licenses": ["MIT"], "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/mMGLS.f95", "max_issues_repo_name": "rosich/mgls", "max_issues_repo_head_hexsha": "64c924f59adba2dddf44bb70a84868173f0b7120", "max_issues_repo_licenses": ["MIT"], "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/mMGLS.f95", "max_forks_repo_name": "rosich/mgls", "max_forks_repo_head_hexsha": "64c924f59adba2dddf44bb70a84868173f0b7120", "max_forks_repo_licenses": ["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.1757719715, "max_line_length": 116, "alphanum_fraction": 0.553042069, "num_tokens": 4791, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206765295399, "lm_q2_score": 0.7248702761768248, "lm_q1q2_score": 0.6537754898855562}} {"text": "! ------------------------------------------------------------------------------\n! DIFFUSION_COEFFICIENTS\n! Compute atomic diffusion coefficients, according to Paquette et al. 1986\n!\n! This function only calculates the first order coefficients at the moment,\n! but calculating the second order corrections (as well as the coefficient\n! for thermodiffusion) is not difficult.\n! ------------------------------------------------------------------------------\n! Input:\n! * rho: Density [g/cm^3]\n! * T: Temperature\n! * abund: Abundance struct\n! Output:\n! * Ddiff(9): Diffusion coefficients [cm^2/s] for the 9 isotopes H, He, C,\n! n, O, Ne, Mg, Si and Fe.\n! ------------------------------------------------------------------------------\nsubroutine diffusion_coefficients(rho, T, abund, Ddiff, Nref)\n use real_kind\n use constants\n use paquette_coefficients\n use atomic_data\n use eostate_types\n\n implicit none\n ! Input and output variables\n real(double), intent(in) :: rho, T\n type(abundance), intent(in) :: abund\n real(double), intent(out) :: Ddiff(9)\n integer, intent(in) :: Nref ! Reference abundance (H)\n ! Local variables\n ! Lengthscales for the plasma\n real(double) :: lambda_I2, lambda_D2, lambda2\n ! Baryon density\n real(double) :: Nb\n ! Convenience, to precalculate as much as possible\n real(double) :: kT, gamma2\n ! Collision integrals Omega (eqn. (18) in Paquette et al)\n real(double) :: OMEGA1(3), OMEGA22\n ! Dimensionless collision integrals (eqn. (65) in Paquette et al)\n real(double) :: F1(3), F22\n ! Local variables\n real(double) :: psi_st, eps_st, gamma_st2, A, e_psi_st\n real(double) :: dpsi_n1, dpsi_n\n integer :: i, j, n\n ! Local copy of struct variables\n real(double) :: NA(9), NIO, NZZ, AVM, Ne\n\n na = abund%na\n nio = abund%nio\n nzz = abund%nzz\n avm = abund%avm\n na = abund%na\n Ne = abund%ne\n\n Nb = rho/(AVM*AMU)\n kT = BOLTZM*T\n\n ! Typical distance between ions (squared)\n lambda_I2 = (3.0/(CPI4*Nb*NIO))**(2.0D0*C3RD)\n ! Debye length (squared) \n lambda_D2 = (kT/(CPI4 * ECHAR**2 * Nb * (NZZ+Ne)))\n ! Use max of lambda_i and lambda_D as typical distance\n lambda2 = MAX(lambda_D2, lambda_I2)\n ! Precompute some factors\n gamma2 = (4.0*kT/(ECHAR**2*KZN(Nref)))**2*lambda2\n do i=1, 9\n gamma_st2 = gamma2/KZN(i)**2\n ! Reduced mass of the two particles\n A = (CAN(i)*CAN(Nref)/(CAN(i)+CAN(Nref)))\n ! Units of Omega: length^2 * velocity\n eps_st = CPI4*lambda2/gamma_st2 * SQRT(2.0D0*kT/(CPI4 * AMU*A))\n ! Find interpolation interval for dimensionless collision integral\n e_psi_st = log(1.0D0+gamma_st2)\n psi_st = log(e_psi_st)\n ! Evaluate the collision integral, for repulsive coefficients\n if (psi_st < 3.0D0) then\n ! Use spline interpolation to evaluate the collision integrals\n ! Determine interval in the table\n n = MIN(50, 1+floor((psi_st +7d0)/0.2d0))\n dpsi_n1 = (-7.0D0 + 0.2D0*(n+1)) - psi_st\n dpsi_n = psi_st - (-7.0D0 + 0.2D0*n)\n do j=1,3\n F1(j) = exp(DC(1,n,j)*dpsi_n1**3 + DC(2,n,j)*dpsi_n**3 &\n + DC(3,n,j)*dpsi_n1 + DC(4,n,j)*dpsi_n)\n end do\n F22 = exp(DD(1,n)*dpsi_n1**3 + DD(2,n)*dpsi_n**3 &\n + DD(3,n)*dpsi_n1 + DD(4,n)*dpsi_n)\n else\n F1(1) = 1.00141D0*e_psi_st - 3.18209D0\n F1(2) = 0.99559D0*e_psi_st - 1.29553D0\n F1(3) = 1.99814D0*e_psi_st - 0.64413D0\n F22 = 1.99016D0*e_psi_st - 4.56958D0\n end if\n OMEGA1(:) = eps_st*F1(:)\n OMEGA22 = eps_st*F22\n\n ! Diffusion coefficient\n Ddiff(i) = 3.0*kT/(16.0*rho*(NA(Nref)+NA(i))*A*OMEGA1(1))\n end do\nend subroutine diffusion_coefficients\n\n\n\n! ------------------------------------------------------------------------------\n! COMPUTE_FULL_DIFFUSION_COEFFS\n! Compute atomic diffusion coefficients, according to Paquette et al. (1986)\n! This is essentially the same as the above subroutine, but it computes\n! extra terms needed for the Burgers formalism.\n! The output are the resistance coefficients in Burgers equations K_ij,\n! z_ij, z'_ij and z''_ij. It is also possible to output diffusion\n! coefficients D_ij and thermal diffusion coeffcient A_th used in\n! Cowling&Chapman formalism, note Ath(NN,i) is Ath_ei.\n! ------------------------------------------------------------------------------\n! Input:\n! (rho - Density [g/cm^3])\n! T - Temperature [k]\n! NN - Number of species (NN = electrons)\n! CAN(i) - Mass numbers for species [amu]\n! KZN(i) - Average charge of species [e]\n! NA(i) - Number densities of species [cm^-3]\n! Output:\n! Kdiff(i,j) - Coefficient for Burgers equations\n! Zdiff(i,j) - Coefficient for Burgers equations\n! Zdiff1(i,j) - Coefficient for Burgers equations\n! Zdiff2(i,j) - Coefficient for Burgers equations\n! ------------------------------------------------------------------------------\n!subroutine compute_full_diffusion_coeffs(rho, T, NN, CAN1, KZN1, NA1, Kdiff, Zdiff, Zdiff1, Zdiff2) !Rho not used\nsubroutine compute_full_diffusion_coeffs(T, NN, CAN1, KZN1, NA1, Kdiff, Zdiff, Zdiff1, Zdiff2)\n use real_kind\n use constants\n use paquette_coefficients\n\n implicit none\n ! Input and output variables\n integer, intent(in) :: NN\n real(double), intent(in) :: T, CAN1(NN), KZN1(NN), NA1(NN)\n real(double), intent(out) :: Kdiff(NN,NN), Zdiff(NN,NN), Zdiff1(NN,NN), Zdiff2(NN,NN)\n\n ! Local variables\n ! Lengthscales for the plasma\n real(double) :: lambda_I2, lambda_D2, lambda2\n\n ! Ion density\n real(double) :: NI\n\n ! Convenience, to precalculate as much as possible\n real(double) :: kT, gamma2\n\n ! Collision integrals Omega (eqn. (18) in Paquette et al)\n real(double) :: OMEGA1(3), OMEGA22, OMEGA2(NN)\n\n ! Dimensionless collision integrals (eqn. (65) in Paquette et al)\n real(double) :: F1(3), F22\n\n ! Local variables\n !real(double) :: Ddiff(NN,NN), Ath(NN, NN)\n real(double) :: psi_st, eps_st, gamma_st2, A, e_psi_st\n real(double) :: AA, BB, CC, EE, Ps, Pt, Pst, Qs, Qt, Qst, Ss\n real(double) :: St, Ms, Mt, Xs, Xt\n !real(double) :: Xe, Me, Pe, Se, Qe, Qet, DELTA\n real(double) :: dpsi_n1, dpsi_n\n integer :: i, j, n, Nref\n real(double) :: NZZ, Ne\n real(double) :: kz(NN)\n\n F22 = 0.0d0 ! Always defined\n\n Ne = NA1(NN)\n NI = 0.0D0\n NZZ = 0.0D0\n do i = 1, NN-1\n NI = NI + NA1(i)\n NZZ = NZZ + KZN1(i)**2 * NA1(i)\n end do\n\n ! Charge, bearing in mind that some species might be neutral.\n ! In this case, we simply treat them as singly ionised.\n ! TODO: we could include a fudge-factor to scale the singly ionised cross\n ! section.\n kz = kzn1\n where (kz == 0) kz = 1\n\n kT = BOLTZM*T\n ! Typical distance between ions (squared)\n lambda_I2 = (3.0D0/(CPI4*NI))**(2.0D0/3.0D0)\n ! Debye length (squared)\n lambda_D2 = (kT/(CPI4 * ECHAR**2 * (Ne + NZZ)))\n ! Use max of lambda_i and lambda_d as typical distance\n lambda2 = MAX(lambda_D2, lambda_I2)\n\n ! First evaluate the collision intergrals OMEGA22_SS, that appear in Ps (eq (9) of Paquette 1986)\n do i = 1, NN\n gamma2 = (4.0D0*kT/(ECHAR**2*KZ(i)))**2*lambda2\n gamma_st2 = gamma2/KZ(i)**2\n\n ! Reduced mass of the two particles [amu]\n A = 0.5d0 * CAN1(i)\n\n ! Units of Omega: length^2 * velocity\n eps_st = CPI4*lambda2/gamma_st2 * SQRT(2.0D0*kT/(CPI4 * AMU*A))\n\n ! Find interpolation interval for dimensionless collision integral\n ! Use boundary value if out of range (may never happen)\n e_psi_st = log(1.0D0+gamma_st2)\n psi_st = MAX(-7.0d0, log(e_psi_st))\n\n ! Evaluate the collision integral\n if (psi_st <= 3.0D0) then\n ! Use spline interpolation to evaluate the collision integrals\n ! Determine interval in the table\n n = MIN(50, 1+floor((psi_st +7d0)/0.2d0))\n dpsi_n1 = (-7.2D0 + 0.2D0*(n+1)) - psi_st\n dpsi_n = psi_st - (-7.2D0 + 0.2D0*n)\n\n ! repulsive potential (ion-ion or electron-electron)\n F22 = exp(DD(1,n)*dpsi_n1**3 + DD(2,n)*dpsi_n**3 &\n + DD(3,n)*dpsi_n1 + DD(4,n)*dpsi_n)\n else if (psi_st > 3.0D0 .and. psi_st < 4.0d0) then\n ! repulsive potential (ion-ion or electron-electron)\n F22 = 1.99016D0*e_psi_st - 4.56958D0\n else\n ! repulsive and attractive coeffcients are the same in this range\n F22 = 1.99016D0*e_psi_st - 4.56958D0\n end if\n OMEGA2(i) = eps_st*F22\n end do ! i\n\n do Nref = 1, NN\n gamma2 = (4.0D0*kT/(ECHAR**2*KZ(Nref)))**2 * lambda2\n do i = 1, NN\n gamma_st2 = gamma2/KZ(i)**2\n\n ! Reduced mass of the two particles:\n A = (CAN1(i)*CAN1(Nref)/(CAN1(i)+CAN1(Nref))) ! in units of AMU\n\n ! Units of Omega: length^2 * velocity:\n eps_st = CPI4*lambda2/gamma_st2 * SQRT(2.0D0*kT/(CPI4 * AMU*A))\n\n ! Find interpolation interval for dimensionless collision integral:\n e_psi_st = log(1.0D0+gamma_st2)\n psi_st = log(e_psi_st)\n\n ! Evaluate the collision integral:\n if (psi_st <= 3.0D0) then\n\n ! If psi_st falls outside range of Paquette fit, then just take border value, will probably never happen:\n psi_st = MAX(-7.D0, psi_st)\n\n ! Use spline interpolation to evaluate the collision integrals\n ! Determine interval in the table\n n = MIN(50, 1+floor((psi_st +7d0)/0.2d0))\n dpsi_n1 = (-7.2D0 + 0.2D0*(n+1)) - psi_st\n dpsi_n = psi_st - (-7.2D0 + 0.2D0*n)\n if ((Nref==NN.and.Nref/=i) .or. (i==NN.and.Nref/=i)) then\n ! attractive potential (electron-ion)\n do j=1,3\n F1(j) = exp(DCAT(1,n,j)*dpsi_n1**3 + DCAT(2,n,j)*dpsi_n**3 &\n + DCAT(3,n,j)*dpsi_n1 + DCAT(4,n,j)*dpsi_n)\n end do\n F22 = exp(DDAT(1,n)*dpsi_n1**3 + DDAT(2,n)*dpsi_n**3 &\n + DDAT(3,n)*dpsi_n1 + DDAT(4,n)*dpsi_n)\n ! repulsive potential (ion-ion or electron-electron)\n else\n do j=1,3\n F1(j) = exp(DC(1,n,j)*dpsi_n1**3 + DC(2,n,j)*dpsi_n**3 &\n + DC(3,n,j)*dpsi_n1 + DC(4,n,j)*dpsi_n)\n end do\n F22 = exp(DD(1,n)*dpsi_n1**3 + DD(2,n)*dpsi_n**3 &\n + DD(3,n)*dpsi_n1 + DD(4,n)*dpsi_n)\n end if\n else if (psi_st > 3.0D0.and.psi_st < 4.0d0) then\n if ((Nref==NN.and.Nref/=i) .or. (i==NN.and.Nref/=i)) then\n ! attractive potential (electron-ion)\n F1(1) = 1.01101D0*e_psi_st - 3.19815D0\n F1(2) = 1.04230D0*e_psi_st - 1.89637D0\n F1(3) = 2.15672D0*e_psi_st - 2.81038D0\n F22 = 2.08699D0*e_psi_st - 5.81444D0\n else\n ! repulsive potential (ion-ion or electron-electron)\n F1(1) = 1.00141D0*e_psi_st - 3.18209D0\n F1(2) = 0.99559D0*e_psi_st - 1.29553D0\n F1(3) = 1.99814D0*e_psi_st - 0.64413D0\n F22 = 1.99016D0*e_psi_st - 4.56958D0\n end if\n else if (psi_st.ge.4.0D0) then\n ! repulsive and attractive coeffcients are the same in this range\n F1(1) = 1.00141D0*e_psi_st - 3.18209D0\n F1(2) = 0.99559D0*e_psi_st - 1.29553D0\n F1(3) = 1.99814D0*e_psi_st - 0.64413D0\n F22 = 1.99016D0*e_psi_st - 4.56958D0\n end if\n OMEGA1(:) = eps_st*F1(:)\n OMEGA22 = eps_st*F22 ! for particle species Nref & k\n\n ! Binary diffusion coefficient for Chapman and Cowling formalism (first approximation)\n !Ddiff(Nref, i) = 3.0D0*kT/(16.0D0*(NA1(Nref)+NA1(i))*(A*AMU)*OMEGA1(1))\n\n AA = OMEGA22/(5.D0*OMEGA1(1))\n BB = (5.D0*OMEGA1(2)-OMEGA1(3))/(5.D0*OMEGA1(1))\n CC = 2.D0*OMEGA1(2)/(5.D0*OMEGA1(1))-1.D0\n Xs = NA1(Nref)/(NA1(i)+NA1(Nref)) ! number concentration of reference species Nref\n Xt = NA1(i)/(NA1(i)+NA1(Nref)) ! number concentration of species i\n Ms = CAN1(Nref)/(CAN1(Nref)+CAN1(i))\n Mt = CAN1(i)/(CAN1(Nref)+CAN1(i))\n Pst = 3.0D0*(Ms - Mt)**2 + 4.D0*Ms*Mt*AA\n EE = kT/(8.D0*Ms*Mt*OMEGA1(1))\n Ps = 8.D0*Ms*EE*OMEGA2(Nref)/(5.D0*kT)\n Pt = 8.D0*Mt*EE*OMEGA2(i)/(5.D0*kT)\n Ss = Ms*Ps-Mt*(3.D0*(Mt-Ms)+4.D0*Ms*AA)\n St = Mt*Pt-Ms*(3.D0*(Ms-Mt)+4.D0*Mt*AA)\n Qs = Ps*(6.D0*Mt*Mt + 5.D0*Ms*Ms - 4.D0*Ms*Ms*BB + 8.D0*Ms*Mt*AA)\n Qt = Pt*(6.D0*Ms*Ms + 5.D0*Mt*Mt - 4.D0*Mt*Mt*BB + 8.D0*Mt*Ms*AA)\n Qst = 3.D0*(Ms-Mt)**2*(5.D0-4.D0*BB) + 4.D0*Ms*Mt*AA*(11.D0-4.D0*BB) + 2.D0*Ps*Pt\n !DELTA = 5.0D0*CC*CC*(Ms*Ms*Ps*Xs*Xs + Mt*Mt*Pt*Xt*Xt + Pst*Xs*Xt)/(Xs*Xs*Qs + Xt*Xt*Qt + Xs*Xt*Qst)\n\n ! second approximation\n !Ddiff(Nref, i) = Ddiff(Nref, i)/(1.0D0 - DELTA)\n\n ! thermal coefficients\n !Ath(Nref,i) = 5.D0*CC*(Xs*Ss-Xt*St)/(Xs**2*Qs+Xt**2*Qt+Xs*Xt*Qst)\n ! resistance coefficients for Burgers equations\n Kdiff(Nref, i) = 16.D0/3.D0*NA1(Nref)*NA1(i)*(A*AMU)*OMEGA1(1)\n Zdiff(Nref, i) = -CC\n Zdiff1(Nref, i) = -2.D0*BB+2.5D0\n Zdiff2(Nref, i) = 5.D0*AA\n end do !i\n end do !k=Nref\n\nend subroutine compute_full_diffusion_coeffs\n\n\n\n! ------------------------------------------------------------------------------\n! DIFFUSION_TERMS_BURGERS\n! Compute the diffusion coefficients by solving the Burgers equations,\n! using the subroutine of Thoul & al. (1994).\n! ------------------------------------------------------------------------------\n! Input:\n! rho - Density [g/cm^3]\n! T - Temperature [k]\n! NN - Number of particle species (not counting electrons)\n! n(i) - Particle number densities [cm^-3]\n! Ne - Electron number density [cm^-3]\n! grad(i) - radiative acceleration [cm/s^2]\n! Z(i) - Average charge of particle species (partial ionisation)\n! A(i) - Baryon number of particle species\n! Output (in cgs units):\n! AP(i) - Pressure terms in the expression for the diffusion velocity\n! AT(i) - Temperature terms in the expression for the diffusion velocity\n! AG(i) - Radiative acceleration terms in the expression for the diffusion velocity\n! AC(i,j) - composition terms in the expression for the diffusion velocity\n! ------------------------------------------------------------------------------\nsubroutine diffusion_terms_burgers(rho,T,NN,n,Ne, grad, Z,A, AP,AT,AG,AC)\n use real_kind\n use constants\n\n implicit none\n integer, intent(in) :: NN\n real(double), intent(in) :: rho, T, n(NN), Ne, grad(NN), Z(NN), A(NN)\n real(double), intent(out) :: AP(NN), AT(NN), AG(NN), AC(NN, NN)\n ! Local variables\n real(double) :: C(NN+1) ! Concentration\n ! Permutation of particle numbers, needed because the solver can only\n ! deal with species that have C(i) > 0\n integer :: Ndiff\n integer, allocatable :: NP(:)\n real(double), allocatable :: NX(:), gradx(:), AA(:), ZZ(:)\n real(double), allocatable :: AAP(:), AAT(:), AAG(:), AAC(:, :)\n ! Diffusion coefficients, for Burgers equations\n real(double), allocatable :: Kdiff(:, :), Zdiff(:, :)\n real(double), allocatable :: Zdiff1(:, :), Zdiff2(:, :)\n ! Miscellaneous\n real(double) :: u;\n integer :: i, j\n\n ! Allocate permutation array\n allocate(NP(NN+1))\n\n ! Initialise all return values to 0\n AP(:) = 0.0d0\n AT(:) = 0.0d0\n AG(:) = 0.0d0\n AC(:,:) = 0.0d0\n\n ! Eliminate elements that are not present (or have very small abundances)\n Ndiff = 0\n do i = 1, NN\n if (n(i) > 1.0d-10) then\n Ndiff = Ndiff+1\n NP(Ndiff) = i;\n end if\n end do\n\n ! We need to have at least two species to calculate diffusion\n if (Ndiff < 2) then\n deallocate(NP)\n return\n end if\n\n ! We have one additional species: electrons\n Ndiff = Ndiff+1\n\n ! Allocate memory for the temporary arrays.\n allocate(NX(Ndiff))\n allocate(gradX(Ndiff))\n allocate(AA(Ndiff))\n allocate(ZZ(Ndiff))\n allocate(AAP(Ndiff))\n allocate(AAT(Ndiff))\n allocate(AAG(Ndiff))\n allocate(AAC(Ndiff, Ndiff))\n allocate(Kdiff(Ndiff,Ndiff))\n allocate(Zdiff(Ndiff,Ndiff))\n allocate(Zdiff1(Ndiff,Ndiff))\n allocate(Zdiff2(Ndiff,Ndiff))\n\n ! Copy data to temporary arrays of appropriate size\n do i = 1, Ndiff-1\n NX(i) = n(NP(i))\n gradX(i) = grad(NP(i)) / (CR*T)\n AA(i) = A(NP(i))\n ZZ(i) = Z(NP(i))\n end do\n ! Add electrons\n NX(Ndiff) = Ne\n AA(Ndiff) = AME/AMU\n ZZ(Ndiff) = -1.0d0\n gradX(Ndiff) = 0.0d0\n\n ! Concentrations, relative to electrons\n C(1:Ndiff) = NX(1:Ndiff) / Ne\n\n ! Compute atomic diffusion coefficients, Paquette et al. (1986)\n Kdiff(:,:) = 0.0d0\n Zdiff(:,:) = 0.0d0\n Zdiff1(:,:) = 0.0d0\n Zdiff2(:,:) = 0.0d0\n\n !call compute_full_diffusion_coeffs(rho, T, Ndiff, AA, ZZ, NX, Kdiff, Zdiff, Zdiff1, Zdiff2) !Rho not used\n call compute_full_diffusion_coeffs(T, Ndiff, AA, ZZ, NX, Kdiff, Zdiff, Zdiff1, Zdiff2)\n\n ! Kdiff = kappa, equation (37) of Thoul et al. (1994)\n Kdiff(:,:) = Kdiff(:,:) * T**1.5 / (1.41d-25*NX(Ndiff)**2)\n\n ! Find pressure, temperature and composition terms for diffusion velocities\n call diffusion_screened(Ndiff, AA, ZZ, C, gradX, Kdiff, Zdiff, Zdiff1, Zdiff2, &\n AAP(1:Ndiff), AAT(1:Ndiff), AAG(1:Ndiff), AAC(1:Ndiff,1:Ndiff))\n\n ! Fix units: solar radii, 1e7 k, 1e2 g/cm^2, 6e13 years\n u = (T/1.0D7)**2.5/(rho/1.0D2) * (CRSN*1.0D11)**2/(6.D13*CSY)\n AAP(1:Ndiff) = AAP(1:Ndiff) * u\n AAT(1:Ndiff) = AAT(1:Ndiff) * u\n AAG(1:Ndiff) = AAG(1:Ndiff) * u\n AAC(1:Ndiff,1:Ndiff) = AAC(1:Ndiff,1:Ndiff) * u\n\n ! Unscramble the results, don't include electrons (we're not treating\n ! them separately anyway)\n do i = 1, Ndiff-1\n AP(NP(i)) = AAP(i)\n AT(NP(i)) = AAT(i)\n AG(NP(i)) = AAG(i)\n do j = 1, Ndiff-1\n AC(NP(i),NP(j)) = AAC(i, j)\n end do\n end do\n\n deallocate(NP)\n deallocate(NX)\n deallocate(AA)\n deallocate(ZZ)\n deallocate(AAP)\n deallocate(AAT)\n deallocate(AAG)\n deallocate(AAC)\n deallocate(Kdiff)\n deallocate(Zdiff)\n deallocate(Zdiff1)\n deallocate(Zdiff2)\nend subroutine diffusion_terms_burgers\n\n\n!> ------------------------------------------------------------------------------\n!! DIFFUSION_SCREENED\n!! Calculate diffusion coefficients by solving Burgers' equations.\n!!\n!! This routine was originally written by Anne A. Thoul, at the Institute\n!! for Advanced Study, Princeton, NJ 08540.\n!! See Thoul et al., Ap.j. 421, p. 828 (1994)\n!! The subroutines LU_BACK_SUBSTITUTION and LU_DECOMPOSITION are based on\n!! Numerical Recipes.\n!!\n!! \\todo FIXME: replace these with LAPACK functions, which are free. See the\n!! equivalent subroutine in MESA to see how this should be done.\n!!\n!! It has been updated to solve the Burgers\n!! equations with resistance coefficients from a screened Coulomb\n!! potential (Paquette et al 1986) instead of a pure Coulomb potential,\n!! by Hu&al 2009\n!!\n!! The system contains n equations with n unknowns.\n!! The equations are: the M momentum equations,\n!! the M energy equations,\n!! two constraints: the current neutrality\n!! the zero fluid velocity.\n!! The unknowns are: the M diffusion velocities,\n!! the M heat fluxes,\n!! the electric field E\n!! the gravitational force g.\n!! ------------------------------------------------------------------------------\n!! Input:\n!! M - Number of atomic species to consider (+electrons)\n!! A(1:M) - Atomic mass numbers\n!! Z(1:M) - Average charge for this species (from Saha equation)\n!! C(1:M) - Concentrations (by number/electron)\n!! G(1:M) - radiative acceleration term, -AMU*g_rad(i)/kT\n!! k(1:M, 1:M) - Relative diffusion coefficients for species i against j\n!! Zdiff(1:M, 1:M) - Relative diffusion coefficients for species i against j\n!! Zdiff1(1:M, 1:M) - Relative diffusion coefficients for species i against j\n!! Zdiff2(1:M, 1:M) - Relative diffusion coefficients for species i against j\n!! See Hu & al. eq (1) and (2) for the definition of these coefficients\n!! Output:\n!! AP(1:M) - Coefficient for pressure term in diffusion equation\n!! AT(1:M) - Coefficient for temperature term in diffusion equation\n!! AG(1:M) - Extra term for radiative levitation in diffusion equation\n!! AX(1:M,1:M) - Coefficient for composition term in diffusion equation\n!! See (3) of Thoul et al (1994). Take care of the units!\n!! ------------------------------------------------------------------------------\n!<\nsubroutine diffusion_screened(M, A, Z, C, G, k, Zdiff, Zdiff1, Zdiff2, AP, AT, AG, AX)\n ! Note that kappa_st is obtained from the resistance coefficient Kdiff with eq (37) Thoul&al.\n ! The vector AP, AT, and array AX contains the results for the diffusion\n ! coefficients used in eq 3 of Thoul et al (1994). Take care of the units!\n ! Warning: this routine does not allow species with 0 mass fraction,\n ! so make sure you leave them out!\n\n use real_kind\n\n implicit none\n integer, intent(in) :: M\n real(double), intent(in) :: A(M), Z(M), C(M), G(M), k(M,M), Zdiff(M,M), Zdiff1(M,M), Zdiff2(M,M)\n real(double), intent(out) :: AP(M), AT(M), AG(M), AX(M,M)\n integer :: n, i, j, L\n integer indx(2*m+2)\n real(double) :: CC, AC\n real(double), allocatable :: XX(:, :), YY(:, :)\n real(double), allocatable :: alpha(:), beta(:), nu(:), gamma(:, :), delta(:, :), ga(:)\n real(double) :: KO, D\n\n ! The vector C contains the concentrations\n ! CC is the total concentration: CC=sum(C_s)\n ! AC is proportional to the mass density: AC=sum(A_s C_s)\n ! The arrays XX, YY and k are various parameters which appear in\n ! Burgers equations.\n ! The vectors and arrays ALPHA, NU, gamma, DELTA, and GA represent\n ! the \"right- and left-hand-sides\" of Burgers equations, and later\n ! the diffusion coefficients.\n\n ! Initialise parameters:\n KO = 2.D0\n n = 2*M + 2\n\n ! Allocate data structures\n allocate(XX(M, M))\n allocate(YY(M, M))\n allocate(alpha(2*M+2))\n allocate(beta(2*M+2))\n allocate(nu(2*M+2))\n allocate(gamma(2*M+2, 2*M+2))\n allocate(delta(2*M+2, 2*M+2))\n allocate(ga(2*M+2))\n\n ! Calculate CC and AC:\n cc = sum(C(:))\n ac = dot_product(A(:), C(:))\n\n ! Calculate the coefficients of the burgers equations\n do i = 1, m\n do j = 1, m\n xx(i,j) = A(j)/(A(i) + A(j))\n end do\n end do\n do i = 1, m\n do j = 1, m\n yy(i,j) = 3.0d0 * xx(j,i) + zdiff1(i,j) * xx(i,j) * A(j)/A(i)\n end do\n end do\n\n ! Write the burgers equations and the two constraints as\n ! alpha_s dp + nu_s dT + sum_t(not 2 or M) gamma_st dC_t\n ! = sum_t delta_st w_t\n ! Note that we do *not* eliminate the He gradient, as in the original\n ! subroutine.\n do i = 1, m\n alpha(i) = C(i)/cc\n beta(i) = G(i) * alpha(i) * A(i)\n nu(i) = 0.d0\n gamma(i,1:m) = 0.d0\n do j = 1, m-1\n gamma(i,j) = -C(j)/cc\n if (j == i) then\n gamma(i,j) = gamma(i,j) + 1.d0\n end if\n gamma(i,j) = gamma(i,j)*C(i)/cc\n end do\n\n gamma(i,m+1:n) = 0.d0\n end do\n\n alpha(m+1:n) = 0.d0\n beta(m+1:n) = 0.d0\n do i = m+1, n-2\n nu(i) = 2.5d0 * C(i-m)/cc\n end do\n nu(n-1:n) = 0.d0\n gamma(m+1:n,1:n) = 0.d0\n delta(1:n,1:n)=0.d0\n\n do i = 1, m\n do j = 1, m\n if (j == i) then\n do l = 1, m\n if(l /= i) then\n delta(i,j) = delta(i,j) - k(i,l)\n end if\n end do\n else\n delta(i,j) = k(i,j)\n end if\n end do\n\n do j = M+1, n-2\n if(j-M == i) then\n do L = 1, M\n if (L /= i) then\n delta(i,j) = delta(i,j) + Zdiff(i,L)*XX(i,L)*k(i,L)\n end if\n end do\n else\n delta(i,j) = -Zdiff(i,j-M)*xx(j-M,i)*k(i,j-M)\n end if\n end do\n\n delta(i,n-1) = C(i)*Z(i)\n\n delta(i,n) = -C(i)*A(i)\n end do\n\n do i = M+1, n-2\n do j = 1, M\n if (j == i-M) then\n do L = 1, M\n if (L /= i-M) then ! pure C potential\n delta(i,j) = delta(i,j) + 2.5D0*Zdiff(i-M,L)*XX(i-M,L)*k(i-M,L)\n end if\n end do\n else ! pure C potential\n delta(i,j) = -2.5D0*Zdiff(i-M,j)*XX(i-M,j)*k(i-M,j)\n end if\n end do\n\n do j = M+1, n-2\n if (j-M == i-M) then\n do L = 1, M\n if (L /= i-M) then ! pure C potential\n delta(i,j) = delta(i,j) - xx(L,i-M)*k(i-M,L)* &\n (0.8D0*Zdiff2(i-M,L)*XX(i-M,L) + YY(i-M,L))\n end if\n end do ! pure C potential\n delta(i,j) = delta(i,j) - 0.4D0*Zdiff2(i-M,i-M)*k(i-M,i-M)\n else ! pure C potential\n delta(i,j) = (3.D0 + Zdiff1(i-M,j-M) - 0.8D0*Zdiff2(i-M,j-M))*k(i-M,j-M)*XX(i-M,j-M)*xx(j-M,i-M)\n end if\n end do\n\n delta(i,n-1) = 0.D0\n delta(i,n) = 0.D0\n end do\n\n delta(n-1,1:M) = C(1:M)*Z(1:M)\n delta(n-1,M+1:n) = 0.D0\n\n delta(n,1:m) = C(1:m)*DNINT(A(1:m)) ! Diffusion velocities are for baryon fractions and not mass fractions\n delta(n,M+1:n) = 0.D0\n\n ! Invert the system for each possible right-hand-side, i.e.,\n ! if alpha is the r.h.s., we obtain the coefficient A_p\n ! if nu ---------------------------------------- A_T\n ! if beta ---------------------------------------- A_g\n ! if gamma(i,j) ----------------------------------- A_Cj\n !\n ! If i=1, we obtain the hydrogen diffusion velocity\n ! If i=2, ------------- helium ------------------\n ! If i=3,M-1, --------- heavy element -------------\n ! If i=M, ------------- electrons -----------------\n ! Is it necessary to keep the elements in this order? i think not (HH)\n ! For i=M,2M, we get the heat fluxes\n ! For i=n-1, we get the electric field\n ! For i=n, we get the gravitational force g\n\n ! delta is now LU decomposition of the original matrix\n call lu_decomposition (delta, n, n, indx, d)\n\n ! LU decomposition of delta is output to delta\n call lu_back_substitution (delta, n, n, indx, alpha)\n call lu_back_substitution (delta, n, n, indx, nu)\n call lu_back_substitution (delta, n, n, indx, beta)\n do j = 1, n\n ga(1:n) = gamma(1:n,j)\n call lu_back_substitution(delta, n, n, indx, ga)\n gamma(1:n,j) = ga(1:n)\n end do\n\n ! The results for the coefficients must be multiplied by p/K_0:\n AP(1:M) = alpha(1:M)*KO*AC*CC\n AT(1:M) = nu(1:M)*KO*AC*CC\n AG(1:M) = beta(1:M)*KO*AC*CC\n AX(1:M,1:M) = gamma(1:M,1:M)*KO*AC*CC\n\n deallocate(XX)\n deallocate(YY)\n deallocate(ALPHA)\n deallocate(beta)\n deallocate(NU)\n deallocate(gamma)\n deallocate(DELTA)\n deallocate(GA)\nend subroutine diffusion_screened\n\n\n\nsubroutine lu_back_substitution(A,n,NP,INDX,B)\n use real_kind\n implicit none\n\n ! .. Scalar Arguments ..\n integer :: n,NP\n ! ..\n ! .. Array Arguments ..\n real(double) :: A(NP,NP),B(n)\n integer :: INDX(n)\n ! ..\n ! .. Local Scalars ..\n real(double) :: SUM\n integer i,II,j,LL\n ! ..\n II = 0\n\n do i = 1,n\n LL = INDX(i)\n SUM = B(LL)\n B(LL) = B(i)\n if (II /= 0) then\n do j = II,i - 1\n SUM = SUM - A(i,j)*B(j)\n end do\n\n else if (SUM /= 0.D0) then\n II = i\n end if\n\n B(i) = SUM\n end do\n\n do i = n,1,-1\n SUM = B(i)\n if (i < n) then\n do j = i + 1,n\n SUM = SUM - A(i,j)*B(j)\n end do\n end if\n\n B(i) = SUM/A(i,i)\n end do\nend subroutine lu_back_substitution\n\n\n\nsubroutine lu_decomposition(A,n,NP,INDX,D)\n use real_kind\n implicit none\n\n ! .. parameters ..\n real(double), parameter :: TINY=1.0D-20\n ! ..\n ! .. Scalar Arguments ..\n real(double) :: D\n integer :: n,NP\n ! ..\n ! .. Array Arguments ..\n real(double) :: A(NP,NP)\n integer :: INDX(n)\n ! ..\n ! .. Local Scalars ..\n real(double) :: AAMAX,DUM,SUM\n integer :: i,IMAX,j,k\n ! ..\n ! .. Local Arrays ..\n real(double), allocatable :: VV(:)\n ! ..\n ! .. Intrinsic Functions ..\n intrinsic dabs\n ! ..\n\n allocate(VV(n))\n\n imax = 1\n D = 1.D0\n do i = 1,n\n AAMAX = 0.D0\n do j = 1,n\n if (abs(A(i,j)) > AAMAX) AAMAX = abs(A(i,j))\n end do\n !if (AAMAX == 0.D0) PAUSE 'Singular matrix.'\n if (AAMAX == 0.D0) write(0,'(A)') 'Singular matrix in lu_decomposition()' !> \\todo Is a reason to stop the code?\n VV(i) = 1./AAMAX\n end do\n\n do j = 1,n\n if (j > 1) then\n do i = 1,j - 1\n SUM = A(i,j)\n if (i > 1) then\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 if\n\n end do\n end if\n\n\n AAMAX = 0.D0\n do i = j,n\n SUM = A(i,j)\n if (j > 1) then\n do k = 1,j - 1\n SUM = SUM - A(i,k)*A(k,j)\n end do\n A(i,j) = SUM\n end if\n\n DUM = VV(i)*abs(SUM)\n if (DUM.GE.AAMAX) then\n IMAX = i\n AAMAX = DUM\n end if\n\n end do\n\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 D = -D\n VV(IMAX) = VV(j)\n end if\n\n INDX(j) = IMAX\n if (j /= n) then\n if (A(j,j) == 0.D0) A(j,j) = TINY\n DUM = 1./A(j,j)\n do i = j + 1,n\n A(i,j) = A(i,j)*DUM\n end do\n end if\n\n end do\n\n if (A(n,n) == 0.D0) A(n,n) = TINY\n\n deallocate(vv)\n\nend subroutine lu_decomposition\n\n", "meta": {"hexsha": "e26408e6c5522a149c715298ccb4f782372a2db1", "size": 30136, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/amuse/community/evtwin/src/trunk/code/diffusion.f90", "max_stars_repo_name": "rknop/amuse", "max_stars_repo_head_hexsha": "85d5bdcc29cfc87dc69d91c264101fafd6658aec", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 131, "max_stars_repo_stars_event_min_datetime": "2015-06-04T09:06:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-01T12:11:29.000Z", "max_issues_repo_path": "src/amuse/community/evtwin/src/trunk/code/diffusion.f90", "max_issues_repo_name": "rknop/amuse", "max_issues_repo_head_hexsha": "85d5bdcc29cfc87dc69d91c264101fafd6658aec", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 690, "max_issues_repo_issues_event_min_datetime": "2015-10-17T12:18:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:15:58.000Z", "max_forks_repo_path": "src/amuse/community/evtwin/src/trunk/code/diffusion.f90", "max_forks_repo_name": "rieder/amuse", "max_forks_repo_head_hexsha": "3ac3b6b8f922643657279ddee5c8ab3fc0440d5e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 102, "max_forks_repo_forks_event_min_datetime": "2015-01-22T10:00:29.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-09T13:29:43.000Z", "avg_line_length": 34.3234624146, "max_line_length": 119, "alphanum_fraction": 0.5425404831, "num_tokens": 10064, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206659843131, "lm_q2_score": 0.724870282120402, "lm_q1q2_score": 0.6537754876022699}} {"text": "program main\n use LinearSolverClass\n use IOClass\n implicit none\n\n ! Create Ax=B and solve x = A^(-1) B\n !integer(int32), parameter :: N = 4 \n integer(int32), parameter :: NN=10000! rank \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 real(real64) ,allocatable :: Val_c(:) \n integer(int32),allocatable :: index_i_c(:),index_j_c(:)\n integer(int32) :: i,m,k,j\n real(real64) :: Amat(NN,NN),bvec(NN),xvec(NN)\n type(LinearSolver_) :: solver ! linear solver instance.\n type(IO_) :: f\n type(Random_) ::rdm\n\n call rdm%init()\n !call f%open(\"Amat.txt\")\n do i=1,size(Amat,1)\n Amat(i,i)=rdm%random()+10.0d0\n enddo\n do i=1,size(Amat,1)-1\n Amat(i,i+1)=Amat(i,i+1)+rdm%random()+1.0d0\n Amat(i+1,i)=Amat(i+1,i)+rdm%random()+2.0d0\n enddo\n do i=1,NN\n Bvec(i)=rdm%random()+2.0d0\n enddo\n !call f%close()\n xvec(:)=0.0d0\n m=0\n do i=1,size(Amat,1)\n do j=1,size(Amat,1)\n if(Amat(i,j)/=0.0d0 )then\n m=m+1 \n endif\n enddo\n enddo\n allocate(val_c(m) )\n allocate(index_i_c(m) )\n allocate(index_j_c(m) )\n\n m=0\n do i=1,size(Amat,1)\n do j=1,size(Amat,1)\n if(Amat(i,j)/=0.0d0 )then\n m=m+1\n val_c(m)=Amat(i,j)\n index_i_c(m) = i\n index_j_c(m) = j\n endif\n enddo\n enddo\n! ! creating A, x, and B\n! A(1:4,1) = (/ 2.0d0, -1.0d0, 0.0d0, 0.0d0 /)\n! A(1:4,2) = (/ -1.0d0, 2.0d0, -2.0d0, 0.0d0 /)\n! A(1:4,3) = (/ 0.0d0, -1.0d0, 3.0d0, 2.0d0 /)\n! A(1:4,4) = (/ 0.0d0, 0.0d0, 2.0d0, 5.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, -2.0d0, -1.0d0, -3.0d0, &\n! 2.0d0, 2.0d0, 5.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 ! import Ax=B into the linear solver instance.\n call solver%import(a = Amat, x = Xvec, b = Bvec)\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\",\"/\",t2-t1,\" sec.\"\n\n ! Similarly ...\n\n! X(1:4) = (/ 0.0d0, 0.0d0, 0.0d0, 0.0d0 /)\n call solver%import(a = Amat, x = Xvec, b = Bvec, val=val_c, index_i=index_i_c, index_j=index_j_c)\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 print *, \"Solved by GaussSeidel\",\"/\",t2-t1,\" sec.\"\n \n! X(1:4) = (/ 0.0d0, 0.0d0, 0.0d0, 0.0d0 /)\n call solver%import(a = Amat, x = Xvec, b = Bvec, val=val_c, index_i=index_i_c, index_j=index_j_c)\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 print *, \"Solved by BiCGSTAB(CRS)\",\"/\",t2-t1,\" sec.\"\n\n! X(1:4) = (/ 0.0d0, 0.0d0, 0.0d0, 0.0d0 /)\n call solver%import(a = Amat, x = Xvec, b = Bvec, val=val_c, index_i=index_i_c, index_j=index_j_c)\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 print *, \"Solved by BiCGSTAB \",\"/\",t2-t1,\" sec.\"\n! X(1:4) = (/ 0.0d0, 0.0d0, 0.0d0, 0.0d0 /)\n call solver%import(a = Amat, x = Xvec, b = Bvec)\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 print *, \"Solved by GPBiCG \",\"/\",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": "103da170802de3a0e61fec763109aaf1bbe3a102", "size": 4311, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/app/std/linear_solver_ex2.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_ex2.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_ex2.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": 34.2142857143, "max_line_length": 101, "alphanum_fraction": 0.5265599629, "num_tokens": 1885, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.90192067652954, "lm_q2_score": 0.7248702642896702, "lm_q1q2_score": 0.6537754791642858}} {"text": "module ising_framework\n implicit none\ncontains\n subroutine ising(L, T, next_I, prev_I, MCS, m, chi, C)\n implicit none\n INTEGER (kind=4),intent(in) :: L, MCS, next_I(L), prev_I(L)\n real (kind=8), INTENT(IN) :: T\n real (kind=8), intent(out) :: m, chi, C\n integer (kind=4):: lattice(L,L), i,j,k, delta_E, no_of_probes\n real (kind=8) :: boltzmann_factor(5), E=0.0d0, m_k=0.0d0, magnetizations = 0.0d0, magnetizations2 = 0.0d0, energies=0.0d0,&\n energies2=0.0d0, r\n\n no_of_probes=(MCS-30000)/100\n lattice = 1\n \n do i=-8,8,4\n boltzmann_factor(i/4 + 3) = exp(-i / T)\n end do\n\n magnetizations = 0.0d0\n magnetizations2 = 0.0d0\n energies = 0.0d0\n energies2 = 0.0d0\n do k=1, MCS\n do j=1, L\n do i=1, L\n delta_E = 2 * lattice(i,j) * (lattice(next_I(i),j) + lattice(prev_I(i),j) + &\n lattice(i,next_I(j)) + lattice(i, prev_I(j)))\n if (delta_E <= 0) then\n lattice(i,j) = -lattice(i,j)\n else\n call random_number(r) \n if (r <= boltzmann_factor(delta_E/4 + 3)) then\n lattice(i,j) = -lattice(i,j)\n end if\n end if\n end do\n end do\n\n if ((30000 < k) .and. (mod(k,100)==0)) then\n m_k = 0.0d0\n E = 0.0d0\n do j=1,L\n do i=1,L\n m_k = m_k + lattice(i,j)\n E = E + lattice(i,j) * (lattice(next_I(i),j) + lattice(i,next_I(j)))\n end do\n end do\n m_k = abs(m_k / L**2)\n magnetizations = magnetizations + m_k\n magnetizations2 = magnetizations2 + m_k**2\n energies = energies + E\n energies2 = energies2 + E**2\n end if\n end do\n m = magnetizations / no_of_probes\n chi = L**2 / T * (magnetizations2 - magnetizations**2 / no_of_probes)/no_of_probes\n C = (energies2 - energies**2 / no_of_probes)/no_of_probes / L**2 / T**2 \n end subroutine ising\nend module ising_framework\n\nprogram ising2d\n use ising_framework\n implicit none\n INTEGER (kind=4), PARAMETER :: MCS=230000, L=20, no_of_probes=(MCS-30000)/100\n REAL(kind=8), PARAMETER :: T1=0.5d0, T2=3.5d0, dT=0.1d0\n INTEGER(kind=4) :: next_I(L), prev_I(L), i\n real(kind=8) :: T, m, chi, C\n\n \n do i=1,L\n next_I(i) = i+1\n prev_I(i) = i-1\n end do\n next_I(L) = 1\n prev_I(1) = L\n\n\n OPEN(1, file=\"m.dat\")\n OPEN(2, file=\"chi.dat\")\n OPEN(3, file=\"C.dat\")\n\n !trzeba zmieni\u0107 taktyk\u0119 z while na for, \u017ceby wrzuci\u0107 do openmp\n T=T1\n do\n if (T>T2) exit\n T = T + dT\n call ising(L, T, next_I, prev_I, MCS, m, chi, C)\n WRITE(1,*) T, m\n WRITE(2,*) T, chi\n WRITE(3,*) T, C\n end do\n\nend program ising2d", "meta": {"hexsha": "95085ab4ab24f89e6976532d83a1f181eb153fa5", "size": 2910, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran90/ising.f90", "max_stars_repo_name": "michelangelo21/isingLangBenchmark", "max_stars_repo_head_hexsha": "c4762cfe1221adfb92b1db1f1feded5ff869a743", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Fortran90/ising.f90", "max_issues_repo_name": "michelangelo21/isingLangBenchmark", "max_issues_repo_head_hexsha": "c4762cfe1221adfb92b1db1f1feded5ff869a743", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Fortran90/ising.f90", "max_forks_repo_name": "michelangelo21/isingLangBenchmark", "max_forks_repo_head_hexsha": "c4762cfe1221adfb92b1db1f1feded5ff869a743", "max_forks_repo_licenses": ["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.9574468085, "max_line_length": 127, "alphanum_fraction": 0.5082474227, "num_tokens": 989, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206659843132, "lm_q2_score": 0.7248702702332475, "lm_q1q2_score": 0.6537754768809996}} {"text": "!Program to test EXPONENT and FRACTION intrinsic function.\n\nprogram test_exponent_fraction\n real x\n integer*4 i\n real*8 y\n integer*8 j\n equivalence (x, i), (y, j)\n\n x = 3.\n call test_4(x)\n\n x = 0.\n call test_4(x)\n\n i = o'00000000001'\n call test_4(x)\n\n i = o'00010000000'\n call test_4(x)\n\n i = o'17700000000'\n call test_4(x)\n\n i = o'00004000001'\n call test_4(x)\n\n i = o'17737777777'\n call test_4(x)\n\n i = o'10000000000'\n call test_4(x)\n\n i = o'0000010000'\n call test_4(x)\n\n y = 0.5\n call test_8(y)\n\n y = 0.\n call test_8(y)\n\n j = o'00000000001'\n call test_8(y)\n\n y = 0.2938735877D-38\n call test_8(y)\n\n y = -1.469369D-39\n call test_8(y)\n\n y = z'7fe00000'\n call test_8(y)\n\n y = -5.739719D+42\n call test_8(y)\nend\n\nsubroutine test_4(x)\nreal*4 x,y\ninteger z\ny = fraction (x)\nz = exponent(x)\nif (z .gt. 0) then\n y = (y * 2.) * (2. ** (z - 1))\nelse\n y = (y / 2.) * (2. ** (z + 1))\nend if\nif (abs (x - y) .gt. abs(x * 1e-6)) call abort()\nend\n\nsubroutine test_8(x)\nreal*8 x, y\ninteger z\ny = fraction (x)\nz = exponent(x)\nif (z .gt. 0) then\n y = (y * 2._8) * (2._8 ** (z - 1))\nelse\n y = (y / 2._8) * (2._8 ** (z + 1))\nend if\nif (abs (x - y) .gt. abs(x * 1e-6)) call abort()\nend\n\n", "meta": {"hexsha": "a22d0b9f50ab67b1511b8a0ad7af95d7102315e9", "size": 1207, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "llvm-gcc-4.2-2.9/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_fraction_exponent.f90", "max_stars_repo_name": "vidkidz/crossbridge", "max_stars_repo_head_hexsha": "ba0bf94aee0ce6cf7eb5be882382e52bc57ba396", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-04-09T02:58:13.000Z", "max_stars_repo_stars_event_max_datetime": "2016-04-09T02:58:13.000Z", "max_issues_repo_path": "llvm-gcc-4.2-2.9/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_fraction_exponent.f90", "max_issues_repo_name": "vidkidz/crossbridge", "max_issues_repo_head_hexsha": "ba0bf94aee0ce6cf7eb5be882382e52bc57ba396", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "llvm-gcc-4.2-2.9/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_fraction_exponent.f90", "max_forks_repo_name": "vidkidz/crossbridge", "max_forks_repo_head_hexsha": "ba0bf94aee0ce6cf7eb5be882382e52bc57ba396", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 14.2, "max_line_length": 58, "alphanum_fraction": 0.5716652858, "num_tokens": 544, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711908591638, "lm_q2_score": 0.7690802476562641, "lm_q1q2_score": 0.6536960539666555}} {"text": "program leap\n implicit none\n\n write(*,*) leap_year([1900, 1996, 1997, 2000])\n\n contains\n\n\tpure elemental function leap_year(y) result(is_leap)\n\timplicit none\n\tlogical :: is_leap\n\tinteger,intent(in) :: y\t\n\t\n\tis_leap = (mod(y,4)==0 .and. .not. mod(y,100)==0) .or. (mod(y,400)==0)\t\n\t\n\tend function leap_year\n\t\nend program leap\n", "meta": {"hexsha": "1df98a0eb68c5cb417f2bb5d6b77c8c34cbb5450", "size": 324, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Leap-year/Fortran/leap-year.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/Leap-year/Fortran/leap-year.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/Leap-year/Fortran/leap-year.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.0, "max_line_length": 72, "alphanum_fraction": 0.6728395062, "num_tokens": 108, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8499711832583695, "lm_q2_score": 0.7690802423634961, "lm_q1q2_score": 0.6536960436223345}} {"text": " subroutine setprob()\n implicit none\n\n double precision pi\n common /compi/ pi\n\n double precision revs_per_second\n common /spherecomm/ revs_per_second\n\n pi = 4.d0*atan(1.d0)\n\n revs_per_second = 0.5d0\n\n end\n", "meta": {"hexsha": "13359d728f7aae52e0e4561e97a93fc9933479ef", "size": 250, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "applications/clawpack/advection/2d/hemisphere/setprob.f", "max_stars_repo_name": "mattzett/forestclaw", "max_stars_repo_head_hexsha": "8c2d012c259e0d9121e44c1ee78dfe2ab4839ec8", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2017-09-26T13:39:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:56:23.000Z", "max_issues_repo_path": "applications/clawpack/advection/2d/hemisphere/setprob.f", "max_issues_repo_name": "mattzett/forestclaw", "max_issues_repo_head_hexsha": "8c2d012c259e0d9121e44c1ee78dfe2ab4839ec8", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 75, "max_issues_repo_issues_event_min_datetime": "2017-08-02T19:56:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T12:36:32.000Z", "max_forks_repo_path": "applications/clawpack/advection/2d/hemisphere/setprob.f", "max_forks_repo_name": "mattzett/forestclaw", "max_forks_repo_head_hexsha": "8c2d012c259e0d9121e44c1ee78dfe2ab4839ec8", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-02-21T00:10:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T19:08:36.000Z", "avg_line_length": 16.6666666667, "max_line_length": 41, "alphanum_fraction": 0.616, "num_tokens": 71, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8499711756575749, "lm_q2_score": 0.7690802370707283, "lm_q1q2_score": 0.6536960332780133}} {"text": "\tSUBROUTINE LICK_SYSTEM(X,Y,N,YS)\n\nc\tTransforms sed in (x,y) to Lick/IDS system by applying a gaussian\nc\tbroadening function to artificially simulate the Lick/IDS spectral\nc\tresolution. The FWHM of the gaussian as a function of wavelength is\nc\tgiven in Table 8 of Worthey and Ottaviani (1997, ApJS, 111, 377)\n\nc\tReturns smoothed spectrum in array (x,ys)\n\nc\tArray declaration\n\treal x(n),y(n),ys(n),u(10000),g(10000)\n\nc\tNumber of sigmas to perform integration\n\tm=6\n\nc\tFWHM of STELIB seds = 3 A (Leborgne et al. 2002)\n\tfwhm_stelib = 3.\n\nc\tPerform smoothing\n\tdo i=1,n\n\tfwhm2 = fwhm_ids(x(i))**2 - fwhm_stelib**2\n\tfwhm = sqrt(fwhm2)\n\nc Note: FWHM = 2*sqrt[2*ln(2)]*sigma = 2.3548*sigma\n\tsigma=fwhm/2.3548\n\n\txmax=x(i)+m*sigma\n\tcall locate(x,n,xmax,i1)\n\tm2=i1+1\n\tm1=2*i-m2\n\tif (m1.lt.1) m1=1\n\tif (m2.gt.n) m2=n\n\tk=0\n\tdo j=m1,m2\n\tk=k+1\n\tu(k)=x(j)\n\tg(k)=y(j)*gauss(x(j),x(i),sigma)\n\tenddo\n\tys(i)=trapz1(u,g,k)\n\tenddo\n\treturn\n\tend\n", "meta": {"hexsha": "d185448edf6c06ce7cc5d5ef7a92db42956ee878", "size": 928, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "bc03/src/lick_system.f", "max_stars_repo_name": "jchavesmontero/galaxpy", "max_stars_repo_head_hexsha": "ef5eaffa8f5ec0418dae44b88cf212ca03814b57", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-10-29T02:26:52.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-15T22:22:35.000Z", "max_issues_repo_path": "bc03/src/lick_system.f", "max_issues_repo_name": "jchavesmontero/galaxpy", "max_issues_repo_head_hexsha": "ef5eaffa8f5ec0418dae44b88cf212ca03814b57", "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": "bc03/src/lick_system.f", "max_forks_repo_name": "jchavesmontero/galaxpy", "max_forks_repo_head_hexsha": "ef5eaffa8f5ec0418dae44b88cf212ca03814b57", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.5813953488, "max_line_length": 69, "alphanum_fraction": 0.6853448276, "num_tokens": 377, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.930458253565792, "lm_q2_score": 0.702530051167069, "lm_q1q2_score": 0.6536748844863975}} {"text": "!=====================================================================!\n! \n!=====================================================================!\n\nprogram main\n\n use element_class , only : spring\n use assembler_class , only : assembler\n use linear_algebra , only : eigvals, solve\n\n implicit none\n\n ! Domain and meshing\n real(8), parameter :: a = 0.0d0, b = 1.0d0\n integer, parameter :: nelems = 10\n integer :: nnodes = nelems + 1\n integer :: me, nimages\n \n real(8) :: dx\n integer :: lnelems\n integer :: e\n integer :: leid\n integer :: lnode_ids(2)\n real(8) :: lnodes(2, 1) = 0.0d0\n real(8), allocatable :: x(:), rhs(:), mat(:,:), jac(:,:)\n \n type(spring), allocatable :: springs(:)\n type(assembler) :: spring_assembler\n \n integer :: i,j \n\n !-------------------------------------------------------------------!\n ! Mesh the one dimensional geometry and partition between procs\n !-------------------------------------------------------------------!\n \n mesh_partition : block\n\n ! Mesh sizse (element length)\n dx = (b-a)/dble(nelems)\n\n ! Identify processors\n me = this_image()\n nimages = num_images()\n if (nimages .gt. nelems) STOP \"Too many processors for the problem size\"\n if (mod(nelems, nimages) .ne. 0) STOP \"Unequal partition. Use different number of processors.\"\n\n ! Decompose domain based on procs\n lnelems = nelems/nimages\n\n end block mesh_partition\n\n !-------------------------------------------------------------------!\n ! Create elements associated with the mesh\n !-------------------------------------------------------------------!\n \n elements : block\n \n ! Create elements locally on each processor\n allocate(springs(lnelems))\n do e = 1, lnelems\n leid = e\n lnode_ids = [leid, leid + 1]\n lnodes(:,1) = [dble(lnode_ids - 1)*dx]\n springs(e) = spring(leid, lnode_ids, lnodes, 1.0d0, me)\n call springs(e) % to_string() \n end do\n\n end block elements\n\n !-------------------------------------------------------------------!\n ! Assemble linear system\n !-------------------------------------------------------------------!\n \n assembly : block\n\n ! Create an assembler for these elements\n spring_assembler = assembler(springs)\n print *, \"created assembler\"\n\n ! Create solution, right hand side, jacobian arrays\n allocate(x(spring_assembler % ndof))\n allocate(rhs(spring_assembler % ndof))\n allocate(jac(spring_assembler % ndof, spring_assembler % ndof))\n\n call random_number(x) ! assumed solution\n x = 1.0d0\n call spring_assembler % residual(x, rhs)\n call spring_assembler % jacobian(x, jac)\n \n print *, \"res=\", rhs\n do i = 1, spring_assembler % ndof\n print *, ( jac(i,j), j = 1, spring_assembler % ndof )\n enddo\n\n!!$ print *, \"jac-vec pdt 1:\", matmul(jac, x)\n!!$ call spring_assembler % jacobian_vector_product(x, rhs)\n!!$ print *, \"jac-vec pdt 2:\", rhs\n\n !print *, \"exact sol\", solve(jac, rhs)\n \n end block assembly\n \n !-------------------------------------------------------------------!\n ! Solve the linear system\n !-------------------------------------------------------------------!\n \n solver: block\n\n integer, parameter :: max_it = 100000\n real(8), parameter :: max_tol = 1.0d-8\n integer :: iter, flag, i, j\n real(8) :: tol \n real(8), allocatable :: x(:)[:]\n\n allocate(x(spring_assembler % ndof)[*])\n x = 1.0d0\n\n call spring_assembler % solve(max_it, max_tol, x, iter, tol, flag)\n\n print *, \"solution\", x, \"from\", this_image()\n \n !rhs = 0.0d0\n !call spring_assembler % jacobian_vector_product(x, rhs)\n !print *, rhs\n\n end block solver\n\n deallocate(springs)\n\nend program main\n", "meta": {"hexsha": "714fe8795634c37a42c5cdb53d1554491c2c169b", "size": 3900, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/finite-element/test_spring.f90", "max_stars_repo_name": "komahanb/coarray-fortran", "max_stars_repo_head_hexsha": "9af9cab1c1e1083ca63cd024af16632cca17b617", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-07-04T19:56:26.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-12T08:05:41.000Z", "max_issues_repo_path": "test/finite-element/test_spring.f90", "max_issues_repo_name": "komahanb/coarray-fortran", "max_issues_repo_head_hexsha": "9af9cab1c1e1083ca63cd024af16632cca17b617", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/finite-element/test_spring.f90", "max_forks_repo_name": "komahanb/coarray-fortran", "max_forks_repo_head_hexsha": "9af9cab1c1e1083ca63cd024af16632cca17b617", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-07-04T19:57:48.000Z", "max_forks_repo_forks_event_max_datetime": "2018-07-04T19:57:48.000Z", "avg_line_length": 29.7709923664, "max_line_length": 98, "alphanum_fraction": 0.4853846154, "num_tokens": 975, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950947024555, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.653667122726102}} {"text": "program newtonmd\r\n\r\nimplicit none\r\nreal:: error\r\ninteger::istep,n,i,z,pointer,j, steps, q, points,outputfile,num, kappa\r\nreal :: mu1, mu2, stepsize, mu \r\nreal:: func\r\nreal, dimension (:), allocatable :: w0, muarray\r\nreal, dimension (:,:), allocatable :: jarray,c,fx,x0, x1,xf, bin0\r\ncharacter (LEN = 60) :: inputval, filename1, filename2 \r\n!CHARACTER*29 :: path ='C:\\Users\\17029\\Desktop\\gfortran\\datfiles\\'\r\n\r\nerror=1.0e-06\r\ninputval = 'S'\r\nkappa = 0\r\n\r\n! initialising n \r\nprint*,\"Enter the dimension\"\r\nREAD(*,*) n\r\n\r\nallocate ( x0(n,1) )\r\nallocate ( bin0(n,1) )\r\nallocate ( w0(n) )\r\nallocate ( fx(n,1))\r\nallocate ( x1(n,1))\r\nallocate ( xf(n,1))\r\nallocate ( jarray(n,n) )\r\nallocate ( c(n,n))\r\n\r\n\r\nprint*,\"Enter mu1 value\"\r\nREAD(*,*) mu1\r\n\r\nprint*,\"Enter mu2 value\"\r\nREAD(*,*) mu2\r\n\r\nprint*,\"Enter points value\"\r\nREAD(*,*) points\r\n\r\n!print*,\"Enter the Guess Vector\"\r\n!DO i = 1, n\r\n! READ(*,*) x0(i,1)\r\n!END DO\r\n\r\nprint*,\"Enter the aeta Vector\"\r\nDO i = 1, n\r\n READ(*,*) w0(i)\r\nEND DO\r\n\r\n!print*,\"Enter kappa value, Enter -1 for all\"\r\n!READ(*,*) kappa\r\n\r\n\r\nstepsize = (mu2-mu1)/(points+1)\r\nallocate ( muarray(points + 2))\r\n\r\n\r\nmuarray(1) = mu1\r\ndo i = 2,(points+1)\r\nmuarray(i) = muarray(i-1) + stepsize\r\nend do\r\nmuarray(points+2) = mu2\r\noutputfile = 1 \r\n\r\n\r\n\r\ndo num = 0, (2**(n) -1)\r\n\r\n\r\nwrite(filename1, '(\"Output\",I0,\".dat\")') outputfile \r\nfilename2= filename1\r\n\r\nprint*, \"this work 2\"\r\ncall dectobin_gen(n,bin0,num)\r\n\r\nprint*, 'this works'\r\nprint*, bin0\r\n\r\n\r\n!if ( sum(bin0) /= kappa) CYCLE\r\n\r\n\r\nx0 = bin0\r\nprint*, \"this works 3\"\r\nopen(90, file=filename2,action=\"write\",POSITION=\"APPEND\")\r\n\r\nq = 1\r\ndo while ( q /= (points + 3))\r\n\r\nmu = muarray(q) \r\n\r\n\r\npointer= 1\r\n\r\nxf = x0\r\n\r\n!do while( ((abs(NORM2(xf)-NORM2(x1))/abs(NORM2(xf))) > 0.00001) )\r\n\r\n\r\n!do while( (pointer /= 70) .or. ((abs(NORM2(xf)-NORM2(x0))/abs(NORM2(x0))) == 0 ) )\r\n\r\n\r\ndo while( pointer /= 70 )\r\n\r\n\r\nz = 1 \r\n\r\nprint*, x0\r\n\r\n\r\n!! generating jacobian \r\n\r\ncall Jac(x0, mu, n, w0, jarray)\r\n\r\ndo i = 1,n\r\ndo j = 1,n\r\n print*, i,j,jarray(i,j)\r\nend do\r\nend do\r\n\r\n\r\n!! generating it's inverse\r\nprint*, \"generating inverse\"\r\n\r\n\r\ncall inverse(jarray,c,n)\r\n\r\nprint*,'c is', c\r\n\r\n\r\n!! generating fx(x0)\r\n\r\ndo while (z /= n+1 )\r\ncall eqn(x0, w0, z, n, mu, func)\r\nfx(z,1) = func\r\nz = z+1\r\nend do\r\n\r\nprint*, fx\r\n\r\n!! computing x1\r\n\r\nx1 = x0 - matmul(c,fx)\r\n\r\n\r\n!!do i = 1,n\r\n!!do j = 1,n\r\n!! print*, i,j,c(i,j)\r\n!!end do\r\n!!end do\r\n\r\n!!print*,'fx is', fx\r\n\r\n\r\n!!print*,'c*fx is', matmul(c, fx) \r\n\r\n!!print*, size(c), size(fx)\r\n\r\n\r\n!!print*, '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'\r\n!!print*, x1\r\n!!print*, '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'\r\n\r\nx0 = x1\r\npointer = pointer + 1\r\nend do\r\n\r\n write(90, '(F8.5,X)', advance='no') muarray(q)\r\n\r\n do j=1,n\r\n write(90, '(F8.5,X)', advance='no') x1(j,1)\r\n end do\r\n\r\n write(90, *) '' ! this gives you the line break\r\n\r\n\r\nq = q+1\r\n\r\n\r\nend do\r\n\r\noutputfile = outputfile + 1\r\nclose(90)\r\nend do \r\n\r\nend program\r\n\r\n!!!!!!!!!! SUBROUTINES !!!!!!!!!!!!!\r\n\r\n\r\n\r\nsubroutine eqn(x0, w0, i, n, mu, f)\r\n\r\ninteger, intent(in):: n\r\nreal :: mu \r\nreal, DIMENSION(1:n) :: x0\r\nreal, DIMENSION(1:n) :: w0 \r\nreal, intent(out):: f\r\ninteger:: i\r\nreal :: sumn\r\n\r\ncall sum(x0, w0, i, n, sumn)\r\n\r\nprint*,'sum = ', sumn\r\nprint*, 'mu =', mu\r\n\r\nf = ((x0(i))**2) - (x0(i)) - (mu*sumn)\r\n\r\nreturn\r\nEND\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\nsubroutine sum(x0, w0, i, n, sumn)\r\n\r\ninteger, intent(in):: n\r\nreal, DIMENSION(n,1) :: x0 \r\nreal, DIMENSION(1:n) :: w0 \r\nreal, intent(out):: sumn \r\ninteger:: i, p,k\r\n\r\nk = i\r\n\r\np = k\r\n\r\nsumn = 0\r\n\r\ndo while (k /= n)\r\nsumn = sumn + (x0(p,1) - x0((k + 1),1))/(w0(p) - w0((k+1)) )\r\nk = k + 1\r\nend do\r\n\r\nk = p\r\n\r\ndo while (k /= 1)\r\nsumn = sumn + (x0(p,1) - x0((k - 1),1))/(w0(p) - w0((k-1)) )\r\nk = k -1\r\nend do\r\n\r\nreturn \r\nend\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\nsubroutine Jac(x0, mu, n, w0, jind)\r\n\r\ninteger :: n, j , i, k\r\nreal, DIMENSION(n,1) :: x0 \r\nreal, DIMENSION(1:n) :: w0 \r\nreal, DIMENSION(1:n, 1:n) :: jind\r\nreal :: mu, sumnaeta\r\n\r\nprint*, 'n value is ', n\r\n\r\nj = 1\r\n\r\ni = 1\r\n\r\n\r\n\r\ndo while( i /= n+1 )\r\n\r\ndo j = 1,n\r\n\r\nprint*, i, j\r\n\r\nif (i == j) then\r\nk = i\r\ncall sumaeta(w0, k, n, sumnaeta)\r\nprint*, 'once'\r\njind(i,j) = 2*(x0(i,1)) - 1 - (mu*sumnaeta) \r\nend if\r\n\r\nif(i /= j) then\r\nprint*, 'twice'\r\njind(i,j) = mu/(w0(i)-w0(j))\r\nend if\r\n\r\nend do \r\n\r\ni = i +1\r\nend do\r\n\r\n\r\nend\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\nsubroutine dectobin_gen(n,bin0,num)\r\n\r\ninteger :: n,num,i,temp\r\nreal, DIMENSION(n,1) :: bin0\r\n\r\ndo i = 1,n\r\n\r\nbin0(i,1) = 0\r\n\r\nend do\r\n\r\n\r\ntemp= num\r\n\r\ndo i=1,n\r\n\r\nif (mod(temp,2)==1) bin0(i,1)=1\r\n\r\n\r\ntemp = temp/2\r\n\r\nif (temp==0) exit\r\n\r\n\r\nend do\r\n\r\nend\r\n\r\n\r\n\r\n\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\nsubroutine sumaeta( w0, i, n, sumnaeta)\r\n\r\ninteger :: n\r\nreal, DIMENSION(1:n) :: w0 \r\nreal :: sumnaeta, sumn \r\ninteger:: i, p\r\n\r\np = i\r\n\r\nsumn = 0\r\n\r\ndo while (i /= n)\r\nsumn = sumn + (1/(w0(p)-w0(i+1)))\r\ni = i + 1\r\nend do\r\n\r\ni = p\r\n\r\ndo while (i /= 1)\r\nsumn = sumn + (1/(w0(p) - w0(i-1)))\r\ni = i -1\r\nend do\r\n\r\nsumnaeta = sumn\r\n\r\nreturn \r\nend\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\n subroutine inverse(a,c,n)\r\n!============================================================\r\n! Inverse matrix\r\n! Method: Based on Doolittle LU factorization for Ax=b\r\n! Alex G. December 2009\r\n!-----------------------------------------------------------\r\n! input ...\r\n! a(n,n) - array of coefficients for matrix A\r\n! n - dimension\r\n! output ...\r\n! c(n,n) - inverse matrix of A\r\n! comments ...\r\n! the original matrix a(n,n) will be destroyed \r\n! during the calculation\r\n!===========================================================\r\nimplicit none \r\ninteger n\r\nreal :: a(n,n), c(n,n)\r\nreal :: L(n,n), U(n,n), b(n), d(n), x(n)\r\nreal :: coeff\r\ninteger i, j, k\r\n\r\n! step 0: initialization for matrices L and U and b\r\n! Fortran 90/95 aloows such operations on matrices\r\nL=0.0\r\nU=0.0\r\nb=0.0\r\n\r\n! step 1: forward elimination\r\ndo k=1, n-1\r\n do i=k+1,n\r\n coeff=a(i,k)/a(k,k)\r\n L(i,k) = coeff\r\n do j=k+1,n\r\n a(i,j) = a(i,j)-coeff*a(k,j)\r\n end do\r\n end do\r\nend do\r\n\r\n! Step 2: prepare L and U matrices \r\n! L matrix is a matrix of the elimination coefficient\r\n! + the diagonal elements are 1.0\r\ndo i=1,n\r\n L(i,i) = 1.0\r\nend do\r\n! U matrix is the upper triangular part of A\r\ndo j=1,n\r\n do i=1,j\r\n U(i,j) = a(i,j)\r\n end do\r\nend do\r\n\r\n! Step 3: compute columns of the inverse matrix C\r\ndo k=1,n\r\n b(k)=1.0\r\n d(1) = b(1)\r\n! Step 3a: Solve Ld=b using the forward substitution\r\n do i=2,n\r\n d(i)=b(i)\r\n do j=1,i-1\r\n d(i) = d(i) - L(i,j)*d(j)\r\n end do\r\n end do\r\n! Step 3b: Solve Ux=d using the back substitution\r\n x(n)=d(n)/U(n,n)\r\n do i = n-1,1,-1\r\n x(i) = d(i)\r\n do j=n,i+1,-1\r\n x(i)=x(i)-U(i,j)*x(j)\r\n end do\r\n x(i) = x(i)/u(i,i)\r\n end do\r\n! Step 3c: fill the solutions x(n) into column k of C\r\n do i=1,n\r\n c(i,k) = x(i)\r\n end do\r\n b(k)=0.0\r\nend do\r\nend subroutine inverse\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\n", "meta": {"hexsha": "74e653861eaae44215c42a87f8e374ecfded0574", "size": 7249, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "newtonmd.f90", "max_stars_repo_name": "altiphyl/interneutrino-interaction-grapher", "max_stars_repo_head_hexsha": "ce0adcaef7e0f9aef4be28501fd05388258e2c67", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "newtonmd.f90", "max_issues_repo_name": "altiphyl/interneutrino-interaction-grapher", "max_issues_repo_head_hexsha": "ce0adcaef7e0f9aef4be28501fd05388258e2c67", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "newtonmd.f90", "max_forks_repo_name": "altiphyl/interneutrino-interaction-grapher", "max_forks_repo_head_hexsha": "ce0adcaef7e0f9aef4be28501fd05388258e2c67", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.6643678161, "max_line_length": 88, "alphanum_fraction": 0.4859980687, "num_tokens": 2525, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951025545427, "lm_q2_score": 0.7745833789613197, "lm_q1q2_score": 0.6536671200256071}} {"text": " program demo_selected_real_kind\n implicit none\n integer,parameter :: p6 = selected_real_kind(6)\n integer,parameter :: p10r100 = selected_real_kind(10,100)\n integer,parameter :: r400 = selected_real_kind(r=400)\n real(kind=p6) :: x\n real(kind=p10r100) :: y\n real(kind=r400) :: z\n\n print *, precision(x), range(x)\n print *, precision(y), range(y)\n print *, precision(z), range(z)\n end program demo_selected_real_kind\n", "meta": {"hexsha": "0472edc6e1619a397b6465d1299003c132c9cb9c", "size": 541, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/demo_selected_real_kind.f90", "max_stars_repo_name": "urbanjost/fortran-intrinsic-manpages", "max_stars_repo_head_hexsha": "672e0545bcbef3dd6c8169c8f6b8424dbb3f0880", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-06-30T07:29:39.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-10T07:36:25.000Z", "max_issues_repo_path": "example/demo_selected_real_kind.f90", "max_issues_repo_name": "urbanjost/fortran-intrinsic-manpages", "max_issues_repo_head_hexsha": "672e0545bcbef3dd6c8169c8f6b8424dbb3f0880", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-10-07T21:29:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-07T00:19:52.000Z", "max_forks_repo_path": "example/demo_selected_real_kind.f90", "max_forks_repo_name": "urbanjost/fortran-intrinsic-manpages", "max_forks_repo_head_hexsha": "672e0545bcbef3dd6c8169c8f6b8424dbb3f0880", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-10-08T00:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-08T00:41:17.000Z", "avg_line_length": 38.6428571429, "max_line_length": 69, "alphanum_fraction": 0.5600739372, "num_tokens": 122, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950947024556, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.6536671183348065}} {"text": "!*************************************************\n!\tno common\n!*************************************************\n\nmodule mod_qrdec\n\n\timplicit none\n\ncontains\n!=========\nsubroutine QRDEC(z_lc,y_lc, detl, nkdata, njtotal, njmt, u, lb, jmtt, ind)\n\n\timplicit none\n\n\tinteger, intent(in) :: nkdata, njtotal, njmt, ind\n\treal(8), intent(inout) :: z_lc(nkdata, njmt), y_lc(njtotal)\n\tinteger, intent(out) :: lb(njmt), jmtt\n\treal(8), intent(out) :: detl, u(njtotal)\n\t\n\tinteger :: i, k, kk\n\treal(8) :: eps, sm, b, sl\n\t\n\teps = 1.d-12\n\tdetl = 0.d0\n\tjmtt = 1\n\tlb = 0\n\t\n\tdo k = 1, njmt\n\t\t\n\t\tsm = 0.d0\n\t\t\n\t\tdo i = jmtt, njtotal\n\t\t\tu(i) = z_lc(i,k)\n\t\t\tsm = sm + u(i) * u(i)\n\t\tend do\n\t\t\n\t\tb = dsqrt(sm)\n\t\t\n\t\tif(b < eps) cycle\n\t\tif(u(jmtt) > 0.d0) b = -b\n\t\t\n\t\tu(jmtt) = u(jmtt) - b\n\t\t\n\t\tdo kk = k+1, njmt\n\t\t\t\n\t\t\tsl = 0.d0\n\t\t\t\n\t\t\tdo i = jmtt, njtotal\n\t\t\t\tsl = sl + z_lc(i,kk) * u(i)\n\t\t\tend do\n\t\t\t\n\t\t\tsl = sl / u(jmtt) / b\n\t\t\t\n\t\t\tdo i = jmtt, njtotal\n\t\t\t\tz_lc(i,kk) = z_lc(i,kk) + u(i) * sl\n\t\t\tend do\n\t\t\t\n\t\tend do\n\t\t\n\t\tz_lc(jmtt,k) = b\n\t\tdetl = detl + dlog(dabs(b))\n\t\t\n\t\tif(ind /= 0) then\n\t\t\t\n\t\t\tsl = 0.d0\n\t\t\t\n\t\t\tdo i = jmtt, njtotal\n\t\t\t\tsl = sl + y_lc(i) * u(i)\n\t\t\tend do\n\t\t\t\n\t\t\tsl = sl / u(jmtt) / b\n\t\t\t\n\t\t\tdo i = jmtt, njtotal\n\t\t\t\ty_lc(i) = y_lc(i) + u(i) * sl\n\t\t\tend do\n\t\t\t\n\t\tend if\n\t\t\n\t\tlb(k) = jmtt\n\t\tjmtt = jmtt + 1\n\t\t\n\tend do\n\t\n\tjmtt = jmtt - 1\n\t\nreturn\nend subroutine QRDEC\n\n!==========\nsubroutine RINV(x_lc, y_lc, z_lc, nkdata, jmtt, ind)\n\n\timplicit none\n\n\tinteger, intent(in) :: nkdata, jmtt, ind\n\treal(8), intent(in) :: y_lc(jmtt), z_lc(nkdata, jmtt)\n\treal(8), intent(inout) :: x_lc(jmtt)\n\n\tinteger :: k, j\n\treal(8) :: uf\n\n\tif(ind == 0) then\n\t\tdo k = jmtt, 1, -1\n\t\t\t\n\t\t\tuf = y_lc(k)\n\t\t\t\n\t\t\tdo j = k+1, jmtt\n\t\t\t\tuf = uf - x_lc(j) * z_lc(k,j)\n\t\t\tend do\n\t\t\t\n\t\t\tx_lc(k) = uf / z_lc(k,k)\n\t\t\t\n\t\tend do\n\t\treturn\n\tend if\n\n\tdo k = ind, jmtt\n\t\t\n\t\tuf = y_lc(k)\n\t\t\n\t\tdo j = ind, k-1\n\t\t\tuf = uf - x_lc(j) * z_lc(j,k)\n\t\tend do\n\t\t\n\t\tx_lc(k) = uf / z_lc(k,k)\n\t\t\n\tend do\n\nreturn\nend subroutine RINV\n\nend module mod_qrdec\n\n", "meta": {"hexsha": "97e16003e78cade288f63ca6310bfa94e8f94ae8", "size": 1998, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fort_160129/X_m_qrdec.f90", "max_stars_repo_name": "s-watanabe-jhod/YM1992", "max_stars_repo_head_hexsha": "85793cba6a81aeded1569dd0c61566e4c934e050", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fort_160129/X_m_qrdec.f90", "max_issues_repo_name": "s-watanabe-jhod/YM1992", "max_issues_repo_head_hexsha": "85793cba6a81aeded1569dd0c61566e4c934e050", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fort_160129/X_m_qrdec.f90", "max_forks_repo_name": "s-watanabe-jhod/YM1992", "max_forks_repo_head_hexsha": "85793cba6a81aeded1569dd0c61566e4c934e050", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-08-27T07:38:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-27T07:38:59.000Z", "avg_line_length": 15.022556391, "max_line_length": 74, "alphanum_fraction": 0.4944944945, "num_tokens": 820, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765234137297, "lm_q2_score": 0.7154240079185318, "lm_q1q2_score": 0.6536661203217208}} {"text": "C\nC-----------------------------------------------------------------------------\nC\n double precision function alfa(alfa0,qsq )\nC\nC-----------------------------------------------------------------------------\nC\nC\tThis function returns the 1-loop value of alpha.\nC\nC\tINPUT: \nC\t\tqsq = Q^2\nC\nC-----------------------------------------------------------------------------\nC\n implicit none\n double precision qsq,alfa0\nc\nc constants\nc\n double precision One, Three, Pi,zmass\n parameter( One = 1.0d0, Three = 3.0d0 )\n parameter( Pi = 3.14159265358979323846d0 )\n parameter( zmass = 91.188d0 )\ncc\n alfa = alfa0 / ( 1.0d0 - alfa0*dlog( qsq/zmass**2 ) /Three /Pi )\nccc\n return\n end\n\nC\nC-----------------------------------------------------------------------------\nC\n double precision function alfaw(alfaw0,qsq,nh )\nC\nC-----------------------------------------------------------------------------\nC\nC\tThis function returns the 1-loop value of alpha_w.\nC\nC\tINPUT: \nC\t\tqsq = Q^2\nC nh = # of Higgs doublets\nC\nC-----------------------------------------------------------------------------\nC\n implicit none\n double precision qsq, alphaw, dum,alfaw0\n integer nh, nq\nc\nc\t include\nc\n\t \nc\nc constants\nc\n double precision Two, Four, Pi, Twpi, zmass,tmass\n parameter( Two = 2.0d0, Four = 4.0d0 )\n parameter( Pi = 3.14159265358979323846d0 )\n parameter( Twpi = 3.0d0*Four*Pi )\n parameter( zmass = 91.188d0,tmass=174d0 )\ncc\n if ( qsq.ge.tmass**2 ) then\n nq = 6\n else\n nq = 5\n end if\n dum = ( 22.0d0 - Four*nq - nh/Two ) / Twpi\n alfaw = alfaw0 / ( 1.0d0 + dum*alfaw0*dlog( qsq/zmass**2 ) )\nccc\n return\n end\n\nC-----------------------------------------------------------------------------\nC\n DOUBLE PRECISION FUNCTION ALPHAS(Q)\nC wrapper to the lhapdf alphaS\nC-----------------------------------------------------------------------------\n IMPLICIT NONE\nc\n include 'alfas.inc'\n REAL*8 Q,alphasPDF\n external alphasPDF\n\nc timing statistics\nc include \"timing_variables.inc\"\n\nc This function takes 20 micro seconds to run, so it is ok to profile\nc it with the 0.3 ms function cpu_time.\nc call cpu_time(tbefore)\n ALPHAS=alphasPDF(Q)\nc call cpu_time(tAfter)\n \nc tPDF = tPDF + (tAfter-tBefore)\n\n RETURN\n END\n\nC-----------------------------------------------------------------------------\nC\n double precision function mfrun(mf,scale,asmz,nloop)\nC\nC-----------------------------------------------------------------------------\nC\nC\tThis function returns the 2-loop value of a MSbar fermion mass\nC at a given scale.\nC\nC\tINPUT: mf = MSbar mass of fermion at MSbar fermion mass scale \nC\t scale = scale at which the running mass is evaluated\nC\t asmz = AS(MZ) : this is passed to alphas(scale,asmz,nloop)\nC nloop = # of loops in the evolution\nC \nC\nC\nC\tEXTERNAL: double precision alphas(scale,asmz,nloop)\nC \nC-----------------------------------------------------------------------------\nC\n implicit none\nC\nC ARGUMENTS\nC\n double precision mf,scale,asmz\n integer nloop\nC\nC LOCAL\nC\n double precision beta0, beta1,gamma0,gamma1\n double precision A1,as,asmf,l2\n integer nf\nC\nC EXTERNAL\nC\n double precision alphas\n external alphas\nc\nc CONSTANTS\nc\n double precision One, Two, Three, Pi\n parameter( One = 1.0d0, Two = 2.0d0, Three = 3.0d0 )\n parameter( Pi = 3.14159265358979323846d0) \n double precision tmass\n parameter(tmass=174d0)\ncc\nC\nC\n if ( mf.gt.tmass ) then\n nf = 6\n else\n nf = 5\n end if\n\n beta0 = ( 11.0d0 - Two/Three *nf )/4d0\n beta1 = ( 102d0 - 38d0/Three*nf )/16d0\n gamma0= 1d0\n gamma1= ( 202d0/3d0 - 20d0/9d0*nf )/16d0\n A1 = -beta1*gamma0/beta0**2+gamma1/beta0\n as = alphas(scale)\n asmf = alphas(mf)\n l2 = (1+ A1*as/Pi)/(1+ A1*asmf/Pi)\n \n \n mfrun = mf * (as/asmf)**(gamma0/beta0)\n\n if(nloop.eq.2) mfrun =mfrun*l2\nccc\n return\n end\n\n", "meta": {"hexsha": "24128b14fb6f9f240e264ce9f210dcddadd76981", "size": 4225, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Template/RWGTNLO/alfas_functions_lhapdf.f", "max_stars_repo_name": "jlrainbolt/MG5_v2_6_1", "max_stars_repo_head_hexsha": "241f0c6f309342d6e8b813284467b2edd393c7d6", "max_stars_repo_licenses": ["NCSA"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-10-23T14:37:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-22T20:59:02.000Z", "max_issues_repo_path": "Template/RWGTNLO/alfas_functions_lhapdf.f", "max_issues_repo_name": "jlrainbolt/MG5_v2_6_1", "max_issues_repo_head_hexsha": "241f0c6f309342d6e8b813284467b2edd393c7d6", "max_issues_repo_licenses": ["NCSA"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2018-10-08T15:49:32.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-15T13:33:36.000Z", "max_forks_repo_path": "Template/RWGTNLO/alfas_functions_lhapdf.f", "max_forks_repo_name": "jlrainbolt/MG5_v2_6_1", "max_forks_repo_head_hexsha": "241f0c6f309342d6e8b813284467b2edd393c7d6", "max_forks_repo_licenses": ["NCSA"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2019-02-18T11:42:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-11T20:46:08.000Z", "avg_line_length": 25.1488095238, "max_line_length": 78, "alphanum_fraction": 0.4738461538, "num_tokens": 1229, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765328159726, "lm_q2_score": 0.7154239897159439, "lm_q1q2_score": 0.6536661104170337}} {"text": "!> \\brief \\b CROTG\n!\n! =========== DOCUMENTATION ===========\n!\n! Online html documentation available at\n! http://www.netlib.org/lapack/explore-html/\n!\n! Definition:\n! ===========\n!\n! CROTG constructs a plane rotation\n! [ c s ] [ a ] = [ r ]\n! [ -conjg(s) c ] [ b ] [ 0 ]\n! where c is real, s is complex, and c**2 + conjg(s)*s = 1.\n!\n!> \\par Purpose:\n! =============\n!>\n!> \\verbatim\n!>\n!> The computation uses the formulas\n!> |x| = sqrt( Re(x)**2 + Im(x)**2 )\n!> sgn(x) = x / |x| if x /= 0\n!> = 1 if x = 0\n!> c = |a| / sqrt(|a|**2 + |b|**2)\n!> s = sgn(a) * conjg(b) / sqrt(|a|**2 + |b|**2)\n!> When a and b are real and r /= 0, the formulas simplify to\n!> r = sgn(a)*sqrt(|a|**2 + |b|**2)\n!> c = a / r\n!> s = b / r\n!> the same as in CROTG when |a| > |b|. When |b| >= |a|, the\n!> sign of c and s will be different from those computed by CROTG\n!> if the signs of a and b are not the same.\n!>\n!> \\endverbatim\n!\n! Arguments:\n! ==========\n!\n!> \\param[in,out] A\n!> \\verbatim\n!> A is COMPLEX\n!> On entry, the scalar a.\n!> On exit, the scalar r.\n!> \\endverbatim\n!>\n!> \\param[in] B\n!> \\verbatim\n!> B is COMPLEX\n!> The scalar b.\n!> \\endverbatim\n!>\n!> \\param[out] C\n!> \\verbatim\n!> C is REAL\n!> The scalar c.\n!> \\endverbatim\n!>\n!> \\param[out] S\n!> \\verbatim\n!> S is COMPLEX\n!> The scalar s.\n!> \\endverbatim\n!\n! Authors:\n! ========\n!\n!> \\author Edward Anderson, Lockheed Martin\n!\n!> \\par Contributors:\n! ==================\n!>\n!> Weslley Pereira, University of Colorado Denver, USA\n!\n!> \\ingroup single_blas_level1\n!\n!> \\par Further Details:\n! =====================\n!>\n!> \\verbatim\n!>\n!> Anderson E. (2017)\n!> Algorithm 978: Safe Scaling in the Level 1 BLAS\n!> ACM Trans Math Softw 44:1--28\n!> https://doi.org/10.1145/3061665\n!>\n!> \\endverbatim\n!\n! =====================================================================\nsubroutine CROTG( a, b, c, s )\n integer, parameter :: wp = kind(1.e0)\n!\n! -- Reference BLAS level1 routine --\n! -- Reference BLAS is a software package provided by Univ. of Tennessee, --\n! -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n!\n! .. Constants ..\n real(wp), parameter :: zero = 0.0_wp\n real(wp), parameter :: one = 1.0_wp\n complex(wp), parameter :: czero = 0.0_wp\n! ..\n! .. Scaling constants ..\n real(wp), parameter :: safmin = real(radix(0._wp),wp)**max( &\n minexponent(0._wp)-1, &\n 1-maxexponent(0._wp) &\n )\n real(wp), parameter :: safmax = real(radix(0._wp),wp)**max( &\n 1-minexponent(0._wp), &\n maxexponent(0._wp)-1 &\n )\n real(wp), parameter :: rtmin = sqrt( real(radix(0._wp),wp)**max( &\n minexponent(0._wp)-1, &\n 1-maxexponent(0._wp) &\n ) / epsilon(0._wp) )\n real(wp), parameter :: rtmax = sqrt( real(radix(0._wp),wp)**max( &\n 1-minexponent(0._wp), &\n maxexponent(0._wp)-1 &\n ) * epsilon(0._wp) )\n! ..\n! .. Scalar Arguments ..\n real(wp) :: c\n complex(wp) :: a, b, s\n! ..\n! .. Local Scalars ..\n real(wp) :: d, f1, f2, g1, g2, h2, p, u, uu, v, vv, w\n complex(wp) :: f, fs, g, gs, r, t\n! ..\n! .. Intrinsic Functions ..\n intrinsic :: abs, aimag, conjg, max, min, real, sqrt\n! ..\n! .. Statement Functions ..\n real(wp) :: ABSSQ\n! ..\n! .. Statement Function definitions ..\n ABSSQ( t ) = real( t )**2 + aimag( t )**2\n! ..\n! .. Executable Statements ..\n!\n f = a\n g = b\n if( g == czero ) then\n c = one\n s = czero\n r = f\n else if( f == czero ) then\n c = zero\n g1 = max( abs(real(g)), abs(aimag(g)) )\n if( g1 > rtmin .and. g1 < rtmax ) then\n!\n! Use unscaled algorithm\n!\n g2 = ABSSQ( g )\n d = sqrt( g2 )\n s = conjg( g ) / d\n r = d\n else\n!\n! Use scaled algorithm\n!\n u = min( safmax, max( safmin, g1 ) )\n uu = one / u\n gs = g*uu\n g2 = ABSSQ( gs )\n d = sqrt( g2 )\n s = conjg( gs ) / d\n r = d*u\n end if\n else\n f1 = max( abs(real(f)), abs(aimag(f)) )\n g1 = max( abs(real(g)), abs(aimag(g)) )\n if( f1 > rtmin .and. f1 < rtmax .and. &\n g1 > rtmin .and. g1 < rtmax ) then\n!\n! Use unscaled algorithm\n!\n f2 = ABSSQ( f )\n g2 = ABSSQ( g )\n h2 = f2 + g2\n if( f2 > rtmin .and. h2 < rtmax ) then\n d = sqrt( f2*h2 )\n else\n d = sqrt( f2 )*sqrt( h2 )\n end if\n p = 1 / d\n c = f2*p\n s = conjg( g )*( f*p )\n r = f*( h2*p )\n else\n!\n! Use scaled algorithm\n!\n u = min( safmax, max( safmin, f1, g1 ) )\n uu = one / u\n gs = g*uu\n g2 = ABSSQ( gs )\n if( f1*uu < rtmin ) then\n!\n! f is not well-scaled when scaled by g1.\n! Use a different scaling for f.\n!\n v = min( safmax, max( safmin, f1 ) )\n vv = one / v\n w = v * uu\n fs = f*vv\n f2 = ABSSQ( fs )\n h2 = f2*w**2 + g2\n else\n!\n! Otherwise use the same scaling for f and g.\n!\n w = one\n fs = f*uu\n f2 = ABSSQ( fs )\n h2 = f2 + g2\n end if\n if( f2 > rtmin .and. h2 < rtmax ) then\n d = sqrt( f2*h2 )\n else\n d = sqrt( f2 )*sqrt( h2 )\n end if\n p = 1 / d\n c = ( f2*p )*w\n s = conjg( gs )*( fs*p )\n r = ( fs*( h2*p ) )*u\n end if\n end if\n a = r\n return\nend subroutine\n", "meta": {"hexsha": "18b7d74a71e06e7acbf251c171a8a97a0d40fa4c", "size": 5561, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "BLAS/SRC/crotg.f90", "max_stars_repo_name": "mathstuf/lapack", "max_stars_repo_head_hexsha": "a066b6a08f23186f2f38f1d9167f6616528ad89f", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-11-13T19:06:15.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-13T19:06:15.000Z", "max_issues_repo_path": "BLAS/SRC/crotg.f90", "max_issues_repo_name": "mathstuf/lapack", "max_issues_repo_head_hexsha": "a066b6a08f23186f2f38f1d9167f6616528ad89f", "max_issues_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-04-23T13:29:34.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-21T22:10:38.000Z", "max_forks_repo_path": "BLAS/SRC/crotg.f90", "max_forks_repo_name": "martin-frbg/lapack", "max_forks_repo_head_hexsha": "5d4180cf8288ae6ad9a771d18793d15bd0c5643c", "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": 24.1782608696, "max_line_length": 80, "alphanum_fraction": 0.4625067434, "num_tokens": 1950, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765210631689, "lm_q2_score": 0.7154239897159438, "lm_q1q2_score": 0.6536661020087958}} {"text": "! This file is part of HolmMHD\n! Copyright (C) 2019 Daniel Verscharen (d.verscharen@ucl.ac.uk)\n!All rights reserved.\n!\n!Redistribution and use in source and binary forms, with or without\n!modification, are permitted provided that the following conditions are met:\n!\n!1. Redistributions of source code must retain the above copyright notice, this\n! list of conditions and the following disclaimer.\n!2. Redistributions in binary form must reproduce the above copyright notice,\n! this list of conditions and the following disclaimer in the documentation\n! and/or other materials provided with the distribution.\n!\n!THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\n!ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n!WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n!DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR\n!ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n!(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n!LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\n!ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n!(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\n!SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n!\n!The views and conclusions contained in the software and documentation are those\n!of the authors and should not be interpreted as representing official policies,\n!either expressed or implied, of the HolmMHD project.\n\n\ndouble precision function divF(F,quant,i,j,k,wvel)\n! Calculate the divergence of F at the point (i,j,k)\n! F is a vector with F(comp,i,j,k)\nuse globals\nimplicit none\n\ndouble precision :: F(3,-1:Nx+2,-1:Ny+2,-1:Nz+2),quant(-1:Nx+2,-1:Ny+2,-1:Nz+2)\ndouble precision :: wvel(3,-1:Nx+2,-1:Ny+2,-1:Nz+2)\ndouble precision :: fph,fmh,flimitp,flimitm,r,fpl,fml\ndouble precision :: top,bot\ninteger :: i,j,k\n\n\n\n\n\n! Hybrid scheme with flux limiter:\n\n\n!!! DERIVATIVE IN X-DIRECTION:\n! This is the van Leer flux limiter:\ntop=quant(i,j,k)-quant(i-1,j,k)\nbot=quant(i+1,j,k)-quant(i,j,k)\nr=top*bot/(bot*bot+1.d-10)\n!flimitp=(r+abs(r))/(1.d0+abs(r))\t! van Leer limiter\nflimitp=max(0.d0,min(1.d0,r)) !min-mod limiter\n\n\ntop=quant(i-1,j,k)-quant(i-2,j,k)\nbot=quant(i,j,k)-quant(i-1,j,k)\nr=top*bot/(bot*bot+1.d-10)\n!flimitm=(r+abs(r))/(1.d0+abs(r))\nflimitm=max(0.d0,min(1.d0,r))\n\n\n! This is the lower order part (Rusanov):\nfpl=0.5d0*(F(1,i,j,k)+F(1,i+1,j,k))-0.5d0*max(wvel(1,i,j,k),wvel(1,i+1,j,k))*(quant(i+1,j,k)-quant(i,j,k))\nfml=0.5d0*(F(1,i-1,j,k)+F(1,i,j,k))-0.5d0*max(wvel(1,i,j,k),wvel(1,i-1,j,k))*(quant(i,j,k)-quant(i-1,j,k))\n\n! This is the higher order part (fourth-order centered):\n\nfph=(7.d0/12.d0)*(F(1,i,j,k)+F(1,i+1,j,k)) - (1.d0/12.d0)*(F(1,i-1,j,k)+F(1,i+2,j,k))\nfmh=(7.d0/12.d0)*(F(1,i-1,j,k)+F(1,i,j,k)) - (1.d0/12.d0)*(F(1,i-2,j,k)+F(1,i+1,j,k))\n!divF=((fpl-0.5d0*flimitp*(fpl-fph))-(fml-0.5d0*flimitm*(fml-fmh)))/dx\ndivF=((fpl-flimitp*(fpl-fph))-(fml-flimitm*(fml-fmh)))/dx\n\n\n\n\n\n!!! DERIVATIVE IN Y-DIRECTION:\n! This is the van Leer flux limiter:\ntop=quant(i,j,k)-quant(i,j-1,k)\nbot=quant(i,j+1,k)-quant(i,j,k)\nr=top*bot/(bot*bot+1.d-10)\n!flimitp=(r+abs(r))/(1.d0+abs(r))\nflimitp=max(0.d0,min(1.d0,r))\n\n\ntop=quant(i,j-1,k)-quant(i,j-2,k)\nbot=quant(i,j,k)-quant(i,j-1,k)\nr=top*bot/(bot*bot+1.d-10)\n!flimitm=(r+abs(r))/(1.d0+abs(r))\nflimitm=max(0.d0,min(1.d0,r))\n\n\n! This is the lower order part (Rusanov):\nfpl=0.5d0*(F(2,i,j,k)+F(2,i,j+1,k))-0.5d0*max(wvel(2,i,j,k),wvel(2,i,j+1,k))*(quant(i,j+1,k)-quant(i,j,k))\nfml=0.5d0*(F(2,i,j-1,k)+F(2,i,j,k))-0.5d0*max(wvel(2,i,j,k),wvel(2,i,j-1,k))*(quant(i,j,k)-quant(i,j-1,k))\n\n\n! This is the higher order part(fourth-order centered):\nfph=(7.d0/12.d0)*(F(2,i,j,k)+F(2,i,j+1,k)) - (1.d0/12.d0)*(F(2,i,j-1,k)+F(2,i,j+2,k))\nfmh=(7.d0/12.d0)*(F(2,i,j-1,k)+F(2,i,j,k)) - (1.d0/12.d0)*(F(2,i,j-2,k)+F(2,i,j+1,k))\n!divF=divF+((fpl-0.5d0*flimitp*(fpl-fph))-(fml-0.5d0*flimitm*(fml-fmh)))/dy\ndivF=divF+((fpl-flimitp*(fpl-fph))-(fml-flimitm*(fml-fmh)))/dy\n\n\n\n\n!!! DERIVATIVE IN Z-DIRECTION:\n! This is the van Leer flux limiter:\n\ntop=quant(i,j,k)-quant(i,j,k-1)\nbot=quant(i,j,k+1)-quant(i,j,k)\nr=top*bot/(bot*bot+1.d-10)\n!flimitp=(r+abs(r))/(1.d0+abs(r))\nflimitp=max(0.d0,min(1.d0,r))\n\ntop=quant(i,j,k-1)-quant(i,j,k-2)\nbot=quant(i,j,k)-quant(i,j,k-1)\nr=top*bot/(bot*bot+1.d-10)\n!flimitm=(r+abs(r))/(1.d0+abs(r))\nflimitm=max(0.d0,min(1.d0,r))\n\n\n! This is the lower order part (Rusanov):\n! We may possibly need a factor 0.5 instead of 0.25:\nfpl=0.5d0*(F(3,i,j,k)+F(3,i,j,k+1))-0.5d0*max(wvel(3,i,j,k),wvel(3,i,j,k+1))*(quant(i,j,k+1)-quant(i,j,k))\nfml=0.5d0*(F(3,i,j,k-1)+F(3,i,j,k))-0.5d0*max(wvel(3,i,j,k),wvel(3,i,j,k-1))*(quant(i,j,k)-quant(i,j,k-1))\n\n\n! This is the higher order part(fourth-order centered):\nfph=(7.d0/12.d0)*(F(3,i,j,k)+F(3,i,j,k+1)) - (1.d0/12.d0)*(F(3,i,j,k-1)+F(3,i,j,k+2))\nfmh=(7.d0/12.d0)*(F(3,i,j,k-1)+F(3,i,j,k)) - (1.d0/12.d0)*(F(3,i,j,k-2)+F(3,i,j,k+1))\n!divF=divF+((fpl-0.5d0*flimitp*(fpl-fph))-(fml-0.5d0*flimitm*(fml-fmh)))/dz\ndivF=divF+((fpl-flimitp*(fpl-fph))-(fml-flimitm*(fml-fmh)))/dz\n\nend function\n", "meta": {"hexsha": "f448085d1597990c553fcdaae8f7c3640ac9cb36", "size": 5170, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/divF.f90", "max_stars_repo_name": "danielver02/HolmMHD", "max_stars_repo_head_hexsha": "e32a42e77377bbc6632cb0e1aa975c45a83d1a66", "max_stars_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-07-16T01:44:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-27T01:55:53.000Z", "max_issues_repo_path": "src/divF.f90", "max_issues_repo_name": "danielver02/HolmMHD", "max_issues_repo_head_hexsha": "e32a42e77377bbc6632cb0e1aa975c45a83d1a66", "max_issues_repo_licenses": ["BSD-2-Clause-FreeBSD"], "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/divF.f90", "max_forks_repo_name": "danielver02/HolmMHD", "max_forks_repo_head_hexsha": "e32a42e77377bbc6632cb0e1aa975c45a83d1a66", "max_forks_repo_licenses": ["BSD-2-Clause-FreeBSD"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.1942446043, "max_line_length": 106, "alphanum_fraction": 0.669245648, "num_tokens": 2053, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765234137296, "lm_q2_score": 0.7154239836484143, "lm_q1q2_score": 0.6536660981466841}} {"text": "!=========================================================================\n! SUBRUTINA PARA EL CALCULO DE FUERZAS DE INTERACCION Y ENERGIA DE LA\n! CONFIGURACION PARA LA SIMULACION DE DINAMICA BROWNIANA\n!\n! AUTOR : MARTIN ALEJANDRO PAREDES SOSA\n!=========================================================================\n\nSubroutine Fuerza(L)\n Use cte\n Implicit None\n Real :: EnePot, U, U2, U3 !ENERGIA\n Real :: FXI, FYI, FZI, fxij, fyij, fzij !FUERZAS TEMP\n Real :: xij, yij, zij, rij !POSICIONES\n Real :: Pres, Pres1\n\n Integer :: i, j, L !CONTADORES (\"L\" CONTADOR DE LA CONFIGURACION)\n Logical :: Ctrl1, Ctrl2\n\n !INICIALIZANDO\n EnePot = 0.0\n FX = 0.0\n FY = 0.0\n FZ = 0.0\n\n Pres1 = 0.0\n\n Parti1: Do i = 1, N - 1\n\n FXI = FX(i)\n FYI = FY(i)\n FZI = FZ(i)\n\n Parti2: Do j = i + 1, N\n\n !SEPARACION\n xij = X(i) - X(j)\n yij = Y(i) - Y(j)\n zij = Z(i) - Z(j)\n \n !CONDICION DE IMAGEN MINIMA\n xij = xij - BoxL * Anint( xij / BoxL )\n yij = yij - BoxL * Anint( yij / BoxL )\n zij = zij - BoxL * Anint( zij / BoxL )\n\n !DISTANCIA\n rij = sqrt( xij*xij + yij*yij + zij*zij )\n\n !TRASLAPES\n Ctrl1 = rij .LE. 1.0\n Traslape : If(Ctrl1) Then\n \n Write(*,*) \"TRASLAPE\", i, j\n \n End If Traslape\n\n !IMPLEMENTACION DEL POTENCIAL\n Ctrl2 = rij .LT. RCut\n Potencial: If(Ctrl2) Then \n \n U = Exp( -YukZk * rij )\n U2 = YukA * U * (YukZk * rij + 1.0 ) / (rij**3)\n U3 = U2 * rij * rij\n EnePot = (YukA * U) / rij + EnePot\n\n fxij = xij * U2\n fyij = yij * U2\n fzij = zij * U2\n\n FXI = FXI + fxij\n FYI = FYI + fyij\n FZI = FZI + fzij\n\n FX(j) = FX(j) - fxij\n FY(j) = FY(j) - fyij\n FZ(j) = FZ(j) - fzij\n\n !PRECALCULO DE PRESION\n Pres1 = Pres1 + U3 \n\n End If Potencial\n \n End Do Parti2\n\n !GUARDANDO FUERZA\n FX(i) = FXI\n FY(i) = FYI\n FZ(i) = FZI\n \n End Do Parti1\n\n !CALCULO DE PRESION\n Pres = dens + (dens / (3.0 * real(N) ) ) * Pres1\n\n !GUADANDO TERMALIZACION (ENERGIA POR PARTICULA)\n Write(3,*) L , EnePot / Real(N), Pres\n \n If( mod(L , iPrint) == 0 ) Then\n Write(*,*) L , EnePot / Real(N) , Pres !MONITOREO EN PANTALLA\n End If\n\nEnd Subroutine Fuerza\n", "meta": {"hexsha": "900a1ce6b7b1f429f4f5a7020bdcf38c1b86a20f", "size": 2581, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "Portafolio_III/Comentarios/Fuerzas.f03", "max_stars_repo_name": "maps16/DesExpII", "max_stars_repo_head_hexsha": "d9d12b445e0fe86e32fce028be4f5b8bcfd2391f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Portafolio_III/Comentarios/Fuerzas.f03", "max_issues_repo_name": "maps16/DesExpII", "max_issues_repo_head_hexsha": "d9d12b445e0fe86e32fce028be4f5b8bcfd2391f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Portafolio_III/Comentarios/Fuerzas.f03", "max_forks_repo_name": "maps16/DesExpII", "max_forks_repo_head_hexsha": "d9d12b445e0fe86e32fce028be4f5b8bcfd2391f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.3039215686, "max_line_length": 113, "alphanum_fraction": 0.4366524603, "num_tokens": 887, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765140114859, "lm_q2_score": 0.7154239897159439, "lm_q1q2_score": 0.6536660969638527}} {"text": "! ============================================\n subroutine setaux(maxmx,maxmy,num_ghost,mx,my,xlower,ylower,dxc,dyc, &\n num_aux,aux,Rsphere)\n! ============================================\n\n! # Set auxiliary arrays for shallow water equations on the sphere.\n\n! # On input: (xc(i),yc(j)) gives uniformly spaced computational grid.\n! # On output: he aux array has the following elements:\n! 1 kappa = ratio of cell area to dxc*dyc\n! 2 enx = x-component of normal vector to left edges in tangent plane\n! 3 eny = y-component of normal vector to left edges in tangent plane\n! 4 enz = z-component of normal vector to left edges in tangent plane\n! 5 etx = x-component of tangent vector to left edges in tangent plane\n! 6 ety = y-component of tangent vector to left edges in tangent plane\n! 7 etz = z-component of tangent vector to left edges in tangent plane\n! 8 enx = x-component of normal vector to bottom edges in tangent plane\n! 9 eny = y-component of normal vector to bottom edges in tangent plane\n! 10 enz = z-component of normal vector to bottom edges in tangent plane\n! 11 etx = x-component of tangent vector to bottom edges in tangent plane\n! 12 ety = y-component of tangent vector to bottom edges in tangent plane\n! 13 etz = z-component of tangent vector to bottom edges in tangent plane\n! 14 erx = x-component of unit vector in radial direction at cell ctr\n! 15 ery = y-component of unit vector in radial direction at cell ctr\n! 16 erz = z-component of unit vector in radial direction at cell ctr\n\n\n implicit double precision (a-h,o-z)\n parameter (maxm3 = 1005)\n dimension xc(-3:maxm3), yc(-3:maxm3)\n dimension xp(-3:maxm3,-3:maxm3), yp(-3:maxm3,-3:maxm3)\n dimension zp(-3:maxm3,-3:maxm3)\n dimension theta(-3:maxm3,-3:maxm3), phi(-3:maxm3,-3:maxm3)\n dimension aux(num_aux,1-num_ghost:maxmx+num_ghost,1-num_ghost:maxmy+num_ghost)\n\n!f2py integer intent(in) maxmx\n!f2py integer intent(in) maxmy\n!f2py integer intent(in) num_ghost\n!f2py integer intent(in) mx\n!f2py integer intent(in) my\n!f2py double precision intent(in) xlower\n!f2py double precision intent(in) ylower\n!f2py double precision intent(in) dx\n!f2py double precision intent(in) dy\n!f2py integer optional, intent(in) num_aux\n!f2py intent(in,out) aux\n!f2py double precision intent(in) Rsphere\n\n pi = 4.d0*datan(1.d0)\n\n if (num_ghost > 4) then\n write(6,*)'*** increase size of local arrays in setaux ***'\n stop\n endif\n \n if (mx+num_ghost+1 > 1005 .OR. my+num_ghost+1 > 1005) then\n write(6,*)'*** increase size of 1005 in setaux ***'\n stop\n endif\n\n! # Set xc and yc so that (xc(i),yc(j)) is the\n! # lower left corner of (i,j) cell in computational space:\n\n do 10 i=1-num_ghost,mx+num_ghost+1\n xc(i) = xlower + (i-1.d0) * dxc\n 10 END DO\n\n do 12 j=1-num_ghost,my+num_ghost+1\n yc(j) = ylower + (j-1.d0) * dyc\n 12 END DO\n\n! # compute cell corners on sphere and angles phi, theta\n! # related to latitude and longitude\n\n do 15 j=1-num_ghost,my+num_ghost+1\n do 15 i=1-num_ghost,mx+num_ghost+1\n\n ! # map computational point to (xp,yp,zp) on sphere:\n call mapc2p(xc(i),yc(j),xp(i,j),yp(i,j),zp(i,j),Rsphere)\n\n ! # compute longitude theta from positive x axis:\n r = dsqrt(xp(i,j)**2 + yp(i,j)**2)\n\n ! theta(i,j) = atan2(xp(i,j),yp(i,j))\n\n if (r > 1.d-4) then\n theta(i,j) = dacos(xp(i,j)/r)\n elseif (yp(i,j) > 0.d0) then\n theta(i,j) = 0.d0\n endif\n if (yp(i,j) < 0.d0) then\n theta(i,j) = -theta(i,j)\n endif\n ! # compute phi, angle down from north pole:\n if (zp(i,j) > 0.d0) then\n phi(i,j) = pi/2.d0 - dacos(r/Rsphere)\n else\n phi(i,j) = pi/2.d0 + dacos(r/Rsphere)\n endif\n 15 END DO\n\n\n do 20 j=1-num_ghost,my+num_ghost\n do 20 i=1-num_ghost,mx+num_ghost\n \n ! # compute normal and tangent vectors to left edges (in tangent plane)\n \n ! # tangent vector is edges vector:\n etx = xp(i,j+1) - xp(i,j)\n ety = yp(i,j+1) - yp(i,j)\n etz = zp(i,j+1) - zp(i,j)\n aux(5,i,j) = etx\n aux(6,i,j) = ety\n aux(7,i,j) = etz\n\n ! # normal to sphere in radial direction at midpoint of edges:\n erx = 0.5d0*(xp(i,j) + xp(i,j+1))\n ery = 0.5d0*(yp(i,j) + yp(i,j+1))\n erz = 0.5d0*(zp(i,j) + zp(i,j+1))\n \n ! # normal to edges in tangent plane is cross product of et and er:\n enx = ety*erz - etz*ery\n eny = etz*erx - etx*erz\n enz = etx*ery - ety*erx\n ennorm = dsqrt(enx**2 + eny**2 + enz**2)\n aux(2,i,j) = enx/ennorm\n aux(3,i,j) = eny/ennorm\n aux(4,i,j) = enz/ennorm\n\n\n ! # compute normal and tangent vectors to bottom edges (in tang. pl.)\n \n ! # tangent vector is edges vector:\n etx = xp(i+1,j) - xp(i,j)\n ety = yp(i+1,j) - yp(i,j)\n etz = zp(i+1,j) - zp(i,j)\n aux(11,i,j) = etx\n aux(12,i,j) = ety\n aux(13,i,j) = etz\n\n ! # normal to sphere in radial direction at midpoint of edges:\n erx = 0.5d0*(xp(i,j) + xp(i+1,j))\n ery = 0.5d0*(yp(i,j) + yp(i+1,j))\n erz = 0.5d0*(zp(i,j) + zp(i+1,j))\n \n ! # normal to edges in tangent plane is cross product of er and et:\n enx = ery*etz - erz*ety\n eny = erz*etx - erx*etz\n enz = erx*ety - ery*etx\n ennorm = dsqrt(enx**2 + eny**2 + enz**2)\n aux(8,i,j) = enx/ennorm\n aux(9,i,j) = eny/ennorm\n aux(10,i,j) = enz/ennorm\n\n ! # normal to sphere in radial direction at cell centers:\n xcm = xlower+(i-0.5)*dxc\n ycm = ylower+(j-0.5)*dyc\n call mapc2p(xcm,ycm,xpm,ypm,zpm,Rsphere)\n\n aux(14,i,j) = xpm\n aux(15,i,j) = ypm\n aux(16,i,j) = zpm\n\n ! # compute area of physical cell from four corners:\n ! # find area on the sphere of two spherical triangles obtained\n ! # by subdividing rectangle. See\n ! # http://mathforum.org/library/drmath/view/65316.html\n\n ! # corners are labeled\n ! # 1: (i,j) 2: (i+1,j) 3: (i,j+1) 4: (i+1,j+1)\n\n beta12 = dsin(phi(i,j))*dsin(phi(i+1,j))* &\n dcos(theta(i,j) - theta(i+1,j)) &\n + dcos(phi(i,j))*dcos(phi(i+1,j))\n beta23 = dsin(phi(i,j+1))*dsin(phi(i+1,j))* &\n dcos(theta(i,j+1) - theta(i+1,j)) &\n + dcos(phi(i,j+1))*dcos(phi(i+1,j))\n beta13 = dsin(phi(i,j+1))*dsin(phi(i,j))* &\n dcos(theta(i,j+1) - theta(i,j)) &\n + dcos(phi(i,j+1))*dcos(phi(i,j))\n beta24 = dsin(phi(i+1,j+1))*dsin(phi(i+1,j))* &\n dcos(theta(i+1,j+1) - theta(i+1,j)) &\n + dcos(phi(i+1,j+1))*dcos(phi(i+1,j))\n beta34 = dsin(phi(i+1,j+1))*dsin(phi(i,j+1))* &\n dcos(theta(i+1,j+1) - theta(i,j+1)) &\n + dcos(phi(i+1,j+1))*dcos(phi(i,j+1))\n\n ! # great circles distances between corners:\n d12 = Rsphere * dacos(beta12)\n d23 = Rsphere * dacos(beta23)\n d13 = Rsphere * dacos(beta13)\n d24 = Rsphere * dacos(beta24)\n d34 = Rsphere * dacos(beta34)\n\n s123 = 0.5d0 * (d12 + d23 + d13)\n s234 = 0.5d0 * (d23 + d34 + d24)\n\n ! # spherical excess for each triangle:\n t123 = dtan(s123/2.d0)*dtan((s123-d12)/2.d0) &\n *dtan((s123-d23)/2.d0)*dtan((s123-d13)/2.d0)\n t123 = dmax1(t123,0.d0)\n E123 = 4.d0*datan(sqrt(t123))\n\n t234 = dtan(s234/2.d0)*dtan((s234-d23)/2.d0) &\n *dtan((s234-d34)/2.d0)*dtan((s234-d24)/2.d0)\n t234 = dmax1(t234,0.d0)\n E234 = 4.d0*datan(sqrt(t234))\n\n ! area = Rsphere**2 * (E123 + E234)\n area = (E123 + E234)\n \n ! # capacity kappa:\n aux(1,i,j) = area / (dxc*dyc)\n \n 20 END DO\n\n return\n end subroutine setaux\n", "meta": {"hexsha": "a38c7dfc6d9be8c87c56f7b4dca4da5fa2395f34", "size": 8583, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "docker/src/clawpack-5.3.1/pyclaw/examples/shallow_sphere/setaux.f90", "max_stars_repo_name": "ian-r-rose/visualization", "max_stars_repo_head_hexsha": "ed6d9fab95eb125e7340ab3fad3ed114ed3214af", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2017-01-04T18:19:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-21T01:46:33.000Z", "max_issues_repo_path": "docker/src/clawpack-5.3.1/pyclaw/examples/shallow_sphere/setaux.f90", "max_issues_repo_name": "ian-r-rose/visualization", "max_issues_repo_head_hexsha": "ed6d9fab95eb125e7340ab3fad3ed114ed3214af", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2016-09-22T20:49:51.000Z", "max_issues_repo_issues_event_max_datetime": "2019-09-06T23:28:13.000Z", "max_forks_repo_path": "docker/src/clawpack-5.3.1/pyclaw/examples/shallow_sphere/setaux.f90", "max_forks_repo_name": "ian-r-rose/visualization", "max_forks_repo_head_hexsha": "ed6d9fab95eb125e7340ab3fad3ed114ed3214af", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2016-09-22T20:20:06.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-13T14:48:32.000Z", "avg_line_length": 39.1917808219, "max_line_length": 89, "alphanum_fraction": 0.5155540021, "num_tokens": 2712, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218348550491, "lm_q2_score": 0.7090191276365462, "lm_q1q2_score": 0.6536602150980109}} {"text": "\\ Program to calculate big factorial\n\\ Michel Jean - December 2021 v1.0\n\ncreate result 10000 cells allot \\ Size of the result\nvariable result_size \nvariable carry\nvariable product\nvariable x\nvariable input\n\n: calcul ( -- ) \n 0 carry !\n result_size @ 0 do\n i cells result + @ x @ * carry @ + product !\n product @ 10 mod result i cells + !\n product @ 10 / carry !\n loop \n \n begin\n carry @ 0 > while\n carry @ 10 mod result result_size @ cells + !\n carry @ 10 / carry !\n result_size @ 1+ result_size !\n repeat\n;\n: output ( -- )\n .\" The factorial of \" input ? .\" is : \" cr\n result_size @ 1- result_size !\n begin\n result_size @ 0 >= while\n result_size @ cells result + ? \n result_size @ 1- result_size !\n result_size 30 mod 0 = if cr then \\ input by line \n repeat\n;\n: factorial ( -- )\n input !\n 1 result 0 cells + !\n 1 result_size !\n 2 x !\n \n begin \n x @ input @ <= while \n calcul\n x @ 1+ x !\n repeat\n output \n;\n", "meta": {"hexsha": "9f28c4fea84ca234d59be5dc159f71bc58b5fd16", "size": 1008, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "factoriel.f", "max_stars_repo_name": "ForthWin/Forth2020UsersGroup", "max_stars_repo_head_hexsha": "75a1eda391d1641ab115b18545cc49ce2b434d1d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2020-01-15T05:11:36.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-22T17:42:41.000Z", "max_issues_repo_path": "factoriel.f", "max_issues_repo_name": "iooo64/Forth2020UsersGroup", "max_issues_repo_head_hexsha": "77ddf3bcd415d9adc2c1a6b3a37e0d57f0a00a42", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "factoriel.f", "max_forks_repo_name": "iooo64/Forth2020UsersGroup", "max_forks_repo_head_hexsha": "77ddf3bcd415d9adc2c1a6b3a37e0d57f0a00a42", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-06T21:53:09.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-06T21:53:09.000Z", "avg_line_length": 20.5714285714, "max_line_length": 54, "alphanum_fraction": 0.5823412698, "num_tokens": 290, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218284193597, "lm_q2_score": 0.7090191276365462, "lm_q1q2_score": 0.653660210534984}} {"text": "\tFUNCTION PR_VSKN ( vsbk )\nC************************************************************************\nC* PR_VSKN\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes VSBN from VSBK. 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* VSBN = .54 * VSBK\t \t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* REAL PR_VSKN ( VSBK )\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*\tVSBK\t\tREAL\t\tVisibility in kilometers *\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPR_VSKN\t\tREAL\t\tVisibility in nautical miles *\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* D. Kidwell/NCEP\t5/97\t \t\t\t*\nC************************************************************************\n INCLUDE 'GEMPRM.PRM'\n INCLUDE 'ERMISS.FNC'\nC------------------------------------------------------------------------\nC*\tCheck for invalid data.\nC\n\tIF ( ERMISS ( vsbk ) ) THEN\n\t PR_VSKN = RMISSD\n\t ELSE\nC\nC*\t Do the conversion.\nC\n\t PR_VSKN = .54 * vsbk\n\tEND IF\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "0c6c134fb01ee145cdb6444a83a5c2b263deb74b", "size": 993, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/pr/prvskn.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/prvskn.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/prvskn.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": 26.8378378378, "max_line_length": 73, "alphanum_fraction": 0.3786505539, "num_tokens": 285, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004187, "lm_q2_score": 0.734119526900183, "lm_q1q2_score": 0.6535823718089107}} {"text": "! MD5 of template: 3549e07e97deb67e68b2b72e1c3d3ba3\n! 3D vector related routines\n!\n! ------------------------------------------------------------------------------\n! Copyright (c) 2009-13, Thomas P. Robitaille\n!\n! All rights reserved.\n!\n! Redistribution and use in source and binary forms, with or without\n! modification, are permitted provided that the following conditions are met:\n!\n! * Redistributions of source code must retain the above copyright notice, this\n! list of conditions and the following disclaimer.\n!\n! * Redistributions in binary form must reproduce the above copyright notice,\n! this list of conditions and the following disclaimer in the documentation\n! and/or other materials provided with the distribution.\n!\n! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n! DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\n! FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n! DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n! SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\n! OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n! OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n! ------------------------------------------------------------------------------\n\nmodule type_vector3d\n\n implicit none\n save\n\n private\n\n integer,parameter :: sp = selected_real_kind(p=6,r=37)\n integer,parameter :: dp = selected_real_kind(p=15,r=307)\n\n public :: vector3d_sp\n type vector3d_sp\n real(sp) :: x,y,z\n end type vector3d_sp\n\n public :: vector3d_dp\n type vector3d_dp\n real(dp) :: x,y,z\n end type vector3d_dp\n\n public :: operator(.eq.)\n interface operator(.eq.)\n module procedure equal_sp\n module procedure equal_dp\n end interface operator(.eq.)\n\n public :: operator(+)\n interface operator(+)\n module procedure add_vector3d_sp\n module procedure add_vector3d_dp\n end interface operator(+)\n\n public :: operator(-)\n interface operator(-)\n module procedure sub_vector3d_sp\n module procedure sub_vector3d_dp\n module procedure minus_vector3d_sp\n module procedure minus_vector3d_dp\n end interface operator(-)\n\n public :: operator(.dot.)\n interface operator(.dot.)\n module procedure dot_product_sp\n module procedure dot_product_dp\n end interface operator(.dot.)\n\n public :: operator(.cross.)\n interface operator(.cross.)\n module procedure cross_product_sp\n module procedure cross_product_dp\n end interface operator(.cross.)\n\n public :: operator(*)\n interface operator(*)\n module procedure scalar_vector3d_mult_sp\n module procedure scalar_vector3d_mult_dp\n module procedure vector3d_scalar_mult_sp\n module procedure vector3d_scalar_mult_dp\n end interface operator(*)\n\n public :: operator(/)\n interface operator(/)\n module procedure scalar_vector3d_div_sp\n module procedure scalar_vector3d_div_dp\n module procedure vector3d_scalar_div_sp\n module procedure vector3d_scalar_div_dp\n end interface operator(/)\n\n public :: vector3d_to_angle3d\n interface vector3d_to_angle3d\n module procedure vector3d_to_angle3d_sp\n module procedure vector3d_to_angle3d_dp\n end interface vector3d_to_angle3d\n\n public :: angle3d_to_vector3d\n interface angle3d_to_vector3d\n module procedure angle3d_to_vector3d_sp\n module procedure angle3d_to_vector3d_dp\n end interface angle3d_to_vector3d\n\n public :: random_sphere_vector3d\n interface random_sphere_vector3d\n module procedure random_sphere_vector3d_sp\n module procedure random_sphere_vector3d_dp\n end interface random_sphere_vector3d\n\ncontains\n\n\n !**********************************************************************!\n ! Test equality\n !**********************************************************************!\n\n logical function equal_dp(a, b) result(e)\n\n implicit none\n\n type(vector3d_dp),intent(in) :: a, b\n\n e = a%x == b%x .and. a%y == b%y .and. a%z == b%z\n\n end function equal_dp\n\n !**********************************************************************!\n ! Vector addition\n !**********************************************************************!\n\n type(vector3d_dp) function add_vector3d_dp(a,b) result(v)\n\n implicit none\n\n type(vector3d_dp),intent(in) :: a,b\n\n v%x = a%x + b%x\n v%y = a%y + b%y\n v%z = a%z + b%z\n\n end function add_vector3d_dp\n\n !**********************************************************************!\n ! Vector subtraction\n !**********************************************************************!\n\n type(vector3d_dp) function sub_vector3d_dp(a,b) result(v)\n\n implicit none\n\n type(vector3d_dp),intent(in) :: a,b\n\n v%x = a%x - b%x\n v%y = a%y - b%y\n v%z = a%z - b%z\n\n end function sub_vector3d_dp\n\n !**********************************************************************!\n ! Unary minus for vectors\n !**********************************************************************!\n\n type(vector3d_dp) function minus_vector3d_dp(a) result(v)\n\n implicit none\n\n type(vector3d_dp),intent(in) :: a\n\n v%x = -a%x\n v%y = -a%y\n v%z = -a%z\n\n end function minus_vector3d_dp\n\n !**********************************************************************!\n ! Vector dot product\n !**********************************************************************!\n\n real(dp) function dot_product_dp(a,b) result(p)\n\n implicit none\n\n type(vector3d_dp),intent(in) :: a,b\n\n p = a%x*b%x + a%y*b%y + a%z*b%z\n\n end function dot_product_dp\n\n !**********************************************************************!\n ! Vector cross product\n !**********************************************************************!\n\n type(vector3d_dp) function cross_product_dp(a,b) result(p)\n\n implicit none\n\n type(vector3d_dp),intent(in) :: a,b\n\n p%x = a%y*b%z - a%z*b%y\n p%y = a%z*b%x - a%x*b%z\n p%z = a%x*b%y - a%y*b%x\n\n end function cross_product_dp\n\n !**********************************************************************!\n ! Scalar * Vector\n !**********************************************************************!\n\n type(vector3d_dp) function scalar_vector3d_mult_dp(a,b) result(v)\n\n implicit none\n\n real(dp),intent(in) :: a\n type(vector3d_dp),intent(in) :: b\n\n v%x = a * b%x\n v%y = a * b%y\n v%z = a * b%z\n\n end function scalar_vector3d_mult_dp\n\n type(vector3d_dp) function vector3d_scalar_mult_dp(a,b) result(v)\n\n implicit none\n\n type(vector3d_dp),intent(in) :: a\n real(dp),intent(in) :: b\n\n v%x = a%x * b\n v%y = a%y * b\n v%z = a%z * b\n\n end function vector3d_scalar_mult_dp\n\n !**********************************************************************!\n ! Scalar / Vector\n !**********************************************************************!\n\n type(vector3d_dp) function scalar_vector3d_div_dp(a,b) result(v)\n\n implicit none\n\n real(dp),intent(in) :: a\n type(vector3d_dp),intent(in) :: b\n\n v%x = a / b%x\n v%y = a / b%y\n v%z = a / b%z\n\n end function scalar_vector3d_div_dp\n\n type(vector3d_dp) function vector3d_scalar_div_dp(a,b) result(v)\n\n implicit none\n\n type(vector3d_dp),intent(in) :: a\n real(dp),intent(in) :: b\n\n v%x = a%x / b\n v%y = a%y / b\n v%z = a%z / b\n\n end function vector3d_scalar_div_dp\n\n !**********************************************************************!\n ! Vector to angle and vice-versa\n !**********************************************************************!\n\n subroutine vector3d_to_angle3d_dp(v,a)\n\n use type_angle3d\n\n implicit none\n\n type(vector3d_dp),intent(in) :: v\n ! input 3d vector\n\n type(angle3d_dp),intent(out) :: a\n ! output 3d angle\n\n real(dp) :: small_r,big_r\n\n small_r = sqrt( v%x * v%x + v%y * v%y )\n big_r = sqrt( v%x * v%x + v%y * v%y + v%z * v%z )\n\n a%cosp = v%x / small_r\n a%sinp = v%y / small_r\n\n a%cost = v%z / big_r\n a%sint = small_r / big_r\n\n end subroutine vector3d_to_angle3d_dp\n\n subroutine angle3d_to_vector3d_dp(a,v)\n\n use type_angle3d\n\n implicit none\n\n type(angle3d_dp),intent(in) :: a\n ! input 3d angle\n\n type(vector3d_dp),intent(out) :: v\n ! output 3d vector\n\n v%x = a%sint * a%cosp\n v%y = a%sint * a%sinp\n v%z = a%cost\n\n end subroutine angle3d_to_vector3d_dp\n\n !**********************************************************************!\n ! Random position on a unit sphere\n !**********************************************************************!\n\n subroutine random_sphere_vector3d_dp(v)\n use lib_random\n implicit none\n type(vector3d_dp),intent(out) :: v\n real(dp) :: mu,phi,radius_cut\n call random_sphere(mu,phi)\n radius_cut = sqrt(1._dp-mu*mu)\n v%x = radius_cut * cos(phi)\n v%y = radius_cut * sin(phi)\n v%z = mu\n end subroutine random_sphere_vector3d_dp\n\n\n !**********************************************************************!\n ! Test equality\n !**********************************************************************!\n\n logical function equal_sp(a, b) result(e)\n\n implicit none\n\n type(vector3d_sp),intent(in) :: a, b\n\n e = a%x == b%x .and. a%y == b%y .and. a%z == b%z\n\n end function equal_sp\n\n !**********************************************************************!\n ! Vector addition\n !**********************************************************************!\n\n type(vector3d_sp) function add_vector3d_sp(a,b) result(v)\n\n implicit none\n\n type(vector3d_sp),intent(in) :: a,b\n\n v%x = a%x + b%x\n v%y = a%y + b%y\n v%z = a%z + b%z\n\n end function add_vector3d_sp\n\n !**********************************************************************!\n ! Vector subtraction\n !**********************************************************************!\n\n type(vector3d_sp) function sub_vector3d_sp(a,b) result(v)\n\n implicit none\n\n type(vector3d_sp),intent(in) :: a,b\n\n v%x = a%x - b%x\n v%y = a%y - b%y\n v%z = a%z - b%z\n\n end function sub_vector3d_sp\n\n !**********************************************************************!\n ! Unary minus for vectors\n !**********************************************************************!\n\n type(vector3d_sp) function minus_vector3d_sp(a) result(v)\n\n implicit none\n\n type(vector3d_sp),intent(in) :: a\n\n v%x = -a%x\n v%y = -a%y\n v%z = -a%z\n\n end function minus_vector3d_sp\n\n !**********************************************************************!\n ! Vector dot product\n !**********************************************************************!\n\n real(sp) function dot_product_sp(a,b) result(p)\n\n implicit none\n\n type(vector3d_sp),intent(in) :: a,b\n\n p = a%x*b%x + a%y*b%y + a%z*b%z\n\n end function dot_product_sp\n\n !**********************************************************************!\n ! Vector cross product\n !**********************************************************************!\n\n type(vector3d_sp) function cross_product_sp(a,b) result(p)\n\n implicit none\n\n type(vector3d_sp),intent(in) :: a,b\n\n p%x = a%y*b%z - a%z*b%y\n p%y = a%z*b%x - a%x*b%z\n p%z = a%x*b%y - a%y*b%x\n\n end function cross_product_sp\n\n !**********************************************************************!\n ! Scalar * Vector\n !**********************************************************************!\n\n type(vector3d_sp) function scalar_vector3d_mult_sp(a,b) result(v)\n\n implicit none\n\n real(sp),intent(in) :: a\n type(vector3d_sp),intent(in) :: b\n\n v%x = a * b%x\n v%y = a * b%y\n v%z = a * b%z\n\n end function scalar_vector3d_mult_sp\n\n type(vector3d_sp) function vector3d_scalar_mult_sp(a,b) result(v)\n\n implicit none\n\n type(vector3d_sp),intent(in) :: a\n real(dp),intent(in) :: b\n\n v%x = a%x * b\n v%y = a%y * b\n v%z = a%z * b\n\n end function vector3d_scalar_mult_sp\n\n !**********************************************************************!\n ! Scalar / Vector\n !**********************************************************************!\n\n type(vector3d_sp) function scalar_vector3d_div_sp(a,b) result(v)\n\n implicit none\n\n real(sp),intent(in) :: a\n type(vector3d_sp),intent(in) :: b\n\n v%x = a / b%x\n v%y = a / b%y\n v%z = a / b%z\n\n end function scalar_vector3d_div_sp\n\n type(vector3d_sp) function vector3d_scalar_div_sp(a,b) result(v)\n\n implicit none\n\n type(vector3d_sp),intent(in) :: a\n real(sp),intent(in) :: b\n\n v%x = a%x / b\n v%y = a%y / b\n v%z = a%z / b\n\n end function vector3d_scalar_div_sp\n\n !**********************************************************************!\n ! Vector to angle and vice-versa\n !**********************************************************************!\n\n subroutine vector3d_to_angle3d_sp(v,a)\n\n use type_angle3d\n\n implicit none\n\n type(vector3d_sp),intent(in) :: v\n ! input 3d vector\n\n type(angle3d_sp),intent(out) :: a\n ! output 3d angle\n\n real(sp) :: small_r,big_r\n\n small_r = sqrt( v%x * v%x + v%y * v%y )\n big_r = sqrt( v%x * v%x + v%y * v%y + v%z * v%z )\n\n a%cosp = v%x / small_r\n a%sinp = v%y / small_r\n\n a%cost = v%z / big_r\n a%sint = small_r / big_r\n\n end subroutine vector3d_to_angle3d_sp\n\n subroutine angle3d_to_vector3d_sp(a,v)\n\n use type_angle3d\n\n implicit none\n\n type(angle3d_sp),intent(in) :: a\n ! input 3d angle\n\n type(vector3d_sp),intent(out) :: v\n ! output 3d vector\n\n v%x = a%sint * a%cosp\n v%y = a%sint * a%sinp\n v%z = a%cost\n\n end subroutine angle3d_to_vector3d_sp\n\n !**********************************************************************!\n ! Random position on a unit sphere\n !**********************************************************************!\n\n subroutine random_sphere_vector3d_sp(v)\n use lib_random\n implicit none\n type(vector3d_sp),intent(out) :: v\n real(sp) :: mu,phi,radius_cut\n call random_sphere(mu,phi)\n radius_cut = sqrt(1._sp-mu*mu)\n v%x = radius_cut * cos(phi)\n v%y = radius_cut * sin(phi)\n v%z = mu\n end subroutine random_sphere_vector3d_sp\n\n\nend module type_vector3d\n", "meta": {"hexsha": "5ebfb2181d9d771774cb9aa05a5c19ab400e59fe", "size": 14303, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "extra/Fortran/fortranlib-master/fortranlib-master/src/type_vector3d.f90", "max_stars_repo_name": "jfitz/code-stat", "max_stars_repo_head_hexsha": "dd2a13177f3ef03ab42123ef3cfcbbd062a2ae26", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 255, "max_stars_repo_stars_event_min_datetime": "2015-01-22T20:12:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-16T05:39:48.000Z", "max_issues_repo_path": "extra/Fortran/fortranlib-master/fortranlib-master/src/type_vector3d.f90", "max_issues_repo_name": "jfitz/code-stat", "max_issues_repo_head_hexsha": "dd2a13177f3ef03ab42123ef3cfcbbd062a2ae26", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2015-05-06T22:43:11.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-27T04:13:37.000Z", "max_forks_repo_path": "extra/Fortran/fortranlib-master/fortranlib-master/src/type_vector3d.f90", "max_forks_repo_name": "jfitz/code-stat", "max_forks_repo_head_hexsha": "dd2a13177f3ef03ab42123ef3cfcbbd062a2ae26", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 75, "max_forks_repo_forks_event_min_datetime": "2015-02-17T13:48:32.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T20:03:53.000Z", "avg_line_length": 25.8643761302, "max_line_length": 80, "alphanum_fraction": 0.5186324547, "num_tokens": 3663, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706734, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.6535407420945156}} {"text": "MODULE triangle_class\r\n!\r\n! This module implements a triangle class. \r\n!\r\n! Record of revisions:\r\n! Date Programmer Description of change\r\n! ==== ========== =====================\r\n! 12/29/06 S. J. Chapman Original code\r\n!\r\nUSE shape_class ! USE parent class\r\nIMPLICIT NONE\r\n\r\n! Type definition\r\nTYPE,PUBLIC,EXTENDS(shape) :: triangle \r\n\r\n ! Additional instance variables. \r\n REAL :: s = 0 ! Length of side\r\n\r\nCONTAINS\r\n\r\n ! Bound procedures\r\n PROCEDURE,PUBLIC :: initialize => initialize_sub\r\n PROCEDURE,PUBLIC :: area => get_area_fn\r\n PROCEDURE,PUBLIC :: perimeter => get_perimeter_fn\r\n PROCEDURE,PUBLIC :: to_string => to_string_fn\r\n\r\nEND TYPE triangle\r\n\r\n! Restrict access to the actual procedure names\r\nPRIVATE :: initialize_sub, get_area_fn, get_perimeter_fn\r\nPRIVATE :: to_string_fn\r\n\r\n! Now add methods\r\nCONTAINS\r\n\r\n SUBROUTINE initialize_sub(this,s)\r\n ! \r\n ! Initialize the triangle object.\r\n !\r\n IMPLICIT NONE\r\n \r\n ! Declare calling arguments\r\n CLASS(triangle) :: this ! Triangle object\r\n REAL,INTENT(IN) :: s ! Length of side\r\n \r\n ! Initialize the triangle\r\n this%s = s\r\n\r\n END SUBROUTINE initialize_sub\r\n\r\n\r\n REAL FUNCTION get_area_fn(this)\r\n ! \r\n ! Return the area of this object.\r\n !\r\n IMPLICIT NONE\r\n \r\n ! Declare calling arguments\r\n CLASS(triangle) :: this ! Triangle object\r\n \r\n ! Calculate area\r\n get_area_fn = SQRT(3.0) / 4.0 * this%s**2\r\n\r\n END FUNCTION get_area_fn\r\n\r\n\r\n REAL FUNCTION get_perimeter_fn(this)\r\n ! \r\n ! Return the perimeter of this object.\r\n !\r\n IMPLICIT NONE\r\n \r\n ! Declare calling arguments\r\n CLASS(triangle) :: this ! Triangle object\r\n \r\n ! Calculate perimeter\r\n get_perimeter_fn = 3.0 * this%s\r\n\r\n END FUNCTION get_perimeter_fn\r\n\r\n\r\n CHARACTER(len=50) FUNCTION to_string_fn(this)\r\n ! \r\n ! Return the a character description of this object.\r\n !\r\n IMPLICIT NONE\r\n \r\n ! Declare calling arguments\r\n CLASS(triangle) :: this ! Triangle object\r\n \r\n ! Return description\r\n WRITE (to_string_fn,'(A,F6.2)') 'Equilateral triangle of side ', &\r\n this%s \r\n\r\n END FUNCTION to_string_fn\r\n\r\nEND MODULE triangle_class\r\n", "meta": {"hexsha": "5a4b4f55f194ffa63012f22fbefbd74719265998", "size": 2309, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran952003ForScientistsandEngineers3rdStephenJChapman/chap16/shape/triangle_class.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/chap16/shape/triangle_class.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/chap16/shape/triangle_class.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": 23.5612244898, "max_line_length": 70, "alphanum_fraction": 0.6084885232, "num_tokens": 548, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706735, "lm_q2_score": 0.7905303087996142, "lm_q1q2_score": 0.6535407298549726}} {"text": "!##############################################################################\n! PROGRAM CalcUtil\n!\n! ## Calculate utility of household for different values of c1 and c2\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!##############################################################################\ninclude \"prog01_16m.f90\"\n\nprogram CalcUtil\n\n use Globals\n use UtilFunc\n\n implicit none\n real*8 :: c1, c2, util\n integer :: j\n\n ! initialize parameters\n beta = 0.9d0\n eta = 2d0\n\n ! calculate utility for different consumption pairs\n ! between 0.3 and 0.7\n do j = 0, 20\n c1 = 0.3d0 + (0.7d0-0.3d0)/20*dble(j)\n c2 = 1d0-c1\n util = utility(c1, c2)\n write(*,'(3f10.4)')c1, c2, util\n enddo\n\nend program\n", "meta": {"hexsha": "fe4680f2f7a1ed830c3ba8d66ceebd6b052ba337", "size": 973, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "complete/prog01/prog01_16/prog01_16.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/prog01/prog01_16/prog01_16.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/prog01/prog01_16/prog01_16.f90", "max_forks_repo_name": "aswinvk28/modflow_fortran", "max_forks_repo_head_hexsha": "0c8dd5da8fe08f0abcc6b677503e96cdcdb7ee1e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-04-07T12:27:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-07T12:27:47.000Z", "avg_line_length": 24.325, "max_line_length": 79, "alphanum_fraction": 0.5077081192, "num_tokens": 280, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117855317474, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.6535407292244643}} {"text": "! ------------------------------------------------------------------\n! Programmer(s): David J. Gardner, and Cody J. Balos @ LLNL\n! ------------------------------------------------------------------\n! SUNDIALS Copyright Start\n! Copyright (c) 2002-2021, Lawrence Livermore National Security\n! and Southern Methodist University.\n! All rights reserved.\n!\n! See the top-level LICENSE and NOTICE files for details.\n!\n! SPDX-License-Identifier: BSD-3-Clause\n! SUNDIALS Copyright End\n! ------------------------------------------------------------------\n! The following is a simple example problem with an analytical\n! solution.\n!\n! dy/dt = lamda*y + 1/(1+t^2) - lamda*atan(t)\n!\n! for t in the interval [0.0, 10.0], with initial condition: y=0.\n!\n! The stiffness of the problem is directly proportional to the\n! value of lamda. The value of lamda should be negative to\n! result in a well-posed ODE; for values with magnitude larger\n! than 100 the problem becomes quite stiff.\n! ------------------------------------------------------------------\n\nmodule ode_mod\n\n !======= Inclusions ===========\n use, intrinsic :: iso_c_binding\n\n !======= Declarations =========\n implicit none\n\n ! number of equations\n integer(c_long), parameter :: neq = 1\n\n ! ODE parameters\n double precision, parameter :: lamda = -100.0d0\n\ncontains\n\n ! ----------------------------------------------------------------\n ! RhsFn provides the right hand side function for the\n ! ODE: dy/dt = f(t,y)\n !\n ! Return values:\n ! 0 = success,\n ! 1 = recoverable error,\n ! -1 = non-recoverable error\n ! ----------------------------------------------------------------\n integer(c_int) function RhsFn(tn, sunvec_y, sunvec_f, user_data) &\n result(ierr) bind(C,name='RhsFn')\n\n !======= Inclusions ===========\n use, intrinsic :: iso_c_binding\n use fsundials_nvector_mod\n\n !======= Declarations =========\n implicit none\n\n ! calling variables\n real(c_double), value :: tn ! current time\n type(N_Vector) :: sunvec_y ! solution N_Vector\n type(N_Vector) :: sunvec_f ! rhs N_Vector\n type(c_ptr), value :: user_data ! user-defined data\n\n ! pointers to data in SUNDIALS vectors\n real(c_double), pointer :: yvec(:)\n real(c_double), pointer :: fvec(:)\n\n !======= Internals ============\n\n ! get data arrays from SUNDIALS vectors\n yvec => FN_VGetArrayPointer(sunvec_y)\n fvec => FN_VGetArrayPointer(sunvec_f)\n\n ! fill RHS vector\n fvec(1) = lamda*yvec(1) + 1.0/(1.0+tn*tn) - lamda*atan(tn)\n\n ! return success\n ierr = 0\n return\n\n end function RhsFn\n\nend module ode_mod\n\n\nprogram main\n\n !======= Inclusions ===========\n use, intrinsic :: iso_c_binding\n\n use fcvode_mod ! Fortran interface to CVODE\n use fsundials_context_mod ! Fortran interface to SUNContext\n use fsundials_nvector_mod ! Fortran interface to generic N_Vector\n use fnvector_serial_mod ! Fortran interface to serial N_Vector\n use fsundials_nonlinearsolver_mod ! Fortran interface to generic SUNNonlinearSolver\n use fsunnonlinsol_fixedpoint_mod ! Fortran interface to fixed point SUNNonlinearSolver\n use ode_mod ! ODE functions\n\n !======= Declarations =========\n implicit none\n\n ! local variables\n real(c_double) :: tstart ! initial time\n real(c_double) :: tend ! final time\n real(c_double) :: rtol, atol ! relative and absolute tolerance\n real(c_double) :: dtout ! output time interval\n real(c_double) :: tout ! output time\n real(c_double) :: tcur(1) ! current time\n integer(c_int) :: ierr ! error flag from C functions\n integer(c_int) :: nout ! number of outputs\n integer(c_int) :: outstep ! output loop counter\n type(c_ptr) :: cvode_mem ! CVODE memory\n type(c_ptr) :: ctx ! SUNDIALS simulation context\n\n type(N_Vector), pointer :: sunvec_y ! sundials vector\n type(SUNNonlinearSolver), pointer :: sunnls ! sundials fixed-point nonlinear solver\n\n ! solution vector, neq is set in the ode_mod module\n real(c_double) :: yvec(neq)\n\n !======= Internals ============\n\n ierr = FSUNContext_Create(c_null_ptr, ctx)\n\n ! initialize ODE\n tstart = 0.0d0\n tend = 10.0d0\n tcur = tstart\n tout = tstart\n dtout = 1.0d0\n nout = ceiling(tend/dtout)\n\n ! initialize solution vector\n yvec(1) = 0.0d0\n\n ! create SUNDIALS N_Vector\n sunvec_y => FN_VMake_Serial(neq, yvec, ctx)\n if (.not. associated(sunvec_y)) then\n print *, 'ERROR: sunvec = NULL'\n stop 1\n end if\n\n ! create CVode memory\n cvode_mem = FCVodeCreate(CV_ADAMS, ctx)\n if (.not. c_associated(cvode_mem)) then\n print *, 'ERROR: cvode_mem = NULL'\n stop 1\n end if\n\n ! initialize CVode\n ierr = FCVodeInit(cvode_mem, c_funloc(RhsFn), tstart, sunvec_y)\n if (ierr /= 0) then\n print *, 'Error in FCVodeInit, ierr = ', ierr, '; halting'\n stop 1\n end if\n\n ! set relative and absolute tolerances\n rtol = 1.0d-6\n atol = 1.0d-10\n\n ierr = FCVodeSStolerances(cvode_mem, rtol, atol)\n if (ierr /= 0) then\n print *, 'Error in FCVodeSStolerances, ierr = ', ierr, '; halting'\n stop 1\n end if\n\n ! create fixed point nonlinear solver object\n sunnls => FSUNNonlinSol_FixedPoint(sunvec_y, 0, ctx)\n if (.not. associated(sunnls)) then\n print *,'ERROR: sunnls = NULL'\n stop 1\n end if\n\n ! attache nonlinear solver object to CVode\n ierr = FCVodeSetNonlinearSolver(cvode_mem, sunnls)\n if (ierr /= 0) then\n print *, 'Error in FCVodeSetNonlinearSolver, ierr = ', ierr, '; halting'\n stop 1\n end if\n\n ! Start time stepping\n print *, ' '\n print *, 'Finished initialization, starting time steps'\n print *, ' '\n print *, ' t y '\n print *, '----------------------------'\n print '(2x,2(es12.5,1x))', tcur, yvec(1)\n do outstep = 1,nout\n\n ! call CVode\n tout = min(tout + dtout, tend)\n ierr = FCVode(cvode_mem, tout, sunvec_y, tcur, CV_NORMAL)\n if (ierr /= 0) then\n print *, 'Error in FCVODE, ierr = ', ierr, '; halting'\n stop 1\n endif\n\n ! output current solution\n print '(2x,2(es12.5,1x))', tcur, yvec(1)\n\n enddo\n\n ! diagnostics output\n call CVodeStats(cvode_mem)\n\n ! clean up\n call FCVodeFree(cvode_mem)\n ierr = FSUNNonLinSolFree(sunnls)\n call FN_VDestroy(sunvec_y)\n ierr = FSUNContext_Free(ctx)\n\nend program main\n\n\n! ----------------------------------------------------------------\n! CVodeStats\n!\n! Print CVODE statstics to standard out\n! ----------------------------------------------------------------\nsubroutine CVodeStats(cvode_mem)\n\n !======= Inclusions ===========\n use iso_c_binding\n use fcvode_mod\n\n !======= Declarations =========\n implicit none\n\n type(c_ptr), intent(in) :: cvode_mem ! solver memory structure\n\n integer(c_int) :: ierr ! error flag\n\n integer(c_long) :: nsteps(1) ! num steps\n integer(c_long) :: nfevals(1) ! num function evals\n integer(c_long) :: nlinsetups(1) ! num linear solver setups\n integer(c_long) :: netfails(1) ! num error test fails\n\n integer(c_int) :: qlast(1) ! method order in last step\n integer(c_int) :: qcur(1) ! method order for next step\n\n real(c_double) :: hinused(1) ! initial step size\n real(c_double) :: hlast(1) ! last step size\n real(c_double) :: hcur(1) ! step size for next step\n real(c_double) :: tcur(1) ! internal time reached\n\n integer(c_long) :: nniters(1) ! nonlinear solver iterations\n integer(c_long) :: nncfails(1) ! nonlinear solver fails\n\n !======= Internals ============\n\n ! general solver statistics\n ierr = FCVodeGetIntegratorStats(cvode_mem, nsteps, nfevals, nlinsetups, &\n netfails, qlast, qcur, hinused, hlast, hcur, tcur)\n if (ierr /= 0) then\n print *, 'Error in FCVodeGetIntegratorStats, ierr = ', ierr, '; halting'\n stop 1\n end if\n\n ! nonlinear solver statistics\n ierr = FCVodeGetNonlinSolvStats(cvode_mem, nniters, nncfails)\n if (ierr /= 0) then\n print *, 'Error in FCVodeGetNonlinSolvStats, ierr = ', ierr, '; halting'\n stop 1\n end if\n\n print *, ' '\n print *, ' General Solver Stats:'\n print '(4x,A,i9)' ,'Total internal steps taken =',nsteps\n print '(4x,A,i9)' ,'Total rhs function calls =',nfevals\n print '(4x,A,i9)' ,'Num lin solver setup calls =',nlinsetups\n print '(4x,A,i9)' ,'Num error test failures =',netfails\n print '(4x,A,i9)' ,'Last method order =',qlast\n print '(4x,A,i9)' ,'Next method order =',qcur\n print '(4x,A,es12.5)','First internal step size =',hinused\n print '(4x,A,es12.5)','Last internal step size =',hlast\n print '(4x,A,es12.5)','Next internal step size =',hcur\n print '(4x,A,es12.5)','Current internal time =',tcur\n print '(4x,A,i9)' ,'Num nonlinear solver iters =',nniters\n print '(4x,A,i9)' ,'Num nonlinear solver fails =',nncfails\n print *, ' '\n\n return\n\nend subroutine CVodeStats\n", "meta": {"hexsha": "ea788155c7deabd302c34f821bd9c716cb8e8785", "size": 8925, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/cvode/F2003_serial/cv_analytic_fp_f2003.f90", "max_stars_repo_name": "d5ch4k/sundials", "max_stars_repo_head_hexsha": "c0097c0bfd56e8f94dbb588e0894fdceacf6f737", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 256, "max_stars_repo_stars_event_min_datetime": "2017-10-06T04:11:32.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T07:15:53.000Z", "max_issues_repo_path": "examples/cvode/F2003_serial/cv_analytic_fp_f2003.f90", "max_issues_repo_name": "d5ch4k/sundials", "max_issues_repo_head_hexsha": "c0097c0bfd56e8f94dbb588e0894fdceacf6f737", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 114, "max_issues_repo_issues_event_min_datetime": "2018-03-24T20:38:31.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T16:59:05.000Z", "max_forks_repo_path": "examples/cvode/F2003_serial/cv_analytic_fp_f2003.f90", "max_forks_repo_name": "d5ch4k/sundials", "max_forks_repo_head_hexsha": "c0097c0bfd56e8f94dbb588e0894fdceacf6f737", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 77, "max_forks_repo_forks_event_min_datetime": "2017-11-16T08:32:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-25T15:22:17.000Z", "avg_line_length": 30.8823529412, "max_line_length": 89, "alphanum_fraction": 0.5985434174, "num_tokens": 2589, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117769928211, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.6535407224741842}} {"text": " \n MODULE functions\n IMPLICIT NONE\n\n REAL, PARAMETER :: PI = 4.0 * ATAN(1.0)\n REAL, PARAMETER :: Degree180 = 180.0\n REAL, PARAMETER :: R_to_D = Degree180/PI\n REAL, PARAMETER :: D_to_R = PI/Degree180\n\n\n CONTAINS\n\n REAL FUNCTION RadianToDegree(Radian)\n IMPLICIT NONE\n real, intent(in) :: Radian\n\n RadianToDegree = Radian * R_to_D\n END FUNCTION RadianToDegree\n\n REAL FUNCTION DegreeToRadian(Degree)\n IMPLICIT NONE\n real, intent(in) :: Degree\n\n DegreeToRadian = Degree * D_to_R\n END FUNCTION DegreeToRadian\n\n\n REAL FUNCTION MySIN(x)\n IMPLICIT NONE\n REAL, intent(in) :: x\n\n MySIN = SIN(DegreeToRadian(x))\n END FUNCTION MySIN\n\n REAL FUNCTION MyCOS(x)\n IMPLICIT NONE\n REAL, INTENT(in) :: x\n\n MyCOS = COS(DegreeToRadian(x))\n END FUNCTION MyCOS\n\n END MODULE functions\n\n PROGRAM main\n USE functions ! use a module\n\n IMPLICIT NONE\n \n integer :: n1, n2, i, j, k\n real :: bind_length, total_length, lattice, total_high\n real :: radis, angle, a1, b1, c1, d1\n real :: a2, b2, c2, d2, e2,f2\n real, allocatable :: x(:,:), y(:,:), xatom(:,:,:)\n real, allocatable :: yatom(:,:,:), high(:,:,:)\n real, allocatable :: fxatom(:,:,:), fyatom(:,:,:)\n real, allocatable :: fhigh(:,:,:)\n real :: total_cell\n\n OPEN(1,file='tube.dat')\n \n READ(1,*)\n READ(1,*) n1, n2\n READ(1,*) bind_length\n\n !armchair\n \n if(n2 .NE. 0) THEN\n radis = (6*n1*((bind_length/2)*SQRT(3.0)))/(2*PI)\n lattice = radis + (radis/2)\n total_high = (bind_length/2)*6\n total_cell = lattice*2\n angle = 360.0/n1\n\n if(total_cell .GE. 50) THEN\n total_cell = 49\n endif\n \n\n allocate(x(2,12), y(2,12), xatom(2,12,n1), yatom(2,12,n1))\n allocate(high(2,12,n1))\n\n x(1,1) = radis\n y(1,1) = 0\n \n x(1,2) = radis*MyCOS(360.0/(n1*6)) - 0*MySIN(360.0/(n1*6))\n y(1,2) = radis*MySIN(360.0/(n1*6)) + 0*MySIN(360.0/(n1*6))\n\n x(1,3) = radis*MyCOS((360.0/(n1*6)*3)) - 0*MySIN((360.0/(n1*6))*3)\n y(1,3) = radis*MySIN((360.0/(n1*6)*3)) + 0*MyCOS((360.0/(n1*6))*3)\n\n x(1,4) = radis*MyCOS((360.0/(n1*6)*4)) -0*MySIN((360.0/(n1*6))*4)\n y(1,4) = radis*MySIN((360.0/(n1*6)*4)) +0*MyCOS((360.0/(n1*6))*4)\n\n a1 = radis - 1.56377985\n b1 = radis + 1.56377985\n\n x(2,1) = a1\n y(2,1) = 0\n\n x(2,2) = b1\n y(2,2) = 0\n\n x(2,3) = b1*MyCOS(360.0/(n1*6)) - 0*MySIN(360.0/(n1*6))\n y(2,3) = b1*MySIN(360.0/(n1*6)) + 0*MySIN(360.0/(n1*6))\n\n x(2,4) = a1*MyCOS((360.0/(n1*6))) -0*MySIN((360.0/(n1*6)))\n y(2,4) = a1*MySIN((360.0/(n1*6))) +0*MyCOS((360.0/(n1*6)))\n\n x(2,5) = b1*MyCOS((360.0/(n1*6))*2) -0*MySIN((360.0/(n1*6))*2)\n y(2,5) = b1*MySIN((360.0/(n1*6))*2) +0*MyCOS((360.0/(n1*6))*2)\n\n x(2,6) = a1*MyCOS((360.0/(n1*6))*2) -0*MySIN((360.0/(n1*6))*2)\n y(2,6) = a1*MySIN((360.0/(n1*6))*2) +0*MyCOS((360.0/(n1*6))*2)\n\n x(2,7) = b1*MyCOS((360.0/(n1*6))*3) -0*MySIN((360.0/(n1*6))*3)\n y(2,7) = b1*MySIN((360.0/(n1*6))*3) +0*MyCOS((360.0/(n1*6))*3)\n\n x(2,8) = a1*MyCOS((360.0/(n1*6))*3) -0*MySIN((360.0/(n1*6))*3)\n y(2,8) = a1*MySIN((360.0/(n1*6))*3) +0*MyCOS((360.0/(n1*6))*3)\n\n x(2,9) = a1*MyCOS((360.0/(n1*6))*4) -0*MySIN((360.0/(n1*6))*4)\n y(2,9) = a1*MySIN((360.0/(n1*6))*4) +0*MyCOS((360.0/(n1*6))*4)\n\n x(2,10) = b1*MyCOS((360.0/(n1*6))*4) -0*MySIN((360.0/(n1*6))*4)\n y(2,10) = b1*MySIN((360.0/(n1*6))*4) +0*MyCOS((360.0/(n1*6))*4)\n\n x(2,11) = b1*MyCOS((360.0/(n1*6))*5) -0*MySIN((360.0/(n1*6))*5)\n y(2,11) = b1*MySIN((360.0/(n1*6))*5) +0*MyCOS((360.0/(n1*6))*5)\n\n x(2,12) = a1*MyCOS((360.0/(n1*6))*5) -0*MySIN((360.0/(n1*6))*5)\n y(2,12) = a1*MySIN((360.0/(n1*6))*5) +0*MyCOS((360.0/(n1*6))*5)\n \n\n do i = 1,4\n xatom(1,i,1) = x(1,i)\n yatom(1,i,1) = y(1,i)\n enddo\n \n do i = 1, 12\n xatom(2,i,1) = x(2,i)\n yatom(2,i,1) = y(2,i)\n enddo\n\n do j = 1, 4\n do i = 2, n1\n xatom(1,j,i) = MyCOS(angle)*xatom(1,j,i-1)&\n - MySIN(angle)*yatom(1,j,i-1)\n yatom(1,j,i) = xatom(1,j,i-1)*MySIN(angle)&\n + yatom(1,j,i-1)*MyCOS(angle)\n\n enddo\n enddo\n\n do j = 1, 12\n do i = 2, n1\n xatom(2,j,i) = MyCOS(angle)*xatom(2,j,i-1)&\n - MySIN(angle)*yatom(2,j,i-1)\n yatom(2,j,i) = xatom(2,j,i-1)*MySIN(angle)&\n + yatom(2,j,i-1)*MyCOS(angle)\n\n\n\n enddo\n enddo\n\n\n do i = 1, n1\n\n high(1,1,i) = 4*(bind_length/2)\n high(1,2,i) = bind_length/2\n high(1,3,i) = bind_length/2\n high(1,4,i) = 4*(bind_length/2)\n\n enddo\n\n do i = 1, n1\n \n high(2,1,i) = 2*(bind_length/2)\n high(2,2,i) = 6*(bind_length/2)\n high(2,3,i) = 3*(bind_length/2)\n high(2,4,i) = 5*(bind_length/2)\n high(2,5,i) = 0\n high(2,6,i) = 2*(bind_length/2)\n high(2,7,i) = 3*(bind_length/2)\n high(2,8,i) = 5*(bind_length/2)\n high(2,9,i) = 2*(bind_length/2)\n high(2,10,i) = 6*( bind_length/2)\n high(2,11,i) = 3*(bind_length/2)\n high(2,12,i) = 5*(bind_length/2)\n\n enddo\n\n allocate(fxatom(2,12,n1), fyatom(2,12,n1),fhigh(2,12,n1))\n\n \n do j = 1, 4\n do k = 1, n1\n\n fxatom(1,j,k) = (xatom(1,j,k)+lattice)/total_cell\n fyatom(1,j,k) = (yatom(1,j,k)+lattice)/total_cell\n\n fhigh(1,j,k) = high(1,j,k)/total_high\n\n enddo\n enddo\n \n do j = 1, 12\n do k = 1, n1\n\n fxatom(2,j,k) = (xatom(2,j,k)+lattice)/total_cell\n fyatom(2,j,k) = (yatom(2,j,k)+lattice)/total_cell\n\n fhigh(2,j,k) = high(2,j,k)/total_high\n\n enddo\n enddo\n\n\n open(24,file='tube.out')\n 100 format(f20.16,3x,f20.16,3x,f20.16)\n\n write(24,*) total_cell, total_high, 'atom1= ', n1*4, 'atom2 =',n1*12\n\n do j = 1, 4\n do k = 1, n1\n\n write(24,100) fxatom(1,j,k), fyatom(1,j,k), fhigh(1,j,k)\n enddo\n enddo\n\n do j = 1, 12\n do k = 1, n1\n\n write(24,100) fxatom(2,j,k), fyatom(2,j,k), fhigh(2,j,k)\n enddo\n enddo\n\n endif\n\n !zig zag\n\n if(n2 .EQ. 0) THEN\n radis = (bind_length*3*(n1-1))/(2*PI)\n lattice = radis + (radis/2)*3\n total_high = ((bind_length/2)*SQRT(3.0))*6\n total_cell = lattice*2\n angle = 360.0/n1\n\n if(total_cell .GE. 50) THEN\n total_cell = 49\n endif \n \n allocate(x(2,12), y(2,12), xatom(2,12,n1), yatom(2,12,n1))\n allocate(high(2,12,n1))\n\n x(1,1) = radis\n y(1,1) = 0\n \n x(1,2) = radis\n y(1,2) = 0\n\n x(1,3) = radis*MyCOS((360.0/(n1*6)*3)) - 0*MySIN((360.0/(n1*6))*3)\n y(1,3) = radis*MySIN((360.0/(n1*6)*3)) + 0*MyCOS((360.0/(n1*6))*3)\n\n x(1,4) = radis*MyCOS((360.0/(n1*6)*3)) - 0*MySIN((360.0/(n1*6))*3)\n y(1,4) = radis*MySIN((360.0/(n1*6)*3)) + 0*MyCOS((360.0/(n1*6))*3)\n\n a1 = radis - 1.56377985\n b1 = radis + 1.56401799\n\n x(2,1) = a1*MyCOS((360.0/(n1*6)*1))&\n -0*MySIN((360.0/(n1*6))*1)\n y(2,1) = a1*MySIN((360.0/(n1*6)*1))&\n +0*MyCOS((360.0/(n1*6))*1)\n\n x(2,2) = a1*MyCOS((360.0/(n1*6)*1))&\n -0*MySIN((360.0/(n1*6))*1)\n y(2,2) = a1*MySIN((360.0/(n1*6)*1))&\n +0*MyCOS((360.0/(n1*6))*1)\n\n x(2,3) = a1*MyCOS((360.0/(n1*6)*1))&\n -0*MySIN((360.0/(n1*6))*1)\n y(2,3) = a1*MySIN((360.0/(n1*6)*1))&\n +0*MyCOS((360.0/(n1*6))*1)\n\n x(2,4) = b1*MyCOS((360.0/(n1*6)*2))&\n -0*MySIN((360.0/(n1*6))*2)\n y(2,4) = b1*MySIN((360.0/(n1*6)*2))&\n +0*MyCOS((360.0/(n1*6))*2)\n \n x(2,5) = b1*MyCOS((360.0/(n1*6)*2))&\n -0*MySIN((360.0/(n1*6))*2)\n y(2,5) = b1*MySIN((360.0/(n1*6)*2))&\n +0*MyCOS((360.0/(n1*6))*2)\n\n x(2,6) = b1*MyCOS((360.0/(n1*6)*2))&\n -0*MySIN((360.0/(n1*6))*2)\n y(2,6) = b1*MySIN((360.0/(n1*6)*2))&\n +0*MyCOS((360.0/(n1*6))*2)\n\n x(2,7) = a1*MyCOS((360.0/(n1*6)*4))&\n -0*MySIN((360.0/(n1*6))*4)\n y(2,7) = a1*MySIN((360.0/(n1*6)*4))&\n +0*MyCOS((360.0/(n1*6))*4)\n\n x(2,8) = a1*MyCOS((360.0/(n1*6)*4))&\n -0*MySIN((360.0/(n1*6))*4)\n y(2,8) = a1*MySIN((360.0/(n1*6)*4))&\n +0*MyCOS((360.0/(n1*6))*4)\n\n x(2,9) = a1*MyCOS((360.0/(n1*6)*4))&\n -0*MySIN((360.0/(n1*6))*4)\n y(2,9) = a1*MySIN((360.0/(n1*6)*4))&\n +0*MyCOS((360.0/(n1*6))*4)\n\n x(2,10) = b1*MyCOS((360.0/(n1*6)*5))&\n -0*MySIN((360.0/(n1*6))*5)\n y(2,10) = b1*MySIN((360.0/(n1*6)*5))&\n +0*MyCOS((360.0/(n1*6))*5)\n\n x(2,11) = b1*MyCOS((360.0/(n1*6)*5))&\n -0*MySIN((360.0/(n1*6))*5)\n y(2,11) = b1*MySIN((360.0/(n1*6)*5))&\n +0*MyCOS((360.0/(n1*6))*5)\n\n x(2,12) = b1*MyCOS((360.0/(n1*6)*5))&\n -0*MySIN((360.0/(n1*6))*5)\n y(2,12) = b1*MySIN((360.0/(n1*6)*5))&\n +0*MyCOS((360.0/(n1*6))*5)\n\n do i = 1,4\n xatom(1,i,1) = x(1,i)\n yatom(1,i,1) = y(1,i)\n enddo\n\n do i = 1, 12\n xatom(2,i,1) = x(2,i)\n yatom(2,i,1) = y(2,i)\n enddo\n\n do j = 1, 4\n do i = 2, n1\n xatom(1,j,i) = MyCOS(angle)*xatom(1,j,i-1)&\n - MySIN(angle)*yatom(1,j,i-1)\n yatom(1,j,i) = xatom(1,j,i-1)*MySIN(angle)&\n + yatom(1,j,i-1)*MyCOS(angle)\n\n enddo\n enddo\n\n do j = 1, 12\n do i = 2, n1\n xatom(2,j,i) = MyCOS(angle)*xatom(2,j,i-1)&\n - MySIN(angle)*yatom(2,j,i-1)\n yatom(2,j,i) = xatom(2,j,i-1)*MySIN(angle)&\n + yatom(2,j,i-1)*MyCOS(angle)\n\n\n\n enddo\n enddo\n\n c1 = (bind_length/2)*SQRT(3.0)\n\n do i = 1, n1\n\n high(1,1,i) = c1\n high(1,2,i) = c1*3\n high(1,3,i) = 0\n high(1,4,i) = c1*4\n\n enddo\n\n do i = 1, n1\n\n high(2,1,i) = 0\n high(2,2,i) = c1*2\n high(2,3,i) = c1*4\n high(2,4,i) = c1\n high(2,5,i) = c1*3\n high(2,6,i) = c1*5\n high(2,7,i) = c1\n high(2,8,i) = c1*3\n high(2,9,i) = c1*5\n high(2,10,i) = 0\n high(2,11,i) = c1*2\n high(2,12,i) = c1*4\n\n enddo\n\n allocate(fxatom(2,12,n1), fyatom(2,12,n1),fhigh(2,12,n1))\n\n\n do j = 1, 4\n do k = 1, n1\n\n fxatom(1,j,k) = (xatom(1,j,k)+lattice)/total_cell\n fyatom(1,j,k) = (yatom(1,j,k)+lattice)/total_cell\n\n fhigh(1,j,k) = high(1,j,k)/total_high\n\n enddo\n enddo\n\n do j = 1, 12\n do k = 1, n1\n\n fxatom(2,j,k) = (xatom(2,j,k)+lattice)/total_cell\n fyatom(2,j,k) = (yatom(2,j,k)+lattice)/total_cell\n\n fhigh(2,j,k) = high(2,j,k)/total_high\n\n enddo\n enddo\n\n\n open(24,file='tube.out')\n\n write(24,*) total_cell, total_high, 'atom1= ', n1*4, 'atom2=',n1*12\n\n do j = 1, 4\n do k = 1, n1\n\n write(24,100) fxatom(1,j,k), fyatom(1,j,k), fhigh(1,j,k)\n enddo\n enddo\n\n do j = 1, 12\n do k = 1, n1\n\n write(24,100) fxatom(2,j,k), fyatom(2,j,k), fhigh(2,j,k)\n enddo\n enddo\n\n endif\n\n\n\n\n END PROGRAM main\n", "meta": {"hexsha": "1bff18d6fc3aab9cc46a4050c5accaf47bdc955e", "size": 12388, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Park_tube_CrI3.f90", "max_stars_repo_name": "pyungjinpark/Vasp_code", "max_stars_repo_head_hexsha": "75ce9bf10fa851b4d5c879138a4642ce518b77e2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Park_tube_CrI3.f90", "max_issues_repo_name": "pyungjinpark/Vasp_code", "max_issues_repo_head_hexsha": "75ce9bf10fa851b4d5c879138a4642ce518b77e2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Park_tube_CrI3.f90", "max_forks_repo_name": "pyungjinpark/Vasp_code", "max_forks_repo_head_hexsha": "75ce9bf10fa851b4d5c879138a4642ce518b77e2", "max_forks_repo_licenses": ["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.0907029478, "max_line_length": 76, "alphanum_fraction": 0.4189538263, "num_tokens": 5257, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248174286374, "lm_q2_score": 0.6959583250334526, "lm_q1q2_score": 0.6535221391024781}} {"text": " FUNCTION bessi0(x)\r\n REAL bessi0,x\r\n REAL ax\r\n DOUBLE PRECISION p1,p2,p3,p4,p5,p6,p7,q1,q2,q3,q4,q5,q6,q7,q8,q9,y\r\n SAVE p1,p2,p3,p4,p5,p6,p7,q1,q2,q3,q4,q5,q6,q7,q8,q9\r\n DATA p1,p2,p3,p4,p5,p6,p7/1.0d0,3.5156229d0,3.0899424d0,\r\n *1.2067492d0,0.2659732d0,0.360768d-1,0.45813d-2/\r\n DATA q1,q2,q3,q4,q5,q6,q7,q8,q9/0.39894228d0,0.1328592d-1,\r\n *0.225319d-2,-0.157565d-2,0.916281d-2,-0.2057706d-1,0.2635537d-1,\r\n *-0.1647633d-1,0.392377d-2/\r\n if (abs(x).lt.3.75) then\r\n y=(x/3.75)**2\r\n bessi0=p1+y*(p2+y*(p3+y*(p4+y*(p5+y*(p6+y*p7)))))\r\n else\r\n ax=abs(x)\r\n y=3.75/ax\r\n bessi0=(exp(ax)/sqrt(ax))*(q1+y*(q2+y*(q3+y*(q4+y*(q5+y*(q6+y*\r\n *(q7+y*(q8+y*q9))))))))\r\n endif\r\n return\r\n END\r\n", "meta": {"hexsha": "38cf3195dd5131d26ae1b203b034fc2b293676e3", "size": 791, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/bessi0.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/bessi0.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/bessi0.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": 35.9545454545, "max_line_length": 73, "alphanum_fraction": 0.5360303413, "num_tokens": 402, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248225478307, "lm_q2_score": 0.6959583124210896, "lm_q1q2_score": 0.6535221308219014}} {"text": " FUNCTION bessk0(x)\r\n REAL bessk0,x\r\nCU USES bessi0\r\n REAL bessi0\r\n DOUBLE PRECISION p1,p2,p3,p4,p5,p6,p7,q1,q2,q3,q4,q5,q6,q7,y\r\n SAVE p1,p2,p3,p4,p5,p6,p7,q1,q2,q3,q4,q5,q6,q7\r\n DATA p1,p2,p3,p4,p5,p6,p7/-0.57721566d0,0.42278420d0,0.23069756d0,\r\n *0.3488590d-1,0.262698d-2,0.10750d-3,0.74d-5/\r\n DATA q1,q2,q3,q4,q5,q6,q7/1.25331414d0,-0.7832358d-1,0.2189568d-1,\r\n *-0.1062446d-1,0.587872d-2,-0.251540d-2,0.53208d-3/\r\n if (x.le.2.0) then\r\n y=x*x/4.0\r\n bessk0=(-log(x/2.0)*bessi0(x))+(p1+y*(p2+y*(p3+y*(p4+y*(p5+y*\r\n *(p6+y*p7))))))\r\n else\r\n y=(2.0/x)\r\n bessk0=(exp(-x)/sqrt(x))*(q1+y*(q2+y*(q3+y*(q4+y*(q5+y*(q6+y*\r\n *q7))))))\r\n endif\r\n return\r\n END\r\n", "meta": {"hexsha": "2a5bf9f2ee6dd9e6747ab6dfdaabf4ec6d8d8d65", "size": 759, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/bessk0.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/bessk0.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/bessk0.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": 34.5, "max_line_length": 73, "alphanum_fraction": 0.5322793149, "num_tokens": 384, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248225478306, "lm_q2_score": 0.6959583124210896, "lm_q1q2_score": 0.6535221308219014}} {"text": "! An f77 subroutine to convolute a stick spectrum with a derivative\n! gaussian line shape using fftpack5 routines\n subroutine convolute(spec,n,lw,sw)\n implicit none\n !Argument variables\n real spec(10000),lw,sw\n integer n\n\n !Local variables\n real wsave(33000),work(65536),r, pi\n complex scr1(32768),myi\n integer lensave,ierr,lenspec,lenwork,i,kb\n external cfft1i\n external cfft1f\n external cfft1b\n\n pi=3.14159265359\n kb = 1024\n myi = cmplx(0,1)\n lensave = 33000\n lenwork = 655536\n\n! zero fill the spectrum to the next nearest power of 2\n do i = 1,5\n if(kb .gt. n) goto 10\n kb = kb * 2\n end do\n 10 lenspec = kb\n do i=1,n\n scr1(i+(kb-n)/2) = cmplx(spec(i),0)\n end do\n\n! Set up and perform the fft\n call cfft1i(kb,wsave,lensave,ierr)\n call cfft1f(kb,1,scr1,lenspec,wsave,lensave,work,lenwork,ierr)\n\n! Multiply the FT by the convolution function\n r = 0.\n do i = 1, kb\n scr1(i) = scr1(i)*exp(-.5*(pi*lw*r/sw)**2) ! FT of a gaussian\n scr1(i) = scr1(i)*2.*pi*r*myi/n ! time domain first derivative\n r = r + 1.\n end do\n\n! Perform the reverse FFT\n call cfft1b(kb,1,scr1,lenspec,wsave,lensave,work,lenwork,ierr)\n do i = 1,n\n spec(i) = n*real(scr1(i+(kb-n)/2))\n end do\n end subroutine convolute\n", "meta": {"hexsha": "a97026bb085c6e4a6250b9c11f3a6aedfaab8a97", "size": 1384, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/convolute_fftpack.f", "max_stars_repo_name": "rpepr/rpEPR", "max_stars_repo_head_hexsha": "5108106153dc17b53b304ae1eba3a748a70732ad", "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": "source/convolute_fftpack.f", "max_issues_repo_name": "rpepr/rpEPR", "max_issues_repo_head_hexsha": "5108106153dc17b53b304ae1eba3a748a70732ad", "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": "source/convolute_fftpack.f", "max_forks_repo_name": "rpepr/rpEPR", "max_forks_repo_head_hexsha": "5108106153dc17b53b304ae1eba3a748a70732ad", "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.137254902, "max_line_length": 70, "alphanum_fraction": 0.600433526, "num_tokens": 469, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.727975460709318, "lm_q1q2_score": 0.6535001438484317}} {"text": "subroutine CORRELS_NEW_STEP_DEF(corrs,metricG,n,centres)\n implicit none\n type(CorrelsRec),intent(inout) :: corrs\n integer,intent(in) :: n\n real(8),intent(in),dimension(3,3) :: metricG\n type(Particule),intent(in) :: centres(*)\n\n integer :: i,j,k,indexg,ng,nr\n real(8) :: r2,prepos(3),relpos(3),rmin,dr, dri\n\n nr=corrs%nr\n ng=corrs%ng\n rmin=corrs%rmin\n dr = corrs%dr\n dri = 1.d0/dr\n\n !$omp parallel do default(shared) private(i,j,prepos, relpos, indexg)\n do i=1,n\n do j=i+1,n\n prepos=centres(i)%pos-centres(j)%pos\n r2=sqrt(DIST2_MI(prepos,relpos,metricG))\n \n k=Indic_(centres(i)%famille,centres(j)%famille,nr)\n indexg=1+floor((r2-rmin)*dri)\n if(indexg>0.and.indexg<=ng) then\n !$omp atomic update\n corrs%nder(indexg,k)=corrs%nder(indexg,k)+2\n endif\n end do\n end do\n !$omp end parallel do\n corrs%step_calc=corrs%step_calc+1\n\nend subroutine\n\n", "meta": {"hexsha": "863d5b47a28b90f5b97d0149df10cc7e3918f5e4", "size": 929, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/analysis/correls_default.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/correls_default.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/correls_default.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": 25.8055555556, "max_line_length": 71, "alphanum_fraction": 0.6404736276, "num_tokens": 344, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813454, "lm_q2_score": 0.7279754489059775, "lm_q1q2_score": 0.653500137237565}} {"text": " subroutine DSFITC(CCODE, XI, YI, SD, KORDER, NCOEF, TKNOTS,\n * BCOEF, RNORM, ISET, INFO, WORK)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc>> 1996-03-30 DSFITC Krogh Added external statement.\nc>> 1996-01-23 DSGITC Krogh Changes to simplify conversion to C.\nc>> 1995-11-21 DSFITC Krogh Converted from SFTRAN to Fortran 77.\nc>> 1994-11-16 CLL Add loops to zero debug arrays XT() and RT().\nc>> 1994-10-19 DSFITC Krogh Changes to use M77CON\nc>> 1994-01-31 DSFITC CLL Added test for SD(i) .le. 0 when SD(1) > 0.\nc>> 1992-12-16 CLL Corrected formula for NEED2 and comments re WORK().\nc>> 1992-11-12 C. L. Lawson, JPL Initializing LEFT, J1, J2.\nc>> 1992-10-27 C. L. Lawson, JPL\nc>> 1989-03-02 C. L. Lawson, JPL\nc>> 1989-02-23 C. L. Lawson, JPL\nc>> 1988-04-01 C. L. Lawson, JPL\nc\nc Weighted least squares fit to discrete data by a polynomial\nc spline function of order KORDER. The user can specify equality or\nc inequality constraints. The fitting equations as well as the\nc constraints may involve the value, a derivative of specified\nc order, or a definite integral of the spline function. A fitting\nc equation or constraint may involve function or derivative values\nc at different points, and relations between derivatives of\nc different orders.\nc\nc The order of a polynomial spline function is one\nc greater than the degree of its polynomial pieces.\nc Example: KORDER = 4 specifies a cubic spline function.\nc\nc The \"proper fitting interval\" is from A = TKNOTS(KORDER) to\nc B = TKNOTS(NT+1-KORDER). Extrapolation outside this interval\nc is permitted, but one must expect diminished accuracy at\nc extrapolated points. The given data or constraint\nc abcissas may be outside [A, B], and subsequent evaluations can be\nc done at points X outside [A, B].\nc ------------------------------------------------------------------\nc Specification of fitting and constraint equations.\nc\nc Let F denote the polynomial spline to be determined. Let the\nc quadruple (CCODE(i), X(i), Y(i), SD(i)) be called the ith\nc specification row. For each desired fitting equation or\nc constraint equation, (either of which we call a relation) the user\nc must specify one or two (consecutive) specification rows.\nc\nc CCODE(i) consists of 4 characters, that we call\nc KIND, DERIV, RELOP, and ACTIVE.\nc\nc KIND may be '1', '2', '3', or '4'. KIND determines the kind of\nc relation being specified. When KIND = '1' or '2' all\nc information for the relation is given in a single specification\nc row. We call this Row i in the following discussion.\nc When KIND = '3' or '4', two consecutive specification rows are use\nc We call these Rows i and i+1. We will complete the explanation of\nc KIND after describing DERIV, RELOP, and ACTIVE.\nc\nc DERIV may be '0', '1', ..., or '9'. This selects the order of\nc derivative of F to appear in the relation. '0' denotes the value\nc of F itself.\nc\nc RELOP may be '~', '=', '<', or '>'.\nc RELOP = '~' means the relation is to be a least-squares fitting\nc equation, '=' means an equality constraint equation, '<' means a\nc less-than-or-equal constraint equation, and '>' means a\nc greater-than-or-equal constraint equation. When RELOP = '~',\nc SD(i) specifies the a priori standard deviation of the right-side\nc member of the equation. When RELOP indicates a constraint\nc equation, SD(i) will be ignored.\nc\nc ACTIVE may be 'A', 'N', or '!'. Lower case 'a' and 'n' are\nc also accepted. ACTIVE = 'A' means the current specification row\nc is active, i.e., a relation will be generated from these\nc specifications. ACTIVE = 'N' means the specifications are not\nc active, i.e., no relation will be generated. ACTIVE = '!' means\nc the current row is inactive and there are no following rows,\nc i.e., this marks the end of the specification data. The user must\nc provide this termination signal.\nc When KIND = '3', or '4', meaning two specification rows are to\nc be interpreted together, the setting of ACTIVE = 'A' or\nc ACTIVE = 'N' must be consistent in these two rows.\nc Setting ACTIVE = '!' in only the first row is permitted, however,\nc since then the second row will not be accessed anyway.\nc\nc The forms of the relations selected by KIND are:\nc\nc KIND = 1: G(X(i)) RELOP Y(i)\nc\nc where G is the derivative of F selected by DERIV.\nc\nc KIND = 2: G(X(i)) - G(Y(i)) RELOP 0\nc\nc where G is the derivative of F selected by DERIV.\nc\nc KIND = 3: G(X(i)) - Y(i+1) * H(X(i+1)) RELOP Y(i)\nc\nc where G is the derivative of F selected by DERIV(i) and\nc and H is the derivative of F selected by DERIV(i+1). In this\nc case KIND(i+1) and RELOP(i+1) are not used.\nc\nc KIND = 4: Integral from X(i) to X(i+1) of F RELOP Y(i)\nc\nc In this case DERIV(i), KIND(i+1), DERIV(i+1), RELOP(i+1), and\nc Y(i+1) are not used.\nc ------------------------------------------------------------------\nC The linear algebra methods were designed by C.L.Lawson and\nc R.J.Hanson. The method of representing spline functions is due\nc to Carl de Boor. References:\nC \"SOLVING LEAST SQUARES PROBLEMS\", by Lawson and Hanson,\nC Prentice-Hall, 1974.\nc \"A PRACTICAL GUIDE TO SPLINES\" by Carl de Boor,\nc Springer-Verlag, 1978.\nc The functionality and user interface of this subprogram are\nc modeled on the \"French Curve\" subroutine, FC, developed by Hanson\nc and Lawson at JPL in 1970, and the subsequent version developed by\nc Hanson at Sandia in 1979.\nc March 1988, CLL, JPL. Revised to conform to the Fortran 77\nc standard. Intended for inclusion in the JPL MATH77 math library.\nc Feb 1989, CLL, JPL. Revised to use KIND = 3 to specify an\nc integral, and added new kind of relation using KIND = 4.\nc ------------------------------------------------------------------\nc SUBROUTINE ARGUMENTS\nc\nc CCODE() [in, char*4] CCODE(i) is regarded as consisting of four\nc single-character fields.\nc CCODE(i)(1:1) = KIND = '1', '2', '3', '4'.\nc CCODE(i)(2:2) = DERIV = '0', '1', ..., '9'.\nc CCODE(i)(3:3) = RELOP = '~', '=', '<', '>'.\nc CCODE(i)(4:4) = ACTIVE = 'A', 'N', '!'\nc Where alphabetic characters are shown, the corresponding\nc lower case character is also acceptable.\nc\nc X() [in] Abcissas for specification of fitting or\nc constraint equations.\nc\nc Y() [in] Values or abcissas for specification\nc of fitting or constraint equations.\nc\nc SD() [in] Specifies the a priori standard deviation of error in the\nc right-side value in each fitting equation.\nc The weighted fitting algorithm will take account of these.\nc Optionally, the user may set SD(1) to a negative value.\nc Then this subr will use abs(SD(1)) as the standard deviation\nc for the right-side value in each fitting equation. In this\nc latter case the SD() array can be dimensioned SD(1).\nc Note that a negative value in SD(1) will always be interpreted\nc in this way by this subr, even if the associated RELOP is not\nc '~' or if ACTIVE is not 'A'.\nc\nc KORDER [in] Order of the spline basis functions. The\nc polynomial degree of the spline segments is one less than the\nc order. Example: the order of a cubic spline is 4.\nc Require KORDER .ge. 1. Internal arrays in subroutines used put\nc an upper limit of 20 on KORDER.\nc\nc NCOEF [in] No. of B-spline coefficients to be determined.\nc\nc (TKNOTS(j),j=1,NT, where NT = NCOEF+KORDER) [in] This is the deBoor\nc knot sequence for definition of the spline basis functions.\nc These values must be nondecreasing.\nc Repeated values are permitted, but values at\nc an index spacing of KORDER must be strictly increasing.\nc The first and last KORDER-1 values in TKNOTS() are needed to\nc support the deBoor method of representing splines.\nc The \"proper fitting interval\" is from\nc A = TKNOTS(KORDER) to B = TKNOTS(NT+1-KORDER). One acceptable and\nc convenient way to set the first and last KORDER-1 knots is to set\nc the first KORDER-1 to A and the last KORDER-1 to B.\nc Continuity of the spline at knots interior to (A, B) will be of\nc order KORDER-2, unless a knot is repeated, in which case the order\nc of continuity will be decreased at that knot.\nc\nc BCOEF() [out] An array of length NCOEF into which the computed\nc coefficients defining the fitted curve will be stored. These\nc are coeffients relative to B-spline basis functions.\nc For I = 1, ..., NCOEF, the coefficient BCOEF(I)\nc is associated with the basis function whose support interval\nc runs from TKNOTS(I) to TKNOTS(I+KORDER).\nc\nc RNORM [out] RNORM := sqrt( sum over the indices i for which\nc fitting was requested of [( (yfit(i) - Y(i))/SD(i))**2])\nc\nc ISET() [in integer] Array of length 3.\nc ISET(1) = NINFO, the dimension of INFO(). A sufficiently\nc large value for NINFO is 7 + 2*(NCOEF + NS).\nc ISET(2) = NWORK, the dimension of WORK(). A sufficiently\nc large value for NWORK can be computed as follows:\nc See definition of NS, M1, and MFIT below under INFO().\nc NTOT = NCOEF + NS\nc MTOT = M1 + MFIT\nc MINMN = min(MTOT, NTOT)\nc NWORK = MTOT*NTOT + 3*MTOT + 6*NTOT + 3*MINMN + M1\nc ISET(3) = KPRINT, a print flag in the range [0, 4]. It is\nc passed on to DBLSE. Larger values produce more printing.\nc\nc INFO() [out and scratch integer] The first 7 elements of INFO()\nc are used to return information about the problem. The\nc following 2*(NCOEF+NS) locations are used as scratch.\nc INFO(1) = IERR5, the Error status indicator.\nc Note that IERR4 comes from DBLSE. Possible values of IERR5 are\nc as follows:\nc\nc = 0 means no errors detected.\nc = 100 means NCOEF .lt. 1\nc = 200 means TKNOTS(I) .gt. TKNOTS(I+1)\nc = 250 means TKNOTS(I) .ge. TKNOTS(I+KORDER)\nc = 300 means NINFO or NWORK is too small.\nc = 500 means DERIV has bad value.\nc = 600 means RELOP has bad value.\nc = 700 means KIND has bad value.\nc = 800 means ACTIVE has bad value.\nc = 1000 + IERR4 means IERR4 .ne. 0 due to error\nc detected in _BLSE.\nc = 1100 means SD(1) = zero.\nc = 1200 means SD(1) > zero and SD(i) .le. zero for some i.\nc\nc INFO(2) = NEED1, the dimension needed for INFO().\nc INFO(3) = NEED2, the dimension needed for WORK().\nc INFO(4) = M1, the number of constraints rows in the matrix\nc representation of the problem. This will be a count of\nc the number of nonignored instances of CCODE(i) having\nc RELOP = '=', '<', or '>, and ACTIVE = 'A'.\nc INFO(5) = MFIT, the number of least-squares equations.\nc This will be a count of\nc the number of nonignored instances of CCODE(i) having\nc RELOP = '~' and ACTIVE = 'A'.\nc INFO(6) = NS, the number of slack variables. This will be a\nc count of the number of nonignored instances of CCODE(i)\nc having RELOP = '<' or '>, and ACTIVE = 'A'.\nc INFO(7) = NSETP, the number of variables in Set P at\nc termination. These variables are at values determined by\nc solution of a system of equations. The other NCOEF + NS\nc - NSETP variables will be at fixed values, either at one of\nc their bounds or at zero.\nc\nc WORK() [scratch] Work space dimensioned NWORK.\nc ------------------------------------------------------------------\nc Important internal variables.\nc\nc BASIS() Array in which values of KORDER basis functions or their\nc will be stored. Dimensioned using the parameter KMAX.\nc This puts an upper limit on permissible KORDER.\nc JCOL Column of matrix into which first element of current\nc set of basis function values will be placed.\nc JCOL = LEFT - KORDER + 1.\nc KINFO Parameter specifying the number of locations at the\nc beginning of INFO() used for specific items of returned\nc information. Space beyond these locations is used for\nc scratch.\nc KMAX Intermal dimensioning parameter. The input value of KORDER\nc must not exceed KMAX.\nc KORDP1 = KORDER+1\nC KSIZE Number of rows in current block.\nc LEFT Index of current spline segment. LEFT will satisfy\nc KORDER .le. LEFT .le. NCOEF.\nc The knot interval associated with index LEFT is from\nc T(LEFT) to T(LEFT+1).\nc Note that the union of these\nc segments is the \"proper fitting interval\".\nc ELIMIT Limit on number of errors in initial scan of specs before\nc quitting.\nc ------------------------------------------------------------------\nc--D replaces \"?\": ?SFITC, ?BLSE, ?SBASI, ?SBASD, ?SFIND, ?ERV1\nc Both versions use ERMOR, ERMSG, IERM1, IERV1\nc ------------------------------------------------------------------\n external D1MACH\n integer ELIMIT, KINFO\n parameter(ELIMIT = 9, KINFO = 7)\n integer ACTIVE, DERIV, FAC\n integer I, IC, IERR4, IERR5\n integer INFO(*), IRCON, IRLS, IROW, ISET(3)\n integer IWBND, IWBVEC, IWCC, IWDIFF, IWINDX, IWJSTA\n integer IWRT, IWSIZ, IWSS, IWTNRM, IWWRK, IWXS, IWXT, IWZ\n integer J, J1, J2, JCOL, JS, KMAX, KORDER, KPRINT, LEFT\n integer M1, MFIT, MINMN, MN, MODE, MTOT\n integer NBADCC, NCOEF, NEED1, NEED2, NINFO, NTOT\n integer NS, NSETP, NT, NWORK, RELOP, KIND\n parameter(KMAX=20)\n double precision D1MACH\n double precision BASIS(KMAX), BCOEF(NCOEF), ONE\n double precision RNORM, RTVAL, SD(*), SDIC\n double precision TKNOTS(NCOEF+KORDER), TOL, UNBND\n double precision WORK(*), WT, WT1\n double precision X, XI(*), YI(*), ZERO\n character ATAB*6, CCODE(*)*4, DTAB*10\n character RTAB*4, NVTAB*4\n character MSG1*19, MSG3*19, MSG4*19\n logical USEWT1\n parameter( ONE = 1.0D0, UNBND = 99.0D0, ZERO = 0.0D0)\n parameter(DTAB='0123456789', RTAB='~=<>')\n parameter(NVTAB='1234', ATAB=' AaNn!')\n data MSG1 / 'CCODE(I)(1:1) = ' /\n data MSG3 / 'CCODE(I)(3:3) = ' /\n data MSG4 / 'CCODE(I)(4:4) = ' /\nc ------------------------------------------------------------------\n NINFO = ISET(1)\n NWORK = ISET(2)\n KPRINT = ISET(3)\n NT = NCOEF + KORDER\n IERR5 = 0\nC\nC Exit immediately if NCOEF .lt. 1 or if\nC the knots fail to be nondecreasing.\nc\n if ( NCOEF .lt. 1 ) then\n IERR5 = 100\n call IERM1('DSFITC',IERR5,0,\n * 'Require NCOEF .ge. 1', 'NCOEF',NCOEF,'.')\n go to 500\n end if\n if(KORDER .gt. KMAX) then\n IERR5 = 150\n call IERM1('DSFITC',IERR5,0,'Require KORDER .le. KMAX.',\n * 'KORDER',KORDER,',')\n call IERV1('KMAX',KMAX,'.')\n go to 500\n end if\nc\n do 20 I = 1,NT-1\n if (TKNOTS(I) .gt. TKNOTS(I+1)) then\n IERR5 = 200\n call IERM1('DSFITC',IERR5,0,\n * 'Require knots, TKNOTS(I), to be nondecreasing.',\n * 'I',I,',')\n call DERV1('TKNOTS(I)',TKNOTS(I),',')\n call DERV1('TKNOTS(I+1)',TKNOTS(I+1),'.')\n go to 500\n end if\n 20 continue\nc\n do 40 I = 1,NCOEF\n if (TKNOTS(I) .ge. TKNOTS(I+KORDER)) then\n IERR5 = 250\n call IERM1('DSFITC',IERR5,0,\n * 'Require TKNOTS(I) < TKNOTS(I+KORDER).',\n * 'I',I,',')\n call DERV1('TKNOTS(I)',TKNOTS(I),',')\n call DERV1('TKNOTS(I+KORDER)',TKNOTS(I+KORDER),'.')\n go to 500\n end if\n 40 continue\nC\nc ------------------------------------------------------------------\nC TEST SD(1)\n if(SD(1) .lt. ZERO) then\n WT1 = -ONE/SD(1)\n USEWT1 = .true.\n else if( SD(1) .gt. ZERO) THEN\n USEWT1 = .false.\n else\n IERR5 = 1100\n call ERMSG('DSFITC',IERR5,0,'Require SD(1) .ne. Zero','.')\n go to 500\n end if\nc\nc . Determine M1, MFIT, NS, MTOT, and NTOT.\nc . M1 = number of non-ignored constraint specifications.\nc . MFIT = number of non-ignored least-squates equations.\nc . NS = number of non-ignored constraints that\nc . are inequality constraints and thus require a slack variable.\nc . MTOT = M1 + MFIT\nc . NTOT = NCOEF + NS\nc\n NBADCC = 0\n M1 = 0\n MFIT = 0\n NS = 0\n I = 1\nc do forever\n 60 continue\n KIND = index(NVTAB, CCODE(I)(1:1))\n DERIV = index(DTAB, CCODE(I)(2:2)) - 1\n RELOP = index(RTAB, CCODE(I)(3:3))\n ACTIVE = index(ATAB, CCODE(I)(4:4))/2\n if(ACTIVE .eq. 3) go to 180\nc\nc . CCODE(I)(1:1) = 1 2 3 4\nc . KIND = 1 2 3 4\nc\nc . CCODE(I)(2:2) = 0 1 2 3 4 5 6 7 8 9\nc . DERIV = 0 1 2 3 4 5 6 7 8 9\nc\nc . CCODE(I)(3:3) = ~ = < >\nc . RELOP = 1 2 3 4\nc\nc . CCODE(I)(4:4) = A a N n !\nc . ACTIVE = 1 1 2 2 3\nc\n if(ACTIVE .eq. 1) then\nC do case(RELOP, 4)\n go to (110, 120, 130, 140), RELOP\nC case other\n IERR5 = 600\n call IERM1('DSFITC',IERR5,0,\n * 'RELOP = CCODE(I)(3:3) has invalid value.','I',I,',')\n MSG3(19:19) = CCODE(I)(3:3)\n call ERMOR(MSG3, '.')\n NBADCC = NBADCC+1\n go to 150\nC case 1\n 110 MFIT = MFIT+1\n go to 150\nC case 2\n 120 M1 = M1+1\n go to 150\nC case 3\n 130 M1 = M1+1\n NS = NS+1\n go to 150\nC case 4\n 140 M1 = M1+1\n NS = NS+1\n 150 continue\nc end case\n else if(ACTIVE .ne. 2) then\n IERR5 = 800\n call IERM1('DSFITC',IERR5,0,\n * 'ACTIVE = CCODE(I)(4:4) has invalid value.','I',I,',')\n MSG4(19:19) = CCODE(I)(4:4)\n call ERMOR(MSG4, '.')\n NBADCC = NBADCC+1\n end if\nc\n if(KIND .eq. 1 .or. KIND .eq. 2) then\n I = I+1\n else if(KIND .eq. 3 .or. KIND .eq. 4) then\n I = I+2\n else\n IERR5 = 700\n call IERM1('DSFITC',IERR5,0,\n * 'KIND = CCODE(I)(1:1) has invalid value.','I',I,',')\n MSG1(19:19) = CCODE(I)(1:1)\n call ERMOR(MSG1, '.')\n NBADCC = ELIMIT+1\n end if\n if(NBADCC .gt. ELIMIT) then\n call ERMSG('DSFITC',IERR5,0,\n * 'Quitting on bad values in CCODE()','.')\n go to 500\n end if\n go to 60\n 180 continue\nC end forever\nc\n if(NBADCC .ne. 0) then\n call ERMSG('DSFITC',IERR5,0,\n * 'Quitting on bad values in CCODE()','.')\n go to 500\n end if\n MTOT = M1 + MFIT\n NTOT = NCOEF + NS\n* print*,'DSFITC.. M1, MFIT, NCOEF, NS =',M1, MFIT, NCOEF, NS\n MINMN = min(MTOT, NTOT)\n INFO(4) = M1\n INFO(5) = MFIT\n INFO(6) = NS\nc\nc . Set indices to partition the work arrays INFO() and WORK().\nc\n IWINDX = 1+KINFO\n IWJSTA = IWINDX+NTOT\n NEED1 = IWJSTA+NTOT - 1\n INFO(2) = NEED1\nc\n MN = MTOT*NTOT\n IWBVEC = MN+1\n IWBND = IWBVEC+MTOT\n IWXS = IWBND +2*NTOT\n IWWRK = IWXS+NTOT\n IWSIZ = IWWRK+NTOT\n IWTNRM = IWSIZ+M1\n IWZ = IWTNRM+NTOT\n IWCC = IWZ+MINMN\n IWSS = IWCC+MINMN\n IWXT = IWSS+MINMN\n IWRT = IWXT+NTOT\n IWDIFF = IWRT+MTOT\n NEED2 = IWDIFF+MTOT - 1\n INFO(3) = NEED2\nc . Check NINFO and NWORK.\nc\n if(NINFO .lt. NEED1 .or. NWORK .lt. NEED2) then\n IERR5 = 300\n call IERM1('DSFITC',IERR5,0,\n * 'Require NINFO .ge. NEED1 and NWORK .ge. NEED2.',\n * 'NINFO',NINFO,',')\n call IERV1('NEED1',NEED1,',')\n call IERV1('NWORK',NWORK,',')\n call IERV1('NEED2',NEED2,'.')\n go to 500\n end if\nc . Zero an MTOT x NTOT space for the matrix.\n do 200 I = 1, MN\n WORK(I) = ZERO\n 200 continue\nc . Zero debug arrays XT() and RT() in WORK().\n do 210 j = 1, ntot\n work(iwxt + j - 1) = ZERO\n 210 continue\n do 220 j = 1, mtot\n work(iwrt + j - 1) = ZERO\n 220 continue\nc\nc . Set bounds for variables. Storing into a 2 x NTOT space.\nc\n do 240 J = 1,2*NTOT\n WORK(IWBND-1+J) = UNBND\n 240 continue\n do 250 J = 1,NS\n WORK(IWBND+(NCOEF+J-1)*2) = ZERO\n 250 continue\nc -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\nc Begin loop to form equations, both constraints and least-squares.\nc\nc Initialize JS = column index of previous slack variable.\nc IRCON = row index of previous constraint equation.\nc IRLS = row index of previous least-squares equation.\nc IC = index of current specification data.\nc LEFT = Arbitrary starting value for use by DSFIND.\nc J1,J2 = Arbitrary starting values for use by DSBASI.\nc\n JS = NCOEF\n IRCON = 0\n IRLS = M1\n IC = 1\n J1 = 1\n J2 = 1\n LEFT = 1\nC do forever\n 300 continue\n ACTIVE = index(ATAB, CCODE(IC)(4:4))/2\n if(ACTIVE .eq. 3) go to 400\n if(ACTIVE .eq. 2) then\n IC = IC+1\n go to 300\n end if\n KIND= index(NVTAB, CCODE(IC)(1:1))\n RELOP = index(RTAB, CCODE(IC)(3:3))\nc\nc . CCODE(I)(1:1) = 1 2 3 4\nc . KIND = 1 2 3 4\nc\nc . CCODE(I)(2:2) = 0 1 2 3 4 5 6 7 8 9\nc . DERIV = 0 1 2 3 4 5 6 7 8 9\nc\nc . CCODE(I)(3:3) = ~ = < >\nc . RELOP = 1 2 3 4\nc\nc . CCODE(I)(4:4) = A a N n !\nc . ACTIVE = 1 1 2 2 3\nc\nc . Set matrix row index, IROW.\nc . Set weight, WT, if RELOP = 1.\nc . Store coefficient of +1 or -1 for slack variable if\nc . RELOP is 3 or 4.\nc\n if(RELOP .eq. 1) then\n IRLS = IRLS+1\n IROW = IRLS\n if( USEWT1) then\n WT = WT1\n else\n SDIC = SD(IC)\n if(SDIC .gt. ZERO) then\n WT=ONE/SDIC\n else\n IERR5 = 1200\n call ERMSG('DSFITC',IERR5,0,\n * 'With SD(1) > 0 require all SD(I) > 0.', ',')\n call DERV1('SD(1)',SD(1),',')\n call IERV1('I',IC,',')\n call DERV1('SD(I)',SDIC,'.')\n go to 500\n end if\n end if\n else\n IRCON = IRCON+1\n IROW = IRCON\n if(RELOP .eq. 3) then\n JS = JS+1\n WORK(IROW+(JS-1)*MTOT) = ONE\n else if(RELOP .eq. 4) then\n JS = JS+1\n WORK(IROW+(JS-1)*MTOT) = -ONE\n end if\n end if\nc\n if(KIND .eq. 4) then\nc Setup for integral\n call DSBASI(KORDER, NCOEF, TKNOTS, XI(IC), XI(IC+1),\n * J1, J2, WORK(IWXS))\n do 320 J = J1, J2\n if(RELOP .eq. 1) then\n WORK(IROW+(J-1)*MTOT) = WORK(IWXS-1+J) * WT\n else\n WORK(IROW+(J-1)*MTOT) = WORK(IWXS-1+J)\n end if\n 320 continue\nc\n if(RELOP .eq. 1) then\n WORK(MN+IROW) = YI(IC) * WT\n else\n WORK(MN+IROW) = YI(IC)\n end if\nc End of setup for integral\n IC = IC+2\n else\nc Setup for value or derivative\nc . DERIV = CCODE()(2:2) = 0 1 2 3 4 5 6 7 8 9\nc\n DERIV = index(DTAB, CCODE(IC)(2:2)) - 1\n X = XI(IC)\n FAC = ONE\nc Negate KIND to flag that this is the first time accumulating values.\n KIND = -KIND\n 340 continue\nc Accumulate values into matrix\n call DSFIND(TKNOTS, KORDER, NCOEF+1, X, LEFT, MODE)\n call DSBASD(KORDER, LEFT, TKNOTS, X, DERIV, BASIS)\n JCOL = LEFT-KORDER+1\n* print*,'DSFITC.. X =',X\n* print*,'DSFITC.. IC,LEFT,JCOL =',IC,LEFT,JCOL\n if(RELOP .eq. 1) FAC = FAC * WT\n do 360 J = 1,KORDER\n WORK(IROW+(JCOL-1)*MTOT) =\n * WORK(IROW+(JCOL-1)*MTOT) + FAC * BASIS(J)\n JCOL = JCOL + 1\n 360 continue\nc End of accumulate values into matrix\n if (KIND .lt. 0) then\nc KIND is reset to positive here.\n KIND = -KIND\n if(KIND .eq. 1) then\n RTVAL = YI(IC)\n else\nc . Here KIND = 2 or 3\n if(KIND .eq. 2) then\n FAC = -ONE\n RTVAL = ZERO\n X = YI(IC)\n else\n DERIV = index(DTAB, CCODE(IC+1)(2:2)) - 1\n FAC = -YI(IC+1)\n RTVAL = YI(IC)\n X = XI(IC+1)\n end if\nc Go back to accumulate values a second time and last time on this iter.\n go to 340\n end if\n end if\nc Set right side of relation.\n if(RELOP .eq. 1) then\n WORK(MN+IROW) = RTVAL * WT\n else\n WORK(MN+IROW) = RTVAL\n end if\nc End of setup for value or derivative\n IC = IC+1\n if(KIND .eq. 3) IC = IC+1\n end if\n go to 300\n 400 continue\nc end forever\nc . End loop to form equations.\nc -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\nc print'(1x/1x,a,i5,a,i5)','DSFITC.. MTOT =',MTOT,', NTOT =',NTOT\nc print'(1x/1x,a/1x)','DSFITC.. Matrix going to DBLSE:'\nc do for I = 1,MTOT\nc print'(1x/1x,i5,3x,5g13.5/(9x,5g13.5))',\nc * I,(WORK(I+(J-1)*MTOT),J=1,NTOT+1)\nc end for\nc\nc . All points have been processed. Call for the solution.\nc\n TOL = D1MACH(4)**(0.75d0)\n call DBLSE(WORK, MTOT, MTOT, NTOT, M1, WORK(MN+1),\n * WORK(IWBND), UNBND, KPRINT, TOL, IERR4, WORK(IWXS),\n * RNORM, NSETP,\n * WORK(IWWRK), WORK(IWSIZ), WORK(IWTNRM), WORK(IWZ),\n * WORK(IWCC), WORK(IWSS), INFO(IWINDX), INFO(IWJSTA),\n * WORK(IWXT), WORK(IWRT), WORK(IWDIFF))\nc\nc -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n INFO(7) = NSETP\n if(IERR4 .ne. 0) then\n IERR5 = 1000 + IERR4\n call ERMSG('DSFITC',IERR5,0, 'Error noted in DBLSE.','.')\n go to 500\n end if\nc\n do 440 I=1,NCOEF\n BCOEF(I) = WORK(IWXS-1+I)\n 440 continue\n INFO(1) = IERR5\n return\nc ------------------------------------------------------------------\nc ERROR RETURN\n 500 do 520 I=1,NCOEF\n BCOEF(I)=ZERO\n 520 continue\n INFO(1) = IERR5\n return\n end\n", "meta": {"hexsha": "1f06d67618e11d5cb64702065bff3e7b4397fa98", "size": 27910, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/dsfitc.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/dsfitc.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/dsfitc.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.6448863636, "max_line_length": 72, "alphanum_fraction": 0.5365102114, "num_tokens": 8963, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952921073469, "lm_q2_score": 0.7279754489059774, "lm_q1q2_score": 0.6535001332526283}} {"text": " double precision function DSINHM (X)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nC>> 1998-10-29 DSINHM Krogh Moved external statement up for mangle.\nc>> 1994-10-20 DSINHM Krogh Changes to use M77CON\nc>> 1994-05-22 DSINHM WV Snyder JPL Make SP and DP alike using CHGTYP\nc>> 1993-07-21 DSINHM WV Snyder JPL Original code\nc\nc Compute SINH(X) - X.\nc\nc--D replaces \"?\": ?SINHM\n double precision X\n external D1MACH\n double precision CUT, D1MACH, E, ROUND, X2\n parameter (CUT = 0.25d0)\n double precision SP5, SP4, SP3, SP2, SP1, SQ1\n parameter ( SP5 = .255251817302048D-09)\n parameter ( SP4 = .723809046696880D-07)\n parameter ( SP3 = .109233297700241D-04)\n parameter ( SP2 = .954811583154274D-03)\n parameter ( SP1 = .452867078563929D-01)\n parameter ( SQ1 =-.471329214363072D-02*6.0D0)\n integer M, N\n save M, ROUND\n data M /-1/\nc\n if (m .lt. 0) then\n round = d1mach(4)\n if (round .lt. 5.0d-14) then\nc Compute appropriate value of M depending on round-off.\n m = 3\n e = cut/6.0d0\n10 if (e .gt. round) then\n m = m + 2\n e = e*cut*cut/(m*(m-1))\n go to 10\n end if\n end if\n end if\nc\n if (round .lt. 5.0d-14) then\n n = m\n x2 = x*x\nc We assume m > 1\n dsinhm = 1.0d0 + x2/(n*(n-1))\n20 if (n .gt. 5) then\n n = n - 2\n dsinhm = 1.0d0 + dsinhm*x2/(n*(n-1))\n go to 20\n end if\n dsinhm = x * x2 * dsinhm / 6.0d0\n return\n end if\nc\nc Use a rational approximation when ABS(X) is less than 1.65,\nc else use the Fortran intrinsic function.\nc\n if (x .lt. 1.65d0) then\n x2 = x*x\n dsinhm = ((((((sp5*x2+sp4)*x2+sp3)*x2+sp2)*x2+sp1)*x2+1.0d0)\n * *x2*x)/(sq1*x2+6.0d0)\n else\n dsinhm = sinh(x) - x\n end if\n return\n end\n", "meta": {"hexsha": "a39a37147a6869d8bb712502d27edf3b8c58f344", "size": 2080, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/dsinhm.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/dsinhm.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/dsinhm.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": 30.5882352941, "max_line_length": 71, "alphanum_fraction": 0.5466346154, "num_tokens": 753, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695283896349, "lm_q2_score": 0.7279754489059774, "lm_q1q2_score": 0.6535001272752236}} {"text": " real(kind(0.0d0)) function volume (vecs, ndim) \r\n!-----------------------------------------------\r\n! M o d u l e s \r\n!-----------------------------------------------\r\n USE vast_kind_param, ONLY: double \r\n!...Translated by Pacific-Sierra Research 77to90 4.4G 17:49:42 03/20/06 \r\n!...Switches: -rl INDDO=2 INDIF=2 \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 integer , intent(in) :: ndim \r\n real(double) , intent(in) :: vecs(3,ndim) \r\n!-----------------------------------------------\r\n! L o c a l V a r i a b l e s\r\n!-----------------------------------------------\r\n real(double) :: a, b, gamma, sing, c, alpha, sina, beta, sinb \r\n!-----------------------------------------------\r\n!**********************************************************************\r\n!\r\n! VOLUME RETURNS (A) THE VOLUME OF A UNIT CELL IF NDIM=3\r\n! (B) THE AREA OF A UNIT CELL IF NDIM=2\r\n! (C) THE LENGTH OF A UNIT CELL IF NDIM=1\r\n!\r\n! ON INPUT VECS = ARRAY OF POINTS MARKING THE ENDS OF UNIT CELL VECTORS\r\n! THE ORIGIN BEING (0.0, 0.0, 0.0)\r\n!\r\n!**********************************************************************\r\n a = sqrt(vecs(1,1)**2+vecs(2,1)**2+vecs(3,1)**2) \r\n!\r\n! CASE 1: SYSTEM IS A POLYMER\r\n!\r\n if (ndim == 1) then \r\n volume = a \r\n return \r\n endif \r\n b = sqrt(vecs(1,2)**2+vecs(2,2)**2+vecs(3,2)**2) \r\n gamma = sqrt((vecs(1,1)-vecs(1,2))**2+(vecs(2,1)-vecs(2,2))**2+(vecs(3,1)&\r\n -vecs(3,2))**2) \r\n!\r\n! SING = SIN OF ANGLE BETWEEN FIRST AND SECOND VECTORS\r\n! OBTAINED FROM COSINE RULE C**2=A**2+B**2-2*A*B*COS(C)\r\n!\r\n sing = sqrt(1.D0 - ((a*a + b*b - gamma*gamma)/(2.D0*a*b))**2) \r\n!\r\n! CASE 2: SYSTEM IS A LAYER STRUCTURE\r\n!\r\n if (ndim == 2) then \r\n!\r\n! AREA OF A PARALLELOGRAM = BASE * HEIGHT\r\n!\r\n volume = a*b*sing \r\n return \r\n endif \r\n!\r\n! CASE 3: SYSTEM IS A SOLID\r\n!\r\n c = sqrt(vecs(1,3)**2+vecs(2,3)**2+vecs(3,3)**2) \r\n alpha = sqrt((vecs(1,2)-vecs(1,3))**2+(vecs(2,2)-vecs(2,3))**2+(vecs(3,2)&\r\n -vecs(3,3))**2) \r\n sina = sqrt(1.D0 - ((b*b + c*c - alpha*alpha)/(2.D0*b*c))**2) \r\n beta = sqrt((vecs(1,1)-vecs(1,3))**2+(vecs(2,1)-vecs(2,3))**2+(vecs(3,1)-&\r\n vecs(3,3))**2) \r\n sinb = sqrt(1.D0 - ((a*a + c*c - beta*beta)/(2.D0*a*c))**2) \r\n!\r\n! SINA = SIN OF ANGLE BETWEEN SECOND AND THIRD VECTORS\r\n! SINB = SIN OF ANGLE BETWEEN FIRST AND THIRD VECTORS\r\n!\r\n! VOLUME OF A PARALLELEPIPED =A*SIN(ALPHA)*B*SIN(BETA)*C*SIN(GAMMA)\r\n!\r\n volume = a*b*c*sina*sinb*sing \r\n return \r\n end function volume \r\n", "meta": {"hexsha": "45a8dc3eccf58084e97b8e4043f7de8437986e4f", "size": 2751, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "2006_MOPAC7.1/src_subroutines/volume.f90", "max_stars_repo_name": "openmopac/MOPAC-archive", "max_stars_repo_head_hexsha": "01510e44246de34a991529297a10bcf831336038", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-12-16T20:53:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-16T20:54:11.000Z", "max_issues_repo_path": "2006_MOPAC7.1/src_subroutines/volume.f90", "max_issues_repo_name": "openmopac/MOPAC-archive", "max_issues_repo_head_hexsha": "01510e44246de34a991529297a10bcf831336038", "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": "2006_MOPAC7.1/src_subroutines/volume.f90", "max_forks_repo_name": "openmopac/MOPAC-archive", "max_forks_repo_head_hexsha": "01510e44246de34a991529297a10bcf831336038", "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": 37.1756756757, "max_line_length": 81, "alphanum_fraction": 0.4238458742, "num_tokens": 906, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.7279754371026367, "lm_q1q2_score": 0.653500122656825}} {"text": "program ch0709\n ! Means and Standard Deviations\n implicit none\n\n real :: mean = 0., ssq = 0., x, w, sd, r\n integer :: i, n\n\n print *, ' enter the number of readings'\n read *, n\n print *, ' enter the ', n, &\n ' values one per line'\n do i = 1, n\n read *, x\n w = x-mean\n r = i-1\n mean = (r*mean+x)/i\n ssq = ssq+w*w*r/i\n end do\n sd = (ssq/r)**0.5\n print *, ' mean is ', mean\n print *, ' standard deviation is ', sd\nend program\n", "meta": {"hexsha": "79a4d7908056292f9b400d93ff7821cda3ac947e", "size": 501, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ch07/ch0709.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": "ch07/ch0709.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": "ch07/ch0709.f90", "max_forks_repo_name": "hechengda/fortran", "max_forks_repo_head_hexsha": "44735609ece7995d049016f758590d710b8a4f15", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.7826086957, "max_line_length": 44, "alphanum_fraction": 0.4910179641, "num_tokens": 165, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473879530491, "lm_q2_score": 0.7490872243177518, "lm_q1q2_score": 0.6534642834825906}} {"text": "subroutine interp_tk (x ,y ,noval ,xx ,yy )\n!----- GPL ---------------------------------------------------------------------\n! \n! Copyright (C) Stichting Deltares, 2011-2016. \n! \n! This program is free software: you can redistribute it and/or modify \n! it under the terms of the GNU General Public License as published by \n! the Free Software Foundation version 3. \n! \n! This program is distributed in the hope that it will be useful, \n! but WITHOUT ANY WARRANTY; without even the implied warranty of \n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \n! GNU General Public License for more details. \n! \n! You should have received a copy of the GNU General Public License \n! along with this program. If not, see . \n! \n! contact: delft3d.support@deltares.nl \n! Stichting Deltares \n! P.O. Box 177 \n! 2600 MH Delft, The Netherlands \n! \n! All indications and logos of, and references to, \"Delft3D\" and \"Deltares\" \n! are registered trademarks of Stichting Deltares, and remain the property of \n! Stichting Deltares. All rights reserved. \n! \n!-------------------------------------------------------------------------------\n! $Id: interp_tk.f90 5717 2016-01-12 11:35:24Z mourits $\n! $HeadURL: https://svn.oss.deltares.nl/repos/delft3d/tags/6686/src/engines_gpl/flow2d3d/packages/kernel/src/compute_nearfar/interp_tk.f90 $\n!!--description-----------------------------------------------------------------\n!\n! Function: Interpolate to the y-value at xx\n!\n! Method used:\n!\n!!--pseudo code and references--------------------------------------------------\n! NONE\n!!--declarations----------------------------------------------------------------\n!\n\n use precision\n !\n implicit none\n!\n! Global variables\n!\n integer , intent (in) :: noval\n real(fp), dimension(noval), intent (in) :: x\n real(fp), dimension(noval), intent (in) :: y \n real(fp), intent (in) :: xx\n real(fp), intent (out) :: yy\n!\n! Local variables\n!\n integer :: n\n!\n!! executable statements -------------------------------------------------------\n!\n if (xx <= x(1)) then\n yy = y(1)\n elseif (xx >= x(noval)) then\n yy = y(noval)\n else\n do n = 2, noval\n if (xx >= x(n-1) .and. xx < x(n)) then\n yy = y(n-1) + ((xx - x(n-1))/(x(n) - x(n-1)))*(y(n) - y(n-1))\n endif\n enddo\n endif\nend subroutine interp_tk\n", "meta": {"hexsha": "989ad44306f2e9ea26ad68bd80e17d9b35a5e50f", "size": 3468, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "docker/water/delft3d/tags/v6686/src/engines_gpl/flow2d3d/packages/kernel/src/compute_nearfar/interp_tk.f90", "max_stars_repo_name": "liujiamingustc/phd", "max_stars_repo_head_hexsha": "4f815a738abad43531d02ac66f5bd0d9a1def52a", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-01-06T03:01:18.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T03:02:55.000Z", "max_issues_repo_path": "docker/water/delft3d/tags/v6686/src/engines_gpl/flow2d3d/packages/kernel/src/compute_nearfar/interp_tk.f90", "max_issues_repo_name": "liujiamingustc/phd", "max_issues_repo_head_hexsha": "4f815a738abad43531d02ac66f5bd0d9a1def52a", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docker/water/delft3d/tags/v6686/src/engines_gpl/flow2d3d/packages/kernel/src/compute_nearfar/interp_tk.f90", "max_forks_repo_name": "liujiamingustc/phd", "max_forks_repo_head_hexsha": "4f815a738abad43531d02ac66f5bd0d9a1def52a", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.8450704225, "max_line_length": 141, "alphanum_fraction": 0.3780276817, "num_tokens": 670, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473879530491, "lm_q2_score": 0.7490872187162397, "lm_q1q2_score": 0.6534642785961261}} {"text": "program gridgenlaval2d\n implicit none\n\n !*****************************************************************************\n ! Grid generator for SFB708 Laval nozzle based on external triangle mesher\n !\n ! Configuration\n !\n ! w1\n ! +----+\n ! | |h1\n ! | | w2\n ! | +----+ w3\n ! | |h2 +------------+\n ! | | | |\n ! + + - - -+ (x1,y1) | |\n ! : + ang1 | |\n ! * h0 + | r1 ---------------+ |h3\n ! : r0 + ---------- |\n ! + + - +----- ang2 - - - - - - - - - -+ |\n ! | |\n ! #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +\n ! |<------------------- length ------------------>|\n !\n ! h0,r0 : height of the midpoint and radius of the inlet\n ! w1,w2 : widths of the inlet chamber\n ! h1,h2 : heights of the inlet chamber\n ! length : total length of the nozzle (without outlet chamber)\n ! (x1,y1) : position of the circle midpoints\n ! r1,ang1 : radius and angle of the circle segment\n ! ang2 : angle of the diverging chamber\n ! w3,h3 : width and height of the outlet chamber\n !\n ! The configuration is mirrored along the x-axis and starts at #.\n !\n !*****************************************************************************\n\n ! Definition of double precision\n integer, parameter :: DP = selected_real_kind(15,307)\n\n ! Definition of mathematical constant PI\n real(DP) :: pi\n\n ! Predefined values\n real(DP) :: dangle1 = 85.0_DP\n real(DP) :: dangle2 = 2.0_DP\n real(DP) :: ddistin = 1.0_DP\n real(DP) :: ddistout = 1.0_DP\n real(DP) :: ddistcon = 1.0_DP \n real(DP) :: ddistdiv = 1.0_DP \n real(DP) :: dheight0 = 7.0_DP\n real(DP) :: dheight1 = 1.0_DP\n real(DP) :: dheight2 = 1.0_DP\n real(DP) :: dheight3 = 14.0_DP\n real(DP) :: dlength = 58.85_DP\n real(DP) :: dradius0 = 2.0_DP\n real(DP) :: dradius1 = 11.75_DP\n real(DP) :: dwidth1 = 1.0_DP\n real(DP) :: dwidth2 = 1.0_DP\n real(DP) :: dwidth3 = 14.0_DP\n real(DP) :: dx1 = 0.0_DP\n real(DP) :: dy1 = 13.0_DP\n\n ! Total number of fixed points\n integer, parameter :: ncoords = 22\n\n ! Coordinates\n real(DP), dimension(2,ncoords) :: Dpoints\n\n ! Definition of output filename\n character(len=1024) :: coutputfile = \"grid\"\n\n ! Options passed to triangle\n character(len=1024) :: ctriangleopts = \"-j -C\"\n\n ! Definition of output format\n character(LEN=*), parameter :: cFormat = '(F32.15)'\n\n ! Use rz-coordinates\n logical :: brzCoords = .false.\n \n ! local variables\n character(len=80) :: cbuffer\n character(len=32) :: cbuffer1,cbuffer2,cbuffer3,cbuffer4,cbuffer5,cbuffer6\n logical :: brewrite\n real(DP) :: domega,dsegmentlen,dx,dy,dpar\n integer :: i,i1,i2,i3,i4,ibdc,iel,ipoint,isubpoint,ivt\n integer :: nel,npoints,nsubsegments,nvt,npar\n \n !-----------------------------------------------------------------------------\n ! Initialize mathematical constant(s)\n !-----------------------------------------------------------------------------\n\n pi = asin(1.0_DP)*2.0_DP\n\n !-----------------------------------------------------------------------------\n ! Get command line arguments\n !-----------------------------------------------------------------------------\n \n call getCmdArgs()\n \n dangle1 = pi/180.0_DP*dangle1\n dangle2 = pi/180.0_DP*dangle2\n\n !-----------------------------------------------------------------------------\n ! Write statistics\n !-----------------------------------------------------------------------------\n\n write(*,'(A)') 'Generating grid'\n write(*,'(A)') '---------------'\n write(*,'(A,T45,A)') 'name of output file: ',trim(adjustl(coutputfile))\n\n !-----------------------------------------------------------------------------\n ! Generate coordinates of all corners\n !-----------------------------------------------------------------------------\n\n if (brzCoords) then\n call genCorners_rz\n else\n call genCorners_xy\n end if\n\n !-----------------------------------------------------------------------------\n ! Generate PRM-file\n !-----------------------------------------------------------------------------\n\n if (brzCoords) then\n call genPRM_rz\n else \n call genPRM_xy\n end if\n\n !-----------------------------------------------------------------------------\n ! Generate PSLG (planar straight line graph) for the external program triangle\n !-----------------------------------------------------------------------------\n\n if (brzCoords) then\n call genPSLR_rz\n else \n call genPSLR_xy\n end if\n \n ! Call triangle mesh generator with specified options\n write(*,*) \"Calling triangle with the following options:\"\n write(*,*) trim(adjustl(ctriangleopts))\n call system('triangle '//trim(adjustl(ctriangleopts)))\n \n !---------------------------------------------------------------------------\n ! Read data for inner triangulation and convert it into TRI format\n !---------------------------------------------------------------------------\n \n open(unit=100, file=trim(adjustl(coutputfile))//'.1.node')\n read(100, fmt=*) nvt\n close(100)\n \n open(unit=100, file=trim(adjustl(coutputfile))//'.1.ele')\n read(100, fmt=*) nel\n close(100)\n \n !-----------------------------------------------------------------------------\n ! Generate TRI-file\n !-----------------------------------------------------------------------------\n\n call genTRI\n\ncontains\n\n ! Here, the real working routines follwo\n\n !*****************************************************************************\n\n subroutine getCmdArgs\n\n do i = 1, command_argument_count()\n\n call get_command_argument(i, cbuffer)\n select case(cbuffer)\n case('-h','-H','--help')\n write(*,'(A)') 'Usage: gridgenlaval2d [OPTION]'\n write(*,'(A)') 'Generate grid for laval nozzle in TRI/PRM format.'\n write(*,*)\n write(*,'(A)') \" w1\"\n write(*,'(A)') \" +----+\"\n write(*,'(A)') \" | |h1\"\n write(*,'(A)') \" | | w2\"\n write(*,'(A)') \" | +----+ w3\"\n write(*,'(A)') \" | |h2 +------------+\"\n write(*,'(A)') \" | | | |\"\n write(*,'(A)') \" + + - - -+ (x1,y1) | |\"\n write(*,'(A)') \" : + ang1 | |\"\n write(*,'(A)') \" * h0 + | r1 ---------------+ |h3\"\n write(*,'(A)') \" : r0 + ---------- |\"\n write(*,'(A)') \" + + - +----- ang2 - - - - - - - - - -+ |\"\n write(*,'(A)') \" | |\"\n write(*,'(A)') \" #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +\"\n write(*,'(A)') \" |<------------------- length ------------------>|\"\n write(*,*)\n write(*,'(A,T30,A)') '-a, --area','average area of triangles'\n write(*,'(A,T30,A)') '-a1, --angle1','angle of the circle segment'\n write(*,'(A,T30,A)') '-a2, --angle2','angle of the diverging chamber'\n write(*,'(A,T30,A)') '-D, --Delaunay','generate conforming Delaunay '//&\n 'triangulation and not just constrained Delaunay triangulation'\n write(*,'(A,T30,A)') '-di, --distinlet','average distance between '//&\n 'points along the inlet boundary'\n write(*,'(A,T30,A)') '-dc, --distconvergent','average distance between '//&\n 'points along the convergent part of the boundary'\n write(*,'(A,T30,A)') '-dd, --distdivergent','average distance between '//&\n 'points along the divergent part of the boundary'\n write(*,'(A,T30,A)') '-do, --distoutlet','average distance between '//&\n 'points along the outlet boundary'\n write(*,'(A,T30,A)') '-F, --Fortune','use Steven Fortunes algorithm for '//&\n 'Delaunay triangulation'\n write(*,'(A,T30,A)') '-h, -H, --help','this help screen'\n write(*,'(A,T30,A)') '-h0, --height0','height of the midpoint of the inlet'\n write(*,'(A,T30,A)') '-h1, --height1','height of the inlet chamber'\n write(*,'(A,T30,A)') '-h2, --height2','height of the inlet chamber'\n write(*,'(A,T30,A)') '-h3, --height3','height of the outlet chamber'\n write(*,'(A,T30,A)') '-i, --incremental','use incremental algorithm for Delaunay triangulation'\n write(*,'(A,T30,A)') '-l, --length','length of the nozzle (without outlet chamber)'\n write(*,'(A,T30,A)') '-o, --outputfile','name of the output file'\n write(*,'(T30,A)') 'If not given, the generated grid is stored in file \"grid.tri/prm\".'\n write(*,'(A,T30,A)') '-Q, --quiet','suppress output other than errors'\n write(*,'(A,T30,A)') '-q, --quality','Quality mesh generation with no '//&\n 'angles smaller than 20 degrees'\n write(*,'(A,T30,A)') '-r0, --radius0','radius of the inlet'\n write(*,'(A,T30,A)') '-r1, --radius1','radius of the circle segment'\n write(*,'(A,T30,A)') '-rz', 'use rz-coodinate system'\n write(*,'(A,T30,A)') '-x1','horizontal position of the circle segment'\n write(*,'(A,T30,A)') '-xy', 'use xy-coodinate system (default)'\n write(*,'(A,T30,A)') '-V, --verbose','print detailed information'\n write(*,'(A,T30,A)') '-Y','do not insert Steiner points on the boundary'\n write(*,'(A,T30,A)') '-YY','do not insert Steiner points anywhere'\n write(*,'(A,T30,A)') '-y1','vertical position of the circle segment'\n write(*,'(A,T30,A)') '-w1, --width1','width of the inlet chamber'\n write(*,'(A,T30,A)') '-w2, --width2','width of the inlet chamber'\n write(*,'(A,T30,A)') '-w3, --width3','width of the outlet chamber'\n write(*,*)\n write(*,'(A)') 'Report bugs to .'\n stop\n\n case('-A','--Area')\n ctriangleopts = trim(adjustl(ctriangleopts))//' -a'\n\n case('-a','--area')\n call get_command_argument(i+1, cbuffer)\n ctriangleopts = trim(adjustl(ctriangleopts))//' -a'//trim(adjustl(cbuffer))\n\n case('-a1','--angle1')\n call get_command_argument(i+1, cbuffer)\n read(cbuffer,*) dangle1\n\n case('-a2','--angle2')\n call get_command_argument(i+1, cbuffer)\n read(cbuffer,*) dangle2\n\n case('-D','--Delaunay')\n ctriangleopts = trim(adjustl(ctriangleopts))//' -D'\n\n case('-di','--distinlet')\n call get_command_argument(i+1, cbuffer)\n read(cbuffer,*) ddistin\n\n case('-do','--distoutlet')\n call get_command_argument(i+1, cbuffer)\n read(cbuffer,*) ddistout\n\n case('-dc','--distconvergent')\n call get_command_argument(i+1, cbuffer)\n read(cbuffer,*) ddistcon\n\n case('-dd','--distdivergent')\n call get_command_argument(i+1, cbuffer)\n read(cbuffer,*) ddistdiv\n\n case('-F','--Fortune')\n ctriangleopts = trim(adjustl(ctriangleopts))//' -F'\n\n case('-h0','--height0')\n call get_command_argument(i+1, cbuffer)\n read(cbuffer,*) dheight0\n\n case('-h1','--height1')\n call get_command_argument(i+1, cbuffer)\n read(cbuffer,*) dheight1\n\n case('-h2','--height2')\n call get_command_argument(i+1, cbuffer)\n read(cbuffer,*) dheight2\n\n case('-h3','--height3')\n call get_command_argument(i+1, cbuffer)\n read(cbuffer,*) dheight3\n\n case('-i','--incremental')\n ctriangleopts = trim(adjustl(ctriangleopts))//' -i'\n\n case('-l','--length')\n call get_command_argument(i+1, cbuffer)\n read(cbuffer,*) dlength\n\n case('-o','--outputfile')\n call get_command_argument(i+1, coutputfile)\n ctriangleopts = trim(adjustl(ctriangleopts))//' -p '//trim(adjustl(coutputfile))\n\n case('-Q','--quiet')\n ctriangleopts = trim(adjustl(ctriangleopts))//' -Q'\n\n case('-q','--quality')\n ctriangleopts = trim(adjustl(ctriangleopts))//' -q'\n\n case('-r0','--radius0')\n call get_command_argument(i+1, cbuffer)\n read(cbuffer,*) dradius0\n\n case('-r1','--radius1')\n call get_command_argument(i+1, cbuffer)\n read(cbuffer,*) dradius1\n\n case('-rz')\n brzCoords = .true.\n\n case('-x1')\n call get_command_argument(i+1, cbuffer)\n read(cbuffer,*) dx1\n\n case('-xy')\n brzCoords = .false.\n\n case('-V','--verbose')\n ctriangleopts = trim(adjustl(ctriangleopts))//' -V'\n\n case('-Y')\n ctriangleopts = trim(adjustl(ctriangleopts))//' -Y'\n\n case('-YY')\n ctriangleopts = trim(adjustl(ctriangleopts))//' -YY'\n\n case('-y1')\n call get_command_argument(i+1, cbuffer)\n read(cbuffer,*) dy1\n\n case('-w1','--width1')\n call get_command_argument(i+1, cbuffer)\n read(cbuffer,*) dwidth1\n\n case('-w2','--width2')\n call get_command_argument(i+1, cbuffer)\n read(cbuffer,*) dwidth2\n\n case('-w3','--width3')\n call get_command_argument(i+1, cbuffer)\n read(cbuffer,*) dwidth3\n\n end select\n end do\n end subroutine getCmdArgs\n\n !*****************************************************************************\n\n subroutine genCorners_xy\n\n Dpoints(1,1) = dx1-dradius1-dwidth1-dwidth2\n Dpoints(2,1) = -(dy1+dheight1+dheight2)\n \n Dpoints(1,2) = dx1-dradius1-dwidth2\n Dpoints(2,2) = Dpoints(2,1)\n \n Dpoints(1,3) = Dpoints(1,2)\n Dpoints(2,3) = -(dy1+dheight2)\n \n Dpoints(1,4) = dx1-dradius1\n Dpoints(2,4) = Dpoints(2,3)\n \n Dpoints(1,5) = Dpoints(1,4)\n Dpoints(2,5) = -dy1\n \n Dpoints(1,6) = dx1+dradius1*cos(pi-dangle1)\n Dpoints(2,6) = -dy1+dradius1*sin(pi-dangle1)\n \n Dpoints(1,7) = dx1+(dlength-dradius1-dwidth1-dwidth2)\n Dpoints(2,7) = Dpoints(2,6)-tan(dangle2)*(Dpoints(1,7)-Dpoints(1,6))\n \n Dpoints(1,8) = Dpoints(1,7)\n Dpoints(2,8) = -dheight3\n \n Dpoints(1,9) = Dpoints(1,8)+dwidth3\n Dpoints(2,9) = Dpoints(2,8)\n \n Dpoints(1,10:18) = Dpoints(1,9:1:-1)\n Dpoints(2,10:18) = -Dpoints(2,9:1:-1)\n \n Dpoints(1,19) = Dpoints(1,18)\n Dpoints(2,19) = min(Dpoints(2,18),&\n 0.5_DP*(Dpoints(2,18)+Dpoints(2,1))+dheight0+dradius0)\n \n Dpoints(1,20) = Dpoints(1,18)\n Dpoints(2,20) = min(Dpoints(2,18),&\n 0.5_DP*(Dpoints(2,18)+Dpoints(2,1))+dheight0-dradius0)\n \n if (dradius0 >= dheight0) then\n Dpoints(:,21) = Dpoints(:,20)\n Dpoints(:,22) = Dpoints(:,20)\n else\n Dpoints(1,21) = Dpoints(1,18)\n Dpoints(2,21) = max(Dpoints(2,1),&\n 0.5_DP*(Dpoints(2,18)+Dpoints(2,1))-dheight0+dradius0)\n \n Dpoints(1,22) = Dpoints(1,18)\n Dpoints(2,22) = max(Dpoints(2,1),&\n 0.5_DP*(Dpoints(2,18)+Dpoints(2,1))-dheight0-dradius0)\n end if\n \n end subroutine genCorners_xy\n\n !*****************************************************************************\n\n subroutine genCorners_rz\n\n Dpoints(1,1) = dx1-dradius1-dwidth1-dwidth2\n Dpoints(2,1) = -(dy1+dheight1+dheight2)\n \n Dpoints(1,2) = dx1-dradius1-dwidth2\n Dpoints(2,2) = Dpoints(2,1)\n \n Dpoints(1,3) = Dpoints(1,2)\n Dpoints(2,3) = -(dy1+dheight2)\n \n Dpoints(1,4) = dx1-dradius1\n Dpoints(2,4) = Dpoints(2,3)\n \n Dpoints(1,5) = Dpoints(1,4)\n Dpoints(2,5) = -dy1\n \n Dpoints(1,6) = dx1+dradius1*cos(pi-dangle1)\n Dpoints(2,6) = -dy1+dradius1*sin(pi-dangle1)\n \n Dpoints(1,7) = dx1+(dlength-dradius1-dwidth1-dwidth2)\n Dpoints(2,7) = Dpoints(2,6)-tan(dangle2)*(Dpoints(1,7)-Dpoints(1,6))\n \n Dpoints(1,8) = Dpoints(1,7)\n Dpoints(2,8) = -dheight3\n \n Dpoints(1,9) = Dpoints(1,8)+dwidth3\n Dpoints(2,9) = Dpoints(2,8)\n \n Dpoints(1,10:18) = Dpoints(1,9:1:-1)\n Dpoints(2,10:18) = 0.0_DP\n \n Dpoints(1,19) = Dpoints(1,18)\n Dpoints(2,19) = min(Dpoints(2,18),&\n 0.5_DP*(Dpoints(2,18)+Dpoints(2,1))+dheight0+dradius0)\n \n Dpoints(1,20) = Dpoints(1,18)\n Dpoints(2,20) = min(Dpoints(2,18),&\n 0.5_DP*(Dpoints(2,18)+Dpoints(2,1))+dheight0-dradius0)\n \n if (dradius0 >= dheight0) then\n Dpoints(:,21) = Dpoints(:,20)\n Dpoints(:,22) = Dpoints(:,20)\n else\n Dpoints(1,21) = Dpoints(1,18)\n Dpoints(2,21) = max(Dpoints(2,1),&\n 0.5_DP*(Dpoints(2,18)+Dpoints(2,1))-dheight0+dradius0)\n \n Dpoints(1,22) = Dpoints(1,18)\n Dpoints(2,22) = max(Dpoints(2,1),&\n 0.5_DP*(Dpoints(2,18)+Dpoints(2,1))-dheight0-dradius0)\n end if\n\n ! Post correction\n Dpoints(1:2,19) = Dpoints(1:2,21)\n Dpoints(1:2,20) = Dpoints(1:2,22)\n\n end subroutine genCorners_rz\n\n !*****************************************************************************\n\n subroutine genPRM_xy\n\n open(unit=100, file=trim(adjustl(coutputfile))//'.prm')\n\n write(100,'(A)') 'NBCT'\n write(100,'(A)') '1'\n write(100,'(A)') 'IBCT'\n write(100,'(A)') '1 '\n write(100,'(A)') 'NCOMP'\n\n write(cbuffer1, fmt='(I4)') 4 + merge(2,0,dheight1 /= 0.0_DP)&\n + merge(2,0,dheight2 /= 0.0_DP)&\n + merge(2,0,dwidth1 /= 0.0_DP)&\n + merge(2,0,dwidth2 /= 0.0_DP)&\n + merge(5,1,dwidth3 > 0.0_DP)&\n + merge(5,merge(1,3,dradius0 >= dheight0),&\n dheight0 > 0.0_DP .and. dradius0 < dheight0)\n\n write(100,'(A)') trim(adjustl(cbuffer1))\n write(100,'(A)') 'ITYP NSPLINE NPAR'\n if (dwidth1 /= 0.0_DP) write(100,'(A)') '1 1 2 '\n if (dheight1 /= 0.0_DP) write(100,'(A)') '1 1 2 '\n if (dwidth2 /= 0.0_DP) write(100,'(A)') '1 1 2 '\n if (dheight2 /= 0.0_DP) write(100,'(A)') '1 1 2 '\n write(100,'(A)') '2 1 3 ' ! lower circle segment\n\n write(100,'(A)') '1 1 2 ' ! lower converging chamber\n if (dwidth3 > 0.0_DP) then\n ! Note that we do not check the special case that\n ! dwidth3 equals the height of the exit throat\n write(100,'(A)') '1 1 2 '\n write(100,'(A)') '1 1 2 ' ! lower boundary outlet chamber\n write(100,'(A)') '1 1 2 ' ! right boundary outlet chamber\n write(100,'(A)') '1 1 2 ' ! upper boundary outlet chamber\n write(100,'(A)') '1 1 2 '\n else\n write(100,'(A)') '1 1 2 ' ! outlet boundary without chamber\n end if\n write(100,'(A)') '1 1 2 ' ! upper converging chamber\n write(100,'(A)') '2 1 3 ' ! upper circle segment\n if (dheight2 /= 0.0_DP) write(100,'(A)') '1 1 2 '\n if (dwidth2 /= 0.0_DP) write(100,'(A)') '1 1 2 '\n if (dheight1 /= 0.0_DP) write(100,'(A)') '1 1 2 '\n if (dwidth1 /= 0.0_DP) write(100,'(A)') '1 1 2 '\n\n ! left boundary inlet chamber\n if (dheight0 > 0.0_DP .and. dradius0 < dheight0) then\n write(100,'(A)') '1 1 2 '\n write(100,'(A)') '1 1 2 '\n write(100,'(A)') '1 1 2 '\n write(100,'(A)') '1 1 2 '\n write(100,'(A)') '1 1 2 '\n else if (dradius0 >= dheight0) then\n write(100,'(A)') '1 1 2 '\n else\n write(100,'(A)') '1 1 2 '\n write(100,'(A)') '1 1 2 '\n write(100,'(A)') '1 1 2 '\n end if\n\n write(100,'(A)') 'PARAMETERS'\n ! Line segment\n if (dwidth1 /= 0.0_DP) then\n write(cbuffer1, cFormat) Dpoints(1,1)\n write(cbuffer2, cFormat) Dpoints(2,1)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,2)-Dpoints(1,1)\n write(cbuffer2, cFormat) Dpoints(2,2)-Dpoints(2,1)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n end if\n ! Line segment\n if (dheight1 /= 0.0_DP) then\n write(cbuffer1, cFormat) Dpoints(1,2)\n write(cbuffer2, cFormat) Dpoints(2,2)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,3)-Dpoints(1,2)\n write(cbuffer2, cFormat) Dpoints(2,3)-Dpoints(2,2)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n end if\n ! Line segment\n if (dwidth2 /= 0.0_DP) then\n write(cbuffer1, cFormat) Dpoints(1,3)\n write(cbuffer2, cFormat) Dpoints(2,3)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,4)-Dpoints(1,3)\n write(cbuffer2, cFormat) Dpoints(2,4)-Dpoints(2,3)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n end if\n ! Line segment\n if (dheight2 /= 0.0_DP) then\n write(cbuffer1, cFormat) Dpoints(1,4)\n write(cbuffer2, cFormat) Dpoints(2,4)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,5)-Dpoints(1,4)\n write(cbuffer2, cFormat) Dpoints(2,5)-Dpoints(2,4)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n end if\n ! Circular segment\n write(cbuffer1, cFormat) dx1\n write(cbuffer2, cFormat) -dy1\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! midpoint\n write(cbuffer1, cFormat) dradius1\n write(cbuffer2, cFormat) 0.0_DP\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! radius1\n write(cbuffer1, cFormat) pi\n write(cbuffer2, cFormat) pi-dangle1\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! angle1\n\n ! Line segment\n write(cbuffer1, cFormat) Dpoints(1,6)\n write(cbuffer2, cFormat) Dpoints(2,6)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,7)-Dpoints(1,6)\n write(cbuffer2, cFormat) Dpoints(2,7)-Dpoints(2,6)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n\n ! Outlet chamber?\n if (dwidth3 > 0.0_DP) then\n ! Line segments\n write(cbuffer1, cFormat) Dpoints(1,7)\n write(cbuffer2, cFormat) Dpoints(2,7)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,8)-Dpoints(1,7)\n write(cbuffer2, cFormat) Dpoints(2,8)-Dpoints(2,7)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n ! Line segments\n write(cbuffer1, cFormat) Dpoints(1,8)\n write(cbuffer2, cFormat) Dpoints(2,8)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,9)-Dpoints(1,8)\n write(cbuffer2, cFormat) Dpoints(2,9)-Dpoints(2,8)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n ! Line segments\n write(cbuffer1, cFormat) Dpoints(1,9)\n write(cbuffer2, cFormat) Dpoints(2,9)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,10)-Dpoints(1,9)\n write(cbuffer2, cFormat) Dpoints(2,10)-Dpoints(2,9)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n ! Line segments\n write(cbuffer1, cFormat) Dpoints(1,10)\n write(cbuffer2, cFormat) Dpoints(2,10)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,11)-Dpoints(1,10)\n write(cbuffer2, cFormat) Dpoints(2,11)-Dpoints(2,10)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n ! Line segments\n write(cbuffer1, cFormat) Dpoints(1,11)\n write(cbuffer2, cFormat) Dpoints(2,11)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,12)-Dpoints(1,11)\n write(cbuffer2, cFormat) Dpoints(2,12)-Dpoints(2,11)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n else\n ! Line segments\n write(cbuffer1, cFormat) Dpoints(1,7)\n write(cbuffer2, cFormat) Dpoints(2,7)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,12)-Dpoints(1,7)\n write(cbuffer2, cFormat) Dpoints(2,12)-Dpoints(2,7)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n end if\n ! Line segments\n write(cbuffer1, cFormat) Dpoints(1,12)\n write(cbuffer2, cFormat) Dpoints(2,12)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,13)-Dpoints(1,12)\n write(cbuffer2, cFormat) Dpoints(2,13)-Dpoints(2,12)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n ! Circular segment\n write(cbuffer1, cFormat) dx1\n write(cbuffer2, cFormat) dy1\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! midpoint\n write(cbuffer1, cFormat) dradius1\n write(cbuffer2, cFormat) 0.0_DP\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! radius1\n write(cbuffer1, cFormat) pi+dangle1\n write(cbuffer2, cFormat) pi\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! angle1\n ! Line segment\n if (dheight2 /= 0.0_DP) then\n write(cbuffer1, cFormat) Dpoints(1,14)\n write(cbuffer2, cFormat) Dpoints(2,14)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,15)-Dpoints(1,14)\n write(cbuffer2, cFormat) Dpoints(2,15)-Dpoints(2,14)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n end if\n ! Line segment\n if (dwidth2 /= 0.0_DP) then\n write(cbuffer1, cFormat) Dpoints(1,15)\n write(cbuffer2, cFormat) Dpoints(2,15)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,16)-Dpoints(1,15)\n write(cbuffer2, cFormat) Dpoints(2,16)-Dpoints(2,15)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n end if\n ! Line segment\n if (dheight1 /= 0.0_DP) then\n write(cbuffer1, cFormat) Dpoints(1,16)\n write(cbuffer2, cFormat) Dpoints(2,16)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,17)-Dpoints(1,16)\n write(cbuffer2, cFormat) Dpoints(2,17)-Dpoints(2,16)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n end if\n ! Line segment\n if (dwidth1 /= 0.0_DP) then\n write(cbuffer1, cFormat) Dpoints(1,17)\n write(cbuffer2, cFormat) Dpoints(2,17)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,18)-Dpoints(1,17)\n write(cbuffer2, cFormat) Dpoints(2,18)-Dpoints(2,17)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n end if\n\n ! left boundary inlet chamber\n if (dheight0 > 0.0_DP .and. dradius0 < dheight0) then\n ! Line segment\n write(cbuffer1, cFormat) Dpoints(1,18)\n write(cbuffer2, cFormat) Dpoints(2,18)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,19)-Dpoints(1,18)\n write(cbuffer2, cFormat) Dpoints(2,19)-Dpoints(2,18)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n ! Line segment\n write(cbuffer1, cFormat) Dpoints(1,19)\n write(cbuffer2, cFormat) Dpoints(2,19)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,20)-Dpoints(1,19)\n write(cbuffer2, cFormat) Dpoints(2,20)-Dpoints(2,19)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n ! Line segment\n write(cbuffer1, cFormat) Dpoints(1,20)\n write(cbuffer2, cFormat) Dpoints(2,20)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,21)-Dpoints(1,20)\n write(cbuffer2, cFormat) Dpoints(2,21)-Dpoints(2,20)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n ! Line segment\n write(cbuffer1, cFormat) Dpoints(1,21)\n write(cbuffer2, cFormat) Dpoints(2,21)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,22)-Dpoints(1,21)\n write(cbuffer2, cFormat) Dpoints(2,22)-Dpoints(2,21)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n ! Line segment\n write(cbuffer1, cFormat) Dpoints(1,22)\n write(cbuffer2, cFormat) Dpoints(2,22)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,1)-Dpoints(1,22)\n write(cbuffer2, cFormat) Dpoints(2,1)-Dpoints(2,22)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n elseif (dradius0 >= dheight0) then\n ! Line segment\n write(cbuffer1, cFormat) Dpoints(1,18)\n write(cbuffer2, cFormat) Dpoints(2,18)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,1)-Dpoints(1,18)\n write(cbuffer2, cFormat) Dpoints(2,1)-Dpoints(2,18)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n else\n ! Line segment\n write(cbuffer1, cFormat) Dpoints(1,18)\n write(cbuffer2, cFormat) Dpoints(2,18)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,19)-Dpoints(1,18)\n write(cbuffer2, cFormat) Dpoints(2,19)-Dpoints(2,18)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n ! Line segment\n write(cbuffer1, cFormat) Dpoints(1,19)\n write(cbuffer2, cFormat) Dpoints(2,19)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,20)-Dpoints(1,19)\n write(cbuffer2, cFormat) Dpoints(2,20)-Dpoints(2,19)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n ! Line segment\n write(cbuffer1, cFormat) Dpoints(1,20)\n write(cbuffer2, cFormat) Dpoints(2,20)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,1)-Dpoints(1,20)\n write(cbuffer2, cFormat) Dpoints(2,1)-Dpoints(2,20)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n end if\n\n close(100)\n\n end subroutine genPRM_xy\n\n !*****************************************************************************\n\n subroutine genPRM_rz\n\n open(unit=100, file=trim(adjustl(coutputfile))//'.prm')\n\n write(100,'(A)') 'NBCT'\n write(100,'(A)') '1'\n write(100,'(A)') 'IBCT'\n write(100,'(A)') '1 '\n write(100,'(A)') 'NCOMP'\n\n write(cbuffer1, fmt='(I4)') 4 + merge(1,0,dheight1 /= 0.0_DP)&\n + merge(1,0,dheight2 /= 0.0_DP)&\n + merge(1,0,dwidth1 /= 0.0_DP)&\n + merge(1,0,dwidth2 /= 0.0_DP)&\n + merge(4,1,dwidth3 > 0.0_DP)&\n + merge(3,merge(1,2,dradius0 >= dheight0),&\n dheight0 > 0.0_DP .and. dradius0 < dheight0)\n\n write(100,'(A)') trim(adjustl(cbuffer1))\n write(100,'(A)') 'ITYP NSPLINE NPAR'\n if (dwidth1 /= 0.0_DP) write(100,'(A)') '1 1 2 '\n if (dheight1 /= 0.0_DP) write(100,'(A)') '1 1 2 '\n if (dwidth2 /= 0.0_DP) write(100,'(A)') '1 1 2 '\n if (dheight2 /= 0.0_DP) write(100,'(A)') '1 1 2 '\n write(100,'(A)') '2 1 3 ' ! lower circle segment\n\n write(100,'(A)') '1 1 2 ' ! lower converging chamber\n if (dwidth3 > 0.0_DP) then\n ! Note that we do not check the special case that\n ! dwidth3 equals the height of the exit throat\n write(100,'(A)') '1 1 2 '\n write(100,'(A)') '1 1 2 ' ! lower boundary outlet chamber\n write(100,'(A)') '1 1 2 ' ! right boundary outlet chamber\n write(100,'(A)') '1 1 2 ' ! upper boundary outlet chamber\n else\n write(100,'(A)') '1 1 2 ' ! outlet boundary without chamber\n end if\n write(100,'(A)') '1 1 2 ' ! upper segment (converging chamber)\n write(100,'(A)') '1 1 2 ' ! upper segment (circle segment\n write(100,'(A)') '1 1 2 ' ! upper segment (inlet chamber)\n\n ! left boundary inlet chamber\n if (dheight0 > 0.0_DP .and. dradius0 < dheight0) then\n write(100,'(A)') '1 1 2 '\n write(100,'(A)') '1 1 2 '\n write(100,'(A)') '1 1 2 '\n else if (dradius0 >= dheight0) then\n write(100,'(A)') '1 1 2 '\n else\n write(100,'(A)') '1 1 2 '\n write(100,'(A)') '1 1 2 '\n end if\n\n write(100,'(A)') 'PARAMETERS'\n ! Line segment\n if (dwidth1 /= 0.0_DP) then\n write(cbuffer1, cFormat) Dpoints(1,1)\n write(cbuffer2, cFormat) Dpoints(2,1)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,2)-Dpoints(1,1)\n write(cbuffer2, cFormat) Dpoints(2,2)-Dpoints(2,1)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n end if\n ! Line segment\n if (dheight1 /= 0.0_DP) then\n write(cbuffer1, cFormat) Dpoints(1,2)\n write(cbuffer2, cFormat) Dpoints(2,2)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,3)-Dpoints(1,2)\n write(cbuffer2, cFormat) Dpoints(2,3)-Dpoints(2,2)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n end if\n ! Line segment\n if (dwidth2 /= 0.0_DP) then\n write(cbuffer1, cFormat) Dpoints(1,3)\n write(cbuffer2, cFormat) Dpoints(2,3)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,4)-Dpoints(1,3)\n write(cbuffer2, cFormat) Dpoints(2,4)-Dpoints(2,3)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n end if\n ! Line segment\n if (dheight2 /= 0.0_DP) then\n write(cbuffer1, cFormat) Dpoints(1,4)\n write(cbuffer2, cFormat) Dpoints(2,4)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,5)-Dpoints(1,4)\n write(cbuffer2, cFormat) Dpoints(2,5)-Dpoints(2,4)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n end if\n ! Circular segment\n write(cbuffer1, cFormat) dx1\n write(cbuffer2, cFormat) -dy1\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! midpoint\n write(cbuffer1, cFormat) dradius1\n write(cbuffer2, cFormat) 0.0_DP\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! radius1\n write(cbuffer1, cFormat) pi\n write(cbuffer2, cFormat) pi-dangle1\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! angle1\n\n ! Line segment\n write(cbuffer1, cFormat) Dpoints(1,6)\n write(cbuffer2, cFormat) Dpoints(2,6)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,7)-Dpoints(1,6)\n write(cbuffer2, cFormat) Dpoints(2,7)-Dpoints(2,6)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n\n ! Outlet chamber?\n if (dwidth3 > 0.0_DP) then\n ! Line segments\n write(cbuffer1, cFormat) Dpoints(1,7)\n write(cbuffer2, cFormat) Dpoints(2,7)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,8)-Dpoints(1,7)\n write(cbuffer2, cFormat) Dpoints(2,8)-Dpoints(2,7)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n ! Line segments\n write(cbuffer1, cFormat) Dpoints(1,8)\n write(cbuffer2, cFormat) Dpoints(2,8)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,9)-Dpoints(1,8)\n write(cbuffer2, cFormat) Dpoints(2,9)-Dpoints(2,8)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n ! Line segments\n write(cbuffer1, cFormat) Dpoints(1,9)\n write(cbuffer2, cFormat) Dpoints(2,9)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,10)-Dpoints(1,9)\n write(cbuffer2, cFormat) Dpoints(2,10)-Dpoints(2,9)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n ! Line segments\n write(cbuffer1, cFormat) Dpoints(1,10)\n write(cbuffer2, cFormat) Dpoints(2,10)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,12)-Dpoints(1,10)\n write(cbuffer2, cFormat) Dpoints(2,12)-Dpoints(2,10)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n else\n ! Line segments\n write(cbuffer1, cFormat) Dpoints(1,7)\n write(cbuffer2, cFormat) Dpoints(2,7)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,12)-Dpoints(1,7)\n write(cbuffer2, cFormat) Dpoints(2,12)-Dpoints(2,7)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n end if\n\n ! Line segments\n write(cbuffer1, cFormat) Dpoints(1,12)\n write(cbuffer2, cFormat) Dpoints(2,12)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,13)-Dpoints(1,12)\n write(cbuffer2, cFormat) Dpoints(2,13)-Dpoints(2,12)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n ! Line segments\n write(cbuffer1, cFormat) Dpoints(1,13)\n write(cbuffer2, cFormat) Dpoints(2,13)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,14)-Dpoints(1,13)\n write(cbuffer2, cFormat) Dpoints(2,14)-Dpoints(2,13)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n ! Line segments\n write(cbuffer1, cFormat) Dpoints(1,14)\n write(cbuffer2, cFormat) Dpoints(2,14)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,18)-Dpoints(1,14)\n write(cbuffer2, cFormat) Dpoints(2,18)-Dpoints(2,14)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n\n ! left boundary inlet chamber\n if (dheight0 > 0.0_DP .and. dradius0 < dheight0) then\n ! Line segment\n write(cbuffer1, cFormat) Dpoints(1,18)\n write(cbuffer2, cFormat) 0.0_DP\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,21)-Dpoints(1,18)\n write(cbuffer2, cFormat) Dpoints(2,21)-Dpoints(2,18)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n ! Line segment\n write(cbuffer1, cFormat) Dpoints(1,21)\n write(cbuffer2, cFormat) Dpoints(2,21)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,22)-Dpoints(1,21)\n write(cbuffer2, cFormat) Dpoints(2,22)-Dpoints(2,21)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n ! Line segment\n write(cbuffer1, cFormat) Dpoints(1,22)\n write(cbuffer2, cFormat) Dpoints(2,22)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,1)-Dpoints(1,22)\n write(cbuffer2, cFormat) Dpoints(2,1)-Dpoints(2,22)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n elseif (dradius0 >= dheight0) then\n ! Line segment\n write(cbuffer1, cFormat) Dpoints(1,18)\n write(cbuffer2, cFormat) Dpoints(2,18)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,1)-Dpoints(1,18)\n write(cbuffer2, cFormat) Dpoints(2,1)-Dpoints(2,18)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n else\n ! Line segment\n write(cbuffer1, cFormat) Dpoints(1,18)\n write(cbuffer2, cFormat) Dpoints(2,18)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,22)-Dpoints(1,18)\n write(cbuffer2, cFormat) Dpoints(2,22)-Dpoints(2,18)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n ! Line segment\n write(cbuffer1, cFormat) Dpoints(1,22)\n write(cbuffer2, cFormat) Dpoints(2,22)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! coordinate\n write(cbuffer1, cFormat) Dpoints(1,1)-Dpoints(1,22)\n write(cbuffer2, cFormat) Dpoints(2,1)-Dpoints(2,22)\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2)) ! direction\n end if\n\n close(100)\n\n end subroutine genPRM_rz\n\n !*****************************************************************************\n\n subroutine genPSLR_xy\n\n ! Initialize the number of points\n npoints = 0\n brewrite = .false.\n\n1 open(unit=100, file=trim(adjustl(coutputfile))//'.poly', form='formatted')\n\n ! Write file header\n write(100, '(A)') \"# \"//trim(adjustl(coutputfile))//'.poly'\n write(100, '(A)') \"#\"\n write(100, '(A)') \"# Poly file generated by gridgenlaval2d.\"\n write(100, '(A)') \"#\"\n\n !-----------------------------------------------------------------------------\n\n ! Write number of points\n write(100, '(A)') \"# Number of points, 2D, one attribute, boundary markers\"\n write(cbuffer1, '(I10)') npoints\n write(100, '(A)') trim(adjustl(cbuffer1))//' 2 1 1'\n\n ! Initialize the number of points\n npoints = 0; npar = 0\n\n ! Write vertex coordinates\n do ipoint = 1, ncoords\n\n ! Check if points coincide\n if (sqrt((Dpoints(1,ipoint)-Dpoints(1,mod(ipoint,ncoords)+1))**2 +&\n (Dpoints(2,ipoint)-Dpoints(2,mod(ipoint,ncoords)+1))**2) <= 1e-12) cycle\n\n ! Increase number of points by one\n npoints = npoints+1\n\n ! Increase number of boundary parameter\n npar = npar+1\n\n ! Fill buffers\n write(cbuffer1, '(I10)') npoints\n write(cbuffer2, cFormat) Dpoints(1,ipoint)\n write(cbuffer3, cFormat) Dpoints(2,ipoint)\n write(cbuffer4, cFormat) real(npar-1,DP)\n\n ! Write line to file\n write(100, '(A)') trim(adjustl(cbuffer1))//' '//&\n trim(adjustl(cbuffer2))//' '//&\n trim(adjustl(cbuffer3))//' '//&\n trim(adjustl(cbuffer4))//' 1'\n\n ! Write extra points between two regular points with user-defined\n ! average distance; note that we must distinguish between points\n ! on a straight line and those on a circular segment\n select case(ipoint)\n case(1:4,6:12,14:ncoords)\n ! Compute line segment length\n dsegmentlen = sqrt((Dpoints(1,mod(ipoint,ncoords)+1)-Dpoints(1,ipoint))**2+&\n (Dpoints(2,mod(ipoint,ncoords)+1)-Dpoints(2,ipoint))**2)\n\n ! Compute number of auxiliary segments\n select case(ipoint)\n case(1:4,14:ncoords)\n nsubsegments = nint(dsegmentlen/ddistin)\n case (6,12)\n nsubsegments = nint(dsegmentlen/ddistdiv)\n case default\n nsubsegments = nint(dsegmentlen/ddistout)\n end select\n\n ! Write vertex coordinates of auxiliary points\n do isubpoint = 1, nsubsegments-1\n ! Increase number of points by one\n npoints = npoints+1\n\n ! Compute relative position of the auxiliary point on\n ! the line segment between the points [ipoint,ipoint+1]\n domega = real(isubpoint,DP)/real(nsubsegments,DP)\n\n ! Fill buffer\n write(cbuffer1, '(I10)') npoints\n write(cbuffer2, cFormat) Dpoints(1,ipoint) +&\n domega*(Dpoints(1,mod(ipoint,ncoords)+1)-Dpoints(1,ipoint))\n write(cbuffer3, cFormat) Dpoints(2,ipoint) +&\n domega*(Dpoints(2,mod(ipoint,ncoords)+1)-Dpoints(2,ipoint))\n write(cbuffer4, cFormat) real(npar-1,DP)+domega\n\n ! Write line to file\n write(100, '(A)') trim(adjustl(cbuffer1))//' '//&\n trim(adjustl(cbuffer2))//' '//&\n trim(adjustl(cbuffer3))//' '//&\n trim(adjustl(cbuffer4))//' 1'\n end do\n\n case(5)\n ! Compute circular segment length\n dsegmentlen = dradius1*dangle1\n\n ! Compute number of auxiliary segments\n nsubsegments = nint(dsegmentlen/ddistcon)\n\n ! Write vertex coordinates of auxiliary points\n do isubpoint = 1, nsubsegments-1\n ! Increase number of points by one\n npoints = npoints+1\n\n ! Compute relative position of the auxiliary point on\n ! the circular segment between the points ipoint and ipoint+1\n domega = real(isubpoint,DP)/real(nsubsegments,DP)\n\n ! Fill buffer\n write(cbuffer1, '(I10)') npoints\n write(cbuffer2, cFormat) dx1+dradius1*cos(pi-dangle1*domega)\n write(cbuffer3, cFormat) -dy1+dradius1*sin(pi-dangle1*domega)\n write(cbuffer4, cFormat) real(npar-1,DP)+domega\n\n ! Write line to file\n write(100, '(A)') trim(adjustl(cbuffer1))//' '//&\n trim(adjustl(cbuffer2))//' '//&\n trim(adjustl(cbuffer3))//' '//&\n trim(adjustl(cbuffer4))//' 1'\n end do\n\n case(13)\n ! Compute circular segment length\n dsegmentlen = dradius1*dangle1\n\n ! Compute number of auxiliary segments\n nsubsegments = nint(dsegmentlen/ddistcon)\n\n ! Write vertex coordinates of auxiliary points\n do isubpoint = nsubsegments-1, 1, -1\n ! Increase number of points by one\n npoints = npoints+1\n\n ! Compute relative position of the auxiliary point on\n ! the circular segment between the points ipoint and ipoint+1\n domega = real(isubpoint,DP)/real(nsubsegments,DP)\n\n ! Fill buffer\n write(cbuffer1, '(I10)') npoints\n write(cbuffer2, cFormat) dx1+dradius1*cos(pi-dangle1*domega)\n write(cbuffer3, cFormat) dy1-dradius1*sin(pi-dangle1*domega)\n write(cbuffer4, cFormat) real(npar-1,DP)+(1.0_DP-domega)\n\n ! Write line to file\n write(100, '(A)') trim(adjustl(cbuffer1))//' '//&\n trim(adjustl(cbuffer2))//' '//&\n trim(adjustl(cbuffer3))//' '//&\n trim(adjustl(cbuffer4))//' 1'\n end do\n end select\n end do\n\n ! Write number of segments\n write(100, '(A)') \"# Number of segments, boundary markers\"\n write(cbuffer1, '(I10)') npoints\n write(100, '(A)') trim(adjustl(cbuffer1))//' 1'\n\n ! Write segments\n do ipoint = 1, npoints\n\n ! Fill buffers\n write(cbuffer1, '(I10)') ipoint\n write(cbuffer2, '(I10)') ipoint\n write(cbuffer3, '(I10)') mod(ipoint,npoints)+1\n\n write(100, '(A)') trim(adjustl(cbuffer1))//' '//&\n trim(adjustl(cbuffer2))//' '//&\n trim(adjustl(cbuffer3))//' 1'\n end do\n\n ! Write number of holes\n write(100, '(A)') \"# Number of holes\"\n write(100, '(A)') \"0\"\n\n ! Write number of regional attributes and/or area constraints\n write(100, '(A)') \"# Number of regional attributes and/or area constraints\"\n write(100, '(A)') \"0\"\n\n close(100)\n\n ! Now, the number of total points is known and needs to be updated\n if ((npoints /= ncoords) .and. .not.brewrite) then\n brewrite = .true.\n goto 1\n end if\n\n end subroutine genPSLR_xy\n\n !*****************************************************************************\n\n subroutine genPSLR_rz\n\n ! Initialize the number of points\n npoints = 0\n brewrite = .false.\n\n1 open(unit=100, file=trim(adjustl(coutputfile))//'.poly', form='formatted')\n\n ! Write file header\n write(100, '(A)') \"# \"//trim(adjustl(coutputfile))//'.poly'\n write(100, '(A)') \"#\"\n write(100, '(A)') \"# Poly file generated by gridgenlaval2d.\"\n write(100, '(A)') \"#\"\n\n !-----------------------------------------------------------------------------\n\n ! Write number of points\n write(100, '(A)') \"# Number of points, 2D, one attribute, boundary markers\"\n write(cbuffer1, '(I10)') npoints\n write(100, '(A)') trim(adjustl(cbuffer1))//' 2 1 1'\n\n ! Initialize the number of points\n npoints = 0; npar = 0\n\n ! Write vertex coordinates\n do ipoint = 1, ncoords\n\n ! Check if points coincide\n if (sqrt((Dpoints(1,ipoint)-Dpoints(1,mod(ipoint,ncoords)+1))**2 +&\n (Dpoints(2,ipoint)-Dpoints(2,mod(ipoint,ncoords)+1))**2) <= 1e-12) cycle\n\n ! Increase number of points by one\n npoints = npoints+1\n\n ! Increase number of boundary parameter\n npar = npar+1\n\n ! Fill buffers\n write(cbuffer1, '(I10)') npoints\n write(cbuffer2, cFormat) Dpoints(1,ipoint)\n write(cbuffer3, cFormat) Dpoints(2,ipoint)\n write(cbuffer4, cFormat) real(npar-1,DP)\n\n ! Write line to file\n write(100, '(A)') trim(adjustl(cbuffer1))//' '//&\n trim(adjustl(cbuffer2))//' '//&\n trim(adjustl(cbuffer3))//' '//&\n trim(adjustl(cbuffer4))//' 1'\n\n ! Write extra points between two regular points with user-defined\n ! average distance; note that we must distinguish between points\n ! on a straight line and those on a circular segment\n select case(ipoint)\n case(1:4,6:10)\n ! Compute line segment length\n dsegmentlen = sqrt((Dpoints(1,mod(ipoint,ncoords)+1)-Dpoints(1,ipoint))**2+&\n (Dpoints(2,mod(ipoint,ncoords)+1)-Dpoints(2,ipoint))**2)\n\n ! Compute number of auxiliary segments\n select case(ipoint)\n case(1:4)\n nsubsegments = nint(dsegmentlen/ddistin)\n case (6)\n nsubsegments = nint(dsegmentlen/ddistdiv)\n case default\n nsubsegments = nint(dsegmentlen/ddistout)\n end select\n\n ! Write vertex coordinates of auxiliary points\n do isubpoint = 1, nsubsegments-1\n ! Increase number of points by one\n npoints = npoints+1\n\n ! Compute relative position of the auxiliary point on\n ! the line segment between the points [ipoint,ipoint+1]\n domega = real(isubpoint,DP)/real(nsubsegments,DP)\n\n ! Fill buffer\n write(cbuffer1, '(I10)') npoints\n write(cbuffer2, cFormat) Dpoints(1,ipoint) +&\n domega*(Dpoints(1,mod(ipoint,ncoords)+1)-Dpoints(1,ipoint))\n write(cbuffer3, cFormat) Dpoints(2,ipoint) +&\n domega*(Dpoints(2,mod(ipoint,ncoords)+1)-Dpoints(2,ipoint))\n write(cbuffer4, cFormat) real(npar-1,DP)+domega\n\n ! Write line to file\n write(100, '(A)') trim(adjustl(cbuffer1))//' '//&\n trim(adjustl(cbuffer2))//' '//&\n trim(adjustl(cbuffer3))//' '//&\n trim(adjustl(cbuffer4))//' 1'\n end do\n\n case(5)\n ! Compute circular segment length\n dsegmentlen = dradius1*dangle1\n\n ! Compute number of auxiliary segments\n nsubsegments = nint(dsegmentlen/ddistcon)\n\n ! Write vertex coordinates of auxiliary points\n do isubpoint = 1, nsubsegments-1\n ! Increase number of points by one\n npoints = npoints+1\n\n ! Compute relative position of the auxiliary point on\n ! the circular segment between the points ipoint and ipoint+1\n domega = real(isubpoint,DP)/real(nsubsegments,DP)\n\n ! Fill buffer\n write(cbuffer1, '(I10)') npoints\n write(cbuffer2, cFormat) dx1+dradius1*cos(pi-dangle1*domega)\n write(cbuffer3, cFormat) -dy1+dradius1*sin(pi-dangle1*domega)\n write(cbuffer4, cFormat) real(npar-1,DP)+domega\n\n ! Write line to file\n write(100, '(A)') trim(adjustl(cbuffer1))//' '//&\n trim(adjustl(cbuffer2))//' '//&\n trim(adjustl(cbuffer3))//' '//&\n trim(adjustl(cbuffer4))//' 1'\n end do\n end select\n end do\n\n ! Write number of segments\n write(100, '(A)') \"# Number of segments, boundary markers\"\n write(cbuffer1, '(I10)') npoints\n write(100, '(A)') trim(adjustl(cbuffer1))//' 1'\n\n ! Write segments\n do ipoint = 1, npoints\n\n ! Fill buffers\n write(cbuffer1, '(I10)') ipoint\n write(cbuffer2, '(I10)') ipoint\n write(cbuffer3, '(I10)') mod(ipoint,npoints)+1\n\n write(100, '(A)') trim(adjustl(cbuffer1))//' '//&\n trim(adjustl(cbuffer2))//' '//&\n trim(adjustl(cbuffer3))//' 1'\n end do\n\n ! Write number of holes\n write(100, '(A)') \"# Number of holes\"\n write(100, '(A)') \"0\"\n\n ! Write number of regional attributes and/or area constraints\n write(100, '(A)') \"# Number of regional attributes and/or area constraints\"\n write(100, '(A)') \"0\"\n\n close(100)\n\n ! Now, the number of total points is known and needs to be updated\n if ((npoints /= ncoords) .and. .not.brewrite) then\n brewrite = .true.\n goto 1\n end if\n\n end subroutine genPSLR_rz\n\n !*****************************************************************************\n\n subroutine genTRI\n\n open(unit=100, file=trim(adjustl(coutputfile))//'.tri')\n\n write(100,'(A)') 'Coarse mesh 2D'\n write(100,'(A)') 'Generated by gridgencirc2d'\n\n write(cbuffer1, '(I10)') nel\n write(cbuffer2, '(I10)') nvt\n\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//&\n trim(adjustl(cbuffer2))//' 0 3 1 NEL NVT NMT NVE NBCT'\n\n !---------------------------------------------------------------------------\n write(100,'(A)') 'DCORVG'\n !---------------------------------------------------------------------------\n\n !---------------------------------------------------------------------------\n ! Copy/convert coordinates from external triangulation\n !---------------------------------------------------------------------------\n\n open(unit=200, file=trim(adjustl(coutputfile))//'.1.node')\n read(200, fmt=*) nvt\n\n ! Read node file line by line and convert coordinates\n do ivt = 1, nvt\n read(200, fmt=*) i, dx, dy, dpar, ibdc\n\n if (ibdc == 0) then\n ! Write inner vertex\n write(cbuffer1, cFormat) dx\n write(cbuffer2, cFormat) dy\n else\n ! Write boundary parametrization\n write(cbuffer1, cFormat) dpar\n write(cbuffer2, cFormat) 0.0_DP\n end if\n\n ! Write line to file\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2))\n end do\n\n close(200)\n\n !---------------------------------------------------------------------------\n write(100,'(A)') 'KVERT'\n !---------------------------------------------------------------------------\n\n !---------------------------------------------------------------------------\n ! Copy elements of inner region from external triangulation\n !---------------------------------------------------------------------------\n\n open(unit=200, file=trim(adjustl(coutputfile))//'.1.ele')\n read(200, fmt=*) nel\n\n ! Read element file line by line and convert coordinates\n do iel = 1, nel\n read(200, fmt=*) i, i1, i2, i3\n\n write(cbuffer1, '(I10)') i1\n write(cbuffer2, '(I10)') i2\n write(cbuffer3, '(I10)') i3\n\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//&\n trim(adjustl(cbuffer2))//' '//&\n trim(adjustl(cbuffer3))\n end do\n\n close(200)\n\n !---------------------------------------------------------------------------\n write(100,'(A)') 'KNPR'\n !---------------------------------------------------------------------------\n\n ! Write nodal property for boundary vertices\n do ipoint = 1, npoints\n write(100,'(A)') '1'\n end do\n\n ! Write nodal property for boundary vertices\n do ipoint = npoints+1,nvt\n write(100,'(A)') '0'\n end do\n\n !---------------------------------------------------------------------------\n write(100,'(A)') 'KMM'\n !---------------------------------------------------------------------------\n\n write(cbuffer1, '(I10)') 1\n write(cbuffer2, '(I10)') npoints\n\n write(100,'(A)') trim(adjustl(cbuffer1))//' '//trim(adjustl(cbuffer2))\n\n close(100)\n\n end subroutine genTRI\n \nend program gridgenlaval2d\n", "meta": {"hexsha": "4f7fb2721f8929a30597f5749fa7488f1fa5c184", "size": 57600, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "applications/flagship/gridgen/src/gridgenlaval2d.f90", "max_stars_repo_name": "trmcnealy/Featflow2", "max_stars_repo_head_hexsha": "4af17507bc2d80396bf8ea85c9e30e9e4d2383df", "max_stars_repo_licenses": ["Intel", "Unlicense"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2017-08-02T11:51:34.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-10T14:14:21.000Z", "max_issues_repo_path": "applications/flagship/gridgen/src/gridgenlaval2d.f90", "max_issues_repo_name": "tudo-math-ls3/FeatFlow2", "max_issues_repo_head_hexsha": "56159aff28f161aca513bc7c5e2014a2d11ff1b3", "max_issues_repo_licenses": ["Intel", "Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "applications/flagship/gridgen/src/gridgenlaval2d.f90", "max_forks_repo_name": "tudo-math-ls3/FeatFlow2", "max_forks_repo_head_hexsha": "56159aff28f161aca513bc7c5e2014a2d11ff1b3", "max_forks_repo_licenses": ["Intel", "Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.9168399168, "max_line_length": 103, "alphanum_fraction": 0.5524305556, "num_tokens": 18472, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473713594991, "lm_q2_score": 0.7490872187162396, "lm_q1q2_score": 0.6534642661661099}} {"text": "Program G1e11 ! Guia 1 ejercicio 11\n\n! Programa del Ejercicio 11 de la Guia1\n! Metodos Numerico 2022\n!\n!Problema 11: Escriba un programa, que utilizando una subrutina, multiplique un\n! vector de N elementos, por una matriz de N \u00d7 N.\n!El programa debe preguntar el valor de N y luego definir los arreglos, y darle\n! valores iniciales tal que:\n! i. la matriz sea triangular superior, con todos sus elementos igual a 1,\n! excepto los de la diagonal que toman valor 3,\n! ii. el vector tendra todos sus elementos pares igual a 2,\n! y los impares igual a 3.\n!No utilice DO para las inicializar el vector, ni DO anidados para inicializar\n! la matriz.\n!\n!\n! version 1.0\n! 4 de abril, 2022\n!\n! Version original de Osvaldo Moreschi\n! Adecuaci\u00f3n de Edgardo Bonzi\n! edgardobonzi@gmail.com\n\nUSE iso_fortran_env\n\nimplicit none\n\ninteger :: ii, jj, dim ! Notar que para fortran dim = DIM\ninteger, parameter :: rl = real128\n\ninteger, allocatable, dimension(:,:) :: matA, matB, matC, matD\ninteger, allocatable, dimension(:) :: vecE, vecF, vecG\n\nreal(rl) :: x ! Ser\u00e1 utilizados al final del programa\nreal(rl), dimension(5) :: w ! Ser\u00e1 utilizados al final del programa\n\nwrite(*,*) 'Ingrese la dimensi\u00f3n de los arreglos :'\nread(*,*) dim\n\nwrite (*, 100)\nwrite (*,*) \"Dimension dim = \", dim\nwrite (*, 99)\n\n! ====================================================\n! Redimensionamos las matrices y los vectores\n! ====================================================\n\nallocate (matA(dim, dim), matB(dim, 1), matC(dim,1), &\n matD(dim, dim), vecE(dim*dim), vecF(dim), vecG(dim))\n\n! ====================================================\n! Jugamos llenando Vector y Matriz Unidimensional\n! ====================================================\n\n! Llenamos con 3 y 2 a un vector de dimension dim, [dim] vecG\n! ***********************************************************\n!\nwrite (*, 100)\nvecG(1: dim: 2) = 3 ! Impares: Comienzo en 1, salto de a 2 y lleno con 3\nvecG(2: dim: 2) = 2 ! Pares: Comienzo en 2, salto de a 2 y lleno con 2\nwrite (*, 99)\n\nwrite (*, 100)\nwrite (*,*) \"Vector unidimensional [dim], vecG = \"\nwrite (*,*) vecG\nwrite (*, 99)\n\n\n\n! Llenamos con 3 y 2 a una matriz unidimensional [dim, 1] matB\n! *************************************************************\n!\nmatB(1:dim: 2, 1) = 3 ! Comienzo en 1 y lleno con 3\nmatB(2:dim: 2, 1) = 2 ! Comienzo en 2 y salto de 2\n\nwrite (*, 100)\nwrite (*,*) \"Matriz unidimensional [dim, 1], matB = \"\nwrite (*,*) matB\nwrite (*, 99)\n\n! Probamos distintas formas de escribr matB\nwrite (*, 100)\ndo ii = 1, dim\n write (*,*) matB(ii, :)\nend do\nwrite (*, 99)\n\nwrite (*, 100)\n write (*,*) matB(:, 1)\nwrite (*, 99)\n\n\n! Otra manera de hacer la asignaci\u00f3n. ( Array Constructors )\n! Notar que 'vecF' es un arreglo unidimensional\nvecF = (/ ( 2 + mod(ii, 2), ii = 1, dim) /)\n\nwrite (*, 100)\nwrite (*,*) \"Matriz unidimensional [dim, 1], matF = \"\nwrite (*,*) vecF\nwrite (*, 99)\n\n! ====================================================\n! Ahora jugamos con la Matriz\n! ====================================================\n! la matriz sea triangular superior, con todos sus elementos igual a 1, excepto los de\n! la diagonal que toman valor 3,\n\n\n!matA(1:dim,1:dim) = 3 ! Comienzo en 1 y lleno con 3\nwrite (*, 100)\nwrite (*, *) \"Sea la matriz triangular superior\"\n! cargamos los datos en el vector vecE que es dim x dim\nvecE = (/ 3, (0, ii = 2, dim), &\n (( 1, ii = 1, jj - 1), 3, (0, ii = jj + 1, dim), jj = 2, dim) /)\n\nwrite (*,*) 'Vector unidimensional de [dim x dim], vecE ='\ndo ii = 0, dim-1\n write(*, *) vecE(dim * ii + 1: dim * ( ii + 1))\nend do\nwrite (*, 99)\n\nwrite (*, 100)\n ! se cambia el vector vecE a un arreglo dim x dim matD\nmatD = reshape ((vecE) ,(/ dim , dim /))\nwrite (*,*) 'Arreglo matD ='\nwrite (*,*) matD\nwrite (*, 99)\n\nwrite (*, 100)\ndo ii = 1, dim\n write (*,*) matD (ii, :)\nend do\nwrite(*, 99)\n! stop \"con todos sus elementos igual a 1, excepto los de la diagonal que toman valor 3\"\n! Otra manera de hacer la asignacion.\n\nmatA = 0\n\nforall (ii = 1: dim, jj = 2: dim, jj > ii) matA(ii, jj) = 1\nforall (ii = 1: dim) matA(ii, ii) = 3\n\nwrite (*,100)\nwrite (*,*) 'MatA(ii, jj) ='\nwrite(*, 99)\n\nwrite (*,100)\ndo ii = 1, dim\n write (*,*) matA(ii,:)\nend do\nwrite(*, 99)\n\nwrite (*,100)\nwrite (*,*) 'Arreglo matB ='\nwrite(*,*) matB\nwrite(*, 99)\n\nwrite (*,100)\nmatC = matA * matB\nwrite (*,*) 'vector matC = matA * matB :'\nwrite(*,*) matC\nwrite(*, 99)\n\nmatC = matmul(matA, matB)\nwrite (*, 100)\nwrite (*,*) 'matC = matmul(matA, matB)'\nwrite (*,*) 'Arreglo matC ='\nwrite(*,*) matC\nwrite (*, 99)\n\n\n\n x = 1.1_rl\n w = (/ 0.0_rl ,x, x-1.0_rl, 0.0_rl, -1.0_rl /)\nwrite (*, 100)\nwrite(*,*) \"Valores en w\"\nwrite(*,110) w\n ! v = matmul(a,c)\n\n ! write (*,*) ''\n\n ! write (*,*) 'matmul(a,c) =', v\n \n 99 Format(' ')\n100 Format('------------------------------------------------')\n110 Format(5(2X, F10.7))\n\nend program G1e11 ! Guia 1 ejercicio 11\n", "meta": {"hexsha": "37aa8ab79791e3de9788ccbfe08aaa9a73f0d68c", "size": 4952, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "G1e11/G1e11.f90", "max_stars_repo_name": "EdgardoBonzi/Fortran-Examples", "max_stars_repo_head_hexsha": "14795aa96e2499b1dfe248fdc59478566e476168", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "G1e11/G1e11.f90", "max_issues_repo_name": "EdgardoBonzi/Fortran-Examples", "max_issues_repo_head_hexsha": "14795aa96e2499b1dfe248fdc59478566e476168", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "G1e11/G1e11.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": 26.2010582011, "max_line_length": 88, "alphanum_fraction": 0.5551292407, "num_tokens": 1664, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7490872131147275, "lm_q2_score": 0.8723473763375644, "lm_q1q2_score": 0.6534642650086505}} {"text": "!Crown Copyright 2012 AWE.\n!\n! This file is part of CloverLeaf.\n!\n! CloverLeaf is free software: you can redistribute it and/or modify it under \n! the terms of the GNU General Public License as published by the \n! Free Software Foundation, either version 3 of the License, or (at your option) \n! any later version.\n!\n! CloverLeaf is distributed in the hope that it will be useful, but \n! WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or \n! FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more \n! details.\n!\n! You should have received a copy of the GNU General Public License along with \n! CloverLeaf. If not, see http://www.gnu.org/licenses/.\n\n!> @brief Fortran ideal gas kernel.\n!> @author Wayne Gaudin\n!> @details Calculates the pressure and sound speed for the mesh chunk using\n!> the ideal gas equation of state, with a fixed gamma of 1.4.\n\nMODULE ideal_gas_kernel_module\n\nCONTAINS\n\nSUBROUTINE ideal_gas_kernel(x_min,x_max,y_min,y_max, &\n density, &\n energy, &\n pressure, &\n soundspeed ) \n\n IMPLICIT NONE\n\n INTEGER :: x_min,x_max,y_min,y_max\n REAL(KIND=8), DIMENSION(x_min-2:x_max+2,y_min-2:y_max+2) :: density\n REAL(KIND=8), DIMENSION(x_min-2:x_max+2,y_min-2:y_max+2) :: energy\n REAL(KIND=8), DIMENSION(x_min-2:x_max+2,y_min-2:y_max+2) :: pressure\n REAL(KIND=8), DIMENSION(x_min-2:x_max+2,y_min-2:y_max+2) :: soundspeed\n\n INTEGER :: j,k\n\n REAL(KIND=8) :: sound_speed_squared,v,pressurebyenergy,pressurebyvolume\n\n DO k=y_min,y_max\n DO j=x_min,x_max\n v=1.0_8/density(j,k)\n pressure(j,k)=(1.4_8-1.0_8)*density(j,k)*energy(j,k)\n pressurebyenergy=(1.4_8-1.0_8)*density(j,k)\n pressurebyvolume=-density(j,k)*pressure(j,k)\n sound_speed_squared=v*v*(pressure(j,k)*pressurebyenergy-pressurebyvolume)\n soundspeed(j,k)=SQRT(sound_speed_squared)\n ENDDO\n ENDDO\n\nEND SUBROUTINE ideal_gas_kernel\n\nEND MODULE ideal_gas_kernel_module\n", "meta": {"hexsha": "b9a2cdcc17be1637e5f4b73be0c241462bbf426d", "size": 2199, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/integration/CloverLeaf_Serial/ideal_gas_kernel.f90", "max_stars_repo_name": "uwplse/stng", "max_stars_repo_head_hexsha": "ce12c2c079516df873382a5aa3c18c407833d130", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2017-03-07T00:14:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-09T00:59:22.000Z", "max_issues_repo_path": "tests/integration/CloverLeaf_Serial/ideal_gas_kernel.f90", "max_issues_repo_name": "uwplse/stng", "max_issues_repo_head_hexsha": "ce12c2c079516df873382a5aa3c18c407833d130", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2016-11-22T13:14:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-14T00:56:51.000Z", "max_forks_repo_path": "tests/integration/CloverLeaf_Serial/ideal_gas_kernel.f90", "max_forks_repo_name": "uwplse/stng", "max_forks_repo_head_hexsha": "ce12c2c079516df873382a5aa3c18c407833d130", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2016-11-07T13:38:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-04T12:13:31.000Z", "avg_line_length": 37.2711864407, "max_line_length": 99, "alphanum_fraction": 0.6425648022, "num_tokens": 569, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473713594992, "lm_q2_score": 0.7490872131147276, "lm_q1q2_score": 0.6534642612796456}} {"text": " Program dsyev_example\n\n! DSYEV Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_example_aux, Only: nagf_blas_damax_val, &\n nagf_file_print_matrix_real_gen\n Use lapack_interfaces, Only: ddisna, dsyev\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Real (Kind=dp), Parameter :: zero = 0.0_dp\n Integer, Parameter :: nb = 64, nin = 5, nout = 6\n! .. Local Scalars ..\n Real (Kind=dp) :: eerrbd, eps, r\n Integer :: i, ifail, info, k, lda, lwork, n\n! .. Local Arrays ..\n Real (Kind=dp), Allocatable :: a(:, :), rcondz(:), w(:), work(:), &\n zerrbd(:)\n Real (Kind=dp) :: dummy(1)\n! .. Intrinsic Procedures ..\n Intrinsic :: abs, epsilon, max, nint\n! .. Executable Statements ..\n Write (nout, *) 'DSYEV Example Program Results'\n Write (nout, *)\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n\n lda = n\n Allocate (a(lda,n), rcondz(n), w(n), zerrbd(n))\n\n! Use routine workspace query to get optimal workspace.\n lwork = -1\n Call dsyev('Vectors', 'Upper', n, a, lda, w, dummy, lwork, info)\n\n! Make sure that there is enough workspace for block size nb.\n lwork = max((nb+2)*n, nint(dummy(1)))\n Allocate (work(lwork))\n\n! Read the upper triangular part of the matrix A from data file\n\n Read (nin, *)(a(i,i:n), i=1, n)\n\n! Solve the symmetric eigenvalue problem\n Call dsyev('Vectors', 'Upper', n, a, lda, w, work, lwork, info)\n\n If (info==0) Then\n\n! Print solution\n\n Write (nout, *) 'Eigenvalues'\n Write (nout, 100) w(1:n)\n Flush (nout)\n\n! Normalize the eigenvectors: largest element positive\n Do i = 1, n\n Call nagf_blas_damax_val(n, a(1,i), 1, k, r)\n If (a(k,i) 0.d0 ) then\n c = c1 + 0.5d0*(smin+smax)*(c2-c1)/d\nendif\n\nif( shrink ) then\n zero = 0.d0 ! find furthest point in E1 from c\n dc = c1 - c\n call ell_pt_near_far( 2, n, dc, gg1, zero, xfar )\n r1 = sum( xfar*xfar)\n \n dc = c2 - c ! find furthest point in E2 from c\n call ell_pt_near_far( 2, n, dc, gg2, zero, xfar )\n r2 = sum( xfar*xfar)\n \n r = sqrt( max(r1,r2) ) ! set r to max. distance from c \nelse\n r = 0.5d0*(smax-smin)\nendif\n\nr = (1.d0 - extend) / r ! diagonal components of G = 1/r\n\nk = 0 ! G into gg\ngg = 0.d0\ndo j = 1, n\n do i = j, n\n k = k + 1\n\t if( i==j ) gg(k) = r\n end do\nend do\n\nreturn\nend subroutine ell_pair_cover_sph\n", "meta": {"hexsha": "f965b4b10c3e8f771624611ff8bcf4f7970b901f", "size": 2633, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/isat/ell_lib/ell_pair_cover_sph.f90", "max_stars_repo_name": "xuhan425/isat_ffd", "max_stars_repo_head_hexsha": "3a5449f7e49b686c33fe0e97ca90ea8d92fc2f00", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-04-10T20:16:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-15T11:09:44.000Z", "max_issues_repo_path": "src/isat/ell_lib/ell_pair_cover_sph.f90", "max_issues_repo_name": "xuhan425/isat_ffd", "max_issues_repo_head_hexsha": "3a5449f7e49b686c33fe0e97ca90ea8d92fc2f00", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-06-07T14:10:25.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-07T14:10:25.000Z", "max_forks_repo_path": "src/isat/ell_lib/ell_pair_cover_sph.f90", "max_forks_repo_name": "xuhan425/isat_ffd", "max_forks_repo_head_hexsha": "3a5449f7e49b686c33fe0e97ca90ea8d92fc2f00", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-06-07T03:44:12.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-05T05:54:10.000Z", "avg_line_length": 33.3291139241, "max_line_length": 97, "alphanum_fraction": 0.5545005697, "num_tokens": 926, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479466, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6534588290014688}} {"text": " subroutine afree(ndata,a,inca,g,incg,gssq)\nc-------------------------------------------------------------------\nc imposes constraint on weights a such that the inner \nc product of vector a and gsurf is unity. useful routine for\nc adding constraint in inverse problem using integration \nc quelling to allow value of the model at 0 to be a free parameter.\nc \nc arguments- \nc \nc ndata - length of vectors a and g\nc a - array of weights that are to be rescaled to satisfy\nc constraint.\nc inca - storage increment of a array ala blas. use 1 if \nc a is stored in column fashion. use first dimension\nc of a if values are stored in rows of a two dimensional \nc array. \nc g - constraint vector of length ndata. in inversion \nc this is the value of all data kernels at 0.\nc incg - storage increment of g array ala blas. (see above)\nc gssq - square of l2 norm of gsurf array. passed for\nc efficiency reason as this routine is expected\nc normally to be called several times within a loop\nc over several sets of weight vectors, a.\nc \nc language - 1977 ansi standard fortran \nc author - gary l. pavlis\nc required software support - library containing blas\nc written - april 1981\nc-------------------------------------------------------------------\n real a(ndata),g(ndata)\n real gssq \n integer ndata \n real alm\n alm = (sdot(ndata,a,inca,g,incg) - 1.0)/gssq \n call saxpy(ndata,-alm,g,incg,a,inca)\n return\n end \n\nc $Id$ \n", "meta": {"hexsha": "20438c21e353580ed0e00e8c463448fb32e0c6ee", "size": 1594, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "lib/location/libglp/afree.f", "max_stars_repo_name": "jreyes1108/antelope_contrib", "max_stars_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_stars_repo_licenses": ["BSD-2-Clause", "MIT"], "max_stars_count": 30, "max_stars_repo_stars_event_min_datetime": "2015-02-20T21:44:29.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-27T02:53:14.000Z", "max_issues_repo_path": "lib/location/libglp/afree.f", "max_issues_repo_name": "jreyes1108/antelope_contrib", "max_issues_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_issues_repo_licenses": ["BSD-2-Clause", "MIT"], "max_issues_count": 14, "max_issues_repo_issues_event_min_datetime": "2015-07-07T19:17:24.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-19T19:18:53.000Z", "max_forks_repo_path": "lib/location/libglp/afree.f", "max_forks_repo_name": "jreyes1108/antelope_contrib", "max_forks_repo_head_hexsha": "be2354605d8463d6067029eb16464a0bf432a41b", "max_forks_repo_licenses": ["BSD-2-Clause", "MIT"], "max_forks_count": 46, "max_forks_repo_forks_event_min_datetime": "2015-02-06T16:22:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T11:46:37.000Z", "avg_line_length": 39.85, "max_line_length": 68, "alphanum_fraction": 0.5978670013, "num_tokens": 407, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319863, "lm_q2_score": 0.7461389817407017, "lm_q1q2_score": 0.6534588190079461}} {"text": "module mod_define_explicit_RK_methods\n! Module containing subroutines and functions defining various explicit Runge-Kutta methods\n use mod_kinds, only: rk,ik\n use mod_constants, only: ZERO,ONE,TWO,THREE,EIGHTH,SIXTH,FOURTH,THIRD,HALF,TWO_THR\n implicit none\n \n \n \n !! \n !! The equation to be solved here is\n !!\n !! \\f$ \\frac{\\partial Q}{\\partial t} + R(Q) = 0 \\f$\n !!\n !! The discretization is given as\n !!\n !! \\f$ Q^{n + 1} = Q^{n} + \\Delta Q \\f$\n !!\n !! where\n !!\n !! \\f$ \\Delta Q = \\sum_{i = 1}^{s} b_{i} \\Delta Q_{i} \\f$\n !!\n !! with \\f$ s \\f$ being the number of stages in the method and\n !!\n !! \\f$ \\Delta Q_{i} = -\\Delta t M^{-1} R(Q^{n} + \\sum_{j = 1}^{i - 1} a_{ij} \\Delta Q_{j} \\f$\n !!\n !! Butcher tableau notation has been followed here\n !! \ncontains\n\n\n\n !> Define Runge's method (2nd order method with two stages)\n !!\n !! @author Mayank Sharma\n !! @date 1/17/2017\n !!\n !! @param[out] nstage - Number of stages in the present method\n !! @param[out] a - Array of coefficients for calculating stagewise updates\n !! @param[out] b - Array of coefficients for summing stagewise updates to get final update\n !!\n !---------------------------------------------------------------------------------------------------\n subroutine runge_2nd_order(nstage,a,b)\n integer(ik), intent(inout) :: nstage\n real(rk), allocatable,intent(inout) :: a(:,:)\n real(rk), allocatable,intent(inout) :: b(:)\n\n\n !\n ! Set number of stages\n !\n nstage = 2\n\n if (allocated(a) .and. allocated(b)) deallocate(a,b)\n allocate(a(nstage,nstage),b(nstage))\n\n !\n ! a is a lower triangular matrix\n !\n a = ZERO\n a(2,1) = HALF\n\n\n b = [ZERO, ONE]\n\n\n end subroutine runge_2nd_order\n !*************************************************************************************************** \n\n\n\n !> Define Heun's method (2nd order method with two stages)\n !!\n !! @author Mayank Sharma\n !! @date 1/17/2017\n !!\n !! @param[out] nstage - Number of stages in the present method\n !! @param[out] a - Array of coefficients for calculating stagewise updates\n !! @param[out] b - Array of coefficients for summing stagewise updates to get final update\n !!\n !---------------------------------------------------------------------------------------------------\n subroutine heun_2nd_order(nstage,a,b)\n integer(ik), intent(inout) :: nstage\n real(rk), allocatable,intent(inout) :: a(:,:)\n real(rk), allocatable,intent(inout) :: b(:)\n\n\n !\n ! Set number of stages\n !\n nstage = 2\n\n if (allocated(a) .and. allocated(b)) deallocate(a,b)\n allocate(a(nstage,nstage),b(nstage))\n\n !\n ! a is a lower triangular matrix\n !\n a = ZERO\n a(2,1) = ONE \n\n\n b = [HALF,HALF]\n\n\n end subroutine heun_2nd_order\n !*************************************************************************************************** \n\n\n\n !> Define Ralston's method (2nd order method with two stages)\n !!\n !! @author Mayank Sharma\n !! @date 1/17/2017\n !!\n !! @param[out] nstage - Number of stages in the present method\n !! @param[out] a - Array of coefficients for calculating stagewise updates\n !! @param[out] b - Array of coefficients for summing stagewise updates to get final update\n !!\n !---------------------------------------------------------------------------------------------------\n subroutine ralston_2nd_order(nstage,a,b)\n integer(ik), intent(inout) :: nstage\n real(rk), allocatable,intent(inout) :: a(:,:)\n real(rk), allocatable,intent(inout) :: b(:)\n\n\n !\n ! Set number of stages\n !\n nstage = 2\n\n if (allocated(a) .and. allocated(b)) deallocate(a,b)\n allocate(a(nstage,nstage),b(nstage))\n\n !\n ! a is a lower triangular matrix\n !\n a = ZERO\n a(2,1) = TWO_THR\n\n\n b = [FOURTH,THREE*FOURTH]\n\n\n end subroutine ralston_2nd_order\n !*************************************************************************************************** \n\n\n\n !> Define Kutta's method (3rd order method with three stages)\n !!\n !! @author Mayank Sharma\n !! @date 1/17/2017\n !!\n !! @param[out] nstage - Number of stages in the present method\n !! @param[out] a - Array of coefficients for calculating stagewise updates\n !! @param[out] b - Array of coefficients for summing stagewise updates to get final update\n !!\n !---------------------------------------------------------------------------------------------------\n subroutine kutta_3rd_order(nstage,a,b)\n integer(ik), intent(inout) :: nstage\n real(rk), allocatable,intent(inout) :: a(:,:)\n real(rk), allocatable,intent(inout) :: b(:)\n\n\n !\n ! Set number of stages\n !\n nstage = 3\n\n if (allocated(a) .and. allocated(b)) deallocate(a,b)\n allocate(a(nstage,nstage),b(nstage))\n\n !\n ! a is a lower triangular matrix\n !\n a = ZERO\n a(2,1) = HALF; a(3,1) = -ONE; a(3,2) = TWO \n\n\n b = [SIXTH,TWO_THR,SIXTH]\n\n\n end subroutine kutta_3rd_order\n !*************************************************************************************************** \n\n\n\n !> Define the Runge-Kutta method (4th order method with four stages)\n !!\n !! @author Mayank Sharma\n !! @date 1/17/2017\n !!\n !! @param[out] nstage - Number of stages in the present method\n !! @param[out] a - Array of coefficients for calculating stagewise updates\n !! @param[out] b - Array of coefficients for summing stagewise updates to get final update\n !!\n !---------------------------------------------------------------------------------------------------\n subroutine runge_kutta_4th_order(nstage,a,b)\n integer(ik), intent(inout) :: nstage\n real(rk), allocatable,intent(inout) :: a(:,:)\n real(rk), allocatable,intent(inout) :: b(:)\n\n\n !\n ! Set number of stages\n !\n nstage = 4\n\n if (allocated(a) .and. allocated(b)) deallocate(a,b)\n allocate(a(nstage,nstage),b(nstage))\n\n !\n ! a is a lower triangular matrix\n !\n a = ZERO\n a(2,1) = HALF; a(3,2) = HALF; a(4,3) = ONE\n\n\n b = [SIXTH,THIRD,THIRD,SIXTH]\n\n\n end subroutine runge_kutta_4th_order\n !*************************************************************************************************** \n\n\n\n !> Define the 3/8-rule method (4th order method with four stages)\n !!\n !! @author Mayank Sharma\n !! @date 1/17/2017\n !!\n !! @param[out] nstage - Number of stages in the present method\n !! @param[out] a - Array of coefficients for calculating stagewise updates\n !! @param[out] b - Array of coefficients for summing stagewise updates to get final update\n !!\n !---------------------------------------------------------------------------------------------------\n subroutine three_eighth_4th_order(nstage,a,b)\n integer(ik), intent(inout) :: nstage\n real(rk), allocatable,intent(inout) :: a(:,:)\n real(rk), allocatable,intent(inout) :: b(:)\n\n\n !\n ! Set number of stages\n !\n nstage = 4\n\n if (allocated(a) .and. allocated(b)) deallocate(a,b)\n allocate(a(nstage,nstage),b(nstage))\n\n !\n ! a is a lower triangular matrix\n !\n a = ZERO\n a(2,1) = THIRD\n a(3,1) = -THIRD; a(3,2) = ONE\n a(4,1) = ONE; a(4,2) = -ONE; a(4,3) = ONE \n\n\n b = [EIGHTH,THREE*EIGHTH,THREE*EIGHTH,EIGHTH]\n\n\n end subroutine three_eighth_4th_order\n !*************************************************************************************************** \n\n\n\n !> Select explicit Runge-Kutta method based on input \n !!\n !! @author Mayank Sharma\n !! @date 1/23/2017\n !!\n !! @param[in] time_scheme - String denoting the method to be used from user input\n !! @param[out] nstage - Number of stages in the selected method\n !! @param[out] a - Array of coefficients for calculating stagewise updates\n !! @param[out] b - Array of coefficients for summing stagewise updates to get final update\n !!\n !---------------------------------------------------------------------------------------------------\n subroutine method_selector(time_scheme,nstage,a,b)\n character(len = :), allocatable, intent(in) :: time_scheme\n integer(ik), intent(inout) :: nstage\n real(rk), allocatable, intent(inout) :: a(:,:)\n real(rk), allocatable, intent(inout) :: b(:)\n\n\n select case(time_scheme)\n \n case('Second Order Runge-Kutta', 'Explicit Midpoint', 'Second Order RK')\n call runge_2nd_order(nstage,a,b)\n\n case('Modified Euler', 'Second Order Heun Method')\n call heun_2nd_order(nstage,a,b)\n\n case('Ralston Method', 'Second Order Ralston Method')\n call ralston_2nd_order(nstage,a,b)\n\n case('Third Order Runge-Kutta', 'Third Order Kutta', 'Third Order RK')\n call kutta_3rd_order(nstage,a,b)\n\n case('Runge-Kutta Method', 'Fourth Runge-Kutta Method', 'Fourth Order RK Method', 'RK4')\n call runge_kutta_4th_order(nstage,a,b)\n\n case('Three-Eighth Rule', 'Fourth Order Kutta')\n call three_eighth_4th_order(nstage,a,b)\n\n end select\n\n\n end subroutine method_selector\n !*************************************************************************************************** \n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \nend module mod_define_explicit_RK_methods\n", "meta": {"hexsha": "a8b30142ff436b88d04db5beea0011191ff4f3eb", "size": 10188, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/time_integrators/marching/explicit/runge_kutta_methods/explicit/mod_explicit_RK_methods.f90", "max_stars_repo_name": "wanglican/ChiDG", "max_stars_repo_head_hexsha": "d3177b87cc2f611e66e26bb51616f9385168f338", "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/time_integrators/marching/explicit/runge_kutta_methods/explicit/mod_explicit_RK_methods.f90", "max_issues_repo_name": "haohb/ChiDG", "max_issues_repo_head_hexsha": "d3177b87cc2f611e66e26bb51616f9385168f338", "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/time_integrators/marching/explicit/runge_kutta_methods/explicit/mod_explicit_RK_methods.f90", "max_forks_repo_name": "haohb/ChiDG", "max_forks_repo_head_hexsha": "d3177b87cc2f611e66e26bb51616f9385168f338", "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": 30.5945945946, "max_line_length": 107, "alphanum_fraction": 0.4740871614, "num_tokens": 2557, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869786798664, "lm_q2_score": 0.7461389817407016, "lm_q1q2_score": 0.6534588044939611}} {"text": "module init_mod\n use helpers_mod\n implicit none\n\n contains\n\n subroutine init_flag(delx, dely, flag, ibound)\n real, intent(in) :: delx, dely\n integer flag(0:imax+1, 0:jmax+1)\n\n real :: mx, my, x, y, rad1, x1, y1\n integer :: ibound;\n\n integer :: i, j\n\n ! mask of a circular obstacle\n mx = 20.0/41.0*jmax*dely\n my = mx\n rad1 = 5.0/41.0*jmax*dely\n\n flag = C_F\n\n ! insert circular mask\n do i = 1, imax\n do j = 1, jmax\n x = (i-0.5)*delx - mx\n y = (j-0.5)*dely - my\n if (x*x + y*y <= rad1*rad1) then\n flag(i,j) = C_B\n end if\n\n ! Some code for adding a few more circular masks near-by\n !x1 = (i-0.5)*delx - mx*4\n !y1 = (j-0.5)*dely - my*1.25\n !if (x1*x1 + y1*y1 <= rad1*rad1) then\n ! flag(i,j) = C_B\n !end if\n !\n !x1 = (i-0.5)*delx - mx*3\n !y1 = (j-0.5)*dely - my*0.5\n !if (x1*x1 + y1*y1 <= rad1*rad1) then\n ! flag(i,j) = C_B\n !end if\n end do\n end do\n\n ! mark east & west bounary cells\n flag(0:imax+1,0) = C_B\n flag(0:imax+1,jmax+1) = C_B\n ! mark north & south boundary cells as obstacles\n flag(0,1:jmax) = C_B\n flag(imax+1,1:jmax) = C_B\n\n\n do i = 1, imax\n do j = 1, jmax\n if (.not. (toLogical (iand(flag(i,j),C_F)))) then\n ibound = ibound + 1\n if (toLogical (iand(flag(i-1,j), C_F))) flag(i,j) = ior(flag(i,j), B_W)\n if (toLogical (iand(flag(i+1,j), C_F))) flag(i,j) = ior(flag(i,j), B_E)\n if (toLogical (iand(flag(i,j-1), C_F))) flag(i,j) = ior(flag(i,j), B_S)\n if (toLogical (iand(flag(i,j+1), C_F))) flag(i,j) = ior(flag(i,j), B_N)\n end if\n end do\n end do\n end subroutine init_flag\nend module init_mod\n", "meta": {"hexsha": "b20127c4af86decd0f6fc7d65a1ececdf776fb4d", "size": 1770, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/init_mod.f90", "max_stars_repo_name": "raehik/navier", "max_stars_repo_head_hexsha": "7e22a09fcde3993864a61d2855ff73ddbb096458", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 49, "max_stars_repo_stars_event_min_datetime": "2015-02-19T07:15:32.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-01T16:53:40.000Z", "max_issues_repo_path": "fortran/init_mod.f90", "max_issues_repo_name": "raehik/navier", "max_issues_repo_head_hexsha": "7e22a09fcde3993864a61d2855ff73ddbb096458", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2016-09-29T01:26:51.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-19T05:18:40.000Z", "max_forks_repo_path": "fortran/init_mod.f90", "max_forks_repo_name": "raehik/navier", "max_forks_repo_head_hexsha": "7e22a09fcde3993864a61d2855ff73ddbb096458", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2015-05-19T01:42:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-10T16:48:34.000Z", "avg_line_length": 26.0294117647, "max_line_length": 81, "alphanum_fraction": 0.5129943503, "num_tokens": 691, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672595, "lm_q2_score": 0.7634837527911057, "lm_q1q2_score": 0.6534284455171354}} {"text": "program ch0505\n ! Relative and Absolute Error\n implicit none\n\n real :: p = 0.4e-4, papprox = 0.41e-4\n real :: abs_error, rel_error\n integer :: i\n\n do i = 1, 3\n abs_error = abs(p-papprox)\n rel_error = abs(p-papprox)/abs(p)\n print 100, p, papprox\n print 110, abs_error, rel_error\n p = p*1.e5\n papprox = papprox*1.e5\n end do\n\n100 format (' p = ', e11.4, /, &\n 'papprox = ', e11.4)\n110 format (' abs error:', 12x, e11.4, /, &\n 'rel error:', 12x, e11.4, /)\nend program\n", "meta": {"hexsha": "3f8feeef7ed5083a70bd6d2268560881a98bec63", "size": 539, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ch05/ch0505.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": "ch05/ch0505.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": "ch05/ch0505.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.4347826087, "max_line_length": 43, "alphanum_fraction": 0.5417439703, "num_tokens": 193, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8558511396138365, "lm_q2_score": 0.7634837527911057, "lm_q1q2_score": 0.6534284399029164}} {"text": " double precision function vol3_mass(decaymass,s)\n implicit none\n double precision decaymass,b0,bp,bm,s,ro,vol\nc Volume of phase space for 2-->p3(decaymass)+p4(decaymass)+p5(0) \n if (decaymass .eq. 0d0) then\n vol3_mass=1d0\n else\n ro=4d0*decaymass**2/s\n b0=dsqrt(1d0-ro)\n bp=0.5d0*(1d0+b0) \n bm=0.5d0*(1d0-b0) \n\n vol3_mass=(3d0-b0**2)/2d0*b0\n . -(1d0-b0**2)*(3d0+b0**2)/4d0*log(bp/bm)\n endif\n vol3_mass=vol3_mass*vol(s,3)\n return\n end\n \n", "meta": {"hexsha": "c002e24b5c066c366114c60a582da121aec07b6a", "size": 536, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "MCFM-JHUGen/src/Vol/vol3_mass.f", "max_stars_repo_name": "tmartini/JHUGen", "max_stars_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-06-08T13:09:28.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-04T19:59:36.000Z", "max_issues_repo_path": "MCFM-JHUGen/src/Vol/vol3_mass.f", "max_issues_repo_name": "tmartini/JHUGen", "max_issues_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 64, "max_issues_repo_issues_event_min_datetime": "2015-06-24T15:08:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-25T04:59:32.000Z", "max_forks_repo_path": "MCFM-JHUGen/src/Vol/vol3_mass.f", "max_forks_repo_name": "tmartini/JHUGen", "max_forks_repo_head_hexsha": "80da31668d7b7eb5b02bb4cac435562c45075d24", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2015-05-04T22:15:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-06T10:04:40.000Z", "avg_line_length": 26.8, "max_line_length": 72, "alphanum_fraction": 0.5652985075, "num_tokens": 214, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.966914019704466, "lm_q2_score": 0.6757646140788308, "lm_q1q2_score": 0.6534062793729994}} {"text": "!------------------------------------------------------------------------------!\n! The Community Multiscale Air Quality (CMAQ) system software is in !\n! continuous development by various groups and is based on information !\n! from these groups: Federal Government employees, contractors working !\n! within a United States Government contract, and non-Federal sources !\n! including research institutions. These groups give the Government !\n! permission to use, prepare derivative works of, and distribute copies !\n! of their work in the CMAQ system to the public and to permit others !\n! to do so. The United States Environmental Protection Agency !\n! therefore grants similar permission to use the CMAQ system software, !\n! but users are requested to provide copies of derivative works or !\n! products designed to operate in the CMAQ system to the United States !\n! Government without restrictions as to use by others. Software !\n! that is used with the CMAQ system but distributed under the GNU !\n! General Public License or the GNU Lesser General Public License is !\n! subject to their copyright restrictions. !\n!------------------------------------------------------------------------------!\n\nSUBROUTINE xy2ll_merc (xx, yy, lambda0, phi, lambda)\n\n!-------------------------------------------------------------------------------\n! Name: (X,Y) to Latitude-Longitude for Polar Stereographic Projection\n! Purpose: Calcluates latitude-longitude for a given (X,Y) pair from origin\n! and polar stereographic projection information.\n! Notes: Equations taken from \"Map Projections: Theory and Applications\"\n! by Frederick Pearson, II (1990), pp. 190-192.\n! Revised: 18 Sep 2009 Original version. (T. Otte)\n! 07 Sep 2011 Updated disclaimer. (T. Otte)\n!-------------------------------------------------------------------------------\n\n USE const, ONLY: rearth\n\n IMPLICIT NONE\n\n REAL(8) :: deg2rad ! convert degrees to radians\n REAL(8) :: drearth ! earth radius [m]\n REAL, INTENT(OUT) :: lambda ! longitude [deg]\n REAL(8) :: lambdarad ! longitude [rad]\n REAL, INTENT(IN) :: lambda0 ! center longitude [deg]\n REAL(8) :: lambda0rad ! center longitude [rad]\n REAL, INTENT(OUT) :: phi ! latitude [deg]\n REAL(8) :: phirad ! latitude [rad]\n REAL(8) :: pi\n REAL(8) :: piover2 ! pi/2\n REAL(8) :: piover4 ! pi/4\n REAL(8) :: rad2deg\n REAL, INTENT(IN) :: xx ! X-coordinate from origin\n REAL(8) :: xxd\n REAL, INTENT(IN) :: yy ! Y-coordinate from origin\n REAL(8) :: yyd\n\n!-------------------------------------------------------------------------------\n! Compute constants.\n!-------------------------------------------------------------------------------\n\n piover4 = DATAN(1.0d0)\n piover2 = 2.0d0 * piover4\n pi = 4.0d0 * piover4\n deg2rad = pi / 1.8d2\n rad2deg = 1.8d2 / pi\n\n drearth = DBLE(rearth)\n\n!-------------------------------------------------------------------------------\n! Set up geometric constants.\n!-------------------------------------------------------------------------------\n\n xxd = DBLE(xx)\n yyd = DBLE(yy)\n\n!-------------------------------------------------------------------------------\n! Compute latitude (PHI).\n!-------------------------------------------------------------------------------\n\n phirad = ( 2.0d0 * DATAN ( DEXP(yyd/drearth) ) ) - piover2\n phi = REAL( phirad * rad2deg )\n\n!-------------------------------------------------------------------------------\n! Compute longitude (LAMBDA).\n!-------------------------------------------------------------------------------\n\n lambda0rad = DBLE(lambda0) * deg2rad\n lambdarad = lambda0rad + xxd/drearth\n lambda = REAL( lambdarad * rad2deg )\n\nEND SUBROUTINE xy2ll_merc\n", "meta": {"hexsha": "43c3ea6e5ce16dfb0028ec959092fe0be6801af5", "size": 4226, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "PREP/mcip/src/xy2ll_merc.f90", "max_stars_repo_name": "Simeng-unique/CMAQ-changed", "max_stars_repo_head_hexsha": "cb83401728ed7ea1bb19a6986c0acc84dabe11a4", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 203, "max_stars_repo_stars_event_min_datetime": "2017-02-04T18:01:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T09:09:00.000Z", "max_issues_repo_path": "PREP/mcip/src/xy2ll_merc.f90", "max_issues_repo_name": "Simeng-unique/CMAQ-changed", "max_issues_repo_head_hexsha": "cb83401728ed7ea1bb19a6986c0acc84dabe11a4", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 54, "max_issues_repo_issues_event_min_datetime": "2017-01-03T21:40:27.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-04T19:03:53.000Z", "max_forks_repo_path": "PREP/mcip/src/xy2ll_merc.f90", "max_forks_repo_name": "Simeng-unique/CMAQ-changed", "max_forks_repo_head_hexsha": "cb83401728ed7ea1bb19a6986c0acc84dabe11a4", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 170, "max_forks_repo_forks_event_min_datetime": "2016-11-09T22:30:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T03:21:59.000Z", "avg_line_length": 48.5747126437, "max_line_length": 80, "alphanum_fraction": 0.4531471841, "num_tokens": 910, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267830311355, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6533686652586891}} {"text": "PROGRAM test_fftw\n USE general_tools\n USE cs_tools\n USE debug_tools\n USE fftw_tools\nIMPLICIT NONE\n\n INTEGER, PARAMETER :: IP_SIZE = 512\n INTEGER :: ibi\n REAL(cp) :: rp_scale = 3.0\n REAL(cp) :: rl_nz_ratio\n real(C_DOUBLE) :: rl_dx\n type(C_PTR) :: plan_forward, plan_backward\n real(C_DOUBLE), dimension(IP_SIZE) :: rla_x, rla_y, rla_in, rla_out, rla_signal, rla_fft_coef\n TYPE(dyn_rVector), DIMENSION(5) :: tla_save\n\n CALL init_all()\n \n rl_dx = 2.0*rp_pi/(IP_SIZE-1)\n rla_x = (/ ((ibi-1)*rl_dx, ibi=1,IP_SIZE) /)\n tla_save(1) = rla_x\n rla_fft_coef = 0.0_cp\n rla_signal = 0.0_cp\n rl_nz_ratio = 0.1\n CALL RANDOM_NUMBER(rla_fft_coef)\n rla_fft_coef = rp_scale*(rla_fft_coef - 0.5_cp)\n CALL randval_randidx(rla_fft_coef, rl_nz_ratio, rp_scale)\n tla_save(3) = rla_fft_coef\n CALL ifftw_trans(rla_fft_coef, rla_signal)\n tla_save(2) = rla_signal\n CALL RANDOM_NUMBER(rla_signal)\n rla_signal = rp_scale*(rla_signal - 0.5_cp)\n CALL randval_randidx(rla_signal, rl_nz_ratio, rp_scale)\n tla_save(4) = rla_signal\n CALL fftw_trans(rla_signal, rla_fft_coef)\n tla_save(5) = rla_fft_coef\n CALL save_trj( tla_save(1:5) , TRIM('output/test.dat' ), ld_column = .TRUE. )\n \n CALL finalize_all()\nCONTAINS\n\n SUBROUTINE init_all()\n CALL init_fftw()\n CALL init_cs_tools()\n END SUBROUTINE init_all\n \n SUBROUTINE finalize_all()\n CALL finalize_fftw()\n CALL finalize_cs_tools()\n END SUBROUTINE finalize_all\n \n SUBROUTINE test()\n !complex(C_DOUBLE_COMPLEX), dimension(IP_SIZE/2 + 1) :: cla_out\n !fftw_plan fftw_plan_r2r_1d(int n, double *in, double *out, fftw_r2r_kind kind, unsigned flags); FFTW_R2HC/FFTW_HC2R\n rl_dx = 2.0*rp_pi/(IP_SIZE-1)\n DO ibi=1, IP_SIZE\n rla_x(ibi) = (ibi-1)*rl_dx!-rp_pi\n END DO\n rla_y = cos(22*rla_x) -cos(40*rla_x)! - sin(16*rla_x)\n tla_save(1) = rla_x\n tla_save(2) = rla_y\n plan_forward = fftw_plan_r2r_1d(IP_SIZE, rla_in , rla_out, FFTW_R2HC, FFTW_ESTIMATE)\n plan_backward = fftw_plan_r2r_1d(IP_SIZE, rla_out, rla_in , FFTW_HC2R, FFTW_ESTIMATE)\n !...\n rla_in = rla_y\n call fftw_execute_r2r(plan_forward , rla_in, rla_out)\n rla_out = rla_out/SQRT(IP_SIZE*1.0_cp)\n tla_save(3) = rla_out\n rla_in = 0.0_cp\n WHERE (ABS(rla_out) tol) GO TO 40\r\n e(i)=f\r\n d(i)=zero\r\n GO TO 100\r\n\r\n 40 l=l+1\r\n g=SQRT(h)\r\n IF (f >= zero) g=-g\r\n e(i)=g\r\n h=h - f*g\r\n z(i,i-1)=f-g\r\n f=zero\r\n DO j=1,l\r\n z(j,i)=z(i,j)/h\r\n g=zero\r\n \r\n! Form element of a * u\r\n \r\n DO k=1,j\r\n g=g + z(j,k)*z(i,k)\r\n END DO\r\n IF (j >= l) GO TO 70\r\n j1=j+1\r\n DO k=j1,l\r\n g=g + z(k,j)*z(i,k)\r\n END DO\r\n \r\n! Form element of p\r\n \r\n 70 e(j)=g/h\r\n f=f + g*z(j,i)\r\n END DO\r\n \r\n! Form k\r\n \r\n hh=f/(h+h)\r\n \r\n! Form reduced a\r\n \r\n DO j=1,l\r\n f=z(i,j)\r\n g=e(j)-hh*f\r\n e(j)=g\r\n DO k=1,j\r\n z(j,k)=z(j,k) - f*e(k) - g*z(i,k)\r\n END DO\r\n END DO\r\n d(i)=h\r\n 100 i=i-1\r\nEND DO\r\nd(1)=zero\r\ne(1)=zero\r\n\r\n! Accumulation of transformation matrices\r\n\r\nDO i=1,n\r\n l=i-1\r\n IF (d(i) == zero .OR. l == 0) GO TO 140\r\n DO j=1,l\r\n g=zero\r\n DO k=1,l\r\n g=g + z(i,k)*z(k,j)\r\n END DO\r\n DO k=1,l\r\n z(k,j)=z(k,j) - g*z(k,i)\r\n END DO\r\n END DO\r\n 140 d(i)=z(i,i)\r\n z(i,i)=one\r\n IF (l == 0) CYCLE\r\n DO j=1,l\r\n z(i,j)=zero\r\n z(j,i)=zero\r\n END DO\r\nEND DO\r\nRETURN\r\nEND SUBROUTINE tdiag\r\n\r\n\r\nSUBROUTINE lrvt (n, precis, d, e, z, ifault, maxdim)\r\n\r\nINTEGER, INTENT(IN) :: n\r\nREAL (dp), INTENT(OUT) :: precis\r\nINTEGER, INTENT(IN) :: maxdim\r\nREAL (dp), INTENT(IN OUT) :: d(maxdim)\r\nREAL (dp), INTENT(OUT) :: e(maxdim)\r\nREAL (dp), INTENT(IN OUT) :: z(maxdim,maxdim)\r\nINTEGER, INTENT(OUT) :: ifault\r\n\r\n! Algorithm AS 60.2 appl.statist. (1973) vol.22, no.2\r\n\r\n! Finds latent roots and vectors of tridiagonal matrix\r\n\r\nINTEGER, PARAMETER :: mits = 30\r\nREAL (dp), PARAMETER :: two = 2.0D0\r\n\r\nINTEGER :: i, i1, j, jj, k, l, m, m1, n1\r\nREAL (dp) :: b, c, f, g, h, p, pr, r, s\r\n\r\nprecis=1.0D-14\r\nifault=2\r\nIF (n <= 1) RETURN\r\nifault=1\r\nn1=n-1\r\nDO i=2,n\r\n e(i-1)=e(i)\r\nEND DO\r\ne(n)=zero\r\nb=zero\r\nf=zero\r\nDO l=1,n\r\n jj=0\r\n h=precis*(ABS(d(l))+ABS(e(l)))\r\n IF (b < h) b=h\r\n \r\n! Look for small sub-diagonal element\r\n \r\n DO m1=l,n\r\n m=m1\r\n IF (ABS(e(m)) <= b) EXIT\r\n END DO\r\n IF (m == l) GO TO 90\r\n 40 IF (jj == mits) RETURN\r\n jj=jj+1\r\n \r\n! Form shift\r\n \r\n p=(d(l+1)-d(l))/(two*e(l))\r\n r=SQRT(p*p + one)\r\n pr=p+r\r\n IF (p < zero) pr=p-r\r\n h=d(l)-e(l)/pr\r\n DO i=l,n\r\n d(i)=d(i)-h\r\n END DO\r\n f=f+h\r\n \r\n! QL transformation\r\n \r\n p=d(m)\r\n c=one\r\n s=zero\r\n m1=m-1\r\n i=m\r\n DO i1=l,m1\r\n j=i\r\n i=i-1\r\n g=c*e(i)\r\n h=c*p\r\n IF (ABS(p) >= ABS(e(i))) GO TO 60\r\n c=p/e(i)\r\n r=SQRT(c*c + one)\r\n e(j)=s*e(i)*r\r\n s=one/r\r\n c=c/r\r\n GO TO 70\r\n 60 c=e(i)/p\r\n r=SQRT(c*c + one)\r\n e(j)=s*p*r\r\n s=c/r\r\n c=one/r\r\n 70 p=c*d(i) - s*g\r\n d(j)=h + s*(c*g + s*d(i))\r\n \r\n! Form vector\r\n \r\n DO k=1,n\r\n h=z(k,j)\r\n z(k,j)=s*z(k,i) + c*h\r\n z(k,i)=c*z(k,i) - s*h\r\n END DO\r\n END DO\r\n e(l)=s*p\r\n d(l)=c*p\r\n IF (ABS(e(l)) > b) GO TO 40\r\n 90 d(l)=d(l) + f\r\nEND DO\r\n\r\n! Order latent roots and vectors\r\n\r\nDO i=1,n1\r\n k=i\r\n p=d(i)\r\n i1=i+1\r\n DO j=i1,n\r\n IF (d(j) <= p) CYCLE\r\n k=j\r\n p=d(j)\r\n END DO\r\n IF (k == i) CYCLE\r\n d(k)=d(i)\r\n d(i)=p\r\n DO j=1,n\r\n p=z(j,i)\r\n z(j,i)=z(j,k)\r\n z(j,k)=p\r\n END DO\r\nEND DO\r\nifault=0\r\nRETURN\r\nEND SUBROUTINE lrvt\r\n\r\nEND MODULE AS60\r\n", "meta": {"hexsha": "2fb0094e7e40a8c78603cad87fa83f36c2f8826c", "size": 4995, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/as60.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/as60.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/as60.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": 18.3639705882, "max_line_length": 73, "alphanum_fraction": 0.4970970971, "num_tokens": 2033, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095294, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6533537574890504}} {"text": " subroutine krnlrowupdate( m, n, A, ldA, cvec, svec )\n\n implicit none\n\n*\n* PURPOSE\n* =======\n*\n* Applies a decreasing sequence of m - 1 row rotations to a\n* rectangular m-by-n matrix A.\n*\n* More specifically, the following update of A is performed:\n*\n* A := G(2) * G(3) * ... * G(m) * A\n*\n* where G(k) for k = 2, 3, ..., m affects only rows k - 1 and k in\n* the following way. Let x denote row k - 1 and y denote row\n* k. Furthermore, define c = cvec(k) and s = svec(k). Then the\n* effect of G(k) * A is equivalent to the update\n*\n* [ x ] := [ c s ] * [ x ]\n* [ y ] [-s c ] [ y ].\n*\n*\n* ARGUMENTS\n* =========\n*\n* m (input) INTEGER\n*\n* The number of rows in A.\n*\n* n (input) INTEGER\n*\n* The number of columns in A.\n*\n* A (input/output) DOUBLE PRECISION array\n* dimension ldA-by-n\n*\n* The matrix A.\n*\n* ldA (input) INTEGER\n*\n* The column stride of A.\n*\n* cvec (input) DOUBLE PRECISION array\n* dimension m\n*\n* cvec(k) is the c-parameter of G(k).\n*\n* svec (input) DOUBLE PRECISION array\n* dimension m\n*\n* svec(k) is the s-parameter of G(k).\n* \n\n*\n* Constants.\n* \n integer slabsz\n parameter( slabsz = 16 )\n\n* \n* Scalar arguments.\n* \n integer m, n, ldA\n\n*\n* Array arguments.\n* \n double precision A( ldA, * ), cvec( * ), svec( * )\n\n*\n* Intrinsics.\n* \n intrinsic min\n\n*\n* Local scalars.\n* \n integer i, j, jj, jend\n double precision c, s, x, y\n\n do jj = 1, n, slabsz\n jend = min( n, jj + slabsz - 1 )\n do i = m, 2, -1\n c = cvec( i )\n s = svec( i )\n do j = jj, jend\n x = A( i - 1, j )\n y = A( i , j )\n A( i - 1, j ) = c * x + s * y\n A( i , j ) = - s * x + c * y\n end do\n end do\n end do\n\n end subroutine\n\n", "meta": {"hexsha": "2c4326ceb26b02993c321a320054368229b10126", "size": 2153, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/3rdparty/pdgghrd/KRNLROWUPDATE.f", "max_stars_repo_name": "NLAFET/StarNEig", "max_stars_repo_head_hexsha": "d47ed4dfbcdaec52e44f0b02d14a6e0cde64d286", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2019-04-28T17:13:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-24T12:30:19.000Z", "max_issues_repo_path": "src/3rdparty/pdgghrd/KRNLROWUPDATE.f", "max_issues_repo_name": "NLAFET/StarNEig", "max_issues_repo_head_hexsha": "d47ed4dfbcdaec52e44f0b02d14a6e0cde64d286", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/3rdparty/pdgghrd/KRNLROWUPDATE.f", "max_forks_repo_name": "NLAFET/StarNEig", "max_forks_repo_head_hexsha": "d47ed4dfbcdaec52e44f0b02d14a6e0cde64d286", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2019-04-30T12:14:12.000Z", "max_forks_repo_forks_event_max_datetime": "2020-04-14T09:41:23.000Z", "avg_line_length": 21.7474747475, "max_line_length": 70, "alphanum_fraction": 0.4245239201, "num_tokens": 642, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467770088162, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6533537545468292}} {"text": "!*****************************************************************************************\n!>\n! Drag model\n\n module drag_module\n\n use kind_module\n\n implicit none\n\n private\n\n public :: drag_acceleration\n\n contains\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Acceleration due to atmospheric drag.\n\n pure subroutine drag_acceleration(vrel,cd,area,m,rho,acc)\n\n implicit none\n\n real(wp),dimension(3),intent(in) :: vrel !! velocity relative to the atmosphere [km/s]\n real(wp),intent(in) :: cd !! spacecraft drag coefficient [--]\n real(wp),intent(in) :: area !! cross-section area [km^2]\n real(wp),intent(in) :: m !! spacecraft mass [kg]\n real(wp),intent(in) :: rho !! atmospheric density [kg/km^3]\n real(wp),dimension(3),intent(out) :: acc !! drag acceleration vector [km/s^2]\n\n real(wp) :: vrel_mag !! magnitude of the relative velocity [km/s]\n\n vrel_mag = norm2(vrel)\n\n acc = - (0.5_wp * rho * cd * area * vrel_mag / m) * vrel\n\n end subroutine drag_acceleration\n!*****************************************************************************************\n\n!*****************************************************************************************\n end module drag_module\n!*****************************************************************************************\n", "meta": {"hexsha": "f9bb0f909dff8e5d614d9da1f0ee9d71b19d8209", "size": 1536, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/drag_module.f90", "max_stars_repo_name": "jacobwilliams/Fortran-Astrodynamics-Toolk", "max_stars_repo_head_hexsha": "f8e18642dc8d78473d233b8fa6078fdbf7a1d6fc", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 122, "max_stars_repo_stars_event_min_datetime": "2015-01-29T05:40:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:20:21.000Z", "max_issues_repo_path": "src/drag_module.f90", "max_issues_repo_name": "gandymagic/Fortran-Astrodynamics-Toolkit", "max_issues_repo_head_hexsha": "7f176fabc8c36cc1981349b02eeb6d8112f2bfbc", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 25, "max_issues_repo_issues_event_min_datetime": "2015-06-10T02:16:59.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T04:28:55.000Z", "max_forks_repo_path": "src/drag_module.f90", "max_forks_repo_name": "gandymagic/Fortran-Astrodynamics-Toolkit", "max_forks_repo_head_hexsha": "7f176fabc8c36cc1981349b02eeb6d8112f2bfbc", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 43, "max_forks_repo_forks_event_min_datetime": "2015-02-12T13:24:23.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-30T04:30:49.000Z", "avg_line_length": 34.1333333333, "max_line_length": 93, "alphanum_fraction": 0.384765625, "num_tokens": 284, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095292, "lm_q2_score": 0.7431680086124811, "lm_q1q2_score": 0.6533537524881567}} {"text": "c ==================================================================\n subroutine setaux(mbc,mx,my,mz,xlower,ylower,zlower,\n & dx,dy,dz,maux,aux)\nc ==================================================================\nc\nc # set auxiliary arrays\nc\nc # advection\nc # aux(i,j,k,1) is u velocity on left face of cell\nc # aux(i,j,k,2) is v velocity on bottom face of cell\nc # aux(i,j,k,3) is w velocity on back face of cell\nc\nc\n implicit none\n\n integer mx, my, mz, mbc, maux, i,j,k\n double precision xlower, ylower, zlower, dx, dy, dz,\n & pi, pi2, dx2, dy2, dz2, compute_u, compute_v, compute_w\n double precision aux(maux,1-mbc:mx+mbc,1-mbc:my+mbc,1-mbc:mz+mbc)\n double precision xc(1-mbc:mx+mbc)\n double precision yc(1-mbc:my+mbc)\n double precision zc(1-mbc:mz+mbc)\n\n common /piconstants/ pi, pi2\n\n pi = 4.d0*atan(1.d0)\n pi2 = 2.d0*pi\n\nc\n\n do i = 1-mbc,mx+mbc\n xc(i) = xlower + (i-0.5d0)*dx\n enddo\n\n do j = 1-mbc,my+mbc\n yc(j) = ylower + (j-0.5d0)*dy\n enddo\n\n do k = 1-mbc,mz+mbc\n zc(k) = zlower + (k-0.5d0)*dz\n enddo\n\n dx2 = 0.5d0*dx\n dy2 = 0.5d0*dy\n dz2 = 0.5d0*dz\n\n do k = 1-mbc,mz+mbc\n do j = 1-mbc,my+mbc\n do i = 1-mbc,mx+mbc\n aux(1,i,j,k) = compute_u(xc(i)-dx2, yc(j),zc(k))\n aux(2,i,j,k) = compute_v(xc(i),yc(j)-dy2, zc(k))\n aux(3,i,j,k) = compute_w(xc(i),yc(j), zc(k)-dz2)\n enddo\n enddo\n enddo\n\n return\n end\n\n double precision function compute_u(x,y,z)\n implicit none\n double precision x,y,z,pi, pi2\n\n common /piconstants/ pi, pi2\n\n compute_u = 2.d0 * dsin(pi*x)**2 * dsin(pi2*y) * dsin(pi2*z)\n end\n\n double precision function compute_v(x,y,z)\n implicit none\n double precision x,y,z,pi, pi2\n\n common /piconstants/ pi, pi2\n\n compute_v = -dsin(pi2*x) * dsin(pi*y)**2 * dsin(pi2*z)\n end\n\n double precision function compute_w(x,y,z)\n implicit none\n double precision x,y,z,pi, pi2\n\n common /piconstants/ pi, pi2\n\n compute_w = -dsin(pi2*x) * dsin(pi2*y) * dsin(pi*z)**2\n end\n", "meta": {"hexsha": "97bb4180a4ed1525b1da2f3d2e9b690af086cd2f", "size": 2252, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "dev/advection_3d_swirl/setaux.f", "max_stars_repo_name": "ClimateImpactLab/clawutil", "max_stars_repo_head_hexsha": "10edc50de410eeaa768932af89540cee45476d27", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2015-05-27T08:16:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-21T06:36:24.000Z", "max_issues_repo_path": "dev/advection_3d_swirl/setaux.f", "max_issues_repo_name": "ClimateImpactLab/clawutil", "max_issues_repo_head_hexsha": "10edc50de410eeaa768932af89540cee45476d27", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 107, "max_issues_repo_issues_event_min_datetime": "2015-01-02T19:51:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-24T03:35:32.000Z", "max_forks_repo_path": "dev/advection_3d_swirl/setaux.f", "max_forks_repo_name": "ClimateImpactLab/clawutil", "max_forks_repo_head_hexsha": "10edc50de410eeaa768932af89540cee45476d27", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 28, "max_forks_repo_forks_event_min_datetime": "2015-01-10T00:03:56.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-11T23:52:34.000Z", "avg_line_length": 26.1860465116, "max_line_length": 72, "alphanum_fraction": 0.5062166963, "num_tokens": 793, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467580102418, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6533537504294838}} {"text": "module mod_polynomial\n#include \n use mod_kinds, only: rk,ik\n use type_point, only: point_t\n\n use mod_legendre\n use mod_lagrange\n use mod_ordering\n implicit none\n\ncontains\n\n\n\n\n !> Return value of a term in a polynomial expansion at a specified (xi, eta, zeta) location.\n !!\n !! @author Nathan A. Wukie\n !!\n !! @param[in] spacedim Integer specifying whether to compute the 1D, 2D, \n !! or 3D expansion function. \n !! @param[in] nterms Number of terms in the polynomial expansion.\n !! @param[in] mode Integer of the mode in the expansion to be computed.\n !! @param[in] node point_t containing (xi,eta,zeta) location on reference element.\n !!\n !-----------------------------------------------------------------------------------------\n function polynomial_val(spacedim,nterms,mode,node) result(polyval)\n integer(ik), intent(in) :: spacedim\n integer(ik), intent(in) :: nterms\n integer(ik), intent(in) :: mode\n real(rk), intent(in) :: node(3)\n\n real(rk) :: polyval\n\n polyval = legendre_val(spacedim,mode,node(1),node(2),node(3))\n\n end function polynomial_val\n !*****************************************************************************************\n\n\n\n\n\n\n\n !> Return directional derivative of a term in a polynomial expansion at a specified \n !! (xi, eta, zeta) location.\n !!\n !! @author Nathan A. Wukie\n !!\n !! @param[in] spacedim Integer specifying whether to compute the 1D, 2D, \n !! or 3D expansion function.\n !! @param[in] nterms Number of terms in the polynomial expansion.\n !! @param[in] mode Integer of the mode in the expansion to be computed.\n !! @param[in] node point_t containing (xi,eta,zeta) location on reference element.\n !! @param[in] dir Integer indicating direction of the derivative (xi, eta, zeta).\n !!\n !----------------------------------------------------------------------------------------\n function dpolynomial_val(spacedim,nterms,mode,node,dir) result(dpolyval)\n integer(ik), intent(in) :: spacedim\n integer(ik), intent(in) :: nterms\n integer(ik), intent(in) :: mode\n real(rk), intent(in) :: node(3)\n integer(ik), intent(in) :: dir\n\n real(rk) :: dpolyval\n\n dpolyval = dlegendre_val(spacedim,mode,node(1),node(2),node(3),dir)\n\n end function dpolynomial_val\n !****************************************************************************************\n\n\n\n\n\n !> Return second/mixed derivative of a term in a polynomial expansion at a specified \n !! (xi, eta, zeta) location.\n !!\n !! @author Nathan A. Wukie (AFRL)\n !! @date 8/7/2017\n !!\n !! @param[in] spacedim Integer specifying whether to compute the 1D, 2D, \n !! or 3D expansion function.\n !! @param[in] nterms Number of terms in the polynomial expansion.\n !! @param[in] mode Integer of the mode in the expansion to be computed.\n !! @param[in] node point_t containing (xi,eta,zeta) location on reference element.\n !! @param[in] dir Integer indicating direction of the derivative (xi, eta, zeta).\n !!\n !----------------------------------------------------------------------------------------\n function ddpolynomial_val(spacedim,nterms,mode,node,partial1,partial2) result(res)\n integer(ik), intent(in) :: spacedim\n integer(ik), intent(in) :: nterms\n integer(ik), intent(in) :: mode\n real(rk), intent(in) :: node(3)\n integer(ik), intent(in) :: partial1\n integer(ik), intent(in) :: partial2\n\n real(rk) :: res\n\n res = ddlegendre_val(spacedim,mode,node(1),node(2),node(3),partial1,partial2)\n\n end function ddpolynomial_val\n !****************************************************************************************\n\n\n\n\n\n\n\n\nend module mod_polynomial\n", "meta": {"hexsha": "38c627f51e0e209c8c96efe46fb0f798201ec68f", "size": 4103, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/polynomial/mod_polynomial.f90", "max_stars_repo_name": "wanglican/ChiDG", "max_stars_repo_head_hexsha": "d3177b87cc2f611e66e26bb51616f9385168f338", "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/polynomial/mod_polynomial.f90", "max_issues_repo_name": "haohb/ChiDG", "max_issues_repo_head_hexsha": "d3177b87cc2f611e66e26bb51616f9385168f338", "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/polynomial/mod_polynomial.f90", "max_forks_repo_name": "haohb/ChiDG", "max_forks_repo_head_hexsha": "d3177b87cc2f611e66e26bb51616f9385168f338", "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": 35.9912280702, "max_line_length": 96, "alphanum_fraction": 0.5159639288, "num_tokens": 1026, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467580102419, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6533537504294838}} {"text": " SUBROUTINE cumt(t,df,cum,ccum)\nC**********************************************************************\nC\nC SUBROUTINE CUMT(T,DF,CUM,CCUM)\nC CUMulative T-distribution\nC\nC\nC Function\nC\nC\nC Computes the integral from -infinity to T of the t-density.\nC\nC\nC Arguments\nC\nC\nC T --> Upper limit of integration of the t-density.\nC T is DOUBLE PRECISION\nC\nC DF --> Degrees of freedom of the t-distribution.\nC DF is DOUBLE PRECISIO\nC\nC CUM <-- Cumulative t-distribution.\nC CCUM is DOUBLE PRECIS\nC\nC CCUM <-- Compliment of Cumulative t-distribution.\nC CCUM is DOUBLE PRECIS\nC\nC\nC Method\nC\nC\nC Formula 26.5.27 of Abramowitz and Stegun, Handbook of\nC Mathematical Functions is used to reduce the t-distribution\nC to an incomplete beta.\nC\nC**********************************************************************\n\nC .. Scalar Arguments ..\n DOUBLE PRECISION df,t,cum,ccum\nC ..\nC .. Local Scalars ..\n DOUBLE PRECISION xx,a,oma,tt,yy,dfptt\nC ..\nC .. External Subroutines ..\n EXTERNAL cumbet\nC ..\nC .. Executable Statements ..\n tt = t*t\n dfptt = df + tt\n xx = df/dfptt\n yy = tt/dfptt\n CALL cumbet(xx,yy,0.5D0*df,0.5D0,a,oma)\n IF (.NOT. (t.LE.0.0D0)) GO TO 10\n cum = 0.5D0*a\n ccum = oma + cum\n GO TO 20\n\n 10 ccum = 0.5D0*a\n cum = oma + ccum\n 20 RETURN\n\n END\n", "meta": {"hexsha": "c69d71847ab8bf8dc084822b5a492b3101b9e5ec", "size": 1702, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "scipy/special/cdflib/cumt.f", "max_stars_repo_name": "Ennosigaeon/scipy", "max_stars_repo_head_hexsha": "2d872f7cf2098031b9be863ec25e366a550b229c", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9095, "max_stars_repo_stars_event_min_datetime": "2015-01-02T18:24:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T20:35:31.000Z", "max_issues_repo_path": "scipy/special/cdflib/cumt.f", "max_issues_repo_name": "Ennosigaeon/scipy", "max_issues_repo_head_hexsha": "2d872f7cf2098031b9be863ec25e366a550b229c", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 11500, "max_issues_repo_issues_event_min_datetime": "2015-01-01T01:15:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T23:07:35.000Z", "max_forks_repo_path": "scipy/special/cdflib/cumt.f", "max_forks_repo_name": "Ennosigaeon/scipy", "max_forks_repo_head_hexsha": "2d872f7cf2098031b9be863ec25e366a550b229c", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5838, "max_forks_repo_forks_event_min_datetime": "2015-01-05T11:56:42.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T23:21:19.000Z", "avg_line_length": 26.59375, "max_line_length": 72, "alphanum_fraction": 0.4547591069, "num_tokens": 454, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467548438126, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6533537380745077}} {"text": "program test10\n#if (_DP==0)\n use iso_fortran_env,only:int32,int64,wp=>real32\n#else\n use iso_fortran_env,only:int32,int64,wp=>real64\n#endif\n#if (_METIS==1)\n use modmetis,only:METIS_CTYPE_SHEM\n#endif\n use modsparse\n implicit none\n integer(kind=int32)::nrow\n integer(kind=int32)::row\n integer(kind=int32)::col\n integer(kind=int32)::iunit, istat\n integer(kind=int32)::i,j\n integer(kind=int32),allocatable::iarray(:,:)\n integer(kind=int32),allocatable::perm(:)\n real(kind=wp)::val\n real(kind=wp),allocatable::x(:),y(:)\n real(kind=wp),allocatable::xx(:)\n logical::lup=.false.\n type(coosparse)::coo\n type(crssparse)::crs\n type(crssparse)::crs1\n\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \n !COO UPPER\n open(newunit=iunit,file='crsinput.ascii',status='old',action='read')\n read(iunit,*) nrow\n\n coo=coosparse(5,lupper=.true.)\n\n call coo%setsymmetric()\n\n do\n read(iunit,*,iostat=istat) row,col,val\n if(istat.ne.0)exit\n call coo%add(row,col,val)\n end do\n close(iunit)\n\n call coo%add(1,1,10._wp)\n call coo%add(2,2,10._wp)\n call coo%add(3,3,10._wp)\n! call coo%add(4,4,1._wp)\n call coo%add(5,5,1._wp)\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \n !CSR UPPER\n crs=coo\n\n call crs%printsquare()\n\n !perm=crs%getordering()\n#if (_METIS==1)\n perm=crs%getordering(compress=1,ctype=METIS_CTYPE_SHEM)\n#else\n perm=(/(i,i=1,crs%getdim(1))/)\n#endif\n\n call crs%printstats()\n\n call crs%setpermutation(perm)\n call crs%printstats()\n\n allocate(x(crs%getdim(1)),y(crs%getdim(1)))\n do i=1,crs%getdim(1)\n y(i)=i\n enddo\n y(4)=0\n print*,'y=[',y,' ]'\n\n \n x=0._wp\n xx=x\n call coo%cg(xx,y)\n\n call crs%solve(x,y)\n print*,'xx ',xx\n print*,' x ',x\n\n\nend program\n", "meta": {"hexsha": "a59541179c10800836307ffdf4ec547568233eaf", "size": 1688, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/test10.f90", "max_stars_repo_name": "jvdp1/libsparse", "max_stars_repo_head_hexsha": "eaf5ec8e45bce873154aff24c2143b8f00df63a8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2019-08-03T14:17:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-14T04:31:16.000Z", "max_issues_repo_path": "examples/test10.f90", "max_issues_repo_name": "jvdp1/libsparse", "max_issues_repo_head_hexsha": "eaf5ec8e45bce873154aff24c2143b8f00df63a8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-09-06T21:38:44.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-08T16:02:40.000Z", "max_forks_repo_path": "examples/test10.f90", "max_forks_repo_name": "jvdp1/libsparse", "max_forks_repo_head_hexsha": "eaf5ec8e45bce873154aff24c2143b8f00df63a8", "max_forks_repo_licenses": ["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.0952380952, "max_line_length": 76, "alphanum_fraction": 0.6261848341, "num_tokens": 604, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199714402812, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6533376265507135}} {"text": "program FizzBuzz\n implicit none\n character(len=4), dimension(100) :: fizzs = '', buzzs = ''\n integer :: i\n \n where (mod( (/ (i,i=1,100) /), 3) == 0) fizzs = 'Fizz'\n where (mod( (/ (i,i=1,100) /), 5) == 0) buzzs = 'Buzz'\n\n do i=1, 100\n if (fizzs(i)/='' .or. buzzs(i)/='') then\n print*, trim(fizzs(i))//trim(buzzs(i))\n else\n write(*,'(A,I0)') ' ', i\n end if\n end do\n \nend program FizzBuzz\n", "meta": {"hexsha": "e594f07dc4d7146b321be69e2bb3b094d8e11c39", "size": 457, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "FizzBuzz.f90", "max_stars_repo_name": "cmplopes/fortran", "max_stars_repo_head_hexsha": "9bffbcb09b3aaad9666210481fcc51d8044b6b4a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "FizzBuzz.f90", "max_issues_repo_name": "cmplopes/fortran", "max_issues_repo_head_hexsha": "9bffbcb09b3aaad9666210481fcc51d8044b6b4a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "FizzBuzz.f90", "max_forks_repo_name": "cmplopes/fortran", "max_forks_repo_head_hexsha": "9bffbcb09b3aaad9666210481fcc51d8044b6b4a", "max_forks_repo_licenses": ["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.3888888889, "max_line_length": 62, "alphanum_fraction": 0.466083151, "num_tokens": 166, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.837619947119304, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6533376118642775}} {"text": "module matrix_mod\r\nuse iso_c_binding, only: c_int, c_float\r\nimplicit none\r\ninterface\r\nsubroutine print_mat(nrow_c, ncol_c, x) bind(c,name=\"print_mat_transpose\")\r\nimport c_int, c_float\r\ninteger(kind=c_int), intent(in), value :: nrow_c, ncol_c\r\nreal(kind=c_float) , intent(in) :: x(ncol_c,nrow_c)\r\nend subroutine print_mat\r\n!\r\nfunction sum_mat(nrow_c,ncol_c,x) result(xsum) bind(c)\r\nimport c_int, c_float\r\ninteger(kind=c_int), intent(in), value :: nrow_c, ncol_c\r\nreal(kind=c_float) , intent(in) :: x(ncol_c,nrow_c)\r\nend function sum_mat\r\n!\r\nsubroutine sum_cols(nrow_c,ncol_c,x,col_sums) bind(c,name=\"sum_rows\")\r\nimport c_int, c_float\r\ninteger(kind=c_int), intent(in), value :: nrow_c, ncol_c\r\nreal(kind=c_float) , intent(in) :: x(ncol_c,nrow_c)\r\nreal(kind=c_float) , intent(out) :: col_sums(nrow_c)\r\nend subroutine sum_cols\r\n!\r\nsubroutine scale_mat(xscale, nrow_c, ncol_c, x) bind(c,name=\"scale_mat\")\r\nimport c_int, c_float\r\nreal(kind=c_float) , intent(in), value :: xscale\r\ninteger(kind=c_int), intent(in), value :: nrow_c, ncol_c\r\nreal(kind=c_float) , intent(in) :: x(ncol_c,nrow_c)\r\nend subroutine scale_mat\r\n!\r\nend interface\r\n!\r\ncontains\r\nfunction column_sums(x) result(col_sums)\r\nreal(kind=c_float), intent(in) :: x(:,:)\r\nreal(kind=c_float) :: col_sums(size(x,2))\r\ncall sum_cols(size(x,2),size(x,1),x,col_sums)\r\nend function column_sums\r\nend module matrix_mod\r\n\r\nprogram xxmat\r\nuse matrix_mod, only: c_float, print_mat, sum_mat, sum_cols, scale_mat, &\r\n column_sums\r\nimplicit none\r\ninteger, parameter :: nr = 2, nc = 3\r\nreal(kind=c_float) :: x(nr,nc),row_sums(nr),col_sums(nc)\r\ninteger :: ir,ic\r\ncharacter (len=20) :: fmt=\"(a,*(1x,f0.1))\"\r\nprint*,\"matrix\"\r\ndo ir=1,nr\r\n do ic=1,nc\r\n x(ir,ic) = real(10*ir + ic, kind = c_float)\r\n end do\r\n print \"(*(1x,f5.1))\",x(ir,:)\r\nend do\r\nprint \"(/,a)\", \"calling print_mat\"\r\ncall print_mat(nrow_c=nc, ncol_c=nr, x=x)\r\nprint*\r\nprint fmt,\"sum_mat(nr,nc,x), sum(x) =\",sum_mat(nr,nc,x),sum(x)\r\ncall sum_cols(nrow_c=nc, ncol_c=nr, x=x, col_sums=col_sums)\r\nprint fmt,\"col_sums =\",col_sums\r\nprint fmt,\"col_sums =\",column_sums(x)\r\nprint fmt,\"sum(x,dim=1) =\",sum(x,dim=1)\r\ncall scale_mat(xscale=10.0, nrow_c=nc, ncol_c=nr, x=x)\r\nprint \"(/,a)\",\"matrix after scaling:\"\r\ncall print_mat(nrow_c=nc, ncol_c=nr, x=x)\r\nend program xxmat\r\n! Compile with\r\n! gcc -c -o sum_mat.o sum_mat.c\r\n! gfortran sum_mat.o xxmat.f90\r\n! output:\r\n! matrix\r\n! 11.0 12.0 13.0\r\n! 21.0 22.0 23.0\r\n! \r\n! calling print_mat\r\n! 11.000000 12.000000 13.000000\r\n! 21.000000 22.000000 23.000000\r\n! \r\n! sum_mat(nr,nc,x), sum(x) = 102.0 102.0\r\n! col_sums = 32.0 34.0 36.0\r\n! col_sums = 32.0 34.0 36.0\r\n! sum(x,dim=1) = 32.0 34.0 36.0\r\n! \r\n! matrix after scaling:\r\n! 110.000000 120.000000 130.000000\r\n! 210.000000 220.000000 230.000000", "meta": {"hexsha": "7bf54fdd074b5f609b0e4671e6141ee7661941ea", "size": 2821, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "xxmat.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": "xxmat.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": "xxmat.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": 32.4252873563, "max_line_length": 75, "alphanum_fraction": 0.6696207019, "num_tokens": 992, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.837619947119304, "lm_q2_score": 0.7799929002541068, "lm_q1q2_score": 0.6533376118642775}} {"text": "!==============================================================================!\n real function U_Plus_Log_Law(turb, y_plus)\n!------------------------------------------------------------------------------!\n! Calculates U+ from log law. !\n!------------------------------------------------------------------------------!\n!----------------------------------[Modules]-----------------------------------!\n use Turb_Mod, only: Turb_Type, e_log, kappa\n!------------------------------------------------------------------------------!\n implicit none\n!---------------------------------[Arguments]----------------------------------!\n type(Turb_Type) :: turb\n real :: y_plus\n!==============================================================================!\n\n U_Plus_Log_Law = log( max(y_plus, 1.05) * e_log ) / kappa\n\n end function\n", "meta": {"hexsha": "023def67f604ccbe53f45b4218ace72a5e8d1d8e", "size": 886, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Sources/Process/Turb_Mod/U_Plus_Log_Law.f90", "max_stars_repo_name": "Dundj/Convex_Geomotry", "max_stars_repo_head_hexsha": "38507824d97270b3e4ead194a16148ff6158b59f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 64, "max_stars_repo_stars_event_min_datetime": "2018-05-29T09:39:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T13:59:18.000Z", "max_issues_repo_path": "Sources/Process/Turb_Mod/U_Plus_Log_Law.f90", "max_issues_repo_name": "EdinSmartLab/T-Flows", "max_issues_repo_head_hexsha": "5a7f70421f18069453977142e6515cdc959a9e50", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 124, "max_issues_repo_issues_event_min_datetime": "2018-05-28T12:58:20.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-03T11:12:31.000Z", "max_forks_repo_path": "Sources/Process/Turb_Mod/U_Plus_Log_Law.f90", "max_forks_repo_name": "EdinSmartLab/T-Flows", "max_forks_repo_head_hexsha": "5a7f70421f18069453977142e6515cdc959a9e50", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 39, "max_forks_repo_forks_event_min_datetime": "2018-05-28T13:13:06.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-27T17:41:08.000Z", "avg_line_length": 49.2222222222, "max_line_length": 80, "alphanum_fraction": 0.2212189616, "num_tokens": 129, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026573249611, "lm_q2_score": 0.7122321903471565, "lm_q1q2_score": 0.6533324808378241}} {"text": "MODULE PekRoot\r\n\r\n ! evaluates a particular branch of the square root that exposes leaky modes\r\n\r\n IMPLICIT NONE\r\n\r\n CONTAINS\r\n FUNCTION PekerisRoot( z )\r\n\r\n ! At one time, this was used to return the 'Pekeris branch cut' \r\n ! which is just a particular branch of the square root that \r\n ! exposes many 'leaky' or 'virtual' modes. \r\n\r\n ! The current version implements a particular branch that was convenient \r\n\r\n COMPLEX (KIND=8), INTENT( IN ) :: z\r\n COMPLEX (KIND=8) :: PekerisRoot\r\n\r\n IF ( REAL( z ) >= 0.0D0 ) THEN \r\n PekerisRoot = SQRT( z ) \r\n ELSE \r\n PekerisRoot = ( 0.0D0, 1.0D0 ) * SQRT( -z ) \r\n ENDIF\r\n\r\n END FUNCTION PekerisRoot\r\nEND MODULE PekRoot\r\n", "meta": {"hexsha": "3d50feea22803046f77b661180d5e994f175e890", "size": 833, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "at_2020_11_4/misc/PekRoot.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/PekRoot.f90", "max_issues_repo_name": "IvanaEscobar/sandbox", "max_issues_repo_head_hexsha": "71d62af2c112686c5ce26def35593247cf6a0ccc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2022-02-15T23:32:52.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T21:35:12.000Z", "max_forks_repo_path": "at_2020_11_4/misc/PekRoot.f90", "max_forks_repo_name": "IvanaEscobar/sandbox", "max_forks_repo_head_hexsha": "71d62af2c112686c5ce26def35593247cf6a0ccc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.8518518519, "max_line_length": 130, "alphanum_fraction": 0.5354141657, "num_tokens": 216, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026528034425, "lm_q2_score": 0.7122321903471563, "lm_q1q2_score": 0.653332477617453}} {"text": "! Mikayla Webber\r\n! 4670 Numerical Analysis\r\n! Homework\r\n\r\nmodule secret\r\n\r\ninteger :: fcounter\r\n\r\nend module secret\r\n\r\n!-----------------------------------------------------------------------------------------------------\r\n\r\nprogram WebberHomework\r\nuse secret\r\nimplicit none\r\n\r\nreal, allocatable :: y(:), t(:)\r\nreal :: yo, tmax, h, k1, k2, y1, f\r\ninteger :: ni, i\r\n\r\nprint*, 'Enter yo, tmax, ni'\r\nread*, yo, tmax, ni\r\nh = tmax/ni\r\nprint*, 'This gives stepsize h=', h\r\nallocate(t(0:ni), y(0:ni))\r\n\r\nt(0) = 0\r\nt(1) = h\r\ny(0) = 1\r\nk1 = -16*h**3\r\ny1 = y(0) + h/2 *(k1 + k2)\r\ndo i = 2, ni\r\n t(i) = i*h\r\n y(i) = y(i-1) + (h/2)*(3*f(t(i-1), y(i - 1))- f(t(i-2), y(i-2)))\r\nend do\r\n\r\nstop\r\nend program WebberHomework\r\n\r\n!-----------------------------------------------------------------------------------------------------\r\nreal function f(t,y)\r\n real :: t,y\r\n\r\n f = -16*t**3*y**2\r\n\r\n return\r\nend\r\n", "meta": {"hexsha": "4ae6eb368b15694005e07048847216fcfde387c0", "size": 895, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "4670 Numerical Analysis/Class Examples/DifferentialEquations.f90", "max_stars_repo_name": "mwebber3/UnderGraduateCourses", "max_stars_repo_head_hexsha": "0040791609ad4dd4336077f072106f8f31fdf8df", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "4670 Numerical Analysis/Class Examples/DifferentialEquations.f90", "max_issues_repo_name": "mwebber3/UnderGraduateCourses", "max_issues_repo_head_hexsha": "0040791609ad4dd4336077f072106f8f31fdf8df", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "4670 Numerical Analysis/Class Examples/DifferentialEquations.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": 18.6458333333, "max_line_length": 103, "alphanum_fraction": 0.4189944134, "num_tokens": 285, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026482819236, "lm_q2_score": 0.7122321781307374, "lm_q1q2_score": 0.6533324631909282}} {"text": " FUNCTION bessy(n,x)\r\n INTEGER n\r\n REAL bessy,x\r\nCU USES bessy0,bessy1\r\n INTEGER j\r\n REAL by,bym,byp,tox,bessy0,bessy1\r\n if(n.lt.2)pause 'bad argument n in bessy'\r\n tox=2./x\r\n by=bessy1(x)\r\n bym=bessy0(x)\r\n do 11 j=1,n-1\r\n byp=j*tox*by-bym\r\n bym=by\r\n by=byp\r\n11 continue\r\n bessy=by\r\n return\r\n END\r\n", "meta": {"hexsha": "1c29a5c7ff42c319a167cb11581f2c9b03ea842b", "size": 390, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/bessy.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/bessy.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/bessy.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.5263157895, "max_line_length": 48, "alphanum_fraction": 0.5025641026, "num_tokens": 146, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240964782012, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6531706374303968}} {"text": "! Riemann solver for the variable speed limit LWR traffic model\n\n! q_t + (u_max(x,t) q(1-q))_x = 0\n\n! Here the speed limit u_max (stored in aux(1,i) may vary with x and t.\n\n! waves: 1\n! equations: 1\n! aux fields: 1\n\n! Conserved quantities:\n! 1 q\n\n! Auxiliary variables:\n! 1 u_max\n\n! See http://www.clawpack.org/riemann.html for a detailed explanation\n! of the Riemann solver API.\n\nsubroutine rp1(maxm,num_eqn,num_waves,num_aux,num_ghost,num_cells, &\n ql,qr,auxl,auxr,wave,s,amdq,apdq)\n implicit none\n ! Inputs\n integer, intent(in) :: maxm, num_eqn, num_waves, num_aux, num_ghost, num_cells\n double precision, intent(in), dimension(num_eqn, 1-num_ghost:maxm+num_ghost) :: ql,qr\n double precision, intent(in), dimension(num_aux, 1-num_ghost:maxm+num_ghost) :: auxl,auxr\n ! Outputs\n double precision, intent(out) :: s(num_waves,1-num_ghost:num_cells+num_ghost)\n double precision, intent(out) :: wave(num_eqn,num_waves,1-num_ghost:num_cells+num_ghost)\n double precision, intent(out), dimension(num_eqn, 1-num_ghost:maxm+num_ghost) :: amdq,apdq\n ! Locals\n double precision :: f_l, f_r, s_l, s_r, f0, q_l, q_r, v_l, v_r\n integer :: i\n\n do i = 2-num_ghost, num_cells+num_ghost\n q_r = ql(1,i)\n q_l = qr(1,i-1)\n v_r = auxl(1,i)\n v_l = auxr(1,i-1)\n\n ! compute characteristic speed in each cell:\n s_l = v_l*(1.d0 - 2.d0*q_l)\n s_r = v_r*(1.d0 - 2.d0*q_r)\n\n ! compute flux in each cell and flux difference:\n f_l = v_l*q_l*(1.d0 - q_l)\n f_r = v_r*q_r*(1.d0 - q_r)\n\n ! This seems to work well even though there can be\n ! a stationary jump in q.\n wave(1,1,i) = q_r - q_l\n s(1,i) = 0.5d0*(s_l + s_r)\n\n if ((f_l .ge. 0.25d0*v_r) .and. (s_r .gt. 0.d0)) then\n ! left-going shock, right-going rarefaction\n f0 = 0.25d0*v_r\n elseif ((f_r .ge. 0.25d0*v_l) .and. (s_l .lt. 0.d0)) then\n ! right-going shock, left-going rarefaction\n f0 = 0.25d0*v_l\n elseif ((s_r .le. 0.d0) .and. (f_l .gt. f_r)) then\n ! left-going shock\n f0 = f_r\n elseif ((s_l .ge. 0.d0) .and. (f_r .gt. f_l)) then\n ! right-going shock\n f0 = f_l\n elseif ((s_l .le. 0.d0) .and. (s_r .ge. 0.d0)) then\n ! Transonic rarefaction\n if (v_r .le. v_l) then\n f0 = 0.25d0*v_r\n else\n f0 = 0.25d0*v_l\n endif\n elseif (f_l .le. f_r) then\n ! left-going rarefaction\n f0 = f_r\n else\n ! right-going rarefaction\n f0 = f_l\n endif\n amdq(1,i) = f0 - f_l\n apdq(1,i) = f_r - f0\n\n\n enddo\n return\nend subroutine rp1\n", "meta": {"hexsha": "189ecacd05bb05bf22d87e12cbe3a1a82fc19680", "size": 2775, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/rp1_traffic_vc.f90", "max_stars_repo_name": "ranocha/riemann", "max_stars_repo_head_hexsha": "d7b4d72d1147eee12e60a64f46a7e076b28a212d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 27, "max_stars_repo_stars_event_min_datetime": "2015-03-08T03:42:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-21T01:46:12.000Z", "max_issues_repo_path": "src/rp1_traffic_vc.f90", "max_issues_repo_name": "ranocha/riemann", "max_issues_repo_head_hexsha": "d7b4d72d1147eee12e60a64f46a7e076b28a212d", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 47, "max_issues_repo_issues_event_min_datetime": "2015-02-11T15:39:22.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-25T01:56:46.000Z", "max_forks_repo_path": "src/rp1_traffic_vc.f90", "max_forks_repo_name": "ranocha/riemann", "max_forks_repo_head_hexsha": "d7b4d72d1147eee12e60a64f46a7e076b28a212d", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 37, "max_forks_repo_forks_event_min_datetime": "2015-01-09T21:44:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-21T12:53:04.000Z", "avg_line_length": 31.8965517241, "max_line_length": 94, "alphanum_fraction": 0.5700900901, "num_tokens": 940, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6531706317070295}} {"text": "program matMulFortran\n integer i,j,k\n integer, parameter :: n=1000\n real*8 :: a(n,n), b(n,n), c(n,n)\n do i=1,n\n do j=1,n\n a(i,j) = i*j\n b(i,j) = i-j\n enddo\n enddo\n print *, \"Data initialized\"\n do i=1,n\n do j=1,n\n c(i,j) = 0.d0\n do k=1,n\n c(i,j)=c(i,j)+a(i,k)*b(k,j)\n enddo\n enddo\n enddo\n\n ! CHECK FOR 3x3 MATRIX\n ! do i=1,n\n ! print *, c(i,1:3)\n ! enddo\n\nend program matMulFortran\n", "meta": {"hexsha": "c8783683750f871851d2e9b6f3bbff62c4c2a19d", "size": 439, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Example2/matMul_naiveFORTRAN.f90", "max_stars_repo_name": "danielpecak/myLittleCuda", "max_stars_repo_head_hexsha": "3e7476f8fca04dd17752f77f3c9185bf02ddea6c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Example2/matMul_naiveFORTRAN.f90", "max_issues_repo_name": "danielpecak/myLittleCuda", "max_issues_repo_head_hexsha": "3e7476f8fca04dd17752f77f3c9185bf02ddea6c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Example2/matMul_naiveFORTRAN.f90", "max_forks_repo_name": "danielpecak/myLittleCuda", "max_forks_repo_head_hexsha": "3e7476f8fca04dd17752f77f3c9185bf02ddea6c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.2592592593, "max_line_length": 35, "alphanum_fraction": 0.5056947608, "num_tokens": 189, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276222, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6531706274124752}} {"text": "C$Procedure PI ( Value of pi )\n \n DOUBLE PRECISION FUNCTION PI ( )\n \nC$ Abstract\nC\nC Return the value of pi (the ratio of the circumference of\nC a circle to its diameter).\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 CONSTANTS\nC\nC$ Declarations\nC\nC None.\nC\nC$ Brief_I/O\nC\nC The function returns the value of pi.\nC\nC$ Detailed_Input\nC\nC None.\nC\nC$ Detailed_Output\nC\nC The function returns the value of pi (the ratio of a circle's\nC circumference to its diameter), determined by the ACOS function.\nC That is,\nC\nC PI = ACOS ( -1.D0 )\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 first time the function is referenced, the value is computed\nC as shown above. The value is saved, and returned directly upon\nC subsequent reference.\nC\nC$ Examples\nC\nC The code fragment below illustrates the use of PI.\nC\nC C\nC C Compute the polar radius,\nC C\nC C p\nC C ----------------\nC C 1 + e cos(theta)\nC C\nC C at evenly spaced values of the polar angle, theta.\nC C\nC DELTA = PI() / N\nC\nC DO I = 0, N\nC R(I) = P / (1.D0 + ECC * COS(I*DELTA))\nC END DO\nC\nC$ Restrictions\nC\nC None.\nC\nC$ Literature_References\nC\nC None.\nC\nC$ Author_and_Institution\nC\nC W.L. Taber (JPL)\nC I.M. Underwood (JPL)\nC\nC$ Version\nC\nC- SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)\nC\nC Comment section for permuted index source lines was added\nC following the header.\nC\nC- SPICELIB Version 1.0.0, 31-JAN-1990 (WLT) (IMU)\nC\nC-&\n \nC$ Index_Entries\nC\nC value of pi\nC\nC-&\n \n \n \n \nC\nC Local variables\nC\n DOUBLE PRECISION VALUE\n SAVE VALUE\n \nC\nC Initial values\nC\n DATA VALUE / 0.D0 /\n \n \nC\nC What is there to say?\nC\n IF ( VALUE .EQ. 0.D0 ) THEN\n VALUE = ACOS ( -1.D0 )\n END IF\n \n PI = VALUE\n \n RETURN\n END\n \n", "meta": {"hexsha": "12b03f0604ebb742f8d1553800f57daf372e8e8a", "size": 3481, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/nasa_f/pi.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/pi.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/pi.f", "max_forks_repo_name": "agforero/fortran-testing-framework", "max_forks_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-31T08:41:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T08:41:53.000Z", "avg_line_length": 22.1719745223, "max_line_length": 71, "alphanum_fraction": 0.633438667, "num_tokens": 1023, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240791017536, "lm_q2_score": 0.7549149868676284, "lm_q1q2_score": 0.6531706243126562}} {"text": "PROGRAM F096\n\n ! Copyright 2021 Melwyn Francis Carlo\n\n IMPLICIT NONE\n\n INTEGER, DIMENSION(50, 9, 9) :: SUDOKU\n\n INTEGER :: SUM_VAL = 0\n INTEGER :: INDEX_VAL = 0\n INTEGER :: SUB_INDEX = 1\n\n INTEGER :: I, I2, J, J2, K, L, PUZZLE\n\n LOGICAL :: DUPLICATE_FOUND\n\n LOGICAL, DIMENSION(9, 9, 9) :: DIGIT\n LOGICAL, DIMENSION(9, 9) :: IS_FIXED_CELL\n\n CHARACTER (LEN=30), PARAMETER :: FILENAME = \"problems/096/p096_sudoku.txt\"\n CHARACTER (LEN=30) :: NUM_STR\n\n OPEN (2, FILE = FILENAME, STATUS = 'OLD')\n\n DO\n READ(2, *, END=10) NUM_STR\n\n IF (NUM_STR(1:1) < '0' .OR. NUM_STR(1:1) > '9') THEN\n SUB_INDEX = 1\n INDEX_VAL = INDEX_VAL + 1\n CYCLE\n\n END IF\n\n DO I = 1, 9\n SUDOKU(INDEX_VAL, SUB_INDEX, I) = IACHAR(NUM_STR(I:I)) - IACHAR('0')\n END DO\n SUB_INDEX = SUB_INDEX + 1\n END DO\n\n 10 CLOSE(2)\n\n DO PUZZLE = 1, 50\n\n IS_FIXED_CELL = .FALSE.\n\n DO I = 1, 9\n DO J = 1, 9\n IF (SUDOKU(PUZZLE, I, J) /= 0) IS_FIXED_CELL(I, J) = .TRUE.\n END DO\n END DO\n\n DIGIT = .FALSE.\n\n I = 1\n DO WHILE (I <= 9)\n J = 1\n DO WHILE (J <= 9)\n\n IF (IS_FIXED_CELL(I, J)) THEN\n J = J + 1\n CYCLE\n END IF\n\n I2 = (INT((I - 1) / 3) * 3) + 1\n J2 = (INT((J - 1) / 3) * 3) + 1\n\n DUPLICATE_FOUND = .TRUE.\n\n IF (.NOT. DIGIT(I, J, 1) .OR. .NOT. DIGIT(I, J, 2) &\n .OR. .NOT. DIGIT(I, J, 3) .OR. .NOT. DIGIT(I, J, 4) &\n .OR. .NOT. DIGIT(I, J, 5) .OR. .NOT. DIGIT(I, J, 6) &\n .OR. .NOT. DIGIT(I, J, 7) .OR. .NOT. DIGIT(I, J, 8) &\n .OR. .NOT. DIGIT(I, J, 9)) THEN\n\n DO K = 1, 9\n\n IF (DIGIT(I, J, K)) CYCLE\n\n DUPLICATE_FOUND = .FALSE.\n\n DO L = 1, 9\n IF (L /= I) THEN\n IF (SUDOKU(PUZZLE, L, J) == K) THEN\n DUPLICATE_FOUND = .TRUE.\n EXIT\n END IF\n END IF\n IF (L /= J) THEN\n IF (SUDOKU(PUZZLE, I, L) == K) THEN\n DUPLICATE_FOUND = .TRUE.\n EXIT\n END IF\n END IF\n END DO\n\n IF (.NOT. DUPLICATE_FOUND) THEN\n IF ((SUDOKU(PUZZLE, I2, J2) == K) &\n .OR. (SUDOKU(PUZZLE, I2, J2 + 1) == K) &\n .OR. (SUDOKU(PUZZLE, I2, J2 + 2) == K) &\n .OR. (SUDOKU(PUZZLE, I2 + 1, J2) == K) &\n .OR. (SUDOKU(PUZZLE, I2 + 1, J2 + 1) == K) &\n .OR. (SUDOKU(PUZZLE, I2 + 1, J2 + 2) == K) &\n .OR. (SUDOKU(PUZZLE, I2 + 2, J2) == K) &\n .OR. (SUDOKU(PUZZLE, I2 + 2, J2 + 1) == K) &\n .OR. (SUDOKU(PUZZLE, I2 + 2, J2 + 2) == K)) THEN\n\n DUPLICATE_FOUND = .TRUE.\n\n END IF\n END IF\n\n IF (.NOT. DUPLICATE_FOUND) THEN\n DIGIT(I, J, K) = .TRUE.\n SUDOKU(PUZZLE, I, J) = K\n EXIT\n END IF\n\n END DO\n\n END IF\n\n IF (DUPLICATE_FOUND) THEN\n\n DIGIT(I, J, 1:9) = .FALSE.\n SUDOKU(PUZZLE, I, J) = 0\n\n J = J - 1\n IF (J == 0) THEN\n J = 9\n I = I - 1\n END IF\n\n DO WHILE (IS_FIXED_CELL(I, J))\n J = J - 1\n IF (J == 0) THEN\n J = 9\n I = I - 1\n END IF\n END DO\n\n ELSE\n J = J + 1\n END IF\n\n END DO\n I = I + 1\n END DO\n SUM_VAL = SUM_VAL + (SUDOKU(PUZZLE, 1, 1) * 100) + &\n (SUDOKU(PUZZLE, 1, 2) * 10) + &\n (SUDOKU(PUZZLE, 1, 3))\n END DO\n\n PRINT ('(I0)'), SUM_VAL\n\nEND PROGRAM F096\n", "meta": {"hexsha": "95e830468d255d9cbb355caba0f5c75b28ddd2b4", "size": 4814, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "problems/096/096.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/096/096.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/096/096.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": 30.6624203822, "max_line_length": 80, "alphanum_fraction": 0.3194848359, "num_tokens": 1418, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.754914975839675, "lm_q1q2_score": 0.6531706226416498}} {"text": " integer function LOCALINDEX(ig,nx,npx,pex)\n!\n! INPUT :\n! ig global index of the x dimension of array element\n! \n! nx x dimension of the global array\n!\n! npx number of processor in the x dimension of the processors grid\n!\n! pex x index of the local processor in the processor grid\n! (starting from zero)\n!\n! OUTPUT :\n!\n! localindex index of the element in the local block\n! \n\n\n IMPLICIT NONE\n\n INTEGER il,ig,nx,npx,pex,r,q\n\n Q = INT(nx/npx)\n R = MOD(nx,npx) \n IF((pex+1).LE.R) THEN\n localindex = ig - (Q+1)*pex\n ELSE\n localindex = ig - Q*pex + R\n end if\n\n return \n end\n", "meta": {"hexsha": "0a5ad67dba091d868847055e330a5f27ed585204", "size": 730, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "comm_serial/localindex.f", "max_stars_repo_name": "sscerr/eTF", "max_stars_repo_head_hexsha": "31dea18c7b24b3ebbb6bdfea98467ffbf79f0852", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-02T04:11:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-02T04:11:49.000Z", "max_issues_repo_path": "comm_serial/localindex.f", "max_issues_repo_name": "sscerr/eTF", "max_issues_repo_head_hexsha": "31dea18c7b24b3ebbb6bdfea98467ffbf79f0852", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "comm_serial/localindex.f", "max_forks_repo_name": "sscerr/eTF", "max_forks_repo_head_hexsha": "31dea18c7b24b3ebbb6bdfea98467ffbf79f0852", "max_forks_repo_licenses": ["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.1212121212, "max_line_length": 78, "alphanum_fraction": 0.5342465753, "num_tokens": 199, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240756264638, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6531706216891077}} {"text": " PROGRAM xlubksb\r\nC driver for routine lubksb\r\n INTEGER NP\r\n PARAMETER (NP=20)\r\n REAL p,a(NP,NP),b(NP,NP),c(NP,NP),x(NP)\r\n INTEGER j,k,l,m,n,indx(NP)\r\n CHARACTER txt*3\r\n open(7,file='MATRX1.DAT',status='old')\r\n read(7,*)\r\n10 read(7,*)\r\n read(7,*) n,m\r\n read(7,*)\r\n read(7,*) ((a(k,l), l=1,n), k=1,n)\r\n read(7,*)\r\n read(7,*) ((b(k,l), k=1,n), l=1,m)\r\nC save matrix a for later testing\r\n do 12 l=1,n\r\n do 11 k=1,n\r\n c(k,l)=a(k,l)\r\n11 continue\r\n12 continue\r\nC do LU decomposition\r\n call ludcmp(c,n,NP,indx,p)\r\nC solve equations for each right-hand vector\r\n do 16 k=1,m\r\n do 13 l=1,n\r\n x(l)=b(l,k)\r\n13 continue\r\n call lubksb(c,n,NP,indx,x)\r\nC test results with original matrix\r\n write(*,*) 'Right-hand side vector:'\r\n write(*,'(1x,6f12.6)') (b(l,k), l=1,n)\r\n write(*,*) 'Result of matrix applied to sol''n vector'\r\n do 15 l=1,n\r\n b(l,k)=0.0\r\n do 14 j=1,n\r\n b(l,k)=b(l,k)+a(l,j)*x(j)\r\n14 continue\r\n15 continue\r\n write(*,'(1x,6f12.6)') (b(l,k), l=1,n)\r\n write(*,*) '***********************************'\r\n16 continue\r\n write(*,*) 'Press RETURN for next problem:'\r\n read(*,*)\r\n read(7,'(a3)') txt\r\n if (txt.ne.'END') goto 10\r\n close(7)\r\n END\r\n", "meta": {"hexsha": "d9f369aa7b0cdc6666407e373957fe0e2f12fbc3", "size": 1406, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xlubksb.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xlubksb.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xlubksb.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.693877551, "max_line_length": 63, "alphanum_fraction": 0.4608819346, "num_tokens": 478, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240721511739, "lm_q2_score": 0.7549149758396752, "lm_q1q2_score": 0.6531706095239088}} {"text": "module n_opt\n implicit none\n public::nOpt\n \ncontains\n \n recursive logical function nOpt(n,topOpt,is) result (successfulOpt)\n use incidence_structure\n implicit none\n type(IncidenceStructure) is\n integer n,row,col1,col2,topOpt\n integer col1_delta, col2_delta\n\n logical sumTotal_low, sumTotal_high\n logical sumInRow_low, sumInRow_high\n\n successfulOpt=.false.\n \n ! Skip criteria for the n-opt:\n ! We reached the end of the n-opt descent, return\n if(n<1) return\n ! For each row try exchanging each two opposite-state cells\n do row=1,is%v\n do col1=1,is%b - 1\n do col2=col1 + 1,is%b\n ! Do not exchange cells with the same state\n if(dormant(is,row,col1).and.dormant(is,row,col2)) cycle\n if(active(is,row,col1).and.active(is,row,col2)) cycle\n\n if(abs(is%sum_in_col(col1)-is%k) > n) cycle\n if(abs(is%sum_in_col(col2)-is%k) > n) cycle\n \n ! Exchange the cells' state \n call flip(is,row,col1)\n call flip(is,row,col2)\n \n ! Try testing for BIBD\n if(isBIBD(is)) then\n print *, topOpt, \"-opt yielded a BIBD\"\n successfulOpt=.true.\n return\n ! Else try descending\n else if(nOpt(n-1,topOpt,is)) then\n successfulOpt=.true.\n return\n ! If the descent failed, flip the cell back and continue\n else\n call flip(is,row,col1)\n call flip(is,row,col2)\n endif\n enddo\n enddo\n enddo\n ! Upon reaching here we return .FALSE.\n return\n end function nOpt\n\nend module n_opt\n", "meta": {"hexsha": "830ab68813c85c6e69b35895940a6efee3db7fcb", "size": 1742, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/main/fortran/n_opt.f90", "max_stars_repo_name": "krvoje/ca-bibd-generator", "max_stars_repo_head_hexsha": "c5263c6bbe5db18411bb9501bd19c5f50fa8a4ec", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/main/fortran/n_opt.f90", "max_issues_repo_name": "krvoje/ca-bibd-generator", "max_issues_repo_head_hexsha": "c5263c6bbe5db18411bb9501bd19c5f50fa8a4ec", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-06-19T02:17:23.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-26T16:24:43.000Z", "max_forks_repo_path": "src/main/fortran/n_opt.f90", "max_forks_repo_name": "krvoje/ca-bibd-generator", "max_forks_repo_head_hexsha": "c5263c6bbe5db18411bb9501bd19c5f50fa8a4ec", "max_forks_repo_licenses": ["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.5254237288, "max_line_length": 72, "alphanum_fraction": 0.5631458094, "num_tokens": 438, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278788223265, "lm_q2_score": 0.7401743677704878, "lm_q1q2_score": 0.6531504973103682}} {"text": "SUBROUTINE SPOTRF_F95( A, UPLO, RCOND, NORM, INFO )\n!\n! -- LAPACK95 interface driver routine (version 3.0) --\n! UNI-C, Denmark; Univ. of Tennessee, USA; NAG Ltd., UK\n! September, 2000\n!\n! .. USE STATEMENTS ..\n USE LA_PRECISION, ONLY: WP => SP\n USE LA_AUXMOD, ONLY: ERINFO, LSAME\n USE F77_LAPACK, ONLY: POTRF_F77 => LA_POTRF, LANSY_F77 => LA_LANSY, &\n POCON_F77 => LA_POCON\n! .. IMPLICIT STATEMENT ..\n IMPLICIT NONE\n! .. CHARACTER ARGUMENTS ..\n CHARACTER(LEN=1), INTENT(IN), OPTIONAL :: NORM, UPLO\n! .. SCALAR ARGUMENTS ..\n INTEGER, INTENT(OUT), OPTIONAL :: INFO\n REAL(WP), INTENT(OUT), OPTIONAL :: RCOND\n! .. ARRAY ARGUMENTS ..\n REAL(WP), INTENT(INOUT) :: A(:,:)\n!-----------------------------------------------------------------\n!\n! Purpose\n! =======\n!\n! LA_POTRF computes the Cholesky factorization of a real symmetric or\n! complex Hermitian positive definite matrix A.\n!\n! The factorization has the form\n! A = U**H * U, if UPLO = 'U', or\n! A = L * L**H, if UPLO = 'L',\n! where U is an upper triangular matrix and L is lower triangular.\n!\n! This is the block version of the algorithm, calling Level 3 BLAS.\n!\n! LA_POTRF optionally estimates the reciprocal of the condition number\n! (in the 1-norm) of a real symmetric or complex Hermitian positive \n! definite matrix A.\n! An estimate is obtained for norm(inv(A)), and the reciprocal of the\n! condition number is computed as RCOND = 1 / (norm(A) * norm(inv(A))).\n!\n! =======\n!\n! SUBROUTINE LA_POTRF( A, UPLO, RCOND, NORM, INFO )\n! (), INTENT(INOUT) :: A(:,:)\n! CHARACTER(LEN=1), INTENT(IN), OPTIONAL :: UPLO\n! REAL(), INTENT(OUT), OPTIONAL :: RCOND\n! CHARACTER(LEN=1), INTENT(IN), OPTIONAL :: NORM\n! INTEGER, INTENT(OUT), OPTIONAL :: INFO\n! where\n! ::= REAL | COMPLEX\n! ::= KIND(1.0) | KIND(1.0D0)\n!\n! Defaults\n! ========\n!\n! 1. If UPLO is not present then UPLO = 'U' is assumed.\n!\n! Arguments\n! =========\n!\n! A (input/output) either REAL or COMPLEX square array, \n! shape (:,:), size(A,1) == size(A,2) >= 0.\n! On entry, the symmetric (Hermitian) matrix A. \n! If UPLO = 'U', the upper triangular part of A contains\n! the upper triangular part of the matrix A, and the \n! strictly lower triangular part of A is not referenced.\n! If UPLO = 'L', the lower triangular part of A contains\n! the lower triangular part of the matrix A, and the\n! strictly upper triangular part of A is not referenced.\n! On exit, if INFO = 0, the factor U or L from the Cholesky\n! factorization A = U**H*U or A = L*L**H.\n!\n! UPLO Optional, (input) CHARACTER*1\n! If UPLO is present then:\n! = 'U': Upper triangle of A is stored;\n! = 'L': Lower triangle of A is stored.\n! otherwise UPLO = 'U' is assumed.\n!\n! RCOND Optional (output) REAL\n! The reciprocal of the condition number of the matrix A \n! computed as RCOND = 1/(norm(A) * norm(inv(A))).\n! NORM Optional (input) CHARACTER*1\n! Specifies whether the 1-norm condition number or the\n! infinity-norm condition number is required:\n! If NORM is present then:\n! = '1', 'O' or 'o': 1-norm;\n! = 'I' or 'i': infinity-norm.\n! otherwise NORM = '1' is used.\n!\n! INFO Optional, (output) INTEGER\n! If INFO is present:\n! = 0: successful exit\n! < 0: if INFO = -i, the i-th argument had an illegal value\n! > 0: if INFO = i, the leading minor of order i is not\n! positive definite, and the factorization could not be\n! completed.\n! If INFO is not present and an error occurs, then the program\n! is terminated with an error message.\n!\n! --------------------------------------\n! .. LOCAL PARAMETERS ..\n CHARACTER(LEN=8), PARAMETER :: SRNAME = 'LA_POTRF'\n! .. LOCAL SCALARS ..\n CHARACTER(LEN=1) :: LNORM, LUPLO\n INTEGER :: LINFO, N, ISTAT, ISTAT1, LD\n REAL(WP) :: ANORM\n! .. LOCAL POINTERS ..\n INTEGER, POINTER :: IWORK(:)\n REAL(WP), POINTER :: WORK(:)\n! .. INTRINSIC FUNCTIONS ..\n INTRINSIC PRESENT, MAX\n! .. EXECUTABLE STATEMENTS ..\n LINFO = 0; N = SIZE(A,1); LD = MAX(1,N); ISTAT = 0\n IF( PRESENT(UPLO) ) THEN; LUPLO = UPLO; ELSE; LUPLO = 'U'; END IF\n IF( PRESENT(NORM) ) THEN; LNORM = NORM; ELSE; LNORM = '1'; END IF\n! .. TEST THE ARGUMENTS\n IF( SIZE( A, 2 ) /= N .AND. N < 0 )THEN; LINFO = -1\n ELSE IF( .NOT.LSAME(LUPLO,'U') .AND. .NOT.LSAME(LUPLO,'L') )THEN; LINFO = -2\n ELSE IF( ( .NOT.PRESENT(RCOND) .AND. PRESENT(NORM) ) .OR. &\n ( .NOT.LSAME(LNORM,'I') .AND. .NOT.LSAME(LNORM,'O') &\n .AND. LNORM /= '1' ) ) THEN; LINFO = -4\n ELSE IF( N > 0 )THEN\n IF( PRESENT(RCOND) ) THEN\n! .. COMPUTE THE NORM OF THE MATRIX A\n ALLOCATE(WORK(N), STAT=ISTAT)\n IF( ISTAT == 0 )THEN; ANORM = LANSY_F77( LNORM, LUPLO, LD, A, N, WORK )\n ELSE; LINFO = -100; END IF\n DEALLOCATE(WORK, STAT=ISTAT1)\n END IF\n!\n IF( LINFO == 0 ) THEN\n! .. COMPUTE THE CHOLESKY FACTORS OF THE MATRIX A\n CALL POTRF_F77( LUPLO, N, A, LD, LINFO )\n!\n IF( PRESENT(RCOND) .AND. LINFO == 0 ) THEN\n! .. COMPUTE THE RECIPROCAL OF THE CONDITION NUMBER OF A\n IF( ANORM == 0.0_WP )THEN; RCOND = 0.0_WP\n ELSE; ALLOCATE(WORK(3*N), IWORK(N), STAT=ISTAT)\n IF( ISTAT == 0 )THEN\n CALL POCON_F77( LUPLO, N, A, LD, ANORM, RCOND, &\n WORK, IWORK, LINFO )\n ELSE; LINFO = -100; END IF\n DEALLOCATE(WORK, IWORK, STAT=ISTAT1)\n END IF\n END IF\n END IF\n ELSE IF( PRESENT(RCOND) ) THEN; RCOND = 1.0_WP; ENDIF\n CALL ERINFO(LINFO,SRNAME,INFO,ISTAT)\nEND SUBROUTINE SPOTRF_F95\n", "meta": {"hexsha": "0066dacda348ff5250a1b7426f8bd1cb6110c1f7", "size": 5927, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/la_spotrf.f90", "max_stars_repo_name": "MattBurn/LAPACK95", "max_stars_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-12-29T15:07:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T10:09:22.000Z", "max_issues_repo_path": "src/la_spotrf.f90", "max_issues_repo_name": "MattBurn/LAPACK95", "max_issues_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-02-21T10:46:38.000Z", "max_issues_repo_issues_event_max_datetime": "2017-10-20T17:03:14.000Z", "max_forks_repo_path": "src/la_spotrf.f90", "max_forks_repo_name": "MattBurn/LAPACK95", "max_forks_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-12-29T15:34:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-15T07:12:40.000Z", "avg_line_length": 39.2516556291, "max_line_length": 80, "alphanum_fraction": 0.5647038974, "num_tokens": 1847, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8824278757303678, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6531504899641694}} {"text": "!*****************************************************************************************\n!>\n! This program tests the ability of [[chkder]] to detect\n! inconsistencies between functions and their first derivatives.\n! fourteen test function vectors and jacobians are used. eleven of\n! the tests are false(f), i.e. there are inconsistencies between\n! the function vectors and the corresponding jacobians. three of\n! the tests are true(t), i.e. there are no inconsistencies. the\n! driver reads in data, calls chkder and prints out information\n! required by and received from chkder.\n\nprogram test_chkder\n\n use minpack_module, only: wp, dpmpar, chkder\n use iso_fortran_env, only: nwrite => output_unit\n\n implicit none\n\n ! originally from file23\n integer,parameter :: ncases = 14\n integer,dimension(ncases),parameter :: nprobs = [1,2,3,4,5,6,7,8,9,10,11,12,13,14]\n integer,dimension(ncases),parameter :: ns = [2,4,2,4,3,9,7,10,10,10,10,10,10,10]\n\n integer :: i, ldfjac, lnp, mode, n, nprob, icase\n real(wp) :: cp\n integer,dimension(ncases) :: na, np\n real(wp),dimension(ncases) :: errmax, errmin\n real(wp),dimension(:),allocatable :: diff, err, fvec1, fvec2, x1, x2\n real(wp),dimension(:,:),allocatable :: fjac\n\n logical,dimension(ncases),parameter :: a = &\n [.false., .false., .false., .true., .false., .false., .false., &\n .true., .false., .false., .false., .false., .true., .false.]\n real(wp), parameter :: one = 1.0_wp\n real(wp), parameter :: tol = sqrt(dpmpar(1)) !! abstol for matching previously generated solutions\n real(wp), parameter :: solution_reltol = 1.0e-4_wp !! reltol for matching previously generated solutions\n\n integer,dimension(ncases),parameter :: info_original = 1 ! not used here\n\n cp = 1.23e-1_wp\n\n do icase = 1, ncases+1\n\n if (icase == ncases+1) then\n write (nwrite, '(a,i3,a/)') '1SUMMARY OF ', lnp, ' TESTS OF CHKDER'\n write (nwrite, '(a/)') ' NPROB N STATUS ERRMIN ERRMAX'\n do i = 1, lnp\n write (nwrite, '(i4, i6, 6x, l1, 3x, 2d15.7)') np(i), na(i), a(i), errmin(i), errmax(i)\n end do\n stop\n else\n nprob = nprobs(icase)\n n = ns(icase)\n ldfjac = n\n\n if (allocated(diff)) deallocate(diff)\n if (allocated(err)) deallocate(err)\n if (allocated(fjac)) deallocate(fjac)\n if (allocated(fvec1)) deallocate(fvec1)\n if (allocated(fvec2)) deallocate(fvec2)\n if (allocated(x1)) deallocate(x1)\n if (allocated(x2)) deallocate(x2)\n allocate(diff(n))\n allocate(err(n))\n allocate(fjac(n, n))\n allocate(fvec1(n))\n allocate(fvec2(n))\n allocate(x1(n))\n allocate(x2(n))\n\n call initpt(n, x1, nprob, one)\n do i = 1, n\n x1(i) = x1(i) + cp\n cp = -cp\n end do\n write (nwrite, '(///5x, a, i5, 5x, a, i5, 2x, a, l1)') ' PROBLEM', nprob, ' WITH DIMENSION', n, ' IS ', a(nprob)\n mode = 1\n call chkder(n, n, x1, fvec1, fjac, ldfjac, x2, fvec2, mode, err)\n mode = 2\n call vecfcn(n, x1, fvec1, nprob)\n call errjac(n, x1, fjac, ldfjac, nprob)\n call vecfcn(n, x2, fvec2, nprob)\n call chkder(n, n, x1, fvec1, fjac, ldfjac, x2, fvec2, mode, err)\n errmin(nprob) = err(1)\n errmax(nprob) = err(1)\n do i = 1, n\n diff(i) = fvec2(i) - fvec1(i)\n if (errmin(nprob) > err(i)) errmin(nprob) = err(i)\n if (errmax(nprob) < err(i)) errmax(nprob) = err(i)\n end do\n np(nprob) = nprob\n lnp = nprob\n na(nprob) = n\n write (nwrite, '(//5x, a//(5x, 5d15.7))') ' FIRST FUNCTION VECTOR ', (fvec1(i), i=1, n)\n write (nwrite, '(//5x, a//(5x, 5d15.7))') ' FUNCTION DIFFERENCE VECTOR', (diff(i), i=1, n)\n write (nwrite, '(//5x, a//(5x, 5d15.7))') ' ERROR VECTOR', (err(i), i=1, n)\n call compare_solutions(nprob, diff, solution_reltol, tol)\n\n end if\n\n end do\n\n contains\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Compare with previously generated solutions.\n\n subroutine compare_solutions(ic, x, reltol, abstol)\n\n implicit none\n\n integer,intent(in) :: ic !! problem number (index is `solution` vector)\n real(wp),dimension(:),intent(in) :: x !! computed `x` vector from the method\n real(wp),intent(in) :: reltol !! relative tolerance for `x` to pass\n real(wp),intent(in) :: abstol !! absolute tolerance for `x` to pass\n\n real(wp),dimension(size(x)) :: diff, absdiff, reldiff\n\n if (info_original(ic)<5) then ! ignore any where the original minpack failed\n diff = solution(ic) - x\n absdiff = abs(diff)\n if (any(absdiff>abstol)) then ! first do an absolute diff\n ! also do a rel diff if the abs diff fails (also protect for divide by zero)\n reldiff = absdiff\n where (solution(ic) /= 0.0_wp) reldiff = absdiff / abs(solution(ic))\n if (any(reldiff > reltol)) then\n write(nwrite,'(A)') 'Failed case'\n write(nwrite, '(//5x, a//(5x, 5d15.7))') 'Expected x: ', solution(ic)\n write(nwrite, '(/5x, a//(5x, 5d15.7))') 'Computed x: ', x\n write(nwrite, '(/5x, a//(5x, 5d15.7))') 'absdiff: ', absdiff\n write(nwrite, '(/5x, a//(5x, 5d15.7))') 'reldiff: ', reldiff\n error stop ! test failed\n end if\n end if\n end if\n\n end subroutine compare_solutions\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Replaced statement function in original code.\n\n pure elemental function dfloat(i) result(f)\n implicit none\n integer, intent(in) :: i\n real(wp) :: f\n f = real(i, wp)\n end function dfloat\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Get expected `diff` vectors for each case.\n\n pure function solution(nprob) result(x)\n\n implicit none\n\n integer,intent(in) :: nprob\n real(wp),dimension(:),allocatable :: x\n\n select case (nprob)\n case(1); x = [-0.1604855093262358E-07_wp,0.4763689633868751E-06_wp]\n case(2); x = [0.2138763655068487E-06_wp,-0.2512328678427878E-07_wp,-0.3578105500778861E-07_wp,&\n 0.4754114257821129E-06_wp]\n case(3); x = [0.3214806338291964E-04_wp,-0.7057517459330143E-08_wp]\n case(4); x = [0.2322078535144101E-03_wp,0.5335169362297165E-04_wp,0.2089913541567512E-03_wp,&\n 0.4808346034224087E-04_wp]\n case(5); x = [0.1832842144722235E-07_wp,-0.1319622122686326E-06_wp,0.1832842821958280E-08_wp]\n case(6); x = [0.4515008482641747E-06_wp,0.8252608125758343E-06_wp,0.1047075926408070E-05_wp,&\n 0.1220878203866960E-05_wp,0.1363612746274612E-05_wp,0.1485299534920159E-05_wp,&\n 0.1592014982065848E-05_wp,0.1687697022134671E-05_wp,0.1775024010441939E-05_wp]\n case(7); x = [0.1542483058641908E-07_wp,0.2060287401794980E-07_wp,0.2376945576476608E-07_wp,&\n 0.5349154558187408E-07_wp,0.9704076181504817E-07_wp,0.1576633008593120E-06_wp,&\n 0.2112184365188341E-06_wp]\n case(8); x = [0.8012354335562577E-07_wp,0.8378922800034161E-07_wp,0.8012354335562577E-07_wp,&\n 0.8378922800034161E-07_wp,0.8012354335562577E-07_wp,0.8378922800034161E-07_wp,&\n 0.8012354335562577E-07_wp,0.8378922800034161E-07_wp,0.8012354335562577E-07_wp,&\n 0.1065043608861060E-09_wp]\n case(9); x = [0.5774599409757997E-08_wp,-0.7078711450336783E-08_wp,0.7631400400498478E-08_wp,&\n -0.7053519379685014E-08_wp,0.7658129463905539E-08_wp,-0.7038501670386665E-08_wp,&\n 0.7685261871337445E-08_wp,-0.7047089523037897E-08_wp,0.6495039228671118E-08_wp,&\n -0.2818530409065545E-08_wp]\n case(10);x = [0.3294705064327275E-08_wp,0.8148107188965525E-09_wp,0.5413627796047038E-08_wp,&\n 0.2381044444943470E-08_wp,0.6401980501280491E-08_wp,0.2764786941056308E-08_wp,&\n 0.6166095051218790E-08_wp,0.1882141179021524E-08_wp,0.4645276802106579E-08_wp,&\n 0.9133731548871538E-09_wp]\n case(11);x = [0.3284536753689338E-08_wp,0.1864164600462459E-08_wp,0.3268772807984988E-08_wp,&\n 0.3333951337225471E-08_wp,0.3253008529213730E-08_wp,0.4803738740122299E-08_wp,&\n 0.3237243362264053E-08_wp,0.6273523034394657E-08_wp,0.3221478195314376E-08_wp,&\n 0.7743309993202274E-08_wp]\n case(12);x = [0.2249654149636626E-02_wp,0.4499298869632185E-02_wp,0.6748936313670129E-02_wp,&\n 0.8998581033665687E-02_wp,0.1124821836128831E-01_wp,0.1349786319769919E-01_wp,&\n 0.1574750046711415E-01_wp,0.1799714541994035E-01_wp,0.2024678350426257E-01_wp,&\n 0.2249642740935087E-01_wp]\n case(13);x = [0.9923452193305593E-07_wp,0.3484660204833290E-07_wp,0.8616620350565540E-07_wp,&\n 0.3484660204833290E-07_wp,0.8616620350565540E-07_wp,0.3484660204833290E-07_wp,&\n 0.8616620350565540E-07_wp,0.3484660204833290E-07_wp,0.8616620350565540E-07_wp,&\n 0.6831460996892247E-07_wp]\n case(14);x = [0.3598775801805232E-06_wp,0.2186061109910042E-06_wp,0.3905816612359558E-06_wp,&\n 0.2493101911582585E-06_wp,0.4212857422913885E-06_wp,0.2800142722136911E-06_wp,&\n 0.4311392522993174E-06_wp,0.2800142722136911E-06_wp,0.4311392522993174E-06_wp,&\n 0.2591637029425442E-06_wp]\n case default\n error stop 'invalid case'\n end select\n\n end function solution\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! This subroutine is derived from [[vecjac]] which defines the\n! jacobian matrices of fourteen test functions. the problem\n! dimensions are as described in the prologue comments of vecfcn.\n! various errors are deliberately introduced to provide a test\n! for chkder.\n\n subroutine errjac(n, x, Fjac, Ldfjac, Nprob)\n implicit none\n\n integer, intent(in) :: n !! a positive integer variable.\n integer, intent(in) :: Ldfjac !! a positive integer variable not less than n\n !! which specifies the leading dimension of the array fjac.\n integer, intent(in) :: Nprob !! a positive integer variable which defines the\n !! number of the problem. nprob must not exceed 14.\n real(wp), intent(in) :: x(n) !! an array of length n.\n real(wp), intent(out) :: Fjac(Ldfjac, n) !! an n by n array. on output fjac contains the\n !! jacobian matrix, with various errors deliberately\n !! introduced, of the nprob function evaluated at x.\n\n real(wp),parameter :: zero = 0.0e0_wp\n real(wp),parameter :: one = 1.0e0_wp\n real(wp),parameter :: two = 2.0e0_wp\n real(wp),parameter :: three = 3.0e0_wp\n real(wp),parameter :: four = 4.0e0_wp\n real(wp),parameter :: five = 5.0e0_wp\n real(wp),parameter :: six = 6.0e0_wp\n real(wp),parameter :: eight = 8.0e0_wp\n real(wp),parameter :: ten = 1.0e1_wp\n real(wp),parameter :: fiftn = 1.5e1_wp\n real(wp),parameter :: twenty = 2.0e1_wp\n real(wp),parameter :: hundrd = 1.0e2_wp\n real(wp),parameter :: c1 = 1.0e4_wp\n real(wp),parameter :: c3 = 2.0e2_wp\n real(wp),parameter :: c4 = 2.02e1_wp\n real(wp),parameter :: c5 = 1.98e1_wp\n real(wp),parameter :: c6 = 1.8e2_wp\n real(wp),parameter :: c9 = 2.9e1_wp\n real(wp),parameter :: tpi = eight*atan(one)\n\n integer :: i, j, k, k1, k2, ml, mu\n real(wp) :: h, prod, sum, sum1, sum2, temp, temp1, temp2, &\n temp3, temp4, ti, tj, tk\n\n Fjac(1:n,1:n) = zero\n\n ! jacobian routine selector.\n\n select case (nprob)\n case (2)\n ! powell singular function with sign reversal affecting element\n ! (3,3).\n do k = 1, 4\n do j = 1, 4\n fjac(k, j) = zero\n end do\n end do\n fjac(1, 1) = one\n fjac(1, 2) = ten\n fjac(2, 3) = sqrt(five)\n fjac(2, 4) = -fjac(2, 3)\n fjac(3, 2) = two*(x(2) - two*x(3))\n fjac(3, 3) = two*fjac(3, 2)\n fjac(4, 1) = two*sqrt(ten)*(x(1) - x(4))\n fjac(4, 4) = -fjac(4, 1)\n case (3)\n ! powell badly scaled function with the sign of the jacobian\n ! reversed.\n fjac(1, 1) = -c1*x(2)\n fjac(1, 2) = -c1*x(1)\n fjac(2, 1) = exp(-x(1))\n fjac(2, 2) = exp(-x(2))\n case (4)\n ! wood function without error.\n do k = 1, 4\n do j = 1, 4\n fjac(k, j) = zero\n end do\n end do\n temp1 = x(2) - three*x(1)**2\n temp2 = x(4) - three*x(3)**2\n fjac(1, 1) = -c3*temp1 + one\n fjac(1, 2) = -c3*x(1)\n fjac(2, 1) = -two*c3*x(1)\n fjac(2, 2) = c3 + c4\n fjac(2, 4) = c5\n fjac(3, 3) = -c6*temp2 + one\n fjac(3, 4) = -c6*x(3)\n fjac(4, 2) = c5\n fjac(4, 3) = -two*c6*x(3)\n fjac(4, 4) = c6 + c4\n case (5)\n ! helical valley function with multiplicative error affecting\n ! elements (2,1) and (2,2).\n temp = x(1)**2 + x(2)**2\n temp1 = tpi*temp\n temp2 = sqrt(temp)\n fjac(1, 1) = hundrd*x(2)/temp1\n fjac(1, 2) = -hundrd*x(1)/temp1\n fjac(1, 3) = ten\n fjac(2, 1) = five*x(1)/temp2\n fjac(2, 2) = five*x(2)/temp2\n fjac(2, 3) = zero\n fjac(3, 1) = zero\n fjac(3, 2) = zero\n fjac(3, 3) = one\n case (6)\n ! watson function with sign reversals affecting the computation of\n ! temp1.\n do k = 1, n\n do j = k, n\n fjac(k, j) = zero\n end do\n end do\n do i = 1, 29\n ti = dfloat(i)/c9\n sum1 = zero\n temp = one\n do j = 2, n\n sum1 = sum1 + dfloat(j - 1)*temp*x(j)\n temp = ti*temp\n end do\n sum2 = zero\n temp = one\n do j = 1, n\n sum2 = sum2 + temp*x(j)\n temp = ti*temp\n end do\n temp1 = two*(sum1 + sum2**2 + one)\n temp2 = two*sum2\n temp = ti**2\n tk = one\n do k = 1, n\n tj = tk\n do j = k, n\n fjac(k, j) = fjac(k, j) &\n + tj*((dfloat(k - 1)/ti - temp2)*(dfloat(j - 1) &\n /ti - temp2) - temp1)\n tj = ti*tj\n end do\n tk = temp*tk\n end do\n end do\n fjac(1, 1) = fjac(1, 1) + six*x(1)**2 - two*x(2) + three\n fjac(1, 2) = fjac(1, 2) - two*x(1)\n fjac(2, 2) = fjac(2, 2) + one\n do k = 1, n\n do j = k, n\n fjac(j, k) = fjac(k, j)\n end do\n end do\n case (7)\n ! chebyquad function with jacobian twice correct size.\n tk = one/dfloat(n)\n do j = 1, n\n temp1 = one\n temp2 = two*x(j) - one\n temp = two*temp2\n temp3 = zero\n temp4 = two\n do k = 1, n\n fjac(k, j) = two*tk*temp4\n ti = four*temp2 + temp*temp4 - temp3\n temp3 = temp4\n temp4 = ti\n ti = temp*temp2 - temp1\n temp1 = temp2\n temp2 = ti\n end do\n end do\n case (8)\n ! brown almost-linear function without error.\n prod = one\n do j = 1, n\n prod = x(j)*prod\n do k = 1, n\n fjac(k, j) = one\n end do\n fjac(j, j) = two\n end do\n do j = 1, n\n temp = x(j)\n if (temp == zero) then\n temp = one\n prod = one\n do k = 1, n\n if (k /= j) prod = x(k)*prod\n end do\n end if\n fjac(n, j) = prod/temp\n end do\n case (9)\n ! discrete boundary value function with multiplicative error\n ! affecting the jacobian diagonal.\n h = one/dfloat(n + 1)\n do k = 1, n\n temp = three*(x(k) + dfloat(k)*h + one)**2\n do j = 1, n\n fjac(k, j) = zero\n end do\n fjac(k, k) = four + temp*h**2\n if (k /= 1) fjac(k, k - 1) = -one\n if (k /= n) fjac(k, k + 1) = -one\n end do\n case (10)\n ! discrete integral equation function with sign error affecting\n ! the jacobian diagonal.\n h = one/dfloat(n + 1)\n do k = 1, n\n tk = dfloat(k)*h\n do j = 1, n\n tj = dfloat(j)*h\n temp = three*(x(j) + tj + one)**2\n fjac(k, j) = h*min(tj*(one - tk), tk*(one - tj))*temp/two\n end do\n fjac(k, k) = fjac(k, k) - one\n end do\n case (11)\n ! trigonometric function with sign errors affecting the\n ! offdiagonal elements of the jacobian.\n do j = 1, n\n temp = sin(x(j))\n do k = 1, n\n fjac(k, j) = -temp\n end do\n fjac(j, j) = dfloat(j + 1)*temp - cos(x(j))\n end do\n case (12)\n ! variably dimensioned function with operation error affecting\n ! the upper triangular elements of the jacobian.\n sum = zero\n do j = 1, n\n sum = sum + dfloat(j)*(x(j) - one)\n end do\n temp = one + six*sum**2\n do k = 1, n\n do j = k, n\n fjac(k, j) = dfloat(k*j)/temp\n fjac(j, k) = fjac(k, j)\n end do\n fjac(k, k) = fjac(k, k) + one\n end do\n case (13)\n ! broyden tridiagonal function without error.\n do k = 1, n\n do j = 1, n\n fjac(k, j) = zero\n end do\n fjac(k, k) = three - four*x(k)\n if (k /= 1) fjac(k, k - 1) = -one\n if (k /= n) fjac(k, k + 1) = -two\n end do\n case (14)\n ! broyden banded function with sign error affecting the jacobian\n ! diagonal.\n ml = 5\n mu = 1\n do k = 1, n\n do j = 1, n\n fjac(k, j) = zero\n end do\n k1 = max(1, k - ml)\n k2 = min(k + mu, n)\n do j = k1, k2\n if (j /= k) fjac(k, j) = -(one + two*x(j))\n end do\n fjac(k, k) = two - fiftn*x(k)**2\n end do\n case default\n ! rosenbrock function with sign reversal affecting element (1,1).\n fjac(1, 1) = one\n fjac(1, 2) = zero\n fjac(2, 1) = -twenty*x(1)\n fjac(2, 2) = ten\n end select\n\n end subroutine errjac\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! This subroutine specifies the standard starting points for\n! the functions defined by subroutine vecfcn. the subroutine\n! returns in x a multiple (factor) of the standard starting\n! point. for the sixth function the standard starting point is\n! zero, so in this case, if factor is not unity, then the\n! subroutine returns the vector x(j) = factor, j=1,...,n.\n\n subroutine initpt(n, x, Nprob, Factor)\n implicit none\n\n integer,intent(in) :: n !! a positive integer input variable.\n real(wp),intent(out) :: x(n) !! an output array of length n which contains the standard\n !! starting point for problem nprob multiplied by factor.\n integer,intent(in) :: Nprob !! a positive integer input variable which defines the\n !! number of the problem. nprob must not exceed 14.\n real(wp),intent(in) :: Factor !! an input variable which specifies the multiple of\n !! the standard starting point. if factor is unity, no\n !! multiplication is performed.\n\n real(wp) :: zero = 0.0_wp\n real(wp) :: half = 5.0e-1_wp\n real(wp) :: one = 1.0_wp\n real(wp) :: three = 3.0_wp\n real(wp) :: c1 = 1.2_wp\n\n integer :: j\n real(wp) :: h, tj\n\n x(1:n) = zero\n\n ! selection of initial point.\n\n select case (Nprob)\n case (2)\n ! powell singular function.\n x(1) = three\n x(2) = -one\n x(3) = zero\n x(4) = one\n case (3)\n ! powell badly scaled function.\n x(1) = zero\n x(2) = one\n case (4)\n ! wood function.\n x(1) = -three\n x(2) = -one\n x(3) = -three\n x(4) = -one\n case (5)\n ! helical valley function.\n x(1) = -one\n x(2) = zero\n x(3) = zero\n case (6)\n ! watson function.\n do j = 1, n\n x(j) = zero\n end do\n case (7)\n ! chebyquad function.\n h = one/dfloat(n + 1)\n do j = 1, n\n x(j) = dfloat(j)*h\n end do\n case (8)\n ! brown almost-linear function.\n do j = 1, n\n x(j) = half\n end do\n case (9, 10)\n ! discrete boundary value and integral equation functions.\n h = one/dfloat(n + 1)\n do j = 1, n\n tj = dfloat(j)*h\n x(j) = tj*(tj - one)\n end do\n case (11)\n ! trigonometric function.\n h = one/dfloat(n)\n do j = 1, n\n x(j) = h\n end do\n case (12)\n ! variably dimensioned function.\n h = one/dfloat(n)\n do j = 1, n\n x(j) = one - dfloat(j)*h\n end do\n case (13, 14)\n ! broyden tridiagonal and banded functions.\n do j = 1, n\n x(j) = -one\n end do\n case default\n ! rosenbrock function.\n x(1) = -c1\n x(2) = one\n end select\n\n ! Compute multiple of initial point.\n\n if (factor /= one) then\n if (nprob == 6) then\n do j = 1, n\n x(j) = factor\n end do\n else\n do j = 1, n\n x(j) = factor*x(j)\n end do\n end if\n end if\n\n end subroutine initpt\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! This subroutine defines fourteen test functions. the first\n! five test functions are of dimensions 2,4,2,4,3, respectively,\n! while the remaining test functions are of variable dimension\n! n for any n greater than or equal to 1 (problem 6 is an\n! exception to this, since it does not allow n = 1).\n\n subroutine vecfcn(n, x, Fvec, Nprob)\n implicit none\n\n integer,intent(in) :: n !! a positive integer input variable.\n integer,intent(in) :: Nprob !! a positive integer input variable which defines the\n !! number of the problem. nprob must not exceed 14.\n real(wp),intent(in) :: x(n) !! an input array of length n.\n real(wp),intent(out) :: Fvec(n) !! an output array of length n which contains the nprob\n !! function vector evaluated at x.\n\n real(wp),parameter :: zero = 0.0_wp\n real(wp),parameter :: one = 1.0_wp\n real(wp),parameter :: two = 2.0_wp\n real(wp),parameter :: three = 3.0_wp\n real(wp),parameter :: five = 5.0_wp\n real(wp),parameter :: eight = 8.0_wp\n real(wp),parameter :: ten = 10.0_wp\n real(wp),parameter :: c1 = 1.0e4_wp\n real(wp),parameter :: c2 = 1.0001_wp\n real(wp),parameter :: c3 = 2.0e2_wp\n real(wp),parameter :: c4 = 2.02e1_wp\n real(wp),parameter :: c5 = 1.98e1_wp\n real(wp),parameter :: c6 = 1.8e2_wp\n real(wp),parameter :: c7 = 2.5e-1_wp\n real(wp),parameter :: c8 = 5.0e-1_wp\n real(wp),parameter :: c9 = 2.9e1_wp\n real(wp),parameter :: tpi = eight*atan(one)\n\n integer :: i, iev, j, k, k1, k2, kp1, ml, mu\n real(wp) :: h, prod, sum, sum1, sum2, temp, temp1, &\n temp2, ti, tj, tk\n\n Fvec(1:n) = zero\n\n ! problem selector.\n\n select case (nprob)\n case (2)\n ! powell singular function.\n fvec(1) = x(1) + ten*x(2)\n fvec(2) = sqrt(five)*(x(3) - x(4))\n fvec(3) = (x(2) - two*x(3))**2\n fvec(4) = sqrt(ten)*(x(1) - x(4))**2\n case (3)\n ! powell badly scaled function.\n fvec(1) = c1*x(1)*x(2) - one\n fvec(2) = exp(-x(1)) + exp(-x(2)) - c2\n case (4)\n ! wood function.\n temp1 = x(2) - x(1)**2\n temp2 = x(4) - x(3)**2\n fvec(1) = -c3*x(1)*temp1 - (one - x(1))\n fvec(2) = c3*temp1 + c4*(x(2) - one) + c5*(x(4) - one)\n fvec(3) = -c6*x(3)*temp2 - (one - x(3))\n fvec(4) = c6*temp2 + c4*(x(4) - one) + c5*(x(2) - one)\n case (5)\n ! helical valley function.\n temp1 = sign(c7, x(2))\n if (x(1) > zero) temp1 = atan(x(2)/x(1))/tpi\n if (x(1) < zero) temp1 = atan(x(2)/x(1))/tpi + c8\n temp2 = sqrt(x(1)**2 + x(2)**2)\n fvec(1) = ten*(x(3) - ten*temp1)\n fvec(2) = ten*(temp2 - one)\n fvec(3) = x(3)\n case (6)\n ! watson function.\n do k = 1, n\n fvec(k) = zero\n end do\n do i = 1, 29\n ti = dfloat(i)/c9\n sum1 = zero\n temp = one\n do j = 2, n\n sum1 = sum1 + dfloat(j - 1)*temp*x(j)\n temp = ti*temp\n end do\n sum2 = zero\n temp = one\n do j = 1, n\n sum2 = sum2 + temp*x(j)\n temp = ti*temp\n end do\n temp1 = sum1 - sum2**2 - one\n temp2 = two*ti*sum2\n temp = one/ti\n do k = 1, n\n fvec(k) = fvec(k) + temp*(dfloat(k - 1) - temp2)*temp1\n temp = ti*temp\n end do\n end do\n temp = x(2) - x(1)**2 - one\n fvec(1) = fvec(1) + x(1)*(one - two*temp)\n fvec(2) = fvec(2) + temp\n case (7)\n ! chebyquad function.\n do k = 1, n\n fvec(k) = zero\n end do\n do j = 1, n\n temp1 = one\n temp2 = two*x(j) - one\n temp = two*temp2\n do i = 1, n\n fvec(i) = fvec(i) + temp2\n ti = temp*temp2 - temp1\n temp1 = temp2\n temp2 = ti\n end do\n end do\n tk = one/dfloat(n)\n iev = -1\n do k = 1, n\n fvec(k) = tk*fvec(k)\n if (iev > 0) fvec(k) = fvec(k) + one/(dfloat(k)**2 - one)\n iev = -iev\n end do\n case (8)\n ! brown almost-linear function.\n sum = -dfloat(n + 1)\n prod = one\n do j = 1, n\n sum = sum + x(j)\n prod = x(j)*prod\n end do\n do k = 1, n\n fvec(k) = x(k) + sum\n end do\n fvec(n) = prod - one\n case (9)\n ! discrete boundary value function.\n h = one/dfloat(n + 1)\n do k = 1, n\n temp = (x(k) + dfloat(k)*h + one)**3\n temp1 = zero\n if (k /= 1) temp1 = x(k - 1)\n temp2 = zero\n if (k /= n) temp2 = x(k + 1)\n fvec(k) = two*x(k) - temp1 - temp2 + temp*h**2/two\n end do\n case (10)\n ! discrete integral equation function.\n h = one/dfloat(n + 1)\n do k = 1, n\n tk = dfloat(k)*h\n sum1 = zero\n do j = 1, k\n tj = dfloat(j)*h\n temp = (x(j) + tj + one)**3\n sum1 = sum1 + tj*temp\n end do\n sum2 = zero\n kp1 = k + 1\n if (n >= kp1) then\n do j = kp1, n\n tj = dfloat(j)*h\n temp = (x(j) + tj + one)**3\n sum2 = sum2 + (one - tj)*temp\n end do\n end if\n fvec(k) = x(k) + h*((one - tk)*sum1 + tk*sum2)/two\n end do\n case (11)\n ! trigonometric function.\n sum = zero\n do j = 1, n\n fvec(j) = cos(x(j))\n sum = sum + fvec(j)\n end do\n do k = 1, n\n fvec(k) = dfloat(n + k) - sin(x(k)) - sum - dfloat(k)*fvec(k)\n end do\n case (12)\n ! variably dimensioned function.\n sum = zero\n do j = 1, n\n sum = sum + dfloat(j)*(x(j) - one)\n end do\n temp = sum*(one + two*sum**2)\n do k = 1, n\n fvec(k) = x(k) - one + dfloat(k)*temp\n end do\n case (13)\n ! broyden tridiagonal function.\n do k = 1, n\n temp = (three - two*x(k))*x(k)\n temp1 = zero\n if (k /= 1) temp1 = x(k - 1)\n temp2 = zero\n if (k /= n) temp2 = x(k + 1)\n fvec(k) = temp - temp1 - two*temp2 + one\n end do\n case (14)\n ! broyden banded function.\n ml = 5\n mu = 1\n do k = 1, n\n k1 = max(1, k - ml)\n k2 = min(k + mu, n)\n temp = zero\n do j = k1, k2\n if (j /= k) temp = temp + x(j)*(one + x(j))\n end do\n fvec(k) = x(k)*(two + five*x(k)**2) + one - temp\n end do\n case default\n ! rosenbrock function.\n fvec(1) = one - x(1)\n fvec(2) = ten*(x(2) - x(1)**2)\n end select\n\n end subroutine vecfcn\n\nend program test_chkder\n", "meta": {"hexsha": "776d8a843946501caeded6a3c6a8dbb1a41c44f4", "size": 32483, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/test_chkder.f90", "max_stars_repo_name": "awvwgk/minpack", "max_stars_repo_head_hexsha": "dc14d611af8d9c16d08039d6e5a6d45b766b8022", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2022-02-02T14:46:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-16T21:34:09.000Z", "max_issues_repo_path": "test/test_chkder.f90", "max_issues_repo_name": "fortran-lang/minpack", "max_issues_repo_head_hexsha": "c0b5aea9fcd2b83865af921a7a7e881904f8d3c2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 58, "max_issues_repo_issues_event_min_datetime": "2022-02-02T14:43:38.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-18T02:18:48.000Z", "max_forks_repo_path": "test/test_chkder.f90", "max_forks_repo_name": "awvwgk/minpack", "max_forks_repo_head_hexsha": "dc14d611af8d9c16d08039d6e5a6d45b766b8022", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2022-02-02T14:58:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-01T17:17:47.000Z", "avg_line_length": 38.9017964072, "max_line_length": 125, "alphanum_fraction": 0.4478650371, "num_tokens": 9669, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.82893881677331, "lm_q2_score": 0.7879312006227324, "lm_q1q2_score": 0.6531467571429813}} {"text": "C SUBROUTINE H12 (MODE,LPIVOT,L1,M,U,IUE,UP,C,ICE,ICV,NCV) \nC \nC CONSTRUCTION AND/OR APPLICATION OF A SINGLE \nC HOUSEHOLDER TRANSFORMATION.. Q = I + U*(U**T)/B \nC \nC The original version of this code was developed by\nC Charles L. Lawson and Richard J. Hanson at Jet Propulsion Laboratory\nC 1973 JUN 12, and published in the book\nC \"SOLVING LEAST SQUARES PROBLEMS\", Prentice-HalL, 1974.\nC Revised FEB 1995 to accompany reprinting of the book by SIAM.\nC ------------------------------------------------------------------\nC Subroutine Arguments\nC\nC MODE = 1 OR 2 Selects Algorithm H1 to construct and apply a\nC Householder transformation, or Algorithm H2 to apply a\nC previously constructed transformation.\nC LPIVOT IS THE INDEX OF THE PIVOT ELEMENT. \nC L1,M IF L1 .LE. M THE TRANSFORMATION WILL BE CONSTRUCTED TO \nC ZERO ELEMENTS INDEXED FROM L1 THROUGH M. IF L1 GT. M \nC THE SUBROUTINE DOES AN IDENTITY TRANSFORMATION.\nC U(),IUE,UP On entry with MODE = 1, U() contains the pivot\nC vector. IUE is the storage increment between elements. \nC On exit when MODE = 1, U() and UP contain quantities\nC defining the vector U of the Householder transformation.\nC on entry with MODE = 2, U() and UP should contain\nC quantities previously computed with MODE = 1. These will\nC not be modified during the entry with MODE = 2. \nC C() ON ENTRY with MODE = 1 or 2, C() CONTAINS A MATRIX WHICH\nC WILL BE REGARDED AS A SET OF VECTORS TO WHICH THE\nC HOUSEHOLDER TRANSFORMATION IS TO BE APPLIED.\nC ON EXIT C() CONTAINS THE SET OF TRANSFORMED VECTORS.\nC ICE STORAGE INCREMENT BETWEEN ELEMENTS OF VECTORS IN C(). \nC ICV STORAGE INCREMENT BETWEEN VECTORS IN C(). \nC NCV NUMBER OF VECTORS IN C() TO BE TRANSFORMED. IF NCV .LE. 0 \nC NO OPERATIONS WILL BE DONE ON C(). \nC ------------------------------------------------------------------\n SUBROUTINE H12 (MODE,LPIVOT,L1,M,U,IUE,UP,C,ICE,ICV,NCV) \nC ------------------------------------------------------------------\n integer I, I2, I3, I4, ICE, ICV, INCR, IUE, J\n integer L1, LPIVOT, M, MODE, NCV\n double precision B, C(*), CL, CLINV, ONE, SM\nC double precision U(IUE,M)\n double precision U(IUE,*)\n double precision UP\n parameter(ONE = 1.0d0)\nC ------------------------------------------------------------------\n IF (0.GE.LPIVOT.OR.LPIVOT.GE.L1.OR.L1.GT.M) RETURN \n CL=abs(U(1,LPIVOT)) \n IF (MODE.EQ.2) GO TO 60 \nC ****** CONSTRUCT THE TRANSFORMATION. ******\n DO 10 J=L1,M \n 10 CL=MAX(abs(U(1,J)),CL) \n IF (CL) 130,130,20\n 20 CLINV=ONE/CL \n SM=(U(1,LPIVOT)*CLINV)**2 \n DO 30 J=L1,M \n 30 SM=SM+(U(1,J)*CLINV)**2 \n CL=CL*SQRT(SM) \n IF (U(1,LPIVOT)) 50,50,40 \n 40 CL=-CL\n 50 UP=U(1,LPIVOT)-CL \n U(1,LPIVOT)=CL \n GO TO 70 \nC ****** APPLY THE TRANSFORMATION I+U*(U**T)/B TO C. ******\nC \n 60 IF (CL) 130,130,70\n 70 IF (NCV.LE.0) RETURN \n B= UP*U(1,LPIVOT)\nC B MUST BE NONPOSITIVE HERE. IF B = 0., RETURN.\nC \n IF (B) 80,130,130 \n 80 B=ONE/B \n I2=1-ICV+ICE*(LPIVOT-1) \n INCR=ICE*(L1-LPIVOT) \n DO 120 J=1,NCV\n I2=I2+ICV \n I3=I2+INCR \n I4=I3 \n SM=C(I2)*UP\n DO 90 I=L1,M \n SM=SM+C(I3)*U(1,I)\n 90 I3=I3+ICE \n IF (SM) 100,120,100 \n 100 SM=SM*B \n C(I2)=C(I2)+SM*UP\n DO 110 I=L1,M \n C(I4)=C(I4)+SM*U(1,I)\n 110 I4=I4+ICE \n 120 CONTINUE \n 130 RETURN\n END \n", "meta": {"hexsha": "0e722c80e32db11cde6ca1074ed66fe60a69f96b", "size": 3857, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "lawson-hanson/fortran/h12.f", "max_stars_repo_name": "jhu-cisst/cisstNetlib", "max_stars_repo_head_hexsha": "19932915dc3e24bddeff7078b270f862e86e3f9e", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-10-19T03:12:28.000Z", "max_stars_repo_stars_event_max_datetime": "2017-10-19T03:12:28.000Z", "max_issues_repo_path": "lawson-hanson/fortran/h12.f", "max_issues_repo_name": "jhu-cisst/cisstNetlib", "max_issues_repo_head_hexsha": "19932915dc3e24bddeff7078b270f862e86e3f9e", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2015-08-07T23:07:38.000Z", "max_issues_repo_issues_event_max_datetime": "2015-09-28T14:48:54.000Z", "max_forks_repo_path": "lawson-hanson/fortran/h12.f", "max_forks_repo_name": "jhu-cisst/cisstNetlib", "max_forks_repo_head_hexsha": "19932915dc3e24bddeff7078b270f862e86e3f9e", "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": 41.9239130435, "max_line_length": 72, "alphanum_fraction": 0.5208711434, "num_tokens": 1215, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388252252041, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.6531467555465307}} {"text": "!\n! ej3a.f90\n!\n! Copyright 2016 Bruno S \n!\n! This program is free software; you can redistribute it and/or modify\n! it under the terms of the GNU General Public License as published by\n! the Free Software Foundation; either version 2 of the License, or\n! (at your option) any later version.\n!\n! This program is distributed in the hope that it will be useful,\n! but WITHOUT ANY WARRANTY; without even the implied warranty of\n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n! GNU General Public License for more details.\n!\nprogram integralMC\nuse precision, pr => dp\nuse mtmod\n\nimplicit none\ninteger :: i, j, k\nreal(pr) :: x, Imc, exact, error, cum\n\n\nopen(unit=10, file='ej3a.dat', status='UNKNOWN', action='WRITE')\nwrite(10, *) \"# n Imc err \"\n\nexact=0.25\ncum = 0\ndo i = 1, 100000\n x = grnd()\n cum = cum + f(x)\n if (mod(i, 10)==0) then\n Imc = cum/real(i, pr)\n error = abs(exact - Imc)\n write(10, *) i, Imc, error\n end if\nend do\n\n\n\ncontains\n\nfunction f(x)\nimplicit none\nreal(pr) :: f, x\n\nf = x**3.\nend function f\n\nend program\n", "meta": {"hexsha": "d6330cdadf6107bf9b90d8c138f616f7137e8463", "size": 1158, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lab3/ej3a.f90", "max_stars_repo_name": "BrunoSanchez/fisicaComp", "max_stars_repo_head_hexsha": "be5f61675fee6e370b6d3f5a7eb254fd112c61b0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lab3/ej3a.f90", "max_issues_repo_name": "BrunoSanchez/fisicaComp", "max_issues_repo_head_hexsha": "be5f61675fee6e370b6d3f5a7eb254fd112c61b0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lab3/ej3a.f90", "max_forks_repo_name": "BrunoSanchez/fisicaComp", "max_forks_repo_head_hexsha": "be5f61675fee6e370b6d3f5a7eb254fd112c61b0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.2692307692, "max_line_length": 70, "alphanum_fraction": 0.6355785838, "num_tokens": 333, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289388167733099, "lm_q2_score": 0.7879311906630568, "lm_q1q2_score": 0.6531467488870196}} {"text": "module types\n ! ----------------------------------------------------------------\n ! cosmetics:\n ! This module contains all types and formats\n ! author:\n ! Exam-roll -- 20419PHY083\n ! env details:\n ! compiler -- gfortran v10.2.0\n ! OS -- macOS 12.0 x86_64\n ! Kernel -- Darwin 21.0.0\n ! Note:\n ! - used for the module \"tools\"\n ! ----------------------------------------------------------------\n implicit none\n\n ! various parameters used across my programs\n integer, parameter :: dp = selected_real_kind(15, 307) ! double precession\n real(dp), parameter :: pi = 4.d0*atan(1.d0) ! value of PI\n\n ! format specifier section\n ! the \"----\" lines\n character(len=15), parameter :: line2 = \"(1x,2a10)\"\n character(len=20), parameter :: line3 = \"(a8,2(2x,a8))\"\n character(len=25), parameter :: line3n = \"(2(2x,a8),10x,a25)\"\n character(len=25), parameter :: line5 = \"(a8,3(2x,a8),5x,a8)\"\n character(len=25), parameter :: line6 = \"(a8,4(2x,a8),5x,a8)\"\n ! the table headers\n character(len=15), parameter :: form_header2 = \"(3x,a8,2x,a8)\"\n character(len=20), parameter :: form_header3 = \"(/,a5,2(5x,a5))\"\n character(len=25), parameter :: form_header3n = \"(/,3x,a5,4x,a5,20x,a8)\"\n character(len=25), parameter :: form_header5 = \"(/,a6,3(5x,a5),8x,a6)\"\n character(len=25), parameter :: form_header6 = \"(/,a6,4(5x,a5),8x,a6)\"\n ! the table datas\n character(len=10), parameter :: form_table2 = \"(2f10.4)\"\n character(len=20), parameter :: form_table3 = \"(i5,3x,2f10.4)\"\n character(len=30), parameter :: form_table5 = \"(i5,3x,3F10.4,2(3x,f10.5))\"\n character(len=30), parameter :: form_table6 = \"(i5,3x,4F10.4,3x,f10.5)\"\n character(len=30), parameter :: form_tableip = \"(f10.2, 10f10.4)\"\n ! the final results\n character(len=15), parameter :: form_result1rj = \"(f10.4,2x,a,i1)\"\n character(len=15), parameter :: form_result2r = \"(f10.4,2x,a)\"\n character(len=15), parameter :: form_result2rp = \"(f15.8,2x,a)\"\n character(len=15), parameter :: form_result2i = \"(i15,2x,a)\"\n character(len=15), parameter :: form_result2c = \"(3x,a10,a28)\"\n\nend module types\n", "meta": {"hexsha": "5342084464a8b2d0b0b805c48ec0a7e3cb4ceea3", "size": 2086, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "module/types.f95", "max_stars_repo_name": "okarin001/fortran-numerical-analysis", "max_stars_repo_head_hexsha": "1e9b88df3d338ff1143b1cd63e057759b47d6876", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "module/types.f95", "max_issues_repo_name": "okarin001/fortran-numerical-analysis", "max_issues_repo_head_hexsha": "1e9b88df3d338ff1143b1cd63e057759b47d6876", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "module/types.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": 44.3829787234, "max_line_length": 76, "alphanum_fraction": 0.6021093001, "num_tokens": 709, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311956428947, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.6531467463554893}} {"text": " program PI\n implicit none\n integer i, num_iter\n double precision x, my_pi, contrib, iter\n contrib = 0.0\n num_iter = 10\n iter = 1.0/num_iter\n\n!$OMP PARALLEL DO REDUCTION (+:contrib)\n DO i = 1, num_iter\n\t x = (i-0.5)*iter\n\t contrib = contrib + 4.0/(1.0+x*x)\n\t print *, i,x,contrib\n END DO\n!$OMP END PARALLEL DO\n\n my_pi = iter * contrib\n\n print *,my_pi\n END\n", "meta": {"hexsha": "211c482d40ab6e0dfdd742d798868b9d47bad8ab", "size": 416, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "packages/PIPS/validation/Step/pi.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/Step/pi.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/Step/pi.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": 19.8095238095, "max_line_length": 46, "alphanum_fraction": 0.5649038462, "num_tokens": 141, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8289387998695209, "lm_q2_score": 0.787931188173138, "lm_q1q2_score": 0.6531467335040066}} {"text": "module interpolation\n\n! Module for cubic splines, Lagrange and Hermite interpolation.\n! Requires Lapack.\n\n! Splines are fully specified by the interpolation points, except that\n! at the ends, we have the freedom to prescribe the second derivatives.\n! If we know a derivative at an end (exactly), then best is to impose that.\n! Otherwise, it is better to use the \"consistent\" end conditions: the second\n! derivative is determined such that it is smooth.\n!\n! High level API: spline3, spline3ders.\n! Low level API: the rest of public soubroutines.\n!\n! Use the high level API to obtain cubic spline fit with consistent boundary\n! conditions and optionally the derivatives. Use the low level API if more fine\n! grained control is needed.\n!\n! This module is based on a code written by John E. Pask, LLNL.\n\nuse types, only: dp\nuse lapack, only: dgesv, dgbsv\nuse utils, only: stop_error, assert, newunit, white_char\nimplicit none\nprivate\npublic spline3pars, spline3valder, iix, iixmin, iixun, iixexp, poly3, dpoly3, &\n d2poly3, spline3, spline3ders, hermite5interp, lagrange3interp, &\n hermite_basis_1, hermite_basis_2, loadtxt\n\ncontains\n\nfunction spline3(x, y, xnew) result(ynew)\n! Takes the function values 'y' on the grid 'x' and returns new values 'ynew'\n! at the given grid 'xnew' using cubic splines interpolation with such\n! boundary conditions so that the 2nd derivative is consistent with the\n! interpolating cubic.\nreal(dp), intent(in) :: x(:), y(:), xnew(:)\nreal(dp) :: ynew(size(xnew))\nreal(dp) :: c(0:4, size(x)-1)\ninteger :: i, ip\n! get spline parameters: 2nd derivs at ends determined by cubic interpolation\ncall spline3pars(x, y, [2, 2], [0._dp, 0._dp], c)\n\nip = 0\ndo i = 1, size(xnew)\n ip = iixmin(xnew(i), x, ip)\n ynew(i) = poly3(xnew(i), c(:, ip))\nend do\nend function\n\nsubroutine spline3ders(x, y, xnew, ynew, dynew, d2ynew)\n! Just like 'spline', but also calculate 1st and 2nd derivatives\nreal(dp), intent(in) :: x(:), y(:), xnew(:)\nreal(dp), intent(out), optional :: ynew(:), dynew(:), d2ynew(:)\nreal(dp) :: c(0:4, size(x)-1)\ninteger :: i, ip\ncall spline3pars(x, y, [2, 2], [0._dp, 0._dp], c)\n\nip = 0\ndo i = 1, size(xnew)\n ip = iixmin(xnew(i), x, ip)\n if (present( ynew)) ynew(i) = poly3(xnew(i), c(:, ip))\n if (present( dynew)) dynew(i) = dpoly3(xnew(i), c(:, ip))\n if (present(d2ynew)) d2ynew(i) = d2poly3(xnew(i), c(:, ip))\nend do\nend subroutine\n\nsubroutine spline3pars(xi,yi,bctype,bcval,c)\n! Returns parameters c defining cubic spline interpolating x-y data xi, yi, with\n! boundary conditions specified by bcytpe, bcvals\nreal(dp), intent(in):: xi(:) ! x values of data\nreal(dp), intent(in):: yi(:) ! y values of data\ninteger, intent(in):: bctype(2) ! type of boundary condition at each end:\n ! bctype(1) = type at left end, bctype(2) = type at right end.\n ! 1 = specified 2nd derivative, 2 = 2nd derivative consistent with interpolating cubic.\nreal(dp), intent(in):: bcval(2) ! boundary condition values at each end:\n ! bcval(1) = value at left end, bcval(2) = value at right end\nreal(dp), intent(out):: c(0:,:) ! parameters defining spline: c(i,j) = ith parameter of jth\n ! spline polynomial, p_j = sum_{i=1}^4 c(i,j) (x-c(0,j))^(i-1), j = 1..n-1, n = # of data pts.\n ! dimensions: c(0:4,1:n-1)\nreal(dp) As(5,2*size(c,2)) ! spline eq. matrix -- LAPACK band form\nreal(dp) bs(2*size(c,2)) ! spline eq. rhs vector\nreal(dp) cs(2*size(c,2)) ! spline eq. solution vector\nreal(dp) hi(size(c,2)) ! spline intervals\nreal(dp) Ae(4,4) ! end-cubic eq. matrix\nreal(dp) be(4) ! end-cubic eq. rhs vector\nreal(dp) ce(4) ! end-cubic eq. solution vector\nreal(dp) xe(4),ye(4) ! x,y values at ends\nreal(dp) d2p1,d2pn ! 2nd derivatives at ends\nreal(dp) x0 ! expansion center\nreal(dp) c1,c2,c3,c4 ! expansion coefficients\ninteger n ! number of data points\ninteger i,j,i2\n! lapack variables\ninteger ipiv(4),ipiv2(2*size(c,2))\nreal(dp) bemat(4,1),bmat(2*size(c,2),1)\ninteger info\n\n! check input parameters\nif (bctype(1) < 1 .or. bctype(1) > 2) call stop_error(\"spline3pars error: bctype /= 1 or 2.\")\nif (bctype(2) < 1 .or. bctype(2) > 2) call stop_error(\"spline3pars error: bctype /= 1 or 2.\")\nif (size(c,1) /= 5) call stop_error(\"spline3pars error: size(c,1) /= 5.\")\nif (size(c,2) /= size(xi)-1) call stop_error(\"spline3pars error: size(c,2) /= size(xi)-1.\")\nif (size(xi) /= size(yi)) call stop_error(\"spline3pars error: size(xi) /= size(yi)\")\n\n! To get rid of compiler warnings:\nd2p1 = 0\nd2pn = 0\n\n! initializations\nn=size(xi)\ndo i=1,n-1\n hi(i)=xi(i+1)-xi(i)\nend do\n\n! compute interpolating-cubic 2nd derivs at ends, if required\n ! left end\nif(bctype(1)==2) then\n if (n < 4) call stop_error(\"spline3pars error: n < 4\")\n xe=xi(1:4)\n ye=yi(1:4)\n x0=xe(1) ! center at end\n do i=1,4\n do j=1,4\n Ae(i,j) = (xe(i)-x0)**(j-1)\n end do\n end do\n Ae(:,1) = 1 ! set 0^0 = 1\n be=ye; bemat(:,1)=be\n call dgesv(4, 1, Ae, 4, ipiv, bemat, 4, info)\n if (info /= 0) call stop_error(\"spline3pars error: dgesv error.\")\n ce=bemat(:,1)\n d2p1=2*ce(3)\nend if\n ! right end\nif(bctype(2)==2) then\n if (n < 4) call stop_error(\"spline3pars error: n < 4\")\n xe=xi(n-3:n)\n ye=yi(n-3:n)\n x0=xe(4) ! center at end\n do i=1,4\n do j=1,4\n Ae(i,j) = (xe(i)-x0)**(j-1)\n end do\n end do\n Ae(:,1) = 1 ! set 0^0 = 1\n be=ye; bemat(:,1)=be\n call dgesv(4, 1, Ae, 4, ipiv, bemat, 4, info)\n if (info /= 0) call stop_error(\"spline3pars error: dgesv error.\")\n ce=bemat(:,1)\n d2pn=2*ce(3)\nend if\n\n! set 2nd derivs at ends\nif(bctype(1)==1) d2p1=bcval(1)\nif(bctype(2)==1) d2pn=bcval(2)\n!write(*,*) d2p1,d2pn\n\n! construct spline equations -- LAPACK band form\n! basis: phi1 = -(x-x_i)/h_i, phi2 = (x-x_{i+1})/h_i, phi3 = phi1^3-phi1, phi4 = phi2^3-phi2\n! on interval [x_i,x_{i+1}] of length h_i = x_{i+1}-x_i\n!A=0 ! full matrix\nAs=0\n ! left end condition\n!A(1,1)=6/hi(1)**2 ! full matrix\nAs(4,1)=6/hi(1)**2\nbs(1)=d2p1\n ! internal knot conditions\ndo i=2,n-1\n i2=2*(i-1)\n! A(i2,i2-1) = 1/hi(i-1) ! full matrix ...\n! A(i2,i2) = 2/hi(i-1)\n! A(i2,i2+1) = 2/hi(i)\n! A(i2,i2+2) = 1/hi(i)\n! A(i2+1,i2) = 1/hi(i-1)**2\n! A(i2+1,i2+1) = -1/hi(i)**2\n As(5,i2-1) = 1/hi(i-1)\n As(4,i2) = 2/hi(i-1)\n As(3,i2+1) = 2/hi(i)\n As(2,i2+2) = 1/hi(i)\n As(5,i2) = 1/hi(i-1)**2\n As(4,i2+1) = -1/hi(i)**2\n bs(i2) = (yi(i+1) - yi(i))/hi(i) - (yi(i) - yi(i-1))/hi(i-1)\n bs(i2+1) = 0\nend do\n ! right end condition \n!A(2*(n-1),2*(n-1))=6/hi(n-1)**2 ! full matrix\nAs(4,2*(n-1))=6/hi(n-1)**2\nbs(2*(n-1))=d2pn\n\n! solve spline equations -- full matrix\n!bmat(:,1)=bs\n!call dgesv(2*(n-1), 1, A, 2*(n-1), ipiv2, bmat, 2*(n-1), info)\n!if (info /= 0) call stop_error(\"spline3pars error: dgesv error.\")\n!cs=bmat(:,1)\n\n! solve spline equations -- LAPACK band form\nbmat(:,1)=bs\ncall dgbsv(2*(n-1), 1, 2, 1, As, 5, ipiv2, bmat, 2*(n-1), info)\nif (info /= 0) call stop_error(\"spline3pars error: dgbsv error.\")\ncs=bmat(:,1)\n!write(*,*) cs(1:6)\n!write(*,*) cs(2*(n-1)-5:2*(n-1))\n\n! transform to (x-x0)^(i-1) basis and return\ndo i=1,n-1\n ! coefficients in spline basis:\n c1=yi(i)\n c2=yi(i+1)\n c3=cs(2*i-1)\n c4=cs(2*i)\n ! coefficients in (x-x0)^(i-1) basis\n c(0,i)=xi(i)\n c(1,i)=c1\n c(2,i)=-(c1-c2+2*c3+c4)/hi(i)\n c(3,i)=3*c3/hi(i)**2\n c(4,i)=(-c3+c4)/hi(i)**3\nend do\nend subroutine\n\n!--------------------------------------------------------------------------------------------------!\n\nsubroutine spline3valder(x,xi,c,val,der)\n! Returns value and 1st derivative of spline defined by knots xi and parameters c\n! returned by spline3pars\nreal(dp), intent(in):: x ! point at which to evaluate spline\nreal(dp), intent(in):: xi(:) ! spline knots (x values of data)\nreal(dp), intent(in):: c(0:,:) ! spline parameters: c(i,j) = ith parameter of jth\n ! spline polynomial, p_j = sum_{i=1}^4 c(i,j) (x-c(0,j))^(i-1), j = 1..n-1, n = # of data pts.\n ! dimensions: c(0:4,1:n-1)\nreal(dp), intent(out):: val ! value of spline at x\nreal(dp), intent(out):: der ! 1st derivative of spline at x\ninteger n ! number of knots\ninteger i1\n\n! initialize, check input parameters\nn=size(xi)\nif (size(c,1) /= 5) call stop_error(\"spline3 error: size(c,1) /= 5.\")\nif (size(c,2) /= size(xi)-1) call stop_error(\"spline3 error: size(c,2) /= size(xi)-1.\")\n! find interval containing x\ni1=iix(x,xi)\n! return value and derivative\nval=poly3(x,c(:,i1))\nder=dpoly3(x,c(:,i1))\nend subroutine\n\n!--------------------------------------------------------------------------------------------------!\n\ninteger function iix(x, xi) result(i1)\n! Returns index i of interval [xi(i),xi(i+1)] containing x in mesh xi,\n! with intervals indexed by left-most points.\n! N.B.: x outside [x1,xn] are indexed to nearest end.\n! Uses bisection, except if \"x\" lies in the first or second elements (which is\n! often the case)\nreal(dp), intent(in) :: x ! target value\nreal(dp), intent(in) :: xi(:) ! mesh, xi(i) < xi(i+1)\ninteger n ! number of mesh points\ninteger i2, ic\n\nn = size(xi)\ni1 = 1\nif (n < 2) then\n call stop_error(\"error in iix: n < 2\")\nelseif (n == 2) then\n i1 = 1\nelseif (n == 3) then\n if (x <= xi(2)) then ! first element\n i1 = 1\n else\n i1 = 2\n end if\nelseif (x <= xi(1)) then ! left end\n i1 = 1\nelseif (x <= xi(2)) then ! first element\n i1 = 1\nelseif (x <= xi(3)) then ! second element\n i1 = 2\nelseif (x >= xi(n)) then ! right end\n i1 = n-1\nelse\n ! bisection: xi(i1) <= x < xi(i2)\n i1 = 3; i2 = n\n do\n if (i2 - i1 == 1) exit\n ic = i1 + (i2 - i1)/2\n if (x >= xi(ic)) then\n i1 = ic\n else\n i2 = ic\n endif\n end do\nend if\nend function\n\ninteger function iixmin(x, xi, i_min) result(ip)\n! Just like iix, but assumes that x >= xi(i_min)\nreal(dp), intent(in) :: x, xi(:)\ninteger, intent(in) :: i_min\nif (i_min >= 1 .and. i_min <= size(xi)-1) then\n ip = iix(x, xi(i_min:)) + i_min - 1\nelse\n ip = iix(x, xi)\nend if\nend function\n\n!--------------------------------------------------------------------------------------------------!\n\nfunction iixun(x,n,x1,xn)\n! Returns index i of interval [x(i),x(i+1)] containing x in uniform mesh defined by\n! x(i) = x1 + (i-1)/(n-1)*(xn-x1), i = 1 .. n,\n! with intervals indexed by left-most points.\n! N.B.: x outside [x1,xn] are indexed to nearest end.\ninteger iixun ! index i of interval [x(i),x(i+1)] containing x\nreal(dp), intent(in):: x ! target value\ninteger, intent(in):: n ! number of mesh points\nreal(dp), intent(in):: x1 ! initial point of mesh\nreal(dp), intent(in):: xn ! final point of mesh\ninteger i\n\n! compute index\ni=int((x-x1)/(xn-x1)*(n-1))+1\n! reset if ouside 1..n\nif (i<1) i=1\nif (i>n-1) i=n-1\niixun=i\nend function\n\n!--------------------------------------------------------------------------------------------------!\n\nfunction iixexp(x,n,x1,alpha,beta)\n! Returns index i of interval [x(i),x(i+1)] containing x in exponential mesh defined by\n! x(i) = x1 + alpha [ exp(beta(i-1)) - 1 ], i = 1 .. n,\n! where alpha = (x(n) - x(1))/[ exp(beta(n-1)) - 1 ],\n! beta = log(r)/(n-2), r = (x(n)-x(n-1))/(x(2)-x(1)) = ratio of last to first interval,\n! and intervals indexed by left-most points.\n! N.B.: x outside [x1,xn] are indexed to nearest end.\ninteger iixexp ! index i of interval [x(i),x(i+1)] containing x\nreal(dp), intent(in):: x ! target value\ninteger, intent(in):: n ! number of mesh points\nreal(dp), intent(in):: x1 ! initial point of mesh\nreal(dp), intent(in):: alpha ! mesh parameter:\n! x(i) = x1 + alpha [ exp(beta(i-1)) - 1 ], i = 1 .. n,\n! where alpha = (x(n) - x(1))/[ exp(beta(n-1)) - 1 ],\n! beta = log(r)/(n-2), r = (x(n)-x(n-1))/(x(2)-x(1)) = ratio of last to first interval,\nreal(dp), intent(in):: beta ! mesh parameter\ninteger i\n\n! compute index\ni=int(log((x-x1)/alpha + 1)/beta) + 1\n! reset if outside 1..n\nif (i<1) i=1\nif (i>n-1) i=n-1\niixexp=i\nend function\n\n!--------------------------------------------------------------------------------------------------!\n\nfunction poly3(x,c)\n! returns value of polynomial \\sum_{i=1}^4 c(i) (x-c(0))^(i-1)\nreal(dp) poly3\nreal(dp), intent(in):: x ! point at which to evaluate polynomial\nreal(dp), intent(in):: c(0:) ! coefficients: poly = \\sum_{i=1}^4 c(i) (x-c(0))^(i-1)\nreal(dp) dx\ndx=x-c(0)\npoly3=c(1)+c(2)*dx+c(3)*dx**2+c(4)*dx**3\nend function\n\n!--------------------------------------------------------------------------------------------------!\n\nfunction dpoly3(x,c)\n! returns 1st derivative of polynomial \\sum_{i=1}^4 c(i) (x-c(0))^(i-1)\nreal(dp) dpoly3\nreal(dp), intent(in):: x ! point at which to evaluate polynomial\nreal(dp), intent(in):: c(0:) ! coefficients: poly = \\sum_{i=1}^4 c(i) (x-c(0))^(i-1)\nreal(dp) dx\ndx=x-c(0)\ndpoly3=c(2)+2*c(3)*dx+3*c(4)*dx**2\nend function\n\n!--------------------------------------------------------------------------------------------------!\n\nfunction d2poly3(x,c)\n! returns 2nd derivative of polynomial \\sum_{i=1}^4 c(i) (x-c(0))^(i-1)\nreal(dp) d2poly3\nreal(dp), intent(in):: x ! point at which to evaluate polynomial\nreal(dp), intent(in):: c(0:) ! coefficients: poly = \\sum_{i=1}^4 c(i) (x-c(0))^(i-1)\nreal(dp) dx\ndx=x-c(0)\nd2poly3=2*c(3)+6*c(4)*dx\nend function\n\nfunction lagrange3interp(x, y, xnew) result(ynew)\n! Takes the function values 'y' on the grid 'x' and returns new values 'ynew'\n! at the given grid 'xnew' using cubic Lagrange interpolation through the\n! current interval plus one to the left and right (3 intervals and 4 points\n! total). The first three intervals are used for interpolation on the first\n! interval or to the left of the grid 'x'. The last three intervals are used\n! for interpolation at the last interval or to the right of the grid 'x'.\nreal(dp), intent(in) :: x(:), y(:), xnew(:)\nreal(dp) :: ynew(size(xnew))\ninteger :: i, j, ip, idx\nidx = 0\ndo i = 1, size(xnew)\n idx = iixmin(xnew(i), x, idx)\n ! Decide which three intervals to use for interpolation at the point xnew(i)\n ip = idx - 1\n if (ip < 1) ip = 1\n if (ip > size(x)-3) ip = size(x)-3\n ! Interpolate using the three intervals given by the four points x(ip, ip+3)\n ynew(i) = 0\n do j = 1, 4\n ynew(i) = ynew(i) + phih(x(ip:ip+3), j, xnew(i)) * y(ip+j-1)\n end do\nend do\nend function\n\nfunction hermite5interp(x, y, yd, extend_right, xnew) result(ynew)\n! Takes the function values 'y' and derivatives 'yd' on the grid 'x' and\n! returns new values 'ynew' at the given grid 'xnew' using 5th order Hermite\n! interpolation. This version uses a Hermite interpolation basis instead of\n! solving a 6x6 linear system.\nreal(dp), intent(in) :: x(:), y(:), yd(:), xnew(:)\nlogical, intent(in) :: extend_right\nreal(dp) :: ynew(size(xnew))\ninteger :: i, j, ip, idx\n\nidx = 0\ndo i = 1, size(xnew)\n idx = iixmin(xnew(i), x, idx)\n ! Decide which two intervals to use for interpolation at the point xnew(i)\n if (extend_right) then\n ip = idx\n if (ip > size(x)-2) ip = size(x)-2\n else\n ip = idx - 1\n if (ip < 1) ip = 1\n end if\n ! Interpolate using the two intervals ip,ip+1 and ip+1,ip+2. These two\n ! intervals are given by the three points x(ip,ip+2).\n ynew(i) = 0\n do j = 1, 3\n ynew(i) = ynew(i) + hermite_basis_1(x(ip:ip+2), j, xnew(i)) * y (ip+j-1)\n ynew(i) = ynew(i) + hermite_basis_2(x(ip:ip+2), j, xnew(i)) * yd(ip+j-1)\n end do\nend do\nend function\n\nreal(dp) pure function phih(xin, n, xi)\n! \"phi hat\": nth Lagrange polynomial with nodes xin at point xi.\n! Value equals to 1 for xi=xin(n) and zero for all other nodes.\nreal(dp), intent(in) :: xin(:) ! polynomial nodes\ninteger, intent(in) :: n ! polynomial index\nreal(dp), intent(in) :: xi ! point at which to evaluate phih\ninteger :: i\n! compute nth polynomial: 1 at node n, 0 at all others\nphih = 1\ndo i = 1, size(xin)\n if (i == n) cycle\n phih = phih * (xi-xin(i))/(xin(n)-xin(i))\nend do\nend function\n\nreal(dp) pure function dphih(xin, n, xi)\n! \"d phi hat\": derivative of nth Lagrange polynomial with nodes 'xin' at point\n! 'xi'.\nreal(dp), intent(in) :: xin(:) ! polynomial nodes\ninteger, intent(in) :: n ! polynomial index\nreal(dp), intent(in) :: xi ! point at which to evaluate dphih\nreal(dp) :: term\nreal(dp) :: tmp(size(xin))\ninteger :: i, j\ndo i = 1, size(xin)\n if (i==n) cycle\n tmp(i) = (xi-xin(i))/(xin(n)-xin(i))\nend do\n! compute derivative of nth polynomial\ndphih = 0\ndo j = 1, size(xin)\n if (j == n) cycle\n term = 1 / (xin(n)-xin(j))\n do i = 1, size(xin)\n if (i==n .or. i==j) cycle\n term = term * tmp(i)\n end do\n dphih = dphih + term\nend do\nend function\n\nreal(dp) pure function hermite_basis_1(xin, n, xi) result(h)\n! nth Hermite basis polynomial (first kind) with nodes 'xin' at point 'xi'.\n! Value equals to 1 for xi=xin(n) and zero for all other nodes. Derivatives are\n! zero for all nodes.\nreal(dp), intent(in) :: xin(:) ! polynomial nodes\ninteger, intent(in) :: n ! polynomial index\nreal(dp), intent(in) :: xi ! point at which to evaluate phih\nh = (1-2*dphih(xin, n, xin(n))*(xi - xin(n))) * phih(xin, n, xi)**2\nend function\n\nreal(dp) pure function hermite_basis_2(xin, n, xi) result(h)\n! nth Hermite basis polynomial (second kind) with nodes 'xin' at point 'xi'.\n! Value is zero for all nodes. Derivative equals to 1 for xi=xin(n) and zero\n! for all other nodes.\nreal(dp), intent(in) :: xin(:) ! polynomial nodes\ninteger, intent(in) :: n ! polynomial index\nreal(dp), intent(in) :: xi ! point at which to evaluate phih\nh = (xi - xin(n)) * phih(xin, n, xi)**2\nend function\n\nsubroutine loadtxt(filename, d)\n! Loads a 2D array from a text file.\n!\n! Arguments\n! ---------\n!\n! Filename to load the array from\ncharacter(len=*), intent(in) :: filename\n! The array 'd' will be automatically allocated with the correct dimensions\nreal(dp), allocatable, intent(out) :: d(:, :)\n!\n! Example\n! -------\n!\n! real(dp), allocatable :: data(:, :)\n! call loadtxt(\"log.txt\", data) ! 'data' will be automatically allocated\n!\n! Where 'log.txt' contains for example::\n!\n! 1 2 3\n! 2 4 6\n! 8 9 10\n! 11 12 13\n! ...\n!\ncharacter :: c\ninteger :: s, ncol, nrow, ios, i\nlogical :: lastwhite\nreal(dp) :: r\n\nopen(newunit(s), file=filename, status=\"old\")\n\n! determine number of columns\nncol = 0\nlastwhite = .true.\ndo\n read(s, '(a)', advance='no', iostat=ios) c\n if (ios /= 0) exit\n if (lastwhite .and. .not. white_char(c)) ncol = ncol + 1\n lastwhite = white_char(c)\nend do\n\nrewind(s)\n\n! determine number or rows\nnrow = 0\ndo\n read(s, *, iostat=ios) r\n if (ios /= 0) exit\n nrow = nrow + 1\nend do\n\nrewind(s)\n\nallocate(d(nrow, ncol))\ndo i = 1, nrow\n read(s, *) d(i, :)\nend do\nclose(s)\nend subroutine\n\nend module\n", "meta": {"hexsha": "423ead2170fae03b200602ebd9b40689470072f3", "size": 19072, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/interpolation.f90", "max_stars_repo_name": "rc/dftatom", "max_stars_repo_head_hexsha": "fe479fd27a7e0f77c6a88a1949996406ec935ac2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 40, "max_stars_repo_stars_event_min_datetime": "2015-03-19T16:00:14.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-29T03:06:10.000Z", "max_issues_repo_path": "src/interpolation.f90", "max_issues_repo_name": "rc/dftatom", "max_issues_repo_head_hexsha": "fe479fd27a7e0f77c6a88a1949996406ec935ac2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2015-06-23T21:59:56.000Z", "max_issues_repo_issues_event_max_datetime": "2019-09-04T20:36:51.000Z", "max_forks_repo_path": "src/interpolation.f90", "max_forks_repo_name": "rc/dftatom", "max_forks_repo_head_hexsha": "fe479fd27a7e0f77c6a88a1949996406ec935ac2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2015-06-07T15:14:49.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-05T07:03:24.000Z", "avg_line_length": 33.4010507881, "max_line_length": 100, "alphanum_fraction": 0.5871958893, "num_tokens": 6611, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543488, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6530615046669062}} {"text": "\t!--------------------------------------------------------------------\n\t!\n\t!\n\t! PURPOSE\n\t!\n\t! This program solves heat equation in 1 dimension\n\t! u_t=\\alpha*u_{xx}\n\t! using a the backward Euler method for x\\in[0,2\\pi]\n\t!\n\t! The boundary conditions are u(0)=u(2\\pi)\n\t! The initial condition is u=sin(x)\n\t!\n\t! .. Parameters ..\n\t! Nx\t= number of modes in x - power of 2 for FFT\n\t! Nt\t= number of timesteps to take\n\t! Tmax\t= maximum simulation time\n\t! plotgap\t\t\t= number of timesteps between plots\n\t! FFTW_IN_PLACE \t= value for FFTW input \n\t! FFTW_MEASURE \t= value for FFTW input\n\t! FFTW_EXHAUSTIVE \t= value for FFTW input\n\t! FFTW_PATIENT \t= value for FFTW input \n\t! FFTW_ESTIMATE \t= value for FFTW input\n\t! FFTW_FORWARD = value for FFTW input\n\t! FFTW_BACKWARD\t= value for FFTW input\t\n\t! pi = 3.14159265358979323846264338327950288419716939937510d0\n\t! L\t\t\t\t= width of box \n\t! alpha\t\t\t= heat conductivity\n\t! .. Scalars ..\n\t! i\t\t\t\t= loop counter in x direction\n\t! n\t\t\t\t= loop counter for timesteps direction\t\n\t! allocatestatus\t= error indicator during allocation\n\t! start\t\t\t= variable to record start time of program\n\t! finish\t\t\t= variable to record end time of program\n\t! count_rate\t\t= variable for clock count rate\n\t! planfx\t\t\t= Forward 1d fft plan in x\n\t! planbx\t\t\t= Backward 1d fft plan in x\n\t! dt\t\t\t\t= timestep\n\t! .. Arrays ..\n\t! u\t\t\t\t= approximate REAL solution\n\t! v\t\t\t\t= Fourier transform of approximate solution\n\t! vna \t\t\t\t= temporary field\n\t! .. Vectors ..\n\t! kx\t\t\t\t= fourier frequencies in x direction\n\t! x\t\t\t\t= x locations\n\t! time\t\t\t\t= times at which save data\n\t! name_config\t\t= array to store filename for data to be saved \t\t\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! FFTW3\t -- Fast Fourier Transform in the West Library\n\t!\t\t\t(http://www.fftw.org/)\n\t\t\t\t\n\tPROGRAM main\n\t\t\t\t \t \n\t! Declare variables\n\tIMPLICIT NONE\t\t\t\t\t \n\tINTEGER(kind=4),\tPARAMETER \t:: Nx=64 \n\tINTEGER(kind=4),\tPARAMETER\t:: Nt=20 \n\tREAL(kind=8),\tPARAMETER\t&\n\t\t:: pi=3.14159265358979323846264338327950288419716939937510d0\n\tREAL(kind=8),\tPARAMETER\t:: L=5.0d0\t\t\t \n\tREAL(kind=8),\tPARAMETER\t:: alpha=0.50d0\t\n\tREAL(kind=8)\t:: dt=0.2d0/REAL(Nt,kind(0d0))\t\t\n\tCOMPLEX(KIND=8), DIMENSION(:),ALLOCATABLE\t:: kx\t\n\tREAL(kind=8), DIMENSION(:),ALLOCATABLE\t:: x\t\n\tCOMPLEX(KIND=8), DIMENSION(:,:),ALLOCATABLE\t:: u,v\t\n\tREAL(kind=8), DIMENSION(:),ALLOCATABLE\t:: time\n\tCOMPLEX(KIND=8), DIMENSION(:),ALLOCATABLE\t:: vna\t\n\tINTEGER(kind=4)\t:: i,j,k,n\n\tINTEGER(kind=4)\t:: start, finish, count_rate, AllocateStatus\n\tINTEGER(kind=4), PARAMETER\t:: FFTW_IN_PLACE = 8, FFTW_MEASURE = 0, &\n\t\tFFTW_EXHAUSTIVE = 8, FFTW_PATIENT = 32, FFTW_ESTIMATE = 64\n\tINTEGER(kind=4), PARAMETER :: FFTW_FORWARD = -1, FFTW_BACKWARD=1\t\n\tCOMPLEX(KIND=8), DIMENSION(:),ALLOCATABLE :: fftfx,fftbx\n\tINTEGER(kind=8)\t:: planfx,planbx\n\tCHARACTER*100\t:: name_config\n\t \t\t\n\tCALL system_clock(start,count_rate)\t\n\tALLOCATE(kx(1:Nx),x(1:Nx),u(1:Nx,1:1+Nt),v(1:Nx,1:1+Nt),&\n \t\t\ttime(1:1+Nt),vna(1:Nx),fftfx(1:Nx),fftbx(1:Nx),&\n \t\t\tstat=AllocateStatus)\n \tIF (AllocateStatus .ne. 0) STOP \n\n\t\t! set up ffts\n\tCALL dfftw_plan_dft_1d(planfx,Nx,fftfx(1:Nx),fftbx(1:Nx),&\n\t\t\tFFTW_FORWARD,FFTW_ESTIMATE)\n\tCALL dfftw_plan_dft_1d(planbx,Nx,fftbx(1:Nx),fftfx(1:Nx),&\n\t\t\tFFTW_BACKWARD,FFTW_ESTIMATE)\n\t\t\n\tPRINT *,'Setup FFTs'\n\t\t\n\t! setup fourier frequencies\n\tDO i=1,1+Nx/2\n\t\tkx(i)= cmplx(0.0d0,1.0d0)*REAL(i-1,kind(0d0))/L \t\t\t\n\tEND DO\n\tkx(1+Nx/2)=0.00d0\n\tDO i = 1,Nx/2 -1\n\t\tkx(i+1+Nx/2)=-kx(1-i+Nx/2)\n\tEND DO\n\tDO i=1,Nx\n\t\tx(i)=(-1.00d0 + 2.00d0*REAL(i-1,kind(0d0))/REAL(Nx,KIND(0d0)))*pi*L\n\tEND DO\n\t\t\n\tPRINT *,'Setup grid and fourier frequencies and splitting coefficients'\n\t\n\tu(1:Nx,1)=sin(x(1:Nx)) \n\t\t! transform initial data\n\tCALL dfftw_execute_dft_(planfx,u(1:Nx,1),v(1:Nx,1)) \n\tPRINT *,'Got initial data, starting timestepping'\n\ttime(1)=0.0d0\n\n\tvna(1:Nx)=v(1:Nx,1)\n\tPRINT *,'Starting timestepping'\n\tDO n=1,Nt\n\t\tDO i=1,Nx\n\t\t\tvna(i)=vna(i)/(1-dt*kx(i)*kx(i))\n\t\tEND DO\n\t\tPRINT *,'storing plot data ',n\n\t\ttime(n+1)=time(n)+dt\n\t\tv(1:Nx,n+1)=vna(1:Nx)\n\t\tCALL dfftw_execute_dft_(planbx,v(1:Nx,n+1),u(1:Nx,n+1))\n\t\tu(1:Nx,n+1)=u(1:Nx,n+1)/REAL(Nx,KIND(0d0))\t! normalize\n\tEND DO\n\tPRINT *,'Finished time stepping'\n\tCALL system_clock(finish,count_rate)\n\tPRINT*,'Program took ',REAL(finish-start)/REAL(count_rate),'for execution'\n\n\t! Write data out to disk\t\n\n\tname_config = 'u.dat' \n\tOPEN(unit=11,FILE=name_config,status=\"UNKNOWN\") \t\n\tREWIND(11)\n\tDO j=1,1+Nt\n\t\tDO i=1,Nx\n\t\t\tWRITE(11,*) REAL(u(i,j))\n\t\tEND DO\n\tEND DO\n\tCLOSE(11)\n\t\t\n\tname_config = 'tdata.dat' \n\tOPEN(unit=11,FILE=name_config,status=\"UNKNOWN\") \t\n\tREWIND(11)\n\tDO j=1,1+Nt\n\t\tWRITE(11,*) time(j)\n\tEND DO\n\tCLOSE(11)\n\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\n\tPRINT *,'Saved data'\n\tDEALLOCATE(kx,x,u,v,&\n \t\t\ttime,vna,fftfx,fftbx,&\n \t\t\tstat=AllocateStatus)\n \tIF (AllocateStatus .ne. 0) STOP \n\t\n\tCALL dfftw_destroy_plan(planbx)\n\tCALL dfftw_destroy_plan(planfx)\n\tCALL dfftw_cleanup()\n\tPRINT *,'Program execution complete'\n\tEND PROGRAM main\n\n", "meta": {"hexsha": "caee1392ed9a44aaa7499d187801abadf5cd78fd", "size": 5370, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "FortranPrograms/Programs/FortranHeatEquation/heat.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": "FortranPrograms/Programs/FortranHeatEquation/heat.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": "FortranPrograms/Programs/FortranHeatEquation/heat.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": 29.6685082873, "max_line_length": 75, "alphanum_fraction": 0.6487895717, "num_tokens": 2034, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093975331752, "lm_q2_score": 0.731058584489497, "lm_q1q2_score": 0.6530615036717684}} {"text": "!=====================================================\nSUBROUTINE eva2d(nx,ny,ix,iy,dx,dy,spl,spval)\n\n! Evaluates a 2-dimensional cubic spline of function f(x,y)\n!\n! Input: nx, ny number of values in x and y\n! ix, iy pointer into the spline array spl\n! dx, dy distance from x(ix) and y(iy)\n! spl array with spline data\n! Output: spval evaluated function value\n\n USE neo_precision\n\n IMPLICIT NONE\n\n INTEGER, INTENT(in) :: nx, ny, ix, iy\n REAL(kind=dp), INTENT(in) :: dx, dy\n REAL(kind=dp), DIMENSION(4,4,nx,ny), INTENT(in) :: spl\n REAL(kind=dp), INTENT(out) :: spval\n\n REAL(kind=dp), DIMENSION(4) :: a\n INTEGER :: l\n\n DO l=1,4\n a(l) = spl(1,l,ix,iy) + dx*(spl(2,l,ix,iy) + &\n dx*(spl(3,l,ix,iy) + dx* spl(4,l,ix,iy)))\n END DO\n spval = a(1)+dy*(a(2)+dy*(a(3)+dy*a(4)))\n\n RETURN\nEND SUBROUTINE eva2d\n", "meta": {"hexsha": "0ddd00c7bc444c763719affba35bd676ff043e2c", "size": 1066, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "NEO/Sources/eva2d.f90", "max_stars_repo_name": "joseluisvelasco/STELLOPT", "max_stars_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2020-05-08T01:47:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T10:35:28.000Z", "max_issues_repo_path": "NEO/Sources/eva2d.f90", "max_issues_repo_name": "joseluisvelasco/STELLOPT", "max_issues_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 77, "max_issues_repo_issues_event_min_datetime": "2020-05-08T07:18:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:20:33.000Z", "max_forks_repo_path": "NEO/Sources/eva2d.f90", "max_forks_repo_name": "joseluisvelasco/STELLOPT", "max_forks_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-02-10T13:47:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T12:53:43.000Z", "avg_line_length": 33.3125, "max_line_length": 68, "alphanum_fraction": 0.4521575985, "num_tokens": 315, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543488, "lm_q2_score": 0.7310585727705126, "lm_q1q2_score": 0.6530614994325665}} {"text": " real function SSINHM (X)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nC>> 1998-10-29 SSINHM Krogh Moved external statement up for mangle.\nc>> 1994-10-20 SSINHM Krogh Changes to use M77CON\nc>> 1994-05-22 SSINHM WV Snyder JPL Make SP and DP alike using CHGTYP\nc>> 1993-07-21 SSINHM WV Snyder JPL Original code\nc\nc Compute SINH(X) - X.\nc\nc--S replaces \"?\": ?SINHM\n real X\n external R1MACH\n real CUT, R1MACH, E, ROUND, X2\n parameter (CUT = 0.25e0)\n real SP5, SP4, SP3, SP2, SP1, SQ1\n parameter ( SP5 = .255251817302048E-09)\n parameter ( SP4 = .723809046696880E-07)\n parameter ( SP3 = .109233297700241E-04)\n parameter ( SP2 = .954811583154274E-03)\n parameter ( SP1 = .452867078563929E-01)\n parameter ( SQ1 =-.471329214363072E-02*6.0E0)\n integer M, N\n save M, ROUND\n data M /-1/\nc\n if (m .lt. 0) then\n round = r1mach(4)\n if (round .lt. 5.0e-14) then\nc Compute appropriate value of M depending on round-off.\n m = 3\n e = cut/6.0e0\n10 if (e .gt. round) then\n m = m + 2\n e = e*cut*cut/(m*(m-1))\n go to 10\n end if\n end if\n end if\nc\n if (round .lt. 5.0e-14) then\n n = m\n x2 = x*x\nc We assume m > 1\n ssinhm = 1.0e0 + x2/(n*(n-1))\n20 if (n .gt. 5) then\n n = n - 2\n ssinhm = 1.0e0 + ssinhm*x2/(n*(n-1))\n go to 20\n end if\n ssinhm = x * x2 * ssinhm / 6.0e0\n return\n end if\nc\nc Use a rational approximation when ABS(X) is less than 1.65,\nc else use the Fortran intrinsic function.\nc\n if (x .lt. 1.65e0) then\n x2 = x*x\n ssinhm = ((((((sp5*x2+sp4)*x2+sp3)*x2+sp2)*x2+sp1)*x2+1.0e0)\n * *x2*x)/(sq1*x2+6.0e0)\n else\n ssinhm = sinh(x) - x\n end if\n return\n end\n", "meta": {"hexsha": "194abcbfb51204a9e24476d9e7e07d94c1ede7f6", "size": 2080, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/ssinhm.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/ssinhm.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/ssinhm.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": 30.5882352941, "max_line_length": 71, "alphanum_fraction": 0.5254807692, "num_tokens": 753, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.7310585727705127, "lm_q1q2_score": 0.6530614952795819}} {"text": "!\tObtain the frequency distribution of a weighted sum of responses.\r\n!\tThe weights are integers.\r\n!\tmaxnw is the array of minimum scores for items.\r\n!\tminw is the array of maximum scores for items.\r\n!\tnumcatobs is the number of observed item categories.\r\n!\tweight is the category weights.\r\n!\tprob is the vector of observed category probabilities.\r\n!\tdist is the probability distribution of the weighted sum.\r\n\r\nsubroutine distwtsum(maxw,minw,numcatobs,weight,prob,dist)\r\nimplicit none\r\ninteger,intent(in)::maxw(:),minw(:),numcatobs(:),weight(:)\r\nreal(kind=8),intent(in)::prob(:)\r\nreal(kind=8),intent(out)::dist(sum(minw):sum(maxw))\r\n\r\n!\tcat is a category.\r\n!\tcat1 is another category.\r\n!\tcounter provides the probability position.\r\n!\titem is an item.\r\n!\tnitems is the number of items.\r\n!\ttop is the maximum value up to item i\r\ninteger::cat,cat1,counter,item,nitems,top\r\n!\tdistnew is the probability distribution for the first i-1 items.\r\n!\tdistold is the probability distribution for the first i items.\r\n\r\nreal(kind=8)::distnew(0:sum(maxw)-sum(minw)),distold(0:sum(maxw)-sum(minw))\t\r\n\r\n\r\n\r\ndistnew=0.0_8\r\ndist=0.0_8\r\ndistnew(0)=1.0_8\r\n\r\ncounter=0\r\ntop=0\r\nnitems=size(numcatobs)\r\ndo item=1,nitems\r\n\t\r\n if(maxw(item)>minw(item)) then\r\n\t\tdistold(0:top)=distnew(0:top)\r\n\t\tdistnew(0:top+maxw(item)-minw(item))=0.0_8\r\n\t\tdo cat=0,top\r\n\t\t\tdo cat1=1,numcatobs(item)\r\n\t\t\t\tdistnew(cat+weight(counter+cat1)-minw(item))=distnew(cat+weight(counter+cat1)-minw(item))+distold(cat)*prob(counter+cat1)\r\n\t\t\tend do\r\n\t\tend do\r\n\t\ttop=top+maxw(item)-minw(item)\r\n\tend if\r\n\tcounter=counter+numcatobs(item)\r\nend do\r\ndist(sum(minw):sum(maxw))=distnew\r\n\r\nreturn\r\n\r\nend subroutine distwtsum\r\n\r\n\r\n", "meta": {"hexsha": "7ad746e78bc7a55883dffedeceacf4802e49cf16", "size": 1669, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Source/distwtsum.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/distwtsum.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/distwtsum.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": 28.775862069, "max_line_length": 126, "alphanum_fraction": 0.7171959257, "num_tokens": 491, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299570920387, "lm_q2_score": 0.7057850340255386, "lm_q1q2_score": 0.6530134567476522}} {"text": " FUNCTION julday(mm,id,iyyy)\r\n INTEGER julday,id,iyyy,mm,IGREG\r\n PARAMETER (IGREG=15+31*(10+12*1582))\r\n INTEGER ja,jm,jy\r\n jy=iyyy\r\n if (jy.eq.0) pause 'julday: there is no year zero'\r\n if (jy.lt.0) jy=jy+1\r\n if (mm.gt.2) then\r\n jm=mm+1\r\n else\r\n jy=jy-1\r\n jm=mm+13\r\n endif\r\n julday=int(365.25*jy)+int(30.6001*jm)+id+1720995\r\n if (id+31*(mm+12*iyyy).ge.IGREG) then\r\n ja=int(0.01*jy)\r\n julday=julday+2-ja+int(0.25*ja)\r\n endif\r\n return\r\n END\r\n", "meta": {"hexsha": "127adac32a52d86c35fba26ea944245459f717f0", "size": 550, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/julday.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/julday.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/julday.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": 26.1904761905, "max_line_length": 57, "alphanum_fraction": 0.5163636364, "num_tokens": 213, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299653388752, "lm_q2_score": 0.7057850216484838, "lm_q1q2_score": 0.653013451116524}} {"text": " FUNCTION SETSTVEL(D,SSG) \n REAL::SETSTVEL,VISC,GP,SSG,GPD,D,SQGPD,RD,WSET,TMP \nC CHANGE RECORD \nC \nC \nC ** NONCOHEASIVE SEDIMENT SETTLING AND SHIELDS CRITERIA \nC ** USING VAN RIJN'S EQUATIONS \nC \n VISC=1.E-6 \n GP=(SSG-1.)*9.82 \n GPD=GP*D \n SQGPD=SQRT(GPD) \n RD=SQGPD*D/VISC \nC \nC ** SETTLING VELOCITY \nC \n IF(D.LT.1.0E-4)THEN \n WSET=SQGPD*RD/18. \n ENDIF \n IF(D.GE.1.0E-4.AND.D.LT.1.E-3)THEN \n TMP=SQRT(1.+0.01*RD*RD)-1. \n WSET=10.0*SQGPD*TMP/RD \n ENDIF \n IF(D.GE.1.E-3)THEN \n WSET=1.1*SQGPD \n ENDIF \n SETSTVEL=WSET \n RETURN \n END \n\n", "meta": {"hexsha": "ca5ec34ef98847be4904263c38e29ef9bd3e3586", "size": 673, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "EFDC_src/SETSTVEL.f", "max_stars_repo_name": "T-Carlotto/SW2D-EFDC", "max_stars_repo_head_hexsha": "7b01a41a308cb79db569a0e6291fe40797f3ef28", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 32, "max_stars_repo_stars_event_min_datetime": "2018-03-31T22:19:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-14T01:35:23.000Z", "max_issues_repo_path": "EFDC_src/SETSTVEL.f", "max_issues_repo_name": "T-Carlotto/SW2D-EFDC", "max_issues_repo_head_hexsha": "7b01a41a308cb79db569a0e6291fe40797f3ef28", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-04-02T06:13:13.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-10T07:15:07.000Z", "max_forks_repo_path": "EFDC_src/SETSTVEL.f", "max_forks_repo_name": "T-Carlotto/SW2D-EFDC", "max_forks_repo_head_hexsha": "7b01a41a308cb79db569a0e6291fe40797f3ef28", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2018-06-27T02:55:23.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-09T07:51:23.000Z", "avg_line_length": 21.7096774194, "max_line_length": 59, "alphanum_fraction": 0.5200594354, "num_tokens": 283, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566342012360932, "lm_q2_score": 0.6825737279551494, "lm_q1q2_score": 0.6529733730271167}} {"text": " function W4(Z)\nc******************************************************************************\nc This routine calculates the complex voigt function using the\nc algorithm of Humlicek 1982.\nc******************************************************************************\n\n COMPLEX W4,Z, T, U\nc REAL*8 X, Y, S\nc z = cmplx(x, y)\n X=REAL(Z)\n Y=AIMAG(Z)\n T=CMPLX(Y,-X)\n S=ABS(X)+Y\n IF (S.LT.15.) GOTO 1\nC******** REGION 1\nc write (*,*) \"Region 1\"\nc write (*,*) Z, X, Y, T\n W4=T*.5641896/(.5+T*T)\n RETURN\n1 IF(S.LT.5.5)GOTO 2\nC******** REGION 2\nc write (*,*) \"Region 2\"\n U=T*T\n W4=T*(1.410474+U*.5641896)/(.75+U*(3.+U))\n RETURN\n2 IF(Y.LT..195*ABS(X)-.176)GOTO 3\nC******** REGION 3\nc write (*,*) \"Region 3\"\n W4=(16.4955+T*(20.20933+T*(11.96482+T*(3.778987+T*.5642236))))/\n /(16.4955+T*(38.82363+T*(39.27121+T*(21.69274+T*(6.699398+T)))))\n RETURN\nC******** REGION 4\n3 U=T*T\nc write (*,*) \"Region 4\"\n W4=CEXP(U)-T*(36183.31-U*(3321.9905-U*(1540.787-U*(219.0313-U*\n *(35.76683-U*(1.320522-U*.56419))))))/(32066.6-U*(24322.84-U*\n *(9022.228-U*(2186.181-U*(364.2191-U*(61.57037-U*(1.841439-U)))))))\n \n RETURN\n\n END\n\n", "meta": {"hexsha": "ae55358ad616311120ad80299c711ef3c9bba037", "size": 1264, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "MoogSource/ComplexVoigt.f", "max_stars_repo_name": "soylentdeen/MoogPy", "max_stars_repo_head_hexsha": "9485a7e302ef4d4339013f27672d1d5e7059a41f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2015-08-21T17:18:15.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-03T15:55:35.000Z", "max_issues_repo_path": "MoogSource/ComplexVoigt.f", "max_issues_repo_name": "soylentdeen/MoogPy", "max_issues_repo_head_hexsha": "9485a7e302ef4d4339013f27672d1d5e7059a41f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MoogSource/ComplexVoigt.f", "max_forks_repo_name": "soylentdeen/MoogPy", "max_forks_repo_head_hexsha": "9485a7e302ef4d4339013f27672d1d5e7059a41f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2016-03-28T09:39:44.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-20T07:47:39.000Z", "avg_line_length": 29.3953488372, "max_line_length": 79, "alphanum_fraction": 0.4375, "num_tokens": 474, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403999037784, "lm_q2_score": 0.7025300698514778, "lm_q1q2_score": 0.6529598290671869}} {"text": "!----------------------------------------------------------------------------- best with 100 columns\n\n!> edge-based finite element discretizations\nmodule modEdgeFEM\n public\n \n integer,parameter,private::DIMS=3\n \ncontains\n \n !> find cell-average curl of vp\n subroutine findCellCurl(grid,vp,rst)\n use modPolyEdgeFeGrid\n use modPolyGrid\n use modSMQ\n class(polyEdgeFeGrid),intent(inout)::grid !< the grid\n double precision,intent(in)::vp(grid%nEdge) !< vector potential\n double precision,allocatable,intent(inout)::rst(:,:) !< curl of vp at cells\n double precision::gradNa(DIMS),gradNb(DIMS),curlNj(DIMS)\n \n call grid%up()\n if(.not.allocated(rst))then\n allocate(rst(DIMS,grid%nC))\n end if\n rst(:,:)=0d0\n do i=1,grid%nC\n select case(grid%sE(i))\n case(TET)\n do j=1,TET_N_EDGE\n l=1 ! only 1 quadrature point for TET\n gradNa=matmul(grid%invJ(:,:,l,i),TET_GRAD_QP(:,TET_NI_EDGE(1,j),l))\n gradNb=matmul(grid%invJ(:,:,l,i),TET_GRAD_QP(:,TET_NI_EDGE(2,j),l))\n curlNj(1)=2*(gradNa(2)*gradNb(3)-gradNa(3)*gradNb(2))\n curlNj(2)=2*(gradNa(3)*gradNb(1)-gradNa(1)*gradNb(3))\n curlNj(3)=2*(gradNa(1)*gradNb(2)-gradNa(2)*gradNb(1))\n curlNj=curlNj*merge(1,-1,grid%sameDir(j,i))\n rst(:,i)=rst(:,i)+curlNj*vp(grid%iEdgeE(j,i))\n end do\n case default\n end select\n end do\n end subroutine\n \n !> find curl of curl operator\n !> NOTE: A must be pre-initialized to contain the temporary CSR matrix with duplications\n subroutine findCurlCurl(grid,A,isInactive)\n use modPolyEdgeFeGrid\n use modPolyGrid\n use modSMQ\n use modSparse\n class(polyEdgeFeGrid),intent(inout)::grid !< the grid\n class(linEq),intent(inout)::A !< the discretized linear system\n logical,intent(in),optional::isInactive(grid%nEdge) !< whether inactive (gauged and Dirichlet)\n integer::nnz,maxNNZ\n integer,allocatable::iA(:),jA(:)\n double precision,allocatable::vA(:)\n double precision::curlNj(DIMS),curlNk(DIMS),gradNa(DIMS),gradNb(DIMS)\n \n call grid%up()\n maxNNZ=size(grid%iEdgeE,1)**2*grid%nC\n allocate(iA(maxNNZ)) ! COO temporary matrix\n allocate(jA(maxNNZ))\n allocate(vA(maxNNZ))\n nnz=0\n do i=1,grid%nC\n select case(grid%sE(i))\n case(TET)\n do j=1,TET_N_EDGE\n if(present(isInactive))then\n if(isInactive(grid%iEdgeE(j,i)))then\n cycle\n end if\n end if\n do k=1,TET_N_EDGE\n nnz=nnz+1\n iA(nnz)=grid%iEdgeE(j,i)\n jA(nnz)=grid%iEdgeE(k,i)\n vA(nnz)=0d0\n do l=1,size(TET_QW)\n gradNa=matmul(grid%invJ(:,:,l,i),TET_GRAD_QP(:,TET_NI_EDGE(1,j),l))\n gradNb=matmul(grid%invJ(:,:,l,i),TET_GRAD_QP(:,TET_NI_EDGE(2,j),l))\n curlNj(1)=2*(gradNa(2)*gradNb(3)-gradNa(3)*gradNb(2))\n curlNj(2)=2*(gradNa(3)*gradNb(1)-gradNa(1)*gradNb(3))\n curlNj(3)=2*(gradNa(1)*gradNb(2)-gradNa(2)*gradNb(1))\n curlNj=curlNj*merge(1,-1,grid%sameDir(j,i))\n gradNa=matmul(grid%invJ(:,:,l,i),TET_GRAD_QP(:,TET_NI_EDGE(1,k),l))\n gradNb=matmul(grid%invJ(:,:,l,i),TET_GRAD_QP(:,TET_NI_EDGE(2,k),l))\n curlNk(1)=2*(gradNa(2)*gradNb(3)-gradNa(3)*gradNb(2))\n curlNk(2)=2*(gradNa(3)*gradNb(1)-gradNa(1)*gradNb(3))\n curlNk(3)=2*(gradNa(1)*gradNb(2)-gradNa(2)*gradNb(1))\n curlNk=curlNk*merge(1,-1,grid%sameDir(k,i))\n vA(nnz)=vA(nnz)+dot_product(curlNj,curlNk)*grid%detJ(l,i)*TET_QW(l)\n end do\n end do\n end do\n case default\n end select\n end do\n if(present(isInactive))then\n do i=1,grid%nEdge\n if(isInactive(i))then\n nnz=nnz+1\n iA(nnz)=i\n jA(nnz)=i\n vA(nnz)=1d0\n end if\n end do\n end if\n call A%setCOO(iA,jA,vA,nnz,job=CSR_CLEAN_SORT)\n deallocate(iA,jA,vA)\n end subroutine\n \n !> find volumetric source discretization of cell vector v\n subroutine findVolVectSrc(grid,v,rst)\n use modPolyEdgeFeGrid\n use modPolyGrid\n use modSMQ\n class(polyEdgeFeGrid),intent(inout)::grid !< the grid\n double precision,intent(in)::v(DIMS,grid%nC) !< vector in cell (source density)\n double precision,allocatable,intent(inout)::rst(:) !< source discretization on edge\n double precision::Na,Nb,gradNa(DIMS),gradNb(DIMS),Ne(DIMS)\n \n call grid%up()\n if(.not.allocated(rst))then\n allocate(rst(grid%nEdge))\n end if\n rst(:)=0d0\n do i=1,grid%nC\n select case(grid%sE(i))\n case(TET)\n do j=1,TET_N_EDGE\n do l=1,size(TET_QW)\n gradNa=matmul(grid%invJ(:,:,l,i),TET_GRAD_QP(:,TET_NI_EDGE(1,j),l))\n gradNb=matmul(grid%invJ(:,:,l,i),TET_GRAD_QP(:,TET_NI_EDGE(2,j),l))\n Na=TET_SHAPE_QP(TET_NI_EDGE(1,j),l)\n Nb=TET_SHAPE_QP(TET_NI_EDGE(2,j),l)\n Ne=(Na*gradNb-Nb*gradNa)*merge(1,-1,grid%sameDir(j,i))\n rst(grid%iEdgeE(j,i))=rst(grid%iEdgeE(j,i))&\n & +dot_product(Ne,v(:,i))*grid%detJ(l,i)*TET_QW(l)\n end do\n end do\n case default\n end select\n end do\n end subroutine\n \nend module\n", "meta": {"hexsha": "c4c1e2edc78f765117654e8a8fb373b0688f0356", "size": 5257, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/libfosolvers/FEM/edgeFEM.f90", "max_stars_repo_name": "mianzhi/fosolvers", "max_stars_repo_head_hexsha": "be4877a9cccd7bf6b97d4e01c58e10634684415d", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2015-08-05T14:10:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-26T10:50:06.000Z", "max_issues_repo_path": "src/libfosolvers/FEM/edgeFEM.f90", "max_issues_repo_name": "mianzhi/fosolvers", "max_issues_repo_head_hexsha": "be4877a9cccd7bf6b97d4e01c58e10634684415d", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2019-11-24T15:46:54.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-30T13:30:29.000Z", "max_forks_repo_path": "src/libfosolvers/FEM/edgeFEM.f90", "max_forks_repo_name": "mianzhi/fosolvers", "max_forks_repo_head_hexsha": "be4877a9cccd7bf6b97d4e01c58e10634684415d", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-08-23T03:10:35.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-01T05:17:19.000Z", "avg_line_length": 35.5202702703, "max_line_length": 100, "alphanum_fraction": 0.588929047, "num_tokens": 1768, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404018582427, "lm_q2_score": 0.7025300573952052, "lm_q1q2_score": 0.6529598188628939}} {"text": "use plantfem\nimplicit none\n\ntype(IO_) :: f\ntype(Math_) :: math\ntype(Random_) :: random\ncomplex(complex64),allocatable :: t(:), Ft(:),Fw(:),Fw_bar(:),Ft_(:),omega(:)\nreal(real64) :: domega, n\ninteger(int32) :: i\n\n! Time\nt = linspace([0.0d0, 10.0d0],1024)\n\n! Frequency\nomega = linspace([0.0d0, 1024.0d0/10.0d0],1024)\n\nFt = zeros(1024)\n!Ft(:) = 1.0d0/2.0d0/Math%PI*domega*(sin( (2.0d0*n + 1)/2.0d0*domega*t ) )/( sin( 1.0d0/2.0d0*domega*t ))\ndo i=1,size(Ft)\n Ft(i) = random%gauss(mu=0.0d0,sigma=0.50d0)\nenddo\nFt(:) = Ft(:)+5.0d0*sin(2.0d0*Math%PI*t) \n\nFw = FFT(Ft)\n\nFw( 516-400:516+400 )=0.0d0\n\nFt_ = IFFT(Fw)\n\nFw_bar = Fw\nFw_bar = Fw*Fw\n\ncall f%open(\"Fw.txt\",\"w\")\n!call f%write(real(t), real(Fw) )\ncall f%write(real(omega(1:size(t)/2 ) ), real(Fw(1:size(t)/2) ) )\ncall f%close()\n\ncall f%open(\"Ft.txt\",\"w\")\n!call f%write(real(t), real(Fw) )\ncall f%write(real(t), real(Ft) )\ncall f%close()\n\ncall f%open(\"Ft_.txt\",\"w\")\n!call f%write(real(t), real(Fw) )\ncall f%write(real(t), real(Ft_) )\ncall f%close()\n\ncall f%plot(\"Ft.txt\",\"w l\")\ncall f%plot(\"Fw.txt\",\"w l\")\ncall f%plot(\"Ft_.txt\",\"w l\")\nend", "meta": {"hexsha": "58092105b6d6a25c519e916ab2a6bc206bbd66fe", "size": 1090, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/std/FFTandIFFT.f90", "max_stars_repo_name": "kazulagi/plantFEM", "max_stars_repo_head_hexsha": "20bf2df8202d41aa5dc25d1cc820385dabbc604f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2020-06-21T08:21:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-13T04:28:30.000Z", "max_issues_repo_path": "Tutorial/std/FFTandIFFT.f90", "max_issues_repo_name": "kazulagi/plantFEM_binary", "max_issues_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-05-08T05:20:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T05:39:29.000Z", "max_forks_repo_path": "Tutorial/std/FFTandIFFT.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": 21.3725490196, "max_line_length": 106, "alphanum_fraction": 0.6128440367, "num_tokens": 493, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403959948494, "lm_q2_score": 0.702530051167069, "lm_q1q2_score": 0.6529598089550024}} {"text": "module constants \nimplicit none \n\n real, parameter :: pi = 3.1415926536 \n real, parameter :: e = 2.7182818285 \n \ncontains \n subroutine show_consts() \n print*, \"Pi = \", pi \n print*, \"e = \", e \n end subroutine show_consts \n \nend module constants \n", "meta": {"hexsha": "1ef75f4bf934392c04f8dbab087ee438c05679c7", "size": 297, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "cons.f90", "max_stars_repo_name": "akkiturb/Ilkay-s-Fortran-Class", "max_stars_repo_head_hexsha": "0600640574354052a5a7d87bad520b8a03650d0e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-12-18T19:31:01.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-18T19:31:01.000Z", "max_issues_repo_path": "cons.f90", "max_issues_repo_name": "akkiturb/Scientific-computing-in-Fortran", "max_issues_repo_head_hexsha": "0600640574354052a5a7d87bad520b8a03650d0e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cons.f90", "max_forks_repo_name": "akkiturb/Scientific-computing-in-Fortran", "max_forks_repo_head_hexsha": "0600640574354052a5a7d87bad520b8a03650d0e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-02-04T19:45:56.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-10T14:22:05.000Z", "avg_line_length": 21.2142857143, "max_line_length": 41, "alphanum_fraction": 0.5555555556, "num_tokens": 75, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.810478926981208, "lm_q2_score": 0.8056321796478255, "lm_q1q2_score": 0.6529479045025015}} {"text": "module sum\n contains\n\tsubroutine fortransum(input_array, tsize, result_out) bind(C,name='fortransum')\n\n\t\tinteger :: tsize\n\t\tinteger :: result_out\n\t\tinteger, dimension(tsize) :: input_array\n\t\tresult_out = 0\n\t\tdo i = 1,tsize\n\t\t\tresult_out = result_out + input_array(i)\n\t\tend do\n\tend subroutine fortransum\n\nend module sum\n\n! program sum\n! \tinteger, dimension(size) :: a\n\n! \tinteger :: total\n\n! \tdo i = 1, size\n! \t\ta(i) = i-1\n! \tend do\n! \ttotal = 0\n! \tdo i = 1, size\n! \t\ttotal = total + a(i)\n! \tend do\n! \ta = total\n\n! \tprint *, \"values: \", size\n! \tprint *, \"total: \", total\n! end program sum\n", "meta": {"hexsha": "e7e3219b2d553e046ccea252a060d8e866d7b21d", "size": 588, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "evaluation/performance/sum.f95", "max_stars_repo_name": "wimvanderbauwhede/AutoParallel-Fortran", "max_stars_repo_head_hexsha": "87a322d1936e6cc92d83235b9523ef86b6d4b26b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-07-29T12:04:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-29T12:04:10.000Z", "max_issues_repo_path": "evaluation/performance/sum.f95", "max_issues_repo_name": "wimvanderbauwhede/AutoParallel-Fortran", "max_issues_repo_head_hexsha": "87a322d1936e6cc92d83235b9523ef86b6d4b26b", "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": "evaluation/performance/sum.f95", "max_forks_repo_name": "wimvanderbauwhede/AutoParallel-Fortran", "max_forks_repo_head_hexsha": "87a322d1936e6cc92d83235b9523ef86b6d4b26b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-08-13T09:39:36.000Z", "max_forks_repo_forks_event_max_datetime": "2018-08-13T09:39:36.000Z", "avg_line_length": 17.8181818182, "max_line_length": 80, "alphanum_fraction": 0.637755102, "num_tokens": 203, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104788995148791, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.6529478899392909}} {"text": "! Related to PR 15326. Try calling string functions whose lengths involve\n! some sort of array calculation.\n! { dg-do run }\npure elemental function double (x)\n integer, intent (in) :: x\n integer :: double\n double = x * 2\nend function double\n\nprogram main\n implicit none\n\n interface\n pure elemental function double (x)\n integer, intent (in) :: x\n integer :: double\n end function double\n end interface\n\n integer, dimension (100:104), target :: a\n integer, dimension (:), pointer :: ap\n integer :: i, lower\n\n a = (/ (i + 5, i = 0, 4) /)\n ap => a\n lower = 11\n\n call test (f1 (a), 35)\n call test (f1 (ap), 35)\n call test (f1 ((/ 5, 10, 50 /)), 65)\n call test (f1 (a (101:103)), 21)\n\n call test (f2 (a), 115)\n call test (f2 (ap), 115)\n call test (f2 ((/ 5, 10, 50 /)), 119)\n call test (f2 (a (101:103)), 116)\n\n call test (f3 (a), 60)\n call test (f3 (ap), 60)\n call test (f3 ((/ 5, 10, 50 /)), 120)\n call test (f3 (a (101:103)), 30)\n\n call test (f4 (a, 13, 1), 21)\n call test (f4 (ap, 13, 2), 14)\n call test (f4 ((/ 5, 10, 50 /), 12, 1), 60)\n call test (f4 (a (101:103), 12, 1), 15)\ncontains\n function f1 (array)\n integer, dimension (10:) :: array\n character (len = sum (array)) :: f1\n f1 = ''\n end function f1\n\n function f2 (array)\n integer, dimension (10:) :: array\n character (len = array (11) + a (104) + 100) :: f2\n f2 = ''\n end function f2\n\n function f3 (array)\n integer, dimension (:) :: array\n character (len = sum (double (array (2:)))) :: f3\n f3 = ''\n end function f3\n\n function f4 (array, upper, stride)\n integer, dimension (10:) :: array\n integer :: upper, stride\n character (len = sum (array (lower:upper:stride))) :: f4\n f4 = ''\n end function f4\n\n subroutine test (string, length)\n character (len = *) :: string\n integer, intent (in) :: length\n if (len (string) .ne. length) call abort\n end subroutine test\nend program main\n", "meta": {"hexsha": "8b9aa92477f92a9022e6930adddc5f1eb7cbc434", "size": 1934, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/char_result_3.f90", "max_stars_repo_name": "maurizioabba/rose", "max_stars_repo_head_hexsha": "7597292cf14da292bdb9a4ef573001b6c5b9b6c0", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/char_result_3.f90", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/char_result_3.f90", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 24.4810126582, "max_line_length": 74, "alphanum_fraction": 0.5858324716, "num_tokens": 682, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104789086703225, "lm_q2_score": 0.8056321796478255, "lm_q1q2_score": 0.6529478897506628}} {"text": "module matrix_utils\n\n use iso_fortran_env, only : dp => REAL64\n\ncontains\n \n !===================================================================!\n ! Setup Toepliz matrix with supplied columns\n !===================================================================!\n\n subroutine toepliz(col, A)\n\n real(dp), allocatable :: A(:,:)\n real(dp) :: col(:)\n integer :: m, i, j\n\n m = size(A, 1)\n do j = 1, m\n do i = 1, m\n if (i.eq.j) then\n A(i,j) = col(1)\n else if (i+1.eq.j .or.i-1.eq.j) then\n A(i,j) = col(2)\n A(j,i) = col(2)\n else if (i+2.eq.j .or.i-2.eq.j) then\n A(i,j) = col(3)\n A(j,i) = col(3)\n else if (i+3.eq.j .or.i-3.eq.j) then\n A(i,j) = col(4)\n A(j,i) = col(4)\n else if (i+4.eq.j .or.i-4.eq.j) then\n A(i,j) = col(5)\n A(j,i) = col(5)\n end if\n end do\n end do\n\n end subroutine toepliz\n \n subroutine print(matrix)\n\n real(dp), intent(in) :: matrix(:,:)\n integer :: i, j, m, n\n\n m = size(matrix, 1)\n n = size(matrix, 2)\n\n do i = 1, m\n write(*,'(100g15.5)') ( matrix(i,j), j=1,n )\n end do\n end subroutine print\n\nend module matrix_utils\n", "meta": {"hexsha": "dad2d17ee0a42ba4f7298f7852acb09c72941df5", "size": 1253, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/matrix_utils.f90", "max_stars_repo_name": "komahanb/math6644-iterative-methods", "max_stars_repo_head_hexsha": "59dfd0fd8bbcb16d5f5b6d96d2565f87541803c9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-03-19T16:36:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-14T21:29:38.000Z", "max_issues_repo_path": "src/matrix_utils.f90", "max_issues_repo_name": "komahanb/math6644-iterative-methods", "max_issues_repo_head_hexsha": "59dfd0fd8bbcb16d5f5b6d96d2565f87541803c9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/matrix_utils.f90", "max_forks_repo_name": "komahanb/math6644-iterative-methods", "max_forks_repo_head_hexsha": "59dfd0fd8bbcb16d5f5b6d96d2565f87541803c9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-23T02:14:36.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-23T02:14:36.000Z", "avg_line_length": 23.2037037037, "max_line_length": 71, "alphanum_fraction": 0.4086193136, "num_tokens": 391, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321796478254, "lm_q2_score": 0.8104789063814616, "lm_q1q2_score": 0.6529478879066827}} {"text": "program main\n\n implicit none\n\n real, allocatable, dimension(:) :: x\n integer :: rnd_nseed, n\n integer, allocatable, dimension(:) :: rnd_seed\n\n print *, 'Enter number of elements'\n read *, n\n\n allocate (x(n))\n\n call random_seed(size=rnd_nseed)\n print *, 'Random Seed (n) : ', rnd_nseed\n allocate(rnd_seed(rnd_nseed))\n call random_seed(get=rnd_seed)\n print *, 'Random Seed (array): ', rnd_seed \n\n call random_number(x)\n\n print *, 'Number of elements :', size(x)\n print *, 'Sum of values in array : ', sum(x) \n print *, 'Average : ', sum(x)/size(x)\n\n deallocate (x)\n\n stop\n\nend program\n", "meta": {"hexsha": "a8820c8e9dcfc32b087c767175c0758e25c9d618", "size": 622, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "files/.fortran/exercise_10.f90", "max_stars_repo_name": "WVUHPC/Modern-Fortran", "max_stars_repo_head_hexsha": "97c4db834d4e6ca43802318e4dc63ce4faa641aa", "max_stars_repo_licenses": ["CC-BY-4.0"], "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": "files/.fortran/exercise_10.f90", "max_issues_repo_name": "WVUHPC/Modern-Fortran", "max_issues_repo_head_hexsha": "97c4db834d4e6ca43802318e4dc63ce4faa641aa", "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": "files/.fortran/exercise_10.f90", "max_forks_repo_name": "WVUHPC/Modern-Fortran", "max_forks_repo_head_hexsha": "97c4db834d4e6ca43802318e4dc63ce4faa641aa", "max_forks_repo_licenses": ["CC-BY-4.0"], "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": 20.064516129, "max_line_length": 49, "alphanum_fraction": 0.6270096463, "num_tokens": 177, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321703143954, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.6529478766541748}} {"text": "! Check we do the right thing with extreme values.\n! From PR12704\nprogram intrinsic_mmloc_3\n integer, dimension(2) :: d\n integer, dimension(2,2) :: a\n logical, dimension(2) :: k\n logical, dimension(2,2) :: l\n\n k = .true.\n l = .true.\n\n d = -huge (d)\n if (maxloc (d, 1) .ne. 1) call abort ()\n\n d = huge (d)\n if (minloc (d, 1) .ne. 1) call abort ()\n\n d = -huge (d)\n if (maxloc (d, 1, k) .ne. 1) call abort ()\n\n d = huge (d)\n if (minloc (d, 1, k) .ne. 1) call abort ()\n\n a = -huge (a)\n d = maxloc (a)\n if (any (d .ne. 1)) call abort ()\n\n a = huge (a)\n d = minloc (a)\n if (any (d .ne. 1)) call abort ()\n\n a = -huge (a)\n d = maxloc (a, l)\n if (any (d .ne. 1)) call abort ()\n\n a = huge (a)\n d = minloc (a, l)\n if (any (d .ne. 1)) call abort ()\n\nend program\n", "meta": {"hexsha": "078a08d70b44e4243eb2aaf9fac81ebe247ffcef", "size": 776, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_mmloc_3.f90", "max_stars_repo_name": "best08618/asylo", "max_stars_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-05-02T17:34:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-17T10:15:18.000Z", "max_issues_repo_path": "llvm-gcc-4.2-2.9/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_mmloc_3.f90", "max_issues_repo_name": "vidkidz/crossbridge", "max_issues_repo_head_hexsha": "ba0bf94aee0ce6cf7eb5be882382e52bc57ba396", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "llvm-gcc-4.2-2.9/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_mmloc_3.f90", "max_forks_repo_name": "vidkidz/crossbridge", "max_forks_repo_head_hexsha": "ba0bf94aee0ce6cf7eb5be882382e52bc57ba396", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-27T00:22:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-01T09:41:02.000Z", "avg_line_length": 18.9268292683, "max_line_length": 50, "alphanum_fraction": 0.5309278351, "num_tokens": 323, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84594244507642, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6529351802180172}} {"text": "!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% main.f %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n \r\n! Code converted using TO_F90 by Alan Miller\r\n! Date: 2002-11-09 Time: 22:01:17\r\n\r\nPROGRAM Test_uobyqa\r\n! The Chebyquad test problem (Fletcher, 1965) for N = 2,4,6,8.\r\n\r\nUSE Powell_Optimize\r\nIMPLICIT NONE\r\nINTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(12, 60)\r\n\r\nREAL (dp) :: rhobeg, rhoend, x(10)\r\nINTEGER :: i, iprint, maxfun, n\r\n\r\niprint=2\r\nmaxfun=5000\r\nrhoend=1.0D-8\r\nDO n=2,8,2\r\n DO i=1,n\r\n x(i)=REAL(i)/REAL(n+1)\r\n END DO\r\n rhobeg=0.2D0*x(1)\r\n WRITE(*, 20) n\r\n 20 FORMAT (//t6, '******************'/ t6, 'Results with N =', i2 / t6, '******************')\r\n CALL uobyqa (n, x, rhobeg, rhoend, iprint, maxfun)\r\nEND DO\r\nSTOP\r\nEND PROGRAM Test_uobyqa\r\n\r\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% calfun.f %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n \r\nSUBROUTINE calfun(n, x, f)\r\n\r\nIMPLICIT NONE\r\nINTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(12, 60)\r\n\r\nINTEGER, INTENT(IN) :: n\r\nREAL (dp), INTENT(IN) :: x(:)\r\nREAL (dp), INTENT(OUT) :: f\r\n\r\n! COMMON a(40,20), b(40,20), e(41)\r\nREAL (dp) :: sum, y(10,10)\r\nINTEGER :: i, iw, j, np\r\n\r\nDO j = 1, n\r\n y(1,j) = 1.0D0\r\n y(2,j) = 2.0D0 * x(j) - 1.0D0\r\nEND DO\r\nDO i = 2, n\r\n DO j = 1, n\r\n y(i+1,j) = 2.0D0 * y(2,j) * y(i,j) - y(i-1,j)\r\n END DO\r\nEND DO\r\nf = 0.0D0\r\nnp = n + 1\r\niw = 1\r\nDO i = 1, np\r\n sum = 0.0D0\r\n DO j = 1, n\r\n sum = sum + y(i,j)\r\n END DO\r\n sum = sum / REAL(n)\r\n IF (iw > 0) sum = sum + 1.0_dp / REAL(i*i - 2*i)\r\n iw = -iw\r\n f = f + sum * sum\r\nEND DO\r\nRETURN\r\nEND SUBROUTINE calfun\r\n", "meta": {"hexsha": "468e41d4c72c655a3ac1caadfc3f9ed1cc55b08f", "size": 1558, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/t_uobyqa.f90", "max_stars_repo_name": "agforero/FTFramework", "max_stars_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-08-19T21:43:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-20T02:57:25.000Z", "max_issues_repo_path": "source/amil/t_uobyqa.f90", "max_issues_repo_name": "agforero/fortran-testing-framework", "max_issues_repo_head_hexsha": "6caf0bc7bae8dc54a62da62df37e852625f0427d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-08-07T21:17:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-09T02:18:07.000Z", "max_forks_repo_path": "source/amil/t_uobyqa.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": 22.2571428571, "max_line_length": 96, "alphanum_fraction": 0.4916559692, "num_tokens": 636, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424295406087, "lm_q2_score": 0.7718434978390747, "lm_q1q2_score": 0.6529351637871084}} {"text": "subroutine press_calc(m,n,o,p,p0,a,b,orog,ps,temp_ml,press_ml)\nimplicit none\ninteger :: m,n,o,p\ninteger :: x,y,s,t\ndouble precision :: ps(m,n,p),a(o),b(o),p0\ndouble precision ::temp_ml(m,n,o,p),orog(m,n)\ndouble precision, intent(out) :: press_ml(m,n,o,p)\nreal ::PlanetGrav = 9.80665\nreal ::PlanetRD = 287.058\nreal ::height_ml,con \ncon= PlanetGrav/PlanetRD\ndo t=1,p \n do s=1,o\n do x=1,m\n do y=1,n\n height_ml = a(s) + b(s) * orog (x,y)\n press_ml(x,y,s,t) = ps(m,n,p) * exp(-1*(con/temp_ml(x,y,s,t)*(height_ml&\n - orog(x,y))))\n end do \n end do \n end do\t\nend do \nend subroutine press_calc\n", "meta": {"hexsha": "f55f9016744f10f13530751bb5d54dce876a40d2", "size": 604, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "wind_afterburner/press_calc_HadGEM2-ES.f90", "max_stars_repo_name": "ahmathlete/Vintp_afterburner", "max_stars_repo_head_hexsha": "68a71b18a01086ebd3f47d8b9205dc1add332c9c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "wind_afterburner/press_calc_HadGEM2-ES.f90", "max_issues_repo_name": "ahmathlete/Vintp_afterburner", "max_issues_repo_head_hexsha": "68a71b18a01086ebd3f47d8b9205dc1add332c9c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "wind_afterburner/press_calc_HadGEM2-ES.f90", "max_forks_repo_name": "ahmathlete/Vintp_afterburner", "max_forks_repo_head_hexsha": "68a71b18a01086ebd3f47d8b9205dc1add332c9c", "max_forks_repo_licenses": ["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.1666666667, "max_line_length": 76, "alphanum_fraction": 0.6357615894, "num_tokens": 226, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632316144274, "lm_q2_score": 0.6859494485880927, "lm_q1q2_score": 0.6529300588571965}} {"text": " subroutine fppocu(idim,k,a,b,ib,db,nb,ie,de,ne,cp,np)\nc subroutine fppocu finds a idim-dimensional polynomial curve p(u) =\nc (p1(u),p2(u),...,pidim(u)) of degree k, satisfying certain derivative\nc constraints at the end points a and b, i.e.\nc (l)\nc if ib > 0 : pj (a) = db(idim*l+j), l=0,1,...,ib-1\nc (l)\nc if ie > 0 : pj (b) = de(idim*l+j), l=0,1,...,ie-1\nc\nc the polynomial curve is returned in its b-spline representation\nc ( coefficients cp(j), j=1,2,...,np )\nc ..\nc ..scalar arguments..\n integer idim,k,ib,nb,ie,ne,np\n real*8 a,b\nc ..array arguments..\n real*8 db(nb),de(ne),cp(np)\nc ..local scalars..\n real*8 ab,aki\n integer i,id,j,jj,l,ll,k1,k2\nc ..local array..\n real*8 work(6,6)\nc ..\n k1 = k+1\n k2 = 2*k1\n ab = b-a\n do 110 id=1,idim\n do 10 j=1,k1\n work(j,1) = 0.\n 10 continue\n if(ib.eq.0) go to 50\n l = id\n do 20 i=1,ib\n work(1,i) = db(l)\n l = l+idim\n 20 continue\n if(ib.eq.1) go to 50\n ll = ib\n do 40 j=2,ib\n ll = ll-1\n do 30 i=1,ll\n aki = k1-i\n work(j,i) = ab*work(j-1,i+1)/aki + work(j-1,i)\n 30 continue\n 40 continue\n 50 if(ie.eq.0) go to 90\n l = id\n j = k1\n do 60 i=1,ie\n work(j,i) = de(l)\n l = l+idim\n j = j-1\n 60 continue\n if(ie.eq.1) go to 90\n ll = ie\n do 80 jj=2,ie\n ll = ll-1\n j = k1+1-jj\n do 70 i=1,ll\n aki = k1-i\n work(j,i) = work(j+1,i) - ab*work(j,i+1)/aki\n j = j-1\n 70 continue\n 80 continue\n 90 l = (id-1)*k2\n do 100 j=1,k1\n l = l+1\n cp(l) = work(j,1)\n 100 continue\n 110 continue\n return\n end\n", "meta": {"hexsha": "740addb5f671507b1d9b73fc5db84487f2cd4413", "size": 1852, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "scipy/interpolate/fitpack/fppocu.f", "max_stars_repo_name": "Ennosigaeon/scipy", "max_stars_repo_head_hexsha": "2d872f7cf2098031b9be863ec25e366a550b229c", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 9095, "max_stars_repo_stars_event_min_datetime": "2015-01-02T18:24:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T20:35:31.000Z", "max_issues_repo_path": "scipy/interpolate/fitpack/fppocu.f", "max_issues_repo_name": "Ennosigaeon/scipy", "max_issues_repo_head_hexsha": "2d872f7cf2098031b9be863ec25e366a550b229c", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 11500, "max_issues_repo_issues_event_min_datetime": "2015-01-01T01:15:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T23:07:35.000Z", "max_forks_repo_path": "scipy/interpolate/fitpack/fppocu.f", "max_forks_repo_name": "Ennosigaeon/scipy", "max_forks_repo_head_hexsha": "2d872f7cf2098031b9be863ec25e366a550b229c", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5838, "max_forks_repo_forks_event_min_datetime": "2015-01-05T11:56:42.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T23:21:19.000Z", "avg_line_length": 25.3698630137, "max_line_length": 72, "alphanum_fraction": 0.4600431965, "num_tokens": 711, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818865, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6529277347576249}} {"text": "use FEMDomainClass\nimplicit None\n\ntype(FEMDomain_) :: Cube\ntype(IO_) :: f\nreal(real64) :: a(3)=0.0d0 ! acceleration\nreal(real64),allocatable :: some_global_vector(:)\n\ncall cube%create(meshtype=\"Cube3D\")\ncall cube%resize(x=10.0d0)\ncall cube%resize(y=10.0d0)\ncall cube%resize(z=10.0d0)\n\n! Mass-Matrix for an Element\ncall f%open(\"MassMatrix.txt\",'w')\n! ElementID=1, Degree of freedom in a node is 3\n! 3 unknowns are defined in a node.\ncall f%write(cube%MassMatrix(ElementID=1, DOF=3))\ncall f%close()\n\n! Mass-Vector for an Element\n! For example, body force N with 3-D space\ncall f%open(\"MassVector.txt\",'w')\na(3) = -9.80d0\ncall f%write(cube%MassVector(ElementID=1, DOF=3, Density=1.0d0,Accel=a) )\ncall f%close()\n\n! Stiffness matrix for an Element\ncall f%open(\"StiffnessMatrix.txt\",'w')\ncall f%write(cube%StiffnessMatrix(ElementID=1, E=1000.0d0, v=0.30d0))\ncall f%close()\n\n! B-matrix (Strain-displacement consistency) for an Element\ncall f%open(\"BMatrix.txt\",'w')\ncall f%write(cube%BMatrix(ElementID=1))\ncall f%close()\n\n! Elastic-Coefficient matrix for an Element\ncall f%open(\"DMatrix.txt\",'w')\ncall f%write(cube%DMatrix(E=1000.0d0, v=0.30d0))\ncall f%close()\n\n! Diffusion matrix for an Element\ncall f%open(\"DiffusionMatrix.txt\",'w')\ncall f%write(cube%DiffusionMatrix(ElementID=1,D=1.0d0))\ncall f%close()\n\n! create sequential vector (0, 1, 2, ...)\nsome_global_vector = arange(cube%nn())\n! Element-wize vector for an Element\n! For example, body force N with 3-D space\ncall f%open(\"ElementVector.txt\",'w')\ncall f%write(cube%ElementVector(ElementID=1,GlobalVector=some_global_vector,DOF=1))\ncall f%close()\n\n\nend", "meta": {"hexsha": "929a60b39800f044d5766ab7574848df61ac1cd4", "size": 1602, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/fem/Matrices.f90", "max_stars_repo_name": "kazulagi/plantFEM", "max_stars_repo_head_hexsha": "20bf2df8202d41aa5dc25d1cc820385dabbc604f", "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/fem/Matrices.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/fem/Matrices.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": 28.1052631579, "max_line_length": 83, "alphanum_fraction": 0.7328339576, "num_tokens": 536, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179043564154, "lm_q2_score": 0.7185943925708561, "lm_q1q2_score": 0.6529277310600026}} {"text": "!fortran_free_source\n\n! need a seperate module for these last two functions b/c\n! the function F_CC calls both of them, and they cannot be \n! in the same module\nmodule pfc1dfuns2\nimplicit none\ncontains\n\n!==========================================================================\n!function to determine thickness in the pavement at the cell face\nFUNCTION F_hp_face(dxin, hin, zin, dxout, hout, zout, b)\nimplicit none\n!INPUTS\nREAL :: dxin, dxout ! size of cells\nREAL :: hin, hout ! thickness at CV center\nREAL :: zin, zout ! elevation at CV center\nREAL :: b ! pavement thickness\nREAL :: F_hp_face\n!DUMMY\nREAL :: head_at_face, Zface !HEAD and ELEVATION at the face\n!\nhead_at_face = ( (hin+zin)*dxin + (hout+zout)*dxout ) &\n / ( dxin + dxout)\nZface = ( zin*dxin + zout*dxout ) / ( dxin + dxout)\nF_hp_face = MIN ( b, head_at_face - Zface )\nEND function \n!===========================================================================\n!function to determine the thickness on the surface at the cell face\nFUNCTION F_hs_face(dxin, hin, zin, dxout, hout, zout, b)\nimplicit none\n!INPUTS\nREAL :: dxin, dxout ! size of cells\nREAL :: hin, hout ! thickness at CV center\nREAL :: zin, zout ! elevation at CV center\nREAL :: b ! pavement thickness\nREAL :: F_hs_face\n!DUMMY\nREAL :: head_at_face, Zface !HEAD and ELEVATION at the face\n!\nhead_at_face = ( (hin+zin)*dxin + (hout+zout)*dxout ) &\n / ( dxin + dxout)\nZface = ( zin*dxin + zout*dxout ) / ( dxin + dxout)\nF_hs_face = MAX ( 0., head_at_face - Zface - b )\nEND FUNCTION \n!=======================================================================\n\nend module pfc1dfuns2\n\n", "meta": {"hexsha": "376277fe8d6f61b80e87c2a4cb50b5e9fdd490d4", "size": 1699, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/pfc1Dfuns2.f95", "max_stars_repo_name": "bradleyjeck/Perfcode", "max_stars_repo_head_hexsha": "13495f27f8492467f07caaa0c26ee3aee1f1c817", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pfc1Dfuns2.f95", "max_issues_repo_name": "bradleyjeck/Perfcode", "max_issues_repo_head_hexsha": "13495f27f8492467f07caaa0c26ee3aee1f1c817", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/pfc1Dfuns2.f95", "max_forks_repo_name": "bradleyjeck/Perfcode", "max_forks_repo_head_hexsha": "13495f27f8492467f07caaa0c26ee3aee1f1c817", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.98, "max_line_length": 76, "alphanum_fraction": 0.5756327251, "num_tokens": 464, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818865, "lm_q2_score": 0.7185943925708562, "lm_q1q2_score": 0.6529277292818201}} {"text": "c\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc . .\nc . copyright (c) 1998 by UCAR .\nc . .\nc . University Corporation for Atmospheric Research .\nc . .\nc . all rights reserved .\nc . .\nc . .\nc . SPHEREPACK .\nc . .\nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .\nc\nc\nc\nc ... file shigc.f\nc\nc this file contains code and documentation for subroutine shigc\nc\nc ... files which must be loaded with shigc.f\nc\nc sphcom.f, hrfft.f, gaqd.f\nc\nc 3/6/98\nc\nc *** shigc is functionally the same as shagci or shsgci. It\nc it included in spherepack3.0 because legacy codes, using\nc the older version of spherepack call shigc to initialize\nc the saved work space wshigc, for either shagc or shsgc\nc\nc subroutine shigc(nlat,nlon,wshigc,lshigc,dwork,ldwork,ierror)\nc\nc subroutine shigc initializes the array wshigc which can then\nc be used repeatedly by subroutines shsgc or shagc. it precomputes\nc and stores in wshigc quantities such as gaussian weights,\nc legendre polynomial coefficients, and fft trigonometric tables.\nc\nc input parameters\nc\nc nlat the number of points in the gaussian colatitude grid on the\nc full sphere. these lie in the interval (0,pi) and are compu\nc in radians in theta(1),...,theta(nlat) by subroutine gaqd.\nc if nlat is odd the equator will be included as the grid poi\nc theta((nlat+1)/2). if nlat is even the equator will be\nc excluded as a grid point and will lie half way between\nc theta(nlat/2) and theta(nlat/2+1). nlat must be at least 3.\nc note: on the half sphere, the number of grid points in the\nc colatitudinal direction is nlat/2 if nlat is even or\nc (nlat+1)/2 if nlat is odd.\nc\nc nlon the number of distinct londitude points. nlon determines\nc the grid increment in longitude as 2*pi/nlon. for example\nc nlon = 72 for a five degree grid. nlon must be greater\nc than or equal to 4. the efficiency of the computation is\nc improved when nlon is a product of small prime numbers.\nc\nc wshigc an array which must be initialized by subroutine shigc.\nc once initialized, wshigc can be used repeatedly by shsgc\nc or shagc as long as nlat and nlon remain unchanged. wshigc\nc must not be altered between calls of shsgc or shagc.\nc\nc lshigc the dimension of the array wshigc as it appears in the\nc program that calls shsgc or shagc. define\nc\nc l1 = min0(nlat,(nlon+2)/2) if nlon is even or\nc l1 = min0(nlat,(nlon+1)/2) if nlon is odd\nc\nc and\nc\nc l2 = nlat/2 if nlat is even or\nc l2 = (nlat+1)/2 if nlat is odd\nc\nc then lshigc must be at least\nc\nc nlat*(2*l2+3*l1-2)+3*l1*(1-l1)/2+nlon+15\nc\nC*PL*ERROR* Comment line too long\nc dwork a double precision work array that does not have to be saved.\nc\nc ldwork the dimension of the array dwork as it appears in the\nc program that calls shigc. ldwork must be at least\nc\nc nlat*(nlat+4)\nc\nc output parameter\nc\nC*PL*ERROR* Comment line too long\nc wshigc an array which must be initialized before calling shsgc or shagc.\nC*PL*ERROR* Comment line too long\nc once initialized, wshigc can be used repeatedly by shsgc or shagc\nc as long as nlat and nlon remain unchanged. wshigc must not\nc altered between calls of shsgc or shagc\nc\nc ierror = 0 no errors\nc = 1 error in the specification of nlat\nc = 2 error in the specification of nlon\nc = 3 error in the specification of lshigc\nc = 4 error in the specification of ldwork\nc = 5 failure in gaqd to compute gaussian points\nc (due to failure in eigenvalue routine)\nc\nc\nc ****************************************************************\n SUBROUTINE DSHIGC(NLAT,NLON,WSHIGC,LSHIGC,DWORK,LDWORK,IERROR)\n DOUBLE PRECISION WSHIGC\nc this subroutine must be called before calling shsgc/shagc with\nc fixed nlat,nlon. it precomputes quantites such as the gaussian\nc points and weights, m=0,m=1 legendre polynomials, recursion\nc recursion coefficients.\n DIMENSION WSHIGC(LSHIGC)\nC*PT*WARNING* Already double-precision\n DOUBLE PRECISION DWORK(LDWORK)\n\n IERROR = 1\n IF (NLAT.LT.3) RETURN\n IERROR = 2\n IF (NLON.LT.4) RETURN\nc set triangular truncation limit for spherical harmonic basis\n L = MIN0((NLON+2)/2,NLAT)\nc set equator or nearest point (if excluded) pointer\n LATE = (NLAT+MOD(NLAT,2))/2\n L1 = L\n L2 = LATE\n IERROR = 3\nc check permanent work space length\n IF (LSHIGC.LT.NLAT* (2*L2+3*L1-2)+3*L1* (1-L1)/2+NLON+15) RETURN\n IERROR = 4\nc if (lwork.lt.4*nlat*(nlat+2)+2) return\n IF (LDWORK.LT.NLAT* (NLAT+4)) RETURN\n IERROR = 0\nc set pointers\n I1 = 1\n I2 = I1 + NLAT\n I3 = I2 + NLAT*LATE\n I4 = I3 + NLAT*LATE\n I5 = I4 + L* (L-1)/2 + (NLAT-L)* (L-1)\n I6 = I5 + L* (L-1)/2 + (NLAT-L)* (L-1)\n I7 = I6 + L* (L-1)/2 + (NLAT-L)* (L-1)\nc set indices in temp work for double precision gaussian wts and pts\n IDTH = 1\nc idwts = idth+2*nlat\nc iw = idwts+2*nlat\n IDWTS = IDTH + NLAT\n IW = IDWTS + NLAT\n CALL DSHIGC1(NLAT,NLON,L,LATE,WSHIGC(I1),WSHIGC(I2),WSHIGC(I3),\n + WSHIGC(I4),WSHIGC(I5),WSHIGC(I6),WSHIGC(I7),\n + DWORK(IDTH),DWORK(IDWTS),DWORK(IW),IERROR)\n IF (IERROR.NE.0) IERROR = 5\n RETURN\n END\n SUBROUTINE DSHIGC1(NLAT,NLON,L,LATE,WTS,P0N,P1N,ABEL,BBEL,CBEL,\n + WFFT,DTHETA,DWTS,WORK,IER)\n DOUBLE PRECISION WTS\n DOUBLE PRECISION P0N\n DOUBLE PRECISION P1N\n DOUBLE PRECISION ABEL\n DOUBLE PRECISION BBEL\n DOUBLE PRECISION CBEL\n DOUBLE PRECISION WFFT\n DOUBLE PRECISION FN\n DOUBLE PRECISION FM\n DIMENSION WTS(NLAT),P0N(NLAT,LATE),P1N(NLAT,LATE),ABEL(1),BBEL(1),\n + CBEL(1),WFFT(1),DTHETA(NLAT),DWTS(NLAT)\nC*PT*WARNING* Already double-precision\n DOUBLE PRECISION PB,DTHETA,DWTS,WORK(*)\nc compute the nlat gaussian points and weights, the\nc m=0,1 legendre polys for gaussian points and all n,\nc and the legendre recursion coefficients\nc define index function used in storing\nc arrays for recursion coefficients (functions of (m,n))\nc the index function indx(m,n) is defined so that\nc the pairs (m,n) map to [1,2,...,indx(l-1,l-1)] with no\nc \"holes\" as m varies from 2 to n and n varies from 2 to l-1.\nc (m=0,1 are set from p0n,p1n for all n)\nc define for 2.le.n.le.l-1\n INDX(M,N) = (N-1)* (N-2)/2 + M - 1\nc define index function for l.le.n.le.nlat\n IMNDX(M,N) = L* (L-1)/2 + (N-L-1)* (L-1) + M - 1\nc preset quantites for fourier transform\n CALL DHRFFTI(NLON,WFFT)\nc compute double precision gaussian points and weights\nc lw = 4*nlat*(nlat+1)+2\n LW = NLAT* (NLAT+2)\n CALL DGAQD(NLAT,DTHETA,DWTS,WORK,LW,IER)\n IF (IER.NE.0) RETURN\nc store gaussian weights single precision to save computation\nc in inner loops in analysis\n DO 100 I = 1,NLAT\n WTS(I) = DWTS(I)\n 100 CONTINUE\nc initialize p0n,p1n using double precision dnlfk,dnlft\n DO 101 NP1 = 1,NLAT\n DO 101 I = 1,LATE\n P0N(NP1,I) = 0.0D0\n P1N(NP1,I) = 0.0D0\n 101 CONTINUE\nc compute m=n=0 legendre polynomials for all theta(i)\n NP1 = 1\n N = 0\n M = 0\n CALL DDNLFK(M,N,WORK)\n DO 103 I = 1,LATE\n CALL DDNLFT(M,N,DTHETA(I),WORK,PB)\n P0N(1,I) = PB\n 103 CONTINUE\nc compute p0n,p1n for all theta(i) when n.gt.0\n DO 104 NP1 = 2,NLAT\n N = NP1 - 1\n M = 0\n CALL DDNLFK(M,N,WORK)\n DO 105 I = 1,LATE\n CALL DDNLFT(M,N,DTHETA(I),WORK,PB)\n P0N(NP1,I) = PB\n 105 CONTINUE\nc compute m=1 legendre polynomials for all n and theta(i)\n M = 1\n CALL DDNLFK(M,N,WORK)\n DO 106 I = 1,LATE\n CALL DDNLFT(M,N,DTHETA(I),WORK,PB)\n P1N(NP1,I) = PB\n 106 CONTINUE\n 104 CONTINUE\nc compute and store swarztrauber recursion coefficients\nc for 2.le.m.le.n and 2.le.n.le.nlat in abel,bbel,cbel\n DO 107 N = 2,NLAT\n FN = DBLE(N)\n MLIM = MIN0(N,L)\n DO 107 M = 2,MLIM\n FM = DBLE(M)\n IMN = INDX(M,N)\n IF (N.GE.L) IMN = IMNDX(M,N)\n ABEL(IMN) = SQRT(((2*FN+1)* (FM+FN-2)* (FM+FN-3))/\n + (((2*FN-3)* (FM+FN-1)* (FM+FN))))\n BBEL(IMN) = SQRT(((2*FN+1)* (FN-FM-1)* (FN-FM))/\n + (((2*FN-3)* (FM+FN-1)* (FM+FN))))\n CBEL(IMN) = SQRT(((FN-FM+1)* (FN-FM+2))/\n + (((FN+FM-1)* (FN+FM))))\n 107 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "afbf4ebdd08fa4501b3c2867c59777c9d56dddcd", "size": 9515, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "external/sphere3.1_dp/shigc.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "external/sphere3.1_dp/shigc.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "external/sphere3.1_dp/shigc.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 39.3181818182, "max_line_length": 78, "alphanum_fraction": 0.5582764057, "num_tokens": 3070, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178994073576, "lm_q2_score": 0.7185943925708561, "lm_q1q2_score": 0.6529277275036374}} {"text": "Module Phys_constants\n! Physical and Mathematical constants\n! Solar constants\n! c.g.s. units\n Real :: Gravity=2.7414e+4 ! cm/s^2 ! Default. Solar surface gravity\n Real, Parameter :: Solar_Gravity = 2.7414e+4 ! Surface gravity (cm/s^2)\n! Physical constants\n! c.g.s. units\n Real, Parameter :: cc = 2.99792458D10, hh = 6.62618D-27, ee = 1.602189D-12 \n Real, Parameter :: mass_el = 9.10953D-28, mass_pr = 1.672648D-24\n Real, Parameter :: bk = 1.38066D-16, Avog=6.022045D23\n! Conversion factor: eV to erg (g cm^2 / s^2). \n! Note that 1 V = 10^7 (g cm^2)/(C s^2)\n Real, Parameter :: eV_to_cgs = ee\n! Mathematical constants\n Real, Parameter :: Pi = 3.14159265389793D0\n Real, Parameter :: SqrtPi = 1.77245390415191650391 ! Sqrt(Pi)\n Real, Parameter :: Piis = 0.56418956659890107D0 ! Inverse of the Sqrt of Pi\nEnd Module Phys_constants\n", "meta": {"hexsha": "9627f37298e61595275957a3ec1d33994c5e4aff", "size": 836, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "inversor/database/NICOLE/main/phys_constants.f90", "max_stars_repo_name": "aasensio/DeepLearning", "max_stars_repo_head_hexsha": "71838115ce93e0ca96c8314cff3f07de1d64c235", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "inversor/database/NICOLE/main/phys_constants.f90", "max_issues_repo_name": "aasensio/DeepLearning", "max_issues_repo_head_hexsha": "71838115ce93e0ca96c8314cff3f07de1d64c235", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "inversor/database/NICOLE/main/phys_constants.f90", "max_forks_repo_name": "aasensio/DeepLearning", "max_forks_repo_head_hexsha": "71838115ce93e0ca96c8314cff3f07de1d64c235", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.8, "max_line_length": 77, "alphanum_fraction": 0.6985645933, "num_tokens": 311, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818865, "lm_q2_score": 0.718594386544335, "lm_q1q2_score": 0.652927723806015}} {"text": "c\nc\ttransformation matrix t5=*\nc\nc\tiverse = 1 forward transform\nc\t =-1 inverse transform\nc\n\tsubroutine t5 (itime,x_in,x_out,iverse)\n\treal x_in(3),x_out(3),phi,lamda,rmjd,ut\n\treal temp(3),fracday\n\tinteger*4 itime(2),iverse,iyr,iday\n\tparameter (pid2=3.1415927/2.0,degrad=3.1415927/180.0)\nc\n\tIYR=itime(1)/1000\n\tIDAY=itime(1)-IYR*1000\n\tut=itime(2)/3600000.0\n\tfracday=ut/24.0\r\nc\nc\tRMJD=44238.0+FLOAT(IYR-1980)*365.+\nc &\t\tFLOAT((IYR-1977)/4)+FLOAT(IDAY)\nc rmjd = modified Julian day = time measured in days from 00:00UT November 17, 1858\r\n\trmjd=45.0+float(iyr-1859)*365.0 + (float((iyr-1861)/4)+1.0)\r\n &\t\t+ float(iday) -1.0 + fracday\r\nc\n\tfactor=(rmjd-46066.0)/365.25\n\tphi=(78.8+4.283e-2*factor)*degrad\n\tlamda=(289.1-1.413e-2*factor)*degrad\nc\n\tif (iverse.eq.1) then\n\t call rotate_z(lamda,x_in,temp)\n\t call rotate_y(phi-pid2,temp,x_out)\n\telse\n\t call rotate_y(iverse*(phi-pid2),x_in,temp)\n\t call rotate_z(iverse*lamda,temp,x_out)\n\tend if\nc\n\treturn\n\tend\n\n", "meta": {"hexsha": "27a3eaf288e260e664ded7751501ddbaafd61c72", "size": 983, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "PyGCPM/__data/libgcpm/xform/T5.for", "max_stars_repo_name": "mattkjames7/PyGCPM", "max_stars_repo_head_hexsha": "90d1c29b82b7b286f570eb49f7bf7618ddc4717b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "PyGCPM/__data/libgcpm/xform/T5.for", "max_issues_repo_name": "mattkjames7/PyGCPM", "max_issues_repo_head_hexsha": "90d1c29b82b7b286f570eb49f7bf7618ddc4717b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "PyGCPM/__data/libgcpm/xform/T5.for", "max_forks_repo_name": "mattkjames7/PyGCPM", "max_forks_repo_head_hexsha": "90d1c29b82b7b286f570eb49f7bf7618ddc4717b", "max_forks_repo_licenses": ["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.2051282051, "max_line_length": 85, "alphanum_fraction": 0.6917599186, "num_tokens": 426, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178870347122, "lm_q2_score": 0.7185943925708561, "lm_q1q2_score": 0.6529277186127238}} {"text": "!derivmodule.f90 - equations of motion for integrator\nmodule derivmodule\n\n use kindmodule\n\n implicit none\n\n complex(wp) :: mu=1.0 ! Gravitational parameter\n complex(wp) :: mustar=0.0121505856 ! Mass ratio for three body problem \n\n public :: dkep, dcrtbp, setmu, setmustar, getmu, getmustar\n private :: mu, mustar\n\ncontains\n\n ! Equations of motion for Keplerian dynamics\n subroutine dkep(t, x, xdot)\n\n use kindmodule\n use mathmodule\n\n ! DECLARATION\n implicit none\n\n ! Input/output\n complex(wp),intent(in) :: t\n complex(wp),intent(in),dimension(:) :: x\n complex(wp),intent(out),dimension(:) :: xdot\n ! Local\n complex(wp) :: rmag3\n\n ! EXECUTION\n xdot(1:3) = x(4:6)\n\n rmag3 = astnorm(x(1:3))**3\n xdot(4) = -mu*x(1)/rmag3\n xdot(5) = -mu*x(2)/rmag3\n xdot(6) = -mu*x(3)/rmag3\n\n end subroutine dkep\n\n\n ! Equations of motion for CRTBP \n subroutine dcrtbp(t, x, xdot)\n\n use kindmodule\n use mathmodule\n\n ! DECLARATION\n implicit none\n\n ! Input/output\n complex(wp),intent(in) :: t\n complex(wp),intent(in),dimension(:) :: x\n complex(wp),intent(out),dimension(:) :: xdot\n ! Local\n complex(wp),dimension(3) :: r1, r2\n complex(wp) :: r1mag3, r2mag3\n\n ! EXECUTION\n xdot(1:3) = x(4:6)\n\n r1(1) = x(1) + mustar\n r1(2) = x(2)\n r1(3) = x(3)\n\n r2(1) = x(1) - 1 + mustar\n r2(2) = x(2)\n r2(3) = x(3)\n\n r1mag3 = astnorm(r1)**3\n r2mag3 = astnorm(r2)**3\n\n xdot(4) = 2*x(5) + x(1) - (1-mustar)*(x(1)+mustar)/r1mag3 - mustar*(x(1)-1+mustar)/r2mag3 \n xdot(5) = -2*x(4) + x(2) - (1-mustar)*x(2)/r1mag3 - mustar*x(2)/r2mag3 \n xdot(6) = -(1-mustar)*x(3)/r1mag3 - mustar*x(3)/r2mag3 \n\n end subroutine dcrtbp\n\n\n ! Sets mass ratio module variable\n subroutine setmustar(mustarin)\n use kindmodule\n implicit none\n complex(wp),intent(in) :: mustarin\n mustar = mustarin\n end subroutine setmustar\n\n\n ! Reports mass ratio module variable\n function getmustar()\n use kindmodule\n implicit none\n complex(wp) :: getmustar\n getmustar = mustar\n end function getmustar\n\n\n ! Sets gravitational parameter module variable\n subroutine setmu(muin)\n use kindmodule\n implicit none\n complex(wp),intent(in) :: muin\n mu = muin\n end subroutine setmu\n\n\n ! Reports gravitational parameter module variable\n function getmu()\n use kindmodule\n implicit none\n complex(wp) :: getmu\n getmu = mu\n end function getmu\n\n\nend module derivmodule\n", "meta": {"hexsha": "293e667fcf4a28515e9a1b2204ba3bf59cb9a68e", "size": 2744, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/integration/src/derivmodule.f90", "max_stars_repo_name": "yookiwooki/AstroLib", "max_stars_repo_head_hexsha": "4598be425e837ea6b216d4f0d09e789aa54d9368", "max_stars_repo_licenses": ["MIT"], "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/integration/src/derivmodule.f90", "max_issues_repo_name": "yookiwooki/AstroLib", "max_issues_repo_head_hexsha": "4598be425e837ea6b216d4f0d09e789aa54d9368", "max_issues_repo_licenses": ["MIT"], "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/integration/src/derivmodule.f90", "max_forks_repo_name": "yookiwooki/AstroLib", "max_forks_repo_head_hexsha": "4598be425e837ea6b216d4f0d09e789aa54d9368", "max_forks_repo_licenses": ["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.2542372881, "max_line_length": 98, "alphanum_fraction": 0.5641399417, "num_tokens": 862, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6529253794863158}} {"text": "subroutine apply_2ndbc_solid(x_solid,nsd,nn_solid,ien_sbc,ne_sbc,nen_solid,&\n ien_solid,ne_solid,solid_bcforce,solid_stress)\n!---------------------------------\n! Calculate solid surface normal integral for 3-D cases\n! 1 find the points on the boundary surface\n! 2 use two vector cross to find the norm of the norm of the surface\n! 3 take one interial point and take the dot between this vector and norm \n! if dot < 0 it is the outward norm and then normalize the norm\n! 4 calculate the area of boundary surface: (1) tet, area of triangle; (2) hex, 2 triangles\n! 5 take norm*area and distribute it equaly to the each node\n\nimplicit none\n\nreal(8) x_solid(nsd,nn_solid)\ninteger nsd\ninteger nn_solid\ninteger ien_sbc(ne_sbc,nen_solid+2)\ninteger ne_sbc\ninteger nen_solid\ninteger ien_solid(ne_solid,nen_solid)\ninteger ne_solid\nreal(8) solid_bcforce(nsd,nn_solid)\nreal(8) solid_stress(nsd*2,nn_solid)\n!------------------------------------\ninteger count\ninteger ibs\ninteger ine\ninteger ntem\ninteger nos\nreal(8), allocatable, dimension(:,:) :: x\nreal(8) p(nsd)\nreal(8) w\nreal(8) norm(nsd)\nreal(8) area\ninteger isd\ninteger jsd\nreal(8) stress_tmp(nsd,nsd)\ninteger error_id\n\nsolid_bcforce(:,:)=0.0d0\n\n\nif (nen_solid == 4) then\nallocate (x(nsd,3))\nw=1.0/3.0\nend if\n\nif (nen_solid == 8) then\nallocate (x(nsd,4))\nw=1.0/4.0\nend if\n\n\ndo ibs=1,ne_sbc\n\n\tine=ien_sbc(ibs,1)\n\tcount=1\n\t\tdo nos=1,nen_solid\n\t\tntem=ien_solid(ine,nos)\n\t\tif (ien_sbc(ibs,nos+1) == 1) then\n\t\tx(1:nsd,count)=x_solid(1:nsd,ntem)\n\t\tcount=count+1\n\t\telse\n\t\tp(1:nsd)=x_solid(1:nsd,ntem)\n\t\tend if\n\t\tend do\n\t\t! find the local nodes on the 2nd type BC surface\n if (count .ne. 4) write(*,*) 'Wrong !!!!!',ibs\n if (nen_solid == 4) then\n call outnormal_tet(x,nsd,p,norm,area)\n elseif (nen_solid == 8) then\n call outnormal_hex(x,nsd,p,norm,area)\n endif\n\t\t! get the ourward norm\n\n do nos=1,nen_solid\n ntem=ien_solid(ine,nos)\n\n if (ien_sbc(ibs,nos+1) == 1 .and. ien_sbc(ibs,nen_solid+2) == -999) then\n stress_tmp(1,1)=solid_stress(1,ntem)\n stress_tmp(2,2)=solid_stress(2,ntem)\n stress_tmp(3,3)=solid_stress(3,ntem)\n stress_tmp(2,3)=solid_stress(4,ntem)\n stress_tmp(3,2)=solid_stress(4,ntem)\n stress_tmp(1,3)=solid_stress(5,ntem)\n stress_tmp(3,1)=solid_stress(5,ntem)\n stress_tmp(1,2)=solid_stress(6,ntem)\n stress_tmp(2,1)=solid_stress(6,ntem)\n\n\t\t\tdo isd=1,nsd\n\t\t\t\tdo jsd=1,nsd\n\t\t\t\tsolid_bcforce(isd,ntem)=solid_bcforce(isd,ntem)+&\n\t\t\t\tarea*stress_tmp(isd,jsd)*norm(jsd)*w\n\t\t\t\tend do\n\t\t\tend do\n\n\t\tend if\n\t\tend do\n\t\t! integrate over 2nd BC surface \\sigma_{ij} n_{j} w \ncontinue\n\nend do\n\n\ndeallocate(x)\n\ncontinue\nreturn\nend \n", "meta": {"hexsha": "2cc2b64c9976053e577234705876c3f2342d825c", "size": 2837, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "apply_2ndbc_solid.f90", "max_stars_repo_name": "biofluids/IFEM-archive", "max_stars_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-15T11:40:16.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-15T11:40:16.000Z", "max_issues_repo_path": "apply_2ndbc_solid.f90", "max_issues_repo_name": "biofluids/IFEM-archive", "max_issues_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "apply_2ndbc_solid.f90", "max_forks_repo_name": "biofluids/IFEM-archive", "max_forks_repo_head_hexsha": "ed14a3ff980251ba98e519a64fb0549d4c991744", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-02-11T16:50:21.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-08T07:24:59.000Z", "avg_line_length": 25.7909090909, "max_line_length": 91, "alphanum_fraction": 0.6383503701, "num_tokens": 988, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505273888289, "lm_q2_score": 0.7217432122827968, "lm_q1q2_score": 0.6529253776309396}} {"text": "\tSUBROUTINE DP_UNMC ( idata, kxky, nbits, ref, scale,\n +\t\t\t grid, iret )\nC************************************************************************\nC* DP_UNMC\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This subroutine unpacks a grid in the NMC format. The unpacking\t*\nC* equation is:\t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC*\tGRID = REF + IDATA * SCALE\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Each grid point must be packed into 16 bits which can be treated\t*\nC* as an INTEGER*2 word. The scaling factor is a multiplier for the\t*\nC* data. It must be set to 1 / 2 ** (15-N) where N is the exponent\t*\nC* with the original NMC grid. This subroutine assumes there is no\t*\nC* missing data.\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* DP_UNMC ( IDATA, KXKY, NBITS, REF, SCALE, GRID, IRET )\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tIDATA (KXKY)\tINTEGER*2\tPacked data\t\t\t*\nC*\tKXKY\t\tINTEGER\t\tNumber of grid points\t\t*\nC*\tNBITS\t\tINTEGER\t\tNumber of bits\t\t\t*\nC*\tREF\t\tREAL\t\tReference value of grid\t\t*\nC*\tSCALE\t\tREAL\t\tScaling factor\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tGRID (KXKY)\tREAL\t\tGrid data\t\t\t*\nC*\tIRET\t\tINTEGER\t\tReturn code\t\t\t*\nC*\t\t\t\t\t 0 = normal return\t\t*\nC*\t\t\t\t\t-10 = NBITS invalid\t\t*\nC*\t\t\t\t\t-12 = invalid scale\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* M. desJardins/GSFC\t 3/89\t\t\t\t\t\t*\nC* M. desJardins/GSFC\t 2/91\tRewrite using INTEGER*2 words\t\t*\nC* K. Brill/NMC\t\t 5/91 Added MV_SW42\t\t\t\t*\nC* S. Jacobs/EAI\t 8/92\tAdded check for ULTRIX machine\t\t*\nC* S. Jacobs/EAI\t10/93\tAdded check for ALPHA machine\t\t*\nC* T. Piper/GSC\t\t11/98\tUpdated prolog\t\t\t\t*\nC* T. Piper/GSC\t\t 3/99\tCorrected prolog\t\t\t*\nC* S. Jacobs/NCEP\t 2/01\tAdded check for LINUX machine\t\t*\nC************************************************************************\n\tINCLUDE\t\t'GEMPRM.PRM'\nC*\n\tREAL\t\tgrid (*)\n\tINTEGER*2\tidata (*)\nC------------------------------------------------------------------------\n\tiret = 0\nC\nC*\tCheck for valid input.\nC\n\tIF ( nbits .ne. 16 ) THEN\n\t iret = -10\n\t RETURN\n\tEND IF\n\tIF ( scale .eq. 0. ) THEN\n\t iret = -12\n\t RETURN\n\tEND IF\nC\nC*\tIf the machine is a VAX, swap the 16-bit words.\nC\n\tIF ( ( MTMACH .eq. MTVAX ) .or. \n +\t ( MTMACH .eq. MTIGPH ) .or.\n +\t ( MTMACH .eq. MTALPH ) .or.\n +\t ( MTMACH .eq. MTLNUX ) .or.\n +\t ( MTMACH .eq. MTULTX ) ) THEN\n\t nwords = kxky / 2\n\t IF ( MOD ( kxky, 2 ) .ne. 0 ) nwords = nwords + 1\n\t ier = MV_SW42 ( nwords, idata, idata )\n\tEND IF\nC\nC*\tLoop through all the grid points.\nC\n\tDO i = 1, kxky\n\t grid (i) = ref + idata (i) * scale\n\tEND DO\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "011266fcc9fb6a8ed6fbda7116b4506272d7abb1", "size": 2492, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/gemlib/dp/dpunmc.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/gemlib/dp/dpunmc.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": "dpunmc.f", "max_forks_repo_name": "sgdecker/pygempak", "max_forks_repo_head_hexsha": "e64dd08c1ab80ce17321dc4c904d67f1317373e2", "max_forks_repo_licenses": ["Apache-2.0"], "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.7654320988, "max_line_length": 73, "alphanum_fraction": 0.5240770465, "num_tokens": 916, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505325302034, "lm_q2_score": 0.7217432003123989, "lm_q1q2_score": 0.652925370512665}} {"text": " subroutine aratio_element_edge(ielmtyp,\n * x,y,z,\n * id_edge_min, id_edge_max,\n * edge_min, edge_max,\n * edge_min_edge_max_ratio)\nC\nC\nC #####################################################################\nC\nC PURPOSE -\nC\nC For a single element finds the ratio:\nC (shortest element edge/longest element edge)\nC\nC INPUT ARGUMENTS -\nC\nC ielmtyp : The element type.\nC (x(),y(),z() : The coordinates of the element.\nC\nC OUTPUT ARGUMENTS -\nC\nC id_edge_min : The local edge number of the shortest edge\nC id_edge_max : The local edge number of the longest edge\nC edge_min : The length of the longest edge\nC edge_max : The length of the shortest edge\nC edge_min_edge_max_ratio : The computed edge min to edge max ratio.\nC\nC CHANGE HISTORY -\nC\nC $Log: aratio_element_edge.f,v $\nC Revision 2.00 2007/11/05 19:45:46 spchu\nC Import to CVS\nC\nCPVCS \r\nCPVCS Rev 1.0 20 Jun 2006 18:25:14 gable\r\nCPVCS Initial revision.\r\nC\nC ######################################################################\nC\nC\n implicit none\nC\n include \"local_element.h\"\nC\n real*8 edge_min_edge_max_ratio, dist, edge_min, edge_max\n real*8 x(1000000), y(1000000), z(1000000)\n integer i, i1, i2, ielmtyp\n integer id_edge_min, id_edge_max\nC\nC ######################################################################\nC\nC\nC Find min and max edge length. Save the square root calculation\nC until the min/max have been found.\nC\n edge_max = -1.e20\n edge_min = 1.e20\n do i=1,nelmnee(ielmtyp)\n i1 = ielmedge1(1,i,ielmtyp)\n i2 = ielmedge1(2,i,ielmtyp)\n dist = (x(i2)-x(i1))**2 + \n 1 (y(i2)-y(i1))**2 +\n 2 (z(i2)-z(i1))**2\n\n if(dist .gt. edge_max)then\n edge_max = dist\n id_edge_max = i\n endif\n if(dist .lt. edge_min)then\n edge_min = dist\n id_edge_min = i\n endif\n enddo\n\n edge_max = sqrt(edge_max)\n edge_min = sqrt(edge_min)\n edge_min_edge_max_ratio = edge_min/edge_max\n\n return\n end\n", "meta": {"hexsha": "c5de5e4302a519f52ef9bbfa58357c56ca9776e0", "size": 2349, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/aratio_element_edge.f", "max_stars_repo_name": "millerta/LaGriT-1", "max_stars_repo_head_hexsha": "511ef22f3b7e839c7e0484604cd7f6a2278ae6b9", "max_stars_repo_licenses": ["CNRI-Python"], "max_stars_count": 73, "max_stars_repo_stars_event_min_datetime": "2017-02-09T17:54:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-09T22:22:32.000Z", "max_issues_repo_path": "src/aratio_element_edge.f", "max_issues_repo_name": "millerta/LaGriT-1", "max_issues_repo_head_hexsha": "511ef22f3b7e839c7e0484604cd7f6a2278ae6b9", "max_issues_repo_licenses": ["CNRI-Python"], "max_issues_count": 166, "max_issues_repo_issues_event_min_datetime": "2017-01-26T17:15:45.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T21:36:28.000Z", "max_forks_repo_path": "src/lg_core/aratio_element_edge.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.0, "max_line_length": 77, "alphanum_fraction": 0.5006385696, "num_tokens": 632, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505273888289, "lm_q2_score": 0.7217431943271998, "lm_q1q2_score": 0.6529253613873993}} {"text": "CNNNNXB----------------------------------------------------------------E\n SUBROUTINE CALVIS(QV,QC,QR,CRAIN,CFRZR,CICEP,CSNOW,TA,PP,VIS)\nC$$$ SUBPROGRAM DOCUMENTATION BLOCK \nC . . . . \nC SUBPROGRAM: CALVIS COMPUTES VISUAL RANGE IN KM FROM GFS\nC PRGMMR: L. D. BURROUGHS ORG: W/NMC21 DATE: 03-03-09 \nC \nC ABSTRACT: COMPUTES HORIZONTAL VISIBILITY AT THE 1000 HPA LAYER FROM\nc QV, QC, QR, CRAIN, CFRZR, CICEP,CSNOW, AIR TEMP AND PRESSURE.\nC \nC PROGRAM HISTORY LOG: \nC 03-02-03 L. D. BURROUGHS \nC \nC USAGE: CALL CALVIS(QV,QC,QR,CRAIN,CFRZR,CICEP,CSNOW,TA,PP,VIS)\nC \nC INPUT ARGUMENT LIST: \nc qv - water vapor mixing ratio (kg/kg)\nc qc - cloud water mixing ratio (kg/kg)\nc qr - rain water mixing ratio (kg/kg)\nc ta - air temperature (k)\nc pp - pressure (hPa)\nc crain - categorical rain (y=1,n=0)\nc cfrzr - categorical freezing rain(y=1,n=0)\nc cicep - categorical ice pellets (y=1.n=0)\nc csnow - categorical snow (y=1,n=0) \nc\nC \nC OUTPUT ARGUMENT LIST: \nC vis - visual range in km\nC \nC INPUT FILES: \nC NONE \nC \nC OUTPUT FILES: \nC NONE \nC \nC SUBPROGRAMS CALLED: \nC \nC UNIQUE: - NONE \nC \nC LIBRARY: \nC W3LIB - NONE \nC \nC IMSL - NONE \nC \nC SPECIAL - LOG\nC \nC REMARKS:\nc If crain and cfrzr = 0 and cicep and csnow = 0; then qc determines\nc vis alone;\nc if crain or cfrzr =1 and cicep and csnow = 0; then qc and qr deter-\nc mine vis;\nc if crain or cfrzr =1 and cicep or csnow =1; then qc and a combo of\nc 50 percent rain and snow is used to determine vis;\nc if crain or cfrzr =0 and cicep or csnow =1; then qc and qs deter-\nc nine vis;\nC \nc The routine uses the following\nc expressions for extinction coefficient, beta (in km**-1),\nc with C being the mass concentration (in g/m**3):\nc\nc cloud water: beta = 144.7 * C ** (0.8800)\nc rain water: beta = 2.24 * C ** (0.7500)\nc cloud ice: beta = 327.8 * C ** (1.0000)\nc snow: beta = 10.36 * C ** (0.7776)\nc\nc These expressions were obtained from the following sources:\nc\nc for cloud water: from Kunkel (1984)\nc for rainwater: from M-P dist'n, with No=8e6 m**-4 and\nc rho_w=1000 kg/m**3\nc for cloud ice: assume randomly oriented plates which follow\nc mass-diameter relationship from Rutledge and Hobbs (1983)\nc for snow: from Stallabrass (1985), assuming beta = -ln(.02)/vis\nc\nc The extinction coefficient for each water species present is\nc calculated, and then all applicable betas are summed to yield\nc a single beta. Then the following relationship is used to\nc determine visibility (in km), where epsilon is the threshhold\nc of contrast, usually taken to be .02:\nc\nc vis = -ln(epsilon)/beta [found in Kunkel (1984)]\nc\nc This procedure was first developed by Stoelinga and Warner, adapted to the\nc eta model postprocessor by Geoff Manikin, and adapted by Larry Burroughs for\nc use with the GFS to replace the statistical open ocean fog and visibility\tc system.\nC \nC ATTRIBUTES: \nC LANGUAGE: FORTRAN90\nC MACHINE: IBM SP\nC \nC$$$ \nC \n IMPLICIT none\nCNNNNX------------------------------------------------------------------\n SAVE\n REAL rdc, coeflc, coeflp, coeffc, coeffp\n REAL exponlc, exponlp, exponfc, exponfp, rhoice, rhowat\n \n PARAMETER(RDC=0.34838,COEFLC=144.7,COEFLP=2.24,COEFFC=327.8,\n 1 COEFFP=10.36,EXPONLC=0.8800,EXPONLP=0.7500,\n 2 EXPONFC=1.0000,EXPONFP=0.7776,RHOICE=916.8,\n 3 RHOWAT=997.37)\n\n! Arguments\n REAL qv, qc, qr, crain, cfrzr, cicep, csnow, ta, pp, vis\n! Local\n REAL const1, sh, tv, rhoair, qcld, vovermd, concfp\n REAL conclc, conclp, concfc, qprr, qprs, qcldi\n REAL betav\nCNNNNX------------------------------------------------------------------\n CONST1=-LOG(0.02)\n SH=QV/(1+QV)\n TV=TA*(1.0+0.608*SH)\n RHOAIR=RDC*PP/TV\nC\nC Determine precipitation type and mixing ratio values\nC\n IF(CRAIN.EQ.0..AND.CFRZR.EQ.0..AND.CICEP.EQ.0..AND.CSNOW.EQ.0.)\n 1 THEN\n QCLD=QC\n VOVERMD=(1.+QV)/RHOAIR+QCLD/RHOWAT\n CONCLC = QCLD/VOVERMD*1000.\n CONCLP = 0.\n CONCFC = 0.\n CONCFP = 0.\n ELSEIF((CRAIN.EQ.1..OR.CFRZR.EQ.1.).AND.CICEP.EQ.0..AND.\n 1 CSNOW.EQ.0.)THEN\n QPRR=QR\n QCLD=QC\n VOVERMD=(1.+QV)/RHOAIR+(QPRR+QCLD)/RHOWAT\n CONCLC = QCLD/VOVERMD*1000.\n CONCLP = QPRR/VOVERMD*1000.\n CONCFC = 0.\n CONCFP = 0.\n ELSEIF((CRAIN.EQ.1..OR.CFRZR.EQ.1.).AND.(CICEP.EQ.1..OR.\n 1 CSNOW.EQ.1.))THEN\n QPRR=0.5*QR\n QPRS=0.5*QR\n QCLD=0.5*QC\n QCLDI=0.5*QC\n VOVERMD=(1.+QV)/RHOAIR+(QPRR+QCLD)/RHOWAT+(QPRS+QCLDI)/RHOICE\n CONCLC = QCLD/VOVERMD*1000.\n CONCLP = QPRR/VOVERMD*1000.\n CONCFC = QCLDI/VOVERMD*1000.\n CONCFP = QPRS/VOVERMD*1000.\n ELSEIF(CRAIN.EQ.0..AND.CFRZR.EQ.0..AND.(CICEP.EQ.1..OR.\n 1 CSNOW.EQ.1.))THEN\n QPRS=QR\n QCLDI=QC\n IF(TA.LE.263.)THEN\n VOVERMD=(1.+QV)/RHOAIR+(QPRS+QCLDI)/RHOICE\n CONCLC = 0.\n CONCLP = 0.\n CONCFC = QCLDI/VOVERMD*1000.\n CONCFP = QPRS/VOVERMD*1000.\n ELSE\n VOVERMD=(1.+QV)/RHOAIR+QCLDI/RHOWAT+QPRS/RHOICE\n CONCLC = QCLDI/VOVERMD*1000.\n CONCLP = 0.\n CONCFC = 0.\n CONCFP = QPRS/VOVERMD*1000.\n ENDIF\n ENDIF\n BETAV=COEFFC*CONCFC**EXPONFC+COEFFP*CONCFP**EXPONFP\n 1 +COEFLC*CONCLC**EXPONLC+COEFLP*CONCLP**EXPONLP\n 2 +1.E-10\nc CHANGED GSM 3-10-00 --> no point in distinguishing values\nc above 20 km, so make that value the max (prev max was 80)\n VIS=1.E3*MIN(20.,CONST1/BETAV)\nC\n RETURN\n END\n", "meta": {"hexsha": "fd7e4a75f6d95b8245a27464b5ce37c51485b271", "size": 8040, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "sorc/omb_gblvsby.fd/calvis.f", "max_stars_repo_name": "rgrumbine/marine_visibility", "max_stars_repo_head_hexsha": "78a8a6d1c169fdc30c84b139bd0a847c665f6839", "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": "sorc/omb_gblvsby.fd/calvis.f", "max_issues_repo_name": "rgrumbine/marine_visibility", "max_issues_repo_head_hexsha": "78a8a6d1c169fdc30c84b139bd0a847c665f6839", "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": "sorc/omb_gblvsby.fd/calvis.f", "max_forks_repo_name": "rgrumbine/marine_visibility", "max_forks_repo_head_hexsha": "78a8a6d1c169fdc30c84b139bd0a847c665f6839", "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": 46.2068965517, "max_line_length": 89, "alphanum_fraction": 0.4281094527, "num_tokens": 2182, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.93812402119614, "lm_q2_score": 0.6959583313396339, "lm_q1q2_score": 0.652895228381293}} {"text": " SUBROUTINE HLUGPROJ(PHI0, LAMBDA0, PHI, LAMBDA, X, Y)\nC\nC Find the projection onto the plane tangent to the globe at\nC (PHI0,LAMBDA0) of the point on the globe (PHI,LAMBDA).\nC The projected point is returned in Cartesian coordinate\nC (X,Y).\nC\n DOUBLE PRECISION PHI0, LAMBDA0, PHI, LAMBDA, X, Y\n DOUBLE PRECISION SIN0, COS0, SINP, COSP, SIND, COSD, DENOM\n DOUBLE PRECISION D2R\n PARAMETER (D2R = 0.017453292519943D0)\nC\n SIN0 = SIN(D2R*PHI0)\n COS0 = COS(D2R*PHI0)\n SINP = SIN(D2R*PHI)\n COSP = COS(D2R*PHI)\n SIND = SIN(D2R*(LAMBDA-LAMBDA0))\n COSD = COS(D2R*(LAMBDA-LAMBDA0))\n DENOM = SIN0*SINP + COS0*COSP*COSD\n X = (COSP*SIND)/DENOM\n Y = (COS0*SINP - SIN0*COSP*COSD)/DENOM\nC\n RETURN\n END\n\n", "meta": {"hexsha": "d86028e95640ed9e6694f659eb7b287ddfebf9c5", "size": 771, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ni/src/lib/hlu/gproj.f", "max_stars_repo_name": "tenomoto/ncl", "max_stars_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 210, "max_stars_repo_stars_event_min_datetime": "2016-11-24T09:05:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T19:15:32.000Z", "max_issues_repo_path": "ni/src/lib/hlu/gproj.f", "max_issues_repo_name": "tenomoto/ncl", "max_issues_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 156, "max_issues_repo_issues_event_min_datetime": "2017-09-22T09:56:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T07:02:21.000Z", "max_forks_repo_path": "ni/src/lib/hlu/gproj.f", "max_forks_repo_name": "tenomoto/ncl", "max_forks_repo_head_hexsha": "a87114a689a1566e9aa03d85bcf6dc7325b47633", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 58, "max_forks_repo_forks_event_min_datetime": "2016-12-14T00:15:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T09:13:00.000Z", "avg_line_length": 29.6538461538, "max_line_length": 64, "alphanum_fraction": 0.6342412451, "num_tokens": 306, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240073565739, "lm_q2_score": 0.6959583313396339, "lm_q1q2_score": 0.6528952187495316}} {"text": "! $UWHPSC/codes/openmp/normalize2.f90\n\n! Example of normalizing a vector using coarse-grain parallelism.\n\nprogram main\n \n use omp_lib\n implicit none\n integer, parameter :: n = 1000\n real(kind=8), dimension(n) :: x,y\n real(kind=8) :: norm,norm_thread,ynorm,ynorm_thread\n integer :: nthreads, points_per_thread,thread_num\n integer :: i,istart,iend\n\n ! Specify number of threads to use:\n nthreads = 1 ! need this value in serial mode\n !$ nthreads = 4 \n !$ call omp_set_num_threads(nthreads)\n !$ print \"('Using OpenMP with ',i3,' threads')\", nthreads\n\n ! Determine how many points to handle with each thread.\n ! Note that dividing two integers and assigning to an integer will\n ! round down if the result is not an integer. \n ! This, together with the min(...) in the definition of iend below,\n ! insures that all points will get distributed to some thread.\n points_per_thread = (n + nthreads - 1) / nthreads\n print *, \"points_per_thread = \",points_per_thread\n\n ! initialize x:\n do i=1,n\n x(i) = dble(i) ! convert to double float\n enddo\n\n norm = 0.d0\n ynorm = 0.d0\n\n !$omp parallel private(i,norm_thread, &\n !$omp istart,iend,thread_num,ynorm_thread) \n\n thread_num = 0 ! needed in serial mode\n !$ thread_num = omp_get_thread_num() ! unique for each thread\n\n ! Determine start and end index for the set of points to be \n ! handled by this thread:\n istart = thread_num * points_per_thread + 1\n iend = min((thread_num+1) * points_per_thread, n)\n\n !$omp critical\n print 201, thread_num, istart, iend\n !$omp end critical\n201 format(\"Thread \",i2,\" will take i = \",i6,\" through i = \",i6)\n\n norm_thread = 0.d0\n do i=istart,iend\n norm_thread = norm_thread + abs(x(i))\n enddo\n\n ! update global norm with value from each thread:\n !$omp critical\n norm = norm + norm_thread\n print *, \"norm updated to: \",norm\n !$omp end critical\n\n ! make sure all have updated norm before proceeding:\n !$omp barrier\n\n ynorm_thread = 0.d0\n do i=istart,iend\n y(i) = x(i) / norm\n ynorm_thread = ynorm_thread + abs(y(i))\n enddo\n\n ! update global ynorm with value from each thread:\n !$omp critical\n ynorm = ynorm + ynorm_thread\n print *, \"ynorm updated to: \",ynorm\n !$omp end critical\n !$omp barrier\n\n !$omp end parallel \n\n print *, \"norm of x = \",norm, \" n(n+1)/2 = \",n*(n+1)/2\n print *, 'ynorm should be 1.0: ynorm = ', ynorm\n\nend program main\n\n", "meta": {"hexsha": "e74fb8c1c62a16ab67499b3f6979a5ef6e24c303", "size": 2568, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/codes/openmp/normalize2.f90", "max_stars_repo_name": "philipwangdk/HPC", "max_stars_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "uwhpsc/codes/openmp/normalize2.f90", "max_issues_repo_name": "philipwangdk/HPC", "max_issues_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "uwhpsc/codes/openmp/normalize2.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": 29.5172413793, "max_line_length": 71, "alphanum_fraction": 0.6312305296, "num_tokens": 727, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031738057795402, "lm_q2_score": 0.8128673201042492, "lm_q1q2_score": 0.6528737390819456}} {"text": "!\n! Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.\n! See https://llvm.org/LICENSE.txt for license information.\n! SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception\n!\n! Module defining a user generic which resolves to a function returning\n! an array whose size is the SIZE of an array argument.\n!\nmodule square\ninterface square\n function square_s(x)\t\t!\"scalar\" version\n integer, intent(in) :: x\n integer :: square_s\n end function square_s\n function square_v(x)\t\t!\"vector\" version\n integer, dimension(:), intent(in) :: x\n integer, dimension(size(x)) :: square_v\n end function square_v\nendinterface\ninteger result(10)\ncommon/result/result\nendmodule square\n\nfunction square_s(x)\t\t!\"scalar\" version\n integer, intent(in) :: x\n integer :: square_s\n square_s = x * x\nend function square_s\n\nfunction square_v(x)\t\t!\"vector\" version\n integer, dimension(:), intent(in) :: x\n integer, dimension(size(x)) :: square_v\n square_v = x * x\nend function square_v\n\nsubroutine test_v(x)\n use square\n implicit none\n integer, dimension(:), intent(in) :: x\n integer, dimension(size(x)) :: gam1\n gam1=square(x)\n! print *, gam1\n result(1:3) = gam1(1:3)\nend subroutine test_v\n\nsubroutine test_s(x)\n use square\n implicit none\n integer :: x, gam1\n result(4) = square(x)\nend subroutine test_s\n\nprogram test\n interface\n\tsubroutine test_v(x)\n\tinteger, dimension(:), intent(in) :: x\n\tendsubroutine\n endinterface\n integer, dimension(3) :: inp = (/2,-3,4/)\n integer, dimension(4) :: expect = (/4,9,16,25/)\n integer result(10)\n common/result/result\n call test_v(inp)\n call test_s(-5)\n! print *, result(1:3), result(4)\n call check(result, expect, 4)\nend\n", "meta": {"hexsha": "ba6786432911422ef310101358fd2376897add7a", "size": 1759, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/f90_correct/src/md17.f90", "max_stars_repo_name": "abrahamtovarmob/flang", "max_stars_repo_head_hexsha": "bcd84b29df046b6d6574f0bfa34ea5059092615a", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 716, "max_stars_repo_stars_event_min_datetime": "2017-05-17T17:58:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T11:20:58.000Z", "max_issues_repo_path": "test/f90_correct/src/md17.f90", "max_issues_repo_name": "abrahamtovarmob/flang", "max_issues_repo_head_hexsha": "bcd84b29df046b6d6574f0bfa34ea5059092615a", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 794, "max_issues_repo_issues_event_min_datetime": "2017-05-18T19:27:40.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T23:22:11.000Z", "max_forks_repo_path": "test/f90_correct/src/md17.f90", "max_forks_repo_name": "abrahamtovarmob/flang", "max_forks_repo_head_hexsha": "bcd84b29df046b6d6574f0bfa34ea5059092615a", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 157, "max_forks_repo_forks_event_min_datetime": "2017-05-17T18:50:33.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T07:06:45.000Z", "avg_line_length": 25.8676470588, "max_line_length": 79, "alphanum_fraction": 0.6782262649, "num_tokens": 489, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673087708698, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.6528737242347559}} {"text": "subroutine check()\n use mpi\n use commondata\n implicit none\n integer :: i, j, k\n real(8) :: error1, error2\n real(8) :: total_error1, total_error2\n\n error1 = 0.0d0\n error2 = 0.0d0\n\n do k = 1, nz\n do j = 1, ny\n do i = 1, nx\n error1 = error1 + (u(i,j,k)-up(i,j,k))*(u(i,j,k)-up(i,j,k))+(v(i,j,k)-vp(i,j,k))*(v(i,j,k)-vp(i,j,k))\n error2 = error2 + u(i,j,k)*u(i,j,k)+v(i,j,k)*v(i,j,k) + w(i,j,k)*w(i,j,k)\n enddo\n enddo\n enddo\n\n up = u\n vp = v\n wp = w\n\n call MPI_Barrier(comm3d, rc)\n\n call MPI_ALLreduce(error1, total_error1, 1, MPI_REAL8, MPI_SUM, comm3d, rc)\n call MPI_ALLreduce(error2, total_error2, 1, MPI_REAL8, MPI_SUM, comm3d, rc)\n\n errorU = sqrt(total_error1)/sqrt(total_error2)\n\n if (rank3d == 0) then\n write(*,*) itc,' ',errorU\n endif\n\n return\nend subroutine check\n", "meta": {"hexsha": "c7a4fdf10138fc3b14cbf4fd1c6df0fc3f1988d1", "size": 901, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "MPI/Lid_driven_cavity/fortran/3d/mpi_3d_blocked/check.f90", "max_stars_repo_name": "cheryli/parallel", "max_stars_repo_head_hexsha": "a6b3f3ea479e64476a56f08e8c9e28c632a1b68b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-12-10T06:44:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-26T16:06:48.000Z", "max_issues_repo_path": "MPI/Lid_driven_cavity/fortran/3d/mpi_3d_blocked/check.f90", "max_issues_repo_name": "cheryli/parallel", "max_issues_repo_head_hexsha": "a6b3f3ea479e64476a56f08e8c9e28c632a1b68b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-12-11T12:50:24.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-11T14:11:56.000Z", "max_forks_repo_path": "MPI/Lid_driven_cavity/fortran/3d/mpi_3d_blocked/check.f90", "max_forks_repo_name": "cheryli/MGLC", "max_forks_repo_head_hexsha": "a6b3f3ea479e64476a56f08e8c9e28c632a1b68b", "max_forks_repo_licenses": ["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.7105263158, "max_line_length": 117, "alphanum_fraction": 0.538290788, "num_tokens": 330, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412808, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6528688158455715}} {"text": "SUBROUTINE PreProcessDiffStencilsZ(FineGrid,DiffStencils,GhostGridZ,gamma)\n! By Allan P. Engsig-Karup.\nUSE Precision\nUSE Constants\nUSE DataTypes\nIMPLICIT NONE\nTYPE (Diff_def), INTENT(OUT) :: DiffStencils\nTYPE (Level_def), INTENT(IN) :: FineGrid\nINTEGER :: GhostGridZ,STAT\nINTEGER :: rank, Nz, order, Nzp, Diff, gamma, i\nREAL(KIND=long), DIMENSION(:), ALLOCATABLE :: Stencil\nINTEGER, DIMENSION(:), ALLOCATABLE :: idx\n\n! TEMPORARY POINTERS/VARIABLES\nNz = FineGrid%Nz\n! Derivatives in z-direction\n! One-sided stencils near free surface.\n! One-side stencils near bottom, and if ghost points\n! are supported then the directional ghost point\n! is included in stencil.\nIF (GhostGridZ==0) THEN; Nzp = Nz; ELSE; Nzp = Nz+1; ENDIF\nALLOCATE( DiffStencils%StencilZ(Nzp,2*gamma+1,2),STAT=STAT)\nIF (STAT/=0) THEN\n\tPRINT*,'Error: Could not allocate memory for differentiation stencil (Z).'\n\tSTOP\nENDIF\nALLOCATE( Stencil(2*gamma+1) )\nALLOCATE( idx(2*gamma+1) )\nDO i=-gamma,gamma,1\n\tidx(i+gamma+1) = i\nEND DO\nDO order=1,2\n DO i = 1, Nzp\n\tIF (i-1=Nz-gamma+1) THEN\n\t\tDiff = i-(Nzp-gamma)\n\t\tCALL TaylorFDStencils1DArbitrary(gamma+Diff,gamma-Diff,order,Stencil,FineGrid%z(i+idx-Diff))\n\tELSE\n\t\tCALL TaylorFDStencils1DArbitrary(gamma,gamma,order,Stencil,FineGrid%z(i+idx))\n\tENDIF\n\tDiffStencils%StencilZ(i,:,order) = Stencil\n END DO\nEND DO\nDEALLOCATE(Stencil,idx)\nEND SUBROUTINE PreProcessDiffStencilsZ\n", "meta": {"hexsha": "ff04ad219e0f907b772ffa9ae7fd84e7c2825113", "size": 1531, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/functions/PreProcessDiffStencilsZ.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/PreProcessDiffStencilsZ.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/PreProcessDiffStencilsZ.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": 31.8958333333, "max_line_length": 94, "alphanum_fraction": 0.7472240366, "num_tokens": 543, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310357, "lm_q2_score": 0.7577943822145998, "lm_q1q2_score": 0.6528688151700642}} {"text": "C \nC MATRIX MULTIPLICATION - VERSION WITH CALL TO SAXPY\nC \nC DATA FLOW INTERPROCEDURAL ANALYSIS\nC SUMMARY OF EFFECTS ON A PROCEDURE\nC PARALLELIZATION OF LOOPS INCLUDING CALLS TO PROCEDURE\nC \n SUBROUTINE MM(N, A, B, C)\nC \n REAL*8 A(N,N), B(N,N), C(N,N), XAUX(0:127)\nC \n DO I = 1,N\n DO J = 1,N\n C(I,J) = 0.0\n ENDDO\n ENDDO\nC \n DO J = 1,N\n DO K = 1,N\n CALL SAXPY(N, C(1,J), A(1,K), B(K,J))\n ENDDO\n ENDDO\nC\n RETURN\n END\nC \nC COMPUTATION OF X = X + S*Y\nC \nC SUMMARY OF EFFECTS ON A PROCEDURE\nC \n SUBROUTINE SAXPY(N, X, Y, S)\nC \n INTEGER N\n REAL*8 X(N), Y(N), S\nC \n DO 10 I = 1, N\n X(I) = X(I) + S*Y(I)\n 10 CONTINUE\nC\n END\n", "meta": {"hexsha": "f8b6585e49b1eded34a8f1cd3c3b1c457c33fbb6", "size": 813, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "packages/PIPS/validation/Demo/SC95.sub/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/Demo/SC95.sub/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/Demo/SC95.sub/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": 19.8292682927, "max_line_length": 59, "alphanum_fraction": 0.4760147601, "num_tokens": 291, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310355, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6528688104574677}} {"text": "module type_ShallowWaterSolver\n\n use spherepack, only: &\n wp, & ! working precision\n ip, & ! integer precision\n PI, &\n Regularsphere\n\n ! Explicit typing only\n implicit none\n\n ! Everything is private unless stated otherwise\n private\n public :: ShallowWaterSolver\n\n ! Parameters confined to the module\n real(wp), parameter :: ZERO = 0.0_wp\n real(wp), parameter :: HALF = 0.5_wp\n real(wp), parameter :: ONE = 1.0_wp\n real(wp), parameter :: TWO = 2.0_wp\n \n type, extends(RegularSphere), public :: ShallowWaterSolver\n contains\n ! Type-bound procedures\n procedure :: spec_to_grid\n procedure :: grid_to_spec\n procedure :: get_vrtdivspec\n procedure :: get_uv\n procedure, nopass :: atanxy\n procedure, nopass :: get_initial_velocity\n procedure, nopass :: sine_transform\n procedure, nopass :: cosine_transform\n end type ShallowWaterSolver\n\ncontains\n\n ! Purpose:\n !\n ! Computes the initial unrotated longitudinal velocity\n ! See: section 3.3\n pure function get_initial_velocity(amp, thetad) result (return_value)\n\n ! Dummy arguments\n real(wp), intent(in) :: amp\n real(wp), intent(in) :: thetad\n real(wp) :: return_value\n\n ! Local variables\n real(wp) :: thetab, thetae, xe, x\n\n thetab = -PI/6\n thetae = PI/2\n xe = 3.0e-1_wp\n\n x = xe*(thetad-thetab)/(thetae-thetab)\n\n return_value = ZERO\n\n if (x <= ZERO .or. x >= xe) return\n\n return_value = amp*exp(-ONE /x-ONE/(xe-x)+4.0_wp/xe)\n\n end function get_initial_velocity\n\n pure function atanxy(x, y) &\n result (return_value)\n\n ! Dummy arguments\n real(wp), intent(in) :: x\n real(wp), intent(in) :: y\n real(wp) :: return_value\n\n return_value = ZERO\n\n if (x == ZERO .and. y == ZERO) return\n\n return_value = atan2(y, x)\n\n end function atanxy\n\n subroutine sine_transform(x)\n\n ! Dummy arguments\n real(wp), intent(inout) :: x(:)\n\n ! Local variables\n integer(ip) :: i, j\n real(wp) :: arg\n\n associate (n => size(x))\n\n arg = PI/(n+1)\n\n block\n real(wp) :: w(n)\n\n do j=1, n\n w(j) = ZERO\n do i=1, n\n w(j) = w(j)+x(i)*sin(real(i*j, kind=wp)*arg)\n end do\n end do\n\n x = TWO * w\n end block\n end associate\n\n end subroutine sine_transform\n\n pure function cosine_transform(theta, cf) &\n result (return_value)\n\n ! Dummy arguments\n real(wp), intent(in) :: theta\n real(wp), intent(in) :: cf(:)\n real(wp) :: return_value\n\n ! Local variables\n integer(ip) :: i\n\n return_value = ZERO\n\n do i=1, size(cf)\n return_value = return_value+cf(i)*cos(real(i, kind=wp)*theta)\n end do\n\n end function cosine_transform\n\n ! Purpose:\n !\n ! Converts complex spectral coefficients (dataspec) to\n ! gridded data array (datagrid).\n subroutine grid_to_spec(self, datagrid, dataspec)\n\n ! Dummy arguments\n class(ShallowWaterSolver), intent(inout) :: self\n real(wp), intent(in) :: datagrid(:, :)\n complex(wp), intent(out) :: dataspec(:)\n\n ! Local variables\n integer(ip) :: n, m\n\n associate (&\n nlat => size(datagrid, dim=2), &\n nlon => size(datagrid, dim=1) &\n )\n block\n real(wp) :: temp(nlat, nlon)\n\n ! Transpose data\n temp = transpose(datagrid)\n\n ! spherical harmonic analysis\n call self%perform_scalar_analysis(temp)\n\n associate (&\n ntrunc => self%TRIANGULAR_TRUNCATION_LIMIT, &\n a => self%workspace%scalar_coefficients%real_component, &\n b => self%workspace%scalar_coefficients%imaginary_component &\n )\n\n ! Fill complex array dataspec with result.\n dataspec = HALF * cmplx( &\n [((a(m, n), n=m, ntrunc+1), m=1, ntrunc+1)], &\n [((b(m, n), n=m, ntrunc+1), m=1, ntrunc+1)], &\n kind=wp)\n\n ! Reset constants\n a = ZERO\n b = ZERO\n end associate\n end block\n end associate\n\n end subroutine grid_to_spec\n\n ! Purpose:\n !\n ! Converts complex spectral coefficients (dataspec) to\n ! gridded data array (datagrid).\n !\n subroutine spec_to_grid(self, dataspec, datagrid)\n\n ! Dummy arguments\n class(ShallowWaterSolver), intent(inout) :: self\n real(wp), intent(inout) :: datagrid(:, :)\n complex(wp), intent(in) :: dataspec(:)\n\n ! Local variables\n integer(ip) :: n, m, nm\n\n associate (&\n nlat => size(datagrid, dim=2), &\n nlon => size(datagrid, dim=1) &\n )\n block\n real(wp) :: temp(nlat, nlon)\n\n ! fill two real arrays (a, b) with contents of dataspec.\n associate (&\n indxn => self%INDEX_DEGREE_N, &\n indxm => self%INDEX_ORDER_M, &\n a => self%workspace%scalar_coefficients%real_component, &\n b => self%workspace%scalar_coefficients%imaginary_component &\n )\n\n a = ZERO\n b = ZERO\n do nm=1, size(dataspec)\n n = indxn(nm) ! Set degree n\n m = indxm(nm) ! Set order m\n a(m + 1, n + 1) = TWO * real(dataspec(nm))\n b(m + 1, n + 1) = TWO * aimag(dataspec(nm))\n end do\n\n ! Perform spherical harmonic synthesis\n call self%perform_scalar_synthesis(temp)\n\n ! Reset coefficients\n a = ZERO\n b = ZERO\n end associate\n\n ! Transpose data\n datagrid = transpose(temp)\n end block\n end associate\n\n end subroutine spec_to_grid\n\n ! Purpose:\n !\n ! Calculate spectral coefficients of vorticity and divergence\n ! (vrtspec, divspec) given input gridded winds (ugrid, vgrid).\n !\n subroutine get_vrtdivspec(self, ugrid, vgrid, vrtspec, divspec)\n\n ! Dummy arguments\n class(ShallowWaterSolver), intent(inout) :: self\n real(wp), intent(in) :: ugrid(:, :)\n real(wp), intent(in) :: vgrid(:, :)\n complex(wp), intent(out) :: vrtspec(:)\n complex(wp), intent(out) :: divspec(:)\n\n ! Local variables\n real(wp) :: fn\n integer(ip) :: n, m ! Counters\n\n associate (&\n nlat => size(ugrid, dim=2), &\n nlon => size(ugrid, dim=1) &\n )\n block\n real(wp) :: v(nlat, nlon)\n real(wp) :: w(nlat, nlon)\n real(wp) :: sqnn(nlat)\n\n ! Transpose data.\n ! minus sign to account for difference between\n ! mathematical and geophysical spherical coords\n v = -transpose(vgrid)\n w = transpose(ugrid)\n\n ! Calculate vector spherical harmonic analysis.\n call self%vector_analysis_from_spherical_components(v, w)\n\n ! Multiply vector harmonic coefficients of winds by\n ! appropriate factors to convert into vorticity and\n ! divergence coefficients.\n associate (&\n ntrunc => self%TRIANGULAR_TRUNCATION_LIMIT, &\n nlat => self%NUMBER_OF_LATITUDES, &\n rsphere => self%RADIUS_OF_SPHERE, &\n a => self%workspace%scalar_coefficients%real_component, &\n b => self%workspace%scalar_coefficients%imaginary_component, &\n br => self%workspace%vector_coefficients%polar%real_component, &\n bi => self%workspace%vector_coefficients%polar%imaginary_component, &\n cr => self%workspace%vector_coefficients%azimuthal%real_component, &\n ci => self%workspace%vector_coefficients%azimuthal%imaginary_component &\n )\n\n do n=1, nlat\n fn = real(n - 1, kind=wp)\n sqnn(n) = sqrt(fn * (fn + ONE))\n end do\n\n a = ZERO\n b = ZERO\n do n=1, nlat\n a(:, n) = -(sqnn(n)/rsphere)*br(:, n)\n b(:, n) = -(sqnn(n)/rsphere)*bi(:, n)\n end do\n\n divspec = HALF * cmplx( &\n [((a(m, n), n=m, ntrunc+1), m=1, ntrunc+1)], &\n [((b(m, n), n=m, ntrunc+1), m=1, ntrunc+1)], &\n kind=wp)\n\n a = ZERO\n b = ZERO\n do n=1, nlat\n a(:, n) = (sqnn(n)/rsphere)*cr(:, n)\n b(:, n) = (sqnn(n)/rsphere)*ci(:, n)\n end do\n\n vrtspec = HALF * cmplx( &\n [((a(m, n), n=m, ntrunc+1), m=1, ntrunc+1)], &\n [((b(m, n), n=m, ntrunc+1), m=1, ntrunc+1)], &\n kind=wp)\n\n ! Reset coefficients\n a = ZERO\n b = ZERO\n br = ZERO\n bi = ZERO\n cr = ZERO\n ci = ZERO\n end associate\n end block\n end associate\n\n end subroutine get_vrtdivspec\n\n ! Purpose:\n !\n ! Given spectral coefficients of vorticity and divergence\n ! (vrtspec, divspec) compute gridded winds (ugrid, vgrid)\n !\n subroutine get_uv(self, vrtspec, divspec, ugrid, vgrid)\n\n ! Dummy arguments\n class(ShallowWaterSolver), intent(inout) :: self\n complex(wp), intent(in) :: vrtspec(:)\n complex(wp), intent(in) :: divspec(:)\n real(wp), intent(out) :: ugrid(:, :)\n real(wp), intent(out) :: vgrid(:, :)\n\n ! Local variables\n real(wp) :: fn\n integer(ip) :: n, m, nm ! Counters\n\n associate (&\n nlat => size(ugrid, dim=2), &\n nlon => size(ugrid, dim=1) &\n )\n block\n real(wp) :: v(nlat, nlon)\n real(wp) :: w(nlat, nlon)\n real(wp) :: isqnn(nlat)\n\n ! Multiply spectral coefficients of vorticity and divergence\n ! by appropriate factors to convert them into vector harmonic\n ! coefficients of winds.\n associate (&\n indxn => self%INDEX_DEGREE_N, &\n indxm => self%INDEX_ORDER_M, &\n nlat => self%NUMBER_OF_LATITUDES, &\n rsphere => self%RADIUS_OF_SPHERE, &\n a => self%workspace%scalar_coefficients%real_component, &\n b => self%workspace%scalar_coefficients%imaginary_component, &\n br => self%workspace%vector_coefficients%polar%real_component, &\n bi => self%workspace%vector_coefficients%polar%imaginary_component, &\n cr => self%workspace%vector_coefficients%azimuthal%real_component, &\n ci => self%workspace%vector_coefficients%azimuthal%imaginary_component &\n )\n\n isqnn(1) = ZERO\n do n=2, nlat\n fn = real(n - 1, kind=wp)\n isqnn(n) = rsphere/sqrt(fn*(fn+ONE))\n end do\n\n ! Preset real harmonic coefficients to 0.0\n a = ZERO\n b = ZERO\n\n ! Preset polar coefficients to 0.0\n br = ZERO\n bi = ZERO\n\n do nm=1, size(divspec)\n n = indxn(nm) ! Set degree n\n m = indxm(nm) ! Set order m\n a(m + 1, n + 1) = -TWO * real(divspec(nm))\n b(m + 1, n + 1) = -TWO * aimag(divspec(nm))\n end do\n\n do n=1, nlat\n br(:, n) = isqnn(n)*a(:, n)\n bi(:, n) = isqnn(n)*b(:, n)\n end do\n\n ! Preset azimuthal coefficients to 0.0\n cr = ZERO\n ci = ZERO\n\n do nm=1, size(divspec)\n n = indxn(nm) ! Set degree n\n m = indxm(nm) ! Set order m\n a(m + 1, n + 1) = TWO * real(vrtspec(nm))\n b(m + 1, n + 1) = TWO * aimag(vrtspec(nm))\n end do\n\n do n=1, nlat\n cr(:, n) = isqnn(n)*a(:, n)\n ci(:, n) = isqnn(n)*b(:, n)\n end do\n\n ! Compute vector harmonic synthesis to get winds on grid.\n call self%perform_vector_synthesis(v, w)\n\n ! Reset coefficients\n a = ZERO\n b = ZERO\n br = ZERO\n bi = ZERO\n cr = ZERO\n ci = ZERO\n end associate\n\n ! Transpose data\n ! minus sign to account for differences\n ! between mathematical and geophysical spherical coords.\n vgrid = -transpose(v)\n ugrid = transpose(w)\n end block\n end associate\n\n end subroutine get_uv\n\nend module type_ShallowWaterSolver\n", "meta": {"hexsha": "d4be5bc31da4a35f511d4350dabda1278d758bca", "size": 14304, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/type_ShallowWaterSolver.f90", "max_stars_repo_name": "jlokimlin/spherepack4.1", "max_stars_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-06-28T14:01:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T21:59:28.000Z", "max_issues_repo_path": "examples/type_ShallowWaterSolver.f90", "max_issues_repo_name": "jlokimlin/spherepack4.1", "max_issues_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2016-05-07T23:00:35.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-22T23:52:30.000Z", "max_forks_repo_path": "examples/type_ShallowWaterSolver.f90", "max_forks_repo_name": "jlokimlin/spherepack4.1", "max_forks_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-06-28T14:03:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T12:53:54.000Z", "avg_line_length": 33.1111111111, "max_line_length": 92, "alphanum_fraction": 0.4578439597, "num_tokens": 3304, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.86153820232079, "lm_q2_score": 0.7577943822145997, "lm_q1q2_score": 0.6528688097819599}} {"text": "!----------------------Subroutine--------------------------------------!\n!\n SUBROUTINE POLINT( XA,YA,N,X,Y,DY,IERR )\n!\n!-------------------------Disclaimer-----------------------------------!\n!\n! This material was prepared as an account of work sponsored by\n! an agency of the United States Government. Neither the\n! United States Government nor the United States Department of\n! Energy, nor Battelle, nor any of their employees, makes any\n! warranty, express or implied, or assumes any legal liability or\n! responsibility for the accuracy, completeness, or usefulness\n! of any information, apparatus, product, software or process\n! disclosed, or represents that its use would not infringe\n! privately owned rights.\n!\n!----------------------Acknowledgement---------------------------------!\n!\n! This software and its documentation were produced with Government\n! support under Contract Number DE-AC06-76RLO-1830 awarded by the\n! United Department of Energy. The Government retains a paid-up\n! non-exclusive, irrevocable worldwide license to reproduce,\n! prepare derivative works, perform publicly and display publicly\n! by or for the Government, including the right to distribute to\n! other Government contractors.\n!\n!---------------------Copyright Notices--------------------------------!\n!\n! Copyright Battelle Memorial Institute, 1996\n! All Rights Reserved.\n!\n!----------------------Description-------------------------------------!\n!\n! Given arrays XA and YA, each of length N, and given a value X,\n! this routine returns a value Y, and an error estimate DY.\n! If P(X) is the polynomial of degree N-1 such that \n! P(XA(I)) = YA(I), I = 1,N, then the returned value Y = P(X).\n!\n! Press, W.H., B.P. Flannery, S.A. Teukolsky, and W.T. Vetterling.\n! 1986. Numerical Recipes, The Art of Scientific Computing.\n! Cambridge University Press, Cambridge.\n!\n!----------------------Authors-----------------------------------------!\n!\n! Written by MD White, Battelle, February, 1999.\n! Last Modified by Mark White, Battelle, February 19, 1999.\n! $Id: rombint.F 1080 2017-03-14 16:22:02Z d3c002 $\n!\n!----------------------Implicit Double Precision-----------------------!\n!\n IMPLICIT REAL*8 (A-H,O-Z)\n IMPLICIT INTEGER (I-N)\n!\n!----------------------Parameter Statements----------------------------!\n!\n PARAMETER( NMAX=10, EPSL=1.D-14 )\n REAL*8 XA(N),YA(N),C(NMAX),D(NMAX)\n!\n!----------------------Executable Lines--------------------------------!\n!\n IERR = 0\n NS = 1\n DIF = ABS(X-XA(1))\n!\n!--- Find the index NS of the closest table entry ---\n!\n DO 11 I = 1,N\n DIFT = ABS(X-XA(I))\n IF( DIFT.LT.DIF ) THEN\n NS = I\n DIF = DIFT\n ENDIF\n!\n!--- Initialize the tableau fo C's and D's ---\n!\n C(I) = YA(I)\n D(I) = YA(I)\n 11 CONTINUE\n!\n!--- Initial approximation to Y ---\n!\n Y = YA(NS)\n NS = NS-1\n!\n!--- Loop over the columns in the tableau and \n! update the C's and D's ---\n!\n DO 13 M = 1,N-1\n DO 12 I = 1,N-M\n HO = XA(I)-X\n HP = XA(I+M)-X\n W = C(I+1)-D(I)\n DEN = HO-HP\n!\n!--- Exit subroutine if two input XA's are identical, \n! within roundoff ---\n!\n IF( ABS( DEN )/EPSL.LT.EPSL ) THEN\n IERR = 1\n RETURN\n ENDIF\n DEN = W/DEN\n!\n!--- Update C's and D's ---\n!\n D(I) = HP*DEN\n C(I) = HO*DEN\n 12 CONTINUE\n!\n!--- After each column in the tableau is completed, \n! decide which direction C or D to add the accumulating \n! value of Y, (i.e., which path to take\n! through the tableau - forking up or down). \n! Do this in such a way as to take the most \"straight line\" \n! route through the tableau to its apex, updating NS accordingly \n! to keep track. This route keeps the partial approximations \n! centered (insofar as possible) on the target X. The\n! last DY added is thus the error indication. ---\n!\n IF( 2*NS.LT.N-M ) THEN\n DY = C(NS+1)\n ELSE\n DY = D(NS)\n NS = NS-1\n ENDIF\n Y = Y+DY\n 13 CONTINUE\n!\n!--- End of POLINT group\n!\n RETURN\n END\n\n!----------------------Subroutine--------------------------------------!\n!\n SUBROUTINE QROMB( FUNC,V,A,B,SSX,IERR,IV )\n!\n!-------------------------Disclaimer-----------------------------------!\n!\n! This material was prepared as an account of work sponsored by\n! an agency of the United States Government. Neither the\n! United States Government nor the United States Department of\n! Energy, nor Battelle, nor any of their employees, makes any\n! warranty, express or implied, or assumes any legal liability or\n! responsibility for the accuracy, completeness, or usefulness\n! of any information, apparatus, product, software or process\n! disclosed, or represents that its use would not infringe\n! privately owned rights.\n!\n!----------------------Acknowledgement---------------------------------!\n!\n! This software and its documentation were produced with Government\n! support under Contract Number DE-AC06-76RLO-1830 awarded by the\n! United Department of Energy. The Government retains a paid-up\n! non-exclusive, irrevocable worldwide license to reproduce,\n! prepare derivative works, perform publicly and display publicly\n! by or for the Government, including the right to distribute to\n! other Government contractors.\n!\n!---------------------Copyright Notices--------------------------------!\n!\n! Copyright Battelle Memorial Institute, 1996\n! All Rights Reserved.\n!\n!----------------------Description-------------------------------------!\n!\n! Returns as S the integral of the function FUNC from A to B.\n! Integration is performed by Romberg's method of order 2K, where\n! e.g., K=2 is Simpson's rule.\n!\n! Press, W.H., B.P. Flannery, S.A. Teukolsky, and W.T. Vetterling.\n! 1986. Numerical Recipes, The Art of Scientific Computing.\n! Cambridge University Press, Cambridge.\n!\n!----------------------Authors-----------------------------------------!\n!\n! Written by MD White, Battelle, November 19, 1999.\n! Last Modified by Mark White, Battelle, November 19, 1999.\n! $Id: rombint.F 1080 2017-03-14 16:22:02Z d3c002 $\n!\n!----------------------Implicit Double Precision-----------------------!\n!\n IMPLICIT REAL*8 (A-H,O-Z)\n IMPLICIT INTEGER (I-N)\n!\n!----------------------Parameter Statements----------------------------!\n!\n PARAMETER( EPS=1.D-6, EPSL=1.D-14 )\n PARAMETER( JMAX=20, JMAXP=JMAX+1, K=5, KM=K-1 )\n!\n!----------------------Type Declarations-------------------------------!\n!\n REAL*8 S(JMAXP),H(JMAXP),V(10)\n INTEGER IV(10)\n EXTERNAL FUNC\n!\n!----------------------Executable Lines--------------------------------!\n!\n IERR = 0\n ZERO = 0.D+0\n!\n!--- S and H store the successive trapezodial approximations and their\n! relative step-sizes. ---\n!\n H(1) = 1.D+0\n DO 10 J = 1,JMAX\n CALL TRAPZD( FUNC,V,A,B,S(J),J,IV )\n IF( J.GE.K ) THEN\n CALL POLINT( H(J-KM),S(J-KM),K,ZERO,SSX,DSS,IERR )\n IF( (ABS(DSS)-EPS*ABS(SSX))/EPSL.LT.EPSL ) RETURN\n ENDIF\n S(J+1) = S(J)\n H(J+1) = 2.5D-1*H(J)\n 10 CONTINUE\n IERR = 1\n!\n!--- End of QROMB group\n!\n RETURN\n END\n\n!----------------------Subroutine--------------------------------------!\n!\n SUBROUTINE QSIMP( FUNC,V,A,B,S,IERR )\n!\n!-------------------------Disclaimer-----------------------------------!\n!\n! This material was prepared as an account of work sponsored by\n! an agency of the United States Government. Neither the\n! United States Government nor the United States Department of\n! Energy, nor Battelle, nor any of their employees, makes any\n! warranty, express or implied, or assumes any legal liability or\n! responsibility for the accuracy, completeness, or usefulness\n! of any information, apparatus, product, software or process\n! disclosed, or represents that its use would not infringe\n! privately owned rights.\n!\n!----------------------Acknowledgement---------------------------------!\n!\n! This software and its documentation were produced with Government\n! support under Contract Number DE-AC06-76RLO-1830 awarded by the\n! United Department of Energy. The Government retains a paid-up\n! non-exclusive, irrevocable worldwide license to reproduce,\n! prepare derivative works, perform publicly and display publicly\n! by or for the Government, including the right to distribute to\n! other Government contractors.\n!\n!---------------------Copyright Notices--------------------------------!\n!\n! Copyright Battelle Memorial Institute, 1996\n! All Rights Reserved.\n!\n!----------------------Description-------------------------------------!\n!\n! Returns as S the integral of the function FUNC from A to B.\n! Integration is performed by Simpson's rule.\n!\n! Press, W.H., B.P. Flannery, S.A. Teukolsky, and W.T. Vetterling.\n! 1986. Numerical Recipes, The Art of Scientific Computing.\n! Cambridge University Press, Cambridge.\n!\n!----------------------Authors-----------------------------------------!\n!\n! Written by MD White, Battelle, February, 1999.\n! Last Modified by Mark White, Battelle, February 19, 1999.\n! $Id: rombint.F 1080 2017-03-14 16:22:02Z d3c002 $\n!\n!----------------------Implicit Double Precision-----------------------!\n!\n IMPLICIT REAL*8 (A-H,O-Z)\n IMPLICIT INTEGER (I-N)\n!\n!----------------------Parameter Statements----------------------------!\n!\n PARAMETER( EPS=1.D-6, JMAX=20 )\n!\n!-------------------------Type Statements------------------------------!\n!\n EXTERNAL FUNC\n REAL*8 V(10)\n INTEGER IV(10)\n!\n!----------------------Executable Lines--------------------------------!\n!\n OST = 1.D+20\n OS = -1.D+20\n DO 100 J = 1,JMAX\n CALL TRAPZD( FUNC,V,A,B,ST,J,IV )\n S = (4.D+0*ST-OST)/3.D+0\n IF( ABS(S-OS).LT.EPS*ABS(OS)) GOTO 200\n OS = S\n OST = ST\n 100 CONTINUE\n IERR = 1\n 200 CONTINUE\n!\n!--- End of QSIMP group\n!\n RETURN\n END\n\n!----------------------Subroutine--------------------------------------!\n!\n SUBROUTINE TRAPZD( FUNC,V,A,B,S,N,IV )\n!\n!-------------------------Disclaimer-----------------------------------!\n!\n! This material was prepared as an account of work sponsored by\n! an agency of the United States Government. Neither the\n! United States Government nor the United States Department of\n! Energy, nor Battelle, nor any of their employees, makes any\n! warranty, express or implied, or assumes any legal liability or\n! responsibility for the accuracy, completeness, or usefulness\n! of any information, apparatus, product, software or process\n! disclosed, or represents that its use would not infringe\n! privately owned rights.\n!\n!----------------------Acknowledgement---------------------------------!\n!\n! This software and its documentation were produced with Government\n! support under Contract Number DE-AC06-76RLO-1830 awarded by the\n! United Department of Energy. The Government retains a paid-up\n! non-exclusive, irrevocable worldwide license to reproduce,\n! prepare derivative works, perform publicly and display publicly\n! by or for the Government, including the right to distribute to\n! other Government contractors.\n!\n!---------------------Copyright Notices--------------------------------!\n!\n! Copyright Battelle Memorial Institute, 1996\n! All Rights Reserved.\n!\n!----------------------Description-------------------------------------!\n!\n! This routine computes the N'th stage of refinement of an\n! extended trapezoid rule.\n!\n! Press, W.H., B.P. Flannery, S.A. Teukolsky, and W.T. Vetterling.\n! 1986. Numerical Recipes, The Art of Scientific Computing.\n! Cambridge University Press, Cambridge.\n!\n!----------------------Authors-----------------------------------------!\n!\n! Written by MD White, Battelle, February, 1999.\n! Last Modified by Mark White, Battelle, February 19, 1999.\n! $Id: rombint.F 1080 2017-03-14 16:22:02Z d3c002 $\n!\n!----------------------Implicit Double Precision-----------------------!\n!\n IMPLICIT REAL*8 (A-H,O-Z)\n IMPLICIT INTEGER (I-N)\n!\n!-------------------------Type Statements------------------------------!\n!\n EXTERNAL FUNC\n REAL*8 V(10)\n INTEGER IV(10)\n SAVE IT\n!\n!----------------------Executable Lines--------------------------------!\n!\n IF( N.EQ.1 ) THEN\n S = 5.D-1*(B-A)*(FUNC(A,V,IV)+FUNC(B,V,IV))\n!\n!--- IT is the number of points to be added on the next call ---\n!\n IT = 1\n ELSE\n REALX = REAL(IT)\n TNM = REALX\n!\n!--- Spacing of the points to be added. ---\n!\n DEL = (B-A)/TNM\n X = A + 5.D-1*DEL\n SUM = 0.D+0\n DO 100 J = 1,IT\n SUM = SUM + FUNC(X,V,IV)\n X = X + DEL\n 100 CONTINUE\n!\n!--- Replace S by its refined value ---\n!\n S = 5.D-1*(S+(B-A)*SUM/TNM)\n IT = 2*IT\n ENDIF\n!\n!--- End of TRAPZD group\n!\n RETURN\n END\n\n!----------------------Function----------------------------------------!\n!\n FUNCTION ADRM( TMX,V,IV )\n!\n!-------------------------Disclaimer-----------------------------------!\n!\n! This material was prepared as an account of work sponsored by\n! an agency of the United States Government. Neither the\n! United States Government nor the United States Department of\n! Energy, nor Battelle, nor any of their employees, makes any\n! warranty, express or implied, or assumes any legal liability or\n! responsibility for the accuracy, completeness, or usefulness\n! of any information, apparatus, product, software or process\n! disclosed, or represents that its use would not infringe\n! privately owned rights.\n!\n!----------------------Acknowledgement---------------------------------!\n!\n! This software and its documentation were produced with Government\n! support under Contract Number DE-AC06-76RLO-1830 awarded by the\n! United Department of Energy. The Government retains a paid-up\n! non-exclusive, irrevocable worldwide license to reproduce,\n! prepare derivative works, perform publicly and display publicly\n! by or for the Government, including the right to distribute to\n! other Government contractors.\n!\n!---------------------Copyright Notices--------------------------------!\n!\n! Copyright Battelle Memorial Institute, 1996\n! All Rights Reserved.\n!\n!----------------------Description-------------------------------------!\n!\n! Inverse van Genuchten function.\n!\n!----------------------Authors-----------------------------------------!\n!\n! Written by MD White, Battelle, February, 1999.\n! Last Modified by Mark White, Battelle, February 19, 1999.\n! $Id: rombint.F 1080 2017-03-14 16:22:02Z d3c002 $\n!\n!----------------------Implicit Double Precision-----------------------!\n!\n IMPLICIT REAL*8 (A-H,O-Z)\n IMPLICIT INTEGER (I-N)\n!\n!----------------------Parameter Statements----------------------------!\n!\n PARAMETER( SMALL=1.D-20 )\n!\n!-------------------------Type Statements------------------------------!\n!\n REAL*8 V(10)\n INTEGER IV(10)\n!\n!----------------------Executable Lines--------------------------------!\n!\n ADRM = 0.D+0\n FCTX = 1.D+0\n DO 200 N = 1,IV(1)\n REALX = REAL(N-1)\n IF( N.GT.1 ) FCTX = FCTX*REALX\n REALX = REAL(IV(1))\n ADRM = ADRM + ((V(1)*REALX*TMX)**(N-1))/FCTX\n 200 CONTINUE\n ADRM = ADRM*V(1)*V(2)*EXP(-V(1)*REALX*TMX)\n!\n!--- End of ADRM group\n!\n RETURN\n END\n\n!----------------------Function----------------------------------------!\n!\n FUNCTION HKI( SLX,V,IV )\n!\n!-------------------------Disclaimer-----------------------------------!\n!\n! This material was prepared as an account of work sponsored by\n! an agency of the United States Government. Neither the\n! United States Government nor the United States Department of\n! Energy, nor Battelle, nor any of their employees, makes any\n! warranty, express or implied, or assumes any legal liability or\n! responsibility for the accuracy, completeness, or usefulness\n! of any information, apparatus, product, software or process\n! disclosed, or represents that its use would not infringe\n! privately owned rights.\n!\n!----------------------Acknowledgement---------------------------------!\n!\n! This software and its documentation were produced with Government\n! support under Contract Number DE-AC06-76RLO-1830 awarded by the\n! United Department of Energy. The Government retains a paid-up\n! non-exclusive, irrevocable worldwide license to reproduce,\n! prepare derivative works, perform publicly and display publicly\n! by or for the Government, including the right to distribute to\n! other Government contractors.\n!\n!---------------------Copyright Notices--------------------------------!\n!\n! Copyright Battelle Memorial Institute, 1996\n! All Rights Reserved.\n!\n!----------------------Description-------------------------------------!\n!\n! Inverse Haverkamp function.\n!\n!----------------------Authors-----------------------------------------!\n!\n! Written by MD White, PNNL, 17 December 2002.\n! Last Modified by Mark White, PNNL, 17 December 2002.\n! $Id: rombint.F 1080 2017-03-14 16:22:02Z d3c002 $\n!\n!----------------------Implicit Double Precision-----------------------!\n!\n IMPLICIT REAL*8 (A-H,O-Z)\n IMPLICIT INTEGER (I-N)\n!\n!----------------------Parameter Statements----------------------------!\n!\n PARAMETER( EPSL=1.D-14, SMALL=1.D-20 )\n!\n!-------------------------Type Statements------------------------------!\n!\n REAL*8 V(10)\n INTEGER IV(10)\n!\n!----------------------Executable Lines--------------------------------!\n!\n IF( (1.D+0-SLX).LT.EPSL ) THEN\n HKI = V(1)\n ELSE\n HKI = V(1) + V(5)*((V(2)*(1.D+0-SLX)/(SLX+SMALL))**\n & (1.D+0/V(3)))\n ENDIF\n!\n!--- End of HKI group\n!\n RETURN\n END\n\n!----------------------Function----------------------------------------!\n!\n FUNCTION SPLNI( SLX,V,IV )\n!\n!-------------------------Disclaimer-----------------------------------!\n!\n! This material was prepared as an account of work sponsored by\n! an agency of the United States Government. Neither the\n! United States Government nor the United States Department of\n! Energy, nor Battelle, nor any of their employees, makes any\n! warranty, express or implied, or assumes any legal liability or\n! responsibility for the accuracy, completeness, or usefulness\n! of any information, apparatus, product, software or process\n! disclosed, or represents that its use would not infringe\n! privately owned rights.\n!\n!----------------------Acknowledgement---------------------------------!\n!\n! This software and its documentation were produced with Government\n! support under Contract Number DE-AC06-76RLO-1830 awarded by the\n! United Department of Energy. The Government retains a paid-up\n! non-exclusive, irrevocable worldwide license to reproduce,\n! prepare derivative works, perform publicly and display publicly\n! by or for the Government, including the right to distribute to\n! other Government contractors.\n!\n!---------------------Copyright Notices--------------------------------!\n!\n! Copyright Battelle Memorial Institute, 1996\n! All Rights Reserved.\n!\n!----------------------Description-------------------------------------!\n!\n! Inverse cubic-spline or log-cubic-spline tabular function.\n!\n!----------------------Authors-----------------------------------------!\n!\n! Written by MD White, PNNL, 17 December 2002.\n! Last Modified by Mark White, PNNL, 17 December 2002.\n! $Id: rombint.F 1080 2017-03-14 16:22:02Z d3c002 $\n!\n!----------------------Implicit Double Precision-----------------------!\n!\n IMPLICIT REAL*8 (A-H,O-Z)\n IMPLICIT INTEGER (I-N)\n!\n!-------------------------Type Statements------------------------------!\n!\n REAL*8 V(10)\n INTEGER IV(10)\n EXTERNAL FSPLNX\n!\n!----------------------Executable Lines--------------------------------!\n!\n SPLNI = FSPLNX( SLX,IV(1),IV(2) )\n!\n!--- End of SPLNI group\n!\n RETURN\n END\n\n!----------------------Function----------------------------------------!\n!\n FUNCTION TBLI( SLX,V,IV )\n!\n!-------------------------Disclaimer-----------------------------------!\n!\n! This material was prepared as an account of work sponsored by\n! an agency of the United States Government. Neither the\n! United States Government nor the United States Department of\n! Energy, nor Battelle, nor any of their employees, makes any\n! warranty, express or implied, or assumes any legal liability or\n! responsibility for the accuracy, completeness, or usefulness\n! of any information, apparatus, product, software or process\n! disclosed, or represents that its use would not infringe\n! privately owned rights.\n!\n!----------------------Acknowledgement---------------------------------!\n!\n! This software and its documentation were produced with Government\n! support under Contract Number DE-AC06-76RLO-1830 awarded by the\n! United Department of Energy. The Government retains a paid-up\n! non-exclusive, irrevocable worldwide license to reproduce,\n! prepare derivative works, perform publicly and display publicly\n! by or for the Government, including the right to distribute to\n! other Government contractors.\n!\n!---------------------Copyright Notices--------------------------------!\n!\n! Copyright Battelle Memorial Institute, 1996\n! All Rights Reserved.\n!\n!----------------------Description-------------------------------------!\n!\n! Inverse linear or log-linear tabular function.\n!\n!----------------------Authors-----------------------------------------!\n!\n! Written by MD White, PNNL, 17 December 2002.\n! Last Modified by Mark White, PNNL, 17 December 2002.\n! $Id: rombint.F 1080 2017-03-14 16:22:02Z d3c002 $\n!\n!----------------------Implicit Double Precision-----------------------!\n!\n IMPLICIT REAL*8 (A-H,O-Z)\n IMPLICIT INTEGER (I-N)\n!\n!-------------------------Type Statements------------------------------!\n!\n REAL*8 V(10)\n INTEGER IV(10)\n EXTERNAL FNTBLX\n!\n!----------------------Executable Lines--------------------------------!\n!\n TBLI = FNTBLX( SLX,IV(1),IV(2),IV(3) )\n!\n!--- End of TBLI group\n!\n RETURN\n END\n\n!----------------------Function----------------------------------------!\n!\n FUNCTION VGI( SLX,V,IV )\n!\n!-------------------------Disclaimer-----------------------------------!\n!\n! This material was prepared as an account of work sponsored by\n! an agency of the United States Government. Neither the\n! United States Government nor the United States Department of\n! Energy, nor Battelle, nor any of their employees, makes any\n! warranty, express or implied, or assumes any legal liability or\n! responsibility for the accuracy, completeness, or usefulness\n! of any information, apparatus, product, software or process\n! disclosed, or represents that its use would not infringe\n! privately owned rights.\n!\n!----------------------Acknowledgement---------------------------------!\n!\n! This software and its documentation were produced with Government\n! support under Contract Number DE-AC06-76RLO-1830 awarded by the\n! United Department of Energy. The Government retains a paid-up\n! non-exclusive, irrevocable worldwide license to reproduce,\n! prepare derivative works, perform publicly and display publicly\n! by or for the Government, including the right to distribute to\n! other Government contractors.\n!\n!---------------------Copyright Notices--------------------------------!\n!\n! Copyright Battelle Memorial Institute, 1996\n! All Rights Reserved.\n!\n!----------------------Description-------------------------------------!\n!\n! Inverse van Genuchten function.\n!\n!----------------------Authors-----------------------------------------!\n!\n! Written by MD White, Battelle, February, 1999.\n! Last Modified by Mark White, Battelle, February 19, 1999.\n! $Id: rombint.F 1080 2017-03-14 16:22:02Z d3c002 $\n!\n!----------------------Implicit Double Precision-----------------------!\n!\n IMPLICIT REAL*8 (A-H,O-Z)\n IMPLICIT INTEGER (I-N)\n!\n!----------------------Parameter Statements----------------------------!\n!\n PARAMETER( SMALL=1.D-20 )\n!\n!-------------------------Type Statements------------------------------!\n!\n REAL*8 V(10)\n INTEGER IV(10)\n!\n!----------------------Executable Lines--------------------------------!\n!\n CNX = V(1)\n CMX = V(2)\n VGI = (-1.D+0 + (1.D+0/(SLX+SMALL))**(1.D+0/CMX))**(1.D+0/CNX)\n!\n!--- End of VGI group\n!\n RETURN\n END\n\n!----------------------Function----------------------------------------!\n!\n FUNCTION VGTI( SLX,V,IV )\n!\n!-------------------------Disclaimer-----------------------------------!\n!\n! This material was prepared as an account of work sponsored by\n! an agency of the United States Government. Neither the\n! United States Government nor the United States Department of\n! Energy, nor Battelle, nor any of their employees, makes any\n! warranty, express or implied, or assumes any legal liability or\n! responsibility for the accuracy, completeness, or usefulness\n! of any information, apparatus, product, software or process\n! disclosed, or represents that its use would not infringe\n! privately owned rights.\n!\n!----------------------Acknowledgement---------------------------------!\n!\n! This software and its documentation were produced with Government\n! support under Contract Number DE-AC06-76RLO-1830 awarded by the\n! United Department of Energy. The Government retains a paid-up\n! non-exclusive, irrevocable worldwide license to reproduce,\n! prepare derivative works, perform publicly and display publicly\n! by or for the Government, including the right to distribute to\n! other Government contractors.\n!\n!---------------------Copyright Notices--------------------------------!\n!\n! Copyright Battelle Memorial Institute, 1996\n! All Rights Reserved.\n!\n!----------------------Description-------------------------------------!\n!\n! Inverse van Genuchten function.\n!\n!----------------------Authors-----------------------------------------!\n!\n! Written by MD White, Battelle, February, 1999.\n! Last Modified by Mark White, Battelle, February 19, 1999.\n! $Id: rombint.F 1080 2017-03-14 16:22:02Z d3c002 $\n!\n!----------------------Implicit Double Precision-----------------------!\n!\n IMPLICIT REAL*8 (A-H,O-Z)\n IMPLICIT INTEGER (I-N)\n!\n!----------------------Parameter Statements----------------------------!\n!\n PARAMETER( SMALL=1.D-20 )\n!\n!-------------------------Type Statements------------------------------!\n!\n REAL*8 V(10)\n INTEGER IV(10)\n!\n!----------------------Executable Lines--------------------------------!\n!\n CNX = V(1)\n CMX = V(2)\n CRX = V(3)\n VGTI = (-1.D+0 + (1.D+0/(SLX+SMALL))**(1.D+0/CMX))**(1.D+0/CNX)\n VGTI = VGTI*SLX/((-1.D+0 + (-1.D+0 + SLX)*CRX)**2)\n!\n!--- End of VGTI group\n!\n RETURN\n END\n\n!----------------------Function----------------------------------------!\n!\n FUNCTION BCI( SLX,V,IV )\n!\n!-------------------------Disclaimer-----------------------------------!\n!\n! This material was prepared as an account of work sponsored by\n! an agency of the United States Government. Neither the\n! United States Government nor the United States Department of\n! Energy, nor Battelle, nor any of their employees, makes any\n! warranty, express or implied, or assumes any legal liability or\n! responsibility for the accuracy, completeness, or usefulness\n! of any information, apparatus, product, software or process\n! disclosed, or represents that its use would not infringe\n! privately owned rights.\n!\n!----------------------Acknowledgement---------------------------------!\n!\n! This software and its documentation were produced with Government\n! support under Contract Number DE-AC06-76RLO-1830 awarded by the\n! United Department of Energy. The Government retains a paid-up\n! non-exclusive, irrevocable worldwide license to reproduce,\n! prepare derivative works, perform publicly and display publicly\n! by or for the Government, including the right to distribute to\n! other Government contractors.\n!\n!---------------------Copyright Notices--------------------------------!\n!\n! Copyright Battelle Memorial Institute, 1996\n! All Rights Reserved.\n!\n!----------------------Description-------------------------------------!\n!\n! Inverse Brooks-Corey function.\n!\n!----------------------Authors-----------------------------------------!\n!\n! Written by MD White, Battelle, February, 1999.\n! Last Modified by Mark White, Battelle, February 19, 1999.\n! $Id: rombint.F 1080 2017-03-14 16:22:02Z d3c002 $\n!\n!----------------------Implicit Double Precision-----------------------!\n!\n IMPLICIT REAL*8 (A-H,O-Z)\n IMPLICIT INTEGER (I-N)\n!\n!----------------------Parameter Statements----------------------------!\n!\n PARAMETER( EPSL=1.D-14 )\n!\n!-------------------------Type Statements------------------------------!\n!\n REAL*8 V(10)\n INTEGER IV(10)\n!\n!----------------------Executable Lines--------------------------------!\n!\n CPX = V(1)\n CLX = V(2)\n IF( (1.D+0-SLX).LT.EPSL ) THEN\n BCI = CPX\n ELSE\n BCI = CPX/(SLX**(1.D+0/CLX))\n ENDIF\n!\n!--- End of BCI group\n!\n RETURN\n END\n\n!----------------------Function----------------------------------------!\n!\n FUNCTION BCTI( SLX,V,IV )\n!\n!-------------------------Disclaimer-----------------------------------!\n!\n! This material was prepared as an account of work sponsored by\n! an agency of the United States Government. Neither the\n! United States Government nor the United States Department of\n! Energy, nor Battelle, nor any of their employees, makes any\n! warranty, express or implied, or assumes any legal liability or\n! responsibility for the accuracy, completeness, or usefulness\n! of any information, apparatus, product, software or process\n! disclosed, or represents that its use would not infringe\n! privately owned rights.\n!\n!----------------------Acknowledgement---------------------------------!\n!\n! This software and its documentation were produced with Government\n! support under Contract Number DE-AC06-76RLO-1830 awarded by the\n! United Department of Energy. The Government retains a paid-up\n! non-exclusive, irrevocable worldwide license to reproduce,\n! prepare derivative works, perform publicly and display publicly\n! by or for the Government, including the right to distribute to\n! other Government contractors.\n!\n!---------------------Copyright Notices--------------------------------!\n!\n! Copyright Battelle Memorial Institute, 1996\n! All Rights Reserved.\n!\n!----------------------Description-------------------------------------!\n!\n! Inverse Brooks-Corey function.\n!\n!----------------------Authors-----------------------------------------!\n!\n! Written by MD White, Battelle, February, 1999.\n! Last Modified by Mark White, Battelle, February 19, 1999.\n! $Id: rombint.F 1080 2017-03-14 16:22:02Z d3c002 $\n!\n!----------------------Implicit Double Precision-----------------------!\n!\n IMPLICIT REAL*8 (A-H,O-Z)\n IMPLICIT INTEGER (I-N)\n!\n!----------------------Parameter Statements----------------------------!\n!\n PARAMETER( EPSL=1.D-14 )\n!\n!-------------------------Type Statements------------------------------!\n!\n REAL*8 V(10)\n INTEGER IV(10)\n!\n!----------------------Executable Lines--------------------------------!\n!\n CPX = V(1)\n CLX = V(2)\n CRX = V(3)\n IF( (1.D+0-SLX).LT.EPSL ) THEN\n BCTI = CPX*SLX/((-1.D+0 + (-1.D+0 + SLX)*CRX)**2)\n ELSE\n BCTI = CPX*SLX/(SLX**(1.D+0/CLX))/\n & ((-1.D+0 + (-1.D+0 + SLX)*CRX)**2)\n ENDIF\n!\n!--- End of BCTI group\n!\n RETURN\n END\n\n\n", "meta": {"hexsha": "05368ee64482f56ed735354836ea905b85d894ad", "size": 32898, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/rombint.f", "max_stars_repo_name": "pnnl/stomp-w", "max_stars_repo_head_hexsha": "ff4498b2116d7bd93b746399ad11641610553d06", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-03-14T19:38:53.000Z", "max_stars_repo_stars_event_max_datetime": "2017-03-14T19:38:53.000Z", "max_issues_repo_path": "src/rombint.f", "max_issues_repo_name": "pnnl/stomp-w", "max_issues_repo_head_hexsha": "ff4498b2116d7bd93b746399ad11641610553d06", "max_issues_repo_licenses": ["MIT"], "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/rombint.f", "max_forks_repo_name": "pnnl/stomp-w", "max_forks_repo_head_hexsha": "ff4498b2116d7bd93b746399ad11641610553d06", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2019-10-07T12:49:30.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-12T22:37:43.000Z", "avg_line_length": 35.2604501608, "max_line_length": 72, "alphanum_fraction": 0.5245303666, "num_tokens": 7737, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412809, "lm_q2_score": 0.7577943658046609, "lm_q1q2_score": 0.6528688064203786}} {"text": "!\n! file tsepx4.f90\n!\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n! * *\n! * copyright(c) 2005 by UCAR *\n! * *\n! * University Corporation for Atmospheric Research *\n! * *\n! * all rights reserved *\n! * *\n! * Fishpack *\n! * *\n! * A Package of Fortran *\n! * *\n! * Subroutines and Example Programs *\n! * *\n! * for Modeling Geophysical Processes *\n! * *\n! * by *\n! * *\n! * John Adams, Paul Swarztrauber and Roland Sweet *\n! * *\n! * of *\n! * *\n! * the National Center for Atmospheric Research *\n! * *\n! * Boulder, Colorado (80307) U.S.A. *\n! * *\n! * which is sponsored by *\n! * *\n! * the National Science Foundation *\n! * *\n! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n!\nprogram test_sepx4\n\n use fishpack\n\n ! Explicit typing only\n implicit none\n\n ! Dictionary\n integer(ip), parameter :: M = 32, N = M\n integer(ip), parameter :: NX = M + 1, NY = N + 1\n integer(ip) :: i, j, mbdcnd, nbdcnd, idmn, iorder\n integer(ip) :: ierror, ierror2, ierror4\n real(wp), dimension(NX, NY) :: usol, grhs\n real(wp), dimension(NY) :: bda, bdb\n real(wp) :: a, b, c, d, dx, dy, x, af, bf, cf, y\n real(wp) :: alpha, beta, dummy_variable(1)\n real(wp) :: pertrb, discretization_error\n real(wp) :: second_order_error, fourth_order_error\n real(wp), parameter :: ZERO = 0.0_wp, ONE = 1.0_wp\n\n ! Set domain\n a = ZERO\n b = ONE\n c = ZERO\n d = ONE\n\n ! Set mesh size\n dx = (b - a)/M\n dy = (d - c)/N\n\n do i = 1, NX\n x = a + real(i - 1, kind=wp) * dx\n\n ! Set specified boundary conditions at y=c, d\n usol(i, 1) = ue(x, c)\n usol(i, NY) = ue(x, d)\n\n call get_coefficients_in_x_direction(x, af, bf, cf)\n\n do j = 1, NY\n y = c + real(j - 1, kind=wp)*dy\n\n ! Set right hand side\n grhs(i, j)=af*uxxe(x, y)+bf*uxe(x, y)+cf*ue(x, y)+uyye(x, y)\n end do\n end do\n\n ! Set mixed boundary conditions at x=a, b\n alpha = ONE\n beta = ONE\n do j = 1, NY\n y = c + real(j - 1, kind=wp) * dy\n bda(j) = uxe(a, y) + alpha * ue(a, y)\n bdb(j) = uxe(b, y) + beta * ue(b, y)\n end do\n\n ! Set boundary switches\n mbdcnd = 3\n nbdcnd = 1\n\n ! Set first dimension of usol, grhs and workspace length\n idmn = size(usol, dim=1)\n\n ! Obtain 2nd-order approximation\n iorder = 2\n\n call sepx4(iorder, a, b, M, mbdcnd, bda, alpha, bdb, beta, c, d, &\n N, nbdcnd, dummy_variable, dummy_variable, &\n get_coefficients_in_x_direction, grhs, usol, idmn, pertrb, ierror)\n\n ! Compute (relative) 2nd-order discretization error\n ! also reset specified boundaries and right hand side.\n discretization_error = ZERO\n do i = 1, NX\n x = a + real(i - 1, kind=wp) * dx\n usol(i, 1) = ue(x, c)\n usol(i, NY) = ue(x, d)\n call get_coefficients_in_x_direction(x, af, bf, cf)\n do j = 1, NY\n y = c + real(j - 1, kind=wp)*dy\n discretization_error = max(discretization_error, abs((usol(i, j)-ue(x, y))/ue(x, y)))\n\n ! Reset right hand side in grhs for 4th-order approximation call\n grhs(i, j)=af*uxxe(x, y)+bf*uxe(x, y)+cf*ue(x, y)+uyye(x, y)\n end do\n end do\n\n ! Set 2nd-order results\n second_order_error = discretization_error\n ierror2 = ierror\n\n ! Obtain 4th-order approximation\n iorder = 4\n call sepx4(iorder, a, b, M, mbdcnd, bda, alpha, bdb, beta, c, d, &\n N, nbdcnd, dummy_variable, dummy_variable, get_coefficients_in_x_direction, &\n grhs, usol, idmn, pertrb, ierror)\n\n ! Compute (relative) 4th-order discretization error\n discretization_error = ZERO\n do j = 1, NY\n y = c + real(j - 1, kind=wp)*dy\n do i = 1, NX\n x = a + real(i - 1, kind=wp)*dx\n discretization_error = max(discretization_error, abs((usol(i, j)-ue(x, y))/ue(x, y)))\n end do\n end do\n\n ! Set 4th-order results\n fourth_order_error = discretization_error\n ierror4 = ierror\n\n block\n real(wp), parameter :: KNOWN_2ND_ORDER_ERROR = 0.159850337215328e-3_wp\n real(wp), parameter :: KNOWN_4TH_ORDER_ERROR = 0.185748791237117e-5_wp\n\n call check_output('sepx4', &\n ierror2, KNOWN_2ND_ORDER_ERROR, second_order_error, &\n ierror4, KNOWN_4TH_ORDER_ERROR, fourth_order_error)\n\n end block\ncontains\n\n pure function ue(s, t) &\n result (return_value)\n\n ! Dummy arguments\n real(wp), intent(in) :: s\n real(wp), intent(in) :: t\n real(wp) :: return_value\n\n return_value =(s*t)**3 + ONE\n\n end function ue\n\n pure function uxe(s, t) &\n result (return_value)\n\n ! Dummy arguments\n real(wp), intent(in) :: s\n real(wp), intent(in) :: t\n real(wp) :: return_value\n\n ! Local variables\n real(wp), parameter :: THREE = 3.0_wp\n\n return_value = THREE *(s**2)*(t**3)\n\n end function uxe\n\n pure function uxxe(s, t) &\n result (return_value)\n\n ! Dummy arguments\n real(wp), intent(in) :: s\n real(wp), intent(in) :: t\n real(wp) :: return_value\n\n ! Local variables\n real(wp), parameter :: SIX = 6.0_wp\n\n return_value = SIX * s *(t**3)\n\n end function uxxe\n\n pure function uyye(s, t) &\n result (return_value)\n\n ! Dummy arguments\n real(wp), intent(in) :: s\n real(wp), intent(in) :: t\n real(wp) :: return_value\n\n ! Local variables\n real(wp), parameter :: SIX = 6.0_wp\n\n return_value = SIX *(s**3) * t\n\n end function uyye\n\n pure subroutine get_coefficients_in_x_direction(x, af, bf, cf)\n\n ! Dummy arguments\n real(wp), intent(in) :: x\n real(wp), intent(out) :: af\n real(wp), intent(out) :: bf\n real(wp), intent(out) :: cf\n\n ! Local variables\n real(wp), parameter :: TWO = 2.0_wp\n\n ! set coefficients in the x-direction.\n af =(x + ONE)**2\n bf = TWO * (x + ONE)\n cf = -x\n\n end subroutine get_coefficients_in_x_direction\n\nend program test_sepx4\n", "meta": {"hexsha": "39d65c3e6c9043dcb85d17292a3fe4f7b65b28c3", "size": 7815, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/tsepx4.f90", "max_stars_repo_name": "jlokimlin/fishpack", "max_stars_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2018-03-12T11:31:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-27T07:58:23.000Z", "max_issues_repo_path": "examples/tsepx4.f90", "max_issues_repo_name": "jlokimlin/fishpack", "max_issues_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2016-05-07T22:42:47.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-15T17:44:58.000Z", "max_forks_repo_path": "examples/tsepx4.f90", "max_forks_repo_name": "jlokimlin/modern_fishpack", "max_forks_repo_head_hexsha": "9dc7d2e7a847fa6a610752d4e91eda3ef9c6130d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-01-26T20:49:05.000Z", "max_forks_repo_forks_event_max_datetime": "2017-01-27T16:44:58.000Z", "avg_line_length": 33.3974358974, "max_line_length": 97, "alphanum_fraction": 0.4287907869, "num_tokens": 2026, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381987656672, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.6528688023753115}} {"text": "MODULE Priestlytaylormod\n IMPLICIT NONE\nCONTAINS\n\n SUBROUTINE model_priestlytaylor(netRadiationEquivalentEvaporation, &\n hslope, &\n psychrometricConstant, &\n Alpha, &\n evapoTranspirationPriestlyTaylor)\n IMPLICIT NONE\n REAL, INTENT(IN) :: netRadiationEquivalentEvaporation\n REAL, INTENT(IN) :: hslope\n REAL, INTENT(IN) :: psychrometricConstant\n REAL, INTENT(IN) :: Alpha\n REAL, INTENT(OUT) :: evapoTranspirationPriestlyTaylor\n !- Description:\n ! * Title: evapoTranspirationPriestlyTaylor Model\n ! * Author: Pierre Martre\n ! * Reference: Modelling energy balance in the wheat crop model SiriusQuality2:\n ! Evapotranspiration and canopy and soil temperature calculations\n ! * Institution: INRA Montpellier\n ! * Abstract: Calculate Energy Balance \n !- inputs:\n ! * name: netRadiationEquivalentEvaporation\n ! ** description : net Radiation in Equivalent Evaporation\n ! ** variablecategory : state\n ! ** datatype : DOUBLE\n ! ** default : 638.142\n ! ** min : 0\n ! ** max : 5000\n ! ** unit : g m-2 d-1\n ! ** uri : http://www1.clermont.inra.fr/siriusquality/?page_id=547\n ! ** inputtype : variable\n ! * name: hslope\n ! ** description : the slope of saturated vapor pressure temperature curve at a given temperature \n ! ** variablecategory : auxiliary\n ! ** datatype : DOUBLE\n ! ** default : 0.584\n ! ** min : 0\n ! ** max : 1000\n ! ** unit : hPa \u00b0C-1\n ! ** uri : http://www1.clermont.inra.fr/siriusquality/?page_id=547\n ! ** inputtype : variable\n ! * name: psychrometricConstant\n ! ** description : psychrometric constant\n ! ** parametercategory : constant\n ! ** datatype : DOUBLE\n ! ** default : 0.66\n ! ** min : 0\n ! ** max : 1\n ! ** unit : \n ! ** uri : http://www1.clermont.inra.fr/siriusquality/?page_id=547\n ! ** inputtype : parameter\n ! * name: Alpha\n ! ** description : Priestley-Taylor evapotranspiration proportionality constant\n ! ** parametercategory : constant\n ! ** datatype : DOUBLE\n ! ** default : 1.5\n ! ** min : 0\n ! ** max : 100\n ! ** unit : \n ! ** uri : http://www1.clermont.inra.fr/siriusquality/?page_id=547\n ! ** inputtype : parameter\n !- outputs:\n ! * name: evapoTranspirationPriestlyTaylor\n ! ** description : evapoTranspiration of Priestly Taylor \n ! ** variablecategory : rate\n ! ** datatype : DOUBLE\n ! ** min : 0\n ! ** max : 10000\n ! ** unit : g m-2 d-1\n ! ** uri : http://www1.clermont.inra.fr/siriusquality/?page_id=547\n evapoTranspirationPriestlyTaylor = MAX(Alpha * hslope * &\n netRadiationEquivalentEvaporation / (hslope + psychrometricConstant), &\n 0.0)\n END SUBROUTINE model_priestlytaylor\n\nEND MODULE\n", "meta": {"hexsha": "66820b24e8dd7b418d9d3b9990eabf744fa91861", "size": 4025, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/Models/energybalance_pkg/src/dssat/Priestlytaylor.f90", "max_stars_repo_name": "brichet/PyCrop2ML", "max_stars_repo_head_hexsha": "7177996f72a8d95fdbabb772a16f1fd87b1d033e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-06-21T18:58:04.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-29T21:32:28.000Z", "max_issues_repo_path": "test/Models/energybalance_pkg/src/dssat/Priestlytaylor.f90", "max_issues_repo_name": "brichet/PyCrop2ML", "max_issues_repo_head_hexsha": "7177996f72a8d95fdbabb772a16f1fd87b1d033e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 27, "max_issues_repo_issues_event_min_datetime": "2018-12-04T15:35:44.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-11T08:25:03.000Z", "max_forks_repo_path": "test/Models/energybalance_pkg/src/dssat/Priestlytaylor.f90", "max_forks_repo_name": "brichet/PyCrop2ML", "max_forks_repo_head_hexsha": "7177996f72a8d95fdbabb772a16f1fd87b1d033e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-04-20T02:25:22.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T07:52:35.000Z", "avg_line_length": 50.9493670886, "max_line_length": 127, "alphanum_fraction": 0.4377639752, "num_tokens": 863, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310357, "lm_q2_score": 0.757794360334681, "lm_q1q2_score": 0.6528687963196781}} {"text": " subroutine irev_eqipsi(n_a1,n_alpha,n_beta,n_iPHI,n_iPI,nm1_ipsi,n\n &p1_ipsi,Nx,ht,res)\n implicit none\n integer i\n integer Nx\n real*8 ht\n real*8 n_a1(Nx)\n real*8 n_alpha(Nx)\n real*8 n_beta(Nx)\n real*8 n_iPHI(Nx)\n real*8 n_iPI(Nx)\n real*8 nm1_ipsi(Nx)\n real*8 np1_ipsi(Nx)\n real*8 res(Nx)\n real*8 qb\n do i=1, Nx, 1\n qb = 0.5000000000000000D0 * (-0.1D1 * nm1_ipsi(i) + np1_ipsi(i)) /\n # ht - 0.1D1 * n_alpha(i) / n_a1(i) * n_iPI(i) - 0.1D1 * n_beta(i) \n #* n_iPHI(i)\n res(i)=qb\n end do\n END\n", "meta": {"hexsha": "2b70544e0f1a04d9fb6d0a64330ff3b48be26c58", "size": 597, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/FD/irev_eqipsi.f", "max_stars_repo_name": "rmanak/bssn_spher", "max_stars_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/FD/irev_eqipsi.f", "max_issues_repo_name": "rmanak/bssn_spher", "max_issues_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/FD/irev_eqipsi.f", "max_forks_repo_name": "rmanak/bssn_spher", "max_forks_repo_head_hexsha": "b91104fd6b9b7cf1ba08e35efd65ff219ab7a5a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.9565217391, "max_line_length": 72, "alphanum_fraction": 0.5443886097, "num_tokens": 252, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436482, "lm_q2_score": 0.7090191460821871, "lm_q1q2_score": 0.652857506639175}} {"text": "\tSUBROUTINE GMTOWQ ( amtrx, invers, polnr,\n +\t\t\t np, rlat, rlon, slat, slon, iret )\nC************************************************************************\nC* GMTOWQ\t\t\t\t\t\t\t\t*\nC* \t\t\t\t\t\t\t\t\t*\nC* This subroutine converts a location from actual latitude/longitude\t*\nC* coordinates to latitude and longitude in a rotated coordinate, if\t*\nC* INVERS = .false. The inverse transformation is done if INVERS =\t*\nC* .true. Actual lat/lon coordinates are M coordinates; the lat/lon\t*\nC* coordinates in the rotated frame are W coordinates (map) or Q\t*\nC* coordinates (grid).\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t* \nC* This routine performs the transformation needed for the any map/grid *\nC* projection. The rotation matrix is AMTRX. The rotation matrices\t*\nC* for map and grid projections are set in the update routines UPD for *\nC* map/grid projections.\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* The transformation from M -> W/Q proceeds as follows:\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* 1) Transform actual lat/lon to cartesian coordinates.\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* 2) Rotate the cartesian system three times:\t\t\t*\nC*\t a) Through POLON = ANGLE2 to reposition xy axes \t\t*\nC*\t b) Through POLAT = ANGLE1 to reposition xz axes\t\t*\nC*\t c) Through ROTAT = ANGLE3 to reposition yz or xy axes\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* 3) Transform from rotated cartesian to spherical W/Q coordinates.\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* The inverse from W/Q -> M reverses these steps.\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* The longitude rotation angle is only used for the special case when\t*\nC* a point falls on a pole in the rotated coordinate. In that case,\t*\nC* longitude is indefinite, but for cylindrical projections a definite\t*\nC* longitude is required when a pole corresponds to a corner point\t*\nC* That is why this rotation is done.\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* \t\t\t\t\t\t\t\t\t*\nC* GMTOWQ ( AMTRX, INVERS, POLNR, NP, RLAT, RLON, SLAT, SLON, IRET )\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tAMTRX(3,3)\tREAL\t\tTransformation matrix\t\t*\nC*\tINVERS\t\tLOGICAL\t\tInverse transform flag\t\t*\nC*\tPOLNR\t\tREAL\t\tLongitude rotation angle\t*\nC*\tNP\t\tINTEGER\t\tNumber of points\t\t*\nC* \tRLAT (NP)\tREAL\t\tInput latitudes\t\t\t*\nC* \tRLON (NP)\tREAL\t\tInput longitudes\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC* \tSLAT (NP)\tREAL\t\tOutput latitudes\t\t*\nC* \tSLON (NP)\tREAL\t\tOutput longitudes\t\t*\nC* \tIRET\t\tINTEGER\t\tReturn code\t\t\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* K. Brill/EMC\t\t 3/96\t\t\t\t\t\t*\nC* T. Lee/GSC\t\t 7/96\t\tFixed pole points plot for RADAR*\nC************************************************************************\n\tINCLUDE\t\t'ERROR.PRM'\n\tINCLUDE\t\t'GEMPRM.PRM'\n\tPARAMETER\t( EPS = .03 )\nC*\n\tREAL \t\tamtrx (3,3)\n\tLOGICAL\t\tinvers\n\tREAL\t\trlat (*), rlon (*), slat (*), slon (*)\nC*\n\tREAL\t\ttmtrx (3,3), x (3), xp (3), phi,\n +\t\t\trlm, cosp, xx, yy\nC*\n\tINCLUDE\t\t'ERMISS.FNC'\nC------------------------------------------------------------------------\n\tiret = NORMAL\nC\nC*\tSet the transformation matrix and look for identity matrix.\nC\n\tIF ( .not. invers ) THEN\n\t DO j = 1, 3\n\t\tDO i = 1, 3\n\t\t tmtrx (i,j) = amtrx (i,j)\n\t\tEND DO\n\t END DO\n\tELSE\nC\nC*\t The inverse is just the transpose.\nC\n\t DO j = 1, 3\n\t\tDO i = 1, 3\n\t\t tmtrx (i,j) = amtrx (j,i)\n\t\tEND DO\n\t END DO\n\tEND IF\nC\nC*\tProcess all the points.\nC\n\tDO ii = 1, np\n\t IF ( .not. ERMISS ( rlat (ii) ) .and.\n +\t\t .not. ERMISS ( rlon (ii) ) ) THEN\nC\nC*\t Convert from spherical to cartesian coordinates.\nC\n\t \tphi = rlat (ii) * DTR\n\t \trlm = rlon (ii) * DTR\n\t \tcosp = COS (phi)\n\t \txx = COS (rlm)\n\t \tyy = SIN (rlm)\n\t \tx (1) = cosp * xx\n\t \tx (2) = cosp * yy\n\t \tx (3) = SIN (phi)\nC\nC*\t \tRotate the coordinates and confine coordinate values.\nC\n\t \tDO i = 1, 3\n\t\t xp (i) = 0.\n\t\t DO j = 1, 3\n\t\t \txp (i) = xp (i) + tmtrx (i,j) * x (j)\n\t\t END DO\n\t\t IF ( xp (i) .gt. 1. ) xp (i) = 1.\n\t\t IF ( xp (i) .lt. -1. ) xp (i) = -1.\n\t \tEND DO\nC\nC*\t \tConvert from cartesian to spherical coordinates.\nC*\t\tIf the rotated coordinate is at a pole; then,\nC*\t\trotate the longitude (since it is indefinite).\nC\n\t \tslat (ii) = ASIN ( xp (3) ) * RTD\n\t\tIF ( ABS ( slat (ii) - 90. ) .lt. EPS ) THEN\n\t\t slat (ii) = 90.\n\t\t rcos = COS ( polnr )\n\t\t rsin = SIN ( polnr )\n\t\t IF ( invers ) rsin = -rsin\n\t\t xxp = xx * rcos + yy * rsin\n\t\t yyp = (-xx) * rsin + yy * rcos\n\t\t slon (ii) = ATAN2 ( yyp, xxp ) * RTD\n\t\tELSE\n\t\t slon (ii) = ATAN2 ( xp (2), xp (1) ) * RTD\n\t\tEND IF\n\t ELSE\n\t\tslat (ii) = RMISSD\n\t\tslon (ii) = RMISSD\n\t END IF\n\tEND DO\nC*\n\tRETURN\n\tEND\n", "meta": {"hexsha": "60160b6f188e42b4c1c2d826c560854ac19c5956", "size": 4432, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/gplt/transform/gmtowq.f", "max_stars_repo_name": "oxelson/gempak", "max_stars_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2015-06-03T15:26:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T22:36:03.000Z", "max_issues_repo_path": "gempak/source/gplt/transform/gmtowq.f", "max_issues_repo_name": "oxelson/gempak", "max_issues_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 60, "max_issues_repo_issues_event_min_datetime": "2015-05-11T21:36:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T16:22:42.000Z", "max_forks_repo_path": "gempak/source/gplt/transform/gmtowq.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.993006993, "max_line_length": 73, "alphanum_fraction": 0.5561823105, "num_tokens": 1544, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436482, "lm_q2_score": 0.7090191337850932, "lm_q1q2_score": 0.6528574953161379}} {"text": "!-----------------------------------------------------------------------------!\n!-----------------------------------------------------------------------------!\n! MAE 6263 Computational Fluid Dynamics - Project 3 !\n! Sk. Mashfiqur Rahman !\n!-----------------------------------------------------------------------------!\n!-----------------------------------------------------------------------------!\n\nprogram channel\nimplicit none\ninteger :: nx,ny,i,j,opt,nitr,ns\nreal*8 :: Re,pe,Tmax,nu,dy,dx,dt,rho,tolt,m\nreal*8 :: t1,t2,lx,ly,tol,gamma,tol1,en\nreal*8,allocatable ::u(:,:),v(:,:),p(:,:),hx(:,:),hy(:,:)\n\ncommon/Reynolds/Re\ncommon/contol/tol\ncommon/density/rho\n\nopen(9,file='project3input.txt')\nread(9,*)lx\t\t !length in x -direction\nread(9,*)ly\t \t!length in y -direction\nread(9,*)nx\t\t !resolution in x direction\nread(9,*)ny\t \t!resolution in y direction\nread(9,*)ns\t \t!number of snapshots\nread(9,*)gamma\t\t!value of gamma to measure time-step size\nread(9,*)rho\t !density\nread(9,*)nu\t \t!kinematic viscosity\nread(9,*)pe\t \t!Peclet number\nread(9,*)Tmax\t\t!final time\nread(9,*)tol !tolerance for iterative solvers\nread(9,*)tolt !tolerance for time integration\nread(9,*)Re !Reynolds number\nread(9,*)opt \t![0]PPE without momentum interpolation, [1]PPE with momentum interpolation\nclose(9) \n\n!Calculating grid spacing (spatial)\ndx = lx/dfloat(nx)\ndy = ly/dfloat(ny)\nprint*, dx\nprint*, dy\n\n!Time step\n!dt = ((dx*dx)*gamma) /nu\ndt = Tmax/dfloat(ns)\n\n!Initial Condition & Boundary Condition Setup\nallocate(u(0:nx,0:ny))\nallocate(v(0:nx,0:ny))\nallocate(p(0:nx,0:ny))\nallocate(hx(0:nx,0:ny))\nallocate(hy(0:nx,0:ny))\n\ndo i = 0,nx\n do j = 0,ny\n u(i,j) = 0\n v(i,j) = 0\n p(i,j) = 0\n end do\nend do\n\ndo j = 0,ny\n p(0,j) = 100.16d0\n p(nx,j) = 100.0d0 \n \nend do\n\nnitr = 0\n!IC File Ouput\nopen(20,file=\"InitialCondition.plt\")\nwrite(20,*)'Title=\"IC Data set\"'\nwrite(20,*)'variables =\"x\",\"y\",\"u\",\"v\",\"p\"'\nclose(20)\n\nopen(20,file=\"InitialCondition.plt\",position=\"append\")\nwrite(20,\"(a,i8,a,i8,a)\")'Zone I = ',nx+1,',J=',ny+1,',F=POINT'\n do j = 0,ny\n do i = 0,nx\n write (20, '(1600F14.3)',advance=\"no\")dfloat(i)/dfloat(ny),dfloat(j)/dfloat(ny),u(i,j),v(i,j),p(i,j)\n write(20,*) ''\n end do\n end do\nclose(20)\n\n!Output file setup\nopen(20,file=\"ContourPlots.plt\")\nwrite(20,*)'Title=\"Transient data set\"'\nwrite(20,*)'variables =\"x\",\"y\",\"u\",\"v\",\"p\"'\nclose(20)\n\nopen(20,file=\"LinePlots.plt\")\nwrite(20,*)'Title=\"Transient data set\"'\nwrite(20,*)'variables =\"x\",\"p\"'\nclose(20)\n\nopen(20,file=\"UprofileLinePlots.plt\")\nwrite(20,*)'Title=\"Transient data set\"'\nwrite(20,*)'variables =\"u\",\"y\"'\nclose(20)\n\nopen(20,file=\"energy.plt\")\nwrite(20,*)'Title=\"Transient data set\"'\nwrite(20,*)'variables =\"e\",\"t\"'\nclose(20)\n\nopen(20,file=\"mass.plt\")\nwrite(20,*)'Title=\"Transient data set\"'\nwrite(20,*)'variables =\"m\",\"t\"'\nclose(20)\n\ncall cpu_time(t1)\n\n!-----------------------------------------------------------------------------!\n!Time integration\n!-----------------------------------------------------------------------------!\n\ntol1 = 1.0d0 \ndo while (tol1.gt.tolt)\n tol1 = 0.0d0\n nitr = nitr + 1\ncall RHS(u,v,hx,hy,nx,ny,dx,dy)\n\nif (opt==0) then\ncall compact(p,hx,hy,nx,ny,dx,dy,tol)\nelse \ncall momentum(p,u,v,dt,nx,ny,dx,dy,tol,nitr)\nend if\n\ncall velocity(u,v,p,hx,hy,nx,ny,dx,dy,dt,tol1)\n\n!Output .plt file for Tecplot \nif (mod(nitr,500)==0) then\n \nopen(20,file=\"ContourPlots.plt\",position=\"append\")\nwrite(20,\"(a,i8,a,i8,a)\")'Zone I = ',nx+1,',J=',ny+1,',F=POINT'\nwrite(20,\"(a,i8)\")'StrandID=0,SolutionTime=',nitr\n do j = 0,ny\n do i = 0,nx\n write (20, '(1600F14.6,1600F14.6,1600F14.6,1600F14.6)',advance=\"no\")dfloat(i)/dfloat(nx/2),&\n &dfloat(j)/dfloat(ny),u(i,j),v(i,j),p(i,j)\n write(20,*) ''\n end do\n end do\nclose(20)\n\nopen(20,file=\"LinePlots.plt\",position=\"append\")\nwrite(20,\"(a,i8,a)\")'Zone I = ',ny+1,',F=POINT'\nwrite(20,\"(a,i8)\")'StrandID=0,SolutionTime=',nitr\n do j = 0,ny\n write (20, '(1600F14.6,1600F14.6)',advance=\"no\")dfloat(j)/dfloat(ny),p(nx/2,j)\n write(20,*) ''\n end do\nclose(20)\n\nopen(20,file=\"UprofileLinePlots.plt\",position=\"append\")\nwrite(20,\"(a,i8,a)\")'Zone I = ',ny+1,',F=POINT'\nwrite(20,\"(a,i8)\")'StrandID=0,SolutionTime=',nitr\n do j = 0,ny\n write (20, '(1600F14.6,1600F14.6)',advance=\"no\")u(nx/2,j),dfloat(j)/dfloat(ny)\n write(20,*) ''\n end do\nclose(20)\n\nen = 0.0d0\nm = 0.0d0\n\nopen(20,file=\"energy.plt\",position=\"append\")\n do i = 0,nx\n do j = 0,ny-1\n en = en + 0.5d0*rho*u(i,j)*u(i,j)\n end do\n end do\n write (20,*) dfloat(nitr),en\n write(20,*) ''\nclose(20)\n\nopen(20,file=\"mass.plt\",position=\"append\")\n do j = 1,ny-1\n m = m + 0.5d0*(u(nx/2+1,j)+u(nx/2+1,j+1))\n end do\n write (20,*) dfloat(nitr),m*dy\n write(20,*) ''\nclose(20)\nend if\n\nend do\n\ncall cpu_time(t2)\n\nopen(4,file='cpu.txt')\nwrite(4,*)\"cpu time (sec)=\",(t2-t1)\nclose(4)\n\nend\n\n\n!-----------------------------------------------------------------------------!\n!Convection-diffusion\n!-----------------------------------------------------------------------------!\nsubroutine RHS(u,v,hx,hy,nx,ny,dx,dy)\nimplicit none\n\ninteger :: nx,ny,i,j\nreal*8::dx,dy,Re\nreal*8,dimension(0:nx,0:ny):: u,v,hx,hy\nreal*8,dimension(-1:nx+1,-1:ny+1)::u2,v2\nreal*8,dimension(0:nx,0:ny)::udx,udy,uddx,uddy,vdx,vdy,vddx,vddy\n\ncommon/Reynolds/Re\n\ndo i = 0,nx\n do j = 0,ny\n u2(i,j) = u(i,j)\n v2(i,j) = v(i,j)\n end do\nend do\n\ndo j = 0,ny\n u2(-1,j) = u(nx-1,j)\n u2(nx+1,j) = u(1,j)\n v2(nx+1,j) = v(1,j)\n v2(-1,j) = v(nx-1,j)\nend do\n \ndo i = 0,nx\n \tdo j = 1,ny-1\n if(u(i,j)>=0) then\n \t\tudx(i,j) = (u2(i,j)-u2(i-1,j))/dx\n vdx(i,j) = (v2(i,j)-v2(i-1,j))/dx\n else if(u(i,j)<0) then\n udx(i,j) = (u2(i+1,j)-u2(i,j))/dx\n vdx(i,j) = (v2(i+1,j)-v2(i,j))/dx\n end if \n\tend do\n udx(i,0) = udx(i,1)\n vdx(i,0) = vdx(i,1)\n udx(i,ny) = udx(i,ny-1)\n vdx(i,ny) = vdx(i,ny-1)\nend do\n\ndo i = 0,nx\n \tdo j = 1,ny-1\n if(v(i,j)>=0) then\n \t\tudy(i,j) = (u2(i,j)-u2(i,j-1))/dy\n vdy(i,j) = (v2(i,j)-v2(i,j-1))/dy\n else if(v(i,j)<0) then\n udy(i,j) = (u2(i,j+1)-u2(i,j))/dy\n vdy(i,j) = (v2(i,j+1)-v2(i,j))/dy\n end if\n\tend do\n udy(i,0) = udy(i,1)\n vdy(i,0) = vdy(i,1)\n udy(i,ny) = udy(i,ny-1)\n vdy(i,ny) = vdy(i,ny-1)\nend do\n\ndo i = 0,nx\n \tdo j = 1,ny-1\n \t\tuddx(i,j) = (u2(i+1,j)+u2(i-1,j)-2.*u2(i,j))/(dx**2)\n vddx(i,j) = (v2(i+1,j)+v2(i-1,j)-2.*v2(i,j))/(dx**2)\n\tend do\n uddx(i,0) = uddx(i,1)\n vddx(i,0) = vddx(i,1)\n uddx(i,ny) = uddx(i,ny-1)\n vddx(i,ny) = vddx(i,ny-1)\nend do\n\ndo i = 0,nx\n \tdo j = 1,ny-1\n \t\tuddy(i,j) = (u2(i,j+1)+u2(i,j-1)-2d0*u2(i,j))/(dy**2)\n vddy(i,j) = (v2(i,j+1)+v2(i,j-1)-2d0*v2(i,j))/(dy**2)\n\tend do\n uddy(i,0) = uddy(i,1)\n vddy(i,0) = vddy(i,1)\n uddy(i,ny) = uddy(i,ny-1)\n vddy(i,ny) = vddy(i,ny-1)\nend do\n\ndo i = 0,nx\n\tdo j = 0,ny\n \thx(i,j) = -u2(i,j)*(udx(i,j))-v2(i,j)*(udy(i,j))+1/Re*(uddx(i,j)+uddy(i,j))\n \thy(i,j) = -u2(i,j)*(vdx(i,j))-v2(i,j)*(vdy(i,j))+1/Re*(vddx(i,j)+vddy(i,j))\n \n\tend do\nend do\n\nreturn\nend\n\n!-----------------------------------------------------------------------------!\n!Pressure\n!-----------------------------------------------------------------------------!\nsubroutine compact(p,hx,hy,nx,ny,dx,dy,tol)\nimplicit none\n\ninteger :: nx,ny,i,j\nreal*8::dy,dx,a,b,tol,err\nreal*8,dimension(0:nx,0:ny):: p,hx,hy,hxdx,hydy,hy2,e\nreal*8,dimension(0:nx,-1:ny+1)::p2,p1\nreal*8,dimension(-1:nx+1,0:ny)::hx2\n\nerr=1.0d0\n \np1(0:nx,0:ny) = p\n\ndo i = 0,nx\n do j = 0,ny\n hx2(i,j) = hx(i,j)\n hy2(i,j) = hy(i,j) \n end do\nend do\n\ndo j = 0,ny\n hx2(-1,j) = hx(nx-1,j)\n hx2(nx+1,j) = hx(1,j)\nend do\n \ndo i = 0,nx\n do j = 1,ny-1\n hxdx(i,j) = (hx2(i+1,j)-hx2(i-1,j))/2.0d0\n hydy(i,j) = (hy2(i,j+1)-hy2(i,j-1))/2.0d0\n end do\n hxdx(i,0)=hxdx(i,1)\n hxdx(i,ny)=hxdx(i,ny-1)\n hydy(i,0)=hydy(i,1)\n hydy(i,ny)=hydy(i,ny-1)\nend do \n\ndo i=0,nx\n p1(i,-1) = p1(i,1)\n p1(i,ny+1) = p1(i,ny-1)\nend do \n \ndo while(err.gt.tol)\nerr=0.0d0\np2 = p1\ndo i = 1,nx-1\n do j = 0,ny\n a = p1(i+1,j)+p2(i-1,j)+p2(i,j-1)+p1(i,j+1)\n b = hxdx(i,j) + hydy(i,j)\n p2(i,j) = a/4-(b*dx)/4\n end do \n p2(i,-1) = p2(i,1)\n\tp2(i,ny+1) = p2(i,ny-1)\nend do\t\n \n !compute L1 norm\n do j=0,ny\n do i=0,nx\n e(i,j) = dabs(p2(i,j)-p(i,j))\n err = e(i,j) + err\n end do\n end do \t \n\n\np1 = p2\ndo j = 0,ny\n do i = 0,nx\n p(i,j) = p1(i,j) \n end do\nend do\nend do\n\nreturn\nend\n\n!-----------------------------------------------------------------------------!\n!velocity update\n!-----------------------------------------------------------------------------!\nsubroutine velocity(u,v,p,hx,hy,nx,ny,dx,dy,dt,tol1)\nimplicit none\n\ncommon/density/rho\n\nreal*8::dx,dy,dt,rho,tol1\ninteger::nx,ny,i,j\nreal*8,dimension(0:nx,0:ny)::u,v,p,hx,hy,p2,s\nreal*8,dimension(0:nx,0:ny)::gradpx,gradpy,uo,vo\n\ndo i = 0,nx\n do j = 0,ny\n p2(i,j) = p(i,j)\n end do\nend do\n\ndo i=0,nx\n do j=0,ny\n gradpx(i,j)=0.0\n gradpy(i,j)=0.0\n end do\nend do \n\ndo j = 0,ny\n do i = 0,nx\n uo(i,j) = u(i,j)\n vo(i,j) = v(i,j) \nend do\nend do \n\ndo i = 1,nx-1\n do j = 1,ny-1\n gradpx(i,j) = (p2(i+1,j)-p2(i-1,j))/(2.*dx)\n end do\nend do\n\ndo i = 1,nx-1\n \tdo j = 1,ny-1\n \tgradpy(i,j) = (p2(i,j+1)-p2(i,j-1))/(2.*dy)\n\tend do\nend do\n\ndo j = 0,ny\n \tgradpx(0,j) = gradpx(1,j)\n \tgradpx(nx,j) = gradpx(nx-1,j) \nend do\n\ndo i = 0,nx\n do j = 1,ny-1\n\tu(i,j) = u(i,j) + dt*(hx(i,j)-gradpx(i,j))\n \tv(i,j) = v(i,j) + dt*(hy(i,j)-gradpy(i,j))\n end do\nend do\n\n !compute L1 norm\n do j=0,ny\n do i=0,nx\n s(i,j) = dabs(u(i,j)-uo(i,j))+dabs(v(i,j)-vo(i,j))\n tol1 = s(i,j) + tol1\n end do\n end do\n print*,tol1 \t \n\nreturn\nend\n", "meta": {"hexsha": "25d15ada429ba71325a161f69cc96b2f1074228a", "size": 9747, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "2DChannel.f95", "max_stars_repo_name": "mashfiq10/2DNavierStokesEquationsSolver", "max_stars_repo_head_hexsha": "3f44d9a1212a152acc73ac7cb887f61f0f61a1b2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2DChannel.f95", "max_issues_repo_name": "mashfiq10/2DNavierStokesEquationsSolver", "max_issues_repo_head_hexsha": "3f44d9a1212a152acc73ac7cb887f61f0f61a1b2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2DChannel.f95", "max_forks_repo_name": "mashfiq10/2DNavierStokesEquationsSolver", "max_forks_repo_head_hexsha": "3f44d9a1212a152acc73ac7cb887f61f0f61a1b2", "max_forks_repo_licenses": ["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.4585253456, "max_line_length": 106, "alphanum_fraction": 0.5023084026, "num_tokens": 4079, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896802383028, "lm_q2_score": 0.7090191214879991, "lm_q1q2_score": 0.6528574901577769}} {"text": "program cpspropagate\n\n use precision\n use mpi\n use globals\n use conversion\n use misc\n use setup\n use hamiltonian\n use propagate\n\n implicit none\n\n \n complex(cdp), dimension(:, :), allocatable :: wavefn, wavefn_t, wavefn0\n complex(cdp), dimension(:), allocatable :: espectrum\n real(fdp) :: e_before, e_after, e_start, e_finish, plotfrequency, trans, refl, trap, norm\n integer(idp) :: step, tstep\n integer(idp), dimension(4) :: potbound\n integer(idp), dimension(dim) :: nl, nu, trnl, trnu\n\n#ifdef MPI \n call s_mpiinit()\n#endif\n\n open(unit=potdata, status='scratch', form=\"formatted\")\n\n call s_setup()\n\n#ifdef MPI\n call s_mpiarraysize(nl, nu, trnl, trnu)\n#else\n nl = (/ 1, 1 /)\n nu = (/ parameters%n(1), parameters%n(2) /)\n trnl = (/ 1, 1 /)\n trnu = (/ parameters%n(2), parameters%n(1) /)\n#endif\n\n call s_checkrestart(nl, nu)\n\n allocate(wavefn(nl(1):nu(1), nl(2):nu(2)), &\n & wavefn0(nl(1):nu(1), nl(2):nu(2)), &\n & wavefn_t(nl(1):nu(1), nl(2):nu(2)), &\n & espectrum(parameters%timesteps))\n\n call s_restart(tstep, wavefn, wavefn0, nl, nu, e_start, espectrum)\n\n e_after = f_wavefnenergy(wavefn, nl, nu)\n\n plotfrequency = dble(parameters%timesteps)/dble(parameters&\n &%plotnumber)\n\n do step = tstep+1, parameters%timesteps\n\n e_before = e_after\n\n call s_display('================================================&\n &================================')\n call s_display('time step= ', char=f_numchar(step)//' / '&\n &//f_numchar(parameters%timesteps))\n\n !\n ! Propagate the wavefunction the required amount\n !\n\n call s_propagatewavefn(wavefn, nl, nu, dble(step-1)*parameters&\n &%tstep, dble(step)*parameters%tstep)\n\n e_after = f_wavefnenergy(wavefn, nl, nu)\n\n !\n ! Save the wave function to disk in a converted format for\n ! loading into Mathematica\n !\n#ifndef MPI\n if (parameters%espectrum) then\n\n espectrum(step) = sum(wavefn*conjg(wavefn0))&\n &*product(parameters%gridspacing)\n\n end if\n#endif\n\n if (parameters%plotwfn .and. ceiling(aint(dble(step)&\n &/plotfrequency)*plotfrequency) == step) then\n\n call s_write2drarray(real(wavefn*conjg(wavefn)), nl, nu,&\n & trim(f_numchar(step)))\n\n end if\n\n wavefn_t = wavefn\n\n call s_c2dfft(wavefn_t, nl, nu, fftfor)\n\n#ifdef MPI\n call s_mpitranspose(wavefn_t, trnl, trnu)\n#endif\n\n call s_cshift(wavefn_t, nl, nu, parameters%n(1)/2, parameters&\n &%n(2)/2)\n\n if (parameters%plotwfnp .and. ceiling(aint(dble(step)&\n &/plotfrequency)*plotfrequency) == step) then\n\n call s_write2drarray(real(wavefn_t*conjg(wavefn_t)), nl, nu,&\n & 'p.'//trim(f_numchar(step)), incboundary=.true.)\n\n end if\n\n call s_display('norm= ', realnum=f_norm(real(wavefn&\n &*conjg(wavefn)), nl, nu))\n call s_display('system energy= ', realnum=e_after)\n call s_display('change in system energy= ', realnum=e_start&\n &-e_after)\n\n if (parameters%tranrefl) then\n \n !\n ! Compute and display the amount transmitted and reflected\n !\n\n potbound(1) = f_gridpointx(parameters%potbound(1))\n potbound(2) = f_gridpointx(parameters%potbound(2))\n potbound(3) = f_gridpointy(parameters%potbound(3))\n potbound(4) = f_gridpointy(parameters%potbound(4))\n\n !\n ! Compute a normal transmission\n !\n \n refl = f_reflection(real(wavefn*conjg(wavefn)), nl, nu,&\n & potbound)\n trap = f_trapped(real(wavefn*conjg(wavefn)), nl, nu, potbound)\n trans = f_transmission(real(wavefn*conjg(wavefn)), nl, nu,&\n & potbound)\n \n norm = refl + trap + trans\n \n call s_display('==== Real Space ==== Absolute &\n & Relative')\n call s_display('rs. norm= ', realnums=(/ norm, norm/norm /))\n call s_display('rs. reflected= ', realnums=(/ refl, refl/norm&\n & /))\n call s_display('rs. trapped= ', realnums=(/ trap, trap/norm/))\n call s_display('rs. transmitted= ', realnums=(/ trans, trans&\n &/norm /))\n\n !\n ! Compute transmission in momentum space\n !\n \n refl = f_preflection(real(wavefn_t*conjg(wavefn_t)), nl, nu)\n trans = f_ptransmission(real(wavefn_t*conjg(wavefn_t)), nl,&\n & nu)\n \n norm = refl + trans\n \n call s_display('==== Momentum Space ==== Absolute &\n & Relative')\n call s_display('ms. norm= ', realnums=(/ norm, norm/norm /))\n call s_display('ms. backward= ', realnums=(/ refl, refl/norm&\n &/))\n call s_display('ms. forward= ', realnums=(/ trans, trans/norm&\n & /))\n \n end if\n\n if ((step/parameters%chkpntfreq)*parameters%chkpntfreq == step) then\n \n call s_checkpoint(step, wavefn, wavefn, nl, nu, e_start, espectrum)\n\n end if\n\n end do\n\n deallocate(wavefn, wavefn0, wavefn_t, espectrum)\n\n close(potdata)\n\n#ifdef MPI\n call s_mpifinalise()\n#endif\n\nend program cpspropagate\n", "meta": {"hexsha": "4a9124d3daae0c0aee86cec27ca6e7d15ce088a8", "size": 5141, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "cps_propagate.f90", "max_stars_repo_name": "sdm900/chebyshev_propagation_scheme", "max_stars_repo_head_hexsha": "24b4633e2bcb71d6966f27b9466b42d11c6b5f80", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cps_propagate.f90", "max_issues_repo_name": "sdm900/chebyshev_propagation_scheme", "max_issues_repo_head_hexsha": "24b4633e2bcb71d6966f27b9466b42d11c6b5f80", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cps_propagate.f90", "max_forks_repo_name": "sdm900/chebyshev_propagation_scheme", "max_forks_repo_head_hexsha": "24b4633e2bcb71d6966f27b9466b42d11c6b5f80", "max_forks_repo_licenses": ["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.6397849462, "max_line_length": 91, "alphanum_fraction": 0.5849056604, "num_tokens": 1484, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314858927011, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6528504840207461}} {"text": " double precision pi,pisq,pisqo6\n parameter(pi=3.14159265358979d0,pisq=pi*pi,pisqo6=pisq/6d0)\n\n double precision zip,half,one,two,three,four,eight\n parameter(zip=0d0,half=0.5d0,one=1d0,two=2d0)\n parameter(three=3d0,four=4d0,eight=8d0)\n\n double complex im,impi,czip,chalf,cone,ctwo,c2ipi\n parameter(im=(0d0,1d0),impi=(0d0,3.14159265358979d0),\n . czip=(0d0,0d0),chalf=(0.5d0,0d0),cone=(1d0,0d0),ctwo=(2d0,0d0),\n . c2ipi=2d0*impi)\n\n DOUBLE COMPLEX nan\n parameter (nan = (1D123, 1D123))\n\n\n", "meta": {"hexsha": "f0d648e648a08bb8fbc33909fe894f7d5fff4918", "size": 538, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "vendor/IREGI/src/qcdloop/ql/qlconstants.f", "max_stars_repo_name": "valassi/mg5amc_test", "max_stars_repo_head_hexsha": "2e04f23353051f64e1604b23105fe3faabd32869", "max_stars_repo_licenses": ["NCSA"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-10-23T14:37:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-22T20:59:02.000Z", "max_issues_repo_path": "vendor/IREGI/src/qcdloop/ql/qlconstants.f", "max_issues_repo_name": "valassi/mg5amc_test", "max_issues_repo_head_hexsha": "2e04f23353051f64e1604b23105fe3faabd32869", "max_issues_repo_licenses": ["NCSA"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2018-10-08T15:49:32.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-15T13:33:36.000Z", "max_forks_repo_path": "vendor/IREGI/src/qcdloop/ql/qlconstants.f", "max_forks_repo_name": "valassi/mg5amc_test", "max_forks_repo_head_hexsha": "2e04f23353051f64e1604b23105fe3faabd32869", "max_forks_repo_licenses": ["NCSA"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2019-02-18T11:42:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-11T20:46:08.000Z", "avg_line_length": 31.6470588235, "max_line_length": 70, "alphanum_fraction": 0.6672862454, "num_tokens": 241, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554445, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.652850479570333}} {"text": " SUBROUTINE FFTSET(NP2)\n COMMON /WTABLE/ M,N,NV2,NM1,WSAVE(24)\nC\n DATA PI /3.14159265/\nC\n M = NP2\n N = 2**M\n NV2 = N/2\n NM1 = N-1\n LE = 1\n DO 20 L = 1,M\n WSAVE(2*L-1) = COS(PI/LE)\n WSAVE(2*L) = SIN(PI/LE)\n LE = 2*LE\n 20 CONTINUE\n RETURN\n END\n\n", "meta": {"hexsha": "1e01df1dc9bc0d5c2b7ac457af41e7a60aed4566", "size": 315, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/fftset_1.for", "max_stars_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_stars_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/fftset_1.for", "max_issues_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_issues_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "WAVES_VMS_Fortran/PJK_Fortran/wind_dir/fftset_1.for", "max_forks_repo_name": "lynnbwilsoniii/Wind_Decom_Code", "max_forks_repo_head_hexsha": "ef596644fe0ed3df5ff3b462602e7550a04323e2", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.5789473684, "max_line_length": 43, "alphanum_fraction": 0.453968254, "num_tokens": 141, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181875, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6528504751199197}} {"text": "\tSUBROUTINE MODDSRATIO\r\n . (ALPHA,POWER,PHI,P0,N,M,resultPSI_L,resultPSI_H)\r\n!MS$ATTRIBUTES REFERENCE :: resultPSI_L\r\n!MS$ATTRIBUTES REFERENCE :: resultPSI_H\r\n\tIMPLICIT NONE\r\n\r\n\tREAL ALPHA,POWER,PHI,P0,N,M,resultPSI_L,resultPSI_H\r\nC\r\nC-Description-----------------------------------------------------------\r\nC\r\nC Function:\r\nC\tDetermine the value of the odds ratio that can be detected\r\nC\twith power 1-BETA from a matched case-control study.\r\nC\t\r\nC Input prompted for from user:\r\nC\tALPHA\tType I error probability for a two sided test\r\nC\tPOWER\tThe desired statistical power\r\nC\tPHI\t\tCorrelation coefficient\r\nC\tP0\t\tProbability of exposure in control group\r\nC\tN\t\tNumber of case patients\r\nC\tM\t\tNumber of matched controls per case patient\r\nC\r\nC Output:\r\nC\tresultPSI_L,resultPSI_H\tOdds ratio\r\nC\t\t-or-\r\nC -1 if the power associated with the odds ratio (100.) is less\r\nC\t\t than 1-BETA.\r\nC\t\t\t\tor\r\nC -2 if no odds ratio exists with the required power given P0 and R.\r\nC\t\t\t\tor\r\nC -3 if N is too small to permit valid normal approximations.\r\nC\r\nC Notes:\r\nC .\tThis routine was written by Dale Plummer.\r\nC .\tReference:\r\nC\t Dupont, WD: \"Power Calculations for Matched Case-Control\r\nC\t Studies\", Biometrics, 1988; 44:1157-1168\r\nC .\tLink with subroutines in file SUBS.FOR\r\nC\r\nC-Declarations----------------------------------------------------------\r\nC\r\nC Locals\r\nC\r\n\tINTEGER ITMAX, ERRORL, ERRORH\r\n\tREAL ERRABS, ERRREL\r\n\tREAL A,B\r\n\r\n\tREAL ITERATED_POWER_FUNCTION\r\n\tEXTERNAL ITERATED_POWER_FUNCTION\r\n\t\r\n\tREAL XALPHA,XPOWER,XPHI,XP0,XN,XM\r\n\tCOMMON/MORCOMM/XALPHA,XPOWER,XPHI,XP0,XN,XM\r\nC\r\nC-Code------------------------------------------------------------------\r\nC\r\nC\r\nC Load the common memory.\r\nC\r\n\tXALPHA=ALPHA\r\n\tXPOWER=POWER\r\n\tXPHI=PHI\r\n\tXP0=P0\r\n\tXN=N\r\n\tXM=M\r\nc\r\nc Find the lower solution.\r\nc\r\n\tERRABS = 1.0E-3\r\n\tERRREL = 1.0E-3\r\n\tITMAX = 100\r\n\tA=.01\r\n\tB=.99\r\nc\tCALL ZBREN (ITERATED_POWER_FUNCTION, ERRABS, ERRREL, A, B, ITMAX)\r\nC\tRESULTPSI_L=B\r\n\tCALL BISEC(A,B,ERRABS,ERRREL,ITERATED_POWER_FUNCTION,\r\n .\tRESULTPSI_L,ERRORL)\r\n\tIF (ERRORL.NE.0) RESULTPSI_L=-999\r\nc\r\nc Find the upper solution.\r\nc\r\n\tERRABS = 1.0E-3\r\n\tERRREL = 1.0E-3\r\n\tITMAX = 100\r\n\tA=1.01\r\n\tB=100000\r\nC\tCALL ZBREN (ITERATED_POWER_FUNCTION, ERRABS, ERRREL, A, B, ITMAX)\r\nC\tRESULTPSI_H=B\r\n\tCALL BISEC(A,B,ERRABS,ERRREL,ITERATED_POWER_FUNCTION,\r\n .\tRESULTPSI_H,ERRORH)\r\n\tIF (ERRORH.NE.0) RESULTPSI_H=-999 \r\n\r\n\tRETURN\r\n\tEND\r\n!--------------------------------------------------------------\t\r\n\tREAL FUNCTION ITERATED_POWER_FUNCTION(XPSI)\r\n!\r\n! This is function to find the zero when determining the\r\n! dichotomous, independemt detectable odds ratio.\r\n!\r\n\tIMPLICIT NONE\r\n\t\r\n\tREAL XPSI\r\n\tREAL SPOWER\r\n\tINTEGER ERR\r\n\tREAL ZALPHA, ZCRVALUE\r\n\tINTEGER IN, IM \r\n \r\n \tREAL XALPHA,XPOWER,XPHI,XP0,XN,XM\r\n\tCOMMON/MORCOMM/XALPHA,XPOWER,XPHI,XP0,XN,XM\r\n \tREAL LOCALPOWER\r\n!\r\n! Code.\r\n!\r\n\tIN=XN\r\n\tIM=XM\r\n\tZALPHA=ZCRVALUE(XALPHA/2.)\r\n\tCALL POWFCN(ZALPHA,IN,XPHI,XP0,IM,XPSI,SPOWER,ERR)\r\n\tLOCALPOWER=SPOWER\r\n\tITERATED_POWER_FUNCTION=XPOWER-LOCALPOWER\r\n\t\r\n\tRETURN\r\n\tEND\r\n", "meta": {"hexsha": "e451e6b657b89d5326af7e49f94341d5d68e3ea5", "size": 3064, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "misc/old_ps/ps-development-version/psDll/moddsrat.for", "max_stars_repo_name": "vubiostat/ps", "max_stars_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2017-12-29T14:19:14.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-06T15:08:46.000Z", "max_issues_repo_path": "misc/old_ps/ps-development-version/psDll/moddsrat.for", "max_issues_repo_name": "vubiostat/ps", "max_issues_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2020-04-30T16:57:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-07T00:26:02.000Z", "max_forks_repo_path": "misc/old_ps/ps-development-version/psDll/moddsrat.for", "max_forks_repo_name": "vubiostat/ps", "max_forks_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-07T20:11:54.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-11T19:18:59.000Z", "avg_line_length": 24.9105691057, "max_line_length": 75, "alphanum_fraction": 0.6494778068, "num_tokens": 988, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181875, "lm_q2_score": 0.7371581510799253, "lm_q1q2_score": 0.6528504597780044}} {"text": "program tarefaa2\n implicit real(8) (a-h,o-z)\n character(70) c_filename\n character(10) c_planeta\n parameter (pi=4d0*atan(1d0))\n dimension ri(2), rmi(2), d2rdt2(2), v(2)\n\n n = 5d4\n\n open(20, file='entrada-a2-10407962.dat')\n\n do j = 1, 9\n read(20,*) c_planeta, a_Mp, a_raio, a_exce, v0\n\n write(c_filename, '(A,A,A)') 'saida-a2-', trim(c_planeta), '-10407962.dat'\n\n Tp = sqrt(a_raio**3d0)\n dt = Tp/n\n GMs = 4*pi**2\n\n! v0 = sqrt(GMs*(1-a_exce)/(a_raio*(1+a_exce)))\n v = (/0d0, v0 /)\n\n write(*,*) c_planeta, Tp**2/a_raio**3, v0\n\n ri = (/ a_raio*(1+a_exce), 0d0 /)\n rmi = ri +v*dt\n\n open(10, file=c_filename)\n\n write(10, *) ri\n\n do i = 1, n\n d2rdt2 = -GMs*ri/dnorm(ri)**3\n\n call verlet(rmi, ri, d2rdt2, dt)\n\n write(10, *) ri\n end do\n\n close(10)\n end do\n\ncontains\n function dnorm(r)\n implicit real(8) (a-h,o-z)\n dimension r(2)\n dnorm = sqrt(r(1)**2 + r(2)**2)\n return\n end function\n\n subroutine verlet(ri, rmi, d2rdt2, dt)\n implicit real(8) (a-h,o-z)\n dimension ri(2), rmi(2), raux(2), d2rdt2(2)\n\n raux = ri\n ri = 2*ri - rmi + d2rdt2*dt**2\n rmi = raux\n end subroutine\n\nend program tarefaa2\n", "meta": {"hexsha": "f5efe2c7358e0b551534a0cebfc10e1f0d0187cd", "size": 1322, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "projeto-6/tarefa-a/tarefa-a2-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-6/tarefa-a/tarefa-a2-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-6/tarefa-a/tarefa-a2-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": 21.3225806452, "max_line_length": 82, "alphanum_fraction": 0.5090771558, "num_tokens": 505, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528094861981, "lm_q2_score": 0.766293653760418, "lm_q1q2_score": 0.6528460312126321}} {"text": "* Home work #1\r\n\r\n* Question (3)\r\n* Draw flow chart and write a FORTRAN program which\r\n* calculates (to five decimal places):\r\n* a) 1/1 +1/3 +1/5 +1/7 +1/21\r\n* b) 2/1 * 4/3 * 6/5 * 22/21\r\n\r\n write(*,*) ' write any number to start'\r\n read(*,*)a\r\n a=a/a\r\n b=a/1+a/3+a/5+a/7+a/21\r\n c=(2.0/1.0)*(4.0/3.0)*(6.0/5.0)*(22.0/21.0)\r\n write(*,*) ' (1/1 +1/3 +1/5 +1/7 +1/21) equals '\r\n write(*,10)b\r\n write(*,*)\r\n write(*,*) ' (2/1 * 4/3 * 6/5 * 22/21) equals '\r\n write(*,10)c\r\n10 format(f 8.5)\r\n\r\n stop\r\n end\r\n\r\n\r\n\r\n", "meta": {"hexsha": "fcc3e987ab97d3ba359c2bd6433a9c01ee1969f1", "size": 633, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "HW(1)/Problem (3)/Hw_1_problem_3_.f", "max_stars_repo_name": "Melhabbash/Computational-Physics-", "max_stars_repo_head_hexsha": "82a92e629fbaaf053d2f5e1ccb1224389b2e94be", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "HW(1)/Problem (3)/Hw_1_problem_3_.f", "max_issues_repo_name": "Melhabbash/Computational-Physics-", "max_issues_repo_head_hexsha": "82a92e629fbaaf053d2f5e1ccb1224389b2e94be", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HW(1)/Problem (3)/Hw_1_problem_3_.f", "max_forks_repo_name": "Melhabbash/Computational-Physics-", "max_forks_repo_head_hexsha": "82a92e629fbaaf053d2f5e1ccb1224389b2e94be", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.3461538462, "max_line_length": 58, "alphanum_fraction": 0.4075829384, "num_tokens": 253, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528019683106, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6528460163575879}} {"text": "c prog5\nc c.l.lawson and r.j.hanson, jet propulsion laboratory, 1973 jun 12\nc to appear in 'solving least squares problems', prentice-hall, 1974\nc\t example of the use of subroutines bndacc and bndsol to solve\nc sequentially the banded least squares problem which arises in\nc spline curve fitting.\nc\n dimension x(12),y(12),b(10),g(12,5),c(12),q(4),cov(12)\nc\nc\t define functions p1 and p2 to be used in constructing\nc\t cubic splines over uniformly spaced breakpoints.\nc\n p1(t)=.25*t**2*t\n p2(t)=-(1.-t)**2*(1.+t)*.75+1.\n zero=0.\nc\n write (6,230)\n mdg=12\n nband=4\n m=12\nc\t\t\t\t set ordinates of data\n y(1)=2.2\n y(2)=4.0\n y(3)=5.0\n y(4)=4.6\n y(5)=2.8\n y(6)=2.7\n y(7)=3.8\n y(8)=5.1\n y(9)=6.1\n y(10)=6.3\n y(11)=5.0\n y(12)=2.0\nc\t\t\t\t set abcissas of data\n\t do 10 i=1,m\n 10\t x(i)=2*i\nc\nc begin loop thru cases using increasing nos of breakpoints.\nc\n\t do 150 nbp=5,10\n\t nc=nbp+2\nc\t\t\t\t set breakpoints\n\t b(1)=x(1)\n\t b(nbp)=x(m)\n\t h=(b(nbp)-b(1))/float(nbp-1)\n\t if (nbp.le.2) go to 30\n\t\tdo 20 i=3,nbp\n 20\t\tb(i-1)=b(i-2)+h\n 30\t continue\n\t write (6,240) nbp,(b(i),i=1,nbp)\nc\nc initialize ir and ip before first call to bndacc.\nc\n\t ir=1\n\t ip=1\n\t i=1\n\t jt=1\n 40\t mt=0\n 50\t continue\n\t if (x(i).gt.b(jt+1)) go to 60\nc\nc\t\t\t set row for ith data point\nc\n\t u=(x(i)-b(jt))/h\n\t ig=ir+mt\n\t g(ig,1)=p1(1.-u)\n\t g(ig,2)=p2(1.-u)\n\t g(ig,3)=p2(u)\n\t g(ig,4)=p1(u)\n\t g(ig,5)=y(i)\n\t mt=mt+1\n\t if (i.eq.m) go to 60\n\t i=i+1\n\t go to 50\nc\nc\t\t send block of data to processor\nc\n 60\t continue\n\t call bndacc (g,mdg,nband,ip,ir,mt,jt)\n\t if (i.eq.m) go to 70\n\t jt=jt+1\n\t go to 40\nc\t\t compute solution c()\n 70\t continue\n\t call bndsol (1,g,mdg,nband,ip,ir,c,nc,rnorm)\nc\t\t write solution coefficients\n\t write (6,180) (c(l),l=1,nc)\n\t write (6,210) rnorm\nc\nc\t compute and print x,y,yfit,r=y-yfit\nc\n\t write (6,160)\n\t jt=1\n\t\tdo 110 i=1,m\n 80\t\tif (x(i).le.b(jt+1)) go to 90\n\t\tjt=jt+1\n\t\tgo to 80\nc\n 90\t\tu=(x(i)-b(jt))/h\n\t\tq(1)=p1(1.-u)\n\t\tq(2)=p2(1.-u)\n\t\tq(3)=p2(u)\n\t\tq(4)=p1(u)\n\t\tyfit=zero\n\t\t do 100 l=1,4\n\t\t ic=jt-1+l\n 100\t\t yfit=yfit+c(ic)*q(l)\n\t\tr=y(i)-yfit\n\t\twrite (6,170) i,x(i),y(i),yfit,r\n 110\t\tcontinue\nc\nc compute residual vector norm.\nc\n\t if (m.le.nc) go to 150\n\t sigsq=(rnorm**2)/float(m-nc)\n\t sigfac=sqrt(sigsq)\n\t write (6,220) sigfac\n\t write (6,200)\nc\nc compute and print cols. of covariance.\nc\n\t\tdo 140 j=1,nc\n\t\t do 120 i=1,nc\n 120\t\t cov(i)=zero\n\t\tcov(j)=1.\n\t\tcall bndsol (2,g,mdg,nband,ip,ir,cov,nc,rdummy)\n\t\tcall bndsol (3,g,mdg,nband,ip,ir,cov,nc,rdummy)\nc\nc compute the jth col. of the covariance matrix.\n\t\t do 130 i=1,nc\n 130\t\t cov(i)=cov(i)*sigsq\n 140\t\twrite (6,190) (l,j,cov(l),l=1,nc)\n 150\t continue\n stop\n 160 format (4h0 i,8x,1hx,10x,1hy,6x,4hyfit,4x,8hr=y-yfit/1x)\n 170 format (1x,i3,4x,f6.0,4x,f6.2,4x,f6.2,4x,f8.4)\n 180 format (4h0c =,10f10.5/(4x,10f10.5))\n 190 format (4(02x,2i5,e15.7))\n 200 format (46h0covariance matrix of the spline coefficients.)\n 210 format (9h0rnorm\t=,e15.8)\n 220 format (9h0sigfac =,e15.8)\n 230 format (50h1prog5. execute a sequence of cubic spline fits,27h\n 1to a discrete set of data.)\n 240 format (1x////,11h0new case..,/47h0number of breakpoints, includin\n 1g endpoints, is,i5/14h0breakpoints =,10f10.5,/(14x,10f10.5))\n end\n", "meta": {"hexsha": "5484b846ff5a97dc54d90cf9ca7607c9e44e1a58", "size": 3463, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iraf.v2161/math/llsq/progs/prog5.f", "max_stars_repo_name": "ysBach/irafdocgen", "max_stars_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:19:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T16:48:42.000Z", "max_issues_repo_path": "math/llsq/progs/prog5.f", "max_issues_repo_name": "kirxkirx/iraf", "max_issues_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-30T13:48:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-02T19:40:25.000Z", "max_forks_repo_path": "math/llsq/progs/prog5.f", "max_forks_repo_name": "kirxkirx/iraf", "max_forks_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.5578231293, "max_line_length": 72, "alphanum_fraction": 0.5734911926, "num_tokens": 1533, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527944504227, "lm_q2_score": 0.7662936484231889, "lm_q1q2_score": 0.6528460151437455}} {"text": "! Copyright (c) 2017-2018 Etienne Descamps\n! All rights reserved.\n!\n! Redistribution and use in source and binary forms, with or without modification,\n! are permitted provided that the following conditions are met:\n!\n! 1. Redistributions of source code must retain the above copyright notice,\n! this list of conditions and the following disclaimer.\n!\n! 2. Redistributions in binary form must reproduce the above copyright notice,\n! this list of conditions and the following disclaimer in the documentation and/or\n! other materials provided with the distribution.\n!\n! 3. Neither the name of the copyright holder nor the names of its contributors may be\n! used to endorse or promote products derived from this software without specific prior\n! written permission.\n!\n! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\n! ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n! WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n! IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n! INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n! (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n! THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\n! NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\n! EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\nProgram test_cmaes\n Use ieee_arithmetic\n Use iso_c_binding\n Use mlf_intf\n Use mlf_rsc_array\n Use mlf_utils\n Use mlf_matrix\n Use mlf_fun_intf\n Use mlf_cmaes\n Use mlf_optim\n Use test_functions\n integer :: lambda=120, ND = 30, Nmax = 2000, Niter = 30, NFirst\n integer :: larg = 32, info\n real(c_double) :: ftarget = 1.0e-10\n real(c_double), allocatable :: X0(:)\n character(len=32) :: arg\n type (mlf_maes_obj), target :: maesOpt\n type (mlf_cmaes_obj), target :: cmaesOpt\n class (mlf_matrix_es_obj), pointer :: optObj => maesOpt\n type (mlf_objective_test) :: fTest\n procedure (mlf_obj_test_fun), pointer :: optFun\n type(mlf_optim_param) :: p\n optFun => OFrosenbrock\n if(COMMAND_ARGUMENT_COUNT()>0) then\n call GET_COMMAND_ARGUMENT(1, arg, larg)\n select case (arg)\n case('sphere')\n optFun => OFsphere\n case('cigar')\n optFun => OFcigar\n case('tablet')\n optFun => OFtablet\n case('ellipsoid')\n optFun => OFellipsoid\n case('rosenbrock')\n optFun => OFrosenbrock\n case default\n print *, \"Error invalid function name\"\n optFun => OFrosenbrock\n end select\n endif \n\n if(COMMAND_ARGUMENT_COUNT()>1) then\n larg = 32\n call GET_COMMAND_ARGUMENT(2, arg, larg)\n select case (arg)\n case('cmaes')\n optObj => cmaesOpt\n case('maes')\n optObj => maesOpt\n case default\n print *, \"Error invalid method name\"\n optObj => cmaesOpt\n end select\n else\n optObj => cmaesOpt\n endif\n if(COMMAND_ARGUMENT_COUNT()>2) then\n larg = 32\n call GET_COMMAND_ARGUMENT(3, arg, larg)\n read(arg,*,iostat=info) ND\n endif\n if(COMMAND_ARGUMENT_COUNT()>3) then\n larg = 32\n call GET_COMMAND_ARGUMENT(4, arg, larg)\n read(arg,*,iostat=info) lambda\n endif\n if(COMMAND_ARGUMENT_COUNT()>4) then\n larg = 32\n call GET_COMMAND_ARGUMENT(5, arg, larg)\n read(arg,*,iostat=info) Nmax\n endif\n if(COMMAND_ARGUMENT_COUNT()>5) then\n larg = 32\n call GET_COMMAND_ARGUMENT(6, arg, larg)\n read(arg,*,iostat=info) ftarget\n endif\n if(COMMAND_ARGUMENT_COUNT()>6) then\n larg = 32\n call GET_COMMAND_ARGUMENT(7, arg, larg)\n read(arg,*,iostat=info) Niter\n endif\n call fTest%init(optFun, ND)\n ALLOCATE(X0(ND))\n call p%init(fTest, lambda)\n Select Type(optObj)\n class is (mlf_maes_obj)\n info = optObj%init(params = p)\n class is (mlf_cmaes_obj)\n info = optObj%init(params = p, covEvery = 1)\n End Select\n DEALLOCATE(X0)\n call optObj%constraints_step(niterMax = int(nMax, kind=8))\n call optObj%constraints_optim(targetFun = ftarget)\n Do While (optObj%step() == 0)\n print *, optObj%niter, optObj%cputime, optObj%realtime, optObj%minFun, optObj%sigma\n End Do\n print *, optObj%minX\n Select Type(optObj)\n class is (mlf_maes_obj)\n print *, \"Algorithm MA-ES\"\n class is (mlf_cmaes_obj)\n print *, \"Algorithm CMA-ES\"\n End Select\n if(COMMAND_ARGUMENT_COUNT()>0) then\n call GET_COMMAND_ARGUMENT(1, arg, larg)\n print *, \"Function: \", arg\n else\n print *, \"Function: rosenbrock\"\n endif\n print *, \"NDim: \", ND, \"lambda: \", lambda, \"mu: \", lambda/2\nEnd\n\n", "meta": {"hexsha": "23456eaaef19cf477ac76a03f22a32077fdd1689", "size": 4636, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/test_cmaes.f90", "max_stars_repo_name": "Etdescamps/MlFortran", "max_stars_repo_head_hexsha": "c35a041ee01125b0f9df443c9bb0a42411b3c41e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-19T16:48:02.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-19T16:48:02.000Z", "max_issues_repo_path": "tests/test_cmaes.f90", "max_issues_repo_name": "Etdescamps/MlFortran", "max_issues_repo_head_hexsha": "c35a041ee01125b0f9df443c9bb0a42411b3c41e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/test_cmaes.f90", "max_forks_repo_name": "Etdescamps/MlFortran", "max_forks_repo_head_hexsha": "c35a041ee01125b0f9df443c9bb0a42411b3c41e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.6478873239, "max_line_length": 90, "alphanum_fraction": 0.7077221743, "num_tokens": 1335, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527869325346, "lm_q2_score": 0.7662936430859597, "lm_q1q2_score": 0.6528460048357684}} {"text": " SUBROUTINE laguer(a,m,x,its)\r\n INTEGER m,its,MAXIT,MR,MT\r\n REAL EPSS\r\n COMPLEX a(m+1),x\r\n PARAMETER (EPSS=2.e-7,MR=8,MT=10,MAXIT=MT*MR)\r\n INTEGER iter,j\r\n REAL abx,abp,abm,err,frac(MR)\r\n COMPLEX dx,x1,b,d,f,g,h,sq,gp,gm,g2\r\n SAVE frac\r\n DATA frac /.5,.25,.75,.13,.38,.62,.88,1./\r\n do 12 iter=1,MAXIT\r\n its=iter\r\n b=a(m+1)\r\n err=abs(b)\r\n d=cmplx(0.,0.)\r\n f=cmplx(0.,0.)\r\n abx=abs(x)\r\n do 11 j=m,1,-1\r\n f=x*f+d\r\n d=x*d+b\r\n b=x*b+a(j)\r\n err=abs(b)+abx*err\r\n11 continue\r\n err=EPSS*err\r\n if(abs(b).le.err) then\r\n return\r\n else\r\n g=d/b\r\n g2=g*g\r\n h=g2-2.*f/b\r\n sq=sqrt((m-1)*(m*h-g2))\r\n gp=g+sq\r\n gm=g-sq\r\n abp=abs(gp)\r\n abm=abs(gm)\r\n if(abp.lt.abm) gp=gm\r\n if (max(abp,abm).gt.0.) then\r\n dx=m/gp\r\n else\r\n dx=exp(cmplx(log(1.+abx),float(iter)))\r\n endif\r\n endif\r\n x1=x-dx\r\n if(x.eq.x1)return\r\n if (mod(iter,MT).ne.0) then\r\n x=x1\r\n else\r\n x=x-dx*frac(iter/MT)\r\n endif\r\n12 continue\r\n pause 'too many iterations in laguer'\r\n return\r\n END\r\n", "meta": {"hexsha": "3ed1efbe7307616f1ebfa3ed27f4afe69270f6cc", "size": 1313, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/laguer.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/laguer.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/laguer.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.3148148148, "max_line_length": 52, "alphanum_fraction": 0.4219345011, "num_tokens": 452, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361652391385, "lm_q2_score": 0.7154239957834733, "lm_q1q2_score": 0.6527787272327339}} {"text": "C LAST UPDATE 29/11/94\nC+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\nC\n SUBROUTINE CIRSPL(X,Y,N,Y2)\n IMPLICIT NONE\nC\nC Purpose: Given arrays X and Y of length N containing a tabulated\nC function, Yi = f(Xi), with X1 TOL) ! take the singular values > tol\n allocate(d2(r,r))\n d2 = Diag(1.0 / d(1:r))\n ai = matmul(matmul(v(:,1:r), d2),transpose(u(:,1:r)))\n deallocate(d2)\n end function Pinv\n\n subroutine Svd(a, u, s, v, nite)\n ! Singular value decomposition\n implicit none\n real(DP), dimension(:,:), intent(in) :: a\n real(DP), dimension(size(a,1), size(a,2)), intent(out) :: u\n real(DP), dimension(size(a,2), size(a,2)), intent(out) :: s, v\n integer, intent(out) :: nite\n real(DP), dimension(size(a,1), size(a,2)) :: q1\n real(DP), dimension(size(a,1), size(a,1)) :: u1\n real(DP), dimension(size(a,2), size(a,2)) :: q, e \n real(DP), dimension(size(a,2)) :: f\n real(DP), parameter :: EPS = 1e-4\n real(DP) :: err\n integer :: n \n ! init u,v,u1\n u = 0.0\n v = 0.0\n u1 = 0.0\n forall (n=1:size(a,1)) u1(n,n) = 1.0\n forall (n=1:size(a,2)) v(n,n) = 1.0\n ! initial state:\n call Qr(a, q1, s)\n U = matmul(u1, q1)\n call Qr(transpose(s), q, s)\n v = matmul(v, q)\n ! iterate while converged:\n nite = 1\n do\n call Qr(transpose(s), q, s)\n u = matmul(u, q)\n call Qr(transpose(s), q, s)\n v = matmul(v, q)\n ! check the error:\n e = Triu(s)\n f = Diag(s)\n err = Norm(reshape(e, [size(e,1)*size(e,2)])) / Norm(f)\n nite = nite + 1\n if (err < EPS) exit\n end do\n end subroutine Svd\n\n function Diag_ele(A) result(v)\n ! Diagonal elements\n implicit none\n real(DP), dimension(:,:), intent(in) :: a\n real(DP), dimension(:), allocatable :: v\n integer :: i, n\n n = minval([size(a,1), size(a,2)]) \n allocate(v(n)) \n forall(i=1:n) v(i) = a(i,i)\n end function Diag_ele\n\n function Diag_mat(v) result(a)\n ! Diagonal matrix\n implicit none\n real(DP), dimension(:), intent(in) :: v\n real(DP), dimension(size(v), size(v)) :: a\n integer :: i\n a = 0.0\n forall(i=1:size(v)) a(i,i) = v(i)\n end function Diag_mat\n\n function Triu(a) result(au)\n ! Upper triangular part\n implicit none\n real(DP), dimension(:,:), intent(in) :: a\n real(DP), dimension(size(a,1), size(a,2)) :: au\n integer :: n, m, i, j\n au = 0.0\n m = size(a,1)\n n = size(a,2)\n do i = 1, m\n do j = i+1, n\n if (i+1 <= n) au(i,j) = a(i,j)\n end do\n end do\n end function Triu\n \n subroutine Qr(a,q,r)\n ! Modified Gram-Schmidt process\n implicit none\n real(DP), dimension(:,:), intent(in) :: a\n real(DP), dimension(size(a,1), size(a,2)), intent(out) :: q\n real(DP), dimension(size(a,2), size(a,2)), intent(out) :: r\n real(DP), dimension(size(a,1), size(a,2)) :: a0\n integer :: k,n\n n = size(a,2)\n q = 0.0\n r = 0.0\n a0 = a\n do k = 1, n\n r(k,k) = Norm(a0(:,k))\n q(:,k) = a0(:,k) / r(k,k)\n r(k,k+1:n) = matmul(q(:,k), a0(:,k+1:n))\n a0(:,k+1:n) = a0(:,k+1:n) - matmul(q(:,k:k), r(k:k,k+1:n))\n end do\n end subroutine Qr\n\n subroutine Levmar(Resfun, Jacfun, theta, cmat, r, rss, data)\n ! Levenberq-Marquardt optimization of \"theta\" parameters\n implicit none\n real(DP), dimension(:), intent(inout) :: theta\n real(DP), dimension(:,:), allocatable, intent(out) :: cmat\n real(DP), intent(out) :: rss\n type(obs), intent(in) :: data\n real(DP), dimension(data%nobs+size(theta)), intent(out) :: r \n real(DP), dimension(data%nobs+size(theta), size(theta)) :: j\n real(DP), dimension(size(theta), size(theta)) :: jj, jj_mod\n real(DP), dimension(size(theta)) :: h, jr\n real(DP) :: rssold, lam\n real(DP), parameter :: ABSTOL = 1e-6 ! convergence tolerance\n integer :: ite\n ! this kind of interface is needed when \n ! passing functions as arguments\n interface\n function Resfun(data, theta) result(r)\n use global_variables\n implicit none\n type(obs), intent(in) :: data\n real(DP), dimension(:), intent(in) :: theta\n real(DP), dimension(data%nobs) :: r\n end function Resfun\n function Jacfun(data, theta) result(j)\n use global_variables\n implicit none\n type(obs), intent(in) :: data\n real(DP), dimension(:), intent(in) :: theta\n real(DP), dimension(data%nobs, size(theta)) :: j\n end function Jacfun\n end interface\n ite = 0\n ! initial nudge factor\n lam = 1e-3\n ! initial residuals\n r = Resfun(data, theta)\n rss = sum(r**2) / (size(r) - size(theta))\n call Write_info(rss, ite, lam, .true.)\n ! iterate while converged\n do\n ite = ite + 1\n rssold = rss\n j = Jacfun(data, theta)\n jj = matmul(transpose(j), j)\n do\n jj_mod = (jj + lam*Diag(Diag(jj)))\n jr = matmul(transpose(j), r)\n h = matmul(Pinv(jj_mod), jr) \n r = Resfun(data, theta+h)\n rss = sum(r**2) / (size(r) - size(theta))\n ! increase lam until rss decreases\n if (rss >= rssold) lam = lam*10.0\n if (abs((rss-rssold)/(rss+0.1)) < abstol) exit\n if (rss < rssold) exit\n end do\n call Write_info(rss,ite,lam)\n theta = theta+h\n if (abs((rss-rssold)/(rss+0.1)) < abstol) exit\n lam = lam/10.0\n end do\n ! estimate of the error covariance at the optimum\n cmat = Pinv(jj)*rss\n end subroutine Levmar\n\n subroutine Write_info(rss, ite, lam, isfirst)\n ! Write some info about LM-iteration\n implicit none\n real(DP), intent(in) :: rss, lam\n integer, intent(in) :: ite\n logical, optional, intent(in) :: isfirst\n character(len=*), parameter :: FORM = '(4x,i2,4x,f12.7,4x,es8.1)'\n if (present(isfirst) .and. isfirst) then\n write(*,*) '----------------------------------' \n write(*,'(1x,a9,5x,a3,10x,a3)') 'Iteration', 'RSS', 'lam'\n write(*,*) '----------------------------------'\n write(*,FORM) ite, rss, lam\n else\n write(*,FORM) ite, rss, lam\n end if\n end subroutine Write_info\n \nend module math\n", "meta": {"hexsha": "315f3b8f9390b7a97cd31aef93d3d11fed414276", "size": 7466, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/math.f90", "max_stars_repo_name": "tukiains/dimred-fortran", "max_stars_repo_head_hexsha": "4c3165dd60ee05607aa973b1addc246e358e4f25", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-05-16T06:59:23.000Z", "max_stars_repo_stars_event_max_datetime": "2018-05-16T06:59:23.000Z", "max_issues_repo_path": "src/math.f90", "max_issues_repo_name": "tukiains/dimred-fortran", "max_issues_repo_head_hexsha": "4c3165dd60ee05607aa973b1addc246e358e4f25", "max_issues_repo_licenses": ["MIT"], "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.f90", "max_forks_repo_name": "tukiains/dimred-fortran", "max_forks_repo_head_hexsha": "4c3165dd60ee05607aa973b1addc246e358e4f25", "max_forks_repo_licenses": ["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.7242798354, "max_line_length": 82, "alphanum_fraction": 0.5463434235, "num_tokens": 2542, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.900529778109184, "lm_q2_score": 0.7248702702332476, "lm_q1q2_score": 0.6527672636110907}} {"text": "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC\nC Written by: Anshuk Attri\nC\nC Contact: contact@anshukattri.in\nC Website: www.anshukattri.in/research\nC GITHUB: github.com/aa-tree/\nC\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n\n\n SUBROUTINE CONVERGENCE_TEST_VECTOR(V_APPROX, V_EXACT, O_RESULT)\n\n REAL*8 V_APPROX(6), V_EXACT(6)\n REAL*8 O_RESULT(2)\n\n! SUMMARY:\n!\n! This routine computes the convergence of two vectors. It\n! accepts two inputs, the vector for which you want the result,\n! and the vector you want to compare it to. The result\n! contains the absolute and relative errors between the two vectos.\n!\n! VARIABLES:\n!\n! NAME TYPE DESCRIPTION\n!\n! V_APPROX(6) Input(REAL*8) The vector for which you want\n! to calculate the error values.\n!\n! V_EXACT(6) Input(REAL*8) The vector which that target\n! vector is supposed to be\n! compared to.\n!\n! O_RESULT(2) Output(REAL*8) The output containing error\n! values. O_RESULT(1) holds the\n! Absolute Error, and O_RESULT(2)\n! hold the Relative Error.\n\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n\n INTEGER I\n REAL*8 V_DIFF(3)\n REAL*8 MOD_DIFF, MOD_EXACT\n\n DO I=1,3\n V_DIFF(I)=V_APPROX(I)-V_EXACT(I)\n ! write(*,*) 'Vec diff', V_APPROX(I), V_EXACT(I), v_diff(i)\n END DO\n\n DO I=1,2\n O_RESULT(I)=0.0D0\n END DO\n\nC\nC Get two-norm of the vector. (Modulus)\nC\n CALL GET_VEC_MOD(V_DIFF, MOD_DIFF)\n\n CALL GET_VEC_MOD(V_EXACT, MOD_EXACT)\n\nC\nC Calc absolute error.\nC\n O_RESULT(1)= ABS(MOD_DIFF)\n\nC\nC Calc relative error.\nC\n O_RESULT(2)= ABS(MOD_DIFF/MOD_EXACT)\n\n\n RETURN\n END SUBROUTINE\n", "meta": {"hexsha": "9ca02c4f673db673d427bdb483959a0c6af77771", "size": 2121, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "fortran_src/code/CONVERGENCE_TEST_VECTOR.f", "max_stars_repo_name": "aa-tree/SPICEReader", "max_stars_repo_head_hexsha": "3242944556178dbc9a895b3736528e3a57fb46b9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fortran_src/code/CONVERGENCE_TEST_VECTOR.f", "max_issues_repo_name": "aa-tree/SPICEReader", "max_issues_repo_head_hexsha": "3242944556178dbc9a895b3736528e3a57fb46b9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran_src/code/CONVERGENCE_TEST_VECTOR.f", "max_forks_repo_name": "aa-tree/SPICEReader", "max_forks_repo_head_hexsha": "3242944556178dbc9a895b3736528e3a57fb46b9", "max_forks_repo_licenses": ["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.28, "max_line_length": 73, "alphanum_fraction": 0.5770862801, "num_tokens": 550, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920116079209, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.6527501364358319}} {"text": "! { dg-do run }\n! { dg-options \"-O\" }\n! Test the fix for PR31011 in which the length of the array sections\n! with stride other than unity were incorrectly calculated.\n!\n! Contributed by \n!\nprogram PotentialMatrix\n implicit none\n real(kind=8),dimension(2),parameter::v2=(/1,2/)\n real(kind=8),dimension(4),parameter::v4=(/1,2,3,4/)\n if (any (v2*v4(1:3:2) .ne. (/1,6/))) call abort ()\n if (any (v2*v4(3:1:-2) .ne. (/3,2/))) call abort ()\nend\n", "meta": {"hexsha": "aa212c050fa96ca5f0913b8ea30b24fc7c5a7a5a", "size": 457, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/parameter_array_section_2.f90", "max_stars_repo_name": "maurizioabba/rose", "max_stars_repo_head_hexsha": "7597292cf14da292bdb9a4ef573001b6c5b9b6c0", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/parameter_array_section_2.f90", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/parameter_array_section_2.f90", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 30.4666666667, "max_line_length": 68, "alphanum_fraction": 0.6542669584, "num_tokens": 161, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8006919925839875, "lm_q2_score": 0.8152324803738429, "lm_q1q2_score": 0.6527501191297187}} {"text": " subroutine non_linear18\n\nC Check polynomial analysis: power is more precisely analyzed than\nC multiply!\n\n continue\n\n k = n**2 + n\n\n k = n**2 - n\n\n k = n*n + n\n\n k = n*n - n\n\n end\n", "meta": {"hexsha": "80efc38aea03e795adbfa0caa2af768aca41f104", "size": 223, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "packages/PIPS/validation/Semantics/non_linear18.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/Semantics/non_linear18.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/Semantics/non_linear18.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": 13.1176470588, "max_line_length": 70, "alphanum_fraction": 0.5112107623, "num_tokens": 63, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.839733983715524, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.6527251132978715}} {"text": "SUBROUTINE setprob()\n IMPLICIT NONE\n\n INTEGER iunit\n CHARACTER(len=25) fname \n\n DOUBLE PRECISION pi, pi2\n COMMON /compi/ pi, pi2\n\n DOUBLE PRECISION :: grav, dry_tolerance, sea_level\n COMMON /common_swe/ grav, dry_tolerance, sea_level\n\n DOUBLE PRECISION :: alpha, breaking\n COMMON /common_dispersive/ alpha, breaking\n\n DOUBLE PRECISION :: a,b,h0\n COMMON /common_initheight/ a,b,h0\n\n pi = 4.d0*atan(1.d0)\n pi2 = 2*pi\n\n iunit = 10\n fname = 'setprob.data' \n call opendatafile(iunit, fname)\n read(10,*) grav\n read(10,*) dry_tolerance\n read(10,*) sea_level\n\n !! Lannes method\n read(10,*) breaking\n read(10,*) alpha\n\n !! Initial conditions\n read(10,*) a\n read(10,*) b\n read(10,*) h0\n close(10);\n\nend subroutine setprob\n", "meta": {"hexsha": "7f83928e67ac6eadc7d28794db63d4290abf5d2a", "size": 803, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "applications/clawpack/shallow/2d/tsunami/sgn1d/setprob.f90", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2017-09-26T13:39:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:56:23.000Z", "max_issues_repo_path": "applications/clawpack/shallow/2d/tsunami/sgn1d/setprob.f90", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 75, "max_issues_repo_issues_event_min_datetime": "2017-08-02T19:56:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T12:36:32.000Z", "max_forks_repo_path": "applications/clawpack/shallow/2d/tsunami/sgn1d/setprob.f90", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-02-21T00:10:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T19:08:36.000Z", "avg_line_length": 20.075, "max_line_length": 54, "alphanum_fraction": 0.6264009963, "num_tokens": 252, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339756938818, "lm_q2_score": 0.7772998663336157, "lm_q1q2_score": 0.65272510706265}} {"text": "\r\n#include \"Config.fpp\"\r\n\r\nmodule mod_trianglew_signal\r\n\r\n \r\n !===================================================================================85\r\n !---------------------------- DESCRIPTION ------------------------------------------85\r\n !\r\n !\r\n !\r\n ! Module name:\r\n ! 'mod_trianglew_signal'\r\n ! \r\n ! Purpose:\r\n ! Triangle Wave Signal\r\n ! approximated by Fourier Series.\r\n !\r\n ! \r\n ! History:\r\n ! Date: 22-08-2017\r\n ! Time: 07:25 GMT+2\r\n ! Modified:\r\n ! Bernard Gingold on: 11-03-2018, 13:13 GMT+2\r\n ! 1) Refactoring to Fortran 2003 standard.\r\n ! 2) Removing unnecessary type-bound members\r\n ! 3) Adding computational subroutines (additive noise)\r\n ! 4) Removing unnecessary destructor,copy and initialization subroutines.\r\n !\r\n ! Version:\r\n !\r\n ! Major: 1\r\n ! Minor: 0\r\n ! Micro: 0\r\n !\r\n ! Author: Bernard Gingold\r\n ! \r\n ! \r\n ! \r\n ! \r\n ! \r\n ! E-mail:\r\n ! \r\n ! beniekg@gmail.com\r\n !==================================================================================85\r\n\r\n ! Tab:5 col - Type and etc.. definitions\r\n ! Tab:10,11 col - Type , function and subroutine code blocks.\r\n\r\n \r\n \r\n use module_kinds , only : I32P, R64P\r\n use mod_code_timing\r\n use mod_complex_arithm , only : vcmag\r\n use mod_jonesvec\r\n implicit none\r\n private\r\n \r\n \r\n \r\n !=====================================================59\r\n ! File and module information:\r\n ! version,creation and build date, author,description\r\n !=====================================================59\r\n \r\n ! Major version\r\n integer(I32P), parameter, public :: MOD_TRIANGLEW_SIGNAL_MAJOR = 1\r\n \r\n ! Minor version\r\n integer(I32P), parameter, public :: MOD_TRIANGLEW_SIGNAL_MINOR = 0\r\n \r\n ! Micro version\r\n integer(I32P), parameter, public :: MOD_TRIANGLEW_SIGNAL_MICRO = 0\r\n \r\n ! Module/file full version\r\n integer(I32P), parameter, public :: MOD_TRIANGLEW_SIGNAL_FULLVER = 1000*MOD_TRIANGLEW_SIGNAL_MAJOR+100*MOD_TRIANGLEW_SIGNAL_MINOR+ &\r\n 10*MOD_TRIANGLEW_SIGNAL_MICRO\r\n \r\n ! Module creation date\r\n character(*), parameter, public :: MOD_TRIANGLEW_SIGNAL_CREATE_DATE = \"22-08-2017 07:25 +00200 (TUE 22 AUG 2017 GMT+2)\"\r\n \r\n ! Module build date (should be set after successful compilation)\r\n character(*), parameter, public :: MOD_TRIANGLEW_SIGNAL_BUILD_DATE = \" \"\r\n \r\n ! Module author info\r\n character(*), parameter, public :: MOD_TRIANGLEW_SIGNAL_AUTHOR = \"Programmer: Bernard Gingold e-mail: beniekg@gmail.com\"\r\n \r\n ! Module short description\r\n character(*), parameter, public :: MOD_TRIANGLEW_SIGNAL_DESCRIPT = \"Fourier series approximation of triangle wave.\"\r\n \r\n !======================================================60\r\n ! Type: TriangleWSignal_t\r\n !======================================================60\r\n \r\n type, public :: TriangleWSignal_t\r\n \r\n private\r\n \r\n ! Signal name\r\n character(len=64) :: m_name\r\n \r\n ! Signal ID\r\n integer(I32P) :: m_sid\r\n \r\n ! Number of signal samples\r\n integer(I32P) :: m_nsamp\r\n \r\n ! Number of Fourier series\r\n integer(I32P) :: m_maxk\r\n \r\n ! Signal duration\r\n real(R64P) :: m_dur\r\n \r\n ! Triangle wave initial time (starting time-point)\r\n real(R64P) :: m_sinit\r\n \r\n ! Triangle wave increment time-step\r\n real(R64P) :: m_stsinc\r\n \r\n ! Triangle wave carrier frequency\r\n real(R64P) :: m_freq\r\n \r\n \r\n \r\n ! Jones vector field\r\n type(JonesVector_t), allocatable, dimension(:), public :: m_jvec\r\n \r\n ! Sine components of k sinusoids\r\n real(R64P), allocatable, dimension(:,:), public :: m_scomp\r\n!DIR$ ATTRIBUTES ALIGN : 64 :: m_scomp\r\n \r\n ! Cosine components of k sinusoids\r\n real(R64P), allocatable, dimension(:,:), public :: m_ccomp\r\n!DIR$ ATTRIBUTES ALIGN : 64 :: m_ccomp\r\n \r\n ! Triangle carrier frequency (f*t)\r\n real(R64P), allocatable, dimension(:), public :: m_wct\r\n!DIR$ ATTRIBUTES ALIGN : 64 :: m_wct\r\n \r\n ! Signal natural envelope\r\n real(R64P), allocatable, dimension(:), public :: m_nenvp\r\n!DIR$ ATTRIBUTES ALIGN : 64 :: m_nenvp\r\n \r\n ! Triangle wave aproximated by k \r\n ! sinusoids\r\n real(R64P), allocatable, dimension(:), public :: m_triangle\r\n!DIR$ ATTRIBUTES ALIGN : 64 :: m_triangle\r\n \r\n ! Triangle wave complex representation\r\n complex(R64P), allocatable, dimension(:), public :: m_cform\r\n!DIR$ ATTRIBUTES ALIGN : 64 :: m_cform\r\n \r\n ! Electric field\r\n complex(R64P), allocatable, dimension(:), public :: m_E\r\n!DIR$ ATTRIBUTES ALIGN : 64 :: m_E\r\n \r\n ! Signal amplitude A(phi,theta)/r used for calculation electric field\r\n ! far from emmiter(antenna)\r\n real(R64P), allocatable, dimension(:), public :: m_amp\r\n!DIR$ ATTRIBUTES ALIGN : 64 :: m_amp\r\n \r\n ! Time-averaged power density\r\n \r\n complex(R64P), allocatable, dimension(:), public :: m_S\r\n!DIR$ ATTRIBUTES ALIGN : 64 :: m_S\r\n \r\n \r\n \r\n contains\r\n \r\n \r\n \r\n \r\n \r\n ! Creates Triangle wave approximated by Fourier\r\n ! series.\r\n procedure, pass(this), public :: triangwave_signal\r\n \r\n \r\n ! Creates signal with noise modulated phase\r\n procedure, pass(this), public :: phase_noise_triangwave_signal\r\n \r\n \r\n ! Creates signal with noise modulated phase\r\n ! coupled with background additive noise.\r\n procedure, pass(this), public :: additive_noise_triangwave_signal\r\n \r\n \r\n \r\n !==========================================52\r\n ! Getter pure functions\r\n !==========================================52\r\n \r\n procedure, pass(this), public :: get_name\r\n \r\n procedure, pass(this), public :: get_sid\r\n \r\n procedure, pass(this), public :: get_nsamp\r\n \r\n procedure, pass(this), public :: get_maxk\r\n \r\n procedure, pass(this), public :: get_dur\r\n \r\n procedure, pass(this), public :: get_sinit\r\n \r\n procedure, pass(this), public :: get_stsinc\r\n \r\n procedure, pass(this), public :: get_freq\r\n \r\n \r\n \r\n !==================================================60\r\n ! Computational subroutines\r\n !==================================================60\r\n \r\n procedure, pass(this), public :: dphi_dt\r\n \r\n \r\n !==============================================56\r\n ! write/read subroutines\r\n !==============================================56\r\n \r\n procedure, nopass, public :: read_state\r\n \r\n procedure, nopass, public :: write_state\r\n \r\n !===============================================\r\n ! Class helper procedures\r\n !===============================================\r\n \r\n procedure, pass(this) , public :: dbg_info\r\n \r\n !===============================================\r\n ! Generic operators\r\n !===============================================\r\n procedure, public :: copy_assign\r\n \r\n generic :: assignment (=) => copy_assign\r\n \r\n end type TriangleWSignal_t\r\n \r\n interface TriangleWSignal_t\r\n procedure :: constructor\r\n end interface TriangleWSignal_t\r\n \r\n contains\r\n \r\n !======================================================60\r\n ! @function: constructor\r\n ! default initialization (no physical meaning)\r\n !======================================================60\r\n type(TriangleWSignal_t) function constructor(name,sid,nsamp,maxk, &\r\n verbose, logging,filename,append)\r\n \r\n use mod_print_error, only : handle_fatal_memory_error\r\n use mod_constants, only : LAM_PINF, LAM_MINSAMP, &\r\n LAM_MINK\r\n character(len=*), intent(in) :: name\r\n integer(I32P), intent(in) :: sid\r\n integer(I32P), intent(inout) :: nsamp,maxk\r\n logical(I32P), intent(in) :: verbose,logging\r\n character(len=*), intent(in) :: filename\r\n logical(I32P), intent(in) :: appendg\r\n ! Locals\r\n \r\n character(len=256) :: emsg\r\n integer(I32P) :: aerr\r\n ! Start of executable statements\r\n \r\n if(nsamp < LAM_MINSAMP) then\r\n nsamp = LAM_MINSAMP\r\n end if\r\n if(maxk < LAM_MINK) then\r\n maxk = LAM_MINK\r\n end if\r\n ! Begin construction\r\n constructor%m_name = name\r\n constructor%m_sid = sid\r\n constructor%m_nsamp = nsamp\r\n constructor%m_maxk = maxk\r\n constructor%m_dur = LAM_PINF\r\n constructor%m_sinit = LAM_PINF\r\n constructor%m_stsinc = LAM_PINF\r\n constructor%m_freq = LAM_PINF\r\n \r\n associate(k=>constructor%m_maxk, &\r\n n=>constructor%m_nsamp)\r\n allocate(constructor%m_jvec(n), &\r\n constructor%m_scomp(k,n), &\r\n constructor%m_ccomp(k,n), &\r\n constructor%m_wct(n), &\r\n constructor%m_nenvp(n), &\r\n constructor%m_triangle(n), &\r\n constructor%m_cform(n), &\r\n constructor%m_E(n), &\r\n constructor%m_amp(n), &\r\n constructor%m_S(n), &\r\n STAT=aerr, &\r\n ERRMSG=emsg)\r\n end associate\r\n if(aerr /= 0) then\r\n \r\n call handle_fatal_memory_error(logging,verbose,append,filename, &\r\n \"logger:303 --> mod_trianglew_signal/constructor: Memory Allocation Failure!!\" , &\r\n \"mod_trianglew_signal/constructor:303 -- Memory Allocation Failure!!\" , &\r\n emsg,__LINE__ )\r\n end if\r\n constructor%m_jvec = JonesVector_t()\r\n constructor%m_scomp = LAM_PINF\r\n constructor%m_ccomp = LAM_PINF\r\n constructor%m_wct = LAM_PINF\r\n constructor%m_nenvp = LAM_PINF\r\n constructor%m_triangle = LAM_PINF\r\n constructor%m_cform = CMPLX(LAM_PINF,LAM_PINF,R64P)\r\n constructor%m_E = CMPLX(LAM_PINF,LAM_PINF,R64P)\r\n constructor%m_amp = LAM_PINF\r\n constructor%m_S = CMPLX(LAM_PINF,LAM_PINF,R64P)\r\n end function constructor \r\n \r\n \r\n \r\n !======================================================60\r\n ! @subroutine: triangwave_signal \r\n ! Physical representation of Triangle wave\r\n ! approximated by K sinusoids (Fourier-\r\n ! series)\r\n !======================================================60 \r\n subroutine triangwave_signal(this,ierr,dur, &\r\n sinit,stsinc,freq,r,h,v, &\r\n verbose,logging,filename,append, &\r\n profiling,qpctimer )\r\n use mod_print_error, only : handle_fatal_memory_error , &\r\n stderr\r\n use mod_constants, only : LAM_ZR8,LAM_PI,LAM_HR64P,LAM_PINF,LAM_2PI,LAM_c,LAM_MEPS8, &\r\n LAM_dtcoeff, LAM_8OPIE2\r\n class(TriangleWSignal_t), intent(inout) :: this\r\n integer(I32P), intent(inout) :: ierr\r\n real(R64P), intent(inout) :: dur\r\n real(R64P), intent(in) :: sinit,stsinc,freq\r\n real(R64P), dimension(:), intent(in) :: r\r\n!DIR$ ASSUME_ALIGNED r:64\r\n complex(R64P), dimension(:), intent(in) :: h,v\r\n!DIR$ ASSUMED_ALIGNED h:64,v:64\r\n logical(I32P), intent(in) :: verbose,logging\r\n character(len=*), intent(in) :: filename\r\n logical(I32P), intent(in) :: append,profiling\r\n type(QPCTimer_t), intent(inout) :: qpctimer\r\n ! Locals\r\n \r\n character(len=256) :: emsg\r\n integer(I32P) :: i,j,k,aerr\r\n integer(BOOL) :: ifail\r\n logical(I32P) :: bfail,invalid\r\n real(R64P) :: insamp,t,t2,delta\r\n real(R64P), allocatable, dimension(:) :: tcos,ts,tc\r\n!DIR$ ATTRIBUTES ALIGN : 64 :: tcos\r\n!DIR$ ATTRIBUTES ALIGN : 64 :: ts\r\n!DIR$ ATTRIBUTES ALIGN : 64 :: tc \r\n ! Start of executable statements\r\n if(ierr < 0_I32P) ierr = 0_I32P\r\n ! Check if stsinc value lies in interval 1/2^-1 -> 1/2^-16\r\n invalid = .false.\r\n do i = 1, 16\r\n if(DABS(stsinc)-DABS(LAM_dtcoeff(i)) > LAM_MEPS8) then\r\n invalid = .true.\r\n end if\r\n end do\r\n if(invalid == .true.) then\r\n ierr = -2_I32P\r\n return\r\n end if\r\n if(dur.LE.LAM_ZR8) then\r\n ierr = -1_I32P\r\n return\r\n end if \r\n this%m_dur = dur\r\n this%m_sinit = sinit\r\n this%m_stsinc = stsinc\r\n this%m_freq = freq\r\n associate(n=>this%m_nsamp)\r\n allocate( tcos(n), &\r\n ts(n), &\r\n tc(n), &\r\n STAT=aerr, &\r\n ERRMSG=emsg)\r\n end associate \r\n if(aerr /= 0) then\r\n \r\n call handle_fatal_memory_error(logging,verbose,append,filename, &\r\n \"logger:388 --> mod_trianglew_signal/triangwave_signal: Memory allocation failure!!\" , &\r\n \"mod_trianglew_signal/triangwave_signal:388 -- Memory Allocation Failure!\" , &\r\n emsg,__LINE__ )\r\n end if\r\n tcos = LAM_PINF\r\n ts = LAM_PINF\r\n tc = LAM_PINF\r\n \r\n \r\n \r\n if(profiling) then\r\n call qpctimer_start(qpctimer,ifail)\r\n if(ifail.EQ.0) then\r\n write(stderr,*) \"mod_trianglew_signal/triangewave_signal: qpctimer_start failed to query performance frequency counter!\"\r\n end if\r\n end if\r\n ! Create Jones vector field.\r\n do i = 1_I32P, this%m_nsamp\r\n this%m_jvec(i) = JonesVector_t(h(i),v(i))\r\n end do\r\n ! Create sine and cosine Fourier series components\r\n \r\n insamp = 1._R64P/DBLE(this%m_nsamp)\r\n k = 0_I32P\r\n do i = 1_I32P, this%m_maxk\r\n k = k+1\r\n do j = 1_I32P, this%m_nsamp\r\n this%m_sinit = this%m_sinit+this%m_stsinc\r\n delta = DBLE(j)*insamp\r\n t = this%m_sinit*delta\r\n this%m_scomp(i,j) = -1**k*DSIN(LAM_2PI*(2*k+1)*this%m_freq*t)/((2*k+1)*(2*k+1))\r\n this%m_ccomp(i,j) = -1**k*DCOS(LAM_2PI*(2*k+1)*this%m_freq*t)/((2*k+1)*(2*k+1))\r\n end do\r\n end do\r\n ! Do summation over the rows\r\n this%m_triangle = SUM(this%m_scomp,dim=2)\r\n tcos = SUM(this%m_ccomp,dim=2)\r\n ! Create sawtooth signal (final approximation) and\r\n ! create signal complex representation\r\n do j = 1_I32P, this%m_nsamp\r\n this%m_sinit = this%m_sinit+this%m_stsinc\r\n delta = DBLE(j)*insamp\r\n t = this%m_sinit*delta\r\n this%m_wct(j) = t\r\n this%m_triangle(j) = LAM_8OPIE2*this%m_triangle(j)\r\n tcos(j) = LAM_8OPIE2*tcos(j)\r\n this%m_cform(j) = DCMPLX(tcos(j),this%m_triangle(j))\r\n end do\r\n ! Compute natural envelope\r\n call vcmag(this%m_cform,this%m_nenvp)\r\n ! Create electrical field far from the emitter.\r\n k = 0_I32P\r\n do i = 1_I32P, this%m_maxk\r\n k = k+1\r\n do j = 1_I32P, this%m_nsamp\r\n this%m_sinit = this%m_sinit+this%m_stsinc\r\n delta = DBLE(j)*insamp\r\n t = this%m_sinit*delta\r\n t2 = t-r(j)/LAM_c\r\n this%m_scomp(i,j) = -1**k*DSIN(LAM_2PI*(2*k+1)*this%m_freq*t2)/((2*k+1)*(2*k+1))\r\n this%m_ccomp(i,j) = -1**k*DCOS(LAM_2PI*(2*k+1)*this%m_freq*t2)/((2*k+1)*(2*k+1))\r\n end do\r\n end do\r\n ! Do summation over the rows\r\n tc = SUM(this%m_ccomp,dim=2)\r\n ts = SUM(this%m_scomp,dim=2)\r\n do j = 1_I32P, this%m_nsamp\r\n tc(j) = LAM_8OPIE2*tc(j)\r\n ts(j) = LAM_8OPIE2*ts(j)\r\n this%m_E(j) = DCMPLX(tc(j),ts(j))\r\n end do\r\n ! Compute A(phi,theta)/r - magnitude of electric field E\r\n call vcmag(this%m_E,this%m_amp)\r\n ! Compute time-average power density i.e. 0.5xExE*/n\r\n do j = 1_I32P, this%m_nsamp\r\n this%m_S(j) = LAM_HR64P*this%m_E(j)*DCONJG(this%m_E(j))*0.0026525198938992_R64P\r\n end do\r\n if(profiling) then\r\n if(ifail == 0) then\r\n call qpctimer_stop(qpctimer,ifail)\r\n call qpctimer_delta(qpctimer,bfail)\r\n if(bfail .EQ. .false.) then\r\n call qpctimer_print(qpctimer)\r\n else\r\n write(stderr,*) \"mod_trianglew_signal/triangwave_signal: qpctimer_delta: failed to compute delta measurement!!\"\r\n end if \r\n else\r\n write(stderr,*) \"mod_trianglew_signal/triangwave_signal: Unable to read performance counter -- fatal!!\"\r\n end if\r\n end if\r\n end subroutine triangwave_signal\r\n \r\n !======================================================60\r\n ! @subroutine: phase_noise_signal \r\n ! Physical representation of Triangle wave\r\n ! approximated by K sinusoids (Fourier-\r\n ! series)\r\n ! This signal is corrupted by phase additive\r\n ! noise. \r\n !======================================================60 \r\n subroutine phase_noise_triangwave_signal(this,ierr, dur, &\r\n sinit,stsinc,freq,noise,r,h,v, &\r\n verbose,logging,filename,append, &\r\n profiling,qpctimer )\r\n use mod_print_error, only : handle_fatal_memory_error , &\r\n stderr\r\n use mod_constants, only : LAM_ZR8,LAM_PI,LAM_HR64P,LAM_PINF,LAM_2PI,LAM_c,LAM_MEPS8, &\r\n LAM_dtcoeff, LAM_8OPIE2\r\n class(TriangleWSignal_t), intent(inout) :: this\r\n integer(I32P), intent(inout) :: ierr\r\n real(R64P), intent(in) :: dur\r\n real(R64P), intent(in) :: sinit,stsinc,freq\r\n real(R64P), dimension(:), intent(in) :: noise,r\r\n!DIR$ ASSUME_ALIGNED noise:64,r:64\r\n complex(R64P), dimension(:), intent(in) :: h,v\r\n!DIR$ ASSUME_ALIGNED h:64,v:64\r\n logical(I32P), intent(in) :: verbose,logging\r\n character(len=*), intent(in) :: filename\r\n logical(I32P), intent(in) :: append,profiling\r\n type(QPCTimer_t), intent(inout) :: qpctimer\r\n ! Locals\r\n \r\n character(len=256) :: emsg\r\n integer(I32P) :: i,j,k,aerr\r\n integer(BOOL) :: ifail\r\n logical(I32P) :: bfail,invalid\r\n real(R64P) :: insamp,t,t2,delta,tn\r\n real(R64P), allocatable, dimension(:) :: tcos,ts,tc\r\n!DIR$ ATTRIBUTES ALIGN : 64 :: tcos\r\n!DIR$ ATTRIBUTES ALIGN : 64 :: ts\r\n!DIR$ ATTRIBUTES ALIGN : 64 :: tc \r\n ! Start of executable statements\r\n if(ierr < 0_I32P) ierr = 0_I32P\r\n ! Check if stsinc value lies in interval 1/2^-1 -> 1/2^-16\r\n invalid = .false.\r\n do i = 1, 16\r\n if(DABS(stsinc)-DABS(LAM_dtcoeff(i)) > LAM_MEPS8) then\r\n invalid = .true.\r\n end if\r\n end do\r\n if(invalid == .true.) then\r\n if(logging) then\r\n ierr = -2_I32P\r\n return\r\n end if\r\n \r\n if(dur <= LAM_ZR8) then\r\n ierr = -1_I32P\r\n return\r\n end if \r\n this%m_dur = dur\r\n this%m_sinit = sinit\r\n this%m_stsinc = stsinc\r\n this%m_freq = freq \r\n associate(n=>this%m_nsamp)\r\n allocate( tcos(n), &\r\n ts(n), &\r\n tc(n), &\r\n STAT=aerr, &\r\n ERRMSG=emsg)\r\n \r\n end associate\r\n if(aerr /= 0) then\r\n \r\n call handle_fatal_memory_error(logging,verbose,append,filename, &\r\n \"logger:553 --> mod_trianglew_signal/phase_noise_triangwave_signal: Memory Allocation Failure!!\" , &\r\n \"mod_trianglew_signal/phase_noise_triangwave_signal:553 -- Memory Allocation Failure!\" , &\r\n emsg,__LINE__ )\r\n end if\r\n if(profiling) then\r\n call qpctimer_start(qpctimer,ifail)\r\n if(ifail == 0) then\r\n write(stderr,*) \"mod_trianglew_signal/phase_noise_striangwave_signal: qpctimer_start failed to query performance frequency counter!\"\r\n end if\r\n end if\r\n ! Create Jones vector field.\r\n do i = 1_I32P, this%m_nsamp\r\n this%m_jvec(i) = JonesVector_t(h(i),v(i))\r\n end do\r\n ! Create sine and cosine Fourier series components\r\n insamp = 1._R64P/DBLE(this%m_nsamp)\r\n k = 0\r\n do i = 1_I32P, this%m_maxk\r\n k = k+1\r\n do j = 1_I32P, this%m_nsamp\r\n this%m_sinit = this%m_sinit+this%m_stsinc\r\n delta = DBLE(j)*insamp\r\n t = this%m_sinit*delta\r\n tn = t + noise(j)\r\n this%m_scomp(i,j) = -1**k*DSIN(LAM_2PI*(2*k+1)*this%m_freq*tn)/((2*k+1)*(2*k+1))\r\n this%m_ccomp(i,j) = -1**k*DCOS(LAM_2PI*(2*k+1)*this%m_freq*tn)/((2*k+1)*(2*k+1))\r\n end do\r\n end do\r\n ! Do summation over the rows\r\n this%m_triangle = SUM(this%m_scomp,dim=2)\r\n tcos = SUM(this%m_ccomp,dim=2)\r\n ! Create sawtooth signal (final approximation) and\r\n ! create signal complex representation\r\n do j = 1_I32P, this%m_nsamp\r\n this%m_sinit = this%m_sinit+this%m_stsinc\r\n delta = DBLE(j)*insamp\r\n t = this%m_sinit*delta\r\n t2 = t + noise(j)\r\n this%m_wct(j) = t2\r\n this%m_triangle(j) = LAM_8OPIE2*this%m_triangle(j)\r\n tcos(j) = LAM_8OPIE2*tcos(j)\r\n this%m_cform(j) = DCMPLX(tcos(j),this%m_triangle(j))\r\n end do\r\n ! Compute natural envelope\r\n call vcmag(this%m_cform,this%m_nenvp)\r\n ! Create electrical field far from the emitter.\r\n k = 0_I32P\r\n do i = 1_I32P, this%m_maxk\r\n k = k+1\r\n do j = 1_I32P, this%m_nsamp\r\n this%m_sinit = this%m_sinit+this%m_stsinc\r\n delta = DBLE(j)*insamp\r\n t = this%m_sinit*delta\r\n t2 = t-r(j)/LAM_c\r\n tn = t2 + noise(j)\r\n this%m_scomp(i,j) = -1**k*DSIN(LAM_2PI*(2*k+1)*this%m_freq*tn)/((2*k+1)*(2*k+1))\r\n this%m_ccomp(i,j) = -1**k*DCOS(LAM_2PI*(2*k+1)*this%m_freq*tn)/((2*k+1)*(2*k+1))\r\n end do\r\n end do\r\n ! Do summation over the rows\r\n tc = SUM(this%m_ccomp,dim=2)\r\n ts = SUM(this%m_scomp,dim=2)\r\n do j = 1_I32P, this%m_nsamp\r\n tc(j) = LAM_8OPIE2*tc(j)\r\n ts(j) = LAM_8OPIE2*ts(j)\r\n this%m_E(j) = DCMPLX(tc(j),ts(j))\r\n end do\r\n ! Compute A(phi,theta)/r - magnitude of electric field E\r\n call vcmag(this%m_E,this%m_amp)\r\n ! Compute time-average power density i.e. 0.5xExE*/n\r\n do j = 1_I32P, this%m_nsamp\r\n this%m_S(j) = LAM_HR64P*this%m_E(j)*DCONJG(this%m_E(j))*0.0026525198938992_R64P\r\n end do\r\n if(profiling) then\r\n if(ifail == 0) then\r\n call qpctimer_stop(qpctimer,ifail)\r\n call qpctimer_delta(qpctimer,bfail)\r\n if(bfail == .false.) then\r\n call qpctimer_print(qpctimer)\r\n else\r\n write(stderr,*) \"mod_trianglew_signal/phase_noise_triangwave_signal: qpctimer_delta: failed to compute delta measurement!!\"\r\n end if \r\n else\r\n write(stderr,*) \"mod_trianglew_signal/phase_noise_triangwave_signal: Unable to read performance counter -- fatal!!\"\r\n end if\r\n end if\r\n end subroutine phase_noise_triangwave_signal \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n !======================================================60\r\n ! @subroutine: additive_noise_triangwave_signal \r\n ! Physical representation of Triangle wave\r\n ! approximated by K sinusoids (Fourier-\r\n ! series)\r\n ! This signal is corrupted by phase additive\r\n ! noise and by background additive noise. \r\n !======================================================60 \r\n subroutine additive_noise_triangwave_signal(this,ierr,dur , &\r\n sinit,stsinc,freq,phnoise,bnoise, &\r\n r,h,v,verbose,logging,filename,append, &\r\n profiling,qpctimer )\r\n \r\n use mod_print_error, only : handle_fatal_memory_error , &\r\n stderr\r\n use mod_constants, only : LAM_ZR8,LAM_PI,LAM_HR64P,LAM_PINF,LAM_2PI,LAM_c,LAM_MEPS8, &\r\n LAM_dtcoeff, LAM_8OPIE2\r\n class(TriangleWSignal_t), intent(inout) :: this\r\n integer(I32P), intent(inout) :: ierr\r\n real(R64P), intent(in) :: dur,sinit,stsinc,freq\r\n real(R64P), dimension(:), intent(in) :: phnoise,bnoise,r\r\n!DIR$ ASSUME_ALIGNED phnoise:64,bnoise:64,r:64\r\n complex(R64P), dimension(:), intent(in) :: h,v\r\n!DIR$ ASSUME_ALIGNED h:64,v:64\r\n logical(I32P), intent(in) :: verbose,logging\r\n character(len=*), intent(in) :: filename\r\n logical(I32P), intent(in) :: append,profiling\r\n type(QPCTimer_t), intent(inout) :: qpctimer\r\n ! Locals\r\n \r\n character(len=256) :: emsg\r\n integer(I32P) :: i,j,k,aerr\r\n integer(BOOL) :: ifail\r\n logical(I32P) :: bfail,invalid\r\n real(R64P) :: insamp,t,t2,delta,tn\r\n real(R64P), allocatable, dimension(:) :: tcos,ts,tc\r\n!DIR$ ATTRIBUTES ALIGN : 64 :: tcos\r\n!DIR$ ATTRIBUTES ALIGN : 64 :: ts\r\n!DIR$ ATTRIBUTES ALIGN : 64 :: tc \r\n ! Start of executable statements\r\n if(ierr < 0_I32P) ierr = 0_I32P\r\n ! Check if stsinc value lies in interval 1/2^-1 -> 1/2^-16\r\n invalid = .false.\r\n do i = 1, 16\r\n if(DABS(stsinc)-DABS(LAM_dtcoeff(i)).GT.LAM_MEPS8) then\r\n invalid = .true.\r\n end if\r\n end do\r\n if(invalid) then\r\n ierr = -2_I32P\r\n return\r\n end if\r\n \r\n if(dur.LE.LAM_ZR8) then\r\n ierr = -1_I32P\r\n return\r\n end if \r\n this%m_dur = dur\r\n this%m_sinit = sinit\r\n this%m_stsinc = stsinc\r\n this%m_freq = freq \r\n associate(n=>this%m_nsamp)\r\n allocate( tcos(n), &\r\n ts(n), &\r\n tc(n), &\r\n STAT=aerr, &\r\n ERRMSG=emsg)\r\n end associate \r\n if(aerr /= 0) then\r\n \r\n call handle_fatal_memory_error(logging,verbose,append,filename, &\r\n \"logger:721 --> mod_trianglew_signal/additive_noise_triangwave_signal: Memory allocation failure!!\" , &\r\n \"mod_trianglew_signal/additive_noise_triangwave_signal:721 -- Memory Allocation Failure!\", &\r\n emag,__LINE__ )\r\n end if\r\n tcos = LAM_PINF \r\n ts = LAM_PINF\r\n tc = LAM_PINF\r\n if(profiling) then\r\n call qpctimer_start(qpctimer,ifail)\r\n if(ifail == 0) then\r\n write(stderr,*) \"mod_trianglew_signal/additive_noise_triangwave_signal: qpctimer_start failed to query performance frequency counter!\"\r\n end if\r\n end if\r\n ! Create Jones vector field.\r\n do i = 1, this%m_nsamp\r\n this%m_jvec(i) = JonesVector_t(h(i),v(i))\r\n end do\r\n ! Create sine and cosine Fourier series components\r\n \r\n insamp = 1._R64P/DBLE(this%m_nsamp)\r\n k = 0\r\n do i = 1, this%m_maxk\r\n k = k+1\r\n do j = 1, this%m_nsamp\r\n this%m_sinit = this%m_sinit+this%m_stsinc\r\n delta = DBLE(j)*insamp\r\n t = this%m_sinit*delta\r\n tn = t + phnoise(j)\r\n this%m_scomp(i,j) = -1**k*DSIN(LAM_2PI*(2*k+1)*this%m_freq*tn)/((2*k+1)*(2*k+1))\r\n this%m_scomp(i,j) = bnoise(j)+this%m_scomp(i,j)\r\n this%m_ccomp(i,j) = -1**k*DCOS(LAM_2PI*(2*k+1)*this%m_freq*tn)/((2*k+1)*(2*k+1))\r\n this%m_ccomp(i,j) = bnoise(j)+this%m_ccomp(i,j)\r\n end do\r\n end do \r\n ! Do summation over the rows\r\n this%m_triangle = SUM(this%m_scomp,dim=2)\r\n tcos = SUM(this%m_ccomp,dim=2)\r\n ! Create sawtooth signal (final approximation) and\r\n ! create signal complex representation\r\n do j = 1_I32P, this%m_nsamp\r\n this%m_sinit = this%m_sinit+this%m_stsinc\r\n delta = DBLE(j)*insamp\r\n t = this%m_sinit*delta\r\n t2 = t + noise(j)\r\n this%m_wct(j) = t2\r\n this%m_triangle(j) = LAM_8OPIE2*this%m_triangle(j)\r\n tcos(j) = LAM_8OPIE2*tcos(j)\r\n this%m_cform(j) = DCMPLX(tcos(j),this%m_triangle(j))\r\n end do\r\n ! Compute natural envelope\r\n call vcmag(this%m_cform,this%m_nenvp)\r\n ! Create electrical field far from the emitter.\r\n k = 0_I32P\r\n do i = 1_I32P, this%m_maxk\r\n k = k+1\r\n do j = 1_I32P, this%m_nsamp\r\n this%m_sinit = this%m_sinit+this%m_stsinc\r\n delta = DBLE(j)*insamp\r\n t = this%m_sinit*delta\r\n t2 = t-r(j)/LAM_c\r\n tn = t2 + noise(j)\r\n this%m_scomp(i,j) = -1**k*DSIN(LAM_2PI*(2*k+1)*this%m_freq*tn)/((2*k+1)*(2*k+1))\r\n this%m_scomp(i,j) = bnoise(j)+this%m_scomp(i,j)\r\n this%m_ccomp(i,j) = -1**k*DCOS(LAM_2PI*(2*k+1)*this%m_freq*tn)/((2*k+1)*(2*k+1))\r\n this%m_ccomp(i,j) = bnoise(j)+this%m_ccomp(i,j)\r\n end do\r\n end do\r\n ! Do summation over the rows\r\n tc = SUM(this%m_ccomp,dim=2)\r\n ts = SUM(this%m_scomp,dim=2)\r\n do j = 1_I32P, this%m_nsamp\r\n tc(j) = LAM_8OPIE2*tc(j)\r\n ts(j) = LAM_8OPIE2*ts(j)\r\n this%m_E(j) = DCMPLX(tc(j),ts(j))\r\n end do \r\n ! Compute A(phi,theta)/r - magnitude of electric field E\r\n call vcmag(this%m_E,this%m_amp)\r\n ! Compute time-average power density i.e. 0.5xExE*/n\r\n do j = 1_I32P, this%m_nsamp\r\n this%m_S(j) = LAM_HR64P*this%m_E(j)*DCONJG(this%m_E(j))*0.0026525198938992_R64P\r\n end do\r\n if(profiling) then\r\n if(ifail == 0) then\r\n call qpctimer_stop(qpctimer,ifail)\r\n call qpctimer_delta(qpctimer,bfail)\r\n if(bfail .EQ. .false.) then\r\n call qpctimer_print(qpctimer)\r\n else\r\n write(stderr,*) \"mod_trianglew_signal/additive_noise_triangwave_signal: qpctimer_delta: failed to compute delta measurement!!\"\r\n end if \r\n else\r\n write(stderr,*) \"mod_trianglew_signal/additive_noise_triangwave_signal: Unable to read performance counter -- fatal!!\"\r\n end if\r\n end if\r\n end subroutine additive_noise_triangwave_signal\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n !======================================================60\r\n ! Getter pure functions\r\n !======================================================60\r\n \r\n pure function get_name(this) result(name)\r\n implicit none\r\n class(TriangleWSignal_t), intent(in) :: this\r\n ! Locals\r\n character(len=64) :: name\r\n ! Start of executable statements\r\n name = this%m_name\r\n end function\r\n \r\n pure function get_sid(this) result(sid)\r\n implicit none\r\n class(TriangleWSignal_t), intent(in) :: this\r\n ! Locals\r\n integer(I32P) :: sid\r\n ! Start of executable statements\r\n sid = this%m_sid\r\n end function\r\n \r\n pure function get_nsamp(this) result(nsamp)\r\n implicit none\r\n class(TriangleWSignal_t), intent(in) :: this\r\n ! Locals\r\n integer(I32P) :: nsamp\r\n ! Start of executable statements\r\n nsamp = this%m_nsamp\r\n end function\r\n \r\n pure function get_maxk(this) result(maxk)\r\n implicit none\r\n class(TriangleWSignal_t), intent(in) :: this\r\n ! Locals\r\n integer(I32P) :: maxk\r\n ! Start of executable statements\r\n maxk = this%m_maxk\r\n end function\r\n \r\n pure function get_dur(this) result(dur)\r\n implicit none\r\n class(TriangleWSignal_t), intent(in) :: this\r\n ! Locals\r\n real(R64P) :: dur\r\n ! Start of executable satements\r\n dur = this%m_dur\r\n end function\r\n \r\n pure function get_sinit(this) result(sinit)\r\n implicit none\r\n class(TriangleWSignal_t), intent(in) :: this\r\n ! Locals\r\n real(R64P) :: sinit\r\n ! Start of executable satatements\r\n sinit = this%m_sinit\r\n end function\r\n \r\n pure function get_stsinc(this) result(stsinc)\r\n implicit none\r\n class(TriangleWSignal_t), intent(in) :: this\r\n ! Locals\r\n real(R64P) :: stsinc\r\n ! Start of executable statements\r\n stsinc = this%m_stsinc\r\n end function\r\n \r\n pure function get_freq(this) result(freq)\r\n implicit none\r\n class(TriangleWSignal_t), intent(in) :: this\r\n ! Locals\r\n real(R64P) :: freq\r\n ! Start of executable sattaements\r\n freq = this%m_freq\r\n end function\r\n \r\n \r\n \r\n \r\n \r\n !======================================================60\r\n ! Computational procedures\r\n !======================================================60\r\n ! TODO:\r\n ! ! Consider using CADNA to test for cancellation errors\r\n subroutine dphi_dt(this,dphi,sfac)\r\n use mod_constants, only : LAM_IZER8, LAM_MEPS8\r\n class(TriangleWSignal_t), intent(in) :: this\r\n real(R64P), dimension(:), intent(out) :: dphi\r\n!DIR$ ASSUME_ALIGNED dphi:32\r\n integer(I64P), intent(inout) :: sfac\r\n ! Locals\r\n integer(I32P) :: i\r\n real(R64P) :: eps,isfac,tmp\r\n ! Start of executable sttements\r\n if(sfac.LE.LAM_IZER8) then\r\n sfac = 1000000000000000_I64P\r\n end if\r\n isfac = 1._R64P/DBLE(sfac)\r\n eps = LAM_MEPS8**0.3333333333333333333333333333_R64P\r\n do i = 2, this%m_nsamp-1\r\n tmp = this%m_wct(i+1)-this%m_wct(i-1)\r\n dphi(i) = this%m_wct(i+1)-this%m_wct(i-1) / &\r\n (2._R64P*eps*DMAX1(DABS(tmp),isfac)*DSIGN(tmp,tmp))\r\n end do\r\n end subroutine\r\n \r\n !============================================\r\n ! Read/write procedures\r\n !============================================\r\n subroutine read_state(this,form,unit,ioerr)\r\n \r\n class(TriangleWSignal_t), intent(in) :: this\r\n character(len=*), intent(in) :: form\r\n integer(I32P), intent(in) :: unit\r\n integer(I32P), intent(inout) :: ioerr\r\n ! Start of executable statements\r\n select case(adjustl(trim(form)))\r\n case (\"*\")\r\n READ(unit,*,iostat=ioerr) this\r\n case default\r\n READ(unit,adjustl(trim(form)),iostat=ioerr) this\r\n end select\r\n end subroutine read_state\r\n \r\n subroutine write_state(this,form,unit,ioerr)\r\n \r\n class(TriangleWSignal_t), intent(in) :: this\r\n character(len=*), intent(in) :: form\r\n integer(I32P), intent(in) :: unit\r\n integer(I32P), intent(inout) :: ioerr\r\n ! Start of executable statements\r\n select case(adjustl(trim(form)))\r\n case (\"*\")\r\n WRITE(unit,*,iostat=ioerr) this\r\n case default\r\n WRITE(unit,adjustl(trim(form)),iostat=ioerr) this\r\n end select\r\n end subroutine write_state\r\n \r\n !======================================================60\r\n ! subroutine: to_screenu\r\n !======================================================60 \r\n subroutine dbg_info(this,verbose)\r\n implicit none\r\n class(TriangleWSignal_t), intent(in) :: this\r\n logical(I32P), intent(in) :: verbose\r\n ! Locals\r\n ! Start of executable statements\r\n call DATE_AND_TIME(date=dstr,time=tstr)\r\n print*, \"======================================================\"\r\n print*, \" ***Printing components of TriangleWSignal_t***\"\r\n print*, \" printing subroutine called at: \" , &\r\n sdate(1:4),\"-\",sdate(5:6),\"-\",sdate(7:8), \" \", &\r\n stime(1:2),\":\",stime(3:4),\":\",stime(5:6)\r\n print*, \" Dumping scalar components \"\r\n print*, \"======================================================\"\r\n print*, \"Name: \", this%m_name\r\n print*, \"Signal ID: \", this%m_sid\r\n print*, \"Number of samples: \", this%m_nsamp\r\n print*, \"Maximum 'k': \", this%m_maxk\r\n print*, \"Signal duration: \", this%m_dur\r\n print*, \"scalar amplitude: \", this%m_A\r\n print*, \"Initial time-point: \", this%m_sinit\r\n print*, \"Time-step increment:\", this%m_stsinc\r\n print*, \"Carrier frequency: \", this%m_freq\r\n print*, \" Dumping array components \"\r\n print*, \"======================================================\"\r\n \r\n \r\n if(verbose) then\r\n print*, \"Sine series components: \", this%m_scomp\r\n print*, \"Cosine series components:\", this%m_ccomp\r\n end if\r\n print*, \"Signal polarization: \", this%m_jvec\r\n print*, \"Time (t): \", this%m_wct\r\n print*, \"Natural Envelope: \", this%m_nenvp\r\n print*, \"Triangle time-domain: \", this%m_triangle\r\n print*, \"Complex form: \", this%m_cform\r\n print*, \"Electric field: \", this%m_E\r\n print*, \"Amplitude: \", this%m_amp\r\n print*, \"Time-average power: \", this%m_S\r\n print*, \"=====================================================\"\r\n end subroutine dbg_info\r\n \r\n !======================================================60\r\n ! subroutine: copy_assign\r\n ! Overloaded assignment (=)\r\n !======================================================60\r\n subroutine copy_assign(lhs,rhs)\r\n class(TriangleWSignal_t), intent(inout) :: lhs\r\n class(TriangleWSignal_t), intent(in) :: rhs\r\n ! Start of executable statements.\r\n lhs%m_name = rhs%m_name\r\n lhs%m_sid = rhs%m_sid\r\n lhs%m_nsamp = rhs%m_nsamp\r\n lhs%m_maxk = rhs%m_maxk\r\n lhs%m_dur = rhs%m_dur\r\n lhs%m_A = rhs%m_A\r\n lhs%m_sinit = rhs%m_sinit\r\n lhs%m_stsinc = lhs%m_stsinc\r\n lhs%m_freq = rhs%m_freq\r\n lhs%m_jvec = rhs%m_jvec\r\n lhs%m_scomp = rhs%m_scomp\r\n lhs%m_ccomp = rhs%m_ccomp\r\n lhs%m_wct = rhs%m_wct\r\n lhs%m_nenvp = rhs%m_nenvp\r\n lhs%m_triangle = rhs%m_triangle\r\n lhs%m_cform = rhs%m_cform\r\n lhs%m_E = rhs%m_E\r\n lhs%m_amp = rhs%m_amp\r\n lhs%m_S = rhs%m_S\r\n end subroutine copy_assign\r\n \r\n \r\nend module mod_trianglew_signal", "meta": {"hexsha": "1fa49e6f4e45bfe5d1ba8344f78de94d6ff15538", "size": 43801, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Weather Radar/module_trianglewave_signal.f90", "max_stars_repo_name": "bgin/LibAtmosModel", "max_stars_repo_head_hexsha": "ee9383d7e09a35d79fa24ce120afe6f8ea6efd09", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-02-27T13:49:01.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-29T09:23:03.000Z", "max_issues_repo_path": "Weather Radar/module_trianglewave_signal.f90", "max_issues_repo_name": "bgin/LibAtmosModel", "max_issues_repo_head_hexsha": "ee9383d7e09a35d79fa24ce120afe6f8ea6efd09", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Weather Radar/module_trianglewave_signal.f90", "max_forks_repo_name": "bgin/LibAtmosModel", "max_forks_repo_head_hexsha": "ee9383d7e09a35d79fa24ce120afe6f8ea6efd09", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-08-26T12:11:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-19T01:45:27.000Z", "avg_line_length": 42.2381870781, "max_line_length": 153, "alphanum_fraction": 0.4578205977, "num_tokens": 10344, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722394, "lm_q2_score": 0.7772998714925403, "lm_q1q2_score": 0.6527251051595527}} {"text": "program test_interp1\n!! Need program statement for FORD\nuse phys_consts, only: wp,pi\nuse interpolation\n\nimplicit none (type, external)\n\ninteger, parameter :: lx1=25, lx2=50\ninteger, parameter :: lx1i=200, lx2i=400\nreal(wp), parameter :: stride=0.5_wp\n\ninteger :: ix1,ix2\n\nreal(wp), allocatable, dimension(:) :: x1, x2, x1i, x2i\nreal(wp), allocatable, dimension(:,:) :: f, fi !< since only doing x1 interpolation\n\nallocate(x1(lx1), x2(lx2), f(lx1,lx2), x1i(lx1i), x2i(lx2i), fi(lx1i,lx2i))\n\n!grid for original data\nx1=[ ((real(ix1,wp)-1._wp)*stride, ix1=1,lx1) ]\nx2=[ ((real(ix2,wp)-1._wp)*stride, ix2=1,lx2) ]\n\n\n!test function\ndo ix2=1,lx2\n f(:,ix2)=sin(2._wp*pi/5._wp*x1)*cos(2._wp*pi/5._wp*x2(ix2))\nend do\n\n\n!grid for interpolated data\nx1i=[ ((real(ix1,wp)-1._wp)*stride/(lx1i/lx1), ix1=1,lx1i) ]\nx2i=[ ((real(ix2,wp)-1._wp)*stride/(lx2i/lx2), ix2=1,lx2i) ]\n\n\n!try a 1d interpolation for each x2 value used in simulation\ndo ix2=1,lx2\n fi(:,ix2)=interp1(x1,f(:,ix2),x1i)\nend do\n\n!dump results to a file so we can check things\nblock\n integer :: u\n open(newunit=u,file='input1D.dat',status='replace',form='unformatted',access='stream', action='write')\n write(u) lx1,lx2\n write(u) x1,x2,f\n close(u)\nend block\n\nblock\n integer :: u\n open(newunit=u,file='output1D.dat',status='replace',form='unformatted',access='stream', action='write')\n write(u) lx1i,lx2\n write(u) x1i,x2,fi !since only interpolating in x1\n close(u)\nend block\n\nend program\n", "meta": {"hexsha": "e8e0ef96aad29fe67a5f2d9f79e0e576b0a28ae0", "size": 1452, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/numerical/interpolation/testinterp1.f90", "max_stars_repo_name": "jklenzing/gemini", "max_stars_repo_head_hexsha": "aed028fbb6f6187ca951e4cd243fdec929514b2a", "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/numerical/interpolation/testinterp1.f90", "max_issues_repo_name": "jklenzing/gemini", "max_issues_repo_head_hexsha": "aed028fbb6f6187ca951e4cd243fdec929514b2a", "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/numerical/interpolation/testinterp1.f90", "max_forks_repo_name": "jklenzing/gemini", "max_forks_repo_head_hexsha": "aed028fbb6f6187ca951e4cd243fdec929514b2a", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.0344827586, "max_line_length": 105, "alphanum_fraction": 0.685261708, "num_tokens": 557, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339596505965, "lm_q2_score": 0.7772998663336157, "lm_q1q2_score": 0.6527250945922065}} {"text": "*###[ ffxli2:\n\tsubroutine ffxli2(xdilog,xlog,x,ier)\n***#[*comment:***********************************************************\n*\t\t\t\t\t\t\t\t\t*\n*\tComputes the dilogarithm (Li2, Sp) for (real) x\tto precision\t*\n*\tprecx. It is assumed that -1<=x<=1/2. As it is available anyway*\n*\tlog(1-x) = -Li1(x) is also passed.\t\t\t\t*\n*\t\t\t\t\t\t\t\t\t*\n*\tInput:\tx\t(real)\t\t\t\t\t\t*\n*\t\t\t\t\t\t\t\t\t*\n*\tOutput: xdilog\t(real) Li2(x)\t\t\t\t*\n*\t\txlog\t(real) log(1-x) = -Li1(x)\t\t\t*\n*\t\tier\t(integer) 0=OK, 1=num prob, 2=error\t\t*\n*\t\t\t\t\t\t\t\t\t*\n*\tCalls:\tlog,dfflo1\t\t\t\t\t\t*\n*\t\t\t\t\t\t\t\t\t*\n***#]*comment:***********************************************************\n* #[ declarations:\n\timplicit none\n*\n*\targuments\n*\n\tinteger ier\n\tDOUBLE PRECISION xdilog,xlog,x\n*\n*\tlocal variables\n*\n\tinteger ipi12\n\tDOUBLE PRECISION dfflo1,u,u2,a,ffbnd,\n +\t\txprec,bdn02,bdn05,bdn10,bdn15\n\tDOUBLE COMPLEX zxdilo,zlog\n\texternal ffbnd,dfflo1\n\tsave xprec,bdn02,bdn05,bdn10,bdn15\n*\n*\tcommon blocks\n*\n\tinclude 'ff.h'\n* #] declarations:\n* #[ initialisations:\n\tdata xprec /-1D0/\n\tif ( xprec .ne. precx ) then\n\t xprec = precx\n\t bdn02 = ffbnd(1,2,bf)\n\t bdn05 = ffbnd(1,5,bf)\n\t bdn10 = ffbnd(1,10,bf)\n\t bdn15 = ffbnd(1,15,bf)\n\tendif\n* #] initialisations:\n* #[ if the argument is too large...\n\tif ( x .lt. -1.5 .or. x .gt. .75 ) then\n\t call ffzxdl(zxdilo,ipi12,zlog,x,0,ier)\n\t if ( DIMAG(zxdilo) .ne. 0 ) then\n\t \tcall fferr(52,ier)\n\t endif\n\t xdilog = DBLE(zxdilo) + ipi12*pi12\n\t xlog = DBLE(zlog)\n\t return\n\tendif\n* #] if the argument is too large...\n* #[ exceptional cases:\n\tif ( x .eq. -1 ) then\n\t xdilog = -pi12\n\t xlog = log(2D0)\n\t return\n\telseif ( x .eq. .5D0 ) then\n\t xdilog = - xlg2**2/2 + pi12\n\t xlog = - xlg2\n\t return\n\telseif ( abs(x) .lt. precx ) then\n\t xdilog = x\n\t xlog = -x\n\t return\n\tendif\n* #] exceptional cases:\n* #[ calculate dilog:\n\tif ( abs(x) .lt. xloss ) then\n\t xlog = dfflo1(x,ier)\n\telse\n\t xlog = log(1-x)\n\tendif\n\tu = -xlog\n\tu2 = u*u\n\ta = abs(u2)\n\tif ( a .gt. bdn15 ) then\n\t xdilog = u2*(bf(16) + u2*(bf(17) + u2*(bf(18) +\n +\t\t u2*(bf(19) + u2*bf(20) ))))\n\telse\n\t xdilog = 0\n\tendif\n\tif ( a .gt. bdn10 ) then\n\t xdilog = u2*(bf(11) + u2*(bf(12) + u2*(bf(13) +\n +\t\t u2*(bf(14) + u2*(bf(15) + xdilog)))))\n\tendif\n\tif ( a .gt. bdn05 ) then\n\t xdilog = u2*(bf(6) + u2*(bf(7) + u2*(bf(8) +\n +\t\t u2*(bf(9) + u2*(bf(10) + xdilog)))))\n\tendif\n\tif ( a .gt. bdn02 ) then\n\t xdilog = u2*(bf(3) + u2*(bf(4) + u2*(bf(5) + xdilog)))\n\tendif\n*\twatch the powers of u.\n\txdilog = u + u2*(bf(1) + u*(bf(2) + xdilog))\n* #] calculate dilog:\n*###] ffxli2:\n\tend\n\n\n*###[ ffzxdl:\n\tsubroutine ffzxdl(zxdilo,ipi12,zlog,x,ieps,ier)\n***#[*comment:***************************************************\n*\tComputes the dilogarithm (Li2, Sp) for any (real) x\t*\n*\tto precision precx. If an error message is given add\t*\n*\tmore bf's. For x > 1 the imaginary part is\t\t*\n*\t -/+i*pi*log(x), corresponding to x+ieps.\t\t*\n*\tThe number of factors pi^2/12 is passed separately in\t*\n*\tipi12 for accuracy. We also calculate log(1-x)\t\t*\n*\twhich is likely to be needed.\t\t\t\t*\n*\t\t\t\t\t\t\t\t*\n*\tInput:\tx\t(real)\t\t\t\t\t*\n*\t\tieps\t(integer,+/-1)\t\t\t\t*\n*\t\t\t\t\t\t\t\t*\n*\tOutput: zxdilo\t(complex) the dilog mod factors pi2/12\t*\n*\t\tipi12\t(integer) these factors\t\t\t*\n*\t\tzlog\t(complex) log(1-x)\t\t\t*\n*\t\t\t\t\t\t\t\t*\n*\tCalls:\tlog,dfflo1\t\t\t\t\t*\n*\t\t\t\t\t\t\t\t*\n***#]*comment:***************************************************\n* #[ declarations:\n\timplicit none\n*\n*\targuments\n*\n\tinteger ipi12,ieps,ier\n\tDOUBLE PRECISION x\n\tDOUBLE COMPLEX zxdilo,zlog\n*\n*\tlocal variables\n*\n\tinteger jsgn\n\tDOUBLE PRECISION fact,u,u2,dfflo1,ffbnd,a,xdilo,\n +\t\txprec,bdn02,bdn05,bdn10,bdn15\n\tDOUBLE COMPLEX cy,cfact\n\texternal ffbnd,dfflo1\n\tsave xprec,bdn02,bdn05,bdn10,bdn15\n*\n*\tcommon blocks\n*\n\tinclude 'ff.h'\n* #] declarations:\n* #[ initialisations:\n\tdata xprec /-1D0/\n\tif ( xprec .ne. precx ) then\n\t xprec = precx\n\t bdn02 = ffbnd(1,2,bf)\n\t bdn05 = ffbnd(1,5,bf)\n\t bdn10 = ffbnd(1,10,bf)\n\t bdn15 = ffbnd(1,15,bf)\n\tendif\n* #] initialisations:\n* #[ exceptional cases:\n\tif ( x .eq. 1) then\n\t zxdilo = 0\n\t zlog = -99999\n\t ipi12 = 2\n\t return\n\telseif (x .eq. -1) then\n\t zxdilo = 0\n\t zlog = xlg2\n\t ipi12 = -1\n\t return\n\telseif (x .eq. .5D0) then\n\t zxdilo = - xlg2**2/2\n\t zlog = -xlg2\n\t ipi12 = 1\n\t return\n\telseif ( abs(x) .lt. precx ) then\n\t zxdilo = x\n\t zlog = -x\n\t ipi12 = 0\n\t return\n\tendif\n* #] exceptional cases:\n* #[ transform to (-1,.5):\n\tif (x .lt. -1) then\n\t fact = log(-x)\n\t cy = - fact**2/2\n\t ipi12 = -2\n\t if ( -x*xloss .gt. 1 ) then\n\t\tu = -dfflo1(1/x,ier)\n\t else\n\t\tu = -log(1-1/x)\n\t endif\n\t zlog = log(1-x)\n\t jsgn = -1\n\telseif ( x .lt. .5D0) then\n\t cy = 0\n\t ipi12 = 0\n\t if ( abs(x) .lt. xloss ) then\n\t\tzlog = dfflo1(x,ier)\n\t else\n\t\tzlog = log(1-x)\n\t endif\n\t u = -DBLE(zlog)\n\t jsgn = 1\n\telseif ( x .le. 2 ) then\n\t u = -log(x)\n\t if ( abs(1-x) .lt. xalogm ) then\n\t\tcy = 0\n\t elseif ( x .lt. 1 ) then\n\t\tzlog = log(1-x)\n\t\tcy = DBLE(u)*zlog\n\t elseif ( ieps .gt. 0 ) then\n\t\tzlog = DCMPLX(log(x-1),-pi)\n\t\tcy = DBLE(u)*zlog\n\t else\n\t\tzlog = DCMPLX(log(x-1),+pi)\n\t\tcy = DBLE(u)*zlog\n\t endif\n\t ipi12 = 2\n\t jsgn = -1\n\telse\n\t if ( ieps .gt. 0 ) then\n\t\tcfact = DCMPLX(log(x),-pi)\n\t\tzlog = DCMPLX(log(x-1),-pi)\n\t else\n\t\tcfact = DCMPLX(log(x),+pi)\n\t\tzlog = DCMPLX(log(x-1),+pi)\n\t endif\n\t cy = - cfact**2/2\n\t ipi12 = -2\n\t if ( x*xloss .gt. 1 ) then\n\t\tu = -dfflo1(1/x,ier)\n\t else\n\t\tu = -log(1-1/x)\n\t endif\n\t jsgn = -1\n\tendif\n* #] transform to (-1,.5):\n* #[ calculate dilog:\n\tif ( abs(u) .lt. xalog2 ) then\n\t xdilo = u\n\telse\n\tu2 = u**2\n\ta = abs(u2)\n\tif ( a .gt. bdn15 ) then\n\t xdilo = u2*(bf(16) + u2*(bf(17) + u2*(bf(18) +\n +\t\t u2*(bf(19) + u2*bf(20) ))))\n\telse\n\t xdilo = 0\n\tendif\n\tif ( a .gt. bdn10 ) then\n\t xdilo = u2*(bf(11) + u2*(bf(12) + u2*(bf(13) +\n +\t\t u2*(bf(14) + u2*(bf(15) + xdilo)))))\n\tendif\n\tif ( a .gt. bdn05 ) then\n\t xdilo = u2*(bf(6) + u2*(bf(7) + u2*(bf(8) +\n +\t\t u2*(bf(9) + u2*(bf(10) + xdilo)))))\n\tendif\n\tif ( a .gt. bdn02 ) then\n\t xdilo = u2*(bf(3) + u2*(bf(4) + u2*(bf(5) + xdilo)))\n\tendif\n*\twatch the powers of u.\n\txdilo = u + u2*(bf(1) + u*(bf(2) + xdilo))\n\tendif\n\tif(jsgn.eq.1)then\n\t zxdilo = DBLE(xdilo) + cy\n\telse\n\t zxdilo = -DBLE(xdilo) + cy\n\tendif\n* #] calculate dilog:\n*###] ffzxdl:\n\tend\n\n\n*###[ zxfflg:\n\tDOUBLE COMPLEX function zxfflg(x,ieps,y,ier)\n***#[*comment:***********************************************************\n*\t\t\t\t\t\t\t\t\t*\n*\tCalculate the complex logarithm of x. The following cases\t*\n*\tare treted separately:\t\t\t\t\t\t*\n*\t\t|x| too small:\t\tgive warning and return 0\t*\n*\t\t\t\t\t(for Absoft, Apollo DN300)\t*\n*\t\t|x| < 0:\t\ttake sign according to ieps\t*\n*\t\t\t\t\t\t\t\t\t*\n***#]*comment:***********************************************************\n* #[ declarations:\n*\n*\targuments\n*\n\timplicit none\n\tinteger ieps,ier\n\tDOUBLE PRECISION x,y\n*\n*\tlocal variables\n*\n\tDOUBLE PRECISION xlog\n*\n*\tcommon blocks\n*\n\tinclude 'ff.h'\n* #] declarations:\n* #[ calculations:\n\tif ( abs(x) .lt. xalogm ) then\n\t zxfflg = 0\n\telseif ( x .gt. 0 ) then\n\t zxfflg = log(x)\n\telse\n\t xlog = log(-x)\n*\t checked imaginary parts 19-May-1988\n\t if ( abs(ieps) .eq. 1 ) then\n\t\tif ( y*ieps .lt. 0 ) then\n\t\t zxfflg = DCMPLX(xlog,-pi)\n\t\telse\n\t\t zxfflg = DCMPLX(xlog,pi)\n\t\tendif\n\t elseif ( ieps .eq. 2 ) then\n\t\tzxfflg = DCMPLX(xlog,-pi)\n\t elseif ( ieps .eq. -2 ) then\n\t\tzxfflg = DCMPLX(xlog,+pi)\n\t else\n\t\tcall fferr(52,ier)\n\t\tzxfflg = DCMPLX(xlog,pi)\n\t endif\n\tendif\n* #] calculations:\n*###] zxfflg:\n\tend\n\n\n*###[ dfflo1:\n\tDOUBLE PRECISION function dfflo1(x,ier)\n***#[*comment:***************************************************\n*\tcalculates log(1-x) for |x|<.14 in a faster way to ~15\t*\n*\tsignificant figures.\t\t\t\t\t*\n***#]*comment:***************************************************\n* #[ declarations:\n\timplicit none\n\tinteger ier\n\tDOUBLE PRECISION x,bdn01,bdn05,bdn10,bdn15,bdn19,xprec,\n +\t\txa,ffbnd\n\tDOUBLE COMPLEX zxfflg\n\texternal ffbnd,zxfflg\n\tsave xprec,bdn01,bdn05,bdn10,bdn15,bdn19\n\tinclude 'ff.h'\n* #] declarations:\n* #[ initialisation:\n\tdata xprec /-1D0/\n\tif ( xprec .ne. precx ) then\n\t xprec = precx\n*\t determine the boundaries for 1,5,10,15 terms\n\t bdn01 = ffbnd(1,1,xninv)\n\t bdn05 = ffbnd(1,5,xninv)\n\t bdn10 = ffbnd(1,10,xninv)\n\t bdn15 = ffbnd(1,15,xninv)\n\t bdn19 = ffbnd(1,19,xninv)\n\tendif\n* #] initialisation:\n* #[ calculations:\n\txa = abs(x)\n\tif ( xa .gt. bdn19 ) then\n\t dfflo1 = DBLE(zxfflg(1-x,0,0D0,ier))\n\t return\n\tendif\n\tif ( xa .gt. bdn15 ) then\n\t dfflo1 = x*( xninv(16) + x*( xninv(17) + x*( xninv(18) +\n +\t\tx*( xninv(19) + x*xninv(20) ))))\n\telse\n\t dfflo1 = 0\n\tendif\n\tif ( xa .gt. bdn10 ) then\n\t dfflo1 = x*( xninv(11) + x*( xninv(12) + x*( xninv(13) +\n +\t\tx*( xninv(14) + x*( xninv(15) + dfflo1 )))))\n\tendif\n\tif ( xa .gt. bdn05 ) then\n\t dfflo1 = x*( xninv(6) + x*( xninv(7) + x*( xninv(8) +\n +\t\tx*( xninv(9) + x*( xninv(10) + dfflo1 )))))\n\tendif\n\tif ( xa .gt. bdn01 ) then\n\t dfflo1 = x*( xninv(2) + x*( xninv(3) + x*( xninv(4) +\n +\t\tx*( xninv(5) + dfflo1 ))))\n\tendif\n\tdfflo1 = - x*( xninv(1) + dfflo1 )\n* #] calculations:\n*###] dfflo1:\n\tend\n\n\n*###[ dfflo2:\n\tDOUBLE PRECISION function dfflo2(x,ier)\n***#[*comment:***************************************************\n*\tcalculates log(1-x)+x for |x|<.14 in a faster way to\t*\n*\t~15 significant figures.\t\t\t\t*\n***#]*comment:***************************************************\n* #[ declarations:\n\timplicit none\n\tinteger ier\n\tDOUBLE PRECISION x,bdn01,bdn05,bdn10,bdn15,bdn18,xprec,\n +\t\txa,ffbnd,dfflo1\n\texternal ffbnd,dfflo1\n\tsave xprec,bdn01,bdn05,bdn10,bdn15,bdn18\n\tinclude 'ff.h'\n* #] declarations:\n* #[ initialisation:\n\tdata xprec /-1D0/\n\tif ( xprec .ne. precx ) then\n\t xprec = precx\n*\t determine the boundaries for 1,5,10,15 terms\n\t bdn01 = ffbnd(1,1,xninv(2))\n\t bdn05 = ffbnd(1,5,xninv(2))\n\t bdn10 = ffbnd(1,10,xninv(2))\n\t bdn15 = ffbnd(1,15,xninv(2))\n\t bdn18 = ffbnd(1,18,xninv(2))\n\tendif\n* #] initialisation:\n* #[ calculations:\n\txa = abs(x)\n\tif ( xa .gt. bdn18 ) then\n\t dfflo2 = dfflo1(x,ier) + x\n\t return\n\tendif\n\tif ( xa .gt. bdn15 ) then\n\t dfflo2 = x*( xninv(17) + x*( xninv(18) + x*( xninv(19) +\n +\t\tx*xninv(20) )))\n\telse\n\t dfflo2 = 0\n\tendif\n\tif ( xa .gt. bdn10 ) then\n\t dfflo2 = x*( xninv(12) + x*( xninv(13) + x*( xninv(14) +\n +\t\tx*( xninv(15) + x*( xninv(16) + dfflo2 )))))\n\tendif\n\tif ( xa .gt. bdn05 ) then\n\t dfflo2 = x*( xninv(7) + x*( xninv(8) + x*( xninv(9) +\n +\t\tx*( xninv(10) + x*( xninv(11) + dfflo2 )))))\n\tendif\n\tif ( xa .gt. bdn01 ) then\n\t dfflo2 = x*( xninv(3) + x*( xninv(4) + x*( xninv(5) +\n +\t\tx*( xninv(6) + dfflo2 ))))\n\tendif\n\tdfflo2 = - x**2*( xninv(2) + dfflo2 )\n* #] calculations:\n*###] dfflo2:\n\tend\n\n\n*###[ dfflo3:\n\tDOUBLE PRECISION function dfflo3(x,ier)\n***#[*comment:***************************************************\n*\tcalculates log(1-x)+x+x^2/2 for |x|<.14 in a faster \t*\n*\tway to ~15 significant figures.\t\t\t\t*\n***#]*comment:***************************************************\n* #[ declarations:\n\timplicit none\n\tinteger ier\n\tDOUBLE PRECISION x,bdn01,bdn05,bdn10,bdn15,xprec,\n +\t\txa,ffbnd,dfflo2\n\texternal ffbnd,dfflo2\n\tsave xprec,bdn01,bdn05,bdn10,bdn15\n\tinclude 'ff.h'\n* #] declarations:\n* #[ initialisation:\n\tdata xprec /-1D0/\n\tif ( xprec .ne. precx ) then\n\t xprec = precx\n*\t determine the boundaries for 1,5,10,15 terms\n\t bdn01 = ffbnd(1,1,xninv(3))\n\t bdn05 = ffbnd(1,5,xninv(3))\n\t bdn10 = ffbnd(1,10,xninv(3))\n\t bdn15 = ffbnd(1,15,xninv(3))\n\tendif\n* #] initialisation:\n* #[ calculations:\n\txa = abs(x)\n\tif ( xa .gt. bdn15 ) then\n\t dfflo3 = dfflo2(x,ier) + x**2/2\n\t return\n\tendif\n\tif ( xa .gt. bdn10 ) then\n\t dfflo3 = x*( xninv(13) + x*( xninv(14) + x*( xninv(15) +\n +\t\tx*( xninv(16) + x*xninv(17) ))))\n\telse\n\t dfflo3 = 0\n\tendif\n\tif ( xa .gt. bdn05 ) then\n\t dfflo3 = x*( xninv(8) + x*( xninv(9) + x*( xninv(10) +\n +\t\tx*( xninv(11) + x*( xninv(12) + dfflo3 )))))\n\tendif\n\tif ( xa .gt. bdn01 ) then\n\t dfflo3 = x*( xninv(4) + x*( xninv(5) + x*( xninv(6) +\n +\t\tx*( xninv(7) + dfflo3 ))))\n\tendif\n\tdfflo3 = - x**3*( xninv(3) + dfflo3 )\n* #] calculations:\n*###] dfflo3:\n\tend\n\n\n*###[ ffxl22:\n\tsubroutine ffxl22(xl22,x,ier)\n***#[*comment:***************************************************\n*\tcalculates Li2(2-x) for |x|<.14 in a faster way to ~15\t*\n*\tsignificant figures.\t\t\t\t\t*\n***#]*comment:***************************************************\n* #[ declarations:\n\timplicit none\n\tinteger ier,init\n\tDOUBLE PRECISION xl22,x,bdn01,bdn05,bdn10,bdn15,bdn20,bdn25,\n +\t\txprec,xa,ffbnd,dilog2(29)\n\texternal ffbnd\n\tsave xprec,bdn01,bdn05,bdn10,bdn15,bdn20,bdn25,init,dilog2\n\tinclude 'ff.h'\n\tdata xprec /-1D0/\n\tdata init /0/\n\tif ( init .eq. 0 ) then\n\t init = 1\n* taylor(dilog(x-1),x,30);\n\t dilog2( 1) = 0.d0\n\t dilog2( 2) = 1/4.d0\n\t dilog2( 3) = 1/6.d0\n\t dilog2( 4) = 5/48.d0\n\t dilog2( 5) = 1/15.d0\n\t dilog2( 6) = 2/45.d0\n\t dilog2( 7) = 13/420.d0\n\t dilog2( 8) = 151/6720.d0\n\t dilog2( 9) = 16/945.d0\n\t dilog2(10) = 83/6300.d0\n\t dilog2(11) = 73/6930.d0\n\t dilog2(12) = 1433/166320.d0\n\t dilog2(13) = 647/90090.d0\n\t dilog2(14) = 15341/2522520.d0\n\t dilog2(15) = 28211/5405400.d0\n\t dilog2(16) = 10447/2306304.d0\n\t dilog2(17) = 608/153153.d0\n\t dilog2(18) = 19345/5513508.d0\n\t dilog2(19) = 18181/5819814.d0\n\t dilog2(20) = 130349/46558512.d0\n\t dilog2(21) = 771079/305540235.d0\n\t dilog2(22) = 731957/320089770.d0\n\t dilog2(23) = 2786599/1338557220.d0\n\t dilog2(24) = 122289917/64250746560.d0\n\t dilog2(25) = 14614772/8365982625.d0\n\t dilog2(26) = 140001721/87006219300.d0\n\t dilog2(27) = 134354573/90352612350.d0\n\t dilog2(28) = 774885169/562194032400.d0\n\t dilog2(29) = 745984697/582272390700.d0\n\tendif\n* #] declarations:\n* #[ initialisation:\n\tif ( xprec .ne. precx ) then\n\t xprec = precx\n*\t determine the boundaries for 1,5,10,15,20 terms\n\t bdn01 = ffbnd(2,1,dilog2)\n\t bdn05 = ffbnd(2,5,dilog2)\n\t bdn10 = ffbnd(2,10,dilog2)\n\t bdn15 = ffbnd(2,15,dilog2)\n\t bdn20 = ffbnd(2,20,dilog2)\n\t bdn25 = ffbnd(2,25,dilog2)\n\tendif\n* #] initialisation:\n* #[ calculations:\n\txa = abs(x)\n\tif ( xa .gt. bdn25 ) then\n\t call ffwarn(230,ier,precx,dilog2(27)*xa**25)\n\tendif\n\tif ( xa .gt. bdn20 ) then\n\t xl22 = x*( dilog2(22) + x*( dilog2(23) + x*( dilog2(24) +\n +\t\tx*( dilog2(25) + x*dilog2(26) ))))\n\telse\n\t xl22 = 0\n\tendif\n\tif ( xa .gt. bdn15 ) then\n\t xl22 = x*( dilog2(17) + x*( dilog2(18) + x*( dilog2(19) +\n +\t\tx*( dilog2(20) + x*dilog2(21) ))))\n\tendif\n\tif ( xa .gt. bdn10 ) then\n\t xl22 = x*( dilog2(12) + x*( dilog2(13) + x*( dilog2(14) +\n +\t\tx*( dilog2(15) + x*dilog2(16) ))))\n\tendif\n\tif ( xa .gt. bdn05 ) then\n\t xl22 = x*( dilog2(7) + x*( dilog2(8) + x*( dilog2(9) +\n +\t\tx*( dilog2(10) + x*( dilog2(11) + xl22 )))))\n\tendif\n\tif ( xa .gt. bdn01 ) then\n\t xl22 = x*( dilog2(3) + x*( dilog2(4) + x*( dilog2(5) +\n +\t\tx*( dilog2(6) + xl22 ))))\n\tendif\n\txl22 = - x**2*( dilog2(2) + xl22 )\n* #] calculations:\n*###] ffxl22:\n\tend\n", "meta": {"hexsha": "a6e849ca859f4029f157c15673dfa1ee21a5f717", "size": 15091, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Tauola1_1_5/SANC/LoopTools-2.1/ff/ffxli2.f", "max_stars_repo_name": "klendathu2k/StarGenerator", "max_stars_repo_head_hexsha": "7dd407c41d4eea059ca96ded80d30bda0bc014a4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-12-24T19:37:00.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T06:57:20.000Z", "max_issues_repo_path": "Tauola1_1_5/SANC/LoopTools-2.1/ff/ffxli2.f", "max_issues_repo_name": "klendathu2k/StarGenerator", "max_issues_repo_head_hexsha": "7dd407c41d4eea059ca96ded80d30bda0bc014a4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Tauola1_1_5/SANC/LoopTools-2.1/ff/ffxli2.f", "max_forks_repo_name": "klendathu2k/StarGenerator", "max_forks_repo_head_hexsha": "7dd407c41d4eea059ca96ded80d30bda0bc014a4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-15T12:22:30.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-15T12:22:30.000Z", "avg_line_length": 25.5346869712, "max_line_length": 73, "alphanum_fraction": 0.5337618448, "num_tokens": 6231, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339516289534, "lm_q2_score": 0.7772998663336157, "lm_q1q2_score": 0.6527250883569844}} {"text": " subroutine fvdge(x,y,ds,dy)\r\n!\r\n use kinddefine\r\n implicit none\r\n real(kind=K8),dimension(5),intent(in) :: x,y\r\n real(kind=K8),intent(out) :: ds,dy\r\n real(kind=K8) :: a1,a3,f1,f2,f3,fx,h,two\r\n real(kind=K8) :: x1,x2,x3,x4,x5,x21,x32,x43,x54\r\n real(kind=K8) :: y1,y2,y3,y4,y5,yp21,yp32,yp43,yp54,ypp1,ypp2,ypp3\r\n real(kind=K8) :: z13\r\n data h/0.5d+0/,two/2.0d+0/\r\n!\r\n x1=x(1)\r\n x2=x(2)\r\n x3=x(3)\r\n x4=x(4)\r\n x5=x(5)\r\n!\r\n y1=y(1)\r\n y2=y(2)\r\n y3=y(3)\r\n y4=y(4)\r\n y5=y(5)\r\n!\r\n! find delta-y\r\n f1=(x3-x1)*(x3-x2)\r\n f1=two/f1\r\n!\r\n f2=(x4-x3)*(x3-x2)\r\n f2=-two/f2\r\n!\r\n f3=(x5-x3)*(x4-x3)\r\n f3=two/f3\r\n!\r\n z13=x1+x2+x2-x4-x4-x5\r\n a1=(x2+x3-x4-x5)/z13\r\n a3=(x1+x2-x3-x4)/z13\r\n!\r\n yp21=(y2-y1)/(x2-x1)\r\n yp32=(y3-y2)/(x3-x2)\r\n yp43=(y4-y3)/(x4-x3)\r\n yp54=(y5-y4)/(x5-x4)\r\n!\r\n x21=h*(x2+x1)\r\n x32=h*(x3+x2)\r\n x43=h*(x4+x3)\r\n x54=h*(x5+x4)\r\n!\r\n ypp1=(yp32-yp21)/(x32-x21)\r\n ypp2=(yp43-yp32)/(x43-x32)\r\n ypp3=(yp54-yp43)/(x54-x43)\r\n ds=a1*ypp1+a3*ypp3-ypp2\r\n fx=f2-a1*f1-a3*f3\r\n dy=ds/fx\r\n!\r\n end subroutine fvdge\r\n", "meta": {"hexsha": "b7634b60700501ff1d78e41d95fa9772e9c20aaa", "size": 1227, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/fvdge.f", "max_stars_repo_name": "aldorona/contur", "max_stars_repo_head_hexsha": "d4197b55e28b20f905f9418f0473b2c39fadb0fd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-03-03T10:30:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-25T22:20:59.000Z", "max_issues_repo_path": "src/fvdge.f", "max_issues_repo_name": "aldorona/contur", "max_issues_repo_head_hexsha": "d4197b55e28b20f905f9418f0473b2c39fadb0fd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-08-01T20:33:57.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-05T13:46:04.000Z", "max_forks_repo_path": "src/fvdge.f", "max_forks_repo_name": "aldorona/contur", "max_forks_repo_head_hexsha": "d4197b55e28b20f905f9418f0473b2c39fadb0fd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-10-25T16:14:26.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-25T12:14:43.000Z", "avg_line_length": 21.5263157895, "max_line_length": 73, "alphanum_fraction": 0.4596577017, "num_tokens": 564, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308036221031, "lm_q2_score": 0.6992544210587586, "lm_q1q2_score": 0.6527056161851854}} {"text": "program main\n use double\n use stoichiometry\n implicit none\n\n integer :: k,l\n integer, parameter :: MATRIXSIZE=5\n real(kind=dp),dimension(MATRIXSIZE,MATRIXSIZE) :: hilb=0_dp\n\n ! construct a hilbert matrix\n do k=lbound(hilb,1),ubound(hilb,1)\n do l=lbound(hilb,2),ubound(hilb,2)\n hilb(k,l)=1._dp/(k+l-1)\n end do\n end do\n\n ! lets print the result\n print *, hilb\nend program main\n", "meta": {"hexsha": "a8bdce4bfc95fe9ce90d2386424041ccedf58c02", "size": 433, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "main.f90", "max_stars_repo_name": "julianschnidder/dynanode", "max_stars_repo_head_hexsha": "edc95ac29acc28cf3d83786a85d03d1515c16292", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "main.f90", "max_issues_repo_name": "julianschnidder/dynanode", "max_issues_repo_head_hexsha": "edc95ac29acc28cf3d83786a85d03d1515c16292", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "main.f90", "max_forks_repo_name": "julianschnidder/dynanode", "max_forks_repo_head_hexsha": "edc95ac29acc28cf3d83786a85d03d1515c16292", "max_forks_repo_licenses": ["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.65, "max_line_length": 63, "alphanum_fraction": 0.6189376443, "num_tokens": 140, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8311430645886583, "lm_q2_score": 0.7853085859124003, "lm_q1q2_score": 0.652703784743018}} {"text": "! { dg-do run }\n! PR fortran/28276\n! Original code submitted by Harald Anlauf\n! Converted to Dejagnu for the testsuite by Steven G. Kargl\n!\nprogram gfcbug36\n implicit none\n real, parameter :: one = 1.0\n real :: a = one\n\n if (fraction(a) /= 0.5) call abort\n if (fraction(one) /= 0.5) call abort\n if (fraction(1.0) /= 0.5) call abort\n\n if (exponent(a) /= 1.0) call abort\n if (exponent(one) /= 1.0) call abort\n if (exponent (1.0) /= 1.0) call abort\n\n if (scale(fraction(a), exponent(a)) / a /= 1.) call abort\n if (scale(fraction(one), exponent(one)) / one /= 1.) call abort\n if (scale(fraction(1.0), exponent(1.0)) / 1.0 /= 1.) call abort\n\nend program gfcbug36\n", "meta": {"hexsha": "9f701e82be1a303a47b9c0be4077e8188683e0e5", "size": 676, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/exponent_1.f90", "max_stars_repo_name": "maurizioabba/rose", "max_stars_repo_head_hexsha": "7597292cf14da292bdb9a4ef573001b6c5b9b6c0", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/exponent_1.f90", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/exponent_1.f90", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 28.1666666667, "max_line_length": 65, "alphanum_fraction": 0.6346153846, "num_tokens": 251, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.7853085808877581, "lm_q1q2_score": 0.6527037674283408}} {"text": "module spherepack_precision\n\n ! Explicit typing only\n implicit none\n\n ! Everything is private unless stated otherwise\n private\n public :: wp ! Working precision\n public :: ip ! Integer precision\n public :: PI, TWO_PI, HALF_PI, MACHINE_EPSILON\n public :: get_pi\n public :: even, odd\n\n ! Floating point precision constants\n integer, parameter :: FLOAT128 = selected_real_kind(p=33, r=4931) ! 33 digits, range [10^(-4931), 10^(+4931) - 1], 128 bits\n integer, parameter :: FLOAT64 = selected_real_kind(p=15, r=307) ! 15 digits, range [10^(-307) , 10^(+307) - 1], 64 bits\n integer, parameter :: FLOAT32 = selected_real_kind(p=6, r=37) ! 6 digits, range [10^(-37) , 10^(+37) - 1], 32 bits\n integer, parameter :: wp = FLOAT64 ! Default floating point precision\n\n ! Integer precision constants\n integer, parameter :: INT64 = selected_int_kind(r=18) ! 19 digits plus sign, range [-2^(63), +2^(63) - 1], 64 bits\n integer, parameter :: INT32 = selected_int_kind(r=9) ! 10 digits plus sign, range [-2^(31), +2^(31) - 1], 32 bits\n integer, parameter :: INT16 = selected_int_kind(r=4) ! 5 digits plus sign, range [-2^(15), +2^(15) - 1], 16 bits\n integer, parameter :: INT8 = selected_int_kind(r=2) ! 3 digits plus sign, range [-2^(7) , +2^(7) - 1], 8 bits\n integer, parameter :: ip = INT32! Default integer precision\n\n ! Parameters confined to the module\n real(wp), parameter :: ONE = 1.0_wp\n real(wp), parameter :: TWO = 2.0_wp\n\n ! Commonly used constants\n real(wp), parameter :: PI = acos(-ONE)\n real(wp), parameter :: HALF_PI = PI/TWO\n real(wp), parameter :: TWO_PI = TWO * PI\n real(wp), parameter :: MACHINE_EPSILON = epsilon(ONE)\n\ncontains\n\n pure function odd(i) &\n result (return_value)\n\n ! Dummy arguments\n integer(ip), intent(in) :: i\n logical :: return_value\n\n return_value = btest(i, 0)\n\n end function odd\n\n pure function even(i) &\n result (return_value)\n\n ! Dummy arguments\n integer(ip), intent(in) :: i\n logical :: return_value\n\n return_value = .not. odd(i)\n\n end function even\n\n pure function get_pi() &\n result (return_value)\n\n ! Dummy arguments\n real(wp) :: return_value\n\n return_value = 3.141592653589793238462643383279502884197169399375105820974_wp\n\n end function get_pi\n\nend module spherepack_precision\n", "meta": {"hexsha": "c72ad4c1bce3773b8ee78538afad1ff5e6c14aa9", "size": 2445, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/spherepack_precision.f90", "max_stars_repo_name": "jlokimlin/spherepack4.1", "max_stars_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-06-28T14:01:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T21:59:28.000Z", "max_issues_repo_path": "src/spherepack_precision.f90", "max_issues_repo_name": "jlokimlin/spherepack4.1", "max_issues_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2016-05-07T23:00:35.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-22T23:52:30.000Z", "max_forks_repo_path": "src/spherepack_precision.f90", "max_forks_repo_name": "jlokimlin/spherepack4.1", "max_forks_repo_head_hexsha": "e80da29462c5987162a0884baaab7434d0215467", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-06-28T14:03:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-20T12:53:54.000Z", "avg_line_length": 33.9583333333, "max_line_length": 127, "alphanum_fraction": 0.6294478528, "num_tokens": 687, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430394931457, "lm_q2_score": 0.7853085808877581, "lm_q1q2_score": 0.6527037608591002}} {"text": "! RUN: bbc -emit-fir %s -o - | FileCheck %s\n\nsubroutine test_dreal(r, c)\n real(8), intent(out) :: r\n complex(8), intent(in) :: c\n\n! CHECK-LABEL: func @_QPtest_dreal(\n! CHECK-SAME: %[[ARG_0:.*]]: !fir.ref {fir.bindc_name = \"r\"},\n! CHECK-SAME: %[[ARG_1:.*]]: !fir.ref> {fir.bindc_name = \"c\"}) {\n! CHECK: %[[VAL_0:.*]] = fir.load %[[ARG_1]] : !fir.ref>\n! CHECK: %[[VAL_1:.*]] = fir.extract_value %[[VAL_0]], [0 : index] : (!fir.complex<8>) -> f64\n! CHECK: fir.store %[[VAL_1]] to %[[ARG_0]] : !fir.ref\n! CHECK: return\n! CHECK: }\n\n r = dreal(c)\nend\n", "meta": {"hexsha": "65d05c900e51aabf0c7bb3ed37ebccda8983d4c9", "size": 598, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "flang/test/Lower/Intrinsics/dreal.f90", "max_stars_repo_name": "ornata/llvm-project", "max_stars_repo_head_hexsha": "494913b8b4e4bce0b3525e5569d8e486e82b9a52", "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": "flang/test/Lower/Intrinsics/dreal.f90", "max_issues_repo_name": "ornata/llvm-project", "max_issues_repo_head_hexsha": "494913b8b4e4bce0b3525e5569d8e486e82b9a52", "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": "flang/test/Lower/Intrinsics/dreal.f90", "max_forks_repo_name": "ornata/llvm-project", "max_forks_repo_head_hexsha": "494913b8b4e4bce0b3525e5569d8e486e82b9a52", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.2222222222, "max_line_length": 95, "alphanum_fraction": 0.5652173913, "num_tokens": 241, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867873410141, "lm_q2_score": 0.8175744850834649, "lm_q1q2_score": 0.6525771516607547}} {"text": "! A simple fortran module for setting up a graph.\r\n! Just vertices, edges and neighbours. \r\nmodule graphf\r\n use iso_fortran_env, wp => real64, sp => real32\r\n implicit none\r\n private\r\n public :: graph\r\n public :: example1\r\n\r\n type graph\r\n integer :: V = 0\r\n integer :: E = 0\r\n integer,allocatable :: edges(:,:)\r\n real(wp),allocatable :: eweight(:) \r\n real(sp),allocatable :: emat(:,:)\r\n integer,allocatable :: nmat(:,:) !matrix of neighbours (1 or 0)\r\n logical :: directed = .false.\r\n \r\n contains\r\n procedure :: deallocate => deallocate_graph\r\n procedure :: addVertex => addVertex_graph\r\n procedure :: setOrder => addVertex_graph\r\n procedure :: addEdge => addEdge_graph\r\n procedure :: degree => degree_graph\r\n\r\n end type graph\r\n\r\ncontains\r\n\r\nsubroutine deallocate_graph(self)\r\n implicit none\r\n class(graph) :: self\r\n if(allocated(self%edges)) deallocate(self%edges)\r\n if(allocated(self%eweight)) deallocate(self%eweight)\r\n if(allocated(self%nmat)) deallocate(self%nmat)\r\n if(allocated(self%emat)) deallocate(self%emat)\r\n self%V = 0\r\n self%E = 0\r\n return\r\nend subroutine deallocate_graph\r\n\r\n!-- add a vertex (or x vertices) to the graph\r\nsubroutine addVertex_graph(self,x)\r\n class(graph) :: self\r\n integer,optional :: x !number of new vertices\r\n integer,allocatable :: ndum(:,:)\r\n real(sp),allocatable :: edum(:,:)\r\n integer :: k,o,n\r\n if(present(x))then\r\n if(x<1)return\r\n k = x\r\n else\r\n k = 1\r\n endif\r\n \r\n self%V = self%V + k\r\n if(.not.allocated(self%nmat))then\r\n allocate(self%nmat(k,k), source = 0)\r\n allocate(self%emat(k,k), source = 0.0_sp)\r\n else\r\n o = self%V - k\r\n n = self%V\r\n allocate(ndum(n,n),edum(n,n))\r\n ndum(1:o,1:o) = self%nmat(1:o,1:o)\r\n edum(1:o,1:o) = self%emat(1:o,1:o)\r\n call move_alloc(ndum,self%nmat)\r\n call move_alloc(edum,self%emat)\r\n self%nmat(:,n) = 0\r\n self%nmat(n,:) = 0\r\n self%emat(:,n) = 0\r\n self%emat(n,:) = 0\r\n endif\r\n \r\nend subroutine addVertex_graph\r\n\r\n!-- add an edge to the graph\r\nsubroutine addEdge_graph(self, vertex1, vertex2, weight)\r\n class(graph) :: self\r\n integer,intent(in) :: vertex1,vertex2\r\n real(sp),optional :: weight\r\n real(sp) :: w2\r\n integer :: edge(2)\r\n !integer,allocatable :: edum(:,:)\r\n !real(wp),allocatable :: wdum(:)\r\n logical :: ex\r\n !-- if any of the two vertices is larger than the specified number\r\n ! of vertices in the graph, print a warning and stop\r\n if(vertex1 > self%V .or. vertex2 > self%V)then\r\n error stop \"please set the number of vertices before defining edges!\"\r\n endif\r\n !-- the edge weight is an optional argument. If not present it is = 1.0\r\n if(present(weight))then\r\n w2=weight\r\n else\r\n w2=1.0_sp\r\n endif\r\n !-- only undirected graphs are sorted\r\n if(vertex1 > vertex2 .and. .not.self%directed)then\r\n edge(2) = vertex1\r\n edge(1) = vertex2\r\n else \r\n edge(1) = vertex1\r\n edge(2) = vertex2\r\n endif \r\n !-- check if the vertex was already documented in the neighbour matrix\r\n ex=areNeighbours(self,edge(1),edge(2))\r\n if(.not.ex)then\r\n self%nmat(edge(1),edge(2)) = 1\r\n self%emat(edge(1),edge(2)) = w2\r\n if(.not.self%directed)then !for undirected graphs nmat is symmetric\r\n self%nmat(edge(2),edge(1)) = 1\r\n self%emat(edge(2),edge(1)) = w2\r\n endif \r\n self%E = self%E + 1\r\n endif\r\n\r\n return\r\nend subroutine addEdge_graph\r\n\r\n!-- are two edges identical?\r\nlogical function equalEdge(edge1, edge2)\r\n implicit none\r\n integer,intent(in) :: edge1(2)\r\n integer,intent(in) :: edge2(2)\r\n equalEdge = .false.\r\n if( edge1(1)==edge2(1) .and. edge1(2)==edge2(2))then\r\n equalEdge = .true.\r\n else\r\n equalEdge = .false.\r\n endif\r\n return\r\nend function equalEdge\r\n\r\n!-- decide if the two vertices are neighbouring\r\nlogical function areNeighbours(self,v1,v2)\r\n implicit none\r\n class(graph) :: self\r\n integer,intent(in) :: v1,v2\r\n areNeighbours = .false.\r\n if( self%nmat(v1,v2) == 1)then\r\n areNeighbours = .true.\r\n endif\r\n return\r\nend function areNeighbours\r\n\r\n!-- get the degree of a vertex (i.e., the number of its neighbours)\r\nfunction degree_graph(self, v, neighbours)\r\n class(graph),intent(in) :: self\r\n integer :: degree_graph\r\n integer,intent(in) :: v\r\n integer :: i,u\r\n integer :: neighbours(*)\r\n u = 0\r\n do i=1,self%V\r\n !-- since nmat is *not* symmetric for directed graphs\r\n ! this should work for both, directed and undirected\r\n if( self%nmat(v,i)==1)then\r\n u = u + 1\r\n neighbours(u)=i\r\n endif\r\n enddo\r\n degree_graph = u\r\n return\r\nend function degree_graph\r\n\r\n!=====================================================================================!\r\n\r\nsubroutine example1(G)\r\n implicit none\r\n class(graph) :: G\r\n real(sp) :: l\r\n call G%setOrder(16)\r\n l = 1.0_sp \r\n\r\n call G%addEdge( 1, 2,l)\r\n call G%addEdge( 1, 5, l)\r\n call G%addEdge( 2, 3, l)\r\n call G%addEdge( 3, 4, l)\r\n call G%addEdge( 3, 8, l)\r\n call G%addEdge( 4, 5, l)\r\n call G%addEdge( 4, 6, l)\r\n call G%addEdge( 5, 9, l)\r\n call G%addEdge( 6, 7, l)\r\n call G%addEdge( 6, 10, l)\r\n call G%addEdge( 6, 11, l)\r\n call G%addEdge( 7, 8, l)\r\n call G%addEdge( 7, 15, l)\r\n call G%addEdge( 9, 10, l)\r\n call G%addEdge(11, 12, l)\r\n call G%addEdge(11, 13, l)\r\n call G%addEdge(12, 13, l)\r\n call G%addEdge(12, 14, l)\r\n call G%addEdge(13, 15, l)\r\n call G%addEdge(14, 15, l)\r\n call G%addEdge(15, 16, l)\r\n return\r\nend subroutine example1\r\n\r\n\r\nend module graphf", "meta": {"hexsha": "edd80e9e3307844eaf104254cb423ba6d2197e74", "size": 5845, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/graphf.f90", "max_stars_repo_name": "pprcht/shortestpaths", "max_stars_repo_head_hexsha": "5c832666bdca34517550f2064febaa4e14b7800e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-04-28T21:23:26.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-16T00:00:48.000Z", "max_issues_repo_path": "fortran/graphf.f90", "max_issues_repo_name": "pprcht/shortestpaths", "max_issues_repo_head_hexsha": "5c832666bdca34517550f2064febaa4e14b7800e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fortran/graphf.f90", "max_forks_repo_name": "pprcht/shortestpaths", "max_forks_repo_head_hexsha": "5c832666bdca34517550f2064febaa4e14b7800e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.225, "max_line_length": 88, "alphanum_fraction": 0.572968349, "num_tokens": 1751, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.798186787341014, "lm_q2_score": 0.8175744850834649, "lm_q1q2_score": 0.6525771516607546}} {"text": "! { dg-do compile }\n! { dg-options \"-O2 -fcheck=bounds\" }\n\n FUNCTION F06FKFN(N,W,INCW,X,INCX)\n IMPLICIT NONE\n INTEGER, PARAMETER :: WP = KIND(0.0D0)\n REAL (KIND=WP) :: F06FKFN\n REAL (KIND=WP), PARAMETER :: ONE = 1.0E+0_WP\n REAL (KIND=WP), PARAMETER :: ZERO = 0.0E+0_WP\n INTEGER, INTENT (IN) :: INCW, INCX, N\n REAL (KIND=WP), INTENT (IN) :: W(*), X(*)\n REAL (KIND=WP) :: ABSYI, NORM, SCALE, SSQ\n INTEGER :: I, IW, IX\n REAL (KIND=WP), EXTERNAL :: F06BMFN\n INTRINSIC ABS, SQRT\n IF (N<1) THEN\n NORM = ZERO\n ELSE IF (N==1) THEN\n NORM = SQRT(W(1))*ABS(X(1))\n ELSE\n IF (INCW>0) THEN\n IW = 1\n ELSE\n IW = 1 - (N-1)*INCW\n END IF\n IF (INCX>0) THEN\n IX = 1\n ELSE\n IX = 1 - (N-1)*INCX\n END IF\n SCALE = ZERO\n SSQ = ONE\n DO I = 1, N\n IF ((W(IW)/=ZERO) .AND. (X(IX)/=ZERO)) THEN\n ABSYI = SQRT(W(IW))*ABS(X(IX))\n IF (SCALE del) STOP 1\n if (abs(c1 - cmplx(-0.5,+0.5)) > del) STOP 2\n if (abs(c2 - cmplx(-0.5E2,+0.5)) > del) STOP 3\n if (abs(c3 - cmplx(-0.5,+0.5E-2)) > del) STOP 4\n if (abs(c4 - cmplx(-1.0,+1.0)) > del) STOP 5\n if (any (abs (rp - 1.0) > del)) STOP 6\n if (any (abs (rn + 1.0) > del)) STOP 7\n end program\n", "meta": {"hexsha": "a2e033200b377d49a3e526b828ffde9806c9939e", "size": 889, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/real_const_1.f", "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/real_const_1.f", "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/real_const_1.f", "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": 35.56, "max_line_length": 69, "alphanum_fraction": 0.4701912261, "num_tokens": 402, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744761936438, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.6525771327902361}} {"text": "C File: goto_05.f\nC A simple program with a single forward conditional goto and\nC a single backward conditional goto.\nC The program computes and prints out the values of n! for n in [1,10].\n\n program factorial\n implicit none\n\n integer i, n, fact\n\n i = 0\n n = 10\n fact = 0\n\n 111 i = i + 1\n if (fact .ne. 0) goto 222\n\n fact = fact + 1 ! this line is executed exactly once\n\n 222 fact = fact * i\n\n write (*, 10) i, fact\n\n if (i .lt. n) goto 111\n\n stop\n 10 format('i = ', I3, '; fact = ', I8)\n\n end program factorial\n", "meta": {"hexsha": "5fbf6927b031f4220bcf643e4f568336ae1c7df7", "size": 595, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/data/program_analysis/goto/goto_05.f", "max_stars_repo_name": "mikiec84/delphi", "max_stars_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2018-03-03T11:57:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-16T21:19:54.000Z", "max_issues_repo_path": "tests/data/program_analysis/goto/goto_05.f", "max_issues_repo_name": "mikiec84/delphi", "max_issues_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 385, "max_issues_repo_issues_event_min_datetime": "2018-02-21T16:52:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-17T07:44:56.000Z", "max_forks_repo_path": "tests/data/program_analysis/goto/goto_05.f", "max_forks_repo_name": "mikiec84/delphi", "max_forks_repo_head_hexsha": "2e517f21e76e334c7dfb14325d25879ddf26d10d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2018-03-20T01:08:11.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-29T01:04:49.000Z", "avg_line_length": 19.8333333333, "max_line_length": 75, "alphanum_fraction": 0.5630252101, "num_tokens": 184, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744673038222, "lm_q2_score": 0.7981867777396212, "lm_q1q2_score": 0.6525771296194252}} {"text": " FUNCTION AREA (G,I,J,K)\r\nC\r\nC THIS ROUTINE IS CALLED BY SFAREA WHICH IS CALLED BY EMGFIN TO\r\nC COMPUTE THE SURFACE AREAS OF THE SOLID ELEMENTS\r\nC\r\n DIMENSION G(1)\r\n AREA = 0.5*SQRT(\r\n 1 ((G(J+2)-G(I+2))*(G(K+3)-G(I+3))-(G(J+3)-G(I+3))*(G(K+2)-G(I+2)))\r\n 2 **2\r\n 3+((G(J+3)-G(I+3))*(G(K+1)-G(I+1))-(G(J+1)-G(I+1))*(G(K+3)-G(I+3)))\r\n 4 **2\r\n 5+((G(J+1)-G(I+1))*(G(K+2)-G(I+2))-(G(J+2)-G(I+2))*(G(K+1)-G(I+1)))\r\n 6 **2)\r\n RETURN\r\n END\r\n", "meta": {"hexsha": "1e78755802296366421e581b5ede2090fcc52191", "size": 492, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "mis/area.f", "max_stars_repo_name": "ldallolio/NASTRAN-95", "max_stars_repo_head_hexsha": "6d2c175f5b53ebaec4ba2b5186f7926ef9d0ed47", "max_stars_repo_licenses": ["NASA-1.3"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2016-01-09T14:33:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-18T11:51:42.000Z", "max_issues_repo_path": "mis/area.f", "max_issues_repo_name": "gassive/NASTRAN95", "max_issues_repo_head_hexsha": "98cb3acaa7990d639360601648498834c7782056", "max_issues_repo_licenses": ["NASA-1.3"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2016-01-17T07:30:19.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-06T19:37:44.000Z", "max_forks_repo_path": "mis/area.f", "max_forks_repo_name": "gassive/NASTRAN95", "max_forks_repo_head_hexsha": "98cb3acaa7990d639360601648498834c7782056", "max_forks_repo_licenses": ["NASA-1.3"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-04-07T20:51:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T14:16:01.000Z", "avg_line_length": 30.75, "max_line_length": 73, "alphanum_fraction": 0.4491869919, "num_tokens": 231, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.95598134762883, "lm_q2_score": 0.6825737408694988, "lm_q1q2_score": 0.6525277646524753}} {"text": "subroutine invmtx(a,b,deter,nsize)\n\n!-----------------------------------------------------------------------\n!\n! This routine inverts a square matrix A -> Mat(nsize,nsize). The\n! inverse is stored in B. Its determinant is DETER\n!\n! \n!-----------------------------------------------------------------------\n use typre\n implicit none\n integer(ip), intent(in) :: nsize\n real(rp), intent(in) :: a(nsize,nsize)\n real(rp), intent(out) :: b(nsize,nsize),deter\n integer(ip) :: isize,jsize\n real(rp) :: denom,t1,t2,t3,t4\n\n select case (nsize)\n \n case(1)\n deter=a(1,1)\n if(deter==0.0_rp) return\n b(1,1) = 1.0_rp/a(1,1)\n\n case(2)\n deter=a(1,1)*a(2,2)-a(2,1)*a(1,2)\n if(deter==0.0_rp) return\n denom=1.0_rp/deter\n b(1,1) = a(2,2)*denom\n b(2,2) = a(1,1)*denom\n b(2,1) =-a(2,1)*denom\n b(1,2) =-a(1,2)*denom \n\n case(3)\n t1 = a(2,2)*a(3,3) - a(3,2)*a(2,3)\n t2 =-a(2,1)*a(3,3) + a(3,1)*a(2,3)\n t3 = a(2,1)*a(3,2) - a(3,1)*a(2,2)\n deter = a(1,1)*t1 + a(1,2)*t2 + a(1,3)*t3\n if(deter==0.0_rp) return\n denom = 1.0_rp/deter\n b(1,1) = t1*denom\n b(2,1) = t2*denom\n b(3,1) = t3*denom\n b(2,2) = ( a(1,1)*a(3,3) - a(3,1)*a(1,3))*denom\n b(3,2) = (-a(1,1)*a(3,2) + a(1,2)*a(3,1))*denom\n b(3,3) = ( a(1,1)*a(2,2) - a(2,1)*a(1,2))*denom\n b(1,2) = (-a(1,2)*a(3,3) + a(3,2)*a(1,3))*denom\n b(1,3) = ( a(1,2)*a(2,3) - a(2,2)*a(1,3))*denom\n b(2,3) = (-a(1,1)*a(2,3) + a(2,1)*a(1,3))*denom\n\n case(4)\n t1= a(2,2)*a(3,3)*a(4,4) + a(2,3)*a(3,4)*a(4,2)&\n + a(2,4)*a(3,2)*a(4,3) - a(2,3)*a(3,2)*a(4,4)&\n - a(2,2)*a(3,4)*a(4,3) - a(2,4)*a(3,3)*a(4,2)\n t2=-a(2,1)*a(3,3)*a(4,4) - a(2,3)*a(3,4)*a(4,1)&\n - a(2,4)*a(3,1)*a(4,3) + a(2,4)*a(3,3)*a(4,1)&\n + a(2,3)*a(3,1)*a(4,4) + a(2,1)*a(3,4)*a(4,3)\n t3=+a(2,1)*a(3,2)*a(4,4) + a(2,2)*a(3,4)*a(4,1)&\n + a(2,4)*a(3,1)*a(4,2) - a(2,4)*a(3,2)*a(4,1)&\n - a(2,2)*a(3,1)*a(4,4) - a(2,1)*a(3,4)*a(4,2)\n t4=-a(2,1)*a(3,2)*a(4,3) - a(2,2)*a(3,3)*a(4,1)&\n - a(2,3)*a(3,1)*a(4,2) + a(2,3)*a(3,2)*a(4,1)&\n + a(2,2)*a(3,1)*a(4,3) + a(2,1)*a(3,3)*a(4,2)\n deter= a(1,1)*t1 + a(1,2)*t2 + a(1,3)*t3 + a(1,4)*t4\n if(deter==0.0_rp) return\n denom=1.0_rp/deter\n b(1,1) = t1*denom\n b(2,1) = t2*denom\n b(3,1) = t3*denom\n b(4,1) = t4*denom\n b(1,2) =(- a(1,2)*a(3,3)*a(4,4) - a(1,3)*a(3,4)*a(4,2)&\n - a(1,4)*a(3,2)*a(4,3) + a(1,3)*a(3,2)*a(4,4)&\n + a(1,2)*a(3,4)*a(4,3) + a(1,4)*a(3,3)*a(4,2))*denom\n b(2,2) =( a(1,1)*a(3,3)*a(4,4) + a(1,3)*a(3,4)*a(4,1)&\n + a(1,4)*a(3,1)*a(4,3) - a(1,4)*a(3,3)*a(4,1)&\n - a(1,3)*a(3,1)*a(4,4) - a(1,1)*a(3,4)*a(4,3))*denom\n b(3,2) =(- a(1,1)*a(3,2)*a(4,4) - a(1,2)*a(3,4)*a(4,1)&\n - a(1,4)*a(3,1)*a(4,2) + a(1,4)*a(3,2)*a(4,1)&\n + a(1,2)*a(3,1)*a(4,4) + a(1,1)*a(3,4)*a(4,2))*denom\n b(4,2) =( a(1,1)*a(3,2)*a(4,3) + a(1,2)*a(3,3)*a(4,1)&\n + a(1,3)*a(3,1)*a(4,2) - a(1,3)*a(3,2)*a(4,1)&\n - a(1,2)*a(3,1)*a(4,3) - a(1,1)*a(3,3)*a(4,2))*denom\n b(1,3) =( a(1,2)*a(2,3)*a(4,4) + a(1,3)*a(2,4)*a(4,2)&\n + a(1,4)*a(2,2)*a(4,3) - a(1,3)*a(2,2)*a(4,4)&\n - a(1,2)*a(2,4)*a(4,3) - a(1,4)*a(2,3)*a(4,2))*denom\n b(2,3) =(- a(1,1)*a(2,3)*a(4,4) - a(1,3)*a(2,4)*a(4,1)&\n - a(1,4)*a(2,1)*a(4,3) + a(1,4)*a(2,3)*a(4,1)&\n + a(1,3)*a(2,1)*a(4,4) + a(1,1)*a(2,4)*a(4,3))*denom\n b(3,3) =( a(1,1)*a(2,2)*a(4,4) + a(1,2)*a(2,4)*a(4,1)&\n + a(1,4)*a(2,1)*a(4,2) - a(1,4)*a(2,2)*a(4,1)&\n - a(1,2)*a(2,1)*a(4,4) - a(1,1)*a(2,4)*a(4,2))*denom\n b(4,3) =(- a(1,1)*a(2,2)*a(4,3) - a(1,2)*a(2,3)*a(4,1)&\n - a(1,3)*a(2,1)*a(4,2) + a(1,3)*a(2,2)*a(4,1)&\n + a(1,2)*a(2,1)*a(4,3) + a(1,1)*a(2,3)*a(4,2))*denom\n b(1,4) =(- a(1,2)*a(2,3)*a(3,4) - a(1,3)*a(2,4)*a(3,2)&\n - a(1,4)*a(2,2)*a(3,3) + a(1,4)*a(2,3)*a(3,2)&\n + a(1,3)*a(2,2)*a(3,4) + a(1,2)*a(2,4)*a(3,3))*denom\n b(2,4) =( a(1,1)*a(2,3)*a(3,4) + a(1,3)*a(2,4)*a(3,1)&\n + a(1,4)*a(2,1)*a(3,3) - a(1,4)*a(2,3)*a(3,1)&\n - a(1,3)*a(2,1)*a(3,4) - a(1,1)*a(2,4)*a(3,3))*denom\n b(3,4) =(- a(1,1)*a(2,2)*a(3,4) - a(1,2)*a(2,4)*a(3,1)&\n - a(1,4)*a(2,1)*a(3,2) + a(1,4)*a(2,2)*a(3,1)&\n + a(1,2)*a(2,1)*a(3,4) + a(1,1)*a(2,4)*a(3,2))*denom\n b(4,4) =( a(1,1)*a(2,2)*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 - a(1,2)*a(2,1)*a(3,3) - a(1,1)*a(2,3)*a(3,2))*denom\n\n \n case default\n b=a\n call invert(b,nsize,nsize)\n\n end select\n\nend subroutine invmtx\n", "meta": {"hexsha": "3446437941418537ce5b405a8a825d92e0415700", "size": 4672, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Sources/mathru/invmtx.f90", "max_stars_repo_name": "ciaid-colombia/InsFEM", "max_stars_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-24T08:19:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-24T08:19:54.000Z", "max_issues_repo_path": "Sources/mathru/invmtx.f90", "max_issues_repo_name": "ciaid-colombia/InsFEM", "max_issues_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Sources/mathru/invmtx.f90", "max_forks_repo_name": "ciaid-colombia/InsFEM", "max_forks_repo_head_hexsha": "be7eb35baa75c31e3b175e95286549ccd84f8d40", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.275862069, "max_line_length": 72, "alphanum_fraction": 0.3831335616, "num_tokens": 2904, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813501370537, "lm_q2_score": 0.6825737279551493, "lm_q1q2_score": 0.6525277540186456}} {"text": "!\tprobvecitem is used to compute underlying item probabilities for one probability.\r\n\r\n!\tlocations provides location parameters and scales provides scale factors.\r\n!\ttheta is the value of the latent vector.\r\nfunction probvecitem(locations,scales,theta)\r\nimplicit none\r\n\r\n\r\nreal(kind=8),intent(in)::locations(:),scales(:,:),theta(:)\r\nreal(kind=8)::probvecitem(size(locations))\r\n\r\n!\t\r\n!\tcat is the category number.\r\n\r\n\r\n\r\ninteger::cat\r\n!\tprobdiv is used to normalize probabilities\t\r\nreal(kind=8)::probdiv\r\n!\tInitialize locations.\r\n\r\n\r\n\r\ndo cat=1,size(locations)\r\n\tprobvecitem(cat)=exp(sum(theta*scales(:,cat))+locations(cat))\r\n\t\r\nend do\r\nprobdiv=sum(probvecitem)\r\nprobvecitem=probvecitem/probdiv\r\n\r\nreturn\r\nend function probvecitem\r\n\t\r\n", "meta": {"hexsha": "b4270ecaebee70c6f7ce2ecd33a19f3a1489c064", "size": 734, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "Source/probvecitem.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/probvecitem.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/probvecitem.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": 21.5882352941, "max_line_length": 84, "alphanum_fraction": 0.7343324251, "num_tokens": 172, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096227509861, "lm_q2_score": 0.7122321903471563, "lm_q1q2_score": 0.652482763210042}} {"text": "C\nC file sepx4.f\nC\n SUBROUTINE SEPX4 (IORDER,A,B,M,MBDCND,BDA,ALPHA,BDB,BETA,C,D,N,\n 1 NBDCND,BDC,BDD,COFX,GRHS,USOL,IDMN,W,PERTRB,\n 2 IERROR)\nC\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC * *\nC * copyright (c) 1999 by UCAR *\nC * *\nC * UNIVERSITY CORPORATION for ATMOSPHERIC RESEARCH *\nC * *\nC * all rights reserved *\nC * *\nC * FISHPACK version 4.1 *\nC * *\nC * A PACKAGE OF FORTRAN SUBPROGRAMS FOR THE SOLUTION OF *\nC * *\nC * SEPARABLE ELLIPTIC PARTIAL DIFFERENTIAL EQUATIONS *\nC * *\nC * BY *\nC * *\nC * JOHN ADAMS, PAUL SWARZTRAUBER AND ROLAND SWEET *\nC * *\nC * OF *\nC * *\nC * THE NATIONAL CENTER FOR ATMOSPHERIC RESEARCH *\nC * *\nC * BOULDER, COLORADO (80307) U.S.A. *\nC * *\nC * WHICH IS SPONSORED BY *\nC * *\nC * THE NATIONAL SCIENCE FOUNDATION *\nC * *\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC\nC\nC\nC DIMENSION OF BDA(N+1), BDB(N+1), BDC(M+1), BDD(M+1),\nC ARGUMENTS USOL(IDMN,N+1), GRHS(IDMN,N+1),\nC W (SEE ARGUMENT LIST)\nC\nC LATEST REVISION NOVEMBER 1988\nC\nC PURPOSE SEPX4 SOLVES FOR EITHER THE SECOND-ORDER\nC FINITE DIFFERENCE APPROXIMATION OR A\nC FOURTH-ORDER APPROXIMATION TO A SEPARABLE\nC ELLIPTIC EQUATION\nC\nC AF(X)*UXX+BF(X)*UX+CF(X)*U+UYY = G(X,Y)\nC\nC ON A RECTANGLE (X GREATER THAN OR EQUAL TO\nC A AND LESS THAN OR EQUAL TO B, Y GREATER THAN\nC OR EQUAL TO C AND LESS THAN OR EQUAL TO D).\nC ANY COMBINATION OF PERIODIC OR MIXED BOUNDARY\nC CONDITIONS IS ALLOWED. IF BOUNDARY\nC CONDITIONS IN THE X DIRECTION ARE PERIODIC\nC (SEE MBDCND=0 BELOW) THEN THE COEFFICIENTS\nC MUST SATISFY\nC\nC AF(X)=C1,BF(X)=0,CF(X)=C2 FOR ALL X.\nC\nC HERE C1,C2 ARE CONSTANTS, C1.GT.0.\nC\nC THE POSSIBLE BOUNDARY CONDITIONS ARE:\nC IN THE X-DIRECTION:\nC (0) PERIODIC, U(X+B-A,Y)=U(X,Y) FOR\nC ALL Y,X\nC (1) U(A,Y), U(B,Y) ARE SPECIFIED FOR ALL Y\nC (2) U(A,Y), DU(B,Y)/DX+BETA*U(B,Y) ARE\nC SPECIFIED FOR ALL Y\nC (3) DU(A,Y)/DX+ALPHA*U(A,Y),DU(B,Y)/DX+\nC BETA*U(B,Y) ARE SPECIFIED FOR ALL Y\nC (4) DU(A,Y)/DX+ALPHA*U(A,Y),U(B,Y) ARE\nC SPECIFIED FOR ALL Y\nC\nC IN THE Y-DIRECTION:\nC (0) PERIODIC, U(X,Y+D-C)=U(X,Y) FOR ALL X,Y\nC (1) U(X,C),U(X,D) ARE SPECIFIED FOR ALL X\nC (2) U(X,C),DU(X,D)/DY ARE SPECIFIED FOR\nC ALL X\nC (3) DU(X,C)/DY,DU(X,D)/DY ARE SPECIFIED FOR\nC ALL X\nC (4) DU(X,C)/DY,U(X,D) ARE SPECIFIED FOR\nC ALL X\nC\nC USAGE CALL SEPX4(IORDER,A,B,M,MBDCND,BDA,ALPHA,BDB,\nC BETA,C,D,N,NBDCND,BDC,BDD,COFX,\nC GRHS,USOL,IDMN,W,PERTRB,IERROR)\nC\nC ARGUMENTS\nC ON INPUT IORDER\nC = 2 IF A SECOND-ORDER APPROXIMATION IS\nC SOUGHT\nC = 4 IF A FOURTH-ORDER APPROXIMATION IS\nC SOUGHT\nC\nC A,B\nC THE RANGE OF THE X-INDEPENDENT VARIABLE,\nC I.E., X IS GREATER THAN OR EQUAL TO A\nC AND LESS THAN OR EQUAL TO B. A MUST BE\nC LESS THAN B.\nC\nC M\nC THE NUMBER OF PANELS INTO WHICH THE\nC INTERVAL (A,B) IS SUBDIVIDED. HENCE,\nC THERE WILL BE M+1 GRID POINTS IN THE X-\nC DIRECTION GIVEN BY XI=A+(I-1)*DLX\nC FOR I=1,2,...,M+1 WHERE DLX=(B-A)/M IS\nC THE PANEL WIDTH. M MUST BE LESS THAN\nC IDMN AND GREATER THAN 5.\nC\nC MBDCND\nC INDICATES THE TYPE OF BOUNDARY CONDITION\nC AT X=A AND X=B\nC = 0 IF THE SOLUTION IS PERIODIC IN X, I.E.,\nC U(X+B-A,Y)=U(X,Y) FOR ALL Y,X\nC = 1 IF THE SOLUTION IS SPECIFIED AT X=A\nC AND X=B, I.E., U(A,Y) AND U(B,Y) ARE\nC SPECIFIED FOR ALL Y\nC = 2 IF THE SOLUTION IS SPECIFIED AT X=A\nC AND THE BOUNDARY CONDITION IS MIXED AT\nC X=B, I.E., U(A,Y) AND\nC DU(B,Y)/DX+BETA*U(B,Y) ARE SPECIFIED\nC FOR ALL Y\nC = 3 IF THE BOUNDARY CONDITIONS AT X=A AND\nC X=B ARE MIXED, I.E.,\nC DU(A,Y)/DX+ALPHA*U(A,Y) AND\nC DU(B,Y)/DX+BETA*U(B,Y) ARE SPECIFIED\nC FOR ALL Y\nC = 4 IF THE BOUNDARY CONDITION AT X=A IS\nC MIXED AND THE SOLUTION IS SPECIFIED\nC AT X=B, I.E., DU(A,Y)/DX+ALPHA*U(A,Y)\nC AND U(B,Y) ARE SPECIFIED FOR ALL Y\nC\nC BDA\nC A ONE-DIMENSIONAL ARRAY OF LENGTH N+1 THAT\nC SPECIFIES THE VALUES OF\nC DU(A,Y)/DX+ ALPHA*U(A,Y) AT X=A, WHEN\nC MBDCND=3 OR 4.\nC BDA(J) = DU(A,YJ)/DX+ALPHA*U(A,YJ),\nC J=1,2,...,N+1\nC WHEN MBDCND HAS ANY OTHER VALUE, BDA IS\nC A DUMMY PARAMETER.\nC\nC ALPHA\nC THE SCALAR MULTIPLYING THE SOLUTION IN CASE\nC OF A MIXED BOUNDARY CONDITION AT X=A\nC (SEE ARGUMENT BDA). IF MBDCND IS NOT EQUAL\nC TO EITHER 3 OR 4, THEN ALPHA IS A DUMMY\nC PARAMETER.\nC\nC BDB\nC A ONE-DIMENSIONAL ARRAY OF LENGTH N+1 THAT\nC SPECIFIES THE VALUES OF\nC DU(B,Y)/DX+ BETA*U(B,Y) AT X=B.\nC WHEN MBDCND=2 OR 3\nC BDB(J) = DU(B,YJ)/DX+BETA*U(B,YJ),\nC J=1,2,...,N+1\nC WHEN MBDCND HAS ANY OTHER VALUE, BDB IS\nC A DUMMY PARAMETER.\nC\nC BETA\nC THE SCALAR MULTIPLYING THE SOLUTION IN\nC CASE OF A MIXED BOUNDARY CONDITION AT X=B\nC (SEE ARGUMENT BDB). IF MBDCND IS NOT EQUAL\nC TO 2 OR 3, THEN BETA IS A DUMMY PARAMETER.\nC\nC C,D\nC THE RANGE OF THE Y-INDEPENDENT VARIABLE,\nC I.E., Y IS GREATER THAN OR EQUAL TO C AND\nC LESS THAN OR EQUAL TO D. C MUST BE LESS\nC THAN D.\nC\nC N\nC THE NUMBER OF PANELS INTO WHICH THE\nC INTERVAL (C,D) IS SUBDIVIDED. HENCE,\nC THERE WILL BE N+1 GRID POINTS IN THE Y-\nC DIRECTION GIVEN BY YJ=C+(J-1)*DLY FOR\nC J=1,2,...,N+1 WHERE DLY=(D-C)/N IS THE\nC PANEL WIDTH. IN ADDITION, N MUST BE\nC GREATER THAN 4.\nC\nC NBDCND\nC INDICATES THE TYPES OF BOUNDARY CONDITIONS\nC AT Y=C AND Y=D\nC = 0 IF THE SOLUTION IS PERIODIC IN Y,\nC I.E., U(X,Y+D-C)=U(X,Y) FOR ALL X,Y\nC = 1 IF THE SOLUTION IS SPECIFIED AT Y=C\nC AND Y = D, I.E., U(X,C) AND U(X,D)\nC ARE SPECIFIED FOR ALL X\nC = 2 IF THE SOLUTION IS SPECIFIED AT Y=C\nC AND THE BOUNDARY CONDITION IS MIXED\nC AT Y=D, I.E., DU(X,C)/DY AND U(X,D)\nC ARE SPECIFIED FOR ALL X\nC = 3 IF THE BOUNDARY CONDITIONS ARE MIXED\nC AT Y=CAND Y=D I.E.,\nC DU(X,D)/DY AND DU(X,D)/DY ARE\nC SPECIFIED FOR ALL X\nC = 4 IF THE BOUNDARY CONDITION IS MIXED\nC AT Y=C AND THE SOLUTION IS SPECIFIED\nC AT Y=D, I.E. DU(X,C)/DY+GAMA*U(X,C)\nC AND U(X,D) ARE SPECIFIED FOR ALL X\nC\nC BDC\nC A ONE-DIMENSIONAL ARRAY OF LENGTH M+1 THAT\nC SPECIFIES THE VALUE DU(X,C)/DY AT Y=C.\nC\nC WHEN NBDCND=3 OR 4\nC BDC(I) = DU(XI,C)/DY I=1,2,...,M+1.\nC\nC WHEN NBDCND HAS ANY OTHER VALUE, BDC IS\nC A DUMMY PARAMETER.\nC\nC BDD\nC A ONE-DIMENSIONAL ARRAY OF LENGTH M+1 THAT\nC SPECIFIED THE VALUE OF DU(X,D)/DY AT Y=D.\nC\nC WHEN NBDCND=2 OR 3\nC BDD(I)=DU(XI,D)/DY I=1,2,...,M+1.\nC\nC WHEN NBDCND HAS ANY OTHER VALUE, BDD IS\nC A DUMMY PARAMETER.\nC\nC COFX\nC A USER-SUPPLIED SUBPROGRAM WITH PARAMETERS\nC X, AFUN, BFUN, CFUN WHICH RETURNS THE\nC VALUES OF THE X-DEPENDENT COEFFICIENTS\nC AF(X), BF(X), CF(X) IN THE ELLIPTIC\nC EQUATION AT X. IF BOUNDARY CONDITIONS IN\nC THE X DIRECTION ARE PERIODIC THEN THE\nC COEFFICIENTS MUST SATISFY AF(X)=C1,BF(X)=0,\nC CF(X)=C2 FOR ALL X. HERE C1.GT.0\nC AND C2 ARE CONSTANTS.\nC\nC NOTE THAT COFX MUST BE DECLARED EXTERNAL\nC IN THE CALLING ROUTINE.\nC\nC GRHS\nC A TWO-DIMENSIONAL ARRAY THAT SPECIFIES THE\nC VALUES OF THE RIGHT-HAND SIDE OF THE\nC ELLIPTIC EQUATION, I.E.,GRHS(I,J)=G(XI,YI),\nC FOR I=2,...,M, J=2,...,N. AT THE\nC BOUNDARIES, GRHS IS DEFINED BY\nC\nC MBDCND GRHS(1,J) GRHS(M+1,J)\nC ------ --------- -----------\nC 0 G(A,YJ) G(B,YJ)\nC 1 * *\nC 2 * G(B,YJ) J=1,2,...,N+1\nC 3 G(A,YJ) G(B,YJ)\nC 4 G(A,YJ) *\nC\nC NBDCND GRHS(I,1) GRHS(I,N+1)\nC ------ --------- -----------\nC 0 G(XI,C) G(XI,D)\nC 1 * *\nC 2 * G(XI,D) I=1,2,...,M+1\nC 3 G(XI,C) G(XI,D)\nC 4 G(XI,C) *\nC\nC WHERE * MEANS THESE QUANTITES ARE NOT USED.\nC GRHS SHOULD BE DIMENSIONED IDMN BY AT LEAST\nC N+1 IN THE CALLING ROUTINE.\nC\nC USOL\nC A TWO-DIMENSIONAL ARRAY THAT SPECIFIES THE\nC VALUES OF THE SOLUTION ALONG THE BOUNDARIES.\nC AT THE BOUNDARIES, USOL IS DEFINED BY\nC\nC MBDCND USOL(1,J) USOL(M+1,J)\nC ------ --------- -----------\nC 0 * *\nC 1 U(A,YJ) U(B,YJ)\nC 2 U(A,YJ) * J=1,2,...,N+1\nC 3 * *\nC 4 * U(B,YJ)\nC\nC NBDCND USOL(I,1) USOL(I,N+1)\nC ------ --------- -----------\nC 0 * *\nC 1 U(XI,C) U(XI,D)\nC 2 U(XI,C) * I=1,2,...,M+1\nC 3 * *\nC 4 * U(XI,D)\nC\nC WHERE * MEANS THE QUANTITES ARE NOT USED\nC IN THE SOLUTION.\nC\nC IF IORDER=2, THE USER MAY EQUIVALENCE GRHS\nC AND USOL TO SAVE SPACE. NOTE THAT IN THIS\nC CASE THE TABLES SPECIFYING THE BOUNDARIES\nC OF THE GRHS AND USOL ARRAYS DETERMINE THE\nC BOUNDARIES UNIQUELY EXCEPT AT THE CORNERS.\nC IF THE TABLES CALL FOR BOTH G(X,Y) AND\nC U(X,Y) AT A CORNER THEN THE SOLUTION MUST\nC BE CHOSEN.\nC FOR EXAMPLE, IF MBDCND=2 AND NBDCND=4,\nC THEN U(A,C), U(A,D),U(B,D) MUST BE CHOSEN\nC AT THE CORNERS IN ADDITION TO G(B,C).\nC\nC IF IORDER=4, THEN THE TWO ARRAYS, USOL AND\nC GRHS, MUST BE DISTINCT.\nC\nC USOL SHOULD BE DIMENSIONED IDMN BY AT LEAST\nC N+1 IN THE CALLING ROUTINE.\nC\nC IDMN\nC THE ROW (OR FIRST) DIMENSION OF THE ARRAYS\nC GRHS AND USOL AS IT APPEARS IN THE PROGRAM\nC CALLING SEPELI. THIS PARAMETER IS USED\nC TO SPECIFY THE VARIABLE DIMENSION OF GRHS\nC AND USOL. IDMN MUST BE AT LEAST 7 AND\nC GREATER THAN OR EQUAL TO M+1.\nC\nC W\nC A ONE-DIMENSIONAL ARRAY THAT MUST BE\nC PROVIDED BY THE USER FOR WORK SPACE.\nC 10*N+(16+INT(LOG2(N+1)))*(M+1)+11 WILL\nC SUFFICE AS A LENGTH FOR W. THE ACTUAL\nC LENGTH OF W IN THE CALLING ROUTINE\nC MUST BE SET IN W(1) (SEE IERROR=11).\nC\nC\nC ON OUTPUT USOL\nC CONTAINS THE APPROXIMATE SOLUTION TO THE\nC ELLIPTIC EQUATION. USOL(I,J) IS THE\nC APPROXIMATION TO U(XI,YJ) FOR I=1,2...,M+1\nC AND J=1,2,...,N+1. THE APPROXIMATION HAS\nC ERROR O(DLX**2+DLY**2) IF CALLED WITH\nC IORDER=2 AND O(DLX**4+DLY**4) IF CALLED\nC WITH IORDER=4.\nC\nC W\nC CONTAINS INTERMEDIATE VALUES THAT MUST NOT\nC BE DESTROYED IF SEPELI IS CALLED AGAIN\nC WITH INTL=1. IN ADDITION W(1) CONTAINS\nC THE EXACT MINIMAL LENGTH (IN FLOATING POINT)\nC REQUIRED FOR THE WORK SPACE (SEE IERROR=11).\nC\nC PERTRB\nC IF A COMBINATION OF PERIODIC OR DERIVATIVE\nC BOUNDARY CONDITIONS (I.E., ALPHA=BETA=0 IF\nC MBDCND=3) IS SPECIFIED AND IF CF(X)=0 FOR\nC ALL X THEN A SOLUTION TO THE DISCRETIZED\nC MATRIX EQUATION MAY NOT EXIST\nC (REFLECTING THE NON-UNIQUENESS OF SOLUTIONS\nC TO THE PDE).\nC PERTRB IS A CONSTANT CALCULATED AND\nC SUBTRACTED FROM THE RIGHT HAND SIDE OF THE\nC MATRIX EQUATION INSURING THE EXISTENCE OF A\nC SOLUTION. SEPX4 COMPUTES THIS SOLUTION\nC WHICH IS A WEIGHTED MINIMAL LEAST SQUARES\nC SOLUTION TO THE ORIGINAL PROBLEM. IF\nC SINGULARITY IS NOT DETECTED PERTRB=0.0 IS\nC RETURNED BY SEPX4.\nC\nC IERROR\nC AN ERROR FLAG THAT INDICATES INVALID INPUT\nC PARAMETERS OR FAILURE TO FIND A SOLUTION\nC\nC = 0 NO ERROR\nC = 1 IF A GREATER THAN B OR C GREATER\nC THAN D\nC = 2 IF MBDCND LESS THAN 0 OR MBDCND\nC GREATER THAN 4\nC = 3 IF NBDCND LESS THAN 0 OR NBDCND\nC GREATER THAN 4\nC = 4 IF ATTEMPT TO FIND A SOLUTION FAILS.\nC (THE LINEAR SYSTEM GENERATED IS NOT\nC DIAGONALLY DOMINANT.)\nC = 5 IF IDMN IS TOO SMALL (SEE DISCUSSION\nC OF IDMN)\nC = 6 IF M IS TOO SMALL OR TOO LARGE\nC (SEE DISCUSSION OF M)\nC = 7 IF N IS TOO SMALL (SEE DISCUSSION OF N)\nC = 8 IF IORDER IS NOT 2 OR 4\nC = 9 IF INTL IS NOT 0 OR 1\nC = 10 IF AFUN IS LESS THAN OR EQUAL TO ZERO\nC FOR SOME INTERIOR MESH POINT XI SOME\nC INTERIOR MESH POINT (XI,YJ)\nC = 11 IF THE WORK SPACE LENGTH INPUT IN W(1)\nC IS LESS THAN THE EXACT MINIMAL WORK\nC SPACE LENGTH REQUIRED OUTPUT IN W(1).\nC = 12 IF MBDCND=0 AND AF(X)=CF(X)=CONSTANT\nC OR BF(X)=0 FOR ALL X IS NOT TRUE.\nC\nC SPECIAL CONDITIONS NONE\nC\nC I/O NONE\nC\nC REQUIRED LIBRARY COMF, GENBUN, GNBNAUX, AND SEPAUX\nC FILES FROM FISHPACK\nC\nC\nC PRECISION SINGLE\nC\nC REQUIRED LIBRARY NONE\nC FILES\nC\nC LANGUAGE FORTRAN\nC\nC HISTORY SEPX4 WAS DEVELOPED AT NCAR BY JOHN C.\nC ADAMS OF THE SCIENTIFIC COMPUTING DIVISION\nC IN OCTOBER 1978. THE BASIS OF THIS CODE IS\nC NCAR ROUTINE SEPELI. BOTH PACKAGES WERE\nC RELEASED ON NCAR'S PUBLIC LIBRARIES IN\nC JANUARY 1980.\nC\nC PORTABILITY FORTRAN 77\nC\nC ALGORITHM SEPX4 AUTOMATICALLY DISCRETIZES THE SEPARABLE\nC ELLIPTIC EQUATION WHICH IS THEN SOLVED BY A\nC GENERALIZED CYCLIC REDUCTION ALGORITHM IN THE\nC SUBROUTINE POIS. THE FOURTH ORDER SOLUTION\nC IS OBTAINED USING THE TECHNIQUE OF DEFFERRED\nC CORRECTIONS REFERENCED BELOW.\nC\nC TIMING WHEN POSSIBLE, SEPX4 SHOULD BE USED INSTEAD\nC OF PACKAGE SEPELI. THE INCREASE IN SPEED\nC IS AT LEAST A FACTOR OF THREE.\nC\nC REFERENCES KELLER, H.B., NUMERICAL METHODS FOR TWO-POINT\nC BOUNDARY-VALUE PROBLEMS, BLAISDEL (1968),\nC WALTHAM, MASS.\nC\nC SWARZTRAUBER, P., AND R. SWEET (1975):\nC EFFICIENT FORTRAN SUBPROGRAMS FOR THE\nC SOLUTION OF ELLIPTIC PARTIAL DIFFERENTIAL\nC EQUATIONS. NCAR TECHNICAL NOTE\nC NCAR-TN/IA-109, PP. 135-137.\nC***********************************************************************\n DIMENSION GRHS(IDMN,1) ,USOL(IDMN,1)\n DIMENSION BDA(*) ,BDB(*) ,BDC(*) ,BDD(*) ,\n 1 W(*)\nC\nC CHECK INPUT PARAMETERS\nC\n CALL C4KPRM(IORDER,A,B,M,MBDCND,C,D,N,NBDCND,COFX,IDMN,IERROR)\n IF (IERROR .NE. 0) RETURN\nC\nC COMPUTE MINIMUM WORK SPACE AND CHECK WORK SPACE LENGTH INPUT\nC\n L = N+1\n IF (NBDCND .EQ. 0) L = N\n K = M+1\n L = N+1\nC ESTIMATE LOG BASE 2 OF N\n LOG2N=INT(ALOG(FLOAT(N+1))/ALOG(2.0)+0.5)\n LENGTH=4*(N+1)+(10+LOG2N)*(M+1)\n IERROR = 11\n LINPUT = INT(W(1)+0.5)\n LOUTPT = LENGTH+6*(K+L)+1\n W(1) = FLOAT(LOUTPT)\n IF (LOUTPT .GT. LINPUT) RETURN\n IERROR = 0\nC\nC SET WORK SPACE INDICES\nC\n I1 = LENGTH+2\n I2 = I1+L\n I3 = I2+L\n I4 = I3+L\n I5 = I4+L\n I6 = I5+L\n I7 = I6+L\n I8 = I7+K\n I9 = I8+K\n I10 = I9+K\n I11 = I10+K\n I12 = I11+K\n I13 = 2\n CALL S4ELIP(IORDER,A,B,M,MBDCND,BDA,ALPHA,BDB,BETA,C,D,N,\n 1 NBDCND,BDC,BDD,COFX,W(I1),W(I2),W(I3),\n 2 W(I4),W(I5),W(I6),W(I7),W(I8),W(I9),W(I10),W(I11),\n 3 W(I12),GRHS,USOL,IDMN,W(I13),PERTRB,IERROR)\n RETURN\n END\n SUBROUTINE S4ELIP(IORDER,A,B,M,MBDCND,BDA,ALPHA,BDB,BETA,C,D,N,\n 1 NBDCND,BDC,BDD,COFX,AN,BN,CN,DN,UN,ZN,AM,BM,\n 2 CM,DM,UM,ZM,GRHS,USOL,IDMN,W,PERTRB,IERROR)\nC\nC S4ELIP SETS UP VECTORS AND ARRAYS FOR INPUT TO BLKTRI\nC AND COMPUTES A SECOND ORDER SOLUTION IN USOL. A RETURN JUMP TO\nC SEPELI OCCURRS IF IORDER=2. IF IORDER=4 A FOURTH ORDER\nC SOLUTION IS GENERATED IN USOL.\nC\n DIMENSION BDA(*) ,BDB(*) ,BDC(*) ,BDD(*) ,\n 1 W(*)\n DIMENSION GRHS(IDMN,1) ,USOL(IDMN,1)\n DIMENSION AN(*) ,BN(*) ,CN(*) ,DN(*) ,\n 1 UN(*) ,ZN(*)\n DIMENSION AM(*) ,BM(*) ,CM(*) ,DM(*) ,\n 1 UM(*) ,ZM(*)\n COMMON /SPLP/ KSWX ,KSWY ,K ,L ,\n 1 AIT ,BIT ,CIT ,DIT ,\n 2 MIT ,NIT ,IS ,MS ,\n 3 JS ,NS ,DLX ,DLY ,\n 4 TDLX3 ,TDLY3 ,DLX4 ,DLY4\n LOGICAL SINGLR\n EXTERNAL COFX\nC\nC SET PARAMETERS INTERNALLY\nC\n KSWX = MBDCND+1\n KSWY = NBDCND+1\n K = M+1\n L = N+1\n AIT = A\n BIT = B\n CIT = C\n DIT = D\n DLY=(DIT-CIT)/FLOAT(N)\nC\nC SET RIGHT HAND SIDE VALUES FROM GRHS IN USOL ON THE INTERIOR\nC AND NON-SPECIFIED BOUNDARIES.\nC\n DO 20 I=2,M\n DO 10 J=2,N\n USOL(I,J)=DLY**2*GRHS(I,J)\n 10 CONTINUE\n 20 CONTINUE\n IF (KSWX.EQ.2 .OR. KSWX.EQ.3) GO TO 40\n DO 30 J=2,N\n USOL(1,J)=DLY**2*GRHS(1,J)\n 30 CONTINUE\n 40 CONTINUE\n IF (KSWX.EQ.2 .OR. KSWX.EQ.5) GO TO 60\n DO 50 J=2,N\n USOL(K,J)=DLY**2*GRHS(K,J)\n 50 CONTINUE\n 60 CONTINUE\n IF (KSWY.EQ.2 .OR. KSWY.EQ.3) GO TO 80\n DO 70 I=2,M\n USOL(I,1)=DLY**2*GRHS(I,1)\n 70 CONTINUE\n 80 CONTINUE\n IF (KSWY.EQ.2 .OR. KSWY.EQ.5) GO TO 100\n DO 90 I=2,M\n USOL(I,L)=DLY**2*GRHS(I,L)\n 90 CONTINUE\n 100 CONTINUE\n IF (KSWX.NE.2 .AND. KSWX.NE.3 .AND. KSWY.NE.2 .AND. KSWY.NE.3)\n 1USOL(1,1)=DLY**2*GRHS(1,1)\n IF (KSWX.NE.2 .AND. KSWX.NE.5 .AND. KSWY.NE.2 .AND. KSWY.NE.3)\n 1USOL(K,1)=DLY**2*GRHS(K,1)\n IF (KSWX.NE.2 .AND. KSWX.NE.3 .AND. KSWY.NE.2 .AND. KSWY.NE.5)\n 1USOL(1,L)=DLY**2*GRHS(1,L)\n IF (KSWX.NE.2 .AND. KSWX.NE.5 .AND. KSWY.NE.2 .AND. KSWY.NE.5)\n 1USOL(K,L)=DLY**2*GRHS(K,L)\n I1 = 1\nC\nC SET SWITCHES FOR PERIODIC OR NON-PERIODIC BOUNDARIES\nC\n MP=1\n IF(KSWX.EQ.1) MP=0\n NP=NBDCND\nC\nC SET DLX,DLY AND SIZE OF BLOCK TRI-DIAGONAL SYSTEM GENERATED\nC IN NINT,MINT\nC\n DLX = (BIT-AIT)/FLOAT(M)\n MIT = K-1\n IF (KSWX .EQ. 2) MIT = K-2\n IF (KSWX .EQ. 4) MIT = K\n DLY = (DIT-CIT)/FLOAT(N)\n NIT = L-1\n IF (KSWY .EQ. 2) NIT = L-2\n IF (KSWY .EQ. 4) NIT = L\n TDLX3 = 2.0*DLX**3\n DLX4 = DLX**4\n TDLY3 = 2.0*DLY**3\n DLY4 = DLY**4\nC\nC SET SUBSCRIPT LIMITS FOR PORTION OF ARRAY TO INPUT TO BLKTRI\nC\n IS = 1\n JS = 1\n IF (KSWX.EQ.2 .OR. KSWX.EQ.3) IS = 2\n IF (KSWY.EQ.2 .OR. KSWY.EQ.3) JS = 2\n NS = NIT+JS-1\n MS = MIT+IS-1\nC\nC SET X - DIRECTION\nC\n DO 110 I=1,MIT\n XI = AIT+FLOAT(IS+I-2)*DLX\n CALL COFX (XI,AI,BI,CI)\n AXI = (AI/DLX-0.5*BI)/DLX\n BXI = -2.*AI/DLX**2+CI\n CXI = (AI/DLX+0.5*BI)/DLX\n AM(I)=DLY**2*AXI\n BM(I)=DLY**2*BXI\n CM(I)=DLY**2*CXI\n 110 CONTINUE\nC\nC SET Y DIRECTION\nC\n DYJ=1.0\n EYJ=-2.0\n FYJ=1.0\n DO 120 J=1,NIT\n AN(J) = DYJ\n BN(J) = EYJ\n CN(J) = FYJ\n 120 CONTINUE\nC\nC ADJUST EDGES IN X DIRECTION UNLESS PERIODIC\nC\n AX1 = AM(1)\n CXM = CM(MIT)\n GO TO (170,130,150,160,140),KSWX\nC\nC DIRICHLET-DIRICHLET IN X DIRECTION\nC\n 130 AM(1) = 0.0\n CM(MIT) = 0.0\n GO TO 170\nC\nC MIXED-DIRICHLET IN X DIRECTION\nC\n 140 AM(1) = 0.0\n BM(1) = BM(1)+2.*ALPHA*DLX*AX1\n CM(1) = CM(1)+AX1\n CM(MIT) = 0.0\n GO TO 170\nC\nC DIRICHLET-MIXED IN X DIRECTION\nC\n 150 AM(1) = 0.0\n AM(MIT) = AM(MIT)+CXM\n BM(MIT) = BM(MIT)-2.*BETA*DLX*CXM\n CM(MIT) = 0.0\n GO TO 170\nC\nC MIXED - MIXED IN X DIRECTION\nC\n 160 CONTINUE\n AM(1) = 0.0\n BM(1) = BM(1)+2.*DLX*ALPHA*AX1\n CM(1) = CM(1)+AX1\n AM(MIT) = AM(MIT)+CXM\n BM(MIT) = BM(MIT)-2.*DLX*BETA*CXM\n CM(MIT) = 0.0\n 170 CONTINUE\nC\nC ADJUST IN Y DIRECTION UNLESS PERIODIC\nC\n DY1 = AN(1)\n FYN = CN(NIT)\n GAMA=0.0\n XNU=0.0\n GO TO (220,180,200,210,190),KSWY\nC\nC DIRICHLET-DIRICHLET IN Y DIRECTION\nC\n 180 CONTINUE\n AN(1) = 0.0\n CN(NIT) = 0.0\n GO TO 220\nC\nC MIXED-DIRICHLET IN Y DIRECTION\nC\n 190 CONTINUE\n AN(1) = 0.0\n BN(1) = BN(1)+2.*DLY*GAMA*DY1\n CN(1) = CN(1)+DY1\n CN(NIT) = 0.0\n GO TO 220\nC\nC DIRICHLET-MIXED IN Y DIRECTION\nC\n 200 AN(1) = 0.0\n AN(NIT) = AN(NIT)+FYN\n BN(NIT) = BN(NIT)-2.*DLY*XNU*FYN\n CN(NIT) = 0.0\n GO TO 220\nC\nC MIXED - MIXED DIRECTION IN Y DIRECTION\nC\n 210 CONTINUE\n AN(1) = 0.0\n BN(1) = BN(1)+2.*DLY*GAMA*DY1\n CN(1) = CN(1)+DY1\n AN(NIT) = AN(NIT)+FYN\n BN(NIT) = BN(NIT)-2.0*DLY*XNU*FYN\n CN(NIT) = 0.0\n 220 IF (KSWX .EQ. 1) GO TO 270\nC\nC ADJUST USOL ALONG X EDGE\nC\n DO 260 J=JS,NS\n IF (KSWX.NE.2 .AND. KSWX.NE.3) GO TO 230\n USOL(IS,J) = USOL(IS,J)-AX1*USOL(1,J)\n GO TO 240\n 230 USOL(IS,J) = USOL(IS,J)+2.0*DLX*AX1*BDA(J)\n 240 IF (KSWX.NE.2 .AND. KSWX.NE.5) GO TO 250\n USOL(MS,J) = USOL(MS,J)-CXM*USOL(K,J)\n GO TO 260\n 250 USOL(MS,J) = USOL(MS,J)-2.0*DLX*CXM*BDB(J)\n 260 CONTINUE\n 270 IF (KSWY .EQ. 1) GO TO 320\nC\nC ADJUST USOL ALONG Y EDGE\nC\n DO 310 I=IS,MS\n IF (KSWY.NE.2 .AND. KSWY.NE.3) GO TO 280\n USOL(I,JS) = USOL(I,JS)-DY1*USOL(I,1)\n GO TO 290\n 280 USOL(I,JS) = USOL(I,JS)+2.0*DLY*DY1*BDC(I)\n 290 IF (KSWY.NE.2 .AND. KSWY.NE.5) GO TO 300\n USOL(I,NS) = USOL(I,NS)-FYN*USOL(I,L)\n GO TO 310\n 300 USOL(I,NS) = USOL(I,NS)-2.0*DLY*FYN*BDD(I)\n 310 CONTINUE\n 320 CONTINUE\nC\nC SAVE ADJUSTED EDGES IN GRHS IF IORDER=4\nC\n IF (IORDER .NE. 4) GO TO 350\n DO 330 J=JS,NS\n GRHS(IS,J) = USOL(IS,J)\n GRHS(MS,J) = USOL(MS,J)\n 330 CONTINUE\n DO 340 I=IS,MS\n GRHS(I,JS) = USOL(I,JS)\n GRHS(I,NS) = USOL(I,NS)\n 340 CONTINUE\n 350 CONTINUE\n IORD = IORDER\n PERTRB = 0.0\nC\nC CHECK IF OPERATOR IS SINGULAR\nC\n CALL C4KSNG(MBDCND,NBDCND,ALPHA,BETA,COFX,SINGLR)\nC\nC COMPUTE NON-ZERO EIGENVECTOR IN NULL SPACE OF TRANSPOSE\nC IF SINGULAR\nC\n IF (SINGLR) CALL SEPTRI (MIT,AM,BM,CM,DM,UM,ZM)\n IF (SINGLR) CALL SEPTRI (NIT,AN,BN,CN,DN,UN,ZN)\nC\nC ADJUST RIGHT HAND SIDE IF NECESSARY\nC\n 360 CONTINUE\n IF (SINGLR) CALL SEPORT (USOL,IDMN,ZN,ZM,PERTRB)\nC\nC COMPUTE SOLUTION\nC\nC SAVE ADJUSTED RIGHT HAND SIDE IN GRHS\n DO 444 J=JS,NS\n DO 444 I=IS,MS\n GRHS(I,J)=USOL(I,J)\n 444 CONTINUE\n CALL GENBUN(NP,NIT,MP,MIT,AM,BM,CM,IDMN,USOL(IS,JS),IEROR,W)\nC CHECK IF ERROR DETECTED IN POIS\nC THIS CAN ONLY CORRESPOND TO IERROR=12\n IF(IEROR.EQ.0) GO TO 224\nC SET ERROR FLAG IF IMPROPER COEFFICIENTS INPUT TO POIS\n IERROR=12\n RETURN\n 224 CONTINUE\n IF (IERROR .NE. 0) RETURN\nC\nC SET PERIODIC BOUNDARIES IF NECESSARY\nC\n IF (KSWX .NE. 1) GO TO 380\n DO 370 J=1,L\n USOL(K,J) = USOL(1,J)\n 370 CONTINUE\n 380 IF (KSWY .NE. 1) GO TO 400\n DO 390 I=1,K\n USOL(I,L) = USOL(I,1)\n 390 CONTINUE\n 400 CONTINUE\nC\nC MINIMIZE SOLUTION WITH RESPECT TO WEIGHTED LEAST SQUARES\nC NORM IF OPERATOR IS SINGULAR\nC\n IF (SINGLR) CALL SEPMIN (USOL,IDMN,ZN,ZM,PRTRB)\nC\nC RETURN IF DEFERRED CORRECTIONS AND A FOURTH ORDER SOLUTION ARE\nC NOT FLAGGED\nC\n IF (IORD .EQ. 2) RETURN\n IORD = 2\nC\nC COMPUTE NEW RIGHT HAND SIDE FOR FOURTH ORDER SOLUTION\nC\n CALL D4FER(COFX,IDMN,USOL,GRHS)\n GO TO 360\n END\n SUBROUTINE C4KPRM(IORDER,A,B,M,MBDCND,C,D,N,NBDCND,COFX,IDMN,IERR\n 1OR)\nC\nC THIS PROGRAM CHECKS THE INPUT PARAMETERS FOR ERRORS\nC\nC\nC\nC CHECK DEFINITION OF SOLUTION REGION\nC\n IERROR = 1\n IF (A.GE.B .OR. C.GE.D) RETURN\nC\nC CHECK BOUNDARY SWITCHES\nC\n IERROR = 2\n IF (MBDCND.LT.0 .OR. MBDCND.GT.4) RETURN\n IERROR = 3\n IF (NBDCND.LT.0 .OR. NBDCND.GT.4) RETURN\nC\nC CHECK FIRST DIMENSION IN CALLING ROUTINE\nC\n IERROR = 5\n IF (IDMN .LT. 7) RETURN\nC\nC CHECK M\nC\n IERROR = 6\n IF (M.GT.(IDMN-1) .OR. M.LT.6) RETURN\nC\nC CHECK N\nC\n IERROR = 7\n IF (N .LT. 5) RETURN\nC\nC CHECK IORDER\nC\n IERROR = 8\n IF (IORDER.NE.2 .AND. IORDER.NE.4) RETURN\nC\nC CHECK INTL\nC\nC\nC CHECK THAT EQUATION IS ELLIPTIC\nC\n DLX = (B-A)/FLOAT(M)\n DO 30 I=2,M\n XI = A+FLOAT(I-1)*DLX\n CALL COFX (XI,AI,BI,CI)\n IF (AI.GT.0.0) GO TO 10\n IERROR=10\n RETURN\n 10 CONTINUE\n 30 CONTINUE\nC\nC NO ERROR FOUND\nC\n IERROR = 0\n RETURN\n END\n SUBROUTINE C4KSNG(MBDCND,NBDCND,ALPHA,BETA,COFX,SINGLR)\nC\nC THIS SUBROUTINE CHECKS IF THE PDE SEPELI\nC MUST SOLVE IS A SINGULAR OPERATOR\nC\n COMMON /SPLP/ KSWX ,KSWY ,K ,L ,\n 1 AIT ,BIT ,CIT ,DIT ,\n 2 MIT ,NIT ,IS ,MS ,\n 3 JS ,NS ,DLX ,DLY ,\n 4 TDLX3 ,TDLY3 ,DLX4 ,DLY4\n LOGICAL SINGLR\n SINGLR = .FALSE.\nC\nC CHECK IF THE BOUNDARY CONDITIONS ARE\nC ENTIRELY PERIODIC AND/OR MIXED\nC\n IF ((MBDCND.NE.0 .AND. MBDCND.NE.3) .OR.\n 1 (NBDCND.NE.0 .AND. NBDCND.NE.3)) RETURN\nC\nC CHECK THAT MIXED CONDITIONS ARE PURE NEUMAN\nC\n IF (MBDCND .NE. 3) GO TO 10\n IF (ALPHA.NE.0.0 .OR. BETA.NE.0.0) RETURN\n 10 CONTINUE\nC\nC CHECK THAT NON-DERIVATIVE COEFFICIENT FUNCTIONS\nC ARE ZERO\nC\n DO 30 I=IS,MS\n XI = AIT+FLOAT(I-1)*DLX\n CALL COFX (XI,AI,BI,CI)\n IF (CI .NE. 0.0) RETURN\n 30 CONTINUE\nC\nC THE OPERATOR MUST BE SINGULAR IF THIS POINT IS REACHED\nC\n SINGLR = .TRUE.\n RETURN\n END\n SUBROUTINE D4FER(COFX,IDMN,USOL,GRHS)\nC\nC THIS SUBROUTINE FIRST APPROXIMATES THE TRUNCATION ERROR GIVEN BY\nC TRUN1(X,Y)=DLX**2*TX+DLY**2*TY WHERE\nC TX=AFUN(X)*UXXXX/12.0+BFUN(X)*UXXX/6.0 ON THE INTERIOR AND\nC AT THE BOUNDARIES IF PERIODIC(HERE UXXX,UXXXX ARE THE THIRD\nC AND FOURTH PARTIAL DERIVATIVES OF U WITH RESPECT TO X).\nC TX IS OF THE FORM AFUN(X)/3.0*(UXXXX/4.0+UXXX/DLX)\nC AT X=A OR X=B IF THE BOUNDARY CONDITION THERE IS MIXED.\nC TX=0.0 ALONG SPECIFIED BOUNDARIES. TY HAS SYMMETRIC FORM\nC IN Y WITH X,AFUN(X),BFUN(X) REPLACED BY Y,DFUN(Y),EFUN(Y).\nC THE SECOND ORDER SOLUTION IN USOL IS USED TO APPROXIMATE\nC (VIA SECOND ORDER FINITE DIFFERENCING) THE TRUNCATION ERROR\nC AND THE RESULT IS ADDED TO THE RIGHT HAND SIDE IN GRHS\nC AND THEN TRANSFERRED TO USOL TO BE USED AS A NEW RIGHT\nC HAND SIDE WHEN CALLING BLKTRI FOR A FOURTH ORDER SOLUTION.\nC\n COMMON /SPLP/ KSWX ,KSWY ,K ,L ,\n 1 AIT ,BIT ,CIT ,DIT ,\n 2 MIT ,NIT ,IS ,MS ,\n 3 JS ,NS ,DLX ,DLY ,\n 4 TDLX3 ,TDLY3 ,DLX4 ,DLY4\n DIMENSION GRHS(IDMN,1) ,USOL(IDMN,1)\nC\nC\nC COMPUTE TRUNCATION ERROR APPROXIMATION OVER THE ENTIRE MESH\nC\n DO 30 I=IS,MS\n XI = AIT+FLOAT(I-1)*DLX\n CALL COFX (XI,AI,BI,CI)\n DO 30 J=JS,NS\nC\nC COMPUTE PARTIAL DERIVATIVE APPROXIMATIONS AT (XI,YJ)\nC\n CALL SEPDX (USOL,IDMN,I,J,UXXX,UXXXX)\n CALL SEPDY (USOL,IDMN,I,J,UYYY,UYYYY)\n TX = AI*UXXXX/12.0+BI*UXXX/6.0\n TY=UYYYY/12.0\nC\nC RESET FORM OF TRUNCATION IF AT BOUNDARY WHICH IS NON-PERIODIC\nC\n IF (KSWX.EQ.1 .OR. (I.GT.1 .AND. I.LT.K)) GO TO 10\n TX = AI/3.0*(UXXXX/4.0+UXXX/DLX)\n 10 IF (KSWY.EQ.1 .OR. (J.GT.1 .AND. J.LT.L)) GO TO 20\n TY = (UYYYY/4.0+UYYY/DLY)/3.0\n 20 GRHS(I,J)=GRHS(I,J)+DLY**2*(DLX**2*TX+DLY**2*TY)\n 30 CONTINUE\nC\nC RESET THE RIGHT HAND SIDE IN USOL\nC\n DO 60 I=IS,MS\n DO 50 J=JS,NS\n USOL(I,J) = GRHS(I,J)\n 50 CONTINUE\n 60 CONTINUE\n RETURN\nC\nC REVISION HISTORY---\nC\nC SEPTEMBER 1973 VERSION 1\nC APRIL 1976 VERSION 2\nC JANUARY 1978 VERSION 3\nC DECEMBER 1979 VERSION 3.1\nC FEBRUARY 1985 DOCUMENTATION UPGRADE\nC NOVEMBER 1988 VERSION 3.2, FORTRAN 77 CHANGES\nC-----------------------------------------------------------------------\n END\n", "meta": {"hexsha": "be49faeed726565cf2468deddc290d566b48ce3d", "size": 36250, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/src/sepx4.f", "max_stars_repo_name": "ipelupessy/omuse", "max_stars_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2020-03-25T10:02:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-18T00:28:35.000Z", "max_issues_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/src/sepx4.f", "max_issues_repo_name": "ipelupessy/omuse", "max_issues_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 45, "max_issues_repo_issues_event_min_datetime": "2020-03-03T16:07:16.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-14T09:01:07.000Z", "max_forks_repo_path": "src/omuse/community/qgmodel/src/fishpack4.1/src/sepx4.f", "max_forks_repo_name": "ipelupessy/omuse", "max_forks_repo_head_hexsha": "83850925beb4b8ba6050c7fa8a1ef2371baf6fbb", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2020-03-03T13:28:50.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-26T09:20:02.000Z", "avg_line_length": 37.7997914494, "max_line_length": 72, "alphanum_fraction": 0.4364413793, "num_tokens": 11127, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096204605946, "lm_q2_score": 0.7122321903471565, "lm_q1q2_score": 0.6524827615787515}} {"text": " program GF_sde_asub ! Calculation of the half-space\n ! electromagnetic Green's tensor\n ! by the short-dsitance expansion\n ! for the case of a metal substrate.\n !\n ! ONLY the reflected part, GR, is computed\nc------------------------------------------------------------------\nc Authors:\nc George Y. Panasyuk, Vadim A. Markel, John C. Schotland\nc University of Pennsylvania\nc E-mail address for questions and comments:\nc vmarkel@mail.med.upenn.edu\nc For updates and additional info check\nc URL: http://whale.seas.upenn.edu/CODES/\nc------------------------------------------------------------------\n implicit none\n\n integer*4 idummy, kl, nl, key, nord\n logical*4 logscale\n character*4 hdummy, output_prec, lambda_scale\n\n real*8 rdummy\n real*8 t, gd, ru, rz, two, three, twopi\n real*8 z1, z2, z_p, eps0, dlambda, rlambda, power\n real*8 lambda_p, lambda, lambda_min, lambda_max, k1, rho\n real*8 zh_p, zh_p_2, eps_1, eps_2_r, eps_2_i\n real*8 L, Lhat, Lhat_2, Lhat_3, Zhat, Rhat, RZLhat, LZRhat\n\n complex*16 cu, cz\n complex*16 eps, eps_m, eps_p, eps_s, eps_c\n complex*16 c1, c2, c3, c4, c5, c6, c7, Lam\n complex*16 eps_2, s\n complex*16 GRxx(0:3), GRyy(0:3), GRzz(0:3), GRxz(0:3)\n\n complex*16 Kxx0, Kyy0, Kzz0, Kxz0\n complex*16 Kxx2, Kyy2, Kzz2, Kxz2\n complex*16 Kxx3, Kyy3, Kzz3, Kxz3\n\n complex*16 GRxx0, GRyy0, GRzz0, GRxz0\n complex*16 GRxx2, GRyy2, GRzz2, GRxz2\n complex*16 GRxx3, GRyy3, GRzz3, GRxz3\nc\nc------ Mathematical constants ------------------------------------\nc\n rz = 0.0d0\n ru = 1.0d0\n cu = (0.0d0, 1.0d0)\n cz = (0.0d0, 0.0d0)\n\n two = 2.0d0\n three = 3.0d0\n twopi = 4.0d0*dasin(ru)\nc\nc---------- Reading input parameters -----------------------------------\nc\n open(unit=70, file='GF.par', status='old', err=101)\n read(70,*) hdummy\n read(70,*) hdummy\n\n read(70,*, err=101) key\n if(key .eq. 0) then\n write(*,*) 'Assuming a metallic substrate;'\n write(*,*) 'Drude formula will be used for eps_2'\n else if (key .eq. 1) then\n write(*,*) 'Assuming that the substrate has a'\n write(*,*) ' ... wavelength-independent permittivity'\n write(*,*) ' ... eps_2 = eps_2_r + i*eps_2_i'\n write(*,*) ' ... where eps_2_r, eps_2_i are given in GF.par'\n write(*,*) 'If you dont like this, use KEY=2'\n write(*,*) ' ... and program your own formula for eps_2'\n else if (key .eq. 2) then\n write(*,*) 'KEY=2 is used for user-defined permittivity'\n write(*,*) 'This option requires additional programming'\n write(*,*) 'But this has not been done so far'\n write(*,*) 'Go to the line \"if(key .eq. 2)\" below'\n write(*,*) ' ...and add your code directly after that line'\n write(*,*) 'Then comment this message out'\n write(*,*) 'For now, I am exiting. Goodby'\n stop\n else \n write(*,*) 'Error. Incorrect parameter: KEY=', key\n write(*,*) 'key is allowed to take only the values 0,1,2'\n write(*,*) 'Correct the error in GF.par and try again'\n stop\n end if\n\n read(70,*,err=101) nord\n if(nord .lt. 0) then\n write(*,*) 'Warning. You have requested NORD<0.'\n write(*,*) 'This option is used only in GF_k2g'\n write(*,*) 'For GF_sde_asub, the sign of NORD does not matter'\n write(*,*) 'I will set NORD=|NORD| and continue.'\n nord = -nord\n write(*,*) 'NORD=', nord\n write(*,*) '--------------------------------------------'\n end if\n if (nord .eq. 1) then\n write(*,*) 'The first order correction is identicallyz zero'\n write(*,*) ' (see paper)'\n write(*,*) 'Therefore, there is no difference between NORD=0'\n write(*,*) ' and NORD=1'\n write(*,*) 'I will set NORD=0 and continue'\n write(*,*) 'The result is not affected. Goodby.'\n nord = 0\n else if(nord .gt. 3) then \n write(*,*) 'Warning. You have requested NORD>3'\n write(*,*) 'GF_sde_asub only allows NORD<=3'\n write(*,*) 'Note that GF_sde_tsub will allow |NORD|<=7'\n write(*,*) 'I will now set NORD=3 and continue'\n write(*,*) 'If this is not OK, either use GF_sde_tsub'\n write(*,*) ' ... or edit GF.par and try again'\n write(*,*) 'Continue with NORD=3?'\n pause\n nord = 3\n write(*,*) 'NORD=', nord\n else if(nord .gt. 7) then \n write(*,*) 'Error. Incorrect parameter: NORD>7'\n write(*,*) 'Correct the error in GF.par and try again'\n stop\n end if\n\n read(70,2,err=101) output_prec\n if(output_prec .eq. 'S') goto 3\n if(output_prec .eq. 's') goto 3\n if(output_prec .eq. 'D') goto 3\n if(output_prec .eq. 'd') goto 3\n write(*,*) 'Incorrect parameter OUTPUT_PREC'\n write(*,*) 'Only chars S, s, D, d are allowed'\n write(*,*) 'Correct the error in GF.par and try again'\n stop\n 3 continue\n\n read(70,4,err=101) lambda_scale\n if(lambda_scale .eq. 'LOG') goto 5\n if(lambda_scale .eq. 'log') goto 5\n if(lambda_scale .eq. 'LIN') goto 5\n if(lambda_scale .eq. 'lin') goto 5\n write(*,*) 'Incorrect parameter LAMBDA_SCALE'\n write(*,*) 'Only \"LOG\", \"log\", \"LIN\", \"lin\" are allowed'\n write(*,*) 'Correct the error in GF.par and try again'\n stop\n 5 continue\n\n read(70,*,err=101) lambda_min, lambda_max, nl\n write(*,*) 'lambda_min,lambda_max:', sngl(lambda_min), \n $ sngl(lambda_max), ' [nm]'\n write(*,*) 'nl:', nl\n if(lambda_min.lt.rz) then\n write(*,*) 'Error. Incorrect parameters: lambda_min<0'\n write(*,*) 'Correct the error in GF.par and try again'\n stop\n else if(lambda_min.gt.lambda_max) then\n write(*,*) 'Error. Incorrect parameters: lambda_min>lambda_max'\n write(*,*) 'Correct the error in GF.par and try again'\n stop\n else if((lambda_min.eq.lambda_max) .and. (nl.ne.1) ) then\n write(*,*) 'Warning. lambda_min=lambda_max but nl=/=1'\n write(*,*) 'Setting nl=1 and continuing'\n nl=1\n else if((lambda_min .lt. lambda_max) .and. (nl.lt.2)) then\n write(*,*) 'Warning. lambda_min=0.002 (the value for Ag)'\n end if\n\n read(70,*,err=101) eps0\n\n read(70,*,err=101) eps_1\n if(eps_1.le.rz) then\n write(*,*) 'Error. Incorrect parameter: eps_1<=0; eps_1=', \n $ eps_1\n write(*,*) 'Correct the error in GF.par and try again'\n stop\n end if\n\n read(70,*) idummy\n read(70,*) idummy\n read(70,*) idummy\n \n read(70,*) rdummy, rdummy\n \n close(unit=70)\nc\nc------- End reading parameters -----------------------------\nc\n\n\nc\nc------- Input-dependent constants --------------------------\nc\n if(nl .gt. 1) then\n dlambda = (lambda_max - lambda_min)/dfloat(nl-1)\n else\n dlambda = rz\n end if\n\n z_p = z2 + z1\n L = dsqrt(rho*rho + z_p*z_p)\n zh_p = z_p/L\n zh_p_2 = zh_p*zh_p\n\n logscale = .false.\n if(lambda_scale .eq. 'LOG') logscale=.true.\n if(lambda_scale .eq. 'log') logscale=.true.\n if(logscale) then\n if(lambda_min .eq. rz) then\n write(*,*) 'If using logscale, lambda_min=0 is not allowed'\n write(*,*) 'Correct GF.par and try again; exiting'\n stop\n end if\n rlambda = lambda_max/lambda_min\n end if\nc\nc-------- End input-dependent constants block ------------------------\nc\n open(71, file='GRxx_asub', status='unknown', err=102)\n open(72, file='GRyy_asub', status='unknown', err=102)\n open(73, file='GRzz_asub', status='unknown', err=102)\n open(74, file='GRxz_asub', status='unknown', err=102)\n\n open(76, file='Kxx_asub', status='unknown', err=102)\n open(77, file='Kyy_asub', status='unknown', err=102)\n open(78, file='Kzz_asub', status='unknown', err=102)\n open(79, file='Kxz_asub', status='unknown', err=102)\nc\nc------- Start loop over wavelengths ---------------------------------\nc\n do 1, kl=1,nl\n if(logscale) then\n power = dfloat(kl-1)/dfloat(nl-1)\n lambda = lambda_min * rlambda**power\n else\n lambda = lambda_min + dlambda*dfloat(kl-1) \n end if\n write(*,*) kl, ': lambda=', sngl(lambda), '[nm]'\n k1 = twopi*dsqrt(eps_1)/lambda\n Lhat = L*k1\n Lhat_2 = Lhat*Lhat\n Lhat_3 = Lhat_2*Lhat\n Zhat = z_p*k1\n Rhat = rho*k1\n LZRhat = (Lhat - Zhat)/Rhat\n RZLhat = Rhat*Zhat/Lhat_2\n\n if(key.eq.0) then\n t = lambda_p/lambda\n eps_2 = (eps0 - ru/t/(t + cu*gd))\n else if(key .eq. 1) then\n eps_2 = eps_2_r + cu*eps_2_i\n else if(key .eq. 2) then\n ! Enter your own formula for eps_2 here\n continue\n ! Do not edit past this line\n else\n write(*,*) 'Unexpected error 1; exiting'\n write(*,*) 'Please report this error to code developers'\n stop\n end if \n\n eps = eps_2/eps_1\n eps_m = eps - ru\n eps_p = eps + ru\n eps_s = eps*eps\n eps_c = eps_s*eps\n s = eps_m/eps_p\n\n c1 = cdsqrt(eps_p)\n c2 = eps_p*eps_p\n c3 = cdsqrt(eps)\n c4 = (ru + c1)/(eps + c3*c1)\n c5 = three*(c3 + ru)\n c6 = (ru - three*(c3-eps) + two*eps**2) / c5\n c7 = ru + c3 + two*eps*(ru+c3-eps*c3) - eps_c\n Lam = (eps/eps_m/c1)*cdlog(c4)\n\n Kxx3 = (cu*eps/c2)*(c6 + Lam)\n Kyy3 = Kxx3\n Kxz3 = rz\n Kzz3 = -(Two*cu/c2)*(c7/c5 + Lam*eps_s)\n\n Kxx0 = s*(three*zh_p_2 - Two)\n Kyy0 = s\n Kzz0 = s*(three*zh_p_2 - ru)\n Kxz0 = s*three*RZLhat\n\n Kxx2 = s*zh_p*((s - ru)/(ru + zh_p) + zh_p) / two\n Kyy2 = s*(s + zh_p)/Two/(ru + zh_p)\n Kzz2 = s*(zh_p_2 + s + Two)/Two\n Kxz2 = s*(eps*LZRhat/eps_p + RZLhat/two)\n\n GRxx0 = Kxx0/Lhat_3\n GRyy0 = Kyy0/Lhat_3\n GRzz0 = Kzz0/Lhat_3\n GRxz0 = Kxz0/Lhat_3\n \n GRxx2 = Kxx2/Lhat\n GRyy2 = Kyy2/Lhat\n GRzz2 = Kzz2/Lhat\n GRxz2 = Kxz2/Lhat\n\n GRxx3 = Kxx3\n GRyy3 = Kyy3\n GRzz3 = Kzz3\n GRxz3 = Kxz3\n\n GRxx(0) = GRxx0\n GRxz(0) = GRxz0\n GRyy(0) = GRyy0\n GRzz(0) = GRzz0\n\n GRxx(2) = GRxx(0) + GRxx2\n GRyy(2) = GRyy(0) + GRyy2\n GRzz(2) = GRzz(0) + GRzz2\n GRxz(2) = GRxz(0) + GRxz2\n\n GRxx(3) = GRxx(2) + GRxx3 \n GRyy(3) = GRyy(2) + GRyy3 \n GRzz(3) = GRzz(2) + GRzz3 \n GRxz(3) = GRxz(2) + GRxz3 \n\n if((output_prec.eq.'S') .or. (output_prec.eq.'s')) then \n\n write(71,6,err=102) sngl(lambda),\n $ sngl(dreal(GRxx(nord))), sngl(dimag(GRxx(nord)))\n write(72,6,err=102) sngl(lambda), \n $ sngl(dreal(GRyy(nord))), sngl(dimag(GRyy(nord)))\n write(73,6,err=102) sngl(lambda), \n $ sngl(dreal(GRzz(nord))), sngl(dimag(GRzz(nord)))\n write(74,6,err=102) sngl(lambda), \n $ sngl(dreal(GRxz(nord))), sngl(dimag(GRxz(nord)))\n\n write(76,8,err=102) sngl(lambda),\n $ sngl(dreal(Kxx0)), sngl(dimag(Kxx0)),\n $ sngl(dreal(Kxx2)), sngl(dimag(Kxx2)),\n $ sngl(dreal(Kxx3)), sngl(dimag(Kxx3))\n write(77,8,err=102) sngl(lambda),\n $ sngl(dreal(Kyy0)), sngl(dimag(Kyy0)),\n $ sngl(dreal(Kyy2)), sngl(dimag(Kyy2)),\n $ sngl(dreal(Kyy3)), sngl(dimag(Kyy3))\n write(78,8,err=102) sngl(lambda),\n $ sngl(dreal(Kzz0)), sngl(dimag(Kzz0)),\n $ sngl(dreal(Kzz2)), sngl(dimag(Kzz2)),\n $ sngl(dreal(Kzz3)), sngl(dimag(Kzz3))\n write(79,8,err=102) sngl(lambda),\n $ sngl(dreal(Kxz0)), sngl(dimag(Kxz0)),\n $ sngl(dreal(Kxz2)), sngl(dimag(Kxz2)),\n $ sngl(dreal(Kxz3)), sngl(dimag(Kxz3))\n\n else if((output_prec.eq.'D') .or. (output_prec.eq.'d')) then\n\n write(71,10,err=102) sngl(lambda),\n $ dreal(GRxx(nord)), dimag(GRxx(nord))\n write(72,10,err=102) sngl(lambda), \n $ dreal(GRyy(nord)), dimag(GRyy(nord))\n write(73,10,err=102) sngl(lambda), \n $ dreal(GRzz(nord)), dimag(GRzz(nord))\n write(74,10,err=102) sngl(lambda), \n $ dreal(GRxz(nord)), dimag(GRxz(nord))\n\n write(76,12,err=102) sngl(lambda),\n $ dreal(Kxx0), dimag(Kxx0),\n $ dreal(Kxx2), dimag(Kxx2),\n $ dreal(Kxx3), dimag(Kxx3)\n write(77,12,err=102) sngl(lambda),\n $ dreal(Kyy0), dimag(Kyy0),\n $ dreal(Kyy2), dimag(Kyy2),\n $ dreal(Kyy3), dimag(Kyy3)\n write(78,12,err=102) sngl(lambda),\n $ dreal(Kzz0), dimag(Kzz0),\n $ dreal(Kzz2), dimag(Kzz2),\n $ dreal(Kzz3), dimag(Kzz3)\n write(79,12,err=102) sngl(lambda),\n $ dreal(Kxz0), dimag(Kxz0),\n $ dreal(Kxz2), dimag(Kxz2),\n $ dreal(Kxz3), dimag(Kxz3)\n\n else\n\n write(*,*) 'Unexpected error 2; exiting'\n write(*,*) 'Please report this error to code developers'\n stop\n\n end if\n\nc$$$ These lines to be used for debugging only \nc$$$ write(*,*) '---------------------------------------------'\nc$$$ write(*,*) 'XX:', dreal(GRxx(nord)), dimag(GRxx(nord))\nc$$$ write(*,*) 'YY:', dreal(GRyy(nord)), dimag(GRyy(nord))\nc$$$ write(*,*) 'ZZ:', dreal(GRzz(nord)), dimag(GRzz(nord))\nc$$$ write(*,*) 'XZ:', dreal(GRxz(nord)), dimag(GRxz(nord))\n\n 1 continue\n close(unit=71)\n close(unit=72)\n close(unit=73)\n close(unit=74)\n close(unit=75)\n close(unit=76)\n close(unit=77)\n close(unit=78)\n close(unit=79)\n\n stop\n\n 101 continue\n write(*,*) 'Error opening or reading input file GF.par; exiting'\n stop\n\n 102 continue\n write(*,*) 'Error opening or writing to an output file; exiting'\n stop\n\n 2 format(a1)\n 4 format(a3)\n 6 format(3G16.7E3)\n 8 format(7G16.7E3)\n 10 format(G16.7E3,2G23.14E3)\n 12 format(G16.7E3,6G23.14E3)\n\n end\n", "meta": {"hexsha": "c5b1e47f0ee92ac165172a13ad85bb0863d15112", "size": 16228, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/dipole_over_dielectric/GF_LIB/GF_sde_asub.f", "max_stars_repo_name": "Riarrieta/WindowedGreenFunctionMethod", "max_stars_repo_head_hexsha": "e6f965cac1acd8d9922e2bf94c33e3577ceb0dc9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/dipole_over_dielectric/GF_LIB/GF_sde_asub.f", "max_issues_repo_name": "Riarrieta/WindowedGreenFunctionMethod", "max_issues_repo_head_hexsha": "e6f965cac1acd8d9922e2bf94c33e3577ceb0dc9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/dipole_over_dielectric/GF_LIB/GF_sde_asub.f", "max_forks_repo_name": "Riarrieta/WindowedGreenFunctionMethod", "max_forks_repo_head_hexsha": "e6f965cac1acd8d9922e2bf94c33e3577ceb0dc9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.7494646681, "max_line_length": 73, "alphanum_fraction": 0.5183017008, "num_tokens": 5315, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096204605946, "lm_q2_score": 0.7122321842389469, "lm_q1q2_score": 0.6524827559829619}} {"text": "! ==============================================================================\n! Riemann solver for the one-dimensional shallow water equations\n! \n! Uses an fwave HLL type of approach and includes bathymetry terms. The\n! common block must contain values for the acceleration due to gravity `g` and\n! the tolerance used to decide whether a cell is dry or not `dry_tolerance`.\n! ==============================================================================\nsubroutine rp1(maxmx, num_eqn, num_waves, num_aux, num_ghost, mx, ql, qr, &\n auxl, auxr, fwave, s, amdq, apdq)\n\n implicit none\n\n ! Input\n integer, intent(in) :: maxmx, num_eqn, num_waves, num_ghost, num_aux, mx\n real(kind=8), intent(in out) :: ql(num_eqn,1-num_ghost:maxmx+num_ghost)\n real(kind=8), intent(in out) :: qr(num_eqn,1-num_ghost:maxmx+num_ghost)\n real(kind=8), intent(in out) :: auxl(num_aux,1-num_ghost:maxmx+num_ghost)\n real(kind=8), intent(in out) :: auxr(num_aux,1-num_ghost:maxmx+num_ghost)\n\n ! Output\n real(kind=8), intent(in out) :: s(num_waves, 1-num_ghost:maxmx+num_ghost)\n real(kind=8), intent(in out) :: fwave(num_eqn, num_waves, 1-num_ghost:maxmx+num_ghost)\n real(kind=8), intent(in out) :: amdq(num_eqn, 1-num_ghost:maxmx+num_ghost)\n real(kind=8), intent(in out) :: apdq(num_eqn, 1-num_ghost:maxmx+num_ghost)\n\n ! Locals\n integer :: i, mw\n real(kind=8) :: h_l, h_r, hu_l, hu_r, u_l, u_r, b_l, b_r, phi_l, phi_r\n real(kind=8) :: delta(2), beta(2)\n\n\n ! Common block\n integer :: mcapa\n real(kind=8) :: g, dry_tolerance, earth_radius, deg2rad\n common /cparam/ g, dry_tolerance, earth_radius, deg2rad, mcapa\n\n fwave = 0.d0\n s = 0.d0\n amdq = 0.d0\n apdq = 0.d0\n\n do i=2-num_ghost,mx+num_ghost\n ! Extract state\n h_l = qr(1, i-1)\n h_r = ql(1, i)\n hu_l = qr(2, i-1)\n hu_r = ql(2, i)\n b_l = auxr(1, i-1)\n b_r = auxl(1, i)\n\n if (h_l < dry_tolerance) then\n u_l = 0.d0\n else\n u_l = hu_l / h_l\n end if\n\n if (h_r < dry_tolerance) then\n u_r = 0.d0\n else\n u_r = hu_r / h_r\n end if\n \n phi_l = h_l * u_l**2 + 0.5d0 * g * h_l**2\n phi_r = h_r * u_r**2 + 0.5d0 * g * h_r**2\n\n ! Speeds\n s(1, i) = u_l - sqrt(g * h_l)\n s(2, i) = u_r + sqrt(g * h_r)\n\n ! Solve for wave strengths\n delta(1) = hu_r - hu_l\n delta(2) = phi_r - phi_l + g * 0.5d0 * (h_r + h_l) * (b_r - b_l)\n\n beta(1) = (s(2, i) * delta(1) - delta(2)) / (s(2, i) - s(1, i))\n beta(2) = (delta(2) - s(1, i) * delta(1)) / (s(2, i) - s(1, i))\n\n ! Construct waves\n fwave(1, 1, i) = beta(1)\n fwave(2, 1, i) = beta(1) * s(1, i)\n\n fwave(1, 2, i) = beta(2)\n fwave(2, 2, i) = beta(2) * s(2, i)\n\n\n ! Calculate accumulated flux\n do mw=1,num_waves\n if (s(mw, i) < 0.d0) then\n amdq(:, i) = amdq(:, i) + fwave(:, mw, i)\n else if (s(mw, i) > 0.d0) then\n apdq(:, i) = apdq(:, i) + fwave(:, mw, i)\n else\n amdq(:, i) = amdq(:, i) + 0.5d0 * fwave(:, mw, i)\n apdq(:, i) = apdq(:, i) + 0.5d0 * fwave(:, mw, i)\n end if\n end do\n enddo\n\nend subroutine rp1", "meta": {"hexsha": "5e83eb81d388675bff17e86bc8c2efa9bcc5c42c", "size": 3321, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/benchmark_1/rp1_shallow_fwave.f90", "max_stars_repo_name": "mandli/coastal", "max_stars_repo_head_hexsha": "8c80a4c740f92ea83b54c8a5432d11058c0d3476", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "examples/benchmark_1/rp1_shallow_fwave.f90", "max_issues_repo_name": "mandli/coastal", "max_issues_repo_head_hexsha": "8c80a4c740f92ea83b54c8a5432d11058c0d3476", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "examples/benchmark_1/rp1_shallow_fwave.f90", "max_forks_repo_name": "mandli/coastal", "max_forks_repo_head_hexsha": "8c80a4c740f92ea83b54c8a5432d11058c0d3476", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.887755102, "max_line_length": 90, "alphanum_fraction": 0.5076784101, "num_tokens": 1155, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096067182449, "lm_q2_score": 0.7122321903471563, "lm_q1q2_score": 0.6524827517910076}} {"text": "Real Function pnska(srt)\n Save\n If (srt>3.0) Then\n pnska = 0\n Return\n End If\n ala = 1.116\n aka = 0.498\n ana = 0.939\n asa = 1.197\n t1 = asa + aka\n If (srt<=t1) Then\n pnska = 0\n Return\n End If\n If (srt<1.9) sbb1 = (0.7/0.218)*(srt-t1)\n If (srt>=1.9) sbb1 = 0.14/(srt-1.7)\n sbb2 = 0.\n If (srt>1.682) sbb2 = 0.5*(1.-0.75*(srt-1.682))\n pnska = 0.25*(sbb1+sbb2)\n pnska = pnska/10.\n Return\nEnd Function pnska\n", "meta": {"hexsha": "7dc4964d0ff188a97c036b8a4715f8a249f4efd7", "size": 435, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/pnska.f90", "max_stars_repo_name": "xiaohaijin/AMPT", "max_stars_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-12-24T19:37:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-14T12:58:59.000Z", "max_issues_repo_path": "src/pnska.f90", "max_issues_repo_name": "xiaohaijin/AMPT", "max_issues_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_issues_repo_licenses": ["MIT"], "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/pnska.f90", "max_forks_repo_name": "xiaohaijin/AMPT", "max_forks_repo_head_hexsha": "90c7a1ab4dc04a092e64af759d53e22f6fea5b02", "max_forks_repo_licenses": ["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.125, "max_line_length": 49, "alphanum_fraction": 0.5471264368, "num_tokens": 238, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.91610961358942, "lm_q2_score": 0.7122321842389469, "lm_q1q2_score": 0.6524827510890902}} {"text": "FUNCTION vertex (coo_b, n1, n2, n3)\r\n\r\n ! check if angle < 165 degs - THIS IS MORE NATURAL IN GiD\r\n ! OLD: check if angle < 160 degs\r\n\r\n USE ctrl_db, ONLY: ndime\r\n\r\n IMPLICIT NONE\r\n LOGICAL :: vertex\r\n ! INPUT\r\n INTEGER (kind=4) :: n1, n2, n3 !number of nodes in contour line\r\n REAL (kind=8) :: coo_b(:,:) !(ndime,nelem) coordinates of contour nodes\r\n\r\n ! local\r\n REAL (kind=8) :: t1(ndime),t2(ndime),xl,cosine\r\n !REAL (kind=8), PARAMETER :: climit = -0.939692621d0 ! cos (160)\r\n REAL (kind=8), PARAMETER :: climit = -0.965925826289068d0 ! cos (165)\r\n\r\n\r\n !=============================\r\n\r\n vertex = .FALSE.\r\n\r\n t1 = coo_b(1:ndime,n1) - coo_b(1:ndime,n2) !vector n2-n1\r\n t2 = coo_b(1:ndime,n3) - coo_b(1:ndime,n2) !vector n2-n3\r\n CALL vecuni (ndime, t1, xl) !normalization of t1\r\n CALL vecuni (ndime, t2, xl) !normalization of t2\r\n cosine = DOT_PRODUCT(t1, t2) !cosine of the angle betw. t1, t2\r\n IF (cosine > climit) vertex = .TRUE. !angle < 160\r\n\r\n RETURN\r\n\r\nEND FUNCTION vertex\r\n", "meta": {"hexsha": "029b823bd873b27bdcf528ffacd7554df2a1c7a1", "size": 1086, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/remesh/vertex.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/remesh/vertex.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/remesh/vertex.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": 31.9411764706, "max_line_length": 79, "alphanum_fraction": 0.5662983425, "num_tokens": 391, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096090086368, "lm_q2_score": 0.7122321781307374, "lm_q1q2_score": 0.6524827422307196}} {"text": " PROGRAM TSTFFT\nC\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC\nC VERSION 4 APRIL 1985\nC\nC A TEST DRIVER FOR\nC A PACKAGE OF FORTRAN SUBPROGRAMS FOR THE FAST FOURIER\nC TRANSFORM OF PERIODIC AND OTHER SYMMETRIC SEQUENCES\nC\nC BY\nC\nC PAUL N SWARZTRAUBER\nC\nC NATIONAL CENTER FOR ATMOSPHERIC RESEARCH BOULDER,COLORADO 80307\nC\nC WHICH IS SPONSORED BY THE NATIONAL SCIENCE FOUNDATION\nC\nC * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\nC\nC\nC THIS PROGRAM TESTS THE PACKAGE OF FAST FOURIER\nC TRANSFORMS FOR BOTH COMPLEX AND REAL PERIODIC SEQUENCES AND\nC CERTIAN OTHER SYMMETRIC SEQUENCES THAT ARE LISTED BELOW.\nC\nC 1. RFFTI INITIALIZE RFFTF AND RFFTB\nC 2. RFFTF FORWARD TRANSFORM OF A REAL PERIODIC SEQUENCE\nC 3. RFFTB BACKWARD TRANSFORM OF A REAL COEFFICIENT ARRAY\nC\nC 4. EZFFTI INITIALIZE EZFFTF AND EZFFTB\nC 5. EZFFTF A SIMPLIFIED REAL PERIODIC FORWARD TRANSFORM\nC 6. EZFFTB A SIMPLIFIED REAL PERIODIC BACKWARD TRANSFORM\nC\nC 7. SINTI INITIALIZE SINT\nC 8. SINT SINE TRANSFORM OF A REAL ODD SEQUENCE\nC\nC 9. COSTI INITIALIZE COST\nC 10. COST COSINE TRANSFORM OF A REAL EVEN SEQUENCE\nC\nC 11. SINQI INITIALIZE SINQF AND SINQB\nC 12. SINQF FORWARD SINE TRANSFORM WITH ODD WAVE NUMBERS\nC 13. SINQB UNNORMALIZED INVERSE OF SINQF\nC\nC 14. COSQI INITIALIZE COSQF AND COSQB\nC 15. COSQF FORWARD COSINE TRANSFORM WITH ODD WAVE NUMBERS\nC 16. COSQB UNNORMALIZED INVERSE OF COSQF\nC\nC 17. CFFTI INITIALIZE CFFTF AND CFFTB\nC 18. CFFTF FORWARD TRANSFORM OF A COMPLEX PERIODIC SEQUENCE\nC 19. CFFTB UNNORMALIZED INVERSE OF CFFTF\nC\nC\n DIMENSION ND(10),X(200),Y(200),W(2000),\n 1 A(100),B(100),AH(100),BH(100),\n 2 XH(200),CX(200),CY(200)\n COMPLEX CX,CY\n DATA ND(1),ND(2),ND(3),ND(4),ND(5),ND(6),ND(7)/120,54,49,32,4,3,2/\n SQRT2 = SQRT(2.)\n NNS = 7\n DO 157 NZ=1,NNS\n N = ND(NZ)\n MODN = MOD(N,2)\n FN = FLOAT(N)\n TFN = FN+FN\n NP1 = N+1\n NM1 = N-1\n DO 101 J=1,NP1\n X(J) = SIN(FLOAT(J)*SQRT2)\n Y(J) = X(J)\n XH(J) = X(J)\n 101 CONTINUE\nC\nC TEST SUBROUTINES RFFTI,RFFTF AND RFFTB\nC\n CALL RFFTI (N,W)\n PI = 3.14159265358979\n DT = (PI+PI)/FN\n NS2 = (N+1)/2\n IF (NS2 .LT. 2) GO TO 104\n DO 103 K=2,NS2\n SUM1 = 0.\n SUM2 = 0.\n ARG = FLOAT(K-1)*DT\n DO 102 I=1,N\n ARG1 = FLOAT(I-1)*ARG\n SUM1 = SUM1+X(I)*COS(ARG1)\n SUM2 = SUM2+X(I)*SIN(ARG1)\n 102 CONTINUE\n Y(2*K-2) = SUM1\n Y(2*K-1) = -SUM2\n 103 CONTINUE\n 104 SUM1 = 0.\n SUM2 = 0.\n DO 105 I=1,NM1,2\n SUM1 = SUM1+X(I)\n SUM2 = SUM2+X(I+1)\n 105 CONTINUE\n IF (MODN .EQ. 1) SUM1 = SUM1+X(N)\n Y(1) = SUM1+SUM2\n IF (MODN .EQ. 0) Y(N) = SUM1-SUM2\n CALL RFFTF (N,X,W)\n RFTF = 0.\n DO 106 I=1,N\n RFTF = AMAX1(RFTF,ABS(X(I)-Y(I)))\n X(I) = XH(I)\n 106 CONTINUE\n RFTF = RFTF/FN\n DO 109 I=1,N\n SUM = .5*X(1)\n ARG = FLOAT(I-1)*DT\n IF (NS2 .LT. 2) GO TO 108\n DO 107 K=2,NS2\n ARG1 = FLOAT(K-1)*ARG\n SUM = SUM+X(2*K-2)*COS(ARG1)-X(2*K-1)*SIN(ARG1)\n 107 CONTINUE\n 108 IF (MODN .EQ. 0) SUM = SUM+.5*FLOAT((-1)**(I-1))*X(N)\n Y(I) = SUM+SUM\n 109 CONTINUE\n CALL RFFTB (N,X,W)\n RFTB = 0.\n DO 110 I=1,N\n RFTB = AMAX1(RFTB,ABS(X(I)-Y(I)))\n X(I) = XH(I)\n Y(I) = XH(I)\n 110 CONTINUE\n CALL RFFTB (N,Y,W)\n CALL RFFTF (N,Y,W)\n CF = 1./FN\n RFTFB = 0.\n DO 111 I=1,N\n RFTFB = AMAX1(RFTFB,ABS(CF*Y(I)-X(I)))\n 111 CONTINUE\nC\nC TEST SUBROUTINES SINTI AND SINT\nC\n DT = PI/FN\n DO 112 I=1,NM1\n X(I) = XH(I)\n 112 CONTINUE\n DO 114 I=1,NM1\n Y(I) = 0.\n ARG1 = FLOAT(I)*DT\n DO 113 K=1,NM1\n Y(I) = Y(I)+X(K)*SIN(FLOAT(K)*ARG1)\n 113 CONTINUE\n Y(I) = Y(I)+Y(I)\n 114 CONTINUE\n CALL SINTI (NM1,W)\n CALL SINT (NM1,X,W)\n CF = .5/FN\n SINTT = 0.\n DO 115 I=1,NM1\n SINTT = AMAX1(SINTT,ABS(X(I)-Y(I)))\n X(I) = XH(I)\n Y(I) = X(I)\n 115 CONTINUE\n SINTT = CF*SINTT\n CALL SINT (NM1,X,W)\n CALL SINT (NM1,X,W)\n SINTFB = 0.\n DO 116 I=1,NM1\n SINTFB = AMAX1(SINTFB,ABS(CF*X(I)-Y(I)))\n 116 CONTINUE\nC\nC TEST SUBROUTINES COSTI AND COST\nC\n DO 117 I=1,NP1\n X(I) = XH(I)\n 117 CONTINUE\n DO 119 I=1,NP1\n Y(I) = .5*(X(1)+FLOAT((-1)**(I+1))*X(N+1))\n ARG = FLOAT(I-1)*DT\n DO 118 K=2,N\n Y(I) = Y(I)+X(K)*COS(FLOAT(K-1)*ARG)\n 118 CONTINUE\n Y(I) = Y(I)+Y(I)\n 119 CONTINUE\n CALL COSTI (NP1,W)\n CALL COST (NP1,X,W)\n COSTT = 0.\n DO 120 I=1,NP1\n COSTT = AMAX1(COSTT,ABS(X(I)-Y(I)))\n X(I) = XH(I)\n Y(I) = XH(I)\n 120 CONTINUE\n COSTT = CF*COSTT\n CALL COST (NP1,X,W)\n CALL COST (NP1,X,W)\n COSTFB = 0.\n DO 121 I=1,NP1\n COSTFB = AMAX1(COSTFB,ABS(CF*X(I)-Y(I)))\n 121 CONTINUE\nC\nC TEST SUBROUTINES SINQI,SINQF AND SINQB\nC\n CF = .25/FN\n DO 122 I=1,N\n Y(I) = XH(I)\n 122 CONTINUE\n DT = PI/(FN+FN)\n DO 124 I=1,N\n X(I) = 0.\n ARG = DT*FLOAT(I)\n DO 123 K=1,N\n X(I) = X(I)+Y(K)*SIN(FLOAT(K+K-1)*ARG)\n 123 CONTINUE\n X(I) = 4.*X(I)\n 124 CONTINUE\n CALL SINQI (N,W)\n CALL SINQB (N,Y,W)\n SINQBT = 0.\n DO 125 I=1,N\n SINQBT = AMAX1(SINQBT,ABS(Y(I)-X(I)))\n X(I) = XH(I)\n 125 CONTINUE\n SINQBT = CF*SINQBT\n DO 127 I=1,N\n ARG = FLOAT(I+I-1)*DT\n Y(I) = .5*FLOAT((-1)**(I+1))*X(N)\n DO 126 K=1,NM1\n Y(I) = Y(I)+X(K)*SIN(FLOAT(K)*ARG)\n 126 CONTINUE\n Y(I) = Y(I)+Y(I)\n 127 CONTINUE\n CALL SINQF (N,X,W)\n SINQFT = 0.\n DO 128 I=1,N\n SINQFT = AMAX1(SINQFT,ABS(X(I)-Y(I)))\n Y(I) = XH(I)\n X(I) = XH(I)\n 128 CONTINUE\n CALL SINQF (N,Y,W)\n CALL SINQB (N,Y,W)\n SINQFB = 0.\n DO 129 I=1,N\n SINQFB = AMAX1(SINQFB,ABS(CF*Y(I)-X(I)))\n 129 CONTINUE\nC\nC TEST SUBROUTINES COSQI,COSQF AND COSQB\nC\n DO 130 I=1,N\n Y(I) = XH(I)\n 130 CONTINUE\n DO 132 I=1,N\n X(I) = 0.\n ARG = FLOAT(I-1)*DT\n DO 131 K=1,N\n X(I) = X(I)+Y(K)*COS(FLOAT(K+K-1)*ARG)\n 131 CONTINUE\n X(I) = 4.*X(I)\n 132 CONTINUE\n CALL COSQI (N,W)\n CALL COSQB (N,Y,W)\n COSQBT = 0.\n DO 133 I=1,N\n COSQBT = AMAX1(COSQBT,ABS(X(I)-Y(I)))\n X(I) = XH(I)\n 133 CONTINUE\n COSQBT = CF*COSQBT\n DO 135 I=1,N\n Y(I) = .5*X(1)\n ARG = FLOAT(I+I-1)*DT\n DO 134 K=2,N\n Y(I) = Y(I)+X(K)*COS(FLOAT(K-1)*ARG)\n 134 CONTINUE\n Y(I) = Y(I)+Y(I)\n 135 CONTINUE\n CALL COSQF (N,X,W)\n COSQFT = 0.\n DO 136 I=1,N\n COSQFT = AMAX1(COSQFT,ABS(Y(I)-X(I)))\n X(I) = XH(I)\n Y(I) = XH(I)\n 136 CONTINUE\n COSQFT = CF*COSQFT\n CALL COSQB (N,X,W)\n CALL COSQF (N,X,W)\n COSQFB = 0.\n DO 137 I=1,N\n COSQFB = AMAX1(COSQFB,ABS(CF*X(I)-Y(I)))\n 137 CONTINUE\nC\nC TEST PROGRAMS EZFFTI,EZFFTF,EZFFTB\nC\n CALL EZFFTI(N,W)\n DO 138 I=1,N\n X(I) = XH(I)\n 138 CONTINUE\n TPI = 8.*ATAN(1.)\n DT = TPI/FLOAT(N)\n NS2 = (N+1)/2\n CF = 2./FLOAT(N)\n NS2M = NS2-1\n IF (NS2M .LE. 0) GO TO 141\n DO 140 K=1,NS2M\n SUM1 = 0.\n SUM2 = 0.\n ARG = FLOAT(K)*DT\n DO 139 I=1,N\n ARG1 = FLOAT(I-1)*ARG\n SUM1 = SUM1+X(I)*COS(ARG1)\n SUM2 = SUM2+X(I)*SIN(ARG1)\n 139 CONTINUE\n A(K) = CF*SUM1\n B(K) = CF*SUM2\n 140 CONTINUE\n 141 NM1 = N-1\n SUM1 = 0.\n SUM2 = 0.\n DO 142 I=1,NM1,2\n SUM1 = SUM1+X(I)\n SUM2 = SUM2+X(I+1)\n 142 CONTINUE\n IF (MODN .EQ. 1) SUM1 = SUM1+X(N)\n AZERO = .5*CF*(SUM1+SUM2)\n IF (MODN .EQ. 0) A(NS2) = .5*CF*(SUM1-SUM2)\n CALL EZFFTF (N,X,AZEROH,AH,BH,W)\n DEZF1 = ABS(AZEROH-AZERO)\n IF (MODN .EQ. 0) DEZF1 = AMAX1(DEZF1,ABS(A(NS2)-AH(NS2)))\n IF (NS2M .LE. 0) GO TO 144\n DO 143 I=1,NS2M\n DEZF1 = AMAX1(DEZF1,ABS(AH(I)-A(I)),ABS(BH(I)-B(I)))\n 143 CONTINUE\n 144 NS2 = N/2\n IF (MODN .EQ. 0) B(NS2) = 0.\n DO 146 I=1,N\n SUM = AZERO\n ARG1 = FLOAT(I-1)*DT\n DO 145 K=1,NS2\n ARG2 = FLOAT(K)*ARG1\n SUM = SUM+A(K)*COS(ARG2)+B(K)*SIN(ARG2)\n 145 CONTINUE\n X(I) = SUM\n 146 CONTINUE\n CALL EZFFTB (N,Y,AZERO,A,B,W)\n DEZB1 = 0.\n DO 147 I=1,N\n DEZB1 = AMAX1(DEZB1,ABS(X(I)-Y(I)))\n X(I) = XH(I)\n 147 CONTINUE\n CALL EZFFTF (N,X,AZERO,A,B,W)\n CALL EZFFTB (N,Y,AZERO,A,B,W)\n DEZFB = 0.\n DO 148 I=1,N\n DEZFB = AMAX1(DEZFB,ABS(X(I)-Y(I)))\n 148 CONTINUE\nC\nC TEST CFFTI,CFFTF,CFFTB\nC\n DO 149 I=1,N\n CX(I) = CMPLX(COS(SQRT2*FLOAT(I)),SIN(SQRT2*FLOAT(I*I)))\n 149 CONTINUE\n DT = (PI+PI)/FN\n DO 151 I=1,N\n ARG1 = -FLOAT(I-1)*DT\n CY(I) = (0.,0.)\n DO 150 K=1,N\n ARG2 = FLOAT(K-1)*ARG1\n CY(I) = CY(I)+CMPLX(COS(ARG2),SIN(ARG2))*CX(K)\n 150 CONTINUE\n 151 CONTINUE\n CALL CFFTI (N,W)\n CALL CFFTF (N,CX,W)\n DCFFTF = 0.\n DO 152 I=1,N\n DCFFTF = AMAX1(DCFFTF,CABS(CX(I)-CY(I)))\n CX(I) = CX(I)/FN\n 152 CONTINUE\n DCFFTF = DCFFTF/FN\n DO 154 I=1,N\n ARG1 = FLOAT(I-1)*DT\n CY(I) = (0.,0.)\n DO 153 K=1,N\n ARG2 = FLOAT(K-1)*ARG1\n CY(I) = CY(I)+CMPLX(COS(ARG2),SIN(ARG2))*CX(K)\n 153 CONTINUE\n 154 CONTINUE\n CALL CFFTB (N,CX,W)\n DCFFTB = 0.\n DO 155 I=1,N\n DCFFTB = AMAX1(DCFFTB,CABS(CX(I)-CY(I)))\n CX(I) = CY(I)\n 155 CONTINUE\n CF = 1./FN\n CALL CFFTF (N,CX,W)\n CALL CFFTB (N,CX,W)\n DCFB = 0.\n DO 156 I=1,N\n DCFB = AMAX1(DCFB,CABS(CF*CX(I)-CY(I)))\n 156 CONTINUE\n WRITE (6,1001) N,RFTF,RFTB,RFTFB,SINTT,SINTFB,COSTT,COSTFB,\n 1 SINQFT,SINQBT,SINQFB,COSQFT,COSQBT,COSQFB,DEZF1,\n 2 DEZB1,DEZFB,DCFFTF,DCFFTB,DCFB\n 157 CONTINUE\nC\nC\nC\n 1001 FORMAT (2H0N,I5,8H RFFTF ,E10.3,8H RFFTB ,E10.3,8H RFFTFB ,\n 1 E10.3,8H SINT ,E10.3,8H SINTFB ,E10.3,8H COST ,E10.3/\n 2 7X,8H COSTFB ,E10.3,8H SINQF ,E10.3,8H SINQB ,E10.3,\n 3 8H SINQFB ,E10.3,8H COSQF ,E10.3,8H COSQB ,E10.3/7X,\n 4 8H COSQFB ,E10.3,8H DEZF ,E10.3,8H DEZB ,E10.3,\n 5 8H DEZFB ,E10.3,8H CFFTF ,E10.3,8H CFFTB ,E10.3/\n 6 7X,8H CFFTFB ,E10.3)\nC\n END\n", "meta": {"hexsha": "fbaf7416c116e0cf37de5f548da777262483fe94", "size": 11897, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "fftpack/test.f", "max_stars_repo_name": "eliteraspberries/udsp", "max_stars_repo_head_hexsha": "83ca89d18b304533adadacda2a9c71ce509fdc9d", "max_stars_repo_licenses": ["0BSD"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-09-04T21:21:21.000Z", "max_stars_repo_stars_event_max_datetime": "2015-09-04T21:21:21.000Z", "max_issues_repo_path": "fftpack/test.f", "max_issues_repo_name": "eliteraspberries/udsp", "max_issues_repo_head_hexsha": "83ca89d18b304533adadacda2a9c71ce509fdc9d", "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": "fftpack/test.f", "max_forks_repo_name": "eliteraspberries/udsp", "max_forks_repo_head_hexsha": "83ca89d18b304533adadacda2a9c71ce509fdc9d", "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": 29.230958231, "max_line_length": 72, "alphanum_fraction": 0.4507018576, "num_tokens": 4671, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096044278533, "lm_q2_score": 0.7122321781307374, "lm_q1q2_score": 0.6524827389681381}} {"text": "program pythagorean_3body\n use physics\n use bulirsch_stoer\n implicit none\n ! to do:\n ! figure out how to make it so I don't have to explicitly use 'accuracy.f08'\n ! within bulirsch_stoer.f08\n ! -- that would help make this a bit easier to use modularly\n\n integer, parameter :: n_bodies = 3\n ! 3-position, 3-velocity\n real(kind=precision), dimension(n_bodies, 3) :: x, v\n real(kind=precision), dimension(n_bodies) :: mass\n\n real(kind=precision), parameter :: H_big = 1./real(10**(4), kind=precision) ! large step size\n real(kind=precision) :: t\n real(kind=precision), parameter :: t_max = 70.\n\n type(accuracy_state) :: state_initial, state_final\n\n integer :: i,j ! loop variables\n\n integer, dimension(n_bodies) :: save_file_units\n character(len=6) :: jth_body_str ! tmp variable used in filenames\n character(len=15) :: filename ! tmp variable used in filenames\n character(len=15) :: data_format ! for saving\n\n do j=1, n_bodies\n write (jth_body_str, \"(I3.3)\") j\n filename = 'body_'//trim(jth_body_str)//'.dat'\n\n open(newunit=save_file_units(j), file=filename, status='unknown')\n write(save_file_units(j), *) \"t\",achar(9),achar(9),achar(9),achar(9),&\n \"x\",achar(9),achar(9),achar(9),achar(9),&\n \"y\",achar(9),achar(9),achar(9),achar(9),&\n \"z\"\n end do\n data_format = \"(4e13.5)\"\n\n\n !initialize\n mass(1) = 3.\n x(1, 1) = 1. ! body 1, x position \n x(1, 2) = 3. ! body 1, y position\n x(1, 3) = 0. ! body 1, z position\n\n\n mass(2) = 4.\n x(2, 1) = -2. ! body 2, x position \n x(2, 2) = -1. ! body 2, y position \n x(2, 3) = 0. ! body 2, z position \n\n mass(3) = 5.\n x(3, 1) = 1. ! body 3, x position \n x(3, 2) = -1. ! body 3, y position \n x(3, 3) = 0. ! body 3, z position\n\n v = 0. ! all bodies, all velocities\n\n call state_initial%initialize(n_bodies, x, v, mass)\n\n print *, 'energy (initial): '\n print *, state_initial%energy\n\n print *, 'angular momentum (initial): '\n print *, state_initial%angular_momentum\n\n t = 0.\n do i=1,int(t_max/ H_big)\n t = t + H_big\n call bulirsch_stoer_step(n_bodies, x, v, mass, H_big)\n \n if (mod(i, int(.1 / H_big)).eq.0) then\n! print *, 't = '\n! print *, i * H_big\n do j=1, n_bodies\n write(save_file_units(j),data_format) t, x(j,1), x(j,2), x(j,3)\n end do\n endif\n end do\n\n call state_final%initialize(n_bodies, x, v, mass)\n\n print *, \"\"\n print *, 'energy (final): '\n print *, state_final%energy\n\n print *, 'angular momentum (final): '\n print *, state_final%angular_momentum\n\n print *, \"overall conservation:\"\n print *, \"energy err:\"\n print *, abs( (state_final%energy - state_initial%energy) / state_initial%energy )\n print *, \"angular momentum err:\"\n print *, abs( state_final%angular_momentum - state_initial%angular_momentum )\n\nend program\n\n\n", "meta": {"hexsha": "8298752250efb92fe7e4fa2b0a0e1b4b9b592444", "size": 3222, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "pythagorean_3body/pythagorean_3body.f08", "max_stars_repo_name": "egentry/BulirschStoer_n-bodies", "max_stars_repo_head_hexsha": "2645f8e6f185c7228bde11f1883626dd006dce7d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-02-05T23:27:11.000Z", "max_stars_repo_stars_event_max_datetime": "2016-02-05T23:27:11.000Z", "max_issues_repo_path": "pythagorean_3body/pythagorean_3body.f08", "max_issues_repo_name": "egentry/BulirschStoer_n-bodies", "max_issues_repo_head_hexsha": "2645f8e6f185c7228bde11f1883626dd006dce7d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "pythagorean_3body/pythagorean_3body.f08", "max_forks_repo_name": "egentry/BulirschStoer_n-bodies", "max_forks_repo_head_hexsha": "2645f8e6f185c7228bde11f1883626dd006dce7d", "max_forks_repo_licenses": ["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.22, "max_line_length": 101, "alphanum_fraction": 0.5487274984, "num_tokens": 996, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.7606506472514405, "lm_q1q2_score": 0.652461864252364}} {"text": "program sw_oned\n implicit none\n integer, parameter :: DP = kind(1.0d0)\n integer, parameter :: ITER_MAX = 100000\n integer, parameter :: N = 500\n real(DP), parameter :: GG = 9.8d0\n real(DP), parameter :: CFL = 0.45d0\n real(DP), parameter :: TIME_FIN = 7.0d0\n real(DP), parameter :: L = 50.0d0\n real(DP), parameter :: XL = 0.0d0\n real(DP), parameter :: X_DAM = 10.0d0\n real(DP), parameter :: DEPTH_LEFT = 1.0d0\n real(DP), parameter :: VELOCITY_LEFT = 2.5d0\n real(DP), parameter :: DEPTH_RIGHT = 0.1d0\n real(DP), parameter :: VELOCITY_RIGHT = 0.0d0\n real(DP), parameter :: BC_U_LEFT = 1.0d0\n real(DP), parameter :: BC_U_RIGHT = 1.0d0\n real(DP), parameter :: DX = L / DFLOAT(N)\n character(len=20), parameter :: OUTPUT_FILE = 'res.dat'\n\n integer :: it=0\n real(DP) :: dt=1.d-8, time=0.0d0\n real(DP) :: t_start, t_end\n real(DP), allocatable :: x(:), h(:), u(:), h_cons(:), u_cons(:)\n real(DP), allocatable :: h_flux(:), u_flux(:)\n\n allocate(x(0:N+1), h(0:N+1), u(0:N+1), h_cons(0:N+1), u_cons(0:N+1))\n allocate(h_flux(0:N+1), u_flux(0:N+1))\n\n call cpu_time(t_start)\n\n call set_mesh(x)\n call set_ic_dambreak(x, h, u)\n do while(timeTIME_FIN-time) dt = TIME_FIN-time\n call set_bc(h, u)\n call riemann_fluxes(h, u, h_flux, u_flux)\n call prim_to_cons(h, u, h_cons, u_cons)\n call godunov(h_cons, u_cons, h_flux, u_flux)\n call cons_to_prim(h_cons, u_cons, h, u)\n\n it=it+1\n time=time+dt\n enddo\n call output_solution(OUTPUT_FILE, x, h, u)\n\n call cpu_time(t_end)\n deallocate(x, h, u, h_cons, u_cons, h_flux, u_flux)\n\n print*, 'cpu time: ', t_end - t_start\n print*, 'time: ', time\n print*, 'iterations:', it\n\ncontains\n\n! INITIALISATION PROCEDURES\n\nsubroutine set_mesh(x)\n real(DP), intent(out) :: x(0:N+1)\n integer :: i\n\n do i=0,N+1\n x(i) = XL+0.5d0*dx+DFLOAT(i-1)*DX\n enddo\nend\n\nsubroutine set_ic_dambreak(x, h, u)\n real(DP), intent(in) :: x(0:N+1)\n real(DP), intent(out) :: h(0:N+1), u(0:N+1)\n integer :: i\n\n do i=1,N\n if (x(i).le.X_DAM) then\n h(i)=DEPTH_LEFT\n u(i)=VELOCITY_LEFT\n else\n h(i)=DEPTH_RIGHT\n u(i)=VELOCITY_RIGHT\n endif\n enddo\nend\n\nsubroutine set_bc(h, u)\n real(DP), intent(inout) :: h(0: N+1), u(0: N+1)\n\n h(0) = h(1)\n u(0) = BC_U_LEFT * u(1)\n h(N+1) = h(N)\n u(N+1) = BC_U_RIGHT * u(N)\nend\n\nreal(DP) function dt_from(h,u)\n implicit none\n real(DP), dimension(0:N+1), intent(in) :: h, u\n real(DP) :: cmax\n integer :: i\n\n cmax = 0.0d0\n do i=1,N\n cmax = max( cmax, dabs(u(i)) + dsqrt(GG*h(i)) )\n enddo\n dt_from = CFL*dx/cmax\nend\n\nsubroutine riemann_fluxes(h, u, h_flux, u_flux)\n implicit none\n real(DP), dimension(0:N+1), intent(in) :: h,u\n real(DP), dimension(0:N+1), intent(out) :: h_flux, u_flux\n real(DP) :: hl,ul,hr,ur,f1,f2\n integer :: i\n\n do i=0,N\n hl=h(i)\n ul=u(i)\n\n hr=h(i+1)\n ur=u(i+1)\n\n call rusanov(hl, ul, hr, ur, f1, f2)\n h_flux(i) = f1\n u_flux(i) = f2\n enddo\nend\n\nsubroutine rusanov(hl,ul,hr,ur,f1,f2)\n implicit none\n real(DP), intent(in) :: hl,ul,hr,ur\n real(DP), intent(out) :: f1,f2\n real(DP) :: pl,al,pr,ar\n real(DP) :: h_cons_l, h_cons_r, u_cons_l, u_cons_r\n real(DP) :: h_flux_l, h_flux_r, u_flux_l, u_flux_r\n real(DP) :: sl,sr,sl1,sr1,sl2,sr2,smid\n\n pl = 0.5d0*GG*hl*hl\n al = DSQRT(GG*hl)\n pr = 0.5d0*GG*hr*hr\n ar = DSQRT(GG*hr)\n\n ! Wave speed estimation\n ! Davis S.F.(1988), 'Simplified second order Godunov type methods',\n ! SIAM J. Sci. and Stat. Comput., N3, 445-473.\n sl1=ul-al; sl2=ur-ar\n sr1=ul+al; sr2=ur+ar\n sl=DMIN1(sl1,sl2); sr=DMAX1(sr1,sr2)\n smid=dmax1(dabs(sl),dabs(sr))\n\n h_cons_l=hl ;\t h_flux_l=hl*ul\n u_cons_l=hl*ul;\t u_flux_l=hl*ul*ul+pl\n\n h_cons_r=hr ; h_flux_r=hr*ur\n u_cons_r=hr*ur; u_flux_r=hr*ur*ur+pr\n\n f1 = 0.5d0*(h_flux_l + h_flux_r) - 0.5d0*smid*(h_cons_r - h_cons_l)\n f2 = 0.5d0*(u_flux_l + u_flux_r) - 0.5d0*smid*(u_cons_r - u_cons_l)\nend\n\nsubroutine godunov(h_cons, u_cons, h_flux, u_flux)\n implicit none\n real(DP), dimension(0:N+1), intent(in) :: h_flux, u_flux\n real(DP), dimension(0:N+1), intent(inout) :: h_cons, u_cons\n integer :: i\n do i=1,N\n h_cons(i) = h_cons(i) - (h_flux(i) - h_flux(i-1)) * dt / dx\n u_cons(i) = u_cons(i) - (u_flux(i) - u_flux(i-1)) * dt / dx\n enddo\nend\n\n! AUX PROCEDURES\n\nsubroutine prim_to_cons(h, u, h_cons, u_cons)\n real(DP), intent(in) :: h(0:N+1), u(0:N+1)\n real(DP), intent(out) :: h_cons(0:N+1), u_cons(0:N+1)\n integer :: i\n\n do i = 1, N\n h_cons(i) = h(i)\n u_cons(i) = h(i) * u(i)\n enddo\n\nend\n\nsubroutine cons_to_prim(h_cons, u_cons, h, u)\n real(DP), intent(in) :: h_cons(0:N+1), u_cons(0:N+1)\n real(DP), intent(out) :: h(0:N+1), u(0:N+1)\n integer :: i\n\n do i = 1, N\n h(i) = h_cons(i)\n u(i) = u_cons(i) / h(i)\n enddo\n\nend\n\nsubroutine output_solution(filename, x, h, u)\n character(len=20), intent(in) :: filename\n real(DP), dimension(0:N+1), intent(in) :: x, h, u\n integer :: i\n\n open(unit=10,file=filename)\n do i=1,N\n write(10,*) x(i), h(i), u(i)\n enddo\n close(10)\nend\n\nend program sw_oned\n", "meta": {"hexsha": "7f7625ac60da10bd586c4e6aa2f17a9b3aa0345d", "size": 5068, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "sw.f90", "max_stars_repo_name": "prujaka/sw-oned", "max_stars_repo_head_hexsha": "c5e54b6732802fc53dcdbf155a4336594eeefb49", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "sw.f90", "max_issues_repo_name": "prujaka/sw-oned", "max_issues_repo_head_hexsha": "c5e54b6732802fc53dcdbf155a4336594eeefb49", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sw.f90", "max_forks_repo_name": "prujaka/sw-oned", "max_forks_repo_head_hexsha": "c5e54b6732802fc53dcdbf155a4336594eeefb49", "max_forks_repo_licenses": ["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.2488038278, "max_line_length": 70, "alphanum_fraction": 0.6110891871, "num_tokens": 2105, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680977182186, "lm_q2_score": 0.7606506526772884, "lm_q1q2_score": 0.652461863375119}} {"text": " SUBROUTINE DLAPLL( N, X, INCX, Y, INCY, SSMIN )\n*\n* -- LAPACK auxiliary routine (version 3.2) --\n* -- LAPACK is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n* November 2006\n*\n* .. Scalar Arguments ..\n INTEGER INCX, INCY, N\n DOUBLE PRECISION SSMIN\n* ..\n* .. Array Arguments ..\n DOUBLE PRECISION X( * ), Y( * )\n* ..\n*\n* Purpose\n* =======\n*\n* Given two column vectors X and Y, let\n*\n* A = ( X Y ).\n*\n* The subroutine first computes the QR factorization of A = Q*R,\n* and then computes the SVD of the 2-by-2 upper triangular matrix R.\n* The smaller singular value of R is returned in SSMIN, which is used\n* as the measurement of the linear dependency of the vectors X and Y.\n*\n* Arguments\n* =========\n*\n* N (input) INTEGER\n* The length of the vectors X and Y.\n*\n* X (input/output) DOUBLE PRECISION array,\n* dimension (1+(N-1)*INCX)\n* On entry, X contains the N-vector X.\n* On exit, X is overwritten.\n*\n* INCX (input) INTEGER\n* The increment between successive elements of X. INCX > 0.\n*\n* Y (input/output) DOUBLE PRECISION array,\n* dimension (1+(N-1)*INCY)\n* On entry, Y contains the N-vector Y.\n* On exit, Y is overwritten.\n*\n* INCY (input) INTEGER\n* The increment between successive elements of Y. INCY > 0.\n*\n* SSMIN (output) DOUBLE PRECISION\n* The smallest singular value of the N-by-2 matrix A = ( X Y ).\n*\n* =====================================================================\n*\n* .. Parameters ..\n DOUBLE PRECISION ZERO, ONE\n PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )\n* ..\n* .. Local Scalars ..\n DOUBLE PRECISION A11, A12, A22, C, SSMAX, TAU\n* ..\n* .. External Functions ..\n DOUBLE PRECISION DDOT\n EXTERNAL DDOT\n* ..\n* .. External Subroutines ..\n EXTERNAL DAXPY, DLARFG, DLAS2\n* ..\n* .. Executable Statements ..\n*\n* Quick return if possible\n*\n IF( N.LE.1 ) THEN\n SSMIN = ZERO\n RETURN\n END IF\n*\n* Compute the QR factorization of the N-by-2 matrix ( X Y )\n*\n CALL DLARFG( N, X( 1 ), X( 1+INCX ), INCX, TAU )\n A11 = X( 1 )\n X( 1 ) = ONE\n*\n C = -TAU*DDOT( N, X, INCX, Y, INCY )\n CALL DAXPY( N, C, X, INCX, Y, INCY )\n*\n CALL DLARFG( N-1, Y( 1+INCY ), Y( 1+2*INCY ), INCY, TAU )\n*\n A12 = Y( 1 )\n A22 = Y( 1+INCY )\n*\n* Compute the SVD of 2-by-2 Upper triangular matrix.\n*\n CALL DLAS2( A11, A12, A22, SSMIN, SSMAX )\n*\n RETURN\n*\n* End of DLAPLL\n*\n END\n", "meta": {"hexsha": "76ed6e1c27d031ac26445403b9ce022e2f31661c", "size": 2776, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Code/External/Ipopt-3.10.2/ThirdParty/Lapack/LAPACK/SRC/dlapll.f", "max_stars_repo_name": "fbudin69500/calatk", "max_stars_repo_head_hexsha": "3cee90488feab7e3ef2ade1f791106aa7f11e404", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-09-15T12:51:02.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-08T14:03:58.000Z", "max_issues_repo_path": "Code/External/Ipopt-3.10.2/ThirdParty/Lapack/LAPACK/SRC/dlapll.f", "max_issues_repo_name": "cpatrick/calatk", "max_issues_repo_head_hexsha": "849c17919ac5084b5b067c7631bc2aa1efd650df", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Code/External/Ipopt-3.10.2/ThirdParty/Lapack/LAPACK/SRC/dlapll.f", "max_forks_repo_name": "cpatrick/calatk", "max_forks_repo_head_hexsha": "849c17919ac5084b5b067c7631bc2aa1efd650df", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-10-20T16:38:28.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-20T16:38:28.000Z", "avg_line_length": 27.4851485149, "max_line_length": 76, "alphanum_fraction": 0.5223342939, "num_tokens": 847, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318195, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.6524551914962087}} {"text": " Program zgesdd_example\n\n! ZGESDD Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_interfaces, Only: zgesdd\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nb = 64, nin = 5, nout = 6, prerr = 0\n! .. Local Scalars ..\n Integer :: i, info, lda, ldu, ldvt, lwork, m, n\n! .. Local Arrays ..\n Complex (Kind=dp), Allocatable :: a(:, :), a_copy(:, :), b(:), u(:, :), &\n vt(:, :), work(:)\n Complex (Kind=dp) :: dummy(1, 1)\n Real (Kind=dp), Allocatable :: rwork(:), s(:)\n Integer, Allocatable :: iwork(:)\n! .. Intrinsic Procedures ..\n Intrinsic :: max, min, nint, real\n! .. Executable Statements ..\n Write (nout, *) 'ZGESDD Example Program Results'\n Write (nout, *)\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) m, n\n lda = m\n ldu = m\n ldvt = n\n Allocate (a(lda,n), a_copy(m,n), s(m), u(ldu,m), vt(ldvt,n), b(m), &\n rwork((5*m+7)*n), iwork(8*m))\n\n! Read the m by n matrix A from data file\n Read (nin, *)(a(i,1:n), i=1, m)\n\n! Read the right hand side of the linear system\n Read (nin, *) b(1:m)\n\n a_copy(1:m, 1:n) = a(1:m, 1:n)\n\n! Use routine workspace query to get optimal workspace.\n lwork = -1\n Call zgesdd('A', m, n, a, lda, s, u, ldu, vt, ldvt, dummy, lwork, rwork, &\n iwork, info)\n\n! Make sure that there is enough workspace for block size nb.\n lwork = max((2*m+2)*m+2*n+nb*(m+n), nint(real(dummy(1,1))))\n Allocate (work(lwork))\n\n! Compute the singular values and left and right singular vectors\n! of A.\n\n Call zgesdd('A', m, n, a, lda, s, u, ldu, vt, ldvt, work, lwork, rwork, &\n iwork, info)\n\n If (info/=0) Then\n Write (nout, 100) 'Failure in ZGESDD. INFO =', info\n100 Format (1X, A, I4)\n Go To 120\n End If\n\n! Print the significant singular values of A\n\n Write (nout, *) 'Singular values of A:'\n Write (nout, 110) s(1:min(m,n))\n110 Format (1X, 4(3X,F11.4))\n\n If (prerr>0) Then\n Call compute_error_bounds(m, n, s)\n End If\n\n If (m= 2, then TAU(j) is the scalar factor of\n* v(j) v(j)' in the Householder transformation H(j) of\n* the product U = H(1)...H(n-2)\n* If ITYPE < 2, then TAU is not referenced.\n* Not modified.\n*\n* WORK REAL array, dimension (2*N**2)\n* Workspace.\n* Modified.\n*\n* RESULT REAL array, dimension (2)\n* The values computed by the two tests described above. The\n* values are currently limited to 1/ulp, to avoid overflow.\n* RESULT(1) is always modified. RESULT(2) is modified only\n* if LDU is at least N.\n* Modified.\n*\n* =====================================================================\n*\n* .. Parameters ..\n REAL ZERO, ONE\n PARAMETER ( ZERO = 0.0E0, ONE = 1.0E0 )\n* ..\n* .. Local Scalars ..\n INTEGER J, JJ, JJ1, JJ2, NN, NNP1\n REAL ANORM, ULP, UNFL, WNORM\n* ..\n* .. External Functions ..\n REAL SLAMCH, SLANSY\n EXTERNAL SLAMCH, SLANSY\n* ..\n* .. External Subroutines ..\n EXTERNAL SGEMM, SSYMM\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC MAX, MIN, REAL\n* ..\n* .. Executable Statements ..\n*\n RESULT( 1 ) = ZERO\n RESULT( 2 ) = ZERO\n IF( N.LE.0 .OR. M.LE.0 )\n $ RETURN\n*\n UNFL = SLAMCH( 'Safe minimum' )\n ULP = SLAMCH( 'Precision' )\n*\n* Do Test 1\n*\n* Norm of A:\n*\n ANORM = MAX( SLANSY( '1', UPLO, N, A, LDA, WORK ), UNFL )\n*\n* Compute error matrix:\n*\n* ITYPE=1: error = U' A U - S\n*\n CALL SSYMM( 'L', UPLO, N, M, ONE, A, LDA, U, LDU, ZERO, WORK, N )\n NN = N*N\n NNP1 = NN + 1\n CALL SGEMM( 'T', 'N', M, M, N, ONE, U, LDU, WORK, N, ZERO,\n $ WORK( NNP1 ), N )\n DO 10 J = 1, M\n JJ = NN + ( J-1 )*N + J\n WORK( JJ ) = WORK( JJ ) - D( J )\n 10 CONTINUE\n IF( KBAND.EQ.1 .AND. N.GT.1 ) THEN\n DO 20 J = 2, M\n JJ1 = NN + ( J-1 )*N + J - 1\n JJ2 = NN + ( J-2 )*N + J\n WORK( JJ1 ) = WORK( JJ1 ) - E( J-1 )\n WORK( JJ2 ) = WORK( JJ2 ) - E( J-1 )\n 20 CONTINUE\n END IF\n WNORM = SLANSY( '1', UPLO, M, WORK( NNP1 ), N, WORK( 1 ) )\n*\n IF( ANORM.GT.WNORM ) THEN\n RESULT( 1 ) = ( WNORM / ANORM ) / ( M*ULP )\n ELSE\n IF( ANORM.LT.ONE ) THEN\n RESULT( 1 ) = ( MIN( WNORM, M*ANORM ) / ANORM ) / ( M*ULP )\n ELSE\n RESULT( 1 ) = MIN( WNORM / ANORM, REAL( M ) ) / ( M*ULP )\n END IF\n END IF\n*\n* Do Test 2\n*\n* Compute U'U - I\n*\n IF( ITYPE.EQ.1 )\n $ CALL SORT01( 'Columns', N, M, U, LDU, WORK, 2*N*N,\n $ RESULT( 2 ) )\n*\n RETURN\n*\n* End of SSYT22\n*\n END\n", "meta": {"hexsha": "36151d56c2e3da92dd79bb2f4980a38322fdfaf5", "size": 6910, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "TESTING/EIG/ssyt22.f", "max_stars_repo_name": "nashmit/lapack-release", "max_stars_repo_head_hexsha": "fd9237f4f4cd45f10a8be62b35e63a702c93328f", "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": "TESTING/EIG/ssyt22.f", "max_issues_repo_name": "nashmit/lapack-release", "max_issues_repo_head_hexsha": "fd9237f4f4cd45f10a8be62b35e63a702c93328f", "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": "TESTING/EIG/ssyt22.f", "max_forks_repo_name": "nashmit/lapack-release", "max_forks_repo_head_hexsha": "fd9237f4f4cd45f10a8be62b35e63a702c93328f", "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.2897196262, "max_line_length": 72, "alphanum_fraction": 0.501447178, "num_tokens": 2123, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587846530937, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.6524551785179108}} {"text": "\tINCLUDE 'VICMAIN_FOR'\n\tSUBROUTINE MAIN44\n\tREAL*4 V(2,900),P(6)\n\n\tCALL XVUNIT(IU,'INP',1,IST,' ')\n\tCALL XVOPEN(IU,IST,' ')\n\tCALL XVREAD(IU,V,IST,' ')\n\tCALL XVCLOSE(IU,IST,' ')\n\tCALL XVPARM('NROW',NR,ICNT,IDEF,0)\n\tCALL XVPARM('NCOL',NC,ICNT,IDEF,0)\nC\tCL = V(1,NR*NC/2+1)\nC\tCS = V(2,NR*NC/2+1)\n\n\tCALL XVPARM('OFFSET',P,ICNT,IDEF,0)\n\tIF (ICNT .EQ. 2) THEN\n\t\tA = 1\n\t\tB = 0\n\t\tC = 0\n\t\tD = 1\n\t\tE = P(1)\n\t\tF = P(2)\n\tEND IF\n\tCALL XVPARM('ROTOFF',P,ICNT,IDEF,0)\n\tIF (ICNT .EQ. 3) THEN\n\t\tPR = 3.1415926*P(3)/180.\n\t\tST = SIN(PR)\n\t\tCT = COS(PR)\n\t\tA = CT\n\t\tB = -ST\n\t\tC = ST\n\t\tD = CT\n\t\tE = P(1)\n\t\tF = P(2)\n\tEND IF\n\tCALL XVPARM('SCALEOFF',P,ICNT,IDEF,0)\n\tIF (ICNT .EQ. 3) THEN\n\t\tA = P(3)\n\t\tB = 0\n\t\tC = 0\n\t\tD = P(3)\n\t\tE = P(1)\n\t\tF = P(2)\n\tEND IF\n\tCALL XVPARM('SRO',P,ICNT,IDEF,0)\n\tIF (ICNT .EQ. 4) THEN\n\t\tPR = 3.1415926*P(3)/180.\n\t\tST = SIN(PR)\n\t\tCT = COS(PR)\n\t\tA = P(4)*CT\n\t\tB = -P(4)*ST\n\t\tC = P(4)*ST\n\t\tD = P(4)*CT\n\t\tE = P(1)\n\t\tF = P(2)\n\tEND IF\n\tCALL XVPARM('UNC',P,ICNT,IDEF,0)\n\tIF (ICNT .EQ. 6) THEN\n\t\tA = P(1)\n\t\tB = P(2)\n\t\tC = P(3)\n\t\tD = P(4)\n\t\tE = P(5)\n\t\tF = P(6)\n\tEND IF\n\n\tPRINT 1, A,B,E\n\tPRINT 1, C,D,F\n1\tFORMAT(3(5X,F12.4))\n\n\tDO 10 I=1,900\n\tVL = V(1,I)\n\tVS = V(2,I)\n\tV(1,I) = A*VL + B*VS + E\n10\tV(2,I) = C*VL + D*VS + F\n\n\tCALL XVUNIT(IO,'OUT',1,IST,' ')\n\tCALL XVOPEN(IO,IST,'OP','WRITE',' ')\n\tCALL XVWRIT(IO,V,IST,' ')\n\tCALL XVCLOSE(IO,IST,' ')\n\nC\tCALL PGRID(V,NR,NC,DUM,0)\n\tRETURN\n\tEND\n", "meta": {"hexsha": "d39a4433fde8e77a6c73cd0a5a626bc887918a5b", "size": 1379, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "vos/p2/prog/skew/skew.f", "max_stars_repo_name": "NASA-AMMOS/VICAR", "max_stars_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2020-10-21T05:56:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T10:02:01.000Z", "max_issues_repo_path": "vos/p2/prog/skew/skew.f", "max_issues_repo_name": "NASA-AMMOS/VICAR", "max_issues_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "vos/p2/prog/skew/skew.f", "max_forks_repo_name": "NASA-AMMOS/VICAR", "max_forks_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-03-09T01:51:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-23T00:23:24.000Z", "avg_line_length": 16.4166666667, "max_line_length": 38, "alphanum_fraction": 0.5250181291, "num_tokens": 746, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513786759492, "lm_q2_score": 0.7279754548076478, "lm_q1q2_score": 0.6524490050136055}} {"text": "*DECK DQC25S\n SUBROUTINE DQC25S (F, A, B, BL, BR, ALFA, BETA, RI, RJ, RG, RH,\n + RESULT, ABSERR, RESASC, INTEGR, NEV)\nC***BEGIN PROLOGUE DQC25S\nC***PURPOSE To compute I = Integral of F*W over (BL,BR), with error\nC estimate, where the weight function W has a singular\nC behaviour of ALGEBRAICO-LOGARITHMIC type at the points\nC A and/or B. (BL,BR) is a part of (A,B).\nC***LIBRARY SLATEC (QUADPACK)\nC***CATEGORY H2A2A2\nC***TYPE DOUBLE PRECISION (QC25S-S, DQC25S-D)\nC***KEYWORDS 25-POINT CLENSHAW-CURTIS INTEGRATION, QUADPACK, QUADRATURE\nC***AUTHOR Piessens, Robert\nC Applied Mathematics and Programming Division\nC K. U. Leuven\nC de Doncker, Elise\nC Applied Mathematics and Programming Division\nC K. U. Leuven\nC***DESCRIPTION\nC\nC Integration rules for integrands having ALGEBRAICO-LOGARITHMIC\nC end point singularities\nC Standard fortran subroutine\nC Double precision version\nC\nC PARAMETERS\nC F - Double precision\nC Function subprogram defining the integrand\nC F(X). The actual name for F needs to be declared\nC E X T E R N A L in the driver program.\nC\nC A - Double precision\nC Left end point of the original interval\nC\nC B - Double precision\nC Right end point of the original interval, B.GT.A\nC\nC BL - Double precision\nC Lower limit of integration, BL.GE.A\nC\nC BR - Double precision\nC Upper limit of integration, BR.LE.B\nC\nC ALFA - Double precision\nC PARAMETER IN THE WEIGHT FUNCTION\nC\nC BETA - Double precision\nC Parameter in the weight function\nC\nC RI,RJ,RG,RH - Double precision\nC Modified CHEBYSHEV moments for the application\nC of the generalized CLENSHAW-CURTIS\nC method (computed in subroutine DQMOMO)\nC\nC RESULT - Double precision\nC Approximation to the integral\nC RESULT is computed by using a generalized\nC CLENSHAW-CURTIS method if B1 = A or BR = B.\nC in all other cases the 15-POINT KRONROD\nC RULE is applied, obtained by optimal addition of\nC Abscissae to the 7-POINT GAUSS RULE.\nC\nC ABSERR - Double precision\nC Estimate of the modulus of the absolute error,\nC which should equal or exceed ABS(I-RESULT)\nC\nC RESASC - Double precision\nC Approximation to the integral of ABS(F*W-I/(B-A))\nC\nC INTEGR - Integer\nC Which determines the weight function\nC = 1 W(X) = (X-A)**ALFA*(B-X)**BETA\nC = 2 W(X) = (X-A)**ALFA*(B-X)**BETA*LOG(X-A)\nC = 3 W(X) = (X-A)**ALFA*(B-X)**BETA*LOG(B-X)\nC = 4 W(X) = (X-A)**ALFA*(B-X)**BETA*LOG(X-A)*\nC LOG(B-X)\nC\nC NEV - Integer\nC Number of integrand evaluations\nC\nC***REFERENCES (NONE)\nC***ROUTINES CALLED DQCHEB, DQK15W, DQWGTS\nC***REVISION HISTORY (YYMMDD)\nC 810101 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890531 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC***END PROLOGUE DQC25S\nC\n DOUBLE PRECISION A,ABSERR,ALFA,B,BETA,BL,BR,CENTR,CHEB12,CHEB24,\n 1 DC,F,FACTOR,FIX,FVAL,HLGTH,RESABS,RESASC,RESULT,RES12,\n 2 RES24,RG,RH,RI,RJ,U,DQWGTS,X\n INTEGER I,INTEGR,ISYM,NEV\nC\n DIMENSION CHEB12(13),CHEB24(25),FVAL(25),RG(25),RH(25),RI(25),\n 1 RJ(25),X(11)\nC\n EXTERNAL F, DQWGTS\nC\nC THE VECTOR X CONTAINS THE VALUES COS(K*PI/24)\nC K = 1, ..., 11, TO BE USED FOR THE COMPUTATION OF THE\nC CHEBYSHEV SERIES EXPANSION OF F.\nC\n SAVE X\n DATA X(1),X(2),X(3),X(4),X(5),X(6),X(7),X(8),X(9),X(10),X(11)/\n 1 0.9914448613738104D+00, 0.9659258262890683D+00,\n 2 0.9238795325112868D+00, 0.8660254037844386D+00,\n 3 0.7933533402912352D+00, 0.7071067811865475D+00,\n 4 0.6087614290087206D+00, 0.5000000000000000D+00,\n 5 0.3826834323650898D+00, 0.2588190451025208D+00,\n 6 0.1305261922200516D+00/\nC\nC LIST OF MAJOR VARIABLES\nC -----------------------\nC\nC FVAL - VALUE OF THE FUNCTION F AT THE POINTS\nC (BR-BL)*0.5*COS(K*PI/24)+(BR+BL)*0.5\nC K = 0, ..., 24\nC CHEB12 - COEFFICIENTS OF THE CHEBYSHEV SERIES EXPANSION\nC OF DEGREE 12, FOR THE FUNCTION F, IN THE\nC INTERVAL (BL,BR)\nC CHEB24 - COEFFICIENTS OF THE CHEBYSHEV SERIES EXPANSION\nC OF DEGREE 24, FOR THE FUNCTION F, IN THE\nC INTERVAL (BL,BR)\nC RES12 - APPROXIMATION TO THE INTEGRAL OBTAINED FROM CHEB12\nC RES24 - APPROXIMATION TO THE INTEGRAL OBTAINED FROM CHEB24\nC DQWGTS - EXTERNAL FUNCTION SUBPROGRAM DEFINING\nC THE FOUR POSSIBLE WEIGHT FUNCTIONS\nC HLGTH - HALF-LENGTH OF THE INTERVAL (BL,BR)\nC CENTR - MID POINT OF THE INTERVAL (BL,BR)\nC\nC***FIRST EXECUTABLE STATEMENT DQC25S\n NEV = 25\n IF(BL.EQ.A.AND.(ALFA.NE.0.0D+00.OR.INTEGR.EQ.2.OR.INTEGR.EQ.4))\n 1 GO TO 10\n IF(BR.EQ.B.AND.(BETA.NE.0.0D+00.OR.INTEGR.EQ.3.OR.INTEGR.EQ.4))\n 1 GO TO 140\nC\nC IF A.GT.BL AND B.LT.BR, APPLY THE 15-POINT GAUSS-KRONROD\nC SCHEME.\nC\nC\n CALL DQK15W(F,DQWGTS,A,B,ALFA,BETA,INTEGR,BL,BR,\n 1 RESULT,ABSERR,RESABS,RESASC)\n NEV = 15\n GO TO 270\nC\nC THIS PART OF THE PROGRAM IS EXECUTED ONLY IF A = BL.\nC ----------------------------------------------------\nC\nC COMPUTE THE CHEBYSHEV SERIES EXPANSION OF THE\nC FOLLOWING FUNCTION\nC F1 = (0.5*(B+B-BR-A)-0.5*(BR-A)*X)**BETA\nC *F(0.5*(BR-A)*X+0.5*(BR+A))\nC\n 10 HLGTH = 0.5D+00*(BR-BL)\n CENTR = 0.5D+00*(BR+BL)\n FIX = B-CENTR\n FVAL(1) = 0.5D+00*F(HLGTH+CENTR)*(FIX-HLGTH)**BETA\n FVAL(13) = F(CENTR)*(FIX**BETA)\n FVAL(25) = 0.5D+00*F(CENTR-HLGTH)*(FIX+HLGTH)**BETA\n DO 20 I=2,12\n U = HLGTH*X(I-1)\n ISYM = 26-I\n FVAL(I) = F(U+CENTR)*(FIX-U)**BETA\n FVAL(ISYM) = F(CENTR-U)*(FIX+U)**BETA\n 20 CONTINUE\n FACTOR = HLGTH**(ALFA+0.1D+01)\n RESULT = 0.0D+00\n ABSERR = 0.0D+00\n RES12 = 0.0D+00\n RES24 = 0.0D+00\n IF(INTEGR.GT.2) GO TO 70\n CALL DQCHEB(X,FVAL,CHEB12,CHEB24)\nC\nC INTEGR = 1 (OR 2)\nC\n DO 30 I=1,13\n RES12 = RES12+CHEB12(I)*RI(I)\n RES24 = RES24+CHEB24(I)*RI(I)\n 30 CONTINUE\n DO 40 I=14,25\n RES24 = RES24+CHEB24(I)*RI(I)\n 40 CONTINUE\n IF(INTEGR.EQ.1) GO TO 130\nC\nC INTEGR = 2\nC\n DC = LOG(BR-BL)\n RESULT = RES24*DC\n ABSERR = ABS((RES24-RES12)*DC)\n RES12 = 0.0D+00\n RES24 = 0.0D+00\n DO 50 I=1,13\n RES12 = RES12+CHEB12(I)*RG(I)\n RES24 = RES12+CHEB24(I)*RG(I)\n 50 CONTINUE\n DO 60 I=14,25\n RES24 = RES24+CHEB24(I)*RG(I)\n 60 CONTINUE\n GO TO 130\nC\nC COMPUTE THE CHEBYSHEV SERIES EXPANSION OF THE\nC FOLLOWING FUNCTION\nC F4 = F1*LOG(0.5*(B+B-BR-A)-0.5*(BR-A)*X)\nC\n 70 FVAL(1) = FVAL(1)*LOG(FIX-HLGTH)\n FVAL(13) = FVAL(13)*LOG(FIX)\n FVAL(25) = FVAL(25)*LOG(FIX+HLGTH)\n DO 80 I=2,12\n U = HLGTH*X(I-1)\n ISYM = 26-I\n FVAL(I) = FVAL(I)*LOG(FIX-U)\n FVAL(ISYM) = FVAL(ISYM)*LOG(FIX+U)\n 80 CONTINUE\n CALL DQCHEB(X,FVAL,CHEB12,CHEB24)\nC\nC INTEGR = 3 (OR 4)\nC\n DO 90 I=1,13\n RES12 = RES12+CHEB12(I)*RI(I)\n RES24 = RES24+CHEB24(I)*RI(I)\n 90 CONTINUE\n DO 100 I=14,25\n RES24 = RES24+CHEB24(I)*RI(I)\n 100 CONTINUE\n IF(INTEGR.EQ.3) GO TO 130\nC\nC INTEGR = 4\nC\n DC = LOG(BR-BL)\n RESULT = RES24*DC\n ABSERR = ABS((RES24-RES12)*DC)\n RES12 = 0.0D+00\n RES24 = 0.0D+00\n DO 110 I=1,13\n RES12 = RES12+CHEB12(I)*RG(I)\n RES24 = RES24+CHEB24(I)*RG(I)\n 110 CONTINUE\n DO 120 I=14,25\n RES24 = RES24+CHEB24(I)*RG(I)\n 120 CONTINUE\n 130 RESULT = (RESULT+RES24)*FACTOR\n ABSERR = (ABSERR+ABS(RES24-RES12))*FACTOR\n GO TO 270\nC\nC THIS PART OF THE PROGRAM IS EXECUTED ONLY IF B = BR.\nC ----------------------------------------------------\nC\nC COMPUTE THE CHEBYSHEV SERIES EXPANSION OF THE\nC FOLLOWING FUNCTION\nC F2 = (0.5*(B+BL-A-A)+0.5*(B-BL)*X)**ALFA\nC *F(0.5*(B-BL)*X+0.5*(B+BL))\nC\n 140 HLGTH = 0.5D+00*(BR-BL)\n CENTR = 0.5D+00*(BR+BL)\n FIX = CENTR-A\n FVAL(1) = 0.5D+00*F(HLGTH+CENTR)*(FIX+HLGTH)**ALFA\n FVAL(13) = F(CENTR)*(FIX**ALFA)\n FVAL(25) = 0.5D+00*F(CENTR-HLGTH)*(FIX-HLGTH)**ALFA\n DO 150 I=2,12\n U = HLGTH*X(I-1)\n ISYM = 26-I\n FVAL(I) = F(U+CENTR)*(FIX+U)**ALFA\n FVAL(ISYM) = F(CENTR-U)*(FIX-U)**ALFA\n 150 CONTINUE\n FACTOR = HLGTH**(BETA+0.1D+01)\n RESULT = 0.0D+00\n ABSERR = 0.0D+00\n RES12 = 0.0D+00\n RES24 = 0.0D+00\n IF(INTEGR.EQ.2.OR.INTEGR.EQ.4) GO TO 200\nC\nC INTEGR = 1 (OR 3)\nC\n CALL DQCHEB(X,FVAL,CHEB12,CHEB24)\n DO 160 I=1,13\n RES12 = RES12+CHEB12(I)*RJ(I)\n RES24 = RES24+CHEB24(I)*RJ(I)\n 160 CONTINUE\n DO 170 I=14,25\n RES24 = RES24+CHEB24(I)*RJ(I)\n 170 CONTINUE\n IF(INTEGR.EQ.1) GO TO 260\nC\nC INTEGR = 3\nC\n DC = LOG(BR-BL)\n RESULT = RES24*DC\n ABSERR = ABS((RES24-RES12)*DC)\n RES12 = 0.0D+00\n RES24 = 0.0D+00\n DO 180 I=1,13\n RES12 = RES12+CHEB12(I)*RH(I)\n RES24 = RES24+CHEB24(I)*RH(I)\n 180 CONTINUE\n DO 190 I=14,25\n RES24 = RES24+CHEB24(I)*RH(I)\n 190 CONTINUE\n GO TO 260\nC\nC COMPUTE THE CHEBYSHEV SERIES EXPANSION OF THE\nC FOLLOWING FUNCTION\nC F3 = F2*LOG(0.5*(B-BL)*X+0.5*(B+BL-A-A))\nC\n 200 FVAL(1) = FVAL(1)*LOG(FIX+HLGTH)\n FVAL(13) = FVAL(13)*LOG(FIX)\n FVAL(25) = FVAL(25)*LOG(FIX-HLGTH)\n DO 210 I=2,12\n U = HLGTH*X(I-1)\n ISYM = 26-I\n FVAL(I) = FVAL(I)*LOG(U+FIX)\n FVAL(ISYM) = FVAL(ISYM)*LOG(FIX-U)\n 210 CONTINUE\n CALL DQCHEB(X,FVAL,CHEB12,CHEB24)\nC\nC INTEGR = 2 (OR 4)\nC\n DO 220 I=1,13\n RES12 = RES12+CHEB12(I)*RJ(I)\n RES24 = RES24+CHEB24(I)*RJ(I)\n 220 CONTINUE\n DO 230 I=14,25\n RES24 = RES24+CHEB24(I)*RJ(I)\n 230 CONTINUE\n IF(INTEGR.EQ.2) GO TO 260\n DC = LOG(BR-BL)\n RESULT = RES24*DC\n ABSERR = ABS((RES24-RES12)*DC)\n RES12 = 0.0D+00\n RES24 = 0.0D+00\nC\nC INTEGR = 4\nC\n DO 240 I=1,13\n RES12 = RES12+CHEB12(I)*RH(I)\n RES24 = RES24+CHEB24(I)*RH(I)\n 240 CONTINUE\n DO 250 I=14,25\n RES24 = RES24+CHEB24(I)*RH(I)\n 250 CONTINUE\n 260 RESULT = (RESULT+RES24)*FACTOR\n ABSERR = (ABSERR+ABS(RES24-RES12))*FACTOR\n 270 RETURN\n END\n", "meta": {"hexsha": "1ddf1a7d7e80dce7036c36ad83b671cc14ad5290", "size": 11274, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/dqc25s.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/dqc25s.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/dqc25s.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.5838150289, "max_line_length": 72, "alphanum_fraction": 0.5419549406, "num_tokens": 4171, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8962513842182775, "lm_q2_score": 0.7279754489059774, "lm_q1q2_score": 0.6524490037589042}} {"text": "!---------------------------------------------------!\n! Copyright (c) 2017 Shunsuke A. Sato !\n! Released under the MIT license !\n! https://opensource.org/licenses/mit-license.php !\n!---------------------------------------------------!\n! Reference Joachim Kopp, Int. J. Mod. Phys. C 19 (2008) 523-548\n!-------10--------20--------30--------40--------50--------60--------70--------80--------90\nsubroutine diag3x3(zA,zB,lambda)\n implicit none\n real(8),parameter :: pi=4d0*atan(1d0)\n complex(8), intent(in) :: zA(3,3)\n complex(8), intent(out) :: zB(3,3)\n real(8), intent(out) :: lambda(3)\n\n real(8) :: c0,c1,c2\n real(8) :: p,q,t,ss,phi,xx(3),xx_t(3)\n complex(8) :: zC(3,3),zx,zy\n integer :: ivec,imin\n\n c2 = -real(zA(1,1)+zA(2,2)+zA(3,3))\n c1 = real( zA(1,1)*zA(2,2) + zA(2,2)*zA(3,3) + zA(3,3)*zA(1,1) &\n -abs(zA(1,2))**2 -abs(zA(1,3))**2 -abs(zA(2,3))**2 )\n c0 = real( zA(1,1)*abs(zA(2,3))**2 + zA(2,2)*abs(zA(1,3))**2 &\n + zA(3,3)*abs(zA(1,2))**2 - zA(1,1)*zA(2,2)*zA(3,3) &\n - 2d0*conjg(zA(1,3))*zA(1,2)*zA(2,3) )\n\n p = c2**2 - 3d0*c1\n q = -27d0*c0/2d0 -c2**3 + 9d0*c2*c1/2d0\n ss = c1**2*(p-c1)/4d0+c0*(q+27d0*c0/4d0)\n ss = sqrt(27d0*ss)/q\n phi = atan(ss)/3d0\n if(phi < 0)phi = phi + pi\n\n xx(1) = 2d0*cos(phi)\n xx(2) = 2d0*cos(phi+2d0*pi/3d0)\n xx(3) = 2d0*cos(phi-2d0*pi/3d0)\n\n lambda(:) = (sqrt(p)*xx(:)-c2)/3d0\n\n do ivec = 1,3\n\n zC = zA\n zC(1,1) = zC(1,1) -lambda(ivec)\n zC(2,2) = zC(2,2) -lambda(ivec)\n zC(3,3) = zC(3,3) -lambda(ivec)\n\n xx(1) = abs(zC(1,1))\n xx(2) = abs(zC(2,2))\n xx(3) = abs(zC(3,3))\n if(xx(1)\n if (l1.LT.0 .OR. l2.LT.0 .OR. l3.LT.0) print *, \"Quantum number l must be non-negative!\"\n Gaunt = mone(m1)*sqrt((2*l1+1)*(2*l2+1)*(2*l3+1)/(4*pi))*f3j(l1_,zero,l2_,zero,l3_,zero)*f3j(l1_,mm1_,l2_,m2_,l3_,m3_)\n return\nEND function Gaunt\n\nREAL*8 function iFactorial(j)\n IMPLICIT NONE\n INTEGER, intent(in) :: j\n INTEGER :: i\n REAL*8 :: x\n if (j<0) print *, \"iFactorial defined only for non-negative numbers!\"\n x=1\n iFactorial = x\n if (j.eq.1) return\n DO i=2,j\n x = x*i\n END DO\n iFactorial = x\n return\nend function iFactorial\n\nREAL*8 function dFactorial(x)\n IMPLICIT NONE\n REAL*8, intent(in) :: x\n REAL*8, PARAMETER :: spi2 = 0.8862269254527579\n REAL*8 :: y, r\n r=1\n y=x\n DO WHILE(y.gt.1.0)\n r = r * y\n y = y -1.\n ENDDO\n IF (abs(y-0.5).LT.1e-10) r = r*spi2\n dFactorial = r\n return\nEND function dFactorial\n\nREAL*8 function mone(i)\n INTEGER, intent(in) :: i\n mone = 1 - 2*MOD(abs(i),2)\n return\nend function mone\n\nREAL*8 function Delta(j1, j2, j)\n IMPLICIT NONE\n REAL*8, intent(in) :: j1, j2, j\n ! function calls\n REAL*8 :: dFactorial\n Delta = sqrt(dFactorial(j1+j2-j)*dFactorial(j1-j2+j)*dFactorial(-j1+j2+j)/dFactorial(j1+j2+j+1))\n return\nEND function Delta\n\nREAL*8 function f3j(j1, m1, j2, m2, j3, m3)\n IMPLICIT NONE\n REAL*8, intent(in) :: j1, j2, j3, m1, m2, m3\n INTEGER :: tmin, tmax, t\n REAL*8 :: sum, v1, v2, dn\n ! function calls\n REAL*8 :: dFactorial\n REAL*8 :: iFactorial\n REAL*8 :: Delta\n REAL*8 :: mone\n f3j=0\n IF (abs(m1+m2+m3) .GT. 1e-10) return\n IF (abs(j1-j2)-1e-14 .GT. j3 .OR. j3 .GT. j1+j2+1e-14) return\n if (abs(m1) .GT. j1 .OR. abs(m2) .GT. j2 .OR. abs(m3) .GT. j3) return\n tmin = INT(max(max(0.0,j2-j3-m1),j1-j3+m2)+1e-14)\n tmax = INT(min(min(j1+j2-j3,j1-m1),j2+m2)+1e-14)\n sum=0\n DO t=tmin, tmax\n v1 = dFactorial(j3-j2+m1+t)*dFactorial(j3-j1-m2+t)\n v2 = dFactorial(j1+j2-j3-t)*dFactorial(j1-m1-t)*dFactorial(j2+m2-t)\n sum = sum + mone(t)/(iFactorial(t)*v1*v2)\n END DO\n dn = dFactorial(j1+m1)*dFactorial(j1-m1)*dFactorial(j2+m2)*dFactorial(j2-m2)*dFactorial(j3+m3)*dFactorial(j3-m3)\n f3j = mone(INT(j1-j2-m3))*Delta(j1,j2,j3)*sqrt(dn)*sum\n return\nEND function f3j\n\n\nREAL*8 function ClebschG(j,m,j1,m1,j2,m2)\n IMPLICIT NONE\n REAL*8, intent(in) :: j,m,j1,m1,j2,m2\n INTEGER :: tmin, tmax, t\n REAL*8 :: sum, v1, v2\n ! function calls\n REAL*8 :: iFactorial\n REAL*8 :: dFactorial\n REAL*8 :: mone\n REAL*8 :: Delta\n\n ClebschG = 0\n IF (m1+m2 .NE. m) return\n tmin = INT(max(max(0.0,j2-j-m1),j1-j+m2)+1e-14)\n tmax = INT(min(min(j1+j2-j,j1-m1),j2+m2)+1e-14)\n sum=0;\n DO t=tmin, tmax\n v1 = sqrt((2*j+1)*dFactorial(j1+m1)*dFactorial(j1-m1)*dFactorial(j2+m2)*dFactorial(j2-m2)*dFactorial(j+m)*dFactorial(j-m))\n v2 = iFactorial(t)*dFactorial(j1+j2-j-t)*dFactorial(j1-m1-t)*dFactorial(j2+m2-t)*dFactorial(j-j2+m1+t)*dFactorial(j-j1-m2+t)\n sum = sum + mone(t)*v1/v2\n END DO\n ClebschG = sum*Delta(j1,j2,j)\n return\nEND function ClebschG\n", "meta": {"hexsha": "c7da65675edf843e1ac41f5869186936766d9337", "size": 6304, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gaunt.f90", "max_stars_repo_name": "kunyuan/PyGW", "max_stars_repo_head_hexsha": "7b32065586f7d7cc221d051b5254397fdf0a3076", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-07-06T01:56:46.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-13T13:07:06.000Z", "max_issues_repo_path": "gaunt.f90", "max_issues_repo_name": "kunyuan/PyGW", "max_issues_repo_head_hexsha": "7b32065586f7d7cc221d051b5254397fdf0a3076", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gaunt.f90", "max_forks_repo_name": "kunyuan/PyGW", "max_forks_repo_head_hexsha": "7b32065586f7d7cc221d051b5254397fdf0a3076", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-07-06T01:56:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-06T01:56:59.000Z", "avg_line_length": 28.5248868778, "max_line_length": 129, "alphanum_fraction": 0.5596446701, "num_tokens": 2798, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513675912912, "lm_q2_score": 0.7279754371026367, "lm_q1q2_score": 0.6524489810761062}} {"text": "! { dg-do compile }\n! { dg-options \"-Warray-temporaries -O -fdump-tree-original\" }\n!\n! PR fortran/43829\n! Scalarization of reductions.\n! Test that sum is properly inlined.\n\n! This is the compile time test only; for the runtime test see inline_sum_2.f90\n! We can't test for temporaries on the run time test directly, as it tries\n! several optimization options among which -Os, and sum inlining is disabled\n! at -Os.\n\n\n implicit none\n\n\n integer :: i, j, k\n\n integer, parameter :: q = 2\n integer, parameter :: nx=3, ny=2*q, nz=5\n integer, parameter, dimension(nx,ny,nz) :: p = &\n & reshape ((/ (i**2, i=1,size(p)) /), shape(p))\n\n integer, parameter, dimension( ny,nz) :: px = &\n & reshape ((/ (( &\n & nx*( nx*j+nx*ny*k+1)*( nx*j+nx*ny*k+1+ (nx-1)) &\n & + nx*(nx-1)*(2*nx-1)/6, &\n & j=0,ny-1), k=0,nz-1) /), shape(px))\n\n integer, parameter, dimension(nx, nz) :: py = &\n & reshape ((/ (( &\n & ny*(i +nx*ny*k+1)*(i +nx*ny*k+1+nx *(ny-1)) &\n & +(nx )**2*ny*(ny-1)*(2*ny-1)/6, &\n & i=0,nx-1), k=0,nz-1) /), shape(py))\n\n integer, parameter, dimension(nx,ny ) :: pz = &\n & reshape ((/ (( &\n & nz*(i+nx*j +1)*(i+nx*j +1+nx*ny*(nz-1)) &\n & +(nx*ny)**2*nz*(nz-1)*(2*nz-1)/6, &\n & i=0,nx-1), j=0,ny-1) /), shape(pz))\n\n\n integer, dimension(nx,ny,nz) :: a\n integer, dimension( ny,nz) :: ax\n integer, dimension(nx, nz) :: ay\n integer, dimension(nx,ny ) :: az\n\n logical, dimension(nx,ny,nz) :: m, true\n\n\n integer, dimension(nx,ny) :: b\n\n integer, dimension(nx,nx) :: onesx\n integer, dimension(ny,ny) :: onesy\n integer, dimension(nz,nz) :: onesz\n\n\n a = p\n m = reshape((/ ((/ .true., .false. /), i=1,size(m)/2) /), shape(m))\n true = reshape((/ (.true., i=1,size(true)) /), shape(true))\n\n onesx = reshape((/ ((1, j=1,i),(0,j=1,nx-i),i=1,size(onesx,2)) /), shape(onesx))\n onesy = reshape((/ ((1, j=1,i),(0,j=1,ny-i),i=1,size(onesy,2)) /), shape(onesy))\n onesz = reshape((/ ((1, j=1,i),(0,j=1,nz-i),i=1,size(onesz,2)) /), shape(onesz))\n\n ! Correct results in simple cases\n ax = sum(a,1)\n if (any(ax /= px)) STOP 1\n\n ay = sum(a,2)\n if (any(ay /= py)) STOP 2\n\n az = sum(a,3)\n if (any(az /= pz)) STOP 3\n\n\n ! Masks work\n if (any(sum(a,1,.false.) /= 0)) STOP 4\n if (any(sum(a,2,.true.) /= py)) STOP 5\n if (any(sum(a,3,m) /= merge(pz,0,m(:,:,1)))) STOP 6\n if (any(sum(a,2,m) /= merge(sum(a(:, ::2,:),2),&\n sum(a(:,2::2,:),2),&\n m(:,1,:)))) STOP 7\n\n\n ! It works too with array constructors ...\n if (any(sum( &\n reshape((/ (i*i,i=1,size(a)) /), shape(a)), &\n 1, &\n true) /= ax)) STOP 8\n\n ! ... and with vector subscripts\n if (any(sum( &\n a((/ (i,i=1,nx) /), &\n (/ (i,i=1,ny) /), &\n (/ (i,i=1,nz) /)), &\n 1) /= ax)) STOP 9\n\n if (any(sum( &\n a(sum(onesx(:,:),1), & ! unnecessary { dg-warning \"Creating array temporary\" }\n sum(onesy(:,:),1), & ! unnecessary { dg-warning \"Creating array temporary\" }\n sum(onesz(:,:),1)), & ! unnecessary { dg-warning \"Creating array temporary\" }\n 1) /= ax)) STOP 10\n\n\n ! Nested sums work\n if (sum(sum(sum(a,1),1),1) /= sum(a)) STOP 11\n if (sum(sum(sum(a,1),2),1) /= sum(a)) STOP 12\n if (sum(sum(sum(a,3),1),1) /= sum(a)) STOP 13\n if (sum(sum(sum(a,3),2),1) /= sum(a)) STOP 14\n\n if (any(sum(sum(a,1),1) /= sum(sum(a,2),1))) STOP 15\n if (any(sum(sum(a,1),2) /= sum(sum(a,3),1))) STOP 16\n if (any(sum(sum(a,2),2) /= sum(sum(a,3),2))) STOP 17\n\n\n ! Temps are unavoidable here (function call's argument or result)\n ax = sum(neid3(a),1) ! { dg-warning \"Creating array temporary\" }\n ! Sums as part of a bigger expr work\n if (any(1+sum(eid(a),1)+ax+sum( &\n neid3(a), & ! { dg-warning \"Creating array temporary\" }\n 1)+1 /= 3*ax+2)) STOP 18\n if (any(1+eid(sum(a,2))+ay+ &\n neid2( & ! { dg-warning \"Creating array temporary\" }\n sum(a,2) & ! { dg-warning \"Creating array temporary\" }\n )+1 /= 3*ay+2)) STOP 19\n if (any(sum(eid(sum(a,3))+az+2* &\n neid2(az) & ! { dg-warning \"Creating array temporary\" }\n ,1)+1 /= 4*sum(az,1)+1)) STOP 20\n\n if (any(sum(transpose(sum(a,1)),1)+sum(az,1) /= sum(ax,2)+sum(sum(a,3),1))) STOP 21\n\n\n ! Creates a temp when needed. \n a(1,:,:) = sum(a,1) ! unnecessary { dg-warning \"Creating array temporary\" }\n if (any(a(1,:,:) /= ax)) STOP 22\n\n b = p(:,:,1)\n call set(b(2:,1), sum(b(:nx-1,:),2)) ! { dg-warning \"Creating array temporary\" }\n if (any(b(2:,1) /= ay(1:nx-1,1))) STOP 23\n\n b = p(:,:,1)\n call set(b(:,1), sum(b,2)) ! unnecessary { dg-warning \"Creating array temporary\" }\n if (any(b(:,1) /= ay(:,1))) STOP 24\n\n b = p(:,:,1)\n call tes(sum(eid(b(:nx-1,:)),2), b(2:,1)) ! { dg-warning \"Creating array temporary\" }\n if (any(b(2:,1) /= ay(1:nx-1,1))) STOP 25\n\n b = p(:,:,1)\n call tes(eid(sum(b,2)), b(:,1)) ! unnecessary { dg-warning \"Creating array temporary\" }\n if (any(b(:,1) /= ay(:,1))) STOP 26\n\ncontains\n\n elemental function eid (x)\n integer, intent(in) :: x\n integer :: eid\n\n eid = x\n end function eid\n\n function neid2 (x)\n integer, intent(in) :: x(:,:)\n integer :: neid2(size(x,1),size(x,2))\n\n neid2 = x\n end function neid2\n\n function neid3 (x)\n integer, intent(in) :: x(:,:,:)\n integer :: neid3(size(x,1),size(x,2),size(x,3))\n\n neid3 = x\n end function neid3\n\n elemental subroutine set (o, i)\n integer, intent(in) :: i\n integer, intent(out) :: o\n\n o = i\n end subroutine set\n\n elemental subroutine tes (i, o)\n integer, intent(in) :: i\n integer, intent(out) :: o\n\n o = i\n end subroutine tes\nend\n! { dg-final { scan-tree-dump-times \"struct array.._integer\\\\(kind=4\\\\) atmp\" 13 \"original\" } }\n! { dg-final { scan-tree-dump-times \"struct array\\[^\\\\n\\]*atmp\" 13 \"original\" } }\n! { dg-final { scan-tree-dump-times \"_gfortran_sum_\" 0 \"original\" } }\n", "meta": {"hexsha": "c1b2db899ecd407b615a4cb0cf34a21a67b954ee", "size": 6316, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/inline_sum_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/inline_sum_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/inline_sum_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.5567010309, "max_line_length": 100, "alphanum_fraction": 0.4988917036, "num_tokens": 2190, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933535169629, "lm_q2_score": 0.7956581049086031, "lm_q1q2_score": 0.6523547918864661}} {"text": "program array_op_3\nimplicit none\n\ninteger :: a(2, 2, 1), b(2, 2, 1)\nlogical :: c(2, 2, 1)\ninteger :: i, j, k\n\ndo i = 1, 2\n do j = 1, 2\n do k = 1, 1\n a(i, j, k) = i/j\n b(i, j, k) = j/i\n end do\n end do\nend do\n\nc = a .eq. b\ncall check(c, a, b, 0)\n\nc = a .ne. b\ncall check(c, a, b, 1)\n\nc = a .lt. b\ncall check(c, a, b, 2)\n\nc = b <= a\ncall check(c, a, b, 3)\n\nc = b .gt. a\ncall check(c, a, b, 4)\n\nc = b >= a\ncall check(c, a, b, 5)\n\ncontains\n\n subroutine check(c, a, b, op_code)\n implicit none\n\n integer, intent(in) :: a(:, :, :), b(:, :, :)\n logical, intent(in) :: c(:, :, :)\n integer, intent(in) :: op_code\n\n integer :: i, j, k\n\n do i = lbound(a, 1), ubound(a, 1)\n do j = lbound(a, 2), ubound(a, 2)\n do k = lbound(a, 3), ubound(a, 3)\n select case(op_code)\n case (0)\n if(c(i, j, k) .neqv. (a(i, j, k) .eq. b(i, j, k))) error stop\n case (1)\n if(c(i, j, k) .neqv. (a(i, j, k) .ne. b(i, j, k))) error stop\n case (2)\n if(c(i, j, k) .neqv. (a(i, j, k) .lt. b(i, j, k))) error stop\n case (3)\n if(c(i, j, k) .neqv. (b(i, j, k) <= a(i, j, k))) error stop\n case (4)\n if(c(i, j, k) .neqv. (b(i, j, k) .gt. a(i, j, k))) error stop\n case (5)\n if(c(i, j, k) .neqv. (b(i, j, k) >= a(i, j, k))) error stop\n end select\n end do\n end do\n end do\n\n end subroutine check\n\nend program", "meta": {"hexsha": "e8a0b80153ecb03eb1d05748d9f202fcd961850f", "size": 1595, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "integration_tests/arrays_op_3.f90", "max_stars_repo_name": "Thirumalai-Shaktivel/lfortran", "max_stars_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 316, "max_stars_repo_stars_event_min_datetime": "2019-03-24T16:23:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:28:33.000Z", "max_issues_repo_path": "integration_tests/arrays_op_3.f90", "max_issues_repo_name": "Thirumalai-Shaktivel/lfortran", "max_issues_repo_head_hexsha": "bb39faf1094b028351d5aefe27d64ee69302300a", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-07-29T04:58:03.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-04T16:40:06.000Z", "max_forks_repo_path": "integration_tests/arrays_op_3.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": 23.115942029, "max_line_length": 81, "alphanum_fraction": 0.4056426332, "num_tokens": 602, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.819893353516963, "lm_q2_score": 0.7956581000631542, "lm_q1q2_score": 0.6523547879137148}} {"text": "! Fortran arrays can have any lower bound. The default is 1\r\n! lbound and ubound are intrinsics that return the lower and upper bounds\r\n! of an array\r\nprogram bounds\r\nimplicit none\r\ninteger :: v(-1:1) = [1,-2,3]\r\ninteger :: mat(-1:1,3)\r\nprint*,lbound(v),ubound(v),size(v) ! -1 1 3\r\nprint*,sum(v) ! 2\r\nprint*,sum(v,mask=v>0) ! 4 -- sum excludes -2\r\nprint*,lbound(mat),ubound(mat),size(mat) ! -1 1 1 3 9\r\nend program bounds\r\n", "meta": {"hexsha": "cb137519ec3f0490cc13f58561d40d3e6d311b88", "size": 423, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "bounds.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": "bounds.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": "bounds.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": 32.5384615385, "max_line_length": 74, "alphanum_fraction": 0.6666666667, "num_tokens": 148, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7956581000631542, "lm_q2_score": 0.8198933315126791, "lm_q1q2_score": 0.652354770405828}} {"text": "!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++!\n! \u00a0 Futility Development Group \u00a0\u00a0 !\n!\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0 All rights reserved.\u00a0\u00a0 \u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0 !\n!\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0 !\n! Futility is a jointly-maintained, open-source project between the University !\n! of Michigan and Oak Ridge National Laboratory.\u00a0 The copyright and license !\n! can be found in LICENSE.txt in the head directory of this repository. \u00a0\u00a0!\n!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++!\nPROGRAM testExtendedMath\n#include \"UnitTest.h\"\nUSE UnitTest\nUSE IntrType\nUSE Constants_Conversion\nUSE ExtendedMath\n\nIMPLICIT NONE\n\nCREATE_TEST('EXTENDED MATH')\n\nREGISTER_SUBTEST('Gamma Function',testGammaF)\nREGISTER_SUBTEST('Rational Fraction',testRatFrac)\nREGISTER_SUBTEST('GCD',testGCD)\nREGISTER_SUBTEST('GCD',testLCM)\nREGISTER_SUBTEST('ATAN2PI',testATAN2PI)\n\nFINALIZE_TEST()\n!\n!===============================================================================\nCONTAINS\n!\n!-------------------------------------------------------------------------------\nSUBROUTINE testGammaF()\n\n ASSERT_SOFTEQ(GAMMAF(0.25_SRK),3.6256099082219083119_SRK,1.0E-12_SRK, 'GammaF 0.25')\n ASSERT_SOFTEQ(GAMMAF(0.5_SRK), 1.7724538509055160273_SRK,1.0E-12_SRK, 'GammaF 0.5')\n ASSERT_SOFTEQ(GAMMAF(0.75_SRK),1.2254167024651776451_SRK,1.0E-12_SRK, 'GammaF 0.75')\n ASSERT_SOFTEQ(GAMMAF(3.5_SRK), 3.3233509704478425512_SRK,1.0E-12_SRK, 'GammaF 3.5')\n ASSERT_SOFTEQ(GAMMAF(5.00_SRK),24.00000000000000000_SRK ,1.0E-12_SRK, 'GammaF 5.0')\n ASSERT_SOFTEQ(GAMMAF(7.00_SRK),720.00000000000000000_SRK,1.0E-10_SRK, 'GammaF 7.0')\nENDSUBROUTINE testGammaF\n!\n!-------------------------------------------------------------------------------\nSUBROUTINE testRatFrac()\n INTEGER(SIK) :: i,N,D\n REAL(SRK) :: dif,tol\n\n CALL Rational_Fraction(1.5_SRK,1.0E-12_SRK,N,D)\n ASSERT_EQ(N , 3, 'RatFrac 1.5 num')\n ASSERT_EQ(D , 2, 'RatFrac 1.5 denom')\n\n CALL Rational_Fraction(12.8125_SRK,1.0E-12_SRK,N,D)\n ASSERT_EQ(N , 205, 'RatFrac 12.8125 num')\n ASSERT_EQ(D , 16, 'RatFrac 12.8125 denom')\n\n ! Values of coefficients checked against wikipedia:\n ! http://en.wikipedia.org/wiki/Continued_fraction\n ! pi: [3;7,15,1,292,1,1,1,2,1,3,1,\u2026].\n ! by truncating at 1e-12, the series should be [3;7,15,1,292,1,1,1,2,1]\n ! which is 1146408 / 364913 from hand calc\n CALL Rational_Fraction(3.141592653589793_SRK,1.0E-12_SRK,N,D)\n ASSERT_EQ(N , 1146408, 'RatFrac PI num')\n ASSERT_EQ(D , 364913, 'RatFrac PI denom')\n\n ! Values of coefficients checked againt wikipedia:\n ! sqrt(19): [4;2,1,3,1,2,8,2,1,3,1,2,8,\u2026] series repeats every 6\n ! by truncating to 1e-8 the series should be [4;2,1,3,1,2,8,2,1,3]\n ! which is 16311 / 3742 from hand calc\n CALL Rational_Fraction(SQRT(19.0_SRK),1.0E-8_SRK,N,D)\n ASSERT_EQ(N , 16311, 'RatFrac SQRT(19) num')\n ASSERT_EQ(D , 3742, 'RatFrac SQRT(19) denom')\n\n ! Checking a range of tolerances to ensure it is working correctly\n ! sqrt(2): [1;2,2,2,...] according to wikipedia. 2 the repeats forever\n ! This is also the slowest converging rational fraction\n DO i=1,12\n tol=10.0_SRK**(-REAL(i,SRK))\n CALL Rational_Fraction(SQRT(2.0_SRK),tol,N,D)\n dif=ABS(REAL(N,SRK)/REAL(D,SRK)/SQRT(2.0_SRK) - 1.0_SRK)\n ASSERT_LE(dif,tol, 'tolerance check')\n ENDDO\n\nENDSUBROUTINE testRatFrac\n!\n!-------------------------------------------------------------------------------\nSUBROUTINE testGCD()\n ! test error conditions (passing negative or 0 values)\n ASSERT_EQ(GreatestCommonDivisor(-1,5),0, 'GCD errors')\n ASSERT_EQ(GreatestCommonDivisor(5,-5),0, 'GCD errors')\n ASSERT_EQ(GreatestCommonDivisor(-1,-5),0, 'GCD errors')\n ASSERT_EQ(GreatestCommonDivisor(0,5),0, 'GCD errors')\n ASSERT_EQ(GreatestCommonDivisor(5,0),0, 'GCD errors')\n\n ASSERT_EQ(GreatestCommonDivisor(2,3),1, 'GCD 2,3')\n ASSERT_EQ(GreatestCommonDivisor(3,2),1, 'GCD 3,2') ! ensure both directions give same answer\n ASSERT_EQ(GreatestCommonDivisor(201,3),3, 'GCD 201,3')\n ASSERT_EQ(GreatestCommonDivisor(33,198),33, 'GCD 33,198')\n ASSERT_EQ(GreatestCommonDivisor(6248,3784),88, 'GCD 6248,3784')\nENDSUBROUTINE testGCD\n!\n!-------------------------------------------------------------------------------\nSUBROUTINE testLCM()\n ASSERT_EQ(LeastCommonMultiple(-1,5),5, 'LCM')\n ASSERT_EQ(LeastCommonMultiple(5,-5),5, 'LCM')\n ASSERT_EQ(LeastCommonMultiple(-1,-5),5, 'LCM')\n ASSERT_EQ(LeastCommonMultiple(0,5),0, 'LCM')\n ASSERT_EQ(LeastCommonMultiple(5,0),0, 'LCM')\n\n ASSERT_EQ(LeastCommonMultiple(2,3),6, 'LCM')\n ASSERT_EQ(LeastCommonMultiple(3,2),6, 'LCM')\n ASSERT_EQ(LeastCommonMultiple(201,3),201, 'LCM')\n ASSERT_EQ(LeastCommonMultiple(33,198),198, 'LCM')\n ASSERT_EQ(LeastCommonMultiple(8,12),24, 'LCM')\n ASSERT_EQ(LeastCommonMultiple(36,8),72, 'LCM')\n\n ASSERT_EQ(LeastCommonMultiple((/8,12,36/)),72,\"LCM array\")\n ASSERT_EQ(LeastCommonMultiple((/3,25,28/)),2100,\"LCM array\")\n ASSERT_EQ(LeastCommonMultiple((/12,15,75,10/)),300,\"LCM array\")\n ASSERT_EQ(LeastCommonMultiple((/100,1000,50,200,25/)),1000,\"LCM array\")\n ASSERT_EQ(LeastCommonMultiple((/100,1000,50,200,24/)),3000,\"LCM array\")\n ASSERT_EQ(LeastCommonMultiple((/198,150,24,205,87,200,154/)),164795400,\"LCM array\")\nENDSUBROUTINE testLCM\n!\n!-------------------------------------------------------------------------------\nSUBROUTINE testATAN2PI()\n ASSERT_APPROXEQ(ATAN2PI(0.0_SRK,0.0_SRK) , 0.0_SRK,'(0,0)')\n\n ASSERT_APPROXEQ(ATAN2PI(1.0_SRK,0.0_SRK) , 0.0_SRK,'(1,0)')\n ASSERT_APPROXEQ(ATAN2PI(0.0_SRK,1.0_SRK) , PI*0.5_SRK,'(0,1)')\n ASSERT_APPROXEQ(ATAN2PI(-1.0_SRK,0.0_SRK) , PI,'(-1,0)')\n ASSERT_APPROXEQ(ATAN2PI(0.0_SRK,-1.0_SRK) , PI*1.5_SRK,'(0,-1)')\n ASSERT_APPROXEQ(ATAN2PI(1.0_SRK,1.0_SRK) , PI*0.25_SRK,'(1,1)')\n ASSERT_APPROXEQ(ATAN2PI(-1.0_SRK,1.0_SRK) , PI*0.75_SRK,'(-1,1)')\n ASSERT_APPROXEQ(ATAN2PI(-1.0_SRK,-1.0_SRK) , PI*1.25_SRK,'(-1,-1)')\n ASSERT_APPROXEQ(ATAN2PI(1.0_SRK,-1.0_SRK) , PI*1.75_SRK,'(1,-1)')\n\n ASSERT_APPROXEQ(ATAN2PI(1.0_SRK,-EPSREAL) , 0.0_SRK,'(1.0,-EPS)')\n ASSERT_APPROXEQ(ATAN2PI(1.0_SRK,EPSREAL) , 0.0_SRK,'(1.0,+EPS)')\n ASSERT_APPROXEQ(ATAN2PI(-EPSREAL,1.0_SRK) , PI*0.5_SRK,'(-EPS,1.0)')\n ASSERT_APPROXEQ(ATAN2PI(EPSREAL,1.0_SRK) , PI*0.5_SRK,'(+EPS,1.0)')\n ASSERT_APPROXEQ(ATAN2PI(EPSREAL,EPSREAL) , 0.0_SRK,'(+EPS,+EPS)')\n ASSERT_APPROXEQ(ATAN2PI(-EPSREAL,EPSREAL) , 0.0_SRK,'(-EPS,+EPS)')\n ASSERT_APPROXEQ(ATAN2PI(EPSREAL,-EPSREAL) , 0.0_SRK,'(+EPS,-EPS)')\n ASSERT_APPROXEQ(ATAN2PI(-EPSREAL,-EPSREAL) , 0.0_SRK,'(-EPS,-EPS)')\nENDSUBROUTINE testATAN2PI\n!\n!-------------------------------------------------------------------------------\nFUNCTION oldATAN2PI(x,y) RESULT(theta)\n REAL(SRK),INTENT(IN) :: x,y\n REAL(SRK) :: theta\n theta=atan2(y,x)\n IF(theta < 0) theta=2.0_SRK*PI+theta\nENDFUNCTION oldATAN2PI\n!\nENDPROGRAM testExtendedMath\n", "meta": {"hexsha": "c6356473d6c2a29465d3dfe6d591f477f2612367", "size": 6882, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "unit_tests/testExtendedMath/testExtendedMath.f90", "max_stars_repo_name": "wgurecky/Futility", "max_stars_repo_head_hexsha": "cd7831395c7c56adcbbc5be38773d2e850c6b5b6", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "unit_tests/testExtendedMath/testExtendedMath.f90", "max_issues_repo_name": "wgurecky/Futility", "max_issues_repo_head_hexsha": "cd7831395c7c56adcbbc5be38773d2e850c6b5b6", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-10-22T20:53:29.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-22T20:53:29.000Z", "max_forks_repo_path": "unit_tests/testExtendedMath/testExtendedMath.f90", "max_forks_repo_name": "wgurecky/Futility", "max_forks_repo_head_hexsha": "cd7831395c7c56adcbbc5be38773d2e850c6b5b6", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.4, "max_line_length": 95, "alphanum_fraction": 0.6253995931, "num_tokens": 2480, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933359135362, "lm_q2_score": 0.795658090372256, "lm_q1q2_score": 0.6523547659619028}} {"text": "! Evalute C_p (thermal conductivity as function of temperature based on correlation\n! C_p units - cal/(mol*K) , 1 cal = 4.184 J\n\n! Correlation is of the form C_p(T) = a + b*T where a, b are constants\n! Currently using FliNaK correlation from Rogers (1982)\n! Valid between 748 - 863 K\n! Input:\n! T - temperature to evaluate density at in Kelvin \n! Output:\n! C_p - evaluated conductivity at T\n! \nsubroutine cond_corr(T, C_p)\n\n USE global_parameters_M\n\n implicit none\n\n!---Dummy\n real(dp), intent(in) :: T\n real(dp), intent(out) :: C_p \n\n!---Local\n real(dp) :: a\n real(dp) :: b \n \n a = 9.636_dp \n b = 10.487_dp\n C_p = a + b*T\n\nend\n", "meta": {"hexsha": "e2cceb064ccb69ecacb3c20c85d349322020f50d", "size": 672, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/cond_corr.f90", "max_stars_repo_name": "ZanderUF/ANL_ptkin", "max_stars_repo_head_hexsha": "cd094a51b8349879968cc4c395928643c6c51411", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-13T06:00:47.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-13T06:00:47.000Z", "max_issues_repo_path": "src/cond_corr.f90", "max_issues_repo_name": "ZanderUF/ANL_ptkin", "max_issues_repo_head_hexsha": "cd094a51b8349879968cc4c395928643c6c51411", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2018-09-14T15:27:30.000Z", "max_issues_repo_issues_event_max_datetime": "2020-01-19T20:23:09.000Z", "max_forks_repo_path": "src/cond_corr.f90", "max_forks_repo_name": "ZanderUF/ANL_ptkin", "max_forks_repo_head_hexsha": "cd094a51b8349879968cc4c395928643c6c51411", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-02T10:26:31.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-02T10:26:31.000Z", "avg_line_length": 21.6774193548, "max_line_length": 83, "alphanum_fraction": 0.6294642857, "num_tokens": 206, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418199787564, "lm_q2_score": 0.7057850216484838, "lm_q1q2_score": 0.6522454544199758}} {"text": "\tREAL FUNCTION TCUM(T,RDF)\r\nC\r\nC-Description-----------------------------------------------------------\r\n\tIMPLICIT NONE\r\nC\r\nC Function:\r\nC\tCalculate the probability that a t statistic with RDF degrees\r\nC\tof freedom is <= T.\r\nC Arguments:\r\nC\tT\t(Real)\r\nC\t\tT STATISTIC\r\nC\tRDF\t(Real)\r\nC\t\tDEGREES OF FREEDOM\r\nC Notes:\r\nC .\tReference:\r\nC\t\"Student's t-Distribution\", _Collected Algorithms\r\nC\tfrom CACM_, vol II, Algorithm 344, 1980.\r\nC\r\nC-Declarations----------------------------------------------------------\r\nC\r\nC\r\nC Arguments\r\nC\r\n REAL T,RDF\r\nC\r\nC Locals\r\nC\r\n\tINTEGER DF1,DF2,DF\r\n\tREAL TCUM1,TCUM2,TCUMFCN\r\nC\r\nC-Code------------------------------------------------------------------\r\nC\r\nC If degrees of freedom is less than 10 then do the calculation in\r\nC two steps.\r\nC\r\n\tIF (RDF.LT.10) THEN\r\n\t DF1=INT(RDF)\r\n\t DF2=DF1+1\r\n\t TCUM1=TCUMFCN(T,DF1)\r\n\t TCUM2=TCUMFCN(T,DF2)\r\n\t TCUM=TCUM1*(DF2-RDF) + TCUM2*(RDF-DF1)\r\n\tELSE\r\nC\r\nC If degrees of freedom >=10 then do the calculation directly.\r\nC\r\n\t DF=NINT(RDF)\r\n\t TCUM=TCUMFCN(T,DF)\r\n\tEND IF\r\n\r\n\tRETURN\r\n\tEND", "meta": {"hexsha": "2b74dfefd243aaae2b3f66b9e6e259e13a14d188", "size": 1091, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "misc/old_ps/ps-development-version/psDll/tcum.for", "max_stars_repo_name": "vubiostat/ps", "max_stars_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2017-12-29T14:19:14.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-06T15:08:46.000Z", "max_issues_repo_path": "misc/old_ps/ps-development-version/psDll/tcum.for", "max_issues_repo_name": "vubiostat/ps", "max_issues_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2020-04-30T16:57:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-07T00:26:02.000Z", "max_forks_repo_path": "misc/old_ps/ps-development-version/psDll/tcum.for", "max_forks_repo_name": "vubiostat/ps", "max_forks_repo_head_hexsha": "0ac136d449256b8bf4ebfc6311654db5d7a01321", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-07T20:11:54.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-11T19:18:59.000Z", "avg_line_length": 21.3921568627, "max_line_length": 73, "alphanum_fraction": 0.5417048579, "num_tokens": 342, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087965937712, "lm_q2_score": 0.7025300573952052, "lm_q1q2_score": 0.6522350851572355}} {"text": " SUBROUTINE FD01AD( JP, L, LAMBDA, XIN, YIN, EFOR, XF, EPSBCK,\n $ CTETA, STETA, YQ, EPOS, EOUT, SALPH, IWARN,\n $ INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To solve the least-squares filtering problem recursively in time.\nC Each subroutine call implements one time update of the solution.\nC The algorithm uses a fast QR-decomposition based approach.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC JP CHARACTER*1\nC Indicates whether the user wishes to apply both prediction\nC and filtering parts, as follows:\nC = 'B': Both prediction and filtering parts are to be\nC applied;\nC = 'P': Only the prediction section is to be applied.\nC\nC Input/Output Parameters\nC\nC L (input) INTEGER\nC The length of the impulse response of the equivalent\nC transversal filter model. L >= 1.\nC\nC LAMBDA (input) DOUBLE PRECISION\nC Square root of the forgetting factor.\nC For tracking capabilities and exponentially stable error\nC propagation, LAMBDA < 1.0 (strict inequality) should\nC be used. 0.0 < LAMBDA <= 1.0.\nC\nC XIN (input) DOUBLE PRECISION\nC The input sample at instant n.\nC (The situation just before and just after the call of\nC the routine are denoted by instant (n-1) and instant n,\nC respectively.)\nC\nC YIN (input) DOUBLE PRECISION\nC If JP = 'B', then YIN must contain the reference sample\nC at instant n.\nC Otherwise, YIN is not referenced.\nC\nC EFOR (input/output) DOUBLE PRECISION\nC On entry, this parameter must contain the square root of\nC exponentially weighted forward prediction error energy\nC at instant (n-1). EFOR >= 0.0.\nC On exit, this parameter contains the square root of the\nC exponentially weighted forward prediction error energy\nC at instant n.\nC\nC XF (input/output) DOUBLE PRECISION array, dimension (L)\nC On entry, this array must contain the transformed forward\nC prediction variables at instant (n-1).\nC On exit, this array contains the transformed forward\nC prediction variables at instant n.\nC\nC EPSBCK (input/output) DOUBLE PRECISION array, dimension (L+1)\nC On entry, the leading L elements of this array must\nC contain the normalized a posteriori backward prediction\nC error residuals of orders zero through L-1, respectively,\nC at instant (n-1), and EPSBCK(L+1) must contain the\nC square-root of the so-called \"conversion factor\" at\nC instant (n-1).\nC On exit, this array contains the normalized a posteriori\nC backward prediction error residuals, plus the square root\nC of the conversion factor at instant n.\nC\nC CTETA (input/output) DOUBLE PRECISION array, dimension (L)\nC On entry, this array must contain the cosines of the\nC rotation angles used in time updates, at instant (n-1).\nC On exit, this array contains the cosines of the rotation\nC angles at instant n.\nC\nC STETA (input/output) DOUBLE PRECISION array, dimension (L)\nC On entry, this array must contain the sines of the\nC rotation angles used in time updates, at instant (n-1).\nC On exit, this array contains the sines of the rotation\nC angles at instant n.\nC\nC YQ (input/output) DOUBLE PRECISION array, dimension (L)\nC On entry, if JP = 'B', then this array must contain the\nC orthogonally transformed reference vector at instant\nC (n-1). These elements are also the tap multipliers of an\nC equivalent normalized lattice least-squares filter.\nC Otherwise, YQ is not referenced and can be supplied as\nC a dummy array (i.e., declare this array to be YQ(1) in\nC the calling program).\nC On exit, if JP = 'B', then this array contains the\nC orthogonally transformed reference vector at instant n.\nC\nC EPOS (output) DOUBLE PRECISION\nC The a posteriori forward prediction error residual.\nC\nC EOUT (output) DOUBLE PRECISION\nC If JP = 'B', then EOUT contains the a posteriori output\nC error residual from the least-squares filter at instant n.\nC\nC SALPH (output) DOUBLE PRECISION array, dimension (L)\nC The element SALPH(i), i=1,...,L, contains the opposite of\nC the i-(th) reflection coefficient for the least-squares\nC normalized lattice predictor (whose value is -SALPH(i)).\nC\nC Warning Indicator\nC\nC IWARN INTEGER\nC = 0: no warning;\nC = 1: an element to be annihilated by a rotation is less\nC than the machine precision (see LAPACK Library\nC routine DLAMCH).\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value.\nC\nC METHOD\nC\nC The output error EOUT at instant n, denoted by EOUT(n), is the\nC reference sample minus a linear combination of L successive input\nC samples:\nC\nC L-1\nC EOUT(n) = YIN(n) - SUM h_i * XIN(n-i),\nC i=0\nC\nC where YIN(n) and XIN(n) are the scalar samples at instant n.\nC A least-squares filter uses those h_0,...,h_{L-1} which minimize\nC an exponentially weighted sum of successive output errors squared:\nC\nC n\nC SUM [LAMBDA**(2(n-k)) * EOUT(k)**2].\nC k=1\nC\nC Each subroutine call performs a time update of the least-squares\nC filter using a fast least-squares algorithm derived from a\nC QR decomposition, as described in references [1] and [2] (the\nC notation from [2] is followed in the naming of the arrays).\nC The algorithm does not compute the parameters h_0,...,h_{L-1} from\nC the above formula, but instead furnishes the parameters of an\nC equivalent normalized least-squares lattice filter, which are\nC available from the arrays SALPH (reflection coefficients) and YQ\nC (tap multipliers), as well as the exponentially weighted input\nC signal energy\nC\nC n L\nC SUM [LAMBDA**(2(n-k)) * XIN(k)**2] = EFOR**2 + SUM XF(i)**2.\nC k=1 i=1\nC\nC For more details on reflection coefficients and tap multipliers,\nC references [2] and [4] are recommended.\nC\nC REFERENCES\nC\nC [1] Proudler, I. K., McWhirter, J. G., and Shepherd, T. J.\nC Fast QRD based algorithms for least-squares linear\nC prediction.\nC Proceedings IMA Conf. Mathematics in Signal Processing\nC Warwick, UK, December 1988.\nC\nC [2] Regalia, P. A., and Bellanger, M. G.\nC On the duality between QR methods and lattice methods in\nC least-squares adaptive filtering.\nC IEEE Trans. Signal Processing, SP-39, pp. 879-891,\nC April 1991.\nC\nC [3] Regalia, P. A.\nC Numerical stability properties of a QR-based fast\nC least-squares algorithm.\nC IEEE Trans. Signal Processing, SP-41, June 1993.\nC\nC [4] Lev-Ari, H., Kailath, T., and Cioffi, J.\nC Least-squares adaptive lattice and transversal filters:\nC A unified geometric theory.\nC IEEE Trans. Information Theory, IT-30, pp. 222-236,\nC March 1984.\nC\nC NUMERICAL ASPECTS\nC\nC The algorithm requires O(L) operations for each subroutine call.\nC It is backward consistent for all input sequences XIN, and\nC backward stable for persistently exciting input sequences,\nC assuming LAMBDA < 1.0 (see [3]).\nC If the condition of the signal is very poor (IWARN = 1), then the\nC results are not guaranteed to be reliable.\nC\nC FURTHER COMMENTS\nC\nC 1. For tracking capabilities and exponentially stable error\nC propagation, LAMBDA < 1.0 should be used. LAMBDA is typically\nC chosen slightly less than 1.0 so that \"past\" data are\nC exponentially forgotten.\nC 2. Prior to the first subroutine call, the variables must be\nC initialized. The following initial values are recommended:\nC\nC XF(i) = 0.0, i=1,...,L\nC EPSBCK(i) = 0.0 i=1,...,L\nC EPSBCK(L+1) = 1.0\nC CTETA(i) = 1.0 i=1,...,L\nC STETA(i) = 0.0 i=1,...,L\nC YQ(i) = 0.0 i=1,...,L\nC\nC EFOR = 0.0 (exact start)\nC EFOR = \"small positive constant\" (soft start).\nC\nC Soft starts are numerically more reliable, but result in a\nC biased least-squares solution during the first few iterations.\nC This bias decays exponentially fast provided LAMBDA < 1.0.\nC If sigma is the standard deviation of the input sequence\nC XIN, then initializing EFOR = sigma*1.0E-02 usually works\nC well.\nC\nC CONTRIBUTOR\nC\nC P. A. Regalia (October 1994).\nC Release 4.0: V. Sima, Katholieke Univ. Leuven, Belgium, Dec. 1999.\nC\nC REVISIONS\nC\nC -\nC\nC KEYWORDS\nC\nC Kalman filtering, least-squares estimator, optimal filtering,\nC orthogonal transformation, recursive estimation, QR decomposition.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ONE, ZERO\n PARAMETER ( ONE = 1.0D0, ZERO = 0.0D0 )\nC .. Scalar Arguments ..\n CHARACTER JP\n INTEGER INFO, IWARN, L\n DOUBLE PRECISION EFOR, EOUT, EPOS, LAMBDA, XIN, YIN\nC .. Array Arguments ..\n DOUBLE PRECISION CTETA(*), EPSBCK(*), SALPH(*), STETA(*), XF(*),\n $ YQ(*)\nC .. Local Scalars ..\n LOGICAL BOTH\n INTEGER I\n DOUBLE PRECISION CTEMP, EPS, FNODE, NORM, TEMP, XFI, YQI\nC .. External Functions ..\n LOGICAL LSAME\n DOUBLE PRECISION DLAMCH, DLAPY2, DNRM2\n EXTERNAL DLAMCH, DLAPY2, DNRM2, LSAME\nC .. External Subroutines ..\n EXTERNAL DLARTG, XERBLA\nC .. Intrinsic Functions\n INTRINSIC ABS, SQRT\nC .. Executable statements ..\nC\nC Test the input scalar arguments.\nC\n BOTH = LSAME( JP, 'B' )\n IWARN = 0\n INFO = 0\nC\n IF( .NOT.BOTH .AND. .NOT.LSAME( JP, 'P' ) ) THEN\n INFO = -1\n ELSE IF( L.LT.1 ) THEN\n INFO = -2\n ELSE IF( ( LAMBDA.LE.ZERO ) .OR. ( LAMBDA.GT.ONE ) ) THEN\n INFO = -3\n END IF\nC\n IF ( INFO.NE.0 ) THEN\nC\nC Error return.\nC\n CALL XERBLA( 'FD01AD', -INFO )\n RETURN\n END IF\nC\nC Computation of the machine precision EPS.\nC\n EPS = DLAMCH( 'Epsilon' )\nC\nC Forward prediction rotations.\nC\n FNODE = XIN\nC\n DO 10 I = 1, L\n XFI = XF(I) * LAMBDA\n XF(I) = STETA(I) * FNODE + CTETA(I) * XFI\n FNODE = CTETA(I) * FNODE - STETA(I) * XFI\n 10 CONTINUE\nC\n EPOS = FNODE * EPSBCK(L+1)\nC\nC Update the square root of the prediction energy.\nC\n EFOR = EFOR * LAMBDA\n TEMP = DLAPY2( FNODE, EFOR )\n IF ( TEMP.LT.EPS ) THEN\n FNODE = ZERO\n IWARN = 1\n ELSE\n FNODE = FNODE * EPSBCK(L+1)/TEMP\n END IF\n EFOR = TEMP\nC\nC Calculate the reflection coefficients and the backward prediction\nC errors.\nC\n DO 20 I = L, 1, -1\n IF ( ABS( XF(I) ).LT.EPS )\n $ IWARN = 1\n CALL DLARTG( TEMP, XF(I), CTEMP, SALPH(I), NORM )\n EPSBCK(I+1) = CTEMP * EPSBCK(I) - SALPH(I) * FNODE\n FNODE = CTEMP * FNODE + SALPH(I) * EPSBCK(I)\n TEMP = NORM\n 20 CONTINUE\nC\n EPSBCK(1) = FNODE\nC\nC Update to new rotation angles.\nC\n NORM = DNRM2( L, EPSBCK, 1 )\n TEMP = SQRT( ( ONE + NORM )*( ONE - NORM ) )\n EPSBCK(L+1) = TEMP\nC\n DO 30 I = L, 1, -1\n IF ( ABS( EPSBCK(I) ).LT.EPS )\n $ IWARN = 1\n CALL DLARTG( TEMP, EPSBCK(I), CTETA(I), STETA(I), NORM )\n TEMP = NORM\n 30 CONTINUE\nC\nC Joint process section.\nC\n IF ( BOTH) THEN\n FNODE = YIN\nC\n DO 40 I = 1, L\n YQI = YQ(I) * LAMBDA\n YQ(I) = STETA(I) * FNODE + CTETA(I) * YQI\n FNODE = CTETA(I) * FNODE - STETA(I) * YQI\n 40 CONTINUE\nC\n EOUT = FNODE * EPSBCK(L+1)\n END IF\nC\n RETURN\nC *** Last line of FD01AD ***\n END\n", "meta": {"hexsha": "e728e41f9f51ad4dbdc08fe782f33d3970005323", "size": 12779, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/FD01AD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/FD01AD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/FD01AD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 36.0988700565, "max_line_length": 72, "alphanum_fraction": 0.5883871977, "num_tokens": 3571, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541561135441, "lm_q2_score": 0.6926419831347361, "lm_q1q2_score": 0.6522292021175515}} {"text": " PROGRAM xcholsl\r\nC driver for routine cholsl\r\n INTEGER N\r\n PARAMETER (N=3)\r\n INTEGER i,j,k\r\n REAL sum,a(N,N),aorig(N,N),atest(N,N),chol(N,N),p(N),b(N),x(N)\r\n DATA a/100.,15.,.01,15.,2.3,.01,.01,.01,1./\r\n DATA b/.4,.02,99./\r\n do 12 i=1,N\r\n do 11 j=1,N\r\n aorig(i,j)=a(i,j)\r\n11 continue\r\n12 continue\r\n call choldc(a,N,N,p)\r\n do 14 i=1,N\r\n do 13 j=1,N\r\n if (i.gt.j) then\r\n chol(i,j)=a(i,j)\r\n else if (i.eq.j) then\r\n chol(i,j)=p(i)\r\n else\r\n chol(i,j)=0.\r\n endif\r\n13 continue\r\n14 continue\r\n do 17 i=1,N\r\n do 16 j=1,N\r\n sum=0.\r\n do 15 k=1,N\r\n sum=sum+chol(i,k)*chol(j,k)\r\n15 continue\r\n atest(i,j)=sum\r\n16 continue\r\n17 continue\r\n write(*,*) 'Original matrix:'\r\n write(*,100) ((aorig(i,j),j=1,N),i=1,N)\r\n write(*,*)\r\n write(*,*) 'Product of Cholesky factors:'\r\n write(*,100) ((atest(i,j),j=1,N),i=1,N)\r\n100 format(1p3e16.6)\r\n write(*,*)\r\n call cholsl(a,N,N,p,b,x)\r\n do 19 i=1,N\r\n sum=0.\r\n do 18 j=1,N\r\n sum=sum+aorig(i,j)*x(j)\r\n18 continue\r\n p(i)=sum\r\n19 continue\r\n write(*,*) 'Check solution vector:'\r\n write(*,101) (p(i),b(i),i=1,N)\r\n101 format(1p2e16.6)\r\n END\r\n", "meta": {"hexsha": "fc305b476def7d56c6ea6363ed6434087e4213bc", "size": 1380, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xcholsl.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xcholsl.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xcholsl.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.5555555556, "max_line_length": 69, "alphanum_fraction": 0.4456521739, "num_tokens": 481, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772417253255, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.6521831179062183}} {"text": "!\n! Copyright (C) 2001-2010 Quantum ESPRESSO group\n! This file is distributed under the terms of the\n! GNU General Public License. See the file `License'\n! in the root directory of the present distribution,\n! or http://www.gnu.org/copyleft/gpl.txt .\n!\n!-----------------------------------------------------------------------\nSUBROUTINE rgen ( dtau, rmax, mxr, at, bg, r, r2, nrm)\n !-----------------------------------------------------------------------\n !\n ! generates neighbours shells (cartesian, in units of lattice parameter)\n ! with length < rmax,and returns them in order of increasing length:\n ! r(:) = i*a1(:) + j*a2(:) + k*a3(:) - dtau(:), r2 = r^2\n ! where a1, a2, a3 are primitive lattice vectors. Other input variables:\n ! mxr = maximum number of vectors\n ! at = lattice vectors ( a1=at(:,1), a2=at(:,2), a3=at(:,3) )\n ! bg = reciprocal lattice vectors ( b1=bg(:,1), b2=bg(:,2), b3=bg(:,3) )\n ! Other output variables:\n ! nrm = the number of vectors with r^2 < rmax^2\n !\n USE kinds, ONLY : DP\n !\n IMPLICIT NONE\n INTEGER, INTENT(in) :: mxr\n INTEGER, INTENT(out):: nrm\n REAL(DP), INTENT(in) :: at(3,3), bg(3,3), dtau(3), rmax\n REAL(DP), INTENT(out):: r(3,mxr), r2(mxr)\n !\n ! and here the local variables\n !\n INTEGER, ALLOCATABLE :: irr (:)\n INTEGER :: nm1, nm2, nm3, i, j, k, ipol, ir, indsw, iswap\n real(DP) :: ds(3), dtau0(3)\n real(DP) :: t (3), tt, swap\n real(DP), EXTERNAL :: dnrm2\n !\n !\n nrm = 0\n IF (rmax==0.d0) RETURN\n\n ! bring dtau into the unit cell centered on the origin - prevents trouble\n ! if atomic positions are not centered around the origin but displaced\n ! far away (remember that translational invariance allows this!)\n !\n ds(:) = matmul( dtau(:), bg(:,:) )\n ds(:) = ds(:) - anint(ds(:))\n dtau0(:) = matmul( at(:,:), ds(:) )\n !\n ALLOCATE (irr( mxr))\n !\n ! these are estimates of the maximum values of needed integer indices\n !\n nm1 = int (dnrm2 (3, bg (1, 1), 1) * rmax) + 2\n nm2 = int (dnrm2 (3, bg (1, 2), 1) * rmax) + 2\n nm3 = int (dnrm2 (3, bg (1, 3), 1) * rmax) + 2\n !\n DO i = -nm1, nm1\n DO j = -nm2, nm2\n DO k = -nm3, nm3\n tt = 0.d0\n DO ipol = 1, 3\n t (ipol) = i*at (ipol, 1) + j*at (ipol, 2) + k*at (ipol, 3) &\n - dtau0(ipol)\n tt = tt + t (ipol) * t (ipol)\n ENDDO\n IF (tt<=rmax**2.and.abs (tt) >1.d-10) THEN\n nrm = nrm + 1\n IF (nrm>mxr) CALL errore ('rgen', 'too many r-vectors', nrm)\n DO ipol = 1, 3\n r (ipol, nrm) = t (ipol)\n ENDDO\n r2 (nrm) = tt\n ENDIF\n ENDDO\n ENDDO\n ENDDO\n !\n ! reorder the vectors in order of increasing magnitude\n !\n ! initialize the index inside sorting routine\n !\n irr (1) = 0\n IF (nrm>1) CALL hpsort (nrm, r2, irr)\n DO ir = 1, nrm - 1\n20 indsw = irr (ir)\n IF (indsw/=ir) THEN\n DO ipol = 1, 3\n swap = r (ipol, indsw)\n r (ipol, indsw) = r (ipol, irr (indsw) )\n r (ipol, irr (indsw) ) = swap\n ENDDO\n iswap = irr (ir)\n irr (ir) = irr (indsw)\n irr (indsw) = iswap\n GOTO 20\n ENDIF\n\n ENDDO\n DEALLOCATE(irr)\n !\n RETURN\nEND SUBROUTINE rgen\n\n", "meta": {"hexsha": "a1271910e14ec02fcc1ec315a7758680e4c08bac", "size": 3281, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/apps/miniDFT/tests/src/rgen.f90", "max_stars_repo_name": "utdsimmons/ohpc", "max_stars_repo_head_hexsha": "70dc728926a835ba049ddd3f4627ef08db7c95a0", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 692, "max_stars_repo_stars_event_min_datetime": "2015-11-12T13:56:43.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T03:45:59.000Z", "max_issues_repo_path": "tests/apps/miniDFT/tests/src/rgen.f90", "max_issues_repo_name": "utdsimmons/ohpc", "max_issues_repo_head_hexsha": "70dc728926a835ba049ddd3f4627ef08db7c95a0", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1096, "max_issues_repo_issues_event_min_datetime": "2015-11-12T09:08:22.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:48:41.000Z", "max_forks_repo_path": "tests/apps/miniDFT/tests/src/rgen.f90", "max_forks_repo_name": "utdsimmons/ohpc", "max_forks_repo_head_hexsha": "70dc728926a835ba049ddd3f4627ef08db7c95a0", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 224, "max_forks_repo_forks_event_min_datetime": "2015-11-12T21:17:03.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T00:57:48.000Z", "avg_line_length": 31.2476190476, "max_line_length": 79, "alphanum_fraction": 0.515696434, "num_tokens": 1171, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772318846386, "lm_q2_score": 0.7461389986757757, "lm_q1q2_score": 0.652183110563698}} {"text": " implicit double precision (a-h,o-z)\n complex*8 ylm\n character*1 aal,aam\n common /alegp/ alp(0:100,-100:100)\n common /factl/ fact(0:100)\n dimension ylm(0:100,0:100)\n pi=4.0d0*datan(1.0d0)\n read(*,*)lmax\n call factorial(2*lmax)\n ifno=0\n do l=0,lmax\n write(aal,'(i1)')l \n do m=0,l\n write(aam,'(i1)')m \n ifno=ifno+1\n open(ifno,file='y'//aal//aam//'r.out',status='unknown')\n ifno=ifno+1\n open(ifno,file='y'//aal//aam//'i.out',status='unknown')\n end do\n end do\n theta=0.d0\n ainc=pi/10.d0\n do while (theta.le.pi)\n x=dcos(theta)\n call alegendrep(lmax,x)\n phi=0.d0\n do while (phi.le.2.0*pi)\n xx=dsin(theta)*dcos(phi)\n yy=dsin(theta)*dsin(phi)\n ifno=0\n do l=0,lmax\n do m=0,l\n fac=dsqrt((2*l+1)*fact(l-m)/(4.0d0*pi*fact(l+m)))\n ylm(l,m)=fac*alp(l,m)*dcmplx(dcos(m*phi),dsin(m*phi))\n ifno=ifno+1\n rr=dreal(ylm(l,m))\n write(ifno,'(1x,3f12.6)') rr*xx,rr*yy,rr*dcos(theta)\n ifno=ifno+1\n rr=imag(ylm(l,m))\n write(ifno,'(1x,3f12.6)') rr*xx,rr*yy,rr*dcos(theta)\n end do\n end do\n phi=phi+ainc\n end do\n theta=theta+ainc\n end do\n\n end\n\nc Calculates assosicated Legendre polynomials upto lmax for a given x\nc -1 < x < 1; Condon-Shortley phase is included\nc i/p lmax, x\nc o/p alp(0:lmax,-lmax:lmax)\n subroutine alegendrep(lmax,x)\n implicit real*8 (a-h,o-z)\n common /alegp/ alp(0:100,-100:100)\n common /factl/ fact(0:100)\n alp(0,0)=1.0d0\n do l=1,lmax\n alp(l,l-1)=x*(2.0d0*(l-1.0d0)+1.0d0)*alp(l-1,l-1)\n alp(l,-l+1)=(-1)**(l-1)*alp(l,l-1)/fact(l+l-1) !m=l-1\n alp(l,l)=-(2.0d0*(l-1.0d0)+1.0d0)*dsqrt(1.d0-x*x)*alp(l-1,l-1)\n alp(l,-l)=(-1)**l*alp(l,l)/fact(l+l)\n do m=l-2,1,-1\n alp(l,m)=(x*(2*l-1)*alp(l-1,m)-(l+m-1)*alp(l-2,m))/dfloat(l-m)\n alp(l,-m)=(-1)**m*fact(l-m)*alp(l,m)/fact(l+m)\n end do\n alp(l,0)=(x*(2*l-1)*alp(l-1,0)-(l-1)*alp(l-2,0))/dfloat(l)\n end do\n end\n\n\nc Calculates and stores 0!,1!,2!,...,n!\nc i/p n\nc o/p fact(0:n)\n subroutine factorial(n)\n implicit double precision (a-h,o-z)\n common /factl/ fact(0:100)\n fact(0)=1\n do i=1,n\n fact(i)=fact(i-1)*i\n end do\n end\n", "meta": {"hexsha": "f4c38d000ec5b1c834e4cf09d467a0efcdf8e7b4", "size": 2478, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "aru/spha.for", "max_stars_repo_name": "deadbeatfour/phn624-comp-nuc-phy", "max_stars_repo_head_hexsha": "deaeaac5240a1f33425c4ca50539aee4fae2f370", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "aru/spha.for", "max_issues_repo_name": "deadbeatfour/phn624-comp-nuc-phy", "max_issues_repo_head_hexsha": "deaeaac5240a1f33425c4ca50539aee4fae2f370", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "aru/spha.for", "max_forks_repo_name": "deadbeatfour/phn624-comp-nuc-phy", "max_forks_repo_head_hexsha": "deaeaac5240a1f33425c4ca50539aee4fae2f370", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.5, "max_line_length": 72, "alphanum_fraction": 0.4943502825, "num_tokens": 984, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772417253256, "lm_q2_score": 0.7461389817407016, "lm_q1q2_score": 0.6521831031036556}} {"text": "***********************************************************************\n*\t COORD_VH2VJ.F\n***********************************************************************\n* PURPOSE: Converts from Heliocentric to Jacobi coords. VELOCITIES ONLY.\n* ARGUMENTS: Input is \n* nbod ==> number of objects (must be less than NBMAX)\n* (integer)\n*\t mass(*) ==> planetary masses (real array)\n*\t\t vxh(*),vyh(*),vzh(*) ==>barycentric particle velocities\n* (real array)\n* Returned are\n* vxj(*),vyj(*),vzj(*) ==> jacobi. particle velocities\n* (real array)\n* \n* ALGORITHM: See my notes Nov 21/92 \n* REMARKS: \n* \n* AUTHOR: M. Duncan.\n* DATE WRITTEN: Jan 29, 1993.\n* REVISIONS: 2/17/93 HFL\n\n\tsubroutine coord_vh2vj(nbod,mass,vxh,vyh,vzh,vxj,vyj,vzj)\n\n\n include '../swift.inc'\n\nc... Inputs: \n\tinteger nbod\n\treal*8 mass(NPLMAX)\n\treal*8 vxh(NPLMAX),vyh(NPLMAX),vzh(NPLMAX)\n\nc... Outputs:\n\treal*8 vxj(NPLMAX),vyj(NPLMAX),vzj(NPLMAX)\n\nc... Internals:\n\treal*8 eta(NPLMAX)\n\treal*8 sumvx,sumvy,sumvz\t\n\treal*8 capvx,capvy,capvz\n\tinteger n\n\nc----\nc... Executable code \n\nc First calc. the array eta(*) then convert to jacobi velocities\n\n\teta(1) = mass(1)\n\tdo n = 2,nbod\n\t eta(n) = eta(n-1) + mass(n)\n\tenddo\n\n\tvxj(1) =0.d0\n\tvyj(1) =0.d0\n\tvzj(1) =0.d0\n\n\tvxj(2) = vxh(2)\n\tvyj(2) = vyh(2)\n\tvzj(2) = vzh(2)\n\n\tsumvx = mass(2)*vxh(2)\n\tsumvy = mass(2)*vyh(2)\n\tsumvz = mass(2)*vzh(2)\n\n\tcapvx = sumvx/eta(2)\n\tcapvy = sumvy/eta(2)\n\tcapvz = sumvz/eta(2)\n\n\tdo n=3,nbod\n\t vxj(n) = vxh(n) - capvx\n\t vyj(n) = vyh(n) - capvy\n\t vzj(n) = vzh(n) - capvz\n\n\t if(n.lt.nbod) then\n sumvx = sumvx + mass(n)*vxh(n)\n sumvy = sumvy + mass(n)*vyh(n)\n sumvz = sumvz + mass(n)*vzh(n)\n\n capvx =sumvx/eta(n)\n capvy =sumvy/eta(n)\n capvz =sumvz/eta(n)\n endif\n\n\tenddo\n\n123\treturn\n\tend ! coord_vh2vj\nc--------------------------------------------------------------------------\n", "meta": {"hexsha": "ea80a5fd3bbd4e8b6d1e4f8453abb952285bc1c5", "size": 2147, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "source/swift_j/coord/coord_vh2vj.f", "max_stars_repo_name": "Simske/exostriker", "max_stars_repo_head_hexsha": "587b0af4c9cadb46637a4ac61a5392a596e966b1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 69, "max_stars_repo_stars_event_min_datetime": "2020-01-06T13:31:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T11:23:14.000Z", "max_issues_repo_path": "exostriker/source/swift_j/coord/coord_vh2vj.f", "max_issues_repo_name": "sai-33/Exostriker", "max_issues_repo_head_hexsha": "f59fa51c6bdce3a2ed51d6621fe42bfcd8c2846f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 67, "max_issues_repo_issues_event_min_datetime": "2019-11-30T14:45:05.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-14T20:26:06.000Z", "max_forks_repo_path": "exostriker/source/swift_j/coord/coord_vh2vj.f", "max_forks_repo_name": "sai-33/Exostriker", "max_forks_repo_head_hexsha": "f59fa51c6bdce3a2ed51d6621fe42bfcd8c2846f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2020-01-06T13:44:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T11:23:17.000Z", "avg_line_length": 24.6781609195, "max_line_length": 76, "alphanum_fraction": 0.4685607825, "num_tokens": 704, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772253241802, "lm_q2_score": 0.746138993030751, "lm_q1q2_score": 0.6521831007344967}} {"text": " INTEGER N,m\n PARAMETER(N=4,m=100000) ! N = Number od differential equation, m = Number of divisions between x1 and x2\n INTEGER:: i\n!\t complex::al,be\n\n\t REAL h,x,y(N),dydx(N),yout(N)\n EXTERNAL derivs\n open(10,file='e:\\1\\JC_Model_Psi.txt') ! Output program results\n ! -------------- initial conditons --------------\n x1=0.0 ! x1 = t1\n\t x2=30 ! x2 = t2\n y(1)=1/sqrt(2.) ! real part of c1(t):= y(1) + iy(2)\n y(2)=0 ! complex part of c1(t):= y(1) + iy(2)\n y(3)=1/sqrt(2.) ! real part of c2(t):= y(3) + iy(4)\n y(4)=0 ! complex part of c2(t):= y(3) + iy(4)\n\n\t x=x1\n\t h=(x2-x1)/m ! Number of divisions\n do i=0,m-1\n\t x=x1+i*h\n call derivs(x,y,dydx)\n call rk4(y,dydx,N,x,h,yout,derivs)\n x=x1+i*h\n A=y(1)*y(1)+y(2)*y(2) ! |c1(t)|^2\n B=y(3)*y(3)+y(4)*y(4) ! |c2(t)|^2\n rho_a_2_11 = A * A\n rho_a_2_22 = B * B\n tr_r_2 = rho_a_2_11 + rho_a_2_22 ! trace (rho_a) ^ 2 \n U = A * A\n O = B * B\n S= -((B*LOG(B)/LOG(2.))+(A*LOG(A)/LOG(2.))) ! Von Neumann entropy\n G= 2*(1-U-O) ! G = L (Linear entropy)\n C = SQRT(G) !Concurence\n if (mod(i,10)==0) then\n write(10,'(22(f10.4,2x))')x,y(1),y(2),y(3),y(4),tr_r_2,S,G ! Computational values to create in the file a.txt\n end if\n\t do j=1,n\n\t y(j)=yout(j) !/sqrt((r11+r22))\n\t end do\n end do\n\n END\n\n\n SUBROUTINE derivs(x,y,dydx)\n \n REAL x,y(N),dydx(N)\n \n ! ------------------- State --------------------\n \n ! psi(t) = c1(t)|e,n> + c2(t)|g,n+1>\n \n ! --------------- initial values --------------- \n \n\n\t wa=1 ! atomic frequency \n\t wp=0.6 ! field frequency\n\t g=0.6 ! coupling strength \n n = 1 ! number of photons\n \n ! ----------------- Equations ------------------ \n \n \n A = n*wp+(wa/2)\n B = (1+n)*wp-(wa/2)\n X = n+1\n C = SQRT(X)\n ! print*, A\n \n ! ----------- Differential equations -----------\n \n\n dydx(1)= A*y(2)+g*C*y(4)\n dydx(2)= -A*y(1)-g*C*y(3)\n dydx(3)= B*y(4)+g*C*y(2)\n dydx(4)= -B*y(3)-g*C*y(1)\n\n\n return\n \n end\n\n ! ------------ Runge-Kutta Function ------------\n \n SUBROUTINE rk4(y,dydx,n,x,h,yout,derivs)\n INTEGER n,NMAX\n REAL h,x,dydx(n),y(n),yout(n)\n EXTERNAL derivs\n PARAMETER (NMAX=50)\n INTEGER i\n REAL h6,hh,xh,dym(NMAX),dyt(NMAX),yt(NMAX)\n hh=h*0.5\n h6=h/6.\n\t x=0\n xh=x+hh\n do 11 i=1,n\n yt(i)=y(i)+hh*dydx(i)\n11 continue\n call derivs(xh,yt,dyt)\n do 12 i=1,n\n yt(i)=y(i)+hh*dyt(i)\n12 continue\n call derivs(xh,yt,dym)\n do 13 i=1,n\n yt(i)=y(i)+h*dym(i)\n dym(i)=dyt(i)+dym(i)\n13 continue\n call derivs(x+h,yt,dyt)\n do 14 i=1,n\n yout(i)=y(i)+h6*(dydx(i)+dyt(i)+2.*dym(i))\n\n14 continue\n return\n END\n", "meta": {"hexsha": "3a1c3b915a778f2edb56e1c7c555e174cbfaaee4", "size": 3202, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "Fortran/for psi/JC_Model_Psi.for", "max_stars_repo_name": "Mahdi-Asadi/python_thesis", "max_stars_repo_head_hexsha": "6cb1dbe24fcf9133e971e64c91e1dde234250da9", "max_stars_repo_licenses": ["MIT"], "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/for psi/JC_Model_Psi.for", "max_issues_repo_name": "Mahdi-Asadi/python_thesis", "max_issues_repo_head_hexsha": "6cb1dbe24fcf9133e971e64c91e1dde234250da9", "max_issues_repo_licenses": ["MIT"], "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/for psi/JC_Model_Psi.for", "max_forks_repo_name": "Mahdi-Asadi/python_thesis", "max_forks_repo_head_hexsha": "6cb1dbe24fcf9133e971e64c91e1dde234250da9", "max_forks_repo_licenses": ["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.8434782609, "max_line_length": 125, "alphanum_fraction": 0.4075577764, "num_tokens": 1138, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044095, "lm_q2_score": 0.7461389873857264, "lm_q1q2_score": 0.6521830982478162}} {"text": "Program PoissonMultigrid\nUse MultiGrid, only : AddFourierMode\nUse IO, only : Textual_Output\nUse MultiGrid, only : Restrict_1D, Prolongate_1D\n\nImplicit None\n\nReal, parameter :: w = (2.0/3.0)\n\nInteger, parameter :: N = 64\nInteger, parameter :: fd = 12\n\nInteger :: t, i, device\nInteger :: nsteps = 5\n\nReal, allocatable, dimension(:), codimension[*] :: V1h, V2h, V4h, V8h, V16h, Buf\n\ndevice = get_subimage(0)\n\nAllocate(V1h(-1:N+1)[*])\nAllocate(Buf(-1:N+1)[*])\nAllocate(V2h(-1:N/2+1)[*])\nAllocate(V4h(-1:N/4+1)[*])\nAllocate(V8h(-1:N/8+1)[*])\nAllocate(V16h(-1:N/16+1)[*])\n\nif (device /= THIS_IMAGE()) then\n Allocate(V1h(-1:N+1)[*]) [[device]]\n Allocate(Buf(-1:N+1)[*]) [[device]]\n Allocate(V2h(-1:N/2+1)[*]) [[device]]\n Allocate(V4h(-1:N/4+1)[*]) [[device]]\n Allocate(V8h(-1:N/8+1)[*]) [[device]]\n Allocate(V16h(-1:N/16+1)[*])[[device]]\nend if\n\nopen(unit=fd, file=\"error_time.dat\")\n\n!! Initialize\n!\nV1h = 0.0\nCall AddFourierMode(N, V1h, 1)\nCall AddFourierMode(N, V1h, 6)\nCall AddFourierMode(N, V1h, 16)\nV1h = (1./3.)*V1h\n\nV1h[device] = V1h\n\n!... Relax solution on 1h mesh\n! -------------------------\ncall Textual_Output(N, V1h, \"1h_0\")\ndo t = 1, nsteps\n call Relax_1D(N, V1h[device], Buf[device]) [[device]]\n call Exchange_Halo_1D(device, N, V1h)\nend do\nV1h = V1h[device]\nwrite(fd, *) t, maxval(V1h)\ncall Textual_Output(N, V1h, \"1h_mid\")\n\n!... Relax solution on 2h mesh\n! -------------------------\ncall Restrict_1D(N, V1h[device], V2h[device]) [[device]]\ncall Textual_Output(N/2, V2h, \"2h_0\")\ndo t = 1, nsteps\n call Relax_1D(N/2, V2h[device], Buf[device]) [[device]]\n call Exchange_Halo_1D(device, N/2, V2h)\nend do\nV2h = V2h[device]\nwrite(fd, *) t, maxval(V2h)\ncall Textual_Output(N/2, V2h, \"2h_mid\")\n\n!... Relax solution on 4h mesh\n! -------------------------\ncall Restrict_1D(N/2, V2h[device], V4h[device]) [[device]]\ncall Textual_Output(N/4, V4h, \"4h_0\")\ndo t = 1, nsteps\n call Relax_1D(N/4, V4h[device], Buf[device]) [[device]]\n call Exchange_Halo_1D(device, N/4, V4h)\nend do\nV4h = V4h[device]\nwrite(fd, *) t, maxval(V4h)\ncall Textual_Output(N/4, V4h, \"4h_mid\")\n\n!... Relax solution on 8h mesh\n! -------------------------\ncall Restrict_1D(N/4, V4h[device], V8h[device]) [[device]]\ncall Textual_Output(N/8, V8h, \"8h_0\")\ndo t = 1, nsteps\n call Relax_1D(N/8, V8h[device], Buf[device]) [[device]]\n call Exchange_Halo_1D(device, N/8, V8h)\nend do\nV8h = V8h[device]\nwrite(fd, *) t, maxval(V8h)\ncall Textual_Output(N/8, V8h, \"8h_mid\")\n\n!! IMPORTANT: this last step should be an exact solution on a smaller grid probably\n!\n! exact solution is 0, so just set to 0.\nV16h = 0\n\nV16h[device] = V16h\ncall Prolongate_1D(N/8, V8h[device], V16h[device]) [[device]]\ndo t = 1, nsteps\n call Relax_1D(N/8, V8h[device], Buf[device]) [[device]]\n call Exchange_Halo_1D(device, N/8, V8h)\nend do\nV8h = V8h[device]\nwrite(fd, *) t, maxval(V8h)\ncall Textual_Output(N/8, V8h, \"8h_end\")\n\ncall Prolongate_1D(N/4, V4h[device], V8h[device]) [[device]]\ndo t = 1, nsteps\n call Relax_1D(N/4, V4h[device], Buf[device]) [[device]]\n call Exchange_Halo_1D(device, N/4, V4h)\nend do\nV4h = V4h[device]\nwrite(fd, *) t, maxval(V4h)\ncall Textual_Output(N/4, V4h, \"4h_end\")\n\ncall Prolongate_1D(N/2, V2h[device], V4h[device]) [[device]]\ndo t = 1, nsteps\n call Relax_1D(N/2, V2h[device], Buf[device]) [[device]]\n call Exchange_Halo_1D(device, N/2, V2h)\nend do\nV2h = V2h[device]\nwrite(fd, *) t, maxval(V2h)\ncall Textual_Output(N/2, V2h, \"2h_end\")\n\ncall Prolongate_1D(N, V1h[device], V2h[device]) [[device]]\ndo t = 1, nsteps\n call Relax_1D(N, V1h[device], Buf[device]) [[device]]\n call Exchange_Halo_1D(device, N, V1h)\nend do\nV1h = V1h[device]\nwrite(fd, *) t, maxval(V1h)\ncall Textual_Output(N, V1h, \"1h_end\")\n\nclose(fd)\n\nEnd Program PoissonMultigrid\n", "meta": {"hexsha": "6dc1cb4eb7e35d53f48a9ed8800fb05e7fd68bc7", "size": 3800, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "LOPe/trans/testfile.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": "LOPe/trans/testfile.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": "LOPe/trans/testfile.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": 27.1428571429, "max_line_length": 83, "alphanum_fraction": 0.6376315789, "num_tokens": 1544, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936879, "lm_q2_score": 0.7690802423634963, "lm_q1q2_score": 0.6521552432199302}} {"text": "program problem61\n implicit none\n integer, dimension(6) :: numbers,polygonal\n logical :: success\n\n success=.false.\n call search(1)\n print *, numbers, polygonal\n print *, sum(numbers)\n\ncontains\n\n recursive subroutine search(depth)\n use euler\n implicit none\n integer, intent(in) :: depth\n integer :: i,start,fin\n\n if (depth>6 .and. (mod(numbers(6),100) == numbers(1)/100)) success=.true.\n\n if (depth==1) then\n start=1010\n fin=9999\n else\n start=mod(numbers(depth-1),100)*100+10\n fin=mod(numbers(depth-1),100)*100+99\n end if\n\n do i=start,fin\n if (success) return\n numbers(depth)=i\n if (is_triangular(i) .and. (.not. any(polygonal(1:depth)==3))) then\n polygonal(depth)=3\n call search(depth+1)\n else if (is_square(i) .and. (.not. any(polygonal(1:depth)==4))) then\n polygonal(depth)=4\n call search(depth+1)\n else if (is_pentagonal(i) .and. (.not. any(polygonal(1:depth)==5))) then\n polygonal(depth)=5\n call search(depth+1)\n else if (is_hexagonal(i) .and. (.not. any(polygonal(1:depth)==6))) then\n polygonal(depth)=6\n call search(depth+1)\n else if (is_heptagonal(i) .and. (.not. any(polygonal(1:depth)==7))) then\n polygonal(depth)=7\n call search(depth+1)\n else if (is_octagonal(i) .and. (.not. any(polygonal(1:depth)==8))) then\n polygonal(depth)=8\n call search(depth+1)\n end if\n end do\n\n end subroutine search\n\nend program problem61\n", "meta": {"hexsha": "ff1ee4b8905873e92cf1322906a1622b1a93f89d", "size": 1576, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "problem61.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": "problem61.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": "problem61.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": 28.1428571429, "max_line_length": 79, "alphanum_fraction": 0.586928934, "num_tokens": 462, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934408, "lm_q2_score": 0.7490872243177518, "lm_q1q2_score": 0.6521532862605749}} {"text": "MODULE my_random\nIMPLICIT NONE\nSAVE\n INTEGER, PARAMETER :: A = 8121, B = 28411, C = 134456\n INTEGER :: rand_int\n REAL :: rand_real\n\nEND MODULE my_random\n\nPROGRAM random_test\nUSE my_random\nIMPLICIT NONE\n INTEGER :: i\n rand_int = 1\n DO i = 1, 10\n CALL rando\n WRITE(*, 100) rand_real\n 100 FORMAT (F10.4)\n END DO\nEND PROGRAM random_test\n\nSUBROUTINE rando\nUSE my_random\nIMPLICIT NONE\n rand_int = MOD(A * rand_int + B, C)\n rand_real = REAL(rand_int) / REAL(C)\n\nEND SUBROUTINE rando\n", "meta": {"hexsha": "ea06a489a8f716bd35e50a2804f7fe3d72b08ead", "size": 494, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap7/random_test.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/random_test.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/random_test.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": 17.0344827586, "max_line_length": 55, "alphanum_fraction": 0.7004048583, "num_tokens": 166, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934406, "lm_q2_score": 0.7490872075132152, "lm_q1q2_score": 0.6521532716305913}} {"text": " real function getz(pval,nt,vr,cdf,zmin,zmax,ltail,ltpar,\n + utail,utpar)\nc-----------------------------------------------------------------------\nc\nc Back Transform Univariate Data from Normal Scores\nc *************************************************\nc\nc This subroutine backtransforms a standard normal deviate from a\nc specified back transform table and option for the tails of the\nc distribution. Call once with \"first\" set to true then set to false\nc unless one of the options for the tail changes.\nc\nc\nc\nc INPUT VARIABLES:\nc\nc pval probability value to use\nc nt number of values in the back transform tbale\nc vr(nt) original data values that were transformed\nc cdf(nt) the corresponding transformed values\nc zmin,zmax limits possibly used for linear or power model\nc ltail option to handle values less than cdf(1)\nc ltpar parameter required for option ltail\nc utail option to handle values greater than cdf(nt)\nc utpar parameter required for option utail\nc\nc\nc\nc-----------------------------------------------------------------------\n\n implicit integer (i-n)\n implicit double precision (a-h,o-z)\n\n parameter(EPSLON=1.0e-20)\n dimension vr(nt),cdf(nt)\n real*8 ltpar,utpar,lambda\n integer ltail,utail\nc\nc Value in the lower tail? 1=linear, 2=power, (3 and 4 are invalid):\nc\n if(pval.le.cdf(1)) then\n getz = vr(1)\n if(ltail.eq.1) then\n getz = powint(0.d0,cdf(1),zmin,vr(1),pval,1.0)\n else if(ltail.eq.2) then\n cpow = 1.0 / ltpar\n getz = powint(0.d0,cdf(1),zmin,vr(1),pval,cpow)\n endif\nc\nc Value in the upper tail? 1=linear, 2=power, 4=hyperbolic:\nc\n else if(pval.ge.cdf(nt)) then\n cdfhi = cdf(nt)\n getz = vr(nt)\n if(utail.eq.1) then\n getz = powint(cdfhi,1.0,vr(nt),zmax,pval,1.0)\n else if(utail.eq.2) then\n cpow = 1.0 / utpar\n getz = powint(cdfhi,1.0,vr(nt),zmax,pval,cpow)\n else if(utail.eq.4) then\n lambda = (vr(nt)**utpar)*(1.0-cdf(nt))\n getz = (lambda/(1.0-pval))**(1.0/utpar)\n endif\n else\nc\nc Value within the transformation table:\nc\n call locate(cdf,nt,1,nt,pval,j)\n j = max(min((nt-1),j),1)\n getz = powint(cdf(j),cdf(j+1),vr(j),vr(j+1),pval,1.0)\n endif\n if(getz.lt.zmin) getz = zmin\n if(getz.gt.zmax) getz = zmax\n return\n end\n", "meta": {"hexsha": "75c31613abac2012eb91530eb37f0077633772a9", "size": 2693, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Src/Extern/gslib/getz.f", "max_stars_repo_name": "memmett/BoxLib", "max_stars_repo_head_hexsha": "a235af87d30cbfc721d4d7eb4da9b8daadeded7d", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 79, "max_stars_repo_stars_event_min_datetime": "2015-08-03T18:29:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-15T11:42:40.000Z", "max_issues_repo_path": "Src/Extern/gslib/getz.f", "max_issues_repo_name": "memmett/BoxLib", "max_issues_repo_head_hexsha": "a235af87d30cbfc721d4d7eb4da9b8daadeded7d", "max_issues_repo_licenses": ["BSD-3-Clause-LBNL"], "max_issues_count": 22, "max_issues_repo_issues_event_min_datetime": "2016-06-15T20:46:49.000Z", "max_issues_repo_issues_event_max_datetime": "2018-09-10T21:33:10.000Z", "max_forks_repo_path": "Src/Extern/gslib/getz.f", "max_forks_repo_name": "memmett/BoxLib", "max_forks_repo_head_hexsha": "a235af87d30cbfc721d4d7eb4da9b8daadeded7d", "max_forks_repo_licenses": ["BSD-3-Clause-LBNL"], "max_forks_count": 48, "max_forks_repo_forks_event_min_datetime": "2015-08-05T02:19:33.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-18T12:33:14.000Z", "avg_line_length": 35.4342105263, "max_line_length": 72, "alphanum_fraction": 0.5198663201, "num_tokens": 769, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476793890012, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.652112686510299}} {"text": "!-------------------------------------------------------------\n! Gives the upper limit as determined by a sphere in a fixed\n! position: R^2=x^2+y^2+(z-H)^2.\n!-------------------------------------------------------------\n FUNCTION SphereBottom( Model, n, t ) RESULT(f)\n USE DefUtils\n IMPLICIT NONE\n\n TYPE(Model_t) :: Model\n INTEGER :: n\n REAL(KIND=dp) :: t,f\n!-------------------------------------------------------------\n REAL(KIND=dp) :: x,y,z,R,Disc,H\n\n x = Model % Nodes % x(n)\n y = Model % Nodes % y(n) \n z = Model % Nodes % z(n)\n R = 3.0_dp\n \n R = ListGetCReal( Model % Simulation,'Sphere Radius')\n H = ListGetCReal( Model % Simulation,'Sphere Z')\n\n Disc = R**2 - x**2 - y**2\n IF( Disc < 0 ) THEN\n f = HUGE(f)\n ELSE\n f = H - SQRT(Disc)\n! PRINT *,'Contact:',x,y,z,H,f\n END IF\n\n END FUNCTION SphereBottom\n!-------------------------------------------------------------\n\n", "meta": {"hexsha": "0f3879bd2101ccf10573c1535b606c58c250a9ab", "size": 943, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "benchmark_apps/elmerfem/fem/tests/LimitDisplacement2/ContactBC.f90", "max_stars_repo_name": "readex-eu/readex-apps", "max_stars_repo_head_hexsha": "38493b11806c306f4e8f1b7b2d97764b45fac8e2", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-11-25T13:10:11.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-15T20:26:35.000Z", "max_issues_repo_path": "elmerfem/fem/tests/LimitDisplacement2/ContactBC.f90", "max_issues_repo_name": "jcmcmurry/pipelining", "max_issues_repo_head_hexsha": "8fface1a501b5050f58e7b902aacdcdde68e9648", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "elmerfem/fem/tests/LimitDisplacement2/ContactBC.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": 27.7352941176, "max_line_length": 62, "alphanum_fraction": 0.4050901379, "num_tokens": 246, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767810736693, "lm_q2_score": 0.7431680199891789, "lm_q1q2_score": 0.652112681976997}} {"text": "SUBROUTINE fill_missing_levs(nx,ny,nz,plevs,data,missval,method)\n\n! Subroutine to fill in missing values in a 3D data array on\n! pressure levels. This routine assumes you have valid data\n! on the top most and bottom most levels.\n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: nx\n INTEGER, INTENT(IN) :: ny\n INTEGER, INTENT(IN) :: nz\n REAL, INTENT(IN) :: plevs(75) ! Press in Pa\n REAL, INTENT(INOUT) :: data(nx,ny,nz)\n REAL, INTENT(IN) :: missval\n INTEGER, INTENT(IN) :: method\n\n INTEGER, PARAMETER :: METHOD_LIN = 1\n INTEGER, PARAMETER :: METHOD_LOG = 2\n\n INTEGER :: k,kbot,ktop\n REAL :: weight_top, weight_bot\n LOGICAL :: goodlev(nz) \n\n goodlev(:) = .false.\n checklevs: DO k = 1,nz\n IF (MAXVAL(data(:,:,k)) .NE. missval) THEN\n goodlev(k) = .true.\n ENDIF\n ENDDO checklevs\n\n fixlevs: DO k = 1, nz\n IF (goodlev(k)) CYCLE fixlevs\n \n ! Else:\n\n ! Find first level below that is \"good\"\n find_kbot: DO kbot = k-1,1,-1\n IF (goodlev(kbot)) EXIT find_kbot\n ENDDO find_kbot\n\n ! Find first level above that is good\n find_ktop: DO ktop = k+1,nz\n IF (goodlev(ktop)) EXIT find_ktop\n ENDDO find_ktop\n\n ! Compute interp weights using plevs and method\n IF (method .EQ. METHOD_LIN) THEN \n ! Linear interp in Pressure\n weight_bot = (plevs(k)-plevs(ktop)) / &\n (plevs(kbot)-plevs(ktop))\n weight_top = 1. - weight_bot\n ELSE IF (method .EQ. METHOD_LOG) THEN\n ! Linear in ln(P)\n weight_bot = ( ALOG(plevs(k)/plevs(ktop)) ) / &\n ( ALOG(plevs(kbot)/plevs(ktop)) )\n weight_top = 1. - weight_bot \n ENDIF\n data(:,:,k) = weight_bot*data(:,:,kbot) + weight_top*data(:,:,ktop)\n ENDDO fixlevs\n RETURN\nEND SUBROUTINE fill_missing_levs\n", "meta": {"hexsha": "282d7f3762922d25196ad64fef5b373fa4a0785d", "size": 1987, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/wfoprep/fill_missing_levs.f90", "max_stars_repo_name": "maxinye/laps-mirror", "max_stars_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_stars_repo_licenses": ["Intel", "Unlicense", "OLDAP-2.2.1", "NetCDF"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2019-04-05T12:28:22.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-29T06:37:29.000Z", "max_issues_repo_path": "src/wfoprep/fill_missing_levs.f90", "max_issues_repo_name": "longwosion/laps-mirror", "max_issues_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_issues_repo_licenses": ["Intel", "NetCDF", "OLDAP-2.2.1", "Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/wfoprep/fill_missing_levs.f90", "max_forks_repo_name": "longwosion/laps-mirror", "max_forks_repo_head_hexsha": "b3f7c08273299a9e19b2187f96bd3eee6e0aa01b", "max_forks_repo_licenses": ["Intel", "NetCDF", "OLDAP-2.2.1", "Unlicense"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-04-27T12:51:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-19T13:57:44.000Z", "avg_line_length": 32.5737704918, "max_line_length": 71, "alphanum_fraction": 0.5535983895, "num_tokens": 588, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6521126817479511}} {"text": "! File flaplace95_forall.f90\n! Author: Ramon Crehuet\nsubroutine timestep(u,n,m,dx,dy,error)\nimplicit none\nreal (kind=8), dimension(0:n-1,0:m-1), intent(inout):: u\n\nreal (kind=8), intent(in) :: dx,dy\nreal (kind=8), intent(out) :: error\ninteger, intent(in) :: n,m\nreal (kind=8), dimension(0:n-1,0:m-1) :: diff\nreal (kind=8) :: dx2,dy2,dnr_inv\ninteger :: i,j\n\n!f2py intent(in) :: dx,dy\n!f2py intent(in,out) :: u\n!f2py intent(out) :: error\n!f2py intent(hide) :: n,m\n\ndx2 = dx*dx\ndy2 = dy*dy\ndnr_inv = 0.5d0 / (dx2+dy2)\n\ndiff=u\n\nforall (i=1:n-2,j=1:m-2)\n u(i,j) = ((u(i-1,j) + u(i+1,j))*dy2+(u(i,j-1) + u(i,j+1))*dx2)*dnr_inv\nend forall\n\nerror=sqrt(sum((u-diff)**2))\n\nend subroutine\n", "meta": {"hexsha": "c6711dc35fc94fa9f76858f88a84e1d808c487c2", "size": 681, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "doc/perfpy/src/flaplace95_forall.f95", "max_stars_repo_name": "srossross/Clyther", "max_stars_repo_head_hexsha": "3540952ef2da2dbbc55bc71bee9b34c43a058edb", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2015-02-02T21:47:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-28T04:18:47.000Z", "max_issues_repo_path": "doc/perfpy/src/flaplace95_forall.f95", "max_issues_repo_name": "srossross/Clyther", "max_issues_repo_head_hexsha": "3540952ef2da2dbbc55bc71bee9b34c43a058edb", "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": "doc/perfpy/src/flaplace95_forall.f95", "max_forks_repo_name": "srossross/Clyther", "max_forks_repo_head_hexsha": "3540952ef2da2dbbc55bc71bee9b34c43a058edb", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-03-21T17:54:33.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-06T22:22:17.000Z", "avg_line_length": 21.28125, "max_line_length": 74, "alphanum_fraction": 0.6284875184, "num_tokens": 289, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476800298183, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6521126812898581}} {"text": "!================================================================================\n! CONSTRUCCION DE UNA CONFIGURACION INICIAL REGULAR EN CELDA BIDIMENSIONAL\n! SIN TRASLAPES\n! Autor: Martin Paredes Sosa\n!================================================================================\n\nSubroutine ConfigIni(N3)\n Use cte\n Implicit None\n Real :: xRan, yRan, xij, yij, dist\n Real :: dBoxl\n Integer :: i, j, k ,l !CONTADOR\n Integer :: N2, N3\n Real, Dimension(:),Allocatable :: nX, nY, nZ !GEN\n \n !CALCULANDO DIMENSIONES DE LA CAJA\n N2 =anint( N**(Dim) ) \n BoxL = (1.0*N/Dens )**(Dim)\n N3 = N2**(1.0/Dim)\n Write(*,*) \"LONGITUD DE LA CELDA:\", BoxL\n Write(*,*) \"TOTAL DE PARTICULAS EN LA CELDA COLOCADAS:\", N3\n dBoxl = BoxL/N2\n\n\n Allocate( nX(N2), nY(N2), nZ(N2) , X(N3), Y(N3), z(N3) )\n \n !GENERANDO COORDENADAS PARA POSICIONES DE LAS PARTICULAS\n GEN: Do i=1, N2 \n\n nx(i) = (-BoxL)/2.0 + dBoxL/2.0 + dBoxL*(i-1)\n ny(i) = (-BoxL)/2.0 + dBoxL/2.0 + dBoxL*(i-1)\n nz(i) = (-BoxL)/2.0 + dBoxL/2.0 + dBoxL*(i-1) \n End Do GEN\n\n !ESCRIBIENDO EN ARCHIVO\n Open (1, File = \"ConIni.dat\" ) \n l = 0 \n EscribirX: Do i = 1, N2\n \n EscribirY: Do j = 1, N2\n\n EscribirZ: Do k = 1, N2\n \n l = l + 1\n X(l) = nX(i)\n Y(l) = nY(j)\n Z(l) = nZ(k)\n \n End Do EscribirZ\n \n End Do EscribirY\n \n End Do EscribirX\n \n !Write(*,*) l !DEBUG\n\n Do i=1, N3\n Write(1,*) X(i), Y(i), Z(i)\n End Do\n \n\n Deallocate(nX, nY, nZ)\n \n Close(1)\n\n\nEnd Subroutine ConfigIni\n", "meta": {"hexsha": "4e646c7ae4e9b2d339b97ed9a3cdfcfcb4c8e475", "size": 1602, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "Portafolio_II/Tarea_III/Act_5/ConfigIni.f03", "max_stars_repo_name": "maps16/DesExpII", "max_stars_repo_head_hexsha": "d9d12b445e0fe86e32fce028be4f5b8bcfd2391f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Portafolio_II/Tarea_III/Act_5/ConfigIni.f03", "max_issues_repo_name": "maps16/DesExpII", "max_issues_repo_head_hexsha": "d9d12b445e0fe86e32fce028be4f5b8bcfd2391f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Portafolio_II/Tarea_III/Act_5/ConfigIni.f03", "max_forks_repo_name": "maps16/DesExpII", "max_forks_repo_head_hexsha": "d9d12b445e0fe86e32fce028be4f5b8bcfd2391f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.5588235294, "max_line_length": 81, "alphanum_fraction": 0.4744069913, "num_tokens": 601, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.7431680086124812, "lm_q1q2_score": 0.652112676756557}} {"text": "use std\nuse FEMDomainClass\nimplicit none\n\ntype(IO_) :: f\ntype(FEMDomain_) :: domain\ntype(Math_) :: math\ncharacter(:),allocatable :: line\nreal(real64) :: x, y, r ,theta,x_sum,y_sum,center(2),max_r,coord(2), ret\nreal(real64),allocatable :: r_data(:),theta_data(:),leafSurface(:,:),tx(:),tfx(:)\ninteger(int32) :: num_ptr, i,id,ids(5),id_n\ncharacter(:),allocatable :: filename\n\n!filename = \"oak.txt\"\n!filename = \"LeafSurface.txt\"\nfilename = \"grape_leaf.txt\"\ncall f%open(filename,\"r\")\n! get brief info\nnum_ptr = 0\n\nx_sum = 0.0d0\ny_sum = 0.0d0\n\ndo \n line = f%readline()\n if(f%EOF) exit\n num_ptr = num_ptr+1\n ! read x-y\n read(line,*) x, y\n x_sum = x_sum + x\n y_sum = y_sum + y\nenddo\ncall f%close()\n\ncenter(1) = x_sum/dble(num_ptr)\ncenter(2) = y_sum/dble(num_ptr)\n\nr_data = zeros(num_ptr)\ntheta_data = zeros(num_ptr)\nleafSurface = zeros(num_ptr,2)\n\n! get detail\ncall f%open(filename,\"r\")\nnum_ptr=0\ndo \n line = f%readline()\n if(f%EOF) exit\n ! read x-y\n read(line,*) x, y\n \n coord(1) = x - center(1)\n coord(2) = y - center(2)\n r = sqrt( dot_product(coord,coord) )\n theta = angles( coord )\n\n num_ptr = num_ptr + 1\n leafSurface(num_ptr,1) = x\n leafSurface(num_ptr,2) = y\n\n r_data(num_ptr) = r\n theta_data(num_ptr) = theta \nenddo\nmax_r = maxval(r_data)\nr_data = r_data/max_r\ncall f%close()\n\n\n\n\ncall domain%create(\"Cylinder3D\",x_num=10,y_num=10)\ncall domain%resize(x=2.0d0)\ncall domain%resize(y=2.0d0)\ncall domain%resize(z=0.010d0)\n\n! ####################################\n! test interpolate\n\n\n!tx = [0.0d0, 1.0d0, 2.0d0, 3.0d0]\n!tfx = [0.0d0, 2.0d0, 4.0d0, 8.0d0]\n!ret = interpolate(x =tx,Fx=tfx,x_value = -0.50d0)\n!print *, ret\n!stop\n! ####################################\n\n! adjust shape\ndo i=1,domain%nn()\n x = domain%mesh%nodcoord(i,1)\n y = domain%mesh%nodcoord(i,2)\n r = sqrt(x**2 + y**2)\n coord(1:2) = domain%mesh%nodcoord(i,1:2)\n r = norm(coord)\n theta = angles(coord)\n ! find nearest theta\n r = r * interpolate(x=theta_data,Fx=r_data,x_value=theta)\n x = r*x\n y = r*y\n domain%mesh%nodcoord(i,1) = x \n domain%mesh%nodcoord(i,2) = y \nenddo\n\n! export data\ncall f%open(\"theta_r_relation.txt\",\"w\")\ndo i=1,size(r_data)\n call f%write(theta_data(i),r_data(i) )\nenddo\ncall f%close()\ncall f%plot(\"theta_r_relation.txt\",\"w l\")\ncall f%plot(filename,\"w l\")\n\ncall domain%vtk(\"leaf\")\n\n\n\nend", "meta": {"hexsha": "185234132cc927d7b4b8f7013aef356af1eb696e", "size": 2370, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/playon_fem/createDomainFromSurface.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/fem/createDomainFromSurface.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/fem/createDomainFromSurface.f90", "max_forks_repo_name": "kazulagi/plantFEM_binary", "max_forks_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-10-20T18:28:59.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-15T08:35:25.000Z", "avg_line_length": 20.6086956522, "max_line_length": 81, "alphanum_fraction": 0.6206751055, "num_tokens": 854, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767746654974, "lm_q2_score": 0.7431680143008301, "lm_q1q2_score": 0.6521126722232548}} {"text": "subroutine Interv ( xt, lxt, x, left, mflag )\n\n!*****************************************************************************80\n!\n!! INTERV brackets a real value in an ascending vector of values.\n!\n! Discussion:\n!\n! The XT array is a set of increasing values. The goal of the routine\n! is to determine the largest index I so that \n!\n! XT(I) < XT(LXT) and XT(I) <= X.\n!\n! The routine is designed to be efficient in the common situation\n! that it is called repeatedly, with X taken from an increasing\n! or decreasing sequence.\n!\n! This will happen when a piecewise polynomial is to be graphed.\n! The first guess for LEFT is therefore taken to be the value\n! returned at the previous call and stored in the local variable ILO.\n!\n! A first check ascertains that ILO < LXT. This is necessary\n! since the present call may have nothing to do with the previous\n! call. Then, if \n! XT(ILO) <= X < XT(ILO+1), \n! we set LEFT = ILO and are done after just three comparisons.\n!\n! Otherwise, we repeatedly double the difference ISTEP = IHI - ILO\n! while also moving ILO and IHI in the direction of X, until\n! XT(ILO) <= X < XT(IHI)\n! after which we use bisection to get, in addition, ILO + 1 = IHI.\n! The value LEFT = ILO is then returned.\n!\n! Thanks to Daniel Gloger for pointing out an important modification\n! to the routine, so that the piecewise polynomial in B-form is\n! left-continuous at the right endpoint of the basic interval,\n! 17 April 2014.\n!\n! Modified:\n!\n! 17 April 2014\n!\n! Author:\n!\n! Carl de Boor\n!\n! Reference:\n!\n! Carl de Boor,\n! A Practical Guide to Splines,\n! Springer, 2001,\n! ISBN: 0387953663,\n! LC: QA1.A647.v27.\n!\n! Parameters:\n!\n! Input, real ( kind = 8 ) XT(LXT), a nondecreasing sequence of values.\n!\n! Input, integer ( kind = 4 ) LXT, the dimension of XT.\n!\n! Input, real ( kind = 8 ) X, the point whose location with \n! respect to the sequence XT is to be determined.\n!\n! Output, integer ( kind = 4 ) LEFT, the index of the bracketing value:\n! 1 if X < XT(1)\n! I if XT(I) <= X < XT(I+1)\n! I if XT(I) < X == XT(I+1) == XT(LXT)\n!\n! Output, integer ( kind = 4 ) MFLAG, indicates whether X lies within the\n! range of the data.\n! -1: X < XT(1)\n! 0: XT(I) <= X < XT(I+1)\n! +1: XT(LXT) < X\n!\n implicit none\n\n integer ( kind = 4 ) lxt\n\n integer ( kind = 4 ) left\n integer ( kind = 4 ) mflag\n integer ( kind = 4 ) ihi\n integer ( kind = 4 ), save :: ilo = 1\n integer ( kind = 4 ) istep\n integer ( kind = 4 ) middle\n real ( kind = 8 ) x\n real ( kind = 8 ) xt(lxt)\n\n ihi = ilo + 1\n\n if ( lxt <= ihi ) then\n\n if ( xt(lxt) <= x ) then\n go to 110\n end if\n\n if ( lxt <= 1 ) then\n mflag = -1\n left = 1\n return\n end if\n\n ilo = lxt - 1\n ihi = lxt\n\n end if\n\n if ( xt(ihi) <= x ) then\n go to 20\n end if\n\n if ( xt(ilo) <= x ) then\n mflag = 0\n left = ilo\n return\n end if\n!\n! Now X < XT(ILO). Decrease ILO to capture X.\n!\n istep = 1\n\n10 continue\n\n ihi = ilo\n ilo = ihi - istep\n\n if ( 1 < ilo ) then\n if ( xt(ilo) <= x ) then\n go to 50\n end if\n istep = istep * 2\n go to 10\n end if\n\n ilo = 1\n\n if ( x < xt(1) ) then\n mflag = -1\n left = 1\n return\n end if\n\n go to 50\n!\n! Now XT(IHI) <= X. Increase IHI to capture X.\n!\n20 continue\n\n istep = 1\n\n30 continue\n\n ilo = ihi\n ihi = ilo + istep\n\n if ( ihi < lxt ) then\n\n if ( x < xt(ihi) ) then\n go to 50\n end if\n\n istep = istep * 2\n go to 30\n\n end if\n\n if ( xt(lxt) <= x ) then\n go to 110\n end if\n!\n! Now XT(ILO) < = X < XT(IHI). Narrow the interval.\n!\n ihi = lxt\n\n50 continue\n\n do\n\n middle = ( ilo + ihi ) / 2\n\n if ( middle == ilo ) then\n mflag = 0\n left = ilo\n return\n end if\n!\n! It is assumed that MIDDLE = ILO in case IHI = ILO+1.\n!\n if ( xt(middle) <= x ) then\n ilo = middle\n else\n ihi = middle\n end if\n\n end do\n!\n! Set output and return.\n!\n110 continue\n\n mflag = 1\n\n if ( x == xt(lxt) ) then\n mflag = 0\n end if\n\n do left = lxt - 1, 1, -1\n if ( xt(left) < xt(lxt) ) then\n return\n end if\n end do\n\n return\nend\n", "meta": {"hexsha": "76e8ffc6537c60b36c04675f4f4abe2d02e6185f", "size": 4251, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/ocloc/recover_timing_errors-master/SRC/Interv.f90", "max_stars_repo_name": "davidn182/ocloc", "max_stars_repo_head_hexsha": "29a2241e5b3fe45bd9b67635b35bb71a63c12235", "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/ocloc/recover_timing_errors-master/SRC/Interv.f90", "max_issues_repo_name": "davidn182/ocloc", "max_issues_repo_head_hexsha": "29a2241e5b3fe45bd9b67635b35bb71a63c12235", "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/ocloc/recover_timing_errors-master/SRC/Interv.f90", "max_forks_repo_name": "davidn182/ocloc", "max_forks_repo_head_hexsha": "29a2241e5b3fe45bd9b67635b35bb71a63c12235", "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": 19.8644859813, "max_line_length": 80, "alphanum_fraction": 0.5572806398, "num_tokens": 1462, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891479496521, "lm_q2_score": 0.7931059511841119, "lm_q1q2_score": 0.6520831062378634}} {"text": " Program dgetrf_example\n\n! DGETRF Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_example_aux, Only: nagf_file_print_matrix_real_gen\n Use lapack_interfaces, Only: dgetrf\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nin = 5, nout = 6\n! .. Local Scalars ..\n Integer :: i, ifail, info, lda, m, n\n! .. Local Arrays ..\n Real (Kind=dp), Allocatable :: a(:, :)\n Integer, Allocatable :: ipiv(:)\n! .. Intrinsic Procedures ..\n Intrinsic :: min\n! .. Executable Statements ..\n Write (nout, *) 'DGETRF Example Program Results'\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) m, n\n lda = m\n Allocate (a(lda,n), ipiv(n))\n\n! Read A from data file\n\n Read (nin, *)(a(i,1:n), i=1, m)\n\n! Factorize A\n\n Call dgetrf(m, n, a, lda, ipiv, info)\n\n! Print details of factorization\n\n Write (nout, *)\n Flush (nout)\n\n! ifail: behaviour on error exit\n! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft\n ifail = 0\n Call nagf_file_print_matrix_real_gen('General', ' ', m, n, a, lda, &\n 'Details of factorization', ifail)\n\n! Print pivot indices\n\n Write (nout, *)\n Write (nout, *) 'IPIV'\n Write (nout, 100) ipiv(1:min(m,n))\n\n If (info/=0) Then\n Write (nout, *) 'The factor U is singular'\n End If\n\n100 Format ((3X,7I11))\n End Program\n", "meta": {"hexsha": "6bd65953b403ba7f0fc4ed16f3fe7c82cf0ae09b", "size": 1693, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/dgetrf_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/dgetrf_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/dgetrf_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 26.873015873, "max_line_length": 90, "alphanum_fraction": 0.5823981099, "num_tokens": 498, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891130942474, "lm_q2_score": 0.7931059511841119, "lm_q1q2_score": 0.6520830785938344}} {"text": "! { dg-do run }\n! { dg-require-effective-target fortran_large_real }\nprogram foo\n implicit none\n integer,parameter :: k = selected_real_kind (precision (0.0_8) + 1)\n\n real(kind=k), dimension(10) :: r_k\n real(kind=k), dimension (2, 3) :: ar_k\n real(kind=k), dimension (2, 2, 3) :: br_k\n complex(kind=k), dimension(10) :: c_k\n complex(kind=k), dimension (2, 3) :: ac_k\n complex(kind=k), dimension (2, 2, 3) :: bc_k\n character (len=200) line1, line2, line3\n\n ar_k = reshape ((/1._k, 2._k, 3._k, 4._k, 5._k, 6._k/), (/2, 3/))\n br_k = spread (ar_k, 1, 2)\n if (any (br_k .ne. reshape ((/1._k, 1._k, 2._k, 2._k, 3._k, 3._k, &\n & 4._k, 4._k, 5._k, 5._k, 6._k, 6._k/), (/2, 2, 3/)))) call abort\n line1 = ' '\n write(line1, 9010) br_k\n line2 = ' '\n write(line2, 9010) spread (ar_k, 1, 2)\n if (line1 /= line2) call abort\n line3 = ' '\n write(line3, 9010) spread (ar_k, 1, 2) + 0._k\n if (line1 /= line3) call abort\n r_k = spread(1._k,1,10)\n if (any(r_k /= 1._k)) call abort\n\n ac_k = reshape ((/(1._k,-1._k), (2._k,-2._k), (3._k, -3._k), (4._k, -4._k), &\n & (5._k,-5._k), (6._k,-6._k)/), (/2, 3/))\n bc_k = spread (ac_k, 1, 2)\n if (any (real(bc_k) .ne. reshape ((/1._k, 1._k, 2._k, 2._k, 3._k, 3._k, &\n & 4._k, 4._k, 5._k, 5._k, 6._k, 6._k/), (/2, 2, 3/)))) call abort\n if (any (-aimag(bc_k) .ne. reshape ((/1._k, 1._k, 2._k, 2._k, 3._k, 3._k, &\n & 4._k, 4._k, 5._k, 5._k, 6._k, 6._k/), (/2, 2, 3/)))) call abort\n line1 = ' '\n write(line1, 9020) bc_k\n line2 = ' '\n write(line2, 9020) spread (ac_k, 1, 2)\n if (line1 /= line2) call abort\n line3 = ' '\n write(line3, 9020) spread (ac_k, 1, 2) + 0._k\n if (line1 /= line3) call abort\n c_k = spread((1._k,-1._k),1,10)\n if (any(c_k /= (1._k,-1._k))) call abort\n\n9010 format(12F7.3)\n9020 format(25F7.3)\n\nend program\n", "meta": {"hexsha": "0a91be7b599aeced6d06d8edc4aba5472d1b8844", "size": 1837, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/intrinsic_spread_2.f90", "max_stars_repo_name": "maurizioabba/rose", "max_stars_repo_head_hexsha": "7597292cf14da292bdb9a4ef573001b6c5b9b6c0", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/intrinsic_spread_2.f90", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/intrinsic_spread_2.f90", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 35.3269230769, "max_line_length": 80, "alphanum_fraction": 0.5432770822, "num_tokens": 868, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256393148982, "lm_q2_score": 0.7745833945721304, "lm_q1q2_score": 0.6520641613383877}} {"text": "SUBROUTINE throw(dice_arr, sides, ndice)\nIMPLICIT NONE\nINTEGER, DIMENSION(2), INTENT(OUT) :: dice_arr\nINTEGER, INTENT(IN) :: sides, ndice\nINTEGER :: i\n\nDO i = 1, ndice\n dice_arr(i) = die()\nEND DO\n\nCONTAINS\n INTEGER FUNCTION die()\n die = CEILING(RAND() * sides)\n END FUNCTION die\nEND SUBROUTINE throw\n\nPROGRAM dice_thrower\nIMPLICIT NONE\nINTEGER, DIMENSION(3) :: dice\nINTEGER :: i\nDO i = 1, 10\n CALL throw(dice, 12, 3)\n WRITE(*, '(3I3)') dice(1), dice(2), dice(3)\nEND DO\nEND PROGRAM dice_thrower\n", "meta": {"hexsha": "65eedfb6cbcde284cc60cf3fa48fa87d1eeba929", "size": 500, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/chap9/dice_thrower.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/dice_thrower.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/dice_thrower.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.2307692308, "max_line_length": 46, "alphanum_fraction": 0.694, "num_tokens": 174, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8418256472515684, "lm_q2_score": 0.7745833789613196, "lm_q1q2_score": 0.6520641543444198}} {"text": "module m_mt\n implicit none\n\n integer,parameter :: r_single = 4\n integer,parameter :: r_kind = kind(0.d0)\n integer,parameter :: i_kind = 4\n\n public :: EIGEN\n public :: EYE\n public :: QR\n public :: INV\n public :: RENORM\n public :: SVD\n public :: RANDN ! Guassian noise N(0,1) generateor\n\n\n interface RENORM\n module procedure RENORM1d\n module procedure RENORM2d\n endinterface\n\n interface RANDN\n module procedure RANDN1d\n module procedure RANDN2d\n endinterface\n\ncontains \n\nsubroutine EIGEN( n, A, eigvect, eigval)\n!\n! check \"dsyev\" in the LAPACK\n!\nimplicit none\n! passed args\n integer, intent(in ) :: n\n real(8),intent(in ) :: A(n,n)\n real(8),intent( out) :: eigvect(n,n)\n real(8),intent( out) :: eigval(n)\n\n! local vars\n real(8) :: r8A(n,n)\n real(8) :: r8eigvect(n,n)\n real(8) :: r8eigval(n)\n integer :: lwk\n integer,parameter :: lwkmax = 3000 \n real(8) :: wk(lwkmax)\n integer :: i, ierr\n\n ierr = 0\n r8A = REAL(A, kind(0.0d0))\n r8eigvect = 0.0d0\n r8eigval = 0.0d0\n wk = 0.0d0\n\n if ( 3*n-1 > lwkmax ) stop \"ERROR in EIGEN: increase lwkmax\"\n! get the optimal work space\n lwk = -1\n call dsyev( 'V', 'U', n, r8A, n, r8eigval, wk, lwk, ierr )\n if (ierr/=0) stop \"ERROR in EIGEN: dsyev\"\n lwk = MIN( lwkmax, INT(wk(1)) )\n! solve eigenproblem\n call dsyev( 'V', 'U', n, r8A, n, r8eigval, wk, lwk, ierr )\n if ( ierr /= 0 ) stop \"ERROR in EIGEN: dsyev\"\n! put the largest eigenvalue as the 1st column, which brings the largest variance\n do i = 1, n\n eigval(i) = r8eigval(n+1-i)\n eigvect(:,i) = r8A(:,n+1-i)\n enddo\n\nendsubroutine\n\n\n!\n! generate random 1d-array\n!\nsubroutine RANDN1d(n, A)\n implicit none\n \n integer,intent(in) :: n\n real(r_kind),intent(out) :: A(n)\n\n integer :: i\n real(r_kind) :: am\n\n do i = 1, n\n A(i) = real(rnorm(),r_kind)\n enddo\n am = sum(A(:))/n\n A(:) = A(:)-am\n\nendsubroutine\n\n!\n! random 2D-array\n!\nsubroutine RANDN2d(n,m,A)\n implicit none\n\n integer,intent(in) :: n, m\n real(r_kind),intent(out) :: A(n,m)\n\n real(r_kind) :: Am\n integer :: i, j\n\n do i = 1, n\n do j = 1, m\n A(i,j) = real(rnorm(),r_kind)\n enddo\n enddo\n Am = sum(A(:,:))/(n*m)\n A = A - Am\n\nendsubroutine\n\n!\n! SVD: A= U * S * V^t\n!\nsubroutine SVD(n,m,A,U,S,VT)\n implicit none\n\n integer,intent(in) :: n, m\n real(r_kind),intent(in) :: A(m,n)\n real(r_kind),intent(out) :: U(m,m), VT(n,n)\n real(r_kind),intent(inout) :: S(:)\n\n character :: jobu, jobvt\n integer :: lda, ldu, ldvt\n integer :: info\n integer :: lwork\n real(r_kind) :: bufA(m,n)\n real(r_kind),allocatable :: work(:)\n\n bufA=A\n lda=m; ldu=m; ldvt=n\n lwork=3*min(m,n) + max ( max(m,n), 2*min(m,n) )\n allocate( work(lwork) )\n jobu='A'; jobvt='A'\n call dgesvd( jobu, jobvt, m, n, bufA, lda, S, U, ldu, VT, ldvt, work, lwork, info)\n if (info/=0) stop 'svd: error in dgesvd'\n deallocate( work )\n\nendsubroutine\n\n!\n! identity matrix\n!\nsubroutine EYE(n,A)\n implicit none\n\n integer,intent(in) :: n\n real(r_kind),intent(out) :: A(n,n)\n\n integer :: i\n\n A=0.d0\n do i = 1, n\n A(i,i) = 1.d0\n enddo\n\nendsubroutine\n\n!\n! A random upper triangle square matrix\n!\nsubroutine RANDUTRI(n,A)\n implicit none\n integer,intent(in) :: n\n real(r_kind),intent(out) :: A(n,n)\n\n integer :: i, j\n\n A=0.d0\n do i = 1, n\n do j = i,n\n A(i,j) = REAL(rnorm(),8)\n enddo\n enddo\n\n call RENORM(n,n,A)\n\nendsubroutine\n\n\nsubroutine RENORM1d(n,A)\n implicit none\n\n integer,intent(in) :: n\n real(r_kind),intent(inout) :: A(n)\n\n real(r_kind) :: rn2\n\n rn2 = sqrt(sum(A(:)*A(:)))\n A(:) = A(:)/rn2\n\nendsubroutine\n\n\n\n!\n! renormalize each column of the general matrix\n!\nsubroutine RENORM2d(n,m,A)\n implicit none\n\n integer,intent(in) :: n, m\n real(r_kind),intent(inout) :: A(n,m)\n\n integer :: i\n real(r_kind) :: rn2\n\n do i = 1, m\n rn2 = sqrt(sum(A(:,i)*A(:,i)))\n A(:,i) = A(:,i)/rn2\n enddo\n\nendsubroutine\n\n!\n! inverse of a general square matrix\n!\nsubroutine INV(n,A,invA)\n implicit none\n\n integer,intent(in) :: n\n real(r_kind),intent(in) :: A(n,n)\n real(r_kind),intent(out) :: invA(n,n)\n\n integer :: info, ipiv(n)\n integer :: lwork, lda\n real(r_kind) :: work(n)\n\n invA = A\n lda = n; lwork = n\n call dgetrf(n,n,invA,lda,ipiv,info)\n if (info/=0) stop \"ERROR in INV: dgetrf\"\n call dgetri(n,invA,lda,ipiv,work,lwork,info)\n if (info/=0) stop \"ERROR in INV: dgetri\"\nendsubroutine\n\n!\n! QR decomposition of a square matrix\n!\nsubroutine QR(n,A,Q,R)\n implicit none\n\n integer,intent(in) :: n\n real(r_kind),intent(in) :: A(n,n) \n real(r_kind),intent(out) :: Q(n,n), R(n,n)\n\n integer :: ierr\n real(r_kind) :: work(n), bufA(n,n), tau(n)\n integer :: lda\n integer :: i\n\n ierr=0\n lda = n\n bufA = A\n call dgeqrf(n,n,bufA,lda,tau,work,n,ierr)\n if (ierr/=0) stop \"ERROR in QR: dgetqrf\"\n R=0.d0\n do i = 1, n\n R(i,i:n) = bufA(i,i:n)\n enddo\n Q=bufA\n call dorgqr(n,n,n,Q,lda,tau,work,n,ierr)\n if (ierr/=0) stop \"ERROR in QR: qorgqr\"\n\nendsubroutine\n\n!\n! random number generator\n!\nsubroutine rnorm1d( nn, r1d )\n implicit none\n\n integer,intent(in) :: nn\n real(r_single),intent(inout) :: r1d(nn)\n \n integer :: i\n\n do i =1 , nn\n r1d(i) = rnorm()\n enddo\n\nendsubroutine \n\nreal(r_single) function rnorm() result( fn_val )\n\n! Generate a random normal deviate using the polar method.\n! Reference: Marsaglia,G. & Bray,T.A. 'A convenient method for generating\n! normal variables', Siam Rev., vol.6, 260-264, 1964.\n\nimplicit none\n\n! Local variables\r\n\nreal(r_single) :: u, sum\nreal(r_single), save :: v, sln\nlogicaL, save :: second = .false.\nreal(r_single), parameter :: one = 1.0_r_single, vsmall = TINY( one )\n\nif (second) then\n! If second, use the second random number generated on last call\n\n second = .false.\n fn_val = v*sln\n\nelse\n! First call; generate a pair of random normals\n\n second = .true.\n do\n call random_number( u )\n call random_number( v )\n u = scale( u, 1 ) - one\n v = scale( v, 1 ) - one\n sum = u*u + v*v + vsmall ! vsmall added to prevent LOG(zero) / zero\n IF(sum < one) exit\n end do\n sln = sqrt(- scale( log(sum), 1 ) / sum)\n fn_val = u*sln\nend if\n\nreturn\nend function rnorm\n\nsubroutine iran(l,n,ran_int)\n! generate an array of N random integers between 0 and L-1.\n real(r_single) :: rnd\n integer(i_kind) :: L,i,N\n integer(i_kind) :: ran_int(N)\n do i = 1,n\n call random_number(rnd)\n ran_int(i) = nint(float(l-1)*rnd)\n end do\nend subroutine iran\n\nsubroutine set_random_seed ( iseed , myrank)\n!\n!*******************************************************************************\n!\n!! SET_RANDOM_SEED initializes the FORTRAN 90 random number generator.\n!\n!\n! Discussion:\n!\n! If ISEED is nonzero, then that value is used to construct a seed.\n!\n! If ISEED is zero, then the seed is determined by calling the date \n! and time routine. Thus, if the code is run at different times, \n! different seed values will be set.\n!\n! Parameters:\n!\n! Input, integer ISEED, is nonzero for a user seed, or 0 if the\n! seed should be determined by this routine.\n!\n implicit none\n!\n integer(i_kind), intent(in), optional :: myrank\n integer(i_kind) date_time(8)\n logical, parameter :: debug = .false.\n integer(i_kind) i,j,k\n integer(i_kind) iseed\n integer(i_kind), allocatable :: seed(:)\n\n!\n! Initialize the random seed routine.\n!\n call random_seed\n!\n! Request the size of a typical seed.\n! (On the DEC ALPHA, K is returned as 2.)\n!\n call random_seed ( size = k )\n\n if ( debug ) then\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SET_RANDOM_SEED:'\n write ( *, '(a,i6)' ) ' Random seed size is K = ', k\n end if\n!\n! Set up space for a seed vector.\n!\n allocate ( seed(k) )\n\n if ( iseed /= 0 ) then\n\n seed(1:k) = iseed\n\n else\n!\n! Make up a \"random\" value based on date and time information.\n!\n call date_and_time ( values = date_time )\n\n do i = 1, k\n\n seed(i) = 0\n\n do j = 1, 8\n if (present(myrank)) then\n seed(i) = seed(i) + ( j + i ) * date_time(j) + myrank * 100\n else\n seed(i) = seed(i) + ( j + i ) * date_time(j)\n endif\n seed(i) = ishftc ( seed(i), 4 * ( j - 1 ) )\n end do\n\n end do\n\n end if\n\n if ( debug ) then\n\n write ( *, '(a)' ) ' '\n write ( *, '(a)' ) 'SET_RANDOM_SEED:'\n write ( *, '(a)' ) ' The random seed vector:'\n write ( *, '(a)' ) ' '\n\n do i = 1, k\n write ( *, '(i12)' ) seed(i)\n end do\n\n end if\n!\n! Send this random value back to the RANDOM_SEED routine, to be\n! used as the seed of the random number generator.\n!\n call random_seed ( put = seed(1:k) )\n\n deallocate ( seed )\n\n end subroutine set_random_seed\n\n\nendmodule\n\n!\n! test SVD\n!\n!program main\n! use m_mt\n! implicit none\n!\n! integer :: n, m\n! real(8),allocatable :: A(:,:), U(:,:),S(:),VT(:,:)\n!\n! integer :: i, j\n!\n! m=3; n=4\n! allocate(A(m,n),U(m,m),S(max(m,n)),VT(n,n))\n! A(1,:)=(/1.d0, 2.d0, 3.d0, 4.d0/)\n! A(2,:)=(/3.d0, 4.d0, 5.d0, 6.d0/)\n! A(3,:)=(/6.d0, 5.d0, 4.d0, 1.d0/)\n! call SVD(n,m,A,U,S,VT)\n! print*, \"A=\"\n! do i = 1, m\n! write(*,*) (A(i,j),j=1,n)\n! enddo\n! \n! print*, \"U=\"\n! do i = 1, m\n! write(*,*) (U(i,j),j=1,m)\n! enddo\n!\n! print*, \"U=\", (S(i),i=1,max(m,n))\n!\n! print*, \"VT=\"\n! do i = 1, n\n! write(*,*) (VT(i,j),j=1,n)\n! enddo\n!endprogram\n\n!\n! test randn\n!\n!program main\n! use m_mt, only :randn\n! implicit none\n!\n! real(8) :: a(100)\n! integer :: i , k \n!\n! do i = 1, 3\n! call randn(100,a)\n! do k = 1 , 5\n! write(*,*) a(k)\n! enddo\n! pause \"i\"\n! enddo\n! \n!endprogram\n\n", "meta": {"hexsha": "f4858c691a64591b5b950e65793ddcc0d22d44a8", "size": 9565, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran_da/m_mt.f90", "max_stars_repo_name": "lysun0725/MAOOAM", "max_stars_repo_head_hexsha": "ad0df11876031b8df31bec8171bc4ce5ac2dff9c", "max_stars_repo_licenses": ["MIT"], "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_da/m_mt.f90", "max_issues_repo_name": "lysun0725/MAOOAM", "max_issues_repo_head_hexsha": "ad0df11876031b8df31bec8171bc4ce5ac2dff9c", "max_issues_repo_licenses": ["MIT"], "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_da/m_mt.f90", "max_forks_repo_name": "lysun0725/MAOOAM", "max_forks_repo_head_hexsha": "ad0df11876031b8df31bec8171bc4ce5ac2dff9c", "max_forks_repo_licenses": ["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.3232323232, "max_line_length": 84, "alphanum_fraction": 0.5825405123, "num_tokens": 3475, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256472515683, "lm_q2_score": 0.7745833789613197, "lm_q1q2_score": 0.6520641543444198}} {"text": "! An example of converting the indices of a 9-element rank 1 array\n! into the indices of a 3-by-3 rank 2 array. Column major ordering!\nprogram convert_array_indices\n\n implicit none\n\n integer, dimension(9) :: a, j, i\n integer :: n, k, ny = 3\n \n n = size(a)\n\n do k = 1, n\n a(k) = k\n end do\n write(*, \"(a, 9(i3))\") \"a =\", a\n\n do k = 1, n\n j(k) = mod((k-1), ny) + 1\n i(k) = (k-1)/ny + 1\n end do\n write(*, \"(a, 9(i3))\") \"j =\", j\n write(*, \"(a, 9(i3))\") \"i =\", i\n\nend program convert_array_indices\n", "meta": {"hexsha": "446da1b24375750e523ed2ce28a9c4b1c4208760", "size": 516, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "convert_array_indices.f90", "max_stars_repo_name": "mdpiper/wunderkammer", "max_stars_repo_head_hexsha": "05291ca9759d458f6d25841e11787b9c75991da7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "convert_array_indices.f90", "max_issues_repo_name": "mdpiper/wunderkammer", "max_issues_repo_head_hexsha": "05291ca9759d458f6d25841e11787b9c75991da7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "convert_array_indices.f90", "max_forks_repo_name": "mdpiper/wunderkammer", "max_forks_repo_head_hexsha": "05291ca9759d458f6d25841e11787b9c75991da7", "max_forks_repo_licenses": ["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.64, "max_line_length": 67, "alphanum_fraction": 0.5503875969, "num_tokens": 203, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7745833737577158, "lm_q2_score": 0.8418256492357358, "lm_q1q2_score": 0.6520641515007957}} {"text": "c\nc\nc ... file rgrd2u.f\nc\nc this file contains documentation followed by fortran code for\nc subroutine rgrd2u and additional subroutines.\nc\nc ... author\nc\nc John C. Adams (NCAR 1999)\nc\nc ... subroutine rgrd2u(nx,ny,p,mx,my,q,intpol,w,lw,iw,liw,ier)\nc\nc ... purpose\nc\nc subroutine rgrd2u interpolates the nx by ny array p onto\nc the mx by my array q. linear or cubic interpolation is\nc used in each direction (see aargumentintpol). it is assumed\nc that p and q are values on uniform nx by ny and mx by my grids\nc superimposed on the same rectangle (INCLUDING BOUNDARIES).\nc if p and q are values on nonuniform orthogonal grids and/or\nc if the grid on which q is defined lies within the p grid\nc then subroutine rgrd2 (see file rgrd2.f) should be used.\nc\nc ... language\nc\nc coded in portable FORTRAN77 and FORTRAN90\nc\nc ... test program\nc\nc file trgrd2u.f on regridpack includes a test program for subroutine rgrd2u\nc\nc\nc ... method\nc\nc linear or cubic interpolation (see intpol) is used in each\nc direction for which the q grid is not a subgrid of the p grid.\nc [the mx (my) uniform grid is a subgrid of the nx (ny) uniform\nc grid if and only if mx-1 (my-1) divides nx-1 (ny-1)].\nc values are set directly without (the need for) interpolation\nc in subgrid directions.\nc\nc ... required files\nc\nc file rgrd1u.f must be loaded with rgrd2u.f. it includes\nc subroutines called by the routines in rgrd2u.f\nc\nc ... efficiency\nc\nc inner most loops in regridpack software vectorize. If\nc the arguments mx,my (see below) have different values, optimal\nc vectorization will be achieved if mx > my.\nc\nc\nc *** input arguments ***\nc\nc\nc ... nx\nc\nc the integer first dimension of p. nx > 1 if intpol(1) = 1 or\nc nx > 3 if intpol(1) = 3 is required (see ier = 2).\nc\nc ... ny\nc\nc the integer second dimension of p. ny > 1 if intpol(2) = 1 or\nc ny > 3 if intpol(2) = 3 is required (see ier = 2).\nc\nc ... p\nc\nc a real nx by ny array of given values\nc\nc ... mx\nc\nc the integer first dimension of q. mx > 1 is required (see ier = 1)\nc\nc ... my\nc\nc the integer second dimension of q. my > 1 is required (see ier = 1)\nc\nc ... intpol\nc\nc an integer vector of dimension 2 which sets linear or cubic\nc interpolation in each of the x,y directions as follows:\nc\nc intpol(1) = 1 sets linear interpolation in the x direction\nc intpol(1) = 3 sets cubic interpolation in the x direction.\nc\nc intpol(2) = 1 sets linear interpolation in the y direction\nc intpol(2) = 3 sets cubic interpolation in the y direction.\nc\nc values other than 1 or 3 in intpol are not allowed (ier = 3).\nc\nc ... w\nc\nc a real work space of length at least lw which must be provided in the\nc routine calling rgrd2u\nc\nc ... lw\nc\nc the integer length of the work space w.\nc\nc let lwx = 1 if mx-1 divides nx-1; otherwise\nc let lwx = mx if intpol(1) = 1 or\nc let lwx = 4*mx if intpol(1) = 3\nc\nc let lwy = 0 if my-1 divides ny-1; otherwise\nc let lwy = 2*mx+my if intpol(2) = 1 or\nc let lwy = 4*(mx+my) if intpol(2) = 3\nc\nc then lw must be greater than or equal to lwx+lwy\nc\nc ... iw\nc\nc an integer work space of length at least liw which must be provided in the\nc routine calling rgrd2u\nc\nc ... liw\nc\nc the integer length of the integer work space iw. liw must be greater than\nc or equal to mx+my.\nc\nc *** output arguments ***\nc\nc\nc ... q\nc\nc a real mx by my array of values which are interpolated from p.\nc\nc ... ier\nc\nc an integer error flag set as follows:\nc\nc ier = 0 if no errors in input arguments are detected\nc\nc ier = 1 if min0(mx,my) < 2\nc\nc ier = 2 if nx < 2 when intpol(1)=1 or nx < 4 when intpol(1)=3 (or)\nc ny < 2 when intpol(2)=1 or ny < 4 when intpol(2)=3.\nc\nc ier = 3 if intpol(1) or intpol(2) is not equal to 1 or 3\nc\nc ier = 4 if lw or liw is to small (insufficient work space)\nc\nc ************************************************************************\nc\nc end of rgrd2u documentation, fortran code follows:\nc\nc ************************************************************************\nc\n subroutine rgrd2u(nx,ny,p,mx,my,q,intpol,w,lw,iw,liw,ier)\nc\nc two dimensional linear or cubic interpolation of p onto q\nc assuming p and q lie on nx by ny and and mx by my uniform grids\nc which subdivide the same rectangle (including boundaries)\nc\n implicit none\n integer nx,ny,mx,my,intpol(2),lw,liw,ier\n real p(nx,ny),q(mx,my),w(lw)\n integer inmx,jnmy,isubx,jsuby,lwx,lwy,jy,iw(liw)\n integer j2,j3,j4,j5,j6,j7,j8,j9,i2,i3,i4,i5\nc\nc check input aarguments\nc\n ier = 1\nc\nc check mx,my\nc\n if (min0(mx,my) .lt. 2) return\nc\nc check intpol\nc\n ier = 3\n if (intpol(1).ne.1 .and. intpol(1).ne.3) return\n if (intpol(2).ne.1 .and. intpol(2).ne.3) return\nc\nc check nx,ny\nc\n ier = 2\n if (intpol(1).eq.1 .and. nx.lt.2) return\n if (intpol(1).eq.3 .and. nx.lt.4) return\n if (intpol(2).eq.1 .and. ny.lt.2) return\n if (intpol(2).eq.3 .and. ny.lt.4) return\nc\nc set subgrid indicators\nc\n inmx = (nx-1)/(mx-1)\n jnmy = (ny-1)/(my-1)\n isubx = nx - inmx*(mx-1)\n jsuby = ny - jnmy*(my-1)\nc\nc check work space length input\nc\n ier = 4\n lwx = 1\n lwy = 0\n if (isubx.ne.1) then\n if (intpol(1).eq.1) then\n lwx = mx\n else\n lwx = mx\n end if\n end if\n if (jsuby.ne.1) then\n if (intpol(2).eq.1) then\n lwy = (my+2*mx)\n else\n lwy = 4*(mx+my)\n end if\n end if\n if (lw .lt. lwx+lwy) return\n if (liw .lt. mx+my) return\nc\nc input arguments o.k.\nc\n ier = 0\n jy = mx+1\nc\nc preset work space pointers\nc\n j2 = 1\n j3 = j2\n j4 = j3\n j5 = j4\n j6 = j5\n j7 = j6\n j8 = j7\n j9 = j8\n i2 = j9\n i3 = i2\n i4 = i3\n i5 = i4\n\n if (intpol(2) .eq.1) then\nc\nc linearly interpolate in y\nc\n\tif (jsuby.ne.1) then\n\t j2 = 1\n\t j3 = j2\n\t j4 = j3+my\n\t j5 = j4\n\t j6 = j5\n\t j7 = j6\n\t j8 = j7+mx\n\t j9 = j8+mx\nc\nc set y interpolation indices and scales and linearly interpolate\nc\n\t call linmxu(ny,my,iw(jy),w(j3))\n\t i2 = j9\n\tend if\nc\nc set work space portion and indices which depend on x interpolation\nc\n\tif (isubx.ne.1) then\n\t if (intpol(1) .eq. 1) then\n\t i3 = i2\n\t i4 = i3\n\t i5 = i4\n\t call linmxu(nx,mx,iw,w(i3))\n\t else\n\t i3 = i2+mx\n\t i4 = i3+mx\n\t i5 = i4+mx\n\t call cubnmxu(nx,mx,iw,w(i2),w(i3),w(i4),w(i5))\n\t end if\n\tend if\n\tcall lint2u(nx,ny,p,mx,my,q,intpol,iw(jy),w(j3),w(j7),\n + w(j8),iw,w(i2),w(i3),w(i4),w(i5),inmx,jnmy,isubx,jsuby)\n\treturn\n\n else\nc\nc cubically interpolate in y, set indice pointers\nc\n\tif (jsuby.ne.1) then\n\t j2 = 1\n\t j3 = j2+my\n\t j4 = j3+my\n\t j5 = j4+my\n\t j6 = j5+my\n\t j7 = j6+mx\n\t j8 = j7+mx\n\t j9 = j8+mx\nc\nc set y interpolation indices and scales and cubically interpolate in y\nc\n\t call cubnmxu(ny,my,iw(jy),w(j2),w(j3),w(j4),w(j5))\n\t i2 = j9+mx\n\tend if\nc\nc set work space portion and indices which depend on x interpolation\nc\n\tif (isubx.ne.1) then\n\t if (intpol(1) .eq. 1) then\n\t i3 = i2\n\t i4 = i3\n\t i5 = i4\n\t call linmxu(nx,mx,iw,w(i3))\n\t else\n\t i3 = i2+mx\n\t i4 = i3+mx\n\t i5 = i4+mx\n\t call cubnmxu(nx,mx,iw,w(i2),w(i3),w(i4),w(i5))\n\t end if\n\tend if\n\tcall cubt2u(nx,ny,p,mx,my,q,intpol,iw(jy),w(j2),w(j3),w(j4),\n + w(j5),w(j6),w(j7),w(j8),w(j9),iw,w(i2),w(i3),w(i4),w(i5),\n + inmx,jnmy,isubx,jsuby)\n\treturn\n end if\n end\n\n subroutine lint2u(nx,ny,p,mx,my,q,intpol,jy,dy,pj,pjp,ix,dxm,dx,\n + dxp,dxpp,inmx,jnmy,isubx,jsuby)\n implicit none\n integer nx,ny,mx,my,intpol(2),jy(my),ix(mx),inmx,jnmy,isubx,jsuby\n integer j,jj,ii,jsave\n real p(nx,ny),q(mx,my)\n real dy(my),pj(mx),pjp(mx)\n real dxm(mx),dx(mx),dxp(mx),dxpp(mx)\nc\nc linearly interpolate p onto q in y\nc\n if (intpol(1) .eq. 1) then\nc\nc linear in x\nc\n\tif (jsuby .eq. 1) then\nc\nc my grid is subset of ny grid\nc\n\tdo jj=1,my\n\t j = jnmy*(jj-1)+1\n\t call lint1u(nx,p(1,j),mx,q(1,jj),ix,dx,inmx,isubx)\n\tend do\n\treturn\n\tend if\n\n\tjsave = -1\n\tdo jj=1,my\n\tj = jy(jj)\n\tif (j .eq. jsave) then\nc\nc pointer has not moved, no interpolation in pj,pjp necessary\nc\n\telse if (j .eq. jsave+1) then\n\t do ii=1,mx\n\t pj(ii) = pjp(ii)\n\t end do\n\t call lint1u(nx,p(1,j+1),mx,pjp,ix,dx,inmx,isubx)\n\telse\n\t call lint1u(nx,p(1,j),mx,pj,ix,dx,inmx,isubx)\n\t call lint1u(nx,p(1,j+1),mx,pjp,ix,dx,inmx,isubx)\n\tend if\nc\nc update pointer\nc\n\tjsave = j\n\tdo ii=1,mx\n\t q(ii,jj) = pj(ii)+dy(jj)*(pjp(ii)-pj(ii))\n\t end do\n\tend do\n\n\treturn\n\n else\nc\nc cubic in x\nc\n\tif (jsuby .eq. 1) then\nc\nc my grid is subset of ny grid\nc\n\t do jj=1,my\n\t j = jnmy*(jj-1)+1\n\t call cubt1u(nx,p(1,j),mx,q(1,jj),ix,dxm,dx,dxp,dxpp,\n + inmx,isubx)\n\t end do\n\t return\n\tend if\n\n\tjsave = -1\n\tdo jj=1,my\n\t j = jy(jj)\n\t if (j .eq. jsave) then\nc\nc no interpolation in pj,pjp necessary\nc\n\t else if (j .eq. jsave+1) then\n\t do ii=1,mx\n\t pj(ii) = pjp(ii)\n\t end do\n\t call cubt1u(nx,p(1,j+1),mx,pjp,ix,dxm,dx,dxp,dxpp,\n + inmx,isubx)\n\t else\n\t call cubt1u(nx,p(1,j),mx,pj,ix,dxm,dx,dxp,dxpp,\n + inmx,isubx)\n\t call cubt1u(nx,p(1,j+1),mx,pjp,ix,dxm,dx,dxp,dxpp,\n + inmx,isubx)\n\t end if\nc\nc update pointer\nc\n\t jsave = j\n\t do ii=1,mx\n\t q(ii,jj) = pj(ii)+dy(jj)*(pjp(ii)-pj(ii))\n\t end do\n\tend do\n\treturn\n\n end if\n\n end\n\n subroutine cubt2u(nx,ny,p,mx,my,q,intpol,jy,dym,dy,dyp,dypp,\n +pjm,pj,pjp,pjpp,ix,dxm,dx,dxp,dxpp,inmx,jnmy,isubx,jsuby)\n implicit none\n integer nx,ny,mx,my,intpol(2),jy(my),ix(mx),inmx,jnmy,isubx,jsuby\n integer j,jj,ii,jsave\n real p(nx,ny),q(mx,my)\n real dym(my),dy(my),dyp(my),dypp(my)\n real pjm(mx),pj(mx),pjp(mx),pjpp(mx)\n real dxm(mx),dx(mx),dxp(mx),dxpp(mx)\nc\nc cubically interpolate p onto q in y\nc\n if (intpol(1) .eq. 1) then\nc\nc linear in x\nc\n\tif (jsuby .eq. 1) then\nc\nc my grid is subset of ny grid\nc\n\t do jj=1,my\n\t j = jnmy*(jj-1)+1\n\t call lint1u(nx,p(1,j),mx,q(1,jj),ix,dx,inmx,isubx)\n\t end do\n\t return\n\tend if\n\n\tjsave = -3\n\tdo jj=1,my\n\t j = jy(jj)\nc\nc load pjm,pj,pjp,pjpp\nc\n\t if (j.eq.jsave) then\nc no updates or x interpolation necessary\n\t else if (j.eq.jsave+1) then\n\t do ii=1,mx\n\t pjm(ii) = pj(ii)\n\t pj(ii) = pjp(ii)\n\t pjp(ii) = pjpp(ii)\n\t end do\n\t call lint1u(nx,p(1,j+2),mx,pjpp,ix,dx,inmx,isubx)\n\t else if (j.eq.jsave+2) then\n\t do ii=1,mx\n\t pjm(ii) = pjp(ii)\n\t pj(ii) = pjpp(ii)\n\t end do\n\t call lint1u(nx,p(1,j+1),mx,pjp,ix,dx,inmx,isubx)\n\t call lint1u(nx,p(1,j+2),mx,pjpp,ix,dx,inmx,isubx)\n\t else if (j.eq.jsave+3) then\n\t do ii=1,mx\n\t pjm(ii) = pjpp(ii)\n\t end do\n\t call lint1u(nx,p(1,j),mx,pj,ix,dx,inmx,isubx)\n\t call lint1u(nx,p(1,j+1),mx,pjp,ix,dx,inmx,isubx)\n\t call lint1u(nx,p(1,j+2),mx,pjpp,ix,dx,inmx,isubx)\n\t else\nc load all four (no updates)\n\t call lint1u(nx,p(1,j-1),mx,pjm,ix,dx,inmx,isubx)\n\t call lint1u(nx,p(1,j),mx,pj,ix,dx,inmx,isubx)\n\t call lint1u(nx,p(1,j+1),mx,pjp,ix,dx,inmx,isubx)\n\t call lint1u(nx,p(1,j+2),mx,pjpp,ix,dx,inmx,isubx)\n\t end if\nc\nc update pointer\nc\n\t jsave = j\n\t do ii=1,mx\n\t q(ii,jj) = dym(jj)*pjm(ii) + dy(jj)*pj(ii) +\n + dyp(jj)*pjp(ii) + dypp(jj)*pjpp(ii)\n\t end do\n\tend do\n\treturn\n\n else\nc\nc cubic in x\nc\n\n\tif (jsuby .eq. 1) then\nc\nc my grid is subset of ny grid\nc\n\t do jj=1,my\n\t j = jnmy*(jj-1)+1\n\t call cubt1u(nx,p(1,j),mx,q(1,jj),ix,dxm,dx,dxp,dxpp,\n + inmx,isubx)\n\t end do\n\t return\n\tend if\n\n\tjsave = -3\n\tdo jj=1,my\n\t j = jy(jj)\nc\nc load pjm,pj,pjp,pjpp\nc\n\t if (j.eq.jsave) then\nc no updates or x interpolation necessary\n\t else if (j.eq.jsave+1) then\n\t do ii=1,mx\n\t pjm(ii) = pj(ii)\n\t pj(ii) = pjp(ii)\n\t pjp(ii) = pjpp(ii)\n\t end do\n\t call cubt1u(nx,p(1,j+2),mx,pjpp,ix,dxm,dx,dxp,dxpp,\n + inmx,isubx)\n\t else if (j.eq.jsave+2) then\n\t do ii=1,mx\n\t pjm(ii) = pjp(ii)\n\t pj(ii) = pjpp(ii)\n\t end do\n\t call cubt1u(nx,p(1,j+1),mx,pjp,ix,dxm,dx,dxp,dxpp,\n + inmx,isubx)\n\t call cubt1u(nx,p(1,j+2),mx,pjpp,ix,dxm,dx,dxp,dxpp,\n + inmx,isubx)\n\t else if (j.eq.jsave+3) then\n\t do ii=1,mx\n\t pjm(ii) = pjpp(ii)\n\t end do\n\t call cubt1u(nx,p(1,j),mx,pj,ix,dxm,dx,dxp,dxpp,\n + inmx,isubx)\n\t call cubt1u(nx,p(1,j+1),mx,pjp,ix,dxm,dx,dxp,dxpp,\n + inmx,isubx)\n\t call cubt1u(nx,p(1,j+2),mx,pjpp,ix,dxm,dx,dxp,dxpp,\n + inmx,isubx)\n\t else\nc load all four (no updates)\n\t call cubt1u(nx,p(1,j-1),mx,pjm,ix,dxm,dx,dxp,dxpp,\n + inmx,isubx)\n\t call cubt1u(nx,p(1,j),mx,pj,ix,dxm,dx,dxp,dxpp,\n + inmx,isubx)\n\t call cubt1u(nx,p(1,j+1),mx,pjp,ix,dxm,dx,dxp,dxpp,\n + inmx,isubx)\n\t call cubt1u(nx,p(1,j+2),mx,pjpp,ix,dxm,dx,dxp,dxpp,\n + inmx,isubx)\n\t end if\nc\nc update pointer\nc\n\t jsave = j\n\t do ii=1,mx\n\t q(ii,jj) = dym(jj)*pjm(ii) + dy(jj)*pj(ii) +\n + dyp(jj)*pjp(ii) + dypp(jj)*pjpp(ii)\n\t end do\n\tend do\n return\n\n end if\n\n end\n\n", "meta": {"hexsha": "fc0dfad84887cd66f3a5be283b4d44183ab6110c", "size": 13525, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "contrib/regridpack/Src/rgrd2u.f", "max_stars_repo_name": "xylar/cdat", "max_stars_repo_head_hexsha": "8a5080cb18febfde365efc96147e25f51494a2bf", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 62, "max_stars_repo_stars_event_min_datetime": "2018-03-30T15:46:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-08T23:30:24.000Z", "max_issues_repo_path": "contrib/regridpack/Src/rgrd2u.f", "max_issues_repo_name": "xylar/cdat", "max_issues_repo_head_hexsha": "8a5080cb18febfde365efc96147e25f51494a2bf", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 114, "max_issues_repo_issues_event_min_datetime": "2018-03-21T01:12:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-05T12:29:54.000Z", "max_forks_repo_path": "contrib/regridpack/Src/rgrd2u.f", "max_forks_repo_name": "CDAT/uvcdat", "max_forks_repo_head_hexsha": "5133560c0c049b5c93ee321ba0af494253b44f91", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2018-06-06T02:42:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-26T03:27:00.000Z", "avg_line_length": 23.8116197183, "max_line_length": 80, "alphanum_fraction": 0.5733826248, "num_tokens": 5340, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256393148982, "lm_q2_score": 0.7745833737577158, "lm_q1q2_score": 0.6520641438162799}} {"text": " DOUBLE PRECISION FUNCTION MA02ID( TYP, NORM, N, A, LDA, QG,\n $ LDQG, DWORK )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute the value of the one norm, or the Frobenius norm, or\nC the infinity norm, or the element of largest absolute value\nC of a real skew-Hamiltonian matrix\nC\nC [ A G ] T T\nC X = [ T ], G = -G, Q = -Q,\nC [ Q A ]\nC\nC or of a real Hamiltonian matrix\nC\nC [ A G ] T T\nC X = [ T ], G = G, Q = Q,\nC [ Q -A ]\nC\nC where A, G and Q are real n-by-n matrices.\nC\nC Note that for this kind of matrices the infinity norm is equal\nC to the one norm.\nC\nC FUNCTION VALUE\nC\nC MA02ID DOUBLE PRECISION\nC The computed norm.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC TYP CHARACTER*1\nC Specifies the type of the input matrix X:\nC = 'S': X is skew-Hamiltonian;\nC = 'H': X is Hamiltonian.\nC\nC NORM CHARACTER*1\nC Specifies the value to be returned in MA02ID:\nC = '1' or 'O': one norm of X;\nC = 'F' or 'E': Frobenius norm of X;\nC = 'I': infinity norm of X;\nC = 'M': max(abs(X(i,j)).\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The order of the matrix A. N >= 0.\nC\nC A (input) DOUBLE PRECISION array, dimension (LDA,N)\nC On entry, the leading N-by-N part of this array must\nC contain the matrix A.\nC\nC LDA INTEGER\nC The leading dimension of the array A. LDA >= MAX(1,N).\nC\nC QG (input) DOUBLE PRECISION array, dimension (LDQG,N+1)\nC On entry, the leading N-by-N+1 part of this array must\nC contain in columns 1:N the lower triangular part of the\nC matrix Q and in columns 2:N+1 the upper triangular part\nC of the matrix G. If TYP = 'S', the parts containing the\nC diagonal and the first supdiagonal of this array are not\nC referenced.\nC\nC LDQG INTEGER\nC The leading dimension of the array QG. LDQG >= MAX(1,N).\nC\nC Workspace\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC where LDWORK >= 2*N when NORM = '1', NORM = 'I' or\nC NORM = 'O'; otherwise, DWORK is not referenced.\nC\nC CONTRIBUTORS\nC\nC D. Kressner, Technical Univ. Berlin, Germany, and\nC P. Benner, Technical Univ. Chemnitz, Germany, December 2003.\nC\nC REVISIONS\nC\nC V. Sima, June 2008 (SLICOT version of the HAPACK routine DLANHA).\nC V. Sima, Jan. 2016 (removed O(N) tests in several loops).\nC\nC KEYWORDS\nC\nC Elementary matrix operations, Hamiltonian matrix, skew-Hamiltonian\nC matrix.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ONE, TWO, ZERO\n PARAMETER ( ONE = 1.0D+0, TWO = 2.0D+0, ZERO = 0.0D+0 )\nC .. Scalar Arguments ..\n CHARACTER NORM, TYP\n INTEGER LDA, LDQG, N\nC .. Array Arguments ..\n DOUBLE PRECISION A(LDA,*), DWORK(*), QG(LDQG,*)\nC .. Local Scalars ..\n LOGICAL LSH\n INTEGER I, J\n DOUBLE PRECISION DSCL, DSUM, SCALE, SUM, TEMP, VALUE\nC .. External Functions ..\n LOGICAL LSAME\n DOUBLE PRECISION DLANGE, DLAPY2\n EXTERNAL DLANGE, DLAPY2, LSAME\nC .. External Subroutines ..\n EXTERNAL DLASSQ\nC .. Intrinsic Functions ..\n INTRINSIC ABS, MAX, SQRT\nC\nC .. Executable Statements ..\nC\n LSH = LSAME( TYP, 'S' )\nC\n IF ( N.EQ.0 ) THEN\n VALUE = ZERO\nC\n ELSE IF ( LSAME( NORM, 'M' ) .AND. LSH ) THEN\nC\nC Find max(abs(A(i,j))).\nC\n VALUE = DLANGE( 'MaxElement', N, N, A, LDA, DWORK )\n IF ( N.GT.1 ) THEN\n DO 30 J = 1, N+1\n DO 10 I = 1, J-2\n VALUE = MAX( VALUE, ABS( QG(I,J) ) )\n 10 CONTINUE\n DO 20 I = J+1, N\n VALUE = MAX( VALUE, ABS( QG(I,J) ) )\n 20 CONTINUE\n 30 CONTINUE\n END IF\nC\n ELSE IF ( LSAME( NORM, 'M' ) ) THEN\nC\nC Find max( abs( A(i,j) ), abs( QG(i,j) ) ).\nC\n VALUE = MAX( DLANGE( 'MaxElement', N, N, A, LDA, DWORK ),\n $ DLANGE( 'MaxElement', N, N+1, QG, LDQG,\n $ DWORK ) )\nC\n ELSE IF ( ( LSAME( NORM, 'O' ) .OR. ( NORM.EQ.'1' ) .OR.\n $ LSAME( NORM, 'I' ) ) .AND. LSH ) THEN\nC\nC Find the column and row sums of A (in one pass).\nC\n VALUE = ZERO\n DO 40 I = 1, N\n DWORK(I) = ZERO\n 40 CONTINUE\nC\n DO 60 J = 1, N\n SUM = ZERO\n DO 50 I = 1, N\n TEMP = ABS( A(I,J) )\n SUM = SUM + TEMP\n DWORK(I) = DWORK(I) + TEMP\n 50 CONTINUE\n DWORK(N+J) = SUM\n 60 CONTINUE\nC\nC Compute the maximal absolute column sum.\nC\n DO 90 J = 1, N\n DO 70 I = 1, J-2\n TEMP = ABS( QG(I,J) )\n DWORK(I) = DWORK(I) + TEMP\n DWORK(J-1) = DWORK(J-1) + TEMP\n 70 CONTINUE\n SUM = DWORK(N+J)\n DO 80 I = J+1, N\n TEMP = ABS( QG(I,J) )\n SUM = SUM + TEMP\n DWORK(N+I) = DWORK(N+I) + TEMP\n 80 CONTINUE\n VALUE = MAX( VALUE, SUM )\n 90 CONTINUE\n DO 100 I = 1, N-1\n TEMP = ABS( QG(I,N+1) )\n DWORK(I) = DWORK(I) + TEMP\n DWORK(N) = DWORK(N) + TEMP\n 100 CONTINUE\n DO 110 I = 1, N\n VALUE = MAX( VALUE, DWORK(I) )\n 110 CONTINUE\nC\n ELSE IF ( LSAME( NORM, 'O' ) .OR. ( NORM.EQ.'1' ) .OR.\n $ LSAME( NORM, 'I' ) ) THEN\nC\nC Find the column and row sums of A (in one pass).\nC\n VALUE = ZERO\n DO 120 I = 1, N\n DWORK(I) = ZERO\n 120 CONTINUE\nC\n DO 140 J = 1, N\n SUM = ZERO\n DO 130 I = 1, N\n TEMP = ABS( A(I,J) )\n SUM = SUM + TEMP\n DWORK(I) = DWORK(I) + TEMP\n 130 CONTINUE\n DWORK(N+J) = SUM\n 140 CONTINUE\nC\nC Compute the maximal absolute column sum.\nC\n SUM = DWORK(N+1) + ABS( QG(1,1) )\n DO 150 I = 2, N\n TEMP = ABS( QG(I,1) )\n SUM = SUM + TEMP\n DWORK(N+I) = DWORK(N+I) + TEMP\n 150 CONTINUE\n VALUE = MAX( VALUE, SUM )\n DO 180 J = 2, N\n DO 160 I = 1, J-2\n TEMP = ABS( QG(I,J) )\n DWORK(I) = DWORK(I) + TEMP\n DWORK(J-1) = DWORK(J-1) + TEMP\n 160 CONTINUE\n DWORK(J-1) = DWORK(J-1) + ABS( QG(J-1,J) )\n SUM = DWORK(N+J) + ABS( QG(J,J) )\n DO 170 I = J+1, N\n TEMP = ABS( QG(I,J) )\n SUM = SUM + TEMP\n DWORK(N+I) = DWORK(N+I) + TEMP\n 170 CONTINUE\n VALUE = MAX( VALUE, SUM )\n 180 CONTINUE\n DO 190 I = 1, J-2\n TEMP = ABS( QG(I,N+1) )\n DWORK(I) = DWORK(I) + TEMP\n DWORK(N) = DWORK(N) + TEMP\n 190 CONTINUE\n DWORK(N) = DWORK(N) + ABS( QG(N,N+1) )\n DO 200 I = 1, N\n VALUE = MAX( VALUE, DWORK(I) )\n 200 CONTINUE\nC\n ELSE IF ( ( LSAME( NORM, 'F' ) .OR.\n $ LSAME( NORM, 'E' ) ) .AND. LSH ) THEN\nC\nC Find normF(A).\nC\n SCALE = ZERO\n SUM = ONE\n DO 210 J = 1, N\n CALL DLASSQ( N, A(1,J), 1, SCALE, SUM )\n 210 CONTINUE\nC\nC Add normF(G) and normF(Q).\nC\n IF ( N.GT.1 )\n $ CALL DLASSQ( N-1, QG(2,1), 1, SCALE, SUM )\n IF ( N.GT.2 )\n $ CALL DLASSQ( N-2, QG(3,2), 1, SCALE, SUM )\n DO 220 J = 3, N-1\n CALL DLASSQ( J-2, QG(1,J), 1, SCALE, SUM )\n CALL DLASSQ( N-J, QG(J+1,J), 1, SCALE, SUM )\n 220 CONTINUE\n CALL DLASSQ( N-2, QG(1,N), 1, SCALE, SUM )\n CALL DLASSQ( N-1, QG(1,N+1), 1, SCALE, SUM )\n VALUE = SQRT( TWO )*SCALE*SQRT( SUM )\nC\n ELSE IF ( LSAME( NORM, 'F' ) .OR. LSAME( NORM, 'E' ) ) THEN\nC\n SCALE = ZERO\n SUM = ONE\n DO 230 J = 1, N\n CALL DLASSQ( N, A(1,J), 1, SCALE, SUM )\n 230 CONTINUE\nC\n DSCL = ZERO\n DSUM = ONE\n CALL DLASSQ( 1, QG(1,1), 1, DSCL, DSUM )\n IF ( N.GT.1 )\n $ CALL DLASSQ( N-1, QG(2,1), 1, SCALE, SUM )\n DO 240 J = 2, N\n CALL DLASSQ( J-2, QG(1,J), 1, SCALE, SUM )\n CALL DLASSQ( 2, QG(J-1,J), 1, DSCL, DSUM )\n CALL DLASSQ( N-J, QG(J+1,J), 1, SCALE, SUM )\n 240 CONTINUE\n CALL DLASSQ( N-1, QG(1,N+1), 1, SCALE, SUM )\n CALL DLASSQ( 1, QG(N,N+1), 1, DSCL, DSUM )\n VALUE = DLAPY2( SQRT( TWO )*SCALE*SQRT( SUM ),\n $ DSCL*SQRT( DSUM ) )\n END IF\nC\n MA02ID = VALUE\n RETURN\nC *** Last line of MA02ID ***\n END\n", "meta": {"hexsha": "98612f283bbaea6a5b4bf45b9f5e3d4d300911c0", "size": 9221, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MA02ID.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MA02ID.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MA02ID.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 30.7366666667, "max_line_length": 72, "alphanum_fraction": 0.4618804902, "num_tokens": 3125, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9196425355825848, "lm_q2_score": 0.7090191460821871, "lm_q1q2_score": 0.6520441652796216}} {"text": " SUBROUTINE PERVEC (VX1,VY1,VZ1, VX2,VY2,VZ2, VX3,VY3,VZ3)\n\nC This subroutine accepts two 3D vectors and returns a vector\nC orthogonal to the first, in the plane of the first two vectors,\nC whose dot product with the second vector is positive, hence\nC the angle between them is < 90 degrees. I.e. the 2nd vector\nC minus the 3rd results in a vector with the same direction (but\nC not length) as the 1st. K is the factor by which V1 is\nC multiplied and then subtracted from V2 - i.e.\nC\nC V3 = V2 - K*V1\n\n\nC _\nC /|A\nC / |\nC / |\nC V2 / | V3\nC / |\nC / |\nC / |\nC / |\nC ----------->.....|\nC V1\nC \\________________/\nC V2 - V3\n\nC Or, V1 can be thought of as the attitude numbers for a plane, and\nC then V3 is the result of the normal projection of V2 into the plane.\nC\nC Closely related to PTPLDS, which is a slightly more general case.\n\n REAL VX1,VY1,VZ1, VX2,VY2,VZ2, VX3,VY3,VZ3, K, DOTPRD, VECL2\n\n K = DOTPRD (VX1,VY1,VZ1, VX2,VY2,VZ2) / VECL2 (VX1, VY1, VZ1)\n VX3 = VX2 - K*VX1\n VY3 = VY2 - K*VY1\n VZ3 = VZ2 - K*VZ1\n\n END\n", "meta": {"hexsha": "aea30b56744ca8d15d576541ae17031df77503b9", "size": 1278, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "third_party/Phigs/PVT/PVT_fort/V2LIB/pervec.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/pervec.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/pervec.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": 31.1707317073, "max_line_length": 71, "alphanum_fraction": 0.5430359937, "num_tokens": 433, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425311777928, "lm_q2_score": 0.7090191399336402, "lm_q1q2_score": 0.6520441565020746}} {"text": " SUBROUTINE HYBSVD(NA, NU, NV, NZ, NB, M, N, A, W, MATU, U, MATV,\n * V, Z, B, IRHS, IERR, RV1)\n INTEGER NA, NU, NV, NZ, M, N, IRHS, IERR, MIN0\n REAL*8 A(NA,1), W(1), U(NU,1), V(NV,1), Z(NZ,1), B(NB,IRHS)\n REAL*8 RV1(1)\n LOGICAL MATU, MATV\nC\nC THIS ROUTINE IS A MODIFICATION OF THE GOLUB-REINSCH PROCEDURE (1)\nC T\nC FOR COMPUTING THE SINGULAR VALUE DECOMPOSITION A = UWV OF A\nC REAL M BY N RECTANGULAR MATRIX. U IS M BY MIN(M,N) CONTAINING\nC THE LEFT SINGULAR VECTORS, W IS A MIN(M,N) BY MIN(M,N) DIAGONAL\nC MATRIX CONTAINING THE SINGULAR VALUES, AND V IS N BY MIN(M,N)\nC CONTAINING THE RIGHT SINGULAR VECTORS.\nC\nC THE ALGORITHM IMPLEMENTED IN THIS\nC ROUTINE HAS A HYBRID NATURE. WHEN M IS APPROXIMATELY EQUAL TO N,\nC THE GOLUB-REINSCH ALGORITHM IS USED, BUT WHEN EITHER OF THE RATIOS\nC M/N OR N/M IS GREATER THAN ABOUT 2,\nC A MODIFIED VERSION OF THE GOLUB-REINSCH\nC ALGORITHM IS USED. THIS MODIFIED ALGORITHM FIRST TRANSFORMS A\nC T\nC INTO UPPER TRIANGULAR FORM BY HOUSEHOLDER TRANSFORMATIONS L\nC AND THEN USES THE GOLUB-REINSCH ALGORITHM TO FIND THE SINGULAR\nC VALUE DECOMPOSITION OF THE RESULTING UPPER TRIANGULAR MATRIX R.\nC WHEN U IS NEEDED EXPLICITLY IN THE CASE M.GE.N (OR V IN THE CASE\nC M.LT.N), AN EXTRA ARRAY Z (OF SIZE AT LEAST\nC MIN(M,N)**2) IS NEEDED, BUT OTHERWISE Z IS NOT REFERENCED\nC AND NO EXTRA STORAGE IS REQUIRED. THIS HYBRID METHOD\nC SHOULD BE MORE EFFICIENT THAN THE GOLUB-REINSCH ALGORITHM WHEN\nC M/N OR N/M IS LARGE. FOR DETAILS, SEE (2).\nC\nC WHEN M .GE. N,\nC HYBSVD CAN ALSO BE USED TO COMPUTE THE MINIMAL LENGTH LEAST\nC SQUARES SOLUTION TO THE OVERDETERMINED LINEAR SYSTEM A*X=B.\nC IF M .LT. N (I.E. FOR UNDERDETERMINED SYSTEMS), THE RHS B\nC IS NOT PROCESSED.\nC\nC NOTICE THAT THE SINGULAR VALUE DECOMPOSITION OF A MATRIX\nC IS UNIQUE ONLY UP TO THE SIGN OF THE CORRESPONDING COLUMNS\nC OF U AND V.\nC\nC THIS ROUTINE HAS BEEN CHECKED BY THE PFORT VERIFIER (3) FOR\nC ADHERENCE TO A LARGE, CAREFULLY DEFINED, PORTABLE SUBSET OF\nC AMERICAN NATIONAL STANDARD FORTRAN CALLED PFORT.\nC\nC REFERENCES:\nC\nC (1) GOLUB,G.H. AND REINSCH,C. (1970) 'SINGULAR VALUE\nC DECOMPOSITION AND LEAST SQUARES SOLUTIONS,'\nC NUMER. MATH. 14,403-420, 1970.\nC\nC (2) CHAN,T.F. (1982) 'AN IMPROVED ALGORITHM FOR COMPUTING\nC THE SINGULAR VALUE DECOMPOSITION,' ACM TOMS, VOL.8,\nC NO. 1, MARCH, 1982.\nC\nC (3) RYDER,B.G. (1974) 'THE PFORT VERIFIER,' SOFTWARE -\nC PRACTICE AND EXPERIENCE, VOL.4, 359-377, 1974.\nC\nC ON INPUT:\nC\nC NA MUST BE SET TO THE ROW DIMENSION OF THE TWO-DIMENSIONAL\nC ARRAY PARAMETER A AS DECLARED IN THE CALLING PROGRAM\nC DIMENSION STATEMENT. NOTE THAT NA MUST BE AT LEAST\nC AS LARGE AS M.\nC\nC NU MUST BE SET TO THE ROW DIMENSION OF THE TWO-DIMENSIONAL\nC ARRAY U AS DECLARED IN THE CALLING PROGRAM DIMENSION\nC STATEMENT. NU MUST BE AT LEAST AS LARGE AS M.\nC\nC NV MUST BE SET TO THE ROW DIMENSION OF THE TWO-DIMENSIONAL\nC ARRAY PARAMETER V AS DECLARED IN THE CALLING PROGRAM\nC DIMENSION STATEMENT. NV MUST BE AT LEAST AS LARGE AS N.\nC\nC NZ MUST BE SET TO THE ROW DIMENSION OF THE TWO-DIMENSIONAL\nC ARRAY PARAMETER Z AS DECLARED IN THE CALLING PROGRAM\nC DIMENSION STATEMENT. NOTE THAT NZ MUST BE AT LEAST\nC AS LARGE AS MIN(M,N).\nC\nC NB MUST BE SET TO THE ROW DIMENSION OF THE TWO-DIMENSIONAL\nC ARRAY PARAMETER B AS DECLARED IN THE CALLING PROGRAM\nC DIMENSION STATEMENT. NB MUST BE AT LEAST AS LARGE AS M.\nC\nC M IS THE NUMBER OF ROWS OF A (AND U).\nC\nC N IS THE NUMBER OF COLUMNS OF A (AND NUMBER OF ROWS OF V).\nC\nC A CONTAINS THE RECTANGULAR INPUT MATRIX TO BE DECOMPOSED.\nC\nC B CONTAINS THE IRHS RIGHT-HAND-SIDES OF THE OVERDETERMINED\nC LINEAR SYSTEM A*X=B. IF IRHS .GT. 0 AND M .GE. N,\nC THEN ON OUTPUT, THE FIRST N COMPONENTS OF THESE IRHS COLUMNS\nC T\nC WILL CONTAIN U B. THUS, TO COMPUTE THE MINIMAL LENGTH LEAST\nC +\nC SQUARES SOLUTION, ONE MUST COMPUTE V*W TIMES THE COLUMNS OF\nC + +\nC B, WHERE W IS A DIAGONAL MATRIX, W (I)=0 IF W(I) IS\nC NEGLIGIBLE, OTHERWISE IS 1/W(I). IF IRHS=0 OR M.LT.N,\nC B IS NOT REFERENCED.\nC\nC IRHS IS THE NUMBER OF RIGHT-HAND-SIDES OF THE OVERDETERMINED\nC SYSTEM A*X=B. IRHS SHOULD BE SET TO ZERO IF ONLY THE SINGULAR\nC VALUE DECOMPOSITION OF A IS DESIRED.\nC\nC MATU SHOULD BE SET TO .TRUE. IF THE U MATRIX IN THE\nC DECOMPOSITION IS DESIRED, AND TO .FALSE. OTHERWISE.\nC\nC MATV SHOULD BE SET TO .TRUE. IF THE V MATRIX IN THE\nC DECOMPOSITION IS DESIRED, AND TO .FALSE. OTHERWISE.\nC\nC WHEN HYBSVD IS USED TO COMPUTE THE MINIMAL LENGTH LEAST\nC SQUARES SOLUTION TO AN OVERDETERMINED SYSTEM, MATU SHOULD\nC BE SET TO .FALSE. , AND MATV SHOULD BE SET TO .TRUE. .\nC\nC ON OUTPUT:\nC\nC A IS UNALTERED (UNLESS OVERWRITTEN BY U OR V).\nC\nC W CONTAINS THE (NON-NEGATIVE) SINGULAR VALUES OF A (THE\nC DIAGONAL ELEMENTS OF W). THEY ARE SORTED IN DESCENDING\nC ORDER. IF AN ERROR EXIT IS MADE, THE SINGULAR VALUES\nC SHOULD BE CORRECT AND SORTED FOR INDICES IERR+1,...,MIN(M,N).\nC\nC U CONTAINS THE MATRIX U (ORTHOGONAL COLUMN VECTORS) OF THE\nC DECOMPOSITION IF MATU HAS BEEN SET TO .TRUE. IF MATU IS\nC FALSE, THEN U IS EITHER USED AS A TEMPORARY STORAGE (IF\nC M .GE. N) OR NOT REFERENCED (IF M .LT. N).\nC U MAY COINCIDE WITH A IN THE CALLING SEQUENCE.\nC IF AN ERROR EXIT IS MADE, THE COLUMNS OF U CORRESPONDING\nC TO INDICES OF CORRECT SINGULAR VALUES SHOULD BE CORRECT.\nC\nC V CONTAINS THE MATRIX V (ORTHOGONAL) OF THE DECOMPOSITION IF\nC MATV HAS BEEN SET TO .TRUE. IF MATV IS\nC FALSE, THEN V IS EITHER USED AS A TEMPORARY STORAGE (IF\nC M .LT. N) OR NOT REFERENCED (IF M .GE. N).\nC IF M .GE. N, V MAY ALSO COINCIDE WITH A. IF AN ERROR\nC EXIT IS MADE, THE COLUMNS OF V CORRESPONDING TO INDICES OF\nC CORRECT SINGULAR VALUES SHOULD BE CORRECT.\nC\nC Z CONTAINS THE MATRIX X IN THE SINGULAR VALUE DECOMPOSITION\nC T\nC OF R=XSY, IF THE MODIFIED ALGORITHM IS USED. IF THE\nC GOLUB-REINSCH PROCEDURE IS USED, THEN IT IS NOT REFERENCED.\nC IF MATU HAS BEEN SET TO .FALSE. IN THE CASE M.GE.N (OR\nC MATV SET TO .FALSE. IN THE CASE M.LT.N), THEN Z IS NOT\nC REFERENCED AND NO EXTRA STORAGE IS REQUIRED.\nC\nC IERR IS SET TO\nC ZERO FOR NORMAL RETURN,\nC K IF THE K-TH SINGULAR VALUE HAS NOT BEEN\nC DETERMINED AFTER 30 ITERATIONS.\nC -1 IF IRHS .LT. 0 .\nC -2 IF M .LT. 1 .OR. N .LT. 1\nC -3 IF NA .LT. M .OR. NU .LT. M .OR. NB .LT. M.\nC -4 IF NV .LT. N .\nC -5 IF NZ .LT. MIN(M,N).\nC\nC RV1 IS A TEMPORARY STORAGE ARRAY OF LENGTH AT LEAST MIN(M,N).\nC\nC PROGRAMMED BY : TONY CHAN\nC BOX 2158, YALE STATION,\nC COMPUTER SCIENCE DEPT, YALE UNIV.,\nC NEW HAVEN, CT 06520.\nC LAST MODIFIED : JANUARY, 1982.\nC\nC HYBSVD USES THE FOLLOWING FUNCTIONS AND SUBROUTINES.\nC INTERNAL GRSVD, MGNSVD, SRELPR\nC FORTRAN MIN0,DABS,DSQRT,DFLOAT,DSIGN,DMAX1\nC BLAS SSWAP\nC\nC -----------------------------------------------------------------\nC ERROR CHECK.\nC\n IERR = 0\n IF (IRHS.GE.0) GO TO 10\n IERR = -1\n RETURN\n 10 IF (M.GE.1 .AND. N.GE.1) GO TO 20\n IERR = -2\n RETURN\n 20 IF (NA.GE.M .AND. NU.GE.M .AND. NB.GE.M) GO TO 30\n IERR = -3\n RETURN\n 30 IF (NV.GE.N) GO TO 40\n IERR = -4\n RETURN\n 40 IF (NZ.GE.MIN0(M,N)) GO TO 50\n IERR = -5\n RETURN\n 50 CONTINUE\nC\nC FIRST COPIES A INTO EITHER U OR V ACCORDING TO WHETHER\nC M .GE. N OR M .LT. N, AND THEN CALLS SUBROUTINE MGNSVD\nC WHICH ASSUMES THAT NUMBER OF ROWS .GE. NUMBER OF COLUMNS.\nC\n IF (M.LT.N) GO TO 80\nC\nC M .GE. N CASE.\nC\n DO 70 I=1,M\n DO 60 J=1,N\n U(I,J) = A(I,J)\n 60 CONTINUE\n 70 CONTINUE\nC\n CALL MGNSVD(NU, NV, NZ, NB, M, N, W, MATU, U, MATV, V, Z, B,\n * IRHS, IERR, RV1)\n RETURN\nC\n 80 CONTINUE\nC T\nC M .LT. N CASE. COPIES A INTO V.\nC\n DO 100 I=1,M\n DO 90 J=1,N\n V(J,I) = A(I,J)\n 90 CONTINUE\n 100 CONTINUE\n CALL MGNSVD(NV, NU, NZ, NB, N, M, W, MATV, V, MATU, U, Z, B, 0,\n * IERR, RV1)\n RETURN\n END\nC MGN 10\n SUBROUTINE MGNSVD(NU, NV, NZ, NB, M, N, W, MATU, U, MATV, V, Z, MGN 20\n * B, IRHS, IERR, RV1)\nC\nC THE DESCRIPTION OF SUBROUTINE MGNSVD IS ALMOST IDENTICAL\nC TO THAT FOR SUBROUTINE HYBSVD ABOVE, WITH THE EXCEPTION\nC THAT MGNSVD ASSUMES M .GE. N.\nC IT ALSO ASSUMES THAT A COPY OF THE MATRIX A IS IN THE ARRAY U.\nC\n INTEGER NU, NV, NZ, M, N, IRHS, IERR, IP1, I, J, K, IM1, IBACK\n REAL*8 W(1), U(NU,1), V(NV,1), Z(NZ,1), B(NB,IRHS), RV1(1)\n REAL*8 XOVRPT, C, R, G, SCALE, DSIGN, DABS, DSQRT, F, S, H\n REAL*8 DFLOAT\n LOGICAL MATU, MATV\nC\nC SET VALUE FOR C. THE VALUE FOR C DEPENDS ON THE RELATIVE\nC EFFICIENCY OF FLOATING POINT MULTIPLICATIONS, FLOATING POINT\nC ADDITIONS AND TWO-DIMENSIONAL ARRAY INDEXINGS ON THE\nC COMPUTER WHERE THIS SUBROUTINE IS TO BE RUN. C SHOULD\nC USUALLY BE BETWEEN 2 AND 4. FOR DETAILS ON CHOOSING C, SEE\nC (2). THE ALGORITHM IS NOT SENSITIVE TO THE VALUE OF C\nC ACTUALLY USED AS LONG AS C IS BETWEEN 2 AND 4.\nC\n C = 4.d0\nC\nC DETERMINE CROSS-OVER POINT\nC\n IF (MATU .AND. MATV) XOVRPT = (C+7.d0/3.d0)/C\n IF (MATU .AND. .NOT.MATV) XOVRPT = (C+7.d0/3.d0)/C\n IF (.NOT.MATU .AND. MATV) XOVRPT = 5.d0/3.d0\n IF (.NOT.MATU .AND. .NOT.MATV) XOVRPT = 5.d0/3.d0\nC\nC DETERMINE WHETHER TO USE GOLUB-REINSCH OR THE MODIFIED\nC ALGORITHM.\nC\n R = DFLOAT(M)/DFLOAT(N)\n IF (R.GE.XOVRPT) GO TO 10\nC\nC USE GOLUB-REINSCH PROCEDURE\nC\n CALL GRSVD(NU, NV, NB, M, N, W, MATU, U, MATV, V, B, IRHS, IERR,\n * RV1)\n GO TO 330\nC\nC USE MODIFIED ALGORITHM\nC\n 10 CONTINUE\nC\nC TRIANGULARIZE U BY HOUSEHOLDER TRANSFORMATIONS, USING\nC W AND RV1 AS TEMPORARY STORAGE.\nC\n DO 110 I=1,N\n G = 0.d0\n S = 0.d0\n SCALE = 0.d0\nC\nC PERFORM SCALING OF COLUMNS TO AVOID UNNECSSARY OVERFLOW\nC OR UNDERFLOW\nC\n DO 20 K=I,M\n SCALE = SCALE + DABS(U(K,I))\n 20 CONTINUE\n IF (SCALE.EQ.0.d0) GO TO 110\n DO 30 K=I,M\n U(K,I) = U(K,I)/SCALE\n S = S + U(K,I)*U(K,I)\n 30 CONTINUE\nC\nC THE VECTOR E OF THE HOUSEHOLDER TRANSFORMATION I + EE'/H\nC WILL BE STORED IN COLUMN I OF U. THE TRANSFORMED ELEMENT\nC U(I,I) WILL BE STORED IN W(I) AND THE SCALAR H IN\nC RV1(I).\nC\n F = U(I,I)\n G = -DSIGN(DSQRT(S),F)\n H = F*G - S\n U(I,I) = F - G\n RV1(I) = H\n W(I) = SCALE*G\nC\n IF (I.EQ.N) GO TO 70\nC\nC APPLY TRANSFORMATIONS TO REMAINING COLUMNS OF A\nC\n IP1 = I + 1\n DO 60 J=IP1,N\n S = 0.d0\n DO 40 K=I,M\n S = S + U(K,I)*U(K,J)\n 40 CONTINUE\n F = S/H\n DO 50 K=I,M\n U(K,J) = U(K,J) + F*U(K,I)\n 50 CONTINUE\n 60 CONTINUE\nC\nC APPLY TRANSFORMATIONS TO COLUMNS OF B IF IRHS .GT. 0\nC\n 70 IF (IRHS.EQ.0) GO TO 110\n DO 100 J=1,IRHS\n S = 0.d0\n DO 80 K=I,M\n S = S + U(K,I)*B(K,J)\n 80 CONTINUE\n F = S/H\n DO 90 K=I,M\n B(K,J) = B(K,J) + F*U(K,I)\n 90 CONTINUE\n 100 CONTINUE\n 110 CONTINUE\nC\nC COPY R INTO Z IF MATU = .TRUE.\nC\n IF (.NOT.MATU) GO TO 290\n DO 130 I=1,N\n DO 120 J=I,N\n Z(J,I) = 0.d0\n Z(I,J) = U(I,J)\n 120 CONTINUE\n Z(I,I) = W(I)\n 130 CONTINUE\nC\nC ACCUMULATE HOUSEHOLDER TRANSFORMATIONS IN U\nC\n DO 240 IBACK=1,N\n I = N - IBACK + 1\n IP1 = I + 1\n G = W(I)\n H = RV1(I)\n IF (I.EQ.N) GO TO 150\nC\n DO 140 J=IP1,N\n U(I,J) = 0.d0\n 140 CONTINUE\nC\n 150 IF (H.EQ.0.d0) GO TO 210\n IF (I.EQ.N) GO TO 190\nC\n DO 180 J=IP1,N\n S = 0.d0\n DO 160 K=IP1,M\n S = S + U(K,I)*U(K,J)\n 160 CONTINUE\n F = S/H\n DO 170 K=I,M\n U(K,J) = U(K,J) + F*U(K,I)\n 170 CONTINUE\n 180 CONTINUE\nC\n 190 S = U(I,I)/H\n DO 200 J=I,M\n U(J,I) = U(J,I)*S\n 200 CONTINUE\n GO TO 230\nC\n 210 DO 220 J=I,M\n U(J,I) = 0.d0\n 220 CONTINUE\n 230 U(I,I) = U(I,I) + 1.d0\n 240 CONTINUE\nC\nC COMPUTE SVD OF R (WHICH IS STORED IN Z)\nC\n CALL GRSVD(NZ, NV, NB, N, N, W, MATU, Z, MATV, V, B, IRHS, IERR,\n * RV1)\nC\nC T\nC FORM L*X TO OBTAIN U (WHERE R=XWY ). X IS RETURNED IN Z\nC BY GRSVD. THE MATRIX MULTIPLY IS DONE ONE ROW AT A TIME,\nC USING RV1 AS SCRATCH SPACE.\nC\n DO 280 I=1,M\n DO 260 J=1,N\n S = 0.d0\n DO 250 K=1,N\n S = S + U(I,K)*Z(K,J)\n 250 CONTINUE\n RV1(J) = S\n 260 CONTINUE\n DO 270 J=1,N\n U(I,J) = RV1(J)\n 270 CONTINUE\n 280 CONTINUE\n GO TO 330\nC\nC FORM R IN U BY ZEROING THE LOWER TRIANGULAR PART OF R IN U\nC\n 290 IF (N.EQ.1) GO TO 320\n DO 310 I=2,N\n IM1 = I - 1\n DO 300 J=1,IM1\n U(I,J) = 0.d0\n 300 CONTINUE\n U(I,I) = W(I)\n 310 CONTINUE\n 320 U(1,1) = W(1)\nC\n CALL GRSVD(NU, NV, NB, N, N, W, MATU, U, MATV, V, B, IRHS, IERR,\n * RV1)\n 330 CONTINUE\n IERRP1 = IERR + 1\n IF (IERR.LT.0 .OR. N.LE.1 .OR. IERRP1.EQ.N) RETURN\nC\nC SORT SINGULAR VALUES AND EXCHANGE COLUMNS OF U AND V ACCORDINGLY.\nC SELECTION SORT MINIMIZES SWAPPING OF U AND V.\nC\n NM1 = N - 1\n DO 360 I=IERRP1,NM1\nC... FIND INDEX OF MAXIMUM SINGULAR VALUE\n ID = I\n IP1 = I + 1\n DO 340 J=IP1,N\n IF (W(J).GT.W(ID)) ID = J\n 340 CONTINUE\n IF (ID.EQ.I) GO TO 360\nC... SWAP SINGULAR VALUES AND VECTORS\n T = W(I)\n W(I) = W(ID)\n W(ID) = T\n IF (MATV) CALL SSWAP(N, V(1,I), 1, V(1,ID), 1)\n IF (MATU) CALL SSWAP(M, U(1,I), 1, U(1,ID), 1)\n IF (IRHS.LT.1) GO TO 360\n DO 350 KRHS=1,IRHS\n T = B(I,KRHS)\n B(I,KRHS) = B(ID,KRHS)\n B(ID,KRHS) = T\n 350 CONTINUE\n 360 CONTINUE\n RETURN\nC ************** LAST CARD OF HYBSVD *****************\n END\n SUBROUTINE GRSVD(NU, NV, NB, M, N, W, MATU, U, MATV, V, B, IRHS, GRS 10\n * IERR, RV1)\nC\n INTEGER I, J, K, L, M, N, II, I1, KK, K1, LL, L1, MN, NU, NV, NB,\n * ITS, IERR, IRHS\n REAL*8 W(1), U(NU,1), V(NV,1), B(NB,IRHS), RV1(1)\n REAL*8 C, F, G, H, S, X, Y, Z, EPS, SCALE, SRELPR, DUMMY\n REAL*8 DSQRT, DMAX1, DABS, DSIGN\n LOGICAL MATU, MATV\nC\nC THIS SUBROUTINE IS A TRANSLATION OF THE ALGOL PROCEDURE SVD,\nC NUM. MATH. 14, 403-420(1970) BY GOLUB AND REINSCH.\nC HANDBOOK FOR AUTO. COMP., VOL II-LINEAR ALGEBRA, 134-151(1971).\nC\nC THIS SUBROUTINE DETERMINES THE SINGULAR VALUE DECOMPOSITION\nC T\nC A=USV OF A REAL M BY N RECTANGULAR MATRIX. HOUSEHOLDER\nC BIDIAGONALIZATION AND A VARIANT OF THE QR ALGORITHM ARE USED.\nC GRSVD ASSUMES THAT A COPY OF THE MATRIX A IS IN THE ARRAY U. IT\nC ALSO ASSUMES M .GE. N. IF M .LT. N, THEN COMPUTE THE SINGULAR\nC T T T T\nC VALUE DECOMPOSITION OF A . IF A =UWV , THEN A=VWU .\nC\nC GRSVD CAN ALSO BE USED TO COMPUTE THE MINIMAL LENGTH LEAST SQUARES\nC SOLUTION TO THE OVERDETERMINED LINEAR SYSTEM A*X=B.\nC\nC ON INPUT-\nC\nC NU MUST BE SET TO THE ROW DIMENSION OF TWO-DIMENSIONAL\nC ARRAY PARAMETERS U AS DECLARED IN THE CALLING PROGRAM\nC DIMENSION STATEMENT. NOTE THAT NU MUST BE AT LEAST\nC AS LARGE AS M,\nC\nC NV MUST BE SET TO THE ROW DIMENSION OF THE TWO-DIMENSIONAL\nC ARRAY PARAMETER V AS DECLARED IN THE CALLING PROGRAM\nC DIMENSION STATEMENT. NV MUST BE AT LEAST AS LARGE AS N,\nC\nC NB MUST BE SET TO THE ROW DIMENSION OF TWO-DIMENSIONAL\nC ARRAY PARAMETERS B AS DECLARED IN THE CALLING PROGRAM\nC DIMENSION STATEMENT. NOTE THAT NB MUST BE AT LEAST\nC AS LARGE AS M,\nC\nC M IS THE NUMBER OF ROWS OF A (AND U),\nC\nC N IS THE NUMBER OF COLUMNS OF A (AND U) AND THE ORDER OF V,\nC\nC A CONTAINS THE RECTANGULAR INPUT MATRIX TO BE DECOMPOSED,\nC\nC B CONTAINS THE IRHS RIGHT-HAND-SIDES OF THE OVERDETERMINED\nC LINEAR SYSTEM A*X=B. IF IRHS .GT. 0, THEN ON OUTPUT,\nC THE FIRST N COMPONENTS OF THESE IRHS COLUMNS OF B\nC T\nC WILL CONTAIN U B. THUS, TO COMPUTE THE MINIMAL LENGTH LEAST\nC +\nC SQUARES SOLUTION, ONE MUST COMPUTE V*W TIMES THE COLUMNS OF\nC + +\nC B, WHERE W IS A DIAGONAL MATRIX, W (I)=0 IF W(I) IS\nC NEGLIGIBLE, OTHERWISE IS 1/W(I). IF IRHS=0, B MAY COINCIDE\nC WITH A OR U AND WILL NOT BE REFERENCED,\nC\nC IRHS IS THE NUMBER OF RIGHT-HAND-SIDES OF THE OVERDETERMINED\nC SYSTEM A*X=B. IRHS SHOULD BE SET TO ZERO IF ONLY THE SINGULA\nC VALUE DECOMPOSITION OF A IS DESIRED,\nC\nC MATU SHOULD BE SET TO .TRUE. IF THE U MATRIX IN THE\nC DECOMPOSITION IS DESIRED, AND TO .FALSE. OTHERWISE,\nC\nC MATV SHOULD BE SET TO .TRUE. IF THE V MATRIX IN THE\nC DECOMPOSITION IS DESIRED, AND TO .FALSE. OTHERWISE.\nC\nC ON OUTPUT-\nC\nC W CONTAINS THE N (NON-NEGATIVE) SINGULAR VALUES OF A (THE\nC DIAGONAL ELEMENTS OF S). THEY ARE UNORDERED. IF AN\nC ERROR EXIT IS MADE, THE SINGULAR VALUES SHOULD BE CORRECT\nC FOR INDICES IERR+1,IERR+2,...,N,\nC\nC U CONTAINS THE MATRIX U (ORTHOGONAL COLUMN VECTORS) OF THE\nC DECOMPOSITION IF MATU HAS BEEN SET TO .TRUE. OTHERWISE\nC U IS USED AS A TEMPORARY ARRAY.\nC IF AN ERROR EXIT IS MADE, THE COLUMNS OF U CORRESPONDING\nC TO INDICES OF CORRECT SINGULAR VALUES SHOULD BE CORRECT,\nC\nC V CONTAINS THE MATRIX V (ORTHOGONAL) OF THE DECOMPOSITION IF\nC MATV HAS BEEN SET TO .TRUE. OTHERWISE V IS NOT REFERENCED.\nC IF AN ERROR EXIT IS MADE, THE COLUMNS OF V CORRESPONDING TO\nC INDICES OF CORRECT SINGULAR VALUES SHOULD BE CORRECT,\nC\nC IERR IS SET TO\nC ZERO FOR NORMAL RETURN,\nC K IF THE K-TH SINGULAR VALUE HAS NOT BEEN\nC DETERMINED AFTER 30 ITERATIONS,\nC -1 IF IRHS .LT. 0 ,\nC -2 IF M .LT. N ,\nC -3 IF NU .LT. M .OR. NB .LT. M,\nC -4 IF NV .LT. N .\nC\nC RV1 IS A TEMPORARY STORAGE ARRAY.\nC\nC THIS SUBROUTINE HAS BEEN CHECKED BY THE PFORT VERIFIER\nC (RYDER, B.G. 'THE PFORT VERIFIER', SOFTWARE - PRACTICE AND\nC EXPERIENCE, VOL.4, 359-377, 1974) FOR ADHERENCE TO A LARGE,\nC CAREFULLY DEFINED, PORTABLE SUBSET OF AMERICAN NATIONAL STANDAR\nC FORTRAN CALLED PFORT.\nC\nC ORIGINAL VERSION OF THIS CODE IS SUBROUTINE SVD IN RELEASE 2 OF\nC EISPACK.\nC\nC MODIFIED BY TONY F. CHAN,\nC COMP. SCI. DEPT, YALE UNIV.,\nC BOX 2158, YALE STATION,\nC CT 06520\nC LAST MODIFIED : JANUARY, 1982.\nC\nC ------------------------------------------------------------------\nC\nC ********** SRELPR IS A MACHINE-DEPENDENT FUNCTION SPECIFYING\nC THE RELATIVE PRECISION OF FLOATING POINT ARITHMETIC.\nC\nC **********\nC\n IERR = 0\n IF (IRHS.GE.0) GO TO 10\n IERR = -1\n RETURN\n 10 IF (M.GE.N) GO TO 20\n IERR = -2\n RETURN\n 20 IF (NU.GE.M .AND. NB.GE.M) GO TO 30\n IERR = -3\n RETURN\n 30 IF (NV.GE.N) GO TO 40\n IERR = -4\n RETURN\n 40 CONTINUE\nC\nC ********** HOUSEHOLDER REDUCTION TO BIDIAGONAL FORM **********\n G = 0.d0\n SCALE = 0.d0\n X = 0.d0\nC\n DO 260 I=1,N\n L = I + 1\n RV1(I) = SCALE*G\n G = 0.d0\n S = 0.d0\n SCALE = 0.d0\nC\nC COMPUTE LEFT TRANSFORMATIONS THAT ZERO THE SUBDIAGONAL ELEMENTS\nC OF THE I-TH COLUMN.\nC\n DO 50 K=I,M\n SCALE = SCALE + DABS(U(K,I))\n 50 CONTINUE\nC\n IF (SCALE.EQ.0.d0) GO TO 160\nC\n DO 60 K=I,M\n U(K,I) = U(K,I)/SCALE\n S = S + U(K,I)**2\n 60 CONTINUE\nC\n F = U(I,I)\n G = -DSIGN(DSQRT(S),F)\n H = F*G - S\n U(I,I) = F - G\n IF (I.EQ.N) GO TO 100\nC\nC APPLY LEFT TRANSFORMATIONS TO REMAINING COLUMNS OF A.\nC\n DO 90 J=L,N\n S = 0.d0\nC\n DO 70 K=I,M\n S = S + U(K,I)*U(K,J)\n 70 CONTINUE\nC\n F = S/H\nC\n DO 80 K=I,M\n U(K,J) = U(K,J) + F*U(K,I)\n 80 CONTINUE\n 90 CONTINUE\nC\nC APPLY LEFT TRANSFORMATIONS TO THE COLUMNS OF B IF IRHS .GT. 0\nC\n 100 IF (IRHS.EQ.0) GO TO 140\n DO 130 J=1,IRHS\n S = 0.d0\n DO 110 K=I,M\n S = S + U(K,I)*B(K,J)\n 110 CONTINUE\n F = S/H\n DO 120 K=I,M\n B(K,J) = B(K,J) + F*U(K,I)\n 120 CONTINUE\n 130 CONTINUE\nC\nC COMPUTE RIGHT TRANSFORMATIONS.\nC\n 140 DO 150 K=I,M\n U(K,I) = SCALE*U(K,I)\n 150 CONTINUE\nC\n 160 W(I) = SCALE*G\n G = 0.d0\n S = 0.d0\n SCALE = 0.d0\n IF (I.GT.M .OR. I.EQ.N) GO TO 250\nC\n DO 170 K=L,N\n SCALE = SCALE + DABS(U(I,K))\n 170 CONTINUE\nC\n IF (SCALE.EQ.0.d0) GO TO 250\nC\n DO 180 K=L,N\n U(I,K) = U(I,K)/SCALE\n S = S + U(I,K)**2\n 180 CONTINUE\nC\n F = U(I,L)\n G = -DSIGN(DSQRT(S),F)\n H = F*G - S\n U(I,L) = F - G\nC\n DO 190 K=L,N\n RV1(K) = U(I,K)/H\n 190 CONTINUE\nC\n IF (I.EQ.M) GO TO 230\nC\n DO 220 J=L,M\n S = 0.d0\nC\n DO 200 K=L,N\n S = S + U(J,K)*U(I,K)\n 200 CONTINUE\nC\n DO 210 K=L,N\n U(J,K) = U(J,K) + S*RV1(K)\n 210 CONTINUE\n 220 CONTINUE\nC\n 230 DO 240 K=L,N\n U(I,K) = SCALE*U(I,K)\n 240 CONTINUE\nC\n 250 X = DMAX1(X,DABS(W(I))+DABS(RV1(I)))\n 260 CONTINUE\nC ********** ACCUMULATION OF RIGHT-HAND TRANSFORMATIONS **********\n IF (.NOT.MATV) GO TO 350\nC ********** FOR I=N STEP -1 UNTIL 1 DO -- **********\n DO 340 II=1,N\n I = N + 1 - II\n IF (I.EQ.N) GO TO 330\n IF (G.EQ.0.d0) GO TO 310\nC\n DO 270 J=L,N\nC ********** DOUBLE DIVISION AVOIDS POSSIBLE UNDERFLOW **********\n V(J,I) = (U(I,J)/U(I,L))/G\n 270 CONTINUE\nC\n DO 300 J=L,N\n S = 0.d0\nC\n DO 280 K=L,N\n S = S + U(I,K)*V(K,J)\n 280 CONTINUE\nC\n DO 290 K=L,N\n V(K,J) = V(K,J) + S*V(K,I)\n 290 CONTINUE\n 300 CONTINUE\nC\n 310 DO 320 J=L,N\n V(I,J) = 0.d0\n V(J,I) = 0.d0\n 320 CONTINUE\nC\n 330 V(I,I) = 1.d0\n G = RV1(I)\n L = I\n 340 CONTINUE\nC ********** ACCUMULATION OF LEFT-HAND TRANSFORMATIONS **********\n 350 IF (.NOT.MATU) GO TO 470\nC **********FOR I=MIN(M,N) STEP -1 UNTIL 1 DO -- **********\n MN = N\n IF (M.LT.N) MN = M\nC\n DO 460 II=1,MN\n I = MN + 1 - II\n L = I + 1\n G = W(I)\n IF (I.EQ.N) GO TO 370\nC\n DO 360 J=L,N\n U(I,J) = 0.d0\n 360 CONTINUE\nC\n 370 IF (G.EQ.0.d0) GO TO 430\n IF (I.EQ.MN) GO TO 410\nC\n DO 400 J=L,N\n S = 0.d0\nC\n DO 380 K=L,M\n S = S + U(K,I)*U(K,J)\n 380 CONTINUE\nC ********** DOUBLE DIVISION AVOIDS POSSIBLE UNDERFLOW **********\n F = (S/U(I,I))/G\nC\n DO 390 K=I,M\n U(K,J) = U(K,J) + F*U(K,I)\n 390 CONTINUE\n 400 CONTINUE\nC\n 410 DO 420 J=I,M\n U(J,I) = U(J,I)/G\n 420 CONTINUE\nC\n GO TO 450\nC\n 430 DO 440 J=I,M\n U(J,I) = 0.d0\n 440 CONTINUE\nC\n 450 U(I,I) = U(I,I) + 1.d0\n 460 CONTINUE\nC ********** DIAGONALIZATION OF THE BIDIAGONAL FORM **********\n 470 EPS = SRELPR(DUMMY)*X\nC ********** FOR K=N STEP -1 UNTIL 1 DO -- **********\n DO 650 KK=1,N\n K1 = N - KK\n K = K1 + 1\n ITS = 0\nC ********** TEST FOR SPLITTING.\nC FOR L=K STEP -1 UNTIL 1 DO -- **********\n 480 DO 490 LL=1,K\n L1 = K - LL\n L = L1 + 1\n IF (DABS(RV1(L)).LE.EPS) GO TO 550\nC ********** RV1(1) IS ALWAYS ZERO, SO THERE IS NO EXIT\nC THROUGH THE BOTTOM OF THE LOOP **********\n IF (DABS(W(L1)).LE.EPS) GO TO 500\n 490 CONTINUE\nC ********** CANCELLATION OF RV1(L) IF L GREATER THAN 1 **********\n 500 C = 0.d0\n S = 1.d0\nC\n DO 540 I=L,K\n F = S*RV1(I)\n RV1(I) = C*RV1(I)\n IF (DABS(F).LE.EPS) GO TO 550\n G = W(I)\n H = DSQRT(F*F+G*G)\n W(I) = H\n C = G/H\n S = -F/H\nC\nC APPLY LEFT TRANSFORMATIONS TO B IF IRHS .GT. 0\nC\n IF (IRHS.EQ.0) GO TO 520\n DO 510 J=1,IRHS\n Y = B(L1,J)\n Z = B(I,J)\n B(L1,J) = Y*C + Z*S\n B(I,J) = -Y*S + Z*C\n 510 CONTINUE\n 520 CONTINUE\nC\n IF (.NOT.MATU) GO TO 540\nC\n DO 530 J=1,M\n Y = U(J,L1)\n Z = U(J,I)\n U(J,L1) = Y*C + Z*S\n U(J,I) = -Y*S + Z*C\n 530 CONTINUE\nC\n 540 CONTINUE\nC ********** TEST FOR CONVERGENCE **********\n 550 Z = W(K)\n IF (L.EQ.K) GO TO 630\nC ********** SHIFT FROM BOTTOM 2 BY 2 MINOR **********\n IF (ITS.EQ.30) GO TO 660\n ITS = ITS + 1\n X = W(L)\n Y = W(K1)\n G = RV1(K1)\n H = RV1(K)\n F = ((Y-Z)*(Y+Z)+(G-H)*(G+H))/(2.d0*H*Y)\n G = DSQRT(F*F+1.0)\n F = ((X-Z)*(X+Z)+H*(Y/(F+DSIGN(G,F))-H))/X\nC ********** NEXT QR TRANSFORMATION **********\n C = 1.0\n S = 1.0\nC\n DO 620 I1=L,K1\n I = I1 + 1\n G = RV1(I)\n Y = W(I)\n H = S*G\n G = C*G\n Z = DSQRT(F*F+H*H)\n RV1(I1) = Z\n C = F/Z\n S = H/Z\n F = X*C + G*S\n G = -X*S + G*C\n H = Y*S\n Y = Y*C\n IF (.NOT.MATV) GO TO 570\nC\n DO 560 J=1,N\n X = V(J,I1)\n Z = V(J,I)\n V(J,I1) = X*C + Z*S\n V(J,I) = -X*S + Z*C\n 560 CONTINUE\nC\n 570 Z = DSQRT(F*F+H*H)\n W(I1) = Z\nC ********** ROTATION CAN BE ARBITRARY IF Z IS ZERO **********\n IF (Z.EQ.0.d0) GO TO 580\n C = F/Z\n S = H/Z\n 580 F = C*G + S*Y\n X = -S*G + C*Y\nC\nC APPLY LEFT TRANSFORMATIONS TO B IF IRHS .GT. 0\nC\n IF (IRHS.EQ.0) GO TO 600\n DO 590 J=1,IRHS\n Y = B(I1,J)\n Z = B(I,J)\n B(I1,J) = Y*C + Z*S\n B(I,J) = -Y*S + Z*C\n 590 CONTINUE\n 600 CONTINUE\nC\n IF (.NOT.MATU) GO TO 620\nC\n DO 610 J=1,M\n Y = U(J,I1)\n Z = U(J,I)\n U(J,I1) = Y*C + Z*S\n U(J,I) = -Y*S + Z*C\n 610 CONTINUE\nC\n 620 CONTINUE\nC\n RV1(L) = 0.d0\n RV1(K) = F\n W(K) = X\n GO TO 480\nC ********** CONVERGENCE **********\n 630 IF (Z.GE.0.d0) GO TO 650\nC ********** W(K) IS MADE NON-NEGATIVE **********\n W(K) = -Z\n IF (.NOT.MATV) GO TO 650\nC\n DO 640 J=1,N\n V(J,K) = -V(J,K)\n 640 CONTINUE\nC\n 650 CONTINUE\nC\n GO TO 670\nC ********** SET ERROR -- NO CONVERGENCE TO A\nC SINGULAR VALUE AFTER 30 ITERATIONS **********\n 660 IERR = K\n 670 RETURN\nC ********** LAST CARD OF GRSVD **********\n END\n SUBROUTINE SSWAP(N, SX, INCX, SY, INCY) SSW 10\nC\nC INTERCHANGES TWO VECTORS.\nC USES UNROLLED LOOPS FOR INCREMENTS EQUAL TO 1.\nC JACK DONGARRA, LINPACK, 3/11/78.\nC\n REAL*8 SX(1), SY(1), STEMP\n INTEGER I, INCX, INCY, IX, IY, M, MP1, N\nC\n IF (N.LE.0) RETURN\n IF (INCX.EQ.1 .AND. INCY.EQ.1) GO TO 20\nC\nC CODE FOR UNEQUAL INCREMENTS OR EQUAL INCREMENTS NOT EQUAL\nC TO 1\nC\n IX = 1\n IY = 1\n IF (INCX.LT.0) IX = (-N+1)*INCX + 1\n IF (INCY.LT.0) IY = (-N+1)*INCY + 1\n DO 10 I=1,N\n STEMP = SX(IX)\n SX(IX) = SY(IY)\n SY(IY) = STEMP\n IX = IX + INCX\n IY = IY + INCY\n 10 CONTINUE\n RETURN\nC\nC CODE FOR BOTH INCREMENTS EQUAL TO 1\nC\nC\nC CLEAN-UP LOOP\nC\n 20 M = MOD(N,3)\n IF (M.EQ.0) GO TO 40\n DO 30 I=1,M\n STEMP = SX(I)\n SX(I) = SY(I)\n SY(I) = STEMP\n 30 CONTINUE\n IF (N.LT.3) RETURN\n 40 MP1 = M + 1\n DO 50 I=MP1,N,3\n STEMP = SX(I)\n SX(I) = SY(I)\n SY(I) = STEMP\n STEMP = SX(I+1)\n SX(I+1) = SY(I+1)\n SY(I+1) = STEMP\n STEMP = SX(I+2)\n SX(I+2) = SY(I+2)\n SY(I+2) = STEMP\n 50 CONTINUE\n RETURN\n END\n REAL*8 FUNCTION SRELPR(DUMMY) SRE 10\n REAL*8 DUMMY\nC\nC SRELPR COMPUTES THE RELATIVE PRECISION OF THE FLOATING POINT\nC ARITHMETIC OF THE MACHINE.\nC\nC IF TROUBLE WITH AUTOMATIC COMPUTATION OF THESE QUANTITIES,\nC THEY CAN BE SET BY DIRECT ASSIGNMENT STATEMENTS.\nC ASSUME THE COMPUTER HAS\nC\nC B = BASE OF ARITHMETIC\nC T = NUMBER OF BASE B DIGITS\nC\nC THEN\nC\nC SRELPR = B**(1-T)\nC\n REAL*8 S\nC\n SRELPR = 1.d0\n 10 SRELPR = SRELPR/2.d0\n S = 1.d0 + SRELPR\n IF (S.GT.1.d0) GO TO 10\n SRELPR = 2.d0*SRELPR\n RETURN\n END\n", "meta": {"hexsha": "e03c1f877f857bf5ca59c3e181b1b11dddfac4c7", "size": 30206, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ccx_prool/CalculiX/ccx_2.9/src/hybsvd.f", "max_stars_repo_name": "alleindrach/calculix-desktop", "max_stars_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ccx_prool/CalculiX/ccx_2.9/src/hybsvd.f", "max_issues_repo_name": "alleindrach/calculix-desktop", "max_issues_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2017-09-21T17:03:55.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-25T16:08:31.000Z", "max_forks_repo_path": "ccx_prool/CalculiX/ccx_2.9/src/hybsvd.f", "max_forks_repo_name": "alleindrach/calculix-desktop", "max_forks_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-08-29T18:41:28.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-29T18:41:28.000Z", "avg_line_length": 29.8773491592, "max_line_length": 82, "alphanum_fraction": 0.5219823876, "num_tokens": 10846, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425377849806, "lm_q2_score": 0.7090191337850933, "lm_q1q2_score": 0.6520441555322319}} {"text": "*> \\brief SGBSV computes the solution to system of linear equations A * X = B for GB matrices (simple driver)\n*\n* =========== DOCUMENTATION ===========\n*\n* Online html documentation available at \n* http://www.netlib.org/lapack/explore-html/ \n*\n*> \\htmlonly\n*> Download SGBSV + dependencies \n*> \n*> [TGZ] \n*> \n*> [ZIP] \n*> \n*> [TXT]\n*> \\endhtmlonly \n*\n* Definition:\n* ===========\n*\n* SUBROUTINE SGBSV( N, KL, KU, NRHS, AB, LDAB, IPIV, B, LDB, INFO )\n* \n* .. Scalar Arguments ..\n* INTEGER INFO, KL, KU, LDAB, LDB, N, NRHS\n* ..\n* .. Array Arguments ..\n* INTEGER IPIV( * )\n* REAL AB( LDAB, * ), B( LDB, * )\n* ..\n* \n*\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*>\n*> SGBSV computes the solution to a real system of linear equations\n*> A * X = B, where A is a band matrix of order N with KL subdiagonals\n*> and KU superdiagonals, and X and B are N-by-NRHS matrices.\n*>\n*> The LU decomposition with partial pivoting and row interchanges is\n*> used to factor A as A = L * U, where L is a product of permutation\n*> and unit lower triangular matrices with KL subdiagonals, and U is\n*> upper triangular with KL+KU superdiagonals. The factored form of A\n*> is then used to solve the system of equations A * X = B.\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in] N\n*> \\verbatim\n*> N is INTEGER\n*> The number of linear equations, i.e., the order of the\n*> matrix A. N >= 0.\n*> \\endverbatim\n*>\n*> \\param[in] KL\n*> \\verbatim\n*> KL is INTEGER\n*> The number of subdiagonals within the band of A. KL >= 0.\n*> \\endverbatim\n*>\n*> \\param[in] KU\n*> \\verbatim\n*> KU is INTEGER\n*> The number of superdiagonals within the band of A. KU >= 0.\n*> \\endverbatim\n*>\n*> \\param[in] NRHS\n*> \\verbatim\n*> NRHS is INTEGER\n*> The number of right hand sides, i.e., the number of columns\n*> of the matrix B. NRHS >= 0.\n*> \\endverbatim\n*>\n*> \\param[in,out] AB\n*> \\verbatim\n*> AB is REAL array, dimension (LDAB,N)\n*> On entry, the matrix A in band storage, in rows KL+1 to\n*> 2*KL+KU+1; rows 1 to KL of the array need not be set.\n*> The j-th column of A is stored in the j-th column of the\n*> array AB as follows:\n*> AB(KL+KU+1+i-j,j) = A(i,j) for max(1,j-KU)<=i<=min(N,j+KL)\n*> On exit, details of the factorization: U is stored as an\n*> upper triangular band matrix with KL+KU superdiagonals in\n*> rows 1 to KL+KU+1, and the multipliers used during the\n*> factorization are stored in rows KL+KU+2 to 2*KL+KU+1.\n*> See below for further details.\n*> \\endverbatim\n*>\n*> \\param[in] LDAB\n*> \\verbatim\n*> LDAB is INTEGER\n*> The leading dimension of the array AB. LDAB >= 2*KL+KU+1.\n*> \\endverbatim\n*>\n*> \\param[out] IPIV\n*> \\verbatim\n*> IPIV is INTEGER array, dimension (N)\n*> The pivot indices that define the permutation matrix P;\n*> row i of the matrix was interchanged with row IPIV(i).\n*> \\endverbatim\n*>\n*> \\param[in,out] B\n*> \\verbatim\n*> B is REAL array, dimension (LDB,NRHS)\n*> On entry, the N-by-NRHS right hand side matrix B.\n*> On exit, if INFO = 0, the N-by-NRHS solution matrix X.\n*> \\endverbatim\n*>\n*> \\param[in] LDB\n*> \\verbatim\n*> LDB is INTEGER\n*> The leading dimension of the array B. LDB >= max(1,N).\n*> \\endverbatim\n*>\n*> \\param[out] INFO\n*> \\verbatim\n*> INFO is INTEGER\n*> = 0: successful exit\n*> < 0: if INFO = -i, the i-th argument had an illegal value\n*> > 0: if INFO = i, U(i,i) is exactly zero. The factorization\n*> has been completed, but the factor U is exactly\n*> singular, and the solution has not been computed.\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee \n*> \\author Univ. of California Berkeley \n*> \\author Univ. of Colorado Denver \n*> \\author NAG Ltd. \n*\n*> \\date November 2011\n*\n*> \\ingroup realGBsolve\n*\n*> \\par Further Details:\n* =====================\n*>\n*> \\verbatim\n*>\n*> The band storage scheme is illustrated by the following example, when\n*> M = N = 6, KL = 2, KU = 1:\n*>\n*> On entry: On exit:\n*>\n*> * * * + + + * * * u14 u25 u36\n*> * * + + + + * * u13 u24 u35 u46\n*> * a12 a23 a34 a45 a56 * u12 u23 u34 u45 u56\n*> a11 a22 a33 a44 a55 a66 u11 u22 u33 u44 u55 u66\n*> a21 a32 a43 a54 a65 * m21 m32 m43 m54 m65 *\n*> a31 a42 a53 a64 * * m31 m42 m53 m64 * *\n*>\n*> Array elements marked * are not used by the routine; elements marked\n*> + need not be set on entry, but are required by the routine to store\n*> elements of U because of fill-in resulting from the row interchanges.\n*> \\endverbatim\n*>\n* =====================================================================\n SUBROUTINE SGBSV( N, KL, KU, NRHS, AB, LDAB, IPIV, B, LDB, INFO )\n*\n* -- LAPACK driver routine (version 3.4.0) --\n* -- LAPACK is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n* November 2011\n*\n* .. Scalar Arguments ..\n INTEGER INFO, KL, KU, LDAB, LDB, N, NRHS\n* ..\n* .. Array Arguments ..\n INTEGER IPIV( * )\n REAL AB( LDAB, * ), B( LDB, * )\n* ..\n*\n* =====================================================================\n*\n* .. External Subroutines ..\n EXTERNAL SGBTRF, SGBTRS, XERBLA\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC MAX\n* ..\n* .. Executable Statements ..\n*\n* Test the input parameters.\n*\n INFO = 0\n IF( N.LT.0 ) THEN\n INFO = -1\n ELSE IF( KL.LT.0 ) THEN\n INFO = -2\n ELSE IF( KU.LT.0 ) THEN\n INFO = -3\n ELSE IF( NRHS.LT.0 ) THEN\n INFO = -4\n ELSE IF( LDAB.LT.2*KL+KU+1 ) THEN\n INFO = -6\n ELSE IF( LDB.LT.MAX( N, 1 ) ) THEN\n INFO = -9\n END IF\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'SGBSV ', -INFO )\n RETURN\n END IF\n*\n* Compute the LU factorization of the band matrix A.\n*\n CALL SGBTRF( N, N, KL, KU, AB, LDAB, IPIV, INFO )\n IF( INFO.EQ.0 ) THEN\n*\n* Solve the system A*X = B, overwriting B with X.\n*\n CALL SGBTRS( 'No transpose', N, KL, KU, NRHS, AB, LDAB, IPIV,\n $ B, LDB, INFO )\n END IF\n RETURN\n*\n* End of SGBSV\n*\n END\n", "meta": {"hexsha": "308e38d62f9969859aa9a98a93ee4c5b0c33e976", "size": 7026, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "netlib/LAPACK/sgbsv.f", "max_stars_repo_name": "debasish83/netlib-java", "max_stars_repo_head_hexsha": "38a78797d57339395bf10f3d65baeda8570d27e3", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 624, "max_stars_repo_stars_event_min_datetime": "2015-01-10T02:29:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-26T22:06:35.000Z", "max_issues_repo_path": "third-party/CoinIpopt/ThirdParty/Lapack/LAPACK/SRC/sgbsv.f", "max_issues_repo_name": "WatsonZhouAnda/Cheetah-Software", "max_issues_repo_head_hexsha": "05e416fb26f968300826f0deb0953be9afb22bfe", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 59, "max_issues_repo_issues_event_min_datetime": "2015-01-01T10:34:19.000Z", "max_issues_repo_issues_event_max_datetime": "2017-07-24T14:20:38.000Z", "max_forks_repo_path": "third-party/CoinIpopt/ThirdParty/Lapack/LAPACK/SRC/sgbsv.f", "max_forks_repo_name": "WatsonZhouAnda/Cheetah-Software", "max_forks_repo_head_hexsha": "05e416fb26f968300826f0deb0953be9afb22bfe", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 154, "max_forks_repo_forks_event_min_datetime": "2015-01-03T22:48:26.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-07T04:58:57.000Z", "avg_line_length": 31.3660714286, "max_line_length": 117, "alphanum_fraction": 0.5394249929, "num_tokens": 2199, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9196425311777929, "lm_q2_score": 0.7090191276365462, "lm_q1q2_score": 0.6520441451931439}} {"text": " DOUBLE PRECISION FUNCTION DAPOLY(N,P)\r\nC\r\nC CALCULATES AREA OF A POLYGON DESCRIBED BY N POINTS (P)\r\nC ( N .LE. 10 )\r\nC\r\nC AREA= -1* LINE INTEGRAL OF Y*DX\r\nC\r\nC AREA CONTRIBUTION FROM SIDE WHOSE ENDS ARE P(I), P(J):\r\nC A(I,J)= 0.5 * (Y(I)+Y(J)) * (X(I)-X(J))\r\nC\r\n DOUBLE PRECISION P(2,1)\r\n INTEGER KEDGE(2,10), K(2,10)\r\nC\r\n DATA KEDGE/ 1,2, 2,3, 3,4, 4,5, 5,6, 6,7, 7,8, 8,9, 9,10,\r\n 1 10,1/\r\nC\r\n DO 10 I=1,2\r\n DO 10 J=1,N\r\n 10 K(I,J)= KEDGE(I,J)\r\n K(2,N)= 1\r\n DAPOLY= 0.0\r\nC\r\n DO 20 NN= 1,N\r\n K1= K(1,NN)\r\n K2= K(2,NN)\r\n 20 DAPOLY= DAPOLY +5.D-1 * (P(2,K1)+P(2,K2)) * (P(1,K1)-P(1,K2))\r\n RETURN\r\n END\r\n", "meta": {"hexsha": "761cf5993f604d40be40d05c7bf3a84058a76dd2", "size": 715, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "mis/dapoly.f", "max_stars_repo_name": "ldallolio/NASTRAN-95", "max_stars_repo_head_hexsha": "6d2c175f5b53ebaec4ba2b5186f7926ef9d0ed47", "max_stars_repo_licenses": ["NASA-1.3"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2016-01-09T14:33:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-18T11:51:42.000Z", "max_issues_repo_path": "mis/dapoly.f", "max_issues_repo_name": "gassive/NASTRAN95", "max_issues_repo_head_hexsha": "98cb3acaa7990d639360601648498834c7782056", "max_issues_repo_licenses": ["NASA-1.3"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2016-01-17T07:30:19.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-06T19:37:44.000Z", "max_forks_repo_path": "mis/dapoly.f", "max_forks_repo_name": "gassive/NASTRAN95", "max_forks_repo_head_hexsha": "98cb3acaa7990d639360601648498834c7782056", "max_forks_repo_licenses": ["NASA-1.3"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-04-07T20:51:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-04T14:16:01.000Z", "avg_line_length": 24.6551724138, "max_line_length": 72, "alphanum_fraction": 0.4685314685, "num_tokens": 342, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533126145178, "lm_q2_score": 0.6992544335934766, "lm_q1q2_score": 0.6520221129646256}} {"text": "SUBROUTINE gcf(gammcf,a,x,gln)\nINTEGER ITMAX\nREAL a,gammcf,gln,x,EPS,FPMIN\nPARAMETER (ITMAX=100,EPS=3.e-7,FPMIN=1.e-30)\n!CU USES gammln\nINTEGER i\nREAL an,b,c,d,del,h,gammln\ngln=gammln(a)\nb=x+1.-a\nc=1./FPMIN\nd=1./b\nh=d\ndo i=1,ITMAX\n an=-i*(i-a)\n b=b+2.\n d=an*d+b\n if(abs(d).lt.FPMIN)d=FPMIN\n c=b+an/c\n if(abs(c).lt.FPMIN)c=FPMIN\n d=1./d\n del=d*c\n h=h*del\n if(abs(del-1.).lt.EPS)goto 1\nenddo\npause 'a too large, ITMAX too small in gcf'\n1 gammcf=exp(-x+a*log(x)-gln)*h\nreturn\nEND\n", "meta": {"hexsha": "c69447e1f57d209b68163f65af296cea454ed4db", "size": 494, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tchi/gcf.f90", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tchi/gcf.f90", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tchi/gcf.f90", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.0344827586, "max_line_length": 44, "alphanum_fraction": 0.6457489879, "num_tokens": 246, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357701094303, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6520218010218006}} {"text": "\tsubroutine fastf(Fr,Fi,n)\nc\nc\tn = the number of data points=2**m\nc\tFr = the real data set\nc\tFi is the imaginary part of data set (=0.0 if only real)\nc\nc\tfirst compute m\nc\n\treal*4 Fr(n), Fi(n), Gr, Gi, Er, Ei, Eu, Ez\n\tm=0\n\tkd=n\n 1\tkd=kd/2\n\tm=m+1\n\tif (kd .ge. 2) go to 1\n\tnd2=n/2\n\tnm1=n-1\n\tl=1\nc\nc\tshuffle input data in binary digit reverse order\nc\n\tdo 4 k=1,nm1\n\tif (k .ge. l) go to 2\n\tGr=Fr(l)\n\tGi=Fi(l)\n\tFr(l)=Fr(k)\n\tFi(l)=Fi(k)\n\tFr(k)=Gr\n\tFi(k)=Gi\n 2\tnnd2=nd2\n ! 3\tif(nnd2 .ge. l) go to 4\n 3\tif(nnd2 .lt. l) then\n\t l=l-nnd2\n\t nnd2=nnd2/2\n\t go to 3\n endif\n ! 4\tl=l+nnd2\n 4 continue\n \tl=l+nnd2\n\tpi=3.14159265\nc\nc\tfirst arrange accounting of m stage\nc\n\tdo 7 j=1,m\n\tnj=2**j\n\tnjd2=nj/2\n\tEu=1.0\n\tEz=0.0\n\tEr=cos(-pi/njd2)\n\tEi=sin(-pi/njd2)\nc\nc\tcompute fourie transform in each m stage\nc\n\tdo 6 it=1,njd2\n do 5 iw=it,n,nj\n\t iwj=iw+njd2\n\t Gr=Fr(iwj)*Eu-Fi(iwj)*Ez\n\t Gi=Fi(iwj)*Eu+Fr(iwj)*Ez\n\t Fr(iwj)=Fr(iw)-Gr\n\t Fi(iwj)=Fi(iw)-Gi\n\t Fr(iw) =Fr(iw)+Gr\n !5\tFi(iw) =Fi(iw)+Gi\n Fi(iw) =Fi(iw)+Gi\n 5 continue\n\t Seu=Eu\n\t Eu=Seu*Er-Ez*Ei\n ! 6\tEz=Ez*Er+Seu*Ei\n Ez=Ez*Er+Seu*Ei\n 6 continue\n 7 continue\n\tReturn\n\tEnd\n", "meta": {"hexsha": "f559807e8cca2871ac33d6c04f69f640fc2fd5f4", "size": 1218, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "fastf.f", "max_stars_repo_name": "henkart/sioseis-2020.5.0", "max_stars_repo_head_hexsha": "1c7e606b5a3a615abf3cdd6687115f8a4117e855", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fastf.f", "max_issues_repo_name": "henkart/sioseis-2020.5.0", "max_issues_repo_head_hexsha": "1c7e606b5a3a615abf3cdd6687115f8a4117e855", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fastf.f", "max_forks_repo_name": "henkart/sioseis-2020.5.0", "max_forks_repo_head_hexsha": "1c7e606b5a3a615abf3cdd6687115f8a4117e855", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.9166666667, "max_line_length": 58, "alphanum_fraction": 0.5566502463, "num_tokens": 587, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.7520125737597972, "lm_q1q2_score": 0.6520217932706117}} {"text": "C PROGRAM No. 2: DISCRETE VORTEX METHOD (THIN WING, ELLIPTIC CAMBER)\nC -----------------------------------------------------------------\nC DISCRETE VORTEX MODEL FOR THIN AIRFOILS (JOE KATZ,CIRCA 1986)\n\n DIMENSION GAMMA(52),XC(52),ZC(52),X(52),Z(52)\n DIMENSION ENX(52),ENZ(52),A(52,52),IP(52)\n DIMENSION DL(52),DCP(52),DCP1(52)\n\n N=10\n C=1.0\n EPSILON=0.1*C\n ALFA1=10.0\n PAY=3.141592654\n ALFA=ALFA1*PAY/180.0\n RO=1.\n V=1.\n UINF=COS(ALFA)*V\n WINF=SIN(ALFA)*V\n QUE=0.5*RO*V*V\n\nC GRID GENERATION (N PANELS)\n DX=C/N\n DO 1 I=1,N\nC COLLOCATION POINT\n XC(I) = C/N*(I-0.25)\n ZC(I) = 4.*EPSILON*XC(I)/C*(1.-XC(I)/C)\nC VORTEX POINT\n X(I) = C/N*(I-0.75)\n Z(I) = 4.*EPSILON*X(I)/C*(1.-X(I)/C)\nC NORMAL AT COLLOCATION POINT; N=(ENX,ENZ)\n DETADX=4.*EPSILON/C*(1.-2.*XC(I)/C)\n SQ=SQRT(1+DETADX**2)\n ENX(I)=-DETADX/SQ\n 1 ENZ(I)= 1./SQ\n\nC INFLUENCE COEFFICIENTS\n DO 3 I=1,N\n DO 2 J=1,N\n CALL VOR2D(XC(I),ZC(I),X(J),Z(J),1.0,U,W)\n A(I,J)=U*ENX(I)+W*ENZ(I)\n 2 CONTINUE\nC THE RHS VECTOR IS PLACED IN THE GAMMA VECTOR\n GAMMA(I)=-UINF*ENX(I)-WINF*ENZ(I)\n 3 CONTINUE\n\nC SOLUTION OF THE PROBLEM: RHS(I)=A(I,J)*GAMMA(I)\n CALL DECOMP(N,52,A,IP)\n CALL SOLVER(N,52,A,GAMMA,IP)\n\nC AERODYNAMIC LOADS\n BL=0.0\n DO 4 I=1,N\n DL(I)=RO*V*GAMMA(I)\n DCP(I)=DL(I)/DX/QUE\nC DCP1 IS THE ANALYTIC SOLUTION\n DD=32.*EPSILON/C*SQRT(X(I)/C*(1.-X(I)/C))\n DCP1(I)=4.*SQRT((C-X(I))/X(I))*ALFA+DD\n 4 BL=BL+DL(I)\n CL=BL/(QUE*C)\n CL1=2.*PAY*(ALFA+2*EPSILON/C)\nC CL1,DCP1-ARE THE EXACT SOLUTIONS\n\nC OUTPUT\n WRITE(6,14)\n WRITE(6,15) V,CL,CL1,N,ALFA1\n DO 5 I=1,N\n 5 WRITE(6,16)I,X(I),DCP(I),DCP1(I)\n\n 14 FORMAT( ' THIN AIRFOIL WITH ELLIPTIC CAMBER ')\n 15 FORMAT( ' V=',F7.1,3X,'CL=',F7.3,3X,'CL(EXACT)=',F7.3,3X,'N= ',\n $I6,3X,'ALPHA= ',F6.1)\n 16 FORMAT( I5,3X,'X=',F8.2,5X,'DCP=',F8.2,3X,'DCP(EXACT)=',5F6.2)\n\nC PLOTTER OUTPUT IS PLACED HERE (e.g. DCP AND DCP1-VS-X/C)\n\n STOP\n END\n\n SUBROUTINE VOR2D(X,Z,X1,Z1,GAMMA,U,W)\nC CALCULATES INFLUENCE OF VORTEX AT (X1,Z1)\n PAY=3.141592654\n U=0.0\n W=0.0\n RX=X-X1\n RZ=Z-Z1\n R=SQRT(RX**2+RZ**2)\n IF(R.LT.0.001) GOTO 1\n V=0.5/PAY*GAMMA/R\n U=V*(RZ/R)\n W=V*(-RX/R)\n 1 CONTINUE\n RETURN\n END\nC\nC THE FOLLOWING SUBROUTINES ARE LISTED WITH THE STEADY STATE\nC VORTEX LATTICE SOLVER (program No. 13).\nC\nC SUBROUTINE DECOMP(N,NDIM,A,IP)\nC SUBROUTINE SOLVER(N,NDIM,A,B,IP)\n", "meta": {"hexsha": "c962e104f3f2d7018d86aa566e47312c941f66ef", "size": 2749, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "tests/f77/VOR2D.f", "max_stars_repo_name": "Budhyant/KatzPlotkinPy", "max_stars_repo_head_hexsha": "60f96e17dd1c4fa53b0ae5e878d455151007c334", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2020-07-21T10:19:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-09T12:54:25.000Z", "max_issues_repo_path": "tests/f77/VOR2D.f", "max_issues_repo_name": "AlwinW/KatzPlotkinPy", "max_issues_repo_head_hexsha": "60f96e17dd1c4fa53b0ae5e878d455151007c334", "max_issues_repo_licenses": ["MIT"], "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/f77/VOR2D.f", "max_forks_repo_name": "AlwinW/KatzPlotkinPy", "max_forks_repo_head_hexsha": "60f96e17dd1c4fa53b0ae5e878d455151007c334", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-07-23T22:18:24.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-25T11:33:45.000Z", "avg_line_length": 27.49, "max_line_length": 72, "alphanum_fraction": 0.5114587123, "num_tokens": 1167, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357460591569, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6520217877545255}} {"text": "module helmholtz\n! contains all variables and subroutines necessary to solve\n! Helmholtz equation of the form: (D^2 - k^2 - dtnui)u = rhs\n! with Dirichlet boundary conditions at zpts(1) and zpts(nzp)\n! setting dtfac to zero solves the corresponding Poisson eqn\n\nimplicit none\npublic\nsave\n\ncontains\n\nsubroutine diagonalize_matrix(D2,n,lamda,e,ei)\n ! find eigenvalues and eigenvectors of d^2/dz^2 matrix D2\n ! to diagonalize it s.t. D2 = E lamda E^-1, where diag is diagonal,\n ! and E are the matrices whose columns are eigenvectors\n use flags, only: debug\n ! use dim, only: nzp,nz,nzm\n ! use mats\n use mpicom, only: myid\n use formatstrings\n integer, intent(in) :: n\n real, dimension(n,n) :: D2\n real, dimension(n), intent(out) :: lamda\n real, dimension(n,n), intent(out) :: e, ei\n ! local vars req'd for LAPACK\n character*1 :: jobvl, jobvr\n integer :: k, i, info, lwork, lda, ldb, ldvl, ldvr\n integer, allocatable, dimension(:) :: ipiv\n real, allocatable, dimension(:,:) :: A, B, vl, vr\n real, allocatable, dimension(:) :: work, alphar, alphai, beta\n ! real :: tmp\n\n ! setup input for LAPACK SGGEV which calculates eigenvalues, \n ! and eigenvectors for problem A v = lamda*B v\n jobvl = 'N'\n jobvr = 'V'\n ! n = nzm\n lda = n\n ldb = n\n ldvl = n\n ldvr = n\n lwork = 10*n\n allocate( A(lda,n), B(ldb,n), vl(ldvl,n), vr(ldvr,n), work(lwork), alphar(n), alphai(n), beta(n), ipiv(n) )\n\n ! A = D2(2:nz,2:nz) because we always solve helmholtz and poisson eqn\n ! with homogeneous boundary conditions e.g.:\n ! [D^2 - k^2 - 2/(nu*dt)] phi = RHS + hbot(z)bc1(x,y) + h2(z)bc2(x,y)\n ! where phi(z=0,H or -1,1) = 0\n ! A = D2(ns:n+1,ns:n+1)\n A = D2\n\n ! B is the identity matrix in this case because we want the solution to\n ! the classical eigenvalue problem A v = lamda*v\n B = 0.0\n do k=1,n\n B(k,k) = 1.\n end do\n\n ! DGGEV computes for a pair of N-by-N real nonsymmetric matrices (A,B)\n ! the generalized eigenvalues, and optionally, the left and/or right\n ! generalized eigenvectors.\n ! A generalized eigenvalue for a pair of matrices (A,B) is a scalar\n ! lambda or a ratio alpha/beta = lambda, such that A - lambda*B is\n ! singular. It is usually represented as the pair (alpha,beta), as\n ! there is a reasonable interpretation for beta=0, and even for both\n ! being zero.\n ! The right eigenvector v(j) corresponding to the eigenvalue lambda(j)\n ! of (A,B) satisfies\n ! A * v(j) = lambda(j) * B * v(j).\n ! The left eigenvector u(j) corresponding to the eigenvalue lambda(j)\n ! of (A,B) satisfies\n ! u(j)**H * A = lambda(j) * u(j)**H * B .\n ! where u(j)**H is the conjugate-transpose of u(j).\n call dggev( jobvl, jobvr, n, A, lda, B, ldb, alphar, alphai, beta, vl, ldvl, vr, ldvr, work, lwork, info )\n ! check for errors\n if (info>=2 .and. myid==0) write(*,'((//,A),I11.4)') 'info =', info\n\n if (debug>=2) then\n ! scale each eigen vector by its first value for comparison with previous code results\n do k=1,n\n vr(:,k) = vr(:,k)/vr(1,k)\n end do\n end if\n\n ! store calculate eigenvalues in lamda, and eigenvectors in e\n lamda = 0.0\n lamda(1:n) = alphar/beta ! assuming only real eigenvalues\n e(1:n,1:n) = vr\n\n ! switch last two eigenvalues if they are in wrong order\n ! if (lamda(n)=2 .and. myid==0) write(*,'((//,A),I11.4)') 'info =', info\n\n ! store E^-1 into ei\n ei(1:n,1:n) = vr\n\n if (debug>=1 .and. myid==0) then\n write(*,'((//,A),I11.4)') 'info =', info\n write(*,'(//,A)') 'eigenvalues ='\n write(*,'(2(E14.7,'',''))') (lamda(i),alphai(i),i=1,n)\n ! write(*,'(//,A)') 'right eigenvectors ='\n ! write(*,fm3) ((e(i,k),k=1,n),i=1,n)\n ! write(*,'(//,A)') 'inv(E) ='\n ! write(*,fm3) ((ei(i,k),k=1,n),i=1,n)\n end if\n\n\n ! deallocate all local vars\n deallocate( A, B, vl, vr, work, alphar, alphai, beta, ipiv )\n\nend subroutine diagonalize_matrix\n\n\n\nsubroutine solve_helmholtz(rhs,dtnui,n,diag,smat,simat)\n ! solves the Helmholtz or Poisson eqn with homogeneous boundary conditions\n use dim\n use grid\n ! use mats\n ! i/o\n integer, intent(in) :: n\n real, dimension(nxpl,ny,nzpl), intent(inout) :: rhs\n real, intent(in) :: dtnui\n real, dimension(n), intent(in) :: diag\n real, dimension(n,n), intent(in) :: smat,simat\n ! vars\n integer :: i, j, k, ks, ke\n real, allocatable, dimension(:) :: denom\n real, allocatable, dimension(:,:) :: dfac\n real, allocatable, dimension(:,:,:) :: q, trhs\n real :: mindiag\n\n mindiag = 1.E-4\n ks = 2; ke = nz;\n if (n==nz) ks = 2; ke = n+1;\n\n ! allocate local vars\n allocate( dfac(nxpl,ny), q(nxpl,ny,n), trhs(nxpl,ny,n), denom(n) )\n ! copy rhs into q\n q = rhs(:,:,ks:ke)\n ! denom\n i = 1\n do k=ks,ke\n denom(i) = diag(k-1)\n i = i +1\n end do\n ! solve (D^2 - k^2 - dtnui)u = rhs\n ! using previously decomposed matrix D^2 = E diag E^-1 s.t.\n ! (D^2 - k^2 - dtnui)q = (E diag E^-1 - I (k^2 + dtnui))q = rhs\n ! left multiply eqn by E^-1, right multiply by E and obtain\n ! (diag - I (k^2 + dtnui))q = E^-1 rhs E\n ! q(z) = E^-1 rhs(z) E / (diag(z) - I (k^2 + dtnui)) for each i,j\n do j=1,ny\n do i=1,nxpl\n ! dfac = -k^2 -dtnui\n dfac(i,j) = -wavxx(i) - wavyy(j) - dtnui\n ! left multiply eqn by E^-1,\n! trhs(i,j,:) = matmul(simat,q(i,j,:))\n call DGEMV ( 'N', n, n, 1.0, simat, n, q(i,j,:), 1, 0.0, trhs(i,j,:), 1 )\n! trhs(i,j,ks:ke) = matmul(rhs(i,j,ks:ke),simat)\n \n ! q(z) = E^-1 rhs(z) E / (diag(z) - I (k^2 + dtnui))\n! trhs(i,j,ks:ke) = trhs(i,j,ks:ke)/(diag(1:nzm) + dfac(i,j))\n ! trhs(i+1,j,ks:ke) = trhs(i+1,j,ks:ke)/(diag(1:nzm) + dfac(ii,j))\n trhs(i,j,:) = trhs(i,j,:)/(denom(:) + dfac(i,j))\n! do k=ks,ke\n! if (abs(diag(k-1)+ dfac(i,j)) >= mindiag ) then\n! trhs(i,j,k) = trhs(i,j,k)/(diag(k-1) + dfac(i,j))\n! else\n! trhs(i,j,k) = 0.0\n! end if\n! end do\n ! right multiply by E\n! q(i,j,:) = matmul(smat,trhs(i,j,:))\n call DGEMV ( 'N', n, n, 1.0, smat, n, trhs(i,j,:), 1, 0.0, q(i,j,:), 1 )\n ! q(i,j,ks:ke) = matmul(trhs(i,j,ks:ke),smat)\n ! q(i,j,ks:ke) = q(i,j,ks:ke)/( diag(1:nzm) + dfac(ii,j) )\n ! copy soln into imaginary part of mode since dfac doesn't change\n ! q(i+1,j,ks:ke) = q(i,j,ks:ke)\n end do\n end do\n\n rhs(:,:,ks:ke) = q\n\n ! apply homogeneous boundary conditions\n! if (n==nzm) then\n rhs(:,:,1) = 0.0\n rhs(:,:,nzp) = 0.0\n! end if\n ! deallocate local vars\n deallocate(dfac, q, trhs, denom)\n\nend subroutine solve_helmholtz\n\n\nsubroutine solve_nhom_helmholtz(rhs, bc, dtnui, diag, smat, simat)\n ! solves the Helmholtz or Poisson eqn with non-homogeneous boundary conditions\n ! bc(x,y,z=zpts(nzp)) and bc(x,y,z=zpts(1)) using Green's function method:\n ! (D^2 - k^2 - dtnui)u = rhs, let u = phi + htop(z)f1(x,y) + hbot(z)f2(x,y) s.t.\n ! (D^2 - k^2 - dtnui)phi = rhs - (D^2 - k^2 - dtnui)(htop(z)f1(x,y) + hbot(z)f2(x,y))\n ! where phi has homogeneous boundary conditions\n use dim\n use grid\n use runparam, only: mapping, blfac\n use paral, only: wbar, wbarpp\n ! use mats\n use flags, only: debug\n use formatstrings\n use mpicom, only: myid\n ! i/o\n real, dimension(nxpl,ny,nzpl), intent(inout) :: rhs\n real, dimension(nxpl,ny,nzpl), intent(in) :: bc\n real, intent(in) :: dtnui\n ! integer, intent(in) :: mapping\n real, dimension(nzpl), intent(in) :: diag\n real, dimension(nzpl,nzpl), intent(in) :: smat,simat\n ! vars\n integer :: i, j, k\n real, allocatable, dimension(:) :: hbot, htop, d2hbot, d2htop\n real :: btop, bbot, atop, abot, width, h\n\n ! allocate vars\n allocate( hbot(nzp), htop(nzp), d2hbot(nzp), d2htop(nzp) )\n ! based on mapping, compute what hbot and h2 should be:\n select case(mapping)\n case(0) ! channel flow\n ! linear htop, hbot\n width = zpts(1) - zpts(nzp)\n htop(1:nzp) = (zpts(1:nzp) - zpts(nzp))/width ! hbot(1) = 1, hbot(nzp) = 0\n hbot(1:nzp) = -(zpts(1:nzp) - zpts(1))/width ! h2(1) = 0, h2(nzp) = 1\n d2htop = 0.0\n d2hbot = 0.0\n case(1) ! semi-infinite BL\n ! exponential from blayscal\n h = zpts(1) - zpts(nzp)\n btop = 0.2\n bbot = 50.0\n ! htop = wbar/wbar(1)\n ! htop(nzp) = 0.0\n ! d2htop = wbarpp/wbar(1)\n htop(1:nzp) = 0.0!exp( -btop*(h-zpts(1:nzp)) )\n d2htop = 0.0!btop**2.0*htop\n! hbot = ( exp(-bbot*zpts) - exp(bbot*(zpts-2.0*h)) )\n! hbot = hbot/( 1.-exp(-2.0*bbot*h) )\n! d2hbot = bbot**2.0*hbot\n hbot(1:nzp) = exp( -bbot*zpts(1:nzp) )\n hbot(1) = 0.0\n d2hbot(:) = bbot**2.0*hbot(:)\n case(2) ! well-resolved Blasius BL problem\n h = zpts(1) - zpts(nzp)\n bbot = 5.0 !blfac\n hbot = ( exp(-bbot*zpts) - exp(bbot*(zpts-2.0*h)) )\n hbot = hbot/( 1.-exp(-2.0*bbot*h) )\n d2hbot = bbot**2*hbot\n htop = wbar/wbar(1)\n htop(nzp) = 0.\n d2htop = wbarpp/wbar(1)\n ! exponential for bottom from blayscal, CTR blending-function for top\n ! to ensure dhtop/dz | z=zpts(1) = 0\n! h = zpts(1) - zpts(nzp)\n! btop = 8.*atan(1.)\n! ! btop = .001\n! htop(1:nzp) = zpts(1:nzp)/h - sin( btop*zpts(1:nzp)/h )/btop\n! d2htop = btop/h**2.0*sin( btop*zpts(1:nzp)/h )\n\n case(3) ! channel flow from z = 0 to zlen\n btop = 50.0\n bbot = 50.0\n ! exponential from blayscal but equal at both ends\n ! htop(1:nzp) = exp( -btop*(zpts(1)-zpts(1:nzp)) )\n ! htop(nzp) = 0.0\n ! hbot(1:nzp) = exp( -bbot*zpts(1:nzp) )\n ! hbot(1) = 0.0\n ! d2htop = btop**2.0*htop\n ! d2hbot = bbot**2.0*hbot\n ! exponential with proper zero BC at other end\n h = zpts(1) - zpts(nzp)\n hbot = ( exp(-bbot*zpts) - exp(bbot*(zpts-2.0*h)) )\n hbot = hbot/( 1.-exp(-2.0*bbot*h) )\n d2hbot = bbot**2.0*hbot\n htop = exp(btop*(zpts-h))*(1.-exp(-2.0*btop*zpts))\n htop = htop/( 1.-exp(-2.0*btop*h) )\n d2htop = btop**2.0*htop\n ! CTR belnding function using x - sin(2pi*x/xlen)/2pi\n ! h = zpts(1) - zpts(nzp)\n ! btop = 8.*atan(1.)\n ! htop(1:nzp) = zpts(1:nzp)/h - sin( btop*zpts(1:nzp)/h )/btop\n ! d2htop = btop/h**2.0*sin( btop*zpts(1:nzp)/h )\n ! hbot = 1. - htop\n ! d2hbot = -d2htop\n \n end select\n\n if (debug>=2 .and. myid==0) then\n write(*,'(//,A)') '-----------------helmholtz----------------'\n write(*,*) 'hbot(z)='\n write(*,fm3) hbot(1:nzp)\n write(*,*) 'd^2 hbot/dz^2 ='\n write(*,fm3) d2hbot(1:nzp)\n write(*,*) 'htop(z)='\n write(*,fm3) htop(1:nzp)\n write(*,*) 'd^2 htop/dz^2 ='\n write(*,fm3) d2htop(1:nzp)\n write(*,*) 'h(z)*bc = '\n write(*,fm3) hbot(1:nzp)*bc(1,1,nzp) + htop(1:nzp)*bc(1,1,1)\n end if\n\n\n ! rhs = rhs - (D^2 - k^2 - dtnui)(htop(z)f1(x,y) + hbot(z)f2(x,y))\n do k=1,nzp\n do j=1,ny\n do i=1,nxpl\n abot = ( d2hbot(k) + (-wavxx(i) - wavyy(j) - dtnui)*hbot(k) )\n rhs(i,j,k) = rhs(i,j,k) - abot*bc(i,j,nzp)\n\n atop = ( d2htop(k) + (-wavxx(i) - wavyy(j) - dtnui)*htop(k) )\n rhs(i,j,k) = rhs(i,j,k) - atop*bc(i,j,1)\n end do\n end do\n end do\n\n if (debug>=2 .and. myid==0) then\n write(*,*) 'rhs(x,z) before helmholtz='\n write(*,fm1f) (rhs(1:nxpl,1,k),k=1,nzp)\n end if\n\n ! now solve for phi\n call solve_helmholtz(rhs, dtnui, nzm, diag, smat, simat)\n\n if (debug>=2 .and. myid==0) then\n write(*,*) 'rhs(x,z) after helmholtz='\n write(*,fm1f) (rhs(1:nxpl,1,k),k=1,nzp)\n end if\n\n ! form complete field u = phi + htop(z)f1(x,y) + hbot(z)f2(x,y)\n do k=1,nzpl\n rhs(:,:,k) = rhs(:,:,k) + hbot(k)*bc(:,:,nzp) + htop(k)*bc(:,:,1)\n end do\n\n\n deallocate(htop,hbot,d2htop,d2hbot)\n\nend subroutine solve_nhom_helmholtz\n\n\n\nend module helmholtz\n", "meta": {"hexsha": "101ffecef4987aeb0c567d565fec9b3b9a65c49e", "size": 13192, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/helmholtz.f90", "max_stars_repo_name": "cadieux/lsbflow", "max_stars_repo_head_hexsha": "a08f232ddf6e88836dc5567f0130003a114855b8", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2015-01-25T18:57:47.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-03T13:50:01.000Z", "max_issues_repo_path": "src/helmholtz.f90", "max_issues_repo_name": "cadieux/lsbflow", "max_issues_repo_head_hexsha": "a08f232ddf6e88836dc5567f0130003a114855b8", "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/helmholtz.f90", "max_forks_repo_name": "cadieux/lsbflow", "max_forks_repo_head_hexsha": "a08f232ddf6e88836dc5567f0130003a114855b8", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2015-06-14T09:21:43.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-24T06:00:11.000Z", "avg_line_length": 36.3415977961, "max_line_length": 111, "alphanum_fraction": 0.5153123105, "num_tokens": 4869, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357563664174, "lm_q2_score": 0.752012568201972, "lm_q1q2_score": 0.6520217858680488}} {"text": "!---------------------------------------------------------------------!\n! OWNER: Ithaca Combustion Enterprise, LLC !\n! COPYRIGHT: \u00a9 2012, Ithaca Combustion Enterprise, LLC !\n! LICENSE: BSD 3-Clause License (The complete text of the license can !\n! be found in the `LICENSE-ICE.txt' file included in the ISAT-CK7 !\n! source directory.) !\n!---------------------------------------------------------------------!\n\nsubroutine ell_radii( n, gg, r_in, r_out )\n\n! gg contains (in packed format) the lower triangular matrix G \n! which defines the ellipsoid E = {x | |G^T * x | <=1 }.\n! This routine returns in r_in and r_out the rdii of the \n! inscribed and circumscribed balls. These are the inverses of the\n! larges and smallest singular vaues of G.\n\nimplicit none\ninteger, parameter :: k_dp = kind(1.d0)\ninteger, intent(in) :: n\nreal(k_dp), intent(in) :: gg((n*(n+1))/2)\nreal(k_dp), intent(out) :: r_in, r_out\n\nreal(k_dp) :: a(n,n), sv(n), u(n,n), vt(n,n), work(10*n*n+20*n)\ninteger :: lwork, info, i, j, k\ncharacter(1) :: jobu, jobvt\n\nlwork = 10*n*n+20*n\n\nif( n > 1 ) then\n\n! unpack gg into a\n\n a = 0.d0\n k = 0\n do j = 1, n\n do i = j, n\n k = k + 1\n\t a(i,j) = gg(k)\n end do\n end do\n\n! form singular values\n\n jobu = 'A' !XXX 'N' should be sufficient, but leads to unexplained error\n jobvt = 'N'\n\n call dgesvd( jobu, jobvt, n, n, a, n, sv, u, n, vt, n, work, lwork, info )\n\n if( info /= 0 ) then\n write(0,*)'ell_radii: info, n, lwork, work(1) = ', info, n, lwork, work(1)\n write(0,*)'sv = '\n write(0,'(1p,5e13.4)') sv\n stop\n endif\n\nelseif( n ==1 ) then\n\n sv(1) = gg(1)\n\nelse\n write(0,*)'ell_radii: invalid n = ', n\n stop\nendif\n\nif( sv(n) <= 0.d0 ) then\n write(0,*)'ell_radii: bad singular value ', sv\n stop\nendif\n\nr_in = 1.d0 / sv(1)\nr_out = 1.d0 / sv(n)\n\nreturn\nend subroutine ell_radii\n", "meta": {"hexsha": "87bf5703dd35124e1574eea10f4cd4d3e92047b8", "size": 1976, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/isat/ell_lib/ell_radii.f90", "max_stars_repo_name": "xuhan425/isat_ffd", "max_stars_repo_head_hexsha": "3a5449f7e49b686c33fe0e97ca90ea8d92fc2f00", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-04-10T20:16:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-15T11:09:44.000Z", "max_issues_repo_path": "src/isat/ell_lib/ell_radii.f90", "max_issues_repo_name": "xuhan425/isat_ffd", "max_issues_repo_head_hexsha": "3a5449f7e49b686c33fe0e97ca90ea8d92fc2f00", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-06-07T14:10:25.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-07T14:10:25.000Z", "max_forks_repo_path": "src/isat/ell_lib/ell_radii.f90", "max_forks_repo_name": "xuhan425/isat_ffd", "max_forks_repo_head_hexsha": "3a5449f7e49b686c33fe0e97ca90ea8d92fc2f00", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-06-07T03:44:12.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-05T05:54:10.000Z", "avg_line_length": 26.3466666667, "max_line_length": 80, "alphanum_fraction": 0.5273279352, "num_tokens": 653, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312226373181, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6519894836506833}} {"text": "!*********************************************************************\n! This file is part of Polylogarithm.\n!\n! Polylogarithm is licenced under the MIT License.\n!*********************************************************************\n\n\n!*********************************************************************\n!> @brief Complex polylogarithm \\f$\\mathrm{Li}_4(z)\\f$\n!> @param z complex argument\n!> @return \\f$\\mathrm{Li}_4(z)\\f$\n!> @author Alexander Voigt\n!*********************************************************************\ndouble complex function cdli4(z)\n implicit none\n double complex :: z, u, u2, u4, u8, c3, lmz, r, fast_pos_cdlog\n double precision :: rz, iz, nz, pz, lnz, arg, sgn\n double precision, parameter :: PI = 3.1415926535897932D0\n double precision, parameter :: PI2 = 9.8696044010893586D0\n double precision, parameter :: PI4 = 97.409091034002437D0\n double precision, parameter :: zeta4 = 1.0823232337111382D0\n double precision, parameter :: c1 = 1.2020569031595943D0\n double precision, parameter :: c2 = 0.82246703342411322D0\n double precision, parameter :: c4 = -1D0/48D0\n double precision, parameter :: bf(18) = (/ &\n 1.0D0 , -7.0D0/16.0D0 , &\n 1.1651234567901235D-01, -1.9820601851851852D-02, &\n 1.9279320987654321D-03, -3.1057098765432099D-05, &\n -1.5624009114857835D-05, 8.4851235467732066D-07, &\n 2.2909616603189711D-07, -2.1832614218526917D-08, &\n -3.8828248791720156D-09, 5.4462921032203321D-10, &\n 6.9608052106827254D-11, -1.3375737686445215D-11, &\n -1.2784852685266572D-12, 3.2605628580248922D-13, &\n 2.3647571168618257D-14, -7.9231351220311617D-15 /)\n double precision, parameter :: cs(7) = (/ &\n -6.9444444444444444D-04, 1.6534391534391534D-06, &\n -1.0935444136502338D-08, 1.0438378493934049D-10, &\n -1.2165942300622435D-12, 1.6130006528350101D-14, &\n -2.3428810452879340D-16 /)\n\n rz = real(z)\n iz = aimag(z)\n\n if (iz .eq. 0) then\n if (rz .eq. 0) then\n cdli4 = 0\n return\n endif\n if (rz .eq. 1) then\n cdli4 = zeta4\n return\n endif\n if (rz .eq. -1) then\n cdli4 = -7*PI4/720\n return\n endif\n endif\n\n nz = rz**2 + iz**2\n pz = datan2(iz, rz)\n lnz = 0.5D0*log(nz)\n\n if (lnz**2 + pz**2 .lt. 1) then ! |log(z)| < 1\n u = dcmplx(lnz, pz) ! log(z)\n u2 = u**2\n u4 = u2**2\n u8 = u4**2\n c3 = (11D0/6 - fast_pos_cdlog(-u))/6\n cdli4 = zeta4 + u2 * (c2 + u2 * c4) + &\n u * ( &\n c1 + &\n c3*u2 + &\n u4*(cs(1) + u2*cs(2)) + &\n u8*(cs(3) + u2*cs(4) + u4*(cs(5) + u2*cs(6))) + &\n u8*u8*cs(7) &\n )\n return\n endif\n\n if (nz .le. 1) then\n u = -fast_pos_cdlog(1 - z)\n r = 0\n sgn = 1\n else ! nz > 1\n if (pz .gt. 0) then\n arg = pz - PI\n else\n arg = pz + PI\n endif\n lmz = dcmplx(lnz, arg) ! log(-z)\n u = -fast_pos_cdlog(1 - 1/z)\n r = (-7*PI4 + lmz**2*(-30*PI2 - 15*lmz**2))/360\n sgn = -1\n endif\n\n u2 = u**2\n u4 = u2**2\n u8 = u4**2\n\n cdli4 = &\n r + sgn * ( &\n u*bf(1) + &\n u2*(bf(2) + u*bf(3)) + &\n u4*(bf(4) + u*bf(5) + u2*(bf(6) + u*bf(7))) + &\n u8*(bf(8) + u*bf(9) + u2*(bf(10) + u*bf(11)) + &\n u4*(bf(12) + u*bf(13) + u2*(bf(14) + u*bf(15)))) + &\n u8*u8*(bf(16) + u*bf(17) + u2*bf(18)) &\n )\n\nend function cdli4\n", "meta": {"hexsha": "510911d56031c4bece4e6d785fb92b9d1cd84240", "size": 3945, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/Li4.f90", "max_stars_repo_name": "Expander/polylogarithm", "max_stars_repo_head_hexsha": "01e76023d9cd88c697fb1230c49e75d9493eeef2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2018-06-02T06:09:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-07T12:42:44.000Z", "max_issues_repo_path": "src/fortran/Li4.f90", "max_issues_repo_name": "Expander/polylogarithm", "max_issues_repo_head_hexsha": "01e76023d9cd88c697fb1230c49e75d9493eeef2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-12-05T12:19:59.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-20T09:17:40.000Z", "max_forks_repo_path": "src/fortran/Li4.f90", "max_forks_repo_name": "Expander/polylogarithm", "max_forks_repo_head_hexsha": "01e76023d9cd88c697fb1230c49e75d9493eeef2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-11-23T01:52:08.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-11T04:14:39.000Z", "avg_line_length": 35.5405405405, "max_line_length": 70, "alphanum_fraction": 0.4299112801, "num_tokens": 1393, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122188543454, "lm_q2_score": 0.7185943985973772, "lm_q1q2_score": 0.6519894782476902}} {"text": "!*****************************************************************************************\n!> author: Jacob Williams\n! license: BSD\n!\n! Multidimensional linear interpolation/extrapolation.\n!\n! Uses repeated linear interpolation to evaluate\n! functions \\(f(x), f(x,y), f(x,y,z), f(x,y,z,q), f(x,y,z,q,r), f(x,y,z,q,r,s) \\)\n! which have been tabulated at the nodes of an n-dimensional rectangular grid.\n! If any coordinate \\( (x_i, y_i, ...) \\) lies outside the range of the corresponding\n! variable, then extrapolation is performed using the two nearest points.\n\n module linear_interpolation_module\n\n use iso_fortran_env, only: wp => real64 ! working precision\n\n implicit none\n\n private\n\n real(wp),parameter,private :: zero = 0.0_wp !! numeric constant\n real(wp),parameter,private :: one = 1.0_wp !! numeric constant\n\n type,public,abstract :: linear_interp_class\n !! Base class for the linear interpolation types\n private\n logical :: initialized = .false. !! if the class was properly initialized\n contains\n private\n procedure(destroy_func),deferred,public :: destroy !! destructor\n procedure :: check_inputs\n end type linear_interp_class\n\n abstract interface\n pure elemental subroutine destroy_func(me) !! interface for bspline destructor routines\n import :: linear_interp_class\n implicit none\n class(linear_interp_class),intent(inout) :: me\n end subroutine destroy_func\n end interface\n\n type,extends(linear_interp_class),public :: linear_interp_1d\n !! Class for 1d linear interpolation.\n private\n real(wp),dimension(:),allocatable :: f\n real(wp),dimension(:),allocatable :: x\n integer :: ilox = 1\n contains\n private\n procedure,public :: initialize => initialize_1d\n procedure,public :: evaluate => interp_1d\n procedure,public :: destroy => destroy_1d\n final :: finalize_1d\n end type linear_interp_1d\n\n type,extends(linear_interp_class),public :: linear_interp_2d\n !! Class for 2d linear interpolation.\n private\n real(wp),dimension(:,:),allocatable :: f\n real(wp),dimension(:),allocatable :: x\n real(wp),dimension(:),allocatable :: y\n integer :: ilox = 1\n integer :: iloy = 1\n contains\n private\n procedure,public :: initialize => initialize_2d\n procedure,public :: evaluate => interp_2d\n procedure,public :: destroy => destroy_2d\n final :: finalize_2d\n end type linear_interp_2d\n\n type,extends(linear_interp_class),public :: linear_interp_3d\n !! Class for 3d linear interpolation.\n private\n real(wp),dimension(:,:,:),allocatable :: f\n real(wp),dimension(:),allocatable :: x\n real(wp),dimension(:),allocatable :: y\n real(wp),dimension(:),allocatable :: z\n integer :: ilox = 1\n integer :: iloy = 1\n integer :: iloz = 1\n contains\n private\n procedure,public :: initialize => initialize_3d\n procedure,public :: evaluate => interp_3d\n procedure,public :: destroy => destroy_3d\n final :: finalize_3d\n end type linear_interp_3d\n\n type,extends(linear_interp_class),public :: linear_interp_4d\n !! Class for 4d linear interpolation.\n private\n real(wp),dimension(:,:,:,:),allocatable :: f\n real(wp),dimension(:),allocatable :: x\n real(wp),dimension(:),allocatable :: y\n real(wp),dimension(:),allocatable :: z\n real(wp),dimension(:),allocatable :: q\n integer :: ilox = 1\n integer :: iloy = 1\n integer :: iloz = 1\n integer :: iloq = 1\n contains\n private\n procedure,public :: initialize => initialize_4d\n procedure,public :: evaluate => interp_4d\n procedure,public :: destroy => destroy_4d\n final :: finalize_4d\n end type linear_interp_4d\n\n type,extends(linear_interp_class),public :: linear_interp_5d\n !! Class for 5d linear interpolation.\n private\n real(wp),dimension(:,:,:,:,:),allocatable :: f\n real(wp),dimension(:),allocatable :: x\n real(wp),dimension(:),allocatable :: y\n real(wp),dimension(:),allocatable :: z\n real(wp),dimension(:),allocatable :: q\n real(wp),dimension(:),allocatable :: r\n integer :: ilox = 1\n integer :: iloy = 1\n integer :: iloz = 1\n integer :: iloq = 1\n integer :: ilor = 1\n contains\n private\n procedure,public :: initialize => initialize_5d\n procedure,public :: evaluate => interp_5d\n procedure,public :: destroy => destroy_5d\n final :: finalize_5d\n end type linear_interp_5d\n\n type,extends(linear_interp_class),public :: linear_interp_6d\n !! Class for 6d linear interpolation.\n private\n real(wp),dimension(:,:,:,:,:,:),allocatable :: f\n real(wp),dimension(:),allocatable :: x\n real(wp),dimension(:),allocatable :: y\n real(wp),dimension(:),allocatable :: z\n real(wp),dimension(:),allocatable :: q\n real(wp),dimension(:),allocatable :: r\n real(wp),dimension(:),allocatable :: s\n integer :: ilox = 1\n integer :: iloy = 1\n integer :: iloz = 1\n integer :: iloq = 1\n integer :: ilor = 1\n integer :: ilos = 1\n contains\n private\n procedure,public :: initialize => initialize_6d\n procedure,public :: evaluate => interp_6d\n procedure,public :: destroy => destroy_6d\n final :: finalize_6d\n end type linear_interp_6d\n\n type,extends(linear_interp_1d),public :: nearest_interp_1d\n !! Class for 1d nearest neighbor interpolation.\n contains\n procedure,public :: evaluate => nearest_1d\n end type nearest_interp_1d\n\n type,extends(linear_interp_2d),public :: nearest_interp_2d\n !! Class for 2d nearest neighbor interpolation.\n contains\n procedure,public :: evaluate => nearest_2d\n end type nearest_interp_2d\n\n type,extends(linear_interp_3d),public :: nearest_interp_3d\n !! Class for 3d nearest neighbor interpolation.\n contains\n procedure,public :: evaluate => nearest_3d\n end type nearest_interp_3d\n\n type,extends(linear_interp_4d),public :: nearest_interp_4d\n !! Class for 4d nearest neighbor interpolation.\n contains\n procedure,public :: evaluate => nearest_4d\n end type nearest_interp_4d\n\n type,extends(linear_interp_5d),public :: nearest_interp_5d\n !! Class for 5d nearest neighbor interpolation.\n contains\n procedure,public :: evaluate => nearest_5d\n end type nearest_interp_5d\n\n type,extends(linear_interp_6d),public :: nearest_interp_6d\n !! Class for 6d nearest neighbor interpolation.\n contains\n procedure,public :: evaluate => nearest_6d\n end type nearest_interp_6d\n\n contains\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Finalizer for a [[linear_interp_1d]] type.\n\n pure elemental subroutine finalize_1d(me)\n\n implicit none\n\n type(linear_interp_1d),intent(inout) :: me\n call me%destroy()\n\n end subroutine finalize_1d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Finalizer for a [[linear_interp_2d]] type.\n\n pure elemental subroutine finalize_2d(me)\n\n implicit none\n\n type(linear_interp_2d),intent(inout) :: me\n call me%destroy()\n\n end subroutine finalize_2d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Finalizer for a [[linear_interp_3d]] type.\n\n pure elemental subroutine finalize_3d(me)\n\n implicit none\n\n type(linear_interp_3d),intent(inout) :: me\n call me%destroy()\n\n end subroutine finalize_3d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Finalizer for a [[linear_interp_4d]] type.\n\n pure elemental subroutine finalize_4d(me)\n\n implicit none\n\n type(linear_interp_4d),intent(inout) :: me\n call me%destroy()\n\n end subroutine finalize_4d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Finalizer for a [[linear_interp_5d]] type.\n\n pure elemental subroutine finalize_5d(me)\n\n implicit none\n\n type(linear_interp_5d),intent(inout) :: me\n call me%destroy()\n\n end subroutine finalize_5d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Finalizer for a [[linear_interp_6d]] type.\n\n pure elemental subroutine finalize_6d(me)\n\n implicit none\n\n type(linear_interp_6d),intent(inout) :: me\n call me%destroy()\n\n end subroutine finalize_6d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Destructor for a [[linear_interp_1d]] class.\n\n pure elemental subroutine destroy_1d(me)\n\n implicit none\n\n class(linear_interp_1d),intent(inout) :: me\n\n if (allocated(me%f)) deallocate(me%f)\n if (allocated(me%x)) deallocate(me%x)\n me%ilox = 1\n me%initialized = .false.\n\n end subroutine destroy_1d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Destructor for a [[linear_interp_2d]] class.\n\n pure elemental subroutine destroy_2d(me)\n\n implicit none\n\n class(linear_interp_2d),intent(inout) :: me\n\n if (allocated(me%f)) deallocate(me%f)\n if (allocated(me%x)) deallocate(me%x)\n if (allocated(me%y)) deallocate(me%y)\n me%ilox = 1\n me%iloy = 1\n me%initialized = .false.\n\n end subroutine destroy_2d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Destructor for a [[linear_interp_3d]] class.\n\n pure elemental subroutine destroy_3d(me)\n\n implicit none\n\n class(linear_interp_3d),intent(inout) :: me\n\n if (allocated(me%f)) deallocate(me%f)\n if (allocated(me%x)) deallocate(me%x)\n if (allocated(me%y)) deallocate(me%y)\n if (allocated(me%z)) deallocate(me%z)\n me%ilox = 1\n me%iloy = 1\n me%iloz = 1\n me%initialized = .false.\n\n end subroutine destroy_3d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Destructor for a [[linear_interp_4d]] class.\n\n pure elemental subroutine destroy_4d(me)\n\n implicit none\n\n class(linear_interp_4d),intent(inout) :: me\n\n if (allocated(me%f)) deallocate(me%f)\n if (allocated(me%x)) deallocate(me%x)\n if (allocated(me%y)) deallocate(me%y)\n if (allocated(me%z)) deallocate(me%z)\n if (allocated(me%q)) deallocate(me%q)\n me%ilox = 1\n me%iloy = 1\n me%iloz = 1\n me%iloq = 1\n me%initialized = .false.\n\n end subroutine destroy_4d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Destructor for a [[linear_interp_5d]] class.\n\n pure elemental subroutine destroy_5d(me)\n\n implicit none\n\n class(linear_interp_5d),intent(inout) :: me\n\n if (allocated(me%f)) deallocate(me%f)\n if (allocated(me%x)) deallocate(me%x)\n if (allocated(me%y)) deallocate(me%y)\n if (allocated(me%z)) deallocate(me%z)\n if (allocated(me%q)) deallocate(me%q)\n if (allocated(me%r)) deallocate(me%r)\n me%ilox = 1\n me%iloy = 1\n me%iloz = 1\n me%iloq = 1\n me%ilor = 1\n me%initialized = .false.\n\n end subroutine destroy_5d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Destructor for a [[linear_interp_6d]] class.\n\n pure elemental subroutine destroy_6d(me)\n\n implicit none\n\n class(linear_interp_6d),intent(inout) :: me\n\n if (allocated(me%f)) deallocate(me%f)\n if (allocated(me%x)) deallocate(me%x)\n if (allocated(me%y)) deallocate(me%y)\n if (allocated(me%z)) deallocate(me%z)\n if (allocated(me%q)) deallocate(me%q)\n if (allocated(me%r)) deallocate(me%r)\n if (allocated(me%s)) deallocate(me%s)\n me%ilox = 1\n me%iloy = 1\n me%iloz = 1\n me%iloq = 1\n me%ilor = 1\n me%ilos = 1\n me%initialized = .false.\n\n end subroutine destroy_6d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Constructor for a [[linear_interp_1d]] class.\n\n pure subroutine initialize_1d(me,x,f,istat)\n\n implicit none\n\n class(linear_interp_1d),intent(inout) :: me\n real(wp),dimension(:),intent(in) :: x\n real(wp),dimension(:),intent(in) :: f\n integer,intent(out) :: istat !! `0` : no problems,\n !! `1` : `x` is not strictly increasing,\n !! `10` : `x` is not equal to size(f,1),\n !! `100` : cannot use linear interpolation for only one point.\n\n call me%destroy()\n\n istat = 0\n\n if (istat==0 .and. size(x)/=size(f,1)) istat = 10\n\n if (istat==0) then\n call me%check_inputs(x=x,ierr=istat)\n if (istat==0) then\n allocate(me%f(size(x))); me%f = f\n allocate(me%x(size(x))); me%x = x\n me%initialized = .true.\n end if\n end if\n\n end subroutine initialize_1d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Constructor for a [[linear_interp_2d]] class.\n\n pure subroutine initialize_2d(me,x,y,f,istat)\n\n implicit none\n\n class(linear_interp_2d),intent(inout) :: me\n real(wp),dimension(:),intent(in) :: x\n real(wp),dimension(:),intent(in) :: y\n real(wp),dimension(:,:),intent(in) :: f\n integer,intent(out) :: istat !! `0` : no problems,\n !! `1` : `x` is not strictly increasing,\n !! `2` : `y` is not strictly increasing,\n !! `10` : `x` is not equal to size(f,1),\n !! `20` : `y` is not equal to size(f,2),\n !! `100` : cannot use linear interpolation for only one point.\n\n call me%destroy()\n\n istat = 0\n\n if (istat==0 .and. size(x)/=size(f,1)) istat = 10\n if (istat==0 .and. size(y)/=size(f,2)) istat = 20\n\n if (istat==0) then\n call me%check_inputs(x=x,y=y,ierr=istat)\n if (istat==0) then\n allocate(me%f(size(x),size(y))); me%f = f\n allocate(me%x(size(x))); me%x = x\n allocate(me%y(size(y))); me%y = y\n me%initialized = .true.\n end if\n end if\n\n end subroutine initialize_2d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Constructor for a [[linear_interp_3d]] class.\n\n pure subroutine initialize_3d(me,x,y,z,f,istat)\n\n implicit none\n\n class(linear_interp_3d),intent(inout) :: me\n real(wp),dimension(:),intent(in) :: x\n real(wp),dimension(:),intent(in) :: y\n real(wp),dimension(:),intent(in) :: z\n real(wp),dimension(:,:,:),intent(in) :: f\n integer,intent(out) :: istat !! `0` : no problems,\n !! `1` : `x` is not strictly increasing,\n !! `2` : `y` is not strictly increasing,\n !! `3` : `z` is not strictly increasing,\n !! `10` : `x` is not equal to size(f,1),\n !! `20` : `y` is not equal to size(f,2),\n !! `30` : `z` is not equal to size(f,3),\n !! `100` : cannot use linear interpolation for only one point.\n\n call me%destroy()\n\n istat = 0\n\n if (istat==0 .and. size(x)/=size(f,1)) istat = 10\n if (istat==0 .and. size(y)/=size(f,2)) istat = 20\n if (istat==0 .and. size(z)/=size(f,3)) istat = 30\n\n if (istat==0) then\n call me%check_inputs(x=x,y=y,z=z,ierr=istat)\n if (istat==0) then\n allocate(me%f(size(x),size(y),size(z))); me%f = f\n allocate(me%x(size(x))); me%x = x\n allocate(me%y(size(y))); me%y = y\n allocate(me%z(size(z))); me%z = z\n me%initialized = .true.\n end if\n end if\n\n end subroutine initialize_3d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Constructor for a [[linear_interp_4d]] class.\n\n pure subroutine initialize_4d(me,x,y,z,q,f,istat)\n\n implicit none\n\n class(linear_interp_4d),intent(inout) :: me\n real(wp),dimension(:),intent(in) :: x\n real(wp),dimension(:),intent(in) :: y\n real(wp),dimension(:),intent(in) :: z\n real(wp),dimension(:),intent(in) :: q\n real(wp),dimension(:,:,:,:),intent(in) :: f\n integer,intent(out) :: istat !! `0` : no problems,\n !! `1` : `x` is not strictly increasing,\n !! `2` : `y` is not strictly increasing,\n !! `3` : `z` is not strictly increasing,\n !! `4` : `q` is not strictly increasing,\n !! `10` : `x` is not equal to size(f,1),\n !! `20` : `y` is not equal to size(f,2),\n !! `30` : `z` is not equal to size(f,3),\n !! `40` : `q` is not equal to size(f,4),\n !! `100` : cannot use linear interpolation for only one point.\n\n call me%destroy()\n\n istat = 0\n\n if (istat==0 .and. size(x)/=size(f,1)) istat = 10\n if (istat==0 .and. size(y)/=size(f,2)) istat = 20\n if (istat==0 .and. size(z)/=size(f,3)) istat = 30\n if (istat==0 .and. size(q)/=size(f,4)) istat = 40\n\n if (istat==0) then\n call me%check_inputs(x=x,y=y,z=z,q=q,ierr=istat)\n if (istat==0) then\n allocate(me%f(size(x),size(y),size(z),size(q))); me%f = f\n allocate(me%x(size(x))); me%x = x\n allocate(me%y(size(y))); me%y = y\n allocate(me%z(size(z))); me%z = z\n allocate(me%q(size(q))); me%q = q\n me%initialized = .true.\n end if\n end if\n\n end subroutine initialize_4d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Constructor for a [[linear_interp_5d]] class.\n\n pure subroutine initialize_5d(me,x,y,z,q,r,f,istat)\n\n implicit none\n\n class(linear_interp_5d),intent(inout) :: me\n real(wp),dimension(:),intent(in) :: x\n real(wp),dimension(:),intent(in) :: y\n real(wp),dimension(:),intent(in) :: z\n real(wp),dimension(:),intent(in) :: q\n real(wp),dimension(:),intent(in) :: r\n real(wp),dimension(:,:,:,:,:),intent(in) :: f\n integer,intent(out) :: istat !! `0` : no problems,\n !! `1` : `x` is not strictly increasing,\n !! `2` : `y` is not strictly increasing,\n !! `3` : `z` is not strictly increasing,\n !! `4` : `q` is not strictly increasing,\n !! `5` : `r` is not strictly increasing,\n !! `10` : `x` is not equal to size(f,1),\n !! `20` : `y` is not equal to size(f,2),\n !! `30` : `z` is not equal to size(f,3),\n !! `40` : `q` is not equal to size(f,4),\n !! `50` : `r` is not equal to size(f,5),\n !! `100` : cannot use linear interpolation for only one point.\n\n call me%destroy()\n\n istat = 0\n\n if (istat==0 .and. size(x)/=size(f,1)) istat = 10\n if (istat==0 .and. size(y)/=size(f,2)) istat = 20\n if (istat==0 .and. size(z)/=size(f,3)) istat = 30\n if (istat==0 .and. size(q)/=size(f,4)) istat = 40\n if (istat==0 .and. size(r)/=size(f,5)) istat = 50\n\n if (istat==0) then\n call me%check_inputs(x=x,y=y,z=z,q=q,r=r,ierr=istat)\n if (istat==0) then\n allocate(me%f(size(x),size(y),size(z),size(q),size(r))); me%f = f\n allocate(me%x(size(x))); me%x = x\n allocate(me%y(size(y))); me%y = y\n allocate(me%z(size(z))); me%z = z\n allocate(me%q(size(q))); me%q = q\n allocate(me%r(size(r))); me%r = r\n me%initialized = .true.\n end if\n end if\n\n end subroutine initialize_5d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Constructor for a [[linear_interp_6d]] class.\n\n pure subroutine initialize_6d(me,x,y,z,q,r,s,f,istat)\n\n implicit none\n\n class(linear_interp_6d),intent(inout) :: me\n real(wp),dimension(:),intent(in) :: x\n real(wp),dimension(:),intent(in) :: y\n real(wp),dimension(:),intent(in) :: z\n real(wp),dimension(:),intent(in) :: q\n real(wp),dimension(:),intent(in) :: r\n real(wp),dimension(:),intent(in) :: s\n real(wp),dimension(:,:,:,:,:,:),intent(in) :: f\n integer,intent(out) :: istat !! `0` : no problems,\n !! `1` : `x` is not strictly increasing,\n !! `2` : `y` is not strictly increasing,\n !! `3` : `z` is not strictly increasing,\n !! `4` : `q` is not strictly increasing,\n !! `5` : `r` is not strictly increasing,\n !! `6` : `s` is not strictly increasing,\n !! `10` : `x` is not equal to size(f,1),\n !! `20` : `y` is not equal to size(f,2),\n !! `30` : `z` is not equal to size(f,3),\n !! `40` : `q` is not equal to size(f,4),\n !! `50` : `r` is not equal to size(f,5),\n !! `60` : `s` is not equal to size(f,6),\n !! `100` : cannot use linear interpolation for only one point.\n\n call me%destroy()\n\n istat = 0\n\n if (istat==0 .and. size(x)/=size(f,1)) istat = 10\n if (istat==0 .and. size(y)/=size(f,2)) istat = 20\n if (istat==0 .and. size(z)/=size(f,3)) istat = 30\n if (istat==0 .and. size(q)/=size(f,4)) istat = 40\n if (istat==0 .and. size(r)/=size(f,5)) istat = 50\n if (istat==0 .and. size(s)/=size(f,6)) istat = 60\n\n if (istat==0) then\n call me%check_inputs(x=x,y=y,z=z,q=q,r=r,s=s,ierr=istat)\n if (istat==0) then\n allocate(me%f(size(x),size(y),size(z),size(q),size(r),size(s))); me%f = f\n allocate(me%x(size(x))); me%x = x\n allocate(me%y(size(y))); me%y = y\n allocate(me%z(size(z))); me%z = z\n allocate(me%q(size(q))); me%q = q\n allocate(me%r(size(r))); me%r = r\n allocate(me%s(size(s))); me%s = s\n me%initialized = .true.\n end if\n end if\n\n end subroutine initialize_6d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! 1D linear interpolation routine.\n\n pure subroutine interp_1d(me,x,f,istat)\n\n implicit none\n\n class(linear_interp_1d),intent(inout) :: me\n real(wp),intent(in) :: x\n real(wp),intent(out) :: f !! Interpolated \\( f(x) \\)\n integer,intent(out),optional :: istat !! `0` : no problems,\n !! `-1` : class has not been initialized\n\n integer,dimension(2) :: ix\n real(wp) :: p1\n real(wp) :: q1\n integer :: mflag\n\n if (me%initialized) then\n\n call dintrv(me%x,x,me%ilox,ix(1),ix(2),mflag)\n\n q1 = (x-me%x(ix(1)))/(me%x(ix(2))-me%x(ix(1)))\n p1 = one-q1\n\n f = p1*me%f(ix(1)) + q1*me%f(ix(2))\n if (present(istat)) istat = 0\n\n else\n\n if (present(istat)) istat = -1\n f = zero\n\n end if\n\n end subroutine interp_1d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! 2D linear interpolation routine.\n\n pure subroutine interp_2d(me,x,y,f,istat)\n\n implicit none\n\n class(linear_interp_2d),intent(inout) :: me\n real(wp),intent(in) :: x\n real(wp),intent(in) :: y\n real(wp),intent(out) :: f !! Interpolated \\( f(x,y) \\)\n integer,intent(out),optional :: istat !! `0` : no problems,\n !! `-1` : class has not been initialized\n\n integer,dimension(2) :: ix, iy\n real(wp) :: p1, p2\n real(wp) :: q1, q2\n integer :: mflag\n real(wp) :: fx1, fx2\n\n if (me%initialized) then\n\n call dintrv(me%x,x,me%ilox,ix(1),ix(2),mflag)\n call dintrv(me%y,y,me%iloy,iy(1),iy(2),mflag)\n\n q1 = (x-me%x(ix(1)))/(me%x(ix(2))-me%x(ix(1)))\n q2 = (y-me%y(iy(1)))/(me%y(iy(2))-me%y(iy(1)))\n p1 = one-q1\n p2 = one-q2\n\n fx1 = p1*me%f(ix(1),iy(1)) + q1*me%f(ix(2),iy(1))\n fx2 = p1*me%f(ix(1),iy(2)) + q1*me%f(ix(2),iy(2))\n\n f = p2*fx1 + q2*fx2\n if (present(istat)) istat = 0\n\n else\n\n if (present(istat)) istat = -1\n f = zero\n\n end if\n\n end subroutine interp_2d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! 3D linear interpolation routine.\n\n pure subroutine interp_3d(me,x,y,z,f,istat)\n\n implicit none\n\n class(linear_interp_3d),intent(inout) :: me\n real(wp),intent(in) :: x\n real(wp),intent(in) :: y\n real(wp),intent(in) :: z\n real(wp),intent(out) :: f !! Interpolated \\( f(x,y,z) \\)\n integer,intent(out),optional :: istat !! `0` : no problems,\n !! `-1` : class has not been initialized\n\n integer,dimension(2) :: ix, iy, iz\n real(wp) :: p1, p2, p3\n real(wp) :: q1, q2, q3\n integer :: mflag\n real(wp) :: fx11, fx21, fx12, fx22, fxy1, fxy2\n\n if (me%initialized) then\n\n call dintrv(me%x,x,me%ilox,ix(1),ix(2),mflag)\n call dintrv(me%y,y,me%iloy,iy(1),iy(2),mflag)\n call dintrv(me%z,z,me%iloz,iz(1),iz(2),mflag)\n\n q1 = (x-me%x(ix(1)))/(me%x(ix(2))-me%x(ix(1)))\n q2 = (y-me%y(iy(1)))/(me%y(iy(2))-me%y(iy(1)))\n q3 = (z-me%z(iz(1)))/(me%z(iz(2))-me%z(iz(1)))\n p1 = one-q1\n p2 = one-q2\n p3 = one-q3\n\n fx11 = p1*me%f(ix(1),iy(1),iz(1)) + q1*me%f(ix(2),iy(1),iz(1))\n fx21 = p1*me%f(ix(1),iy(2),iz(1)) + q1*me%f(ix(2),iy(2),iz(1))\n fx12 = p1*me%f(ix(1),iy(1),iz(2)) + q1*me%f(ix(2),iy(1),iz(2))\n fx22 = p1*me%f(ix(1),iy(2),iz(2)) + q1*me%f(ix(2),iy(2),iz(2))\n fxy1 = p2*fx11 + q2*fx21\n fxy2 = p2*fx12 + q2*fx22\n\n f = p3*fxy1 + q3*fxy2\n if (present(istat)) istat = 0\n\n else\n\n if (present(istat)) istat = -1\n f = zero\n\n end if\n\n end subroutine interp_3d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! 4D linear interpolation routine.\n\n pure subroutine interp_4d(me,x,y,z,q,f,istat)\n\n implicit none\n\n class(linear_interp_4d),intent(inout) :: me\n real(wp),intent(in) :: x\n real(wp),intent(in) :: y\n real(wp),intent(in) :: z\n real(wp),intent(in) :: q\n real(wp),intent(out) :: f !! Interpolated \\( f(x,y,z,q) \\)\n integer,intent(out),optional :: istat !! `0` : no problems,\n !! `-1` : class has not been initialized\n\n integer,dimension(2) :: ix, iy, iz, iq\n real(wp) :: p1, p2, p3, p4\n real(wp) :: q1, q2, q3, q4\n integer :: mflag\n real(wp) :: fx111,fx211,fx121,fx221,fxy11,fxy21,fxyz1,&\n fx112,fx212,fx122,fx222,fxy12,fxy22,fxyz2\n\n if (me%initialized) then\n\n call dintrv(me%x,x,me%ilox,ix(1),ix(2),mflag)\n call dintrv(me%y,y,me%iloy,iy(1),iy(2),mflag)\n call dintrv(me%z,z,me%iloz,iz(1),iz(2),mflag)\n call dintrv(me%q,q,me%iloq,iq(1),iq(2),mflag)\n\n q1 = (x-me%x(ix(1)))/(me%x(ix(2))-me%x(ix(1)))\n q2 = (y-me%y(iy(1)))/(me%y(iy(2))-me%y(iy(1)))\n q3 = (z-me%z(iz(1)))/(me%z(iz(2))-me%z(iz(1)))\n q4 = (q-me%q(iq(1)))/(me%q(iq(2))-me%q(iq(1)))\n p1 = one-q1\n p2 = one-q2\n p3 = one-q3\n p4 = one-q4\n\n fx111 = p1*me%f(ix(1),iy(1),iz(1),iq(1)) + q1*me%f(ix(2),iy(1),iz(1),iq(1))\n fx211 = p1*me%f(ix(1),iy(2),iz(1),iq(1)) + q1*me%f(ix(2),iy(2),iz(1),iq(1))\n fx121 = p1*me%f(ix(1),iy(1),iz(2),iq(1)) + q1*me%f(ix(2),iy(1),iz(2),iq(1))\n fx221 = p1*me%f(ix(1),iy(2),iz(2),iq(1)) + q1*me%f(ix(2),iy(2),iz(2),iq(1))\n fx112 = p1*me%f(ix(1),iy(1),iz(1),iq(2)) + q1*me%f(ix(2),iy(1),iz(1),iq(2))\n fx212 = p1*me%f(ix(1),iy(2),iz(1),iq(2)) + q1*me%f(ix(2),iy(2),iz(1),iq(2))\n fx122 = p1*me%f(ix(1),iy(1),iz(2),iq(2)) + q1*me%f(ix(2),iy(1),iz(2),iq(2))\n fx222 = p1*me%f(ix(1),iy(2),iz(2),iq(2)) + q1*me%f(ix(2),iy(2),iz(2),iq(2))\n\n fxy11 = p2*fx111 + q2*fx211\n fxy21 = p2*fx121 + q2*fx221\n fxy12 = p2*fx112 + q2*fx212\n fxy22 = p2*fx122 + q2*fx222\n\n fxyz1 = p3*fxy11 + q3*fxy21\n fxyz2 = p3*fxy12 + q3*fxy22\n\n f = p4*fxyz1 + q4*fxyz2\n if (present(istat)) istat = 0\n\n else\n\n if (present(istat)) istat = -1\n f = zero\n\n end if\n\n end subroutine interp_4d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! 5D linear interpolation routine.\n\n pure subroutine interp_5d(me,x,y,z,q,r,f,istat)\n\n implicit none\n\n class(linear_interp_5d),intent(inout) :: me\n real(wp),intent(in) :: x\n real(wp),intent(in) :: y\n real(wp),intent(in) :: z\n real(wp),intent(in) :: q\n real(wp),intent(in) :: r\n real(wp),intent(out) :: f !! Interpolated \\( f(x,y,z,q,r) \\)\n integer,intent(out),optional :: istat !! `0` : no problems,\n !! `-1` : class has not been initialized\n\n integer,dimension(2) :: ix, iy, iz, iq, ir\n real(wp) :: p1, p2, p3, p4, p5\n real(wp) :: q1, q2, q3, q4, q5\n integer :: mflag\n real(wp) :: fx1111, fx2111, fx1211, fx2211, fx1121, fx2121, fx1221, fx2221, &\n fxy111, fxy211, fxy121, fxy221, fxyz11, fxyz21, fxyzq1, fx1112, &\n fx2112, fx1212, fx2212, fx1122, fx2122, fx1222, fx2222, fxy112, &\n fxy212, fxy122, fxy222, fxyz12, fxyz22, fxyzq2\n\n if (me%initialized) then\n\n call dintrv(me%x,x,me%ilox,ix(1),ix(2),mflag)\n call dintrv(me%y,y,me%iloy,iy(1),iy(2),mflag)\n call dintrv(me%z,z,me%iloz,iz(1),iz(2),mflag)\n call dintrv(me%q,q,me%iloq,iq(1),iq(2),mflag)\n call dintrv(me%r,r,me%ilor,ir(1),ir(2),mflag)\n\n q1 = (x-me%x(ix(1)))/(me%x(ix(2))-me%x(ix(1)))\n q2 = (y-me%y(iy(1)))/(me%y(iy(2))-me%y(iy(1)))\n q3 = (z-me%z(iz(1)))/(me%z(iz(2))-me%z(iz(1)))\n q4 = (q-me%q(iq(1)))/(me%q(iq(2))-me%q(iq(1)))\n q5 = (r-me%r(ir(1)))/(me%r(ir(2))-me%r(ir(1)))\n p1 = one-q1\n p2 = one-q2\n p3 = one-q3\n p4 = one-q4\n p5 = one-q5\n\n fx1111 = p1*me%f(ix(1),iy(1),iz(1),iq(1),ir(1)) + q1*me%f(ix(2),iy(1),iz(1),iq(1),ir(1))\n fx2111 = p1*me%f(ix(1),iy(2),iz(1),iq(1),ir(1)) + q1*me%f(ix(2),iy(2),iz(1),iq(1),ir(1))\n fx1211 = p1*me%f(ix(1),iy(1),iz(2),iq(1),ir(1)) + q1*me%f(ix(2),iy(1),iz(2),iq(1),ir(1))\n fx2211 = p1*me%f(ix(1),iy(2),iz(2),iq(1),ir(1)) + q1*me%f(ix(2),iy(2),iz(2),iq(1),ir(1))\n fx1121 = p1*me%f(ix(1),iy(1),iz(1),iq(2),ir(1)) + q1*me%f(ix(2),iy(1),iz(1),iq(2),ir(1))\n fx2121 = p1*me%f(ix(1),iy(2),iz(1),iq(2),ir(1)) + q1*me%f(ix(2),iy(2),iz(1),iq(2),ir(1))\n fx1221 = p1*me%f(ix(1),iy(1),iz(2),iq(2),ir(1)) + q1*me%f(ix(2),iy(1),iz(2),iq(2),ir(1))\n fx2221 = p1*me%f(ix(1),iy(2),iz(2),iq(2),ir(1)) + q1*me%f(ix(2),iy(2),iz(2),iq(2),ir(1))\n fx1112 = p1*me%f(ix(1),iy(1),iz(1),iq(1),ir(2)) + q1*me%f(ix(2),iy(1),iz(1),iq(1),ir(2))\n fx2112 = p1*me%f(ix(1),iy(2),iz(1),iq(1),ir(2)) + q1*me%f(ix(2),iy(2),iz(1),iq(1),ir(2))\n fx1212 = p1*me%f(ix(1),iy(1),iz(2),iq(1),ir(2)) + q1*me%f(ix(2),iy(1),iz(2),iq(1),ir(2))\n fx2212 = p1*me%f(ix(1),iy(2),iz(2),iq(1),ir(2)) + q1*me%f(ix(2),iy(2),iz(2),iq(1),ir(2))\n fx1122 = p1*me%f(ix(1),iy(1),iz(1),iq(2),ir(2)) + q1*me%f(ix(2),iy(1),iz(1),iq(2),ir(2))\n fx2122 = p1*me%f(ix(1),iy(2),iz(1),iq(2),ir(2)) + q1*me%f(ix(2),iy(2),iz(1),iq(2),ir(2))\n fx1222 = p1*me%f(ix(1),iy(1),iz(2),iq(2),ir(2)) + q1*me%f(ix(2),iy(1),iz(2),iq(2),ir(2))\n fx2222 = p1*me%f(ix(1),iy(2),iz(2),iq(2),ir(2)) + q1*me%f(ix(2),iy(2),iz(2),iq(2),ir(2))\n\n fxy111 = p2*fx1111 + q2*fx2111\n fxy211 = p2*fx1211 + q2*fx2211\n fxy121 = p2*fx1121 + q2*fx2121\n fxy221 = p2*fx1221 + q2*fx2221\n fxy112 = p2*fx1112 + q2*fx2112\n fxy212 = p2*fx1212 + q2*fx2212\n fxy122 = p2*fx1122 + q2*fx2122\n fxy222 = p2*fx1222 + q2*fx2222\n\n fxyz11 = p3*fxy111 + q3*fxy211\n fxyz21 = p3*fxy121 + q3*fxy221\n fxyz12 = p3*fxy112 + q3*fxy212\n fxyz22 = p3*fxy122 + q3*fxy222\n\n fxyzq1 = p4*fxyz11 + q4*fxyz21\n fxyzq2 = p4*fxyz12 + q4*fxyz22\n\n f = p5*fxyzq1 + q5*fxyzq2\n if (present(istat)) istat = 0\n\n else\n\n if (present(istat)) istat = -1\n f = zero\n\n end if\n\n end subroutine interp_5d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! 6D linear interpolation routine.\n\n pure subroutine interp_6d(me,x,y,z,q,r,s,f,istat)\n\n implicit none\n\n class(linear_interp_6d),intent(inout) :: me\n real(wp),intent(in) :: x\n real(wp),intent(in) :: y\n real(wp),intent(in) :: z\n real(wp),intent(in) :: q\n real(wp),intent(in) :: r\n real(wp),intent(in) :: s\n real(wp),intent(out) :: f !! Interpolated \\( f(x,y,z,q,r,s) \\)\n integer,intent(out),optional :: istat !! `0` : no problems,\n !! `-1` : class has not been initialized\n\n integer,dimension(2) :: ix, iy, iz, iq, ir, is\n real(wp) :: p1, p2, p3, p4, p5, p6\n real(wp) :: q1, q2, q3, q4, q5, q6\n integer :: mflag\n real(wp) :: fx11111, fx21111, fx12111, fx22111, fx11211, fx21211, fx12211, &\n fx22211, fxy1111, fxy2111, fxy1211, fxy2211, fxyz111, fxyz211, &\n fxyzq11, fx11121, fx21121, fx12121, fx22121, fx11221, fx21221, &\n fx12221, fx22221, fxy1121, fxy2121, fxy1221, fxy2221, fxyz121, &\n fxyz221, fxyzq21, fx11112, fx21112, fx12112, fx22112, fx11212, &\n fx21212, fx12212, fx22212, fxy1112, fxy2112, fxy1212, fxy2212, &\n fxyz112, fxyz212, fxyzq12, fx11122, fx21122, fx12122, fx22122, &\n fx11222, fx21222, fx12222, fx22222, fxy1122, fxy2122, fxy1222, &\n fxy2222, fxyz122, fxyz222, fxyzq22, fxyzqr1, fxyzqr2\n\n if (me%initialized) then\n\n call dintrv(me%x,x,me%ilox,ix(1),ix(2),mflag)\n call dintrv(me%y,y,me%iloy,iy(1),iy(2),mflag)\n call dintrv(me%z,z,me%iloz,iz(1),iz(2),mflag)\n call dintrv(me%q,q,me%iloq,iq(1),iq(2),mflag)\n call dintrv(me%r,r,me%ilor,ir(1),ir(2),mflag)\n call dintrv(me%s,s,me%ilos,is(1),is(2),mflag)\n\n q1 = (x-me%x(ix(1)))/(me%x(ix(2))-me%x(ix(1)))\n q2 = (y-me%y(iy(1)))/(me%y(iy(2))-me%y(iy(1)))\n q3 = (z-me%z(iz(1)))/(me%z(iz(2))-me%z(iz(1)))\n q4 = (q-me%q(iq(1)))/(me%q(iq(2))-me%q(iq(1)))\n q5 = (r-me%r(ir(1)))/(me%r(ir(2))-me%r(ir(1)))\n q6 = (s-me%s(is(1)))/(me%s(is(2))-me%s(is(1)))\n p1 = one-q1\n p2 = one-q2\n p3 = one-q3\n p4 = one-q4\n p5 = one-q5\n p6 = one-q6\n\n fx11111 = p1*me%f(ix(1),iy(1),iz(1),iq(1),ir(1),is(1)) + q1*me%f(ix(2),iy(1),iz(1),iq(1),ir(1),is(1))\n fx21111 = p1*me%f(ix(1),iy(2),iz(1),iq(1),ir(1),is(1)) + q1*me%f(ix(2),iy(2),iz(1),iq(1),ir(1),is(1))\n fx12111 = p1*me%f(ix(1),iy(1),iz(2),iq(1),ir(1),is(1)) + q1*me%f(ix(2),iy(1),iz(2),iq(1),ir(1),is(1))\n fx22111 = p1*me%f(ix(1),iy(2),iz(2),iq(1),ir(1),is(1)) + q1*me%f(ix(2),iy(2),iz(2),iq(1),ir(1),is(1))\n fx11211 = p1*me%f(ix(1),iy(1),iz(1),iq(2),ir(1),is(1)) + q1*me%f(ix(2),iy(1),iz(1),iq(2),ir(1),is(1))\n fx21211 = p1*me%f(ix(1),iy(2),iz(1),iq(2),ir(1),is(1)) + q1*me%f(ix(2),iy(2),iz(1),iq(2),ir(1),is(1))\n fx12211 = p1*me%f(ix(1),iy(1),iz(2),iq(2),ir(1),is(1)) + q1*me%f(ix(2),iy(1),iz(2),iq(2),ir(1),is(1))\n fx22211 = p1*me%f(ix(1),iy(2),iz(2),iq(2),ir(1),is(1)) + q1*me%f(ix(2),iy(2),iz(2),iq(2),ir(1),is(1))\n fx11121 = p1*me%f(ix(1),iy(1),iz(1),iq(1),ir(2),is(1)) + q1*me%f(ix(2),iy(1),iz(1),iq(1),ir(2),is(1))\n fx21121 = p1*me%f(ix(1),iy(2),iz(1),iq(1),ir(2),is(1)) + q1*me%f(ix(2),iy(2),iz(1),iq(1),ir(2),is(1))\n fx12121 = p1*me%f(ix(1),iy(1),iz(2),iq(1),ir(2),is(1)) + q1*me%f(ix(2),iy(1),iz(2),iq(1),ir(2),is(1))\n fx22121 = p1*me%f(ix(1),iy(2),iz(2),iq(1),ir(2),is(1)) + q1*me%f(ix(2),iy(2),iz(2),iq(1),ir(2),is(1))\n fx11221 = p1*me%f(ix(1),iy(1),iz(1),iq(2),ir(2),is(1)) + q1*me%f(ix(2),iy(1),iz(1),iq(2),ir(2),is(1))\n fx21221 = p1*me%f(ix(1),iy(2),iz(1),iq(2),ir(2),is(1)) + q1*me%f(ix(2),iy(2),iz(1),iq(2),ir(2),is(1))\n fx12221 = p1*me%f(ix(1),iy(1),iz(2),iq(2),ir(2),is(1)) + q1*me%f(ix(2),iy(1),iz(2),iq(2),ir(2),is(1))\n fx22221 = p1*me%f(ix(1),iy(2),iz(2),iq(2),ir(2),is(1)) + q1*me%f(ix(2),iy(2),iz(2),iq(2),ir(2),is(1))\n fx11112 = p1*me%f(ix(1),iy(1),iz(1),iq(1),ir(1),is(2)) + q1*me%f(ix(2),iy(1),iz(1),iq(1),ir(1),is(2))\n fx21112 = p1*me%f(ix(1),iy(2),iz(1),iq(1),ir(1),is(2)) + q1*me%f(ix(2),iy(2),iz(1),iq(1),ir(1),is(2))\n fx12112 = p1*me%f(ix(1),iy(1),iz(2),iq(1),ir(1),is(2)) + q1*me%f(ix(2),iy(1),iz(2),iq(1),ir(1),is(2))\n fx22112 = p1*me%f(ix(1),iy(2),iz(2),iq(1),ir(1),is(2)) + q1*me%f(ix(2),iy(2),iz(2),iq(1),ir(1),is(2))\n fx11212 = p1*me%f(ix(1),iy(1),iz(1),iq(2),ir(1),is(2)) + q1*me%f(ix(2),iy(1),iz(1),iq(2),ir(1),is(2))\n fx21212 = p1*me%f(ix(1),iy(2),iz(1),iq(2),ir(1),is(2)) + q1*me%f(ix(2),iy(2),iz(1),iq(2),ir(1),is(2))\n fx12212 = p1*me%f(ix(1),iy(1),iz(2),iq(2),ir(1),is(2)) + q1*me%f(ix(2),iy(1),iz(2),iq(2),ir(1),is(2))\n fx22212 = p1*me%f(ix(1),iy(2),iz(2),iq(2),ir(1),is(2)) + q1*me%f(ix(2),iy(2),iz(2),iq(2),ir(1),is(2))\n fx11122 = p1*me%f(ix(1),iy(1),iz(1),iq(1),ir(2),is(2)) + q1*me%f(ix(2),iy(1),iz(1),iq(1),ir(2),is(2))\n fx21122 = p1*me%f(ix(1),iy(2),iz(1),iq(1),ir(2),is(2)) + q1*me%f(ix(2),iy(2),iz(1),iq(1),ir(2),is(2))\n fx12122 = p1*me%f(ix(1),iy(1),iz(2),iq(1),ir(2),is(2)) + q1*me%f(ix(2),iy(1),iz(2),iq(1),ir(2),is(2))\n fx22122 = p1*me%f(ix(1),iy(2),iz(2),iq(1),ir(2),is(2)) + q1*me%f(ix(2),iy(2),iz(2),iq(1),ir(2),is(2))\n fx11222 = p1*me%f(ix(1),iy(1),iz(1),iq(2),ir(2),is(2)) + q1*me%f(ix(2),iy(1),iz(1),iq(2),ir(2),is(2))\n fx21222 = p1*me%f(ix(1),iy(2),iz(1),iq(2),ir(2),is(2)) + q1*me%f(ix(2),iy(2),iz(1),iq(2),ir(2),is(2))\n fx12222 = p1*me%f(ix(1),iy(1),iz(2),iq(2),ir(2),is(2)) + q1*me%f(ix(2),iy(1),iz(2),iq(2),ir(2),is(2))\n fx22222 = p1*me%f(ix(1),iy(2),iz(2),iq(2),ir(2),is(2)) + q1*me%f(ix(2),iy(2),iz(2),iq(2),ir(2),is(2))\n\n fxy1111 = p2*fx11111 + q2*fx21111\n fxy2111 = p2*fx12111 + q2*fx22111\n fxy1211 = p2*fx11211 + q2*fx21211\n fxy2211 = p2*fx12211 + q2*fx22211\n fxy1121 = p2*fx11121 + q2*fx21121\n fxy2121 = p2*fx12121 + q2*fx22121\n fxy1221 = p2*fx11221 + q2*fx21221\n fxy2221 = p2*fx12221 + q2*fx22221\n fxy1112 = p2*fx11112 + q2*fx21112\n fxy2112 = p2*fx12112 + q2*fx22112\n fxy1212 = p2*fx11212 + q2*fx21212\n fxy2212 = p2*fx12212 + q2*fx22212\n fxy1122 = p2*fx11122 + q2*fx21122\n fxy2122 = p2*fx12122 + q2*fx22122\n fxy1222 = p2*fx11222 + q2*fx21222\n fxy2222 = p2*fx12222 + q2*fx22222\n\n fxyz111 = p3*fxy1111 + q3*fxy2111\n fxyz211 = p3*fxy1211 + q3*fxy2211\n fxyz121 = p3*fxy1121 + q3*fxy2121\n fxyz221 = p3*fxy1221 + q3*fxy2221\n fxyz112 = p3*fxy1112 + q3*fxy2112\n fxyz212 = p3*fxy1212 + q3*fxy2212\n fxyz122 = p3*fxy1122 + q3*fxy2122\n fxyz222 = p3*fxy1222 + q3*fxy2222\n\n fxyzq11 = p4*fxyz111 + q4*fxyz211\n fxyzq21 = p4*fxyz121 + q4*fxyz221\n fxyzq12 = p4*fxyz112 + q4*fxyz212\n fxyzq22 = p4*fxyz122 + q4*fxyz222\n\n fxyzqr1 = p5*fxyzq11 + q5*fxyzq21\n fxyzqr2 = p5*fxyzq12 + q5*fxyzq22\n\n f = p6*fxyzqr1 + q6*fxyzqr2\n if (present(istat)) istat = 0\n\n else\n\n if (present(istat)) istat = -1\n f = zero\n\n end if\n\n end subroutine interp_6d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Returns the indices in `xt` that bound `x`, to use for interpolation.\n! If outside the range, then the indices are returned that can\n! be used for extrapolation.\n! Precisely,\n!\n!```fortran\n! if x < xt(1) then ileft=1, iright=2, mflag=-1\n! if xt(i) <= x < xt(i+1) then ileft=i, iright=i+1, mflag=0\n! if xt(n) <= x then ileft=n-1, iright=n, mflag=1\n!```\n!\n!### History\n!\n! * interv written by carl de boor [5]\n! * dintrv author: amos, d. e., (snla) : date written 800901\n! * revision date 820801\n! * Jacob Williams, 2/24/2015 : updated to free-form Fortran.\n! * Jacob Williams, 2/17/2016 : additional refactoring (eliminated GOTOs).\n! * Jacob Williams, 2/22/2016 : modified bspline-fortran `dintrv` routine for\n! linear interpolation/extrapolation use.\n! * Jacob Williams, 10/9/2019 : added optional `inearest` output.\n\n pure subroutine dintrv(xt,x,ilo,ileft,iright,mflag,inearest)\n\n implicit none\n\n real(wp),dimension(:),intent(in) :: xt !! a knot or break point vector\n real(wp),intent(in) :: x !! argument\n integer,intent(inout) :: ilo !! an initialization parameter which must be set\n !! to 1 the first time the array `xt` is\n !! processed by dintrv. `ilo` contains information for\n !! efficient processing after the initial call and `ilo`\n !! must not be changed by the user. each dimension\n !! requires a distinct `ilo` parameter.\n integer,intent(out) :: ileft !! left index\n integer,intent(out) :: iright !! right index\n integer,intent(out) :: mflag !! signals when `x` lies out of bounds\n integer,intent(out),optional :: inearest !! nearest index\n\n integer :: ihi, istep, imid, n\n\n n = size(xt)\n\n if (n==1) then\n ! this is only allowed for nearest interpolation\n if (present(inearest)) then\n inearest = 1\n return\n end if\n end if\n\n ihi = ilo + 1\n if ( ihi>=n ) then\n if ( x>=xt(n) ) then\n mflag = 1\n ileft = n-1\n iright= n\n if (present(inearest)) inearest = n\n return\n end if\n if ( n<=1 ) then\n mflag = -1\n ileft = 1\n iright= 2\n if (present(inearest)) inearest = 1\n return\n end if\n ilo = n - 1\n ihi = n\n endif\n\n if ( x>=xt(ihi) ) then\n\n ! now x >= xt(ilo). find upper bound\n istep = 1\n do\n ilo = ihi\n ihi = ilo + istep\n if ( ihi>=n ) then\n if ( x>=xt(n) ) then\n mflag = 1\n ileft = n-1\n iright= n\n if (present(inearest)) inearest = n\n return\n end if\n ihi = n\n elseif ( x>=xt(ihi) ) then\n istep = istep*2\n cycle\n endif\n exit\n end do\n\n else\n\n if ( x>=xt(ilo) ) then\n mflag = 0\n ileft = ilo\n iright= ilo+1\n if (present(inearest)) then\n if ( abs(x-xt(ileft)) <= abs(x-xt(iright)) ) then\n inearest = ileft\n else\n inearest = iright\n end if\n end if\n return\n end if\n ! now x <= xt(ihi). find lower bound\n istep = 1\n do\n ihi = ilo\n ilo = ihi - istep\n if ( ilo<=1 ) then\n ilo = 1\n if ( x\n! 1D nearest neighbor interpolation routine.\n\n pure subroutine nearest_1d(me,x,f,istat)\n\n implicit none\n\n class(nearest_interp_1d),intent(inout) :: me\n real(wp),intent(in) :: x\n real(wp),intent(out) :: f !! Nearest \\( f(x) \\)\n integer,intent(out),optional :: istat !! `0` : no problems,\n !! `-1` : class has not been initialized\n\n integer :: mflag\n integer,dimension(2) :: ix\n integer :: i\n\n if (me%initialized) then\n\n call dintrv(me%x,x,me%ilox,ix(1),ix(2),mflag,i)\n\n f = me%f(i)\n if (present(istat)) istat = 0\n\n else\n\n if (present(istat)) istat = -1\n f = zero\n\n end if\n\n end subroutine nearest_1d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! 2D nearest neighbor interpolation routine.\n\n pure subroutine nearest_2d(me,x,y,f,istat)\n\n implicit none\n\n class(nearest_interp_2d),intent(inout) :: me\n real(wp),intent(in) :: x\n real(wp),intent(in) :: y\n real(wp),intent(out) :: f !! Nearest \\( f(x,y) \\)\n integer,intent(out),optional :: istat !! `0` : no problems,\n !! `-1` : class has not been initialized\n\n integer :: mflag\n integer,dimension(2) :: ix, iy\n integer :: i, j\n\n if (me%initialized) then\n\n call dintrv(me%x,x,me%ilox,ix(1),ix(2),mflag,i)\n call dintrv(me%y,y,me%iloy,iy(1),iy(2),mflag,j)\n\n f = me%f(i,j)\n if (present(istat)) istat = 0\n\n else\n\n if (present(istat)) istat = -1\n f = zero\n\n end if\n\n end subroutine nearest_2d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! 3D nearest neighbor interpolation routine.\n\n pure subroutine nearest_3d(me,x,y,z,f,istat)\n\n implicit none\n\n class(nearest_interp_3d),intent(inout) :: me\n real(wp),intent(in) :: x\n real(wp),intent(in) :: y\n real(wp),intent(in) :: z\n real(wp),intent(out) :: f !! Nearest \\( f(x,y,z) \\)\n integer,intent(out),optional :: istat !! `0` : no problems,\n !! `-1` : class has not been initialized\n\n integer :: mflag\n integer,dimension(2) :: ix, iy, iz\n integer :: i, j, k\n\n if (me%initialized) then\n\n call dintrv(me%x,x,me%ilox,ix(1),ix(2),mflag,i)\n call dintrv(me%y,y,me%iloy,iy(1),iy(2),mflag,j)\n call dintrv(me%z,z,me%iloz,iz(1),iz(2),mflag,k)\n\n f = me%f(i,j,k)\n if (present(istat)) istat = 0\n\n else\n\n if (present(istat)) istat = -1\n f = zero\n\n end if\n\n end subroutine nearest_3d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! 4D nearest neighbor interpolation routine.\n\n pure subroutine nearest_4d(me,x,y,z,q,f,istat)\n\n implicit none\n\n class(nearest_interp_4d),intent(inout) :: me\n real(wp),intent(in) :: x\n real(wp),intent(in) :: y\n real(wp),intent(in) :: z\n real(wp),intent(in) :: q\n real(wp),intent(out) :: f !! Nearest \\( f(x,y,z,q) \\)\n integer,intent(out),optional :: istat !! `0` : no problems,\n !! `-1` : class has not been initialized\n\n integer :: mflag\n integer,dimension(2) :: ix, iy, iz, iq\n integer :: i, j, k, l\n\n if (me%initialized) then\n\n call dintrv(me%x,x,me%ilox,ix(1),ix(2),mflag,i)\n call dintrv(me%y,y,me%iloy,iy(1),iy(2),mflag,j)\n call dintrv(me%z,z,me%iloz,iz(1),iz(2),mflag,k)\n call dintrv(me%q,q,me%iloq,iq(1),iq(2),mflag,l)\n\n f = me%f(i,j,k,l)\n if (present(istat)) istat = 0\n\n else\n\n if (present(istat)) istat = -1\n f = zero\n\n end if\n\n end subroutine nearest_4d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! 5D nearest neighbor interpolation routine.\n\n pure subroutine nearest_5d(me,x,y,z,q,r,f,istat)\n\n implicit none\n\n class(nearest_interp_5d),intent(inout) :: me\n real(wp),intent(in) :: x\n real(wp),intent(in) :: y\n real(wp),intent(in) :: z\n real(wp),intent(in) :: q\n real(wp),intent(in) :: r\n real(wp),intent(out) :: f !! Nearest \\( f(x,y,z,q,r) \\)\n integer,intent(out),optional :: istat !! `0` : no problems,\n !! `-1` : class has not been initialized\n\n integer :: mflag\n integer,dimension(2) :: ix, iy, iz, iq, ir\n integer :: i, j, k, l, m\n\n if (me%initialized) then\n\n call dintrv(me%x,x,me%ilox,ix(1),ix(2),mflag,i)\n call dintrv(me%y,y,me%iloy,iy(1),iy(2),mflag,j)\n call dintrv(me%z,z,me%iloz,iz(1),iz(2),mflag,k)\n call dintrv(me%q,q,me%iloq,iq(1),iq(2),mflag,l)\n call dintrv(me%r,r,me%ilor,ir(1),ir(2),mflag,m)\n\n f = me%f(i,j,k,l,m)\n if (present(istat)) istat = 0\n\n else\n\n if (present(istat)) istat = -1\n f = zero\n\n end if\n\n end subroutine nearest_5d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! 6D nearest neighbor interpolation routine.\n\n pure subroutine nearest_6d(me,x,y,z,q,r,s,f,istat)\n\n implicit none\n\n class(nearest_interp_6d),intent(inout) :: me\n real(wp),intent(in) :: x\n real(wp),intent(in) :: y\n real(wp),intent(in) :: z\n real(wp),intent(in) :: q\n real(wp),intent(in) :: r\n real(wp),intent(in) :: s\n real(wp),intent(out) :: f !! Nearest \\( f(x,y,z,q,r,s) \\)\n integer,intent(out),optional :: istat !! `0` : no problems,\n !! `-1` : class has not been initialized\n\n integer :: mflag\n integer,dimension(2) :: ix, iy, iz, iq, ir, is\n integer :: i, j, k, l, m, n\n\n if (me%initialized) then\n\n call dintrv(me%x,x,me%ilox,ix(1),ix(2),mflag,i)\n call dintrv(me%y,y,me%iloy,iy(1),iy(2),mflag,j)\n call dintrv(me%z,z,me%iloz,iz(1),iz(2),mflag,k)\n call dintrv(me%q,q,me%iloq,iq(1),iq(2),mflag,l)\n call dintrv(me%r,r,me%ilor,ir(1),ir(2),mflag,m)\n call dintrv(me%s,s,me%ilos,is(1),is(2),mflag,n)\n\n f = me%f(i,j,k,l,m,n)\n if (present(istat)) istat = 0\n\n else\n\n if (present(istat)) istat = -1\n f = zero\n\n end if\n\n end subroutine nearest_6d\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Returns true if all the elements in the array `x` are unique.\n! Note: the array must be sorted.\n!\n!@note This routine is not currently used in the module.\n\n pure function check_if_unique(x) result(unique)\n\n implicit none\n\n real(wp),dimension(:),intent(in) :: x !! a sorted array\n logical :: unique !! true if all elements are unique\n\n integer :: i !! counter\n\n unique = .true. ! initialize\n\n do i=1,size(x)-1\n if (x(i)==x(i+1)) then\n unique = .false.\n exit\n end if\n end do\n\n end function check_if_unique\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Sorts an array `dx` in increasing order,\n! carrying along an additional array `dy`.\n!\n! Uses a non-recursive quicksort, reverting to insertion sort on arrays of\n! size <= 20. Dimension of `stack` limits array size to about \\(2^32\\).\n!\n!### License\n! * [Original LAPACK license](http://www.netlib.org/lapack/LICENSE.txt)\n!\n!### History\n! * Based on the LAPACK routine [DLASRT](http://www.netlib.org/lapack/explore-html/df/ddf/dlasrt_8f.html).\n! * Extensively modified by Jacob Williams, Feb. 2016. Converted to\n! modern Fortran and added the `dy` output. Removed the descending sort option.\n!\n!@note This routine is not currently used in the module.\n\n pure subroutine sort(dx,dy)\n\n implicit none\n\n real(wp),dimension(:),intent(inout) :: dx !! on entry, the array to be sorted.\n !! on exit, `dx` has been sorted into increasing order\n !! (`dx(1) <= ... <= dx(n)`) or into decreasing order\n !! (`dx(1) >= ... >= dx(n)`), depending on `id`.\n real(wp),dimension(:),intent(inout) :: dy !! array carried along with `dx`.\n\n integer,parameter :: select = 20 !! max size for using insertion sort.\n\n integer :: endd, i, j, n, start, stkpnt\n real(wp) :: d1, d2, d3, dmnmx, dmnmy, tmp\n integer,dimension(2,32) :: stack\n\n ! number of elements to sort:\n n = size(dx)\n\n if ( n>1 ) then\n\n stkpnt = 1\n stack(1,1) = 1\n stack(2,1) = n\n\n do\n\n start = stack(1,stkpnt)\n endd = stack(2,stkpnt)\n stkpnt = stkpnt - 1\n if ( endd-start<=select .and. endd>start ) then\n\n ! do insertion sort on dx( start:endd )\n insertion: do i = start + 1, endd\n do j = i, start + 1, -1\n if ( dx(j)>=dx(j-1) ) cycle insertion\n dmnmx = dx(j)\n dx(j) = dx(j-1)\n dx(j-1) = dmnmx\n dmnmy = dy(j)\n dy(j) = dy(j-1)\n dy(j-1) = dmnmy\n enddo\n enddo insertion\n\n elseif ( endd-start>select ) then\n\n ! partition dx( start:endd ) and stack parts, largest one first\n ! choose partition entry as median of 3\n\n d1 = dx(start)\n d2 = dx(endd)\n i = (start+endd)/2\n d3 = dx(i)\n if ( d1=dmnmx ) exit\n end do\n if ( iendd-j-1 ) then\n stkpnt = stkpnt + 1\n stack(1,stkpnt) = start\n stack(2,stkpnt) = j\n stkpnt = stkpnt + 1\n stack(1,stkpnt) = j + 1\n stack(2,stkpnt) = endd\n else\n stkpnt = stkpnt + 1\n stack(1,stkpnt) = j + 1\n stack(2,stkpnt) = endd\n stkpnt = stkpnt + 1\n stack(1,stkpnt) = start\n stack(2,stkpnt) = j\n endif\n\n endif\n\n if ( stkpnt<=0 ) exit\n\n end do\n\n end if\n\n end subroutine sort\n!*****************************************************************************************\n\n!*****************************************************************************************\n!>\n! Check the validity of the inputs to the initialize routines.\n! Prints warning message if there is an error,\n! and also sets `ierr` (/=0 if there were any errors).\n!\n! Supports up to 6D: x,y,z,q,r,s\n!\n!# History\n! * Jacob Williams, 2/24/2015 : Created this routine.\n! * Jacob Williams, 2/23/2016 : modified for linear interp module.\n\n pure subroutine check_inputs(me,x,y,z,q,r,s,ierr)\n\n implicit none\n\n class(linear_interp_class),intent(in) :: me\n real(wp),dimension(:),intent(in),optional :: x !! `x` abscissa vector\n real(wp),dimension(:),intent(in),optional :: y !! `y` abscissa vector\n real(wp),dimension(:),intent(in),optional :: z !! `z` abscissa vector\n real(wp),dimension(:),intent(in),optional :: q !! `q` abscissa vector\n real(wp),dimension(:),intent(in),optional :: r !! `r` abscissa vector\n real(wp),dimension(:),intent(in),optional :: s !! `s` abscissa vector\n integer,intent(out) :: ierr !! `0` : no problems,\n !! `1` : `x` is not strictly increasing,\n !! `2` : `y` is not strictly increasing,\n !! `3` : `z` is not strictly increasing,\n !! `4` : `q` is not strictly increasing,\n !! `5` : `r` is not strictly increasing,\n !! `6` : `s` is not strictly increasing,\n !! `100` : cannot use linear interpolation for only one point.\n\n ierr = 0 ! initialize\n\n if (present(x)) call check(x,1,ierr); if (ierr/=0) return\n if (present(y)) call check(y,2,ierr); if (ierr/=0) return\n if (present(z)) call check(z,3,ierr); if (ierr/=0) return\n if (present(q)) call check(q,4,ierr); if (ierr/=0) return\n if (present(r)) call check(r,5,ierr); if (ierr/=0) return\n if (present(s)) call check(s,6,ierr); if (ierr/=0) return\n\n if (ierr == 0) then\n select type (me)\n class is (nearest_interp_1d)\n class is (nearest_interp_2d)\n class is (nearest_interp_3d)\n class is (nearest_interp_4d)\n class is (nearest_interp_5d)\n class is (nearest_interp_6d)\n class default\n ! need at least two points for linear interpolation:\n if (size(x)==1) ierr = 100\n end select\n end if\n\n contains\n!*****************************************************************************************\n\n pure subroutine check(v,error_code,ierr)\n\n implicit none\n\n real(wp),dimension(:),intent(in) :: v !! abcissae vector\n integer,intent(in) :: error_code !! error code for check\n integer,intent(inout) :: ierr !! will be set to `error_code` if there is a problem\n\n integer :: i !! counter\n integer :: n !! size of the input `v` array\n\n n = size(v)\n do i=2,n\n if (v(i) <= v(i-1)) then\n ierr = error_code\n exit\n end if\n end do\n\n end subroutine check\n\n end subroutine check_inputs\n!*****************************************************************************************\n\n!*****************************************************************************************\n end module linear_interpolation_module\n!*****************************************************************************************\n", "meta": {"hexsha": "4f4239edb6e6da3b4c6995fcd166b3ba194b9b32", "size": 66580, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/linear_interpolation_module.f90", "max_stars_repo_name": "jacobwilliams/finterp", "max_stars_repo_head_hexsha": "cccb3c9c5547d951983bf8471f7abb0191f712fa", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 42, "max_stars_repo_stars_event_min_datetime": "2016-03-02T03:08:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T21:02:34.000Z", "max_issues_repo_path": "src/linear_interpolation_module.f90", "max_issues_repo_name": "jacobwilliams/finterp", "max_issues_repo_head_hexsha": "cccb3c9c5547d951983bf8471f7abb0191f712fa", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2019-10-10T04:31:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T23:57:05.000Z", "max_forks_repo_path": "src/linear_interpolation_module.f90", "max_forks_repo_name": "jacobwilliams/finterp", "max_forks_repo_head_hexsha": "cccb3c9c5547d951983bf8471f7abb0191f712fa", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2016-03-13T13:36:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-26T03:21:47.000Z", "avg_line_length": 37.2788353863, "max_line_length": 118, "alphanum_fraction": 0.4461249625, "num_tokens": 19680, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312226373181, "lm_q2_score": 0.7185943925708561, "lm_q1q2_score": 0.6519894781827471}} {"text": " SUBROUTINE CNMN04 (II,XBAR,EPS,X1,Y1,SLOPE,X2,Y2,X3,Y3,X4,Y4)\n IMPLICIT DOUBLE PRECISION(A-H,O-Z)\nC ROUTINE TO FIND FIRST XBAR.GE.EPS CORRESPONDING TO A MINIMUM\nC OF A ONE-DIMENSIONAL REAL FUNCTION BY POLYNOMIEL INTERPOLATION. \nC BY G. N. VANDERPLAATS APRIL, 1972. \nC NASA-AMES RESEARCH CENTER, MOFFETT FIELD, CALIF. \nC \nC II = CALCULATION CONTROL. \nC 1: 2-POINT QUADRATIC INTERPOLATION, GIVEN X1, Y1, SLOPE,\nC X2 AND Y2. \nC 2: 3-POINT QUADRATIC INTERPOLATION, GIVEN X1, Y1, X2, Y2, \nC X3 AND Y3. \nC 3: 3-POINT CUBIC INTERPOLATION, GIVEN X1, Y1, SLOPE, X2, Y2,\nC X3 AND Y3. \nC 4: 4-POINT CUBIC INTERPOLATION, GIVEN X1, Y1, X2, Y2, X3, \nC Y3, X4 AND Y4. \nC EPS MAY BE NEGATIVE.\nC IF REQUIRED MINIMUM ON Y DOES NOT EXITS, OR THE FUNCTION IS \nC ILL-CONDITIONED, XBAR = EPS-1.0 WILL BE RETURNED AS AN ERROR\nC INDICATOR.\nC IF DESIRED INTERPOLATION IS ILL-CONDITIONED, A LOWER ORDER\nC INTERPOLATION, CONSISTANT WITH INPUT DATA, WILL BE ATTEMPTED, \nC AND II WILL BE CHANGED ACCORDINGLY. \n XBAR1=EPS-1.\n XBAR=XBAR1\n X21=X2-X1 \n IF (ABS(X21).LT.1.0E-20) RETURN \n NSLOP=MOD(II,2) \n GO TO (10,20,40,50),II\n10 CONTINUE\nC ------------------------------------------------------------------\nC II=1: 2-POINT QUADRATIC INTERPOLATION \nC ------------------------------------------------------------------\n II=1\n DX=X1-X2\n IF (ABS(DX).LT.1.0E-20) RETURN\n AA=(SLOPE+(Y2-Y1)/DX)/DX\n IF (AA.LT.1.0E-20) RETURN \n BB=SLOPE-2.*AA*X1 \n XBAR=-.5*BB/AA\n IF (XBAR.LT.EPS) XBAR=XBAR1 \n RETURN\n20 CONTINUE\nC ------------------------------------------------------------------\nC II=2: 3-POINT QUADRATIC INTERPOLATION \nC ------------------------------------------------------------------\n II=2\n X21=X2-X1 \n X31=X3-X1 \n X32=X3-X2 \n QQ=X21*X31*X32\n IF (ABS(QQ).LT.1.0E-20) RETURN\n AA=(Y1*X32-Y2*X31+Y3*X21)/QQ\n IF (AA.LT.1.0E-20) GO TO 30 \n BB=(Y2-Y1)/X21-AA*(X1+X2) \n XBAR=-.5*BB/AA\n IF (XBAR.LT.EPS) XBAR=XBAR1 \n RETURN\n30 CONTINUE\n IF (NSLOP.EQ.0) RETURN\n GO TO 10\n40 CONTINUE\nC ------------------------------------------------------------------\nC II=3: 3-POINT CUBIC INTERPOLATION \nC ------------------------------------------------------------------\n II=3\n X21=X2-X1 \n X31=X3-X1 \n X32=X3-X2 \n QQ=X21*X31*X32\n IF (ABS(QQ).LT.1.0E-20) RETURN\n X11=X1*X1 \n DNOM=X2*X2*X31-X11*X32-X3*X3*X21\n IF (ABS(DNOM).LT.1.0E-20) GO TO 20\n AA=((X31*X31*(Y2-Y1)-X21*X21*(Y3-Y1))/(X31*X21)-SLOPE*X32)/DNOM \n IF (ABS(AA).LT.1.0E-20) GO TO 20\n BB=((Y2-Y1)/X21-SLOPE-AA*(X2*X2+X1*X2-2.*X11))/X21\n CC=SLOPE-3.*AA*X11-2.*BB*X1 \n BAC=BB*BB-3.*AA*CC\n IF (BAC.LT.0.) GO TO 20 \n BAC=SQRT(BAC) \n XBAR=(BAC-BB)/(3.*AA) \n IF (XBAR.LT.EPS) XBAR=EPS \n RETURN\n50 CONTINUE\nC ------------------------------------------------------------------\nC II=4: 4-POINT CUBIC INTERPOLATION\nC ------------------------------------------------------------------\n X21=X2-X1 \n X31=X3-X1 \n X41=X4-X1 \n X32=X3-X2 \n X42=X4-X2 \n X11=X1*X1 \n X22=X2*X2 \n X33=X3*X3 \n X44=X4*X4 \n X111=X1*X11 \n X222=X2*X22 \n Q2=X31*X21*X32\n IF (ABS(Q2).LT.1.0E-30) RETURN\n Q1=X111*X32-X222*X31+X3*X33*X21 \n Q4=X111*X42-X222*X41+X4*X44*X21 \n Q5=X41*X21*X42\n DNOM=Q2*Q4-Q1*Q5\n IF (ABS(DNOM).LT.1.0E-30) GO TO 60\n Q3=Y3*X21-Y2*X31+Y1*X32 \n Q6=Y4*X21-Y2*X41+Y1*X42 \n AA=(Q2*Q6-Q3*Q5)/DNOM \n BB=(Q3-Q1*AA)/Q2\n CC=(Y2-Y1-AA*(X222-X111))/X21-BB*(X1+X2)\n BAC=BB*BB-3.*AA*CC\n IF (ABS(AA).LT.1.0E-20.OR.BAC.LT.0.) GO TO 60 \n BAC=SQRT(BAC) \n XBAR=(BAC-BB)/(3.*AA) \n IF (XBAR.LT.EPS) XBAR=XBAR1 \n RETURN\n60 CONTINUE\n IF (NSLOP.EQ.1) GO TO 40\n GO TO 20\n END ", "meta": {"hexsha": "e621a9f0b1ddff57a171e4cc036e96eda2533c3d", "size": 4133, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "docker/optimization/pyOpt/tags/v1.2.0/pyOpt/pyCONMIN/source/cnmn04.f", "max_stars_repo_name": "liujiamingustc/phd", "max_stars_repo_head_hexsha": "4f815a738abad43531d02ac66f5bd0d9a1def52a", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-01-06T03:01:18.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T03:02:55.000Z", "max_issues_repo_path": "docker/optimization/pyOpt/tags/v1.2.0/pyOpt/pyCONMIN/source/cnmn04.f", "max_issues_repo_name": "liujiamingustc/phd", "max_issues_repo_head_hexsha": "4f815a738abad43531d02ac66f5bd0d9a1def52a", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docker/optimization/pyOpt/tags/v1.2.0/pyOpt/pyCONMIN/source/cnmn04.f", "max_forks_repo_name": "liujiamingustc/phd", "max_forks_repo_head_hexsha": "4f815a738abad43531d02ac66f5bd0d9a1def52a", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.1570247934, "max_line_length": 72, "alphanum_fraction": 0.4710863779, "num_tokens": 1567, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312213841788, "lm_q2_score": 0.718594386544335, "lm_q1q2_score": 0.6519894637098221}} {"text": "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!!!!!! FEAST Expert Driver - Dense Storage\n!!!!!!! solving Ax=ex with A complex-symmetric (non-Hermitian)\n!!!!!!! James Kestyn, Eric Polizzi 2015\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nprogram pdriver \n\n implicit none\ninclude 'mpif.h'\n!!!!!!!!!!!!!!!!! Feast declaration variable\n integer,dimension(64) :: feastparam \n integer :: loop\n character(len=1) :: UPLO='F' ! 'L' or 'U' also fine\n\n!!!!!!!!!!!!!!!!! Matrix declaration variable\n character(len=100) :: name\n integer :: n,nnz\n complex(kind=kind(1.0d0)),dimension(:,:),allocatable :: A,B\n\n!!!!!!!!!!!!!!!!! Contour\n integer :: ccN\n complex(kind=kind(1.0d0)),dimension(:),allocatable :: Zne, Wne, Zedge\n integer, dimension(:), allocatable :: Nedge, Tedge \n\n!!!!!!!!!!!!!!!!! FEAST\n integer :: M0,M,info\n double precision :: r,epsout \n complex(kind=kind(1.0d0)) :: Emid \n complex(kind=kind(1.0d0)),dimension(:,:),allocatable :: XR ! eigenvectors\n complex(kind=kind(1.0d0)),dimension(:),allocatable :: E ! eigenvalues\n double precision,dimension(:),allocatable :: resr ! residual\n\n!!!!!!!!!!!!!!!!! Others\n integer :: t1,t2,tim\n integer :: i,j,k\n double precision :: rea,img\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! MPI!!!!!!!!!!!!!!!!!!!!\ninteger :: code,rank,nb_procs\n call MPI_INIT(code)\n call MPI_COMM_SIZE(MPI_COMM_WORLD,nb_procs,code)\n call MPI_COMM_RANK(MPI_COMM_WORLD,rank,code)\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!!!!!!!!Read Coordinate format and convert to dense format\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n name='../../system4'\n\n\n open(10,file=trim(name),status='old')\n read(10,*) n,nnz\n allocate(A(1:n,1:n))\n A=0.0d0\n do k=1,nnz\n read(10,*) i,j,rea,img\n A(i,j)=rea*(1.0d0,0.0d0)+img*(0.0d0,1.0d0)\n enddo\n close(10)\n\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!!!!!!!!!!!!!!!!!!!!! INFORMATION ABOUT MATRIX !!!!!!!!!!!!!!!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n if(rank ==0) print *,'dense matrix -system4- size',n\n\n call system_clock(t1,tim)\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!!!!!!!!!!!!!!!!!! FEAST in dense format !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n call feastinit(feastparam)\n feastparam(1)=1\n M0=50 !! M0>=M\n\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n ! Create Custom Contour\n\n ccN = 3 !! number of pieces that make up contour\n allocate(Zedge(1:ccN))\n allocate(Nedge(1:ccN))\n allocate(Tedge(1:ccN))\n\n !!! Example contour - triangle \n Zedge = (/(0.10d0,0.410d0),(4.2d0,0.41d0),(4.2d0,-8.3d0)/)\n Tedge(:) = (/0,0,0/)\n Nedge(:) = (/6,6,18/)\n\n !! Note: user must specify total # of contour points and edit feastparam(8)\n feastparam(8) = sum(Nedge(1:ccN))\n allocate(Zne(1:feastparam(8))) !! Contains the complex valued contour points \n allocate(Wne(1:feastparam(8))) !! Contains the complex valued integrations weights\n\n !! Fill Zne/Wne\n print *, 'Enter FEAST CC'\n call zfeast_customcontour(feastparam(8),ccN,Nedge,Tedge,Zedge,Zne,Wne)\n\nif(rank==0)then\n print *,'---- Printing Countour ----'\n do i=1,feastparam(8)\n write(*,*)i,dble(Zne(i)),aimag(Zne(i))\n enddo\nendif\n\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n!!!!!!!!!!!!! ALLOCATE VARIABLE \n allocate(E(1:M0)) ! Eigenvalue\n allocate(XR(1:n,1:M0)) ! Right Eigenvectors ( XL = CONJG(XR) )\n allocate(resr(1:M0)) ! Residual (if needed)\n\n!!!!!!!!!!!! FEAST\n print *, 'Enter FEAST',rank\n call zfeast_syevx(UPLO,N,A,N,feastparam,epsout,loop,Emid,r,M0,E,XR,M,resr,info,Zne,Wne)\n\n!!!!!!!!!! POST-PROCESSING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n call system_clock(t2,tim)\n if(rank==0)print *,'FEAST OUTPUT INFO',info\n if (info==0 .and. rank==0) then\n print *,'*************************************************'\n print *,'************** REPORT ***************************'\n print *,'*************************************************'\n print *,'SIMULATION TIME',(t2-t1)*1.0d0/tim\n print *,'# mode found/subspace',M,M0\n print *,'# iterations',loop\n print *,'TRACE',sum(E(1:M))\n print *,'Relative error on the Trace',epsout\n print *,'Eigenvalues/Residuals'\n do i=1,M\n print *,i,dble(E(i)),aimag(E(i)),resr(i)\n enddo\n endif\n\n call MPI_FINALIZE(code)\n\nend program pdriver \n\n\n\n", "meta": {"hexsha": "1ec12c5bde7e5564ee4753d249fc66adfbee34df", "size": 4507, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/Non-Hermitian/Fortran-MPI/1_dense/pdriver_zfeast_syevx.f90", "max_stars_repo_name": "PFEM/feast", "max_stars_repo_head_hexsha": "79c7a67167f92ce5ebdc6f28b1ff856575adcbb7", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-16T13:18:41.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-16T13:18:41.000Z", "max_issues_repo_path": "example/Non-Hermitian/Fortran-MPI/1_dense/pdriver_zfeast_syevx.f90", "max_issues_repo_name": "PFEM/feast", "max_issues_repo_head_hexsha": "79c7a67167f92ce5ebdc6f28b1ff856575adcbb7", "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": "example/Non-Hermitian/Fortran-MPI/1_dense/pdriver_zfeast_syevx.f90", "max_forks_repo_name": "PFEM/feast", "max_forks_repo_head_hexsha": "79c7a67167f92ce5ebdc6f28b1ff856575adcbb7", "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.9645390071, "max_line_length": 89, "alphanum_fraction": 0.4896827158, "num_tokens": 1316, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110569397306, "lm_q2_score": 0.731058584489497, "lm_q1q2_score": 0.6519661289184416}} {"text": "program problem37\n use euler\n implicit none\n integer, parameter :: limit=11\n integer :: count=0,answer=0\n integer*8 :: i\n\n i=11\n do while(count0)\n if (.not. is_prime(temp)) then\n left_prime=.false.\n exit\n end if\n temp=mod(temp,10**(number_length(temp)-1))\n end do\n\n end function left_prime\n\n pure function right_prime(n)\n implicit none\n integer*8, intent(in) :: n\n integer*8 :: temp\n logical :: right_prime\n\n right_prime=.true.\n temp=n\n do while(temp>0)\n if (.not. is_prime(temp)) then\n right_prime=.false.\n exit\n end if\n temp=temp/10\n end do\n\n end function right_prime\n\nend program problem37\n", "meta": {"hexsha": "2d016183d47d5ce329489213901f121a84ddc474", "size": 1138, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "problem37.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": "problem37.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": "problem37.f08", "max_forks_repo_name": "jamesmcclain/Dioskouroi", "max_forks_repo_head_hexsha": "e433cbf7a1306d2755723f1028a4a3034da9d64a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.2881355932, "max_line_length": 49, "alphanum_fraction": 0.5562390158, "num_tokens": 308, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6519661194886368}} {"text": "! The KISS (Keep It Simple Stupid) random number generator. Combines:\n! (1) The congruential generator x(n)=69069*x(n-1)+1327217885, period 2^32.\n! (2) A 3-shift shift-register generator, period 2^32-1,\n! (3) Two 16-bit multiply-with-carry generators, period 597273182964842497>2^59\n! Overall period>2^123;\n!\n FUNCTION random()\n IMPLICIT NONE\n INTEGER(kind=4) :: kiss,x,y,z,w\n REAL(kind=8) :: random\n\tCOMMON /kisscom/x,y,z,w\nC\n x = 69069*x + 1327217885\n y = IEOR(y,ISHFT(y,13))\n y = IEOR(y,ISHFT(y,-17))\n y = IEOR(y,ISHFT(y,5))\n z = 18000*IAND(z,65535) + ISHFT(z,-16)\n w = 30903*IAND(w,65535) + ISHFT(w,-16)\n kiss = x + y + ISHFT(z,16) + w\n random = (DBLE(kiss) + 2147483648.d0)/4294967296.d0\n RETURN\n\tEND\n!-------------------------------\n SUBROUTINE rand_init(seed)\n!-------------------------------\n IMPLICIT NONE\n INTEGER,INTENT(IN) :: seed\n INTEGER,PARAMETER :: init_x = 123456789\n INTEGER,PARAMETER :: init_y = 362436069\n INTEGER,PARAMETER :: init_z = 521288629\n INTEGER,PARAMETER :: init_w = 916191069\n REAL(kind=4) :: x,y,z,w\n\tCOMMON /kisscom/x,y,z,w\nc\n x = init_x + seed\n y = init_y + seed\n z = init_z + seed\n w = init_w + seed\n\n END SUBROUTINE\nc\nc Uncomment the following section to test the random number generator\nc gfortran random.f ; for mpi processes, use mpif90 random.f\nc ./a.out ; for mpi process, use mpirun -np 4 ./a.out\nc PROGRAM main\nc\tIMPLICIT NONE\nc INCLUDE \"mpif.h\"\nc\tINTEGER :: i,seed\nc INTEGER :: myrank,ierr,nprocs\nc\tREAL(kind=8) :: rand,rand2,random\nc CHARACTER(LEN=100):: fo_name2\nc\nc CALL MPI_INIT(IERR)\nc CALL MPI_COMM_SIZE(MPI_COMM_WORLD,NPROCS,IERR)\nc CALL MPI_COMM_RANK(MPI_COMM_WORLD,MYRANK,IERR)\nc\tseed = 123456789*(1 + myrank)\nc \tCALL rand_init(seed)\nc\tWRITE(*,*) myrank, seed\nc WRITE(fo_name2,444) 'random',myrank\nc OPEN (1,file=fo_name2,form='formatted',status='unknown')\nc\nc\tDO i = 1,700\nc WRITE(1,*) random(), random()\nc\tEND DO\nc\nc CLOSE(1)\nc CALL MPI_FINALIZE(IERR)\nc444 FORMAT(A,I3.3,'.dat')\nc\tSTOP\nc END\n", "meta": {"hexsha": "0835ccf8fb04a5a6c40fbd34f99bdb9a77a6038b", "size": 2161, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/random.f", "max_stars_repo_name": "StevE-Ong/LEC", "max_stars_repo_head_hexsha": "df479b38de83f6629ad5453760c166f9289b38e6", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-07-02T14:57:31.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-19T09:44:40.000Z", "max_issues_repo_path": "src/random.f", "max_issues_repo_name": "StevE-Ong/LEC", "max_issues_repo_head_hexsha": "df479b38de83f6629ad5453760c166f9289b38e6", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-07-23T15:05:27.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-19T12:12:53.000Z", "max_forks_repo_path": "src/random.f", "max_forks_repo_name": "StevE-Ong/LEC", "max_forks_repo_head_hexsha": "df479b38de83f6629ad5453760c166f9289b38e6", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-07-24T08:11:32.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-10T02:58:14.000Z", "avg_line_length": 30.4366197183, "max_line_length": 79, "alphanum_fraction": 0.6131420639, "num_tokens": 739, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379297, "lm_q2_score": 0.7310585786300048, "lm_q1q2_score": 0.6519661152843915}} {"text": "********************************************************************** \n********************************************************************** \n subroutine detko(alf,phi,del)\n*\n* is called to determine coefficients of taylor series for interpolation\n*\tof deflection angle due to cells\n*\n* input:\n* alf(8) - vector with four angles alphax(1), ..., alphay(4) \n* del - distance between two adjacent rays \n*\n* output:\n* phi(8) - coefficients\n*\n* called in:\n* main\n*\n* use of subroutines:\n* none\n*\n* use of functions:\n* none\n*\t\t\t\t\tOctober 31, 1991; J. Wambsganss\n*\n implicit none\n integer debug\n double precision alf(8),phi(8),fac(4),del,oodel\n common/test/debug\n*\n oodel = 1.0d0/del\n fac(1) = 0.250d0\n fac(2) = 0.125d0*oodel\n fac(3) = 0.250d0*oodel*oodel\n fac(4) = 0.375d0*oodel*oodel*oodel\n*\n phi(1) = fac(1)*\n & (+alf(1) +alf(3) +alf(5) +alf(7) )\n phi(2) = fac(1)*\n & ( +alf(2) +alf(4) +alf(6) +alf(8) )\n phi(3) = fac(2)*\n & (+alf(1)-alf(2)-alf(3)-alf(4)-alf(5)+alf(6)+alf(7)+alf(8) )\n phi(4) = fac(2)*\n & (+alf(1)+alf(2)+alf(3)-alf(4)-alf(5)-alf(6)-alf(7)+alf(8) )\n phi(5) = fac(3)*\n & ( -alf(2) +alf(4) -alf(6) +alf(8) )\n phi(6) = fac(3)*\n & (+alf(1) -alf(3) +alf(5) -alf(7) )\n phi(7) = fac(4)*\n & (-alf(1)-alf(2)+alf(3)-alf(4)+alf(5)+alf(6)-alf(7)+alf(8) )\n phi(8) = fac(4)*\n & (+alf(1)-alf(2)+alf(3)+alf(4)-alf(5)+alf(6)-alf(7)-alf(8) )\n*\n return\n end\n", "meta": {"hexsha": "a3a8be8dbda30192cac802689d11e3d3a59cfc75", "size": 1700, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "sntd/microlens/detko.f", "max_stars_repo_name": "srodney/sntd", "max_stars_repo_head_hexsha": "c091e3ce76fcb6a73d31eb2a719bbb4fc649016c", "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": "sntd/microlens/detko.f", "max_issues_repo_name": "srodney/sntd", "max_issues_repo_head_hexsha": "c091e3ce76fcb6a73d31eb2a719bbb4fc649016c", "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": "sntd/microlens/detko.f", "max_forks_repo_name": "srodney/sntd", "max_forks_repo_head_hexsha": "c091e3ce76fcb6a73d31eb2a719bbb4fc649016c", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-08T13:06:50.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-08T13:06:50.000Z", "avg_line_length": 30.9090909091, "max_line_length": 72, "alphanum_fraction": 0.4147058824, "num_tokens": 625, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379296, "lm_q2_score": 0.7310585786300048, "lm_q1q2_score": 0.6519661152843914}} {"text": "FUNCTION zeroin(f, ax, bx, aerr, rerr) RESULT(fn_val)\r\n \r\n! Code converted using TO_F90 by Alan Miller\r\n! Date: 2003-07-14 Time: 12:32:54\r\n \r\n!-----------------------------------------------------------------------\r\n\r\n! FINDING A ZERO OF THE FUNCTION F(X) IN THE INTERVAL (AX,BX)\r\n\r\n! ------------------------\r\n\r\n! INPUT...\r\n\r\n! F FUNCTION SUBPROGRAM WHICH EVALUATES F(X) FOR ANY X IN THE\r\n! CLOSED INTERVAL (AX,BX). IT IS ASSUMED THAT F IS CONTINUOUS,\r\n! AND THAT F(AX) AND F(BX) HAVE DIFFERENT SIGNS.\r\n! AX LEFT ENDPOINT OF THE INTERVAL\r\n! BX RIGHT ENDPOINT OF THE INTERVAL\r\n! AERR THE ABSOLUTE ERROR TOLERANCE TO BE SATISFIED\r\n! RERR THE RELATIVE ERROR TOLERANCE TO BE SATISFIED\r\n\r\n! OUTPUT...\r\n\r\n! ABCISSA APPROXIMATING A ZERO OF F IN THE INTERVAL (AX,BX)\r\n\r\n!-----------------------------------------------------------------------\r\n! ZEROIN IS A SLIGHTLY MODIFIED TRANSLATION OF THE ALGOL PROCEDURE\r\n! ZERO GIVEN BY RICHARD BRENT IN ALGORITHMS FOR MINIMIZATION WITHOUT\r\n! DERIVATIVES, PRENTICE-HALL, INC. (1973).\r\n!-----------------------------------------------------------------------\r\n\r\nIMPLICIT NONE\r\nINTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(14, 60)\r\n\r\nREAL (dp), INTENT(IN) :: ax\r\nREAL (dp), INTENT(IN) :: bx\r\nREAL (dp), INTENT(IN) :: aerr\r\nREAL (dp), INTENT(IN) :: rerr\r\nREAL (dp) :: fn_val\r\n\r\n! EXTERNAL f\r\nINTERFACE\r\n FUNCTION f(x) RESULT(fn_val)\r\n IMPLICIT NONE\r\n INTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(14, 60)\r\n REAL (dp), INTENT(IN) :: x\r\n REAL (dp) :: fn_val\r\n END FUNCTION f\r\nEND INTERFACE\r\n\r\nREAL (dp) :: a, b, c, d, e, eps, fa, fb, fc, tol, xm, p, q, r, s, atol, rtol\r\n\r\n! COMPUTE EPS, THE RELATIVE MACHINE PRECISION\r\n\r\neps = EPSILON(0.0_dp)\r\n\r\n! INITIALIZATION\r\n\r\na = ax\r\nb = bx\r\nfa = f(a)\r\nfb = f(b)\r\natol = 0.5 * aerr\r\nrtol = MAX(0.5_dp*rerr, 2.0_dp*eps)\r\n\r\n! BEGIN STEP\r\n\r\n10 c = a\r\nfc = fa\r\nd = b - a\r\ne = d\r\n20 IF (ABS(fc) < ABS(fb)) THEN\r\n a = b\r\n b = c\r\n c = a\r\n fa = fb\r\n fb = fc\r\n fc = fa\r\nEND IF\r\n\r\n! CONVERGENCE TEST\r\n\r\ntol = rtol * MAX(ABS(b),ABS(c)) + atol\r\nxm = 0.5 * (c-b)\r\nIF (ABS(xm) > tol) THEN\r\n IF (fb /= 0.0) THEN\r\n \r\n! IS BISECTION NECESSARY\r\n \r\n IF (ABS(e) >= tol) THEN\r\n IF (ABS(fa) > ABS(fb)) THEN\r\n \r\n! IS QUADRATIC INTERPOLATION POSSIBLE\r\n \r\n IF (a == c) THEN\r\n \r\n! LINEAR INTERPOLATION\r\n \r\n s = fb / fc\r\n p = (c-b) * s\r\n q = 1.0 - s\r\n ELSE\r\n \r\n! INVERSE QUADRATIC INTERPOLATION\r\n \r\n q = fa / fc\r\n r = fb / fc\r\n s = fb / fa\r\n p = s * ((c-b)*q*(q-r)-(b-a)*(r-1.0))\r\n q = (q-1.0) * (r-1.0) * (s-1.0)\r\n END IF\r\n \r\n! ADJUST SIGNS\r\n \r\n IF (p > 0.0) q = -q\r\n p = ABS(p)\r\n \r\n! IS INTERPOLATION ACCEPTABLE\r\n \r\n IF (2.0*p < (3.0*xm*q-ABS(tol*q))) THEN\r\n IF (p < ABS(0.5*e*q)) THEN\r\n e = d\r\n d = p / q\r\n GO TO 30\r\n END IF\r\n END IF\r\n END IF\r\n END IF\r\n \r\n! BISECTION\r\n \r\n d = xm\r\n e = d\r\n \r\n! COMPLETE STEP\r\n \r\n 30 a = b\r\n fa = fb\r\n IF (ABS(d) > tol) b = b + d\r\n IF (ABS(d) <= tol) b = b + SIGN(tol,xm)\r\n fb = f(b)\r\n IF (fb*(fc/ABS(fc)) > 0.0) GO TO 10\r\n GO TO 20\r\n END IF\r\nEND IF\r\n\r\n! DONE\r\n\r\nfn_val = b\r\nRETURN\r\nEND FUNCTION zeroin\r\n", "meta": {"hexsha": "13ce8c0c91504aa85d30ef482363292f556c624b", "size": 3434, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/zeroin.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/zeroin.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/zeroin.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": 22.5921052632, "max_line_length": 78, "alphanum_fraction": 0.4688410017, "num_tokens": 1102, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127678225575, "lm_q2_score": 0.7634837743174788, "lm_q1q2_score": 0.6519485429150512}} {"text": "*DECK DQAWCE\n SUBROUTINE DQAWCE (F, A, B, C, EPSABS, EPSREL, LIMIT, RESULT,\n + ABSERR, NEVAL, IER, ALIST, BLIST, RLIST, ELIST, IORD, LAST)\nC***BEGIN PROLOGUE DQAWCE\nC***PURPOSE The routine calculates an approximation result to a\nC CAUCHY PRINCIPAL VALUE I = Integral of F*W over (A,B)\nC (W(X) = 1/(X-C), (C.NE.A, C.NE.B), hopefully satisfying\nC following claim for accuracy\nC ABS(I-RESULT).LE.MAX(EPSABS,EPSREL*ABS(I))\nC***LIBRARY SLATEC (QUADPACK)\nC***CATEGORY H2A2A1, J4\nC***TYPE DOUBLE PRECISION (QAWCE-S, DQAWCE-D)\nC***KEYWORDS AUTOMATIC INTEGRATOR, CAUCHY PRINCIPAL VALUE,\nC CLENSHAW-CURTIS METHOD, QUADPACK, QUADRATURE,\nC SPECIAL-PURPOSE\nC***AUTHOR Piessens, Robert\nC Applied Mathematics and Programming Division\nC K. U. Leuven\nC de Doncker, Elise\nC Applied Mathematics and Programming Division\nC K. U. Leuven\nC***DESCRIPTION\nC\nC Computation of a CAUCHY PRINCIPAL VALUE\nC Standard fortran subroutine\nC Double precision version\nC\nC PARAMETERS\nC ON ENTRY\nC F - Double precision\nC Function subprogram defining the integrand\nC function F(X). The actual name for F needs to be\nC declared E X T E R N A L in the driver program.\nC\nC A - Double precision\nC Lower limit of integration\nC\nC B - Double precision\nC Upper limit of integration\nC\nC C - Double precision\nC Parameter in the WEIGHT function, C.NE.A, C.NE.B\nC If C = A OR C = B, the routine will end with\nC IER = 6.\nC\nC EPSABS - Double precision\nC Absolute accuracy requested\nC EPSREL - Double precision\nC Relative accuracy requested\nC If EPSABS.LE.0\nC and EPSREL.LT.MAX(50*REL.MACH.ACC.,0.5D-28),\nC the routine will end with IER = 6.\nC\nC LIMIT - Integer\nC Gives an upper bound on the number of subintervals\nC in the partition of (A,B), LIMIT.GE.1\nC\nC ON RETURN\nC RESULT - Double precision\nC Approximation to the integral\nC\nC ABSERR - Double precision\nC Estimate of the modulus of the absolute error,\nC which should equal or exceed ABS(I-RESULT)\nC\nC NEVAL - Integer\nC Number of integrand evaluations\nC\nC IER - Integer\nC IER = 0 Normal and reliable termination of the\nC routine. It is assumed that the requested\nC accuracy has been achieved.\nC IER.GT.0 Abnormal termination of the routine\nC the estimates for integral and error are\nC less reliable. It is assumed that the\nC requested accuracy has not been achieved.\nC ERROR MESSAGES\nC IER = 1 Maximum number of subdivisions allowed\nC has been achieved. One can allow more sub-\nC divisions by increasing the value of\nC LIMIT. However, if this yields no\nC improvement it is advised to analyze the\nC the integrand, in order to determine the\nC the integration difficulties. If the\nC position of a local difficulty can be\nC determined (e.g. SINGULARITY,\nC DISCONTINUITY within the interval) one\nC will probably gain from splitting up the\nC interval at this point and calling\nC appropriate integrators on the subranges.\nC = 2 The occurrence of roundoff error is detec-\nC ted, which prevents the requested\nC tolerance from being achieved.\nC = 3 Extremely bad integrand behaviour\nC occurs at some interior points of\nC the integration interval.\nC = 6 The input is invalid, because\nC C = A or C = B or\nC (EPSABS.LE.0 and\nC EPSREL.LT.MAX(50*REL.MACH.ACC.,0.5D-28))\nC or LIMIT.LT.1.\nC RESULT, ABSERR, NEVAL, RLIST(1), ELIST(1),\nC IORD(1) and LAST are set to zero. ALIST(1)\nC and BLIST(1) are set to A and B\nC respectively.\nC\nC ALIST - Double precision\nC Vector of dimension at least LIMIT, the first\nC LAST elements of which are the left\nC end points of the subintervals in the partition\nC of the given integration range (A,B)\nC\nC BLIST - Double precision\nC Vector of dimension at least LIMIT, the first\nC LAST elements of which are the right\nC end points of the subintervals in the partition\nC of the given integration range (A,B)\nC\nC RLIST - Double precision\nC Vector of dimension at least LIMIT, the first\nC LAST elements of which are the integral\nC approximations on the subintervals\nC\nC ELIST - Double precision\nC Vector of dimension LIMIT, the first LAST\nC elements of which are the moduli of the absolute\nC error estimates on the subintervals\nC\nC IORD - Integer\nC Vector of dimension at least LIMIT, the first K\nC elements of which are pointers to the error\nC estimates over the subintervals, so that\nC ELIST(IORD(1)), ..., ELIST(IORD(K)) with K = LAST\nC If LAST.LE.(LIMIT/2+2), and K = LIMIT+1-LAST\nC otherwise, form a decreasing sequence\nC\nC LAST - Integer\nC Number of subintervals actually produced in\nC the subdivision process\nC\nC***REFERENCES (NONE)\nC***ROUTINES CALLED D1MACH, DQC25C, DQPSRT\nC***REVISION HISTORY (YYMMDD)\nC 800101 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890831 Modified array declarations. (WRB)\nC 890831 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC***END PROLOGUE DQAWCE\nC\n DOUBLE PRECISION A,AA,ABSERR,ALIST,AREA,AREA1,AREA12,AREA2,A1,A2,\n 1 B,BB,BLIST,B1,B2,C,D1MACH,ELIST,EPMACH,EPSABS,EPSREL,\n 2 ERRBND,ERRMAX,ERROR1,ERRO12,ERROR2,ERRSUM,F,RESULT,RLIST,UFLOW\n INTEGER IER,IORD,IROFF1,IROFF2,K,KRULE,LAST,LIMIT,MAXERR,NEV,\n 1 NEVAL,NRMAX\nC\n DIMENSION ALIST(*),BLIST(*),RLIST(*),ELIST(*),\n 1 IORD(*)\nC\n EXTERNAL F\nC\nC LIST OF MAJOR VARIABLES\nC -----------------------\nC\nC ALIST - LIST OF LEFT END POINTS OF ALL SUBINTERVALS\nC CONSIDERED UP TO NOW\nC BLIST - LIST OF RIGHT END POINTS OF ALL SUBINTERVALS\nC CONSIDERED UP TO NOW\nC RLIST(I) - APPROXIMATION TO THE INTEGRAL OVER\nC (ALIST(I),BLIST(I))\nC ELIST(I) - ERROR ESTIMATE APPLYING TO RLIST(I)\nC MAXERR - POINTER TO THE INTERVAL WITH LARGEST\nC ERROR ESTIMATE\nC ERRMAX - ELIST(MAXERR)\nC AREA - SUM OF THE INTEGRALS OVER THE SUBINTERVALS\nC ERRSUM - SUM OF THE ERRORS OVER THE SUBINTERVALS\nC ERRBND - REQUESTED ACCURACY MAX(EPSABS,EPSREL*\nC ABS(RESULT))\nC *****1 - VARIABLE FOR THE LEFT SUBINTERVAL\nC *****2 - VARIABLE FOR THE RIGHT SUBINTERVAL\nC LAST - INDEX FOR SUBDIVISION\nC\nC\nC MACHINE DEPENDENT CONSTANTS\nC ---------------------------\nC\nC EPMACH IS THE LARGEST RELATIVE SPACING.\nC UFLOW IS THE SMALLEST POSITIVE MAGNITUDE.\nC\nC***FIRST EXECUTABLE STATEMENT DQAWCE\n EPMACH = D1MACH(4)\n UFLOW = D1MACH(1)\nC\nC\nC TEST ON VALIDITY OF PARAMETERS\nC ------------------------------\nC\n IER = 6\n NEVAL = 0\n LAST = 0\n ALIST(1) = A\n BLIST(1) = B\n RLIST(1) = 0.0D+00\n ELIST(1) = 0.0D+00\n IORD(1) = 0\n RESULT = 0.0D+00\n ABSERR = 0.0D+00\n IF (C.EQ.A.OR.C.EQ.B.OR.(EPSABS.LE.0.0D+00.AND.\n 1 EPSREL.LT.MAX(0.5D+02*EPMACH,0.5D-28))) GO TO 999\nC\nC FIRST APPROXIMATION TO THE INTEGRAL\nC -----------------------------------\nC\n AA=A\n BB=B\n IF (A.LE.B) GO TO 10\n AA=B\n BB=A\n10 IER=0\n KRULE = 1\n CALL DQC25C(F,AA,BB,C,RESULT,ABSERR,KRULE,NEVAL)\n LAST = 1\n RLIST(1) = RESULT\n ELIST(1) = ABSERR\n IORD(1) = 1\n ALIST(1) = A\n BLIST(1) = B\nC\nC TEST ON ACCURACY\nC\n ERRBND = MAX(EPSABS,EPSREL*ABS(RESULT))\n IF(LIMIT.EQ.1) IER = 1\n IF(ABSERR.LT.MIN(0.1D-01*ABS(RESULT),ERRBND)\n 1 .OR.IER.EQ.1) GO TO 70\nC\nC INITIALIZATION\nC --------------\nC\n ALIST(1) = AA\n BLIST(1) = BB\n RLIST(1) = RESULT\n ERRMAX = ABSERR\n MAXERR = 1\n AREA = RESULT\n ERRSUM = ABSERR\n NRMAX = 1\n IROFF1 = 0\n IROFF2 = 0\nC\nC MAIN DO-LOOP\nC ------------\nC\n DO 40 LAST = 2,LIMIT\nC\nC BISECT THE SUBINTERVAL WITH NRMAX-TH LARGEST\nC ERROR ESTIMATE.\nC\n A1 = ALIST(MAXERR)\n B1 = 0.5D+00*(ALIST(MAXERR)+BLIST(MAXERR))\n B2 = BLIST(MAXERR)\n IF(C.LE.B1.AND.C.GT.A1) B1 = 0.5D+00*(C+B2)\n IF(C.GT.B1.AND.C.LT.B2) B1 = 0.5D+00*(A1+C)\n A2 = B1\n KRULE = 2\n CALL DQC25C(F,A1,B1,C,AREA1,ERROR1,KRULE,NEV)\n NEVAL = NEVAL+NEV\n CALL DQC25C(F,A2,B2,C,AREA2,ERROR2,KRULE,NEV)\n NEVAL = NEVAL+NEV\nC\nC IMPROVE PREVIOUS APPROXIMATIONS TO INTEGRAL\nC AND ERROR AND TEST FOR ACCURACY.\nC\n AREA12 = AREA1+AREA2\n ERRO12 = ERROR1+ERROR2\n ERRSUM = ERRSUM+ERRO12-ERRMAX\n AREA = AREA+AREA12-RLIST(MAXERR)\n IF(ABS(RLIST(MAXERR)-AREA12).LT.0.1D-04*ABS(AREA12)\n 1 .AND.ERRO12.GE.0.99D+00*ERRMAX.AND.KRULE.EQ.0)\n 2 IROFF1 = IROFF1+1\n IF(LAST.GT.10.AND.ERRO12.GT.ERRMAX.AND.KRULE.EQ.0)\n 1 IROFF2 = IROFF2+1\n RLIST(MAXERR) = AREA1\n RLIST(LAST) = AREA2\n ERRBND = MAX(EPSABS,EPSREL*ABS(AREA))\n IF(ERRSUM.LE.ERRBND) GO TO 15\nC\nC TEST FOR ROUNDOFF ERROR AND EVENTUALLY SET ERROR FLAG.\nC\n IF(IROFF1.GE.6.AND.IROFF2.GT.20) IER = 2\nC\nC SET ERROR FLAG IN THE CASE THAT NUMBER OF INTERVAL\nC BISECTIONS EXCEEDS LIMIT.\nC\n IF(LAST.EQ.LIMIT) IER = 1\nC\nC SET ERROR FLAG IN THE CASE OF BAD INTEGRAND BEHAVIOUR\nC AT A POINT OF THE INTEGRATION RANGE.\nC\n IF(MAX(ABS(A1),ABS(B2)).LE.(0.1D+01+0.1D+03*EPMACH)\n 1 *(ABS(A2)+0.1D+04*UFLOW)) IER = 3\nC\nC APPEND THE NEWLY-CREATED INTERVALS TO THE LIST.\nC\n 15 IF(ERROR2.GT.ERROR1) GO TO 20\n ALIST(LAST) = A2\n BLIST(MAXERR) = B1\n BLIST(LAST) = B2\n ELIST(MAXERR) = ERROR1\n ELIST(LAST) = ERROR2\n GO TO 30\n 20 ALIST(MAXERR) = A2\n ALIST(LAST) = A1\n BLIST(LAST) = B1\n RLIST(MAXERR) = AREA2\n RLIST(LAST) = AREA1\n ELIST(MAXERR) = ERROR2\n ELIST(LAST) = ERROR1\nC\nC CALL SUBROUTINE DQPSRT TO MAINTAIN THE DESCENDING ORDERING\nC IN THE LIST OF ERROR ESTIMATES AND SELECT THE SUBINTERVAL\nC WITH NRMAX-TH LARGEST ERROR ESTIMATE (TO BE BISECTED NEXT).\nC\n 30 CALL DQPSRT(LIMIT,LAST,MAXERR,ERRMAX,ELIST,IORD,NRMAX)\nC ***JUMP OUT OF DO-LOOP\n IF(IER.NE.0.OR.ERRSUM.LE.ERRBND) GO TO 50\n 40 CONTINUE\nC\nC COMPUTE FINAL RESULT.\nC ---------------------\nC\n 50 RESULT = 0.0D+00\n DO 60 K=1,LAST\n RESULT = RESULT+RLIST(K)\n 60 CONTINUE\n ABSERR = ERRSUM\n 70 IF (AA.EQ.B) RESULT=-RESULT\n 999 RETURN\n END\n", "meta": {"hexsha": "20a8e138a54bf0f8a6213a1107e19d36318d068d", "size": 12644, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/dqawce.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-03-09T21:31:09.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-09T21:31:09.000Z", "max_issues_repo_path": "slatec/src/dqawce.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/dqawce.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.2979351032, "max_line_length": 72, "alphanum_fraction": 0.530370136, "num_tokens": 3603, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970904940926, "lm_q2_score": 0.7401743620390162, "lm_q1q2_score": 0.6519434245422866}} {"text": "*deck aratio_qud\n subroutine aratio_qud(xl1,yl1,zl1,\n * xl2,yl2,zl2,\n * xl3,yl3,zl3,\n * xl4,yl4,zl4,\n * aratqud)\nC\nC\nC #####################################################################\nC\nC PURPOSE -\nC\nC Finds the aspect ratio of a quad.\nC\nC INPUT ARGUMENTS -\nC\nC (x1,y1,z1),...,(x4,y4,z4) - The coordinates of the quad.\nC\nC OUTPUT ARGUMENTS -\nC\nC aratqud : The aspect ratio of the quad.\nC\nC CHANGE HISTORY -\nC\nC $Log: aratio_qud.f,v $\nC Revision 2.00 2007/11/05 19:45:46 spchu\nC Import to CVS\nC\nCPVCS \nCPVCS Rev 1.0 Fri Aug 29 14:11:36 1997 dcg\nCPVCS Initial revision.\nC\nC ######################################################################\nC\nC\n implicit none\nC\n include \"local_element.h\"\nC\n real*8 xl1,yl1,zl1,xl2,yl2,zl2,xl3,yl3,zl3,xl4,yl4,zl4\n real*8 aratqud\n real*8 xb,yb,zb,xc,yc,zc\n real*8 smdiag,lardiag,dist1,dist2\nC\nC ######################################################################\nC\nC\nC Calculation of \"dist\", the length of the\nC diagonals of the quad.\nC\n xb = xl1 - xl3\n yb = yl1 - yl3\n zb = zl1 - zl3\n xc = xl2 - xl4\n yc = yl2 - yl4\n zc = zl2 - zl4\n dist1 = sqrt ( xb*xb + yb*yb + zb*zb )\n dist2 = sqrt ( xc*xc + yc*yc + zc*zc )\n if (dist1 .lt. dist2) then\n smdiag = dist1\n lardiag = dist2\n else\n lardiag = dist1\n smdiag = dist2\n endif\n \n aratqud = smdiag/lardiag\n \n return\n end\n", "meta": {"hexsha": "036c715ded0b5231af1439d02743a7dc2fe954db", "size": 1600, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/aratio_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/aratio_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/aratio_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": 22.5352112676, "max_line_length": 72, "alphanum_fraction": 0.46, "num_tokens": 548, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970873650401, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6519434222262424}} {"text": "c Introduced by Ben Allanach to provide a wrapper to C class\n subroutine dilogwrap(a, b, c, d)\n \n implicit none\n \n double precision a, b, c, d\n complex*16 x, l, pCSPEN\n \n x = dcmplx(a, b)\n l = pCSPEN(x)\n \n c = dble(l)\n d = dimag(l)\n \n return\n end\n \nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC SPENCE-FUNKTION KOMPLEX, FREI NACH HOLLIK C\nC---------------------------------------------------------------------C\nC 20.07.83 LAST CHANGED 10.05.89 ANSGAR DENNER C\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n \n FUNCTION pCSPEN(ZZ)\n \n COMPLEX*16 pCSPEN,W,SUM,ZZ,Z,U\n DOUBLE PRECISION RZ,AZ,A1\n DOUBLE PRECISION B(9)\nC BEACHTE: B(N)=B2N\nC B(1)=1./6.\nC B(2)=-1./30.\nC B(3)=1./42.\nC B(4)=-1./30.\nC B(5)=5./66.\nC B(6)=-691./2730.\nC B(7)=7./6.\nC B(8)=-3617./510.\nC B(9)=43867./798.\nC PI=3.1415926535897932384\nC PI*PI/6.=1.6449..., PI*PI/3=3.28986...\n \n B(1)=0.1666666666666666666666666667d0\n B(2)=-0.0333333333333333333333333333d0\n B(3)=0.0238095238095238095238095238d0\n B(4)=-0.0333333333333333333333333333d0\n B(5)=0.0757575757575757575757575758d0\n B(6)=-0.2531135531135531135531135531d0\n B(7)=1.1666666666666666666666666667d0\n B(8)=-7.09215686274509804d0\n B(9)=54.97117794486215539d0\n \nc write(*,*) 'z:',z\n Z =ZZ*DCMPLX(1D0)\n RZ=DREAL(Z)\n AZ=CDABS(Z)\n A1=CDABS(1D0-Z)\nc write(*,*)'z, rz, az, a1:',z,rz,az,a1\nC IF((SNGL(RZ) .EQ. 0.0) .AND. (SNGL(DIMAG(Z)) .EQ. 0.0)) THEN\nC ---> CHANGED 10.5.89\n IF(AZ .LT. 1D-20) THEN\n pCSPEN=-CDLOG(1D0-Z)\nc write(*,*) 'cspen:', cspen\n RETURN\n END IF\n IF((SNGL(RZ) .EQ. 1.0) .AND. (SNGL(DIMAG(Z)) .EQ. 0.0)) THEN\n pCSPEN=1.64493406684822643D0\nc write(*,*) 'cspen:', cspen\n RETURN\n END IF\n IF(RZ.GT.5D-1) GOTO 20\n IF(AZ.GT.1D0) GOTO 10\n W=-CDLOG(1D0-Z)\n SUM=W-0.25D0*W*W\n U=W\n IF(CDABS(U).LT.1D-10) GOTO 2\nc write(*,*) 'u:',u\nc write(*,*) 'sum:',sum\n DO 1 K=1,9\n U=U*W*W/DFLOAT(2*K*(2*K+1))\n IF(CDABS(U*B(K)/SUM).LT.1D-20) GOTO 2\n SUM=SUM+U*B(K)\n 1 CONTINUE\n 2 pCSPEN=SUM\nc write(*,*) 'cspen:', cspen\n RETURN\n 10 W=-CDLOG(1D0-1D0/Z)\n SUM=W-0.25D0*W*W\n U=W\n IF(CDABS(U).LT.1D-10) GOTO 12\n \n DO 11 K=1,9\n U=U*W*W/DFLOAT(2*K*(2*K+1))\n IF(CDABS(B(K)*U/SUM).LT.1D-20) GOTO 12\n SUM=SUM+U*B(K)\n 11 CONTINUE\n 12 pCSPEN=-SUM-1.64493406684822643D0-.5D0*CDLOG(-Z)**2\nc write(*,*) 'cspen:', cspen\n RETURN\n 20 IF(A1.GT.1D0) GOTO 30\n W=-CDLOG(Z)\n SUM=W-0.25D0*W*W\n U=W\n IF(CDABS(U).LT.1D-10) GOTO 22\n DO 21 K=1,9\n U=U*W*W/DFLOAT(2*K*(2*K+1))\n IF(CDABS(U*B(K)/SUM).LT.1D-20) GOTO 22\n SUM=SUM+U*B(K)\n 21 CONTINUE\n 22 pCSPEN=-SUM+1.64493406684822643D0-CDLOG(Z)*CDLOG(1D0-Z)\nc write(*,*) 'cspen:', cspen\n RETURN\n 30 W=CDLOG(1D0-1D0/Z)\n SUM=W-0.25D0*W*W\n U=W\n IF(CDABS(U).LT.1D-10) GOTO 32\n DO 31 K=1,9\n U=U*W*W/DFLOAT(2*K*(2*K+1))\n IF(CDABS(U*B(K)/SUM).LT.1D-20) GOTO 32\n SUM=SUM+U*B(K)\n 31 CONTINUE\n 32 pCSPEN=SUM+3.28986813369645287D0\n * +.5D0*CDLOG(Z-1D0)**2-CDLOG(Z)*CDLOG(1D0-Z)\nc write(*,*) 'cspen:', cspen\n END\n \n", "meta": {"hexsha": "25088899432658d2fc34c99f9487a403805d101c", "size": 3540, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "contrib/MassSpectra/MSSM-SoftSUSY/softsusy-3.5.1/src/dilogwrap.f", "max_stars_repo_name": "aaronvincent/gambit_aaron", "max_stars_repo_head_hexsha": "a38bd6fc10d781e71f2adafd401c76e1e3476b05", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-09-08T20:05:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-26T07:57:56.000Z", "max_issues_repo_path": "contrib/MassSpectra/MSSM-SoftSUSY/softsusy-3.5.1/src/dilogwrap.f", "max_issues_repo_name": "aaronvincent/gambit_aaron", "max_issues_repo_head_hexsha": "a38bd6fc10d781e71f2adafd401c76e1e3476b05", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2020-10-19T09:56:17.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-28T06:12:03.000Z", "max_forks_repo_path": "contrib/MassSpectra/MSSM-SoftSUSY/softsusy-3.5.1/src/dilogwrap.f", "max_forks_repo_name": "aaronvincent/gambit_aaron", "max_forks_repo_head_hexsha": "a38bd6fc10d781e71f2adafd401c76e1e3476b05", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2020-09-08T02:23:34.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-23T08:48:04.000Z", "avg_line_length": 28.0952380952, "max_line_length": 71, "alphanum_fraction": 0.5242937853, "num_tokens": 1558, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970654616711, "lm_q2_score": 0.7401743735019595, "lm_q1q2_score": 0.6519434161104568}} {"text": " subroutine DSVALA ( K, N, T, NDERIV, BDIF, X, SVALUE)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc>> 1994-10-20 DSVALA Krogh Changes to use M77CON\nc>> 1993-01-12 DSVALA CLL Bringing basis computation inline.\nc>> 1992-11-12 C. L. Lawson, JPL Saving LEFTI.\nc>> 1992-11-02 C. L. Lawson, JPL\nc>> 1988-03-16 C. L. Lawson, JPL\nc\nc A spline function is defined by the contents of K, N, and T().\nc Given array BDIF(,) containing B-spline coefficients and\nc differences of these, this subroutine computes and stores into\nc SVALUE(1:NDERIV+1) the value and derivatives through order NDERIV\nc of the spline function evaluated at the abcissa, X.\nc Derivatives of order .ge. K will be zero.\nc\nc The subroutine, BSPLPP, given on pp. 140-141 of\nc A PRACTICAL GUIDE TO SPLINES by Carl De Boor, Springer-Verlag,\nc 1978, has been recoded as separate subroutines: DSTOT (or DSTOP)\nc calling DSDIF and DSVALA. This subroutine has the functionality\nc of lines 72-103 of BSPLPP in the book.\nc ------------------------------------------------------------------\nc--D replaces \"?\": ?SVALA, ?SFIND\nc Both versions use IERM1, IERV1\nc ------------------------------------------------------------------\n integer KMAX\n parameter(KMAX=20)\n integer I, ID, J, JP1, K, KP1MN, L, LEFT, LEFTI, LEFTPL\n integer MODE, N, NDER, NDERIV\n double precision BDIF(N,NDERIV+1), DELTAL(KMAX), DELTAR(KMAX)\n double precision ONE, SAVED, SVALUE(NDERIV+1)\n double precision T(N+K), TERM, VNIKX(KMAX), X, ZERO\n parameter(ONE = 1.0d0, ZERO = 0.0d0)\n save LEFTI\n data LEFTI / 1/\nc ------------------------------------------------------------------\n if(K .gt. KMAX) then\n call IERM1('DSVALA',1,2,'Require KORDER .le. KMAX.',\n * 'KORDER',K,',')\n call IERV1('KMAX',KMAX,'.')\n return\n endif\n do 5 I=1,NDERIV+1\n SVALUE(I) = ZERO\n 5 continue\n call DSFIND(T, K, N+1, X, LEFTI, MODE)\nC\nc LEFTI has been found so that [T(LEFTI), T(LEFTI+1)] is the\nc reference interval for the polynomial piece to be used in\nc evaluating at X.\nc\n NDER = min(NDERIV, K-1)\n KP1MN = K-NDER\nc\nc Compute values of KP1MN basis functions of order KP1MN at X.\nc Store these in VNIKX(1:KP1MN). Here KP1MN .ge. 1.\nc\n VNIKX(1) = ONE\n do 27 J = 1, KP1MN-1\n JP1 = J + 1\n DELTAR(J) = T(LEFTI+J) - X\n DELTAL(J) = X - T(LEFTI+1-J)\n SAVED = ZERO\n do 26 I=1,J\n TERM = VNIKX(I)/(DELTAR(I) + DELTAL(JP1-I))\n VNIKX(I) = SAVED + DELTAR(I)*TERM\n SAVED = DELTAL(JP1-I)*TERM\n 26 continue\n VNIKX(JP1) = SAVED\n 27 continue\nc\nc Loop on ID. For each value of ID, evaluate the derivative of\nc order ID-1 at X, and store it in SVALUE(ID).\nc Then, if ID > 1, update basis function values\nc in VNIKX() to the next higher order. (From order J to JP1).\nc\n do 55 ID = NDER+1, 1, -1\n LEFT = LEFTI - KP1MN\n do 52 L=1,KP1MN\n LEFTPL = LEFT+L\n SVALUE(ID) = VNIKX(L)*BDIF(LEFTPL,ID) + SVALUE(ID)\n 52 continue\n if (ID .gt. 1) then\n J = KP1MN\n JP1 = J + 1\n DELTAR(J) = T(LEFTI+J) - X\n DELTAL(J) = X - T(LEFTI+1-J)\n SAVED = ZERO\n do 54 I=1,J\n TERM = VNIKX(I)/(DELTAR(I) + DELTAL(JP1-I))\n VNIKX(I) = SAVED + DELTAR(I)*TERM\n SAVED = DELTAL(JP1-I)*TERM\n 54 continue\n VNIKX(JP1) = SAVED\n endif\n KP1MN = KP1MN+1\n 55 continue\n return\n end\n", "meta": {"hexsha": "b3f85d8d795aab23bc6c45388973e58a905e5f35", "size": 3767, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/dsvala.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/dsvala.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/dsvala.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": 37.297029703, "max_line_length": 72, "alphanum_fraction": 0.5550836209, "num_tokens": 1260, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.651943415694283}} {"text": " \n! A collection of functions to compute various moist thermodynamic quantities\n\n! Rodrigo Caballero Augi 2000, 2005\n\n! References: Bolton (1980), Mon. Wea. Rev. 108, 1046-1053 \n! Bohren and Albrecht (1998), \"Atmospheric Thermodynamics\"\n! Flatau et al (1992), J. App. Met . 31, 1507-1513.\n\n!------------------------------------------------------------------------\nsubroutine tdew(km,jm,im,p,q,t)\n\n! compute dew point temperature tdew [K] \n! at pressure p [mb] and specific humidity q [g/kg]\n! Use Bolton eqn (11)\n!\n implicit none\n integer,intent(in) :: km,jm,im\n!f2py intent(hide) km,jm,im\n real(8), dimension(km,jm,im), intent(in) :: p,q\n real(8), dimension(km,jm,im), intent(out) :: t\n\n! Local\n real(8) :: Rv, Rd, eps\n real(8), dimension(km,jm,im) :: r,es,loges\n\n Rv = 461.5\n Rd = 287.04\n eps = Rd/Rv\n r = q/(1.e3 - q) * 1.e3 ! water vap. mixing ratio [g/kg]\n es = p*r/(r+eps*1.e3) ! vapor pressure of water vap\n loges = log(es)\n\n t = ( 243.5*loges-440.8 )/( 19.48-loges ) + 273.15\n\nend subroutine tdew\n!------------------------------------------------------------------------\nsubroutine tstar(km,jm,im,T,p,q,Ts)\n\n! compute saturation point temperature Ts [K] \n! (i.e. temperature at lifting condensation level) \n! given temperature T [K], pressure p [mb], specific humidity q [g/kg].\n! Use Bolton eqn (12)\n\n implicit none\n integer,intent(in) :: km,jm,im\n!f2py intent(hide) km,jm,im\n real(8), dimension(km,jm,im), intent(in) :: T,p,q\n real(8), dimension(km,jm,im), intent(out) :: Ts\n\n! Local\n real(8) :: Rv, Rd, eps, oneoverk\n real(8), dimension(km,jm,im) :: r,th,c,e\n\n Rv = 461.5\n Rd = 287.04\n eps = Rd/Rv\n oneoverk = 3.504 ! Cp/Rd\n r = q/(1.e3 - q) ! water vap. mixing ratio [kg/kg]\n\n! call theta(km,jm,im,t,p,q,th)\n! c=log( r/(r+eps*1.e3)/t**oneoverk / 1.7743e-8 )\n! ts=217.8*c/(12.992-c) + 273.15\n e = p*r/(r+eps)\n Ts = 2840./( 3.5*log(t) - log(e) - 4.805) + 55. \n\nend subroutine tstar\n!------------------------------------------------------------------------\nsubroutine theta(km,jm,im, Rd, Rv, cpd, cpv, p0, p, T, q, th)\n\n! compute potential temperature theta [K]\n! given temperature t [K], pressure p [mb], specific humidity q [g/kg].\n \n implicit none\n integer,intent(in) :: km,jm,im\n!f2py intent(hide) km,jm,im\n real(8), intent(in) :: p0,Rd,Rv,cpd,cpv\n real(8), dimension(km,jm,im), intent(in) :: T,p,q\n real(8), dimension(km,jm,im), intent(out) :: th\n\n! Local\n real(8) :: eps\n real(8), dimension(km,jm,im) :: cp,R,kappa\n\n eps = Rd/Rv\n R = Rd * (1.+ (1.-eps)/eps*q*1.e-3)\n cp = cpd * (1. + (cpv/cpd-1.)*q*1.e-3)\n kappa = R/cp \n\n th = T*(p0/p)**kappa\n \nend subroutine theta\n!------------------------------------------------------------------------\nsubroutine theta_old(km,jm,im,t,p,q,th)\n\n! compute potential temperature theta [K]\n! given temperature t [K], pressure p [mb], specific humidity q [g/kg].\n! Use Bolton eqn (7) \n \n implicit none\n integer,intent(in) :: km,jm,im\n!f2py intent(hide) km,jm,im\n real(8), dimension(km,jm,im), intent(in) :: t,p,q\n real(8), dimension(km,jm,im), intent(out) :: th\n\n! Local\n real(8) :: ak\n real(8), dimension(km,jm,im) :: r\n\n ak=0.2854 ! R_(dry air)/Cp\n r = q/(1.e3 - q) * 1.e3 ! water vap. mixing ratio [g/kg]\n\n th = t*(1000./p)**( ak*(1.-0.28e-3*r) )\n \nend subroutine theta_old\n!------------------------------------------------------------------------\nsubroutine thetae(km,jm,im,Rd,Rv,lv0,cpd,cpv,cl,p0,p,T,wt,the)\n\n! compute equivalent potential temperature the [K]\n! given temperature t [K], pressure p [mb], \n! total water mixing ratio [g/kg].\n! Use Bohren+Albrecht (6.119) and (6.122), p.293\n\n implicit none\n integer, intent(in) :: km,jm,im\n!f2py intent(hide) km,jm,im\n real(8), intent(in) :: p0,Rd,Rv,lv0,cpv,cpd,cl\n real(8), dimension(km,jm,im), intent(in) :: p,T,wt\n real(8), dimension(km,jm,im), intent(out) :: the\n\n! Local\n integer :: k,j,i\n real(8), dimension(km,jm,im) :: esat,wsat,lv,cp,T1,p1,wt1\n real(8) :: eps,q,Tst,pst\n\n eps = Rd/Rv\n\n T1 = T\n p1 = p\n wt1 = wt\n call ws(km,jm,im,Rd,Rv,T,p,wsat)\n do i=1,im\n do j=1,jm\n do k=1,km \n ! if wt was not specified, set it to wsat\n if (wt(k,j,i) < 0.) then\n wt1(k,j,i) = wsat(k,j,i)\n ! if parcel unsaturated, bring to LCL\n else if (wt(k,j,i) < wsat(k,j,i)) then\n q = wt(k,j,i)/(1.+wt(k,j,i)*1.e-3) \n call tstar(1,1,1,T(k,j,i),p(k,j,i),q,Tst) ! gives T at LCL\n pst = p(k,j,i)*(Tst/T(k,j,i))**(cpd/Rd) ! gives p at LCL\n T1(k,j,i) = Tst\n p1(k,j,i) = pst\n endif\n enddo\n enddo\n enddo\n call es(km,jm,im,T1,esat)\n call ws(km,jm,im,Rd,Rv,T1,p1,wsat)\n lv = lv0 + (cpv-cl)*(T1-273.15) \n cp = cpd+wt1*1.e-3*cl\n the = T1*((p1-esat)/p0)**(-Rd/cp)*exp(lv*wsat*1.e-3/cp/T1)\n \nend subroutine thetae\n!------------------------------------------------------------------------\nsubroutine thetaes(km,jm,im,Rd,Rv,lv0,cpd,cpv,cl,p0,p,T,thes)\n\n! compute saturation equivalent potential temperature thes [K]\n! given temperature T [K] and pressure p [mb]\n! Use Bohren+Albrecht (6.123), p.293\n\n implicit none\n integer, intent(in) :: km,jm,im\n!f2py intent(hide) km,jm,im\n real(8), intent(in) :: p0,Rd,Rv,lv0,cpv,cpd,cl\n real(8), dimension(km,jm,im), intent(in) :: p,T\n real(8), dimension(km,jm,im), intent(out) :: thes\n\n! Local\n integer :: k,j,i\n real(8), dimension(km,jm,im) :: esat,wsat,lv,cp\n real(8) :: eps,q,Tst,pst\n\n eps = Rd/Rv\n\n call es(km,jm,im,T,esat)\n call ws(km,jm,im,Rd,Rv,T,p,wsat)\n wsat = wsat * 1.e-3 ! g/kg -> kg/kg\n lv = lv0 + (cpv-cl)*(T-273.15) \n cp = cpd + wsat*cl\n thes = T*((p-esat)/p0)**(-Rd/cp)*exp(lv*wsat/cp/T)\n \nend subroutine thetaes\n!------------------------------------------------------------------------\nsubroutine thetae_old(km,jm,im,t,p,q,the)\n\n! compute equivalent potential temperature thetae [K]\n! given temperature t [K], pressure p [mb], specific humidity q [g/kg].\n! Use Bolton eqn (38)\n\n implicit none\n integer,intent(in) :: km,jm,im\n!f2py intent(hide) km,jm,im\n real(8), dimension(km,jm,im), intent(in) :: t,p,q\n real(8), dimension(km,jm,im), intent(out) :: the\n\n! Local\n real(8), dimension(km,jm,im) :: r,th,ts\n\n call theta(km,jm,im,t,p,q,th)\n call tstar(km,jm,im,t,p,q,ts)\n r = q/(1.e3 - q) * 1.e3 ! water vap. mixing ratio [g/kg]\n\n the = th * exp( (3.376/ts-0.00254)*r*(1.+0.81e-3*r) )\n\nend subroutine thetae_old\n!------------------------------------------------------------------------\nsubroutine es(km,jm,im,T,e)\n\n! Compute saturation partial pressure of water vapor es [mb]\n! at temperature T [K].\n! Use Bohren+Albrecht p. 198\n \n implicit none\n integer,intent(in) :: km,jm,im\n!f2py intent(hide) km,jm,im\n real(8), dimension(km,jm,im), intent(in) :: T\n real(8), dimension(km,jm,im), intent(out) :: e\n\n! Local\n real(8) :: T0\n\n T0 = 273.15\n e = 6.11 * exp( 6808.*(1./T0 - 1./T) - 5.09*log(T/T0) )\n\nend subroutine es\n!------------------------------------------------------------------------\nsubroutine esflatau(km,jm,im,T,i,e)\n\n! Compute saturation partial pressure of water vapor es [mb]\n! at temperature T [K].\n! Use 8th oRder polynomial fit of Flatau et al (1992), Table 4\n\n! i=1 => vapour pressure over water (valid -85C < t < 70C)\n! i=2 => vapour pressure over ice (valid -90C < t < 0C)\n \n implicit none\n integer,intent(in) :: km,jm,im,i\n!f2py intent(hide) km,jm,im\n real(8), dimension(km,jm,im), intent(in) :: T\n real(8), dimension(km,jm,im), intent(out) :: e\n\n! Local\n integer :: n\n real(8) :: t0\n real(8), dimension(9,2) :: a\n\n data a / 6.11239921, 0.443987641, 0.142986287e-1, 0.264847430e-3, &\n 0.302950461e-5, 0.206739458e-7, 0.640689451e-10,-0.952447341e-13, &\n -0.976195544e-15, &\n 6.11147274, 0.503160820, 0.188439774e-1, 0.420895665e-3, &\n 0.615021634e-5, 0.602588177e-7, 0.385852041e-9, 0.146898966e-11, &\n 0.252751365e-14 /\n\n t0=273.15\n\n e = a(9,i)\n do n=8,1,-1\n e = e*(t-t0) + a(n,i)\n enddo\n\nend subroutine esflatau\n!------------------------------------------------------------------------\nsubroutine qs(km,jm,im,Rd,Rv,T,p,q)\n\n! Compute saturation specific humidity qs [g/kg]\n! given temperature T [K] and total (air+vapor) pressure p [mb]\n! use Bohren+Albrecht p. 186\n \n implicit none\n integer,intent(in) :: km,jm,im\n!f2py intent(hide) km,jm,im\n real(8), intent(in) :: Rd,Rv\n real(8), dimension(km,jm,im), intent(in) :: T,p\n real(8), dimension(km,jm,im), intent(out) :: q\n\n! Local\n real(8) :: eps\n real(8), dimension(km,jm,im) :: e\n\n eps=Rd/Rv\n call es(km,jm,im,T,e)\n q = eps*e/(p+e*(eps-1.)) * 1.e3\n\nend subroutine qs\n!------------------------------------------------------------------------\nsubroutine qsflatau(km,jm,im,Rd,Rv,T,p,i,q)\n\n! Compute saturation specific humidity qs [g/kg]\n! given temperature T [K] and total (air+vapor) pressure p [mb]\n! Use 8th oRder polynomial fit of Flatau et al (1992), Table 4\n\n! i=1 => sat. mix. rat. over water (valid -85C < t < 70C)\n! i=2 => sat. mix. rat. over ice (valid -90C < t < 0C)\n\n implicit none\n integer,intent(in) :: km,jm,im,i\n!f2py intent(hide) km,jm,im\n real(8), intent(in) :: Rd,Rv\n real(8), dimension(km,jm,im), intent(in) :: T,p\n real(8), dimension(km,jm,im), intent(out) :: q\n\n! Local\n real(8) :: eps\n real(8), dimension(km,jm,im) :: e\n\n eps=Rd/Rv\n call esflatau(km,jm,im,T,i,e)\n q = eps*e/(p+e*(eps-1.)) * 1.e3\n! q = eps*e/p * 1.e3\n \nend subroutine qsflatau\n!------------------------------------------------------------------------\nsubroutine ws(km,jm,im,Rd,Rv,T,p,w)\n\n! Compute saturation water vapor mass mixing ratio ws [g/kg]\n! given temperature T [K] and total (air+vapor) pressure p [mb]\n! use Bohren+Albrecht p. 186\n \n implicit none\n integer,intent(in) :: km,jm,im\n!f2py intent(hide) km,jm,im\n real(8), intent(in) :: Rd,Rv\n real(8), dimension(km,jm,im), intent(in) :: T,p\n real(8), dimension(km,jm,im), intent(out) :: w\n\n! Local\n real(8) :: eps\n real(8), dimension(km,jm,im) :: e\n\n eps=Rd/Rv\n call es(km,jm,im,T,e)\n w = eps*e/(p-e) * 1.e3\n\nend subroutine ws\n!------------------------------------------------------------------------\nsubroutine wsflatau(km,jm,im,Rd,Rv,T,p,i,w)\n\n! Compute saturation water vapor mass mixing ratio ws [g/kg]\n! given temperature T [K] and total (air+vapor) pressure p [mb]\n! Use 8th oRder polynomial fit of Flatau et al (1992), Table 4\n\n! i=1 => sat. mix. rat. over water (valid -85C < t < 70C)\n! i=2 => sat. mix. rat. over ice (valid -90C < t < 0C)\n\n implicit none\n integer,intent(in) :: km,jm,im,i\n!f2py intent(hide) km,jm,im\n real(8), intent(in) :: Rd,Rv\n real(8), dimension(km,jm,im), intent(in) :: T,p\n real(8), dimension(km,jm,im), intent(out) :: w\n\n! Local\n real(8) :: eps\n real(8), dimension(km,jm,im) :: e\n\n eps=Rd/Rv\n call esflatau(km,jm,im,t,i,e)\n w = eps*e/(p-e) * 1.e3\n\nend subroutine wsflatau\n!------------------------------------------------------------------------\nsubroutine pdryadiab(km,jm,im,t,theta,q,p)\n\n! compute pressure level pdryadiab [mb] at which temperature is t [K]\n! on the dry (i.e. unsaturated) adiabat identified by \n! potential temperature theta [K] and mixing ratio q [g/kg].\n! Use Bolton eqn (7) \n\n implicit none\n integer,intent(in) :: km,jm,im\n!f2py intent(hide) km,jm,im\n real(8), dimension(km,jm,im), intent(in) :: t,theta,q\n real(8), dimension(km,jm,im), intent(out) :: p\n\n! Local\n real(8) :: oneoverk\n real(8), dimension(km,jm,im) :: r\n\n oneoverk=3.504 ! Cp/R_(dry air)\n r = q/(1.e3 - q) * 1.e3 ! water vap. mixing ratio [g/kg]\n\n p = 1000.*(t/theta)**( oneoverk/(1.-0.28e-3*r) )\n\nend subroutine pdryadiab\n!------------------------------------------------------------------------\nsubroutine tdryadiab(km,jm,im,theta,p,q,T)\n\n! Compute temperature T [K] at level p [mb] \n! on the dry (i.e. unsaturated) adiabat identified by \n! potential temperature theta [K] and mixing ratio q [g/kg].\n! Use Bolton eqn (7) \n\n implicit none\n integer,intent(in) :: km,jm,im\n!f2py intent(hide) km,jm,im\n real(8), dimension(km,jm,im), intent(in) :: theta,p,q\n real(8), dimension(km,jm,im), intent(out) :: T\n\n! Local\n real(8) :: ak\n real(8), dimension(km,jm,im) :: r\n\n ak=0.2854 ! R_(dry air)/Cp\n r = q/(1.e3 - q) * 1.e3 ! water vap. mixing ratio [g/kg]\n\n T = theta*(1000./p)**( -ak*(1.-0.28e-3*r) )\n \nend subroutine tdryadiab\n!------------------------------------------------------------------------\nsubroutine tmoistadiab(km,jm,im,thetaes,p,t)\n\n! Compute temperature [K] at level p [mb] \n! on the moist (i.e. saturated) pseudo-adiabat identified \n! by saturation equivalent potential temperature thetaes [K].\n! Do it by varying t until \n! delthetae := thetaes - thetae(t,p,qs(t,p)) = 0\n! Use Bolton, eqn (43)\n\n implicit none\n integer,intent(in) :: km,jm,im\n!f2py intent(hide) km,jm,im\n real(8), intent(in) :: thetaes\n real(8), dimension(km,jm,im), intent(in) :: p\n real(8), dimension(km,jm,im), intent(out) :: t\n\n! Local\n integer :: i,j,k\n real(8) :: tmin,tmax,f1,f2,delthetae,ridder\n real(8), dimension(10) :: params\n external delthetae,ridder\n logical success\n\ndo i=1,im\n do j=1,jm\n do k=1,km\n params = 0.\n params(1) = thetaes\n params(2) = p(k,j,i)\n ! bracket zero crossing to within 2K\n tmin = 50.\n tmax = 51.\n f1 = delthetae(params,tmin)\n f2 = delthetae(params,tmax)\n1 continue\n if(tmax.gt.500.) goto 2\n if(f1*f2.lt.0.) goto 3\n tmax = tmax+1.\n f2 = delthetae(params,tmax)\n goto 1\n2 stop 'tmoistadiab(): cannot bracket root'\n3 continue\n tmin = tmax-2.\n ! refine estimate using Ridder's method \n t(k,j,i) = ridder(success,delthetae, params, tmin, tmax, 0.0001)\n if (.not.success) stop 'tmoistadiab(): root not bracketed'\n enddo\n enddo\nenddo\n\nend subroutine tmoistadiab\n!-----------------------------------------------------------------------\nreal(8) function delthetae(params,t)\n\n implicit none\n real(8) :: p,t,q,thetaes,the\n real(8), dimension(10) :: params\n external qs,thetae\n\n thetaes = params(1)\n p = params(2)\n call qs(1,1,1,t,p,q)\n call thetae_old(1,1,1,t,p,q,the)\n delthetae = thetaes - the\n\nend function delthetae\n!------------------------------------------------------------------------\nreal(8) function ridder(success,func,params,xmin,xmax,acc)\n\n! Find zero crossing of func(x) in range xmin < x < xmax with accuracy acc\n! Use Ridder's method (Numerical Recipes)\n\n implicit real*8 (a-h,o-z)\n real*8 params(10),xmin,xmax,acc\n logical success\n external func\n\n maxit=60 ! max number of iterations\n success=.true.\n\n fl=func(params,xmin)\n fh=func(params,xmax)\n\n if((fl.gt.0..and.fh.lt.0.).or.(fl.lt.0..and.fh.gt.0.))then\n xl=xmin\n xh=xmax\n ridder=-1.11e30\n do j=1,maxit\n xm=0.5*(xl+xh)\n fm=func(params,xm)\n s=sqrt(fm**2-fl*fh)\n if(s.eq.0.)return\n xnew=xm+(xm-xl)*(sign(1.,real(fl-fh))*fm/s)\n if (abs(xnew-ridder).le.acc) return\n ridder=xnew\n fnew=func(params,ridder)\n if (fnew.eq.0.) return\n if(sign(fm,fnew).ne.fm) then\n xl=xm\n fl=fm\n xh=ridder\n fh=fnew\n else if(sign(fl,fnew).ne.fl) then\n xh=ridder\n fh=fnew\n else if(sign(fh,fnew).ne.fh) then\n xl=ridder\n fl=fnew\n else\n stop 'never get here in ridder'\n endif\n if(abs(xh-xl).le.acc) return\n enddo\n stop 'ridder exceed maximum iterations maxit'\n else if (fl.eq.0.) then\n ridder=xmin\n else if (fh.eq.0.) then\n ridder=xmax\n else\n success=.false.\n endif\n \nend function ridder\n\n\n!------------------------------------------------------------------------\nsubroutine z(km,jm,im,R,g,p0,p,t,zz)\n\n!\n implicit none\n integer, intent(in) :: km,jm,im\n!f2py intent(hide) km,jm,im\n real(8), intent(in) :: R,g\n real(8), dimension(jm,im), intent(in) :: p0\n real(8), dimension(km,jm,im), intent(in) :: p,t\n real(8), dimension(km,jm,im), intent(out) :: zz\n\n! Local\n integer :: k\n real(8), dimension(jm,im) :: dp,pm,Tm\n\n! bottom level\n dp = (p0 - p(km,:,:))\n pm = (p0 + p(km,:,:))/2.\n zz(km,:,:) = R/g * T(km,:,:)/pm * dp\n\n! build up from bottom\n do k=km-1,1,-1\n dp = p(k+1,:,:) - p(k,:,:)\n pm = (p(k+1,:,:) + p(k,:,:))/2.\n Tm = (T(k+1,:,:) + T(k,:,:))/2.\n zz(k,:,:) = zz(k+1,:,:) + R/g * Tm/pm * dp\n enddo\n\nend subroutine z\n!------------------------------------------------------------------------\nsubroutine pseudoadiab(km,jm,im,Rd,Rv,lv0,cpd,cpv,cl,p_in0,p00,T00,T_out)\n\n implicit none\n integer, parameter :: N=10000\n integer, intent(in) :: km,jm,im\n!f2py intent(hide) km,jm,im\n real(8), intent(in) :: Rd,Rv,lv0,cpv,cpd,cl\n real(8), dimension(jm,im), intent(in) :: p00,T00\n real(8), dimension(km,jm,im), intent(in) :: p_in0\n real(8), dimension(km,jm,im), intent(out) :: T_out\n\n! Local\n integer :: k,j,i,kmin\n real(8) :: eps,dp,e,w,R,lv,cp,T,p,pmax,pmin,delta\n real(8), dimension(jm,im) :: p0,T0\n real(8), dimension(km,jm,im) :: p_in\n\n eps = Rd/Rv\n p0 = log(p00*100.)\n T0 = log(T00)\n p_in = log(p_in0*100.)\n\n do i=1,im\n do j=1,jm\n pmax = max( p0(j,i), p_in(km,j,i) )\n pmin = min( p0(j,i), p_in(1,j,i) )\n dp = (pmax-pmin)/(N-1.)\n\n !--- up to top\n T = T0(j,i)\n p = p0(j,i)\n ! check if we're matching any of the required levels\n kmin = minloc(abs(p-p_in(:,j,i)),1)\n delta = abs(p-p_in(kmin,j,i))\n if (delta.le.dp) T_out(kmin,j,i) = T\n do k=1,N\n ! see if we've gone off the top\n p = p - dp\n if (p.lt.pmin) exit\n ! compute new T\n call es(1,1,1,exp(T),e)\n w = eps*e/(exp(p)/100.-e)\n cp = cpd+w*cl\n R = Rd*(1.+(1.-eps)/eps*w/(w+1.))\n lv = lv0 + (cpv-cl)*(exp(T)-273.15)\n T = T - Rd/cp* &\n (1.+lv*w/R/exp(T))/(1.+lv*lv*w/cp/Rv/exp(T)/exp(T)) * dp\n ! check if we're matching any of the required levels\n kmin = minloc(abs(p-p_in(:,j,i)),1)\n delta = abs(p-p_in(kmin,j,i))\n if (delta.le.dp) T_out(kmin,j,i) = T\n enddo\n\n ! down to bottom\n T = T0(j,i)\n p = p0(j,i)\n do k=1,N\n ! see if we've gone off the bottom\n p = p + dp\n if (p.gt.pmax) exit\n ! compute new value of T\n call es(1,1,1,exp(T),e)\n w = eps*e/(exp(p)/100.-e)\n cp = cpd+w*cl\n R = Rd*(1.+(1.-eps)/eps*w/(w+1.))\n lv = lv0 + (cpv-cl)*(exp(T)-273.15)\n T = T + Rd/cp* &\n (1.+lv*w/R/exp(T))/(1.+lv*lv*w/cp/Rv/exp(T)/exp(T)) * dp\n ! check if we're matching any of the required levels\n kmin = minloc(abs(p-p_in(:,j,i)),1)\n delta = abs(p-p_in(kmin,j,i))\n if (delta.le.dp) T_out(kmin,j,i) = T\n enddo\n\n enddo\n enddo\n\n T_out = exp(T_out)\n\nend subroutine pseudoadiab\n!------------------------------------------------------------------------\nsubroutine cape(km,jm,im,Rd,Rv,lv0,cpd,cpv,cl,virtual,ml_depth,p_in, T_in, q_in, c)\n\n implicit none\n integer, intent(in) :: km,jm,im\n!f2py intent(hide) km,jm,im\n integer, intent(in) :: virtual\n real(8), intent(in) :: ml_depth\n real(8), intent(in) :: Rd,Rv,lv0,cpv,cpd,cl\n real(8), dimension(km,jm,im), intent(in) :: p_in, T_in, q_in\n real(8), dimension(jm,im), intent(out) :: c\n\n! Local\n integer :: k,j,i\n real(8) :: eps,delT\n real(8), dimension(km,jm,im) :: q,qp, Tp, Tvp, Tvs\n real(8), dimension(jm,im) :: T0,q0, pst,Tst\n real(8), dimension(0:km) :: pint\n real(8), dimension(km) :: dp, dlnp\n\n eps = Rd/Rv\n q = max(q_in,q_in*0.) ! take out any negs in q\n\n! get saturation point temp and press Tst, pst for mean parcel in mixed layer\n call mean_parcel(km,jm,im,Rd,cpd,ml_depth,p_in,T_in,q,T0,q0,Tst,pst)\n\n! get the temperature profile of the corresponding moist adiabat \n call pseudoadiab(km,jm,im,Rd,Rv,lv0,cpd,cpv,cl,p_in,pst,Tst,Tp)\n\n! get the temperature profile of the corresponding dry adiabat \n do k=1,km\n Tp(k,:,:) = max( Tp(k,:,:), Tst*(p_in(k,:,:)/pst)**(Rd/cpd) )\n end do\n\n! apply virtual temp correction if required\n if (virtual > 0) then\n Tvs = T_in*(1.+ (1.-eps)/eps*q*1.e-3)\n call qs(km,jm,im,Rd,Rv,Tp,p_in,qp)\n do k=1,km\n qp(k,:,:) = min( qp(k,:,:), q0)\n end do\n Tvp = Tp*(1.+ (1.-eps)/eps*qp*1.e-3)\n endif \n\n! integrate to get CAPE\n c = 0.\n do i=1,im\n do j=1,jm\n pint(1:km-1) = (p_in(2:km,j,i)+p_in(1:km-1,j,i))/2.\n pint(0) = 0.\n pint(km) = p_in(km,j,i)+(p_in(km,j,i)-p_in(km-1,j,i))/2.\n dp = pint(1:km)-pint(0:km-1)\n dlnp = dp/p_in(:,j,i)\n do k=1,km\n if (virtual == 0) then \n delT = Tp(k,j,i)-T_in(k,j,i)\n else\n delT = Tvp(k,j,i)-Tvs(k,j,i) \n endif\n if ( delT > 0. ) then\n c(j,i) = c(j,i) + Rd*delT*dlnp(k)\n endif\n enddo\n enddo\n enddo\n\nend subroutine cape\n!------------------------------------------------------------------------\nsubroutine cine(km,jm,im,Rd,Rv,lv0,cpd,cpv,cl,virtual,ml_depth,p_in, T_in, q_in, c)\n\n implicit none\n integer, intent(in) :: km,jm,im\n!f2py intent(hide) km,jm,im\n integer, intent(in) :: virtual\n real(8), intent(in) :: ml_depth\n real(8), intent(in) :: Rd,Rv,lv0,cpv,cpd,cl\n real(8), dimension(km,jm,im), intent(in) :: p_in, T_in, q_in\n real(8), dimension(jm,im), intent(out) :: c\n\n! Local\n integer :: k,j,i\n real(8) :: eps,delT\n real(8), dimension(km,jm,im) :: q,qp, Tp, Tvp, Tvs\n real(8), dimension(jm,im) :: T0,q0, pst,Tst\n real(8), dimension(0:km) :: pint\n real(8), dimension(km) :: dp, dlnp\n\n eps = Rd/Rv\n q = max(q_in,q_in*0.) ! take out any negs in q\n\n! get saturation point temp and press Tst, pst for mean parcel in mixed layer\n call mean_parcel(km,jm,im,Rd,cpd,ml_depth,p_in,T_in,q,T0,q0,Tst,pst)\n\n! get the temperature profile of the corresponding moist adiabat \n call pseudoadiab(km,jm,im,Rd,Rv,lv0,cpd,cpv,cl,p_in,pst,Tst,Tp)\n\n! get the temperature profile of the corresponding dry adiabat \n do k=1,km\n Tp(k,:,:) = max( Tp(k,:,:), Tst*(p_in(k,:,:)/pst)**(Rd/cpd) )\n end do\n\n! apply virtual temp correction if required\n if (virtual > 0) then\n Tvs = T_in*(1.+ (1.-eps)/eps*q*1.e-3)\n call qs(km,jm,im,Rd,Rv,Tp,p_in,qp)\n do k=1,km\n qp(k,:,:) = min( qp(k,:,:), q0)\n end do\n Tvp = Tp*(1.+ (1.-eps)/eps*qp*1.e-3)\n endif \n\n ! integrate to get CINE\n c = 0.\n do i=1,im\n do j=1,jm\n pint(1:km-1) = (p_in(2:km,j,i)+p_in(1:km-1,j,i))/2.\n pint(0) = 0.\n pint(km) = p_in(km,j,i)+(p_in(km,j,i)-p_in(km-1,j,i))/2.\n dp = pint(1:km)-pint(0:km-1)\n dlnp = dp/p_in(:,j,i)\n inner_loop: do k=km,1,-1\n if (virtual == 0) then \n delT = Tp(k,j,i)-T_in(k,j,i)\n else\n delT = Tvp(k,j,i)-Tvs(k,j,i) \n endif\n if ( delT < 0. ) then \n c(j,i) = c(j,i) + Rd*delT*dlnp(k)\n else\n exit inner_loop\n endif\n enddo inner_loop\n enddo\n enddo\n \n c = -c\n\nend subroutine cine\n!------------------------------------------------------------------------\nsubroutine mean_parcel(km,jm,im,Rd,cpd,ml_depth,p,T,q,T0,q0,Tst,pst)\n\n! compute mean thermodyn properties over layer of depth ml_depth above ground\n\n implicit none\n integer, intent(in) :: km,jm,im\n real(8), intent(in) :: ml_depth\n real(8), intent(in) :: Rd,cpd\n real(8), dimension(km,jm,im), intent(in) :: p, T, q\n real(8), dimension(jm,im), intent(out) :: Tst,pst,T0,q0\n\n! Local\n integer :: k,j,i\n real(8) :: dp\n real(8), dimension(5,jm,im) :: p5,T5,q5,theta5\n real(8), dimension(jm,im) :: p0\n\n! if mixed layer depth is 0, use surface values\n if (ml_depth == 0.) then\n p0 = p(km,:,:)\n T0 = T(km,:,:)\n q0 = q(km,:,:)\n\n else\n! compute new pressure grid, equispaced over 5 layers from ground to top\n dp = ml_depth/5.\n do k=1,5\n p5(k,:,:) = p(km,:,:) - dp*(5-k)\n end do\n\n! interpolate T, q onto new pressure grid\n do i=1,im\n do j=1,jm\n call interpol(p(:,j,i),T(:,j,i),km,p5(:,j,i),T5(:,j,i),5)\n call interpol(p(:,j,i),q(:,j,i),km,p5(:,j,i),q5(:,j,i),5)\n end do\n end do\n \n! average conserved quantities over mixed layer\n p0 = p(km,:,:)\n do k=1,5\n theta5(k,:,:) = T5(k,:,:)*( p5(k,:,:)/p0 )**(Rd/cpd)\n end do\n do i=1,im\n do j=1,jm\n T0(j,i) = sum(theta5(:,j,i))/5.\n q0(j,i) = sum(q5(:,j,i))/5.\n end do\n end do\n\n endif\n\n! compute saturation point pressure and temp\n call tstar(1,jm,im,T0,p0,q0,Tst)\n pst = p0*(Tst/T0)**(cpd/Rd)\n\nend subroutine mean_parcel\n!--------------------------------------------------------------------------\nsubroutine interpol(xin,yin,nin,xout,yout,nout)\n\n real xin(nin),yin(nin),xout(nout),yout(nout),spl(2000)\n\n yp1=1.e30\n ypn=1.e30\n call spline(xin,yin,nin,yp1,ypn,spl) \n\n do n=1,nout\n call splint(xin,yin,spl,nin,xout(n),yout(n))\n enddo\n\nend subroutine interpol\n!------------------------------------------------------------------------\nSUBROUTINE spline(x,y,n,yp1,ypn,y2)\n INTEGER n,NMAX\n REAL yp1,ypn,x(n),y(n),y2(n)\n PARAMETER (NMAX=500)\n INTEGER i,k\n REAL p,qn,sig,un,u(NMAX)\n if (yp1.gt..99e30) then\n y2(1)=0.\n u(1)=0.\n else\n y2(1)=-0.5\n u(1)=(3./(x(2)-x(1)))*((y(2)-y(1))/(x(2)-x(1))-yp1)\n endif\n do i=2,n-1\n sig=(x(i)-x(i-1))/(x(i+1)-x(i-1))\n p=sig*y2(i-1)+2.\n y2(i)=(sig-1.)/p\n u(i)=(6.*((y(i+1)-y(i))/(x(i+1)-x(i))-(y(i)-y(i-1))/(x(i)-x(i-1)))&\n /(x(i+1)-x(i-1))-sig*u(i-1))/p\n enddo\n if (ypn.gt..99e30) then\n qn=0.\n un=0.\n else\n qn=0.5\n un=(3./(x(n)-x(n-1)))*(ypn-(y(n)-y(n-1))/(x(n)-x(n-1)))\n endif\n y2(n)=(un-qn*u(n-1))/(qn*y2(n-1)+1.)\n do k=n-1,1,-1\n y2(k)=y2(k)*y2(k+1)+u(k)\n enddo\nend SUBROUTINE spline\n! (C) Copr. 1986-92 Numerical Recipes Software \n!---------------------------------------------------------------------------\nSUBROUTINE splint(xa,ya,y2a,n,x,y)\n INTEGER n\n REAL x,y,xa(n),y2a(n),ya(n)\n INTEGER k,khi,klo\n REAL a,b,h\n klo=1\n khi=n\n1 if (khi-klo.gt.1) then\n k=(khi+klo)/2\n if(xa(k).gt.x)then\n khi=k\n else\n klo=k\n endif\n goto 1\n endif\n h=xa(khi)-xa(klo)\n if (h.eq.0.) stop 'bad xa input in splint'\n a=(xa(khi)-x)/h\n b=(x-xa(klo))/h\n y=a*ya(klo)+b*ya(khi)+((a**3-a)*y2a(klo)+(b**3-b)*y2a(khi))*(h**2)/6.\n \nEND SUBROUTINE splint\n! (C) Copr. 1986-92 Numerical Recipes Software \n\n\n\n\n\n\n\n", "meta": {"hexsha": "322c33f4c44d7b0e381f291ae240a82798094c8d", "size": 27579, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/thermodyn/Driver.f90", "max_stars_repo_name": "CliMT/climt-legacy", "max_stars_repo_head_hexsha": "adbd4fe77426c90deb8d2c046a2f3dc3b72df89e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/thermodyn/Driver.f90", "max_issues_repo_name": "CliMT/climt-legacy", "max_issues_repo_head_hexsha": "adbd4fe77426c90deb8d2c046a2f3dc3b72df89e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/thermodyn/Driver.f90", "max_forks_repo_name": "CliMT/climt-legacy", "max_forks_repo_head_hexsha": "adbd4fe77426c90deb8d2c046a2f3dc3b72df89e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.5278372591, "max_line_length": 83, "alphanum_fraction": 0.5165524493, "num_tokens": 9835, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797068590724, "lm_q2_score": 0.7401743677704878, "lm_q1q2_score": 0.6519434133782381}} {"text": "!*******************************************************************************\n!> author: Jacob Williams\n!\n! Test for the [[slsqp_module]].\n\n program slsqp_test_2\n\n use slsqp_module\n use slsqp_kinds\n\n implicit none\n\n integer,parameter :: n = 3 !! number of optimization variables\n integer,parameter :: m = 2 !! total number of constraints\n integer,parameter :: meq = 1 !! number of equality constraints\n integer,parameter :: max_iter = 100 !! maximum number of allowed iterations\n real(wp),dimension(n),parameter :: xl = [-10.0_wp, -10.0_wp, -10.0_wp] !! lower bounds\n real(wp),dimension(n),parameter :: xu = [ 10.0_wp, 10.0_wp, 10.0_wp] !! upper bounds\n real(wp),parameter :: acc = 1.0e-7_wp !! tolerance\n integer,parameter :: linesearch_mode = 1 !! use inexact linesearch.\n\n type(slsqp_solver) :: solver !! instantiate an slsqp solver\n real(wp),dimension(n) :: x !! optimization variable vector\n integer :: istat !! for solver status check\n logical :: status_ok !! for initialization status check\n integer :: iterations !! number of iterations by the solver\n\n x = [1.0_wp, 2.0_wp, 3.0_wp] ! initial guess\n\n call solver%initialize(n,m,meq,max_iter,acc,test_func,test_grad,&\n xl,xu,linesearch_mode=linesearch_mode,status_ok=status_ok,&\n report=report_iteration,&\n alphamin=0.1_wp, alphamax=0.5_wp) !to limit search steps\n\n if (status_ok) then\n call solver%optimize(x,istat,iterations)\n write(*,*) ''\n write(*,*) 'solution :', x\n write(*,*) 'istat :', istat\n write(*,*) 'iterations :', iterations\n write(*,*) ''\n else\n error stop 'error calling slsqp.'\n end if\n\n ! Solution is: x = [1,1,1], f = 3\n\n contains\n\n subroutine test_func(me,x,f,c)\n\n !! Compute the objective function and constraints\n !!\n !! Minimize:\n !!\n !! * \\( f = x_1^2 + x_2^2 + x_3 \\)\n !!\n !! Subject to:\n !!\n !! * \\( c_1 = x_1 x_2 - x_3 = 0 \\)\n !! * \\( c_2 = x_3 - 1 \\ge 0 \\)\n\n implicit none\n\n class(slsqp_solver),intent(inout) :: me\n real(wp),dimension(:),intent(in) :: x !! optimization variable vector\n real(wp),intent(out) :: f !! value of the objective function\n real(wp),dimension(:),intent(out) :: c !! the constraint vector `dimension(m)`,\n !! equality constraints (if any) first.\n\n f = x(1)**2 + x(2)**2 + x(3) !objective function\n\n c(1) = x(1)*x(2) - x(3) !equality constraint (==0)\n c(2) = x(3) - 1.0_wp !inequality constraint (>=0)\n\n end subroutine test_func\n\n subroutine test_grad(me,x,g,a)\n\n !! compute the gradients.\n\n implicit none\n\n class(slsqp_solver),intent(inout) :: me\n real(wp),dimension(:),intent(in) :: x !! optimization variable vector\n real(wp),dimension(:),intent(out) :: g !! objective function partials w.r.t x `dimension(n)`\n real(wp),dimension(:,:),intent(out) :: a !! gradient matrix of constraints w.r.t. x `dimension(m,n)`\n\n g(1) = 2.0_wp*x(1)\n g(2) = 2.0_wp*x(2)\n g(3) = 1.0_wp\n\n a(1,1) = x(2)\n a(1,2) = x(1)\n a(1,3) = -1.0_wp\n\n a(2,1) = 0.0_wp\n a(2,2) = 0.0_wp\n a(2,3) = 1.0_wp\n\n end subroutine test_grad\n\n subroutine report_iteration(me,iter,x,f,c)\n\n !! report an iteration (print to the console).\n\n use, intrinsic :: iso_fortran_env, only: output_unit\n\n implicit none\n\n class(slsqp_solver),intent(inout) :: me\n integer,intent(in) :: iter\n real(wp),dimension(:),intent(in) :: x\n real(wp),intent(in) :: f\n real(wp),dimension(:),intent(in) :: c\n\n !write a header:\n if (iter==0) then\n write(output_unit,'(*(A20,1X))') 'iteration', &\n 'x(1)', 'x(2)', 'x(3)', &\n 'f(1)', 'c(1)', 'c(2)'\n end if\n\n !write the iteration data:\n write(output_unit,'(I20,1X,(*(F20.16,1X)))') iter,x,f,c\n\n end subroutine report_iteration\n\n end program slsqp_test_2\n!*******************************************************************************\n", "meta": {"hexsha": "cb2978565e9c68418680527e7666f71169ba9e4b", "size": 4649, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/slsqp_test_2.f90", "max_stars_repo_name": "LKedward/slsqp", "max_stars_repo_head_hexsha": "163628e77d5de6d8647c6f44d2bf9cdf9dbb04f2", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 52, "max_stars_repo_stars_event_min_datetime": "2016-01-12T17:41:53.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-30T09:38:15.000Z", "max_issues_repo_path": "src/tests/slsqp_test_2.f90", "max_issues_repo_name": "LKedward/slsqp", "max_issues_repo_head_hexsha": "163628e77d5de6d8647c6f44d2bf9cdf9dbb04f2", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 20, "max_issues_repo_issues_event_min_datetime": "2018-03-14T21:58:16.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-26T15:19:49.000Z", "max_forks_repo_path": "src/tests/slsqp_test_2.f90", "max_forks_repo_name": "LKedward/slsqp", "max_forks_repo_head_hexsha": "163628e77d5de6d8647c6f44d2bf9cdf9dbb04f2", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2016-03-28T10:37:10.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-05T06:33:41.000Z", "avg_line_length": 35.4885496183, "max_line_length": 111, "alphanum_fraction": 0.4912884491, "num_tokens": 1254, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970811069351, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6519434125458898}} {"text": " SUBROUTINE polcoe(x,y,n,cof)\r\n INTEGER n,NMAX\r\n REAL cof(n),x(n),y(n)\r\n PARAMETER (NMAX=15)\r\n INTEGER i,j,k\r\n REAL b,ff,phi,s(NMAX)\r\n do 11 i=1,n\r\n s(i)=0.\r\n cof(i)=0.\r\n11 continue\r\n s(n)=-x(1)\r\n do 13 i=2,n\r\n do 12 j=n+1-i,n-1\r\n s(j)=s(j)-x(i)*s(j+1)\r\n12 continue\r\n s(n)=s(n)-x(i)\r\n13 continue\r\n do 16 j=1,n\r\n phi=n\r\n do 14 k=n-1,1,-1\r\n phi=k*s(k+1)+x(j)*phi\r\n14 continue\r\n ff=y(j)/phi\r\n b=1.\r\n do 15 k=n,1,-1\r\n cof(k)=cof(k)+b*ff\r\n b=s(k)+x(j)*b\r\n15 continue\r\n16 continue\r\n return\r\n END\r\n", "meta": {"hexsha": "c345d784625fe346fd715bb0f4625938d10c1ba2", "size": 674, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/polcoe.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/polcoe.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/polcoe.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": 21.0625, "max_line_length": 35, "alphanum_fraction": 0.4035608309, "num_tokens": 247, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778824, "lm_q2_score": 0.7401743563075446, "lm_q1q2_score": 0.6519434102298453}} {"text": "c\nc\nc\nc =================================================\n double precision function fdisc(blockno,xc,yc)\nc =================================================\n implicit none\n\n double precision xc,yc\n integer blockno\n\n double precision x0, y0, alf, beta, r0\n integer idisc\n common/cdisc/ x0,y0,alf,beta,r0,idisc\n\n\n double precision x, y, f1,f2\n\nc\nc # for computing cell averages for initial data that has a\nc # discontinuity along some curve. fdisc should be negative to the\nc # left of the curve and positive to the right\nc # idisc specifies the nature of the discontinuity for two\nc # particular cases (a straight line and circle) but this routine\nc # can be modified for any other curve.\nc\n\n x = xc\n y = yc\n\n go to (10,20,30,40) idisc\nc\n 10 continue\nc # straight line through (x0,y0) with normal (alf,beta) pointing\nc # into right state\nc\n fdisc = (x-x0)*alf + (y-y0)*beta\n return\nc\n 20 continue\nc # circle of radius r0:\n fdisc = (x-x0)**2 + (y-y0)**2 - r0**2\n return\n\n 30 continue\n f1 = (x-x0)**2 + (y-y0+0.5d0)**2 - r0**2\n f2 = (x-x0)**2 + (y-y0-0.5d0)**2 - r0**2\n if (f1 .lt. 0) then\n fdisc = f1\n elseif (f2 .lt. 0) then\n fdisc = f2\n else\n fdisc = min(f1,f2)\n endif\n return\n\n 40 continue\n f1 = (x-x0)**2 + (y-y0+0.5d0)**2 - (r0/sqrt(2.d0))**2\n f2 = (x-x0)**2 + (y-y0-0.5d0)**2 - (r0/sqrt(2.d0))**2\n if (f1 .lt. 0) then\n fdisc = f1\n elseif (f2 .lt. 0) then\n fdisc = f2\n else\n fdisc = min(f1,f2)\n endif\n\n\n return\n end\n", "meta": {"hexsha": "8acfed06fa36d1d9a4a2a8c026fc81c05a1149e3", "size": 1671, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "applications/clawpack/euler/2d/shockbubble/fdisc.f", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2017-09-26T13:39:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:56:23.000Z", "max_issues_repo_path": "applications/clawpack/euler/2d/shockbubble/fdisc.f", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 75, "max_issues_repo_issues_event_min_datetime": "2017-08-02T19:56:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T12:36:32.000Z", "max_forks_repo_path": "applications/clawpack/euler/2d/shockbubble/fdisc.f", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-02-21T00:10:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T19:08:36.000Z", "avg_line_length": 23.5352112676, "max_line_length": 72, "alphanum_fraction": 0.5146618791, "num_tokens": 573, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970717197768, "lm_q2_score": 0.7401743505760728, "lm_q1q2_score": 0.6519434005494925}} {"text": "C ************************************************************\nC Source for the library implementing a bias function that \nC populates the large pt tale of the leading jet. \nC\nC The two options of this subroutine, that can be set in\nC the run card are:\nC > (double precision) ptj_bias_target_ptj : target ptj value\nC > (double precision) ptj_bias_enhancement_power : exponent\nC\nC Schematically, the functional form of the enhancement is\nC bias_wgt = [ptj(evt)/mean_ptj]^enhancement_power\nC ************************************************************\nC\nC The following lines are read by MG5aMC to set what are the \nC relevant parameters for this bias module.\nC\nC parameters = {'ptj_bias_target_ptj': 1000.0,\nC 'ptj_bias_enhancement_power': 4.0}\nC\n\n subroutine bias_wgt(p, original_weight, bias_weight)\n implicit none\nC\nC Parameters\nC\n include '../../maxparticles.inc' \n include '../../nexternal.inc'\n\nC\nC Arguments\nC\n double precision p(0:3,nexternal)\n double precision original_weight, bias_weight\nC\nC local variables\nC\n integer i\n double precision ptj(nexternal)\n double precision max_ptj\nc\nc local variables defined in the run_card\nc\n double precision ptj_bias_target_ptj\n double precision ptj_bias_enhancement_power\nC\nC Global variables\nC\nC\nC Mandatory common block to be defined in bias modules\nC\n double precision stored_bias_weight\n data stored_bias_weight/1.0d0/ \n logical impact_xsec, requires_full_event_info\nC We only want to bias distributions, but not impact the xsec. \n data impact_xsec/.False./\nC Of course this module does not require the full event\nC information (color, resonances, helicities, etc..)\n data requires_full_event_info/.False./ \n common/bias/stored_bias_weight,impact_xsec,\n & requires_full_event_info\nC\nC Accessingt the details of the event\nC\n logical is_a_j(nexternal),is_a_l(nexternal),\n & is_a_b(nexternal),is_a_a(nexternal),\n & is_a_onium(nexternal),is_a_nu(nexternal),\n & is_heavy(nexternal),do_cuts(nexternal)\n common/to_specisa/is_a_j,is_a_a,is_a_l,is_a_b,is_a_nu,\n & is_heavy,is_a_onium,do_cuts\n\nC\nC Setup the value of the parameters from the run_card \nC\n include '../bias.inc'\n\nC --------------------\nC BEGIN IMPLEMENTATION\nC --------------------\n \n do i=1,nexternal\n ptj(i)=-1.0d0\n if (is_a_j(i)) then\n ptj(i)=sqrt(p(1,i)**2+p(2,i)**2)\n endif\n enddo\n\n max_ptj=-1.0d0\n do i=1,nexternal\n max_ptj = max(max_ptj,ptj(i))\n enddo\n if (max_ptj.lt.0.0d0) then\n bias_weight = 1.0d0\n return\n endif\n\n bias_weight = (max_ptj/ptj_bias_target_ptj)\n & **ptj_bias_enhancement_power\n\n return\n\n end subroutine bias_wgt\n", "meta": {"hexsha": "7ce41370c4d9015bbdfa6b70aa2586b6971ba095", "size": 3090, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Template/LO/Source/BIAS/ptj_bias/ptj_bias.f", "max_stars_repo_name": "valassi/mg5amc_test", "max_stars_repo_head_hexsha": "2e04f23353051f64e1604b23105fe3faabd32869", "max_stars_repo_licenses": ["NCSA"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-10-23T14:37:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-22T20:59:02.000Z", "max_issues_repo_path": "Template/LO/Source/BIAS/ptj_bias/ptj_bias.f", "max_issues_repo_name": "valassi/mg5amc_test", "max_issues_repo_head_hexsha": "2e04f23353051f64e1604b23105fe3faabd32869", "max_issues_repo_licenses": ["NCSA"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2018-10-08T15:49:32.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-15T13:33:36.000Z", "max_forks_repo_path": "Template/LO/Source/BIAS/ptj_bias/ptj_bias.f", "max_forks_repo_name": "valassi/mg5amc_test", "max_forks_repo_head_hexsha": "2e04f23353051f64e1604b23105fe3faabd32869", "max_forks_repo_licenses": ["NCSA"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2019-02-18T11:42:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-11T20:46:08.000Z", "avg_line_length": 30.2941176471, "max_line_length": 72, "alphanum_fraction": 0.598381877, "num_tokens": 766, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797027760039, "lm_q2_score": 0.7154239957834733, "lm_q1q2_score": 0.6518798238368062}} {"text": "\nMODULE PRECOMPUTATION\n\nUSE MPI\nUSE BASIS\nUSE MESH, ONLY: NEL_TOTAL\nUSE PARAM, ONLY: N, M\n\nIMPLICIT NONE\n\nDOUBLE PRECISION, ALLOCATABLE, DIMENSION(:, :) :: GL_POINT_ALL ! GUASS LEGENDRE POINTS\nDOUBLE PRECISION, ALLOCATABLE, DIMENSION(:, :) :: GL_W_ALL ! GUASS LEGENDRE WEIGHTS\nDOUBLE PRECISION, ALLOCATABLE, DIMENSION(:, :) :: GLL_POINT_ALL ! GUASS LEGENDRE LOBATTO POINT\nDOUBLE PRECISION, ALLOCATABLE, DIMENSION(:, :) :: GLL_W_ALL ! GUASS LEGENDRE LOBATTO WEIGHTS\n \nCONTAINS\n\nSUBROUTINE \n\n IMPLICIT NONE\n \n INTEGER :: I\n \n ALLOCATE(GL_POINT_ALL(M+1))\n \n !-------------------------------------------------------------------\n DO I=1, NEL_TOTAL\n !Gauss Legendre quadrature nodes and weights\n CALL GL(N)\n \n CALL GLL(N)\n ENDDO\n !-------------------------------------------------------------------\n \n\n\nEND MODULE PRECOMPUTATION\n", "meta": {"hexsha": "3a49db7742905fde08f8644801df399111fb9eb5", "size": 890, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/precomputation.f90", "max_stars_repo_name": "ShiqiHe000/1d_DG_advaction", "max_stars_repo_head_hexsha": "05f0dd809dabc43aa3ee3d765261f658508a21ff", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-15T01:38:37.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-15T01:38:37.000Z", "max_issues_repo_path": "src/precomputation.f90", "max_issues_repo_name": "ShiqiHe000/1d_DG_advaction", "max_issues_repo_head_hexsha": "05f0dd809dabc43aa3ee3d765261f658508a21ff", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/precomputation.f90", "max_forks_repo_name": "ShiqiHe000/1d_DG_advaction", "max_forks_repo_head_hexsha": "05f0dd809dabc43aa3ee3d765261f658508a21ff", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.4210526316, "max_line_length": 94, "alphanum_fraction": 0.5696629213, "num_tokens": 234, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391624034103, "lm_q2_score": 0.7549149978955811, "lm_q1q2_score": 0.6517872860407672}} {"text": "program i\n integer::a=3*4 + 5/6\nend program i\n", "meta": {"hexsha": "f5ef9543562bd074d3ab2289d0c165fe0b411ed3", "size": 47, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/decl/scalar_init/decl_init3.f90", "max_stars_repo_name": "clementval/fc", "max_stars_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/decl/scalar_init/decl_init3.f90", "max_issues_repo_name": "clementval/fc", "max_issues_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/decl/scalar_init/decl_init3.f90", "max_forks_repo_name": "clementval/fc", "max_forks_repo_head_hexsha": "a5b444963c1b46e4eb34d938d992836d718010f7", "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": 11.75, "max_line_length": 22, "alphanum_fraction": 0.6595744681, "num_tokens": 21, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916240341031, "lm_q2_score": 0.7549149923816048, "lm_q1q2_score": 0.6517872812800463}} {"text": " Program dstedc_example\n\n! DSTEDC Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_example_aux, Only: nagf_file_print_matrix_real_gen\n Use lapack_interfaces, Only: dsbtrd, dstedc\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nin = 5, nout = 6\n Character (1), Parameter :: uplo = 'U'\n! .. Local Scalars ..\n Integer :: i, ifail, info, j, kd, ldab, ldz, lgn, liwork, lwork, n\n! .. Local Arrays ..\n Real (Kind=dp), Allocatable :: ab(:, :), d(:), e(:), work(:), z(:, :)\n Real (Kind=dp) :: rdum(1)\n Integer :: idum(1)\n Integer, Allocatable :: iwork(:)\n! .. Intrinsic Procedures ..\n Intrinsic :: ceiling, log, max, min, nint, real\n! .. Executable Statements ..\n Write (nout, *) 'DSTEDC Example Program Results'\n Write (nout, *)\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n, kd\n ldab = kd + 1\n ldz = n\n lgn = ceiling(log(real(n,kind=dp))/log(2.0E0_dp))\n Allocate (ab(ldab,n), d(n), e(n-1), z(ldz,n))\n\n! Use routine workspace query to get optimal workspace.\n lwork = -1\n liwork = -1\n Call dstedc('V', n, d, e, z, ldz, rdum, lwork, idum, liwork, info)\n\n! Make sure that there is enough workspace.\n lwork = max(1+3*n+2*n*lgn+4*n*n, nint(rdum(1)))\n liwork = max(6+6*n+5*n*lgn, idum(1))\n Allocate (work(lwork), iwork(liwork))\n\n! Read the upper or lower triangular part of the band matrix A\n! from data file\n\n If (uplo=='U') Then\n Do i = 1, n\n Read (nin, *)(ab(kd+1+i-j,j), j=i, min(n,i+kd))\n End Do\n Else If (uplo=='L') Then\n Do i = 1, n\n Read (nin, *)(ab(1+i-j,j), j=max(1,i-kd), i)\n End Do\n End If\n\n! Reduce A to tridiagonal form T = (Z**T)*A*Z, and form Z\n Call dsbtrd('V', uplo, n, kd, ab, ldab, d, e, z, ldz, work, info)\n\n! Calculate all the eigenvalues and eigenvectors of A,\n! from T and Z\n Call dstedc('V', n, d, e, z, ldz, work, lwork, iwork, liwork, info)\n\n If (info==0) Then\n\n! Print eigenvalues and eigenvectors\n\n Write (nout, *) 'Eigenvalues'\n Write (nout, 100) d(1:n)\n\n Write (nout, *)\n Flush (nout)\n\n! Standardize the eigenvectors so that first elements are non-negative.\n Do i = 1, n\n If (z(1,i)<0.0_dp) Then\n z(1:n, i) = -z(1:n, i)\n End If\n End Do\n\n! ifail: behaviour on error exit\n! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft\n ifail = 0\n Call nagf_file_print_matrix_real_gen('General', ' ', n, n, z, ldz, &\n 'Eigenvectors', ifail)\n\n Else\n Write (nout, 110) 'Failure in DSTEDC. INFO = ', info\n End If\n\n100 Format ((3X,8F8.4))\n110 Format (1X, A, I10)\n End Program\n", "meta": {"hexsha": "a2aa2d0f167bc769f8ae4327ba8e7af1b1eaf77d", "size": 3079, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/dstedc_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/dstedc_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/dstedc_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 31.4183673469, "max_line_length": 90, "alphanum_fraction": 0.5566742449, "num_tokens": 1008, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916170039421, "lm_q2_score": 0.7549149978955811, "lm_q1q2_score": 0.6517872807335934}} {"text": " program demo_poly\n use M_calcomp, only : plots, poly, plot\n implicit none\n real :: xstart, ystart\n real :: side_length\n real :: number_of_sides\n real :: angle\n integer :: i\n call plots(0.0,10.0,0.0,10.0)\n call plot(0.001,0.001,-3) ! move origin a bit so lines on edge OK\n call poly(0.0,0.0,10.0,4.0,0.0) ! 10 inch square\n side_length=2.35\n xstart=(10.0-side_length)/2.0\n ystart=0.5\n angle=0.0\n do i = 3,12\n number_of_sides=real(i)\n call poly(xstart,ystart,side_length,number_of_sides,angle)\n enddo\n call plot(0.0,0.0,999)\n end program demo_poly\n", "meta": {"hexsha": "9c7c91f679101b437737851fabf76c70c6fc893b", "size": 734, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "example/demo_poly.f90", "max_stars_repo_name": "urbanjost/M_calcomp", "max_stars_repo_head_hexsha": "72eb83b3cb6f6498c39097fcb379130beb27eedb", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-05-15T10:22:11.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-15T10:22:11.000Z", "max_issues_repo_path": "example/demo_poly.f90", "max_issues_repo_name": "urbanjost/M_calcomp", "max_issues_repo_head_hexsha": "72eb83b3cb6f6498c39097fcb379130beb27eedb", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "example/demo_poly.f90", "max_forks_repo_name": "urbanjost/M_calcomp", "max_forks_repo_head_hexsha": "72eb83b3cb6f6498c39097fcb379130beb27eedb", "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.3636363636, "max_line_length": 73, "alphanum_fraction": 0.5272479564, "num_tokens": 233, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.7549149978955811, "lm_q1q2_score": 0.6517872807335933}} {"text": "C******************** START FILE FLINT_Z.FOR ; GROUP SIGS2 ********************\nC==============================================================================\nC\nC FLINT_Z\nC INTERPOLATE ON A 2D ARRAY\nC\n SUBROUTINE FLINT_Z(X,Y,F,N,MTX,XMIN,XMAX,XLR,NX,YMIN,YMAX,YLR,\n > NY,IWARN)\nC\nC============\nC idecl: explicitize implicit INTEGER declarations:\n IMPLICIT NONE\n INTEGER n,nx,ny,it,iwarn,ix,iy,ixp1,iyp1\nC============\nC idecl: explicitize implicit REAL declarations:\n REAL*8 f,mtx,x,y,xmin,xmax,xlr,ymin,ymax,ylr,zx,zy,zzx,zlogx,\n > zzy,zlogy,zf00,zf01,zf10,zf11\nC============\n DIMENSION MTX(NX,NY)\n DIMENSION X(N)\n DIMENSION Y(N)\n DIMENSION F(N)\nc\nc Interpolates the table MTX(NX,NY) to find the value at (x,y).\nc If XLR>0, then the X grid is equally spaced on a logarithmic scale:\nc\nc X(i) = XMIN * (exp(XLR)) ** ( (i-1)/(NX-1) )\nc\nc So X(i) ranges from XMIN to XMIN*exp(XLR), and XLR=log(xmax/xmin).\nc\nc For XLR<=0, the X grid is equally spaced on a linear scale from\nc XMIN to XMAX.\nc\nc For YLR>0, Y is logarithmically spaced from YMIN to YMIN*exp(YLR)\nc and for YLR<=0, Y is linearly spaced from YMIN to YMAX.\nC\nC Modified 7/26/00 (PCR) - vectorized.\nC\n integer idebug\n common/flint_debug/ idebug\nC\nC\n iwarn=0\nC\n do 70 it=1,n\nC\n ZX=X(it)\n ZY=Y(it)\nC\n if(zx .lt. xmin .or. zx/xmin .le. 0.0) then\n zzx=0.0D0\n else\n \n IF(XLR.GT.0.0D0) THEN\n ZLOGX=log(ZX/XMIN)\n ZZX=1.0D0+ZLOGX/XLR * (NX-1)\n ELSE\n ZZX=1.0D0+(ZX-XMIN)/(XMAX-XMIN) * (NX-1)\n ENDIF\n \n endif\nC\n if(zy .lt. ymin .or. zy/ymin .le. 0.0) then\n zzy=0.0D0\n else\n \n IF(YLR.GT.0.0D0) THEN\n ZLOGY=log(ZY/YMIN)\n ZZY=1.0D0+ZLOGY/YLR * (NY-1)\n ELSE\n ZZY=1.0D0+(ZY-YMIN)/(YMAX-YMIN) * (NY-1)\n ENDIF\n \n endif\nC\n IX=ZZX\n IY=ZZY\nC CHECK FOR POINT OUT OF BOUNDS OF ARRAY\n IF(IX.GE.1) GO TO 10\nC\n IF(ZX.LT.(XMIN - 5.0D-7)) THEN\n IWARN=1\n ENDIF\n IX=1\n ZZX=1.0D0\nC\n 10 CONTINUE\n IF(IY.GE.1) GO TO 20\nC\n IF(ZY.LT.(YMIN - 5.0D-7)) THEN\n IWARN=1\n ENDIF\n IY=1\n ZZY=1.0D0\nC\n 20 CONTINUE\n IF(IX.LT.NX) GO TO 30\nC\n IF(ZX.GT.(XMAX + 5.0D-7)) THEN\n IWARN=1\n ENDIF\n IX=NX-1\n ZZX=NX\nC\n 30 CONTINUE\n IF(IY.LT.NY) GO TO 40\nC\n IF(ZY.GT.(YMAX + 5.0D-7)) THEN\n IWARN=1\n ENDIF\n IY=NY-1\n ZZY=NY\nC\nC---------------------------\nC OK\nC\n 40 CONTINUE\n IXP1=IX+1\n IYP1=IY+1\n ZZX=ZZX-IX\n ZZY=ZZY-IY\n ZF00=(1.D0-ZZX)*(1.D0-ZZY)\n ZF01=(1.D0-ZZX)*ZZY\n ZF10=ZZX*(1.D0-ZZY)\n ZF11=ZZX*ZZY\nC\nC INTERPOLATE\nC\n F(it)=ZF00*MTX(IX,IY)+ZF01*MTX(IX,IYP1)+\n > ZF10*MTX(IXP1,IY)+ZF11*MTX(IXP1,IYP1)\nc\n if(idebug.eq.99) then\n write(6,*) 'flin1_z: zx,zy=',zx,zy,' ix,iy=',ix,iy\n write(6,*) ' mtx(ix,iy:iyp1) = ',mtx(ix,iy:iyp1)\n write(6,*) ' mtx(ixp1,iy:iyp1) = ',mtx(ixp1,iy:iyp1)\n write(6,*) ' it,F(it)=',it,F(it)\n endif\nC\n 70 continue\nC\n idebug=0 ! clear debug flag\nC\n END\nC\nC******************** END FILE FLINT.FOR ; GROUP SIGS2 ************************\n! 26Jul2000 fgtok -s r8_precision.sub \"r8con.csh conversion\"\n", "meta": {"hexsha": "ddf2c16b56964cb97ddc14a235d273d5356d7135", "size": 3536, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "LIBSTELL/Sources/Modules/flint_z.f", "max_stars_repo_name": "joseluisvelasco/STELLOPT", "max_stars_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2020-05-08T01:47:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T10:35:28.000Z", "max_issues_repo_path": "LIBSTELL/Sources/Modules/flint_z.f", "max_issues_repo_name": "joseluisvelasco/STELLOPT", "max_issues_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 77, "max_issues_repo_issues_event_min_datetime": "2020-05-08T07:18:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:20:33.000Z", "max_forks_repo_path": "LIBSTELL/Sources/Modules/flint_z.f", "max_forks_repo_name": "joseluisvelasco/STELLOPT", "max_forks_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-02-10T13:47:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T12:53:43.000Z", "avg_line_length": 24.0544217687, "max_line_length": 79, "alphanum_fraction": 0.4884049774, "num_tokens": 1345, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737807, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.651787265904977}} {"text": "submodule (m_Sort) sm_introsort\n !! introsort and argIntrosort routines\n\n use m_swap, only: swap\n use m_partition, only: partition, argPartition\n use m_medianOf3, only: medianOf3, argMedianOf3\n\n implicit none\n\n integer(i32), parameter :: minimumLengthForInsertion = 16\n\n contains\n !====================================================================!\n module procedure introsort_r1D\n !! Interfaced with introsort()\n !====================================================================!\n integer(i32) :: left,right\n integer(i32) :: maxDepth\n left=1\n right=size(this)\n maxDepth = 2*idnint(log(dble(right)))\n call r_introsort_r1D(this,left,right,maxDepth)\n end procedure\n !====================================================================!\n !====================================================================!\n recursive subroutine r_introsort_r1D(this,left,right,maxDepth)\n !====================================================================!\n real(r32) :: this(:)\n integer(i32) :: left,right\n integer(i32) :: maxDepth\n integer(i32) :: imid,iPivot\n integer(i32) :: N\n N = right - left + 1\n if (N < minimumLengthForInsertion) then\n call InsertionSort(this,left,right)\n return\n end if\n if (maxDepth == 0) then\n call heapsort_r1D(this(left:right))\n return\n end if\n imid = left + N/2\n call medianOf3(this, left, imid, right)\n call swap(this(left), this(imid))\n call partition(this,left,right,iPivot)\n call r_introsort_r1D(this,left,iPivot-1,maxDepth-1)\n call r_introsort_r1D(this,iPivot+1,right,maxDepth-1)\n end subroutine\n !====================================================================!\n !====================================================================!\n module procedure introsort_d1D\n !! Interfaced with introsort()\n !====================================================================!\n integer(i32) :: left,right,maxDepth\n left=1\n right=size(this)\n maxDepth = 2*idnint(log(dble(right)))\n call r_introsort_d1D(this,left,right,maxDepth)\n end procedure\n !====================================================================!\n !====================================================================!\n recursive subroutine r_introsort_d1D(this,left,right,maxDepth)\n !====================================================================!\n real(r64) :: this(:)\n integer(i32) :: left,right\n integer(i32) :: maxDepth\n integer(i32) :: imid,iPivot\n integer(i32) :: N\n N = right - left + 1\n if (N < minimumLengthForInsertion) then\n call InsertionSort(this,left,right)\n return\n end if\n if (maxDepth == 0) then\n call heapsort_d1D(this(left:right))\n return\n end if\n imid = left + N/2\n call medianOf3(this, left, imid, right)\n call swap(this(left), this(imid))\n call partition(this,left,right,iPivot)\n call r_introsort_d1D(this,left,iPivot-1, maxDepth-1)\n call r_introsort_d1D(this,iPivot+1,right, maxDepth-1)\n end subroutine\n !====================================================================!\n !====================================================================!\n module procedure introsort_i1D\n !! Interfaced with introsort()\n !====================================================================!\n integer(i32) :: left,right\n integer(i32) :: maxDepth\n left=1\n right=size(this)\n maxDepth=2*idnint(log(dble(right)))\n call r_introsort_i1D(this,left,right,maxDepth)\n end procedure\n !====================================================================!\n !====================================================================!\n recursive subroutine r_introsort_i1D(this,left,right,maxDepth)\n !====================================================================!\n integer(i32) :: this(:)\n integer(i32) :: left,right\n integer(i32) :: maxDepth\n integer(i32) :: imid,iPivot\n integer(i32) :: N\n N=right-left + 1\n if (N < minimumLengthForInsertion) then\n call InsertionSort(this,left,right)\n return\n end if\n if (maxDepth == 0) then\n call heapsort_i1D(this(left:right))\n return\n end if\n iMid = (left+right)/2\n call medianOf3(this, left, imid, right)\n call swap(this(left), this(imid))\n call partition(this,left,right,iPivot)\n call r_introsort_i1D(this,left,iPivot-1,maxDepth-1)\n call r_introsort_i1D(this,iPivot+1,right,maxDepth-1)\n end subroutine\n !====================================================================!\n !====================================================================!\n module procedure introsort_id1D\n !! Interfaced with introsort()\n !====================================================================!\n integer(i32) :: left,right\n integer(i32) :: maxDepth\n left=1\n right=size(this)\n maxDepth=2*idnint(log(dble(right)))\n call r_introsort_id1D(this,left,right,maxDepth)\n end procedure\n !====================================================================!\n !====================================================================!\n recursive subroutine r_introsort_id1D(this,left,right,maxDepth)\n !====================================================================!\n integer(i64) :: this(:)\n integer(i32) :: left,right\n integer(i32) :: maxDepth\n integer(i32) :: imid,iPivot\n integer(i32) :: N\n N=right-left + 1\n if (N < minimumLengthForInsertion) then\n call InsertionSort(this,left,right)\n return\n end if\n if (maxDepth == 0) then\n call heapsort_id1D(this(left:right))\n return\n end if\n imid = left + N/2\n call medianOf3(this, left, imid, right)\n call swap(this(left), this(imid))\n call partition(this,left,right,iPivot)\n call r_introsort_id1D(this,left,iPivot-1,maxDepth-1)\n call r_introsort_id1D(this,iPivot+1,right,maxDepth-1)\n end subroutine\n !====================================================================!\n !====================================================================!\n module procedure argIntrosort_r1D\n !! Interfaced with argIntrosort()\n !====================================================================!\n integer(i32) :: left,right\n integer(i32) :: maxDepth\n left=1\n right=size(this)\n maxDepth=2*idnint(log(dble(right)))\n call r_argIntrosort_r1D(this,i,left,right,maxDepth)\n end procedure\n !====================================================================!\n !====================================================================!\n recursive subroutine r_argIntrosort_r1D(this,idx,left,right,maxDepth)\n !====================================================================!\n real(r32) :: this(:)\n integer(i32) :: idx(:)\n integer(i32) :: left,right\n integer(i32) :: maxDepth\n integer(i32) :: imid,iPivot\n integer(i32) :: N\n N=right-left + 1\n if (N < minimumLengthForInsertion) then\n call argInsertionSort(this,idx,left,right)\n return\n end if\n if (maxDepth == 0) then\n call argHeapsort_r1D(this, idx(left:right))\n return\n end if\n imid = left + N/2\n call argMedianOf3(this, idx, left, imid, right)\n call swap(idx(left), idx(imid))\n call argPartition(this,idx,left,right,iPivot)\n call r_argIntrosort_r1D(this,idx,left,iPivot-1,maxDepth-1)\n call r_argIntrosort_r1D(this,idx,iPivot+1,right,maxDepth-1)\n end subroutine\n !====================================================================!\n !====================================================================!\n module procedure argIntrosort_d1D\n !! Interfaced with argIntrosort()\n !====================================================================!\n integer(i32) :: left,right\n integer(i32) :: maxDepth\n left=1\n right=size(this)\n maxDepth=2*idnint(log(dble(right)))\n call r_argIntrosort_d1D(this,i,left,right,maxDepth)\n end procedure\n !====================================================================!\n !====================================================================!\n recursive subroutine r_argIntrosort_d1D(this,idx,left,right,maxDepth)\n !====================================================================!\n real(r64) :: this(:)\n integer(i32) :: idx(:)\n integer(i32) :: left,right\n integer(i32) :: maxDepth\n integer(i32) :: imid,iPivot\n integer(i32) :: N\n N = right - left + 1\n if (N < minimumLengthForInsertion) then\n call argInsertionSort(this,idx,left,right)\n return\n end if\n if (maxDepth == 0) then\n call argHeapsort_d1D(this, idx(left:right))\n return\n end if\n imid = left + N/2\n call argMedianOf3(this, idx, left, imid, right)\n call swap(idx(left), idx(imid))\n call argPartition(this,idx,left,right,iPivot)\n call r_argIntrosort_d1D(this,idx,left,iPivot-1,maxDepth-1)\n call r_argIntrosort_d1D(this,idx,iPivot+1,right,maxDepth-1)\n end subroutine\n !====================================================================!\n !====================================================================!\n module procedure argIntrosort_i1D\n !! Interfaced with argIntrosort()\n !====================================================================!\n integer(i32) :: left,right\n integer(i32) :: maxDepth\n left=1\n right=size(this)\n maxDepth=2*idnint(log(dble(right)))\n call r_argIntrosort_i1D(this,i,left,right,maxDepth)\n end procedure\n !====================================================================!\n !====================================================================!\n recursive subroutine r_argIntrosort_i1D(this,idx,left,right,maxDepth)\n !====================================================================!\n integer(i32) :: this(:)\n integer(i32) :: idx(:)\n integer(i32) :: left,right\n integer(i32) :: maxDepth\n integer(i32) :: imid,iPivot\n integer(i32) :: N\n N=right - left + 1\n if (N < minimumLengthForInsertion) then\n call argInsertionSort(this,idx,left,right)\n return\n end if\n if (maxDepth == 0) then\n call argHeapsort_i1D(this, idx(left:right))\n return\n end if\n imid = left + N/2\n call argMedianOf3(this, idx, left, imid, right)\n !call swap(idx(left), idx(imid))\n call argPartition(this,idx,left,right,iPivot)\n call r_argIntrosort_i1D(this,idx,left,iPivot-1,maxDepth-1)\n call r_argIntrosort_i1D(this,idx,iPivot+1,right,maxDepth-1)\n end subroutine\n !====================================================================!\n !====================================================================!\n module procedure argIntrosort_id1D\n !! Interfaced with argIntrosort()\n !====================================================================!\n integer(i32) :: left,right\n integer(i32) :: maxDepth\n left=1\n right=size(this)\n maxDepth=2*idnint(log(dble(right)))\n call r_argIntrosort_id1D(this,i,left,right,maxDepth)\n end procedure\n !====================================================================!\n !====================================================================!\n recursive subroutine r_argIntrosort_id1D(this,idx,left,right,maxDepth)\n !====================================================================!\n integer(i64) :: this(:)\n integer(i32) :: idx(:)\n integer(i32) :: left,right\n integer(i32) :: maxDepth\n integer(i32) :: imid,iPivot\n integer(i32) :: N\n N = right - left + 1\n if (N < minimumLengthForInsertion) then\n call argInsertionSort(this,idx,left,right)\n return\n end if\n if (maxDepth == 0) then\n call argHeapsort_id1D(this, idx(left:right))\n return\n end if\n imid = left + N/2\n call argMedianOf3(this, idx, left, imid, right)\n call swap(idx(left), idx(imid))\n call argPartition(this,idx,left,right,iPivot)\n call r_argIntrosort_id1D(this,idx,left,iPivot-1,maxDepth-1)\n call r_argIntrosort_id1D(this,idx,iPivot+1,right,maxDepth-1)\n end subroutine\n !====================================================================!\nend submodule\n", "meta": {"hexsha": "16b46dd5767eaf5ee6e3ae564aa3ce87f0da9db4", "size": 11628, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/sorting/sm_introSort.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/sorting/sm_introSort.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/sorting/sm_introSort.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": 37.1501597444, "max_line_length": 72, "alphanum_fraction": 0.493120055, "num_tokens": 2852, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737806, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.651787261144256}} {"text": "cc Copyright (C) 2004-2009: Leslie Greengard and June-Yub Lee \ncc Contact: greengard@cims.nyu.edu\ncc \ncc This program is free software; you can redistribute it and/or modify \ncc it under the terms of the GNU General Public License as published by \ncc the Free Software Foundation; either version 2 of the License, or \ncc (at your option) any later version. This program is distributed in \ncc the hope that it will be useful, but WITHOUT ANY WARRANTY; without \ncc even the implied warranty of MERCHANTABILITY or FITNESS FOR A \ncc PARTICULAR PURPOSE. See the GNU General Public License for more \ncc details. You should have received a copy of the GNU General Public \ncc License along with this program; \ncc if not, see .\nc\n program testfft\n implicit none\nc\nc --- local variables\nc\n integer i,ier,iflag,j,k1,mx,ms,nj\n parameter (mx=10 000)\n real(8):: xj(mx), sk(mx)\n real(8):: err,eps,pi\n parameter (pi=3.141592653589793d0)\n complex(8) :: cj(mx),cj0(mx),cj1(mx)\n complex(8) :: fk0(mx),fk1(mx)\nc\nc --------------------------------------------------\nc create some test data\nc --------------------------------------------------\n ms = 90\n nj = 128\n do k1 = -nj/2, (nj-1)/2\n j = k1+nj/2+1\n xj(j) = pi * dcos(-pi*j/nj)\n cj(j) = dcmplx( dsin(pi*j/nj), dcos(pi*j/nj))\n enddo\nc\nc --------------------------------------------------\nc start tests\nc --------------------------------------------------\nc\n iflag = 1\n print*,' Start 1D testing: ', ' nj =',nj, ' ms =',ms\n do i = 1,3\n if (i.eq.1) eps=1d-4\n if (i.eq.2) eps=1d-8\n if (i.eq.3) eps=1d-12\n print*,' '\n print*,' Requested precision eps =',eps\n print*,' '\nc\nc -----------------------\nc call 1D Type1 method\nc -----------------------\nc\n call dirft1d1(nj,xj,cj,iflag, ms,fk0)\n call nufft1d1f90(nj,xj,cj,iflag,eps, ms,fk1,ier)\n call errcomp(fk0,fk1,ms,err)\n print *,' ier = ',ier\n print *,' type 1 error = ',err\nc\nc -----------------------\nc call 1D Type2 method\nc -----------------------\nc\n call dirft1d2(nj,xj,cj0,iflag, ms,fk0,ier)\n call nufft1d2f90(nj,xj,cj1,iflag, eps, ms,fk0,ier)\n call errcomp(cj0,cj1,nj,err)\n print *,' ier = ',ier\n print *,' type 2 error = ',err\nc\nc -----------------------\nc call 1D Type3 method\nc -----------------------\n do k1 = 1, ms\n sk(k1) = 48d0*dcos(k1*pi/ms)\n enddo\n call dirft1d3(nj,xj,cj,iflag, ms,sk,fk0)\n call nufft1d3f90(nj,xj,cj,iflag,eps, ms,sk,fk1,ier)\n call errcomp(cj0,cj1,nj,err)\n print *,' ier = ',ier\n print *,' type 3 error = ',err\n enddo\n stop\n end\nc\nc\nc\nc\nc\n subroutine errcomp(fk0,fk1,n,err)\n implicit none\n integer k,n\n complex(8) :: fk0(n), fk1(n)\n real(8) :: salg,ealg,err\nc\n ealg = 0d0\n salg = 0d0\n do k = 1, n\n ealg = ealg + cdabs(fk1(k)-fk0(k))**2\n salg = salg + cdabs(fk0(k))**2\n enddo\n err =sqrt(ealg/salg)\n return\n end\n", "meta": {"hexsha": "cd77fd95353a6ed9b3a724b60a1fcfde404edd38", "size": 3194, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "external/nufft/nufft1d_demof90.f", "max_stars_repo_name": "utastudents/selalib", "max_stars_repo_head_hexsha": "84af43d0e82d4686a837c64384bbd173412df50e", "max_stars_repo_licenses": ["CECILL-B"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-03-11T15:22:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-22T16:26:18.000Z", "max_issues_repo_path": "external/nufft/nufft1d_demof90.f", "max_issues_repo_name": "utastudents/selalib", "max_issues_repo_head_hexsha": "84af43d0e82d4686a837c64384bbd173412df50e", "max_issues_repo_licenses": ["CECILL-B"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2021-06-30T20:39:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-15T12:42:50.000Z", "max_forks_repo_path": "external/nufft/nufft1d_demof90.f", "max_forks_repo_name": "utastudents/selalib", "max_forks_repo_head_hexsha": "84af43d0e82d4686a837c64384bbd173412df50e", "max_forks_repo_licenses": ["CECILL-B"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-03-13T17:09:10.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-22T00:30:19.000Z", "avg_line_length": 29.8504672897, "max_line_length": 72, "alphanum_fraction": 0.5090795241, "num_tokens": 1036, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737806, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.651787261144256}} {"text": "program newton\n\treal*8 a,b,t,dt\n\ta=0.0;b=3.0\n\tt=1.0;e=0.01\n\tdt=1.0\n\t\n\topen(13,file=\"Newton\")\n\twrite(13,\"(A12,A12)\")\"t-t0\",\"t\"\n\tdo while(dt>=e)\n\t\tdt=(((3*t**2-2)/(6*t))**2)**0.5\n\t\tt=t-(3*t**2-2)/(6*t)\n\t\twrite(13,\"(f12.6,f12.6)\")dt,t\n\tend do\n\twrite(13,*)t,t**3-2*t+1,e\nend program newton\n", "meta": {"hexsha": "9ad8172ba40aa0202f6eaa84f3461f092f8045bd", "size": 286, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Newtonqiexian.f90", "max_stars_repo_name": "DearDon/Optimization", "max_stars_repo_head_hexsha": "f22a95bc1317aff69664516c495d94831dabce51", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Newtonqiexian.f90", "max_issues_repo_name": "DearDon/Optimization", "max_issues_repo_head_hexsha": "f22a95bc1317aff69664516c495d94831dabce51", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Newtonqiexian.f90", "max_forks_repo_name": "DearDon/Optimization", "max_forks_repo_head_hexsha": "f22a95bc1317aff69664516c495d94831dabce51", "max_forks_repo_licenses": ["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.875, "max_line_length": 33, "alphanum_fraction": 0.541958042, "num_tokens": 149, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916064586998, "lm_q2_score": 0.7549149758396752, "lm_q1q2_score": 0.6517872537299477}} {"text": "\n SUBROUTINE RENPAR6(A,N,K,M)\n INTEGER N,K,M,A(N)\n DIMENSION WORK(100,100)\n K = M * M\n DO I = 1,N\n DO J = 1,N\n WORK(J,K) = J + K\n ENDDO\n\n CALL INC1(K)\n\n DO J = 1,N\n WORK(J,K) = J * J - K * K\n A(I) = A(I) + WORK(J,K) + WORK(J,K-1)\n ENDDO\n ENDDO\n END\n\n \n SUBROUTINE INC1(I)\n I = I + 1\n END\n\n\n SUBROUTINE RENPAR6_2(A,N,K,M)\n INTEGER N,K,M,A(N)\n DIMENSION WORK(100,100)\n K0 = M * M\n DO I = 1,N\n K = K0+I-1\n DO J = 1,N\n WORK(J,K) = J + K\n ENDDO\n\n CALL INC1(K)\n\n DO J = 1,N\n WORK(J,K) = J * J - K * K\n A(I) = A(I) + WORK(J,K) + WORK(J,K-1)\n ENDDO\n ENDDO\n END\n\n \n\n", "meta": {"hexsha": "776ce7600840bbd62fd6ed9da87da9c8b533ded8", "size": 806, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "packages/PIPS/validation/Demo/SC95.sub/renpar6.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/Demo/SC95.sub/renpar6.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/Demo/SC95.sub/renpar6.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": 17.1489361702, "max_line_length": 49, "alphanum_fraction": 0.3635235732, "num_tokens": 293, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619263765707, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.6517621473551121}} {"text": " program power04\n\nC Check constant power\n\n i = 3**2\n n = 2\n i = 4**n\n m = 3\n i = m**3\n i = n**m\n\n print *, i\n\n end\n", "meta": {"hexsha": "d11b4bcca626a21983e2e985adb6d41ee035d0d2", "size": 164, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "packages/PIPS/validation/Semantics/power04.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/Semantics/power04.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/Semantics/power04.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": 10.9333333333, "max_line_length": 26, "alphanum_fraction": 0.3536585366, "num_tokens": 61, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.7905303087996143, "lm_q2_score": 0.8244619263765706, "lm_q1q2_score": 0.6517621412519952}} {"text": "program main\n\n use bml\n\n implicit none\n integer, parameter :: dp = kind(1.0d0)\n type(bml_matrix_t) :: hmat_bml\n real(dp), allocatable :: H(:,:)\n character(20) :: bml_type\n real(dp) :: numthresh\n integer :: i,j,hdim,mdim\n\n\n write(*,*)''\n write(*,*)'Example Fortran BML 1: Read a dense matrix form file, convert to bml_ellpack'\n write(*,*)'; get bml parameters N,M and type; and print the bml matrix'\n write(*,*)''\n\n open(1,file='hamiltonian.dat')\n read(1,*)hdim\n mdim = hdim/2\n bml_type = \"ellpack\"\n numthresh = 0.05_dp\n\n allocate(H(hdim,hdim))\n\n H=0.0_dp\n\n do i=1,hdim\n do j=1,hdim\n read(1,*)H(i,j)\n enddo\n enddo\n\n call bml_zero_matrix(bml_type,bml_element_real,dp,hdim,mdim,hmat_bml)\n\n call bml_convert_from_dense(bml_type,H,hmat_bml,numthresh,mdim)\n\n write(*,*)''\n write(*,*)\"bml_type = \", bml_get_type(hmat_bml)\n write(*,*)\"N = \", bml_get_N(hmat_bml)\n write(*,*)\"M = \", bml_get_M(hmat_bml)\n write(*,*)''\n\n !The printing routine starts from 0.\n call bml_print_matrix(\"hmat_bml\",hmat_bml,0,6,0,6)\n\nend program main\n", "meta": {"hexsha": "b52c958b796e3143d0ae8e30e74e822c17e8d501", "size": 1061, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/example1/main.f90", "max_stars_repo_name": "mikiec84/bml", "max_stars_repo_head_hexsha": "b26c6902dd79785edc2008ff4d054ea288037469", "max_stars_repo_licenses": ["Unlicense", "BSD-3-Clause"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2017-11-10T02:20:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T07:10:53.000Z", "max_issues_repo_path": "examples/example1/main.f90", "max_issues_repo_name": "mikiec84/bml", "max_issues_repo_head_hexsha": "b26c6902dd79785edc2008ff4d054ea288037469", "max_issues_repo_licenses": ["Unlicense", "BSD-3-Clause"], "max_issues_count": 408, "max_issues_repo_issues_event_min_datetime": "2017-07-27T05:01:47.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-23T23:03:02.000Z", "max_forks_repo_path": "examples/example1/main.f90", "max_forks_repo_name": "mikiec84/bml", "max_forks_repo_head_hexsha": "b26c6902dd79785edc2008ff4d054ea288037469", "max_forks_repo_licenses": ["Unlicense", "BSD-3-Clause"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2017-06-21T20:38:32.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T07:10:51.000Z", "avg_line_length": 21.6530612245, "max_line_length": 90, "alphanum_fraction": 0.6522148916, "num_tokens": 393, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8244619177503205, "lm_q2_score": 0.7905303112671295, "lm_q1q2_score": 0.6517621364670554}} {"text": "RECURSIVE FUNCTION prtrng(q, v, r) RESULT(prob)\r\n\r\n! N.B. Argument IFAULT has been removed.\r\n\r\n! Code converted using TO_F90 by Alan Miller\r\n! Date: 1999-04-02 Time: 20:07:46\r\n\r\nIMPLICIT NONE\r\nINTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(14, 60)\r\n\r\nREAL (dp), INTENT(IN) :: q\r\nREAL (dp), INTENT(IN) :: v\r\nREAL (dp), INTENT(IN) :: r\r\nREAL (dp) :: prob\r\n\r\n! Algorithm AS 190 Appl. Statist. (1983) Vol.32, No. 2\r\n\r\n! Evaluates the probability from 0 to q for a studentized range\r\n! having v degrees of freedom and r samples.\r\n\r\n! Uses subroutine ALNORM = algorithm AS66.\r\n\r\n! Arrays vw and qw store transient values used in the quadrature\r\n! summation. Node spacing is controlled by step. pcutj and pcutk control\r\n! truncation. Minimum and maximum number of steps are controlled by\r\n! jmin, jmax, kmin and kmax. Accuracy can be increased by use of a finer\r\n! grid - Increase sizes of arrays vw and qw, and jmin, jmax, kmin, kmax and\r\n! 1/step proportionally.\r\n\r\nREAL (dp) :: vw(30), qw(30)\r\nREAL (dp) :: g, gmid, r1, c, h, v2, gstep, pk1, pk2, gk, pk\r\nREAL (dp) :: w0, pz, x, hj, ehj, pj\r\nINTEGER :: ifault, j, jj, jump, k\r\nREAL (dp), PARAMETER :: pcutj = 0.00003_dp, pcutk = 0.0001_dp, step = 0.45_dp, &\r\n vmax = 120.0_dp, zero = 0.0_dp, fifth = 0.2_dp, &\r\n half = 0.5_dp, one = 1.0_dp, two = 2.0_dp, &\r\n cv1 = 0.193064705_dp, cv2 = 0.293525326_dp, &\r\n cvmax = 0.39894228_dp, cv(4) = (/ 0.318309886_dp, &\r\n -0.268132716D-2, 0.347222222D-2, 0.833333333D-1 /)\r\nINTEGER, PARAMETER :: jmin = 3, jmax = 15, kmin = 7, kmax = 15\r\n\r\n! Check initial values\r\n\r\nprob = zero\r\nifault = 0\r\nIF (v < one .OR. r < two) ifault = 1\r\nIF (q <= zero .OR. ifault == 1) GO TO 99\r\n\r\n! Computing constants, local midpoint, adjusting steps.\r\n\r\ng = step * r ** (-fifth)\r\ngmid = half * LOG(r)\r\nr1 = r - one\r\nc = LOG(r * g * cvmax)\r\nIF(v > vmax) GO TO 20\r\n\r\nh = step * v ** (-half)\r\nv2 = v * half\r\nIF (v == one) c = cv1\r\nIF (v == two) c = cv2\r\nIF (.NOT. (v == one .OR. v == two)) c = SQRT(v2) &\r\n * cv(1) / (one + ((cv(2) / v2 + cv(3)) / v2 + cv(4)) / v2)\r\nc = LOG(c * r * g * h)\r\n\r\n! Computing integral\r\n! Given a row k, the procedure starts at the midpoint and works\r\n! outward (index j) in calculating the probability at nodes\r\n! symmetric about the midpoint. The rows (index k) are also\r\n! processed outwards symmetrically about the midpoint. The\r\n! centre row is unpaired.\r\n\r\n20 gstep = g\r\nqw(1) = -one\r\nqw(jmax + 1) = -one\r\npk1 = one\r\npk2 = one\r\nDO k = 1, kmax\r\n gstep = gstep - g\r\n 21 gstep = -gstep\r\n gk = gmid + gstep\r\n pk = zero\r\n IF (pk2 <= pcutk .AND. k > kmin) GO TO 26\r\n w0 = c - gk * gk * half\r\n pz = alnorm(gk, .true.)\r\n x = alnorm(gk - q, .true.) - pz\r\n IF (x > zero) pk = EXP(w0 + r1 * LOG(x))\r\n IF (v > vmax) GO TO 26\r\n \r\n jump = -jmax\r\n 22 jump = jump + jmax\r\n DO j = 1, jmax\r\n jj = j + jump\r\n IF (qw(jj) > zero) GO TO 23\r\n hj = h * j\r\n IF (j < jmax) qw(jj + 1) = -one\r\n ehj = EXP(hj)\r\n qw(jj) = q * ehj\r\n vw(jj) = v * (hj + half - ehj * ehj * half)\r\n \r\n 23 pj = zero\r\n x = alnorm(gk - qw(jj), .true.) - pz\r\n IF (x > zero) pj = EXP(w0 + vw(jj) + r1 * LOG(x))\r\n pk = pk + pj\r\n IF (pj > pcutj) CYCLE\r\n IF (jj > jmin .OR. k > kmin) EXIT\r\n END DO\r\n h = -h\r\n IF (h < zero) GO TO 22\r\n \r\n 26 prob = prob + pk\r\n IF (k > kmin .AND. pk <= pcutk .AND. pk1 <= pcutk) GO TO 99\r\n pk2 = pk1\r\n pk1 = pk\r\n IF (gstep > zero) GO TO 21\r\nEND DO\r\n\r\n99 IF (ifault /= 0) WRITE(*, '(a, i3)') ' IFAULT = ', ifault\r\nRETURN\r\n\r\nCONTAINS\r\n\r\n\r\nFUNCTION qtrng(p, v, r) RESULT(quantile)\r\n\r\n! N.B. Argument IFAULT has been removed.\r\n\r\nREAL (dp), INTENT(IN) :: p\r\nREAL (dp), INTENT(IN) :: v\r\nREAL (dp), INTENT(IN) :: r\r\nREAL (dp) :: quantile\r\n\r\n! Algorithm AS 190.1 Appl. Statist. (1983) Vol.32, No. 2\r\n\r\n! Approximates the quantile p for a studentized range distribution\r\n! having v degrees of freedom and r samples for probability 0.9 < p < 0.99.\r\n\r\n! Uses functions alnorm, ppnd, prtrng and qtrng0 -\r\n! Algorithms AS 66, AS 241, AS 190 and AS 190.2\r\n\r\nREAL (dp) :: q1, p1, q2, p2, d, e1, e2\r\nINTEGER :: ifault, j, nfault\r\nINTEGER, PARAMETER :: jmax = 8\r\nREAL (dp), PARAMETER :: pcut = 0.001_dp, p75 = 0.75_dp, p80 = 0.80_dp, &\r\n p90 = 0.9_dp, p99 = 0.99_dp, p995 = 0.995_dp, &\r\n p175 = 1.75_dp, one = 1.0_dp, two = 2.0_dp, &\r\n five = 5.0_dp, eps = 1.0D-04\r\n\r\n! Check input parameters\r\n\r\nifault = 0\r\nnfault = 0\r\nIF (v < one .OR. r < two) ifault = 1\r\nIF (p < p90 .OR. p > p99) ifault = 2\r\nIF (ifault /= 0) GO TO 99\r\n\r\n! Obtain initial values\r\n\r\nq1 = qtrng0(p, v, r)\r\np1 = prtrng(q1, v, r)\r\nIF (nfault /= 0) GO TO 99\r\nquantile = q1\r\nIF (ABS(p1-p) < pcut) GO TO 99\r\nIF (p1 > p) p1 = p175 * p - p75 * p1\r\nIF (p1 < p) p2 = p + (p - p1) * (one - p) / (one - p1) * p75\r\nIF (p2 < p80) p2 = p80\r\nIF (p2 > p995) p2 = p995\r\nq2 = qtrng0(p2, v, r)\r\nIF (nfault /= 0) GO TO 99\r\n\r\n! Refine approximation\r\n\r\nDO j = 2, jmax\r\n p2 = prtrng(q2, v, r)\r\n IF (nfault /= 0) GO TO 99\r\n e1 = p1 - p\r\n e2 = p2 - p\r\n quantile = (q1 + q2) / two\r\n d = e2 - e1\r\n IF (ABS(d) > eps) quantile = (e2 * q1 - e1 * q2) / d\r\n IF(ABS(e1) < ABS(e2)) GO TO 12\r\n q1 = q2\r\n p1 = p2\r\n 12 IF (ABS(p1 - p) < pcut * five) GO TO 99\r\n q2 = quantile\r\nEND DO\r\n\r\n99 IF (nfault /= 0) ifault = 9\r\nIF (ifault /= 0) WRITE(*, '(a, i4, a)') ' IFAULT = ', ifault, ' from QTRNG'\r\nRETURN\r\nEND FUNCTION qtrng\r\n\r\n\r\n\r\nFUNCTION qtrng0(p, v, r) RESULT(initq)\r\n\r\n! N.B. Argument IFAULT has been removed.\r\n\r\nREAL (dp), INTENT(IN) :: p\r\nREAL (dp), INTENT(IN) :: v\r\nREAL (dp), INTENT(IN) :: r\r\nREAL (dp) :: initq\r\n\r\n! Algorithm AS 190.2 Appl. Statist. (1983) Vol.32, No.2\r\n\r\n! Calculates an initial quantile p for a studentized range distribution\r\n! having v degrees of freedom and r samples for probability p, 0.8 < p < 0.995\r\n\r\n! Uses function ppnd - Algorithm AS 241\r\n\r\nINTEGER :: ifault\r\nREAL (dp) :: q, t\r\nREAL (dp), PARAMETER :: vmax = 120.0_dp, half = 0.5_dp, one = 1.0_dp, &\r\n four = 4.0_dp, c1 = 0.8843_dp, c2 = 0.2368_dp, &\r\n c3 = 1.214_dp, c4 = 1.208_dp, c5 = 1.4142_dp\r\n\r\nCALL ppnd16(half + half * p, t, ifault)\r\nIF (v < vmax) t = t + (t * t* t + t) / v / four\r\nq = c1 - c2 * t\r\nIF (v < vmax) q = q - c3 / v + c4 * t / v\r\ninitq = t * (q * LOG(r - one) + c5)\r\n\r\nRETURN\r\nEND FUNCTION qtrng0\r\n\r\n\r\n\r\nFUNCTION alnorm(x, upper) RESULT(fn_val)\r\n\r\n! Algorithm AS66 Applied Statistics (1973) vol.22, no.3\r\n\r\n! Evaluates the tail area of the standardised normal curve\r\n! from x to infinity if upper is .true. or\r\n! from minus infinity to x if upper is .false.\r\n\r\n! ELF90-compatible version by Alan Miller\r\n! Latest revision - 29 November 1997\r\n\r\nREAL (dp), INTENT(IN) :: x\r\nLOGICAL, INTENT(IN) :: upper\r\nREAL (dp) :: fn_val\r\n\r\n! Local variables\r\nREAL (dp), PARAMETER :: zero = 0.0_dp, one = 1.0_dp, half = 0.5_dp, &\r\n con = 1.28_dp\r\nREAL (dp) :: z, y\r\nLOGICAL :: up\r\n\r\n!*** machine dependent constants\r\nREAL (dp), PARAMETER :: ltone = 7.0_dp, utzero = 18.66_dp\r\n\r\nREAL (dp), PARAMETER :: p = 0.398942280444_dp, q = 0.39990348504_dp, &\r\n r = 0.398942280385_dp, a1 = 5.75885480458_dp, &\r\n a2 = 2.62433121679_dp, a3 = 5.92885724438_dp, &\r\n b1 = -29.8213557807_dp, b2 = 48.6959930692_dp, &\r\n c1 = -3.8052E-8_dp, c2 = 3.98064794E-4_dp, &\r\n c3 = -0.151679116635_dp, c4 = 4.8385912808_dp, &\r\n c5 = 0.742380924027_dp, c6 = 3.99019417011_dp, &\r\n d1 = 1.00000615302_dp, d2 = 1.98615381364_dp, &\r\n d3 = 5.29330324926_dp, d4 = -15.1508972451_dp, &\r\n d5 = 30.789933034_dp\r\n\r\nup = upper\r\nz = x\r\nIF(z >= zero) GO TO 10\r\nup = .NOT. up\r\nz = -z\r\n10 IF(z <= ltone .OR. up .AND. z <= utzero) GO TO 20\r\nfn_val = zero\r\nGO TO 40\r\n20 y = half*z*z\r\nIF(z > con) GO TO 30\r\n\r\nfn_val = half - z*(p-q*y/(y+a1+b1/(y+a2+b2/(y+a3))))\r\nGO TO 40\r\n30 fn_val = r*EXP(-y)/(z+c1+d1/(z+c2+d2/(z+c3+d3/(z+c4+d4/(z+c5+d5/(z+c6))))))\r\n40 IF(.NOT. up) fn_val = one - fn_val\r\n\r\nRETURN\r\nEND FUNCTION alnorm\r\n\r\n\r\n\r\nSUBROUTINE ppnd16 (p, normal_dev, ifault)\r\n\r\n! ALGORITHM AS241 APPL. STATIST. (1988) VOL. 37, NO. 3\r\n\r\n! Produces the normal deviate Z corresponding to a given lower\r\n! tail area of P; Z is accurate to about 1 part in 10**16.\r\n\r\n! The hash sums below are the sums of the mantissas of the\r\n! coefficients. They are included for use in checking\r\n! transcription.\r\n\r\n! This ELF90-compatible version by Alan Miller - 20 August 1996\r\n! N.B. The original algorithm is as a function; this is a subroutine\r\n\r\nREAL (dp), INTENT(IN) :: p\r\nINTEGER, INTENT(OUT) :: ifault\r\nREAL (dp), INTENT(OUT) :: normal_dev\r\n\r\n! Local variables\r\n\r\nREAL (dp) :: zero = 0.d0, one = 1.d0, half = 0.5d0, split1 = 0.425d0, &\r\n split2 = 5.d0, const1 = 0.180625d0, const2 = 1.6d0, q, r\r\n\r\n! Coefficients for P close to 0.5\r\n\r\nREAL (dp) :: a0 = 3.3871328727963666080D0, &\r\n a1 = 1.3314166789178437745D+2, &\r\n a2 = 1.9715909503065514427D+3, &\r\n a3 = 1.3731693765509461125D+4, &\r\n a4 = 4.5921953931549871457D+4, &\r\n a5 = 6.7265770927008700853D+4, &\r\n a6 = 3.3430575583588128105D+4, &\r\n a7 = 2.5090809287301226727D+3, &\r\n b1 = 4.2313330701600911252D+1, &\r\n b2 = 6.8718700749205790830D+2, &\r\n b3 = 5.3941960214247511077D+3, &\r\n b4 = 2.1213794301586595867D+4, &\r\n b5 = 3.9307895800092710610D+4, &\r\n b6 = 2.8729085735721942674D+4, &\r\n b7 = 5.2264952788528545610D+3\r\n! HASH SUM AB 55.8831928806149014439\r\n\r\n! Coefficients for P not close to 0, 0.5 or 1.\r\n\r\nREAL (dp) :: c0 = 1.42343711074968357734D0, &\r\n c1 = 4.63033784615654529590D0, &\r\n c2 = 5.76949722146069140550D0, &\r\n c3 = 3.64784832476320460504D0, &\r\n c4 = 1.27045825245236838258D0, &\r\n c5 = 2.41780725177450611770D-1, &\r\n c6 = 2.27238449892691845833D-2, &\r\n c7 = 7.74545014278341407640D-4, &\r\n d1 = 2.05319162663775882187D0, &\r\n d2 = 1.67638483018380384940D0, &\r\n d3 = 6.89767334985100004550D-1, &\r\n d4 = 1.48103976427480074590D-1, &\r\n d5 = 1.51986665636164571966D-2, &\r\n d6 = 5.47593808499534494600D-4, &\r\n d7 = 1.05075007164441684324D-9\r\n! HASH SUM CD 49.33206503301610289036\r\n\r\n! Coefficients for P near 0 or 1.\r\n\r\nREAL (dp) :: e0 = 6.65790464350110377720D0, &\r\n e1 = 5.46378491116411436990D0, &\r\n e2 = 1.78482653991729133580D0, &\r\n e3 = 2.96560571828504891230D-1, &\r\n e4 = 2.65321895265761230930D-2, &\r\n e5 = 1.24266094738807843860D-3, &\r\n e6 = 2.71155556874348757815D-5, &\r\n e7 = 2.01033439929228813265D-7, &\r\n f1 = 5.99832206555887937690D-1, &\r\n f2 = 1.36929880922735805310D-1, &\r\n f3 = 1.48753612908506148525D-2, &\r\n f4 = 7.86869131145613259100D-4, &\r\n f5 = 1.84631831751005468180D-5, &\r\n f6 = 1.42151175831644588870D-7, &\r\n f7 = 2.04426310338993978564D-15\r\n! HASH SUM EF 47.52583317549289671629\r\n\r\nifault = 0\r\nq = p - half\r\nIF (ABS(q) <= split1) THEN\r\n r = const1 - q * q\r\n normal_dev = q * (((((((a7*r + a6)*r + a5)*r + a4)*r + a3)*r + a2)*r + a1)*r + a0) / &\r\n (((((((b7*r + b6)*r + b5)*r + b4)*r + b3)*r + b2)*r + b1)*r + one)\r\n RETURN\r\nELSE\r\n IF (q < zero) THEN\r\n r = p\r\n ELSE\r\n r = one - p\r\n END IF\r\n IF (r <= zero) THEN\r\n ifault = 1\r\n normal_dev = zero\r\n RETURN\r\n END IF\r\n r = SQRT(-LOG(r))\r\n IF (r <= split2) THEN\r\n r = r - const2\r\n normal_dev = (((((((c7*r + c6)*r + c5)*r + c4)*r + c3)*r + c2)*r + c1)*r + c0) / &\r\n (((((((d7*r + d6)*r + d5)*r + d4)*r + d3)*r + d2)*r + d1)*r + one)\r\n ELSE\r\n r = r - split2\r\n normal_dev = (((((((e7*r + e6)*r + e5)*r + e4)*r + e3)*r + e2)*r + e1)*r + e0) / &\r\n (((((((f7*r + f6)*r + f5)*r + f4)*r + f3)*r + f2)*r + f1)*r + one)\r\n END IF\r\n IF (q < zero) normal_dev = - normal_dev\r\n RETURN\r\nEND IF\r\nRETURN\r\nEND SUBROUTINE ppnd16\r\n\r\nEND FUNCTION prtrng\r\n", "meta": {"hexsha": "0c0660b579cd0dd446157211ad47e47d3b734b78", "size": 12561, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/amil/as190.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/as190.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/as190.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": 31.5603015075, "max_line_length": 89, "alphanum_fraction": 0.5412785606, "num_tokens": 4903, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636754, "lm_q2_score": 0.7248702880639791, "lm_q1q2_score": 0.6517463678273024}} {"text": "!********************************************************************************\n! NAN_INF: Test FPML ability to avoid overflow/underflow and produce meaningful results.\n! Author: Thomas R. Cameron, Davidson College\n! Last Modified: 16 May 2019\n!********************************************************************************\n! The speed and accuracy of FPML is compared against Polzeros and AMVW for\n! computing the roots of the polynomial sum(i+1)x^i.\n!********************************************************************************\nprogram nan_inf\n use fpml\n implicit none\n ! testing variables\n integer :: deg, j, k\n real(kind=dp) :: a, r\n real(kind=dp), parameter :: pi2 = 6.2831853071795864769_dp\n complex(kind=dp), allocatable :: exact_roots(:)\n ! FPML variables\n integer, parameter :: nitmax = 30\n integer, allocatable :: conv(:)\n real(kind=dp), allocatable :: berr(:), cond(:)\n complex(kind=dp), allocatable :: p(:), roots(:)\n\n ! Test 1: p(z) = -a^-1 + az^deg, a = 2.0_dp**(deg)\n\twrite(*,'(A)') 'Test 1: '\n open(unit=1,file=\"data_files/nan_inf1.dat\")\n write(1,'(A)') 'deg, relative forward error, backward error, condition number'\n do deg=1012,1013\n write(1,'(I10,A)',advance='no') deg, ', '\n ! allocate\n allocate(exact_roots(deg), conv(deg), berr(deg), cond(deg), p(deg+1), roots(deg))\n ! polynomial and roots\n a = 2.0_dp**(deg)\n r = 2.0_dp**(-2)\n exact_roots = (/ (r*cmplx(cos(pi2*k/real(deg,kind=dp)),sin(pi2*k/real(deg,kind=dp)),kind=dp), k=1,deg)/)\n p = cmplx(0,0,kind=dp)\n p(1) = cmplx(-a**(-1),0,kind=dp)\n p(deg+1) = cmplx(a,0,kind=dp)\n ! fpml\n call main(p, deg, roots, berr, cond, conv, nitmax)\n ! relative forward error, backward error, and condition number\n write(1,'(ES15.2,ES15.2,ES15.2)') max_rel_err(roots, exact_roots, deg), maxval(berr), maxval(cond)\n ! deallocate\n deallocate(exact_roots, conv, berr, cond, p, roots)\n end do\n ! close file\n close(1)\n\n ! Test 2: p(z) = 0 + 0z + ... + -a^(-1)z^10 + az^11, a = 2.0_dp**(j)\n\twrite(*,'(A)') 'Test 2: '\n open(unit=1,file=\"data_files/nan_inf2.dat\")\n write(1,'(A)') 'power, relative forward error, backward error, condition number'\n deg = 11\n do j=1012,1013\n write(1,'(I10,A)',advance='no') j, ', '\n ! allocate\n allocate(exact_roots(deg), conv(deg), berr(deg), cond(deg), p(deg+1), roots(deg))\n ! polynomial and roots\n a = 2.0_dp**(j)\n r = 2.0_dp**(-2.0_dp*j)\n exact_roots(1:deg-1) = 0.0_dp\n exact_roots(deg) = r\n p(1:deg-1) = cmplx(0,0,kind=dp)\n p(deg) = cmplx(-a**(-1),0,kind=dp)\n p(deg+1) = cmplx(a,0,kind=dp)\n ! fpml\n call main(p, deg, roots, berr, cond, conv, nitmax)\n ! relative forward error, backward error, and condition number\n write(1,'(ES15.2,ES15.2,ES15.2)') max_rel_err(roots, exact_roots, deg), maxval(berr), maxval(cond)\n ! deallocate\n deallocate(exact_roots, conv, berr, cond, p, roots)\n end do\n ! close file\n close(1)\n \n ! Test 3: p(z) = -a+a^(-1)z^deg, a = 2.0_dp**(deg)\n\twrite(*,'(A)') 'Test 3: '\n open(unit=1,file=\"data_files/nan_inf3.dat\")\n write(1,'(A)') 'deg, relative forward error, backward error, condition number'\n do deg=1012,1013\n write(1,'(I10,A)',advance='no') deg, ', '\n ! allocate\n allocate(exact_roots(deg), conv(deg), berr(deg), cond(deg), p(deg+1), roots(deg))\n ! polynomial and roots\n a = 2.0_dp**(deg)\n r = 2.0_dp**(2)\n exact_roots = (/ (r*cmplx(cos(pi2*k/real(deg,kind=dp)),sin(pi2*k/real(deg,kind=dp)),kind=dp), k=1,deg)/)\n p = cmplx(0,0,kind=dp)\n p(1) = cmplx(-a,0,kind=dp)\n p(deg+1) = cmplx(a**(-1),0,kind=dp)\n ! fpml\n call main(p, deg, roots, berr, cond, conv, nitmax)\n ! relative forward error, backward error, and condition number\n write(1,'(ES15.2,ES15.2,ES15.2)') max_rel_err(roots, exact_roots, deg), maxval(berr), maxval(cond)\n ! deallocate\n deallocate(exact_roots, conv, berr, cond, p, roots)\n end do\n ! close file\n close(1)\n \n ! Test 4: p(z) = 0 + 0z + ... + -az^10 + a^(-1)z^11, a = 2.0_dp**(j)\n\twrite(*,'(A)') 'Test 4: '\n open(unit=1,file=\"data_files/nan_inf4.dat\")\n write(1,'(A)') 'power, relative forward error, backward error, condition number'\n deg = 11\n do j=1012,1013\n write(1,'(I10,A)',advance='no') j, ', '\n ! allocate\n allocate(exact_roots(deg), conv(deg), berr(deg), cond(deg), p(deg+1), roots(deg))\n ! polynomial and roots\n a = 2.0_dp**(j)\n r = 2.0_dp**(2.0_dp*j)\n exact_roots(1:deg-1) = 0.0_dp\n exact_roots(deg) = r\n p(1:deg-1) = cmplx(0,0,kind=dp)\n p(deg) = cmplx(-a,0,kind=dp)\n p(deg+1) = cmplx(a**(-1),0,kind=dp)\n ! fpml\n call main(p, deg, roots, berr, cond, conv, nitmax)\n ! relative forward error, backward error, and condition number\n write(1,'(ES15.2,ES15.2,ES15.2)') max_rel_err(roots, exact_roots, deg), maxval(berr), maxval(cond)\n ! deallocate\n deallocate(exact_roots, conv, berr, cond, p, roots)\n end do\n ! close file\n close(1)\n \n ! Test 5: 0 + 1z + ... + 9z^9 - a^(-1)z^10 + az^11, a = 2.0_dp**(j)\n\twrite(*,'(A)') 'Test 5: '\n open(unit=1,file=\"data_files/nan_inf5.dat\")\n write(1,'(A)') 'power, backward error, condition number'\n deg = 11\n do j=1012,1013\n write(1,'(I10,A)',advance='no') j, ', '\n ! allocate\n allocate(conv(deg), berr(deg), cond(deg), p(deg+1), roots(deg))\n ! polynomial and roots\n a = 2.0_dp**(j)\n p(1:deg-1) = (/ (cmplx(k,0,kind=dp), k=0,deg-2) /)\n p(deg) = cmplx(-a**(-1),0,kind=dp)\n p(deg+1) = cmplx(a,0,kind=dp)\n ! fpml\n call main(p, deg, roots, berr, cond, conv, nitmax)\n ! relative forward error, backward error, and condition number\n write(1,'(ES15.2,ES15.2)') maxval(berr), maxval(cond)\n ! deallocate\n deallocate(conv, berr, cond, p, roots)\n end do\n ! close file\n close(1)\n \n ! Test 6: 0 + 1z + ... + 9z^9 - az^10 + a(-1)z^11, a = 2.0_dp**(j)\n\twrite(*,'(A)') 'Test 6: '\n open(unit=1,file=\"data_files/nan_inf6.dat\")\n write(1,'(A)') 'power, backward error, condition number'\n deg = 11\n do j=1012,1013\n write(1,'(I10,A)',advance='no') j, ', '\n ! allocate\n allocate(conv(deg), berr(deg), cond(deg), p(deg+1), roots(deg))\n ! polynomial and roots\n a = 2.0_dp**(j)\n p(1:deg-1) = (/ (cmplx(k,0,kind=dp), k=0,deg-2) /)\n p(deg) = cmplx(-a,0,kind=dp)\n p(deg+1) = cmplx(a**(-1),0,kind=dp)\n ! fpml\n call main(p, deg, roots, berr, cond, conv, nitmax)\n ! relative forward error, backward error, and condition number\n write(1,'(ES15.2,ES15.2)') maxval(berr), maxval(cond)\n ! deallocate\n deallocate(conv, berr, cond, p, roots)\n end do\n ! close file\n close(1)\n \ncontains\n\n !************************************************\n ! max_rel_err *\n !************************************************\n ! Compute maximum relative error between roots\n ! and exact roots.\n !************************************************\n function max_rel_err(roots, exact_roots, deg) result(res)\n implicit none\n ! argument variables\n integer, intent(in) :: deg\n complex(kind=dp), intent(in) :: exact_roots(:), roots(:)\n ! local variables\n logical :: m(deg)\n integer :: i, j, k\n real(kind=dp) :: delta, err, res, relerr, rmax\n ! intrinsic procedures\n intrinsic :: abs, max, huge\n\n ! initialize\n m = .True.\n rmax = huge(1.0_dp)\n res = eps\n ! main loop\n do i=1,deg\n ! find corresponding exact root (yet to be matched)\n err = rmax\n do j=1,deg\n if(m(j)) then\n delta = abs(exact_roots(j) - roots(i))\n if(delta < err) then\n err = delta\n k = j\n end if\n end if\n end do\n ! mark corresponding root as matched\n m(k) = .False.\n ! calculate relative error on this root and update max\n ! zero roots give unhelpful relative errors, so revert to absolute error\n if(abs(roots(i))>>>>>> CRS format\n solver%x=0.0d0\n call time%start()\n call solver%convertCOOtoCRS(OpenMP=false)\n call time%show()\n call bicgstab_CRS(solver%val, solver%CRS_index_I, solver%index_J, &\n solver%x, solver%b, solver%itrmax, solver%er0)\n call time%show()\n print *,\"CRS\", norm(solver%x)\nelse\n !>>>>>>> COO format\n solver%x=0.0d0\n call time%start()\n call bicgstab_COO(solver%val, solver%index_I, solver%index_J, &\n solver%x, solver%b, solver%itrmax, solver%er0)\n call time%show()\n print *,\"COO\", norm(solver%x)\nendif\n\n\n\ncall mpid%end()\n\nend", "meta": {"hexsha": "94b9a47566e48d2294bd5ce615579542e9487b64", "size": 2629, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/std/convertCOOtoCRS_LinearSolver.f90", "max_stars_repo_name": "kazulagi/plantFEM", "max_stars_repo_head_hexsha": "20bf2df8202d41aa5dc25d1cc820385dabbc604f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2020-06-21T08:21:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-13T04:28:30.000Z", "max_issues_repo_path": "Tutorial/std/convertCOOtoCRS_LinearSolver.f90", "max_issues_repo_name": "kazulagi/plantFEM_binary", "max_issues_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-05-08T05:20:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T05:39:29.000Z", "max_forks_repo_path": "Tutorial/std/convertCOOtoCRS_LinearSolver.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": 21.032, "max_line_length": 71, "alphanum_fraction": 0.5926207684, "num_tokens": 928, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392695254319, "lm_q2_score": 0.7371581568543044, "lm_q1q2_score": 0.651676758510193}} {"text": "module points_in_poly_mod\n !\n !! Module to find whether points are inside (or on the boundary of) a polygon\n !\n !! The tests suggest being on the boundary is counted as being inside, although\n !! I would not rely on that behaviour always being true for complex polygons.\n !!\n !! Main routine is \n !! points_in_poly(vertx, verty, px, py, is_inside)\n !! where all arguments are arrays \n !! (with size(vertx) == size(verty) & (size(px) == size(py) == size(is_inside))\n !!\n !! A discussion of the problem is here (we use a similar algorithm)\n !! https://www.ecse.rpi.edu/~wrf/Research/Short_Notes/pnpoly.html\n !\n use global_mod, only: ip, dp\n implicit none\n\n contains \n\n ! Find if a single point (px, py) is inside a poly defined by nvert vertices\n ! (vertx, verty). \n !\n ! @param nvert number of vertices in the polygon\n ! @param vertx x coordinates of polygon vertices, in order\n ! @param verty y coordinates of polygon vertices in order\n ! @param px x coordinates of points which might be in or outside the polygon\n ! @param py y coordinates of points which might be in or outside the polygon\n ! @param is_inside output logical array which indicates if each px,py is inside the polygon\n !\n pure subroutine point_in_poly(nvert, vertx, verty, px, py, is_inside)\n integer(ip), intent(in):: nvert\n real(dp), intent(in):: vertx(nvert), verty(nvert), px, py\n logical, intent(out):: is_inside\n\n integer(ip) :: i, j\n real(dp) :: g0\n\n is_inside = .FALSE.\n\n do i = 1, nvert\n ! j is an index of the next vertex\n if(i == 1) then\n j = nvert\n else\n j = i - 1\n end if\n\n ! Main test\n if((verty(i) > py) .neqv. (verty(j) > py)) then\n g0 = (vertx(j) - vertx(i)) * (py - verty(i)) / (verty(j) - verty(i)) + vertx(i)\n if(px < g0) then\n is_inside = (.NOT. is_inside)\n end if\n end if\n\n end do\n end subroutine\n\n ! Generalise point_in_poly to many points\n !\n ! Use a bounding box check which could speed up some cases.\n !\n ! @param vertx x coordinates of polygon vertices, in order\n ! @param verty y coordinates of polygon vertices in order\n ! @param px x coordinates of points which might be in or outside the polygon\n ! @param py y coordinates of points which might be in or outside the polygon\n ! @param is_inside output logical array which indicates if each px,py is inside the polygon\n !\n pure subroutine points_in_poly(vertx, verty, px, py, is_inside)\n real(dp), intent(in):: vertx(:), verty(:), px(:), py(:)\n logical, intent(out):: is_inside(:)\n\n integer(ip):: i, nvert, np\n\n ! bounding box for polygon to speed up check\n real(dp):: min_vertx, max_vertx, min_verty, max_verty\n \n nvert = size(vertx, kind=ip)\n np = size(px, kind=ip)\n\n min_vertx = minval(vertx)\n max_vertx = maxval(vertx)\n min_verty = minval(verty)\n max_verty = maxval(verty)\n\n do i = 1, np\n if(px(i) >= min_vertx .and. px(i) <= max_vertx .and. &\n py(i) >= min_verty .and. py(i) <= max_verty) then\n call point_in_poly(nvert, vertx, verty, px(i), py(i), is_inside(i))\n else\n is_inside(i) = .FALSE.\n end if\n end do\n\n end subroutine\n\n\n ! Test. Call as test_points_in_poly_mod()\n !\n subroutine test_points_in_poly_mod\n integer(ip):: nvert\n \n ! doesn't seem to matter whether last point == first point or not\n real(dp), dimension(5) :: vertx = [0._dp, 0.0_dp, 1.0_dp, 1.0_dp, 0._dp]\n real(dp), dimension(5) :: verty = [0._dp, 1.0_dp, 1.0_dp, 0.0_dp, 0._dp]\n !real(dp), dimension(4) :: vertx = [0._dp, 0.0_dp, 1.0_dp, 1.0_dp]\n !real(dp), dimension(4) :: verty = [0._dp, 1.0_dp, 1.0_dp, 0.0_dp]\n\n integer(ip):: i\n logical:: is_inside_result\n\n type test_point_type\n real(dp):: p(2)\n logical:: is_inside\n end type\n\n type(test_point_type):: test_points(10)\n \n real(dp):: test_points_array(10, 2)\n logical:: is_inside_result_array(10), is_inside_array(10)\n \n nvert = size(vertx, kind=ip)\n \n ! Manually make test points and flag if they lie on a boundary \n ! \n ! It seems the routine counts being 'on' the boundary as being inside\n ! (although that may vary in more complex cases due to round-off?) \n !\n test_points(1) = test_point_type([-1.0_dp, 0.0_dp], .FALSE.)\n test_points(2) = test_point_type([-1.0_dp, 0.5_dp], .FALSE.)\n test_points(3) = test_point_type([ 0.0_dp, 0.0_dp], .TRUE.)\n test_points(4) = test_point_type([ 0.0_dp, 0.5_dp], .TRUE.)\n test_points(5) = test_point_type([ 0.5_dp, 0.5_dp], .TRUE.)\n test_points(6) = test_point_type([ 0.1_dp, 0.9_dp], .TRUE.)\n test_points(7) = test_point_type([ 0.1_dp, 2.9_dp], .FALSE.)\n test_points(8) = test_point_type([ 0.1_dp, 0.0_dp], .TRUE.)\n test_points(9) = test_point_type([ 1.0e-10_dp, 1.0e-10_dp], .TRUE.)\n test_points(10) = test_point_type([ -1.0e-10_dp, -1.0e-10_dp], .FALSE.)\n \n do i = 1, 10\n\n call point_in_poly(size(vertx)*1_ip, vertx, verty, &\n test_points(i)%p(1), test_points(i)%p(2), is_inside_result)\n\n if(is_inside_result .eqv. test_points(i)%is_inside) then\n print*, 'PASS'\n else\n print*, 'FAIL on point ', i, ' : ', test_points(i)\n end if\n\n end do \n\n ! Test the array version\n do i = 1, 10\n test_points_array(i,:) = test_points(i)%p\n is_inside_array(i) = test_points(i)%is_inside\n end do\n\n call points_in_poly(vertx, verty, test_points_array(:,1), &\n test_points_array(:,2), is_inside_result_array)\n\n if(all(is_inside_result_array .eqv. is_inside_array)) then\n print*, 'PASS'\n else\n print*, 'FAIL on array test'\n end if\n\n end subroutine\n\nend module\n\n\n", "meta": {"hexsha": "a723f5bb96fc9be6908df096917ba785a2ea33c2", "size": 6249, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "propagation/SWALS/src/util/points_in_poly_mod.f90", "max_stars_repo_name": "KayaGeoAus/ptha", "max_stars_repo_head_hexsha": "183c956506f35930437fa37d24d5b49abbb94284", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2017-03-28T02:33:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-10T01:11:24.000Z", "max_issues_repo_path": "propagation/SWALS/src/util/points_in_poly_mod.f90", "max_issues_repo_name": "KayaGeoAus/ptha", "max_issues_repo_head_hexsha": "183c956506f35930437fa37d24d5b49abbb94284", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2021-11-15T22:44:38.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-02T06:04:18.000Z", "max_forks_repo_path": "propagation/SWALS/src/util/points_in_poly_mod.f90", "max_forks_repo_name": "KayaGeoAus/ptha", "max_forks_repo_head_hexsha": "183c956506f35930437fa37d24d5b49abbb94284", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-11-08T21:22:37.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-07T11:36:39.000Z", "avg_line_length": 35.9137931034, "max_line_length": 95, "alphanum_fraction": 0.5815330453, "num_tokens": 1782, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835534888481, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.6516712442732012}} {"text": "! DART software - Copyright UCAR. This open source software is provided\n! by UCAR, \"as is\", without charge, subject to all terms of use at\n! http://www.image.ucar.edu/DAReS/DART/DART_download\n!\n! $Id$\n\nprogram test_random\n\n! test the uniform random number generator routine\n\nuse types_mod, only : r8\nuse utilities_mod, only : register_module, &\n open_file, close_file, &\n initialize_utilities, finalize_utilities, &\n squeeze_out_blanks\nuse random_seq_mod, only : random_seq_type, init_random_seq, random_uniform\n\nimplicit none\n\n! version controlled file description for error handling, do not edit\ncharacter(len=256), parameter :: source = &\n \"$URL$\"\ncharacter(len=32 ), parameter :: revision = \"$Revision$\"\ncharacter(len=128), parameter :: revdate = \"$Date$\"\n\ntype (random_seq_type) :: r\ninteger :: i, j, n, f\nreal(r8) :: r1, sum\nreal(r8) :: mean, compmean, compdiffm\nlogical :: write_this_one\ncharacter(len=50) :: formf = '(I12,4(F16.5))'\ncharacter(len=256) :: fname, temp\n\nlogical :: write_me = .true. ! if true, write each distribution into a file for later diagnostics\ninteger :: write_limit = 1000000 ! but only if rep count is not greater than this limit\n\ntype t_inputs\n integer :: t_nreps\nend type\n\n\n! to add more tests or change the parameters, specify a test count\n! and update the sets of inputs here:\n\ninteger, parameter :: ntests = 11\ntype(t_inputs) :: t(ntests) = (/ &\n t_inputs( 100), &\n t_inputs( 500), &\n t_inputs( 1000), &\n t_inputs( 5000), &\n t_inputs( 10000), &\n t_inputs( 50000), &\n t_inputs( 100000), &\n t_inputs( 500000), &\n t_inputs( 1000000), &\n t_inputs( 5000000), &\n t_inputs( 10000000) /)\n\n\ncall initialize_utilities('test_random')\ncall register_module(source,revision,revdate)\n\nwrite(*, *) ''\nwrite(*, *) 'sample size computed mean actual mean diff mean % diff mean'\nwrite(*, *) ''\n\ndo j=1, ntests\n\n call init_random_seq(r, 5)\n\n n = t(j)%t_nreps\n\n ! save all values in a file for post-plotting?\n write_this_one = (write_me .and. n <= write_limit)\n\n if (write_this_one) then\n write(temp, \"(A,I10)\") \"random_\", n\n call squeeze_out_blanks(temp, fname)\n f = open_file(fname)\n endif\n\n ! analytical values:\n mean = 0.5\n\n sum = 0.0_r8\n\n do i = 1, n\n r1 = random_uniform(r)\n\n if (write_this_one) write(f,*) r1\n\n sum = sum + r1\n end do\n\n if (write_this_one) call close_file(f)\n\n ! computed values:\n compmean = sum / n\n\n ! differences\n compdiffm = compmean - mean\n\n write(*, formf) n, mean, compmean, compdiffm, &\n abs(compdiffm/mean) * 100._r8\n \n\nenddo\n\ncall finalize_utilities()\n\nend program test_random\n\n! \n! $URL$\n! $Id$\n! $Revision$\n! $Date$\n", "meta": {"hexsha": "36abe4914b83083ba160bbc27342a6fac23d86a8", "size": 2891, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "developer_tests/random_seq/test_random.f90", "max_stars_repo_name": "hkershaw-brown/feature-preprocess", "max_stars_repo_head_hexsha": "fe2bd77b38c63fa0566c83ebc4d2fac1623aef66", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 65, "max_stars_repo_stars_event_min_datetime": "2019-10-16T13:31:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-14T11:52:58.000Z", "max_issues_repo_path": "developer_tests/random_seq/test_random.f90", "max_issues_repo_name": "hkershaw-brown/feature-preprocess", "max_issues_repo_head_hexsha": "fe2bd77b38c63fa0566c83ebc4d2fac1623aef66", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 283, "max_issues_repo_issues_event_min_datetime": "2019-09-23T15:48:34.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:44:41.000Z", "max_forks_repo_path": "developer_tests/random_seq/test_random.f90", "max_forks_repo_name": "hkershaw-brown/feature-preprocess", "max_forks_repo_head_hexsha": "fe2bd77b38c63fa0566c83ebc4d2fac1623aef66", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 67, "max_forks_repo_forks_event_min_datetime": "2019-09-19T22:13:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-20T15:58:26.000Z", "avg_line_length": 24.5, "max_line_length": 103, "alphanum_fraction": 0.636457973, "num_tokens": 824, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.835483553488848, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6516712357275461}} {"text": "!*==zlargv.f90 processed by SPAG 7.51RB at 20:08 on 3 Mar 2022\n!> \\brief \\b ZLARGV generates a vector of plane rotations with real cosines and complex sines.\n!\n! =========== DOCUMENTATION ===========\n!\n! Online html documentation available at\n! http://www.netlib.org/lapack/explore-html/\n!\n!> \\htmlonly\n!> Download ZLARGV + dependencies\n!> \n!> [TGZ]\n!> \n!> [ZIP]\n!> \n!> [TXT]\n!> \\endhtmlonly\n!\n! Definition:\n! ===========\n!\n! SUBROUTINE ZLARGV( N, X, INCX, Y, INCY, C, INCC )\n!\n! .. Scalar Arguments ..\n! INTEGER INCC, INCX, INCY, N\n! ..\n! .. Array Arguments ..\n! DOUBLE PRECISION C( * )\n! COMPLEX*16 X( * ), Y( * )\n! ..\n!\n!\n!> \\par Purpose:\n! =============\n!>\n!> \\verbatim\n!>\n!> ZLARGV generates a vector of complex plane rotations with real\n!> cosines, determined by elements of the complex vectors x and y.\n!> For i = 1,2,...,n\n!>\n!> ( c(i) s(i) ) ( x(i) ) = ( r(i) )\n!> ( -conjg(s(i)) c(i) ) ( y(i) ) = ( 0 )\n!>\n!> where c(i)**2 + ABS(s(i))**2 = 1\n!>\n!> The following conventions are used (these are the same as in ZLARTG,\n!> but differ from the BLAS1 routine ZROTG):\n!> If y(i)=0, then c(i)=1 and s(i)=0.\n!> If x(i)=0, then c(i)=0 and s(i) is chosen so that r(i) is real.\n!> \\endverbatim\n!\n! Arguments:\n! ==========\n!\n!> \\param[in] N\n!> \\verbatim\n!> N is INTEGER\n!> The number of plane rotations to be generated.\n!> \\endverbatim\n!>\n!> \\param[in,out] X\n!> \\verbatim\n!> X is COMPLEX*16 array, dimension (1+(N-1)*INCX)\n!> On entry, the vector x.\n!> On exit, x(i) is overwritten by r(i), for i = 1,...,n.\n!> \\endverbatim\n!>\n!> \\param[in] INCX\n!> \\verbatim\n!> INCX is INTEGER\n!> The increment between elements of X. INCX > 0.\n!> \\endverbatim\n!>\n!> \\param[in,out] Y\n!> \\verbatim\n!> Y is COMPLEX*16 array, dimension (1+(N-1)*INCY)\n!> On entry, the vector y.\n!> On exit, the sines of the plane rotations.\n!> \\endverbatim\n!>\n!> \\param[in] INCY\n!> \\verbatim\n!> INCY is INTEGER\n!> The increment between elements of Y. INCY > 0.\n!> \\endverbatim\n!>\n!> \\param[out] C\n!> \\verbatim\n!> C is DOUBLE PRECISION array, dimension (1+(N-1)*INCC)\n!> The cosines of the plane rotations.\n!> \\endverbatim\n!>\n!> \\param[in] INCC\n!> \\verbatim\n!> INCC is INTEGER\n!> The increment between elements of C. INCC > 0.\n!> \\endverbatim\n!\n! Authors:\n! ========\n!\n!> \\author Univ. of Tennessee\n!> \\author Univ. of California Berkeley\n!> \\author Univ. of Colorado Denver\n!> \\author NAG Ltd.\n!\n!> \\date December 2016\n!\n!> \\ingroup complex16OTHERauxiliary\n!\n!> \\par Further Details:\n! =====================\n!>\n!> \\verbatim\n!>\n!> 6-6-96 - Modified with a new algorithm by W. Kahan and J. Demmel\n!>\n!> This version has a few statements commented out for thread safety\n!> (machine parameters are computed on each entry). 10 feb 03, SJH.\n!> \\endverbatim\n!>\n! =====================================================================\n SUBROUTINE ZLARGV(N,X,Incx,Y,Incy,C,Incc)\n IMPLICIT NONE\n!*--ZLARGV126\n!\n! -- LAPACK auxiliary routine (version 3.7.0) --\n! -- LAPACK is a software package provided by Univ. of Tennessee, --\n! -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n! December 2016\n!\n! .. Scalar Arguments ..\n INTEGER Incc , Incx , Incy , N\n! ..\n! .. Array Arguments ..\n DOUBLE PRECISION C(*)\n COMPLEX*16 X(*) , Y(*)\n! ..\n!\n! =====================================================================\n!\n! .. Parameters ..\n DOUBLE PRECISION TWO , ONE , ZERO\n PARAMETER (TWO=2.0D+0,ONE=1.0D+0,ZERO=0.0D+0)\n COMPLEX*16 CZERO\n PARAMETER (CZERO=(0.0D+0,0.0D+0))\n! ..\n! .. Local Scalars ..\n! LOGICAL FIRST\n \n INTEGER count , i , ic , ix , iy , j\n DOUBLE PRECISION cs , d , di , dr , eps , f2 , f2s , g2 , g2s , &\n & safmin , safmn2 , safmx2 , scale\n COMPLEX*16 f , ff , fs , g , gs , r , sn\n! ..\n! .. External Functions ..\n DOUBLE PRECISION DLAMCH , DLAPY2\n EXTERNAL DLAMCH , DLAPY2\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC ABS , DBLE , DCMPLX , DCONJG , DIMAG , INT , LOG , MAX ,&\n & SQRT\n! ..\n! .. Statement Functions ..\n DOUBLE PRECISION ABS1 , ABSSQ\n! ..\n! .. Save statement ..\n! SAVE FIRST, SAFMX2, SAFMIN, SAFMN2\n! ..\n! .. Data statements ..\n! DATA FIRST / .TRUE. /\n! ..\n! .. Statement Function definitions ..\n ABS1(ff) = MAX(ABS(DBLE(ff)),ABS(DIMAG(ff)))\n ABSSQ(ff) = DBLE(ff)**2 + DIMAG(ff)**2\n! ..\n! .. Executable Statements ..\n!\n! IF( FIRST ) THEN\n! FIRST = .FALSE.\n safmin = DLAMCH('S')\n eps = DLAMCH('E')\n safmn2 = DLAMCH('B')**INT(LOG(safmin/eps)/LOG(DLAMCH('B'))/TWO)\n safmx2 = ONE/safmn2\n! END IF\n ix = 1\n iy = 1\n ic = 1\n DO i = 1 , N\n f = X(ix)\n g = Y(iy)\n!\n! Use identical algorithm as in ZLARTG\n!\n scale = MAX(ABS1(f),ABS1(g))\n fs = f\n gs = g\n count = 0\n IF ( scale>=safmx2 ) THEN\n DO\n count = count + 1\n fs = fs*safmn2\n gs = gs*safmn2\n scale = scale*safmn2\n IF ( scale=20 ) EXIT\n ENDDO\n ELSEIF ( scale<=safmn2 ) THEN\n IF ( g==CZERO ) THEN\n cs = ONE\n sn = CZERO\n r = f\n GOTO 50\n ENDIF\n DO\n count = count - 1\n fs = fs*safmx2\n gs = gs*safmx2\n scale = scale*safmx2\n IF ( scale>safmn2 ) EXIT\n ENDDO\n ENDIF\n f2 = ABSSQ(fs)\n g2 = ABSSQ(gs)\n IF ( f2<=MAX(g2,ONE)*safmin ) THEN\n!\n! This is a rare case: F is very small.\n!\n IF ( f==CZERO ) THEN\n cs = ZERO\n r = DLAPY2(DBLE(g),DIMAG(g))\n! Do complex/real division explicitly with two real\n! divisions\n d = DLAPY2(DBLE(gs),DIMAG(gs))\n sn = DCMPLX(DBLE(gs)/d,-DIMAG(gs)/d)\n GOTO 50\n ENDIF\n f2s = DLAPY2(DBLE(fs),DIMAG(fs))\n! G2 and G2S are accurate\n! G2 is at least SAFMIN, and G2S is at least SAFMN2\n g2s = SQRT(g2)\n! Error in CS from underflow in F2S is at most\n! UNFL / SAFMN2 .lt. sqrt(UNFL*EPS) .lt. EPS\n! If MAX(G2,ONE)=G2, then F2 .lt. G2*SAFMIN,\n! and so CS .lt. sqrt(SAFMIN)\n! If MAX(G2,ONE)=ONE, then F2 .lt. SAFMIN\n! and so CS .lt. sqrt(SAFMIN)/SAFMN2 = sqrt(EPS)\n! Therefore, CS = F2S/G2S / sqrt( 1 + (F2S/G2S)**2 ) = F2S/G2S\n cs = f2s/g2s\n! Make sure abs(FF) = 1\n! Do complex/real division explicitly with 2 real divisions\n IF ( ABS1(f)>ONE ) THEN\n d = DLAPY2(DBLE(f),DIMAG(f))\n ff = DCMPLX(DBLE(f)/d,DIMAG(f)/d)\n ELSE\n dr = safmx2*DBLE(f)\n di = safmx2*DIMAG(f)\n d = DLAPY2(dr,di)\n ff = DCMPLX(dr/d,di/d)\n ENDIF\n sn = ff*DCMPLX(DBLE(gs)/g2s,-DIMAG(gs)/g2s)\n r = cs*f + sn*g\n ELSE\n!\n! This is the most common case.\n! Neither F2 nor F2/G2 are less than SAFMIN\n! F2S cannot overflow, and it is accurate\n!\n f2s = SQRT(ONE+g2/f2)\n! Do the F2S(real)*FS(complex) multiply with two real\n! multiplies\n r = DCMPLX(f2s*DBLE(fs),f2s*DIMAG(fs))\n cs = ONE/f2s\n d = f2 + g2\n! Do complex/real division explicitly with two real divisions\n sn = DCMPLX(DBLE(r)/d,DIMAG(r)/d)\n sn = sn*DCONJG(gs)\n IF ( count/=0 ) THEN\n IF ( count>0 ) THEN\n DO j = 1 , count\n r = r*safmx2\n ENDDO\n ELSE\n DO j = 1 , -count\n r = r*safmn2\n ENDDO\n ENDIF\n ENDIF\n ENDIF\n 50 C(ic) = cs\n Y(iy) = sn\n X(ix) = r\n ic = ic + Incc\n iy = iy + Incy\n ix = ix + Incx\n ENDDO\n!\n! End of ZLARGV\n!\n END SUBROUTINE ZLARGV\n", "meta": {"hexsha": "a3de61d1dd573f25ba7cb5f7229fe23a22a31561", "size": 8807, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/doublecomplex/zlargv.f90", "max_stars_repo_name": "urbanjost/spag_lapack", "max_stars_repo_head_hexsha": "1b082638c0ff5feb1a295a3aa4624c538d14847c", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2022-03-04T13:15:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-04T17:40:26.000Z", "max_issues_repo_path": "src/doublecomplex/zlargv.f90", "max_issues_repo_name": "urbanjost/spag_lapack", "max_issues_repo_head_hexsha": "1b082638c0ff5feb1a295a3aa4624c538d14847c", "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": "src/doublecomplex/zlargv.f90", "max_forks_repo_name": "urbanjost/spag_lapack", "max_forks_repo_head_hexsha": "1b082638c0ff5feb1a295a3aa4624c538d14847c", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.2591362126, "max_line_length": 111, "alphanum_fraction": 0.4917679119, "num_tokens": 2827, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835371034369, "lm_q2_score": 0.7799928951399098, "lm_q1q2_score": 0.6516712229470419}} {"text": "************************************************************************\r\n*\r\n* Function LOGLK Called by: CALIBR\r\n*\r\n* calculate the log likelihood of Tobit regression (Paarsch, 1984)\r\n*\r\n* locals vars\r\n* -----------\r\n* YHAT predicted value of the response variable\r\n*\r\n************************************************************************\r\n DOUBLE PRECISION FUNCTION LOGLK(NPAR,NOBSC,XLCAL,YLCAL,CENSFLAG,\r\n & PARAML,RESSTD,NOBSCI)\r\n*\r\n* subroutine arguments\r\n*\r\n INTEGER*4 NPAR,NOBSC,NOBSCI\r\n LOGICAL CENSFLAG(*)\r\n DOUBLE PRECISION RESSTD,YLCAL(*),PARAML(*),XLCAL(NOBSCI,*)\r\n*\r\n* local vars\r\n*\r\n INTEGER*4 I\r\n DOUBLE PRECISION YHAT\r\n*\r\n* function declarations\r\n*\r\n DOUBLE PRECISION ERF,PRED\r\n*\r\n* compute the log likelihood due to censored and uncensored data\r\n*\r\n* if the observation is censored, its contribution to LOGLK is based\r\n* on the integral of the probability density of a standardized\r\n* normal variable from X to infinity (the complement of the\r\n* cumulative distribution function)(Abramowitz and Stegun, 1964, p.\r\n* 297 & 931). If the observation is uncensored, the contribution is\r\n* based on the probability density function of the standard normal\r\n* distribution, divided by the residual standard deviation (RESSTD).\r\n*\r\n LOGLK = 0.D0\r\n\r\n DO 10 I=1,NOBSC\r\n YHAT = PRED(NPAR,NOBSCI,I,XLCAL,PARAML)\r\n IF (CENSFLAG(I)) THEN\r\n LOGLK = LOGLK\r\n & + DLOG((1.D0\r\n & -ERF((-(YLCAL(I)-YHAT)/RESSTD)/DSQRT(2.D0)))/2.D0)\r\n ELSE\r\n LOGLK = LOGLK\r\n & + DLOG(((1.D0/DSQRT(2.D0*3.14159265359D0)) *\r\n & DEXP(-(((YLCAL(I)-YHAT)/RESSTD)**2)/2.D0)\r\n & /RESSTD))\r\n ENDIF\r\n 10 CONTINUE\r\n\r\n RETURN\r\n END\r\n", "meta": {"hexsha": "5a05622ee86c6ab788593b9c24e1c08bc7d875f8", "size": 1979, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "codeNexampls/[loadest]/loadsrc/loadest/source_USGS/loglk.f", "max_stars_repo_name": "lthiamodelers/baseflow-coefficients", "max_stars_repo_head_hexsha": "183fef49548fa2e1bf0bb8cff57e96e75d629760", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "codeNexampls/[loadest]/loadsrc/loadest/source_USGS/loglk.f", "max_issues_repo_name": "lthiamodelers/baseflow-coefficients", "max_issues_repo_head_hexsha": "183fef49548fa2e1bf0bb8cff57e96e75d629760", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "codeNexampls/[loadest]/loadsrc/loadest/source_USGS/loglk.f", "max_forks_repo_name": "lthiamodelers/baseflow-coefficients", "max_forks_repo_head_hexsha": "183fef49548fa2e1bf0bb8cff57e96e75d629760", "max_forks_repo_licenses": ["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.1206896552, "max_line_length": 73, "alphanum_fraction": 0.5103587671, "num_tokens": 513, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897459384731, "lm_q2_score": 0.6926419767901475, "lm_q1q2_score": 0.6516304693707247}} {"text": "! =====================================================\nsubroutine rpn2(ixy,maxm,meqn,mwaves,maux,mbc,mx,ql,qr,auxl,auxr,wave,s,amdq,apdq)\n! =====================================================\n\n! HLLE solver for the 2D shallow water equations.\n\n! waves: 2\n! equations: 3\n\n! Conserved quantities:\n! 1 depth\n! 2 x-momentum\n! 3 y-momentum\n\n implicit none\n\n integer, intent(in) :: ixy, maxm, meqn, mwaves, maux, mbc, mx\n double precision, dimension(meqn,1-mbc:maxm+mbc), intent(in) :: ql, qr\n double precision, dimension(maux,1-mbc:maxm+mbc), intent(in) :: auxl, auxr\n double precision, dimension(meqn, mwaves, 1-mbc:maxm+mbc), intent(out) :: wave\n double precision, dimension(mwaves, 1-mbc:maxm+mbc), intent(out) :: s\n double precision, dimension(meqn, 1-mbc:maxm+mbc), intent(out) :: amdq, apdq\n\n double precision :: u_l, u_r, c_l, c_r, u_hat, c_hat, v_l, v_r, v_hat, h_hat\n double precision :: h_l, h_r, hsqrt_l, hsqrt_r, hsq2\n double precision :: grav\n double precision :: h_m, hu_m, hv_m, s1, s2\n integer :: depth, mu, mv\n integer :: i, m, mw\n\n common /cparam/ grav\n\n! # set mu to point to the component of the system that corresponds\n! # to momentum in the direction of this slice, mv to the orthogonal\n! # momentum:\n!\n\n depth = 1\n if (ixy.eq.1) then\n mu = 2\n mv = 3\n else\n mu = 3\n mv = 2\n endif\n\n do i=2-mbc,mx+mbc\n h_l = qr(depth,i-1)\n h_r = ql(depth,i)\n ! Velocity\n u_l = qr(mu,i-1) / qr(depth,i-1)\n u_r = ql(mu,i ) / ql(depth,i )\n v_l = qr(mv,i-1) / qr(depth,i-1)\n v_r = ql(mv,i ) / ql(depth,i )\n ! Sound speed\n c_l = dsqrt(grav*h_l)\n c_r = dsqrt(grav*h_r)\n\n hsqrt_l = dsqrt(qr(depth,i-1))\n hsqrt_r = dsqrt(ql(depth,i))\n hsq2 = hsqrt_l + hsqrt_r\n h_hat = 0.5*(h_l + h_r)\n u_hat = (u_l*hsqrt_l + u_r*hsqrt_r) / hsq2\n v_hat = (v_l*hsqrt_l + v_r*hsqrt_r) / hsq2\n c_hat = dsqrt(grav*h_hat)\n\n ! Speeds of non-shear waves\n s1 = min(u_l - c_l, u_hat - c_hat)\n s2 = max(u_r + c_r, u_hat + c_hat)\n\n ! middle\" state\n h_m = (ql(mu,i) - qr(mu,i-1) - s2*ql(depth,i) + s1*qr(depth,i-1))/(s1-s2)\n hu_m = (ql(mu,i)*(u_r-s2) - qr(mu,i-1)*(u_l-s1) + 0.5*grav*(h_r**2 - h_l**2) ) / (s1-s2)\n hv_m = (ql(mv,i)*u_r - qr(mv,i-1)*u_l - s2*ql(mv,i) + s1*qr(mv,i-1))/(s1-s2)\n\n wave(depth,1,i) = h_m - h_l\n wave(mu,1,i) = hu_m - qr(mu,i-1)\n wave(mv,1,i) = hv_m - qr(mv,i-1)\n s(1,i) = s1\n\n wave(depth,2,i) = h_r - h_m\n wave(mu,2,i) = ql(mu,i) - hu_m\n wave(mv,2,i) = ql(mv,i) - hv_m\n s(2,i) = s2\n end do\n\n\n do m=1, meqn\n do i=2-mbc, mx+mbc\n amdq(m,i) = 0.d0\n apdq(m,i) = 0.d0\n do mw=1, mwaves\n if (s(mw,i) .lt. 0.d0) then\n amdq(m,i) = amdq(m,i) + s(mw,i)*wave(m,mw,i)\n else\n apdq(m,i) = apdq(m,i) + s(mw,i)*wave(m,mw,i)\n endif\n end do\n end do\n end do\n\nend subroutine rpn2\n", "meta": {"hexsha": "88bbed1245db21945fc5bcaa39d2d8bebba17711", "size": 3147, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/rpn2_shallow_hlle.f90", "max_stars_repo_name": "ranocha/riemann", "max_stars_repo_head_hexsha": "d7b4d72d1147eee12e60a64f46a7e076b28a212d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 27, "max_stars_repo_stars_event_min_datetime": "2015-03-08T03:42:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-21T01:46:12.000Z", "max_issues_repo_path": "src/rpn2_shallow_hlle.f90", "max_issues_repo_name": "ranocha/riemann", "max_issues_repo_head_hexsha": "d7b4d72d1147eee12e60a64f46a7e076b28a212d", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 47, "max_issues_repo_issues_event_min_datetime": "2015-02-11T15:39:22.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-25T01:56:46.000Z", "max_forks_repo_path": "src/rpn2_shallow_hlle.f90", "max_forks_repo_name": "ranocha/riemann", "max_forks_repo_head_hexsha": "d7b4d72d1147eee12e60a64f46a7e076b28a212d", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 37, "max_forks_repo_forks_event_min_datetime": "2015-01-09T21:44:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-21T12:53:04.000Z", "avg_line_length": 30.5533980583, "max_line_length": 96, "alphanum_fraction": 0.5058786146, "num_tokens": 1157, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009596336303, "lm_q2_score": 0.7122321903471563, "lm_q1q2_score": 0.6516219144305757}} {"text": "MODULE AttenMod\r\n\r\n ! Attenuation module\r\n ! Routines to convert a sound speed and attenuation in user units to a complex sound speed\r\n ! Includes a formula for volume attenuation\r\n\r\n IMPLICIT NONE\r\n INTEGER, PARAMETER :: MaxBioLayers = 200\r\n INTEGER :: iBio, NBioLayers\r\n REAL (KIND=8) :: T = 20, Salinity = 35, pH = 8, z_bar = 0, FG ! Francois-Garrison volume attenuation; temperature, salinity, ...\r\n\r\n TYPE bioStructure\r\n REAL (KIND=8) :: Z1, Z2, f0, Q, a0\r\n END TYPE bioStructure\r\n\r\n TYPE( bioStructure ) :: bio( MaxBioLayers )\r\n\r\nCONTAINS\r\n FUNCTION CRCI( z, c, alpha, freq, freq0, AttenUnit, beta, fT )\r\n\r\n ! Converts real wave speed and attenuation to a single\r\n ! complex wave speed (with positive imaginary part)\r\n\r\n ! AttenUnit\r\n ! 6 Cases: N Nepers/meter\r\n ! M dB/meter (M for Meters)\r\n ! m dB/meter with a power law\r\n ! F dB/m-kHz (F for Frequency dependent)\r\n ! W dB/wavelength (W for Wavelength)\r\n ! Q Q\r\n ! L Loss parameter\r\n !\r\n ! second letter adds volume attenuation according to standard laws:\r\n ! T for Thorp\r\n ! F for Francois Garrison\r\n ! B for biological\r\n !\r\n ! freq is the current frequency\r\n ! freq0 is the reference frequency for which the dB/meter was specified (used only for 'm')\r\n\r\n ! Returns\r\n ! c real part of sound speed\r\n ! alpha imaginary part of sound speed\r\n\r\n USE MathConstants\r\n\r\n REAL (KIND=8), INTENT( IN ) :: freq, freq0, alpha, c, z, beta, fT\r\n CHARACTER (LEN=2), INTENT( IN ) :: AttenUnit\r\n REAL (KIND=8) :: f2, omega, alphaT, Thorp, a, FG\r\n COMPLEX (KIND=8) :: CRCI\r\n\r\n omega = 2.0 * pi * freq\r\n\r\n ! Convert to Nepers/m \r\n alphaT = 0.0\r\n SELECT CASE ( AttenUnit( 1 : 1 ) )\r\n CASE ( 'N' )\r\n alphaT = alpha\r\n CASE ( 'M' ) ! dB/m\r\n alphaT = alpha / 8.6858896D0\r\n CASE ( 'm' ) ! dB/m with power law\r\n alphaT = alpha / 8.6858896D0\r\n IF ( freq < fT ) THEN ! frequency raised to the power beta\r\n alphaT = alphaT * ( freq / freq0 ) ** beta\r\n ELSE ! linear in frequency\r\n alphaT = alphaT * ( freq / freq0 ) * ( fT / freq0 ) ** ( beta - 1 )\r\n END IF\r\n CASE ( 'F' ) ! dB/(m kHz)\r\n alphaT = alpha * freq / 8685.8896D0\r\n CASE ( 'W' ) ! dB/wavelength\r\n IF ( c /= 0.0 ) alphaT = alpha * freq / ( 8.6858896D0 * c )\r\n ! The following lines give f^1.25 Frequency dependence\r\n ! FAC = SQRT( SQRT( freq / 50.0 ) )\r\n ! IF ( c /= 0.0 ) alphaT = FAC * alpha * freq / ( 8.6858896D0 * c )\r\n CASE ( 'Q' ) ! Quality factor\r\n IF ( c * alpha /= 0.0 ) alphaT = omega / ( 2.0 * c * alpha )\r\n CASE ( 'L' ) ! loss parameter\r\n IF ( c /= 0.0 ) alphaT = alpha * omega / c\r\n END SELECT\r\n\r\n ! added volume attenuation\r\n SELECT CASE ( AttenUnit( 2 : 2 ) )\r\n CASE ( 'T' )\r\n f2 = ( freq / 1000.0 ) ** 2\r\n\r\n ! Original formula from Thorp 1967\r\n ! Thorp = 40.0 * f2 / ( 4100.0 + f2 ) + 0.1 * f2 / ( 1.0 + f2 ) ! dB/kyard\r\n ! Thorp = Thorp / 914.4D0 ! dB / m\r\n ! Thorp = Thorp / 8.6858896D0 ! Nepers / m\r\n\r\n ! Updated formula from JKPS Eq. 1.34\r\n Thorp = 3.3d-3 + 0.11 * f2 / ( 1.0 + f2 ) + 44.0 * f2 / ( 4100.0 + f2 ) + 3d-4 * f2 ! dB/km\r\n Thorp = Thorp / 8685.8896 ! Nepers / m\r\n\r\n alphaT = alphaT + Thorp\r\n CASE ( 'F' ) ! Francois-Garrison\r\n FG = Franc_Garr( freq / 1000 ); ! dB/km\r\n FG = FG / 8685.8896; ! Nepers / m\r\n alphaT = alphaT + FG\r\n CASE ( 'B' ) ! biological attenuation per Orest Diachok\r\n DO iBio = 1, NBioLayers\r\n IF ( z >= bio( iBio )%Z1 .AND. z <= bio( iBio )%Z2 ) THEN\r\n a = bio( iBio )%a0 / ( ( 1.0 - bio( iBio )%f0 ** 2 / freq ** 2 ) ** 2 + 1.0 / bio( iBio )%Q ** 2 ) ! dB/km\r\n a = a / 8685.8896 ! Nepers / m\r\n alphaT = alphaT + a\r\n END IF\r\n END DO\r\n END SELECT\r\n\r\n ! Convert Nepers/m to equivalent imaginary sound speed \r\n alphaT = alphaT * c * c / omega\r\n CRCI = CMPLX( c, alphaT, KIND=8 )\r\n\r\n RETURN\r\n END FUNCTION CRCI\r\n\r\n !**********************************************************************!\r\n\r\n FUNCTION Franc_Garr( f )\r\n\r\n ! Francois Garrison formulas for attenuation\r\n ! Based on a Matlab version by D. Jackson APL-UW\r\n\r\n ! mbp Feb. 2019\r\n ! Verified using F-G Table IV\r\n\r\n ! alpha = attenuation (dB/km)\r\n ! f = frequency (kHz)\r\n ! T = temperature (deg C)\r\n ! S = salinity (psu)\r\n ! pH = 7 for neutral water\r\n ! z_bar = depth (m)\r\n\r\n ! Returns\r\n ! alpha = volume attenuation in dB/km\r\n\r\n REAL (KIND=8) :: f, Franc_Garr\r\n REAL (KIND=8) :: c, A1, A2, A3, P1, P2, P3, f1, f2\r\n\r\n c = 1412 + 3.21 * T + 1.19 * Salinity + 0.0167 * z_bar\r\n\r\n ! Boric acid contribution\r\n A1 = 8.86 / c * 10 ** ( 0.78 * pH - 5 )\r\n P1 = 1\r\n f1 = 2.8 * sqrt( Salinity / 35 ) * 10 ** ( 4 - 1245 / ( T + 273 ) )\r\n\r\n ! Magnesium sulfate contribution\r\n A2 = 21.44 * Salinity / c * ( 1 + 0.025 * T )\r\n P2 = 1 - 1.37D-4 * z_bar + 6.2D-9 * z_bar ** 2\r\n f2 = 8.17 * 10 ** ( 8 - 1990 / ( T + 273 ) ) / ( 1 + 0.0018 * ( Salinity - 35 ) )\r\n\r\n ! Viscosity\r\n P3 = 1 - 3.83D-5 * z_bar + 4.9D-10 * z_bar ** 2\r\n if ( T < 20 ) THEN\r\n A3 = 4.937D-4 - 2.59D-5 * T + 9.11D-7 * T ** 2 - 1.5D-8 * T ** 3\r\n else\r\n A3 = 3.964D-4 -1.146D-5 * T + 1.45D-7 * T ** 2 - 6.5D-10 * T ** 3\r\n end if\r\n\r\n Franc_Garr = A1 * P1 * ( f1 * f ** 2 ) / ( f1 ** 2 + f ** 2 ) + A2 * P2 * ( f2 * f ** 2 ) / ( f2 ** 2 + f ** 2 ) + &\r\n A3 * P3 * f ** 2\r\n\r\n END FUNCTION Franc_Garr\r\n\r\nEND MODULE AttenMod\r\n", "meta": {"hexsha": "f9caab83c432ff4e096583416534f23f773dc6b9", "size": 5983, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "AcousticToolbox/at/misc/AttenMod.f90", "max_stars_repo_name": "sarapierson234/SMALLBETS", "max_stars_repo_head_hexsha": "f78add47dada5848b4a44053011bc52bf4edbf2d", "max_stars_repo_licenses": ["Naumen", "Condor-1.1", "MS-PL"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "AcousticToolbox/at/misc/AttenMod.f90", "max_issues_repo_name": "sarapierson234/SMALLBETS", "max_issues_repo_head_hexsha": "f78add47dada5848b4a44053011bc52bf4edbf2d", "max_issues_repo_licenses": ["Naumen", "Condor-1.1", "MS-PL"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-03-19T19:51:38.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-19T19:51:38.000Z", "max_forks_repo_path": "AcousticToolbox/at/misc/AttenMod.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": 36.0421686747, "max_line_length": 136, "alphanum_fraction": 0.484038108, "num_tokens": 2075, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009619539554, "lm_q2_score": 0.7122321781307374, "lm_q1q2_score": 0.6516219049063725}} {"text": "*DECK CPOIR\n SUBROUTINE CPOIR (A, LDA, N, V, ITASK, IND, WORK)\nC***BEGIN PROLOGUE CPOIR\nC***PURPOSE Solve a positive definite Hermitian system of linear\nC equations. Iterative refinement is used to obtain an\nC error estimate.\nC***LIBRARY SLATEC\nC***CATEGORY D2D1B\nC***TYPE COMPLEX (SPOIR-S, CPOIR-C)\nC***KEYWORDS HERMITIAN, LINEAR EQUATIONS, POSITIVE DEFINITE, SYMMETRIC\nC***AUTHOR Voorhees, E. A., (LANL)\nC***DESCRIPTION\nC\nC Subroutine CPOIR solves a complex positive definite Hermitian\nC NxN system of single precision linear equations using LINPACK\nC subroutines CPOFA and CPOSL. One pass of iterative refine-\nC ment is used only to obtain an estimate of the accuracy. That\nC is, if A is an NxN complex positive definite Hermitian matrix\nC and if X and B are complex N-vectors, then CPOIR solves the\nC equation\nC\nC A*X=B.\nC\nC Care should be taken not to use CPOIR with a non-Hermitian\nC matrix.\nC\nC The matrix A is first factored into upper and lower\nC triangular matrices R and R-TRANSPOSE. These\nC factors are used to calculate the solution, X.\nC Then the residual vector is found and used\nC to calculate an estimate of the relative error, IND.\nC IND estimates the accuracy of the solution only when the\nC input matrix and the right hand side are represented\nC exactly in the computer and does not take into account\nC any errors in the input data.\nC\nC If the equation A*X=B is to be solved for more than one vector\nC B, the factoring of A does not need to be performed again and\nC the option to only solve (ITASK .GT. 1) will be faster for\nC the succeeding solutions. In this case, the contents of A,\nC LDA, N, and WORK must not have been altered by the user\nC following factorization (ITASK=1). IND will not be changed\nC by CPOIR in this case.\nC\nC Argument Description ***\nC A COMPLEX(LDA,N)\nC the doubly subscripted array with dimension (LDA,N)\nC which contains the coefficient matrix. Only the\nC upper triangle, including the diagonal, of the\nC coefficient matrix need be entered. A is not\nC altered by the routine.\nC LDA INTEGER\nC the leading dimension of the array A. LDA must be great-\nC er than or equal to N. (terminal error message IND=-1)\nC N INTEGER\nC the order of the matrix A. N must be greater than\nC or equal to one. (terminal error message IND=-2)\nC V COMPLEX(N)\nC on entry, the singly subscripted array(vector) of di-\nC mension N which contains the right hand side B of a\nC system of simultaneous linear equations A*X=B.\nC on return, V contains the solution vector, X .\nC ITASK INTEGER\nC if ITASK = 1, the matrix A is factored and then the\nC linear equation is solved.\nC if ITASK .GT. 1, the equation is solved using the existing\nC factored matrix A (stored in WORK).\nC if ITASK .LT. 1, then terminal terminal error IND=-3 is\nC printed.\nC IND INTEGER\nC GT. 0 IND is a rough estimate of the number of digits\nC of accuracy in the solution, X. IND=75 means\nC that the solution vector X is zero.\nC LT. 0 see error message corresponding to IND below.\nC WORK COMPLEX(N*(N+1))\nC a singly subscripted array of dimension at least N*(N+1).\nC\nC Error Messages Printed ***\nC\nC IND=-1 terminal N is greater than LDA.\nC IND=-2 terminal N is less than one.\nC IND=-3 terminal ITASK is less than one.\nC IND=-4 terminal The matrix A is computationally singular\nC or is not positive definite.\nC A solution has not been computed.\nC IND=-10 warning The solution has no apparent significance.\nC the solution may be inaccurate or the matrix\nC a may be poorly scaled.\nC\nC NOTE- the above terminal(*fatal*) error messages are\nC designed to be handled by XERMSG in which\nC LEVEL=1 (recoverable) and IFLAG=2 . LEVEL=0\nC for warning error messages from XERMSG. Unless\nC the user provides otherwise, an error message\nC will be printed followed by an abort.\nC\nC***REFERENCES J. J. Dongarra, J. R. Bunch, C. B. Moler, and G. W.\nC Stewart, LINPACK Users' Guide, SIAM, 1979.\nC***ROUTINES CALLED CCOPY, CPOFA, CPOSL, DCDOT, R1MACH, SCASUM, XERMSG\nC***REVISION HISTORY (YYMMDD)\nC 800530 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890831 Modified array declarations. (WRB)\nC 890831 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\nC 900510 Convert XERRWV calls to XERMSG calls, cvt GOTO's to\nC IF-THEN-ELSE. (RWC)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE CPOIR\nC\n INTEGER LDA,N,ITASK,IND,INFO,J\n COMPLEX A(LDA,*),V(*),WORK(N,*)\n REAL SCASUM,XNORM,DNORM,R1MACH\n DOUBLE PRECISION DR1,DI1,DR2,DI2\n CHARACTER*8 XERN1, XERN2\nC***FIRST EXECUTABLE STATEMENT CPOIR\n IF (LDA.LT.N) THEN\n IND = -1\n WRITE (XERN1, '(I8)') LDA\n WRITE (XERN2, '(I8)') N\n CALL XERMSG ('SLATEC', 'CPOIR', 'LDA = ' // XERN1 //\n * ' IS LESS THAN N = ' // XERN2, -1, 1)\n RETURN\n ENDIF\nC\n IF (N.LE.0) THEN\n IND = -2\n WRITE (XERN1, '(I8)') N\n CALL XERMSG ('SLATEC', 'CPOIR', 'N = ' // XERN1 //\n * ' IS LESS THAN 1', -2, 1)\n RETURN\n ENDIF\nC\n IF (ITASK.LT.1) THEN\n IND = -3\n WRITE (XERN1, '(I8)') ITASK\n CALL XERMSG ('SLATEC', 'CPOIR', 'ITASK = ' // XERN1 //\n * ' IS LESS THAN 1', -3, 1)\n RETURN\n ENDIF\nC\n IF (ITASK.EQ.1) THEN\nC\nC MOVE MATRIX A TO WORK\nC\n DO 10 J=1,N\n CALL CCOPY(N,A(1,J),1,WORK(1,J),1)\n 10 CONTINUE\nC\nC FACTOR MATRIX A INTO R\nC\n CALL CPOFA(WORK,N,N,INFO)\nC\nC CHECK FOR SINGULAR OR NOT POS.DEF. MATRIX\nC\n IF (INFO.NE.0) THEN\n IND = -4\n CALL XERMSG ('SLATEC', 'CPOIR',\n * 'SINGULAR OR NOT POSITIVE DEFINITE - NO SOLUTION', -4, 1)\n RETURN\n ENDIF\n ENDIF\nC\nC SOLVE AFTER FACTORING\nC MOVE VECTOR B TO WORK\nC\n CALL CCOPY(N,V(1),1,WORK(1,N+1),1)\n CALL CPOSL(WORK,N,N,V)\nC\nC FORM NORM OF X0\nC\n XNORM = SCASUM(N,V(1),1)\n IF (XNORM.EQ.0.0) THEN\n IND = 75\n RETURN\n ENDIF\nC\nC COMPUTE RESIDUAL\nC\n DO 40 J=1,N\n CALL DCDOT(J-1,-1.D0,A(1,J),1,V(1),1,DR1,DI1)\n CALL DCDOT(N-J+1,1.D0,A(J,J),LDA,V(J),1,DR2,DI2)\n DR1 = DR1+DR2-DBLE(REAL(WORK(J,N+1)))\n DI1 = DI1+DI2-DBLE(AIMAG(WORK(J,N+1)))\n WORK(J,N+1) = CMPLX(REAL(DR1),REAL(DI1))\n 40 CONTINUE\nC\nC SOLVE A*DELTA=R\nC\n CALL CPOSL(WORK,N,N,WORK(1,N+1))\nC\nC FORM NORM OF DELTA\nC\n DNORM = SCASUM(N,WORK(1,N+1),1)\nC\nC COMPUTE IND (ESTIMATE OF NO. OF SIGNIFICANT DIGITS)\nC AND CHECK FOR IND GREATER THAN ZERO\nC\n IND = -LOG10(MAX(R1MACH(4),DNORM/XNORM))\n IF (IND.LE.0) THEN\n IND = -10\n CALL XERMSG ('SLATEC', 'CPOIR',\n * 'SOLUTION MAY HAVE NO SIGNIFICANCE', -10, 0)\n ENDIF\n RETURN\n END\n", "meta": {"hexsha": "3b9dbb51a5e4054d561aadb350052eb9e01d0ee2", "size": 7647, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/cpoir.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/cpoir.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/cpoir.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.7644230769, "max_line_length": 72, "alphanum_fraction": 0.6006276971, "num_tokens": 2366, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009642742806, "lm_q2_score": 0.7122321720225279, "lm_q1q2_score": 0.651621900970576}} {"text": " FUNCTION integral (n, x, y1, y2)\n USE stel_kinds\n IMPLICIT NONE\n!-----------------------------------------------\n! D u m m y A r g u m e n t s\n!-----------------------------------------------\n INTEGER, INTENT(IN) :: n\n REAL(rprec), INTENT(IN), DIMENSION(n) :: y1, y2 , x\n REAL(rprec), PARAMETER :: one = 1\n REAL(rprec) :: h, integral\n!------------------------------------------------------------------------------\n! WARNING: The integral formula assumes values on the half MESH,\n! that is, the independent variable is given from x(3/2) to x(M-1/2),\n! but the limits of the integral are x(1)=-1 and x(M)=1. N = M-1 is the\n! number of points on the half mesh.\n! In the current version, fulfilment of this condition is ONLY checked\n! for the case in which the interval of integration is the interval\n! of orthogonality of Legendre polynomias, i.e., [-1,1].\n! Integration formula is a 2-nd order HALF-MESH formula from\n! \"Numerical Recipes\", W.Press et al, Chapter 4, page 110.\n!------------------------------------------------------------------------------\n IF (n < 10) STOP 'Too few points to carry out integration.!'\n IF (x(n) < x(1)) STOP ' B < A in INTEGRAL!'\n IF (x(n) == one .or. x(1) == -one) STOP 'HALF MESH INTEGRAL!'\n\n h = (x(n)-x(1))/(n-1)\n integral = h* SUM(y1*y2)\n\n END FUNCTION integral\n", "meta": {"hexsha": "813398eaeade144e07c8159254a73f088040b2a5", "size": 1413, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "LIBSTELL/Sources/Miscel/integral.f", "max_stars_repo_name": "joseluisvelasco/STELLOPT", "max_stars_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 29, "max_stars_repo_stars_event_min_datetime": "2020-05-08T01:47:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-06T10:35:28.000Z", "max_issues_repo_path": "LIBSTELL/Sources/Miscel/integral.f", "max_issues_repo_name": "joseluisvelasco/STELLOPT", "max_issues_repo_head_hexsha": "e064ebb96414d5afc4e205f43b44766558dca2af", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 77, "max_issues_repo_issues_event_min_datetime": "2020-05-08T07:18:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:20:33.000Z", "max_forks_repo_path": "Sources/Miscel/integral.f", "max_forks_repo_name": "ORNL-Fusion/LIBSTELL", "max_forks_repo_head_hexsha": "ba938c678d776b84d7bb260ea541a9b45deb37e2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-02-10T13:47:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-21T12:53:43.000Z", "avg_line_length": 47.1, "max_line_length": 79, "alphanum_fraction": 0.4946921444, "num_tokens": 382, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009480320036, "lm_q2_score": 0.7122321781307374, "lm_q1q2_score": 0.6516218949907104}} {"text": " module MOD_BNUE\r\n contains\r\n PURE FUNCTION BNUE(XLAMBDA,T)\r\n !use MOD_ERROR\r\nC*** PLANCK FUNCTION, LAMBDA IN ANGSTROEM, T IN KELVIN ****************\r\nC*** BNUE IN CGS UNITS: ERG PER CM**2, PER SEC AND PER HERTZ ************\r\nC*** CONSTANTS : C1 = H * C / K (DIMENSION ANGSTROEM * KELVIN )\r\nC*** C2 = 2 * H * C (DIMENSION ANGSTROEM**3 * ERG/SEC/HZ/CM**2)\r\n IMPLICIT NONE\r\n real*8 :: BNUE, cxt\r\n real*8,intent(in) :: XLAMBDA,T\r\n real*8,parameter :: C1=1.438831D8\r\n real*8,parameter :: C2=3.972967D+8\r\n \r\n IF (T .LE. .0) THEN\r\n BNUE=.0\r\n !print '(A,f0.2,X,f0.2)','T,XLAMBDA = ',T,XLAMBDA\r\n ELSE\r\n CXT=C1/XLAMBDA/T\r\n IF (CXT.GT.500.) THEN\r\n BNUE=0.0\r\n ELSE\r\n BNUE=C2/(EXP(CXT)-1d0)/XLAMBDA**3 !/XLAMBDA/XLAMBDA\r\n ENDIF\r\n ENDIF\r\n END function\r\n end module", "meta": {"hexsha": "d034a9d817c675bc11602887308201d517a2fd10", "size": 924, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "src/bnue.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/bnue.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/bnue.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": 34.2222222222, "max_line_length": 81, "alphanum_fraction": 0.5, "num_tokens": 336, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850093037731, "lm_q2_score": 0.6959583187272711, "lm_q1q2_score": 0.6516153409246013}} {"text": "C Compute the scale at a given ring radius in km/pixel. The scale is computed\nC at the point on the visible ring closest to the camera.\nC\n SUBROUTINE RING_SCALE(OM,VSC,FL,OAL,OAS,SCALE,NL,NS,R,\n &\t\tlon,srange,rline,rsamp,rscl,ascl,ind)\n IMPLICIT NONE\n REAL*8 OM(3,3) !Camera to planet transformation matrix\n REAL*8 VSC(3) !Vector from target center to spacecraft\n REAL*4 FL !Camera focal length in mm \n REAL*4 OAL,OAS !Optical axis intercept line-sample\n REAL*4 SCALE !Picture scale in pixels/mm\n INTEGER NL,NS\t\t!Number of lines and samples in image\n REAL*8 R\t\t\t!Input ring radius\n REAL*8 LON\t\t!Output longitude\n REAL*8 SRANGE\t\t!Slant range\n REAL*8 RLINE,RSAMP !Output image coordinates\n REAL*8 RSCL,ASCL\t\t!Radial and azimuthal ring scale (km/pixel)\n INTEGER IND\t\t! =1 if RSCL and ASCL are valid, =0 otherwise\n\n REAL*8 L,S,LON0,SR,V(3),PIXELS,KILOMETERS,PI,RPD\n INTEGER I\n\n PI = 3.141592653589793D0\n RPD = PI/180.D0 !radians per degree\n\n RSCL = -999.\n ASCL = -999.\n SRANGE = 2.D+9\nC ...Scan at 1 degree increments for the point on the ring closest\nC ...to the camera (minimum slant range).\n DO 20 I=1,360\n LON0 = 1.0*I\n CALL RING_PROJ(OM,VSC,FL,OAL,OAS,SCALE,R,LON0,l,s,ind)\n IF (IND.EQ.0) GOTO 20\n IF (L.LT.1. .OR. L.GT.NL) GOTO 20\n IF (S.LT.1. .OR. S.GT.NS) GOTO 20\n V(1) = R*DCOS(LON0*RPD) - VSC(1) !Vector from camera to ring pt\n V(2) = -R*DSIN(LON0*RPD) - VSC(2)\n V(3) = - VSC(3)\n SR = DSQRT(V(1)**2 + V(2)**2 + V(3)**2) !Distance to camera\n IF (SR .GE. SRANGE) GOTO 20\n SRANGE = SR\n LON = LON0\n RLINE = L\n RSAMP = S\n 20 CONTINUE\n\n IF (SRANGE .LT. 1.D+9) GOTO 100\n\nC ...Repeat scanning for the point on the ring closest to the camera,\nC ...but without restricting it to points in the image.\n DO 30 I=1,360\n LON0 = 1.0*I\n CALL RING_PROJ(OM,VSC,FL,OAL,OAS,SCALE,R,LON0,l,s,ind)\n IF (IND.EQ.0) GOTO 30\n V(1) = R*DCOS(LON0*RPD) - VSC(1) !Vector from camera to ring pt\n V(2) = -R*DSIN(LON0*RPD) - VSC(2)\n V(3) = - VSC(3)\n SR = DSQRT(V(1)**2 + V(2)**2 + V(3)**2) !Distance to camera\n IF (SR .GE. SRANGE) GOTO 30\n SRANGE = SR\n LON = LON0\n RLINE = L\n RSAMP = S\n 30 CONTINUE\n\n IF (SRANGE .GT. 1.D+9) THEN\n SRANGE = -999.\n IND = 0\n RETURN\n ENDIF\n\nC ...Compute the arc length making up 1 deg of the ring in pixels\n 100 CALL RING_PROJ(OM,VSC,FL,OAL,OAS,SCALE,R,LON+1.,l,s,ind)\n PIXELS = DSQRT((RLINE-L)**2 + (RSAMP-S)**2)\nC ...Compute the same arc length in kilometers: S = R*DLON\n KILOMETERS = R*RPD\n ASCL = KILOMETERS/PIXELS\t\t!Azimuthal scale\n \nC ...Compute the pixels representing 1 km radial distance\n CALL RING_PROJ(OM,VSC,FL,OAL,OAS,SCALE,R+1.,LON,l,s,ind)\n PIXELS = DSQRT((RLINE-L)**2 + (RSAMP-S)**2)\n RSCL = 1./PIXELS\t\t\t!Radial scale\n RETURN\n END\n", "meta": {"hexsha": "8cff607b2833016bb619979fb6e4bcd0a5c3d078", "size": 3142, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "vos/p2/sub/ring_proj/ring_scale.f", "max_stars_repo_name": "NASA-AMMOS/VICAR", "max_stars_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2020-10-21T05:56:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T10:02:01.000Z", "max_issues_repo_path": "vos/p2/sub/ring_proj/ring_scale.f", "max_issues_repo_name": "NASA-AMMOS/VICAR", "max_issues_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "vos/p2/sub/ring_proj/ring_scale.f", "max_forks_repo_name": "NASA-AMMOS/VICAR", "max_forks_repo_head_hexsha": "4504c1f558855d9c6eaef89f4460217aa4909f8e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-03-09T01:51:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-23T00:23:24.000Z", "avg_line_length": 36.5348837209, "max_line_length": 78, "alphanum_fraction": 0.5719287078, "num_tokens": 1144, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850075259038, "lm_q2_score": 0.6959583187272711, "lm_q1q2_score": 0.6516153396872784}} {"text": "!--------------------------------------------------------------------------------\n! Copyright (c) 2016 Peter Gr\u00fcnberg Institut, Forschungszentrum J\u00fclich, 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_sgaunt\n\n USE m_clebsch\n USE m_constants,ONLY:pi_const\n\n IMPLICIT NONE\n\n CONTAINS\n SUBROUTINE sgaunt(lmax,c)\n\n !************************************************************\n !* Calculation of the Gaunt coefficients C(L2M2,L1M1,LM) *\n !* *\n !* l2m2 / * *\n !* C =C(l2m2,l1m1,lm)=\\dr*Y(r)*Y(r)*Y(r) *\n !* lm,l1m1 / lm l1m1 l2m2 *\n !* *\n !* and C.ne.0 when l2=/l1-l/,/l1-l/+2,...,l1+l,m2=m1-m *\n !* Y(lm) is a complex spherical garmonic with a phase *\n !* after Condon and Shortley *\n !* Written by S.Yu.Savrasov (P.N.Lebedev Physical Institute)*\n !************************************************************\n !* called by umtx() ; part of the LDA+U package *\n !* G.B., Oct. 2000 *\n !************************************************************\n\n INTEGER, INTENT(IN) :: lmax\n REAL, INTENT(INOUT) :: c(0:,:,:)\n\n INTEGER :: l1,m1,l ,l1m1,l2,lm,m2,ll2,m\n REAL :: aj,bj,am,bm,cj,cm,dl1,dl2,dl3,a1,a2\n\n DO l1 = 0,lmax\n DO m1 = -l1,l1\n DO l = 0,lmax\n DO m = -l,l\n l1m1 = l1*(l1+1)+m1+1\n lm = l *(l +1)+m +1\n DO l2 = ABS(l1-l),l1+l,2\n ll2 = l2/2\n m2 = m1-m\n IF (ABS(m2).LE.l2) THEN !!! selection rule\n aj = REAL(l)\n bj = REAL(l2)\n am = REAL(m)\n bm = REAL(m2)\n cj = REAL(l1)\n cm = REAL(m1)\n a1 = clebsch(aj,bj,0.0,0.0,cj,0.0) !!! Clebsch-Gordan coefficients\n a2 = clebsch(aj,bj,am,bm,cj,cm) !!! Clebsch-Gordan coefficients\n dl1 = REAL(2*l +1)\n dl2 = REAL(2*l2+1)\n dl3 = REAL(2*l1+1)\n c(ll2,l1m1,lm)=a1*a2*SQRT(dl1*dl2/dl3/4.0/pi_const)\n ELSEIF (ABS(m2).GT.l2)THEN\n c(ll2,l1m1,lm)=0.0\n ENDIF\n ENDDO\n ENDDO\n ENDDO\n ENDDO\n ENDDO\n\n END SUBROUTINE sgaunt\nEND MODULE m_sgaunt\n", "meta": {"hexsha": "d5ce9481263bf3fb379b785540a48e42dcb6046e", "size": 2947, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ldau/sgaunt.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": "ldau/sgaunt.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": "ldau/sgaunt.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": 40.9305555556, "max_line_length": 91, "alphanum_fraction": 0.3512046149, "num_tokens": 797, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039738, "lm_q2_score": 0.705785040214066, "lm_q1q2_score": 0.651467233697438}} {"text": " PROGRAM xfasper\r\nC driver for routine fasper\r\n INTEGER NP,MP,NPR\r\n REAL TWOPI\r\n PARAMETER(NP=90,MP=4096,NPR=11,TWOPI=6.2831853)\r\n INTEGER idum,j,jmax,n,nout\r\n REAL gasdev,prob,x(NP),y(NP),px(MP),py(MP)\r\n idum=-4\r\n j=0\r\n do 11 n=1,NP+10\r\n if (n.ne.3.and.n.ne.4.and.n.ne.6.and.n.ne.21.and.\r\n * n.ne.38.and.n.ne.51.and.n.ne.67.and.n.ne.68.and.\r\n * n.ne.83.and.n.ne.93) then\r\n j=j+1\r\n x(j)=n\r\n y(j)=0.75*cos(0.6*x(j))+gasdev(idum)\r\n endif\r\n11 continue\r\n call fasper(x,y,j,4.,1.,px,py,MP,nout,jmax,prob)\r\n write(*,*) 'FASPER results for test signal (cos(0.6x) + noise):'\r\n write(*,*) 'NOUT,JMAX,PROB=',nout,jmax,prob\r\n do 12 n=max(1,jmax-NPR/2),min(nout,jmax+NPR/2)\r\n write(*,*) n,TWOPI*px(n),py(n)\r\n12 continue\r\n END\r\n", "meta": {"hexsha": "2a398747eb7781c0fa5ea45c957783fade1976ea", "size": 863, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xfasper.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xfasper.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xfasper.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": 33.1923076923, "max_line_length": 71, "alphanum_fraction": 0.5237543453, "num_tokens": 329, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637648915617, "lm_q2_score": 0.7577943658046608, "lm_q1q2_score": 0.651448357521248}} {"text": "\tFUNCTION TRAPEZ(Y,N,DX)\nc\tFINDS AREA BELOW CURVE (X,Y) ACCORDING TO TRAPEZOIDAL RULE.\nc\tASSUMES EQUAL SPACING DX BETWEEN N POINTS.\n\tREAL Y(N)\n\tTRAPEZ=0.\n\tIF (N.LE.1) RETURN\n\tTRAPEZ=(Y(1) + Y(N))*DX/2.\n\tIF (N.EQ.2) RETURN\n\tA=0.\t\n\tDO I=2,N-1\n\tA = A + Y(I)\n\tENDDO\n\tTRAPEZ = TRAPEZ + A*DX\n\tRETURN\n\tEND\n", "meta": {"hexsha": "02d3078840eab38fc3efd34d018c8bc369a9f7ba", "size": 299, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "bc03/src/trapez.f", "max_stars_repo_name": "jchavesmontero/galaxpy", "max_stars_repo_head_hexsha": "ef5eaffa8f5ec0418dae44b88cf212ca03814b57", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-10-29T02:26:52.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-15T22:22:35.000Z", "max_issues_repo_path": "bc03/src/trapez.f", "max_issues_repo_name": "jchavesmontero/galaxpy", "max_issues_repo_head_hexsha": "ef5eaffa8f5ec0418dae44b88cf212ca03814b57", "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": "bc03/src/trapez.f", "max_forks_repo_name": "jchavesmontero/galaxpy", "max_forks_repo_head_hexsha": "ef5eaffa8f5ec0418dae44b88cf212ca03814b57", "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": 18.6875, "max_line_length": 61, "alphanum_fraction": 0.6454849498, "num_tokens": 141, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8596637433190939, "lm_q2_score": 0.7577943822145998, "lm_q1q2_score": 0.651448355280783}} {"text": "! $Id: TestLUPIV.f90 460 2013-03-05 09:01:48Z abuttari $\n! ------------------------------------\n! Programme principal permettant\n! de tester la factorisation LU AVEC pivotage\n! d'une matrice pleine \n! ------------------------------------\n\nprogram mainlu\n implicit none\n interface\n subroutine init(a, acopie, xexact, b, bcopie, x, y, r, &\n p,q,lda, n,ipivot)\n integer, intent(out) :: lda,n,ipivot\n double precision, dimension(:,:), allocatable, intent(out) :: a, acopie\n integer, dimension(:), allocatable , intent(out) :: p,q\n double precision, dimension(:), allocatable, intent(out) :: &\n xexact, b, bcopie, x, y, r\n end subroutine init\n end interface\n\n ! Dimension principale (taille de la structure de donn\ufffde allouee en memoire)\n integer :: lda \n ! Dimension reelle du systeme a factoriser (on factorise A(1:n,1:n))\n integer :: n\n ! Matrice a factoriser et permutation P et Q\n double precision, dimension(:,:), allocatable :: a, acopie\n integer, dimension (:), allocatable :: p, q \n ! Solution exacte, second membre, solution calculee du systeme et residu\n double precision, dimension(:), allocatable :: xexact, b, x, & \n r, bcopie\n ! Vecteur temporaire\n double precision, dimension(:), allocatable :: y\n ! Determinant = DET_Mantisse * 2^DET_Exposant\n ! Pour eviter les underflows et overflows, le mantisse\n ! et l'exposant du determinant sont separees.\n double precision :: det_mantisse\n integer :: det_exposant\n ! Scalaire local\n integer :: ierr\n ! Strat\ufffdgie de pivot\n integer :: ipivot\n ! EXTERNAL\n external norme\n double precision norme\n !\n ! --------------------------------------------\n ! Initialisation matrice A et second membre b\n ! --------------------------------------------\n ! -- definir A et Xexact puis calculer b = A xexact\n ! (faire une copie de A --> Acopie et b --> bcopie)\n ! allouer x, y et r, P\n\n call init(a, acopie, xexact, b, bcopie, x, y, r, p,q, lda, n,ipivot)\n ! -------------------------\n ! Factorisation de Gauss ( P A = L U ) et calcul du determinant\n ! -------------------------\n!! write(6,*) ' '\n!! write(6,*) ' ............................... '\n!! write(6,*) ' FACTORISATION LU A ECRIRE '\n!! write(6,*) ' ............................... '\n call facto(a, lda, n,ipivot, p,q,ierr) \n write(6,*) ' '\n if(ierr==1)then\n write(6,*) 'Echec de la factorisation' \n \n else\n ! ----------------------\n ! Algorithme de descente ( L y = Pb)\n ! ----------------------\n call descente ( a, lda, n, p, b, y)\n ! ----------------------\n ! Algorithme de remontee ( U x = y )\n ! ----------------------\n call remontee ( a, lda, n, y, x)\n\n !------------------------------------------\n ! Analyse de l'erreur :\n ! Calcul/affichage du residu || b - A x || et \n ! du residu equilibre || b - A x || / || |A||X| + |b| ||\n ! Calcul et affichage de || x - xexact\ufffd|| / || xexact ||\n !------------------------------------------\n\n!! write(6,*) ' '\n!! write(6,*) ' ............................... '\n!! write(6,*) ' ROUTINE ANALYSE ERREUR A ECRIRE '\n!! write(6,*) ' ............................... '\n call analyse_erreur (acopie,lda,n,bcopie,x,r,xexact)\n write(6,*) ' '\n endif\n \n deallocate (a, acopie, p, b, bcopie, x, r, y, xexact)\n\n\n stop\nend program mainlu\n!--------------------------------------------------------------\n!--------------------------------------------------------------\n\n\n!**************************************************\n! Subroutines utilis\ufffdes par le programme principal\n!\n!\n!**************************************************\nsubroutine init(m,mcopie,xexact,b,bcopie, &\n x,y,r,p,q,ldm,n,ipivot)\n implicit none\n ! -------------------------------------------------------------\n ! Objectif:\n ! - Tous les tableaux/matrices passes en arguments \n ! sont alloues dans la routine.\n ! - Initialisation, de la matrice M, de la solution x \n ! et du vecteur b tel que b = M x\n ! M est une matrice de dimension principale ldm avec \n ! n colonnes. \n ! Deux classes de matrices sont proposees:\n ! Classe I/ \n ! -Les matrices d'ordre pair sont diagonales dominantes\n ! -Les matrices d'ordre impair ont de petites valeurs \n ! sur la diagonale et peuvent conduire \ufffd une perte \n ! de precision dans la solution\n ! Classe II/ \n ! -12 matrices utilisant le generateur de LAPACK\n ! Soit x / x(i) = dble(i) on construit alors b = M x\n ! Une copie de M (-->Mcopie) et de b (--> bcopie) est effectuee\n ! --------------------------------------------------------------\n !\n interface\n subroutine matgen(imat, a, n, info)\n real(kind(1.d0)), allocatable :: a(:,:)\n integer :: imat, n, info\n end subroutine matgen\n end interface\n\n ! Parametres :\n ! ----------\n integer, intent(out) :: ldm,n,ipivot\n double precision, allocatable, intent(out) :: &\n m(:,:), mcopie(:,:), xexact(:), &\n b(:), bcopie(:), x(:), y(:), r(:) \n integer, allocatable, intent(out) :: p(:), q(:)\n\n ! Dimension maximale du systeme\n integer :: ldmmax=5000\n !\n ! Variables locales :\n ! -----------------\n integer :: i,j, ierr, classmat, imat\n logical :: pair\n !\n ! Fonctions intrinseques\n intrinsic dble, min\n ! -- taille du probleme\n\n classmat = 1 \n ldm = -1\n n = 0 \n do while (n.gt.ldm.or. ldm.ge.ldmmax) \n write(6,*) ' Entrer la taille de la matrice lda (< ', &\n ldmmax, ' ) ?'\n read(5,*) ldm\n write(6,*) ' Entrer la dimension reelle n (< ', ldm, ' ) ?'\n read(5,*) n\n !\n write(6,*) ' Entrer la classe de matrice ', &\n ' (1 sinon 2 (generateur LAPACK)) ?'\n read(5,*) classmat\n !\n if (classmat.eq.1) then\n ! -------------------------------\n ! Utilisation du generateur local\n ! -------------------------------\n !\n allocate(m(ldm,n), stat=ierr)\n if (ierr > 0) then\n write(6,*) ' Probleme allocation memoire :', &\n ' reduire n=', n\n stop\n endif\n !\n pair=(mod(n,2) .eq. 0)\n ! -- Initialisation de la matrice M\n ! Les matrices d'indice pair sont diagonales dominantes\n ! les matrices d'indice impair ont de petites valeurs \n ! sur la diagonale.\n if (pair) then \n do i = 1,n\n do j=1,n\n m(i,j) = dble(1)\n end do\n m(i,i) = dble(n+100)\n end do\n else\n do i = 1,n\n do j=1,n\n m(i,j) = dble(i)*dble(j)\n end do\n m(i,i) = dble(i)*sqrt(epsilon(m(i,i))) \n end do\n endif\n else\n ! -------------------------------------------------------------------\n ! Utilisation du generateur de matrices pour valider les codes LAPACK\n ! -------------------------------------------------------------------\n imat = 0\n do while (imat.le.0.or.imat.gt.12)\n write(6,*) ' Generateur de matrices de LAPACK '\n write(6,*) ' Entrer le numero de la matrice entre 1 et 12 ?'\n read(5,*) imat\n end do\n ! -- Initialisation de la matrice M\n ldm = n\n call matgen(imat, m, n, ierr)\n if (ierr.ne.0) then\n write(6,*) \" Erreur dans le gnerateur LAPACK (matgen)\"\n stop\n endif\n endif\n !\n ! -- allocation des structures de donn\ufffdes\n allocate (p(n),q(n), mcopie(ldm,n), b(n), bcopie(n), x(n), &\n r(n), y(n), xexact(n), stat=ierr)\n \n ! Strat\ufffdgie de pivot\n write(6,*) ' Entreer la strategie de pivot ', &\n '0: sans pivot, 1 : pivot partiel, 2 : recherche du noyau'\n read(5,*) ipivot\n \t \n end do\n if (ierr > 0) then\n write(6,*) ' Probleme allocation memoire :', &\n ' reduire n=', n\n stop\n endif\n ! Copie de la matrice\n mcopie = m\n ! -- Initialisation de la solution exacte dans xexact\n do i=1,n\n xexact(i) = dble(i)\n end do\n !\n ! -- Calcul de b / b = A xexact\n do i = 1, n\n b(i) = dble(0)\n do j=1,n\n b(i) = b(i) + m(i,j) * xexact(j)\n enddo\n enddo\n ! Sauvegarde de b\n bcopie = b\n\n ! -- impression des donnees\n if (n.le.10) then\n write (6,*) ' Matrice initiale A = '\n do i = 1,min(n,6)\n write(6,'(A,I3,6(E14.5))') ' ... Ligne ', i, m(i,1:min(n,6))\n end do\n write (6,'(A,6(E14.5))') ' xexact =', xexact(1:min(n,6))\n write (6,'(A,6(E14.5))') ' b =', b(1:min(n,6))\n endif\n\n return\nend subroutine init\n!\n!\n!**************************************************\nsubroutine facto(m, ldm, n, ipivot, p, q, ierr)\n implicit none\n ! ------------------------------------------------------\n ! Objectifs: Factorisation LU AVEC pivotage\n ! 1/ Calculer L / P M = L U\n ! La matrice M est de dimension principale ldm.\n ! On factorise le bloc M(1:n, 1:n) \n ! par l'algorithme de factorisation LU sans pivotage \n ! comme present\ufffd en cours.\n !\n ! Calculer le determinant\n !\n ! En entr\ufffde la matrice M est \ufffdcras\ufffde en sortie\n ! par les facteurs L et U.\n !\n ! IERR > 0 si un pivot trop petit\n ! a \ufffdt\ufffd rencontr\ufffd durant factorisation \n ! ------------------------------------------------------\n !\n ! Parametres :\n ! ----------\n integer, intent(in) :: ldm,n,ipivot\n double precision, intent(inout) :: m(ldm,n) ! matrice\n integer, intent(out) :: p(n) ! permutation des lignes\n integer, intent(out) ::q(n) ! permutation des colonnes\n integer, intent(out) :: ierr \n ! \n ! Interface\n interface\n double precision function norme_f ( a, n,m)\n integer, intent(in) :: n,m\n double precision, intent(in) :: a(n,m)\n end function norme_f\n end interface\n\n ! Fonctions intrinseques\n intrinsic epsilon\n \n ! Variables locales :\n ! -----------------\n ! Indices de boucle\n integer :: i,j,k\n\n double precision :: eps\n \n ! epsilon machine (pour v\ufffdrifier si pas d pivot trop petit)\n eps = epsilon(eps)\n\n ! initialisation de la permutation (identit\ufffd)\n do k = 1, n\n p(k) = k\n end do\n\n !!!!!!!!!!!!!!!!! A ECRIRE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \n !!Etape de factorisation LU avec trois strat\ufffdgies de pivot : \n !! sans pivot (ipivot =0), avec pivot partiel (ipivot=1),\n !! recherche du noyau pour matrice non inversible (ipivot>1) \n do j = 1, n-1\n if (abs(m(j, j)) < eps) then\n ierr = ierr + 1\n end if\n m(j+1:n, j) = m(j+1:n, j) / m(j, j);\n !m(j+1:n, j+1:n) = m(j+1:n, j+1:n) - matmul(m(j+1:n, j), m(j, j+1:n))\n end do\n \n ! -- impression des donnees :\n ! -- determinant\n write(6,*) \" ==============================================\"\n write(6,*) \" Fin de la FACTORISATION \" \n write(6,*) \" ========================\" \n write(6,*) \" ... AFFICHER DETERMINANT de la matrice \" \n \n \n if (n.le.6) then\n write (6,*) ' ... Matrice factorisee par ligne : '\n do i = 1,n \n write(6,'(6(E14.5))') m(i,1:n)\n end do \n write (6,*) \" ... Permutation P : \", P(1:n)\n write (6,*) \" ... Permutation Q : \", Q(1:n)\n endif\n write(6,*) \" ==============================================\"\n\n return\nend subroutine facto\n\n!**************************************************\nsubroutine descente (m,ldm,n,p,b,x)\n implicit none\n ! -----------------------------------------------------------\n ! Objectif:\n ! Resoudre L x = P b avec \n ! L la partie triangulaire inferieure de la matrice M,\n ! de dimension principale ldm et de n colonnes.\n ! Algorithme avec report:\n ! cet algorithme a assez naturellement tendance\n ! \ufffd modifier le second membre ce qui n'est \n ! ni une bonne propriete ni\n ! indispensable comme le montre l'implementation fournie ici\n ! -------------------------------------------------------------\n ! \n ! Parametres :\n ! ----------\n integer, intent(in) :: ldm,n\n double precision, intent(in) :: m(ldm,n)\n integer, intent(in) :: p(n)\n ! attention assez naturellement on va \n ! lors du report modifier b \n ! ( MAIS uniquement si on est peu attentif !)\n double precision, intent(in) :: b(n)\n double precision, intent(out) :: x(n)\n !\n ! Variables locales :\n ! -----------------\n ! Indices de boucle\n integer :: i,j\n double precision :: xtemp\n !\n ! Algorithme avec report sans modification de b\n !\n\n x = b\n \n ! Ecrire la prise en compte de la permutation P en permutant\n ! le second membre qui est maintenant dans x\n write(6,*)\"Descente : permutation P non prise en compte\" \n \n \n do i = 1, n\n ! calcul du x(i)\n ! L a des 1 sur la diagonale (non stockes dans M!)\n ! report de la connaissance de x(i) sur es second membres.\n ! pour eviter de modifier b on note \n ! qu'a chaque etape i, les parties\n ! modifiees de b et calculees de x forment une partition de {1,..,n}\n do j = i+1, n\n ! --- avec modification de b:\n ! --- b(j) = b(j) - M(j,i) * x(i) \n ! sans modification de b:\n x(j) = x(j) - m(j,i) * x(i)\n end do\n end do\n ! write (6,*) \" En sortie de la descente Ly = b: \"\n ! write (6,'(A,6(E14.5))') ' b =', b(1:min(n,6))\n ! write (6,'(A,6(E14.5))') ' y =', x(1:min(n,6))\n\n return\nend subroutine descente\n!\n!**************************************************\nsubroutine remontee (m,ldm,n,b,x)\n implicit none\n ! ------------------------------------------------------\n ! Objectif:\n ! Resoudre U x = b avec \n ! U la partie triangulaire superieure de la matrice M,\n ! de dimension principale ldm et de n colonnes.\n ! Algorithme sans report.\n ! ------------------------------------------------------\n ! \n ! Parametres :\n ! ----------\n integer, intent(in) :: ldm,n\n double precision, intent(in) :: m(ldm,n), b(n) \n double precision, intent(out) :: x(n)\n !\n ! Variables locales :\n ! -----------------\n ! Indices de boucle\n integer :: i,j\n ! Permutation\n double precision :: xtemp\n \n ! Algorithme sans report.\n do i = n, 1, -1\n x(i) = b(i)\n ! on reporte la connaissance des x(j) pour j> i\n ! et on va chercher M(i,j) dans la triangulaire inferieure\n do j = i+1, n\n x(i) = x(i) - m(i,j) * x(j)\n end do\n x(i) = x(i) / m(i,i)\n end do\n \n ! write (6,*) \" En sortie de la remontee Ux = y: \"\n ! write (6,'(A,6(E14.5))') ' y =', b(1:min(n,6))\n ! write (6,'(A,6(E14.5))') ' x =', x(1:min(n,6))\n return\nend subroutine remontee\n\n!**************************************************\nsubroutine analyse_erreur(m,ldm,n,b,x,r,xexact)\n implicit none\n ! ------------------------------------------------------------\n ! Objectif:\n ! Analyse de l'erreur :\n ! Calcul et affichage de || b - M x || / || |M||X| + |b| ||\n ! Calcul et affichage de || x - xexact\ufffd|| / || xexact ||\n ! M etant une matrice carree de\n ! dimension principale ldm et de n colonnes. \n ! -------------------------------------------------------------\n !\n ! Parametres :\n ! ----------\n integer, intent(in) :: ldm,n\n double precision, intent(in) :: m(ldm,n), x(n), b(n)\n double precision, intent(out) :: r(n)\n double precision, intent(in) :: xexact(n)\n\n ! Interfaces\n interface\n double precision function norme ( x, n)\n integer, intent(in) :: n\n double precision, intent(in) :: x(n)\n end function norme\n\n double precision function norme_f ( a, n,m)\n integer, intent(in) :: n,m\n double precision, intent(in) :: a(n,m)\n end function norme_f\n end interface\n\n\n !\n ! Variables locales :\n ! -----------------\n ! Indices de boucles\n integer :: i, j\n\n!!!!!!!!!!!!!!!!! A ECRIRE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!! Calcul et affichage de des erreurs relatives directe et inverse\n!! Calcul et afffichage de la norme du r\ufffdsidu \n write(6,*) \"Analyse erreur non faite \"\n\n\n write(6,*) \" \"\n write(6,*) \" ==============================================\"\n write(6,*) \" Analyse d'ERREUR \"\n write(6,*) \" ================ \"\n write(6,'(A,6(E14.5))') ' xexact =', xexact(1:min(n,6))\n write(6,'(A,6(E14.5))') ' xcalcule =', x(1:min(n,6))\n write(6,*) \" ==============================================\"\n\n return\nend subroutine analyse_erreur\n\n!**************************************************\nsubroutine noyau (m,ldm,n,q,kstop,x)\n implicit none\n ! ------------------------------------------------------\n ! Objectif:\n ! Calculer une base du noyau depuis la factorisation incomplete\n ! Arret de la factosiation \ufffd l'\ufffdtape kstop\n ! Ker (AQ) = Im[-U11^(-1)*U12;Ir]\n ! \n ! \n ! ------------------------------------------------------\n ! \n ! Parametres :\n ! ----------\n integer, intent(in) :: ldm,n,kstop\n double precision, intent(in) :: m(ldm,n) ! facto LU incomplete de PAQ\n integer, intent(in) :: q(n) ! permutation des colonnes\n double precision, intent(out) :: x(n,n-kstop+1) ! base du noyau\n !\n ! Variables locales :\n ! -----------------\n ! Indices de boucle\n integer :: i,j,l\n \n !!!!!!!!!!!!!!!!! A ECRIRE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!! Calcul d'une base du noyau de A\n\n\n write (6,*) \"Base du noyau non calculee\"\n \n return\nend subroutine noyau\n\n!**************************************************\ndouble precision function norme ( x, n)\n implicit none\n ! ---------------------------------------\n ! Objectif: NORME = || x || , with 2 norm\n ! ----------------------------------------\n integer, intent(in) :: n\n double precision, intent(in) :: x(n)\n !\n ! Variables locales :\n ! -----------------\n ! Indices de boucles\n integer :: i\n !\n ! Fonctions intrinseques\n intrinsic sqrt, dble\n\n norme = dble(0)\n do i=1, n\n norme = norme + x(i) *x(i)\n enddo\n norme = sqrt(norme)\n\n return\nend function norme\n\n!**************************************************\ndouble precision function norme_f ( a, n,m)\n implicit none\n ! ---------------------------------------\n ! Objectif: NORME_F = || A ||, avec norme de Frobenius\n ! ----------------------------------------\n integer, intent(in) :: n, m\n double precision, intent(in) :: a(n,m)\n !\n ! Variables locales :\n ! -----------------\n ! Indices de boucles\n integer :: i,j\n !\n ! Fonctions intrinseques\n intrinsic sqrt, dble\n\n norme_f = dble(0)\n do j=1,m\n do i=1,n\n norme_f = norme_f + a(i,j)*a(i,j)\n enddo\n enddo \n norme_f = sqrt(norme_f)\n\n return\nend function norme_f\n\n\n\n", "meta": {"hexsha": "a950b7c135b7659c639bfa129378f7e8ba0bb6d0", "size": 18840, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Calcul_Scientifique/TP2/TestLUPIV.f90", "max_stars_repo_name": "Hathoute/ENSEEIHT", "max_stars_repo_head_hexsha": "d42f0b0dedb269e6df3b1c006d4d45e52fc518b8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-06-26T21:51:11.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-26T21:51:11.000Z", "max_issues_repo_path": "Calcul_Scientifique/TP2/TestLUPIV.f90", "max_issues_repo_name": "Hathoute/ENSEEIHT", "max_issues_repo_head_hexsha": "d42f0b0dedb269e6df3b1c006d4d45e52fc518b8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Calcul_Scientifique/TP2/TestLUPIV.f90", "max_forks_repo_name": "Hathoute/ENSEEIHT", "max_forks_repo_head_hexsha": "d42f0b0dedb269e6df3b1c006d4d45e52fc518b8", "max_forks_repo_licenses": ["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.2956810631, "max_line_length": 81, "alphanum_fraction": 0.4736730361, "num_tokens": 5511, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190939, "lm_q2_score": 0.7577943767446202, "lm_q1q2_score": 0.65144835057844}} {"text": "*DECK CINVIT\n SUBROUTINE CINVIT (NM, N, AR, AI, WR, WI, SELECT, MM, M, ZR, ZI,\n + IERR, RM1, RM2, RV1, RV2)\nC***BEGIN PROLOGUE CINVIT\nC***PURPOSE Compute the eigenvectors of a complex upper Hessenberg\nC associated with specified eigenvalues using inverse\nC iteration.\nC***LIBRARY SLATEC (EISPACK)\nC***CATEGORY D4C2B\nC***TYPE COMPLEX (INVIT-S, CINVIT-C)\nC***KEYWORDS EIGENVALUES, EIGENVECTORS, EISPACK\nC***AUTHOR Smith, B. T., et al.\nC***DESCRIPTION\nC\nC This subroutine is a translation of the ALGOL procedure CXINVIT\nC by Peters and Wilkinson.\nC HANDBOOK FOR AUTO. COMP. VOL.II-LINEAR ALGEBRA, 418-439(1971).\nC\nC This subroutine finds those eigenvectors of A COMPLEX UPPER\nC Hessenberg matrix corresponding to specified eigenvalues,\nC using inverse iteration.\nC\nC On INPUT\nC\nC NM must be set to the row dimension of the two-dimensional\nC array parameters, AR, AI, ZR and ZI, as declared in the\nC calling program dimension statement. NM is an INTEGER\nC variable.\nC\nC N is the order of the matrix A=(AR,AI). N is an INTEGER\nC variable. N must be less than or equal to NM.\nC\nC AR and AI contain the real and imaginary parts, respectively,\nC of the complex upper Hessenberg matrix. AR and AI are\nC two-dimensional REAL arrays, dimensioned AR(NM,N)\nC and AI(NM,N).\nC\nC WR and WI contain the real and imaginary parts, respectively,\nC of the eigenvalues of the matrix. The eigenvalues must be\nC stored in a manner identical to that of subroutine COMLR,\nC which recognizes possible splitting of the matrix. WR and\nC WI are one-dimensional REAL arrays, dimensioned WR(N) and\nC WI(N).\nC\nC SELECT specifies the eigenvectors to be found. The\nC eigenvector corresponding to the J-th eigenvalue is\nC specified by setting SELECT(J) to .TRUE. SELECT is a\nC one-dimensional LOGICAL array, dimensioned SELECT(N).\nC\nC MM should be set to an upper bound for the number of\nC eigenvectors to be found. MM is an INTEGER variable.\nC\nC On OUTPUT\nC\nC AR, AI, WI, and SELECT are unaltered.\nC\nC WR may have been altered since close eigenvalues are perturbed\nC slightly in searching for independent eigenvectors.\nC\nC M is the number of eigenvectors actually found. M is an\nC INTEGER variable.\nC\nC ZR and ZI contain the real and imaginary parts, respectively,\nC of the eigenvectors corresponding to the flagged eigenvalues.\nC The eigenvectors are normalized so that the component of\nC largest magnitude is 1. Any vector which fails the\nC acceptance test is set to zero. ZR and ZI are\nC two-dimensional REAL arrays, dimensioned ZR(NM,MM) and\nC ZI(NM,MM).\nC\nC IERR is an INTEGER flag set to\nC Zero for normal return,\nC -(2*N+1) if more than MM eigenvectors have been requested\nC (the MM eigenvectors calculated to this point are\nC in ZR and ZI),\nC -K if the iteration corresponding to the K-th\nC value fails (if this occurs more than once, K\nC is the index of the last occurrence); the\nC corresponding columns of ZR and ZI are set to\nC zero vectors,\nC -(N+K) if both error situations occur.\nC\nC RV1 and RV2 are one-dimensional REAL arrays used for\nC temporary storage, dimensioned RV1(N) and RV2(N).\nC They hold the approximate eigenvectors during the inverse\nC iteration process.\nC\nC RM1 and RM2 are two-dimensional REAL arrays used for\nC temporary storage, dimensioned RM1(N,N) and RM2(N,N).\nC These arrays hold the triangularized form of the upper\nC Hessenberg matrix used in the inverse iteration process.\nC\nC The ALGOL procedure GUESSVEC appears in CINVIT in-line.\nC\nC Calls PYTHAG(A,B) for sqrt(A**2 + B**2).\nC Calls CDIV for complex division.\nC\nC Questions and comments should be directed to B. S. Garbow,\nC APPLIED MATHEMATICS DIVISION, ARGONNE NATIONAL LABORATORY\nC ------------------------------------------------------------------\nC\nC***REFERENCES B. T. Smith, J. M. Boyle, J. J. Dongarra, B. S. Garbow,\nC Y. Ikebe, V. C. Klema and C. B. Moler, Matrix Eigen-\nC system Routines - EISPACK Guide, Springer-Verlag,\nC 1976.\nC***ROUTINES CALLED CDIV, PYTHAG\nC***REVISION HISTORY (YYMMDD)\nC 760101 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890831 Modified array declarations. (WRB)\nC 890831 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE CINVIT\nC\n INTEGER I,J,K,M,N,S,II,MM,MP,NM,UK,IP1,ITS,KM1,IERR\n REAL AR(NM,*),AI(NM,*),WR(*),WI(*),ZR(NM,*),ZI(NM,*)\n REAL RM1(N,*),RM2(N,*),RV1(*),RV2(*)\n REAL X,Y,EPS3,NORM,NORMV,GROWTO,ILAMBD,RLAMBD,UKROOT\n REAL PYTHAG\n LOGICAL SELECT(N)\nC\nC***FIRST EXECUTABLE STATEMENT CINVIT\n IERR = 0\n UK = 0\n S = 1\nC\n DO 980 K = 1, N\n IF (.NOT. SELECT(K)) GO TO 980\n IF (S .GT. MM) GO TO 1000\n IF (UK .GE. K) GO TO 200\nC .......... CHECK FOR POSSIBLE SPLITTING ..........\n DO 120 UK = K, N\n IF (UK .EQ. N) GO TO 140\n IF (AR(UK+1,UK) .EQ. 0.0E0 .AND. AI(UK+1,UK) .EQ. 0.0E0)\n 1 GO TO 140\n 120 CONTINUE\nC .......... COMPUTE INFINITY NORM OF LEADING UK BY UK\nC (HESSENBERG) MATRIX ..........\n 140 NORM = 0.0E0\n MP = 1\nC\n DO 180 I = 1, UK\n X = 0.0E0\nC\n DO 160 J = MP, UK\n 160 X = X + PYTHAG(AR(I,J),AI(I,J))\nC\n IF (X .GT. NORM) NORM = X\n MP = I\n 180 CONTINUE\nC .......... EPS3 REPLACES ZERO PIVOT IN DECOMPOSITION\nC AND CLOSE ROOTS ARE MODIFIED BY EPS3 ..........\n IF (NORM .EQ. 0.0E0) NORM = 1.0E0\n EPS3 = NORM\n 190 EPS3 = 0.5E0*EPS3\n IF (NORM + EPS3 .GT. NORM) GO TO 190\n EPS3 = 2.0E0*EPS3\nC .......... GROWTO IS THE CRITERION FOR GROWTH ..........\n UKROOT = SQRT(REAL(UK))\n GROWTO = 0.1E0 / UKROOT\n 200 RLAMBD = WR(K)\n ILAMBD = WI(K)\n IF (K .EQ. 1) GO TO 280\n KM1 = K - 1\n GO TO 240\nC .......... PERTURB EIGENVALUE IF IT IS CLOSE\nC TO ANY PREVIOUS EIGENVALUE ..........\n 220 RLAMBD = RLAMBD + EPS3\nC .......... FOR I=K-1 STEP -1 UNTIL 1 DO -- ..........\n 240 DO 260 II = 1, KM1\n I = K - II\n IF (SELECT(I) .AND. ABS(WR(I)-RLAMBD) .LT. EPS3 .AND.\n 1 ABS(WI(I)-ILAMBD) .LT. EPS3) GO TO 220\n 260 CONTINUE\nC\n WR(K) = RLAMBD\nC .......... FORM UPPER HESSENBERG (AR,AI)-(RLAMBD,ILAMBD)*I\nC AND INITIAL COMPLEX VECTOR ..........\n 280 MP = 1\nC\n DO 320 I = 1, UK\nC\n DO 300 J = MP, UK\n RM1(I,J) = AR(I,J)\n RM2(I,J) = AI(I,J)\n 300 CONTINUE\nC\n RM1(I,I) = RM1(I,I) - RLAMBD\n RM2(I,I) = RM2(I,I) - ILAMBD\n MP = I\n RV1(I) = EPS3\n 320 CONTINUE\nC .......... TRIANGULAR DECOMPOSITION WITH INTERCHANGES,\nC REPLACING ZERO PIVOTS BY EPS3 ..........\n IF (UK .EQ. 1) GO TO 420\nC\n DO 400 I = 2, UK\n MP = I - 1\n IF (PYTHAG(RM1(I,MP),RM2(I,MP)) .LE.\n 1 PYTHAG(RM1(MP,MP),RM2(MP,MP))) GO TO 360\nC\n DO 340 J = MP, UK\n Y = RM1(I,J)\n RM1(I,J) = RM1(MP,J)\n RM1(MP,J) = Y\n Y = RM2(I,J)\n RM2(I,J) = RM2(MP,J)\n RM2(MP,J) = Y\n 340 CONTINUE\nC\n 360 IF (RM1(MP,MP) .EQ. 0.0E0 .AND. RM2(MP,MP) .EQ. 0.0E0)\n 1 RM1(MP,MP) = EPS3\n CALL CDIV(RM1(I,MP),RM2(I,MP),RM1(MP,MP),RM2(MP,MP),X,Y)\n IF (X .EQ. 0.0E0 .AND. Y .EQ. 0.0E0) GO TO 400\nC\n DO 380 J = I, UK\n RM1(I,J) = RM1(I,J) - X * RM1(MP,J) + Y * RM2(MP,J)\n RM2(I,J) = RM2(I,J) - X * RM2(MP,J) - Y * RM1(MP,J)\n 380 CONTINUE\nC\n 400 CONTINUE\nC\n 420 IF (RM1(UK,UK) .EQ. 0.0E0 .AND. RM2(UK,UK) .EQ. 0.0E0)\n 1 RM1(UK,UK) = EPS3\n ITS = 0\nC .......... BACK SUBSTITUTION\nC FOR I=UK STEP -1 UNTIL 1 DO -- ..........\n 660 DO 720 II = 1, UK\n I = UK + 1 - II\n X = RV1(I)\n Y = 0.0E0\n IF (I .EQ. UK) GO TO 700\n IP1 = I + 1\nC\n DO 680 J = IP1, UK\n X = X - RM1(I,J) * RV1(J) + RM2(I,J) * RV2(J)\n Y = Y - RM1(I,J) * RV2(J) - RM2(I,J) * RV1(J)\n 680 CONTINUE\nC\n 700 CALL CDIV(X,Y,RM1(I,I),RM2(I,I),RV1(I),RV2(I))\n 720 CONTINUE\nC .......... ACCEPTANCE TEST FOR EIGENVECTOR\nC AND NORMALIZATION ..........\n ITS = ITS + 1\n NORM = 0.0E0\n NORMV = 0.0E0\nC\n DO 780 I = 1, UK\n X = PYTHAG(RV1(I),RV2(I))\n IF (NORMV .GE. X) GO TO 760\n NORMV = X\n J = I\n 760 NORM = NORM + X\n 780 CONTINUE\nC\n IF (NORM .LT. GROWTO) GO TO 840\nC .......... ACCEPT VECTOR ..........\n X = RV1(J)\n Y = RV2(J)\nC\n DO 820 I = 1, UK\n CALL CDIV(RV1(I),RV2(I),X,Y,ZR(I,S),ZI(I,S))\n 820 CONTINUE\nC\n IF (UK .EQ. N) GO TO 940\n J = UK + 1\n GO TO 900\nC .......... IN-LINE PROCEDURE FOR CHOOSING\nC A NEW STARTING VECTOR ..........\n 840 IF (ITS .GE. UK) GO TO 880\n X = UKROOT\n Y = EPS3 / (X + 1.0E0)\n RV1(1) = EPS3\nC\n DO 860 I = 2, UK\n 860 RV1(I) = Y\nC\n J = UK - ITS + 1\n RV1(J) = RV1(J) - EPS3 * X\n GO TO 660\nC .......... SET ERROR -- UNACCEPTED EIGENVECTOR ..........\n 880 J = 1\n IERR = -K\nC .......... SET REMAINING VECTOR COMPONENTS TO ZERO ..........\n 900 DO 920 I = J, N\n ZR(I,S) = 0.0E0\n ZI(I,S) = 0.0E0\n 920 CONTINUE\nC\n 940 S = S + 1\n 980 CONTINUE\nC\n GO TO 1001\nC .......... SET ERROR -- UNDERESTIMATE OF EIGENVECTOR\nC SPACE REQUIRED ..........\n 1000 IF (IERR .NE. 0) IERR = IERR - N\n IF (IERR .EQ. 0) IERR = -(2 * N + 1)\n 1001 M = S - 1\n RETURN\n END\n", "meta": {"hexsha": "26265102eb4cd9624c77cefc256dd725b59d5196", "size": 10571, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "slatec/src/cinvit.f", "max_stars_repo_name": "andremirt/v_cond", "max_stars_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "slatec/src/cinvit.f", "max_issues_repo_name": "andremirt/v_cond", "max_issues_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "slatec/src/cinvit.f", "max_forks_repo_name": "andremirt/v_cond", "max_forks_repo_head_hexsha": "6b5c364d7cd4243686488b2bd4318be3927e07ea", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.0033112583, "max_line_length": 72, "alphanum_fraction": 0.5306971904, "num_tokens": 3521, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637397236823, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.651448343151514}} {"text": "program test_fluid\n use fluid\n implicit none\n ! Fluid solver class.\n type(FluidSlv) :: FldSlv2D, FldSlv3D\n ! Names of variables.\n character(len=:), dimension(:), allocatable :: names2D, names3D\n ! Dimensions of the simulation domains.\n integer :: whd2D(2), whd3D(3)\n ! Simulation parameters.\n real(dp) :: scale, safety\n ! Density.\n real(dp) :: rho, timestep\n ! Add in flow coordinates.\n type(Vec2D2) :: xi2D\n type(Vec2D) :: xi\n real(dp) :: initial_cond(3)\n ! Time\n real(dp) :: t\n ! Timers\n integer :: startvalues(8), endvalues(8), startcount, endcount\n real(4) :: countrate\n ! Counter\n integer :: i, j\n ! Arrays\n real(dp), allocatable :: u(:,:), prhs(:)\n real(dp) :: celsiz\n real(dp) :: coefficients(16)\n\n ! Initialise names.\n allocate(character(len=8) :: names2D(4))\n\n ! Test 2D.1: Initialise Fluid.\n ! Safety factor.\n safety = 1._dp\n ! Grid scale.\n scale = 1._dp\n ! 10x10 2D grid with sides of length 3 (each box is of size 1x1).\n whd2D = 5\n ! Density.\n rho = 0.1_dp\n ! Initial timestep.\n timestep = 0.005\n ! Names\n names2D(1)(:) = \"Density.\"\n names2D(2)(:) = \"Vx.\"\n names2D(3)(:) = \"Vy.\"\n call FldSlv2D % Init(names2D, whd2D, rho, timestep, scale, safety)\n\n xi2D % x = [0.2_dp, .7_dp, 0.2_dp, 0.7_dp]\n initial_cond = [5.0_dp, 1.0_dp, 1.0_dp]\n xi % x = [0.5_dp, 0.5_dp]\n\n call FldSlv2D % InitFlow(xi2D, initial_cond)\n\n print*, \"Slow Cubic interpolation: \", FldSlv2D % u(1) % Cerp(xi), new_line(new_line(\"\"))\n\n\n coefficients = FldSlv2D % u(1) % BcC2D(xi)\n\n do i = 1, 16\n print*,i, coefficients(i)\n end do\n print*, new_line(new_line(\"\"))\n\n print*, \"Quick Cubic interpolation: \", FldSlv2D % u(1) % QuickCerp2D(xi, FldSlv2D % u(1) % BcC2D(xi)), new_line(new_line(\"\"))\nend program test_fluid\n", "meta": {"hexsha": "940946e3389030280cd03e227e65cb266a14dc82", "size": 1748, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "fluid_dynamics/fscg/better_advection/test_fluid.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": "fluid_dynamics/fscg/better_advection/test_fluid.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": "fluid_dynamics/fscg/better_advection/test_fluid.f08", "max_forks_repo_name": "dcelisgarza/applied_math", "max_forks_repo_head_hexsha": "a8a6e49ce225392bafffb02b51c22299ffb9d20e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.7058823529, "max_line_length": 127, "alphanum_fraction": 0.6332951945, "num_tokens": 666, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637361282706, "lm_q2_score": 0.7577943658046608, "lm_q1q2_score": 0.651448335724588}} {"text": " REAL FUNCTION CSEDVIS(SED) \n REAL::SED,VISR,WTL,WTH,VISL,VISH\nC CHANGE RECORD \nC \nC \nC ** CALCULATES KINEMATIC VISCOSITY OF HIGH CONCENTRATION COHESIVE \nC ** SEDIMENT-WATER MIXTURE BASED ON \nC ** \nC ** MEHTA, A. J., AND F.JIANG, 1990: SOME OBSERVATIONS ON BOTTOM \nC ** MUD MOTION DUE TO WAVES. COASTAL AND OCEANOGRAPHIC ENGINEERING \nC ** DEPARTMENT, UNIVERSITY OF FLORIDA, GAINESVILLE, FL32661 \nC \n IF(SED.LE.25667.) VISR=0.116883E-3*SED \n IF(SED.GE.36667.) VISR=1.52646E-6*SED+3.125 \n IF(SED.GT.25667.0.AND.SED.LT.36667.0)THEN \n WTL=(36667.-SED)/11000. \n WTH=(SED-25667.)/11000. \n VISL=0.116883E-3*25667 \n VISH=1.52646E-6*36667.+3.125 \n VISR=WTL*VISL+WTH*VISH \n ENDIF \n CSEDVIS=1.E-6*(10.**VISR) \n RETURN \n END \n\n", "meta": {"hexsha": "e603b1b0d25a26be21d10c0aa6ce13ec0bd8777e", "size": 823, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "EFDC_src/CSEDVIS.f", "max_stars_repo_name": "T-Carlotto/SW2D-EFDC", "max_stars_repo_head_hexsha": "7b01a41a308cb79db569a0e6291fe40797f3ef28", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 32, "max_stars_repo_stars_event_min_datetime": "2018-03-31T22:19:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-14T01:35:23.000Z", "max_issues_repo_path": "EFDC_src/CSEDVIS.f", "max_issues_repo_name": "T-Carlotto/SW2D-EFDC", "max_issues_repo_head_hexsha": "7b01a41a308cb79db569a0e6291fe40797f3ef28", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-04-02T06:13:13.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-10T07:15:07.000Z", "max_forks_repo_path": "EFDC_src/CSEDVIS.f", "max_forks_repo_name": "T-Carlotto/SW2D-EFDC", "max_forks_repo_head_hexsha": "7b01a41a308cb79db569a0e6291fe40797f3ef28", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 15, "max_forks_repo_forks_event_min_datetime": "2018-06-27T02:55:23.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-09T07:51:23.000Z", "avg_line_length": 31.6538461538, "max_line_length": 70, "alphanum_fraction": 0.6123936817, "num_tokens": 327, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693702514737, "lm_q2_score": 0.6859494614282923, "lm_q1q2_score": 0.6514251930589439}} {"text": "module fcn_mxsquared_px\n use mod_kinds, only: rk,ik\n use type_function, only: function_t\n use type_point, only: point_t\n use mod_constants, only: ONE\n implicit none\n private\n\n\n\n !> x-squared function.\n !!\n !! \\f$ f(t,\\vec{x}) = x^2 \\f$\n !!\n !! @author Nathan A. Wukie\n !! @date 2/1/2016\n !!\n !-------------------------------------------------------------------------\n type, extends(function_t), public :: mxsquared_px_f\n\n contains\n\n procedure :: init\n procedure :: compute\n\n end type mxsquared_px_f\n !**************************************************************************\n\n\n\ncontains\n\n\n !>\n !!\n !! @author Nathan A. Wukie\n !! @date 2/2/2016\n !!\n !-------------------------------------------------------------------------\n subroutine init(self)\n class(mxsquared_px_f), intent(inout) :: self\n\n !\n ! Set function name\n !\n call self%set_name(\"-x_squared+x\")\n\n\n !\n ! Set function options to default settings\n !\n\n\n end subroutine init\n !*************************************************************************\n\n\n\n\n !>\n !! @author Nathan A. Wukie\n !! @date 2/2/2016\n !!\n !!\n !--------------------------------------------------------------------------\n impure elemental function compute(self,time,coord) result(val)\n class(mxsquared_px_f), intent(inout) :: self\n real(rk), intent(in) :: time\n type(point_t), intent(in) :: coord\n\n real(rk) :: val\n\n ! f(x) = -x**2+x\n val = -(ONE) * coord%c1_ * coord%c1_ + coord%c1_\n\n end function compute\n !**************************************************************************\n\n\nend module fcn_mxsquared_px\n", "meta": {"hexsha": "612406a11505898fb4b947b1f528a68c83065ce8", "size": 1844, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/functions/elementary/fcn_mxsquared_px.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/functions/elementary/fcn_mxsquared_px.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/functions/elementary/fcn_mxsquared_px.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": 22.7654320988, "max_line_length": 79, "alphanum_fraction": 0.3877440347, "num_tokens": 439, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117812622842, "lm_q2_score": 0.7879311956428946, "lm_q1q2_score": 0.6513920022620587}} {"text": "\nsubroutine sum(x, res)\n implicit none\n real, intent(in) :: x(:)\n real, intent(out) :: res\n\n integer :: i\n\n !print *, \"sum: size(x) = \", size(x)\n\n res = 0.0\n\n do i = 1, size(x)\n res = res + x(i)\n enddo\n\nend subroutine sum\n\nfunction fsum(x) result (res)\n implicit none\n real, intent(in) :: x(:)\n real :: res\n\n integer :: i\n\n !print *, \"fsum: size(x) = \", size(x)\n\n res = 0.0\n\n do i = 1, size(x)\n res = res + x(i)\n enddo\n\nend function fsum\n", "meta": {"hexsha": "b301710f5dda005e67e40cc21a5e0d62d0ec116a", "size": 460, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "crabageprediction/venv/Lib/site-packages/numpy/f2py/tests/src/assumed_shape/foo_free.f90", "max_stars_repo_name": "13rianlucero/CrabAgePrediction", "max_stars_repo_head_hexsha": "92bc7fbe1040f49e820473e33cc3902a5a7177c7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 20453, "max_stars_repo_stars_event_min_datetime": "2015-01-02T09:00:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:35:56.000Z", "max_issues_repo_path": "venv/lib/python3.7/site-packages/numpy/f2py/tests/src/assumed_shape/foo_free.f90", "max_issues_repo_name": "John1001Song/Big-Data-Robo-Adviser", "max_issues_repo_head_hexsha": "9444dce96954c546333d5aecc92a06c3bfd19aa5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 14862, "max_issues_repo_issues_event_min_datetime": "2015-01-01T01:28:34.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T23:48:52.000Z", "max_forks_repo_path": "venv/lib/python3.7/site-packages/numpy/f2py/tests/src/assumed_shape/foo_free.f90", "max_forks_repo_name": "John1001Song/Big-Data-Robo-Adviser", "max_forks_repo_head_hexsha": "9444dce96954c546333d5aecc92a06c3bfd19aa5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 9362, "max_forks_repo_forks_event_min_datetime": "2015-01-01T15:49:43.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T21:26:51.000Z", "avg_line_length": 13.1428571429, "max_line_length": 39, "alphanum_fraction": 0.5434782609, "num_tokens": 169, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7879311856832191, "lm_q2_score": 0.8267117898012104, "lm_q1q2_score": 0.6513920007563639}} {"text": "C Copyright(C) 1999-2020 National Technology & Engineering Solutions\nC of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with\nC NTESS, the U.S. Government retains certain rights in this software.\nC\nC See packages/seacas/LICENSE for details\n\nC ... Calculate nodal volume...\n\n SUBROUTINE PRNVOL (NDIM, CRD, IX, NUMNP, NUMEL, NNODE,\n & VOLUME, IUNIT)\n\n DIMENSION CRD(NUMNP, *), IX(NNODE,*)\n DIMENSION GRADOP(8)\n REAL volume(*)\n\n IF (NDIM .EQ. 3 .AND. NNODE .EQ. 8) THEN\n do 10 i = 1, numnp\n volume(i) = 0.0\n 10 continue\n\n DO 20 IEL = 1, numel\n y1 = crd(ix(1,iel),2)\n y2 = crd(ix(2,iel),2)\n y3 = crd(ix(3,iel),2)\n y4 = crd(ix(4,iel),2)\n y5 = crd(ix(5,iel),2)\n y6 = crd(ix(6,iel),2)\n y7 = crd(ix(7,iel),2)\n y8 = crd(ix(8,iel),2)\n\n Z1 = crd(ix(1,iel),3)\n Z2 = crd(ix(2,iel),3)\n Z3 = crd(ix(3,iel),3)\n Z4 = crd(ix(4,iel),3)\n Z5 = crd(ix(5,iel),3)\n Z6 = crd(ix(6,iel),3)\n Z7 = crd(ix(7,iel),3)\n Z8 = crd(ix(8,iel),3)\n\n Z24 = Z2 - Z4\n Z52 = Z5 - Z2\n Z45 = Z4 - Z5\n GRADOP(1) = ( Y2*(Z6-Z3-Z45) + Y3*Z24 + Y4*(Z3-Z8-Z52)\n * + Y5*(Z8-Z6-Z24) + Y6*Z52 + Y8*Z45 ) / 12.\n Z31 = Z3 - Z1\n Z63 = Z6 - Z3\n Z16 = Z1 - Z6\n GRADOP(2) = ( Y3*(Z7-Z4-Z16) + Y4*Z31 + Y1*(Z4-Z5-Z63)\n * + Y6*(Z5-Z7-Z31) + Y7*Z63 + Y5*Z16 ) / 12.\n Z42 = Z4 - Z2\n Z74 = Z7 - Z4\n Z27 = Z2 - Z7\n GRADOP(3) = ( Y4*(Z8-Z1-Z27) + Y1*Z42 + Y2*(Z1-Z6-Z74)\n * + Y7*(Z6-Z8-Z42) + Y8*Z74 + Y6*Z27 ) / 12.\n Z13 = Z1 - Z3\n Z81 = Z8 - Z1\n Z38 = Z3 - Z8\n GRADOP(4) = ( Y1*(Z5-Z2-Z38) + Y2*Z13 + Y3*(Z2-Z7-Z81)\n * + Y8*(Z7-Z5-Z13) + Y5*Z81 + Y7*Z38 ) / 12.\n Z86 = Z8 - Z6\n Z18 = Z1 - Z8\n Z61 = Z6 - Z1\n GRADOP(5) = ( Y8*(Z4-Z7-Z61) + Y7*Z86 + Y6*(Z7-Z2-Z18)\n * + Y1*(Z2-Z4-Z86) + Y4*Z18 + Y2*Z61 ) / 12.\n Z57 = Z5 - Z7\n Z25 = Z2 - Z5\n Z72 = Z7 - Z2\n GRADOP(6) = ( Y5*(Z1-Z8-Z72) + Y8*Z57 + Y7*(Z8-Z3-Z25)\n * + Y2*(Z3-Z1-Z57) + Y1*Z25 + Y3*Z72 ) / 12.\n Z68 = Z6 - Z8\n Z36 = Z3 - Z6\n Z83 = Z8 - Z3\n GRADOP(7) = ( Y6*(Z2-Z5-Z83) + Y5*Z68 + Y8*(Z5-Z4-Z36)\n * + Y3*(Z4-Z2-Z68) + Y2*Z36 + Y4*Z83 ) / 12.\n Z75 = Z7 - Z5\n Z47 = Z4 - Z7\n Z54 = Z5 - Z4\n GRADOP(8) = ( Y7*(Z3-Z6-Z54) + Y6*Z75 + Y5*(Z6-Z1-Z47)\n * + Y4*(Z1-Z3-Z75) + Y3*Z47 + Y1*Z54 ) / 12.\n\n EVOL = crd(ix(1,iel),1) * GRADOP(1)\n * + crd(ix(2,iel),1) * GRADOP(2)\n * + crd(ix(3,iel),1) * GRADOP(3)\n * + crd(ix(4,iel),1) * GRADOP(4)\n * + crd(ix(5,iel),1) * GRADOP(5)\n * + crd(ix(6,iel),1) * GRADOP(6)\n * + crd(ix(7,iel),1) * GRADOP(7)\n * + crd(ix(8,iel),1) * GRADOP(8)\n if (volume(iel) .lt. 0.0) then\n write (*,*) 'Zero or negative volume at element',\n & iel\n endif\n\n do 15 i=1, 8\n node = ix(i,iel)\n volume(node) = volume(node) + EVOL / 8.0\n 15 continue\n 20 CONTINUE\n\nC ... Special for Frank Dempsey -- Print volumes and connectivity to file\n tvol = 0.0\n DO 30 I=1, NUMNP\n write (IUNIT,999) i, volume(i)\n tvol = tvol + volume(i)\n 999 format(i8,1PE17.8)\n 30 CONTINUE\n write (iunit, 998) tvol\n 998 format(/,'Total Volume = ',1pe17.8)\n ELSE\n STOP 'Not Implemented'\n END IF\n RETURN\n END\n\n", "meta": {"hexsha": "d316a1892917f6e9a03a540290d8ab892441a8b1", "size": 3697, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "packages/seacas/applications/numbers/nu_prnvol.f", "max_stars_repo_name": "jschueller/seacas", "max_stars_repo_head_hexsha": "14c34ae08b757cba43a3a03ec0f129c8a168a9d3", "max_stars_repo_licenses": ["Python-2.0", "Zlib", "BSD-2-Clause", "MIT", "NetCDF", "BSL-1.0", "X11", "BSD-3-Clause"], "max_stars_count": 82, "max_stars_repo_stars_event_min_datetime": "2016-02-04T18:38:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T03:01:49.000Z", "max_issues_repo_path": "packages/seacas/applications/numbers/nu_prnvol.f", "max_issues_repo_name": "jschueller/seacas", "max_issues_repo_head_hexsha": "14c34ae08b757cba43a3a03ec0f129c8a168a9d3", "max_issues_repo_licenses": ["Python-2.0", "Zlib", "BSD-2-Clause", "MIT", "NetCDF", "BSL-1.0", "X11", "BSD-3-Clause"], "max_issues_count": 206, "max_issues_repo_issues_event_min_datetime": "2015-11-20T01:57:47.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:12:04.000Z", "max_forks_repo_path": "packages/seacas/applications/numbers/nu_prnvol.f", "max_forks_repo_name": "jschueller/seacas", "max_forks_repo_head_hexsha": "14c34ae08b757cba43a3a03ec0f129c8a168a9d3", "max_forks_repo_licenses": ["Python-2.0", "Zlib", "BSD-2-Clause", "MIT", "NetCDF", "BSL-1.0", "X11", "BSD-3-Clause"], "max_forks_count": 68, "max_forks_repo_forks_event_min_datetime": "2016-01-13T22:46:51.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T06:25:05.000Z", "avg_line_length": 32.147826087, "max_line_length": 75, "alphanum_fraction": 0.4433324317, "num_tokens": 1583, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789468908171, "lm_q2_score": 0.7279754607093178, "lm_q1q2_score": 0.6513847758662716}} {"text": "SUBROUTINE elmat(area,rho,emm)\r\n!\r\n! This subroutine forms the \"analytical\" lumped mass matrix for\r\n! quadrilateral 4- or 8-node plane strain elements.\r\n!\r\n IMPLICIT NONE\r\n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\r\n REAL(iwp),INTENT(IN)::area,rho \r\n REAL(iwp),INTENT(OUT)::emm(:,:)\r\n REAL(iwp)::zero=0.0_iwp,pt2=0.2_iwp,pt25=0.25_iwp\r\n INTEGER::i,ndof\r\n ndof=UBOUND(emm,1)\r\n emm=zero\r\n SELECT CASE(ndof)\r\n CASE(8) \r\n DO i=1,8\r\n emm(i,i)=pt25*area*rho\r\n END DO\r\n CASE(16)\r\n DO i=1,16\r\n emm(i,i)=pt2*area*rho\r\n END DO\r\n DO i=1,13,4\r\n emm(i,i)=pt25*emm(3,3)\r\n END DO\r\n DO i=2,14,4\r\n emm(i,i)=pt25*emm(3,3)\r\n END DO \r\n CASE DEFAULT\r\n WRITE(*,*)\"Wrong number of nodes for rectangular element\"\r\n END SELECT\r\nRETURN\r\nEND SUBROUTINE elmat \r\n\r\n", "meta": {"hexsha": "c401cdf32b50d206e5cd7639ab8513b64b6be2de", "size": 797, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "src/libs/main/elmat.f03", "max_stars_repo_name": "leemargetts/PoreFEM", "max_stars_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/libs/main/elmat.f03", "max_issues_repo_name": "leemargetts/PoreFEM", "max_issues_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/libs/main/elmat.f03", "max_forks_repo_name": "leemargetts/PoreFEM", "max_forks_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.7714285714, "max_line_length": 64, "alphanum_fraction": 0.6210790464, "num_tokens": 290, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894745194283, "lm_q2_score": 0.7279754489059775, "lm_q1q2_score": 0.6513847693896245}} {"text": "SUBROUTINE interp(k,dtim,rt,rl,al,nstep)\r\n!\r\n! This subroutine forms the load/time functions by interpolation.\r\n! If dtim is not an exact multiple it stops one short.\r\n!\r\n IMPLICIT NONE\r\n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\r\n REAL(iwp),INTENT(IN)::dtim,rt(:),rl(:)\r\n INTEGER,INTENT(IN)::k,nstep\r\n REAL(iwp),INTENT(IN OUT)::al(:,:)\r\n INTEGER::np,i,j\r\n REAL(iwp)::t,val \r\n np=SIZE(rt)\r\n al(1,k)=rl(1)\r\n t=rt(1)\r\n DO j=2,nstep\r\n t=t+dtim\r\n DO i=2,np\r\n IF(t.LE.rt(i))THEN\r\n val=rl(i-1)+((t-rt(i-1))/(rt(i)-rt(i-1)))*(rl(i)-rl(i-1))\r\n EXIT\r\n END IF\r\n END DO\r\n al(j,k)=val\r\n END DO\r\nRETURN\r\nEND SUBROUTINE interp\r\n", "meta": {"hexsha": "1f4e17b8ebdd4fea4f37cc6e04ae34a7e7f4ed89", "size": 646, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "src/libs/main/interp.f03", "max_stars_repo_name": "leemargetts/PoreFEM", "max_stars_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/libs/main/interp.f03", "max_issues_repo_name": "leemargetts/PoreFEM", "max_issues_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/libs/main/interp.f03", "max_forks_repo_name": "leemargetts/PoreFEM", "max_forks_repo_head_hexsha": "23be1d3fa3091bcb4ec114a319b402feb5cba7d3", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.0714285714, "max_line_length": 66, "alphanum_fraction": 0.6083591331, "num_tokens": 228, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969136, "lm_q2_score": 0.7279754548076477, "lm_q1q2_score": 0.6513847665006617}} {"text": "c\nc spatialFilter routine -- Apply a fixed spatial filter (smoother) in lat/lon and then average over times/grids\nc\nc Designed to be called from python using f2py.\nc\nc\nc Low Pass Filter = 1/9 * [1 1 1 ! normalization = 9\nc 1 1 1\nc 1 1 1]\nc\nc Gaussian Filter = 1/16 * [1 2 1 ! normalization = 16\nc 2 4 2\nc 1 2 1]\nc\n\n subroutine spatialFilter_f(var, mask,\n & time, lat, lon,\n & filter, normalization,\n & missingValue,\n & verbose,\n & vinterp, vcount, status,\n & ntime, nlat, nlon)\n\n implicit none\n integer*4 ntime, nlat, nlon\nc ! prepared 3D array of variable data over time, lon, & lat\n real*4 var(ntime, nlat, nlon)\nc ! variable to be interpolated, over ntime epochs\n integer*1 mask(ntime, nlat, nlon)\nc ! pixel quality mask\n integer*4 time(ntime)\nc ! time epochs to gaussian-interpolate over\n real*4 lat(nlat)\n ! latitude corrdinate vector\n real*4 lon(nlon)\n ! longitude corrdinate vector\ncf2py intent(in) var, mask, time, lat, lon !! annotations for f2py processor\n\n integer*4 filter(3, 3)\nc ! 3x3 filter coefficients as integers\n integer*4 normalization\nc ! Normalization factor for the filter, divide by sum of integers\ncf2py intent(in) filter, normalization\n\n real*4 missingValue\nc ! value to mark missing values in interp result\n integer*4 verbose\nc ! integer to set verbosity level\ncf2py intent(in) missingValue, verbose\n\n real*4 vinterp(nlat, nlon)\nc ! interpolated variable using gaussians, missing values not counted\n integer*4 vcount(nlat, nlon)\nc ! count of good data, might be zero after masking\n integer*4 status\nc ! negative status indicates error\ncf2py intent(out) vinterp, vcount, status\n\n integer*4 iin, jin, kin\n integer*4 i, j, fac, count\n real*4 val, sum\n\n write(6, *) 'Echoing inputs ...'\n write(6, *) 'ntime, nlat, nlon:', ntime, nlat, nlon\n write(6, *) 'filter:', filter\n write(6, *) 'normalization', normalization\n write(6, *) 'missingValue:', missingValue\n\n status = 0\n\n if (verbose .gt. 3) then\n write(6, *) 'time:', time\n write(6, *) 'lat:', lat\n write(6, *) 'lon:', lon\nc write(6, *) 'mask(3):', mask(3,:,:)\n write(6, *) 'var(3):', var(3,:,:)\n end if\n\n do i = 1, nlat\n if (verbose .gt. 1) write(6, *) lat(i)\n do j = 1, nlon\n vinterp(i,j) = 0.0\n vcount(i,j) = 0.0\n if (verbose .gt. 3) then\n write(6, *) '(i,j) = ', i, j\n write(6, *) '(lat,lon) = ', lat(i), lon(j)\n end if\n\n do kin = 1, ntime\n sum = 0.0\n count = 0\n do iin = -1, +1\n if (i+iin .lt. 1 .or. i+iin .gt. nlat) cycle\n do jin = -1, +1\n if (j+jin .lt. 1 .or. j+jin .gt. nlon) cycle\n\n if (mask(kin,iin,jin) .eq. 0) then\n fac = filter(iin+2, jin+2)\n val = var(kin,iin,jin)\n sum = sum + fac * val\n count = count + fac\n end if\n end do\n end do\n if (count .gt. 0) then\nc ! filter for (i,j) pixel isn't empty\n vinterp(i,j) = vinterp(i,j) + sum / normalization\n vcount(i,j) = vcount(i,j) + 1\n end if\n end do\n if (vcount(i,j) .gt. 0) then\n vinterp(i,j) = vinterp(i,j) / vcount(i,j)\nc ! compute mean over number of non-empty times/grids\n else\n vinterp(i,j) = missingValue\n end if\n end do\n end do\n return\n end\n\n", "meta": {"hexsha": "1b705b44abc827bbc62e0212bec4de0694b61c65", "size": 4218, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "climatology/clim/spatialFilter_f.f", "max_stars_repo_name": "tloubrieu-jpl/incubator-sdap-nexus", "max_stars_repo_head_hexsha": "5bf903f04f12eb27f25ea2aa738c617ca404a87b", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2016-08-09T22:45:14.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-17T08:18:29.000Z", "max_issues_repo_path": "climatology/clim/spatialFilter_f.f", "max_issues_repo_name": "ifenty/incubator-sdap-nexus", "max_issues_repo_head_hexsha": "3059c66f53d3f3d24c74d557c7632bdcc7f1eeec", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 35, "max_issues_repo_issues_event_min_datetime": "2018-01-11T00:50:20.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-17T23:08:07.000Z", "max_forks_repo_path": "climatology/clim/spatialFilter_f.f", "max_forks_repo_name": "ifenty/incubator-sdap-nexus", "max_forks_repo_head_hexsha": "3059c66f53d3f3d24c74d557c7632bdcc7f1eeec", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 25, "max_forks_repo_forks_event_min_datetime": "2017-11-16T07:36:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-03T20:48:46.000Z", "avg_line_length": 34.5737704918, "max_line_length": 111, "alphanum_fraction": 0.4724988146, "num_tokens": 1154, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894604912849, "lm_q2_score": 0.7279754489059775, "lm_q1q2_score": 0.6513847591774806}} {"text": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\ncc cc\ncc mnsphe : sphere test program cc\ncc cc\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\n real teta(192),phi(192),r(192),w(192),tp(30),tt(30),c(300),\n * p(9),t(9),f(81),wrk1(12000),wrk2(72)\n integer iwrk(300)\n real eps,fp,pi,pi2,pi4,s,scale,scp,sct,ai\n integer i,ier,iopt,j,kwrk,lwrk1,lwrk2,l1,l2,l,m,np,npest,nt,ntest\n * ,is,i1,i2,nc,ntt,npp\n real atan,testsp\nc set constants\n pi4 = atan(0.1e+01)\n pi = pi4*4\n pi2 = pi+pi\n scale = pi4/0.45e+02\nc we fetch the number of data points.\n m = 192\nc we fetch and print the latitude - longitude coordinates of the data\nc points (in degrees).\n write(6,900)\n write(6,905)\n l2 = 0\n do 10 i=1,48\n l1 = l2+1\n l2 = l2+4\n read(5,910) (teta(l),phi(l),l=l1,l2)\n write(6,915)(teta(l),phi(l),l=l1,l2)\n 10 continue\nc we set up the weights, scale into radians the latitude-longitude\nc coordinates and calculate the function values.\n do 20 i=1,m\n w(i) = 0.1e+01\n teta(i) = teta(i)*scale\n phi(i) = phi(i)*scale\n if(teta(i).gt.pi) teta(i) = pi\n if(phi(i).gt.pi2) phi(i) = pi2\n r(i) = testsp(teta(i),phi(i))\n 20 continue\nc we set up the coordinates of the grid points for the evaluation of\nc the spline approximations.\n sct = pi/8\n scp = pi2/8\n do 30 i=1,8\n ai = i-1\n t(i) = ai*sct\n p(i) = ai*scp\n 30 continue\n t(9) = pi\n p(9) = pi2\nc we set up the dimension information\n ntest = 15\n npest = 19\n lwrk1 = 12000\n lwrk2 = 72\n kwrk = 300\nc we choose a value for eps\n eps = 0.1e-05\nc main loop for the different spline approximations\n do 300 is=1,4\n go to (110,120,130,140),is\nc we start computing the least-squares constrained polynomial (large s)\n 110 iopt = 0\n s = 500.\n go to 200\nc iopt = 1 from the second call on.\n 120 iopt = 1\n s = 135.\n go to 200\n 130 s = 15.\n go to 200\nc a least-squares spherical spline with specified knots.\n 140 iopt = -1\nc we set up the number of knots.\n nt = 11\n np = 15\nc we set up the position of the interior knots of the spline.\n ntt = nt-8\n do 150 i=1,ntt\n ai = i\n j = i+4\n tt(j) = ai*pi4\n 150 continue\n npp = np-8\n do 160 i=1,npp\n ai = i\n j = i+4\n tp(j) = ai*pi4\n 160 continue\nc determination of the spline approximation.\n 200 call sphere(iopt,m,teta,phi,r,w,s,ntest,npest,eps,nt,tt,\n * np,tp,c,fp,wrk1,lwrk1,wrk2,lwrk2,iwrk,kwrk,ier)\nc printing of the fitting results.\n if(iopt.ge.0) go to 210\n write(6,920)\n go to 220\n 210 write(6,925)\n write(6,930) s\n 220 write(6,935) fp,ier\n write(6,940) nt\n write(6,945)\n write(6,950) (tt(i),i=1,nt)\n write(6,955) np\n write(6,945)\n write(6,950) (tp(i),i=1,np)\n nc = (nt-4)*(np-4)\n write(6,960)\n write(6,965) (c(i),i=1,nc)\nc evaluation of the spline approximation.\n call bispev(tt,nt,tp,np,c,3,3,t,9,p,9,f,wrk2,lwrk2,\n * iwrk,kwrk,ier)\n write(6,970) (p(i),i=1,9)\n write(6,975)\n i2 = 0\n do 230 i=1,9\n i1 = i2+1\n i2 = i2+9\n write(6,980) t(i),(f(j),j=i1,i2)\n 230 continue\n 300 continue\n stop\nc format statements.\n 900 format(55h1latitude-longitude values of the data points (degrees))\n 905 format(1h0,4(3x,10hteta phi,3x))\n 910 format(8f6.0)\n 915 format(1h ,4(3x,f4.0,2x,f4.0,3x))\n 920 format(50h0least-squares spline approximation on the sphere.)\n 925 format(32h0smoothing spline on the sphere.)\n 930 format(20h smoothing factor s=,f9.0)\n 935 format(1x,23hsum squared residuals =,e15.6,5x,11herror flag=,i3)\n 940 format(1x,45htotal number of knots in the teta-direction =,i3)\n 945 format(1x,22hposition of the knots )\n 950 format(5x,8f8.4)\n 955 format(1x,44htotal number of knots in the phi-direction =,i3)\n 960 format(23h0b-spline coefficients )\n 965 format(5x,8f9.4)\n 970 format(9h phi,9f7.3)\n 975 format(6h teta)\n 980 format(1h ,f6.3,2x,9f7.3)\n end\n real function testsp(v,u)\nc function program testsp calculates the value of a test function for\nc the sphere package.\nc ..\n real cos,cu,cv,rad1,rad2,rad3,sin,sqrt,su,sv,u,v\n cu = cos(u)\n cv = cos(v)\n su = sin(u)\n sv = sin(v)\n rad1 = (cu*sv*0.2)**2+(su*sv)**2+(cv*0.5)**2\n rad2 = (cu*sv)**2+(su*sv*0.5)**2+(cv*0.2)**2\n rad3 = (cu*sv*0.5)**2+(su*sv*0.2)**2+cv**2\n testsp = 1./sqrt(rad1) + 1./sqrt(rad2) + 1./sqrt(rad3)\n return\n end\n", "meta": {"hexsha": "bdab06f9e1d4552fb580888f8ee1a64020a1b08f", "size": 4954, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ApproxSpline/Resources/F77-Sources/ex/mnsphe.f", "max_stars_repo_name": "modelica-3rdparty/ApproxSpline", "max_stars_repo_head_hexsha": "28420f5c1a88c9cd069defbd8c05e4a78a090675", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-07-13T17:24:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-18T16:16:02.000Z", "max_issues_repo_path": "ApproxSpline/Resources/F77-Sources/ex/mnsphe.f", "max_issues_repo_name": "tbeu/ApproxSpline", "max_issues_repo_head_hexsha": "28420f5c1a88c9cd069defbd8c05e4a78a090675", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2019-03-28T09:08:23.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T07:35:48.000Z", "max_forks_repo_path": "ApproxSpline/Resources/F77-Sources/ex/mnsphe.f", "max_forks_repo_name": "modelica-3rdparty/ApproxSpline", "max_forks_repo_head_hexsha": "28420f5c1a88c9cd069defbd8c05e4a78a090675", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-10-21T07:46:49.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T20:02:06.000Z", "avg_line_length": 31.5541401274, "max_line_length": 72, "alphanum_fraction": 0.5633831247, "num_tokens": 1834, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894604912848, "lm_q2_score": 0.7279754489059774, "lm_q1q2_score": 0.6513847591774804}} {"text": "*DECK DCSEVL\n DOUBLE PRECISION FUNCTION DCSEVL (X, CS, N)\nC***BEGIN PROLOGUE DCSEVL\nC***PURPOSE Evaluate a Chebyshev series.\nC***LIBRARY SLATEC (FNLIB)\nC***CATEGORY C3A2\nC***TYPE DOUBLE PRECISION (CSEVL-S, DCSEVL-D)\nC***KEYWORDS CHEBYSHEV SERIES, FNLIB, SPECIAL FUNCTIONS\nC***AUTHOR Fullerton, W., (LANL)\nC***DESCRIPTION\nC\nC Evaluate the N-term Chebyshev series CS at X. Adapted from\nC a method presented in the paper by Broucke referenced below.\nC\nC Input Arguments --\nC X value at which the series is to be evaluated.\nC CS array of N terms of a Chebyshev series. In evaluating\nC CS, only half the first coefficient is summed.\nC N number of terms in array CS.\nC\nC***REFERENCES R. Broucke, Ten subroutines for the manipulation of\nC Chebyshev series, Algorithm 446, Communications of\nC the A.C.M. 16, (1973) pp. 254-256.\nC L. Fox and I. B. Parker, Chebyshev Polynomials in\nC Numerical Analysis, Oxford University Press, 1968,\nC page 56.\nC***ROUTINES CALLED D1MACH, XERMSG\nC***REVISION HISTORY (YYMMDD)\nC 770401 DATE WRITTEN\nC 890831 Modified array declarations. (WRB)\nC 890831 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\nC 900329 Prologued revised extensively and code rewritten to allow\nC X to be slightly outside interval (-1,+1). (WRB)\nC 920501 Reformatted the REFERENCES section. (WRB)\nC***END PROLOGUE DCSEVL\n DOUBLE PRECISION B0, B1, B2, CS(*), ONEPL, TWOX, X, D1MACH\n LOGICAL FIRST\n SAVE FIRST, ONEPL\n DATA FIRST /.TRUE./\nC***FIRST EXECUTABLE STATEMENT DCSEVL\n IF (FIRST) ONEPL = 1.0D0 + D1MACH(4)\n FIRST = .FALSE.\n IF (N .LT. 1) CALL XERMSG ('SLATEC', 'DCSEVL',\n + 'NUMBER OF TERMS .LE. 0', 2, 2)\n IF (N .GT. 1000) CALL XERMSG ('SLATEC', 'DCSEVL',\n + 'NUMBER OF TERMS .GT. 1000', 3, 2)\n IF (ABS(X) .GT. ONEPL) CALL XERMSG ('SLATEC', 'DCSEVL',\n + 'X OUTSIDE THE INTERVAL (-1,+1)', 1, 1)\nC\n B1 = 0.0D0\n B0 = 0.0D0\n TWOX = 2.0D0*X\n DO 10 I = 1,N\n B2 = B1\n B1 = B0\n NI = N + 1 - I\n B0 = TWOX*B1 - B2 + CS(NI)\n 10 CONTINUE\nC\n DCSEVL = 0.5D0*(B0-B2)\nC\n RETURN\n END\n", "meta": {"hexsha": "7cff4065136d03e09c007e78f93943bb05803204", "size": 2364, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Modules/ThirdParty/Netlib/src/netlib/slatec/dcsevl.f", "max_stars_repo_name": "floryst/ITK", "max_stars_repo_head_hexsha": "321e673bcbac15aae2fcad863fd0977b7fbdb3e9", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 945, "max_stars_repo_stars_event_min_datetime": "2015-01-09T00:43:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T08:23:02.000Z", "max_issues_repo_path": "Modules/ThirdParty/Netlib/src/netlib/slatec/dcsevl.f", "max_issues_repo_name": "floryst/ITK", "max_issues_repo_head_hexsha": "321e673bcbac15aae2fcad863fd0977b7fbdb3e9", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2354, "max_issues_repo_issues_event_min_datetime": "2015-02-04T21:54:21.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T20:58:21.000Z", "max_forks_repo_path": "Modules/ThirdParty/Netlib/src/netlib/slatec/dcsevl.f", "max_forks_repo_name": "floryst/ITK", "max_forks_repo_head_hexsha": "321e673bcbac15aae2fcad863fd0977b7fbdb3e9", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 566, "max_forks_repo_forks_event_min_datetime": "2015-01-04T14:26:57.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T20:33:18.000Z", "avg_line_length": 35.8181818182, "max_line_length": 69, "alphanum_fraction": 0.6214043993, "num_tokens": 839, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951104066293, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6513549582544939}} {"text": "!234567890\n subroutine spline(f,x,n,t,d2f)\n! constructs a spline assuming periodic boundary conditions\n! input: coordinate x, function value f, number of points n, period t\n! output: second derivatives d2f\n implicit none\n integer n,nm\n double precision x(n),f(n),d2f(n),t\n integer ii,jj,iperm(n),nperm\n double precision cmat(n,n)\n\n do ii=1,n\n do jj=1,n\n cmat(ii,jj)=0.d0\n enddo\n enddo\n d2f(1)=(f(2)-f(1))/(x(2)-x(1)) &\n& -(f(1)-f(n))/(x(1)-x(n)+t)\n cmat(1,n)=(x(1)-x(n)+t)/6.d0\n cmat(1,1)=(x(2)-x(n)+t)/3.d0\n cmat(1,2)=(x(2)-x(1))/6.d0\n do jj=2,n-1\n d2f(jj)=(f(jj+1)-f(jj))/(x(jj+1)-x(jj)) &\n& -(f(jj)-f(jj-1))/(x(jj)-x(jj-1))\n cmat(jj,jj-1)=(x(jj)-x(jj-1))/6.d0\n cmat(jj,jj)=(x(jj+1)-x(jj-1))/3.d0\n cmat(jj,jj+1)=(x(jj+1)-x(jj))/6.d0\n enddo\n d2f(n)=(f(1)-f(n))/(x(1)-x(n)+t) &\n& -(f(n)-f(n-1))/(x(n)-x(n-1))\n cmat(n,n-1)=(x(n)-x(n-1))/6.d0\n cmat(n,n)=(x(1)-x(n-1)+t)/3.d0\n cmat(n,1)=(x(1)-x(n)+t)/6.d0\n\n call loupd(cmat,n,n,iperm,nperm)\n\n call baksublu(cmat,d2f,n,n,iperm)\n\n return\n end\n\n!*************************************************************************\n\n subroutine dspline(f,x,d2f,n,df)\n! constructs table of first derivatives of spline function\n! through values f on grid n with second derivatives d2f\n implicit none\n integer n\n double precision f(n),x(n),d2f(n),df(n)\n integer ii,jj\n\n do ii=1,n-1\n df(ii)=(f(ii+1)-f(ii))/(x(ii+1)-x(ii)) &\n& -(x(ii+1)-x(ii))*d2f(ii)/3.d0 &\n& -(x(ii+1)-x(ii))*d2f(ii+1)/6.d0\n enddo\n df(n)=(f(n)-f(n-1))/(x(n)-x(n-1)) &\n& +(x(n)-x(n-1))*d2f(n-1)/6.d0 &\n& +(x(n)-x(n-1))*d2f(n)/3.d0\n\n return\n end\n\n\n!*************************************************************************\n\n subroutine dsplv(f,x,t,d2f,n,xv,dfv)\n! first derivative of spline function\n! through values f on grid n with second derivatives d2f\n implicit none\n integer n\n double precision f(n),x(n),t,d2f(n),xv,dfv\n integer ii,jj\n integer ihi,ilo\n double precision aa,bb,dx\n\n if (xv.lt.x(1)) then\n ihi=1\n ilo=n\n dx=x(ihi)-x(ilo)+t\n else\n ihi=n\n ilo=1\n 100 if (ihi-ilo.gt.1) then\n ii=(ihi+ilo)/2\n if (x(ii).gt.xv) then\n ihi=ii\n else\n ilo=ii\n endif\n goto 100\n endif\n dx=x(ihi)-x(ilo)\n endif\n aa=(x(ihi)-xv)/dx\n bb=1-aa\n dfv=(f(ihi)-f(ilo))/dx &\n& -dx*d2f(ilo)*(3*aa**2-1.d0)/6.d0 &\n& +dx*d2f(ihi)*(3*bb**2-1.d0)/6.d0\n\n return\n end\n\n\n!*************************************************************************\n\n subroutine evalspline(f,x,t,d2f,n,xv,fv)\n! evaluate spline through periodic function f on points x \n! with second derivatives d2f at value xv and period t, returning fv\n implicit none\n integer n\n double precision f(n),x(n),d2f(n),t\n double precision xv,fv\n integer ihi,ilo,ii\n double precision aa,bb,dx,f1,f2\n\n if (xv.lt.x(1)) then\n ihi=1\n ilo=n\n dx=x(ihi)-x(ilo)+t\n else\n ihi=n\n ilo=1\n 100 if (ihi-ilo.gt.1) then\n ii=(ihi+ilo)/2\n if (x(ii).gt.xv) then\n ihi=ii\n else\n ilo=ii\n endif\n goto 100\n endif\n dx=x(ihi)-x(ilo)\n endif\n aa=(x(ihi)-xv)/dx\n bb=1-aa\n fv=aa*f(ilo)+bb*f(ihi) &\n& +((aa**3-aa)*d2f(ilo)+(bb**3-bb)*d2f(ihi))*dx**2/6.d0\n\n return\n end\n", "meta": {"hexsha": "79fa77ea344dd5ff587b220d325d7e38ae986868", "size": 3695, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/nwpw/gw/Transfer/spline.f90", "max_stars_repo_name": "dinisAbranches/nwchem", "max_stars_repo_head_hexsha": "21cb07ff634475600ab687882652b823cad8c0cd", "max_stars_repo_licenses": ["ECL-2.0"], "max_stars_count": 317, "max_stars_repo_stars_event_min_datetime": "2017-11-20T21:29:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T11:48:24.000Z", "max_issues_repo_path": "src/nwpw/gw/Transfer/spline.f90", "max_issues_repo_name": "dinisAbranches/nwchem", "max_issues_repo_head_hexsha": "21cb07ff634475600ab687882652b823cad8c0cd", "max_issues_repo_licenses": ["ECL-2.0"], "max_issues_count": 356, "max_issues_repo_issues_event_min_datetime": "2017-12-05T01:38:12.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T02:28:21.000Z", "max_forks_repo_path": "src/nwpw/gw/Transfer/spline.f90", "max_forks_repo_name": "dinisAbranches/nwchem", "max_forks_repo_head_hexsha": "21cb07ff634475600ab687882652b823cad8c0cd", "max_forks_repo_licenses": ["ECL-2.0"], "max_forks_count": 135, "max_forks_repo_forks_event_min_datetime": "2017-11-19T18:36:44.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T02:28:49.000Z", "avg_line_length": 26.0211267606, "max_line_length": 74, "alphanum_fraction": 0.4565629229, "num_tokens": 1325, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951025545426, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6513549521939117}} {"text": " REAL FUNCTION SASINH(X)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc>> 2001-05-25 SASINH Krogh Minor change for making .f90 version.\nC>> 1996-04-01 SASINH Krogh Converted to Fortran 77 from SFTRAN.\nC>> 1995-10-24 SASINH Krogh Removed blanks in numbers for C conversion.\nC>> 1994-10-19 SASINH Krogh Changes to use M77CON\nC>> 1994-04-19 SASINH CLL Edited type stmts to make DP & SP similar.\nC>> 1992-03-13 SASINH FTK Removed implicit statements.\nC>> 1986-03-18 SASINH Lawson Initial code.\nC--S replaces \"?\": ?ACOSH,?ACSCH,?ACTNH,?ASECH,?ASINH,?ATANH\nC--& ?HYPC, ?HYPS, ?HYPH, ?HYPER, ?ERM1\nC\nC This program unit has six entry points for computing\nC the six inverse hyperbolic functions.\nC Using the SFTRAN3 preprocessor.\nC Uses R1MACH(3) to obtain machine precision.\nC All critical constants are given correctly rounded\nC to 25 decimal places. Accuracy of the subprogram\nC adapts to the machine precision up to 25 decimal\nC places precision.\nC\nC -----------------------------------------------------------\nC\nC-- Begin mask code changes\nC The single precision code was tested in May 1983, on a\nC Univac 1100 using the JPL program ST4 that compares a\nC single precision function with a double precision function.\nC Each function was tested on at least 6000 points. Max\nC relative errors are expressed as a multiple of R1MACH(3),\nC which for the Univac 1100 is 2**(-27) = 0.745E-8 .\nC\nC FUNCTION RANGE MAX REL ERROR\nC -------- ----- -------------\nC SASINH ALL X 2.4\nC\nC SACOSH 1.0 .LE. X .LE. 1.03 LARGE\nC 1.03 .LE. X .LE. 1.21 3.4\nC 1.21 .LE. X 2.3\nC\nC SATANH ABS(X) .LE. 0.44 3.2\nC 0.44 .LE. ABS(X) .LE. 0.92 5.1\nC 0.92 .LE. ABS(X) .LE. 1.0 LARGE\nC\nC SACSCH ABS(X) .NE. 0 3.4\nC\nC SASECH 0.0 .LT. X .LE. 0.24 2.0\nC 0.24 .LE. X .LE. 0.68 3.0\nC 0.68 .LE. X .LE. 0.88 10.0\nC 0.88 .LE. X .LE. 1.0 LARGE\nC\nC SACTNH 1.0 .LE. ABS(X) .LE. 1.16 LARGE\nC 1.16 .LE. ABS(X) .LE. 2.20 7.1\nC 2.20 LE. ABS(X) 3.7\nC\nC -----------------------------------------------------------\nC\nC The D.P. and S.P. codes have each been tested using\nC identities such as X - SINH( ASINH(X) ) = 0. The\nC D.P. codes have about the same accuracy relative to\nC D1MACH(3) as do the S.P. codes relative to R1MACH(3).\nC\nC-- End mask code changes\nC Error Messages\nC 1) Arg .LT. 1 ( IN SACOSH )\nC 2) Arg .LT. or .EQ. to 1 ( IN SATANH )\nC 3) ABS(Arg) .LT. or .EQ. to 1 ( IN SACTNH )\nC 4) Arg .EQ. 0 ( IN SACSCH )\nC 5) Arg .LT. or .EQ. 0 or Arg .GT. 1 ( IN SASECH )\nC\nC -----------------------------------------------------------\nC\nC C.L.Lawson and Stella Chan,JPL,Feb 23,1983.\nC\n REAL X\n EXTERNAL SHYPS\n REAL SHYPS\nC\nC Begin computation for SASINH(x)\nC Defined for all x.The value u ranges from negative infinity to\nC positive infinity as x ranges from negative infinity to positive i\n\nC\n IF (X .EQ. 0.E0) THEN\n SASINH=0.E0\n ELSE\n SASINH = SIGN(SHYPS(ABS(X)), X)\n END IF\n RETURN\n END\nC\nC\n REAL FUNCTION SACOSH(X)\nC\nC Defined (float -valued) for all X greater than or equal to 1.\nC We compute the nonnegative value U ranging from zero to infinity\nC as X ranges from 1 to infinity.The second value would be -U.\n REAL X\n EXTERNAL SHYPC\n REAL SHYPC\nC\n IF (X .LT. 1.E0) THEN\n SACOSH=0.E0\n CALL SERM1('SACOSH',1,0,'ARG.LT.1','ARG',X,'.')\n ELSE\n SACOSH = SHYPC(X)\n END IF\n RETURN\n END\nC\nC\n REAL FUNCTION SATANH(X)\nC\nC Defined for -1 < x < +1. The value U ranges from negative\nC infinity to positive infinity.\n REAL X\n EXTERNAL SHYPH\n REAL SHYPH\nC\n IF (ABS(X) .GE. 1.E0) THEN\n SATANH=0.E0\n CALL SERM1('SATANH',2,0,'ABS(ARG).GE.1','ARG',X,'.')\n ELSE IF (X .EQ. 0.E0) THEN\n SATANH=0.E0\n ELSE\n SATANH = SIGN(SHYPH(ABS(X)), X)\n END IF\n RETURN\n END\nC\nC\n REAL FUNCTION SACTNH(X)\nC\nC Defined for ABS(X) > 1. The value U ranges from zero to negative\nC infinity as X ranges from negative infinity to -1,and from\nC positive infinity to zero as X ranges from 1 to positive\nC infinity.\n REAL X\n EXTERNAL SHYPH\n REAL SHYPH\nC\n IF (ABS(X) .LE. 1.E0) THEN\n SACTNH=0.E0\n CALL SERM1('SACTNH',3,0,'ABS(ARG).LE.1','ARG',X,'.')\n ELSE\n SACTNH = SIGN(SHYPH(1.E0 / ABS(X)), X)\n END IF\n RETURN\n END\nC\nC\n REAL FUNCTION SACSCH(X)\nC\nC Defined for all X not equal to 0. The value varies from\nC zero to negative infinity as X ranges from negative\nC infinity to zero,jumps from negative infinity to positive\nC infinity at zero, and varies from positive infinity to\nC zero as X ranges from zero to positive infinity.\n REAL X\n EXTERNAL SHYPS\n REAL SHYPS\nC\n IF (X .EQ. 0.E0) THEN\n SACSCH=0.E0\n CALL SERM1('SACSCH',4,0,'ARG.EQ.0','ARG',X,'.')\n ELSE\n SACSCH = SIGN(SHYPS(1.E0 / ABS(X)), X)\n END IF\n RETURN\n END\nC\nC\n REAL FUNCTION SASECH(X)\nC\nC Defined (float valued) for X greater than zero and X less than\nC or equal to 1.E0. We compute the nonnegative value that varies\nC from infinity to zero as X varies from zero to 1.E0. The other\nC value would be the negative of this.\n REAL X\n EXTERNAL SHYPC\n REAL SHYPC\nC\n IF (X .LE. 0.E0 .OR. X .GT. 1.E0) THEN\n SASECH=0.E0\n CALL SERM1('SASECH',5,0,'ARG.GT.1 OR ARG.LE.0','ARG',X,'.')\n ELSE\n SASECH = SHYPC(1.E0 / X)\n END IF\n RETURN\n END\nC\nC\n REAL FUNCTION SHYPS(P)\nC\nC Here P > 0.\nC We break the p range into three intervals separated by CUT2\nC and HICUT. In the middle range between CUT2 and HICUT we use\nC SHYPS=LOG(P+SQRT(1+P**2))\nC CUT2 is set to 1.176 to keep the argument of LOG() greater\nC than e = 2.718 to avoid amplification of relative error by LOG().\nC We set HICUT = 10.**16 assuming that all machines on which\nC this code is to run have overflow limit greater than 10.**32\nC and precision not greater than 32 decimal places. Thus we\nC assume that HICUT**2 would not overflow and HICUT**2 plus or\nC minus 1.E0 would evaluate to HICUT**2.\nC The idea of using SHYPS = LOG(P) + LOG(2) for P .GT. HICUT is\nC copied from an ASINH subroutine due to WAYNE FULLERTON.\nC\n REAL P\n EXTERNAL SHYPER\n REAL CU, CUT2, SHYPER, HICUT, LOGE2\n DATA CUT2, HICUT / 1.176E0, 1.E16 /\n DATA LOGE2 / 0.6931471805599453094172321E0 /\nC\n IF (P .GT. HICUT) THEN\n SHYPS = LOG(P) + LOGE2\n ELSE\n CU=SQRT(1.E0+P**2)\n IF (P .LT. CUT2) THEN\n SHYPS = SHYPER(P, CU)\n ELSE\n SHYPS = LOG(P + CU)\n END IF\n END IF\n RETURN\n END\nC\nC\n REAL FUNCTION SHYPC(P)\nC\nC Here P .GE. 1.\nC See comments in function SHYPS\nC The mid-range formula for SACOSH is:\nC U=LOG(P+SQRT(P**2-1))\nC\n REAL P\n EXTERNAL SHYPER\n REAL CUT2, SHYPER, HICUT, LOGE2, SU\n DATA CUT2, HICUT / 1.176E0, 1.E16 /\n DATA LOGE2 / 0.6931471805599453094172321E0 /\nC\n IF (P .GT. HICUT) THEN\n SHYPC = LOG(P) + LOGE2\n ELSE\n SU = SQRT( (P-1.E0)*(P+1.E0) )\n IF (SU .LT. CUT2) THEN\n SHYPC = SHYPER(SU, P)\n ELSE\n SHYPC = LOG(SU + P)\n END IF\n END IF\n RETURN\n END\nC\nC\n REAL FUNCTION SHYPH(Q)\nC\nC Here Q satisfies 0 < Q < 1.\nC When Q exceeds CUT1 = 0.463 then (1+Q)/(1-Q) > e = 2.718,\nC and this is large enough to be used as an argument\nC to LOG() without amplification of relative error.\nC When Q is less than CUT1 we transform Q to COSH(U)\nC and SINH(U) and use procedure (LOW RANGE).\nC\nC The simple formulas for CU and SU would be\nC CU = 1.E0 / SQRT(1.E0 - Q**2)\nC and SU = Q / SQRT(1.E0 - Q**2)\nC The more complicated formulas used here have less\nC accumulation of round-of error since\nC 0.0 .LT. TERM .LT. 0.1283\nC\n REAL Q\n EXTERNAL SHYPER\n REAL CUT1, SHYPER, DIF, QSQ, TERM\n DATA CUT1 / 0.463E0 /\nC\n IF (Q .LT. CUT1) THEN\n QSQ = Q * Q\n DIF = 1.E0 - QSQ\n TERM = QSQ / (DIF + SQRT(DIF))\n SHYPH = SHYPER(Q + Q*TERM, 1.E0 + TERM)\n ELSE\n SHYPH = 0.5E0 * LOG((1.E0+Q)/(1.E0-Q))\n END IF\n RETURN\n END\nC\nC do (LOW RANGE) ==> DYPER(SU, CU)\nC\n REAL FUNCTION SHYPER(SU, CU)\nC\nC This procedure controls computation of U, given\nC SU=SINH(U) and CU=COSH(U).These will satisfy\nC 0 .LE. SU .LE. 1.176\nC AND 0 .LE. CU .LE. 1.5437\nC so the result, U , will satisfy\nC 0 .LE. U .LE. 1.00052\nC\nC\nC Here the argument R satisfies 0 .LE. R .LE. SINH(0.125) = 0.125326\nC\nC ------------------------------------------------------------------\nC\nC On the first call to this procedure the value NMAX\nC will be set and saved.\nC FOR MACHINE PRECISION BETWEEN 4.43062 AND 6.45985 USE NMAX = 2\nC FOR MACHINE PRECISION BETWEEN 6.45985 AND 8.43090 USE NMAX = 3\nC FOR MACHINE PRECISION BETWEEN 8.43090 AND 10.36773 USE NMAX = 4\nC FOR MACHINE PRECISION BETWEEN 10.36773 AND 12.28199 USE NMAX = 5\nC FOR MACHINE PRECISION BETWEEN 12.28199 AND 14.18024 USE NMAX = 6\nC FOR MACHINE PRECISION BETWEEN 14.18024 AND 16.06654 USE NMAX = 7\nC FOR MACHINE PRECISION BETWEEN 16.06654 AND 17.94359 USE NMAX = 8\nC FOR MACHINE PRECISION BETWEEN 17.94359 AND 19.81325 USE NMAX = 9\nC FOR MACHINE PRECISION BETWEEN 19.81325 AND 21.67688 USE NMAX = 10\nC FOR MACHINE PRECISION BETWEEN 21.67688 AND 23.53550 USE NMAX = 11\nC FOR MACHINE PRECISION BETWEEN 23.53550 AND 25.38987 USE NMAX = 12\nC\n REAL SU, CU\n EXTERNAL R1MACH\n REAL B1,B2,C(0:13),CV(8),R1MACH,R,RSQ,SV(8),U,V(8)\n INTEGER I, II, NMAX\n LOGICAL FIRST\n SAVE FIRST, NMAX\nC\nC Coeffs for SASINH series. C(0) is half of its true value.\nC This series will be used only for arguments, R , in the\nC range 0 .LE. R .LE. SINH(0.125) = 0.125326 .\nC\n DATA C( 0)/0.5E0/\n DATA C( 1) /-.1666666666666666666666667E+00/\n DATA C( 2) /+.7500000000000000000000000E-01/\n DATA C( 3) /-.4464285714285714285714286E-01/\n DATA C( 4) /+.3038194444444444444444444E-01/\n DATA C( 5) /-.2237215909090909090909091E-01/\n DATA C( 6) /+.1735276442307692307692308E-01/\n DATA C( 7) /-.1396484375000000000000000E-01/\n DATA C( 8) /+.1155180089613970588235294E-01/\n DATA C( 9) /-.9761609529194078947368421E-02/\n DATA C(10) /+.8390335809616815476190476E-02/\n DATA C(11) /-.7312525873598845108695652E-02/\n DATA C(12) /+.6447210311889648437500000E-02/\n DATA C(13) /-.5740037670841923466435185E-02/\nC\nC SV(I) = SINH(V(I))\nC CV(I) = COSH(V(I))\nC\n DATA V( 1) /+.1250000000000000000000000E+00/\n DATA SV( 1) /+.1253257752411154569820575E+00/\n DATA CV( 1) /+.1007822677825710859846950E+01/\n DATA V( 2) /+.2500000000000000000000000E+00/\n DATA SV( 2) /+.2526123168081683079141252E+00/\n DATA CV( 2) /+.1031413099879573176159295E+01/\n DATA V( 3) /+.3750000000000000000000000E+00/\n DATA SV( 3) /+.3838510679136145687542957E+00/\n DATA CV( 3) /+.1071140346704586767299498E+01/\n DATA V( 4) /+.5000000000000000000000000E+00/\n DATA SV( 4) /+.5210953054937473616224256E+00/\n DATA CV( 4) /+.1127625965206380785226225E+01/\n DATA V( 5) /+.6250000000000000000000000E+00/\n DATA SV( 5) /+.6664922644566160822726066E+00/\n DATA CV( 5) /+.1201753692975606324229229E+01/\n DATA V( 6) /+.7500000000000000000000000E+00/\n DATA SV( 6) /+.8223167319358299807036616E+00/\n DATA CV( 6) /+.1294683284676844687841708E+01/\n DATA V( 7) /+.8750000000000000000000000E+00/\n DATA SV( 7) /+.9910066371442947560531743E+00/\n DATA CV( 7) /+.1407868656822803158638471E+01/\n DATA V( 8) /+.1000000000000000000000000E+01/\n DATA SV( 8) /+.1175201193643801456882382E+01/\n DATA CV( 8) /+.1543080634815243778477906E+01/\n DATA B1,B2 / 0.52344E0, 4.4306E0 /\nc\n data FIRST / .true. /\nc\n IF (FIRST) THEN\n FIRST = .FALSE.\nC The following linear expression approximate the NMAX\nC selection criteria described above. The expression\nC never sets NMAX too small but will set NMAX too\nC large, by one, in boundary cases.\n NMAX = 2 + INT(B1 * (-log10(R1MACH(3)) - B2))\n NMAX = MAX(2,MIN(NMAX,12))\n END IF\nc\n IF (SU .LE. SV(1)) THEN\n R = SU\n ELSE\n II = MIN ( 7,INT(SU/SV(1)) )\n IF (SU .LT. SV(II)) II = II - 1\nC\nC Here we transform to an argument, R , in the range\nC 0 .LE. R .LE. SINH(0.125). The simple formula would\nC be : R = SU * CV(II) - SV(II) * CU\nC However we transform this to extract the factor\nC (SU - SV(II)) for better control of round-off error.\nC\n R = (SU-SV(II))*(CV(II)-(SV(II)+SU)*SV(II)/(CV(II)+CU))\n END IF\nC\n RSQ = R*R\n U = C(NMAX)\n DO 110 I = NMAX-1, 0, -1\n U = RSQ * U + C(I)\n 110 CONTINUE\n SHYPER = R * (U + 0.5E0)\n IF (SU .GT. SV(1)) SHYPER = V(II) + SHYPER\n return\n end\n", "meta": {"hexsha": "9389a16095c86a301f3d5529c5349e1a253e7e7c", "size": 14299, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/sasinh.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/sasinh.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/sasinh.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": 34.8756097561, "max_line_length": 72, "alphanum_fraction": 0.5622770823, "num_tokens": 5001, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950986284991, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6513549491636206}} {"text": "!*****************************************************************************************\n!>\n! Units test for 1d-6d tensor product b-spline interpolation.\n\n program bspline_test\n\n use bspline_module\n use bspline_kinds_module, only: wp\n\n implicit none\n\n integer,parameter :: nx = 6 !! number of points in x\n integer,parameter :: ny = 6 !! number of points in y\n integer,parameter :: nz = 6 !! number of points in z\n integer,parameter :: nq = 6 !! number of points in q\n integer,parameter :: nr = 6 !! number of points in r\n integer,parameter :: ns = 6 !! number of points in s\n\n integer,parameter :: kx = 4 !! order in x\n integer,parameter :: ky = 4 !! order in y\n integer,parameter :: kz = 4 !! order in z\n integer,parameter :: kq = 4 !! order in q\n integer,parameter :: kr = 4 !! order in r\n integer,parameter :: ks = 4 !! order in s\n\n integer,parameter :: iknot = 0 !! automatically select the knots\n\n real(wp) :: x(nx),y(ny),z(nz),q(nq),r(nr),s(ns)\n real(wp) :: tx(nx+kx),ty(ny+ky),tz(nz+kz),tq(nq+kq),tr(nr+kr),ts(ns+ks)\n real(wp) :: fcn_1d(nx)\n real(wp) :: fcn_2d(nx,ny)\n real(wp) :: fcn_3d(nx,ny,nz)\n real(wp) :: fcn_4d(nx,ny,nz,nq)\n real(wp) :: fcn_5d(nx,ny,nz,nq,nr)\n real(wp) :: fcn_6d(nx,ny,nz,nq,nr,ns)\n\n real(wp) :: tol\n real(wp),dimension(6) :: val,tru,err,errmax\n logical :: fail\n integer :: i,j,k,l,m,n,idx,idy,idz,idq,idr,ids\n integer,dimension(6) :: iflag\n integer :: inbvx,inbvy,inbvz,inbvq,inbvr,inbvs\n integer :: iloy,iloz,iloq,ilor,ilos\n\n fail = .false.\n tol = 1.0e-14_wp\n idx = 0\n idy = 0\n idz = 0\n idq = 0\n idr = 0\n ids = 0\n\n do i=1,nx\n x(i) = dble(i-1)/dble(nx-1)\n end do\n do j=1,ny\n y(j) = dble(j-1)/dble(ny-1)\n end do\n do k=1,nz\n z(k) = dble(k-1)/dble(nz-1)\n end do\n do l=1,nq\n q(l) = dble(l-1)/dble(nq-1)\n end do\n do m=1,nr\n r(m) = dble(m-1)/dble(nr-1)\n end do\n do n=1,ns\n s(n) = dble(n-1)/dble(ns-1)\n end do\n do i=1,nx\n fcn_1d(i) = f1(x(i))\n do j=1,ny\n fcn_2d(i,j) = f2(x(i),y(j))\n do k=1,nz\n fcn_3d(i,j,k) = f3(x(i),y(j),z(k))\n do l=1,nq\n fcn_4d(i,j,k,l) = f4(x(i),y(j),z(k),q(l))\n do m=1,nr\n fcn_5d(i,j,k,l,m) = f5(x(i),y(j),z(k),q(l),r(m))\n do n=1,ns\n fcn_6d(i,j,k,l,m,n) = f6(x(i),y(j),z(k),q(l),r(m),s(n))\n end do\n end do\n end do\n end do\n end do\n end do\n\n !have to set these before the first evaluate call:\n inbvx = 1\n inbvy = 1\n inbvz = 1\n inbvq = 1\n inbvr = 1\n inbvs = 1\n iloy = 1\n iloz = 1\n iloq = 1\n ilor = 1\n ilos = 1\n\n ! initialize\n call db1ink(x,nx,fcn_1d,kx,iknot,tx,fcn_1d,iflag(1))\n call db2ink(x,nx,y,ny,fcn_2d,kx,ky,iknot,tx,ty,fcn_2d,iflag(2))\n call db3ink(x,nx,y,ny,z,nz,fcn_3d,kx,ky,kz,iknot,tx,ty,tz,fcn_3d,iflag(3))\n call db4ink(x,nx,y,ny,z,nz,q,nq,fcn_4d,kx,ky,kz,kq,iknot,tx,ty,tz,tq,fcn_4d,iflag(4))\n call db5ink(x,nx,y,ny,z,nz,q,nq,r,nr,fcn_5d,kx,ky,kz,kq,kr,iknot,tx,ty,tz,tq,tr,fcn_5d,iflag(5))\n call db6ink(x,nx,y,ny,z,nz,q,nq,r,nr,s,ns,fcn_6d,kx,ky,kz,kq,kr,ks,iknot,tx,ty,tz,tq,tr,ts,fcn_6d,iflag(6))\n\n if (any(iflag/=0)) then\n do i=1,6\n if (iflag(i)/=0) then\n write(*,*) 'Error initializing ',i,'D spline: '//get_status_message(iflag(i))\n end if\n end do\n end if\n\n ! compute max error at interpolation points\n\n errmax = 0.0_wp\n do i=1,nx\n call db1val(x(i),idx,&\n tx,nx,kx,fcn_1d,val(1),iflag(1),inbvx)\n tru(1) = f1(x(i))\n err(1) = abs(tru(1)-val(1))\n errmax(1) = max(err(1),errmax(1))\n do j=1,ny\n call db2val(x(i),y(j),idx,idy,&\n tx,ty,nx,ny,kx,ky,fcn_2d,val(2),iflag(2),&\n inbvx,inbvy,iloy)\n tru(2) = f2(x(i),y(j))\n err(2) = abs(tru(2)-val(2))\n errmax(2) = max(err(2),errmax(2))\n do k=1,nz\n call db3val(x(i),y(j),z(k),idx,idy,idz,&\n tx,ty,tz,nx,ny,nz,kx,ky,kz,fcn_3d,val(3),iflag(3),&\n inbvx,inbvy,inbvz,iloy,iloz)\n tru(3) = f3(x(i),y(j),z(k))\n err(3) = abs(tru(3)-val(3))\n errmax(3) = max(err(3),errmax(3))\n do l=1,nq\n call db4val(x(i),y(j),z(k),q(l),idx,idy,idz,idq,&\n tx,ty,tz,tq,nx,ny,nz,nq,kx,ky,kz,kq,fcn_4d,val(4),iflag(4),&\n inbvx,inbvy,inbvz,inbvq,iloy,iloz,iloq)\n tru(4) = f4(x(i),y(j),z(k),q(l))\n err(4) = abs(tru(4)-val(4))\n errmax(4) = max(err(4),errmax(4))\n do m=1,nr\n call db5val(x(i),y(j),z(k),q(l),r(m),idx,idy,idz,idq,idr,&\n tx,ty,tz,tq,tr,nx,ny,nz,nq,nr,kx,ky,kz,kq,kr,fcn_5d,val(5),iflag(5),&\n inbvx,inbvy,inbvz,inbvq,inbvr,iloy,iloz,iloq,ilor)\n tru(5) = f5(x(i),y(j),z(k),q(l),r(m))\n err(5) = abs(tru(5)-val(5))\n errmax(5) = max(err(5),errmax(5))\n do n=1,ns\n call db6val(x(i),y(j),z(k),q(l),r(m),s(n),idx,idy,idz,idq,idr,ids,&\n tx,ty,tz,tq,tr,ts,nx,ny,nz,nq,nr,ns,kx,ky,kz,kq,kr,ks,fcn_6d,val(6),iflag(6),&\n inbvx,inbvy,inbvz,inbvq,inbvr,inbvs,iloy,iloz,iloq,ilor,ilos)\n tru(6) = f6(x(i),y(j),z(k),q(l),r(m),s(n))\n err(6) = abs(tru(6)-val(6))\n errmax(6) = max(err(6),errmax(6))\n end do\n end do\n end do\n end do\n end do\n end do\n\n ! check max error against tolerance\n do i=1,6\n write(*,*) i,'D: max error:', errmax(i)\n if (errmax(i) >= tol) then\n write(*,*) ' ** test failed ** '\n else\n write(*,*) ' ** test passed ** '\n end if\n write(*,*) ''\n end do\n\n contains\n\n real(wp) function f1(x) !! 1d test function\n implicit none\n real(wp) :: x\n f1 = 0.5_wp * (x*exp(-x) + sin(x) )\n end function f1\n\n real(wp) function f2(x,y) !! 2d test function\n implicit none\n real(wp) x,y,piov2\n piov2 = 2.0_wp * atan(1.0_wp)\n f2 = 0.5_wp * (y*exp(-x) + sin(piov2*y) )\n end function f2\n\n real(wp) function f3 (x,y,z) !! 3d test function\n implicit none\n real(wp) x,y,z,piov2\n piov2 = 2.0_wp*atan(1.0_wp)\n f3 = 0.5_wp*( y*exp(-x) + z*sin(piov2*y) )\n end function f3\n\n real(wp) function f4 (x,y,z,q) !! 4d test function\n implicit none\n real(wp) x,y,z,q,piov2\n piov2 = 2.0_wp*atan(1.0_wp)\n f4 = 0.5_wp*( y*exp(-x) + z*sin(piov2*y) + q )\n end function f4\n\n real(wp) function f5 (x,y,z,q,r) !! 5d test function\n implicit none\n real(wp) x,y,z,q,r,piov2\n piov2 = 2.0_wp*atan(1.0_wp)\n f5 = 0.5_wp*( y*exp(-x) + z*sin(piov2*y) + q*r )\n end function f5\n\n real(wp) function f6 (x,y,z,q,r,s) !! 6d test function\n implicit none\n real(wp) x,y,z,q,r,s,piov2\n piov2 = 2.0_wp*atan(1.0_wp)\n f6 = 0.5_wp*( y*exp(-x) + z*sin(piov2*y) + q*r + 2.0_wp*s )\n end function f6\n\n end program bspline_test\n", "meta": {"hexsha": "91bca0f6fc4b9837a11cac26bf47bf9363ec3f2d", "size": 8115, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/bspline_test.f90", "max_stars_repo_name": "hhc2tech/bspline-fortran", "max_stars_repo_head_hexsha": "2dea3f1a9ce04095ce45bb48c97c0fd9d0e8c9be", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/tests/bspline_test.f90", "max_issues_repo_name": "hhc2tech/bspline-fortran", "max_issues_repo_head_hexsha": "2dea3f1a9ce04095ce45bb48c97c0fd9d0e8c9be", "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/tests/bspline_test.f90", "max_forks_repo_name": "hhc2tech/bspline-fortran", "max_forks_repo_head_hexsha": "2dea3f1a9ce04095ce45bb48c97c0fd9d0e8c9be", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.907079646, "max_line_length": 122, "alphanum_fraction": 0.4448552064, "num_tokens": 2916, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950868503681, "lm_q2_score": 0.7718435030872968, "lm_q1q2_score": 0.6513549400727466}} {"text": " SUBROUTINE flmoon(n,nph,jd,frac)\r\n INTEGER jd,n,nph\r\n REAL frac,RAD\r\n PARAMETER (RAD=3.14159265/180.)\r\n INTEGER i\r\n REAL am,as,c,t,t2,xtra\r\n c=n+nph/4.\r\n t=c/1236.85\r\n t2=t**2\r\n as=359.2242+29.105356*c\r\n am=306.0253+385.816918*c+0.010730*t2\r\n jd=2415020+28*n+7*nph\r\n xtra=0.75933+1.53058868*c+(1.178e-4-1.55e-7*t)*t2\r\n if(nph.eq.0.or.nph.eq.2)then\r\n xtra=xtra+(0.1734-3.93e-4*t)*sin(RAD*as)-0.4068*sin(RAD*am)\r\n else if(nph.eq.1.or.nph.eq.3)then\r\n xtra=xtra+(0.1721-4.e-4*t)*sin(RAD*as)-0.6280*sin(RAD*am)\r\n else\r\n pause 'nph is unknown in flmoon'\r\n endif\r\n if(xtra.ge.0.)then\r\n i=int(xtra)\r\n else\r\n i=int(xtra-1.)\r\n endif\r\n jd=jd+i\r\n frac=xtra-i\r\n return\r\n END\r\n", "meta": {"hexsha": "e34dea2892087af32caf88b7a0fe905889e4c7e1", "size": 819, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/flmoon.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/flmoon.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/flmoon.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.3, "max_line_length": 68, "alphanum_fraction": 0.525030525, "num_tokens": 332, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625107731764, "lm_q2_score": 0.6992544210587585, "lm_q1q2_score": 0.651329278708635}} {"text": "C NMR_PSD: Determine an NMR pore-size distribution from $T_{1}$ data\nC --------\nC\nC NMR relaxation data are used to determine a PSD using the method of\nC Munn and Smith [J. Colloid and Interface Sci., 119, 117, 1987].\nC\nC The problem is the solution of the 1st-order Frredholm equation:\nC\nC m(t) (M0 - M(t))/2M0 = \\int_{Tmin}^{Tmax} exp(-t/T) f(T) dT\nC\nC where 1/T = 1/T1(bulk) + gamma/( r*T1(surface) ) and f(T) is therefore\nC directly related to the pore-size distribution for r. The relationship\nC is in fact parameterized by:\nC\nC 1/T = alpha + beta/r\nC\nC The method of solution is to discretize the above integral to yield:\nC\nC m(i) = K(i,j) f(j)\nC\nC j = 1, NJ\nC i = 1, NI\nC\nC where m(i) = m(ti); K(i,j) = exp(-ti/Tj) dT; f(j) = f(Tj). The step\nC dT is such that dT = (Tmax-Tmin) / (NJ - 1) and Tj = Tmin + (j-1)*dT.\nC\nC The additional criterion on f(j) is that f(j) >= 0 for all j, therefore\nC the solution to the above matrix equation is formed in terms of minimizing\nC the sum, S:\nC\nC S = sum( i=1,NI ) sum( j=1,NJ ) [ m(i) - K(i,j)f(j) ]**2\nC\nC This is done using the NAG routine E04FDF.\nC\nC\nC The user must supply the following:\nC Number of data points and data values at the time steps\nC NI, m(i), t(i)\nC The range in T and number of steps\nC Tmin, Tmax, NJ (NJ < NI)\nC The parameters of the T <==> T1 transformation\nC alpha, beta\nC\nC-\n\nC define experimental data\n integer max_NI\n parameter (max_NI = 100)\n integer NI, i\n real*4 x(max_NI), y(max_NI), xx, yy\n real*8 m(max_NI), t(max_NI)\nC .. initial guess of mean T1 and m normalization\n real*8 guess_T1, M0\nC define steps\n integer max_NJ\n parameter (max_NJ = 20)\n integer NJ, j\n real*8 f(max_NJ), TT(max_NJ), Tmin, Tmax, dT,\n * g(max_NJ), rr(max_NJ)\nC define matrix\n real*8 K(max_NI,max_NJ)\nC details of the transformation\n real*8 alpha, beta\nC arrays used in the minimization\n integer max_work, max_iwork\n parameter (max_work = 7*max_NJ + 2*max_NJ*max_NJ +\n * 2*max_NJ*max_NI + 3*max_NI )\n parameter (max_iwork = 500)\n real*8 fsumsq, work( max_work )\n integer iwork( max_iwork )\n\nC file name character string\n character file*256, dir*256\nC file unit number\n integer iunit, id\nC error status\n integer status, ifail\nC local R*4 variables\n real*4 rm0, rt1, rtmin, rtmax, ralpha, rbeta\n\nC local arrays passed in common\n common /local_data/ m, t, K, TT\n\nC standard include files\n include 'mrao_lib:chrlib_functions.h'\n include 'spec_lib:spec_global.h'\n include 'spec_lib:spec_pars.h'\n\nC initialise\n call cmd_extpars( 'SPECTRUM', dir, status )\n call cmd_getiline( 'nmr_PSD',\n * dir(1:chr_lenb(dir))//anal_definitions, status)\n\nC find input file name and allocate file\n call cmd_items( 'file', file, status)\n call spec_allocate( file(1:chr_lenb(file)),\n * 'read', id, status)\nC read data\n call spec_get_data( id, 1, x, NI, status)\n call spec_get_data( id, 2, y, NI, status)\nC deallocate\n call spec_deallocate( id, status )\n\nC read in the control data\n call cmd_itemi( 'nj', 1, nj, status )\n call cmd_itemr( 'tmin', 1, rtmin, status )\n Tmin = rtmin\n call cmd_itemr( 'tmax', 1, rtmax, status )\n Tmax = rtmax\n call cmd_itemr( 'm0', 1, rm0, status )\n M0 = rm0\n call cmd_itemr( 'alpha', 1, ralpha, status )\n alpha = ralpha\n call cmd_itemr( 'beta', 1, rbeta, status )\n beta = rbeta\n call cmd_itemr( 't1', 1, rt1, status )\n guess_T1 = rt1\n\nC modify input data to normalize\n do i=1,NI\n t(i) = x(i)\n m(i) = (M0 - y(i)) / (2.0*M0)\n end do\n\nC setup the TT array\n dT = (Tmax - Tmin) / float( NJ-1 )\n do j=1,NJ\n TT(j) = Tmin + float(j-1)*dT\n end do\n\nC setup the matrix\n do i=1,NI\n do j=1,NJ\n K(i,j) = exp( -t(i)/TT(j) ) * dT\n end do\n end do\n\nC setup initial guess for f array\n do j=1,NJ\n f(j) = 0.0\n end do\n j = nint( (guess_T1-Tmin)/dT + 1.0 )\n f(j) = 1.0\n\nC do the minimization\n ifail = 1\n call e04fdf( NI, NJ, f, fsumsq,\n * iwork, max_iwork, work, max_work, ifail )\n\nC report results\n call io_enqout( iunit )\n write( iunit, 10 ) ifail, fsumsq\n10 format( ' On exit IFAIL = ',I2 /\n * ' Sum-of-squares = ',1PD12.3 )\n\nC write output\n call cmd_items( 'psd', file, status)\n call io_opefil( iunit, file(1:chr_lenb(file)),\n * 'WRITE', 0, status )\n write(iunit,*) '\\ncols 4'\n write(iunit,*) '\\ndata ',NJ\n do j=1,NJ\n rr(j) = beta/( (1.0/TT(j)) - alpha )\n g(j) = f(j)* (beta*TT(j)*TT(J)) / (rr(j)*rr(j))\n write(iunit,*) rr(j), g(j), TT(j), f(j)\n end do\n close (iunit)\n\nC write fit\n call cmd_items( 'fit', file, status)\n call io_opefil( iunit, file(1:chr_lenb(file)),\n * 'WRITE', 0, status )\n print *,'.. opening fit file: ',iunit,' ',file(1:chr_lenb(file))\n write(iunit,*) '\\ncols 2'\n write(iunit,*) '\\ndata ',5*NI\n do i=1,5*NI\n xx = t(1) + float(i-1)*(t(NI)-t(1))/float(5*NI-1)\n yy = 0.0\n do j=1,NJ\n yy = yy + f(j) * exp(-xx/TT(j)) * dT\n end do\n yy = M0*(1.0-2.0*yy)\n write(iunit,*) xx, yy\n end do\n close (iunit)\n\n end\nC\nC\n subroutine LSFUN1( NI, NJ, f, df )\nC ----------------------------------\nC\nC Supplied routine to calculate residuals\n integer NI, NJ\n real*8 f(NJ), df(NI)\n\n integer max_NI\n parameter (max_NI = 100)\n integer i\n real*8 m(max_NI), t(max_NI)\nC define steps\n integer max_NJ\n parameter (max_NJ = 20)\n integer j\n real*8 TT(max_NJ)\nC define matrix\n real*8 K(max_NI,max_NJ)\nC local arrays passed in common\n common /local_data/ m, t, K, TT\n\nC local variables\n real*8 tot\n\n do j=1,NJ\n if (f(j).lt.0.0D+0) f(j) = 0.0D+0\n end do\n\n do i=1,NI\n\n tot = 0.0D+0\n do j=1,NJ\n tot = tot + K(i,j)*f(j)\n end do\n df(i) = (m(i) - tot)\n\n end do\n end\n", "meta": {"hexsha": "a1386a8a60e03d1d5244a0451e0be3a33b74d45a", "size": 6446, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "nmr_tools/old_nmr_PSD.f", "max_stars_repo_name": "CavendishAstrophysics/anmap", "max_stars_repo_head_hexsha": "efb611d7f80a3d14dc55e46cd01e8a622f6fd294", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-09-01T12:40:45.000Z", "max_stars_repo_stars_event_max_datetime": "2015-09-01T12:40:45.000Z", "max_issues_repo_path": "nmr_tools/old_nmr_PSD.f", "max_issues_repo_name": "CavendishAstrophysics/anmap", "max_issues_repo_head_hexsha": "efb611d7f80a3d14dc55e46cd01e8a622f6fd294", "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": "nmr_tools/old_nmr_PSD.f", "max_forks_repo_name": "CavendishAstrophysics/anmap", "max_forks_repo_head_hexsha": "efb611d7f80a3d14dc55e46cd01e8a622f6fd294", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.2719298246, "max_line_length": 76, "alphanum_fraction": 0.5485572448, "num_tokens": 2175, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625107731764, "lm_q2_score": 0.6992544147913993, "lm_q1q2_score": 0.6513292728708249}} {"text": " SUBROUTINE AB09KD( JOB, DICO, WEIGHT, EQUIL, ORDSEL, N, NV, NW, M,\n $ P, NR, ALPHA, A, LDA, B, LDB, C, LDC, D, LDD,\n $ AV, LDAV, BV, LDBV, CV, LDCV, DV, LDDV,\n $ AW, LDAW, BW, LDBW, CW, LDCW, DW, LDDW,\n $ NS, HSV, TOL1, TOL2, IWORK, DWORK, LDWORK,\n $ IWARN, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute a reduced order model (Ar,Br,Cr,Dr) for an original\nC state-space representation (A,B,C,D) by using the frequency\nC weighted optimal Hankel-norm approximation method.\nC The Hankel norm of the weighted error\nC\nC V*(G-Gr)*W or conj(V)*(G-Gr)*conj(W)\nC\nC is minimized, where G and Gr are the transfer-function matrices\nC of the original and reduced systems, respectively, and V and W\nC are the transfer-function matrices of the left and right frequency\nC weights, specified by their state space realizations (AV,BV,CV,DV)\nC and (AW,BW,CW,DW), respectively. When minimizing the weighted\nC error V*(G-Gr)*W, V and W must be antistable transfer-function\nC matrices. When minimizing conj(V)*(G-Gr)*conj(W), V and W must be\nC stable transfer-function matrices.\nC Additionally, V and W must be invertible transfer-function\nC matrices, with the feedthrough matrices DV and DW invertible.\nC If the original system is unstable, then the frequency weighted\nC Hankel-norm approximation is computed only for the\nC ALPHA-stable part of the system.\nC\nC For a transfer-function matrix G, conj(G) denotes the conjugate\nC of G given by G'(-s) for a continuous-time system or G'(1/z)\nC for a discrete-time system.\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC JOB CHARACTER*1\nC Specifies the frequency-weighting problem as follows:\nC = 'N': solve min||V*(G-Gr)*W||_H;\nC = 'C': solve min||conj(V)*(G-Gr)*conj(W)||_H.\nC\nC DICO CHARACTER*1\nC Specifies the type of the original system as follows:\nC = 'C': continuous-time system;\nC = 'D': discrete-time system.\nC\nC WEIGHT CHARACTER*1\nC Specifies the type of frequency weighting, as follows:\nC = 'N': no weightings are used (V = I, W = I);\nC = 'L': only left weighting V is used (W = I);\nC = 'R': only right weighting W is used (V = I);\nC = 'B': both left and right weightings V and W are used.\nC\nC EQUIL CHARACTER*1\nC Specifies whether the user wishes to preliminarily\nC equilibrate the triplet (A,B,C) as follows:\nC = 'S': perform equilibration (scaling);\nC = 'N': do not perform equilibration.\nC\nC ORDSEL CHARACTER*1\nC Specifies the order selection method as follows:\nC = 'F': the resulting order NR is fixed;\nC = 'A': the resulting order NR is automatically determined\nC on basis of the given tolerance TOL1.\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The order of the original state-space representation,\nC i.e., the order of the matrix A. N >= 0.\nC\nC NV (input) INTEGER\nC The order of the realization of the left frequency\nC weighting V, i.e., the order of the matrix AV. NV >= 0.\nC\nC NW (input) INTEGER\nC The order of the realization of the right frequency\nC weighting W, i.e., the order of the matrix AW. NW >= 0.\nC\nC M (input) INTEGER\nC The number of system inputs. M >= 0.\nC\nC P (input) INTEGER\nC The number of system outputs. P >= 0.\nC\nC NR (input/output) INTEGER\nC On entry with ORDSEL = 'F', NR is the desired order of\nC the resulting reduced order system. 0 <= NR <= N.\nC On exit, if INFO = 0, NR is the order of the resulting\nC reduced order model. For a system with NU ALPHA-unstable\nC eigenvalues and NS ALPHA-stable eigenvalues (NU+NS = N),\nC NR is set as follows: if ORDSEL = 'F', NR is equal to\nC NU+MIN(MAX(0,NR-NU-KR+1),NMIN), where KR is the\nC multiplicity of the Hankel singular value HSV(NR-NU+1),\nC NR is the desired order on entry, and NMIN is the order\nC of a minimal realization of the ALPHA-stable part of the\nC given system; NMIN is determined as the number of Hankel\nC singular values greater than NS*EPS*HNORM(As,Bs,Cs), where\nC EPS is the machine precision (see LAPACK Library Routine\nC DLAMCH) and HNORM(As,Bs,Cs) is the Hankel norm of the\nC ALPHA-stable part of the weighted system (computed in\nC HSV(1));\nC if ORDSEL = 'A', NR is the sum of NU and the number of\nC Hankel singular values greater than\nC MAX(TOL1,NS*EPS*HNORM(As,Bs,Cs)).\nC\nC ALPHA (input) DOUBLE PRECISION\nC Specifies the ALPHA-stability boundary for the eigenvalues\nC of the state dynamics matrix A. For a continuous-time\nC system (DICO = 'C'), ALPHA <= 0 is the boundary value for\nC the real parts of eigenvalues, while for a discrete-time\nC system (DICO = 'D'), 0 <= ALPHA <= 1 represents the\nC boundary value for the moduli of eigenvalues.\nC The ALPHA-stability domain does not include the boundary.\nC\nC A (input/output) DOUBLE PRECISION array, dimension (LDA,N)\nC On entry, the leading N-by-N part of this array must\nC contain the state dynamics matrix A.\nC On exit, if INFO = 0, the leading NR-by-NR part of this\nC array contains the state dynamics matrix Ar of the\nC reduced order system in a real Schur form.\nC The resulting A has a block-diagonal form with two blocks.\nC For a system with NU ALPHA-unstable eigenvalues and\nC NS ALPHA-stable eigenvalues (NU+NS = N), the leading\nC NU-by-NU block contains the unreduced part of A\nC corresponding to ALPHA-unstable eigenvalues.\nC The trailing (NR+NS-N)-by-(NR+NS-N) block contains\nC the reduced part of A corresponding to ALPHA-stable\nC eigenvalues.\nC\nC LDA INTEGER\nC The leading dimension of array A. LDA >= MAX(1,N).\nC\nC B (input/output) DOUBLE PRECISION array, dimension (LDB,M)\nC On entry, the leading N-by-M part of this array must\nC contain the original input/state matrix B.\nC On exit, if INFO = 0, the leading NR-by-M part of this\nC array contains the input/state matrix Br of the reduced\nC order system.\nC\nC LDB INTEGER\nC The leading dimension of array B. LDB >= MAX(1,N).\nC\nC C (input/output) DOUBLE PRECISION array, dimension (LDC,N)\nC On entry, the leading P-by-N part of this array must\nC contain the original state/output matrix C.\nC On exit, if INFO = 0, the leading P-by-NR part of this\nC array contains the state/output matrix Cr of the reduced\nC order system.\nC\nC LDC INTEGER\nC The leading dimension of array C. LDC >= MAX(1,P).\nC\nC D (input/output) DOUBLE PRECISION array, dimension (LDD,M)\nC On entry, the leading P-by-M part of this array must\nC contain the original input/output matrix D.\nC On exit, if INFO = 0, the leading P-by-M part of this\nC array contains the input/output matrix Dr of the reduced\nC order system.\nC\nC LDD INTEGER\nC The leading dimension of array D. LDD >= MAX(1,P).\nC\nC AV (input/output) DOUBLE PRECISION array, dimension (LDAV,NV)\nC On entry, if WEIGHT = 'L' or 'B', the leading NV-by-NV\nC part of this array must contain the state matrix AV of a\nC state space realization of the left frequency weighting V.\nC On exit, if WEIGHT = 'L' or 'B', and INFO = 0, the leading\nC NV-by-NV part of this array contains a real Schur form\nC of the state matrix of a state space realization of the\nC inverse of V.\nC AV is not referenced if WEIGHT = 'R' or 'N'.\nC\nC LDAV INTEGER\nC The leading dimension of the array AV.\nC LDAV >= MAX(1,NV), if WEIGHT = 'L' or 'B';\nC LDAV >= 1, if WEIGHT = 'R' or 'N'.\nC\nC BV (input/output) DOUBLE PRECISION array, dimension (LDBV,P)\nC On entry, if WEIGHT = 'L' or 'B', the leading NV-by-P part\nC of this array must contain the input matrix BV of a state\nC space realization of the left frequency weighting V.\nC On exit, if WEIGHT = 'L' or 'B', and INFO = 0, the leading\nC NV-by-P part of this array contains the input matrix of a\nC state space realization of the inverse of V.\nC BV is not referenced if WEIGHT = 'R' or 'N'.\nC\nC LDBV INTEGER\nC The leading dimension of the array BV.\nC LDBV >= MAX(1,NV), if WEIGHT = 'L' or 'B';\nC LDBV >= 1, if WEIGHT = 'R' or 'N'.\nC\nC CV (input/output) DOUBLE PRECISION array, dimension (LDCV,NV)\nC On entry, if WEIGHT = 'L' or 'B', the leading P-by-NV part\nC of this array must contain the output matrix CV of a state\nC space realization of the left frequency weighting V.\nC On exit, if WEIGHT = 'L' or 'B', and INFO = 0, the leading\nC P-by-NV part of this array contains the output matrix of a\nC state space realization of the inverse of V.\nC CV is not referenced if WEIGHT = 'R' or 'N'.\nC\nC LDCV INTEGER\nC The leading dimension of the array CV.\nC LDCV >= MAX(1,P), if WEIGHT = 'L' or 'B';\nC LDCV >= 1, if WEIGHT = 'R' or 'N'.\nC\nC DV (input/output) DOUBLE PRECISION array, dimension (LDDV,P)\nC On entry, if WEIGHT = 'L' or 'B', the leading P-by-P part\nC of this array must contain the feedthrough matrix DV of a\nC state space realization of the left frequency weighting V.\nC On exit, if WEIGHT = 'L' or 'B', and INFO = 0, the leading\nC P-by-P part of this array contains the feedthrough matrix\nC of a state space realization of the inverse of V.\nC DV is not referenced if WEIGHT = 'R' or 'N'.\nC\nC LDDV INTEGER\nC The leading dimension of the array DV.\nC LDDV >= MAX(1,P), if WEIGHT = 'L' or 'B';\nC LDDV >= 1, if WEIGHT = 'R' or 'N'.\nC\nC AW (input/output) DOUBLE PRECISION array, dimension (LDAW,NW)\nC On entry, if WEIGHT = 'R' or 'B', the leading NW-by-NW\nC part of this array must contain the state matrix AW of\nC a state space realization of the right frequency\nC weighting W.\nC On exit, if WEIGHT = 'R' or 'B', and INFO = 0, the leading\nC NW-by-NW part of this array contains a real Schur form of\nC the state matrix of a state space realization of the\nC inverse of W.\nC AW is not referenced if WEIGHT = 'L' or 'N'.\nC\nC LDAW INTEGER\nC The leading dimension of the array AW.\nC LDAW >= MAX(1,NW), if WEIGHT = 'R' or 'B';\nC LDAW >= 1, if WEIGHT = 'L' or 'N'.\nC\nC BW (input/output) DOUBLE PRECISION array, dimension (LDBW,M)\nC On entry, if WEIGHT = 'R' or 'B', the leading NW-by-M part\nC of this array must contain the input matrix BW of a state\nC space realization of the right frequency weighting W.\nC On exit, if WEIGHT = 'R' or 'B', and INFO = 0, the leading\nC NW-by-M part of this array contains the input matrix of a\nC state space realization of the inverse of W.\nC BW is not referenced if WEIGHT = 'L' or 'N'.\nC\nC LDBW INTEGER\nC The leading dimension of the array BW.\nC LDBW >= MAX(1,NW), if WEIGHT = 'R' or 'B';\nC LDBW >= 1, if WEIGHT = 'L' or 'N'.\nC\nC CW (input/output) DOUBLE PRECISION array, dimension (LDCW,NW)\nC On entry, if WEIGHT = 'R' or 'B', the leading M-by-NW part\nC of this array must contain the output matrix CW of a state\nC space realization of the right frequency weighting W.\nC On exit, if WEIGHT = 'R' or 'B', and INFO = 0, the leading\nC M-by-NW part of this array contains the output matrix of a\nC state space realization of the inverse of W.\nC CW is not referenced if WEIGHT = 'L' or 'N'.\nC\nC LDCW INTEGER\nC The leading dimension of the array CW.\nC LDCW >= MAX(1,M), if WEIGHT = 'R' or 'B';\nC LDCW >= 1, if WEIGHT = 'L' or 'N'.\nC\nC DW (input/output) DOUBLE PRECISION array, dimension (LDDW,M)\nC On entry, if WEIGHT = 'R' or 'B', the leading M-by-M part\nC of this array must contain the feedthrough matrix DW of\nC a state space realization of the right frequency\nC weighting W.\nC On exit, if WEIGHT = 'R' or 'B', and INFO = 0, the leading\nC M-by-M part of this array contains the feedthrough matrix\nC of a state space realization of the inverse of W.\nC DW is not referenced if WEIGHT = 'L' or 'N'.\nC\nC LDDW INTEGER\nC The leading dimension of the array DW.\nC LDDW >= MAX(1,M), if WEIGHT = 'R' or 'B';\nC LDDW >= 1, if WEIGHT = 'L' or 'N'.\nC\nC NS (output) INTEGER\nC The dimension of the ALPHA-stable subsystem.\nC\nC HSV (output) DOUBLE PRECISION array, dimension (N)\nC If INFO = 0, the leading NS elements of this array contain\nC the Hankel singular values, ordered decreasingly, of the\nC ALPHA-stable part of the weighted original system.\nC HSV(1) is the Hankel norm of the ALPHA-stable weighted\nC subsystem.\nC\nC Tolerances\nC\nC TOL1 DOUBLE PRECISION\nC If ORDSEL = 'A', TOL1 contains the tolerance for\nC determining the order of reduced system.\nC For model reduction, the recommended value is\nC TOL1 = c*HNORM(As,Bs,Cs), where c is a constant in the\nC interval [0.00001,0.001], and HNORM(As,Bs,Cs) is the\nC Hankel-norm of the ALPHA-stable part of the weighted\nC original system (computed in HSV(1)).\nC If TOL1 <= 0 on entry, the used default value is\nC TOL1 = NS*EPS*HNORM(As,Bs,Cs), where NS is the number of\nC ALPHA-stable eigenvalues of A and EPS is the machine\nC precision (see LAPACK Library Routine DLAMCH).\nC If ORDSEL = 'F', the value of TOL1 is ignored.\nC\nC TOL2 DOUBLE PRECISION\nC The tolerance for determining the order of a minimal\nC realization of the ALPHA-stable part of the given system.\nC The recommended value is TOL2 = NS*EPS*HNORM(As,Bs,Cs).\nC This value is used by default if TOL2 <= 0 on entry.\nC If TOL2 > 0 and ORDSEL = 'A', then TOL2 <= TOL1.\nC\nC Workspace\nC\nC IWORK INTEGER array, dimension (LIWORK)\nC LIWORK = MAX(1,M,c), if DICO = 'C',\nC LIWORK = MAX(1,N,M,c), if DICO = 'D',\nC where c = 0, if WEIGHT = 'N',\nC c = 2*P, if WEIGHT = 'L',\nC c = 2*M, if WEIGHT = 'R',\nC c = MAX(2*M,2*P), if WEIGHT = 'B'.\nC On exit, if INFO = 0, IWORK(1) contains NMIN, the order of\nC the computed minimal realization.\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0, DWORK(1) returns the optimal value\nC of LDWORK.\nC\nC LDWORK INTEGER\nC The length of the array DWORK.\nC LDWORK >= MAX( LDW1, LDW2, LDW3, LDW4 ), where\nC LDW1 = 0 if WEIGHT = 'R' or 'N' and\nC LDW1 = MAX( NV*(NV+5), NV*N + MAX( a, P*N, P*M ) )\nC if WEIGHT = 'L' or WEIGHT = 'B',\nC LDW2 = 0 if WEIGHT = 'L' or 'N' and\nC LDW2 = MAX( NW*(NW+5), NW*N + MAX( b, M*N, P*M ) )\nC if WEIGHT = 'R' or WEIGHT = 'B', with\nC a = 0, b = 0, if DICO = 'C' or JOB = 'N',\nC a = 2*NV, b = 2*NW, if DICO = 'D' and JOB = 'C';\nC LDW3 = N*(2*N + MAX(N,M,P) + 5) + N*(N+1)/2,\nC LDW4 = N*(M+P+2) + 2*M*P + MIN(N,M) +\nC MAX( 3*M+1, MIN(N,M)+P ).\nC For optimum performance LDWORK should be larger.\nC\nC Warning Indicator\nC\nC IWARN INTEGER\nC = 0: no warning;\nC = 1: with ORDSEL = 'F', the selected order NR is greater\nC than NSMIN, the sum of the order of the\nC ALPHA-unstable part and the order of a minimal\nC realization of the ALPHA-stable part of the given\nC system; in this case, the resulting NR is set equal\nC to NSMIN;\nC = 2: with ORDSEL = 'F', the selected order NR is less\nC than the order of the ALPHA-unstable part of the\nC given system; in this case NR is set equal to the\nC order of the ALPHA-unstable part.\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value;\nC = 1: the computation of the ordered real Schur form of A\nC failed;\nC = 2: the separation of the ALPHA-stable/unstable\nC diagonal blocks failed because of very close\nC eigenvalues;\nC = 3: the reduction of AV or AV-BV*inv(DV)*CV to a\nC real Schur form failed;\nC = 4: the reduction of AW or AW-BW*inv(DW)*CW to a\nC real Schur form failed;\nC = 5: JOB = 'N' and AV is not antistable, or\nC JOB = 'C' and AV is not stable;\nC = 6: JOB = 'N' and AW is not antistable, or\nC JOB = 'C' and AW is not stable;\nC = 7: the computation of Hankel singular values failed;\nC = 8: the computation of stable projection in the\nC Hankel-norm approximation algorithm failed;\nC = 9: the order of computed stable projection in the\nC Hankel-norm approximation algorithm differs\nC from the order of Hankel-norm approximation;\nC = 10: DV is singular;\nC = 11: DW is singular;\nC = 12: the solution of the Sylvester equation failed\nC because the zeros of V (if JOB = 'N') or of conj(V)\nC (if JOB = 'C') are not distinct from the poles\nC of G1sr (see METHOD);\nC = 13: the solution of the Sylvester equation failed\nC because the zeros of W (if JOB = 'N') or of conj(W)\nC (if JOB = 'C') are not distinct from the poles\nC of G1sr (see METHOD).\nC\nC METHOD\nC\nC Let G be the transfer-function matrix of the original\nC linear system\nC\nC d[x(t)] = Ax(t) + Bu(t)\nC y(t) = Cx(t) + Du(t), (1)\nC\nC where d[x(t)] is dx(t)/dt for a continuous-time system and x(t+1)\nC for a discrete-time system. The subroutine AB09KD determines\nC the matrices of a reduced order system\nC\nC d[z(t)] = Ar*z(t) + Br*u(t)\nC yr(t) = Cr*z(t) + Dr*u(t), (2)\nC\nC such that the corresponding transfer-function matrix Gr minimizes\nC the Hankel-norm of the frequency-weighted error\nC\nC V*(G-Gr)*W, (3)\nC or\nC conj(V)*(G-Gr)*conj(W). (4)\nC\nC For minimizing (3), V and W are assumed to be antistable, while\nC for minimizing (4), V and W are assumed to be stable transfer-\nC function matrices.\nC\nC Note: conj(G) = G'(-s) for a continuous-time system and\nC conj(G) = G'(1/z) for a discrete-time system.\nC\nC The following procedure is used to reduce G (see [1]):\nC\nC 1) Decompose additively G as\nC\nC G = G1 + G2,\nC\nC such that G1 = (A1,B1,C1,D) has only ALPHA-stable poles and\nC G2 = (A2,B2,C2,0) has only ALPHA-unstable poles.\nC\nC 2) Compute G1s, the stable projection of V*G1*W or\nC conj(V)*G1*conj(W), using explicit formulas [4].\nC\nC 3) Determine G1sr, the optimal Hankel-norm approximation of G1s\nC of order r.\nC\nC 4) Compute G1r, the stable projection of either inv(V)*G1sr*inv(W)\nC or conj(inv(V))*G1sr*conj(inv(W)), using explicit formulas [4].\nC\nC 5) Assemble the reduced model Gr as\nC\nC Gr = G1r + G2.\nC\nC To reduce the weighted ALPHA-stable part G1s at step 3, the\nC optimal Hankel-norm approximation method of [2], based on the\nC square-root balancing projection formulas of [3], is employed.\nC\nC The optimal weighted approximation error satisfies\nC\nC HNORM[V*(G-Gr)*W] = S(r+1),\nC or\nC HNORM[conj(V)*(G-Gr)*conj(W)] = S(r+1),\nC\nC where S(r+1) is the (r+1)-th Hankel singular value of G1s, the\nC transfer-function matrix computed at step 2 of the above\nC procedure, and HNORM(.) denotes the Hankel-norm.\nC\nC REFERENCES\nC\nC [1] Latham, G.A. and Anderson, B.D.O.\nC Frequency-weighted optimal Hankel-norm approximation of stable\nC transfer functions.\nC Systems & Control Letters, Vol. 5, pp. 229-236, 1985.\nC\nC [2] Glover, K.\nC All optimal Hankel norm approximation of linear\nC multivariable systems and their L-infinity error bounds.\nC Int. J. Control, Vol. 36, pp. 1145-1193, 1984.\nC\nC [3] Tombs M.S. and Postlethwaite I.\nC Truncated balanced realization of stable, non-minimal\nC state-space systems.\nC Int. J. Control, Vol. 46, pp. 1319-1330, 1987.\nC\nC [4] Varga A.\nC Explicit formulas for an efficient implementation\nC of the frequency-weighting model reduction approach.\nC Proc. 1993 European Control Conference, Groningen, NL,\nC pp. 693-696, 1993.\nC\nC NUMERICAL ASPECTS\nC\nC The implemented methods rely on an accuracy enhancing square-root\nC technique.\nC 3\nC The algorithms require less than 30N floating point operations.\nC\nC CONTRIBUTORS\nC\nC A. Varga, German Aerospace Center, Oberpfaffenhofen, April 2000.\nC D. Sima, University of Bucharest, May 2000.\nC V. Sima, Research Institute for Informatics, Bucharest, May 2000.\nC Based on the RASP routines SFRLW, SFRLW1, SFRRW and SFRRW1,\nC by A. Varga, 1992.\nC\nC REVISIONS\nC\nC A. Varga, Australian National University, Canberra, November 2000.\nC V. Sima, Research Institute for Informatics, Bucharest, Dec. 2000.\nC Oct. 2001, March 2005.\nC\nC KEYWORDS\nC\nC Frequency weighting, model reduction, multivariable system,\nC state-space model, state-space representation.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION C100, ONE, ZERO\n PARAMETER ( C100 = 100.0D0, ONE = 1.0D0, ZERO = 0.0D0 )\nC .. Scalar Arguments ..\n CHARACTER DICO, EQUIL, JOB, ORDSEL, WEIGHT\n INTEGER INFO, IWARN, LDA, LDAV, LDAW, LDB, LDBV, LDBW,\n $ LDC, LDCV, LDCW, LDD, LDDV, LDDW, LDWORK, M, N,\n $ NR, NS, NV, NW, P\n DOUBLE PRECISION ALPHA, TOL1, TOL2\nC .. Array Arguments ..\n INTEGER IWORK(*)\n DOUBLE PRECISION A(LDA,*), AV(LDAV,*), AW(LDAW,*),\n $ B(LDB,*), BV(LDBV,*), BW(LDBW,*),\n $ C(LDC,*), CV(LDCV,*), CW(LDCW,*),\n $ D(LDD,*), DV(LDDV,*), DW(LDDW,*), DWORK(*),\n $ HSV(*)\nC .. Local Scalars ..\n LOGICAL CONJS, DISCR, FIXORD, FRWGHT, LEFTW, RIGHTW\n INTEGER IA, IB, IERR, IWARNL, KI, KL, KU, KW, LW, NMIN,\n $ NRA, NU, NU1\n DOUBLE PRECISION ALPWRK, MAXRED, RCOND, WRKOPT\nC .. External Functions ..\n LOGICAL LSAME\n DOUBLE PRECISION DLAMCH\n EXTERNAL DLAMCH, LSAME\nC .. External Subroutines ..\n EXTERNAL AB07ND, AB09CX, AB09KX, TB01ID, TB01KD, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC DBLE, MAX, MIN, SQRT\nC .. Executable Statements ..\nC\n INFO = 0\n IWARN = 0\n CONJS = LSAME( JOB, 'C' )\n DISCR = LSAME( DICO, 'D' )\n FIXORD = LSAME( ORDSEL, 'F' )\n LEFTW = LSAME( WEIGHT, 'L' ) .OR. LSAME( WEIGHT, 'B' )\n RIGHTW = LSAME( WEIGHT, 'R' ) .OR. LSAME( WEIGHT, 'B' )\n FRWGHT = LEFTW .OR. RIGHTW\nC\n IF ( DISCR .AND. CONJS ) THEN\n IA = 2*NV\n IB = 2*NW\n ELSE\n IA = 0\n IB = 0\n END IF\n LW = 1\n IF( LEFTW )\n $ LW = MAX( LW, NV*(NV+5), NV*N + MAX( IA, P*N, P*M ) )\n IF( RIGHTW )\n $ LW = MAX( LW, MAX( NW*(NW+5), NW*N + MAX( IB, M*N, P*M ) ) )\n LW = MAX( LW, N*( 2*N + MAX( N, M, P ) + 5 ) + ( N*( N + 1 ) )/2 )\n LW = MAX( LW, N*( M + P + 2 ) + 2*M*P + MIN( N, M ) +\n $ MAX ( 3*M + 1, MIN( N, M ) + P ) )\nC\nC Check the input scalar arguments.\nC\n IF( .NOT. ( LSAME( JOB, 'N' ) .OR. CONJS ) ) THEN\n INFO = -1\n ELSE IF( .NOT. ( LSAME( DICO, 'C' ) .OR. DISCR ) ) THEN\n INFO = -2\n ELSE IF( .NOT.( FRWGHT .OR. LSAME( WEIGHT, 'N' ) ) ) THEN\n INFO = -3\n ELSE IF( .NOT. ( LSAME( EQUIL, 'S' ) .OR.\n $ LSAME( EQUIL, 'N' ) ) ) THEN\n INFO = -4\n ELSE IF( .NOT. ( FIXORD .OR. LSAME( ORDSEL, 'A' ) ) ) THEN\n INFO = -5\n ELSE IF( N.LT.0 ) THEN\n INFO = -6\n ELSE IF( NV.LT.0 ) THEN\n INFO = -7\n ELSE IF( NW.LT.0 ) THEN\n INFO = -8\n ELSE IF( M.LT.0 ) THEN\n INFO = -9\n ELSE IF( P.LT.0 ) THEN\n INFO = -10\n ELSE IF( FIXORD .AND. ( NR.LT.0 .OR. NR.GT.N ) ) THEN\n INFO = -11\n ELSE IF( ( DISCR .AND. ( ALPHA.LT.ZERO .OR. ALPHA.GT.ONE ) ) .OR.\n $ ( .NOT.DISCR .AND. ALPHA.GT.ZERO ) ) THEN\n INFO = -12\n ELSE IF( LDA.LT.MAX( 1, N ) ) THEN\n INFO = -14\n ELSE IF( LDB.LT.MAX( 1, N ) ) THEN\n INFO = -16\n ELSE IF( LDC.LT.MAX( 1, P ) ) THEN\n INFO = -18\n ELSE IF( LDD.LT.MAX( 1, P ) ) THEN\n INFO = -20\n ELSE IF( LDAV.LT.1 .OR. ( LEFTW .AND. LDAV.LT.NV ) ) THEN\n INFO = -22\n ELSE IF( LDBV.LT.1 .OR. ( LEFTW .AND. LDBV.LT.NV ) ) THEN\n INFO = -24\n ELSE IF( LDCV.LT.1 .OR. ( LEFTW .AND. LDCV.LT.P ) ) THEN\n INFO = -26\n ELSE IF( LDDV.LT.1 .OR. ( LEFTW .AND. LDDV.LT.P ) ) THEN\n INFO = -28\n ELSE IF( LDAW.LT.1 .OR. ( RIGHTW .AND. LDAW.LT.NW ) ) THEN\n INFO = -30\n ELSE IF( LDBW.LT.1 .OR. ( RIGHTW .AND. LDBW.LT.NW ) ) THEN\n INFO = -32\n ELSE IF( LDCW.LT.1 .OR. ( RIGHTW .AND. LDCW.LT.M ) ) THEN\n INFO = -34\n ELSE IF( LDDW.LT.1 .OR. ( RIGHTW .AND. LDDW.LT.M ) ) THEN\n INFO = -36\n ELSE IF( TOL2.GT.ZERO .AND. .NOT.FIXORD .AND. TOL2.GT.TOL1 ) THEN\n INFO = -40\n ELSE IF( LDWORK.LT.LW ) THEN\n INFO = -43\n END IF\nC\n IF( INFO.NE.0 ) THEN\nC\nC Error return.\nC\n CALL XERBLA( 'AB09KD', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF( MIN( N, M, P ).EQ.0 ) THEN\n NR = 0\n NS = 0\n IWORK(1) = 0\n DWORK(1) = ONE\n RETURN\n END IF\nC\n IF( LSAME( EQUIL, 'S' ) ) THEN\nC\nC Scale simultaneously the matrices A, B and C:\nC A <- inv(D)*A*D, B <- inv(D)*B and C <- C*D, where D is a\nC diagonal matrix.\nC Workspace: N.\nC\n MAXRED = C100\n CALL TB01ID( 'All', N, M, P, MAXRED, A, LDA, B, LDB, C, LDC,\n $ DWORK, INFO )\n END IF\nC\nC Correct the value of ALPHA to ensure stability.\nC\n ALPWRK = ALPHA\n IF( DISCR ) THEN\n IF( ALPHA.EQ.ONE ) ALPWRK = ONE - SQRT( DLAMCH( 'E' ) )\n ELSE\n IF( ALPHA.EQ.ZERO ) ALPWRK = -SQRT( DLAMCH( 'E' ) )\n END IF\nC\nC Allocate working storage.\nC\n KU = 1\n KL = KU + N*N\n KI = KL + N\n KW = KI + N\nC\nC Reduce A to a block-diagonal real Schur form, with the\nC ALPHA-unstable part in the leading diagonal position, using a\nC non-orthogonal similarity transformation, A <- inv(T)*A*T, and\nC apply the transformation to B and C: B <- inv(T)*B and C <- C*T.\nC\nC Workspace needed: N*(N+2);\nC Additional workspace: need 3*N;\nC prefer larger.\nC\n CALL TB01KD( DICO, 'Unstable', 'General', N, M, P, ALPWRK, A, LDA,\n $ B, LDB, C, LDC, NU, DWORK(KU), N, DWORK(KL),\n $ DWORK(KI), DWORK(KW), LDWORK-KW+1, IERR )\nC\n IF( IERR.NE.0 ) THEN\n IF( IERR.NE.3 ) THEN\n INFO = 1\n ELSE\n INFO = 2\n END IF\n RETURN\n END IF\nC\n WRKOPT = DWORK(KW) + DBLE( KW-1 )\nC\nC Compute the stable projection of the weighted ALPHA-stable part.\nC\nC Workspace: need MAX( 1, LDW1, LDW2 ),\nC LDW1 = 0 if WEIGHT = 'R' or 'N' and\nC LDW1 = MAX( NV*(NV+5), NV*N + MAX( a, P*N, P*M ) )\nC if WEIGHT = 'L' or 'B',\nC LDW2 = 0 if WEIGHT = 'L' or 'N' and\nC LDW2 = MAX( NW*(NW+5), NW*N + MAX( b, M*N, P*M ) )\nC if WEIGHT = 'R' or 'B',\nC where a = 0, b = 0, if DICO = 'C' or JOB = 'N',\nC a = 2*NV, b = 2*NW, if DICO = 'D' and JOB = 'C';\nC prefer larger.\nC\n NS = N - NU\nC\nC Finish if only unstable part is present.\nC\n IF( NS.EQ.0 ) THEN\n NR = NU\n IWORK(1) = 0\n DWORK(1) = WRKOPT\n RETURN\n END IF\nC\n NU1 = NU + 1\n IF( FRWGHT ) THEN\n CALL AB09KX( JOB, DICO, WEIGHT, NS, NV, NW, M, P, A(NU1,NU1),\n $ LDA, B(NU1,1), LDB, C(1,NU1), LDC, D, LDD,\n $ AV, LDAV, BV, LDBV, CV, LDCV, DV, LDDV,\n $ AW, LDAW, BW, LDBW, CW, LDCW, DW, LDDW,\n $ DWORK, LDWORK, IWARNL, IERR )\nC\n IF( IERR.NE.0 ) THEN\nC\nC Note: Only IERR = 1 or IERR = 2 are possible.\nC Set INFO to 3 or 4.\nC\n INFO = IERR + 2\n RETURN\n END IF\nC\n IF( IWARNL.NE.0 ) THEN\nC\nC Stability/antistability of V and W are compulsory.\nC\n IF( IWARNL.EQ.1 .OR. IWARNL.EQ.3 ) THEN\n INFO = 5\n ELSE\n INFO = 6\n END IF\n RETURN\n END IF\nC\n DWORK(1) = MAX( WRKOPT, DWORK(1) )\n END IF\nC\nC Determine a reduced order approximation of the ALPHA-stable part.\nC\nC Workspace: need MAX( LDW3, LDW4 ),\nC LDW3 = N*(2*N + MAX(N,M,P) + 5) + N*(N+1)/2,\nC LDW4 = N*(M+P+2) + 2*M*P + MIN(N,M) +\nC MAX( 3*M+1, MIN(N,M)+P );\nC prefer larger.\nC\n IWARNL = 0\n IF( FIXORD ) THEN\n NRA = MAX( 0, NR - NU )\n IF( NRA.EQ.0 )\n $ IWARNL = 2\n ELSE\n NRA = 0\n END IF\n CALL AB09CX( DICO, ORDSEL, NS, M, P, NRA, A(NU1,NU1), LDA,\n $ B(NU1,1), LDB, C(1,NU1), LDC, D, LDD, HSV, TOL1,\n $ TOL2, IWORK, DWORK, LDWORK, IWARN, IERR )\nC\n IWARN = MAX( IWARN, IWARNL )\n IF( IERR.NE.0 ) THEN\nC\nC Set INFO = 7, 8 or 9.\nC\n INFO = IERR + 5\n RETURN\n END IF\nC\n WRKOPT = MAX( WRKOPT, DWORK(1) )\n NMIN = IWORK(1)\nC\nC Compute the state space realizations of the inverses of V and W.\nC\nC Integer workspace: need c,\nC Real workspace: need MAX(1,2*c),\nC where c = 0, if WEIGHT = 'N',\nC c = 2*P, if WEIGHT = 'L',\nC c = 2*M, if WEIGHT = 'R',\nC c = MAX(2*M,2*P), if WEIGHT = 'B'.\nC\n IF( LEFTW ) THEN\n CALL AB07ND( NV, P, AV, LDAV, BV, LDBV, CV, LDCV, DV, LDDV,\n $ RCOND, IWORK, DWORK, LDWORK, IERR )\n IF( IERR.NE.0 ) THEN\n INFO = 10\n RETURN\n END IF\n END IF\n IF( RIGHTW ) THEN\n CALL AB07ND( NW, M, AW, LDAW, BW, LDBW, CW, LDCW, DW, LDDW,\n $ RCOND, IWORK, DWORK, LDWORK, IERR )\n IF( IERR.NE.0 ) THEN\n INFO = 11\n RETURN\n END IF\n END IF\nC\n WRKOPT = MAX( WRKOPT, DWORK(1) )\nC\nC Compute the stable projection of weighted reduced ALPHA-stable\nC part.\nC\n IF( FRWGHT ) THEN\n CALL AB09KX( JOB, DICO, WEIGHT, NRA, NV, NW, M, P, A(NU1,NU1),\n $ LDA, B(NU1,1), LDB, C(1,NU1), LDC, D, LDD,\n $ AV, LDAV, BV, LDBV, CV, LDCV, DV, LDDV,\n $ AW, LDAW, BW, LDBW, CW, LDCW, DW, LDDW,\n $ DWORK, LDWORK, IWARNL, IERR )\nC\n IF( IERR.NE.0 ) THEN\n IF( IERR.LE.2 ) THEN\nC\nC Set INFO to 3 or 4.\nC\n INFO = IERR + 2\n ELSE\nC\nC Set INFO to 12 or 13.\nC\n INFO = IERR + 9\n END IF\n RETURN\n END IF\n END IF\nC\n NR = NRA + NU\n IWORK(1) = NMIN\n DWORK(1) = MAX( WRKOPT, DWORK(1) )\nC\n RETURN\nC *** Last line of AB09KD ***\n END\n", "meta": {"hexsha": "0d3fb73c1b76f188792a2764b5be2748198919c4", "size": 34278, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/AB09KD.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/AB09KD.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/AB09KD.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 40.2796709753, "max_line_length": 72, "alphanum_fraction": 0.5357663808, "num_tokens": 10352, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9314625031628428, "lm_q2_score": 0.6992544147913994, "lm_q1q2_score": 0.6513292675492657}} {"text": " subroutine DEVVUN(A, LDA, N, EVALR, EVALI, VEC, IFLAG, WORK)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nc This file contains DEVVUN and CDIV.\nc>> 1996-03-30 DEVUNN Krogh MIN0 => MIN, added external statement.\nc>> 1994-11-02 DEVVUN Krogh Changes to use M77CON\nc>> 1992-04-23 DEVVUN CLL Declaring all variables.\nc>> 1992-04-22 DEVVUN Krogh Removed unused labels 330 and 1220.\nc>> 1992-03-05 DEVVUN Krogh Initial version, converted from EISPACK.\nc\nc This subroutine uses slight modifcations of EISPACK routines\nc BALANC, ELMHES, ELTRAN, HQR2 and BALBAK to get the eigenvalues and\nc eigenvectors of a general real matrix by the QR method. The first\nc two are are encapsulated in DEVBH. The following three are given\nc inline here.\nc\nc ELTRAN is a translation of the algol procedure ELMTRANS,\nc Num. Math. 16, 181-204(1970) by Peters and Wilkinson.\nc Handbook for Auto. Comp., Vol.ii-Linear Algebra, 372-395(1971).\nc\nc HQR2 is a translation of the ALGOL procedure HQR2,\nc Num. Math. 16, 181-204(1970) by Peters and Wilkinson.\nc Handbook for Auto. Comp., Vol.ii-Linear Algebra, 372-395(1971).\nc\nc BALBAK is a translation of the ALGOL procedure BALBAK,\nc Num. Math. 13, 293-304(1969) by Parlett and Reinsch.\nc Handbook for Auto. Comp., Vol.ii-Linear Algebra, 315-326(1971).\nc\nc This subroutine finds the eigenvalues and eigenvectors\nc of a real general matrix by the QR method.\nc\nc On input\nc\nc LDA must be set to the row dimension of two-dimensional\nc array parameters as declared in the calling program\nc dimension statement.\nc N is the order of the matrix.\nc A contains the input matrix whose eigenvalues and eigenvectors\nc are desired.\nc\nc On output\nc A has been destroyed.\nc EVALR and EVALI contain real and imaginary parts, respectively, of\nc the eigenvalues. The eigenvalues are given in order of\nc increasing real parts. When real parts are equal they are\nc given in order of increasing absolute complex part. Complex\nc conjugate pairs of values appear consecutively with\nc the eigenvalue having the positive imaginary part first. If\nc an error exit is made, the eigenvalues should be correct\nc (but unordered) for indices IFLAG(1)+1,...,N.\nc VEC contains the real and imaginary parts of the eigenvectors.\nc if the I-th eigenvalue is real, the I-th column of VEC\nc contains its eigenvector. If the I-th eigenvalue is complex\nc with positive imaginary part, the I-th and (I+1)-th\nc columns of VEC contain the real and imaginary parts of its\nc eigenvector. The eigenvectors are unnormalized. If an\nc error exit is made, none of the eigenvectors has been found.\nc IFLAG(1) is set to\nc 1 If all eigenvalues are real.\nc 2 If some eigenvalues are complex.\nc 3 If N < 1 on the initial entry.\nc 4 If the limit of 30*N iterations is exhausted.\nc ------------------------------------------------------------------\nc--D replaces \"?\": ?EVVUN, ?EVBH, ?NRM2, ?SCAL, ?CDIV\nc ------------------------------------------------------------------\n external DNRM2\n integer I,J,K,L,M,N,EN,NA,LDA,IGH,ITN,ITS,LOW,MP,MP2,ENM2\n integer II, IFLAG(N), LTYPE\n double precision A(LDA,N),EVALR(N),EVALI(N),VEC(LDA,N), WORK(N)\n double precision P,Q,R,S,T,W,X,Y,RA,SA,VI,VR,ZZ,NORM,TST1,TST2\n double precision DNRM2\n logical NOTLAS\nc ------------------------------------------------------------------\nc\n call DEVBH(A, LDA, N, LOW, IGH, IFLAG, WORK)\n LTYPE = 1\nc\nc -------------------------------- ELTRAN ---------------------------\nc\nc Accumulate the stabilized elementary similarity transformations\nc used in the preceding reduction of the matrix to upper Hessenberg\nc form.\nc\nc .......... initialize VEC to identity matrix ..........\n do 20 J = 1, N\n do 10 I = 1, N\n VEC(I,J) = 0.0D0\n 10 continue\n VEC(J,J) = 1.0D0\n 20 continue\n if (IGH .gt. LOW+1) then\n do 50 MP = IGH-1, LOW+1, -1\n do 30 I = MP+1, IGH\n VEC(I,MP) = A(I,MP-1)\n 30 continue\n I = IFLAG(MP)\n if (I .ne. MP) then\n do 40 J = MP, IGH\n VEC(MP,J) = VEC(I,J)\n VEC(I,J) = 0.0D0\n 40 continue\n VEC(I,MP) = 1.0D0\n end if\n 50 continue\n end if\nc\nc -------------------------------- HQR2 -----------------------------\nc\nc Find the eigenvalues of a real upper Hessenberg matrix by the QR\nc method.\nc\n IFLAG(1) = 0\n NORM = 0.0D0\n K = 1\nc .......... store roots isolated by balanc\nc and compute matrix norm ..........\n do 70 I = 1, N\n do 60 J = K, N\n NORM = NORM + abs(A(I,J))\n 60 continue\n K = I\n if ((I .lt. LOW) .or. (I .gt. IGH)) then\n EVALR(I) = A(I,I)\n EVALI(I) = 0.0D0\n end if\n 70 continue\n EN = IGH\n T = 0.0D0\n ITN = 30*N\nc .......... search for next eigenvalues ..........\n 80 if (EN .lt. LOW) go to 340\n ITS = 0\n NA = EN - 1\n ENM2 = NA - 1\nc .......... look for single small sub-diagonal element\n 90 do 100 L = EN, LOW+1, -1\n S = abs(A(L-1,L-1)) + abs(A(L,L))\n if (S .eq. 0.0D0) S = NORM\n TST1 = S\n TST2 = TST1 + abs(A(L,L-1))\n if (TST2 .eq. TST1) go to 110\n 100 continue\nc .......... form shift ..........\n 110 X = A(EN,EN)\n if (L .eq. EN) go to 270\n Y = A(NA,NA)\n W = A(EN,NA) * A(NA,EN)\n if (L .eq. NA) go to 280\n if (ITN .le. 0) then\nc .......... set error -- all eigenvalues have not\nc converged after 30*N iterations ..........\n call ERMSG('DEVVUN', EN, 0,\n 1'ERROR NO. is index of eigenvalue causing convergence failure.',\n 2 '.')\n IFLAG(1) = 4\n if (EN .le. 0) IFLAG(1) = 3\n return\n end if\n if (ITS .ne. 10 .and. ITS .ne. 20) go to 130\nc .......... form exceptional shift ..........\n T = T + X\n do 120 I = LOW, EN\n A(I,I) = A(I,I) - X\n 120 continue\n S = abs(A(EN,NA)) + abs(A(NA,ENM2))\n X = 0.75D0 * S\n Y = X\n W = -0.4375D0 * S * S\n 130 ITS = ITS + 1\n ITN = ITN - 1\nc .......... look for two consecutive small sub-diagonal elements.\n do 140 M = ENM2, L, -1\n ZZ = A(M,M)\n R = X - ZZ\n S = Y - ZZ\n P = (R * S - W) / A(M+1,M) + A(M,M+1)\n Q = A(M+1,M+1) - ZZ - R - S\n R = A(M+2,M+1)\n S = abs(P) + abs(Q) + abs(R)\n P = P / S\n Q = Q / S\n R = R / S\n if (M .eq. L) go to 150\n TST1 = abs(P)*(abs(A(M-1,M-1)) + abs(ZZ) + abs(A(M+1,M+1)))\n TST2 = TST1 + abs(A(M,M-1))*(abs(Q) + abs(R))\n if (TST2 .eq. TST1) go to 150\n 140 continue\n 150 MP2 = M + 2\n do 160 I = MP2, EN\n A(I,I-2) = 0.0D0\n if (I .ne. MP2) A(I,I-3) = 0.0D0\n 160 continue\nc .......... double QR step involving rows L to EN and\nc columns M to EN ..........\n do 260 K = M, NA\n NOTLAS = K .ne. NA\n if (K .ne. M) then\n P = A(K,K-1)\n Q = A(K+1,K-1)\n R = 0.0D0\n if (NOTLAS) R = A(K+2,K-1)\n X = abs(P) + abs(Q) + abs(R)\n if (X .eq. 0.0D0) go to 260\n P = P / X\n Q = Q / X\n R = R / X\n end if\n S = sign(sqrt(P*P+Q*Q+R*R),P)\n if (K .ne. M) then\n A(K,K-1) = -S * X\n else\n if (L .ne. M) A(K,K-1) = -A(K,K-1)\n end if\n P = P + S\n X = P / S\n Y = Q / S\n ZZ = R / S\n Q = Q / P\n R = R / P\n if (NOTLAS) then\nc .......... row modification ..........\n do 200 J = K, N\n P = A(K,J) + Q * A(K+1,J) + R * A(K+2,J)\n A(K,J) = A(K,J) - P * X\n A(K+1,J) = A(K+1,J) - P * Y\n A(K+2,J) = A(K+2,J) - P * ZZ\n 200 continue\n J = min(EN,K+3)\nc .......... column modification ..........\n do 210 I = 1, J\n P = X * A(I,K) + Y * A(I,K+1) + ZZ * A(I,K+2)\n A(I,K) = A(I,K) - P\n A(I,K+1) = A(I,K+1) - P * Q\n A(I,K+2) = A(I,K+2) - P * R\n 210 continue\nc .......... accumulate transformations ..........\n do 220 I = LOW, IGH\n P = X * VEC(I,K) + Y * VEC(I,K+1) + ZZ * VEC(I,K+2)\n VEC(I,K) = VEC(I,K) - P\n VEC(I,K+1) = VEC(I,K+1) - P * Q\n VEC(I,K+2) = VEC(I,K+2) - P * R\n 220 continue\n else\nc .......... row modification ..........\n do 230 J = K, N\n P = A(K,J) + Q * A(K+1,J)\n A(K,J) = A(K,J) - P * X\n A(K+1,J) = A(K+1,J) - P * Y\n 230 continue\nc\n J = min(EN,K+3)\nc .......... column modification ..........\n do 240 I = 1, J\n P = X * A(I,K) + Y * A(I,K+1)\n A(I,K) = A(I,K) - P\n A(I,K+1) = A(I,K+1) - P * Q\n 240 continue\nc .......... accumulate transformations ..........\n do 250 I = LOW, IGH\n P = X * VEC(I,K) + Y * VEC(I,K+1)\n VEC(I,K) = VEC(I,K) - P\n VEC(I,K+1) = VEC(I,K+1) - P * Q\n 250 continue\n end if\n 260 continue\n go to 90\nc .......... one root found ..........\n 270 A(EN,EN) = X + T\n EVALR(EN) = A(EN,EN)\n EVALI(EN) = 0.0D0\n EN = NA\n go to 80\nc .......... two roots found ..........\n 280 P = (Y - X) / 2.0D0\n Q = P * P + W\n ZZ = sqrt(abs(Q))\n A(EN,EN) = X + T\n X = A(EN,EN)\n A(NA,NA) = Y + T\n if (Q .ge. 0.0D0) then\nc .......... real pair ..........\n ZZ = P + sign(ZZ,P)\n EVALR(NA) = X + ZZ\n EVALR(EN) = EVALR(NA)\n if (ZZ .ne. 0.0D0) EVALR(EN) = X - W / ZZ\n EVALI(NA) = 0.0D0\n EVALI(EN) = 0.0D0\n X = A(EN,NA)\n S = abs(X) + abs(ZZ)\n P = X / S\n Q = ZZ / S\n R = sqrt(P*P+Q*Q)\n P = P / R\n Q = Q / R\nc .......... row modification ..........\n do 290 J = NA, N\n ZZ = A(NA,J)\n A(NA,J) = Q * ZZ + P * A(EN,J)\n A(EN,J) = Q * A(EN,J) - P * ZZ\n 290 continue\nc .......... column modification ..........\n do 300 I = 1, EN\n ZZ = A(I,NA)\n A(I,NA) = Q * ZZ + P * A(I,EN)\n A(I,EN) = Q * A(I,EN) - P * ZZ\n 300 continue\nc .......... accumulate transformations ..........\n do 310 I = LOW, IGH\n ZZ = VEC(I,NA)\n VEC(I,NA) = Q * ZZ + P * VEC(I,EN)\n VEC(I,EN) = Q * VEC(I,EN) - P * ZZ\n 310 continue\n else\nc .......... complex pair ..........\n LTYPE = 2\n EVALR(NA) = X + P\n EVALR(EN) = X + P\n EVALI(NA) = ZZ\n EVALI(EN) = -ZZ\n end if\n EN = ENM2\n go to 80\nc .......... all roots found. Backsubstitute to find\nc vectors of upper triangular form ..........\n 340 if (NORM .eq. 0.0D0) go to 1000\n do 800 EN = N, 1, -1\n P = EVALR(EN)\n Q = EVALI(EN)\n NA = EN - 1\n if (Q) 710, 600, 800\nc .......... real vector ..........\n 600 M = EN\n A(EN,EN) = 1.0D0\n do 700 I = NA, 1, -1\n W = A(I,I) - P\n R = 0.0D0\n do 610 J = M, EN\n R = R + A(I,J) * A(J,EN)\n 610 continue\n if (EVALI(I) .lt. 0.0D0) then\n ZZ = W\n S = R\n else\n M = I\n if (EVALI(I) .eq. 0.0D0) then\n T = W\n if (T .eq. 0.0D0) then\n TST1 = NORM\n T = TST1\n 640 T = 0.01D0 * T\n TST2 = NORM + T\n if (TST2 .gt. TST1) go to 640\n end if\n A(I,EN) = -R / T\n else\nc .......... solve real equations ..........\n X = A(I,I+1)\n Y = A(I+1,I)\n Q = (EVALR(I)-P) * (EVALR(I)-P) + EVALI(I) * EVALI(I)\n T = (X * S - ZZ * R) / Q\n A(I,EN) = T\n if (abs(X) .gt. abs(ZZ)) then\n A(I+1,EN) = (-R - W * T) / X\n else\n A(I+1,EN) = (-S - Y * T) / ZZ\n end if\n end if\nc .......... overflow control ..........\n T = abs(A(I,EN))\n if (T .ne. 0.0D0) then\n TST1 = T\n TST2 = TST1 + 1.0D0/TST1\n if (TST2 .le. TST1) then\n do 690 J = I, EN\n A(J,EN) = A(J,EN)/T\n 690 continue\n end if\n end if\n end if\n 700 continue\nc .......... end real vector ..........\n go to 800\nc\nc .......... complex vector ..........\n 710 M = NA\nc .......... last vector component chosen imaginary so that\nc eigenvector matrix is triangular ..........\n if (abs(A(EN,NA)) .gt. abs(A(NA,EN))) then\n A(NA,NA) = Q / A(EN,NA)\n A(NA,EN) = -(A(EN,EN) - P) / A(EN,NA)\n else\n call DCDIV(0.0D0,-A(NA,EN),A(NA,NA)-P,Q,A(NA,NA),A(NA,EN))\n end if\n A(EN,NA) = 0.0D0\n A(EN,EN) = 1.0D0\n ENM2 = NA - 1\n do 760 I = ENM2, 1, -1\n W = A(I,I) - P\n RA = 0.0D0\n SA = 0.0D0\n do 730 J = M, EN\n RA = RA + A(I,J) * A(J,NA)\n SA = SA + A(I,J) * A(J,EN)\n 730 continue\n if (EVALI(I) .lt. 0.0D0) then\n ZZ = W\n R = RA\n S = SA\n else\n M = I\n if (EVALI(I) .eq. 0.0D0) then\n call DCDIV(-RA,-SA,W,Q,A(I,NA),A(I,EN))\n else\nc .......... solve complex equations ..........\n X = A(I,I+1)\n Y = A(I+1,I)\n VR = (EVALR(I)-P)*(EVALR(I)-P)+EVALI(I)*EVALI(I)-Q*Q\n VI = (EVALR(I) - P) * 2.0D0 * Q\n if (VR .eq. 0.0D0 .and. VI .eq. 0.0D0) then\n TST1 = NORM * (abs(W)+abs(Q)+abs(X)+abs(Y)+abs(ZZ))\n VR = TST1\n 740 VR = 0.01D0 * VR\n TST2 = TST1 + VR\n if (TST2 .gt. TST1) go to 740\n end if\n call DCDIV(X*R-ZZ*RA+Q*SA,X*S-ZZ*SA-Q*RA,VR,VI,\n x A(I,NA),A(I,EN))\n if (abs(X) .gt. abs(ZZ) + abs(Q)) then\n A(I+1,NA) = (-RA - W * A(I,NA) + Q * A(I,EN)) / X\n A(I+1,EN) = (-SA - W * A(I,EN) - Q * A(I,NA)) / X\n else\n call DCDIV(-R-Y*A(I,NA),-S-Y*A(I,EN),ZZ,Q,\n x A(I+1,NA),A(I+1,EN))\n end if\n end if\nc .......... overflow control ..........\n T = max(abs(A(I,NA)), abs(A(I,EN)))\n if (T .ne. 0.0D0) then\n TST1 = T\n TST2 = TST1 + 1.0D0/TST1\n if (TST2 .le. TST1) then\n do 750 J = I, EN\n A(J,NA) = A(J,NA)/T\n A(J,EN) = A(J,EN)/T\n 750 continue\n end if\n end if\n end if\n 760 continue\nc .......... end complex vector ..........\n 800 continue\nc .......... end back substitution.\nc vectors of isolated roots ..........\n do 840 I = 1, N\n if (I .ge. LOW .and. I .le. IGH) go to 840\nc\n do 820 J = I, N\n VEC(I,J) = A(I,J)\n 820 continue\nc\n 840 continue\nc .......... multiply by transformation matrix to give\nc vectors of original full matrix.\n do 880 J = N, LOW, -1\n M = min(J,IGH)\nc\n do 880 I = LOW, IGH\n ZZ = 0.0D0\nc\n do 860 K = LOW, M\n ZZ = ZZ + VEC(I,K) * A(K,J)\n 860 continue\nc\n VEC(I,J) = ZZ\n 880 continue\nc\n 1000 continue\nc\nc ------------------------------ BALBAK -----------------------------\nc\nc Form eigenvectors of a real general matrix by back transforming\nc those of the corresponding balanced matrix determined by BALANC.\nc\n if (IGH .ne. LOW) then\n do 1110 I = LOW, IGH\n S = WORK(I)\nc .......... left hand eigenvectors are back transformed\nc if the foregoing statement is replaced by\nc S=1.0D0/WORK(I). ..........\n do 1100 J = 1, N\n VEC(I,J) = VEC(I,J) * S\n 1100 continue\n 1110 continue\n end if\nc ......... for I=LOW-1 step -1 until 1,\nc IGH+1 step 1 until N do -- ..........\n do 1140 II = 1, N\n I = II\n if ((I .lt. LOW) .or. (I .gt. IGH)) then\n if (I .lt. LOW) I = LOW - II\n K = WORK(I)\n if (K .ne. I) then\n do 1130 J = 1, N\n S = VEC(I,J)\n VEC(I,J) = VEC(K,J)\n VEC(K,J) = S\n 1130 continue\n end if\n end if\n 1140 continue\nc Normalize the eigenvectors\n do 1220 I = 1, N\n P = DNRM2(N, VEC(1, I), 1)\n if (EVALI(I) .eq. 0.D0) then\n call DSCAL(N, sign(1.D0, VEC(1,I)) / P, VEC(1,I), 1)\n else if (EVALI(I) .gt. 0.D0) then\n Q = DNRM2(N, VEC(1, I+1), 1)\n if (P .gt. Q) then\n P = P * sqrt(1.D0 + (Q/P)**2)\n else if (Q .ne. 0.D0) then\n P = Q * sqrt(1.D0 + (P/Q)**2)\n else\n go to 1220\n end if\n if (VEC(1, I+1) .eq. 0.D0) then\n P = sign(1.D0, VEC(1,I+1)) / P\n Q = 0.D0\n else if (abs(VEC(1, I)) .gt. abs(VEC(1, I+1))) then\n P = 1.D0 / (P*sqrt(1.D0+(VEC(1,I+1)/VEC(1,I))**2))\n Q = P * (VEC(1,I+1) / abs(VEC(1,I)))\n P = sign(P, VEC(1, I))\n else\n Q = 1.D0 / (P*sqrt(1.D0+(VEC(1,I)/VEC(1,I+1))**2))\n P = Q * (VEC(1,I) / abs(VEC(1,I+1)))\n Q = sign(Q, VEC(1, I+1))\n end if\n do 1200 J = 1, N\n R = P * VEC(J, I) + Q * VEC(J, I+1)\n VEC(J, I+1) = P * VEC(J, I+1) - Q * VEC(J, I)\n VEC(J, I) = R\n 1200 continue\n end if\n 1220 continue\nc-- Begin mask code changes\nc Set up for Shell sort\nc Sort so real parts are algebraically increasing\nc For = real parts, so abs(imag. parts) are increasing\nc For both =, sort on index -- preserves complex pair order\nc-- End mask code changes\n do 2000 I = 1, N\n IFLAG(I) = I\n 2000 continue\n L = 1\n do 2010 K = 1, N\n L = 3*L + 1\n if (L .ge. N) go to 2020\n 2010 continue\n 2020 L = max(1, (L-4) / 9)\n 2030 do 2100 J = L+1, N\n K = IFLAG(J)\n P = EVALR(K)\n I = J - L\n 2040 if (P - EVALR(IFLAG(I))) 2070, 2050, 2080\n 2050 if (abs(EVALI(K)) - abs(EVALI(IFLAG(I)))) 2070, 2060, 2080\n 2060 if (K .gt. IFLAG(I)) go to 2080\n 2070 IFLAG(I+L) = IFLAG(I)\n I = I - L\n if (I .gt. 0) go to 2040\n 2080 IFLAG(I+L) = K\n 2100 continue\n L = (L-1) / 3\n if (L .ne. 0) go to 2030\nc Indices in IFLAG now give the desired order --\nc Move entries to get this order.\n 2110 do 2150 I = L+1, N\n if (IFLAG(I) .ne. I) then\n L = I\n M = I\n P = EVALR(I)\n Q = EVALI(I)\n do 2115 J = 1, N\n WORK(J) = VEC(J, I)\n 2115 continue\n 2120 K = IFLAG(M)\n IFLAG(M) = M\n if (K .ne. L) then\n EVALR(M) = EVALR(K)\n EVALI(M) = EVALI(K)\n do 2130 J = 1, N\n VEC(J, M) = VEC(J, K)\n 2130 continue\n M = K\n go to 2120\n else\n EVALR(M) = P\n EVALI(M) = Q\n do 2140 J = 1, N\n VEC(J, M) = WORK(J)\n 2140 continue\n go to 2110\n end if\n end if\n 2150 continue\n IFLAG(1) = LTYPE\n return\n end\nc ==================================================================\n subroutine DCDIV(AR,AI,BR,BI,CR,CI)\nc\nc complex division, (CR,CI) = (AR,AI)/(BR,BI)\nc ------------------------------------------------------------------\n double precision AR,AI,BR,BI,CR,CI\n double precision S,ARS,AIS,BRS,BIS\n S = abs(BR) + abs(BI)\n ARS = AR/S\n AIS = AI/S\n BRS = BR/S\n BIS = BI/S\n S = BRS**2 + BIS**2\n CR = (ARS*BRS + AIS*BIS)/S\n CI = (AIS*BRS - ARS*BIS)/S\n return\n end\n", "meta": {"hexsha": "7eae96228694b83487f415c8ec9003c7408d4b8a", "size": 21298, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/devvun.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/devvun.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/devvun.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": 34.0768, "max_line_length": 72, "alphanum_fraction": 0.4164240774, "num_tokens": 7116, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872046056466901, "lm_q2_score": 0.7341195385342971, "lm_q1q2_score": 0.6513142356828512}} {"text": "SUBROUTINE deemat(dee,e,v)\n!\n! This subroutine returns the elastic dee matrix for ih=3 (plane strain),\n! ih=4 (axisymmetry or plane strain elastoplasticity) or ih=6\n! (three dimensions).\n!\n IMPLICIT NONE\n INTEGER,PARAMETER::iwp=SELECTED_REAL_KIND(15)\n REAL(iwp),INTENT(IN)::e,v\n REAL(iwp),INTENT(OUT)::dee(:,:)\n REAL(iwp)::v1,v2,c,vv,zero=0.0_iwp,pt5=0.5_iwp,one=1.0_iwp,two=2.0_iwp\n INTEGER::i,ih\n dee=zero \n ih=UBOUND(dee,1)\n v1=one-v\n c=e/((one+v)*(one-two*v))\n SELECT CASE(ih)\n CASE(3)\n dee(1,1)=v1*c\n dee(2,2)=v1*c\n dee(1,2)=v*c\n dee(2,1)=v*c\n dee(3,3)=pt5*c*(one-two*v)\n CASE(4)\n dee(1,1)=v1*c\n dee(2,2)=v1*c\n dee(4,4)=v1*c\n dee(3,3)=pt5*c*(one-two*v) \n dee(1,2)=v*c\n dee(2,1)=v*c\n dee(1,4)=v*c\n dee(4,1)=v*c\n dee(2,4)=v*c\n dee(4,2)=v*c\n CASE(6)\n v2=v/(one-v)\n vv=(one-two*v)/(one-v)*pt5\n DO i=1,3\n dee(i,i)=one\n END DO\n DO i=4,6\n dee(i,i)=vv\n END DO\n dee(1,2)=v2\n dee(2,1)=v2\n dee(1,3)=v2\n dee(3,1)=v2\n dee(2,3)=v2\n dee(3,2)=v2\n dee=dee*e/(two*(one+v)*vv)\n CASE DEFAULT\n WRITE(*,*)'wrong size for dee matrix'\n END SELECT\nRETURN\nEND SUBROUTINE deemat \n", "meta": {"hexsha": "c4328248cb2e247b83ef725dc6065f1721811fdf", "size": 1128, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "main/deemat.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/deemat.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/deemat.f90", "max_forks_repo_name": "cunyizju/Programming-FEM-5th-Fortran", "max_forks_repo_head_hexsha": "7740d381c0871c7e860aee8a19c467bd97a4cf45", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-06-03T12:47:06.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-30T13:35:28.000Z", "avg_line_length": 20.1428571429, "max_line_length": 73, "alphanum_fraction": 0.5930851064, "num_tokens": 520, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045966995027, "lm_q2_score": 0.7341195210831261, "lm_q1q2_score": 0.6513142136317869}} {"text": "!******************************************************************************\n!*\n!* GENERAL ADAPTATIVE GRID WITH ACCURACY CONTROL\n!*\n!******************************************************************************\n\n !==========================================================================\n ! 1) AUTHOR: F. Galliano\n !\n ! 2) HISTORY: \n ! - Created 04/2014 \n ! \n ! 3) DESCRIPTION: function generating adaptative grid, with control of the \n ! accuracy on the interpolation.\n !==========================================================================\n\nMODULE adaptative_grid\n\n USE utilities, ONLY:\n USE arrays, ONLY:\n USE integration, ONLY:\n IMPLICIT NONE\n PRIVATE\n\n PUBLIC :: gridadapt1D, grid_kernel\n\n INTERFACE gridadapt1D\n MODULE PROCEDURE gridadapt1D_simple, gridadapt1D_zgrid\n END INTERFACE gridadapt1D\n\n\nCONTAINS\n\n\n ! Interface for DPRIMITIVE (removing the first element)\n !-------------------------\n PURE FUNCTION dPrim (x,f,xlog,ylog,lnx,lnf)\n\n USE utilities, ONLY: DP\n USE integration, ONLY: dPrimitive\n IMPLICIT NONE\n\n REAL(DP), INTENT(IN), DIMENSION(:) :: x, f\n LOGICAL, INTENT(IN) :: xlog, ylog\n REAL(DP), INTENT(IN), DIMENSION(:), OPTIONAL :: lnx, lnf\n REAL(DP), DIMENSION(SIZE(x)-1) :: dPrim\n\n INTEGER :: N\n REAL(DP), DIMENSION(SIZE(x)) :: dF\n\n !------------------------------------------------------------------------\n\n N = SIZE(x)\n IF (.NOT. xlog .AND. ylog) THEN \n dF(:) = DPRIMITIVE(x,f,XLOG=xlog,YLOG=ylog,LNF=lnf)\n ELSE IF (xlog .AND. ylog) THEN\n dF(:) = DPRIMITIVE(x,f,XLOG=xlog,YLOG=ylog,LNX=lnx,LNF=lnf)\n ELSE\n dF(:) = DPRIMITIVE(x,f,XLOG=xlog,YLOG=ylog)\n END IF\n dPrim(:) = dF(2:N)\n\n !------------------------------------------------------------------------ \n \n END FUNCTION dPrim\n\n\n !==========================================================================\n ! CALL GRIDADAPT1D_SIMPLE (xcoarse[N0],xfine[N],yfine[N],yfunc,accuracy, &\n ! ABSACC=T/F,INTERP=T/F,INTEG=T/F,primitive[N], &\n ! XLOG=T/F,YLOG=T/F,REEVALUATE=T/F,MINSTEP=, &\n ! /LNFUNC,/RESCALE,/ADJUSTXLIM[2], &\n ! SCALING=,NMAX=)\n !\n ! Returns an adaptative grid xfine[N], and function values yfine[N] of \n ! function, YFUNC, from an initial grid xcoarse[N0] (between x0min and x0max).\n ! The grid adapted so that the accuracy on the linear interpretation between \n ! two values is better than ACCURACY.\n ! If ABSACC is true, then it is an absolute accuracy (default is relative).\n ! If INTEG is true, the accuracy is on the integral and not on the \n ! interpolation.\n ! If keyword REEVALUATE is set, then the function is evaluated on the entire\n ! grid at each iteration, while it is evaluated only at mid-points if it is \n ! not set. REEVALUATE is used when the function needs the entire grid to be \n ! evaluated properly (normalization, etc.).\n ! If keyword SLIM is set, then we keep only the points needed to achieve\n ! the required accuracy, and not necessary the last midpoints. This keyword\n ! is useful when one want use the computed grid later. This way the grid has\n ! the minimal size. \n ! If /LNFUNC, then YFUNC is supposed to return ln(Y) instead of Y.\n ! If /RESCALE, then YFUNC is rescaled at each iteration so that its maximum \n ! sampled is 1. In the end the results YFINE and PRIMITIVE are affected by \n ! this rescaling. This scaling factor can be recovered through the SCALING\n ! argument. This function is useful when sampling a non normalized \n ! probability distribution.\n !==========================================================================\n\n SUBROUTINE gridadapt1D_simple (xcoarse,xfine,yfine,yfunc,accuracy,Nmax, &\n absacc,interp,integ,primitive,xlog,ylog, &\n reevaluate,minstep,slim,verbose,rescale, &\n lnfunc,adjustxlim,scaling)\n\n USE utilities, ONLY: DP, tinyDP, hugeDP, epsDP, trimlr, pring, isNaN, &\n verbatim\n USE arrays, ONLY: reallocate, ramp, iwhere\n USE integration, ONLY: dPrimitive\n IMPLICIT NONE\n\n REAL(DP), INTENT(IN), DIMENSION(:) :: xcoarse\n REAL(DP), INTENT(OUT), ALLOCATABLE, DIMENSION(:) :: xfine, yfine\n REAL(DP), INTENT(IN) :: accuracy\n INTEGER, INTENT(IN), OPTIONAL :: Nmax\n REAL(DP), INTENT(IN), OPTIONAL :: minstep\n LOGICAL, INTENT(IN), OPTIONAL :: absacc, interp, integ, xlog, ylog\n LOGICAL, INTENT(IN), OPTIONAL :: reevaluate, slim, verbose, rescale, lnfunc\n LOGICAL, DIMENSION(2), INTENT(IN), OPTIONAL :: adjustxlim\n REAL(DP), INTENT(OUT), OPTIONAL :: scaling\n REAL(DP), INTENT(OUT), ALLOCATABLE, DIMENSION(:), OPTIONAL :: primitive\n INTERFACE\n FUNCTION yfunc (x)\n USE utilities, ONLY: DP\n IMPLICIT NONE\n REAL(DP), DIMENSION(:), INTENT(IN) :: x\n REAL(DP), DIMENSION(SIZE(x)) :: yfunc\n END FUNCTION yfunc\n END INTERFACE\n\n INTEGER, PARAMETER :: Nrefmax = 50\n INTEGER, PARAMETER :: Nmax0 = HUGE(KIND(1))\n\n INTEGER :: i, k, N0, N1, Nref, Nmaxi, counter, Nslim, i1, i2, Nlim\n INTEGER, DIMENSION(:), ALLOCATABLE :: imid0, imid1, ind1\n REAL(DP), DIMENSION(2) :: xlim\n REAL(DP), DIMENSION(:), ALLOCATABLE :: x0, x1, f0, f1, xmid, fmid, fmidint\n REAL(DP), DIMENSION(:), ALLOCATABLE :: lnx0, lnx1, lnf0, lnf1\n REAL(DP), DIMENSION(:), ALLOCATABLE :: lnxmid, lnfmid, lnfmidint\n REAL(DP), DIMENSION(:), ALLOCATABLE :: dF0, dF1, prim1, threshint\n REAL(DP), DIMENSION(:), ALLOCATABLE :: deltadF0, deltadF1, relstep\n REAL(DP) :: threshprim, stepmin, scaling0, scaling1, ratscl, maxf\n LOGICAL :: integacc, relacc, xl, yl, evalall, dontkeep\n LOGICAL :: verb, rescl, lnfn\n LOGICAL, DIMENSION(2) :: adjxlim, limOK \n LOGICAL, DIMENSION(:), ALLOCATABLE :: good0, good1, keep0, keep1\n \n !------------------------------------------------------------------------\n\n\n !------------------------------------------------------------------------\n ! I. Preliminary\n !------------------------------------------------------------------------\n\n ! 1) Manage keywords and options\n !-------------------------------\n ! Method\n integacc = .False.\n IF (PRESENT(integ)) integacc = integ\n IF (PRESENT(interp)) integacc = (.NOT. interp)\n\n ! Accuracy\n relacc = .True.\n IF (PRESENT(absacc)) relacc = (.NOT. absacc)\n \n ! Maximum size if required\n IF (PRESENT(Nmax)) THEN ; Nmaxi = Nmax ; ELSE ; Nmaxi = Nmax0 ; END IF\n\n ! Minimum step\n stepmin = epsDP\n IF (PRESENT(minstep)) stepmin = minstep\n\n ! Verbose\n verb = verbatim\n IF (PRESENT(verbose)) verb = verbose\n\n ! Lin/log\n xl = .False.\n IF (PRESENT(xlog)) xl = xlog\n yl = .False.\n IF (PRESENT(ylog)) yl = ylog\n\n ! Function evaluation\n evalall = .False.\n IF (PRESENT(reevaluate)) evalall = reevaluate\n lnfn = .False.\n IF (PRESENT(lnfunc)) lnfn = lnfunc\n rescl = .False.\n IF (PRESENT(rescale)) rescl = rescale\n IF (lnfn) THEN\n scaling0 = 0._DP\n scaling1 = 0._DP\n ELSE\n scaling0 = 1._DP\n scaling1 = 1._DP\n END IF\n\n ! Optimal grid\n dontkeep = .True.\n IF (PRESENT(slim)) dontkeep = slim\n\n ! Refinement of the coarse grid\n adjxlim(:) = [.False.,.False.]\n IF (PRESENT(adjustxlim)) adjxlim(:) = adjustxlim(:)\n limOK(:) = ( .NOT. adjxlim(:) )\n xlim(:) = [ MINVAL(xcoarse(:)), MAXVAL(xcoarse(:)) ]\n\n\n ! 2) Design the coarse grid\n !--------------------------\n ! Initialize the coarse grid\n N0 = SIZE(xcoarse(:))\n ALLOCATE (x0(N0),f0(N0))\n IF (yl .OR. lnfn) ALLOCATE(lnf0(N0))\n x0(:) = xcoarse(:)\n IF (verb) PRINT*, \"Adapatative grid: coarse grid; N = \"//TRIMLR(PRING(N0))\n\n ! Push the limits away, if required\n counter = 0\n coarsegrid: DO \n\n ! Swap\n N1 = N0\n CALL REALLOCATE(x1,N1)\n CALL REALLOCATE(f1,N1)\n IF (yl .OR. lnfn) CALL REALLOCATE(lnf1,N1)\n x1(:) = x0(:)\n scaling1 = scaling0\n \n ! Evalutate the function\n evalinit: IF (.NOT. evalall) THEN\n notallinit: IF (.NOT. lnfn) THEN\n IF (counter == 0) THEN\n f1(:) = YFUNC(x1(:))\n ELSE\n Nlim = COUNT(.NOT. limOK(:))\n IF (Nlim > 0) THEN\n CALL REALLOCATE(ind1,Nlim)\n ind1(:) = PACK( [1,N1], (.NOT. limOK(:)) )\n f1(ind1(:)) = YFUNC(x1(ind1(:))) / scaling1\n END IF\n f1(i1:i2) = f0(i1:i2)\n END IF\n IF (rescl) THEN\n maxf = MAXVAL(f1(:)) * scaling1\n scaling1 = MERGE( maxf, scaling0, &\n ABS(maxf) < hugeDP .AND. ABS(maxf) > tinyDP )\n f1(:) = f1(:) * ( scaling0 / scaling1 )\n END IF\n IF (yl) THEN\n lnf1(:) = LOG(f1(:))\n WHERE (f1(:) < tinyDP) lnf1(:) = -hugeDP\n END IF\n ELSE\n IF (counter == 0) THEN\n lnf1(:) = YFUNC(x1(:))\n ELSE\n Nlim = COUNT(.NOT. limOK(:))\n IF (Nlim > 0) THEN\n CALL REALLOCATE(ind1,Nlim)\n ind1(:) = PACK( [1,N1], (.NOT. limOK(:)) )\n lnf1(ind1(:)) = YFUNC(x1(ind1(:))) - scaling1\n END IF\n lnf1(i1:i2) = lnf0(i1:i2) \n END IF\n IF (rescl) THEN\n maxf = MAXVAL(lnf1(:)) + scaling0\n scaling1 = MERGE( maxf, scaling0, ABS(maxf) < hugeDP )\n lnf1(:) = lnf1(:) + ( scaling0 - scaling1 )\n END IF\n f1(:) = EXP(lnf1(:))\n END IF notallinit\n ELSE\n allinit: IF (.NOT. lnfn) THEN\n f1(:) = YFUNC(x1(:))\n IF (rescl) THEN\n maxf = MAXVAL(f1(:))\n scaling1 = MERGE( maxf, 1._DP, &\n ABS(maxf) < hugeDP .AND. ABS(maxf) > tinyDP )\n f1(:) = f1(:) / scaling1\n END IF\n IF (yl) THEN\n lnf1(:) = LOG(f1(:))\n WHERE (f1(:) < tinyDP) lnf1(:) = -hugeDP\n END IF\n ELSE\n lnf1(:) = YFUNC(x1(:))\n IF (rescl) THEN\n maxf = MAXVAL(lnf1(:))\n scaling1 = MERGE( maxf, 0._DP, ABS(maxf) < hugeDP )\n lnf1(:) = lnf1(:) - scaling1\n END IF\n f1(:) = EXP(lnf1(:))\n END IF allinit\n END IF evalinit\n\n ! Iterate until we find zeros on each side. This method implicitly assumes\n ! that some non-zero values of the function are included in the original\n ! interval. The iteration looks for the edges (below machine precision).\n ! This method is not appropriate if the function has several narrow peaks \n ! with zeros between them. \n counter = counter + 1\n adjustlim: IF ( ALL(limOK(:)) .OR. counter == Nrefmax ) THEN\n EXIT\n ELSE\n IF (.NOT. limOK(1)) THEN\n IF (f1(1) > tinyDP .AND. f1(2) /= f1(1)) THEN\n xlim(1) = MERGE( x1(1)**2/x1(N1), 2._DP*x1(1)-x1(N1), xl )\n ELSE\n xlim(1) = x1(1)\n limOK(1) = .True.\n END IF\n END IF\n IF (.NOT. limOK(2)) THEN\n IF (f1(N1) > tinyDP .AND. f1(N1-1) /= f1(N1)) THEN\n xlim(2) = MERGE( x1(N1)**2/x1(1), 2._DP*x1(N1)-x1(1), xl )\n ELSE\n xlim(2) = x1(N1)\n limOK(2) = .True.\n END IF\n END IF\n N0 = N1 + COUNT(.NOT. limOK(:))\n IF (verb .AND. ANY(.NOT. limOK(:))) &\n PRINT*, \"Adapatative grid: new limits \"//TRIMLR(PRING(counter)) &\n //\"; N=\"//TRIMLR(PRING(N0))\n CALL REALLOCATE(x0,N0) \n CALL REALLOCATE(f0,N0) \n IF (yl .OR. lnfn) CALL REALLOCATE(lnf0,N0) \n i1 = MERGE( 1, 2, limOK(1) )\n i2 = MERGE( N0, N0-1, limOK(2) )\n x0(i1:i2) = x1(:)\n f0(i1:i2) = f1(:)\n scaling0 = scaling1\n IF (yl .OR. lnfn) lnf0(i1:i2) = lnf1(:)\n IF (.NOT. limOK(1)) x0(1) = xlim(1)\n IF (.NOT. limOK(2)) x0(N0) = xlim(2)\n END IF adjustlim\n \n END DO coarsegrid\n\n ! Primitive on the coarse grid\n IF (xl) THEN\n ALLOCATE (lnx1(N1))\n lnx1(:) = LOG(x1(:))\n END IF\n IF (integacc) THEN\n ALLOCATE (dF1(N1))\n IF (.NOT. xl .AND. yl) THEN \n dF1(:) = DPRIMITIVE(x1(:),f1(:),XLOG=xl,YLOG=yl,LNF=lnf1(:))\n ELSE IF (xl .AND. yl) THEN \n dF1(:) = DPRIMITIVE(x1(:),f1(:),XLOG=xl,YLOG=yl, &\n LNX=lnx1(:),LNF=lnf1(:))\n ELSE\n dF1(:) = DPRIMITIVE(x1(:),f1(:),XLOG=xl,YLOG=yl)\n END IF\n ALLOCATE(deltadF1(N1-1))\n deltadF1(:) = SUM(dF1(:)) ! large value for initialization\n END IF\n Nref = N1 - 1\n ALLOCATE (good1(N1-1))\n good1(:) = .False.\n IF (dontkeep) THEN\n ALLOCATE (keep1(N1))\n keep1(:) = .True.\n END IF\n\n \n !------------------------------------------------------------------------\n ! II. Refining the grid\n !------------------------------------------------------------------------\n\n counter = 0\n refinement: DO\n \n\n ! 1) Preamble\n !------------\n ! Update the various arrays\n N0 = N1\n CALL REALLOCATE(x0,N0)\n CALL REALLOCATE(f0,N0)\n CALL REALLOCATE(good0,N0-1)\n IF (dontkeep) CALL REALLOCATE(keep0,N0)\n x0(:) = x1(:)\n f0(:) = f1(:)\n IF (xl) THEN\n CALL REALLOCATE(lnx0,N0)\n lnx0(:) = lnx1(:)\n END IF\n IF (yl .OR. lnfn) THEN\n CALL REALLOCATE(lnf0,N0)\n lnf0(:) = lnf1(:)\n END IF\n good0(:) = good1(:)\n IF (dontkeep) keep0(:) = keep1(:)\n IF (integacc) THEN \n CALL REALLOCATE(dF0,N0)\n dF0(:) = dF1(:)\n CALL REALLOCATE(deltadF0,N0-1)\n deltadF0(:) = deltadF1(:)\n END IF\n IF (rescl) scaling0 = scaling1\n\n ! Indices where to refine \n N1 = N0 + Nref\n IF (verb) &\n PRINT*, \"Adapatative grid: iteration \"//TRIMLR(PRING(counter+1)) &\n //\"; N = \"//TRIMLR(PRING(N1))\n CALL REALLOCATE(imid0,Nref) ! position of mid-points on grid 0 (x0 below)\n CALL REALLOCATE(imid1,Nref) ! position of mid-points on grid 1\n CALL REALLOCATE(ind1,N0) ! position of grid 0 points on grid 1\n imid0(:) = PACK([(i,i=1,N0-1)],.NOT. good0(:))\n imid1(:) = imid0(:) + [(i,i=1,Nref)]\n k = 0\n ind1(1) = 1\n DO i=2,N0\n IF (.NOT. good0(i-1)) k = k + 1\n ind1(i) = i + k\n END DO\n\n \n ! 2) Refine the grid\n !-------------------\n ! Add mid-points where needed\n CALL REALLOCATE(xmid,Nref)\n IF (xl) THEN\n CALL REALLOCATE(lnxmid,Nref)\n lnxmid(:) = 0.5_DP * ( lnx0(imid0(:)+1) + lnx0(imid0(:)) )\n xmid(:) = EXP(lnxmid(:))\n ELSE \n xmid(:) = 0.5_DP * ( x0(imid0(:)+1) + x0(imid0(:)) ) \n END IF\n\n ! Update the refinement of the grid\n CALL REALLOCATE(x1,N1)\n x1(ind1(:)) = x0(:)\n x1(imid1(:)) = xmid(:)\n IF (xl) THEN\n CALL REALLOCATE(lnx1,N1)\n lnx1(ind1(:)) = lnx0(:)\n lnx1(imid1(:)) = lnxmid(:)\n END IF\n\n ! Evaluate function on the new grid\n evalfunc: IF (.NOT. evalall) THEN\n CALL REALLOCATE(fmid,Nref)\n mideval: IF (.NOT. lnfn) THEN\n fmid(:) = YFUNC(xmid(:))\n midrescl: IF (rescl) THEN\n maxf = MAXVAL(fmid(:))\n scaling1 = MERGE( maxf, scaling0, &\n ( ABS(maxf) < hugeDP .AND. ABS(maxf) > tinyDP ) )\n IF (scaling1 >= scaling0) THEN \n ratscl = scaling0 / scaling1\n f0(:) = f0(:) * ratscl\n IF (yl) lnf0(:) = lnf0(:) + LOG(ratscl)\n IF (integacc) THEN\n dF0(:) = dF0(:) * ratscl\n deltadF0(:) = deltadF0(:) * ratscl\n END IF\n ELSE\n scaling1 = scaling0\n END IF\n fmid(:) = fmid(:) / scaling1\n END IF midrescl\n IF (yl) THEN\n CALL REALLOCATE(lnfmid,Nref)\n lnfmid(:) = LOG(fmid(:))\n WHERE (fmid(:) < tinyDP) lnfmid(:) = -hugeDP\n END IF\n ELSE\n CALL REALLOCATE(lnfmid,Nref)\n lnfmid(:) = YFUNC(xmid(:))\n midlnrescl: IF (rescl) THEN\n maxf = MAXVAL(lnfmid(:))\n scaling1 = MERGE( maxf, scaling0, ABS(maxf) < hugeDP )\n IF (scaling1 >= scaling0) THEN\n ratscl = EXP( scaling0 - scaling1 )\n f0(:) = f0(:) * ratscl\n lnf0(:) = lnf0(:) + ( scaling0 - scaling1 )\n IF (integacc) THEN\n dF0(:) = dF0(:) * ratscl\n deltadF0(:) = deltadF0(:) * ratscl \n END IF\n ELSE\n scaling1 = scaling0\n END IF\n END IF midlnrescl\n lnfmid(:) = lnfmid(:) - scaling1\n fmid(:) = EXP(lnfmid(:))\n END IF mideval\n CALL REALLOCATE(f1,N1)\n f1(ind1(:)) = f0(:)\n f1(imid1(:)) = fmid(:)\n IF (yl .OR. lnfn) THEN\n CALL REALLOCATE(lnf1,N1)\n lnf1(ind1(:)) = lnf0(:)\n lnf1(imid1(:)) = lnfmid(:)\n END IF\n ELSE\n CALL REALLOCATE(f1,N1)\n CALL REALLOCATE(fmid,Nref)\n alleval: IF (.NOT. lnfn) THEN\n f1(:) = YFUNC(x1(:))\n allrescl: IF (rescl) THEN\n maxf = MAXVAL(f1(:))\n scaling1 = MERGE( maxf, 1._DP, &\n ( ABS(maxf) < hugeDP .AND. ABS(maxf) > tinyDP ) )\n ratscl = scaling0 / scaling1\n f0(:) = f0(:) * ratscl\n IF (yl) lnf0(:) = lnf0(:) + LOG(ratscl)\n IF (integacc) THEN\n dF0(:) = dF0(:) * ratscl\n deltadF0(:) = deltadF0(:) * ratscl\n END IF\n END IF allrescl\n fmid(:) = f1(imid1(:))\n IF (yl) THEN\n CALL REALLOCATE(lnf1,N1)\n lnf1(:) = LOG(f1(:))\n WHERE (f1(:) < tinyDP) lnf1(:) = -hugeDP\n CALL REALLOCATE(lnfmid,Nref)\n lnfmid(:) = lnf1(imid1(:))\n END IF\n ELSE\n CALL REALLOCATE(lnf1,N1)\n lnf1(:) = YFUNC(x1(:))\n alllnrescl: IF (rescl) THEN\n maxf = MAXVAL(lnf1(:))\n scaling1 = MERGE( maxf, 0._DP, ABS(maxf) < hugeDP )\n ratscl = EXP( scaling0 - scaling1 )\n f0(:) = f0(:) * ratscl\n lnf0(:) = lnf0(:) + ( scaling0 - scaling1 )\n IF (integacc) THEN\n dF0(:) = dF0(:) * ratscl\n deltadF0(:) = deltadF0(:) * ratscl \n END IF\n END IF alllnrescl\n CALL REALLOCATE(lnfmid,Nref)\n lnfmid(:) = lnf1(imid1(:))\n f1(:) = EXP(lnf1(:))\n fmid(:) = f1(imid1(:))\n END IF alleval\n END IF evalfunc\n \n ! Update the mask \n CALL REALLOCATE(good1,N1-1)\n good1(ind1(1:N0-1)) = good0(:)\n\n\n ! 3) Interpolation method\n !------------------------\n interpol: IF (.NOT. integacc) THEN\n\n ! Interpolation at mid-point\n CALL REALLOCATE(fmidint,Nref)\n IF (yl) THEN\n CALL REALLOCATE(lnfmidint,Nref)\n lnfmidint(:) = lnf0(imid0(:)) &\n + 0.5_DP * ( lnf0(imid0(:)+1) - lnf0(imid0(:)) )\n fmidint(:) = EXP(lnfmidint(:))\n ELSE\n fmidint(:) = f0(imid0(:)) + 0.5_DP * ( f0(imid0(:)+1) - f0(imid0(:)) )\n END IF\n\n ! Update the mask\n CALL REALLOCATE(threshint,Nref)\n IF (relacc) THEN\n WHERE( ABS(fmid(:)) > tinyDP/accuracy )\n threshint(:) = ABS(fmid(:)) * accuracy\n ELSEWHERE ( ABS(fmidint(:)) > tinyDP/accuracy )\n threshint(:) = ABS(fmidint(:)) * accuracy\n ELSEWHERE\n threshint(:) = ABS(fmid(:)-fmidint(:)) * 2._DP\n END WHERE\n ELSE\n threshint(:) = accuracy\n END IF\n FORALL (i=1:Nref) &\n good1(imid1(i)-1:imid1(i)) &\n = ( ABS(fmid(i) - fmidint(i)) <= threshint(i) .OR. isNaN(fmid(i)) &\n .OR. threshint(i) < tinyDP )\n IF (yl) THEN\n FORALL (i=1:Nref,fmid(i) < tinyDP) good1(imid1(i)-1:imid1(i)) = .True.\n END IF\n END IF interpol\n\n\n ! 4) Integration method\n !----------------------\n ! Compute the primitive\n integr: IF (integacc) THEN\n CALL REALLOCATE(dF1,N1)\n evalprim: IF (.NOT. evalall) THEN\n\n dF1(ind1(:)) = dF0(:)\n linlog: IF (.NOT. xl .AND. yl) THEN \n FORALL (i=1:Nref) &\n dF1(imid1(i):imid1(i)+1) = &\n DPRIM( [x0(imid0(i)),xmid(i),x0(imid0(i)+1)], &\n [f0(imid0(i)),fmid(i),f0(imid0(i)+1)], &\n XLOG=xl,YLOG=(lnf0(imid0(i))/=lnf0(imid0(i)+1)), &\n LNF=[lnf0(imid0(i)),lnfmid(i),lnf0(imid0(i)+1)] )\n ELSE IF (xl .AND. yl) THEN \n FORALL (i=1:Nref) &\n dF1(imid1(i):imid1(i)+1) = &\n DPRIM( [x0(imid0(i)),xmid(i),x0(imid0(i)+1)], &\n [f0(imid0(i)),fmid(i),f0(imid0(i)+1)], XLOG=xl, YLOG=yl,&\n LNX=[lnx0(imid0(i)),lnxmid(i),lnx0(imid0(i)+1)], &\n LNF=[lnf0(imid0(i)),lnfmid(i),lnf0(imid0(i)+1)] )\n ELSE\n FORALL (i=1:Nref) &\n dF1(imid1(i):imid1(i)+1) = &\n DPRIM( [x0(imid0(i)),xmid(i),x0(imid0(i)+1)], &\n [f0(imid0(i)),fmid(i),f0(imid0(i)+1)], XLOG=xl, YLOG=yl )\n END IF linlog\n\n ELSE\n\n linlog2: IF (.NOT. xl .AND. yl) THEN \n dF1(:) = DPRIMITIVE(x1(:),f1(:),XLOG=xl,YLOG=yl,LNF=lnf1(:))\n ELSE IF (xl .AND. yl) THEN \n dF1(:) = DPRIMITIVE(x1(:),f1(:),XLOG=xl,YLOG=yl, &\n LNX=lnx1(:),LNF=lnf1(:))\n ELSE\n dF1(:) = DPRIMITIVE(x1(:),f1(:),XLOG=xl,YLOG=yl)\n END IF linlog2\n \n END IF evalprim\n WHERE (ISNAN(dF1(:))) dF1(:) = 0._DP\n IF (yl) &\n WHERE (dF1(:) <= 0._DP) dF1(:) = 0._DP\n \n ! Decide where to refine\n CALL REALLOCATE(deltadF1,N1-1)\n deltadF1(ind1(1:N0-1)) = deltadF0(:)\n FORALL (i=1:Nref) &\n deltadF1(imid1(i)-1:imid1(i)) = ABS( SUM(dF1(imid1(i):imid1(i)+1)) &\n - dF0(imid0(i)+1) )\n threshprim = MERGE(accuracy * SUM(dF1(:)) / SQRT(REAL(N1,DP)), &\n accuracy,relacc)\n good1(:) = ( deltadF1(:) <= threshprim )\n \n END IF integr\n\n\n ! 5) Adjustments and exit conditions\n !-----------------------------------\n ! Case of narrow support function\n IF (yl .OR. lnfn) THEN\n IF (COUNT(f1(:) > 0._DP) <= 1) good1(:) = .False.\n END IF\n\n ! Slim mode\n IF (dontkeep) THEN\n CALL REALLOCATE(keep1,N1)\n keep1(ind1(:)) = keep0(:)\n keep1(imid1(:)) = (.NOT. good1(imid1(:)) )\n END IF\n\n ! Enforce minimum step\n CALL REALLOCATE (relstep,Nref)\n relstep(:) = (x0(imid0(:)+1)-x0(imid0(:))) &\n / MERGE(x0(imid0(:)),x0(imid0(:)+1),x0(imid0(:)) /= 0._DP)\n FORALL (i=1:Nref,ABS(relstep(i)) <= stepmin) &\n good1(imid1(i)-1:imid1(i)) = .True.\n\n ! Exit when no more refinement is needed\n Nref = COUNT(.NOT. good1)\n counter = counter + 1\n IF (counter == Nrefmax .OR. Nref == 0 .OR. N1 >= Nmaxi) EXIT\n\n END DO refinement\n\n\n !------------------------------------------------------------------------\n ! III. Final grid\n !------------------------------------------------------------------------\n\n ! Slim mode\n nokeep: IF (.NOT. dontkeep) THEN\n ALLOCATE (xfine(N1),yfine(N1))\n xfine(:) = x1(:)\n yfine(:) = f1(:)\n ELSE\n Nslim = COUNT(keep1(:))\n ALLOCATE (xfine(Nslim),yfine(Nslim))\n xfine(:) = PACK(x1(:),keep1(:))\n yfine(:) = PACK(f1(:),keep1(:))\n END IF nokeep\n \n ! Primitive\n doprim: IF (integacc .AND. PRESENT(primitive)) THEN\n IF (.NOT. dontkeep) THEN\n ALLOCATE (primitive(N1))\n primitive(1) = 0._DP\n DO i=2,N1 ; primitive(i) = dF1(i) + primitive(i-1) ; END DO\n ELSE\n ALLOCATE (prim1(N1),primitive(Nslim))\n prim1(1) = 0._DP\n DO i=2,N1 ; prim1(i) = dF1(i) + prim1(i-1) ; END DO\n primitive(:) = PACK(prim1(:),keep1(:))\n DEALLOCATE (prim1)\n END IF\n END IF doprim\n\n ! Scaling\n IF (rescl .AND. PRESENT (scaling)) &\n scaling = MERGE(EXP(scaling1),scaling1,lnfn)\n\n ! Clean memory\n IF (verb) PRINT*, \"Adaptative grid: packing and tagging...\"\n DEALLOCATE(x0,x1,f0,f1,ind1,good0,good1,imid0,imid1,xmid,fmid,relstep)\n IF (yl .OR. lnfn) DEALLOCATE(lnf0,lnf1,lnfmid)\n IF (xl) DEALLOCATE(lnx0,lnx1,lnxmid)\n IF (integacc) DEALLOCATE(dF0,dF1,deltadF0,deltadF1)\n IF (dontkeep) DEALLOCATE(keep0,keep1)\n IF (.NOT. integacc) DEALLOCATE(fmidint)\n IF (.NOT. integacc .AND. yl) DEALLOCATE(lnfmidint)\n IF (.NOT. integacc) DEALLOCATE(threshint)\n\n !------------------------------------------------------------------------\n\n END SUBROUTINE gridadapt1D_simple\n\n\n !==========================================================================\n ! CALL GRIDADAPT1D_ZGRID (xcoarse[N0],zgrid[Nz],xfine[N],yfine[N,Nz],yfunc, &\n ! accuracy,ABSACC=T/F,INTERP=T/F,INTEG=T/F, &\n ! REEVALUATE=T/F,primitive[N],slim)\n !\n ! Returns an adaptative grid xfine[N], and function values yfine[N] of \n ! function, YFUNC, from an initial grid xcoarse[N0] (between x0min and x0max).\n ! The grid adapted so that the accuracy on the linear interpretation between \n ! two values is better than ACCURACY. The difference between the _SIMPLE and\n ! _ZGRID procedures, is that the interpolation of the data is simple in the \n ! first case, and is done at one value of X, but several value of an \n ! additional parameter Z, for _ZGRID. The latter case, can be the sampling\n ! in wavelength (X) of a black body spectrum, that has to be accurate for\n ! all temperatures (Z).\n ! IF ABSACC is true, then it is an absolute accuracy (default is relative).\n ! If INTEG is true, the accuracy is on the integral and not on the \n ! interpolation.\n ! IF keyword REEVALUATE is set, then the function is evaluated on the entire\n ! grid at each iteration, while it is evaluated only at mid-points if it is \n ! not set. REEVALUATE is used when the function needs the entire grid to be \n ! evaluated properly (normalization, etc.).\n ! IF keyword SLIM is set, then we keep only the points needed to achieve\n ! the required accuracy, and not necessary the last midpoints. This keyword\n ! is useful when one want use the computed grid later. This way the grid has\n ! the minimal size. \n !==========================================================================\n\n SUBROUTINE gridadapt1D_zgrid (xcoarse,zgrid,xfine,yfine,yfunc,accuracy, &\n absacc,interp,integ,primitive,xlog,ylog, &\n reevaluate,minstep,slim,verbose)\n\n USE utilities, ONLY: DP, tinyDP, hugeDP, epsDP, trimlr, pring, isNaN, &\n verbatim\n USE arrays, ONLY: reallocate\n USE integration, ONLY: dPrimitive\n IMPLICIT NONE\n\n REAL(DP), INTENT(IN), DIMENSION(:) :: xcoarse, zgrid\n REAL(DP), INTENT(OUT), ALLOCATABLE, DIMENSION(:) :: xfine\n REAL(DP), INTENT(OUT), ALLOCATABLE, DIMENSION(:,:) :: yfine\n REAL(DP), INTENT(IN) :: accuracy\n REAL(DP), INTENT(IN), OPTIONAL :: minstep\n LOGICAL, INTENT(IN), OPTIONAL :: absacc, interp, integ, xlog, ylog\n LOGICAL, INTENT(IN), OPTIONAL :: reevaluate, slim, verbose\n REAL(DP), INTENT(OUT), ALLOCATABLE, DIMENSION(:,:), OPTIONAL :: primitive\n INTERFACE\n FUNCTION yfunc (x,z)\n USE utilities, ONLY: DP\n IMPLICIT NONE\n REAL(DP), DIMENSION(:), INTENT(IN) :: x, z\n REAL(DP), DIMENSION(SIZE(x),SIZE(z)) :: yfunc\n END FUNCTION yfunc\n END INTERFACE\n\n INTEGER, PARAMETER :: Nrefmax = 50\n\n INTEGER :: i, k, iz, N0, N1, Nz, Nref, counter, Nslim\n INTEGER, DIMENSION(:), ALLOCATABLE :: imid0, imid1, ind1\n REAL(DP), DIMENSION(SIZE(zgrid)) :: threshprim\n REAL(DP), DIMENSION(:), ALLOCATABLE :: x0, x1, xmid, lnx0, lnx1, lnxmid\n REAL(DP), DIMENSION(:), ALLOCATABLE :: relstep\n REAL(DP), DIMENSION(:,:), ALLOCATABLE :: lnf0, lnf1, f0, f1, fmid, fmidint\n REAL(DP), DIMENSION(:,:), ALLOCATABLE :: lnfmid, lnfmidint, threshint\n REAL(DP), DIMENSION(:,:), ALLOCATABLE :: dF0, dF1, prim1\n REAL(DP), DIMENSION(:,:), ALLOCATABLE :: deltadF0, deltadF1\n REAL(DP) :: stepmin\n LOGICAL :: integacc, relacc, xl, yl, evalall, dontkeep, verb\n LOGICAL, DIMENSION(:), ALLOCATABLE :: good0, good1, keep0, keep1\n \n !------------------------------------------------------------------------\n\n ! 1. Preliminary\n !---------------\n ! Method\n integacc = .False.\n IF (PRESENT(integ)) integacc = integ\n IF (PRESENT(interp)) integacc = (.NOT. interp)\n\n ! Accuracy\n relacc = .True.\n IF (PRESENT(absacc)) relacc = (.NOT. absacc)\n\n ! Minimum step\n stepmin = epsDP\n IF (PRESENT(minstep)) stepmin = minstep\n\n ! Verbose\n verb = verbatim\n IF (PRESENT(verbose)) verb = verbose\n\n ! Lin/log\n xl = .False.\n IF (PRESENT(xlog)) xl = xlog\n yl = .False.\n IF (PRESENT(ylog)) yl = ylog\n\n ! Function evaluation\n evalall = .False.\n IF (PRESENT(reevaluate)) evalall = reevaluate\n\n ! Optimal grid\n dontkeep = .True.\n IF (PRESENT(slim)) dontkeep = slim\n\n ! Coarse grid\n N1 = SIZE(xcoarse)\n IF (verb) PRINT*, \"Adapatative grid: coarse grid; N = \"//TRIMLR(PRING(N1))\n Nz = SIZE(zgrid)\n ALLOCATE (x1(N1),f1(N1,Nz))\n x1(:) = xcoarse(:)\n f1(:,:) = YFUNC(x1(:),zgrid(:))\n IF (xl) THEN\n ALLOCATE (lnx1(N1))\n lnx1(:) = LOG(x1(:))\n END IF\n IF (yl) THEN\n ALLOCATE (lnf1(N1,Nz))\n lnf1(:,:) = LOG(f1(:,:))\n WHERE (f1(:,:) < tinyDP) lnf1(:,:) = -hugeDP\n END IF\n IF (integacc) THEN\n ALLOCATE (dF1(N1,Nz))\n IF (.NOT. xl .AND. yl) THEN \n FORALL(iz=1:Nz) &\n dF1(:,iz) = dPRIMITIVE(x1,f1(:,iz),XLOG=xl,YLOG=yl,LNF=lnf1(:,iz))\n ELSE IF (xl .AND. yl) THEN \n FORALL(iz=1:Nz) &\n dF1(:,iz) = DPRIMITIVE(x1(:),f1(:,iz),XLOG=xl,YLOG=yl, &\n LNX=lnx1(:),LNF=lnf1(:,iz))\n ELSE\n FORALL(iz=1:Nz) &\n dF1(:,iz) = DPRIMITIVE(x1(:),f1(:,iz),XLOG=xl,YLOG=yl)\n END IF\n ALLOCATE(deltadF1(N1-1,Nz))\n FORALL (iz=1:Nz) deltadF1(:,iz) = SUM(dF1(:,iz)) ! large value for start\n END IF\n Nref = N1 - 1\n ALLOCATE (good1(N1-1))\n good1(:) = .False.\n IF (dontkeep) THEN\n ALLOCATE (keep1(N1))\n keep1(:) = .True.\n END IF\n\n \n ! 2. Refining the grid\n !---------------------\n counter = 0\n refinement: DO\n\n ! Preamble\n N0 = N1\n CALL REALLOCATE(x0,N0)\n CALL REALLOCATE(f0,N0,Nz)\n CALL REALLOCATE(good0,N0-1)\n IF (dontkeep) CALL REALLOCATE(keep0,N0)\n x0(:) = x1(:)\n f0(:,:) = f1(:,:)\n IF (xl) THEN\n CALL REALLOCATE(lnx0,N0)\n lnx0(:) = lnx1(:)\n END IF\n IF (yl) THEN\n CALL REALLOCATE(lnf0,N0,Nz)\n lnf0(:,:) = lnf1(:,:)\n END IF\n good0(:) = good1(:)\n IF (dontkeep) keep0(:) = keep1(:)\n IF (integacc) THEN \n CALL REALLOCATE(dF0,N0,Nz)\n dF0(:,:) = dF1(:,:)\n CALL REALLOCATE(deltadF0,N0-1,Nz)\n deltadF0(:,:) = deltadF1(:,:)\n END IF\n\n ! Indices where to refine \n N1 = N0 + Nref\n IF (verb) &\n PRINT*, \"Adapatative grid: iteration \"//TRIMLR(PRING(counter+1)) &\n //\"; N = \"//TRIMLR(PRING(N1))\n CALL REALLOCATE(imid0,Nref) ! position of mid-points on grid 0 (x0 below)\n CALL REALLOCATE(imid1,Nref) ! position of mid-points on grid 1\n CALL REALLOCATE(ind1,N0) ! position of grid 0 points on grid 1\n imid0(:) = PACK([(i,i=1,N0-1)],.NOT. good0)\n imid1(:) = imid0(:) + [(i,i=1,Nref)]\n k = 0\n ind1(1) = 1\n DO i=2,N0\n IF (.NOT. good0(i-1)) k = k + 1\n ind1(i) = i + k\n END DO\n\n ! Add mid-points where needed\n CALL REALLOCATE(xmid,Nref)\n IF (xl) THEN\n CALL REALLOCATE(lnxmid,Nref)\n lnxmid(:) = 0.5_DP * ( lnx0(imid0(:)+1) + lnx0(imid0(:)) )\n xmid(:) = EXP(lnxmid(:))\n ELSE \n xmid(:) = 0.5_DP * ( x0(imid0(:)+1) + x0(imid0(:)) ) \n END IF\n\n ! Update the refinement\n CALL REALLOCATE(x1,N1)\n x1(ind1(:)) = x0(:)\n x1(imid1(:)) = xmid(:)\n IF (xl) THEN\n CALL REALLOCATE(lnx1,N1)\n lnx1(ind1(:)) = lnx0(:)\n lnx1(imid1(:)) = lnxmid(:)\n END IF\n\n ! Evaluate the function on the new grid\n evalfunc: IF (.NOT. evalall) THEN\n CALL REALLOCATE(fmid,Nref,Nz)\n fmid(:,:) = YFUNC(xmid(:),zgrid(:))\n IF (yl) THEN\n CALL REALLOCATE(lnfmid,Nref,Nz)\n lnfmid(:,:) = LOG(fmid(:,:))\n WHERE (fmid(:,:) < tinyDP) lnfmid(:,:) = -hugeDP\n END IF\n CALL REALLOCATE(f1,N1,Nz)\n f1(ind1(:),:) = f0(:,:)\n f1(imid1(:),:) = fmid(:,:)\n IF (yl) THEN\n CALL REALLOCATE(lnf1,N1,Nz)\n lnf1(ind1(:),:) = lnf0(:,:)\n lnf1(imid1(:),:) = lnfmid(:,:)\n END IF\n ELSE \n CALL REALLOCATE(f1,N1,Nz)\n CALL REALLOCATE(fmid,Nref,Nz)\n f1(:,:) = YFUNC(x1(:),zgrid(:))\n fmid(:,:) = f1(imid1(:),:)\n IF (yl) THEN\n CALL REALLOCATE(lnf1,N1,Nz)\n lnf1(:,:) = LOG(f1(:,:))\n WHERE (f1(:,:) < tinyDP) lnf1(:,:) = -hugeDP\n CALL REALLOCATE(lnfmid,Nref,Nz)\n lnfmid(:,:) = lnf1(imid1(:),:)\n END IF\n END IF evalfunc\n\n ! Interpolation at mid-point\n CALL REALLOCATE(fmidint,Nref,Nz)\n IF (yl) THEN\n CALL REALLOCATE(lnfmidint,Nref,Nz)\n lnfmidint(:,:) = lnf0(imid0(:),:) &\n + 0.5_DP * ( lnf0(imid0(:)+1,:) - lnf0(imid0(:),:) )\n fmidint(:,:) = EXP(lnfmidint(:,:))\n ELSE\n fmidint(:,:) = f0(imid0(:),:) &\n + 0.5_DP * ( f0(imid0(:)+1,:) - f0(imid0(:),:) )\n END IF\n\n ! Update the mask\n CALL REALLOCATE(good1,N1-1)\n good1(ind1(1:N0-1)) = good0(:)\n interpol: IF (.NOT. integacc) THEN \n CALL REALLOCATE(threshint,Nref,Nz)\n IF (relacc) THEN\n FORALL(iz=1:Nz)\n WHERE( ABS(fmid(:,iz)) > tinyDP/accuracy )\n threshint(:,iz) = ABS(fmid(:,iz)) * accuracy\n ELSEWHERE ( ABS(fmidint(:,iz)) > tinyDP/accuracy )\n threshint(:,iz) = ABS(fmidint(:,iz)) * accuracy\n ELSEWHERE\n threshint(:,iz) = ABS(fmid(:,iz)-fmidint(:,iz)) * 2._DP\n END WHERE\n END FORALL\n ELSE\n threshint(:,:) = accuracy\n END IF\n FORALL (i=1:Nref) &\n good1(imid1(i)-1:imid1(i)) &\n = ALL( ABS(fmid(i,:) - fmidint(i,:)) <= threshint(i,:) &\n .OR. isNaN(fmid(i,:)) .OR. threshint(i,:) < tinyDP)\n IF (yl) THEN\n FORALL (i=1:Nref,ALL(fmid(i,:) < tinyDP)) &\n good1(imid1(i)-1:imid1(i)) = .True.\n END IF\n END IF interpol\n\n ! Compute the primitive\n integr: IF (integacc) THEN\n CALL REALLOCATE(dF1,N1,Nz)\n evalprim: IF (.NOT. evalall) THEN\n\n dF1(ind1(:),:) = dF0(:,:)\n linlog: IF (.NOT. xl .AND. yl) THEN \n FORALL (i=1:Nref,iz=1:Nz) &\n dF1(imid1(i):imid1(i)+1,iz) = &\n DPRIM( [x0(imid0(i)),xmid(i),x0(imid0(i)+1)], &\n [f0(imid0(i),iz),fmid(i,iz),f0(imid0(i)+1,iz)], &\n XLOG=xl, YLOG=yl, &\n LNF=[lnf0(imid0(i),iz),lnfmid(i,iz),lnf0(imid0(i)+1,iz)] )\n ELSE IF (xl .AND. yl) THEN \n FORALL (i=1:Nref,iz=1:Nz) &\n dF1(imid1(i):imid1(i)+1,iz) = &\n DPRIM( [x0(imid0(i)),xmid(i),x0(imid0(i)+1)], &\n [f0(imid0(i),iz),fmid(i,iz),f0(imid0(i)+1,iz)], &\n XLOG=xl, YLOG=yl, &\n LNX=[lnx0(imid0(i)),lnxmid(i),lnx0(imid0(i)+1)], &\n LNF=[lnf0(imid0(i),iz),lnfmid(i,iz),lnf0(imid0(i)+1,iz)] )\n ELSE\n FORALL (i=1:Nref,iz=1:Nz) &\n dF1(imid1(i):imid1(i)+1,iz) = &\n DPRIM( [x0(imid0(i)),xmid(i),x0(imid0(i)+1)], &\n [f0(imid0(i),iz),fmid(i,iz),f0(imid0(i)+1,iz)], &\n XLOG=xl, YLOG=yl )\n END IF linlog\n\n ELSE\n\n linlog2: IF (.NOT. xl .AND. yl) THEN \n FORALL (iz=1:Nz) &\n dF1(:,iz) = DPRIMITIVE(x1(:),f1(:,iz),XLOG=xl,YLOG=yl, &\n LNF=lnf1(:,iz))\n ELSE IF (xl .AND. yl) THEN \n FORALL (iz=1:Nz) &\n dF1(:,iz) = DPRIMITIVE(x1(:),f1(:,iz),XLOG=xl,YLOG=yl, &\n LNX=lnx1(:),LNF=lnf1(:,iz))\n ELSE\n FORALL (iz=1:Nz) &\n dF1(:,iz) = DPRIMITIVE(x1(:),f1(:,iz),XLOG=xl,YLOG=yl)\n END IF linlog2\n\n END IF evalprim\n WHERE(ISNAN(dF1(:,:))) dF1(:,:) = 0._DP\n\n ! Decide where to refine\n CALL REALLOCATE(deltadF1,N1-1,Nz)\n deltadF1(ind1(1:N0-1),:) = deltadF0(:,:)\n FORALL (i=1:Nref,iz=1:Nz) &\n deltadF1(imid1(i)-1:imid1(i),iz) &\n = ABS( SUM(dF1(imid1(i):imid1(i)+1,iz)) - dF0(imid0(i)+1,iz) )\n threshprim(:) = MERGE(accuracy*SUM(ABS(dF1(:,:)),1)/SQRT(REAL(N1,DP)), &\n accuracy,relacc)\n FORALL (i=1:N1-1) good1(i) = ALL( deltadF1(i,:) <= threshprim(:) )\n IF (yl) THEN\n FORALL (i=1:Nref,ALL(fmid(i,:) < tinyDP)) &\n good1(imid1(i)-1:imid1(i)) = .True.\n END IF\n\n END IF integr\n\n ! Slim mode\n IF (dontkeep) THEN\n CALL REALLOCATE(keep1,N1)\n keep1(ind1(:)) = keep0(:)\n keep1(imid1(:)) = (.NOT. good1(imid1(:)) )\n END IF\n\n ! Enforce minimum step\n CALL REALLOCATE (relstep,Nref)\n relstep(:) = (x0(imid0(:)+1)-x0(imid0(:))) &\n / MERGE(x0(imid0(:)),x0(imid0(:)+1),x0(imid0(:)) /= 0._DP)\n FORALL (i=1:Nref,ABS(relstep(i)) <= stepmin) &\n good1(imid1(i)-1:imid1(i)) = .True.\n\n ! Exit when no more refinement is needed\n Nref = COUNT(.NOT. good1)\n counter = counter + 1\n IF (counter == Nrefmax .OR. Nref == 0) EXIT\n\n END DO refinement\n\n\n ! 3. Fine grid\n !-------------\n nokeep: IF (.NOT. dontkeep) THEN\n ALLOCATE (xfine(N1),yfine(N1,Nz))\n xfine(:) = x1(:)\n yfine(:,:) = f1(:,:)\n ELSE\n Nslim = COUNT(keep1(:))\n ALLOCATE (xfine(Nslim),yfine(Nslim,Nz))\n xfine(:) = PACK(x1(:),keep1(:))\n FORALL (iz=1:Nz) yfine(:,iz) = PACK(f1(:,iz),keep1(:))\n END IF nokeep\n\n ! Primitive\n doprim: IF (integacc .AND. PRESENT(primitive)) THEN\n IF (.NOT. dontkeep) THEN\n ALLOCATE (primitive(N1,Nz))\n primitive(1,:) = 0._DP\n DO i=2,N1 ; primitive(i,:) = dF1(i,:) + primitive(i-1,:) ; END DO\n ELSE\n ALLOCATE (prim1(N1,Nz),primitive(Nslim,Nz))\n prim1(1,:) = 0._DP\n DO i=2,N1 ; prim1(i,:) = dF1(i,:) + prim1(i-1,:) ; END DO\n FORALL (iz=1:Nz) primitive(:,iz) = PACK(prim1(:,iz),keep1(:))\n DEALLOCATE (prim1)\n END IF\n END IF doprim\n\n ! Clean memory\n DEALLOCATE(x0,x1,f0,f1,ind1,good0,good1,imid0,imid1,xmid,fmid,relstep)\n IF (yl) DEALLOCATE(lnf0,lnf1,lnfmid)\n IF (xl) DEALLOCATE(lnx0,lnx1,lnxmid)\n IF (integacc) DEALLOCATE(dF0,dF1,deltadF0,deltadF1)\n IF (dontkeep) DEALLOCATE(keep0,keep1)\n IF (.NOT. integacc) DEALLOCATE(fmidint)\n IF (.NOT. integacc .AND. yl) DEALLOCATE(lnfmidint)\n IF (.NOT. integacc) DEALLOCATE(threshint)\n\n !------------------------------------------------------------------------\n\n END SUBROUTINE gridadapt1D_zgrid\n\n\n !===========================================================================\n ! x[N] = GRID_KERNEL(N,xinf,xsup,xgrid,fgrid,xlog,ylog)\n !\n ! Creates a grid by inversing a cumulative distribution function of f, \n ! which is a tabulated function.\n !===========================================================================\n\n FUNCTION grid_kernel (N,xinf,xsup,xgrid,fgrid,xlog,ylog)\n! TO BE TESTED!!!...\n\n USE utilities, ONLY: DP\n USE interpolation, ONLY: interp_lin_sorted\n USE integration, ONLY: integ_tabulated\n IMPLICIT NONE\n\n INTEGER, INTENT(IN) :: N\n REAL(DP), INTENT(IN) :: xinf, xsup\n REAL(DP), DIMENSION(:), INTENT(IN) :: xgrid, fgrid\n REAL(DP), DIMENSION(N) :: grid_kernel\n LOGICAL, INTENT(IN), OPTIONAL :: xlog, ylog\n\n INTEGER :: i, Ngrid\n REAL(DP) :: intgrid\n REAL(DP), DIMENSION(N) :: ind\n REAL(DP), DIMENSION(SIZE(xgrid)) :: primgrid\n LOGICAL :: xl, yl\n\n !------------------------------------------------------------------------\n\n ! Options\n xl = .False.\n IF (PRESENT(xlog)) xl = xlog\n yl = .False.\n IF (PRESENT(ylog)) yl = ylog\n\n ! Primitive of the kernel\n Ngrid = SIZE(xgrid(:))\n intgrid = INTEG_TABULATED(xgrid(:),fgrid(:),XRANGE=[xinf,xsup], &\n PRIMITIVE=primgrid,XLOG=xl,YLOG=yl)\n primgrid(:) = primgrid(:) / primgrid(Ngrid)\n \n ! Inversion\n ind(:) = [(i,i=0,N-1)] / REAL(N-1,DP)\n grid_kernel(:) = INTERP_LIN_SORTED(xgrid(:),primgrid(:),ind(:),XLOG=yl)\n\n !------------------------------------------------------------------------\n\n END FUNCTION grid_kernel\n\n\nEND MODULE adaptative_grid\n", "meta": {"hexsha": "3a99eb35bdc18c582c882c28a860ad329cfa53ea", "size": 41534, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "MILES/swing/Math/adaptative_grid.f90", "max_stars_repo_name": "kxxdhdn/MISSILE", "max_stars_repo_head_hexsha": "89dea38aa9247f20c444ccd0b832c674be275fbf", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "MILES/swing/Math/adaptative_grid.f90", "max_issues_repo_name": "kxxdhdn/MISSILE", "max_issues_repo_head_hexsha": "89dea38aa9247f20c444ccd0b832c674be275fbf", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MILES/swing/Math/adaptative_grid.f90", "max_forks_repo_name": "kxxdhdn/MISSILE", "max_forks_repo_head_hexsha": "89dea38aa9247f20c444ccd0b832c674be275fbf", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.0202360877, "max_line_length": 80, "alphanum_fraction": 0.4982664805, "num_tokens": 13461, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6513142114423518}} {"text": " FUNCTION BICO(N,K)\n BICO=ANINT(EXP(FACTLN(N)-FACTLN(K)-FACTLN(N-K)))\n RETURN\n END\n", "meta": {"hexsha": "84edcb5766d53c40576de047067fcdaa75b45615", "size": 103, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "Math3/NumRec/source/bico.for", "max_stars_repo_name": "domijin/MM3", "max_stars_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Math3/NumRec/source/bico.for", "max_issues_repo_name": "domijin/MM3", "max_issues_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Math3/NumRec/source/bico.for", "max_forks_repo_name": "domijin/MM3", "max_forks_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.6, "max_line_length": 54, "alphanum_fraction": 0.5533980583, "num_tokens": 38, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9184802440252811, "lm_q2_score": 0.7090191399336402, "lm_q1q2_score": 0.6512200726648447}} {"text": "c=======================================================================\nc\nc GENMN \nc \nc Multivariate Normal random deviate\nc\nc-----------------------------------------------------------------------\nc\nc----------------------------------------------------------------------- \n SUBROUTINE genmn(parm, x, work)\nc----------------------------------------------------------------------- \nc\nc INPUT :\nc PARM --> Parameters needed to generate multivariate normal\nc deviates (MEANV and Cholesky decomposition of\nc COVM). Set by a previous call to SETGMN.\nc 1 : 1 - size of deviate, P\nc 2 : P + 1 - mean vector\nc P+2 : P*(P+3)/2 + 1 - upper half of cholesky\nc decomposition of cov matrix\nc DOUBLE PRECISION PARM(*)\nc\nc X <-- Vector deviate generated (P) double\nc WORK <--> scratch array (P) double \nc\nc Method\nc 1) Generate P independent standard normal deviates - Ei ~ N(0,1)\nc 2) Using Cholesky decomposition find A s.t. trans(A)*A = COVM\nc 3) trans(A)E + MEANV ~ N(MEANV,COVM)\nc\nc======================================================================\nc\nc array arguments\n DOUBLE PRECISION parm(*), work(*), x(*)\nc \nc local scalars\n DOUBLE PRECISION ae\n INTEGER i, icount, j, p\nc \nc external functions\n DOUBLE PRECISION snorm\n EXTERNAL snorm\nc \nc intrinsic functions\n INTRINSIC int\nc \nc executable statements\n p = int(parm(1))\nc\nc generate P independent normal deviates - WORK ~ N(0,1)\n DO 10,i = 1,p\n work(i) = snorm()\n 10 CONTINUE\n DO 30,i = 1,p\nc\nc PARM (P+2 : P*(P+3)/2 + 1) contains A, the Cholesky\nc decomposition of the desired covariance matrix.\nc trans(A)(1,1) = PARM(P+2)\nc trans(A)(2,1) = PARM(P+3)\nc trans(A)(2,2) = PARM(P+2+P)\nc trans(A)(3,1) = PARM(P+4)\nc trans(A)(3,2) = PARM(P+3+P)\nc trans(A)(3,3) = PARM(P+2-1+2P) ...\nc\nc trans(A)*WORK + MEANV ~ N(MEANV,COVM)\n icount = 0\n ae = 0.0\n DO 20,j = 1,i\n icount = icount + j - 1\n ae = ae + parm(i+ (j-1)*p-icount+p+1)*work(j)\n 20 CONTINUE\n x(i) = ae + parm(i+1)\n 30 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "413e1d2da473b7c54afd98ea9f16fcd67e2b13d1", "size": 2518, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/rnd/genmn.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/genmn.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/genmn.f", "max_forks_repo_name": "alpgodev/numx", "max_forks_repo_head_hexsha": "d2d3a0713020e1b83b65d3a661c3801ea256aff9", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.1315789474, "max_line_length": 78, "alphanum_fraction": 0.4197776013, "num_tokens": 687, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802417938535, "lm_q2_score": 0.7090191399336402, "lm_q1q2_score": 0.6512200710827198}} {"text": "SUBROUTINE BottomBerkoff(FineGrid,GX,GY)\n!\n! Define bottom profile for Berkhoff experiment (3D)\n!\n! By Allan P. Engsig-Karup.\nUSE Precision\nUSE Constants\nUSE DataTypes\nIMPLICIT NONE\nTYPE (Level_def) :: FineGrid\nREAL(KIND=long) :: y, x, xr, yr, k, angle, dxrdx, dxrdy, dyrdx, dyrdy\nINTEGER :: Nx, Ny, i, j, GX, GY\n\n!hbb Added the ghost points here.\nNx = FineGrid%Nx+2*GX\nNy = FineGrid%Ny+2*GY\nangle = 20\nk = angle/180.0_long*pi\nDO j = 1, Ny\n!hbb x and y are 2D arrays in the FineGrid. \n DO i = 1 , Nx\n x = FineGrid%x(i,1) - half*FineGrid%x(Nx,1) ! position shoal in middle relative to y-axis\n y = FineGrid%y(1,j) - 11.0_long ! FIXME: translation relative to standard y-coordinates\n xr = cos(k)*x - sin(k)*y\n yr = sin(k)*x + cos(k)*y\n dxrdx = cos(k)\n dyrdx = sin(k)\n dxrdy = -sin(k)\n dyrdy = cos(k)\n IF (yr<=-5.82_long) THEN\n FineGrid%h(i,j) = 0.45_long\n FineGrid%hx(i,j) = zero\n FineGrid%hy(i,j) = zero\n FineGrid%hxx(i,j) = zero\n FineGrid%hyy(i,j) = zero\n ELSE ! IF (yr>-5.82_long) THEN\n FineGrid%h(i,j) = 0.45_long-0.02_long*(5.82_long+yr)\n FineGrid%hx(i,j) = -0.02_long*dyrdx\n FineGrid%hy(i,j) = -0.02_long*dyrdy\n FineGrid%hxx(i,j) = zero\n FineGrid%hyy(i,j) = zero\n END IF\n IF ((xr/four)**2 + (yr/three)**2<1) THEN\n FineGrid%h(i,j) = FineGrid%h(i,j) + 0.3_long - half*sqrt(one-(xr/five)**2-(yr/3.75_long)**2)\n!WRITE(*,*) ' WARNING: The bottom slopes for the Berkhoff experiment is not defined analytically (i.e. not implemented).'\n!WRITE(*,*) ' WARNING: Therefore the derivatives of the bottom profile function is determined numerically.'\n FineGrid%hx(i,j) = FineGrid%hx(i,j) + (0.02_long*xr*dxrdx + &\n 0.0355556_long*yr*dyrdx)/sqrt(one-0.04_long*xr**2-0.0711111_long*yr**2) \n FineGrid%hy(i,j) = FineGrid%hy(i,j) + (0.02_long*xr*dxrdy + & \n 0.0355556_long*yr*dyrdy)/sqrt(one-0.04_long*xr**2-0.0711111_long*yr**2) \n! FineGrid%hxx(i,j) = FineGrid%hxx(i,j) + \n! FineGrid%hyy(i,j) = FineGrid%hyy(i,j) + \n END IF\n IF (FineGrid%h(i,j)<0.1_long) THEN\n ! flat bottom profile after shoal \n ! - this is very absorption zone should effectively damp outgoing waves\n FineGrid%h(i,j) = 0.1_long\n FineGrid%hx(i,j) = zero\n FineGrid%hy(i,j) = zero\n FineGrid%hxx(i,j) = zero\n FineGrid%hyy(i,j) = zero\n END IF\n END DO\nEND DO\nWRITE(*,*) ' WARNING: The bottom slopes for the Berkhoff experiment is not defined analytically (i.e. not implemented).'\nWRITE(*,*) ' WARNING: Therefore the derivatives of the bottom profile function is determined numerically.'\nEND SUBROUTINE BottomBerkoff\n", "meta": {"hexsha": "14c3329bdbac9b40fc388d4b7558cbe1e872f10f", "size": 2765, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/analyticalsolutions/bottomBerkoff.f90", "max_stars_repo_name": "apengsigkarup/OceanWave3D", "max_stars_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 46, "max_stars_repo_stars_event_min_datetime": "2016-01-08T12:36:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T06:56:45.000Z", "max_issues_repo_path": "src/analyticalsolutions/bottomBerkoff.f90", "max_issues_repo_name": "apengsigkarup/OceanWave3D", "max_issues_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2015-10-10T19:45:08.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-07T07:37:11.000Z", "max_forks_repo_path": "src/analyticalsolutions/bottomBerkoff.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": 40.6617647059, "max_line_length": 122, "alphanum_fraction": 0.6126582278, "num_tokens": 980, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802417938535, "lm_q2_score": 0.7090191276365462, "lm_q1q2_score": 0.651220059788082}} {"text": "MODULE FUN_xyzCENTROID\n!!#### PURPOSE\n!! Calculate the centroid (center-of-mass) of a polygon.\n\n!!#### METHOD\n!! First collapse R^3 variables into R^2 using transformation matrix,\n!! then calculate centroid via R^2 procedure xyCENTROID_Pg.\n\n!!#### EXTERNAL KINDS\nUSE KND_IntrinsicTypes,ONLY: KIND_Rsp,KIND_Rdp !!((01-A-KND_IntrinsicTypes.f90))\n\n!!#### EXTERNAL PARAMETERS\nUSE PAR_Constants_Rsp,ONLY: c_1_by_6_Rsp => c_1_by_6 !!((02-A-PAR_Constants_Rsp.f90))\nUSE PAR_Constants_Rdp,ONLY: c_1_by_6_Rdp => c_1_by_6 !!((02-A-PAR_Constants_Rdp.f90))\n\n!!#### EXTERNAL PROCEDURES\nUSE FUN_xyzSAREA ,ONLY: !!((06-B-FUN_xyzSAREA.f90))\nUSE FUN_xyzCOLLAPSE,ONLY: xyzCOLLAPSE_Pg !!((05-B-FUN_xyzCOLLAPSE.f90))\nUSE FUN_xyCENTROID ,ONLY: xyCENTROID_Pg !!((05-B-FUN_xyCENTROID.f90))\nUSE FUN_xyEXPAND ,ONLY: xyEXPAND_P !!((05-B-FUN_xyEXPAND.f90))\n\n!!#### DEFAULT IMPLICIT\nIMPLICIT NONE\n\n!!#### DEFAULT ACCESS\nPRIVATE\n\n!!#### PROCEDURE OVERLOADING\nINTERFACE xyzCENTROID_Pg\n MODULE PROCEDURE xyzCENTROID_Pg_Rsp\n MODULE PROCEDURE xyzCENTROID_Pg_Rdp\nEND INTERFACE\n\n!!#### PUBLIC ACCESS LIST\nPUBLIC :: xyzCENTROID_Pg\n\n\nCONTAINS\n\n\nFUNCTION xyzCENTROID_Pg_Rsp( N , Pg , M32_transform , SAREA ) RESULT(xyzP)\n!!#### LOCAL KINDS\nUSE KND_IntrinsicTypes,ONLY: KIND_R=>KIND_Rsp !!((01-A-KND_IntrinsicTypes.f90))\n!!#### LOCAL PARAMETERS\nREAL(KIND_R),PARAMETER :: c_1_by_6 = c_1_by_6_Rsp\nINCLUDE \"07-B-FUN_xyzCENTROID_Pg.f90.hdr\"\n!!--begin--\nINCLUDE \"07-B-FUN_xyzCENTROID_Pg.f90.bdy\"\n!!--end--\nENDFUNCTION\n\nFUNCTION xyzCENTROID_Pg_Rdp( N , Pg , M32_transform , SAREA ) RESULT(xyzP)\n!!#### LOCAL KINDS\nUSE KND_IntrinsicTypes,ONLY: KIND_R=>KIND_Rdp !!((01-A-KND_IntrinsicTypes.f90))\n!!#### LOCAL PARAMETERS\nREAL(KIND_R),PARAMETER :: c_1_by_6 = c_1_by_6_Rdp\nINCLUDE \"07-B-FUN_xyzCENTROID_Pg.f90.hdr\"\n!!--begin--\nINCLUDE \"07-B-FUN_xyzCENTROID_Pg.f90.bdy\"\n!!--end--\nENDFUNCTION\n\nENDMODULE\n", "meta": {"hexsha": "e232f52962e727a6c25d6ef6a153b3d5b1e5d993", "size": 1943, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/07-B-FUN_xyzCENTROID.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/07-B-FUN_xyzCENTROID.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/07-B-FUN_xyzCENTROID.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.359375, "max_line_length": 86, "alphanum_fraction": 0.7128152342, "num_tokens": 629, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.837619979547273, "lm_q2_score": 0.7772998663336158, "lm_q1q2_score": 0.6510818981404612}} {"text": "program fibo_arr\n! !\u304b\u3089\u884c\u672b\u307e\u3067\u306f\u30b3\u30e1\u30f3\u30c8\u3068\u3057\u3066\u6271\u308f\u308c\u308b\u3002\n! FOTRAN\u306b\u306f\u300c\u56fa\u5b9a\u5f62\u5f0f\u300d\u3068\u300c\u81ea\u7531\u5f62\u5f0f\u300d\u3068\u3044\u30462\u3064\u306e\u66f8\u304d\u65b9\u304c\u3042\u308b\u3089\u3057\u304f\u3001\n! \u3053\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u306f\u81ea\u7531\u5f62\u5f0f\u306e\u65b9\u3067\u66f8\u3044\u3066\u3044\u308b\n! \u8a73\u3057\u304f\u306f\u300cfortran \u81ea\u7531\u5f62\u5f0f \u56fa\u5b9a\u5f62\u5f0f\u300d\u306a\u3069\u3067\u30b0\u30b0\u308b\u3068\u51fa\u3066\u304f\u308b\n\n! \u300c\u6697\u9ed9\u306e\u578b\u5ba3\u8a00\u300d\u3092\u884c\u308f\u306a\u3044\u3002\n! FOTRAN\u3067\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306f\u578b\u5ba3\u8a00\u3092\u884c\u308f\u306a\u3044\u5834\u5408\n! [a-ho-z]\u3067\u59cb\u307e\u308b\u5909\u6570\u306f\u5b9f\u6570\u578b\u3001[i-n]\u3067\u59cb\u307e\u308b\u5909\u6570\u306f\u6574\u6570\u578b\u3068\u3057\u3066\u6271\u308f\u308c\u308b\n implicit none\n! \u6574\u6570\u578b\u306e\u30eb\u30fc\u30d7\u5909\u6570i\n integer i\n! \u8981\u7d20\u657020\u306e\u914d\u5217\u306e\u5ba3\u8a00\n! \u914d\u5217\u306e[]\u306fFOTRAN\u3067\u306f()\u3068\u306a\u308b\u3002\u53c8\u3001\u6dfb\u5b57\u306f1\u304b\u3089\u59cb\u307e\u308b\n integer f(20)\n! fib[1]\u3001fib[2]\u306e\u8a2d\u5b9a\n f(1) = 1\n f(2) = 1\n\n! \u7b2c\u4e09\u9805\u4ee5\u964d\u3092\u8a08\u7b97\u3057\u3066\u914d\u5217\u306e\u5404\u8981\u7d20\u306b\u683c\u7d0d\n do i=3,20\n f(i) = f(i-1) + f(i-2)\n end do\n! \u914d\u5217\u306e\u4e2d\u8eab\u3092\u8868\u793a\n do i=1,20\n print *, f(i)\n end do\nend program fibo_arr\n\n! \u53c2\u8003: Fortran\u5165\u9580 \n\n", "meta": {"hexsha": "4801a997fe7a8d44e6481d121966d7fe04bec013", "size": 631, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "sampleCodes/fortran/fib.f90", "max_stars_repo_name": "tasuten/kc3-2012", "max_stars_repo_head_hexsha": "c371ca67ed74cef6b6bb99f99db838f3944ceb6b", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-07-02T07:40:28.000Z", "max_stars_repo_stars_event_max_datetime": "2015-07-02T07:40:28.000Z", "max_issues_repo_path": "sampleCodes/fortran/fib.f90", "max_issues_repo_name": "tasuten/kc3-2012", "max_issues_repo_head_hexsha": "c371ca67ed74cef6b6bb99f99db838f3944ceb6b", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sampleCodes/fortran/fib.f90", "max_forks_repo_name": "tasuten/kc3-2012", "max_forks_repo_head_hexsha": "c371ca67ed74cef6b6bb99f99db838f3944ceb6b", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.71875, "max_line_length": 59, "alphanum_fraction": 0.6354992076, "num_tokens": 421, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7772998611746912, "lm_q2_score": 0.8376199673867852, "lm_q1q2_score": 0.6510818843668975}} {"text": " program trnkey\n\nc TRNKEY -- program to make a numerical version of a transpostion\nc key for use (most likely) in a (cryptographic) transposition\nc cipher. The input is a character string.\nc\nc The way this works is as follows:\nc The user inputs a character string containing any ASCII\nc characters. The characters are mapped to upper-case and\nc any non-alphabetic characters are eliminated.\nc The letters in the resulting string are then numbered\nc alphabetically, with duplicate letters being numbered from\nc left to right.\nc For instance:\nc JOANN yields the numerical sequence 2-5-1-3-4.\nc For classical cryptographic applications, 2-5-1-3-4 would be\nc the resultant numerical version of the key.\nc For computer applications, an \"inverted\" form of the key, with\nc the ordinal number of \"1\" first, the ordinal number of \"2\"\nc second, etc., might be more useful.\nc\nc Written by Mark Riordan 27 September 1986\n\n integer nkeymx\n parameter(nkeymx=160)\n integer nkey,j,inew,iold,tint\n logical debug,qchng\n character key(nkeymx)*1,tchar\n integer numkey(nkeymx)\n\n debug = .false.\ncc\twrite(*,9000)\ncc9000\tformat(' Please input the key string:')\n read(*,8000,end=666) (key(j),j=1,nkeymx)\n8000 format(160a)\n\n inew = 0\n do 120 iold = 1, nkeymx\n\tif(key(iold).ge.'a' .and. key(iold).le.'z') then\n\t key(iold) = char(ichar(key(iold))-32)\n\tendif\n\tif(key(iold).ge.'A' .and. key(iold).le.'Z') then\n\t inew = inew + 1\n\t key(inew) = key(iold)\n\tendif\n120 continue\n nkey = inew\n if(nkey .le. 0) then\n\twrite(*,*) 'No legal key characters were input.'\n\tgo to 999\n endif\n\n if(debug) then\n\twrite(*,9200) (key(j),j=1,inew)\n9200\tformat(' ',160a)\n endif\n\nc Create an array of ordinal positions. The sorted version of\nc this array will be the numerical version of the key.\nc Initially, for this algorithm, we start out with 1-2-3-...\nc in this array.\n\n do 140 j = 1, nkey\n\tnumkey(j) = j\n140 continue\n\nc Sort the key characters, and drag their ordinal numbers along\nc to keep track of things.\n\n160 continue\n qchng = .false.\n\tdo 200 j = 1, nkey-1\n\t if(key(j) .gt. key(j+1)) then\n\t tchar = key(j)\n\t key(j) = key(j+1)\n\t key(j+1) = tchar\n\t tint = numkey(j)\n\t numkey(j) = numkey(j+1)\n\t numkey(j+1) = tint\n\t qchng = .true.\n\t endif\n200\tcontinue\n if(qchng) go to 160\n\nc The key is now sorted.\n\n if(debug) then\n\twrite(*,9220) (numkey(j), j=1,nkey)\n9220\tformat(' Row #''s in ordinal order:',40i4)\n endif\n\ncc\topen(12,file='tordkey.txt')\ncc\trewind 12\n write(*,9030) (numkey(j),j=1,nkey)\n9030 format(40i4)\n\n goto 999\n666 continue\n\twrite(*,*) 'Premature end-of-file encountered.'\n\tgo to 999\n\n999 continue\n end\n end\n\u001a", "meta": {"hexsha": "b909c1d471d210c63d5a00a42c4fd9571cd275a1", "size": 2818, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "MRRCIP/mktrnkey.for", "max_stars_repo_name": "ab300819/applied-cryptography", "max_stars_repo_head_hexsha": "3fddc4cda2e1874e978608259034d36c60a4dbba", "max_stars_repo_licenses": ["MIT", "Unlicense"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-04-17T05:01:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-17T05:01:00.000Z", "max_issues_repo_path": "MRRCIP/mktrnkey.for", "max_issues_repo_name": "ab300819/applied-cryptography", "max_issues_repo_head_hexsha": "3fddc4cda2e1874e978608259034d36c60a4dbba", "max_issues_repo_licenses": ["MIT", "Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "MRRCIP/mktrnkey.for", "max_forks_repo_name": "ab300819/applied-cryptography", "max_forks_repo_head_hexsha": "3fddc4cda2e1874e978608259034d36c60a4dbba", "max_forks_repo_licenses": ["MIT", "Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.8380952381, "max_line_length": 68, "alphanum_fraction": 0.6479772889, "num_tokens": 890, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199714402812, "lm_q2_score": 0.7772998560157665, "lm_q1q2_score": 0.651081883196461}} {"text": "! Main program\n\nprogram intersections\n\n use newton, only: solve\n use functions, only: f_int, fprime_int\n\n implicit none\n real(kind=8) :: x, x0, fx\n real(kind=8) :: x0vals(4)\n integer :: iters, itest\n\tlogical :: debug\n\n print *, \"Test routine for computing zero of f\"\n debug = .true.\n\n ! values to test as x0:\n x0vals = (/-2.2d0, -1.6d0, -0.8d0, 1.45d0/)\n\n do itest=1,4\n x0 = x0vals(itest)\n\t\tprint *, ' ' ! blank line\n call solve(f_int, fprime_int, x0, x, iters, debug)\n\n print 11, x, iters\n11 format('solver returns x = ', es22.15, ' after', i3, ' iterations')\n\n fx = f_int(x)\n print 12, fx\n12 format('the value of f(x) is ', es22.15)\n\n enddo\n\nend program intersections\n", "meta": {"hexsha": "4589a82b5d8c8621e7c5a2596e995a35c4f3d9ea", "size": 756, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "uwhpsc/2013/solutions/homework3/intersections.f90", "max_stars_repo_name": "philipwangdk/HPC", "max_stars_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "uwhpsc/2013/solutions/homework3/intersections.f90", "max_issues_repo_name": "philipwangdk/HPC", "max_issues_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "uwhpsc/2013/solutions/homework3/intersections.f90", "max_forks_repo_name": "philipwangdk/HPC", "max_forks_repo_head_hexsha": "e2937016821701adb80ece5bf65d43d1860640c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.6, "max_line_length": 75, "alphanum_fraction": 0.5793650794, "num_tokens": 257, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199552262968, "lm_q2_score": 0.7772998508568416, "lm_q1q2_score": 0.6510818662721148}} {"text": "C++***************************************************************\nC Subset of FFT routines modified for fft1.for \nC Using NAG library \nC (Extracted from fft_nag.for to be compiled with fft1.for)\nC\nC JLP\nC Version of 06-09-95\nC--***************************************************************\nC********************************************************************\nC FFT 1D routine along the columns\nC Input:\nC TR, TI: real part and imaginary part (input/output) of the image\nC\nC KOD=1, or 2 direct\nC KOD=-1, or -2 inverse\nC KOD=-2, or 2: power spectrum, and phase\nC********************************************************************\n\tSUBROUTINE FFT_1D_Y_NAG(TR,TI,NX,NY,IDIM1,KOD)\n\tPARAMETER (IDIM=600)\n\tREAL TR(IDIM1,*),TI(IDIM1,*)\n\tDOUBLE PRECISION DR(IDIM*IDIM),DI(IDIM*IDIM),WORK(2000)\n\tREAL F_NORM\n\tINTEGER NX,NY,KOD\n\tPI=3.14159265358979323846\n \nC Main loop on I=1,NX\n\tDO I=1,NX\n\nC Conversion of the input (when KOD=-2)\n\tII=0\n\tIF(KOD.EQ.-2) THEN\n\t DO J=1,NY\n\t XM=TR(I,J)\n\t XP=TI(I,J)\n\t II=II+1\n\t DR(II)=XM*COS(XP)\n\t DI(II)=XM*SIN(XP)\n\t ENDDO\n ELSE\n\t DO J=1,NY\n\t II=II+1\n\t DR(II)=TR(I,J)\n\t DI(II)=TI(I,J)\n\t END DO\n\tENDIF\t\n \nC Compute the FFT:\n\t IFAIL=0\nC WARNING: NAG FFT divides the result by SQRT(NX*NY)\n\t IF(KOD.GT.0)THEN\n\t CALL C06FCF(DR,DI,NY,WORK,IFAIL)\n\t ELSE\n\t CALL C06GCF(DI,NY,IFAIL)\n\t CALL C06FCF(DR,DI,NY,WORK,IFAIL)\n\t CALL C06GCF(DI,NY,IFAIL)\n\t ENDIF\n \nC Copy back the arrays \nC Division by sqrt(ntot) \nC\tF_NORM=1./SQRT(FLOAT(NY))\nC JLP2000: NAG already divides by ny:\n\tF_NORM=1.\n\n\tII=0\n\t DO J=1,NY\n\t II=II+1\n\t TR(I,J)=DR(II)*F_NORM\n\t TI(I,J)=DI(II)*F_NORM\n\t END DO\n \n\t IF(KOD.EQ.2)THEN\nC Power and phase spectrum in output when KOD=2:\n\t DO J=1,NY\n\t AR=TR(I,J)\n\t AI=TI(I,J)\n\t TR(I,J)=SQRT(AR*AR+AI*AI)\n\t IF(AR.EQ.0) THEN\n\t TI(I,J)=PI/2.\n\t IF(AI.LT.0.)TI(I,J)=3.*PI/2.\n\t ELSE\n\t TI(I,J)=ATAN(AI/AR)\n\t IF(AR.LT.0.)TI(I,J)=TI(I,J)+PI\n\t ENDIF\n IF(TI(I,J).LT.0.)TI(I,J)=TI(I,J)+2.*PI\n\t ENDDO\n\t ENDIF\n\nC End of loop on I=1,NX: \n\tENDDO\n\t\n\tRETURN\n\tEND\n", "meta": {"hexsha": "6dc6c768142323ffac874ed3d40c55193b2e0093", "size": 2105, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "jlp_numeric/old/fft_num_old/fft1_nag.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/old/fft_num_old/fft1_nag.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/old/fft_num_old/fft1_nag.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": 22.6344086022, "max_line_length": 69, "alphanum_fraction": 0.5273159145, "num_tokens": 780, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898203834278, "lm_q2_score": 0.718594386544335, "lm_q1q2_score": 0.6510391991938416}} {"text": " subroutine wipowe(vr,vi,p,rr,ri,ierr)\nc!purpose\nc computes v^p with v complex and p integer\nc!calling sequence \nc subroutine wipowe(vr,vi,p,rr,ri,ierr)\nc integer ierr\nc double precision vr,vi,p,rr,ri\nc vr : real part of v\nc vi : imaginary part of v\nc rr : result's real part\nc ri : result's imaginary part\nc ierr : error flag\nc ierr=0 if ok\nc ierr=1 if 0**0\nc ierr=2 if 0**k with k<0\nc!origin\nc Serge Steer INRIA 1996\nc!\nc Copyright INRIA\n integer p,ierr\n double precision vr,vi,xr,xi,rr,ri,infinity\nc\n ierr=0\nc\n if(p.eq.0) then\n rr=1.0d+0\n ri=0.0d+0\n elseif(p.lt.0) then\n if(abs(vr)+abs(vi).ne.0.0d+0) then\n call wdiv(1.0d+0,0.0d+0,vr,vi,rr,ri)\n xr=rr\n xi=ri\n do 10 k=2,abs(p)\n call wmul(xr,xi,rr,ri,rr,ri)\n 10 continue\n else\n ri=0.0d0\n rr=infinity(ri)\n ierr=2\n endif\n else\n rr=vr\n ri=vi\n xr=rr\n xi=ri\n do 20 k=2,abs(p)\n call wmul(xr,xi,rr,ri,rr,ri)\n 20 continue\n endif\n return\n end\n", "meta": {"hexsha": "657aac3635d18738fc2e8911167640fc04a67538", "size": 1212, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/math/calelm/wipowe.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/wipowe.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/wipowe.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": 23.3076923077, "max_line_length": 49, "alphanum_fraction": 0.5041254125, "num_tokens": 432, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898254600902, "lm_q2_score": 0.7185943805178139, "lm_q1q2_score": 0.6510391973819358}} {"text": "module randutil\n\n use,intrinsic :: iso_fortran_env\n\n implicit none\n private\n\n public :: i1rand, i2rand, i4rand, i8rand, &\n r4rand, r8rand, c8rand, c16rand, strrand\n\ncontains\n\n subroutine i1rand(x)\n integer(kind=1), intent(out) :: x\n real(kind=REAL32) :: r\n call random_number(r)\n x = floor(256*r) - 128\n end subroutine i1rand\n \n subroutine i2rand(x)\n integer(kind=2), intent(out) :: x\n real(kind=REAL32) :: r\n call random_number(r)\n x = floor(65536*r) - 32768\n end subroutine i2rand\n \n subroutine i4rand(x)\n integer(kind=4), intent(out) :: x\n integer(kind=2) :: r(2)\n call i2rand(r(1))\n call i2rand(r(2))\n x = transfer(r,x)\n end subroutine i4rand\n \n subroutine i8rand(x)\n integer(kind=8), intent(out) :: x\n integer(kind=4) :: r(2)\n call i4rand(r(1))\n call i4rand(r(2))\n x = transfer(r,x)\n end subroutine i8rand\n \n subroutine r4rand(x)\n real(kind=REAL32), intent(out) :: x\n call random_number(x)\n end subroutine r4rand\n\n subroutine r8rand(x)\n real(kind=REAL64), intent(out) :: x\n call random_number(x)\n end subroutine r8rand\n\n subroutine c8rand(x)\n complex(kind=REAL32), intent(out) :: x\n real(kind=REAL32) :: r(2)\n call random_number(r)\n x = cmplx(r(1), r(2), kind=REAL32)\n end subroutine c8rand\n\n subroutine c16rand(x)\n complex(kind=REAL64), intent(out) :: x\n real(kind=REAL64) :: r(2)\n call random_number(r)\n x = cmplx(r(1), r(2), kind=REAL64)\n end subroutine c16rand\n\n subroutine chrrand(x)\n character, intent(out) :: x\n real(kind=REAL32) :: r\n call random_number(r)\n x = char(floor(32 + 96*r))\n end subroutine chrrand\n\n subroutine strrand(x)\n character(len=*), intent(out) :: x\n integer :: i\n do i = 1,len(x)\n call chrrand(x(i:i))\n end do\n end subroutine strrand\n\nend module randutil\n\n", "meta": {"hexsha": "d3f63aafb8de5008a59d6139f003f3709d21c2dc", "size": 1967, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "test/codegen/randutil.f90", "max_stars_repo_name": "UnofficialJuliaMirror/FortranFiles.jl-c58ffaec-ab22-586d-bfc5-781a99fd0b10", "max_stars_repo_head_hexsha": "3709541e482cca9527a594f66ba39c03dcdebd14", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 27, "max_stars_repo_stars_event_min_datetime": "2017-04-05T14:00:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-09T13:20:35.000Z", "max_issues_repo_path": "test/codegen/randutil.f90", "max_issues_repo_name": "UnofficialJuliaMirror/FortranFiles.jl-c58ffaec-ab22-586d-bfc5-781a99fd0b10", "max_issues_repo_head_hexsha": "3709541e482cca9527a594f66ba39c03dcdebd14", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2017-06-30T14:31:41.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-21T19:01:53.000Z", "max_forks_repo_path": "test/codegen/randutil.f90", "max_forks_repo_name": "UnofficialJuliaMirror/FortranFiles.jl-c58ffaec-ab22-586d-bfc5-781a99fd0b10", "max_forks_repo_head_hexsha": "3709541e482cca9527a594f66ba39c03dcdebd14", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2017-04-05T13:30:32.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-11T15:23:22.000Z", "avg_line_length": 23.4166666667, "max_line_length": 53, "alphanum_fraction": 0.5922724962, "num_tokens": 596, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511579973931, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.651003746569048}} {"text": "! Program to test the ABS intrinsic\nprogram intrinsic_abs\n implicit none\n integer i\n real(kind=4) r\n real(kind=8) q\n complex z\n\n i = 42\n i = abs(i)\n if (i .ne. 42) call abort\n i = -43\n i = abs(i)\n if (i .ne. 43) call abort\n\n r = 42.0\n r = abs(r)\n if (r .ne. 42.0) call abort\n r = -43.0\n r = abs(r)\n if (r .ne. 43.0) call abort\n\n q = 42.0_8\n q = abs(q)\n if (q .ne. 42.0_8) call abort\n q = -43.0_8\n q = abs(q)\n if (q .ne. 43.0_8) call abort\n\n z = (3, 4)\n r = abs(z)\n if (r .ne. 5) call abort\nend program\n", "meta": {"hexsha": "9e44657bad148e26479d38af79aac5aa9786dd99", "size": 554, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_abs.f90", "max_stars_repo_name": "best08618/asylo", "max_stars_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-05-02T17:34:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-17T10:15:18.000Z", "max_issues_repo_path": "llvm-gcc-4.2-2.9/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_abs.f90", "max_issues_repo_name": "vidkidz/crossbridge", "max_issues_repo_head_hexsha": "ba0bf94aee0ce6cf7eb5be882382e52bc57ba396", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "llvm-gcc-4.2-2.9/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_abs.f90", "max_forks_repo_name": "vidkidz/crossbridge", "max_forks_repo_head_hexsha": "ba0bf94aee0ce6cf7eb5be882382e52bc57ba396", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-27T00:22:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-01T09:41:02.000Z", "avg_line_length": 16.2941176471, "max_line_length": 35, "alphanum_fraction": 0.5216606498, "num_tokens": 245, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.7606506581031359, "lm_q1q2_score": 0.6510037381789695}} {"text": "subroutine f_main\n\n! This program finds polynomial roots. Double precision, double complex,\n! arbitrary precision real and arbitrary precision complex versions are\n! included.\n! David H Bailey 2004-05-27\n\nuse mpmodule\nimplicit none\ninteger i, n, ndp, nr\nparameter (n = 10, ndp = 500)\nreal*8 da(0:n), second, tm0, tm1\n! real*8 dr, dr0\ncomplex*16 dr, dr0\ntype (mp_real) a(0:n)\n! type (mp_real) r0, r\ntype (mp_complex) r0, r\ndata da/1.d0, 1.d0, 0.d0, -1.d0, -1.d0, -1.d0, -1.d0, -1.d0, 0.d0, 1.d0, 1.d0/\n! data dr0/1.176d0/\ndata dr0/(0.457d0, 0.889d0)/\n\ncall mpinit\ncall mpsetprec (ndp)\nmpoud = ndp\n\nwrite (6, 1) da\n1 format ('Arbitrary precision polynomial root finder.'/'Coefficients:'/ &\n (1p,4d19.10))\n\ncall dcroot (n, dr0, da, nr, dr)\nwrite (6, 2) dr\n2 format ('Double precision root:'/(1p,2d19.10))\n\n! Copy coefficients in da to a.\n\ndo i = 0, n\n a(i) = da(i)\nenddo\n\nr0 = dr0\n\n! Find root of polynomial.\n\ntm0 = second ()\n! call rroot (n, r0, a, nr, r)\ncall croot (n, r0, a, nr, r)\ntm1 = second ()\nwrite (6, 3) tm1 - tm0\n3 format ('cpu time =',f8.2)\nwrite (6, 4)\n4 format ('Arbitrary precision root:')\ncall mpwrite (6, r)\nstop\nend\n\nsubroutine drroot (n, dr0, da, nr, dr)\n\n! Finds a single double-precision real root, beginning at dr0.\n\nimplicit none\ninteger i, j, n, nit, nr\nparameter (nit = 20)\nreal*8 da(0:n), dad(0:n-1), eps, eps1\nreal*8 d1, d2, d3, d4, dr, dr0\nparameter (eps = 1.d-15)\n\n! Compute derivative.\n\ndo i = 0, n - 1\n dad(i) = (i + 1) * da(i+1)\nenddo\n\nd1 = dr0\neps1 = eps * max (abs (d1), 1.d0)\n\n! Perform up to nit double-precision Newton iterations.\n\ndo j = 1, nit\n\n! Evaluate polynomial at d1.\n\n d2 = 0.d0\n\n do i = n, 0, -1\n d2 = d1 * d2 + da(i)\n enddo\n\n! Evaluate polynomial derivative at d1.\n\n d3 = 0.d0\n\n do i = n - 1, 0, -1\n d3 = d1 * d3 + dad(i)\n enddo\n\n d4 = d1 - d2 / d3\n if (abs (d1 - d4) < eps1) goto 100\n d1 = d4\nenddo\n\nwrite (6, 1)\n1 format ('drroot: failed to find double precision real root.')\nnr = 0\ndr = 0.d0\ngoto 110\n\n100 continue\n\nnr = 1\ndr = d1\n\n110 continue\n\nreturn\nend\n\nsubroutine dcroot (n, dr0, da, nr, dr)\n\n! Finds a single double-precision complex root, beginning at dr0.\n\nimplicit none\ninteger i, j, n, nit, nr\nparameter (nit = 20)\nreal*8 da(0:n), dad(0:n-1), eps, eps1\ncomplex*16 d1, d2, d3, d4, dr, dr0\nparameter (eps = 1.d-15)\n\n! Compute derivative.\n\ndo i = 0, n - 1\n dad(i) = (i + 1) * da(i+1)\nenddo\n\nd1 = dr0\neps1 = eps * max (abs (d1), 1.d0)\n\n! Perform up to nit double-precision Newton iterations.\n\ndo j = 1, nit\n\n! Evaluate polynomial at d1.\n\n d2 = 0.d0\n\n do i = n, 0, -1\n d2 = d1 * d2 + da(i)\n enddo\n\n! Evaluate polynomial derivative at d1.\n\n d3 = 0.d0\n\n do i = n - 1, 0, -1\n d3 = d1 * d3 + dad(i)\n enddo\n\n d4 = d1 - d2 / d3\n if (abs (d1 - d4) < eps1) goto 100\n d1 = d4\nenddo\n\nwrite (6, 1)\n1 format ('dcroot: failed to find double precision complex root.')\nnr = 0\ndr = 0.d0\ngoto 110\n\n100 continue\n\nnr = 1\ndr = d1\n\n110 continue\n\nreturn\nend\n\nsubroutine rroot (n, r0, a, nr, r)\n\n! Finds a single arbitrary-precision real root, beginning at r0.\n\nuse mpmodule\nimplicit none\ninteger i, j, n, nit, nr, nwp, nws\nparameter (nit = 100)\ntype (mp_real) a(0:n), ad(0:n-1), eps1\ntype (mp_real) t1, t2, t3, t4, r, r0\n\n! Compute derivative.\n\ndo i = 0, n - 1\n ad(i) = (i + 1) * a(i+1)\nenddo\n\ncall mpgetprecwords (nws)\nnwp = 3\ncall mpsetprecwords (nwp)\nt1 = r0\nt2 = 0.d0\nif (r0 /= t2) then\n eps1 = 2.d0 ** (-96) * abs (t1)\nelse\n eps1 = 2.d0 ** (-96)\nendif\n\n! Perform up to nit double-precision Newton iterations.\n\ndo j = 1, nit\n\n! Evaluate polynomial at t1.\n\n t2 = 0.d0\n\n do i = n, 0, -1\n t2 = t1 * t2 + a(i)\n enddo\n\n! Evaluate polynomial derivative at t1.\n\n t3 = 0.d0\n\n do i = n - 1, 0, -1\n t3 = t1 * t3 + ad(i)\n enddo\n\n t4 = t1 - t2 / t3\n if (nwp == 3) then\n if (abs (t1 - t4) < eps1) then\n nwp = min (2 * nwp - 1, nws)\n call mpsetprecwords (nwp)\n endif\n elseif (nwp < nws) then\n nwp = min (2 * nwp - 1, nws)\n call mpsetprecwords (nwp)\n else\n t1 = t4\n goto 100\n endif\n t1 = t4\nenddo\n\nwrite (6, 1)\n1 format ('rroot: failed to find arbitrary precision real root.')\nnr = 0\nr = 0.d0\ngoto 110\n\n100 continue\n\nnr = 1\nr = t1\n\n110 continue\n\nreturn\nend\n\nsubroutine croot (n, r0, a, nr, r)\n\n! Finds a single arbitrary-precision complex root, beginning at r0.\n\nuse mpmodule\nimplicit none\ninteger i, j, n, nit, nr, nwp, nws\nparameter (nit = 100)\ntype (mp_real) a(0:n), ad(0:n-1), eps1\ntype(mp_complex) t1, t2, t3, t4, r, r0\n\n! Compute derivative.\n\ndo i = 0, n - 1\n ad(i) = (i + 1) * a(i+1)\nenddo\n\ncall mpgetprecwords (nws)\nnwp = 3\ncall mpsetprecwords (nwp)\nt1 = r0\nt2 = (0.d0, 0.d0)\nif (r0 /= t2) then\n eps1 = 2.d0 ** (-96) * abs (t1)\nelse\n eps1 = 2.d0 ** (-96)\nendif\n\n! Perform up to nit double-precision Newton iterations.\n\ndo j = 1, nit\n\n! Evaluate polynomial at t1.\n\n t2 = (0.d0, 0.d0)\n\n do i = n, 0, -1\n t2 = t1 * t2 + a(i)\n enddo\n\n! Evaluate polynomial derivative at t1.\n\n t3 = (0.d0, 0.d0)\n\n do i = n - 1, 0, -1\n t3 = t1 * t3 + ad(i)\n enddo\n\n t4 = t1 - t2 / t3\n if (nwp == 3) then\n if (abs (t1 - t4) < eps1) then\n nwp = min (2 * nwp - 1, nws)\n call mpsetprecwords (nwp)\n endif\n elseif (nwp < nws) then\n nwp = min (2 * nwp - 1, nws)\n call mpsetprecwords (nwp)\n else\n t1 = t4\n goto 100\n endif\n t1 = t4\nenddo\n\nwrite (6, 1)\n1 format ('croot: failed to find multiple precision complex root.')\nnr = 0\nr = (0.d0, 0.d0)\ngoto 110\n\n100 continue\n\nnr = 1\nr = t1\n\n110 continue\n\nreturn\nend\n\n\n", "meta": {"hexsha": "e697854b1503b57b8711be87369cf6e22f3e1e9a", "size": 5492, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "ARPREC/arprec/fortran/roots.f", "max_stars_repo_name": "paveloom-p/P3", "max_stars_repo_head_hexsha": "57df3b6263db81685f137a7ed9428dbd3c1b4a5b", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ARPREC/arprec/fortran/roots.f", "max_issues_repo_name": "paveloom-p/P3", "max_issues_repo_head_hexsha": "57df3b6263db81685f137a7ed9428dbd3c1b4a5b", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ARPREC/arprec/fortran/roots.f", "max_forks_repo_name": "paveloom-p/P3", "max_forks_repo_head_hexsha": "57df3b6263db81685f137a7ed9428dbd3c1b4a5b", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 16.2005899705, "max_line_length": 78, "alphanum_fraction": 0.6026948288, "num_tokens": 2297, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.855851143290548, "lm_q2_score": 0.7606506418255928, "lm_q1q2_score": 0.6510037214511227}} {"text": "*> \\brief \\b CROTG\n*\n* =========== DOCUMENTATION ===========\n*\n* Online html documentation available at\n* http://www.netlib.org/lapack/explore-html/\n*\n* Definition:\n* ===========\n*\n* SUBROUTINE CROTG(CA,CB,C,S)\n*\n* .. Scalar Arguments ..\n* COMPLEX CA,CB,S\n* REAL C\n* ..\n*\n*\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*>\n*> CROTG determines a complex Givens rotation.\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in] CA\n*> \\verbatim\n*> CA is COMPLEX\n*> \\endverbatim\n*>\n*> \\param[in] CB\n*> \\verbatim\n*> CB is COMPLEX\n*> \\endverbatim\n*>\n*> \\param[out] C\n*> \\verbatim\n*> C is REAL\n*> \\endverbatim\n*>\n*> \\param[out] S\n*> \\verbatim\n*> S is COMPLEX\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee\n*> \\author Univ. of California Berkeley\n*> \\author Univ. of Colorado Denver\n*> \\author NAG Ltd.\n*\n*> \\date December 2016\n*\n*> \\ingroup complex_blas_level1\n*\n* =====================================================================\n SUBROUTINE CROTG(CA,CB,C,S)\n*\n* -- Reference BLAS level1 routine (version 3.7.0) --\n* -- Reference BLAS is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n* December 2016\n*\n* .. Scalar Arguments ..\n COMPLEX CA,CB,S\n REAL C\n* ..\n*\n* =====================================================================\n*\n* .. Local Scalars ..\n COMPLEX ALPHA\n REAL NORM,SCALE\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC CABS,CONJG,SQRT\n* ..\n IF (CABS(CA).EQ.0.) THEN\n C = 0.\n S = (1.,0.)\n CA = CB\n ELSE\n SCALE = CABS(CA) + CABS(CB)\n NORM = SCALE*SQRT((CABS(CA/SCALE))**2+ (CABS(CB/SCALE))**2)\n ALPHA = CA/CABS(CA)\n C = CABS(CA)/NORM\n S = ALPHA*CONJG(CB)/NORM\n CA = ALPHA*NORM\n END IF\n RETURN\n END\n", "meta": {"hexsha": "43159682fe329c1a0f7a20cdb751e2ba018808a8", "size": 1970, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "lapack-3.7.1/BLAS/SRC/crotg.f", "max_stars_repo_name": "supreethms1809/magma-2.2.0", "max_stars_repo_head_hexsha": "b713d0b0a7a4724847e3a4050987c5ea9e7a7279", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 63, "max_stars_repo_stars_event_min_datetime": "2018-06-21T14:11:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T11:24:36.000Z", "max_issues_repo_path": "lapack-3.7.1/BLAS/SRC/crotg.f", "max_issues_repo_name": "supreethms1809/magma-2.2.0", "max_issues_repo_head_hexsha": "b713d0b0a7a4724847e3a4050987c5ea9e7a7279", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2018-09-22T14:01:53.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-27T16:11:05.000Z", "max_forks_repo_path": "lapack-3.7.1/BLAS/SRC/crotg.f", "max_forks_repo_name": "supreethms1809/magma-2.2.0", "max_forks_repo_head_hexsha": "b713d0b0a7a4724847e3a4050987c5ea9e7a7279", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2018-08-23T15:59:44.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-20T06:47:22.000Z", "avg_line_length": 20.1020408163, "max_line_length": 80, "alphanum_fraction": 0.4837563452, "num_tokens": 585, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.828938825225204, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.6509727724803702}} {"text": "module root_module\n use precision_module, only : wp\n use error_module\n use constants_module\n\n implicit none\n public\n\ncontains\n\n\nfunction root(cf,limitL,limitR)\n implicit none\n real(wp) :: cf(5), limitL, limitR\n real(wp) :: rcf1(2),rcf2(3),rcf3(4), rcf4(5)\n real(wp) :: root\n\n if (cf(1).eq.0.0d0 .and. & \n cf(2).eq.0.0d0 .and. &\n cf(3).eq.0.0d0) then !linear potentials\n rcf1=cf(4:5) !get rid of first three elements \n rcf1=rcf1/rcf1(1) !get reduced polynomial \n root=poly1_root(rcf1,limitL,limitR) !find root of cubic polynomial \n\n elseif (cf(1).eq.0.0d0 .and. & \n cf(2).eq.0.0d0) then !quadratic polynomial\n rcf2=cf(3:5) !get rid of first element \n rcf2=rcf2/rcf2(1) !get reduced polynomial \n root=poly2_root(rcf2,limitL,limitR) !find root of cubic polynomial \n\n elseif (cf(1).eq.0.0d0) then !cubic polynomial \n rcf3=cf(2:5) !get rid of the first element \n rcf3=rcf3/rcf3(1) !get reduced polynomial \n root=poly3_root(rcf3,limitL,limitR) !find root of cubic polynomial \n\n else !quiartic polynomial \n rcf4=cf/cf(1) ! get reduced polynomial \n root=poly4_root(rcf4,limitL,limitR) !find root of quartic polynomial\n endif\nend function root\n\n!---------------------------------------------------------------------\n!---------------------------------------------------------------------\nfunction poly1_root(rcf,limitL,limitR)\n implicit none\n real(wp) :: rcf(2), limitL, limitR\n real(wp) :: x, poly1_root\n\n x=-rcf(2)\n if (x.gt.limitL .and. x.lt.limitR) then\n poly1_root=x\n else\n call error_message(8)!error code in parentheses \n endif\nend function poly1_root\n\n!---------------------------------------------------------------------\n!---------------------------------------------------------------------\nfunction poly2_root(rcf,limitL,limitR)\n implicit none\n real(wp) :: rcf(3), limitL, limitR\n real(wp) :: b,c,dd,x1,x2, poly2_root\n integer :: i\n\n b=rcf(2)\n c=rcf(3)\n dd=b**2.0d0-4.0d0*c !calculate determinant of reduced polynomial\n \n i=0 !number of roots\n if (dd.gt.0.0d0) then !two real root \n x1=(-b+sqrt(dd))/2\n x2=(-b-sqrt(dd))/2\n if (x1.gt.limitL .and. x1.lt.limitR) then\n poly2_root=x1\n i=i+1\n elseif (x2.gt.limitL .and. x2.lt.limitR) then\n poly2_root=x1\n i=i+1\n endif \n elseif (dd.eq.0.0d0) then\n x1=-b/2\n if (x1.gt.limitL .and. x1.lt.limitR) then\n poly2_root=x1\n i=i+1\n endif\n endif\n \n if (i.gt.1) then !multiple crossings in the region of interest \n call error_message(9) \n elseif (i.eq.0) then !no crossings in the region of interest \n call error_message(8) \n endif \nend function poly2_root\n\n!---------------------------------------------------------------------\n!---------------ROOTS ARE COMPUTED USING CARDANO METHOD---------------\n!----see details at http://mathworld.wolfram.com/CubicFormula.html-----\nfunction poly3_root(rcf,limitL,limitR)\n implicit none\n real(wp) :: rcf(4), limitL, limitR\n real(wp) :: poly3_root\n real(wp) :: y1, y2, y3, factor, phi\n real(wp) :: q, r, det, s, t\n complex(wp) :: y2i, y3i\n integer :: i\n \n! rcf=cf/cf(1) ! coefficient in front of x^3 is set to one \n q=(3.0d0*rcf(3)-rcf(2)**2.0d0)/9.0d0\n r=(-2.0d0*rcf(2)**3.0d0+9.0d0*rcf(2)*rcf(3)-27.0d0*rcf(4))/54.0d0\n det=q**3.0d0+r**2.0d0\n \n if (det.gt.0.0d0) then !Only one real root\n s=r+sqrt(det)\n if (s.lt.0.0d0) then\n s=-((ABS(s))**(1.0d0/3.0d0))\n else\n s=s**(1.0d0/3.0d0)\n endif\n t=r-sqrt(det)\n if (t.lt.0.0d0) then\n t=-(ABS(t)**(1.0d0/3.0d0))\n else\n t=t**(1.0d0/3.0d0)\n endif\n y1=-rcf(2)/3.0d0+s+t\n \n !!!!!!!!!!!!!SKIP COMPEX ROOTS!!!!!!!!!!!!!!!!!!!!!!!!!\n ! re=-rcf(2)/3.0d0-(s+t)/2.0d0\n ! im=(sqrt(3.0d0)/2.0d0)*(s-t)\n ! y2i=cmplx(re,im)\n ! y3i=cmplx(re,-im)\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n \n elseif (det.eq.0.0d0) then ! three real roots (two are equal)\n if (s.lt.0.0d0) then\n s=-((abs(r))**(1.0d0/3.0d0))\n else\n s=r**(1.0d0/3.0d0)\n endif\n y1=-rcf(2)/3.0d0+s*2.0d0\n y2=-rcf(2)/3.0d0-s\n y3=y2\n\n elseif (det.lt.0.0d0) then ! three real unequal roots \n phi=r/sqrt(abs(q**3.0d0))\n phi=1.0d0/(cos(phi))\n factor=2.0d0*sqrt(-q)\n y1=factor*cos(phi/3.0d0)-rcf(2)/3.0d0\n y2=factor*cos((phi+2.0d0*pi)/3.0d0)-rcf(2)/3.0d0\n y3=factor*cos((phi+4.0d0*pi)/3.0d0)-rcf(2)/3.0d0\n endif\n \n i=0 !number of roots\n if (det.gt.0.0d0) then !\n if (y1.gt.limitL .and. y1.lt.limitR) then\n poly3_root=y1\n i=i+1\n else\n call error_message(7)!error code in parentheses \n endif \n elseif (det.eq.0.0d0) then ! \n if (y1.gt.limitL .and. y1.lt.limitR) then\n poly3_root=y1\n i=i+1\n elseif (y2.gt.limitL .and. y2.lt.limitR) then\n poly3_root=y2 ! y3 is equal to y2, so there's no need to track y3\n i=i+1\n endif \n elseif (det.lt.0.0d0) then! \n if (y1.gt.limitL .and. y1.lt.limitR) then\n poly3_root=y1\n i=i+1\n elseif (y2.gt.limitL .and. y2.lt.limitR) then\n poly3_root=y2\n i=i+1\n elseif (y3.gt.limitL .and. y3.lt.limitR) then\n poly3_root=y3\n i=i+1\n else\n call error_message(8)!error code in parentheses \n endif \n endif\n \n if (i.gt.1) then !you have multiple crossings in region of interest \n call error_message(9)!error code in parentheses \n endif \nend function poly3_root\n\n\n!---------------------------------------------------------------------\n!---------------ROOTS ARE COMPUTED USING FERRARI'S METHOD-------------\n!----see details at https://en.wikipedia.org/wiki/Quartic_function---- \nfunction poly4_root(rcf,limitL,limitR)\n implicit none\n real(wp) :: rcf(5), limitL, limitR\n real(wp) :: poly4_root\n real(wp) :: a,b,c,d,e\n real(wp) :: p,q, dd,dd0,dd1,T,tmp\n complex(wp) :: S,x(4)\n integer :: i,j\n\n\n a=rcf(1) !simplify nottion for polynomial coefficients\n b=rcf(2)\n c=rcf(3)\n d=rcf(4)\n e=rcf(5)\n\n dd=256d0*e**3.0d0-192d0*b*d*e**2.0d0-128d0*c**2.0d0*e**2.0d0\n dd=dd+144*c*d**2.0d0*e-27d0*d**4.0d0+144*b**2.0d0*c*e**2.0d0\n dd=dd-6.0d0*b**2.0d0*d**2.d0*e-80.0d0*b*c**2.0d0*d*e\n dd=dd+18.0d0*b*c*d**3.0d0+16.0d0*c**4.0d0*e-4.0d0*c**3.0d0*d**2.0d0\n dd=dd-27.0d0*b**4.0d0*e**2.0d0+18.0d0*b**3.0d0*c*d*e\n dd=dd-4.0d0*b**3.0d0*d**3.0d0-4.0d0*b**2.0d0*c**3.0d0*e\n dd=dd+b**2.0d0*c**2.0d0*d**2.0d0\n\n dd0=c**2.0d0-3.0d0*b*d+12.0d0*e\n dd1=2.0d0*c**3.0d0-9.0d0*b*c*d+27.0d0*b**2.0d0*e\n dd1=dd1+27.0d0*d**2.0d0-72.0d0*c*e\n p=(8.0d0*c-3.0d0*b**2.0d0)/8\n q=(b**3.0d0+8.0d0*d-4.0d0*b*c)/8\n \n! if (dd.lt.0) then\n\n T=(sqrt(-27.0d0*dd)+dd1)/2\n if (T.lt.0.0d0) then \n T=-(abs(T)**(1.0d0/3.0d0))\n else \n T=T**(1.0d0/3.0d0)\n endif\n \n S=-2.0d0/3.0d0*p+(T+dd0/T)/3.0d0\n S=0.5d0*sqrt(S)\n\n!print *,'a,b,c,d,e',a,b,c,d,e\n!print *,'dd,dd1,dd0',dd,dd1,dd0\n!print *,'p,q,T,S',p,q,T,S\n\n x(1)=-4.0d0*S**2.0d0-2.0d0*p+q/S\n x(1)=-b/4.0d0-S+0.5d0*sqrt(x(1))\n\n x(2)=-4.0d0*S**2.0d0-2.0d0*p+q/S\n x(2)=-b/4.0d0-S-0.5d0*sqrt(x(2))\n\n x(3)=-4.0d0*S**2.0d0-2.0d0*p-q/S\n x(3)=-b/4.0d0+S+0.5d0*sqrt(x(3))\n\n x(4)=-4.0d0*S**2.0d0-2.0d0*p-q/S\n x(4)=-b/4.0d0+S-0.5d0*sqrt(x(4))\n\n!print *,'ROOOOOTS',x(1),x(2),x(3),x(4)\n!print *,'IMAG PART',aimag(x(3)),aimag(x(4))\n i=0\n do j=1,4\n if (aimag(x(j)).eq.0.0d0) then !real root\n tmp=real(x(j))\n!print *,'tmp',tmp\n if (tmp.gt.limitL .and. tmp.lt.limitR) then\n poly4_root=tmp\n i=i+1\n endif\n endif \n enddo\n!print *,'iiiiiiii',i\n!print *,'root',poly4_root\n \n if (i.gt.1) then !multiple crossings in the region of interest \n call error_message(9) \n elseif (i.eq.0) then !no crossings in the region of interest \n call error_message(8) \n endif \nend function poly4_root\n!---------------------------------------------------------------------\nend module root_module\n", "meta": {"hexsha": "282f5ff0b304c57b5f3070b4fbe7bb8f323e3c59", "size": 8201, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source/root.f90", "max_stars_repo_name": "svarganov/NAST", "max_stars_repo_head_hexsha": "7e87c4aeec03f84a895f4e7cc270db807ce514c1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "source/root.f90", "max_issues_repo_name": "svarganov/NAST", "max_issues_repo_head_hexsha": "7e87c4aeec03f84a895f4e7cc270db807ce514c1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-02-19T13:10:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-20T01:08:41.000Z", "max_forks_repo_path": "source/root.f90", "max_forks_repo_name": "svarganov/NAST", "max_forks_repo_head_hexsha": "7e87c4aeec03f84a895f4e7cc270db807ce514c1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-09-14T00:11:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-14T00:11:42.000Z", "avg_line_length": 29.8218181818, "max_line_length": 76, "alphanum_fraction": 0.5270089014, "num_tokens": 3256, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.7154239957834733, "lm_q1q2_score": 0.650969309546797}} {"text": " PROGRAM xsimpr\r\nC driver for routine simpr\r\n INTEGER NMAX,NVAR\r\n REAL HTOT,X1\r\n PARAMETER(NMAX=3,NVAR=3,X1=0.,HTOT=50.)\r\n INTEGER i\r\n REAL a1,a2,a3,y(NMAX),yout(NMAX),\r\n * dfdx(NMAX),dfdy(NMAX,NMAX),dydx(NMAX)\r\n EXTERNAL derivs\r\n y(1)=1.\r\n y(2)=1.\r\n y(3)=0.\r\n a1=0.5976\r\n a2=1.4023\r\n a3=0.\r\n call derivs(X1,y,dydx)\r\n call jacobn(X1,y,dfdx,dfdy,NVAR,NMAX)\r\n write(*,'(1x,a/)') 'Test Problem'\r\n do 11 i=5,50,5\r\n call simpr(y,dydx,dfdx,dfdy,NMAX,NVAR,X1,HTOT,i,yout,derivs)\r\n write(*,'(1x,a,f6.4,a,f7.4,a,i2,a)') 'X = ',X1,\r\n * ' to ',X1+HTOT,' in ',i,' steps'\r\n write(*,'(1x,t5,a,t20,a)') 'Integration','Answer'\r\n write(*,'(1x,2f12.6)') yout(1),a1\r\n write(*,'(1x,2f12.6)') yout(2),a2\r\n write(*,'(1x,2f12.6)') yout(3),a3\r\n11 continue\r\n END\r\n", "meta": {"hexsha": "75b35da79f55f18f45b0fc1550dee63837d09724", "size": 896, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xsimpr.for", "max_stars_repo_name": "DingdingLuan/nrfunctions_fortran", "max_stars_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xsimpr.for", "max_issues_repo_name": "DingdingLuan/nrfunctions_fortran", "max_issues_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Examples/xsimpr.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": 30.8965517241, "max_line_length": 69, "alphanum_fraction": 0.4988839286, "num_tokens": 372, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380481, "lm_q2_score": 0.7154239957834733, "lm_q1q2_score": 0.6509693060511172}} {"text": "module physics_constants\n\n use utils_constants\n\n public\n\n ! Basic physical constants of matter. The 10^-23 and 10^23 factors\n ! have been removed to ease calculations.\n\n ! Boltzman Constant - CODATA 2010\n real(8) , parameter :: boltzk = 1.380648813_r8\n ! Avogadro Constant - International Avogadro cohordination 2011\n real(8) , parameter :: navgdr = 6.0221407818_r8\n\n ! Gas constant in J/K/mol\n real(dp) , parameter :: rgasmol = boltzk*navgdr \n\n ! Molecular weight of water\n real(dp) , parameter :: watmolwgt = 18.01528_r8 ! g/mol\n ! Mean dry air molecular weight\n real(dp) , parameter :: airmolwgt = 28.96443_r8 ! g/mol\n ! Ratio of mean molecular weight of water to that of dry air\n real(dp) , parameter :: wgtfrac = watmolwgt/airmolwgt\n\n ! Gas constant for dry air in J/K/kg\n real(dp) , parameter :: rgas = (rgasmol/airmolwgt)*d_1000\n ! Gas constant for water in J/K/kg\n real(dp) , parameter :: rwat = (rgasmol/watmolwgt)*d_1000\n\n ! 0 C in Kelvin\n real(dp) , parameter :: tzero = 273.16_r8\n\n ! Standard Gravity (m/sec**2) 3rd CGPM\n real(dp) , parameter :: egrav = 9.80665_r8\n\n ! Earth radius in meters\n real(8) , parameter :: earthrad = 6.371229D+06\n real(8) , parameter :: erkm = earthrad/d_1000\n ! Angular velocity of rotation of Earth\n real(8) , parameter :: eomeg = 7.2921159D-05\n real(8) , parameter :: eomeg2 = d_2*eomeg\n\n ! Hydrostatic coefficient\n real(8) , parameter :: gmr = egrav*airmolwgt/rgasmol\n\n ! Specific heat at constant pressure for dry air J/kg/K\n real(dp) , parameter :: cpd = 1005.46_r8\n ! Specific heat at constant pressure for moist air J/kg/K\n real(dp) , parameter :: cpv = 1869.46_r8\n ! Specific heat of water at 15 Celsius J/kg/K\n real(dp) , parameter :: cpw = 4186.95_r8\n ! Specific heat of water at 0 Celsius J/kg/K\n real(dp) , parameter :: cpw0 = 4218.0_r8\n\n ! Derived\n real(dp) , parameter :: rgovrw = rgas/rwat\n real(dp) , parameter :: rwovrg = rwat/rgas\n real(dp) , parameter :: rgovcp = rgas/cpd\n real(dp) , parameter :: rgovg = rgas/egrav\n real(dp) , parameter :: govrg = egrav/rgas\n \n real(dp) , parameter :: regrav = d_1/egrav\n real(dp) , parameter :: rrgas = d_1/rgas\n real(dp) , parameter :: rcpd = d_1/cpd\n\nend module physics_constants\n", "meta": {"hexsha": "12e4bfa16d7de1ead14111c30f8ed45da4dfdd74", "size": 2230, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "reference/physics_constants.f90", "max_stars_repo_name": "ZanderZhao/msise00", "max_stars_repo_head_hexsha": "b602cf9779e27595485a59b0c9bb6d3f2138406b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 31, "max_stars_repo_stars_event_min_datetime": "2019-06-12T08:52:43.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T14:15:18.000Z", "max_issues_repo_path": "reference/physics_constants.f90", "max_issues_repo_name": "ZanderZhao/msise00", "max_issues_repo_head_hexsha": "b602cf9779e27595485a59b0c9bb6d3f2138406b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 17, "max_issues_repo_issues_event_min_datetime": "2019-06-10T16:18:57.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T18:34:21.000Z", "max_forks_repo_path": "reference/physics_constants.f90", "max_forks_repo_name": "ZanderZhao/msise00", "max_forks_repo_head_hexsha": "b602cf9779e27595485a59b0c9bb6d3f2138406b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2019-06-10T16:21:10.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-04T11:21:59.000Z", "avg_line_length": 33.2835820896, "max_line_length": 68, "alphanum_fraction": 0.6820627803, "num_tokens": 768, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380482, "lm_q2_score": 0.7154239897159438, "lm_q1q2_score": 0.6509693005302298}} {"text": "*> \\brief DPTSVX computes the solution to system of linear equations A * X = B for PT matrices\n*\n* =========== DOCUMENTATION ===========\n*\n* Online html documentation available at\n* http://www.netlib.org/lapack/explore-html/\n*\n*> \\htmlonly\n*> Download DPTSVX + dependencies\n*> \n*> [TGZ]\n*> \n*> [ZIP]\n*> \n*> [TXT]\n*> \\endhtmlonly\n*\n* Definition:\n* ===========\n*\n* SUBROUTINE DPTSVX( FACT, N, NRHS, D, E, DF, EF, B, LDB, X, LDX,\n* RCOND, FERR, BERR, WORK, INFO )\n*\n* .. Scalar Arguments ..\n* CHARACTER FACT\n* INTEGER INFO, LDB, LDX, N, NRHS\n* DOUBLE PRECISION RCOND\n* ..\n* .. Array Arguments ..\n* DOUBLE PRECISION B( LDB, * ), BERR( * ), D( * ), DF( * ),\n* $ E( * ), EF( * ), FERR( * ), WORK( * ),\n* $ X( LDX, * )\n* ..\n*\n*\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*>\n*> DPTSVX uses the factorization A = L*D*L**T to compute the solution\n*> to a real system of linear equations A*X = B, where A is an N-by-N\n*> symmetric positive definite tridiagonal matrix and X and B are\n*> N-by-NRHS matrices.\n*>\n*> Error bounds on the solution and a condition estimate are also\n*> provided.\n*> \\endverbatim\n*\n*> \\par Description:\n* =================\n*>\n*> \\verbatim\n*>\n*> The following steps are performed:\n*>\n*> 1. If FACT = 'N', the matrix A is factored as A = L*D*L**T, where L\n*> is a unit lower bidiagonal matrix and D is diagonal. The\n*> factorization can also be regarded as having the form\n*> A = U**T*D*U.\n*>\n*> 2. If the leading i-by-i principal minor is not positive definite,\n*> then the routine returns with INFO = i. Otherwise, the factored\n*> form of A is used to estimate the condition number of the matrix\n*> A. If the reciprocal of the condition number is less than machine\n*> precision, INFO = N+1 is returned as a warning, but the routine\n*> still goes on to solve for X and compute error bounds as\n*> described below.\n*>\n*> 3. The system of equations is solved for X using the factored form\n*> of A.\n*>\n*> 4. Iterative refinement is applied to improve the computed solution\n*> matrix and calculate error bounds and backward error estimates\n*> for it.\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in] FACT\n*> \\verbatim\n*> FACT is CHARACTER*1\n*> Specifies whether or not the factored form of A has been\n*> supplied on entry.\n*> = 'F': On entry, DF and EF contain the factored form of A.\n*> D, E, DF, and EF will not be modified.\n*> = 'N': The matrix A will be copied to DF and EF and\n*> factored.\n*> \\endverbatim\n*>\n*> \\param[in] N\n*> \\verbatim\n*> N is INTEGER\n*> The order of the matrix A. N >= 0.\n*> \\endverbatim\n*>\n*> \\param[in] NRHS\n*> \\verbatim\n*> NRHS is INTEGER\n*> The number of right hand sides, i.e., the number of columns\n*> of the matrices B and X. NRHS >= 0.\n*> \\endverbatim\n*>\n*> \\param[in] D\n*> \\verbatim\n*> D is DOUBLE PRECISION array, dimension (N)\n*> The n diagonal elements of the tridiagonal matrix A.\n*> \\endverbatim\n*>\n*> \\param[in] E\n*> \\verbatim\n*> E is DOUBLE PRECISION array, dimension (N-1)\n*> The (n-1) subdiagonal elements of the tridiagonal matrix A.\n*> \\endverbatim\n*>\n*> \\param[in,out] DF\n*> \\verbatim\n*> DF is DOUBLE PRECISION array, dimension (N)\n*> If FACT = 'F', then DF is an input argument and on entry\n*> contains the n diagonal elements of the diagonal matrix D\n*> from the L*D*L**T factorization of A.\n*> If FACT = 'N', then DF is an output argument and on exit\n*> contains the n diagonal elements of the diagonal matrix D\n*> from the L*D*L**T factorization of A.\n*> \\endverbatim\n*>\n*> \\param[in,out] EF\n*> \\verbatim\n*> EF is DOUBLE PRECISION array, dimension (N-1)\n*> If FACT = 'F', then EF is an input argument and on entry\n*> contains the (n-1) subdiagonal elements of the unit\n*> bidiagonal factor L from the L*D*L**T factorization of A.\n*> If FACT = 'N', then EF is an output argument and on exit\n*> contains the (n-1) subdiagonal elements of the unit\n*> bidiagonal factor L from the L*D*L**T factorization of A.\n*> \\endverbatim\n*>\n*> \\param[in] B\n*> \\verbatim\n*> B is DOUBLE PRECISION array, dimension (LDB,NRHS)\n*> The N-by-NRHS right hand side matrix B.\n*> \\endverbatim\n*>\n*> \\param[in] LDB\n*> \\verbatim\n*> LDB is INTEGER\n*> The leading dimension of the array B. LDB >= max(1,N).\n*> \\endverbatim\n*>\n*> \\param[out] X\n*> \\verbatim\n*> X is DOUBLE PRECISION array, dimension (LDX,NRHS)\n*> If INFO = 0 of INFO = N+1, the N-by-NRHS solution matrix X.\n*> \\endverbatim\n*>\n*> \\param[in] LDX\n*> \\verbatim\n*> LDX is INTEGER\n*> The leading dimension of the array X. LDX >= max(1,N).\n*> \\endverbatim\n*>\n*> \\param[out] RCOND\n*> \\verbatim\n*> RCOND is DOUBLE PRECISION\n*> The reciprocal condition number of the matrix A. If RCOND\n*> is less than the machine precision (in particular, if\n*> RCOND = 0), the matrix is singular to working precision.\n*> This condition is indicated by a return code of INFO > 0.\n*> \\endverbatim\n*>\n*> \\param[out] FERR\n*> \\verbatim\n*> FERR is DOUBLE PRECISION array, dimension (NRHS)\n*> The forward error bound for each solution vector\n*> X(j) (the j-th column of the solution matrix X).\n*> If XTRUE is the true solution corresponding to X(j), FERR(j)\n*> is an estimated upper bound for the magnitude of the largest\n*> element in (X(j) - XTRUE) divided by the magnitude of the\n*> largest element in X(j).\n*> \\endverbatim\n*>\n*> \\param[out] BERR\n*> \\verbatim\n*> BERR is DOUBLE PRECISION array, dimension (NRHS)\n*> The componentwise relative backward error of each solution\n*> vector X(j) (i.e., the smallest relative change in any\n*> element of A or B that makes X(j) an exact solution).\n*> \\endverbatim\n*>\n*> \\param[out] WORK\n*> \\verbatim\n*> WORK is DOUBLE PRECISION array, dimension (2*N)\n*> \\endverbatim\n*>\n*> \\param[out] INFO\n*> \\verbatim\n*> INFO is INTEGER\n*> = 0: successful exit\n*> < 0: if INFO = -i, the i-th argument had an illegal value\n*> > 0: if INFO = i, and i is\n*> <= N: the leading minor of order i of A is\n*> not positive definite, so the factorization\n*> could not be completed, and the solution has not\n*> been computed. RCOND = 0 is returned.\n*> = N+1: U is nonsingular, but RCOND is less than machine\n*> precision, meaning that the matrix is singular\n*> to working precision. Nevertheless, the\n*> solution and error bounds are computed because\n*> there are a number of situations where the\n*> computed solution can be more accurate than the\n*> value of RCOND would suggest.\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee\n*> \\author Univ. of California Berkeley\n*> \\author Univ. of Colorado Denver\n*> \\author NAG Ltd.\n*\n*> \\ingroup doublePTsolve\n*\n* =====================================================================\n SUBROUTINE DPTSVX( FACT, N, NRHS, D, E, DF, EF, B, LDB, X, LDX,\n $ RCOND, FERR, BERR, WORK, INFO )\n*\n* -- LAPACK driver routine --\n* -- LAPACK is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n*\n* .. Scalar Arguments ..\n CHARACTER FACT\n INTEGER INFO, LDB, LDX, N, NRHS\n DOUBLE PRECISION RCOND\n* ..\n* .. Array Arguments ..\n DOUBLE PRECISION B( LDB, * ), BERR( * ), D( * ), DF( * ),\n $ E( * ), EF( * ), FERR( * ), WORK( * ),\n $ X( LDX, * )\n* ..\n*\n* =====================================================================\n*\n* .. Parameters ..\n DOUBLE PRECISION ZERO\n PARAMETER ( ZERO = 0.0D+0 )\n* ..\n* .. Local Scalars ..\n LOGICAL NOFACT\n DOUBLE PRECISION ANORM\n* ..\n* .. External Functions ..\n LOGICAL LSAME\n DOUBLE PRECISION DLAMCH, DLANST\n EXTERNAL LSAME, DLAMCH, DLANST\n* ..\n* .. External Subroutines ..\n EXTERNAL DCOPY, DLACPY, DPTCON, DPTRFS, DPTTRF, DPTTRS,\n $ XERBLA\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC MAX\n* ..\n* .. Executable Statements ..\n*\n* Test the input parameters.\n*\n INFO = 0\n NOFACT = LSAME( FACT, 'N' )\n IF( .NOT.NOFACT .AND. .NOT.LSAME( FACT, 'F' ) ) THEN\n INFO = -1\n ELSE IF( N.LT.0 ) THEN\n INFO = -2\n ELSE IF( NRHS.LT.0 ) THEN\n INFO = -3\n ELSE IF( LDB.LT.MAX( 1, N ) ) THEN\n INFO = -9\n ELSE IF( LDX.LT.MAX( 1, N ) ) THEN\n INFO = -11\n END IF\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'DPTSVX', -INFO )\n RETURN\n END IF\n*\n IF( NOFACT ) THEN\n*\n* Compute the L*D*L**T (or U**T*D*U) factorization of A.\n*\n CALL DCOPY( N, D, 1, DF, 1 )\n IF( N.GT.1 )\n $ CALL DCOPY( N-1, E, 1, EF, 1 )\n CALL DPTTRF( N, DF, EF, INFO )\n*\n* Return if INFO is non-zero.\n*\n IF( INFO.GT.0 )THEN\n RCOND = ZERO\n RETURN\n END IF\n END IF\n*\n* Compute the norm of the matrix A.\n*\n ANORM = DLANST( '1', N, D, E )\n*\n* Compute the reciprocal of the condition number of A.\n*\n CALL DPTCON( N, DF, EF, ANORM, RCOND, WORK, INFO )\n*\n* Compute the solution vectors X.\n*\n CALL DLACPY( 'Full', N, NRHS, B, LDB, X, LDX )\n CALL DPTTRS( N, NRHS, DF, EF, X, LDX, INFO )\n*\n* Use iterative refinement to improve the computed solutions and\n* compute error bounds and backward error estimates for them.\n*\n CALL DPTRFS( N, NRHS, D, E, DF, EF, B, LDB, X, LDX, FERR, BERR,\n $ WORK, INFO )\n*\n* Set INFO = N+1 if the matrix is singular to working precision.\n*\n IF( RCOND.LT.DLAMCH( 'Epsilon' ) )\n $ INFO = N + 1\n*\n RETURN\n*\n* End of DPTSVX\n*\n END\n", "meta": {"hexsha": "7fb6cf4365d003660d6b4bc42ba68f8e670100d0", "size": 10883, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "SRC/dptsvx.f", "max_stars_repo_name": "sergey-v-kuznetsov/lapack", "max_stars_repo_head_hexsha": "799ef93faa5878aa8702f7cf9980cfc649cc39cc", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 998, "max_stars_repo_stars_event_min_datetime": "2016-05-04T20:50:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T17:43:13.000Z", "max_issues_repo_path": "SRC/dptsvx.f", "max_issues_repo_name": "sergey-v-kuznetsov/lapack", "max_issues_repo_head_hexsha": "799ef93faa5878aa8702f7cf9980cfc649cc39cc", "max_issues_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_issues_count": 603, "max_issues_repo_issues_event_min_datetime": "2016-06-04T07:28:21.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T21:16:50.000Z", "max_forks_repo_path": "SRC/dptsvx.f", "max_forks_repo_name": "sergey-v-kuznetsov/lapack", "max_forks_repo_head_hexsha": "799ef93faa5878aa8702f7cf9980cfc649cc39cc", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 373, "max_forks_repo_forks_event_min_datetime": "2016-06-04T06:05:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T17:25:45.000Z", "avg_line_length": 32.5838323353, "max_line_length": 111, "alphanum_fraction": 0.552329321, "num_tokens": 3058, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.7154239836484143, "lm_q1q2_score": 0.6509692985050218}} {"text": " FUNCTION BESSI0(X)\n REAL*8 Y,P1,P2,P3,P4,P5,P6,P7,\n * Q1,Q2,Q3,Q4,Q5,Q6,Q7,Q8,Q9\n DATA P1,P2,P3,P4,P5,P6,P7/1.0D0,3.5156229D0,3.0899424D0,1.2067492D\n *0,\n * 0.2659732D0,0.360768D-1,0.45813D-2/\n DATA Q1,Q2,Q3,Q4,Q5,Q6,Q7,Q8,Q9/0.39894228D0,0.1328592D-1,\n * 0.225319D-2,-0.157565D-2,0.916281D-2,-0.2057706D-1,\n * 0.2635537D-1,-0.1647633D-1,0.392377D-2/\n IF (ABS(X).LT.3.75) THEN\n Y=(X/3.75)**2\n BESSI0=P1+Y*(P2+Y*(P3+Y*(P4+Y*(P5+Y*(P6+Y*P7)))))\n ELSE\n AX=ABS(X)\n Y=3.75/AX\n BESSI0=(EXP(AX)/SQRT(AX))*(Q1+Y*(Q2+Y*(Q3+Y*(Q4\n * +Y*(Q5+Y*(Q6+Y*(Q7+Y*(Q8+Y*Q9))))))))\n ENDIF\n RETURN\n END\n", "meta": {"hexsha": "5b45a0940789646c7f6b0445b1d98358c37637d5", "size": 703, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "Math3/NumRec/source/bessi0.for", "max_stars_repo_name": "domijin/MM3", "max_stars_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Math3/NumRec/source/bessi0.for", "max_issues_repo_name": "domijin/MM3", "max_issues_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Math3/NumRec/source/bessi0.for", "max_forks_repo_name": "domijin/MM3", "max_forks_repo_head_hexsha": "cf696d0cf26ea8e8e24c86287cf8856cab7eaf77", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.4761904762, "max_line_length": 72, "alphanum_fraction": 0.5135135135, "num_tokens": 384, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.935346511643776, "lm_q2_score": 0.6959583250334526, "lm_q1q2_score": 0.6509621915694851}} {"text": "program Cipher\n implicit none\n ! define a defualt value for the key\n integer :: offset = 10 \n\n ! Input string to be encrypted \n character(3) :: str = 'HAL'\n character(3) :: og = ''\n character(3) :: encrypted = ''\n og = str\n\n write(*, '(2a)') 'Original string = '//og\n \n ! Call the encrypt and concat using `//` <= why would they choose that!\n call encrypt(str, offset)\n write(*, '(2a)') 'Encrypt: '//og//' => '//str\n ! Store the encrypted value\n encrypted = str\n ! Repeat the proccess for decryption \n call decrypt(str, offset)\n write(*, '(2a)') 'Decrypted: '//encrypted//' => '//str\n\n ! encrypt for [0,26]\n call solve(str, og)\n \n \ncontains\n \nsubroutine encrypt(text, shift)\n character(*), intent(inout) :: text\n integer :: shift\n integer :: i\n\n ! do loop, iterate through the string\n do i = 1, len(text)\n select case(text(i:i))\n case ('A':'Z')\n ! use ascii code and add the shift....thank you stack overflow\n text(i:i) = achar(modulo(iachar(text(i:i)) - 65 + shift, 26) + 65)\n case ('a':'z')\n ! do the same for lowercase leters\n text(i:i) = achar(modulo(iachar(text(i:i)) - 97 + shift, 26) + 97)\n end select\n end do\nend subroutine\n \nsubroutine decrypt(text, shift)\n character(*), intent(inout) :: text\n integer :: shift\n integer :: i\n \n do i = 1, len(text)\n select case(text(i:i))\n case ('A':'Z')\n ! subtract the same shift interval\n text(i:i) = achar(modulo(iachar(text(i:i)) - 65 - shift, 26) + 65)\n case ('a':'z')\n ! do the same for the lil letters\n text(i:i) = achar(modulo(iachar(text(i:i)) - 97 - shift, 26) + 97)\n end select\n end do\nend subroutine\n\nsubroutine solve(text, og)\n character(*), intent(inout) :: text\n character(*), intent(inout) :: og\n character(4) :: key\n integer :: i\n \n ! The easy part.....call encrypt 27 times\n do i = 0, 26\n text = og\n call encrypt(text, i)\n ! convert int to string.....I miss .lower()\n write(key, '(I2)') i \n ! trim the key because it gets weird otherwise\n write(*, '(2a)') 'Key:'//trim(key)//' => '//text\n end do\nend subroutine\n \nend program Cipher", "meta": {"hexsha": "195a49e23d9cc248775d40250204495ec5829f5d", "size": 2143, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran/Cipher.f90", "max_stars_repo_name": "dgisolfi/CaesarCiphersCMPT331", "max_stars_repo_head_hexsha": "d74f6542127e8b0fe3fe60f98ac7d27e916f9f57", "max_stars_repo_licenses": ["MIT"], "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/Cipher.f90", "max_issues_repo_name": "dgisolfi/CaesarCiphersCMPT331", "max_issues_repo_head_hexsha": "d74f6542127e8b0fe3fe60f98ac7d27e916f9f57", "max_issues_repo_licenses": ["MIT"], "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/Cipher.f90", "max_forks_repo_name": "dgisolfi/CaesarCiphersCMPT331", "max_forks_repo_head_hexsha": "d74f6542127e8b0fe3fe60f98ac7d27e916f9f57", "max_forks_repo_licenses": ["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.4567901235, "max_line_length": 74, "alphanum_fraction": 0.5912272515, "num_tokens": 652, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8031737963569016, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.6509554164288822}} {"text": "! hilbert transform\n\n\nuse MathClass\nuse ArrayClass\nuse IOClass\nimplicit none\n\ntype(Math_) :: math\ntype(IO_) :: f\ntype(Random_) :: random\ncomplex(complex64),allocatable :: t(:), wave(:), h_top_wave(:)&\n ,h_bottom_wave(:),spectre(:),t_w(:,:)\nreal(real64) :: omega_1\nreal(real64) :: omega_2\n\n\nomega_1=0.10d0/math%pi\nomega_2=0.3d0/math%pi\n\nt = linspace([0.0d0,1000.0d0],1024)\nwave = sin(omega_1*t(:)) * 0.30d0*sin(omega_2*t(:) +2.0d0)* exp(-omega_1/10.0d0*t(:) ) +0.40d0*sin(omega_1*20.0d0*t(:)) \nwave(500:550) = wave(500:550) +0.80d0*sin(omega_1*80.0d0*t(500:550)) \n\ndo i_i=700,750\n wave(i_i) = wave(i_i) + random%gauss(mu=0.0d0,sigma=1.0d0)\nenddo\nwave(400:450) = wave(400:450)*2.0d0\n\ncall f%open(\"input_wave.txt\")\ncall f%write(abs(t),real(wave) )\ncall f%close()\ncall f%plot(option=\"with lines\")\n\nt_w = short_time_FFT(wave,128)\n\ncall f%open(\"result.txt\")\ndo i_i=1,size(t_w,1)\n do j_j=1,size(t_w,2)/2\n write(f%fh,*) i_i,j_j,abs(t_w(i_i,j_j))\n enddo\n write(f%fh,*) \" \"\nenddo\ncall f%close()\ncall f%splot(option=\"with lines\")\n\n\nend ", "meta": {"hexsha": "03ce8dfe4dd908b50783021241428fc0167f1417", "size": 1051, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Tutorial/spectrogram.f90", "max_stars_repo_name": "kazulagi/faba", "max_stars_repo_head_hexsha": "7ef140f1ebea0e0ca496d14fdb94a3c024393cfa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-05T06:04:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:04:25.000Z", "max_issues_repo_path": "Tutorial/std/spectrogram.f90", "max_issues_repo_name": "kazulagi/plantFEM_binary", "max_issues_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Tutorial/std/spectrogram.f90", "max_forks_repo_name": "kazulagi/plantFEM_binary", "max_forks_repo_head_hexsha": "32acf059a6d778307211718c2a512ff796b81c52", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.8958333333, "max_line_length": 120, "alphanum_fraction": 0.6555661275, "num_tokens": 439, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206686206199, "lm_q2_score": 0.7217432182679956, "lm_q1q2_score": 0.6509551259926686}} {"text": "*> \\brief \\b SLQT02\n*\n* =========== DOCUMENTATION ===========\n*\n* Online html documentation available at\n* http://www.netlib.org/lapack/explore-html/\n*\n* Definition:\n* ===========\n*\n* SUBROUTINE SLQT02( M, N, K, A, AF, Q, L, LDA, TAU, WORK, LWORK,\n* RWORK, RESULT )\n*\n* .. Scalar Arguments ..\n* INTEGER K, LDA, LWORK, M, N\n* ..\n* .. Array Arguments ..\n* REAL A( LDA, * ), AF( LDA, * ), L( LDA, * ),\n* $ Q( LDA, * ), RESULT( * ), RWORK( * ), TAU( * ),\n* $ WORK( LWORK )\n* ..\n*\n*\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*>\n*> SLQT02 tests SORGLQ, which generates an m-by-n matrix Q with\n*> orthonornmal rows that is defined as the product of k elementary\n*> reflectors.\n*>\n*> Given the LQ factorization of an m-by-n matrix A, SLQT02 generates\n*> the orthogonal matrix Q defined by the factorization of the first k\n*> rows of A; it compares L(1:k,1:m) with A(1:k,1:n)*Q(1:m,1:n)', and\n*> checks that the rows of Q are orthonormal.\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in] M\n*> \\verbatim\n*> M is INTEGER\n*> The number of rows of the matrix Q to be generated. M >= 0.\n*> \\endverbatim\n*>\n*> \\param[in] N\n*> \\verbatim\n*> N is INTEGER\n*> The number of columns of the matrix Q to be generated.\n*> N >= M >= 0.\n*> \\endverbatim\n*>\n*> \\param[in] K\n*> \\verbatim\n*> K is INTEGER\n*> The number of elementary reflectors whose product defines the\n*> matrix Q. M >= K >= 0.\n*> \\endverbatim\n*>\n*> \\param[in] A\n*> \\verbatim\n*> A is REAL array, dimension (LDA,N)\n*> The m-by-n matrix A which was factorized by SLQT01.\n*> \\endverbatim\n*>\n*> \\param[in] AF\n*> \\verbatim\n*> AF is REAL array, dimension (LDA,N)\n*> Details of the LQ factorization of A, as returned by SGELQF.\n*> See SGELQF for further details.\n*> \\endverbatim\n*>\n*> \\param[out] Q\n*> \\verbatim\n*> Q is REAL array, dimension (LDA,N)\n*> \\endverbatim\n*>\n*> \\param[out] L\n*> \\verbatim\n*> L is REAL array, dimension (LDA,M)\n*> \\endverbatim\n*>\n*> \\param[in] LDA\n*> \\verbatim\n*> LDA is INTEGER\n*> The leading dimension of the arrays A, AF, Q and L. LDA >= N.\n*> \\endverbatim\n*>\n*> \\param[in] TAU\n*> \\verbatim\n*> TAU is REAL array, dimension (M)\n*> The scalar factors of the elementary reflectors corresponding\n*> to the LQ factorization in AF.\n*> \\endverbatim\n*>\n*> \\param[out] WORK\n*> \\verbatim\n*> WORK is REAL array, dimension (LWORK)\n*> \\endverbatim\n*>\n*> \\param[in] LWORK\n*> \\verbatim\n*> LWORK is INTEGER\n*> The dimension of the array WORK.\n*> \\endverbatim\n*>\n*> \\param[out] RWORK\n*> \\verbatim\n*> RWORK is REAL array, dimension (M)\n*> \\endverbatim\n*>\n*> \\param[out] RESULT\n*> \\verbatim\n*> RESULT is REAL array, dimension (2)\n*> The test ratios:\n*> RESULT(1) = norm( L - A*Q' ) / ( N * norm(A) * EPS )\n*> RESULT(2) = norm( I - Q*Q' ) / ( N * EPS )\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee\n*> \\author Univ. of California Berkeley\n*> \\author Univ. of Colorado Denver\n*> \\author NAG Ltd.\n*\n*> \\ingroup single_lin\n*\n* =====================================================================\n SUBROUTINE SLQT02( M, N, K, A, AF, Q, L, LDA, TAU, WORK, LWORK,\n $ RWORK, RESULT )\n*\n* -- LAPACK test routine --\n* -- LAPACK is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n*\n* .. Scalar Arguments ..\n INTEGER K, LDA, LWORK, M, N\n* ..\n* .. Array Arguments ..\n REAL A( LDA, * ), AF( LDA, * ), L( LDA, * ),\n $ Q( LDA, * ), RESULT( * ), RWORK( * ), TAU( * ),\n $ WORK( LWORK )\n* ..\n*\n* =====================================================================\n*\n* .. Parameters ..\n REAL ZERO, ONE\n PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 )\n REAL ROGUE\n PARAMETER ( ROGUE = -1.0E+10 )\n* ..\n* .. Local Scalars ..\n INTEGER INFO\n REAL ANORM, EPS, RESID\n* ..\n* .. External Functions ..\n REAL SLAMCH, SLANGE, SLANSY\n EXTERNAL SLAMCH, SLANGE, SLANSY\n* ..\n* .. External Subroutines ..\n EXTERNAL SGEMM, SLACPY, SLASET, SORGLQ, SSYRK\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC MAX, REAL\n* ..\n* .. Scalars in Common ..\n CHARACTER*32 SRNAMT\n* ..\n* .. Common blocks ..\n COMMON / SRNAMC / SRNAMT\n* ..\n* .. Executable Statements ..\n*\n EPS = SLAMCH( 'Epsilon' )\n*\n* Copy the first k rows of the factorization to the array Q\n*\n CALL SLASET( 'Full', M, N, ROGUE, ROGUE, Q, LDA )\n CALL SLACPY( 'Upper', K, N-1, AF( 1, 2 ), LDA, Q( 1, 2 ), LDA )\n*\n* Generate the first n columns of the matrix Q\n*\n SRNAMT = 'SORGLQ'\n CALL SORGLQ( M, N, K, Q, LDA, TAU, WORK, LWORK, INFO )\n*\n* Copy L(1:k,1:m)\n*\n CALL SLASET( 'Full', K, M, ZERO, ZERO, L, LDA )\n CALL SLACPY( 'Lower', K, M, AF, LDA, L, LDA )\n*\n* Compute L(1:k,1:m) - A(1:k,1:n) * Q(1:m,1:n)'\n*\n CALL SGEMM( 'No transpose', 'Transpose', K, M, N, -ONE, A, LDA, Q,\n $ LDA, ONE, L, LDA )\n*\n* Compute norm( L - A*Q' ) / ( N * norm(A) * EPS ) .\n*\n ANORM = SLANGE( '1', K, N, A, LDA, RWORK )\n RESID = SLANGE( '1', K, M, L, LDA, RWORK )\n IF( ANORM.GT.ZERO ) THEN\n RESULT( 1 ) = ( ( RESID / REAL( MAX( 1, N ) ) ) / ANORM ) / EPS\n ELSE\n RESULT( 1 ) = ZERO\n END IF\n*\n* Compute I - Q*Q'\n*\n CALL SLASET( 'Full', M, M, ZERO, ONE, L, LDA )\n CALL SSYRK( 'Upper', 'No transpose', M, N, -ONE, Q, LDA, ONE, L,\n $ LDA )\n*\n* Compute norm( I - Q*Q' ) / ( N * EPS ) .\n*\n RESID = SLANSY( '1', 'Upper', M, L, LDA, RWORK )\n*\n RESULT( 2 ) = ( RESID / REAL( MAX( 1, N ) ) ) / EPS\n*\n RETURN\n*\n* End of SLQT02\n*\n END\n", "meta": {"hexsha": "d59a8a01c59169137363d635ee47b79d955cdf68", "size": 6236, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "TESTING/LIN/slqt02.f", "max_stars_repo_name": "sergey-v-kuznetsov/lapack", "max_stars_repo_head_hexsha": "799ef93faa5878aa8702f7cf9980cfc649cc39cc", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 998, "max_stars_repo_stars_event_min_datetime": "2016-05-04T20:50:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T17:43:13.000Z", "max_issues_repo_path": "TESTING/LIN/slqt02.f", "max_issues_repo_name": "sergey-v-kuznetsov/lapack", "max_issues_repo_head_hexsha": "799ef93faa5878aa8702f7cf9980cfc649cc39cc", "max_issues_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_issues_count": 603, "max_issues_repo_issues_event_min_datetime": "2016-06-04T07:28:21.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T21:16:50.000Z", "max_forks_repo_path": "TESTING/LIN/slqt02.f", "max_forks_repo_name": "sergey-v-kuznetsov/lapack", "max_forks_repo_head_hexsha": "799ef93faa5878aa8702f7cf9980cfc649cc39cc", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 373, "max_forks_repo_forks_event_min_datetime": "2016-06-04T06:05:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T17:25:45.000Z", "avg_line_length": 27.350877193, "max_line_length": 76, "alphanum_fraction": 0.4879730597, "num_tokens": 1961, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206659843132, "lm_q2_score": 0.7217432182679956, "lm_q1q2_score": 0.6509551240899321}} {"text": "program l2norm\n implicit none\n integer :: n\n real, allocatable :: arr(:)\n\n print '(a)', \"Size of the vector: \"\n read *, n\n allocate(arr(n))\n print '(a)', \"Vector: \"\n read *, arr\n\n print '(a, g0)', \"L2-norm is \", norm2(arr)\n deallocate(arr)\nend program l2norm\n", "meta": {"hexsha": "25417c0e6aaf24c5e01150d30571ae82ea565ef9", "size": 299, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Lecture_01/l2norm/l2norm.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_01/l2norm/l2norm.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_01/l2norm/l2norm.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": 19.9333333333, "max_line_length": 46, "alphanum_fraction": 0.5384615385, "num_tokens": 90, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473879530491, "lm_q2_score": 0.7461389930307512, "lm_q1q2_score": 0.650892401620294}} {"text": "SUBROUTINE interp_orb3(mjd, NPint, rint, vint)\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! SUBROUTINE: interp_orb3.f90\r\n! ----------------------------------------------------------------------\r\n! Purpose:\r\n! GNSS sp3 orbit interpolation based on Lagrange polynomials\r\n! ----------------------------------------------------------------------\r\n! Input arguments:\r\n! - mjd:\t\t\tModified Julian Day number in GPS Time (including the fraction of the day)\r\n! - NPint:\t\t\tNumber of data points to be used for interpolation (defines the order of the polynomial)\r\n!\r\n! Input arguments (via module):\r\n! - orb3:\t\t\tOrbit array in ITRF including only the position vector per epoch\r\n! - orb4:\t\t\tOrbit array in ICRF including only the position vector per epoch\r\n! - mdl_arr.f90: \tModule used for the declaration of orb4 variable as allocatable array\r\n!\r\n! Output arguments:\r\n! - rint: \t\tPosition vector at the input epoch based on orbit interpolation \r\n! - vint: \t\tVelocity vector at the input epoch based on orbit interpolation \r\n! ----------------------------------------------------------------------\r\n! Dr. Thomas Papanikolaou\r\n! Cooperative Research Centre for Spatial Information, Australia\r\n! Created: 27 June 2017\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n USE mdl_precision\r\n USE mdl_num\r\n USE mdl_arr\r\n USE mdl_write\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) :: mjd\r\n INTEGER (KIND = prec_int8), INTENT(IN) :: NPint\r\n! OUT\r\n REAL (KIND = prec_d), INTENT(OUT) :: rint(3), vint(3)\r\n! ----------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n! Local variables declaration\r\n! ----------------------------------------------------------------------\r\n INTEGER (KIND = prec_int8) :: sz1, sz2 \r\n INTEGER (KIND = prec_int8) :: NPint_1, NPint_2 \r\n\t INTEGER (KIND = prec_int8) :: i, j, i1, i2, i0\r\n\t REAL (KIND = prec_d) :: tepoch, torb_1, torb_max \r\n\t REAL (KIND = prec_d) :: SecDay_i, MJD_i \r\n\t REAL (KIND = prec_d) :: dmjd, dsec \r\n\t REAL (KIND = prec_d) :: MJD_tint, tint, Xint, Xint_1, Yint, Yint_1, Zint, Zint_1\r\n\t REAL (KIND = prec_d) :: X, Y, Z, Vx, Vy, Vz\r\n INTEGER (KIND = prec_int2) :: AllocateStatus, DeAllocateStatus\r\n! ----------------------------------------------------------------------\r\n REAL (KIND = prec_q), DIMENSION(:,:), ALLOCATABLE :: orbint \r\n\r\n\r\n\t \r\n\t \r\n! ----------------------------------------------------------------------\r\n! Orbit array to be applied:\r\n! ----------------------------------------------------------------------\r\n! 'orb3' global variable via module mdl_arr.f90 \r\nsz1 = size(orb3, DIM = 1)\r\nsz2 = size(orb3, DIM = 2)\r\n! ----------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n! Allocatable array: Orbit to be applied for the data points required for the numerical interpolation\r\nALLOCATE (orbint(sz1, sz2) , STAT = AllocateStatus)\r\n! ----------------------------------------------------------------------\r\n\r\norbint = orb3\r\n\r\n\r\n\r\nsz1 = size(orbint, DIM = 1)\r\nsz2 = size(orbint, DIM = 2)\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! Conditions epochs\r\ntepoch = mjd\r\ntorb_1 = orbint(1,1)\r\ntorb_max = orbint(sz1,1)\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n! Allocatable arrays for Lagrange Interpolation (declared in mdl_arr.f90)\r\nALLOCATE (X_interp(NPint), STAT = AllocateStatus)\r\nALLOCATE (Y_interp(NPint), STAT = AllocateStatus)\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! Number of data points (used for the interpolation) before and after of the orbit point closest to the computation epoch\t \r\nNPint_1 = INT(NPint/2) \r\nNPint_2 = NPint - NPint_1 \r\n! ----------------------------------------------------------------------\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! Form arrays with data points to be used in the interpolation\t\t\r\n! ----------------------------------------------------------------------\r\nIf ( tepoch <= torb_1 ) then\r\n! Extrapolation (backward in time): Computation epoch is before the first epoch of the orbit array\r\n\r\n! Interpolation arrays indicators\r\ni1 = 1\r\ni2 = 1 + (NPint - 1)\r\n\r\ni0 = i1\r\n!Else If ( tepoch == torb_1 ) then\r\n\r\n\r\nElse If ( tepoch>torb_1 .and. tepoch <= orbint( NPint_1 ,1) ) Then\t\r\n! Interpolation arrays indicators\r\ni1 = 1\r\ni2 = 1 + (NPint - 1)\r\n\r\ni0 = i1\r\n\r\nElse If ( tepoch > orbint( NPint_1 ,1) .and. tepoch < orbint(sz1-NPint_2 , 1) ) Then\t\r\n! Find orbit epoch that is the closest smaller to the interpolation epoch \r\n DO j = NPint_1 , sz1-1\r\n !if (tepoch > orbint(j,1) .and. tepoch < orbint(j+1,1)) then\r\n if (tepoch > orbint(j,1)) then \r\n\t IF (tepoch < orbint(j+1,1) ) then\r\n\t i = j\r\n\r\n\t\t ! Interpolation arrays indicators\r\n i1 = i - (NPint_1 - 1)\r\n i2 = i + NPint_2\r\n\t\t \r\n\t EXIT\r\n\t\tend if \r\n\t end IF\r\n End Do\r\n\t\r\ni0 = i\r\n\t\r\nElse If ( tepoch >= orbint(sz1-NPint_2 , 1) ) Then\r\n! Interpolation arrays indicators\r\ni1 = sz1 - (NPint - 1)\r\ni2 = sz1\r\n\r\ni0 = i1\r\n\t \r\nElse If ( tepoch > orbint(sz1 , 1) ) Then\r\n! Interpolation arrays indicators\r\ni1 = sz1 - (NPint - 1)\r\ni2 = sz1\r\n\r\ni0 = i1\r\n\r\nEnd IF\t \r\n! ----------------------------------------------------------------------\r\n\r\n!print *,\"i1\",i1\r\n!print *,\"i2\",i2\r\n!print *,\"i0\",i0\r\n!print *,\"tepoch\",tepoch\r\n!print *,\"torb_1\",torb_1\r\n!print *,\"orbint( NPint_1 ,1)\",orbint( NPint_1 ,1)\r\n!print *,\"orbint(sz1-NPint_2 , 1)\",orbint(sz1-NPint_2 , 1)\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! Time array of the data points used for the interpolation\r\n! ----------------------------------------------------------------------\r\n! Time array in seconds (Sec of Day)\r\nX_interp = orbint(i1:i2, 2)\t\r\n! ----------------------------------------------------------------------\r\n\r\n! ----------------------------------------------------------------------\r\n! Interpolation epoch \r\n! ----------------------------------------------------------------------\r\n! Time difference (in days)\r\n!dmjd = (mjd - orbint(i1,1))\r\n\r\n! Time difference (in seconds)\r\n!dsec = dmjd * 86400.D0 \r\n\r\n! Interpolation epoch in seconds\r\n!tint = X_interp(1) + dsec\r\n\r\n! ----------------------------------------------------------------------\r\n! Time difference (in days)\r\ndmjd = (mjd - orbint(i0,1))\r\n\r\n! Time difference (in seconds)\r\ndsec = dmjd * 86400.D0 \r\n\r\n! Interpolation epoch in seconds\r\ntint = orbint(i0,2) + dsec\r\n! ----------------------------------------------------------------------\r\n\r\n!print *,\"dsec\",dsec\r\n!print *,\"tint\",tint\r\n!print *,\"X_interp\",X_interp\r\n\r\n\t\t\r\n\r\n! ----------------------------------------------------------------------\r\n! Position and Velocity Vectors\r\n! ----------------------------------------------------------------------\r\n! X\r\nY_interp = orbint(i1:i2, 3)\t\t\r\nCall interp_lag(tint, Xint)\r\n\r\n! Vx\r\nCall interp_lag(tint-1.D0, Xint_1) \r\n!Vx = Xint_1 - Xint \r\nVx = Xint - Xint_1 \r\n\t\t\t\r\n! Y\r\nY_interp = orbint(i1:i2, 4)\r\nCall interp_lag(tint, Yint) \r\n\r\n! Vy\r\nCall interp_lag(tint-1.D0, Yint_1) \r\n!Vy = Yint_1 - Yint\r\nVy = Yint - Yint_1\r\n\t\t\t\r\n! Z\r\nY_interp = orbint(i1:i2, 5)\r\nCall interp_lag(tint, Zint) \r\n\r\n! Vz\r\nCall interp_lag(tint-1.D0, Zint_1) \r\n!Vz = Zint_1 - Zint\r\nVz = Zint - Zint_1\t \r\n! ----------------------------------------------------------------------\r\n\r\n\r\n! ----------------------------------------------------------------------\r\n! Write state vector coordinates to output arguments\r\nrint(1) = Xint\r\nrint(2) = Yint\r\nrint(3) = Zint\r\n\r\nvint(1) = Vx\r\nvint(2) = Vy\r\nvint(3) = Vz\r\n! ----------------------------------------------------------------------\r\n\r\n\r\n! Deallocation\r\nDEALLOCATE (orbint, STAT = DeAllocateStatus)\r\nDeallocate (X_interp)\t \r\nDeallocate (Y_interp)\t \r\n\r\n\r\n\r\nEnd subroutine\r\n\r\n", "meta": {"hexsha": "df69228eeda2ad3547c1c2d10d1025d5351ccfc6", "size": 8182, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/interp_orb3.f90", "max_stars_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_stars_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 73, "max_stars_repo_stars_event_min_datetime": "2021-07-08T23:35:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T15:17:58.000Z", "max_issues_repo_path": "src/fortran/interp_orb3.f90", "max_issues_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_issues_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2021-09-27T14:27:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T23:50:02.000Z", "max_forks_repo_path": "src/fortran/interp_orb3.f90", "max_forks_repo_name": "RodrigoNaves/ginan-bitbucket-update-tests", "max_forks_repo_head_hexsha": "4bd5cc0a9dd0e94b1c2d8b35385e128404009b0c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 39, "max_forks_repo_forks_event_min_datetime": "2021-07-12T05:42:51.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T15:15:34.000Z", "avg_line_length": 31.5907335907, "max_line_length": 125, "alphanum_fraction": 0.4409679785, "num_tokens": 2025, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.872347368040789, "lm_q2_score": 0.7461389930307512, "lm_q1q2_score": 0.6508923867629804}} {"text": " subroutine SCONMC(N, COEFF)\nc Copyright (c) 1996 California Institute of Technology, Pasadena, CA.\nc ALL RIGHTS RESERVED.\nc Based on Government Sponsored Research NAS7-03001.\nC>> 1994-11-11 SCONMC Krogh Declared all vars.\nc>> 1994-10-20 SCONMC Krogh Changes to use M77CON\nc>> 1992-06-04 SCONMC Krogh Corrected line below.\nc>> 1992-01-31 SCONMC Krogh Initial Code.\nc--S replaces \"?\": ?CONMC\nc\nc Converts COEFF in monomial basis to the Chebyshev basis.\nc\n integer N, J, I\n real COEFF(0:N), TP\nc\n if (N .le. 0) return\n TP = .5E0**(N-1)\n COEFF(N) = TP * COEFF(N)\n COEFF(N-1) = TP * COEFF(N-1)\n do 20 J = N-2, 0, -1\n TP = 2.E0 * TP\n COEFF(J) = TP * COEFF(J)\n COEFF(J+1) = 2.E0 * COEFF(J+1)\n do 10 I = J, N-2\n COEFF(I) = COEFF(I) + COEFF(I+2)\n 10 continue\n 20 continue\n return\n end\n", "meta": {"hexsha": "116295cfc409b6e47e74b65b475aea7fb1e080c8", "size": 894, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/sconmc.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/sconmc.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/sconmc.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": 29.8, "max_line_length": 70, "alphanum_fraction": 0.5850111857, "num_tokens": 330, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473614033683, "lm_q2_score": 0.7461389817407016, "lm_q1q2_score": 0.650892371961697}} {"text": "module fac_mod\n implicit none\ncontains\n function factorial(n) result(fac)\n use FMZM\n integer, intent(in) :: n\n integer :: i\n type(IM) :: fac\n type(IM), save :: ii\n\n call FM_ENTER_USER_FUNCTION(fac)\n fac = to_im(1)\n\n if (n < 0) then\n write (*, *) \"Error in factorial N=\", n\n stop 1\n else if (n > 1) then\n do i = 1, n\n ii = to_im(i)\n fac = fac * ii\n end do\n end if\n call FM_EXIT_USER_FUNCTION(fac)\n end function factorial\nend module fac_mod\n\nprogram main\n use FMZM \n use fac_mod, only: f=>factorial\n implicit none\n type(IM) :: res\n integer :: n, lenr\n character(:), allocatable :: str\n character(1024) :: fmat\n\n print *, \"Enter a number: \"\n read *, n\n res = f(n)\n lenr = 2 + log10(TO_FM(res))\n allocate (character(lenr) :: str)\n write (fmat, \"(A5,I0)\") \"i\", lenr\n call im_form(fmat, res, str) \n print *, trim(adjustl(str))\nend program main\n", "meta": {"hexsha": "ad38f91348e9277039ab45908b94c4fdb35e301e", "size": 1047, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "main.f", "max_stars_repo_name": "BonfireScratch/100LanguageFactorial", "max_stars_repo_head_hexsha": "05c9f14380e4380825e5e0148bd981d5ccfc2576", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-17T09:34:27.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-15T19:24:51.000Z", "max_issues_repo_path": "main.f", "max_issues_repo_name": "BonfireScratch/100LanguageFactorial", "max_issues_repo_head_hexsha": "05c9f14380e4380825e5e0148bd981d5ccfc2576", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2019-01-02T14:54:19.000Z", "max_issues_repo_issues_event_max_datetime": "2020-06-18T20:30:46.000Z", "max_forks_repo_path": "main.f", "max_forks_repo_name": "BonfireScratch/100LanguageFactorial", "max_forks_repo_head_hexsha": "05c9f14380e4380825e5e0148bd981d5ccfc2576", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2019-01-02T15:48:38.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-18T13:35:29.000Z", "avg_line_length": 23.2666666667, "max_line_length": 51, "alphanum_fraction": 0.5243553009, "num_tokens": 306, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942377652497, "lm_q2_score": 0.7310585844894971, "lm_q1q2_score": 0.6508572452398192}} {"text": " SUBROUTINE DROTG(DA,DB,C,S)\n* .. Scalar Arguments ..\n DOUBLE PRECISION C,DA,DB,S\n* ..\n*\n* Purpose\n* =======\n*\n* construct givens plane rotation.\n* jack dongarra, linpack, 3/11/78.\n*\n*\n* .. Local Scalars ..\n DOUBLE PRECISION R,ROE,SCALE,Z\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC DABS,DSIGN,DSQRT\n* ..\n ROE = DB\n IF (DABS(DA).GT.DABS(DB)) ROE = DA\n SCALE = DABS(DA) + DABS(DB)\n IF (SCALE.NE.0.0d0) GO TO 10\n C = 1.0d0\n S = 0.0d0\n R = 0.0d0\n Z = 0.0d0\n GO TO 20\n 10 R = SCALE*DSQRT((DA/SCALE)**2+ (DB/SCALE)**2)\n R = DSIGN(1.0d0,ROE)*R\n C = DA/R\n S = DB/R\n Z = 1.0d0\n IF (DABS(DA).GT.DABS(DB)) Z = S\n IF (DABS(DB).GE.DABS(DA) .AND. C.NE.0.0d0) Z = 1.0d0/C\n 20 DA = R\n DB = Z\n RETURN\n END\n", "meta": {"hexsha": "e50dd648ab671e071ef5fe5650a6f834a81481a9", "size": 838, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "BLAS/SRC/drotg.f", "max_stars_repo_name": "nashmit/lapack-release", "max_stars_repo_head_hexsha": "fd9237f4f4cd45f10a8be62b35e63a702c93328f", "max_stars_repo_licenses": ["BSD-3-Clause"], "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": "BLAS/SRC/drotg.f", "max_issues_repo_name": "nashmit/lapack-release", "max_issues_repo_head_hexsha": "fd9237f4f4cd45f10a8be62b35e63a702c93328f", "max_issues_repo_licenses": ["BSD-3-Clause"], "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": "BLAS/SRC/drotg.f", "max_forks_repo_name": "nashmit/lapack-release", "max_forks_repo_head_hexsha": "fd9237f4f4cd45f10a8be62b35e63a702c93328f", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 47, "max_forks_repo_forks_event_min_datetime": "2015-01-27T06:22:57.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-11T20:59:04.000Z", "avg_line_length": 21.4871794872, "max_line_length": 60, "alphanum_fraction": 0.4832935561, "num_tokens": 350, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942377652497, "lm_q2_score": 0.731058584489497, "lm_q1q2_score": 0.6508572452398191}} {"text": "!\n! Special_Funcitons\n!\n! Module containing procedures for providing/evaluating various special\n! functions.\n!\n!\n! CREATION HISTORY:\n! Written by: Paul van Delst, 28-Nov-2001\n! paul.vandelst@nooa.gov\n!\n\nMODULE Special_Functions\n\n\n ! -----------------\n ! Environment setup\n ! -----------------\n ! Module use\n USE Type_Kinds, ONLY: fp, Single\n USE Message_Handler, ONLY: SUCCESS, FAILURE, Display_Message\n ! Disable all implicit typing\n IMPLICIT NONE\n\n\n ! ------------\n ! Visibilities\n ! ------------\n PRIVATE\n PUBLIC :: ln_Gamma\n PUBLIC :: Factorial\n PUBLIC :: Binomial_Coefficient\n\n\n ! -----------------\n ! Module parameters\n ! -----------------\n ! Version Id for the module\n CHARACTER(*), PARAMETER :: MODULE_VERSION_ID = &\n ! Message string length\n INTEGER, PARAMETER :: ML = 256\n ! Literal constants\n REAL(fp), PARAMETER :: ZERO = 0.0_fp\n REAL(fp), PARAMETER :: ONE = 1.0_fp\n REAL(fp), PARAMETER :: TWO = 2.0_fp\n\n\nCONTAINS\n\n\n!------------------------------------------------------------------------------\n!:sdoc+:\n!\n! NAME:\n! ln_Gamma\n!\n! PURPOSE:\n! Function to return the natural logarithm of the Gamma function.\n!\n! CALLING SEQUENCE:\n! result = ln_Gamma( x )\n!\n! INPUTS:\n! x: Argument of the Gamma function, Gamma(x), for which \n! the Gamma function logarithm is required. x > or = 1.\n! UNITS: N/A\n! TYPE: REAL(fp)\n! DIMENSION: Scalar\n! ATTRIBUTES: INTENT(IN)\n!\n! FUNCTION RESULT:\n! result: The return value is LN(GAMMA(x)). If the passed\n! value of x is less than 1.0, the returned result\n! is -1.0.\n! UNITS: N/A\n! TYPE: REAL(fp)\n! DIMENSION: Scalar\n!\n! PROCEDURE:\n! The algorithm used here is based on the Lanczos approximation detailed in,\n!\n! [1] Abramowitz, M., and Stegun, I.A. (eds) 1972, \"Handbook of Mathematical\n! Functions\", Applied Mathematics Series, vol.55 (Washington:\n! National Bureau of Standards)\n!\n! and discussed in,\n!\n! [2] Press, W.H. etal., 1992, \"Numerical Recipes in Fortran\", 2nd ed.,\n! Cambridge University Press, pp206-207\n!\n! the latter reference from which this code is adapted.\n!\n! The Gamma function is defined by the integral,\n!\n! Inf\n! /\\\n! | z-1 -t\n! Gamma(z) = | t .e dt\n! \\/\n! 0\n!\n! When the argument z is an integer,\n!\n! n! = Gamma(n+1)\n!\n! The Gamma function satisfies the recurrance relation,\n!\n! Gamma(z+1) = z.Gamma(z) .....(1)\n!\n! For z > 0, the Lanczos approximation to the Gamma function\n! can be written as,\n!\n! z+0.5 ___ [ c1 c2 cN ]\n! Gamma(z+1) = (z+y+0.5) .exp(-(z+y+0.5)) . \\/2pi [ c0 + ----- + ----- + ... + ----- + e ]\n! [ z+1 z+2 z+N ]\n!\n! .....(2)\n!\n! where e is the error term.\n!\n! For y = 5, N = 6 and using the coefficients from ref.[2], the\n! error is smaller that |e| < 2e-10. For the purposes which this\n! function will be used, that is good enough.\n!\n! The natural log of the Gamma function is obtained simply by taking\n! the logarithm of the RHS of eqn(2).\n!\n!:sdoc-:\n!------------------------------------------------------------------------------\n\n FUNCTION ln_Gamma( x )\n ! Arguments\n REAL(fp), INTENT(IN) :: x\n ! Function result\n REAL(fp) :: ln_Gamma\n ! Local parameters\n CHARACTER(*), PARAMETER :: ROUTINE_NAME = 'ln_Gamma'\n ! ...The series coefficients\n INTEGER, PARAMETER :: N_GAMMA_COEFFICIENTS = 6\n REAL(fp), PARAMETER :: GAMMA_COEFFICIENT( N_GAMMA_COEFFICIENTS ) = &\n [ 76.18009172947146_fp, -86.50532032941677_fp, 24.01409824083091_fp, &\n -1.231739572450155_fp, 1.208650973866179e-03_fp, -5.395239384953e-06_fp ]\n ! ...The other series parameters\n REAL(fp), PARAMETER :: Y = 5.0_fp\n REAL(fp), PARAMETER :: SQRT_2PI = 2.5066282746310005_fp\n REAL(fp), PARAMETER :: C0_AND_ERROR_TERM = 1.000000000190015_fp\n ! ...Literal constants\n REAL(fp), PARAMETER :: POINT5 = 0.5_fp\n ! Local variables\n CHARACTER(ML) :: msg\n REAL(fp) :: z\n\n\n ! Set up\n IF ( x < ONE ) THEN\n ln_Gamma = -ONE\n msg = 'Input X argument must be > or = 1.'\n CALL Display_Message( ROUTINE_NAME, msg, FAILURE )\n RETURN\n END IF\n \n\n ! Z is the temporary argument variable\n z = x\n\n\n ! Calculate the multipler terms for ln(Gamma(x+1))\n ln_Gamma = z + Y + POINT5\n ln_Gamma = ( ( z + POINT5 ) * LOG(ln_Gamma) ) - ln_Gamma\n\n\n ! Compute the series approximation term\n ! ...Initialise the sum to c0 + e.\n series_sum = C0_AND_ERROR_TERM\n ! ...Sum the series.\n DO i = 1, N_GAMMA_COEFFICIENTS\n series_sum = series_sum + ( GAMMA_COEFFICIENT(i) / ( z + REAL(i,fp) ) )\n END DO\n\n\n ! Complete the calculation. Note that the division\n ! by \"z\" here is to ensure that ln(Gamma(X)) is\n ! being calculated, NOT ln(Gamma(x+1))\n ln_Gamma = ln_Gamma + LOG(SQRT_2PI * series_sum / z)\n\n END FUNCTION ln_Gamma\n\n\n\n!------------------------------------------------------------------------------\n!:sdoc+:\n!\n! NAME:\n! Factorial\n!\n! PURPOSE:\n! Function to compute the factorial, n!\n!\n! CALLING SEQUENCE:\n! result = Factorial( n )\n!\n! INPUT ARGUMENTS:\n! n: Value for which n! is required. n > or = 0. The upper\n! limit depends on the definition of the floating point\n! kind type, fp. See RESTRICTIONS below.\n! UNITS: N/A\n! TYPE: INTEGER\n! DIMENSION: Scalar\n! ATTRIBUTES: INTENT(IN)\n!\n! FUNCTION RESULT:\n! result: The return value is n!. If the passed value of n is\n! less than 0, or if it is so large that a floating point\n! variable with the \"fp\" kind type cannot represent the\n! value of n!, the returned result is -1.0.\n! UNITS: N/A\n! TYPE: REAL(fp)\n! DIMENSION: Scalar\n!\n! RESTRICTIONS:\n! Input n argument must be > or = 0. Upper limits are:\n! Single precision: n < or = 30.\n! Double/Quad precision: n < or = 168.\n! Note that these limits are one less than the values that would place the\n! result of n! on the bleeding edge of what can be represented.\n!\n! The type of floating point variables used are determined by the fp\n! data type defined in the Type_Kinds module.\n!\n! PROCEDURE:\n! If the input value of n is < or = 30, the returned factorial is obtained from\n! a table of values. For n > 30 and <= 168, \n!\n! n! = EXP(LN(Gamma(n+1)))\n!\n!:sdoc-:\n!------------------------------------------------------------------------------\n\n FUNCTION factorial( n )\n ! Arguments\n INTEGER, INTENT(IN) :: n\n ! Function result\n REAL(fp) :: factorial\n ! Local parameters\n CHARACTER( * ), PARAMETER :: ROUTINE_NAME = 'Factorial'\n ! ...Maximum value of n allowed.\n INTEGER, PARAMETER :: MAX_N = 168\n ! ...The tabulated values up to n = 30\n INTEGER, PARAMETER :: N_TABULATED_VALUES = 30\n REAL(fp), PARAMETER :: FACTORIAL_TABLE(0:N_TABULATED_VALUES) = &\n ! 3 2 1\n ! 3 21098765432109876543210987654321\n [ 1.00000000000000000000000000000000e+00_fp, &\n 1.00000000000000000000000000000000e+00_fp, &\n 2.00000000000000000000000000000000e+00_fp, &\n 6.00000000000000000000000000000000e+00_fp, &\n 2.40000000000000000000000000000000e+01_fp, &\n 1.20000000000000000000000000000000e+02_fp, &\n 7.20000000000000000000000000000000e+02_fp, &\n 5.04000000000000000000000000000000e+03_fp, &\n 4.03200000000000000000000000000000e+04_fp, &\n 3.62880000000000000000000000000000e+05_fp, &\n 3.62880000000000000000000000000000e+06_fp, &\n 3.99168000000000000000000000000000e+07_fp, &\n 4.79001600000000000000000000000000e+08_fp, &\n 6.22702080000000000000000000000000e+09_fp, &\n 8.71782912000000000000000000000000e+10_fp, &\n 1.30767436800000000000000000000000e+12_fp, &\n 2.09227898880000000000000000000000e+13_fp, &\n 3.55687428096000000000000000000000e+14_fp, &\n 6.40237370572800000000000000000000e+15_fp, &\n 1.21645100408832000000000000000000e+17_fp, &\n 2.43290200817664000000000000000000e+18_fp, &\n 5.10909421717094400000000000000000e+19_fp, &\n 1.12400072777760768000000000000000e+21_fp, &\n 2.58520167388849766400000000000000e+22_fp, &\n 6.20448401733239439360000000000000e+23_fp, &\n 1.55112100433309859840000000000000e+25_fp, &\n 4.03291461126605635584000000000000e+26_fp, &\n 1.08888694504183521607680000000000e+28_fp, &\n 3.04888344611713860501504000000000e+29_fp, &\n 8.84176199373970195454361600000000e+30_fp, &\n 2.65252859812191058636308480000000e+32_fp ]\n ! Local variables\n CHARACTER(ML) :: msg\n REAL(fp) :: x\n\n\n ! Setup\n IF ( n < 0 ) THEN\n Factorial = -ONE\n msg = 'Input n argument must be > or = 0.'\n CALL Display_Message( ROUTINE_NAME, msg, FAILURE )\n RETURN\n END IF\n\n\n ! Calculate n!\n IF ( n <= N_TABULATED_VALUES ) THEN\n\n ! ...Get value from table\n Factorial = FACTORIAL_TABLE(n)\n\n ELSE\n\n ! ...Check if data type can handle the value\n IF ( fp == Single ) THEN\n Factorial = -ONE\n WRITE(msg,'(\"Floating point type is single precision. \"&\n &\"Cannot represent \",i0,\"! accurately\")') n\n CALL Display_Message( ROUTINE_NAME, msg, FAILURE )\n RETURN\n ELSE\n IF ( n > MAX_N ) THEN\n Factorial = -ONE\n msg = 'Input value of n is just too big!'\n CALL Display_Message( ROUTINE_NAME, msg, FAILURE )\n RETURN\n END IF\n END IF\n\n ! ...Calculate factorial using Gamma function.\n x = REAL(n, fp)\n Factorial = EXP(ln_Gamma( x + ONE ))\n\n END IF\n\n END FUNCTION Factorial\n\n\n\n!------------------------------------------------------------------------------\n!:sdoc+:\n!\n! NAME:\n! Binomial_Coefficient\n!\n! PURPOSE:\n! Function to compute the binomial coefficient.\n!\n! CALLING SEQUENCE:\n! result = Binomial_Coefficient( n, k )\n!\n! INPUTS:\n! n: Total number of values from which an unordered\n! combination is required.\n! Must be > or = k.\n! UNITS: N/A\n! TYPE: INTEGER\n! DIMENSION: Scalar\n! ATTRIBUTES: INTENT(IN)\n!\n! k: The number of unordered sequences to select from\n! n numbers.\n! Must be > or = 0.\n! UNITS: N/A\n! TYPE: INTEGER\n! DIMENSION: Scalar\n! ATTRIBUTES: INTENT(IN)\n!\n! FUNCTION RESULT:\n! result: The return value is the binomial coefficient. If the\n! passed arguments are invalid, or the result is not\n! representable (too big), the returned value is -1.\n! UNITS: N/A\n! TYPE: INTEGER\n! DIMENSION: Scalar\n!\n! PROCEDURE:\n! The number of ways of picking k unordered sequences from n numbers\n! is the binomial coefficient or combinatorial number. It is given by,\n!\n! n!\n! n(C)k = --------------- .....................(1)\n! ( n-k )! . k!\n!\n! The factorial can be written as a Gamma function,\n!\n! n! = Gamma( n+1 )\n!\n! thus eqn(1) can be expressed as,\n!\n! Gamma( n+1 )\n! n(C)k = ------------------------------- .....(2)\n! Gamma( n-k+1 ) . Gamma( k+1 )\n!\n! Depending on the values of n and k, the resultant Gamma values can\n! be quite large (and unrepresentable) so eqn(2) can be recast to\n! provide the logarithm of the binomial coefficient,\n!\n!\n! b = LN(Gamma( n+1 )) - LN(Gamma( n-k+1 )) - LN(Gamma( k+1 )) \n!\n! from which the binomial coefficient is easily obtained,\n!\n! n(C)k = EXP( b ) ............................(3)\n!\n! In this function, before eqn(3) is evaluated, the value of b\n! is tested so that the integer form of EXP( b ) is representable.\n! \n!:sdoc-:\n!------------------------------------------------------------------------------\n\n FUNCTION Binomial_Coefficient( n, k )\n ! Arguments\n INTEGER, INTENT(IN) :: n\n INTEGER, INTENT(IN) :: k\n ! Function result\n INTEGER :: Binomial_Coefficient\n ! Local parameters\n CHARACTER(*), PARAMETER :: ROUTINE_NAME = 'Binomial_Coefficient'\n ! Local variables\n CHARACTER(ML) :: msg\n REAL(fp) :: xn, xk\n REAL(fp) :: ln_coeff\n\n\n ! Set up\n IF ( n < 0 .OR. k < 0 ) THEN\n Binomial_Coefficient = -1\n msg = 'Input n, k arguments must be > or = 0.'\n CALL Display_Message( ROUTINE_NAME, msg, FAILURE )\n RETURN\n END IF\n IF ( n < k ) THEN\n Binomial_Coefficient = 0\n msg = 'Input n is < input k. Setting result to 0.'\n CALL Display_Message( ROUTINE_NAME, msg, WARNING )\n RETURN\n END IF\n IF ( k == 0 ) THEN\n Binomial_Coefficient = 1\n RETURN\n END IF\n\n\n ! Convert the input integer arguments to floats\n xn = REAL(n, fp)\n xk = REAL(k, fp)\n\n\n ! Calulate the natural log of the binomial\n ! coefficient using the ln_Gamma() function\n ln_coeff = ln_Gamma( xn+ONE ) - ln_Gamma( xk+ONE ) - ln_Gamma( xn-xk+ONE )\n\n\n ! Determine if the result is representable\n IF ( ln_coeff > LOG(TWO**DIGITS(Binomial_Coefficient) - ONE) ) THEN\n Binomial_Coefficient = -1\n msg = 'Coefficient value too large to represent.'\n CALL Display_Message( ROUTINE_NAME, msg, FAILURE )\n RETURN\n END IF\n \n \n ! Convert the coefficient logarithm to its actual value\n Binomial_Coefficient = NINT(EXP(ln_coeff))\n\n END FUNCTION Binomial_Coefficient\n\nEND MODULE Special_Functions\n", "meta": {"hexsha": "feb228ed6196c479280663ae8494ee95596609c5", "size": 14611, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/Utility/Math_Utility/Special_Functions.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/Math_Utility/Special_Functions.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/Math_Utility/Special_Functions.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": 31.6255411255, "max_line_length": 102, "alphanum_fraction": 0.5458216412, "num_tokens": 4038, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942348544447, "lm_q2_score": 0.7310585786300048, "lm_q1q2_score": 0.650857237895178}} {"text": "!version: serial with no mpi\n! solves the 2d Stommel Model of Ocean Circulation \n! using a Five-point stencil and Jacobi iteration\n!\n! gamma*((d(d(psi)/dx)/dx) + (d(d(psi)/dy)/dy))\n! +beta(d(psi)/dx)=-alpha*sin(pi*y/(2*ly))\n!\nmodule numz\n! module defines the basic real type and pi\n integer, parameter:: b8 = selected_real_kind(14)\n real(b8), parameter :: pi = 3.141592653589793239_b8\nend module\n!*********************\nmodule input\n! module contains the inputs \n use numz\n integer nx,ny ! number of interior points for our grid (50 50)\n real(b8) lx,ly ! physical size of our grid (2000 2000)\n real(b8) alpha,beta,gamma ! parameters of the calculation (1.0e-9 2.25e-11 3.0e-6)\n integer steps ! number of Jacobi iteration steps (60)\nend module\n!*********************\nmodule constants\n! this module contains the invariants (constants) of the\n! calculation. these values are determined in the main\n! routine and used in the do_jacobi Jacobi iteration subroutine\n! a6 is used in the force function\n use numz\n real(b8) dx,dy,a1,a2,a3,a4,a5,a6\n real(b8), allocatable:: for(:,:) ! our force grid\nend module\n!*********************\nmodule face\n! this module contains the interface for the two subroutines\n! that modify the grid. an interface is a good idea in this\n! case because we are passing allocatable arrays\n interface bc\n subroutine bc (psi,i1,i2,j1,j2)\n! sets the boundary conditions\n! input is the grid and the indices for the interior cells\n use numz\n real(b8),dimension(i1:i2,j1:j2):: psi\n integer,intent(in):: i1,i2,j1,j2\n end subroutine\n end interface\n interface do_jacobi\n subroutine do_jacobi (psi,new_psi,diff,i1,i2,j1,j2)\n! does a single Jacobi iteration step\n! input is the grid and the indices for the interior cells\n! new_psi is temp storage for the the updated grid\n! output is the updated grid in psi and diff which is\n! the sum of the differences between the old and new grids\n use numz\n real(b8),dimension(i1-1:i2+1,j1-1:j2+1):: psi\n real(b8),dimension(i1-1:i2+1,j1-1:j2+1):: new_psi\n real(b8) diff\n integer,intent(in):: i1,i2,j1,j2\n end subroutine\n end interface\n! interface for the forcing function\n interface force\n function force(y)\n use numz\n real(b8) force,y\n end function force\n end interface \n interface do_force\n subroutine do_force (i1,i2,j1,j2)\n! sets the boundary conditions\n! input is the grid and the indices for the interior cells\n use numz\n integer,intent(in):: i1,i2,j1,j2\n end subroutine\n end interface\n! interface for routine to write the grid\n interface write_grid\n subroutine write_grid (psi,i1,i2,j1,j2)\n! input is the grid and the indices for the interior cells\n use numz\n real(b8),dimension(i1:i2,j1:j2):: psi\n integer,intent(in):: i1,i2,j1,j2\n end subroutine\n end interface\nend module\n!*********************\nprogram stommel\n use numz\n use input\n use constants\n use face\n implicit none\n real(b8)diff\n real(b8)dx2,dy2,bottom\n real(b8), allocatable:: psi(:,:) ! our calculation grid\n real(b8), allocatable:: new_psi(:,:) ! temp storage for the grid\n integer i,j,i1,i2,j1,j2\n integer omp_get_max_threads\n real(b8) t1,t2,walltime\n integer n_thread,n_mpi\n integer iout\n! get the input. see above for typical values\n read(*,*)nx,ny\n read(*,*)lx,ly\n read(*,*)alpha,beta,gamma\n read(*,*)steps\n write(*,*)\"threads=\",omp_get_max_threads()\n n_thread=omp_get_max_threads()\n n_mpi=1\n! allocate the grid to size nx * ny plus the boundary cells\n allocate(psi(0:nx+1,0:ny+1))\n allocate(new_psi(0:nx+1,0:ny+1))\n allocate(for(0:nx+1,0:ny+1))\n! calculate the constants for the calculations\n dx=lx/(nx+1)\n dy=ly/(ny+1)\n dx2=dx*dx\n dy2=dy*dy\n bottom=2.0_b8*(dx2+dy2)\n a1=(dy2/bottom)+(beta*dx2*dy2)/(2.0_b8*gamma*dx*bottom)\n a2=(dy2/bottom)-(beta*dx2*dy2)/(2.0_b8*gamma*dx*bottom)\n a3=dx2/bottom\n a4=dx2/bottom\n a5=dx2*dy2/(gamma*bottom)\n a6=pi/(ly)\n! set initial guess for the value of the grid\n psi=1.0_b8\n! set the indices for the interior of the grid\n i1=1\n i2=nx\n j1=1\n j2=ny\n! set boundary conditions\n call bc(psi,i1,i2,j1,j2)\n! set the force array\n call do_force(i1,i2,j1,j2)\n new_psi=psi\n! do the jacobian iterations\n iout=steps/100\n if(iout == 0)iout=1\n t1=walltime()\n do i=1,steps\n call do_jacobi(psi,new_psi,diff,i1,i2,j1,j2)\n\tif(mod(i,iout) .eq. 0)write(*,'(i6,1x,g20.10)')i,diff\n enddo\n t2=walltime()\n write(*,*)\"run time =\",t2-t1,n_mpi,n_thread\n! write out the final grid\n! call write_grid(psi,i1,i2,j1,j2)\nend program stommel\n!*********************\nsubroutine bc(psi,i1,i2,j1,j2)\n! sets the boundary conditions\n! input is the grid and the indices for the interior cells\n use numz\n implicit none\n integer,intent(in):: i1,i2,j1,j2\n real(b8),dimension(i1-1:i2+1,j1-1:j2+1):: psi\n psi(i1-1,:)=0.0_b8\n psi(i2+1,:)=0.0_b8\n psi(:,j1-1)=0.0_b8\n psi(:,j2+1)=0.0_b8\nend subroutine bc\n!*********************\nsubroutine do_jacobi(psi,new_psi,diff,i1,i2,j1,j2)\n! does a single Jacobi iteration step\n! input is the grid and the indices for the interior cells\n! new_psi is temp storage for the the updated grid\n! output is the updated grid in psi and diff which is\n! the sum of the differences between the old and new grids\n use numz\n use constants\n implicit none\n integer,intent(in) :: i1,i2,j1,j2\n real(b8),dimension(i1-1:i2+1,j1-1:j2+1):: psi\n real(b8),dimension(i1-1:i2+1,j1-1:j2+1):: new_psi\n real(b8) diff\n integer i,j\n real(b8) y\n diff=0.0_b8\n!$OMP PARALLEL\n!$OMP DO SCHEDULE (STATIC) private(i) firstprivate(a1,a2,a3,a4,a5) reduction(+:diff)\n do j=j1,j2\n do i=i1,i2\n! y=j*dy\n new_psi(i,j)=a1*psi(i+1,j) + a2*psi(i-1,j) + &\n a3*psi(i,j+1) + a4*psi(i,j-1) - &\n a5*for(i,j)\n! a5*force(y)\n diff=diff+abs(new_psi(i,j)-psi(i,j))\n enddo\n enddo\n!$OMP END DO\n!$OMP END PARALLEL\n!$OMP parallel workshare\n psi(i1:i2,j1:j2)=new_psi(i1:i2,j1:j2)\n!$OMP end parallel workshare\nend subroutine do_jacobi\n!*********************\nfunction force(y)\n use numz\n use input\n use constants\n implicit none\n real(b8) force,y\n force=-alpha*sin(y*a6)\nend function force\n!*********************\nsubroutine do_force (i1,i2,j1,j2)\n! sets the force conditions\n! input is the grid and the indices for the interior cells\n use numz\n use constants, only:for,dy\n use face, only : force\n implicit none\n integer,intent(in):: i1,i2,j1,j2\n real(b8) y\n integer i,j\n do i=i1,i2\n do j=j1,j2\n y=j*dy\n for(i,j)=force(y)\n enddo\n enddo\nend subroutine\n!*********************\nsubroutine write_grid(psi,i1,i2,j1,j2)\n! input is the grid and the indices for the interior cells\n use numz\n implicit none\n integer,intent(in):: i1,i2,j1,j2\n real(b8),dimension(i1-1:i2+1,j1-1:j2+1):: psi\n integer i,j\n integer istart,iend,jstart,jend\n integer rl\n! each processor writes its section of the grid\n istart=i1-1\n iend=i2+1\n jstart=j1-1\n jend=j2+1\n rl=max(80,15*((jend-jstart)+3)+2)\n open(23,file=\"out_omp\",recl=rl)\n! write(23,101)istart,iend,jstart,jend\n!101 format(6x,\" (\",i3,\" <= i <= \",i3,\") , \", &\n! \" (\",i3,\" <= j <= \",i3,\")\")\n write(23,'(2i6)')iend-istart+1,jend-jstart+1\n \n do i=istart,iend\n do j=jstart,jend\n write(23,'(g14.7)',advance=\"no\")psi(i,j)\n if(j .ne. jend)write(23,'(\" \")',advance=\"no\")\n enddo\n write(23,*)\n enddo\n close(23)\nend subroutine write_grid\n\n\nfunction walltime()\n use numz\n real(b8) walltime\n integer count,count_rate,count_max\n call system_clock(count,count_rate,count_max)\n walltime=real(count,b8)/real(count_rate,b8)\nend function walltime\n \n\n", "meta": {"hexsha": "e047890b376762c075ac8b566a5302d75a8b6f07", "size": 8129, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "workshop/hybrid/StomOmpf_00g.f", "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": "hybrid/StomOmpf_00g.f", "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": "workshop/hybrid/StomOmpf_00g.f", "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": 30.4456928839, "max_line_length": 86, "alphanum_fraction": 0.621601673, "num_tokens": 2630, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942290328345, "lm_q2_score": 0.7310585786300049, "lm_q1q2_score": 0.6508572336392401}} {"text": "function SHPowerLC(cilm, l)\n!------------------------------------------------------------------------------\n!\n! This function will compute the dimensionless power at\n! degree l corresponding to the complex 4-pi normalized spherical harmonic\n! coefficients cilm(i, l, m).\n!\n! Power(l) = Sum_{m=0}^l | c1lm | **2 + | c2lm | **2 )\n!\n! Calling Parameters\n!\n! cilm Complex spherical harmonic coefficients, dimensioned as\n! (2, lmax+1, lmax+1).\n! l Spherical harmonic degree to compute power.\n!\n! Copyright (c) 2016-2019, SHTOOLS\n! All rights reserved.\n!\n!------------------------------------------------------------------------------\n use ftypes\n\n implicit none\n\n real(dp) :: SHPowerLC\n complex(dp), intent(in) :: cilm(:,:,:)\n integer(int32), intent(in) :: l\n integer(int32) :: i, m, l1, m1\n\n l1 = l + 1\n\n if (size(cilm(:,1,1)) < 2 .or. size(cilm(1,:,1)) < l1 &\n .or. size(cilm(1,1,:)) < l1) then\n print*, \"Error --- SHPowerLC\"\n print*, \"CILM must be dimensioned as (2, L+1, L+1) where L is \", l\n print*, \"Input array is dimensioned \", size(cilm(:,1,1)), &\n size(cilm(1,:,1)), size(cilm(1,1,:))\n stop\n\n end if\n\n SHPowerLC = dble(cilm(1, l1, 1))**2 + aimag(cilm(1, l1, 1))**2\n\n do m = 1, l, 1\n m1 = m + 1\n\n do i = 1, 2\n SHPowerLC = SHPowerLC + dble(cilm(i, l1, m1))**2 &\n + aimag(cilm(i, l1, m1))**2\n\n end do\n\n end do\n\nend function SHPowerLC\n\n\nfunction SHPowerDensityLC(cilm, l)\n!------------------------------------------------------------------------------\n!\n! This function will compute the dimensionless power per coefficient\n! (density) at degree l of the complex 4-pi normalized spherical harmonic\n! coefficients cilm(i, l, m).\n!\n! PowerSpectralDensity(l) = Sum_{m=0}^l ( | c1lm |**2 + | c2lm |**2 ) /(2l+1)\n!\n! Calling Parameters\n!\n! cilm Complex spherical harmonic coefficients, dimensioned as\n! (2, lmax+1, lmax+1).\n! l Spherical harmonic degree to compute power.\n!\n! Copyright (c) 2016-2019, SHTOOLS\n! All rights reserved.\n!\n!------------------------------------------------------------------------------\n use ftypes\n\n implicit none\n\n real(dp) :: SHPowerDensityLC\n complex(dp), intent(in) :: cilm(:,:,:)\n integer(int32), intent(in) :: l\n integer(int32) :: i, m, l1, m1\n\n l1 = l + 1\n\n if (size(cilm(:,1,1)) < 2 .or. size(cilm(1,:,1)) < l1 &\n .or. size(cilm(1,1,:)) < l1) then\n print*, \"Error --- SHPowerDensityLC\"\n print*, \"CILM must be dimensioned as (2, L+1, L+1) where L is \", l\n print*, \"Input array is dimensioned \", size(cilm(:,1,1)), &\n size(cilm(1,:,1)), size(cilm(1,1,:))\n stop\n\n end if\n\n SHPowerDensityLC = dble(cilm(1, l1, 1))**2 + aimag(cilm(1, l1, 1))**2\n\n do m = 1, l, 1\n m1 = m + 1\n\n do i = 1, 2\n SHPowerDensityLC = SHPowerDensityLC + dble(cilm(i, l1, m1))**2 &\n + aimag(cilm(i, l1, m1))**2\n\n end do\n end do\n\n SHPowerDensityLC = SHPowerDensityLC / dble(2*l+1)\n\nend function SHPowerDensityLC\n\n\nfunction SHCrossPowerLC(cilm1, cilm2, l)\n!------------------------------------------------------------------------------\n!\n! This function will compute the dimensionless cross power at\n! degree l for the complex 4-pi normalized spherical harmonic\n! coefficients cilm1(i, l, m) and cilm2(i,l,m).\n!\n! CrossPower = Sum_{m=0}^l ( c11lm * c21lm^* + c12lm * c22lm^* )\n!\n! Calling Parameters\n!\n! cilm1 Complex spherical harmonic coefficients, dimensioned as\n! (2, lmax+1, lmax+1).\n! cilm2 Complex spherical harmonic coefficients, dimensioned as\n! (2, lmax+1, lmax+1).\n! l Spherical harmonic degree to compute power.\n!\n! Copyright (c) 2016-2019, SHTOOLS\n! All rights reserved.\n!\n!------------------------------------------------------------------------------\n use ftypes\n\n implicit none\n\n complex(dp) :: SHCrossPowerLC\n complex(dp), intent(in) :: cilm1(:,:,:), cilm2(:,:,:)\n integer(int32), intent(in) :: l\n integer(int32) :: i, m, l1, m1\n\n l1 = l + 1\n\n if (size(cilm1(:,1,1)) < 2 .or. size(cilm1(1,:,1)) < l1 &\n .or. size(cilm1(1,1,:)) < l1) then\n print*, \"Error --- SHCrossPowerLC\"\n print*, \"CILM1 must be dimensioned as (2, L+1, L+1) where L is \", l\n print*, \"Input array is dimensioned \", size(cilm1(:,1,1)), &\n size(cilm1(1,:,1)), size(cilm1(1,1,:))\n stop\n\n else if (size(cilm2(:,1,1)) < 2 .or. size(cilm2(1,:,1)) < l1 .or. &\n size(cilm2(1,1,:)) < l1) then\n print*, \"SHCrossPowerLC --- Error\"\n print*, \"CILM2 must be dimensioned as (2, L+1, L+1) where L is \", l\n print*, \"Input array is dimensioned \", size(cilm2(:,1,1)), &\n size(cilm2(1,:,1)), size(cilm2(1,1,:))\n stop\n\n end if\n\n SHCrossPowerLC = cilm1(1, l1, 1) * conjg(cilm2(1,l1,1))\n\n do m = 1, l, 1\n m1 = m + 1\n\n do i = 1, 2\n SHCrossPowerLC = SHCrossPowerLC + cilm1(i,l1,m1) &\n * conjg(cilm2(i,l1,m1))\n\n end do\n\n end do\n\nend function SHCrossPowerLC\n\n\nfunction SHCrossPowerDensityLC(cilm1, cilm2, l)\n!------------------------------------------------------------------------------\n!\n! This function will compute the dimensionless cross power\n! (density) at degree l of the complex 4-pi normalized spherical harmonic\n! coefficients cilm1(i, l, m) and cilm2(i,l,m).\n!\n! CrossPower(l) = Sum_{m=0}^l ( c11lm * C21lm^* + c12lm * C22lm^* ) / (2l+1)\n!\n! Calling Parameters\n!\n! cilm1 Complex spherical harmonic coefficients, dimensioned as\n! (2, lmax+1, lmax+1).\n! cilm2 Complex spherical harmonic coefficients, dimensioned as\n! (2, lmax+1, lmax+1).\n! l Spherical harmonic degree to compute power.\n!\n! Copyright (c) 2016-2019, SHTOOLS\n! All rights reserved.\n!\n!------------------------------------------------------------------------------\n use ftypes\n\n implicit none\n\n complex(dp) :: SHCrossPowerDensityLC\n complex(dp), intent(in) :: cilm1(:,:,:), cilm2(:,:,:)\n integer(int32), intent(in) :: l\n integer(int32) :: i, m, l1, m1\n\n l1 = l + 1\n\n if (size(cilm1(:,1,1)) < 2 .or. size(cilm1(1,:,1)) < l1 &\n .or. size(cilm1(1,1,:)) < l1) then\n print*, \"Error --- SHCrossPowerDensityLC\"\n print*, \"CILM1 must be dimensioned as (2, L+1, L+1) where L is \", l\n print*, \"Input array is dimensioned \", size(cilm1(:,1,1)), &\n size(cilm1(1,:,1)), size(cilm1(1,1,:))\n stop\n\n else if (size(cilm2(:,1,1)) < 2 .or. size(cilm2(1,:,1)) < l1 &\n .or. size(cilm2(1,1,:)) < l1) then\n print*, \"Error --- SHCrossPowerDensityLC\"\n print*, \"CILM2 must be dimensioned as (2, L+1, L+1) where L is \", l\n print*, \"Input array is dimensioned \", size(cilm2(:,1,1)), &\n size(cilm2(1,:,1)), size(cilm2(1,1,:))\n stop\n\n end if\n\n SHCrossPowerDensityLC = cilm1(1, l1, 1) * conjg(cilm2(1,l1,1))\n\n do m = 1, l, 1\n m1 = m + 1\n\n do i = 1, 2\n SHCrossPowerDensityLC = SHCrossPowerDensityLC &\n + cilm1(i, l1, m1) * conjg(cilm2(i,l1,m1))\n\n end do\n\n end do\n\n SHCrossPowerDensityLC = SHCrossPowerDensityLC / dble(2*l+1)\n\nend function SHCrossPowerDensityLC\n\n\nsubroutine SHPowerSpectrumC(cilm, lmax, spectra, exitstatus)\n!------------------------------------------------------------------------------\n!\n! This function will compute the dimensionless power spectrum\n! of the complex 4-pi normalized spherical harmonic coefficients\n! cilm(i, l, m).\n!\n! Power(l) = Sum_{m=0}^l ( | c1lm |**2 + | c2lm |**2 )\n!\n! Calling Parameters\n!\n! IN\n! cilm Complex pherical harmonic coefficients, dimensioned as\n! (2, lmax+1, lmax+1).\n! lmax Spherical harmonic degree to compute power.\n!\n! OUT\n! spectra Array of length (lmax+1) containing the power\n! spectra of cilm.\n!\n! OPTIONAL (OUT)\n! exitstatus If present, instead of executing a STOP when an error\n! is encountered, the variable exitstatus will be\n! returned describing the error.\n! 0 = No errors;\n! 1 = Improper dimensions of input array;\n! 2 = Improper bounds for input variable;\n! 3 = Error allocating memory;\n! 4 = File IO error.\n!\n! Copyright (c) 2016-2019, SHTOOLS\n! All rights reserved.\n!\n!------------------------------------------------------------------------------\n use ftypes\n\n implicit none\n\n complex(dp), intent(in) :: cilm(:,:,:)\n integer(int32), intent(in) :: lmax\n real(dp), intent(out) :: spectra(:)\n integer(int32), intent(out), optional :: exitstatus\n integer(int32) :: i, m, l1, m1, l\n\n if (present(exitstatus)) exitstatus = 0\n\n if (size(cilm(:,1,1)) < 2 .or. size(cilm(1,:,1)) < lmax+1 &\n .or. size(cilm(1,1,:)) < lmax+1) then\n print*, \"Error --- SHPowerSpectrumC\"\n print*, \"CILM must be dimensioned as (2, LMAX+1, LMAX+1) \" // &\n \"where LMAX is \", lmax\n print*, \"Input array is dimensioned \", size(cilm(:,1,1)), &\n size(cilm(1,:,1)), size(cilm(1,1,:))\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n else if (size(spectra) < lmax+1) then\n print*, \"Error --- SHPowerSpectrumC\"\n print*, \"SPECTRA must be dimensioned as (LMAX+1) where LMAX is \", lmax\n print*, \"Input vector has dimension \", size(spectra)\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n end if\n\n spectra = 0.0_dp\n\n do l = 0, lmax\n l1 = l + 1\n\n spectra(l1) = dble(cilm(1, l1, 1))**2 + aimag(cilm(1, l1, 1))**2\n\n do m = 1, l, 1\n m1 = m + 1\n\n do i = 1, 2\n spectra(l1) = spectra(l1) + dble(cilm(i, l1, m1))**2 &\n + aimag(cilm(i, l1, m1))**2\n\n end do\n end do\n end do\n\nend subroutine SHPowerSpectrumC\n\n\nsubroutine SHPowerSpectrumDensityC(cilm, lmax, spectra, exitstatus)\n!------------------------------------------------------------------------------\n!\n! This function will compute the dimensionless power spectrum\n! density of the complex 4-pi normalized spherical harmonic coefficients\n! cilm(i, l, m).\n!\n! PowerSpectralDensityC(l) = Sum_{m=0}^l ( c1lm**2 + c2lm**2 ) / (2l+1)\n!\n! Calling Parameters\n!\n! IN\n! cilm Complex spherical harmonic coefficients, dimensioned as\n! (2, lmax+1, lmax+1).\n! lmax Spherical harmonic degree to compute power.\n!\n! OUT\n! spectra Array of length (lmax+1) containing the power\n! spectra density of cilm.\n!\n! OPTIONAL (OUT)\n! exitstatus If present, instead of executing a STOP when an error\n! is encountered, the variable exitstatus will be\n! returned describing the error.\n! 0 = No errors;\n! 1 = Improper dimensions of input array;\n! 2 = Improper bounds for input variable;\n! 3 = Error allocating memory;\n! 4 = File IO error.\n!\n! Copyright (c) 2016-2019, SHTOOLS\n! All rights reserved.\n!\n!-------------------------------------------------------------------------------\n use ftypes\n\n implicit none\n\n complex(dp), intent(in) :: cilm(:,:,:)\n integer(int32), intent(in) :: lmax\n real(dp), intent(out) :: spectra(:)\n integer(int32), intent(out), optional :: exitstatus\n integer(int32) :: i, m, l1, m1, l\n\n if (present(exitstatus)) exitstatus = 0\n\n if (size(cilm(:,1,1)) < 2 .or. size(cilm(1,:,1)) < lmax+1 &\n .or. size(cilm(1,1,:)) < lmax+1) then\n print*, \"Error --- SHPowerSpectrumDensityC\"\n print*, \"CILM must be dimensioned as (2, LMAX+1, LMAX+1) \" // &\n \"where LMAX is \", lmax\n print*, \"Input array is dimensioned \", size(cilm(:,1,1)), &\n size(cilm(1,:,1)), size(cilm(1,1,:))\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n else if (size(spectra) < lmax+1) then\n print*, \"Error --- SHPowerSpectrumDensityC\"\n print*, \"SPECTRA must be dimensioned as (LMAX+1) where LMAX is \", lmax\n print*, \"Input vector has dimension \", size(spectra)\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n end if\n\n spectra = 0.0_dp\n\n do l = 0, lmax\n l1 = l + 1\n\n spectra(l1) = dble(cilm(1, l1, 1))**2 + aimag(cilm(1, l1, 1))**2\n\n do m = 1, l, 1\n m1 = m + 1\n\n do i = 1, 2\n spectra(l1) = spectra(l1) + dble(cilm(i, l1, m1))**2 &\n + aimag(cilm(i, l1, m1))**2\n\n end do\n\n end do\n\n spectra(l1) = spectra(l1) / dble(2*l+1)\n\n end do\n\nend subroutine SHPowerSpectrumDensityC\n\n\nsubroutine SHCrossPowerSpectrumC(cilm1, cilm2, lmax, cspectra, exitstatus)\n!------------------------------------------------------------------------------\n!\n! This function will compute the dimensionless cross power spectrum\n! of the complex 4-pi normalized spherical harmonic coefficients\n! cilm1(i, l, m) and cilm2(1,l,m).\n!\n! CrossPower(l) = Sum_{m=0}^l ( c11lm * c21lm^* + c12lm * c22lm^* )\n!\n! Calling Parameters\n!\n! IN\n! cilm1 Complex spherical harmonic coefficients, dimensioned as\n! (2, lmax+1, lmax+1).\n! cilm2 Complex spherical harmonic coefficients, dimensioned as\n! (2, lmax+1, lmax+1).\n! lmax Spherical harmonic degree to compute power.\n! OUT\n! cspectra Array of length (lmax+1) containing the complex cross\n! power spectra of cilm1 and cilm2.\n!\n! OPTIONAL (OUT)\n! exitstatus If present, instead of executing a STOP when an error\n! is encountered, the variable exitstatus will be\n! returned describing the error.\n! 0 = No errors;\n! 1 = Improper dimensions of input array;\n! 2 = Improper bounds for input variable;\n! 3 = Error allocating memory;\n! 4 = File IO error.\n!\n! Copyright (c) 2016-2019, SHTOOLS\n! All rights reserved.\n!\n!------------------------------------------------------------------------------\n use ftypes\n\n implicit none\n\n complex(dp), intent(in) :: cilm1(:,:,:), cilm2(:,:,:)\n integer(int32), intent(in) :: lmax\n complex(dp), intent(out) :: cspectra(:)\n integer(int32), intent(out), optional :: exitstatus\n integer(int32) :: i, m, l1, m1, l\n\n if (present(exitstatus)) exitstatus = 0\n\n if (size(cilm1(:,1,1)) < 2 .or. size(cilm1(1,:,1)) < lmax+1 &\n .or. size(cilm1(1,1,:)) < lmax+1) then\n print*, \"Error --- SHCrossPowerSpectrumC\"\n print*, \"CILM1 must be dimensioned as (2, LMAX+1, LMAX+1) \" // &\n \"where lmax is\", lmax\n print*, \"Input array is dimensioned \", size(cilm1(:,1,1)), &\n size(cilm1(1,:,1)), size(cilm1(1,1,:))\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n else if (size(cilm2(:,1,1)) < 2 .or. size(cilm2(1,:,1)) < lmax+1 &\n .or. size(cilm2(1,1,:)) < lmax+1) then\n print*, \"Error --- SHCrossPowerSpectrumC\"\n print*, \"CILM2 must be dimensioned as (2, LMAX+1, LMAX+1)\"\n print*, \"Input array is dimensioned \", size(cilm2(:,1,1)), &\n size(cilm2(1,:,1)), size(cilm2(1,1,:))\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n else if (size(cspectra) < lmax+1) then\n print*, \"Error --- SHCrossPowerSpectrumC\"\n print*, \"CSPECTRA must be dimensioned as (LMAX+1) where lmax is \", lmax\n print*, \"Input vector has dimension \", size(cspectra)\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n end if\n\n cspectra = 0.0_dp\n\n do l = 0, lmax\n l1 = l + 1\n\n cspectra(l1) = cilm1(1, l1, 1) * conjg(cilm2(1, l1, 1))\n\n do m = 1, l, 1\n m1 = m + 1\n\n do i = 1, 2\n cspectra(l1) = cspectra(l1) &\n + cilm1(i, l1, m1) * conjg(cilm2(i, l1, m1))\n\n end do\n\n end do\n\n end do\n\nend subroutine SHCrossPowerSpectrumC\n\n\nsubroutine SHCrossPowerSpectrumDensityC(cilm1, cilm2, lmax, cspectra, &\n exitstatus)\n!------------------------------------------------------------------------------\n!\n! This function will compute the dimensionless cross power spectrum\n! density of the complex 4-pi normalized spherical harmonic coefficients\n! cilm1(i, l, m) and cilm2(i,l,m).\n!\n! CrossPower(l) = Sum_{m=0}^l ( c11lm * c21lm^* + c12lm * c22lm^* ) / (2l+1)\n!\n! Calling Parameters\n!\n! IN\n! cilm1 Complex spherical harmonic coefficients, dimensioned as\n! (2, lmax+1, lmax+1).\n! cilm2 Complex spherical harmonic coefficients, dimensioned as\n! (2, lmax+1, lmax+1).\n! lmax Spherical harmonic degree to compute power.\n!\n! OUT\n! cspectra Array of length (lmax+1) containing the complex cross\n! power spectral density of cilm1 and cilm2.\n!\n! OPTIONAL (OUT)\n! exitstatus If present, instead of executing a STOP when an error\n! is encountered, the variable exitstatus will be\n! returned describing the error.\n! 0 = No errors;\n! 1 = Improper dimensions of input array;\n! 2 = Improper bounds for input variable;\n! 3 = Error allocating memory;\n! 4 = File IO error.\n!\n! Copyright (c) 2005-2019, SHTOOLS\n! All rights reserved.\n!\n!------------------------------------------------------------------------------\n use ftypes\n\n implicit none\n\n complex(dp), intent(in) :: cilm1(:,:,:), cilm2(:,:,:)\n integer(int32), intent(in) :: lmax\n complex(dp), intent(out) :: cspectra(:)\n integer(int32), intent(out), optional :: exitstatus\n integer(int32) :: i, m, l1, m1, l\n\n if (present(exitstatus)) exitstatus = 0\n\n if (size(cilm1(:,1,1)) < 2 .or. size(cilm1(1,:,1)) < lmax+1 &\n .or. size(cilm1(1,1,:)) < lmax+1) then\n print*, \"Error --- SHCrossPowerSpectrumDensityC\"\n print*, \"CILM1 must be dimensioned as (2, LMAX+1, LMAX+1) \" // &\n \"where lmax is\", lmax\n print*, \"Input array is dimensioned \", size(cilm1(:,1,1)), &\n size(cilm1(1,:,1)), size(cilm1(1,1,:))\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n else if (size(cilm2(:,1,1)) < 2 .or. size(cilm2(1,:,1)) < lmax+1 &\n .or. size(cilm2(1,1,:)) < lmax+1) then\n print*, \"Error --- SHCrossPowerSpectrumDensityC\"\n print*, \"CILM2 must be dimensioned as (2, LMAX+1, LMAX+1)\"\n print*, \"Input array is dimensioned \", size(cilm2(:,1,1)), &\n size(cilm2(1,:,1)), size(cilm2(1,1,:))\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n else if (size(cspectra) < lmax+1) then\n print*, \"Error --- SHCrossPowerSpectrumDensityC\"\n print*, \"CSPECTRA must be dimensioned as (LMAX+1) where lmax is \", lmax\n print*, \"Input vector has dimension \", size(cspectra)\n if (present(exitstatus)) then\n exitstatus = 1\n return\n else\n stop\n end if\n\n end if\n\n cspectra = 0.0_dp\n\n do l = 0, lmax\n l1 = l + 1\n\n cspectra(l1) = cilm1(1, l1, 1) * conjg(cilm2(1, l1, 1))\n\n do m = 1, l, 1\n m1 = m + 1\n\n do i = 1, 2\n cspectra(l1) = cspectra(l1) &\n + cilm1(i, l1, m1) * conjg(cilm2(i, l1, m1))\n\n end do\n\n end do\n\n cspectra(l1) = cspectra(l1) / dble(2*l+1)\n\n end do\n\nend subroutine SHCrossPowerSpectrumDensityC\n", "meta": {"hexsha": "34395c726684f5849c8c9b76b20a932f695874be", "size": 21099, "ext": "f95", "lang": "FORTRAN", "max_stars_repo_path": "src/SHPowerSpectraC.f95", "max_stars_repo_name": "mjc87/SHTOOLS", "max_stars_repo_head_hexsha": "8d83c42d1313d5624c4db8c2e57300c5d819834e", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 251, "max_stars_repo_stars_event_min_datetime": "2015-01-27T12:58:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T17:19:36.000Z", "max_issues_repo_path": "src/SHPowerSpectraC.f95", "max_issues_repo_name": "mjc87/SHTOOLS", "max_issues_repo_head_hexsha": "8d83c42d1313d5624c4db8c2e57300c5d819834e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 193, "max_issues_repo_issues_event_min_datetime": "2015-03-11T06:21:08.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T14:05:45.000Z", "max_forks_repo_path": "src/SHPowerSpectraC.f95", "max_forks_repo_name": "mreineck/SHTOOLS", "max_forks_repo_head_hexsha": "fec33f203ee0b47008fd69d4080304d6ebd272e7", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 100, "max_forks_repo_forks_event_min_datetime": "2015-04-03T07:11:05.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-23T23:46:33.000Z", "avg_line_length": 31.8716012085, "max_line_length": 80, "alphanum_fraction": 0.4977487085, "num_tokens": 6200, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8902942173896131, "lm_q2_score": 0.731058584489497, "lm_q1q2_score": 0.6508572303440351}} {"text": " FUNCTION elle(phi,ak)\r\n REAL elle,ak,phi\r\nCU USES rd,rf\r\n REAL cc,q,s,rd,rf\r\n s=sin(phi)\r\n cc=cos(phi)**2\r\n q=(1.-s*ak)*(1.+s*ak)\r\n elle=s*(rf(cc,q,1.)-((s*ak)**2)*rd(cc,q,1.)/3.)\r\n return\r\n END\r\n", "meta": {"hexsha": "c060ffe52a19e8c8778ead62ed23971f04171281", "size": 245, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "NR-Functions/Numerical Recipes- Example & Functions/Functions/elle.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/elle.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/elle.for", "max_forks_repo_name": "DingdingLuan/nrfunctions_fortran", "max_forks_repo_head_hexsha": "37e376dab8d6b99e63f6f1398d0c33d5d6ad3f8c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.2727272727, "max_line_length": 54, "alphanum_fraction": 0.4408163265, "num_tokens": 96, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.7310585727705126, "lm_q1q2_score": 0.6508572262945986}} {"text": "SUBROUTINE InvertMatrix(M,rank)\n! By Allan P. Engsig-Karup.\nUSE GlobalVariables\nIMPLICIT NONE\nINTEGER :: rank, lwork, info\nREAL(KIND=long), DIMENSION(rank,rank) :: M\nREAL(KIND=long), DIMENSION(5*rank**2) :: work\nINTEGER, DIMENSION(rank) :: ipiv\nrank = SIZE(M,1)\nCALL dgetrf(rank,rank,M,rank,ipiv,info)\nIF(info/=0)THEN\n PRINT *, 'Problems with L-U of the finite-difference matrix',info\n STOP\nEND IF\nlwork=rank\nCALL dgetri(rank,M,rank,ipiv,work,lwork,info)\n IF(info/=0)THEN\n PRINT *, 'Problems with inversion of the finite-difference matrix',info\n STOP\nEND IF\nEND SUBROUTINE InvertMatrix\n", "meta": {"hexsha": "68358fa77452d615d5182dac172d826e554b4fdc", "size": 593, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/wrappers/InvertMatrix.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/wrappers/InvertMatrix.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/wrappers/InvertMatrix.f90", "max_forks_repo_name": "apengsigkarup/OceanWave3D", "max_forks_repo_head_hexsha": "91979da3ede3215b2ae65bffab89b695ff17f112", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2015-10-01T12:17:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-02T16:23:37.000Z", "avg_line_length": 26.9545454545, "max_line_length": 73, "alphanum_fraction": 0.7403035413, "num_tokens": 197, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.7310585669110203, "lm_q1q2_score": 0.6508572168219883}} {"text": "PROGRAM factorial_program\n IMPLICIT NONE\n\n INTEGER :: n, factorial = 1, i\n PRINT *, \"Enter number: \" \n READ *, n\n DO i = 1, n\n factorial = factorial * i \n ENDDO\n WRITE(*, 10) factorial \n 10 FORMAT(\"Factorial is \", i5)\n\nEND", "meta": {"hexsha": "2ec77c41d7e4ad7a9d4540cbd91da2cab2e8ce05", "size": 253, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Learning FORTRAN Concepts/8.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": "Learning FORTRAN Concepts/8.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": "Learning FORTRAN Concepts/8.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": 19.4615384615, "max_line_length": 34, "alphanum_fraction": 0.5731225296, "num_tokens": 78, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319862, "lm_q2_score": 0.7431680199891789, "lm_q1q2_score": 0.650856889334015}} {"text": " REAL FUNCTION SDASNM (NEQ, V, WT, RWORK, IWORK)\nc Copyright (c) 2006, Math a la Carte, Inc.\nc>> 2003-03-06 sdasnm Hanson changed norm computation to use reciprocals\nc>> 2001-11-23 sdasnm Krogh Changed many names per library conventions.\nc>> 2001-11-04 sdasnm Krogh Fixes for F77 and conversion to single\nc>> 2001-11-01 sdasnm Hanson Provide code to Math a la Carte.\nc--S replaces \"?\": ?DASNM, ?DASLX\nc IMPLICIT NONE\nC***BEGIN PROLOGUE SDASNM\nC***SUBSIDIARY\nC***PURPOSE Compute vector norm for SDASLX.\nC***LIBRARY SLATEC (SDASLX)\nC***TYPE DOUBLE PRECISION (SDASNM-S, SDASNM-D)\nC***AUTHOR Petzold, Linda R., (LLNL)\nC***DESCRIPTION\nc ----------------------------------------------------------------------\nC THIS FUNCTION ROUTINE COMPUTES THE WEIGHTED\nC ROOT-MEAN-SQUARE NORM OF THE VECTOR OF LENGTH\nC NEQ CONTAINED IN THE ARRAY V,WITH WEIGHTS\nC CONTAINED IN THE ARRAY WT OF LENGTH NEQ.\nC SDASNM=SQRT((1/NEQ)*SUM(V(I)/WT(I))**2)\nc ----------------------------------------------------------------------\nC***ROUTINES CALLED (NONE)\nC***REVISION HISTORY (YYMMDD)\nC 830315 DATE WRITTEN\nC 901009 Finished conversion to SLATEC 4.0 format (F.N.Fritsch)\nC 901019 Merged changes made by C. Ulrich with SLATEC 4.0 format.\nC 901026 Added explicit declarations for all variables and minor\nC cosmetic changes to prologue. (FNF)\nC***END PROLOGUE SDASNM\nC\n INTEGER NEQ, IWORK(*)\n REAL V(NEQ), WT(NEQ), RWORK(*)\nC\n INTEGER I\n REAL SUM, VMAX\n \n EXTERNAL R1MACH\n REAL R1MACH, G, H, T\n INTEGER L\nC\nC***FIRST EXECUTABLE STATEMENT SDASNM\n \n H=sqrt(sqrt(r1mach(2)))\n G=r1mach(1)/r1mach(4)\n sum=0.e0\n vmax=0.e0\n DO 100 I=1,NEQ\n t=abs(v(i)*wt(i))\nC If a component will have a square .gt. sqrt(huge) then\nC shift to a scaled version of the norm.\n if(t .gt. H) GO TO 110\n sum=sum+t**2\n vmax=max(vmax, t)\n \n 100 CONTINUE\nC May have a damaging underflow here. If vmax = 0 then\nC vector was flat zero. If sum of squares is .le. tiny/epsilon\nC then underflows (set to zero) may hurt accuracy. So\nC shift to a scaled version of the norm.\n I=NEQ+1\n if(sum .le. G .and. vmax .gt. 0.E0) GO TO 110\n sdasnm=sqrt(sum/neq)\n return\n \n 110 CONTINUE\n SDASNM = 0.0E0\n \nC Can start loop at I since the first I-1 components have\nC been scanned for the max abs already.\n DO 10 L = I,NEQ\n IF(ABS(V(L)*WT(L)) .GT. VMAX) VMAX = ABS(V(L)*WT(L))\n10 CONTINUE\n IF(VMAX .LE. 0.0E0) GO TO 30\n SUM = 0.0E0\n DO 20 I = 1,NEQ\n20 SUM = SUM + ((V(I)*WT(I))/VMAX)**2\n SDASNM = VMAX*SQRT(SUM/NEQ)\n30 CONTINUE\n RETURN\nc -----END OF FUNCTION SDASNM------\n END\n", "meta": {"hexsha": "af6a33afae81f4b61836f0d41019b590addd05ea", "size": 2789, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MATH77/sdasnm.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/sdasnm.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/sdasnm.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": 33.6024096386, "max_line_length": 72, "alphanum_fraction": 0.5984223736, "num_tokens": 932, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869948899666, "lm_q2_score": 0.7431680199891789, "lm_q1q2_score": 0.6508568869246496}} {"text": "c function ploren.f\nc\nc source\nc Bevington, page 51.\nc\nc purpose\nc evaluate lorentzian probability function\nc\nc usage\nc result = ploren (x, averag, width)\nc\nc description of parameters\nc x - value for which probability is to be evaluated\nc averag - mean of distribution\nc width - full width at half maximum of distribution\nc\nc subroutines and function subprograms required\nc none\nc\n\tfunction ploren (x,averag,width)\n1\tploren=0.1591549431*width/((x-averag)**2+(width/2.)**2)\n\treturn\n\tend\n", "meta": {"hexsha": "20fcb7c3656e020fd6fe0857fbefa35802d2e16f", "size": 507, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iraf.v2161/math/bevington/ploren.f", "max_stars_repo_name": "ysBach/irafdocgen", "max_stars_repo_head_hexsha": "b11fcd75cc44b01ae69c9c399e650ec100167a54", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-12-01T15:19:09.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-02T16:48:42.000Z", "max_issues_repo_path": "math/bevington/ploren.f", "max_issues_repo_name": "kirxkirx/iraf", "max_issues_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-30T13:48:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-12-02T19:40:25.000Z", "max_forks_repo_path": "math/bevington/ploren.f", "max_forks_repo_name": "kirxkirx/iraf", "max_forks_repo_head_hexsha": "fcd7569b4e0ddbea29f7dbe534a25759e0c31883", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.125, "max_line_length": 59, "alphanum_fraction": 0.7376725838, "num_tokens": 161, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8757870046160258, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6508568792073995}} {"text": "!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n! %\r\n! Copyright (C) 2015 Adrian Martinez Vargas %\r\n! %\r\n! This software may be modified and distributed under the terms %\r\n! of the MIT license. See the LICENSE.txt file for details. %\r\n! %\r\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n! %\r\n! Copyright (C) 1996, The Board of Trustees of the Leland Stanford %\r\n! Junior University. All rights reserved. %\r\n! %\r\n! The programs in GSLIB are distributed in the hope that they will be %\r\n! useful, but WITHOUT ANY WARRANTY. No author or distributor accepts %\r\n! responsibility to anyone for the consequences of using them or for %\r\n! whether they serve any particular purpose or work at all, unless he %\r\n! says so in writing. Everyone is granted permission to copy, modify %\r\n! and redistribute the programs in GSLIB, but only under the condition %\r\n! that this notice and the above copyright notice remain intact. %\r\n! %\r\n!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n!-----------------------------------------------------------------------\r\n!\r\n! The functions and subroutines below were modified from the\r\n! version 2.0 of the gslib code written in fortran 77\r\n! \r\n! The objective is to add functionality to GSLIB and to link \r\n! this code with python using f2py. It uses f90 code convention. \r\n! The arrays are dynamic and externally declared (from python)\r\n!\r\n! the code was converted from Fortran 77 to Fortran 90 using F2F.pl\r\n! \r\n! for more information please refer to:\r\n! - gslib77 source code: http://www.statios.com/software/gslib77_ls.tar.gz\r\n! - GSLIB: Geostatistical Software Library and User's Guide. Second edition \r\n! by Clayton V. Deutsch, Andre G. Journel, 1997.\r\n! - F2PY Users Guide: http://docs.scipy.org/doc/numpy-dev/f2py/\r\n! - F2F https://bitbucket.org/lemonlab/f2f\r\n!-----------------------------------------------------------------------\r\n\r\nreal function gcum(x)\r\n !-----------------------------------------------------------------------\r\n\r\n ! Evaluate the standard normal cdf given a normal deviate x. gcum is\r\n ! the area under a unit normal curve to the left of x. The results are\r\n ! accurate only to about 5 decimal places.\r\n\r\n\r\n !-----------------------------------------------------------------------\r\n \r\n real :: x, z, e2\r\n \r\n z = x\r\n if(z < 0.) z = -z\r\n t = 1./(1.+ 0.2316419*z)\r\n gcum = t*(0.31938153 + t*(-0.356563782 + t*(1.781477937 + &\r\n t*(-1.821255978 + t*1.330274429))))\r\n e2 = 0.\r\n\r\n ! 6 standard deviations out gets treated as infinity:\r\n\r\n if(z <= 6.) e2 = exp(-z*z/2.)*0.3989422803\r\n gcum = 1.0- e2 * gcum\r\n if(x >= 0.) return\r\n gcum = 1.0 - gcum\r\n \r\n return\r\n \r\nend function gcum\r\n\r\n\r\ndouble precision function dgcum(x)\r\n !-----------------------------------------------------------------------\r\n\r\n ! Evaluate the standard normal cdf given a normal deviate x. gcum is\r\n ! the area under a unit normal curve to the left of x. The results are\r\n ! accurate only to about 5 decimal places.\r\n\r\n\r\n !-----------------------------------------------------------------------\r\n \r\n real*8 :: x, z, e2, t\r\n \r\n \r\n z = x\r\n if(z < 0.) z = -z\r\n t = 1./(1.+ 0.2316419*z)\r\n dgcum = t*(0.31938153 + t*(-0.356563782 + t*(1.781477937 + &\r\n t*(-1.821255978 + t*1.330274429))))\r\n e2 = 0.\r\n\r\n ! 6 standard deviations out gets treated as infinity:\r\n\r\n if(z <= 6.) e2 = exp(-z*z/2.)*0.3989422803\r\n dgcum = 1.0- e2 * dgcum\r\n if(x >= 0.) return\r\n dgcum = 1.0 - dgcum\r\n \r\n return\r\n \r\nend function dgcum\r\n", "meta": {"hexsha": "f9ce6a2756198cc04cb015229d3064f04dfdec2b", "size": 4238, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "for_code/gcum.f90", "max_stars_repo_name": "cmrajan/pygslib", "max_stars_repo_head_hexsha": "acdf96d9ec17658f18fe9f078104c6259b479f52", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 94, "max_stars_repo_stars_event_min_datetime": "2015-10-23T20:35:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T08:24:49.000Z", "max_issues_repo_path": "for_code/gcum.f90", "max_issues_repo_name": "kaufmanno/pygslib", "max_issues_repo_head_hexsha": "7fb0c201eba6304b1914cf88a437aa9dc42e7021", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 55, "max_issues_repo_issues_event_min_datetime": "2016-09-19T17:20:46.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-20T03:44:01.000Z", "max_forks_repo_path": "for_code/gcum.f90", "max_forks_repo_name": "kaufmanno/pygslib", "max_forks_repo_head_hexsha": "7fb0c201eba6304b1914cf88a437aa9dc42e7021", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 47, "max_forks_repo_forks_event_min_datetime": "2016-03-31T08:17:47.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T02:35:33.000Z", "avg_line_length": 41.145631068, "max_line_length": 77, "alphanum_fraction": 0.4480887211, "num_tokens": 976, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757870046160257, "lm_q2_score": 0.7431680029241321, "lm_q1q2_score": 0.6508568792073994}} {"text": "program problem73\n use euler\n implicit none\n integer, parameter :: limit=12000\n real*16, parameter :: lower=1.0q0/3.0q0,upper=1.0q0/2.0q0\n real*16 :: temp\n integer :: n,d,answer\n\n answer=0\n\n do d=2,limit\n do n=1,d\n temp=real(n,16)/real(d,16)\n if (lower meas_thresh, DIM=2) !identify all valid rows\n! unfortunately, we cannot return the already cleaned matrix, because dynamically sizing the \n! the return value is not possible (afaik)\n\nend subroutine clean_data_7\n\n!===============================================================================\n", "meta": {"hexsha": "f453b14ebc5532f2a64359f83e60f67aa7fa211f", "size": 2235, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "_episodes_rmd/fortran/external_library.f90", "max_stars_repo_name": "swc-bb/2017-05-17-r-workshop", "max_stars_repo_head_hexsha": "09442ef8e22bfecd8c548552d79fe2f29e5acd15", "max_stars_repo_licenses": ["CC-BY-4.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": "_episodes_rmd/fortran/external_library.f90", "max_issues_repo_name": "swc-bb/2017-05-17-r-workshop", "max_issues_repo_head_hexsha": "09442ef8e22bfecd8c548552d79fe2f29e5acd15", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-03-26T13:23:01.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-26T13:25:56.000Z", "max_forks_repo_path": "_episodes_rmd/fortran/external_library.f90", "max_forks_repo_name": "swc-bb/2017-05-17-r-workshop", "max_forks_repo_head_hexsha": "09442ef8e22bfecd8c548552d79fe2f29e5acd15", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.5869565217, "max_line_length": 114, "alphanum_fraction": 0.4617449664, "num_tokens": 385, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8006920116079209, "lm_q2_score": 0.8128673201042492, "lm_q1q2_score": 0.6508563697046111}} {"text": "! { dg-do run }\n\nfunction dotprod_ref (B, C, N) result (sum)\n implicit none\n real :: B(N), C(N), sum\n integer :: N, i\n sum = 0.0e0\n do i = 1, N\n sum = sum + B(i) * C(i)\n end do\nend function\n\nfunction dotprod (B, C, N) result(sum)\n real :: B(N), C(N), sum\n integer :: N, i\n sum = 0.0e0\n !$omp target teams map(to: B, C) map(tofrom: sum) &\n !$omp& reduction(+:sum)\n !$omp distribute parallel do reduction(+:sum)\n do i = 1, N\n sum = sum + B(i) * C(i)\n end do\n !$omp end target teams\nend function\n\nsubroutine init (B, C, N)\n real :: B(N), C(N)\n integer :: N, i\n do i = 1, N\n B(i) = 0.0001 * i\n C(i) = 0.000001 * i * i\n end do\nend subroutine\n\nsubroutine check (a, b)\n real :: a, b, err\n real, parameter :: EPS = 0.0001\n if (b == 0.0) then\n err = a\n else if (a == 0.0) then\n err = b\n else\n err = (a - b) / b\n end if\n if (err > EPS .or. err < -EPS) call abort\nend subroutine\n\nprogram e_54_3\n integer :: n\n real :: ref, d\n real, pointer, dimension(:) :: B, C\n n = 1024 * 1024\n allocate (B(n), C(n))\n call init (B, C, n)\n ref = dotprod_ref (B, C, n)\n d = dotprod (B, C, n)\n call check (ref, d)\n deallocate (B, C)\nend program\n", "meta": {"hexsha": "9de77afd7d2abf659ac54895632764f98914ccc6", "size": 1181, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gcc-gcc-7_3_0-release/libgomp/testsuite/libgomp.fortran/examples-4/teams-3.f90", "max_stars_repo_name": "best08618/asylo", "max_stars_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-05-02T17:34:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-17T10:15:18.000Z", "max_issues_repo_path": "gcc-gcc-7_3_0-release/libgomp/testsuite/libgomp.fortran/examples-4/teams-3.f90", "max_issues_repo_name": "best08618/asylo", "max_issues_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "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": "gcc-gcc-7_3_0-release/libgomp/testsuite/libgomp.fortran/examples-4/teams-3.f90", "max_forks_repo_name": "best08618/asylo", "max_forks_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-27T00:22:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-01T09:41:02.000Z", "avg_line_length": 19.6833333333, "max_line_length": 53, "alphanum_fraction": 0.5461473328, "num_tokens": 475, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673178375735, "lm_q2_score": 0.8006919925839875, "lm_q1q2_score": 0.6508563524257682}} {"text": "PROGRAM teoric_algorithm\n\n use gs\n\n implicit none\n\n ! PARAMETERS\n integer, parameter :: MAXIT = 1000\n\n ! LOCAL ARRAYS\n real(8), allocatable :: M(:,:),b(:),x(:),rv(:),sol(:)\n integer, allocatable :: seed(:)\n\n ! LOCAL SCALARS\n real(8) :: r,mr,msdiff,mt,miter\n integer :: i,k,n,status,rsize,t1,t2,clock_rate,clock_max,iter\n \n write(*,*) \"Type dimension...\"\n read(*,*) n\n\n allocate(M(n,n),b(n),x(n),rv(n),sol(n),STAT=status)\n\n if (status .ne. 0) then\n write(*,*) \"Memory problems\"\n stop\n end if\n\n CALL RANDOM_SEED(SIZE=rsize)\n\n allocate(seed(rsize))\n do i = 1,rsize\n seed(i) = 123456789\n end do\n\n CALL RANDOM_SEED(PUT=seed)\n\n write(*,*) \"Starting serial CCS...\"\n\n call genDDRandSystem(n,M,b,sol)\n\n do i = 1,n\n x(i) = 0.0D0\n end do\n\n CALL SYSTEM_CLOCK(t1,clock_rate,clock_max)\n\n CALL serialccs(5*n,n,M,b,x,r,iter,1.0D-5,MAXIT)\n \n CALL SYSTEM_CLOCK(t2,clock_rate,clock_max)\n\n write(*,9000) r,(t2 - t1) / (1.0 * clock_rate),iter,maxval(abs(x - sol))\n\n9000 FORMAT('RESIDUAL:',1X,D12.5,1X,'TIME (in secs):',1X,F7.4,&\n 1X,'ITERATIONS:',1X,I8,1X,'DIFF',1X,D12.5)\n\ncontains\n\n subroutine genDDRandSystem(n,A,b,sol)\n \n ! Generates a random diagonal dominant linear system\n\n ! ARGUMENTS\n integer :: n\n real(8) :: A(n,n),b(n),sol(n)\n\n intent(out) :: A,b,sol\n intent(in ) :: n\n\n ! LOCAL SCALARS\n integer :: i,j\n real(8) :: rnumber,s\n\n do i = 1,n\n s = 0.0D0\n do j = 2,n\n CALL RANDOM_NUMBER(rnumber)\n M(i,j) = - n + 2 * n * rnumber\n s = s + abs(M(i,j))\n end do\n M(i,i) = s\n end do\n\n do i = 1,n\n CALL RANDOM_NUMBER(rnumber)\n sol(i) = - n + 2 * n * rnumber\n b(i) = 0.0D0\n end do\n\n do j = 1,n\n do i = 1,n\n b(i) = b(i) + A(i,j) * sol(j)\n end do\n end do \n\n end subroutine genDDRandSystem\n\nEND PROGRAM teoric_algorithm\n", "meta": {"hexsha": "db87f1326e4ac02eee88513304c60e516d94b1f0", "size": 1898, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran/teo_alg.f90", "max_stars_repo_name": "fsobral/ccs", "max_stars_repo_head_hexsha": "5f78b24f394c5476cbf5d56b3e694ce2442ddb5b", "max_stars_repo_licenses": ["Beerware"], "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/teo_alg.f90", "max_issues_repo_name": "fsobral/ccs", "max_issues_repo_head_hexsha": "5f78b24f394c5476cbf5d56b3e694ce2442ddb5b", "max_issues_repo_licenses": ["Beerware"], "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/teo_alg.f90", "max_forks_repo_name": "fsobral/ccs", "max_forks_repo_head_hexsha": "5f78b24f394c5476cbf5d56b3e694ce2442ddb5b", "max_forks_repo_licenses": ["Beerware"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.3673469388, "max_line_length": 74, "alphanum_fraction": 0.5626975764, "num_tokens": 686, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8128673087708698, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.6508563490321146}} {"text": "submodule (stdlib_stats) stdlib_stats_moment_all\n\n use, intrinsic:: ieee_arithmetic, only: ieee_value, ieee_quiet_nan\n use stdlib_error, only: error_stop\n use stdlib_optval, only: optval\n implicit none\n\ncontains\n\n module function moment_all_1_rdp_rdp(x, order, center, mask) result(res)\n real(dp), intent(in) :: x(:)\n integer, intent(in) :: order\n real(dp), intent(in), optional :: center\n logical, intent(in), optional :: mask\n real(dp) :: res\n\n real(dp) :: n\n real(dp) :: center_\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n\n if (present(center)) then\n center_ = center\n else\n center_ = mean(x)\n end if\n res = sum((x - center_)**order) / n\n\n end function moment_all_1_rdp_rdp\n module function moment_all_2_rdp_rdp(x, order, center, mask) result(res)\n real(dp), intent(in) :: x(:,:)\n integer, intent(in) :: order\n real(dp), intent(in), optional :: center\n logical, intent(in), optional :: mask\n real(dp) :: res\n\n real(dp) :: n\n real(dp) :: center_\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n\n if (present(center)) then\n center_ = center\n else\n center_ = mean(x)\n end if\n res = sum((x - center_)**order) / n\n\n end function moment_all_2_rdp_rdp\n module function moment_all_3_rdp_rdp(x, order, center, mask) result(res)\n real(dp), intent(in) :: x(:,:,:)\n integer, intent(in) :: order\n real(dp), intent(in), optional :: center\n logical, intent(in), optional :: mask\n real(dp) :: res\n\n real(dp) :: n\n real(dp) :: center_\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n\n if (present(center)) then\n center_ = center\n else\n center_ = mean(x)\n end if\n res = sum((x - center_)**order) / n\n\n end function moment_all_3_rdp_rdp\n module function moment_all_4_rdp_rdp(x, order, center, mask) result(res)\n real(dp), intent(in) :: x(:,:,:,:)\n integer, intent(in) :: order\n real(dp), intent(in), optional :: center\n logical, intent(in), optional :: mask\n real(dp) :: res\n\n real(dp) :: n\n real(dp) :: center_\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n\n if (present(center)) then\n center_ = center\n else\n center_ = mean(x)\n end if\n res = sum((x - center_)**order) / n\n\n end function moment_all_4_rdp_rdp\n module function moment_all_1_cdp_cdp(x, order, center, mask) result(res)\n complex(dp), intent(in) :: x(:)\n integer, intent(in) :: order\n complex(dp), intent(in), optional :: center\n logical, intent(in), optional :: mask\n complex(dp) :: res\n\n real(dp) :: n\n complex(dp) :: center_\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n\n if (present(center)) then\n center_ = center\n else\n center_ = mean(x)\n end if\n res = sum((x - center_)**order) / n\n\n end function moment_all_1_cdp_cdp\n module function moment_all_2_cdp_cdp(x, order, center, mask) result(res)\n complex(dp), intent(in) :: x(:,:)\n integer, intent(in) :: order\n complex(dp), intent(in), optional :: center\n logical, intent(in), optional :: mask\n complex(dp) :: res\n\n real(dp) :: n\n complex(dp) :: center_\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n\n if (present(center)) then\n center_ = center\n else\n center_ = mean(x)\n end if\n res = sum((x - center_)**order) / n\n\n end function moment_all_2_cdp_cdp\n module function moment_all_3_cdp_cdp(x, order, center, mask) result(res)\n complex(dp), intent(in) :: x(:,:,:)\n integer, intent(in) :: order\n complex(dp), intent(in), optional :: center\n logical, intent(in), optional :: mask\n complex(dp) :: res\n\n real(dp) :: n\n complex(dp) :: center_\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n\n if (present(center)) then\n center_ = center\n else\n center_ = mean(x)\n end if\n res = sum((x - center_)**order) / n\n\n end function moment_all_3_cdp_cdp\n module function moment_all_4_cdp_cdp(x, order, center, mask) result(res)\n complex(dp), intent(in) :: x(:,:,:,:)\n integer, intent(in) :: order\n complex(dp), intent(in), optional :: center\n logical, intent(in), optional :: mask\n complex(dp) :: res\n\n real(dp) :: n\n complex(dp) :: center_\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n\n if (present(center)) then\n center_ = center\n else\n center_ = mean(x)\n end if\n res = sum((x - center_)**order) / n\n\n end function moment_all_4_cdp_cdp\n\n\n module function moment_all_1_iint32_dp(x, order, center, mask) result(res)\n integer(int32), intent(in) :: x(:)\n integer, intent(in) :: order\n real(dp), intent(in), optional :: center\n logical, intent(in), optional :: mask\n real(dp) :: res\n\n real(dp) :: n\n real(dp) :: center_\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n\n if (present(center)) then\n center_ = center\n else\n center_ = mean(x)\n end if\n res = sum((real(x, dp) - center_)**order) / n\n\n end function moment_all_1_iint32_dp\n module function moment_all_2_iint32_dp(x, order, center, mask) result(res)\n integer(int32), intent(in) :: x(:,:)\n integer, intent(in) :: order\n real(dp), intent(in), optional :: center\n logical, intent(in), optional :: mask\n real(dp) :: res\n\n real(dp) :: n\n real(dp) :: center_\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n\n if (present(center)) then\n center_ = center\n else\n center_ = mean(x)\n end if\n res = sum((real(x, dp) - center_)**order) / n\n\n end function moment_all_2_iint32_dp\n module function moment_all_3_iint32_dp(x, order, center, mask) result(res)\n integer(int32), intent(in) :: x(:,:,:)\n integer, intent(in) :: order\n real(dp), intent(in), optional :: center\n logical, intent(in), optional :: mask\n real(dp) :: res\n\n real(dp) :: n\n real(dp) :: center_\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n\n if (present(center)) then\n center_ = center\n else\n center_ = mean(x)\n end if\n res = sum((real(x, dp) - center_)**order) / n\n\n end function moment_all_3_iint32_dp\n module function moment_all_4_iint32_dp(x, order, center, mask) result(res)\n integer(int32), intent(in) :: x(:,:,:,:)\n integer, intent(in) :: order\n real(dp), intent(in), optional :: center\n logical, intent(in), optional :: mask\n real(dp) :: res\n\n real(dp) :: n\n real(dp) :: center_\n\n if (.not.optval(mask, .true.)) then\n res = ieee_value(1._dp, ieee_quiet_nan)\n return\n end if\n\n n = real(size(x, kind = int64), dp)\n\n if (present(center)) then\n center_ = center\n else\n center_ = mean(x)\n end if\n res = sum((real(x, dp) - center_)**order) / n\n\n end function moment_all_4_iint32_dp\n\n\n module function moment_mask_all_1_rdp_rdp(x, order, center, mask) result(res)\n real(dp), intent(in) :: x(:)\n integer, intent(in) :: order\n real(dp), intent(in), optional :: center\n logical, intent(in) :: mask(:)\n real(dp) :: res\n\n real(dp) :: n\n real(dp) :: center_\n\n n = real(count(mask, kind = int64), dp)\n\n if (present(center)) then\n center_ = center\n else\n center_ = mean(x, mask)\n end if\n res = sum((x - center_)**order, mask) / n\n\n end function moment_mask_all_1_rdp_rdp\n module function moment_mask_all_2_rdp_rdp(x, order, center, mask) result(res)\n real(dp), intent(in) :: x(:,:)\n integer, intent(in) :: order\n real(dp), intent(in), optional :: center\n logical, intent(in) :: mask(:,:)\n real(dp) :: res\n\n real(dp) :: n\n real(dp) :: center_\n\n n = real(count(mask, kind = int64), dp)\n\n if (present(center)) then\n center_ = center\n else\n center_ = mean(x, mask)\n end if\n res = sum((x - center_)**order, mask) / n\n\n end function moment_mask_all_2_rdp_rdp\n module function moment_mask_all_3_rdp_rdp(x, order, center, mask) result(res)\n real(dp), intent(in) :: x(:,:,:)\n integer, intent(in) :: order\n real(dp), intent(in), optional :: center\n logical, intent(in) :: mask(:,:,:)\n real(dp) :: res\n\n real(dp) :: n\n real(dp) :: center_\n\n n = real(count(mask, kind = int64), dp)\n\n if (present(center)) then\n center_ = center\n else\n center_ = mean(x, mask)\n end if\n res = sum((x - center_)**order, mask) / n\n\n end function moment_mask_all_3_rdp_rdp\n module function moment_mask_all_4_rdp_rdp(x, order, center, mask) result(res)\n real(dp), intent(in) :: x(:,:,:,:)\n integer, intent(in) :: order\n real(dp), intent(in), optional :: center\n logical, intent(in) :: mask(:,:,:,:)\n real(dp) :: res\n\n real(dp) :: n\n real(dp) :: center_\n\n n = real(count(mask, kind = int64), dp)\n\n if (present(center)) then\n center_ = center\n else\n center_ = mean(x, mask)\n end if\n res = sum((x - center_)**order, mask) / n\n\n end function moment_mask_all_4_rdp_rdp\n module function moment_mask_all_1_cdp_cdp(x, order, center, mask) result(res)\n complex(dp), intent(in) :: x(:)\n integer, intent(in) :: order\n complex(dp), intent(in), optional :: center\n logical, intent(in) :: mask(:)\n complex(dp) :: res\n\n real(dp) :: n\n complex(dp) :: center_\n\n n = real(count(mask, kind = int64), dp)\n\n if (present(center)) then\n center_ = center\n else\n center_ = mean(x, mask)\n end if\n res = sum((x - center_)**order, mask) / n\n\n end function moment_mask_all_1_cdp_cdp\n module function moment_mask_all_2_cdp_cdp(x, order, center, mask) result(res)\n complex(dp), intent(in) :: x(:,:)\n integer, intent(in) :: order\n complex(dp), intent(in), optional :: center\n logical, intent(in) :: mask(:,:)\n complex(dp) :: res\n\n real(dp) :: n\n complex(dp) :: center_\n\n n = real(count(mask, kind = int64), dp)\n\n if (present(center)) then\n center_ = center\n else\n center_ = mean(x, mask)\n end if\n res = sum((x - center_)**order, mask) / n\n\n end function moment_mask_all_2_cdp_cdp\n module function moment_mask_all_3_cdp_cdp(x, order, center, mask) result(res)\n complex(dp), intent(in) :: x(:,:,:)\n integer, intent(in) :: order\n complex(dp), intent(in), optional :: center\n logical, intent(in) :: mask(:,:,:)\n complex(dp) :: res\n\n real(dp) :: n\n complex(dp) :: center_\n\n n = real(count(mask, kind = int64), dp)\n\n if (present(center)) then\n center_ = center\n else\n center_ = mean(x, mask)\n end if\n res = sum((x - center_)**order, mask) / n\n\n end function moment_mask_all_3_cdp_cdp\n module function moment_mask_all_4_cdp_cdp(x, order, center, mask) result(res)\n complex(dp), intent(in) :: x(:,:,:,:)\n integer, intent(in) :: order\n complex(dp), intent(in), optional :: center\n logical, intent(in) :: mask(:,:,:,:)\n complex(dp) :: res\n\n real(dp) :: n\n complex(dp) :: center_\n\n n = real(count(mask, kind = int64), dp)\n\n if (present(center)) then\n center_ = center\n else\n center_ = mean(x, mask)\n end if\n res = sum((x - center_)**order, mask) / n\n\n end function moment_mask_all_4_cdp_cdp\n\n\n module function moment_mask_all_1_iint32_dp(x, order, center, mask) result(res)\n integer(int32), intent(in) :: x(:)\n integer, intent(in) :: order\n real(dp),intent(in), optional :: center\n logical, intent(in) :: mask(:)\n real(dp) :: res\n\n real(dp) :: n\n real(dp) :: center_\n\n n = real(count(mask, kind = int64), dp)\n\n if (present(center)) then\n center_ = center\n else\n center_ = mean(x, mask)\n end if\n res = sum((real(x, dp) - center_)**order, mask) / n\n\n end function moment_mask_all_1_iint32_dp\n module function moment_mask_all_2_iint32_dp(x, order, center, mask) result(res)\n integer(int32), intent(in) :: x(:,:)\n integer, intent(in) :: order\n real(dp),intent(in), optional :: center\n logical, intent(in) :: mask(:,:)\n real(dp) :: res\n\n real(dp) :: n\n real(dp) :: center_\n\n n = real(count(mask, kind = int64), dp)\n\n if (present(center)) then\n center_ = center\n else\n center_ = mean(x, mask)\n end if\n res = sum((real(x, dp) - center_)**order, mask) / n\n\n end function moment_mask_all_2_iint32_dp\n module function moment_mask_all_3_iint32_dp(x, order, center, mask) result(res)\n integer(int32), intent(in) :: x(:,:,:)\n integer, intent(in) :: order\n real(dp),intent(in), optional :: center\n logical, intent(in) :: mask(:,:,:)\n real(dp) :: res\n\n real(dp) :: n\n real(dp) :: center_\n\n n = real(count(mask, kind = int64), dp)\n\n if (present(center)) then\n center_ = center\n else\n center_ = mean(x, mask)\n end if\n res = sum((real(x, dp) - center_)**order, mask) / n\n\n end function moment_mask_all_3_iint32_dp\n module function moment_mask_all_4_iint32_dp(x, order, center, mask) result(res)\n integer(int32), intent(in) :: x(:,:,:,:)\n integer, intent(in) :: order\n real(dp),intent(in), optional :: center\n logical, intent(in) :: mask(:,:,:,:)\n real(dp) :: res\n\n real(dp) :: n\n real(dp) :: center_\n\n n = real(count(mask, kind = int64), dp)\n\n if (present(center)) then\n center_ = center\n else\n center_ = mean(x, mask)\n end if\n res = sum((real(x, dp) - center_)**order, mask) / n\n\n end function moment_mask_all_4_iint32_dp\n\nend submodule\n", "meta": {"hexsha": "9cba8721651b5ee42aec82915809e1c16b8d09d6", "size": 16054, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/stdlib_stats_moment_all.f90", "max_stars_repo_name": "zoziha/dp-stdlib", "max_stars_repo_head_hexsha": "d317f4d273cb0fcabf532578a7ec0e4687e18700", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-12-08T04:45:43.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-09T11:42:41.000Z", "max_issues_repo_path": "src/stdlib_stats_moment_all.f90", "max_issues_repo_name": "zoziha/dp-stdlib", "max_issues_repo_head_hexsha": "d317f4d273cb0fcabf532578a7ec0e4687e18700", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2021-12-08T12:35:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-17T02:33:12.000Z", "max_forks_repo_path": "src/stdlib_stats_moment_all.f90", "max_forks_repo_name": "zoziha/dp-stdlib", "max_forks_repo_head_hexsha": "d317f4d273cb0fcabf532578a7ec0e4687e18700", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-09T01:54:34.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-09T01:54:34.000Z", "avg_line_length": 28.770609319, "max_line_length": 85, "alphanum_fraction": 0.5375607325, "num_tokens": 4316, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267626522814, "lm_q2_score": 0.7490872243177518, "lm_q1q2_score": 0.6508270280481756}} {"text": "program problem58\n use euler\n implicit none\n integer :: len,total,numprime\n integer*8 :: temp\n\n total=1\n numprime=0\n\n do len=3,huge(len),2\n total=total+4\n\n temp=(len**2)-(len-1)\n if (is_prime(temp)) numprime=numprime+1\n temp=temp-(len-1)\n if (is_prime(temp)) numprime=numprime+1\n temp=temp-(len-1)\n if (is_prime(temp)) numprime=numprime+1\n\n if (real(numprime)/total < 0.10) go to 100\n end do\n\n100 continue\n print *, len, total, numprime\n\nend program problem58\n", "meta": {"hexsha": "e3f3f27632f7480ea8ae033f927015b8adf747d7", "size": 503, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "problem58.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": "problem58.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": "problem58.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": 18.6296296296, "max_line_length": 47, "alphanum_fraction": 0.6461232604, "num_tokens": 167, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267830311354, "lm_q2_score": 0.749087201911703, "lm_q1q2_score": 0.6508270238467394}} {"text": "!***********************************/\n!\tName:\u975e\u69cb\u9020\u683c\u5b50\u304b\u3089\u69cb\u9020\u683c\u5b50\u3078\u306e\u30c7\u30fc\u30bf\u79fb\u52d5\n!\tAlias:OOverSetS2U\n!\tDescription:\n!\tType:Geom,CellCenter\n!\tInput:Geom,CC\n!\tOutput:CC%PrimitiveVariable\n!\tNote:\n!\tAuthor:Akitaka Toyota\n!\tDate:2017.11.24\n!\tUpdate:2017.11.24\n!\tOther:\n!***********************************/\nsubroutine OMakeTransformationMatrix(MG,Geom)\n use StructVar_Mod\n use LoopVar_Mod\n implicit none\n type(Geometry), intent(in) :: Geom\n type(MoveGrid), intent(inout) :: MG\n double precision, allocatable :: TmpTransformation(:,:)\n !double precision, allocatable :: RotationalMatrix(:,:,:)\n\n! write(6,*) \"Make Transformation Matrix of Moving Grid\"\n allocate(TmpTransformation(4,4))\n if(Geom%Dimension == 2) then\n\n TmpTransformation = 0.0d0\n\n TmpTransformation(1,1) = cos(MG%GCD%Rotation(3))\n TmpTransformation(1,2) = sin(MG%GCD%Rotation(3))\n TmpTransformation(2,1) = -sin(MG%GCD%Rotation(3))\n TmpTransformation(2,2) = cos(MG%GCD%Rotation(3))\n\n TmpTransformation(3,3) = 1.0d0\n\n TmpTransformation(1:3,4) = MG%GCD%Translation(:)\n TmpTransformation(4,4) = 1.0d0\n\n MG%TM%Next2Current = TmpTransformation\n\n MG%TM%Current2Top = MG%TM%Next2Top\n\n MG%TM%Next2Top = matmul(MG%TM%Current2Top,MG%TM%Next2Current)\n\n call MakeInverseMatrix\n !else\n ! allocate(RotationalMatrix(3,3,3))\n !\n end if\n\nreturn\ncontains\n\n subroutine MakeInverseMatrix\n implicit none\n\n MG%TM%Current2Next(1:3,1:3) = transpose(MG%TM%Next2Current(1:3,1:3)) !\u56de\u8ee2\u884c\u5217\u3092\u53cd\u8ee2\u3055\u305b\u308b\n MG%TM%Current2Next(1:3,4) = - matmul(transpose(MG%TM%Next2Current(1:3,1:3)),MG%TM%Next2Current(1:3,4)) !\u5e73\u884c\u79fb\u52d5\u30d9\u30af\u30c8\u30eb\u306e\u5ea7\u6a19\u3092\u5909\u63db\u3059\u308b\n MG%TM%Current2Next(4,1:4) = MG%TM%Next2Current(4,1:4) !\u6700\u5f8c\u306e\u884c\u306f\u540c\u3058\n\n MG%TM%Top2Current = MG%TM%Top2Next\n\n MG%TM%Top2Next = matmul(MG%TM%Current2Next,MG%TM%Top2Current)\n\n return\n end subroutine MakeInverseMatrix\n\nend subroutine OMakeTransformationMatrix\n", "meta": {"hexsha": "cdc0c46c1aa8880410d468092e601d57b4fcc8ba", "size": 1935, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "flow_solver/EulerSolver2_2018/source/MultipleOverSetMethod/MainProcess/MoveGrid/OMakeTransformationMatrix.f90", "max_stars_repo_name": "Mayu14/2D_comp_viscos", "max_stars_repo_head_hexsha": "a62633d8684b218b52e39d47a13717a1edfa4a46", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-05-08T18:00:28.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-08T18:00:28.000Z", "max_issues_repo_path": "flow_solver/EulerSolver2_2018/source/MultipleOverSetMethod/MainProcess/MoveGrid/OMakeTransformationMatrix.f90", "max_issues_repo_name": "Mayu14/2D_comp_viscos", "max_issues_repo_head_hexsha": "a62633d8684b218b52e39d47a13717a1edfa4a46", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "flow_solver/EulerSolver2_2018/source/MultipleOverSetMethod/MainProcess/MoveGrid/OMakeTransformationMatrix.f90", "max_forks_repo_name": "Mayu14/2D_comp_viscos", "max_forks_repo_head_hexsha": "a62633d8684b218b52e39d47a13717a1edfa4a46", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-02-20T09:26:27.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-20T09:26:27.000Z", "avg_line_length": 28.0434782609, "max_line_length": 124, "alphanum_fraction": 0.6573643411, "num_tokens": 705, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768557238084, "lm_q2_score": 0.6893056104028797, "lm_q1q2_score": 0.6508264038629714}} {"text": " SUBROUTINE TG01HX( COMPQ, COMPZ, L, N, M, P, N1, LBE, A, LDA,\n $ E, LDE, B, LDB, C, LDC, Q, LDQ, Z, LDZ, NR,\n $ NRBLCK, RTAU, TOL, IWORK, DWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC Given the descriptor system (A-lambda*E,B,C) with the system\nC matrices A, E and B of the form\nC\nC ( A1 X1 ) ( E1 Y1 ) ( B1 )\nC A = ( ) , E = ( ) , B = ( ) ,\nC ( 0 X2 ) ( 0 Y2 ) ( 0 )\nC\nC where\nC - B is an L-by-M matrix, with B1 an N1-by-M submatrix\nC - A is an L-by-N matrix, with A1 an N1-by-N1 submatrix\nC - E is an L-by-N matrix, with E1 an N1-by-N1 submatrix\nC with LBE nonzero sub-diagonals,\nC this routine reduces the pair (A1-lambda*E1,B1) to the form\nC\nC Qc'*[B1 A1-lambda*E1]*diag(I,Zc) =\nC\nC ( Bc Ac-lambda*Ec * )\nC ( ) ,\nC ( 0 0 Anc-lambda*Enc )\nC\nC where:\nC 1) the pencil ( Bc Ac-lambda*Ec ) has full row rank NR for\nC all finite lambda and is in a staircase form with\nC _ _ _ _\nC ( A1,0 A1,1 ... A1,k-1 A1,k )\nC ( _ _ _ )\nC ( Bc Ac ) = ( 0 A2,1 ... A2,k-1 A2,k ) , (1)\nC ( ... _ _ )\nC ( 0 0 ... Ak,k-1 Ak,k )\nC\nC _ _ _\nC ( E1,1 ... E1,k-1 E1,k )\nC ( _ _ )\nC Ec = ( 0 ... E2,k-1 E2,k ) , (2)\nC ( ... _ )\nC ( 0 ... 0 Ek,k )\nC _\nC where Ai,i-1 is an rtau(i)-by-rtau(i-1) full row rank\nC _\nC matrix (with rtau(0) = M) and Ei,i is an rtau(i)-by-rtau(i)\nC upper triangular matrix.\nC\nC 2) the pencil Anc-lambda*Enc is regular of order N1-NR with Enc\nC upper triangular; this pencil contains the uncontrollable\nC finite eigenvalues of the pencil (A1-lambda*E1).\nC\nC The transformations are applied to the whole matrices A, E, B\nC and C. The left and/or right orthogonal transformations Qc and Zc\nC performed to reduce the pencil can be optionally accumulated\nC in the matrices Q and Z, respectively.\nC\nC The reduced order descriptor system (Ac-lambda*Ec,Bc,Cc) has no\nC uncontrollable finite eigenvalues and has the same\nC transfer-function matrix as the original system (A-lambda*E,B,C).\nC\nC ARGUMENTS\nC\nC Mode Parameters\nC\nC COMPQ CHARACTER*1\nC = 'N': do not compute Q;\nC = 'I': Q is initialized to the unit matrix, and the\nC orthogonal matrix Q is returned;\nC = 'U': Q must contain an orthogonal matrix Q1 on entry,\nC and the product Q1*Q is returned.\nC\nC COMPZ CHARACTER*1\nC = 'N': do not compute Z;\nC = 'I': Z is initialized to the unit matrix, and the\nC orthogonal matrix Z is returned;\nC = 'U': Z must contain an orthogonal matrix Z1 on entry,\nC and the product Z1*Z is returned.\nC\nC Input/Output Parameters\nC\nC L (input) INTEGER\nC The number of descriptor state equations; also the number\nC of rows of matrices A, E and B. L >= 0.\nC\nC N (input) INTEGER\nC The dimension of the descriptor state vector; also the\nC number of columns of matrices A, E and C. N >= 0.\nC\nC M (input) INTEGER\nC The dimension of descriptor system input vector; also the\nC number of columns of matrix B. M >= 0.\nC\nC P (input) INTEGER\nC The dimension of descriptor system output; also the\nC number of rows of matrix C. P >= 0.\nC\nC N1 (input) INTEGER\nC The order of subsystem (A1-lambda*E1,B1,C1) to be reduced.\nC MIN(L,N) >= N1 >= 0.\nC\nC LBE (input) INTEGER\nC The number of nonzero sub-diagonals of submatrix E1.\nC MAX(0,N1-1) >= LBE >= 0.\nC\nC A (input/output) DOUBLE PRECISION array, dimension (LDA,N)\nC On entry, the leading L-by-N part of this array must\nC contain the L-by-N state matrix A in the partitioned\nC form\nC ( A1 X1 )\nC A = ( ) ,\nC ( 0 X2 )\nC\nC where A1 is N1-by-N1.\nC On exit, the leading L-by-N part of this array contains\nC the transformed state matrix,\nC\nC ( Ac * * )\nC Qc'*A*Zc = ( 0 Anc * ) ,\nC ( 0 0 * )\nC\nC where Ac is NR-by-NR and Anc is (N1-NR)-by-(N1-NR).\nC The matrix ( Bc Ac ) is in the controllability\nC staircase form (1).\nC\nC LDA INTEGER\nC The leading dimension of array A. LDA >= MAX(1,L).\nC\nC E (input/output) DOUBLE PRECISION array, dimension (LDE,N)\nC On entry, the leading L-by-N part of this array must\nC contain the L-by-N descriptor matrix E in the partitioned\nC form\nC ( E1 Y1 )\nC E = ( ) ,\nC ( 0 Y2 )\nC\nC where E1 is N1-by-N1 matrix with LBE nonzero\nC sub-diagonals.\nC On exit, the leading L-by-N part of this array contains\nC the transformed descriptor matrix\nC\nC ( Ec * * )\nC Qc'*E*Zc = ( 0 Enc * ) ,\nC ( 0 0 * )\nC\nC where Ec is NR-by-NR and Enc is (N1-NR)-by-(N1-NR).\nC Both Ec and Enc are upper triangular and Enc is\nC nonsingular.\nC\nC LDE INTEGER\nC The leading dimension of array E. LDE >= MAX(1,L).\nC\nC B (input/output) DOUBLE PRECISION array, dimension (LDB,M)\nC On entry, the leading L-by-M part of this array must\nC contain the L-by-M input matrix B in the partitioned\nC form\nC ( B1 )\nC B = ( ) ,\nC ( 0 )\nC\nC where B1 is N1-by-M.\nC On exit, the leading L-by-M part of this array contains\nC the transformed input matrix\nC\nC ( Bc )\nC Qc'*B = ( ) ,\nC ( 0 )\nC\nC where Bc is NR-by-M.\nC The matrix ( Bc Ac ) is in the controllability\nC staircase form (1).\nC\nC LDB INTEGER\nC The leading dimension of array B. LDB >= MAX(1,L).\nC\nC C (input/output) DOUBLE PRECISION array, dimension (LDC,N)\nC On entry, the leading P-by-N part of this array must\nC contain the state/output matrix C.\nC On exit, the leading P-by-N part of this array contains\nC the transformed matrix C*Zc.\nC\nC LDC INTEGER\nC The leading dimension of array C. LDC >= MAX(1,P).\nC\nC Q (input/output) DOUBLE PRECISION array, dimension (LDQ,L)\nC If COMPQ = 'N': Q is not referenced.\nC If COMPQ = 'I': on entry, Q need not be set;\nC on exit, the leading L-by-L part of this\nC array contains the orthogonal matrix Qc,\nC where Qc' is the product of transformations\nC which are applied to A, E, and B on\nC the left.\nC If COMPQ = 'U': on entry, the leading L-by-L part of this\nC array must contain an orthogonal matrix Q;\nC on exit, the leading L-by-L part of this\nC array contains the orthogonal matrix\nC Q*Qc.\nC\nC LDQ INTEGER\nC The leading dimension of array Q.\nC LDQ >= 1, if COMPQ = 'N';\nC LDQ >= MAX(1,L), if COMPQ = 'U' or 'I'.\nC\nC Z (input/output) DOUBLE PRECISION array, dimension (LDZ,N)\nC If COMPZ = 'N': Z is not referenced.\nC If COMPZ = 'I': on entry, Z need not be set;\nC on exit, the leading N-by-N part of this\nC array contains the orthogonal matrix Zc,\nC which is the product of transformations\nC applied to A, E, and C on the right.\nC If COMPZ = 'U': on entry, the leading N-by-N part of this\nC array must contain an orthogonal matrix Z;\nC on exit, the leading N-by-N part of this\nC array contains the orthogonal matrix\nC Z*Zc.\nC\nC LDZ INTEGER\nC The leading dimension of array Z.\nC LDZ >= 1, if COMPZ = 'N';\nC LDZ >= MAX(1,N), if COMPZ = 'U' or 'I'.\nC\nC NR (output) INTEGER\nC The order of the reduced matrices Ac and Ec, and the\nC number of rows of the reduced matrix Bc; also the order of\nC the controllable part of the pair (B, A-lambda*E).\nC\nC NRBLCK (output) INTEGER _\nC The number k, of full row rank blocks Ai,i in the\nC staircase form of the pencil (Bc Ac-lambda*Ec) (see (1)\nC and (2)).\nC\nC RTAU (output) INTEGER array, dimension (N1)\nC RTAU(i), for i = 1, ..., NRBLCK, is the row dimension of\nC _\nC the full row rank block Ai,i-1 in the staircase form (1).\nC\nC Tolerances\nC\nC TOL DOUBLE PRECISION\nC The tolerance to be used in rank determinations when\nC transforming (A-lambda*E, B). If the user sets TOL > 0,\nC then the given value of TOL is used as a lower bound for\nC reciprocal condition numbers in rank determinations; a\nC (sub)matrix whose estimated condition number is less than\nC 1/TOL is considered to be of full rank. If the user sets\nC TOL <= 0, then an implicitly computed, default tolerance,\nC defined by TOLDEF = L*N*EPS, is used instead, where\nC EPS is the machine precision (see LAPACK Library routine\nC DLAMCH). TOL < 1.\nC\nC Workspace\nC\nC IWORK INTEGER array, dimension (M)\nC\nC DWORK DOUBLE PRECISION array, dimension (MAX(N,L,2*M))\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value.\nC\nC METHOD\nC\nC The subroutine is based on the reduction algorithm of [1].\nC\nC REFERENCES\nC\nC [1] Varga, A.\nC Computation of Irreducible Generalized State-Space\nC Realizations.\nC Kybernetika, vol. 26, pp. 89-106, 1990.\nC\nC NUMERICAL ASPECTS\nC\nC The algorithm is numerically backward stable and requires\nC 0( N*N1**2 ) floating point operations.\nC\nC CONTRIBUTOR\nC\nC A. Varga, German Aerospace Center, DLR Oberpfaffenhofen.\nC March 1999. Based on the RASP routine RPDS05.\nC\nC REVISIONS\nC\nC V. Sima, Research Institute for Informatics, Bucharest, July 1999,\nC May 2003, Nov. 2003.\nC A. Varga, German Aerospace Center, Oberpfaffenhofen, Nov. 2003.\nC V. Sima, Jan. 2010, following Bujanovic and Drmac's suggestion.\nC V. Sima, Apr. 2017, Mar. 2019.\nC\nC KEYWORDS\nC\nC Controllability, minimal realization, orthogonal canonical form,\nC orthogonal transformation.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n INTEGER IMAX, IMIN\n PARAMETER ( IMAX = 1, IMIN = 2 )\n DOUBLE PRECISION ONE, ZERO\n PARAMETER ( ONE = 1.0D0, ZERO = 0.0D0 )\nC .. Scalar Arguments ..\n CHARACTER COMPQ, COMPZ\n INTEGER INFO, L, LBE, LDA, LDB, LDC, LDE, LDQ, LDZ, M,\n $ N, N1, NR, NRBLCK, P\n DOUBLE PRECISION TOL\nC .. Array Arguments ..\n INTEGER IWORK( * ), RTAU( * )\n DOUBLE PRECISION A( LDA, * ), B( LDB, * ), C( LDC, * ),\n $ DWORK( * ), E( LDE, * ), Q( LDQ, * ),\n $ Z( LDZ, * )\nC .. Local Scalars ..\n LOGICAL ILQ, ILZ, WITHC\n INTEGER I, IC, ICOL, ICOMPQ, ICOMPZ, IROW, ISMAX,\n $ ISMIN, J, K, MN, NF, NR1, RANK, TAUIM1\n DOUBLE PRECISION C1, C2, CO, NRMA, RCOND, S1, S2, SI, SMAX,\n $ SMAXPR, SMIN, SMINPR, SVLMAX, T, TOLZ, TT\nC .. External Functions ..\n LOGICAL LSAME\n INTEGER IDAMAX\n DOUBLE PRECISION DLAMCH, DLANGE, DNRM2\n EXTERNAL DLAMCH, DLANGE, DNRM2, IDAMAX, LSAME\nC .. External Subroutines ..\n EXTERNAL DLACPY, DLAIC1, DLARF, DLARFG, DLARTG, DLASET,\n $ DROT, DSWAP, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC ABS, DBLE, MAX, MIN, SQRT\nC\nC .. Executable Statements ..\nC\nC Decode COMPQ.\nC\n IF( LSAME( COMPQ, 'N' ) ) THEN\n ILQ = .FALSE.\n ICOMPQ = 1\n ELSE IF( LSAME( COMPQ, 'U' ) ) THEN\n ILQ = .TRUE.\n ICOMPQ = 2\n ELSE IF( LSAME( COMPQ, 'I' ) ) THEN\n ILQ = .TRUE.\n ICOMPQ = 3\n ELSE\n ICOMPQ = 0\n END IF\nC\nC Decode COMPZ.\nC\n IF( LSAME( COMPZ, 'N' ) ) THEN\n ILZ = .FALSE.\n ICOMPZ = 1\n ELSE IF( LSAME( COMPZ, 'U' ) ) THEN\n ILZ = .TRUE.\n ICOMPZ = 2\n ELSE IF( LSAME( COMPZ, 'I' ) ) THEN\n ILZ = .TRUE.\n ICOMPZ = 3\n ELSE\n ICOMPZ = 0\n END IF\nC\nC Test the input scalar parameters.\nC\n INFO = 0\n IF( ICOMPQ.LE.0 ) THEN\n INFO = -1\n ELSE IF( ICOMPZ.LE.0 ) THEN\n INFO = -2\n ELSE IF( L.LT.0 ) THEN\n INFO = -3\n ELSE IF( N.LT.0 ) THEN\n INFO = -4\n ELSE IF( M.LT.0 ) THEN\n INFO = -5\n ELSE IF( P.LT.0 ) THEN\n INFO = -6\n ELSE IF( N1.LT.0 .OR. N1.GT.MIN( L, N ) ) THEN\n INFO = -7\n ELSE IF( LBE.LT.0 .OR. LBE.GT.MAX( 0, N1-1 ) ) THEN\n INFO = -8\n ELSE IF( LDA.LT.MAX( 1, L ) ) THEN\n INFO = -10\n ELSE IF( LDE.LT.MAX( 1, L ) ) THEN\n INFO = -12\n ELSE IF( LDB.LT.MAX( 1, L ) ) THEN\n INFO = -14\n ELSE IF( LDC.LT.MAX( 1, P ) ) THEN\n INFO = -16\n ELSE IF( ( ILQ .AND. LDQ.LT.L ) .OR. LDQ.LT.1 ) THEN\n INFO = -18\n ELSE IF( ( ILZ .AND. LDZ.LT.N ) .OR. LDZ.LT.1 ) THEN\n INFO = -20\n ELSE IF( TOL.GE.ONE ) THEN\n INFO = -24\n END IF\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'TG01HX', -INFO )\n RETURN\n END IF\nC\nC Initialize Q and Z if necessary.\nC\n IF( ICOMPQ.EQ.3 )\n $ CALL DLASET( 'Full', L, L, ZERO, ONE, Q, LDQ )\n IF( ICOMPZ.EQ.3 )\n $ CALL DLASET( 'Full', N, N, ZERO, ONE, Z, LDZ )\nC\nC Initialize output variables.\nC\n NR = 0\n NRBLCK = 0\nC\nC Quick return if possible.\nC\n IF( M.EQ.0 .OR. N1.EQ.0 ) THEN\n RETURN\n END IF\nC\n TOLZ = SQRT( DLAMCH( 'Epsilon' ) )\n WITHC = P.GT.0\n SVLMAX = ZERO\n NRMA = DLANGE( 'F', L, N, A, LDA, DWORK )\n RCOND = TOL\n IF ( RCOND.LE.ZERO ) THEN\nC\nC Use the default tolerance in controllability determination.\nC\n RCOND = DBLE( L*N )*DLAMCH( 'EPSILON' )\n END IF\nC\nC Reduce E to upper triangular form if necessary.\nC\n IF( LBE.GT.0 ) THEN\n DO 10 I = 1, N1-1\nC\nC Generate elementary reflector H(i) to annihilate\nC E(i+1:i+lbe,i).\nC\n K = MIN( LBE, N1-I ) + 1\n CALL DLARFG( K, E(I,I), E(I+1,I), 1, TT )\n T = E(I,I)\n E(I,I) = ONE\nC\nC Apply H(i) to E(i:n1,i+1:n) from the left.\nC\n CALL DLARF( 'Left', K, N-I, E(I,I), 1, TT,\n $ E(I,I+1), LDE, DWORK )\nC\nC Apply H(i) to A(i:n1,1:n) from the left.\nC\n CALL DLARF( 'Left', K, N, E(I,I), 1, TT,\n $ A(I,1), LDA, DWORK )\nC\nC Apply H(i) to B(i:n1,1:m) from the left.\nC\n CALL DLARF( 'Left', K, M, E(I,I), 1, TT,\n $ B(I,1), LDB, DWORK )\n IF( ILQ ) THEN\nC\nC Apply H(i) to Q(1:l,i:n1) from the right.\nC\n CALL DLARF( 'Right', L, K, E(I,I), 1, TT,\n $ Q(1,I), LDQ, DWORK )\n END IF\n E(I,I) = T\n 10 CONTINUE\n CALL DLASET( 'Lower', N1-1, N1-1, ZERO, ZERO, E(2,1), LDE )\n END IF\nC\n ISMIN = 1\n ISMAX = ISMIN + M\n IC = -M\n TAUIM1 = M\n NF = N1\nC\n 20 CONTINUE\n NRBLCK = NRBLCK + 1\n RANK = 0\n IF( NF.GT.0 ) THEN\nC\nC IROW will point to the current pivot line in B,\nC ICOL+1 will point to the first active columns of A.\nC\n ICOL = IC + TAUIM1\n IROW = NR\n NR1 = NR + 1\n IF( NR.GT.0 ) THEN\n CALL DLACPY( 'Full', NF, TAUIM1, A(NR1,IC+1), LDA,\n $ B(NR1,1), LDB )\n IF( SVLMAX.EQ.ZERO )\n $ SVLMAX = NRMA\n END IF\nC\nC Perform QR-decomposition with column pivoting on the current B\nC while keeping E upper triangular.\nC The current B is at first iteration B and for subsequent\nC iterations the NF-by-TAUIM1 matrix delimited by rows\nC NR + 1 to N1 and columns IC + 1 to IC + TAUIM1 of A.\nC The rank of current B is computed in RANK.\nC\n IF( TAUIM1.GT.1 ) THEN\nC\nC Compute column norms.\nC\n DO 30 J = 1, TAUIM1\n DWORK(J) = DNRM2( NF, B(NR1,J), 1 )\n DWORK(M+J) = DWORK(J)\n IWORK(J) = J\n 30 CONTINUE\n END IF\nC\n MN = MIN( NF, TAUIM1 )\nC\n 40 CONTINUE\n IF( RANK.LT.MN ) THEN\n J = RANK + 1\n IROW = IROW + 1\nC\nC Pivot if necessary.\nC\n IF( J.NE.TAUIM1 ) THEN\n K = ( J - 1 ) + IDAMAX( TAUIM1-J+1, DWORK(J), 1 )\n IF( K.NE.J ) THEN\n CALL DSWAP( NF, B(NR1,J), 1, B(NR1,K), 1 )\n I = IWORK(K)\n IWORK(K) = IWORK(J)\n IWORK(J) = I\n DWORK(K) = DWORK(J)\n DWORK(M+K) = DWORK(M+J)\n END IF\n END IF\nC\nC Zero elements below the current diagonal element of B.\nC\n DO 50 I = N1-1, IROW, -1\nC\nC Rotate rows I and I+1 to zero B(I+1,J).\nC\n T = B(I,J)\n CALL DLARTG( T, B(I+1,J), CO, SI, B(I,J) )\n B(I+1,J) = ZERO\n CALL DROT( N-I+1, E(I,I), LDE, E(I+1,I), LDE, CO, SI )\n IF( J.LT.TAUIM1 )\n $ CALL DROT( TAUIM1-J, B(I,J+1), LDB,\n $ B(I+1,J+1), LDB, CO, SI )\n CALL DROT( N-ICOL, A(I,ICOL+1), LDA,\n $ A(I+1,ICOL+1), LDA, CO, SI )\n IF( ILQ ) CALL DROT( L, Q(1,I), 1, Q(1,I+1), 1, CO, SI )\nC\nC Rotate columns I, I+1 to zero E(I+1,I).\nC\n T = E(I+1,I+1)\n CALL DLARTG( T, E(I+1,I), CO, SI, E(I+1,I+1) )\n E(I+1,I) = ZERO\n CALL DROT( I, E(1,I+1), 1, E(1,I), 1, CO, SI )\n CALL DROT( N1, A(1,I+1), 1, A(1,I), 1, CO, SI )\n IF( ILZ ) CALL DROT( N, Z(1,I+1), 1, Z(1,I), 1, CO, SI )\n IF( WITHC )\n $ CALL DROT( P, C(1,I+1), 1, C(1,I), 1, CO, SI )\n 50 CONTINUE\nC\n IF( RANK.EQ.0 ) THEN\nC\nC Initialize; exit if the matrix is negligible (RANK = 0).\nC\n SMAX = ABS( B(NR1,1) )\n IF ( SMAX.LE.RCOND ) GO TO 80\n SMIN = SMAX\n SMAXPR = SMAX\n SMINPR = SMIN\n C1 = ONE\n C2 = ONE\n ELSE\nC\nC One step of incremental condition estimation.\nC\n CALL DLAIC1( IMIN, RANK, DWORK(ISMIN), SMIN,\n $ B(NR1,J), B(IROW,J), SMINPR, S1, C1 )\n CALL DLAIC1( IMAX, RANK, DWORK(ISMAX), SMAX,\n $ B(NR1,J), B(IROW,J), SMAXPR, S2, C2 )\n END IF\nC\nC Check the rank; finish the loop if rank loss occurs.\nC\n IF( SVLMAX*RCOND.LE.SMAXPR ) THEN\n IF( SVLMAX*RCOND.LE.SMINPR ) THEN\n IF( SMAXPR*RCOND.LT.SMINPR ) THEN\nC\nC Finish the loop if last row.\nC\n IF( IROW.EQ.N1 ) THEN\n RANK = RANK + 1\n GO TO 80\n END IF\nC\nC Update partial column norms.\nC\n DO 60 I = J + 1, TAUIM1\n IF( DWORK(I).NE.ZERO ) THEN\n T = ABS( B(IROW,I) )/DWORK(I)\n T = MAX( ( ONE + T )*( ONE - T ), ZERO)\n TT = T*( DWORK(I)/DWORK(M+I) )**2\n IF( TT.GT.TOLZ ) THEN\n DWORK(I) = DWORK(I)*SQRT( T )\n ELSE\n DWORK(I) = DNRM2( NF-J, B(IROW+1,I), 1 )\n DWORK(M+I) = DWORK(I)\n END IF\n END IF\n 60 CONTINUE\nC\n DO 70 I = 1, RANK\n DWORK(ISMIN+I-1) = S1*DWORK(ISMIN+I-1)\n DWORK(ISMAX+I-1) = S2*DWORK(ISMAX+I-1)\n 70 CONTINUE\nC\n DWORK(ISMIN+RANK) = C1\n DWORK(ISMAX+RANK) = C2\n SMIN = SMINPR\n SMAX = SMAXPR\n RANK = RANK + 1\n GO TO 40\n END IF\n END IF\n END IF\n IF( NR.GT.0 ) THEN\n CALL DLASET( 'Full', N1-IROW+1, TAUIM1-J+1, ZERO, ZERO,\n $ B(IROW,J), LDB )\n END IF\n GO TO 80\n END IF\n END IF\nC\n 80 IF( RANK.GT.0 ) THEN\n RTAU(NRBLCK) = RANK\nC\nC Back permute interchanged columns.\nC\n IF( TAUIM1.GT.1 ) THEN\n DO 100 J = 1, TAUIM1\n IF( IWORK(J).GT.0 ) THEN\n K = IWORK(J)\n IWORK(J) = -K\n 90 CONTINUE\n IF( K.NE.J ) THEN\n CALL DSWAP( RANK, B(NR1,J), 1, B(NR1,K), 1 )\n IWORK(K) = -IWORK(K)\n K = -IWORK(K)\n GO TO 90\n END IF\n END IF\n 100 CONTINUE\n END IF\n END IF\n IF( NR.GT.0 )\n $ CALL DLACPY( 'Full', NF, TAUIM1, B(NR1,1), LDB,\n $ A(NR1,IC+1), LDA )\n IF( RANK.GT.0 ) THEN\n NR = NR + RANK\n NF = NF - RANK\n IC = IC + TAUIM1\n TAUIM1 = RANK\n GO TO 20\n ELSE\n NRBLCK = NRBLCK - 1\n END IF\nC\n IF( NRBLCK.GT.0 ) RANK = RTAU(1)\n IF( RANK.LT.N1 )\n $ CALL DLASET( 'Full', N1-RANK, M, ZERO, ZERO, B(RANK+1,1), LDB )\nC\n RETURN\nC *** Last line of TG01HX ***\n END\n", "meta": {"hexsha": "d21cbd69131ef5e2a40448a99f5f234ec356c720", "size": 23769, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/TG01HX.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/TG01HX.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/TG01HX.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 34.9030837004, "max_line_length": 73, "alphanum_fraction": 0.4593377929, "num_tokens": 7244, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9263037343628702, "lm_q2_score": 0.7025300573952054, "lm_q1q2_score": 0.6507562156673402}} {"text": " SUBROUTINE FLUX(F,Z,TMIN,TMAX,NSTRU)\n IMPLICIT NONE\n* Returns H1 pomeron flux if NSTRU=6\n* Returns H1 reggeon flux if NSTRU=7\n* Returns flux for user defined structure function if NSTRU=8\n* B.Cox and J. Forshaw 11/05/00\n DOUBLE PRECISION F,Z,TMIN,TMAX\n DOUBLE PRECISION alpha,B,alphap\n DOUBLE PRECISION alphar,alpharp,Br,Cr\n* H1 best fits \n* PARAMETER (alpha=1.203,alphap=0.26,B=4.6)\n* PARAMETER (alphar=0.50,alpharp=0.90,Br=2.0,Cr=16.0)\n* H1 parameters with no interference (best fit to H1 F2D3 using POMWIG)\n PARAMETER (alpha=1.200,alphap=0.26,B=4.6)\n PARAMETER (alphar=0.57,alpharp=0.90,Br=2.0,Cr=48.0) \n DOUBLE PRECISION V,W,X \n INTEGER NSTRU \n \n if (NSTRU.EQ.9) then\n V = DEXP(-(B+2.D0*alphap*DLOG(1.D0/Z))*TMIN)-\n + DEXP(-(B+2.D0*alphap*DLOG(1.D0/Z))*TMAX)\n W = 1.D0/(B+2.D0*alphap*DLOG(1.D0/Z))\n X = 1.D0/(Z**(2.D0*alpha-1.D0))\n F = X*W*V\n elseif (NSTRU.EQ.10) then\n V = DEXP(-(Br+2.D0*alpharp*DLOG(1.D0/Z))*TMIN)-\n + DEXP(-(Br+2.D0*alpharp*DLOG(1.D0/Z))*TMAX)\n W = 1.D0/(Br+2.D0*alpharp*DLOG(1.D0/Z))\n X = 1.D0/(Z**(2.D0*alphar-1.D0))\n F = Cr*X*W*V \n elseif (NSTRU.EQ.11) then\n V = DEXP(-(B+2.D0*alphap*DLOG(1.D0/Z))*TMIN)-\n + DEXP(-(B+2.D0*alphap*DLOG(1.D0/Z))*TMAX)\n W = 1.D0/(B+2.D0*alphap*DLOG(1.D0/Z))\n X = 1.D0/(Z**(2.D0*alpha-1.D0))\n F = X*W*V\n else\n write(*,*) 'pomwig : NSTRU must be 9, 10 or 11 in herwig65'\n STOP\n endif\n RETURN\n END\n", "meta": {"hexsha": "aa04e8ffe8f122b2c0241bfb21773774750f84b6", "size": 1612, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "GeneratorInterface/PomwigInterface/src/flux65.f", "max_stars_repo_name": "ckamtsikis/cmssw", "max_stars_repo_head_hexsha": "ea19fe642bb7537cbf58451dcf73aa5fd1b66250", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 852, "max_stars_repo_stars_event_min_datetime": "2015-01-11T21:03:51.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T21:14:00.000Z", "max_issues_repo_path": "GeneratorInterface/PomwigInterface/src/flux65.f", "max_issues_repo_name": "ckamtsikis/cmssw", "max_issues_repo_head_hexsha": "ea19fe642bb7537cbf58451dcf73aa5fd1b66250", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 30371, "max_issues_repo_issues_event_min_datetime": "2015-01-02T00:14:40.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T23:26:05.000Z", "max_forks_repo_path": "GeneratorInterface/PomwigInterface/src/flux65.f", "max_forks_repo_name": "ckamtsikis/cmssw", "max_forks_repo_head_hexsha": "ea19fe642bb7537cbf58451dcf73aa5fd1b66250", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 3240, "max_forks_repo_forks_event_min_datetime": "2015-01-02T05:53:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T17:24:21.000Z", "avg_line_length": 37.488372093, "max_line_length": 71, "alphanum_fraction": 0.5514888337, "num_tokens": 654, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037323284109, "lm_q2_score": 0.7025300449389326, "lm_q1q2_score": 0.6507562026997795}} {"text": "*DECK DBESI0\n DOUBLE PRECISION FUNCTION DBESI0 (X)\nC***BEGIN PROLOGUE DBESI0\nC***PURPOSE Compute the hyperbolic Bessel function of the first kind\nC of order zero.\nC***LIBRARY SLATEC (FNLIB)\nC***CATEGORY C10B1\nC***TYPE DOUBLE PRECISION (BESI0-S, DBESI0-D)\nC***KEYWORDS FIRST KIND, FNLIB, HYPERBOLIC BESSEL FUNCTION,\nC MODIFIED BESSEL FUNCTION, ORDER ZERO, SPECIAL FUNCTIONS\nC***AUTHOR Fullerton, W., (LANL)\nC***DESCRIPTION\nC\nC DBESI0(X) calculates the double precision modified (hyperbolic)\nC Bessel function of the first kind of order zero and double\nC precision argument X.\nC\nC Series for BI0 on the interval 0. to 9.00000E+00\nC with weighted error 9.51E-34\nC log weighted error 33.02\nC significant figures required 33.31\nC decimal places required 33.65\nC\nC***REFERENCES (NONE)\nC***ROUTINES CALLED D1MACH, DBSI0E, DCSEVL, INITDS, XERMSG\nC***REVISION HISTORY (YYMMDD)\nC 770701 DATE WRITTEN\nC 890531 Changed all specific intrinsics to generic. (WRB)\nC 890531 REVISION DATE from Version 3.2\nC 891214 Prologue converted to Version 4.0 format. (BAB)\nC 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ)\nC***END PROLOGUE DBESI0\n DOUBLE PRECISION X, BI0CS(18), XMAX, XSML, Y, D1MACH,\n 1 DCSEVL, DBSI0E\n LOGICAL FIRST\n SAVE BI0CS, NTI0, XSML, XMAX, FIRST\n DATA BI0CS( 1) / -.7660547252 8391449510 8189497624 3285 D-1 /\n DATA BI0CS( 2) / +.1927337953 9938082699 5240875088 1196 D+1 /\n DATA BI0CS( 3) / +.2282644586 9203013389 3702929233 0415 D+0 /\n DATA BI0CS( 4) / +.1304891466 7072904280 7933421069 1888 D-1 /\n DATA BI0CS( 5) / +.4344270900 8164874513 7868268102 6107 D-3 /\n DATA BI0CS( 6) / +.9422657686 0019346639 2317174411 8766 D-5 /\n DATA BI0CS( 7) / +.1434006289 5106910799 6209187817 9957 D-6 /\n DATA BI0CS( 8) / +.1613849069 6617490699 1541971999 4611 D-8 /\n DATA BI0CS( 9) / +.1396650044 5356696994 9509270814 2522 D-10 /\n DATA BI0CS( 10) / +.9579451725 5054453446 2752317189 3333 D-13 /\n DATA BI0CS( 11) / +.5333981859 8625021310 1510774400 0000 D-15 /\n DATA BI0CS( 12) / +.2458716088 4374707746 9678591999 9999 D-17 /\n DATA BI0CS( 13) / +.9535680890 2487700269 4434133333 3333 D-20 /\n DATA BI0CS( 14) / +.3154382039 7214273367 8933333333 3333 D-22 /\n DATA BI0CS( 15) / +.9004564101 0946374314 6666666666 6666 D-25 /\n DATA BI0CS( 16) / +.2240647369 1236700160 0000000000 0000 D-27 /\n DATA BI0CS( 17) / +.4903034603 2428373333 3333333333 3333 D-30 /\n DATA BI0CS( 18) / +.9508172606 1226666666 6666666666 6666 D-33 /\n DATA FIRST /.TRUE./\nC***FIRST EXECUTABLE STATEMENT DBESI0\n IF (FIRST) THEN\n NTI0 = INITDS (BI0CS, 18, 0.1*REAL(D1MACH(3)))\n XSML = SQRT(4.5D0*D1MACH(3))\n XMAX = LOG (D1MACH(2))\n ENDIF\n FIRST = .FALSE.\nC\n Y = ABS(X)\n IF (Y.GT.3.0D0) GO TO 20\nC\n DBESI0 = 1.0D0\n IF (Y.GT.XSML) DBESI0 = 2.75D0 + DCSEVL (Y*Y/4.5D0-1.D0, BI0CS,\n 1 NTI0)\n RETURN\nC\n 20 IF (Y .GT. XMAX) CALL XERMSG ('SLATEC', 'DBESI0',\n + 'ABS(X) SO BIG I0 OVERFLOWS', 2, 2)\nC\n DBESI0 = EXP(Y) * DBSI0E(X)\nC\n RETURN\n END\n", "meta": {"hexsha": "ef4e2c4ceb2e5750cfef366b4855b7c43fa875b7", "size": 3380, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "external/SLATEC/src/dbesi0.f", "max_stars_repo_name": "ygeorgi/MESS", "max_stars_repo_head_hexsha": "42db490295b08193dfc37496489467ccd2e5b6ae", "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": "external/SLATEC/src/dbesi0.f", "max_issues_repo_name": "ygeorgi/MESS", "max_issues_repo_head_hexsha": "42db490295b08193dfc37496489467ccd2e5b6ae", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "external/SLATEC/src/dbesi0.f", "max_forks_repo_name": "ygeorgi/MESS", "max_forks_repo_head_hexsha": "42db490295b08193dfc37496489467ccd2e5b6ae", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.7848101266, "max_line_length": 71, "alphanum_fraction": 0.623964497, "num_tokens": 1367, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765328159726, "lm_q2_score": 0.7122321903471563, "lm_q1q2_score": 0.6507498382363156}} {"text": "!*************************************************************************\nsubroutine fan_gmres(nd)\n use global_com,only: dp,nitermax,precis\n use global_dim\n implicit none\n integer,parameter :: m = 30\n integer::itertotal,iterout,n,nd,k\n complex(kind=dp)::cx(nd)\n complex(kind=dp)::cb(m+1)\n complex(kind=dp)::cy(nd,m+1),ch(m+1,m) \n complex(kind=dp)::cs(m)\n real(kind=dp)::rc(m)\n complex(kind=dp)::ctemp\n real(kind=dp)::ay0, be, bea\n real(kind=dp)::xtime,xtim\n real(kind=dp),external:: scnrm22\n\n print *, '.......in fan_gmres algorithm ......'\n open(unit=161,file='con_fangmres.out')\r\n PRINT*, \"Starting iteration of solution...\"\n call cpu_time(xtime)\n\n cx = (0.0_dp,0.0_dp)\n ay0 = scnrm22(nd,crhs)\n itertotal = 0\n\n!print*,\"nd\",nd\n\n!************************************************************************\n do iterout = 1, nitermax \n!************************************************************************\n itertotal = itertotal +1\n!====================================================================\n call convol(cx(1:nd),cy(1:nd,m+1),nd)\n cy(1:nd,m+1) = crhs(1:nd) -cy(1:nd,m+1)\n cb(1) = scnrm22(nd,cy(1:nd,m+1)) \n be = cb(1)/ay0\n!====================================================================\n !write(*,*) 'restart', iterout,itertotal,' truebe',be\n !write(161,*) itertotal,be\n if(be.le.precis.or.itertotal>nitermax) exit\n cy(1:nd,1) = cy(1:nd,m+1)/cb(1)\n!************************************************************************\n do n = 1, m\n!************************************************************************\n itertotal = itertotal +1 \n!========================step1=======================================\n call convol(cy(1:nd,n),cy(1:nd,n+1),nd) \n!========================step2=======================================\n \tdo k=1,n\n ch(k,n) = dot_product(cy(1:nd,k),cy(1:nd,n+1))\n cy(1:nd,n+1) = cy(1:nd,n+1) - cy(1:nd,k)*ch(k,n) \n enddo\n ch(n+1,n) = scnrm22(nd,cy(1:nd,n+1)) \n if(n.lt.m) cy(1:nd,n+1) = cy(1:nd,n+1)/ch(n+1,n)\n if(n.ne.1) then\n do k=1,n-1\n ctemp = rc(k)*ch(k+1,n) - cs(k) *ch(k,n)\n ch(k,n) = rc(k)*ch(k,n) + conjg (cs(k))*ch(k+1,n)\n ch(k+1,n) = ctemp \n enddo\n endif\n!========================step3=======================================\n call givens_loc(ch(n,n),ch(n+1,n),rc(n),cs(n))\n!========================step4=======================================\n cb(n+1) = -cs(n)*cb(n)\n cb(n) = rc(n)*cb(n) \n ch(n,n) = rc(n)*ch(n,n)+ conjg (cs(n))*ch(n+1,n) \n ch(n+1,n) = (0.0_dp,0.0_dp)\n!========================step5=======================================\n bea = abs(cb(n+1))/ay0\n !write(*,*) itertotal,bea\n !write(161,*) itertotal,bea\n if(n.eq.m.or.bea.le.precis) then\n call cutrisub(n, ch(1:n,1:n), cb(1:n), cb(1:n))\n cy(1:nd,m+1) = matmul(cy(1:nd,1:n),cb(1:n))\n cx = cx + cy(1:nd,m+1)\t \n exit\n endif\n!===================================================================\n enddo !n }\n enddo !iterout}\n!===================================================================\n if(be>precis) then\n write( *,*) 'convergence is not achieved'\n write(161,*) 'convergence is not achieved'\n else\n write( *,*) 'convergence achieved'\n write(161,*) 'convergence achieved'\n endif\n call cpu_time(xtim)\n write(*, *) \"gmres itr time...\", xtim-xtime\n write(161,*) \"gmres itr time...\", xtim-xtime \n\n!------------------------solution------------------------\n rj = cx\n\n close(161)\n\n return\nend subroutine fan_gmres\n!*************************************************************************\n\n!*************************************************************************\nsubroutine givens_loc(z1,z2,c,s)\n use global_com,only: dp\n implicit none\n complex(kind=dp):: z1,z2,s\n real(kind=dp):: c,vnormz\n\n vnormz = sqrt ( abs(z1)**2 + abs(z2)**2)\n if (abs(z1).ne.0.) then\n c = abs(z1)/vnormz\n s = z2/z1* c\n else if (abs(z2).ne.0.) then\n c = 0.\n s = z2/ abs(z2)\n else\n c = 1.\n s = 0.\n endif\n\nend subroutine givens_loc\n!*************************************************************************\n\n!*************************************************************************\nfunction scnrm22(nd,cy9) \n use global_com,only: dp\n implicit none\n integer nd,i\n complex(kind=dp):: cy9(nd)\n real(kind=dp):: scnrm22\n\n scnrm22=0.0_dp\n do i=1,nd\n scnrm22= scnrm22+( conjg( cy9(i) )*cy9(i))\n end do\n scnrm22=sqrt(scnrm22)\n !\twrite(*,*) scnrm22\n !\tpause\n\n return\nend function scnrm22\n!*************************************************************************\n\n!*************************************************************************\nsubroutine cutrisub(n, cma, cvx, cvy)\n use global_com,only: dp\n implicit none\n integer n\n complex(kind=dp):: cma(n, n), cvx(n), cvy(n)\n integer i, j\n\n do i = n, 1, - 1\n cvy(i) = cvx(i)\n do j = i + 1, n\n cvy(i) = cvy(i) - cma(i, j) * cvy(j)\n enddo\n cvy(i) = cvy(i) / cma(i, i)\n enddo\n\nend subroutine cutrisub\n!*************************************************************************\n\n!*************************************************************************\nsubroutine convol(cin,cout,nd) !!!convolnear\n use global_com,only: dp,ntriangle,nipp\n use global_dim,only: zzsparse\n implicit none\n integer::nd,i,kk1,kk2\n complex(kind=dp):: cin(nd),cout(nd)\n\n cout = (0.0_dp,0.0_dp)\n\n do i = 1, ntriangle*nipp\n kk1 = (i-1)*ntriangle*nipp+1\n kk2 = i*ntriangle*nipp\n cout(i) = dot_product(conjg(zzsparse(kk1:kk2)),cin(1:ntriangle*nipp))\n enddo\n\nend subroutine convol\n!*************************************************************************\n", "meta": {"hexsha": "2d50223ae96617df333089c2e6de6ba918557eb2", "size": 5868, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/applications/acoustic/acoustic-kernel/gmres_fannew.f90", "max_stars_repo_name": "wawando/stars-h", "max_stars_repo_head_hexsha": "03e11375bf559bc850243c4c38796be21112a5f4", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-11-22T22:28:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-09T07:35:59.000Z", "max_issues_repo_path": "src/applications/acoustic/acoustic-kernel/gmres_fannew.f90", "max_issues_repo_name": "wawando/stars-h", "max_issues_repo_head_hexsha": "03e11375bf559bc850243c4c38796be21112a5f4", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-11-04T01:10:54.000Z", "max_issues_repo_issues_event_max_datetime": "2020-11-08T20:01:54.000Z", "max_forks_repo_path": "src/applications/acoustic/acoustic-kernel/gmres_fannew.f90", "max_forks_repo_name": "wawando/stars-h", "max_forks_repo_head_hexsha": "03e11375bf559bc850243c4c38796be21112a5f4", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2017-11-12T16:28:00.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T18:08:24.000Z", "avg_line_length": 32.0655737705, "max_line_length": 74, "alphanum_fraction": 0.3933197001, "num_tokens": 1738, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765187126079, "lm_q2_score": 0.7122321903471563, "lm_q1q2_score": 0.6507498281914453}} {"text": " subroutine derivs(x,y,Ntraj,fx,fy,pe,ipot)\n implicit real*8(a-h,o-z)\n integer*4,intent(IN) :: Ntraj,ipot\n real*8,intent(IN) :: x(Ntraj),y(Ntraj)\n real*8 :: De,a,x0,y0,b,c,d,e,v,f,w,ky,xmin\n real*8,intent(OUT) :: fx(Ntraj),fy(Ntraj),pe(Ntraj)\n real*8 xe,k1,k2\n! common/pes/ipot\nc morse potential for x coordinate, Eckart potential for y direction \n \tfx = 0d0\n\tfy = 0d0\n\tpe = 0d0\n\nC\n xmin=0.3342534836\n if (ipot .eq. 1) then\n do i=1,Ntraj\n fx(i)=0.0908295*exp(-1.5d0*(x(i)-y(i)*lambda/2d0))/\n & (1d0+exp(-1.5d0*(x(i)-y(i)*lambda/2d0)))**2\n & -0.09246906195d0*sinh(0.75d0*(x(i)-y(i)*lambda/2d0))/\n & (cosh(0.75d0*(x(i)-y(i)*lambda/2d0)))**3\n\n fy(i)=-k2*y(i)-0.04541475d0*lambda*exp(-1.5d0*x(i)+\n & 0.75d0*y(i)*lambda)/(1d0+exp(-1.5d0*x(i)+0.75d0*y(i)*lambda))**2+\n & 0.04623453098d0*sinh(0.75d0*x(i)-0.375d0*y(i)*lambda)*lambda/\n & cosh(0.75d0*x(i)-0.375d0*y(i)*lambda)**3\n\n pe(i)=0.063740d0-0.060553d0/(1d0+exp(-1.5d0*(x(i)-\n & y(i)*lambda/2d0)))\n & - 0.06164604130d0/cosh(0.75d0*(x(i)-y(i)*lambda/2d0))**2+\n & k2*y(i)**2/2d0\n end do\n endif\nC Harmonic \n if(ipot .eq. 2) then\n\tak = 0.8d0\n do i=1,Ntraj\n fx(i)=-x(i)-ak*y(i)\n fy(i)=-y(i)-ak*x(i)\n pe(i)=x(i)**2/2d0+y(i)**2/2d0+ak*x(i)*y(i)\n enddo\n endif\nC Morse for H2\n if(ipot .eq. 3) then\n De = 0.176d0\n xe=1.4d0\n ye = 1.4d0\n alpha = 1.02\n\n do i=1,Ntraj\n fx(i)=-2d0*De*alpha*exp(-alpha*(x(i)-xe))*\n & (1d0-exp(-alpha*(x(i)-xe)))\n fy(i)=-2d0*De*alpha*exp(-alpha*(y(i)-ye))*\n & (1d0-exp(-alpha*(y(i)-ye)))\n pe(i)=De*(1d0-exp(-alpha*(x(i)-xe)))**2+\n & De*(1d0-exp(-alpha*(y(i)-ye)))**2\n enddo\n endif\nC Henon-Hailes\n IF(ipot .eq. 4) THEN\n k1=1d0\n k2=1d0\n do i=1,Ntraj\n fx(i)=-k1*x(i)-2d0*x(i)*y(i)\n fy(i)=-k2*y(i)-x(i)**2+y(i)**2\n pe(i)=k1*x(i)**2/2d0+k2*y(i)**2/2d0+\n & (x(i)**2*y(i)-y(i)**3/3d0)\n ENDDO\n ENDIF\n! Coupled harmonic oscilator\n\t\n if(ipot .eq. 5) then\n do i=1,Ntraj\n fx(i)=-x(i)-0.2d0*x(i)**2\n fy(i)=-y(i)\n pe(i)=0.5d0*(x(i)**2+y(i)**2)+0.2d0*x(i)**3/3d0\n enddo\n endif\n\n\tRETURN\n END subroutine\n", "meta": {"hexsha": "e76ddc5384e697868560dc5f0cd106dcc4364b9a", "size": 2367, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "QTM_F/1D/pH2/fcl.f", "max_stars_repo_name": "binggu56/qmd", "max_stars_repo_head_hexsha": "e2628710de15f8a8b9a1280fcf92f9e87559414c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "QTM_F/1D/pH2/fcl.f", "max_issues_repo_name": "binggu56/qmd", "max_issues_repo_head_hexsha": "e2628710de15f8a8b9a1280fcf92f9e87559414c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "QTM_F/1D/pH2/fcl.f", "max_forks_repo_name": "binggu56/qmd", "max_forks_repo_head_hexsha": "e2628710de15f8a8b9a1280fcf92f9e87559414c", "max_forks_repo_licenses": ["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.8658536585, "max_line_length": 72, "alphanum_fraction": 0.4866920152, "num_tokens": 1077, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.913676530465412, "lm_q2_score": 0.7122321781307374, "lm_q1q2_score": 0.6507498254003153}} {"text": " Program zgeevx_example\n\n! ZGEEVX Example Program Text\n\n! Copyright (c) 2018, Numerical Algorithms Group (NAG Ltd.)\n! For licence see\n! https://github.com/numericalalgorithmsgroup/LAPACK_Examples/blob/master/LICENCE.md\n\n! .. Use Statements ..\n Use lapack_interfaces, Only: zgeevx\n Use lapack_precision, Only: dp\n! .. Implicit None Statement ..\n Implicit None\n! .. Parameters ..\n Integer, Parameter :: nb = 64, nin = 5, nout = 6\n! .. Local Scalars ..\n Real (Kind=dp) :: abnrm, eps, tol\n Integer :: i, ihi, ilo, info, j, lda, ldvl, ldvr, lwork, n\n! .. Local Arrays ..\n Complex (Kind=dp), Allocatable :: a(:, :), vl(:, :), vr(:, :), w(:), &\n work(:)\n Complex (Kind=dp) :: dummy(1)\n Real (Kind=dp), Allocatable :: rconde(:), rcondv(:), rwork(:), scale(:)\n! .. Intrinsic Procedures ..\n Intrinsic :: epsilon, max, nint, real\n! .. Executable Statements ..\n Write (nout, *) 'ZGEEVX Example Program Results'\n! Skip heading in data file\n Read (nin, *)\n Read (nin, *) n\n lda = n\n ldvl = n\n ldvr = n\n Allocate (a(lda,n), vl(ldvl,n), vr(ldvr,n), w(n), rconde(n), rcondv(n), &\n rwork(2*n), scale(n))\n\n! Use routine workspace query to get optimal workspace.\n lwork = -1\n Call zgeevx('Balance', 'Vectors (left)', 'Vectors (right)', &\n 'Both reciprocal condition numbers', n, a, lda, w, vl, ldvl, vr, ldvr, &\n ilo, ihi, scale, abnrm, rconde, rcondv, dummy, lwork, rwork, info)\n\n! Make sure that there is enough workspace for block size nb.\n lwork = max((nb+1)*n, nint(real(dummy(1))))\n Allocate (work(lwork))\n\n! Read the matrix A from data file\n\n Read (nin, *)(a(i,1:n), i=1, n)\n\n! Solve the eigenvalue problem\n\n Call zgeevx('Balance', 'Vectors (left)', 'Vectors (right)', &\n 'Both reciprocal condition numbers', n, a, lda, w, vl, ldvl, vr, ldvr, &\n ilo, ihi, scale, abnrm, rconde, rcondv, work, lwork, rwork, info)\n\n If (info==0) Then\n\n! Compute the machine precision\n\n eps = epsilon(1.0E0_dp)\n tol = eps*abnrm\n\n! Print the eigenvalues and vectors, and associated condition\n! number and bounds\n\n Write (nout, *)\n Write (nout, *) 'Eigenvalues'\n Write (nout, *)\n Write (nout, *) ' Eigenvalue rcond error'\n\n Do j = 1, n\n\n! Print information on j-th eigenvalue\n\n If (rconde(j)>0.0_dp) Then\n If (tol/rconde(j)<10.0_dp*eps) Then\n Write (nout, 100) j, w(j), rconde(j), '-'\n Else\n Write (nout, 110) j, w(j), rconde(j), tol/rconde(j)\n End If\n Else\n Write (nout, 100) j, w(j), rconde(j), 'Inf'\n End If\n\n End Do\n\n Write (nout, *)\n Write (nout, *) 'Eigenvectors'\n Write (nout, *)\n Write (nout, *) ' Eigenvector rcond error'\n\n Do j = 1, n\n\n! Print information on j-th eigenvector\n\n Write (nout, *)\n\n! Make first real part component be positive\n If (real(vr(1,j))<0.0_dp) Then\n vr(1:n, j) = -vr(1:n, j)\n End If\n If (rcondv(j)>0.0_dp) Then\n If (tol/rcondv(j)<10.0_dp*eps) Then\n Write (nout, 100) j, vr(1, j), rcondv(j), '-'\n Else\n Write (nout, 110) j, vr(1, j), rcondv(j), tol/rcondv(j)\n End If\n Else\n Write (nout, 100) j, vr(1, j), rcondv(j), 'Inf'\n End If\n\n Write (nout, 120) vr(2:n, j)\n\n End Do\n Write (nout, *)\n Write (nout, *) 'Errors below 10*machine precision are not displayed'\n Else\n Write (nout, *)\n Write (nout, 130) 'Failure in ZGEEVX. INFO =', info\n End If\n\n100 Format (1X, I2, 1X, '(', 1P, E11.4, ',', E11.4, ')', 1X, 0P, F7.4, 4X, &\n A)\n110 Format (1X, I2, 1X, '(', 1P, E11.4, ',', E11.4, ')', 1X, 0P, F7.4, 1X, &\n 1P, E8.1)\n120 Format (1X, 3X, '(', 1P, E11.4, ',', E11.4, ')')\n130 Format (1X, A, I4)\n\n End Program\n", "meta": {"hexsha": "67a5d1cd2ed8d654245d7f660a8cf2257b8cfa33", "size": 4115, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/source/zgeevx_example.f90", "max_stars_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_stars_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2018-01-28T15:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T09:26:43.000Z", "max_issues_repo_path": "examples/source/zgeevx_example.f90", "max_issues_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_issues_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "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": "examples/source/zgeevx_example.f90", "max_forks_repo_name": "numericalalgorithmsgroup/LAPACK_examples", "max_forks_repo_head_hexsha": "0dde05ae4817ce9698462bbca990c4225337f481", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2019-04-19T12:22:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-18T03:32:12.000Z", "avg_line_length": 31.4122137405, "max_line_length": 90, "alphanum_fraction": 0.5205346294, "num_tokens": 1348, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467548438124, "lm_q2_score": 0.740174367770488, "lm_q1q2_score": 0.650721893443995}} {"text": "program problem15\n use euler\n implicit none\n\n print *, binomial(40_8,20_8)\n \nend program problem15\n", "meta": {"hexsha": "8a646c57d8cda88c95b60bdb470cc7995b082e52", "size": 103, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "problem15.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": "problem15.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": "problem15.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": 12.875, "max_line_length": 30, "alphanum_fraction": 0.7378640777, "num_tokens": 32, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8791467548438124, "lm_q2_score": 0.7401743620390163, "lm_q1q2_score": 0.6507218884051904}} {"text": "PROGRAM CNPE2_HT_VAL\n USE PE2D_TYPE\n USE PE2D_VAR\n USE PE2D_AUX\n USE PE2D_GROUND\n IMPLICIT NONE\n !-----------------------------------------------------------\n !-----------------------------------------------------------\n WRITE(*,*) \"\"\n WRITE(*,*) \"================================================\"\n WRITE(*,*) \"========== Parabolic Equation Package ==========\"\n WRITE(*,*) \"================================================\"\n WRITE(*,*) \"\"\n WRITE(*,*) \"University of Bristol\"\n WRITE(*,*) \"Mech. Eng. Department\"\n WRITE(*,*) \"Aerodynamics and Aeroacoustics Research Group\"\n WRITE(*,*) \"\"\n WRITE(*,*) \"Codor Khodr, July 2016\"\n WRITE(*,*) \"\"\n WRITE(*,*) \"================================================\"\n WRITE(*,*) \"\"\n WRITE(*,*) \"CNPE2_HT\"\n WRITE(*,*) \"Dimension : \t2D\"\n WRITE(*,*) \"Atmosphere :\tHomogeneous\"\n WRITE(*,*) \"Boundary : \tShift Map\"\n WRITE(*,*) \"Impedance : \tRigid\"\n WRITE(*,*) \"\"\n WRITE(*,*) \"================================================\"\n WRITE(*,*) \"\"\n WRITE(*,*) \"PE Validation program\"\n WRITE(*,*) \"Choose source frequency - 1 (10 Hz), 2 (100 Hz), 3 (1000 Hz)\"\n WRITE(*,*) \"\"\n READ *, FREQ_I\n WRITE(*,*) \"Atmospheric refraction - 1 (Isothermal), 2 (+0.1), 3 (-0.1)\"\n WRITE(*,*) \"\"\n READ*, ATMO_I\n WRITE(*,*) \"\"\n !-----------------------------------------------------------\n !-----------------------------------------------------------\n !Ascension Island data driver variables\n WRITE(FREQ,'(I0)') FREQ_I\n WRITE(ATMO,'(I0)') ATMO_I\n FREQ_VAL = (/ 10.0_DP, 100.0_DP, 1000.0_DP /)\n Z_VAL = (/ CMPLX(38.79_DP,38.41_DP,KIND=DPC), &\n CMPLX(12.81_DP,11.62_DP,KIND=DPC), &\n CMPLX( 5.96_DP, 2.46_DP,KIND=DPC) /)\n ATMO_REF = (/ 0.0_DP, 0.1_DP, -0.1_DP /)\n L = 10000_DP\n ZS = 5.000_DP\n ZR = 1.000_DP\n F\t = FREQ_VAL(FREQ_I)\n Z = Z_VAL(FREQ_I)\n R = (Z-1.0_DP)/(Z+1.0_DP)\n !-----------------------------------------------------------\n !-----------------------------------------------------------\n !Discretization of the Atmosphere domain\n C0 = 343.0_DP\n LMBDA0 = C0/F\n K0 = 2.0_DP*PI*F/C0\n DZ = LMBDA0/10\n DR = LMBDA0/10\n H = 100*LMBDA0\n HA = 30*LMBDA0\n N = FLOOR(H/DZ)\n M = FLOOR(L/DR)\n WRITE(*,*) \"================================================\"\n WRITE(*,*) \"\"\n WRITE(*,*) \"Size of the system : \", N\n WRITE(*,*) \"Number of steps : \", M\n WRITE(*,*) \"\"\n WRITE(*,*) \"================================================\"\n NS = MAX(1,FLOOR(ZS/DZ))\n NR = MAX(1,FLOOR(ZR/DZ))\n NA = FLOOR(HA/DZ)\n A = IM/(2.0_DP*K0*DZ**2)\n KU = 1\n KL = 1\n NDIAG = KU+KL+1\n !-----------------------------------------------------------\n !-----------------------------------------------------------\n !Absorbing coefficient\n AS = 4.897_DP*(10**(-9))*(F**3) - &\n 7.119_DP*(10**(-6))*(F**2) + &\n 3.109_DP*(10**(-3))*F + &\n 0.113\n !-----------------------------------------------------------\n !-----------------------------------------------------------\n !Atmosphere density and wave velocity\n ALLOCATE(C(N),K(N),DK2(N),ALT(N))\n DC = ATMO_REF(ATMO_I)\n DO NZ = 1,N\n ALT(NZ) = NZ*DZ\n C(NZ) = C0+DC*ALT(NZ)\n K(NZ) = 2.0_DP*PI*F/C(NZ)\n IF (NZ.GT.(N-NA)) THEN\n K(NZ) = K(NZ)+AS*IM*(NZ-N+NA)**2/NA**2\n END IF\n DK2(NZ) = K(NZ)**2-K0**2\n END DO\n !-----------------------------------------------------------\n !-----------------------------------------------------------\n !Terrain Boundary condition\n ALLOCATE(X(M),TERR(M),TERR1(M),TERR2(M),SLOPX(M))\n DO MX = 0,M\n X(MX) = MX*DR\n TERR(MX) = 0.000_DP\n TERR1(MX) = 0.000_DP\n TERR2(MX) = 0.000_DP\n SLOPX(MX) = ATAN(TERR1(MX))\n END DO\n !-----------------------------------------------------------\n !-----------------------------------------------------------\n !Starting field\n ALLOCATE(PHI(N,M+1),PC(N,M),QC(N,M),P(N,M),Q(N,M))\n A0 = 1.3717_DP\n A2 = -0.3701_DP\n B = 3.0_DP\n DO NZ = 1,N\n PHI(NZ,1) = SQRT(IM*K0)* &\n ((A0+A2*K0**2*(NZ*DZ-ZS)**2)*EXP(-K0**2*(NZ*DZ-ZS)**2/B) + &\n R*(A0+A2*K0**2*(NZ*DZ+ZS)**2)*EXP(-K0**2*(NZ*DZ+ZS)**2/B))\n END DO\n !-----------------------------------------------------------\n !-----------------------------------------------------------\n !Boundary condition - Finite Difference\n ALLOCATE(T(N,N),D(N,N),E(N,N),I(N,N))\n TAU1 = 4.0_DP/(3.0_DP-2.0_DP*IM*K0*DZ)\n TAU2 = -1.0_DP/(3.0_DP-2.0_DP*IM*K0*DZ)\n SIGMA1 = 4.0_DP*Z/(3.0_DP*Z-2.0_DP*IM*K0*DZ)\n SIGMA2 = -1.0_DP*Z/(3.0_DP*Z-2.0_DP*IM*K0*DZ)\n !Matrix Initialization (Dense Matrices) - T, D and E\n T(:,:) = 0.0_DP\n DO NZ = 2,N-1\n T(NZ,NZ-1) = 1.0_DP\n T(NZ,NZ) = -2.0_DP\n T(NZ,NZ+1) = 1.0_DP\n END DO\n T(1,1) = -2.0_DP+SIGMA1\n T(1,2) = 1.0_DP+SIGMA2\n T(N,N-1) = 1.0_DP+TAU2\n T(N,N) = -2.0_DP+TAU1\n E = DDIAG(CMPLX(ALT,0.0_DP,KIND=DPC),N)\n D = (IM/(2.0_DP*K0))*DDIAG(DK2,N)\n I = EYE(N)\n !-----------------------------------------------------------\n !-----------------------------------------------------------\n !System - M1 and M2\n ALLOCATE(M1(N,N),M2(N,N),MB2(NDIAG,N),MB1(NDIAG,N))\n C1 = CMPLX(1.0_DP,0.0_DP,KIND=DP)\n C2 = CMPLX(0.0_DP,0.0_DP,KIND=DP)\n BETA1 = 1.0_DP/(2.0_DP*IM*K0)+DR/2.0_DP\n BETA2 = 1.0_DP/(2.0_DP*IM*K0)-DR/2.0_DP\n M1 = I+A*BETA1*T+BETA1*D\n M2 = I+A*BETA2*T+BETA2*D\n MB1 = D2B(M1,N,KL,KU)\n MB2 = D2B(M2,N,KL,KU)\n !-----------------------------------------------------------\n !-----------------------------------------------------------\n !Forward-marching procedure\n ALLOCATE(MB1T(NDIAG,N),MB2T(KL+NDIAG,N),IPIV(N),TEMP(N,1))\n CALL CPU_TIME(TI)\n DO MX = 2,M+1\n WRITE(*,*) \"Step :\", MX-1, \"out of\", M\n !Matrix updating\n MB1T = MB1\n MB1T(KU+1,:) = MB1(KU+1,:)-BETA1*IM*K0*TERR2(MX-1)*ALT\n MB2T(KL+1:KL+NDIAG,:) = MB2\n MB2T(KL+KU+1,:) = MB2(KU+1,:)-BETA2*IM*K0*TERR2(MX-1)*ALT\n !Right hand side multiplication\n CALL ZGBMV('N',N,N,KL,KU,C1,MB1T,KL+KU+1,PHI(1:N,MX-1),1,C2,TEMP(:,1),1) !Band matrix form\n WRITE(*,*) \".... Right-hand side multiplied\"\n !System solving\n CALL ZGBSV(N,KL,KU,1,MB2T,2*KL+KU+1,IPIV,TEMP,N,INFO) !Band matrix form\n IF (INFO.NE.0) THEN\n STOP \"ERROR : Matrix is singular\"\n END IF\n WRITE(*,*) \".... System solved\"\n !Complex and real pressure\n PHI(1:N,MX) = TEMP(:,1)\n PC(1:N,MX-1) = EXP(IM*K0*(MX-1)*DR)*PHI(1:N,MX)/SQRT((MX-1)*DR)\n P(1:N,MX-1) = REALPART(PC(1:N,MX-1))\n WRITE(*,*)\n END DO\n CALL CPU_TIME(TF)\n !-----------------------------------------------------------\n !-----------------------------------------------------------\n !Transmission loss conversion\n ALLOCATE(LP(N,M),LQ(N,M),LPG(M),LQG(M))\n P0 = ABS(PC(NS,1)) !Reference pressure (real)\n Q0 = ABS(QC(NS,1)) !Reference corrected pressure (real)\n DO MX = 1,M\n DO NZ = 1,N\n LP(NZ,MX) = 10.0_DP*LOG10(ABS(PC(NZ,MX))**2/(P0**2))\n LQ(NZ,MX) = 10.0_DP*LOG10(ABS(QC(NZ,MX))**2/(Q0**2))\n IF (LP(NZ,MX).LE.-120) THEN\n LP(NZ,MX) = -120\n LQ(NZ,MX) = -120\n END IF\n END DO\n END DO\n LP0 = LP(NS,1)\n LQ0 = LQ(NS,1)\n LPG = LP(1,1:M)\n LQG = LQ(1,1:M)\n LPR = LP(NR,M)\n LQR = LQ(NR,M)\n PR = SQRT(2.0_DP)*P0*10**(LPR/20)\n QR = SQRT(2.0_DP)*Q0*10**(LPR/20)\n !-----------------------------------------------------------\n !-----------------------------------------------------------\n !Output\n OUT_EXT = \"W\" // WIDE // \"_A\" // ATMO // \"_f\" // FREQ\n OUT_LPg = \"LPg_\" // TRIM(OUT_EXT) // \".dat\"\n OPEN(UNIT=10,FILE=TRIM(OUT_LPg))\n DO MX = 1,M\n WRITE(10,100) X(MX), LPG(MX)\n END DO\n 100 FORMAT(3(3X,F12.3))\n !-----------------------------------------------------------\n !-----------------------------------------------------------\n DEALLOCATE(PHI,PC,QC,P,Q,LP,LQ)\n WRITE(*,*) \"================================================\"\n WRITE(*,*) \"Input file : \", TOPO\n WRITE(*,*) \"================================================\"\n WRITE(*,*) \"Output file : \", TRIM(OUT_LPg)\n WRITE(*,*) \" \", TRIM(OUT_TOPO)\n WRITE(*,*) \"================================================\"\n WRITE(*,*)\n WRITE(*,*) \"System size (N x M) :\", N, M\n WRITE(*,*) \"Step size :\", DR\n WRITE(*,*) \"Main CPU time (s) :\", TF-TI\n WRITE(*,*) \"Real pressure at the source - P0 (Pa) :\", P0\n WRITE(*,*) \"Real pressure at the target - PR (Pa) :\", PR\n WRITE(*,*) \"SPL/TL at the target - LPR (dB) :\", LPR\n WRITE(*,*)\n !-----------------------------------------------------------\n !----------------------------------------------------------\nEND PROGRAM CNPE2_HT_VAL\n", "meta": {"hexsha": "a72a44a0d126f25ba8fbef00faf7cb7cbb099c05", "size": 8391, "ext": "f03", "lang": "FORTRAN", "max_stars_repo_path": "Parabolic_Equation/2DPE/SRC/CNPE/CNPE2_HT_VAL.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/SRC/CNPE/CNPE2_HT_VAL.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/SRC/CNPE/CNPE2_HT_VAL.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": 35.1087866109, "max_line_length": 94, "alphanum_fraction": 0.4059110952, "num_tokens": 2904, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953003183444, "lm_q2_score": 0.7248702821204019, "lm_q1q2_score": 0.6507126455999173}} {"text": "! wireframe.f90\n!\n! Double buffered software rendering of a 3-D wire-frame model. The model\n! is loaded from a Wavefront OBJ file.\n!\n! Author: Philipp Engel\n! Licence: ISC\nmodule vector\n implicit none\n real, parameter :: pi = acos(-1.0)\n\n public :: project\n public :: rotate_x\n public :: rotate_y\n public :: rotate_z\n\n type :: point2d\n real :: x, y\n end type point2d\n\n type :: point3d\n real :: x, y, z\n end type point3d\ncontains\n type(point2d) function project(v, width, height, fov, distance) result(p)\n !! Transforms a 3-D vector to a 2-D vector by using perspective projection.\n type(point3d), intent(in) :: v\n integer, intent(in) :: width\n integer, intent(in) :: height\n real, intent(in) :: fov\n real, intent(in) :: distance\n real :: f\n\n f = fov / (distance + v%z)\n p%x = v%x * f + width / 2\n p%y = -1 * v%y * f + height / 2\n end function project\n\n real function rad(deg)\n !! Converts an angle from deg to rad.\n real, intent(in) :: deg\n\n rad = deg * pi / 180\n end function rad\n\n type(point3d) function rotate_x(v, angle) result(r)\n !! Rotates vector in x.\n type(point3d), intent(in) :: v\n real, intent(in) :: angle\n\n r%x = v%x\n r%y = v%y * cos(angle) - v%z * sin(angle)\n r%z = v%z * sin(angle) + v%z * cos(angle)\n end function rotate_x\n\n type(point3d) function rotate_y(v, angle) result(r)\n !! Rotates vector in y.\n type(point3d), intent(in) :: v\n real, intent(in) :: angle\n\n r%x = v%z * sin(angle) + v%x * cos(angle)\n r%y = v%y\n r%z = v%z * cos(angle) - v%x * sin(angle)\n end function rotate_y\n\n type(point3d) function rotate_z(v, angle) result(r)\n !! Rotates vector in z.\n type(point3d), intent(in) :: v\n real, intent(in) :: angle\n\n r%x = v%x * cos(angle) - v%y * sin(angle)\n r%y = v%x * sin(angle) - v%y * cos(angle)\n r%z = v%z\n end function rotate_z\nend module vector\n\nmodule obj\n !! Loads and stores a 3-D object.\n use :: vector\n implicit none\n\n type :: face\n integer :: v1, v2\n end type face\n\n type(point3d), allocatable :: vertices(:)\n type(face), allocatable :: faces(:)\n\n public :: load_obj_file\ncontains\n subroutine load_obj_file(file_name)\n !! Loads a Wavefront OBJ file.\n character(len=*), intent(in) :: file_name !! File name.\n integer, parameter :: U = 10 !! Output unit.\n character(len=100) :: buffer !! Line buffer.\n character(len=1) :: str !! Temporary string.\n integer :: v_size, f_size !! Array sizes.\n integer :: rc !! I/O status.\n type(point3d), allocatable :: tmp_vertices(:) !! Temporary array for vertices.\n type(face), allocatable :: tmp_faces(:) !! Temporary array for faces.\n\n allocate (vertices(1))\n allocate (faces(1))\n\n open (unit=U, file=file_name, action='read', iostat=rc)\n\n if (rc == 0) then\n do\n read (U, '(a)', iostat=rc) buffer\n if (rc /= 0) exit\n\n select case (buffer(1:1))\n case ('v')\n ! Read vertice.\n v_size = size(vertices)\n allocate (tmp_vertices(v_size + 1))\n tmp_vertices(1:v_size) = vertices\n\n read (buffer, *) str, &\n tmp_vertices(v_size)%x, &\n tmp_vertices(v_size)%y, &\n tmp_vertices(v_size)%z\n\n call move_alloc(tmp_vertices, vertices)\n case ('f')\n ! Read face.\n f_size = size(faces)\n allocate (tmp_faces(f_size + 1))\n tmp_faces(1:f_size) = faces\n\n read (buffer, *) str, &\n tmp_faces(f_size)%v1, &\n tmp_faces(f_size)%v2\n\n call move_alloc(tmp_faces, faces)\n case default\n continue\n end select\n end do\n else\n print *, 'Reading file \"', file_name, '\" failed: ', rc\n end if\n\n close (U)\n\n ! Resize the arrays to their actual sizes (ugly, I know ...).\n if (allocated(tmp_vertices)) &\n deallocate (tmp_vertices)\n\n if (allocated(tmp_faces)) &\n deallocate (tmp_faces)\n\n ! Actual array sizes.\n v_size = size(vertices) - 1\n f_size = size(faces) - 1\n\n allocate (tmp_vertices(v_size))\n allocate (tmp_faces(f_size))\n\n tmp_vertices = vertices(1:v_size)\n tmp_faces = faces(1:f_size)\n\n call move_alloc(tmp_vertices, vertices)\n call move_alloc(tmp_faces, faces)\n end subroutine load_obj_file\nend module obj\n\nprogram main\n use, intrinsic :: iso_c_binding, only: c_ptr, c_null_char, c_bool, c_ptr\n use :: xlib\n use :: obj\n use :: vector\n implicit none\n integer, parameter :: WIDTH = 640\n integer, parameter :: HEIGHT = 480\n character(len=*), parameter :: FILE_NAME = 'examples/wireframe/tie.obj'\n\n type(c_ptr) :: display\n type(c_ptr) :: gc\n type(x_color) :: color\n type(x_event) :: event\n type(x_gc_values) :: values\n type(x_size_hints) :: size_hints\n integer :: screen\n integer :: rc\n integer(kind=8) :: root\n integer(kind=8) :: colormap\n integer(kind=8) :: double_buffer\n integer(kind=8) :: black\n integer(kind=8) :: white\n integer(kind=8) :: window\n integer(kind=8) :: wm_delete_window\n integer(kind=8) :: long(5)\n type(point2d), allocatable :: transformed(:)\n real :: angle_x = 0.0\n real :: angle_y = 0.0\n real :: angle_z = 0.0\n\n interface\n subroutine usleep(useconds) bind(c)\n !! Interface to usleep in libc.\n use, intrinsic :: iso_c_binding, only: c_int32_t\n integer(c_int32_t), value :: useconds\n end subroutine\n end interface\n\n call load_obj_file(FILE_NAME)\n\n if (.not. allocated(vertices) .or. .not. allocated(faces)) &\n stop\n\n ! Open display.\n display = x_open_display(c_null_char)\n screen = x_default_screen(display)\n root = x_default_root_window(display)\n colormap = x_default_colormap(display, screen)\n\n ! Define colours.\n black = x_black_pixel(display, screen)\n white = x_white_pixel(display, screen)\n\n rc = x_alloc_named_color(display, colormap, 'SteelBlue' // c_null_char, color, color)\n\n if (rc == 0) then\n print *, 'XAllocNamedColor failed to allocate \"SteelBlue\" colour.'\n stop\n end if\n\n ! Create window.\n window = x_create_simple_window(display, root, 0, 0, WIDTH, HEIGHT, 0, white, black)\n call x_store_name(display, window, 'Fortran' // c_null_char)\n\n wm_delete_window = x_intern_atom(display, 'WM_DELETE_WINDOW' // c_null_char, .false._c_bool)\n rc = x_set_wm_protocols(display, window, wm_delete_window, 1)\n\n ! Prevent resizing.\n size_hints%flags = ior(P_MIN_SIZE, P_MAX_SIZE)\n size_hints%min_width = WIDTH\n size_hints%min_height = HEIGHT\n size_hints%max_width = WIDTH\n size_hints%max_height = HEIGHT\n\n call x_set_wm_normal_hints(display, window, size_hints)\n\n ! Create graphics context.\n gc = x_create_gc(display, window, 0, values)\n\n call x_set_background(display, gc, black)\n call x_set_foreground(display, gc, white)\n\n ! Create double buffer.\n double_buffer = x_create_pixmap(display, window, WIDTH, HEIGHT, 24)\n\n ! Show window.\n call x_select_input(display, window, ior(EXPOSURE_MASK, STRUCTURE_NOTIFY_MASK))\n call x_map_window(display, window)\n\n do\n rc = x_pending(display)\n\n if (rc > 0) then\n call x_next_event(display, event)\n\n select case (event%type)\n case (expose)\n ! call draw()\n case (client_message)\n long = transfer(event%x_client_message%data, long)\n\n if (long(1) == wm_delete_window) &\n exit\n end select\n else\n call update(angle_x, angle_y, angle_z)\n call render()\n\n ! angle_x = angle_x + 1.0\n angle_y = angle_y + 1.0\n ! angle_z = angle_z + 1.0\n\n call draw()\n call microsleep(25000)\n end if\n end do\n\n ! Clean up and close window.\n call x_free_colors(display, colormap, [ color%pixel ], 1, int(0, kind=8))\n call x_free_pixmap(display, double_buffer)\n call x_free_gc(display, gc)\n call x_destroy_window(display, window)\n call x_close_display(display)\ncontains\n subroutine microsleep(t)\n !! Wrapper for usleep.\n integer, intent(in) :: t\n\n call usleep(int(t, c_int32_t))\n end subroutine microsleep\n\n subroutine update(angle_x, angle_y, angle_z)\n !! Rotates the 3-D object.\n real, intent(in) :: angle_x\n real, intent(in) :: angle_y\n real, intent(in) :: angle_z\n type(point3d) :: v\n integer :: i\n\n if (.not. allocated(transformed)) &\n allocate (transformed(size(vertices)))\n\n do i = 1, size(vertices, 1)\n v = vertices(i)\n v = rotate_x(v, rad(angle_x))\n v = rotate_y(v, rad(angle_y))\n v = rotate_z(v, rad(angle_z))\n transformed(i) = project(v, WIDTH, HEIGHT, 256.0, 8.0)\n end do\n end subroutine update\n\n subroutine render()\n !! Renders the scene on the double buffer.\n integer :: x1, y1, x2, y2\n integer :: i\n\n call x_set_foreground(display, gc, black)\n call x_fill_rectangle(display, double_buffer, gc, 0, 0, WIDTH, HEIGHT)\n call x_set_foreground(display, gc, color%pixel)\n\n do i = 1, size(faces, 1)\n x1 = int(transformed(faces(i)%v1)%x)\n y1 = int(transformed(faces(i)%v1)%y)\n x2 = int(transformed(faces(i)%v2)%x)\n y2 = int(transformed(faces(i)%v2)%y)\n\n call x_draw_line(display, double_buffer, gc, x1, y1, x2, y2)\n end do\n end subroutine render\n\n subroutine draw()\n !! Copies double buffer to window.\n call x_copy_area(display, double_buffer, window, gc, 0, 0, WIDTH, HEIGHT, 0, 0)\n end subroutine draw\nend program main\n", "meta": {"hexsha": "9923f79060728450aa48bc753366e269eb4e02eb", "size": 11050, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "examples/wireframe/wireframe.f90", "max_stars_repo_name": "interkosmos/fortran-xlib", "max_stars_repo_head_hexsha": "0552aad2dca2ab3267b30a6f5126eb42d7eb2271", "max_stars_repo_licenses": ["0BSD"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-03-13T17:17:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-13T16:20:56.000Z", "max_issues_repo_path": "examples/wireframe/wireframe.f90", "max_issues_repo_name": "interkosmos/fortran-xlib", "max_issues_repo_head_hexsha": "0552aad2dca2ab3267b30a6f5126eb42d7eb2271", "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": "examples/wireframe/wireframe.f90", "max_forks_repo_name": "interkosmos/fortran-xlib", "max_forks_repo_head_hexsha": "0552aad2dca2ab3267b30a6f5126eb42d7eb2271", "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": 32.1220930233, "max_line_length": 96, "alphanum_fraction": 0.5362895928, "num_tokens": 2750, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813453, "lm_q2_score": 0.724870282120402, "lm_q1q2_score": 0.650712643615948}} {"text": "program testcap\n use defcapsol\n implicit none\n integer :: n, m, l_js, verbose, d_steps, test\n real(dp) :: h0, rho_max, Z_max, rtip, theta_deg, hcone, rcant, hsam, dcant, eps_r\n real(dp) :: C_unitless ! finest grid spacing and simulation box size (truncation lengths)\n \n character*10 method_in\n\n real(dp), allocatable :: hess(:, :) ! grid-spacing and coordinates of each grid point\n\n\n\n ! Nuni = 5\n n=500\n m=500\n l_js=20\n h0=0.5_dp\n rho_max=1d6\n Z_max=1d6\n d_steps=20\n rtip=20.0\n theta_deg=15.0\n hcone=15000.0\n rcant=15000.0\n dcant=500.0\n eps_r=5.0\n hsam=10.0\n method_in='LAPACK'\n test=0\n verbose=2\n C_unitless = 0.0_dp\n\n\n allocate (Hess(0:min(m+ l_js + d_steps + 1, n+1), (n+1)*( l_js + d_steps + m + 1)))\n\n CALL CapSolCyl(n,m,l_js, h0,rho_max,z_max, d_steps, rtip,theta_deg, hcone, rcant, &\n dcant, eps_r,hsam, method_in, test, verbose, C_unitless, Hess)\n\n deallocate (Hess)\nend program testcap", "meta": {"hexsha": "7a3e563fb42275094be7de4e433cfddb36910c76", "size": 990, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "capsol/test_capsolpy.f90", "max_stars_repo_name": "maroniea/xsede-spm", "max_stars_repo_head_hexsha": "d272c62ecce7df9f6923b456e54d59cd0738e6c6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-10-04T22:22:40.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-04T22:44:46.000Z", "max_issues_repo_path": "capsol/test_capsolpy.f90", "max_issues_repo_name": "maroniea/xsede-spm", "max_issues_repo_head_hexsha": "d272c62ecce7df9f6923b456e54d59cd0738e6c6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-07-27T02:00:38.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-27T02:00:38.000Z", "max_forks_repo_path": "capsol/test_capsolpy.f90", "max_forks_repo_name": "maroniea/xsede-spm", "max_forks_repo_head_hexsha": "d272c62ecce7df9f6923b456e54d59cd0738e6c6", "max_forks_repo_licenses": ["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.1463414634, "max_line_length": 95, "alphanum_fraction": 0.6313131313, "num_tokens": 369, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703477, "lm_q2_score": 0.7248702761768248, "lm_q1q2_score": 0.6507126323285185}} {"text": "C\nC $Id$\nC\n FUNCTION SH3VAL (PX,PY,PZ,N,X,Y,Z,F,NR,LCELL,LNEXT,\n + XYZMIN,XYZDEL,RMAX,RSQ,A)\n INTEGER N, NR, LCELL(NR,NR,NR), LNEXT(N)\n REAL PX, PY, PZ, X(N), Y(N), Z(N), F(N), XYZMIN(3),\n + XYZDEL(3), RMAX, RSQ(N), A(9,N)\nC\nC***********************************************************\nC\nC ROBERT RENKA\nC UNIV. OF NORTH TEXAS\nC (817) 565-2767\nC 10/28/87\nC\nC This function returns the value Q(PX,PY,PZ) where Q is\nC the weighted sum of quadratic nodal functions defined in\nC subroutine SHQSHEP. SH3GRD may be called to compute a\nC gradient of Q along with the value, and/or to test for\nC errors.\nC\nC ON INPUT --\nC\nC PX,PY,PZ = Cartesian coordinates of the point P at\nC which Q is to be evaluated.\nC\nC N = Number of nodes and data values defining Q.\nC N .GE. 10.\nC\nC X,Y,Z,F = Arrays of length N containing the nodes\nC and data values interpolated by Q.\nC\nC NR = Number of rows, columns, and planes in the cell\nC grid. Refer to SHSTORE3. NR .GE. 1.\nC\nC LCELL = NR by NR by NR array of nodal indices associated\nC with cells. Refer to SHSTORE3.\nC\nC LNEXT = Array of length N containing next-node indices\nC Refer to SHSTORE3.\nC\nC XYZMIN,XYZDEL = Arrays of length 3 containing minimum\nC nodal coordinates and cell dimensions\nC respectively. XYZDEL elements must be \nC positive. Refer to SHSTORE3.\nC\nC RMAX = Square root of the largest element in RSQ --\nC maximum radius.\nC\nC RSQ = Array of length N containing the squared radii\nC which enter into the weights defining Q.\nC\nC A = 9 by N array containing the coefficients for the\nC nodal functions defining Q.\nC\nC Input parameters are not altered by this function. The\nC parameters other than PX, PY and PZ should be input unaltered\nC from their values on output from SHQSHEP. This function\nC should not be called if a nonzero error flag was returned by \nC SHQSHEP.\nC\nC ON OUTPUT --\nC\nC SH3VAL = function value Q(PX,PY,PZ) unless N, NR,\nC XYZDEL, or RMAX is invalid, in which case\nC no value is returned.\nC\nC MODULES REQUIRED BY SH3VAL -- NONE\nC\nC INTRINSIC FUNCTIONS CALLED BY SH3VAL -- IFIX, SQRT\nC\nC***********************************************************\nC\n XP = PX\n YP = PY\n ZP = PZ\n XMIN = XYZMIN(1)\n YMIN = XYZMIN(2)\n ZMIN = XYZMIN(3)\n DX = XYZDEL(1)\n DY = XYZDEL(2)\n DZ = XYZDEL(3)\n IF (N .LT. 10) THEN\n GO TO 30\n ELSEIF (NR .LT. 1) THEN\n GO TO 31\n ELSEIF (DX .LE. 0.) THEN\n GO TO 32\n ELSEIF (DY .LE. 0.) THEN\n GO TO 33\n ELSEIF (DZ .LE. 0.) THEN\n GO TO 34\n ELSEIF (RMAX .LT. 0.) THEN\n GO TO 35\n ENDIF\nC\nC Set IMIN, IMAX, JMIN, JMAX, KMIN, and KMAX to cell indices\nC defining the range of the search for nodes whose radii\nC include P. The cells which must be searched are those\nC intersected by (or contained in) a sphere of radius RMAX\nC centered at P.\nC\n IMIN = IFIX((XP-XMIN-RMAX)/DX) + 1\n IMAX = IFIX((XP-XMIN+RMAX)/DX) + 1\n IF (IMIN .LT. 1) IMIN = 1\n IF (IMAX .GT. NR) IMAX = NR\n JMIN = IFIX((YP-YMIN-RMAX)/DY) + 1\n JMAX = IFIX((YP-YMIN+RMAX)/DY) + 1\n IF (JMIN .LT. 1) JMIN = 1\n IF (JMAX .GT. NR) JMAX = NR\n KMIN = IFIX((ZP-ZMIN-RMAX)/DZ) + 1\n KMAX = IFIX((ZP-ZMIN+RMAX)/DZ) + 1\n IF (KMIN .LT. 1) KMIN = 1\n IF (KMAX .GT. NR) KMAX = NR\nC\nC The following is a test for no cells within the sphere\nC of radius RMAX.\nC\n IF (IMIN .GT. IMAX .OR. JMIN .GT. JMAX .OR.\n . KMIN .GT. KMAX) GO TO 5\nC\nC Accumulate weight values in SW and weighted nodal function\nC values in SWQ. The weights are W(L) = ((R-D)+/(R*D))**2\nC for R**2 = RSQ(L) and D = distance between P and node L.\nC\n SW = 0.\n SWQ = 0.\nC\nC Outer loop on cells (I,J,K).\nC\n DO 3 K = KMIN,KMAX\n DO 3 J = JMIN,JMAX\n DO 3 I = IMIN,IMAX\n L = LCELL(I,J,K)\n IF (L .EQ. 0) GO TO 3\nC\nC Inner loop on nodes L.\nC\n 1 DELX = XP - X(L)\n DELY = YP - Y(L)\n DELZ = ZP - Z(L)\n DXSQ = DELX*DELX\n DYSQ = DELY*DELY\n DZSQ = DELZ*DELZ\n DS = DXSQ + DYSQ + DZSQ\n RS = RSQ(L)\n IF (DS .GE. RS) GO TO 2\n IF (DS .EQ. 0.) GO TO 4\n RDS = RS*DS\n RD = SQRT(RDS)\n W = (RS+DS-RD-RD)/RDS\n SW = SW + W\n SWQ = SWQ + W*( A(1,L)*DXSQ + A(2,L)*DELX*DELY +\n + A(3,L)*DYSQ + A(4,L)*DELX*DELZ +\n + A(5,L)*DELY*DELZ + A(6,L)*DZSQ +\n + A(7,L)*DELX + A(8,L)*DELY +\n + A(9,L)*DELZ + F(L) )\nC\nC Bottom of loop on nodes in cell (I,J,K).\nC\n 2 LP = L\n L = LNEXT(LP)\n IF (L .NE. LP) GO TO 1\n 3 CONTINUE\nC\nC SW = 0 iff P is not within the radius R(L) for any node L.\nC\n IF (SW .EQ. 0.) GO TO 5\n SH3VAL = SWQ/SW\n RETURN\nC\nC (PX,PY,PZ) = (X(L),Y(L),Z(L))\nC\n 4 SH3VAL = F(L)\n RETURN\nC\nC All weights are 0 at P.\nC\n 5 SH3VAL = 0.\n RETURN\nC\nC Invalid input parameter.\nC\n 30 CONTINUE\n CALL SHERR (1,'SH3VAL - number of input data must be > 9',41)\n SH3VAL = 0.\n RETURN\n 31 CONTINUE\n CALL SHERR (7,'SH3VAL - cell grid dimensions must be positive',\n + 46)\n SH3VAL = 0.\n RETURN\n 32 CONTINUE\n CALL SHERR (10,'SH3VAL - at least two points must have different X\n + coordinates',62)\n SH3VAL = 0.\n RETURN\n 33 CONTINUE\n CALL SHERR (11,'SH3VAL - at least two points must have different Y\n + coordinates',62)\n SH3VAL = 0.\n RETURN\n 34 CONTINUE\n CALL SHERR (12,'SH3VAL - at least two points must have different Z\n + coordinates',62)\n SH3VAL = 0.\n RETURN\n 35 CONTINUE\n CALL SHERR (14,\n +'SH3GRD - negative search radius in calculating least squares fit'\n + ,64)\n SH3VAL = 0.\n RETURN\n END\n", "meta": {"hexsha": "fa4940cfd466043946e5b447ee31d0f363cabc91", "size": 6333, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "contrib/shgrid/Src/sh3val.f", "max_stars_repo_name": "xylar/cdat", "max_stars_repo_head_hexsha": "8a5080cb18febfde365efc96147e25f51494a2bf", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 62, "max_stars_repo_stars_event_min_datetime": "2018-03-30T15:46:56.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-08T23:30:24.000Z", "max_issues_repo_path": "contrib/shgrid/Src/sh3val.f", "max_issues_repo_name": "xylar/cdat", "max_issues_repo_head_hexsha": "8a5080cb18febfde365efc96147e25f51494a2bf", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 114, "max_issues_repo_issues_event_min_datetime": "2018-03-21T01:12:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-05T12:29:54.000Z", "max_forks_repo_path": "contrib/shgrid/Src/sh3val.f", "max_forks_repo_name": "CDAT/uvcdat", "max_forks_repo_head_hexsha": "5133560c0c049b5c93ee321ba0af494253b44f91", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 14, "max_forks_repo_forks_event_min_datetime": "2018-06-06T02:42:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-26T03:27:00.000Z", "avg_line_length": 29.3194444444, "max_line_length": 72, "alphanum_fraction": 0.5278698879, "num_tokens": 2116, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952811593495, "lm_q2_score": 0.724870282120402, "lm_q1q2_score": 0.6507126317121313}} {"text": "!--------------------------------------------------------------------------------\n! Copyright (c) 2016 Peter Gr\u00fcnberg Institut, Forschungszentrum J\u00fclich, 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\n MODULE m_metrz0\n use m_juDFT\nc *****************************************************\nc calculates weights for a 7-point simpson integration\nc in analogy to intgz0\nc r.pentcheva,24.06.96,kfa\nc work array whelp eliminated\nc s.bluegel, BNL 9.Aug.96\nc *****************************************************\n CONTAINS\n SUBROUTINE metr_z0(\n > nz,\n < wght)\n\n IMPLICIT NONE\nC ..\nC .. Scalar Arguments ..\n INTEGER, INTENT (IN) :: nz\nC ..\nC .. Array Arguments ..\n REAL, INTENT (OUT) :: wght(nz)\nC ..\nC .. Local Scalars ..\n INTEGER i,iz,j,iz0,jz,nsteps\n INTEGER, PARAMETER :: nz7 = 7 , nz6 = 6\n REAL, PARAMETER :: h0 = 140. \nC ..\nC .. Local Arrays ..\n!\n! lagrangian integration coefficients (simpson 7 point rule: error h**9)\n!\n INTEGER, DIMENSION(7), PARAMETER :: ih =\n + (/41,216,27,272,27,216,41/)\n REAL, DIMENSION(7,5), PARAMETER :: a = RESHAPE(\n + (/19087.,65112.,-46461., 37504.,-20211., 6312.,-863.,\n + -863.,25128., 46989.,-16256., 7299.,-2088., 271.,\n + 271.,-2760., 30819., 37504., -6771., 1608.,-191.,\n + -191., 1608., -6771., 37504., 30819.,-2760., 271.,\n + 271.,-2088., 7299.,-16256., 46989.,25128.,-863./),(/7,5/))\nC ..\n wght(:)=0.0\n nsteps = (nz-1)/nz6\n iz0 = nz-nz6*nsteps\n DO iz = 1, iz0-1\nc\nc---> for iz-points, 1 weights for simpson integration\n iz0 = nz - iz0 + 2\n DO j=1,nsteps\n DO i=1,nz7\n wght(iz0-i) = wght(iz0-i) + ih(i)\n ENDDO\n iz0 = iz0 - nz6\n ENDDO\n IF (iz0-1.ne.1) CALL juDFT_error(\"iz0> REAL64\n implicit none\n real(kind=DP) :: x, x0, r\n integer :: nr_iterations, i\n\n call get_parameters(x0, r, nr_iterations)\n x = x0\n do i = 1, nr_iterations\n x = logistic_iteration(x, r)\n print '(I0, F15.7)', i, x\n end do\n\ncontains\n\n function logistic_iteration(x, r) result(y)\n implicit none\n real(kind=DP), value :: x, r\n real(kind=DP) :: y\n\n y = r*x*(1.0_DP - x)\n end function logistic_iteration\n\n subroutine get_parameters(x0, r, nr_iterations)\n use, intrinsic :: iso_fortran_env, only : error_unit\n implicit none\n real(kind=DP), intent(out) :: x0, r\n integer, intent(out) :: nr_iterations\n character(len=1024) :: buffer, msg\n integer :: status\n\n if (command_argument_count() /= 3) then\n x0 = 0.5\n r = 3.0\n nr_iterations = 1000\n else\n call get_command_argument(1, buffer)\n read (buffer, fmt=*, iostat=status, iomsg=msg) x0\n if (status /= 0) then\n write (unit=error_unit, fmt='(2A)') 'error: ', msg\n stop 1\n end if\n call get_command_argument(2, buffer)\n read (buffer, fmt=*, iostat=status, iomsg=msg) r\n if (status /= 0) then\n write (unit=error_unit, fmt='(2A)') 'error: ', msg\n stop 1\n end if\n call get_command_argument(3, buffer)\n read (buffer, fmt=*, iostat=status, iomsg=msg) nr_iterations\n if (status /= 0) then\n write (unit=error_unit, fmt='(2A)') 'error: ', msg\n stop 1\n end if\n end if\n end subroutine get_parameters\n\nend program logistic_function\n", "meta": {"hexsha": "73d22db21963d35627bf8e6dd903d8531d7d3752", "size": 1827, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source_code/logistic_map/logistic_function.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/logistic_map/logistic_function.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/logistic_map/logistic_function.f90", "max_forks_repo_name": "caguerra/Fortran-MOOC", "max_forks_repo_head_hexsha": "fb8a9c24e62ce5f388deb06b21e3009aea6b78d4", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2021-09-27T07:30:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-07T16:23:19.000Z", "avg_line_length": 30.9661016949, "max_line_length": 72, "alphanum_fraction": 0.5446086481, "num_tokens": 503, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.798186787341014, "lm_q2_score": 0.8152324848629214, "lm_q1q2_score": 0.6507077980287671}} {"text": "module matrix_ops\n use :: precision_defs, only : dp\n implicit none\n private\n public :: init_matrix, print_matrix, print_vector\n\ncontains\n\n subroutine init_matrix(A)\n implicit none\n real(kind=dp), dimension(:,:), intent(out) :: A\n integer :: i, j\n do j = 1, size(A, 2)\n do i = 1, size(A, 1)\n call random_number(A(i, j))\n end do\n end do\n end subroutine init_matrix\n\n subroutine print_matrix(A, label)\n implicit none\n real(kind=dp), dimension(:,:), intent(in) :: A\n character(len=*), optional, intent(in) :: label\n integer :: i\n character(len=40) :: format_str\n if (present(label)) then\n write (*, \"(2A)\") label, \":\"\n end if\n write (format_str, \"(A,I3,A)\") \"(\", size(A, 2), \"(F8.3))\"\n do i = 1, size(A, 1)\n write (*, format_str) A(i, :)\n end do\n end subroutine print_matrix\n\n subroutine print_vector(v, label)\n implicit none\n real(kind=dp), dimension(:), intent(in) :: v\n character(len=*), optional, intent(in) :: label\n character(len=40) :: format_str\n if (present(label)) then\n write (*, \"(2A)\") label, \":\"\n end if\n write (format_str, \"(A,I3,A)\") \"(\", size(v), \"(F8.3))\"\n write (*, format_str) v(:)\n end subroutine print_vector\n\nend module matrix_ops\n", "meta": {"hexsha": "3ccf349d5a7518c967c735124e6cb0c698ce13ce", "size": 1411, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Fortran/Matrices/matrix_ops.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/matrix_ops.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/matrix_ops.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": 29.3958333333, "max_line_length": 65, "alphanum_fraction": 0.533664068, "num_tokens": 373, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7981867585368343, "lm_q2_score": 0.8152324803738429, "lm_q1q2_score": 0.650707770963541}} {"text": "program tpk\n implicit none\n\n real, parameter :: overflow = 400.0\n real :: a(11), res\n integer :: i\n\n write(*,*) \"Input eleven numbers:\"\n read(*,*) a\n\n a = a(11:1:-1)\n do i = 1, 11\n res = f(a(i))\n write(*, \"(a, f0.3, a)\", advance = \"no\") \"f(\", a(i), \") = \"\n if(res > overflow) then\n write(*, \"(a)\") \"overflow!\"\n else\n write(*, \"(f0.3)\") res\n end if\n end do\n\ncontains\n\nreal function f(x)\n real, intent(in) :: x\n\n f = sqrt(abs(x)) + 5.0*x**3\n\nend function\nend program\n", "meta": {"hexsha": "c20882413bd9a566878d153d0e9f2037c1bcd546", "size": 502, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Trabb-Pardo-Knuth-algorithm/Fortran/trabb-pardo-knuth-algorithm-1.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Trabb-Pardo-Knuth-algorithm/Fortran/trabb-pardo-knuth-algorithm-1.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Trabb-Pardo-Knuth-algorithm/Fortran/trabb-pardo-knuth-algorithm-1.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 16.1935483871, "max_line_length": 63, "alphanum_fraction": 0.5139442231, "num_tokens": 186, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218305645894, "lm_q2_score": 0.7057850278370111, "lm_q1q2_score": 0.650678624848577}} {"text": "!-----------------------------------------------------------------------\n! Update soil temperatures\n!-----------------------------------------------------------------------\nsubroutine SOIL(csoil,Gsoil,ksoil)\n\nuse DRIVING, only : &\n dt ! Timestep (s)\n\nuse GRID, only : &\n Dzsoil, &! Soil layer thicknesses (m)\n Nsoil ! Number of soil layers\n\nuse STATE_VARIABLES, only : &\n Tsoil ! Soil layer temperatures (K)\n\nimplicit none\n\nreal*8, intent(in) :: &\n csoil(Nsoil), &! Areal heat capacity of soil (J/K/m^2)\n Gsoil, &! Heat flux into soil (W/m^2)\n ksoil(Nsoil) ! Thermal conductivity of soil (W/m/K)\n\ninteger*8 :: &\n k ! Level counter\n\nreal*8 :: &\n a(Nsoil), &! Below-diagonal matrix elements\n b(Nsoil), &! Diagonal matrix elements\n c(Nsoil), &! Above-diagonal matrix elements\n dTs(Nsoil), &! Temperature increments (k)\n Gs(Nsoil), &! Thermal conductivity between layers (W/m^2/k)\n rhs(Nsoil) ! Matrix equation rhs\n\ndo k = 1, Nsoil - 1\n Gs(k) = 2 / (Dzsoil(k)/ksoil(k) + Dzsoil(k+1)/ksoil(k+1))\nend do\na(1) = 0\nb(1) = csoil(1) + Gs(1)*dt\nc(1) = - Gs(1)*dt\nrhs(1) = (Gsoil - Gs(1)*(Tsoil(1) - Tsoil(2)))*dt\ndo k = 2, Nsoil - 1\n a(k) = c(k-1)\n b(k) = csoil(k) + (Gs(k-1) + Gs(k))*dt\n c(k) = - Gs(k)*dt\n rhs(k) = Gs(k-1)*(Tsoil(k-1) - Tsoil(k))*dt &\n + Gs(k)*(Tsoil(k+1) - Tsoil(k))*dt \nend do\nk = Nsoil\nGs(k) = ksoil(k)/Dzsoil(k)\na(k) = c(k-1)\nb(k) = csoil(k) + (Gs(k-1) + Gs(k))*dt\nc(k) = 0\nrhs(k) = Gs(k-1)*(Tsoil(k-1) - Tsoil(k))*dt\ncall TRIDIAG(Nsoil,Nsoil,a,b,c,rhs,dTs)\ndo k = 1, Nsoil\n Tsoil(k) = Tsoil(k) + dTs(k)\nend do\n\nend subroutine SOIL\n", "meta": {"hexsha": "a4155b7bd822d541fa23b31b4213c1fae6d2c5ef", "size": 1724, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "deps/SOIL.f90", "max_stars_repo_name": "jmgnve/JFSM.jl", "max_stars_repo_head_hexsha": "5cbe139f2e7eb7d8e5844d8a7feffa93f69e8596", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "deps/SOIL.f90", "max_issues_repo_name": "jmgnve/JFSM.jl", "max_issues_repo_head_hexsha": "5cbe139f2e7eb7d8e5844d8a7feffa93f69e8596", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "deps/SOIL.f90", "max_forks_repo_name": "jmgnve/JFSM.jl", "max_forks_repo_head_hexsha": "5cbe139f2e7eb7d8e5844d8a7feffa93f69e8596", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-02-08T11:09:51.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-08T11:09:51.000Z", "avg_line_length": 28.7333333333, "max_line_length": 72, "alphanum_fraction": 0.4965197216, "num_tokens": 648, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218391455084, "lm_q2_score": 0.7057850154599562, "lm_q1q2_score": 0.6506786194941839}} {"text": " SUBROUTINE MB05ND( N, DELTA, A, LDA, EX, LDEX, EXINT, LDEXIN,\n $ TOL, IWORK, DWORK, LDWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To compute\nC\nC (a) F(delta) = exp(A*delta) and\nC\nC (b) H(delta) = Int[F(s) ds] from s = 0 to s = delta,\nC\nC where A is a real N-by-N matrix and delta is a scalar value.\nC\nC ARGUMENTS\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The order of the matrix A. N >= 0.\nC\nC DELTA (input) DOUBLE PRECISION\nC The scalar value delta of the problem.\nC\nC A (input) DOUBLE PRECISION array, dimension (LDA,N)\nC The leading N-by-N part of this array must contain the\nC matrix A of the problem. (Array A need not be set if\nC DELTA = 0.)\nC\nC LDA INTEGER\nC The leading dimension of array A. LDA >= max(1,N).\nC\nC EX (output) DOUBLE PRECISION array, dimension (LDEX,N)\nC The leading N-by-N part of this array contains an\nC approximation to F(delta).\nC\nC LDEX INTEGER\nC The leading dimension of array EX. LDEX >= MAX(1,N).\nC\nC EXINT (output) DOUBLE PRECISION array, dimension (LDEXIN,N)\nC The leading N-by-N part of this array contains an\nC approximation to H(delta).\nC\nC LDEXIN INTEGER\nC The leading dimension of array EXINT. LDEXIN >= MAX(1,N).\nC\nC Tolerances\nC\nC TOL DOUBLE PRECISION\nC The tolerance to be used in determining the order of the\nC Pade approximation to H(t), where t is a scale factor\nC determined by the routine. A reasonable value for TOL may\nC be SQRT(EPS), where EPS is the machine precision (see\nC LAPACK Library routine DLAMCH).\nC\nC Workspace\nC\nC IWORK INTEGER array, dimension (N)\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0, DWORK(1) returns the optimal value\nC of LDWORK.\nC\nC LDWORK INTEGER\nC The length of the array DWORK. LDWORK >= MAX(1,N*(N+1)).\nC For optimum performance LDWORK should be larger (2*N*N).\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value;\nC > 0: if INFO = i, the (i,i) element of the denominator of\nC the Pade approximation is zero, so the denominator\nC is exactly singular;\nC = N+1: if DELTA = (delta * frobenius norm of matrix A) is\nC probably too large to permit meaningful computation.\nC That is, DELTA > SQRT(BIG), where BIG is a\nC representable number near the overflow threshold of\nC the machine (see LAPACK Library Routine DLAMCH).\nC\nC METHOD\nC\nC This routine uses a Pade approximation to H(t) for some small\nC value of t (where 0 < t <= delta) and then calculates F(t) from\nC H(t). Finally, the results are re-scaled to give F(delta) and\nC H(delta). For a detailed description of the implementation of this\nC algorithm see [1].\nC\nC REFERENCES\nC\nC [1] Benson, C.J.\nC The numerical evaluation of the matrix exponential and its\nC integral.\nC Report 82/03, Control Systems Research Group,\nC School of Electronic Engineering and Computer\nC Science, Kingston Polytechnic, January 1982.\nC\nC [2] Ward, R.C.\nC Numerical computation of the matrix exponential with accuracy\nC estimate.\nC SIAM J. Numer. Anal., 14, pp. 600-610, 1977.\nC\nC [3] Moler, C.B. and Van Loan, C.F.\nC Nineteen Dubious Ways to Compute the Exponential of a Matrix.\nC SIAM Rev., 20, pp. 801-836, 1978.\nC\nC NUMERICAL ASPECTS\nC 3\nC The algorithm requires 0(N ) operations.\nC\nC CONTRIBUTOR\nC\nC Release 3.0: V. Sima, Katholieke Univ. Leuven, Belgium, May 1997.\nC Supersedes Release 2.0 routine MB05BD by C.J. Benson, Kingston\nC Polytechnic, January 1982.\nC\nC REVISIONS\nC\nC -\nC\nC KEYWORDS\nC\nC Continuous-time system, matrix algebra, matrix exponential,\nC matrix operations, Pade approximation.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, HALF, ONE, ONE64, THREE, FOUR8\n PARAMETER ( ZERO = 0.0D0, HALF = 0.5D0, ONE = 1.0D0,\n $ ONE64 = 1.64D0, THREE = 3.0D0, FOUR8 = 4.8D0 )\nC .. Scalar Arguments ..\n INTEGER INFO, LDA, LDEX, LDEXIN, LDWORK, N\n DOUBLE PRECISION DELTA, TOL\nC .. Array Arguments ..\n INTEGER IWORK(*)\n DOUBLE PRECISION A(LDA,*), DWORK(*), EX(LDEX,*), EXINT(LDEXIN,*)\nC .. Local Scalars ..\n INTEGER I, I2IQ1, IJ, IQ, J, JSCAL, KK, L, NN\n DOUBLE PRECISION COEFFD, COEFFN, DELSC, EPS, ERR, F2IQ1,\n $ FNORM, FNORM2, QMAX, SMALL\nC .. External Functions ..\n LOGICAL LSAME\n DOUBLE PRECISION DLAMCH, DLANGE\n EXTERNAL DLAMCH, DLANGE, LSAME\nC .. External Subroutines ..\n EXTERNAL DAXPY, DCOPY, DGEMM, DGEMV, DGESV, DLACPY,\n $ DLASET, DSCAL, XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC ABS, DBLE, EXP, MAX, MOD, SQRT\nC .. Executable Statements ..\nC\n INFO = 0\n NN = N*N\nC\nC Test the input scalar arguments.\nC\n IF( N.LT.0 ) THEN\n INFO = -1\n ELSE IF( LDA.LT.MAX( 1, N ) ) THEN\n INFO = -4\n ELSE IF( LDEX.LT.MAX( 1, N ) ) THEN\n INFO = -6\n ELSE IF( LDEXIN.LT.MAX( 1, N ) ) THEN\n INFO = -8\n ELSE IF( LDWORK.LT.MAX( 1, NN + N ) ) THEN\n INFO = -12\n END IF\nC\n IF ( INFO.NE.0 ) THEN\nC\nC Error return.\nC\n CALL XERBLA( 'MB05ND', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n DWORK(1) = ONE\n IF ( N.EQ.0 )\n $ RETURN\nC\n CALL DLASET( 'Full', N, N, ZERO, ZERO, EX, LDEX )\n CALL DLASET( 'Full', N, N, ZERO, ZERO, EXINT, LDEXIN )\nC\n IF ( DELTA.EQ.ZERO ) THEN\n CALL DLASET( 'Upper', N, N, ZERO, ONE, EX, LDEX )\n RETURN\n END IF\nC\n IF ( N.EQ.1 ) THEN\n EX(1,1) = EXP( DELTA*A(1,1) )\n IF ( A(1,1).EQ.ZERO ) THEN\n EXINT(1,1) = DELTA\n ELSE\n EXINT(1,1) = ( ( ONE/A(1,1) )*EX(1,1) ) - ( ONE/A(1,1) )\n END IF\n RETURN\n END IF\nC\nC Set some machine parameters.\nC\n EPS = DLAMCH( 'Epsilon' )\n SMALL = DLAMCH( 'Safe minimum' )/EPS\nC\nC First calculate the Frobenius norm of A, and the scaling factor.\nC\n FNORM = DELTA*DLANGE( 'Frobenius', N, N, A, LDA, DWORK )\nC\n IF ( FNORM.GT.SQRT( ONE/SMALL ) ) THEN\n INFO = N + 1\n RETURN\n END IF\nC\n JSCAL = 0\n DELSC = DELTA\nC WHILE ( FNORM >= HALF ) DO\n 20 CONTINUE\n IF ( FNORM.GE.HALF ) THEN\n JSCAL = JSCAL + 1\n DELSC = DELSC*HALF\n FNORM = FNORM*HALF\n GO TO 20\n END IF\nC END WHILE 20\nC\nC Calculate the order of the Pade approximation needed to satisfy\nC the requested relative error TOL.\nC\n FNORM2 = FNORM**2\n IQ = 1\n QMAX = FNORM/THREE\n ERR = DELTA/DELSC*FNORM2**2/FOUR8\nC WHILE ( ERR > TOL*( 2*IQ + 3 - FNORM )/1.64 and QMAX >= EPS ) DO\n 40 CONTINUE\n IF ( ERR.GT.TOL*( DBLE( 2*IQ + 3 ) - FNORM )/ONE64 ) THEN\n IQ = IQ + 1\n QMAX = QMAX*DBLE( IQ + 1 )*FNORM/DBLE( 2*IQ*( 2*IQ + 1 ) )\n IF ( QMAX.GE.EPS ) THEN\n ERR = ERR*FNORM2*DBLE( 2*IQ + 5 )/DBLE( ( 2*IQ + 3 )**2\n $ *( 2*IQ + 4 ) )\n GO TO 40\n END IF\n END IF\nC END WHILE 40\nC\nC Initialise DWORK (to contain succesive powers of A),\nC EXINT (to contain the numerator) and\nC EX (to contain the denominator).\nC\n I2IQ1 = 2*IQ + 1\n F2IQ1 = DBLE( I2IQ1 )\n COEFFD = -DBLE( IQ )/F2IQ1\n COEFFN = HALF/F2IQ1\n IJ = 1\nC\n DO 80 J = 1, N\nC\n DO 60 I = 1, N\n DWORK(IJ) = DELSC*A(I,J)\n EXINT(I,J) = COEFFN*DWORK(IJ)\n EX(I,J) = COEFFD*DWORK(IJ)\n IJ = IJ + 1\n 60 CONTINUE\nC\n EXINT(J,J) = EXINT(J,J) + ONE\n EX(J,J) = EX(J,J) + ONE\n 80 CONTINUE\nC\n DO 140 KK = 2, IQ\nC\nC Calculate the next power of A*DELSC, and update the numerator\nC and denominator.\nC\n COEFFD = -COEFFD*DBLE( IQ+1-KK )/DBLE( KK*( I2IQ1+1-KK ) )\n IF ( MOD( KK, 2 ).EQ.0 ) THEN\n COEFFN = COEFFD/DBLE( KK + 1 )\n ELSE\n COEFFN = -COEFFD/DBLE( I2IQ1 - KK )\n END IF\n IJ = 1\nC\n IF ( LDWORK.GE.2*NN ) THEN\nC\nC Enough space for a BLAS 3 calculation.\nC\n CALL DGEMM( 'No transpose', 'No transpose', N, N, N, DELSC,\n $ A, LDA, DWORK, N, ZERO, DWORK(NN+1), N )\n CALL DCOPY( NN, DWORK(NN+1), 1, DWORK, 1 )\nC\n DO 100 J = 1, N\n CALL DAXPY( N, COEFFN, DWORK(IJ), 1, EXINT(1,J), 1 )\n CALL DAXPY( N, COEFFD, DWORK(IJ), 1, EX(1,J), 1 )\n IJ = IJ + N\n 100 CONTINUE\nC\n ELSE\nC\nC Not enough space for a BLAS 3 calculation. Use BLAS 2.\nC\n DO 120 J = 1, N\n CALL DGEMV( 'No transpose', N, N, ONE, A, LDA, DWORK(IJ),\n $ 1, ZERO, DWORK(NN+1), 1 )\n CALL DCOPY( N, DWORK(NN+1), 1, DWORK(IJ), 1 )\n CALL DSCAL( N, DELSC, DWORK(IJ), 1 )\n CALL DAXPY( N, COEFFN, DWORK(IJ), 1, EXINT(1,J), 1 )\n CALL DAXPY( N, COEFFD, DWORK(IJ), 1, EX(1,J), 1 )\n IJ = IJ + N\n 120 CONTINUE\nC\n END IF\n 140 CONTINUE\nC\nC We now have numerator in EXINT, denominator in EX.\nC\nC Solve the set of N systems of linear equations for the columns of\nC EXINT using the LU factorization of EX.\nC\n CALL DGESV( N, N, EX, LDEX, IWORK, EXINT, LDEXIN, INFO )\n IF ( INFO.NE.0 )\n $ RETURN\nC\nC Now we can form EX from EXINT using the formula:\nC EX = EXINT * A + I\nC\n DO 160 J = 1, N\n CALL DSCAL( N, DELSC, EXINT(1,J), 1 )\n 160 CONTINUE\nC\n CALL DGEMM( 'No transpose', 'No transpose', N, N, N, ONE, EXINT,\n $ LDEXIN, A, LDA, ZERO, EX, LDEX )\nC\n DO 180 J = 1, N\n EX(J,J) = EX(J,J) + ONE\n 180 CONTINUE\nC\nC EX and EXINT have been evaluated at DELSC, so the results\nC must be re-scaled to give the function values at DELTA.\nC\nC EXINT(2t) = EXINT(t) * ^ EX(t) + I [\nC EX(2t) = EX(t) * EX(t)\nC\nC DWORK is used to accumulate products.\nC\n DO 200 L = 1, JSCAL\n CALL DLACPY( 'Full', N, N, EXINT, LDEXIN, DWORK, N )\n CALL DGEMM( 'No transpose', 'No transpose', N, N, N, ONE,\n $ DWORK, N, EX, LDEX, ONE, EXINT, LDEXIN )\n CALL DLACPY( 'Full', N, N, EX, LDEX, DWORK, N )\n CALL DGEMM( 'No transpose', 'No transpose', N, N, N, ONE,\n $ DWORK, N, DWORK, N, ZERO, EX, LDEX )\n 200 CONTINUE\nC\n DWORK(1) = 2*NN\n RETURN\nC *** Last line of MB05ND ***\n END\n", "meta": {"hexsha": "70f9dfb80f9a5ed4c5a2059798f0c1a4780336ab", "size": 11365, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB05ND.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB05ND.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB05ND.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 31.2225274725, "max_line_length": 72, "alphanum_fraction": 0.5350637923, "num_tokens": 3792, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9219218370002787, "lm_q2_score": 0.7057850154599562, "lm_q1q2_score": 0.650678617980113}} {"text": "!>\n!> @file\n!>\n!> PLASMA is a software package provided by:\n!> University of Tennessee, US,\n!> University of Manchester, UK.\n!>\n!> @precisions normal z -> s d c\n!>\n!> @brief Tests PLASMA Cholesky factorization\n\n program test_zpotrf\n\n use, intrinsic :: iso_fortran_env\n use :: iso_c_binding\n use :: omp_lib\n use :: plasma\n implicit none\n\n ! Precisions\n integer, parameter :: sp = c_float\n integer, parameter :: dp = c_double\n\n ! set working precision, this value is rewritten for different precisions\n integer, parameter :: wp = dp\n\n integer, parameter :: n = 2000\n complex(wp), parameter :: zmone = -1.0\n complex(wp), allocatable :: A(:,:), Aref(:,:)\n real(wp), allocatable :: work(:)\n integer :: seed(4) = [0, 0, 0, 1]\n real(wp) :: Anorm, error, tol\n character :: uploLapack ='L'\n integer :: uploPlasma = PlasmaLower\n integer :: lda, infoPlasma, infoLapack, i\n logical :: success = .false.\n\n\n ! External functions\n real(wp), external :: dlamch, zlanhe, zlange\n\n\n tol = 50.0 * dlamch('E')\n print *, \"tol:\", tol\n\n lda = max(1,n)\n\n ! Allocate matrix A\n allocate(A(lda,n), stat=infoPlasma)\n\n ! Generate random Hermitian positive definite matrix A\n call zlarnv(1, seed, lda*n, A)\n A = A * conjg(transpose(A))\n do i = 1, n\n A(i,i) = A(i,i) + n\n end do\n\n allocate(Aref(lda,n), stat=infoPlasma)\n Aref = A\n\n !==============================================\n ! Initialize PLASMA.\n !==============================================\n call plasma_init(infoPlasma)\n\n !==============================================\n ! Perform Cholesky factorization.\n !==============================================\n call plasma_zpotrf(uploPlasma, n, A, lda, infoPlasma)\n\n !==============================================\n ! Finalise PLASMA.\n !==============================================\n call plasma_finalize(infoPlasma)\n\n ! Check Cholesky decomposition is correct\n\n ! Factorize matrix A using Cholesky\n call zpotrf(uploLapack, n, Aref, lda, infoLapack)\n print *, \"zpotrf:\", infoLapack\n\n if (infoLapack == 0) then\n\n ! Calculate difference A := -1*Aref+A, A := A-Aref\n ! A = A-Aref\n call zaxpy(lda*n, zmone, Aref, 1, A, 1)\n\n ! Calculate norms |Aref|_F, |Aref-A|_F,\n Anorm = zlanhe('F', uploLapack, n, Aref, lda, work)\n print *, \"|Aref|_F:\", Anorm\n\n error = zlange('F', n, n, A, lda, work)\n print *, \"|A-Aref|_F:\", error\n\n ! Calculate error |A-Aref|_F / |Aref|_F\n error = error/Anorm\n\n if (error < tol) success = .true.\n\n else\n\n if (infoPlasma == infoLapack) then\n error = 0.0\n success =.true.\n else\n error = 0.0\n success =.false.\n end if\n\n end if\n\n print *, \"|A-Aref|_F / |Aref|_F:\", error\n print *, \"success: \", success\n\n if (success) then\n write(*,'(a)') \" The result is CORRECT.\"\n else\n write(*,'(a)') \" The result is WRONG!\"\n end if\n write(*,'(a)') \"\"\n\n ! Deallocate matrix Aref\n deallocate(Aref, stat=infoPlasma)\n\n ! Deallocate matrix A\n deallocate(A, stat=infoPlasma)\n\n end program test_zpotrf\n", "meta": {"hexsha": "6821685fe86bd0dc2de349ef4d250d354dfb579d", "size": 3517, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fortran_examples/test_zpotrf.f90", "max_stars_repo_name": "luszczek/plasma", "max_stars_repo_head_hexsha": "a3cf431cd84d98cde0f4746a28891fd9cf3990a6", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2021-09-07T13:52:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-30T01:39:04.000Z", "max_issues_repo_path": "fortran_examples/test_zpotrf.f90", "max_issues_repo_name": "luszczek/plasma", "max_issues_repo_head_hexsha": "a3cf431cd84d98cde0f4746a28891fd9cf3990a6", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2021-09-14T13:17:51.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-09T18:00:04.000Z", "max_forks_repo_path": "fortran_examples/test_zpotrf.f90", "max_forks_repo_name": "luszczek/plasma", "max_forks_repo_head_hexsha": "a3cf431cd84d98cde0f4746a28891fd9cf3990a6", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 8, "max_forks_repo_forks_event_min_datetime": "2021-09-03T13:52:42.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-14T02:02:47.000Z", "avg_line_length": 27.2635658915, "max_line_length": 79, "alphanum_fraction": 0.4842195053, "num_tokens": 977, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.7520125793176222, "lm_q1q2_score": 0.6506593992534085}} {"text": "program double_quantum_well\n\n implicit none\n\n integer, parameter :: dp = selected_real_kind(8)\n real(dp), parameter :: Zero = 0.d0, Half = 0.5d0, One = 1.d0, Two = 2.d0\n real(dp), parameter :: pi = acos(-One)\n\n integer, parameter :: N = 200 ! discretization of x\n integer, parameter :: N_basis = 500 ! number of basis functions\n real(dp), parameter :: Range_of_X = 6.d0, x0 = 1.5d0\n real(dp) :: V_pot(-N:N), X(-N:N), dx, E, Y(-N:N)\n\n integer :: i, Idx\n\n ! ... executable ...\n dx = Range_of_X/N\n\n ! generate the potential data\n do i = -N, N\n X(i) = dx*i\n V_pot(i) = Half*( (x(i)**2 - x0**2)**2/Two/Two/x0**2 - X(i)**2 )\n end do \n\n open(unit=1, file='Vpot.dat', status = 'unknown')\n do i = -N, N\n write(1, '(2f12.6)') X(i), V_pot(i)\n end do\n close(1)\n\n ! calculate with numeral approach\n E = -1.5d0\n call Numerov(N, X, V_pot, E, Y)\n Y = Zero\n ! \n\n do Idx = 1, 2\n call Matrix_diagonalization(Idx, N, N_basis, X, V_pot)\n end do \n\ncontains\n !----------------------------------------------------------------------\n subroutine Numerov(Nx, X, Vpot, E, Y)\n !\n ! Purpose\n ! =======\n ! Solving one-dimensional Schrodinger equation with Numerov method.\n !\n integer, intent(in) :: Nx\n real(dp), intent(in) :: X(-Nx:Nx), Vpot(-Nx:Nx)\n real(dp), intent(out) :: Y(-Nx:Nx)\n real(dp), intent(inout) :: E\n\n ! ... local vars ...\n integer :: ite, i\n real(dp) :: f(-Nx:Nx), g(-Nx:Nx), dx, fac, Y_old, Emin, Emax, dE, temp(-Nx:Nx)\n logical :: bisection = .false.\n\n ! ... executable ...\n write(*, *) 'Numerov calculation starts ...'\n dx = X(2) - X(1)\n Y = Zero\n\n ! set boundary condition at Y(-Nx) and Y(-Nx+1) \n\n Emin = -200.d0\n Emax = 200.d0\n\n iteration: do ite = 1, 10000000\n \n Y = Zero\n Y(-Nx) = 0.d0\n Y(-Nx+1) = 0.00001d0\n dE = 0.0001d0\n\n do i = -Nx, Nx\n g(i) = 2.d0*(E - Vpot(i))\n f(i) = 1.d0 + g(i)/12.d0*dx*dx\n end do\n\n ! Nomerov's method\n do i = -Nx+1, Nx-1\n Y(i+1) = ((12.d0 - 10.d0*f(i))*Y(i) - f(i-1)*Y(i-1))/f(i+1)\n end do\n\n ! normalize the wave function Y(x)\n do i = -Nx, Nx\n Temp(i) = Y(i)**2\n end do\n call Simpson(Temp(-Nx:Nx), 2*Nx+1, dx, fac)\n Y = Y/sqrt(fac)\n\n\n if (ite == 1) Y_old = Y(Nx)\n \n ! monitor the boundary value of Y(Nx)\n if (ite == 1) write(*, *) 'Iteration, energy and boundary value'\n write(*, '(i10, f20.12, 4x, f20.12)') ite, E, Y(Nx)\n \n if (.NOT. bisection) then\n if (Y_old*Y(Nx) >= 0.d0) then\n Emin = E\n E = E + dE\n Y_old = Y(Nx)\n else\n Emax = E\n Emin = E-de\n bisection = .true.\n E = 0.5d0*(Emin+Emax)\n end if\n else\n if (Y_old*Y(Nx) >= 0 ) then\n Emin = E\n Y_old = Y(Nx)\n else\n Emax = E\n end if\n E = 0.5d0*(Emax + Emin)\n if (abs(Y(Nx)) < 1.d-8) exit\n end if\n\n end do iteration\n\n open(unit = 1, file='wave_Numerov.dat', status='unknown')\n do i = -Nx, Nx\n write(1, '(2f12.6)') X(i), Y(i)\n end do\n close(1)\n\n end subroutine Numerov\n\n !----------------------------------------------------------------------\n subroutine Matrix_diagonalization(Idx, Nx, N_basis, X, Vpot)\n !\n ! Purpose\n ! =======\n ! By using basis funtion to express the Hamiltonian in matrix form and \n ! calculate the ground state energy by diagonalizing it.\n !\n integer, intent(in) :: Idx, Nx, N_basis\n real(dp), intent(in) :: X(-Nx:Nx), Vpot(-Nx:Nx)\n\n ! local vars \n integer :: i, j, k, INFO, LWORK\n real(dp) :: basis(2*Nx+1, N_basis), Ham(N_basis, N_basis), WORK(10*N_basis), W(N_basis) \n real(dp) :: Xmax, V0, Temp(2*Nx+1)\n character(len=30) :: FLE \n\n\n Xmax = X(Nx)\n dx = X(2) - X(1)\n\n ! step[1]: generating the basis functions\n basis = 0.d0\n call basis_generation(Idx, Nx, N_basis, basis)\n\n ! step[2]: generating the Hamiltonian matrix\n Ham = 0.d0\n do i = 1, N_basis\n do j = i, N_basis\n\n select case (Idx)\n case(1)\n ! eigenvectors of inifite quantum well as basis\n do k = -Nx, Nx\n Temp(k+Nx+1) = Vpot(k)*basis(k+Nx+1, i)*basis(k+Nx+1, j) \n end do \n call Simpson(Temp, 2*Nx+1, dx, V0)\n Ham(i, j) = V0\n\n if (i == j) then\n Ham(i, i) = Ham(i, i) + (dble(i)*pi)**2/8.d0/Xmax/Xmax\n end if\n case(2)\n ! eigenvectors of quantum harmonic oscillator as basis\n do k = -Nx, Nx\n Temp(k+Nx+1) = (Vpot(k)-Half*X(k)**2)*basis(k+Nx+1, i)*basis(k+Nx+1, j) \n end do \n call Simpson(Temp, 2*Nx+1, dx, V0)\n Ham(i, j) = V0\n\n if (j == i) Ham(i, i) = Ham(i, i) + 0.5d0 + dble(j-1) \n end select\n Ham(j, i) = Ham(i, j)\n end do\n end do\n\n LWORK = 10*N_basis\n call DSYEV( 'V', 'U', N_basis, Ham, N_basis, W, WORK, LWORK, INFO)\n \n if (INFO == 0) then\n write(FLE, '(a,i1,a)') 'eigenvalue-', Idx, '.dat'\n open(unit=1, file=FLE, status='unknown')\n \n ! multiply the coefficient (which is stored in Ham now) with the basis function\n ! to get the wave functions. \n basis = matmul(basis, Ham) ! use basis to store Psi(x) = Sum_n c_n * Phi_n(x)\n \n ! renormalize the wave function\n do i = 1, N_basis\n call Simpson(basis(1:2*Nx+1, i)**2, 2*Nx+1, dx, V0)\n basis(1:2*Nx+1, i) = basis(1:2*Nx+1, i)/sqrt(V0)\n end do\n\n ! output results\n do i = 1, N_basis\n write(1, '(i4, f20.12)') i, W(i)\n end do\n close(1)\n\n write(FLE, '(a,i1,a)') 'wavefunction-', Idx, '.dat'\n open(unit=2, file=FLE, status='unknown')\n do i = 1, 2*Nx+1\n write(2, '(f12.6)', advance='no') X(i-Nx-1)\n do j = 1, N_basis\n write(2, '(f12.6)', advance='no') basis(i, j)\n end do\n write(2, *)\n end do\n close(2)\n else\n write(*, *) 'Diagonalization went wrong! aborting ...'\n stop \n end if\n\n end subroutine Matrix_diagonalization\n\n !--------------------------------------------------------------------\n subroutine basis_generation(Idx, Nx, N_basis, basis)\n\n integer, intent(in) :: Idx\n integer, intent(in) :: Nx, N_basis\n real(dp), intent(out) :: basis(2*Nx+1, N_basis) \n !\n ! Purposes\n ! =========\n ! This subroutine generates the basis functions for the Hamiltonian matrix.\n ! Here, two different eigenvectors can be selected by sepecifying the switcher\n ! Idx = 1 --- eigenvectors of the infinite quantum Well\n ! Idx = 2 --- eigenvectors of the quantum harmonic oscillator\n !\n\n ! ... local vars ...\n integer :: i, j \n\n open(unit = 1, file = 'basis_function.dat', status='unknown')\n \n select case(Idx)\n case(1)\n write(*, *) 'case 1: eigenvector of infinite quantum well as basis functions'\n do i = 1, 2*Nx+1 ! coordinate index\n do j = 1, N_basis ! order of basis function\n if (mod(j, 2) /= 0) then\n ! j is odd\n basis(i, j) = sqrt(1.d0/X(Nx))*cos(dble(j)*pi*X(i-Nx-1)/2.d0/X(Nx))\n else\n ! j is even\n basis(i, j) = sqrt(1.d0/X(Nx))*sin(dble(j)*pi*X(i-Nx-1)/2.d0/X(Nx))\n end if\n end do\n end do\n case(2)\n write(*, *) 'case 2: eigenvectors of quantum harmonic oscillator as basis functions'\n basis = 0.d0\n do i = 1, 2*Nx + 1 ! order of basis function\n basis(i, 1) = (1.d0/pi)**0.25*exp(-X(i-Nx-1)**2/2.d0)\n basis(i, 2) = (1.d0/pi)**0.25*exp(-X(i-Nx-1)**2/2.d0)*X(i-Nx-1)*sqrt(Two)\n end do \n\n do i = 1, 2*Nx + 1\n write(1, '(3f12.6)', advance='no') X(i-Nx-1), basis(i, 1), basis(i, 2)\n do j = 3, N_basis ! coordinate index\n basis(i, j) = (Two*X(i-Nx-1)*basis(i, j-1) - sqrt(Two*(j-2))*basis(i,j-2))/sqrt(Two*(j-1)) \n write(1, '(f12.6)', advance='no') basis(i, j)\n end do\n write(1, *)\n end do \n end select \n\n close(1)\n\n end subroutine basis_generation\n\n !--------------------------------------------------------------------\n subroutine Simpson(Func, nL, h, solution)\n\n implicit none\n integer, intent(in) :: nL\n real(dp), intent(in) :: Func(nL), h\n real(dp), intent(out) :: solution\n\n integer :: i\n\n if (Mod(nL, 2) == 0) then\n print*, \"nL must be odd!\"\n stop\n endif\n\n solution = (Func(1) + Func(nL))\n do i = 2, nL-1, 2\n solution = solution + 4.d0 * Func(i)\n enddo\n do i = 3, nL-2, 2\n solution = solution + 2.d0 * Func(i)\n enddo\n solution = solution * h/3.d0\n\n end subroutine Simpson\n\nend program double_quantum_well", "meta": {"hexsha": "1ac00b4d1e5aca7e7ad6d79eb2b4d04cd1b03bae", "size": 9434, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Week-2-Assignment-1/Assignment/4-sol/double_quantum_well.f90", "max_stars_repo_name": "Chen-Jialin/Computational-Physics-Exercises-and-Assignments", "max_stars_repo_head_hexsha": "592407af2e999b539473f473ca99186a12418b99", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-04-15T10:30:01.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-07T08:22:51.000Z", "max_issues_repo_path": "Week-2-Assignment-1/Assignment/4-sol/double_quantum_well.f90", "max_issues_repo_name": "Chen-Jialin/Computational-Physics-Exercises-and-Assignments", "max_issues_repo_head_hexsha": "592407af2e999b539473f473ca99186a12418b99", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Week-2-Assignment-1/Assignment/4-sol/double_quantum_well.f90", "max_forks_repo_name": "Chen-Jialin/Computational-Physics-Exercises-and-Assignments", "max_forks_repo_head_hexsha": "592407af2e999b539473f473ca99186a12418b99", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.4322580645, "max_line_length": 106, "alphanum_fraction": 0.4663981344, "num_tokens": 3015, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240756264639, "lm_q2_score": 0.7520125793176223, "lm_q1q2_score": 0.6506593887995626}} {"text": "program variables\r\n real :: a, b, c !entrada\r\n real :: d ! operaci\u00f3n\r\n character(16) :: msj_salida\r\n character(2) :: dun ! unidad distancia\r\n\r\n msj_salida = \"El promedio es:\"\r\n dun = \"km\"\r\n !a = 29.0\r\n !b = 4.0\r\n !c = 6.0\r\n print*, \"Ingrese los valores de a, b y c en \", dun\r\n read*, a, b, c \r\n \r\n d= (a + b + c) / 3.0\r\n\r\n print*, msj_salida, d, dun\r\n\r\nend program variables", "meta": {"hexsha": "0039f7410026f7aac9580a71d5d149f413826db7", "size": 416, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "promedio.f90", "max_stars_repo_name": "totallynotdavid/fortran", "max_stars_repo_head_hexsha": "da1551313ea6016fef19bc37445a3cb462e6fd8a", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "promedio.f90", "max_issues_repo_name": "totallynotdavid/fortran", "max_issues_repo_head_hexsha": "da1551313ea6016fef19bc37445a3cb462e6fd8a", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "promedio.f90", "max_forks_repo_name": "totallynotdavid/fortran", "max_forks_repo_head_hexsha": "da1551313ea6016fef19bc37445a3cb462e6fd8a", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.8947368421, "max_line_length": 55, "alphanum_fraction": 0.5144230769, "num_tokens": 148, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240756264639, "lm_q2_score": 0.7520125682019722, "lm_q1q2_score": 0.6506593791820344}} {"text": "! { dg-do run }\nprogram nint_1\n if (int(anint(8388609.0)) /= 8388609) call abort\n if (int(anint(0.49999997)) /= 0) call abort\n if (nint(8388609.0) /= 8388609) call abort\n if (nint(0.49999997) /= 0) call abort\n if (int(dnint(4503599627370497.0d0),8) /= 4503599627370497_8) call abort\n if (int(dnint(0.49999999999999994d0)) /= 0) call abort\n if (int(anint(-8388609.0)) /= -8388609) call abort\n if (int(anint(-0.49999997)) /= 0) call abort\n if (nint(-8388609.0) /= -8388609) call abort\n if (nint(-0.49999997) /= 0) call abort\n if (int(dnint(-4503599627370497.0d0),8) /= -4503599627370497_8) call abort\n if (int(dnint(-0.49999999999999994d0)) /= 0) call abort\nend program nint_1\n", "meta": {"hexsha": "e487bec8ff6424989dab457fff2aad3762ded033", "size": 687, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/nint_1.f90", "max_stars_repo_name": "maurizioabba/rose", "max_stars_repo_head_hexsha": "7597292cf14da292bdb9a4ef573001b6c5b9b6c0", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/nint_1.f90", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/nint_1.f90", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 42.9375, "max_line_length": 76, "alphanum_fraction": 0.6783114993, "num_tokens": 305, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424373085145, "lm_q2_score": 0.7690802370707283, "lm_q1q2_score": 0.650597610233422}} {"text": "c ======================================================================\r\nc User Subroutine VUMAT for Abaqus visco elastic material\r\nc All rights of reproduction or distribution in any form are reserved.\r\nc By Irfan Habeeb CN (PhD, Technion - IIT)\r\nc using the formulation https://imechanica.org/files/Kelvin-Voigt-Code-Development_0.pdf\r\nc ======================================================================\r\n subroutine vumat(\r\nC Read only -\r\n 1 nblock, ndir, nshr, nstatev, nfieldv, nprops, lanneal,\r\n 2 stepTime, totalTime, dt, cmname, coordMp, charLength,\r\n 3 props, density, strainInc, relSpinInc,\r\n 4 tempOld, stretchOld, defgradOld, fieldOld,\r\n 5 stressOld, stateOld, enerInternOld, enerInelasOld,\r\n 6 tempNew, stretchNew, defgradNew, fieldNew,\r\nC Write only -\r\n 7 stressNew, stateNew, enerInternNew, enerInelasNew)\r\nc\r\n include 'vaba_param.inc'\r\nc\r\n dimension props(nprops), density(nblock), coordMp(nblock,*),\r\n 1 charLength(nblock), strainInc(nblock,ndir+nshr),\r\n 2 relSpinInc(nblock,nshr), tempOld(nblock),\r\n 3 stretchOld(nblock,ndir+nshr),\r\n 4 defgradOld(nblock,ndir+nshr+nshr),\r\n 5 fieldOld(nblock,nfieldv), stressOld(nblock,ndir+nshr),\r\n 6 stateOld(nblock,nstatev), enerInternOld(nblock),\r\n 7 enerInelasOld(nblock), tempNew(nblock),\r\n 8 stretchNew(nblock,ndir+nshr),\r\n 8 defgradNew(nblock,ndir+nshr+nshr),\r\n 9 fieldNew(nblock,nfieldv),\r\n 1 stressNew(nblock,ndir+nshr), stateNew(nblock,nstatev),\r\n 2 enerInternNew(nblock), enerInelasNew(nblock)\r\nc\r\n character*80 cmname\r\n\r\n integer i, k1, k2\r\n\r\n real*8 E, nu, rho, eta, lambda, mu, D1(ndir+nshr,ndir+nshr), \r\n 1 D2(ndir+nshr,ndir+nshr), D3(ndir+nshr,ndir+nshr)\r\n\r\nc material properties\r\n E = props(1) ! Young's modulus\r\n nu = props(2) ! Poisson's ratio\r\n rho = props(3) ! density\r\n eta = props(4) ! visco-elastic coef.\r\n \r\n do 10 i = 1, nblock\r\n\r\nc lame's parameters\r\n lambda = E*nu/((1.0d0+nu)*(1.0d0-2.0d0*nu))\r\n mu = E/(2.0d0*(1.0d0+nu))\r\n\r\nc stiffness matrix with viscous effects\r\n D1 = 0.d0\r\n D2 = 0.d0\r\n D3 = 0.d0\r\n\r\n if (stepTime .gt. 0.d0) then\r\n do k1 = 1, ndir\r\n do k2 = 1, ndir\r\n D1(k1, k2) = lambda*(1.0d0 + 3.0d0*eta/(E*dt))\r\n D2(k1, k2) = lambda\r\n end do \r\n D1(k1, k1) = lambda*(1.0d0 + 3.0d0*eta/(E*dt)) +\r\n 1 2.0d0*mu*(1.0d0 + eta/(mu*dt))\r\n D2(k1, k1) = lambda + 2.0d0*mu\r\n D3(k1, k1) = -1.0d0\r\n end do \r\nc shear stress\r\n do k1 = ndir+1, ndir+nshr\r\n D1(k1, k1) = mu*(1.0d0 + eta/(mu*dt))\r\n D2(k1, k1) = mu\r\n D3(k1, k1) = -1.0d0\r\n end do \r\n else \r\n do k1 = 1, ndir\r\n do k2 = 1, ndir\r\n D1(k1, k2) = lambda\r\n D2(k1, k2) = lambda\r\n end do \r\n D1(k1, k1) = lambda + 2.0d0*mu\r\n D2(k1, k1) = lambda + 2.0d0*mu\r\n D3(k1, k1) = -1.0d0\r\n end do \r\n do k1 = ndir+1, ndir+nshr\r\n D1(k1, k1) = mu\r\n D2(k1, k1) = mu\r\n D3(k1, k1) = -1.0d0\r\n end do \r\n end if \r\n\r\nc updating the state variable (old stress)\r\n stateNew(i, 1:ndir+nshr) = stressOld(i, 1:ndir+nshr)\r\n\r\nc stress increment\r\n do k1 = 1, ndir+nshr\r\n do k2 = 1, ndir+nshr\r\n stateNew(i, k1) = stateNew(i, k1) + \r\n 1 D1(k1, k2) * strainInc(i, k2) +\r\n 2 D2(k1, k2) * stateOld(i,k2+ 12) +\r\n 3 D3(k1, k2) * stressOld(i, k2)\r\n end do \r\n end do\r\n\r\nc updating stress from statevariables\r\n stressNew(i, 1:ndir+nshr) = stateNew(i, 1:ndir+nshr)\r\n\r\nc Total strain stateNew(i,13-18) = total strain\r\n stateNew(i, 13:ndir+nshr) = stateOld(i, 13:ndir+nshr) + \r\n 1 strainInc(i, 1:ndir+nshr)\r\n\r\nc updating the internal energy\r\n enerInternNew(k) = enerInternOld(k) + \r\n 1 dot_product( 0.5d0*(stressOld(k, 1:ndir+nshr) +\r\n 2 stressNew(k, 1:ndir+nshr)), strainInc(k, 1:ndir+nshr)) / rho\r\n \r\n 10 continue\r\n return\r\n end\r\n", "meta": {"hexsha": "dfc5ddd6f85d6d27d8e5067e96b7e616418c125d", "size": 4248, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "vumat_visco_voigt.for", "max_stars_repo_name": "irfancn/Abaqus-VUMAT-viscoelastic", "max_stars_repo_head_hexsha": "4090cc3910220698edffe4b61b3df3ebfbc18c70", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2020-11-03T12:44:53.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-02T03:04:08.000Z", "max_issues_repo_path": "vumat_visco_voigt.for", "max_issues_repo_name": "irfancn/Abaqus-VUMAT-viscoelastic", "max_issues_repo_head_hexsha": "4090cc3910220698edffe4b61b3df3ebfbc18c70", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "vumat_visco_voigt.for", "max_forks_repo_name": "irfancn/Abaqus-VUMAT-viscoelastic", "max_forks_repo_head_hexsha": "4090cc3910220698edffe4b61b3df3ebfbc18c70", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-06-23T11:30:54.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-07T07:51:00.000Z", "avg_line_length": 35.4, "max_line_length": 89, "alphanum_fraction": 0.5230696798, "num_tokens": 1470, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.962673113726775, "lm_q2_score": 0.6757645944891559, "lm_q1q2_score": 0.6505404063231872}} {"text": "\nprogram pi_main\n\n use timer\n use omp_lib\n\n ! Local variables\n integer, parameter :: num_steps = 100000000 ! number of steps over which to estimate pi\n real(kind=8) :: step ! the step size\n integer :: ii ! genereric counter\n real(kind=8) :: x ! intermediate value\n real(kind=8) :: pi = 0.0_8 ! overall estimate\n real(kind=8), allocatable :: sum(:) ! variable to store partial sum\n real(kind=8) :: start, end ! timers\n integer :: nthreads ! number of OpenMP threads\n integer :: tid ! thread id\n\n real(kind=8), parameter :: PI_8 = 4.0_8 * atan(1.0_8)\n\n ! Get number of OpenMP threads\n !$omp parallel\n nthreads = omp_get_num_threads()\n !$omp end parallel\n\n allocate(sum(nthreads))\n\n ! step size is dependent upon the number of steps\n step = 1.0_8/num_steps\n\n ! Start timer\n call wtime(start)\n\n ! main loop\n !$omp parallel private(x,tid)\n tid = omp_get_thread_num()\n sum(tid+1) = 0.0_8\n !$omp do\n do ii = 1, num_steps\n x = (ii-0.5_8)*step\n sum(tid+1) = sum(tid+1) + (4.0_8/(1.0_8+x*x))\n !$omp flush(sum)\n end do\n !$omp end do\n !$omp end parallel\n\n ! Total partial sums serially\n do ii = 1, nthreads\n pi = pi + sum(ii)\n end do\n pi = pi * step\n\n ! Stop timer\n call wtime(end)\n\n ! Print result\n write(*,\"(A)\") \"------------------------------------\"\n write(*,\"(A,F19.16)\") \"pi is: \", pi\n write(*,\"(A,F19.16)\") \"error is: \", abs(pi - PI_8)\n write(*,\"(A,F10.3)\") \"runtime: \", end-start\n write(*,\"(A)\") \"------------------------------------\"\n\n deallocate(sum)\n\nend program pi_main\n", "meta": {"hexsha": "1eabe481d256568210e997dd63f8d6c43058c302", "size": 1722, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "code/pi_array.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/pi_array.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/pi_array.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": 26.4923076923, "max_line_length": 89, "alphanum_fraction": 0.5284552846, "num_tokens": 516, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744939732855, "lm_q2_score": 0.7956581000631542, "lm_q1q2_score": 0.6505097685348791}} {"text": "! 7.2a \u0432 \u0443\u0447\u0435\u0431\u043d\u0438\u043a\u0435\n\nprogram ex_7_2a\n implicit none\n\n integer :: size = 0, negatives = 0, Out = 0, In = 0, i = 0, minpos = 0\n integer, allocatable :: Arr(:)\n logical, allocatable :: mask(:)\n character(*), parameter :: output_file = \"output.txt\", &\n input_file = \"../data/input.txt\"\n\n open (file=input_file, newunit=In)\n read(In, *) size\n allocate(Arr(size))\n read(In, *) Arr(:)\n close (In)\n\n mask = Arr < 0\n\n negatives = count(mask)\n\n Arr = [pack(Arr, mask), pack(Arr, .not. mask)]\n\n do i = 1, negatives\n minpos = minloc(Arr(i:negatives), 1)\n if (minpos /= 1) then\n Arr(i:negatives) = cshift(Arr(i:negatives), minpos - 1)\n endif\n enddo\n\n open (file=output_file, newunit=Out)\n write(Out, *) Arr(:)\n close (Out)\n \nend program ex_7_2a", "meta": {"hexsha": "f7c95c2b12bba341236c06780c5aba725a5f9f16", "size": 886, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "ex_7_2a/src/ex_7_2a.f90", "max_stars_repo_name": "taxnuke/algorithm-exercises", "max_stars_repo_head_hexsha": "5dae749093489d0e66a74bd8bc3b2040496449bf", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-06-01T06:06:44.000Z", "max_stars_repo_stars_event_max_datetime": "2017-06-01T09:16:17.000Z", "max_issues_repo_path": "ex_7_2a/src/ex_7_2a.f90", "max_issues_repo_name": "taxnuke/algorithm-exercises", "max_issues_repo_head_hexsha": "5dae749093489d0e66a74bd8bc3b2040496449bf", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ex_7_2a/src/ex_7_2a.f90", "max_forks_repo_name": "taxnuke/algorithm-exercises", "max_forks_repo_head_hexsha": "5dae749093489d0e66a74bd8bc3b2040496449bf", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.3142857143, "max_line_length": 90, "alphanum_fraction": 0.5270880361, "num_tokens": 275, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744850834648, "lm_q2_score": 0.7956581049086031, "lm_q1q2_score": 0.6505097654231365}} {"text": "! { dg-do run }\n! PR41807 data statement with nested type constructors\n! Test case provided by Steve Kargl\n implicit none\n\n type :: a\n real :: x(3)\n end type a\n\n integer, parameter :: n = 3\n\n type(a) :: b(n)\n\n real, parameter :: d1(3) = (/1., 2., 3./)\n real, parameter :: d2(3) = (/4., 5., 6./)\n real, parameter :: d3(3) = (/7., 8., 9./)\n\n integer :: i, z(n)\n \n data (b(i), i = 1, n) /a(d1), a(d2), a(d3)/\n data (z(i), i = 1, n) / 1, 2, 3/\n\n if (any(z.ne.[1, 2, 3])) call abort\n if (any(b(1)%x.ne.[1, 2, 3]) .or. &\n any(b(2)%x.ne.[4, 5, 6]) .or. &\n any(b(3)%x.ne.[7, 8, 9])) call abort\nend\n\n", "meta": {"hexsha": "5cf49aee74484d5c6609585a28a916e5d3d86f53", "size": 619, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/array_constructor_32.f90", "max_stars_repo_name": "maurizioabba/rose", "max_stars_repo_head_hexsha": "7597292cf14da292bdb9a4ef573001b6c5b9b6c0", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/array_constructor_32.f90", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/array_constructor_32.f90", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 21.3448275862, "max_line_length": 55, "alphanum_fraction": 0.49273021, "num_tokens": 273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7956581000631542, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.6505097508517338}} {"text": "! { dg-do run }\n! { dg-require-effective-target fortran_large_real }\nprogram main\n integer,parameter :: k = selected_real_kind (precision (0.0_8) + 1)\n character(len=90) line\n real(k) :: a(3,3)\n real(k) :: b(9)\n a = 1.0_k\n a(1,3) = 0.0_k\n write (line,'(9G10.6)') transpose(a)\n write (line,'(9G10.6)') reshape(a,shape(b))\nend\n", "meta": {"hexsha": "83da8faeb1cb0bd02eca1f4a83367e5675de9602", "size": 333, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "validation_tests/llvm/f18/gfortran.dg/transpose_reshape_r10.f90", "max_stars_repo_name": "brugger1/testsuite", "max_stars_repo_head_hexsha": "9b504db668cdeaf7c561f15b76c95d05bfdd1517", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 488, "max_stars_repo_stars_event_min_datetime": "2015-01-09T08:54:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:15:46.000Z", "max_issues_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/transpose_reshape_r10.f90", "max_issues_repo_name": "sujankh/rose-matlab", "max_issues_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 174, "max_issues_repo_issues_event_min_datetime": "2015-01-28T18:41:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T16:51:05.000Z", "max_forks_repo_path": "tests/CompileTests/Fortran_tests/gfortranTestSuite/gfortran.dg/transpose_reshape_r10.f90", "max_forks_repo_name": "sujankh/rose-matlab", "max_forks_repo_head_hexsha": "7435d4fa1941826c784ba97296c0ec55fa7d7c7e", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 146, "max_forks_repo_forks_event_min_datetime": "2015-04-27T02:48:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T07:32:53.000Z", "avg_line_length": 25.6153846154, "max_line_length": 69, "alphanum_fraction": 0.6276276276, "num_tokens": 132, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8175744584140004, "lm_q2_score": 0.7956581000631542, "lm_q1q2_score": 0.6505097402418458}} {"text": " program trnkey\r\n\r\nc TRNKEY -- program to make a numerical version of a transpostion\r\nc key for use (most likely) in a (cryptographic) transposition\r\nc cipher. The input is a character string.\r\nc\r\nc The way this works is as follows:\r\nc The user inputs a character string containing any ASCII\r\nc characters. The characters are mapped to upper-case and\r\nc any non-alphabetic characters are eliminated.\r\nc The letters in the resulting string are then numbered\r\nc alphabetically, with duplicate letters being numbered from\r\nc left to right.\r\nc For instance:\r\nc JOANN yields the numerical sequence 2-5-1-3-4.\r\nc For classical cryptographic applications, 2-5-1-3-4 would be\r\nc the resultant numerical version of the key.\r\nc For computer applications, an \"inverted\" form of the key, with\r\nc the ordinal number of \"1\" first, the ordinal number of \"2\"\r\nc second, etc., might be more useful.\r\nc\r\nc Written by Mark Riordan 27 September 1986\r\n\r\n integer nkeymx\r\n parameter(nkeymx=160)\r\n integer nkey,j,inew,iold,tint\r\n logical debug,qchng\r\n character key(nkeymx)*1,tchar\r\n integer numkey(nkeymx)\r\n\r\n debug = .false.\r\ncc\twrite(*,9000)\r\ncc9000\tformat(' Please input the key string:')\r\n read(*,8000,end=666) (key(j),j=1,nkeymx)\r\n8000 format(160a)\r\n\r\n inew = 0\r\n do 120 iold = 1, nkeymx\r\n\tif(key(iold).ge.'a' .and. key(iold).le.'z') then\r\n\t key(iold) = char(ichar(key(iold))-32)\r\n\tendif\r\n\tif(key(iold).ge.'A' .and. key(iold).le.'Z') then\r\n\t inew = inew + 1\r\n\t key(inew) = key(iold)\r\n\tendif\r\n120 continue\r\n nkey = inew\r\n if(nkey .le. 0) then\r\n\twrite(*,*) 'No legal key characters were input.'\r\n\tgo to 999\r\n endif\r\n\r\n if(debug) then\r\n\twrite(*,9200) (key(j),j=1,inew)\r\n9200\tformat(' ',160a)\r\n endif\r\n\r\nc Create an array of ordinal positions. The sorted version of\r\nc this array will be the numerical version of the key.\r\nc Initially, for this algorithm, we start out with 1-2-3-...\r\nc in this array.\r\n\r\n do 140 j = 1, nkey\r\n\tnumkey(j) = j\r\n140 continue\r\n\r\nc Sort the key characters, and drag their ordinal numbers along\r\nc to keep track of things.\r\n\r\n160 continue\r\n qchng = .false.\r\n\tdo 200 j = 1, nkey-1\r\n\t if(key(j) .gt. key(j+1)) then\r\n\t tchar = key(j)\r\n\t key(j) = key(j+1)\r\n\t key(j+1) = tchar\r\n\t tint = numkey(j)\r\n\t numkey(j) = numkey(j+1)\r\n\t numkey(j+1) = tint\r\n\t qchng = .true.\r\n\t endif\r\n200\tcontinue\r\n if(qchng) go to 160\r\n\r\nc The key is now sorted.\r\n\r\n if(debug) then\r\n\twrite(*,9220) (numkey(j), j=1,nkey)\r\n9220\tformat(' Row #''s in ordinal order:',40i4)\r\n endif\r\n\r\ncc\topen(12,file='tordkey.txt')\r\ncc\trewind 12\r\n write(*,9030) (numkey(j),j=1,nkey)\r\n9030 format(40i4)\r\n\r\n goto 999\r\n666 continue\r\n\twrite(*,*) 'Premature end-of-file encountered.'\r\n\tgo to 999\r\n\r\n999 continue\r\n end\r\n end\r\n\u001a", "meta": {"hexsha": "4651cd721f7e18f5d755169225f1d8beb8e333fa", "size": 2922, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "Encryption/MRRCIP/mktrnkey.for", "max_stars_repo_name": "dendisuhubdy/grokmachine", "max_stars_repo_head_hexsha": "120a21a25c2730ed356739231ec8b99fc0575c8b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 46, "max_stars_repo_stars_event_min_datetime": "2017-05-15T11:15:08.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-02T03:32:52.000Z", "max_issues_repo_path": "Encryption/MRRCIP/mktrnkey.for", "max_issues_repo_name": "dendisuhubdy/grokmachine", "max_issues_repo_head_hexsha": "120a21a25c2730ed356739231ec8b99fc0575c8b", "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": "Encryption/MRRCIP/mktrnkey.for", "max_forks_repo_name": "dendisuhubdy/grokmachine", "max_forks_repo_head_hexsha": "120a21a25c2730ed356739231ec8b99fc0575c8b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 24, "max_forks_repo_forks_event_min_datetime": "2017-05-17T03:26:17.000Z", "max_forks_repo_forks_event_max_datetime": "2018-07-09T07:00:50.000Z", "avg_line_length": 27.8285714286, "max_line_length": 69, "alphanum_fraction": 0.6249144422, "num_tokens": 893, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430562234878, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.6505044889618191}} {"text": "program test_henon\n ! This program just tries the code written for the assigment.\n use henondim\n use lsq\n use precision\n implicit none\n real(DP) :: d\n integer :: j,Neps\n real(DP), dimension(:), allocatable :: eps, N\n \n Neps=10\n allocate(N(Neps),eps(Neps))\n eps = (/(2d0**j, j=-21,-12) /)\n\n call basin_alg(Neps,eps,d)\n print *, \" \"\n print *, \"d =\",d\n \nend program test_henon\n", "meta": {"hexsha": "548683354a940adf5f75be0dfda8c521e524a6d9", "size": 391, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "HighPerformanceComputing/Homework5/test_henon.f90", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "HighPerformanceComputing/Homework5/test_henon.f90", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "HighPerformanceComputing/Homework5/test_henon.f90", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.55, "max_line_length": 63, "alphanum_fraction": 0.631713555, "num_tokens": 136, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430394931456, "lm_q2_score": 0.7826624840223698, "lm_q1q2_score": 0.650504475867608}} {"text": "! Program to test elemental functions.\nprogram test_elemental\n implicit none\n integer, dimension (2, 4) :: a\n integer, dimension (2, 4) :: b\n integer(kind = 8), dimension(2) :: c\n\n a = reshape ((/2, 3, 4, 5, 6, 7, 8, 9/), (/2, 4/))\n b = 0\n b(2, :) = e_fn (a(1, :), 1)\n if (any (b .ne. reshape ((/0, 1, 0, 3, 0, 5, 0, 7/), (/2, 4/)))) call abort\n a = e_fn (a(:, 4:1:-1), 1 + b)\n if (any (a .ne. reshape ((/7, 7, 5, 3, 3, -1, 1, -5/), (/2, 4/)))) call abort\n ! This tests intrinsic elemental conversion functions.\n c = 2 * a(1, 1)\n if (any (c .ne. 14)) call abort\n\n ! This triggered bug due to building ss chains in the wrong order.\n b = 0;\n a = a - e_fn (a, b)\n if (any (a .ne. 0)) call abort\n\n ! Check expressions involving constants\n a = e_fn (b + 1, 1)\n if (any (a .ne. 0)) call abort\ncontains\n\nelemental integer(kind=4) function e_fn (p, q)\n integer, intent(in) :: p, q\n e_fn = p - q\nend function\nend program\n", "meta": {"hexsha": "79a511cdee820989776d13bf19c59a456bb1d2ce", "size": 956, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.fortran-torture/execute/elemental.f90", "max_stars_repo_name": "best08618/asylo", "max_stars_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2020-05-02T17:34:05.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-17T10:15:18.000Z", "max_issues_repo_path": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.fortran-torture/execute/elemental.f90", "max_issues_repo_name": "best08618/asylo", "max_issues_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "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": "gcc-gcc-7_3_0-release/gcc/testsuite/gfortran.fortran-torture/execute/elemental.f90", "max_forks_repo_name": "best08618/asylo", "max_forks_repo_head_hexsha": "5a520a9f5c461ede0f32acc284017b737a43898c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-07-27T00:22:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-01T09:41:02.000Z", "avg_line_length": 28.9696969697, "max_line_length": 80, "alphanum_fraction": 0.5543933054, "num_tokens": 393, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430394931456, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.6505044716541846}} {"text": "!! This module makes a bimodal distribution using two maxwellians \r\n!! one maxwellian on the left and another on the right and some sort of linear? switching in between... \r\n!! IN 3D in velocity space and 1D in physical space...\r\n\r\n!DIMENSIONLESS SEE NOTES FOR THE REDUCTION FORMULAS\r\nmodule DGV_distributions_mod\r\nuse nrtype ! contains kind parameters (DP), (DP), (I4B) etc. \r\n\r\nimplicit none\r\n interface maxwelveldist\r\n module procedure maxwelveldist, maxwelveldist_T_vector, maxwelveldist_u_vectors, &\r\n maxwelveldist_T_vector_u_vectors\r\n end interface\r\n\r\n interface ESBGK\r\n module procedure ESBGK_f0\r\n end interface\r\n \r\n!!!!!!!!!!!!! parameters and global variables \r\nreal (DP), parameter, private :: pi25DT = 3.141592653589793238462643d0\r\n!!!!!!!!!!\r\n\r\n\r\ncontains\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! maxwelveldist (T,u_0,n,u) result (y)\r\n! \r\n! This function evauates the 3D velocity dimensionless maxwellian equilibrium distribution with given temperature and average velocity\r\n! Temperature and average velocity can be arrays (corresponding to different points in x variable\r\n!\r\n! This function evaluates \r\n! f_{M}(t,x,u)=(\\pi T(t,x))^{-1/2} \\exp(-\\frac{(u-\\bar{u})^2}{2RT}) \r\n!\r\n! This is a reloadable function\r\n!!!!!!!!!!!!!!!!!!!!!!!\r\n!\r\n! this is the copy when T is vector and u is scalar\r\nfunction maxwelveldist_T_vector_u_vectors (T,u_0,v_0,w_0,n,u,v,w) result (y)\r\n real (DP), dimension (:), intent (in) :: T ! temperature parameter (may depend on x)\r\n real (DP), dimension (:), intent (in) :: n ! density parameter (may depend on x)\r\n real (DP), dimension (:), intent (in) :: u_0,v_0,w_0 ! average velocity (may depend on x)\r\n !!! T,n,u_0 must be the same size !!! \r\n real (DP), dimension (:), intent (in) :: u,v,w ! value of the velocity variable\r\n real (DP), dimension (size(T),size(u)) :: y ! value of the dencity for this values of u and T\r\n!!!\r\n real (DP), dimension (size(T)) :: beta ! local variable to keep temporary results\r\n integer (I4B) :: i ! local counter\r\n!!! \r\nbeta=sqrt(pi25DT*T)*(pi25DT*T)\r\ndo i=1,size(u)\r\n y(:,i) = n*exp(-((u(i)-u_0)*(u(i)-u_0)+(v(i)-v_0)*(v(i)-v_0)+&\r\n (w(i)-w_0)*(w(i)-w_0))/max(T,0.0000001_DP))/beta\r\nend do \r\nend function maxwelveldist_T_vector_u_vectors\r\n\r\n! this is the copy when T is vector and u is scalar\r\nfunction maxwelveldist_T_vector (T,u_0,v_0,w_0,n,u,v,w) result (y)\r\n real (DP), dimension (:), intent (in) :: T ! temperature parameter (may depend on x)\r\n real (DP), dimension (:), intent (in) :: n ! density parameter (may depend on x)\r\n real (DP), dimension (:), intent (in) :: u_0, v_0,w_0 ! average velocity (may depend on x)\r\n !!! T,n,u_0 must be the same size !!! \r\n real (DP), intent (in) :: u,v,w ! value of the velocity variable \r\n real (DP), dimension (size(T)) :: y ! value of the dencity for this values of u and T \r\n!!!\r\n real (DP), dimension (size(T)) :: beta ! local variable to keep temporary results \r\nbeta=sqrt(pi25DT*T)*(pi25DT*T)\r\ny = n*exp(-((u-u_0)*(u-u_0)+(v-v_0)*(v-v_0)+&\r\n (w-w_0)*(w-w_0))/max(T,0.0000001_DP))/beta\r\nend function maxwelveldist_T_vector\r\n\r\n! this is the copy when T is scalar and u is vector\r\nfunction maxwelveldist_u_vectors (T,u_0,v_0,w_0,n,u,v,w) result (y)\r\n real (DP), intent (in) :: T ! temperature parameter (scalar)\r\n real (DP), intent (in) :: u_0,v_0,w_0 ! average velocity (scalar)\r\n real (DP), intent (in) :: n ! density parameter (scalar)\r\n real (DP), dimension (:), intent (in) :: u,v,w ! values of the velocity variable \r\n real (DP), dimension (size(u)) :: y ! value of the dencity for this values of u and T \r\n!!!\r\n real (DP) :: beta ! local variable to keep temporary results \r\nbeta=sqrt(pi25DT*T)*(pi25DT*T)\r\ny = n*exp(-((u-u_0)*(u-u_0)+(v-v_0)*(v-v_0)+&\r\n (w-w_0)*(w-w_0))/max(T,0.0000001_DP))/beta\r\nend function maxwelveldist_u_vectors\r\n\r\n! this is the copy when both T and u are scalars\r\nfunction maxwelveldist (T,u_0,v_0,w_0,n,u,v,w) result (y)\r\n real (DP), intent (in) :: T ! temperature parameter (may depend on x)\r\n real (DP), intent (in) :: u_0,v_0,w_0 ! average velocity (scalar)\r\n real (DP), intent (in) :: n ! density parameter (scalar)\r\n real (DP), intent (in) :: u,v,w ! value of the velocity variable \r\n real (DP) :: y ! value of the dencity for this values of u and T \r\n!!!\r\n real (DP) :: beta ! local variable to keep temporary results \r\nbeta=sqrt(pi25DT*T)*(pi25DT*T)\r\ny = n*exp(-((u-u_0)*(u-u_0)+(v-v_0)*(v-v_0)+&\r\n (w-w_0)*(w-w_0))/max(T,0.0000001_DP))/beta\r\nend function maxwelveldist \r\n\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! ESBGK_f0\r\n! \r\n! This function evauates the 3D ES-BGK equilibrium distribution with given temperature and average velocity.\r\n! Note that the parameters are dependent on time and velocity but not in the spacial variable x\r\n!\r\n! This function evaluates \r\n! f_0(t,u)=\\frac{n(t)}{\\sqrt{(\\pi^3 det(\\mathbb{T})}} \\exp(-c'\\mathbb{T}c) \r\n!\r\n!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\nfunction ESBGK_f0 (TensorInv,Determinant,n,u_0,v_0,w_0,nodes_u,nodes_v,nodes_w) result (f0)\r\n! Evaluate f0 for ESBGK\r\nreal (DP), dimension(3,3), intent (in) :: TensorInv ! The inverse of the tensor matrix\r\nreal (DP), intent (in) :: u_0, v_0, w_0 ! These are the bulk velocities\r\nreal (DP), intent (in) :: Determinant ! This is the Determinant of the Tensor matrix\r\nreal (DP), intent (in) :: n ! this is the number density\r\nreal (DP), dimension(:), intent (in) :: nodes_u,nodes_v,nodes_w ! These are the velocity nodes\r\ninteger (I4B) :: Unodes ! the number of nodes in velocity space\r\nreal (DP), dimension(3) :: Left, c ! c-v vector\r\nreal (DP), parameter :: PI25DT = 3.141592653589793238462643d0\r\ninteger :: loc_alloc_stat\r\nreal (DP), dimension (:), allocatable :: Prod ! This is the component that goes into the argument of the exponent\r\nreal (DP), dimension (1:size(nodes_u,1)) :: f0 ! result -- the ES-BGK distribution function\r\n!real (DP), dimension(1:size(nodes_u,1)) :: nodes_cu, nodes_cv, nodes_cw\r\ninteger (I4B) :: i,j,k ! these are local counters\r\n\r\nUnodes = size(nodes_U) ! Get the number of elements of each of the nodes\r\n\r\nallocate (Prod(1:size(nodes_u,1)), stat=loc_alloc_stat)\r\nif (loc_alloc_stat >0) then \r\n print *, \"ESBGK_f0: Allocation error for variables (Prod)\"\r\n stop\r\nend if\r\n\r\n! from here, the component in the exponent's argument is computed\r\n\r\ndo i=1,Unodes\r\n ! c = \\vec{u} - \\vec{bar{u}}\r\n c(1) = nodes_u(i) - u_0\r\n c(2) = nodes_v(i) - v_0\r\n c(3) = nodes_w(i) - w_0\r\n\r\n ! used as part of the left operation (i.e. c'*TensorInv)\r\n Left(1) = c(1)*TensorInv(1,1) + c(2)*TensorInv(2,1) + c(3)*TensorInv(3,1)\r\n Left(2) = c(1)*TensorInv(1,2) + c(2)*TensorInv(2,2) + c(3)*TensorInv(3,2)\r\n Left(3) = c(1)*TensorInv(1,3) + c(2)*TensorInv(2,3) + c(3)*TensorInv(3,3)\r\n\r\n Prod(i) = Left(1)*c(1) + Left(2)*c(2) + Left(3)*c(3)! final computation of c'*TensorInv*c\r\nend do\r\n\r\nf0 = n/sqrt((PI25DT)**3*Determinant) * exp(-Prod)\r\n\r\ndeallocate (Prod)\r\n\r\nend function ESBGK_f0\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n! Shakhov_f0\r\n! \r\n! This function evauates the dimensionless 3D Shakhov equilibrium distribution function \r\n! with given temperature and average velocity and the \r\n! give Prandtl number. \r\n!\r\n!Note that the parameters are dependent on time and velocity but not in the spacial variable x\r\n!\r\n! This function evaluates \r\n! f_0(t,u)=f_{M}(t,u)(1+(4/5)(1-Pr)S_{a}c^{a}(c_{a}c^{a}-5/2)) where c_a=(u_a-\\bar{u}_a)/\\sqrt{T}\r\n! S_a=q_{a}/(nT^{3/2}), q_{a} = \\int f (u_{a}-\\bar(u)_{a})|u-\\bar{u}|^2 du\r\n!\r\n!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\nfunction Shakhov_f0 (alpha,n,u_0,v_0,w_0,T,S_u,S_v,S_w,nodes_u,nodes_v,nodes_w) result (f0)\r\n! Evaluate f0 for Shakhov model\r\nreal (DP), intent (in) :: alpha ! the Prandtl number \r\nreal (DP), intent (in) :: T ! This is the temperature of the local maxwellian \r\nreal (DP), intent (in) :: n ! this is the number density \r\nreal (DP), intent (in) :: u_0, v_0, w_0 ! These are the bulk velocities of the local maxwellian\r\nreal (DP), dimension(:), intent (in) :: S_u,S_v,S_w ! These are the components of the vector S in the shakov model\r\n\r\nreal (DP), dimension(:), intent (in) :: nodes_u,nodes_v,nodes_w ! These are the velocity nodes\r\nreal (DP), dimension (1:size(nodes_u,1)) :: f0 ! the Shakhov distribution function -- the result\r\n!\r\n!\r\nreal (DP), parameter :: PI25DT = 3.141592653589793238462643d0\r\nreal (DP), dimension (:), allocatable :: ShCorr,c_u, c_v, c_w! This are useful arrays, \r\ninteger (I4B) :: i,j,k,loc_alloc_stat ! these are local counters\r\n\r\n\r\nallocate (ShCorr(1:size(nodes_u,1)),c_u(1:size(nodes_u,1)),c_v(1:size(nodes_u,1)),&\r\n c_w(1:size(nodes_u,1)), stat=loc_alloc_stat)\r\nif (loc_alloc_stat >0) then \r\n print *, \"Shakhov_f0: Allocation error for variables (ShCorr,c_u,c_v,c_w)\"\r\n stop\r\nend if\r\n\r\n! first, we compute the components of vector c:\r\nc_u = (nodes_u-u_0)/sqrt(T)\r\nc_v = (nodes_v-v_0)/sqrt(T)\r\nc_w = (nodes_w-w_0)/sqrt(T)\r\n! Next we compute the Shakhov correction term\r\nShCorr = (S_u*c_u+S_v*c_v+S_w*c_w)*((c_u*c_u+c_v*c_v+c_w*c_w)-5.0_DP/2.0_DP)\r\nShCorr = (1+4.0_DP/5.0_DP*((-1)*alpha)/(1-alpha)*ShCorr)\r\n!!!!!!!!\r\nf0 = maxwelveldist(T,u_0,v_0,w_0,n,nodes_u,nodes_v,nodes_w)*ShCorr\r\n\r\ndeallocate (ShCorr,c_u,c_v,c_w)\r\n\r\nend function Shakhov_f0\r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n!EvalGrad13f0\r\n!\r\n!Evaluates the 13 moment grad function\r\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\nfunction EvalGrad13f0(n,p,sigma,q,u_0,v_0,w_0,nodes_u,nodes_v,nodes_w) result(f0)\r\n\r\nreal (DP), intent (in) :: p ! Pressure, scalar\r\nreal (DP), intent (in) :: n ! density parameter (scalar)\r\nreal (DP), intent (in) :: u_0,v_0,w_0 ! average velocity (may depend on x)\r\nreal (DP), dimension(:), intent (in) :: nodes_u,nodes_v,nodes_w ! These are the velocity nodes\r\n!!! T,u_0 must be the same size !!! \r\nreal (DP), dimension(3,3), intent(in) :: sigma !The traceless stress tensor\r\nreal (DP), dimension(3), intent(in) :: q !The heatflux \r\n\r\nreal (DP), dimension (1:size(nodes_u,1)) :: f0 ! result -- the 13 moment grad function\r\n\r\nreal (DP), dimension(3) :: Left, c ! c-v vector\r\nreal (DP) :: T !Temperature, derived from the density and the pressure\r\nreal (DP) :: trace_c !A varaible to store the trace of the velocity\r\ninteger (I4B) :: Unodes ! the number of nodes in velocity space\r\ninteger (I4B) :: i,j,k ! these are local counters\r\n\r\nUnodes = size(nodes_u)\r\nT=2*p/n\r\n\r\ndo i=1,Unodes\r\n c(1) = nodes_u(i) - u_0\r\n c(2) = nodes_v(i) - v_0\r\n c(3) = nodes_w(i) - w_0\r\n \r\n trace_c=sum(c*c)\r\n \r\n\r\n f0(i)=(sigma(1,1)*(c(1)*c(1) - trace_c/3.0_DP) + 2*sigma(1,2)*c(1)*c(2) + 2*sigma(1,3)*c(1)*c(3) + &\r\n sigma(2,2)*(c(2)*c(2) - trace_c/3.0_DP) + 2*sigma(2,3)*c(2)*c(3) + sigma(3,3)*(c(3)*c(3) - trace_c/3.0_DP))/(p*T)\r\n \r\n f0(i)=f0(i)+ 4.0_DP/(5.0_DP*p*T)*(trace_c / T - 5.0_DP/2.0_DP)*(q(1)*c(1)+q(2)*c(2)+q(3)*c(3))\r\n \r\n f0(i)=f0(i)+1\r\n \r\n f0(i)=maxwelveldist(T,u_0,v_0,w_0,n,nodes_u(i),nodes_v(i),nodes_w(i))*f0(i)\r\n \r\nend do\r\n\r\nend function EvalGrad13f0\r\n\r\n\r\n\r\nend module DGV_distributions_mod", "meta": {"hexsha": "b6b36bbb7973ff626746e062b82866d1e4af06dc", "size": 11319, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "DGV_distributions_mod.f90", "max_stars_repo_name": "alexmalekseenko/DGVlib", "max_stars_repo_head_hexsha": "9d6f09f27f8591e457f71384c82d2384ad4dfba4", "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": "DGV_distributions_mod.f90", "max_issues_repo_name": "alexmalekseenko/DGVlib", "max_issues_repo_head_hexsha": "9d6f09f27f8591e457f71384c82d2384ad4dfba4", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-04-13T05:30:11.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-13T05:30:11.000Z", "max_forks_repo_path": "DGV_distributions_mod.f90", "max_forks_repo_name": "alexmalekseenko/DGVlib", "max_forks_repo_head_hexsha": "9d6f09f27f8591e457f71384c82d2384ad4dfba4", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.367816092, "max_line_length": 135, "alphanum_fraction": 0.6209912536, "num_tokens": 3725, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278633625322, "lm_q2_score": 0.7371581741774411, "lm_q1q2_score": 0.6504889125996247}} {"text": "subroutine dens_unes(temp, salt, rhouns, rhods, rhodt)\n!----- GPL ---------------------------------------------------------------------\n! \n! Copyright (C) Stichting Deltares, 2011-2016. \n! \n! This program is free software: you can redistribute it and/or modify \n! it under the terms of the GNU General Public License as published by \n! the Free Software Foundation version 3. \n! \n! This program is distributed in the hope that it will be useful, \n! but WITHOUT ANY WARRANTY; without even the implied warranty of \n! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \n! GNU General Public License for more details. \n! \n! You should have received a copy of the GNU General Public License \n! along with this program. If not, see . \n! \n! contact: delft3d.support@deltares.nl \n! Stichting Deltares \n! P.O. Box 177 \n! 2600 MH Delft, The Netherlands \n! \n! All indications and logos of, and references to, \"Delft3D\" and \"Deltares\" \n! are registered trademarks of Stichting Deltares, and remain the property of \n! Stichting Deltares. All rights reserved. \n! \n!-------------------------------------------------------------------------------\n! $Id: dens_unes.f90 5717 2016-01-12 11:35:24Z mourits $\n! $HeadURL: https://svn.oss.deltares.nl/repos/delft3d/tags/6686/src/engines_gpl/flow2d3d/packages/kernel/src/compute/dens_unes.f90 $\n!!--description-----------------------------------------------------------------\n!\n! Function: Computes water density from temperature and\n! salinity using equation of state (rhowat).\n! \n! Method used: Equation of state following UNESCO, (UNESCO,\n! Algorithms for computation of fundamental \n! properties of seawater, UNESCO technical papers\n! in marine science, 1983)\n!\n!!--pseudo code and references--------------------------------------------------\n! NONE\n!!--declarations----------------------------------------------------------------\n!\n use precision\n implicit none\n!\n! Global variables\n!\n real(fp), intent(in) :: salt\n real(fp), intent(in) :: temp\n real(fp), intent(out) :: rhouns\n real(fp), intent(out) :: rhods\n real(fp), intent(out) :: rhodt\n!\n! Local variables\n!\n real(fp) :: s\n real(fp) :: sq\n real(fp) :: rhwa\n real(fp) :: asal\n real(fp) :: bsal\n real(fp), dimension(5) :: t\n real(fp), dimension(0:5), parameter :: cf = &\n (/ 999.842594_fp ,&\n 6.793952e-2_fp ,&\n -9.095290e-3_fp ,&\n 1.001685e-4_fp ,&\n -1.120083e-6_fp ,&\n 6.536332e-9_fp /)\n real(fp), dimension(0:4), parameter :: ca = &\n (/ 8.24493e-1_fp ,&\n -4.0899e-3_fp ,&\n 7.6438e-5_fp ,&\n -8.2467e-7_fp ,&\n 5.3875e-9_fp /)\n real(fp), dimension(0:2), parameter :: cb = &\n (/ -5.72466e-3_fp ,&\n 1.0227e-4_fp ,&\n -1.6546e-6_fp /)\n real(fp) , parameter :: csal = 4.8314e-4_fp\n!\n!! executable statements -------------------------------------------------------\n!\n t(1) = temp\n t(2) = temp*t(1)\n t(3) = temp*t(2)\n t(4) = temp*t(3)\n t(5) = temp*t(4)\n !\n s = salt\n sq = sqrt(max(0.0_fp,s))\n !\n rhwa = cf(0) + cf(1)*t(1) + cf(2)*t(2) + cf(3)*t(3) + cf(4)*t(4) &\n & + cf(5)*t(5)\n asal = ca(0) + ca(1)*t(1) + ca(2)*t(2) + ca(3)*t(3) + ca(4)*t(4)\n bsal = cb(0) + cb(1)*t(1) + cb(2)*t(2)\n !\n rhouns = rhwa + (asal+bsal*sq+csal*s) * s\n !\n rhods = asal + 1.5_fp*bsal*sq + 2.0_fp*csal*s\n !\n rhodt = cf(1) + 2.0_fp*cf(2)*t(1) + 3.0_fp*cf(3)*t(2) &\n & + 4.0_fp*cf(4)*t(3) + 5.0_fp*cf(5)*t(4) &\n & + (ca(1) + 2.0_fp*ca(2)*t(1) + 3.0_fp*ca(3)*t(2) &\n & + 4.0_fp*ca(4)*t(3)) * s &\n & + (cb(1) + 2.0_fp*cb(2)*t(1)) * sq * s \nend subroutine dens_unes\n", "meta": {"hexsha": "9a7c48eaa6ce271d4ada61967096f640bbae77e7", "size": 5022, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "docker/water/delft3d/tags/v6686/src/engines_gpl/flow2d3d/packages/kernel/src/compute/dens_unes.f90", "max_stars_repo_name": "liujiamingustc/phd", "max_stars_repo_head_hexsha": "4f815a738abad43531d02ac66f5bd0d9a1def52a", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-01-06T03:01:18.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T03:02:55.000Z", "max_issues_repo_path": "docker/water/delft3d/tags/v6686/src/engines_gpl/flow2d3d/packages/kernel/src/compute/dens_unes.f90", "max_issues_repo_name": "liujiamingustc/phd", "max_issues_repo_head_hexsha": "4f815a738abad43531d02ac66f5bd0d9a1def52a", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docker/water/delft3d/tags/v6686/src/engines_gpl/flow2d3d/packages/kernel/src/compute/dens_unes.f90", "max_forks_repo_name": "liujiamingustc/phd", "max_forks_repo_head_hexsha": "4f815a738abad43531d02ac66f5bd0d9a1def52a", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.5, "max_line_length": 133, "alphanum_fraction": 0.3950617284, "num_tokens": 1315, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544912, "lm_q2_score": 0.7371581684030623, "lm_q1q2_score": 0.6504889097834148}} {"text": "module feril\n!****************************************************************************\n! feril = fortran electron repulsion integral (ERI) library\n!\n! The main function to be used is coulomb_rep4, a 4-center ERI calculator\n! for Gaussian type orbitals (GTOs). Also includes a 2-center ERI, \n! coulomb_rep2, which is a wrapper for coulomb_rep4. \n! This work is based off of the pyquante2 code.\n! https://github.com/rpmuller/pyquante2/blob/master/pyquante2/ints/two.py\n! which is a python implementation of:\n! 'Gaussian Expansion Methods for Molecular Orbitals' H. Taketa,\n! S. Huzinaga & K. O-ohata. H. Pys. Soc. Japan, 21, 2313, 1966.\n! Special functions are based off of \n! -Gamma & Incomplete Gamma Functions:\n! 'Computation of Special Functions' by S. Zhang & J. Jin\n! -Boys Function:\n! 'Molecular Electronic-Structure Theory' by T. Helgaker, P. Jorgensen\n! & J. Olsen\n!\n! Author: Date: Version:\n! Aaron Mahler 04Nov2018 0.0\n!****************************************************************************\n\n! @TODO: add timing to see what takes the longest\n\n use kinds, only : dp\n use constants, only: pi\n implicit none\n\n ! Hard coded limit so b_arrays can be on the stack.\n ! INT(KIND=8) limit is @ vmax_am_tot=29, because fact_ratio2 is maxed \n ! @ (28,14). It also disagrees with pyquante2 when vmax_am_tot = 25 by \n ! ~0.2% for maxed out input angular momentum.\n integer, parameter :: vmax_am_tot = 21 ! 4*5 + 1 (4 h-type orbitals)\n real(dp), dimension(vmax_am_tot) :: bax, bay, baz\n real(dp), dimension(0:vmax_am_tot) :: fbar ! array of fboys evaluations\n real(dp) :: ericoef = 2.0_dp * (pi**2.5_dp)\n real(dp), parameter :: taytol = 0.01_dp ! tolerance to eval fboys with Taylor series\n real(dp), parameter :: anatol = 150.0_dp ! tol to analytical eval fboys for big arg\n\n contains\nfunction fboys(nin, xin) result(ret)\n!****************************************************************************\n! fboys evaluates the Boys function(n,x) := \\int_0^1 exp(-xt^2)t^(2n) dt\n!\n! for small x<0.01, Taylor series at x=0\n! for large x>150, analytic form of \\int_0^\\infty exp(-xt^2)t^(2n) dt\n! for intermediate range use F_n(x) = \\gamma(n+1/2,x) / ( 2x^(n+1/2) ),\n! where \\gamma is the lower incomplete gamma function \n!\n! Parameters:\n! Input, real(dp) :: nin, xin ! both inputs should be >= 0\n! Output, real(dp) :: ret ! Boys func, range is 1/(2n+1) >= F_n(x) > 0\n!****************************************************************************\n use kinds, only : dp\n use constants, only : pi\n implicit none\n ! Params\n real(dp), intent(in) :: nin, xin\n ! Locals\n real(dp) :: r1\n integer :: ii\n ! Return\n real(dp) :: ret\n\n ! input error checking, change nin to int type?\n if ( (xin .lt. 0.0_dp) .or. (nin .lt. 0.0_dp) ) then\n write(6,'(\"ERR in fboys, negative input not allowed\")')\n ret = -1.0_dp\n return\n end if\n\n if ( xin .lt. taytol ) then\n ! Use truncated series expansion at x=0 for small x\n ! F_n(x) = \\sum_{k=0}^{\\infty} (-x)^k / ( k! (2n+2k+1) )\n\n ret = 1.0_dp / ( 2.0_dp*nin + 1.0_dp )\n !r1 = 1.0_dp\n !do ii = 1, 5 ! loop method for testing different truncation lengths\n ! r1 = real(ii, dp)*r1\n ! ret = ret + (-xin)**ii / (r1 * (2.0_dp*nin + 2.0_dp*ii + 1.0_dp))\n !end do\n ! manually unroll loop\n ! truncation at k=5 tested against Mathematica up to n=50 for x=0.01\n ret = ret - xin / (2.0_dp*nin + 3.0_dp)\n ret = ret + xin**2 / (4.0_dp*nin + 10.0_dp)\n ret = ret - xin**3 / (12.0_dp*nin + 42.0_dp)\n ret = ret + xin**4 / (48.0_dp*nin + 216.0_dp)\n ret = ret - xin**5 / (240.0_dp*nin + 1320.0_dp)\n !write(6,*) 'fboys taylor'\n return\n\n else if ( xin .gt. anatol ) then\n ! F_n(x) \\approx (2n-1)!! / 2^(n+1) * Sqrt( \\pi / x^(2n+1) ); for large x\n ! tested against Mathematica up to n=50 for x=150\n r1 = 1.0_dp\n if ( nin .ge. 2.0_dp ) then ! double factorial\n do ii = 2*int(nin)-1, 1, -2\n r1 = r1 * real(ii, dp)\n end do\n end if\n ret = r1 * 2.0_dp**(-nin-1) * sqrt( pi * xin**(-2*nin-1) )\n ! write(6,*) 'fboys large'\n return\n\n end if\n\n ! else use incomplete gamma func\n r1 = nin + 0.5_dp\n ret = incgaml(r1, xin) / ( 2.0_dp * xin**r1 )\n ! write(6,*) 'fboys incgaml'\n\n return\nend function fboys\n\n\nfunction gam_zj(xin) result(ga)\n!****************************************************************************\n! gam_zj evaluates the Gamma Function(n) := \n! \\int_0^{\\infty} exp(-t) t^{n-1) dt\n!\n! Reference:\n! Shanjie Zhang, Jianming Jin,\n! Computation of Special Functions,\n! Wiley, 1996, ISBN: 0-471-11963-6, LC: QA351.C45\n! https://people.sc.fsu.edu/~jburkardt/f_src/special_functions/special_functions.f90\n!\n! Parameters:\n! Input, real (dp) Xin, the argument.\n! Xin must not be 0, or any negative integer.\n! Output, real (dp) GA, the value of the Gamma function.\n!****************************************************************************\n use kinds, only : dp\n use constants, only : pi\n\n implicit none\n ! Params\n real(dp), intent(in) :: xin\n ! Locals\n real(dp), dimension (26) :: gra = (/ &\n 1.0E+00_dp, &\n 0.5772156649015329E+00_dp, &\n -0.6558780715202538E+00_dp, &\n -0.420026350340952E-01_dp, &\n 0.1665386113822915E+00_dp, &\n -0.421977345555443E-01_dp, &\n -0.96219715278770E-02_dp, &\n 0.72189432466630E-02_dp, &\n -0.11651675918591E-02_dp, &\n -0.2152416741149E-03_dp, &\n 0.1280502823882E-03_dp, & \n -0.201348547807E-04_dp, &\n -0.12504934821E-05_dp, &\n 0.11330272320E-05_dp, &\n -0.2056338417E-06_dp, & \n 0.61160950E-08_dp, &\n 0.50020075E-08_dp, &\n -0.11812746E-08_dp, &\n 0.1043427E-09_dp, & \n 0.77823E-11_dp, &\n -0.36968E-11_dp, &\n 0.51E-12_dp, &\n -0.206E-13_dp, &\n -0.54E-14_dp, &\n 0.14E-14_dp, &\n 0.1E-15_dp /)\n\n real(dp) :: gr, rr, rz\n integer :: ik, im, im1\n ! Return\n real(dp) :: ga\n\n ifgam1: if ( xin == aint(xin) ) then\n\n if ( 0.0_dp < xin ) then\n ga = 1.0_dp\n im1 = int(xin) - 1\n do ik = 2, im1\n ga = ga * real(ik, dp)\n end do\n else\n ga = 1.0E+300_dp\n end if\n\n else ifgam1\n\n if ( 1.0_dp < abs(xin) ) then\n rz = abs(xin)\n im = int(rz)\n rr = 1.0_dp\n do ik = 1, im\n rr = rr * ( rz - real(ik, kind=dp) )\n end do\n rz = rz - real(im, kind=dp)\n else\n rz = xin\n end if\n\n gr = gra(26)\n do ik = 25, 1, -1\n gr = gr * rz + gra(ik)\n end do\n\n ga = 1.0_dp / ( gr * rz )\n\n if ( 1.0_dp < abs(xin) ) then\n ga = ga * rr\n if ( xin < 0.0_dp ) then\n ga = - pi / ( xin * ga * sin(pi*xin) )\n end if\n end if\n\n end if ifgam1\n\n return\nend function gam_zj\n\nfunction incgaml(ain, xin) result(gout)\n!****************************************************************************\n! incgaml evaluates the Lower Incomplete Gamma Function(a,x) := \n! \\int_0^x exp(-t) t^{n-1) dt\n! \n! Reference:\n! Shanjie Zhang, Jianming Jin,\n! Computation of Special Functions,\n! Wiley, 1996, ISBN: 0-471-11963-6, LC: QA351.C45.\n! https://people.sc.fsu.edu/~jburkardt/f_src/special_functions/special_functions.f90\n!\n! Parameters:\n! Input, real ( kind = 8 ) ain, the parameter.\n! Input, real ( kind = 8 ) xin, the argument.\n! Output, real(dp) gout\n!****************************************************************************\n use kinds, only : dp\n implicit none\n ! Params\n real(dp), intent(in) :: ain, xin\n ! Locals\n real(dp) :: rr, rs\n real(dp) :: t0, xam\n integer :: ik\n ! Return\n real(dp) :: gout\n\n xam = -xin + ain*log(xin)\n\n if ( 700.0_dp < xam .or. 170.0_dp < ain ) then\n write(6, '(/,a)') 'ERR (incgaml), arg(s) too large! returning 0.0'\n gout = 0.0_dp\n return\n end if\n\n if ( xin .lt. 1.0e-50_dp ) then\n ! Tested against Mathematica, Gamma[1,0,10^-50] = 10e-50\n ! which is small enough to cutoff for this module\n gout = 0.0_dp\n\n else if ( xin .le. (1.0_dp+ain) ) then\n rs = 1.0_dp / ain\n rr = rs\n dok1: do ik = 1, 60\n rr = rr * xin / ( ain + real(ik, dp) )\n rs = rs + rr\n if ( abs(rr/rs) .lt. 1.0E-15_dp ) then\n exit dok1\n end if\n end do dok1\n gout = exp(xam) * rs\n\n else if ( (1.0_dp+ain) .lt. xin ) then\n t0 = 0.0_dp\n do ik = 60, 1, -1\n t0 = ( real(ik,dp) - ain ) / ( 1.0_dp + real(ik, dp)/(xin+t0) )\n end do \n gout = gam_zj(ain) - ( exp(xam) / (xin+t0) )\n !gout = gamma(ain) - ( exp(xam) / (xin+t0) )\n\n else ! usually a NaN\n write(*,*) 'ERR (incgaml) undefined for requested input' \n write(*,*) 'xin: ', xin\n write(*,*) 'ain: ', ain\n stop 4 ! SIGILL: illegal instruction\n end if\n\n return\nend function incgaml\n\n\nfunction fact_ratio2(ain, bin) result(ret)\n!****************************************************************************\n! Factorial ratio 2 := a! / ( b! (a-2b)! )\n!****************************************************************************\n implicit none\n ! Params\n integer, intent(in) :: ain, bin ! ain >= 2bin\n ! Locals\n integer :: i1, imx, imn\n ! Return\n integer(kind=8) :: ret\n\n if ( (ain.eq.0) .or. (ain.eq.1) .or. &\n (bin.eq.0) ) then\n ret = 1\n return\n else if (ain.gt.28) then\n write(6,'(\"ERR, fact_ratio2 cannot handle numbers > 28\")')\n ret = 0\n return\n end if\n\n imx = max(bin, ain - 2*bin)\n imn = min(bin, ain - 2*bin)\n\n ret = 1\n do i1 = imx+1, ain\n ret = ret * int(i1, 8)\n end do\n if ( imn .gt. 1) then\n do i1 = 2, imn\n ret = ret / int(i1, 8)\n end do\n end if\n\n return\nend function fact_ratio2\n\n\nfunction binomcof(ain, bin) result(ret)\n!****************************************************************************\n! binomial coefficient := a! / ( b! (a-b)! )\n!****************************************************************************\n implicit none\n ! Params\n integer, intent(in) :: ain, bin\n ! Locals\n integer :: i1, imx, imn\n ! Return\n integer :: ret\n\n if ( (ain.eq.0) .or. (ain.eq.1) .or. &\n (bin.eq.0) ) then\n ret = 1\n return\n end if\n\n imx = max(bin, ain - bin)\n imn = min(bin, ain - bin)\n\n ret = 1\n do i1 = imx+1, ain\n ret = ret * i1\n end do\n if ( imn .gt. 1) then\n do i1 = 2, imn\n ret = ret / i1\n end do\n end if\n\n return\nend function binomcof\n\n\nfunction binom_prefac_v2(si, iai) result(ret)\n!****************************************************************************\n! integral prefactor with the binom coefficient from Augspruger & Dykstra\n! adapted from \n! https://github.com/rpmuller/pyquante2/blob/master/pyquante2/ints/one.py\n!****************************************************************************\n use kinds, only : dp\n implicit none\n ! Params\n integer, intent(in) :: si, iai\n ! Return\n real(dp) :: ret\n\n ret = real(binomcof(iai, si), dp)\n return\nend function binom_prefac_v2\n\n\nfunction binom_prefac(si, iai, ibi, xpai, xpbi) result(ret)\n!****************************************************************************\n! integral prefactor with the binom coefficient from Augspruger & Dykstra\n! adapted from \n! https://github.com/rpmuller/pyquante2/blob/master/pyquante2/ints/one.py\n!****************************************************************************\n use kinds, only : dp\n implicit none\n ! Params\n integer, intent(in) :: si, iai, ibi\n real(dp), intent(in) :: xpai, xpbi\n ! Locals\n integer :: i1\n ! Return\n real(dp) :: ret\n\n ret = 0.0_dp\n do i1 = 0, si\n if ( ((si-iai).le.i1) .and. (i1.le.ibi) ) then\n ret = ret + real(binomcof(iai, si-i1), dp) * &\n real(binomcof(ibi, i1), dp) * &\n xpai ** (iai - si + i1) * &\n xpbi ** (ibi - i1)\n end if\n end do\n\n return\nend function binom_prefac\n\nfunction fb_v2(l1in, rin, gin) result(ret)\n!****************************************************************************\n! @TODO: combine with b0, rename to something more relevant\n!****************************************************************************\n use kinds, only : dp\n implicit none\n ! Params\n integer, intent(in) :: l1in, rin\n real(dp), intent(in) :: gin\n ! Locals\n real(dp) :: r1\n ! Return\n real(dp) :: ret\n\n ret = 0.0_dp\n !write(6,*) 'yee', i1, iin, l1in\n !if (iin.le.l1in) then !.and. (i1.le.0) ) then\n !if (iin.eq.l1in) then !.and. (i1.le.0) ) then\n !r1 = real(binomcof(l1in, iin), dp) * &\n ! 0.0_dp ** (l1in - iin) !* &\n ret = real(fact_ratio2(l1in, rin), dp) * (4.0_dp*gin)**(rin-l1in)\n !end if\n\n return \nend function fb_v2\n\n\nfunction b0(iin, rin, gin) result(ret)\n!****************************************************************************\n use kinds, only : dp\n implicit none\n ! Params\n integer, intent(in) :: iin, rin\n real(dp), intent(in) :: gin\n ! Return\n real(dp) :: ret\n\n ret = real(fact_ratio2(iin, rin), dp) * (4.0_dp*gin)**(rin-iin)\n\n return\nend function b0\n\n\nfunction fb(iin, l1in, l2in, pin, ain, bin, rin, gin) result(ret)\n!****************************************************************************\n! @TODO: combine with b0, rename to something more relevant\n!****************************************************************************\n use kinds, only : dp\n implicit none\n ! Params\n integer, intent(in) :: iin, l1in, l2in, rin\n real(dp), intent(in) :: pin, ain, bin, gin\n ! Return\n real(dp) :: ret\n\n ret = b0(iin, rin, gin) * &\n binom_prefac(iin, l1in, l2in, pin-ain, pin-bin)\n\n return \nend function fb\n\n\nfunction b_term(i1i, i2i, r1i, r2i, ui, l1i, l2i, l3i, l4i, pxi, axi, &\n bxi, qxi, cxi, dxi, gam1, gam2, deli) result(ret)\n!****************************************************************************\n! Logic for filling elements of b_array\n!****************************************************************************\n use kinds, only : dp\n implicit none\n ! Params\n integer, intent(in) :: i1i, i2i, r1i, r2i, ui\n integer, intent(in) :: l1i, l2i, l3i, l4i\n real(dp), intent(in) :: pxi, axi, bxi\n real(dp), intent(in) :: qxi, cxi, dxi\n real(dp), intent(in) :: gam1, gam2, deli\n ! Locals\n real(dp) :: sgn1, p1, p2, fb1, fb2, frat\n ! Return\n real(dp) :: ret\n\n sgn1 = real( (-1)**(i2i+ui), dp)\n p1 = (qxi-pxi) ** (i1i + i2i - 2*(r1i+r2i+ui))\n p2 = deli ** (i1i + i2i - ui - 2*(r1i+r2i))\n fb1 = fb(i1i, l1i, l2i, pxi, axi, bxi, r1i, gam1)\n fb2 = fb(i2i, l3i, l4i, qxi, cxi, dxi, r2i, gam2)\n frat = real( fact_ratio2( i1i + i2i - 2*(r1i+r2i), ui), dp)\n\n ret = fb1 * fb2 * frat * sgn1 * p1 / p2\n\n return\nend function b_term\n\n\nsubroutine b_array(l1i, l2i, l3i, l4i, pin, ain, bin, qin, cin, din, &\n g1i, g2i, deli, bout)\n!****************************************************************************\n! @TODO: combine with b_term\n!****************************************************************************\n use kinds, only : dp\n implicit none\n ! Params\n integer, intent(in) :: l1i, l2i, l3i, l4i\n real(dp), intent(in) :: pin, ain, bin\n real(dp), intent(in) :: qin, cin, din\n real(dp), intent(in) :: g1i, g2i, deli\n! real(dp), allocatable, intent(out) :: bout(:)\n real(dp), intent(out) :: bout(vmax_am_tot)\n ! Locals\n integer :: i1, i2, ir1, ir2, iu, ij\n integer :: imax\n\n! if ( allocated(bout) ) deallocate(bout)\n imax = l1i + l2i + l3i + l4i + 1\n! allocate( bout(imax) )\n\n bout(:) = 0.0_dp\n do i1 = 1, l1i + l2i + 1\n do i2 = 1, l3i + l4i + 1\n do ir1 = 1, (i1-1)/2 + 1\n do ir2 = 1, (i2-1)/2 + 1\n do iu = 1, (i1+i2-2)/2 - ir1 - ir2 + 3\n ij = i1 + i2 - 2*(ir1+ir2-2) - iu ! +4 for 1-based indexing\n bout(ij) = bout(ij) + b_term(i1-1, i2-1, ir1-1, ir2-1, iu-1, &\n l1i, l2i, l3i, l4i, &\n pin, ain, bin, qin, cin, din, &\n g1i, g2i, deli)\n! write(6,'(2x,6(i2,x,\",\"))') i1-1, i2-1, ir1-1, ir2-1, iu-1, ij-1\n end do\n end do\n end do\n end do\n end do\n\nend subroutine b_array\n\n\nsubroutine gauss_prod_center(alpa, acen, alpb, bcen, ocen)\n!****************************************************************************\n! fill ocen with the center of the combined gaussians\n!****************************************************************************\n use kinds, only : dp\n implicit none\n ! Params\n real(dp), intent(in) :: alpa, alpb ! exponents\n real(dp), intent(in) :: acen(3), bcen(3) ! centers\n real(dp), intent(out) :: ocen(3) ! output center\n ! Locals\n real(dp) :: alpab\n\n alpab = 1.0_dp / (alpa + alpb)\n ocen(1) = (alpa*acen(1) + alpb*bcen(1)) * alpab\n ocen(2) = (alpa*acen(2) + alpb*bcen(2)) * alpab\n ocen(3) = (alpa*acen(3) + alpb*bcen(3)) * alpab\n\nend subroutine gauss_prod_center\n\n \nfunction diff3_norm2(vec1, vec2) result(ret)\n!****************************************************************************\n! find norm^2 of the difference of two 3d vectors\n!****************************************************************************\n use kinds, only : dp\n implicit none\n ! Params\n real(dp), intent(in) :: vec1(3), vec2(3)\n ! Return\n real(dp) :: ret\n\n ret = ( vec1(1) - vec2(1) )**2 + &\n ( vec1(2) - vec2(2) )**2 + &\n ( vec1(3) - vec2(3) )**2\n\n return\nend function diff3_norm2\n\n\nsubroutine b_array_v2(l1i, l3i, cmain, g1i, g2i, deli, bout)\n!****************************************************************************\n! b_array just for 2 center, all functions inlined for speed\n!****************************************************************************\n use kinds, only : dp\n implicit none\n ! Params\n integer, intent(in) :: l1i, l3i\n real(dp), intent(in) :: cmain ! cin - ain\n real(dp), intent(in) :: g1i, g2i, deli\n real(dp), intent(out) :: bout(vmax_am_tot)\n ! Locals\n integer :: ir1, ir2, iu, ij\n integer :: l1p3\n real(dp) :: sgn1, p1, p2, fb1, fb2, frat\n real(dp) :: fg1, fg2\n\n bout(:) = 0.0_dp\n\n l1p3 = l1i + l3i\n fg1 = 4.0_dp * g1i\n fg2 = 4.0_dp * g2i\n\n do ir1 = 0, l1i/2\n do ir2 = 0, l3i/2\n do iu = 0, (l1i+l3i)/2 - ir1 - ir2\n ij = l1i + l3i - 2*(ir1+ir2) - iu + 1 \n\n sgn1 = real( (-1)**(l3i+iu), dp )\n p1 = cmain ** (l1p3 - 2*(ir1+ir2+iu))\n p2 = deli ** (l1p3 - iu - 2*(ir1+ir2))\n fb1 = real(fact_ratio2(l1i, ir1), dp) * fg1**(ir1-l1i)\n fb2 = real(fact_ratio2(l3i, ir2), dp) * fg2**(ir2-l3i)\n frat = real( fact_ratio2( l1p3 - 2*(ir1+ir2), iu), dp)\n\n bout(ij) = bout(ij) + ( fb1 * fb2 * frat * sgn1 * p1 / p2 )\n end do\n end do\n end do\n\n return\nend subroutine b_array_v2\n\n\nfunction coulomb_rep2_v2( acen, amom, alpa, &\n ccen, cmom, alpc ) result(ret)\n!****************************************************************************\n! 2-center ERI, rewritten from coulomb_rep4, not just a wrapper\n! take advantage of 2-center to speed up b_array\n! switch to downward recursion of fboys so only eval once\n!\n! Parameters:\n! Input, real(dp), dim(3) :: acen, ccen ! origins of the GTOs\n! Input, real(dp) :: alpa, alpc ! alpha(abcd), exponents\n! Input, integer, dim(3) :: amom, cmom ! ang. mom. of GTOs\n! Output, real(dp) :: ret ! the value of the ERI\n!****************************************************************************\n use kinds, only : dp\n use constants, only : pi\n implicit none\n ! Params\n real(dp), intent(in) :: acen(3), ccen(3) ! origins\n real(dp), intent(in) :: alpa, alpc ! exponents\n integer, intent(in) :: amom(3), cmom(3) ! ang. mom.\n ! Locals\n real(dp), parameter :: rtol = 1.0e-8_dp\n integer :: ii, jj, kk\n real(dp) :: rpq2\n real(dp) :: delt, fbarg, fbnum\n! real(dp), dimension(vmax_am_tot) :: bax, bay, baz\n! real(dp), dimension(0:vmax_am_tot) :: fbar\n integer :: fbarsz\n ! Return\n real(dp) :: ret\n\n call start_clock('crep2v2')\n\n ret = 0.0_dp\n rpq2 = diff3_norm2(acen, ccen) ! find p & q diff norm\n delt = 0.25_dp * ( 1.0_dp/alpa + 1.0_dp/alpc ) ! b_array arg\n fbarg = 0.25_dp * rpq2 / delt ! fboys arg\n\n if ( (alpa.lt.rtol) .or. (alpc.lt.rtol) .or. (delt.lt.rtol) ) then\n write(6,'(\"ERR (coulomb_rep2), invalid input, returning 0\")')\n ret = 0.0_dp\n return\n end if\n\n !call start_clock('barrays')\n call b_array_v2(amom(1), cmom(1), ccen(1)-acen(1), alpa, alpc, delt, bax)\n call b_array_v2(amom(2), cmom(2), ccen(2)-acen(2), alpa, alpc, delt, bay)\n call b_array_v2(amom(3), cmom(3), ccen(3)-acen(3), alpa, alpc, delt, baz)\n !call stop_clock('barrays')\n\n !call start_clock('fboys comp')\n fbarsz = sum( amom + cmom ) \n if ( (fbarg.lt.taytol) .or. (fbarg.gt.anatol) ) then\n ! taylor series and analytical are fast, go ahead and calculate\n do ii = 0, fbarsz\n fbar(ii) = fboys( real(ii,dp), fbarg )\n end do\n else ! use downward recursion\n fbar(fbarsz) = fboys( real(fbarsz,dp), fbarg )\n if ( fbarsz .gt. 0 ) then\n do ii = fbarsz-1, 0, -1\n fbar(ii) = 2*fbarg*fbar(ii+1) + exp(-fbarg)\n fbar(ii) = fbar(ii) / real( 2*ii + 1, dp )\n end do\n end if\n end if\n !call stop_clock('fboys comp')\n\n !call start_clock('fboys contract')\n if ( fbarsz .gt. 0 ) then\n do ii = 1, amom(1) + cmom(1) + 1\n do jj = 1, amom(2) + cmom(2) + 1\n do kk = 1, amom(3) + cmom(3) + 1\n ret = ret + bax(ii)*bay(jj)*baz(kk)*fbar(ii+jj+kk-3)\n end do\n end do\n end do\n else ! s-types, no need to contract\n ! I can't tell from run times if eval'ing s-types separately is any faster\n ret = bax(1)*bay(1)*baz(1)*fbar(0)\n end if\n !call stop_clock('fboys contract')\n\n ret = ret * ericoef / ( alpa*alpc*sqrt(alpa+alpc) )\n\n call stop_clock('crep2v2')\n return\nend function coulomb_rep2_v2\n\n\nfunction coulomb_rep4(acen, amom, alpa, bcen, bmom, alpb, &\n ccen, cmom, alpc, dcen, dmom, alpd) result(ret)\n!****************************************************************************\n! 4-center ERI, adapted from pyquante2/ints/two.py\n!\n! Parameters:\n! Input, real(dp), dim(3) :: acen, bcen, ccen, dcen ! origins of the GTOs\n! Input, real(dp) :: alpa, alpb, alpc, alpd ! alpha(abcd), exponents\n! Input, integer, dim(3) :: amom, bmom, cmom, dmom ! ang. mom. of GTOs\n! Output, real(dp) :: ret ! the value of the ERI\n!****************************************************************************\n use kinds, only : dp\n use constants, only : pi\n implicit none\n ! Params\n real(dp), intent(in) :: acen(3), bcen(3), ccen(3), dcen(3) ! origins\n real(dp), intent(in) :: alpa, alpb, alpc, alpd ! exponents\n integer, intent(in) :: amom(3), bmom(3), cmom(3), dmom(3) ! ang. mom.\n ! Locals\n real(dp), parameter :: rtol = 1.0e-8_dp\n integer :: ii, jj, kk\n real(dp) :: rab2, rcd2, rpq2\n real(dp) :: gam1, gam2, delt, fbarg, fbnum\n real(dp) :: pcen(3), qcen(3)\n! real(dp), allocatable :: bax(:), bay(:), baz(:)\n\n! real(dp), dimension(vmax_am_tot) :: bax, bay, baz\n! real(dp), dimension(0:vmax_am_tot) :: fbar\n integer :: fbarsz\n ! Return\n real(dp) :: ret\n\n call start_clock('coulomb_rep4')\n\n ret = 0.0_dp\n\n ! Combine a & b => p\n rab2 = diff3_norm2(acen, bcen)\n gam1 = alpa + alpb\n call gauss_prod_center(alpa, acen, alpb, bcen, pcen)\n\n ! Combine c & d => q\n rcd2 = diff3_norm2(ccen, dcen)\n gam2 = alpc + alpd\n call gauss_prod_center(alpc, ccen, alpd, dcen, qcen)\n\n rpq2 = diff3_norm2(pcen, qcen) ! find p & q diff norm\n delt = 0.25_dp * ( 1.0_dp/gam1 + 1.0_dp/gam2 ) ! b_array arg\n ! @TODO?\n! delt = 0.25_dp * ( gam1**-1 + gam2**-1 ) ! b_array arg\n fbarg = 0.25_dp * rpq2 / delt ! fboys arg\n\n if ( (gam1.lt.rtol) .or. (gam2.lt.rtol) .or. (delt.lt.rtol) ) then\n write(6,'(\"ERR (coulomb_rep4), invalid input, returning 0\")')\n ret = 0.0_dp\n return\n end if\n\n call start_clock('barrays')\n call b_array(amom(1), bmom(1), cmom(1), dmom(1), &\n pcen(1), acen(1), bcen(1), qcen(1), ccen(1), dcen(1), &\n gam1, gam2, delt, bax)\n call b_array(amom(2), bmom(2), cmom(2), dmom(2), &\n pcen(2), acen(2), bcen(2), qcen(2), ccen(2), dcen(2), &\n gam1, gam2, delt, bay)\n call b_array(amom(3), bmom(3), cmom(3), dmom(3), &\n pcen(3), acen(3), bcen(3), qcen(3), ccen(3), dcen(3), &\n gam1, gam2, delt, baz)\n call stop_clock('barrays')\n\n call start_clock('fboys contract')\n\n fbarsz = sum( amom + bmom + cmom + dmom ) \n do ii = 0, fbarsz\n fbar(ii) = fboys( real(ii,dp), fbarg )\n end do\n\n do ii = 1, amom(1) + bmom(1) + cmom(1) + dmom(1) + 1\n do jj = 1, amom(2) + bmom(2) + cmom(2) + dmom(2) + 1\n do kk = 1, amom(3) + bmom(3) + cmom(3) + dmom(3) + 1\n !fbnum = real( ii + jj + kk - 3, dp )\n !ret = ret + bax(ii)*bay(jj)*baz(kk)*fboys(fbnum, fbarg)\n ret = ret + bax(ii)*bay(jj)*baz(kk)*fbar(ii+jj+kk-3)\n end do\n end do\n end do\n call stop_clock('fboys contract')\n\n ret = ret * 2.0_dp * (pi**2.5_dp) / ( gam1*gam2*sqrt(gam1+gam2) ) * &\n exp( -alpa * alpb * rab2 / gam1 ) * &\n exp( -alpc * alpd * rcd2 / gam2 )\n\n call stop_clock('coulomb_rep4')\n return\nend function coulomb_rep4\n\n\nfunction coulomb_rep2(acen, amom, alpa, bcen, bmom, alpb) result(ret)\n!****************************************************************************\n! 2-center ERI, wrapper for coulomb_rep4\n!****************************************************************************\n use kinds, only : dp\n implicit none\n ! Params\n real(dp), intent(in) :: acen(3), bcen(3) ! origins\n real(dp), intent(in) :: alpa, alpb ! exponents\n integer, intent(in) :: amom(3), bmom(3) ! ang. mom.\n ! Locals\n integer :: am0(3)\n real(dp) :: alp0\n ! Return\n real(dp) :: ret\n\n am0 = (/ 0, 0, 0 /)\n alp0 = 0.0_dp\n\n ret = coulomb_rep4(acen, amom, alpa, acen, am0, alp0, &\n bcen, bmom, alpb, bcen, am0, alp0)\n\n return\nend function coulomb_rep2\n\n\nend module feril\n", "meta": {"hexsha": "270545723e471fc0c05dacd59d7ab05ce24ff8cc", "size": 25740, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "feril.f90", "max_stars_repo_name": "mtesseracted/feril", "max_stars_repo_head_hexsha": "472a972ffe1b364b193bc6ab81884d1d4c579db0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "feril.f90", "max_issues_repo_name": "mtesseracted/feril", "max_issues_repo_head_hexsha": "472a972ffe1b364b193bc6ab81884d1d4c579db0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "feril.f90", "max_forks_repo_name": "mtesseracted/feril", "max_forks_repo_head_hexsha": "472a972ffe1b364b193bc6ab81884d1d4c579db0", "max_forks_repo_licenses": ["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.4976303318, "max_line_length": 87, "alphanum_fraction": 0.5166666667, "num_tokens": 9230, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544911, "lm_q2_score": 0.7371581626286834, "lm_q1q2_score": 0.6504889046879418}} {"text": "module geometry_t_interface\n !! Model the propellent grain as a cylinder burning radially outward from its\n !! evacuated axial core and axially inward towards its cross-sectional mid-plane.\n !! The outer diameter is inhibited by the surroundin casing as the propellent was\n !! poured into the tube/chamber so that only the inner diameter burns when ignited.\n use constants, only : dp\n implicit none\n\n private\n\n type, public :: geometry_t\n !! Encapsulate the grain geometry and burnout condition\n private\n real(dp) vol_ !! volume\n real(dp) id_ !! inner diameter\n real(dp) od_ !! outer diameter\n real(dp) length_ !! axial length\n contains\n procedure :: surf\n procedure :: vol\n procedure :: burnout\n end type\n\n interface geometry_t\n module procedure new_geometry_t, incremented_geometry_t\n end interface\n\n interface\n\n pure module function new_geometry_t(vol, id, od, length)\n !! Result is a new geometry_t object defined by the actual arguments\n implicit none\n real(dp), intent(in) :: vol !! volume\n real(dp), intent(in) :: id !! inner diameter\n real(dp), intent(in) :: od !! outer diameter\n real(dp), intent(in) :: length !! axial length\n type(geometry_t) :: new_geometry_t\n end function\n\n pure module function incremented_geometry_t(old_geometry_t, volume_increment)\n !! Result is an updated cylinder after one time step of burning from the inner\n !! diameter outward and from both ends inward along the axial length.\n implicit none\n type(geometry_t), intent(in) :: old_geometry_t\n real(dp), intent(in) :: volume_increment\n type(geometry_t) incremented_geometry_t\n end function\n\n pure module function surf(this, burn_depth)\n !! Result is the annular grain surface area\n implicit none\n class(geometry_t), intent(in) :: this\n real(dp), intent(in) :: burn_depth !! surface-normal distance burned\n real(dp) surf\n end function\n\n pure module function vol(this)\n !! Result is the annular grain volume\n implicit none\n class(geometry_t), intent(in) :: this\n real(dp) vol\n end function\n\n pure module function burnout(this, db)\n !! Result is .true. if all grain has been depleted and .false. otherwise\n implicit none\n class(geometry_t), intent(in) :: this\n real(dp), intent(in) :: db !! burn depth\n logical burnout\n end function\n\n end interface\n\nend module geometry_t_interface\n", "meta": {"hexsha": "09baa0802dccd4a048bcca6e61e0a89bb1782289", "size": 2501, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/refurbished/geometry_t_interface.f90", "max_stars_repo_name": "sourceryinstitute/rocket-science", "max_stars_repo_head_hexsha": "92c79b1008db7a715770e098db0dbda6a6062d54", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-09-23T15:09:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-24T05:50:57.000Z", "max_issues_repo_path": "src/refurbished/geometry_t_interface.f90", "max_issues_repo_name": "sourceryinstitute/rocket-science", "max_issues_repo_head_hexsha": "92c79b1008db7a715770e098db0dbda6a6062d54", "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/refurbished/geometry_t_interface.f90", "max_forks_repo_name": "sourceryinstitute/rocket-science", "max_forks_repo_head_hexsha": "92c79b1008db7a715770e098db0dbda6a6062d54", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2021-03-04T14:17:20.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-21T17:35:44.000Z", "avg_line_length": 33.3466666667, "max_line_length": 85, "alphanum_fraction": 0.6845261895, "num_tokens": 572, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544911, "lm_q2_score": 0.7371581568543044, "lm_q1q2_score": 0.6504888995924689}} {"text": " Read (*,*)x1,x2\r\n pi=3.1456\r\n y1=1/sqrt(pi)*exp(-x1**2)/2\r\n y2=1/sqrt(pi)*exp(-x2**2)/2\r\n write(*,*)x1,x2,y1,y2\r\n stop\r\n end\r\n", "meta": {"hexsha": "7409eeb4b0603af1eb9e8b5cb3a36b325d001e8b", "size": 176, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "last28-52009/Example/Example1/Example1.f", "max_stars_repo_name": "Melhabbash/Computational-Physics-", "max_stars_repo_head_hexsha": "82a92e629fbaaf053d2f5e1ccb1224389b2e94be", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "last28-52009/Example/Example1/Example1.f", "max_issues_repo_name": "Melhabbash/Computational-Physics-", "max_issues_repo_head_hexsha": "82a92e629fbaaf053d2f5e1ccb1224389b2e94be", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "last28-52009/Example/Example1/Example1.f", "max_forks_repo_name": "Melhabbash/Computational-Physics-", "max_forks_repo_head_hexsha": "82a92e629fbaaf053d2f5e1ccb1224389b2e94be", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.0, "max_line_length": 36, "alphanum_fraction": 0.3806818182, "num_tokens": 74, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705731, "lm_q2_score": 0.7371581568543044, "lm_q1q2_score": 0.6504888950339434}} {"text": "program twodintx\nuse twod_quad\nREAL*8 X(3,2),Y(3,2),DATA(450),RES,ERR,s(3)\nINTEGER IWORK(100),NU,ND,NEVALS,IFLAG\nEXTERNAL F\nX(1,1)=0.\nY(1,1)=0.\nX(2,1)=1.\nY(2,1)=0.\nX(3,1)=1.\nY(3,1)=1.\nX(1,2)=0.\nY(1,2)=0.\nX(2,2)=1.\nY(2,2)=1.\nX(3,2)=0.\nY(3,2)=1.\nNU=0\nND=0\nIFLAG=1\nCALL TWODQ(F,2,X,Y,1.E-08,1,50,4000,RES,ERR,NU,ND, NEVALS,IFLAG,DATA,IWORK)\nPRINT*,RES,ERR,NEVALS,IFLAG\n!CALL twodqd(f, 2, x, y, 1.e-04, 1, 50, 4000, result, &\n! error, nu, nd, nevals, iflag)\n!PRINT*,RES,ERR,NEVALS,IFLAG\nend program twodintx\n\nreal*8 FUNCTION F(X,Y)\nreal*8 x,y\nF=dCOS(X+Y)\nRETURN\nEND\n\n", "meta": {"hexsha": "9eb9b181a5c1ecbac2bf677ee5124aa83b8067ad", "size": 581, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/testwodq.f90", "max_stars_repo_name": "jnnccc/ring-gravity", "max_stars_repo_head_hexsha": "e326c3507a872f507443f1523051e0ebe6f24a5e", "max_stars_repo_licenses": ["MIT"], "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/testwodq.f90", "max_issues_repo_name": "jnnccc/ring-gravity", "max_issues_repo_head_hexsha": "e326c3507a872f507443f1523051e0ebe6f24a5e", "max_issues_repo_licenses": ["MIT"], "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/testwodq.f90", "max_forks_repo_name": "jnnccc/ring-gravity", "max_forks_repo_head_hexsha": "e326c3507a872f507443f1523051e0ebe6f24a5e", "max_forks_repo_licenses": ["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.0882352941, "max_line_length": 75, "alphanum_fraction": 0.6161790017, "num_tokens": 315, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.851952809486198, "lm_q2_score": 0.7634837635542924, "lm_q1q2_score": 0.6504521373571754}} {"text": " subroutine initialize(mx,my,meqn,mbc,blockno,\n & xlower,ylower,dx,dy,q)\n implicit none\n\n integer meqn, mbc, mx, my, blockno\n double precision xlower, ylower, dx, dy\n double precision q(1-mbc:mx+mbc, 1-mbc:my+mbc, meqn)\n\n integer i, j, mq, ichoice\n double precision xlow, ylow,wl\n\n common /com_init/ ichoice\n\nc # ichoice = 1 : One large circle only\nc # ichocie = 2 : One large circle and several satellite circles\n ichoice = 2\n\n\n do mq = 1,meqn\n do i = 1-mbc,mx+mbc\n xlow = xlower + (i-1)*dx\n do j = 1-mbc,my+mbc\n ylow = ylower + (j-1)*dy\n\n call cellave2(blockno,xlow,ylow,dx,dy,wl)\n q(i,j,mq) = wl\n enddo\n enddo\n enddo\n\n return\n end\n\n double precision function fdisc(blockno,xc,yc)\n implicit none\n\n double precision xc,yc, r\n double precision xp, yp, zp, rp, th, x0\n double precision y0, pi\n integer m, ichoice, blockno\n logical fclaw2d_map_is_used\n\n integer*8 cont, get_context\n\n common /com_init/ ichoice\n\n cont = get_context()\n\n pi = 4.d0*atan(1.d0)\n\n if (fclaw2d_map_is_used(cont)) then\n call fclaw2d_map_c2m(cont,\n & blockno,xc,yc,xp,yp,zp)\n else\n xp = xc\n yp = yc\n endif\n\n fdisc = -1\n rp = sqrt((xp)**2 + (yp)**2)\n\nc # Large inner circle\n if (rp .lt. 0.4d0) then\n fdisc = 1.d0\n endif\n\n if (ichoice .eq. 1) then\n fdisc = -fdisc\n return\n endif\n\nc # Smaller surrounding circles\n do m = 1,4\nc # Larger circles\n th = (m-1)*pi/2.d0\n x0 = 0.6*cos(th)\n y0 = 0.6*sin(th)\n rp = sqrt((xp - x0)**2 + (yp-y0)**2)\n if (rp .lt. 0.2) then\n fdisc = 1.d0\n endif\n\nc # Smaller circles\n th = pi/4.d0 + (m-1)*pi/2.d0\n x0 = 0.55*cos(th)\n y0 = 0.55*sin(th)\n rp = sqrt((xp - x0)**2 + (yp-y0)**2)\n if (rp .lt. 0.15) then\n fdisc = 1.d0\n endif\n enddo\n fdisc = -fdisc\n\n\n end\n", "meta": {"hexsha": "43df1c6876ad292d3f635b59a12d971fdf4b8d79", "size": 2146, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "applications/no_solver/user_4.6/initialize.f", "max_stars_repo_name": "ECLAIRWaveS/ForestClaw", "max_stars_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 34, "max_stars_repo_stars_event_min_datetime": "2017-09-26T13:39:44.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T08:56:23.000Z", "max_issues_repo_path": "applications/no_solver/user_4.6/initialize.f", "max_issues_repo_name": "ECLAIRWaveS/ForestClaw", "max_issues_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 75, "max_issues_repo_issues_event_min_datetime": "2017-08-02T19:56:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T12:36:32.000Z", "max_forks_repo_path": "applications/no_solver/user_4.6/initialize.f", "max_forks_repo_name": "ECLAIRWaveS/ForestClaw", "max_forks_repo_head_hexsha": "0a18a563b8c91c55fb51b56034fe5d3928db37dd", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 23, "max_forks_repo_forks_event_min_datetime": "2018-02-21T00:10:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T19:08:36.000Z", "avg_line_length": 22.3541666667, "max_line_length": 68, "alphanum_fraction": 0.5018639329, "num_tokens": 738, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527982093666, "lm_q2_score": 0.7634837635542925, "lm_q1q2_score": 0.6504521287474979}} {"text": "! Ken Klare, LANL P-4 (c)1990,1991\n!***********************************************************************\n!********************* 3.5 Piecewise Polynomial ************************\n!-----------------------------------------------------------------------\n Real*8 Function DPPVAL(x,korder,nintv,break,c)\n Real*8 x !input, the point to evaluate\n Integer korder !input, the order of the polynomial (degree+1)\n Integer nintv !input, the number of polynomial pieces\n Real*8 break(*)!input, [nintv+1] breakpoints\n Real*8 c(*) !input, [korder,nintv] polynomial coefficients\n!+Evaluate a piecewise polynomial\n Real*8 DPPDER\n DPPVAL = DPPDER(0,x,korder,nintv,break,c)\n End\n!-----------------------------------------------------------------------\n Real*8 Function DPPDER(ideriv,x,korder,nintv,break,c)\n Integer ideriv !input, the order of deriavtive to be evaluated\n Real*8 x !input, the point to evaluate\n Integer korder !input, the order of the polynomial (degree+1)\n Integer nintv !input, the number of polynomial pieces\n Real*8 break(*)!input, [nintv+1] breakpoints\n Real*8 c(korder,*)!input, [korder,nintv] polynomial coefficients\n!+Evaluate derivative of a piecewise polynomial\n Integer j,m,keep\n Real*8 h\n Data keep/1000000/\n! can only take so many derivatives\n If (ideriv.ge.korder) Then\n DPPDER = 0\n Else\n! look up the place\n Call DSRCH(nintv,x,break,1,keep)\n If (keep.gt.0) Then\n DPPDER = c(ideriv+1,keep)\n Else\n j = -1-keep\n if (j.le.0) j = 1\n h = x - break(j)\n DPPDER = c(korder,j)\n Do m = korder-ideriv-1, 1, -1\n DPPDER = DPPDER*h/m + c(m+ideriv,j)\n Enddo\n Endif\n Endif\n End\n!-----------------------------------------------------------------------\n Real*8 Function DPPITG(a,b,korder,nintv,break,c)\n Real*8 a,b !input, the range to evaluate\n Integer korder !input, the order of the polynomial (degree+1)\n Integer nintv !input, the number of polynomial pieces\n Real*8 break(*)!input, [nintv] breakpoints\n Real*8 c(korder,*)!input, [korder,nintv] polynomial coefficients\n!+Evaluate the integral of a piecewise polynomial\n Integer ia, ib, j\n Real*8 DP9ITG\n data ia /999999/\n data ib /999999/\n Call DSRCH(nintv,b,break,1,ib)\n If (ib.gt.0) Then\n DPPITG = 0\n Else\n ib = -1-ib\n if (ib.le.0) ib = 1\n DPPITG = DP9ITG(b-break(ib),korder,c(1,ib))\n Endif\n Call DSRCH(nintv,a,break,1,ia)\n If (ia.le.0) Then\n ia = -1-ia\n if (ia.le.0) ia = 1\n DPPITG = DPPITG - DP9ITG(a-break(ia),korder,c(1,ia))\n Endif\n Do j = ia,ib-1\n DPPITG = DPPITG + DP9ITG(break(j+1)-break(j),korder,c(1,j))\n Enddo\n Do j = ib,ia-1\n DPPITG = DPPITG - DP9ITG(break(j+1)-break(j),korder,c(1,j))\n Enddo\n End\n!-----------------------------------------------------------------------\n Real*8 Function DP9ITG(h,korder,c)\n Real*8 h !input, offset point\n Integer korder !input, number of terms, degree+1\n Real*8 c(*) !input, [korder] value and derivatives\n Integer j\n!+Evaluate integral of single polynomial\n DP9ITG = 0\n Do j = korder,1,-1\n DP9ITG = (DP9ITG*h + c(j))/j\n Enddo\n DP9ITG = DP9ITG*h\n End\n!-----------------------------------------------------------------------\n Subroutine DPCOEF(ndata,xdata,fdata,cof)\n Integer ndata !input, polynomial order (degree+1)\n Real*8 xdata(*)!input, [ndata] the ordinates, must be distinct\n Real*8 fdata(*)!input, [ndata] the abscissae\n Real*8 cof(*) !input, [ndata] the polynomial coeff\n!+Create single piecewise polynomial, value and derivatives at first\n! Not an IMSL routine. Method of G.Rybicki from Numerical Recipes POLCOE\n Integer nmax\n Parameter (nmax=15)\n Integer i,j,k,n\n Real*8 xx,s(nmax),b,ff,phi,fact(3:nmax)\n Data fact/2,6,24,120,720,5040,40320,362880,3628800,39916800,\n 1 479001600,6227020800E0,87178291200E0/\n\n n=ndata\n Do i=1,n\n cof(i)=0\n s(i)=0\n Enddo\n! s(n)=-(xdata(1)-xdata(1))\n! recurrence\n Do i=2,n\n xx=xdata(i)-xdata(1)\n Do j=n+1-i,n-1\n s(j)=s(j)-xx*s(j+1)\n Enddo\n s(n)=s(n)-xx\n Enddo\n Do j=1,n\n xx=xdata(j)-xdata(1)\n phi=n\n! phi=product(xj-xk) for j.ne.k\n Do k=n-1,1,-1\n phi=k*s(k+1)+xx*phi\n Enddo\n ff=fdata(j)/phi\n b=1\n Do k=n,1,-1\n cof(k)=cof(k)+b*ff\n b=s(k)+xx*b\n Enddo\n Enddo\n Do k=3,n\n cof(k)=cof(k)*fact(k)\n Enddo\n End\n!***********************************************************************\n!********************* Extension for vectors ***************************\n!-----------------------------------------------------------------------\n Subroutine DPPVALV(nx,x,korder,nintv,break,c,y)\n Integer nx !input, the number of points\n Real*8 x(*) !input, the [nx] points to evaluate\n Integer korder !input, the order of the polynomial (degree+1)\n Integer nintv !input, the number of polynomial pieces\n Real*8 break(*)!input, [nintv+1] breakpoints\n Real*8 c(*) !input, [korder,nintv] polynomial coefficients\n Real*8 y(*) !output, the evaluated points\n!+Evaluate a piecewise polynomial\n Call DPPDERV(0,nx,x,korder,nintv,break,c,y)\n End\n!-----------------------------------------------------------------------\n Subroutine DPPDERV(ideriv,nx,x,korder,nintv,break,c,y)\n Integer ideriv !input, the order of deriavtive to be evaluated\n Integer nx !input, the number of points\n Real*8 x(*) !input, the [nx] points to evaluate\n Integer korder !input, the order of the polynomial (degree+1)\n Integer nintv !input, the number of polynomial pieces\n Real*8 break(*)!input, [nintv+1] breakpoints\n Real*8 c(korder,*)!input, [korder,nintv] polynomial coefficients\n Real*8 y(*) !output, the evaluated points\n!+Evaluate derivative of a piecewise polynomial\n Integer j\n Real*8 DPPDER\n Do j=1,nx\n y(j) = DPPDER(ideriv,x(j),korder,nintv,break,c)\n Enddo\n End\n!-----------------------------------------------------------------------\n Subroutine DPPITGV(na,a,nb,b,korder,nintv,break,c,y)\n Integer na !input, the number of points\n Real*8 a(*) !input, the [na] points to evaluate from first\n Integer nb !input, the number of points\n Real*8 b(*) !input, the [nb] points to evaluate from first\n Integer korder !input, the order of the polynomial (degree+1)\n Integer nintv !input, the number of polynomial pieces\n Real*8 break(*)!input, [nintv] breakpoints\n Real*8 c(korder,*)!input, [korder,nintv] polynomial coefficients\n Real*8 y(*) !output, the evaluated points\n!+Evaluate the integral of a piecewise polynomial\n Real*8 DPPITG\n Integer j,ja,jb,n,inca,incb\n n = min(na,nb)\n If (na.eq.1) n = nb\n inca = 0\n incb = 0\n If (na.gt.1) inca = 1\n If (nb.gt.1) incb = 1\n ja = 1\n jb = 1\n Do j=1,n\n y(j) = DPPITG(a(ja),b(jb),korder,nintv,break,c)\n ja = ja + inca\n jb = jb + incb\n Enddo\n End\n", "meta": {"hexsha": "99e55237440260c2c1f1b26608a530da7d7de67b", "size": 7889, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "math/dppval.f", "max_stars_repo_name": "fluffynukeit/mdsplus", "max_stars_repo_head_hexsha": "a204d2e9d26554bb035945595210f2a57d187250", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 53, "max_stars_repo_stars_event_min_datetime": "2015-01-05T08:55:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T07:43:41.000Z", "max_issues_repo_path": "math/dppval.f", "max_issues_repo_name": "fluffynukeit/mdsplus", "max_issues_repo_head_hexsha": "a204d2e9d26554bb035945595210f2a57d187250", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 1231, "max_issues_repo_issues_event_min_datetime": "2015-02-02T18:54:02.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T08:27:45.000Z", "max_forks_repo_path": "math/dppval.f", "max_forks_repo_name": "fluffynukeit/mdsplus", "max_forks_repo_head_hexsha": "a204d2e9d26554bb035945595210f2a57d187250", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 44, "max_forks_repo_forks_event_min_datetime": "2015-05-24T20:18:06.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-07T13:51:04.000Z", "avg_line_length": 39.8434343434, "max_line_length": 77, "alphanum_fraction": 0.4957535809, "num_tokens": 2314, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527982093666, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6504521241626344}} {"text": "program lagrange_main\n\nimplicit none\nreal(8),allocatable :: x(:),y(:),L(:),xvg(:),yvg(:),xpl(:),ypl(:),er(:)\nreal(8)::xu,xl,delX, xg, yg,era,DP(6)\ninteger :: i,j,k,n,m,p\n\nn=10 !(n-1) is the order of polynomial (this means that there should atleast be n+1 values to create a polynomial)\n!m=100 !number of values to interpolate after creating the polynomial\n\n\ndo i=1,6\n DP(i)=10**i\nend do\n\ndo p=1,6\nm=DP(p) !number of values to interpolate after creating the polynomial\nallocate(x(n+1),y(n+1),L(n+1),xvg(m),yvg(m),xpl(m),ypl(m),er(6))\n\n xl=-1.0\n xu=+1.0\n delX=(xu-xl)/(n+1)\n \n do i=1,n+1\n if (i==1) then\n x(i)=xl\n else \n x(i)=x(i-1)+delX\n end if\n !y(i)=(x(i)**2)-(4*x(i))+4\n !print *,x(i)\n !print *,y(i)\n end do \n\n!enter the equation here\n!y=(x**2)-(4*x)+4\ny=1/(1+(25*(x**2)))\n!y=cos(x*3.14159265359)\n!print *, x\n!print *, y\n\ndelX=(xu-xl)/(m+1)\n do i=1,m\n if (i==1) then\n xvg(i)=xl\n else \n xvg(i)=xvg(i-1)+delX\n end if\n !print *,xvg(i)\n end do \n!print *, xvg\n!print *,yvg\nxpl=xvg\n\n!enter the equation here again\n!ypl=(xpl**2)-(4*xpl)+4\nypl=1/(1+(25*(xpl**2)))\n!ypl=cos(xpl*3.14159265359)\n\nyvg=0.0\ndo k=1,size(xvg)\nxg=xvg(k)\ndo i=1,n\n L(i)=1\n do j=1,n\n if (j.ne.i) then\n L(i)=L(i)*(xg-x(j))/(x(i)-x(j))\n end if\n end do\n!print *,i,L(i)\nyg=yg+L(i)*y(i)\nend do\n!print *, \"Value of y at\", xg, \"is\",yg\nyvg(k)=yg \nyg=0.0 !!for error not to propagate\nend do\nera=abs((sum(yvg)/size(yvg))-(sum(ypl)/size(ypl)))\n\ner(p)=era\nera=0.0\n\nprint*, DP(p),er(p)\n\ndeallocate(x,y,L,xvg,yvg,xpl,ypl,er)\nend do !!for the p loop\n\n\n\n\n!open(99, file='eqn1.dat')\n!do i=1,m\n! write(99,*) xpl(i),ypl(i),xvg(i),yvg(i)\n !print *, xpl(i),ypl(i),xvg(i),yvg(i)\n!end do\nclose(99)\n\n\n\n\nend program\n", "meta": {"hexsha": "a07ff94a63dc2dea4d53b087125f4fadc5eb6fd2", "size": 1764, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "lagrange_finish/lagr_finish.f90", "max_stars_repo_name": "akkiturb/Ilkay-s-Fortran-Class", "max_stars_repo_head_hexsha": "0600640574354052a5a7d87bad520b8a03650d0e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-12-18T19:31:01.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-18T19:31:01.000Z", "max_issues_repo_path": "lagrange_finish/lagr_finish.f90", "max_issues_repo_name": "akkiturb/Scientific-computing-in-Fortran", "max_issues_repo_head_hexsha": "0600640574354052a5a7d87bad520b8a03650d0e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lagrange_finish/lagr_finish.f90", "max_forks_repo_name": "akkiturb/Scientific-computing-in-Fortran", "max_forks_repo_head_hexsha": "0600640574354052a5a7d87bad520b8a03650d0e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-02-04T19:45:56.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-10T14:22:05.000Z", "avg_line_length": 17.4653465347, "max_line_length": 114, "alphanum_fraction": 0.5612244898, "num_tokens": 762, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527869325346, "lm_q2_score": 0.7634837581726991, "lm_q1q2_score": 0.6504521155529563}} {"text": "\n\n\n\n\n\n\n\n\n\n\n\n\n\nC-- File port_rand.F: Portable random number generator functions\nC-- Contents\nC-- o PORT_RAND\nC-- o PORT_RANARR\nC-- o PORT_RAND_NORM\n\nC---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|\nCBOP\nC !ROUTINE: PORT_RAND\nC !INTERFACE:\n real*8 FUNCTION PORT_RAND(seed)\n\nC !DESCRIPTION:\nC Portable random number generator\nC seed >=0 :: initialise using this seed ; and return 0\nC seed < 0 :: if first call then initialise using the default seed (=mseed)\nC and always return a random number\n\nC !USES:\n IMPLICIT NONE\n\nC !INPUT PARAMETERS:\n real*8 seed\nCEOP\n\nC !LOCAL VARIABLES:\n INTEGER nff,idum\n PARAMETER(nff=55)\n PARAMETER(idum=-2)\n real*8 fac\n real*8 mbig,mseed,mz\n PARAMETER (mbig=4000000.,mz=0.,fac=1.d0/mbig)\n real*8 mj,mk,ma(nff)\n DATA mseed/1618033./\n LOGICAL firstCall\n INTEGER i,ii,inext,inextp,k\n DATA firstCall /.true./\n SAVE firstCall,inext,inextp,ma\n\nC- Initialise the random number generator\n IF (firstCall .OR. seed.GE.mz) THEN\n IF (seed.GE.mz) mseed = seed\n firstCall=.false.\n mj=mseed-iabs(idum)\n mj=mod(mj,mbig)\n ma(nff)=mj\n mk=1\n DO i=1,nff-1\n ii=mod(21*i,nff)\n ma(ii)=mk\n mk=mj-mk\n IF (mk.LT.mz) mk=mk+mbig\n mj=ma(ii)\n ENDDO\n DO k=1,4\n DO i=1,nff\n ma(i)=ma(i)-ma(1+mod(i+30,nff))\n IF (ma(i).LT.mz) ma(i)=ma(i)+mbig\n ENDDO\n ENDDO\n inext=0\n inextp=31\n ENDIF\n\nC- Compute a random number (only if seed < 0)\n IF (seed.GE.mz) THEN\n port_rand=0.d0\n ELSE\n inext=mod(inext,nff)+1\n inextp=mod(inextp,nff)+1\n mj=ma(inext)-ma(inextp)\n IF (mj.LT.mz) mj=mj+mbig\n ma(inext)=mj\n port_rand=mj*fac\n ENDIF\n\n RETURN\n END\n\nC---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|\n\nCBOP\nC !ROUTINE: PORT_RANARR\nC !INTERFACE:\n SUBROUTINE PORT_RANARR(n,arr)\n\nC !DESCRIPTION:\nC Portable random number array generator\n\nC !USES:\n IMPLICIT NONE\n\nC !INPUT PARAMETERS:\n INTEGER n\n real*8 arr(n)\nCEOP\n\nC !LOCAL VARIABLES:\n INTEGER i\n real*8 port_rand\n real*8 seed\n seed=-1.d0\nc seed=1618033.0d0\n DO i=1,n\n arr(i)=port_rand(seed)\n ENDDO\n\n RETURN\n END\n\nC---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|\nCBOP\nC !ROUTINE: PORT_RAND_NORM\nC !INTERFACE:\n real*8 FUNCTION PORT_RAND_NORM()\n\nC !DESCRIPTION:\nC This function generates a normally distributed random number with\nC the so called polar algorithm. The algorithm actually generates 2\nC numbers, but only 1 is returned for maximum compatibility with old\nC code. The most obvious way to improve this function would be to\nC make sure that the second number is not wasted.\n\nC Changed: 2004.09.06 antti.westerlund@fimr.fi\n\nC !USES:\n IMPLICIT NONE\nCEOP\n\nC !LOCAL VARIABLES:\n real*8 port_rand\n real*8 x1, x2, xs, t\n\n real*8 seed\n seed=-1.d0\nc seed=1618033.0d0\n\nC first generate 2 equally distributed random numbers (-1,1)\n xs = 0.0\n DO WHILE ( xs.GE.1.0 .OR. xs.EQ.0.0 )\n x1=2.0*port_rand(seed)-1.0\n x2=2.0*port_rand(seed)-1.0\n xs=x1**2+x2**2\n ENDDO\n\n t = SQRT(-2.0*LOG(xs)/xs)\n port_rand_norm = t*x1\n\nC also t*x2 would be a gaussian random number and could be returned\n\n RETURN\n END\n", "meta": {"hexsha": "7cc277e8a15f4c8b31690ef619c570196b11b9d8", "size": 3649, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "build/port_rand.f", "max_stars_repo_name": "ElizabethYankovsky/MITgcm", "max_stars_repo_head_hexsha": "9e3cbd9dd7b61dbea201517a5c776fc7748f82af", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "build/port_rand.f", "max_issues_repo_name": "ElizabethYankovsky/MITgcm", "max_issues_repo_head_hexsha": "9e3cbd9dd7b61dbea201517a5c776fc7748f82af", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "build/port_rand.f", "max_forks_repo_name": "ElizabethYankovsky/MITgcm", "max_forks_repo_head_hexsha": "9e3cbd9dd7b61dbea201517a5c776fc7748f82af", "max_forks_repo_licenses": ["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.8502994012, "max_line_length": 80, "alphanum_fraction": 0.5478213209, "num_tokens": 1201, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722394, "lm_q2_score": 0.7745833841649233, "lm_q1q2_score": 0.6504439784778016}} {"text": "!---------------------------------------------------------------------- \n!---------------------------------------------------------------------- \n! lor : The Lorenz Equations\n!---------------------------------------------------------------------- \n!---------------------------------------------------------------------- \n\n SUBROUTINE FUNC(NDIM,U,ICP,PAR,IJAC,F,DFDU,DFDP) \n! ---------- ---- \n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: NDIM, ICP(*), IJAC\n DOUBLE PRECISION, INTENT(IN) :: U(NDIM), PAR(*)\n DOUBLE PRECISION, INTENT(OUT) :: F(NDIM)\n DOUBLE PRECISION, INTENT(INOUT) :: DFDU(NDIM,NDIM), DFDP(NDIM,*)\n\n F(1)= PAR(3) * (U(2)- U(1))\n F(2)= PAR(1)*U(1) - U(2) - U(1)*U(3)\n F(3)= U(1)*U(2) - PAR(2)*U(3)\n\n END SUBROUTINE FUNC\n\n SUBROUTINE STPNT(NDIM,U,PAR,T)\n! ---------- ----- \n\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: NDIM\n DOUBLE PRECISION, INTENT(INOUT) :: U(NDIM),PAR(*)\n DOUBLE PRECISION, INTENT(IN) :: T\n\n! Parameter values for the starting orbit in lor.dat :\n PAR(1)=280.\n PAR(2)= 8.d0/3.d0 \n PAR(3)=10. \n\n END SUBROUTINE STPNT\n\n SUBROUTINE BCND \n END SUBROUTINE BCND\n\n SUBROUTINE ICND \n END SUBROUTINE ICND\n\n SUBROUTINE FOPT \n END SUBROUTINE FOPT\n\n SUBROUTINE PVLS\n END SUBROUTINE PVLS\n", "meta": {"hexsha": "cd5684737ab11298fdc2afb9ee79908081dfc724", "size": 1359, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "07p/demos/lor/lor.f90", "max_stars_repo_name": "st970703/AUTO07P-Update-to-Python-3.0", "max_stars_repo_head_hexsha": "fb2d2aebf2127fa914064d01ed62c0acb5f6421c", "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": "07p/demos/lor/lor.f90", "max_issues_repo_name": "st970703/AUTO07P-Update-to-Python-3.0", "max_issues_repo_head_hexsha": "fb2d2aebf2127fa914064d01ed62c0acb5f6421c", "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": "07p/demos/lor/lor.f90", "max_forks_repo_name": "st970703/AUTO07P-Update-to-Python-3.0", "max_forks_repo_head_hexsha": "fb2d2aebf2127fa914064d01ed62c0acb5f6421c", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.3125, "max_line_length": 72, "alphanum_fraction": 0.4238410596, "num_tokens": 392, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339516289534, "lm_q2_score": 0.7745833893685269, "lm_q1q2_score": 0.6504439704205813}} {"text": "subroutine ray_lay(r2,r1,v2,v1,p,time,dist)\r\n! This subroutine computes transit times and delta increase\r\n! of a ray travelling from radius R2 down to R1 (or to the\r\n! turning point Rt if R1<Rt<R2), for linear velocity behaviour\r\n! from V2 (at R2) to V1. Slowness is P. Output: time T (sec)\r\n! and distance D (rad). Velocity in km/sec, radii in km.\r\n! Equations from G.Nolet, Linearized inversion of (teleseismic)\r\n! data. In: R.Cassinis,'The inverse problem in geophysical\r\n! interpretation',Plenum Press,NY,1981.\r\ncommon/pi/pi,per\r\nrz=6378\r\n\r\nrr=(r2-r1)/r1\r\nvv=(v2-v1)/v1\r\n!kod_sing=0\r\n!if(abs(vv/rr)-1..lt.0.01) then\r\n!\tkod_sing=1\r\n!\trzz=rz+1000.\r\n!\tp = p * rzz / rz\r\n!\tr1=r1+1000.\r\n!\tr2=r2+1000.\r\n!\twrite(*,*)' singularity'\r\n!end if\r\n!write(*,*)' kod_sing=',kod_sing\r\n\r\n\r\ntime=0\r\ndist=0\r\nif(abs(v1*v2).lt.0.000001) return\r\n\r\nif(abs(p).lt.0.000001) then\r\n\tif(abs(v2-v1).gt.0.000001) then\r\n\t\ttime=(log(v2)-log(v1))/dvdr\r\n\telse\r\n\t\ttime=(r2-r1)/v1\r\n\tend if\r\n\treturn\r\nend if\r\n\r\n\r\n!vr1=v1/r1\r\n!vr2=v2/r2\r\n!dif_pr=100*(vr2-vr1)/vr1\r\n!write(*,*)' v1/r1=',v1/r1,' v2/r2=',v2/r2,' dif_pr=',dif_pr\r\n!if(abs(dif_pr).lt.0.0001) then\r\n!\tsint=p*v1/r1\r\n!\tcost=sqrt(1-sint*sint)\r\n!\tds=abs(r2-r1)/cost\r\n!\tv=(v2+v1)/2\r\n!\tr=(r2+r1)/2\r\n!\ttime=ds/v\r\n!\tdist=ds*sint/r\r\n!\treturn\r\n!end if\r\n\r\n\r\nzav=rz-(r2+r1)/2.\r\n\r\n!if((zav-150)*(zav-155).lt.0) write(*,*)' z1=',rz-r1,' z2=',rz-r2\r\n!if((zav-150)*(zav-155).lt.0) write(*,*)' v1=',v1,' v2=',v2\r\n!if((zav-150)*(zav-155).lt.0) write(*,*)' v1/r1=',v1/r1,' v2/r2=',v2/r2\r\n\r\n!write(*,*)\r\n!write(*,*)' v1/r1=',v1/r1,' v2/r2=',v2/r2,' diff=',diff\r\n\r\ndiff=100*(v1/r1-v2/r2)/(v1/r1)\r\nif(diff.lt.0.0001) then\r\n\tsint=p*v1/r1\r\n\tcost=sqrt(1-sint*sint)\r\n\tdz=abs(r2-r1)\r\n\tds=dz/cost\r\n\tvav=(v1+v2)/2\r\n\ttime=ds/vav\r\n\tdh=ds*sint\r\n\tdist=dh/rz\r\n\treturn\r\nend if\r\n\r\n\r\n\r\ndvdr=(v2-v1)/(r2-r1)\r\nap = dvdr*p\r\n\r\nif(r2.gt.0.0000001) then\r\n\tsint2=p*v2/r2\r\nelse\r\n\tsint2=1.\r\nend if\r\nif(sint2.gt.1.) return\r\n\r\nif(r1.gt.0.0000001) then\r\n\tsint1=p*v1/r1\r\nelse\r\n\tsint1=1.\r\nend if\r\nif(sint1.gt.1.) sint1=1\r\n\r\n\r\n!write(*,*)' sint1=',sint1,' sint2=',sint2\r\n\r\nteta1=asin(sint1)\r\nteta2=asin(sint2)\r\n\r\ntgt1=TAN(teta1 / 2.)\r\ntgt2=TAN(teta2 / 2.)\r\n\r\nif(ap.eq.0.) then\r\n\tsntet=0\r\n\tc1=1. / TAN(TETA1)\r\n\tc2=1. / TAN(TETA2)\r\n\ttime=p*(c2-c1)\r\nelse\r\n\tap2=ap*ap\r\n\tsqap=SQRT(abs(1.-ap2))\r\n\tif(ap2.eq.1.) then\r\n\t\tsntet1=TAN(.785398132 + ap * .5 * teta1)\r\n\t\tsntet2=TAN(.785398132 + ap * .5 * teta2)\r\n\t\t!write(*,*)' metka2'\r\n\telse if(ap2.lt.1.) then\r\n\t\talfa=acos(-ap)\r\n\r\n\t\tsntet1=-.5*log((1.+SIN(alfa+teta1))/(1.-SIN(alfa-teta1)))/sqap\r\n\t\tsntet2=-.5*log((1.+SIN(alfa+teta2))/(1.-SIN(alfa-teta2)))/sqap\r\n\t\t!write(*,*)' teta1=',teta1,' teta2=',teta2,' alfa=',alfa\r\n\telse if(ap2.gt.1) then\r\n\t\taptg1 = -ap * tgt1 + 1.\r\n\t\taptg2 = -ap * tgt2 + 1.\r\n\t\tsntet1=2.*ATAN(aptg1/sqap)/sqap\r\n\t\tsntet2=2.*ATAN(aptg2/sqap)/sqap\r\n\t\t!write(*,*)' metka222'\r\n\tend if\r\n\ttime = (log(tgt2) - log(tgt1) - sntet2 + sntet1) / dvdr\r\n\tdist = teta1-teta2-ap*(sntet2-sntet1)\r\n\t!write(*,*)' metka11'\r\nend if\r\n\r\n!if(kod_sing.eq.1) then\r\n!\tdist=dist*rzz/rz\r\n!\tp = p * rz / rzz\r\n!\tr1=r1-1000.\r\n!\tr2=r2-1000.\r\n!end if\r\n\r\n\r\nreturn\r\nend", "meta": {"hexsha": "3a5c53850f3769b3abf4d8141b17477e1191e4b4", "size": 3108, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "PROGRAMS/subr/rays_locate/ray_lay.f90", "max_stars_repo_name": "ilyasnsk/colima_lotos_2019", "max_stars_repo_head_hexsha": "d3ff4f32034e49a32560f170e980b6847b6ea9c7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-10-28T06:16:54.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-16T02:52:23.000Z", "max_issues_repo_path": "PROGRAMS/subr/rays_locate/ray_lay.f90", "max_issues_repo_name": "ilyasnsk/colima_lotos_2019", "max_issues_repo_head_hexsha": "d3ff4f32034e49a32560f170e980b6847b6ea9c7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "PROGRAMS/subr/rays_locate/ray_lay.f90", "max_forks_repo_name": "ilyasnsk/colima_lotos_2019", "max_forks_repo_head_hexsha": "d3ff4f32034e49a32560f170e980b6847b6ea9c7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.2876712329, "max_line_length": 73, "alphanum_fraction": 0.5936293436, "num_tokens": 1421, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248191350352, "lm_q2_score": 0.6926419831347362, "lm_q1q2_score": 0.6504080129384278}} {"text": "c\nc ---------------------------------------------------------------------\nc\n subroutine rmnv(ql,qr,qgdnv)\n implicit double precision (a-h,o-z)\n dimension ql(4), qr(4), qgdnv(4)\n data itno/2/, small/1.d-6/\nc\n gamma = 1.4\n gamma1 = gamma - 1.\n gp1g2i = (gamma+1.d0)/(2.d0*gamma)\nc\nc # Riemann solver in x-direction\nc # Given states ql and qr, compute flux at interfaces.\n\nc # change variables from q1 = rho, q2 = rho*u, ... to\nc # rho, u, p:\nc\n rhol = ql(1)\n rhor = qr(1)\n ul = ql(2)/rhol\n ur = qr(2)/rhor\n utl = ql(3)/rhol\n utr = qr(3)/rhor\n pl = gamma1* (ql(4)- .5d0* (ql(2)*ql(2)/ql(1) \n & + ql(3)* ql(3)/ql(1)))\n pr = gamma1* (qr(4)- .5d0* (qr(2)*qr(2)/qr(1) \n & + qr(3)* qr(3)/qr(1)))\nc\nc # iterate to find pstar, ustar:\nc\n clsl = gamma*rhol*pl\n wm = dsqrt(clsl)\n clsr = gamma*rhor*pr\n wp = wm\n wm = dsqrt(clsr)\n pstar = (wp*pr+ wm*pl- wm*wp\n & *(ur- ul))/(wp+ wm)\n pstar = dmax1(pstar,small)\nc\n do 30 iter = 1, itno\n wsqp = clsl*(1.d0+gp1g2i*(pstar/pl-1.d0))\n wp = dsqrt(wsqp)\n wsqm = clsr*(1.d0+gp1g2i*(pstar/pr-1.d0))\n wm = dsqrt(wsqm)\nc \n zp = 2.d0*wp*wsqp/(wsqp+clsl)\n zm = 2.d0*wm*wsqm/(wsqm+clsr)\nc \n ustarm = ur-(pr-pstar)/wm\n ustarp = ul+(pl-pstar)/wp\n zsum = zp+zm\n epsp = zp*zm*(ustarm-ustarp)/zsum\n pstar = pstar-epsp\n pstar = dmax1(pstar,small)\n 30 continue\nc\n ustar = (zp*ustarm+zm*ustarp)/zsum\n sein = -dsign(1.d0,ustar)\n\t if (sein .ge. 0.0) then\n uo = ur\n po = pr\n ro = rhor\n utgdnv = utr\n\t else\n uo = ul\n po = pl\n ro = rhol\n utgdnv = utl\n\t endif\n co = dsqrt(po*gamma/ro)\n\n dummy = pstar-po\n wo = gamma*ro*po*(1.d0+gp1g2i*dummy/po)\n rstar = ro/(1.d0-ro*dummy/wo)\n wo = dsqrt(wo)\n cstar = dsqrt(gamma*pstar/rstar)\n wso = sein*uo+co\n wsi = sein*ustar+cstar\n ushok = sein*ustar+wo/rstar\n\t if (dummy .ge. 0.d0) then\n wsi = ushok\n wso = ushok\n\t else\n wsi = wsi\n wso = wso\n\t endif\n \n t4 = (wso+wsi)/dmax1(wso-wsi,wso+wsi,small)\n t4 = .5d0*(t4+1.d0)\n t5 = 1.d0-t4\n t3 = t4*cstar+t5*co\n rgdnv = t4*rstar+t5*ro\n ugdnv = t4*ustar+t5*uo\n pgdnv = t3*t3*rgdnv/gamma\n \n\t if (wso .ge. 0.d0) then\n pgdnv = pgdnv\n rgdnv = rgdnv\n ugdnv = ugdnv\n\t else\n pgdnv = po\n rgdnv = ro\n ugdnv = uo\n\t endif\n \n\t if (wsi .lt. 0.d0) then\n pgdnv = pgdnv\n rgdnv = rgdnv\n ugdnv = ugdnv\n\t else\n pgdnv = pstar\n rgdnv = rstar\n ugdnv = ustar\n\t endif\n\n qgdnv(1) = rgdnv\n qgdnv(2) = rgdnv*ugdnv\n qgdnv(3) = rgdnv*utgdnv\n qgdnv(4) = pgdnv/gamma1+.5*rgdnv*(ugdnv**2+utgdnv**2)\nc\n return\n end\n", "meta": {"hexsha": "229d81db2d11836cf7ed7c035c890c446cffa1b6", "size": 3166, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/2d/ag_ho/rmnv.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/rmnv.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/rmnv.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": 25.5322580645, "max_line_length": 71, "alphanum_fraction": 0.4437776374, "num_tokens": 1227, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248208414329, "lm_q2_score": 0.6926419767901475, "lm_q1q2_score": 0.6504080081626242}} {"text": "!*********************************************************************\n! This file is part of Polylogarithm.\n!\n! Polylogarithm is licenced under the MIT License.\n!*********************************************************************\n\n\n!*********************************************************************\n!> @brief Complex polylogarithm \\f$\\operatorname{Li}_6(z)\\f$\n!> @param z complex argument\n!> @return \\f$\\operatorname{Li}_6(z)\\f$\n!> @author Alexander Voigt\n!*********************************************************************\ndouble complex function cdli6(z)\n implicit none\n double complex :: z, u, u2, u4, u8, c5, lmz, r, fast_pos_cdlog\n double precision :: rz, iz, nz, pz, lnz, arg, sgn\n double precision, parameter :: PI = 3.1415926535897932D0\n double precision, parameter :: PI2 = 9.8696044010893586D0\n double precision, parameter :: PI4 = 97.409091034002437D0\n double precision, parameter :: PI6 = 961.38919357530444D0\n double precision, parameter :: zeta6 = 1.0173430619844491D0\n double precision, parameter :: c1 = 1.0369277551433699D0 ! zeta(5)\n double precision, parameter :: c2 = 0.54116161685556910D0\n double precision, parameter :: c3 = 0.20034281719326571D0\n double precision, parameter :: c4 = 0.068538919452009435D0\n double precision, parameter :: c6 = -1D0/1440\n double precision, parameter :: bf(18) = (/ &\n 1.0D0 , -31.0D0/64.0D0 , &\n 1.5241340877914952D-01, -3.4365555877057613D-02, &\n 5.7174797239368999D-03, -6.8180453746570645D-04, &\n 4.9960361948734493D-05, -4.9166051196039048D-07, &\n -3.0632975161302164D-07, 1.4414599270849095D-08, &\n 3.7272438230924107D-09, -3.7300867345487607D-10, &\n -5.1246526816085832D-11, 9.0541930956636683D-12, &\n 6.7381882615512517D-13, -2.1215831150303135D-13, &\n -6.8408811719011698D-15, 4.8691178462005581D-15 /)\n double precision, parameter :: cs(5) = (/ &\n -1.6534391534391534D-05, 2.2964432686654909D-08, &\n -9.9413128513657614D-11, 6.6912682653423394D-13, &\n -5.7933058574392549D-15 /)\n\n rz = real(z)\n iz = aimag(z)\n\n if (iz .eq. 0) then\n if (rz .eq. 0) then\n cdli6 = 0\n return\n endif\n if (rz .eq. 1) then\n cdli6 = zeta6\n return\n endif\n if (rz .eq. -1) then\n cdli6 = -31*zeta6/32\n return\n endif\n endif\n\n nz = rz**2 + iz**2\n pz = datan2(iz, rz)\n lnz = 0.5D0*log(nz)\n\n if (lnz**2 + pz**2 .lt. 1) then ! |log(z)| < 1\n u = dcmplx(lnz, pz) ! log(z)\n u2 = u**2\n c5 = (137D0/60 - fast_pos_cdlog(-u))/120\n cdli6 = zeta6 + u * c1 + &\n u2 * (c2 + u * c3 + &\n u2 * (c4 + u * c5 + &\n u2 * (c6 + &\n u * (cs(1) + &\n u2 * (cs(2) + &\n u2 * (cs(3) + &\n u2 * (cs(4) + &\n u2 * (cs(5)))))))))\n return\n endif\n\n if (nz .le. 1) then\n u = -fast_pos_cdlog(1 - z)\n r = 0\n sgn = 1\n else ! nz > 1\n if (pz .gt. 0) then\n arg = pz - PI\n else\n arg = pz + PI\n endif\n lmz = dcmplx(lnz, arg) ! log(-z)\n u = -fast_pos_cdlog(1 - 1/z)\n r = -31*PI6/15120 + lmz**2*(-7*PI4/720 + lmz**2*(-PI2/144 - lmz**2/720))\n sgn = -1\n endif\n\n u2 = u**2\n u4 = u2**2\n u8 = u4**2\n\n cdli6 = &\n r + sgn * ( &\n u*bf(1) + &\n u2*(bf(2) + u*bf(3)) + &\n u4*(bf(4) + u*bf(5) + u2*(bf(6) + u*bf(7))) + &\n u8*(bf(8) + u*bf(9) + u2*(bf(10) + u*bf(11)) + &\n u4*(bf(12) + u*bf(13) + u2*(bf(14) + u*bf(15)))) + &\n u8*u8*(bf(16) + u*bf(17) + u2*bf(18)) &\n )\n\nend function cdli6\n", "meta": {"hexsha": "766324975e109dd43b6bc2de08e3b1e969b37ac0", "size": 3929, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/fortran/Li6.f90", "max_stars_repo_name": "Expander/dilogarithm", "max_stars_repo_head_hexsha": "ad86038206895ab5bff79a26294f4bb5c5634eb5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-05-04T14:47:41.000Z", "max_stars_repo_stars_event_max_datetime": "2017-08-02T13:13:45.000Z", "max_issues_repo_path": "src/fortran/Li6.f90", "max_issues_repo_name": "Expander/dilogarithm", "max_issues_repo_head_hexsha": "ad86038206895ab5bff79a26294f4bb5c5634eb5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/fortran/Li6.f90", "max_forks_repo_name": "Expander/dilogarithm", "max_forks_repo_head_hexsha": "ad86038206895ab5bff79a26294f4bb5c5634eb5", "max_forks_repo_licenses": ["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.0803571429, "max_line_length": 78, "alphanum_fraction": 0.4627131586, "num_tokens": 1429, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248123094437, "lm_q2_score": 0.6926419767901475, "lm_q1q2_score": 0.6504080022530103}} {"text": "C *********************************************************\nC * *\nC * TEST NUMBER: 06.01.01/04 *\nC * TEST TITLE : Behavior of matrix composition *\nC * *\nC * PHIGS Validation Tests, produced by NIST *\nC * *\nC *********************************************************\n \n COMMON /GLOBNU/ CTLHND, ERRSIG, ERRFIL, IERRCT, UNERR,\n 1 TESTCT, IFLERR, PASSSW, ERRSW, MAXLIN,\n 2 CONID, MEMUN, WKID, WTYPE, GLBLUN, INDLUN,\n 3 DUMINT, DUMRL\n INTEGER CTLHND, ERRSIG, ERRFIL, IERRCT, UNERR,\n 1 TESTCT, IFLERR, PASSSW, ERRSW, MAXLIN,\n 2 CONID, MEMUN, WKID, WTYPE, GLBLUN, INDLUN,\n 3 DUMINT(20), ERRIND\n REAL DUMRL(20)\n \n COMMON /GLOBCH/ PIDENT, GLBERR, TSTMSG, FUNCID,\n 1 DUMCH\n CHARACTER PIDENT*40, GLBERR*60, TSTMSG*900, FUNCID*80,\n 1 DUMCH(20)*20\n \n REAL ACT4X4(4,4), EXP4X4(4,4), AIN4X4(4,4), BIN4X4(4,4)\n REAL ACT3X3(3,3), EXP3X3(3,3), AIN3X3(3,3), BIN3X3(3,3)\n REAL INC\n INTEGER I,J\n LOGICAL TRNSEQ\n \n CALL INITGL ('06.01.01/04')\n \nC open PHIGS\n CALL XPOPPH (ERRFIL, MEMUN)\n CALL SETMSG ('1 2 11', 'The matrix returned by should perform the same 3D ' //\n 2 'transformation as that resulting from the ' //\n 3 'multiplication of the two specified matrices.')\n \n AIN4X4(1,1) = -2.2\n AIN4X4(1,2) = 3.3\n AIN4X4(1,3) = 4.4\n AIN4X4(1,4) = 5.5\n AIN4X4(2,1) = 0.0023\n AIN4X4(2,2) = -727.12\n AIN4X4(2,3) = 2.09\n AIN4X4(2,4) = 33.33\n AIN4X4(3,1) = 0\n AIN4X4(3,2) = 34\n AIN4X4(3,3) = 54.1\n AIN4X4(3,4) = -0.045\n AIN4X4(4,1) = 7\n AIN4X4(4,2) = 6\n AIN4X4(4,3) = 5\n AIN4X4(4,4) = 4\n \n INC = 0.0\n DO 401 I = 1,4\n DO 402 J = 1,4\n BIN4X4(I,J) = TAN(-1.56 + INC)\n INC = INC + 3.0/16.0\n402 CONTINUE\n401 CONTINUE\n \n CALL PCOM3 (AIN4X4, BIN4X4, ERRIND, ACT4X4)\n CALL CHKINQ ('pcom3', ERRIND)\n \nC Compute exp4x4 = expected array\n CALL ECOM3 (AIN4X4, BIN4X4, EXP4X4)\n \nC pass if matrices represent same transformation\n CALL IFPF (TRNSEQ(4, ACT4X4, EXP4X4))\n \n CALL SETMSG ('1 2 12', 'The matrix returned by should perform the same 2D ' //\n 2 'transformation as that resulting from the ' //\n 3 'multiplication of the two specified matrices.')\n \n AIN3X3(1,1) = -2.2\n AIN3X3(1,2) = 3.3\n AIN3X3(1,3) = 5.5\n AIN3X3(2,1) = 0.0023\n AIN3X3(2,2) = -727.12\n AIN3X3(2,3) = 33.33\n AIN3X3(3,1) = 0\n AIN3X3(3,2) = 34\n AIN3X3(3,3) = -0.045\n \n INC = 0.0\n DO 301 I = 1,3\n DO 302 J = 1,3\n BIN3X3(I,J) = TAN(-1.56 + INC)\n INC = INC + 3.0/9.0\n302 CONTINUE\n301 CONTINUE\n \n CALL PCOM (AIN3X3, BIN3X3, ERRIND, ACT3X3)\n CALL CHKINQ ('pcom', ERRIND)\n \nC Compute exp3x3 = expected array\n CALL ECOM (AIN3X3, BIN3X3, EXP3X3)\n \nC pass if matrices represent same transformation\n CALL IFPF (TRNSEQ(3, ACT3X3, EXP3X3))\n \n CALL ENDIT\n END\n", "meta": {"hexsha": "b4877bad70d91dcbe2c5f2d42705ea820ad30ac2", "size": 3431, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "third_party/Phigs/PVT/PVT_fort/06/01/01/p04.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/06/01/01/p04.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/06/01/01/p04.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": 31.7685185185, "max_line_length": 67, "alphanum_fraction": 0.4785776741, "num_tokens": 1344, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412809, "lm_q2_score": 0.7549149978955811, "lm_q1q2_score": 0.6503881209272239}} {"text": "PROGRAM LA_CHEEVD_ET_EXAMPLE\n!\n! -- LAPACK95 interface driver routine (version 3.0) --\n! UNI-C, Denmark; Univ. of Tennessee, USA; NAG Ltd., UK\n! September, 2000\n!\n! .. USE STATEMENTS\n USE LA_PRECISION, ONLY: WP => SP\n USE F95_LAPACK, ONLY: LA_HEEVD\n! .. IMPLICIT STATEMENT ..\n IMPLICIT NONE\n! .. PARAMETERS ..\n CHARACTER(LEN=*), PARAMETER :: FMT = '(4(1X,1H(,F7.3,1H,,F7.3,1H):))'\n INTEGER, PARAMETER :: NIN=5, NOUT=6\n! .. LOCAL SCALARS ..\n INTEGER :: I, J, INFO, N \n! .. LOCAL ARRAYS ..\n REAL(WP), ALLOCATABLE :: AA(:,:), W(:)\n COMPLEX(WP), ALLOCATABLE :: A(:,:)\n!\n! .. EXECUTABLE STATEMENTS ..\n!\n WRITE(NOUT,*) 'CHEEVD ET_Example Program Results.'\n READ(NIN,*) ! SKIP HEADING IN DATA FILE\n READ(NIN,*) N\n ALLOCATE ( A(N,N), AA(N,N), W(N) )\n DO I = 1, N\n READ(NIN,*) (AA(I, J), J = 1, N)\n ENDDO\n A=AA\n WRITE(NOUT,*) 'The matrix A:'\n DO I = 1, N\n WRITE(NOUT,FMT) A(I,:)\n ENDDO\n!\n WRITE(NOUT,*) '---------------------------------------------------------'\n WRITE(NOUT,*)\n WRITE ( NOUT, * )'Details of LA_CHEEVD LAPACK Subroutine Results.'\n WRITE(NOUT,*)\n!\n WRITE(NOUT,*)\n WRITE(NOUT,*) 'CALL LA_HEEVD(A, W, INFO=INFO)'\n WRITE(NOUT,*) 'ON ENTRY: A'\n WRITE(NOUT,*) ' A - the original matrix (upper triangular)'\n WRITE(NOUT,*) 'ON EXIT: A, W'\n WRITE(NOUT,*) ' A - destroyed matrix A'\n WRITE(NOUT,*) ' W - the eigenvalues in ascending order'\n A=AA\n CALL LA_HEEVD(A,W,INFO=INFO)\n WRITE(NOUT,*) 'The eigenvalues computed by LA_HEEVD:'\n WRITE(NOUT,FMT) W(:)\n WRITE(NOUT,*) 'INFO = ',INFO\n! \n WRITE(NOUT,*)\n WRITE(NOUT,*) \"CALL LA_HEEVD(A, W, 'V')\"\n WRITE(NOUT,*) 'ON ENTRY: A'\n WRITE(NOUT,*) ' A - the original matrix (upper triangular)'\n WRITE(NOUT,*) 'ON EXIT: A, W'\n WRITE(NOUT,*) ' A - orthonormal eigenvectors of the matrix A'\n WRITE(NOUT,*) ' W - the eigenvalues in ascending order'\n A=AA\n CALL LA_HEEVD(A,W,'V')\n WRITE(NOUT,*) 'The eigenvalues computed by LA_HEEVD:'\n WRITE(NOUT,FMT) W(:)\n WRITE(NOUT,*) 'The orthonormal eigenvectors computed by LA_HEEVD:'\n DO I = 1, N\n WRITE(NOUT,FMT) A(I,:)\n END DO\n! \n WRITE(NOUT,*)\n WRITE(NOUT,*) \"CALL LA_HEEVD(A, W, 'V', 'L')\"\n WRITE(NOUT,*) 'ON ENTRY: A'\n WRITE(NOUT,*) ' A - the original matrix (lower triangular)'\n WRITE(NOUT,*) 'ON EXIT: A, W'\n WRITE(NOUT,*) ' A - orthonormal eigenvectors of the matrix A'\n WRITE(NOUT,*) ' W - the eigenvalues in ascending order'\n A=AA\n CALL LA_HEEVD(A,W,'V','L')\n WRITE(NOUT,*) 'The eigenvalues computed by LA_HEEVD:'\n WRITE(NOUT,FMT) W(:)\n WRITE(NOUT,*) 'The orthonormal eigenvectors computed by LA_HEEVD:'\n DO I = 1, N\n WRITE(NOUT,FMT) A(I,:)\n END DO\n! \n WRITE(NOUT,*)\n WRITE(NOUT,*) \"CALL LA_HEEVD(A, W, UPLO='L')\"\n WRITE(NOUT,*) 'ON ENTRY: A'\n WRITE(NOUT,*) ' A - the original matrix (lower triangular)'\n WRITE(NOUT,*) 'ON EXIT: A, W'\n WRITE(NOUT,*) ' A - destroyed matrix A'\n WRITE(NOUT,*) ' W - the eigenvalues in ascending order'\n A=AA\n CALL LA_HEEVD(A,W,UPLO='L')\n WRITE(NOUT,*) 'The eigenvalues computed by LA_HEEVD:'\n WRITE(NOUT,FMT) W(:)\n! \nEND PROGRAM LA_CHEEVD_ET_EXAMPLE\n", "meta": {"hexsha": "f3252dfef8e30677677de057ea54e7a3311d1d79", "size": 3189, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "EXAMPLES2/cheevdet.f90", "max_stars_repo_name": "MattBurn/LAPACK95", "max_stars_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-12-29T15:07:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T10:09:22.000Z", "max_issues_repo_path": "EXAMPLES2/cheevdet.f90", "max_issues_repo_name": "MattBurn/LAPACK95", "max_issues_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-12-30T15:38:47.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-31T06:45:11.000Z", "max_forks_repo_path": "EXAMPLES2/cheevdet.f90", "max_forks_repo_name": "MattBurn/LAPACK95", "max_forks_repo_head_hexsha": "bcd9d4b706f4213a6a4c0ebb4521754ffeff3752", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-12-29T15:34:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-15T07:12:40.000Z", "avg_line_length": 32.2121212121, "max_line_length": 76, "alphanum_fraction": 0.5857635622, "num_tokens": 1125, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382236515258, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6503881120433498}} {"text": " program AnimatedPendulum\n**********************************************\n* Program: Simple_Pendulum_Solver *\n* Written_By: Brian Downing *\n* Fordham University *\n* Date: October 23rd, 1990 *\n**********************************************\n\n Implicit None\n*\n* Declare double precision variables.\n*\n double precision a,g,l,t,dt,w,Pi,Theta,ThetaM\n*\n* Initialize some constant values.\n*\n Pi = 4.0*ATAN(1.0)\n*\n* Clear screen and then prompt for real numbers for variables.\n*\n Call CLS\n write(5,100)\n read*,dt\n\n write(5,200)\n read*,Theta\n\n write(5,300)\n read*,l\n\n*\n* Initialize other variables.\n*\n g = 9.81\n ThetaM = Theta*Pi/180.0 \n Theta = ThetaM\n t = 0.0\n w = 0.0\n a = (-g/l)*DSIN(Theta)\n*\n* Loop until finished (angle.eq.-Theta_naught .or. omega = 0)?\n*\n Call EnterGraphicsMode\n do while (.true.)\n a = (-g/l)*DSIN(Theta)\n w = w + a*dt\n Theta = Theta + w*dt\n t = t + dt\n Call PlotBall(Theta)\n if (Theta.le.(-ThetaM)) goto 10\n enddo\n10 continue\n*\n* Print out final results.\n* \n print*,'Finished calculations.'\n write(5,20)a,w,Theta,t\n*\n* Program format statements.\n*\n20 format(1x,'Acceleration',T15,'= ',D12.4/\n 1 1x,'Omega',T15,'= ',D12.4/\n 2 1x,'Theta',T15,'= ',D12.4/\n 3 1x,'Time',T15,'= ',D12.4/)\n100 format(1x,'Enter real number for delta time in seconds: ',$)\n200 format(1x,'Enter real number for Theta in degrees: ',$)\n300 format(1x,'Enter real number for Length in meters: ',$)\n Call ExitGraphicsMode\n End\n", "meta": {"hexsha": "7630aaa0ac1848eb1acc8731b0d31f02bae0a0b6", "size": 1816, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "test/animated_pendulum_main.f", "max_stars_repo_name": "kurtsansom/ftnchek", "max_stars_repo_head_hexsha": "cb5b24689fec20e0dac4d158ae57a5b7387e9723", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-17T16:41:23.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-17T16:41:23.000Z", "max_issues_repo_path": "test/animated_pendulum_main.f", "max_issues_repo_name": "OS2World/DEV-FORTRAN-UTIL-ftnchek", "max_issues_repo_head_hexsha": "6a0369cb369312d7f4cfc96c6ce27a28e28acfd5", "max_issues_repo_licenses": ["MIT"], "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/animated_pendulum_main.f", "max_forks_repo_name": "OS2World/DEV-FORTRAN-UTIL-ftnchek", "max_forks_repo_head_hexsha": "6a0369cb369312d7f4cfc96c6ce27a28e28acfd5", "max_forks_repo_licenses": ["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.9428571429, "max_line_length": 68, "alphanum_fraction": 0.4845814978, "num_tokens": 511, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412808, "lm_q2_score": 0.7549149813536518, "lm_q1q2_score": 0.6503881066757194}} {"text": "\nmodule constants_mod\n\n! \n! Bruce Wyman\n! \n\n! \n\n! \n! Defines useful constants for Earth.\n! \n\n! \n! Constants are defined as real parameters.\n! Constants are accessed through the \"use\" statement.\n! \n\nimplicit none\nprivate\n\ncharacter(len=128) :: version='$Id: constants.f90,v 13.0 2006/03/28 21:37:37 fms Exp $'\ncharacter(len=128) :: tagname='$Name: latest $'\n!dummy variable to use in HUGE initializations\nreal :: realnumber\n\n!------------ physical constants ---------------\n! \n! radius of the earth\n! \n! \n! rotation rate of the planet (earth)\n! \n! \n! acceleration due to gravity\n! \n! \n! gas constant for dry air\n! \n! \n! RDGAS / CP_AIR\n! \n! \n! specific heat capacity of dry air at constant pressure\n! \n! \n! specific heat capacity taken from McDougall (2002) \"Potential Enthalpy ...\"\n! \n! \n! average density of sea water\n! \n! \n! reciprocal of average density of sea water\n! \n! \n! (kg/m^3)*(cal/kg/deg C)(joules/cal) = (joules/m^3/deg C)\n! \n\nreal, public, parameter :: RADIUS = 6371.0e3 \nreal, public, parameter :: OMEGA = 7.292e-5 \nreal, public, parameter :: GRAV = 9.80 \nreal, public, parameter :: RDGAS = 287.04 \nreal, public, parameter :: KAPPA = 2./7. \nreal, public, parameter :: CP_AIR = RDGAS/KAPPA \nreal, public, parameter :: CP_OCEAN = 3989.24495292815\nreal, public, parameter :: RHO0 = 1.035e3\nreal, public, parameter :: RHO0R = 1.0/RHO0\nreal, public, parameter :: RHO_CP = RHO0*CP_OCEAN\n\n!------------ water vapor constants ---------------\n! \n! gas constant for water vapor\n! \n! \n! specific heat capacity of water vapor at constant pressure\n! \n! \n! density of liquid water\n! \n! \n! latent heat of evaporation\n! \n! \n! latent heat of fusion\n! \n! \n! latent heat of sublimation\n! \n! \n! temp where fresh water freezes\n! \n\nreal, public, parameter :: RVGAS = 461.50 \nreal, public, parameter :: CP_VAPOR = 4.0*RVGAS\nreal, public, parameter :: DENS_H2O = 1000. \nreal, public, parameter :: HLV = 2.500e6 \nreal, public, parameter :: HLF = 3.34e5 \nreal, public, parameter :: HLS = HLV + HLF\nreal, public, parameter :: TFREEZE = 273.16 \n\n!-------------- radiation constants -----------------\n\n! \n! molecular weight of air \n! \n! \n! molecular weight of water\n! \n! \n! molecular weight of ozone\n! \n! \n! diffusivity factor\n! \n! \n! seconds in a day\n! \n! \n! Avogadro's number \n! \n! \n! mean sea level pressure\n! \n! \n! mean sea level pressure\n! \n\nreal, public, parameter :: WTMAIR = 2.896440E+01\nreal, public, parameter :: WTMH2O = WTMAIR*(RDGAS/RVGAS) !pjp OK to change value because not used yet.\nreal, public, parameter :: WTMO3 = 47.99820E+01\nreal, public, parameter :: DIFFAC = 1.660000E+00\nreal, public, parameter :: SECONDS_PER_DAY = 8.640000E+04\nreal, public, parameter :: AVOGNO = 6.023000E+23\nreal, public, parameter :: PSTD = 1.013250E+06\nreal, public, parameter :: PSTD_MKS = 101325.0\n!real, public, parameter :: REARTH = 6.356766E+08 !pjp Not used anywhere. \n\n! \n! factor used to convert flux divergence to heating rate in degrees per day\n! \n! \n! factor used to convert flux divergence to heating rate in degrees per day\n! \n! \n! mixing ratio of molecular oxygen in air\n! \n! \n! reference atmospheric density\n! \n! \n! minimum value allowed as argument to log function\n! \n\nreal, public, parameter :: RADCON = ((1.0E+02*GRAV)/(1.0E+04*CP_AIR))*SECONDS_PER_DAY\nreal, public, parameter :: RADCON_MKS = (GRAV/CP_AIR)*SECONDS_PER_DAY\nreal, public, parameter :: O2MIXRAT = 2.0953E-01\nreal, public, parameter :: RHOAIR = 1.292269\nreal, public, parameter :: ALOGMIN = -50.0\n\n!------------ miscellaneous constants ---------------\n! \n! Stefan-Boltzmann constant\n! \n! \n! Von Karman constant\n! \n! \n! ratio of circle circumference to diameter\n! \n! \n! degrees per radian\n! \n! \n! radians per degree\n! \n! \n! equal to RAD_TO_DEG. Named RADIAN for backward compatability.\n! \n! \n! converts rho*g*z (in mks) to dbars: 1dbar = 10^4 (kg/m^3)(m/s^2)m\n! \n! \n! degrees Kelvin at zero Celsius\n! \n! \n! a small number to prevent divide by zero exceptions\n! \n\nreal, public, parameter :: STEFAN = 5.6734e-8 \nreal, public, parameter :: VONKARM = 0.40 \nreal, public, parameter :: PI = 3.14159265358979323846\nreal, public, parameter :: RAD_TO_DEG=180./PI\nreal, public, parameter :: DEG_TO_RAD=PI/180.\nreal, public, parameter :: RADIAN = RAD_TO_DEG\nreal, public, parameter :: C2DBARS = 1.e-4\nreal, public, parameter :: KELVIN = 273.15\nreal, public, parameter :: EPSLN = 1.0e-40\n!-----------------------------------------------------------------------\n! version and tagname published\n! so that write_version_number can be called for constants_mod by fms_init\npublic :: version, tagname\n!-----------------------------------------------------------------------\npublic :: constants_init\n\ncontains\n\nsubroutine constants_init\n\n! dummy routine.\n\nend subroutine constants_init\n\nend module constants_mod\n\n! \n\n! \n! 1. Renaming of constants.\n! \n! \n! 2. Additional constants.\n! \n! \n! Constants have been declared as type REAL, PARAMETER.\n!\n! The value a constant can not be changed in a users program.\n! New constants can be defined in terms of values from the\n! constants module using a parameter statement.

\n!\n! The name given to a particular constant may be changed.

\n!\n! Constants can be used on the right side on an assignment statement\n! (their value can not be reassigned). \n!\n!\n!\n!
\n!    use constants_mod, only:  TFREEZE, grav_new => GRAV\n!    real, parameter :: grav_inv = 1.0 / grav_new\n!    tempc(:,:,:) = tempk(:,:,:) - TFREEZE\n!    geopotential(:,:) = height(:,:) * grav_new\n!
\n!
\n!
\n\n!
\n\n", "meta": {"hexsha": "b5a3f7d6da2805f89081dccbf499a22bc0eb2be2", "size": 8763, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "fms_dynamical_cores/_fortran/src/shared/constants/constants.f90", "max_stars_repo_name": "JoyMonteiro/FMSDynamicalCore", "max_stars_repo_head_hexsha": "b46a8943de28f8b16a1d36f5607f10e928ed6667", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-05-23T13:35:20.000Z", "max_stars_repo_stars_event_max_datetime": "2018-05-23T13:35:20.000Z", "max_issues_repo_path": "fms_dynamical_cores/_fortran/src/shared/constants/constants.f90", "max_issues_repo_name": "JoyMonteiro/fms_dynamical_cores", "max_issues_repo_head_hexsha": "b46a8943de28f8b16a1d36f5607f10e928ed6667", "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": "fms_dynamical_cores/_fortran/src/shared/constants/constants.f90", "max_forks_repo_name": "JoyMonteiro/fms_dynamical_cores", "max_forks_repo_head_hexsha": "b46a8943de28f8b16a1d36f5607f10e928ed6667", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.3346774194, "max_line_length": 119, "alphanum_fraction": 0.6510327513, "num_tokens": 2911, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381952105442, "lm_q2_score": 0.7549149868676283, "lm_q1q2_score": 0.6503880953233281}} {"text": "module damageModelsNewLib\nuse funcAux\n\nimplicit none\n\ncontains\n\n\nsubroutine getH(H,Hder,r,damagePar)\n\treal*8 , intent(out) :: H, Hder\n\treal*8, intent(in) :: r , damagePar(:)\n\tinteger :: damageModel\n\t\n\tdamageModel = nint(damagePar(2))\n\t\n\tselect case(damageModel)\n\t\n\t\tcase(1)\n\t\t\tcall exp1Reg(H,Hder,r,damagePar)\n\t\t\n\t\tcase(2)\n\t\t\tcall exp2Reg(H,Hder,r,damagePar)\n\t\t\t\n\t\tcase(3)\n\t\t\tcall LinReg(H,Hder,r,damagePar)\t\n\t\t\n\t\tcase(4)\n\t\t\tcall exp3dinf(H,Hder,r,damagePar)\t\t\t\n\t\tcase default\n\t\t\n\t\t\tH = 0.0d0\n\t\t\t\n\tend select\n\nend subroutine\n\nsubroutine exp1Reg(H,Hder,r,damagePar)\n\treal*8 , intent(out) :: H , Hder\n\treal*8, intent(in) :: r , damagePar(:)\n\treal*8 :: r0, Gf, lmu, H0\n\t\n\tr0 = damagePar(3)\n\tGf = damagePar(4)\n\tlmu = damagePar(5)\n\t\n!~ \tH0 = (0.5d0-Gf/(r0*r0*lmu))**(-1.0d0)\n!~ \twrite(0,*) 'H0 == ' , H0\n\t\n\tH0 = -r0*r0*lmu/Gf\n\t\n\tH = H0*dexp(H0*(r- r0)/r0)\n\n\tHder = H*(H0/r0)\n\nend subroutine\n\n\nsubroutine exp2Reg(H,Hder,r,damagePar)\n\treal*8 , intent(out) :: H , Hder\n\treal*8, intent(in) :: r , damagePar(:)\n\treal*8 :: r0, Gf, lmu, beta\n\t\n\tr0 = damagePar(3)\n\tGf = damagePar(4)\n\tlmu = damagePar(5)\n\t\t\n\tbeta = 0.5*(-r0 + dsqrt((4.0d0*Gf/lmu)-r0*r0))\n\twrite(0,*) beta\n\t\n\tH = dexp(-(r- r0)/beta)*(1.0d0 - r/beta)\n\tHder = - dexp(-(r-r0)/beta)*(2.0d0 - r/beta)/beta\n\t\n\t\t\n\twrite(0,*) r0,Gf,lmu\n\t\n\tpause \n\nend subroutine\n\nsubroutine LinReg(H,Hder,r,damagePar)\n\treal*8 , intent(out) :: H, Hder\n\treal*8, intent(in) :: r , damagePar(:)\n\treal*8 :: r0, Gf, lmu, H0\n\n\tr0 = damagePar(3)\n\tGf = damagePar(4)\n\tlmu = damagePar(5)\n\t\n\tH0 = (1.0 - 2.0*Gf/(r0*r0*lmu))**(-1.0)\n\n\tH = H0\n\tHder = 0.0d0\n\t\n\twrite(0,*) r0,Gf,lmu\n\t\n\tpause \n\nend subroutine\n\n\nsubroutine exp3dinf(H,Hder,r,damagePar)\n\treal*8 , intent(out) :: H , Hder\n\treal*8, intent(in) :: r , damagePar(:)\n\treal*8 :: r0, dinf, alpha, E\n\t\n\tr0 = damagePar(3)\n\talpha = damagePar(4)\n\tdinf = damagePar(5)\n\t\n\tE = dexp(-alpha*(r- r0)/r0)\n\t\n\tH = E*dinf*(1.0d0 - alpha*r/r0) + 1.0d0 - dinf\n\t\n\tHder = - (alpha*E*dinf/r0)*(2.0d0 - alpha*r/r0)\n\t\n\twrite(0,*) r0,alpha, dinf\n\t\n\tpause \n\nend subroutine\n\n\t\nend module\n\n", "meta": {"hexsha": "49c6d62cca24826a1af4ec5b5e0c142eea494d95", "size": 2036, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/damage/damageModelsNewLib.f90", "max_stars_repo_name": "felipefr/gpmaterials", "max_stars_repo_head_hexsha": "db9c4b2c348a85c1af01d8d3256a243fb7b59a21", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-08-24T22:15:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-23T03:30:22.000Z", "max_issues_repo_path": "src/damage/damageModelsNewLib.f90", "max_issues_repo_name": "felipefr/gpmaterials", "max_issues_repo_head_hexsha": "db9c4b2c348a85c1af01d8d3256a243fb7b59a21", "max_issues_repo_licenses": ["MIT"], "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/damage/damageModelsNewLib.f90", "max_forks_repo_name": "felipefr/gpmaterials", "max_forks_repo_head_hexsha": "db9c4b2c348a85c1af01d8d3256a243fb7b59a21", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-18T02:23:44.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T02:23:44.000Z", "avg_line_length": 16.288, "max_line_length": 50, "alphanum_fraction": 0.6011787819, "num_tokens": 845, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072386, "lm_q2_score": 0.7090191399336402, "lm_q1q2_score": 0.6503851459641511}} {"text": "\tFUNCTION PR_TMST ( thte, pres, tguess )\nC************************************************************************\nC* PR_TMST \t\t\t\t\t\t\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* This function computes TMST from THTE, PRES, TGUESS. TMST is the\t*\nC* parcel temperature at level PRES on a specified moist adiabat \t*\nC* (THTE). The computation is an iterative Newton-Raphson technique\t*\nC* of the form:\t\t\t\t\t\t\t\t*\nC*\t *\nC* x = x(guess) + [ f( x ) - f( x(guess) ) ] / f'( x(guess) )\t\t*\nC*\t *\nC* f' is approximated with finite differences\t\t\t*\nC* f' = [ f( x(guess) + 1 ) - f( x(guess) ) ] / 1\t\t\t*\nC*\t *\nC* If TGUESS is 0, a reasonable first guess will be made.\t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Convergence is not guaranteed for extreme input values. If the\t*\nC* computation does not converge after 100 iterations, the missing\t*\nC* data value will be returned.\t\t\t\t\t\t*\nC*\t *\nC* REAL PR_TMST ( THTE, PRES, TGUESS ) \t\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Input parameters:\t\t\t\t\t\t\t*\nC*\tTHTE \t\tREAL\t\tEquivalent potential temp in K\t*\nC*\tPRES \tREAL \tPressure in millibars\t\t*\nC*\tTGUESS \tREAL \tFirst guess temperature in K\t*\nC*\t\t\t\t\t\t\t\t\t*\nC* Output parameters:\t\t\t\t\t\t\t*\nC*\tPR_TMST\t\tREAL\t\tParcel temperature in Kelvin\t*\nC**\t\t\t\t\t\t\t\t\t*\nC* Log:\t\t\t\t\t\t\t\t\t*\nC* P. Kocin\t\t1980 Orginal source\t\t\t\t*\nC* M. Goodman/RDS\t 9/84\tModified prologue\t\t\t*\nC* G. Huffman/GSC\t 8/88\tRecode (retain Newton-Raphson concept);\t*\nC*\t\t\t\tuse Mark Handel (MIT) first guess\t*\nC* M. desJardins/GSFC\t 8/90\tMove tguess into temp variable\t\t*\nC* M. Linda/GSC\t\t 9/97\tCorrected right border of prologue\t*\nC************************************************************************\n INCLUDE 'GEMPRM.PRM'\n INCLUDE 'ERMISS.FNC'\nC------------------------------------------------------------------------\n\tIF ( ERMISS ( thte ) .or. ERMISS ( pres )\n +\t .or. ERMISS ( tguess ) .or. ( thte .le. 0. )\n + .or. ( pres .le. 0 ) .or. ( tguess .lt. 0. ) ) THEN\n\t PR_TMST = RMISSD\n\t RETURN\n\tEND IF\nC\nC*\tMove tguess into another variable.\nC\n\ttg = tguess\nC\nC*\tIf TGUESS is passed as 0. it is computed from an MIT scheme.\nC\n\tIF ( tg .eq. 0. ) tg =\n * \t(thte - .5 * ( MAX ( thte-270., 0. ) ) ** 1.05 )\n * \t\t* ( pres / 1000. ) ** .2\nC\nC*\tSet convergence and initial guess in degrees C.\nC\n\tepsi = .01\n\ttgnu = PR_TMKC ( tg )\nC\nC*\tSet a limit of 100 iterations. Compute TENU, TENUP, the\nC*\tTHTE's at, one degree above the guess temperature.\nC\n\tDO i = 1, 100\n\t tgnup = tgnu + 1.\n\t tenu = PR_THTE ( pres, tgnu, tgnu )\n\t tenup = PR_THTE ( pres, tgnup, tgnup )\nC\nC*\t Check that the THTE's exist.\nC\n\t IF ( ( ERMISS ( tenu ) ) .or. ( ERMISS ( tenup ) ) ) THEN\n\t PR_TMST = RMISSD\n\t RETURN\n\t END IF\nC\nC*\t Compute the correction, DELTG; return on convergence.\nC\n\t cor = ( thte - tenu ) / ( tenup - tenu )\n\t tgnu = tgnu + cor\n\t IF ( ( cor .lt. epsi ) .and. ( -cor .lt. epsi ) ) THEN\n\t PR_TMST = PR_TMCK ( tgnu )\n\t RETURN\n\t END IF\n\tEND DO\nC\nC*\tFailed to converge - return missing.\nC\n\tPR_TMST = RMISSD\n\tRETURN\n\tEND\n", "meta": {"hexsha": "88197081b7293e014f6146933bbc3fd5af44b4c6", "size": 3274, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "gempak/source/prmcnvlib/pr/prtmst.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/prtmst.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/prtmst.f", "max_forks_repo_name": "oxelson/gempak", "max_forks_repo_head_hexsha": "e7c477814d7084c87d3313c94e192d13d8341fa1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 27, "max_forks_repo_forks_event_min_datetime": "2016-06-06T21:55:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T18:23:28.000Z", "avg_line_length": 34.829787234, "max_line_length": 73, "alphanum_fraction": 0.4963347587, "num_tokens": 1050, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026573249612, "lm_q2_score": 0.7090191276365462, "lm_q1q2_score": 0.6503851298752297}} {"text": "c\nc************************\nc \n subroutine chdec(b,a,n,ier)\n \nc cholesky decomposition of real symmetric matrix; b is input\nc matrix of order n in symmetric storage mode (requires array of\nc length n*(n+1)/2 in calling routine); a is output (in same form)\nc of lower triangular matrix\n \n real a(*),b(*)\n \n ier=0\n \n do 30 i=1,n\n ii=(i-1)*i/2\n \n do 15 j=1,i-1\n jj=(j-1)*j/2\n t=b(ii+j)\n i1=ii\n \n do 10 k=1,j-1\n i1=i1+1\n jj=jj+1\n10 t=t-a(i1)*a(jj)\n \n15 a(ii+j)=t/a(jj+1)\n \n i1=ii\n t=b(ii+i)\n \n do 20 k=1,i-1\n i1=i1+1\n20 t=t-a(i1)*a(i1)\n \n if(t.lt.0) then\n ier=-1\n return\n end if\n \n30 a(ii+i)=sqrt(t)\n \n return\n end\n", "meta": {"hexsha": "4f35c5c467118308f94e1565258af5af10a90a58", "size": 866, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "iris_mt_scratch/egbert_codes-20210121T193218Z-001/egbert_codes/EMTF/T/chdec.f", "max_stars_repo_name": "simpeg-research/iris-mt-scratch", "max_stars_repo_head_hexsha": "ea458f253071db513fd0731118a2a7452a725944", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "iris_mt_scratch/egbert_codes-20210121T193218Z-001/egbert_codes/EMTF/T/chdec.f", "max_issues_repo_name": "simpeg-research/iris-mt-scratch", "max_issues_repo_head_hexsha": "ea458f253071db513fd0731118a2a7452a725944", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 19, "max_issues_repo_issues_event_min_datetime": "2020-12-23T17:55:48.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-24T21:01:05.000Z", "max_forks_repo_path": "iris_mt_scratch/egbert_codes-20210121T193218Z-001/egbert_codes/EMTF/T/chdec.f", "max_forks_repo_name": "simpeg-research/iris-mt-scratch", "max_forks_repo_head_hexsha": "ea458f253071db513fd0731118a2a7452a725944", "max_forks_repo_licenses": ["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.8260869565, "max_line_length": 72, "alphanum_fraction": 0.4145496536, "num_tokens": 280, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094174159127, "lm_q2_score": 0.7279754548076477, "lm_q1q2_score": 0.6503073294273038}} {"text": "!-*- mode: compilation; default-directory: \"/tmp/\" -*-\n!Compilation started at Mon Jun 3 18:07:59\n!\n!a=./f && make $a && OMP_NUM_THREADS=2 $a\n!gfortran -std=f2008 -Wall -fopenmp -ffree-form -fall-intrinsics -fimplicit-none f.f08 -o f\n! -7.80250048E-06 350 10\n! 90.0000000 90 180 270 360\n! 19.9999962 10 20 30\n!\n!Compilation finished at Mon Jun 3 18:07:59\n\nprogram average_angles\n !real(kind=8), parameter :: TAU = 6.283185307179586232 ! http://tauday.com/\n !integer, dimension(13), parameter :: test_data = (/2,350,10, 4,90,180,270,360, 3,10,20,30, 0/)\n !integer :: i, j, n\n !complex(kind=16) :: some\n !real(kind=8) :: angle\n real, parameter :: TAU = 6.283185307179586232 ! http://tauday.com/\n integer, dimension(13), parameter :: test_data = (/2,350,10, 4,90,180,270,360, 3,10,20,30, 0/)\n integer :: i, j, n\n complex :: some\n real :: angle\n i = 1\n n = int(test_data(i))\n do while (0 .lt. n)\n some = 0\n do j = 1, n\n angle = (TAU/360)*test_data(i+j)\n some = some + cmplx(cos(angle), sin(angle))\n end do\n some = some / n\n write(6,*)(360/TAU)*atan2(aimag(some), real(some)),test_data(i+1:i+n)\n i = i + n + 1\n n = int(test_data(i))\n end do\nend program average_angles\n", "meta": {"hexsha": "7e3875769dca3500745898847d8d04ef5d413c92", "size": 1300, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "Task/Averages-Mean-angle/Fortran/averages-mean-angle.f", "max_stars_repo_name": "LaudateCorpus1/RosettaCodeData", "max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_stars_repo_licenses": ["Info-ZIP"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-11-09T22:08:38.000Z", "max_stars_repo_stars_event_max_datetime": "2018-11-09T22:08:38.000Z", "max_issues_repo_path": "Task/Averages-Mean-angle/Fortran/averages-mean-angle.f", "max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_issues_repo_licenses": ["Info-ZIP"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Task/Averages-Mean-angle/Fortran/averages-mean-angle.f", "max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData", "max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d", "max_forks_repo_licenses": ["Info-ZIP"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-11-09T22:08:40.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-09T22:08:40.000Z", "avg_line_length": 35.1351351351, "max_line_length": 97, "alphanum_fraction": 0.5838461538, "num_tokens": 484, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543488, "lm_q2_score": 0.7279754548076477, "lm_q1q2_score": 0.6503073211563642}} {"text": "!********************************************************************************\n! UNITY: Compare FPML against Polzers and AMVW on roots of unity.\n! Author: Thomas R. Cameron, Davidson College\n! Last Modified: 11 Novemeber 2018\n!********************************************************************************\n! The speed and accuracy of FPML is compared against Polzeros and AMVW for\n! computing the roots of unity via the polynomial z^n-1.\n!********************************************************************************\nprogram unity\n use fpml\n use poly_zeroes\n implicit none\n ! read in variables\n character(len=32) :: arg\n integer :: flag, startDegree, endDegree, itnum\n ! testing variables\n integer :: deg, it, j, clock_rate, clock_start, clock_stop\n real(kind=dp), parameter :: pi = 3.141592653589793_dp\n real(kind=dp), dimension(:,:), allocatable :: results\n complex(kind=dp), dimension(:), allocatable :: exact_roots\n ! FPML variables\n integer, parameter :: nitmax=30\n integer, dimension(:), allocatable :: conv\n real(kind=dp), dimension(:), allocatable :: berr, cond \n complex(kind=dp), dimension(:), allocatable :: p, roots\n ! Polzeros variables\n integer :: iter\n logical, dimension(:), allocatable :: h\n real(kind=dp), dimension(:), allocatable :: radius\n complex(kind=dp), dimension(:), allocatable :: zeros\n ! AMVW variables\n real(kind=dp), dimension(:), allocatable :: residuals\n complex(kind=dp), dimension(:), allocatable :: coeffs, eigs\n \n ! read in optional arguments\n call get_command_argument(1,arg,status=flag)\n if(flag==0) then\n read(arg, '(I10)') startDegree\n else\n startDegree=80\n end if\n call get_command_argument(2,arg,status=flag)\n if(flag==0) then\n read(arg, '(I10)') endDegree\n else\n endDegree=5120\n end if\n call get_command_argument(3,arg,status=flag)\n if(flag==0) then\n read(arg, '(I10)') itnum\n else\n itnum=128\n end if\n \n ! Testing: roots of unity\n open(unit=1,file=\"data_files/unity.dat\")\n write(1,'(A)') 'Degree, FPML_time, FPML_err, Polzeros_time, Polzeros_err, AMVW_time, AMVW_err'\n allocate(results(itnum,6))\n deg=startDegree\n do while(deg<=endDegree)\n write(1,'(I10)', advance='no') deg\n write(1,'(A)', advance='no') ','\n allocate(exact_roots(deg))\n allocate(p(deg+1), roots(deg), berr(deg), cond(deg), conv(deg))\n allocate(zeros(deg), radius(deg), h(deg+1))\n allocate(coeffs(deg+1), eigs(deg), residuals(deg))\n ! polynomial and roots\n p(1) = -1.0_dp\n p(2:deg) = 0.0_dp\n p(deg+1) = 1.0_dp\n coeffs = (/ (p(deg-j+1), j=0,deg)/)\n exact_roots = (/ (cmplx(cos(2*pi*j/deg),sin(2*pi*j/deg),kind=dp), j=1,deg)/)\n do it=1,itnum\n ! FPML\n call system_clock(count_rate=clock_rate)\n call system_clock(count=clock_start)\n call main(p, deg, roots, berr, cond, conv, nitmax)\n call system_clock(count=clock_stop)\n results(it,1) = dble(clock_stop-clock_start)/dble(clock_rate)\n results(it,2) = maxrel_fwderr(roots, exact_roots, deg)\n ! Polzeros\n call system_clock(count_rate=clock_rate)\n call system_clock(count=clock_start)\n call polzeros(deg, p, eps, big, small, nitmax, zeros, radius, h, iter)\n call system_clock(count=clock_stop)\n results(it,3)=dble(clock_stop-clock_start)/dble(clock_rate)\n results(it,4) = maxrel_fwderr(zeros, exact_roots, deg)\n ! AMVW\n call system_clock(count_rate=clock_rate)\n call system_clock(count=clock_start)\n call z_poly_roots(deg, coeffs, eigs, residuals, flag)\n call system_clock(count=clock_stop)\n results(it,5)=dble(clock_stop-clock_start)/dble(clock_rate)\n results(it,6) = maxrel_fwderr(eigs, exact_roots, deg)\n end do\n deallocate(exact_roots, p, roots, berr, cond, conv, zeros, radius, h, coeffs, eigs, residuals)\n ! write results to file\n write(1,'(ES15.2)', advance='no') sum(results(1:itnum,1))/itnum\n write(1,'(A)', advance='no') ','\n write(1,'(ES15.2)', advance='no') sum(results(1:itnum,2))/itnum\n write(1,'(A)', advance='no') ','\n write(1,'(ES15.2)', advance='no') sum(results(1:itnum,3))/itnum\n write(1,'(A)', advance='no') ','\n write(1,'(ES15.2)', advance='no') sum(results(1:itnum,4))/itnum\n write(1,'(A)', advance='no') ','\n write(1,'(ES15.2)', advance='no') sum(results(1:itnum,5))/itnum\n write(1,'(A)', advance='no') ','\n write(1,'(ES15.2)') sum(results(1:itnum,6))/itnum\n ! update deg and itnum\n deg=2*deg\n itnum=itnum/2\n end do\n deallocate(results)\n ! close file\n close(1)\ncontains\n !************************************************\n ! maxrel_fwderr *\n !************************************************\n ! Compute the maximum relative forward error\n ! in the approximation roots to exact_roots.\n !************************************************\n function maxrel_fwderr(roots, exact_roots, deg) result(res)\n implicit none\n ! argument variables\n integer, intent(in) :: deg\n complex(kind=dp), intent(in) :: exact_roots(:)\n complex(kind=dp), intent(inout) :: roots(:)\n ! local variables\n integer :: i, j, k\n real(kind=dp) :: hd, res\n \n ! main\n res = 0.0_dp\n do i=1,deg\n hd = abs(roots(i)-exact_roots(1))\n j = 1\n do k = 2,deg\n if (hd>abs(roots(i)-exact_roots(k))) then\n hd = abs(roots(i)-exact_roots(k))\n j = k\n end if\n end do\n if (res amrex_real\n implicit none\n \n real(rt) , parameter :: pi = 3.1415926535897932384626e0_rt\n real(rt) :: bk_const = a_rad * 15.e0_rt/pi**4\n ! = 8 * pi * k**4 / (c**3 * h**3)\n real(rt) :: magic_const = pi**4/15.e0_rt\n integer, parameter :: Ncoefs = 8\n real(rt) , dimension(0:Ncoefs) :: coefs = &\n (/ 1.e0_rt/60.e0_rt, -1.e0_rt/5040.e0_rt, 1.e0_rt/272160.e0_rt, -1.e0_rt/13305600.e0_rt, &\n 1.e0_rt/622702080.e0_rt, -691.e0_rt/19615115520000.e0_rt, 1.e0_rt/1270312243200.e0_rt, &\n -3617.e0_rt/202741834014720000.e0_rt, 43867.e0_rt/107290978560589824000.e0_rt /)\n real(rt) , parameter :: tol = 1.0e-10_rt\n\n real(rt) , parameter :: xmagic = 2.061981e0_rt\n real(rt) , parameter :: xsmall = 1.e-5_rt\n real(rt) , parameter :: xlarge = 100.e0_rt\n \n private\n public :: BdBdTIndefInteg, BIndefInteg, BGroup\n\n contains\n\n subroutine BdBdTIndefInteg(T, nu, B, dBdT)\n use amrex_fort_module, only : rt => amrex_real\n real(rt) , intent(in) :: T, nu\n real(rt) , intent(out) :: B, dBdT\n real(rt) :: x, integ, part\n \n x = hplanck*nu/(k_B*T)\n\n if (x .gt. xlarge) then\n B = a_rad * T**4\n dBdT = 4.e0_rt * a_rad * T**3\n else if ( x .lt. xsmall) then\n B = 0.e0_rt\n dBdT = 0.e0_rt\n else\n if (x .gt. xmagic) then\n integ = integlarge(x)\n else\n integ = integsmall(x)\n end if\n part = x**4/(exp(x) - 1.e0_rt)\n B = bk_const*T**4 * integ\n dBdT = bk_const*T**3 * (4.*integ - part)\n end if\n end subroutine BdBdTIndefInteg\n\n function BIndefInteg(T, nu)\n use amrex_fort_module, only : rt => amrex_real\n real(rt) BIndefInteg\n real(rt) , intent(in) :: T, nu\n real(rt) :: x, integ\n \n x = hplanck*nu/(k_B*T)\n\n if (x .gt. xlarge) then\n BIndefInteg = a_rad * T**4\n else if ( x .lt. xsmall) then\n BIndefInteg = 0.e0_rt\n else\n if (x .gt. xmagic) then\n integ = integlarge(x)\n else\n integ = integsmall(x)\n end if\n BIndefInteg = bk_const*T**4 * integ\n end if\n end function BIndefInteg\n\n function BGroup(T, nu0, nu1)\n use amrex_fort_module, only : rt => amrex_real\n real(rt) BGroup\n real(rt) , intent(in) :: T, nu0, nu1\n BGroup = BIndefInteg(T,nu1) - BIndefInteg(T,nu0)\n end function BGroup\n \n function Li(n, z)\n use amrex_fort_module, only : rt => amrex_real\n integer, intent(in) :: n\n real(rt) , intent(in) :: z\n real(rt) :: Li, t\n integer :: k\n integer, parameter :: kmax = 18\n Li = z\n do k = 2, kmax\n t = z**k / k**n\n Li = Li + t\n if (t/Li .lt. tol) then\n exit\n end if\n end do\n end function Li\n\n function integlarge(x)\n use amrex_fort_module, only : rt => amrex_real\n real(rt) , intent(in) :: x\n real(rt) :: integlarge, z\n z = exp(-x)\n integlarge = magic_const & \n - (x**3 * Li(1,z) + 3.e0_rt * x**2 * Li(2,z) &\n + 6.e0_rt* x * Li(3,z) + 6.e0_rt * Li(4,z))\n end function integlarge\n\n function integsmall(x)\n use amrex_fort_module, only : rt => amrex_real\n real(rt) , intent(in) :: x\n real(rt) :: integsmall, t\n integer :: i\n real(rt) :: x2, x3, xfoo\n x2 = x**2\n x3 = x**3\n integsmall = x3/3.e0_rt - x2**2/8.e0_rt\n xfoo = x3\n do i = 0, Ncoefs\n xfoo = xfoo * x2\n t = coefs(i) * xfoo\n integsmall = integsmall + t\n if (abs(t/integsmall) .lt. tol) then\n exit\n end if\n end do\n end function integsmall\n\nend module blackbody_module\n", "meta": {"hexsha": "a63fd2fcc62f6ebc2b484c88373b39d0f91b2651", "size": 4182, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "Source/radiation/blackbody.f90", "max_stars_repo_name": "yingtchen/Castro", "max_stars_repo_head_hexsha": "5e9bd2f7a699a45447b92a1c9c3064f6c2e3552c", "max_stars_repo_licenses": ["BSD-3-Clause-LBNL"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-06-05T19:23:47.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-05T19:23:47.000Z", "max_issues_repo_path": "Source/radiation/blackbody.f90", "max_issues_repo_name": "yingtchen/Castro", "max_issues_repo_head_hexsha": "5e9bd2f7a699a45447b92a1c9c3064f6c2e3552c", "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": "Source/radiation/blackbody.f90", "max_forks_repo_name": "yingtchen/Castro", "max_forks_repo_head_hexsha": "5e9bd2f7a699a45447b92a1c9c3064f6c2e3552c", "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": 30.9777777778, "max_line_length": 97, "alphanum_fraction": 0.5260640842, "num_tokens": 1426, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735663, "lm_q2_score": 0.7279754489059775, "lm_q1q2_score": 0.6503073117488766}} {"text": "!-----------------------------------------------------------------------\n subroutine eval(dimn,x,rslt)\n integer dimn\n real*8 x(3)\n real*8 rslt\n\n rslt=tanh(x(1)+0.1)\n if (dimn>1) then\n rslt=rslt+atan(x(2)+0.2)\n endif\n if (dimn>2) then \n rslt=rslt+exp(-(x(3)+0.3)*(x(3)+0.3))\n endif\n\n end\n!-----------------------------------------------------------------------\n program test\n implicit none\n include 'ceed/fortran.h'\n\n integer ceed,err\n integer x,xq,u,uq,ones,gtposeones\n integer bxl,bug\n integer dimn,d\n integer i\n integer p\n integer q\n parameter(p=8)\n parameter(q=10)\n integer maxdim\n parameter(maxdim=3)\n integer qdimnmax\n parameter(qdimnmax=q**maxdim)\n integer pdimnmax\n parameter(pdimnmax=p**maxdim)\n integer xdimmax\n parameter(xdimmax=2**maxdim)\n integer pdimn,qdimn,xdim\n\n real*8 xx(xdimmax*maxdim)\n real*8 xxx(maxdim)\n real*8 xxq(pdimnmax*maxdim)\n real*8 uuq(qdimnmax*maxdim)\n real*8 uu(pdimnmax)\n real*8 ggtposeones(pdimnmax)\n real*8 sum1\n real*8 sum2\n integer dimxqdimn\n integer*8 uoffset,xoffset,offset1,offset2,offset3\n\n character arg*32\n\n call getarg(1,arg)\n call ceedinit(trim(arg)//char(0),ceed,err)\n\n do dimn=1,maxdim\n qdimn=q**dimn\n pdimn=p**dimn\n xdim=2**dimn\n dimxqdimn=dimn*qdimn\n sum1=0\n sum2=0\n\n do d=0,dimn-1\n do i=1,xdim\n if ((mod(i-1,2**(dimn-d))/(2**(dimn-d-1))).ne.0) then\n xx(d*xdim+i)=1\n else\n xx(d*xdim+i)=-1\n endif\n enddo\n enddo\n\n call ceedvectorcreate(ceed,xdim*dimn,x,err)\n xoffset=0\n call ceedvectorsetarray(x,ceed_mem_host,ceed_use_pointer,xx,xoffset,err)\n call ceedvectorcreate(ceed,pdimn*dimn,xq,err)\n call ceedvectorsetvalue(xq,0.d0,err)\n call ceedvectorcreate(ceed,pdimn,u,err)\n call ceedvectorcreate(ceed,qdimn*dimn,uq,err)\n call ceedvectorsetvalue(uq,0.d0,err)\n call ceedvectorcreate(ceed,qdimn*dimn,ones,err)\n call ceedvectorsetvalue(ones,1.d0,err)\n call ceedvectorcreate(ceed,pdimn,gtposeones,err)\n call ceedvectorsetvalue(gtposeones,0.d0,err)\n\n call ceedbasiscreatetensorh1lagrange(ceed,dimn,dimn,2,p,&\n & ceed_gauss_lobatto,bxl,err)\n call ceedbasisapply(bxl,1,ceed_notranspose,ceed_eval_interp,x,xq,err)\n\n call ceedvectorgetarrayread(xq,ceed_mem_host,xxq,offset1,err)\n do i=1,pdimn\n do d=0,dimn-1\n xxx(d+1)=xxq(d*pdimn+i+offset1)\n enddo\n call eval(dimn,xxx,uu(i))\n enddo\n call ceedvectorrestorearrayread(xq,xxq,offset1,err)\n uoffset=0\n call ceedvectorsetarray(u,ceed_mem_host,ceed_use_pointer,uu,uoffset,err)\n\n call ceedbasiscreatetensorh1lagrange(ceed,dimn,1,p,q,ceed_gauss,bug,err)\n\n call ceedbasisapply(bug,1,ceed_notranspose,ceed_eval_grad,u,uq,err)\n call ceedbasisapply(bug,1,ceed_transpose,ceed_eval_grad,ones,&\n & gtposeones,err)\n\n call ceedvectorgetarrayread(gtposeones,ceed_mem_host,ggtposeones,&\n & offset1,err)\n call ceedvectorgetarrayread(u,ceed_mem_host,uu,offset2,err)\n call ceedvectorgetarrayread(uq,ceed_mem_host,uuq,offset3,err)\n do i=1,pdimn\n sum1=sum1+ggtposeones(i+offset1)*uu(i+offset2)\n enddo\n do i=1,dimxqdimn\n sum2=sum2+uuq(i+offset3)\n enddo\n call ceedvectorrestorearrayread(gtposeones,ggtposeones,offset1,err)\n call ceedvectorrestorearrayread(u,uu,offset2,err)\n call ceedvectorrestorearrayread(uq,uuq,offset3,err)\n if(abs(sum1-sum2) > 1.0D-10) then\n! LCOV_EXCL_START\n write(*,'(A,I1,A,F12.6,A,F12.6)')'[',dimn,'] Error: ',sum1, ' != ',&\n & sum2\n! LCOV_EXCL_STOP\n endif\n\n call ceedvectordestroy(x,err)\n call ceedvectordestroy(xq,err)\n call ceedvectordestroy(u,err)\n call ceedvectordestroy(uq,err)\n call ceedvectordestroy(ones,err)\n call ceedvectordestroy(gtposeones,err)\n call ceedbasisdestroy(bxl,err)\n call ceedbasisdestroy(bug,err)\n enddo\n\n call ceeddestroy(ceed,err)\n end\n!-----------------------------------------------------------------------\n", "meta": {"hexsha": "db6569d4557ad7dfcaa2bac7fa34a01b51c60b4e", "size": 4396, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tests/t314-basis-f.f90", "max_stars_repo_name": "AdelekeBankole/libCEED", "max_stars_repo_head_hexsha": "aae8ce39fa1e28b745979a9cbffc67a790eb3f5e", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 123, "max_stars_repo_stars_event_min_datetime": "2018-01-29T02:04:05.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T18:13:48.000Z", "max_issues_repo_path": "tests/t314-basis-f.f90", "max_issues_repo_name": "AdelekeBankole/libCEED", "max_issues_repo_head_hexsha": "aae8ce39fa1e28b745979a9cbffc67a790eb3f5e", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 781, "max_issues_repo_issues_event_min_datetime": "2017-12-22T17:20:35.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T21:34:34.000Z", "max_forks_repo_path": "tests/t314-basis-f.f90", "max_forks_repo_name": "AdelekeBankole/libCEED", "max_forks_repo_head_hexsha": "aae8ce39fa1e28b745979a9cbffc67a790eb3f5e", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 41, "max_forks_repo_forks_event_min_datetime": "2017-12-27T22:35:13.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-01T13:02:07.000Z", "avg_line_length": 31.1773049645, "max_line_length": 80, "alphanum_fraction": 0.5900818926, "num_tokens": 1376, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093975331752, "lm_q2_score": 0.7279754371026368, "lm_q1q2_score": 0.6503072991371063}} {"text": "subroutine MONOD_NH4(Temp,PAR,NH4,NO3,PO4,mu0,Qnmin,Qpmin,aI0,bI0,KN,KP,DFe,KFe,muNet,QN,QP,theta,SI,Lno3)\n! This subroutine calculate nondiatroph phytoplankton growth rates, QN and Theta based on the simplest MONOD equation\nuse bio_MOD, only: TEMPBOL, Ep, do_IRON, N2fix,thetamax,thetamin\nreal, intent(in) :: Temp, PAR,NH4,NO3,PO4,mu0,Qnmin,Qpmin,aI0,bI0,KN,KP,DFe,KFe\nreal, intent(out) :: QN, QP, theta, SI, Lno3,muNet\nreal :: rmax_T,Qnmax,Qpmax,Lpo4\n\n ! Maximal N:C ratio\n Qnmax=3.*Qnmin\n Qpmax=3.*Qpmin\n\n ! The maximal growth rate (rmax_T) under temperature tC \n rmax_T = mu0*TEMPBOL(Ep,Temp)\n\n !The light limitation index (SI)\n ! Unit of aI0_C: (W m-2)-1, different from other models (aI0_Chl)\n ! Include photoinhibition (Platt et al. J Phycol 1980)\n SI = (1d0 - exp(-aI0*PAR/rmax_T))*exp(-bI0*PAR/rmax_T)\n\n ! Growth rate (d-1) is the product function of temperature, light, and nutrient \n\n ! Nitrate dependence\n Lno3 = NO3/(NO3 + KN)*(1. - Lnh4)\n\n if (N2fix) then\n Lpo4 = PO4/(PO4 + KP)\n Lno3 = min(Lno3, Lpo4)\n endif\n\n if (DO_IRON) then\n Lpo4 = DFe/(DFe + KFe)\n Lno3 = min(Lno3, Lpo4)\n endif\n muNet = rmax_T*Lno3*SI\n QN = Qnmin/(1d0-(1d0-Qnmin/Qnmax)*Lno3)\n\n if (N2fix) QP=Qpmin/(1d0-(1d0-Qpmin/Qpmax)*(PO4/(PO4+KP)))\n \n theta = thetamin+muNet/PAR/aI0*(thetamax-thetamin) !Unit: gChl/molC\n return\nend subroutine\n\n", "meta": {"hexsha": "8d18336624384746ce82c1a496a5e510f6b3136c", "size": 1383, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "DRAM/src/Monod_NH4.f90", "max_stars_repo_name": "BingzhangChen/NPZDFeCONT", "max_stars_repo_head_hexsha": "0083d46dadc4fb8fed8728816755678da8294e16", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "DRAM/src/Monod_NH4.f90", "max_issues_repo_name": "BingzhangChen/NPZDFeCONT", "max_issues_repo_head_hexsha": "0083d46dadc4fb8fed8728816755678da8294e16", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "DRAM/src/Monod_NH4.f90", "max_forks_repo_name": "BingzhangChen/NPZDFeCONT", "max_forks_repo_head_hexsha": "0083d46dadc4fb8fed8728816755678da8294e16", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.1627906977, "max_line_length": 117, "alphanum_fraction": 0.6760665221, "num_tokens": 587, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951607140233, "lm_q2_score": 0.6959583376458152, "lm_q1q2_score": 0.650300102754826}} {"text": " SUBROUTINE MB04RU( N, ILO, A, LDA, QG, LDQG, CS, TAU, DWORK,\n $ LDWORK, INFO )\nC\nC SLICOT RELEASE 5.7.\nC\nC Copyright (c) 2002-2020 NICONET e.V.\nC\nC PURPOSE\nC\nC To reduce a skew-Hamiltonian matrix,\nC\nC [ A G ]\nC W = [ T ] ,\nC [ Q A ]\nC\nC where A is an N-by-N matrix and G, Q are N-by-N skew-symmetric\nC matrices, to Paige/Van Loan (PVL) form. That is, an orthogonal\nC symplectic matrix U is computed so that\nC\nC T [ Aout Gout ]\nC U W U = [ T ] ,\nC [ 0 Aout ]\nC\nC where Aout is in upper Hessenberg form.\nC Unblocked version.\nC\nC ARGUMENTS\nC\nC Input/Output Parameters\nC\nC N (input) INTEGER\nC The order of the matrix A. N >= 0.\nC\nC ILO (input) INTEGER\nC It is assumed that A is already upper triangular and Q is\nC zero in rows and columns 1:ILO-1. ILO is normally set by a\nC previous call to the SLICOT Library routine MB04DS;\nC otherwise it should be set to 1.\nC 1 <= ILO <= N+1, if N > 0; ILO = 1, if N = 0.\nC\nC A (input/output) DOUBLE PRECISION array, dimension (LDA,N)\nC On entry, the leading N-by-N part of this array must\nC contain the matrix A.\nC On exit, the leading N-by-N part of this array contains\nC the matrix Aout and, in the zero part of Aout, information\nC about the elementary reflectors used to compute the\nC PVL factorization.\nC\nC LDA INTEGER\nC The leading dimension of the array A. LDA >= MAX(1,N).\nC\nC QG (input/output) DOUBLE PRECISION array, dimension\nC (LDQG,N+1)\nC On entry, the leading N-by-N+1 part of this array must\nC contain in columns 1:N the strictly lower triangular part\nC of the matrix Q and in columns 2:N+1 the strictly upper\nC triangular part of the matrix G. The parts containing the\nC diagonal and the first superdiagonal of this array are not\nC referenced.\nC On exit, the leading N-by-N+1 part of this array contains\nC in its first N-1 columns information about the elementary\nC reflectors used to compute the PVL factorization and in\nC its last N columns the strictly upper triangular part of\nC the matrix Gout.\nC\nC LDQG INTEGER\nC The leading dimension of the array QG. LDQG >= MAX(1,N).\nC\nC CS (output) DOUBLE PRECISION array, dimension (2N-2)\nC On exit, the first 2N-2 elements of this array contain the\nC cosines and sines of the symplectic Givens rotations used\nC to compute the PVL factorization.\nC\nC TAU (output) DOUBLE PRECISION array, dimension (N-1)\nC On exit, the first N-1 elements of this array contain the\nC scalar factors of some of the elementary reflectors.\nC\nC Workspace\nC\nC DWORK DOUBLE PRECISION array, dimension (LDWORK)\nC On exit, if INFO = 0, DWORK(1) returns the optimal value\nC of LDWORK.\nC On exit, if INFO = -10, DWORK(1) returns the minimum\nC value of LDWORK.\nC\nC LDWORK INTEGER\nC The length of the array DWORK. LDWORK >= MAX(1,N-1).\nC\nC Error Indicator\nC\nC INFO INTEGER\nC = 0: successful exit;\nC < 0: if INFO = -i, the i-th argument had an illegal\nC value.\nC\nC METHOD\nC\nC The matrix U is represented as a product of symplectic reflectors\nC and Givens rotations\nC\nC U = diag( H(1),H(1) ) G(1) diag( F(1),F(1) )\nC diag( H(2),H(2) ) G(2) diag( F(2),F(2) )\nC ....\nC diag( H(n-1),H(n-1) ) G(n-1) diag( F(n-1),F(n-1) ).\nC\nC Each H(i) has the form\nC\nC H(i) = I - tau * v * v'\nC\nC where tau is a real scalar, and v is a real vector with v(1:i) = 0\nC and v(i+1) = 1; v(i+2:n) is stored on exit in QG(i+2:n,i), and\nC tau in QG(i+1,i).\nC\nC Each F(i) has the form\nC\nC F(i) = I - nu * w * w'\nC\nC where nu is a real scalar, and w is a real vector with w(1:i) = 0\nC and w(i+1) = 1; w(i+2:n) is stored on exit in A(i+2:n,i), and\nC nu in TAU(i).\nC\nC Each G(i) is a Givens rotation acting on rows i+1 and n+i+1, where\nC the cosine is stored in CS(2*i-1) and the sine in CS(2*i).\nC\nC NUMERICAL ASPECTS\nC\nC The algorithm requires 40/3 N**3 + O(N) floating point operations\nC and is strongly backward stable.\nC\nC REFERENCES\nC\nC [1] Van Loan, C.F.\nC A symplectic method for approximating all the eigenvalues of\nC a Hamiltonian matrix.\nC Linear Algebra and its Applications, 61, pp. 233-251, 1984.\nC\nC CONTRIBUTORS\nC\nC D. Kressner (Technical Univ. Berlin, Germany) and\nC P. Benner (Technical Univ. Chemnitz, Germany), December 2003.\nC\nC REVISIONS\nC V. Sima, Nov. 2008 (SLICOT version of the HAPACK routine DSHPVL).\nC V. Sima, Nov. 2011, Oct. 2012.\nC\nC KEYWORDS\nC\nC Elementary matrix operations, skew-Hamiltonian matrix.\nC\nC ******************************************************************\nC\nC .. Parameters ..\n DOUBLE PRECISION ZERO, ONE\n PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )\nC .. Scalar Arguments ..\n INTEGER ILO, INFO, LDA, LDQG, LDWORK, N\nC .. Array Arguments ..\n DOUBLE PRECISION A(LDA,*), CS(*), DWORK(*), QG(LDQG,*), TAU(*)\nC .. Local Scalars ..\n INTEGER I\n DOUBLE PRECISION ALPHA, C, NU, S, TEMP\nC .. External Subroutines ..\n EXTERNAL DLARF, DLARFG, DLARTG, DROT, MB01MD, MB01ND,\n $ XERBLA\nC .. Intrinsic Functions ..\n INTRINSIC DBLE, MAX, MIN\nC\nC .. Executable Statements ..\nC\nC Check the scalar input parameters.\nC\n INFO = 0\n IF ( N.LT.0 ) THEN\n INFO = -1\n ELSE IF ( ILO.LT.1 .OR. ILO.GT.N+1 ) THEN\n INFO = -2\n ELSE IF ( LDA.LT.MAX( 1, N ) ) THEN\n INFO = -4\n ELSE IF ( LDQG.LT.MAX( 1, N ) ) THEN\n INFO = -6\n ELSE IF ( LDWORK.LT.MAX( 1, N-1 ) ) THEN\n DWORK(1) = DBLE( MAX( 1, N-1 ) )\n INFO = -10\n END IF\nC\nC Return if there were illegal values.\nC\n IF ( INFO.NE.0 ) THEN\n CALL XERBLA( 'MB04RU', -INFO )\n RETURN\n END IF\nC\nC Quick return if possible.\nC\n IF ( N.LE.ILO ) THEN\n DWORK(1) = ONE\n RETURN\n END IF\nC\n DO 10 I = ILO, N - 1\nC\nC Generate elementary reflector H(i) to annihilate QG(i+2:n,i).\nC\n ALPHA = QG(I+1,I)\n CALL DLARFG( N-I, ALPHA, QG(MIN( I+2, N ),I), 1, NU )\n IF ( NU.NE.ZERO ) THEN\n QG(I+1,I) = ONE\nC\nC Apply H(i) from both sides to QG(i+1:n,i+1:n).\nC Compute x := nu * QG(i+1:n,i+1:n) * v.\nC\n CALL MB01MD( 'Lower', N-I, NU, QG(I+1,I+1), LDQG, QG(I+1,I),\n $ 1, ZERO, DWORK, 1 )\nC\nC Apply the transformation as a rank-2 update:\nC QG(i+1:n,i+1:n) := QG(i+1:n,i+1:n) + v * x' - x * v'.\nC\n CALL MB01ND( 'Lower', N-I, ONE, QG(I+1,I), 1, DWORK, 1,\n $ QG(I+1,I+1), LDQG )\nC\nC Apply H(i) from the right hand side to QG(1:i,i+2:n+1).\nC\n CALL DLARF( 'Right', I, N-I, QG(I+1,I), 1, NU, QG(1,I+2),\n $ LDQG, DWORK )\nC\nC Apply H(i) from both sides to QG(i+1:n,i+2:n+1).\nC Compute x := nu * QG(i+1:n,i+2:n+1) * v.\nC\n CALL MB01MD( 'Upper', N-I, NU, QG(I+1,I+2), LDQG, QG(I+1,I),\n $ 1, ZERO, DWORK, 1 )\nC\nC Apply the transformation as a rank-2 update:\nC QG(i+1:n,i+2:n+1) := QG(i+1:n,i+2:n+1) + v * x' - x * v'.\nC\n CALL MB01ND( 'Upper', N-I, ONE, QG(I+1,I), 1, DWORK, 1,\n $ QG(I+1,I+2), LDQG )\nC\nC Apply H(i) from the left hand side to A(i+1:n,i:n).\nC\n CALL DLARF( 'Left', N-I, N-I+1, QG(I+1,I), 1, NU, A(I+1,I),\n $ LDA, DWORK )\nC\nC Apply H(i) from the right hand side to A(1:n,i+1:n).\nC\n CALL DLARF( 'Right', N, N-I, QG(I+1,I), 1, NU, A(1,I+1),\n $ LDA, DWORK )\n END IF\n QG(I+1,I) = NU\nC\nC Generate symplectic Givens rotation G(i) to annihilate\nC QG(i+1,i).\nC\n TEMP = A(I+1,I)\n CALL DLARTG( TEMP, ALPHA, C, S, A(I+1,I) )\nC\nC Apply G(i) to [A(I+1,I+2:N); QG(I+2:N,I+1)'].\nC\n CALL DROT( N-I-1, A(I+1,I+2), LDA, QG(I+2,I+1), 1, C, -S )\nC\nC Apply G(i) to [A(1:I,I+1) QG(1:I,I+2)].\nC\n CALL DROT( I, A(1,I+1), 1, QG(1,I+2), 1, C, S )\nC\nC Apply G(i) to [A(I+2:N,I+1) QG(I+1, I+3:N+1)'] from the right.\nC\n CALL DROT( N-I-1, A(I+2,I+1), 1, QG(I+1,I+3), LDQG, C, -S )\nC\n CS(2*I-1) = C\n CS(2*I) = S\nC\nC Generate elementary reflector F(i) to annihilate A(i+2:n,i).\nC\n CALL DLARFG( N-I, A(I+1,I), A(MIN( I+2, N ),I), 1, NU )\n IF ( NU.NE.ZERO ) THEN\n TEMP = A(I+1,I)\n A(I+1,I) = ONE\nC\nC Apply F(i) from the left hand side to A(i+1:n,i+1:n).\nC\n CALL DLARF( 'Left', N-I, N-I, A(I+1,I), 1, NU, A(I+1,I+1),\n $ LDA, DWORK )\nC\nC Apply F(i) from the right hand side to A(1:n,i+1:n).\nC\n CALL DLARF( 'Right', N, N-I, A(I+1,I), 1, NU, A(1,I+1),\n $ LDA, DWORK )\nC\nC Apply F(i) from both sides to QG(i+1:n,i+1:n).\nC Compute x := nu * QG(i+1:n,i+1:n) * v.\nC\n CALL MB01MD( 'Lower', N-I, NU, QG(I+1,I+1), LDQG, A(I+1,I),\n $ 1, ZERO, DWORK, 1 )\nC\nC Apply the transformation as a rank-2 update:\nC QG(i+1:n,i+1:n) := QG(i+1:n,i+1:n) + v * x' - x * v'.\nC\n CALL MB01ND( 'Lower', N-I, ONE, A(I+1,I), 1, DWORK, 1,\n $ QG(I+1,I+1), LDQG )\nC\nC Apply F(i) from the right hand side to QG(1:i,i+2:n+1).\nC\n CALL DLARF( 'Right', I, N-I, A(I+1,I), 1, NU, QG(1,I+2),\n $ LDQG, DWORK )\nC\nC Apply F(i) from both sides to QG(i+1:n,i+2:n+1).\nC Compute x := nu * QG(i+1:n,i+2:n+1) * v.\nC\n CALL MB01MD( 'Upper', N-I, NU, QG(I+1,I+2), LDQG, A(I+1,I),\n $ 1, ZERO, DWORK, 1 )\nC\nC Apply the transformation as a rank-2 update:\nC QG(i+1:n,i+2:n+1) := QG(i+1:n,i+2:n+1) + v * x' - x * v'.\nC\n CALL MB01ND( 'Upper', N-I, ONE, A(I+1,I), 1, DWORK, 1,\n $ QG(I+1,I+2), LDQG )\n A(I+1,I) = TEMP\n END IF\n TAU(I) = NU\n 10 CONTINUE\n DWORK(1) = DBLE( MAX( 1, N-1 ) )\n RETURN\nC *** Last line of MB04RU ***\n END\n", "meta": {"hexsha": "d96bdbb11c4ff5bcbd1956b0e85198acc651887b", "size": 10938, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "src/MB04RU.f", "max_stars_repo_name": "bnavigator/SLICOT-Reference", "max_stars_repo_head_hexsha": "7b96b6470ee0eaf75519a612d15d5e3e2857407d", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2020-11-10T23:47:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:34:43.000Z", "max_issues_repo_path": "src/MB04RU.f", "max_issues_repo_name": "RJHKnight/slicotr", "max_issues_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2021-02-07T22:26:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T11:01:07.000Z", "max_forks_repo_path": "src/MB04RU.f", "max_forks_repo_name": "RJHKnight/slicotr", "max_forks_repo_head_hexsha": "a7332d459aa0867d3bc51f2a5dd70bd75ab67ec0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-11-26T11:06:38.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T00:37:21.000Z", "avg_line_length": 33.7592592593, "max_line_length": 72, "alphanum_fraction": 0.5050283416, "num_tokens": 3810, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951661947456, "lm_q2_score": 0.6959583313396339, "lm_q1q2_score": 0.6503001006767151}} {"text": " SUBROUTINE TOCART(U,KEPLER,IANOM,POS,VEL,IERPNT,IERR)\nC\nC PURPOSE: TOCART CONVERTS THE KEPLERIAN ELEMENTS OF A VEHICLE\nC IN ORBIT INTO CARTESIAN COORDINATES\nC\nC\nC\nC VAR DIM TYPE I/O DESCRIPTION\nC --- --- ---- --- -----------\nC\nC U 1 R*8 I CENTRAL BODY GRAVITATION CONSTANT.\nC EX: U=398601.2 KM**3/SEC**2\nC LENGTH UNIT IS THE SAME AS SEMI-MAJOR\nC AXIS UNIT. TIME UNIT IS THE SAME AS\nC FOR VELOCITY TO BE OUTPUT.\nC\nC KEPLER 6 R*8 I KEPLERIAN ELEMENTS TO BE CONVERTED TO\nC CARTESIAN COORDINATES. LENGTH UNITS ARE\nC THE SAME AS FOR U. ANGLE UNITS ARE\nC RADIANS. ORDER IS: SMA, ECC, INCL, NODE,\nC ARGP, ANOM(MEAN OR TRUE: SEE IANOM).\nC\nC IANOM 1 I*4 I ANOMALY FLAG.\nC =0 MEANS KEPLER(6) IS MEAN ANOMALY.\nC =NON-ZERO MEANS KEPLER(6) IS TRUE ANOMALY.\nC\nC POS 3 R*8 O CARTESIAN POSITION VECTOR. LENGTH UNIT IS\nC AS FOR U AND ELEM(1).\nC\nC VEL 3 R*8 O CARTESIAN VELOCITY VECTOR. LENGTH UNIT IS\nC AS FOR R. TIME UNIT IS AS FOR U.\nC\nC IERPNT 1 I*4 I FORTRAN UNIT FOR ERROR MESSAGE. NONE\nC POSSIBLE IF =0. ERROR MESSAGE IS FOR A \nC NON-ELLIPSE/CIRCLE INPUT.\nC\nC IERR 1 I*4 O ERROR RETURN FLAG.\nC =0 NO ERROR. =1, ERROR.\nC\nC*******************************************************************\nC\nC CODING: TAKEN FROM 580'S MAESTRO PROGRAM. \nC C PETRUZZO 9/81.\nC MODIFICATIONS:\nC\nC*******************************************************************\nC\n IMPLICIT REAL*8 (A-H,O-Z)\n REAL*8 INCL,NODE,MEAN,KEPLER(6),P(3,2),RTEMP(2),VTEMP(2),MU\n REAL*8 POS(3),VEL(3)\n REAL*8 PI/ 3.141592653589793D0 /\n REAL*8 TWOPI/ 6.283185307179586D0 /\nC\nC\nC\n MU=U\n SMA=KEPLER(1)\n ECC=KEPLER(2)\n INCL=KEPLER(3)\n NODE=KEPLER(4)\n ARGP=KEPLER(5)\nC\nC ERROR CHECKS.\n IERR=0\n IF(ECC.LT.0.D0 .OR. ECC.GE.1.D0) IERR=1\n IF(SMA.LE.0.D0) IERR=1\n IF(IERR.NE.0) GO TO 1400\nC\nC WE NEED TRUE ANOMALY FOR CALCULATIONS. BE SURE WE HAVE IT.\n IF(IANOM.EQ.0) GO TO 10\nC KEPLER(6) IS TRUE ANOMALY.\n TRANOM=DMOD(DABS(KEPLER(6)),TWOPI)\n IF(KEPLER(6).LT.0.D0) TRANOM=TWOPI-TRANOM\n GO TO 20\n 10 CONTINUE\nC KEPLER(6) IS MEAN ANOMALY.\n MEAN=DMOD(DABS(KEPLER(6)),TWOPI)\n IF(KEPLER(6).LT.0.D0) MEAN=TWOPI-MEAN\n TRANOM=ANOMLY(+1,MEAN,ECC,0,IDUM)\nC\n 20 CONTINUE\nC BE SURE CONVENTIONS ARE SATISFIED.\n IF(INCL.EQ.0.D0) NODE=0.D0\n IF(ECC.EQ.0.D0) ARGP=0.D0\nC\nC\nC FORMULATION FROM DOCUMENT X-582-76-77(APRIL 1976), PAGE 3-49.\nC MATH THEORY OF THE G.T.D.S.\nC\n COSTRU=DCOS(TRANOM)\n ECANOM=DARCOS( (COSTRU+ECC)/(1.D0+ECC*COSTRU) )\n IF(TRANOM.GT.PI) ECANOM=TWOPI-ECANOM\n SINEC=DSIN(ECANOM)\n COSEC=DCOS(ECANOM)\n DUM1=DSQRT(1.D0-ECC*ECC)\n RTEMP(1) = SMA * (COSEC-ECC)\n RTEMP(2) = SMA * DUM1 * SINEC\n DUM2=DSQRT(MU/SMA)/(1.D0-ECC*COSEC)\n VTEMP(1)=-DUM2*SINEC\n VTEMP(2)=DUM2*DUM1*COSEC\nC\n COSAP=DCOS(ARGP)\n SINAP=DSIN(ARGP)\n COSNOD=DCOS(NODE)\n SINNOD=DSIN(NODE)\n COSINC=DCOS(INCL)\n SININC=DSIN(INCL)\n P(1,1)= COSAP*COSNOD - SINAP*SINNOD*COSINC\n P(2,1)= COSAP*SINNOD + SINAP*COSNOD*COSINC\n P(3,1)= SINAP*SININC\n P(1,2)=-SINAP*COSNOD - COSAP*SINNOD*COSINC\n P(2,2)=-SINAP*SINNOD + COSAP*COSNOD*COSINC\n P(3,2)= COSAP*SININC\nC\n POS(1) = P(1,1)*RTEMP(1) + P(1,2)*RTEMP(2)\n POS(2) = P(2,1)*RTEMP(1) + P(2,2)*RTEMP(2)\n POS(3) = P(3,1)*RTEMP(1) + P(3,2)*RTEMP(2)\n VEL(1) = P(1,1)*VTEMP(1) + P(1,2)*VTEMP(2)\n VEL(2) = P(2,1)*VTEMP(1) + P(2,2)*VTEMP(2)\n VEL(3) = P(3,1)*VTEMP(1) + P(3,2)*VTEMP(2)\n GO TO 9000\nC\n 1400 CONTINUE\n IF(IERPNT.NE.0) WRITE(IERPNT,1200) SMA,ECC\n 1200 FORMAT('0TOCART. BIG ERROR. ELLIPSE NOT INPUT. ARBITRARY ',\n 1 'R/V OUTPUT. IGNORE RESULTS. SMA,ECC IN=',G12.5,1X,G23.16)\n DO 1401 I=1,3\n POS(I)=10000.D0\n 1401 VEL(I)=1.D0\nC\n 9000 CONTINUE\n RETURN\n END\n", "meta": {"hexsha": "4ad10af878eb0a127bc6545674576bf78578e4a3", "size": 4388, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "gsc-13083/tocart.for", "max_stars_repo_name": "SteveDoyle2/nasa-cosmic", "max_stars_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_stars_repo_licenses": ["BSD-Source-Code"], "max_stars_count": 22, "max_stars_repo_stars_event_min_datetime": "2015-03-14T07:26:35.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-16T12:23:17.000Z", "max_issues_repo_path": "gsc-13083/tocart.for", "max_issues_repo_name": "SteveDoyle2/nasa-cosmic", "max_issues_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_issues_repo_licenses": ["BSD-Source-Code"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "gsc-13083/tocart.for", "max_forks_repo_name": "SteveDoyle2/nasa-cosmic", "max_forks_repo_head_hexsha": "c8015a9851a04f0483b978d92c2cbaee31c81fe3", "max_forks_repo_licenses": ["BSD-Source-Code"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2016-02-12T22:18:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-08T17:46:54.000Z", "avg_line_length": 32.7462686567, "max_line_length": 71, "alphanum_fraction": 0.5259799453, "num_tokens": 1730, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951661947456, "lm_q2_score": 0.6959583187272711, "lm_q1q2_score": 0.6503000888917843}} {"text": "program std\n\n implicit none\n\n character(len=80) filename\n\n integer i, j, npts, nfiles\n \n double precision, allocatable :: file(:)\n\n double precision :: temp1, temp2\n \n print*,'enter filename'\n read(*,*) filename\n\n print*,'how many points'\n read(*,*) npts\n\n allocate(file(npts))\n\n open(unit=999,file=trim(filename))\n do i=1,npts\n read(unit=999, FMT=*) file(i)\n end do\n\n temp1 = 0.\n do i=1,npts\n temp1 = temp1 + file(i) \n end do\n temp1 = temp1 / npts\n\n temp2 = 0.\n do i=1,npts\n temp2 = temp2 + ( file(i) - temp1 )**2\n end do\n temp2 = sqrt(temp2/npts)\n\n print*,'mean',temp1\n print*,'standard deviation',temp2\n print*,'standard error',temp2/sqrt(dble(npts))\n\nend program std\n", "meta": {"hexsha": "f70589f0d65154cdf2c3d8d400cb2acd633e5dc7", "size": 709, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "exec/immersedIons/postprocessing/std.f90", "max_stars_repo_name": "ckim103/FHDeX", "max_stars_repo_head_hexsha": "9182d7589db7e7ee318ca2a0f343c378d9c120a0", "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": "exec/immersedIons/postprocessing/std.f90", "max_issues_repo_name": "ckim103/FHDeX", "max_issues_repo_head_hexsha": "9182d7589db7e7ee318ca2a0f343c378d9c120a0", "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": "exec/immersedIons/postprocessing/std.f90", "max_forks_repo_name": "ckim103/FHDeX", "max_forks_repo_head_hexsha": "9182d7589db7e7ee318ca2a0f343c378d9c120a0", "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": 16.488372093, "max_line_length": 48, "alphanum_fraction": 0.6262341326, "num_tokens": 244, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059707450325, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.6502623000870881}} {"text": "subroutine swap(ind,size,x,y)\n integer::x,y,z,size\n integer,dimension(1:size)::ind\n z = ind(x)\n ind(x) = ind(y)\n ind(y) = z\nend subroutine swap\n \nsubroutine sift_down(a,ind,end,i,size) \n integer::i,size,ln,j,end\n real(kind=8),dimension(1:size)::a\n integer,dimension(1:size)::ind\n \n j = i\n do while (j .le. (end/2))\n ln = 2*j\n if (ln .lt. end) then\n if ((a(ind(ln+1))) .gt. (a(ind(ln)))) then \n ln = ln+1\n end if\n end if\n if (a(ind(ln)) .gt. a(ind(j))) then\n call swap(ind,size,j,ln)\n j = ln\n else\n j = end\n end if\n end do\n \n return\nend subroutine sift_down\n \nsubroutine heapify(a,ind,size)\n integer::size,i\n real(kind=8),dimension(1:size)::a\n integer,dimension(1:size)::ind\n \n do i = size/2,1,-1\n call sift_down(a,ind,size,i,size)\n end do\n\nend subroutine heapify\n\nsubroutine heapsort_index(a,ind,size) \n integer::size,i\n real(kind=8),dimension(1:size)::a\n integer,dimension(1:size)::ind\n\n do i=1,size \n ind(i)=i\n end do\n\n call heapify(a,ind,size)\n\n do i=size,1,-1\n call swap(ind,size,1,i)\n call sift_down(a,ind,i-1,1,size)\n end do\n\n\nend subroutine heapsort_index\n", "meta": {"hexsha": "96d4e7a88f4089d6e06ab6e3ff9129cc4b755e1d", "size": 1173, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/amuse/community/ramses/src/pm/heapsort_index.f90", "max_stars_repo_name": "rknop/amuse", "max_stars_repo_head_hexsha": "85d5bdcc29cfc87dc69d91c264101fafd6658aec", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-12-28T22:47:51.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-28T22:47:51.000Z", "max_issues_repo_path": "src/amuse/community/ramses/src/pm/heapsort_index.f90", "max_issues_repo_name": "rknop/amuse", "max_issues_repo_head_hexsha": "85d5bdcc29cfc87dc69d91c264101fafd6658aec", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-01-10T12:02:27.000Z", "max_issues_repo_issues_event_max_datetime": "2020-06-04T10:50:45.000Z", "max_forks_repo_path": "src/amuse/community/ramses/src/pm/heapsort_index.f90", "max_forks_repo_name": "rknop/amuse", "max_forks_repo_head_hexsha": "85d5bdcc29cfc87dc69d91c264101fafd6658aec", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-11-19T04:41:37.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-20T02:11:17.000Z", "avg_line_length": 18.9193548387, "max_line_length": 51, "alphanum_fraction": 0.6010230179, "num_tokens": 398, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059609645724, "lm_q2_score": 0.8198933447152497, "lm_q1q2_score": 0.6502622990488455}} {"text": "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n PROGRAM PROJ2\nC Project 2: The structure of white dwarf stars\nC COMPUTATIONAL PHYSICS (FORTRAN VERSION)\nC by Steven E. Koonin and Dawn C. Meredith\nC Copyright 1989, Addison-Wesley Publishing Company Inc.\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n CALL INIT !display header screen, setup parameters\n5 CONTINUE !main loop; execute once for each set of param\n CALL PARAM !get input parameters\n CALL ARCHON !calculate density, mass and radius of stars\n GOTO 5\n END\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n SUBROUTINE ARCHON\nC calculate the mass(r), density(r) for a range of central densities\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC Global variables:\n INCLUDE 'IO.ALL'\n INCLUDE 'PARAM.P2'\nC Local variables:\n REAL MSTOR(MAXMOD) !mass of star\n REAL RADIUS(MAXMOD) !radius of star\n REAL STEP(MAXMOD) !step size\n REAL RMIN(MAXMOD) !starting radius\n INTEGER NSTEP(MAXMOD) !number of radial steps\n REAL RHOSTR(MAXMOD,0:MAXSTP) !density(r) of star\n INTEGER IMODEL !index of current model\n INTEGER NLINES !number of lines printed out\n REAL M,RHO !current mass and density\n REAL R !current radius\n REAL DR !radial step\n REAL EGRAV !gravitational energy of star\n REAL EKINT !kinetic energy of star\n REAL EXPONT !temporary exponent\n REAL RHOCEN !central density for this model\n INTEGER IR !number of radial steps\n INTEGER DEVICE !current graphing device\n INTEGER SCREEN !send to terminal\n INTEGER PAPER !make a hardcopy\n INTEGER FILE !send to a file\nC Functions:\n REAL GAMMA !dPressure/dDensity\n DATA SCREEN,PAPER,FILE/1,2,3/\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC output summary of parameters\n IF (TTERM) CALL PRMOUT(OUNIT,NLINES)\n IF (TFILE) CALL PRMOUT(TUNIT,NLINES)\n IF (GFILE) CALL PRMOUT(GUNIT,NLINES)\nC\n DO 20 IMODEL=1,NMODEL !loop over central dens\nC \nC calculate central density\n EXPONT=FLOAT(IMODEL-1)/FLOAT(NMODEL-1) !spacing between dens\n RHOCEN=(RHO1/RHO0)*((RHO2/RHO1)**EXPONT) !equal on log scale\nC\n DR=((3.0*0.001/RHOCEN)**(1.0/3.0))/3.0 !radial step\n R=DR/10. !begin at finite radius\n RMIN(IMODEL)=R*R0/10.E+08 !starting radius\n STEP(IMODEL)=DR*R0/10.E+08 !step size\nC\nC use Taylor expansion to obtain initial conditions\n M=(R**3.0)*(RHOCEN/3.0) !initial mass\nC initial density\n RHO=RHOCEN*(1-RHOCEN*R**2.0/6.0/GAMMA(RHOCEN**(1./3.))) \n RHOSTR(IMODEL,0)=RHO*RHO0\nC\nC integrate equations and find energies, mass, and radius of star\n CALL INTGRT(M,RHO,R,DR,EGRAV,EKINT,IMODEL,IR,RHOSTR)\nC\n MSTOR(IMODEL)=M*M0/10.E+33 !save values for graph\n RADIUS(IMODEL)=R*R0/10.E+08\n NSTEP(IMODEL)=IR \nC\n IF (TTERM) !text output\n + CALL TXTOUT(OUNIT,NLINES,R,M,DR,RHOCEN,EKINT,EGRAV,IR)\n IF (TFILE) \n + CALL TXTOUT(TUNIT,NLINES,R,M,DR,RHOCEN,EKINT,EGRAV,IR)\nC \n20 CONTINUE\nC\n IF (TTERM) CALL PAUSE('to continue...',1) \n IF (TTERM) CALL CLEAR\nC\nC graphics output\n IF (GTERM) CALL GRFOUT(SCREEN,MSTOR,RADIUS,STEP,RMIN,NSTEP,RHOSTR)\n IF (GFILE) CALL GRFOUT(FILE,MSTOR,RADIUS,STEP,RMIN,NSTEP,RHOSTR)\n IF (GHRDCP) CALL GRFOUT(PAPER,MSTOR,RADIUS,STEP,RMIN,NSTEP,RHOSTR)\nC \n RETURN\n END\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n SUBROUTINE INTGRT(M,RHO,R,DR,EGRAV,EKINT,IMODEL,IR,RHOSTR)\nC integrates mass and density beginning with M and RHO at radius R;\nC calculates gravitational and kinetic energies\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC Global variables:\n INCLUDE 'PARAM.P2'\nC Passed variables:\n REAL RHOSTR(MAXMOD,0:MAXSTP)!density(r) of star (output)\n INTEGER IMODEL !index of current model (input)\n REAL M,RHO !current mass and density (I/O)\n REAL R !current radius (I/O)\n REAL DR !radial step (input)\n REAL EGRAV !gravitational energy of star (output)\n REAL EKINT !kinetic energy of star (output)\n INTEGER IR !current lattice point (output)\nC Function:\n REAL EPSRHO !function in energy density\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n EGRAV=0.0 !zero sums\n EKINT=0.0\n IR=0\n10 IF ((IR .LT. MAXSTP) .AND. (RHO .GT. RHOCUT)) THEN\n IR=IR+1 !update radial index\n CALL RUNGE(M,RHO,R,DR) !take a Runge-Kutta step\n IF (RHO .LT. RHOCUT) RHO=RHOCUT !avoid small densities\n RHOSTR(IMODEL,IR)=RHO*RHO0 !save values for graphing\n EGRAV=EGRAV+M*RHO*R !contribution to energy integ.\n EKINT=EKINT+R**2*EPSRHO(RHO**(1./3.))\n GOTO 10\n END IF\n EGRAV=-EGRAV*DR*E0 !unscaled energies\n EKINT=EKINT*DR*E0\n RETURN \n END\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n SUBROUTINE RUNGE(M,RHO,R,DR)\nC take a Runge-Kutta step to integrate mass and density\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC Passed variables:\n REAL M,RHO !current mass and density (I/O)\n REAL R !current radius (input)\n REAL DR !radial step (input)\nC Local variables:\n REAL DMDR,DRHODR !radial derivatives of mass and dens\n REAL K1M,K1RHO !intermediate increments of mass and\n REAL K2M,K2RHO ! density\n REAL K3M,K3RHO\n REAL K4M,K4RHO\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n CALL DERS(M,RHO,R,DMDR,DRHODR) !calculate k1's\n K1M=DR*DMDR\n K1RHO=DR*DRHODR\nC\n R=R+DR/2.0 !calculate k2's\n M=M+.5*K1M\n RHO=RHO+.5*K1RHO\n CALL DERS(M,RHO,R,DMDR,DRHODR)\n K2M=DR*DMDR\n K2RHO=DR*DRHODR\nC\n M=M+.5*(K2M-K1M) !calculate k3's\n RHO=RHO+.5*(K2RHO-K1RHO)\n CALL DERS(M,RHO,R,DMDR,DRHODR)\n K3M=DR*DMDR\n K3RHO=DR*DRHODR\nC\n R=R+DR/2.0 !calculate k4's\n M=M+K3M-.5*K2M\n RHO=RHO+K3RHO-.5*K2RHO\n CALL DERS(M,RHO,R,DMDR,DRHODR)\n K4M=DR*DMDR\n K4RHO=DR*DRHODR\nC\nC values of mass and density at new radius\n M=M-K3M+(K1M+2.0*K2M+2.0*K3M+K4M)/6.0\n RHO=RHO-K3RHO+(K1RHO+2.0*K2RHO+2.0*K3RHO+K4RHO)/6.\nC\n RETURN\n END\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n SUBROUTINE DERS(M,RHO,R,DMDR,DRHODR)\nC calculate the derivatives of mass and density with respect to radius\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC Passed variables:\n REAL M,RHO !current mass and density (input)\n REAL R !current radius (input)\n REAL DMDR,DRHODR !radial derivatives of mass and dens (output)\nC Functions\n REAL GAMMA !dPressure/dDensity\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n IF (RHO .GT. 0.0) THEN !avoid division by zero\n DRHODR=-M*RHO/((R**2)*GAMMA(RHO**(1.0/3.0)))\n DMDR=(R**2)*RHO\n END IF\n RETURN\n END\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n REAL FUNCTION GAMMA(X)\nC derivative of pressure with respect to density\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC Passed variables:\n REAL X !cubed root of density\n GAMMA=X*X/3.0/SQRT(X*X+1)\n END\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n REAL FUNCTION EPSRHO(X)\nC function needed in the calculation of the energy\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC Passed variables:\n REAL X !cubed root of density\nC Local variables:\n REAL PART1,PART2 !terms in the function\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n PART1=X*(1.0+2.0*X**2)*SQRT(1.0+X**2)\n PART2=LOG(X+SQRT(1.0+X**2))\n EPSRHO=0.375*(PART1-PART2)\n END\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n SUBROUTINE INIT\nC initializes constants, displays header screen,\nC initializes arrays for input parameters\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC Global variables:\n INCLUDE 'IO.ALL'\n INCLUDE 'MENU.ALL'\n INCLUDE 'PARAM.P2'\nC Local parameters:\n CHARACTER*80 DESCRP !program description\n DIMENSION DESCRP(22)\n INTEGER NHEAD,NTEXT,NGRF !number of lines for each description\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n CALL SETUP !get environment parameters\nC \nC display header screen \n DESCRP(1)= 'PROJECT 2'\n DESCRP(2)= 'The structure of white dwarf stars'\n NHEAD=2\nC\nC text output description\n DESCRP(3)= 'mass, radius, and energy of each star'\n NTEXT=1\nC\nC graphics output description\n DESCRP(4)= 'total mass vs. final radius for all models'\n DESCRP(5)= 'density vs. radius for each model'\n NGRF=2\nC \n CALL HEADER(DESCRP,NHEAD,NTEXT,NGRF)\nC\nC calculate constants \n MEORMP = 1./1836.\nC\nC setup menu\n CALL MENU !setup constant part of menu\nC\n MPRMPT(4)='2) (not used)'\nC \n MTYPE(13)=FLOAT\n MPRMPT(13)= 'Enter electron fraction, YE'\n MTAG(13)= 'Electron fraction, YE'\n MLOLIM(13)=.001\n MHILIM(13)=10.\n MREALS(13)=1.0\nC \n MTYPE(14)=FLOAT\n MPRMPT(14)= 'Enter central density (gm/cm^3) for the first model'\n MTAG(14)= 'Initial central density (gm/cm^3)'\n MLOLIM(14)=1.E5\n MHILIM(14)=1.E15\n MREALS(14)=1.E5\nC \n MTYPE(15)=FLOAT\n MPRMPT(15)= 'Enter central density (gm/cm^3) for the last model'\n MTAG(15)= 'Final central density (gm/cm^3)'\n MLOLIM(15)=1.E5\n MHILIM(15)=1.E15\n MREALS(15)=1.E11\nC \n MTYPE(16)=NUM\n MPRMPT(16)= 'Enter the number of models to calculate'\n MTAG(16)= 'Number of models to calculate'\n MLOLIM(16)=1.\n MHILIM(16)=MAXMOD\n MINTS(16)=4.\nC \n MTYPE(17)=SKIP\n MREALS(17)=35.\nC\n MTYPE(36)=SKIP\n MREALS(36)=60.\nC\n MSTRNG(MINTS(75))= 'proj2.txt'\nC \n MTYPE(76)=SKIP\n MREALS(76)=80.\nC \n MSTRNG(MINTS(86))= 'proj2.grf'\nC\n MTYPE(87)=SKIP\n MREALS(87)=90.\nC \n RETURN\n END\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n SUBROUTINE PARAM\nC gets parameters from screen\nC ends program on request\nC closes old files\nC maps menu variables to program variables\nC opens new files\nC calculates all derivative parameters\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC Global variables:\n INCLUDE 'MENU.ALL'\n INCLUDE 'IO.ALL'\n INCLUDE 'PARAM.P2'\n INCLUDE 'MAP.P2'\nC Function:\n LOGICAL LOGCVT !converts 1 and 0 to true and false \nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC get input from terminal\n CALL CLEAR \n CALL ASK(1,ISTOP)\nC \nC stop program if requested\n IF (MREALS(IMAIN) .EQ. STOP) CALL FINISH \nC\nC close files if necessary\n IF (TNAME .NE. MSTRNG(MINTS(ITNAME))) \n + CALL FLCLOS(TNAME,TUNIT)\n IF (GNAME .NE. MSTRNG(MINTS(IGNAME))) \n + CALL FLCLOS(GNAME,GUNIT)\nC\nC set new parameter values \nC physical and numerical:\n YE=MREALS(IYE)\n RHO1=MREALS(IRHO1)\n RHO2=MREALS(IRHO2)\n NMODEL=MINTS(INMODL)\nC\nC text output\n TTERM=LOGCVT(MINTS(ITTERM))\n TFILE=LOGCVT(MINTS(ITFILE))\n TNAME=MSTRNG(MINTS(ITNAME))\nC\nC graphics output\n GTERM=LOGCVT(MINTS(IGTERM))\n GHRDCP=LOGCVT(MINTS(IGHRD))\n GFILE=LOGCVT(MINTS(IGFILE))\n GNAME=MSTRNG(MINTS(IGNAME))\nC\nC open files \n IF (TFILE) CALL FLOPEN(TNAME,TUNIT)\n IF (GFILE) CALL FLOPEN(GNAME,GUNIT)\nC files may have been renamed\n MSTRNG(MINTS(ITNAME))=TNAME\n MSTRNG(MINTS(IGNAME))=GNAME\nC\n CALL PCHECK\n CALL CLEAR\nC\nC calculate parameter dependent quantities\n R0=7.72E+08*YE !scaling radius\n M0=5.67E+33*(YE**2) !scaling mass\n RHO0=979000./YE !scaling density\n E0=YE*MEORMP*9*(M0/1E+31) !scaling energy\n RHOCUT=1000./RHO0 !nearly zero density\nC \n RETURN\n END\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n SUBROUTINE PCHECK\nC ensure that RHO1 < RHO2\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC Global parameters:\n INCLUDE 'PARAM.P2'\n INCLUDE 'MENU.ALL'\n INCLUDE 'IO.ALL'\n INCLUDE 'MAP.P2'\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n10 IF (RHO1 .GE. RHO2) THEN\n WRITE (OUNIT,15) \n CALL ASK(IRHO1,IRHO2)\n RHO1=MREALS(IRHO1)\n RHO2=MREALS(IRHO2)\n GOTO 10\n END IF\n15 FORMAT \n + (' The initial density must be smaller than the final density')\n RETURN\n END \nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n SUBROUTINE PRMOUT(MUNIT,NLINES)\nC outputs parameters to the specified unit\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC Global variables\n INCLUDE 'PARAM.P2'\n INCLUDE 'IO.ALL'\nC Passed variables\n INTEGER MUNIT !unit number for output (input)\n INTEGER NLINES !number of lines written so far (I/O)\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n IF (MUNIT .EQ. OUNIT) CALL CLEAR\nC\n WRITE (MUNIT,19)\n WRITE (MUNIT,21)\n WRITE (MUNIT,25) NMODEL\n WRITE (MUNIT,27) YE\n WRITE (MUNIT,29) RHO1,RHO2\n WRITE (MUNIT,19)\nC\n IF (MUNIT .NE. GUNIT) THEN !headers for text output only\n WRITE (MUNIT,31)\n WRITE (MUNIT,32)\n WRITE (MUNIT,33)\n END IF\nC\n NLINES = 9\nC \n19 FORMAT (' ')\n21 FORMAT (' Output from project 2: ',\n + 'The structure of white dwarf stars ')\n25 FORMAT (' Number of models = ',I3)\n27 FORMAT (' Electron fraction YE= ',1PE9.3)\n29 FORMAT (' First central density=',1PE9.3, \n + 5X,' Final central density=',1PE9.3)\n31 FORMAT (3X,'Step',4X,'Cent Den',1X,'Nstep',3X,'Radius',\n + 5X,'Mass', 7X,'Kin E',6X,'Grav E',7X,'Tot E')\n32 FORMAT (3X,' cm ',4X,'gm/cm^-3',1X,' ',3X,' cm ',\n + 5X,' gm ', 7X,9X,'10^51 ergs ',4X,' ')\n33 FORMAT (3X,'----',4X,'--------',1X,'-----',3X,'------',\n + 5X,'----', 7X,'-----',6X,'------',7X,'-----')\nC\n RETURN \n END\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n SUBROUTINE TXTOUT(MUNIT,NLINES,R,M,DR,RHOCEN,EKINT,EGRAV,IR)\nC writes results for one model to the requested unit\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC Global variables:\n INCLUDE 'IO.ALL'\n INCLUDE 'PARAM.P2'\nC Input variables:\n INTEGER MUNIT !unit to which we are writing\n INTEGER NLINES !number of lines printed out (I/O)\n REAL M,RHO !current mass and density\n REAL RHOCEN !central density\n REAL R !current radius\n REAL DR !radial step\n REAL EGRAV !gravitational energy of star\n REAL EKINT !kinetic energy of star\n INTEGER IR !number of radial steps\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC if screen is full, clear screen and retype headings \n IF ((MOD(NLINES,TRMLIN-4) .EQ. 0) \n + .AND. (MUNIT .EQ. OUNIT)) THEN\n CALL PAUSE('to continue',1)\n CALL CLEAR\n WRITE (MUNIT,31)\n WRITE (MUNIT,32)\n WRITE (MUNIT,33)\n END IF\nC\nC write unscaled values to screen\n WRITE (MUNIT,35) DR*R0,RHOCEN*RHO0,IR,\n + R*R0,M*M0,EKINT,EGRAV,EKINT+EGRAV\nC\nC keep track of printed lines only for terminal output\n IF (MUNIT .EQ. OUNIT) NLINES=NLINES+1\nC\n31 FORMAT (3X,'Step',4X,'Cent Den',1X,'Nstep',3X,'Radius',\n + 5X,'Mass', 7X,'Kin E',6X,'Grav E',7X,'Tot E')\n32 FORMAT (3X,' cm ',4X,'gm/cm^-3',1X,' ',3X,' cm ',\n + 5X,' gm ', 7X,9X,'10^51 ergs ',4X,' ')\n33 FORMAT (3X,'----',4X,'--------',1X,'-----',3X,'------',\n + 5X,'----', 7X,'-----',6X,'------',7X,'-----')\n35 FORMAT (2(1X,1PE8.2),1X,I4,3(2X,1PE9.3),2(2X,1PE10.3))\nC \n RETURN\n END\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n SUBROUTINE GRFOUT(DEVICE,MSTOR,RADIUS,STEP,RMIN,NSTEP,RHOSTR)\nC outputs two plots: 1) total mass vs. final radius of star\nC 2) density vs. radius\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC Global variables \n INCLUDE 'IO.ALL'\n INCLUDE 'PARAM.P2'\n INCLUDE 'GRFDAT.ALL'\nC Input variables:\n INTEGER DEVICE !which device is being used?\n REAL MSTOR(MAXMOD) !mass of stars\n REAL RADIUS(MAXMOD) !radius of stars\n REAL STEP(MAXMOD) !step size\n REAL RMIN(MAXMOD) !starting radius\n INTEGER NSTEP(MAXMOD) !number of radial steps\n REAL RHOSTR(MAXMOD,0:MAXSTP) !density(r) of star\nC Local variables\n REAL R,DEN !radius and density for one model\n INTEGER IM,IR !current model and radius\n DIMENSION R(0:MAXSTP),DEN(0:MAXSTP) !radius and density \n CHARACTER*9 CYE !electron fraction as charac string\n INTEGER LEN !length of string\n INTEGER SCREEN !send to terminal\n INTEGER PAPER !make a hardcopy\n INTEGER FILE !send to a file\n DATA SCREEN,PAPER,FILE/1,2,3/\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nC messages for the impatient\n IF (DEVICE .NE. SCREEN) WRITE (OUNIT,100) \nC\nC define parameters which are the same for both plots\n IF (DEVICE .NE. FILE) THEN\n NPLOT=2 !how many plots?\nC\n XMIN=0. \n Y0VAL=0.\nC\n ILINE=1 !line and symbol styles\n ISYM=1\n IFREQ=1\n NXTICK=5\n NYTICK=5\nC \n CALL CONVRT(YE,CYE,LEN)\n TITLE = 'White Dwarf Stars with electron fraction='//CYE\nC\n CALL GTDEV(DEVICE) !device nomination\n IF (DEVICE .EQ. SCREEN) CALL GMODE !change to graphics mode\n END IF\nC \n DO 20 IPLOT=1,NPLOT\nC define parameters which are different for each plot\n IF (DEVICE .NE. FILE) THEN\n IF (IPLOT .EQ. 1) THEN\n YMIN=MSTOR(1)\n X0VAL=MSTOR(1)\n XMAX=RADIUS(1)\n YMAX=MSTOR(NMODEL)\n NPOINT=NMODEL\n LABEL(1)= 'radius (10**8 cm)'\n LABEL(2)= 'mass (10**33 gm)'\n CALL LNLNAX \n ELSE\n XMAX=RADIUS(1) \n YMAX=RHO2\n YMIN=RHOCUT*RHO0\n X0VAL=RHOCUT*RHO0\n IFREQ=0\n LABEL(1)= 'radius (10**8 cm)'\n LABEL(2)= 'density (gm*cm**(-3))'\n CALL LGLNAX\n END IF\n END IF \nC \nC output results\n IF (IPLOT .EQ. 1) THEN\nC total mass vs. final radius\n IF (DEVICE .EQ. FILE) THEN\n WRITE (GUNIT,80)\n WRITE (GUNIT,70) (RADIUS(IM),MSTOR(IM),IM=1,NMODEL)\n ELSE\n CALL XYPLOT (RADIUS,MSTOR)\n END IF\nC\n ELSE\nC density(r) vs. r for each model\n DO 30 IM=1,NMODEL\n NPOINT=NSTEP(IM)+1\n DO 40 IR=0,NPOINT-1\n R(IR)=RMIN(IM)+IR*STEP(IM)\n DEN(IR)=RHOSTR(IM,IR)\n40 CONTINUE \n IF (DEVICE .EQ. FILE) THEN\n WRITE (GUNIT,85) IM\n WRITE (GUNIT,70) (R(IR),DEN(IR),IR=0,NPOINT)\n ELSE\n CALL XYPLOT(R,DEN)\n END IF\n30 CONTINUE \n END IF\n20 CONTINUE \nC\n IPLOT=NPLOT\nC end graphing session\n IF (DEVICE .NE. FILE) CALL GPAGE(DEVICE) !end graphing package\n IF (DEVICE .EQ. SCREEN) CALL TMODE !switch to text mode\nC\n70 FORMAT (2(5X,E11.3))\n80 FORMAT (/,10X,'radius',10X,'mass')\n85 FORMAT (/,' Density vs. radius for model ',I2)\n100 FORMAT (/,' Patience, please; output going to a file.')\nC\n RETURN\n END\n \n", "meta": {"hexsha": "a271de4f9aec7a71ca7d2626ea920a918ec152a4", "size": 22353, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "Source-Koonin-Code/Project/proj2.for", "max_stars_repo_name": "ajz34/Comp-Phys-Koonin", "max_stars_repo_head_hexsha": "9fc371bdb44b7030025d254eda040a55bfa3b7cd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-10-29T12:21:38.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-31T17:03:43.000Z", "max_issues_repo_path": "Source-Koonin-Code/Project/proj2.for", "max_issues_repo_name": "ajz34/Comp-Phys-Koonin", "max_issues_repo_head_hexsha": "9fc371bdb44b7030025d254eda040a55bfa3b7cd", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Source-Koonin-Code/Project/proj2.for", "max_forks_repo_name": "ajz34/Comp-Phys-Koonin", "max_forks_repo_head_hexsha": "9fc371bdb44b7030025d254eda040a55bfa3b7cd", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.9507640068, "max_line_length": 73, "alphanum_fraction": 0.5886458194, "num_tokens": 6571, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933447152497, "lm_q2_score": 0.7931059536292271, "lm_q1q2_score": 0.6502622930346447}} {"text": "module diffusion_mod\n use, intrinsic :: iso_fortran_env, only : SP => REAL32, error_unit\n implicit none\n\n public :: diffusion_step\n\ncontains\n\n subroutine init_system(n, temp, new_temp)\n implicit none\n integer, value :: n\n real(kind=SP), dimension(:, :), allocatable, intent(out) :: temp\n real(kind=SP), dimension(:, :), allocatable, intent(out) :: new_temp\n integer :: istat\n\n allocate (temp(n, n), new_temp(n, n), stat=istat)\n if (istat /= 0) then\n write (unit=error_unit, fmt='(A)') &\n 'error: can not allocate arrays'\n stop 1\n end if\n temp(1, :) = 1.0_SP\n temp(2:, :) = 0.0_SP\n new_temp = temp\n !$acc enter data copyin(temp, new_temp)\n end subroutine init_system\n\n subroutine diffusion_step(temp, new_temp, error)\n implicit none\n real(kind=SP), dimension(:, :), intent(in) :: temp\n real(kind=SP), dimension(:, :), intent(out) :: new_temp\n real(kind=SP) :: error\n integer :: i, j\n\n error = 0.0_SP\n !$acc kernels present(temp, new_temp)\n do j = 2, size(temp, 2) - 1\n do i = 2, size(temp, 1) - 1\n new_temp(i, j) = 0.25_SP*(temp(i - 1, j) + temp(i, j - 1) + &\n temp(i + 1, j) + temp(i, j + 1))\n error = max(error, abs(new_temp(i, j) - temp(i, j)))\n end do\n end do\n !$acc end kernels\n end subroutine diffusion_step\n\n subroutine swap(temp, new_temp)\n implicit none\n real(kind=SP), dimension(:, :), intent(in) :: temp\n real(kind=SP), dimension(:, :), intent(out) :: new_temp\n integer :: i, j\n\n !$acc kernels present(temp, new_temp)\n do j = 1, size(temp, 2)\n do i = 1, size(temp, 1)\n new_temp(i, j) = temp(i, j)\n end do\n end do\n !$acc end kernels\n end subroutine swap\n\n subroutine dealloc_system(temp, new_temp)\n real(kind=SP), dimension(:, :), allocatable, intent(inout) :: temp, new_temp\n\n !$acc exit data delete(temp, new_temp)\n deallocate (temp, new_temp)\n end subroutine dealloc_system\n\n subroutine print_system(temp)\n implicit none\n real(kind=SP), dimension(:, :), intent(in) :: temp\n integer :: i\n\n do i = 1, size(temp, 1)\n print '(*(E10.3))', temp(i, :)\n end do\n end subroutine print_system\n\nend module diffusion_mod\n", "meta": {"hexsha": "75158d0618c89b6ce5b428489fb3cdb861bb40e9", "size": 2505, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "source_code/openacc/diffusion_mod.f90", "max_stars_repo_name": "gjbex/Fortran-MOOC", "max_stars_repo_head_hexsha": "9c8a778313a082473f7f717a58133397b41ce29c", "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/openacc/diffusion_mod.f90", "max_issues_repo_name": "gjbex/Fortran-MOOC", "max_issues_repo_head_hexsha": "9c8a778313a082473f7f717a58133397b41ce29c", "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/openacc/diffusion_mod.f90", "max_forks_repo_name": "gjbex/Fortran-MOOC", "max_forks_repo_head_hexsha": "9c8a778313a082473f7f717a58133397b41ce29c", "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": 31.3125, "max_line_length": 84, "alphanum_fraction": 0.5361277445, "num_tokens": 675, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.7931059511841119, "lm_q2_score": 0.8198933425148214, "lm_q1q2_score": 0.6502622892847383}} {"text": "! This file is provided as part of the \"projet long\" for the \"Calcul Scientifique et Analyse de Donn\u00e9es\" course\n! at INP-ENSEEIHT\n! Date: 02/2018\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 driver for testing the developed methods\n! \nprogram main\n implicit none\n integer :: ierr, m, n, maxit, lwork, i, j, it, n_ev, disp, version, imat, p\n double precision, allocatable :: a(:,:), work(:)\n double precision, allocatable :: w(:), w_aux(:), e_vect(:,:), u(:)\n double precision, allocatable :: e_vals(:), res_ev(:)\n integer, allocatable :: it_ev(:)\n integer :: t_start, t_end, t_rate, len\n double precision :: time, eps, res, percentage, dummy, accuracy\n double precision, parameter :: done = 1.d0, dzero = 0.d0\n character (len=20) :: version_str\n double precision :: normF_A, workf(1)\n \n ! external functions\n double precision, external :: dlange, dnrm2\n\n !! parameter initializations \n ierr = 0\n\n !! THOSE ARE THE ONLY VALUES YOU ARE ALLOWED TO MODIFY IN THIS FILE\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n maxit = 30000\n eps = 1d-15\n p = 20\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n call parse_args(n, m, version, imat, percentage, disp)\n\n allocate(a(n,n), e_vals(n), stat=ierr)\n if(ierr .ne.0) then\n write(*,'(\"Cannot allocate data, Input matrix is too big\")')\n stop\n endif\n \n ! Generate the matrix\n call matgen(imat, a, n, n, e_vals, ierr)\n\n if(disp >= 1) then\n write(*,'(\" \")')\n write(*,'(\"Here are the first \",i2,\" eigenvalues: \")', advance='no')min(n,10)\n do i=1, min(n,10)\n write(*,'(f10.3,x)',advance='no') e_vals(i)\n end do\n write(*,'(\" \")')\n\n ! print the spectrum of the matrix in 'spectrum.txt'\n open(20, file='spectrum.txt')\n do i = 1,n\n write(20,'(f10.3,x)') e_vals(i)\n end do\n close(20)\n end if\n\n write(version_str, \"(I2)\") version\n\n normF_A = dlange('f', n, n, a, n, workf)\n\n write(*,*)\n select case(version)\n\n case(10)\n\n write(*,'(\"Calling LAPACK DSYEV on A\")')\n \n lwork=2*max(1,3*n+n,5*n)\n allocate(w(n), work(lwork), e_vect(n,n), w_aux(n), stat=ierr)\n if(ierr .ne.0) then\n write(*,'(\"Cannot allocate data, Input matrix is too big for the LAPACK version\")')\n stop\n endif\n\n call system_clock(t_start)\n call dsyev('v', 'u', n, a, n, w_aux, work, lwork, ierr)\n do i=1, n\n e_vect(:, i) = a(:, n-i +1)\n w(i) = w_aux(n-i +1)\n end do\n call system_clock(t_end, t_rate)\n time = real(t_end-t_start)/real(t_rate)\n\n write(*,'(\"End of LAPACK DSYEV\")')\n \n m = 10\n n_ev = m\n\n case(11)\n \n write(*,'(\"Calling the basic deflated power method\")')\n\n allocate(w(m), e_vect(n, m), it_ev(m), res_ev(m), stat=ierr)\n if(ierr .ne.0) then\n write(*,'(\"Cannot allocate data.\")')\n stop\n endif\n\n call system_clock(t_start)\n call deflated_power_method(n, m, a, percentage, maxit, eps, w, e_vect, n_ev, res_ev, it_ev, ierr)\n call system_clock(t_end, t_rate)\n time = real(t_end-t_start)/real(t_rate)\n\n write(*,'(\"End of the basic deflated power method\")')\n\n select case(ierr)\n case(-3) \n write(*,*) \"maxit reached : ERROR\"\n write(*,*) \"hints: increase maxit or decrease eps in main.f90\"\n case(-2)\n write(*,*) \"allocation problem : ERROR\"\n case(-1)\n write(*,*) \"parameters consistancy : ERROR\"\n case(0)\n write(*,'(\" \")')\n write(*,'(\"percentage \", f5.2, \" reached with \", i4, \" eigenvalues\")') percentage, n_ev\n case(1)\n write(*,'(\"percentage \", f5.2, \" NOT reached with \", i4, \" eigenvalues\")') percentage, n_ev\n end select\n \n case(0)\n\n write(*,'(\"Calling the basic subspace iteration method v0\")')\n\n allocate(w(m), e_vect(n, m), it_ev(m), stat=ierr)\n if(ierr .ne.0) then\n write(*,'(\"Cannot allocate data.\")')\n stop\n endif\n\n call random_number(e_vect)\n\n call system_clock(t_start)\n call subspace_iter_v0(n, m, a, maxit, eps, e_vect, w, res, it, ierr)\n call system_clock(t_end, t_rate)\n time = real(t_end-t_start)/real(t_rate)\n write(*,'(\"End of the basic subspace iteration method\")')\n\n select case(ierr)\n case(-4)\n write(*,'(\"Problem in dsyev : ERROR\")')\n case(-3) \n write(*,*) \"maxit reached : ERROR\"\n write(*,*) \"hints: increase maxit or decrease eps in main.f90\"\n case(-2)\n write(*,*) \"allocation problem : ERROR\"\n case(-1)\n write(*,*) \"parameters consistancy : ERROR\"\n case(0)\n write(*,'(\" \")')\n write(*,'(i4, \" Eigenvalues computed in \", i10, \" iterations with a residual of\", e10.3 )') m, it, res\n end select\n\n n_ev = m\n\n case(1)\n\n write(*,'(\"Calling the subspace iteration method v1\")')\n\n allocate(w(m), e_vect(n, m), it_ev(m), res_ev(m), stat=ierr)\n if(ierr .ne.0) then\n write(*,'(\"Cannot allocate data.\")')\n stop\n endif\n\n call random_number(e_vect)\n\n call system_clock(t_start)\n call subspace_iter_v1(n, m, a, percentage, maxit, eps, e_vect, w, n_ev, res_ev, it_ev, ierr)\n call system_clock(t_end, t_rate)\n time = real(t_end-t_start)/real(t_rate)\n\n write(*,'(\"End the subspace iteration method v1\")')\n \n select case(ierr)\n case(-4)\n write(*,'(\"Problem in dsyev : ERROR\")')\n case(-3) \n write(*,*) \"maxit reached : ERROR\"\n write(*,*) \"hints: increase maxit or decrease eps in main.f90\"\n case(-2)\n write(*,*) \"allocation problem : ERROR\"\n case(-1)\n write(*,*) \"parameters consistancy : ERROR\"\n case(0)\n write(*,'(\" \")')\n write(*,'(\"percentage \", f5.2, \" reached with \", i4, \" eigenvalues\")') percentage, n_ev\n case(1)\n write(*,'(\"percentage \", f5.2, \" NOT reached with \", i4, \" eigenvalues\")') percentage, n_ev\n end select\n\n write(*,*) 'n_ev =', n_ev\n\n case(2)\n\n write(*,'(\"Calling the subspace iteration method v2\")')\n\n allocate(w(m), e_vect(n, m), it_ev(m), res_ev(m), stat=ierr)\n if(ierr .ne.0) then\n write(*,'(\"Cannot allocate data.\")')\n stop\n endif\n\n call random_number(e_vect)\n\n call system_clock(t_start)\n call subspace_iter_v2(n, m, a, p, percentage, maxit, eps, e_vect, w, n_ev, res_ev, it_ev, ierr)\n call system_clock(t_end, t_rate)\n time = real(t_end-t_start)/real(t_rate)\n\n write(*,'(\"End the subspace iteration method v2\")')\n \n select case(ierr)\n case(-4)\n write(*,'(\"Problem in dsyev : ERROR\")')\n case(-3) \n write(*,*) \"maxit reached : ERROR\"\n write(*,*) \"hints: increase maxit or decrease eps in main.f90\"\n case(-2)\n write(*,*) \"allocation problem : ERROR\"\n case(-1)\n write(*,*) \"parameters consistancy : ERROR\"\n case(0)\n write(*,'(\" \")')\n write(*,'(\"percentage \", f5.2, \" reached with \", i4, \" eigenvalues\")') percentage, n_ev\n case(1)\n write(*,'(\"percentage \", f5.2, \" NOT reached with \", i4, \" eigenvalues\")') percentage, n_ev\n end select\n\n write(*,*) 'n_ev =', n_ev\n\n \n case(3)\n\n write(*,'(\"Calling the subspace iteration method v3\")')\n\n allocate(w(m), e_vect(n, m), it_ev(m), res_ev(m), stat=ierr)\n if(ierr .ne.0) then\n write(*,'(\"Cannot allocate data.\")')\n stop\n endif\n\n call random_number(e_vect)\n\n call system_clock(t_start)\n ! CHANGE to v3 when you are ready to test this version\n call subspace_iter_v2(n, m, a, p, percentage, maxit, eps, e_vect, w, n_ev, res_ev, it_ev, ierr)\n call system_clock(t_end, t_rate)\n time = real(t_end-t_start)/real(t_rate)\n\n write(*,'(\"End the subspace iteration method v3\")')\n \n select case(ierr)\n case(-4)\n write(*,'(\"Problem in dsyev : ERROR\")')\n case(-3) \n write(*,*) \"maxit reached : ERROR\"\n write(*,*) \"hints: increase maxit or decrease eps in main.f90\"\n case(-2)\n write(*,*) \"allocation problem : ERROR\"\n case(-1)\n write(*,*) \"parameters consistancy : ERROR\"\n case(0)\n write(*,'(\" \")')\n write(*,'(\"percentage \", f5.2, \" reached with \", i4, \" eigenvalues\")') percentage, n_ev\n case(1)\n write(*,'(\"percentage \", f5.2, \" NOT reached with \", i4, \" eigenvalues\")') percentage, n_ev\n end select\n\n write(*,*) 'n_ev =', n_ev\n\n\n case default\n write(*,'(\"Version is not valid or yet implemented\")')\n\n end select\n\n\n if(ierr.ge.0) then\n if(disp >= 1) then\n write(*,'(\" \")')\n write(*,'(\" \")')\n write(*,'(i4, \" First eigenvalues \")') min(n_ev,m)\n write(*,*) \"=========================\"\n do i=1, min(n_ev, m)\n select case(version)\n case(10)\n write(*,'(\"Eigenvalue \",i4,\":\",f10.3)') i, w(i)\n case(11) \n write(*,'(\"Eigenvalue \",i4,\":\",f10.3, \" accuracy :\", e10.3, \" number of iterations : \",i10)') &\n i, w(i), res_ev(i), it_ev(i)\n case(0)\n write(*,'(\"Eigenvalue \",i4,\":\",f10.3)') i, w(i)\n case(1) \n write(*,'(\"Eigenvalue \",i4,\":\",f10.3, \" accuracy :\", e10.3, \" number of iterations : \",i10)') &\n i, w(i), res_ev(i), it_ev(i)\n case(2) \n write(*,'(\"Eigenvalue \",i4,\":\",f10.3, \" accuracy :\", e10.3, \" number of iterations : \",i10)') &\n i, w(i), res_ev(i), it_ev(i)\n end select\n end do\n write(*,'(\" \")')\n end if\n\n if(disp >= 2) then\n ! check the accuracy ||A*V_i - Lambda_i*V_i||/|Lambda_i| for each pair\n\n allocate(u(n))\n ! A is lost with DSYEV and power\n if(version >= 10) then\n call matgen(imat, a, n, n, e_vals, ierr)\n end if\n\n write(*,*) '||A*V_i - Lambda_i*V_i||/||A||'\n write(*,*) \"==============================\"\n do i = 1, min(n_ev, m)\n call dgemv('n', n, n, done, a, n, e_vect(1,i), 1, dzero, u, 1)\n u = u - w(i)*e_vect(:,i)\n write(*, '(\"Eigenvalue \",i4,\":\",e10.3)') i, dnrm2(n, u, 1) / normF_A\n end do\n deallocate(u)\n\n if(disp == 3) then\n ! save eigenvectors in a file\n open(20, file=\"eigenvectors_\"//trim(adjustl(version_str))//\".txt\")\n do i = 1, n\n do j = 1, min(n_ev, m)\n write(20,'(f10.6,x)', advance='no') e_vect(i, j)\n end do\n write(20, *) ''\n end do\n close(20)\n end if\n\n end if\n\n else\n write(*,'(\"An error was found. IERR=\",i4)')ierr\n end if\n\n deallocate(a, w, stat=ierr)\n\n if(allocated(e_vect)) deallocate(e_vect, stat=ierr)\n if(allocated(w_aux)) deallocate(w_aux, stat=ierr)\n if(allocated(work)) deallocate(work, stat=ierr)\n if(allocated(res_ev)) deallocate(res_ev, stat=ierr)\n if(allocated(it_ev)) deallocate(it_ev, stat=ierr)\n\n write(*,*) \n write(*,*) \"==================================\"\n write(*,*) 'Time = ', time\n write(*,*) \"==================================\"\n\n stop\n \nend program main\n", "meta": {"hexsha": "e38797e4c8198293e5917bbe509ab278a890d0d6", "size": 11121, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "tp2/Fortran/main.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/main.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/main.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": 30.8060941828, "max_line_length": 112, "alphanum_fraction": 0.5410484669, "num_tokens": 3393, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933447152497, "lm_q2_score": 0.7931059487389966, "lm_q1q2_score": 0.6502622890251774}} {"text": "!\nMODULE ConstantsModule\n !\n ! This module provides commonly used constants of all types.\n !\n ! ==================== Other Modules\n !\n USE IntrinsicTypesModule, ONLY : &\n & RK => REAL_KIND, IK => INTEGER_KIND, LK => LOGICAL_KIND\n !\n IMPLICIT NONE\n !\n PRIVATE RK, IK, LK\n !\n ! ==================== Public Entities\n !\n PUBLIC ! all public\n !\n ! ========== Reals\n !\n ! Values for real constants are prefixed with\n ! \"RK_\" to indicate the default \"REAL KIND\".\n ! Below, the values are of the right type because of the\n ! rules for intrinsic assignment.\n !\n ! --- Real form of integers\n !\n REAL(RK), PUBLIC, PARAMETER ::&\n & RK_ZERO = 0.0_RK, RK_ONE = 1.0_RK, RK_TWO = 2.0_RK, &\n & RK_THREE = 3.0_RK, RK_FOUR = 4.0_RK, RK_SIX = 6.0_RK, &\n & RK_180 = 180.0_RK\n !\n ! --- Common fractions.\n !\n REAL(RK), PUBLIC, PARAMETER ::&\n & RK_ONE_HALF = 0.5_RK, RK_ONE_THIRD = RK_ONE/RK_THREE\n !\n ! --- Things related to pi.\n !\n ! The values for pi and various other numbers were computed to 50 \n ! decimal places using `bc'. They could not be initialized here since \n ! they involve intrinsic functions and would have to be set at run-time.\n !\n REAL(RK), PUBLIC, PARAMETER ::&\n & RK_PI = 3.14159265358979323846264338327950288419716939937508_RK\n !\n REAL(RK), PUBLIC, PARAMETER ::&\n & RK_TWO_PI = RK_PI*RK_TWO, &\n & RK_PI_OVER_2 = RK_PI/RK_TWO, &\n & RK_PI_OVER_3 = RK_PI/RK_THREE,&\n & RK_PI_OVER_4 = RK_PI/RK_FOUR, &\n & RK_PI_OVER_6 = RK_PI/RK_SIX, &\n & RK_PI_OVER_180 = RK_PI/RK_180, &\n & RK_180_OVER_PI = RK_180/RK_PI\n\n REAL(RK), PUBLIC, PARAMETER ::& ! For convenience ...\n & DEGREES_PER_RADIAN = RK_180_OVER_PI,&\n & RADIANS_PER_DEGREE = RK_PI_OVER_180\n !\n ! --- Architecture-Related Values\n !\n REAL(RK), PUBLIC, PARAMETER :: RK_HUGE = HUGE(RK_ONE)\n !\n ! --- Algebraic Numbers\n !\n ! Various roots, golden section.\n !\n !\n REAL(RK), PUBLIC, PARAMETER ::&\n & RK_ROOT_2 =&\n & 1.41421356237309504880168872420969807856967187537694_RK,&\n & RK_ROOT_3 =&\n & 1.73205080756887729352744634150587236694280525381038_RK,&\n & RK_ROOT_5 =&\n & 2.23606797749978969640917366873127623544061835961152_RK,&\n & RK_ROOT_7 =&\n & 2.64575131106459059050161575363926042571025918308245_RK\n !\n REAL(RK), PUBLIC, PARAMETER ::&\n & RK_ROOT_6 = RK_ROOT_2 * RK_ROOT_3,&\n & RK_ROOT_14 = RK_ROOT_2 * RK_ROOT_7,&\n & RK_ROOT_3_HALVES = RK_ROOT_3/RK_ROOT_2,&\n & RK_GOLD = RK_ONE_HALF * (RK_ROOT_5 + RK_ONE),&\n & RK_GOLD_CONJ = RK_ONE_HALF * (RK_ROOT_5 - RK_ONE)\n !\n ! ========== Integers\n !\n INTEGER(IK), PUBLIC, PARAMETER :: &\n & IK_ZERO = 0_IK, IK_ONE = 1_IK, IK_TWO = 2_IK, IK_THREE = 3_IK,&\n & IK_FOUR = 4_IK\n !\n ! ========== Logicals\n !\n LOGICAL(LK), PUBLIC, PARAMETER :: &\n & TRUE = .TRUE., FALSE = .FALSE.\n !\n ! ========== Characters\n !\n ! ASCII numbers of various characters.\n ! \n CHARACTER, PUBLIC, PARAMETER ::&\n & ASCII_TAB = ACHAR(9), ASCII_NULL = ACHAR(0),&\n & ASCII_BELL = ACHAR(7), ASCII_BACK = ACHAR(8),&\n & ASCII_LF = ACHAR(10), ASCII_VTAB = ACHAR(11),&\n & ASCII_CR = ACHAR(13), ASCII_SPACE = ACHAR(32)\n !\n CHARACTER(LEN=*), PUBLIC, PARAMETER :: WHITESPACE = ASCII_SPACE//ASCII_TAB\n !\nEND MODULE ConstantsModule\n", "meta": {"hexsha": "b99e0b325c8889e67d4db7467b3ec8fc74183a4b", "size": 3501, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "PythonFortranCode/ConstantsModule.f90", "max_stars_repo_name": "rcarson3/pyFEpX", "max_stars_repo_head_hexsha": "f95851e41025fb57893041d0395d53a5745b7e6c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-03-27T21:24:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-11T13:35:59.000Z", "max_issues_repo_path": "PythonFortranCode/ConstantsModule.f90", "max_issues_repo_name": "rcarson3/pyFEpX", "max_issues_repo_head_hexsha": "f95851e41025fb57893041d0395d53a5745b7e6c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-09-10T22:54:10.000Z", "max_issues_repo_issues_event_max_datetime": "2018-09-10T22:54:10.000Z", "max_forks_repo_path": "PythonFortranCode/ConstantsModule.f90", "max_forks_repo_name": "rcarson3/pyFEpX", "max_forks_repo_head_hexsha": "f95851e41025fb57893041d0395d53a5745b7e6c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-05-13T07:44:35.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-11T13:36:00.000Z", "avg_line_length": 31.8272727273, "max_line_length": 76, "alphanum_fraction": 0.587832048, "num_tokens": 1189, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8198933447152497, "lm_q2_score": 0.7931059487389968, "lm_q1q2_score": 0.6502622890251774}} {"text": "module logspace\n\n use types, only: dp\n\n implicit none\n\ncontains\n \n elemental function log1p(x) result (y)\n real(dp), intent(in) :: x\n real(dp) :: y\n real(dp), volatile :: z\n\n z = 1.0d0 + x\n if (z == 0) then\n y = log(z)\n else\n y = log(z) - ((z - 1.0d0) - x) / z ! cancels errors with IEEE arithmetic\n end if\n end function log1p\n\n\n function logadd(x, y) result (sum)\n use ieee_constants, only: isneginf\n\n real(dp), intent(in) :: x, y\n real(dp) :: sum\n\n if (isneginf(x)) then\n sum = y\n else if (isneginf(y)) then\n sum = x\n else\n sum = max(x, y) + log1p(exp(-abs(x - y)))\n end if\n end function logadd\n\nend module logspace\n", "meta": {"hexsha": "12ced43d8f7fa7663f040e15f9f40ca4376d01c0", "size": 700, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "discover/src/src/logspace.f90", "max_stars_repo_name": "ZoliQua/orthologs", "max_stars_repo_head_hexsha": "8d247605ab0f470b38033904525c520a71523a72", "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": "discover/src/src/logspace.f90", "max_issues_repo_name": "ZoliQua/orthologs", "max_issues_repo_head_hexsha": "8d247605ab0f470b38033904525c520a71523a72", "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": "discover/src/src/logspace.f90", "max_forks_repo_name": "ZoliQua/orthologs", "max_forks_repo_head_hexsha": "8d247605ab0f470b38033904525c520a71523a72", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.9487179487, "max_line_length": 82, "alphanum_fraction": 0.5528571429, "num_tokens": 240, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314858927012, "lm_q2_score": 0.734119521083126, "lm_q1q2_score": 0.6501593622796871}} {"text": "!*==slagtf.f90 processed by SPAG 7.51RB at 20:08 on 3 Mar 2022\n!> \\brief \\b SLAGTF computes an LU factorization of a matrix T-\u03bbI, where T is a general tridiagonal matrix, and \u03bb a scalar, using partial pivoting with row interchanges.\n!\n! =========== DOCUMENTATION ===========\n!\n! Online html documentation available at\n! http://www.netlib.org/lapack/explore-html/\n!\n!> \\htmlonly\n!> Download SLAGTF + dependencies\n!> \n!> [TGZ]\n!> \n!> [ZIP]\n!> \n!> [TXT]\n!> \\endhtmlonly\n!\n! Definition:\n! ===========\n!\n! SUBROUTINE SLAGTF( N, A, LAMBDA, B, C, TOL, D, IN, INFO )\n!\n! .. Scalar Arguments ..\n! INTEGER INFO, N\n! REAL LAMBDA, TOL\n! ..\n! .. Array Arguments ..\n! INTEGER IN( * )\n! REAL A( * ), B( * ), C( * ), D( * )\n! ..\n!\n!\n!> \\par Purpose:\n! =============\n!>\n!> \\verbatim\n!>\n!> SLAGTF factorizes the matrix (T - lambda*I), where T is an n by n\n!> tridiagonal matrix and lambda is a scalar, as\n!>\n!> T - lambda*I = PLU,\n!>\n!> where P is a permutation matrix, L is a unit lower tridiagonal matrix\n!> with at most one non-zero sub-diagonal elements per column and U is\n!> an upper triangular matrix with at most two non-zero super-diagonal\n!> elements per column.\n!>\n!> The factorization is obtained by Gaussian elimination with partial\n!> pivoting and implicit row scaling.\n!>\n!> The parameter LAMBDA is included in the routine so that SLAGTF may\n!> be used, in conjunction with SLAGTS, to obtain eigenvectors of T by\n!> inverse iteration.\n!> \\endverbatim\n!\n! Arguments:\n! ==========\n!\n!> \\param[in] N\n!> \\verbatim\n!> N is INTEGER\n!> The order of the matrix T.\n!> \\endverbatim\n!>\n!> \\param[in,out] A\n!> \\verbatim\n!> A is REAL array, dimension (N)\n!> On entry, A must contain the diagonal elements of T.\n!>\n!> On exit, A is overwritten by the n diagonal elements of the\n!> upper triangular matrix U of the factorization of T.\n!> \\endverbatim\n!>\n!> \\param[in] LAMBDA\n!> \\verbatim\n!> LAMBDA is REAL\n!> On entry, the scalar lambda.\n!> \\endverbatim\n!>\n!> \\param[in,out] B\n!> \\verbatim\n!> B is REAL array, dimension (N-1)\n!> On entry, B must contain the (n-1) super-diagonal elements of\n!> T.\n!>\n!> On exit, B is overwritten by the (n-1) super-diagonal\n!> elements of the matrix U of the factorization of T.\n!> \\endverbatim\n!>\n!> \\param[in,out] C\n!> \\verbatim\n!> C is REAL array, dimension (N-1)\n!> On entry, C must contain the (n-1) sub-diagonal elements of\n!> T.\n!>\n!> On exit, C is overwritten by the (n-1) sub-diagonal elements\n!> of the matrix L of the factorization of T.\n!> \\endverbatim\n!>\n!> \\param[in] TOL\n!> \\verbatim\n!> TOL is REAL\n!> On entry, a relative tolerance used to indicate whether or\n!> not the matrix (T - lambda*I) is nearly singular. TOL should\n!> normally be chose as approximately the largest relative error\n!> in the elements of T. For example, if the elements of T are\n!> correct to about 4 significant figures, then TOL should be\n!> set to about 5*10**(-4). If TOL is supplied as less than eps,\n!> where eps is the relative machine precision, then the value\n!> eps is used in place of TOL.\n!> \\endverbatim\n!>\n!> \\param[out] D\n!> \\verbatim\n!> D is REAL array, dimension (N-2)\n!> On exit, D is overwritten by the (n-2) second super-diagonal\n!> elements of the matrix U of the factorization of T.\n!> \\endverbatim\n!>\n!> \\param[out] IN\n!> \\verbatim\n!> IN is INTEGER array, dimension (N)\n!> On exit, IN contains details of the permutation matrix P. If\n!> an interchange occurred at the kth step of the elimination,\n!> then IN(k) = 1, otherwise IN(k) = 0. The element IN(n)\n!> returns the smallest positive integer j such that\n!>\n!> abs( u(j,j) ) <= norm( (T - lambda*I)(j) )*TOL,\n!>\n!> where norm( A(j) ) denotes the sum of the absolute values of\n!> the jth row of the matrix A. If no such j exists then IN(n)\n!> is returned as zero. If IN(n) is returned as positive, then a\n!> diagonal element of U is small, indicating that\n!> (T - lambda*I) is singular or nearly singular,\n!> \\endverbatim\n!>\n!> \\param[out] INFO\n!> \\verbatim\n!> INFO is INTEGER\n!> = 0: successful exit\n!> < 0: if INFO = -k, the kth argument had an illegal value\n!> \\endverbatim\n!\n! Authors:\n! ========\n!\n!> \\author Univ. of Tennessee\n!> \\author Univ. of California Berkeley\n!> \\author Univ. of Colorado Denver\n!> \\author NAG Ltd.\n!\n!> \\date December 2016\n!\n!> \\ingroup auxOTHERcomputational\n!\n! =====================================================================\n SUBROUTINE SLAGTF(N,A,Lambda,B,C,Tol,D,In,Info)\n IMPLICIT NONE\n!*--SLAGTF160\n!\n! -- LAPACK computational routine (version 3.7.0) --\n! -- LAPACK is a software package provided by Univ. of Tennessee, --\n! -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n! December 2016\n!\n! .. Scalar Arguments ..\n INTEGER Info , N\n REAL Lambda , Tol\n! ..\n! .. Array Arguments ..\n INTEGER In(*)\n REAL A(*) , B(*) , C(*) , D(*)\n! ..\n!\n! =====================================================================\n!\n! .. Parameters ..\n REAL ZERO\n PARAMETER (ZERO=0.0E+0)\n! ..\n! .. Local Scalars ..\n INTEGER k\n REAL eps , mult , piv1 , piv2 , scale1 , scale2 , temp , tl\n! ..\n! .. Intrinsic Functions ..\n INTRINSIC ABS , MAX\n! ..\n! .. External Functions ..\n REAL SLAMCH\n EXTERNAL SLAMCH\n! ..\n! .. External Subroutines ..\n EXTERNAL XERBLA\n! ..\n! .. Executable Statements ..\n!\n Info = 0\n IF ( N<0 ) THEN\n Info = -1\n CALL XERBLA('SLAGTF',-Info)\n RETURN\n ENDIF\n!\n IF ( N==0 ) RETURN\n!\n A(1) = A(1) - Lambda\n In(N) = 0\n IF ( N==1 ) THEN\n IF ( A(1)==ZERO ) In(1) = 1\n RETURN\n ENDIF\n!\n eps = SLAMCH('Epsilon')\n!\n tl = MAX(Tol,eps)\n scale1 = ABS(A(1)) + ABS(B(1))\n DO k = 1 , N - 1\n A(k+1) = A(k+1) - Lambda\n scale2 = ABS(C(k)) + ABS(A(k+1))\n IF ( k<(N-1) ) scale2 = scale2 + ABS(B(k+1))\n IF ( A(k)==ZERO ) THEN\n piv1 = ZERO\n ELSE\n piv1 = ABS(A(k))/scale1\n ENDIF\n IF ( C(k)==ZERO ) THEN\n In(k) = 0\n piv2 = ZERO\n scale1 = scale2\n IF ( k<(N-1) ) D(k) = ZERO\n ELSE\n piv2 = ABS(C(k))/scale2\n IF ( piv2<=piv1 ) THEN\n In(k) = 0\n scale1 = scale2\n C(k) = C(k)/A(k)\n A(k+1) = A(k+1) - C(k)*B(k)\n IF ( k<(N-1) ) D(k) = ZERO\n ELSE\n In(k) = 1\n mult = A(k)/C(k)\n A(k) = C(k)\n temp = A(k+1)\n A(k+1) = B(k) - mult*temp\n IF ( k<(N-1) ) THEN\n D(k) = B(k+1)\n B(k+1) = -mult*D(k)\n ENDIF\n B(k) = temp\n C(k) = mult\n ENDIF\n ENDIF\n IF ( (MAX(piv1,piv2)<=tl) .AND. (In(N)==0) ) In(N) = k\n ENDDO\n IF ( (ABS(A(N))<=scale1*tl) .AND. (In(N)==0) ) In(N) = N\n!\n!\n! End of SLAGTF\n!\n END SUBROUTINE SLAGTF\n", "meta": {"hexsha": "d5e5dfea2f03d4d7d1cfefef5250dc0cf6d7b028", "size": 7850, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/single/slagtf.f90", "max_stars_repo_name": "urbanjost/spag_lapack", "max_stars_repo_head_hexsha": "1b082638c0ff5feb1a295a3aa4624c538d14847c", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2022-03-04T13:15:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-04T17:40:26.000Z", "max_issues_repo_path": "src/single/slagtf.f90", "max_issues_repo_name": "urbanjost/spag_lapack", "max_issues_repo_head_hexsha": "1b082638c0ff5feb1a295a3aa4624c538d14847c", "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": "src/single/slagtf.f90", "max_forks_repo_name": "urbanjost/spag_lapack", "max_forks_repo_head_hexsha": "1b082638c0ff5feb1a295a3aa4624c538d14847c", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.9618320611, "max_line_length": 169, "alphanum_fraction": 0.5284076433, "num_tokens": 2385, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.7341195269001831, "lm_q1q2_score": 0.6501593541352513}} {"text": "*> \\brief DGTSVX computes the solution to system of linear equations A * X = B for GT matrices \n*\n* =========== DOCUMENTATION ===========\n*\n* Online html documentation available at\n* http://www.netlib.org/lapack/explore-html/\n*\n*> \\htmlonly\n*> Download DGTSVX + dependencies\n*> \n*> [TGZ]\n*> \n*> [ZIP]\n*> \n*> [TXT]\n*> \\endhtmlonly\n*\n* Definition:\n* ===========\n*\n* SUBROUTINE DGTSVX( FACT, TRANS, N, NRHS, DL, D, DU, DLF, DF, DUF,\n* DU2, IPIV, B, LDB, X, LDX, RCOND, FERR, BERR,\n* WORK, IWORK, INFO )\n*\n* .. Scalar Arguments ..\n* CHARACTER FACT, TRANS\n* INTEGER INFO, LDB, LDX, N, NRHS\n* DOUBLE PRECISION RCOND\n* ..\n* .. Array Arguments ..\n* INTEGER IPIV( * ), IWORK( * )\n* DOUBLE PRECISION B( LDB, * ), BERR( * ), D( * ), DF( * ),\n* $ DL( * ), DLF( * ), DU( * ), DU2( * ), DUF( * ),\n* $ FERR( * ), WORK( * ), X( LDX, * )\n* ..\n*\n*\n*> \\par Purpose:\n* =============\n*>\n*> \\verbatim\n*>\n*> DGTSVX uses the LU factorization to compute the solution to a real\n*> system of linear equations A * X = B or A**T * X = B,\n*> where A is a tridiagonal matrix of order N and X and B are N-by-NRHS\n*> matrices.\n*>\n*> Error bounds on the solution and a condition estimate are also\n*> provided.\n*> \\endverbatim\n*\n*> \\par Description:\n* =================\n*>\n*> \\verbatim\n*>\n*> The following steps are performed:\n*>\n*> 1. If FACT = 'N', the LU decomposition is used to factor the matrix A\n*> as A = L * U, where L is a product of permutation and unit lower\n*> bidiagonal matrices and U is upper triangular with nonzeros in\n*> only the main diagonal and first two superdiagonals.\n*>\n*> 2. If some U(i,i)=0, so that U is exactly singular, then the routine\n*> returns with INFO = i. Otherwise, the factored form of A is used\n*> to estimate the condition number of the matrix A. If the\n*> reciprocal of the condition number is less than machine precision,\n*> INFO = N+1 is returned as a warning, but the routine still goes on\n*> to solve for X and compute error bounds as described below.\n*>\n*> 3. The system of equations is solved for X using the factored form\n*> of A.\n*>\n*> 4. Iterative refinement is applied to improve the computed solution\n*> matrix and calculate error bounds and backward error estimates\n*> for it.\n*> \\endverbatim\n*\n* Arguments:\n* ==========\n*\n*> \\param[in] FACT\n*> \\verbatim\n*> FACT is CHARACTER*1\n*> Specifies whether or not the factored form of A has been\n*> supplied on entry.\n*> = 'F': DLF, DF, DUF, DU2, and IPIV contain the factored\n*> form of A; DL, D, DU, DLF, DF, DUF, DU2 and IPIV\n*> will not be modified.\n*> = 'N': The matrix will be copied to DLF, DF, and DUF\n*> and factored.\n*> \\endverbatim\n*>\n*> \\param[in] TRANS\n*> \\verbatim\n*> TRANS is CHARACTER*1\n*> Specifies the form of the system of equations:\n*> = 'N': A * X = B (No transpose)\n*> = 'T': A**T * X = B (Transpose)\n*> = 'C': A**H * X = B (Conjugate transpose = Transpose)\n*> \\endverbatim\n*>\n*> \\param[in] N\n*> \\verbatim\n*> N is INTEGER\n*> The order of the matrix A. N >= 0.\n*> \\endverbatim\n*>\n*> \\param[in] NRHS\n*> \\verbatim\n*> NRHS is INTEGER\n*> The number of right hand sides, i.e., the number of columns\n*> of the matrix B. NRHS >= 0.\n*> \\endverbatim\n*>\n*> \\param[in] DL\n*> \\verbatim\n*> DL is DOUBLE PRECISION array, dimension (N-1)\n*> The (n-1) subdiagonal elements of A.\n*> \\endverbatim\n*>\n*> \\param[in] D\n*> \\verbatim\n*> D is DOUBLE PRECISION array, dimension (N)\n*> The n diagonal elements of A.\n*> \\endverbatim\n*>\n*> \\param[in] DU\n*> \\verbatim\n*> DU is DOUBLE PRECISION array, dimension (N-1)\n*> The (n-1) superdiagonal elements of A.\n*> \\endverbatim\n*>\n*> \\param[in,out] DLF\n*> \\verbatim\n*> DLF is DOUBLE PRECISION array, dimension (N-1)\n*> If FACT = 'F', then DLF is an input argument and on entry\n*> contains the (n-1) multipliers that define the matrix L from\n*> the LU factorization of A as computed by DGTTRF.\n*>\n*> If FACT = 'N', then DLF is an output argument and on exit\n*> contains the (n-1) multipliers that define the matrix L from\n*> the LU factorization of A.\n*> \\endverbatim\n*>\n*> \\param[in,out] DF\n*> \\verbatim\n*> DF is DOUBLE PRECISION array, dimension (N)\n*> If FACT = 'F', then DF is an input argument and on entry\n*> contains the n diagonal elements of the upper triangular\n*> matrix U from the LU factorization of A.\n*>\n*> If FACT = 'N', then DF is an output argument and on exit\n*> contains the n diagonal elements of the upper triangular\n*> matrix U from the LU factorization of A.\n*> \\endverbatim\n*>\n*> \\param[in,out] DUF\n*> \\verbatim\n*> DUF is DOUBLE PRECISION array, dimension (N-1)\n*> If FACT = 'F', then DUF is an input argument and on entry\n*> contains the (n-1) elements of the first superdiagonal of U.\n*>\n*> If FACT = 'N', then DUF is an output argument and on exit\n*> contains the (n-1) elements of the first superdiagonal of U.\n*> \\endverbatim\n*>\n*> \\param[in,out] DU2\n*> \\verbatim\n*> DU2 is DOUBLE PRECISION array, dimension (N-2)\n*> If FACT = 'F', then DU2 is an input argument and on entry\n*> contains the (n-2) elements of the second superdiagonal of\n*> U.\n*>\n*> If FACT = 'N', then DU2 is an output argument and on exit\n*> contains the (n-2) elements of the second superdiagonal of\n*> U.\n*> \\endverbatim\n*>\n*> \\param[in,out] IPIV\n*> \\verbatim\n*> IPIV is INTEGER array, dimension (N)\n*> If FACT = 'F', then IPIV is an input argument and on entry\n*> contains the pivot indices from the LU factorization of A as\n*> computed by DGTTRF.\n*>\n*> If FACT = 'N', then IPIV is an output argument and on exit\n*> contains the pivot indices from the LU factorization of A;\n*> row i of the matrix was interchanged with row IPIV(i).\n*> IPIV(i) will always be either i or i+1; IPIV(i) = i indicates\n*> a row interchange was not required.\n*> \\endverbatim\n*>\n*> \\param[in] B\n*> \\verbatim\n*> B is DOUBLE PRECISION array, dimension (LDB,NRHS)\n*> The N-by-NRHS right hand side matrix B.\n*> \\endverbatim\n*>\n*> \\param[in] LDB\n*> \\verbatim\n*> LDB is INTEGER\n*> The leading dimension of the array B. LDB >= max(1,N).\n*> \\endverbatim\n*>\n*> \\param[out] X\n*> \\verbatim\n*> X is DOUBLE PRECISION array, dimension (LDX,NRHS)\n*> If INFO = 0 or INFO = N+1, the N-by-NRHS solution matrix X.\n*> \\endverbatim\n*>\n*> \\param[in] LDX\n*> \\verbatim\n*> LDX is INTEGER\n*> The leading dimension of the array X. LDX >= max(1,N).\n*> \\endverbatim\n*>\n*> \\param[out] RCOND\n*> \\verbatim\n*> RCOND is DOUBLE PRECISION\n*> The estimate of the reciprocal condition number of the matrix\n*> A. If RCOND is less than the machine precision (in\n*> particular, if RCOND = 0), the matrix is singular to working\n*> precision. This condition is indicated by a return code of\n*> INFO > 0.\n*> \\endverbatim\n*>\n*> \\param[out] FERR\n*> \\verbatim\n*> FERR is DOUBLE PRECISION array, dimension (NRHS)\n*> The estimated forward error bound for each solution vector\n*> X(j) (the j-th column of the solution matrix X).\n*> If XTRUE is the true solution corresponding to X(j), FERR(j)\n*> is an estimated upper bound for the magnitude of the largest\n*> element in (X(j) - XTRUE) divided by the magnitude of the\n*> largest element in X(j). The estimate is as reliable as\n*> the estimate for RCOND, and is almost always a slight\n*> overestimate of the true error.\n*> \\endverbatim\n*>\n*> \\param[out] BERR\n*> \\verbatim\n*> BERR is DOUBLE PRECISION array, dimension (NRHS)\n*> The componentwise relative backward error of each solution\n*> vector X(j) (i.e., the smallest relative change in\n*> any element of A or B that makes X(j) an exact solution).\n*> \\endverbatim\n*>\n*> \\param[out] WORK\n*> \\verbatim\n*> WORK is DOUBLE PRECISION array, dimension (3*N)\n*> \\endverbatim\n*>\n*> \\param[out] IWORK\n*> \\verbatim\n*> IWORK is INTEGER array, dimension (N)\n*> \\endverbatim\n*>\n*> \\param[out] INFO\n*> \\verbatim\n*> INFO is INTEGER\n*> = 0: successful exit\n*> < 0: if INFO = -i, the i-th argument had an illegal value\n*> > 0: if INFO = i, and i is\n*> <= N: U(i,i) is exactly zero. The factorization\n*> has not been completed unless i = N, but the\n*> factor U is exactly singular, so the solution\n*> and error bounds could not be computed.\n*> RCOND = 0 is returned.\n*> = N+1: U is nonsingular, but RCOND is less than machine\n*> precision, meaning that the matrix is singular\n*> to working precision. Nevertheless, the\n*> solution and error bounds are computed because\n*> there are a number of situations where the\n*> computed solution can be more accurate than the\n*> value of RCOND would suggest.\n*> \\endverbatim\n*\n* Authors:\n* ========\n*\n*> \\author Univ. of Tennessee\n*> \\author Univ. of California Berkeley\n*> \\author Univ. of Colorado Denver\n*> \\author NAG Ltd.\n*\n*> \\ingroup doubleGTsolve\n*\n* =====================================================================\n SUBROUTINE DGTSVX( FACT, TRANS, N, NRHS, DL, D, DU, DLF, DF, DUF,\n $ DU2, IPIV, B, LDB, X, LDX, RCOND, FERR, BERR,\n $ WORK, IWORK, INFO )\n*\n* -- LAPACK driver routine --\n* -- LAPACK is a software package provided by Univ. of Tennessee, --\n* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--\n*\n* .. Scalar Arguments ..\n CHARACTER FACT, TRANS\n INTEGER INFO, LDB, LDX, N, NRHS\n DOUBLE PRECISION RCOND\n* ..\n* .. Array Arguments ..\n INTEGER IPIV( * ), IWORK( * )\n DOUBLE PRECISION B( LDB, * ), BERR( * ), D( * ), DF( * ),\n $ DL( * ), DLF( * ), DU( * ), DU2( * ), DUF( * ),\n $ FERR( * ), WORK( * ), X( LDX, * )\n* ..\n*\n* =====================================================================\n*\n* .. Parameters ..\n DOUBLE PRECISION ZERO\n PARAMETER ( ZERO = 0.0D+0 )\n* ..\n* .. Local Scalars ..\n LOGICAL NOFACT, NOTRAN\n CHARACTER NORM\n DOUBLE PRECISION ANORM\n* ..\n* .. External Functions ..\n LOGICAL LSAME\n DOUBLE PRECISION DLAMCH, DLANGT\n EXTERNAL LSAME, DLAMCH, DLANGT\n* ..\n* .. External Subroutines ..\n EXTERNAL DCOPY, DGTCON, DGTRFS, DGTTRF, DGTTRS, DLACPY,\n $ XERBLA\n* ..\n* .. Intrinsic Functions ..\n INTRINSIC MAX\n* ..\n* .. Executable Statements ..\n*\n INFO = 0\n NOFACT = LSAME( FACT, 'N' )\n NOTRAN = LSAME( TRANS, 'N' )\n IF( .NOT.NOFACT .AND. .NOT.LSAME( FACT, 'F' ) ) THEN\n INFO = -1\n ELSE IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) .AND. .NOT.\n $ LSAME( TRANS, 'C' ) ) THEN\n INFO = -2\n ELSE IF( N.LT.0 ) THEN\n INFO = -3\n ELSE IF( NRHS.LT.0 ) THEN\n INFO = -4\n ELSE IF( LDB.LT.MAX( 1, N ) ) THEN\n INFO = -14\n ELSE IF( LDX.LT.MAX( 1, N ) ) THEN\n INFO = -16\n END IF\n IF( INFO.NE.0 ) THEN\n CALL XERBLA( 'DGTSVX', -INFO )\n RETURN\n END IF\n*\n IF( NOFACT ) THEN\n*\n* Compute the LU factorization of A.\n*\n CALL DCOPY( N, D, 1, DF, 1 )\n IF( N.GT.1 ) THEN\n CALL DCOPY( N-1, DL, 1, DLF, 1 )\n CALL DCOPY( N-1, DU, 1, DUF, 1 )\n END IF\n CALL DGTTRF( N, DLF, DF, DUF, DU2, IPIV, INFO )\n*\n* Return if INFO is non-zero.\n*\n IF( INFO.GT.0 )THEN\n RCOND = ZERO\n RETURN\n END IF\n END IF\n*\n* Compute the norm of the matrix A.\n*\n IF( NOTRAN ) THEN\n NORM = '1'\n ELSE\n NORM = 'I'\n END IF\n ANORM = DLANGT( NORM, N, DL, D, DU )\n*\n* Compute the reciprocal of the condition number of A.\n*\n CALL DGTCON( NORM, N, DLF, DF, DUF, DU2, IPIV, ANORM, RCOND, WORK,\n $ IWORK, INFO )\n*\n* Compute the solution vectors X.\n*\n CALL DLACPY( 'Full', N, NRHS, B, LDB, X, LDX )\n CALL DGTTRS( TRANS, N, NRHS, DLF, DF, DUF, DU2, IPIV, X, LDX,\n $ INFO )\n*\n* Use iterative refinement to improve the computed solutions and\n* compute error bounds and backward error estimates for them.\n*\n CALL DGTRFS( TRANS, N, NRHS, DL, D, DU, DLF, DF, DUF, DU2, IPIV,\n $ B, LDB, X, LDX, FERR, BERR, WORK, IWORK, INFO )\n*\n* Set INFO = N+1 if the matrix is singular to working precision.\n*\n IF( RCOND.LT.DLAMCH( 'Epsilon' ) )\n $ INFO = N + 1\n*\n RETURN\n*\n* End of DGTSVX\n*\n END\n", "meta": {"hexsha": "ec8df80bb616b4215e9d12dd21eace7eb3f01f47", "size": 13897, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "SRC/dgtsvx.f", "max_stars_repo_name": "sergey-v-kuznetsov/lapack", "max_stars_repo_head_hexsha": "799ef93faa5878aa8702f7cf9980cfc649cc39cc", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": 998, "max_stars_repo_stars_event_min_datetime": "2016-05-04T20:50:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T17:43:13.000Z", "max_issues_repo_path": "SRC/dgtsvx.f", "max_issues_repo_name": "sergey-v-kuznetsov/lapack", "max_issues_repo_head_hexsha": "799ef93faa5878aa8702f7cf9980cfc649cc39cc", "max_issues_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_issues_count": 603, "max_issues_repo_issues_event_min_datetime": "2016-06-04T07:28:21.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T21:16:50.000Z", "max_forks_repo_path": "SRC/dgtsvx.f", "max_forks_repo_name": "sergey-v-kuznetsov/lapack", "max_forks_repo_head_hexsha": "799ef93faa5878aa8702f7cf9980cfc649cc39cc", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_forks_count": 373, "max_forks_repo_forks_event_min_datetime": "2016-06-04T06:05:24.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T17:25:45.000Z", "avg_line_length": 33.7305825243, "max_line_length": 111, "alphanum_fraction": 0.5481758653, "num_tokens": 3974, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008906, "lm_q2_score": 0.7185943925708561, "lm_q1q2_score": 0.6500768017597244}} {"text": " FUNCTION hmin(x)\r\n!---------------------------------------------------\r\n!*** calculates minimum height of a tetrahedron\r\n!---------------------------------------------------\r\n\r\n IMPLICIT NONE\r\n REAL(kind=8):: hmin, x(3,4)\r\n\r\n REAL(kind=8):: vol\r\n\r\n REAL(kind=8) :: x1(3),x2(3),x3(3),xp(3),h(4),a\r\n\r\n x1(:) = x(:,2)-x(:,1)\r\n x2(:) = x(:,3)-x(:,1)\r\n x3(:) = x(:,4)-x(:,1)\r\n CALL vecpro(x1,x2,xp)\r\n vol = DOT_PRODUCT(x3,xp)\r\n vol = vol/6.d0\r\n a = SQRT(DOT_PRODUCT(xp,xp)) / 2d0\r\n h(1) = 3d0 * vol / a\r\n\r\n x1(:) = x(:,3)-x(:,2)\r\n x2(:) = x(:,4)-x(:,2)\r\n CALL vecpro(x1,x2,xp)\r\n a = SQRT(DOT_PRODUCT(xp,xp)) / 2d0\r\n h(2) = 3d0 * vol / a\r\n\r\n x1(:) = x(:,4)-x(:,1)\r\n x2(:) = x(:,2)-x(:,1)\r\n CALL vecpro(x1,x2,xp)\r\n a = SQRT(DOT_PRODUCT(xp,xp)) / 2d0\r\n h(3) = 3d0 * vol / a\r\n\r\n x1(:) = x(:,3)-x(:,1)\r\n x2(:) = x(:,4)-x(:,1)\r\n CALL vecpro(x1,x2,xp)\r\n a = SQRT(DOT_PRODUCT(xp,xp)) / 2d0\r\n h(4) = 3d0 * vol / a\r\n\r\n hmin = MIN (h(1), h(2), h(3), h(4))\r\n\r\n END FUNCTION hmin\r\n", "meta": {"hexsha": "a830c5c185c4be44f29dbb255d41112c40d7576c", "size": 1115, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/rigid/hmin.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/rigid/hmin.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/rigid/hmin.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": 25.9302325581, "max_line_length": 53, "alphanum_fraction": 0.3739910314, "num_tokens": 439, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008906, "lm_q2_score": 0.7185943925708561, "lm_q1q2_score": 0.6500768017597244}} {"text": "subroutine INPUT\r\n use simsphere_mod\r\n implicit none\r\n\r\n! ** Modified 8/14/90 >> Modified Hi (SKONST / S).\r\n\r\n! ** Subroutine INPUT computes solar radiation as a function of the\r\n! ** day, season, atmospheric attenuation, and albedo.\r\n\r\n! real(kind=8) :: EFFDEC, SOLSIN\r\n real :: EFFDEC=0.0, SOLSIN=0.0\r\n real :: SS(12)\r\n integer :: MD(12)\r\n\r\n! Don't need to declare FTABS, FBSCAT, FTSCAT -- subroutine rewritten as function\r\n! real :: FTABS, FBSCAT, FTSCAT, RM, S, N\r\n real :: RM=0.0, S=0.0, N=0.0, RLPATH=0.0, PATH=0.0\r\n real :: TABS=0.0, BSCAT=0.0, TSCAT=0.0, TABSD=0.0, BSCATD=0.0, TSCATD=0.0\r\n real :: DF=0.0, DE=0.0, SIG=0.0, EQT=0.0, HRANGL=0.0, SLB=0.0, SHEAT=0.0, HI=0.0, XSER=0.0, SOLEL=0.0\r\n real :: sinsolelslope=0.0, solelslope=0.0, GMT=0.0\r\n real, parameter :: skonst = 1.94*4.1868e4/60\r\n integer :: IMO1=0, JMO=0, I=0, K=0, DAD=0\r\n\r\n! INCLUDE 'modvars.h'\r\n\r\n! ** The definition of the variables in the following DATA statements\r\n! ** can be found in the manual.\r\n\r\n DATA MD / 31 , 29 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30, 31/\r\n DATA SS / 0.967 , 0.971 , 0.982 , 0.999 , 1.016 , 1.029 , 1.034, &\r\n 1.030 , 1.018 , 1.002 , 0.985 , 0.973 /\r\n\r\n! ** Y ...Counter for determining celestial mechanics for long, lat and\r\n! ** time of year.\r\n\r\n IF ( Y /= 1 ) GO TO 19\r\n Y = Y + 1\r\n\r\n IMO1 = IMO + 1\r\n IF (IMO1 == 13) IMO1 = 1\r\n\r\n! ** Compute the solar distance factor.\r\n\r\n RM = FLOAT( IDAY - 1 ) / FLOAT( MD ( IMO ) )\r\n S = SS( IMO ) + RM * (SS( IMO1 ) - SS( IMO ) )\r\n\r\n! ** Set up the number of the day in the year (DAD).\r\n\r\n K = IDAY\r\n JMO = IMO - 1\r\n IF ( JMO < 1 ) GO TO 12\r\n do I = 1 , JMO\r\n K = K + MD(I)\r\n end do\r\n12 N = IYR / 4\r\n N = IYR - N * 4\r\n IF (N /= 0 .AND. K >= 60) K = K - 1\r\n DAD = K - 1\r\n\r\n! ** Calculate the angular fraction of a year, convert to radians.\r\n\r\n DF = DAD * 360 / 365.242\r\n DE = real(DF / RADIAN,4)\r\n\r\n! ** Correction to declination caused by elliptical orbit.\r\n\r\n SIG = SIGA + DF + 1.914827 * SIN( DE ) - 0.079525 * COS( DE ) &\r\n & + 0.019938 * SIN( DE * 2 ) - 0.00162 * COS( DE * 2 )\r\n SIG = real(SIG / RADIAN,4)\r\n\r\n! ** Declination of the sun.\r\n\r\n EFFDEC = real(ASIN( SDEC * SIN( SIG ) ),4)\r\n\r\n! ** True solar noon.\r\n\r\n EQT = 0.12357 * SIN( DE ) - 0.004289 * COS( DE ) &\r\n & + 0.153809 * SIN( DE * 2 ) + 0.060783 * COS( DE * 2 )\r\n EQT = EQT + 12\r\n\r\n19 CONTINUE\r\n\r\n! ** Calc time in Greenwich Mean Time.\r\n\r\n GMT = PTIME + TZ\r\n\r\n! Calculate the solar hour angle in radians.\r\n\r\n HRANGL = 15 * ( GMT - EQT ) - XLONG\r\n HRANGL = real(HRANGL / RADIAN,4)\r\n\r\n! Now we can finally compute the solar elevation angle.\r\n\r\n SLB = real(XLAT / RADIAN,4)\r\n SOLSIN = SIN(EFFDEC)*SIN(SLB)+COS(EFFDEC)*COS(SLB)*COS(HRANGL)\r\n SOLEL = real(ASIN( SOLSIN ) * RADIAN,4)\r\n\r\n if (SLOPE > 0) then\r\n call sslope (sinsolelslope,solelslope,effdec,slb,hrangl)\r\n else\r\n call albedo (solsin)\r\n sinsolelslope = solsin\r\n end if\r\n\r\n! If the solar altitude is less that or equal to zero it's night so\r\n! return, otherwise compute absolute optical air mass (PATH).\r\n\r\n IF ( SOLEL <= 0 ) THEN\r\n SWAVE = 0\r\n RETURN\r\n END IF\r\n\r\n RLPATH = ( SOLSIN + 0.15 * ( SOLEL + 3.885 ) ** (-1.253) ) ** (-1)\r\n! if (rlpath < 1.0) rlpath = 1.0 \r\n PATH = 0.001 * PS1 * RLPATH\r\n SOLEL = real(SOLEL / RADIAN,4)\r\n\r\n! write(*,*) 'SOLSIN: ',SOLSIN, ' SOLEL: ',SOLEL,' RLPATH: ',RLPATH,' PATH: ',PATH\r\n!TJC These lines moved to functions in module: ftabsT, ftscatT, fbscatT\r\n! CALL TRANSM (RLPATH,FTABS,FTSCAT,FBSCAT)\r\n\r\n! Store values for use.\r\n\r\n! TABS = FTABS\r\n! TSCAT = FTSCAT\r\n! BSCAT = FBSCAT\r\n\r\n if ( RLPATH == RLPATH ) then\r\n TABS = ftabsT(RLPATH)\r\n TSCAT = ftscatT(RLPATH)\r\n BSCAT = fbscatT(RLPATH)\r\n else\r\n write(*,*) 'RLPATH is NaN, input.f90:128'\r\n stop\r\n end if\r\n\r\n!TJC End\r\n\r\n! Set the PATH length for diffuse radiation equal to 1.7.\r\n\r\n PATH = 1.7\r\n\r\n!TJC These lines moved to functions in module: ftabsT, ftscatT, fbscatT\r\n! CALL TRANSM (PATH,FTABS,FTSCAT,FBSCAT)\r\n!\r\n!! Again store values for use.\r\n!\r\n! TABSD = FTABS\r\n! TSCATD = FTSCAT\r\n! BSCATD = FBSCAT\r\n\r\n TABSD = ftabsT(PATH)\r\n TSCATD = ftscatT(PATH)\r\n BSCATD = fbscatT(PATH)\r\n\r\n!TJC End\r\n\r\n! ** SHEAT >>> Sunlight amount on horizontal plane outside atmosphere\r\n! ** XSER >>> Diffuse Shortwave Radiation at the ground.\r\n! ** HI >>> Direct SW Radiation reaching the ground.\r\n! ** SWAVE >>> Diffuse + Direct = 'Global'\r\n\r\n if (S /= 0) SHEAT = SKONST * sinsolelslope / S\r\n XSER = BSCATD * ALBDOE * ( 1 - TSCATD ) * TABSD * SIN( SOLEL )\r\n if (S /= 0) HI = ( SHEAT * TABS * TSCAT ) + ( SKONST / S* TABS * ( 1 - TSCAT ) &\r\n& * ( 1 - BSCAT ) ) * SIN( SOLEL )\r\n if (XSER /= 1.0) then\r\n SWAVE = ( HI * ( 1 - ALBDOE ) ) / ( 1.0 - XSER )\r\n else\r\n write(*,*) 'Attempted divide by zero: input.f90:168'\r\n stop\r\n end if\r\n \r\n\r\n IF(CLOUD_FLAG) SWAVE = SWAVE*(1-(0.7*(0.1*CLD_FRACT)))\r\n ! impose cloud fraction; reduce swave according to cloud amount\r\n ! Note: forcing real arithmetic\r\n\r\n return\r\nend\r\n\r\n\r\n", "meta": {"hexsha": "0f93b3beb99e48fca930ac3d686444ff6e913bb2", "size": 5089, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/input.f90", "max_stars_repo_name": "aap1/simsphere", "max_stars_repo_head_hexsha": "b35ab1c67902f935264900c950cd42b6e96c4574", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2019-11-04T05:08:50.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T04:19:21.000Z", "max_issues_repo_path": "src/input.f90", "max_issues_repo_name": "aap1/simsphere", "max_issues_repo_head_hexsha": "b35ab1c67902f935264900c950cd42b6e96c4574", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 17, "max_issues_repo_issues_event_min_datetime": "2018-10-04T15:35:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-06T15:15:02.000Z", "max_forks_repo_path": "src/input.f90", "max_forks_repo_name": "aap1/simsphere", "max_forks_repo_head_hexsha": "b35ab1c67902f935264900c950cd42b6e96c4574", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2018-10-06T18:43:14.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-01T01:33:53.000Z", "avg_line_length": 27.8087431694, "max_line_length": 104, "alphanum_fraction": 0.5700530556, "num_tokens": 1995, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505325302034, "lm_q2_score": 0.718594386544335, "lm_q1q2_score": 0.6500767944605476}} {"text": "c ============================================\n subroutine setaux(mbc,mx,my,xlower,ylower,dxc,dyc,\n & maux,aux)\nc ============================================\nc\nc # set auxiliary arrays for advection on a curvilinear grid\nc\nc # on input, (xc(i),yc(j)) gives uniformly spaced computational grid.\nc # on output, \nc # aux(1,i,j) is edge velocity at \"left\" boundary of grid point (i,j)\nc # aux(2,i,j) is edge velocity at \"bottom\" boundary of grid point (i,j)\nc # aux(3,i,j) = kappa is ratio of cell area to dxc*dyc\nc \n implicit double precision (a-h,o-z)\n double precision, intent(inout), \n & dimension(3, 1-mbc:mx+mbc,1-mbc:my+mbc) :: aux\n dimension xccorn(5),yccorn(5),xpcorn(5),ypcorn(5)\nc\nc\n do 20 j=1-mbc,my+mbc\n do 20 i=1-mbc,mx+mbc\nc\nc # computational points (xc,yc) are mapped to physical\nc # coordinates (xp,yp) by mapc2p:\nc\nc # lower left corner:\n\t xccorn(1) = xlower + (i-1)*dxc\n\t yccorn(1) = ylower + (j-1)*dyc\n\t call mapc2p(xccorn(1),yccorn(1),xpcorn(1),ypcorn(1))\n\nc # upper left corner:\n\t xccorn(2) = xccorn(1)\n\t yccorn(2) = yccorn(1) + dyc\n\t call mapc2p(xccorn(2),yccorn(2),xpcorn(2),ypcorn(2))\nc\nc # upper right corner:\n\t xccorn(3) = xccorn(1) + dxc\n\t yccorn(3) = yccorn(1) + dyc\n\t call mapc2p(xccorn(3),yccorn(3),xpcorn(3),ypcorn(3))\nc\nc # lower right corner:\n\t xccorn(4) = xccorn(1) + dxc\n\t yccorn(4) = yccorn(1)\n \tcall mapc2p(xccorn(4),yccorn(4),xpcorn(4),ypcorn(4))\nc\nc\nc # compute edge velocities by differencing stream function:\nc\n\t aux(1,i,j) = (stream(xpcorn(2),ypcorn(2))\n &\t\t\t - stream(xpcorn(1),ypcorn(1)))/ dyc\nc\n\t aux(2,i,j) = -(stream(xpcorn(4),ypcorn(4))\n &\t\t\t - stream(xpcorn(1),ypcorn(1)))/ dxc\n\nc\nc\nc # compute area of physical cell from four corners:\n\n\t xpcorn(5) = xpcorn(1)\n\t ypcorn(5) = ypcorn(1)\n\t area = 0.d0\n\t do ic=1,4\n\t area = area + 0.5d0 * (ypcorn(ic)+ypcorn(ic+1)) *\n & (xpcorn(ic+1)-xpcorn(ic))\n\t enddo\n\t \n\t aux(3,i,j) = area / (dxc*dyc)\nc\n 20 continue\nc\n return\n\n end\n", "meta": {"hexsha": "c2810ef913842984751231a35321092d5e2bb4cd", "size": 2218, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "docker/src/clawpack-5.3.1/amrclaw/tests/advection_2d_annulus/setaux.f", "max_stars_repo_name": "ian-r-rose/visualization", "max_stars_repo_head_hexsha": "ed6d9fab95eb125e7340ab3fad3ed114ed3214af", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2017-01-04T18:19:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-21T01:46:33.000Z", "max_issues_repo_path": "docker/src/clawpack-5.3.1/amrclaw/tests/advection_2d_annulus/setaux.f", "max_issues_repo_name": "ian-r-rose/visualization", "max_issues_repo_head_hexsha": "ed6d9fab95eb125e7340ab3fad3ed114ed3214af", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2016-09-22T20:49:51.000Z", "max_issues_repo_issues_event_max_datetime": "2019-09-06T23:28:13.000Z", "max_forks_repo_path": "docker/src/clawpack-5.3.1/amrclaw/tests/advection_2d_annulus/setaux.f", "max_forks_repo_name": "ian-r-rose/visualization", "max_forks_repo_head_hexsha": "ed6d9fab95eb125e7340ab3fad3ed114ed3214af", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 13, "max_forks_repo_forks_event_min_datetime": "2016-09-22T20:20:06.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-13T14:48:32.000Z", "avg_line_length": 29.972972973, "max_line_length": 78, "alphanum_fraction": 0.5378719567, "num_tokens": 824, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505325302034, "lm_q2_score": 0.718594386544335, "lm_q1q2_score": 0.6500767944605476}} {"text": " implicit double precision (a-h,o-z)\n common /factl/ fact(0:100)\n common /herm/ h(0:100)\n dimension wf(0:100)\n pi=4.0d0*datan(1.0d0)\n read(*,*)nmax\n call factorial(nmax)\n nx=100\n xmin=-5.d0\n xmax=+5.d0\n xinc=(xmax-xmin)/nx\n x=xmin\n do i=1,nx+1\n call hermite(nmax,x)\n do n=0,nmax\n wf(n)=dsqrt(1.0d0/(2.0d0**n*dsqrt(pi)*fact(n)))*\n & dexp(-x*x/2.0d0)*h(n) \n end do\n write(*,'(1x,f5.2,101f12.6)')x,(wf(n),n=0,nmax)\n x=x+xinc\n end do\n\n end\n\n subroutine factorial(n)\n implicit double precision (a-h,o-z)\n common /factl/ fact(0:100)\n fact(0)=1\n do i=1,n\n fact(i)=fact(i-1)*i\n end do\n end\n\n subroutine hermite(n,x)\n implicit real*8 (a-h,o-z)\n common /herm/ h(0:100)\n h(0)=1.0d0\n h(1)=2.0d0*x\n do i=2,n\n h(i)=2.0d0*x*h(i-1)-2.0d0*(i-1)*h(i-2)\n end do\n end\n\n \n", "meta": {"hexsha": "6f3cd0c0a4cdcf7becc8bcd07113960f4077e34a", "size": 1008, "ext": "for", "lang": "FORTRAN", "max_stars_repo_path": "aru/howf.for", "max_stars_repo_name": "deadbeatfour/phn624-comp-nuc-phy", "max_stars_repo_head_hexsha": "deaeaac5240a1f33425c4ca50539aee4fae2f370", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "aru/howf.for", "max_issues_repo_name": "deadbeatfour/phn624-comp-nuc-phy", "max_issues_repo_head_hexsha": "deaeaac5240a1f33425c4ca50539aee4fae2f370", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "aru/howf.for", "max_forks_repo_name": "deadbeatfour/phn624-comp-nuc-phy", "max_forks_repo_head_hexsha": "deaeaac5240a1f33425c4ca50539aee4fae2f370", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.4, "max_line_length": 60, "alphanum_fraction": 0.4613095238, "num_tokens": 388, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.718594386544335, "lm_q1q2_score": 0.6500767926132661}} {"text": "c--------------------------------------------------------\r\nc This program uses a semi-implicit representation of\r\nc the nonlinearities along with up- and down- winding\r\nc in regions where \\psi_y=u is +ve or -ve respectively\r\nc The flow is periodic in x and also odd about x=pi\r\nc The latter condition is enforced in the finite-differences.\r\nc 2nd order upwind and downwind formulas are used.\r\nc--------------------------------------------------------\r\nc\r\nc NOTE that the BC here psi_\\eta = - sin(x)\r\nc Here the solution is computed on the full y range [-1,1]\r\nc----------------------------------------------------------\r\nc Gursh-Edited the code to make memory consumption minimal via\r\nc introducing INX and INN\r\nc \r\nc In this version of the code, the solution for Psi is calculated\r\nc by using Finite differences and upwind differencing in the \r\nc x-direction. Moreover, the x domain is [0,pi] and NOT [0,2pi]\r\n\r\n\r\n implicit double precision(a-h,o-y)\r\n implicit complex*16(z)\r\n integer INX, INN\r\n parameter(INX=265,INN=110)\r\n\r\n\r\n dimension a(INN),b(INN),c(INN),d(INN),e(INN)\r\n dimension r(INN),x(INN),y(INN),u(INN),v(INN),xx(INX)\r\n dimension psi(INX,0:INN),psi1(INX,0:INN),shp(INX)\r\n $,psix(INX,0:INN), zvhp(INX), zuhp(INX),\r\n $ uhm(INX),vhm(INX),uhp(INX),vhp(INX),uh0(INX),vh0(INX),\r\n $ psit(10), psitimes(5), periods(5)\r\n\r\n \r\n open(1,file='input',status='old')\r\nc open(2,file='en.m',status='unknown')\r\nc open(3,file='u1.m',status='unknown')\r\nc open(4,file='u2.m',status='unknown')\r\nc open(7,file='u3.m',status='unknown')\r\nc open(8,file='v1.m',status='unknown')\r\nc open(9,file='v2.m',status='unknown')\r\nc open(10,file='v3.m',status='unknown')\r\nc open(11,file='final',status='unknown')\r\nc open(13,file='vpi.m',status='unknown')\r\nc open(14,file='v0.m',status='unknown')\r\nc open(20,file='uhm.m',status='unknown')\r\nc open(21,file='vhm.m',status='unknown')\r\nc open(22,file='uhp.m',status='unknown')\r\nc open(23,file='vhp.m',status='unknown')\r\nc open(24,file='uh0.m',status='unknown')\r\nc open(25,file='vh0.m',status='unknown')\r\nc open(30,file='psi.m',status='unknown')\r\nc open(31,file='sum.m',status='unknown')\r\n open(32,file='psifin.m',status='unknown')\r\n \r\n\r\n read(1,*) n\r\n read(1,*) nx\r\n read(1,*) dt\r\n read(1,*) nmax\r\n read(1,*) rm\r\n read(1,*) tmax\r\n read(1,*) tstart\r\n read(1,*) papstart\r\n read(1,*) nstore\r\n read(1,*) nwrite\r\n read(1,*) icont\r\n read(1,*) iphase\r\n read(1,*) ipap\r\n\r\n write(6,*) 'Rey=',rm,' Tmax=',tmax,' dt=', dt,' Nx=',nx,\r\n # ' Ny=', n\r\n write(6,*) 'Max Iter=', nmax\r\n\r\nc-----computational parameters-------------------------------\r\nc h=step in the y-direction\r\nc dx=step in the x-direction\r\nc (n+1) points in the y-direction\r\nc (nx+1) points in the x-direction\r\n \r\n if((INN.lt.(n+5)).or.(inx.lt.(nx+5))) then\r\n write(6,*), 'INN or INX too small in code -increase them'\r\n end if\r\n\r\nc change value of h\r\n h=2.d0/float(n+1)\r\n h2=h**2\r\n h3=h**3\r\n h4=h**4\r\n api=4.d0*datan(1.d0)\r\n dx=api/float(nx)\r\n aa1=DBLE(dt/(rm*h*h))\r\n aa2=dt/(4.*h*dx)\r\n aw=-1.d0\r\n bw=-1.d0\r\n nx1=nx/8\r\n nx2=nx/4\r\n nx3=3*nx/8\r\n nm=1+(n+1)/4\r\n np=1+3*(n+1)/4\r\n n0=1+(n+1)/2\r\n ixp=10\r\n nspec=1/dt\r\n flush_time=5.0\r\n \r\n tol=1.d-8\r\n do 91 i=1,10\r\n 91 psit(i)=-1\r\n \r\n\r\n \r\n\r\n\r\nc------------------------------------------------------------\r\nc1234 continue\r\n if(icont.eq.1) goto 88\r\n\r\nc--- Set up initial conditions --------------------------------\r\n t=0.d0\r\n 3 continue\r\n do 19 i=1,nx\r\n xx(i)=dx*(i-1)\r\n do 1 j=1,n+2\r\n y(j)=-1.d0+h*(j-1)\r\n psi(i+2,j)=0.\r\nc1 psi(i,j)=sin(api*y(j))*sin(xx(i))/api\r\n 1 psi(i,j)=.5d0*(y(j)-y(j)*y(j)*y(j))*sin(xx(i))\r\n 19 continue\r\n do 44 i=1,nx\r\nc change value derivative\r\n psi(i,0)=psi(i,2)-2.d0*h*aw*sin(dx*(i-1))\r\n psi(i,n+3)=psi(i,n+1)+2.d0*h*bw*sin(dx*(i-1))\r\nc psi(i,n+3)=-psi(i,n+1)\r\n psi(i,1)=0.d0\r\n psi(i,n+2)=0.d0\r\n 44 continue\r\n goto 89\r\nc-------------------------------------------------------------\r\n\r\nc-- the following are the read initial conditions for continuation\r\n 88 read(11,*) t\r\n do 656 j=0,n+3\r\n read(40,1024) (psi(i,j),i=1,nx)\r\n 656 continue\r\nc---------------------------------------------------------------\r\n\r\n 89 continue\r\n\r\nc---Time loop ---------------------------------------------------\r\n\r\n do 4 iu=1,nmax\r\n\r\n\r\nc--- set up psix(i,j) the derivative psi_x, pseudospectrally\r\n\r\n do 350 j=2,n+1\r\n do 354 i=2,(nx-1)\r\n psix(i,j)=0.5*(psi(i+1,j)-psi(i-1,j))/dx\r\nc---- winding on the psi_x derivative\r\n if( (j.gt.2).and.(j.lt.n)) then\r\n if ((-0.5*psi(i,j-2)+psi(i,j-1)-psi(i,j+1)\r\n &+0.5*psi(i,j+2)).lt.0.0) then \r\n psix(i,j) = (psi(i+1,j)-psi(i,j))/dx \r\n elseif((-0.5*psi(i,j-2)+psi(i,j-1)-psi(i,j+1)\r\n &+0.5*psi(i,j+2)).gt.0.0) then \r\n psix(i,j) = (psi(i,j)-psi(i-1,j))/dx\r\n endif\r\n endif \r\n 354 continue \r\nc--- need these derivatives to be second order one-sided \r\nc--- infact the value of psix(1,j) is always multiplied by zero\r\nc--- therefore the accuracy of this term is unimportant\r\nc--- Note psi(nx+1,j)=0 is imposed so that psix(nx,j) is 2nd order\r\n psix(1,j)=psi(2,j)/dx\r\n psix(nx,j)=0.5*(0.d0-psi(nx-1,j))/dx\r\n 350 continue\r\n\r\n do 355 i=1,nx\r\n psix(i,1)=0.d0\r\n 355 psix(i,n+2)=0.d0\r\n\r\nc--- psix(i,j) is a real valued array equal to psi_x\r\n\r\n\r\n do 55 ix=1,nx\r\n\r\nc---- loop in y-direction ii=2,n+1 (y=-1+h, 1-h)\r\n\r\n do 2 ii=2,n+1\r\n\r\n i=ii-1\r\n \r\n\r\n a(i)=-.5d0*aa1\r\n b(i)=1.d0+2.d0*aa1\r\n c(i)=-2.d0-3.d0*aa1\r\n d(i)=1.d0+2.d0*aa1\r\n e(i)=-.5d0*aa1\r\n\r\nc-----Here psi_yyx is upwinded according to sign of psi_y\r\n if( ((psi(ix,ii+1)-psi(ix,ii-1)).lt.0).or.(ix.eq.1)) then\r\n psiyyxwind= \r\n # (psi(ix+1,ii+1)-psi(ix,ii+1))/dx \r\n # -2.d0*(psi(ix+1,ii)-psi(ix,ii))/dx \r\n # +(psi(ix+1,ii-1)-psi(ix,ii-1))/dx\r\n else\r\n psiyyxwind= \r\n # (psi(ix,ii+1)-psi(ix-1,ii+1))/dx \r\n # -2.d0*(psi(ix,ii)-psi(ix-1,ii))/dx \r\n # +(psi(ix,ii-1)-psi(ix-1,ii-1))/dx\r\n endif \r\n\r\n r(i)=psi(ix,ii+1)-2.d0*psi(ix,ii)+\r\n # psi(ix,ii-1)+.5d0*aa1*(psi(ix,ii+2)\r\n # -4.d0*psi(ix,ii+1)+6.d0*psi(ix,ii)\r\n # -4.d0*psi(ix,ii-1)+psi(ix,ii-2))\r\n # +.5d0*(dt/h)*(\r\n # psix(ix,ii)*(psi(ix,ii+2)-2.d0*psi(ix,ii+1)\r\n # +2.d0*psi(ix,ii-1)-psi(ix,ii-2))\r\n # -(psi(ix,ii+1)-psi(ix,ii-1))\r\n # *psiyyxwind\r\n # )\r\n\r\n 2 continue\r\nc change LU matrix and RHS vector \r\n c(1)=c(1)+a(1)\r\n c(n)=c(n)+e(n)\r\n r(1)=r(1)+2.d0*h*aw*a(1)*sin((ix-1)*dx)\r\n r(n)=r(n)-2.d0*h*bw*e(n)*sin((ix-1)*dx)\r\nc----------------------------------------------------------------\r\nc This is the inversion procedure for the matrix with \r\nc columns a b c d with RHS vector r\r\n\r\n D(1)=D(1)/C(1)\r\n E(1)=E(1)/C(1)\r\n r(1)=r(1)/C(1)\r\n C(2)=C(2)-B(2)*D(1)\r\n D(2)=(D(2)-B(2)*E(1))/C(2)\r\n r(2)=(r(2)-B(2)*r(1))/C(2)\r\n E(2)=E(2)/C(2)\r\n DO 7 I=3,N\r\n B(I)=B(I)-A(I)*D(I-2)\r\n C(I)=C(I)-A(I)*E(I-2)\r\n r(I)=r(I)-A(I)*r(I-2)\r\n C(I)=C(I)-B(I)*D(I-1)\r\n D(I)=(D(I)-B(I)*E(I-1))/C(I)\r\n E(I)=E(I)/C(I)\r\n 7 r(I)=(r(I)-B(I)*r(I-1))/C(I)\r\n X(N)=r(N)\r\n X(N-1)=r(N-1)-D(N-1)*X(N)\r\n NM1=N-2\r\n DO 8 I=1,NM1\r\n K=N-I-1\r\n X(K)=r(K)-D(K)*X(K+1)-E(K)*X(K+2)\r\n 8 CONTINUE\r\n\r\n do 444 i=2,n+1\r\n 444 psi1(ix,i)=x(i-1)\r\n\r\nc change Solution update after inversion \r\n psi1(ix,0)=psi1(ix,2)-2.d0*h*aw*sin(dx*(ix-1))\r\nc psi1(ix,n+3)=-psi1(ix,n+1)\r\n psi1(ix,n+3)=psi1(ix,n+1)+2.d0*h*bw*sin(dx*(ix-1))\r\n psi1(ix,1)=0.d0\r\n psi1(ix,n+2)=0.d0\r\n\r\n 55 continue\r\n t=t+dt\r\n do 555 i=1,nx\r\n do 556 j=0,n+3\r\n 556 psi(i,j)=psi1(i,j)\r\n 555 continue\r\n\r\n\r\n\r\n if((mod(iu,nstore).eq.0).and.(ipap.eq.1).and.(t.gt.papstart)) then\r\n sum=0.d0\r\n sum1=0.d0\r\n sum2=0.d0\r\n sum3=0.d0\r\n sum0=0.d0\r\n do 77 i=2,n+1\r\n v0=-psix(1,i)\r\n vpi=-psix(nx/2,i)\r\n u1=(psi(nx1,i+1)-psi(nx1,i-1))/2.d0/h\r\n v1=-psix(nx1+1,i)\r\n u2=(psi(nx2,i+1)-psi(nx2,i-1))/2.d0/h\r\n v2=-psix(nx2+1,i)\r\n u3=(psi(nx3,i+1)-psi(nx3,i-1))/2.d0/h\r\n v3=-psix(nx3+1,i)\r\n sum0=sum0+h*v0*v0\r\n sum=sum+h*vpi*vpi\r\n sum1=sum1+h*(u1*u1+v1*v1)\r\n sum2=sum2+h*(u2*u2+v2*v2)\r\n sum3=sum3+h*(u3*u3+v3*v3)\r\n 77 continue\r\n sum1=sum1+h*sin((nx1-1)*dx)\r\n sum2=sum2+h*sin((nx2-1)*dx)\r\n sum3=sum3+h*sin((nx1-1)*dx)\r\n sumdif=sum1-sumold\r\n sumold=sum1\r\n sum0=sqrt(sum0)\r\n sum=sqrt(sum)\r\nc write(2,666) t,sum,sum1,sum2,sum3\r\nc write(31,667) t,sum0,sum\r\n write(6,666) t,sum1,sum2,sum3,sumdif\r\nc if(abs(sum).gt.500.d0) stop\r\n if(abs(sum1).gt.100.d0) then\r\n write(6,*) 'sum1 > 100 '\r\n goto 1234\r\n endif\r\n endif\r\n\r\nc--- set up velocity profiles to save ------------------------------\r\n if(mod(iu,nwrite).eq.0) then\r\n\r\nc rewind(3)\r\nc rewind(4)\r\nc rewind(7)\r\nc rewind(8)\r\nc rewind(9)\r\nc rewind(10)\r\nc rewind(11)\r\nc rewind(13)\r\nc rewind(14)\r\nc rewind(20)\r\nc rewind(21)\r\nc rewind(22)\r\nc rewind(23)\r\nc rewind(24)\r\nc rewind(25)\r\n do 9 j=2,n+1\r\n v(j)=(psi(2,j)-psi(nx,j))/2.d0/dx\r\n 9 u(j)=(psi(nx1,j+1)-psi(nx1,j-1))/2.d0/h\r\n v(1)=0.d0\r\n u(1)=aw*sin(dx*(nx1-1))\r\n u(n+2)=bw*sin(dx*(nx1-1))\r\n v(n+2)=0.d0\r\nc write(3,333) (y(i),u(i),i=1,n+2)\r\nc write(8,333) (y(i),v(i),i=1,n+2)\r\n do 10 j=2,n+1\r\n v(j)=(psi(nx1+1,j)-psi(nx1-1,j))/2.d0/dx\r\n 10 u(j)=(psi(nx2,j+1)-psi(nx2,j-1))/2.d0/h\r\n u(1)=aw*sin(dx*(nx2-1))\r\n v(1)=0.d0\r\n u(n+2)=bw*sin(dx*(nx2-1))\r\n v(n+2)=0.d0\r\nc write(4,333) (y(i),u(i),i=1,n+2)\r\nc write(9,333) (y(i),v(i),i=1,n+2)\r\n do 11 j=2,n+1\r\n v(j)=(psi(nx2+1,j)-psi(nx2-1,j))/2.d0/dx\r\n 11 u(j)=(psi(nx3,j+1)-psi(nx3,j-1))/2.d0/h\r\n u(1)=aw*sin(dx*(nx3-1))\r\n v(1)=0.d0\r\n u(n+2)=bw*sin(dx*(nx3-1))\r\n v(n+2)=0.d0\r\nc write(7,333) (y(i),u(i),i=1,n+2)\r\nc write(10,333) (y(i),v(i),i=1,n+2)\r\n do 12 j=2,n+1\r\n 12 v(j)=-psi(nx,j)/dx\r\n v(1)=0.d0\r\n v(n+2)=0.d0\r\nc write(13,333) (y(i),v(i),i=1,n+2)\r\n do 79 j=2,n+1\r\n 79 v(j)=-psi(2,j)/dx\r\n v(1)=0.d0\r\n v(n+2)=0.d0\r\nc write(14,333) (y(i),v(i),i=1,n+2)\r\n do 78 i=1,nx\r\nc change shear\r\nc shp(i)=(psi(i,n+3)-2.d0*psi(i,n+2)+psi(i,n+1))/h/h\r\n shp(i)=(psi(i,0)-2.d0*psi(i,1)+psi(i,2))/h/h\r\n uhm(i)=.5d0*(psi(i,nm+1)-psi(i,nm-1))/h\r\n vhm(i)=-psix(i,nm)\r\n uh0(i)=.5d0*(psi(i,n0+1)-psi(i,n0-1))/h\r\n vh0(i)=-psix(i,n0)\r\n uhp(i)=.5d0*(psi(i,np+1)-psi(i,np-1))/h\r\n 78 vhp(i)=-psix(i,np)\r\nc write(20,333) (xx(i),uhm(i),i=1,nx)\r\nc write(21,333) (xx(i),vhm(i),i=1,nx)\r\nc write(22,333) (xx(i),uhp(i),i=1,nx)\r\nc write(23,333) (xx(i),vhp(i),i=1,nx)\r\nc write(24,333) (xx(i),uh0(i),i=1,nx)\r\nc write(25,333) (xx(i),vh0(i),i=1,nx)\r\nc write(28,333) (xx(i),shp(i),i=1,nx)\r\n \r\n\r\n if((mod(iu,nstore).eq.0).and.(ipap.eq.1).and.(t.gt.papstart)) then\r\n rewind(30)\r\nc write(30,*) t\r\n do 20 j=0,n+3\r\nc 20 write(30,512) (psi(i,j),i=1,nx)\r\nc 20 write(30,1024) (psi(i,j),i=1,nx)\r\n 20 continue \r\n endif\r\nc write(11,*) t \r\n endif\r\n if(mod(iu,nspec).eq.0) then\r\n do 459 i=1,nx\r\n zvhp(i)=vhp(i)\r\n 459 zuhp(i)=uhp(i)\r\nc write(26,333) (i,cdabs(zvhp(i))/nx,i=1,nx/2)\r\nc write(27,333) (i,cdabs(zuhp(i))/nx,i=1,nx/2)\r\n endif\r\n \r\n do 80 i=1,nx\r\n 80 shp(i)=(psi(i,0)-2.d0*psi(i,1)+psi(i,2))/h/h\r\n shpmax=0.\r\n shpmin=0.\r\n do 778 i=1,nx\r\n if(shp(i).gt.shpmax) then \r\n shpmax=shp(i)\r\n imax=i\r\n endif\r\n if(shp(i).lt.shpmin) then \r\n shpmin=shp(i)\r\n imin=i\r\n endif\r\n 778 continue\r\n if((shpmax.gt.9000000).or.(shpmin.lt.-9000000)) then\r\n write(6,*) 'Shear > 9000000'\r\n goto 1234 \r\n endif\r\n \r\n \r\n nearxzero=15*nx/128\r\n nearxpeak=80*nx/128\r\n jval=80*(n+1)/100\r\n psit(4)=0.d0\r\n psit(5)=0.d0\r\n do 92 i=1,n\r\n 92 psit(5)=psit(5)+abs(psi(nearxpeak,i)) \r\n psit(5)=psit(5)*h*0.5\r\n do 93 i=1,nx\r\n 93 psit(4)=psit(4)+abs(psi(i,jval)) \r\n psit(4)=psit(4)*dx\r\n \r\n psit(2)=(psit(4)-psit(1))/dt\r\n if (psit(2)*psit(3).lt.0) then\r\n psitimes(2)=psitimes(1)\r\n psitimes(1)=t\r\n periods(1)= psitimes(1)-psitimes(2)\r\n endif\r\n psit(3)=psit(2)\r\n psit(1)=psit(4)\r\n \r\n psit(7)=(psit(5)-psit(6))/dt\r\n if (psit(7)*psit(8).lt.0) then\r\n psitimes(4)=psitimes(3)\r\n psitimes(3)=t\r\n periods(2)= psitimes(3)-psitimes(4)\r\n endif\r\n psit(8)=psit(7)\r\n psit(6)=psit(5)\r\n \r\n if(mod(iu,nstore).eq.0) then \r\n write(6,94) t, shpmin, shpmax, psit(4), psit(5) \r\n 94 format('SHR',f11.4,f17.10,f16.10,2f13.8)\r\n endif\r\n\r\n if(flush_time.lt.t) then\r\n rewind(32)\r\nc write(32,*) '% Rey=',rm,' Nx=',nx,' Ny=',n,' dt=',dt, \r\nc # ' timemarched for Tmax=',t, ' %Actual Tmax=',tmax\r\n do 221 j=0,n+3\r\n 221 write(32,1024) (psi(i,j),i=1,nx)\r\n CALL FLUSH(32)\r\n flush_time=flush_time+5.0\r\n endif\r\n \r\n \r\n if(t.gt.tmax) goto 999\r\n\r\n4 continue\r\n 999 continue\r\n 1234 continue\r\n write(6,*) 'FINAL t===', t,'Reynolds==',rm\r\nc write(11,*) t\r\n rewind(32)\r\nc-- write(32,*) '% Rey=',rm,' Nx=',nx,' Ny=',n,' dt=',dt, \r\nc-- # ' timemarched for Tmax=',t, ' %Actual Tmax=',tmax\r\n do 220 j=0,n+3\r\nc220 write(32,512) (psi(i,j),i=1,nx)\r\n 220 write(32,1024) (psi(i,j),i=1,nx)\r\nc do 221 j=2,n+3\r\nc 221 write(32,1024) (-psi(i,n+3-j),i=1,nx)\r\n\r\n\r\n 222 format(2x,e13.6,4x,e13.6)\r\n 64 format(3x,64f13.4)\r\n 128 format(2x,128f13.4)\r\n 256 format(2x,256f13.6)\r\n 512 format(2x,512f13.6)\r\n1024 format(2x,1024f17.10)\r\n \r\n 666 format(2x,e13.6,3x,e13.6,3x,e13.6,3x,e13.6,3x,e13.6)\r\n 333 format(2x,e13.6,3x,e13.6)\r\n 334 format(2x,e13.6,3x,e13.6,3x,e13.6)\r\n 667 format(1x,e13.6,4x,e13.6,4x,e13.6)\r\n stop\r\n end\r\n\r\n", "meta": {"hexsha": "b2a11fb9f0cfa849b2dae3e481116b98fbe849aa", "size": 14510, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "sineFDwindfull2021.f", "max_stars_repo_name": "gsagoo/SolvingDifferentialEquations", "max_stars_repo_head_hexsha": "63c2b231b45ad64206a11824198b3d5fe20c062b", "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": "sineFDwindfull2021.f", "max_issues_repo_name": "gsagoo/SolvingDifferentialEquations", "max_issues_repo_head_hexsha": "63c2b231b45ad64206a11824198b3d5fe20c062b", "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": "sineFDwindfull2021.f", "max_forks_repo_name": "gsagoo/SolvingDifferentialEquations", "max_forks_repo_head_hexsha": "63c2b231b45ad64206a11824198b3d5fe20c062b", "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.8469184891, "max_line_length": 73, "alphanum_fraction": 0.4813232254, "num_tokens": 5881, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178944582997, "lm_q2_score": 0.7154240018510025, "lm_q1q2_score": 0.6500470502067885}} {"text": "MODULE QuadraticMap\nIMPLICIT NONE\n\nCONTAINS\nPURE SUBROUTINE QUADRATIC_STEP(a, x, y)\nIMPLICIT NONE\n! Inputs:\n! a -- 12 coefficients for quadratic map\n! x, y -- current point\n!\n! Outputs:\n! x, y -- the point after one iteration\n REAL, DIMENSION(12), INTENT(IN) :: a\n REAL, INTENT(INOUT) :: x, y\n REAL :: tmp, xy, x2, y2\n\n xy = x * y\n x2 = x ** 2\n y2 = y ** 2\n\n tmp = a(1) + a(2) * x + a(3) * y + a(4) * xy + a(5) * x2 + a(6) * y2\n y = a(7) + a(8) * x + a(9) * y + a(10) * xy + a(11) * x2 + a(12) * y2\n x = tmp\n\nEND SUBROUTINE QUADRATIC_STEP\n\nPURE SUBROUTINE LINEAR_STEP(a, x, y, e1, e2, n1, n2)\nIMPLICIT NONE\n! Inputs:\n! a -- 12 coefficients for quadratic map\n! x, y -- current point\n! e1, e2 -- current tangent space orthonormal basis\n!\n! Ouptuts:\n! e1, e2 -- the result of orthonormalization of Jacobian applied to e1 and e2\n! n1, n2 -- norms of (new) e1 and e2 before normalization\n REAL, DIMENSION(12), INTENT(IN) :: a\n REAL, INTENT(IN) :: x, y\n REAL, DIMENSION(2), INTENT(INOUT) :: e1, e2\n REAL, INTENT(OUT) :: n1, n2\n\n REAL, DIMENSION(2, 2) :: jacobian\n REAL, DIMENSION(2) :: e2_rotated\n\n jacobian = J(a, x, y)\n e1 = MATMUL(jacobian, e1)\n e2 = MATMUL(jacobian, e2)\n ! Reorthonormalize\n n1 = NORM2(e1)\n e1 = e1 / n1\n e2_rotated = e2 - DOT_PRODUCT(e2, e1) * e1\n n2 = NORM2(e2_rotated)\n e2 = e2_rotated / n2\n\n CONTAINS\n\n ! Jacobian\n PURE FUNCTION J(a, x, y)\n IMPLICIT NONE\n REAL, DIMENSION(2, 2) :: J\n REAL, DIMENSION(12), INTENT(IN) :: a\n REAL, INTENT(IN) :: x, y\n\n REAL :: dXx, dXy, dYx, dYy\n\n dXx = a(2) + a(4) * y + 2 * a(5) * x\n dXy = a(3) + a(4) * x + 2 * a(6) * y\n dYx = a(8) + a(10) * y + 2 * a(11) * x\n dYy = a(9) + a(10) * x + 2 * a(12) * y\n\n J(1,1) = dXx\n J(1,2) = dXy\n J(2,1) = dYx\n J(2,2) = dYy\n END FUNCTION J\n\nEND SUBROUTINE LINEAR_STEP\n\nEND MODULE QuadraticMap\n", "meta": {"hexsha": "4e49828ce7941ab511b127856f46226a3fec9f1d", "size": 1953, "ext": "f08", "lang": "FORTRAN", "max_stars_repo_path": "QuadraticMap.f08", "max_stars_repo_name": "avysk/StrangelyAttractive", "max_stars_repo_head_hexsha": "1f7af19ea4be3daa71c836327fe18e64517fb578", "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": "QuadraticMap.f08", "max_issues_repo_name": "avysk/StrangelyAttractive", "max_issues_repo_head_hexsha": "1f7af19ea4be3daa71c836327fe18e64517fb578", "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": "QuadraticMap.f08", "max_forks_repo_name": "avysk/StrangelyAttractive", "max_forks_repo_head_hexsha": "1f7af19ea4be3daa71c836327fe18e64517fb578", "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.4125, "max_line_length": 77, "alphanum_fraction": 0.5473630312, "num_tokens": 812, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818865, "lm_q2_score": 0.7154239897159439, "lm_q1q2_score": 0.6500470444916693}} {"text": "MODULE non_linear_solvers\n!\n! It contains algorithms and numerical methods used for the inversion of the\n! Span-Wagner EoS, necessary for the evaluation of properties in each node of the\n! grid.\n! \n! It contains a 2D Newton-Raphson algorithm, a 1D Newton-Raphson algorithm, a\n! Brent algorithm and the corresponding functions of which we seek the zeros.\n!==============================================================================\n!============================================================================== \n!\nUSE def_constants\nUSE properties\n!USE def_variables, ONLY: vL_psat_spline, vV_psat_spline,&\n! &uL_psat_spline, uV_psat_spline,&\n! &Tsat_psat_spline, saturP\n!USE Interp_table\nIMPLICIT NONE\n!\nPRIVATE\nPUBLIC New_Rap2D, New_Rap3D, New_Rap1D, BrentRoots\nCONTAINS\n!\n!\n!\n!===============================================================================\n SUBROUTINE New_Rap2D(MODE, out1_NewRap, out2_NewRap, &\n & resnorm, Niter, exitflag, in_1, in_2, guess_1, guess_2)\n!===============================================================================\n!------------------------------------------------------------------- \n! 2D TWO-PHASE or SINGLE-PHASE\n!-------------------------------------------------------------------\n!\n! Input :\n! -------\n! MODE = 1 saturation, 2 to be added, etc. \n! in_1, in_2 = Input values (optional, not always needed),\n! For MODE=1: in_1 is the T_sat\n! For MODE=2: in_1 is the pressure, in_2 is the internal energy\n! guess_1, guess_2 = Initial guess\n! For MODE=1: guess_1 is v_liquid, guess_2 is v_vapor\n! For MODE=2: guess_1 is the Temperature, guess_2 is the specific volume\n!\n! Output :\n! -------\n! resnorm = Norm of the \"residual vector\"\n! Niter = Number of iterations\n! exitflag = 1 \"normal exit\", < 1 \"a problem occurred\"\n!\n! out1_NewRap, out2_NewRap depend on the MODE used\n!\n!-----------------------------------------------------------------------\n! M. De Lorenzo 07/10/2016\n!-----------------------------------------------------------------------\n!\n!\n IMPLICIT NONE\n!\n! Global variables\n INTEGER, INTENT(IN) :: MODE\n INTEGER, INTENT(OUT) :: exitflag, Niter\n REAL(8),INTENT(IN) :: guess_1, guess_2, in_1, in_2\n REAL(8),INTENT(OUT) :: out1_NewRap, out2_NewRap, resnorm\n!\n! Local variables \n INTEGER :: n, nx, nf, INFO, MAX_ITER \n INTEGER,POINTER :: IPIV(:)\n REAL(8) :: x, TOL_X, TOL_FUN, ALPHA, MIN_LAMBDA, MAX_LAMBDA,&\n & Dx_J, lambda, slope, fffold, lambda_min, fff, &\n & fff2, A_l, lambda2, lambda_OLD, aa, bb, discriminant \n REAL(8), DIMENSION (2,1) :: XXX, F, delta, XXX_forw, XXX_back,&\n & F_forw, F_back, dF, TYPX, dx_star, dx, XXX_old, C_l, aabb \n REAL(8), DIMENSION (1,2) :: g\n REAL(8), DIMENSION (2,2) :: J, J0, Jstar, AAA, B_l\n !\n ! ------------- INITIALIZATION ----------\n XXX(1,1) = guess_1 \n XXX(2,1) = guess_2\n !\n ! Options\n !\n TOL_X = 1.d-20 ! relative max step tolerance\n TOL_FUN = 1.d-12 ! function tolerance\n MAX_ITER = 500 ! max number of iterations\n ALPHA = 1.d-4 ! criteria for decrease\n MIN_LAMBDA = 0.1d0 ! min lambda\n MAX_LAMBDA = 0.5d0 \n TYPX = abs(XXX) ! x scaling value, remove zeros\n !\n !\n call F_New_Rap2D (MODE, F, XXX, in_1, in_2)\n !\n ! ---- Jacobian estimation\n !\n Dx_J = 1.d-6 ! finite difference delta\n nx = 2 ! degrees of freedom\n nf = 2 ! number of functions\n DO n = 1,nx\n delta(1,1) = 0.d0; delta(2,1) = 0.d0\n delta(n,1) = delta(n,1) + Dx_J \n XXX_forw = XXX + delta \n XXX_back = XXX - delta\n call F_New_Rap2D (MODE, F_forw, XXX_forw, in_1, in_2)\n call F_New_Rap2D (MODE, F_back, XXX_back, in_1, in_2)\n dF = F_forw - F_back ! delta F\n J(1, n) = dF(1,1)/Dx_J/2.d0 ! derivatives dF/d_n\n J(2, n) = dF(2,1)/Dx_J/2.d0 ! derivatives dF/d_n\n ENDDO\n J0(1,1) = 1.d0 / TYPX(1,1) ! Jacobian scaling matrix\n J0(1,2) = 1.d0 / TYPX(2,1)\n J0(2,1) = J0(1,1)\n J0(2,2) = J0(1,2)\n Jstar = J/J0; ! scale Jacobian\n !\n resnorm = sqrt(F(1,1)*F(1,1) + F(2,1)*F(2,1))\n exitflag = 1\n !\n !--- SOLVER -------------------\n !\n Niter = 0 ! start counter\n lambda = 1.d0 ! backtracking\n lambda_OLD = lambda\n!\n allocate(IPIV(nf))\n! \n 1 DO WHILE (((resnorm .GT. TOL_FUN) .OR. (lambda .LT. 1.d0)) &\n & .AND. (exitflag >= 0) .AND. (Niter <= MAX_ITER)) \n Niter = Niter + 1\n ! \n IF (lambda==1.d0) THEN \n ! Newton-Raphson solver\n ! dx_star = -Jstar\\F calculate Newton step\n AAA = -Jstar\n dx_star = F\n !call PLU decomposition routine from LAPACK\n call DGETRF( nf, nf, AAA,nf, IPIV, INFO)\n call DGETRS('N', nf,1,AAA,nf, IPIV, dx_star,nf,INFO) \n \t dx = dx_star*TYPX\n g = MATMUL(TRANSPOSE(F),Jstar)\n \t slope = g(1,1)*dx_star(1,1) + g(1,2)*dx_star(2,1)\n \t fffold = SUM(F*F)\n XXX_old = XXX \n lambda_min = TOL_X/MAXVAL(ABS(dx)/ABS(XXX_old))\n ENDIF\n! \n! print*, 'LAMBDA = ', lambda, 'resnorm',resnorm\n IF (lambda < lambda_min) THEN\n exitflag = -2; ! XXX is too close to XXX_OLD \n ! print*,'XXX is too close to XXX_OLD'\n !ELSEIF any(isnan(dx)) || any(isinf(dx))\n ! exitflag = -1; ! matrix may be singular\n ! STOP\n ENDIF\n! \n! XXX at new step \n! \t\n \t XXX = XXX_old + dx*lambda\n! print*, 'resnorm',resnorm\n! print*,'dx*lambda= ',dx*lambda\n! print*,'xxx', XXX\n! print*, 'lambda_min', lambda_min\n call F_New_Rap2D (MODE, F, XXX, in_1, in_2)\n !\n ! ---- Jacobian estimation\n !\n DO n = 1,nx\n \t delta(1,1) = 0.d0; delta(2,1) = 0.d0\n \t delta(n,1) = delta(n,1) + Dx_J \n \t XXX_forw = XXX + delta \n \t XXX_back = XXX - delta\n call F_New_Rap2D (MODE, F_forw, XXX_forw, in_1, in_2)\n call F_New_Rap2D (MODE, F_back, XXX_back, in_1, in_2)\n \t dF = F_forw - F_back ! delta F\n \t J(1, n) = dF(1,1)/Dx_J/2.d0 ! derivatives dF/d_n\n \t J(2, n) = dF(2,1)/Dx_J/2.d0 ! derivatives dF/d_n\n \tENDDO \n \tJstar = J/J0 ! scale Jacobian\n \tfff = SUM(F*F) ! f to be minimized\n! \n! Optimization\n! \n IF (fff > fffold + ALPHA*lambda*slope) THEN\n IF (lambda .eq. 1.d0) THEN\n lambda = -slope/2.d0/(fff-fffold-slope) ! calculate lambda\n ELSE\n A_l = 1.d0/(lambda_OLD - lambda2)\n B_l(1,1) = 1.d0/lambda_OLD**2.d0\n B_l(1,2) = -1.d0/lambda2**2.d0\n B_l(2,1) = -lambda2/lambda_OLD**2.d0\n B_l(2,2) = lambda_OLD/lambda2**2.d0\n \t C_l(1,1) = fff-fffold-lambda_OLD*slope\n C_l(2,1) = fff2-fffold-lambda2*slope\n !\n \t aabb = A_l* MATMUL(B_l,C_l)\n aa = aabb(1,1)\n bb = aabb(2,1)\n IF (aa == 0.d0) THEN\n lambda = -slope/2.d0/bb;\n ELSE\n discriminant = bb**2.d0 - 3.d0*aa*slope;\n IF (discriminant < 0.d0) THEN\n lambda = MAX_LAMBDA*lambda_OLD;\n ELSEIF (bb <= 0.d0) THEN\n lambda = (-bb + sqrt(discriminant))/3.d0/aa\n ELSE\n lambda = -slope/(bb + sqrt(discriminant))\n ENDIF\n \t ENDIF\n lambda = min(lambda,MAX_LAMBDA*lambda_OLD)! minimum step length\n ENDIF \n ELSE\n lambda = 1.d0; ! fraction of Newton step\n ENDIF \n IF (lambda < 1.d0) THEN\n lambda2 = lambda_OLD;\n fff2 = fff; ! save 2nd most previous value\n lambda = max(lambda,MIN_LAMBDA*lambda_OLD) ! minimum step length\n GO TO 1\n ENDIF\n !\n !\n resnorm = sqrt(F(1,1)*F(1,1) + F(2,1)*F(2,1))\n !\n ENDDO\n !\n deallocate(IPIV)\n out1_NewRap = XXX(1,1)\n out2_NewRap = XXX(2,1) \n END SUBROUTINE New_Rap2D\n!\n!\n!\n SUBROUTINE F_New_Rap2D (MODE, F, XXX, in_1, in_2) \n IMPLICIT NONE \n INTEGER, INTENT(IN) :: MODE \n REAL(8), INTENT(IN) :: in_1, in_2\n REAL(8), DIMENSION (2,1), INTENT(IN) :: XXX\n REAL(8), DIMENSION (2,1), INTENT(OUT) :: F\n! REAL(8), DIMENSION (2,1) :: F_out\n REAL(8) :: F1_MODE, F2_MODE, Helmholtz, T, v, p, e, cv, cp, s, c, &\n & v_l, p_l, s_l, e_l, g_l, v_v, p_v, s_v, e_v, g_v,&\n & helmho_v,helmho_l,deriv,dummy1,dummy2,x_out,a_out,entropy,enth\n! \n IF (MODE .EQ. 1) THEN\n! Calculation of the saturation specific volumes of vapor \n! and liquid phase.\n! The saturation specific volume is obtained by imposing:\n! p_l = p_v pressure equality\n! g_l = g_v Gibbs free enthalpy equality\n!\n! That is the Maxwell criterion for saturation.\n!\n v_l = XXX(1,1)\n v_v = XXX(2,1)\n T = in_1\n! \n CALL pressure(T,v_l,p_l)\n CALL pressure(T,v_v,p_v)\n! \n CALL helmho(T,v_l,helmho_l)\n CALL helmho(T,v_v,helmho_v) \n! g_l = Helmholtz(v_l,T) + p_l*v_l*1e-3_pr ! kJ / kg\n! g_v = Helmholtz(v_v,T) + p_v*v_v*1e-3_pr ! kJ / kg\n! \n g_l = helmho_l + p_l*v_l ! J / kg\n g_v = helmho_v + p_v*v_v\n F(1,1) = (p_l - p_v)*1e-6_pr\n F(2,1) = (g_l - g_v)*1e-3_pr\n!\n ELSEIF (MODE .EQ. 2) THEN\n! Calculation of temperature and specific volume for imposed pressure p\n! and specific internal energy, e.\n! \n! For this function:\n! in_1 = p\n! in_2 = e\n! XXX(1,1) = T\n! XXX(2,1) = v\n!\n! \n T = XXX(1,1)\n v = XXX(2,1)\n CALL pressure(T,v,p)\n CALL inter_energy(T,v,e)\n\n!print*, 'T',T,'v',v,'p',p,'e',e\n F(1,1) = (in_1 - p)*1d-6 ! Pa\n F(2,1) = (in_2 - e)*1d-3 ! J/kg\n!print*, F(1,1),F(2,1)\n!print*, in_1,in_2, p,e\n!\n!\n ELSEIF (MODE .EQ. 3) THEN\n! META liquid: dpdv_T = 0 and e(t,v) = e_in\n! For this function:\n! in_1 = e\n! in_2 = \n! XXX(1,1) = T\n! XXX(2,1) = v_l\n!\n! \n T = XXX(1,1)\n v_l = XXX(2,1)\n!\n CALL inter_energy(T,v_l,e)\n CALL dpdv_T(T,v_l,deriv)\n!\n F(1,1) = deriv * 1e-6_pr\n F(2,1) = (in_1 - e) *1e-3_pr \n ELSEIF (MODE .EQ. 4) THEN\n! META liquid: p = 0 and e(t,v) = e_in\n! For this function:\n! in_1 = e\n! in_2 = \n! XXX(1,1) = T\n! XXX(2,1) = v_l\n!\n! \n T = XXX(1,1)\n v_l = XXX(2,1)\n!\n CALL inter_energy(T,v_l,e)\n CALL pressure(T,v_l,p)\n!\n F(1,1) = p * 1e-6_pr\n F(2,1) = (in_1 - e) *1e-3_pr\n\n!\n!\n ELSE\n print*,'MODE of New_Rap2D unknown'\n STOP\n ENDIF\n!\n END SUBROUTINE F_New_Rap2D\n!\n\n!\n!===============================================================================\n SUBROUTINE New_Rap3D(MODE, out1_NewRap, out2_NewRap, out3_NewRap, &\n & resnorm, Niter, exitflag, in_1,in_2, guess_1, guess_2, guess_3)\n!===============================================================================\n!\n IMPLICIT NONE\n!\n! Global variables\n INTEGER, INTENT(IN) :: MODE\n INTEGER, INTENT(OUT) :: exitflag, Niter\n REAL(pr),INTENT(IN) :: guess_1, guess_2, guess_3, in_1, in_2!,in_3\n REAL(pr),INTENT(OUT) :: out1_NewRap, out2_NewRap, out3_NewRap, resnorm\n!\n! Local variables \n INTEGER :: n, nx, nf, INFO, MAX_ITER \n INTEGER,POINTER :: IPIV(:)\n REAL(8) :: x, TOL_X, TOL_FUN, ALPHA, MIN_LAMBDA, MAX_LAMBDA,&\n & Dx_J, lambda, slope, fffold, lambda_min, fff, &\n & fff2, A_l, lambda2, lambda_OLD, aa, bb, discriminant \n REAL(8), DIMENSION (3,1) :: XXX, F, delta, XXX_forw, XXX_back,&\n & F_forw, F_back, dF, TYPX, dx_star, dx, XXX_old, C_l, aabb \n REAL(8), DIMENSION (1,3) :: g\n REAL(8), DIMENSION (3,3) :: J, J0, Jstar, AAA, B_l\n !\n ! ------------- INITIALIZATION ----------\n XXX(1,1) = guess_1 \n XXX(2,1) = guess_2\n XXX(3,1) = guess_3\n !\n ! Options\n !\n TOL_X = 1.d-20 ! relative max step tolerance\n TOL_FUN = 1.d-9 ! function tolerance\n MAX_ITER = 500 ! max number of iterations\n ALPHA = 1.d-4 ! criteria for decrease\n MIN_LAMBDA = 0.1d0 ! min lambda\n MAX_LAMBDA = 0.5d0 \n TYPX = abs(XXX) ! x scaling value, remove zeros\n !\n !\n call F_New_Rap3D (MODE, F, XXX, in_1,in_2)\n !\n ! ---- Jacobian estimation\n !\n Dx_J = 1.d-6 ! finite difference delta\n nx = 3 ! degrees of freedom\n nf = 3 ! number of functions\n DO n = 1,nx\n delta(1,1) = 0.d0; delta(2,1) = 0.d0; delta(3,1) = 0.d0\n delta(n,1) = delta(n,1) + Dx_J \n XXX_forw = XXX + delta \n XXX_back = XXX - delta\n call F_New_Rap3D (MODE, F_forw, XXX_forw, in_1,in_2)\n call F_New_Rap3D (MODE, F_back, XXX_back, in_1,in_2)\n dF = F_forw - F_back ! delta F\n J(1, n) = dF(1,1)/Dx_J/2.d0 ! derivatives dF/d_n\n J(2, n) = dF(2,1)/Dx_J/2.d0 ! derivatives dF/d_n\n J(3, n) = dF(3,1)/Dx_J/2.d0 ! derivatives dF/d_n\n ENDDO\n J0(1,1) = 1.d0 / TYPX(1,1) ! Jacobian scaling matrix\n J0(1,2) = 1.d0 / TYPX(2,1)\n J0(1,3) = 1.d0 / TYPX(3,1)\n J0(2,1) = J0(1,1)\n J0(2,2) = J0(1,2)\n J0(2,3) = J0(1,3)\n J0(3,1) = J0(1,1)\n J0(3,2) = J0(1,2)\n J0(3,3) = J0(1,3)\n Jstar = J/J0; ! scale Jacobian\n !\n resnorm = sqrt(F(1,1)*F(1,1) + F(2,1)*F(2,1)+ F(3,1)*F(3,1))\n exitflag = 1\n !\n !--- SOLVER -------------------\n !\n Niter = 0 ! start counter\n lambda = 1.d0 ! backtracking\n lambda_OLD = lambda\n!\n allocate(IPIV(nf))\n! \n 1 DO WHILE (((resnorm .GT. TOL_FUN) .OR. (lambda .LT. 1.d0)) &\n & .AND. (exitflag >= 0) .AND. (Niter <= MAX_ITER)) \n Niter = Niter + 1\n ! \n IF (lambda==1.d0) THEN \n ! Newton-Raphson solver\n ! dx_star = -Jstar\\F calculate Newton step\n AAA = -Jstar\n dx_star = F\n !call PLU decomposition routine from LAPACK\n call DGETRF( nf, nf, AAA,nf, IPIV, INFO)\n call DGETRS('N', nf,1,AAA,nf, IPIV, dx_star,nf,INFO) \n \t dx = dx_star*TYPX\n g = MATMUL(TRANSPOSE(F),Jstar)\n \t slope = g(1,1)*dx_star(1,1) + g(1,2)*dx_star(2,1) +&\n & g(1,3)*dx_star(3,1)\n \t fffold = SUM(F*F)\n XXX_old = XXX \n lambda_min = TOL_X/MAXVAL(ABS(dx)/ABS(XXX_old))\n ENDIF\n! \n! print*, 'LAMBDA = ', lambda, 'resnorm',resnorm\n IF (lambda < lambda_min) THEN\n exitflag = -2; ! XXX is too close to XXX_OLD \n ! print*,'XXX is too close to XXX_OLD'\n !ELSEIF any(isnan(dx)) || any(isinf(dx))\n ! exitflag = -1; ! matrix may be singular\n ! STOP\n ENDIF\n! \n! XXX at new step \n! \t\n \t XXX = XXX_old + dx*lambda\n! print*, 'resnorm',resnorm\n! print*,'dx*lambda= ',dx*lambda\n! print*,'xxx', XXX\n! print*, 'lambda_min', lambda_min\n call F_New_Rap3D (MODE, F, XXX, in_1,in_2)\n !\n ! ---- Jacobian estimation\n !\n DO n = 1,nx\n \t delta(1,1) = 0.d0; delta(2,1) = 0.d0; delta(3,1)=0.d0\n \t delta(n,1) = delta(n,1) + Dx_J \n \t XXX_forw = XXX + delta \n \t XXX_back = XXX - delta\n call F_New_Rap3D (MODE, F_forw, XXX_forw, in_1,in_2)\n call F_New_Rap3D (MODE, F_back, XXX_back, in_1,in_2)\n \t dF = F_forw - F_back ! delta F\n \t J(1, n) = dF(1,1)/Dx_J/2.d0 ! derivatives dF/d_n\n \t J(2, n) = dF(2,1)/Dx_J/2.d0 ! derivatives dF/d_n\n \t J(3, n) = dF(3,1)/Dx_J/2.d0 ! derivatives dF/d_n\n \tENDDO \n \tJstar = J/J0 ! scale Jacobian\n \tfff = SUM(F*F) ! f to be minimized\n! \n! Optimization\n! \n IF (fff > fffold + ALPHA*lambda*slope) THEN\n IF (lambda .eq. 1.d0) THEN\n lambda = -slope/2.d0/(fff-fffold-slope) ! calculate lambda\n ELSE\n A_l = 1.d0/(lambda_OLD - lambda2)\n B_l(1,1) = 1.d0/lambda_OLD**2.d0\n B_l(1,2) = -1.d0/lambda2**2.d0\n B_l(2,1) = -lambda2/lambda_OLD**2.d0\n B_l(2,2) = lambda_OLD/lambda2**2.d0\n \t C_l(1,1) = fff-fffold-lambda_OLD*slope\n C_l(2,1) = fff2-fffold-lambda2*slope\n !\n \t aabb = A_l* MATMUL(B_l,C_l)\n aa = aabb(1,1)\n bb = aabb(2,1)\n IF (aa == 0.d0) THEN\n lambda = -slope/2.d0/bb;\n ELSE\n discriminant = bb**2.d0 - 3.d0*aa*slope;\n IF (discriminant < 0.d0) THEN\n lambda = MAX_LAMBDA*lambda_OLD;\n ELSEIF (bb <= 0.d0) THEN\n lambda = (-bb + sqrt(discriminant))/3.d0/aa\n ELSE\n lambda = -slope/(bb + sqrt(discriminant))\n ENDIF\n \t ENDIF\n lambda = min(lambda,MAX_LAMBDA*lambda_OLD)! minimum step length\n ENDIF \n ELSE\n lambda = 1.d0; ! fraction of Newton step\n ENDIF \n IF (lambda < 1.d0) THEN\n lambda2 = lambda_OLD;\n fff2 = fff; ! save 2nd most previous value\n lambda = max(lambda,MIN_LAMBDA*lambda_OLD) ! minimum step length\n GO TO 1\n ENDIF\n !\n !\n resnorm = sqrt(F(1,1)*F(1,1) + F(2,1)*F(2,1) + F(3,1)*F(3,1))\n !\n ENDDO\n !\n deallocate(IPIV)\n out1_NewRap = XXX(1,1)\n out2_NewRap = XXX(2,1) \n out3_NewRap = XXX(3,1) \n END SUBROUTINE New_Rap3D\n!\n!\n!\n SUBROUTINE F_New_Rap3D (MODE, F, XXX, in_1,in_2) \n IMPLICIT NONE \n INTEGER, INTENT(IN) :: MODE \n REAL(pr), INTENT(IN) :: in_1, in_2!, in_3\n REAL(pr), DIMENSION (3,1), INTENT(IN) :: XXX\n REAL(pr), DIMENSION (3,1), INTENT(OUT) :: F\n REAL(pr), DIMENSION (3,1) :: F_out\n REAL(pr) :: F1_MODE, F2_MODE, Helmholtz, T, v, p, e, cv, cp, s, c, &\n & v_l, p_l, s_l, e_l, g_l, v_v, p_v, s_v, e_v, g_v,&\n & helmho_v,helmho_l,x,y,z,qual \n! \n IF (MODE .EQ. 1) THEN\n! FOR LL right boundary (liquid saturation line):\n! p_l = p_v pressure equality\n! g_l = g_v Gibbs free enthalpy equality\n! el = e at one interal energy\n! That is the Maxwell criterion for saturation.\n!\n v_l = XXX(1,1)\n v_v = XXX(2,1) \n T = XXX(3,1)\n e = in_1 \n! \n CALL pressure(T,v_l,p_l)\n CALL pressure(T,v_v,p_v)\n! \n CALL helmho(T,v_l,helmho_l)\n CALL helmho(T,v_v,helmho_v)\n!\n CALL inter_energy(T,v_l,e_l) \n! \n g_l = helmho_l + p_l*v_l ! J / kg\n g_v = helmho_v + p_v*v_v\n F(1,1) = (p_l - p_v)*1e-6_pr\n F(2,1) = (g_l - g_v)*1e-3_pr\n F(3,1) = (e_l - e)*1e-3_pr \n!cas test for 3D solver\n ELSEIF (MODE .EQ. 2) THEN\n x= XXX(1,1)\n y= XXX(2,1)\n z= XXX(3,1)\n!\n F(1,1) = sin(x)\n F(2,1) = cos(y)\n F(3,1) = z*z*z - 6_pr*z*z + 11_pr*z -6\n!\n! \n ELSEIF (MODE .EQ. 3) THEN\n! FOR TP region\n! p=p_l pressure equality\n! p =p_v pressure equality\n! g_l = g_v Gibbs free enthalpy equality\n! That is the Maxwell criterion for saturation.\n!\n v_l = XXX(1,1)\n v_v = XXX(2,1)\n T = XXX(3,1)\n p = in_1\n! \n CALL pressure(T,v_l,p_l)\n CALL pressure(T,v_v,p_v)\n! \n CALL helmho(T,v_l,helmho_l)\n CALL helmho(T,v_v,helmho_v)\n!\n! \n g_l = helmho_l + p_l*v_l ! J / kg\n g_v = helmho_v + p_v*v_v\n!\n F(1,1) = (p_l - p_v)*1e-6_pr\n F(2,1) = (p_v - p)*1e-6_pr\n F(3,1) = (g_l - g_v)*1e-3_pr\n ELSEIF (MODE .EQ. 4) THEN\n! FOR LH right boundary (vapor saturation line)\n! p_l = p_v pressure equality\n! g_l = g_v Gibbs free enthalpy equality\n! ev = e at one interal energy\n! That is the Maxwell criterion for saturation.\n!\n v_l = XXX(1,1)\n v_v = XXX(2,1)\n T = XXX(3,1)\n e = in_1\n! \n CALL pressure(T,v_l,p_l)\n CALL pressure(T,v_v,p_v)\n! \n CALL helmho(T,v_l,helmho_l)\n CALL helmho(T,v_v,helmho_v)\n!\n CALL inter_energy(T,v_v,e_v)\n! \n g_l = helmho_l + p_l*v_l ! J / kg\n g_v = helmho_v + p_v*v_v\n F(1,1) = (p_l - p_v)*1e-6_pr\n F(2,1) = (g_l - g_v)*1e-3_pr\n F(3,1) = (e_v - e)*1e-3_pr\n!\n ELSEIF (MODE .EQ. 5) THEN\n! for a given input couple of values of specific internal energy and\n! specific volume, the temperature, vapor specific volume, liquid specific\n! volume, are evalued at sauration and the corresponding quality is\n! computed. (TP region)\n! (v,e)--> (Vv, Vl, T, x) \n! F1 = pv = pl\n! F2 = gv = gl\n! F3 = e - x*ev - (1-x)*el\n! x = (v-Vl)/(Vv - Vl)\n!\n v_l = XXX(1,1)\n v_v = XXX(2,1)\n T = XXX(3,1)\n e = in_1\n v = in_2\n! \n CALL pressure(T,v_l,p_l)\n CALL pressure(T,v_v,p_v)\n! \n CALL helmho(T,v_l,helmho_l)\n CALL helmho(T,v_v,helmho_v)\n!\n CALL inter_energy(T,v_v,e_v)\n CALL inter_energy(T,v_l,e_l)\n! \n qual = (v - v_l)/(v_v-v_l)\n g_l = helmho_l + p_l*v_l ! J / kg\n g_v = helmho_v + p_v*v_v\n!\n F(1,1) = (p_l - p_v)*1e-6_pr\n F(2,1) = (g_l - g_v)*1e-3_pr\n F(3,1) = (e - qual*e_v - (1_pr - qual)*e_l)*1e-3_pr \n!\n ELSE\n print*,'MODE of New_Rap3D unknown'\n STOP\n ENDIF\n END SUBROUTINE F_New_Rap3D\n!\n!===============================================================================\n SUBROUTINE New_Rap1D(MODE, out_1, out_2, resnorm, Niter,& \n & exitflag, GGG, X0, in_1, out3)\n!===============================================================================\n! 1D TWO-PHASE or SINGLE-PHASE\n!-------------------------------------------------------------------\n!\n! Input :\n! -------\n! MODE = it will depend on the used function\n! GGG = idem\n! in_1 = idem\n! in_2 = idem\n! X0 = idem\n!\n!\n! Output :\n! -------\n!\n! out_1 = idem\n! out_2 = idem\n!\n!-------------------------------------------------------------------\n! M. De Lorenzo 03/2016\n!-------------------------------------------------------------------\n!\n!\n IMPLICIT NONE\n!\n INTEGER :: MAX_ITER\n INTEGER, INTENT(IN) :: MODE\n INTEGER, INTENT(OUT) :: exitflag, Niter\n REAL(8), INTENT(IN) :: GGG, X0, in_1\n REAL(8), INTENT(OUT) :: out_1, out_2, resnorm, out3\n REAL(8) :: TOL_X, TOL_FUN, ALPHA, MIN_LAMBDA, MAX_LAMBDA, Jstar,&\n & lambda, slope, fffold, lambda_min, fff, fff2, A_l, aa, bb, Dx_J,&\n & discriminant, lambda2, lambda_OLD, XXX, F, delta, XXX_forw, J0,&\n & XXX_back, F_forw, F_back, dF, TYPX, dx_star, dx, XXX_old, g, J \n REAL(8), DIMENSION (2,2) :: B_l\n REAL(8), DIMENSION (2,1) :: C_l, aabb\n!\n!\n XXX = X0 ! Initial value\n!\n! Options\n!\n TOL_X = 1d-20 ! relative max step tolerance\n TOL_FUN = 1d-12 ! function tolerance\n MAX_ITER = 500 ! max number of iterations\n ALPHA = 1d-4 ! criteria for decrease\n MIN_LAMBDA = 1d-1 ! min lambda\n MAX_LAMBDA = 5d-1\n TYPX = abs(XXX) ! x scaling value, remove zeros\n!\n! ---- Function F definition\n! F = GGG_input - GGG\n!\n call F_New_Rap1D(MODE, F, out_2, XXX, GGG, in_1, out3)\n!\n!\n! --------- Jacobian estimation-----------------\n!\n Dx_J = 1d-6 ! finite difference delta\n delta = Dx_J\n XXX_forw = XXX + delta\n XXX_back = XXX - delta\n call F_New_Rap1D(MODE, F_forw, out_2, XXX_forw, GGG, in_1, out3)\n call F_New_Rap1D(MODE, F_back, out_2, XXX_back, GGG, in_1, out3)\n dF = F_forw - F_back ! delta F\n J = dF/Dx_J/2d0 ! derivatives dF/d_n\n J0 = 1d0 / TYPX ! Jacobian scaling factor\n Jstar = J/J0; ! scale Jacobian\n resnorm = abs(F) ! Norm of residues\n exitflag = 1\n!\n!\n!--- SOLVER -------------------\n!\n Niter = 0\n lambda = 1d0 ! backtracking\n lambda_OLD = lambda\n!\n!\n!\n1 DO WHILE ( ((resnorm>TOL_FUN) .OR. (lambda<1d0)) .AND. &\n & (exitflag>=0) .AND. (Niter<=MAX_ITER))\n Niter = Niter + 1\n!\n!--------- Newton-Raphson solver\n!\n IF (lambda .eq. 1.0d0) THEN\n dx_star = -F/Jstar ! calculate Newton step\n dx = dx_star*TYPX\n g = F*Jstar\n slope = g*dx_star\n fffold = F*F \n XXX_old = XXX\n lambda_min = TOL_X/(ABS(dx)/ABS(XXX_old))\n ENDIF\n!\n!--------- Check about proximity of XXX and XXX_OLD\n!\n IF (lambda < lambda_min) THEN\n exitflag = 2;\n !print*,'XXX is too close to XXX_OLD'\n !EXIT ! OUT NewRap\n ENDIF\n!\n!--------- Eventually, backtracking of New-Rap step\n!\n XXX = XXX_old + dx*lambda\n call F_New_Rap1D(MODE, F, out_2, XXX, GGG, in_1, out3)\n!\n!--------- Jacobian estimation\n!\n XXX_forw = XXX + delta\n XXX_back = XXX - delta\n call F_New_Rap1D(MODE, F_forw, out_2, XXX_forw, GGG, in_1,&\n & out3)\n call F_New_Rap1D(MODE, F_back, out_2, XXX_back, GGG, in_1,&\n & out3)\n dF = F_forw - F_back ! delta F\n J = dF/Dx_J/2d0 ! derivatives dF/d_n\n Jstar = J/J0 ! scale Jacobian\n fff = F*F ! f to be minimized\n!\n!--------- Optimization technique (minimizing fff = SUM(F*F) )\n!\n IF (fff > fffold + ALPHA*lambda*slope) THEN\n IF (lambda .eq. 1d0) THEN\n lambda = -slope/2d0/(fff-fffold-slope) ! calculate lambda\n ELSE\n A_l = 1d0/(lambda_OLD - lambda2)\n B_l(1,1) = 1d0/lambda_OLD/lambda_OLD\n B_l(1,2) = -1d0/lambda2/lambda2\n B_l(2,1) = -lambda2/lambda_OLD/lambda_OLD\n B_l(2,2) = lambda_OLD/lambda2/lambda2\n C_l(1,1) = fff-fffold-lambda_OLD*slope\n C_l(2,1) = fff2-fffold-lambda2*slope\n !\n aabb = A_l* MATMUL(B_l,C_l)\n aa = aabb(1,1)\n bb = aabb(2,1)\n IF (aa .EQ. 0.0d0) THEN\n lambda = -slope/2d0/bb;\n ELSE\n discriminant = bb**2d0 - 3d0*aa*slope;\n IF (discriminant < 0d0) THEN\n lambda = MAX_LAMBDA*lambda_OLD;\n ELSEIF (bb <= 0d0) THEN\n lambda = (-bb + sqrt(discriminant))/3d0/aa\n ELSE\n lambda = -slope/(bb + sqrt(discriminant))\n ENDIF\n ENDIF\n lambda = min(lambda,MAX_LAMBDA*lambda_OLD) ! minimum step length\n ENDIF\n ELSE\n lambda = 1d0; ! fraction of Newton step\n ENDIF\n IF (lambda < 1d0) THEN\n lambda2 = lambda_OLD;\n fff2 = fff; ! save 2nd most previous value\n lambda = max(lambda,MIN_LAMBDA*lambda_OLD) ! minimum step length\n GO TO 1\n ENDIF\n!\n resnorm = abs(F)\n!\n END DO\n!\n out_1 = XXX\n!\n \n END SUBROUTINE New_Rap1D\n!\n!\n!===============================================================================\n SUBROUTINE F_New_Rap1D(MODE, F, out_2, XXX, GGG, in_1, out_3)\n!===============================================================================\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: MODE\n REAL(8), INTENT(IN) :: in_1, XXX, GGG\n REAL(8), INTENT(OUT) :: F, out_2,out_3\n!\n!LOCAL\n INTEGER :: i,j\n REAL(8) :: temp, e, v\n REAL(8) :: delta_p,press,e_l,e_v,V_v,V_l,qual \n \n IF (MODE .EQ. 1) THEN\n! (v,e) --> T: v=in_1, e=GGG, T=XXX\n v = in_1\n temp = XXX\n! \n CALL inter_energy(temp, v, e)\n! \n F = (e - GGG) * 1e-3_pr\n out_2 = 0.0_pr\n out_3 = 0.0_pr\n!\n! \n ELSEIF (MODE .EQ. 2) THEN\n! In two-phase region, (e,v) --> (psat,x,Tsat) \n! \n press = XXX\n v = in_1\n e = GGG \n CALL satprop(3, press, temp, v_v, v_l, e_v, e_l)\n\n! print*, 'iter process',v,v_l, v_v\n out_3 = temp \n qual = (v - v_l)/(v_v-v_l)\n out_2 = qual\n F = (e - qual*e_v - (1_pr - qual)*e_l) * 1e-3_pr\n!\n! \n ELSEIF (MODE .EQ. 3) THEN\n v = XXX\n temp = in_1 \n CALL pressure(temp,v,press)\n F = (press - GGG) * 1e-6_pr\n \n ELSE\n print*,'MODE of New_Rap1D unknown'\n STOP\n ENDIF\n!\n END SUBROUTINE F_New_Rap1D\n\n!=======================================================================================\n!\nSUBROUTINE BrentRoots(MODE, out_1, out_2, residue, Niter, GGG, lower, upper, in_1, in_2)\n!\n!=======================================================================================\n!\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: MODE\n INTEGER, INTENT(OUT) :: Niter\n REAL(8), INTENT(IN) :: lower, upper, GGG, in_1, in_2\n REAL(8), INTENT(OUT) :: out_1, out_2, residue\n\n INTEGER :: done\n REAL(8), PARAMETER :: FPP = 1d-16 ! floating-point precision\n REAL(8), PARAMETER :: MAX_ITER = 2d2 ! maximum allowed number of iterations\n REAL(8), PARAMETER :: nearzero = 1d-16\n REAL(8) :: TOL, AA, BB, CC, DD, EE, FA, FB, FC, xm, PP, SS, QQ, RR,&\n& Tol1, Root, Minimum\n\n TOL = 1d-12\n done = 0\n Niter = 0\n!\n AA = lower\n BB = upper\n CALL F_Brent(MODE, FA, out_2, AA, GGG, in_1, in_2)\n IF (abs(FA) .LT. TOL) THEN\n out_1 = AA\n RETURN\n ENDIF\n!\n CALL F_Brent(MODE, FB, out_2, BB, GGG, in_1, in_2)\n IF (abs(FB) .LT. TOL) THEN\n out_1 = BB\n RETURN\n ENDIF\n!\n! Check if root is bracketed\n IF (((FA .GT. 0d0) .AND. (FB .GT. 0d0)) .OR. ((FA .LT. 0d0) .AND.&\n & (FB .LT. 0d0))) THEN\n print*, 'ERROR: Root is not bracketed in MODE', MODE\n STOP\n ELSE\n FC = FB\n DO WHILE ((done .EQ. 0) .AND. (Niter .LT. MAX_ITER))\n Niter = Niter + 1\n!\n IF (((FC .GT. 0d0) .AND. (FB .GT. 0d0)) .OR.&\n & ((FC .LT. 0d0) .AND. (FB .LT. 0d0))) THEN\n ! rename AA, BB, CC and adjust bounding interval DD\n CC = AA\n FC = FA\n DD = BB - AA\n EE = DD\n ENDIF\n IF (abs(FC) .LT. abs(FB)) THEN\n AA = BB\n BB = CC\n CC = AA\n FA = FB\n FB = FC\n FC = FA\n ENDIF\n Tol1 = 2d0 * FPP * abs(BB) + 0.5d0 * TOL ! convergence check\n xm = 0.5d0 * (CC - BB)\n IF((abs(xm) .LE.Tol1) .OR. (abs(FA) .LT.nearzero)) THEN\n ! a root has been found\n Root = BB\n done = 1\n CALL F_Brent(MODE, residue, out_2,BB,GGG,in_1,in_2)\n ELSE\n IF ((abs(EE) .GE. Tol1) .AND.&\n & (abs(FA) .GT. abs(FB))) THEN\n SS = FB / FA ! attempt inverse quadratic function\n IF (abs(AA - CC) .LT. nearzero) THEN\n PP = 2d0 * xm * SS\n QQ = 1d0 - SS\n ELSE\n QQ = FA / FC\n RR = FB / FC\n PP = SS * (2d0 * xm * QQ * (QQ - RR) -&\n & (BB- AA) * (RR - 1d0))\n QQ = (QQ - 1d0) * (RR - 1d0) * (SS - 1d0)\n ENDIF\n IF (PP .GT. nearzero) THEN\n QQ = -QQ\n ENDIF\n PP = abs(PP)\n ! Evaluation of the minimum\n IF ((3d0 * xm * QQ - abs(Tol1 * QQ)) .LT.&\n & (abs(EE * QQ))) THEN\n Minimum = 3d0 * xm * QQ - abs(Tol1 * QQ)\n ELSE\n Minimum = abs(EE * QQ)\n ENDIF\n!\n IF ((2d0 * PP) .LT. Minimum) THEN\n ! accept interpolation\n EE = DD\n DD = PP / QQ\n ELSE\n ! interpolation failed, use bisection\n DD = xm\n EE = DD\n ENDIF\n ELSE\n ! bounds decreasing too slowly, use bisection\n DD = xm\n EE = DD\n ENDIF\n AA = BB ! move last best guess to AA\n FA = FB\n IF (abs(DD) .GT. Tol1) THEN\n ! evaluate new trial root\n BB = BB + DD\n ELSE\n IF (xm .GT. 0d0) THEN\n BB = BB + abs(Tol1)\n ELSE\n BB = BB - abs(Tol1)\n ENDIF\n ENDIF\n CALL F_Brent(MODE, FB, out_2, BB, GGG, in_1, in_2)\n IF (Niter .GT. MAX_ITER) THEN\n print*, 'Max N iteration exceeded in Brent'\n STOP\n ENDIF\n ENDIF\n END DO\n ENDIF\n!\n out_1 = Root\n!\nEND SUBROUTINE BrentRoots\n!\n!\n!===============================================================================\n SUBROUTINE F_Brent(MODE, F, out_2, XXX, GGG, in_1, in_2)\n!===============================================================================\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: MODE\n REAL(8), INTENT(IN) :: XXX, GGG, in_1, in_2\n REAL(8), INTENT(OUT) :: F, out_2\n REAL(8) :: temp, v_v, v_l, e_v, e_l,e,press,v,qual\n\n\n IF (MODE .EQ. 1) THEN\n!\n! In two-phase region, (e,v) --> (psat,x,Tsat) \n press = XXX\n v = in_1\n e = GGG\n CALL satprop(3, press, temp, v_v, v_l, e_v, e_l)\n\n! print*, 'iter process',v,v_l, v_v\n out_2 = temp\n qual = (v - v_l)/(v_v-v_l)\n F = (e - qual*e_v - (1_pr - qual)*e_l) * 1e-3_pr\n!\n!\n \n ELSE\n STOP 'MODE of BrentRoots unknown'\n ENDIF\n!\n END SUBROUTINE F_Brent\n!\n!\n!\n!\n!\n!\n!\nEND MODULE non_linear_solvers\n", "meta": {"hexsha": "cb0caf9f70fe078175697bb3b276861109aed5de", "size": 37666, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "non_linear_solvers.f90", "max_stars_repo_name": "yufang67/CO2-look-up-table", "max_stars_repo_head_hexsha": "2acfb66790158fb2e4e1b91e18f639b26b9f297b", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-05-15T17:23:21.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-28T17:30:53.000Z", "max_issues_repo_path": "non_linear_solvers.f90", "max_issues_repo_name": "yufang67/CO2-look-up-table", "max_issues_repo_head_hexsha": "2acfb66790158fb2e4e1b91e18f639b26b9f297b", "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": "non_linear_solvers.f90", "max_forks_repo_name": "yufang67/CO2-look-up-table", "max_forks_repo_head_hexsha": "2acfb66790158fb2e4e1b91e18f639b26b9f297b", "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.1361940299, "max_line_length": 97, "alphanum_fraction": 0.4301757553, "num_tokens": 11769, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179043564153, "lm_q2_score": 0.7154239836484143, "lm_q1q2_score": 0.6500470407489406}} {"text": "!***************************************************************************************************\n!>\n! Main program for EZ test.\n\n program main\n\n use lsqr_kinds\n use lsqr_module, only: lsqr_solver_ez\n use iso_fortran_env, only: output_unit\n\n implicit none\n\n ! define a 3x3 dense system to solve:\n integer,parameter :: m = 3 !! number of rows in `A` matrix\n integer,parameter :: n = 3 !! number of columns in `A` matrix\n real(wp),dimension(m),parameter :: b = real([1,2,3],wp)\n integer,dimension(m*n),parameter :: icol = [1,1,1,2,2,2,3,3,3]\n integer,dimension(m*n),parameter :: irow = [1,2,3,1,2,3,1,2,3]\n real(wp),dimension(m*n),parameter :: a = real([1,4,7,2,5,88,3,66,9],wp)\n real(wp),parameter :: damp = zero\n real(wp),dimension(m),parameter :: b_vec = b\n real(wp),dimension(m,n),parameter :: a_mat = reshape(a,[3,3])\n\n type(lsqr_solver_ez) :: solver\n real(wp),dimension(n) :: x\n real(wp),dimension(1) :: se !! not used\n real(wp),dimension(n,1) :: x_vec\n integer :: istop\n\n call solver%initialize(m,n,a,irow,icol,&\n itnlim = 100,&\n nout = output_unit)\n call solver%solve(b,damp,x,istop)\n\n x_vec(1:3,1) = x\n\n write(*,*) ''\n write(*,*) 'istop = ', istop\n write(*,*) ''\n write(*,'(1P,A,*(E16.6))') 'x = ', x\n write(*,'(1P,A,*(E16.6))') 'A*x = ', matmul(a_mat, x_vec)\n write(*,'(1P,A,*(E16.6))') 'A*x - b = ', matmul(a_mat, x_vec) - reshape(b_vec,(/m,3/))\n\n end program main\n!***************************************************************************************************\n", "meta": {"hexsha": "e69acf35287d7a4d2f1f2fe3fa0e4acae38fe3c7", "size": 1639, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/tests/lsqrtest_ez.f90", "max_stars_repo_name": "nachopage92/LSQR", "max_stars_repo_head_hexsha": "681b6bbe03dac55b6a7fc7ad6e64773074c1db19", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/tests/lsqrtest_ez.f90", "max_issues_repo_name": "nachopage92/LSQR", "max_issues_repo_head_hexsha": "681b6bbe03dac55b6a7fc7ad6e64773074c1db19", "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": "src/tests/lsqrtest_ez.f90", "max_forks_repo_name": "nachopage92/LSQR", "max_forks_repo_head_hexsha": "681b6bbe03dac55b6a7fc7ad6e64773074c1db19", "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": 35.6304347826, "max_line_length": 100, "alphanum_fraction": 0.4893227578, "num_tokens": 509, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681158979307, "lm_q2_score": 0.7577943712746406, "lm_q1q2_score": 0.6500118500863054}} {"text": "C **************************************************************** \nC * * \nC * SOLUTION TO THE CONFLUENT HYPERGEOMETRIC FUNCTION * \nC * * \nC * by * \nC * * \nC * MARK NARDIN, * \nC * * \nC * W. F. PERGER and ATUL BHALLA * \nC * * \nC * * \nC * Michigan Technological University, Copyright 1989 * \nC * * \nC * * \nC * Description : A numerical evaluator for the confluent * \nC * hypergeometric function for complex arguments with large * \nC * magnitudes using a direct summation of the Kummer series. * \nC * The method used allows an accuracy of up to thirteen * \nC * decimal places through the use of large real arrays * \nC * and a single final division. LNCHF is a variable which * \nC * selects how the result should be represented. A '0' will * \nC * return the value in standard exponential form. A '1' * \nC * will return the natural log of the result. IP is an *\nC * integer variable that specifies how many array positions *\nC * are desired (usually 10 is sufficient). Setting IP=0 *\nC * causes the program to estimate the number of array *\nC * positions. *\nC * * \nC * The confluent hypergeometric function is the solution to * \nC * the differential equation: * \nC * * \nC * z M\"(a;b;z) + (b-z) M'(a;b;z) - a M(a;b;z) = 0 * \nC * * \nC * Subprograms called: BITS, CHGF * \nC * *\nC **************************************************************** \n \n FUNCTION CONHYP (A,B,Z,LNCHF,IP) \n \n INTEGER LNCHF,I,BITS,IP\n COMPLEX*16 CHGF,A,B,Z,CONHYP \n DOUBLE PRECISION NTERM,FX,TERM1,MAX,TERM2,ANG,PI\n COMMON/CONSTS/ZERO,HALF,ONE,TWO,TEN,EPS\n DOUBLE PRECISION ZERO,HALF,ONE,TWO,TEN,EPS\n \n ZERO=0.0D0\n PI=TWO*TWO*ATAN(ONE) \n IF (CDABS(Z) .NE. ZERO) THEN\n ANG=DATAN2(DIMAG(Z),DBLE(Z)) \n ELSE \n ANG=ONE \n ENDIF \n IF (DABS(ANG) .LT. (PI*HALF)) THEN \n ANG=ONE \n ELSE \n ANG=DSIN(DABS(ANG)-(PI*HALF))+ONE \n ENDIF \n MAX=ZERO \n NTERM=ZERO \n FX=ZERO \n TERM1=ZERO \n10 NTERM=NTERM+ONE \n TERM2=CDABS((A+NTERM-1)*Z/((B+NTERM-1)*NTERM)) \n IF (TERM2 .EQ. ZERO) GOTO 20 \n IF (TERM2 .LT. ONE) THEN \n IF ((DBLE(A)+NTERM-1) .GT. ONE) THEN \n IF ((DBLE(B)+NTERM-1) .GT. ONE) THEN \n IF ((TERM2-TERM1) .LT. ZERO) THEN \n GOTO 20 \n ENDIF \n ENDIF \n ENDIF \n ENDIF \n FX=FX+DLOG(TERM2) \n IF (FX .GT. MAX) MAX=FX \n TERM1=TERM2 \n GOTO 10 \n20 MAX=MAX*2/(BITS()*6.93147181D-1) \n I=INT(MAX*ANG)+7 \n IF (I .LT. 5) I=5 \n IF (IP .GT. I) I=IP\n CONHYP=CHGF(A,B,Z,I,LNCHF) \n RETURN \n END \n \n \nC **************************************************************** \nC * * \nC * FUNCTION BITS * \nC * * \nC * * \nC * Description : Determines the number of significant figures * \nC * of machine precision to arrive at the size of the array * \nC * the numbers must must be stored in to get the accuracy * \nC * of the solution. * \nC * * \nC * Subprograms called: none * \nC * * \nC **************************************************************** \n \n INTEGER FUNCTION BITS() \n \n DOUBLE PRECISION BIT,BIT2 \n INTEGER COUNT \n COMMON/CONSTS/ZERO,HALF,ONE,TWO,TEN,EPS\n DOUBLE PRECISION ZERO,HALF,ONE,TWO,TEN,EPS\n \n BIT=ONE \n COUNT=0 \n10 COUNT=COUNT+1 \n BIT2=BIT*TWO \n BIT=BIT2+ONE \n IF ((BIT-BIT2) .NE. 0.0) GOTO 10 \n BITS=COUNT-1\n RETURN \n END \n \n \n \nC **************************************************************** \nC * * \nC * FUNCTION CHGF * \nC * * \nC * * \nC * Description : Function that sums the Kummer series and * \nC * returns the solution of the confluent hypergeometric * \nC * function. * \nC * * \nC * Subprograms called: ARMULT, ARYDIV, BITS, CMPADD, CMPMUL * \nC * * \nC **************************************************************** \n \n FUNCTION CHGF (A,B,Z,L,LNCHF) \n \n PARAMETER (LENGTH=777)\n INTEGER L,I,BITS,BIT,LNCHF,NMACH,ICOUNT,IXCNT\n COMPLEX*16 A,B,Z,FINAL,CHGF \n DOUBLE PRECISION AR,AI,CR,CI,XR,XI,SUMR,SUMI,CNT,SIGFIG,MX1,MX2\n DOUBLE PRECISION NUMR,NUMI,DENOMR,DENOMI,RMAX\n DOUBLE PRECISION QR1,QR2,QI1,QI2,AR2,AI2,CR2,CI2,XR2,XI2\n DIMENSION SUMR(-1:LENGTH),SUMI(-1:LENGTH),NUMR(-1:LENGTH)\n DIMENSION NUMI(-1:LENGTH),DENOMR(-1:LENGTH),DENOMI(-1:LENGTH)\n DIMENSION QR1(-1:LENGTH),QR2(-1:LENGTH),QI1(-1:LENGTH),\n : QI2(-1:LENGTH)\n COMMON/CONSTS/ZERO,HALF,ONE,TWO,TEN,EPS\n DOUBLE PRECISION ZERO,HALF,ONE,TWO,TEN,EPS\n \n \n BIT=BITS() \n RMAX=TWO**(BIT/2) \n SIGFIG=TWO**(BIT/4) \n*\n* SET TO ZERO ANY ARGUMENTS WHICH ARE BELOW THE PRECISION OF THE\n* ALGORITHM.\n*\n AR2=DBLE(A)*SIGFIG \n AR=DINT(AR2) \n AR2=DNINT((AR2-AR)*RMAX) \n AI2=DIMAG(A)*SIGFIG \n AI=DINT(AI2) \n AI2=DNINT((AI2-AI)*RMAX) \n CR2=DBLE(B)*SIGFIG \n CR=DINT(CR2) \n CR2=DNINT((CR2-CR)*RMAX) \n CI2=DIMAG(B)*SIGFIG \n CI=DINT(CI2) \n CI2=DNINT((CI2-CI)*RMAX) \n XR2=DBLE(Z)*SIGFIG \n XR=DINT(XR2) \n XR2=DNINT((XR2-XR)*RMAX) \n XI2=DIMAG(Z)*SIGFIG \n XI=DINT(XI2) \n XI2=DNINT((XI2-XI)*RMAX) \n*\n* WARN THE USER THAT THE INPUT VALUE WAS SO CLOSE TO ZERO THAT IT\n* WAS SET EQUAL TO ZERO.\n*\n IF ((DBLE(A).NE.ZERO) .AND. (AR.EQ.ZERO) .AND. (AR2.EQ.ZERO)) \n : WRITE (6,*) ' WARNING - REAL PART OF A WAS SET TO ZERO'\n IF ((DIMAG(A).NE.ZERO) .AND. (AI.EQ.ZERO) .AND. (AI2.EQ.ZERO))\n : WRITE (6,*) ' WARNING - IMAG PART OF A WAS SET TO ZERO'\n IF ((DBLE(B).NE.ZERO) .AND. (CR.EQ.ZERO) .AND. (CR2.EQ.ZERO))\n : WRITE (6,*) ' WARNING - REAL PART OF B WAS SET TO ZERO'\n IF ((DIMAG(B).NE.ZERO) .AND. (CI.EQ.ZERO) .AND. (CI2.EQ.ZERO))\n : WRITE (6,*) ' WARNING - IMAG PART OF B WAS SET TO ZERO'\n IF ((DBLE(Z).NE.ZERO) .AND. (XR.EQ.ZERO) .AND. (XR2.EQ.ZERO))\n : WRITE (6,*) ' WARNING - REAL PART OF Z WAS SET TO ZERO'\n IF ((DIMAG(Z).NE.ZERO) .AND. (XI.EQ.ZERO) .AND. (XI2.EQ.ZERO))\n : WRITE (6,*) ' WARNING - IMAG PART OF Z WAS SET TO ZERO'\n*\n* SCREENING OF THE CASE WHEN B IS ZERO OR A NEGATIVE INTEGER.\n*\n IF ((CR .EQ. ZERO) .AND. (CR2 .EQ. ZERO) .AND.\n : (CI .EQ. ZERO) .AND. (CI2 .EQ. ZERO)) THEN\n WRITE (6,*) ' ERROR-- ARGUMENT B WAS EQUAL TO ZERO'\n STOP\n END IF\n NMACH=INT(LOG10(TWO**INT(BITS())))\n IF ((CI .EQ. ZERO) .AND. (CI2 .EQ. ZERO) .AND.\n : (DBLE(B) .LT. ZERO)) THEN\n IF (ABS(DBLE(B)-DBLE(NINT(DBLE(B)))) .LT. TEN**(-NMACH)) THEN \n WRITE (6,*) ' ERROR-- ARGUMENT B WAS A NEGATIVE INTEGER'\n STOP\n END IF\n END IF\n SUMR(-1)=ONE \n SUMI(-1)=ONE \n NUMR(-1)=ONE \n NUMI(-1)=ONE \n DENOMR(-1)=ONE \n DENOMI(-1)=ONE \n DO 100 I=0,L+1 \n SUMR(I)=ZERO \n SUMI(I)=ZERO \n NUMR(I)=ZERO \n NUMI(I)=ZERO \n DENOMR(I)=ZERO \n DENOMI(I)=ZERO \n100 CONTINUE \n SUMR(1)=ONE \n NUMR(1)=ONE \n DENOMR(1)=ONE \n CNT=SIGFIG \n ICOUNT=-1\n IF ((AI .EQ. ZERO) .AND. (AI2 .EQ. ZERO) .AND.\n : (DBLE(A) .LT. ZERO)) THEN\n IF (ABS(DBLE(A)-DBLE(NINT(DBLE(A)))) .LT. TEN**(-NMACH)) \n : ICOUNT=-NINT(DBLE(A))\n END IF\n IXCNT=0\n 110 IF (SUMR(1) .LT. HALF) THEN\n MX1=SUMI(L+1)\n ELSE IF (SUMI(1) .LT. HALF) THEN \n MX1=SUMR(L+1) \n ELSE \n MX1=DMAX1(SUMR(L+1),SUMI(L+1)) \n ENDIF \n IF (NUMR(1) .LT. HALF) THEN \n MX2=NUMI(L+1) \n ELSE IF (NUMI(1) .LT. HALF) THEN \n MX2=NUMR(L+1) \n ELSE \n MX2=DMAX1(NUMR(L+1),NUMI(L+1)) \n ENDIF \n IF (MX1-MX2 .GT. 2.0) THEN \n IF (CR .GT. ZERO) THEN \n IF (CDABS(CMPLX(AR,AI)*CMPLX(XR,XI)/(CMPLX(CR,CI)*CNT)) \n : .LE. ONE) GOTO 190 \n ENDIF \n ENDIF \n IF (IXCNT .EQ. ICOUNT) GO TO 190\n IXCNT=IXCNT+1\n CALL CMPMUL(SUMR,SUMI,CR,CI,QR1,QI1,L,RMAX) \n CALL CMPMUL(SUMR,SUMI,CR2,CI2,QR2,QI2,L,RMAX) \n QR2(L+1)=QR2(L+1)-1 \n QI2(L+1)=QI2(L+1)-1 \n CALL CMPADD(QR1,QI1,QR2,QI2,SUMR,SUMI,L,RMAX) \n \n CALL ARMULT(SUMR,CNT,SUMR,L,RMAX) \n CALL ARMULT(SUMI,CNT,SUMI,L,RMAX) \n CALL CMPMUL(DENOMR,DENOMI,CR,CI,QR1,QI1,L,RMAX) \n CALL CMPMUL(DENOMR,DENOMI,CR2,CI2,QR2,QI2,L,RMAX) \n QR2(L+1)=QR2(L+1)-1 \n QI2(L+1)=QI2(L+1)-1 \n CALL CMPADD(QR1,QI1,QR2,QI2,DENOMR,DENOMI,L,RMAX) \n \n CALL ARMULT(DENOMR,CNT,DENOMR,L,RMAX) \n CALL ARMULT(DENOMI,CNT,DENOMI,L,RMAX) \n CALL CMPMUL(NUMR,NUMI,AR,AI,QR1,QI1,L,RMAX) \n CALL CMPMUL(NUMR,NUMI,AR2,AI2,QR2,QI2,L,RMAX) \n QR2(L+1)=QR2(L+1)-1 \n QI2(L+1)=QI2(L+1)-1 \n CALL CMPADD(QR1,QI1,QR2,QI2,NUMR,NUMI,L,RMAX) \n \n CALL CMPMUL(NUMR,NUMI,XR,XI,QR1,QI1,L,RMAX) \n CALL CMPMUL(NUMR,NUMI,XR2,XI2,QR2,QI2,L,RMAX) \n QR2(L+1)=QR2(L+1)-1 \n QI2(L+1)=QI2(L+1)-1 \n CALL CMPADD(QR1,QI1,QR2,QI2,NUMR,NUMI,L,RMAX) \n \n CALL CMPADD(SUMR,SUMI,NUMR,NUMI,SUMR,SUMI,L,RMAX) \n CNT=CNT+SIGFIG \n AR=AR+SIGFIG \n CR=CR+SIGFIG \n GOTO 110 \n190 CALL ARYDIV(SUMR,SUMI,DENOMR,DENOMI,FINAL,L,LNCHF,RMAX,BIT) \n CHGF=FINAL \n RETURN \n END \n \n \nC **************************************************************** \nC * * \nC * SUBROUTINE ARADD * \nC * * \nC * * \nC * Description : Accepts two arrays of numbers and returns * \nC * the sum of the array. Each array is holding the value * \nC * of one number in the series. The parameter L is the * \nC * size of the array representing the number and RMAX is * \nC * the actual number of digits needed to give the numbers * \nC * the desired accuracy. * \nC * * \nC * Subprograms called: none * \nC * * \nC **************************************************************** \n \n SUBROUTINE ARADD(A,B,C,L,RMAX) \n \n INTEGER L\n DOUBLE PRECISION A,B,C,Z,RMAX \n INTEGER EDIFF,I,J \n DIMENSION A(-1:*),B(-1:*),C(-1:*),Z(-1:777) \n COMMON/CONSTS/ZERO,HALF,ONE,TWO,TEN,EPS\n DOUBLE PRECISION ZERO,HALF,ONE,TWO,TEN,EPS\n \n DO 110 I=0,L+1 \n Z(I)=ZERO \n110 CONTINUE \n EDIFF=DNINT(A(L+1)-B(L+1)) \n IF (DABS(A(1)) .LT. HALF .OR. EDIFF .LE. -L) GOTO 111 \n IF (DABS(B(1)) .LT. HALF .OR. EDIFF .GE. L) GOTO 113 \n GOTO 115 \n111 DO 112 I=-1,L+1 \n C(I)=B(I) \n112 CONTINUE \n GOTO 311 \n113 DO 114 I=-1,L+1 \n C(I)=A(I) \n114 CONTINUE \n GOTO 311 \n115 Z(-1)=A(-1) \n IF (DABS(A(-1)-B(-1)) .LT. HALF) GOTO 200 \n IF (EDIFF .GT. 0) THEN \n Z(L+1)=A(L+1) \n GOTO 233 \n ENDIF \n IF (EDIFF .LT. 0) THEN \n Z(L+1)=B(L+1) \n Z(-1)=B(-1) \n GOTO 266 \n ENDIF \n DO 120 I=1,L \n IF (A(I) .GT. B(I)) THEN \n Z(L+1)=A(L+1) \n GOTO 233 \n ENDIF \n IF (A(I) .LT. B(I)) THEN \n Z(L+1)=B(L+1) \n Z(-1)=B(-1) \n GOTO 266 \n ENDIF \n120 CONTINUE \n GOTO 300 \n \n200 IF (EDIFF .GT. 0) GOTO 203 \n IF (EDIFF .LT. 0) GOTO 207 \n Z(L+1)=A(L+1) \n DO 201 I=L,1,-1 \n Z(I)=A(I)+B(I)+Z(I) \n IF (Z(I) .GE. RMAX) THEN \n Z(I)=Z(I)-RMAX \n Z(I-1)=ONE \n ENDIF \n201 CONTINUE \n IF (Z(0) .GT. HALF) THEN \n DO 202 I=L,1,-1 \n Z(I)=Z(I-1) \n202 CONTINUE \n Z(L+1)=Z(L+1)+ONE \n Z(0)=ZERO \n ENDIF \n GOTO 300 \n203 Z(L+1)=A(L+1) \n DO 204 I=L,1+EDIFF,-1 \n Z(I)=A(I)+B(I-EDIFF)+Z(I) \n IF (Z(I) .GE. RMAX) THEN \n Z(I)=Z(I)-RMAX \n Z(I-1)=ONE \n ENDIF \n204 CONTINUE \n DO 205 I=EDIFF,1,-1 \n Z(I)=A(I)+Z(I) \n IF (Z(I) .GE. RMAX) THEN \n Z(I)=Z(I)-RMAX \n Z(I-1)=ONE \n ENDIF \n205 CONTINUE \n IF (Z(0) .GT. HALF) THEN \n DO 206 I=L,1,-1 \n Z(I)=Z(I-1) \n206 CONTINUE \n Z(L+1)=Z(L+1)+1 \n Z(0)=ZERO \n ENDIF \n GOTO 300 \n207 Z(L+1)=B(L+1) \n DO 208 I=L,1-EDIFF,-1 \n Z(I)=A(I+EDIFF)+B(I)+Z(I) \n IF (Z(I) .GE. RMAX) THEN \n Z(I)=Z(I)-RMAX \n Z(I-1)=ONE \n ENDIF \n208 CONTINUE \n DO 209 I=0-EDIFF,1,-1 \n Z(I)=B(I)+Z(I) \n IF (Z(I) .GE. RMAX) THEN \n Z(I)=Z(I)-RMAX \n Z(I-1)=ONE \n ENDIF \n209 CONTINUE \n IF (Z(0) .GT. HALF) THEN \n DO 210 I=L,1,-1 \n Z(I)=Z(I-1) \n210 CONTINUE \n Z(L+1)=Z(L+1)+ONE \n Z(0)=ZERO \n ENDIF \n GOTO 300 \n \n233 IF (EDIFF .GT. 0) GOTO 243 \n DO 234 I=L,1,-1 \n Z(I)=A(I)-B(I)+Z(I) \n IF (Z(I) .LT. ZERO) THEN \n Z(I)=Z(I)+RMAX \n Z(I-1)=-ONE \n ENDIF \n234 CONTINUE \n GOTO 290 \n243 DO 244 I=L,1+EDIFF,-1 \n Z(I)=A(I)-B(I-EDIFF)+Z(I) \n IF (Z(I) .LT. ZERO) THEN \n Z(I)=Z(I)+RMAX \n Z(I-1)=-ONE \n ENDIF \n244 CONTINUE \n DO 245 I=EDIFF,1,-1 \n Z(I)=A(I)+Z(I) \n IF (Z(I) .LT. ZERO) THEN \n Z(I)=Z(I)+RMAX \n Z(I-1)=-ONE \n ENDIF \n245 CONTINUE \n GOTO 290 \n \n266 IF (EDIFF .LT. 0) GOTO 276 \n DO 267 I=L,1,-1 \n Z(I)=B(I)-A(I)+Z(I) \n IF (Z(I) .LT. ZERO) THEN \n Z(I)=Z(I)+RMAX \n Z(I-1)=-ONE \n ENDIF \n267 CONTINUE \n GOTO 290 \n276 DO 277 I=L,1-EDIFF,-1 \n Z(I)=B(I)-A(I+EDIFF)+Z(I) \n IF (Z(I) .LT. ZERO) THEN \n Z(I)=Z(I)+RMAX \n Z(I-1)=-ONE \n ENDIF \n277 CONTINUE \n DO 278 I=0-EDIFF,1,-1 \n Z(I)=B(I)+Z(I) \n IF (Z(I) .LT. ZERO) THEN \n Z(I)=Z(I)+RMAX \n Z(I-1)=-ONE \n ENDIF \n278 CONTINUE \n \n290 IF (Z(1) .GT. HALF) GOTO 300 \n I=1 \n291 I=I+1 \n IF (Z(I) .LT. HALF .AND. I .LT. L+1) GOTO 291 \n IF (I .EQ. L+1) THEN \n Z(-1)=ONE \n Z(L+1)=ZERO \n GOTO 300 \n ENDIF \n292 DO 293 J=1,L+1-I \n Z(J)=Z(J+I-1) \n293 CONTINUE \n DO 294 J=L+2-I,L \n Z(J)=ZERO \n294 CONTINUE \n Z(L+1)=Z(L+1)-I+1 \n300 DO 310 I=-1,L+1 \n C(I)=Z(I) \n310 CONTINUE \n311 IF (C(1) .LT. HALF) THEN \n C(-1)=ONE \n C(L+1)=ZERO \n ENDIF \n RETURN \n END \n \n \nC **************************************************************** \nC * * \nC * SUBROUTINE ARSUB * \nC * * \nC * * \nC * Description : Accepts two arrays and subtracts each element * \nC * in the second array from the element in the first array * \nC * and returns the solution. The parameters L and RMAX are * \nC * the size of the array and the number of digits needed for * \nC * the accuracy, respectively. * \nC * * \nC * Subprograms called: ARADD * \nC * * \nC **************************************************************** \n \n SUBROUTINE ARSUB(A,B,C,L,RMAX) \n \n INTEGER L,I\n DOUBLE PRECISION A,B,C,B2,RMAX \n DIMENSION A(-1:*),B(-1:*),C(-1:*),B2(-1:777) \n COMMON/CONSTS/ZERO,HALF,ONE,TWO,TEN,EPS\n DOUBLE PRECISION ZERO,HALF,ONE,TWO,TEN,EPS\n \n DO 100 I=-1,L+1 \n B2(I)=B(I) \n100 CONTINUE \n B2(-1)=(-ONE)*B2(-1) \n CALL ARADD(A,B2,C,L,RMAX) \n RETURN \n END \n \n \nC **************************************************************** \nC * * \nC * SUBROUTINE ARMULT * \nC * * \nC * * \nC * Description : Accepts two arrays and returns the product. * \nC * L and RMAX are the size of the arrays and the number of * \nC * digits needed to represent the numbers with the required * \nC * accuracy. * \nC * * \nC * Subprograms called: none * \nC * * \nC **************************************************************** \n \n SUBROUTINE ARMULT(A,B,C,L,RMAX) \n \n INTEGER L\n DOUBLE PRECISION A,B,C,Z,B2,CARRY,RMAX,RMAX2 \n DIMENSION A(-1:*),C(-1:*),Z(-1:777) \n INTEGER I \n COMMON/CONSTS/ZERO,HALF,ONE,TWO,TEN,EPS\n DOUBLE PRECISION ZERO,HALF,ONE,TWO,TEN,EPS\n \n RMAX2=ONE/RMAX \n Z(-1)=DSIGN(ONE,B)*A(-1) \n B2=DABS(B) \n Z(L+1)=A(L+1) \n DO 100 I=0,L \n Z(I)=ZERO \n100 CONTINUE \n IF (B2 .LE. EPS .OR. A(1) .LE. EPS) THEN \n Z(-1)=ONE \n Z(L+1)=ZERO \n GOTO 198 \n ENDIF \n DO 110 I=L,1,-1 \n Z(I)=A(I)*B2+Z(I) \n IF (Z(I) .GE. RMAX) THEN \n CARRY=DINT(Z(I)/RMAX) \n Z(I)=Z(I)-CARRY*RMAX \n Z(I-1)=CARRY \n ENDIF \n110 CONTINUE \n IF (Z(0) .LT. HALF) GOTO 150 \n DO 120 I=L,1,-1 \n Z(I)=Z(I-1) \n120 CONTINUE \n Z(L+1)=Z(L+1)+ONE \n Z(0)=ZERO \n150 CONTINUE \n \n \n198 DO 199 I=-1,L+1 \n C(I)=Z(I) \n199 CONTINUE \n IF (C(1) .LT. HALF) THEN \n C(-1)=ONE \n C(L+1)=ZERO \n ENDIF \n RETURN \n END \n \n \nC **************************************************************** \nC * * \nC * SUBROUTINE CMPADD * \nC * * \nC * * \nC * Description : Takes two arrays representing one real and * \nC * one imaginary part, and adds two arrays representing * \nC * another complex number and returns two array holding the * \nC * complex sum. * \nC * (CR,CI) = (AR+BR, AI+BI) * \nC * * \nC * Subprograms called: ARADD * \nC * * \nC **************************************************************** \n \n SUBROUTINE CMPADD(AR,AI,BR,BI,CR,CI,L,RMAX) \n \n INTEGER L\n DOUBLE PRECISION AR,AI,BR,BI,CR,CI,RMAX \n DIMENSION AR(-1:*),AI(-1:*),BR(-1:*),BI(-1:*) \n DIMENSION CR(-1:*),CI(-1:*) \n \n CALL ARADD(AR,BR,CR,L,RMAX) \n CALL ARADD(AI,BI,CI,L,RMAX) \n RETURN \n END \n \n \nC **************************************************************** \nC * * \nC * SUBROUTINE CMPSUB * \nC * * \nC * * \nC * Description : Takes two arrays representing one real and * \nC * one imaginary part, and subtracts two arrays representing * \nC * another complex number and returns two array holding the * \nC * complex sum. * \nC * (CR,CI) = (AR+BR, AI+BI) * \nC * * \nC * Subprograms called: ARADD * \nC * * \nC **************************************************************** \n \n SUBROUTINE CMPSUB(AR,AI,BR,BI,CR,CI,L,RMAX) \n \n INTEGER L\n DOUBLE PRECISION AR,AI,BR,BI,CR,CI,RMAX \n DIMENSION AR(-1:*),AI(-1:*),BR(-1:*),BI(-1:*) \n DIMENSION CR(-1:*),CI(-1:*) \n \n CALL ARSUB(AR,BR,CR,L,RMAX) \n CALL ARSUB(AI,BI,CI,L,RMAX) \n RETURN \n END \n \n \nC **************************************************************** \nC * * \nC * SUBROUTINE CMPMUL * \nC * * \nC * * \nC * Description : Takes two arrays representing one real and * \nC * one imaginary part, and multiplies it with two arrays * \nC * representing another complex number and returns the * \nC * complex product. * \nC * * \nC * Subprograms called: ARMULT, ARSUB, ARADD * \nC * * \nC **************************************************************** \n \n SUBROUTINE CMPMUL(AR,AI,BR,BI,CR,CI,L,RMAX) \n \n INTEGER L\n DOUBLE PRECISION AR,AI,BR,BI,CR,CI,D1,D2,RMAX \n DIMENSION AR(-1:*),AI(-1:*),CR(-1:*),CI(-1:*) \n DIMENSION D1(-1:777),D2(-1:777) \n \n CALL ARMULT(AR,BR,D1,L,RMAX) \n CALL ARMULT(AI,BI,D2,L,RMAX) \n CALL ARSUB(D1,D2,CR,L,RMAX) \n CALL ARMULT(AR,BI,D1,L,RMAX) \n CALL ARMULT(AI,BR,D2,L,RMAX) \n CALL ARADD(D1,D2,CI,L,RMAX) \n RETURN \n END \n \n \nC **************************************************************** \nC * * \nC * SUBROUTINE ARYDIV * \nC * * \nC * * \nC * Description : Returns the double precision complex number * \nC * resulting from the division of four arrays, representing * \nC * two complex numbers. The number returned will be in one * \nC * two different forms: either standard scientific or as * \nC * the natural log of the number. * \nC * * \nC * Subprograms called: CONV21, CONV12, EADD, ECPDIV, EMULT * \nC * * \nC **************************************************************** \n \n SUBROUTINE ARYDIV(AR,AI,BR,BI,C,L,LNCHF,RMAX,BIT) \n \n INTEGER L,BIT,REXP,IR10,II10,LNCHF\n COMPLEX*16 C \n DOUBLE PRECISION AR,AI,BR,BI,PHI,N1,N2,N3,E1,E2,E3,RR10,RI10,X \n DOUBLE PRECISION AE,BE,X1,X2,DUM1,DUM2,CE,RMAX \n DIMENSION AR(-1:*),AI(-1:*),BR(-1:*),BI(-1:*) \n DIMENSION AE(2,2),BE(2,2),CE(2,2) \n COMMON/CONSTS/ZERO,HALF,ONE,TWO,TEN,EPS\n DOUBLE PRECISION ZERO,HALF,ONE,TWO,TEN,EPS\n \n REXP=BIT/2 \n X=REXP*(AR(L+1)-2) \n RR10=X*DLOG10(TWO)/DLOG10(TEN) \n IR10=INT(RR10) \n RR10=RR10-IR10 \n X=REXP*(AI(L+1)-2) \n RI10=X*DLOG10(TWO)/DLOG10(TEN) \n II10=INT(RI10) \n RI10=RI10-II10 \n DUM1=DSIGN(AR(1)*RMAX*RMAX+AR(2)*RMAX+AR(3),AR(-1)) \n DUM2=DSIGN(AI(1)*RMAX*RMAX+AI(2)*RMAX+AI(3),AI(-1)) \n DUM1=DUM1*10**RR10 \n DUM2=DUM2*10**RI10 \n CALL CONV12(DCMPLX(DUM1,DUM2),AE) \n AE(1,2)=AE(1,2)+IR10 \n AE(2,2)=AE(2,2)+II10 \n X=REXP*(BR(L+1)-2) \n RR10=X*DLOG10(TWO)/DLOG10(TEN) \n IR10=INT(RR10) \n RR10=RR10-IR10 \n X=REXP*(BI(L+1)-2) \n RI10=X*DLOG10(TWO)/DLOG10(TEN) \n II10=INT(RI10) \n RI10=RI10-II10 \n DUM1=DSIGN(BR(1)*RMAX*RMAX+BR(2)*RMAX+BR(3),BR(-1)) \n DUM2=DSIGN(BI(1)*RMAX*RMAX+BI(2)*RMAX+BI(3),BI(-1)) \n DUM1=DUM1*10**RR10 \n DUM2=DUM2*10**RI10 \n CALL CONV12(DCMPLX(DUM1,DUM2),BE) \n BE(1,2)=BE(1,2)+IR10 \n BE(2,2)=BE(2,2)+II10 \n CALL ECPDIV(AE,BE,CE) \n IF (LNCHF .EQ. 0) THEN \n CALL CONV21(CE,C) \n ELSE \n CALL EMULT(CE(1,1),CE(1,2),CE(1,1),CE(1,2),N1,E1) \n CALL EMULT(CE(2,1),CE(2,2),CE(2,1),CE(2,2),N2,E2) \n CALL EADD(N1,E1,N2,E2,N3,E3) \n N1=CE(1,1) \n E1=CE(1,2)-CE(2,2) \n X2=CE(2,1) \n IF (E1 .GT. 74.0D0) THEN \n X1=1.0D75 \n ELSEIF (E1 .LT. -74.0D0) THEN \n X1=0 \n ELSE \n X1=N1*(10**E1) \n ENDIF \n PHI=DATAN2(X2,X1) \n C=DCMPLX(HALF*(DLOG(N3)+E3*DLOG(TEN)),PHI) \n ENDIF \n RETURN \n END \n \n \nC **************************************************************** \nC * * \nC * SUBROUTINE EMULT * \nC * * \nC * * \nC * Description : Takes one base and exponent and multiplies it * \nC * by another numbers base and exponent to give the product * \nC * in the form of base and exponent. * \nC * * \nC * Subprograms called: none * \nC * * \nC **************************************************************** \n \n SUBROUTINE EMULT(N1,E1,N2,E2,NF,EF) \n \n DOUBLE PRECISION N1,E1,N2,E2,NF,EF \n COMMON/CONSTS/ZERO,HALF,ONE,TWO,TEN,EPS\n DOUBLE PRECISION ZERO,HALF,ONE,TWO,TEN,EPS\n \n NF=N1*N2 \n EF=E1+E2 \n IF (DABS(NF) .GE. TEN) THEN \n NF=NF/TEN \n EF=EF+ONE \n ENDIF \n RETURN \n END \n \n \nC **************************************************************** \nC * * \nC * SUBROUTINE EDIV * \nC * * \nC * * \nC * Description : returns the solution in the form of base and * \nC * exponent of the division of two exponential numbers. * \nC * * \nC * Subprograms called: none * \nC * * \nC **************************************************************** \n \n SUBROUTINE EDIV(N1,E1,N2,E2,NF,EF) \n \n DOUBLE PRECISION N1,E1,N2,E2,NF,EF \n COMMON/CONSTS/ZERO,HALF,ONE,TWO,TEN,EPS\n DOUBLE PRECISION ZERO,HALF,ONE,TWO,TEN,EPS\n \n NF=N1/N2 \n EF=E1-E2 \n IF ((DABS(NF) .LT. ONE) .AND. (NF .NE. ZERO)) THEN \n NF=NF*TEN \n EF=EF-ONE \n ENDIF \n RETURN \n END \n \n \nC **************************************************************** \nC * * \nC * SUBROUTINE EADD * \nC * * \nC * * \nC * Description : Returns the sum of two numbers in the form * \nC * of a base and an exponent. * \nC * * \nC * Subprograms called: none * \nC * * \nC **************************************************************** \n \n SUBROUTINE EADD(N1,E1,N2,E2,NF,EF) \n \n DOUBLE PRECISION N1,E1,N2,E2,NF,EF,EDIFF,THIRSIX\n COMMON/CONSTS/ZERO,HALF,ONE,TWO,TEN,EPS\n DOUBLE PRECISION ZERO,HALF,ONE,TWO,TEN,EPS\n \n EDIFF=E1-E2 \n THIRSIX=(ONE+TWO)*(TWO+TEN)\n IF (EDIFF .GT. THIRSIX) THEN \n NF=N1 \n EF=E1 \n ELSE IF (EDIFF .LT. -THIRSIX) THEN \n NF=N2 \n EF=E2 \n ELSE \n NF=N1*(TEN**EDIFF)+N2 \n EF=E2 \n400 IF (DABS(NF) .LT. TEN) GOTO 410 \n NF=NF/TEN \n EF=EF+ONE \n GOTO 400 \n410 IF ((DABS(NF) .GE. ONE) .OR. (NF .EQ. ZERO)) GOTO 420 \n NF=NF*TEN \n EF=EF-ONE \n GOTO 410 \n ENDIF \n420 RETURN \n END \n \n \nC **************************************************************** \nC * * \nC * SUBROUTINE ESUB * \nC * * \nC * * \nC * Description : Returns the solution to the subtraction of * \nC * two numbers in the form of base and exponent. * \nC * * \nC * Subprograms called: EADD * \nC * * \nC **************************************************************** \n \n SUBROUTINE ESUB(N1,E1,N2,E2,NF,EF) \n \n DOUBLE PRECISION N1,E1,N2,E2,NF,EF \n COMMON/CONSTS/ZERO,HALF,ONE,TWO,TEN,EPS\n DOUBLE PRECISION ZERO,HALF,ONE,TWO,TEN,EPS\n \n CALL EADD(N1,E1,N2*(-ONE),E2,NF,EF) \n RETURN \n END \n \n \nC **************************************************************** \nC * * \nC * SUBROUTINE CONV12 * \nC * * \nC * * \nC * Description : Converts a number from complex notation to a * \nC * form of a 2x2 real array. * \nC * * \nC * Subprograms called: none * \nC * * \nC **************************************************************** \n \n SUBROUTINE CONV12(CN,CAE) \n \n COMPLEX*16 CN \n DOUBLE PRECISION CAE \n DIMENSION CAE(2,2) \n COMMON/CONSTS/ZERO,HALF,ONE,TWO,TEN,EPS\n DOUBLE PRECISION ZERO,HALF,ONE,TWO,TEN,EPS\n \n CAE(1,1)=DBLE(CN) \n CAE(1,2)=ZERO \n300 IF (DABS(CAE(1,1)) .LT. TEN) GOTO 310 \n CAE(1,1)=CAE(1,1)/TEN \n CAE(1,2)=CAE(1,2)+ONE \n GOTO 300 \n310 IF ((DABS(CAE(1,1)) .GE. ONE) .OR. (CAE(1,1) .EQ. ZERO)) \n : GOTO 320 \n CAE(1,1)=CAE(1,1)*TEN \n CAE(1,2)=CAE(1,2)-ONE \n GOTO 310 \n320 CAE(2,1)=DIMAG(CN) \n CAE(2,2)=ZERO \n330 IF (DABS(CAE(2,1)) .LT. TEN) GOTO 340 \n CAE(2,1)=CAE(2,1)/TEN \n CAE(2,2)=CAE(2,2)+ONE \n GOTO 330 \n340 IF ((DABS(CAE(2,1)) .GE. ONE) .OR. (CAE(2,1) .EQ. ZERO)) \n : GOTO 350 \n CAE(2,1)=CAE(2,1)*TEN \n CAE(2,2)=CAE(2,2)-ONE \n GOTO 340 \n350 RETURN \n END \n \n \nC **************************************************************** \nC * * \nC * SUBROUTINE CONV21 * \nC * * \nC * * \nC * Description : Converts a number represented in a 2x2 real * \nC * array to the form of a complex number. * \nC * * \nC * Subprograms called: none * \nC * * \nC **************************************************************** \n \n SUBROUTINE CONV21(CAE,CN) \n \n DOUBLE PRECISION CAE \n COMPLEX*16 CN \n DIMENSION CAE(2,2) \n COMMON/CONSTS/ZERO,HALF,ONE,TWO,TEN,EPS\n DOUBLE PRECISION ZERO,HALF,ONE,TWO,TEN,EPS\n IF (CAE(1,2) .GT. 75 .OR. CAE(2,2) .GT. 75) THEN \n CN=CMPLX(1.0D75,1.0D75) \n ELSE IF (CAE(2,2) .LT. -75) THEN \n CN=DCMPLX(CAE(1,1)*(10**CAE(1,2)),ZERO) \n ELSE \n CN=DCMPLX(CAE(1,1)*(10**CAE(1,2)),CAE(2,1)*(10**CAE(2,2))) \n ENDIF \n RETURN \n END \n \n \nC **************************************************************** \nC * * \nC * SUBROUTINE ECPMUL * \nC * * \nC * * \nC * Description : Multiplies two numbers which are each * \nC * represented in the form of a two by two array and returns * \nC * the solution in the same form. * \nC * * \nC * Subprograms called: EMULT, ESUB, EADD * \nC * * \nC **************************************************************** \n \n SUBROUTINE ECPMUL(A,B,C) \n \n DOUBLE PRECISION A,B,C,N1,E1,N2,E2,C2 \n DIMENSION A(2,2),B(2,2),C(2,2),C2(2,2) \n \n CALL EMULT(A(1,1),A(1,2),B(1,1),B(1,2),N1,E1) \n CALL EMULT(A(2,1),A(2,2),B(2,1),B(2,2),N2,E2) \n CALL ESUB(N1,E1,N2,E2,C2(1,1),C2(1,2)) \n CALL EMULT(A(1,1),A(1,2),B(2,1),B(2,2),N1,E1) \n CALL EMULT(A(2,1),A(2,2),B(1,1),B(1,2),N2,E2) \n CALL EADD(N1,E1,N2,E2,C(2,1),C(2,2)) \n C(1,1)=C2(1,1) \n C(1,2)=C2(1,2) \n RETURN \n END \n \n \nC **************************************************************** \nC * * \nC * SUBROUTINE ECPDIV * \nC * * \nC * * \nC * Description : Divides two numbers and returns the solution. * \nC * All numbers are represented by a 2x2 array. * \nC * * \nC * Subprograms called: EADD, ECPMUL, EDIV, EMULT * \nC * * \nC **************************************************************** \n \n SUBROUTINE ECPDIV(A,B,C) \n \n DOUBLE PRECISION A,B,C,N1,E1,N2,E2,B2,N3,E3,C2 \n DIMENSION A(2,2),B(2,2),C(2,2),B2(2,2),C2(2,2) \n COMMON/CONSTS/ZERO,HALF,ONE,TWO,TEN,EPS\n DOUBLE PRECISION ZERO,HALF,ONE,TWO,TEN,EPS\n \n B2(1,1)=B(1,1) \n B2(1,2)=B(1,2) \n B2(2,1)=-ONE*B(2,1) \n B2(2,2)=B(2,2) \n CALL ECPMUL(A,B2,C2) \n CALL EMULT(B(1,1),B(1,2),B(1,1),B(1,2),N1,E1) \n CALL EMULT(B(2,1),B(2,2),B(2,1),B(2,2),N2,E2) \n CALL EADD(N1,E1,N2,E2,N3,E3) \n CALL EDIV(C2(1,1),C2(1,2),N3,E3,C(1,1),C(1,2)) \n CALL EDIV(C2(2,1),C2(2,2),N3,E3,C(2,1),C(2,2)) \n RETURN \n END \nC **************************************************************** \nC * * \nC * BLOCK DATA BLDAT1 * \nC * * \nC * * \nC * Description : Sets of frequently used numbers in a common * \nC * block. This makes it easier to convert the code to a * \nC * single precision version. * \nC * * \nC **************************************************************** \n \n BLOCK DATA BLDAT1\nC\n COMMON/CONSTS/ZERO,HALF,ONE,TWO,TEN,EPS\n DOUBLE PRECISION ZERO,HALF,ONE,TWO,TEN,EPS\n DATA ZERO,HALF,ONE,TWO,TEN,EPS/0.0D0,0.5D0,1.0D0,2.0D0,\n : 10.0D0,1.0D-10/\n END\n", "meta": {"hexsha": "2e19b018363baffabf0ce1016a64dc362b8ad008", "size": 71872, "ext": "f", "lang": "FORTRAN", "max_stars_repo_path": "algorithms/conhyp.f", "max_stars_repo_name": "tpudlik/hyp1f1", "max_stars_repo_head_hexsha": "2509509b019b7eabb9063da8d68e8e1405bf2ffe", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "algorithms/conhyp.f", "max_issues_repo_name": "tpudlik/hyp1f1", "max_issues_repo_head_hexsha": "2509509b019b7eabb9063da8d68e8e1405bf2ffe", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "algorithms/conhyp.f", "max_forks_repo_name": "tpudlik/hyp1f1", "max_forks_repo_head_hexsha": "2509509b019b7eabb9063da8d68e8e1405bf2ffe", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 69.3076181292, "max_line_length": 82, "alphanum_fraction": 0.1977265138, "num_tokens": 11837, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299550303293, "lm_q2_score": 0.7025300698514778, "lm_q1q2_score": 0.650001864936137}}